blob: 1ee0c05f624e8ffd1217f9ea619e4d704e63b2a0 [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04002 * Marvell 88e6xxx Ethernet switch single-chip support
3 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 * Copyright (c) 2008 Marvell Semiconductor
5 *
Vivien Didelotb8fee952015-08-13 12:52:19 -04006 * Copyright (c) 2015 CMC Electronics, Inc.
7 * Added support for VLAN Table Unit operations
8 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02009 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
10 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
Barry Grussling19b2f972013-01-08 16:05:54 +000017#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070018#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020019#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070020#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020021#include <linux/interrupt.h>
22#include <linux/irq.h>
23#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000024#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000025#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020026#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000027#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040028#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020029#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020030#include <linux/of_mdio.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000031#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010032#include <linux/gpio/consumer.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000033#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000034#include <net/dsa.h>
Vivien Didelot1f36faf2015-10-08 11:35:13 -040035#include <net/switchdev.h>
Vivien Didelotec561272016-09-02 14:45:33 -040036
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000037#include "mv88e6xxx.h"
Vivien Didelota935c052016-09-29 12:21:53 -040038#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040039#include "global2.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010040#include "port.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000041
Vivien Didelotfad09c72016-06-21 12:28:20 -040042static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040043{
Vivien Didelotfad09c72016-06-21 12:28:20 -040044 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
45 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040046 dump_stack();
47 }
48}
49
Vivien Didelot914b32f2016-06-20 13:14:11 -040050/* The switch ADDR[4:1] configuration pins define the chip SMI device address
51 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
52 *
53 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
54 * is the only device connected to the SMI master. In this mode it responds to
55 * all 32 possible SMI addresses, and thus maps directly the internal devices.
56 *
57 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
58 * multiple devices to share the SMI interface. In this mode it responds to only
59 * 2 registers, used to indirectly access the internal SMI devices.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000060 */
Vivien Didelot914b32f2016-06-20 13:14:11 -040061
Vivien Didelotfad09c72016-06-21 12:28:20 -040062static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040063 int addr, int reg, u16 *val)
64{
Vivien Didelotfad09c72016-06-21 12:28:20 -040065 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040066 return -EOPNOTSUPP;
67
Vivien Didelotfad09c72016-06-21 12:28:20 -040068 return chip->smi_ops->read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040069}
70
Vivien Didelotfad09c72016-06-21 12:28:20 -040071static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040072 int addr, int reg, u16 val)
73{
Vivien Didelotfad09c72016-06-21 12:28:20 -040074 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040075 return -EOPNOTSUPP;
76
Vivien Didelotfad09c72016-06-21 12:28:20 -040077 return chip->smi_ops->write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040078}
79
Vivien Didelotfad09c72016-06-21 12:28:20 -040080static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040081 int addr, int reg, u16 *val)
82{
83 int ret;
84
Vivien Didelotfad09c72016-06-21 12:28:20 -040085 ret = mdiobus_read_nested(chip->bus, addr, reg);
Vivien Didelot914b32f2016-06-20 13:14:11 -040086 if (ret < 0)
87 return ret;
88
89 *val = ret & 0xffff;
90
91 return 0;
92}
93
Vivien Didelotfad09c72016-06-21 12:28:20 -040094static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040095 int addr, int reg, u16 val)
96{
97 int ret;
98
Vivien Didelotfad09c72016-06-21 12:28:20 -040099 ret = mdiobus_write_nested(chip->bus, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400100 if (ret < 0)
101 return ret;
102
103 return 0;
104}
105
Vivien Didelotc08026a2016-09-29 12:21:59 -0400106static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400107 .read = mv88e6xxx_smi_single_chip_read,
108 .write = mv88e6xxx_smi_single_chip_write,
109};
110
Vivien Didelotfad09c72016-06-21 12:28:20 -0400111static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000112{
113 int ret;
114 int i;
115
116 for (i = 0; i < 16; i++) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400117 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000118 if (ret < 0)
119 return ret;
120
Andrew Lunncca8b132015-04-02 04:06:39 +0200121 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000122 return 0;
123 }
124
125 return -ETIMEDOUT;
126}
127
Vivien Didelotfad09c72016-06-21 12:28:20 -0400128static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400129 int addr, int reg, u16 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000130{
131 int ret;
132
Barry Grussling3675c8d2013-01-08 16:05:53 +0000133 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400134 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000135 if (ret < 0)
136 return ret;
137
Barry Grussling3675c8d2013-01-08 16:05:53 +0000138 /* Transmit the read command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400139 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Neil Armstrong6e899e62015-10-22 10:37:53 +0200140 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000141 if (ret < 0)
142 return ret;
143
Barry Grussling3675c8d2013-01-08 16:05:53 +0000144 /* Wait for the read command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400145 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000146 if (ret < 0)
147 return ret;
148
Barry Grussling3675c8d2013-01-08 16:05:53 +0000149 /* Read the data. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400150 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000151 if (ret < 0)
152 return ret;
153
Vivien Didelot914b32f2016-06-20 13:14:11 -0400154 *val = ret & 0xffff;
155
156 return 0;
157}
158
Vivien Didelotfad09c72016-06-21 12:28:20 -0400159static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400160 int addr, int reg, u16 val)
161{
162 int ret;
163
164 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400165 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400166 if (ret < 0)
167 return ret;
168
169 /* Transmit the data to write. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400170 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400171 if (ret < 0)
172 return ret;
173
174 /* Transmit the write command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400175 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400176 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
177 if (ret < 0)
178 return ret;
179
180 /* Wait for the write command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400181 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400182 if (ret < 0)
183 return ret;
184
185 return 0;
186}
187
Vivien Didelotc08026a2016-09-29 12:21:59 -0400188static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400189 .read = mv88e6xxx_smi_multi_chip_read,
190 .write = mv88e6xxx_smi_multi_chip_write,
191};
192
Vivien Didelotec561272016-09-02 14:45:33 -0400193int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400194{
195 int err;
196
Vivien Didelotfad09c72016-06-21 12:28:20 -0400197 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400198
Vivien Didelotfad09c72016-06-21 12:28:20 -0400199 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400200 if (err)
201 return err;
202
Vivien Didelotfad09c72016-06-21 12:28:20 -0400203 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400204 addr, reg, *val);
205
206 return 0;
207}
208
Vivien Didelotec561272016-09-02 14:45:33 -0400209int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400210{
211 int err;
212
Vivien Didelotfad09c72016-06-21 12:28:20 -0400213 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400214
Vivien Didelotfad09c72016-06-21 12:28:20 -0400215 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400216 if (err)
217 return err;
218
Vivien Didelotfad09c72016-06-21 12:28:20 -0400219 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400220 addr, reg, val);
221
222 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000223}
224
Andrew Lunnee26a222017-01-24 14:53:48 +0100225static int mv88e6165_phy_read(struct mv88e6xxx_chip *chip,
226 struct mii_bus *bus,
227 int addr, int reg, u16 *val)
Andrew Lunnefb3e742017-01-24 14:53:47 +0100228{
229 return mv88e6xxx_read(chip, addr, reg, val);
230}
231
Andrew Lunnee26a222017-01-24 14:53:48 +0100232static int mv88e6165_phy_write(struct mv88e6xxx_chip *chip,
233 struct mii_bus *bus,
234 int addr, int reg, u16 val)
Andrew Lunnefb3e742017-01-24 14:53:47 +0100235{
236 return mv88e6xxx_write(chip, addr, reg, val);
237}
238
Andrew Lunna3c53be52017-01-24 14:53:50 +0100239static struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
240{
241 struct mv88e6xxx_mdio_bus *mdio_bus;
242
243 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
244 list);
245 if (!mdio_bus)
246 return NULL;
247
248 return mdio_bus->bus;
249}
250
Vivien Didelote57e5e72016-08-15 17:19:00 -0400251static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
252 int reg, u16 *val)
253{
254 int addr = phy; /* PHY devices addresses start at 0x0 */
Andrew Lunna3c53be52017-01-24 14:53:50 +0100255 struct mii_bus *bus;
Vivien Didelote57e5e72016-08-15 17:19:00 -0400256
Andrew Lunna3c53be52017-01-24 14:53:50 +0100257 bus = mv88e6xxx_default_mdio_bus(chip);
258 if (!bus)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400259 return -EOPNOTSUPP;
260
Andrew Lunna3c53be52017-01-24 14:53:50 +0100261 if (!chip->info->ops->phy_read)
Andrew Lunnee26a222017-01-24 14:53:48 +0100262 return -EOPNOTSUPP;
263
264 return chip->info->ops->phy_read(chip, bus, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400265}
266
267static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
268 int reg, u16 val)
269{
270 int addr = phy; /* PHY devices addresses start at 0x0 */
Andrew Lunna3c53be52017-01-24 14:53:50 +0100271 struct mii_bus *bus;
Vivien Didelote57e5e72016-08-15 17:19:00 -0400272
Andrew Lunna3c53be52017-01-24 14:53:50 +0100273 bus = mv88e6xxx_default_mdio_bus(chip);
274 if (!bus)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400275 return -EOPNOTSUPP;
276
Andrew Lunna3c53be52017-01-24 14:53:50 +0100277 if (!chip->info->ops->phy_write)
Andrew Lunnee26a222017-01-24 14:53:48 +0100278 return -EOPNOTSUPP;
279
280 return chip->info->ops->phy_write(chip, bus, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400281}
282
Vivien Didelot09cb7df2016-08-15 17:19:01 -0400283static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
284{
285 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_PHY_PAGE))
286 return -EOPNOTSUPP;
287
288 return mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
289}
290
291static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip *chip, int phy)
292{
293 int err;
294
295 /* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
296 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, PHY_PAGE_COPPER);
297 if (unlikely(err)) {
298 dev_err(chip->dev, "failed to restore PHY %d page Copper (%d)\n",
299 phy, err);
300 }
301}
302
303static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy,
304 u8 page, int reg, u16 *val)
305{
306 int err;
307
308 /* There is no paging for registers 22 */
309 if (reg == PHY_PAGE)
310 return -EINVAL;
311
312 err = mv88e6xxx_phy_page_get(chip, phy, page);
313 if (!err) {
314 err = mv88e6xxx_phy_read(chip, phy, reg, val);
315 mv88e6xxx_phy_page_put(chip, phy);
316 }
317
318 return err;
319}
320
321static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy,
322 u8 page, int reg, u16 val)
323{
324 int err;
325
326 /* There is no paging for registers 22 */
327 if (reg == PHY_PAGE)
328 return -EINVAL;
329
330 err = mv88e6xxx_phy_page_get(chip, phy, page);
331 if (!err) {
332 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
333 mv88e6xxx_phy_page_put(chip, phy);
334 }
335
336 return err;
337}
338
339static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
340{
341 return mv88e6xxx_phy_page_read(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
342 reg, val);
343}
344
345static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
346{
347 return mv88e6xxx_phy_page_write(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
348 reg, val);
349}
350
Andrew Lunndc30c352016-10-16 19:56:49 +0200351static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
352{
353 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
354 unsigned int n = d->hwirq;
355
356 chip->g1_irq.masked |= (1 << n);
357}
358
359static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
360{
361 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
362 unsigned int n = d->hwirq;
363
364 chip->g1_irq.masked &= ~(1 << n);
365}
366
367static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
368{
369 struct mv88e6xxx_chip *chip = dev_id;
370 unsigned int nhandled = 0;
371 unsigned int sub_irq;
372 unsigned int n;
373 u16 reg;
374 int err;
375
376 mutex_lock(&chip->reg_lock);
377 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
378 mutex_unlock(&chip->reg_lock);
379
380 if (err)
381 goto out;
382
383 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
384 if (reg & (1 << n)) {
385 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
386 handle_nested_irq(sub_irq);
387 ++nhandled;
388 }
389 }
390out:
391 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
392}
393
394static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
395{
396 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
397
398 mutex_lock(&chip->reg_lock);
399}
400
401static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
402{
403 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
404 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
405 u16 reg;
406 int err;
407
408 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
409 if (err)
410 goto out;
411
412 reg &= ~mask;
413 reg |= (~chip->g1_irq.masked & mask);
414
415 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
416 if (err)
417 goto out;
418
419out:
420 mutex_unlock(&chip->reg_lock);
421}
422
423static struct irq_chip mv88e6xxx_g1_irq_chip = {
424 .name = "mv88e6xxx-g1",
425 .irq_mask = mv88e6xxx_g1_irq_mask,
426 .irq_unmask = mv88e6xxx_g1_irq_unmask,
427 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
428 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
429};
430
431static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
432 unsigned int irq,
433 irq_hw_number_t hwirq)
434{
435 struct mv88e6xxx_chip *chip = d->host_data;
436
437 irq_set_chip_data(irq, d->host_data);
438 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
439 irq_set_noprobe(irq);
440
441 return 0;
442}
443
444static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
445 .map = mv88e6xxx_g1_irq_domain_map,
446 .xlate = irq_domain_xlate_twocell,
447};
448
449static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
450{
451 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100452 u16 mask;
453
454 mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
455 mask |= GENMASK(chip->g1_irq.nirqs, 0);
456 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
457
458 free_irq(chip->irq, chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200459
Andreas Färber5edef2f2016-11-27 23:26:28 +0100460 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100461 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200462 irq_dispose_mapping(virq);
463 }
464
Andrew Lunna3db3d32016-11-20 20:14:14 +0100465 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200466}
467
468static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
469{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100470 int err, irq, virq;
471 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200472
473 chip->g1_irq.nirqs = chip->info->g1_irqs;
474 chip->g1_irq.domain = irq_domain_add_simple(
475 NULL, chip->g1_irq.nirqs, 0,
476 &mv88e6xxx_g1_irq_domain_ops, chip);
477 if (!chip->g1_irq.domain)
478 return -ENOMEM;
479
480 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
481 irq_create_mapping(chip->g1_irq.domain, irq);
482
483 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
484 chip->g1_irq.masked = ~0;
485
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100486 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200487 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100488 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200489
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100490 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200491
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100492 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200493 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100494 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200495
496 /* Reading the interrupt status clears (most of) them */
497 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
498 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100499 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200500
501 err = request_threaded_irq(chip->irq, NULL,
502 mv88e6xxx_g1_irq_thread_fn,
503 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
504 dev_name(chip->dev), chip);
505 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100506 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200507
508 return 0;
509
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100510out_disable:
511 mask |= GENMASK(chip->g1_irq.nirqs, 0);
512 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
513
514out_mapping:
515 for (irq = 0; irq < 16; irq++) {
516 virq = irq_find_mapping(chip->g1_irq.domain, irq);
517 irq_dispose_mapping(virq);
518 }
519
520 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200521
522 return err;
523}
524
Vivien Didelotec561272016-09-02 14:45:33 -0400525int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400526{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200527 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400528
Andrew Lunn6441e6692016-08-19 00:01:55 +0200529 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400530 u16 val;
531 int err;
532
533 err = mv88e6xxx_read(chip, addr, reg, &val);
534 if (err)
535 return err;
536
537 if (!(val & mask))
538 return 0;
539
540 usleep_range(1000, 2000);
541 }
542
Andrew Lunn30853552016-08-19 00:01:57 +0200543 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400544 return -ETIMEDOUT;
545}
546
Vivien Didelotf22ab642016-07-18 20:45:31 -0400547/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400548int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400549{
550 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200551 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400552
553 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200554 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
555 if (err)
556 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400557
558 /* Set the Update bit to trigger a write operation */
559 val = BIT(15) | update;
560
561 return mv88e6xxx_write(chip, addr, reg, val);
562}
563
Vivien Didelota935c052016-09-29 12:21:53 -0400564static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000565{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500566 if (!chip->info->ops->ppu_disable)
567 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000568
Vivien Didelota199d8b2016-12-05 17:30:28 -0500569 return chip->info->ops->ppu_disable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000570}
571
Vivien Didelotfad09c72016-06-21 12:28:20 -0400572static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000573{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500574 if (!chip->info->ops->ppu_enable)
575 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000576
Vivien Didelota199d8b2016-12-05 17:30:28 -0500577 return chip->info->ops->ppu_enable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000578}
579
580static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
581{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400582 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000583
Vivien Didelotfad09c72016-06-21 12:28:20 -0400584 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200585
Vivien Didelotfad09c72016-06-21 12:28:20 -0400586 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200587
Vivien Didelotfad09c72016-06-21 12:28:20 -0400588 if (mutex_trylock(&chip->ppu_mutex)) {
589 if (mv88e6xxx_ppu_enable(chip) == 0)
590 chip->ppu_disabled = 0;
591 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000592 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200593
Vivien Didelotfad09c72016-06-21 12:28:20 -0400594 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000595}
596
597static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
598{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400599 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000600
Vivien Didelotfad09c72016-06-21 12:28:20 -0400601 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000602}
603
Vivien Didelotfad09c72016-06-21 12:28:20 -0400604static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000605{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000606 int ret;
607
Vivien Didelotfad09c72016-06-21 12:28:20 -0400608 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000609
Barry Grussling3675c8d2013-01-08 16:05:53 +0000610 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000611 * we can access the PHY registers. If it was already
612 * disabled, cancel the timer that is going to re-enable
613 * it.
614 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400615 if (!chip->ppu_disabled) {
616 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000617 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400618 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000619 return ret;
620 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400621 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000622 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400623 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000624 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000625 }
626
627 return ret;
628}
629
Vivien Didelotfad09c72016-06-21 12:28:20 -0400630static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000631{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000632 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400633 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
634 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000635}
636
Vivien Didelotfad09c72016-06-21 12:28:20 -0400637static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000638{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400639 mutex_init(&chip->ppu_mutex);
640 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000641 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
642 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000643}
644
Andrew Lunn930188c2016-08-22 16:01:03 +0200645static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
646{
647 del_timer_sync(&chip->ppu_timer);
648}
649
Andrew Lunnee26a222017-01-24 14:53:48 +0100650static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip,
651 struct mii_bus *bus,
652 int addr, int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000653{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400654 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000655
Vivien Didelote57e5e72016-08-15 17:19:00 -0400656 err = mv88e6xxx_ppu_access_get(chip);
657 if (!err) {
658 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400659 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000660 }
661
Vivien Didelote57e5e72016-08-15 17:19:00 -0400662 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000663}
664
Andrew Lunnee26a222017-01-24 14:53:48 +0100665static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip,
666 struct mii_bus *bus,
667 int addr, int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000668{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400669 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000670
Vivien Didelote57e5e72016-08-15 17:19:00 -0400671 err = mv88e6xxx_ppu_access_get(chip);
672 if (!err) {
673 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400674 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000675 }
676
Vivien Didelote57e5e72016-08-15 17:19:00 -0400677 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000678}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000679
Vivien Didelotfad09c72016-06-21 12:28:20 -0400680static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200681{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400682 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200683}
684
Vivien Didelotfad09c72016-06-21 12:28:20 -0400685static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200686{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400687 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200688}
689
Vivien Didelotfad09c72016-06-21 12:28:20 -0400690static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700691{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400692 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700693}
694
Gregory CLEMENTa75961d2017-01-30 20:29:34 +0100695static bool mv88e6xxx_6341_family(struct mv88e6xxx_chip *chip)
696{
697 return chip->info->family == MV88E6XXX_FAMILY_6341;
698}
699
Vivien Didelotfad09c72016-06-21 12:28:20 -0400700static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200701{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400702 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200703}
704
Vivien Didelotfad09c72016-06-21 12:28:20 -0400705static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200706{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400707 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200708}
709
Vivien Didelotd78343d2016-11-04 03:23:36 +0100710static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
711 int link, int speed, int duplex,
712 phy_interface_t mode)
713{
714 int err;
715
716 if (!chip->info->ops->port_set_link)
717 return 0;
718
719 /* Port's MAC control must not be changed unless the link is down */
720 err = chip->info->ops->port_set_link(chip, port, 0);
721 if (err)
722 return err;
723
724 if (chip->info->ops->port_set_speed) {
725 err = chip->info->ops->port_set_speed(chip, port, speed);
726 if (err && err != -EOPNOTSUPP)
727 goto restore_link;
728 }
729
730 if (chip->info->ops->port_set_duplex) {
731 err = chip->info->ops->port_set_duplex(chip, port, duplex);
732 if (err && err != -EOPNOTSUPP)
733 goto restore_link;
734 }
735
736 if (chip->info->ops->port_set_rgmii_delay) {
737 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
738 if (err && err != -EOPNOTSUPP)
739 goto restore_link;
740 }
741
Andrew Lunnf39908d2017-02-04 20:02:50 +0100742 if (chip->info->ops->port_set_cmode) {
743 err = chip->info->ops->port_set_cmode(chip, port, mode);
744 if (err && err != -EOPNOTSUPP)
745 goto restore_link;
746 }
747
Vivien Didelotd78343d2016-11-04 03:23:36 +0100748 err = 0;
749restore_link:
750 if (chip->info->ops->port_set_link(chip, port, link))
751 netdev_err(chip->ds->ports[port].netdev,
752 "failed to restore MAC's link\n");
753
754 return err;
755}
756
Andrew Lunndea87022015-08-31 15:56:47 +0200757/* We expect the switch to perform auto negotiation if there is a real
758 * phy. However, in the case of a fixed link phy, we force the port
759 * settings from the fixed link settings.
760 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400761static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
762 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200763{
Vivien Didelot04bed142016-08-31 18:06:13 -0400764 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200765 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200766
767 if (!phy_is_pseudo_fixed_link(phydev))
768 return;
769
Vivien Didelotfad09c72016-06-21 12:28:20 -0400770 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100771 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
772 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400773 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100774
775 if (err && err != -EOPNOTSUPP)
776 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200777}
778
Andrew Lunna605a0f2016-11-21 23:26:58 +0100779static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000780{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100781 if (!chip->info->ops->stats_snapshot)
782 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000783
Andrew Lunna605a0f2016-11-21 23:26:58 +0100784 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000785}
786
Andrew Lunne413e7e2015-04-02 04:06:38 +0200787static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100788 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
789 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
790 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
791 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
792 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
793 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
794 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
795 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
796 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
797 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
798 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
799 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
800 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
801 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
802 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
803 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
804 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
805 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
806 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
807 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
808 { "single", 4, 0x14, STATS_TYPE_BANK0, },
809 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
810 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
811 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
812 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
813 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
814 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
815 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
816 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
817 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
818 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
819 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
820 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
821 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
822 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
823 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
824 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
825 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
826 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
827 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
828 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
829 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
830 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
831 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
832 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
833 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
834 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
835 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
836 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
837 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
838 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
839 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
840 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
841 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
842 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
843 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
844 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
845 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
846 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200847};
848
Vivien Didelotfad09c72016-06-21 12:28:20 -0400849static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100850 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100851 int port, u16 bank1_select,
852 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200853{
Andrew Lunn80c46272015-06-20 18:42:30 +0200854 u32 low;
855 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100856 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200857 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200858 u64 value;
859
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100860 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100861 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200862 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
863 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200864 return UINT64_MAX;
865
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200866 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200867 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200868 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
869 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200870 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200871 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200872 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100873 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100874 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100875 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100876 /* fall through */
877 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100878 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100879 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200880 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100881 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200882 }
883 value = (((u64)high) << 16) | low;
884 return value;
885}
886
Andrew Lunndfafe442016-11-21 23:27:02 +0100887static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
888 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100889{
890 struct mv88e6xxx_hw_stat *stat;
891 int i, j;
892
893 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
894 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100895 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100896 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
897 ETH_GSTRING_LEN);
898 j++;
899 }
900 }
901}
902
Andrew Lunndfafe442016-11-21 23:27:02 +0100903static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
904 uint8_t *data)
905{
906 mv88e6xxx_stats_get_strings(chip, data,
907 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
908}
909
910static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
911 uint8_t *data)
912{
913 mv88e6xxx_stats_get_strings(chip, data,
914 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
915}
916
917static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
918 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100919{
Vivien Didelot04bed142016-08-31 18:06:13 -0400920 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100921
922 if (chip->info->ops->stats_get_strings)
923 chip->info->ops->stats_get_strings(chip, data);
924}
925
926static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
927 int types)
928{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100929 struct mv88e6xxx_hw_stat *stat;
930 int i, j;
931
932 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
933 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100934 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100935 j++;
936 }
937 return j;
938}
939
Andrew Lunndfafe442016-11-21 23:27:02 +0100940static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
941{
942 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
943 STATS_TYPE_PORT);
944}
945
946static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
947{
948 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
949 STATS_TYPE_BANK1);
950}
951
952static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
953{
954 struct mv88e6xxx_chip *chip = ds->priv;
955
956 if (chip->info->ops->stats_get_sset_count)
957 return chip->info->ops->stats_get_sset_count(chip);
958
959 return 0;
960}
961
Andrew Lunn052f9472016-11-21 23:27:03 +0100962static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100963 uint64_t *data, int types,
964 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100965{
966 struct mv88e6xxx_hw_stat *stat;
967 int i, j;
968
969 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
970 stat = &mv88e6xxx_hw_stats[i];
971 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100972 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
973 bank1_select,
974 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100975 j++;
976 }
977 }
978}
979
980static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
981 uint64_t *data)
982{
983 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100984 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
985 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100986}
987
988static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
989 uint64_t *data)
990{
991 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100992 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
993 GLOBAL_STATS_OP_BANK_1_BIT_9,
994 GLOBAL_STATS_OP_HIST_RX_TX);
995}
996
997static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
998 uint64_t *data)
999{
1000 return mv88e6xxx_stats_get_stats(chip, port, data,
1001 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1002 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001003}
1004
1005static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1006 uint64_t *data)
1007{
1008 if (chip->info->ops->stats_get_stats)
1009 chip->info->ops->stats_get_stats(chip, port, data);
1010}
1011
Vivien Didelotf81ec902016-05-09 13:22:58 -04001012static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1013 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001014{
Vivien Didelot04bed142016-08-31 18:06:13 -04001015 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001016 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001017
Vivien Didelotfad09c72016-06-21 12:28:20 -04001018 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001019
Andrew Lunna605a0f2016-11-21 23:26:58 +01001020 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001021 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001022 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001023 return;
1024 }
Andrew Lunn052f9472016-11-21 23:27:03 +01001025
1026 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001027
Vivien Didelotfad09c72016-06-21 12:28:20 -04001028 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001029}
Ben Hutchings98e67302011-11-25 14:36:19 +00001030
Andrew Lunnde2273872016-11-21 23:27:01 +01001031static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1032{
1033 if (chip->info->ops->stats_set_histogram)
1034 return chip->info->ops->stats_set_histogram(chip);
1035
1036 return 0;
1037}
1038
Vivien Didelotf81ec902016-05-09 13:22:58 -04001039static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001040{
1041 return 32 * sizeof(u16);
1042}
1043
Vivien Didelotf81ec902016-05-09 13:22:58 -04001044static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1045 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001046{
Vivien Didelot04bed142016-08-31 18:06:13 -04001047 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001048 int err;
1049 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001050 u16 *p = _p;
1051 int i;
1052
1053 regs->version = 0;
1054
1055 memset(p, 0xff, 32 * sizeof(u16));
1056
Vivien Didelotfad09c72016-06-21 12:28:20 -04001057 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001058
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001059 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001060
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001061 err = mv88e6xxx_port_read(chip, port, i, &reg);
1062 if (!err)
1063 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001064 }
Vivien Didelot23062512016-05-09 13:22:45 -04001065
Vivien Didelotfad09c72016-06-21 12:28:20 -04001066 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001067}
1068
Vivien Didelotfad09c72016-06-21 12:28:20 -04001069static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001070{
Vivien Didelota935c052016-09-29 12:21:53 -04001071 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001072}
1073
Vivien Didelotf81ec902016-05-09 13:22:58 -04001074static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1075 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001076{
Vivien Didelot04bed142016-08-31 18:06:13 -04001077 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001078 u16 reg;
1079 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001080
Vivien Didelotfad09c72016-06-21 12:28:20 -04001081 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001082 return -EOPNOTSUPP;
1083
Vivien Didelotfad09c72016-06-21 12:28:20 -04001084 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001085
Vivien Didelot9c938292016-08-15 17:19:02 -04001086 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1087 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001088 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001089
1090 e->eee_enabled = !!(reg & 0x0200);
1091 e->tx_lpi_enabled = !!(reg & 0x0100);
1092
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001093 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001094 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001095 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001096
Andrew Lunncca8b132015-04-02 04:06:39 +02001097 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001098out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001099 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001100
1101 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001102}
1103
Vivien Didelotf81ec902016-05-09 13:22:58 -04001104static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1105 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001106{
Vivien Didelot04bed142016-08-31 18:06:13 -04001107 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001108 u16 reg;
1109 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001110
Vivien Didelotfad09c72016-06-21 12:28:20 -04001111 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001112 return -EOPNOTSUPP;
1113
Vivien Didelotfad09c72016-06-21 12:28:20 -04001114 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001115
Vivien Didelot9c938292016-08-15 17:19:02 -04001116 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1117 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001118 goto out;
1119
Vivien Didelot9c938292016-08-15 17:19:02 -04001120 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001121 if (e->eee_enabled)
1122 reg |= 0x0200;
1123 if (e->tx_lpi_enabled)
1124 reg |= 0x0100;
1125
Vivien Didelot9c938292016-08-15 17:19:02 -04001126 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001127out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001128 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001129
Vivien Didelot9c938292016-08-15 17:19:02 -04001130 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001131}
1132
Vivien Didelotfad09c72016-06-21 12:28:20 -04001133static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001134{
Vivien Didelota935c052016-09-29 12:21:53 -04001135 u16 val;
1136 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001137
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001138 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001139 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1140 if (err)
1141 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001142 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001143 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001144 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1145 if (err)
1146 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001147
Vivien Didelota935c052016-09-29 12:21:53 -04001148 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1149 (val & 0xfff) | ((fid << 8) & 0xf000));
1150 if (err)
1151 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001152
1153 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1154 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001155 }
1156
Vivien Didelota935c052016-09-29 12:21:53 -04001157 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1158 if (err)
1159 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001160
Vivien Didelotfad09c72016-06-21 12:28:20 -04001161 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001162}
1163
Vivien Didelotfad09c72016-06-21 12:28:20 -04001164static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001165 struct mv88e6xxx_atu_entry *entry)
1166{
1167 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1168
1169 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1170 unsigned int mask, shift;
1171
1172 if (entry->trunk) {
1173 data |= GLOBAL_ATU_DATA_TRUNK;
1174 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1175 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1176 } else {
1177 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1178 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1179 }
1180
1181 data |= (entry->portv_trunkid << shift) & mask;
1182 }
1183
Vivien Didelota935c052016-09-29 12:21:53 -04001184 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001185}
1186
Vivien Didelotfad09c72016-06-21 12:28:20 -04001187static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001188 struct mv88e6xxx_atu_entry *entry,
1189 bool static_too)
1190{
1191 int op;
1192 int err;
1193
Vivien Didelotfad09c72016-06-21 12:28:20 -04001194 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001195 if (err)
1196 return err;
1197
Vivien Didelotfad09c72016-06-21 12:28:20 -04001198 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001199 if (err)
1200 return err;
1201
1202 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001203 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1204 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1205 } else {
1206 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1207 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1208 }
1209
Vivien Didelotfad09c72016-06-21 12:28:20 -04001210 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001211}
1212
Vivien Didelotfad09c72016-06-21 12:28:20 -04001213static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001214 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001215{
1216 struct mv88e6xxx_atu_entry entry = {
1217 .fid = fid,
1218 .state = 0, /* EntryState bits must be 0 */
1219 };
1220
Vivien Didelotfad09c72016-06-21 12:28:20 -04001221 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001222}
1223
Vivien Didelotfad09c72016-06-21 12:28:20 -04001224static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001225 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001226{
1227 struct mv88e6xxx_atu_entry entry = {
1228 .trunk = false,
1229 .fid = fid,
1230 };
1231
1232 /* EntryState bits must be 0xF */
1233 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1234
1235 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1236 entry.portv_trunkid = (to_port & 0x0f) << 4;
1237 entry.portv_trunkid |= from_port & 0x0f;
1238
Vivien Didelotfad09c72016-06-21 12:28:20 -04001239 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001240}
1241
Vivien Didelotfad09c72016-06-21 12:28:20 -04001242static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001243 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001244{
1245 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001246 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001247}
1248
Vivien Didelotfad09c72016-06-21 12:28:20 -04001249static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001250{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001251 struct dsa_switch *ds = chip->ds;
Vivien Didelotfae8a252017-01-27 15:29:42 -05001252 struct net_device *bridge = ds->ports[port].bridge_dev;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001253 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001254 int i;
1255
1256 /* allow CPU port or DSA link(s) to send frames to every port */
1257 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001258 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001259 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001260 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001261 /* allow sending frames to every group member */
Vivien Didelotfae8a252017-01-27 15:29:42 -05001262 if (bridge && ds->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001263 output_ports |= BIT(i);
1264
1265 /* allow sending frames to CPU port and DSA link(s) */
1266 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1267 output_ports |= BIT(i);
1268 }
1269 }
1270
1271 /* prevent frames from going back out of the port they came in on */
1272 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001273
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001274 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001275}
1276
Vivien Didelotf81ec902016-05-09 13:22:58 -04001277static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1278 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001279{
Vivien Didelot04bed142016-08-31 18:06:13 -04001280 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001281 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001282 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001283
1284 switch (state) {
1285 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001286 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001287 break;
1288 case BR_STATE_BLOCKING:
1289 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001290 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001291 break;
1292 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001293 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001294 break;
1295 case BR_STATE_FORWARDING:
1296 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001297 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001298 break;
1299 }
1300
Vivien Didelotfad09c72016-06-21 12:28:20 -04001301 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001302 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001303 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001304
1305 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001306 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001307}
1308
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001309static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1310{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001311 int err;
1312
1313 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1314 if (err)
1315 return err;
1316
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001317 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1318}
1319
Vivien Didelot749efcb2016-09-22 16:49:24 -04001320static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1321{
1322 struct mv88e6xxx_chip *chip = ds->priv;
1323 int err;
1324
1325 mutex_lock(&chip->reg_lock);
1326 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1327 mutex_unlock(&chip->reg_lock);
1328
1329 if (err)
1330 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1331}
1332
Vivien Didelotfad09c72016-06-21 12:28:20 -04001333static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001334{
Vivien Didelota935c052016-09-29 12:21:53 -04001335 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001336}
1337
Vivien Didelotfad09c72016-06-21 12:28:20 -04001338static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001339{
Vivien Didelota935c052016-09-29 12:21:53 -04001340 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001341
Vivien Didelota935c052016-09-29 12:21:53 -04001342 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1343 if (err)
1344 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001345
Vivien Didelotfad09c72016-06-21 12:28:20 -04001346 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001347}
1348
Vivien Didelotfad09c72016-06-21 12:28:20 -04001349static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001350{
1351 int ret;
1352
Vivien Didelotfad09c72016-06-21 12:28:20 -04001353 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001354 if (ret < 0)
1355 return ret;
1356
Vivien Didelotfad09c72016-06-21 12:28:20 -04001357 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001358}
1359
Vivien Didelotfad09c72016-06-21 12:28:20 -04001360static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001361 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001362 unsigned int nibble_offset)
1363{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001364 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001365 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001366
1367 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001368 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001369
Vivien Didelota935c052016-09-29 12:21:53 -04001370 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1371 if (err)
1372 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001373 }
1374
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001375 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001376 unsigned int shift = (i % 4) * 4 + nibble_offset;
1377 u16 reg = regs[i / 4];
1378
1379 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1380 }
1381
1382 return 0;
1383}
1384
Vivien Didelotfad09c72016-06-21 12:28:20 -04001385static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001386 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001387{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001388 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001389}
1390
Vivien Didelotfad09c72016-06-21 12:28:20 -04001391static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001392 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001393{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001394 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001395}
1396
Vivien Didelotfad09c72016-06-21 12:28:20 -04001397static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001398 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001399 unsigned int nibble_offset)
1400{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001401 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001402 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001403
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001404 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001405 unsigned int shift = (i % 4) * 4 + nibble_offset;
1406 u8 data = entry->data[i];
1407
1408 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1409 }
1410
1411 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001412 u16 reg = regs[i];
1413
1414 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1415 if (err)
1416 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001417 }
1418
1419 return 0;
1420}
1421
Vivien Didelotfad09c72016-06-21 12:28:20 -04001422static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001423 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001424{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001425 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001426}
1427
Vivien Didelotfad09c72016-06-21 12:28:20 -04001428static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001429 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001430{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001431 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001432}
1433
Vivien Didelotfad09c72016-06-21 12:28:20 -04001434static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001435{
Vivien Didelota935c052016-09-29 12:21:53 -04001436 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1437 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001438}
1439
Vivien Didelotfad09c72016-06-21 12:28:20 -04001440static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001441 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001442{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001443 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001444 u16 val;
1445 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001446
Vivien Didelota935c052016-09-29 12:21:53 -04001447 err = _mv88e6xxx_vtu_wait(chip);
1448 if (err)
1449 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001450
Vivien Didelota935c052016-09-29 12:21:53 -04001451 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1452 if (err)
1453 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001454
Vivien Didelota935c052016-09-29 12:21:53 -04001455 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1456 if (err)
1457 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001458
Vivien Didelota935c052016-09-29 12:21:53 -04001459 next.vid = val & GLOBAL_VTU_VID_MASK;
1460 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001461
1462 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001463 err = mv88e6xxx_vtu_data_read(chip, &next);
1464 if (err)
1465 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001466
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001467 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001468 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1469 if (err)
1470 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001471
Vivien Didelota935c052016-09-29 12:21:53 -04001472 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001473 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001474 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1475 * VTU DBNum[3:0] are located in VTU Operation 3:0
1476 */
Vivien Didelota935c052016-09-29 12:21:53 -04001477 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1478 if (err)
1479 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001480
Vivien Didelota935c052016-09-29 12:21:53 -04001481 next.fid = (val & 0xf00) >> 4;
1482 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001483 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001484
Vivien Didelotfad09c72016-06-21 12:28:20 -04001485 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001486 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1487 if (err)
1488 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001489
Vivien Didelota935c052016-09-29 12:21:53 -04001490 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001491 }
1492 }
1493
1494 *entry = next;
1495 return 0;
1496}
1497
Vivien Didelotf81ec902016-05-09 13:22:58 -04001498static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1499 struct switchdev_obj_port_vlan *vlan,
1500 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001501{
Vivien Didelot04bed142016-08-31 18:06:13 -04001502 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001503 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001504 u16 pvid;
1505 int err;
1506
Vivien Didelotfad09c72016-06-21 12:28:20 -04001507 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001508 return -EOPNOTSUPP;
1509
Vivien Didelotfad09c72016-06-21 12:28:20 -04001510 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001511
Vivien Didelot77064f32016-11-04 03:23:30 +01001512 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001513 if (err)
1514 goto unlock;
1515
Vivien Didelotfad09c72016-06-21 12:28:20 -04001516 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001517 if (err)
1518 goto unlock;
1519
1520 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001521 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001522 if (err)
1523 break;
1524
1525 if (!next.valid)
1526 break;
1527
1528 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1529 continue;
1530
1531 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001532 vlan->vid_begin = next.vid;
1533 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001534 vlan->flags = 0;
1535
1536 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1537 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1538
1539 if (next.vid == pvid)
1540 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1541
1542 err = cb(&vlan->obj);
1543 if (err)
1544 break;
1545 } while (next.vid < GLOBAL_VTU_VID_MASK);
1546
1547unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001548 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001549
1550 return err;
1551}
1552
Vivien Didelotfad09c72016-06-21 12:28:20 -04001553static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001554 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001555{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001556 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001557 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001558 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001559
Vivien Didelota935c052016-09-29 12:21:53 -04001560 err = _mv88e6xxx_vtu_wait(chip);
1561 if (err)
1562 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001563
1564 if (!entry->valid)
1565 goto loadpurge;
1566
1567 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001568 err = mv88e6xxx_vtu_data_write(chip, entry);
1569 if (err)
1570 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001571
Vivien Didelotfad09c72016-06-21 12:28:20 -04001572 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001573 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001574 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1575 if (err)
1576 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001577 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001578
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001579 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001580 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001581 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1582 if (err)
1583 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001584 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001585 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1586 * VTU DBNum[3:0] are located in VTU Operation 3:0
1587 */
1588 op |= (entry->fid & 0xf0) << 8;
1589 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001590 }
1591
1592 reg = GLOBAL_VTU_VID_VALID;
1593loadpurge:
1594 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001595 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1596 if (err)
1597 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001598
Vivien Didelotfad09c72016-06-21 12:28:20 -04001599 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001600}
1601
Vivien Didelotfad09c72016-06-21 12:28:20 -04001602static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001603 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001604{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001605 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001606 u16 val;
1607 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001608
Vivien Didelota935c052016-09-29 12:21:53 -04001609 err = _mv88e6xxx_vtu_wait(chip);
1610 if (err)
1611 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001612
Vivien Didelota935c052016-09-29 12:21:53 -04001613 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1614 sid & GLOBAL_VTU_SID_MASK);
1615 if (err)
1616 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001617
Vivien Didelota935c052016-09-29 12:21:53 -04001618 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1619 if (err)
1620 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001621
Vivien Didelota935c052016-09-29 12:21:53 -04001622 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1623 if (err)
1624 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001625
Vivien Didelota935c052016-09-29 12:21:53 -04001626 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001627
Vivien Didelota935c052016-09-29 12:21:53 -04001628 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1629 if (err)
1630 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001631
Vivien Didelota935c052016-09-29 12:21:53 -04001632 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001633
1634 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001635 err = mv88e6xxx_stu_data_read(chip, &next);
1636 if (err)
1637 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001638 }
1639
1640 *entry = next;
1641 return 0;
1642}
1643
Vivien Didelotfad09c72016-06-21 12:28:20 -04001644static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001645 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001646{
1647 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001648 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001649
Vivien Didelota935c052016-09-29 12:21:53 -04001650 err = _mv88e6xxx_vtu_wait(chip);
1651 if (err)
1652 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001653
1654 if (!entry->valid)
1655 goto loadpurge;
1656
1657 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001658 err = mv88e6xxx_stu_data_write(chip, entry);
1659 if (err)
1660 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001661
1662 reg = GLOBAL_VTU_VID_VALID;
1663loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001664 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1665 if (err)
1666 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001667
1668 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001669 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1670 if (err)
1671 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001672
Vivien Didelotfad09c72016-06-21 12:28:20 -04001673 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001674}
1675
Vivien Didelotfad09c72016-06-21 12:28:20 -04001676static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001677{
1678 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001679 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001680 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001681
1682 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1683
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001684 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001685 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001686 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001687 if (err)
1688 return err;
1689
1690 set_bit(*fid, fid_bitmap);
1691 }
1692
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001693 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001694 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001695 if (err)
1696 return err;
1697
1698 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001699 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001700 if (err)
1701 return err;
1702
1703 if (!vlan.valid)
1704 break;
1705
1706 set_bit(vlan.fid, fid_bitmap);
1707 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1708
1709 /* The reset value 0x000 is used to indicate that multiple address
1710 * databases are not needed. Return the next positive available.
1711 */
1712 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001713 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001714 return -ENOSPC;
1715
1716 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001717 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001718}
1719
Vivien Didelotfad09c72016-06-21 12:28:20 -04001720static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001721 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001722{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001723 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001724 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001725 .valid = true,
1726 .vid = vid,
1727 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001728 int i, err;
1729
Vivien Didelotfad09c72016-06-21 12:28:20 -04001730 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001731 if (err)
1732 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001733
Vivien Didelot3d131f02015-11-03 10:52:52 -05001734 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001735 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001736 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1737 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1738 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001739
Vivien Didelotfad09c72016-06-21 12:28:20 -04001740 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01001741 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip) ||
1742 mv88e6xxx_6341_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001743 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001744
1745 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1746 * implemented, only one STU entry is needed to cover all VTU
1747 * entries. Thus, validate the SID 0.
1748 */
1749 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001750 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001751 if (err)
1752 return err;
1753
1754 if (vstp.sid != vlan.sid || !vstp.valid) {
1755 memset(&vstp, 0, sizeof(vstp));
1756 vstp.valid = true;
1757 vstp.sid = vlan.sid;
1758
Vivien Didelotfad09c72016-06-21 12:28:20 -04001759 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001760 if (err)
1761 return err;
1762 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001763 }
1764
1765 *entry = vlan;
1766 return 0;
1767}
1768
Vivien Didelotfad09c72016-06-21 12:28:20 -04001769static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001770 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001771{
1772 int err;
1773
1774 if (!vid)
1775 return -EINVAL;
1776
Vivien Didelotfad09c72016-06-21 12:28:20 -04001777 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001778 if (err)
1779 return err;
1780
Vivien Didelotfad09c72016-06-21 12:28:20 -04001781 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001782 if (err)
1783 return err;
1784
1785 if (entry->vid != vid || !entry->valid) {
1786 if (!creat)
1787 return -EOPNOTSUPP;
1788 /* -ENOENT would've been more appropriate, but switchdev expects
1789 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1790 */
1791
Vivien Didelotfad09c72016-06-21 12:28:20 -04001792 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001793 }
1794
1795 return err;
1796}
1797
Vivien Didelotda9c3592016-02-12 12:09:40 -05001798static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1799 u16 vid_begin, u16 vid_end)
1800{
Vivien Didelot04bed142016-08-31 18:06:13 -04001801 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001802 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001803 int i, err;
1804
1805 if (!vid_begin)
1806 return -EOPNOTSUPP;
1807
Vivien Didelotfad09c72016-06-21 12:28:20 -04001808 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001809
Vivien Didelotfad09c72016-06-21 12:28:20 -04001810 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001811 if (err)
1812 goto unlock;
1813
1814 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001815 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001816 if (err)
1817 goto unlock;
1818
1819 if (!vlan.valid)
1820 break;
1821
1822 if (vlan.vid > vid_end)
1823 break;
1824
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001825 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001826 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1827 continue;
1828
Andrew Lunn66e28092016-12-11 21:07:19 +01001829 if (!ds->ports[port].netdev)
1830 continue;
1831
Vivien Didelotda9c3592016-02-12 12:09:40 -05001832 if (vlan.data[i] ==
1833 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1834 continue;
1835
Vivien Didelotfae8a252017-01-27 15:29:42 -05001836 if (ds->ports[i].bridge_dev ==
1837 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001838 break; /* same bridge, check next VLAN */
1839
Vivien Didelotfae8a252017-01-27 15:29:42 -05001840 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001841 continue;
1842
Andrew Lunnc8b09802016-06-04 21:16:57 +02001843 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001844 "hardware VLAN %d already used by %s\n",
1845 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001846 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001847 err = -EOPNOTSUPP;
1848 goto unlock;
1849 }
1850 } while (vlan.vid < vid_end);
1851
1852unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001853 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001854
1855 return err;
1856}
1857
Vivien Didelotf81ec902016-05-09 13:22:58 -04001858static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1859 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001860{
Vivien Didelot04bed142016-08-31 18:06:13 -04001861 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001862 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001863 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001864 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001865
Vivien Didelotfad09c72016-06-21 12:28:20 -04001866 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001867 return -EOPNOTSUPP;
1868
Vivien Didelotfad09c72016-06-21 12:28:20 -04001869 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001870 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001871 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001872
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001873 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001874}
1875
Vivien Didelot57d32312016-06-20 13:13:58 -04001876static int
1877mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1878 const struct switchdev_obj_port_vlan *vlan,
1879 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001880{
Vivien Didelot04bed142016-08-31 18:06:13 -04001881 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001882 int err;
1883
Vivien Didelotfad09c72016-06-21 12:28:20 -04001884 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001885 return -EOPNOTSUPP;
1886
Vivien Didelotda9c3592016-02-12 12:09:40 -05001887 /* If the requested port doesn't belong to the same bridge as the VLAN
1888 * members, do not support it (yet) and fallback to software VLAN.
1889 */
1890 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1891 vlan->vid_end);
1892 if (err)
1893 return err;
1894
Vivien Didelot76e398a2015-11-01 12:33:55 -05001895 /* We don't need any dynamic resource from the kernel (yet),
1896 * so skip the prepare phase.
1897 */
1898 return 0;
1899}
1900
Vivien Didelotfad09c72016-06-21 12:28:20 -04001901static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001902 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001903{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001904 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001905 int err;
1906
Vivien Didelotfad09c72016-06-21 12:28:20 -04001907 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001908 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001909 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001910
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001911 vlan.data[port] = untagged ?
1912 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1913 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1914
Vivien Didelotfad09c72016-06-21 12:28:20 -04001915 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001916}
1917
Vivien Didelotf81ec902016-05-09 13:22:58 -04001918static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1919 const struct switchdev_obj_port_vlan *vlan,
1920 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001921{
Vivien Didelot04bed142016-08-31 18:06:13 -04001922 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001923 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1924 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1925 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001926
Vivien Didelotfad09c72016-06-21 12:28:20 -04001927 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001928 return;
1929
Vivien Didelotfad09c72016-06-21 12:28:20 -04001930 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001931
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001932 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001933 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001934 netdev_err(ds->ports[port].netdev,
1935 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001936 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001937
Vivien Didelot77064f32016-11-04 03:23:30 +01001938 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001939 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001940 vlan->vid_end);
1941
Vivien Didelotfad09c72016-06-21 12:28:20 -04001942 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001943}
1944
Vivien Didelotfad09c72016-06-21 12:28:20 -04001945static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001946 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001947{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001948 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001949 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001950 int i, err;
1951
Vivien Didelotfad09c72016-06-21 12:28:20 -04001952 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001953 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001954 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001955
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001956 /* Tell switchdev if this VLAN is handled in software */
1957 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001958 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001959
1960 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1961
1962 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001963 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001964 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001965 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001966 continue;
1967
1968 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001969 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001970 break;
1971 }
1972 }
1973
Vivien Didelotfad09c72016-06-21 12:28:20 -04001974 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001975 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001976 return err;
1977
Vivien Didelotfad09c72016-06-21 12:28:20 -04001978 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001979}
1980
Vivien Didelotf81ec902016-05-09 13:22:58 -04001981static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1982 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001983{
Vivien Didelot04bed142016-08-31 18:06:13 -04001984 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001985 u16 pvid, vid;
1986 int err = 0;
1987
Vivien Didelotfad09c72016-06-21 12:28:20 -04001988 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001989 return -EOPNOTSUPP;
1990
Vivien Didelotfad09c72016-06-21 12:28:20 -04001991 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001992
Vivien Didelot77064f32016-11-04 03:23:30 +01001993 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001994 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001995 goto unlock;
1996
Vivien Didelot76e398a2015-11-01 12:33:55 -05001997 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001998 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001999 if (err)
2000 goto unlock;
2001
2002 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01002003 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002004 if (err)
2005 goto unlock;
2006 }
2007 }
2008
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002009unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002010 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002011
2012 return err;
2013}
2014
Vivien Didelotfad09c72016-06-21 12:28:20 -04002015static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04002016 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002017{
Vivien Didelota935c052016-09-29 12:21:53 -04002018 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002019
2020 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002021 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
2022 (addr[i * 2] << 8) | addr[i * 2 + 1]);
2023 if (err)
2024 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002025 }
2026
2027 return 0;
2028}
2029
Vivien Didelotfad09c72016-06-21 12:28:20 -04002030static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04002031 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002032{
Vivien Didelota935c052016-09-29 12:21:53 -04002033 u16 val;
2034 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002035
2036 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002037 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
2038 if (err)
2039 return err;
2040
2041 addr[i * 2] = val >> 8;
2042 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002043 }
2044
2045 return 0;
2046}
2047
Vivien Didelotfad09c72016-06-21 12:28:20 -04002048static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04002049 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002050{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002051 int ret;
2052
Vivien Didelotfad09c72016-06-21 12:28:20 -04002053 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002054 if (ret < 0)
2055 return ret;
2056
Vivien Didelotfad09c72016-06-21 12:28:20 -04002057 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002058 if (ret < 0)
2059 return ret;
2060
Vivien Didelotfad09c72016-06-21 12:28:20 -04002061 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002062 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002063 return ret;
2064
Vivien Didelotfad09c72016-06-21 12:28:20 -04002065 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002066}
David S. Millercdf09692015-08-11 12:00:37 -07002067
Vivien Didelot88472932016-09-19 19:56:11 -04002068static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2069 struct mv88e6xxx_atu_entry *entry);
2070
2071static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2072 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2073{
2074 struct mv88e6xxx_atu_entry next;
2075 int err;
2076
Andrew Lunn59527582017-01-04 19:56:24 +01002077 memcpy(next.mac, addr, ETH_ALEN);
2078 eth_addr_dec(next.mac);
Vivien Didelot88472932016-09-19 19:56:11 -04002079
2080 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2081 if (err)
2082 return err;
2083
2084 do {
2085 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2086 if (err)
2087 return err;
2088
2089 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2090 break;
2091
2092 if (ether_addr_equal(next.mac, addr)) {
2093 *entry = next;
2094 return 0;
2095 }
Andrew Lunn59527582017-01-04 19:56:24 +01002096 } while (ether_addr_greater(addr, next.mac));
Vivien Didelot88472932016-09-19 19:56:11 -04002097
2098 memset(entry, 0, sizeof(*entry));
2099 entry->fid = fid;
2100 ether_addr_copy(entry->mac, addr);
2101
2102 return 0;
2103}
2104
Vivien Didelot83dabd12016-08-31 11:50:04 -04002105static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2106 const unsigned char *addr, u16 vid,
2107 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002108{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002109 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002110 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002111 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002112
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002113 /* Null VLAN ID corresponds to the port private database */
2114 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002115 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002116 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002117 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002118 if (err)
2119 return err;
2120
Vivien Didelot88472932016-09-19 19:56:11 -04002121 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2122 if (err)
2123 return err;
2124
2125 /* Purge the ATU entry only if no port is using it anymore */
2126 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2127 entry.portv_trunkid &= ~BIT(port);
2128 if (!entry.portv_trunkid)
2129 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2130 } else {
2131 entry.portv_trunkid |= BIT(port);
2132 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002133 }
2134
Vivien Didelotfad09c72016-06-21 12:28:20 -04002135 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002136}
2137
Vivien Didelotf81ec902016-05-09 13:22:58 -04002138static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2139 const struct switchdev_obj_port_fdb *fdb,
2140 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002141{
2142 /* We don't need any dynamic resource from the kernel (yet),
2143 * so skip the prepare phase.
2144 */
2145 return 0;
2146}
2147
Vivien Didelotf81ec902016-05-09 13:22:58 -04002148static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2149 const struct switchdev_obj_port_fdb *fdb,
2150 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002151{
Vivien Didelot04bed142016-08-31 18:06:13 -04002152 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002153
Vivien Didelotfad09c72016-06-21 12:28:20 -04002154 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002155 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2156 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2157 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002158 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002159}
2160
Vivien Didelotf81ec902016-05-09 13:22:58 -04002161static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2162 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002163{
Vivien Didelot04bed142016-08-31 18:06:13 -04002164 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002165 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002166
Vivien Didelotfad09c72016-06-21 12:28:20 -04002167 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002168 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2169 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002170 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002171
Vivien Didelot83dabd12016-08-31 11:50:04 -04002172 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002173}
2174
Vivien Didelotfad09c72016-06-21 12:28:20 -04002175static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002176 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002177{
Vivien Didelot1d194042015-08-10 09:09:51 -04002178 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002179 u16 val;
2180 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002181
2182 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002183
Vivien Didelota935c052016-09-29 12:21:53 -04002184 err = _mv88e6xxx_atu_wait(chip);
2185 if (err)
2186 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002187
Vivien Didelota935c052016-09-29 12:21:53 -04002188 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2189 if (err)
2190 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002191
Vivien Didelota935c052016-09-29 12:21:53 -04002192 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2193 if (err)
2194 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002195
Vivien Didelota935c052016-09-29 12:21:53 -04002196 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2197 if (err)
2198 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002199
Vivien Didelota935c052016-09-29 12:21:53 -04002200 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002201 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2202 unsigned int mask, shift;
2203
Vivien Didelota935c052016-09-29 12:21:53 -04002204 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002205 next.trunk = true;
2206 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2207 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2208 } else {
2209 next.trunk = false;
2210 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2211 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2212 }
2213
Vivien Didelota935c052016-09-29 12:21:53 -04002214 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002215 }
2216
2217 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002218 return 0;
2219}
2220
Vivien Didelot83dabd12016-08-31 11:50:04 -04002221static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2222 u16 fid, u16 vid, int port,
2223 struct switchdev_obj *obj,
2224 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002225{
2226 struct mv88e6xxx_atu_entry addr = {
2227 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2228 };
2229 int err;
2230
Vivien Didelotfad09c72016-06-21 12:28:20 -04002231 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002232 if (err)
2233 return err;
2234
2235 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002236 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002237 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002238 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002239
2240 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2241 break;
2242
Vivien Didelot83dabd12016-08-31 11:50:04 -04002243 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2244 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002245
Vivien Didelot83dabd12016-08-31 11:50:04 -04002246 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2247 struct switchdev_obj_port_fdb *fdb;
2248
2249 if (!is_unicast_ether_addr(addr.mac))
2250 continue;
2251
2252 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002253 fdb->vid = vid;
2254 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002255 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2256 fdb->ndm_state = NUD_NOARP;
2257 else
2258 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002259 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2260 struct switchdev_obj_port_mdb *mdb;
2261
2262 if (!is_multicast_ether_addr(addr.mac))
2263 continue;
2264
2265 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2266 mdb->vid = vid;
2267 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002268 } else {
2269 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002270 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002271
2272 err = cb(obj);
2273 if (err)
2274 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002275 } while (!is_broadcast_ether_addr(addr.mac));
2276
2277 return err;
2278}
2279
Vivien Didelot83dabd12016-08-31 11:50:04 -04002280static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2281 struct switchdev_obj *obj,
2282 int (*cb)(struct switchdev_obj *obj))
2283{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002284 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002285 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2286 };
2287 u16 fid;
2288 int err;
2289
2290 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002291 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002292 if (err)
2293 return err;
2294
2295 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2296 if (err)
2297 return err;
2298
2299 /* Dump VLANs' Filtering Information Databases */
2300 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2301 if (err)
2302 return err;
2303
2304 do {
2305 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2306 if (err)
2307 return err;
2308
2309 if (!vlan.valid)
2310 break;
2311
2312 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2313 obj, cb);
2314 if (err)
2315 return err;
2316 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2317
2318 return err;
2319}
2320
Vivien Didelotf81ec902016-05-09 13:22:58 -04002321static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2322 struct switchdev_obj_port_fdb *fdb,
2323 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002324{
Vivien Didelot04bed142016-08-31 18:06:13 -04002325 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002326 int err;
2327
Vivien Didelotfad09c72016-06-21 12:28:20 -04002328 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002329 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002330 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002331
2332 return err;
2333}
2334
Vivien Didelotf81ec902016-05-09 13:22:58 -04002335static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002336 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002337{
Vivien Didelot04bed142016-08-31 18:06:13 -04002338 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002339 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002340
Vivien Didelotfad09c72016-06-21 12:28:20 -04002341 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002342
Vivien Didelotfae8a252017-01-27 15:29:42 -05002343 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002344 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfae8a252017-01-27 15:29:42 -05002345 if (ds->ports[i].bridge_dev == br) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002346 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002347 if (err)
2348 break;
2349 }
2350 }
2351
Vivien Didelotfad09c72016-06-21 12:28:20 -04002352 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002353
Vivien Didelot466dfa02016-02-26 13:16:05 -05002354 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002355}
2356
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002357static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2358 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002359{
Vivien Didelot04bed142016-08-31 18:06:13 -04002360 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002361 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002362
Vivien Didelotfad09c72016-06-21 12:28:20 -04002363 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002364
Vivien Didelotfae8a252017-01-27 15:29:42 -05002365 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002366 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfae8a252017-01-27 15:29:42 -05002367 if (i == port || ds->ports[i].bridge_dev == br)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002368 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002369 netdev_warn(ds->ports[i].netdev,
2370 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002371
Vivien Didelotfad09c72016-06-21 12:28:20 -04002372 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002373}
2374
Vivien Didelot17e708b2016-12-05 17:30:27 -05002375static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2376{
2377 if (chip->info->ops->reset)
2378 return chip->info->ops->reset(chip);
2379
2380 return 0;
2381}
2382
Vivien Didelot309eca62016-12-05 17:30:26 -05002383static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2384{
2385 struct gpio_desc *gpiod = chip->reset;
2386
2387 /* If there is a GPIO connected to the reset pin, toggle it */
2388 if (gpiod) {
2389 gpiod_set_value_cansleep(gpiod, 1);
2390 usleep_range(10000, 20000);
2391 gpiod_set_value_cansleep(gpiod, 0);
2392 usleep_range(10000, 20000);
2393 }
2394}
2395
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002396static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2397{
2398 int i, err;
2399
2400 /* Set all ports to the Disabled state */
2401 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2402 err = mv88e6xxx_port_set_state(chip, i,
2403 PORT_CONTROL_STATE_DISABLED);
2404 if (err)
2405 return err;
2406 }
2407
2408 /* Wait for transmit queues to drain,
2409 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2410 */
2411 usleep_range(2000, 4000);
2412
2413 return 0;
2414}
2415
Vivien Didelotfad09c72016-06-21 12:28:20 -04002416static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002417{
Vivien Didelota935c052016-09-29 12:21:53 -04002418 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002419
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002420 err = mv88e6xxx_disable_ports(chip);
2421 if (err)
2422 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002423
Vivien Didelot309eca62016-12-05 17:30:26 -05002424 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002425
Vivien Didelot17e708b2016-12-05 17:30:27 -05002426 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002427}
2428
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002429static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002430{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002431 u16 val;
2432 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002433
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002434 /* Clear Power Down bit */
2435 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2436 if (err)
2437 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002438
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002439 if (val & BMCR_PDOWN) {
2440 val &= ~BMCR_PDOWN;
2441 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002442 }
2443
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002444 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002445}
2446
Andrew Lunn56995cb2016-12-03 04:35:19 +01002447static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2448 int upstream_port)
2449{
2450 int err;
2451
2452 err = chip->info->ops->port_set_frame_mode(
2453 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2454 if (err)
2455 return err;
2456
2457 return chip->info->ops->port_set_egress_unknowns(
2458 chip, port, port == upstream_port);
2459}
2460
2461static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2462{
2463 int err;
2464
2465 switch (chip->info->tag_protocol) {
2466 case DSA_TAG_PROTO_EDSA:
2467 err = chip->info->ops->port_set_frame_mode(
2468 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2469 if (err)
2470 return err;
2471
2472 err = mv88e6xxx_port_set_egress_mode(
2473 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2474 if (err)
2475 return err;
2476
2477 if (chip->info->ops->port_set_ether_type)
2478 err = chip->info->ops->port_set_ether_type(
2479 chip, port, ETH_P_EDSA);
2480 break;
2481
2482 case DSA_TAG_PROTO_DSA:
2483 err = chip->info->ops->port_set_frame_mode(
2484 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2485 if (err)
2486 return err;
2487
2488 err = mv88e6xxx_port_set_egress_mode(
2489 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2490 break;
2491 default:
2492 err = -EINVAL;
2493 }
2494
2495 if (err)
2496 return err;
2497
2498 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2499}
2500
2501static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2502{
2503 int err;
2504
2505 err = chip->info->ops->port_set_frame_mode(
2506 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2507 if (err)
2508 return err;
2509
2510 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2511}
2512
Vivien Didelotea698f42017-03-11 16:12:50 -05002513static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2514{
2515 bool message = dsa_is_dsa_port(chip->ds, port);
2516
2517 return mv88e6xxx_port_set_message_port(chip, port, message);
2518}
2519
Vivien Didelotfad09c72016-06-21 12:28:20 -04002520static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002521{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002522 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002523 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002524 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002525
Vivien Didelotd78343d2016-11-04 03:23:36 +01002526 /* MAC Forcing register: don't force link, speed, duplex or flow control
2527 * state to any particular values on physical ports, but force the CPU
2528 * port and all DSA ports to their maximum bandwidth and full duplex.
2529 */
2530 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2531 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2532 SPEED_MAX, DUPLEX_FULL,
2533 PHY_INTERFACE_MODE_NA);
2534 else
2535 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2536 SPEED_UNFORCED, DUPLEX_UNFORCED,
2537 PHY_INTERFACE_MODE_NA);
2538 if (err)
2539 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002540
2541 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2542 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2543 * tunneling, determine priority by looking at 802.1p and IP
2544 * priority fields (IP prio has precedence), and set STP state
2545 * to Forwarding.
2546 *
2547 * If this is the CPU link, use DSA or EDSA tagging depending
2548 * on which tagging mode was configured.
2549 *
2550 * If this is a link to another switch, use DSA tagging mode.
2551 *
2552 * If this is the upstream port for this switch, enable
2553 * forwarding of unknown unicasts and multicasts.
2554 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002555 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002556 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2557 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002558 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2559 if (err)
2560 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002561
Andrew Lunn56995cb2016-12-03 04:35:19 +01002562 if (dsa_is_cpu_port(ds, port)) {
2563 err = mv88e6xxx_setup_port_cpu(chip, port);
2564 } else if (dsa_is_dsa_port(ds, port)) {
2565 err = mv88e6xxx_setup_port_dsa(chip, port,
2566 dsa_upstream_port(ds));
2567 } else {
2568 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002569 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002570 if (err)
2571 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002572
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002573 /* If this port is connected to a SerDes, make sure the SerDes is not
2574 * powered down.
2575 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002576 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002577 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2578 if (err)
2579 return err;
2580 reg &= PORT_STATUS_CMODE_MASK;
2581 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2582 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2583 (reg == PORT_STATUS_CMODE_SGMII)) {
2584 err = mv88e6xxx_serdes_power_on(chip);
2585 if (err < 0)
2586 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002587 }
2588 }
2589
Vivien Didelot8efdda42015-08-13 12:52:23 -04002590 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002591 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002592 * untagged frames on this port, do a destination address lookup on all
2593 * received packets as usual, disable ARP mirroring and don't send a
2594 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002595 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002596 err = mv88e6xxx_port_set_map_da(chip, port);
2597 if (err)
2598 return err;
2599
Andrew Lunn54d792f2015-05-06 01:09:47 +02002600 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01002601 if (chip->info->ops->port_set_upstream_port) {
2602 err = chip->info->ops->port_set_upstream_port(
2603 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002604 if (err)
2605 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002606 }
2607
Andrew Lunna23b2962017-02-04 20:15:28 +01002608 err = mv88e6xxx_port_set_8021q_mode(chip, port,
2609 PORT_CONTROL_2_8021Q_DISABLED);
2610 if (err)
2611 return err;
2612
Andrew Lunn5f436662016-12-03 04:45:17 +01002613 if (chip->info->ops->port_jumbo_config) {
2614 err = chip->info->ops->port_jumbo_config(chip, port);
2615 if (err)
2616 return err;
2617 }
2618
Andrew Lunn54d792f2015-05-06 01:09:47 +02002619 /* Port Association Vector: when learning source addresses
2620 * of packets, add the address to the address database using
2621 * a port bitmap that has only the bit for this port set and
2622 * the other bits clear.
2623 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002624 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002625 /* Disable learning for CPU port */
2626 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002627 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002628
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002629 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2630 if (err)
2631 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002632
2633 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002634 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2635 if (err)
2636 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002637
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002638 if (chip->info->ops->port_pause_config) {
2639 err = chip->info->ops->port_pause_config(chip, port);
2640 if (err)
2641 return err;
2642 }
2643
Vivien Didelotfad09c72016-06-21 12:28:20 -04002644 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2645 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01002646 mv88e6xxx_6320_family(chip) || mv88e6xxx_6341_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002647 /* Port ATU control: disable limiting the number of
2648 * address database entries that this port is allowed
2649 * to use.
2650 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002651 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2652 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002653 /* Priority Override: disable DA, SA and VTU priority
2654 * override.
2655 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002656 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2657 0x0000);
2658 if (err)
2659 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002660 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002661
Andrew Lunnef0a7312016-12-03 04:35:16 +01002662 if (chip->info->ops->port_tag_remap) {
2663 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002664 if (err)
2665 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002666 }
2667
Andrew Lunnef70b112016-12-03 04:45:18 +01002668 if (chip->info->ops->port_egress_rate_limiting) {
2669 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002670 if (err)
2671 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002672 }
2673
Vivien Didelotea698f42017-03-11 16:12:50 -05002674 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002675 if (err)
2676 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002677
Vivien Didelot207afda2016-04-14 14:42:09 -04002678 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002679 * database, and allow bidirectional communication between the
2680 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002681 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002682 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002683 if (err)
2684 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002685
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002686 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2687 if (err)
2688 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002689
2690 /* Default VLAN ID and priority: don't set a default VLAN
2691 * ID, and set the default packet priority to zero.
2692 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002693 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002694}
2695
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002696static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002697{
2698 int err;
2699
Vivien Didelota935c052016-09-29 12:21:53 -04002700 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002701 if (err)
2702 return err;
2703
Vivien Didelota935c052016-09-29 12:21:53 -04002704 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002705 if (err)
2706 return err;
2707
Vivien Didelota935c052016-09-29 12:21:53 -04002708 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2709 if (err)
2710 return err;
2711
2712 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002713}
2714
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002715static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2716 unsigned int ageing_time)
2717{
Vivien Didelot04bed142016-08-31 18:06:13 -04002718 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002719 int err;
2720
2721 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002722 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002723 mutex_unlock(&chip->reg_lock);
2724
2725 return err;
2726}
2727
Vivien Didelot97299342016-07-18 20:45:30 -04002728static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002729{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002730 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002731 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002732 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002733
Vivien Didelot119477b2016-05-09 13:22:51 -04002734 /* Enable the PHY Polling Unit if present, don't discard any packets,
2735 * and mask all interrupt sources.
2736 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002737 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002738 if (err)
2739 return err;
2740
Andrew Lunn33641992016-12-03 04:35:17 +01002741 if (chip->info->ops->g1_set_cpu_port) {
2742 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2743 if (err)
2744 return err;
2745 }
2746
2747 if (chip->info->ops->g1_set_egress_port) {
2748 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2749 if (err)
2750 return err;
2751 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002752
Vivien Didelot50484ff2016-05-09 13:22:54 -04002753 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002754 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2755 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2756 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002757 if (err)
2758 return err;
2759
Vivien Didelotacddbd22016-07-18 20:45:39 -04002760 /* Clear all the VTU and STU entries */
2761 err = _mv88e6xxx_vtu_stu_flush(chip);
2762 if (err < 0)
2763 return err;
2764
Vivien Didelot97299342016-07-18 20:45:30 -04002765 /* Clear all ATU entries */
2766 err = _mv88e6xxx_atu_flush(chip, 0, true);
2767 if (err)
2768 return err;
2769
Vivien Didelot08a01262016-05-09 13:22:50 -04002770 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002771 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002772 if (err)
2773 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002774 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 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_2, 0x5555);
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_3, 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_4, 0xaaaa);
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_5, 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_6, 0xffff);
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_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002793 if (err)
2794 return err;
2795
2796 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002797 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002798 if (err)
2799 return err;
2800
Andrew Lunnde2273872016-11-21 23:27:01 +01002801 /* Initialize the statistics unit */
2802 err = mv88e6xxx_stats_set_histogram(chip);
2803 if (err)
2804 return err;
2805
Vivien Didelot97299342016-07-18 20:45:30 -04002806 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002807 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2808 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002809 if (err)
2810 return err;
2811
2812 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002813 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002814 if (err)
2815 return err;
2816
2817 return 0;
2818}
2819
Vivien Didelotf81ec902016-05-09 13:22:58 -04002820static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002821{
Vivien Didelot04bed142016-08-31 18:06:13 -04002822 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002823 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002824 int i;
2825
Vivien Didelotfad09c72016-06-21 12:28:20 -04002826 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002827 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002828
Vivien Didelotfad09c72016-06-21 12:28:20 -04002829 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002830
Vivien Didelot97299342016-07-18 20:45:30 -04002831 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002832 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002833 err = mv88e6xxx_setup_port(chip, i);
2834 if (err)
2835 goto unlock;
2836 }
2837
2838 /* Setup Switch Global 1 Registers */
2839 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002840 if (err)
2841 goto unlock;
2842
Vivien Didelot97299342016-07-18 20:45:30 -04002843 /* Setup Switch Global 2 Registers */
2844 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2845 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002846 if (err)
2847 goto unlock;
2848 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002849
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002850 err = mv88e6xxx_atu_setup(chip);
2851 if (err)
2852 goto unlock;
2853
Andrew Lunn6e55f692016-12-03 04:45:16 +01002854 /* Some generations have the configuration of sending reserved
2855 * management frames to the CPU in global2, others in
2856 * global1. Hence it does not fit the two setup functions
2857 * above.
2858 */
2859 if (chip->info->ops->mgmt_rsvd2cpu) {
2860 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2861 if (err)
2862 goto unlock;
2863 }
2864
Vivien Didelot6b17e862015-08-13 12:52:18 -04002865unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002866 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002867
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002868 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002869}
2870
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002871static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2872{
Vivien Didelot04bed142016-08-31 18:06:13 -04002873 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002874 int err;
2875
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002876 if (!chip->info->ops->set_switch_mac)
2877 return -EOPNOTSUPP;
2878
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002879 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002880 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002881 mutex_unlock(&chip->reg_lock);
2882
2883 return err;
2884}
2885
Vivien Didelote57e5e72016-08-15 17:19:00 -04002886static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002887{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002888 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2889 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002890 u16 val;
2891 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002892
Andrew Lunnee26a222017-01-24 14:53:48 +01002893 if (!chip->info->ops->phy_read)
2894 return -EOPNOTSUPP;
2895
Vivien Didelotfad09c72016-06-21 12:28:20 -04002896 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002897 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002898 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002899
Andrew Lunnda9f3302017-02-01 03:40:05 +01002900 if (reg == MII_PHYSID2) {
2901 /* Some internal PHYS don't have a model number. Use
2902 * the mv88e6390 family model number instead.
2903 */
2904 if (!(val & 0x3f0))
2905 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2906 }
2907
Vivien Didelote57e5e72016-08-15 17:19:00 -04002908 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002909}
2910
Vivien Didelote57e5e72016-08-15 17:19:00 -04002911static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002912{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002913 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2914 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002915 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002916
Andrew Lunnee26a222017-01-24 14:53:48 +01002917 if (!chip->info->ops->phy_write)
2918 return -EOPNOTSUPP;
2919
Vivien Didelotfad09c72016-06-21 12:28:20 -04002920 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002921 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002922 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002923
2924 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002925}
2926
Vivien Didelotfad09c72016-06-21 12:28:20 -04002927static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002928 struct device_node *np,
2929 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002930{
2931 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002932 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002933 struct mii_bus *bus;
2934 int err;
2935
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002936 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002937 if (!bus)
2938 return -ENOMEM;
2939
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002940 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002941 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002942 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002943 INIT_LIST_HEAD(&mdio_bus->list);
2944 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002945
Andrew Lunnb516d452016-06-04 21:17:06 +02002946 if (np) {
2947 bus->name = np->full_name;
2948 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2949 } else {
2950 bus->name = "mv88e6xxx SMI";
2951 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2952 }
2953
2954 bus->read = mv88e6xxx_mdio_read;
2955 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002956 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002957
Andrew Lunna3c53be52017-01-24 14:53:50 +01002958 if (np)
2959 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002960 else
2961 err = mdiobus_register(bus);
2962 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002963 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002964 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002965 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002966
2967 if (external)
2968 list_add_tail(&mdio_bus->list, &chip->mdios);
2969 else
2970 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002971
2972 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002973}
2974
Andrew Lunna3c53be52017-01-24 14:53:50 +01002975static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2976 { .compatible = "marvell,mv88e6xxx-mdio-external",
2977 .data = (void *)true },
2978 { },
2979};
2980
2981static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2982 struct device_node *np)
2983{
2984 const struct of_device_id *match;
2985 struct device_node *child;
2986 int err;
2987
2988 /* Always register one mdio bus for the internal/default mdio
2989 * bus. This maybe represented in the device tree, but is
2990 * optional.
2991 */
2992 child = of_get_child_by_name(np, "mdio");
2993 err = mv88e6xxx_mdio_register(chip, child, false);
2994 if (err)
2995 return err;
2996
2997 /* Walk the device tree, and see if there are any other nodes
2998 * which say they are compatible with the external mdio
2999 * bus.
3000 */
3001 for_each_available_child_of_node(np, child) {
3002 match = of_match_node(mv88e6xxx_mdio_external_match, child);
3003 if (match) {
3004 err = mv88e6xxx_mdio_register(chip, child, true);
3005 if (err)
3006 return err;
3007 }
3008 }
3009
3010 return 0;
3011}
3012
3013static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02003014
3015{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003016 struct mv88e6xxx_mdio_bus *mdio_bus;
3017 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003018
Andrew Lunna3c53be52017-01-24 14:53:50 +01003019 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3020 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003021
Andrew Lunna3c53be52017-01-24 14:53:50 +01003022 mdiobus_unregister(bus);
3023 }
Andrew Lunnb516d452016-06-04 21:17:06 +02003024}
3025
Vivien Didelot855b1932016-07-20 18:18:35 -04003026static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3027{
Vivien Didelot04bed142016-08-31 18:06:13 -04003028 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003029
3030 return chip->eeprom_len;
3031}
3032
Vivien Didelot855b1932016-07-20 18:18:35 -04003033static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3034 struct ethtool_eeprom *eeprom, u8 *data)
3035{
Vivien Didelot04bed142016-08-31 18:06:13 -04003036 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003037 int err;
3038
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003039 if (!chip->info->ops->get_eeprom)
3040 return -EOPNOTSUPP;
3041
Vivien Didelot855b1932016-07-20 18:18:35 -04003042 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003043 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003044 mutex_unlock(&chip->reg_lock);
3045
3046 if (err)
3047 return err;
3048
3049 eeprom->magic = 0xc3ec4951;
3050
3051 return 0;
3052}
3053
Vivien Didelot855b1932016-07-20 18:18:35 -04003054static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3055 struct ethtool_eeprom *eeprom, u8 *data)
3056{
Vivien Didelot04bed142016-08-31 18:06:13 -04003057 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003058 int err;
3059
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003060 if (!chip->info->ops->set_eeprom)
3061 return -EOPNOTSUPP;
3062
Vivien Didelot855b1932016-07-20 18:18:35 -04003063 if (eeprom->magic != 0xc3ec4951)
3064 return -EINVAL;
3065
3066 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003067 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003068 mutex_unlock(&chip->reg_lock);
3069
3070 return err;
3071}
3072
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003073static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003074 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003075 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003076 .phy_read = mv88e6xxx_phy_ppu_read,
3077 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003078 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003079 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003080 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003081 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003082 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3083 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3084 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003085 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003086 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003087 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003088 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3089 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003090 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003091 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3092 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003093 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003094 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003095 .ppu_enable = mv88e6185_g1_ppu_enable,
3096 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003097 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003098};
3099
3100static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003101 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003102 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003103 .phy_read = mv88e6xxx_phy_ppu_read,
3104 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003105 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003106 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003107 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003108 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01003109 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
3110 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003111 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003112 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3113 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003114 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003115 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003116 .ppu_enable = mv88e6185_g1_ppu_enable,
3117 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003118 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003119};
3120
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003121static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003122 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003123 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3124 .phy_read = mv88e6xxx_g2_smi_phy_read,
3125 .phy_write = mv88e6xxx_g2_smi_phy_write,
3126 .port_set_link = mv88e6xxx_port_set_link,
3127 .port_set_duplex = mv88e6xxx_port_set_duplex,
3128 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003129 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003130 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3131 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3132 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003133 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003134 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003135 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003136 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3137 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3138 .stats_get_strings = mv88e6095_stats_get_strings,
3139 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003140 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3141 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01003142 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003143 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003144 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003145};
3146
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003147static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003148 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003149 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003150 .phy_read = mv88e6165_phy_read,
3151 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003152 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003153 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003154 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003155 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3156 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003157 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003158 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3159 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003160 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003161 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3162 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003163 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003164 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003165 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003166};
3167
3168static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003169 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003170 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003171 .phy_read = mv88e6xxx_phy_ppu_read,
3172 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003173 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003174 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003175 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003176 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003177 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01003178 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003179 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01003180 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01003181 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003182 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003183 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003184 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003185 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3186 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003187 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003188 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3189 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003190 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003191 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003192 .ppu_enable = mv88e6185_g1_ppu_enable,
3193 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003194 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003195};
3196
3197static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003198 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003199 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003200 .phy_read = mv88e6165_phy_read,
3201 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003202 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003203 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003204 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003205 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003206 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3207 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3208 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003209 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003210 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003211 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003212 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003213 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3214 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003215 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003216 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3217 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003218 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003219 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003220 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003221};
3222
3223static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003224 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003225 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003226 .phy_read = mv88e6165_phy_read,
3227 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003228 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003229 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003230 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003231 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003232 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3233 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003234 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003235 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3236 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003237 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003238 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003239 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003240};
3241
3242static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003243 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003244 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003245 .phy_read = mv88e6xxx_g2_smi_phy_read,
3246 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003247 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003248 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003249 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003250 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003251 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003252 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3253 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3254 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003255 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003256 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003257 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003258 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003259 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3260 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003261 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003262 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3263 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003264 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003265 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003266 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003267};
3268
3269static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003270 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003271 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3272 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003273 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003274 .phy_read = mv88e6xxx_g2_smi_phy_read,
3275 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003276 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003277 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003278 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003279 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003280 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003281 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3282 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3283 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003284 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003285 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003286 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003287 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003288 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3289 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003290 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003291 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3292 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003293 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003294 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003295 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003296};
3297
3298static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003299 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003300 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003301 .phy_read = mv88e6xxx_g2_smi_phy_read,
3302 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003303 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003304 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003305 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003306 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003307 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003308 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3309 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3310 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003311 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003312 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003313 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003314 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003315 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3316 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003317 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003318 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3319 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003320 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003321 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003322 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003323};
3324
3325static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003326 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003327 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3328 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003329 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003330 .phy_read = mv88e6xxx_g2_smi_phy_read,
3331 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003332 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003333 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003334 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003335 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003336 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003337 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3338 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3339 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003340 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003341 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003342 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003343 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003344 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3345 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003346 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003347 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3348 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003349 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003350 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003351 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003352};
3353
3354static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003355 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003356 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003357 .phy_read = mv88e6xxx_phy_ppu_read,
3358 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003359 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003360 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003361 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003362 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Andrew Lunna23b2962017-02-04 20:15:28 +01003363 .port_set_egress_unknowns = mv88e6095_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003364 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003365 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003366 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003367 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3368 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003369 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003370 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3371 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003372 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003373 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003374 .ppu_enable = mv88e6185_g1_ppu_enable,
3375 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003376 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003377};
3378
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003379static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003380 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003381 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3382 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003383 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3384 .phy_read = mv88e6xxx_g2_smi_phy_read,
3385 .phy_write = mv88e6xxx_g2_smi_phy_write,
3386 .port_set_link = mv88e6xxx_port_set_link,
3387 .port_set_duplex = mv88e6xxx_port_set_duplex,
3388 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3389 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003390 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003391 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3392 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3393 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003394 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003395 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003396 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003397 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3398 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003399 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003400 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3401 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003402 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003403 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003404 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003405};
3406
3407static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003408 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003409 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3410 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003411 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3412 .phy_read = mv88e6xxx_g2_smi_phy_read,
3413 .phy_write = mv88e6xxx_g2_smi_phy_write,
3414 .port_set_link = mv88e6xxx_port_set_link,
3415 .port_set_duplex = mv88e6xxx_port_set_duplex,
3416 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3417 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003418 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003419 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3420 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3421 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003422 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003423 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003424 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003425 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3426 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003427 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003428 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3429 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003430 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003431 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003432 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003433};
3434
3435static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003436 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003437 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3438 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003439 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3440 .phy_read = mv88e6xxx_g2_smi_phy_read,
3441 .phy_write = mv88e6xxx_g2_smi_phy_write,
3442 .port_set_link = mv88e6xxx_port_set_link,
3443 .port_set_duplex = mv88e6xxx_port_set_duplex,
3444 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3445 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003446 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003447 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3448 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3449 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003450 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003451 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003452 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003453 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3454 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003455 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003456 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3457 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003458 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003459 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003460 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003461};
3462
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003463static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003464 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003465 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3466 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003467 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003468 .phy_read = mv88e6xxx_g2_smi_phy_read,
3469 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003470 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003471 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003472 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003473 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003474 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003475 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3476 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3477 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003478 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003479 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003480 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003481 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003482 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3483 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003484 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003485 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3486 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003487 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003488 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003489 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003490};
3491
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003492static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003493 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003494 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3495 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003496 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3497 .phy_read = mv88e6xxx_g2_smi_phy_read,
3498 .phy_write = mv88e6xxx_g2_smi_phy_write,
3499 .port_set_link = mv88e6xxx_port_set_link,
3500 .port_set_duplex = mv88e6xxx_port_set_duplex,
3501 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3502 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003503 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003504 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3505 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3506 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003507 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003508 .port_set_cmode = mv88e6390x_port_set_cmode,
Andrew Lunn79523472016-11-21 23:27:00 +01003509 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003510 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003511 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3512 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003513 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003514 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3515 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003516 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003517 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003518 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003519};
3520
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003521static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003522 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003523 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3524 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003525 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003526 .phy_read = mv88e6xxx_g2_smi_phy_read,
3527 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003528 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003529 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003530 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003531 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003532 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3533 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3534 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003535 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003536 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003537 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003538 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003539 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3540 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003541 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003542 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3543 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003544 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003545 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003546};
3547
3548static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003549 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003550 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3551 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003552 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003553 .phy_read = mv88e6xxx_g2_smi_phy_read,
3554 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003555 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003556 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003557 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003558 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003559 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3560 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3561 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003562 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003563 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003564 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003565 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003566 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3567 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003568 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003569 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3570 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003571 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003572};
3573
3574static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003575 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003576 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003577 .phy_read = mv88e6xxx_g2_smi_phy_read,
3578 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003579 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003580 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003581 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003582 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003583 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003584 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3585 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3586 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003587 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003588 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003589 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003590 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003591 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3592 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003593 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003594 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3595 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003596 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003597 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003598 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003599};
3600
3601static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003602 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003603 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003604 .phy_read = mv88e6xxx_g2_smi_phy_read,
3605 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003606 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003607 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003608 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003609 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003610 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003611 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3612 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3613 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003614 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003615 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003616 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003617 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003618 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3619 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003620 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003621 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3622 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003623 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003624 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003625 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003626};
3627
3628static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003629 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003630 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3631 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003632 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003633 .phy_read = mv88e6xxx_g2_smi_phy_read,
3634 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003635 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003636 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003637 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003638 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003639 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003640 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3641 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3642 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003643 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003644 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003645 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003646 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003647 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3648 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003649 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003650 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3651 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003652 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003653 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003654 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003655};
3656
Gregory CLEMENT15587272017-01-30 20:29:35 +01003657static const struct mv88e6xxx_ops mv88e6141_ops = {
3658 /* MV88E6XXX_FAMILY_6341 */
3659 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3660 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3661 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3662 .phy_read = mv88e6xxx_g2_smi_phy_read,
3663 .phy_write = mv88e6xxx_g2_smi_phy_write,
3664 .port_set_link = mv88e6xxx_port_set_link,
3665 .port_set_duplex = mv88e6xxx_port_set_duplex,
3666 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3667 .port_set_speed = mv88e6390_port_set_speed,
3668 .port_tag_remap = mv88e6095_port_tag_remap,
3669 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3670 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3671 .port_set_ether_type = mv88e6351_port_set_ether_type,
3672 .port_jumbo_config = mv88e6165_port_jumbo_config,
3673 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3674 .port_pause_config = mv88e6097_port_pause_config,
3675 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3676 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3677 .stats_get_strings = mv88e6320_stats_get_strings,
3678 .stats_get_stats = mv88e6390_stats_get_stats,
3679 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3680 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003681 .watchdog_ops = &mv88e6390_watchdog_ops,
Gregory CLEMENT15587272017-01-30 20:29:35 +01003682 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3683 .reset = mv88e6352_g1_reset,
3684};
3685
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003686static const struct mv88e6xxx_ops mv88e6341_ops = {
3687 /* MV88E6XXX_FAMILY_6341 */
3688 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3689 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3690 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3691 .phy_read = mv88e6xxx_g2_smi_phy_read,
3692 .phy_write = mv88e6xxx_g2_smi_phy_write,
3693 .port_set_link = mv88e6xxx_port_set_link,
3694 .port_set_duplex = mv88e6xxx_port_set_duplex,
3695 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3696 .port_set_speed = mv88e6390_port_set_speed,
3697 .port_tag_remap = mv88e6095_port_tag_remap,
3698 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3699 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3700 .port_set_ether_type = mv88e6351_port_set_ether_type,
3701 .port_jumbo_config = mv88e6165_port_jumbo_config,
3702 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3703 .port_pause_config = mv88e6097_port_pause_config,
3704 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3705 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3706 .stats_get_strings = mv88e6320_stats_get_strings,
3707 .stats_get_stats = mv88e6390_stats_get_stats,
3708 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3709 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003710 .watchdog_ops = &mv88e6390_watchdog_ops,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003711 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3712 .reset = mv88e6352_g1_reset,
3713};
3714
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003715static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003716 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003717 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3718 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003719 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3720 .phy_read = mv88e6xxx_g2_smi_phy_read,
3721 .phy_write = mv88e6xxx_g2_smi_phy_write,
3722 .port_set_link = mv88e6xxx_port_set_link,
3723 .port_set_duplex = mv88e6xxx_port_set_duplex,
3724 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3725 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003726 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003727 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3728 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3729 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003730 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003731 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003732 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003733 .port_set_cmode = mv88e6390x_port_set_cmode,
Andrew Lunn79523472016-11-21 23:27:00 +01003734 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003735 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003736 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3737 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003738 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003739 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3740 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003741 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003742 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003743 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003744};
3745
3746static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003747 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003748 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3749 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003750 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3751 .phy_read = mv88e6xxx_g2_smi_phy_read,
3752 .phy_write = mv88e6xxx_g2_smi_phy_write,
3753 .port_set_link = mv88e6xxx_port_set_link,
3754 .port_set_duplex = mv88e6xxx_port_set_duplex,
3755 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3756 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003757 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003758 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3759 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3760 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003761 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003762 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003763 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003764 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003765 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003766 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3767 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003768 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003769 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3770 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003771 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003772 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003773 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003774};
3775
3776static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003777 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003778 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3779 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003780 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3781 .phy_read = mv88e6xxx_g2_smi_phy_read,
3782 .phy_write = mv88e6xxx_g2_smi_phy_write,
3783 .port_set_link = mv88e6xxx_port_set_link,
3784 .port_set_duplex = mv88e6xxx_port_set_duplex,
3785 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3786 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003787 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003788 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3789 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3790 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003791 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003792 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003793 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003794 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3795 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003796 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003797 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3798 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003799 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003800 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003801 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003802};
3803
Andrew Lunn56995cb2016-12-03 04:35:19 +01003804static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3805 const struct mv88e6xxx_ops *ops)
3806{
3807 if (!ops->port_set_frame_mode) {
3808 dev_err(chip->dev, "Missing port_set_frame_mode");
3809 return -EINVAL;
3810 }
3811
3812 if (!ops->port_set_egress_unknowns) {
3813 dev_err(chip->dev, "Missing port_set_egress_mode");
3814 return -EINVAL;
3815 }
3816
3817 return 0;
3818}
3819
Vivien Didelotf81ec902016-05-09 13:22:58 -04003820static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3821 [MV88E6085] = {
3822 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3823 .family = MV88E6XXX_FAMILY_6097,
3824 .name = "Marvell 88E6085",
3825 .num_databases = 4096,
3826 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003827 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003828 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003829 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003830 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003831 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003832 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003833 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003834 },
3835
3836 [MV88E6095] = {
3837 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3838 .family = MV88E6XXX_FAMILY_6095,
3839 .name = "Marvell 88E6095/88E6095F",
3840 .num_databases = 256,
3841 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003842 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003843 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003844 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003845 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003846 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003847 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003848 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003849 },
3850
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003851 [MV88E6097] = {
3852 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3853 .family = MV88E6XXX_FAMILY_6097,
3854 .name = "Marvell 88E6097/88E6097F",
3855 .num_databases = 4096,
3856 .num_ports = 11,
3857 .port_base_addr = 0x10,
3858 .global1_addr = 0x1b,
3859 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003860 .g1_irqs = 8,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003861 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003862 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3863 .ops = &mv88e6097_ops,
3864 },
3865
Vivien Didelotf81ec902016-05-09 13:22:58 -04003866 [MV88E6123] = {
3867 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3868 .family = MV88E6XXX_FAMILY_6165,
3869 .name = "Marvell 88E6123",
3870 .num_databases = 4096,
3871 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003872 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003873 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003874 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003875 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003876 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003877 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003878 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003879 },
3880
3881 [MV88E6131] = {
3882 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3883 .family = MV88E6XXX_FAMILY_6185,
3884 .name = "Marvell 88E6131",
3885 .num_databases = 256,
3886 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003887 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003888 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003889 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003890 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003891 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003892 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003893 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003894 },
3895
3896 [MV88E6161] = {
3897 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3898 .family = MV88E6XXX_FAMILY_6165,
3899 .name = "Marvell 88E6161",
3900 .num_databases = 4096,
3901 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003902 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003903 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003904 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003905 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003906 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003907 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003908 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003909 },
3910
3911 [MV88E6165] = {
3912 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3913 .family = MV88E6XXX_FAMILY_6165,
3914 .name = "Marvell 88E6165",
3915 .num_databases = 4096,
3916 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003917 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003918 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003919 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003920 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003921 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003922 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003923 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003924 },
3925
3926 [MV88E6171] = {
3927 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3928 .family = MV88E6XXX_FAMILY_6351,
3929 .name = "Marvell 88E6171",
3930 .num_databases = 4096,
3931 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003932 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003933 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003934 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003935 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003936 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003937 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003938 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003939 },
3940
3941 [MV88E6172] = {
3942 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3943 .family = MV88E6XXX_FAMILY_6352,
3944 .name = "Marvell 88E6172",
3945 .num_databases = 4096,
3946 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003947 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003948 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003949 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003950 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003951 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003952 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003953 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003954 },
3955
3956 [MV88E6175] = {
3957 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3958 .family = MV88E6XXX_FAMILY_6351,
3959 .name = "Marvell 88E6175",
3960 .num_databases = 4096,
3961 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003962 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003963 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003964 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003965 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003966 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003967 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003968 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003969 },
3970
3971 [MV88E6176] = {
3972 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3973 .family = MV88E6XXX_FAMILY_6352,
3974 .name = "Marvell 88E6176",
3975 .num_databases = 4096,
3976 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003977 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003978 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003979 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003980 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003981 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003982 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003983 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003984 },
3985
3986 [MV88E6185] = {
3987 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3988 .family = MV88E6XXX_FAMILY_6185,
3989 .name = "Marvell 88E6185",
3990 .num_databases = 256,
3991 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003992 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003993 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003994 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003995 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003996 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003997 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003998 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003999 },
4000
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004001 [MV88E6190] = {
4002 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
4003 .family = MV88E6XXX_FAMILY_6390,
4004 .name = "Marvell 88E6190",
4005 .num_databases = 4096,
4006 .num_ports = 11, /* 10 + Z80 */
4007 .port_base_addr = 0x0,
4008 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004009 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004010 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004011 .g1_irqs = 9,
4012 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4013 .ops = &mv88e6190_ops,
4014 },
4015
4016 [MV88E6190X] = {
4017 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
4018 .family = MV88E6XXX_FAMILY_6390,
4019 .name = "Marvell 88E6190X",
4020 .num_databases = 4096,
4021 .num_ports = 11, /* 10 + Z80 */
4022 .port_base_addr = 0x0,
4023 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004024 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004025 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004026 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004027 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4028 .ops = &mv88e6190x_ops,
4029 },
4030
4031 [MV88E6191] = {
4032 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
4033 .family = MV88E6XXX_FAMILY_6390,
4034 .name = "Marvell 88E6191",
4035 .num_databases = 4096,
4036 .num_ports = 11, /* 10 + Z80 */
4037 .port_base_addr = 0x0,
4038 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004039 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004040 .g1_irqs = 9,
4041 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004042 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4043 .ops = &mv88e6391_ops,
4044 },
4045
Vivien Didelotf81ec902016-05-09 13:22:58 -04004046 [MV88E6240] = {
4047 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
4048 .family = MV88E6XXX_FAMILY_6352,
4049 .name = "Marvell 88E6240",
4050 .num_databases = 4096,
4051 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004052 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004053 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004054 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004055 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004056 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004057 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004058 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004059 },
4060
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004061 [MV88E6290] = {
4062 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
4063 .family = MV88E6XXX_FAMILY_6390,
4064 .name = "Marvell 88E6290",
4065 .num_databases = 4096,
4066 .num_ports = 11, /* 10 + Z80 */
4067 .port_base_addr = 0x0,
4068 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004069 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004070 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004071 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004072 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4073 .ops = &mv88e6290_ops,
4074 },
4075
Vivien Didelotf81ec902016-05-09 13:22:58 -04004076 [MV88E6320] = {
4077 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
4078 .family = MV88E6XXX_FAMILY_6320,
4079 .name = "Marvell 88E6320",
4080 .num_databases = 4096,
4081 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004082 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004083 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004084 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004085 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004086 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004087 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004088 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004089 },
4090
4091 [MV88E6321] = {
4092 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
4093 .family = MV88E6XXX_FAMILY_6320,
4094 .name = "Marvell 88E6321",
4095 .num_databases = 4096,
4096 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004097 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004098 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004099 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004100 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004101 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004102 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004103 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004104 },
4105
Gregory CLEMENT15587272017-01-30 20:29:35 +01004106 [MV88E6141] = {
4107 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
4108 .family = MV88E6XXX_FAMILY_6341,
4109 .name = "Marvell 88E6341",
4110 .num_databases = 4096,
4111 .num_ports = 6,
4112 .port_base_addr = 0x10,
4113 .global1_addr = 0x1b,
4114 .age_time_coeff = 3750,
4115 .tag_protocol = DSA_TAG_PROTO_EDSA,
4116 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
4117 .ops = &mv88e6141_ops,
4118 },
4119
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004120 [MV88E6341] = {
4121 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
4122 .family = MV88E6XXX_FAMILY_6341,
4123 .name = "Marvell 88E6341",
4124 .num_databases = 4096,
4125 .num_ports = 6,
4126 .port_base_addr = 0x10,
4127 .global1_addr = 0x1b,
4128 .age_time_coeff = 3750,
4129 .tag_protocol = DSA_TAG_PROTO_EDSA,
4130 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
4131 .ops = &mv88e6341_ops,
4132 },
4133
Vivien Didelotf81ec902016-05-09 13:22:58 -04004134 [MV88E6350] = {
4135 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
4136 .family = MV88E6XXX_FAMILY_6351,
4137 .name = "Marvell 88E6350",
4138 .num_databases = 4096,
4139 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004140 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004141 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004142 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004143 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004144 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004145 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004146 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004147 },
4148
4149 [MV88E6351] = {
4150 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4151 .family = MV88E6XXX_FAMILY_6351,
4152 .name = "Marvell 88E6351",
4153 .num_databases = 4096,
4154 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004155 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004156 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004157 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004158 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004159 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004160 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004161 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004162 },
4163
4164 [MV88E6352] = {
4165 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4166 .family = MV88E6XXX_FAMILY_6352,
4167 .name = "Marvell 88E6352",
4168 .num_databases = 4096,
4169 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004170 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004171 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004172 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004173 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004174 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004175 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004176 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004177 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004178 [MV88E6390] = {
4179 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4180 .family = MV88E6XXX_FAMILY_6390,
4181 .name = "Marvell 88E6390",
4182 .num_databases = 4096,
4183 .num_ports = 11, /* 10 + Z80 */
4184 .port_base_addr = 0x0,
4185 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004186 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004187 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004188 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004189 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4190 .ops = &mv88e6390_ops,
4191 },
4192 [MV88E6390X] = {
4193 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4194 .family = MV88E6XXX_FAMILY_6390,
4195 .name = "Marvell 88E6390X",
4196 .num_databases = 4096,
4197 .num_ports = 11, /* 10 + Z80 */
4198 .port_base_addr = 0x0,
4199 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004200 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004201 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004202 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004203 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4204 .ops = &mv88e6390x_ops,
4205 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004206};
4207
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004208static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004209{
Vivien Didelota439c062016-04-17 13:23:58 -04004210 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004211
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004212 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4213 if (mv88e6xxx_table[i].prod_num == prod_num)
4214 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004215
Vivien Didelotb9b37712015-10-30 19:39:48 -04004216 return NULL;
4217}
4218
Vivien Didelotfad09c72016-06-21 12:28:20 -04004219static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004220{
4221 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004222 unsigned int prod_num, rev;
4223 u16 id;
4224 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004225
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004226 mutex_lock(&chip->reg_lock);
4227 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4228 mutex_unlock(&chip->reg_lock);
4229 if (err)
4230 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004231
4232 prod_num = (id & 0xfff0) >> 4;
4233 rev = id & 0x000f;
4234
4235 info = mv88e6xxx_lookup_info(prod_num);
4236 if (!info)
4237 return -ENODEV;
4238
Vivien Didelotcaac8542016-06-20 13:14:09 -04004239 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004240 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004241
Vivien Didelotca070c12016-09-02 14:45:34 -04004242 err = mv88e6xxx_g2_require(chip);
4243 if (err)
4244 return err;
4245
Vivien Didelotfad09c72016-06-21 12:28:20 -04004246 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4247 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004248
4249 return 0;
4250}
4251
Vivien Didelotfad09c72016-06-21 12:28:20 -04004252static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004253{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004254 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004255
Vivien Didelotfad09c72016-06-21 12:28:20 -04004256 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4257 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004258 return NULL;
4259
Vivien Didelotfad09c72016-06-21 12:28:20 -04004260 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004261
Vivien Didelotfad09c72016-06-21 12:28:20 -04004262 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004263 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004264
Vivien Didelotfad09c72016-06-21 12:28:20 -04004265 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004266}
4267
Vivien Didelote57e5e72016-08-15 17:19:00 -04004268static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4269{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004270 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004271 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004272}
4273
Andrew Lunn930188c2016-08-22 16:01:03 +02004274static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4275{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004276 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004277 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004278}
4279
Vivien Didelotfad09c72016-06-21 12:28:20 -04004280static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004281 struct mii_bus *bus, int sw_addr)
4282{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004283 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004284 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004285 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004286 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004287 else
4288 return -EINVAL;
4289
Vivien Didelotfad09c72016-06-21 12:28:20 -04004290 chip->bus = bus;
4291 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004292
4293 return 0;
4294}
4295
Andrew Lunn7b314362016-08-22 16:01:01 +02004296static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4297{
Vivien Didelot04bed142016-08-31 18:06:13 -04004298 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004299
Andrew Lunn443d5a12016-12-03 04:35:18 +01004300 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004301}
4302
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004303static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4304 struct device *host_dev, int sw_addr,
4305 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004306{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004307 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004308 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004309 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004310
Vivien Didelota439c062016-04-17 13:23:58 -04004311 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004312 if (!bus)
4313 return NULL;
4314
Vivien Didelotfad09c72016-06-21 12:28:20 -04004315 chip = mv88e6xxx_alloc_chip(dsa_dev);
4316 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004317 return NULL;
4318
Vivien Didelotcaac8542016-06-20 13:14:09 -04004319 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004320 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004321
Vivien Didelotfad09c72016-06-21 12:28:20 -04004322 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004323 if (err)
4324 goto free;
4325
Vivien Didelotfad09c72016-06-21 12:28:20 -04004326 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004327 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004328 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004329
Andrew Lunndc30c352016-10-16 19:56:49 +02004330 mutex_lock(&chip->reg_lock);
4331 err = mv88e6xxx_switch_reset(chip);
4332 mutex_unlock(&chip->reg_lock);
4333 if (err)
4334 goto free;
4335
Vivien Didelote57e5e72016-08-15 17:19:00 -04004336 mv88e6xxx_phy_init(chip);
4337
Andrew Lunna3c53be52017-01-24 14:53:50 +01004338 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004339 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004340 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004341
Vivien Didelotfad09c72016-06-21 12:28:20 -04004342 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004343
Vivien Didelotfad09c72016-06-21 12:28:20 -04004344 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004345free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004346 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004347
4348 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004349}
4350
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004351static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4352 const struct switchdev_obj_port_mdb *mdb,
4353 struct switchdev_trans *trans)
4354{
4355 /* We don't need any dynamic resource from the kernel (yet),
4356 * so skip the prepare phase.
4357 */
4358
4359 return 0;
4360}
4361
4362static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4363 const struct switchdev_obj_port_mdb *mdb,
4364 struct switchdev_trans *trans)
4365{
Vivien Didelot04bed142016-08-31 18:06:13 -04004366 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004367
4368 mutex_lock(&chip->reg_lock);
4369 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4370 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4371 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4372 mutex_unlock(&chip->reg_lock);
4373}
4374
4375static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4376 const struct switchdev_obj_port_mdb *mdb)
4377{
Vivien Didelot04bed142016-08-31 18:06:13 -04004378 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004379 int err;
4380
4381 mutex_lock(&chip->reg_lock);
4382 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4383 GLOBAL_ATU_DATA_STATE_UNUSED);
4384 mutex_unlock(&chip->reg_lock);
4385
4386 return err;
4387}
4388
4389static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4390 struct switchdev_obj_port_mdb *mdb,
4391 int (*cb)(struct switchdev_obj *obj))
4392{
Vivien Didelot04bed142016-08-31 18:06:13 -04004393 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004394 int err;
4395
4396 mutex_lock(&chip->reg_lock);
4397 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4398 mutex_unlock(&chip->reg_lock);
4399
4400 return err;
4401}
4402
Florian Fainellia82f67a2017-01-08 14:52:08 -08004403static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004404 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004405 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004406 .setup = mv88e6xxx_setup,
4407 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004408 .adjust_link = mv88e6xxx_adjust_link,
4409 .get_strings = mv88e6xxx_get_strings,
4410 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4411 .get_sset_count = mv88e6xxx_get_sset_count,
4412 .set_eee = mv88e6xxx_set_eee,
4413 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004414 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004415 .get_eeprom = mv88e6xxx_get_eeprom,
4416 .set_eeprom = mv88e6xxx_set_eeprom,
4417 .get_regs_len = mv88e6xxx_get_regs_len,
4418 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004419 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004420 .port_bridge_join = mv88e6xxx_port_bridge_join,
4421 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4422 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004423 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004424 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4425 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4426 .port_vlan_add = mv88e6xxx_port_vlan_add,
4427 .port_vlan_del = mv88e6xxx_port_vlan_del,
4428 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4429 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4430 .port_fdb_add = mv88e6xxx_port_fdb_add,
4431 .port_fdb_del = mv88e6xxx_port_fdb_del,
4432 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004433 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4434 .port_mdb_add = mv88e6xxx_port_mdb_add,
4435 .port_mdb_del = mv88e6xxx_port_mdb_del,
4436 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004437};
4438
Florian Fainelliab3d4082017-01-08 14:52:07 -08004439static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4440 .ops = &mv88e6xxx_switch_ops,
4441};
4442
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004443static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004444{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004445 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004446 struct dsa_switch *ds;
4447
Vivien Didelota0c02162017-01-27 15:29:36 -05004448 ds = dsa_switch_alloc(dev, DSA_MAX_PORTS);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004449 if (!ds)
4450 return -ENOMEM;
4451
Vivien Didelotfad09c72016-06-21 12:28:20 -04004452 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004453 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004454
4455 dev_set_drvdata(dev, ds);
4456
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004457 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004458}
4459
Vivien Didelotfad09c72016-06-21 12:28:20 -04004460static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004461{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004462 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004463}
4464
Vivien Didelot57d32312016-06-20 13:13:58 -04004465static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004466{
4467 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004468 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004469 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004470 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004471 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004472 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004473
Vivien Didelotcaac8542016-06-20 13:14:09 -04004474 compat_info = of_device_get_match_data(dev);
4475 if (!compat_info)
4476 return -EINVAL;
4477
Vivien Didelotfad09c72016-06-21 12:28:20 -04004478 chip = mv88e6xxx_alloc_chip(dev);
4479 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004480 return -ENOMEM;
4481
Vivien Didelotfad09c72016-06-21 12:28:20 -04004482 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004483
Andrew Lunn56995cb2016-12-03 04:35:19 +01004484 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4485 if (err)
4486 return err;
4487
Vivien Didelotfad09c72016-06-21 12:28:20 -04004488 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004489 if (err)
4490 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004491
Andrew Lunnb4308f02016-11-21 23:26:55 +01004492 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4493 if (IS_ERR(chip->reset))
4494 return PTR_ERR(chip->reset);
4495
Vivien Didelotfad09c72016-06-21 12:28:20 -04004496 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004497 if (err)
4498 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004499
Vivien Didelote57e5e72016-08-15 17:19:00 -04004500 mv88e6xxx_phy_init(chip);
4501
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004502 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004503 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004504 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004505
Andrew Lunndc30c352016-10-16 19:56:49 +02004506 mutex_lock(&chip->reg_lock);
4507 err = mv88e6xxx_switch_reset(chip);
4508 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004509 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004510 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004511
Andrew Lunndc30c352016-10-16 19:56:49 +02004512 chip->irq = of_irq_get(np, 0);
4513 if (chip->irq == -EPROBE_DEFER) {
4514 err = chip->irq;
4515 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004516 }
4517
Andrew Lunndc30c352016-10-16 19:56:49 +02004518 if (chip->irq > 0) {
4519 /* Has to be performed before the MDIO bus is created,
4520 * because the PHYs will link there interrupts to these
4521 * interrupt controllers
4522 */
4523 mutex_lock(&chip->reg_lock);
4524 err = mv88e6xxx_g1_irq_setup(chip);
4525 mutex_unlock(&chip->reg_lock);
4526
4527 if (err)
4528 goto out;
4529
4530 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4531 err = mv88e6xxx_g2_irq_setup(chip);
4532 if (err)
4533 goto out_g1_irq;
4534 }
4535 }
4536
Andrew Lunna3c53be52017-01-24 14:53:50 +01004537 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004538 if (err)
4539 goto out_g2_irq;
4540
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004541 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004542 if (err)
4543 goto out_mdio;
4544
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004545 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004546
4547out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004548 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004549out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004550 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004551 mv88e6xxx_g2_irq_free(chip);
4552out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004553 if (chip->irq > 0) {
4554 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004555 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004556 mutex_unlock(&chip->reg_lock);
4557 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004558out:
4559 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004560}
4561
4562static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4563{
4564 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004565 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004566
Andrew Lunn930188c2016-08-22 16:01:03 +02004567 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004568 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004569 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004570
Andrew Lunn467126442016-11-20 20:14:15 +01004571 if (chip->irq > 0) {
4572 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4573 mv88e6xxx_g2_irq_free(chip);
4574 mv88e6xxx_g1_irq_free(chip);
4575 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004576}
4577
4578static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004579 {
4580 .compatible = "marvell,mv88e6085",
4581 .data = &mv88e6xxx_table[MV88E6085],
4582 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004583 {
4584 .compatible = "marvell,mv88e6190",
4585 .data = &mv88e6xxx_table[MV88E6190],
4586 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004587 { /* sentinel */ },
4588};
4589
4590MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4591
4592static struct mdio_driver mv88e6xxx_driver = {
4593 .probe = mv88e6xxx_probe,
4594 .remove = mv88e6xxx_remove,
4595 .mdiodrv.driver = {
4596 .name = "mv88e6085",
4597 .of_match_table = mv88e6xxx_of_match,
4598 },
4599};
4600
Ben Hutchings98e67302011-11-25 14:36:19 +00004601static int __init mv88e6xxx_init(void)
4602{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004603 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004604 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004605}
4606module_init(mv88e6xxx_init);
4607
4608static void __exit mv88e6xxx_cleanup(void)
4609{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004610 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004611 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004612}
4613module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004614
4615MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4616MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4617MODULE_LICENSE("GPL");