blob: e62d1476b63dc09609de40b11ca513b07090fa42 [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
Andrew Lunnf39908d2017-02-04 20:02:50 +0100752 if (chip->info->ops->port_set_cmode) {
753 err = chip->info->ops->port_set_cmode(chip, port, mode);
754 if (err && err != -EOPNOTSUPP)
755 goto restore_link;
756 }
757
Vivien Didelotd78343d2016-11-04 03:23:36 +0100758 err = 0;
759restore_link:
760 if (chip->info->ops->port_set_link(chip, port, link))
761 netdev_err(chip->ds->ports[port].netdev,
762 "failed to restore MAC's link\n");
763
764 return err;
765}
766
Andrew Lunndea87022015-08-31 15:56:47 +0200767/* We expect the switch to perform auto negotiation if there is a real
768 * phy. However, in the case of a fixed link phy, we force the port
769 * settings from the fixed link settings.
770 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400771static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
772 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200773{
Vivien Didelot04bed142016-08-31 18:06:13 -0400774 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200775 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200776
777 if (!phy_is_pseudo_fixed_link(phydev))
778 return;
779
Vivien Didelotfad09c72016-06-21 12:28:20 -0400780 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100781 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
782 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400783 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100784
785 if (err && err != -EOPNOTSUPP)
786 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200787}
788
Andrew Lunna605a0f2016-11-21 23:26:58 +0100789static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000790{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100791 if (!chip->info->ops->stats_snapshot)
792 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000793
Andrew Lunna605a0f2016-11-21 23:26:58 +0100794 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000795}
796
Andrew Lunne413e7e2015-04-02 04:06:38 +0200797static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100798 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
799 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
800 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
801 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
802 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
803 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
804 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
805 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
806 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
807 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
808 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
809 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
810 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
811 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
812 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
813 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
814 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
815 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
816 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
817 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
818 { "single", 4, 0x14, STATS_TYPE_BANK0, },
819 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
820 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
821 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
822 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
823 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
824 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
825 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
826 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
827 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
828 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
829 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
830 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
831 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
832 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
833 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
834 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
835 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
836 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
837 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
838 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
839 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
840 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
841 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
842 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
843 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
844 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
845 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
846 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
847 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
848 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
849 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
850 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
851 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
852 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
853 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
854 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
855 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
856 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200857};
858
Vivien Didelotfad09c72016-06-21 12:28:20 -0400859static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100860 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100861 int port, u16 bank1_select,
862 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200863{
Andrew Lunn80c46272015-06-20 18:42:30 +0200864 u32 low;
865 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100866 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200867 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200868 u64 value;
869
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100870 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100871 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200872 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
873 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200874 return UINT64_MAX;
875
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200876 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200877 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200878 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
879 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200880 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200881 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200882 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100883 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100884 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100885 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100886 /* fall through */
887 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100888 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100889 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200890 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100891 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200892 }
893 value = (((u64)high) << 16) | low;
894 return value;
895}
896
Andrew Lunndfafe442016-11-21 23:27:02 +0100897static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
898 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100899{
900 struct mv88e6xxx_hw_stat *stat;
901 int i, j;
902
903 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
904 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100905 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100906 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
907 ETH_GSTRING_LEN);
908 j++;
909 }
910 }
911}
912
Andrew Lunndfafe442016-11-21 23:27:02 +0100913static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
914 uint8_t *data)
915{
916 mv88e6xxx_stats_get_strings(chip, data,
917 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
918}
919
920static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
921 uint8_t *data)
922{
923 mv88e6xxx_stats_get_strings(chip, data,
924 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
925}
926
927static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
928 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100929{
Vivien Didelot04bed142016-08-31 18:06:13 -0400930 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100931
932 if (chip->info->ops->stats_get_strings)
933 chip->info->ops->stats_get_strings(chip, data);
934}
935
936static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
937 int types)
938{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100939 struct mv88e6xxx_hw_stat *stat;
940 int i, j;
941
942 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
943 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100944 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100945 j++;
946 }
947 return j;
948}
949
Andrew Lunndfafe442016-11-21 23:27:02 +0100950static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
951{
952 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
953 STATS_TYPE_PORT);
954}
955
956static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
957{
958 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
959 STATS_TYPE_BANK1);
960}
961
962static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
963{
964 struct mv88e6xxx_chip *chip = ds->priv;
965
966 if (chip->info->ops->stats_get_sset_count)
967 return chip->info->ops->stats_get_sset_count(chip);
968
969 return 0;
970}
971
Andrew Lunn052f9472016-11-21 23:27:03 +0100972static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100973 uint64_t *data, int types,
974 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100975{
976 struct mv88e6xxx_hw_stat *stat;
977 int i, j;
978
979 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
980 stat = &mv88e6xxx_hw_stats[i];
981 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100982 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
983 bank1_select,
984 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100985 j++;
986 }
987 }
988}
989
990static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
991 uint64_t *data)
992{
993 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100994 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
995 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100996}
997
998static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
999 uint64_t *data)
1000{
1001 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +01001002 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1003 GLOBAL_STATS_OP_BANK_1_BIT_9,
1004 GLOBAL_STATS_OP_HIST_RX_TX);
1005}
1006
1007static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1008 uint64_t *data)
1009{
1010 return mv88e6xxx_stats_get_stats(chip, port, data,
1011 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1012 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001013}
1014
1015static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1016 uint64_t *data)
1017{
1018 if (chip->info->ops->stats_get_stats)
1019 chip->info->ops->stats_get_stats(chip, port, data);
1020}
1021
Vivien Didelotf81ec902016-05-09 13:22:58 -04001022static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1023 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001024{
Vivien Didelot04bed142016-08-31 18:06:13 -04001025 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001026 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001027
Vivien Didelotfad09c72016-06-21 12:28:20 -04001028 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001029
Andrew Lunna605a0f2016-11-21 23:26:58 +01001030 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001031 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001032 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001033 return;
1034 }
Andrew Lunn052f9472016-11-21 23:27:03 +01001035
1036 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001037
Vivien Didelotfad09c72016-06-21 12:28:20 -04001038 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001039}
Ben Hutchings98e67302011-11-25 14:36:19 +00001040
Andrew Lunnde2273872016-11-21 23:27:01 +01001041static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1042{
1043 if (chip->info->ops->stats_set_histogram)
1044 return chip->info->ops->stats_set_histogram(chip);
1045
1046 return 0;
1047}
1048
Vivien Didelotf81ec902016-05-09 13:22:58 -04001049static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001050{
1051 return 32 * sizeof(u16);
1052}
1053
Vivien Didelotf81ec902016-05-09 13:22:58 -04001054static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1055 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001056{
Vivien Didelot04bed142016-08-31 18:06:13 -04001057 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001058 int err;
1059 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001060 u16 *p = _p;
1061 int i;
1062
1063 regs->version = 0;
1064
1065 memset(p, 0xff, 32 * sizeof(u16));
1066
Vivien Didelotfad09c72016-06-21 12:28:20 -04001067 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001068
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001069 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001070
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001071 err = mv88e6xxx_port_read(chip, port, i, &reg);
1072 if (!err)
1073 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001074 }
Vivien Didelot23062512016-05-09 13:22:45 -04001075
Vivien Didelotfad09c72016-06-21 12:28:20 -04001076 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001077}
1078
Vivien Didelotfad09c72016-06-21 12:28:20 -04001079static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001080{
Vivien Didelota935c052016-09-29 12:21:53 -04001081 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001082}
1083
Vivien Didelotf81ec902016-05-09 13:22:58 -04001084static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1085 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001086{
Vivien Didelot04bed142016-08-31 18:06:13 -04001087 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001088 u16 reg;
1089 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001090
Vivien Didelotfad09c72016-06-21 12:28:20 -04001091 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001092 return -EOPNOTSUPP;
1093
Vivien Didelotfad09c72016-06-21 12:28:20 -04001094 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001095
Vivien Didelot9c938292016-08-15 17:19:02 -04001096 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1097 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001098 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001099
1100 e->eee_enabled = !!(reg & 0x0200);
1101 e->tx_lpi_enabled = !!(reg & 0x0100);
1102
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001103 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001104 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001105 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001106
Andrew Lunncca8b132015-04-02 04:06:39 +02001107 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001108out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001109 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001110
1111 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001112}
1113
Vivien Didelotf81ec902016-05-09 13:22:58 -04001114static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1115 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001116{
Vivien Didelot04bed142016-08-31 18:06:13 -04001117 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001118 u16 reg;
1119 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001120
Vivien Didelotfad09c72016-06-21 12:28:20 -04001121 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001122 return -EOPNOTSUPP;
1123
Vivien Didelotfad09c72016-06-21 12:28:20 -04001124 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001125
Vivien Didelot9c938292016-08-15 17:19:02 -04001126 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1127 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001128 goto out;
1129
Vivien Didelot9c938292016-08-15 17:19:02 -04001130 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001131 if (e->eee_enabled)
1132 reg |= 0x0200;
1133 if (e->tx_lpi_enabled)
1134 reg |= 0x0100;
1135
Vivien Didelot9c938292016-08-15 17:19:02 -04001136 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001137out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001138 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001139
Vivien Didelot9c938292016-08-15 17:19:02 -04001140 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001141}
1142
Vivien Didelotfad09c72016-06-21 12:28:20 -04001143static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001144{
Vivien Didelota935c052016-09-29 12:21:53 -04001145 u16 val;
1146 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001147
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001148 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001149 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1150 if (err)
1151 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001152 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001153 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001154 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1155 if (err)
1156 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001157
Vivien Didelota935c052016-09-29 12:21:53 -04001158 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1159 (val & 0xfff) | ((fid << 8) & 0xf000));
1160 if (err)
1161 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001162
1163 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1164 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001165 }
1166
Vivien Didelota935c052016-09-29 12:21:53 -04001167 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1168 if (err)
1169 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001170
Vivien Didelotfad09c72016-06-21 12:28:20 -04001171 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001172}
1173
Vivien Didelotfad09c72016-06-21 12:28:20 -04001174static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001175 struct mv88e6xxx_atu_entry *entry)
1176{
1177 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1178
1179 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1180 unsigned int mask, shift;
1181
1182 if (entry->trunk) {
1183 data |= GLOBAL_ATU_DATA_TRUNK;
1184 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1185 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1186 } else {
1187 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1188 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1189 }
1190
1191 data |= (entry->portv_trunkid << shift) & mask;
1192 }
1193
Vivien Didelota935c052016-09-29 12:21:53 -04001194 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001195}
1196
Vivien Didelotfad09c72016-06-21 12:28:20 -04001197static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001198 struct mv88e6xxx_atu_entry *entry,
1199 bool static_too)
1200{
1201 int op;
1202 int err;
1203
Vivien Didelotfad09c72016-06-21 12:28:20 -04001204 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001205 if (err)
1206 return err;
1207
Vivien Didelotfad09c72016-06-21 12:28:20 -04001208 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001209 if (err)
1210 return err;
1211
1212 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001213 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1214 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1215 } else {
1216 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1217 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1218 }
1219
Vivien Didelotfad09c72016-06-21 12:28:20 -04001220 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001221}
1222
Vivien Didelotfad09c72016-06-21 12:28:20 -04001223static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001224 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001225{
1226 struct mv88e6xxx_atu_entry entry = {
1227 .fid = fid,
1228 .state = 0, /* EntryState bits must be 0 */
1229 };
1230
Vivien Didelotfad09c72016-06-21 12:28:20 -04001231 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001232}
1233
Vivien Didelotfad09c72016-06-21 12:28:20 -04001234static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001235 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001236{
1237 struct mv88e6xxx_atu_entry entry = {
1238 .trunk = false,
1239 .fid = fid,
1240 };
1241
1242 /* EntryState bits must be 0xF */
1243 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1244
1245 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1246 entry.portv_trunkid = (to_port & 0x0f) << 4;
1247 entry.portv_trunkid |= from_port & 0x0f;
1248
Vivien Didelotfad09c72016-06-21 12:28:20 -04001249 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001250}
1251
Vivien Didelotfad09c72016-06-21 12:28:20 -04001252static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001253 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001254{
1255 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001256 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001257}
1258
Vivien Didelotfad09c72016-06-21 12:28:20 -04001259static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001260{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001261 struct dsa_switch *ds = chip->ds;
Vivien Didelotfae8a252017-01-27 15:29:42 -05001262 struct net_device *bridge = ds->ports[port].bridge_dev;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001263 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001264 int i;
1265
1266 /* allow CPU port or DSA link(s) to send frames to every port */
1267 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001268 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001269 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001270 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001271 /* allow sending frames to every group member */
Vivien Didelotfae8a252017-01-27 15:29:42 -05001272 if (bridge && ds->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001273 output_ports |= BIT(i);
1274
1275 /* allow sending frames to CPU port and DSA link(s) */
1276 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1277 output_ports |= BIT(i);
1278 }
1279 }
1280
1281 /* prevent frames from going back out of the port they came in on */
1282 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001283
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001284 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001285}
1286
Vivien Didelotf81ec902016-05-09 13:22:58 -04001287static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1288 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001289{
Vivien Didelot04bed142016-08-31 18:06:13 -04001290 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001291 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001292 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001293
1294 switch (state) {
1295 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001296 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001297 break;
1298 case BR_STATE_BLOCKING:
1299 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001300 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001301 break;
1302 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001303 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001304 break;
1305 case BR_STATE_FORWARDING:
1306 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001307 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001308 break;
1309 }
1310
Vivien Didelotfad09c72016-06-21 12:28:20 -04001311 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001312 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001313 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001314
1315 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001316 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001317}
1318
Vivien Didelot749efcb2016-09-22 16:49:24 -04001319static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1320{
1321 struct mv88e6xxx_chip *chip = ds->priv;
1322 int err;
1323
1324 mutex_lock(&chip->reg_lock);
1325 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1326 mutex_unlock(&chip->reg_lock);
1327
1328 if (err)
1329 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1330}
1331
Vivien Didelotfad09c72016-06-21 12:28:20 -04001332static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001333{
Vivien Didelota935c052016-09-29 12:21:53 -04001334 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001335}
1336
Vivien Didelotfad09c72016-06-21 12:28:20 -04001337static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001338{
Vivien Didelota935c052016-09-29 12:21:53 -04001339 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001340
Vivien Didelota935c052016-09-29 12:21:53 -04001341 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1342 if (err)
1343 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001344
Vivien Didelotfad09c72016-06-21 12:28:20 -04001345 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001346}
1347
Vivien Didelotfad09c72016-06-21 12:28:20 -04001348static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001349{
1350 int ret;
1351
Vivien Didelotfad09c72016-06-21 12:28:20 -04001352 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001353 if (ret < 0)
1354 return ret;
1355
Vivien Didelotfad09c72016-06-21 12:28:20 -04001356 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001357}
1358
Vivien Didelotfad09c72016-06-21 12:28:20 -04001359static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001360 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001361 unsigned int nibble_offset)
1362{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001363 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001364 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001365
1366 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001367 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001368
Vivien Didelota935c052016-09-29 12:21:53 -04001369 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1370 if (err)
1371 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001372 }
1373
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001374 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001375 unsigned int shift = (i % 4) * 4 + nibble_offset;
1376 u16 reg = regs[i / 4];
1377
1378 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1379 }
1380
1381 return 0;
1382}
1383
Vivien Didelotfad09c72016-06-21 12:28:20 -04001384static int mv88e6xxx_vtu_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, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001388}
1389
Vivien Didelotfad09c72016-06-21 12:28:20 -04001390static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001391 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001392{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001393 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001394}
1395
Vivien Didelotfad09c72016-06-21 12:28:20 -04001396static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001397 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001398 unsigned int nibble_offset)
1399{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001400 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001401 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001402
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001403 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001404 unsigned int shift = (i % 4) * 4 + nibble_offset;
1405 u8 data = entry->data[i];
1406
1407 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1408 }
1409
1410 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001411 u16 reg = regs[i];
1412
1413 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1414 if (err)
1415 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001416 }
1417
1418 return 0;
1419}
1420
Vivien Didelotfad09c72016-06-21 12:28:20 -04001421static int mv88e6xxx_vtu_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, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001425}
1426
Vivien Didelotfad09c72016-06-21 12:28:20 -04001427static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001428 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001429{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001430 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001431}
1432
Vivien Didelotfad09c72016-06-21 12:28:20 -04001433static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001434{
Vivien Didelota935c052016-09-29 12:21:53 -04001435 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1436 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001437}
1438
Vivien Didelotfad09c72016-06-21 12:28:20 -04001439static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001440 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001441{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001442 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001443 u16 val;
1444 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001445
Vivien Didelota935c052016-09-29 12:21:53 -04001446 err = _mv88e6xxx_vtu_wait(chip);
1447 if (err)
1448 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001449
Vivien Didelota935c052016-09-29 12:21:53 -04001450 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1451 if (err)
1452 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001453
Vivien Didelota935c052016-09-29 12:21:53 -04001454 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1455 if (err)
1456 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001457
Vivien Didelota935c052016-09-29 12:21:53 -04001458 next.vid = val & GLOBAL_VTU_VID_MASK;
1459 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001460
1461 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001462 err = mv88e6xxx_vtu_data_read(chip, &next);
1463 if (err)
1464 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001465
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001466 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001467 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1468 if (err)
1469 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001470
Vivien Didelota935c052016-09-29 12:21:53 -04001471 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001472 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001473 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1474 * VTU DBNum[3:0] are located in VTU Operation 3:0
1475 */
Vivien Didelota935c052016-09-29 12:21:53 -04001476 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1477 if (err)
1478 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001479
Vivien Didelota935c052016-09-29 12:21:53 -04001480 next.fid = (val & 0xf00) >> 4;
1481 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001482 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001483
Vivien Didelotfad09c72016-06-21 12:28:20 -04001484 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001485 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1486 if (err)
1487 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001488
Vivien Didelota935c052016-09-29 12:21:53 -04001489 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001490 }
1491 }
1492
1493 *entry = next;
1494 return 0;
1495}
1496
Vivien Didelotf81ec902016-05-09 13:22:58 -04001497static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1498 struct switchdev_obj_port_vlan *vlan,
1499 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001500{
Vivien Didelot04bed142016-08-31 18:06:13 -04001501 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001502 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001503 u16 pvid;
1504 int err;
1505
Vivien Didelotfad09c72016-06-21 12:28:20 -04001506 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001507 return -EOPNOTSUPP;
1508
Vivien Didelotfad09c72016-06-21 12:28:20 -04001509 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001510
Vivien Didelot77064f32016-11-04 03:23:30 +01001511 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001512 if (err)
1513 goto unlock;
1514
Vivien Didelotfad09c72016-06-21 12:28:20 -04001515 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001516 if (err)
1517 goto unlock;
1518
1519 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001520 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001521 if (err)
1522 break;
1523
1524 if (!next.valid)
1525 break;
1526
1527 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1528 continue;
1529
1530 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001531 vlan->vid_begin = next.vid;
1532 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001533 vlan->flags = 0;
1534
1535 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1536 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1537
1538 if (next.vid == pvid)
1539 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1540
1541 err = cb(&vlan->obj);
1542 if (err)
1543 break;
1544 } while (next.vid < GLOBAL_VTU_VID_MASK);
1545
1546unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001547 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001548
1549 return err;
1550}
1551
Vivien Didelotfad09c72016-06-21 12:28:20 -04001552static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001553 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001554{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001555 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001556 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001557 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001558
Vivien Didelota935c052016-09-29 12:21:53 -04001559 err = _mv88e6xxx_vtu_wait(chip);
1560 if (err)
1561 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001562
1563 if (!entry->valid)
1564 goto loadpurge;
1565
1566 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001567 err = mv88e6xxx_vtu_data_write(chip, entry);
1568 if (err)
1569 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001570
Vivien Didelotfad09c72016-06-21 12:28:20 -04001571 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001572 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001573 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1574 if (err)
1575 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001576 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001577
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001578 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001579 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001580 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1581 if (err)
1582 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001583 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001584 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1585 * VTU DBNum[3:0] are located in VTU Operation 3:0
1586 */
1587 op |= (entry->fid & 0xf0) << 8;
1588 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001589 }
1590
1591 reg = GLOBAL_VTU_VID_VALID;
1592loadpurge:
1593 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001594 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1595 if (err)
1596 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001597
Vivien Didelotfad09c72016-06-21 12:28:20 -04001598 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001599}
1600
Vivien Didelotfad09c72016-06-21 12:28:20 -04001601static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001602 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001603{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001604 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001605 u16 val;
1606 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001607
Vivien Didelota935c052016-09-29 12:21:53 -04001608 err = _mv88e6xxx_vtu_wait(chip);
1609 if (err)
1610 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001611
Vivien Didelota935c052016-09-29 12:21:53 -04001612 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1613 sid & GLOBAL_VTU_SID_MASK);
1614 if (err)
1615 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001616
Vivien Didelota935c052016-09-29 12:21:53 -04001617 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1618 if (err)
1619 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001620
Vivien Didelota935c052016-09-29 12:21:53 -04001621 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1622 if (err)
1623 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001624
Vivien Didelota935c052016-09-29 12:21:53 -04001625 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001626
Vivien Didelota935c052016-09-29 12:21:53 -04001627 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1628 if (err)
1629 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001630
Vivien Didelota935c052016-09-29 12:21:53 -04001631 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001632
1633 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001634 err = mv88e6xxx_stu_data_read(chip, &next);
1635 if (err)
1636 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001637 }
1638
1639 *entry = next;
1640 return 0;
1641}
1642
Vivien Didelotfad09c72016-06-21 12:28:20 -04001643static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001644 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001645{
1646 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001647 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001648
Vivien Didelota935c052016-09-29 12:21:53 -04001649 err = _mv88e6xxx_vtu_wait(chip);
1650 if (err)
1651 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001652
1653 if (!entry->valid)
1654 goto loadpurge;
1655
1656 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001657 err = mv88e6xxx_stu_data_write(chip, entry);
1658 if (err)
1659 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001660
1661 reg = GLOBAL_VTU_VID_VALID;
1662loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001663 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1664 if (err)
1665 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001666
1667 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001668 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1669 if (err)
1670 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001671
Vivien Didelotfad09c72016-06-21 12:28:20 -04001672 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001673}
1674
Vivien Didelotfad09c72016-06-21 12:28:20 -04001675static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001676{
1677 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001678 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001679 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001680
1681 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1682
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001683 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001684 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001685 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001686 if (err)
1687 return err;
1688
1689 set_bit(*fid, fid_bitmap);
1690 }
1691
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001692 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001693 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001694 if (err)
1695 return err;
1696
1697 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001698 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001699 if (err)
1700 return err;
1701
1702 if (!vlan.valid)
1703 break;
1704
1705 set_bit(vlan.fid, fid_bitmap);
1706 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1707
1708 /* The reset value 0x000 is used to indicate that multiple address
1709 * databases are not needed. Return the next positive available.
1710 */
1711 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001712 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001713 return -ENOSPC;
1714
1715 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001716 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001717}
1718
Vivien Didelotfad09c72016-06-21 12:28:20 -04001719static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001720 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001721{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001722 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001723 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001724 .valid = true,
1725 .vid = vid,
1726 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001727 int i, err;
1728
Vivien Didelotfad09c72016-06-21 12:28:20 -04001729 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001730 if (err)
1731 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001732
Vivien Didelot3d131f02015-11-03 10:52:52 -05001733 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001734 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001735 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1736 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1737 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001738
Vivien Didelotfad09c72016-06-21 12:28:20 -04001739 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01001740 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip) ||
1741 mv88e6xxx_6341_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001742 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001743
1744 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1745 * implemented, only one STU entry is needed to cover all VTU
1746 * entries. Thus, validate the SID 0.
1747 */
1748 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001749 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001750 if (err)
1751 return err;
1752
1753 if (vstp.sid != vlan.sid || !vstp.valid) {
1754 memset(&vstp, 0, sizeof(vstp));
1755 vstp.valid = true;
1756 vstp.sid = vlan.sid;
1757
Vivien Didelotfad09c72016-06-21 12:28:20 -04001758 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001759 if (err)
1760 return err;
1761 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001762 }
1763
1764 *entry = vlan;
1765 return 0;
1766}
1767
Vivien Didelotfad09c72016-06-21 12:28:20 -04001768static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001769 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001770{
1771 int err;
1772
1773 if (!vid)
1774 return -EINVAL;
1775
Vivien Didelotfad09c72016-06-21 12:28:20 -04001776 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001777 if (err)
1778 return err;
1779
Vivien Didelotfad09c72016-06-21 12:28:20 -04001780 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001781 if (err)
1782 return err;
1783
1784 if (entry->vid != vid || !entry->valid) {
1785 if (!creat)
1786 return -EOPNOTSUPP;
1787 /* -ENOENT would've been more appropriate, but switchdev expects
1788 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1789 */
1790
Vivien Didelotfad09c72016-06-21 12:28:20 -04001791 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001792 }
1793
1794 return err;
1795}
1796
Vivien Didelotda9c3592016-02-12 12:09:40 -05001797static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1798 u16 vid_begin, u16 vid_end)
1799{
Vivien Didelot04bed142016-08-31 18:06:13 -04001800 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001801 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001802 int i, err;
1803
1804 if (!vid_begin)
1805 return -EOPNOTSUPP;
1806
Vivien Didelotfad09c72016-06-21 12:28:20 -04001807 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001808
Vivien Didelotfad09c72016-06-21 12:28:20 -04001809 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001810 if (err)
1811 goto unlock;
1812
1813 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001814 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001815 if (err)
1816 goto unlock;
1817
1818 if (!vlan.valid)
1819 break;
1820
1821 if (vlan.vid > vid_end)
1822 break;
1823
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001824 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001825 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1826 continue;
1827
Andrew Lunn66e28092016-12-11 21:07:19 +01001828 if (!ds->ports[port].netdev)
1829 continue;
1830
Vivien Didelotda9c3592016-02-12 12:09:40 -05001831 if (vlan.data[i] ==
1832 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1833 continue;
1834
Vivien Didelotfae8a252017-01-27 15:29:42 -05001835 if (ds->ports[i].bridge_dev ==
1836 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001837 break; /* same bridge, check next VLAN */
1838
Vivien Didelotfae8a252017-01-27 15:29:42 -05001839 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001840 continue;
1841
Andrew Lunnc8b09802016-06-04 21:16:57 +02001842 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001843 "hardware VLAN %d already used by %s\n",
1844 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001845 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001846 err = -EOPNOTSUPP;
1847 goto unlock;
1848 }
1849 } while (vlan.vid < vid_end);
1850
1851unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001852 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001853
1854 return err;
1855}
1856
Vivien Didelotf81ec902016-05-09 13:22:58 -04001857static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1858 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001859{
Vivien Didelot04bed142016-08-31 18:06:13 -04001860 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001861 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001862 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001863 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001864
Vivien Didelotfad09c72016-06-21 12:28:20 -04001865 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001866 return -EOPNOTSUPP;
1867
Vivien Didelotfad09c72016-06-21 12:28:20 -04001868 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001869 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001870 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001871
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001872 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001873}
1874
Vivien Didelot57d32312016-06-20 13:13:58 -04001875static int
1876mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1877 const struct switchdev_obj_port_vlan *vlan,
1878 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001879{
Vivien Didelot04bed142016-08-31 18:06:13 -04001880 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001881 int err;
1882
Vivien Didelotfad09c72016-06-21 12:28:20 -04001883 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001884 return -EOPNOTSUPP;
1885
Vivien Didelotda9c3592016-02-12 12:09:40 -05001886 /* If the requested port doesn't belong to the same bridge as the VLAN
1887 * members, do not support it (yet) and fallback to software VLAN.
1888 */
1889 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1890 vlan->vid_end);
1891 if (err)
1892 return err;
1893
Vivien Didelot76e398a2015-11-01 12:33:55 -05001894 /* We don't need any dynamic resource from the kernel (yet),
1895 * so skip the prepare phase.
1896 */
1897 return 0;
1898}
1899
Vivien Didelotfad09c72016-06-21 12:28:20 -04001900static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001901 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001902{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001903 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001904 int err;
1905
Vivien Didelotfad09c72016-06-21 12:28:20 -04001906 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001907 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001908 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001909
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001910 vlan.data[port] = untagged ?
1911 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1912 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1913
Vivien Didelotfad09c72016-06-21 12:28:20 -04001914 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001915}
1916
Vivien Didelotf81ec902016-05-09 13:22:58 -04001917static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1918 const struct switchdev_obj_port_vlan *vlan,
1919 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001920{
Vivien Didelot04bed142016-08-31 18:06:13 -04001921 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001922 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1923 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1924 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001925
Vivien Didelotfad09c72016-06-21 12:28:20 -04001926 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001927 return;
1928
Vivien Didelotfad09c72016-06-21 12:28:20 -04001929 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001930
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001931 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001932 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001933 netdev_err(ds->ports[port].netdev,
1934 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001935 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001936
Vivien Didelot77064f32016-11-04 03:23:30 +01001937 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001938 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001939 vlan->vid_end);
1940
Vivien Didelotfad09c72016-06-21 12:28:20 -04001941 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001942}
1943
Vivien Didelotfad09c72016-06-21 12:28:20 -04001944static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001945 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001946{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001947 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001948 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001949 int i, err;
1950
Vivien Didelotfad09c72016-06-21 12:28:20 -04001951 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001952 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001953 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001954
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001955 /* Tell switchdev if this VLAN is handled in software */
1956 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001957 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001958
1959 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1960
1961 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001962 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001963 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001964 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001965 continue;
1966
1967 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001968 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001969 break;
1970 }
1971 }
1972
Vivien Didelotfad09c72016-06-21 12:28:20 -04001973 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001974 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001975 return err;
1976
Vivien Didelotfad09c72016-06-21 12:28:20 -04001977 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001978}
1979
Vivien Didelotf81ec902016-05-09 13:22:58 -04001980static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1981 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001982{
Vivien Didelot04bed142016-08-31 18:06:13 -04001983 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001984 u16 pvid, vid;
1985 int err = 0;
1986
Vivien Didelotfad09c72016-06-21 12:28:20 -04001987 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001988 return -EOPNOTSUPP;
1989
Vivien Didelotfad09c72016-06-21 12:28:20 -04001990 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001991
Vivien Didelot77064f32016-11-04 03:23:30 +01001992 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001993 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001994 goto unlock;
1995
Vivien Didelot76e398a2015-11-01 12:33:55 -05001996 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001997 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001998 if (err)
1999 goto unlock;
2000
2001 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01002002 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002003 if (err)
2004 goto unlock;
2005 }
2006 }
2007
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002008unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002009 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002010
2011 return err;
2012}
2013
Vivien Didelotfad09c72016-06-21 12:28:20 -04002014static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04002015 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002016{
Vivien Didelota935c052016-09-29 12:21:53 -04002017 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002018
2019 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002020 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
2021 (addr[i * 2] << 8) | addr[i * 2 + 1]);
2022 if (err)
2023 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002024 }
2025
2026 return 0;
2027}
2028
Vivien Didelotfad09c72016-06-21 12:28:20 -04002029static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04002030 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002031{
Vivien Didelota935c052016-09-29 12:21:53 -04002032 u16 val;
2033 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002034
2035 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002036 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
2037 if (err)
2038 return err;
2039
2040 addr[i * 2] = val >> 8;
2041 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002042 }
2043
2044 return 0;
2045}
2046
Vivien Didelotfad09c72016-06-21 12:28:20 -04002047static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04002048 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002049{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002050 int ret;
2051
Vivien Didelotfad09c72016-06-21 12:28:20 -04002052 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002053 if (ret < 0)
2054 return ret;
2055
Vivien Didelotfad09c72016-06-21 12:28:20 -04002056 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002057 if (ret < 0)
2058 return ret;
2059
Vivien Didelotfad09c72016-06-21 12:28:20 -04002060 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002061 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002062 return ret;
2063
Vivien Didelotfad09c72016-06-21 12:28:20 -04002064 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002065}
David S. Millercdf09692015-08-11 12:00:37 -07002066
Vivien Didelot88472932016-09-19 19:56:11 -04002067static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2068 struct mv88e6xxx_atu_entry *entry);
2069
2070static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2071 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2072{
2073 struct mv88e6xxx_atu_entry next;
2074 int err;
2075
Andrew Lunn59527582017-01-04 19:56:24 +01002076 memcpy(next.mac, addr, ETH_ALEN);
2077 eth_addr_dec(next.mac);
Vivien Didelot88472932016-09-19 19:56:11 -04002078
2079 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2080 if (err)
2081 return err;
2082
2083 do {
2084 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2085 if (err)
2086 return err;
2087
2088 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2089 break;
2090
2091 if (ether_addr_equal(next.mac, addr)) {
2092 *entry = next;
2093 return 0;
2094 }
Andrew Lunn59527582017-01-04 19:56:24 +01002095 } while (ether_addr_greater(addr, next.mac));
Vivien Didelot88472932016-09-19 19:56:11 -04002096
2097 memset(entry, 0, sizeof(*entry));
2098 entry->fid = fid;
2099 ether_addr_copy(entry->mac, addr);
2100
2101 return 0;
2102}
2103
Vivien Didelot83dabd12016-08-31 11:50:04 -04002104static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2105 const unsigned char *addr, u16 vid,
2106 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002107{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002108 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002109 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002110 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002111
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002112 /* Null VLAN ID corresponds to the port private database */
2113 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002114 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002115 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002116 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002117 if (err)
2118 return err;
2119
Vivien Didelot88472932016-09-19 19:56:11 -04002120 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2121 if (err)
2122 return err;
2123
2124 /* Purge the ATU entry only if no port is using it anymore */
2125 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2126 entry.portv_trunkid &= ~BIT(port);
2127 if (!entry.portv_trunkid)
2128 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2129 } else {
2130 entry.portv_trunkid |= BIT(port);
2131 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002132 }
2133
Vivien Didelotfad09c72016-06-21 12:28:20 -04002134 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002135}
2136
Vivien Didelotf81ec902016-05-09 13:22:58 -04002137static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2138 const struct switchdev_obj_port_fdb *fdb,
2139 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002140{
2141 /* We don't need any dynamic resource from the kernel (yet),
2142 * so skip the prepare phase.
2143 */
2144 return 0;
2145}
2146
Vivien Didelotf81ec902016-05-09 13:22:58 -04002147static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2148 const struct switchdev_obj_port_fdb *fdb,
2149 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002150{
Vivien Didelot04bed142016-08-31 18:06:13 -04002151 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002152
Vivien Didelotfad09c72016-06-21 12:28:20 -04002153 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002154 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2155 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2156 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002157 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002158}
2159
Vivien Didelotf81ec902016-05-09 13:22:58 -04002160static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2161 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002162{
Vivien Didelot04bed142016-08-31 18:06:13 -04002163 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002164 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002165
Vivien Didelotfad09c72016-06-21 12:28:20 -04002166 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002167 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2168 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002169 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002170
Vivien Didelot83dabd12016-08-31 11:50:04 -04002171 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002172}
2173
Vivien Didelotfad09c72016-06-21 12:28:20 -04002174static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002175 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002176{
Vivien Didelot1d194042015-08-10 09:09:51 -04002177 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002178 u16 val;
2179 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002180
2181 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002182
Vivien Didelota935c052016-09-29 12:21:53 -04002183 err = _mv88e6xxx_atu_wait(chip);
2184 if (err)
2185 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002186
Vivien Didelota935c052016-09-29 12:21:53 -04002187 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2188 if (err)
2189 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002190
Vivien Didelota935c052016-09-29 12:21:53 -04002191 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2192 if (err)
2193 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002194
Vivien Didelota935c052016-09-29 12:21:53 -04002195 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2196 if (err)
2197 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002198
Vivien Didelota935c052016-09-29 12:21:53 -04002199 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002200 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2201 unsigned int mask, shift;
2202
Vivien Didelota935c052016-09-29 12:21:53 -04002203 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002204 next.trunk = true;
2205 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2206 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2207 } else {
2208 next.trunk = false;
2209 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2210 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2211 }
2212
Vivien Didelota935c052016-09-29 12:21:53 -04002213 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002214 }
2215
2216 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002217 return 0;
2218}
2219
Vivien Didelot83dabd12016-08-31 11:50:04 -04002220static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2221 u16 fid, u16 vid, int port,
2222 struct switchdev_obj *obj,
2223 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002224{
2225 struct mv88e6xxx_atu_entry addr = {
2226 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2227 };
2228 int err;
2229
Vivien Didelotfad09c72016-06-21 12:28:20 -04002230 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002231 if (err)
2232 return err;
2233
2234 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002235 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002236 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002237 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002238
2239 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2240 break;
2241
Vivien Didelot83dabd12016-08-31 11:50:04 -04002242 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2243 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002244
Vivien Didelot83dabd12016-08-31 11:50:04 -04002245 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2246 struct switchdev_obj_port_fdb *fdb;
2247
2248 if (!is_unicast_ether_addr(addr.mac))
2249 continue;
2250
2251 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002252 fdb->vid = vid;
2253 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002254 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2255 fdb->ndm_state = NUD_NOARP;
2256 else
2257 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002258 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2259 struct switchdev_obj_port_mdb *mdb;
2260
2261 if (!is_multicast_ether_addr(addr.mac))
2262 continue;
2263
2264 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2265 mdb->vid = vid;
2266 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002267 } else {
2268 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002269 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002270
2271 err = cb(obj);
2272 if (err)
2273 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002274 } while (!is_broadcast_ether_addr(addr.mac));
2275
2276 return err;
2277}
2278
Vivien Didelot83dabd12016-08-31 11:50:04 -04002279static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2280 struct switchdev_obj *obj,
2281 int (*cb)(struct switchdev_obj *obj))
2282{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002283 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002284 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2285 };
2286 u16 fid;
2287 int err;
2288
2289 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002290 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002291 if (err)
2292 return err;
2293
2294 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2295 if (err)
2296 return err;
2297
2298 /* Dump VLANs' Filtering Information Databases */
2299 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2300 if (err)
2301 return err;
2302
2303 do {
2304 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2305 if (err)
2306 return err;
2307
2308 if (!vlan.valid)
2309 break;
2310
2311 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2312 obj, cb);
2313 if (err)
2314 return err;
2315 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2316
2317 return err;
2318}
2319
Vivien Didelotf81ec902016-05-09 13:22:58 -04002320static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2321 struct switchdev_obj_port_fdb *fdb,
2322 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002323{
Vivien Didelot04bed142016-08-31 18:06:13 -04002324 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002325 int err;
2326
Vivien Didelotfad09c72016-06-21 12:28:20 -04002327 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002328 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002329 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002330
2331 return err;
2332}
2333
Vivien Didelotf81ec902016-05-09 13:22:58 -04002334static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002335 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002336{
Vivien Didelot04bed142016-08-31 18:06:13 -04002337 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002338 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002339
Vivien Didelotfad09c72016-06-21 12:28:20 -04002340 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002341
Vivien Didelotfae8a252017-01-27 15:29:42 -05002342 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002343 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfae8a252017-01-27 15:29:42 -05002344 if (ds->ports[i].bridge_dev == br) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002345 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002346 if (err)
2347 break;
2348 }
2349 }
2350
Vivien Didelotfad09c72016-06-21 12:28:20 -04002351 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002352
Vivien Didelot466dfa02016-02-26 13:16:05 -05002353 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002354}
2355
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002356static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2357 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002358{
Vivien Didelot04bed142016-08-31 18:06:13 -04002359 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002360 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002361
Vivien Didelotfad09c72016-06-21 12:28:20 -04002362 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002363
Vivien Didelotfae8a252017-01-27 15:29:42 -05002364 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002365 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfae8a252017-01-27 15:29:42 -05002366 if (i == port || ds->ports[i].bridge_dev == br)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002367 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002368 netdev_warn(ds->ports[i].netdev,
2369 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002370
Vivien Didelotfad09c72016-06-21 12:28:20 -04002371 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002372}
2373
Vivien Didelot17e708b2016-12-05 17:30:27 -05002374static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2375{
2376 if (chip->info->ops->reset)
2377 return chip->info->ops->reset(chip);
2378
2379 return 0;
2380}
2381
Vivien Didelot309eca62016-12-05 17:30:26 -05002382static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2383{
2384 struct gpio_desc *gpiod = chip->reset;
2385
2386 /* If there is a GPIO connected to the reset pin, toggle it */
2387 if (gpiod) {
2388 gpiod_set_value_cansleep(gpiod, 1);
2389 usleep_range(10000, 20000);
2390 gpiod_set_value_cansleep(gpiod, 0);
2391 usleep_range(10000, 20000);
2392 }
2393}
2394
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002395static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2396{
2397 int i, err;
2398
2399 /* Set all ports to the Disabled state */
2400 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2401 err = mv88e6xxx_port_set_state(chip, i,
2402 PORT_CONTROL_STATE_DISABLED);
2403 if (err)
2404 return err;
2405 }
2406
2407 /* Wait for transmit queues to drain,
2408 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2409 */
2410 usleep_range(2000, 4000);
2411
2412 return 0;
2413}
2414
Vivien Didelotfad09c72016-06-21 12:28:20 -04002415static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002416{
Vivien Didelota935c052016-09-29 12:21:53 -04002417 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002418
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002419 err = mv88e6xxx_disable_ports(chip);
2420 if (err)
2421 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002422
Vivien Didelot309eca62016-12-05 17:30:26 -05002423 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002424
Vivien Didelot17e708b2016-12-05 17:30:27 -05002425 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002426}
2427
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002428static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002429{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002430 u16 val;
2431 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002432
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002433 /* Clear Power Down bit */
2434 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2435 if (err)
2436 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002437
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002438 if (val & BMCR_PDOWN) {
2439 val &= ~BMCR_PDOWN;
2440 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002441 }
2442
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002443 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002444}
2445
Andrew Lunn56995cb2016-12-03 04:35:19 +01002446static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2447 int upstream_port)
2448{
2449 int err;
2450
2451 err = chip->info->ops->port_set_frame_mode(
2452 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2453 if (err)
2454 return err;
2455
2456 return chip->info->ops->port_set_egress_unknowns(
2457 chip, port, port == upstream_port);
2458}
2459
2460static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2461{
2462 int err;
2463
2464 switch (chip->info->tag_protocol) {
2465 case DSA_TAG_PROTO_EDSA:
2466 err = chip->info->ops->port_set_frame_mode(
2467 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2468 if (err)
2469 return err;
2470
2471 err = mv88e6xxx_port_set_egress_mode(
2472 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2473 if (err)
2474 return err;
2475
2476 if (chip->info->ops->port_set_ether_type)
2477 err = chip->info->ops->port_set_ether_type(
2478 chip, port, ETH_P_EDSA);
2479 break;
2480
2481 case DSA_TAG_PROTO_DSA:
2482 err = chip->info->ops->port_set_frame_mode(
2483 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2484 if (err)
2485 return err;
2486
2487 err = mv88e6xxx_port_set_egress_mode(
2488 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2489 break;
2490 default:
2491 err = -EINVAL;
2492 }
2493
2494 if (err)
2495 return err;
2496
2497 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2498}
2499
2500static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2501{
2502 int err;
2503
2504 err = chip->info->ops->port_set_frame_mode(
2505 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2506 if (err)
2507 return err;
2508
2509 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2510}
2511
Vivien Didelotfad09c72016-06-21 12:28:20 -04002512static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002513{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002514 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002515 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002516 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002517
Vivien Didelotd78343d2016-11-04 03:23:36 +01002518 /* MAC Forcing register: don't force link, speed, duplex or flow control
2519 * state to any particular values on physical ports, but force the CPU
2520 * port and all DSA ports to their maximum bandwidth and full duplex.
2521 */
2522 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2523 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2524 SPEED_MAX, DUPLEX_FULL,
2525 PHY_INTERFACE_MODE_NA);
2526 else
2527 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2528 SPEED_UNFORCED, DUPLEX_UNFORCED,
2529 PHY_INTERFACE_MODE_NA);
2530 if (err)
2531 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002532
2533 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2534 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2535 * tunneling, determine priority by looking at 802.1p and IP
2536 * priority fields (IP prio has precedence), and set STP state
2537 * to Forwarding.
2538 *
2539 * If this is the CPU link, use DSA or EDSA tagging depending
2540 * on which tagging mode was configured.
2541 *
2542 * If this is a link to another switch, use DSA tagging mode.
2543 *
2544 * If this is the upstream port for this switch, enable
2545 * forwarding of unknown unicasts and multicasts.
2546 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002547 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002548 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2549 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002550 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2551 if (err)
2552 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002553
Andrew Lunn56995cb2016-12-03 04:35:19 +01002554 if (dsa_is_cpu_port(ds, port)) {
2555 err = mv88e6xxx_setup_port_cpu(chip, port);
2556 } else if (dsa_is_dsa_port(ds, port)) {
2557 err = mv88e6xxx_setup_port_dsa(chip, port,
2558 dsa_upstream_port(ds));
2559 } else {
2560 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002561 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002562 if (err)
2563 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002564
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002565 /* If this port is connected to a SerDes, make sure the SerDes is not
2566 * powered down.
2567 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002568 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002569 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2570 if (err)
2571 return err;
2572 reg &= PORT_STATUS_CMODE_MASK;
2573 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2574 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2575 (reg == PORT_STATUS_CMODE_SGMII)) {
2576 err = mv88e6xxx_serdes_power_on(chip);
2577 if (err < 0)
2578 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002579 }
2580 }
2581
Vivien Didelot8efdda42015-08-13 12:52:23 -04002582 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002583 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002584 * untagged frames on this port, do a destination address lookup on all
2585 * received packets as usual, disable ARP mirroring and don't send a
2586 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002587 */
2588 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002589 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2590 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2591 mv88e6xxx_6095_family(chip) || mv88e6xxx_6320_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01002592 mv88e6xxx_6185_family(chip) || mv88e6xxx_6341_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002593 reg = PORT_CONTROL_2_MAP_DA;
2594
Vivien Didelotfad09c72016-06-21 12:28:20 -04002595 if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002596 /* Set the upstream port this port should use */
2597 reg |= dsa_upstream_port(ds);
2598 /* enable forwarding of unknown multicast addresses to
2599 * the upstream port
2600 */
2601 if (port == dsa_upstream_port(ds))
2602 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
2603 }
2604
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002605 reg |= PORT_CONTROL_2_8021Q_DISABLED;
Vivien Didelot8efdda42015-08-13 12:52:23 -04002606
Andrew Lunn54d792f2015-05-06 01:09:47 +02002607 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002608 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
2609 if (err)
2610 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002611 }
2612
Andrew Lunn5f436662016-12-03 04:45:17 +01002613 if (chip->info->ops->port_jumbo_config) {
2614 err = chip->info->ops->port_jumbo_config(chip, port);
2615 if (err)
2616 return err;
2617 }
2618
Andrew Lunn54d792f2015-05-06 01:09:47 +02002619 /* Port Association Vector: when learning source addresses
2620 * of packets, add the address to the address database using
2621 * a port bitmap that has only the bit for this port set and
2622 * the other bits clear.
2623 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002624 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002625 /* Disable learning for CPU port */
2626 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002627 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002628
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002629 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2630 if (err)
2631 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002632
2633 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002634 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2635 if (err)
2636 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002637
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002638 if (chip->info->ops->port_pause_config) {
2639 err = chip->info->ops->port_pause_config(chip, port);
2640 if (err)
2641 return err;
2642 }
2643
Vivien Didelotfad09c72016-06-21 12:28:20 -04002644 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2645 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01002646 mv88e6xxx_6320_family(chip) || mv88e6xxx_6341_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002647 /* Port ATU control: disable limiting the number of
2648 * address database entries that this port is allowed
2649 * to use.
2650 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002651 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2652 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002653 /* Priority Override: disable DA, SA and VTU priority
2654 * override.
2655 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002656 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2657 0x0000);
2658 if (err)
2659 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002660 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002661
Andrew Lunnef0a7312016-12-03 04:35:16 +01002662 if (chip->info->ops->port_tag_remap) {
2663 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002664 if (err)
2665 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002666 }
2667
Andrew Lunnef70b112016-12-03 04:45:18 +01002668 if (chip->info->ops->port_egress_rate_limiting) {
2669 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002670 if (err)
2671 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002672 }
2673
Guenter Roeck366f0a02015-03-26 18:36:30 -07002674 /* Port Control 1: disable trunking, disable sending
2675 * learning messages to this port.
Guenter Roeckd827e882015-03-26 18:36:29 -07002676 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002677 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_1, 0x0000);
2678 if (err)
2679 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002680
Vivien Didelot207afda2016-04-14 14:42:09 -04002681 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002682 * database, and allow bidirectional communication between the
2683 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002684 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002685 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002686 if (err)
2687 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002688
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002689 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2690 if (err)
2691 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002692
2693 /* Default VLAN ID and priority: don't set a default VLAN
2694 * ID, and set the default packet priority to zero.
2695 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002696 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002697}
2698
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002699static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002700{
2701 int err;
2702
Vivien Didelota935c052016-09-29 12:21:53 -04002703 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002704 if (err)
2705 return err;
2706
Vivien Didelota935c052016-09-29 12:21:53 -04002707 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002708 if (err)
2709 return err;
2710
Vivien Didelota935c052016-09-29 12:21:53 -04002711 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2712 if (err)
2713 return err;
2714
2715 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002716}
2717
Vivien Didelotacddbd22016-07-18 20:45:39 -04002718static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
2719 unsigned int msecs)
2720{
2721 const unsigned int coeff = chip->info->age_time_coeff;
2722 const unsigned int min = 0x01 * coeff;
2723 const unsigned int max = 0xff * coeff;
2724 u8 age_time;
2725 u16 val;
2726 int err;
2727
2728 if (msecs < min || msecs > max)
2729 return -ERANGE;
2730
2731 /* Round to nearest multiple of coeff */
2732 age_time = (msecs + coeff / 2) / coeff;
2733
Vivien Didelota935c052016-09-29 12:21:53 -04002734 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002735 if (err)
2736 return err;
2737
2738 /* AgeTime is 11:4 bits */
2739 val &= ~0xff0;
2740 val |= age_time << 4;
2741
Vivien Didelota935c052016-09-29 12:21:53 -04002742 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002743}
2744
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002745static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2746 unsigned int ageing_time)
2747{
Vivien Didelot04bed142016-08-31 18:06:13 -04002748 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002749 int err;
2750
2751 mutex_lock(&chip->reg_lock);
2752 err = mv88e6xxx_g1_set_age_time(chip, ageing_time);
2753 mutex_unlock(&chip->reg_lock);
2754
2755 return err;
2756}
2757
Vivien Didelot97299342016-07-18 20:45:30 -04002758static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002759{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002760 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002761 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002762 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002763
Vivien Didelot119477b2016-05-09 13:22:51 -04002764 /* Enable the PHY Polling Unit if present, don't discard any packets,
2765 * and mask all interrupt sources.
2766 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002767 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002768 if (err)
2769 return err;
2770
Andrew Lunn33641992016-12-03 04:35:17 +01002771 if (chip->info->ops->g1_set_cpu_port) {
2772 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2773 if (err)
2774 return err;
2775 }
2776
2777 if (chip->info->ops->g1_set_egress_port) {
2778 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2779 if (err)
2780 return err;
2781 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002782
Vivien Didelot50484ff2016-05-09 13:22:54 -04002783 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002784 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2785 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2786 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002787 if (err)
2788 return err;
2789
Vivien Didelotacddbd22016-07-18 20:45:39 -04002790 /* Clear all the VTU and STU entries */
2791 err = _mv88e6xxx_vtu_stu_flush(chip);
2792 if (err < 0)
2793 return err;
2794
Vivien Didelot08a01262016-05-09 13:22:50 -04002795 /* Set the default address aging time to 5 minutes, and
2796 * enable address learn messages to be sent to all message
2797 * ports.
2798 */
Vivien Didelota935c052016-09-29 12:21:53 -04002799 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2800 GLOBAL_ATU_CONTROL_LEARN2ALL);
Vivien Didelot08a01262016-05-09 13:22:50 -04002801 if (err)
2802 return err;
2803
Vivien Didelotacddbd22016-07-18 20:45:39 -04002804 err = mv88e6xxx_g1_set_age_time(chip, 300000);
2805 if (err)
Vivien Didelot97299342016-07-18 20:45:30 -04002806 return err;
2807
2808 /* Clear all ATU entries */
2809 err = _mv88e6xxx_atu_flush(chip, 0, true);
2810 if (err)
2811 return err;
2812
Vivien Didelot08a01262016-05-09 13:22:50 -04002813 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002814 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
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_1, 0x0000);
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_2, 0x5555);
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_3, 0x5555);
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_4, 0xaaaa);
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_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002830 if (err)
2831 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002832 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002833 if (err)
2834 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002835 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002836 if (err)
2837 return err;
2838
2839 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002840 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002841 if (err)
2842 return err;
2843
Andrew Lunnde2273872016-11-21 23:27:01 +01002844 /* Initialize the statistics unit */
2845 err = mv88e6xxx_stats_set_histogram(chip);
2846 if (err)
2847 return err;
2848
Vivien Didelot97299342016-07-18 20:45:30 -04002849 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002850 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2851 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002852 if (err)
2853 return err;
2854
2855 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002856 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002857 if (err)
2858 return err;
2859
2860 return 0;
2861}
2862
Vivien Didelotf81ec902016-05-09 13:22:58 -04002863static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002864{
Vivien Didelot04bed142016-08-31 18:06:13 -04002865 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002866 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002867 int i;
2868
Vivien Didelotfad09c72016-06-21 12:28:20 -04002869 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002870 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002871
Vivien Didelotfad09c72016-06-21 12:28:20 -04002872 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002873
Vivien Didelot97299342016-07-18 20:45:30 -04002874 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002875 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002876 err = mv88e6xxx_setup_port(chip, i);
2877 if (err)
2878 goto unlock;
2879 }
2880
2881 /* Setup Switch Global 1 Registers */
2882 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002883 if (err)
2884 goto unlock;
2885
Vivien Didelot97299342016-07-18 20:45:30 -04002886 /* Setup Switch Global 2 Registers */
2887 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2888 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002889 if (err)
2890 goto unlock;
2891 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002892
Andrew Lunn6e55f692016-12-03 04:45:16 +01002893 /* Some generations have the configuration of sending reserved
2894 * management frames to the CPU in global2, others in
2895 * global1. Hence it does not fit the two setup functions
2896 * above.
2897 */
2898 if (chip->info->ops->mgmt_rsvd2cpu) {
2899 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2900 if (err)
2901 goto unlock;
2902 }
2903
Vivien Didelot6b17e862015-08-13 12:52:18 -04002904unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002905 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002906
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002907 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002908}
2909
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002910static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2911{
Vivien Didelot04bed142016-08-31 18:06:13 -04002912 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002913 int err;
2914
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002915 if (!chip->info->ops->set_switch_mac)
2916 return -EOPNOTSUPP;
2917
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002918 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002919 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002920 mutex_unlock(&chip->reg_lock);
2921
2922 return err;
2923}
2924
Vivien Didelote57e5e72016-08-15 17:19:00 -04002925static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002926{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002927 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2928 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002929 u16 val;
2930 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002931
Andrew Lunnee26a222017-01-24 14:53:48 +01002932 if (!chip->info->ops->phy_read)
2933 return -EOPNOTSUPP;
2934
Vivien Didelotfad09c72016-06-21 12:28:20 -04002935 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002936 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002937 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002938
Andrew Lunnda9f3302017-02-01 03:40:05 +01002939 if (reg == MII_PHYSID2) {
2940 /* Some internal PHYS don't have a model number. Use
2941 * the mv88e6390 family model number instead.
2942 */
2943 if (!(val & 0x3f0))
2944 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2945 }
2946
Vivien Didelote57e5e72016-08-15 17:19:00 -04002947 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002948}
2949
Vivien Didelote57e5e72016-08-15 17:19:00 -04002950static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002951{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002952 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2953 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002954 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002955
Andrew Lunnee26a222017-01-24 14:53:48 +01002956 if (!chip->info->ops->phy_write)
2957 return -EOPNOTSUPP;
2958
Vivien Didelotfad09c72016-06-21 12:28:20 -04002959 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002960 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002961 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002962
2963 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002964}
2965
Vivien Didelotfad09c72016-06-21 12:28:20 -04002966static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002967 struct device_node *np,
2968 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002969{
2970 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002971 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002972 struct mii_bus *bus;
2973 int err;
2974
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002975 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002976 if (!bus)
2977 return -ENOMEM;
2978
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002979 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002980 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002981 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002982 INIT_LIST_HEAD(&mdio_bus->list);
2983 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002984
Andrew Lunnb516d452016-06-04 21:17:06 +02002985 if (np) {
2986 bus->name = np->full_name;
2987 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2988 } else {
2989 bus->name = "mv88e6xxx SMI";
2990 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2991 }
2992
2993 bus->read = mv88e6xxx_mdio_read;
2994 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002995 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002996
Andrew Lunna3c53be52017-01-24 14:53:50 +01002997 if (np)
2998 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002999 else
3000 err = mdiobus_register(bus);
3001 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04003002 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01003003 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02003004 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01003005
3006 if (external)
3007 list_add_tail(&mdio_bus->list, &chip->mdios);
3008 else
3009 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02003010
3011 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02003012}
3013
Andrew Lunna3c53be52017-01-24 14:53:50 +01003014static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
3015 { .compatible = "marvell,mv88e6xxx-mdio-external",
3016 .data = (void *)true },
3017 { },
3018};
3019
3020static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
3021 struct device_node *np)
3022{
3023 const struct of_device_id *match;
3024 struct device_node *child;
3025 int err;
3026
3027 /* Always register one mdio bus for the internal/default mdio
3028 * bus. This maybe represented in the device tree, but is
3029 * optional.
3030 */
3031 child = of_get_child_by_name(np, "mdio");
3032 err = mv88e6xxx_mdio_register(chip, child, false);
3033 if (err)
3034 return err;
3035
3036 /* Walk the device tree, and see if there are any other nodes
3037 * which say they are compatible with the external mdio
3038 * bus.
3039 */
3040 for_each_available_child_of_node(np, child) {
3041 match = of_match_node(mv88e6xxx_mdio_external_match, child);
3042 if (match) {
3043 err = mv88e6xxx_mdio_register(chip, child, true);
3044 if (err)
3045 return err;
3046 }
3047 }
3048
3049 return 0;
3050}
3051
3052static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02003053
3054{
Andrew Lunna3c53be52017-01-24 14:53:50 +01003055 struct mv88e6xxx_mdio_bus *mdio_bus;
3056 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003057
Andrew Lunna3c53be52017-01-24 14:53:50 +01003058 list_for_each_entry(mdio_bus, &chip->mdios, list) {
3059 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003060
Andrew Lunna3c53be52017-01-24 14:53:50 +01003061 mdiobus_unregister(bus);
3062 }
Andrew Lunnb516d452016-06-04 21:17:06 +02003063}
3064
Vivien Didelot855b1932016-07-20 18:18:35 -04003065static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3066{
Vivien Didelot04bed142016-08-31 18:06:13 -04003067 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003068
3069 return chip->eeprom_len;
3070}
3071
Vivien Didelot855b1932016-07-20 18:18:35 -04003072static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3073 struct ethtool_eeprom *eeprom, u8 *data)
3074{
Vivien Didelot04bed142016-08-31 18:06:13 -04003075 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003076 int err;
3077
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003078 if (!chip->info->ops->get_eeprom)
3079 return -EOPNOTSUPP;
3080
Vivien Didelot855b1932016-07-20 18:18:35 -04003081 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003082 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003083 mutex_unlock(&chip->reg_lock);
3084
3085 if (err)
3086 return err;
3087
3088 eeprom->magic = 0xc3ec4951;
3089
3090 return 0;
3091}
3092
Vivien Didelot855b1932016-07-20 18:18:35 -04003093static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3094 struct ethtool_eeprom *eeprom, u8 *data)
3095{
Vivien Didelot04bed142016-08-31 18:06:13 -04003096 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003097 int err;
3098
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003099 if (!chip->info->ops->set_eeprom)
3100 return -EOPNOTSUPP;
3101
Vivien Didelot855b1932016-07-20 18:18:35 -04003102 if (eeprom->magic != 0xc3ec4951)
3103 return -EINVAL;
3104
3105 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003106 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003107 mutex_unlock(&chip->reg_lock);
3108
3109 return err;
3110}
3111
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003112static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003113 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003114 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003115 .phy_read = mv88e6xxx_phy_ppu_read,
3116 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003117 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003118 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003119 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003120 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003121 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3122 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3123 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003124 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003125 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003126 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003127 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3128 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003129 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003130 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3131 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003132 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003133 .ppu_enable = mv88e6185_g1_ppu_enable,
3134 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003135 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003136};
3137
3138static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003139 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003140 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003141 .phy_read = mv88e6xxx_phy_ppu_read,
3142 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003143 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003144 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003145 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003146 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3147 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003148 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003149 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3150 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003151 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003152 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003153 .ppu_enable = mv88e6185_g1_ppu_enable,
3154 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003155 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003156};
3157
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003158static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003159 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003160 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3161 .phy_read = mv88e6xxx_g2_smi_phy_read,
3162 .phy_write = mv88e6xxx_g2_smi_phy_write,
3163 .port_set_link = mv88e6xxx_port_set_link,
3164 .port_set_duplex = mv88e6xxx_port_set_duplex,
3165 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003166 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003167 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3168 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3169 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003170 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003171 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003172 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003173 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3174 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3175 .stats_get_strings = mv88e6095_stats_get_strings,
3176 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003177 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3178 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003179 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003180 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003181};
3182
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003183static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003184 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003185 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003186 .phy_read = mv88e6165_phy_read,
3187 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003188 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003189 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003190 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003191 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3192 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003193 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003194 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3195 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003196 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003197 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3198 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003199 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003200 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003201};
3202
3203static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003204 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003205 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003206 .phy_read = mv88e6xxx_phy_ppu_read,
3207 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003208 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003209 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003210 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003211 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003212 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3213 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3214 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003215 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003216 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003217 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003218 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003219 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3220 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003221 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003222 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3223 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003224 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003225 .ppu_enable = mv88e6185_g1_ppu_enable,
3226 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003227 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003228};
3229
3230static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003231 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003232 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003233 .phy_read = mv88e6165_phy_read,
3234 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003235 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003236 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003237 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003238 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003239 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3240 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3241 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003242 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003243 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003244 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003245 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003246 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3247 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003248 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003249 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3250 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003251 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003252 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003253};
3254
3255static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003256 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003257 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003258 .phy_read = mv88e6165_phy_read,
3259 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003260 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003261 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003262 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003263 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003264 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3265 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003266 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003267 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3268 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003269 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003270 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003271};
3272
3273static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003274 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003275 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003276 .phy_read = mv88e6xxx_g2_smi_phy_read,
3277 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003278 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003279 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003280 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003281 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003282 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003283 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3284 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3285 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003286 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003287 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003288 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003289 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003290 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3291 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003292 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003293 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3294 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003295 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003296 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003297};
3298
3299static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003300 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003301 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3302 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003303 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003304 .phy_read = mv88e6xxx_g2_smi_phy_read,
3305 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003306 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003307 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003308 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003309 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003310 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003311 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3312 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3313 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003314 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003315 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003316 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003317 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003318 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3319 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003320 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003321 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3322 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003323 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003324 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003325};
3326
3327static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003328 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003329 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003330 .phy_read = mv88e6xxx_g2_smi_phy_read,
3331 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003332 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003333 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003334 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003335 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003336 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003337 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3338 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3339 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003340 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003341 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003342 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003343 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003344 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3345 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003346 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003347 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3348 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003349 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003350 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003351};
3352
3353static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003354 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003355 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3356 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003357 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003358 .phy_read = mv88e6xxx_g2_smi_phy_read,
3359 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003360 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003361 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003362 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003363 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003364 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003365 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3366 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3367 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003368 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003369 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003370 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003371 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003372 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3373 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003374 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003375 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3376 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003377 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003378 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003379};
3380
3381static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003382 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003383 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003384 .phy_read = mv88e6xxx_phy_ppu_read,
3385 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003386 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003387 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003388 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003389 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3390 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003391 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003392 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003393 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3394 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003395 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003396 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3397 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003398 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003399 .ppu_enable = mv88e6185_g1_ppu_enable,
3400 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003401 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003402};
3403
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003404static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003405 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003406 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3407 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003408 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3409 .phy_read = mv88e6xxx_g2_smi_phy_read,
3410 .phy_write = mv88e6xxx_g2_smi_phy_write,
3411 .port_set_link = mv88e6xxx_port_set_link,
3412 .port_set_duplex = mv88e6xxx_port_set_duplex,
3413 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3414 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003415 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003416 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3417 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3418 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003419 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003420 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003421 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003422 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3423 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003424 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003425 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3426 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003427 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003428 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003429};
3430
3431static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003432 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003433 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3434 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003435 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3436 .phy_read = mv88e6xxx_g2_smi_phy_read,
3437 .phy_write = mv88e6xxx_g2_smi_phy_write,
3438 .port_set_link = mv88e6xxx_port_set_link,
3439 .port_set_duplex = mv88e6xxx_port_set_duplex,
3440 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3441 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003442 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003443 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3444 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3445 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003446 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003447 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003448 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003449 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3450 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003451 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003452 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3453 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003454 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003455 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003456};
3457
3458static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003459 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003460 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3461 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003462 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3463 .phy_read = mv88e6xxx_g2_smi_phy_read,
3464 .phy_write = mv88e6xxx_g2_smi_phy_write,
3465 .port_set_link = mv88e6xxx_port_set_link,
3466 .port_set_duplex = mv88e6xxx_port_set_duplex,
3467 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3468 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003469 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003470 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3471 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3472 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003473 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003474 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003475 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003476 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3477 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003478 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003479 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3480 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003481 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003482 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003483};
3484
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003485static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003486 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003487 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3488 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003489 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003490 .phy_read = mv88e6xxx_g2_smi_phy_read,
3491 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003492 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003493 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003494 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003495 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003496 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003497 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3498 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3499 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003500 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003501 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003502 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003503 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003504 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3505 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003506 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003507 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3508 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003509 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003510 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003511};
3512
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003513static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003514 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003515 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3516 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003517 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3518 .phy_read = mv88e6xxx_g2_smi_phy_read,
3519 .phy_write = mv88e6xxx_g2_smi_phy_write,
3520 .port_set_link = mv88e6xxx_port_set_link,
3521 .port_set_duplex = mv88e6xxx_port_set_duplex,
3522 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3523 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003524 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003525 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3526 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3527 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003528 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003529 .port_set_cmode = mv88e6390x_port_set_cmode,
Andrew Lunn79523472016-11-21 23:27:00 +01003530 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003531 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003532 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3533 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003534 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003535 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3536 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003537 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003538 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003539};
3540
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003541static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003542 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003543 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3544 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003545 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003546 .phy_read = mv88e6xxx_g2_smi_phy_read,
3547 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003548 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003549 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003550 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003551 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003552 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3553 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3554 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003555 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003556 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003557 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003558 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003559 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3560 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003561 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003562 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3563 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003564 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003565 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003566};
3567
3568static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003569 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003570 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3571 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003572 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003573 .phy_read = mv88e6xxx_g2_smi_phy_read,
3574 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003575 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003576 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003577 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003578 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003579 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3580 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3581 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003582 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003583 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003584 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003585 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003586 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3587 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003588 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003589 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3590 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003591 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003592};
3593
3594static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003595 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003596 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003597 .phy_read = mv88e6xxx_g2_smi_phy_read,
3598 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003599 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003600 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003601 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003602 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003603 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003604 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3605 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3606 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003607 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003608 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003609 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003610 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003611 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3612 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003613 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003614 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3615 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003616 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003617 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003618};
3619
3620static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003621 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003622 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003623 .phy_read = mv88e6xxx_g2_smi_phy_read,
3624 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003625 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003626 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003627 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003628 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003629 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003630 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3631 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3632 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003633 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003634 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003635 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003636 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003637 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3638 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003639 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003640 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3641 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003642 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003643 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003644};
3645
3646static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003647 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003648 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3649 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003650 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003651 .phy_read = mv88e6xxx_g2_smi_phy_read,
3652 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003653 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003654 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003655 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003656 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003657 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003658 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3659 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3660 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003661 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003662 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003663 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003664 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003665 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3666 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003667 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003668 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3669 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003670 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003671 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003672};
3673
Gregory CLEMENT15587272017-01-30 20:29:35 +01003674static const struct mv88e6xxx_ops mv88e6141_ops = {
3675 /* MV88E6XXX_FAMILY_6341 */
3676 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3677 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3678 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3679 .phy_read = mv88e6xxx_g2_smi_phy_read,
3680 .phy_write = mv88e6xxx_g2_smi_phy_write,
3681 .port_set_link = mv88e6xxx_port_set_link,
3682 .port_set_duplex = mv88e6xxx_port_set_duplex,
3683 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3684 .port_set_speed = mv88e6390_port_set_speed,
3685 .port_tag_remap = mv88e6095_port_tag_remap,
3686 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3687 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3688 .port_set_ether_type = mv88e6351_port_set_ether_type,
3689 .port_jumbo_config = mv88e6165_port_jumbo_config,
3690 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3691 .port_pause_config = mv88e6097_port_pause_config,
3692 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3693 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3694 .stats_get_strings = mv88e6320_stats_get_strings,
3695 .stats_get_stats = mv88e6390_stats_get_stats,
3696 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3697 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3698 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3699 .reset = mv88e6352_g1_reset,
3700};
3701
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003702static const struct mv88e6xxx_ops mv88e6341_ops = {
3703 /* MV88E6XXX_FAMILY_6341 */
3704 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3705 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3706 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3707 .phy_read = mv88e6xxx_g2_smi_phy_read,
3708 .phy_write = mv88e6xxx_g2_smi_phy_write,
3709 .port_set_link = mv88e6xxx_port_set_link,
3710 .port_set_duplex = mv88e6xxx_port_set_duplex,
3711 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3712 .port_set_speed = mv88e6390_port_set_speed,
3713 .port_tag_remap = mv88e6095_port_tag_remap,
3714 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3715 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3716 .port_set_ether_type = mv88e6351_port_set_ether_type,
3717 .port_jumbo_config = mv88e6165_port_jumbo_config,
3718 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3719 .port_pause_config = mv88e6097_port_pause_config,
3720 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3721 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3722 .stats_get_strings = mv88e6320_stats_get_strings,
3723 .stats_get_stats = mv88e6390_stats_get_stats,
3724 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3725 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3726 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3727 .reset = mv88e6352_g1_reset,
3728};
3729
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003730static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003731 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003732 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3733 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003734 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3735 .phy_read = mv88e6xxx_g2_smi_phy_read,
3736 .phy_write = mv88e6xxx_g2_smi_phy_write,
3737 .port_set_link = mv88e6xxx_port_set_link,
3738 .port_set_duplex = mv88e6xxx_port_set_duplex,
3739 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3740 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003741 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003742 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3743 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3744 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003745 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003746 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003747 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003748 .port_set_cmode = mv88e6390x_port_set_cmode,
Andrew Lunn79523472016-11-21 23:27:00 +01003749 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003750 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003751 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3752 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003753 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003754 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3755 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003756 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003757 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003758};
3759
3760static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003761 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003762 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3763 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003764 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3765 .phy_read = mv88e6xxx_g2_smi_phy_read,
3766 .phy_write = mv88e6xxx_g2_smi_phy_write,
3767 .port_set_link = mv88e6xxx_port_set_link,
3768 .port_set_duplex = mv88e6xxx_port_set_duplex,
3769 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3770 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003771 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003772 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3773 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3774 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003775 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003776 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003777 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003778 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003779 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003780 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3781 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003782 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003783 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3784 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003785 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003786 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003787};
3788
3789static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003790 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003791 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3792 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003793 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3794 .phy_read = mv88e6xxx_g2_smi_phy_read,
3795 .phy_write = mv88e6xxx_g2_smi_phy_write,
3796 .port_set_link = mv88e6xxx_port_set_link,
3797 .port_set_duplex = mv88e6xxx_port_set_duplex,
3798 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3799 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003800 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003801 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3802 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3803 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003804 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003805 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003806 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003807 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3808 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003809 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003810 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3811 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003812 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003813 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003814};
3815
Andrew Lunn56995cb2016-12-03 04:35:19 +01003816static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3817 const struct mv88e6xxx_ops *ops)
3818{
3819 if (!ops->port_set_frame_mode) {
3820 dev_err(chip->dev, "Missing port_set_frame_mode");
3821 return -EINVAL;
3822 }
3823
3824 if (!ops->port_set_egress_unknowns) {
3825 dev_err(chip->dev, "Missing port_set_egress_mode");
3826 return -EINVAL;
3827 }
3828
3829 return 0;
3830}
3831
Vivien Didelotf81ec902016-05-09 13:22:58 -04003832static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3833 [MV88E6085] = {
3834 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3835 .family = MV88E6XXX_FAMILY_6097,
3836 .name = "Marvell 88E6085",
3837 .num_databases = 4096,
3838 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003839 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003840 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003841 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003842 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003843 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003844 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003845 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003846 },
3847
3848 [MV88E6095] = {
3849 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3850 .family = MV88E6XXX_FAMILY_6095,
3851 .name = "Marvell 88E6095/88E6095F",
3852 .num_databases = 256,
3853 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003854 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003855 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003856 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003857 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003858 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003859 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003860 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003861 },
3862
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003863 [MV88E6097] = {
3864 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3865 .family = MV88E6XXX_FAMILY_6097,
3866 .name = "Marvell 88E6097/88E6097F",
3867 .num_databases = 4096,
3868 .num_ports = 11,
3869 .port_base_addr = 0x10,
3870 .global1_addr = 0x1b,
3871 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003872 .g1_irqs = 8,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003873 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003874 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3875 .ops = &mv88e6097_ops,
3876 },
3877
Vivien Didelotf81ec902016-05-09 13:22:58 -04003878 [MV88E6123] = {
3879 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3880 .family = MV88E6XXX_FAMILY_6165,
3881 .name = "Marvell 88E6123",
3882 .num_databases = 4096,
3883 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003884 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003885 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003886 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003887 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003888 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003889 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003890 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003891 },
3892
3893 [MV88E6131] = {
3894 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3895 .family = MV88E6XXX_FAMILY_6185,
3896 .name = "Marvell 88E6131",
3897 .num_databases = 256,
3898 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003899 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003900 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003901 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003902 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003903 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003904 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003905 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003906 },
3907
3908 [MV88E6161] = {
3909 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3910 .family = MV88E6XXX_FAMILY_6165,
3911 .name = "Marvell 88E6161",
3912 .num_databases = 4096,
3913 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003914 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003915 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003916 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003917 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003918 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003919 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003920 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003921 },
3922
3923 [MV88E6165] = {
3924 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3925 .family = MV88E6XXX_FAMILY_6165,
3926 .name = "Marvell 88E6165",
3927 .num_databases = 4096,
3928 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003929 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003930 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003931 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003932 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003933 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003934 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003935 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003936 },
3937
3938 [MV88E6171] = {
3939 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3940 .family = MV88E6XXX_FAMILY_6351,
3941 .name = "Marvell 88E6171",
3942 .num_databases = 4096,
3943 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003944 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003945 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003946 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003947 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003948 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003949 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003950 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003951 },
3952
3953 [MV88E6172] = {
3954 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3955 .family = MV88E6XXX_FAMILY_6352,
3956 .name = "Marvell 88E6172",
3957 .num_databases = 4096,
3958 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003959 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003960 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003961 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003962 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003963 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003964 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003965 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003966 },
3967
3968 [MV88E6175] = {
3969 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3970 .family = MV88E6XXX_FAMILY_6351,
3971 .name = "Marvell 88E6175",
3972 .num_databases = 4096,
3973 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003974 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003975 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003976 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003977 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003978 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003979 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003980 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003981 },
3982
3983 [MV88E6176] = {
3984 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3985 .family = MV88E6XXX_FAMILY_6352,
3986 .name = "Marvell 88E6176",
3987 .num_databases = 4096,
3988 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003989 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003990 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003991 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003992 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003993 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003994 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003995 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003996 },
3997
3998 [MV88E6185] = {
3999 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
4000 .family = MV88E6XXX_FAMILY_6185,
4001 .name = "Marvell 88E6185",
4002 .num_databases = 256,
4003 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004004 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004005 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004006 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004007 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004008 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004009 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004010 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004011 },
4012
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004013 [MV88E6190] = {
4014 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
4015 .family = MV88E6XXX_FAMILY_6390,
4016 .name = "Marvell 88E6190",
4017 .num_databases = 4096,
4018 .num_ports = 11, /* 10 + Z80 */
4019 .port_base_addr = 0x0,
4020 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004021 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004022 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004023 .g1_irqs = 9,
4024 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4025 .ops = &mv88e6190_ops,
4026 },
4027
4028 [MV88E6190X] = {
4029 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
4030 .family = MV88E6XXX_FAMILY_6390,
4031 .name = "Marvell 88E6190X",
4032 .num_databases = 4096,
4033 .num_ports = 11, /* 10 + Z80 */
4034 .port_base_addr = 0x0,
4035 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004036 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004037 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004038 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004039 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4040 .ops = &mv88e6190x_ops,
4041 },
4042
4043 [MV88E6191] = {
4044 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
4045 .family = MV88E6XXX_FAMILY_6390,
4046 .name = "Marvell 88E6191",
4047 .num_databases = 4096,
4048 .num_ports = 11, /* 10 + Z80 */
4049 .port_base_addr = 0x0,
4050 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004051 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004052 .g1_irqs = 9,
4053 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004054 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4055 .ops = &mv88e6391_ops,
4056 },
4057
Vivien Didelotf81ec902016-05-09 13:22:58 -04004058 [MV88E6240] = {
4059 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
4060 .family = MV88E6XXX_FAMILY_6352,
4061 .name = "Marvell 88E6240",
4062 .num_databases = 4096,
4063 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004064 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004065 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004066 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004067 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004068 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004069 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004070 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004071 },
4072
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004073 [MV88E6290] = {
4074 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
4075 .family = MV88E6XXX_FAMILY_6390,
4076 .name = "Marvell 88E6290",
4077 .num_databases = 4096,
4078 .num_ports = 11, /* 10 + Z80 */
4079 .port_base_addr = 0x0,
4080 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004081 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004082 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004083 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004084 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4085 .ops = &mv88e6290_ops,
4086 },
4087
Vivien Didelotf81ec902016-05-09 13:22:58 -04004088 [MV88E6320] = {
4089 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
4090 .family = MV88E6XXX_FAMILY_6320,
4091 .name = "Marvell 88E6320",
4092 .num_databases = 4096,
4093 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004094 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004095 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004096 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004097 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004098 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004099 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004100 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004101 },
4102
4103 [MV88E6321] = {
4104 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
4105 .family = MV88E6XXX_FAMILY_6320,
4106 .name = "Marvell 88E6321",
4107 .num_databases = 4096,
4108 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004109 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004110 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004111 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004112 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004113 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004114 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004115 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004116 },
4117
Gregory CLEMENT15587272017-01-30 20:29:35 +01004118 [MV88E6141] = {
4119 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
4120 .family = MV88E6XXX_FAMILY_6341,
4121 .name = "Marvell 88E6341",
4122 .num_databases = 4096,
4123 .num_ports = 6,
4124 .port_base_addr = 0x10,
4125 .global1_addr = 0x1b,
4126 .age_time_coeff = 3750,
4127 .tag_protocol = DSA_TAG_PROTO_EDSA,
4128 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
4129 .ops = &mv88e6141_ops,
4130 },
4131
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01004132 [MV88E6341] = {
4133 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
4134 .family = MV88E6XXX_FAMILY_6341,
4135 .name = "Marvell 88E6341",
4136 .num_databases = 4096,
4137 .num_ports = 6,
4138 .port_base_addr = 0x10,
4139 .global1_addr = 0x1b,
4140 .age_time_coeff = 3750,
4141 .tag_protocol = DSA_TAG_PROTO_EDSA,
4142 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
4143 .ops = &mv88e6341_ops,
4144 },
4145
Vivien Didelotf81ec902016-05-09 13:22:58 -04004146 [MV88E6350] = {
4147 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
4148 .family = MV88E6XXX_FAMILY_6351,
4149 .name = "Marvell 88E6350",
4150 .num_databases = 4096,
4151 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004152 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004153 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004154 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004155 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004156 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004157 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004158 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004159 },
4160
4161 [MV88E6351] = {
4162 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4163 .family = MV88E6XXX_FAMILY_6351,
4164 .name = "Marvell 88E6351",
4165 .num_databases = 4096,
4166 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004167 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004168 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004169 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004170 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004171 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004172 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004173 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004174 },
4175
4176 [MV88E6352] = {
4177 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4178 .family = MV88E6XXX_FAMILY_6352,
4179 .name = "Marvell 88E6352",
4180 .num_databases = 4096,
4181 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004182 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004183 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004184 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004185 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004186 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004187 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004188 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004189 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004190 [MV88E6390] = {
4191 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4192 .family = MV88E6XXX_FAMILY_6390,
4193 .name = "Marvell 88E6390",
4194 .num_databases = 4096,
4195 .num_ports = 11, /* 10 + Z80 */
4196 .port_base_addr = 0x0,
4197 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004198 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004199 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004200 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004201 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4202 .ops = &mv88e6390_ops,
4203 },
4204 [MV88E6390X] = {
4205 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4206 .family = MV88E6XXX_FAMILY_6390,
4207 .name = "Marvell 88E6390X",
4208 .num_databases = 4096,
4209 .num_ports = 11, /* 10 + Z80 */
4210 .port_base_addr = 0x0,
4211 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004212 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004213 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004214 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004215 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4216 .ops = &mv88e6390x_ops,
4217 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004218};
4219
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004220static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004221{
Vivien Didelota439c062016-04-17 13:23:58 -04004222 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004223
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004224 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4225 if (mv88e6xxx_table[i].prod_num == prod_num)
4226 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004227
Vivien Didelotb9b37712015-10-30 19:39:48 -04004228 return NULL;
4229}
4230
Vivien Didelotfad09c72016-06-21 12:28:20 -04004231static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004232{
4233 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004234 unsigned int prod_num, rev;
4235 u16 id;
4236 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004237
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004238 mutex_lock(&chip->reg_lock);
4239 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4240 mutex_unlock(&chip->reg_lock);
4241 if (err)
4242 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004243
4244 prod_num = (id & 0xfff0) >> 4;
4245 rev = id & 0x000f;
4246
4247 info = mv88e6xxx_lookup_info(prod_num);
4248 if (!info)
4249 return -ENODEV;
4250
Vivien Didelotcaac8542016-06-20 13:14:09 -04004251 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004252 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004253
Vivien Didelotca070c12016-09-02 14:45:34 -04004254 err = mv88e6xxx_g2_require(chip);
4255 if (err)
4256 return err;
4257
Vivien Didelotfad09c72016-06-21 12:28:20 -04004258 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4259 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004260
4261 return 0;
4262}
4263
Vivien Didelotfad09c72016-06-21 12:28:20 -04004264static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004265{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004266 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004267
Vivien Didelotfad09c72016-06-21 12:28:20 -04004268 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4269 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004270 return NULL;
4271
Vivien Didelotfad09c72016-06-21 12:28:20 -04004272 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004273
Vivien Didelotfad09c72016-06-21 12:28:20 -04004274 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004275 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004276
Vivien Didelotfad09c72016-06-21 12:28:20 -04004277 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004278}
4279
Vivien Didelote57e5e72016-08-15 17:19:00 -04004280static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4281{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004282 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004283 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004284}
4285
Andrew Lunn930188c2016-08-22 16:01:03 +02004286static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4287{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004288 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004289 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004290}
4291
Vivien Didelotfad09c72016-06-21 12:28:20 -04004292static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004293 struct mii_bus *bus, int sw_addr)
4294{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004295 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004296 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004297 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004298 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004299 else
4300 return -EINVAL;
4301
Vivien Didelotfad09c72016-06-21 12:28:20 -04004302 chip->bus = bus;
4303 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004304
4305 return 0;
4306}
4307
Andrew Lunn7b314362016-08-22 16:01:01 +02004308static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4309{
Vivien Didelot04bed142016-08-31 18:06:13 -04004310 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004311
Andrew Lunn443d5a12016-12-03 04:35:18 +01004312 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004313}
4314
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004315static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4316 struct device *host_dev, int sw_addr,
4317 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004318{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004319 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004320 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004321 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004322
Vivien Didelota439c062016-04-17 13:23:58 -04004323 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004324 if (!bus)
4325 return NULL;
4326
Vivien Didelotfad09c72016-06-21 12:28:20 -04004327 chip = mv88e6xxx_alloc_chip(dsa_dev);
4328 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004329 return NULL;
4330
Vivien Didelotcaac8542016-06-20 13:14:09 -04004331 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004332 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004333
Vivien Didelotfad09c72016-06-21 12:28:20 -04004334 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004335 if (err)
4336 goto free;
4337
Vivien Didelotfad09c72016-06-21 12:28:20 -04004338 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004339 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004340 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004341
Andrew Lunndc30c352016-10-16 19:56:49 +02004342 mutex_lock(&chip->reg_lock);
4343 err = mv88e6xxx_switch_reset(chip);
4344 mutex_unlock(&chip->reg_lock);
4345 if (err)
4346 goto free;
4347
Vivien Didelote57e5e72016-08-15 17:19:00 -04004348 mv88e6xxx_phy_init(chip);
4349
Andrew Lunna3c53be52017-01-24 14:53:50 +01004350 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004351 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004352 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004353
Vivien Didelotfad09c72016-06-21 12:28:20 -04004354 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004355
Vivien Didelotfad09c72016-06-21 12:28:20 -04004356 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004357free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004358 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004359
4360 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004361}
4362
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004363static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4364 const struct switchdev_obj_port_mdb *mdb,
4365 struct switchdev_trans *trans)
4366{
4367 /* We don't need any dynamic resource from the kernel (yet),
4368 * so skip the prepare phase.
4369 */
4370
4371 return 0;
4372}
4373
4374static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4375 const struct switchdev_obj_port_mdb *mdb,
4376 struct switchdev_trans *trans)
4377{
Vivien Didelot04bed142016-08-31 18:06:13 -04004378 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004379
4380 mutex_lock(&chip->reg_lock);
4381 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4382 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4383 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4384 mutex_unlock(&chip->reg_lock);
4385}
4386
4387static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4388 const struct switchdev_obj_port_mdb *mdb)
4389{
Vivien Didelot04bed142016-08-31 18:06:13 -04004390 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004391 int err;
4392
4393 mutex_lock(&chip->reg_lock);
4394 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4395 GLOBAL_ATU_DATA_STATE_UNUSED);
4396 mutex_unlock(&chip->reg_lock);
4397
4398 return err;
4399}
4400
4401static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4402 struct switchdev_obj_port_mdb *mdb,
4403 int (*cb)(struct switchdev_obj *obj))
4404{
Vivien Didelot04bed142016-08-31 18:06:13 -04004405 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004406 int err;
4407
4408 mutex_lock(&chip->reg_lock);
4409 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4410 mutex_unlock(&chip->reg_lock);
4411
4412 return err;
4413}
4414
Florian Fainellia82f67a2017-01-08 14:52:08 -08004415static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004416 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004417 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004418 .setup = mv88e6xxx_setup,
4419 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004420 .adjust_link = mv88e6xxx_adjust_link,
4421 .get_strings = mv88e6xxx_get_strings,
4422 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4423 .get_sset_count = mv88e6xxx_get_sset_count,
4424 .set_eee = mv88e6xxx_set_eee,
4425 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004426 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004427 .get_eeprom = mv88e6xxx_get_eeprom,
4428 .set_eeprom = mv88e6xxx_set_eeprom,
4429 .get_regs_len = mv88e6xxx_get_regs_len,
4430 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004431 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004432 .port_bridge_join = mv88e6xxx_port_bridge_join,
4433 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4434 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004435 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004436 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4437 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4438 .port_vlan_add = mv88e6xxx_port_vlan_add,
4439 .port_vlan_del = mv88e6xxx_port_vlan_del,
4440 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4441 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4442 .port_fdb_add = mv88e6xxx_port_fdb_add,
4443 .port_fdb_del = mv88e6xxx_port_fdb_del,
4444 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004445 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4446 .port_mdb_add = mv88e6xxx_port_mdb_add,
4447 .port_mdb_del = mv88e6xxx_port_mdb_del,
4448 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004449};
4450
Florian Fainelliab3d4082017-01-08 14:52:07 -08004451static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4452 .ops = &mv88e6xxx_switch_ops,
4453};
4454
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004455static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004456{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004457 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004458 struct dsa_switch *ds;
4459
Vivien Didelota0c02162017-01-27 15:29:36 -05004460 ds = dsa_switch_alloc(dev, DSA_MAX_PORTS);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004461 if (!ds)
4462 return -ENOMEM;
4463
Vivien Didelotfad09c72016-06-21 12:28:20 -04004464 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004465 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004466
4467 dev_set_drvdata(dev, ds);
4468
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004469 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004470}
4471
Vivien Didelotfad09c72016-06-21 12:28:20 -04004472static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004473{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004474 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004475}
4476
Vivien Didelot57d32312016-06-20 13:13:58 -04004477static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004478{
4479 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004480 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004481 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004482 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004483 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004484 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004485
Vivien Didelotcaac8542016-06-20 13:14:09 -04004486 compat_info = of_device_get_match_data(dev);
4487 if (!compat_info)
4488 return -EINVAL;
4489
Vivien Didelotfad09c72016-06-21 12:28:20 -04004490 chip = mv88e6xxx_alloc_chip(dev);
4491 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004492 return -ENOMEM;
4493
Vivien Didelotfad09c72016-06-21 12:28:20 -04004494 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004495
Andrew Lunn56995cb2016-12-03 04:35:19 +01004496 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4497 if (err)
4498 return err;
4499
Vivien Didelotfad09c72016-06-21 12:28:20 -04004500 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004501 if (err)
4502 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004503
Andrew Lunnb4308f02016-11-21 23:26:55 +01004504 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4505 if (IS_ERR(chip->reset))
4506 return PTR_ERR(chip->reset);
4507
Vivien Didelotfad09c72016-06-21 12:28:20 -04004508 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004509 if (err)
4510 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004511
Vivien Didelote57e5e72016-08-15 17:19:00 -04004512 mv88e6xxx_phy_init(chip);
4513
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004514 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004515 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004516 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004517
Andrew Lunndc30c352016-10-16 19:56:49 +02004518 mutex_lock(&chip->reg_lock);
4519 err = mv88e6xxx_switch_reset(chip);
4520 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004521 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004522 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004523
Andrew Lunndc30c352016-10-16 19:56:49 +02004524 chip->irq = of_irq_get(np, 0);
4525 if (chip->irq == -EPROBE_DEFER) {
4526 err = chip->irq;
4527 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004528 }
4529
Andrew Lunndc30c352016-10-16 19:56:49 +02004530 if (chip->irq > 0) {
4531 /* Has to be performed before the MDIO bus is created,
4532 * because the PHYs will link there interrupts to these
4533 * interrupt controllers
4534 */
4535 mutex_lock(&chip->reg_lock);
4536 err = mv88e6xxx_g1_irq_setup(chip);
4537 mutex_unlock(&chip->reg_lock);
4538
4539 if (err)
4540 goto out;
4541
4542 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4543 err = mv88e6xxx_g2_irq_setup(chip);
4544 if (err)
4545 goto out_g1_irq;
4546 }
4547 }
4548
Andrew Lunna3c53be52017-01-24 14:53:50 +01004549 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004550 if (err)
4551 goto out_g2_irq;
4552
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004553 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004554 if (err)
4555 goto out_mdio;
4556
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004557 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004558
4559out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004560 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004561out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004562 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004563 mv88e6xxx_g2_irq_free(chip);
4564out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004565 if (chip->irq > 0) {
4566 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004567 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004568 mutex_unlock(&chip->reg_lock);
4569 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004570out:
4571 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004572}
4573
4574static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4575{
4576 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004577 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004578
Andrew Lunn930188c2016-08-22 16:01:03 +02004579 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004580 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004581 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004582
Andrew Lunn467126442016-11-20 20:14:15 +01004583 if (chip->irq > 0) {
4584 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4585 mv88e6xxx_g2_irq_free(chip);
4586 mv88e6xxx_g1_irq_free(chip);
4587 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004588}
4589
4590static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004591 {
4592 .compatible = "marvell,mv88e6085",
4593 .data = &mv88e6xxx_table[MV88E6085],
4594 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004595 {
4596 .compatible = "marvell,mv88e6190",
4597 .data = &mv88e6xxx_table[MV88E6190],
4598 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004599 { /* sentinel */ },
4600};
4601
4602MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4603
4604static struct mdio_driver mv88e6xxx_driver = {
4605 .probe = mv88e6xxx_probe,
4606 .remove = mv88e6xxx_remove,
4607 .mdiodrv.driver = {
4608 .name = "mv88e6085",
4609 .of_match_table = mv88e6xxx_of_match,
4610 },
4611};
4612
Ben Hutchings98e67302011-11-25 14:36:19 +00004613static int __init mv88e6xxx_init(void)
4614{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004615 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004616 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004617}
4618module_init(mv88e6xxx_init);
4619
4620static void __exit mv88e6xxx_cleanup(void)
4621{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004622 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004623 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004624}
4625module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004626
4627MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4628MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4629MODULE_LICENSE("GPL");