blob: 8b8c3cb167c15e041749909043143a4c07e065f8 [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04002 * Marvell 88e6xxx Ethernet switch single-chip support
3 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 * Copyright (c) 2008 Marvell Semiconductor
5 *
Vivien Didelotb8fee952015-08-13 12:52:19 -04006 * Copyright (c) 2015 CMC Electronics, Inc.
7 * Added support for VLAN Table Unit operations
8 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02009 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
10 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
Barry Grussling19b2f972013-01-08 16:05:54 +000017#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070018#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020019#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070020#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020021#include <linux/interrupt.h>
22#include <linux/irq.h>
23#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000024#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000025#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020026#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000027#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040028#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020029#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020030#include <linux/of_mdio.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000031#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010032#include <linux/gpio/consumer.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000033#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000034#include <net/dsa.h>
Vivien Didelot1f36faf2015-10-08 11:35:13 -040035#include <net/switchdev.h>
Vivien Didelotec561272016-09-02 14:45:33 -040036
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000037#include "mv88e6xxx.h"
Vivien Didelota935c052016-09-29 12:21:53 -040038#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040039#include "global2.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010040#include "port.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000041
Vivien Didelotfad09c72016-06-21 12:28:20 -040042static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040043{
Vivien Didelotfad09c72016-06-21 12:28:20 -040044 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
45 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040046 dump_stack();
47 }
48}
49
Vivien Didelot914b32f2016-06-20 13:14:11 -040050/* The switch ADDR[4:1] configuration pins define the chip SMI device address
51 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
52 *
53 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
54 * is the only device connected to the SMI master. In this mode it responds to
55 * all 32 possible SMI addresses, and thus maps directly the internal devices.
56 *
57 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
58 * multiple devices to share the SMI interface. In this mode it responds to only
59 * 2 registers, used to indirectly access the internal SMI devices.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000060 */
Vivien Didelot914b32f2016-06-20 13:14:11 -040061
Vivien Didelotfad09c72016-06-21 12:28:20 -040062static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040063 int addr, int reg, u16 *val)
64{
Vivien Didelotfad09c72016-06-21 12:28:20 -040065 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040066 return -EOPNOTSUPP;
67
Vivien Didelotfad09c72016-06-21 12:28:20 -040068 return chip->smi_ops->read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040069}
70
Vivien Didelotfad09c72016-06-21 12:28:20 -040071static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040072 int addr, int reg, u16 val)
73{
Vivien Didelotfad09c72016-06-21 12:28:20 -040074 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040075 return -EOPNOTSUPP;
76
Vivien Didelotfad09c72016-06-21 12:28:20 -040077 return chip->smi_ops->write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040078}
79
Vivien Didelotfad09c72016-06-21 12:28:20 -040080static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040081 int addr, int reg, u16 *val)
82{
83 int ret;
84
Vivien Didelotfad09c72016-06-21 12:28:20 -040085 ret = mdiobus_read_nested(chip->bus, addr, reg);
Vivien Didelot914b32f2016-06-20 13:14:11 -040086 if (ret < 0)
87 return ret;
88
89 *val = ret & 0xffff;
90
91 return 0;
92}
93
Vivien Didelotfad09c72016-06-21 12:28:20 -040094static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040095 int addr, int reg, u16 val)
96{
97 int ret;
98
Vivien Didelotfad09c72016-06-21 12:28:20 -040099 ret = mdiobus_write_nested(chip->bus, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400100 if (ret < 0)
101 return ret;
102
103 return 0;
104}
105
Vivien Didelotc08026a2016-09-29 12:21:59 -0400106static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400107 .read = mv88e6xxx_smi_single_chip_read,
108 .write = mv88e6xxx_smi_single_chip_write,
109};
110
Vivien Didelotfad09c72016-06-21 12:28:20 -0400111static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000112{
113 int ret;
114 int i;
115
116 for (i = 0; i < 16; i++) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400117 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000118 if (ret < 0)
119 return ret;
120
Andrew Lunncca8b132015-04-02 04:06:39 +0200121 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000122 return 0;
123 }
124
125 return -ETIMEDOUT;
126}
127
Vivien Didelotfad09c72016-06-21 12:28:20 -0400128static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400129 int addr, int reg, u16 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000130{
131 int ret;
132
Barry Grussling3675c8d2013-01-08 16:05:53 +0000133 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400134 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000135 if (ret < 0)
136 return ret;
137
Barry Grussling3675c8d2013-01-08 16:05:53 +0000138 /* Transmit the read command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400139 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Neil Armstrong6e899e62015-10-22 10:37:53 +0200140 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000141 if (ret < 0)
142 return ret;
143
Barry Grussling3675c8d2013-01-08 16:05:53 +0000144 /* Wait for the read command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400145 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000146 if (ret < 0)
147 return ret;
148
Barry Grussling3675c8d2013-01-08 16:05:53 +0000149 /* Read the data. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400150 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000151 if (ret < 0)
152 return ret;
153
Vivien Didelot914b32f2016-06-20 13:14:11 -0400154 *val = ret & 0xffff;
155
156 return 0;
157}
158
Vivien Didelotfad09c72016-06-21 12:28:20 -0400159static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400160 int addr, int reg, u16 val)
161{
162 int ret;
163
164 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400165 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400166 if (ret < 0)
167 return ret;
168
169 /* Transmit the data to write. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400170 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400171 if (ret < 0)
172 return ret;
173
174 /* Transmit the write command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400175 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400176 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
177 if (ret < 0)
178 return ret;
179
180 /* Wait for the write command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400181 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400182 if (ret < 0)
183 return ret;
184
185 return 0;
186}
187
Vivien Didelotc08026a2016-09-29 12:21:59 -0400188static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400189 .read = mv88e6xxx_smi_multi_chip_read,
190 .write = mv88e6xxx_smi_multi_chip_write,
191};
192
Vivien Didelotec561272016-09-02 14:45:33 -0400193int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400194{
195 int err;
196
Vivien Didelotfad09c72016-06-21 12:28:20 -0400197 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400198
Vivien Didelotfad09c72016-06-21 12:28:20 -0400199 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400200 if (err)
201 return err;
202
Vivien Didelotfad09c72016-06-21 12:28:20 -0400203 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400204 addr, reg, *val);
205
206 return 0;
207}
208
Vivien Didelotec561272016-09-02 14:45:33 -0400209int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400210{
211 int err;
212
Vivien Didelotfad09c72016-06-21 12:28:20 -0400213 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400214
Vivien Didelotfad09c72016-06-21 12:28:20 -0400215 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400216 if (err)
217 return err;
218
Vivien Didelotfad09c72016-06-21 12:28:20 -0400219 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400220 addr, reg, val);
221
222 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000223}
224
Andrew Lunnee26a222017-01-24 14:53:48 +0100225static int mv88e6165_phy_read(struct mv88e6xxx_chip *chip,
226 struct mii_bus *bus,
227 int addr, int reg, u16 *val)
Andrew Lunnefb3e742017-01-24 14:53:47 +0100228{
229 return mv88e6xxx_read(chip, addr, reg, val);
230}
231
Andrew Lunnee26a222017-01-24 14:53:48 +0100232static int mv88e6165_phy_write(struct mv88e6xxx_chip *chip,
233 struct mii_bus *bus,
234 int addr, int reg, u16 val)
Andrew Lunnefb3e742017-01-24 14:53:47 +0100235{
236 return mv88e6xxx_write(chip, addr, reg, val);
237}
238
Andrew Lunna3c53be52017-01-24 14:53:50 +0100239static struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
240{
241 struct mv88e6xxx_mdio_bus *mdio_bus;
242
243 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
244 list);
245 if (!mdio_bus)
246 return NULL;
247
248 return mdio_bus->bus;
249}
250
Vivien Didelote57e5e72016-08-15 17:19:00 -0400251static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
252 int reg, u16 *val)
253{
254 int addr = phy; /* PHY devices addresses start at 0x0 */
Andrew Lunna3c53be52017-01-24 14:53:50 +0100255 struct mii_bus *bus;
Vivien Didelote57e5e72016-08-15 17:19:00 -0400256
Andrew Lunna3c53be52017-01-24 14:53:50 +0100257 bus = mv88e6xxx_default_mdio_bus(chip);
258 if (!bus)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400259 return -EOPNOTSUPP;
260
Andrew Lunna3c53be52017-01-24 14:53:50 +0100261 if (!chip->info->ops->phy_read)
Andrew Lunnee26a222017-01-24 14:53:48 +0100262 return -EOPNOTSUPP;
263
264 return chip->info->ops->phy_read(chip, bus, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400265}
266
267static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
268 int reg, u16 val)
269{
270 int addr = phy; /* PHY devices addresses start at 0x0 */
Andrew Lunna3c53be52017-01-24 14:53:50 +0100271 struct mii_bus *bus;
Vivien Didelote57e5e72016-08-15 17:19:00 -0400272
Andrew Lunna3c53be52017-01-24 14:53:50 +0100273 bus = mv88e6xxx_default_mdio_bus(chip);
274 if (!bus)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400275 return -EOPNOTSUPP;
276
Andrew Lunna3c53be52017-01-24 14:53:50 +0100277 if (!chip->info->ops->phy_write)
Andrew Lunnee26a222017-01-24 14:53:48 +0100278 return -EOPNOTSUPP;
279
280 return chip->info->ops->phy_write(chip, bus, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400281}
282
Vivien Didelot09cb7df2016-08-15 17:19:01 -0400283static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
284{
285 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_PHY_PAGE))
286 return -EOPNOTSUPP;
287
288 return mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
289}
290
291static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip *chip, int phy)
292{
293 int err;
294
295 /* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
296 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, PHY_PAGE_COPPER);
297 if (unlikely(err)) {
298 dev_err(chip->dev, "failed to restore PHY %d page Copper (%d)\n",
299 phy, err);
300 }
301}
302
303static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy,
304 u8 page, int reg, u16 *val)
305{
306 int err;
307
308 /* There is no paging for registers 22 */
309 if (reg == PHY_PAGE)
310 return -EINVAL;
311
312 err = mv88e6xxx_phy_page_get(chip, phy, page);
313 if (!err) {
314 err = mv88e6xxx_phy_read(chip, phy, reg, val);
315 mv88e6xxx_phy_page_put(chip, phy);
316 }
317
318 return err;
319}
320
321static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy,
322 u8 page, int reg, u16 val)
323{
324 int err;
325
326 /* There is no paging for registers 22 */
327 if (reg == PHY_PAGE)
328 return -EINVAL;
329
330 err = mv88e6xxx_phy_page_get(chip, phy, page);
331 if (!err) {
332 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
333 mv88e6xxx_phy_page_put(chip, phy);
334 }
335
336 return err;
337}
338
339static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
340{
341 return mv88e6xxx_phy_page_read(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
342 reg, val);
343}
344
345static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
346{
347 return mv88e6xxx_phy_page_write(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
348 reg, val);
349}
350
Andrew Lunndc30c352016-10-16 19:56:49 +0200351static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
352{
353 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
354 unsigned int n = d->hwirq;
355
356 chip->g1_irq.masked |= (1 << n);
357}
358
359static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
360{
361 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
362 unsigned int n = d->hwirq;
363
364 chip->g1_irq.masked &= ~(1 << n);
365}
366
367static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
368{
369 struct mv88e6xxx_chip *chip = dev_id;
370 unsigned int nhandled = 0;
371 unsigned int sub_irq;
372 unsigned int n;
373 u16 reg;
374 int err;
375
376 mutex_lock(&chip->reg_lock);
377 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
378 mutex_unlock(&chip->reg_lock);
379
380 if (err)
381 goto out;
382
383 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
384 if (reg & (1 << n)) {
385 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
386 handle_nested_irq(sub_irq);
387 ++nhandled;
388 }
389 }
390out:
391 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
392}
393
394static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
395{
396 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
397
398 mutex_lock(&chip->reg_lock);
399}
400
401static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
402{
403 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
404 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
405 u16 reg;
406 int err;
407
408 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
409 if (err)
410 goto out;
411
412 reg &= ~mask;
413 reg |= (~chip->g1_irq.masked & mask);
414
415 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
416 if (err)
417 goto out;
418
419out:
420 mutex_unlock(&chip->reg_lock);
421}
422
423static struct irq_chip mv88e6xxx_g1_irq_chip = {
424 .name = "mv88e6xxx-g1",
425 .irq_mask = mv88e6xxx_g1_irq_mask,
426 .irq_unmask = mv88e6xxx_g1_irq_unmask,
427 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
428 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
429};
430
431static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
432 unsigned int irq,
433 irq_hw_number_t hwirq)
434{
435 struct mv88e6xxx_chip *chip = d->host_data;
436
437 irq_set_chip_data(irq, d->host_data);
438 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
439 irq_set_noprobe(irq);
440
441 return 0;
442}
443
444static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
445 .map = mv88e6xxx_g1_irq_domain_map,
446 .xlate = irq_domain_xlate_twocell,
447};
448
449static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
450{
451 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100452 u16 mask;
453
454 mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
455 mask |= GENMASK(chip->g1_irq.nirqs, 0);
456 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
457
458 free_irq(chip->irq, chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200459
Andreas Färber5edef2f2016-11-27 23:26:28 +0100460 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100461 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200462 irq_dispose_mapping(virq);
463 }
464
Andrew Lunna3db3d32016-11-20 20:14:14 +0100465 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200466}
467
468static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
469{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100470 int err, irq, virq;
471 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200472
473 chip->g1_irq.nirqs = chip->info->g1_irqs;
474 chip->g1_irq.domain = irq_domain_add_simple(
475 NULL, chip->g1_irq.nirqs, 0,
476 &mv88e6xxx_g1_irq_domain_ops, chip);
477 if (!chip->g1_irq.domain)
478 return -ENOMEM;
479
480 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
481 irq_create_mapping(chip->g1_irq.domain, irq);
482
483 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
484 chip->g1_irq.masked = ~0;
485
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100486 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200487 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100488 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200489
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100490 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200491
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100492 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200493 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100494 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200495
496 /* Reading the interrupt status clears (most of) them */
497 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
498 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100499 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200500
501 err = request_threaded_irq(chip->irq, NULL,
502 mv88e6xxx_g1_irq_thread_fn,
503 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
504 dev_name(chip->dev), chip);
505 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100506 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200507
508 return 0;
509
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100510out_disable:
511 mask |= GENMASK(chip->g1_irq.nirqs, 0);
512 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
513
514out_mapping:
515 for (irq = 0; irq < 16; irq++) {
516 virq = irq_find_mapping(chip->g1_irq.domain, irq);
517 irq_dispose_mapping(virq);
518 }
519
520 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200521
522 return err;
523}
524
Vivien Didelotec561272016-09-02 14:45:33 -0400525int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400526{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200527 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400528
Andrew Lunn6441e6692016-08-19 00:01:55 +0200529 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400530 u16 val;
531 int err;
532
533 err = mv88e6xxx_read(chip, addr, reg, &val);
534 if (err)
535 return err;
536
537 if (!(val & mask))
538 return 0;
539
540 usleep_range(1000, 2000);
541 }
542
Andrew Lunn30853552016-08-19 00:01:57 +0200543 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400544 return -ETIMEDOUT;
545}
546
Vivien Didelotf22ab642016-07-18 20:45:31 -0400547/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400548int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400549{
550 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200551 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400552
553 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200554 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
555 if (err)
556 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400557
558 /* Set the Update bit to trigger a write operation */
559 val = BIT(15) | update;
560
561 return mv88e6xxx_write(chip, addr, reg, val);
562}
563
Vivien Didelota935c052016-09-29 12:21:53 -0400564static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000565{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500566 if (!chip->info->ops->ppu_disable)
567 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000568
Vivien Didelota199d8b2016-12-05 17:30:28 -0500569 return chip->info->ops->ppu_disable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000570}
571
Vivien Didelotfad09c72016-06-21 12:28:20 -0400572static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000573{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500574 if (!chip->info->ops->ppu_enable)
575 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000576
Vivien Didelota199d8b2016-12-05 17:30:28 -0500577 return chip->info->ops->ppu_enable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000578}
579
580static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
581{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400582 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000583
Vivien Didelotfad09c72016-06-21 12:28:20 -0400584 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200585
Vivien Didelotfad09c72016-06-21 12:28:20 -0400586 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200587
Vivien Didelotfad09c72016-06-21 12:28:20 -0400588 if (mutex_trylock(&chip->ppu_mutex)) {
589 if (mv88e6xxx_ppu_enable(chip) == 0)
590 chip->ppu_disabled = 0;
591 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000592 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200593
Vivien Didelotfad09c72016-06-21 12:28:20 -0400594 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000595}
596
597static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
598{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400599 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000600
Vivien Didelotfad09c72016-06-21 12:28:20 -0400601 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000602}
603
Vivien Didelotfad09c72016-06-21 12:28:20 -0400604static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000605{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000606 int ret;
607
Vivien Didelotfad09c72016-06-21 12:28:20 -0400608 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000609
Barry Grussling3675c8d2013-01-08 16:05:53 +0000610 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000611 * we can access the PHY registers. If it was already
612 * disabled, cancel the timer that is going to re-enable
613 * it.
614 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400615 if (!chip->ppu_disabled) {
616 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000617 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400618 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000619 return ret;
620 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400621 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000622 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400623 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000624 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000625 }
626
627 return ret;
628}
629
Vivien Didelotfad09c72016-06-21 12:28:20 -0400630static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000631{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000632 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400633 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
634 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000635}
636
Vivien Didelotfad09c72016-06-21 12:28:20 -0400637static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000638{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400639 mutex_init(&chip->ppu_mutex);
640 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000641 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
642 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000643}
644
Andrew Lunn930188c2016-08-22 16:01:03 +0200645static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
646{
647 del_timer_sync(&chip->ppu_timer);
648}
649
Andrew Lunnee26a222017-01-24 14:53:48 +0100650static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip,
651 struct mii_bus *bus,
652 int addr, int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000653{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400654 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000655
Vivien Didelote57e5e72016-08-15 17:19:00 -0400656 err = mv88e6xxx_ppu_access_get(chip);
657 if (!err) {
658 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400659 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000660 }
661
Vivien Didelote57e5e72016-08-15 17:19:00 -0400662 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000663}
664
Andrew Lunnee26a222017-01-24 14:53:48 +0100665static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip,
666 struct mii_bus *bus,
667 int addr, int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000668{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400669 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000670
Vivien Didelote57e5e72016-08-15 17:19:00 -0400671 err = mv88e6xxx_ppu_access_get(chip);
672 if (!err) {
673 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400674 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000675 }
676
Vivien Didelote57e5e72016-08-15 17:19:00 -0400677 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000678}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000679
Vivien Didelotfad09c72016-06-21 12:28:20 -0400680static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200681{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400682 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200683}
684
Vivien Didelotfad09c72016-06-21 12:28:20 -0400685static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200686{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400687 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200688}
689
Vivien Didelotfad09c72016-06-21 12:28:20 -0400690static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700691{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400692 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700693}
694
Gregory CLEMENTa75961d2017-01-30 20:29:34 +0100695static bool mv88e6xxx_6341_family(struct mv88e6xxx_chip *chip)
696{
697 return chip->info->family == MV88E6XXX_FAMILY_6341;
698}
699
Vivien Didelotfad09c72016-06-21 12:28:20 -0400700static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200701{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400702 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200703}
704
Vivien Didelotfad09c72016-06-21 12:28:20 -0400705static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200706{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400707 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200708}
709
Vivien Didelotd78343d2016-11-04 03:23:36 +0100710static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
711 int link, int speed, int duplex,
712 phy_interface_t mode)
713{
714 int err;
715
716 if (!chip->info->ops->port_set_link)
717 return 0;
718
719 /* Port's MAC control must not be changed unless the link is down */
720 err = chip->info->ops->port_set_link(chip, port, 0);
721 if (err)
722 return err;
723
724 if (chip->info->ops->port_set_speed) {
725 err = chip->info->ops->port_set_speed(chip, port, speed);
726 if (err && err != -EOPNOTSUPP)
727 goto restore_link;
728 }
729
730 if (chip->info->ops->port_set_duplex) {
731 err = chip->info->ops->port_set_duplex(chip, port, duplex);
732 if (err && err != -EOPNOTSUPP)
733 goto restore_link;
734 }
735
736 if (chip->info->ops->port_set_rgmii_delay) {
737 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
738 if (err && err != -EOPNOTSUPP)
739 goto restore_link;
740 }
741
Andrew Lunnf39908d2017-02-04 20:02:50 +0100742 if (chip->info->ops->port_set_cmode) {
743 err = chip->info->ops->port_set_cmode(chip, port, mode);
744 if (err && err != -EOPNOTSUPP)
745 goto restore_link;
746 }
747
Vivien Didelotd78343d2016-11-04 03:23:36 +0100748 err = 0;
749restore_link:
750 if (chip->info->ops->port_set_link(chip, port, link))
751 netdev_err(chip->ds->ports[port].netdev,
752 "failed to restore MAC's link\n");
753
754 return err;
755}
756
Andrew Lunndea87022015-08-31 15:56:47 +0200757/* We expect the switch to perform auto negotiation if there is a real
758 * phy. However, in the case of a fixed link phy, we force the port
759 * settings from the fixed link settings.
760 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400761static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
762 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200763{
Vivien Didelot04bed142016-08-31 18:06:13 -0400764 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200765 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200766
767 if (!phy_is_pseudo_fixed_link(phydev))
768 return;
769
Vivien Didelotfad09c72016-06-21 12:28:20 -0400770 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100771 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
772 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400773 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100774
775 if (err && err != -EOPNOTSUPP)
776 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200777}
778
Andrew Lunna605a0f2016-11-21 23:26:58 +0100779static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000780{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100781 if (!chip->info->ops->stats_snapshot)
782 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000783
Andrew Lunna605a0f2016-11-21 23:26:58 +0100784 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000785}
786
Andrew Lunne413e7e2015-04-02 04:06:38 +0200787static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100788 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
789 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
790 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
791 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
792 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
793 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
794 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
795 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
796 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
797 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
798 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
799 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
800 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
801 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
802 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
803 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
804 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
805 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
806 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
807 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
808 { "single", 4, 0x14, STATS_TYPE_BANK0, },
809 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
810 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
811 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
812 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
813 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
814 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
815 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
816 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
817 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
818 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
819 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
820 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
821 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
822 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
823 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
824 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
825 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
826 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
827 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
828 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
829 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
830 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
831 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
832 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
833 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
834 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
835 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
836 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
837 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
838 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
839 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
840 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
841 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
842 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
843 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
844 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
845 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
846 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200847};
848
Vivien Didelotfad09c72016-06-21 12:28:20 -0400849static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100850 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100851 int port, u16 bank1_select,
852 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200853{
Andrew Lunn80c46272015-06-20 18:42:30 +0200854 u32 low;
855 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100856 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200857 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200858 u64 value;
859
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100860 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100861 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200862 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
863 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200864 return UINT64_MAX;
865
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200866 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200867 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200868 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
869 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200870 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200871 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200872 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100873 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100874 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100875 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100876 /* fall through */
877 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100878 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100879 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200880 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100881 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200882 }
883 value = (((u64)high) << 16) | low;
884 return value;
885}
886
Andrew Lunndfafe442016-11-21 23:27:02 +0100887static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
888 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100889{
890 struct mv88e6xxx_hw_stat *stat;
891 int i, j;
892
893 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
894 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100895 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100896 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
897 ETH_GSTRING_LEN);
898 j++;
899 }
900 }
901}
902
Andrew Lunndfafe442016-11-21 23:27:02 +0100903static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
904 uint8_t *data)
905{
906 mv88e6xxx_stats_get_strings(chip, data,
907 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
908}
909
910static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
911 uint8_t *data)
912{
913 mv88e6xxx_stats_get_strings(chip, data,
914 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
915}
916
917static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
918 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100919{
Vivien Didelot04bed142016-08-31 18:06:13 -0400920 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100921
922 if (chip->info->ops->stats_get_strings)
923 chip->info->ops->stats_get_strings(chip, data);
924}
925
926static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
927 int types)
928{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100929 struct mv88e6xxx_hw_stat *stat;
930 int i, j;
931
932 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
933 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100934 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100935 j++;
936 }
937 return j;
938}
939
Andrew Lunndfafe442016-11-21 23:27:02 +0100940static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
941{
942 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
943 STATS_TYPE_PORT);
944}
945
946static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
947{
948 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
949 STATS_TYPE_BANK1);
950}
951
952static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
953{
954 struct mv88e6xxx_chip *chip = ds->priv;
955
956 if (chip->info->ops->stats_get_sset_count)
957 return chip->info->ops->stats_get_sset_count(chip);
958
959 return 0;
960}
961
Andrew Lunn052f9472016-11-21 23:27:03 +0100962static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100963 uint64_t *data, int types,
964 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100965{
966 struct mv88e6xxx_hw_stat *stat;
967 int i, j;
968
969 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
970 stat = &mv88e6xxx_hw_stats[i];
971 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100972 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
973 bank1_select,
974 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100975 j++;
976 }
977 }
978}
979
980static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
981 uint64_t *data)
982{
983 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100984 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
985 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100986}
987
988static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
989 uint64_t *data)
990{
991 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100992 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
993 GLOBAL_STATS_OP_BANK_1_BIT_9,
994 GLOBAL_STATS_OP_HIST_RX_TX);
995}
996
997static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
998 uint64_t *data)
999{
1000 return mv88e6xxx_stats_get_stats(chip, port, data,
1001 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1002 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001003}
1004
1005static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1006 uint64_t *data)
1007{
1008 if (chip->info->ops->stats_get_stats)
1009 chip->info->ops->stats_get_stats(chip, port, data);
1010}
1011
Vivien Didelotf81ec902016-05-09 13:22:58 -04001012static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1013 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001014{
Vivien Didelot04bed142016-08-31 18:06:13 -04001015 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001016 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001017
Vivien Didelotfad09c72016-06-21 12:28:20 -04001018 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001019
Andrew Lunna605a0f2016-11-21 23:26:58 +01001020 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001021 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001022 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001023 return;
1024 }
Andrew Lunn052f9472016-11-21 23:27:03 +01001025
1026 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001027
Vivien Didelotfad09c72016-06-21 12:28:20 -04001028 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001029}
Ben Hutchings98e67302011-11-25 14:36:19 +00001030
Andrew Lunnde2273872016-11-21 23:27:01 +01001031static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1032{
1033 if (chip->info->ops->stats_set_histogram)
1034 return chip->info->ops->stats_set_histogram(chip);
1035
1036 return 0;
1037}
1038
Vivien Didelotf81ec902016-05-09 13:22:58 -04001039static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001040{
1041 return 32 * sizeof(u16);
1042}
1043
Vivien Didelotf81ec902016-05-09 13:22:58 -04001044static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1045 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001046{
Vivien Didelot04bed142016-08-31 18:06:13 -04001047 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001048 int err;
1049 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001050 u16 *p = _p;
1051 int i;
1052
1053 regs->version = 0;
1054
1055 memset(p, 0xff, 32 * sizeof(u16));
1056
Vivien Didelotfad09c72016-06-21 12:28:20 -04001057 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001058
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001059 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001060
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001061 err = mv88e6xxx_port_read(chip, port, i, &reg);
1062 if (!err)
1063 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001064 }
Vivien Didelot23062512016-05-09 13:22:45 -04001065
Vivien Didelotfad09c72016-06-21 12:28:20 -04001066 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001067}
1068
Vivien Didelotfad09c72016-06-21 12:28:20 -04001069static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001070{
Vivien Didelota935c052016-09-29 12:21:53 -04001071 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001072}
1073
Vivien Didelotf81ec902016-05-09 13:22:58 -04001074static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1075 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001076{
Vivien Didelot04bed142016-08-31 18:06:13 -04001077 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001078 u16 reg;
1079 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001080
Vivien Didelotfad09c72016-06-21 12:28:20 -04001081 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001082 return -EOPNOTSUPP;
1083
Vivien Didelotfad09c72016-06-21 12:28:20 -04001084 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001085
Vivien Didelot9c938292016-08-15 17:19:02 -04001086 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1087 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001088 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001089
1090 e->eee_enabled = !!(reg & 0x0200);
1091 e->tx_lpi_enabled = !!(reg & 0x0100);
1092
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001093 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001094 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001095 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001096
Andrew Lunncca8b132015-04-02 04:06:39 +02001097 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001098out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001099 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001100
1101 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001102}
1103
Vivien Didelotf81ec902016-05-09 13:22:58 -04001104static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1105 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001106{
Vivien Didelot04bed142016-08-31 18:06:13 -04001107 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001108 u16 reg;
1109 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001110
Vivien Didelotfad09c72016-06-21 12:28:20 -04001111 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001112 return -EOPNOTSUPP;
1113
Vivien Didelotfad09c72016-06-21 12:28:20 -04001114 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001115
Vivien Didelot9c938292016-08-15 17:19:02 -04001116 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1117 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001118 goto out;
1119
Vivien Didelot9c938292016-08-15 17:19:02 -04001120 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001121 if (e->eee_enabled)
1122 reg |= 0x0200;
1123 if (e->tx_lpi_enabled)
1124 reg |= 0x0100;
1125
Vivien Didelot9c938292016-08-15 17:19:02 -04001126 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001127out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001128 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001129
Vivien Didelot9c938292016-08-15 17:19:02 -04001130 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001131}
1132
Vivien Didelotfad09c72016-06-21 12:28:20 -04001133static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001134{
Vivien Didelota935c052016-09-29 12:21:53 -04001135 u16 val;
1136 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001137
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001138 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001139 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1140 if (err)
1141 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001142 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001143 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001144 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1145 if (err)
1146 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001147
Vivien Didelota935c052016-09-29 12:21:53 -04001148 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1149 (val & 0xfff) | ((fid << 8) & 0xf000));
1150 if (err)
1151 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001152
1153 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1154 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001155 }
1156
Vivien Didelota935c052016-09-29 12:21:53 -04001157 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1158 if (err)
1159 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001160
Vivien Didelotfad09c72016-06-21 12:28:20 -04001161 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001162}
1163
Vivien Didelotfad09c72016-06-21 12:28:20 -04001164static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001165 struct mv88e6xxx_atu_entry *entry)
1166{
1167 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1168
1169 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1170 unsigned int mask, shift;
1171
1172 if (entry->trunk) {
1173 data |= GLOBAL_ATU_DATA_TRUNK;
1174 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1175 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1176 } else {
1177 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1178 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1179 }
1180
1181 data |= (entry->portv_trunkid << shift) & mask;
1182 }
1183
Vivien Didelota935c052016-09-29 12:21:53 -04001184 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001185}
1186
Vivien Didelotfad09c72016-06-21 12:28:20 -04001187static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001188 struct mv88e6xxx_atu_entry *entry,
1189 bool static_too)
1190{
1191 int op;
1192 int err;
1193
Vivien Didelotfad09c72016-06-21 12:28:20 -04001194 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001195 if (err)
1196 return err;
1197
Vivien Didelotfad09c72016-06-21 12:28:20 -04001198 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001199 if (err)
1200 return err;
1201
1202 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001203 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1204 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1205 } else {
1206 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1207 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1208 }
1209
Vivien Didelotfad09c72016-06-21 12:28:20 -04001210 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001211}
1212
Vivien Didelotfad09c72016-06-21 12:28:20 -04001213static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001214 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001215{
1216 struct mv88e6xxx_atu_entry entry = {
1217 .trunk = false,
1218 .fid = fid,
1219 };
1220
1221 /* EntryState bits must be 0xF */
1222 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1223
1224 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1225 entry.portv_trunkid = (to_port & 0x0f) << 4;
1226 entry.portv_trunkid |= from_port & 0x0f;
1227
Vivien Didelotfad09c72016-06-21 12:28:20 -04001228 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001229}
1230
Vivien Didelotfad09c72016-06-21 12:28:20 -04001231static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001232 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001233{
1234 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001235 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001236}
1237
Vivien Didelotfad09c72016-06-21 12:28:20 -04001238static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001239{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001240 struct dsa_switch *ds = chip->ds;
Vivien Didelotfae8a252017-01-27 15:29:42 -05001241 struct net_device *bridge = ds->ports[port].bridge_dev;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001242 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001243 int i;
1244
1245 /* allow CPU port or DSA link(s) to send frames to every port */
1246 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001247 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001248 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001249 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001250 /* allow sending frames to every group member */
Vivien Didelotfae8a252017-01-27 15:29:42 -05001251 if (bridge && ds->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001252 output_ports |= BIT(i);
1253
1254 /* allow sending frames to CPU port and DSA link(s) */
1255 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1256 output_ports |= BIT(i);
1257 }
1258 }
1259
1260 /* prevent frames from going back out of the port they came in on */
1261 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001262
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001263 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001264}
1265
Vivien Didelotf81ec902016-05-09 13:22:58 -04001266static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1267 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001268{
Vivien Didelot04bed142016-08-31 18:06:13 -04001269 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001270 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001271 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001272
1273 switch (state) {
1274 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001275 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001276 break;
1277 case BR_STATE_BLOCKING:
1278 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001279 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001280 break;
1281 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001282 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001283 break;
1284 case BR_STATE_FORWARDING:
1285 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001286 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001287 break;
1288 }
1289
Vivien Didelotfad09c72016-06-21 12:28:20 -04001290 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001291 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001292 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001293
1294 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001295 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001296}
1297
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001298static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1299{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001300 int err;
1301
Vivien Didelotdaefc942017-03-11 16:12:54 -05001302 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1303 if (err)
1304 return err;
1305
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001306 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1307 if (err)
1308 return err;
1309
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001310 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1311}
1312
Vivien Didelot749efcb2016-09-22 16:49:24 -04001313static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1314{
1315 struct mv88e6xxx_chip *chip = ds->priv;
1316 int err;
1317
1318 mutex_lock(&chip->reg_lock);
1319 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1320 mutex_unlock(&chip->reg_lock);
1321
1322 if (err)
1323 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1324}
1325
Vivien Didelotfad09c72016-06-21 12:28:20 -04001326static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001327{
Vivien Didelota935c052016-09-29 12:21:53 -04001328 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001329}
1330
Vivien Didelotfad09c72016-06-21 12:28:20 -04001331static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001332{
Vivien Didelota935c052016-09-29 12:21:53 -04001333 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001334
Vivien Didelota935c052016-09-29 12:21:53 -04001335 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1336 if (err)
1337 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001338
Vivien Didelotfad09c72016-06-21 12:28:20 -04001339 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001340}
1341
Vivien Didelotfad09c72016-06-21 12:28:20 -04001342static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001343{
1344 int ret;
1345
Vivien Didelotfad09c72016-06-21 12:28:20 -04001346 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001347 if (ret < 0)
1348 return ret;
1349
Vivien Didelotfad09c72016-06-21 12:28:20 -04001350 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001351}
1352
Vivien Didelotfad09c72016-06-21 12:28:20 -04001353static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001354 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001355 unsigned int nibble_offset)
1356{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001357 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001358 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001359
1360 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001361 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001362
Vivien Didelota935c052016-09-29 12:21:53 -04001363 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1364 if (err)
1365 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001366 }
1367
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001368 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001369 unsigned int shift = (i % 4) * 4 + nibble_offset;
1370 u16 reg = regs[i / 4];
1371
1372 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1373 }
1374
1375 return 0;
1376}
1377
Vivien Didelotfad09c72016-06-21 12:28:20 -04001378static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001379 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001380{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001381 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001382}
1383
Vivien Didelotfad09c72016-06-21 12:28:20 -04001384static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001385 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001386{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001387 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001388}
1389
Vivien Didelotfad09c72016-06-21 12:28:20 -04001390static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001391 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001392 unsigned int nibble_offset)
1393{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001394 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001395 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001396
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001397 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001398 unsigned int shift = (i % 4) * 4 + nibble_offset;
1399 u8 data = entry->data[i];
1400
1401 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1402 }
1403
1404 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001405 u16 reg = regs[i];
1406
1407 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1408 if (err)
1409 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001410 }
1411
1412 return 0;
1413}
1414
Vivien Didelotfad09c72016-06-21 12:28:20 -04001415static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001416 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001417{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001418 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001419}
1420
Vivien Didelotfad09c72016-06-21 12:28:20 -04001421static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001422 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001423{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001424 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001425}
1426
Vivien Didelotfad09c72016-06-21 12:28:20 -04001427static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001428{
Vivien Didelota935c052016-09-29 12:21:53 -04001429 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1430 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001431}
1432
Vivien Didelotfad09c72016-06-21 12:28:20 -04001433static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001434 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001435{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001436 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001437 u16 val;
1438 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001439
Vivien Didelota935c052016-09-29 12:21:53 -04001440 err = _mv88e6xxx_vtu_wait(chip);
1441 if (err)
1442 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001443
Vivien Didelota935c052016-09-29 12:21:53 -04001444 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1445 if (err)
1446 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001447
Vivien Didelota935c052016-09-29 12:21:53 -04001448 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1449 if (err)
1450 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001451
Vivien Didelota935c052016-09-29 12:21:53 -04001452 next.vid = val & GLOBAL_VTU_VID_MASK;
1453 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001454
1455 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001456 err = mv88e6xxx_vtu_data_read(chip, &next);
1457 if (err)
1458 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001459
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001460 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001461 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1462 if (err)
1463 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001464
Vivien Didelota935c052016-09-29 12:21:53 -04001465 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001466 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001467 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1468 * VTU DBNum[3:0] are located in VTU Operation 3:0
1469 */
Vivien Didelota935c052016-09-29 12:21:53 -04001470 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1471 if (err)
1472 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001473
Vivien Didelota935c052016-09-29 12:21:53 -04001474 next.fid = (val & 0xf00) >> 4;
1475 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001476 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001477
Vivien Didelotfad09c72016-06-21 12:28:20 -04001478 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001479 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1480 if (err)
1481 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001482
Vivien Didelota935c052016-09-29 12:21:53 -04001483 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001484 }
1485 }
1486
1487 *entry = next;
1488 return 0;
1489}
1490
Vivien Didelotf81ec902016-05-09 13:22:58 -04001491static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1492 struct switchdev_obj_port_vlan *vlan,
1493 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001494{
Vivien Didelot04bed142016-08-31 18:06:13 -04001495 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001496 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001497 u16 pvid;
1498 int err;
1499
Vivien Didelotfad09c72016-06-21 12:28:20 -04001500 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001501 return -EOPNOTSUPP;
1502
Vivien Didelotfad09c72016-06-21 12:28:20 -04001503 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001504
Vivien Didelot77064f32016-11-04 03:23:30 +01001505 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001506 if (err)
1507 goto unlock;
1508
Vivien Didelotfad09c72016-06-21 12:28:20 -04001509 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001510 if (err)
1511 goto unlock;
1512
1513 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001514 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001515 if (err)
1516 break;
1517
1518 if (!next.valid)
1519 break;
1520
1521 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1522 continue;
1523
1524 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001525 vlan->vid_begin = next.vid;
1526 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001527 vlan->flags = 0;
1528
1529 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1530 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1531
1532 if (next.vid == pvid)
1533 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1534
1535 err = cb(&vlan->obj);
1536 if (err)
1537 break;
1538 } while (next.vid < GLOBAL_VTU_VID_MASK);
1539
1540unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001541 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001542
1543 return err;
1544}
1545
Vivien Didelotfad09c72016-06-21 12:28:20 -04001546static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001547 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001548{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001549 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001550 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001551 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001552
Vivien Didelota935c052016-09-29 12:21:53 -04001553 err = _mv88e6xxx_vtu_wait(chip);
1554 if (err)
1555 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001556
1557 if (!entry->valid)
1558 goto loadpurge;
1559
1560 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001561 err = mv88e6xxx_vtu_data_write(chip, entry);
1562 if (err)
1563 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001564
Vivien Didelotfad09c72016-06-21 12:28:20 -04001565 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001566 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001567 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1568 if (err)
1569 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001570 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001571
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001572 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001573 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001574 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1575 if (err)
1576 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001577 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001578 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1579 * VTU DBNum[3:0] are located in VTU Operation 3:0
1580 */
1581 op |= (entry->fid & 0xf0) << 8;
1582 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001583 }
1584
1585 reg = GLOBAL_VTU_VID_VALID;
1586loadpurge:
1587 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001588 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1589 if (err)
1590 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001591
Vivien Didelotfad09c72016-06-21 12:28:20 -04001592 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001593}
1594
Vivien Didelotfad09c72016-06-21 12:28:20 -04001595static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001596 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001597{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001598 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001599 u16 val;
1600 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001601
Vivien Didelota935c052016-09-29 12:21:53 -04001602 err = _mv88e6xxx_vtu_wait(chip);
1603 if (err)
1604 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001605
Vivien Didelota935c052016-09-29 12:21:53 -04001606 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1607 sid & GLOBAL_VTU_SID_MASK);
1608 if (err)
1609 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001610
Vivien Didelota935c052016-09-29 12:21:53 -04001611 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1612 if (err)
1613 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001614
Vivien Didelota935c052016-09-29 12:21:53 -04001615 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1616 if (err)
1617 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001618
Vivien Didelota935c052016-09-29 12:21:53 -04001619 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001620
Vivien Didelota935c052016-09-29 12:21:53 -04001621 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1622 if (err)
1623 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001624
Vivien Didelota935c052016-09-29 12:21:53 -04001625 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001626
1627 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001628 err = mv88e6xxx_stu_data_read(chip, &next);
1629 if (err)
1630 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001631 }
1632
1633 *entry = next;
1634 return 0;
1635}
1636
Vivien Didelotfad09c72016-06-21 12:28:20 -04001637static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001638 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001639{
1640 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001641 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001642
Vivien Didelota935c052016-09-29 12:21:53 -04001643 err = _mv88e6xxx_vtu_wait(chip);
1644 if (err)
1645 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001646
1647 if (!entry->valid)
1648 goto loadpurge;
1649
1650 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001651 err = mv88e6xxx_stu_data_write(chip, entry);
1652 if (err)
1653 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001654
1655 reg = GLOBAL_VTU_VID_VALID;
1656loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001657 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1658 if (err)
1659 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001660
1661 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001662 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1663 if (err)
1664 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001665
Vivien Didelotfad09c72016-06-21 12:28:20 -04001666 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001667}
1668
Vivien Didelotfad09c72016-06-21 12:28:20 -04001669static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001670{
1671 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001672 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001673 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001674
1675 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1676
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001677 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001678 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001679 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001680 if (err)
1681 return err;
1682
1683 set_bit(*fid, fid_bitmap);
1684 }
1685
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001686 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001687 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001688 if (err)
1689 return err;
1690
1691 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001692 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001693 if (err)
1694 return err;
1695
1696 if (!vlan.valid)
1697 break;
1698
1699 set_bit(vlan.fid, fid_bitmap);
1700 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1701
1702 /* The reset value 0x000 is used to indicate that multiple address
1703 * databases are not needed. Return the next positive available.
1704 */
1705 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001706 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001707 return -ENOSPC;
1708
1709 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001710 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001711}
1712
Vivien Didelotfad09c72016-06-21 12:28:20 -04001713static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001714 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001715{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001716 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001717 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001718 .valid = true,
1719 .vid = vid,
1720 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001721 int i, err;
1722
Vivien Didelotfad09c72016-06-21 12:28:20 -04001723 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001724 if (err)
1725 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001726
Vivien Didelot3d131f02015-11-03 10:52:52 -05001727 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001728 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001729 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1730 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1731 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001732
Vivien Didelotfad09c72016-06-21 12:28:20 -04001733 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01001734 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip) ||
1735 mv88e6xxx_6341_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001736 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001737
1738 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1739 * implemented, only one STU entry is needed to cover all VTU
1740 * entries. Thus, validate the SID 0.
1741 */
1742 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001743 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001744 if (err)
1745 return err;
1746
1747 if (vstp.sid != vlan.sid || !vstp.valid) {
1748 memset(&vstp, 0, sizeof(vstp));
1749 vstp.valid = true;
1750 vstp.sid = vlan.sid;
1751
Vivien Didelotfad09c72016-06-21 12:28:20 -04001752 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001753 if (err)
1754 return err;
1755 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001756 }
1757
1758 *entry = vlan;
1759 return 0;
1760}
1761
Vivien Didelotfad09c72016-06-21 12:28:20 -04001762static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001763 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001764{
1765 int err;
1766
1767 if (!vid)
1768 return -EINVAL;
1769
Vivien Didelotfad09c72016-06-21 12:28:20 -04001770 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001771 if (err)
1772 return err;
1773
Vivien Didelotfad09c72016-06-21 12:28:20 -04001774 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001775 if (err)
1776 return err;
1777
1778 if (entry->vid != vid || !entry->valid) {
1779 if (!creat)
1780 return -EOPNOTSUPP;
1781 /* -ENOENT would've been more appropriate, but switchdev expects
1782 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1783 */
1784
Vivien Didelotfad09c72016-06-21 12:28:20 -04001785 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001786 }
1787
1788 return err;
1789}
1790
Vivien Didelotda9c3592016-02-12 12:09:40 -05001791static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1792 u16 vid_begin, u16 vid_end)
1793{
Vivien Didelot04bed142016-08-31 18:06:13 -04001794 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001795 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001796 int i, err;
1797
1798 if (!vid_begin)
1799 return -EOPNOTSUPP;
1800
Vivien Didelotfad09c72016-06-21 12:28:20 -04001801 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001802
Vivien Didelotfad09c72016-06-21 12:28:20 -04001803 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001804 if (err)
1805 goto unlock;
1806
1807 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001808 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001809 if (err)
1810 goto unlock;
1811
1812 if (!vlan.valid)
1813 break;
1814
1815 if (vlan.vid > vid_end)
1816 break;
1817
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001818 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001819 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1820 continue;
1821
Andrew Lunn66e28092016-12-11 21:07:19 +01001822 if (!ds->ports[port].netdev)
1823 continue;
1824
Vivien Didelotda9c3592016-02-12 12:09:40 -05001825 if (vlan.data[i] ==
1826 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1827 continue;
1828
Vivien Didelotfae8a252017-01-27 15:29:42 -05001829 if (ds->ports[i].bridge_dev ==
1830 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001831 break; /* same bridge, check next VLAN */
1832
Vivien Didelotfae8a252017-01-27 15:29:42 -05001833 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001834 continue;
1835
Andrew Lunnc8b09802016-06-04 21:16:57 +02001836 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001837 "hardware VLAN %d already used by %s\n",
1838 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001839 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001840 err = -EOPNOTSUPP;
1841 goto unlock;
1842 }
1843 } while (vlan.vid < vid_end);
1844
1845unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001846 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001847
1848 return err;
1849}
1850
Vivien Didelotf81ec902016-05-09 13:22:58 -04001851static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1852 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001853{
Vivien Didelot04bed142016-08-31 18:06:13 -04001854 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001855 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001856 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001857 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001858
Vivien Didelotfad09c72016-06-21 12:28:20 -04001859 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001860 return -EOPNOTSUPP;
1861
Vivien Didelotfad09c72016-06-21 12:28:20 -04001862 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001863 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001864 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001865
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001866 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001867}
1868
Vivien Didelot57d32312016-06-20 13:13:58 -04001869static int
1870mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1871 const struct switchdev_obj_port_vlan *vlan,
1872 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001873{
Vivien Didelot04bed142016-08-31 18:06:13 -04001874 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001875 int err;
1876
Vivien Didelotfad09c72016-06-21 12:28:20 -04001877 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001878 return -EOPNOTSUPP;
1879
Vivien Didelotda9c3592016-02-12 12:09:40 -05001880 /* If the requested port doesn't belong to the same bridge as the VLAN
1881 * members, do not support it (yet) and fallback to software VLAN.
1882 */
1883 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1884 vlan->vid_end);
1885 if (err)
1886 return err;
1887
Vivien Didelot76e398a2015-11-01 12:33:55 -05001888 /* We don't need any dynamic resource from the kernel (yet),
1889 * so skip the prepare phase.
1890 */
1891 return 0;
1892}
1893
Vivien Didelotfad09c72016-06-21 12:28:20 -04001894static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001895 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001896{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001897 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001898 int err;
1899
Vivien Didelotfad09c72016-06-21 12:28:20 -04001900 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001901 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001902 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001903
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001904 vlan.data[port] = untagged ?
1905 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1906 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1907
Vivien Didelotfad09c72016-06-21 12:28:20 -04001908 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001909}
1910
Vivien Didelotf81ec902016-05-09 13:22:58 -04001911static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1912 const struct switchdev_obj_port_vlan *vlan,
1913 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001914{
Vivien Didelot04bed142016-08-31 18:06:13 -04001915 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001916 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1917 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1918 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001919
Vivien Didelotfad09c72016-06-21 12:28:20 -04001920 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001921 return;
1922
Vivien Didelotfad09c72016-06-21 12:28:20 -04001923 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001924
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001925 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001926 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001927 netdev_err(ds->ports[port].netdev,
1928 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001929 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001930
Vivien Didelot77064f32016-11-04 03:23:30 +01001931 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001932 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001933 vlan->vid_end);
1934
Vivien Didelotfad09c72016-06-21 12:28:20 -04001935 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001936}
1937
Vivien Didelotfad09c72016-06-21 12:28:20 -04001938static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001939 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001940{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001941 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001942 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001943 int i, err;
1944
Vivien Didelotfad09c72016-06-21 12:28:20 -04001945 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001946 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001947 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001948
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001949 /* Tell switchdev if this VLAN is handled in software */
1950 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001951 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001952
1953 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1954
1955 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001956 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001957 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001958 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001959 continue;
1960
1961 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001962 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001963 break;
1964 }
1965 }
1966
Vivien Didelotfad09c72016-06-21 12:28:20 -04001967 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001968 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001969 return err;
1970
Vivien Didelotfad09c72016-06-21 12:28:20 -04001971 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001972}
1973
Vivien Didelotf81ec902016-05-09 13:22:58 -04001974static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1975 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001976{
Vivien Didelot04bed142016-08-31 18:06:13 -04001977 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001978 u16 pvid, vid;
1979 int err = 0;
1980
Vivien Didelotfad09c72016-06-21 12:28:20 -04001981 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001982 return -EOPNOTSUPP;
1983
Vivien Didelotfad09c72016-06-21 12:28:20 -04001984 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001985
Vivien Didelot77064f32016-11-04 03:23:30 +01001986 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001987 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001988 goto unlock;
1989
Vivien Didelot76e398a2015-11-01 12:33:55 -05001990 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001991 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001992 if (err)
1993 goto unlock;
1994
1995 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001996 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001997 if (err)
1998 goto unlock;
1999 }
2000 }
2001
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002002unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002003 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002004
2005 return err;
2006}
2007
Vivien Didelot83dabd12016-08-31 11:50:04 -04002008static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2009 const unsigned char *addr, u16 vid,
2010 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002011{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002012 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002013 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002014 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002015
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002016 /* Null VLAN ID corresponds to the port private database */
2017 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002018 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002019 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002020 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002021 if (err)
2022 return err;
2023
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002024 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2025 ether_addr_copy(entry.mac, addr);
2026 eth_addr_dec(entry.mac);
2027
2028 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04002029 if (err)
2030 return err;
2031
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002032 /* Initialize a fresh ATU entry if it isn't found */
2033 if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
2034 !ether_addr_equal(entry.mac, addr)) {
2035 memset(&entry, 0, sizeof(entry));
2036 ether_addr_copy(entry.mac, addr);
2037 }
2038
Vivien Didelot88472932016-09-19 19:56:11 -04002039 /* Purge the ATU entry only if no port is using it anymore */
2040 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2041 entry.portv_trunkid &= ~BIT(port);
2042 if (!entry.portv_trunkid)
2043 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2044 } else {
2045 entry.portv_trunkid |= BIT(port);
2046 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002047 }
2048
Vivien Didelot9c13c022017-03-11 16:12:52 -05002049 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002050}
2051
Vivien Didelotf81ec902016-05-09 13:22:58 -04002052static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2053 const struct switchdev_obj_port_fdb *fdb,
2054 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002055{
2056 /* We don't need any dynamic resource from the kernel (yet),
2057 * so skip the prepare phase.
2058 */
2059 return 0;
2060}
2061
Vivien Didelotf81ec902016-05-09 13:22:58 -04002062static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2063 const struct switchdev_obj_port_fdb *fdb,
2064 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002065{
Vivien Didelot04bed142016-08-31 18:06:13 -04002066 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002067
Vivien Didelotfad09c72016-06-21 12:28:20 -04002068 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002069 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2070 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2071 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002072 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002073}
2074
Vivien Didelotf81ec902016-05-09 13:22:58 -04002075static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2076 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002077{
Vivien Didelot04bed142016-08-31 18:06:13 -04002078 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002079 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002080
Vivien Didelotfad09c72016-06-21 12:28:20 -04002081 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002082 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2083 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002084 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002085
Vivien Didelot83dabd12016-08-31 11:50:04 -04002086 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002087}
2088
Vivien Didelot83dabd12016-08-31 11:50:04 -04002089static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2090 u16 fid, u16 vid, int port,
2091 struct switchdev_obj *obj,
2092 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002093{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002094 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002095 int err;
2096
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002097 addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2098 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002099
2100 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002101 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002102 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002103 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002104
2105 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2106 break;
2107
Vivien Didelot83dabd12016-08-31 11:50:04 -04002108 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2109 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002110
Vivien Didelot83dabd12016-08-31 11:50:04 -04002111 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2112 struct switchdev_obj_port_fdb *fdb;
2113
2114 if (!is_unicast_ether_addr(addr.mac))
2115 continue;
2116
2117 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002118 fdb->vid = vid;
2119 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002120 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2121 fdb->ndm_state = NUD_NOARP;
2122 else
2123 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002124 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2125 struct switchdev_obj_port_mdb *mdb;
2126
2127 if (!is_multicast_ether_addr(addr.mac))
2128 continue;
2129
2130 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2131 mdb->vid = vid;
2132 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002133 } else {
2134 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002135 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002136
2137 err = cb(obj);
2138 if (err)
2139 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002140 } while (!is_broadcast_ether_addr(addr.mac));
2141
2142 return err;
2143}
2144
Vivien Didelot83dabd12016-08-31 11:50:04 -04002145static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2146 struct switchdev_obj *obj,
2147 int (*cb)(struct switchdev_obj *obj))
2148{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002149 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002150 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2151 };
2152 u16 fid;
2153 int err;
2154
2155 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002156 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002157 if (err)
2158 return err;
2159
2160 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2161 if (err)
2162 return err;
2163
2164 /* Dump VLANs' Filtering Information Databases */
2165 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2166 if (err)
2167 return err;
2168
2169 do {
2170 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2171 if (err)
2172 return err;
2173
2174 if (!vlan.valid)
2175 break;
2176
2177 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2178 obj, cb);
2179 if (err)
2180 return err;
2181 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2182
2183 return err;
2184}
2185
Vivien Didelotf81ec902016-05-09 13:22:58 -04002186static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2187 struct switchdev_obj_port_fdb *fdb,
2188 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002189{
Vivien Didelot04bed142016-08-31 18:06:13 -04002190 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002191 int err;
2192
Vivien Didelotfad09c72016-06-21 12:28:20 -04002193 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002194 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002195 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002196
2197 return err;
2198}
2199
Vivien Didelotf81ec902016-05-09 13:22:58 -04002200static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002201 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002202{
Vivien Didelot04bed142016-08-31 18:06:13 -04002203 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002204 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002205
Vivien Didelotfad09c72016-06-21 12:28:20 -04002206 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002207
Vivien Didelotfae8a252017-01-27 15:29:42 -05002208 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002209 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfae8a252017-01-27 15:29:42 -05002210 if (ds->ports[i].bridge_dev == br) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002211 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002212 if (err)
2213 break;
2214 }
2215 }
2216
Vivien Didelotfad09c72016-06-21 12:28:20 -04002217 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002218
Vivien Didelot466dfa02016-02-26 13:16:05 -05002219 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002220}
2221
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002222static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2223 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002224{
Vivien Didelot04bed142016-08-31 18:06:13 -04002225 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002226 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002227
Vivien Didelotfad09c72016-06-21 12:28:20 -04002228 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002229
Vivien Didelotfae8a252017-01-27 15:29:42 -05002230 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002231 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfae8a252017-01-27 15:29:42 -05002232 if (i == port || ds->ports[i].bridge_dev == br)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002233 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002234 netdev_warn(ds->ports[i].netdev,
2235 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002236
Vivien Didelotfad09c72016-06-21 12:28:20 -04002237 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002238}
2239
Vivien Didelot17e708b2016-12-05 17:30:27 -05002240static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2241{
2242 if (chip->info->ops->reset)
2243 return chip->info->ops->reset(chip);
2244
2245 return 0;
2246}
2247
Vivien Didelot309eca62016-12-05 17:30:26 -05002248static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2249{
2250 struct gpio_desc *gpiod = chip->reset;
2251
2252 /* If there is a GPIO connected to the reset pin, toggle it */
2253 if (gpiod) {
2254 gpiod_set_value_cansleep(gpiod, 1);
2255 usleep_range(10000, 20000);
2256 gpiod_set_value_cansleep(gpiod, 0);
2257 usleep_range(10000, 20000);
2258 }
2259}
2260
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002261static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2262{
2263 int i, err;
2264
2265 /* Set all ports to the Disabled state */
2266 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2267 err = mv88e6xxx_port_set_state(chip, i,
2268 PORT_CONTROL_STATE_DISABLED);
2269 if (err)
2270 return err;
2271 }
2272
2273 /* Wait for transmit queues to drain,
2274 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2275 */
2276 usleep_range(2000, 4000);
2277
2278 return 0;
2279}
2280
Vivien Didelotfad09c72016-06-21 12:28:20 -04002281static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002282{
Vivien Didelota935c052016-09-29 12:21:53 -04002283 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002284
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002285 err = mv88e6xxx_disable_ports(chip);
2286 if (err)
2287 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002288
Vivien Didelot309eca62016-12-05 17:30:26 -05002289 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002290
Vivien Didelot17e708b2016-12-05 17:30:27 -05002291 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002292}
2293
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002294static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002295{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002296 u16 val;
2297 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002298
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002299 /* Clear Power Down bit */
2300 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2301 if (err)
2302 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002303
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002304 if (val & BMCR_PDOWN) {
2305 val &= ~BMCR_PDOWN;
2306 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002307 }
2308
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002309 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002310}
2311
Andrew Lunn56995cb2016-12-03 04:35:19 +01002312static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2313 int upstream_port)
2314{
2315 int err;
2316
2317 err = chip->info->ops->port_set_frame_mode(
2318 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2319 if (err)
2320 return err;
2321
2322 return chip->info->ops->port_set_egress_unknowns(
2323 chip, port, port == upstream_port);
2324}
2325
2326static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2327{
2328 int err;
2329
2330 switch (chip->info->tag_protocol) {
2331 case DSA_TAG_PROTO_EDSA:
2332 err = chip->info->ops->port_set_frame_mode(
2333 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2334 if (err)
2335 return err;
2336
2337 err = mv88e6xxx_port_set_egress_mode(
2338 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2339 if (err)
2340 return err;
2341
2342 if (chip->info->ops->port_set_ether_type)
2343 err = chip->info->ops->port_set_ether_type(
2344 chip, port, ETH_P_EDSA);
2345 break;
2346
2347 case DSA_TAG_PROTO_DSA:
2348 err = chip->info->ops->port_set_frame_mode(
2349 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2350 if (err)
2351 return err;
2352
2353 err = mv88e6xxx_port_set_egress_mode(
2354 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2355 break;
2356 default:
2357 err = -EINVAL;
2358 }
2359
2360 if (err)
2361 return err;
2362
2363 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2364}
2365
2366static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2367{
2368 int err;
2369
2370 err = chip->info->ops->port_set_frame_mode(
2371 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2372 if (err)
2373 return err;
2374
2375 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2376}
2377
Vivien Didelotea698f42017-03-11 16:12:50 -05002378static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2379{
2380 bool message = dsa_is_dsa_port(chip->ds, port);
2381
2382 return mv88e6xxx_port_set_message_port(chip, port, message);
2383}
2384
Vivien Didelotfad09c72016-06-21 12:28:20 -04002385static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002386{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002387 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002388 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002389 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002390
Vivien Didelotd78343d2016-11-04 03:23:36 +01002391 /* MAC Forcing register: don't force link, speed, duplex or flow control
2392 * state to any particular values on physical ports, but force the CPU
2393 * port and all DSA ports to their maximum bandwidth and full duplex.
2394 */
2395 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2396 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2397 SPEED_MAX, DUPLEX_FULL,
2398 PHY_INTERFACE_MODE_NA);
2399 else
2400 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2401 SPEED_UNFORCED, DUPLEX_UNFORCED,
2402 PHY_INTERFACE_MODE_NA);
2403 if (err)
2404 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002405
2406 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2407 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2408 * tunneling, determine priority by looking at 802.1p and IP
2409 * priority fields (IP prio has precedence), and set STP state
2410 * to Forwarding.
2411 *
2412 * If this is the CPU link, use DSA or EDSA tagging depending
2413 * on which tagging mode was configured.
2414 *
2415 * If this is a link to another switch, use DSA tagging mode.
2416 *
2417 * If this is the upstream port for this switch, enable
2418 * forwarding of unknown unicasts and multicasts.
2419 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002420 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002421 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2422 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002423 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2424 if (err)
2425 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002426
Andrew Lunn56995cb2016-12-03 04:35:19 +01002427 if (dsa_is_cpu_port(ds, port)) {
2428 err = mv88e6xxx_setup_port_cpu(chip, port);
2429 } else if (dsa_is_dsa_port(ds, port)) {
2430 err = mv88e6xxx_setup_port_dsa(chip, port,
2431 dsa_upstream_port(ds));
2432 } else {
2433 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002434 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002435 if (err)
2436 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002437
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002438 /* If this port is connected to a SerDes, make sure the SerDes is not
2439 * powered down.
2440 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002441 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002442 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2443 if (err)
2444 return err;
2445 reg &= PORT_STATUS_CMODE_MASK;
2446 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2447 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2448 (reg == PORT_STATUS_CMODE_SGMII)) {
2449 err = mv88e6xxx_serdes_power_on(chip);
2450 if (err < 0)
2451 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002452 }
2453 }
2454
Vivien Didelot8efdda42015-08-13 12:52:23 -04002455 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002456 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002457 * untagged frames on this port, do a destination address lookup on all
2458 * received packets as usual, disable ARP mirroring and don't send a
2459 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002460 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002461 err = mv88e6xxx_port_set_map_da(chip, port);
2462 if (err)
2463 return err;
2464
Andrew Lunn54d792f2015-05-06 01:09:47 +02002465 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01002466 if (chip->info->ops->port_set_upstream_port) {
2467 err = chip->info->ops->port_set_upstream_port(
2468 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002469 if (err)
2470 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002471 }
2472
Andrew Lunna23b2962017-02-04 20:15:28 +01002473 err = mv88e6xxx_port_set_8021q_mode(chip, port,
2474 PORT_CONTROL_2_8021Q_DISABLED);
2475 if (err)
2476 return err;
2477
Andrew Lunn5f436662016-12-03 04:45:17 +01002478 if (chip->info->ops->port_jumbo_config) {
2479 err = chip->info->ops->port_jumbo_config(chip, port);
2480 if (err)
2481 return err;
2482 }
2483
Andrew Lunn54d792f2015-05-06 01:09:47 +02002484 /* Port Association Vector: when learning source addresses
2485 * of packets, add the address to the address database using
2486 * a port bitmap that has only the bit for this port set and
2487 * the other bits clear.
2488 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002489 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002490 /* Disable learning for CPU port */
2491 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002492 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002493
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002494 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2495 if (err)
2496 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002497
2498 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002499 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2500 if (err)
2501 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002502
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002503 if (chip->info->ops->port_pause_config) {
2504 err = chip->info->ops->port_pause_config(chip, port);
2505 if (err)
2506 return err;
2507 }
2508
Vivien Didelotfad09c72016-06-21 12:28:20 -04002509 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2510 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01002511 mv88e6xxx_6320_family(chip) || mv88e6xxx_6341_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002512 /* Port ATU control: disable limiting the number of
2513 * address database entries that this port is allowed
2514 * to use.
2515 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002516 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2517 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002518 /* Priority Override: disable DA, SA and VTU priority
2519 * override.
2520 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002521 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2522 0x0000);
2523 if (err)
2524 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002525 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002526
Andrew Lunnef0a7312016-12-03 04:35:16 +01002527 if (chip->info->ops->port_tag_remap) {
2528 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002529 if (err)
2530 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002531 }
2532
Andrew Lunnef70b112016-12-03 04:45:18 +01002533 if (chip->info->ops->port_egress_rate_limiting) {
2534 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002535 if (err)
2536 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002537 }
2538
Vivien Didelotea698f42017-03-11 16:12:50 -05002539 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002540 if (err)
2541 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002542
Vivien Didelot207afda2016-04-14 14:42:09 -04002543 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002544 * database, and allow bidirectional communication between the
2545 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002546 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002547 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002548 if (err)
2549 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002550
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002551 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2552 if (err)
2553 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002554
2555 /* Default VLAN ID and priority: don't set a default VLAN
2556 * ID, and set the default packet priority to zero.
2557 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002558 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002559}
2560
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002561static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002562{
2563 int err;
2564
Vivien Didelota935c052016-09-29 12:21:53 -04002565 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002566 if (err)
2567 return err;
2568
Vivien Didelota935c052016-09-29 12:21:53 -04002569 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002570 if (err)
2571 return err;
2572
Vivien Didelota935c052016-09-29 12:21:53 -04002573 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2574 if (err)
2575 return err;
2576
2577 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002578}
2579
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002580static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2581 unsigned int ageing_time)
2582{
Vivien Didelot04bed142016-08-31 18:06:13 -04002583 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002584 int err;
2585
2586 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002587 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002588 mutex_unlock(&chip->reg_lock);
2589
2590 return err;
2591}
2592
Vivien Didelot97299342016-07-18 20:45:30 -04002593static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002594{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002595 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002596 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002597 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002598
Vivien Didelot119477b2016-05-09 13:22:51 -04002599 /* Enable the PHY Polling Unit if present, don't discard any packets,
2600 * and mask all interrupt sources.
2601 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002602 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002603 if (err)
2604 return err;
2605
Andrew Lunn33641992016-12-03 04:35:17 +01002606 if (chip->info->ops->g1_set_cpu_port) {
2607 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2608 if (err)
2609 return err;
2610 }
2611
2612 if (chip->info->ops->g1_set_egress_port) {
2613 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2614 if (err)
2615 return err;
2616 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002617
Vivien Didelot50484ff2016-05-09 13:22:54 -04002618 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002619 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2620 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2621 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002622 if (err)
2623 return err;
2624
Vivien Didelotacddbd22016-07-18 20:45:39 -04002625 /* Clear all the VTU and STU entries */
2626 err = _mv88e6xxx_vtu_stu_flush(chip);
2627 if (err < 0)
2628 return err;
2629
Vivien Didelot08a01262016-05-09 13:22:50 -04002630 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002631 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002632 if (err)
2633 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002634 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002635 if (err)
2636 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002637 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002638 if (err)
2639 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002640 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002641 if (err)
2642 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002643 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002644 if (err)
2645 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002646 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002647 if (err)
2648 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002649 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002650 if (err)
2651 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002652 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002653 if (err)
2654 return err;
2655
2656 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002657 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002658 if (err)
2659 return err;
2660
Andrew Lunnde2273872016-11-21 23:27:01 +01002661 /* Initialize the statistics unit */
2662 err = mv88e6xxx_stats_set_histogram(chip);
2663 if (err)
2664 return err;
2665
Vivien Didelot97299342016-07-18 20:45:30 -04002666 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002667 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2668 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002669 if (err)
2670 return err;
2671
2672 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002673 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002674 if (err)
2675 return err;
2676
2677 return 0;
2678}
2679
Vivien Didelotf81ec902016-05-09 13:22:58 -04002680static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002681{
Vivien Didelot04bed142016-08-31 18:06:13 -04002682 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002683 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002684 int i;
2685
Vivien Didelotfad09c72016-06-21 12:28:20 -04002686 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002687 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002688
Vivien Didelotfad09c72016-06-21 12:28:20 -04002689 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002690
Vivien Didelot97299342016-07-18 20:45:30 -04002691 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002692 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002693 err = mv88e6xxx_setup_port(chip, i);
2694 if (err)
2695 goto unlock;
2696 }
2697
2698 /* Setup Switch Global 1 Registers */
2699 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002700 if (err)
2701 goto unlock;
2702
Vivien Didelot97299342016-07-18 20:45:30 -04002703 /* Setup Switch Global 2 Registers */
2704 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2705 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002706 if (err)
2707 goto unlock;
2708 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002709
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002710 err = mv88e6xxx_atu_setup(chip);
2711 if (err)
2712 goto unlock;
2713
Andrew Lunn6e55f692016-12-03 04:45:16 +01002714 /* Some generations have the configuration of sending reserved
2715 * management frames to the CPU in global2, others in
2716 * global1. Hence it does not fit the two setup functions
2717 * above.
2718 */
2719 if (chip->info->ops->mgmt_rsvd2cpu) {
2720 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2721 if (err)
2722 goto unlock;
2723 }
2724
Vivien Didelot6b17e862015-08-13 12:52:18 -04002725unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002726 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002727
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002728 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002729}
2730
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002731static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2732{
Vivien Didelot04bed142016-08-31 18:06:13 -04002733 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002734 int err;
2735
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002736 if (!chip->info->ops->set_switch_mac)
2737 return -EOPNOTSUPP;
2738
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002739 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002740 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002741 mutex_unlock(&chip->reg_lock);
2742
2743 return err;
2744}
2745
Vivien Didelote57e5e72016-08-15 17:19:00 -04002746static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002747{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002748 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2749 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002750 u16 val;
2751 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002752
Andrew Lunnee26a222017-01-24 14:53:48 +01002753 if (!chip->info->ops->phy_read)
2754 return -EOPNOTSUPP;
2755
Vivien Didelotfad09c72016-06-21 12:28:20 -04002756 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002757 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002758 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002759
Andrew Lunnda9f3302017-02-01 03:40:05 +01002760 if (reg == MII_PHYSID2) {
2761 /* Some internal PHYS don't have a model number. Use
2762 * the mv88e6390 family model number instead.
2763 */
2764 if (!(val & 0x3f0))
2765 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2766 }
2767
Vivien Didelote57e5e72016-08-15 17:19:00 -04002768 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002769}
2770
Vivien Didelote57e5e72016-08-15 17:19:00 -04002771static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002772{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002773 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2774 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002775 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002776
Andrew Lunnee26a222017-01-24 14:53:48 +01002777 if (!chip->info->ops->phy_write)
2778 return -EOPNOTSUPP;
2779
Vivien Didelotfad09c72016-06-21 12:28:20 -04002780 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002781 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002782 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002783
2784 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002785}
2786
Vivien Didelotfad09c72016-06-21 12:28:20 -04002787static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002788 struct device_node *np,
2789 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002790{
2791 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002792 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002793 struct mii_bus *bus;
2794 int err;
2795
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002796 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002797 if (!bus)
2798 return -ENOMEM;
2799
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002800 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002801 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002802 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002803 INIT_LIST_HEAD(&mdio_bus->list);
2804 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002805
Andrew Lunnb516d452016-06-04 21:17:06 +02002806 if (np) {
2807 bus->name = np->full_name;
2808 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2809 } else {
2810 bus->name = "mv88e6xxx SMI";
2811 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2812 }
2813
2814 bus->read = mv88e6xxx_mdio_read;
2815 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002816 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002817
Andrew Lunna3c53be52017-01-24 14:53:50 +01002818 if (np)
2819 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002820 else
2821 err = mdiobus_register(bus);
2822 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002823 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002824 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002825 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002826
2827 if (external)
2828 list_add_tail(&mdio_bus->list, &chip->mdios);
2829 else
2830 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002831
2832 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002833}
2834
Andrew Lunna3c53be52017-01-24 14:53:50 +01002835static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2836 { .compatible = "marvell,mv88e6xxx-mdio-external",
2837 .data = (void *)true },
2838 { },
2839};
2840
2841static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2842 struct device_node *np)
2843{
2844 const struct of_device_id *match;
2845 struct device_node *child;
2846 int err;
2847
2848 /* Always register one mdio bus for the internal/default mdio
2849 * bus. This maybe represented in the device tree, but is
2850 * optional.
2851 */
2852 child = of_get_child_by_name(np, "mdio");
2853 err = mv88e6xxx_mdio_register(chip, child, false);
2854 if (err)
2855 return err;
2856
2857 /* Walk the device tree, and see if there are any other nodes
2858 * which say they are compatible with the external mdio
2859 * bus.
2860 */
2861 for_each_available_child_of_node(np, child) {
2862 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2863 if (match) {
2864 err = mv88e6xxx_mdio_register(chip, child, true);
2865 if (err)
2866 return err;
2867 }
2868 }
2869
2870 return 0;
2871}
2872
2873static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002874
2875{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002876 struct mv88e6xxx_mdio_bus *mdio_bus;
2877 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002878
Andrew Lunna3c53be52017-01-24 14:53:50 +01002879 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2880 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002881
Andrew Lunna3c53be52017-01-24 14:53:50 +01002882 mdiobus_unregister(bus);
2883 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002884}
2885
Vivien Didelot855b1932016-07-20 18:18:35 -04002886static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2887{
Vivien Didelot04bed142016-08-31 18:06:13 -04002888 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002889
2890 return chip->eeprom_len;
2891}
2892
Vivien Didelot855b1932016-07-20 18:18:35 -04002893static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2894 struct ethtool_eeprom *eeprom, u8 *data)
2895{
Vivien Didelot04bed142016-08-31 18:06:13 -04002896 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002897 int err;
2898
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002899 if (!chip->info->ops->get_eeprom)
2900 return -EOPNOTSUPP;
2901
Vivien Didelot855b1932016-07-20 18:18:35 -04002902 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002903 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002904 mutex_unlock(&chip->reg_lock);
2905
2906 if (err)
2907 return err;
2908
2909 eeprom->magic = 0xc3ec4951;
2910
2911 return 0;
2912}
2913
Vivien Didelot855b1932016-07-20 18:18:35 -04002914static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2915 struct ethtool_eeprom *eeprom, u8 *data)
2916{
Vivien Didelot04bed142016-08-31 18:06:13 -04002917 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002918 int err;
2919
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002920 if (!chip->info->ops->set_eeprom)
2921 return -EOPNOTSUPP;
2922
Vivien Didelot855b1932016-07-20 18:18:35 -04002923 if (eeprom->magic != 0xc3ec4951)
2924 return -EINVAL;
2925
2926 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002927 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002928 mutex_unlock(&chip->reg_lock);
2929
2930 return err;
2931}
2932
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002933static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002934 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002935 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002936 .phy_read = mv88e6xxx_phy_ppu_read,
2937 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002938 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002939 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002940 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002941 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002942 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2943 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
2944 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002945 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002946 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002947 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002948 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2949 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002950 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002951 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2952 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002953 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002954 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002955 .ppu_enable = mv88e6185_g1_ppu_enable,
2956 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002957 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002958};
2959
2960static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002961 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002962 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002963 .phy_read = mv88e6xxx_phy_ppu_read,
2964 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002965 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002966 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002967 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002968 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01002969 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
2970 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002971 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002972 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2973 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002974 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002975 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002976 .ppu_enable = mv88e6185_g1_ppu_enable,
2977 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002978 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002979};
2980
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002981static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002982 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002983 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2984 .phy_read = mv88e6xxx_g2_smi_phy_read,
2985 .phy_write = mv88e6xxx_g2_smi_phy_write,
2986 .port_set_link = mv88e6xxx_port_set_link,
2987 .port_set_duplex = mv88e6xxx_port_set_duplex,
2988 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002989 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002990 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2991 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
2992 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002993 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002994 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002995 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002996 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2997 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2998 .stats_get_strings = mv88e6095_stats_get_strings,
2999 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003000 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3001 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003002 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003003 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003004 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003005};
3006
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003007static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003008 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003009 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003010 .phy_read = mv88e6165_phy_read,
3011 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003012 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003013 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003014 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003015 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3016 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003017 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003018 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3019 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003020 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003021 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3022 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003023 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003024 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003025 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003026};
3027
3028static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003029 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003030 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003031 .phy_read = mv88e6xxx_phy_ppu_read,
3032 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003033 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003034 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003035 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003036 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003037 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01003038 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003039 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003040 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01003041 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003042 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003043 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003044 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003045 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3046 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003047 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003048 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3049 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003050 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003051 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003052 .ppu_enable = mv88e6185_g1_ppu_enable,
3053 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003054 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003055};
3056
3057static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003058 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003059 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003060 .phy_read = mv88e6165_phy_read,
3061 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003062 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003063 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003064 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003065 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003066 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3067 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3068 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003069 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003070 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003071 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003072 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003073 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3074 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003075 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003076 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3077 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003078 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003079 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003080 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003081};
3082
3083static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003084 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003085 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003086 .phy_read = mv88e6165_phy_read,
3087 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003088 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003089 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003090 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003091 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003092 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3093 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003094 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003095 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3096 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003097 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003098 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003099 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003100};
3101
3102static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003103 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003104 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003105 .phy_read = mv88e6xxx_g2_smi_phy_read,
3106 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003107 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003108 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003109 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003110 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003111 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003112 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3113 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3114 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003115 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003116 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003117 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003118 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003119 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3120 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003121 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003122 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3123 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003124 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003125 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003126 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003127};
3128
3129static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003130 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003131 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3132 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003133 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003134 .phy_read = mv88e6xxx_g2_smi_phy_read,
3135 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003136 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003137 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003138 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003139 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003140 .port_tag_remap = mv88e6095_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 Lunn5f436662016-12-03 04:45:17 +01003144 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003145 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003146 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003147 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003148 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3149 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003150 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003151 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3152 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003153 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003154 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003155 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003156};
3157
3158static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003159 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003160 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003161 .phy_read = mv88e6xxx_g2_smi_phy_read,
3162 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003163 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003164 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003165 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003166 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003167 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003168 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3169 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3170 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003171 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003172 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003173 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003174 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003175 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3176 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003177 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003178 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3179 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003180 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003181 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003182 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003183};
3184
3185static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003186 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003187 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3188 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003189 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003190 .phy_read = mv88e6xxx_g2_smi_phy_read,
3191 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003192 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003193 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003194 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003195 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003196 .port_tag_remap = mv88e6095_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 Lunn5f436662016-12-03 04:45:17 +01003200 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003201 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003202 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003203 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003204 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3205 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003206 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003207 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3208 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003209 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003210 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003211 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003212};
3213
3214static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003215 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003216 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003217 .phy_read = mv88e6xxx_phy_ppu_read,
3218 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003219 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003220 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003221 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003222 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01003223 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003224 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003225 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003226 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003227 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3228 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003229 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003230 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3231 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003232 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003233 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003234 .ppu_enable = mv88e6185_g1_ppu_enable,
3235 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003236 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003237};
3238
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003239static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003240 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003241 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3242 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003243 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3244 .phy_read = mv88e6xxx_g2_smi_phy_read,
3245 .phy_write = mv88e6xxx_g2_smi_phy_write,
3246 .port_set_link = mv88e6xxx_port_set_link,
3247 .port_set_duplex = mv88e6xxx_port_set_duplex,
3248 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3249 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003250 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003251 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3252 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3253 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003254 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003255 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003256 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003257 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3258 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003259 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003260 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3261 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003262 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003263 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003264 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003265};
3266
3267static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003268 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003269 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3270 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003271 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3272 .phy_read = mv88e6xxx_g2_smi_phy_read,
3273 .phy_write = mv88e6xxx_g2_smi_phy_write,
3274 .port_set_link = mv88e6xxx_port_set_link,
3275 .port_set_duplex = mv88e6xxx_port_set_duplex,
3276 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3277 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003278 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003279 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3280 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3281 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003282 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003283 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003284 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003285 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3286 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003287 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003288 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3289 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003290 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003291 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003292 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003293};
3294
3295static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003296 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003297 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3298 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003299 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3300 .phy_read = mv88e6xxx_g2_smi_phy_read,
3301 .phy_write = mv88e6xxx_g2_smi_phy_write,
3302 .port_set_link = mv88e6xxx_port_set_link,
3303 .port_set_duplex = mv88e6xxx_port_set_duplex,
3304 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3305 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003306 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003307 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3308 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3309 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003310 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003311 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003312 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003313 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3314 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003315 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003316 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3317 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003318 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003319 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003320 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003321};
3322
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003323static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003324 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003325 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3326 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003327 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003328 .phy_read = mv88e6xxx_g2_smi_phy_read,
3329 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003330 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003331 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003332 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003333 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003334 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003335 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3336 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3337 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003338 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003339 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003340 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003341 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003342 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3343 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003344 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003345 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3346 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003347 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003348 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003349 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003350};
3351
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003352static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003353 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003354 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3355 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003356 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3357 .phy_read = mv88e6xxx_g2_smi_phy_read,
3358 .phy_write = mv88e6xxx_g2_smi_phy_write,
3359 .port_set_link = mv88e6xxx_port_set_link,
3360 .port_set_duplex = mv88e6xxx_port_set_duplex,
3361 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3362 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003363 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003364 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3365 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3366 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003367 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003368 .port_set_cmode = mv88e6390x_port_set_cmode,
Andrew Lunn79523472016-11-21 23:27:00 +01003369 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003370 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003371 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3372 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003373 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003374 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3375 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003376 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003377 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003378 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003379};
3380
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003381static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003382 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003383 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3384 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003385 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003386 .phy_read = mv88e6xxx_g2_smi_phy_read,
3387 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003388 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003389 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003390 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003391 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003392 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3393 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3394 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003395 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003396 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003397 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003398 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003399 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3400 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003401 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003402 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3403 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003404 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003405 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003406};
3407
3408static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003409 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003410 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3411 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003412 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003413 .phy_read = mv88e6xxx_g2_smi_phy_read,
3414 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003415 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003416 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003417 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003418 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003419 .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,
Andrew Lunn5f436662016-12-03 04:45:17 +01003422 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003423 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003424 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003425 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003426 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3427 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003428 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003429 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3430 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003431 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003432};
3433
3434static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003435 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003436 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003437 .phy_read = mv88e6xxx_g2_smi_phy_read,
3438 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003439 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003440 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003441 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003442 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003443 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003444 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3445 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3446 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003447 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003448 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003449 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003450 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003451 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3452 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003453 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003454 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3455 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003456 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003457 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003458 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003459};
3460
3461static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003462 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003463 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003464 .phy_read = mv88e6xxx_g2_smi_phy_read,
3465 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003466 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003467 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003468 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003469 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003470 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003471 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3472 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3473 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003474 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003475 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003476 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003477 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003478 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3479 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003480 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003481 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3482 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003483 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003484 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003485 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003486};
3487
3488static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003489 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003490 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3491 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003492 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003493 .phy_read = mv88e6xxx_g2_smi_phy_read,
3494 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003495 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003496 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003497 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003498 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003499 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003500 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3501 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3502 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003503 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003504 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003505 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003506 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003507 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3508 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003509 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003510 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3511 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003512 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003513 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003514 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003515};
3516
Gregory CLEMENT15587272017-01-30 20:29:35 +01003517static const struct mv88e6xxx_ops mv88e6141_ops = {
3518 /* MV88E6XXX_FAMILY_6341 */
3519 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3520 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3521 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3522 .phy_read = mv88e6xxx_g2_smi_phy_read,
3523 .phy_write = mv88e6xxx_g2_smi_phy_write,
3524 .port_set_link = mv88e6xxx_port_set_link,
3525 .port_set_duplex = mv88e6xxx_port_set_duplex,
3526 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3527 .port_set_speed = mv88e6390_port_set_speed,
3528 .port_tag_remap = mv88e6095_port_tag_remap,
3529 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3530 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3531 .port_set_ether_type = mv88e6351_port_set_ether_type,
3532 .port_jumbo_config = mv88e6165_port_jumbo_config,
3533 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3534 .port_pause_config = mv88e6097_port_pause_config,
3535 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3536 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3537 .stats_get_strings = mv88e6320_stats_get_strings,
3538 .stats_get_stats = mv88e6390_stats_get_stats,
3539 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3540 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003541 .watchdog_ops = &mv88e6390_watchdog_ops,
Gregory CLEMENT15587272017-01-30 20:29:35 +01003542 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3543 .reset = mv88e6352_g1_reset,
3544};
3545
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003546static const struct mv88e6xxx_ops mv88e6341_ops = {
3547 /* MV88E6XXX_FAMILY_6341 */
3548 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3549 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3550 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3551 .phy_read = mv88e6xxx_g2_smi_phy_read,
3552 .phy_write = mv88e6xxx_g2_smi_phy_write,
3553 .port_set_link = mv88e6xxx_port_set_link,
3554 .port_set_duplex = mv88e6xxx_port_set_duplex,
3555 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3556 .port_set_speed = mv88e6390_port_set_speed,
3557 .port_tag_remap = mv88e6095_port_tag_remap,
3558 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3559 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3560 .port_set_ether_type = mv88e6351_port_set_ether_type,
3561 .port_jumbo_config = mv88e6165_port_jumbo_config,
3562 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3563 .port_pause_config = mv88e6097_port_pause_config,
3564 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3565 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3566 .stats_get_strings = mv88e6320_stats_get_strings,
3567 .stats_get_stats = mv88e6390_stats_get_stats,
3568 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3569 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003570 .watchdog_ops = &mv88e6390_watchdog_ops,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003571 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3572 .reset = mv88e6352_g1_reset,
3573};
3574
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003575static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003576 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003577 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3578 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003579 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3580 .phy_read = mv88e6xxx_g2_smi_phy_read,
3581 .phy_write = mv88e6xxx_g2_smi_phy_write,
3582 .port_set_link = mv88e6xxx_port_set_link,
3583 .port_set_duplex = mv88e6xxx_port_set_duplex,
3584 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3585 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003586 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003587 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3588 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3589 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003590 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003591 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003592 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003593 .port_set_cmode = mv88e6390x_port_set_cmode,
Andrew Lunn79523472016-11-21 23:27:00 +01003594 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003595 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003596 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3597 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003598 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003599 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3600 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003601 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003602 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003603 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003604};
3605
3606static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003607 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003608 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3609 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003610 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3611 .phy_read = mv88e6xxx_g2_smi_phy_read,
3612 .phy_write = mv88e6xxx_g2_smi_phy_write,
3613 .port_set_link = mv88e6xxx_port_set_link,
3614 .port_set_duplex = mv88e6xxx_port_set_duplex,
3615 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3616 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003617 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003618 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3619 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3620 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003621 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003622 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003623 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003624 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003625 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003626 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3627 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003628 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003629 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3630 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003631 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003632 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003633 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003634};
3635
3636static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003637 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003638 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3639 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003640 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3641 .phy_read = mv88e6xxx_g2_smi_phy_read,
3642 .phy_write = mv88e6xxx_g2_smi_phy_write,
3643 .port_set_link = mv88e6xxx_port_set_link,
3644 .port_set_duplex = mv88e6xxx_port_set_duplex,
3645 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3646 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003647 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003648 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3649 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3650 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003651 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003652 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003653 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003654 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3655 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003656 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003657 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3658 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003659 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003660 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003661 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003662};
3663
Andrew Lunn56995cb2016-12-03 04:35:19 +01003664static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3665 const struct mv88e6xxx_ops *ops)
3666{
3667 if (!ops->port_set_frame_mode) {
3668 dev_err(chip->dev, "Missing port_set_frame_mode");
3669 return -EINVAL;
3670 }
3671
3672 if (!ops->port_set_egress_unknowns) {
3673 dev_err(chip->dev, "Missing port_set_egress_mode");
3674 return -EINVAL;
3675 }
3676
3677 return 0;
3678}
3679
Vivien Didelotf81ec902016-05-09 13:22:58 -04003680static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3681 [MV88E6085] = {
3682 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3683 .family = MV88E6XXX_FAMILY_6097,
3684 .name = "Marvell 88E6085",
3685 .num_databases = 4096,
3686 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003687 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003688 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003689 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003690 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003691 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003692 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003693 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003694 },
3695
3696 [MV88E6095] = {
3697 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3698 .family = MV88E6XXX_FAMILY_6095,
3699 .name = "Marvell 88E6095/88E6095F",
3700 .num_databases = 256,
3701 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003702 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003703 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003704 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003705 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003706 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003707 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003708 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003709 },
3710
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003711 [MV88E6097] = {
3712 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3713 .family = MV88E6XXX_FAMILY_6097,
3714 .name = "Marvell 88E6097/88E6097F",
3715 .num_databases = 4096,
3716 .num_ports = 11,
3717 .port_base_addr = 0x10,
3718 .global1_addr = 0x1b,
3719 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003720 .g1_irqs = 8,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003721 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003722 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3723 .ops = &mv88e6097_ops,
3724 },
3725
Vivien Didelotf81ec902016-05-09 13:22:58 -04003726 [MV88E6123] = {
3727 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3728 .family = MV88E6XXX_FAMILY_6165,
3729 .name = "Marvell 88E6123",
3730 .num_databases = 4096,
3731 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003732 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003733 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003734 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003735 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003736 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003737 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003738 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003739 },
3740
3741 [MV88E6131] = {
3742 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3743 .family = MV88E6XXX_FAMILY_6185,
3744 .name = "Marvell 88E6131",
3745 .num_databases = 256,
3746 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003747 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003748 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003749 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003750 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003751 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003752 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003753 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003754 },
3755
3756 [MV88E6161] = {
3757 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3758 .family = MV88E6XXX_FAMILY_6165,
3759 .name = "Marvell 88E6161",
3760 .num_databases = 4096,
3761 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003762 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003763 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003764 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003765 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003766 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003767 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003768 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003769 },
3770
3771 [MV88E6165] = {
3772 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3773 .family = MV88E6XXX_FAMILY_6165,
3774 .name = "Marvell 88E6165",
3775 .num_databases = 4096,
3776 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003777 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003778 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003779 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003780 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003781 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003782 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003783 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003784 },
3785
3786 [MV88E6171] = {
3787 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3788 .family = MV88E6XXX_FAMILY_6351,
3789 .name = "Marvell 88E6171",
3790 .num_databases = 4096,
3791 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003792 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003793 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003794 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003795 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003796 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003797 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003798 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003799 },
3800
3801 [MV88E6172] = {
3802 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3803 .family = MV88E6XXX_FAMILY_6352,
3804 .name = "Marvell 88E6172",
3805 .num_databases = 4096,
3806 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003807 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003808 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003809 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003810 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003811 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003812 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003813 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003814 },
3815
3816 [MV88E6175] = {
3817 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3818 .family = MV88E6XXX_FAMILY_6351,
3819 .name = "Marvell 88E6175",
3820 .num_databases = 4096,
3821 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003822 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003823 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003824 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003825 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003826 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003827 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003828 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003829 },
3830
3831 [MV88E6176] = {
3832 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3833 .family = MV88E6XXX_FAMILY_6352,
3834 .name = "Marvell 88E6176",
3835 .num_databases = 4096,
3836 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003837 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003838 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003839 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003840 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003841 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003842 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003843 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003844 },
3845
3846 [MV88E6185] = {
3847 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3848 .family = MV88E6XXX_FAMILY_6185,
3849 .name = "Marvell 88E6185",
3850 .num_databases = 256,
3851 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003852 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003853 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003854 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003855 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003856 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003857 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003858 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003859 },
3860
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003861 [MV88E6190] = {
3862 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3863 .family = MV88E6XXX_FAMILY_6390,
3864 .name = "Marvell 88E6190",
3865 .num_databases = 4096,
3866 .num_ports = 11, /* 10 + Z80 */
3867 .port_base_addr = 0x0,
3868 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003869 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003870 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003871 .g1_irqs = 9,
3872 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3873 .ops = &mv88e6190_ops,
3874 },
3875
3876 [MV88E6190X] = {
3877 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3878 .family = MV88E6XXX_FAMILY_6390,
3879 .name = "Marvell 88E6190X",
3880 .num_databases = 4096,
3881 .num_ports = 11, /* 10 + Z80 */
3882 .port_base_addr = 0x0,
3883 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003884 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003885 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003886 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003887 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3888 .ops = &mv88e6190x_ops,
3889 },
3890
3891 [MV88E6191] = {
3892 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3893 .family = MV88E6XXX_FAMILY_6390,
3894 .name = "Marvell 88E6191",
3895 .num_databases = 4096,
3896 .num_ports = 11, /* 10 + Z80 */
3897 .port_base_addr = 0x0,
3898 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003899 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003900 .g1_irqs = 9,
3901 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003902 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3903 .ops = &mv88e6391_ops,
3904 },
3905
Vivien Didelotf81ec902016-05-09 13:22:58 -04003906 [MV88E6240] = {
3907 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3908 .family = MV88E6XXX_FAMILY_6352,
3909 .name = "Marvell 88E6240",
3910 .num_databases = 4096,
3911 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003912 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003913 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003914 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003915 .g1_irqs = 9,
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_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003918 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003919 },
3920
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003921 [MV88E6290] = {
3922 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3923 .family = MV88E6XXX_FAMILY_6390,
3924 .name = "Marvell 88E6290",
3925 .num_databases = 4096,
3926 .num_ports = 11, /* 10 + Z80 */
3927 .port_base_addr = 0x0,
3928 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003929 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003930 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003931 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003932 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3933 .ops = &mv88e6290_ops,
3934 },
3935
Vivien Didelotf81ec902016-05-09 13:22:58 -04003936 [MV88E6320] = {
3937 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3938 .family = MV88E6XXX_FAMILY_6320,
3939 .name = "Marvell 88E6320",
3940 .num_databases = 4096,
3941 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003942 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003943 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003944 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003945 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003946 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003947 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003948 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003949 },
3950
3951 [MV88E6321] = {
3952 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3953 .family = MV88E6XXX_FAMILY_6320,
3954 .name = "Marvell 88E6321",
3955 .num_databases = 4096,
3956 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003957 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003958 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003959 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003960 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003961 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003962 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003963 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003964 },
3965
Gregory CLEMENT15587272017-01-30 20:29:35 +01003966 [MV88E6141] = {
3967 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
3968 .family = MV88E6XXX_FAMILY_6341,
3969 .name = "Marvell 88E6341",
3970 .num_databases = 4096,
3971 .num_ports = 6,
3972 .port_base_addr = 0x10,
3973 .global1_addr = 0x1b,
3974 .age_time_coeff = 3750,
3975 .tag_protocol = DSA_TAG_PROTO_EDSA,
3976 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3977 .ops = &mv88e6141_ops,
3978 },
3979
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003980 [MV88E6341] = {
3981 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
3982 .family = MV88E6XXX_FAMILY_6341,
3983 .name = "Marvell 88E6341",
3984 .num_databases = 4096,
3985 .num_ports = 6,
3986 .port_base_addr = 0x10,
3987 .global1_addr = 0x1b,
3988 .age_time_coeff = 3750,
3989 .tag_protocol = DSA_TAG_PROTO_EDSA,
3990 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3991 .ops = &mv88e6341_ops,
3992 },
3993
Vivien Didelotf81ec902016-05-09 13:22:58 -04003994 [MV88E6350] = {
3995 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3996 .family = MV88E6XXX_FAMILY_6351,
3997 .name = "Marvell 88E6350",
3998 .num_databases = 4096,
3999 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004000 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004001 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004002 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004003 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004004 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004005 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004006 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004007 },
4008
4009 [MV88E6351] = {
4010 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4011 .family = MV88E6XXX_FAMILY_6351,
4012 .name = "Marvell 88E6351",
4013 .num_databases = 4096,
4014 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004015 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004016 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004017 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004018 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004019 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004020 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004021 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004022 },
4023
4024 [MV88E6352] = {
4025 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4026 .family = MV88E6XXX_FAMILY_6352,
4027 .name = "Marvell 88E6352",
4028 .num_databases = 4096,
4029 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004030 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004031 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004032 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004033 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004034 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004035 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004036 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004037 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004038 [MV88E6390] = {
4039 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4040 .family = MV88E6XXX_FAMILY_6390,
4041 .name = "Marvell 88E6390",
4042 .num_databases = 4096,
4043 .num_ports = 11, /* 10 + Z80 */
4044 .port_base_addr = 0x0,
4045 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004046 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004047 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004048 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004049 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4050 .ops = &mv88e6390_ops,
4051 },
4052 [MV88E6390X] = {
4053 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4054 .family = MV88E6XXX_FAMILY_6390,
4055 .name = "Marvell 88E6390X",
4056 .num_databases = 4096,
4057 .num_ports = 11, /* 10 + Z80 */
4058 .port_base_addr = 0x0,
4059 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004060 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004061 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004062 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004063 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4064 .ops = &mv88e6390x_ops,
4065 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004066};
4067
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004068static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004069{
Vivien Didelota439c062016-04-17 13:23:58 -04004070 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004071
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004072 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4073 if (mv88e6xxx_table[i].prod_num == prod_num)
4074 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004075
Vivien Didelotb9b37712015-10-30 19:39:48 -04004076 return NULL;
4077}
4078
Vivien Didelotfad09c72016-06-21 12:28:20 -04004079static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004080{
4081 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004082 unsigned int prod_num, rev;
4083 u16 id;
4084 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004085
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004086 mutex_lock(&chip->reg_lock);
4087 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4088 mutex_unlock(&chip->reg_lock);
4089 if (err)
4090 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004091
4092 prod_num = (id & 0xfff0) >> 4;
4093 rev = id & 0x000f;
4094
4095 info = mv88e6xxx_lookup_info(prod_num);
4096 if (!info)
4097 return -ENODEV;
4098
Vivien Didelotcaac8542016-06-20 13:14:09 -04004099 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004100 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004101
Vivien Didelotca070c12016-09-02 14:45:34 -04004102 err = mv88e6xxx_g2_require(chip);
4103 if (err)
4104 return err;
4105
Vivien Didelotfad09c72016-06-21 12:28:20 -04004106 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4107 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004108
4109 return 0;
4110}
4111
Vivien Didelotfad09c72016-06-21 12:28:20 -04004112static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004113{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004114 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004115
Vivien Didelotfad09c72016-06-21 12:28:20 -04004116 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4117 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004118 return NULL;
4119
Vivien Didelotfad09c72016-06-21 12:28:20 -04004120 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004121
Vivien Didelotfad09c72016-06-21 12:28:20 -04004122 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004123 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004124
Vivien Didelotfad09c72016-06-21 12:28:20 -04004125 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004126}
4127
Vivien Didelote57e5e72016-08-15 17:19:00 -04004128static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4129{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004130 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004131 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004132}
4133
Andrew Lunn930188c2016-08-22 16:01:03 +02004134static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4135{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004136 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004137 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004138}
4139
Vivien Didelotfad09c72016-06-21 12:28:20 -04004140static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004141 struct mii_bus *bus, int sw_addr)
4142{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004143 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004144 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004145 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004146 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004147 else
4148 return -EINVAL;
4149
Vivien Didelotfad09c72016-06-21 12:28:20 -04004150 chip->bus = bus;
4151 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004152
4153 return 0;
4154}
4155
Andrew Lunn7b314362016-08-22 16:01:01 +02004156static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4157{
Vivien Didelot04bed142016-08-31 18:06:13 -04004158 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004159
Andrew Lunn443d5a12016-12-03 04:35:18 +01004160 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004161}
4162
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004163static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4164 struct device *host_dev, int sw_addr,
4165 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004166{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004167 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004168 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004169 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004170
Vivien Didelota439c062016-04-17 13:23:58 -04004171 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004172 if (!bus)
4173 return NULL;
4174
Vivien Didelotfad09c72016-06-21 12:28:20 -04004175 chip = mv88e6xxx_alloc_chip(dsa_dev);
4176 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004177 return NULL;
4178
Vivien Didelotcaac8542016-06-20 13:14:09 -04004179 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004180 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004181
Vivien Didelotfad09c72016-06-21 12:28:20 -04004182 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004183 if (err)
4184 goto free;
4185
Vivien Didelotfad09c72016-06-21 12:28:20 -04004186 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004187 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004188 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004189
Andrew Lunndc30c352016-10-16 19:56:49 +02004190 mutex_lock(&chip->reg_lock);
4191 err = mv88e6xxx_switch_reset(chip);
4192 mutex_unlock(&chip->reg_lock);
4193 if (err)
4194 goto free;
4195
Vivien Didelote57e5e72016-08-15 17:19:00 -04004196 mv88e6xxx_phy_init(chip);
4197
Andrew Lunna3c53be52017-01-24 14:53:50 +01004198 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004199 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004200 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004201
Vivien Didelotfad09c72016-06-21 12:28:20 -04004202 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004203
Vivien Didelotfad09c72016-06-21 12:28:20 -04004204 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004205free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004206 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004207
4208 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004209}
4210
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004211static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4212 const struct switchdev_obj_port_mdb *mdb,
4213 struct switchdev_trans *trans)
4214{
4215 /* We don't need any dynamic resource from the kernel (yet),
4216 * so skip the prepare phase.
4217 */
4218
4219 return 0;
4220}
4221
4222static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4223 const struct switchdev_obj_port_mdb *mdb,
4224 struct switchdev_trans *trans)
4225{
Vivien Didelot04bed142016-08-31 18:06:13 -04004226 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004227
4228 mutex_lock(&chip->reg_lock);
4229 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4230 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4231 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4232 mutex_unlock(&chip->reg_lock);
4233}
4234
4235static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4236 const struct switchdev_obj_port_mdb *mdb)
4237{
Vivien Didelot04bed142016-08-31 18:06:13 -04004238 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004239 int err;
4240
4241 mutex_lock(&chip->reg_lock);
4242 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4243 GLOBAL_ATU_DATA_STATE_UNUSED);
4244 mutex_unlock(&chip->reg_lock);
4245
4246 return err;
4247}
4248
4249static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4250 struct switchdev_obj_port_mdb *mdb,
4251 int (*cb)(struct switchdev_obj *obj))
4252{
Vivien Didelot04bed142016-08-31 18:06:13 -04004253 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004254 int err;
4255
4256 mutex_lock(&chip->reg_lock);
4257 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4258 mutex_unlock(&chip->reg_lock);
4259
4260 return err;
4261}
4262
Florian Fainellia82f67a2017-01-08 14:52:08 -08004263static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004264 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004265 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004266 .setup = mv88e6xxx_setup,
4267 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004268 .adjust_link = mv88e6xxx_adjust_link,
4269 .get_strings = mv88e6xxx_get_strings,
4270 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4271 .get_sset_count = mv88e6xxx_get_sset_count,
4272 .set_eee = mv88e6xxx_set_eee,
4273 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004274 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004275 .get_eeprom = mv88e6xxx_get_eeprom,
4276 .set_eeprom = mv88e6xxx_set_eeprom,
4277 .get_regs_len = mv88e6xxx_get_regs_len,
4278 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004279 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004280 .port_bridge_join = mv88e6xxx_port_bridge_join,
4281 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4282 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004283 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004284 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4285 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4286 .port_vlan_add = mv88e6xxx_port_vlan_add,
4287 .port_vlan_del = mv88e6xxx_port_vlan_del,
4288 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4289 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4290 .port_fdb_add = mv88e6xxx_port_fdb_add,
4291 .port_fdb_del = mv88e6xxx_port_fdb_del,
4292 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004293 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4294 .port_mdb_add = mv88e6xxx_port_mdb_add,
4295 .port_mdb_del = mv88e6xxx_port_mdb_del,
4296 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004297};
4298
Florian Fainelliab3d4082017-01-08 14:52:07 -08004299static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4300 .ops = &mv88e6xxx_switch_ops,
4301};
4302
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004303static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004304{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004305 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004306 struct dsa_switch *ds;
4307
Vivien Didelota0c02162017-01-27 15:29:36 -05004308 ds = dsa_switch_alloc(dev, DSA_MAX_PORTS);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004309 if (!ds)
4310 return -ENOMEM;
4311
Vivien Didelotfad09c72016-06-21 12:28:20 -04004312 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004313 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004314
4315 dev_set_drvdata(dev, ds);
4316
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004317 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004318}
4319
Vivien Didelotfad09c72016-06-21 12:28:20 -04004320static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004321{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004322 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004323}
4324
Vivien Didelot57d32312016-06-20 13:13:58 -04004325static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004326{
4327 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004328 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004329 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004330 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004331 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004332 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004333
Vivien Didelotcaac8542016-06-20 13:14:09 -04004334 compat_info = of_device_get_match_data(dev);
4335 if (!compat_info)
4336 return -EINVAL;
4337
Vivien Didelotfad09c72016-06-21 12:28:20 -04004338 chip = mv88e6xxx_alloc_chip(dev);
4339 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004340 return -ENOMEM;
4341
Vivien Didelotfad09c72016-06-21 12:28:20 -04004342 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004343
Andrew Lunn56995cb2016-12-03 04:35:19 +01004344 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4345 if (err)
4346 return err;
4347
Vivien Didelotfad09c72016-06-21 12:28:20 -04004348 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004349 if (err)
4350 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004351
Andrew Lunnb4308f02016-11-21 23:26:55 +01004352 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4353 if (IS_ERR(chip->reset))
4354 return PTR_ERR(chip->reset);
4355
Vivien Didelotfad09c72016-06-21 12:28:20 -04004356 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004357 if (err)
4358 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004359
Vivien Didelote57e5e72016-08-15 17:19:00 -04004360 mv88e6xxx_phy_init(chip);
4361
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004362 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004363 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004364 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004365
Andrew Lunndc30c352016-10-16 19:56:49 +02004366 mutex_lock(&chip->reg_lock);
4367 err = mv88e6xxx_switch_reset(chip);
4368 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004369 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004370 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004371
Andrew Lunndc30c352016-10-16 19:56:49 +02004372 chip->irq = of_irq_get(np, 0);
4373 if (chip->irq == -EPROBE_DEFER) {
4374 err = chip->irq;
4375 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004376 }
4377
Andrew Lunndc30c352016-10-16 19:56:49 +02004378 if (chip->irq > 0) {
4379 /* Has to be performed before the MDIO bus is created,
4380 * because the PHYs will link there interrupts to these
4381 * interrupt controllers
4382 */
4383 mutex_lock(&chip->reg_lock);
4384 err = mv88e6xxx_g1_irq_setup(chip);
4385 mutex_unlock(&chip->reg_lock);
4386
4387 if (err)
4388 goto out;
4389
4390 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4391 err = mv88e6xxx_g2_irq_setup(chip);
4392 if (err)
4393 goto out_g1_irq;
4394 }
4395 }
4396
Andrew Lunna3c53be52017-01-24 14:53:50 +01004397 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004398 if (err)
4399 goto out_g2_irq;
4400
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004401 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004402 if (err)
4403 goto out_mdio;
4404
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004405 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004406
4407out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004408 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004409out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004410 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004411 mv88e6xxx_g2_irq_free(chip);
4412out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004413 if (chip->irq > 0) {
4414 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004415 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004416 mutex_unlock(&chip->reg_lock);
4417 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004418out:
4419 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004420}
4421
4422static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4423{
4424 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004425 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004426
Andrew Lunn930188c2016-08-22 16:01:03 +02004427 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004428 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004429 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004430
Andrew Lunn467126442016-11-20 20:14:15 +01004431 if (chip->irq > 0) {
4432 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4433 mv88e6xxx_g2_irq_free(chip);
4434 mv88e6xxx_g1_irq_free(chip);
4435 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004436}
4437
4438static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004439 {
4440 .compatible = "marvell,mv88e6085",
4441 .data = &mv88e6xxx_table[MV88E6085],
4442 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004443 {
4444 .compatible = "marvell,mv88e6190",
4445 .data = &mv88e6xxx_table[MV88E6190],
4446 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004447 { /* sentinel */ },
4448};
4449
4450MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4451
4452static struct mdio_driver mv88e6xxx_driver = {
4453 .probe = mv88e6xxx_probe,
4454 .remove = mv88e6xxx_remove,
4455 .mdiodrv.driver = {
4456 .name = "mv88e6085",
4457 .of_match_table = mv88e6xxx_of_match,
4458 },
4459};
4460
Ben Hutchings98e67302011-11-25 14:36:19 +00004461static int __init mv88e6xxx_init(void)
4462{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004463 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004464 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004465}
4466module_init(mv88e6xxx_init);
4467
4468static void __exit mv88e6xxx_cleanup(void)
4469{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004470 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004471 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004472}
4473module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004474
4475MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4476MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4477MODULE_LICENSE("GPL");