blob: 2d1ec0d79fb68057b347362fb1dd47558a5a366f [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
Vivien Didelotfad09c72016-06-21 12:28:20 -0400690static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700691{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400692 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700693}
694
Gregory CLEMENTa75961d2017-01-30 20:29:34 +0100695static bool mv88e6xxx_6341_family(struct mv88e6xxx_chip *chip)
696{
697 return chip->info->family == MV88E6XXX_FAMILY_6341;
698}
699
Vivien Didelotfad09c72016-06-21 12:28:20 -0400700static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200701{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400702 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200703}
704
Vivien Didelotfad09c72016-06-21 12:28:20 -0400705static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200706{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400707 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200708}
709
Vivien Didelotd78343d2016-11-04 03:23:36 +0100710static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
711 int link, int speed, int duplex,
712 phy_interface_t mode)
713{
714 int err;
715
716 if (!chip->info->ops->port_set_link)
717 return 0;
718
719 /* Port's MAC control must not be changed unless the link is down */
720 err = chip->info->ops->port_set_link(chip, port, 0);
721 if (err)
722 return err;
723
724 if (chip->info->ops->port_set_speed) {
725 err = chip->info->ops->port_set_speed(chip, port, speed);
726 if (err && err != -EOPNOTSUPP)
727 goto restore_link;
728 }
729
730 if (chip->info->ops->port_set_duplex) {
731 err = chip->info->ops->port_set_duplex(chip, port, duplex);
732 if (err && err != -EOPNOTSUPP)
733 goto restore_link;
734 }
735
736 if (chip->info->ops->port_set_rgmii_delay) {
737 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
738 if (err && err != -EOPNOTSUPP)
739 goto restore_link;
740 }
741
Andrew Lunnf39908d2017-02-04 20:02:50 +0100742 if (chip->info->ops->port_set_cmode) {
743 err = chip->info->ops->port_set_cmode(chip, port, mode);
744 if (err && err != -EOPNOTSUPP)
745 goto restore_link;
746 }
747
Vivien Didelotd78343d2016-11-04 03:23:36 +0100748 err = 0;
749restore_link:
750 if (chip->info->ops->port_set_link(chip, port, link))
751 netdev_err(chip->ds->ports[port].netdev,
752 "failed to restore MAC's link\n");
753
754 return err;
755}
756
Andrew Lunndea87022015-08-31 15:56:47 +0200757/* We expect the switch to perform auto negotiation if there is a real
758 * phy. However, in the case of a fixed link phy, we force the port
759 * settings from the fixed link settings.
760 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400761static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
762 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200763{
Vivien Didelot04bed142016-08-31 18:06:13 -0400764 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200765 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200766
767 if (!phy_is_pseudo_fixed_link(phydev))
768 return;
769
Vivien Didelotfad09c72016-06-21 12:28:20 -0400770 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100771 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
772 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400773 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100774
775 if (err && err != -EOPNOTSUPP)
776 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200777}
778
Andrew Lunna605a0f2016-11-21 23:26:58 +0100779static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000780{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100781 if (!chip->info->ops->stats_snapshot)
782 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000783
Andrew Lunna605a0f2016-11-21 23:26:58 +0100784 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000785}
786
Andrew Lunne413e7e2015-04-02 04:06:38 +0200787static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100788 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
789 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
790 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
791 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
792 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
793 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
794 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
795 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
796 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
797 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
798 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
799 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
800 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
801 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
802 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
803 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
804 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
805 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
806 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
807 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
808 { "single", 4, 0x14, STATS_TYPE_BANK0, },
809 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
810 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
811 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
812 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
813 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
814 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
815 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
816 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
817 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
818 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
819 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
820 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
821 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
822 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
823 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
824 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
825 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
826 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
827 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
828 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
829 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
830 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
831 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
832 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
833 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
834 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
835 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
836 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
837 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
838 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
839 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
840 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
841 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
842 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
843 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
844 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
845 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
846 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200847};
848
Vivien Didelotfad09c72016-06-21 12:28:20 -0400849static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100850 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100851 int port, u16 bank1_select,
852 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200853{
Andrew Lunn80c46272015-06-20 18:42:30 +0200854 u32 low;
855 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100856 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200857 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200858 u64 value;
859
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100860 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100861 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200862 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
863 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200864 return UINT64_MAX;
865
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200866 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200867 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200868 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
869 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200870 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200871 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200872 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100873 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100874 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100875 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100876 /* fall through */
877 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100878 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100879 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200880 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100881 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200882 }
883 value = (((u64)high) << 16) | low;
884 return value;
885}
886
Andrew Lunndfafe442016-11-21 23:27:02 +0100887static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
888 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100889{
890 struct mv88e6xxx_hw_stat *stat;
891 int i, j;
892
893 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
894 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100895 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100896 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
897 ETH_GSTRING_LEN);
898 j++;
899 }
900 }
901}
902
Andrew Lunndfafe442016-11-21 23:27:02 +0100903static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
904 uint8_t *data)
905{
906 mv88e6xxx_stats_get_strings(chip, data,
907 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
908}
909
910static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
911 uint8_t *data)
912{
913 mv88e6xxx_stats_get_strings(chip, data,
914 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
915}
916
917static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
918 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100919{
Vivien Didelot04bed142016-08-31 18:06:13 -0400920 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100921
922 if (chip->info->ops->stats_get_strings)
923 chip->info->ops->stats_get_strings(chip, data);
924}
925
926static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
927 int types)
928{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100929 struct mv88e6xxx_hw_stat *stat;
930 int i, j;
931
932 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
933 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100934 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100935 j++;
936 }
937 return j;
938}
939
Andrew Lunndfafe442016-11-21 23:27:02 +0100940static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
941{
942 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
943 STATS_TYPE_PORT);
944}
945
946static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
947{
948 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
949 STATS_TYPE_BANK1);
950}
951
952static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
953{
954 struct mv88e6xxx_chip *chip = ds->priv;
955
956 if (chip->info->ops->stats_get_sset_count)
957 return chip->info->ops->stats_get_sset_count(chip);
958
959 return 0;
960}
961
Andrew Lunn052f9472016-11-21 23:27:03 +0100962static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100963 uint64_t *data, int types,
964 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100965{
966 struct mv88e6xxx_hw_stat *stat;
967 int i, j;
968
969 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
970 stat = &mv88e6xxx_hw_stats[i];
971 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100972 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
973 bank1_select,
974 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100975 j++;
976 }
977 }
978}
979
980static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
981 uint64_t *data)
982{
983 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100984 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
985 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100986}
987
988static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
989 uint64_t *data)
990{
991 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100992 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
993 GLOBAL_STATS_OP_BANK_1_BIT_9,
994 GLOBAL_STATS_OP_HIST_RX_TX);
995}
996
997static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
998 uint64_t *data)
999{
1000 return mv88e6xxx_stats_get_stats(chip, port, data,
1001 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1002 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001003}
1004
1005static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1006 uint64_t *data)
1007{
1008 if (chip->info->ops->stats_get_stats)
1009 chip->info->ops->stats_get_stats(chip, port, data);
1010}
1011
Vivien Didelotf81ec902016-05-09 13:22:58 -04001012static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1013 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001014{
Vivien Didelot04bed142016-08-31 18:06:13 -04001015 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001016 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001017
Vivien Didelotfad09c72016-06-21 12:28:20 -04001018 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001019
Andrew Lunna605a0f2016-11-21 23:26:58 +01001020 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001021 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001022 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001023 return;
1024 }
Andrew Lunn052f9472016-11-21 23:27:03 +01001025
1026 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001027
Vivien Didelotfad09c72016-06-21 12:28:20 -04001028 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001029}
Ben Hutchings98e67302011-11-25 14:36:19 +00001030
Andrew Lunnde2273872016-11-21 23:27:01 +01001031static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1032{
1033 if (chip->info->ops->stats_set_histogram)
1034 return chip->info->ops->stats_set_histogram(chip);
1035
1036 return 0;
1037}
1038
Vivien Didelotf81ec902016-05-09 13:22:58 -04001039static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001040{
1041 return 32 * sizeof(u16);
1042}
1043
Vivien Didelotf81ec902016-05-09 13:22:58 -04001044static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1045 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001046{
Vivien Didelot04bed142016-08-31 18:06:13 -04001047 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001048 int err;
1049 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001050 u16 *p = _p;
1051 int i;
1052
1053 regs->version = 0;
1054
1055 memset(p, 0xff, 32 * sizeof(u16));
1056
Vivien Didelotfad09c72016-06-21 12:28:20 -04001057 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001058
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001059 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001060
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001061 err = mv88e6xxx_port_read(chip, port, i, &reg);
1062 if (!err)
1063 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001064 }
Vivien Didelot23062512016-05-09 13:22:45 -04001065
Vivien Didelotfad09c72016-06-21 12:28:20 -04001066 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001067}
1068
Vivien Didelotfad09c72016-06-21 12:28:20 -04001069static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001070{
Vivien Didelota935c052016-09-29 12:21:53 -04001071 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001072}
1073
Vivien Didelotf81ec902016-05-09 13:22:58 -04001074static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1075 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001076{
Vivien Didelot04bed142016-08-31 18:06:13 -04001077 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001078 u16 reg;
1079 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001080
Vivien Didelotfad09c72016-06-21 12:28:20 -04001081 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001082 return -EOPNOTSUPP;
1083
Vivien Didelotfad09c72016-06-21 12:28:20 -04001084 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001085
Vivien Didelot9c938292016-08-15 17:19:02 -04001086 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1087 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001088 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001089
1090 e->eee_enabled = !!(reg & 0x0200);
1091 e->tx_lpi_enabled = !!(reg & 0x0100);
1092
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001093 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001094 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001095 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001096
Andrew Lunncca8b132015-04-02 04:06:39 +02001097 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001098out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001099 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001100
1101 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001102}
1103
Vivien Didelotf81ec902016-05-09 13:22:58 -04001104static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1105 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001106{
Vivien Didelot04bed142016-08-31 18:06:13 -04001107 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001108 u16 reg;
1109 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001110
Vivien Didelotfad09c72016-06-21 12:28:20 -04001111 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001112 return -EOPNOTSUPP;
1113
Vivien Didelotfad09c72016-06-21 12:28:20 -04001114 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001115
Vivien Didelot9c938292016-08-15 17:19:02 -04001116 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1117 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001118 goto out;
1119
Vivien Didelot9c938292016-08-15 17:19:02 -04001120 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001121 if (e->eee_enabled)
1122 reg |= 0x0200;
1123 if (e->tx_lpi_enabled)
1124 reg |= 0x0100;
1125
Vivien Didelot9c938292016-08-15 17:19:02 -04001126 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001127out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001128 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001129
Vivien Didelot9c938292016-08-15 17:19:02 -04001130 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001131}
1132
Vivien Didelotfad09c72016-06-21 12:28:20 -04001133static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001134{
Vivien Didelota935c052016-09-29 12:21:53 -04001135 u16 val;
1136 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001137
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001138 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001139 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1140 if (err)
1141 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001142 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001143 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001144 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1145 if (err)
1146 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001147
Vivien Didelota935c052016-09-29 12:21:53 -04001148 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1149 (val & 0xfff) | ((fid << 8) & 0xf000));
1150 if (err)
1151 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001152
1153 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1154 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001155 }
1156
Vivien Didelota935c052016-09-29 12:21:53 -04001157 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1158 if (err)
1159 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001160
Vivien Didelotfad09c72016-06-21 12:28:20 -04001161 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001162}
1163
Vivien Didelotfad09c72016-06-21 12:28:20 -04001164static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001165 struct mv88e6xxx_atu_entry *entry)
1166{
1167 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1168
1169 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1170 unsigned int mask, shift;
1171
1172 if (entry->trunk) {
1173 data |= GLOBAL_ATU_DATA_TRUNK;
1174 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1175 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1176 } else {
1177 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1178 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1179 }
1180
1181 data |= (entry->portv_trunkid << shift) & mask;
1182 }
1183
Vivien Didelota935c052016-09-29 12:21:53 -04001184 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001185}
1186
Vivien Didelotfad09c72016-06-21 12:28:20 -04001187static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001188 struct mv88e6xxx_atu_entry *entry,
1189 bool static_too)
1190{
1191 int op;
1192 int err;
1193
Vivien Didelotfad09c72016-06-21 12:28:20 -04001194 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001195 if (err)
1196 return err;
1197
Vivien Didelotfad09c72016-06-21 12:28:20 -04001198 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001199 if (err)
1200 return err;
1201
1202 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001203 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1204 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1205 } else {
1206 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1207 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1208 }
1209
Vivien Didelotfad09c72016-06-21 12:28:20 -04001210 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001211}
1212
Vivien Didelotfad09c72016-06-21 12:28:20 -04001213static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001214 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001215{
1216 struct mv88e6xxx_atu_entry entry = {
1217 .fid = fid,
1218 .state = 0, /* EntryState bits must be 0 */
1219 };
1220
Vivien Didelotfad09c72016-06-21 12:28:20 -04001221 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001222}
1223
Vivien Didelotfad09c72016-06-21 12:28:20 -04001224static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001225 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001226{
1227 struct mv88e6xxx_atu_entry entry = {
1228 .trunk = false,
1229 .fid = fid,
1230 };
1231
1232 /* EntryState bits must be 0xF */
1233 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1234
1235 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1236 entry.portv_trunkid = (to_port & 0x0f) << 4;
1237 entry.portv_trunkid |= from_port & 0x0f;
1238
Vivien Didelotfad09c72016-06-21 12:28:20 -04001239 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001240}
1241
Vivien Didelotfad09c72016-06-21 12:28:20 -04001242static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001243 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001244{
1245 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001246 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001247}
1248
Vivien Didelotfad09c72016-06-21 12:28:20 -04001249static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001250{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001251 struct dsa_switch *ds = chip->ds;
Vivien Didelotfae8a252017-01-27 15:29:42 -05001252 struct net_device *bridge = ds->ports[port].bridge_dev;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001253 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001254 int i;
1255
1256 /* allow CPU port or DSA link(s) to send frames to every port */
1257 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001258 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001259 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001260 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001261 /* allow sending frames to every group member */
Vivien Didelotfae8a252017-01-27 15:29:42 -05001262 if (bridge && ds->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001263 output_ports |= BIT(i);
1264
1265 /* allow sending frames to CPU port and DSA link(s) */
1266 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1267 output_ports |= BIT(i);
1268 }
1269 }
1270
1271 /* prevent frames from going back out of the port they came in on */
1272 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001273
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001274 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001275}
1276
Vivien Didelotf81ec902016-05-09 13:22:58 -04001277static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1278 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001279{
Vivien Didelot04bed142016-08-31 18:06:13 -04001280 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001281 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001282 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001283
1284 switch (state) {
1285 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001286 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001287 break;
1288 case BR_STATE_BLOCKING:
1289 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001290 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001291 break;
1292 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001293 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001294 break;
1295 case BR_STATE_FORWARDING:
1296 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001297 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001298 break;
1299 }
1300
Vivien Didelotfad09c72016-06-21 12:28:20 -04001301 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001302 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001303 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001304
1305 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001306 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001307}
1308
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001309static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1310{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001311 int err;
1312
1313 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1314 if (err)
1315 return err;
1316
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001317 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1318}
1319
Vivien Didelot749efcb2016-09-22 16:49:24 -04001320static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1321{
1322 struct mv88e6xxx_chip *chip = ds->priv;
1323 int err;
1324
1325 mutex_lock(&chip->reg_lock);
1326 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1327 mutex_unlock(&chip->reg_lock);
1328
1329 if (err)
1330 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1331}
1332
Vivien Didelotfad09c72016-06-21 12:28:20 -04001333static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001334{
Vivien Didelota935c052016-09-29 12:21:53 -04001335 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001336}
1337
Vivien Didelotfad09c72016-06-21 12:28:20 -04001338static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001339{
Vivien Didelota935c052016-09-29 12:21:53 -04001340 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001341
Vivien Didelota935c052016-09-29 12:21:53 -04001342 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1343 if (err)
1344 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001345
Vivien Didelotfad09c72016-06-21 12:28:20 -04001346 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001347}
1348
Vivien Didelotfad09c72016-06-21 12:28:20 -04001349static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001350{
1351 int ret;
1352
Vivien Didelotfad09c72016-06-21 12:28:20 -04001353 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001354 if (ret < 0)
1355 return ret;
1356
Vivien Didelotfad09c72016-06-21 12:28:20 -04001357 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001358}
1359
Vivien Didelotfad09c72016-06-21 12:28:20 -04001360static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001361 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001362 unsigned int nibble_offset)
1363{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001364 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001365 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001366
1367 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001368 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001369
Vivien Didelota935c052016-09-29 12:21:53 -04001370 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1371 if (err)
1372 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001373 }
1374
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001375 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001376 unsigned int shift = (i % 4) * 4 + nibble_offset;
1377 u16 reg = regs[i / 4];
1378
1379 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1380 }
1381
1382 return 0;
1383}
1384
Vivien Didelotfad09c72016-06-21 12:28:20 -04001385static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001386 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001387{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001388 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001389}
1390
Vivien Didelotfad09c72016-06-21 12:28:20 -04001391static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001392 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001393{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001394 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001395}
1396
Vivien Didelotfad09c72016-06-21 12:28:20 -04001397static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001398 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001399 unsigned int nibble_offset)
1400{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001401 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001402 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001403
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001404 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001405 unsigned int shift = (i % 4) * 4 + nibble_offset;
1406 u8 data = entry->data[i];
1407
1408 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1409 }
1410
1411 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001412 u16 reg = regs[i];
1413
1414 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1415 if (err)
1416 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001417 }
1418
1419 return 0;
1420}
1421
Vivien Didelotfad09c72016-06-21 12:28:20 -04001422static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001423 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001424{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001425 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001426}
1427
Vivien Didelotfad09c72016-06-21 12:28:20 -04001428static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001429 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001430{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001431 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001432}
1433
Vivien Didelotfad09c72016-06-21 12:28:20 -04001434static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001435{
Vivien Didelota935c052016-09-29 12:21:53 -04001436 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1437 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001438}
1439
Vivien Didelotfad09c72016-06-21 12:28:20 -04001440static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001441 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001442{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001443 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001444 u16 val;
1445 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001446
Vivien Didelota935c052016-09-29 12:21:53 -04001447 err = _mv88e6xxx_vtu_wait(chip);
1448 if (err)
1449 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001450
Vivien Didelota935c052016-09-29 12:21:53 -04001451 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1452 if (err)
1453 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001454
Vivien Didelota935c052016-09-29 12:21:53 -04001455 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1456 if (err)
1457 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001458
Vivien Didelota935c052016-09-29 12:21:53 -04001459 next.vid = val & GLOBAL_VTU_VID_MASK;
1460 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001461
1462 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001463 err = mv88e6xxx_vtu_data_read(chip, &next);
1464 if (err)
1465 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001466
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001467 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001468 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1469 if (err)
1470 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001471
Vivien Didelota935c052016-09-29 12:21:53 -04001472 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001473 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001474 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1475 * VTU DBNum[3:0] are located in VTU Operation 3:0
1476 */
Vivien Didelota935c052016-09-29 12:21:53 -04001477 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1478 if (err)
1479 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001480
Vivien Didelota935c052016-09-29 12:21:53 -04001481 next.fid = (val & 0xf00) >> 4;
1482 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001483 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001484
Vivien Didelotfad09c72016-06-21 12:28:20 -04001485 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001486 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1487 if (err)
1488 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001489
Vivien Didelota935c052016-09-29 12:21:53 -04001490 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001491 }
1492 }
1493
1494 *entry = next;
1495 return 0;
1496}
1497
Vivien Didelotf81ec902016-05-09 13:22:58 -04001498static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1499 struct switchdev_obj_port_vlan *vlan,
1500 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001501{
Vivien Didelot04bed142016-08-31 18:06:13 -04001502 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001503 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001504 u16 pvid;
1505 int err;
1506
Vivien Didelotfad09c72016-06-21 12:28:20 -04001507 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001508 return -EOPNOTSUPP;
1509
Vivien Didelotfad09c72016-06-21 12:28:20 -04001510 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001511
Vivien Didelot77064f32016-11-04 03:23:30 +01001512 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001513 if (err)
1514 goto unlock;
1515
Vivien Didelotfad09c72016-06-21 12:28:20 -04001516 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001517 if (err)
1518 goto unlock;
1519
1520 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001521 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001522 if (err)
1523 break;
1524
1525 if (!next.valid)
1526 break;
1527
1528 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1529 continue;
1530
1531 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001532 vlan->vid_begin = next.vid;
1533 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001534 vlan->flags = 0;
1535
1536 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1537 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1538
1539 if (next.vid == pvid)
1540 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1541
1542 err = cb(&vlan->obj);
1543 if (err)
1544 break;
1545 } while (next.vid < GLOBAL_VTU_VID_MASK);
1546
1547unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001548 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001549
1550 return err;
1551}
1552
Vivien Didelotfad09c72016-06-21 12:28:20 -04001553static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001554 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001555{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001556 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001557 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001558 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001559
Vivien Didelota935c052016-09-29 12:21:53 -04001560 err = _mv88e6xxx_vtu_wait(chip);
1561 if (err)
1562 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001563
1564 if (!entry->valid)
1565 goto loadpurge;
1566
1567 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001568 err = mv88e6xxx_vtu_data_write(chip, entry);
1569 if (err)
1570 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001571
Vivien Didelotfad09c72016-06-21 12:28:20 -04001572 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001573 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001574 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1575 if (err)
1576 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001577 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001578
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001579 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001580 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001581 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1582 if (err)
1583 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001584 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001585 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1586 * VTU DBNum[3:0] are located in VTU Operation 3:0
1587 */
1588 op |= (entry->fid & 0xf0) << 8;
1589 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001590 }
1591
1592 reg = GLOBAL_VTU_VID_VALID;
1593loadpurge:
1594 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001595 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1596 if (err)
1597 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001598
Vivien Didelotfad09c72016-06-21 12:28:20 -04001599 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001600}
1601
Vivien Didelotfad09c72016-06-21 12:28:20 -04001602static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001603 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001604{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001605 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001606 u16 val;
1607 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001608
Vivien Didelota935c052016-09-29 12:21:53 -04001609 err = _mv88e6xxx_vtu_wait(chip);
1610 if (err)
1611 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001612
Vivien Didelota935c052016-09-29 12:21:53 -04001613 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1614 sid & GLOBAL_VTU_SID_MASK);
1615 if (err)
1616 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001617
Vivien Didelota935c052016-09-29 12:21:53 -04001618 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1619 if (err)
1620 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001621
Vivien Didelota935c052016-09-29 12:21:53 -04001622 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1623 if (err)
1624 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001625
Vivien Didelota935c052016-09-29 12:21:53 -04001626 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001627
Vivien Didelota935c052016-09-29 12:21:53 -04001628 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1629 if (err)
1630 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001631
Vivien Didelota935c052016-09-29 12:21:53 -04001632 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001633
1634 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001635 err = mv88e6xxx_stu_data_read(chip, &next);
1636 if (err)
1637 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001638 }
1639
1640 *entry = next;
1641 return 0;
1642}
1643
Vivien Didelotfad09c72016-06-21 12:28:20 -04001644static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001645 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001646{
1647 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001648 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001649
Vivien Didelota935c052016-09-29 12:21:53 -04001650 err = _mv88e6xxx_vtu_wait(chip);
1651 if (err)
1652 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001653
1654 if (!entry->valid)
1655 goto loadpurge;
1656
1657 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001658 err = mv88e6xxx_stu_data_write(chip, entry);
1659 if (err)
1660 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001661
1662 reg = GLOBAL_VTU_VID_VALID;
1663loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001664 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1665 if (err)
1666 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001667
1668 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001669 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1670 if (err)
1671 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001672
Vivien Didelotfad09c72016-06-21 12:28:20 -04001673 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001674}
1675
Vivien Didelotfad09c72016-06-21 12:28:20 -04001676static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001677{
1678 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001679 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001680 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001681
1682 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1683
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001684 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001685 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001686 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001687 if (err)
1688 return err;
1689
1690 set_bit(*fid, fid_bitmap);
1691 }
1692
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001693 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001694 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001695 if (err)
1696 return err;
1697
1698 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001699 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001700 if (err)
1701 return err;
1702
1703 if (!vlan.valid)
1704 break;
1705
1706 set_bit(vlan.fid, fid_bitmap);
1707 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1708
1709 /* The reset value 0x000 is used to indicate that multiple address
1710 * databases are not needed. Return the next positive available.
1711 */
1712 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001713 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001714 return -ENOSPC;
1715
1716 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001717 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001718}
1719
Vivien Didelotfad09c72016-06-21 12:28:20 -04001720static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001721 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001722{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001723 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001724 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001725 .valid = true,
1726 .vid = vid,
1727 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001728 int i, err;
1729
Vivien Didelotfad09c72016-06-21 12:28:20 -04001730 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001731 if (err)
1732 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001733
Vivien Didelot3d131f02015-11-03 10:52:52 -05001734 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001735 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001736 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1737 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1738 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001739
Vivien Didelotfad09c72016-06-21 12:28:20 -04001740 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01001741 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip) ||
1742 mv88e6xxx_6341_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001743 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001744
1745 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1746 * implemented, only one STU entry is needed to cover all VTU
1747 * entries. Thus, validate the SID 0.
1748 */
1749 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001750 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001751 if (err)
1752 return err;
1753
1754 if (vstp.sid != vlan.sid || !vstp.valid) {
1755 memset(&vstp, 0, sizeof(vstp));
1756 vstp.valid = true;
1757 vstp.sid = vlan.sid;
1758
Vivien Didelotfad09c72016-06-21 12:28:20 -04001759 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001760 if (err)
1761 return err;
1762 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001763 }
1764
1765 *entry = vlan;
1766 return 0;
1767}
1768
Vivien Didelotfad09c72016-06-21 12:28:20 -04001769static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001770 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001771{
1772 int err;
1773
1774 if (!vid)
1775 return -EINVAL;
1776
Vivien Didelotfad09c72016-06-21 12:28:20 -04001777 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001778 if (err)
1779 return err;
1780
Vivien Didelotfad09c72016-06-21 12:28:20 -04001781 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001782 if (err)
1783 return err;
1784
1785 if (entry->vid != vid || !entry->valid) {
1786 if (!creat)
1787 return -EOPNOTSUPP;
1788 /* -ENOENT would've been more appropriate, but switchdev expects
1789 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1790 */
1791
Vivien Didelotfad09c72016-06-21 12:28:20 -04001792 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001793 }
1794
1795 return err;
1796}
1797
Vivien Didelotda9c3592016-02-12 12:09:40 -05001798static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1799 u16 vid_begin, u16 vid_end)
1800{
Vivien Didelot04bed142016-08-31 18:06:13 -04001801 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001802 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001803 int i, err;
1804
1805 if (!vid_begin)
1806 return -EOPNOTSUPP;
1807
Vivien Didelotfad09c72016-06-21 12:28:20 -04001808 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001809
Vivien Didelotfad09c72016-06-21 12:28:20 -04001810 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001811 if (err)
1812 goto unlock;
1813
1814 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001815 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001816 if (err)
1817 goto unlock;
1818
1819 if (!vlan.valid)
1820 break;
1821
1822 if (vlan.vid > vid_end)
1823 break;
1824
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001825 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001826 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1827 continue;
1828
Andrew Lunn66e28092016-12-11 21:07:19 +01001829 if (!ds->ports[port].netdev)
1830 continue;
1831
Vivien Didelotda9c3592016-02-12 12:09:40 -05001832 if (vlan.data[i] ==
1833 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1834 continue;
1835
Vivien Didelotfae8a252017-01-27 15:29:42 -05001836 if (ds->ports[i].bridge_dev ==
1837 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001838 break; /* same bridge, check next VLAN */
1839
Vivien Didelotfae8a252017-01-27 15:29:42 -05001840 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001841 continue;
1842
Andrew Lunnc8b09802016-06-04 21:16:57 +02001843 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001844 "hardware VLAN %d already used by %s\n",
1845 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001846 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001847 err = -EOPNOTSUPP;
1848 goto unlock;
1849 }
1850 } while (vlan.vid < vid_end);
1851
1852unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001853 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001854
1855 return err;
1856}
1857
Vivien Didelotf81ec902016-05-09 13:22:58 -04001858static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1859 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001860{
Vivien Didelot04bed142016-08-31 18:06:13 -04001861 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001862 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001863 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001864 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001865
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 Didelot385a0992016-11-04 03:23:31 +01001870 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001871 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001872
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001873 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001874}
1875
Vivien Didelot57d32312016-06-20 13:13:58 -04001876static int
1877mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1878 const struct switchdev_obj_port_vlan *vlan,
1879 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001880{
Vivien Didelot04bed142016-08-31 18:06:13 -04001881 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001882 int err;
1883
Vivien Didelotfad09c72016-06-21 12:28:20 -04001884 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001885 return -EOPNOTSUPP;
1886
Vivien Didelotda9c3592016-02-12 12:09:40 -05001887 /* If the requested port doesn't belong to the same bridge as the VLAN
1888 * members, do not support it (yet) and fallback to software VLAN.
1889 */
1890 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1891 vlan->vid_end);
1892 if (err)
1893 return err;
1894
Vivien Didelot76e398a2015-11-01 12:33:55 -05001895 /* We don't need any dynamic resource from the kernel (yet),
1896 * so skip the prepare phase.
1897 */
1898 return 0;
1899}
1900
Vivien Didelotfad09c72016-06-21 12:28:20 -04001901static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001902 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001903{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001904 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001905 int err;
1906
Vivien Didelotfad09c72016-06-21 12:28:20 -04001907 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001908 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001909 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001910
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001911 vlan.data[port] = untagged ?
1912 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1913 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1914
Vivien Didelotfad09c72016-06-21 12:28:20 -04001915 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001916}
1917
Vivien Didelotf81ec902016-05-09 13:22:58 -04001918static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1919 const struct switchdev_obj_port_vlan *vlan,
1920 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001921{
Vivien Didelot04bed142016-08-31 18:06:13 -04001922 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001923 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1924 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1925 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001926
Vivien Didelotfad09c72016-06-21 12:28:20 -04001927 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001928 return;
1929
Vivien Didelotfad09c72016-06-21 12:28:20 -04001930 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001931
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001932 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001933 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001934 netdev_err(ds->ports[port].netdev,
1935 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001936 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001937
Vivien Didelot77064f32016-11-04 03:23:30 +01001938 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001939 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001940 vlan->vid_end);
1941
Vivien Didelotfad09c72016-06-21 12:28:20 -04001942 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001943}
1944
Vivien Didelotfad09c72016-06-21 12:28:20 -04001945static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001946 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001947{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001948 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001949 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001950 int i, err;
1951
Vivien Didelotfad09c72016-06-21 12:28:20 -04001952 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001953 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001954 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001955
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001956 /* Tell switchdev if this VLAN is handled in software */
1957 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001958 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001959
1960 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1961
1962 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001963 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001964 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001965 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001966 continue;
1967
1968 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001969 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001970 break;
1971 }
1972 }
1973
Vivien Didelotfad09c72016-06-21 12:28:20 -04001974 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001975 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001976 return err;
1977
Vivien Didelotfad09c72016-06-21 12:28:20 -04001978 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001979}
1980
Vivien Didelotf81ec902016-05-09 13:22:58 -04001981static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1982 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001983{
Vivien Didelot04bed142016-08-31 18:06:13 -04001984 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001985 u16 pvid, vid;
1986 int err = 0;
1987
Vivien Didelotfad09c72016-06-21 12:28:20 -04001988 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001989 return -EOPNOTSUPP;
1990
Vivien Didelotfad09c72016-06-21 12:28:20 -04001991 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001992
Vivien Didelot77064f32016-11-04 03:23:30 +01001993 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001994 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001995 goto unlock;
1996
Vivien Didelot76e398a2015-11-01 12:33:55 -05001997 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001998 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001999 if (err)
2000 goto unlock;
2001
2002 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01002003 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002004 if (err)
2005 goto unlock;
2006 }
2007 }
2008
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002009unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002010 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002011
2012 return err;
2013}
2014
Vivien Didelot83dabd12016-08-31 11:50:04 -04002015static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2016 const unsigned char *addr, u16 vid,
2017 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002018{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002019 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002020 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002021 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002022
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002023 /* Null VLAN ID corresponds to the port private database */
2024 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002025 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002026 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002027 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002028 if (err)
2029 return err;
2030
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002031 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2032 ether_addr_copy(entry.mac, addr);
2033 eth_addr_dec(entry.mac);
2034
2035 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04002036 if (err)
2037 return err;
2038
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002039 /* Initialize a fresh ATU entry if it isn't found */
2040 if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
2041 !ether_addr_equal(entry.mac, addr)) {
2042 memset(&entry, 0, sizeof(entry));
2043 ether_addr_copy(entry.mac, addr);
2044 }
2045
Vivien Didelot88472932016-09-19 19:56:11 -04002046 /* Purge the ATU entry only if no port is using it anymore */
2047 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2048 entry.portv_trunkid &= ~BIT(port);
2049 if (!entry.portv_trunkid)
2050 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2051 } else {
2052 entry.portv_trunkid |= BIT(port);
2053 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002054 }
2055
Vivien Didelot9c13c022017-03-11 16:12:52 -05002056 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002057}
2058
Vivien Didelotf81ec902016-05-09 13:22:58 -04002059static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2060 const struct switchdev_obj_port_fdb *fdb,
2061 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002062{
2063 /* We don't need any dynamic resource from the kernel (yet),
2064 * so skip the prepare phase.
2065 */
2066 return 0;
2067}
2068
Vivien Didelotf81ec902016-05-09 13:22:58 -04002069static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2070 const struct switchdev_obj_port_fdb *fdb,
2071 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002072{
Vivien Didelot04bed142016-08-31 18:06:13 -04002073 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002074
Vivien Didelotfad09c72016-06-21 12:28:20 -04002075 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002076 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2077 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2078 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002079 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002080}
2081
Vivien Didelotf81ec902016-05-09 13:22:58 -04002082static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2083 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002084{
Vivien Didelot04bed142016-08-31 18:06:13 -04002085 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002086 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002087
Vivien Didelotfad09c72016-06-21 12:28:20 -04002088 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002089 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2090 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002091 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002092
Vivien Didelot83dabd12016-08-31 11:50:04 -04002093 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002094}
2095
Vivien Didelot83dabd12016-08-31 11:50:04 -04002096static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2097 u16 fid, u16 vid, int port,
2098 struct switchdev_obj *obj,
2099 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002100{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002101 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002102 int err;
2103
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002104 addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2105 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002106
2107 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002108 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002109 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002110 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002111
2112 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2113 break;
2114
Vivien Didelot83dabd12016-08-31 11:50:04 -04002115 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2116 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002117
Vivien Didelot83dabd12016-08-31 11:50:04 -04002118 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2119 struct switchdev_obj_port_fdb *fdb;
2120
2121 if (!is_unicast_ether_addr(addr.mac))
2122 continue;
2123
2124 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002125 fdb->vid = vid;
2126 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002127 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2128 fdb->ndm_state = NUD_NOARP;
2129 else
2130 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002131 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2132 struct switchdev_obj_port_mdb *mdb;
2133
2134 if (!is_multicast_ether_addr(addr.mac))
2135 continue;
2136
2137 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2138 mdb->vid = vid;
2139 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002140 } else {
2141 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002142 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002143
2144 err = cb(obj);
2145 if (err)
2146 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002147 } while (!is_broadcast_ether_addr(addr.mac));
2148
2149 return err;
2150}
2151
Vivien Didelot83dabd12016-08-31 11:50:04 -04002152static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2153 struct switchdev_obj *obj,
2154 int (*cb)(struct switchdev_obj *obj))
2155{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002156 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002157 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2158 };
2159 u16 fid;
2160 int err;
2161
2162 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002163 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002164 if (err)
2165 return err;
2166
2167 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2168 if (err)
2169 return err;
2170
2171 /* Dump VLANs' Filtering Information Databases */
2172 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2173 if (err)
2174 return err;
2175
2176 do {
2177 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2178 if (err)
2179 return err;
2180
2181 if (!vlan.valid)
2182 break;
2183
2184 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2185 obj, cb);
2186 if (err)
2187 return err;
2188 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2189
2190 return err;
2191}
2192
Vivien Didelotf81ec902016-05-09 13:22:58 -04002193static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2194 struct switchdev_obj_port_fdb *fdb,
2195 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002196{
Vivien Didelot04bed142016-08-31 18:06:13 -04002197 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002198 int err;
2199
Vivien Didelotfad09c72016-06-21 12:28:20 -04002200 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002201 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002202 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002203
2204 return err;
2205}
2206
Vivien Didelotf81ec902016-05-09 13:22:58 -04002207static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002208 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002209{
Vivien Didelot04bed142016-08-31 18:06:13 -04002210 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002211 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002212
Vivien Didelotfad09c72016-06-21 12:28:20 -04002213 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002214
Vivien Didelotfae8a252017-01-27 15:29:42 -05002215 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002216 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfae8a252017-01-27 15:29:42 -05002217 if (ds->ports[i].bridge_dev == br) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002218 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002219 if (err)
2220 break;
2221 }
2222 }
2223
Vivien Didelotfad09c72016-06-21 12:28:20 -04002224 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002225
Vivien Didelot466dfa02016-02-26 13:16:05 -05002226 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002227}
2228
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002229static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2230 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002231{
Vivien Didelot04bed142016-08-31 18:06:13 -04002232 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002233 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002234
Vivien Didelotfad09c72016-06-21 12:28:20 -04002235 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002236
Vivien Didelotfae8a252017-01-27 15:29:42 -05002237 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002238 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfae8a252017-01-27 15:29:42 -05002239 if (i == port || ds->ports[i].bridge_dev == br)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002240 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002241 netdev_warn(ds->ports[i].netdev,
2242 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002243
Vivien Didelotfad09c72016-06-21 12:28:20 -04002244 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002245}
2246
Vivien Didelot17e708b2016-12-05 17:30:27 -05002247static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2248{
2249 if (chip->info->ops->reset)
2250 return chip->info->ops->reset(chip);
2251
2252 return 0;
2253}
2254
Vivien Didelot309eca62016-12-05 17:30:26 -05002255static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2256{
2257 struct gpio_desc *gpiod = chip->reset;
2258
2259 /* If there is a GPIO connected to the reset pin, toggle it */
2260 if (gpiod) {
2261 gpiod_set_value_cansleep(gpiod, 1);
2262 usleep_range(10000, 20000);
2263 gpiod_set_value_cansleep(gpiod, 0);
2264 usleep_range(10000, 20000);
2265 }
2266}
2267
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002268static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2269{
2270 int i, err;
2271
2272 /* Set all ports to the Disabled state */
2273 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2274 err = mv88e6xxx_port_set_state(chip, i,
2275 PORT_CONTROL_STATE_DISABLED);
2276 if (err)
2277 return err;
2278 }
2279
2280 /* Wait for transmit queues to drain,
2281 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2282 */
2283 usleep_range(2000, 4000);
2284
2285 return 0;
2286}
2287
Vivien Didelotfad09c72016-06-21 12:28:20 -04002288static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002289{
Vivien Didelota935c052016-09-29 12:21:53 -04002290 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002291
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002292 err = mv88e6xxx_disable_ports(chip);
2293 if (err)
2294 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002295
Vivien Didelot309eca62016-12-05 17:30:26 -05002296 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002297
Vivien Didelot17e708b2016-12-05 17:30:27 -05002298 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002299}
2300
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002301static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002302{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002303 u16 val;
2304 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002305
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002306 /* Clear Power Down bit */
2307 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2308 if (err)
2309 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002310
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002311 if (val & BMCR_PDOWN) {
2312 val &= ~BMCR_PDOWN;
2313 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002314 }
2315
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002316 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002317}
2318
Andrew Lunn56995cb2016-12-03 04:35:19 +01002319static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2320 int upstream_port)
2321{
2322 int err;
2323
2324 err = chip->info->ops->port_set_frame_mode(
2325 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2326 if (err)
2327 return err;
2328
2329 return chip->info->ops->port_set_egress_unknowns(
2330 chip, port, port == upstream_port);
2331}
2332
2333static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2334{
2335 int err;
2336
2337 switch (chip->info->tag_protocol) {
2338 case DSA_TAG_PROTO_EDSA:
2339 err = chip->info->ops->port_set_frame_mode(
2340 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2341 if (err)
2342 return err;
2343
2344 err = mv88e6xxx_port_set_egress_mode(
2345 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2346 if (err)
2347 return err;
2348
2349 if (chip->info->ops->port_set_ether_type)
2350 err = chip->info->ops->port_set_ether_type(
2351 chip, port, ETH_P_EDSA);
2352 break;
2353
2354 case DSA_TAG_PROTO_DSA:
2355 err = chip->info->ops->port_set_frame_mode(
2356 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2357 if (err)
2358 return err;
2359
2360 err = mv88e6xxx_port_set_egress_mode(
2361 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2362 break;
2363 default:
2364 err = -EINVAL;
2365 }
2366
2367 if (err)
2368 return err;
2369
2370 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2371}
2372
2373static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2374{
2375 int err;
2376
2377 err = chip->info->ops->port_set_frame_mode(
2378 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2379 if (err)
2380 return err;
2381
2382 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2383}
2384
Vivien Didelotea698f42017-03-11 16:12:50 -05002385static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2386{
2387 bool message = dsa_is_dsa_port(chip->ds, port);
2388
2389 return mv88e6xxx_port_set_message_port(chip, port, message);
2390}
2391
Vivien Didelotfad09c72016-06-21 12:28:20 -04002392static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002393{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002394 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002395 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002396 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002397
Vivien Didelotd78343d2016-11-04 03:23:36 +01002398 /* MAC Forcing register: don't force link, speed, duplex or flow control
2399 * state to any particular values on physical ports, but force the CPU
2400 * port and all DSA ports to their maximum bandwidth and full duplex.
2401 */
2402 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2403 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2404 SPEED_MAX, DUPLEX_FULL,
2405 PHY_INTERFACE_MODE_NA);
2406 else
2407 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2408 SPEED_UNFORCED, DUPLEX_UNFORCED,
2409 PHY_INTERFACE_MODE_NA);
2410 if (err)
2411 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002412
2413 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2414 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2415 * tunneling, determine priority by looking at 802.1p and IP
2416 * priority fields (IP prio has precedence), and set STP state
2417 * to Forwarding.
2418 *
2419 * If this is the CPU link, use DSA or EDSA tagging depending
2420 * on which tagging mode was configured.
2421 *
2422 * If this is a link to another switch, use DSA tagging mode.
2423 *
2424 * If this is the upstream port for this switch, enable
2425 * forwarding of unknown unicasts and multicasts.
2426 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002427 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002428 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2429 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002430 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2431 if (err)
2432 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002433
Andrew Lunn56995cb2016-12-03 04:35:19 +01002434 if (dsa_is_cpu_port(ds, port)) {
2435 err = mv88e6xxx_setup_port_cpu(chip, port);
2436 } else if (dsa_is_dsa_port(ds, port)) {
2437 err = mv88e6xxx_setup_port_dsa(chip, port,
2438 dsa_upstream_port(ds));
2439 } else {
2440 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002441 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002442 if (err)
2443 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002444
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002445 /* If this port is connected to a SerDes, make sure the SerDes is not
2446 * powered down.
2447 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002448 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002449 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2450 if (err)
2451 return err;
2452 reg &= PORT_STATUS_CMODE_MASK;
2453 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2454 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2455 (reg == PORT_STATUS_CMODE_SGMII)) {
2456 err = mv88e6xxx_serdes_power_on(chip);
2457 if (err < 0)
2458 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002459 }
2460 }
2461
Vivien Didelot8efdda42015-08-13 12:52:23 -04002462 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002463 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002464 * untagged frames on this port, do a destination address lookup on all
2465 * received packets as usual, disable ARP mirroring and don't send a
2466 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002467 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002468 err = mv88e6xxx_port_set_map_da(chip, port);
2469 if (err)
2470 return err;
2471
Andrew Lunn54d792f2015-05-06 01:09:47 +02002472 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01002473 if (chip->info->ops->port_set_upstream_port) {
2474 err = chip->info->ops->port_set_upstream_port(
2475 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002476 if (err)
2477 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002478 }
2479
Andrew Lunna23b2962017-02-04 20:15:28 +01002480 err = mv88e6xxx_port_set_8021q_mode(chip, port,
2481 PORT_CONTROL_2_8021Q_DISABLED);
2482 if (err)
2483 return err;
2484
Andrew Lunn5f436662016-12-03 04:45:17 +01002485 if (chip->info->ops->port_jumbo_config) {
2486 err = chip->info->ops->port_jumbo_config(chip, port);
2487 if (err)
2488 return err;
2489 }
2490
Andrew Lunn54d792f2015-05-06 01:09:47 +02002491 /* Port Association Vector: when learning source addresses
2492 * of packets, add the address to the address database using
2493 * a port bitmap that has only the bit for this port set and
2494 * the other bits clear.
2495 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002496 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002497 /* Disable learning for CPU port */
2498 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002499 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002500
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002501 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2502 if (err)
2503 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002504
2505 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002506 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2507 if (err)
2508 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002509
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002510 if (chip->info->ops->port_pause_config) {
2511 err = chip->info->ops->port_pause_config(chip, port);
2512 if (err)
2513 return err;
2514 }
2515
Vivien Didelotfad09c72016-06-21 12:28:20 -04002516 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2517 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01002518 mv88e6xxx_6320_family(chip) || mv88e6xxx_6341_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002519 /* Port ATU control: disable limiting the number of
2520 * address database entries that this port is allowed
2521 * to use.
2522 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002523 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2524 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002525 /* Priority Override: disable DA, SA and VTU priority
2526 * override.
2527 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002528 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2529 0x0000);
2530 if (err)
2531 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002532 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002533
Andrew Lunnef0a7312016-12-03 04:35:16 +01002534 if (chip->info->ops->port_tag_remap) {
2535 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002536 if (err)
2537 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002538 }
2539
Andrew Lunnef70b112016-12-03 04:45:18 +01002540 if (chip->info->ops->port_egress_rate_limiting) {
2541 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002542 if (err)
2543 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002544 }
2545
Vivien Didelotea698f42017-03-11 16:12:50 -05002546 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002547 if (err)
2548 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002549
Vivien Didelot207afda2016-04-14 14:42:09 -04002550 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002551 * database, and allow bidirectional communication between the
2552 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002553 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002554 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002555 if (err)
2556 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002557
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002558 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2559 if (err)
2560 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002561
2562 /* Default VLAN ID and priority: don't set a default VLAN
2563 * ID, and set the default packet priority to zero.
2564 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002565 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002566}
2567
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002568static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002569{
2570 int err;
2571
Vivien Didelota935c052016-09-29 12:21:53 -04002572 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002573 if (err)
2574 return err;
2575
Vivien Didelota935c052016-09-29 12:21:53 -04002576 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002577 if (err)
2578 return err;
2579
Vivien Didelota935c052016-09-29 12:21:53 -04002580 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2581 if (err)
2582 return err;
2583
2584 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002585}
2586
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002587static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2588 unsigned int ageing_time)
2589{
Vivien Didelot04bed142016-08-31 18:06:13 -04002590 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002591 int err;
2592
2593 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002594 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002595 mutex_unlock(&chip->reg_lock);
2596
2597 return err;
2598}
2599
Vivien Didelot97299342016-07-18 20:45:30 -04002600static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002601{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002602 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002603 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002604 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002605
Vivien Didelot119477b2016-05-09 13:22:51 -04002606 /* Enable the PHY Polling Unit if present, don't discard any packets,
2607 * and mask all interrupt sources.
2608 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002609 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002610 if (err)
2611 return err;
2612
Andrew Lunn33641992016-12-03 04:35:17 +01002613 if (chip->info->ops->g1_set_cpu_port) {
2614 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2615 if (err)
2616 return err;
2617 }
2618
2619 if (chip->info->ops->g1_set_egress_port) {
2620 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2621 if (err)
2622 return err;
2623 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002624
Vivien Didelot50484ff2016-05-09 13:22:54 -04002625 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002626 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2627 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2628 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002629 if (err)
2630 return err;
2631
Vivien Didelotacddbd22016-07-18 20:45:39 -04002632 /* Clear all the VTU and STU entries */
2633 err = _mv88e6xxx_vtu_stu_flush(chip);
2634 if (err < 0)
2635 return err;
2636
Vivien Didelot97299342016-07-18 20:45:30 -04002637 /* Clear all ATU entries */
2638 err = _mv88e6xxx_atu_flush(chip, 0, true);
2639 if (err)
2640 return err;
2641
Vivien Didelot08a01262016-05-09 13:22:50 -04002642 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002643 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002644 if (err)
2645 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002646 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002647 if (err)
2648 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002649 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002650 if (err)
2651 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002652 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002653 if (err)
2654 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002655 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002656 if (err)
2657 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002658 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002659 if (err)
2660 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002661 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002662 if (err)
2663 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002664 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002665 if (err)
2666 return err;
2667
2668 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002669 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002670 if (err)
2671 return err;
2672
Andrew Lunnde2273872016-11-21 23:27:01 +01002673 /* Initialize the statistics unit */
2674 err = mv88e6xxx_stats_set_histogram(chip);
2675 if (err)
2676 return err;
2677
Vivien Didelot97299342016-07-18 20:45:30 -04002678 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002679 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2680 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002681 if (err)
2682 return err;
2683
2684 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002685 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002686 if (err)
2687 return err;
2688
2689 return 0;
2690}
2691
Vivien Didelotf81ec902016-05-09 13:22:58 -04002692static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002693{
Vivien Didelot04bed142016-08-31 18:06:13 -04002694 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002695 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002696 int i;
2697
Vivien Didelotfad09c72016-06-21 12:28:20 -04002698 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002699 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002700
Vivien Didelotfad09c72016-06-21 12:28:20 -04002701 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002702
Vivien Didelot97299342016-07-18 20:45:30 -04002703 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002704 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002705 err = mv88e6xxx_setup_port(chip, i);
2706 if (err)
2707 goto unlock;
2708 }
2709
2710 /* Setup Switch Global 1 Registers */
2711 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002712 if (err)
2713 goto unlock;
2714
Vivien Didelot97299342016-07-18 20:45:30 -04002715 /* Setup Switch Global 2 Registers */
2716 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2717 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002718 if (err)
2719 goto unlock;
2720 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002721
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002722 err = mv88e6xxx_atu_setup(chip);
2723 if (err)
2724 goto unlock;
2725
Andrew Lunn6e55f692016-12-03 04:45:16 +01002726 /* Some generations have the configuration of sending reserved
2727 * management frames to the CPU in global2, others in
2728 * global1. Hence it does not fit the two setup functions
2729 * above.
2730 */
2731 if (chip->info->ops->mgmt_rsvd2cpu) {
2732 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2733 if (err)
2734 goto unlock;
2735 }
2736
Vivien Didelot6b17e862015-08-13 12:52:18 -04002737unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002738 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002739
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002740 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002741}
2742
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002743static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2744{
Vivien Didelot04bed142016-08-31 18:06:13 -04002745 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002746 int err;
2747
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002748 if (!chip->info->ops->set_switch_mac)
2749 return -EOPNOTSUPP;
2750
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002751 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002752 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002753 mutex_unlock(&chip->reg_lock);
2754
2755 return err;
2756}
2757
Vivien Didelote57e5e72016-08-15 17:19:00 -04002758static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002759{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002760 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2761 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002762 u16 val;
2763 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002764
Andrew Lunnee26a222017-01-24 14:53:48 +01002765 if (!chip->info->ops->phy_read)
2766 return -EOPNOTSUPP;
2767
Vivien Didelotfad09c72016-06-21 12:28:20 -04002768 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002769 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002770 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002771
Andrew Lunnda9f3302017-02-01 03:40:05 +01002772 if (reg == MII_PHYSID2) {
2773 /* Some internal PHYS don't have a model number. Use
2774 * the mv88e6390 family model number instead.
2775 */
2776 if (!(val & 0x3f0))
2777 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2778 }
2779
Vivien Didelote57e5e72016-08-15 17:19:00 -04002780 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002781}
2782
Vivien Didelote57e5e72016-08-15 17:19:00 -04002783static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002784{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002785 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2786 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002787 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002788
Andrew Lunnee26a222017-01-24 14:53:48 +01002789 if (!chip->info->ops->phy_write)
2790 return -EOPNOTSUPP;
2791
Vivien Didelotfad09c72016-06-21 12:28:20 -04002792 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002793 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002794 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002795
2796 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002797}
2798
Vivien Didelotfad09c72016-06-21 12:28:20 -04002799static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002800 struct device_node *np,
2801 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002802{
2803 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002804 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002805 struct mii_bus *bus;
2806 int err;
2807
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002808 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002809 if (!bus)
2810 return -ENOMEM;
2811
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002812 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002813 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002814 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002815 INIT_LIST_HEAD(&mdio_bus->list);
2816 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002817
Andrew Lunnb516d452016-06-04 21:17:06 +02002818 if (np) {
2819 bus->name = np->full_name;
2820 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2821 } else {
2822 bus->name = "mv88e6xxx SMI";
2823 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2824 }
2825
2826 bus->read = mv88e6xxx_mdio_read;
2827 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002828 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002829
Andrew Lunna3c53be52017-01-24 14:53:50 +01002830 if (np)
2831 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002832 else
2833 err = mdiobus_register(bus);
2834 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002835 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002836 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002837 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002838
2839 if (external)
2840 list_add_tail(&mdio_bus->list, &chip->mdios);
2841 else
2842 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002843
2844 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002845}
2846
Andrew Lunna3c53be52017-01-24 14:53:50 +01002847static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2848 { .compatible = "marvell,mv88e6xxx-mdio-external",
2849 .data = (void *)true },
2850 { },
2851};
2852
2853static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2854 struct device_node *np)
2855{
2856 const struct of_device_id *match;
2857 struct device_node *child;
2858 int err;
2859
2860 /* Always register one mdio bus for the internal/default mdio
2861 * bus. This maybe represented in the device tree, but is
2862 * optional.
2863 */
2864 child = of_get_child_by_name(np, "mdio");
2865 err = mv88e6xxx_mdio_register(chip, child, false);
2866 if (err)
2867 return err;
2868
2869 /* Walk the device tree, and see if there are any other nodes
2870 * which say they are compatible with the external mdio
2871 * bus.
2872 */
2873 for_each_available_child_of_node(np, child) {
2874 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2875 if (match) {
2876 err = mv88e6xxx_mdio_register(chip, child, true);
2877 if (err)
2878 return err;
2879 }
2880 }
2881
2882 return 0;
2883}
2884
2885static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002886
2887{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002888 struct mv88e6xxx_mdio_bus *mdio_bus;
2889 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002890
Andrew Lunna3c53be52017-01-24 14:53:50 +01002891 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2892 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002893
Andrew Lunna3c53be52017-01-24 14:53:50 +01002894 mdiobus_unregister(bus);
2895 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002896}
2897
Vivien Didelot855b1932016-07-20 18:18:35 -04002898static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2899{
Vivien Didelot04bed142016-08-31 18:06:13 -04002900 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002901
2902 return chip->eeprom_len;
2903}
2904
Vivien Didelot855b1932016-07-20 18:18:35 -04002905static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2906 struct ethtool_eeprom *eeprom, u8 *data)
2907{
Vivien Didelot04bed142016-08-31 18:06:13 -04002908 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002909 int err;
2910
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002911 if (!chip->info->ops->get_eeprom)
2912 return -EOPNOTSUPP;
2913
Vivien Didelot855b1932016-07-20 18:18:35 -04002914 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002915 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002916 mutex_unlock(&chip->reg_lock);
2917
2918 if (err)
2919 return err;
2920
2921 eeprom->magic = 0xc3ec4951;
2922
2923 return 0;
2924}
2925
Vivien Didelot855b1932016-07-20 18:18:35 -04002926static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2927 struct ethtool_eeprom *eeprom, u8 *data)
2928{
Vivien Didelot04bed142016-08-31 18:06:13 -04002929 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002930 int err;
2931
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002932 if (!chip->info->ops->set_eeprom)
2933 return -EOPNOTSUPP;
2934
Vivien Didelot855b1932016-07-20 18:18:35 -04002935 if (eeprom->magic != 0xc3ec4951)
2936 return -EINVAL;
2937
2938 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002939 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002940 mutex_unlock(&chip->reg_lock);
2941
2942 return err;
2943}
2944
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002945static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002946 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002947 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002948 .phy_read = mv88e6xxx_phy_ppu_read,
2949 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002950 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002951 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002952 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002953 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002954 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2955 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
2956 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002957 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002958 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002959 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002960 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2961 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002962 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002963 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2964 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002965 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002966 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002967 .ppu_enable = mv88e6185_g1_ppu_enable,
2968 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002969 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002970};
2971
2972static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002973 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002974 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002975 .phy_read = mv88e6xxx_phy_ppu_read,
2976 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002977 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002978 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002979 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002980 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01002981 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
2982 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002983 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002984 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2985 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002986 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002987 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002988 .ppu_enable = mv88e6185_g1_ppu_enable,
2989 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002990 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002991};
2992
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002993static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002994 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002995 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2996 .phy_read = mv88e6xxx_g2_smi_phy_read,
2997 .phy_write = mv88e6xxx_g2_smi_phy_write,
2998 .port_set_link = mv88e6xxx_port_set_link,
2999 .port_set_duplex = mv88e6xxx_port_set_duplex,
3000 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003001 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003002 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3003 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3004 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003005 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003006 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003007 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003008 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3009 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3010 .stats_get_strings = mv88e6095_stats_get_strings,
3011 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003012 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3013 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003014 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003015 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003016 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003017};
3018
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003019static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003020 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003021 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003022 .phy_read = mv88e6165_phy_read,
3023 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003024 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003025 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003026 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003027 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3028 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003029 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003030 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3031 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003032 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003033 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3034 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003035 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003036 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003037 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003038};
3039
3040static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003041 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003042 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003043 .phy_read = mv88e6xxx_phy_ppu_read,
3044 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003045 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003046 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003047 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003048 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003049 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01003050 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003051 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003052 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01003053 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003054 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003055 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003056 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003057 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3058 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003059 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003060 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3061 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003062 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003063 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003064 .ppu_enable = mv88e6185_g1_ppu_enable,
3065 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003066 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003067};
3068
3069static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003070 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003071 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003072 .phy_read = mv88e6165_phy_read,
3073 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003074 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003075 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003076 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003077 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003078 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3079 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3080 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003081 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003082 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003083 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003084 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003085 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3086 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003087 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003088 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3089 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003090 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003091 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003092 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003093};
3094
3095static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003096 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003097 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003098 .phy_read = mv88e6165_phy_read,
3099 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003100 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003101 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003102 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003103 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003104 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3105 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003106 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003107 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3108 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003109 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003110 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003111 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003112};
3113
3114static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003115 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003116 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003117 .phy_read = mv88e6xxx_g2_smi_phy_read,
3118 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003119 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003120 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003121 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003122 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003123 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003124 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3125 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3126 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003127 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003128 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003129 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003130 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003131 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3132 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003133 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003134 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3135 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003136 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003137 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003138 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003139};
3140
3141static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003142 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003143 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3144 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003145 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003146 .phy_read = mv88e6xxx_g2_smi_phy_read,
3147 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003148 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003149 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003150 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003151 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003152 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003153 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3154 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3155 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003156 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003157 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003158 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003159 .stats_snapshot = mv88e6320_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 Didelot17e708b2016-12-05 17:30:27 -05003167 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003168};
3169
3170static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003171 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003172 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003173 .phy_read = mv88e6xxx_g2_smi_phy_read,
3174 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003175 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003176 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003177 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003178 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003179 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003180 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3181 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3182 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003183 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003184 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003185 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003186 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003187 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3188 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003189 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003190 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3191 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003192 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003193 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003194 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003195};
3196
3197static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003198 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003199 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3200 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003201 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003202 .phy_read = mv88e6xxx_g2_smi_phy_read,
3203 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003204 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003205 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003206 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003207 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003208 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003209 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3210 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3211 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003212 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003213 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003214 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003215 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003216 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3217 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003218 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003219 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3220 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003221 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003222 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003223 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003224};
3225
3226static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003227 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003228 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003229 .phy_read = mv88e6xxx_phy_ppu_read,
3230 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003231 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003232 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003233 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003234 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01003235 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003236 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003237 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003238 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003239 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3240 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003241 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003242 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3243 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003244 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003245 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003246 .ppu_enable = mv88e6185_g1_ppu_enable,
3247 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003248 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003249};
3250
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003251static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003252 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003253 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3254 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003255 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3256 .phy_read = mv88e6xxx_g2_smi_phy_read,
3257 .phy_write = mv88e6xxx_g2_smi_phy_write,
3258 .port_set_link = mv88e6xxx_port_set_link,
3259 .port_set_duplex = mv88e6xxx_port_set_duplex,
3260 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3261 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003262 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003263 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3264 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3265 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003266 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003267 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003268 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003269 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3270 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003271 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003272 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3273 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003274 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003275 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003276 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003277};
3278
3279static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003280 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003281 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3282 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003283 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3284 .phy_read = mv88e6xxx_g2_smi_phy_read,
3285 .phy_write = mv88e6xxx_g2_smi_phy_write,
3286 .port_set_link = mv88e6xxx_port_set_link,
3287 .port_set_duplex = mv88e6xxx_port_set_duplex,
3288 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3289 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003290 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003291 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3292 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3293 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003294 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003295 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003296 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003297 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3298 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003299 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003300 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3301 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003302 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003303 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003304 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003305};
3306
3307static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003308 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003309 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3310 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003311 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3312 .phy_read = mv88e6xxx_g2_smi_phy_read,
3313 .phy_write = mv88e6xxx_g2_smi_phy_write,
3314 .port_set_link = mv88e6xxx_port_set_link,
3315 .port_set_duplex = mv88e6xxx_port_set_duplex,
3316 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3317 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003318 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003319 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3320 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3321 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003322 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003323 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003324 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003325 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3326 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003327 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003328 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3329 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003330 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003331 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003332 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003333};
3334
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003335static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003336 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003337 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3338 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003339 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003340 .phy_read = mv88e6xxx_g2_smi_phy_read,
3341 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003342 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003343 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003344 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003345 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003346 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003347 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3348 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3349 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003350 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003351 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003352 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003353 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003354 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3355 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003356 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003357 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3358 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003359 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003360 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003361 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003362};
3363
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003364static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003365 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003366 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3367 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003368 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3369 .phy_read = mv88e6xxx_g2_smi_phy_read,
3370 .phy_write = mv88e6xxx_g2_smi_phy_write,
3371 .port_set_link = mv88e6xxx_port_set_link,
3372 .port_set_duplex = mv88e6xxx_port_set_duplex,
3373 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3374 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003375 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003376 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3377 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3378 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003379 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003380 .port_set_cmode = mv88e6390x_port_set_cmode,
Andrew Lunn79523472016-11-21 23:27:00 +01003381 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003382 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003383 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3384 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003385 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003386 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3387 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003388 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003389 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003390 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003391};
3392
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003393static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003394 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003395 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3396 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003397 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003398 .phy_read = mv88e6xxx_g2_smi_phy_read,
3399 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003400 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003401 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003402 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003403 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003404 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3405 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3406 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003407 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003408 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003409 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003410 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003411 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3412 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003413 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003414 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3415 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003416 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003417 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003418};
3419
3420static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003421 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003422 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3423 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003424 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003425 .phy_read = mv88e6xxx_g2_smi_phy_read,
3426 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003427 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003428 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003429 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003430 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003431 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3432 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3433 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003434 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003435 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003436 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003437 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003438 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3439 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003440 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003441 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3442 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003443 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003444};
3445
3446static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003447 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003448 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003449 .phy_read = mv88e6xxx_g2_smi_phy_read,
3450 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003451 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003452 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003453 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003454 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003455 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003456 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3457 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3458 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003459 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003460 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003461 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003462 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003463 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3464 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003465 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003466 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3467 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003468 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003469 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003470 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003471};
3472
3473static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003474 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003475 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003476 .phy_read = mv88e6xxx_g2_smi_phy_read,
3477 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003478 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003479 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003480 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003481 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003482 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003483 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3484 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3485 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003486 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003487 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003488 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003489 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003490 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3491 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003492 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003493 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3494 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003495 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003496 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003497 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003498};
3499
3500static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003501 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003502 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3503 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003504 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003505 .phy_read = mv88e6xxx_g2_smi_phy_read,
3506 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003507 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003508 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003509 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003510 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003511 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003512 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3513 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3514 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003515 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003516 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003517 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003518 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003519 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3520 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003521 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003522 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3523 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003524 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003525 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003526 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003527};
3528
Gregory CLEMENT15587272017-01-30 20:29:35 +01003529static const struct mv88e6xxx_ops mv88e6141_ops = {
3530 /* MV88E6XXX_FAMILY_6341 */
3531 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3532 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3533 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3534 .phy_read = mv88e6xxx_g2_smi_phy_read,
3535 .phy_write = mv88e6xxx_g2_smi_phy_write,
3536 .port_set_link = mv88e6xxx_port_set_link,
3537 .port_set_duplex = mv88e6xxx_port_set_duplex,
3538 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3539 .port_set_speed = mv88e6390_port_set_speed,
3540 .port_tag_remap = mv88e6095_port_tag_remap,
3541 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3542 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3543 .port_set_ether_type = mv88e6351_port_set_ether_type,
3544 .port_jumbo_config = mv88e6165_port_jumbo_config,
3545 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3546 .port_pause_config = mv88e6097_port_pause_config,
3547 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3548 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3549 .stats_get_strings = mv88e6320_stats_get_strings,
3550 .stats_get_stats = mv88e6390_stats_get_stats,
3551 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3552 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003553 .watchdog_ops = &mv88e6390_watchdog_ops,
Gregory CLEMENT15587272017-01-30 20:29:35 +01003554 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3555 .reset = mv88e6352_g1_reset,
3556};
3557
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003558static const struct mv88e6xxx_ops mv88e6341_ops = {
3559 /* MV88E6XXX_FAMILY_6341 */
3560 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3561 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3562 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3563 .phy_read = mv88e6xxx_g2_smi_phy_read,
3564 .phy_write = mv88e6xxx_g2_smi_phy_write,
3565 .port_set_link = mv88e6xxx_port_set_link,
3566 .port_set_duplex = mv88e6xxx_port_set_duplex,
3567 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3568 .port_set_speed = mv88e6390_port_set_speed,
3569 .port_tag_remap = mv88e6095_port_tag_remap,
3570 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3571 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3572 .port_set_ether_type = mv88e6351_port_set_ether_type,
3573 .port_jumbo_config = mv88e6165_port_jumbo_config,
3574 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3575 .port_pause_config = mv88e6097_port_pause_config,
3576 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3577 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3578 .stats_get_strings = mv88e6320_stats_get_strings,
3579 .stats_get_stats = mv88e6390_stats_get_stats,
3580 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3581 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003582 .watchdog_ops = &mv88e6390_watchdog_ops,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003583 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3584 .reset = mv88e6352_g1_reset,
3585};
3586
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003587static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003588 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003589 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3590 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003591 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3592 .phy_read = mv88e6xxx_g2_smi_phy_read,
3593 .phy_write = mv88e6xxx_g2_smi_phy_write,
3594 .port_set_link = mv88e6xxx_port_set_link,
3595 .port_set_duplex = mv88e6xxx_port_set_duplex,
3596 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3597 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003598 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003599 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3600 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3601 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003602 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003603 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003604 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003605 .port_set_cmode = mv88e6390x_port_set_cmode,
Andrew Lunn79523472016-11-21 23:27:00 +01003606 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003607 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003608 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3609 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003610 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003611 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3612 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003613 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003614 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003615 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003616};
3617
3618static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003619 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003620 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3621 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003622 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3623 .phy_read = mv88e6xxx_g2_smi_phy_read,
3624 .phy_write = mv88e6xxx_g2_smi_phy_write,
3625 .port_set_link = mv88e6xxx_port_set_link,
3626 .port_set_duplex = mv88e6xxx_port_set_duplex,
3627 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3628 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003629 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003630 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3631 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3632 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003633 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003634 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003635 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003636 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003637 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003638 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3639 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003640 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003641 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3642 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003643 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003644 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003645 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003646};
3647
3648static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003649 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003650 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3651 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003652 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3653 .phy_read = mv88e6xxx_g2_smi_phy_read,
3654 .phy_write = mv88e6xxx_g2_smi_phy_write,
3655 .port_set_link = mv88e6xxx_port_set_link,
3656 .port_set_duplex = mv88e6xxx_port_set_duplex,
3657 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3658 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003659 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003660 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3661 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3662 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003663 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003664 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003665 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003666 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3667 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003668 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003669 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3670 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003671 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003672 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003673 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003674};
3675
Andrew Lunn56995cb2016-12-03 04:35:19 +01003676static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3677 const struct mv88e6xxx_ops *ops)
3678{
3679 if (!ops->port_set_frame_mode) {
3680 dev_err(chip->dev, "Missing port_set_frame_mode");
3681 return -EINVAL;
3682 }
3683
3684 if (!ops->port_set_egress_unknowns) {
3685 dev_err(chip->dev, "Missing port_set_egress_mode");
3686 return -EINVAL;
3687 }
3688
3689 return 0;
3690}
3691
Vivien Didelotf81ec902016-05-09 13:22:58 -04003692static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3693 [MV88E6085] = {
3694 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3695 .family = MV88E6XXX_FAMILY_6097,
3696 .name = "Marvell 88E6085",
3697 .num_databases = 4096,
3698 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003699 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003700 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003701 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003702 .g1_irqs = 8,
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_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003705 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003706 },
3707
3708 [MV88E6095] = {
3709 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3710 .family = MV88E6XXX_FAMILY_6095,
3711 .name = "Marvell 88E6095/88E6095F",
3712 .num_databases = 256,
3713 .num_ports = 11,
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 = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003718 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003719 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003720 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003721 },
3722
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003723 [MV88E6097] = {
3724 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3725 .family = MV88E6XXX_FAMILY_6097,
3726 .name = "Marvell 88E6097/88E6097F",
3727 .num_databases = 4096,
3728 .num_ports = 11,
3729 .port_base_addr = 0x10,
3730 .global1_addr = 0x1b,
3731 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003732 .g1_irqs = 8,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003733 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003734 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3735 .ops = &mv88e6097_ops,
3736 },
3737
Vivien Didelotf81ec902016-05-09 13:22:58 -04003738 [MV88E6123] = {
3739 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3740 .family = MV88E6XXX_FAMILY_6165,
3741 .name = "Marvell 88E6123",
3742 .num_databases = 4096,
3743 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003744 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003745 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003746 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003747 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003748 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003749 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003750 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003751 },
3752
3753 [MV88E6131] = {
3754 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3755 .family = MV88E6XXX_FAMILY_6185,
3756 .name = "Marvell 88E6131",
3757 .num_databases = 256,
3758 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003759 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003760 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003761 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003762 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003763 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003764 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003765 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003766 },
3767
3768 [MV88E6161] = {
3769 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3770 .family = MV88E6XXX_FAMILY_6165,
3771 .name = "Marvell 88E6161",
3772 .num_databases = 4096,
3773 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003774 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003775 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003776 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003777 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003778 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003779 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003780 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003781 },
3782
3783 [MV88E6165] = {
3784 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3785 .family = MV88E6XXX_FAMILY_6165,
3786 .name = "Marvell 88E6165",
3787 .num_databases = 4096,
3788 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003789 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003790 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003791 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003792 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003793 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003794 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003795 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003796 },
3797
3798 [MV88E6171] = {
3799 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3800 .family = MV88E6XXX_FAMILY_6351,
3801 .name = "Marvell 88E6171",
3802 .num_databases = 4096,
3803 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003804 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003805 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003806 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003807 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003808 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003809 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003810 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003811 },
3812
3813 [MV88E6172] = {
3814 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3815 .family = MV88E6XXX_FAMILY_6352,
3816 .name = "Marvell 88E6172",
3817 .num_databases = 4096,
3818 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003819 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003820 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003821 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003822 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003823 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003824 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003825 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003826 },
3827
3828 [MV88E6175] = {
3829 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3830 .family = MV88E6XXX_FAMILY_6351,
3831 .name = "Marvell 88E6175",
3832 .num_databases = 4096,
3833 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003834 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003835 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003836 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003837 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003838 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003839 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003840 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003841 },
3842
3843 [MV88E6176] = {
3844 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3845 .family = MV88E6XXX_FAMILY_6352,
3846 .name = "Marvell 88E6176",
3847 .num_databases = 4096,
3848 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003849 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003850 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003851 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003852 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003853 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003854 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003855 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003856 },
3857
3858 [MV88E6185] = {
3859 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3860 .family = MV88E6XXX_FAMILY_6185,
3861 .name = "Marvell 88E6185",
3862 .num_databases = 256,
3863 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003864 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003865 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003866 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003867 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003868 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003869 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003870 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003871 },
3872
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003873 [MV88E6190] = {
3874 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3875 .family = MV88E6XXX_FAMILY_6390,
3876 .name = "Marvell 88E6190",
3877 .num_databases = 4096,
3878 .num_ports = 11, /* 10 + Z80 */
3879 .port_base_addr = 0x0,
3880 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003881 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003882 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003883 .g1_irqs = 9,
3884 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3885 .ops = &mv88e6190_ops,
3886 },
3887
3888 [MV88E6190X] = {
3889 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3890 .family = MV88E6XXX_FAMILY_6390,
3891 .name = "Marvell 88E6190X",
3892 .num_databases = 4096,
3893 .num_ports = 11, /* 10 + Z80 */
3894 .port_base_addr = 0x0,
3895 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003896 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003897 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003898 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003899 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3900 .ops = &mv88e6190x_ops,
3901 },
3902
3903 [MV88E6191] = {
3904 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3905 .family = MV88E6XXX_FAMILY_6390,
3906 .name = "Marvell 88E6191",
3907 .num_databases = 4096,
3908 .num_ports = 11, /* 10 + Z80 */
3909 .port_base_addr = 0x0,
3910 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003911 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003912 .g1_irqs = 9,
3913 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003914 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3915 .ops = &mv88e6391_ops,
3916 },
3917
Vivien Didelotf81ec902016-05-09 13:22:58 -04003918 [MV88E6240] = {
3919 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3920 .family = MV88E6XXX_FAMILY_6352,
3921 .name = "Marvell 88E6240",
3922 .num_databases = 4096,
3923 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003924 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003925 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003926 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003927 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003928 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003929 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003930 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003931 },
3932
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003933 [MV88E6290] = {
3934 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3935 .family = MV88E6XXX_FAMILY_6390,
3936 .name = "Marvell 88E6290",
3937 .num_databases = 4096,
3938 .num_ports = 11, /* 10 + Z80 */
3939 .port_base_addr = 0x0,
3940 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003941 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003942 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003943 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003944 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3945 .ops = &mv88e6290_ops,
3946 },
3947
Vivien Didelotf81ec902016-05-09 13:22:58 -04003948 [MV88E6320] = {
3949 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3950 .family = MV88E6XXX_FAMILY_6320,
3951 .name = "Marvell 88E6320",
3952 .num_databases = 4096,
3953 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003954 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003955 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003956 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003957 .g1_irqs = 8,
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_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003960 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003961 },
3962
3963 [MV88E6321] = {
3964 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3965 .family = MV88E6XXX_FAMILY_6320,
3966 .name = "Marvell 88E6321",
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 = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003973 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003974 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003975 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003976 },
3977
Gregory CLEMENT15587272017-01-30 20:29:35 +01003978 [MV88E6141] = {
3979 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
3980 .family = MV88E6XXX_FAMILY_6341,
3981 .name = "Marvell 88E6341",
3982 .num_databases = 4096,
3983 .num_ports = 6,
3984 .port_base_addr = 0x10,
3985 .global1_addr = 0x1b,
3986 .age_time_coeff = 3750,
3987 .tag_protocol = DSA_TAG_PROTO_EDSA,
3988 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3989 .ops = &mv88e6141_ops,
3990 },
3991
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003992 [MV88E6341] = {
3993 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
3994 .family = MV88E6XXX_FAMILY_6341,
3995 .name = "Marvell 88E6341",
3996 .num_databases = 4096,
3997 .num_ports = 6,
3998 .port_base_addr = 0x10,
3999 .global1_addr = 0x1b,
4000 .age_time_coeff = 3750,
4001 .tag_protocol = DSA_TAG_PROTO_EDSA,
4002 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
4003 .ops = &mv88e6341_ops,
4004 },
4005
Vivien Didelotf81ec902016-05-09 13:22:58 -04004006 [MV88E6350] = {
4007 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
4008 .family = MV88E6XXX_FAMILY_6351,
4009 .name = "Marvell 88E6350",
4010 .num_databases = 4096,
4011 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004012 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004013 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004014 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004015 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004016 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004017 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004018 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004019 },
4020
4021 [MV88E6351] = {
4022 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4023 .family = MV88E6XXX_FAMILY_6351,
4024 .name = "Marvell 88E6351",
4025 .num_databases = 4096,
4026 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004027 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004028 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004029 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004030 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004031 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004032 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004033 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004034 },
4035
4036 [MV88E6352] = {
4037 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4038 .family = MV88E6XXX_FAMILY_6352,
4039 .name = "Marvell 88E6352",
4040 .num_databases = 4096,
4041 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004042 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004043 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004044 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004045 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004046 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004047 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004048 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004049 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004050 [MV88E6390] = {
4051 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4052 .family = MV88E6XXX_FAMILY_6390,
4053 .name = "Marvell 88E6390",
4054 .num_databases = 4096,
4055 .num_ports = 11, /* 10 + Z80 */
4056 .port_base_addr = 0x0,
4057 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004058 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004059 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004060 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004061 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4062 .ops = &mv88e6390_ops,
4063 },
4064 [MV88E6390X] = {
4065 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4066 .family = MV88E6XXX_FAMILY_6390,
4067 .name = "Marvell 88E6390X",
4068 .num_databases = 4096,
4069 .num_ports = 11, /* 10 + Z80 */
4070 .port_base_addr = 0x0,
4071 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004072 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004073 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004074 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004075 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4076 .ops = &mv88e6390x_ops,
4077 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004078};
4079
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004080static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004081{
Vivien Didelota439c062016-04-17 13:23:58 -04004082 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004083
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004084 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4085 if (mv88e6xxx_table[i].prod_num == prod_num)
4086 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004087
Vivien Didelotb9b37712015-10-30 19:39:48 -04004088 return NULL;
4089}
4090
Vivien Didelotfad09c72016-06-21 12:28:20 -04004091static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004092{
4093 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004094 unsigned int prod_num, rev;
4095 u16 id;
4096 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004097
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004098 mutex_lock(&chip->reg_lock);
4099 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4100 mutex_unlock(&chip->reg_lock);
4101 if (err)
4102 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004103
4104 prod_num = (id & 0xfff0) >> 4;
4105 rev = id & 0x000f;
4106
4107 info = mv88e6xxx_lookup_info(prod_num);
4108 if (!info)
4109 return -ENODEV;
4110
Vivien Didelotcaac8542016-06-20 13:14:09 -04004111 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004112 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004113
Vivien Didelotca070c12016-09-02 14:45:34 -04004114 err = mv88e6xxx_g2_require(chip);
4115 if (err)
4116 return err;
4117
Vivien Didelotfad09c72016-06-21 12:28:20 -04004118 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4119 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004120
4121 return 0;
4122}
4123
Vivien Didelotfad09c72016-06-21 12:28:20 -04004124static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004125{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004126 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004127
Vivien Didelotfad09c72016-06-21 12:28:20 -04004128 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4129 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004130 return NULL;
4131
Vivien Didelotfad09c72016-06-21 12:28:20 -04004132 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004133
Vivien Didelotfad09c72016-06-21 12:28:20 -04004134 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004135 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004136
Vivien Didelotfad09c72016-06-21 12:28:20 -04004137 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004138}
4139
Vivien Didelote57e5e72016-08-15 17:19:00 -04004140static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4141{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004142 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004143 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004144}
4145
Andrew Lunn930188c2016-08-22 16:01:03 +02004146static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4147{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004148 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004149 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004150}
4151
Vivien Didelotfad09c72016-06-21 12:28:20 -04004152static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004153 struct mii_bus *bus, int sw_addr)
4154{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004155 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004156 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004157 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004158 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004159 else
4160 return -EINVAL;
4161
Vivien Didelotfad09c72016-06-21 12:28:20 -04004162 chip->bus = bus;
4163 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004164
4165 return 0;
4166}
4167
Andrew Lunn7b314362016-08-22 16:01:01 +02004168static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4169{
Vivien Didelot04bed142016-08-31 18:06:13 -04004170 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004171
Andrew Lunn443d5a12016-12-03 04:35:18 +01004172 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004173}
4174
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004175static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4176 struct device *host_dev, int sw_addr,
4177 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004178{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004179 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004180 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004181 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004182
Vivien Didelota439c062016-04-17 13:23:58 -04004183 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004184 if (!bus)
4185 return NULL;
4186
Vivien Didelotfad09c72016-06-21 12:28:20 -04004187 chip = mv88e6xxx_alloc_chip(dsa_dev);
4188 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004189 return NULL;
4190
Vivien Didelotcaac8542016-06-20 13:14:09 -04004191 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004192 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004193
Vivien Didelotfad09c72016-06-21 12:28:20 -04004194 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004195 if (err)
4196 goto free;
4197
Vivien Didelotfad09c72016-06-21 12:28:20 -04004198 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004199 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004200 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004201
Andrew Lunndc30c352016-10-16 19:56:49 +02004202 mutex_lock(&chip->reg_lock);
4203 err = mv88e6xxx_switch_reset(chip);
4204 mutex_unlock(&chip->reg_lock);
4205 if (err)
4206 goto free;
4207
Vivien Didelote57e5e72016-08-15 17:19:00 -04004208 mv88e6xxx_phy_init(chip);
4209
Andrew Lunna3c53be52017-01-24 14:53:50 +01004210 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004211 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004212 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004213
Vivien Didelotfad09c72016-06-21 12:28:20 -04004214 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004215
Vivien Didelotfad09c72016-06-21 12:28:20 -04004216 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004217free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004218 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004219
4220 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004221}
4222
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004223static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4224 const struct switchdev_obj_port_mdb *mdb,
4225 struct switchdev_trans *trans)
4226{
4227 /* We don't need any dynamic resource from the kernel (yet),
4228 * so skip the prepare phase.
4229 */
4230
4231 return 0;
4232}
4233
4234static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4235 const struct switchdev_obj_port_mdb *mdb,
4236 struct switchdev_trans *trans)
4237{
Vivien Didelot04bed142016-08-31 18:06:13 -04004238 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004239
4240 mutex_lock(&chip->reg_lock);
4241 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4242 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4243 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4244 mutex_unlock(&chip->reg_lock);
4245}
4246
4247static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4248 const struct switchdev_obj_port_mdb *mdb)
4249{
Vivien Didelot04bed142016-08-31 18:06:13 -04004250 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004251 int err;
4252
4253 mutex_lock(&chip->reg_lock);
4254 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4255 GLOBAL_ATU_DATA_STATE_UNUSED);
4256 mutex_unlock(&chip->reg_lock);
4257
4258 return err;
4259}
4260
4261static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4262 struct switchdev_obj_port_mdb *mdb,
4263 int (*cb)(struct switchdev_obj *obj))
4264{
Vivien Didelot04bed142016-08-31 18:06:13 -04004265 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004266 int err;
4267
4268 mutex_lock(&chip->reg_lock);
4269 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4270 mutex_unlock(&chip->reg_lock);
4271
4272 return err;
4273}
4274
Florian Fainellia82f67a2017-01-08 14:52:08 -08004275static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004276 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004277 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004278 .setup = mv88e6xxx_setup,
4279 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004280 .adjust_link = mv88e6xxx_adjust_link,
4281 .get_strings = mv88e6xxx_get_strings,
4282 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4283 .get_sset_count = mv88e6xxx_get_sset_count,
4284 .set_eee = mv88e6xxx_set_eee,
4285 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004286 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004287 .get_eeprom = mv88e6xxx_get_eeprom,
4288 .set_eeprom = mv88e6xxx_set_eeprom,
4289 .get_regs_len = mv88e6xxx_get_regs_len,
4290 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004291 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004292 .port_bridge_join = mv88e6xxx_port_bridge_join,
4293 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4294 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004295 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004296 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4297 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4298 .port_vlan_add = mv88e6xxx_port_vlan_add,
4299 .port_vlan_del = mv88e6xxx_port_vlan_del,
4300 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4301 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4302 .port_fdb_add = mv88e6xxx_port_fdb_add,
4303 .port_fdb_del = mv88e6xxx_port_fdb_del,
4304 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004305 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4306 .port_mdb_add = mv88e6xxx_port_mdb_add,
4307 .port_mdb_del = mv88e6xxx_port_mdb_del,
4308 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004309};
4310
Florian Fainelliab3d4082017-01-08 14:52:07 -08004311static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4312 .ops = &mv88e6xxx_switch_ops,
4313};
4314
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004315static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004316{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004317 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004318 struct dsa_switch *ds;
4319
Vivien Didelota0c02162017-01-27 15:29:36 -05004320 ds = dsa_switch_alloc(dev, DSA_MAX_PORTS);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004321 if (!ds)
4322 return -ENOMEM;
4323
Vivien Didelotfad09c72016-06-21 12:28:20 -04004324 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004325 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004326
4327 dev_set_drvdata(dev, ds);
4328
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004329 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004330}
4331
Vivien Didelotfad09c72016-06-21 12:28:20 -04004332static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004333{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004334 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004335}
4336
Vivien Didelot57d32312016-06-20 13:13:58 -04004337static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004338{
4339 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004340 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004341 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004342 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004343 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004344 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004345
Vivien Didelotcaac8542016-06-20 13:14:09 -04004346 compat_info = of_device_get_match_data(dev);
4347 if (!compat_info)
4348 return -EINVAL;
4349
Vivien Didelotfad09c72016-06-21 12:28:20 -04004350 chip = mv88e6xxx_alloc_chip(dev);
4351 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004352 return -ENOMEM;
4353
Vivien Didelotfad09c72016-06-21 12:28:20 -04004354 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004355
Andrew Lunn56995cb2016-12-03 04:35:19 +01004356 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4357 if (err)
4358 return err;
4359
Vivien Didelotfad09c72016-06-21 12:28:20 -04004360 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004361 if (err)
4362 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004363
Andrew Lunnb4308f02016-11-21 23:26:55 +01004364 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4365 if (IS_ERR(chip->reset))
4366 return PTR_ERR(chip->reset);
4367
Vivien Didelotfad09c72016-06-21 12:28:20 -04004368 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004369 if (err)
4370 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004371
Vivien Didelote57e5e72016-08-15 17:19:00 -04004372 mv88e6xxx_phy_init(chip);
4373
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004374 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004375 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004376 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004377
Andrew Lunndc30c352016-10-16 19:56:49 +02004378 mutex_lock(&chip->reg_lock);
4379 err = mv88e6xxx_switch_reset(chip);
4380 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004381 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004382 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004383
Andrew Lunndc30c352016-10-16 19:56:49 +02004384 chip->irq = of_irq_get(np, 0);
4385 if (chip->irq == -EPROBE_DEFER) {
4386 err = chip->irq;
4387 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004388 }
4389
Andrew Lunndc30c352016-10-16 19:56:49 +02004390 if (chip->irq > 0) {
4391 /* Has to be performed before the MDIO bus is created,
4392 * because the PHYs will link there interrupts to these
4393 * interrupt controllers
4394 */
4395 mutex_lock(&chip->reg_lock);
4396 err = mv88e6xxx_g1_irq_setup(chip);
4397 mutex_unlock(&chip->reg_lock);
4398
4399 if (err)
4400 goto out;
4401
4402 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4403 err = mv88e6xxx_g2_irq_setup(chip);
4404 if (err)
4405 goto out_g1_irq;
4406 }
4407 }
4408
Andrew Lunna3c53be52017-01-24 14:53:50 +01004409 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004410 if (err)
4411 goto out_g2_irq;
4412
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004413 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004414 if (err)
4415 goto out_mdio;
4416
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004417 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004418
4419out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004420 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004421out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004422 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004423 mv88e6xxx_g2_irq_free(chip);
4424out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004425 if (chip->irq > 0) {
4426 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004427 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004428 mutex_unlock(&chip->reg_lock);
4429 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004430out:
4431 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004432}
4433
4434static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4435{
4436 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004437 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004438
Andrew Lunn930188c2016-08-22 16:01:03 +02004439 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004440 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004441 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004442
Andrew Lunn467126442016-11-20 20:14:15 +01004443 if (chip->irq > 0) {
4444 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4445 mv88e6xxx_g2_irq_free(chip);
4446 mv88e6xxx_g1_irq_free(chip);
4447 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004448}
4449
4450static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004451 {
4452 .compatible = "marvell,mv88e6085",
4453 .data = &mv88e6xxx_table[MV88E6085],
4454 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004455 {
4456 .compatible = "marvell,mv88e6190",
4457 .data = &mv88e6xxx_table[MV88E6190],
4458 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004459 { /* sentinel */ },
4460};
4461
4462MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4463
4464static struct mdio_driver mv88e6xxx_driver = {
4465 .probe = mv88e6xxx_probe,
4466 .remove = mv88e6xxx_remove,
4467 .mdiodrv.driver = {
4468 .name = "mv88e6085",
4469 .of_match_table = mv88e6xxx_of_match,
4470 },
4471};
4472
Ben Hutchings98e67302011-11-25 14:36:19 +00004473static int __init mv88e6xxx_init(void)
4474{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004475 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004476 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004477}
4478module_init(mv88e6xxx_init);
4479
4480static void __exit mv88e6xxx_cleanup(void)
4481{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004482 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004483 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004484}
4485module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004486
4487MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4488MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4489MODULE_LICENSE("GPL");