blob: bf385377a461dd44204433c6e3899819f39ff720 [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_6095_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_6095;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200683}
684
Vivien Didelotfad09c72016-06-21 12:28:20 -0400685static bool mv88e6xxx_6097_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_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200688}
689
Vivien Didelotfad09c72016-06-21 12:28:20 -0400690static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200691{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400692 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200693}
694
Vivien Didelotfad09c72016-06-21 12:28:20 -0400695static bool mv88e6xxx_6185_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200696{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400697 return chip->info->family == MV88E6XXX_FAMILY_6185;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200698}
699
Vivien Didelotfad09c72016-06-21 12:28:20 -0400700static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700701{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400702 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700703}
704
Gregory CLEMENTa75961d2017-01-30 20:29:34 +0100705static bool mv88e6xxx_6341_family(struct mv88e6xxx_chip *chip)
706{
707 return chip->info->family == MV88E6XXX_FAMILY_6341;
708}
709
Vivien Didelotfad09c72016-06-21 12:28:20 -0400710static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200711{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400712 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200713}
714
Vivien Didelotfad09c72016-06-21 12:28:20 -0400715static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200716{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400717 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200718}
719
Vivien Didelotd78343d2016-11-04 03:23:36 +0100720static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
721 int link, int speed, int duplex,
722 phy_interface_t mode)
723{
724 int err;
725
726 if (!chip->info->ops->port_set_link)
727 return 0;
728
729 /* Port's MAC control must not be changed unless the link is down */
730 err = chip->info->ops->port_set_link(chip, port, 0);
731 if (err)
732 return err;
733
734 if (chip->info->ops->port_set_speed) {
735 err = chip->info->ops->port_set_speed(chip, port, speed);
736 if (err && err != -EOPNOTSUPP)
737 goto restore_link;
738 }
739
740 if (chip->info->ops->port_set_duplex) {
741 err = chip->info->ops->port_set_duplex(chip, port, duplex);
742 if (err && err != -EOPNOTSUPP)
743 goto restore_link;
744 }
745
746 if (chip->info->ops->port_set_rgmii_delay) {
747 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
748 if (err && err != -EOPNOTSUPP)
749 goto restore_link;
750 }
751
752 err = 0;
753restore_link:
754 if (chip->info->ops->port_set_link(chip, port, link))
755 netdev_err(chip->ds->ports[port].netdev,
756 "failed to restore MAC's link\n");
757
758 return err;
759}
760
Andrew Lunndea87022015-08-31 15:56:47 +0200761/* We expect the switch to perform auto negotiation if there is a real
762 * phy. However, in the case of a fixed link phy, we force the port
763 * settings from the fixed link settings.
764 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400765static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
766 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200767{
Vivien Didelot04bed142016-08-31 18:06:13 -0400768 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200769 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200770
771 if (!phy_is_pseudo_fixed_link(phydev))
772 return;
773
Vivien Didelotfad09c72016-06-21 12:28:20 -0400774 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100775 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
776 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400777 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100778
779 if (err && err != -EOPNOTSUPP)
780 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200781}
782
Andrew Lunna605a0f2016-11-21 23:26:58 +0100783static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000784{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100785 if (!chip->info->ops->stats_snapshot)
786 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000787
Andrew Lunna605a0f2016-11-21 23:26:58 +0100788 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000789}
790
Andrew Lunne413e7e2015-04-02 04:06:38 +0200791static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100792 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
793 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
794 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
795 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
796 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
797 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
798 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
799 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
800 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
801 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
802 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
803 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
804 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
805 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
806 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
807 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
808 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
809 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
810 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
811 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
812 { "single", 4, 0x14, STATS_TYPE_BANK0, },
813 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
814 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
815 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
816 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
817 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
818 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
819 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
820 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
821 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
822 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
823 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
824 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
825 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
826 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
827 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
828 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
829 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
830 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
831 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
832 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
833 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
834 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
835 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
836 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
837 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
838 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
839 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
840 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
841 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
842 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
843 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
844 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
845 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
846 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
847 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
848 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
849 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
850 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200851};
852
Vivien Didelotfad09c72016-06-21 12:28:20 -0400853static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100854 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100855 int port, u16 bank1_select,
856 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200857{
Andrew Lunn80c46272015-06-20 18:42:30 +0200858 u32 low;
859 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100860 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200861 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200862 u64 value;
863
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100864 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100865 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200866 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
867 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200868 return UINT64_MAX;
869
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200870 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200871 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200872 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
873 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200874 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200875 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200876 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100877 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100878 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100879 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100880 /* fall through */
881 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100882 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100883 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200884 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100885 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200886 }
887 value = (((u64)high) << 16) | low;
888 return value;
889}
890
Andrew Lunndfafe442016-11-21 23:27:02 +0100891static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
892 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100893{
894 struct mv88e6xxx_hw_stat *stat;
895 int i, j;
896
897 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
898 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100899 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100900 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
901 ETH_GSTRING_LEN);
902 j++;
903 }
904 }
905}
906
Andrew Lunndfafe442016-11-21 23:27:02 +0100907static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
908 uint8_t *data)
909{
910 mv88e6xxx_stats_get_strings(chip, data,
911 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
912}
913
914static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
915 uint8_t *data)
916{
917 mv88e6xxx_stats_get_strings(chip, data,
918 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
919}
920
921static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
922 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100923{
Vivien Didelot04bed142016-08-31 18:06:13 -0400924 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100925
926 if (chip->info->ops->stats_get_strings)
927 chip->info->ops->stats_get_strings(chip, data);
928}
929
930static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
931 int types)
932{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100933 struct mv88e6xxx_hw_stat *stat;
934 int i, j;
935
936 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
937 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100938 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100939 j++;
940 }
941 return j;
942}
943
Andrew Lunndfafe442016-11-21 23:27:02 +0100944static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
945{
946 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
947 STATS_TYPE_PORT);
948}
949
950static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
951{
952 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
953 STATS_TYPE_BANK1);
954}
955
956static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
957{
958 struct mv88e6xxx_chip *chip = ds->priv;
959
960 if (chip->info->ops->stats_get_sset_count)
961 return chip->info->ops->stats_get_sset_count(chip);
962
963 return 0;
964}
965
Andrew Lunn052f9472016-11-21 23:27:03 +0100966static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100967 uint64_t *data, int types,
968 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100969{
970 struct mv88e6xxx_hw_stat *stat;
971 int i, j;
972
973 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
974 stat = &mv88e6xxx_hw_stats[i];
975 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100976 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
977 bank1_select,
978 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100979 j++;
980 }
981 }
982}
983
984static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
985 uint64_t *data)
986{
987 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100988 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
989 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100990}
991
992static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
993 uint64_t *data)
994{
995 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100996 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
997 GLOBAL_STATS_OP_BANK_1_BIT_9,
998 GLOBAL_STATS_OP_HIST_RX_TX);
999}
1000
1001static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1002 uint64_t *data)
1003{
1004 return mv88e6xxx_stats_get_stats(chip, port, data,
1005 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1006 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001007}
1008
1009static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1010 uint64_t *data)
1011{
1012 if (chip->info->ops->stats_get_stats)
1013 chip->info->ops->stats_get_stats(chip, port, data);
1014}
1015
Vivien Didelotf81ec902016-05-09 13:22:58 -04001016static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1017 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001018{
Vivien Didelot04bed142016-08-31 18:06:13 -04001019 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001020 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001021
Vivien Didelotfad09c72016-06-21 12:28:20 -04001022 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001023
Andrew Lunna605a0f2016-11-21 23:26:58 +01001024 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001025 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001026 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001027 return;
1028 }
Andrew Lunn052f9472016-11-21 23:27:03 +01001029
1030 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001031
Vivien Didelotfad09c72016-06-21 12:28:20 -04001032 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001033}
Ben Hutchings98e67302011-11-25 14:36:19 +00001034
Andrew Lunnde2273872016-11-21 23:27:01 +01001035static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1036{
1037 if (chip->info->ops->stats_set_histogram)
1038 return chip->info->ops->stats_set_histogram(chip);
1039
1040 return 0;
1041}
1042
Vivien Didelotf81ec902016-05-09 13:22:58 -04001043static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001044{
1045 return 32 * sizeof(u16);
1046}
1047
Vivien Didelotf81ec902016-05-09 13:22:58 -04001048static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1049 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001050{
Vivien Didelot04bed142016-08-31 18:06:13 -04001051 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001052 int err;
1053 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001054 u16 *p = _p;
1055 int i;
1056
1057 regs->version = 0;
1058
1059 memset(p, 0xff, 32 * sizeof(u16));
1060
Vivien Didelotfad09c72016-06-21 12:28:20 -04001061 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001062
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001063 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001064
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001065 err = mv88e6xxx_port_read(chip, port, i, &reg);
1066 if (!err)
1067 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001068 }
Vivien Didelot23062512016-05-09 13:22:45 -04001069
Vivien Didelotfad09c72016-06-21 12:28:20 -04001070 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001071}
1072
Vivien Didelotfad09c72016-06-21 12:28:20 -04001073static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001074{
Vivien Didelota935c052016-09-29 12:21:53 -04001075 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001076}
1077
Vivien Didelotf81ec902016-05-09 13:22:58 -04001078static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1079 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001080{
Vivien Didelot04bed142016-08-31 18:06:13 -04001081 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001082 u16 reg;
1083 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001084
Vivien Didelotfad09c72016-06-21 12:28:20 -04001085 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001086 return -EOPNOTSUPP;
1087
Vivien Didelotfad09c72016-06-21 12:28:20 -04001088 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001089
Vivien Didelot9c938292016-08-15 17:19:02 -04001090 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1091 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001092 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001093
1094 e->eee_enabled = !!(reg & 0x0200);
1095 e->tx_lpi_enabled = !!(reg & 0x0100);
1096
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001097 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001098 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001099 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001100
Andrew Lunncca8b132015-04-02 04:06:39 +02001101 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001102out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001103 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001104
1105 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001106}
1107
Vivien Didelotf81ec902016-05-09 13:22:58 -04001108static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1109 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001110{
Vivien Didelot04bed142016-08-31 18:06:13 -04001111 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001112 u16 reg;
1113 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001114
Vivien Didelotfad09c72016-06-21 12:28:20 -04001115 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001116 return -EOPNOTSUPP;
1117
Vivien Didelotfad09c72016-06-21 12:28:20 -04001118 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001119
Vivien Didelot9c938292016-08-15 17:19:02 -04001120 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1121 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001122 goto out;
1123
Vivien Didelot9c938292016-08-15 17:19:02 -04001124 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001125 if (e->eee_enabled)
1126 reg |= 0x0200;
1127 if (e->tx_lpi_enabled)
1128 reg |= 0x0100;
1129
Vivien Didelot9c938292016-08-15 17:19:02 -04001130 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001131out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001132 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001133
Vivien Didelot9c938292016-08-15 17:19:02 -04001134 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001135}
1136
Vivien Didelotfad09c72016-06-21 12:28:20 -04001137static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001138{
Vivien Didelota935c052016-09-29 12:21:53 -04001139 u16 val;
1140 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001141
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001142 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001143 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1144 if (err)
1145 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001146 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001147 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001148 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1149 if (err)
1150 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001151
Vivien Didelota935c052016-09-29 12:21:53 -04001152 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1153 (val & 0xfff) | ((fid << 8) & 0xf000));
1154 if (err)
1155 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001156
1157 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1158 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001159 }
1160
Vivien Didelota935c052016-09-29 12:21:53 -04001161 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1162 if (err)
1163 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001164
Vivien Didelotfad09c72016-06-21 12:28:20 -04001165 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001166}
1167
Vivien Didelotfad09c72016-06-21 12:28:20 -04001168static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001169 struct mv88e6xxx_atu_entry *entry)
1170{
1171 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1172
1173 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1174 unsigned int mask, shift;
1175
1176 if (entry->trunk) {
1177 data |= GLOBAL_ATU_DATA_TRUNK;
1178 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1179 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1180 } else {
1181 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1182 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1183 }
1184
1185 data |= (entry->portv_trunkid << shift) & mask;
1186 }
1187
Vivien Didelota935c052016-09-29 12:21:53 -04001188 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001189}
1190
Vivien Didelotfad09c72016-06-21 12:28:20 -04001191static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001192 struct mv88e6xxx_atu_entry *entry,
1193 bool static_too)
1194{
1195 int op;
1196 int err;
1197
Vivien Didelotfad09c72016-06-21 12:28:20 -04001198 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001199 if (err)
1200 return err;
1201
Vivien Didelotfad09c72016-06-21 12:28:20 -04001202 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001203 if (err)
1204 return err;
1205
1206 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001207 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1208 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1209 } else {
1210 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1211 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1212 }
1213
Vivien Didelotfad09c72016-06-21 12:28:20 -04001214 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001215}
1216
Vivien Didelotfad09c72016-06-21 12:28:20 -04001217static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001218 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001219{
1220 struct mv88e6xxx_atu_entry entry = {
1221 .fid = fid,
1222 .state = 0, /* EntryState bits must be 0 */
1223 };
1224
Vivien Didelotfad09c72016-06-21 12:28:20 -04001225 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001226}
1227
Vivien Didelotfad09c72016-06-21 12:28:20 -04001228static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001229 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001230{
1231 struct mv88e6xxx_atu_entry entry = {
1232 .trunk = false,
1233 .fid = fid,
1234 };
1235
1236 /* EntryState bits must be 0xF */
1237 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1238
1239 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1240 entry.portv_trunkid = (to_port & 0x0f) << 4;
1241 entry.portv_trunkid |= from_port & 0x0f;
1242
Vivien Didelotfad09c72016-06-21 12:28:20 -04001243 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001244}
1245
Vivien Didelotfad09c72016-06-21 12:28:20 -04001246static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001247 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001248{
1249 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001250 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001251}
1252
Vivien Didelotfad09c72016-06-21 12:28:20 -04001253static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001254{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001255 struct dsa_switch *ds = chip->ds;
Vivien Didelotfae8a252017-01-27 15:29:42 -05001256 struct net_device *bridge = ds->ports[port].bridge_dev;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001257 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001258 int i;
1259
1260 /* allow CPU port or DSA link(s) to send frames to every port */
1261 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001262 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001263 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001264 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001265 /* allow sending frames to every group member */
Vivien Didelotfae8a252017-01-27 15:29:42 -05001266 if (bridge && ds->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001267 output_ports |= BIT(i);
1268
1269 /* allow sending frames to CPU port and DSA link(s) */
1270 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1271 output_ports |= BIT(i);
1272 }
1273 }
1274
1275 /* prevent frames from going back out of the port they came in on */
1276 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001277
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001278 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001279}
1280
Vivien Didelotf81ec902016-05-09 13:22:58 -04001281static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1282 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001283{
Vivien Didelot04bed142016-08-31 18:06:13 -04001284 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001285 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001286 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001287
1288 switch (state) {
1289 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001290 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001291 break;
1292 case BR_STATE_BLOCKING:
1293 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001294 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001295 break;
1296 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001297 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001298 break;
1299 case BR_STATE_FORWARDING:
1300 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001301 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001302 break;
1303 }
1304
Vivien Didelotfad09c72016-06-21 12:28:20 -04001305 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001306 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001307 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001308
1309 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001310 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001311}
1312
Vivien Didelot749efcb2016-09-22 16:49:24 -04001313static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1314{
1315 struct mv88e6xxx_chip *chip = ds->priv;
1316 int err;
1317
1318 mutex_lock(&chip->reg_lock);
1319 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1320 mutex_unlock(&chip->reg_lock);
1321
1322 if (err)
1323 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1324}
1325
Vivien Didelotfad09c72016-06-21 12:28:20 -04001326static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001327{
Vivien Didelota935c052016-09-29 12:21:53 -04001328 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001329}
1330
Vivien Didelotfad09c72016-06-21 12:28:20 -04001331static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001332{
Vivien Didelota935c052016-09-29 12:21:53 -04001333 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001334
Vivien Didelota935c052016-09-29 12:21:53 -04001335 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1336 if (err)
1337 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001338
Vivien Didelotfad09c72016-06-21 12:28:20 -04001339 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001340}
1341
Vivien Didelotfad09c72016-06-21 12:28:20 -04001342static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001343{
1344 int ret;
1345
Vivien Didelotfad09c72016-06-21 12:28:20 -04001346 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001347 if (ret < 0)
1348 return ret;
1349
Vivien Didelotfad09c72016-06-21 12:28:20 -04001350 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001351}
1352
Vivien Didelotfad09c72016-06-21 12:28:20 -04001353static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001354 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001355 unsigned int nibble_offset)
1356{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001357 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001358 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001359
1360 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001361 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001362
Vivien Didelota935c052016-09-29 12:21:53 -04001363 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1364 if (err)
1365 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001366 }
1367
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001368 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001369 unsigned int shift = (i % 4) * 4 + nibble_offset;
1370 u16 reg = regs[i / 4];
1371
1372 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1373 }
1374
1375 return 0;
1376}
1377
Vivien Didelotfad09c72016-06-21 12:28:20 -04001378static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001379 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001380{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001381 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001382}
1383
Vivien Didelotfad09c72016-06-21 12:28:20 -04001384static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001385 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001386{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001387 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001388}
1389
Vivien Didelotfad09c72016-06-21 12:28:20 -04001390static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001391 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001392 unsigned int nibble_offset)
1393{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001394 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001395 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001396
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001397 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001398 unsigned int shift = (i % 4) * 4 + nibble_offset;
1399 u8 data = entry->data[i];
1400
1401 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1402 }
1403
1404 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001405 u16 reg = regs[i];
1406
1407 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1408 if (err)
1409 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001410 }
1411
1412 return 0;
1413}
1414
Vivien Didelotfad09c72016-06-21 12:28:20 -04001415static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001416 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001417{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001418 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001419}
1420
Vivien Didelotfad09c72016-06-21 12:28:20 -04001421static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001422 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001423{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001424 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001425}
1426
Vivien Didelotfad09c72016-06-21 12:28:20 -04001427static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001428{
Vivien Didelota935c052016-09-29 12:21:53 -04001429 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1430 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001431}
1432
Vivien Didelotfad09c72016-06-21 12:28:20 -04001433static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001434 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001435{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001436 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001437 u16 val;
1438 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001439
Vivien Didelota935c052016-09-29 12:21:53 -04001440 err = _mv88e6xxx_vtu_wait(chip);
1441 if (err)
1442 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001443
Vivien Didelota935c052016-09-29 12:21:53 -04001444 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1445 if (err)
1446 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001447
Vivien Didelota935c052016-09-29 12:21:53 -04001448 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1449 if (err)
1450 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001451
Vivien Didelota935c052016-09-29 12:21:53 -04001452 next.vid = val & GLOBAL_VTU_VID_MASK;
1453 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001454
1455 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001456 err = mv88e6xxx_vtu_data_read(chip, &next);
1457 if (err)
1458 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001459
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001460 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001461 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1462 if (err)
1463 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001464
Vivien Didelota935c052016-09-29 12:21:53 -04001465 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001466 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001467 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1468 * VTU DBNum[3:0] are located in VTU Operation 3:0
1469 */
Vivien Didelota935c052016-09-29 12:21:53 -04001470 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1471 if (err)
1472 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001473
Vivien Didelota935c052016-09-29 12:21:53 -04001474 next.fid = (val & 0xf00) >> 4;
1475 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001476 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001477
Vivien Didelotfad09c72016-06-21 12:28:20 -04001478 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001479 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1480 if (err)
1481 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001482
Vivien Didelota935c052016-09-29 12:21:53 -04001483 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001484 }
1485 }
1486
1487 *entry = next;
1488 return 0;
1489}
1490
Vivien Didelotf81ec902016-05-09 13:22:58 -04001491static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1492 struct switchdev_obj_port_vlan *vlan,
1493 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001494{
Vivien Didelot04bed142016-08-31 18:06:13 -04001495 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001496 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001497 u16 pvid;
1498 int err;
1499
Vivien Didelotfad09c72016-06-21 12:28:20 -04001500 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001501 return -EOPNOTSUPP;
1502
Vivien Didelotfad09c72016-06-21 12:28:20 -04001503 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001504
Vivien Didelot77064f32016-11-04 03:23:30 +01001505 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001506 if (err)
1507 goto unlock;
1508
Vivien Didelotfad09c72016-06-21 12:28:20 -04001509 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001510 if (err)
1511 goto unlock;
1512
1513 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001514 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001515 if (err)
1516 break;
1517
1518 if (!next.valid)
1519 break;
1520
1521 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1522 continue;
1523
1524 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001525 vlan->vid_begin = next.vid;
1526 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001527 vlan->flags = 0;
1528
1529 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1530 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1531
1532 if (next.vid == pvid)
1533 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1534
1535 err = cb(&vlan->obj);
1536 if (err)
1537 break;
1538 } while (next.vid < GLOBAL_VTU_VID_MASK);
1539
1540unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001541 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001542
1543 return err;
1544}
1545
Vivien Didelotfad09c72016-06-21 12:28:20 -04001546static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001547 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001548{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001549 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001550 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001551 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001552
Vivien Didelota935c052016-09-29 12:21:53 -04001553 err = _mv88e6xxx_vtu_wait(chip);
1554 if (err)
1555 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001556
1557 if (!entry->valid)
1558 goto loadpurge;
1559
1560 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001561 err = mv88e6xxx_vtu_data_write(chip, entry);
1562 if (err)
1563 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001564
Vivien Didelotfad09c72016-06-21 12:28:20 -04001565 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001566 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001567 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1568 if (err)
1569 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001570 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001571
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001572 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001573 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001574 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1575 if (err)
1576 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001577 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001578 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1579 * VTU DBNum[3:0] are located in VTU Operation 3:0
1580 */
1581 op |= (entry->fid & 0xf0) << 8;
1582 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001583 }
1584
1585 reg = GLOBAL_VTU_VID_VALID;
1586loadpurge:
1587 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001588 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1589 if (err)
1590 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001591
Vivien Didelotfad09c72016-06-21 12:28:20 -04001592 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001593}
1594
Vivien Didelotfad09c72016-06-21 12:28:20 -04001595static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001596 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001597{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001598 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001599 u16 val;
1600 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001601
Vivien Didelota935c052016-09-29 12:21:53 -04001602 err = _mv88e6xxx_vtu_wait(chip);
1603 if (err)
1604 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001605
Vivien Didelota935c052016-09-29 12:21:53 -04001606 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1607 sid & GLOBAL_VTU_SID_MASK);
1608 if (err)
1609 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001610
Vivien Didelota935c052016-09-29 12:21:53 -04001611 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1612 if (err)
1613 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001614
Vivien Didelota935c052016-09-29 12:21:53 -04001615 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1616 if (err)
1617 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001618
Vivien Didelota935c052016-09-29 12:21:53 -04001619 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001620
Vivien Didelota935c052016-09-29 12:21:53 -04001621 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1622 if (err)
1623 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001624
Vivien Didelota935c052016-09-29 12:21:53 -04001625 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001626
1627 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001628 err = mv88e6xxx_stu_data_read(chip, &next);
1629 if (err)
1630 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001631 }
1632
1633 *entry = next;
1634 return 0;
1635}
1636
Vivien Didelotfad09c72016-06-21 12:28:20 -04001637static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001638 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001639{
1640 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001641 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001642
Vivien Didelota935c052016-09-29 12:21:53 -04001643 err = _mv88e6xxx_vtu_wait(chip);
1644 if (err)
1645 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001646
1647 if (!entry->valid)
1648 goto loadpurge;
1649
1650 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001651 err = mv88e6xxx_stu_data_write(chip, entry);
1652 if (err)
1653 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001654
1655 reg = GLOBAL_VTU_VID_VALID;
1656loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001657 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1658 if (err)
1659 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001660
1661 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001662 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1663 if (err)
1664 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001665
Vivien Didelotfad09c72016-06-21 12:28:20 -04001666 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001667}
1668
Vivien Didelotfad09c72016-06-21 12:28:20 -04001669static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001670{
1671 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001672 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001673 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001674
1675 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1676
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001677 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001678 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001679 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001680 if (err)
1681 return err;
1682
1683 set_bit(*fid, fid_bitmap);
1684 }
1685
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001686 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001687 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001688 if (err)
1689 return err;
1690
1691 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001692 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001693 if (err)
1694 return err;
1695
1696 if (!vlan.valid)
1697 break;
1698
1699 set_bit(vlan.fid, fid_bitmap);
1700 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1701
1702 /* The reset value 0x000 is used to indicate that multiple address
1703 * databases are not needed. Return the next positive available.
1704 */
1705 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001706 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001707 return -ENOSPC;
1708
1709 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001710 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001711}
1712
Vivien Didelotfad09c72016-06-21 12:28:20 -04001713static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001714 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001715{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001716 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001717 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001718 .valid = true,
1719 .vid = vid,
1720 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001721 int i, err;
1722
Vivien Didelotfad09c72016-06-21 12:28:20 -04001723 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001724 if (err)
1725 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001726
Vivien Didelot3d131f02015-11-03 10:52:52 -05001727 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001728 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001729 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1730 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1731 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001732
Vivien Didelotfad09c72016-06-21 12:28:20 -04001733 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01001734 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip) ||
1735 mv88e6xxx_6341_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001736 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001737
1738 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1739 * implemented, only one STU entry is needed to cover all VTU
1740 * entries. Thus, validate the SID 0.
1741 */
1742 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001743 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001744 if (err)
1745 return err;
1746
1747 if (vstp.sid != vlan.sid || !vstp.valid) {
1748 memset(&vstp, 0, sizeof(vstp));
1749 vstp.valid = true;
1750 vstp.sid = vlan.sid;
1751
Vivien Didelotfad09c72016-06-21 12:28:20 -04001752 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001753 if (err)
1754 return err;
1755 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001756 }
1757
1758 *entry = vlan;
1759 return 0;
1760}
1761
Vivien Didelotfad09c72016-06-21 12:28:20 -04001762static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001763 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001764{
1765 int err;
1766
1767 if (!vid)
1768 return -EINVAL;
1769
Vivien Didelotfad09c72016-06-21 12:28:20 -04001770 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001771 if (err)
1772 return err;
1773
Vivien Didelotfad09c72016-06-21 12:28:20 -04001774 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001775 if (err)
1776 return err;
1777
1778 if (entry->vid != vid || !entry->valid) {
1779 if (!creat)
1780 return -EOPNOTSUPP;
1781 /* -ENOENT would've been more appropriate, but switchdev expects
1782 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1783 */
1784
Vivien Didelotfad09c72016-06-21 12:28:20 -04001785 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001786 }
1787
1788 return err;
1789}
1790
Vivien Didelotda9c3592016-02-12 12:09:40 -05001791static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1792 u16 vid_begin, u16 vid_end)
1793{
Vivien Didelot04bed142016-08-31 18:06:13 -04001794 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001795 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001796 int i, err;
1797
1798 if (!vid_begin)
1799 return -EOPNOTSUPP;
1800
Vivien Didelotfad09c72016-06-21 12:28:20 -04001801 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001802
Vivien Didelotfad09c72016-06-21 12:28:20 -04001803 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001804 if (err)
1805 goto unlock;
1806
1807 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001808 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001809 if (err)
1810 goto unlock;
1811
1812 if (!vlan.valid)
1813 break;
1814
1815 if (vlan.vid > vid_end)
1816 break;
1817
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001818 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001819 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1820 continue;
1821
Andrew Lunn66e28092016-12-11 21:07:19 +01001822 if (!ds->ports[port].netdev)
1823 continue;
1824
Vivien Didelotda9c3592016-02-12 12:09:40 -05001825 if (vlan.data[i] ==
1826 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1827 continue;
1828
Vivien Didelotfae8a252017-01-27 15:29:42 -05001829 if (ds->ports[i].bridge_dev ==
1830 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001831 break; /* same bridge, check next VLAN */
1832
Vivien Didelotfae8a252017-01-27 15:29:42 -05001833 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001834 continue;
1835
Andrew Lunnc8b09802016-06-04 21:16:57 +02001836 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001837 "hardware VLAN %d already used by %s\n",
1838 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001839 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001840 err = -EOPNOTSUPP;
1841 goto unlock;
1842 }
1843 } while (vlan.vid < vid_end);
1844
1845unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001846 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001847
1848 return err;
1849}
1850
Vivien Didelotf81ec902016-05-09 13:22:58 -04001851static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1852 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001853{
Vivien Didelot04bed142016-08-31 18:06:13 -04001854 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001855 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001856 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001857 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001858
Vivien Didelotfad09c72016-06-21 12:28:20 -04001859 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001860 return -EOPNOTSUPP;
1861
Vivien Didelotfad09c72016-06-21 12:28:20 -04001862 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001863 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001864 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001865
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001866 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001867}
1868
Vivien Didelot57d32312016-06-20 13:13:58 -04001869static int
1870mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1871 const struct switchdev_obj_port_vlan *vlan,
1872 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001873{
Vivien Didelot04bed142016-08-31 18:06:13 -04001874 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001875 int err;
1876
Vivien Didelotfad09c72016-06-21 12:28:20 -04001877 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001878 return -EOPNOTSUPP;
1879
Vivien Didelotda9c3592016-02-12 12:09:40 -05001880 /* If the requested port doesn't belong to the same bridge as the VLAN
1881 * members, do not support it (yet) and fallback to software VLAN.
1882 */
1883 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1884 vlan->vid_end);
1885 if (err)
1886 return err;
1887
Vivien Didelot76e398a2015-11-01 12:33:55 -05001888 /* We don't need any dynamic resource from the kernel (yet),
1889 * so skip the prepare phase.
1890 */
1891 return 0;
1892}
1893
Vivien Didelotfad09c72016-06-21 12:28:20 -04001894static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001895 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001896{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001897 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001898 int err;
1899
Vivien Didelotfad09c72016-06-21 12:28:20 -04001900 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001901 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001902 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001903
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001904 vlan.data[port] = untagged ?
1905 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1906 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1907
Vivien Didelotfad09c72016-06-21 12:28:20 -04001908 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001909}
1910
Vivien Didelotf81ec902016-05-09 13:22:58 -04001911static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1912 const struct switchdev_obj_port_vlan *vlan,
1913 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001914{
Vivien Didelot04bed142016-08-31 18:06:13 -04001915 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001916 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1917 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1918 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001919
Vivien Didelotfad09c72016-06-21 12:28:20 -04001920 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001921 return;
1922
Vivien Didelotfad09c72016-06-21 12:28:20 -04001923 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001924
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001925 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001926 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001927 netdev_err(ds->ports[port].netdev,
1928 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001929 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001930
Vivien Didelot77064f32016-11-04 03:23:30 +01001931 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001932 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001933 vlan->vid_end);
1934
Vivien Didelotfad09c72016-06-21 12:28:20 -04001935 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001936}
1937
Vivien Didelotfad09c72016-06-21 12:28:20 -04001938static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001939 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001940{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001941 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001942 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001943 int i, err;
1944
Vivien Didelotfad09c72016-06-21 12:28:20 -04001945 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001946 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001947 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001948
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001949 /* Tell switchdev if this VLAN is handled in software */
1950 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001951 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001952
1953 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1954
1955 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001956 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001957 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001958 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001959 continue;
1960
1961 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001962 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001963 break;
1964 }
1965 }
1966
Vivien Didelotfad09c72016-06-21 12:28:20 -04001967 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001968 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001969 return err;
1970
Vivien Didelotfad09c72016-06-21 12:28:20 -04001971 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001972}
1973
Vivien Didelotf81ec902016-05-09 13:22:58 -04001974static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1975 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001976{
Vivien Didelot04bed142016-08-31 18:06:13 -04001977 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001978 u16 pvid, vid;
1979 int err = 0;
1980
Vivien Didelotfad09c72016-06-21 12:28:20 -04001981 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001982 return -EOPNOTSUPP;
1983
Vivien Didelotfad09c72016-06-21 12:28:20 -04001984 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001985
Vivien Didelot77064f32016-11-04 03:23:30 +01001986 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001987 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001988 goto unlock;
1989
Vivien Didelot76e398a2015-11-01 12:33:55 -05001990 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001991 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001992 if (err)
1993 goto unlock;
1994
1995 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001996 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001997 if (err)
1998 goto unlock;
1999 }
2000 }
2001
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002002unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002003 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002004
2005 return err;
2006}
2007
Vivien Didelotfad09c72016-06-21 12:28:20 -04002008static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04002009 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002010{
Vivien Didelota935c052016-09-29 12:21:53 -04002011 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002012
2013 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002014 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
2015 (addr[i * 2] << 8) | addr[i * 2 + 1]);
2016 if (err)
2017 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002018 }
2019
2020 return 0;
2021}
2022
Vivien Didelotfad09c72016-06-21 12:28:20 -04002023static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04002024 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002025{
Vivien Didelota935c052016-09-29 12:21:53 -04002026 u16 val;
2027 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002028
2029 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002030 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
2031 if (err)
2032 return err;
2033
2034 addr[i * 2] = val >> 8;
2035 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002036 }
2037
2038 return 0;
2039}
2040
Vivien Didelotfad09c72016-06-21 12:28:20 -04002041static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04002042 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002043{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002044 int ret;
2045
Vivien Didelotfad09c72016-06-21 12:28:20 -04002046 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002047 if (ret < 0)
2048 return ret;
2049
Vivien Didelotfad09c72016-06-21 12:28:20 -04002050 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002051 if (ret < 0)
2052 return ret;
2053
Vivien Didelotfad09c72016-06-21 12:28:20 -04002054 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002055 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002056 return ret;
2057
Vivien Didelotfad09c72016-06-21 12:28:20 -04002058 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002059}
David S. Millercdf09692015-08-11 12:00:37 -07002060
Vivien Didelot88472932016-09-19 19:56:11 -04002061static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2062 struct mv88e6xxx_atu_entry *entry);
2063
2064static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2065 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2066{
2067 struct mv88e6xxx_atu_entry next;
2068 int err;
2069
Andrew Lunn59527582017-01-04 19:56:24 +01002070 memcpy(next.mac, addr, ETH_ALEN);
2071 eth_addr_dec(next.mac);
Vivien Didelot88472932016-09-19 19:56:11 -04002072
2073 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2074 if (err)
2075 return err;
2076
2077 do {
2078 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2079 if (err)
2080 return err;
2081
2082 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2083 break;
2084
2085 if (ether_addr_equal(next.mac, addr)) {
2086 *entry = next;
2087 return 0;
2088 }
Andrew Lunn59527582017-01-04 19:56:24 +01002089 } while (ether_addr_greater(addr, next.mac));
Vivien Didelot88472932016-09-19 19:56:11 -04002090
2091 memset(entry, 0, sizeof(*entry));
2092 entry->fid = fid;
2093 ether_addr_copy(entry->mac, addr);
2094
2095 return 0;
2096}
2097
Vivien Didelot83dabd12016-08-31 11:50:04 -04002098static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2099 const unsigned char *addr, u16 vid,
2100 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002101{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002102 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002103 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002104 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002105
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002106 /* Null VLAN ID corresponds to the port private database */
2107 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002108 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002109 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002110 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002111 if (err)
2112 return err;
2113
Vivien Didelot88472932016-09-19 19:56:11 -04002114 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2115 if (err)
2116 return err;
2117
2118 /* Purge the ATU entry only if no port is using it anymore */
2119 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2120 entry.portv_trunkid &= ~BIT(port);
2121 if (!entry.portv_trunkid)
2122 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2123 } else {
2124 entry.portv_trunkid |= BIT(port);
2125 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002126 }
2127
Vivien Didelotfad09c72016-06-21 12:28:20 -04002128 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002129}
2130
Vivien Didelotf81ec902016-05-09 13:22:58 -04002131static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2132 const struct switchdev_obj_port_fdb *fdb,
2133 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002134{
2135 /* We don't need any dynamic resource from the kernel (yet),
2136 * so skip the prepare phase.
2137 */
2138 return 0;
2139}
2140
Vivien Didelotf81ec902016-05-09 13:22:58 -04002141static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2142 const struct switchdev_obj_port_fdb *fdb,
2143 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002144{
Vivien Didelot04bed142016-08-31 18:06:13 -04002145 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002146
Vivien Didelotfad09c72016-06-21 12:28:20 -04002147 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002148 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2149 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2150 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002151 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002152}
2153
Vivien Didelotf81ec902016-05-09 13:22:58 -04002154static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2155 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002156{
Vivien Didelot04bed142016-08-31 18:06:13 -04002157 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002158 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002159
Vivien Didelotfad09c72016-06-21 12:28:20 -04002160 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002161 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2162 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002163 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002164
Vivien Didelot83dabd12016-08-31 11:50:04 -04002165 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002166}
2167
Vivien Didelotfad09c72016-06-21 12:28:20 -04002168static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002169 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002170{
Vivien Didelot1d194042015-08-10 09:09:51 -04002171 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002172 u16 val;
2173 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002174
2175 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002176
Vivien Didelota935c052016-09-29 12:21:53 -04002177 err = _mv88e6xxx_atu_wait(chip);
2178 if (err)
2179 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002180
Vivien Didelota935c052016-09-29 12:21:53 -04002181 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2182 if (err)
2183 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002184
Vivien Didelota935c052016-09-29 12:21:53 -04002185 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2186 if (err)
2187 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002188
Vivien Didelota935c052016-09-29 12:21:53 -04002189 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2190 if (err)
2191 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002192
Vivien Didelota935c052016-09-29 12:21:53 -04002193 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002194 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2195 unsigned int mask, shift;
2196
Vivien Didelota935c052016-09-29 12:21:53 -04002197 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002198 next.trunk = true;
2199 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2200 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2201 } else {
2202 next.trunk = false;
2203 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2204 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2205 }
2206
Vivien Didelota935c052016-09-29 12:21:53 -04002207 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002208 }
2209
2210 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002211 return 0;
2212}
2213
Vivien Didelot83dabd12016-08-31 11:50:04 -04002214static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2215 u16 fid, u16 vid, int port,
2216 struct switchdev_obj *obj,
2217 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002218{
2219 struct mv88e6xxx_atu_entry addr = {
2220 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2221 };
2222 int err;
2223
Vivien Didelotfad09c72016-06-21 12:28:20 -04002224 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002225 if (err)
2226 return err;
2227
2228 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002229 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002230 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002231 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002232
2233 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2234 break;
2235
Vivien Didelot83dabd12016-08-31 11:50:04 -04002236 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2237 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002238
Vivien Didelot83dabd12016-08-31 11:50:04 -04002239 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2240 struct switchdev_obj_port_fdb *fdb;
2241
2242 if (!is_unicast_ether_addr(addr.mac))
2243 continue;
2244
2245 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002246 fdb->vid = vid;
2247 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002248 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2249 fdb->ndm_state = NUD_NOARP;
2250 else
2251 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002252 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2253 struct switchdev_obj_port_mdb *mdb;
2254
2255 if (!is_multicast_ether_addr(addr.mac))
2256 continue;
2257
2258 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2259 mdb->vid = vid;
2260 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002261 } else {
2262 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002263 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002264
2265 err = cb(obj);
2266 if (err)
2267 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002268 } while (!is_broadcast_ether_addr(addr.mac));
2269
2270 return err;
2271}
2272
Vivien Didelot83dabd12016-08-31 11:50:04 -04002273static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2274 struct switchdev_obj *obj,
2275 int (*cb)(struct switchdev_obj *obj))
2276{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002277 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002278 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2279 };
2280 u16 fid;
2281 int err;
2282
2283 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002284 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002285 if (err)
2286 return err;
2287
2288 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2289 if (err)
2290 return err;
2291
2292 /* Dump VLANs' Filtering Information Databases */
2293 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2294 if (err)
2295 return err;
2296
2297 do {
2298 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2299 if (err)
2300 return err;
2301
2302 if (!vlan.valid)
2303 break;
2304
2305 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2306 obj, cb);
2307 if (err)
2308 return err;
2309 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2310
2311 return err;
2312}
2313
Vivien Didelotf81ec902016-05-09 13:22:58 -04002314static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2315 struct switchdev_obj_port_fdb *fdb,
2316 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002317{
Vivien Didelot04bed142016-08-31 18:06:13 -04002318 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002319 int err;
2320
Vivien Didelotfad09c72016-06-21 12:28:20 -04002321 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002322 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002323 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002324
2325 return err;
2326}
2327
Vivien Didelotf81ec902016-05-09 13:22:58 -04002328static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002329 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002330{
Vivien Didelot04bed142016-08-31 18:06:13 -04002331 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002332 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002333
Vivien Didelotfad09c72016-06-21 12:28:20 -04002334 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002335
Vivien Didelotfae8a252017-01-27 15:29:42 -05002336 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002337 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfae8a252017-01-27 15:29:42 -05002338 if (ds->ports[i].bridge_dev == br) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002339 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002340 if (err)
2341 break;
2342 }
2343 }
2344
Vivien Didelotfad09c72016-06-21 12:28:20 -04002345 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002346
Vivien Didelot466dfa02016-02-26 13:16:05 -05002347 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002348}
2349
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002350static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2351 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002352{
Vivien Didelot04bed142016-08-31 18:06:13 -04002353 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002354 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002355
Vivien Didelotfad09c72016-06-21 12:28:20 -04002356 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002357
Vivien Didelotfae8a252017-01-27 15:29:42 -05002358 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002359 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfae8a252017-01-27 15:29:42 -05002360 if (i == port || ds->ports[i].bridge_dev == br)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002361 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002362 netdev_warn(ds->ports[i].netdev,
2363 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002364
Vivien Didelotfad09c72016-06-21 12:28:20 -04002365 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002366}
2367
Vivien Didelot17e708b2016-12-05 17:30:27 -05002368static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2369{
2370 if (chip->info->ops->reset)
2371 return chip->info->ops->reset(chip);
2372
2373 return 0;
2374}
2375
Vivien Didelot309eca62016-12-05 17:30:26 -05002376static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2377{
2378 struct gpio_desc *gpiod = chip->reset;
2379
2380 /* If there is a GPIO connected to the reset pin, toggle it */
2381 if (gpiod) {
2382 gpiod_set_value_cansleep(gpiod, 1);
2383 usleep_range(10000, 20000);
2384 gpiod_set_value_cansleep(gpiod, 0);
2385 usleep_range(10000, 20000);
2386 }
2387}
2388
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002389static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2390{
2391 int i, err;
2392
2393 /* Set all ports to the Disabled state */
2394 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2395 err = mv88e6xxx_port_set_state(chip, i,
2396 PORT_CONTROL_STATE_DISABLED);
2397 if (err)
2398 return err;
2399 }
2400
2401 /* Wait for transmit queues to drain,
2402 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2403 */
2404 usleep_range(2000, 4000);
2405
2406 return 0;
2407}
2408
Vivien Didelotfad09c72016-06-21 12:28:20 -04002409static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002410{
Vivien Didelota935c052016-09-29 12:21:53 -04002411 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002412
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002413 err = mv88e6xxx_disable_ports(chip);
2414 if (err)
2415 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002416
Vivien Didelot309eca62016-12-05 17:30:26 -05002417 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002418
Vivien Didelot17e708b2016-12-05 17:30:27 -05002419 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002420}
2421
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002422static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002423{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002424 u16 val;
2425 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002426
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002427 /* Clear Power Down bit */
2428 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2429 if (err)
2430 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002431
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002432 if (val & BMCR_PDOWN) {
2433 val &= ~BMCR_PDOWN;
2434 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002435 }
2436
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002437 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002438}
2439
Andrew Lunn56995cb2016-12-03 04:35:19 +01002440static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2441 int upstream_port)
2442{
2443 int err;
2444
2445 err = chip->info->ops->port_set_frame_mode(
2446 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2447 if (err)
2448 return err;
2449
2450 return chip->info->ops->port_set_egress_unknowns(
2451 chip, port, port == upstream_port);
2452}
2453
2454static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2455{
2456 int err;
2457
2458 switch (chip->info->tag_protocol) {
2459 case DSA_TAG_PROTO_EDSA:
2460 err = chip->info->ops->port_set_frame_mode(
2461 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2462 if (err)
2463 return err;
2464
2465 err = mv88e6xxx_port_set_egress_mode(
2466 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2467 if (err)
2468 return err;
2469
2470 if (chip->info->ops->port_set_ether_type)
2471 err = chip->info->ops->port_set_ether_type(
2472 chip, port, ETH_P_EDSA);
2473 break;
2474
2475 case DSA_TAG_PROTO_DSA:
2476 err = chip->info->ops->port_set_frame_mode(
2477 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2478 if (err)
2479 return err;
2480
2481 err = mv88e6xxx_port_set_egress_mode(
2482 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2483 break;
2484 default:
2485 err = -EINVAL;
2486 }
2487
2488 if (err)
2489 return err;
2490
2491 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2492}
2493
2494static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2495{
2496 int err;
2497
2498 err = chip->info->ops->port_set_frame_mode(
2499 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2500 if (err)
2501 return err;
2502
2503 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2504}
2505
Vivien Didelotfad09c72016-06-21 12:28:20 -04002506static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002507{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002508 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002509 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002510 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002511
Vivien Didelotd78343d2016-11-04 03:23:36 +01002512 /* MAC Forcing register: don't force link, speed, duplex or flow control
2513 * state to any particular values on physical ports, but force the CPU
2514 * port and all DSA ports to their maximum bandwidth and full duplex.
2515 */
2516 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2517 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2518 SPEED_MAX, DUPLEX_FULL,
2519 PHY_INTERFACE_MODE_NA);
2520 else
2521 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2522 SPEED_UNFORCED, DUPLEX_UNFORCED,
2523 PHY_INTERFACE_MODE_NA);
2524 if (err)
2525 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002526
2527 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2528 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2529 * tunneling, determine priority by looking at 802.1p and IP
2530 * priority fields (IP prio has precedence), and set STP state
2531 * to Forwarding.
2532 *
2533 * If this is the CPU link, use DSA or EDSA tagging depending
2534 * on which tagging mode was configured.
2535 *
2536 * If this is a link to another switch, use DSA tagging mode.
2537 *
2538 * If this is the upstream port for this switch, enable
2539 * forwarding of unknown unicasts and multicasts.
2540 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002541 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002542 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2543 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002544 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2545 if (err)
2546 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002547
Andrew Lunn56995cb2016-12-03 04:35:19 +01002548 if (dsa_is_cpu_port(ds, port)) {
2549 err = mv88e6xxx_setup_port_cpu(chip, port);
2550 } else if (dsa_is_dsa_port(ds, port)) {
2551 err = mv88e6xxx_setup_port_dsa(chip, port,
2552 dsa_upstream_port(ds));
2553 } else {
2554 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002555 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002556 if (err)
2557 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002558
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002559 /* If this port is connected to a SerDes, make sure the SerDes is not
2560 * powered down.
2561 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002562 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002563 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2564 if (err)
2565 return err;
2566 reg &= PORT_STATUS_CMODE_MASK;
2567 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2568 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2569 (reg == PORT_STATUS_CMODE_SGMII)) {
2570 err = mv88e6xxx_serdes_power_on(chip);
2571 if (err < 0)
2572 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002573 }
2574 }
2575
Vivien Didelot8efdda42015-08-13 12:52:23 -04002576 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002577 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002578 * untagged frames on this port, do a destination address lookup on all
2579 * received packets as usual, disable ARP mirroring and don't send a
2580 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002581 */
2582 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002583 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2584 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2585 mv88e6xxx_6095_family(chip) || mv88e6xxx_6320_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01002586 mv88e6xxx_6185_family(chip) || mv88e6xxx_6341_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002587 reg = PORT_CONTROL_2_MAP_DA;
2588
Vivien Didelotfad09c72016-06-21 12:28:20 -04002589 if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002590 /* Set the upstream port this port should use */
2591 reg |= dsa_upstream_port(ds);
2592 /* enable forwarding of unknown multicast addresses to
2593 * the upstream port
2594 */
2595 if (port == dsa_upstream_port(ds))
2596 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
2597 }
2598
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002599 reg |= PORT_CONTROL_2_8021Q_DISABLED;
Vivien Didelot8efdda42015-08-13 12:52:23 -04002600
Andrew Lunn54d792f2015-05-06 01:09:47 +02002601 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002602 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
2603 if (err)
2604 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002605 }
2606
Andrew Lunn5f436662016-12-03 04:45:17 +01002607 if (chip->info->ops->port_jumbo_config) {
2608 err = chip->info->ops->port_jumbo_config(chip, port);
2609 if (err)
2610 return err;
2611 }
2612
Andrew Lunn54d792f2015-05-06 01:09:47 +02002613 /* Port Association Vector: when learning source addresses
2614 * of packets, add the address to the address database using
2615 * a port bitmap that has only the bit for this port set and
2616 * the other bits clear.
2617 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002618 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002619 /* Disable learning for CPU port */
2620 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002621 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002622
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002623 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2624 if (err)
2625 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002626
2627 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002628 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2629 if (err)
2630 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002631
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002632 if (chip->info->ops->port_pause_config) {
2633 err = chip->info->ops->port_pause_config(chip, port);
2634 if (err)
2635 return err;
2636 }
2637
Vivien Didelotfad09c72016-06-21 12:28:20 -04002638 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2639 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01002640 mv88e6xxx_6320_family(chip) || mv88e6xxx_6341_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002641 /* Port ATU control: disable limiting the number of
2642 * address database entries that this port is allowed
2643 * to use.
2644 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002645 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2646 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002647 /* Priority Override: disable DA, SA and VTU priority
2648 * override.
2649 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002650 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2651 0x0000);
2652 if (err)
2653 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002654 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002655
Andrew Lunnef0a7312016-12-03 04:35:16 +01002656 if (chip->info->ops->port_tag_remap) {
2657 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002658 if (err)
2659 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002660 }
2661
Andrew Lunnef70b112016-12-03 04:45:18 +01002662 if (chip->info->ops->port_egress_rate_limiting) {
2663 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002664 if (err)
2665 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002666 }
2667
Guenter Roeck366f0a02015-03-26 18:36:30 -07002668 /* Port Control 1: disable trunking, disable sending
2669 * learning messages to this port.
Guenter Roeckd827e882015-03-26 18:36:29 -07002670 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002671 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_1, 0x0000);
2672 if (err)
2673 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002674
Vivien Didelot207afda2016-04-14 14:42:09 -04002675 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002676 * database, and allow bidirectional communication between the
2677 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002678 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002679 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002680 if (err)
2681 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002682
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002683 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2684 if (err)
2685 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002686
2687 /* Default VLAN ID and priority: don't set a default VLAN
2688 * ID, and set the default packet priority to zero.
2689 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002690 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002691}
2692
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002693static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002694{
2695 int err;
2696
Vivien Didelota935c052016-09-29 12:21:53 -04002697 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002698 if (err)
2699 return err;
2700
Vivien Didelota935c052016-09-29 12:21:53 -04002701 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002702 if (err)
2703 return err;
2704
Vivien Didelota935c052016-09-29 12:21:53 -04002705 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2706 if (err)
2707 return err;
2708
2709 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002710}
2711
Vivien Didelotacddbd22016-07-18 20:45:39 -04002712static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
2713 unsigned int msecs)
2714{
2715 const unsigned int coeff = chip->info->age_time_coeff;
2716 const unsigned int min = 0x01 * coeff;
2717 const unsigned int max = 0xff * coeff;
2718 u8 age_time;
2719 u16 val;
2720 int err;
2721
2722 if (msecs < min || msecs > max)
2723 return -ERANGE;
2724
2725 /* Round to nearest multiple of coeff */
2726 age_time = (msecs + coeff / 2) / coeff;
2727
Vivien Didelota935c052016-09-29 12:21:53 -04002728 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002729 if (err)
2730 return err;
2731
2732 /* AgeTime is 11:4 bits */
2733 val &= ~0xff0;
2734 val |= age_time << 4;
2735
Vivien Didelota935c052016-09-29 12:21:53 -04002736 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002737}
2738
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002739static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2740 unsigned int ageing_time)
2741{
Vivien Didelot04bed142016-08-31 18:06:13 -04002742 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002743 int err;
2744
2745 mutex_lock(&chip->reg_lock);
2746 err = mv88e6xxx_g1_set_age_time(chip, ageing_time);
2747 mutex_unlock(&chip->reg_lock);
2748
2749 return err;
2750}
2751
Vivien Didelot97299342016-07-18 20:45:30 -04002752static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002753{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002754 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002755 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002756 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002757
Vivien Didelot119477b2016-05-09 13:22:51 -04002758 /* Enable the PHY Polling Unit if present, don't discard any packets,
2759 * and mask all interrupt sources.
2760 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002761 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002762 if (err)
2763 return err;
2764
Andrew Lunn33641992016-12-03 04:35:17 +01002765 if (chip->info->ops->g1_set_cpu_port) {
2766 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2767 if (err)
2768 return err;
2769 }
2770
2771 if (chip->info->ops->g1_set_egress_port) {
2772 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2773 if (err)
2774 return err;
2775 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002776
Vivien Didelot50484ff2016-05-09 13:22:54 -04002777 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002778 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2779 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2780 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002781 if (err)
2782 return err;
2783
Vivien Didelotacddbd22016-07-18 20:45:39 -04002784 /* Clear all the VTU and STU entries */
2785 err = _mv88e6xxx_vtu_stu_flush(chip);
2786 if (err < 0)
2787 return err;
2788
Vivien Didelot08a01262016-05-09 13:22:50 -04002789 /* Set the default address aging time to 5 minutes, and
2790 * enable address learn messages to be sent to all message
2791 * ports.
2792 */
Vivien Didelota935c052016-09-29 12:21:53 -04002793 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2794 GLOBAL_ATU_CONTROL_LEARN2ALL);
Vivien Didelot08a01262016-05-09 13:22:50 -04002795 if (err)
2796 return err;
2797
Vivien Didelotacddbd22016-07-18 20:45:39 -04002798 err = mv88e6xxx_g1_set_age_time(chip, 300000);
2799 if (err)
Vivien Didelot97299342016-07-18 20:45:30 -04002800 return err;
2801
2802 /* Clear all ATU entries */
2803 err = _mv88e6xxx_atu_flush(chip, 0, true);
2804 if (err)
2805 return err;
2806
Vivien Didelot08a01262016-05-09 13:22:50 -04002807 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002808 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002809 if (err)
2810 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002811 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002812 if (err)
2813 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002814 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002815 if (err)
2816 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002817 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002818 if (err)
2819 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002820 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002821 if (err)
2822 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002823 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002824 if (err)
2825 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002826 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002827 if (err)
2828 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002829 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002830 if (err)
2831 return err;
2832
2833 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002834 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002835 if (err)
2836 return err;
2837
Andrew Lunnde2273872016-11-21 23:27:01 +01002838 /* Initialize the statistics unit */
2839 err = mv88e6xxx_stats_set_histogram(chip);
2840 if (err)
2841 return err;
2842
Vivien Didelot97299342016-07-18 20:45:30 -04002843 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002844 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2845 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002846 if (err)
2847 return err;
2848
2849 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002850 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002851 if (err)
2852 return err;
2853
2854 return 0;
2855}
2856
Vivien Didelotf81ec902016-05-09 13:22:58 -04002857static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002858{
Vivien Didelot04bed142016-08-31 18:06:13 -04002859 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002860 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002861 int i;
2862
Vivien Didelotfad09c72016-06-21 12:28:20 -04002863 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002864 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002865
Vivien Didelotfad09c72016-06-21 12:28:20 -04002866 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002867
Vivien Didelot97299342016-07-18 20:45:30 -04002868 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002869 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002870 err = mv88e6xxx_setup_port(chip, i);
2871 if (err)
2872 goto unlock;
2873 }
2874
2875 /* Setup Switch Global 1 Registers */
2876 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002877 if (err)
2878 goto unlock;
2879
Vivien Didelot97299342016-07-18 20:45:30 -04002880 /* Setup Switch Global 2 Registers */
2881 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2882 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002883 if (err)
2884 goto unlock;
2885 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002886
Andrew Lunn6e55f692016-12-03 04:45:16 +01002887 /* Some generations have the configuration of sending reserved
2888 * management frames to the CPU in global2, others in
2889 * global1. Hence it does not fit the two setup functions
2890 * above.
2891 */
2892 if (chip->info->ops->mgmt_rsvd2cpu) {
2893 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2894 if (err)
2895 goto unlock;
2896 }
2897
Vivien Didelot6b17e862015-08-13 12:52:18 -04002898unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002899 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002900
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002901 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002902}
2903
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002904static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2905{
Vivien Didelot04bed142016-08-31 18:06:13 -04002906 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002907 int err;
2908
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002909 if (!chip->info->ops->set_switch_mac)
2910 return -EOPNOTSUPP;
2911
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002912 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002913 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002914 mutex_unlock(&chip->reg_lock);
2915
2916 return err;
2917}
2918
Vivien Didelote57e5e72016-08-15 17:19:00 -04002919static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002920{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002921 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2922 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002923 u16 val;
2924 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002925
Andrew Lunnee26a222017-01-24 14:53:48 +01002926 if (!chip->info->ops->phy_read)
2927 return -EOPNOTSUPP;
2928
Vivien Didelotfad09c72016-06-21 12:28:20 -04002929 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002930 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002931 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002932
2933 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002934}
2935
Vivien Didelote57e5e72016-08-15 17:19:00 -04002936static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002937{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002938 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2939 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002940 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002941
Andrew Lunnee26a222017-01-24 14:53:48 +01002942 if (!chip->info->ops->phy_write)
2943 return -EOPNOTSUPP;
2944
Vivien Didelotfad09c72016-06-21 12:28:20 -04002945 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002946 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002947 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002948
2949 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002950}
2951
Vivien Didelotfad09c72016-06-21 12:28:20 -04002952static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002953 struct device_node *np,
2954 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002955{
2956 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002957 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002958 struct mii_bus *bus;
2959 int err;
2960
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002961 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002962 if (!bus)
2963 return -ENOMEM;
2964
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002965 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002966 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002967 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002968 INIT_LIST_HEAD(&mdio_bus->list);
2969 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002970
Andrew Lunnb516d452016-06-04 21:17:06 +02002971 if (np) {
2972 bus->name = np->full_name;
2973 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2974 } else {
2975 bus->name = "mv88e6xxx SMI";
2976 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2977 }
2978
2979 bus->read = mv88e6xxx_mdio_read;
2980 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002981 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002982
Andrew Lunna3c53be52017-01-24 14:53:50 +01002983 if (np)
2984 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002985 else
2986 err = mdiobus_register(bus);
2987 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002988 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002989 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002990 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002991
2992 if (external)
2993 list_add_tail(&mdio_bus->list, &chip->mdios);
2994 else
2995 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002996
2997 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002998}
2999
Andrew Lunna3c53be52017-01-24 14:53:50 +01003000static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
3001 { .compatible = "marvell,mv88e6xxx-mdio-external",
3002 .data = (void *)true },
3003 { },
3004};
3005
3006static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3007 struct device_node *np)
3008{
3009 const struct of_device_id *match;
3010 struct device_node *child;
3011 int err;
3012
3013 /* Always register one mdio bus for the internal/default mdio
3014 * bus. This maybe represented in the device tree, but is
3015 * optional.
3016 */
3017 child = of_get_child_by_name(np, "mdio");
3018 err = mv88e6xxx_mdio_register(chip, child, false);
3019 if (err)
3020 return err;
3021
3022 /* Walk the device tree, and see if there are any other nodes
3023 * which say they are compatible with the external mdio
3024 * bus.
3025 */
3026 for_each_available_child_of_node(np, child) {
3027 match = of_match_node(mv88e6xxx_mdio_external_match, child);
3028 if (match) {
3029 err = mv88e6xxx_mdio_register(chip, child, true);
3030 if (err)
3031 return err;
3032 }
3033 }
3034
3035 return 0;
3036}
3037
3038static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02003039
3040{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003041 struct mv88e6xxx_mdio_bus *mdio_bus;
3042 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003043
Andrew Lunna3c53be52017-01-24 14:53:50 +01003044 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3045 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003046
Andrew Lunna3c53be52017-01-24 14:53:50 +01003047 mdiobus_unregister(bus);
3048 }
Andrew Lunnb516d452016-06-04 21:17:06 +02003049}
3050
Vivien Didelot855b1932016-07-20 18:18:35 -04003051static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3052{
Vivien Didelot04bed142016-08-31 18:06:13 -04003053 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003054
3055 return chip->eeprom_len;
3056}
3057
Vivien Didelot855b1932016-07-20 18:18:35 -04003058static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3059 struct ethtool_eeprom *eeprom, u8 *data)
3060{
Vivien Didelot04bed142016-08-31 18:06:13 -04003061 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003062 int err;
3063
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003064 if (!chip->info->ops->get_eeprom)
3065 return -EOPNOTSUPP;
3066
Vivien Didelot855b1932016-07-20 18:18:35 -04003067 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003068 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003069 mutex_unlock(&chip->reg_lock);
3070
3071 if (err)
3072 return err;
3073
3074 eeprom->magic = 0xc3ec4951;
3075
3076 return 0;
3077}
3078
Vivien Didelot855b1932016-07-20 18:18:35 -04003079static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3080 struct ethtool_eeprom *eeprom, u8 *data)
3081{
Vivien Didelot04bed142016-08-31 18:06:13 -04003082 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003083 int err;
3084
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003085 if (!chip->info->ops->set_eeprom)
3086 return -EOPNOTSUPP;
3087
Vivien Didelot855b1932016-07-20 18:18:35 -04003088 if (eeprom->magic != 0xc3ec4951)
3089 return -EINVAL;
3090
3091 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003092 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003093 mutex_unlock(&chip->reg_lock);
3094
3095 return err;
3096}
3097
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003098static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003099 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003100 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003101 .phy_read = mv88e6xxx_phy_ppu_read,
3102 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003103 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003104 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003105 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003106 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003107 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3108 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3109 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003110 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003111 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003112 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003113 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3114 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003115 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003116 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3117 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003118 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003119 .ppu_enable = mv88e6185_g1_ppu_enable,
3120 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003121 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003122};
3123
3124static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003125 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003126 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003127 .phy_read = mv88e6xxx_phy_ppu_read,
3128 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003129 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003130 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003131 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003132 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3133 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003134 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003135 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3136 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003137 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003138 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003139 .ppu_enable = mv88e6185_g1_ppu_enable,
3140 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003141 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003142};
3143
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003144static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003145 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003146 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3147 .phy_read = mv88e6xxx_g2_smi_phy_read,
3148 .phy_write = mv88e6xxx_g2_smi_phy_write,
3149 .port_set_link = mv88e6xxx_port_set_link,
3150 .port_set_duplex = mv88e6xxx_port_set_duplex,
3151 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003152 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003153 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3154 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3155 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003156 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003157 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003158 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003159 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3160 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3161 .stats_get_strings = mv88e6095_stats_get_strings,
3162 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003163 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3164 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003165 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003166 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003167};
3168
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003169static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003170 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003171 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003172 .phy_read = mv88e6165_phy_read,
3173 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003174 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003175 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003176 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003177 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3178 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003179 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003180 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3181 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003182 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003183 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3184 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003185 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003186 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003187};
3188
3189static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003190 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003191 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003192 .phy_read = mv88e6xxx_phy_ppu_read,
3193 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003194 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003195 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003196 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003197 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003198 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3199 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3200 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003201 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003202 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003203 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003204 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003205 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3206 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003207 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003208 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3209 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003210 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003211 .ppu_enable = mv88e6185_g1_ppu_enable,
3212 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003213 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003214};
3215
3216static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003217 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003218 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003219 .phy_read = mv88e6165_phy_read,
3220 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003221 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003222 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003223 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003224 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003225 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3226 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3227 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003228 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003229 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003230 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003231 .stats_snapshot = 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 Lunn6e55f692016-12-03 04:45:16 +01003237 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003238 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003239};
3240
3241static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003242 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003243 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003244 .phy_read = mv88e6165_phy_read,
3245 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003246 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003247 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003248 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003249 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003250 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3251 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003252 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003253 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3254 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003255 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003256 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003257};
3258
3259static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003260 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003261 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003262 .phy_read = mv88e6xxx_g2_smi_phy_read,
3263 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003264 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003265 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003266 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003267 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003268 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003269 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3270 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3271 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003272 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003273 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003274 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003275 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003276 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3277 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003278 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003279 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3280 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003281 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003282 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003283};
3284
3285static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003286 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003287 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3288 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003289 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003290 .phy_read = mv88e6xxx_g2_smi_phy_read,
3291 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003292 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003293 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003294 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003295 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003296 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003297 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3298 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3299 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003300 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003301 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003302 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003303 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003304 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3305 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003306 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003307 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3308 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003309 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003310 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003311};
3312
3313static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003314 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003315 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003316 .phy_read = mv88e6xxx_g2_smi_phy_read,
3317 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003318 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003319 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003320 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003321 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003322 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003323 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3324 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3325 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003326 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003327 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003328 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003329 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003330 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3331 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003332 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003333 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3334 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003335 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003336 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003337};
3338
3339static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003340 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003341 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3342 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003343 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003344 .phy_read = mv88e6xxx_g2_smi_phy_read,
3345 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003346 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003347 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003348 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003349 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003350 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003351 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3352 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3353 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003354 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003355 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003356 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003357 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003358 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3359 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003360 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003361 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3362 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003363 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003364 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003365};
3366
3367static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003368 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003369 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003370 .phy_read = mv88e6xxx_phy_ppu_read,
3371 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003372 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003373 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003374 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003375 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3376 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003377 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003378 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003379 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3380 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003381 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003382 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3383 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003384 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003385 .ppu_enable = mv88e6185_g1_ppu_enable,
3386 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003387 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003388};
3389
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003390static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003391 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003392 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3393 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003394 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3395 .phy_read = mv88e6xxx_g2_smi_phy_read,
3396 .phy_write = mv88e6xxx_g2_smi_phy_write,
3397 .port_set_link = mv88e6xxx_port_set_link,
3398 .port_set_duplex = mv88e6xxx_port_set_duplex,
3399 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3400 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003401 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003402 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3403 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3404 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003405 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003406 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003407 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003408 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3409 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003410 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003411 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3412 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003413 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003414 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003415};
3416
3417static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003418 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003419 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3420 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003421 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3422 .phy_read = mv88e6xxx_g2_smi_phy_read,
3423 .phy_write = mv88e6xxx_g2_smi_phy_write,
3424 .port_set_link = mv88e6xxx_port_set_link,
3425 .port_set_duplex = mv88e6xxx_port_set_duplex,
3426 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3427 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003428 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003429 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3430 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3431 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003432 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003433 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003434 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003435 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3436 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003437 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003438 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3439 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003440 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003441 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003442};
3443
3444static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003445 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003446 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3447 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003448 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3449 .phy_read = mv88e6xxx_g2_smi_phy_read,
3450 .phy_write = mv88e6xxx_g2_smi_phy_write,
3451 .port_set_link = mv88e6xxx_port_set_link,
3452 .port_set_duplex = mv88e6xxx_port_set_duplex,
3453 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3454 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003455 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003456 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3457 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3458 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003459 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003460 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003461 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003462 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3463 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003464 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003465 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3466 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003467 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003468 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003469};
3470
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003471static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003472 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003473 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3474 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003475 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003476 .phy_read = mv88e6xxx_g2_smi_phy_read,
3477 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003478 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003479 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003480 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003481 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003482 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003483 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3484 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3485 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003486 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003487 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003488 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003489 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003490 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3491 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003492 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003493 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3494 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003495 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003496 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003497};
3498
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003499static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003500 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003501 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3502 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003503 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3504 .phy_read = mv88e6xxx_g2_smi_phy_read,
3505 .phy_write = mv88e6xxx_g2_smi_phy_write,
3506 .port_set_link = mv88e6xxx_port_set_link,
3507 .port_set_duplex = mv88e6xxx_port_set_duplex,
3508 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3509 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003510 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003511 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3512 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3513 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003514 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003515 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003516 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003517 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3518 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003519 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003520 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3521 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003522 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003523 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003524};
3525
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003526static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003527 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003528 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3529 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003530 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003531 .phy_read = mv88e6xxx_g2_smi_phy_read,
3532 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003533 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003534 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003535 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003536 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003537 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3538 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3539 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003540 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003541 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003542 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003543 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003544 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3545 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003546 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003547 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3548 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003549 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003550 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003551};
3552
3553static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003554 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003555 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3556 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003557 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003558 .phy_read = mv88e6xxx_g2_smi_phy_read,
3559 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003560 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003561 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003562 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003563 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003564 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3565 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3566 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003567 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003568 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003569 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003570 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003571 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3572 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003573 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003574 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3575 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003576 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003577};
3578
3579static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003580 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003581 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003582 .phy_read = mv88e6xxx_g2_smi_phy_read,
3583 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003584 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003585 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003586 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003587 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003588 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003589 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3590 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3591 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003592 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003593 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003594 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003595 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003596 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3597 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003598 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003599 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3600 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003601 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003602 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003603};
3604
3605static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003606 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003607 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003608 .phy_read = mv88e6xxx_g2_smi_phy_read,
3609 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003610 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003611 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003612 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003613 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003614 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003615 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3616 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3617 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003618 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003619 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003620 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003621 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003622 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3623 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003624 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003625 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3626 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003627 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003628 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003629};
3630
3631static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003632 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003633 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3634 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003635 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003636 .phy_read = mv88e6xxx_g2_smi_phy_read,
3637 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003638 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003639 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003640 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003641 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003642 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003643 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3644 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3645 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003646 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003647 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003648 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003649 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003650 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3651 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003652 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003653 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3654 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003655 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003656 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003657};
3658
Gregory CLEMENT15587272017-01-30 20:29:35 +01003659static const struct mv88e6xxx_ops mv88e6141_ops = {
3660 /* MV88E6XXX_FAMILY_6341 */
3661 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3662 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3663 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3664 .phy_read = mv88e6xxx_g2_smi_phy_read,
3665 .phy_write = mv88e6xxx_g2_smi_phy_write,
3666 .port_set_link = mv88e6xxx_port_set_link,
3667 .port_set_duplex = mv88e6xxx_port_set_duplex,
3668 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3669 .port_set_speed = mv88e6390_port_set_speed,
3670 .port_tag_remap = mv88e6095_port_tag_remap,
3671 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3672 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3673 .port_set_ether_type = mv88e6351_port_set_ether_type,
3674 .port_jumbo_config = mv88e6165_port_jumbo_config,
3675 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3676 .port_pause_config = mv88e6097_port_pause_config,
3677 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3678 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3679 .stats_get_strings = mv88e6320_stats_get_strings,
3680 .stats_get_stats = mv88e6390_stats_get_stats,
3681 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3682 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3683 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3684 .reset = mv88e6352_g1_reset,
3685};
3686
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003687static const struct mv88e6xxx_ops mv88e6341_ops = {
3688 /* MV88E6XXX_FAMILY_6341 */
3689 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3690 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3691 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3692 .phy_read = mv88e6xxx_g2_smi_phy_read,
3693 .phy_write = mv88e6xxx_g2_smi_phy_write,
3694 .port_set_link = mv88e6xxx_port_set_link,
3695 .port_set_duplex = mv88e6xxx_port_set_duplex,
3696 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3697 .port_set_speed = mv88e6390_port_set_speed,
3698 .port_tag_remap = mv88e6095_port_tag_remap,
3699 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3700 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3701 .port_set_ether_type = mv88e6351_port_set_ether_type,
3702 .port_jumbo_config = mv88e6165_port_jumbo_config,
3703 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3704 .port_pause_config = mv88e6097_port_pause_config,
3705 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3706 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3707 .stats_get_strings = mv88e6320_stats_get_strings,
3708 .stats_get_stats = mv88e6390_stats_get_stats,
3709 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3710 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3711 .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 Lunn79523472016-11-21 23:27:00 +01003733 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003734 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003735 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3736 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003737 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003738 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3739 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003740 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003741 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003742};
3743
3744static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003745 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003746 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3747 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003748 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3749 .phy_read = mv88e6xxx_g2_smi_phy_read,
3750 .phy_write = mv88e6xxx_g2_smi_phy_write,
3751 .port_set_link = mv88e6xxx_port_set_link,
3752 .port_set_duplex = mv88e6xxx_port_set_duplex,
3753 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3754 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003755 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003756 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3757 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3758 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003759 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003760 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003761 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003762 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003763 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003764 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3765 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003766 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003767 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3768 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003769 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003770 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003771};
3772
3773static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003774 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003775 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3776 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003777 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3778 .phy_read = mv88e6xxx_g2_smi_phy_read,
3779 .phy_write = mv88e6xxx_g2_smi_phy_write,
3780 .port_set_link = mv88e6xxx_port_set_link,
3781 .port_set_duplex = mv88e6xxx_port_set_duplex,
3782 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3783 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003784 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003785 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3786 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3787 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003788 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003789 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003790 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003791 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3792 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003793 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003794 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3795 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003796 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003797 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003798};
3799
Andrew Lunn56995cb2016-12-03 04:35:19 +01003800static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3801 const struct mv88e6xxx_ops *ops)
3802{
3803 if (!ops->port_set_frame_mode) {
3804 dev_err(chip->dev, "Missing port_set_frame_mode");
3805 return -EINVAL;
3806 }
3807
3808 if (!ops->port_set_egress_unknowns) {
3809 dev_err(chip->dev, "Missing port_set_egress_mode");
3810 return -EINVAL;
3811 }
3812
3813 return 0;
3814}
3815
Vivien Didelotf81ec902016-05-09 13:22:58 -04003816static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3817 [MV88E6085] = {
3818 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3819 .family = MV88E6XXX_FAMILY_6097,
3820 .name = "Marvell 88E6085",
3821 .num_databases = 4096,
3822 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003823 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003824 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003825 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003826 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003827 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003828 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003829 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003830 },
3831
3832 [MV88E6095] = {
3833 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3834 .family = MV88E6XXX_FAMILY_6095,
3835 .name = "Marvell 88E6095/88E6095F",
3836 .num_databases = 256,
3837 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003838 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003839 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003840 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003841 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003842 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003843 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003844 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003845 },
3846
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003847 [MV88E6097] = {
3848 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3849 .family = MV88E6XXX_FAMILY_6097,
3850 .name = "Marvell 88E6097/88E6097F",
3851 .num_databases = 4096,
3852 .num_ports = 11,
3853 .port_base_addr = 0x10,
3854 .global1_addr = 0x1b,
3855 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003856 .g1_irqs = 8,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003857 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003858 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3859 .ops = &mv88e6097_ops,
3860 },
3861
Vivien Didelotf81ec902016-05-09 13:22:58 -04003862 [MV88E6123] = {
3863 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3864 .family = MV88E6XXX_FAMILY_6165,
3865 .name = "Marvell 88E6123",
3866 .num_databases = 4096,
3867 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003868 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003869 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003870 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003871 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003872 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003873 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003874 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003875 },
3876
3877 [MV88E6131] = {
3878 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3879 .family = MV88E6XXX_FAMILY_6185,
3880 .name = "Marvell 88E6131",
3881 .num_databases = 256,
3882 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003883 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003884 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003885 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003886 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003887 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003888 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003889 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003890 },
3891
3892 [MV88E6161] = {
3893 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3894 .family = MV88E6XXX_FAMILY_6165,
3895 .name = "Marvell 88E6161",
3896 .num_databases = 4096,
3897 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003898 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003899 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003900 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003901 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003902 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003903 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003904 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003905 },
3906
3907 [MV88E6165] = {
3908 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3909 .family = MV88E6XXX_FAMILY_6165,
3910 .name = "Marvell 88E6165",
3911 .num_databases = 4096,
3912 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003913 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003914 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003915 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003916 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003917 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003918 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003919 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003920 },
3921
3922 [MV88E6171] = {
3923 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3924 .family = MV88E6XXX_FAMILY_6351,
3925 .name = "Marvell 88E6171",
3926 .num_databases = 4096,
3927 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003928 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003929 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003930 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003931 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003932 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003933 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003934 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003935 },
3936
3937 [MV88E6172] = {
3938 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3939 .family = MV88E6XXX_FAMILY_6352,
3940 .name = "Marvell 88E6172",
3941 .num_databases = 4096,
3942 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003943 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003944 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003945 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003946 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003947 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003948 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003949 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003950 },
3951
3952 [MV88E6175] = {
3953 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3954 .family = MV88E6XXX_FAMILY_6351,
3955 .name = "Marvell 88E6175",
3956 .num_databases = 4096,
3957 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003958 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003959 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003960 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003961 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003962 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003963 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003964 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003965 },
3966
3967 [MV88E6176] = {
3968 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3969 .family = MV88E6XXX_FAMILY_6352,
3970 .name = "Marvell 88E6176",
3971 .num_databases = 4096,
3972 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003973 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003974 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003975 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003976 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003977 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003978 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003979 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003980 },
3981
3982 [MV88E6185] = {
3983 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3984 .family = MV88E6XXX_FAMILY_6185,
3985 .name = "Marvell 88E6185",
3986 .num_databases = 256,
3987 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003988 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003989 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003990 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003991 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003992 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003993 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003994 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003995 },
3996
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003997 [MV88E6190] = {
3998 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3999 .family = MV88E6XXX_FAMILY_6390,
4000 .name = "Marvell 88E6190",
4001 .num_databases = 4096,
4002 .num_ports = 11, /* 10 + Z80 */
4003 .port_base_addr = 0x0,
4004 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004005 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004006 .age_time_coeff = 15000,
4007 .g1_irqs = 9,
4008 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4009 .ops = &mv88e6190_ops,
4010 },
4011
4012 [MV88E6190X] = {
4013 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
4014 .family = MV88E6XXX_FAMILY_6390,
4015 .name = "Marvell 88E6190X",
4016 .num_databases = 4096,
4017 .num_ports = 11, /* 10 + Z80 */
4018 .port_base_addr = 0x0,
4019 .global1_addr = 0x1b,
4020 .age_time_coeff = 15000,
4021 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004022 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004023 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4024 .ops = &mv88e6190x_ops,
4025 },
4026
4027 [MV88E6191] = {
4028 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
4029 .family = MV88E6XXX_FAMILY_6390,
4030 .name = "Marvell 88E6191",
4031 .num_databases = 4096,
4032 .num_ports = 11, /* 10 + Z80 */
4033 .port_base_addr = 0x0,
4034 .global1_addr = 0x1b,
4035 .age_time_coeff = 15000,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004036 .g1_irqs = 9,
4037 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004038 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4039 .ops = &mv88e6391_ops,
4040 },
4041
Vivien Didelotf81ec902016-05-09 13:22:58 -04004042 [MV88E6240] = {
4043 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
4044 .family = MV88E6XXX_FAMILY_6352,
4045 .name = "Marvell 88E6240",
4046 .num_databases = 4096,
4047 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004048 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004049 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004050 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004051 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004052 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004053 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004054 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004055 },
4056
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004057 [MV88E6290] = {
4058 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
4059 .family = MV88E6XXX_FAMILY_6390,
4060 .name = "Marvell 88E6290",
4061 .num_databases = 4096,
4062 .num_ports = 11, /* 10 + Z80 */
4063 .port_base_addr = 0x0,
4064 .global1_addr = 0x1b,
4065 .age_time_coeff = 15000,
4066 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004067 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004068 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4069 .ops = &mv88e6290_ops,
4070 },
4071
Vivien Didelotf81ec902016-05-09 13:22:58 -04004072 [MV88E6320] = {
4073 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
4074 .family = MV88E6XXX_FAMILY_6320,
4075 .name = "Marvell 88E6320",
4076 .num_databases = 4096,
4077 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004078 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004079 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004080 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004081 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004082 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004083 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004084 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004085 },
4086
4087 [MV88E6321] = {
4088 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
4089 .family = MV88E6XXX_FAMILY_6320,
4090 .name = "Marvell 88E6321",
4091 .num_databases = 4096,
4092 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004093 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004094 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004095 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004096 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004097 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004098 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004099 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004100 },
4101
Gregory CLEMENT15587272017-01-30 20:29:35 +01004102 [MV88E6141] = {
4103 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
4104 .family = MV88E6XXX_FAMILY_6341,
4105 .name = "Marvell 88E6341",
4106 .num_databases = 4096,
4107 .num_ports = 6,
4108 .port_base_addr = 0x10,
4109 .global1_addr = 0x1b,
4110 .age_time_coeff = 3750,
4111 .tag_protocol = DSA_TAG_PROTO_EDSA,
4112 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
4113 .ops = &mv88e6141_ops,
4114 },
4115
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004116 [MV88E6341] = {
4117 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
4118 .family = MV88E6XXX_FAMILY_6341,
4119 .name = "Marvell 88E6341",
4120 .num_databases = 4096,
4121 .num_ports = 6,
4122 .port_base_addr = 0x10,
4123 .global1_addr = 0x1b,
4124 .age_time_coeff = 3750,
4125 .tag_protocol = DSA_TAG_PROTO_EDSA,
4126 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
4127 .ops = &mv88e6341_ops,
4128 },
4129
Vivien Didelotf81ec902016-05-09 13:22:58 -04004130 [MV88E6350] = {
4131 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
4132 .family = MV88E6XXX_FAMILY_6351,
4133 .name = "Marvell 88E6350",
4134 .num_databases = 4096,
4135 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004136 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004137 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004138 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004139 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004140 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004141 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004142 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004143 },
4144
4145 [MV88E6351] = {
4146 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4147 .family = MV88E6XXX_FAMILY_6351,
4148 .name = "Marvell 88E6351",
4149 .num_databases = 4096,
4150 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004151 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004152 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004153 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004154 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004155 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004156 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004157 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004158 },
4159
4160 [MV88E6352] = {
4161 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4162 .family = MV88E6XXX_FAMILY_6352,
4163 .name = "Marvell 88E6352",
4164 .num_databases = 4096,
4165 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004166 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004167 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004168 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004169 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004170 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004171 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004172 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004173 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004174 [MV88E6390] = {
4175 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4176 .family = MV88E6XXX_FAMILY_6390,
4177 .name = "Marvell 88E6390",
4178 .num_databases = 4096,
4179 .num_ports = 11, /* 10 + Z80 */
4180 .port_base_addr = 0x0,
4181 .global1_addr = 0x1b,
4182 .age_time_coeff = 15000,
4183 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004184 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004185 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4186 .ops = &mv88e6390_ops,
4187 },
4188 [MV88E6390X] = {
4189 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4190 .family = MV88E6XXX_FAMILY_6390,
4191 .name = "Marvell 88E6390X",
4192 .num_databases = 4096,
4193 .num_ports = 11, /* 10 + Z80 */
4194 .port_base_addr = 0x0,
4195 .global1_addr = 0x1b,
4196 .age_time_coeff = 15000,
4197 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004198 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004199 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4200 .ops = &mv88e6390x_ops,
4201 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004202};
4203
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004204static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004205{
Vivien Didelota439c062016-04-17 13:23:58 -04004206 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004207
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004208 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4209 if (mv88e6xxx_table[i].prod_num == prod_num)
4210 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004211
Vivien Didelotb9b37712015-10-30 19:39:48 -04004212 return NULL;
4213}
4214
Vivien Didelotfad09c72016-06-21 12:28:20 -04004215static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004216{
4217 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004218 unsigned int prod_num, rev;
4219 u16 id;
4220 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004221
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004222 mutex_lock(&chip->reg_lock);
4223 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4224 mutex_unlock(&chip->reg_lock);
4225 if (err)
4226 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004227
4228 prod_num = (id & 0xfff0) >> 4;
4229 rev = id & 0x000f;
4230
4231 info = mv88e6xxx_lookup_info(prod_num);
4232 if (!info)
4233 return -ENODEV;
4234
Vivien Didelotcaac8542016-06-20 13:14:09 -04004235 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004236 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004237
Vivien Didelotca070c12016-09-02 14:45:34 -04004238 err = mv88e6xxx_g2_require(chip);
4239 if (err)
4240 return err;
4241
Vivien Didelotfad09c72016-06-21 12:28:20 -04004242 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4243 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004244
4245 return 0;
4246}
4247
Vivien Didelotfad09c72016-06-21 12:28:20 -04004248static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004249{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004250 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004251
Vivien Didelotfad09c72016-06-21 12:28:20 -04004252 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4253 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004254 return NULL;
4255
Vivien Didelotfad09c72016-06-21 12:28:20 -04004256 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004257
Vivien Didelotfad09c72016-06-21 12:28:20 -04004258 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004259 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004260
Vivien Didelotfad09c72016-06-21 12:28:20 -04004261 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004262}
4263
Vivien Didelote57e5e72016-08-15 17:19:00 -04004264static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4265{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004266 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004267 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004268}
4269
Andrew Lunn930188c2016-08-22 16:01:03 +02004270static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4271{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004272 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004273 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004274}
4275
Vivien Didelotfad09c72016-06-21 12:28:20 -04004276static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004277 struct mii_bus *bus, int sw_addr)
4278{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004279 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004280 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004281 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004282 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004283 else
4284 return -EINVAL;
4285
Vivien Didelotfad09c72016-06-21 12:28:20 -04004286 chip->bus = bus;
4287 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004288
4289 return 0;
4290}
4291
Andrew Lunn7b314362016-08-22 16:01:01 +02004292static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4293{
Vivien Didelot04bed142016-08-31 18:06:13 -04004294 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004295
Andrew Lunn443d5a12016-12-03 04:35:18 +01004296 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004297}
4298
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004299static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4300 struct device *host_dev, int sw_addr,
4301 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004302{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004303 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004304 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004305 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004306
Vivien Didelota439c062016-04-17 13:23:58 -04004307 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004308 if (!bus)
4309 return NULL;
4310
Vivien Didelotfad09c72016-06-21 12:28:20 -04004311 chip = mv88e6xxx_alloc_chip(dsa_dev);
4312 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004313 return NULL;
4314
Vivien Didelotcaac8542016-06-20 13:14:09 -04004315 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004316 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004317
Vivien Didelotfad09c72016-06-21 12:28:20 -04004318 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004319 if (err)
4320 goto free;
4321
Vivien Didelotfad09c72016-06-21 12:28:20 -04004322 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004323 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004324 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004325
Andrew Lunndc30c352016-10-16 19:56:49 +02004326 mutex_lock(&chip->reg_lock);
4327 err = mv88e6xxx_switch_reset(chip);
4328 mutex_unlock(&chip->reg_lock);
4329 if (err)
4330 goto free;
4331
Vivien Didelote57e5e72016-08-15 17:19:00 -04004332 mv88e6xxx_phy_init(chip);
4333
Andrew Lunna3c53be52017-01-24 14:53:50 +01004334 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004335 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004336 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004337
Vivien Didelotfad09c72016-06-21 12:28:20 -04004338 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004339
Vivien Didelotfad09c72016-06-21 12:28:20 -04004340 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004341free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004342 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004343
4344 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004345}
4346
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004347static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4348 const struct switchdev_obj_port_mdb *mdb,
4349 struct switchdev_trans *trans)
4350{
4351 /* We don't need any dynamic resource from the kernel (yet),
4352 * so skip the prepare phase.
4353 */
4354
4355 return 0;
4356}
4357
4358static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4359 const struct switchdev_obj_port_mdb *mdb,
4360 struct switchdev_trans *trans)
4361{
Vivien Didelot04bed142016-08-31 18:06:13 -04004362 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004363
4364 mutex_lock(&chip->reg_lock);
4365 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4366 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4367 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4368 mutex_unlock(&chip->reg_lock);
4369}
4370
4371static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4372 const struct switchdev_obj_port_mdb *mdb)
4373{
Vivien Didelot04bed142016-08-31 18:06:13 -04004374 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004375 int err;
4376
4377 mutex_lock(&chip->reg_lock);
4378 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4379 GLOBAL_ATU_DATA_STATE_UNUSED);
4380 mutex_unlock(&chip->reg_lock);
4381
4382 return err;
4383}
4384
4385static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4386 struct switchdev_obj_port_mdb *mdb,
4387 int (*cb)(struct switchdev_obj *obj))
4388{
Vivien Didelot04bed142016-08-31 18:06:13 -04004389 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004390 int err;
4391
4392 mutex_lock(&chip->reg_lock);
4393 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4394 mutex_unlock(&chip->reg_lock);
4395
4396 return err;
4397}
4398
Florian Fainellia82f67a2017-01-08 14:52:08 -08004399static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004400 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004401 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004402 .setup = mv88e6xxx_setup,
4403 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004404 .adjust_link = mv88e6xxx_adjust_link,
4405 .get_strings = mv88e6xxx_get_strings,
4406 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4407 .get_sset_count = mv88e6xxx_get_sset_count,
4408 .set_eee = mv88e6xxx_set_eee,
4409 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004410 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004411 .get_eeprom = mv88e6xxx_get_eeprom,
4412 .set_eeprom = mv88e6xxx_set_eeprom,
4413 .get_regs_len = mv88e6xxx_get_regs_len,
4414 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004415 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004416 .port_bridge_join = mv88e6xxx_port_bridge_join,
4417 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4418 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004419 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004420 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4421 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4422 .port_vlan_add = mv88e6xxx_port_vlan_add,
4423 .port_vlan_del = mv88e6xxx_port_vlan_del,
4424 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4425 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4426 .port_fdb_add = mv88e6xxx_port_fdb_add,
4427 .port_fdb_del = mv88e6xxx_port_fdb_del,
4428 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004429 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4430 .port_mdb_add = mv88e6xxx_port_mdb_add,
4431 .port_mdb_del = mv88e6xxx_port_mdb_del,
4432 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004433};
4434
Florian Fainelliab3d4082017-01-08 14:52:07 -08004435static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4436 .ops = &mv88e6xxx_switch_ops,
4437};
4438
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004439static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004440{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004441 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004442 struct dsa_switch *ds;
4443
Vivien Didelota0c02162017-01-27 15:29:36 -05004444 ds = dsa_switch_alloc(dev, DSA_MAX_PORTS);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004445 if (!ds)
4446 return -ENOMEM;
4447
Vivien Didelotfad09c72016-06-21 12:28:20 -04004448 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004449 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004450
4451 dev_set_drvdata(dev, ds);
4452
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004453 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004454}
4455
Vivien Didelotfad09c72016-06-21 12:28:20 -04004456static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004457{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004458 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004459}
4460
Vivien Didelot57d32312016-06-20 13:13:58 -04004461static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004462{
4463 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004464 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004465 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004466 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004467 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004468 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004469
Vivien Didelotcaac8542016-06-20 13:14:09 -04004470 compat_info = of_device_get_match_data(dev);
4471 if (!compat_info)
4472 return -EINVAL;
4473
Vivien Didelotfad09c72016-06-21 12:28:20 -04004474 chip = mv88e6xxx_alloc_chip(dev);
4475 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004476 return -ENOMEM;
4477
Vivien Didelotfad09c72016-06-21 12:28:20 -04004478 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004479
Andrew Lunn56995cb2016-12-03 04:35:19 +01004480 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4481 if (err)
4482 return err;
4483
Vivien Didelotfad09c72016-06-21 12:28:20 -04004484 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004485 if (err)
4486 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004487
Andrew Lunnb4308f02016-11-21 23:26:55 +01004488 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4489 if (IS_ERR(chip->reset))
4490 return PTR_ERR(chip->reset);
4491
Vivien Didelotfad09c72016-06-21 12:28:20 -04004492 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004493 if (err)
4494 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004495
Vivien Didelote57e5e72016-08-15 17:19:00 -04004496 mv88e6xxx_phy_init(chip);
4497
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004498 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004499 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004500 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004501
Andrew Lunndc30c352016-10-16 19:56:49 +02004502 mutex_lock(&chip->reg_lock);
4503 err = mv88e6xxx_switch_reset(chip);
4504 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004505 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004506 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004507
Andrew Lunndc30c352016-10-16 19:56:49 +02004508 chip->irq = of_irq_get(np, 0);
4509 if (chip->irq == -EPROBE_DEFER) {
4510 err = chip->irq;
4511 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004512 }
4513
Andrew Lunndc30c352016-10-16 19:56:49 +02004514 if (chip->irq > 0) {
4515 /* Has to be performed before the MDIO bus is created,
4516 * because the PHYs will link there interrupts to these
4517 * interrupt controllers
4518 */
4519 mutex_lock(&chip->reg_lock);
4520 err = mv88e6xxx_g1_irq_setup(chip);
4521 mutex_unlock(&chip->reg_lock);
4522
4523 if (err)
4524 goto out;
4525
4526 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4527 err = mv88e6xxx_g2_irq_setup(chip);
4528 if (err)
4529 goto out_g1_irq;
4530 }
4531 }
4532
Andrew Lunna3c53be52017-01-24 14:53:50 +01004533 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004534 if (err)
4535 goto out_g2_irq;
4536
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004537 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004538 if (err)
4539 goto out_mdio;
4540
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004541 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004542
4543out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004544 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004545out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004546 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004547 mv88e6xxx_g2_irq_free(chip);
4548out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004549 if (chip->irq > 0) {
4550 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004551 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004552 mutex_unlock(&chip->reg_lock);
4553 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004554out:
4555 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004556}
4557
4558static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4559{
4560 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004561 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004562
Andrew Lunn930188c2016-08-22 16:01:03 +02004563 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004564 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004565 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004566
Andrew Lunn467126442016-11-20 20:14:15 +01004567 if (chip->irq > 0) {
4568 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4569 mv88e6xxx_g2_irq_free(chip);
4570 mv88e6xxx_g1_irq_free(chip);
4571 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004572}
4573
4574static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004575 {
4576 .compatible = "marvell,mv88e6085",
4577 .data = &mv88e6xxx_table[MV88E6085],
4578 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004579 {
4580 .compatible = "marvell,mv88e6190",
4581 .data = &mv88e6xxx_table[MV88E6190],
4582 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004583 { /* sentinel */ },
4584};
4585
4586MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4587
4588static struct mdio_driver mv88e6xxx_driver = {
4589 .probe = mv88e6xxx_probe,
4590 .remove = mv88e6xxx_remove,
4591 .mdiodrv.driver = {
4592 .name = "mv88e6085",
4593 .of_match_table = mv88e6xxx_of_match,
4594 },
4595};
4596
Ben Hutchings98e67302011-11-25 14:36:19 +00004597static int __init mv88e6xxx_init(void)
4598{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004599 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004600 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004601}
4602module_init(mv88e6xxx_init);
4603
4604static void __exit mv88e6xxx_cleanup(void)
4605{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004606 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004607 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004608}
4609module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004610
4611MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4612MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4613MODULE_LICENSE("GPL");