blob: 3918790c4a75a94ea4e7632f1a30c617b49e5cc6 [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 *
Vivien Didelotb8fee952015-08-13 12:52:19 -04006 * Copyright (c) 2015 CMC Electronics, Inc.
7 * Added support for VLAN Table Unit operations
8 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02009 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
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 Didelotfad09c72016-06-21 12:28:20 -0400680static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200681{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400682 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200683}
684
Vivien Didelotfad09c72016-06-21 12:28:20 -0400685static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200686{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400687 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200688}
689
Gregory CLEMENTa75961d2017-01-30 20:29:34 +0100690static bool mv88e6xxx_6341_family(struct mv88e6xxx_chip *chip)
691{
692 return chip->info->family == MV88E6XXX_FAMILY_6341;
693}
694
Vivien Didelotfad09c72016-06-21 12:28:20 -0400695static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200696{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400697 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200698}
699
Vivien Didelotfad09c72016-06-21 12:28:20 -0400700static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200701{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400702 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200703}
704
Vivien Didelotd78343d2016-11-04 03:23:36 +0100705static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
706 int link, int speed, int duplex,
707 phy_interface_t mode)
708{
709 int err;
710
711 if (!chip->info->ops->port_set_link)
712 return 0;
713
714 /* Port's MAC control must not be changed unless the link is down */
715 err = chip->info->ops->port_set_link(chip, port, 0);
716 if (err)
717 return err;
718
719 if (chip->info->ops->port_set_speed) {
720 err = chip->info->ops->port_set_speed(chip, port, speed);
721 if (err && err != -EOPNOTSUPP)
722 goto restore_link;
723 }
724
725 if (chip->info->ops->port_set_duplex) {
726 err = chip->info->ops->port_set_duplex(chip, port, duplex);
727 if (err && err != -EOPNOTSUPP)
728 goto restore_link;
729 }
730
731 if (chip->info->ops->port_set_rgmii_delay) {
732 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
733 if (err && err != -EOPNOTSUPP)
734 goto restore_link;
735 }
736
Andrew Lunnf39908d2017-02-04 20:02:50 +0100737 if (chip->info->ops->port_set_cmode) {
738 err = chip->info->ops->port_set_cmode(chip, port, mode);
739 if (err && err != -EOPNOTSUPP)
740 goto restore_link;
741 }
742
Vivien Didelotd78343d2016-11-04 03:23:36 +0100743 err = 0;
744restore_link:
745 if (chip->info->ops->port_set_link(chip, port, link))
746 netdev_err(chip->ds->ports[port].netdev,
747 "failed to restore MAC's link\n");
748
749 return err;
750}
751
Andrew Lunndea87022015-08-31 15:56:47 +0200752/* We expect the switch to perform auto negotiation if there is a real
753 * phy. However, in the case of a fixed link phy, we force the port
754 * settings from the fixed link settings.
755 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400756static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
757 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200758{
Vivien Didelot04bed142016-08-31 18:06:13 -0400759 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200760 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200761
762 if (!phy_is_pseudo_fixed_link(phydev))
763 return;
764
Vivien Didelotfad09c72016-06-21 12:28:20 -0400765 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100766 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
767 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400768 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100769
770 if (err && err != -EOPNOTSUPP)
771 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200772}
773
Andrew Lunna605a0f2016-11-21 23:26:58 +0100774static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000775{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100776 if (!chip->info->ops->stats_snapshot)
777 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000778
Andrew Lunna605a0f2016-11-21 23:26:58 +0100779 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000780}
781
Andrew Lunne413e7e2015-04-02 04:06:38 +0200782static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100783 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
784 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
785 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
786 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
787 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
788 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
789 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
790 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
791 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
792 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
793 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
794 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
795 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
796 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
797 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
798 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
799 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
800 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
801 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
802 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
803 { "single", 4, 0x14, STATS_TYPE_BANK0, },
804 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
805 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
806 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
807 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
808 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
809 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
810 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
811 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
812 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
813 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
814 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
815 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
816 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
817 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
818 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
819 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
820 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
821 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
822 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
823 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
824 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
825 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
826 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
827 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
828 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
829 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
830 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
831 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
832 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
833 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
834 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
835 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
836 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
837 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
838 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
839 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
840 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
841 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200842};
843
Vivien Didelotfad09c72016-06-21 12:28:20 -0400844static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100845 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100846 int port, u16 bank1_select,
847 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200848{
Andrew Lunn80c46272015-06-20 18:42:30 +0200849 u32 low;
850 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100851 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200852 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200853 u64 value;
854
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100855 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100856 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200857 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
858 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200859 return UINT64_MAX;
860
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200861 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200862 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200863 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
864 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200865 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200866 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200867 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100868 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100869 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100870 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100871 /* fall through */
872 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100873 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100874 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200875 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100876 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200877 }
878 value = (((u64)high) << 16) | low;
879 return value;
880}
881
Andrew Lunndfafe442016-11-21 23:27:02 +0100882static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
883 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100884{
885 struct mv88e6xxx_hw_stat *stat;
886 int i, j;
887
888 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
889 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100890 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100891 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
892 ETH_GSTRING_LEN);
893 j++;
894 }
895 }
896}
897
Andrew Lunndfafe442016-11-21 23:27:02 +0100898static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
899 uint8_t *data)
900{
901 mv88e6xxx_stats_get_strings(chip, data,
902 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
903}
904
905static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
906 uint8_t *data)
907{
908 mv88e6xxx_stats_get_strings(chip, data,
909 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
910}
911
912static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
913 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100914{
Vivien Didelot04bed142016-08-31 18:06:13 -0400915 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100916
917 if (chip->info->ops->stats_get_strings)
918 chip->info->ops->stats_get_strings(chip, data);
919}
920
921static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
922 int types)
923{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100924 struct mv88e6xxx_hw_stat *stat;
925 int i, j;
926
927 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
928 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100929 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100930 j++;
931 }
932 return j;
933}
934
Andrew Lunndfafe442016-11-21 23:27:02 +0100935static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
936{
937 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
938 STATS_TYPE_PORT);
939}
940
941static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
942{
943 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
944 STATS_TYPE_BANK1);
945}
946
947static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
948{
949 struct mv88e6xxx_chip *chip = ds->priv;
950
951 if (chip->info->ops->stats_get_sset_count)
952 return chip->info->ops->stats_get_sset_count(chip);
953
954 return 0;
955}
956
Andrew Lunn052f9472016-11-21 23:27:03 +0100957static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100958 uint64_t *data, int types,
959 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100960{
961 struct mv88e6xxx_hw_stat *stat;
962 int i, j;
963
964 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
965 stat = &mv88e6xxx_hw_stats[i];
966 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100967 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
968 bank1_select,
969 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100970 j++;
971 }
972 }
973}
974
975static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
976 uint64_t *data)
977{
978 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100979 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
980 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100981}
982
983static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
984 uint64_t *data)
985{
986 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100987 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
988 GLOBAL_STATS_OP_BANK_1_BIT_9,
989 GLOBAL_STATS_OP_HIST_RX_TX);
990}
991
992static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
993 uint64_t *data)
994{
995 return mv88e6xxx_stats_get_stats(chip, port, data,
996 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
997 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100998}
999
1000static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1001 uint64_t *data)
1002{
1003 if (chip->info->ops->stats_get_stats)
1004 chip->info->ops->stats_get_stats(chip, port, data);
1005}
1006
Vivien Didelotf81ec902016-05-09 13:22:58 -04001007static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1008 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001009{
Vivien Didelot04bed142016-08-31 18:06:13 -04001010 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001011 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001012
Vivien Didelotfad09c72016-06-21 12:28:20 -04001013 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001014
Andrew Lunna605a0f2016-11-21 23:26:58 +01001015 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001016 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001017 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001018 return;
1019 }
Andrew Lunn052f9472016-11-21 23:27:03 +01001020
1021 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001022
Vivien Didelotfad09c72016-06-21 12:28:20 -04001023 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001024}
Ben Hutchings98e67302011-11-25 14:36:19 +00001025
Andrew Lunnde2273872016-11-21 23:27:01 +01001026static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1027{
1028 if (chip->info->ops->stats_set_histogram)
1029 return chip->info->ops->stats_set_histogram(chip);
1030
1031 return 0;
1032}
1033
Vivien Didelotf81ec902016-05-09 13:22:58 -04001034static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001035{
1036 return 32 * sizeof(u16);
1037}
1038
Vivien Didelotf81ec902016-05-09 13:22:58 -04001039static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1040 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001041{
Vivien Didelot04bed142016-08-31 18:06:13 -04001042 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001043 int err;
1044 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001045 u16 *p = _p;
1046 int i;
1047
1048 regs->version = 0;
1049
1050 memset(p, 0xff, 32 * sizeof(u16));
1051
Vivien Didelotfad09c72016-06-21 12:28:20 -04001052 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001053
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001054 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001055
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001056 err = mv88e6xxx_port_read(chip, port, i, &reg);
1057 if (!err)
1058 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001059 }
Vivien Didelot23062512016-05-09 13:22:45 -04001060
Vivien Didelotfad09c72016-06-21 12:28:20 -04001061 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001062}
1063
Vivien Didelotf81ec902016-05-09 13:22:58 -04001064static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1065 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001066{
Vivien Didelot04bed142016-08-31 18:06:13 -04001067 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001068 u16 reg;
1069 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001070
Vivien Didelotfad09c72016-06-21 12:28:20 -04001071 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001072 return -EOPNOTSUPP;
1073
Vivien Didelotfad09c72016-06-21 12:28:20 -04001074 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001075
Vivien Didelot9c938292016-08-15 17:19:02 -04001076 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1077 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001078 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001079
1080 e->eee_enabled = !!(reg & 0x0200);
1081 e->tx_lpi_enabled = !!(reg & 0x0100);
1082
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001083 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001084 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001085 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001086
Andrew Lunncca8b132015-04-02 04:06:39 +02001087 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001088out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001089 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001090
1091 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001092}
1093
Vivien Didelotf81ec902016-05-09 13:22:58 -04001094static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1095 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001096{
Vivien Didelot04bed142016-08-31 18:06:13 -04001097 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001098 u16 reg;
1099 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001100
Vivien Didelotfad09c72016-06-21 12:28:20 -04001101 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001102 return -EOPNOTSUPP;
1103
Vivien Didelotfad09c72016-06-21 12:28:20 -04001104 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001105
Vivien Didelot9c938292016-08-15 17:19:02 -04001106 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1107 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001108 goto out;
1109
Vivien Didelot9c938292016-08-15 17:19:02 -04001110 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001111 if (e->eee_enabled)
1112 reg |= 0x0200;
1113 if (e->tx_lpi_enabled)
1114 reg |= 0x0100;
1115
Vivien Didelot9c938292016-08-15 17:19:02 -04001116 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001117out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001118 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001119
Vivien Didelot9c938292016-08-15 17:19:02 -04001120 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001121}
1122
Vivien Didelotfad09c72016-06-21 12:28:20 -04001123static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001124{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001125 struct dsa_switch *ds = chip->ds;
Vivien Didelotfae8a252017-01-27 15:29:42 -05001126 struct net_device *bridge = ds->ports[port].bridge_dev;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001127 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001128 int i;
1129
1130 /* allow CPU port or DSA link(s) to send frames to every port */
1131 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001132 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001133 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001134 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001135 /* allow sending frames to every group member */
Vivien Didelotfae8a252017-01-27 15:29:42 -05001136 if (bridge && ds->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001137 output_ports |= BIT(i);
1138
1139 /* allow sending frames to CPU port and DSA link(s) */
1140 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1141 output_ports |= BIT(i);
1142 }
1143 }
1144
1145 /* prevent frames from going back out of the port they came in on */
1146 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001147
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001148 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001149}
1150
Vivien Didelotf81ec902016-05-09 13:22:58 -04001151static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1152 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001153{
Vivien Didelot04bed142016-08-31 18:06:13 -04001154 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001155 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001156 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001157
1158 switch (state) {
1159 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001160 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001161 break;
1162 case BR_STATE_BLOCKING:
1163 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001164 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001165 break;
1166 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001167 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001168 break;
1169 case BR_STATE_FORWARDING:
1170 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001171 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001172 break;
1173 }
1174
Vivien Didelotfad09c72016-06-21 12:28:20 -04001175 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001176 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001177 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001178
1179 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001180 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001181}
1182
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001183static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1184{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001185 int err;
1186
Vivien Didelotdaefc942017-03-11 16:12:54 -05001187 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1188 if (err)
1189 return err;
1190
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001191 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1192 if (err)
1193 return err;
1194
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001195 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1196}
1197
Vivien Didelot749efcb2016-09-22 16:49:24 -04001198static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1199{
1200 struct mv88e6xxx_chip *chip = ds->priv;
1201 int err;
1202
1203 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001204 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001205 mutex_unlock(&chip->reg_lock);
1206
1207 if (err)
1208 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1209}
1210
Vivien Didelotfad09c72016-06-21 12:28:20 -04001211static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001212{
Vivien Didelota935c052016-09-29 12:21:53 -04001213 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001214}
1215
Vivien Didelotfad09c72016-06-21 12:28:20 -04001216static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001217{
Vivien Didelota935c052016-09-29 12:21:53 -04001218 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001219
Vivien Didelota935c052016-09-29 12:21:53 -04001220 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1221 if (err)
1222 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001223
Vivien Didelotfad09c72016-06-21 12:28:20 -04001224 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001225}
1226
Vivien Didelotfad09c72016-06-21 12:28:20 -04001227static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001228{
1229 int ret;
1230
Vivien Didelotfad09c72016-06-21 12:28:20 -04001231 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001232 if (ret < 0)
1233 return ret;
1234
Vivien Didelotfad09c72016-06-21 12:28:20 -04001235 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001236}
1237
Vivien Didelotfad09c72016-06-21 12:28:20 -04001238static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001239 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001240 unsigned int nibble_offset)
1241{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001242 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001243 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001244
1245 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001246 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001247
Vivien Didelota935c052016-09-29 12:21:53 -04001248 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1249 if (err)
1250 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001251 }
1252
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001253 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001254 unsigned int shift = (i % 4) * 4 + nibble_offset;
1255 u16 reg = regs[i / 4];
1256
1257 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1258 }
1259
1260 return 0;
1261}
1262
Vivien Didelotfad09c72016-06-21 12:28:20 -04001263static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001264 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001265{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001266 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001267}
1268
Vivien Didelotfad09c72016-06-21 12:28:20 -04001269static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001270 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001271{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001272 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001273}
1274
Vivien Didelotfad09c72016-06-21 12:28:20 -04001275static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001276 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001277 unsigned int nibble_offset)
1278{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001279 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001280 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001281
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001282 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001283 unsigned int shift = (i % 4) * 4 + nibble_offset;
1284 u8 data = entry->data[i];
1285
1286 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1287 }
1288
1289 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001290 u16 reg = regs[i];
1291
1292 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1293 if (err)
1294 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001295 }
1296
1297 return 0;
1298}
1299
Vivien Didelotfad09c72016-06-21 12:28:20 -04001300static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001301 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001302{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001303 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001304}
1305
Vivien Didelotfad09c72016-06-21 12:28:20 -04001306static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001307 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001308{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001309 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001310}
1311
Vivien Didelotfad09c72016-06-21 12:28:20 -04001312static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001313{
Vivien Didelota935c052016-09-29 12:21:53 -04001314 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1315 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001316}
1317
Vivien Didelotfad09c72016-06-21 12:28:20 -04001318static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001319 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001320{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001321 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001322 u16 val;
1323 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001324
Vivien Didelota935c052016-09-29 12:21:53 -04001325 err = _mv88e6xxx_vtu_wait(chip);
1326 if (err)
1327 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001328
Vivien Didelota935c052016-09-29 12:21:53 -04001329 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1330 if (err)
1331 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001332
Vivien Didelota935c052016-09-29 12:21:53 -04001333 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1334 if (err)
1335 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001336
Vivien Didelota935c052016-09-29 12:21:53 -04001337 next.vid = val & GLOBAL_VTU_VID_MASK;
1338 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001339
1340 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001341 err = mv88e6xxx_vtu_data_read(chip, &next);
1342 if (err)
1343 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001344
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001345 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001346 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1347 if (err)
1348 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001349
Vivien Didelota935c052016-09-29 12:21:53 -04001350 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001351 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001352 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1353 * VTU DBNum[3:0] are located in VTU Operation 3:0
1354 */
Vivien Didelota935c052016-09-29 12:21:53 -04001355 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1356 if (err)
1357 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001358
Vivien Didelota935c052016-09-29 12:21:53 -04001359 next.fid = (val & 0xf00) >> 4;
1360 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001361 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001362
Vivien Didelotfad09c72016-06-21 12:28:20 -04001363 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001364 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1365 if (err)
1366 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001367
Vivien Didelota935c052016-09-29 12:21:53 -04001368 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001369 }
1370 }
1371
1372 *entry = next;
1373 return 0;
1374}
1375
Vivien Didelotf81ec902016-05-09 13:22:58 -04001376static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1377 struct switchdev_obj_port_vlan *vlan,
1378 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001379{
Vivien Didelot04bed142016-08-31 18:06:13 -04001380 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001381 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001382 u16 pvid;
1383 int err;
1384
Vivien Didelotfad09c72016-06-21 12:28:20 -04001385 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001386 return -EOPNOTSUPP;
1387
Vivien Didelotfad09c72016-06-21 12:28:20 -04001388 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001389
Vivien Didelot77064f32016-11-04 03:23:30 +01001390 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001391 if (err)
1392 goto unlock;
1393
Vivien Didelotfad09c72016-06-21 12:28:20 -04001394 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001395 if (err)
1396 goto unlock;
1397
1398 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001399 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001400 if (err)
1401 break;
1402
1403 if (!next.valid)
1404 break;
1405
1406 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1407 continue;
1408
1409 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001410 vlan->vid_begin = next.vid;
1411 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001412 vlan->flags = 0;
1413
1414 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1415 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1416
1417 if (next.vid == pvid)
1418 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1419
1420 err = cb(&vlan->obj);
1421 if (err)
1422 break;
1423 } while (next.vid < GLOBAL_VTU_VID_MASK);
1424
1425unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001426 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001427
1428 return err;
1429}
1430
Vivien Didelotfad09c72016-06-21 12:28:20 -04001431static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001432 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001433{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001434 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001435 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001436 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001437
Vivien Didelota935c052016-09-29 12:21:53 -04001438 err = _mv88e6xxx_vtu_wait(chip);
1439 if (err)
1440 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001441
1442 if (!entry->valid)
1443 goto loadpurge;
1444
1445 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001446 err = mv88e6xxx_vtu_data_write(chip, entry);
1447 if (err)
1448 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001449
Vivien Didelotfad09c72016-06-21 12:28:20 -04001450 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001451 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001452 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1453 if (err)
1454 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001455 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001456
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001457 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001458 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001459 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1460 if (err)
1461 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001462 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001463 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1464 * VTU DBNum[3:0] are located in VTU Operation 3:0
1465 */
1466 op |= (entry->fid & 0xf0) << 8;
1467 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001468 }
1469
1470 reg = GLOBAL_VTU_VID_VALID;
1471loadpurge:
1472 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001473 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1474 if (err)
1475 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001476
Vivien Didelotfad09c72016-06-21 12:28:20 -04001477 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001478}
1479
Vivien Didelotfad09c72016-06-21 12:28:20 -04001480static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001481 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001482{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001483 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001484 u16 val;
1485 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001486
Vivien Didelota935c052016-09-29 12:21:53 -04001487 err = _mv88e6xxx_vtu_wait(chip);
1488 if (err)
1489 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001490
Vivien Didelota935c052016-09-29 12:21:53 -04001491 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1492 sid & GLOBAL_VTU_SID_MASK);
1493 if (err)
1494 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001495
Vivien Didelota935c052016-09-29 12:21:53 -04001496 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1497 if (err)
1498 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001499
Vivien Didelota935c052016-09-29 12:21:53 -04001500 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1501 if (err)
1502 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001503
Vivien Didelota935c052016-09-29 12:21:53 -04001504 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001505
Vivien Didelota935c052016-09-29 12:21:53 -04001506 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1507 if (err)
1508 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001509
Vivien Didelota935c052016-09-29 12:21:53 -04001510 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001511
1512 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001513 err = mv88e6xxx_stu_data_read(chip, &next);
1514 if (err)
1515 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001516 }
1517
1518 *entry = next;
1519 return 0;
1520}
1521
Vivien Didelotfad09c72016-06-21 12:28:20 -04001522static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001523 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001524{
1525 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001526 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001527
Vivien Didelota935c052016-09-29 12:21:53 -04001528 err = _mv88e6xxx_vtu_wait(chip);
1529 if (err)
1530 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001531
1532 if (!entry->valid)
1533 goto loadpurge;
1534
1535 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001536 err = mv88e6xxx_stu_data_write(chip, entry);
1537 if (err)
1538 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001539
1540 reg = GLOBAL_VTU_VID_VALID;
1541loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001542 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1543 if (err)
1544 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001545
1546 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001547 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1548 if (err)
1549 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001550
Vivien Didelotfad09c72016-06-21 12:28:20 -04001551 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001552}
1553
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001554static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001555{
1556 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001557 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001558 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001559
1560 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1561
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001562 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001563 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001564 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001565 if (err)
1566 return err;
1567
1568 set_bit(*fid, fid_bitmap);
1569 }
1570
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001571 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001572 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001573 if (err)
1574 return err;
1575
1576 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001577 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001578 if (err)
1579 return err;
1580
1581 if (!vlan.valid)
1582 break;
1583
1584 set_bit(vlan.fid, fid_bitmap);
1585 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1586
1587 /* The reset value 0x000 is used to indicate that multiple address
1588 * databases are not needed. Return the next positive available.
1589 */
1590 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001591 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001592 return -ENOSPC;
1593
1594 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001595 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001596}
1597
Vivien Didelotfad09c72016-06-21 12:28:20 -04001598static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001599 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001600{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001601 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001602 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001603 .valid = true,
1604 .vid = vid,
1605 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001606 int i, err;
1607
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001608 err = mv88e6xxx_atu_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001609 if (err)
1610 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001611
Vivien Didelot3d131f02015-11-03 10:52:52 -05001612 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001613 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001614 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1615 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1616 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001617
Vivien Didelotfad09c72016-06-21 12:28:20 -04001618 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01001619 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip) ||
1620 mv88e6xxx_6341_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001621 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001622
1623 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1624 * implemented, only one STU entry is needed to cover all VTU
1625 * entries. Thus, validate the SID 0.
1626 */
1627 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001628 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001629 if (err)
1630 return err;
1631
1632 if (vstp.sid != vlan.sid || !vstp.valid) {
1633 memset(&vstp, 0, sizeof(vstp));
1634 vstp.valid = true;
1635 vstp.sid = vlan.sid;
1636
Vivien Didelotfad09c72016-06-21 12:28:20 -04001637 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001638 if (err)
1639 return err;
1640 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001641 }
1642
1643 *entry = vlan;
1644 return 0;
1645}
1646
Vivien Didelotfad09c72016-06-21 12:28:20 -04001647static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001648 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001649{
1650 int err;
1651
1652 if (!vid)
1653 return -EINVAL;
1654
Vivien Didelotfad09c72016-06-21 12:28:20 -04001655 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001656 if (err)
1657 return err;
1658
Vivien Didelotfad09c72016-06-21 12:28:20 -04001659 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001660 if (err)
1661 return err;
1662
1663 if (entry->vid != vid || !entry->valid) {
1664 if (!creat)
1665 return -EOPNOTSUPP;
1666 /* -ENOENT would've been more appropriate, but switchdev expects
1667 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1668 */
1669
Vivien Didelotfad09c72016-06-21 12:28:20 -04001670 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001671 }
1672
1673 return err;
1674}
1675
Vivien Didelotda9c3592016-02-12 12:09:40 -05001676static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1677 u16 vid_begin, u16 vid_end)
1678{
Vivien Didelot04bed142016-08-31 18:06:13 -04001679 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001680 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001681 int i, err;
1682
1683 if (!vid_begin)
1684 return -EOPNOTSUPP;
1685
Vivien Didelotfad09c72016-06-21 12:28:20 -04001686 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001687
Vivien Didelotfad09c72016-06-21 12:28:20 -04001688 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001689 if (err)
1690 goto unlock;
1691
1692 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001693 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001694 if (err)
1695 goto unlock;
1696
1697 if (!vlan.valid)
1698 break;
1699
1700 if (vlan.vid > vid_end)
1701 break;
1702
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001703 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001704 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1705 continue;
1706
Andrew Lunn66e28092016-12-11 21:07:19 +01001707 if (!ds->ports[port].netdev)
1708 continue;
1709
Vivien Didelotda9c3592016-02-12 12:09:40 -05001710 if (vlan.data[i] ==
1711 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1712 continue;
1713
Vivien Didelotfae8a252017-01-27 15:29:42 -05001714 if (ds->ports[i].bridge_dev ==
1715 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001716 break; /* same bridge, check next VLAN */
1717
Vivien Didelotfae8a252017-01-27 15:29:42 -05001718 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001719 continue;
1720
Andrew Lunnc8b09802016-06-04 21:16:57 +02001721 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001722 "hardware VLAN %d already used by %s\n",
1723 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001724 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001725 err = -EOPNOTSUPP;
1726 goto unlock;
1727 }
1728 } while (vlan.vid < vid_end);
1729
1730unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001731 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001732
1733 return err;
1734}
1735
Vivien Didelotf81ec902016-05-09 13:22:58 -04001736static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1737 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001738{
Vivien Didelot04bed142016-08-31 18:06:13 -04001739 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001740 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001741 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001742 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001743
Vivien Didelotfad09c72016-06-21 12:28:20 -04001744 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001745 return -EOPNOTSUPP;
1746
Vivien Didelotfad09c72016-06-21 12:28:20 -04001747 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001748 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001749 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001750
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001751 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001752}
1753
Vivien Didelot57d32312016-06-20 13:13:58 -04001754static int
1755mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1756 const struct switchdev_obj_port_vlan *vlan,
1757 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001758{
Vivien Didelot04bed142016-08-31 18:06:13 -04001759 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001760 int err;
1761
Vivien Didelotfad09c72016-06-21 12:28:20 -04001762 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001763 return -EOPNOTSUPP;
1764
Vivien Didelotda9c3592016-02-12 12:09:40 -05001765 /* If the requested port doesn't belong to the same bridge as the VLAN
1766 * members, do not support it (yet) and fallback to software VLAN.
1767 */
1768 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1769 vlan->vid_end);
1770 if (err)
1771 return err;
1772
Vivien Didelot76e398a2015-11-01 12:33:55 -05001773 /* We don't need any dynamic resource from the kernel (yet),
1774 * so skip the prepare phase.
1775 */
1776 return 0;
1777}
1778
Vivien Didelotfad09c72016-06-21 12:28:20 -04001779static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001780 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001781{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001782 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001783 int err;
1784
Vivien Didelotfad09c72016-06-21 12:28:20 -04001785 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001786 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001787 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001788
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001789 vlan.data[port] = untagged ?
1790 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1791 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1792
Vivien Didelotfad09c72016-06-21 12:28:20 -04001793 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001794}
1795
Vivien Didelotf81ec902016-05-09 13:22:58 -04001796static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1797 const struct switchdev_obj_port_vlan *vlan,
1798 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001799{
Vivien Didelot04bed142016-08-31 18:06:13 -04001800 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001801 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1802 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1803 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001804
Vivien Didelotfad09c72016-06-21 12:28:20 -04001805 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001806 return;
1807
Vivien Didelotfad09c72016-06-21 12:28:20 -04001808 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001809
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001810 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001811 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001812 netdev_err(ds->ports[port].netdev,
1813 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001814 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001815
Vivien Didelot77064f32016-11-04 03:23:30 +01001816 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001817 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001818 vlan->vid_end);
1819
Vivien Didelotfad09c72016-06-21 12:28:20 -04001820 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001821}
1822
Vivien Didelotfad09c72016-06-21 12:28:20 -04001823static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001824 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001825{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001826 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001827 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001828 int i, err;
1829
Vivien Didelotfad09c72016-06-21 12:28:20 -04001830 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001831 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001832 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001833
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001834 /* Tell switchdev if this VLAN is handled in software */
1835 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001836 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001837
1838 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1839
1840 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001841 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001842 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001843 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001844 continue;
1845
1846 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001847 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001848 break;
1849 }
1850 }
1851
Vivien Didelotfad09c72016-06-21 12:28:20 -04001852 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001853 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001854 return err;
1855
Vivien Didelote606ca32017-03-11 16:12:55 -05001856 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001857}
1858
Vivien Didelotf81ec902016-05-09 13:22:58 -04001859static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1860 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001861{
Vivien Didelot04bed142016-08-31 18:06:13 -04001862 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001863 u16 pvid, vid;
1864 int err = 0;
1865
Vivien Didelotfad09c72016-06-21 12:28:20 -04001866 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001867 return -EOPNOTSUPP;
1868
Vivien Didelotfad09c72016-06-21 12:28:20 -04001869 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001870
Vivien Didelot77064f32016-11-04 03:23:30 +01001871 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001872 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001873 goto unlock;
1874
Vivien Didelot76e398a2015-11-01 12:33:55 -05001875 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001876 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001877 if (err)
1878 goto unlock;
1879
1880 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001881 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001882 if (err)
1883 goto unlock;
1884 }
1885 }
1886
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001887unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001888 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001889
1890 return err;
1891}
1892
Vivien Didelot83dabd12016-08-31 11:50:04 -04001893static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1894 const unsigned char *addr, u16 vid,
1895 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001896{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001897 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001898 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001899 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001900
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001901 /* Null VLAN ID corresponds to the port private database */
1902 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001903 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001904 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04001905 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001906 if (err)
1907 return err;
1908
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001909 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1910 ether_addr_copy(entry.mac, addr);
1911 eth_addr_dec(entry.mac);
1912
1913 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001914 if (err)
1915 return err;
1916
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001917 /* Initialize a fresh ATU entry if it isn't found */
1918 if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
1919 !ether_addr_equal(entry.mac, addr)) {
1920 memset(&entry, 0, sizeof(entry));
1921 ether_addr_copy(entry.mac, addr);
1922 }
1923
Vivien Didelot88472932016-09-19 19:56:11 -04001924 /* Purge the ATU entry only if no port is using it anymore */
1925 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001926 entry.portvec &= ~BIT(port);
1927 if (!entry.portvec)
Vivien Didelot88472932016-09-19 19:56:11 -04001928 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1929 } else {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001930 entry.portvec |= BIT(port);
Vivien Didelot88472932016-09-19 19:56:11 -04001931 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001932 }
1933
Vivien Didelot9c13c022017-03-11 16:12:52 -05001934 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001935}
1936
Vivien Didelotf81ec902016-05-09 13:22:58 -04001937static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1938 const struct switchdev_obj_port_fdb *fdb,
1939 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001940{
1941 /* We don't need any dynamic resource from the kernel (yet),
1942 * so skip the prepare phase.
1943 */
1944 return 0;
1945}
1946
Vivien Didelotf81ec902016-05-09 13:22:58 -04001947static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1948 const struct switchdev_obj_port_fdb *fdb,
1949 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001950{
Vivien Didelot04bed142016-08-31 18:06:13 -04001951 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04001952
Vivien Didelotfad09c72016-06-21 12:28:20 -04001953 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001954 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1955 GLOBAL_ATU_DATA_STATE_UC_STATIC))
1956 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001957 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001958}
1959
Vivien Didelotf81ec902016-05-09 13:22:58 -04001960static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1961 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07001962{
Vivien Didelot04bed142016-08-31 18:06:13 -04001963 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001964 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001965
Vivien Didelotfad09c72016-06-21 12:28:20 -04001966 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001967 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1968 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001969 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001970
Vivien Didelot83dabd12016-08-31 11:50:04 -04001971 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001972}
1973
Vivien Didelot83dabd12016-08-31 11:50:04 -04001974static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1975 u16 fid, u16 vid, int port,
1976 struct switchdev_obj *obj,
1977 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001978{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001979 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001980 int err;
1981
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001982 addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1983 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001984
1985 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001986 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001987 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001988 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001989
1990 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
1991 break;
1992
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001993 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001994 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001995
Vivien Didelot83dabd12016-08-31 11:50:04 -04001996 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
1997 struct switchdev_obj_port_fdb *fdb;
1998
1999 if (!is_unicast_ether_addr(addr.mac))
2000 continue;
2001
2002 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002003 fdb->vid = vid;
2004 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002005 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2006 fdb->ndm_state = NUD_NOARP;
2007 else
2008 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002009 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2010 struct switchdev_obj_port_mdb *mdb;
2011
2012 if (!is_multicast_ether_addr(addr.mac))
2013 continue;
2014
2015 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2016 mdb->vid = vid;
2017 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002018 } else {
2019 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002020 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002021
2022 err = cb(obj);
2023 if (err)
2024 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002025 } while (!is_broadcast_ether_addr(addr.mac));
2026
2027 return err;
2028}
2029
Vivien Didelot83dabd12016-08-31 11:50:04 -04002030static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2031 struct switchdev_obj *obj,
2032 int (*cb)(struct switchdev_obj *obj))
2033{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002034 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002035 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2036 };
2037 u16 fid;
2038 int err;
2039
2040 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002041 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002042 if (err)
2043 return err;
2044
2045 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2046 if (err)
2047 return err;
2048
2049 /* Dump VLANs' Filtering Information Databases */
2050 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2051 if (err)
2052 return err;
2053
2054 do {
2055 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2056 if (err)
2057 return err;
2058
2059 if (!vlan.valid)
2060 break;
2061
2062 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2063 obj, cb);
2064 if (err)
2065 return err;
2066 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2067
2068 return err;
2069}
2070
Vivien Didelotf81ec902016-05-09 13:22:58 -04002071static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2072 struct switchdev_obj_port_fdb *fdb,
2073 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002074{
Vivien Didelot04bed142016-08-31 18:06:13 -04002075 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002076 int err;
2077
Vivien Didelotfad09c72016-06-21 12:28:20 -04002078 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002079 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002080 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002081
2082 return err;
2083}
2084
Vivien Didelotf81ec902016-05-09 13:22:58 -04002085static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002086 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002087{
Vivien Didelot04bed142016-08-31 18:06:13 -04002088 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002089 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002090
Vivien Didelotfad09c72016-06-21 12:28:20 -04002091 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002092
Vivien Didelotfae8a252017-01-27 15:29:42 -05002093 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002094 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfae8a252017-01-27 15:29:42 -05002095 if (ds->ports[i].bridge_dev == br) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002096 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002097 if (err)
2098 break;
2099 }
2100 }
2101
Vivien Didelotfad09c72016-06-21 12:28:20 -04002102 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002103
Vivien Didelot466dfa02016-02-26 13:16:05 -05002104 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002105}
2106
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002107static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2108 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002109{
Vivien Didelot04bed142016-08-31 18:06:13 -04002110 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002111 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002112
Vivien Didelotfad09c72016-06-21 12:28:20 -04002113 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002114
Vivien Didelotfae8a252017-01-27 15:29:42 -05002115 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002116 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfae8a252017-01-27 15:29:42 -05002117 if (i == port || ds->ports[i].bridge_dev == br)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002118 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002119 netdev_warn(ds->ports[i].netdev,
2120 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002121
Vivien Didelotfad09c72016-06-21 12:28:20 -04002122 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002123}
2124
Vivien Didelot17e708b2016-12-05 17:30:27 -05002125static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2126{
2127 if (chip->info->ops->reset)
2128 return chip->info->ops->reset(chip);
2129
2130 return 0;
2131}
2132
Vivien Didelot309eca62016-12-05 17:30:26 -05002133static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2134{
2135 struct gpio_desc *gpiod = chip->reset;
2136
2137 /* If there is a GPIO connected to the reset pin, toggle it */
2138 if (gpiod) {
2139 gpiod_set_value_cansleep(gpiod, 1);
2140 usleep_range(10000, 20000);
2141 gpiod_set_value_cansleep(gpiod, 0);
2142 usleep_range(10000, 20000);
2143 }
2144}
2145
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002146static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2147{
2148 int i, err;
2149
2150 /* Set all ports to the Disabled state */
2151 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2152 err = mv88e6xxx_port_set_state(chip, i,
2153 PORT_CONTROL_STATE_DISABLED);
2154 if (err)
2155 return err;
2156 }
2157
2158 /* Wait for transmit queues to drain,
2159 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2160 */
2161 usleep_range(2000, 4000);
2162
2163 return 0;
2164}
2165
Vivien Didelotfad09c72016-06-21 12:28:20 -04002166static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002167{
Vivien Didelota935c052016-09-29 12:21:53 -04002168 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002169
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002170 err = mv88e6xxx_disable_ports(chip);
2171 if (err)
2172 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002173
Vivien Didelot309eca62016-12-05 17:30:26 -05002174 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002175
Vivien Didelot17e708b2016-12-05 17:30:27 -05002176 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002177}
2178
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002179static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002180{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002181 u16 val;
2182 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002183
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002184 /* Clear Power Down bit */
2185 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2186 if (err)
2187 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002188
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002189 if (val & BMCR_PDOWN) {
2190 val &= ~BMCR_PDOWN;
2191 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002192 }
2193
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002194 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002195}
2196
Vivien Didelot43145572017-03-11 16:12:59 -05002197static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2198 enum mv88e6xxx_frame_mode frame, u16 egress,
2199 u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002200{
2201 int err;
2202
Vivien Didelot43145572017-03-11 16:12:59 -05002203 if (!chip->info->ops->port_set_frame_mode)
2204 return -EOPNOTSUPP;
2205
2206 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002207 if (err)
2208 return err;
2209
Vivien Didelot43145572017-03-11 16:12:59 -05002210 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2211 if (err)
2212 return err;
2213
2214 if (chip->info->ops->port_set_ether_type)
2215 return chip->info->ops->port_set_ether_type(chip, port, etype);
2216
2217 return 0;
2218}
2219
2220static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2221{
2222 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2223 PORT_CONTROL_EGRESS_UNMODIFIED,
2224 PORT_ETH_TYPE_DEFAULT);
2225}
2226
2227static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2228{
2229 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2230 PORT_CONTROL_EGRESS_UNMODIFIED,
2231 PORT_ETH_TYPE_DEFAULT);
2232}
2233
2234static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2235{
2236 return mv88e6xxx_set_port_mode(chip, port,
2237 MV88E6XXX_FRAME_MODE_ETHERTYPE,
2238 PORT_CONTROL_EGRESS_ADD_TAG, ETH_P_EDSA);
2239}
2240
2241static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2242{
2243 if (dsa_is_dsa_port(chip->ds, port))
2244 return mv88e6xxx_set_port_mode_dsa(chip, port);
2245
2246 if (dsa_is_normal_port(chip->ds, port))
2247 return mv88e6xxx_set_port_mode_normal(chip, port);
2248
2249 /* Setup CPU port mode depending on its supported tag format */
2250 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2251 return mv88e6xxx_set_port_mode_dsa(chip, port);
2252
2253 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2254 return mv88e6xxx_set_port_mode_edsa(chip, port);
2255
2256 return -EINVAL;
2257}
2258
Vivien Didelotea698f42017-03-11 16:12:50 -05002259static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2260{
2261 bool message = dsa_is_dsa_port(chip->ds, port);
2262
2263 return mv88e6xxx_port_set_message_port(chip, port, message);
2264}
2265
Vivien Didelot601aeed2017-03-11 16:13:00 -05002266static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2267{
2268 bool flood = port == dsa_upstream_port(chip->ds);
2269
2270 /* Upstream ports flood frames with unknown unicast or multicast DA */
2271 if (chip->info->ops->port_set_egress_floods)
2272 return chip->info->ops->port_set_egress_floods(chip, port,
2273 flood, flood);
2274
2275 return 0;
2276}
2277
Vivien Didelotfad09c72016-06-21 12:28:20 -04002278static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002279{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002280 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002281 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002282 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002283
Vivien Didelotd78343d2016-11-04 03:23:36 +01002284 /* MAC Forcing register: don't force link, speed, duplex or flow control
2285 * state to any particular values on physical ports, but force the CPU
2286 * port and all DSA ports to their maximum bandwidth and full duplex.
2287 */
2288 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2289 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2290 SPEED_MAX, DUPLEX_FULL,
2291 PHY_INTERFACE_MODE_NA);
2292 else
2293 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2294 SPEED_UNFORCED, DUPLEX_UNFORCED,
2295 PHY_INTERFACE_MODE_NA);
2296 if (err)
2297 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002298
2299 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2300 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2301 * tunneling, determine priority by looking at 802.1p and IP
2302 * priority fields (IP prio has precedence), and set STP state
2303 * to Forwarding.
2304 *
2305 * If this is the CPU link, use DSA or EDSA tagging depending
2306 * on which tagging mode was configured.
2307 *
2308 * If this is a link to another switch, use DSA tagging mode.
2309 *
2310 * If this is the upstream port for this switch, enable
2311 * forwarding of unknown unicasts and multicasts.
2312 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002313 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002314 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2315 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002316 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2317 if (err)
2318 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002319
Vivien Didelot601aeed2017-03-11 16:13:00 -05002320 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002321 if (err)
2322 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002323
Vivien Didelot601aeed2017-03-11 16:13:00 -05002324 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002325 if (err)
2326 return err;
2327
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002328 /* If this port is connected to a SerDes, make sure the SerDes is not
2329 * powered down.
2330 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002331 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002332 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2333 if (err)
2334 return err;
2335 reg &= PORT_STATUS_CMODE_MASK;
2336 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2337 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2338 (reg == PORT_STATUS_CMODE_SGMII)) {
2339 err = mv88e6xxx_serdes_power_on(chip);
2340 if (err < 0)
2341 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002342 }
2343 }
2344
Vivien Didelot8efdda42015-08-13 12:52:23 -04002345 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002346 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002347 * untagged frames on this port, do a destination address lookup on all
2348 * received packets as usual, disable ARP mirroring and don't send a
2349 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002350 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002351 err = mv88e6xxx_port_set_map_da(chip, port);
2352 if (err)
2353 return err;
2354
Andrew Lunn54d792f2015-05-06 01:09:47 +02002355 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01002356 if (chip->info->ops->port_set_upstream_port) {
2357 err = chip->info->ops->port_set_upstream_port(
2358 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002359 if (err)
2360 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002361 }
2362
Andrew Lunna23b2962017-02-04 20:15:28 +01002363 err = mv88e6xxx_port_set_8021q_mode(chip, port,
2364 PORT_CONTROL_2_8021Q_DISABLED);
2365 if (err)
2366 return err;
2367
Andrew Lunn5f436662016-12-03 04:45:17 +01002368 if (chip->info->ops->port_jumbo_config) {
2369 err = chip->info->ops->port_jumbo_config(chip, port);
2370 if (err)
2371 return err;
2372 }
2373
Andrew Lunn54d792f2015-05-06 01:09:47 +02002374 /* Port Association Vector: when learning source addresses
2375 * of packets, add the address to the address database using
2376 * a port bitmap that has only the bit for this port set and
2377 * the other bits clear.
2378 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002379 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002380 /* Disable learning for CPU port */
2381 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002382 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002383
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002384 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2385 if (err)
2386 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002387
2388 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002389 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2390 if (err)
2391 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002392
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002393 if (chip->info->ops->port_pause_config) {
2394 err = chip->info->ops->port_pause_config(chip, port);
2395 if (err)
2396 return err;
2397 }
2398
Vivien Didelotc8c94892017-03-11 16:13:01 -05002399 if (chip->info->ops->port_disable_learn_limit) {
2400 err = chip->info->ops->port_disable_learn_limit(chip, port);
2401 if (err)
2402 return err;
2403 }
2404
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002405 if (chip->info->ops->port_disable_pri_override) {
2406 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002407 if (err)
2408 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002409 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002410
Andrew Lunnef0a7312016-12-03 04:35:16 +01002411 if (chip->info->ops->port_tag_remap) {
2412 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002413 if (err)
2414 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002415 }
2416
Andrew Lunnef70b112016-12-03 04:45:18 +01002417 if (chip->info->ops->port_egress_rate_limiting) {
2418 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002419 if (err)
2420 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002421 }
2422
Vivien Didelotea698f42017-03-11 16:12:50 -05002423 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002424 if (err)
2425 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002426
Vivien Didelot207afda2016-04-14 14:42:09 -04002427 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002428 * database, and allow bidirectional communication between the
2429 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002430 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002431 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002432 if (err)
2433 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002434
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002435 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2436 if (err)
2437 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002438
2439 /* Default VLAN ID and priority: don't set a default VLAN
2440 * ID, and set the default packet priority to zero.
2441 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002442 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002443}
2444
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002445static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002446{
2447 int err;
2448
Vivien Didelota935c052016-09-29 12:21:53 -04002449 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002450 if (err)
2451 return err;
2452
Vivien Didelota935c052016-09-29 12:21:53 -04002453 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002454 if (err)
2455 return err;
2456
Vivien Didelota935c052016-09-29 12:21:53 -04002457 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2458 if (err)
2459 return err;
2460
2461 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002462}
2463
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002464static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2465 unsigned int ageing_time)
2466{
Vivien Didelot04bed142016-08-31 18:06:13 -04002467 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002468 int err;
2469
2470 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002471 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002472 mutex_unlock(&chip->reg_lock);
2473
2474 return err;
2475}
2476
Vivien Didelot97299342016-07-18 20:45:30 -04002477static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002478{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002479 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002480 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002481 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002482
Vivien Didelot119477b2016-05-09 13:22:51 -04002483 /* Enable the PHY Polling Unit if present, don't discard any packets,
2484 * and mask all interrupt sources.
2485 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002486 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002487 if (err)
2488 return err;
2489
Andrew Lunn33641992016-12-03 04:35:17 +01002490 if (chip->info->ops->g1_set_cpu_port) {
2491 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2492 if (err)
2493 return err;
2494 }
2495
2496 if (chip->info->ops->g1_set_egress_port) {
2497 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2498 if (err)
2499 return err;
2500 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002501
Vivien Didelot50484ff2016-05-09 13:22:54 -04002502 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002503 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2504 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2505 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002506 if (err)
2507 return err;
2508
Vivien Didelotacddbd22016-07-18 20:45:39 -04002509 /* Clear all the VTU and STU entries */
2510 err = _mv88e6xxx_vtu_stu_flush(chip);
2511 if (err < 0)
2512 return err;
2513
Vivien Didelot08a01262016-05-09 13:22:50 -04002514 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002515 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002516 if (err)
2517 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002518 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002519 if (err)
2520 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002521 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002522 if (err)
2523 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002524 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002525 if (err)
2526 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002527 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002528 if (err)
2529 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002530 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002531 if (err)
2532 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002533 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002534 if (err)
2535 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002536 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002537 if (err)
2538 return err;
2539
2540 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002541 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002542 if (err)
2543 return err;
2544
Andrew Lunnde2273872016-11-21 23:27:01 +01002545 /* Initialize the statistics unit */
2546 err = mv88e6xxx_stats_set_histogram(chip);
2547 if (err)
2548 return err;
2549
Vivien Didelot97299342016-07-18 20:45:30 -04002550 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002551 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2552 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002553 if (err)
2554 return err;
2555
2556 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002557 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002558 if (err)
2559 return err;
2560
2561 return 0;
2562}
2563
Vivien Didelotf81ec902016-05-09 13:22:58 -04002564static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002565{
Vivien Didelot04bed142016-08-31 18:06:13 -04002566 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002567 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002568 int i;
2569
Vivien Didelotfad09c72016-06-21 12:28:20 -04002570 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002571 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002572
Vivien Didelotfad09c72016-06-21 12:28:20 -04002573 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002574
Vivien Didelot97299342016-07-18 20:45:30 -04002575 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002576 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002577 err = mv88e6xxx_setup_port(chip, i);
2578 if (err)
2579 goto unlock;
2580 }
2581
2582 /* Setup Switch Global 1 Registers */
2583 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002584 if (err)
2585 goto unlock;
2586
Vivien Didelot97299342016-07-18 20:45:30 -04002587 /* Setup Switch Global 2 Registers */
2588 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2589 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002590 if (err)
2591 goto unlock;
2592 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002593
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002594 err = mv88e6xxx_atu_setup(chip);
2595 if (err)
2596 goto unlock;
2597
Andrew Lunn6e55f692016-12-03 04:45:16 +01002598 /* Some generations have the configuration of sending reserved
2599 * management frames to the CPU in global2, others in
2600 * global1. Hence it does not fit the two setup functions
2601 * above.
2602 */
2603 if (chip->info->ops->mgmt_rsvd2cpu) {
2604 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2605 if (err)
2606 goto unlock;
2607 }
2608
Vivien Didelot6b17e862015-08-13 12:52:18 -04002609unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002610 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002611
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002612 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002613}
2614
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002615static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2616{
Vivien Didelot04bed142016-08-31 18:06:13 -04002617 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002618 int err;
2619
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002620 if (!chip->info->ops->set_switch_mac)
2621 return -EOPNOTSUPP;
2622
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002623 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002624 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002625 mutex_unlock(&chip->reg_lock);
2626
2627 return err;
2628}
2629
Vivien Didelote57e5e72016-08-15 17:19:00 -04002630static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002631{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002632 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2633 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002634 u16 val;
2635 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002636
Andrew Lunnee26a222017-01-24 14:53:48 +01002637 if (!chip->info->ops->phy_read)
2638 return -EOPNOTSUPP;
2639
Vivien Didelotfad09c72016-06-21 12:28:20 -04002640 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002641 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002642 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002643
Andrew Lunnda9f3302017-02-01 03:40:05 +01002644 if (reg == MII_PHYSID2) {
2645 /* Some internal PHYS don't have a model number. Use
2646 * the mv88e6390 family model number instead.
2647 */
2648 if (!(val & 0x3f0))
2649 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2650 }
2651
Vivien Didelote57e5e72016-08-15 17:19:00 -04002652 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002653}
2654
Vivien Didelote57e5e72016-08-15 17:19:00 -04002655static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002656{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002657 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2658 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002659 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002660
Andrew Lunnee26a222017-01-24 14:53:48 +01002661 if (!chip->info->ops->phy_write)
2662 return -EOPNOTSUPP;
2663
Vivien Didelotfad09c72016-06-21 12:28:20 -04002664 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002665 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002666 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002667
2668 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002669}
2670
Vivien Didelotfad09c72016-06-21 12:28:20 -04002671static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002672 struct device_node *np,
2673 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002674{
2675 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002676 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002677 struct mii_bus *bus;
2678 int err;
2679
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002680 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002681 if (!bus)
2682 return -ENOMEM;
2683
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002684 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002685 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002686 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002687 INIT_LIST_HEAD(&mdio_bus->list);
2688 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002689
Andrew Lunnb516d452016-06-04 21:17:06 +02002690 if (np) {
2691 bus->name = np->full_name;
2692 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2693 } else {
2694 bus->name = "mv88e6xxx SMI";
2695 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2696 }
2697
2698 bus->read = mv88e6xxx_mdio_read;
2699 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002700 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002701
Andrew Lunna3c53be52017-01-24 14:53:50 +01002702 if (np)
2703 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002704 else
2705 err = mdiobus_register(bus);
2706 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002707 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002708 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002709 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002710
2711 if (external)
2712 list_add_tail(&mdio_bus->list, &chip->mdios);
2713 else
2714 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002715
2716 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002717}
2718
Andrew Lunna3c53be52017-01-24 14:53:50 +01002719static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2720 { .compatible = "marvell,mv88e6xxx-mdio-external",
2721 .data = (void *)true },
2722 { },
2723};
2724
2725static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2726 struct device_node *np)
2727{
2728 const struct of_device_id *match;
2729 struct device_node *child;
2730 int err;
2731
2732 /* Always register one mdio bus for the internal/default mdio
2733 * bus. This maybe represented in the device tree, but is
2734 * optional.
2735 */
2736 child = of_get_child_by_name(np, "mdio");
2737 err = mv88e6xxx_mdio_register(chip, child, false);
2738 if (err)
2739 return err;
2740
2741 /* Walk the device tree, and see if there are any other nodes
2742 * which say they are compatible with the external mdio
2743 * bus.
2744 */
2745 for_each_available_child_of_node(np, child) {
2746 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2747 if (match) {
2748 err = mv88e6xxx_mdio_register(chip, child, true);
2749 if (err)
2750 return err;
2751 }
2752 }
2753
2754 return 0;
2755}
2756
2757static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002758
2759{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002760 struct mv88e6xxx_mdio_bus *mdio_bus;
2761 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002762
Andrew Lunna3c53be52017-01-24 14:53:50 +01002763 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2764 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002765
Andrew Lunna3c53be52017-01-24 14:53:50 +01002766 mdiobus_unregister(bus);
2767 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002768}
2769
Vivien Didelot855b1932016-07-20 18:18:35 -04002770static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2771{
Vivien Didelot04bed142016-08-31 18:06:13 -04002772 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002773
2774 return chip->eeprom_len;
2775}
2776
Vivien Didelot855b1932016-07-20 18:18:35 -04002777static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2778 struct ethtool_eeprom *eeprom, u8 *data)
2779{
Vivien Didelot04bed142016-08-31 18:06:13 -04002780 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002781 int err;
2782
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002783 if (!chip->info->ops->get_eeprom)
2784 return -EOPNOTSUPP;
2785
Vivien Didelot855b1932016-07-20 18:18:35 -04002786 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002787 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002788 mutex_unlock(&chip->reg_lock);
2789
2790 if (err)
2791 return err;
2792
2793 eeprom->magic = 0xc3ec4951;
2794
2795 return 0;
2796}
2797
Vivien Didelot855b1932016-07-20 18:18:35 -04002798static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2799 struct ethtool_eeprom *eeprom, u8 *data)
2800{
Vivien Didelot04bed142016-08-31 18:06:13 -04002801 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002802 int err;
2803
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002804 if (!chip->info->ops->set_eeprom)
2805 return -EOPNOTSUPP;
2806
Vivien Didelot855b1932016-07-20 18:18:35 -04002807 if (eeprom->magic != 0xc3ec4951)
2808 return -EINVAL;
2809
2810 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002811 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002812 mutex_unlock(&chip->reg_lock);
2813
2814 return err;
2815}
2816
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002817static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002818 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002819 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002820 .phy_read = mv88e6xxx_phy_ppu_read,
2821 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002822 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002823 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002824 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002825 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002826 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002827 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002828 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002829 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002830 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002831 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002832 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002833 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002834 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2835 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002836 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002837 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2838 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002839 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002840 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002841 .ppu_enable = mv88e6185_g1_ppu_enable,
2842 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002843 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002844};
2845
2846static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002847 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002848 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002849 .phy_read = mv88e6xxx_phy_ppu_read,
2850 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002851 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002852 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002853 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002854 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002855 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002856 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002857 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002858 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2859 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002860 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002861 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002862 .ppu_enable = mv88e6185_g1_ppu_enable,
2863 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002864 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002865};
2866
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002867static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002868 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002869 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2870 .phy_read = mv88e6xxx_g2_smi_phy_read,
2871 .phy_write = mv88e6xxx_g2_smi_phy_write,
2872 .port_set_link = mv88e6xxx_port_set_link,
2873 .port_set_duplex = mv88e6xxx_port_set_duplex,
2874 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002875 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002876 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002877 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002878 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002879 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002880 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002881 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002882 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002883 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002884 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2885 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2886 .stats_get_strings = mv88e6095_stats_get_strings,
2887 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002888 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2889 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002890 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002891 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002892 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002893};
2894
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002895static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002896 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002897 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002898 .phy_read = mv88e6165_phy_read,
2899 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002900 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002901 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002902 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002903 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002904 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002905 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002906 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002907 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002908 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2909 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002910 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002911 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2912 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002913 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002914 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002915 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002916};
2917
2918static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002919 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002920 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002921 .phy_read = mv88e6xxx_phy_ppu_read,
2922 .phy_write = mv88e6xxx_phy_ppu_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 Didelot96a2b402016-11-04 03:23:35 +01002925 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002926 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002927 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002928 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002929 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002930 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
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,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002934 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002935 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2936 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002937 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002938 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2939 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002940 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002941 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002942 .ppu_enable = mv88e6185_g1_ppu_enable,
2943 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002944 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002945};
2946
Vivien Didelot990e27b2017-03-28 13:50:32 -04002947static const struct mv88e6xxx_ops mv88e6141_ops = {
2948 /* MV88E6XXX_FAMILY_6341 */
2949 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2950 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2951 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2952 .phy_read = mv88e6xxx_g2_smi_phy_read,
2953 .phy_write = mv88e6xxx_g2_smi_phy_write,
2954 .port_set_link = mv88e6xxx_port_set_link,
2955 .port_set_duplex = mv88e6xxx_port_set_duplex,
2956 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2957 .port_set_speed = mv88e6390_port_set_speed,
2958 .port_tag_remap = mv88e6095_port_tag_remap,
2959 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2960 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2961 .port_set_ether_type = mv88e6351_port_set_ether_type,
2962 .port_jumbo_config = mv88e6165_port_jumbo_config,
2963 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2964 .port_pause_config = mv88e6097_port_pause_config,
2965 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2966 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2967 .stats_snapshot = mv88e6390_g1_stats_snapshot,
2968 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2969 .stats_get_strings = mv88e6320_stats_get_strings,
2970 .stats_get_stats = mv88e6390_stats_get_stats,
2971 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2972 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
2973 .watchdog_ops = &mv88e6390_watchdog_ops,
2974 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2975 .reset = mv88e6352_g1_reset,
2976};
2977
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002978static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002979 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002980 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002981 .phy_read = mv88e6165_phy_read,
2982 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002983 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002984 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002985 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002986 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002987 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002988 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002989 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002990 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002991 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002992 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002993 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002994 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002995 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002996 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2997 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002998 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002999 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3000 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003001 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003002 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003003 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003004};
3005
3006static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003007 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003008 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003009 .phy_read = mv88e6165_phy_read,
3010 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003011 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003012 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003013 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003014 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003015 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003016 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003017 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3018 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003019 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003020 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3021 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003022 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003023 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003024 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003025};
3026
3027static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003028 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003029 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003030 .phy_read = mv88e6xxx_g2_smi_phy_read,
3031 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003032 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003033 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003034 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003035 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003036 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003037 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003038 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003039 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003040 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003041 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003042 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003043 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003044 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003045 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003046 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3047 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003048 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003049 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3050 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003051 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003052 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003053 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003054};
3055
3056static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003057 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003058 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3059 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003060 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003061 .phy_read = mv88e6xxx_g2_smi_phy_read,
3062 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003063 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003064 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003065 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003066 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003067 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003068 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003069 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003070 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003071 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003072 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003073 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003074 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003075 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003076 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003077 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3078 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003079 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003080 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3081 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003082 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003083 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003084 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003085};
3086
3087static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003088 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003089 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003090 .phy_read = mv88e6xxx_g2_smi_phy_read,
3091 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003092 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003093 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003094 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003095 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003096 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003097 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003098 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003099 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003100 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003101 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003102 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003103 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003104 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003105 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003106 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3107 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003108 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003109 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3110 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003111 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003112 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003113 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003114};
3115
3116static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003117 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003118 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3119 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003120 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003121 .phy_read = mv88e6xxx_g2_smi_phy_read,
3122 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003123 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003124 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003125 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003126 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003127 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003128 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003129 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003130 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003131 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003132 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003133 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003134 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003135 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003136 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003137 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3138 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003139 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003140 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3141 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003142 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003143 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003144 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003145};
3146
3147static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003148 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003149 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003150 .phy_read = mv88e6xxx_phy_ppu_read,
3151 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003152 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003153 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003154 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003155 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003156 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003157 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003158 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003159 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003160 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3161 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003162 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003163 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3164 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003165 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003166 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003167 .ppu_enable = mv88e6185_g1_ppu_enable,
3168 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003169 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003170};
3171
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003172static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003173 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003174 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3175 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003176 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3177 .phy_read = mv88e6xxx_g2_smi_phy_read,
3178 .phy_write = mv88e6xxx_g2_smi_phy_write,
3179 .port_set_link = mv88e6xxx_port_set_link,
3180 .port_set_duplex = mv88e6xxx_port_set_duplex,
3181 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3182 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003183 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003184 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003185 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003186 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003187 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003188 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003189 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003190 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003191 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003192 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3193 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003194 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003195 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3196 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003197 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003198 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003199 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003200};
3201
3202static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003203 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003204 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3205 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003206 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3207 .phy_read = mv88e6xxx_g2_smi_phy_read,
3208 .phy_write = mv88e6xxx_g2_smi_phy_write,
3209 .port_set_link = mv88e6xxx_port_set_link,
3210 .port_set_duplex = mv88e6xxx_port_set_duplex,
3211 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3212 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003213 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003214 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003215 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003216 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003217 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003218 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003219 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003220 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003221 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003222 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3223 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003224 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003225 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3226 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003227 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003228 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003229 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003230};
3231
3232static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003233 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003234 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3235 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003236 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3237 .phy_read = mv88e6xxx_g2_smi_phy_read,
3238 .phy_write = mv88e6xxx_g2_smi_phy_write,
3239 .port_set_link = mv88e6xxx_port_set_link,
3240 .port_set_duplex = mv88e6xxx_port_set_duplex,
3241 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3242 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003243 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003244 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003245 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003246 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003247 .port_pause_config = mv88e6390_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 Lunn79523472016-11-21 23:27:00 +01003250 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003251 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003252 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3253 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003254 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003255 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3256 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003257 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003258 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003259 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003260};
3261
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003262static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003263 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003264 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3265 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003266 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003267 .phy_read = mv88e6xxx_g2_smi_phy_read,
3268 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003269 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003270 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003271 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003272 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003273 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003274 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003275 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003276 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003277 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003278 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003279 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003280 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003281 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003282 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003283 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3284 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003285 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003286 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3287 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003288 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003289 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003290 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003291};
3292
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003293static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003294 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003295 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3296 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003297 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3298 .phy_read = mv88e6xxx_g2_smi_phy_read,
3299 .phy_write = mv88e6xxx_g2_smi_phy_write,
3300 .port_set_link = mv88e6xxx_port_set_link,
3301 .port_set_duplex = mv88e6xxx_port_set_duplex,
3302 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3303 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003304 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003305 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003306 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003307 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003308 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003309 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003310 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003311 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003312 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003313 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003314 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3315 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003316 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003317 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3318 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003319 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003320 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003321 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003322};
3323
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003324static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003325 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003326 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3327 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003328 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003329 .phy_read = mv88e6xxx_g2_smi_phy_read,
3330 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003331 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003332 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003333 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003334 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003335 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003336 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003337 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003338 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003339 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003340 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003341 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003342 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003343 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003344 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3345 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003346 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003347 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3348 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003349 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003350 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003351};
3352
3353static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003354 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003355 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3356 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003357 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003358 .phy_read = mv88e6xxx_g2_smi_phy_read,
3359 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003360 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003361 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003362 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003363 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003364 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003365 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003366 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003367 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003368 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003369 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003370 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003371 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003372 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003373 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3374 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003375 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003376 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3377 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003378 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003379};
3380
Vivien Didelot16e329a2017-03-28 13:50:33 -04003381static const struct mv88e6xxx_ops mv88e6341_ops = {
3382 /* MV88E6XXX_FAMILY_6341 */
3383 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3384 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3385 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3386 .phy_read = mv88e6xxx_g2_smi_phy_read,
3387 .phy_write = mv88e6xxx_g2_smi_phy_write,
3388 .port_set_link = mv88e6xxx_port_set_link,
3389 .port_set_duplex = mv88e6xxx_port_set_duplex,
3390 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3391 .port_set_speed = mv88e6390_port_set_speed,
3392 .port_tag_remap = mv88e6095_port_tag_remap,
3393 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3394 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3395 .port_set_ether_type = mv88e6351_port_set_ether_type,
3396 .port_jumbo_config = mv88e6165_port_jumbo_config,
3397 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3398 .port_pause_config = mv88e6097_port_pause_config,
3399 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3400 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3401 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3402 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3403 .stats_get_strings = mv88e6320_stats_get_strings,
3404 .stats_get_stats = mv88e6390_stats_get_stats,
3405 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3406 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3407 .watchdog_ops = &mv88e6390_watchdog_ops,
3408 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3409 .reset = mv88e6352_g1_reset,
3410};
3411
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003412static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003413 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003414 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003415 .phy_read = mv88e6xxx_g2_smi_phy_read,
3416 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003417 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003418 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003419 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003420 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003421 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003422 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003423 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003424 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003425 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003426 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003427 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003428 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003429 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003430 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003431 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3432 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003433 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003434 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3435 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003436 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003437 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003438 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003439};
3440
3441static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003442 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003443 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003444 .phy_read = mv88e6xxx_g2_smi_phy_read,
3445 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003446 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003447 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003448 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003449 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003450 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003451 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003452 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003453 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003454 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003455 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003456 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003457 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003458 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003459 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003460 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3461 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003462 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003463 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3464 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003465 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003466 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003467 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003468};
3469
3470static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003471 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003472 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3473 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003474 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003475 .phy_read = mv88e6xxx_g2_smi_phy_read,
3476 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003477 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003478 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003479 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003480 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003481 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003482 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003483 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003484 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003485 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003486 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003487 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003488 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003489 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003490 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003491 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3492 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003493 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003494 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3495 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003496 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003497 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003498 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003499};
3500
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003501static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003502 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003503 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3504 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003505 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3506 .phy_read = mv88e6xxx_g2_smi_phy_read,
3507 .phy_write = mv88e6xxx_g2_smi_phy_write,
3508 .port_set_link = mv88e6xxx_port_set_link,
3509 .port_set_duplex = mv88e6xxx_port_set_duplex,
3510 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3511 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003512 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003513 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003514 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003515 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003516 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003517 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003518 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003519 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003520 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003521 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003522 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003523 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003524 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3525 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003526 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003527 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3528 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003529 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003530 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003531 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003532};
3533
3534static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003535 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003536 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3537 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003538 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3539 .phy_read = mv88e6xxx_g2_smi_phy_read,
3540 .phy_write = mv88e6xxx_g2_smi_phy_write,
3541 .port_set_link = mv88e6xxx_port_set_link,
3542 .port_set_duplex = mv88e6xxx_port_set_duplex,
3543 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3544 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003545 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003546 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003547 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003548 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003549 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003550 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003551 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003552 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003553 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003554 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003555 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003556 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3557 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003558 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003559 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3560 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003561 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003562 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003563 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003564};
3565
3566static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003567 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003568 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3569 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003570 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3571 .phy_read = mv88e6xxx_g2_smi_phy_read,
3572 .phy_write = mv88e6xxx_g2_smi_phy_write,
3573 .port_set_link = mv88e6xxx_port_set_link,
3574 .port_set_duplex = mv88e6xxx_port_set_duplex,
3575 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3576 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003577 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003578 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003579 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003580 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003581 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003582 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003583 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003584 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003585 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003586 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3587 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003588 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003589 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3590 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003591 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003592 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003593 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003594};
3595
Vivien Didelotf81ec902016-05-09 13:22:58 -04003596static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3597 [MV88E6085] = {
3598 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3599 .family = MV88E6XXX_FAMILY_6097,
3600 .name = "Marvell 88E6085",
3601 .num_databases = 4096,
3602 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003603 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003604 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003605 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003606 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003607 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003608 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003609 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003610 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003611 },
3612
3613 [MV88E6095] = {
3614 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3615 .family = MV88E6XXX_FAMILY_6095,
3616 .name = "Marvell 88E6095/88E6095F",
3617 .num_databases = 256,
3618 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003619 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003620 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003621 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003622 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003623 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003624 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003625 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003626 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003627 },
3628
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003629 [MV88E6097] = {
3630 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3631 .family = MV88E6XXX_FAMILY_6097,
3632 .name = "Marvell 88E6097/88E6097F",
3633 .num_databases = 4096,
3634 .num_ports = 11,
3635 .port_base_addr = 0x10,
3636 .global1_addr = 0x1b,
3637 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003638 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003639 .atu_move_port_mask = 0xf,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003640 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003641 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3642 .ops = &mv88e6097_ops,
3643 },
3644
Vivien Didelotf81ec902016-05-09 13:22:58 -04003645 [MV88E6123] = {
3646 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3647 .family = MV88E6XXX_FAMILY_6165,
3648 .name = "Marvell 88E6123",
3649 .num_databases = 4096,
3650 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003651 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003652 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003653 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003654 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003655 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003656 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003657 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003658 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003659 },
3660
3661 [MV88E6131] = {
3662 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3663 .family = MV88E6XXX_FAMILY_6185,
3664 .name = "Marvell 88E6131",
3665 .num_databases = 256,
3666 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003667 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003668 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003669 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003670 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003671 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003672 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003673 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003674 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003675 },
3676
Vivien Didelot990e27b2017-03-28 13:50:32 -04003677 [MV88E6141] = {
3678 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
3679 .family = MV88E6XXX_FAMILY_6341,
3680 .name = "Marvell 88E6341",
3681 .num_databases = 4096,
3682 .num_ports = 6,
3683 .port_base_addr = 0x10,
3684 .global1_addr = 0x1b,
3685 .age_time_coeff = 3750,
3686 .atu_move_port_mask = 0x1f,
3687 .tag_protocol = DSA_TAG_PROTO_EDSA,
3688 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3689 .ops = &mv88e6141_ops,
3690 },
3691
Vivien Didelotf81ec902016-05-09 13:22:58 -04003692 [MV88E6161] = {
3693 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3694 .family = MV88E6XXX_FAMILY_6165,
3695 .name = "Marvell 88E6161",
3696 .num_databases = 4096,
3697 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003698 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003699 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003700 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003701 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003702 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003703 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003704 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003705 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003706 },
3707
3708 [MV88E6165] = {
3709 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3710 .family = MV88E6XXX_FAMILY_6165,
3711 .name = "Marvell 88E6165",
3712 .num_databases = 4096,
3713 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003714 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003715 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003716 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003717 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003718 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003719 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003720 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003721 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003722 },
3723
3724 [MV88E6171] = {
3725 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3726 .family = MV88E6XXX_FAMILY_6351,
3727 .name = "Marvell 88E6171",
3728 .num_databases = 4096,
3729 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003730 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003731 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003732 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003733 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003734 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003735 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003736 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003737 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003738 },
3739
3740 [MV88E6172] = {
3741 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3742 .family = MV88E6XXX_FAMILY_6352,
3743 .name = "Marvell 88E6172",
3744 .num_databases = 4096,
3745 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003746 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003747 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003748 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003749 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003750 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003751 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003752 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003753 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003754 },
3755
3756 [MV88E6175] = {
3757 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3758 .family = MV88E6XXX_FAMILY_6351,
3759 .name = "Marvell 88E6175",
3760 .num_databases = 4096,
3761 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003762 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003763 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003764 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003765 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003766 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003767 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003768 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003769 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003770 },
3771
3772 [MV88E6176] = {
3773 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3774 .family = MV88E6XXX_FAMILY_6352,
3775 .name = "Marvell 88E6176",
3776 .num_databases = 4096,
3777 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003778 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003779 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003780 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003781 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003782 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003783 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003784 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003785 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003786 },
3787
3788 [MV88E6185] = {
3789 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3790 .family = MV88E6XXX_FAMILY_6185,
3791 .name = "Marvell 88E6185",
3792 .num_databases = 256,
3793 .num_ports = 10,
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 = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003798 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003799 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003800 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003801 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003802 },
3803
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003804 [MV88E6190] = {
3805 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3806 .family = MV88E6XXX_FAMILY_6390,
3807 .name = "Marvell 88E6190",
3808 .num_databases = 4096,
3809 .num_ports = 11, /* 10 + Z80 */
3810 .port_base_addr = 0x0,
3811 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003812 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003813 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003814 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003815 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003816 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3817 .ops = &mv88e6190_ops,
3818 },
3819
3820 [MV88E6190X] = {
3821 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3822 .family = MV88E6XXX_FAMILY_6390,
3823 .name = "Marvell 88E6190X",
3824 .num_databases = 4096,
3825 .num_ports = 11, /* 10 + Z80 */
3826 .port_base_addr = 0x0,
3827 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003828 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003829 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003830 .atu_move_port_mask = 0x1f,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003831 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003832 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3833 .ops = &mv88e6190x_ops,
3834 },
3835
3836 [MV88E6191] = {
3837 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3838 .family = MV88E6XXX_FAMILY_6390,
3839 .name = "Marvell 88E6191",
3840 .num_databases = 4096,
3841 .num_ports = 11, /* 10 + Z80 */
3842 .port_base_addr = 0x0,
3843 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003844 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003845 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003846 .atu_move_port_mask = 0x1f,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003847 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003848 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3849 .ops = &mv88e6391_ops,
3850 },
3851
Vivien Didelotf81ec902016-05-09 13:22:58 -04003852 [MV88E6240] = {
3853 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3854 .family = MV88E6XXX_FAMILY_6352,
3855 .name = "Marvell 88E6240",
3856 .num_databases = 4096,
3857 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003858 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003859 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003860 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003861 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003862 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003863 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003864 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003865 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003866 },
3867
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003868 [MV88E6290] = {
3869 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3870 .family = MV88E6XXX_FAMILY_6390,
3871 .name = "Marvell 88E6290",
3872 .num_databases = 4096,
3873 .num_ports = 11, /* 10 + Z80 */
3874 .port_base_addr = 0x0,
3875 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003876 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003877 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003878 .atu_move_port_mask = 0x1f,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003879 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003880 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3881 .ops = &mv88e6290_ops,
3882 },
3883
Vivien Didelotf81ec902016-05-09 13:22:58 -04003884 [MV88E6320] = {
3885 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3886 .family = MV88E6XXX_FAMILY_6320,
3887 .name = "Marvell 88E6320",
3888 .num_databases = 4096,
3889 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003890 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003891 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003892 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003893 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003894 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003895 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003896 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003897 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003898 },
3899
3900 [MV88E6321] = {
3901 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3902 .family = MV88E6XXX_FAMILY_6320,
3903 .name = "Marvell 88E6321",
3904 .num_databases = 4096,
3905 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003906 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003907 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003908 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003909 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003910 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003911 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003912 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003913 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003914 },
3915
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003916 [MV88E6341] = {
3917 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
3918 .family = MV88E6XXX_FAMILY_6341,
3919 .name = "Marvell 88E6341",
3920 .num_databases = 4096,
3921 .num_ports = 6,
3922 .port_base_addr = 0x10,
3923 .global1_addr = 0x1b,
3924 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003925 .atu_move_port_mask = 0x1f,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003926 .tag_protocol = DSA_TAG_PROTO_EDSA,
3927 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3928 .ops = &mv88e6341_ops,
3929 },
3930
Vivien Didelotf81ec902016-05-09 13:22:58 -04003931 [MV88E6350] = {
3932 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3933 .family = MV88E6XXX_FAMILY_6351,
3934 .name = "Marvell 88E6350",
3935 .num_databases = 4096,
3936 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003937 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003938 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003939 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003940 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003941 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003942 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003943 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003944 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003945 },
3946
3947 [MV88E6351] = {
3948 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3949 .family = MV88E6XXX_FAMILY_6351,
3950 .name = "Marvell 88E6351",
3951 .num_databases = 4096,
3952 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003953 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003954 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003955 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003956 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003957 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003958 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003959 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003960 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003961 },
3962
3963 [MV88E6352] = {
3964 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
3965 .family = MV88E6XXX_FAMILY_6352,
3966 .name = "Marvell 88E6352",
3967 .num_databases = 4096,
3968 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003969 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003970 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003971 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003972 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003973 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003974 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003975 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003976 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003977 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003978 [MV88E6390] = {
3979 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
3980 .family = MV88E6XXX_FAMILY_6390,
3981 .name = "Marvell 88E6390",
3982 .num_databases = 4096,
3983 .num_ports = 11, /* 10 + Z80 */
3984 .port_base_addr = 0x0,
3985 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003986 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003987 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003988 .atu_move_port_mask = 0x1f,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003989 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003990 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3991 .ops = &mv88e6390_ops,
3992 },
3993 [MV88E6390X] = {
3994 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
3995 .family = MV88E6XXX_FAMILY_6390,
3996 .name = "Marvell 88E6390X",
3997 .num_databases = 4096,
3998 .num_ports = 11, /* 10 + Z80 */
3999 .port_base_addr = 0x0,
4000 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004001 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004002 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004003 .atu_move_port_mask = 0x1f,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004004 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004005 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4006 .ops = &mv88e6390x_ops,
4007 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004008};
4009
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004010static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004011{
Vivien Didelota439c062016-04-17 13:23:58 -04004012 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004013
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004014 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4015 if (mv88e6xxx_table[i].prod_num == prod_num)
4016 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004017
Vivien Didelotb9b37712015-10-30 19:39:48 -04004018 return NULL;
4019}
4020
Vivien Didelotfad09c72016-06-21 12:28:20 -04004021static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004022{
4023 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004024 unsigned int prod_num, rev;
4025 u16 id;
4026 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004027
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004028 mutex_lock(&chip->reg_lock);
4029 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4030 mutex_unlock(&chip->reg_lock);
4031 if (err)
4032 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004033
4034 prod_num = (id & 0xfff0) >> 4;
4035 rev = id & 0x000f;
4036
4037 info = mv88e6xxx_lookup_info(prod_num);
4038 if (!info)
4039 return -ENODEV;
4040
Vivien Didelotcaac8542016-06-20 13:14:09 -04004041 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004042 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004043
Vivien Didelotca070c12016-09-02 14:45:34 -04004044 err = mv88e6xxx_g2_require(chip);
4045 if (err)
4046 return err;
4047
Vivien Didelotfad09c72016-06-21 12:28:20 -04004048 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4049 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004050
4051 return 0;
4052}
4053
Vivien Didelotfad09c72016-06-21 12:28:20 -04004054static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004055{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004056 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004057
Vivien Didelotfad09c72016-06-21 12:28:20 -04004058 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4059 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004060 return NULL;
4061
Vivien Didelotfad09c72016-06-21 12:28:20 -04004062 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004063
Vivien Didelotfad09c72016-06-21 12:28:20 -04004064 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004065 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004066
Vivien Didelotfad09c72016-06-21 12:28:20 -04004067 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004068}
4069
Vivien Didelote57e5e72016-08-15 17:19:00 -04004070static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4071{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004072 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004073 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004074}
4075
Andrew Lunn930188c2016-08-22 16:01:03 +02004076static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4077{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004078 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004079 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004080}
4081
Vivien Didelotfad09c72016-06-21 12:28:20 -04004082static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004083 struct mii_bus *bus, int sw_addr)
4084{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004085 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004086 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004087 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004088 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004089 else
4090 return -EINVAL;
4091
Vivien Didelotfad09c72016-06-21 12:28:20 -04004092 chip->bus = bus;
4093 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004094
4095 return 0;
4096}
4097
Andrew Lunn7b314362016-08-22 16:01:01 +02004098static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4099{
Vivien Didelot04bed142016-08-31 18:06:13 -04004100 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004101
Andrew Lunn443d5a12016-12-03 04:35:18 +01004102 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004103}
4104
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004105static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4106 struct device *host_dev, int sw_addr,
4107 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004108{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004109 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004110 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004111 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004112
Vivien Didelota439c062016-04-17 13:23:58 -04004113 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004114 if (!bus)
4115 return NULL;
4116
Vivien Didelotfad09c72016-06-21 12:28:20 -04004117 chip = mv88e6xxx_alloc_chip(dsa_dev);
4118 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004119 return NULL;
4120
Vivien Didelotcaac8542016-06-20 13:14:09 -04004121 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004122 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004123
Vivien Didelotfad09c72016-06-21 12:28:20 -04004124 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004125 if (err)
4126 goto free;
4127
Vivien Didelotfad09c72016-06-21 12:28:20 -04004128 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004129 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004130 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004131
Andrew Lunndc30c352016-10-16 19:56:49 +02004132 mutex_lock(&chip->reg_lock);
4133 err = mv88e6xxx_switch_reset(chip);
4134 mutex_unlock(&chip->reg_lock);
4135 if (err)
4136 goto free;
4137
Vivien Didelote57e5e72016-08-15 17:19:00 -04004138 mv88e6xxx_phy_init(chip);
4139
Andrew Lunna3c53be52017-01-24 14:53:50 +01004140 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004141 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004142 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004143
Vivien Didelotfad09c72016-06-21 12:28:20 -04004144 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004145
Vivien Didelotfad09c72016-06-21 12:28:20 -04004146 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004147free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004148 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004149
4150 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004151}
4152
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004153static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4154 const struct switchdev_obj_port_mdb *mdb,
4155 struct switchdev_trans *trans)
4156{
4157 /* We don't need any dynamic resource from the kernel (yet),
4158 * so skip the prepare phase.
4159 */
4160
4161 return 0;
4162}
4163
4164static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4165 const struct switchdev_obj_port_mdb *mdb,
4166 struct switchdev_trans *trans)
4167{
Vivien Didelot04bed142016-08-31 18:06:13 -04004168 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004169
4170 mutex_lock(&chip->reg_lock);
4171 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4172 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4173 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4174 mutex_unlock(&chip->reg_lock);
4175}
4176
4177static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4178 const struct switchdev_obj_port_mdb *mdb)
4179{
Vivien Didelot04bed142016-08-31 18:06:13 -04004180 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004181 int err;
4182
4183 mutex_lock(&chip->reg_lock);
4184 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4185 GLOBAL_ATU_DATA_STATE_UNUSED);
4186 mutex_unlock(&chip->reg_lock);
4187
4188 return err;
4189}
4190
4191static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4192 struct switchdev_obj_port_mdb *mdb,
4193 int (*cb)(struct switchdev_obj *obj))
4194{
Vivien Didelot04bed142016-08-31 18:06:13 -04004195 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004196 int err;
4197
4198 mutex_lock(&chip->reg_lock);
4199 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4200 mutex_unlock(&chip->reg_lock);
4201
4202 return err;
4203}
4204
Florian Fainellia82f67a2017-01-08 14:52:08 -08004205static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004206 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004207 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004208 .setup = mv88e6xxx_setup,
4209 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004210 .adjust_link = mv88e6xxx_adjust_link,
4211 .get_strings = mv88e6xxx_get_strings,
4212 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4213 .get_sset_count = mv88e6xxx_get_sset_count,
4214 .set_eee = mv88e6xxx_set_eee,
4215 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004216 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004217 .get_eeprom = mv88e6xxx_get_eeprom,
4218 .set_eeprom = mv88e6xxx_set_eeprom,
4219 .get_regs_len = mv88e6xxx_get_regs_len,
4220 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004221 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004222 .port_bridge_join = mv88e6xxx_port_bridge_join,
4223 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4224 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004225 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004226 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4227 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4228 .port_vlan_add = mv88e6xxx_port_vlan_add,
4229 .port_vlan_del = mv88e6xxx_port_vlan_del,
4230 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4231 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4232 .port_fdb_add = mv88e6xxx_port_fdb_add,
4233 .port_fdb_del = mv88e6xxx_port_fdb_del,
4234 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004235 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4236 .port_mdb_add = mv88e6xxx_port_mdb_add,
4237 .port_mdb_del = mv88e6xxx_port_mdb_del,
4238 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004239};
4240
Florian Fainelliab3d4082017-01-08 14:52:07 -08004241static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4242 .ops = &mv88e6xxx_switch_ops,
4243};
4244
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004245static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004246{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004247 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004248 struct dsa_switch *ds;
4249
Vivien Didelota0c02162017-01-27 15:29:36 -05004250 ds = dsa_switch_alloc(dev, DSA_MAX_PORTS);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004251 if (!ds)
4252 return -ENOMEM;
4253
Vivien Didelotfad09c72016-06-21 12:28:20 -04004254 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004255 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004256 ds->ageing_time_min = chip->info->age_time_coeff;
4257 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004258
4259 dev_set_drvdata(dev, ds);
4260
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004261 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004262}
4263
Vivien Didelotfad09c72016-06-21 12:28:20 -04004264static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004265{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004266 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004267}
4268
Vivien Didelot57d32312016-06-20 13:13:58 -04004269static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004270{
4271 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004272 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004273 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004274 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004275 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004276 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004277
Vivien Didelotcaac8542016-06-20 13:14:09 -04004278 compat_info = of_device_get_match_data(dev);
4279 if (!compat_info)
4280 return -EINVAL;
4281
Vivien Didelotfad09c72016-06-21 12:28:20 -04004282 chip = mv88e6xxx_alloc_chip(dev);
4283 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004284 return -ENOMEM;
4285
Vivien Didelotfad09c72016-06-21 12:28:20 -04004286 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004287
Vivien Didelotfad09c72016-06-21 12:28:20 -04004288 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004289 if (err)
4290 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004291
Andrew Lunnb4308f02016-11-21 23:26:55 +01004292 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4293 if (IS_ERR(chip->reset))
4294 return PTR_ERR(chip->reset);
4295
Vivien Didelotfad09c72016-06-21 12:28:20 -04004296 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004297 if (err)
4298 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004299
Vivien Didelote57e5e72016-08-15 17:19:00 -04004300 mv88e6xxx_phy_init(chip);
4301
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004302 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004303 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004304 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004305
Andrew Lunndc30c352016-10-16 19:56:49 +02004306 mutex_lock(&chip->reg_lock);
4307 err = mv88e6xxx_switch_reset(chip);
4308 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004309 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004310 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004311
Andrew Lunndc30c352016-10-16 19:56:49 +02004312 chip->irq = of_irq_get(np, 0);
4313 if (chip->irq == -EPROBE_DEFER) {
4314 err = chip->irq;
4315 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004316 }
4317
Andrew Lunndc30c352016-10-16 19:56:49 +02004318 if (chip->irq > 0) {
4319 /* Has to be performed before the MDIO bus is created,
4320 * because the PHYs will link there interrupts to these
4321 * interrupt controllers
4322 */
4323 mutex_lock(&chip->reg_lock);
4324 err = mv88e6xxx_g1_irq_setup(chip);
4325 mutex_unlock(&chip->reg_lock);
4326
4327 if (err)
4328 goto out;
4329
4330 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4331 err = mv88e6xxx_g2_irq_setup(chip);
4332 if (err)
4333 goto out_g1_irq;
4334 }
4335 }
4336
Andrew Lunna3c53be52017-01-24 14:53:50 +01004337 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004338 if (err)
4339 goto out_g2_irq;
4340
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004341 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004342 if (err)
4343 goto out_mdio;
4344
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004345 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004346
4347out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004348 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004349out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004350 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004351 mv88e6xxx_g2_irq_free(chip);
4352out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004353 if (chip->irq > 0) {
4354 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004355 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004356 mutex_unlock(&chip->reg_lock);
4357 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004358out:
4359 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004360}
4361
4362static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4363{
4364 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004365 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004366
Andrew Lunn930188c2016-08-22 16:01:03 +02004367 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004368 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004369 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004370
Andrew Lunn467126442016-11-20 20:14:15 +01004371 if (chip->irq > 0) {
4372 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4373 mv88e6xxx_g2_irq_free(chip);
4374 mv88e6xxx_g1_irq_free(chip);
4375 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004376}
4377
4378static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004379 {
4380 .compatible = "marvell,mv88e6085",
4381 .data = &mv88e6xxx_table[MV88E6085],
4382 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004383 {
4384 .compatible = "marvell,mv88e6190",
4385 .data = &mv88e6xxx_table[MV88E6190],
4386 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004387 { /* sentinel */ },
4388};
4389
4390MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4391
4392static struct mdio_driver mv88e6xxx_driver = {
4393 .probe = mv88e6xxx_probe,
4394 .remove = mv88e6xxx_remove,
4395 .mdiodrv.driver = {
4396 .name = "mv88e6085",
4397 .of_match_table = mv88e6xxx_of_match,
4398 },
4399};
4400
Ben Hutchings98e67302011-11-25 14:36:19 +00004401static int __init mv88e6xxx_init(void)
4402{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004403 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004404 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004405}
4406module_init(mv88e6xxx_init);
4407
4408static void __exit mv88e6xxx_cleanup(void)
4409{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004410 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004411 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004412}
4413module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004414
4415MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4416MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4417MODULE_LICENSE("GPL");