blob: a11e5354f14fe949615f8591d88f6568a4a8ef19 [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 Didelotf81ec902016-05-09 13:22:58 -04001069static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1070 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001071{
Vivien Didelot04bed142016-08-31 18:06:13 -04001072 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001073 u16 reg;
1074 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001075
Vivien Didelotfad09c72016-06-21 12:28:20 -04001076 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001077 return -EOPNOTSUPP;
1078
Vivien Didelotfad09c72016-06-21 12:28:20 -04001079 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001080
Vivien Didelot9c938292016-08-15 17:19:02 -04001081 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1082 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001083 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001084
1085 e->eee_enabled = !!(reg & 0x0200);
1086 e->tx_lpi_enabled = !!(reg & 0x0100);
1087
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001088 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001089 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001090 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001091
Andrew Lunncca8b132015-04-02 04:06:39 +02001092 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001093out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001094 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001095
1096 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001097}
1098
Vivien Didelotf81ec902016-05-09 13:22:58 -04001099static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1100 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001101{
Vivien Didelot04bed142016-08-31 18:06:13 -04001102 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001103 u16 reg;
1104 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001105
Vivien Didelotfad09c72016-06-21 12:28:20 -04001106 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001107 return -EOPNOTSUPP;
1108
Vivien Didelotfad09c72016-06-21 12:28:20 -04001109 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001110
Vivien Didelot9c938292016-08-15 17:19:02 -04001111 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1112 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001113 goto out;
1114
Vivien Didelot9c938292016-08-15 17:19:02 -04001115 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001116 if (e->eee_enabled)
1117 reg |= 0x0200;
1118 if (e->tx_lpi_enabled)
1119 reg |= 0x0100;
1120
Vivien Didelot9c938292016-08-15 17:19:02 -04001121 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001122out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001123 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001124
Vivien Didelot9c938292016-08-15 17:19:02 -04001125 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001126}
1127
Vivien Didelotfad09c72016-06-21 12:28:20 -04001128static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001129{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001130 struct dsa_switch *ds = chip->ds;
Vivien Didelotfae8a252017-01-27 15:29:42 -05001131 struct net_device *bridge = ds->ports[port].bridge_dev;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001132 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001133 int i;
1134
1135 /* allow CPU port or DSA link(s) to send frames to every port */
1136 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001137 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001138 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001139 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001140 /* allow sending frames to every group member */
Vivien Didelotfae8a252017-01-27 15:29:42 -05001141 if (bridge && ds->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001142 output_ports |= BIT(i);
1143
1144 /* allow sending frames to CPU port and DSA link(s) */
1145 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1146 output_ports |= BIT(i);
1147 }
1148 }
1149
1150 /* prevent frames from going back out of the port they came in on */
1151 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001152
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001153 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001154}
1155
Vivien Didelotf81ec902016-05-09 13:22:58 -04001156static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1157 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001158{
Vivien Didelot04bed142016-08-31 18:06:13 -04001159 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001160 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001161 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001162
1163 switch (state) {
1164 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001165 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001166 break;
1167 case BR_STATE_BLOCKING:
1168 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001169 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001170 break;
1171 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001172 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001173 break;
1174 case BR_STATE_FORWARDING:
1175 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001176 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001177 break;
1178 }
1179
Vivien Didelotfad09c72016-06-21 12:28:20 -04001180 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001181 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001182 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001183
1184 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001185 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001186}
1187
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001188static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1189{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001190 int err;
1191
Vivien Didelotdaefc942017-03-11 16:12:54 -05001192 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1193 if (err)
1194 return err;
1195
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001196 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1197 if (err)
1198 return err;
1199
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001200 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1201}
1202
Vivien Didelot749efcb2016-09-22 16:49:24 -04001203static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1204{
1205 struct mv88e6xxx_chip *chip = ds->priv;
1206 int err;
1207
1208 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001209 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001210 mutex_unlock(&chip->reg_lock);
1211
1212 if (err)
1213 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1214}
1215
Vivien Didelotfad09c72016-06-21 12:28:20 -04001216static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001217{
Vivien Didelota935c052016-09-29 12:21:53 -04001218 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001219}
1220
Vivien Didelotfad09c72016-06-21 12:28:20 -04001221static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001222{
Vivien Didelota935c052016-09-29 12:21:53 -04001223 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001224
Vivien Didelota935c052016-09-29 12:21:53 -04001225 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1226 if (err)
1227 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001228
Vivien Didelotfad09c72016-06-21 12:28:20 -04001229 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001230}
1231
Vivien Didelotfad09c72016-06-21 12:28:20 -04001232static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001233{
1234 int ret;
1235
Vivien Didelotfad09c72016-06-21 12:28:20 -04001236 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001237 if (ret < 0)
1238 return ret;
1239
Vivien Didelotfad09c72016-06-21 12:28:20 -04001240 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001241}
1242
Vivien Didelotfad09c72016-06-21 12:28:20 -04001243static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001244 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001245 unsigned int nibble_offset)
1246{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001247 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001248 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001249
1250 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001251 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001252
Vivien Didelota935c052016-09-29 12:21:53 -04001253 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1254 if (err)
1255 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001256 }
1257
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001258 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001259 unsigned int shift = (i % 4) * 4 + nibble_offset;
1260 u16 reg = regs[i / 4];
1261
1262 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1263 }
1264
1265 return 0;
1266}
1267
Vivien Didelotfad09c72016-06-21 12:28:20 -04001268static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001269 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001270{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001271 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001272}
1273
Vivien Didelotfad09c72016-06-21 12:28:20 -04001274static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001275 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001276{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001277 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001278}
1279
Vivien Didelotfad09c72016-06-21 12:28:20 -04001280static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001281 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001282 unsigned int nibble_offset)
1283{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001284 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001285 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001286
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001287 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001288 unsigned int shift = (i % 4) * 4 + nibble_offset;
1289 u8 data = entry->data[i];
1290
1291 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1292 }
1293
1294 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001295 u16 reg = regs[i];
1296
1297 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1298 if (err)
1299 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001300 }
1301
1302 return 0;
1303}
1304
Vivien Didelotfad09c72016-06-21 12:28:20 -04001305static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001306 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001307{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001308 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001309}
1310
Vivien Didelotfad09c72016-06-21 12:28:20 -04001311static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001312 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001313{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001314 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001315}
1316
Vivien Didelotfad09c72016-06-21 12:28:20 -04001317static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001318{
Vivien Didelota935c052016-09-29 12:21:53 -04001319 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1320 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001321}
1322
Vivien Didelotfad09c72016-06-21 12:28:20 -04001323static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001324 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001325{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001326 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001327 u16 val;
1328 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001329
Vivien Didelota935c052016-09-29 12:21:53 -04001330 err = _mv88e6xxx_vtu_wait(chip);
1331 if (err)
1332 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001333
Vivien Didelota935c052016-09-29 12:21:53 -04001334 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1335 if (err)
1336 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001337
Vivien Didelota935c052016-09-29 12:21:53 -04001338 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1339 if (err)
1340 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001341
Vivien Didelota935c052016-09-29 12:21:53 -04001342 next.vid = val & GLOBAL_VTU_VID_MASK;
1343 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001344
1345 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001346 err = mv88e6xxx_vtu_data_read(chip, &next);
1347 if (err)
1348 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001349
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001350 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001351 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1352 if (err)
1353 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001354
Vivien Didelota935c052016-09-29 12:21:53 -04001355 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001356 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001357 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1358 * VTU DBNum[3:0] are located in VTU Operation 3:0
1359 */
Vivien Didelota935c052016-09-29 12:21:53 -04001360 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1361 if (err)
1362 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001363
Vivien Didelota935c052016-09-29 12:21:53 -04001364 next.fid = (val & 0xf00) >> 4;
1365 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001366 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001367
Vivien Didelotfad09c72016-06-21 12:28:20 -04001368 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001369 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1370 if (err)
1371 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001372
Vivien Didelota935c052016-09-29 12:21:53 -04001373 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001374 }
1375 }
1376
1377 *entry = next;
1378 return 0;
1379}
1380
Vivien Didelotf81ec902016-05-09 13:22:58 -04001381static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1382 struct switchdev_obj_port_vlan *vlan,
1383 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001384{
Vivien Didelot04bed142016-08-31 18:06:13 -04001385 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001386 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001387 u16 pvid;
1388 int err;
1389
Vivien Didelotfad09c72016-06-21 12:28:20 -04001390 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001391 return -EOPNOTSUPP;
1392
Vivien Didelotfad09c72016-06-21 12:28:20 -04001393 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001394
Vivien Didelot77064f32016-11-04 03:23:30 +01001395 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001396 if (err)
1397 goto unlock;
1398
Vivien Didelotfad09c72016-06-21 12:28:20 -04001399 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001400 if (err)
1401 goto unlock;
1402
1403 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001404 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001405 if (err)
1406 break;
1407
1408 if (!next.valid)
1409 break;
1410
1411 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1412 continue;
1413
1414 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001415 vlan->vid_begin = next.vid;
1416 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001417 vlan->flags = 0;
1418
1419 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1420 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1421
1422 if (next.vid == pvid)
1423 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1424
1425 err = cb(&vlan->obj);
1426 if (err)
1427 break;
1428 } while (next.vid < GLOBAL_VTU_VID_MASK);
1429
1430unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001431 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001432
1433 return err;
1434}
1435
Vivien Didelotfad09c72016-06-21 12:28:20 -04001436static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001437 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001438{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001439 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001440 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001441 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001442
Vivien Didelota935c052016-09-29 12:21:53 -04001443 err = _mv88e6xxx_vtu_wait(chip);
1444 if (err)
1445 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001446
1447 if (!entry->valid)
1448 goto loadpurge;
1449
1450 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001451 err = mv88e6xxx_vtu_data_write(chip, entry);
1452 if (err)
1453 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001454
Vivien Didelotfad09c72016-06-21 12:28:20 -04001455 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001456 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001457 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1458 if (err)
1459 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001460 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001461
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001462 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001463 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001464 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1465 if (err)
1466 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001467 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001468 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1469 * VTU DBNum[3:0] are located in VTU Operation 3:0
1470 */
1471 op |= (entry->fid & 0xf0) << 8;
1472 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001473 }
1474
1475 reg = GLOBAL_VTU_VID_VALID;
1476loadpurge:
1477 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001478 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1479 if (err)
1480 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001481
Vivien Didelotfad09c72016-06-21 12:28:20 -04001482 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001483}
1484
Vivien Didelotfad09c72016-06-21 12:28:20 -04001485static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001486 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001487{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001488 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001489 u16 val;
1490 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001491
Vivien Didelota935c052016-09-29 12:21:53 -04001492 err = _mv88e6xxx_vtu_wait(chip);
1493 if (err)
1494 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001495
Vivien Didelota935c052016-09-29 12:21:53 -04001496 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1497 sid & GLOBAL_VTU_SID_MASK);
1498 if (err)
1499 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001500
Vivien Didelota935c052016-09-29 12:21:53 -04001501 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1502 if (err)
1503 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001504
Vivien Didelota935c052016-09-29 12:21:53 -04001505 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1506 if (err)
1507 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001508
Vivien Didelota935c052016-09-29 12:21:53 -04001509 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001510
Vivien Didelota935c052016-09-29 12:21:53 -04001511 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1512 if (err)
1513 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001514
Vivien Didelota935c052016-09-29 12:21:53 -04001515 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001516
1517 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001518 err = mv88e6xxx_stu_data_read(chip, &next);
1519 if (err)
1520 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001521 }
1522
1523 *entry = next;
1524 return 0;
1525}
1526
Vivien Didelotfad09c72016-06-21 12:28:20 -04001527static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001528 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001529{
1530 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001531 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001532
Vivien Didelota935c052016-09-29 12:21:53 -04001533 err = _mv88e6xxx_vtu_wait(chip);
1534 if (err)
1535 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001536
1537 if (!entry->valid)
1538 goto loadpurge;
1539
1540 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001541 err = mv88e6xxx_stu_data_write(chip, entry);
1542 if (err)
1543 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001544
1545 reg = GLOBAL_VTU_VID_VALID;
1546loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001547 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1548 if (err)
1549 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001550
1551 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001552 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1553 if (err)
1554 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001555
Vivien Didelotfad09c72016-06-21 12:28:20 -04001556 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001557}
1558
Vivien Didelotfad09c72016-06-21 12:28:20 -04001559static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001560{
1561 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001562 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001563 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001564
1565 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1566
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001567 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001568 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001569 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001570 if (err)
1571 return err;
1572
1573 set_bit(*fid, fid_bitmap);
1574 }
1575
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001576 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001577 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001578 if (err)
1579 return err;
1580
1581 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001582 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001583 if (err)
1584 return err;
1585
1586 if (!vlan.valid)
1587 break;
1588
1589 set_bit(vlan.fid, fid_bitmap);
1590 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1591
1592 /* The reset value 0x000 is used to indicate that multiple address
1593 * databases are not needed. Return the next positive available.
1594 */
1595 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001596 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001597 return -ENOSPC;
1598
1599 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001600 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001601}
1602
Vivien Didelotfad09c72016-06-21 12:28:20 -04001603static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001604 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001605{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001606 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001607 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001608 .valid = true,
1609 .vid = vid,
1610 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001611 int i, err;
1612
Vivien Didelotfad09c72016-06-21 12:28:20 -04001613 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001614 if (err)
1615 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001616
Vivien Didelot3d131f02015-11-03 10:52:52 -05001617 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001618 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001619 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1620 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1621 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001622
Vivien Didelotfad09c72016-06-21 12:28:20 -04001623 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01001624 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip) ||
1625 mv88e6xxx_6341_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001626 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001627
1628 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1629 * implemented, only one STU entry is needed to cover all VTU
1630 * entries. Thus, validate the SID 0.
1631 */
1632 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001633 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001634 if (err)
1635 return err;
1636
1637 if (vstp.sid != vlan.sid || !vstp.valid) {
1638 memset(&vstp, 0, sizeof(vstp));
1639 vstp.valid = true;
1640 vstp.sid = vlan.sid;
1641
Vivien Didelotfad09c72016-06-21 12:28:20 -04001642 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001643 if (err)
1644 return err;
1645 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001646 }
1647
1648 *entry = vlan;
1649 return 0;
1650}
1651
Vivien Didelotfad09c72016-06-21 12:28:20 -04001652static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001653 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001654{
1655 int err;
1656
1657 if (!vid)
1658 return -EINVAL;
1659
Vivien Didelotfad09c72016-06-21 12:28:20 -04001660 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001661 if (err)
1662 return err;
1663
Vivien Didelotfad09c72016-06-21 12:28:20 -04001664 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001665 if (err)
1666 return err;
1667
1668 if (entry->vid != vid || !entry->valid) {
1669 if (!creat)
1670 return -EOPNOTSUPP;
1671 /* -ENOENT would've been more appropriate, but switchdev expects
1672 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1673 */
1674
Vivien Didelotfad09c72016-06-21 12:28:20 -04001675 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001676 }
1677
1678 return err;
1679}
1680
Vivien Didelotda9c3592016-02-12 12:09:40 -05001681static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1682 u16 vid_begin, u16 vid_end)
1683{
Vivien Didelot04bed142016-08-31 18:06:13 -04001684 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001685 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001686 int i, err;
1687
1688 if (!vid_begin)
1689 return -EOPNOTSUPP;
1690
Vivien Didelotfad09c72016-06-21 12:28:20 -04001691 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001692
Vivien Didelotfad09c72016-06-21 12:28:20 -04001693 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001694 if (err)
1695 goto unlock;
1696
1697 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001698 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001699 if (err)
1700 goto unlock;
1701
1702 if (!vlan.valid)
1703 break;
1704
1705 if (vlan.vid > vid_end)
1706 break;
1707
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001708 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001709 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1710 continue;
1711
Andrew Lunn66e28092016-12-11 21:07:19 +01001712 if (!ds->ports[port].netdev)
1713 continue;
1714
Vivien Didelotda9c3592016-02-12 12:09:40 -05001715 if (vlan.data[i] ==
1716 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1717 continue;
1718
Vivien Didelotfae8a252017-01-27 15:29:42 -05001719 if (ds->ports[i].bridge_dev ==
1720 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001721 break; /* same bridge, check next VLAN */
1722
Vivien Didelotfae8a252017-01-27 15:29:42 -05001723 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001724 continue;
1725
Andrew Lunnc8b09802016-06-04 21:16:57 +02001726 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001727 "hardware VLAN %d already used by %s\n",
1728 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001729 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001730 err = -EOPNOTSUPP;
1731 goto unlock;
1732 }
1733 } while (vlan.vid < vid_end);
1734
1735unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001736 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001737
1738 return err;
1739}
1740
Vivien Didelotf81ec902016-05-09 13:22:58 -04001741static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1742 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001743{
Vivien Didelot04bed142016-08-31 18:06:13 -04001744 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001745 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001746 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001747 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001748
Vivien Didelotfad09c72016-06-21 12:28:20 -04001749 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001750 return -EOPNOTSUPP;
1751
Vivien Didelotfad09c72016-06-21 12:28:20 -04001752 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001753 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001754 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001755
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001756 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001757}
1758
Vivien Didelot57d32312016-06-20 13:13:58 -04001759static int
1760mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1761 const struct switchdev_obj_port_vlan *vlan,
1762 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001763{
Vivien Didelot04bed142016-08-31 18:06:13 -04001764 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001765 int err;
1766
Vivien Didelotfad09c72016-06-21 12:28:20 -04001767 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001768 return -EOPNOTSUPP;
1769
Vivien Didelotda9c3592016-02-12 12:09:40 -05001770 /* If the requested port doesn't belong to the same bridge as the VLAN
1771 * members, do not support it (yet) and fallback to software VLAN.
1772 */
1773 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1774 vlan->vid_end);
1775 if (err)
1776 return err;
1777
Vivien Didelot76e398a2015-11-01 12:33:55 -05001778 /* We don't need any dynamic resource from the kernel (yet),
1779 * so skip the prepare phase.
1780 */
1781 return 0;
1782}
1783
Vivien Didelotfad09c72016-06-21 12:28:20 -04001784static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001785 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001786{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001787 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001788 int err;
1789
Vivien Didelotfad09c72016-06-21 12:28:20 -04001790 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001791 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001792 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001793
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001794 vlan.data[port] = untagged ?
1795 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1796 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1797
Vivien Didelotfad09c72016-06-21 12:28:20 -04001798 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001799}
1800
Vivien Didelotf81ec902016-05-09 13:22:58 -04001801static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1802 const struct switchdev_obj_port_vlan *vlan,
1803 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001804{
Vivien Didelot04bed142016-08-31 18:06:13 -04001805 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001806 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1807 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1808 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001809
Vivien Didelotfad09c72016-06-21 12:28:20 -04001810 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001811 return;
1812
Vivien Didelotfad09c72016-06-21 12:28:20 -04001813 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001814
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001815 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001816 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001817 netdev_err(ds->ports[port].netdev,
1818 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001819 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001820
Vivien Didelot77064f32016-11-04 03:23:30 +01001821 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001822 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001823 vlan->vid_end);
1824
Vivien Didelotfad09c72016-06-21 12:28:20 -04001825 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001826}
1827
Vivien Didelotfad09c72016-06-21 12:28:20 -04001828static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001829 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001830{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001831 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001832 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001833 int i, err;
1834
Vivien Didelotfad09c72016-06-21 12:28:20 -04001835 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001836 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001837 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001838
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001839 /* Tell switchdev if this VLAN is handled in software */
1840 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001841 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001842
1843 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1844
1845 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001846 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001847 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001848 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001849 continue;
1850
1851 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001852 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001853 break;
1854 }
1855 }
1856
Vivien Didelotfad09c72016-06-21 12:28:20 -04001857 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001858 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001859 return err;
1860
Vivien Didelote606ca32017-03-11 16:12:55 -05001861 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001862}
1863
Vivien Didelotf81ec902016-05-09 13:22:58 -04001864static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1865 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001866{
Vivien Didelot04bed142016-08-31 18:06:13 -04001867 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001868 u16 pvid, vid;
1869 int err = 0;
1870
Vivien Didelotfad09c72016-06-21 12:28:20 -04001871 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001872 return -EOPNOTSUPP;
1873
Vivien Didelotfad09c72016-06-21 12:28:20 -04001874 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001875
Vivien Didelot77064f32016-11-04 03:23:30 +01001876 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001877 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001878 goto unlock;
1879
Vivien Didelot76e398a2015-11-01 12:33:55 -05001880 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001881 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001882 if (err)
1883 goto unlock;
1884
1885 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001886 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001887 if (err)
1888 goto unlock;
1889 }
1890 }
1891
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001892unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001893 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001894
1895 return err;
1896}
1897
Vivien Didelot83dabd12016-08-31 11:50:04 -04001898static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1899 const unsigned char *addr, u16 vid,
1900 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001901{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001902 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001903 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001904 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001905
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001906 /* Null VLAN ID corresponds to the port private database */
1907 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001908 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001909 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04001910 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001911 if (err)
1912 return err;
1913
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001914 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1915 ether_addr_copy(entry.mac, addr);
1916 eth_addr_dec(entry.mac);
1917
1918 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001919 if (err)
1920 return err;
1921
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001922 /* Initialize a fresh ATU entry if it isn't found */
1923 if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
1924 !ether_addr_equal(entry.mac, addr)) {
1925 memset(&entry, 0, sizeof(entry));
1926 ether_addr_copy(entry.mac, addr);
1927 }
1928
Vivien Didelot88472932016-09-19 19:56:11 -04001929 /* Purge the ATU entry only if no port is using it anymore */
1930 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
1931 entry.portv_trunkid &= ~BIT(port);
1932 if (!entry.portv_trunkid)
1933 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1934 } else {
1935 entry.portv_trunkid |= BIT(port);
1936 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001937 }
1938
Vivien Didelot9c13c022017-03-11 16:12:52 -05001939 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001940}
1941
Vivien Didelotf81ec902016-05-09 13:22:58 -04001942static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1943 const struct switchdev_obj_port_fdb *fdb,
1944 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001945{
1946 /* We don't need any dynamic resource from the kernel (yet),
1947 * so skip the prepare phase.
1948 */
1949 return 0;
1950}
1951
Vivien Didelotf81ec902016-05-09 13:22:58 -04001952static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1953 const struct switchdev_obj_port_fdb *fdb,
1954 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001955{
Vivien Didelot04bed142016-08-31 18:06:13 -04001956 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04001957
Vivien Didelotfad09c72016-06-21 12:28:20 -04001958 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001959 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1960 GLOBAL_ATU_DATA_STATE_UC_STATIC))
1961 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001962 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001963}
1964
Vivien Didelotf81ec902016-05-09 13:22:58 -04001965static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1966 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07001967{
Vivien Didelot04bed142016-08-31 18:06:13 -04001968 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001969 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001970
Vivien Didelotfad09c72016-06-21 12:28:20 -04001971 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001972 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1973 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001974 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001975
Vivien Didelot83dabd12016-08-31 11:50:04 -04001976 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001977}
1978
Vivien Didelot83dabd12016-08-31 11:50:04 -04001979static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1980 u16 fid, u16 vid, int port,
1981 struct switchdev_obj *obj,
1982 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001983{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001984 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001985 int err;
1986
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001987 addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1988 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001989
1990 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001991 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001992 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04001993 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001994
1995 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
1996 break;
1997
Vivien Didelot83dabd12016-08-31 11:50:04 -04001998 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
1999 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002000
Vivien Didelot83dabd12016-08-31 11:50:04 -04002001 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2002 struct switchdev_obj_port_fdb *fdb;
2003
2004 if (!is_unicast_ether_addr(addr.mac))
2005 continue;
2006
2007 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002008 fdb->vid = vid;
2009 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002010 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2011 fdb->ndm_state = NUD_NOARP;
2012 else
2013 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002014 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2015 struct switchdev_obj_port_mdb *mdb;
2016
2017 if (!is_multicast_ether_addr(addr.mac))
2018 continue;
2019
2020 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2021 mdb->vid = vid;
2022 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002023 } else {
2024 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002025 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002026
2027 err = cb(obj);
2028 if (err)
2029 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002030 } while (!is_broadcast_ether_addr(addr.mac));
2031
2032 return err;
2033}
2034
Vivien Didelot83dabd12016-08-31 11:50:04 -04002035static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2036 struct switchdev_obj *obj,
2037 int (*cb)(struct switchdev_obj *obj))
2038{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002039 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002040 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2041 };
2042 u16 fid;
2043 int err;
2044
2045 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002046 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002047 if (err)
2048 return err;
2049
2050 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2051 if (err)
2052 return err;
2053
2054 /* Dump VLANs' Filtering Information Databases */
2055 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2056 if (err)
2057 return err;
2058
2059 do {
2060 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2061 if (err)
2062 return err;
2063
2064 if (!vlan.valid)
2065 break;
2066
2067 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2068 obj, cb);
2069 if (err)
2070 return err;
2071 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2072
2073 return err;
2074}
2075
Vivien Didelotf81ec902016-05-09 13:22:58 -04002076static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2077 struct switchdev_obj_port_fdb *fdb,
2078 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002079{
Vivien Didelot04bed142016-08-31 18:06:13 -04002080 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002081 int err;
2082
Vivien Didelotfad09c72016-06-21 12:28:20 -04002083 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002084 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002085 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002086
2087 return err;
2088}
2089
Vivien Didelotf81ec902016-05-09 13:22:58 -04002090static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002091 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002092{
Vivien Didelot04bed142016-08-31 18:06:13 -04002093 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002094 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002095
Vivien Didelotfad09c72016-06-21 12:28:20 -04002096 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002097
Vivien Didelotfae8a252017-01-27 15:29:42 -05002098 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002099 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfae8a252017-01-27 15:29:42 -05002100 if (ds->ports[i].bridge_dev == br) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002101 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002102 if (err)
2103 break;
2104 }
2105 }
2106
Vivien Didelotfad09c72016-06-21 12:28:20 -04002107 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002108
Vivien Didelot466dfa02016-02-26 13:16:05 -05002109 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002110}
2111
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002112static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2113 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002114{
Vivien Didelot04bed142016-08-31 18:06:13 -04002115 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002116 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002117
Vivien Didelotfad09c72016-06-21 12:28:20 -04002118 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002119
Vivien Didelotfae8a252017-01-27 15:29:42 -05002120 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002121 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfae8a252017-01-27 15:29:42 -05002122 if (i == port || ds->ports[i].bridge_dev == br)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002123 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002124 netdev_warn(ds->ports[i].netdev,
2125 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002126
Vivien Didelotfad09c72016-06-21 12:28:20 -04002127 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002128}
2129
Vivien Didelot17e708b2016-12-05 17:30:27 -05002130static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2131{
2132 if (chip->info->ops->reset)
2133 return chip->info->ops->reset(chip);
2134
2135 return 0;
2136}
2137
Vivien Didelot309eca62016-12-05 17:30:26 -05002138static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2139{
2140 struct gpio_desc *gpiod = chip->reset;
2141
2142 /* If there is a GPIO connected to the reset pin, toggle it */
2143 if (gpiod) {
2144 gpiod_set_value_cansleep(gpiod, 1);
2145 usleep_range(10000, 20000);
2146 gpiod_set_value_cansleep(gpiod, 0);
2147 usleep_range(10000, 20000);
2148 }
2149}
2150
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002151static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2152{
2153 int i, err;
2154
2155 /* Set all ports to the Disabled state */
2156 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2157 err = mv88e6xxx_port_set_state(chip, i,
2158 PORT_CONTROL_STATE_DISABLED);
2159 if (err)
2160 return err;
2161 }
2162
2163 /* Wait for transmit queues to drain,
2164 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2165 */
2166 usleep_range(2000, 4000);
2167
2168 return 0;
2169}
2170
Vivien Didelotfad09c72016-06-21 12:28:20 -04002171static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002172{
Vivien Didelota935c052016-09-29 12:21:53 -04002173 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002174
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002175 err = mv88e6xxx_disable_ports(chip);
2176 if (err)
2177 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002178
Vivien Didelot309eca62016-12-05 17:30:26 -05002179 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002180
Vivien Didelot17e708b2016-12-05 17:30:27 -05002181 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002182}
2183
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002184static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002185{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002186 u16 val;
2187 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002188
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002189 /* Clear Power Down bit */
2190 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2191 if (err)
2192 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002193
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002194 if (val & BMCR_PDOWN) {
2195 val &= ~BMCR_PDOWN;
2196 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002197 }
2198
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002199 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002200}
2201
Andrew Lunn56995cb2016-12-03 04:35:19 +01002202static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2203 int upstream_port)
2204{
2205 int err;
2206
2207 err = chip->info->ops->port_set_frame_mode(
2208 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2209 if (err)
2210 return err;
2211
2212 return chip->info->ops->port_set_egress_unknowns(
2213 chip, port, port == upstream_port);
2214}
2215
2216static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2217{
2218 int err;
2219
2220 switch (chip->info->tag_protocol) {
2221 case DSA_TAG_PROTO_EDSA:
2222 err = chip->info->ops->port_set_frame_mode(
2223 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2224 if (err)
2225 return err;
2226
2227 err = mv88e6xxx_port_set_egress_mode(
2228 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2229 if (err)
2230 return err;
2231
2232 if (chip->info->ops->port_set_ether_type)
2233 err = chip->info->ops->port_set_ether_type(
2234 chip, port, ETH_P_EDSA);
2235 break;
2236
2237 case DSA_TAG_PROTO_DSA:
2238 err = chip->info->ops->port_set_frame_mode(
2239 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2240 if (err)
2241 return err;
2242
2243 err = mv88e6xxx_port_set_egress_mode(
2244 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2245 break;
2246 default:
2247 err = -EINVAL;
2248 }
2249
2250 if (err)
2251 return err;
2252
2253 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2254}
2255
2256static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2257{
2258 int err;
2259
2260 err = chip->info->ops->port_set_frame_mode(
2261 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2262 if (err)
2263 return err;
2264
2265 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2266}
2267
Vivien Didelotea698f42017-03-11 16:12:50 -05002268static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2269{
2270 bool message = dsa_is_dsa_port(chip->ds, port);
2271
2272 return mv88e6xxx_port_set_message_port(chip, port, message);
2273}
2274
Vivien Didelotfad09c72016-06-21 12:28:20 -04002275static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002276{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002277 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002278 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002279 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002280
Vivien Didelotd78343d2016-11-04 03:23:36 +01002281 /* MAC Forcing register: don't force link, speed, duplex or flow control
2282 * state to any particular values on physical ports, but force the CPU
2283 * port and all DSA ports to their maximum bandwidth and full duplex.
2284 */
2285 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2286 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2287 SPEED_MAX, DUPLEX_FULL,
2288 PHY_INTERFACE_MODE_NA);
2289 else
2290 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2291 SPEED_UNFORCED, DUPLEX_UNFORCED,
2292 PHY_INTERFACE_MODE_NA);
2293 if (err)
2294 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002295
2296 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2297 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2298 * tunneling, determine priority by looking at 802.1p and IP
2299 * priority fields (IP prio has precedence), and set STP state
2300 * to Forwarding.
2301 *
2302 * If this is the CPU link, use DSA or EDSA tagging depending
2303 * on which tagging mode was configured.
2304 *
2305 * If this is a link to another switch, use DSA tagging mode.
2306 *
2307 * If this is the upstream port for this switch, enable
2308 * forwarding of unknown unicasts and multicasts.
2309 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002310 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002311 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2312 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002313 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2314 if (err)
2315 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002316
Andrew Lunn56995cb2016-12-03 04:35:19 +01002317 if (dsa_is_cpu_port(ds, port)) {
2318 err = mv88e6xxx_setup_port_cpu(chip, port);
2319 } else if (dsa_is_dsa_port(ds, port)) {
2320 err = mv88e6xxx_setup_port_dsa(chip, port,
2321 dsa_upstream_port(ds));
2322 } else {
2323 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002324 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002325 if (err)
2326 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002327
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002328 /* If this port is connected to a SerDes, make sure the SerDes is not
2329 * powered down.
2330 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002331 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002332 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2333 if (err)
2334 return err;
2335 reg &= PORT_STATUS_CMODE_MASK;
2336 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2337 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2338 (reg == PORT_STATUS_CMODE_SGMII)) {
2339 err = mv88e6xxx_serdes_power_on(chip);
2340 if (err < 0)
2341 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002342 }
2343 }
2344
Vivien Didelot8efdda42015-08-13 12:52:23 -04002345 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002346 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002347 * untagged frames on this port, do a destination address lookup on all
2348 * received packets as usual, disable ARP mirroring and don't send a
2349 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002350 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002351 err = mv88e6xxx_port_set_map_da(chip, port);
2352 if (err)
2353 return err;
2354
Andrew Lunn54d792f2015-05-06 01:09:47 +02002355 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01002356 if (chip->info->ops->port_set_upstream_port) {
2357 err = chip->info->ops->port_set_upstream_port(
2358 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002359 if (err)
2360 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002361 }
2362
Andrew Lunna23b2962017-02-04 20:15:28 +01002363 err = mv88e6xxx_port_set_8021q_mode(chip, port,
2364 PORT_CONTROL_2_8021Q_DISABLED);
2365 if (err)
2366 return err;
2367
Andrew Lunn5f436662016-12-03 04:45:17 +01002368 if (chip->info->ops->port_jumbo_config) {
2369 err = chip->info->ops->port_jumbo_config(chip, port);
2370 if (err)
2371 return err;
2372 }
2373
Andrew Lunn54d792f2015-05-06 01:09:47 +02002374 /* Port Association Vector: when learning source addresses
2375 * of packets, add the address to the address database using
2376 * a port bitmap that has only the bit for this port set and
2377 * the other bits clear.
2378 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002379 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002380 /* Disable learning for CPU port */
2381 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002382 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002383
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002384 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2385 if (err)
2386 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002387
2388 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002389 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2390 if (err)
2391 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002392
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002393 if (chip->info->ops->port_pause_config) {
2394 err = chip->info->ops->port_pause_config(chip, port);
2395 if (err)
2396 return err;
2397 }
2398
Vivien Didelotfad09c72016-06-21 12:28:20 -04002399 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2400 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01002401 mv88e6xxx_6320_family(chip) || mv88e6xxx_6341_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002402 /* Port ATU control: disable limiting the number of
2403 * address database entries that this port is allowed
2404 * to use.
2405 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002406 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2407 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002408 /* Priority Override: disable DA, SA and VTU priority
2409 * override.
2410 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002411 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2412 0x0000);
2413 if (err)
2414 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002415 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002416
Andrew Lunnef0a7312016-12-03 04:35:16 +01002417 if (chip->info->ops->port_tag_remap) {
2418 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002419 if (err)
2420 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002421 }
2422
Andrew Lunnef70b112016-12-03 04:45:18 +01002423 if (chip->info->ops->port_egress_rate_limiting) {
2424 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002425 if (err)
2426 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002427 }
2428
Vivien Didelotea698f42017-03-11 16:12:50 -05002429 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002430 if (err)
2431 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002432
Vivien Didelot207afda2016-04-14 14:42:09 -04002433 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002434 * database, and allow bidirectional communication between the
2435 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002436 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002437 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002438 if (err)
2439 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002440
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002441 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2442 if (err)
2443 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002444
2445 /* Default VLAN ID and priority: don't set a default VLAN
2446 * ID, and set the default packet priority to zero.
2447 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002448 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002449}
2450
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002451static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002452{
2453 int err;
2454
Vivien Didelota935c052016-09-29 12:21:53 -04002455 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002456 if (err)
2457 return err;
2458
Vivien Didelota935c052016-09-29 12:21:53 -04002459 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002460 if (err)
2461 return err;
2462
Vivien Didelota935c052016-09-29 12:21:53 -04002463 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2464 if (err)
2465 return err;
2466
2467 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002468}
2469
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002470static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2471 unsigned int ageing_time)
2472{
Vivien Didelot04bed142016-08-31 18:06:13 -04002473 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002474 int err;
2475
2476 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002477 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002478 mutex_unlock(&chip->reg_lock);
2479
2480 return err;
2481}
2482
Vivien Didelot97299342016-07-18 20:45:30 -04002483static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002484{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002485 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002486 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002487 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002488
Vivien Didelot119477b2016-05-09 13:22:51 -04002489 /* Enable the PHY Polling Unit if present, don't discard any packets,
2490 * and mask all interrupt sources.
2491 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002492 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002493 if (err)
2494 return err;
2495
Andrew Lunn33641992016-12-03 04:35:17 +01002496 if (chip->info->ops->g1_set_cpu_port) {
2497 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2498 if (err)
2499 return err;
2500 }
2501
2502 if (chip->info->ops->g1_set_egress_port) {
2503 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2504 if (err)
2505 return err;
2506 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002507
Vivien Didelot50484ff2016-05-09 13:22:54 -04002508 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002509 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2510 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2511 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002512 if (err)
2513 return err;
2514
Vivien Didelotacddbd22016-07-18 20:45:39 -04002515 /* Clear all the VTU and STU entries */
2516 err = _mv88e6xxx_vtu_stu_flush(chip);
2517 if (err < 0)
2518 return err;
2519
Vivien Didelot08a01262016-05-09 13:22:50 -04002520 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002521 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002522 if (err)
2523 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002524 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002525 if (err)
2526 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002527 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002528 if (err)
2529 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002530 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002531 if (err)
2532 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002533 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002534 if (err)
2535 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002536 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002537 if (err)
2538 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002539 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002540 if (err)
2541 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002542 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002543 if (err)
2544 return err;
2545
2546 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002547 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002548 if (err)
2549 return err;
2550
Andrew Lunnde2273872016-11-21 23:27:01 +01002551 /* Initialize the statistics unit */
2552 err = mv88e6xxx_stats_set_histogram(chip);
2553 if (err)
2554 return err;
2555
Vivien Didelot97299342016-07-18 20:45:30 -04002556 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002557 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2558 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002559 if (err)
2560 return err;
2561
2562 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002563 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002564 if (err)
2565 return err;
2566
2567 return 0;
2568}
2569
Vivien Didelotf81ec902016-05-09 13:22:58 -04002570static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002571{
Vivien Didelot04bed142016-08-31 18:06:13 -04002572 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002573 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002574 int i;
2575
Vivien Didelotfad09c72016-06-21 12:28:20 -04002576 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002577 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002578
Vivien Didelotfad09c72016-06-21 12:28:20 -04002579 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002580
Vivien Didelot97299342016-07-18 20:45:30 -04002581 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002582 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002583 err = mv88e6xxx_setup_port(chip, i);
2584 if (err)
2585 goto unlock;
2586 }
2587
2588 /* Setup Switch Global 1 Registers */
2589 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002590 if (err)
2591 goto unlock;
2592
Vivien Didelot97299342016-07-18 20:45:30 -04002593 /* Setup Switch Global 2 Registers */
2594 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2595 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002596 if (err)
2597 goto unlock;
2598 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002599
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002600 err = mv88e6xxx_atu_setup(chip);
2601 if (err)
2602 goto unlock;
2603
Andrew Lunn6e55f692016-12-03 04:45:16 +01002604 /* Some generations have the configuration of sending reserved
2605 * management frames to the CPU in global2, others in
2606 * global1. Hence it does not fit the two setup functions
2607 * above.
2608 */
2609 if (chip->info->ops->mgmt_rsvd2cpu) {
2610 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2611 if (err)
2612 goto unlock;
2613 }
2614
Vivien Didelot6b17e862015-08-13 12:52:18 -04002615unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002616 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002617
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002618 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002619}
2620
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002621static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2622{
Vivien Didelot04bed142016-08-31 18:06:13 -04002623 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002624 int err;
2625
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002626 if (!chip->info->ops->set_switch_mac)
2627 return -EOPNOTSUPP;
2628
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002629 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002630 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002631 mutex_unlock(&chip->reg_lock);
2632
2633 return err;
2634}
2635
Vivien Didelote57e5e72016-08-15 17:19:00 -04002636static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002637{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002638 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2639 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002640 u16 val;
2641 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002642
Andrew Lunnee26a222017-01-24 14:53:48 +01002643 if (!chip->info->ops->phy_read)
2644 return -EOPNOTSUPP;
2645
Vivien Didelotfad09c72016-06-21 12:28:20 -04002646 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002647 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002648 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002649
Andrew Lunnda9f3302017-02-01 03:40:05 +01002650 if (reg == MII_PHYSID2) {
2651 /* Some internal PHYS don't have a model number. Use
2652 * the mv88e6390 family model number instead.
2653 */
2654 if (!(val & 0x3f0))
2655 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2656 }
2657
Vivien Didelote57e5e72016-08-15 17:19:00 -04002658 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002659}
2660
Vivien Didelote57e5e72016-08-15 17:19:00 -04002661static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002662{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002663 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2664 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002665 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002666
Andrew Lunnee26a222017-01-24 14:53:48 +01002667 if (!chip->info->ops->phy_write)
2668 return -EOPNOTSUPP;
2669
Vivien Didelotfad09c72016-06-21 12:28:20 -04002670 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002671 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002672 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002673
2674 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002675}
2676
Vivien Didelotfad09c72016-06-21 12:28:20 -04002677static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002678 struct device_node *np,
2679 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002680{
2681 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002682 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002683 struct mii_bus *bus;
2684 int err;
2685
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002686 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002687 if (!bus)
2688 return -ENOMEM;
2689
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002690 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002691 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002692 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002693 INIT_LIST_HEAD(&mdio_bus->list);
2694 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002695
Andrew Lunnb516d452016-06-04 21:17:06 +02002696 if (np) {
2697 bus->name = np->full_name;
2698 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2699 } else {
2700 bus->name = "mv88e6xxx SMI";
2701 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2702 }
2703
2704 bus->read = mv88e6xxx_mdio_read;
2705 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002706 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002707
Andrew Lunna3c53be52017-01-24 14:53:50 +01002708 if (np)
2709 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002710 else
2711 err = mdiobus_register(bus);
2712 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002713 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002714 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002715 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002716
2717 if (external)
2718 list_add_tail(&mdio_bus->list, &chip->mdios);
2719 else
2720 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002721
2722 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002723}
2724
Andrew Lunna3c53be52017-01-24 14:53:50 +01002725static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2726 { .compatible = "marvell,mv88e6xxx-mdio-external",
2727 .data = (void *)true },
2728 { },
2729};
2730
2731static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2732 struct device_node *np)
2733{
2734 const struct of_device_id *match;
2735 struct device_node *child;
2736 int err;
2737
2738 /* Always register one mdio bus for the internal/default mdio
2739 * bus. This maybe represented in the device tree, but is
2740 * optional.
2741 */
2742 child = of_get_child_by_name(np, "mdio");
2743 err = mv88e6xxx_mdio_register(chip, child, false);
2744 if (err)
2745 return err;
2746
2747 /* Walk the device tree, and see if there are any other nodes
2748 * which say they are compatible with the external mdio
2749 * bus.
2750 */
2751 for_each_available_child_of_node(np, child) {
2752 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2753 if (match) {
2754 err = mv88e6xxx_mdio_register(chip, child, true);
2755 if (err)
2756 return err;
2757 }
2758 }
2759
2760 return 0;
2761}
2762
2763static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002764
2765{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002766 struct mv88e6xxx_mdio_bus *mdio_bus;
2767 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002768
Andrew Lunna3c53be52017-01-24 14:53:50 +01002769 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2770 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002771
Andrew Lunna3c53be52017-01-24 14:53:50 +01002772 mdiobus_unregister(bus);
2773 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002774}
2775
Vivien Didelot855b1932016-07-20 18:18:35 -04002776static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2777{
Vivien Didelot04bed142016-08-31 18:06:13 -04002778 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002779
2780 return chip->eeprom_len;
2781}
2782
Vivien Didelot855b1932016-07-20 18:18:35 -04002783static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2784 struct ethtool_eeprom *eeprom, u8 *data)
2785{
Vivien Didelot04bed142016-08-31 18:06:13 -04002786 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002787 int err;
2788
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002789 if (!chip->info->ops->get_eeprom)
2790 return -EOPNOTSUPP;
2791
Vivien Didelot855b1932016-07-20 18:18:35 -04002792 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002793 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002794 mutex_unlock(&chip->reg_lock);
2795
2796 if (err)
2797 return err;
2798
2799 eeprom->magic = 0xc3ec4951;
2800
2801 return 0;
2802}
2803
Vivien Didelot855b1932016-07-20 18:18:35 -04002804static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2805 struct ethtool_eeprom *eeprom, u8 *data)
2806{
Vivien Didelot04bed142016-08-31 18:06:13 -04002807 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002808 int err;
2809
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002810 if (!chip->info->ops->set_eeprom)
2811 return -EOPNOTSUPP;
2812
Vivien Didelot855b1932016-07-20 18:18:35 -04002813 if (eeprom->magic != 0xc3ec4951)
2814 return -EINVAL;
2815
2816 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002817 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002818 mutex_unlock(&chip->reg_lock);
2819
2820 return err;
2821}
2822
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002823static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002824 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002825 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002826 .phy_read = mv88e6xxx_phy_ppu_read,
2827 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002828 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002829 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002830 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002831 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002832 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2833 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
2834 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002835 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002836 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002837 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002838 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2839 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002840 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002841 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2842 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002843 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002844 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002845 .ppu_enable = mv88e6185_g1_ppu_enable,
2846 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002847 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002848};
2849
2850static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002851 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002852 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002853 .phy_read = mv88e6xxx_phy_ppu_read,
2854 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002855 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002856 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002857 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002858 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01002859 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
2860 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002861 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002862 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2863 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002864 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002865 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002866 .ppu_enable = mv88e6185_g1_ppu_enable,
2867 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002868 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002869};
2870
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002871static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002872 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002873 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2874 .phy_read = mv88e6xxx_g2_smi_phy_read,
2875 .phy_write = mv88e6xxx_g2_smi_phy_write,
2876 .port_set_link = mv88e6xxx_port_set_link,
2877 .port_set_duplex = mv88e6xxx_port_set_duplex,
2878 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002879 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002880 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2881 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
2882 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002883 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002884 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002885 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002886 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2887 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2888 .stats_get_strings = mv88e6095_stats_get_strings,
2889 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002890 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2891 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002892 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002893 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002894 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002895};
2896
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002897static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002898 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002899 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002900 .phy_read = mv88e6165_phy_read,
2901 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002902 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002903 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002904 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002905 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
2906 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002907 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002908 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2909 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002910 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002911 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2912 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002913 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002914 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002915 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002916};
2917
2918static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002919 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002920 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002921 .phy_read = mv88e6xxx_phy_ppu_read,
2922 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002923 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002924 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002925 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002926 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002927 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01002928 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002929 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002930 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01002931 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002932 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002933 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002934 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002935 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2936 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002937 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002938 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2939 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002940 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002941 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002942 .ppu_enable = mv88e6185_g1_ppu_enable,
2943 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002944 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002945};
2946
2947static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002948 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002949 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002950 .phy_read = mv88e6165_phy_read,
2951 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002952 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002953 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002954 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002955 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002956 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2957 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
2958 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002959 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002960 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002961 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002962 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002963 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2964 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002965 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002966 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2967 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002968 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002969 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002970 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002971};
2972
2973static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002974 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002975 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002976 .phy_read = mv88e6165_phy_read,
2977 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002978 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002979 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002980 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002981 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002982 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2983 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002984 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002985 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2986 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002987 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002988 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002989 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002990};
2991
2992static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002993 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002994 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002995 .phy_read = mv88e6xxx_g2_smi_phy_read,
2996 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002997 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002998 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01002999 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003000 .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 = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003007 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003008 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003009 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3010 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003011 .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,
Andrew Lunnfcd25162017-02-09 00:03:42 +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,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003017};
3018
3019static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003020 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003021 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3022 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003023 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003024 .phy_read = mv88e6xxx_g2_smi_phy_read,
3025 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003026 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003027 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003028 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003029 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003030 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003031 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3032 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3033 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003034 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003035 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003036 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003037 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003038 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3039 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003040 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003041 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3042 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003043 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003044 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003045 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003046};
3047
3048static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003049 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003050 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003051 .phy_read = mv88e6xxx_g2_smi_phy_read,
3052 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003053 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003054 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003055 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003056 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003057 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003058 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3059 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3060 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003061 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003062 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003063 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003064 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003065 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3066 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003067 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003068 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3069 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003070 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003071 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003072 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003073};
3074
3075static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003076 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003077 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3078 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003079 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003080 .phy_read = mv88e6xxx_g2_smi_phy_read,
3081 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003082 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003083 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003084 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003085 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003086 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003087 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3088 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3089 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003090 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003091 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003092 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003093 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003094 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3095 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003096 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003097 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3098 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003099 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003100 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003101 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003102};
3103
3104static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003105 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003106 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003107 .phy_read = mv88e6xxx_phy_ppu_read,
3108 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003109 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003110 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003111 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003112 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01003113 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003114 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003115 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003116 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003117 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3118 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003119 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003120 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3121 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003122 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003123 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003124 .ppu_enable = mv88e6185_g1_ppu_enable,
3125 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003126 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003127};
3128
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003129static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003130 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003131 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3132 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003133 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3134 .phy_read = mv88e6xxx_g2_smi_phy_read,
3135 .phy_write = mv88e6xxx_g2_smi_phy_write,
3136 .port_set_link = mv88e6xxx_port_set_link,
3137 .port_set_duplex = mv88e6xxx_port_set_duplex,
3138 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3139 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003140 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003141 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3142 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3143 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003144 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003145 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003146 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003147 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3148 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003149 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003150 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3151 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003152 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003153 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003154 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003155};
3156
3157static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003158 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003159 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3160 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003161 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3162 .phy_read = mv88e6xxx_g2_smi_phy_read,
3163 .phy_write = mv88e6xxx_g2_smi_phy_write,
3164 .port_set_link = mv88e6xxx_port_set_link,
3165 .port_set_duplex = mv88e6xxx_port_set_duplex,
3166 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3167 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003168 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003169 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3170 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3171 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003172 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003173 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003174 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003175 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3176 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003177 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003178 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3179 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003180 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003181 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003182 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003183};
3184
3185static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003186 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003187 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3188 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003189 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3190 .phy_read = mv88e6xxx_g2_smi_phy_read,
3191 .phy_write = mv88e6xxx_g2_smi_phy_write,
3192 .port_set_link = mv88e6xxx_port_set_link,
3193 .port_set_duplex = mv88e6xxx_port_set_duplex,
3194 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3195 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003196 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003197 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3198 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3199 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003200 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003201 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003202 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003203 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3204 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003205 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003206 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3207 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003208 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003209 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003210 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003211};
3212
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003213static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003214 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003215 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3216 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003217 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003218 .phy_read = mv88e6xxx_g2_smi_phy_read,
3219 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003220 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003221 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003222 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003223 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003224 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003225 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3226 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3227 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003228 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003229 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003230 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003231 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003232 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3233 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003234 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003235 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3236 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003237 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003238 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003239 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003240};
3241
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003242static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003243 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003244 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3245 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003246 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3247 .phy_read = mv88e6xxx_g2_smi_phy_read,
3248 .phy_write = mv88e6xxx_g2_smi_phy_write,
3249 .port_set_link = mv88e6xxx_port_set_link,
3250 .port_set_duplex = mv88e6xxx_port_set_duplex,
3251 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3252 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003253 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003254 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3255 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3256 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003257 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003258 .port_set_cmode = mv88e6390x_port_set_cmode,
Andrew Lunn79523472016-11-21 23:27:00 +01003259 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003260 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003261 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3262 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003263 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003264 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3265 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003266 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003267 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003268 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003269};
3270
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003271static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003272 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003273 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3274 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003275 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003276 .phy_read = mv88e6xxx_g2_smi_phy_read,
3277 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003278 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003279 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003280 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003281 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003282 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3283 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3284 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003285 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003286 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003287 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003288 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003289 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3290 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003291 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003292 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3293 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003294 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003295 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003296};
3297
3298static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003299 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003300 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3301 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003302 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003303 .phy_read = mv88e6xxx_g2_smi_phy_read,
3304 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003305 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003306 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003307 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003308 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003309 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3310 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3311 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003312 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003313 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003314 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003315 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003316 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3317 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003318 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003319 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3320 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003321 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003322};
3323
3324static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003325 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003326 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003327 .phy_read = mv88e6xxx_g2_smi_phy_read,
3328 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003329 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003330 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003331 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003332 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003333 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003334 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3335 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3336 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003337 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003338 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003339 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003340 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003341 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3342 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003343 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003344 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3345 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003346 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003347 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003348 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003349};
3350
3351static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003352 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003353 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003354 .phy_read = mv88e6xxx_g2_smi_phy_read,
3355 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003356 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003357 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003358 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003359 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003360 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003361 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3362 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3363 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003364 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003365 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003366 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003367 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003368 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3369 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003370 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003371 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3372 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003373 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003374 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003375 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003376};
3377
3378static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003379 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003380 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3381 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003382 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003383 .phy_read = mv88e6xxx_g2_smi_phy_read,
3384 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003385 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003386 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003387 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003388 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003389 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003390 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3391 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3392 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003393 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003394 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003395 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003396 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003397 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3398 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003399 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003400 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3401 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003402 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003403 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003404 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003405};
3406
Gregory CLEMENT15587272017-01-30 20:29:35 +01003407static const struct mv88e6xxx_ops mv88e6141_ops = {
3408 /* MV88E6XXX_FAMILY_6341 */
3409 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3410 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3411 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3412 .phy_read = mv88e6xxx_g2_smi_phy_read,
3413 .phy_write = mv88e6xxx_g2_smi_phy_write,
3414 .port_set_link = mv88e6xxx_port_set_link,
3415 .port_set_duplex = mv88e6xxx_port_set_duplex,
3416 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3417 .port_set_speed = mv88e6390_port_set_speed,
3418 .port_tag_remap = mv88e6095_port_tag_remap,
3419 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3420 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3421 .port_set_ether_type = mv88e6351_port_set_ether_type,
3422 .port_jumbo_config = mv88e6165_port_jumbo_config,
3423 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3424 .port_pause_config = mv88e6097_port_pause_config,
3425 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3426 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3427 .stats_get_strings = mv88e6320_stats_get_strings,
3428 .stats_get_stats = mv88e6390_stats_get_stats,
3429 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3430 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003431 .watchdog_ops = &mv88e6390_watchdog_ops,
Gregory CLEMENT15587272017-01-30 20:29:35 +01003432 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3433 .reset = mv88e6352_g1_reset,
3434};
3435
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003436static const struct mv88e6xxx_ops mv88e6341_ops = {
3437 /* MV88E6XXX_FAMILY_6341 */
3438 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3439 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3440 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3441 .phy_read = mv88e6xxx_g2_smi_phy_read,
3442 .phy_write = mv88e6xxx_g2_smi_phy_write,
3443 .port_set_link = mv88e6xxx_port_set_link,
3444 .port_set_duplex = mv88e6xxx_port_set_duplex,
3445 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3446 .port_set_speed = mv88e6390_port_set_speed,
3447 .port_tag_remap = mv88e6095_port_tag_remap,
3448 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3449 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3450 .port_set_ether_type = mv88e6351_port_set_ether_type,
3451 .port_jumbo_config = mv88e6165_port_jumbo_config,
3452 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3453 .port_pause_config = mv88e6097_port_pause_config,
3454 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3455 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3456 .stats_get_strings = mv88e6320_stats_get_strings,
3457 .stats_get_stats = mv88e6390_stats_get_stats,
3458 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3459 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003460 .watchdog_ops = &mv88e6390_watchdog_ops,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003461 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3462 .reset = mv88e6352_g1_reset,
3463};
3464
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003465static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003466 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003467 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3468 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003469 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3470 .phy_read = mv88e6xxx_g2_smi_phy_read,
3471 .phy_write = mv88e6xxx_g2_smi_phy_write,
3472 .port_set_link = mv88e6xxx_port_set_link,
3473 .port_set_duplex = mv88e6xxx_port_set_duplex,
3474 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3475 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003476 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003477 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3478 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3479 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003480 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003481 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003482 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003483 .port_set_cmode = mv88e6390x_port_set_cmode,
Andrew Lunn79523472016-11-21 23:27:00 +01003484 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003485 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003486 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3487 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003488 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003489 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3490 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003491 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003492 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003493 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003494};
3495
3496static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003497 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003498 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3499 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003500 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3501 .phy_read = mv88e6xxx_g2_smi_phy_read,
3502 .phy_write = mv88e6xxx_g2_smi_phy_write,
3503 .port_set_link = mv88e6xxx_port_set_link,
3504 .port_set_duplex = mv88e6xxx_port_set_duplex,
3505 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3506 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003507 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003508 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3509 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3510 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003511 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003512 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003513 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003514 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003515 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003516 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3517 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003518 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003519 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3520 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003521 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003522 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003523 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003524};
3525
3526static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003527 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003528 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3529 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003530 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3531 .phy_read = mv88e6xxx_g2_smi_phy_read,
3532 .phy_write = mv88e6xxx_g2_smi_phy_write,
3533 .port_set_link = mv88e6xxx_port_set_link,
3534 .port_set_duplex = mv88e6xxx_port_set_duplex,
3535 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3536 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003537 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003538 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3539 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3540 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003541 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003542 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003543 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003544 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3545 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003546 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003547 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3548 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003549 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003550 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003551 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003552};
3553
Andrew Lunn56995cb2016-12-03 04:35:19 +01003554static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3555 const struct mv88e6xxx_ops *ops)
3556{
3557 if (!ops->port_set_frame_mode) {
3558 dev_err(chip->dev, "Missing port_set_frame_mode");
3559 return -EINVAL;
3560 }
3561
3562 if (!ops->port_set_egress_unknowns) {
3563 dev_err(chip->dev, "Missing port_set_egress_mode");
3564 return -EINVAL;
3565 }
3566
3567 return 0;
3568}
3569
Vivien Didelotf81ec902016-05-09 13:22:58 -04003570static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3571 [MV88E6085] = {
3572 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3573 .family = MV88E6XXX_FAMILY_6097,
3574 .name = "Marvell 88E6085",
3575 .num_databases = 4096,
3576 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003577 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003578 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003579 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003580 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003581 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003582 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003583 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003584 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003585 },
3586
3587 [MV88E6095] = {
3588 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3589 .family = MV88E6XXX_FAMILY_6095,
3590 .name = "Marvell 88E6095/88E6095F",
3591 .num_databases = 256,
3592 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003593 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003594 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003595 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003596 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003597 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003598 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003599 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003600 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003601 },
3602
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003603 [MV88E6097] = {
3604 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3605 .family = MV88E6XXX_FAMILY_6097,
3606 .name = "Marvell 88E6097/88E6097F",
3607 .num_databases = 4096,
3608 .num_ports = 11,
3609 .port_base_addr = 0x10,
3610 .global1_addr = 0x1b,
3611 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003612 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003613 .atu_move_port_mask = 0xf,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003614 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003615 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3616 .ops = &mv88e6097_ops,
3617 },
3618
Vivien Didelotf81ec902016-05-09 13:22:58 -04003619 [MV88E6123] = {
3620 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3621 .family = MV88E6XXX_FAMILY_6165,
3622 .name = "Marvell 88E6123",
3623 .num_databases = 4096,
3624 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003625 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003626 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003627 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003628 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003629 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003630 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003631 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003632 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003633 },
3634
3635 [MV88E6131] = {
3636 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3637 .family = MV88E6XXX_FAMILY_6185,
3638 .name = "Marvell 88E6131",
3639 .num_databases = 256,
3640 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003641 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003642 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003643 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003644 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003645 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003646 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003647 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003648 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003649 },
3650
3651 [MV88E6161] = {
3652 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3653 .family = MV88E6XXX_FAMILY_6165,
3654 .name = "Marvell 88E6161",
3655 .num_databases = 4096,
3656 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003657 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003658 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003659 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003660 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003661 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003662 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003663 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003664 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003665 },
3666
3667 [MV88E6165] = {
3668 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3669 .family = MV88E6XXX_FAMILY_6165,
3670 .name = "Marvell 88E6165",
3671 .num_databases = 4096,
3672 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003673 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003674 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003675 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003676 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003677 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003678 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003679 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003680 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003681 },
3682
3683 [MV88E6171] = {
3684 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3685 .family = MV88E6XXX_FAMILY_6351,
3686 .name = "Marvell 88E6171",
3687 .num_databases = 4096,
3688 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003689 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003690 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003691 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003692 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003693 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003694 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003695 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003696 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003697 },
3698
3699 [MV88E6172] = {
3700 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3701 .family = MV88E6XXX_FAMILY_6352,
3702 .name = "Marvell 88E6172",
3703 .num_databases = 4096,
3704 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003705 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003706 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003707 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003708 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003709 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003710 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003711 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003712 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003713 },
3714
3715 [MV88E6175] = {
3716 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3717 .family = MV88E6XXX_FAMILY_6351,
3718 .name = "Marvell 88E6175",
3719 .num_databases = 4096,
3720 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003721 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003722 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003723 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003724 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003725 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003726 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003727 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003728 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003729 },
3730
3731 [MV88E6176] = {
3732 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3733 .family = MV88E6XXX_FAMILY_6352,
3734 .name = "Marvell 88E6176",
3735 .num_databases = 4096,
3736 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003737 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003738 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003739 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003740 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003741 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003742 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003743 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003744 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003745 },
3746
3747 [MV88E6185] = {
3748 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3749 .family = MV88E6XXX_FAMILY_6185,
3750 .name = "Marvell 88E6185",
3751 .num_databases = 256,
3752 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003753 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003754 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003755 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003756 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003757 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003758 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003759 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003760 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003761 },
3762
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003763 [MV88E6190] = {
3764 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3765 .family = MV88E6XXX_FAMILY_6390,
3766 .name = "Marvell 88E6190",
3767 .num_databases = 4096,
3768 .num_ports = 11, /* 10 + Z80 */
3769 .port_base_addr = 0x0,
3770 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003771 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003772 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003773 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003774 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003775 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3776 .ops = &mv88e6190_ops,
3777 },
3778
3779 [MV88E6190X] = {
3780 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3781 .family = MV88E6XXX_FAMILY_6390,
3782 .name = "Marvell 88E6190X",
3783 .num_databases = 4096,
3784 .num_ports = 11, /* 10 + Z80 */
3785 .port_base_addr = 0x0,
3786 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003787 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003788 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003789 .atu_move_port_mask = 0x1f,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003790 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003791 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3792 .ops = &mv88e6190x_ops,
3793 },
3794
3795 [MV88E6191] = {
3796 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3797 .family = MV88E6XXX_FAMILY_6390,
3798 .name = "Marvell 88E6191",
3799 .num_databases = 4096,
3800 .num_ports = 11, /* 10 + Z80 */
3801 .port_base_addr = 0x0,
3802 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003803 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003804 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003805 .atu_move_port_mask = 0x1f,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003806 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003807 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3808 .ops = &mv88e6391_ops,
3809 },
3810
Vivien Didelotf81ec902016-05-09 13:22:58 -04003811 [MV88E6240] = {
3812 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3813 .family = MV88E6XXX_FAMILY_6352,
3814 .name = "Marvell 88E6240",
3815 .num_databases = 4096,
3816 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003817 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003818 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003819 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003820 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003821 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003822 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003823 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003824 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003825 },
3826
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003827 [MV88E6290] = {
3828 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3829 .family = MV88E6XXX_FAMILY_6390,
3830 .name = "Marvell 88E6290",
3831 .num_databases = 4096,
3832 .num_ports = 11, /* 10 + Z80 */
3833 .port_base_addr = 0x0,
3834 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003835 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003836 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003837 .atu_move_port_mask = 0x1f,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003838 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003839 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3840 .ops = &mv88e6290_ops,
3841 },
3842
Vivien Didelotf81ec902016-05-09 13:22:58 -04003843 [MV88E6320] = {
3844 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3845 .family = MV88E6XXX_FAMILY_6320,
3846 .name = "Marvell 88E6320",
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 = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003853 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003854 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003855 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003856 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003857 },
3858
3859 [MV88E6321] = {
3860 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3861 .family = MV88E6XXX_FAMILY_6320,
3862 .name = "Marvell 88E6321",
3863 .num_databases = 4096,
3864 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003865 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003866 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003867 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003868 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003869 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003870 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003871 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003872 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003873 },
3874
Gregory CLEMENT15587272017-01-30 20:29:35 +01003875 [MV88E6141] = {
3876 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
3877 .family = MV88E6XXX_FAMILY_6341,
3878 .name = "Marvell 88E6341",
3879 .num_databases = 4096,
3880 .num_ports = 6,
3881 .port_base_addr = 0x10,
3882 .global1_addr = 0x1b,
3883 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003884 .atu_move_port_mask = 0x1f,
Gregory CLEMENT15587272017-01-30 20:29:35 +01003885 .tag_protocol = DSA_TAG_PROTO_EDSA,
3886 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3887 .ops = &mv88e6141_ops,
3888 },
3889
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003890 [MV88E6341] = {
3891 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
3892 .family = MV88E6XXX_FAMILY_6341,
3893 .name = "Marvell 88E6341",
3894 .num_databases = 4096,
3895 .num_ports = 6,
3896 .port_base_addr = 0x10,
3897 .global1_addr = 0x1b,
3898 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003899 .atu_move_port_mask = 0x1f,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003900 .tag_protocol = DSA_TAG_PROTO_EDSA,
3901 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3902 .ops = &mv88e6341_ops,
3903 },
3904
Vivien Didelotf81ec902016-05-09 13:22:58 -04003905 [MV88E6350] = {
3906 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3907 .family = MV88E6XXX_FAMILY_6351,
3908 .name = "Marvell 88E6350",
3909 .num_databases = 4096,
3910 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003911 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003912 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003913 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003914 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003915 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003916 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003917 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003918 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003919 },
3920
3921 [MV88E6351] = {
3922 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3923 .family = MV88E6XXX_FAMILY_6351,
3924 .name = "Marvell 88E6351",
3925 .num_databases = 4096,
3926 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003927 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003928 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003929 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003930 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003931 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003932 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003933 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003934 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003935 },
3936
3937 [MV88E6352] = {
3938 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
3939 .family = MV88E6XXX_FAMILY_6352,
3940 .name = "Marvell 88E6352",
3941 .num_databases = 4096,
3942 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003943 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003944 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003945 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003946 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003947 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003948 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003949 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003950 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003951 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003952 [MV88E6390] = {
3953 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
3954 .family = MV88E6XXX_FAMILY_6390,
3955 .name = "Marvell 88E6390",
3956 .num_databases = 4096,
3957 .num_ports = 11, /* 10 + Z80 */
3958 .port_base_addr = 0x0,
3959 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003960 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003961 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003962 .atu_move_port_mask = 0x1f,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003963 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003964 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3965 .ops = &mv88e6390_ops,
3966 },
3967 [MV88E6390X] = {
3968 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
3969 .family = MV88E6XXX_FAMILY_6390,
3970 .name = "Marvell 88E6390X",
3971 .num_databases = 4096,
3972 .num_ports = 11, /* 10 + Z80 */
3973 .port_base_addr = 0x0,
3974 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003975 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003976 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003977 .atu_move_port_mask = 0x1f,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003978 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003979 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3980 .ops = &mv88e6390x_ops,
3981 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003982};
3983
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003984static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003985{
Vivien Didelota439c062016-04-17 13:23:58 -04003986 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003987
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003988 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3989 if (mv88e6xxx_table[i].prod_num == prod_num)
3990 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003991
Vivien Didelotb9b37712015-10-30 19:39:48 -04003992 return NULL;
3993}
3994
Vivien Didelotfad09c72016-06-21 12:28:20 -04003995static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003996{
3997 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003998 unsigned int prod_num, rev;
3999 u16 id;
4000 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004001
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004002 mutex_lock(&chip->reg_lock);
4003 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4004 mutex_unlock(&chip->reg_lock);
4005 if (err)
4006 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004007
4008 prod_num = (id & 0xfff0) >> 4;
4009 rev = id & 0x000f;
4010
4011 info = mv88e6xxx_lookup_info(prod_num);
4012 if (!info)
4013 return -ENODEV;
4014
Vivien Didelotcaac8542016-06-20 13:14:09 -04004015 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004016 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004017
Vivien Didelotca070c12016-09-02 14:45:34 -04004018 err = mv88e6xxx_g2_require(chip);
4019 if (err)
4020 return err;
4021
Vivien Didelotfad09c72016-06-21 12:28:20 -04004022 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4023 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004024
4025 return 0;
4026}
4027
Vivien Didelotfad09c72016-06-21 12:28:20 -04004028static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004029{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004030 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004031
Vivien Didelotfad09c72016-06-21 12:28:20 -04004032 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4033 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004034 return NULL;
4035
Vivien Didelotfad09c72016-06-21 12:28:20 -04004036 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004037
Vivien Didelotfad09c72016-06-21 12:28:20 -04004038 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004039 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004040
Vivien Didelotfad09c72016-06-21 12:28:20 -04004041 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004042}
4043
Vivien Didelote57e5e72016-08-15 17:19:00 -04004044static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4045{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004046 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004047 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004048}
4049
Andrew Lunn930188c2016-08-22 16:01:03 +02004050static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4051{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004052 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004053 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004054}
4055
Vivien Didelotfad09c72016-06-21 12:28:20 -04004056static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004057 struct mii_bus *bus, int sw_addr)
4058{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004059 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004060 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004061 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004062 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004063 else
4064 return -EINVAL;
4065
Vivien Didelotfad09c72016-06-21 12:28:20 -04004066 chip->bus = bus;
4067 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004068
4069 return 0;
4070}
4071
Andrew Lunn7b314362016-08-22 16:01:01 +02004072static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4073{
Vivien Didelot04bed142016-08-31 18:06:13 -04004074 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004075
Andrew Lunn443d5a12016-12-03 04:35:18 +01004076 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004077}
4078
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004079static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4080 struct device *host_dev, int sw_addr,
4081 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004082{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004083 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004084 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004085 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004086
Vivien Didelota439c062016-04-17 13:23:58 -04004087 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004088 if (!bus)
4089 return NULL;
4090
Vivien Didelotfad09c72016-06-21 12:28:20 -04004091 chip = mv88e6xxx_alloc_chip(dsa_dev);
4092 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004093 return NULL;
4094
Vivien Didelotcaac8542016-06-20 13:14:09 -04004095 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004096 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004097
Vivien Didelotfad09c72016-06-21 12:28:20 -04004098 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004099 if (err)
4100 goto free;
4101
Vivien Didelotfad09c72016-06-21 12:28:20 -04004102 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004103 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004104 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004105
Andrew Lunndc30c352016-10-16 19:56:49 +02004106 mutex_lock(&chip->reg_lock);
4107 err = mv88e6xxx_switch_reset(chip);
4108 mutex_unlock(&chip->reg_lock);
4109 if (err)
4110 goto free;
4111
Vivien Didelote57e5e72016-08-15 17:19:00 -04004112 mv88e6xxx_phy_init(chip);
4113
Andrew Lunna3c53be52017-01-24 14:53:50 +01004114 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004115 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004116 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004117
Vivien Didelotfad09c72016-06-21 12:28:20 -04004118 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004119
Vivien Didelotfad09c72016-06-21 12:28:20 -04004120 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004121free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004122 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004123
4124 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004125}
4126
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004127static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4128 const struct switchdev_obj_port_mdb *mdb,
4129 struct switchdev_trans *trans)
4130{
4131 /* We don't need any dynamic resource from the kernel (yet),
4132 * so skip the prepare phase.
4133 */
4134
4135 return 0;
4136}
4137
4138static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4139 const struct switchdev_obj_port_mdb *mdb,
4140 struct switchdev_trans *trans)
4141{
Vivien Didelot04bed142016-08-31 18:06:13 -04004142 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004143
4144 mutex_lock(&chip->reg_lock);
4145 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4146 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4147 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4148 mutex_unlock(&chip->reg_lock);
4149}
4150
4151static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4152 const struct switchdev_obj_port_mdb *mdb)
4153{
Vivien Didelot04bed142016-08-31 18:06:13 -04004154 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004155 int err;
4156
4157 mutex_lock(&chip->reg_lock);
4158 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4159 GLOBAL_ATU_DATA_STATE_UNUSED);
4160 mutex_unlock(&chip->reg_lock);
4161
4162 return err;
4163}
4164
4165static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4166 struct switchdev_obj_port_mdb *mdb,
4167 int (*cb)(struct switchdev_obj *obj))
4168{
Vivien Didelot04bed142016-08-31 18:06:13 -04004169 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004170 int err;
4171
4172 mutex_lock(&chip->reg_lock);
4173 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4174 mutex_unlock(&chip->reg_lock);
4175
4176 return err;
4177}
4178
Florian Fainellia82f67a2017-01-08 14:52:08 -08004179static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004180 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004181 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004182 .setup = mv88e6xxx_setup,
4183 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004184 .adjust_link = mv88e6xxx_adjust_link,
4185 .get_strings = mv88e6xxx_get_strings,
4186 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4187 .get_sset_count = mv88e6xxx_get_sset_count,
4188 .set_eee = mv88e6xxx_set_eee,
4189 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004190 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004191 .get_eeprom = mv88e6xxx_get_eeprom,
4192 .set_eeprom = mv88e6xxx_set_eeprom,
4193 .get_regs_len = mv88e6xxx_get_regs_len,
4194 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004195 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004196 .port_bridge_join = mv88e6xxx_port_bridge_join,
4197 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4198 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004199 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004200 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4201 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4202 .port_vlan_add = mv88e6xxx_port_vlan_add,
4203 .port_vlan_del = mv88e6xxx_port_vlan_del,
4204 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4205 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4206 .port_fdb_add = mv88e6xxx_port_fdb_add,
4207 .port_fdb_del = mv88e6xxx_port_fdb_del,
4208 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004209 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4210 .port_mdb_add = mv88e6xxx_port_mdb_add,
4211 .port_mdb_del = mv88e6xxx_port_mdb_del,
4212 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004213};
4214
Florian Fainelliab3d4082017-01-08 14:52:07 -08004215static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4216 .ops = &mv88e6xxx_switch_ops,
4217};
4218
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004219static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004220{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004221 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004222 struct dsa_switch *ds;
4223
Vivien Didelota0c02162017-01-27 15:29:36 -05004224 ds = dsa_switch_alloc(dev, DSA_MAX_PORTS);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004225 if (!ds)
4226 return -ENOMEM;
4227
Vivien Didelotfad09c72016-06-21 12:28:20 -04004228 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004229 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004230
4231 dev_set_drvdata(dev, ds);
4232
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004233 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004234}
4235
Vivien Didelotfad09c72016-06-21 12:28:20 -04004236static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004237{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004238 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004239}
4240
Vivien Didelot57d32312016-06-20 13:13:58 -04004241static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004242{
4243 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004244 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004245 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004246 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004247 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004248 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004249
Vivien Didelotcaac8542016-06-20 13:14:09 -04004250 compat_info = of_device_get_match_data(dev);
4251 if (!compat_info)
4252 return -EINVAL;
4253
Vivien Didelotfad09c72016-06-21 12:28:20 -04004254 chip = mv88e6xxx_alloc_chip(dev);
4255 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004256 return -ENOMEM;
4257
Vivien Didelotfad09c72016-06-21 12:28:20 -04004258 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004259
Andrew Lunn56995cb2016-12-03 04:35:19 +01004260 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4261 if (err)
4262 return err;
4263
Vivien Didelotfad09c72016-06-21 12:28:20 -04004264 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004265 if (err)
4266 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004267
Andrew Lunnb4308f02016-11-21 23:26:55 +01004268 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4269 if (IS_ERR(chip->reset))
4270 return PTR_ERR(chip->reset);
4271
Vivien Didelotfad09c72016-06-21 12:28:20 -04004272 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004273 if (err)
4274 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004275
Vivien Didelote57e5e72016-08-15 17:19:00 -04004276 mv88e6xxx_phy_init(chip);
4277
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004278 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004279 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004280 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004281
Andrew Lunndc30c352016-10-16 19:56:49 +02004282 mutex_lock(&chip->reg_lock);
4283 err = mv88e6xxx_switch_reset(chip);
4284 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004285 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004286 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004287
Andrew Lunndc30c352016-10-16 19:56:49 +02004288 chip->irq = of_irq_get(np, 0);
4289 if (chip->irq == -EPROBE_DEFER) {
4290 err = chip->irq;
4291 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004292 }
4293
Andrew Lunndc30c352016-10-16 19:56:49 +02004294 if (chip->irq > 0) {
4295 /* Has to be performed before the MDIO bus is created,
4296 * because the PHYs will link there interrupts to these
4297 * interrupt controllers
4298 */
4299 mutex_lock(&chip->reg_lock);
4300 err = mv88e6xxx_g1_irq_setup(chip);
4301 mutex_unlock(&chip->reg_lock);
4302
4303 if (err)
4304 goto out;
4305
4306 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4307 err = mv88e6xxx_g2_irq_setup(chip);
4308 if (err)
4309 goto out_g1_irq;
4310 }
4311 }
4312
Andrew Lunna3c53be52017-01-24 14:53:50 +01004313 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004314 if (err)
4315 goto out_g2_irq;
4316
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004317 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004318 if (err)
4319 goto out_mdio;
4320
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004321 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004322
4323out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004324 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004325out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004326 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004327 mv88e6xxx_g2_irq_free(chip);
4328out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004329 if (chip->irq > 0) {
4330 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004331 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004332 mutex_unlock(&chip->reg_lock);
4333 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004334out:
4335 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004336}
4337
4338static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4339{
4340 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004341 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004342
Andrew Lunn930188c2016-08-22 16:01:03 +02004343 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004344 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004345 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004346
Andrew Lunn467126442016-11-20 20:14:15 +01004347 if (chip->irq > 0) {
4348 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4349 mv88e6xxx_g2_irq_free(chip);
4350 mv88e6xxx_g1_irq_free(chip);
4351 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004352}
4353
4354static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004355 {
4356 .compatible = "marvell,mv88e6085",
4357 .data = &mv88e6xxx_table[MV88E6085],
4358 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004359 {
4360 .compatible = "marvell,mv88e6190",
4361 .data = &mv88e6xxx_table[MV88E6190],
4362 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004363 { /* sentinel */ },
4364};
4365
4366MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4367
4368static struct mdio_driver mv88e6xxx_driver = {
4369 .probe = mv88e6xxx_probe,
4370 .remove = mv88e6xxx_remove,
4371 .mdiodrv.driver = {
4372 .name = "mv88e6085",
4373 .of_match_table = mv88e6xxx_of_match,
4374 },
4375};
4376
Ben Hutchings98e67302011-11-25 14:36:19 +00004377static int __init mv88e6xxx_init(void)
4378{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004379 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004380 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004381}
4382module_init(mv88e6xxx_init);
4383
4384static void __exit mv88e6xxx_cleanup(void)
4385{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004386 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004387 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004388}
4389module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004390
4391MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4392MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4393MODULE_LICENSE("GPL");