blob: 5c1b5825fe6c4f957778178bf3944c752773dd53 [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04002 * Marvell 88e6xxx Ethernet switch single-chip support
3 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 * Copyright (c) 2008 Marvell Semiconductor
5 *
Vivien Didelotb8fee952015-08-13 12:52:19 -04006 * Copyright (c) 2015 CMC Electronics, Inc.
7 * Added support for VLAN Table Unit operations
8 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02009 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
10 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
Barry Grussling19b2f972013-01-08 16:05:54 +000017#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070018#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020019#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070020#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020021#include <linux/interrupt.h>
22#include <linux/irq.h>
23#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000024#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000025#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020026#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000027#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040028#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020029#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020030#include <linux/of_mdio.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000031#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010032#include <linux/gpio/consumer.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000033#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000034#include <net/dsa.h>
Vivien Didelot1f36faf2015-10-08 11:35:13 -040035#include <net/switchdev.h>
Vivien Didelotec561272016-09-02 14:45:33 -040036
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000037#include "mv88e6xxx.h"
Vivien Didelota935c052016-09-29 12:21:53 -040038#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040039#include "global2.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010040#include "port.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000041
Vivien Didelotfad09c72016-06-21 12:28:20 -040042static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040043{
Vivien Didelotfad09c72016-06-21 12:28:20 -040044 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
45 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040046 dump_stack();
47 }
48}
49
Vivien Didelot914b32f2016-06-20 13:14:11 -040050/* The switch ADDR[4:1] configuration pins define the chip SMI device address
51 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
52 *
53 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
54 * is the only device connected to the SMI master. In this mode it responds to
55 * all 32 possible SMI addresses, and thus maps directly the internal devices.
56 *
57 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
58 * multiple devices to share the SMI interface. In this mode it responds to only
59 * 2 registers, used to indirectly access the internal SMI devices.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000060 */
Vivien Didelot914b32f2016-06-20 13:14:11 -040061
Vivien Didelotfad09c72016-06-21 12:28:20 -040062static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040063 int addr, int reg, u16 *val)
64{
Vivien Didelotfad09c72016-06-21 12:28:20 -040065 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040066 return -EOPNOTSUPP;
67
Vivien Didelotfad09c72016-06-21 12:28:20 -040068 return chip->smi_ops->read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040069}
70
Vivien Didelotfad09c72016-06-21 12:28:20 -040071static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040072 int addr, int reg, u16 val)
73{
Vivien Didelotfad09c72016-06-21 12:28:20 -040074 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040075 return -EOPNOTSUPP;
76
Vivien Didelotfad09c72016-06-21 12:28:20 -040077 return chip->smi_ops->write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040078}
79
Vivien Didelotfad09c72016-06-21 12:28:20 -040080static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040081 int addr, int reg, u16 *val)
82{
83 int ret;
84
Vivien Didelotfad09c72016-06-21 12:28:20 -040085 ret = mdiobus_read_nested(chip->bus, addr, reg);
Vivien Didelot914b32f2016-06-20 13:14:11 -040086 if (ret < 0)
87 return ret;
88
89 *val = ret & 0xffff;
90
91 return 0;
92}
93
Vivien Didelotfad09c72016-06-21 12:28:20 -040094static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040095 int addr, int reg, u16 val)
96{
97 int ret;
98
Vivien Didelotfad09c72016-06-21 12:28:20 -040099 ret = mdiobus_write_nested(chip->bus, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400100 if (ret < 0)
101 return ret;
102
103 return 0;
104}
105
Vivien Didelotc08026a2016-09-29 12:21:59 -0400106static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400107 .read = mv88e6xxx_smi_single_chip_read,
108 .write = mv88e6xxx_smi_single_chip_write,
109};
110
Vivien Didelotfad09c72016-06-21 12:28:20 -0400111static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000112{
113 int ret;
114 int i;
115
116 for (i = 0; i < 16; i++) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400117 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000118 if (ret < 0)
119 return ret;
120
Andrew Lunncca8b132015-04-02 04:06:39 +0200121 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000122 return 0;
123 }
124
125 return -ETIMEDOUT;
126}
127
Vivien Didelotfad09c72016-06-21 12:28:20 -0400128static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400129 int addr, int reg, u16 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000130{
131 int ret;
132
Barry Grussling3675c8d2013-01-08 16:05:53 +0000133 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400134 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000135 if (ret < 0)
136 return ret;
137
Barry Grussling3675c8d2013-01-08 16:05:53 +0000138 /* Transmit the read command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400139 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Neil Armstrong6e899e62015-10-22 10:37:53 +0200140 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000141 if (ret < 0)
142 return ret;
143
Barry Grussling3675c8d2013-01-08 16:05:53 +0000144 /* Wait for the read command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400145 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000146 if (ret < 0)
147 return ret;
148
Barry Grussling3675c8d2013-01-08 16:05:53 +0000149 /* Read the data. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400150 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000151 if (ret < 0)
152 return ret;
153
Vivien Didelot914b32f2016-06-20 13:14:11 -0400154 *val = ret & 0xffff;
155
156 return 0;
157}
158
Vivien Didelotfad09c72016-06-21 12:28:20 -0400159static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400160 int addr, int reg, u16 val)
161{
162 int ret;
163
164 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400165 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400166 if (ret < 0)
167 return ret;
168
169 /* Transmit the data to write. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400170 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400171 if (ret < 0)
172 return ret;
173
174 /* Transmit the write command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400175 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400176 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
177 if (ret < 0)
178 return ret;
179
180 /* Wait for the write command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400181 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400182 if (ret < 0)
183 return ret;
184
185 return 0;
186}
187
Vivien Didelotc08026a2016-09-29 12:21:59 -0400188static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400189 .read = mv88e6xxx_smi_multi_chip_read,
190 .write = mv88e6xxx_smi_multi_chip_write,
191};
192
Vivien Didelotec561272016-09-02 14:45:33 -0400193int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400194{
195 int err;
196
Vivien Didelotfad09c72016-06-21 12:28:20 -0400197 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400198
Vivien Didelotfad09c72016-06-21 12:28:20 -0400199 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400200 if (err)
201 return err;
202
Vivien Didelotfad09c72016-06-21 12:28:20 -0400203 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400204 addr, reg, *val);
205
206 return 0;
207}
208
Vivien Didelotec561272016-09-02 14:45:33 -0400209int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400210{
211 int err;
212
Vivien Didelotfad09c72016-06-21 12:28:20 -0400213 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400214
Vivien Didelotfad09c72016-06-21 12:28:20 -0400215 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400216 if (err)
217 return err;
218
Vivien Didelotfad09c72016-06-21 12:28:20 -0400219 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400220 addr, reg, val);
221
222 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000223}
224
Andrew Lunnee26a222017-01-24 14:53:48 +0100225static int mv88e6165_phy_read(struct mv88e6xxx_chip *chip,
226 struct mii_bus *bus,
227 int addr, int reg, u16 *val)
Andrew Lunnefb3e742017-01-24 14:53:47 +0100228{
229 return mv88e6xxx_read(chip, addr, reg, val);
230}
231
Andrew Lunnee26a222017-01-24 14:53:48 +0100232static int mv88e6165_phy_write(struct mv88e6xxx_chip *chip,
233 struct mii_bus *bus,
234 int addr, int reg, u16 val)
Andrew Lunnefb3e742017-01-24 14:53:47 +0100235{
236 return mv88e6xxx_write(chip, addr, reg, val);
237}
238
Andrew Lunna3c53be52017-01-24 14:53:50 +0100239static struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
240{
241 struct mv88e6xxx_mdio_bus *mdio_bus;
242
243 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
244 list);
245 if (!mdio_bus)
246 return NULL;
247
248 return mdio_bus->bus;
249}
250
Vivien Didelote57e5e72016-08-15 17:19:00 -0400251static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
252 int reg, u16 *val)
253{
254 int addr = phy; /* PHY devices addresses start at 0x0 */
Andrew Lunna3c53be52017-01-24 14:53:50 +0100255 struct mii_bus *bus;
Vivien Didelote57e5e72016-08-15 17:19:00 -0400256
Andrew Lunna3c53be52017-01-24 14:53:50 +0100257 bus = mv88e6xxx_default_mdio_bus(chip);
258 if (!bus)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400259 return -EOPNOTSUPP;
260
Andrew Lunna3c53be52017-01-24 14:53:50 +0100261 if (!chip->info->ops->phy_read)
Andrew Lunnee26a222017-01-24 14:53:48 +0100262 return -EOPNOTSUPP;
263
264 return chip->info->ops->phy_read(chip, bus, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400265}
266
267static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
268 int reg, u16 val)
269{
270 int addr = phy; /* PHY devices addresses start at 0x0 */
Andrew Lunna3c53be52017-01-24 14:53:50 +0100271 struct mii_bus *bus;
Vivien Didelote57e5e72016-08-15 17:19:00 -0400272
Andrew Lunna3c53be52017-01-24 14:53:50 +0100273 bus = mv88e6xxx_default_mdio_bus(chip);
274 if (!bus)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400275 return -EOPNOTSUPP;
276
Andrew Lunna3c53be52017-01-24 14:53:50 +0100277 if (!chip->info->ops->phy_write)
Andrew Lunnee26a222017-01-24 14:53:48 +0100278 return -EOPNOTSUPP;
279
280 return chip->info->ops->phy_write(chip, bus, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400281}
282
Vivien Didelot09cb7df2016-08-15 17:19:01 -0400283static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
284{
285 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_PHY_PAGE))
286 return -EOPNOTSUPP;
287
288 return mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
289}
290
291static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip *chip, int phy)
292{
293 int err;
294
295 /* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
296 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, PHY_PAGE_COPPER);
297 if (unlikely(err)) {
298 dev_err(chip->dev, "failed to restore PHY %d page Copper (%d)\n",
299 phy, err);
300 }
301}
302
303static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy,
304 u8 page, int reg, u16 *val)
305{
306 int err;
307
308 /* There is no paging for registers 22 */
309 if (reg == PHY_PAGE)
310 return -EINVAL;
311
312 err = mv88e6xxx_phy_page_get(chip, phy, page);
313 if (!err) {
314 err = mv88e6xxx_phy_read(chip, phy, reg, val);
315 mv88e6xxx_phy_page_put(chip, phy);
316 }
317
318 return err;
319}
320
321static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy,
322 u8 page, int reg, u16 val)
323{
324 int err;
325
326 /* There is no paging for registers 22 */
327 if (reg == PHY_PAGE)
328 return -EINVAL;
329
330 err = mv88e6xxx_phy_page_get(chip, phy, page);
331 if (!err) {
332 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
333 mv88e6xxx_phy_page_put(chip, phy);
334 }
335
336 return err;
337}
338
339static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
340{
341 return mv88e6xxx_phy_page_read(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
342 reg, val);
343}
344
345static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
346{
347 return mv88e6xxx_phy_page_write(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
348 reg, val);
349}
350
Andrew Lunndc30c352016-10-16 19:56:49 +0200351static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
352{
353 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
354 unsigned int n = d->hwirq;
355
356 chip->g1_irq.masked |= (1 << n);
357}
358
359static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
360{
361 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
362 unsigned int n = d->hwirq;
363
364 chip->g1_irq.masked &= ~(1 << n);
365}
366
367static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
368{
369 struct mv88e6xxx_chip *chip = dev_id;
370 unsigned int nhandled = 0;
371 unsigned int sub_irq;
372 unsigned int n;
373 u16 reg;
374 int err;
375
376 mutex_lock(&chip->reg_lock);
377 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
378 mutex_unlock(&chip->reg_lock);
379
380 if (err)
381 goto out;
382
383 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
384 if (reg & (1 << n)) {
385 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
386 handle_nested_irq(sub_irq);
387 ++nhandled;
388 }
389 }
390out:
391 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
392}
393
394static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
395{
396 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
397
398 mutex_lock(&chip->reg_lock);
399}
400
401static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
402{
403 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
404 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
405 u16 reg;
406 int err;
407
408 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
409 if (err)
410 goto out;
411
412 reg &= ~mask;
413 reg |= (~chip->g1_irq.masked & mask);
414
415 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
416 if (err)
417 goto out;
418
419out:
420 mutex_unlock(&chip->reg_lock);
421}
422
423static struct irq_chip mv88e6xxx_g1_irq_chip = {
424 .name = "mv88e6xxx-g1",
425 .irq_mask = mv88e6xxx_g1_irq_mask,
426 .irq_unmask = mv88e6xxx_g1_irq_unmask,
427 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
428 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
429};
430
431static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
432 unsigned int irq,
433 irq_hw_number_t hwirq)
434{
435 struct mv88e6xxx_chip *chip = d->host_data;
436
437 irq_set_chip_data(irq, d->host_data);
438 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
439 irq_set_noprobe(irq);
440
441 return 0;
442}
443
444static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
445 .map = mv88e6xxx_g1_irq_domain_map,
446 .xlate = irq_domain_xlate_twocell,
447};
448
449static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
450{
451 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100452 u16 mask;
453
454 mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
455 mask |= GENMASK(chip->g1_irq.nirqs, 0);
456 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
457
458 free_irq(chip->irq, chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200459
Andreas Färber5edef2f2016-11-27 23:26:28 +0100460 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100461 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200462 irq_dispose_mapping(virq);
463 }
464
Andrew Lunna3db3d32016-11-20 20:14:14 +0100465 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200466}
467
468static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
469{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100470 int err, irq, virq;
471 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200472
473 chip->g1_irq.nirqs = chip->info->g1_irqs;
474 chip->g1_irq.domain = irq_domain_add_simple(
475 NULL, chip->g1_irq.nirqs, 0,
476 &mv88e6xxx_g1_irq_domain_ops, chip);
477 if (!chip->g1_irq.domain)
478 return -ENOMEM;
479
480 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
481 irq_create_mapping(chip->g1_irq.domain, irq);
482
483 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
484 chip->g1_irq.masked = ~0;
485
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100486 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200487 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100488 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200489
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100490 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200491
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100492 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200493 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100494 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200495
496 /* Reading the interrupt status clears (most of) them */
497 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
498 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100499 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200500
501 err = request_threaded_irq(chip->irq, NULL,
502 mv88e6xxx_g1_irq_thread_fn,
503 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
504 dev_name(chip->dev), chip);
505 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100506 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200507
508 return 0;
509
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100510out_disable:
511 mask |= GENMASK(chip->g1_irq.nirqs, 0);
512 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
513
514out_mapping:
515 for (irq = 0; irq < 16; irq++) {
516 virq = irq_find_mapping(chip->g1_irq.domain, irq);
517 irq_dispose_mapping(virq);
518 }
519
520 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200521
522 return err;
523}
524
Vivien Didelotec561272016-09-02 14:45:33 -0400525int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400526{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200527 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400528
Andrew Lunn6441e6692016-08-19 00:01:55 +0200529 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400530 u16 val;
531 int err;
532
533 err = mv88e6xxx_read(chip, addr, reg, &val);
534 if (err)
535 return err;
536
537 if (!(val & mask))
538 return 0;
539
540 usleep_range(1000, 2000);
541 }
542
Andrew Lunn30853552016-08-19 00:01:57 +0200543 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400544 return -ETIMEDOUT;
545}
546
Vivien Didelotf22ab642016-07-18 20:45:31 -0400547/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400548int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400549{
550 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200551 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400552
553 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200554 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
555 if (err)
556 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400557
558 /* Set the Update bit to trigger a write operation */
559 val = BIT(15) | update;
560
561 return mv88e6xxx_write(chip, addr, reg, val);
562}
563
Vivien Didelota935c052016-09-29 12:21:53 -0400564static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000565{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500566 if (!chip->info->ops->ppu_disable)
567 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000568
Vivien Didelota199d8b2016-12-05 17:30:28 -0500569 return chip->info->ops->ppu_disable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000570}
571
Vivien Didelotfad09c72016-06-21 12:28:20 -0400572static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000573{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500574 if (!chip->info->ops->ppu_enable)
575 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000576
Vivien Didelota199d8b2016-12-05 17:30:28 -0500577 return chip->info->ops->ppu_enable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000578}
579
580static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
581{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400582 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000583
Vivien Didelotfad09c72016-06-21 12:28:20 -0400584 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200585
Vivien Didelotfad09c72016-06-21 12:28:20 -0400586 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200587
Vivien Didelotfad09c72016-06-21 12:28:20 -0400588 if (mutex_trylock(&chip->ppu_mutex)) {
589 if (mv88e6xxx_ppu_enable(chip) == 0)
590 chip->ppu_disabled = 0;
591 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000592 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200593
Vivien Didelotfad09c72016-06-21 12:28:20 -0400594 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000595}
596
597static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
598{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400599 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000600
Vivien Didelotfad09c72016-06-21 12:28:20 -0400601 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000602}
603
Vivien Didelotfad09c72016-06-21 12:28:20 -0400604static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000605{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000606 int ret;
607
Vivien Didelotfad09c72016-06-21 12:28:20 -0400608 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000609
Barry Grussling3675c8d2013-01-08 16:05:53 +0000610 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000611 * we can access the PHY registers. If it was already
612 * disabled, cancel the timer that is going to re-enable
613 * it.
614 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400615 if (!chip->ppu_disabled) {
616 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000617 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400618 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000619 return ret;
620 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400621 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000622 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400623 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000624 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000625 }
626
627 return ret;
628}
629
Vivien Didelotfad09c72016-06-21 12:28:20 -0400630static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000631{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000632 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400633 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
634 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000635}
636
Vivien Didelotfad09c72016-06-21 12:28:20 -0400637static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000638{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400639 mutex_init(&chip->ppu_mutex);
640 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000641 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
642 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000643}
644
Andrew Lunn930188c2016-08-22 16:01:03 +0200645static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
646{
647 del_timer_sync(&chip->ppu_timer);
648}
649
Andrew Lunnee26a222017-01-24 14:53:48 +0100650static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip,
651 struct mii_bus *bus,
652 int addr, int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000653{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400654 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000655
Vivien Didelote57e5e72016-08-15 17:19:00 -0400656 err = mv88e6xxx_ppu_access_get(chip);
657 if (!err) {
658 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400659 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000660 }
661
Vivien Didelote57e5e72016-08-15 17:19:00 -0400662 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000663}
664
Andrew Lunnee26a222017-01-24 14:53:48 +0100665static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip,
666 struct mii_bus *bus,
667 int addr, int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000668{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400669 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000670
Vivien Didelote57e5e72016-08-15 17:19:00 -0400671 err = mv88e6xxx_ppu_access_get(chip);
672 if (!err) {
673 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400674 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000675 }
676
Vivien Didelote57e5e72016-08-15 17:19:00 -0400677 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000678}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000679
Vivien Didelotfad09c72016-06-21 12:28:20 -0400680static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200681{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400682 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200683}
684
Vivien Didelotfad09c72016-06-21 12:28:20 -0400685static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200686{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400687 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200688}
689
Vivien Didelotfad09c72016-06-21 12:28:20 -0400690static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700691{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400692 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700693}
694
Gregory CLEMENTa75961d2017-01-30 20:29:34 +0100695static bool mv88e6xxx_6341_family(struct mv88e6xxx_chip *chip)
696{
697 return chip->info->family == MV88E6XXX_FAMILY_6341;
698}
699
Vivien Didelotfad09c72016-06-21 12:28:20 -0400700static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200701{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400702 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200703}
704
Vivien Didelotfad09c72016-06-21 12:28:20 -0400705static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200706{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400707 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200708}
709
Vivien Didelotd78343d2016-11-04 03:23:36 +0100710static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
711 int link, int speed, int duplex,
712 phy_interface_t mode)
713{
714 int err;
715
716 if (!chip->info->ops->port_set_link)
717 return 0;
718
719 /* Port's MAC control must not be changed unless the link is down */
720 err = chip->info->ops->port_set_link(chip, port, 0);
721 if (err)
722 return err;
723
724 if (chip->info->ops->port_set_speed) {
725 err = chip->info->ops->port_set_speed(chip, port, speed);
726 if (err && err != -EOPNOTSUPP)
727 goto restore_link;
728 }
729
730 if (chip->info->ops->port_set_duplex) {
731 err = chip->info->ops->port_set_duplex(chip, port, duplex);
732 if (err && err != -EOPNOTSUPP)
733 goto restore_link;
734 }
735
736 if (chip->info->ops->port_set_rgmii_delay) {
737 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
738 if (err && err != -EOPNOTSUPP)
739 goto restore_link;
740 }
741
Andrew Lunnf39908d2017-02-04 20:02:50 +0100742 if (chip->info->ops->port_set_cmode) {
743 err = chip->info->ops->port_set_cmode(chip, port, mode);
744 if (err && err != -EOPNOTSUPP)
745 goto restore_link;
746 }
747
Vivien Didelotd78343d2016-11-04 03:23:36 +0100748 err = 0;
749restore_link:
750 if (chip->info->ops->port_set_link(chip, port, link))
751 netdev_err(chip->ds->ports[port].netdev,
752 "failed to restore MAC's link\n");
753
754 return err;
755}
756
Andrew Lunndea87022015-08-31 15:56:47 +0200757/* We expect the switch to perform auto negotiation if there is a real
758 * phy. However, in the case of a fixed link phy, we force the port
759 * settings from the fixed link settings.
760 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400761static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
762 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200763{
Vivien Didelot04bed142016-08-31 18:06:13 -0400764 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200765 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200766
767 if (!phy_is_pseudo_fixed_link(phydev))
768 return;
769
Vivien Didelotfad09c72016-06-21 12:28:20 -0400770 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100771 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
772 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400773 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100774
775 if (err && err != -EOPNOTSUPP)
776 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200777}
778
Andrew Lunna605a0f2016-11-21 23:26:58 +0100779static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000780{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100781 if (!chip->info->ops->stats_snapshot)
782 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000783
Andrew Lunna605a0f2016-11-21 23:26:58 +0100784 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000785}
786
Andrew Lunne413e7e2015-04-02 04:06:38 +0200787static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100788 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
789 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
790 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
791 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
792 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
793 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
794 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
795 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
796 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
797 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
798 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
799 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
800 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
801 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
802 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
803 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
804 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
805 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
806 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
807 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
808 { "single", 4, 0x14, STATS_TYPE_BANK0, },
809 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
810 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
811 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
812 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
813 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
814 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
815 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
816 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
817 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
818 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
819 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
820 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
821 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
822 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
823 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
824 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
825 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
826 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
827 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
828 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
829 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
830 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
831 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
832 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
833 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
834 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
835 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
836 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
837 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
838 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
839 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
840 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
841 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
842 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
843 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
844 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
845 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
846 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200847};
848
Vivien Didelotfad09c72016-06-21 12:28:20 -0400849static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100850 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100851 int port, u16 bank1_select,
852 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200853{
Andrew Lunn80c46272015-06-20 18:42:30 +0200854 u32 low;
855 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100856 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200857 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200858 u64 value;
859
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100860 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100861 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200862 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
863 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200864 return UINT64_MAX;
865
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200866 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200867 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200868 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
869 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200870 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200871 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200872 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100873 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100874 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100875 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100876 /* fall through */
877 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100878 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100879 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200880 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100881 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200882 }
883 value = (((u64)high) << 16) | low;
884 return value;
885}
886
Andrew Lunndfafe442016-11-21 23:27:02 +0100887static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
888 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100889{
890 struct mv88e6xxx_hw_stat *stat;
891 int i, j;
892
893 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
894 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100895 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100896 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
897 ETH_GSTRING_LEN);
898 j++;
899 }
900 }
901}
902
Andrew Lunndfafe442016-11-21 23:27:02 +0100903static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
904 uint8_t *data)
905{
906 mv88e6xxx_stats_get_strings(chip, data,
907 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
908}
909
910static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
911 uint8_t *data)
912{
913 mv88e6xxx_stats_get_strings(chip, data,
914 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
915}
916
917static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
918 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100919{
Vivien Didelot04bed142016-08-31 18:06:13 -0400920 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100921
922 if (chip->info->ops->stats_get_strings)
923 chip->info->ops->stats_get_strings(chip, data);
924}
925
926static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
927 int types)
928{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100929 struct mv88e6xxx_hw_stat *stat;
930 int i, j;
931
932 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
933 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100934 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100935 j++;
936 }
937 return j;
938}
939
Andrew Lunndfafe442016-11-21 23:27:02 +0100940static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
941{
942 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
943 STATS_TYPE_PORT);
944}
945
946static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
947{
948 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
949 STATS_TYPE_BANK1);
950}
951
952static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
953{
954 struct mv88e6xxx_chip *chip = ds->priv;
955
956 if (chip->info->ops->stats_get_sset_count)
957 return chip->info->ops->stats_get_sset_count(chip);
958
959 return 0;
960}
961
Andrew Lunn052f9472016-11-21 23:27:03 +0100962static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100963 uint64_t *data, int types,
964 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100965{
966 struct mv88e6xxx_hw_stat *stat;
967 int i, j;
968
969 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
970 stat = &mv88e6xxx_hw_stats[i];
971 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100972 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
973 bank1_select,
974 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100975 j++;
976 }
977 }
978}
979
980static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
981 uint64_t *data)
982{
983 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100984 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
985 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100986}
987
988static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
989 uint64_t *data)
990{
991 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100992 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
993 GLOBAL_STATS_OP_BANK_1_BIT_9,
994 GLOBAL_STATS_OP_HIST_RX_TX);
995}
996
997static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
998 uint64_t *data)
999{
1000 return mv88e6xxx_stats_get_stats(chip, port, data,
1001 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1002 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001003}
1004
1005static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1006 uint64_t *data)
1007{
1008 if (chip->info->ops->stats_get_stats)
1009 chip->info->ops->stats_get_stats(chip, port, data);
1010}
1011
Vivien Didelotf81ec902016-05-09 13:22:58 -04001012static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1013 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001014{
Vivien Didelot04bed142016-08-31 18:06:13 -04001015 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001016 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001017
Vivien Didelotfad09c72016-06-21 12:28:20 -04001018 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001019
Andrew Lunna605a0f2016-11-21 23:26:58 +01001020 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001021 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001022 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001023 return;
1024 }
Andrew Lunn052f9472016-11-21 23:27:03 +01001025
1026 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001027
Vivien Didelotfad09c72016-06-21 12:28:20 -04001028 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001029}
Ben Hutchings98e67302011-11-25 14:36:19 +00001030
Andrew Lunnde2273872016-11-21 23:27:01 +01001031static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1032{
1033 if (chip->info->ops->stats_set_histogram)
1034 return chip->info->ops->stats_set_histogram(chip);
1035
1036 return 0;
1037}
1038
Vivien Didelotf81ec902016-05-09 13:22:58 -04001039static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001040{
1041 return 32 * sizeof(u16);
1042}
1043
Vivien Didelotf81ec902016-05-09 13:22:58 -04001044static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1045 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001046{
Vivien Didelot04bed142016-08-31 18:06:13 -04001047 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001048 int err;
1049 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001050 u16 *p = _p;
1051 int i;
1052
1053 regs->version = 0;
1054
1055 memset(p, 0xff, 32 * sizeof(u16));
1056
Vivien Didelotfad09c72016-06-21 12:28:20 -04001057 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001058
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001059 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001060
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001061 err = mv88e6xxx_port_read(chip, port, i, &reg);
1062 if (!err)
1063 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001064 }
Vivien Didelot23062512016-05-09 13:22:45 -04001065
Vivien Didelotfad09c72016-06-21 12:28:20 -04001066 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001067}
1068
Vivien Didelotfad09c72016-06-21 12:28:20 -04001069static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001070{
Vivien Didelota935c052016-09-29 12:21:53 -04001071 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001072}
1073
Vivien Didelotf81ec902016-05-09 13:22:58 -04001074static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1075 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001076{
Vivien Didelot04bed142016-08-31 18:06:13 -04001077 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001078 u16 reg;
1079 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001080
Vivien Didelotfad09c72016-06-21 12:28:20 -04001081 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001082 return -EOPNOTSUPP;
1083
Vivien Didelotfad09c72016-06-21 12:28:20 -04001084 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001085
Vivien Didelot9c938292016-08-15 17:19:02 -04001086 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1087 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001088 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001089
1090 e->eee_enabled = !!(reg & 0x0200);
1091 e->tx_lpi_enabled = !!(reg & 0x0100);
1092
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001093 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001094 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001095 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001096
Andrew Lunncca8b132015-04-02 04:06:39 +02001097 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001098out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001099 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001100
1101 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001102}
1103
Vivien Didelotf81ec902016-05-09 13:22:58 -04001104static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1105 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001106{
Vivien Didelot04bed142016-08-31 18:06:13 -04001107 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001108 u16 reg;
1109 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001110
Vivien Didelotfad09c72016-06-21 12:28:20 -04001111 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001112 return -EOPNOTSUPP;
1113
Vivien Didelotfad09c72016-06-21 12:28:20 -04001114 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001115
Vivien Didelot9c938292016-08-15 17:19:02 -04001116 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1117 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001118 goto out;
1119
Vivien Didelot9c938292016-08-15 17:19:02 -04001120 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001121 if (e->eee_enabled)
1122 reg |= 0x0200;
1123 if (e->tx_lpi_enabled)
1124 reg |= 0x0100;
1125
Vivien Didelot9c938292016-08-15 17:19:02 -04001126 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001127out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001128 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001129
Vivien Didelot9c938292016-08-15 17:19:02 -04001130 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001131}
1132
Vivien Didelotfad09c72016-06-21 12:28:20 -04001133static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001134{
Vivien Didelota935c052016-09-29 12:21:53 -04001135 u16 val;
1136 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001137
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001138 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001139 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1140 if (err)
1141 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001142 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001143 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001144 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1145 if (err)
1146 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001147
Vivien Didelota935c052016-09-29 12:21:53 -04001148 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1149 (val & 0xfff) | ((fid << 8) & 0xf000));
1150 if (err)
1151 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001152
1153 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1154 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001155 }
1156
Vivien Didelota935c052016-09-29 12:21:53 -04001157 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1158 if (err)
1159 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001160
Vivien Didelotfad09c72016-06-21 12:28:20 -04001161 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001162}
1163
Vivien Didelotfad09c72016-06-21 12:28:20 -04001164static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001165 struct mv88e6xxx_atu_entry *entry)
1166{
1167 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1168
1169 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1170 unsigned int mask, shift;
1171
1172 if (entry->trunk) {
1173 data |= GLOBAL_ATU_DATA_TRUNK;
1174 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1175 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1176 } else {
1177 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1178 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1179 }
1180
1181 data |= (entry->portv_trunkid << shift) & mask;
1182 }
1183
Vivien Didelota935c052016-09-29 12:21:53 -04001184 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001185}
1186
Vivien Didelotfad09c72016-06-21 12:28:20 -04001187static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001188 struct mv88e6xxx_atu_entry *entry,
1189 bool static_too)
1190{
1191 int op;
1192 int err;
1193
Vivien Didelotfad09c72016-06-21 12:28:20 -04001194 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001195 if (err)
1196 return err;
1197
Vivien Didelotfad09c72016-06-21 12:28:20 -04001198 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001199 if (err)
1200 return err;
1201
1202 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001203 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1204 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1205 } else {
1206 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1207 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1208 }
1209
Vivien Didelotfad09c72016-06-21 12:28:20 -04001210 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001211}
1212
Vivien Didelotfad09c72016-06-21 12:28:20 -04001213static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001214 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001215{
1216 struct mv88e6xxx_atu_entry entry = {
1217 .fid = fid,
1218 .state = 0, /* EntryState bits must be 0 */
1219 };
1220
Vivien Didelotfad09c72016-06-21 12:28:20 -04001221 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001222}
1223
Vivien Didelotfad09c72016-06-21 12:28:20 -04001224static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001225 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001226{
1227 struct mv88e6xxx_atu_entry entry = {
1228 .trunk = false,
1229 .fid = fid,
1230 };
1231
1232 /* EntryState bits must be 0xF */
1233 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1234
1235 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1236 entry.portv_trunkid = (to_port & 0x0f) << 4;
1237 entry.portv_trunkid |= from_port & 0x0f;
1238
Vivien Didelotfad09c72016-06-21 12:28:20 -04001239 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001240}
1241
Vivien Didelotfad09c72016-06-21 12:28:20 -04001242static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001243 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001244{
1245 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001246 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001247}
1248
Vivien Didelotfad09c72016-06-21 12:28:20 -04001249static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001250{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001251 struct dsa_switch *ds = chip->ds;
Vivien Didelotfae8a252017-01-27 15:29:42 -05001252 struct net_device *bridge = ds->ports[port].bridge_dev;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001253 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001254 int i;
1255
1256 /* allow CPU port or DSA link(s) to send frames to every port */
1257 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001258 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001259 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001260 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001261 /* allow sending frames to every group member */
Vivien Didelotfae8a252017-01-27 15:29:42 -05001262 if (bridge && ds->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001263 output_ports |= BIT(i);
1264
1265 /* allow sending frames to CPU port and DSA link(s) */
1266 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1267 output_ports |= BIT(i);
1268 }
1269 }
1270
1271 /* prevent frames from going back out of the port they came in on */
1272 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001273
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001274 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001275}
1276
Vivien Didelotf81ec902016-05-09 13:22:58 -04001277static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1278 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001279{
Vivien Didelot04bed142016-08-31 18:06:13 -04001280 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001281 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001282 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001283
1284 switch (state) {
1285 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001286 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001287 break;
1288 case BR_STATE_BLOCKING:
1289 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001290 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001291 break;
1292 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001293 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001294 break;
1295 case BR_STATE_FORWARDING:
1296 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001297 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001298 break;
1299 }
1300
Vivien Didelotfad09c72016-06-21 12:28:20 -04001301 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001302 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001303 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001304
1305 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001306 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001307}
1308
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001309static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1310{
1311 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1312}
1313
Vivien Didelot749efcb2016-09-22 16:49:24 -04001314static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1315{
1316 struct mv88e6xxx_chip *chip = ds->priv;
1317 int err;
1318
1319 mutex_lock(&chip->reg_lock);
1320 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1321 mutex_unlock(&chip->reg_lock);
1322
1323 if (err)
1324 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1325}
1326
Vivien Didelotfad09c72016-06-21 12:28:20 -04001327static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001328{
Vivien Didelota935c052016-09-29 12:21:53 -04001329 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001330}
1331
Vivien Didelotfad09c72016-06-21 12:28:20 -04001332static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001333{
Vivien Didelota935c052016-09-29 12:21:53 -04001334 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001335
Vivien Didelota935c052016-09-29 12:21:53 -04001336 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1337 if (err)
1338 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001339
Vivien Didelotfad09c72016-06-21 12:28:20 -04001340 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001341}
1342
Vivien Didelotfad09c72016-06-21 12:28:20 -04001343static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001344{
1345 int ret;
1346
Vivien Didelotfad09c72016-06-21 12:28:20 -04001347 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001348 if (ret < 0)
1349 return ret;
1350
Vivien Didelotfad09c72016-06-21 12:28:20 -04001351 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001352}
1353
Vivien Didelotfad09c72016-06-21 12:28:20 -04001354static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001355 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001356 unsigned int nibble_offset)
1357{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001358 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001359 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001360
1361 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001362 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001363
Vivien Didelota935c052016-09-29 12:21:53 -04001364 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1365 if (err)
1366 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001367 }
1368
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001369 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001370 unsigned int shift = (i % 4) * 4 + nibble_offset;
1371 u16 reg = regs[i / 4];
1372
1373 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1374 }
1375
1376 return 0;
1377}
1378
Vivien Didelotfad09c72016-06-21 12:28:20 -04001379static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001380 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001381{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001382 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001383}
1384
Vivien Didelotfad09c72016-06-21 12:28:20 -04001385static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001386 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001387{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001388 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001389}
1390
Vivien Didelotfad09c72016-06-21 12:28:20 -04001391static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001392 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001393 unsigned int nibble_offset)
1394{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001395 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001396 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001397
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001398 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001399 unsigned int shift = (i % 4) * 4 + nibble_offset;
1400 u8 data = entry->data[i];
1401
1402 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1403 }
1404
1405 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001406 u16 reg = regs[i];
1407
1408 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1409 if (err)
1410 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001411 }
1412
1413 return 0;
1414}
1415
Vivien Didelotfad09c72016-06-21 12:28:20 -04001416static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001417 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001418{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001419 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001420}
1421
Vivien Didelotfad09c72016-06-21 12:28:20 -04001422static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001423 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001424{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001425 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001426}
1427
Vivien Didelotfad09c72016-06-21 12:28:20 -04001428static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001429{
Vivien Didelota935c052016-09-29 12:21:53 -04001430 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1431 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001432}
1433
Vivien Didelotfad09c72016-06-21 12:28:20 -04001434static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001435 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001436{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001437 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001438 u16 val;
1439 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001440
Vivien Didelota935c052016-09-29 12:21:53 -04001441 err = _mv88e6xxx_vtu_wait(chip);
1442 if (err)
1443 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001444
Vivien Didelota935c052016-09-29 12:21:53 -04001445 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1446 if (err)
1447 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001448
Vivien Didelota935c052016-09-29 12:21:53 -04001449 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1450 if (err)
1451 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001452
Vivien Didelota935c052016-09-29 12:21:53 -04001453 next.vid = val & GLOBAL_VTU_VID_MASK;
1454 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001455
1456 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001457 err = mv88e6xxx_vtu_data_read(chip, &next);
1458 if (err)
1459 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001460
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001461 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001462 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1463 if (err)
1464 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001465
Vivien Didelota935c052016-09-29 12:21:53 -04001466 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001467 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001468 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1469 * VTU DBNum[3:0] are located in VTU Operation 3:0
1470 */
Vivien Didelota935c052016-09-29 12:21:53 -04001471 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1472 if (err)
1473 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001474
Vivien Didelota935c052016-09-29 12:21:53 -04001475 next.fid = (val & 0xf00) >> 4;
1476 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001477 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001478
Vivien Didelotfad09c72016-06-21 12:28:20 -04001479 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001480 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1481 if (err)
1482 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001483
Vivien Didelota935c052016-09-29 12:21:53 -04001484 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001485 }
1486 }
1487
1488 *entry = next;
1489 return 0;
1490}
1491
Vivien Didelotf81ec902016-05-09 13:22:58 -04001492static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1493 struct switchdev_obj_port_vlan *vlan,
1494 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001495{
Vivien Didelot04bed142016-08-31 18:06:13 -04001496 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001497 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001498 u16 pvid;
1499 int err;
1500
Vivien Didelotfad09c72016-06-21 12:28:20 -04001501 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001502 return -EOPNOTSUPP;
1503
Vivien Didelotfad09c72016-06-21 12:28:20 -04001504 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001505
Vivien Didelot77064f32016-11-04 03:23:30 +01001506 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001507 if (err)
1508 goto unlock;
1509
Vivien Didelotfad09c72016-06-21 12:28:20 -04001510 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001511 if (err)
1512 goto unlock;
1513
1514 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001515 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001516 if (err)
1517 break;
1518
1519 if (!next.valid)
1520 break;
1521
1522 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1523 continue;
1524
1525 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001526 vlan->vid_begin = next.vid;
1527 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001528 vlan->flags = 0;
1529
1530 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1531 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1532
1533 if (next.vid == pvid)
1534 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1535
1536 err = cb(&vlan->obj);
1537 if (err)
1538 break;
1539 } while (next.vid < GLOBAL_VTU_VID_MASK);
1540
1541unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001542 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001543
1544 return err;
1545}
1546
Vivien Didelotfad09c72016-06-21 12:28:20 -04001547static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001548 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001549{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001550 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001551 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001552 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001553
Vivien Didelota935c052016-09-29 12:21:53 -04001554 err = _mv88e6xxx_vtu_wait(chip);
1555 if (err)
1556 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001557
1558 if (!entry->valid)
1559 goto loadpurge;
1560
1561 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001562 err = mv88e6xxx_vtu_data_write(chip, entry);
1563 if (err)
1564 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001565
Vivien Didelotfad09c72016-06-21 12:28:20 -04001566 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001567 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001568 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1569 if (err)
1570 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001571 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001572
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001573 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001574 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001575 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1576 if (err)
1577 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001578 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001579 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1580 * VTU DBNum[3:0] are located in VTU Operation 3:0
1581 */
1582 op |= (entry->fid & 0xf0) << 8;
1583 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001584 }
1585
1586 reg = GLOBAL_VTU_VID_VALID;
1587loadpurge:
1588 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001589 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1590 if (err)
1591 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001592
Vivien Didelotfad09c72016-06-21 12:28:20 -04001593 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001594}
1595
Vivien Didelotfad09c72016-06-21 12:28:20 -04001596static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001597 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001598{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001599 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001600 u16 val;
1601 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001602
Vivien Didelota935c052016-09-29 12:21:53 -04001603 err = _mv88e6xxx_vtu_wait(chip);
1604 if (err)
1605 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001606
Vivien Didelota935c052016-09-29 12:21:53 -04001607 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1608 sid & GLOBAL_VTU_SID_MASK);
1609 if (err)
1610 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001611
Vivien Didelota935c052016-09-29 12:21:53 -04001612 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1613 if (err)
1614 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001615
Vivien Didelota935c052016-09-29 12:21:53 -04001616 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1617 if (err)
1618 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001619
Vivien Didelota935c052016-09-29 12:21:53 -04001620 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001621
Vivien Didelota935c052016-09-29 12:21:53 -04001622 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1623 if (err)
1624 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001625
Vivien Didelota935c052016-09-29 12:21:53 -04001626 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001627
1628 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001629 err = mv88e6xxx_stu_data_read(chip, &next);
1630 if (err)
1631 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001632 }
1633
1634 *entry = next;
1635 return 0;
1636}
1637
Vivien Didelotfad09c72016-06-21 12:28:20 -04001638static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001639 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001640{
1641 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001642 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001643
Vivien Didelota935c052016-09-29 12:21:53 -04001644 err = _mv88e6xxx_vtu_wait(chip);
1645 if (err)
1646 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001647
1648 if (!entry->valid)
1649 goto loadpurge;
1650
1651 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001652 err = mv88e6xxx_stu_data_write(chip, entry);
1653 if (err)
1654 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001655
1656 reg = GLOBAL_VTU_VID_VALID;
1657loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001658 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1659 if (err)
1660 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001661
1662 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001663 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1664 if (err)
1665 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001666
Vivien Didelotfad09c72016-06-21 12:28:20 -04001667 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001668}
1669
Vivien Didelotfad09c72016-06-21 12:28:20 -04001670static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001671{
1672 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001673 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001674 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001675
1676 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1677
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001678 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001679 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001680 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001681 if (err)
1682 return err;
1683
1684 set_bit(*fid, fid_bitmap);
1685 }
1686
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001687 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001688 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001689 if (err)
1690 return err;
1691
1692 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001693 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001694 if (err)
1695 return err;
1696
1697 if (!vlan.valid)
1698 break;
1699
1700 set_bit(vlan.fid, fid_bitmap);
1701 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1702
1703 /* The reset value 0x000 is used to indicate that multiple address
1704 * databases are not needed. Return the next positive available.
1705 */
1706 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001707 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001708 return -ENOSPC;
1709
1710 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001711 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001712}
1713
Vivien Didelotfad09c72016-06-21 12:28:20 -04001714static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001715 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001716{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001717 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001718 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001719 .valid = true,
1720 .vid = vid,
1721 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001722 int i, err;
1723
Vivien Didelotfad09c72016-06-21 12:28:20 -04001724 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001725 if (err)
1726 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001727
Vivien Didelot3d131f02015-11-03 10:52:52 -05001728 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001729 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001730 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1731 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1732 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001733
Vivien Didelotfad09c72016-06-21 12:28:20 -04001734 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01001735 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip) ||
1736 mv88e6xxx_6341_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001737 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001738
1739 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1740 * implemented, only one STU entry is needed to cover all VTU
1741 * entries. Thus, validate the SID 0.
1742 */
1743 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001744 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001745 if (err)
1746 return err;
1747
1748 if (vstp.sid != vlan.sid || !vstp.valid) {
1749 memset(&vstp, 0, sizeof(vstp));
1750 vstp.valid = true;
1751 vstp.sid = vlan.sid;
1752
Vivien Didelotfad09c72016-06-21 12:28:20 -04001753 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001754 if (err)
1755 return err;
1756 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001757 }
1758
1759 *entry = vlan;
1760 return 0;
1761}
1762
Vivien Didelotfad09c72016-06-21 12:28:20 -04001763static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001764 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001765{
1766 int err;
1767
1768 if (!vid)
1769 return -EINVAL;
1770
Vivien Didelotfad09c72016-06-21 12:28:20 -04001771 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001772 if (err)
1773 return err;
1774
Vivien Didelotfad09c72016-06-21 12:28:20 -04001775 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001776 if (err)
1777 return err;
1778
1779 if (entry->vid != vid || !entry->valid) {
1780 if (!creat)
1781 return -EOPNOTSUPP;
1782 /* -ENOENT would've been more appropriate, but switchdev expects
1783 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1784 */
1785
Vivien Didelotfad09c72016-06-21 12:28:20 -04001786 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001787 }
1788
1789 return err;
1790}
1791
Vivien Didelotda9c3592016-02-12 12:09:40 -05001792static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1793 u16 vid_begin, u16 vid_end)
1794{
Vivien Didelot04bed142016-08-31 18:06:13 -04001795 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001796 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001797 int i, err;
1798
1799 if (!vid_begin)
1800 return -EOPNOTSUPP;
1801
Vivien Didelotfad09c72016-06-21 12:28:20 -04001802 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001803
Vivien Didelotfad09c72016-06-21 12:28:20 -04001804 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001805 if (err)
1806 goto unlock;
1807
1808 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001809 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001810 if (err)
1811 goto unlock;
1812
1813 if (!vlan.valid)
1814 break;
1815
1816 if (vlan.vid > vid_end)
1817 break;
1818
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001819 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001820 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1821 continue;
1822
Andrew Lunn66e28092016-12-11 21:07:19 +01001823 if (!ds->ports[port].netdev)
1824 continue;
1825
Vivien Didelotda9c3592016-02-12 12:09:40 -05001826 if (vlan.data[i] ==
1827 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1828 continue;
1829
Vivien Didelotfae8a252017-01-27 15:29:42 -05001830 if (ds->ports[i].bridge_dev ==
1831 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001832 break; /* same bridge, check next VLAN */
1833
Vivien Didelotfae8a252017-01-27 15:29:42 -05001834 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001835 continue;
1836
Andrew Lunnc8b09802016-06-04 21:16:57 +02001837 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001838 "hardware VLAN %d already used by %s\n",
1839 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001840 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001841 err = -EOPNOTSUPP;
1842 goto unlock;
1843 }
1844 } while (vlan.vid < vid_end);
1845
1846unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001847 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001848
1849 return err;
1850}
1851
Vivien Didelotf81ec902016-05-09 13:22:58 -04001852static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1853 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001854{
Vivien Didelot04bed142016-08-31 18:06:13 -04001855 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001856 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001857 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001858 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001859
Vivien Didelotfad09c72016-06-21 12:28:20 -04001860 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001861 return -EOPNOTSUPP;
1862
Vivien Didelotfad09c72016-06-21 12:28:20 -04001863 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001864 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001865 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001866
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001867 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001868}
1869
Vivien Didelot57d32312016-06-20 13:13:58 -04001870static int
1871mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1872 const struct switchdev_obj_port_vlan *vlan,
1873 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001874{
Vivien Didelot04bed142016-08-31 18:06:13 -04001875 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001876 int err;
1877
Vivien Didelotfad09c72016-06-21 12:28:20 -04001878 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001879 return -EOPNOTSUPP;
1880
Vivien Didelotda9c3592016-02-12 12:09:40 -05001881 /* If the requested port doesn't belong to the same bridge as the VLAN
1882 * members, do not support it (yet) and fallback to software VLAN.
1883 */
1884 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1885 vlan->vid_end);
1886 if (err)
1887 return err;
1888
Vivien Didelot76e398a2015-11-01 12:33:55 -05001889 /* We don't need any dynamic resource from the kernel (yet),
1890 * so skip the prepare phase.
1891 */
1892 return 0;
1893}
1894
Vivien Didelotfad09c72016-06-21 12:28:20 -04001895static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001896 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001897{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001898 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001899 int err;
1900
Vivien Didelotfad09c72016-06-21 12:28:20 -04001901 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001902 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001903 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001904
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001905 vlan.data[port] = untagged ?
1906 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1907 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1908
Vivien Didelotfad09c72016-06-21 12:28:20 -04001909 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001910}
1911
Vivien Didelotf81ec902016-05-09 13:22:58 -04001912static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1913 const struct switchdev_obj_port_vlan *vlan,
1914 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001915{
Vivien Didelot04bed142016-08-31 18:06:13 -04001916 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001917 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1918 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1919 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001920
Vivien Didelotfad09c72016-06-21 12:28:20 -04001921 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001922 return;
1923
Vivien Didelotfad09c72016-06-21 12:28:20 -04001924 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001925
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001926 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001927 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001928 netdev_err(ds->ports[port].netdev,
1929 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001930 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001931
Vivien Didelot77064f32016-11-04 03:23:30 +01001932 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001933 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001934 vlan->vid_end);
1935
Vivien Didelotfad09c72016-06-21 12:28:20 -04001936 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001937}
1938
Vivien Didelotfad09c72016-06-21 12:28:20 -04001939static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001940 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001941{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001942 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001943 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001944 int i, err;
1945
Vivien Didelotfad09c72016-06-21 12:28:20 -04001946 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001947 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001948 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001949
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001950 /* Tell switchdev if this VLAN is handled in software */
1951 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001952 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001953
1954 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1955
1956 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001957 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001958 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001959 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001960 continue;
1961
1962 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001963 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001964 break;
1965 }
1966 }
1967
Vivien Didelotfad09c72016-06-21 12:28:20 -04001968 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001969 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001970 return err;
1971
Vivien Didelotfad09c72016-06-21 12:28:20 -04001972 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001973}
1974
Vivien Didelotf81ec902016-05-09 13:22:58 -04001975static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1976 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001977{
Vivien Didelot04bed142016-08-31 18:06:13 -04001978 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001979 u16 pvid, vid;
1980 int err = 0;
1981
Vivien Didelotfad09c72016-06-21 12:28:20 -04001982 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001983 return -EOPNOTSUPP;
1984
Vivien Didelotfad09c72016-06-21 12:28:20 -04001985 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001986
Vivien Didelot77064f32016-11-04 03:23:30 +01001987 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001988 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001989 goto unlock;
1990
Vivien Didelot76e398a2015-11-01 12:33:55 -05001991 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001992 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001993 if (err)
1994 goto unlock;
1995
1996 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001997 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001998 if (err)
1999 goto unlock;
2000 }
2001 }
2002
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002003unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002004 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002005
2006 return err;
2007}
2008
Vivien Didelotfad09c72016-06-21 12:28:20 -04002009static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04002010 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002011{
Vivien Didelota935c052016-09-29 12:21:53 -04002012 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002013
2014 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002015 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
2016 (addr[i * 2] << 8) | addr[i * 2 + 1]);
2017 if (err)
2018 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002019 }
2020
2021 return 0;
2022}
2023
Vivien Didelotfad09c72016-06-21 12:28:20 -04002024static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04002025 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002026{
Vivien Didelota935c052016-09-29 12:21:53 -04002027 u16 val;
2028 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002029
2030 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002031 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
2032 if (err)
2033 return err;
2034
2035 addr[i * 2] = val >> 8;
2036 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002037 }
2038
2039 return 0;
2040}
2041
Vivien Didelotfad09c72016-06-21 12:28:20 -04002042static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04002043 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002044{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002045 int ret;
2046
Vivien Didelotfad09c72016-06-21 12:28:20 -04002047 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002048 if (ret < 0)
2049 return ret;
2050
Vivien Didelotfad09c72016-06-21 12:28:20 -04002051 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002052 if (ret < 0)
2053 return ret;
2054
Vivien Didelotfad09c72016-06-21 12:28:20 -04002055 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002056 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002057 return ret;
2058
Vivien Didelotfad09c72016-06-21 12:28:20 -04002059 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002060}
David S. Millercdf09692015-08-11 12:00:37 -07002061
Vivien Didelot88472932016-09-19 19:56:11 -04002062static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2063 struct mv88e6xxx_atu_entry *entry);
2064
2065static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2066 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2067{
2068 struct mv88e6xxx_atu_entry next;
2069 int err;
2070
Andrew Lunn59527582017-01-04 19:56:24 +01002071 memcpy(next.mac, addr, ETH_ALEN);
2072 eth_addr_dec(next.mac);
Vivien Didelot88472932016-09-19 19:56:11 -04002073
2074 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2075 if (err)
2076 return err;
2077
2078 do {
2079 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2080 if (err)
2081 return err;
2082
2083 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2084 break;
2085
2086 if (ether_addr_equal(next.mac, addr)) {
2087 *entry = next;
2088 return 0;
2089 }
Andrew Lunn59527582017-01-04 19:56:24 +01002090 } while (ether_addr_greater(addr, next.mac));
Vivien Didelot88472932016-09-19 19:56:11 -04002091
2092 memset(entry, 0, sizeof(*entry));
2093 entry->fid = fid;
2094 ether_addr_copy(entry->mac, addr);
2095
2096 return 0;
2097}
2098
Vivien Didelot83dabd12016-08-31 11:50:04 -04002099static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2100 const unsigned char *addr, u16 vid,
2101 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002102{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002103 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002104 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002105 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002106
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002107 /* Null VLAN ID corresponds to the port private database */
2108 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002109 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002110 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002111 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002112 if (err)
2113 return err;
2114
Vivien Didelot88472932016-09-19 19:56:11 -04002115 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2116 if (err)
2117 return err;
2118
2119 /* Purge the ATU entry only if no port is using it anymore */
2120 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2121 entry.portv_trunkid &= ~BIT(port);
2122 if (!entry.portv_trunkid)
2123 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2124 } else {
2125 entry.portv_trunkid |= BIT(port);
2126 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002127 }
2128
Vivien Didelotfad09c72016-06-21 12:28:20 -04002129 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002130}
2131
Vivien Didelotf81ec902016-05-09 13:22:58 -04002132static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2133 const struct switchdev_obj_port_fdb *fdb,
2134 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002135{
2136 /* We don't need any dynamic resource from the kernel (yet),
2137 * so skip the prepare phase.
2138 */
2139 return 0;
2140}
2141
Vivien Didelotf81ec902016-05-09 13:22:58 -04002142static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2143 const struct switchdev_obj_port_fdb *fdb,
2144 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002145{
Vivien Didelot04bed142016-08-31 18:06:13 -04002146 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002147
Vivien Didelotfad09c72016-06-21 12:28:20 -04002148 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002149 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2150 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2151 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002152 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002153}
2154
Vivien Didelotf81ec902016-05-09 13:22:58 -04002155static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2156 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002157{
Vivien Didelot04bed142016-08-31 18:06:13 -04002158 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002159 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002160
Vivien Didelotfad09c72016-06-21 12:28:20 -04002161 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002162 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2163 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002164 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002165
Vivien Didelot83dabd12016-08-31 11:50:04 -04002166 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002167}
2168
Vivien Didelotfad09c72016-06-21 12:28:20 -04002169static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002170 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002171{
Vivien Didelot1d194042015-08-10 09:09:51 -04002172 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002173 u16 val;
2174 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002175
2176 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002177
Vivien Didelota935c052016-09-29 12:21:53 -04002178 err = _mv88e6xxx_atu_wait(chip);
2179 if (err)
2180 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002181
Vivien Didelota935c052016-09-29 12:21:53 -04002182 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2183 if (err)
2184 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002185
Vivien Didelota935c052016-09-29 12:21:53 -04002186 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2187 if (err)
2188 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002189
Vivien Didelota935c052016-09-29 12:21:53 -04002190 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2191 if (err)
2192 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002193
Vivien Didelota935c052016-09-29 12:21:53 -04002194 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002195 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2196 unsigned int mask, shift;
2197
Vivien Didelota935c052016-09-29 12:21:53 -04002198 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002199 next.trunk = true;
2200 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2201 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2202 } else {
2203 next.trunk = false;
2204 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2205 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2206 }
2207
Vivien Didelota935c052016-09-29 12:21:53 -04002208 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002209 }
2210
2211 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002212 return 0;
2213}
2214
Vivien Didelot83dabd12016-08-31 11:50:04 -04002215static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2216 u16 fid, u16 vid, int port,
2217 struct switchdev_obj *obj,
2218 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002219{
2220 struct mv88e6xxx_atu_entry addr = {
2221 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2222 };
2223 int err;
2224
Vivien Didelotfad09c72016-06-21 12:28:20 -04002225 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002226 if (err)
2227 return err;
2228
2229 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002230 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002231 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002232 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002233
2234 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2235 break;
2236
Vivien Didelot83dabd12016-08-31 11:50:04 -04002237 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2238 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002239
Vivien Didelot83dabd12016-08-31 11:50:04 -04002240 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2241 struct switchdev_obj_port_fdb *fdb;
2242
2243 if (!is_unicast_ether_addr(addr.mac))
2244 continue;
2245
2246 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002247 fdb->vid = vid;
2248 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002249 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2250 fdb->ndm_state = NUD_NOARP;
2251 else
2252 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002253 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2254 struct switchdev_obj_port_mdb *mdb;
2255
2256 if (!is_multicast_ether_addr(addr.mac))
2257 continue;
2258
2259 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2260 mdb->vid = vid;
2261 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002262 } else {
2263 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002264 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002265
2266 err = cb(obj);
2267 if (err)
2268 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002269 } while (!is_broadcast_ether_addr(addr.mac));
2270
2271 return err;
2272}
2273
Vivien Didelot83dabd12016-08-31 11:50:04 -04002274static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2275 struct switchdev_obj *obj,
2276 int (*cb)(struct switchdev_obj *obj))
2277{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002278 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002279 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2280 };
2281 u16 fid;
2282 int err;
2283
2284 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002285 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002286 if (err)
2287 return err;
2288
2289 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2290 if (err)
2291 return err;
2292
2293 /* Dump VLANs' Filtering Information Databases */
2294 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2295 if (err)
2296 return err;
2297
2298 do {
2299 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2300 if (err)
2301 return err;
2302
2303 if (!vlan.valid)
2304 break;
2305
2306 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2307 obj, cb);
2308 if (err)
2309 return err;
2310 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2311
2312 return err;
2313}
2314
Vivien Didelotf81ec902016-05-09 13:22:58 -04002315static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2316 struct switchdev_obj_port_fdb *fdb,
2317 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002318{
Vivien Didelot04bed142016-08-31 18:06:13 -04002319 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002320 int err;
2321
Vivien Didelotfad09c72016-06-21 12:28:20 -04002322 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002323 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002324 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002325
2326 return err;
2327}
2328
Vivien Didelotf81ec902016-05-09 13:22:58 -04002329static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002330 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002331{
Vivien Didelot04bed142016-08-31 18:06:13 -04002332 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002333 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002334
Vivien Didelotfad09c72016-06-21 12:28:20 -04002335 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002336
Vivien Didelotfae8a252017-01-27 15:29:42 -05002337 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002338 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfae8a252017-01-27 15:29:42 -05002339 if (ds->ports[i].bridge_dev == br) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002340 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002341 if (err)
2342 break;
2343 }
2344 }
2345
Vivien Didelotfad09c72016-06-21 12:28:20 -04002346 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002347
Vivien Didelot466dfa02016-02-26 13:16:05 -05002348 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002349}
2350
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002351static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2352 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002353{
Vivien Didelot04bed142016-08-31 18:06:13 -04002354 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002355 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002356
Vivien Didelotfad09c72016-06-21 12:28:20 -04002357 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002358
Vivien Didelotfae8a252017-01-27 15:29:42 -05002359 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002360 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfae8a252017-01-27 15:29:42 -05002361 if (i == port || ds->ports[i].bridge_dev == br)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002362 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002363 netdev_warn(ds->ports[i].netdev,
2364 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002365
Vivien Didelotfad09c72016-06-21 12:28:20 -04002366 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002367}
2368
Vivien Didelot17e708b2016-12-05 17:30:27 -05002369static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2370{
2371 if (chip->info->ops->reset)
2372 return chip->info->ops->reset(chip);
2373
2374 return 0;
2375}
2376
Vivien Didelot309eca62016-12-05 17:30:26 -05002377static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2378{
2379 struct gpio_desc *gpiod = chip->reset;
2380
2381 /* If there is a GPIO connected to the reset pin, toggle it */
2382 if (gpiod) {
2383 gpiod_set_value_cansleep(gpiod, 1);
2384 usleep_range(10000, 20000);
2385 gpiod_set_value_cansleep(gpiod, 0);
2386 usleep_range(10000, 20000);
2387 }
2388}
2389
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002390static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2391{
2392 int i, err;
2393
2394 /* Set all ports to the Disabled state */
2395 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2396 err = mv88e6xxx_port_set_state(chip, i,
2397 PORT_CONTROL_STATE_DISABLED);
2398 if (err)
2399 return err;
2400 }
2401
2402 /* Wait for transmit queues to drain,
2403 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2404 */
2405 usleep_range(2000, 4000);
2406
2407 return 0;
2408}
2409
Vivien Didelotfad09c72016-06-21 12:28:20 -04002410static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002411{
Vivien Didelota935c052016-09-29 12:21:53 -04002412 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002413
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002414 err = mv88e6xxx_disable_ports(chip);
2415 if (err)
2416 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002417
Vivien Didelot309eca62016-12-05 17:30:26 -05002418 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002419
Vivien Didelot17e708b2016-12-05 17:30:27 -05002420 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002421}
2422
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002423static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002424{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002425 u16 val;
2426 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002427
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002428 /* Clear Power Down bit */
2429 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2430 if (err)
2431 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002432
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002433 if (val & BMCR_PDOWN) {
2434 val &= ~BMCR_PDOWN;
2435 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002436 }
2437
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002438 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002439}
2440
Andrew Lunn56995cb2016-12-03 04:35:19 +01002441static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2442 int upstream_port)
2443{
2444 int err;
2445
2446 err = chip->info->ops->port_set_frame_mode(
2447 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2448 if (err)
2449 return err;
2450
2451 return chip->info->ops->port_set_egress_unknowns(
2452 chip, port, port == upstream_port);
2453}
2454
2455static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2456{
2457 int err;
2458
2459 switch (chip->info->tag_protocol) {
2460 case DSA_TAG_PROTO_EDSA:
2461 err = chip->info->ops->port_set_frame_mode(
2462 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2463 if (err)
2464 return err;
2465
2466 err = mv88e6xxx_port_set_egress_mode(
2467 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2468 if (err)
2469 return err;
2470
2471 if (chip->info->ops->port_set_ether_type)
2472 err = chip->info->ops->port_set_ether_type(
2473 chip, port, ETH_P_EDSA);
2474 break;
2475
2476 case DSA_TAG_PROTO_DSA:
2477 err = chip->info->ops->port_set_frame_mode(
2478 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2479 if (err)
2480 return err;
2481
2482 err = mv88e6xxx_port_set_egress_mode(
2483 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2484 break;
2485 default:
2486 err = -EINVAL;
2487 }
2488
2489 if (err)
2490 return err;
2491
2492 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2493}
2494
2495static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2496{
2497 int err;
2498
2499 err = chip->info->ops->port_set_frame_mode(
2500 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2501 if (err)
2502 return err;
2503
2504 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2505}
2506
Vivien Didelotea698f42017-03-11 16:12:50 -05002507static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2508{
2509 bool message = dsa_is_dsa_port(chip->ds, port);
2510
2511 return mv88e6xxx_port_set_message_port(chip, port, message);
2512}
2513
Vivien Didelotfad09c72016-06-21 12:28:20 -04002514static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002515{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002516 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002517 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002518 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002519
Vivien Didelotd78343d2016-11-04 03:23:36 +01002520 /* MAC Forcing register: don't force link, speed, duplex or flow control
2521 * state to any particular values on physical ports, but force the CPU
2522 * port and all DSA ports to their maximum bandwidth and full duplex.
2523 */
2524 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2525 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2526 SPEED_MAX, DUPLEX_FULL,
2527 PHY_INTERFACE_MODE_NA);
2528 else
2529 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2530 SPEED_UNFORCED, DUPLEX_UNFORCED,
2531 PHY_INTERFACE_MODE_NA);
2532 if (err)
2533 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002534
2535 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2536 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2537 * tunneling, determine priority by looking at 802.1p and IP
2538 * priority fields (IP prio has precedence), and set STP state
2539 * to Forwarding.
2540 *
2541 * If this is the CPU link, use DSA or EDSA tagging depending
2542 * on which tagging mode was configured.
2543 *
2544 * If this is a link to another switch, use DSA tagging mode.
2545 *
2546 * If this is the upstream port for this switch, enable
2547 * forwarding of unknown unicasts and multicasts.
2548 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002549 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002550 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2551 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002552 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2553 if (err)
2554 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002555
Andrew Lunn56995cb2016-12-03 04:35:19 +01002556 if (dsa_is_cpu_port(ds, port)) {
2557 err = mv88e6xxx_setup_port_cpu(chip, port);
2558 } else if (dsa_is_dsa_port(ds, port)) {
2559 err = mv88e6xxx_setup_port_dsa(chip, port,
2560 dsa_upstream_port(ds));
2561 } else {
2562 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002563 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002564 if (err)
2565 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002566
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002567 /* If this port is connected to a SerDes, make sure the SerDes is not
2568 * powered down.
2569 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002570 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002571 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2572 if (err)
2573 return err;
2574 reg &= PORT_STATUS_CMODE_MASK;
2575 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2576 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2577 (reg == PORT_STATUS_CMODE_SGMII)) {
2578 err = mv88e6xxx_serdes_power_on(chip);
2579 if (err < 0)
2580 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002581 }
2582 }
2583
Vivien Didelot8efdda42015-08-13 12:52:23 -04002584 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002585 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002586 * untagged frames on this port, do a destination address lookup on all
2587 * received packets as usual, disable ARP mirroring and don't send a
2588 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002589 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002590 err = mv88e6xxx_port_set_map_da(chip, port);
2591 if (err)
2592 return err;
2593
Andrew Lunn54d792f2015-05-06 01:09:47 +02002594 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01002595 if (chip->info->ops->port_set_upstream_port) {
2596 err = chip->info->ops->port_set_upstream_port(
2597 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002598 if (err)
2599 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002600 }
2601
Andrew Lunna23b2962017-02-04 20:15:28 +01002602 err = mv88e6xxx_port_set_8021q_mode(chip, port,
2603 PORT_CONTROL_2_8021Q_DISABLED);
2604 if (err)
2605 return err;
2606
Andrew Lunn5f436662016-12-03 04:45:17 +01002607 if (chip->info->ops->port_jumbo_config) {
2608 err = chip->info->ops->port_jumbo_config(chip, port);
2609 if (err)
2610 return err;
2611 }
2612
Andrew Lunn54d792f2015-05-06 01:09:47 +02002613 /* Port Association Vector: when learning source addresses
2614 * of packets, add the address to the address database using
2615 * a port bitmap that has only the bit for this port set and
2616 * the other bits clear.
2617 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002618 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002619 /* Disable learning for CPU port */
2620 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002621 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002622
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002623 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2624 if (err)
2625 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002626
2627 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002628 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2629 if (err)
2630 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002631
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002632 if (chip->info->ops->port_pause_config) {
2633 err = chip->info->ops->port_pause_config(chip, port);
2634 if (err)
2635 return err;
2636 }
2637
Vivien Didelotfad09c72016-06-21 12:28:20 -04002638 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2639 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01002640 mv88e6xxx_6320_family(chip) || mv88e6xxx_6341_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002641 /* Port ATU control: disable limiting the number of
2642 * address database entries that this port is allowed
2643 * to use.
2644 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002645 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2646 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002647 /* Priority Override: disable DA, SA and VTU priority
2648 * override.
2649 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002650 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2651 0x0000);
2652 if (err)
2653 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002654 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002655
Andrew Lunnef0a7312016-12-03 04:35:16 +01002656 if (chip->info->ops->port_tag_remap) {
2657 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002658 if (err)
2659 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002660 }
2661
Andrew Lunnef70b112016-12-03 04:45:18 +01002662 if (chip->info->ops->port_egress_rate_limiting) {
2663 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002664 if (err)
2665 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002666 }
2667
Vivien Didelotea698f42017-03-11 16:12:50 -05002668 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002669 if (err)
2670 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002671
Vivien Didelot207afda2016-04-14 14:42:09 -04002672 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002673 * database, and allow bidirectional communication between the
2674 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002675 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002676 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002677 if (err)
2678 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002679
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002680 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2681 if (err)
2682 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002683
2684 /* Default VLAN ID and priority: don't set a default VLAN
2685 * ID, and set the default packet priority to zero.
2686 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002687 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002688}
2689
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002690static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002691{
2692 int err;
2693
Vivien Didelota935c052016-09-29 12:21:53 -04002694 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002695 if (err)
2696 return err;
2697
Vivien Didelota935c052016-09-29 12:21:53 -04002698 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002699 if (err)
2700 return err;
2701
Vivien Didelota935c052016-09-29 12:21:53 -04002702 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2703 if (err)
2704 return err;
2705
2706 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002707}
2708
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002709static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2710 unsigned int ageing_time)
2711{
Vivien Didelot04bed142016-08-31 18:06:13 -04002712 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002713 int err;
2714
2715 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002716 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002717 mutex_unlock(&chip->reg_lock);
2718
2719 return err;
2720}
2721
Vivien Didelot97299342016-07-18 20:45:30 -04002722static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002723{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002724 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002725 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002726 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002727
Vivien Didelot119477b2016-05-09 13:22:51 -04002728 /* Enable the PHY Polling Unit if present, don't discard any packets,
2729 * and mask all interrupt sources.
2730 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002731 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002732 if (err)
2733 return err;
2734
Andrew Lunn33641992016-12-03 04:35:17 +01002735 if (chip->info->ops->g1_set_cpu_port) {
2736 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2737 if (err)
2738 return err;
2739 }
2740
2741 if (chip->info->ops->g1_set_egress_port) {
2742 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2743 if (err)
2744 return err;
2745 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002746
Vivien Didelot50484ff2016-05-09 13:22:54 -04002747 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002748 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2749 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2750 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002751 if (err)
2752 return err;
2753
Vivien Didelotacddbd22016-07-18 20:45:39 -04002754 /* Clear all the VTU and STU entries */
2755 err = _mv88e6xxx_vtu_stu_flush(chip);
2756 if (err < 0)
2757 return err;
2758
Vivien Didelot08a01262016-05-09 13:22:50 -04002759 /* Set the default address aging time to 5 minutes, and
2760 * enable address learn messages to be sent to all message
2761 * ports.
2762 */
Vivien Didelota935c052016-09-29 12:21:53 -04002763 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2764 GLOBAL_ATU_CONTROL_LEARN2ALL);
Vivien Didelot08a01262016-05-09 13:22:50 -04002765 if (err)
2766 return err;
2767
Vivien Didelot97299342016-07-18 20:45:30 -04002768 /* Clear all ATU entries */
2769 err = _mv88e6xxx_atu_flush(chip, 0, true);
2770 if (err)
2771 return err;
2772
Vivien Didelot08a01262016-05-09 13:22:50 -04002773 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002774 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002775 if (err)
2776 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002777 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002778 if (err)
2779 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002780 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002781 if (err)
2782 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002783 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002784 if (err)
2785 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002786 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002787 if (err)
2788 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002789 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002790 if (err)
2791 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002792 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002793 if (err)
2794 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002795 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002796 if (err)
2797 return err;
2798
2799 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002800 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002801 if (err)
2802 return err;
2803
Andrew Lunnde2273872016-11-21 23:27:01 +01002804 /* Initialize the statistics unit */
2805 err = mv88e6xxx_stats_set_histogram(chip);
2806 if (err)
2807 return err;
2808
Vivien Didelot97299342016-07-18 20:45:30 -04002809 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002810 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2811 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002812 if (err)
2813 return err;
2814
2815 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002816 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002817 if (err)
2818 return err;
2819
2820 return 0;
2821}
2822
Vivien Didelotf81ec902016-05-09 13:22:58 -04002823static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002824{
Vivien Didelot04bed142016-08-31 18:06:13 -04002825 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002826 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002827 int i;
2828
Vivien Didelotfad09c72016-06-21 12:28:20 -04002829 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002830 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002831
Vivien Didelotfad09c72016-06-21 12:28:20 -04002832 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002833
Vivien Didelot97299342016-07-18 20:45:30 -04002834 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002835 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002836 err = mv88e6xxx_setup_port(chip, i);
2837 if (err)
2838 goto unlock;
2839 }
2840
2841 /* Setup Switch Global 1 Registers */
2842 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002843 if (err)
2844 goto unlock;
2845
Vivien Didelot97299342016-07-18 20:45:30 -04002846 /* Setup Switch Global 2 Registers */
2847 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2848 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002849 if (err)
2850 goto unlock;
2851 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002852
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002853 err = mv88e6xxx_atu_setup(chip);
2854 if (err)
2855 goto unlock;
2856
Andrew Lunn6e55f692016-12-03 04:45:16 +01002857 /* Some generations have the configuration of sending reserved
2858 * management frames to the CPU in global2, others in
2859 * global1. Hence it does not fit the two setup functions
2860 * above.
2861 */
2862 if (chip->info->ops->mgmt_rsvd2cpu) {
2863 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2864 if (err)
2865 goto unlock;
2866 }
2867
Vivien Didelot6b17e862015-08-13 12:52:18 -04002868unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002869 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002870
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002871 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002872}
2873
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002874static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2875{
Vivien Didelot04bed142016-08-31 18:06:13 -04002876 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002877 int err;
2878
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002879 if (!chip->info->ops->set_switch_mac)
2880 return -EOPNOTSUPP;
2881
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002882 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002883 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002884 mutex_unlock(&chip->reg_lock);
2885
2886 return err;
2887}
2888
Vivien Didelote57e5e72016-08-15 17:19:00 -04002889static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002890{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002891 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2892 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002893 u16 val;
2894 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002895
Andrew Lunnee26a222017-01-24 14:53:48 +01002896 if (!chip->info->ops->phy_read)
2897 return -EOPNOTSUPP;
2898
Vivien Didelotfad09c72016-06-21 12:28:20 -04002899 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002900 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002901 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002902
Andrew Lunnda9f3302017-02-01 03:40:05 +01002903 if (reg == MII_PHYSID2) {
2904 /* Some internal PHYS don't have a model number. Use
2905 * the mv88e6390 family model number instead.
2906 */
2907 if (!(val & 0x3f0))
2908 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2909 }
2910
Vivien Didelote57e5e72016-08-15 17:19:00 -04002911 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002912}
2913
Vivien Didelote57e5e72016-08-15 17:19:00 -04002914static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002915{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002916 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2917 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002918 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002919
Andrew Lunnee26a222017-01-24 14:53:48 +01002920 if (!chip->info->ops->phy_write)
2921 return -EOPNOTSUPP;
2922
Vivien Didelotfad09c72016-06-21 12:28:20 -04002923 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002924 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002925 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002926
2927 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002928}
2929
Vivien Didelotfad09c72016-06-21 12:28:20 -04002930static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002931 struct device_node *np,
2932 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002933{
2934 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002935 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002936 struct mii_bus *bus;
2937 int err;
2938
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002939 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002940 if (!bus)
2941 return -ENOMEM;
2942
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002943 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002944 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002945 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002946 INIT_LIST_HEAD(&mdio_bus->list);
2947 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002948
Andrew Lunnb516d452016-06-04 21:17:06 +02002949 if (np) {
2950 bus->name = np->full_name;
2951 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2952 } else {
2953 bus->name = "mv88e6xxx SMI";
2954 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2955 }
2956
2957 bus->read = mv88e6xxx_mdio_read;
2958 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002959 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002960
Andrew Lunna3c53be52017-01-24 14:53:50 +01002961 if (np)
2962 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002963 else
2964 err = mdiobus_register(bus);
2965 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002966 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002967 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002968 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002969
2970 if (external)
2971 list_add_tail(&mdio_bus->list, &chip->mdios);
2972 else
2973 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002974
2975 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002976}
2977
Andrew Lunna3c53be52017-01-24 14:53:50 +01002978static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2979 { .compatible = "marvell,mv88e6xxx-mdio-external",
2980 .data = (void *)true },
2981 { },
2982};
2983
2984static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2985 struct device_node *np)
2986{
2987 const struct of_device_id *match;
2988 struct device_node *child;
2989 int err;
2990
2991 /* Always register one mdio bus for the internal/default mdio
2992 * bus. This maybe represented in the device tree, but is
2993 * optional.
2994 */
2995 child = of_get_child_by_name(np, "mdio");
2996 err = mv88e6xxx_mdio_register(chip, child, false);
2997 if (err)
2998 return err;
2999
3000 /* Walk the device tree, and see if there are any other nodes
3001 * which say they are compatible with the external mdio
3002 * bus.
3003 */
3004 for_each_available_child_of_node(np, child) {
3005 match = of_match_node(mv88e6xxx_mdio_external_match, child);
3006 if (match) {
3007 err = mv88e6xxx_mdio_register(chip, child, true);
3008 if (err)
3009 return err;
3010 }
3011 }
3012
3013 return 0;
3014}
3015
3016static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02003017
3018{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003019 struct mv88e6xxx_mdio_bus *mdio_bus;
3020 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003021
Andrew Lunna3c53be52017-01-24 14:53:50 +01003022 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3023 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003024
Andrew Lunna3c53be52017-01-24 14:53:50 +01003025 mdiobus_unregister(bus);
3026 }
Andrew Lunnb516d452016-06-04 21:17:06 +02003027}
3028
Vivien Didelot855b1932016-07-20 18:18:35 -04003029static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3030{
Vivien Didelot04bed142016-08-31 18:06:13 -04003031 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003032
3033 return chip->eeprom_len;
3034}
3035
Vivien Didelot855b1932016-07-20 18:18:35 -04003036static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3037 struct ethtool_eeprom *eeprom, u8 *data)
3038{
Vivien Didelot04bed142016-08-31 18:06:13 -04003039 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003040 int err;
3041
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003042 if (!chip->info->ops->get_eeprom)
3043 return -EOPNOTSUPP;
3044
Vivien Didelot855b1932016-07-20 18:18:35 -04003045 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003046 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003047 mutex_unlock(&chip->reg_lock);
3048
3049 if (err)
3050 return err;
3051
3052 eeprom->magic = 0xc3ec4951;
3053
3054 return 0;
3055}
3056
Vivien Didelot855b1932016-07-20 18:18:35 -04003057static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3058 struct ethtool_eeprom *eeprom, u8 *data)
3059{
Vivien Didelot04bed142016-08-31 18:06:13 -04003060 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003061 int err;
3062
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003063 if (!chip->info->ops->set_eeprom)
3064 return -EOPNOTSUPP;
3065
Vivien Didelot855b1932016-07-20 18:18:35 -04003066 if (eeprom->magic != 0xc3ec4951)
3067 return -EINVAL;
3068
3069 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003070 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003071 mutex_unlock(&chip->reg_lock);
3072
3073 return err;
3074}
3075
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003076static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003077 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003078 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003079 .phy_read = mv88e6xxx_phy_ppu_read,
3080 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003081 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003082 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003083 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003084 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003085 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3086 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3087 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003088 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003089 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003090 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003091 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3092 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003093 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003094 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3095 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003096 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003097 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003098 .ppu_enable = mv88e6185_g1_ppu_enable,
3099 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003100 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003101};
3102
3103static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003104 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003105 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003106 .phy_read = mv88e6xxx_phy_ppu_read,
3107 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003108 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003109 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003110 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003111 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01003112 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
3113 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003114 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003115 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3116 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003117 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003118 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003119 .ppu_enable = mv88e6185_g1_ppu_enable,
3120 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003121 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003122};
3123
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003124static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003125 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003126 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3127 .phy_read = mv88e6xxx_g2_smi_phy_read,
3128 .phy_write = mv88e6xxx_g2_smi_phy_write,
3129 .port_set_link = mv88e6xxx_port_set_link,
3130 .port_set_duplex = mv88e6xxx_port_set_duplex,
3131 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003132 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003133 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3134 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3135 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003136 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003137 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003138 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003139 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3140 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3141 .stats_get_strings = mv88e6095_stats_get_strings,
3142 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003143 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3144 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003145 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003146 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003147 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003148};
3149
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003150static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003151 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003152 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003153 .phy_read = mv88e6165_phy_read,
3154 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003155 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003156 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003157 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003158 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3159 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003160 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003161 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3162 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003163 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003164 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3165 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003166 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003167 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003168 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003169};
3170
3171static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003172 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003173 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003174 .phy_read = mv88e6xxx_phy_ppu_read,
3175 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003176 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003177 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003178 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003179 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003180 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01003181 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003182 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003183 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01003184 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003185 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003186 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003187 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003188 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3189 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003190 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003191 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3192 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003193 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003194 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003195 .ppu_enable = mv88e6185_g1_ppu_enable,
3196 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003197 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003198};
3199
3200static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003201 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003202 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003203 .phy_read = mv88e6165_phy_read,
3204 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003205 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003206 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003207 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003208 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003209 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3210 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3211 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003212 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003213 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003214 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003215 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003216 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3217 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003218 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003219 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3220 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003221 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003222 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003223 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003224};
3225
3226static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003227 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003228 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003229 .phy_read = mv88e6165_phy_read,
3230 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003231 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003232 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003233 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003234 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003235 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3236 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003237 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003238 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3239 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003240 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003241 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003242 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003243};
3244
3245static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003246 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003247 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003248 .phy_read = mv88e6xxx_g2_smi_phy_read,
3249 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003250 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003251 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003252 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003253 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003254 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003255 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3256 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3257 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003258 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003259 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003260 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003261 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003262 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3263 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003264 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003265 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3266 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003267 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003268 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003269 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003270};
3271
3272static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003273 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003274 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3275 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003276 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003277 .phy_read = mv88e6xxx_g2_smi_phy_read,
3278 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003279 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003280 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003281 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003282 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003283 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003284 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3285 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3286 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003287 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003288 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003289 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003290 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003291 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3292 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003293 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003294 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3295 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003296 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003297 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003298 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003299};
3300
3301static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003302 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003303 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003304 .phy_read = mv88e6xxx_g2_smi_phy_read,
3305 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003306 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003307 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003308 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003309 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003310 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003311 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3312 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3313 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003314 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003315 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003316 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003317 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003318 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3319 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003320 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003321 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3322 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003323 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003324 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003325 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003326};
3327
3328static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003329 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003330 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3331 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003332 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003333 .phy_read = mv88e6xxx_g2_smi_phy_read,
3334 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003335 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003336 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003337 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003338 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003339 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003340 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3341 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3342 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003343 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003344 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003345 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003346 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003347 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3348 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003349 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003350 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3351 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003352 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003353 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003354 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003355};
3356
3357static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003358 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003359 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003360 .phy_read = mv88e6xxx_phy_ppu_read,
3361 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003362 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003363 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003364 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003365 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01003366 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003367 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003368 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003369 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003370 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3371 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003372 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003373 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3374 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003375 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003376 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003377 .ppu_enable = mv88e6185_g1_ppu_enable,
3378 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003379 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003380};
3381
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003382static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003383 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003384 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3385 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003386 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3387 .phy_read = mv88e6xxx_g2_smi_phy_read,
3388 .phy_write = mv88e6xxx_g2_smi_phy_write,
3389 .port_set_link = mv88e6xxx_port_set_link,
3390 .port_set_duplex = mv88e6xxx_port_set_duplex,
3391 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3392 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003393 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003394 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3395 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3396 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003397 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003398 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003399 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003400 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3401 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003402 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003403 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3404 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003405 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003406 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003407 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003408};
3409
3410static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003411 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003412 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3413 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003414 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3415 .phy_read = mv88e6xxx_g2_smi_phy_read,
3416 .phy_write = mv88e6xxx_g2_smi_phy_write,
3417 .port_set_link = mv88e6xxx_port_set_link,
3418 .port_set_duplex = mv88e6xxx_port_set_duplex,
3419 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3420 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003421 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003422 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3423 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3424 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003425 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003426 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003427 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003428 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3429 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003430 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003431 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3432 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003433 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003434 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003435 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003436};
3437
3438static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003439 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003440 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3441 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003442 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3443 .phy_read = mv88e6xxx_g2_smi_phy_read,
3444 .phy_write = mv88e6xxx_g2_smi_phy_write,
3445 .port_set_link = mv88e6xxx_port_set_link,
3446 .port_set_duplex = mv88e6xxx_port_set_duplex,
3447 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3448 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003449 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003450 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3451 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3452 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003453 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003454 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003455 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003456 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3457 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003458 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003459 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3460 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003461 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003462 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003463 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003464};
3465
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003466static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003467 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003468 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3469 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003470 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003471 .phy_read = mv88e6xxx_g2_smi_phy_read,
3472 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003473 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003474 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003475 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003476 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003477 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003478 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3479 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3480 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003481 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003482 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003483 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003484 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003485 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3486 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003487 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003488 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3489 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003490 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003491 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003492 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003493};
3494
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003495static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003496 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003497 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3498 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003499 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3500 .phy_read = mv88e6xxx_g2_smi_phy_read,
3501 .phy_write = mv88e6xxx_g2_smi_phy_write,
3502 .port_set_link = mv88e6xxx_port_set_link,
3503 .port_set_duplex = mv88e6xxx_port_set_duplex,
3504 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3505 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003506 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003507 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3508 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3509 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003510 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003511 .port_set_cmode = mv88e6390x_port_set_cmode,
Andrew Lunn79523472016-11-21 23:27:00 +01003512 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003513 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003514 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3515 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003516 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003517 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3518 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003519 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003520 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003521 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003522};
3523
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003524static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003525 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003526 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3527 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003528 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003529 .phy_read = mv88e6xxx_g2_smi_phy_read,
3530 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003531 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003532 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003533 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003534 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003535 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3536 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3537 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003538 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003539 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003540 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003541 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003542 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3543 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003544 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003545 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3546 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003547 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003548 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003549};
3550
3551static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003552 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003553 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3554 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003555 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003556 .phy_read = mv88e6xxx_g2_smi_phy_read,
3557 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003558 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003559 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003560 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003561 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003562 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3563 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3564 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003565 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003566 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003567 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003568 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003569 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3570 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003571 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003572 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3573 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003574 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003575};
3576
3577static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003578 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003579 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003580 .phy_read = mv88e6xxx_g2_smi_phy_read,
3581 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003582 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003583 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003584 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003585 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003586 .port_tag_remap = mv88e6095_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 Lunnb35d322a2016-12-03 04:45:19 +01003592 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003593 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003594 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3595 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003596 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003597 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3598 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003599 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003600 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003601 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003602};
3603
3604static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003605 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003606 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003607 .phy_read = mv88e6xxx_g2_smi_phy_read,
3608 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003609 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003610 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003611 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003612 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003613 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003614 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3615 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3616 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003617 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003618 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003619 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003620 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003621 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3622 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003623 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003624 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3625 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003626 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003627 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003628 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003629};
3630
3631static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003632 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003633 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3634 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003635 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003636 .phy_read = mv88e6xxx_g2_smi_phy_read,
3637 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003638 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003639 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003640 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003641 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003642 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003643 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3644 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3645 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003646 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003647 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003648 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003649 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003650 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3651 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003652 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003653 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3654 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003655 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003656 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003657 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003658};
3659
Gregory CLEMENT15587272017-01-30 20:29:35 +01003660static const struct mv88e6xxx_ops mv88e6141_ops = {
3661 /* MV88E6XXX_FAMILY_6341 */
3662 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3663 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3664 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3665 .phy_read = mv88e6xxx_g2_smi_phy_read,
3666 .phy_write = mv88e6xxx_g2_smi_phy_write,
3667 .port_set_link = mv88e6xxx_port_set_link,
3668 .port_set_duplex = mv88e6xxx_port_set_duplex,
3669 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3670 .port_set_speed = mv88e6390_port_set_speed,
3671 .port_tag_remap = mv88e6095_port_tag_remap,
3672 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3673 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3674 .port_set_ether_type = mv88e6351_port_set_ether_type,
3675 .port_jumbo_config = mv88e6165_port_jumbo_config,
3676 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3677 .port_pause_config = mv88e6097_port_pause_config,
3678 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3679 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3680 .stats_get_strings = mv88e6320_stats_get_strings,
3681 .stats_get_stats = mv88e6390_stats_get_stats,
3682 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3683 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003684 .watchdog_ops = &mv88e6390_watchdog_ops,
Gregory CLEMENT15587272017-01-30 20:29:35 +01003685 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3686 .reset = mv88e6352_g1_reset,
3687};
3688
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003689static const struct mv88e6xxx_ops mv88e6341_ops = {
3690 /* MV88E6XXX_FAMILY_6341 */
3691 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3692 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3693 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3694 .phy_read = mv88e6xxx_g2_smi_phy_read,
3695 .phy_write = mv88e6xxx_g2_smi_phy_write,
3696 .port_set_link = mv88e6xxx_port_set_link,
3697 .port_set_duplex = mv88e6xxx_port_set_duplex,
3698 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3699 .port_set_speed = mv88e6390_port_set_speed,
3700 .port_tag_remap = mv88e6095_port_tag_remap,
3701 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3702 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3703 .port_set_ether_type = mv88e6351_port_set_ether_type,
3704 .port_jumbo_config = mv88e6165_port_jumbo_config,
3705 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3706 .port_pause_config = mv88e6097_port_pause_config,
3707 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3708 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3709 .stats_get_strings = mv88e6320_stats_get_strings,
3710 .stats_get_stats = mv88e6390_stats_get_stats,
3711 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3712 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003713 .watchdog_ops = &mv88e6390_watchdog_ops,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003714 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3715 .reset = mv88e6352_g1_reset,
3716};
3717
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003718static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003719 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003720 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3721 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003722 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3723 .phy_read = mv88e6xxx_g2_smi_phy_read,
3724 .phy_write = mv88e6xxx_g2_smi_phy_write,
3725 .port_set_link = mv88e6xxx_port_set_link,
3726 .port_set_duplex = mv88e6xxx_port_set_duplex,
3727 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3728 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003729 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003730 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3731 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3732 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003733 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003734 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003735 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003736 .port_set_cmode = mv88e6390x_port_set_cmode,
Andrew Lunn79523472016-11-21 23:27:00 +01003737 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003738 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003739 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3740 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003741 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003742 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3743 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003744 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003745 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003746 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003747};
3748
3749static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003750 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003751 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3752 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003753 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3754 .phy_read = mv88e6xxx_g2_smi_phy_read,
3755 .phy_write = mv88e6xxx_g2_smi_phy_write,
3756 .port_set_link = mv88e6xxx_port_set_link,
3757 .port_set_duplex = mv88e6xxx_port_set_duplex,
3758 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3759 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003760 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003761 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3762 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3763 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003764 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003765 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003766 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003767 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003768 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003769 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3770 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003771 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003772 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3773 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003774 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003775 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003776 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003777};
3778
3779static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003780 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003781 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3782 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003783 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3784 .phy_read = mv88e6xxx_g2_smi_phy_read,
3785 .phy_write = mv88e6xxx_g2_smi_phy_write,
3786 .port_set_link = mv88e6xxx_port_set_link,
3787 .port_set_duplex = mv88e6xxx_port_set_duplex,
3788 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3789 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003790 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003791 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3792 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3793 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003794 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003795 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003796 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003797 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3798 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003799 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003800 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3801 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003802 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003803 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003804 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003805};
3806
Andrew Lunn56995cb2016-12-03 04:35:19 +01003807static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3808 const struct mv88e6xxx_ops *ops)
3809{
3810 if (!ops->port_set_frame_mode) {
3811 dev_err(chip->dev, "Missing port_set_frame_mode");
3812 return -EINVAL;
3813 }
3814
3815 if (!ops->port_set_egress_unknowns) {
3816 dev_err(chip->dev, "Missing port_set_egress_mode");
3817 return -EINVAL;
3818 }
3819
3820 return 0;
3821}
3822
Vivien Didelotf81ec902016-05-09 13:22:58 -04003823static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3824 [MV88E6085] = {
3825 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3826 .family = MV88E6XXX_FAMILY_6097,
3827 .name = "Marvell 88E6085",
3828 .num_databases = 4096,
3829 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003830 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003831 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003832 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003833 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003834 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003835 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003836 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003837 },
3838
3839 [MV88E6095] = {
3840 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3841 .family = MV88E6XXX_FAMILY_6095,
3842 .name = "Marvell 88E6095/88E6095F",
3843 .num_databases = 256,
3844 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003845 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003846 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003847 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003848 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003849 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003850 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003851 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003852 },
3853
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003854 [MV88E6097] = {
3855 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3856 .family = MV88E6XXX_FAMILY_6097,
3857 .name = "Marvell 88E6097/88E6097F",
3858 .num_databases = 4096,
3859 .num_ports = 11,
3860 .port_base_addr = 0x10,
3861 .global1_addr = 0x1b,
3862 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003863 .g1_irqs = 8,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003864 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003865 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3866 .ops = &mv88e6097_ops,
3867 },
3868
Vivien Didelotf81ec902016-05-09 13:22:58 -04003869 [MV88E6123] = {
3870 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3871 .family = MV88E6XXX_FAMILY_6165,
3872 .name = "Marvell 88E6123",
3873 .num_databases = 4096,
3874 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003875 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003876 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003877 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003878 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003879 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003880 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003881 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003882 },
3883
3884 [MV88E6131] = {
3885 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3886 .family = MV88E6XXX_FAMILY_6185,
3887 .name = "Marvell 88E6131",
3888 .num_databases = 256,
3889 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003890 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003891 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003892 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003893 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003894 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003895 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003896 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003897 },
3898
3899 [MV88E6161] = {
3900 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3901 .family = MV88E6XXX_FAMILY_6165,
3902 .name = "Marvell 88E6161",
3903 .num_databases = 4096,
3904 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003905 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003906 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003907 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003908 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003909 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003910 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003911 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003912 },
3913
3914 [MV88E6165] = {
3915 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3916 .family = MV88E6XXX_FAMILY_6165,
3917 .name = "Marvell 88E6165",
3918 .num_databases = 4096,
3919 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003920 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003921 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003922 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003923 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003924 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003925 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003926 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003927 },
3928
3929 [MV88E6171] = {
3930 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3931 .family = MV88E6XXX_FAMILY_6351,
3932 .name = "Marvell 88E6171",
3933 .num_databases = 4096,
3934 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003935 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003936 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003937 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003938 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003939 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003940 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003941 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003942 },
3943
3944 [MV88E6172] = {
3945 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3946 .family = MV88E6XXX_FAMILY_6352,
3947 .name = "Marvell 88E6172",
3948 .num_databases = 4096,
3949 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003950 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003951 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003952 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003953 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003954 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003955 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003956 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003957 },
3958
3959 [MV88E6175] = {
3960 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3961 .family = MV88E6XXX_FAMILY_6351,
3962 .name = "Marvell 88E6175",
3963 .num_databases = 4096,
3964 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003965 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003966 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003967 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003968 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003969 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003970 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003971 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003972 },
3973
3974 [MV88E6176] = {
3975 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3976 .family = MV88E6XXX_FAMILY_6352,
3977 .name = "Marvell 88E6176",
3978 .num_databases = 4096,
3979 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003980 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003981 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003982 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003983 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003984 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003985 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003986 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003987 },
3988
3989 [MV88E6185] = {
3990 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3991 .family = MV88E6XXX_FAMILY_6185,
3992 .name = "Marvell 88E6185",
3993 .num_databases = 256,
3994 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003995 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003996 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003997 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003998 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003999 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004000 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004001 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004002 },
4003
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004004 [MV88E6190] = {
4005 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
4006 .family = MV88E6XXX_FAMILY_6390,
4007 .name = "Marvell 88E6190",
4008 .num_databases = 4096,
4009 .num_ports = 11, /* 10 + Z80 */
4010 .port_base_addr = 0x0,
4011 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004012 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004013 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004014 .g1_irqs = 9,
4015 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4016 .ops = &mv88e6190_ops,
4017 },
4018
4019 [MV88E6190X] = {
4020 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
4021 .family = MV88E6XXX_FAMILY_6390,
4022 .name = "Marvell 88E6190X",
4023 .num_databases = 4096,
4024 .num_ports = 11, /* 10 + Z80 */
4025 .port_base_addr = 0x0,
4026 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004027 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004028 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004029 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004030 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4031 .ops = &mv88e6190x_ops,
4032 },
4033
4034 [MV88E6191] = {
4035 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
4036 .family = MV88E6XXX_FAMILY_6390,
4037 .name = "Marvell 88E6191",
4038 .num_databases = 4096,
4039 .num_ports = 11, /* 10 + Z80 */
4040 .port_base_addr = 0x0,
4041 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004042 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004043 .g1_irqs = 9,
4044 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004045 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4046 .ops = &mv88e6391_ops,
4047 },
4048
Vivien Didelotf81ec902016-05-09 13:22:58 -04004049 [MV88E6240] = {
4050 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
4051 .family = MV88E6XXX_FAMILY_6352,
4052 .name = "Marvell 88E6240",
4053 .num_databases = 4096,
4054 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004055 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004056 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004057 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004058 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004059 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004060 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004061 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004062 },
4063
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004064 [MV88E6290] = {
4065 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
4066 .family = MV88E6XXX_FAMILY_6390,
4067 .name = "Marvell 88E6290",
4068 .num_databases = 4096,
4069 .num_ports = 11, /* 10 + Z80 */
4070 .port_base_addr = 0x0,
4071 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004072 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004073 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004074 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004075 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4076 .ops = &mv88e6290_ops,
4077 },
4078
Vivien Didelotf81ec902016-05-09 13:22:58 -04004079 [MV88E6320] = {
4080 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
4081 .family = MV88E6XXX_FAMILY_6320,
4082 .name = "Marvell 88E6320",
4083 .num_databases = 4096,
4084 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004085 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004086 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004087 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004088 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004089 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004090 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004091 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004092 },
4093
4094 [MV88E6321] = {
4095 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
4096 .family = MV88E6XXX_FAMILY_6320,
4097 .name = "Marvell 88E6321",
4098 .num_databases = 4096,
4099 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004100 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004101 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004102 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004103 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004104 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004105 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004106 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004107 },
4108
Gregory CLEMENT15587272017-01-30 20:29:35 +01004109 [MV88E6141] = {
4110 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
4111 .family = MV88E6XXX_FAMILY_6341,
4112 .name = "Marvell 88E6341",
4113 .num_databases = 4096,
4114 .num_ports = 6,
4115 .port_base_addr = 0x10,
4116 .global1_addr = 0x1b,
4117 .age_time_coeff = 3750,
4118 .tag_protocol = DSA_TAG_PROTO_EDSA,
4119 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
4120 .ops = &mv88e6141_ops,
4121 },
4122
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004123 [MV88E6341] = {
4124 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
4125 .family = MV88E6XXX_FAMILY_6341,
4126 .name = "Marvell 88E6341",
4127 .num_databases = 4096,
4128 .num_ports = 6,
4129 .port_base_addr = 0x10,
4130 .global1_addr = 0x1b,
4131 .age_time_coeff = 3750,
4132 .tag_protocol = DSA_TAG_PROTO_EDSA,
4133 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
4134 .ops = &mv88e6341_ops,
4135 },
4136
Vivien Didelotf81ec902016-05-09 13:22:58 -04004137 [MV88E6350] = {
4138 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
4139 .family = MV88E6XXX_FAMILY_6351,
4140 .name = "Marvell 88E6350",
4141 .num_databases = 4096,
4142 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004143 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004144 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004145 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004146 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004147 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004148 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004149 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004150 },
4151
4152 [MV88E6351] = {
4153 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4154 .family = MV88E6XXX_FAMILY_6351,
4155 .name = "Marvell 88E6351",
4156 .num_databases = 4096,
4157 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004158 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004159 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004160 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004161 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004162 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004163 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004164 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004165 },
4166
4167 [MV88E6352] = {
4168 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4169 .family = MV88E6XXX_FAMILY_6352,
4170 .name = "Marvell 88E6352",
4171 .num_databases = 4096,
4172 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004173 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004174 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004175 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004176 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004177 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004178 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004179 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004180 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004181 [MV88E6390] = {
4182 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4183 .family = MV88E6XXX_FAMILY_6390,
4184 .name = "Marvell 88E6390",
4185 .num_databases = 4096,
4186 .num_ports = 11, /* 10 + Z80 */
4187 .port_base_addr = 0x0,
4188 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004189 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004190 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004191 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004192 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4193 .ops = &mv88e6390_ops,
4194 },
4195 [MV88E6390X] = {
4196 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4197 .family = MV88E6XXX_FAMILY_6390,
4198 .name = "Marvell 88E6390X",
4199 .num_databases = 4096,
4200 .num_ports = 11, /* 10 + Z80 */
4201 .port_base_addr = 0x0,
4202 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004203 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004204 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004205 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004206 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4207 .ops = &mv88e6390x_ops,
4208 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004209};
4210
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004211static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004212{
Vivien Didelota439c062016-04-17 13:23:58 -04004213 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004214
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004215 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4216 if (mv88e6xxx_table[i].prod_num == prod_num)
4217 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004218
Vivien Didelotb9b37712015-10-30 19:39:48 -04004219 return NULL;
4220}
4221
Vivien Didelotfad09c72016-06-21 12:28:20 -04004222static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004223{
4224 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004225 unsigned int prod_num, rev;
4226 u16 id;
4227 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004228
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004229 mutex_lock(&chip->reg_lock);
4230 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4231 mutex_unlock(&chip->reg_lock);
4232 if (err)
4233 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004234
4235 prod_num = (id & 0xfff0) >> 4;
4236 rev = id & 0x000f;
4237
4238 info = mv88e6xxx_lookup_info(prod_num);
4239 if (!info)
4240 return -ENODEV;
4241
Vivien Didelotcaac8542016-06-20 13:14:09 -04004242 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004243 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004244
Vivien Didelotca070c12016-09-02 14:45:34 -04004245 err = mv88e6xxx_g2_require(chip);
4246 if (err)
4247 return err;
4248
Vivien Didelotfad09c72016-06-21 12:28:20 -04004249 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4250 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004251
4252 return 0;
4253}
4254
Vivien Didelotfad09c72016-06-21 12:28:20 -04004255static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004256{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004257 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004258
Vivien Didelotfad09c72016-06-21 12:28:20 -04004259 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4260 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004261 return NULL;
4262
Vivien Didelotfad09c72016-06-21 12:28:20 -04004263 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004264
Vivien Didelotfad09c72016-06-21 12:28:20 -04004265 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004266 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004267
Vivien Didelotfad09c72016-06-21 12:28:20 -04004268 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004269}
4270
Vivien Didelote57e5e72016-08-15 17:19:00 -04004271static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4272{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004273 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004274 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004275}
4276
Andrew Lunn930188c2016-08-22 16:01:03 +02004277static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4278{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004279 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004280 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004281}
4282
Vivien Didelotfad09c72016-06-21 12:28:20 -04004283static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004284 struct mii_bus *bus, int sw_addr)
4285{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004286 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004287 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004288 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004289 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004290 else
4291 return -EINVAL;
4292
Vivien Didelotfad09c72016-06-21 12:28:20 -04004293 chip->bus = bus;
4294 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004295
4296 return 0;
4297}
4298
Andrew Lunn7b314362016-08-22 16:01:01 +02004299static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4300{
Vivien Didelot04bed142016-08-31 18:06:13 -04004301 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004302
Andrew Lunn443d5a12016-12-03 04:35:18 +01004303 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004304}
4305
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004306static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4307 struct device *host_dev, int sw_addr,
4308 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004309{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004310 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004311 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004312 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004313
Vivien Didelota439c062016-04-17 13:23:58 -04004314 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004315 if (!bus)
4316 return NULL;
4317
Vivien Didelotfad09c72016-06-21 12:28:20 -04004318 chip = mv88e6xxx_alloc_chip(dsa_dev);
4319 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004320 return NULL;
4321
Vivien Didelotcaac8542016-06-20 13:14:09 -04004322 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004323 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004324
Vivien Didelotfad09c72016-06-21 12:28:20 -04004325 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004326 if (err)
4327 goto free;
4328
Vivien Didelotfad09c72016-06-21 12:28:20 -04004329 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004330 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004331 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004332
Andrew Lunndc30c352016-10-16 19:56:49 +02004333 mutex_lock(&chip->reg_lock);
4334 err = mv88e6xxx_switch_reset(chip);
4335 mutex_unlock(&chip->reg_lock);
4336 if (err)
4337 goto free;
4338
Vivien Didelote57e5e72016-08-15 17:19:00 -04004339 mv88e6xxx_phy_init(chip);
4340
Andrew Lunna3c53be52017-01-24 14:53:50 +01004341 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004342 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004343 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004344
Vivien Didelotfad09c72016-06-21 12:28:20 -04004345 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004346
Vivien Didelotfad09c72016-06-21 12:28:20 -04004347 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004348free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004349 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004350
4351 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004352}
4353
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004354static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4355 const struct switchdev_obj_port_mdb *mdb,
4356 struct switchdev_trans *trans)
4357{
4358 /* We don't need any dynamic resource from the kernel (yet),
4359 * so skip the prepare phase.
4360 */
4361
4362 return 0;
4363}
4364
4365static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4366 const struct switchdev_obj_port_mdb *mdb,
4367 struct switchdev_trans *trans)
4368{
Vivien Didelot04bed142016-08-31 18:06:13 -04004369 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004370
4371 mutex_lock(&chip->reg_lock);
4372 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4373 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4374 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4375 mutex_unlock(&chip->reg_lock);
4376}
4377
4378static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4379 const struct switchdev_obj_port_mdb *mdb)
4380{
Vivien Didelot04bed142016-08-31 18:06:13 -04004381 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004382 int err;
4383
4384 mutex_lock(&chip->reg_lock);
4385 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4386 GLOBAL_ATU_DATA_STATE_UNUSED);
4387 mutex_unlock(&chip->reg_lock);
4388
4389 return err;
4390}
4391
4392static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4393 struct switchdev_obj_port_mdb *mdb,
4394 int (*cb)(struct switchdev_obj *obj))
4395{
Vivien Didelot04bed142016-08-31 18:06:13 -04004396 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004397 int err;
4398
4399 mutex_lock(&chip->reg_lock);
4400 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4401 mutex_unlock(&chip->reg_lock);
4402
4403 return err;
4404}
4405
Florian Fainellia82f67a2017-01-08 14:52:08 -08004406static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004407 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004408 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004409 .setup = mv88e6xxx_setup,
4410 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004411 .adjust_link = mv88e6xxx_adjust_link,
4412 .get_strings = mv88e6xxx_get_strings,
4413 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4414 .get_sset_count = mv88e6xxx_get_sset_count,
4415 .set_eee = mv88e6xxx_set_eee,
4416 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004417 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004418 .get_eeprom = mv88e6xxx_get_eeprom,
4419 .set_eeprom = mv88e6xxx_set_eeprom,
4420 .get_regs_len = mv88e6xxx_get_regs_len,
4421 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004422 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004423 .port_bridge_join = mv88e6xxx_port_bridge_join,
4424 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4425 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004426 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004427 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4428 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4429 .port_vlan_add = mv88e6xxx_port_vlan_add,
4430 .port_vlan_del = mv88e6xxx_port_vlan_del,
4431 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4432 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4433 .port_fdb_add = mv88e6xxx_port_fdb_add,
4434 .port_fdb_del = mv88e6xxx_port_fdb_del,
4435 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004436 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4437 .port_mdb_add = mv88e6xxx_port_mdb_add,
4438 .port_mdb_del = mv88e6xxx_port_mdb_del,
4439 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004440};
4441
Florian Fainelliab3d4082017-01-08 14:52:07 -08004442static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4443 .ops = &mv88e6xxx_switch_ops,
4444};
4445
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004446static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004447{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004448 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004449 struct dsa_switch *ds;
4450
Vivien Didelota0c02162017-01-27 15:29:36 -05004451 ds = dsa_switch_alloc(dev, DSA_MAX_PORTS);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004452 if (!ds)
4453 return -ENOMEM;
4454
Vivien Didelotfad09c72016-06-21 12:28:20 -04004455 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004456 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004457
4458 dev_set_drvdata(dev, ds);
4459
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004460 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004461}
4462
Vivien Didelotfad09c72016-06-21 12:28:20 -04004463static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004464{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004465 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004466}
4467
Vivien Didelot57d32312016-06-20 13:13:58 -04004468static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004469{
4470 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004471 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004472 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004473 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004474 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004475 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004476
Vivien Didelotcaac8542016-06-20 13:14:09 -04004477 compat_info = of_device_get_match_data(dev);
4478 if (!compat_info)
4479 return -EINVAL;
4480
Vivien Didelotfad09c72016-06-21 12:28:20 -04004481 chip = mv88e6xxx_alloc_chip(dev);
4482 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004483 return -ENOMEM;
4484
Vivien Didelotfad09c72016-06-21 12:28:20 -04004485 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004486
Andrew Lunn56995cb2016-12-03 04:35:19 +01004487 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4488 if (err)
4489 return err;
4490
Vivien Didelotfad09c72016-06-21 12:28:20 -04004491 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004492 if (err)
4493 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004494
Andrew Lunnb4308f02016-11-21 23:26:55 +01004495 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4496 if (IS_ERR(chip->reset))
4497 return PTR_ERR(chip->reset);
4498
Vivien Didelotfad09c72016-06-21 12:28:20 -04004499 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004500 if (err)
4501 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004502
Vivien Didelote57e5e72016-08-15 17:19:00 -04004503 mv88e6xxx_phy_init(chip);
4504
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004505 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004506 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004507 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004508
Andrew Lunndc30c352016-10-16 19:56:49 +02004509 mutex_lock(&chip->reg_lock);
4510 err = mv88e6xxx_switch_reset(chip);
4511 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004512 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004513 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004514
Andrew Lunndc30c352016-10-16 19:56:49 +02004515 chip->irq = of_irq_get(np, 0);
4516 if (chip->irq == -EPROBE_DEFER) {
4517 err = chip->irq;
4518 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004519 }
4520
Andrew Lunndc30c352016-10-16 19:56:49 +02004521 if (chip->irq > 0) {
4522 /* Has to be performed before the MDIO bus is created,
4523 * because the PHYs will link there interrupts to these
4524 * interrupt controllers
4525 */
4526 mutex_lock(&chip->reg_lock);
4527 err = mv88e6xxx_g1_irq_setup(chip);
4528 mutex_unlock(&chip->reg_lock);
4529
4530 if (err)
4531 goto out;
4532
4533 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4534 err = mv88e6xxx_g2_irq_setup(chip);
4535 if (err)
4536 goto out_g1_irq;
4537 }
4538 }
4539
Andrew Lunna3c53be52017-01-24 14:53:50 +01004540 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004541 if (err)
4542 goto out_g2_irq;
4543
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004544 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004545 if (err)
4546 goto out_mdio;
4547
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004548 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004549
4550out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004551 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004552out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004553 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004554 mv88e6xxx_g2_irq_free(chip);
4555out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004556 if (chip->irq > 0) {
4557 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004558 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004559 mutex_unlock(&chip->reg_lock);
4560 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004561out:
4562 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004563}
4564
4565static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4566{
4567 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004568 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004569
Andrew Lunn930188c2016-08-22 16:01:03 +02004570 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004571 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004572 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004573
Andrew Lunn467126442016-11-20 20:14:15 +01004574 if (chip->irq > 0) {
4575 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4576 mv88e6xxx_g2_irq_free(chip);
4577 mv88e6xxx_g1_irq_free(chip);
4578 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004579}
4580
4581static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004582 {
4583 .compatible = "marvell,mv88e6085",
4584 .data = &mv88e6xxx_table[MV88E6085],
4585 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004586 {
4587 .compatible = "marvell,mv88e6190",
4588 .data = &mv88e6xxx_table[MV88E6190],
4589 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004590 { /* sentinel */ },
4591};
4592
4593MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4594
4595static struct mdio_driver mv88e6xxx_driver = {
4596 .probe = mv88e6xxx_probe,
4597 .remove = mv88e6xxx_remove,
4598 .mdiodrv.driver = {
4599 .name = "mv88e6085",
4600 .of_match_table = mv88e6xxx_of_match,
4601 },
4602};
4603
Ben Hutchings98e67302011-11-25 14:36:19 +00004604static int __init mv88e6xxx_init(void)
4605{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004606 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004607 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004608}
4609module_init(mv88e6xxx_init);
4610
4611static void __exit mv88e6xxx_cleanup(void)
4612{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004613 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004614 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004615}
4616module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004617
4618MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4619MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4620MODULE_LICENSE("GPL");