blob: b0fd1432f4f3a644fa9c0341daba4e92f7f03485 [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
Vivien Didelote57e5e72016-08-15 17:19:00 -0400239static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
240 int reg, u16 *val)
241{
242 int addr = phy; /* PHY devices addresses start at 0x0 */
Andrew Lunnee26a222017-01-24 14:53:48 +0100243 struct mii_bus *bus = chip->mdio_bus;
Vivien Didelote57e5e72016-08-15 17:19:00 -0400244
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400245 if (!chip->info->ops->phy_read)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400246 return -EOPNOTSUPP;
247
Andrew Lunnee26a222017-01-24 14:53:48 +0100248 if (!bus)
249 return -EOPNOTSUPP;
250
251 return chip->info->ops->phy_read(chip, bus, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400252}
253
254static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
255 int reg, u16 val)
256{
257 int addr = phy; /* PHY devices addresses start at 0x0 */
Andrew Lunnee26a222017-01-24 14:53:48 +0100258 struct mii_bus *bus = chip->mdio_bus;
Vivien Didelote57e5e72016-08-15 17:19:00 -0400259
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400260 if (!chip->info->ops->phy_write)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400261 return -EOPNOTSUPP;
262
Andrew Lunnee26a222017-01-24 14:53:48 +0100263 if (!bus)
264 return -EOPNOTSUPP;
265
266 return chip->info->ops->phy_write(chip, bus, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400267}
268
Vivien Didelot09cb7df2016-08-15 17:19:01 -0400269static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
270{
271 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_PHY_PAGE))
272 return -EOPNOTSUPP;
273
274 return mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
275}
276
277static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip *chip, int phy)
278{
279 int err;
280
281 /* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
282 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, PHY_PAGE_COPPER);
283 if (unlikely(err)) {
284 dev_err(chip->dev, "failed to restore PHY %d page Copper (%d)\n",
285 phy, err);
286 }
287}
288
289static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy,
290 u8 page, int reg, u16 *val)
291{
292 int err;
293
294 /* There is no paging for registers 22 */
295 if (reg == PHY_PAGE)
296 return -EINVAL;
297
298 err = mv88e6xxx_phy_page_get(chip, phy, page);
299 if (!err) {
300 err = mv88e6xxx_phy_read(chip, phy, reg, val);
301 mv88e6xxx_phy_page_put(chip, phy);
302 }
303
304 return err;
305}
306
307static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy,
308 u8 page, int reg, u16 val)
309{
310 int err;
311
312 /* There is no paging for registers 22 */
313 if (reg == PHY_PAGE)
314 return -EINVAL;
315
316 err = mv88e6xxx_phy_page_get(chip, phy, page);
317 if (!err) {
318 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
319 mv88e6xxx_phy_page_put(chip, phy);
320 }
321
322 return err;
323}
324
325static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
326{
327 return mv88e6xxx_phy_page_read(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
328 reg, val);
329}
330
331static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
332{
333 return mv88e6xxx_phy_page_write(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
334 reg, val);
335}
336
Andrew Lunndc30c352016-10-16 19:56:49 +0200337static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
338{
339 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
340 unsigned int n = d->hwirq;
341
342 chip->g1_irq.masked |= (1 << n);
343}
344
345static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
346{
347 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
348 unsigned int n = d->hwirq;
349
350 chip->g1_irq.masked &= ~(1 << n);
351}
352
353static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
354{
355 struct mv88e6xxx_chip *chip = dev_id;
356 unsigned int nhandled = 0;
357 unsigned int sub_irq;
358 unsigned int n;
359 u16 reg;
360 int err;
361
362 mutex_lock(&chip->reg_lock);
363 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
364 mutex_unlock(&chip->reg_lock);
365
366 if (err)
367 goto out;
368
369 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
370 if (reg & (1 << n)) {
371 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
372 handle_nested_irq(sub_irq);
373 ++nhandled;
374 }
375 }
376out:
377 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
378}
379
380static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
381{
382 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
383
384 mutex_lock(&chip->reg_lock);
385}
386
387static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
388{
389 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
390 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
391 u16 reg;
392 int err;
393
394 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
395 if (err)
396 goto out;
397
398 reg &= ~mask;
399 reg |= (~chip->g1_irq.masked & mask);
400
401 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
402 if (err)
403 goto out;
404
405out:
406 mutex_unlock(&chip->reg_lock);
407}
408
409static struct irq_chip mv88e6xxx_g1_irq_chip = {
410 .name = "mv88e6xxx-g1",
411 .irq_mask = mv88e6xxx_g1_irq_mask,
412 .irq_unmask = mv88e6xxx_g1_irq_unmask,
413 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
414 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
415};
416
417static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
418 unsigned int irq,
419 irq_hw_number_t hwirq)
420{
421 struct mv88e6xxx_chip *chip = d->host_data;
422
423 irq_set_chip_data(irq, d->host_data);
424 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
425 irq_set_noprobe(irq);
426
427 return 0;
428}
429
430static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
431 .map = mv88e6xxx_g1_irq_domain_map,
432 .xlate = irq_domain_xlate_twocell,
433};
434
435static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
436{
437 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100438 u16 mask;
439
440 mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
441 mask |= GENMASK(chip->g1_irq.nirqs, 0);
442 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
443
444 free_irq(chip->irq, chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200445
Andreas Färber5edef2f2016-11-27 23:26:28 +0100446 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100447 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200448 irq_dispose_mapping(virq);
449 }
450
Andrew Lunna3db3d32016-11-20 20:14:14 +0100451 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200452}
453
454static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
455{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100456 int err, irq, virq;
457 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200458
459 chip->g1_irq.nirqs = chip->info->g1_irqs;
460 chip->g1_irq.domain = irq_domain_add_simple(
461 NULL, chip->g1_irq.nirqs, 0,
462 &mv88e6xxx_g1_irq_domain_ops, chip);
463 if (!chip->g1_irq.domain)
464 return -ENOMEM;
465
466 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
467 irq_create_mapping(chip->g1_irq.domain, irq);
468
469 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
470 chip->g1_irq.masked = ~0;
471
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100472 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200473 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100474 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200475
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100476 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200477
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100478 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200479 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100480 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200481
482 /* Reading the interrupt status clears (most of) them */
483 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
484 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100485 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200486
487 err = request_threaded_irq(chip->irq, NULL,
488 mv88e6xxx_g1_irq_thread_fn,
489 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
490 dev_name(chip->dev), chip);
491 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100492 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200493
494 return 0;
495
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100496out_disable:
497 mask |= GENMASK(chip->g1_irq.nirqs, 0);
498 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
499
500out_mapping:
501 for (irq = 0; irq < 16; irq++) {
502 virq = irq_find_mapping(chip->g1_irq.domain, irq);
503 irq_dispose_mapping(virq);
504 }
505
506 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200507
508 return err;
509}
510
Vivien Didelotec561272016-09-02 14:45:33 -0400511int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400512{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200513 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400514
Andrew Lunn6441e6692016-08-19 00:01:55 +0200515 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400516 u16 val;
517 int err;
518
519 err = mv88e6xxx_read(chip, addr, reg, &val);
520 if (err)
521 return err;
522
523 if (!(val & mask))
524 return 0;
525
526 usleep_range(1000, 2000);
527 }
528
Andrew Lunn30853552016-08-19 00:01:57 +0200529 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400530 return -ETIMEDOUT;
531}
532
Vivien Didelotf22ab642016-07-18 20:45:31 -0400533/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400534int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400535{
536 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200537 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400538
539 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200540 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
541 if (err)
542 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400543
544 /* Set the Update bit to trigger a write operation */
545 val = BIT(15) | update;
546
547 return mv88e6xxx_write(chip, addr, reg, val);
548}
549
Vivien Didelota935c052016-09-29 12:21:53 -0400550static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000551{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500552 if (!chip->info->ops->ppu_disable)
553 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000554
Vivien Didelota199d8b2016-12-05 17:30:28 -0500555 return chip->info->ops->ppu_disable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000556}
557
Vivien Didelotfad09c72016-06-21 12:28:20 -0400558static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000559{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500560 if (!chip->info->ops->ppu_enable)
561 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000562
Vivien Didelota199d8b2016-12-05 17:30:28 -0500563 return chip->info->ops->ppu_enable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000564}
565
566static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
567{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400568 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000569
Vivien Didelotfad09c72016-06-21 12:28:20 -0400570 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200571
Vivien Didelotfad09c72016-06-21 12:28:20 -0400572 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200573
Vivien Didelotfad09c72016-06-21 12:28:20 -0400574 if (mutex_trylock(&chip->ppu_mutex)) {
575 if (mv88e6xxx_ppu_enable(chip) == 0)
576 chip->ppu_disabled = 0;
577 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000578 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200579
Vivien Didelotfad09c72016-06-21 12:28:20 -0400580 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000581}
582
583static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
584{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400585 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000586
Vivien Didelotfad09c72016-06-21 12:28:20 -0400587 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000588}
589
Vivien Didelotfad09c72016-06-21 12:28:20 -0400590static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000591{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000592 int ret;
593
Vivien Didelotfad09c72016-06-21 12:28:20 -0400594 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000595
Barry Grussling3675c8d2013-01-08 16:05:53 +0000596 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000597 * we can access the PHY registers. If it was already
598 * disabled, cancel the timer that is going to re-enable
599 * it.
600 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400601 if (!chip->ppu_disabled) {
602 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000603 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400604 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000605 return ret;
606 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400607 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000608 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400609 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000610 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000611 }
612
613 return ret;
614}
615
Vivien Didelotfad09c72016-06-21 12:28:20 -0400616static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000617{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000618 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400619 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
620 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000621}
622
Vivien Didelotfad09c72016-06-21 12:28:20 -0400623static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000624{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400625 mutex_init(&chip->ppu_mutex);
626 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000627 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
628 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000629}
630
Andrew Lunn930188c2016-08-22 16:01:03 +0200631static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
632{
633 del_timer_sync(&chip->ppu_timer);
634}
635
Andrew Lunnee26a222017-01-24 14:53:48 +0100636static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip,
637 struct mii_bus *bus,
638 int addr, int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000639{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400640 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000641
Vivien Didelote57e5e72016-08-15 17:19:00 -0400642 err = mv88e6xxx_ppu_access_get(chip);
643 if (!err) {
644 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400645 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000646 }
647
Vivien Didelote57e5e72016-08-15 17:19:00 -0400648 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000649}
650
Andrew Lunnee26a222017-01-24 14:53:48 +0100651static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip,
652 struct mii_bus *bus,
653 int addr, int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000654{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400655 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000656
Vivien Didelote57e5e72016-08-15 17:19:00 -0400657 err = mv88e6xxx_ppu_access_get(chip);
658 if (!err) {
659 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400660 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000661 }
662
Vivien Didelote57e5e72016-08-15 17:19:00 -0400663 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000664}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000665
Vivien Didelotfad09c72016-06-21 12:28:20 -0400666static bool mv88e6xxx_6095_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200667{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400668 return chip->info->family == MV88E6XXX_FAMILY_6095;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200669}
670
Vivien Didelotfad09c72016-06-21 12:28:20 -0400671static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200672{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400673 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200674}
675
Vivien Didelotfad09c72016-06-21 12:28:20 -0400676static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200677{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400678 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200679}
680
Vivien Didelotfad09c72016-06-21 12:28:20 -0400681static bool mv88e6xxx_6185_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200682{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400683 return chip->info->family == MV88E6XXX_FAMILY_6185;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200684}
685
Vivien Didelotfad09c72016-06-21 12:28:20 -0400686static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700687{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400688 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700689}
690
Vivien Didelotfad09c72016-06-21 12:28:20 -0400691static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200692{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400693 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200694}
695
Vivien Didelotfad09c72016-06-21 12:28:20 -0400696static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200697{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400698 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200699}
700
Vivien Didelotd78343d2016-11-04 03:23:36 +0100701static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
702 int link, int speed, int duplex,
703 phy_interface_t mode)
704{
705 int err;
706
707 if (!chip->info->ops->port_set_link)
708 return 0;
709
710 /* Port's MAC control must not be changed unless the link is down */
711 err = chip->info->ops->port_set_link(chip, port, 0);
712 if (err)
713 return err;
714
715 if (chip->info->ops->port_set_speed) {
716 err = chip->info->ops->port_set_speed(chip, port, speed);
717 if (err && err != -EOPNOTSUPP)
718 goto restore_link;
719 }
720
721 if (chip->info->ops->port_set_duplex) {
722 err = chip->info->ops->port_set_duplex(chip, port, duplex);
723 if (err && err != -EOPNOTSUPP)
724 goto restore_link;
725 }
726
727 if (chip->info->ops->port_set_rgmii_delay) {
728 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
729 if (err && err != -EOPNOTSUPP)
730 goto restore_link;
731 }
732
733 err = 0;
734restore_link:
735 if (chip->info->ops->port_set_link(chip, port, link))
736 netdev_err(chip->ds->ports[port].netdev,
737 "failed to restore MAC's link\n");
738
739 return err;
740}
741
Andrew Lunndea87022015-08-31 15:56:47 +0200742/* We expect the switch to perform auto negotiation if there is a real
743 * phy. However, in the case of a fixed link phy, we force the port
744 * settings from the fixed link settings.
745 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400746static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
747 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200748{
Vivien Didelot04bed142016-08-31 18:06:13 -0400749 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200750 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200751
752 if (!phy_is_pseudo_fixed_link(phydev))
753 return;
754
Vivien Didelotfad09c72016-06-21 12:28:20 -0400755 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100756 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
757 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400758 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100759
760 if (err && err != -EOPNOTSUPP)
761 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200762}
763
Andrew Lunna605a0f2016-11-21 23:26:58 +0100764static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000765{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100766 if (!chip->info->ops->stats_snapshot)
767 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000768
Andrew Lunna605a0f2016-11-21 23:26:58 +0100769 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000770}
771
Andrew Lunne413e7e2015-04-02 04:06:38 +0200772static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100773 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
774 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
775 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
776 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
777 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
778 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
779 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
780 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
781 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
782 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
783 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
784 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
785 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
786 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
787 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
788 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
789 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
790 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
791 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
792 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
793 { "single", 4, 0x14, STATS_TYPE_BANK0, },
794 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
795 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
796 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
797 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
798 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
799 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
800 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
801 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
802 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
803 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
804 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
805 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
806 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
807 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
808 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
809 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
810 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
811 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
812 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
813 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
814 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
815 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
816 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
817 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
818 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
819 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
820 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
821 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
822 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
823 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
824 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
825 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
826 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
827 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
828 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
829 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
830 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
831 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200832};
833
Vivien Didelotfad09c72016-06-21 12:28:20 -0400834static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100835 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100836 int port, u16 bank1_select,
837 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200838{
Andrew Lunn80c46272015-06-20 18:42:30 +0200839 u32 low;
840 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100841 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200842 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200843 u64 value;
844
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100845 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100846 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200847 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
848 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200849 return UINT64_MAX;
850
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200851 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200852 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200853 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
854 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200855 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200856 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200857 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100858 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100859 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100860 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100861 /* fall through */
862 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100863 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100864 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200865 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100866 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200867 }
868 value = (((u64)high) << 16) | low;
869 return value;
870}
871
Andrew Lunndfafe442016-11-21 23:27:02 +0100872static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
873 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100874{
875 struct mv88e6xxx_hw_stat *stat;
876 int i, j;
877
878 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
879 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100880 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100881 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
882 ETH_GSTRING_LEN);
883 j++;
884 }
885 }
886}
887
Andrew Lunndfafe442016-11-21 23:27:02 +0100888static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
889 uint8_t *data)
890{
891 mv88e6xxx_stats_get_strings(chip, data,
892 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
893}
894
895static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
896 uint8_t *data)
897{
898 mv88e6xxx_stats_get_strings(chip, data,
899 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
900}
901
902static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
903 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100904{
Vivien Didelot04bed142016-08-31 18:06:13 -0400905 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100906
907 if (chip->info->ops->stats_get_strings)
908 chip->info->ops->stats_get_strings(chip, data);
909}
910
911static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
912 int types)
913{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100914 struct mv88e6xxx_hw_stat *stat;
915 int i, j;
916
917 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
918 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100919 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100920 j++;
921 }
922 return j;
923}
924
Andrew Lunndfafe442016-11-21 23:27:02 +0100925static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
926{
927 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
928 STATS_TYPE_PORT);
929}
930
931static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
932{
933 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
934 STATS_TYPE_BANK1);
935}
936
937static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
938{
939 struct mv88e6xxx_chip *chip = ds->priv;
940
941 if (chip->info->ops->stats_get_sset_count)
942 return chip->info->ops->stats_get_sset_count(chip);
943
944 return 0;
945}
946
Andrew Lunn052f9472016-11-21 23:27:03 +0100947static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100948 uint64_t *data, int types,
949 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100950{
951 struct mv88e6xxx_hw_stat *stat;
952 int i, j;
953
954 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
955 stat = &mv88e6xxx_hw_stats[i];
956 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100957 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
958 bank1_select,
959 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100960 j++;
961 }
962 }
963}
964
965static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
966 uint64_t *data)
967{
968 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100969 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
970 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100971}
972
973static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
974 uint64_t *data)
975{
976 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100977 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
978 GLOBAL_STATS_OP_BANK_1_BIT_9,
979 GLOBAL_STATS_OP_HIST_RX_TX);
980}
981
982static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
983 uint64_t *data)
984{
985 return mv88e6xxx_stats_get_stats(chip, port, data,
986 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
987 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100988}
989
990static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
991 uint64_t *data)
992{
993 if (chip->info->ops->stats_get_stats)
994 chip->info->ops->stats_get_stats(chip, port, data);
995}
996
Vivien Didelotf81ec902016-05-09 13:22:58 -0400997static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
998 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000999{
Vivien Didelot04bed142016-08-31 18:06:13 -04001000 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001001 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001002
Vivien Didelotfad09c72016-06-21 12:28:20 -04001003 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001004
Andrew Lunna605a0f2016-11-21 23:26:58 +01001005 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001006 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001007 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001008 return;
1009 }
Andrew Lunn052f9472016-11-21 23:27:03 +01001010
1011 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001012
Vivien Didelotfad09c72016-06-21 12:28:20 -04001013 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001014}
Ben Hutchings98e67302011-11-25 14:36:19 +00001015
Andrew Lunnde2273872016-11-21 23:27:01 +01001016static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1017{
1018 if (chip->info->ops->stats_set_histogram)
1019 return chip->info->ops->stats_set_histogram(chip);
1020
1021 return 0;
1022}
1023
Vivien Didelotf81ec902016-05-09 13:22:58 -04001024static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001025{
1026 return 32 * sizeof(u16);
1027}
1028
Vivien Didelotf81ec902016-05-09 13:22:58 -04001029static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1030 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001031{
Vivien Didelot04bed142016-08-31 18:06:13 -04001032 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001033 int err;
1034 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001035 u16 *p = _p;
1036 int i;
1037
1038 regs->version = 0;
1039
1040 memset(p, 0xff, 32 * sizeof(u16));
1041
Vivien Didelotfad09c72016-06-21 12:28:20 -04001042 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001043
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001044 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001045
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001046 err = mv88e6xxx_port_read(chip, port, i, &reg);
1047 if (!err)
1048 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001049 }
Vivien Didelot23062512016-05-09 13:22:45 -04001050
Vivien Didelotfad09c72016-06-21 12:28:20 -04001051 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001052}
1053
Vivien Didelotfad09c72016-06-21 12:28:20 -04001054static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001055{
Vivien Didelota935c052016-09-29 12:21:53 -04001056 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001057}
1058
Vivien Didelotf81ec902016-05-09 13:22:58 -04001059static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1060 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001061{
Vivien Didelot04bed142016-08-31 18:06:13 -04001062 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001063 u16 reg;
1064 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001065
Vivien Didelotfad09c72016-06-21 12:28:20 -04001066 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001067 return -EOPNOTSUPP;
1068
Vivien Didelotfad09c72016-06-21 12:28:20 -04001069 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001070
Vivien Didelot9c938292016-08-15 17:19:02 -04001071 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1072 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001073 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001074
1075 e->eee_enabled = !!(reg & 0x0200);
1076 e->tx_lpi_enabled = !!(reg & 0x0100);
1077
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001078 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001079 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001080 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001081
Andrew Lunncca8b132015-04-02 04:06:39 +02001082 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001083out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001084 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001085
1086 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001087}
1088
Vivien Didelotf81ec902016-05-09 13:22:58 -04001089static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1090 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001091{
Vivien Didelot04bed142016-08-31 18:06:13 -04001092 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001093 u16 reg;
1094 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001095
Vivien Didelotfad09c72016-06-21 12:28:20 -04001096 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001097 return -EOPNOTSUPP;
1098
Vivien Didelotfad09c72016-06-21 12:28:20 -04001099 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001100
Vivien Didelot9c938292016-08-15 17:19:02 -04001101 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1102 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001103 goto out;
1104
Vivien Didelot9c938292016-08-15 17:19:02 -04001105 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001106 if (e->eee_enabled)
1107 reg |= 0x0200;
1108 if (e->tx_lpi_enabled)
1109 reg |= 0x0100;
1110
Vivien Didelot9c938292016-08-15 17:19:02 -04001111 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001112out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001113 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001114
Vivien Didelot9c938292016-08-15 17:19:02 -04001115 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001116}
1117
Vivien Didelotfad09c72016-06-21 12:28:20 -04001118static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001119{
Vivien Didelota935c052016-09-29 12:21:53 -04001120 u16 val;
1121 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001122
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001123 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001124 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1125 if (err)
1126 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001127 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001128 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001129 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1130 if (err)
1131 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001132
Vivien Didelota935c052016-09-29 12:21:53 -04001133 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1134 (val & 0xfff) | ((fid << 8) & 0xf000));
1135 if (err)
1136 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001137
1138 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1139 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001140 }
1141
Vivien Didelota935c052016-09-29 12:21:53 -04001142 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1143 if (err)
1144 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001145
Vivien Didelotfad09c72016-06-21 12:28:20 -04001146 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001147}
1148
Vivien Didelotfad09c72016-06-21 12:28:20 -04001149static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001150 struct mv88e6xxx_atu_entry *entry)
1151{
1152 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1153
1154 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1155 unsigned int mask, shift;
1156
1157 if (entry->trunk) {
1158 data |= GLOBAL_ATU_DATA_TRUNK;
1159 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1160 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1161 } else {
1162 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1163 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1164 }
1165
1166 data |= (entry->portv_trunkid << shift) & mask;
1167 }
1168
Vivien Didelota935c052016-09-29 12:21:53 -04001169 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001170}
1171
Vivien Didelotfad09c72016-06-21 12:28:20 -04001172static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001173 struct mv88e6xxx_atu_entry *entry,
1174 bool static_too)
1175{
1176 int op;
1177 int err;
1178
Vivien Didelotfad09c72016-06-21 12:28:20 -04001179 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001180 if (err)
1181 return err;
1182
Vivien Didelotfad09c72016-06-21 12:28:20 -04001183 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001184 if (err)
1185 return err;
1186
1187 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001188 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1189 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1190 } else {
1191 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1192 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1193 }
1194
Vivien Didelotfad09c72016-06-21 12:28:20 -04001195 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001196}
1197
Vivien Didelotfad09c72016-06-21 12:28:20 -04001198static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001199 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001200{
1201 struct mv88e6xxx_atu_entry entry = {
1202 .fid = fid,
1203 .state = 0, /* EntryState bits must be 0 */
1204 };
1205
Vivien Didelotfad09c72016-06-21 12:28:20 -04001206 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001207}
1208
Vivien Didelotfad09c72016-06-21 12:28:20 -04001209static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001210 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001211{
1212 struct mv88e6xxx_atu_entry entry = {
1213 .trunk = false,
1214 .fid = fid,
1215 };
1216
1217 /* EntryState bits must be 0xF */
1218 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1219
1220 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1221 entry.portv_trunkid = (to_port & 0x0f) << 4;
1222 entry.portv_trunkid |= from_port & 0x0f;
1223
Vivien Didelotfad09c72016-06-21 12:28:20 -04001224 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001225}
1226
Vivien Didelotfad09c72016-06-21 12:28:20 -04001227static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001228 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001229{
1230 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001231 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001232}
1233
Vivien Didelotfad09c72016-06-21 12:28:20 -04001234static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001235{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001236 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001237 struct dsa_switch *ds = chip->ds;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001238 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001239 int i;
1240
1241 /* allow CPU port or DSA link(s) to send frames to every port */
1242 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001243 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001244 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001245 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001246 /* allow sending frames to every group member */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001247 if (bridge && chip->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001248 output_ports |= BIT(i);
1249
1250 /* allow sending frames to CPU port and DSA link(s) */
1251 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1252 output_ports |= BIT(i);
1253 }
1254 }
1255
1256 /* prevent frames from going back out of the port they came in on */
1257 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001258
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001259 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001260}
1261
Vivien Didelotf81ec902016-05-09 13:22:58 -04001262static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1263 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001264{
Vivien Didelot04bed142016-08-31 18:06:13 -04001265 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001266 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001267 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001268
1269 switch (state) {
1270 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001271 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001272 break;
1273 case BR_STATE_BLOCKING:
1274 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001275 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001276 break;
1277 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001278 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001279 break;
1280 case BR_STATE_FORWARDING:
1281 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001282 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001283 break;
1284 }
1285
Vivien Didelotfad09c72016-06-21 12:28:20 -04001286 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001287 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001288 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001289
1290 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001291 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001292}
1293
Vivien Didelot749efcb2016-09-22 16:49:24 -04001294static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1295{
1296 struct mv88e6xxx_chip *chip = ds->priv;
1297 int err;
1298
1299 mutex_lock(&chip->reg_lock);
1300 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1301 mutex_unlock(&chip->reg_lock);
1302
1303 if (err)
1304 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1305}
1306
Vivien Didelotfad09c72016-06-21 12:28:20 -04001307static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001308{
Vivien Didelota935c052016-09-29 12:21:53 -04001309 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001310}
1311
Vivien Didelotfad09c72016-06-21 12:28:20 -04001312static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001313{
Vivien Didelota935c052016-09-29 12:21:53 -04001314 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001315
Vivien Didelota935c052016-09-29 12:21:53 -04001316 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1317 if (err)
1318 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001319
Vivien Didelotfad09c72016-06-21 12:28:20 -04001320 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001321}
1322
Vivien Didelotfad09c72016-06-21 12:28:20 -04001323static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001324{
1325 int ret;
1326
Vivien Didelotfad09c72016-06-21 12:28:20 -04001327 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001328 if (ret < 0)
1329 return ret;
1330
Vivien Didelotfad09c72016-06-21 12:28:20 -04001331 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001332}
1333
Vivien Didelotfad09c72016-06-21 12:28:20 -04001334static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001335 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001336 unsigned int nibble_offset)
1337{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001338 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001339 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001340
1341 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001342 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001343
Vivien Didelota935c052016-09-29 12:21:53 -04001344 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1345 if (err)
1346 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001347 }
1348
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001349 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001350 unsigned int shift = (i % 4) * 4 + nibble_offset;
1351 u16 reg = regs[i / 4];
1352
1353 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1354 }
1355
1356 return 0;
1357}
1358
Vivien Didelotfad09c72016-06-21 12:28:20 -04001359static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001360 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001361{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001362 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001363}
1364
Vivien Didelotfad09c72016-06-21 12:28:20 -04001365static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001366 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001367{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001368 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001369}
1370
Vivien Didelotfad09c72016-06-21 12:28:20 -04001371static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001372 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001373 unsigned int nibble_offset)
1374{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001375 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001376 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001377
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001378 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001379 unsigned int shift = (i % 4) * 4 + nibble_offset;
1380 u8 data = entry->data[i];
1381
1382 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1383 }
1384
1385 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001386 u16 reg = regs[i];
1387
1388 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1389 if (err)
1390 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001391 }
1392
1393 return 0;
1394}
1395
Vivien Didelotfad09c72016-06-21 12:28:20 -04001396static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001397 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001398{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001399 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001400}
1401
Vivien Didelotfad09c72016-06-21 12:28:20 -04001402static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001403 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001404{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001405 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001406}
1407
Vivien Didelotfad09c72016-06-21 12:28:20 -04001408static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001409{
Vivien Didelota935c052016-09-29 12:21:53 -04001410 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1411 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001412}
1413
Vivien Didelotfad09c72016-06-21 12:28:20 -04001414static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001415 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001416{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001417 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001418 u16 val;
1419 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001420
Vivien Didelota935c052016-09-29 12:21:53 -04001421 err = _mv88e6xxx_vtu_wait(chip);
1422 if (err)
1423 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001424
Vivien Didelota935c052016-09-29 12:21:53 -04001425 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1426 if (err)
1427 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001428
Vivien Didelota935c052016-09-29 12:21:53 -04001429 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1430 if (err)
1431 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001432
Vivien Didelota935c052016-09-29 12:21:53 -04001433 next.vid = val & GLOBAL_VTU_VID_MASK;
1434 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001435
1436 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001437 err = mv88e6xxx_vtu_data_read(chip, &next);
1438 if (err)
1439 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001440
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001441 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001442 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1443 if (err)
1444 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001445
Vivien Didelota935c052016-09-29 12:21:53 -04001446 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001447 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001448 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1449 * VTU DBNum[3:0] are located in VTU Operation 3:0
1450 */
Vivien Didelota935c052016-09-29 12:21:53 -04001451 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1452 if (err)
1453 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001454
Vivien Didelota935c052016-09-29 12:21:53 -04001455 next.fid = (val & 0xf00) >> 4;
1456 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001457 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001458
Vivien Didelotfad09c72016-06-21 12:28:20 -04001459 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001460 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1461 if (err)
1462 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001463
Vivien Didelota935c052016-09-29 12:21:53 -04001464 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001465 }
1466 }
1467
1468 *entry = next;
1469 return 0;
1470}
1471
Vivien Didelotf81ec902016-05-09 13:22:58 -04001472static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1473 struct switchdev_obj_port_vlan *vlan,
1474 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001475{
Vivien Didelot04bed142016-08-31 18:06:13 -04001476 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001477 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001478 u16 pvid;
1479 int err;
1480
Vivien Didelotfad09c72016-06-21 12:28:20 -04001481 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001482 return -EOPNOTSUPP;
1483
Vivien Didelotfad09c72016-06-21 12:28:20 -04001484 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001485
Vivien Didelot77064f32016-11-04 03:23:30 +01001486 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001487 if (err)
1488 goto unlock;
1489
Vivien Didelotfad09c72016-06-21 12:28:20 -04001490 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001491 if (err)
1492 goto unlock;
1493
1494 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001495 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001496 if (err)
1497 break;
1498
1499 if (!next.valid)
1500 break;
1501
1502 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1503 continue;
1504
1505 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001506 vlan->vid_begin = next.vid;
1507 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001508 vlan->flags = 0;
1509
1510 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1511 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1512
1513 if (next.vid == pvid)
1514 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1515
1516 err = cb(&vlan->obj);
1517 if (err)
1518 break;
1519 } while (next.vid < GLOBAL_VTU_VID_MASK);
1520
1521unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001522 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001523
1524 return err;
1525}
1526
Vivien Didelotfad09c72016-06-21 12:28:20 -04001527static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001528 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001529{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001530 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001531 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001532 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001533
Vivien Didelota935c052016-09-29 12:21:53 -04001534 err = _mv88e6xxx_vtu_wait(chip);
1535 if (err)
1536 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001537
1538 if (!entry->valid)
1539 goto loadpurge;
1540
1541 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001542 err = mv88e6xxx_vtu_data_write(chip, entry);
1543 if (err)
1544 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001545
Vivien Didelotfad09c72016-06-21 12:28:20 -04001546 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001547 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001548 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1549 if (err)
1550 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001551 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001552
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001553 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001554 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001555 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1556 if (err)
1557 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001558 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001559 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1560 * VTU DBNum[3:0] are located in VTU Operation 3:0
1561 */
1562 op |= (entry->fid & 0xf0) << 8;
1563 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001564 }
1565
1566 reg = GLOBAL_VTU_VID_VALID;
1567loadpurge:
1568 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001569 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1570 if (err)
1571 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001572
Vivien Didelotfad09c72016-06-21 12:28:20 -04001573 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001574}
1575
Vivien Didelotfad09c72016-06-21 12:28:20 -04001576static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001577 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001578{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001579 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001580 u16 val;
1581 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001582
Vivien Didelota935c052016-09-29 12:21:53 -04001583 err = _mv88e6xxx_vtu_wait(chip);
1584 if (err)
1585 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001586
Vivien Didelota935c052016-09-29 12:21:53 -04001587 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1588 sid & GLOBAL_VTU_SID_MASK);
1589 if (err)
1590 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001591
Vivien Didelota935c052016-09-29 12:21:53 -04001592 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1593 if (err)
1594 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001595
Vivien Didelota935c052016-09-29 12:21:53 -04001596 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1597 if (err)
1598 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001599
Vivien Didelota935c052016-09-29 12:21:53 -04001600 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001601
Vivien Didelota935c052016-09-29 12:21:53 -04001602 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1603 if (err)
1604 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001605
Vivien Didelota935c052016-09-29 12:21:53 -04001606 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001607
1608 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001609 err = mv88e6xxx_stu_data_read(chip, &next);
1610 if (err)
1611 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001612 }
1613
1614 *entry = next;
1615 return 0;
1616}
1617
Vivien Didelotfad09c72016-06-21 12:28:20 -04001618static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001619 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001620{
1621 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001622 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001623
Vivien Didelota935c052016-09-29 12:21:53 -04001624 err = _mv88e6xxx_vtu_wait(chip);
1625 if (err)
1626 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001627
1628 if (!entry->valid)
1629 goto loadpurge;
1630
1631 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001632 err = mv88e6xxx_stu_data_write(chip, entry);
1633 if (err)
1634 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001635
1636 reg = GLOBAL_VTU_VID_VALID;
1637loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001638 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1639 if (err)
1640 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001641
1642 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001643 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1644 if (err)
1645 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001646
Vivien Didelotfad09c72016-06-21 12:28:20 -04001647 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001648}
1649
Vivien Didelotfad09c72016-06-21 12:28:20 -04001650static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001651{
1652 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001653 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001654 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001655
1656 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1657
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001658 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001659 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001660 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001661 if (err)
1662 return err;
1663
1664 set_bit(*fid, fid_bitmap);
1665 }
1666
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001667 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001668 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001669 if (err)
1670 return err;
1671
1672 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001673 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001674 if (err)
1675 return err;
1676
1677 if (!vlan.valid)
1678 break;
1679
1680 set_bit(vlan.fid, fid_bitmap);
1681 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1682
1683 /* The reset value 0x000 is used to indicate that multiple address
1684 * databases are not needed. Return the next positive available.
1685 */
1686 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001687 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001688 return -ENOSPC;
1689
1690 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001691 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001692}
1693
Vivien Didelotfad09c72016-06-21 12:28:20 -04001694static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001695 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001696{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001697 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001698 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001699 .valid = true,
1700 .vid = vid,
1701 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001702 int i, err;
1703
Vivien Didelotfad09c72016-06-21 12:28:20 -04001704 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001705 if (err)
1706 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001707
Vivien Didelot3d131f02015-11-03 10:52:52 -05001708 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001709 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001710 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1711 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1712 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001713
Vivien Didelotfad09c72016-06-21 12:28:20 -04001714 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
1715 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001716 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001717
1718 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1719 * implemented, only one STU entry is needed to cover all VTU
1720 * entries. Thus, validate the SID 0.
1721 */
1722 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001723 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001724 if (err)
1725 return err;
1726
1727 if (vstp.sid != vlan.sid || !vstp.valid) {
1728 memset(&vstp, 0, sizeof(vstp));
1729 vstp.valid = true;
1730 vstp.sid = vlan.sid;
1731
Vivien Didelotfad09c72016-06-21 12:28:20 -04001732 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001733 if (err)
1734 return err;
1735 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001736 }
1737
1738 *entry = vlan;
1739 return 0;
1740}
1741
Vivien Didelotfad09c72016-06-21 12:28:20 -04001742static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001743 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001744{
1745 int err;
1746
1747 if (!vid)
1748 return -EINVAL;
1749
Vivien Didelotfad09c72016-06-21 12:28:20 -04001750 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001751 if (err)
1752 return err;
1753
Vivien Didelotfad09c72016-06-21 12:28:20 -04001754 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001755 if (err)
1756 return err;
1757
1758 if (entry->vid != vid || !entry->valid) {
1759 if (!creat)
1760 return -EOPNOTSUPP;
1761 /* -ENOENT would've been more appropriate, but switchdev expects
1762 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1763 */
1764
Vivien Didelotfad09c72016-06-21 12:28:20 -04001765 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001766 }
1767
1768 return err;
1769}
1770
Vivien Didelotda9c3592016-02-12 12:09:40 -05001771static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1772 u16 vid_begin, u16 vid_end)
1773{
Vivien Didelot04bed142016-08-31 18:06:13 -04001774 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001775 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001776 int i, err;
1777
1778 if (!vid_begin)
1779 return -EOPNOTSUPP;
1780
Vivien Didelotfad09c72016-06-21 12:28:20 -04001781 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001782
Vivien Didelotfad09c72016-06-21 12:28:20 -04001783 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001784 if (err)
1785 goto unlock;
1786
1787 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001788 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001789 if (err)
1790 goto unlock;
1791
1792 if (!vlan.valid)
1793 break;
1794
1795 if (vlan.vid > vid_end)
1796 break;
1797
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001798 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001799 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1800 continue;
1801
Andrew Lunn66e28092016-12-11 21:07:19 +01001802 if (!ds->ports[port].netdev)
1803 continue;
1804
Vivien Didelotda9c3592016-02-12 12:09:40 -05001805 if (vlan.data[i] ==
1806 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1807 continue;
1808
Vivien Didelotfad09c72016-06-21 12:28:20 -04001809 if (chip->ports[i].bridge_dev ==
1810 chip->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001811 break; /* same bridge, check next VLAN */
1812
Andrew Lunn66e28092016-12-11 21:07:19 +01001813 if (!chip->ports[i].bridge_dev)
1814 continue;
1815
Andrew Lunnc8b09802016-06-04 21:16:57 +02001816 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001817 "hardware VLAN %d already used by %s\n",
1818 vlan.vid,
Vivien Didelotfad09c72016-06-21 12:28:20 -04001819 netdev_name(chip->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001820 err = -EOPNOTSUPP;
1821 goto unlock;
1822 }
1823 } while (vlan.vid < vid_end);
1824
1825unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001826 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001827
1828 return err;
1829}
1830
Vivien Didelotf81ec902016-05-09 13:22:58 -04001831static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1832 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001833{
Vivien Didelot04bed142016-08-31 18:06:13 -04001834 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001835 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001836 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001837 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001838
Vivien Didelotfad09c72016-06-21 12:28:20 -04001839 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001840 return -EOPNOTSUPP;
1841
Vivien Didelotfad09c72016-06-21 12:28:20 -04001842 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001843 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001844 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001845
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001846 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001847}
1848
Vivien Didelot57d32312016-06-20 13:13:58 -04001849static int
1850mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1851 const struct switchdev_obj_port_vlan *vlan,
1852 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001853{
Vivien Didelot04bed142016-08-31 18:06:13 -04001854 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001855 int err;
1856
Vivien Didelotfad09c72016-06-21 12:28:20 -04001857 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001858 return -EOPNOTSUPP;
1859
Vivien Didelotda9c3592016-02-12 12:09:40 -05001860 /* If the requested port doesn't belong to the same bridge as the VLAN
1861 * members, do not support it (yet) and fallback to software VLAN.
1862 */
1863 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1864 vlan->vid_end);
1865 if (err)
1866 return err;
1867
Vivien Didelot76e398a2015-11-01 12:33:55 -05001868 /* We don't need any dynamic resource from the kernel (yet),
1869 * so skip the prepare phase.
1870 */
1871 return 0;
1872}
1873
Vivien Didelotfad09c72016-06-21 12:28:20 -04001874static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001875 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001876{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001877 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001878 int err;
1879
Vivien Didelotfad09c72016-06-21 12:28:20 -04001880 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001881 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001882 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001883
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001884 vlan.data[port] = untagged ?
1885 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1886 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1887
Vivien Didelotfad09c72016-06-21 12:28:20 -04001888 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001889}
1890
Vivien Didelotf81ec902016-05-09 13:22:58 -04001891static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1892 const struct switchdev_obj_port_vlan *vlan,
1893 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001894{
Vivien Didelot04bed142016-08-31 18:06:13 -04001895 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001896 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1897 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1898 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001899
Vivien Didelotfad09c72016-06-21 12:28:20 -04001900 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001901 return;
1902
Vivien Didelotfad09c72016-06-21 12:28:20 -04001903 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001904
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001905 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001906 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001907 netdev_err(ds->ports[port].netdev,
1908 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001909 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001910
Vivien Didelot77064f32016-11-04 03:23:30 +01001911 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001912 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001913 vlan->vid_end);
1914
Vivien Didelotfad09c72016-06-21 12:28:20 -04001915 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001916}
1917
Vivien Didelotfad09c72016-06-21 12:28:20 -04001918static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001919 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001920{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001921 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001922 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001923 int i, err;
1924
Vivien Didelotfad09c72016-06-21 12:28:20 -04001925 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001926 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001927 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001928
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001929 /* Tell switchdev if this VLAN is handled in software */
1930 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001931 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001932
1933 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1934
1935 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001936 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001937 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001938 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001939 continue;
1940
1941 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001942 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001943 break;
1944 }
1945 }
1946
Vivien Didelotfad09c72016-06-21 12:28:20 -04001947 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001948 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001949 return err;
1950
Vivien Didelotfad09c72016-06-21 12:28:20 -04001951 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001952}
1953
Vivien Didelotf81ec902016-05-09 13:22:58 -04001954static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1955 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001956{
Vivien Didelot04bed142016-08-31 18:06:13 -04001957 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001958 u16 pvid, vid;
1959 int err = 0;
1960
Vivien Didelotfad09c72016-06-21 12:28:20 -04001961 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001962 return -EOPNOTSUPP;
1963
Vivien Didelotfad09c72016-06-21 12:28:20 -04001964 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001965
Vivien Didelot77064f32016-11-04 03:23:30 +01001966 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001967 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001968 goto unlock;
1969
Vivien Didelot76e398a2015-11-01 12:33:55 -05001970 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001971 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001972 if (err)
1973 goto unlock;
1974
1975 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001976 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001977 if (err)
1978 goto unlock;
1979 }
1980 }
1981
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001982unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001983 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001984
1985 return err;
1986}
1987
Vivien Didelotfad09c72016-06-21 12:28:20 -04001988static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04001989 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001990{
Vivien Didelota935c052016-09-29 12:21:53 -04001991 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001992
1993 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04001994 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
1995 (addr[i * 2] << 8) | addr[i * 2 + 1]);
1996 if (err)
1997 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001998 }
1999
2000 return 0;
2001}
2002
Vivien Didelotfad09c72016-06-21 12:28:20 -04002003static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04002004 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002005{
Vivien Didelota935c052016-09-29 12:21:53 -04002006 u16 val;
2007 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002008
2009 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002010 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
2011 if (err)
2012 return err;
2013
2014 addr[i * 2] = val >> 8;
2015 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002016 }
2017
2018 return 0;
2019}
2020
Vivien Didelotfad09c72016-06-21 12:28:20 -04002021static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04002022 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002023{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002024 int ret;
2025
Vivien Didelotfad09c72016-06-21 12:28:20 -04002026 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002027 if (ret < 0)
2028 return ret;
2029
Vivien Didelotfad09c72016-06-21 12:28:20 -04002030 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002031 if (ret < 0)
2032 return ret;
2033
Vivien Didelotfad09c72016-06-21 12:28:20 -04002034 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002035 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002036 return ret;
2037
Vivien Didelotfad09c72016-06-21 12:28:20 -04002038 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002039}
David S. Millercdf09692015-08-11 12:00:37 -07002040
Vivien Didelot88472932016-09-19 19:56:11 -04002041static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2042 struct mv88e6xxx_atu_entry *entry);
2043
2044static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2045 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2046{
2047 struct mv88e6xxx_atu_entry next;
2048 int err;
2049
Andrew Lunn59527582017-01-04 19:56:24 +01002050 memcpy(next.mac, addr, ETH_ALEN);
2051 eth_addr_dec(next.mac);
Vivien Didelot88472932016-09-19 19:56:11 -04002052
2053 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2054 if (err)
2055 return err;
2056
2057 do {
2058 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2059 if (err)
2060 return err;
2061
2062 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2063 break;
2064
2065 if (ether_addr_equal(next.mac, addr)) {
2066 *entry = next;
2067 return 0;
2068 }
Andrew Lunn59527582017-01-04 19:56:24 +01002069 } while (ether_addr_greater(addr, next.mac));
Vivien Didelot88472932016-09-19 19:56:11 -04002070
2071 memset(entry, 0, sizeof(*entry));
2072 entry->fid = fid;
2073 ether_addr_copy(entry->mac, addr);
2074
2075 return 0;
2076}
2077
Vivien Didelot83dabd12016-08-31 11:50:04 -04002078static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2079 const unsigned char *addr, u16 vid,
2080 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002081{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002082 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002083 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002084 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002085
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002086 /* Null VLAN ID corresponds to the port private database */
2087 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002088 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002089 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002090 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002091 if (err)
2092 return err;
2093
Vivien Didelot88472932016-09-19 19:56:11 -04002094 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2095 if (err)
2096 return err;
2097
2098 /* Purge the ATU entry only if no port is using it anymore */
2099 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2100 entry.portv_trunkid &= ~BIT(port);
2101 if (!entry.portv_trunkid)
2102 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2103 } else {
2104 entry.portv_trunkid |= BIT(port);
2105 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002106 }
2107
Vivien Didelotfad09c72016-06-21 12:28:20 -04002108 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002109}
2110
Vivien Didelotf81ec902016-05-09 13:22:58 -04002111static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2112 const struct switchdev_obj_port_fdb *fdb,
2113 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002114{
2115 /* We don't need any dynamic resource from the kernel (yet),
2116 * so skip the prepare phase.
2117 */
2118 return 0;
2119}
2120
Vivien Didelotf81ec902016-05-09 13:22:58 -04002121static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2122 const struct switchdev_obj_port_fdb *fdb,
2123 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002124{
Vivien Didelot04bed142016-08-31 18:06:13 -04002125 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002126
Vivien Didelotfad09c72016-06-21 12:28:20 -04002127 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002128 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2129 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2130 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002131 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002132}
2133
Vivien Didelotf81ec902016-05-09 13:22:58 -04002134static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2135 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002136{
Vivien Didelot04bed142016-08-31 18:06:13 -04002137 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002138 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002139
Vivien Didelotfad09c72016-06-21 12:28:20 -04002140 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002141 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2142 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002143 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002144
Vivien Didelot83dabd12016-08-31 11:50:04 -04002145 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002146}
2147
Vivien Didelotfad09c72016-06-21 12:28:20 -04002148static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002149 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002150{
Vivien Didelot1d194042015-08-10 09:09:51 -04002151 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002152 u16 val;
2153 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002154
2155 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002156
Vivien Didelota935c052016-09-29 12:21:53 -04002157 err = _mv88e6xxx_atu_wait(chip);
2158 if (err)
2159 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002160
Vivien Didelota935c052016-09-29 12:21:53 -04002161 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2162 if (err)
2163 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002164
Vivien Didelota935c052016-09-29 12:21:53 -04002165 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2166 if (err)
2167 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002168
Vivien Didelota935c052016-09-29 12:21:53 -04002169 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2170 if (err)
2171 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002172
Vivien Didelota935c052016-09-29 12:21:53 -04002173 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002174 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2175 unsigned int mask, shift;
2176
Vivien Didelota935c052016-09-29 12:21:53 -04002177 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002178 next.trunk = true;
2179 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2180 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2181 } else {
2182 next.trunk = false;
2183 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2184 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2185 }
2186
Vivien Didelota935c052016-09-29 12:21:53 -04002187 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002188 }
2189
2190 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002191 return 0;
2192}
2193
Vivien Didelot83dabd12016-08-31 11:50:04 -04002194static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2195 u16 fid, u16 vid, int port,
2196 struct switchdev_obj *obj,
2197 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002198{
2199 struct mv88e6xxx_atu_entry addr = {
2200 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2201 };
2202 int err;
2203
Vivien Didelotfad09c72016-06-21 12:28:20 -04002204 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002205 if (err)
2206 return err;
2207
2208 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002209 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002210 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002211 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002212
2213 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2214 break;
2215
Vivien Didelot83dabd12016-08-31 11:50:04 -04002216 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2217 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002218
Vivien Didelot83dabd12016-08-31 11:50:04 -04002219 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2220 struct switchdev_obj_port_fdb *fdb;
2221
2222 if (!is_unicast_ether_addr(addr.mac))
2223 continue;
2224
2225 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002226 fdb->vid = vid;
2227 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002228 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2229 fdb->ndm_state = NUD_NOARP;
2230 else
2231 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002232 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2233 struct switchdev_obj_port_mdb *mdb;
2234
2235 if (!is_multicast_ether_addr(addr.mac))
2236 continue;
2237
2238 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2239 mdb->vid = vid;
2240 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002241 } else {
2242 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002243 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002244
2245 err = cb(obj);
2246 if (err)
2247 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002248 } while (!is_broadcast_ether_addr(addr.mac));
2249
2250 return err;
2251}
2252
Vivien Didelot83dabd12016-08-31 11:50:04 -04002253static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2254 struct switchdev_obj *obj,
2255 int (*cb)(struct switchdev_obj *obj))
2256{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002257 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002258 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2259 };
2260 u16 fid;
2261 int err;
2262
2263 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002264 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002265 if (err)
2266 return err;
2267
2268 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2269 if (err)
2270 return err;
2271
2272 /* Dump VLANs' Filtering Information Databases */
2273 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2274 if (err)
2275 return err;
2276
2277 do {
2278 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2279 if (err)
2280 return err;
2281
2282 if (!vlan.valid)
2283 break;
2284
2285 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2286 obj, cb);
2287 if (err)
2288 return err;
2289 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2290
2291 return err;
2292}
2293
Vivien Didelotf81ec902016-05-09 13:22:58 -04002294static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2295 struct switchdev_obj_port_fdb *fdb,
2296 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002297{
Vivien Didelot04bed142016-08-31 18:06:13 -04002298 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002299 int err;
2300
Vivien Didelotfad09c72016-06-21 12:28:20 -04002301 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002302 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002303 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002304
2305 return err;
2306}
2307
Vivien Didelotf81ec902016-05-09 13:22:58 -04002308static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
2309 struct net_device *bridge)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002310{
Vivien Didelot04bed142016-08-31 18:06:13 -04002311 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002312 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002313
Vivien Didelotfad09c72016-06-21 12:28:20 -04002314 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002315
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002316 /* Assign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002317 chip->ports[port].bridge_dev = bridge;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002318
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002319 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002320 if (chip->ports[i].bridge_dev == bridge) {
2321 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002322 if (err)
2323 break;
2324 }
2325 }
2326
Vivien Didelotfad09c72016-06-21 12:28:20 -04002327 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002328
Vivien Didelot466dfa02016-02-26 13:16:05 -05002329 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002330}
2331
Vivien Didelotf81ec902016-05-09 13:22:58 -04002332static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002333{
Vivien Didelot04bed142016-08-31 18:06:13 -04002334 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002335 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002336 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002337
Vivien Didelotfad09c72016-06-21 12:28:20 -04002338 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002339
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002340 /* Unassign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002341 chip->ports[port].bridge_dev = NULL;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002342
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002343 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002344 if (i == port || chip->ports[i].bridge_dev == bridge)
2345 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002346 netdev_warn(ds->ports[i].netdev,
2347 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002348
Vivien Didelotfad09c72016-06-21 12:28:20 -04002349 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002350}
2351
Vivien Didelot17e708b2016-12-05 17:30:27 -05002352static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2353{
2354 if (chip->info->ops->reset)
2355 return chip->info->ops->reset(chip);
2356
2357 return 0;
2358}
2359
Vivien Didelot309eca62016-12-05 17:30:26 -05002360static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2361{
2362 struct gpio_desc *gpiod = chip->reset;
2363
2364 /* If there is a GPIO connected to the reset pin, toggle it */
2365 if (gpiod) {
2366 gpiod_set_value_cansleep(gpiod, 1);
2367 usleep_range(10000, 20000);
2368 gpiod_set_value_cansleep(gpiod, 0);
2369 usleep_range(10000, 20000);
2370 }
2371}
2372
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002373static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2374{
2375 int i, err;
2376
2377 /* Set all ports to the Disabled state */
2378 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2379 err = mv88e6xxx_port_set_state(chip, i,
2380 PORT_CONTROL_STATE_DISABLED);
2381 if (err)
2382 return err;
2383 }
2384
2385 /* Wait for transmit queues to drain,
2386 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2387 */
2388 usleep_range(2000, 4000);
2389
2390 return 0;
2391}
2392
Vivien Didelotfad09c72016-06-21 12:28:20 -04002393static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002394{
Vivien Didelota935c052016-09-29 12:21:53 -04002395 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002396
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002397 err = mv88e6xxx_disable_ports(chip);
2398 if (err)
2399 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002400
Vivien Didelot309eca62016-12-05 17:30:26 -05002401 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002402
Vivien Didelot17e708b2016-12-05 17:30:27 -05002403 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002404}
2405
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002406static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002407{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002408 u16 val;
2409 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002410
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002411 /* Clear Power Down bit */
2412 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2413 if (err)
2414 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002415
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002416 if (val & BMCR_PDOWN) {
2417 val &= ~BMCR_PDOWN;
2418 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002419 }
2420
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002421 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002422}
2423
Andrew Lunn56995cb2016-12-03 04:35:19 +01002424static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2425 int upstream_port)
2426{
2427 int err;
2428
2429 err = chip->info->ops->port_set_frame_mode(
2430 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2431 if (err)
2432 return err;
2433
2434 return chip->info->ops->port_set_egress_unknowns(
2435 chip, port, port == upstream_port);
2436}
2437
2438static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2439{
2440 int err;
2441
2442 switch (chip->info->tag_protocol) {
2443 case DSA_TAG_PROTO_EDSA:
2444 err = chip->info->ops->port_set_frame_mode(
2445 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2446 if (err)
2447 return err;
2448
2449 err = mv88e6xxx_port_set_egress_mode(
2450 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2451 if (err)
2452 return err;
2453
2454 if (chip->info->ops->port_set_ether_type)
2455 err = chip->info->ops->port_set_ether_type(
2456 chip, port, ETH_P_EDSA);
2457 break;
2458
2459 case DSA_TAG_PROTO_DSA:
2460 err = chip->info->ops->port_set_frame_mode(
2461 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2462 if (err)
2463 return err;
2464
2465 err = mv88e6xxx_port_set_egress_mode(
2466 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2467 break;
2468 default:
2469 err = -EINVAL;
2470 }
2471
2472 if (err)
2473 return err;
2474
2475 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2476}
2477
2478static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2479{
2480 int err;
2481
2482 err = chip->info->ops->port_set_frame_mode(
2483 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2484 if (err)
2485 return err;
2486
2487 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2488}
2489
Vivien Didelotfad09c72016-06-21 12:28:20 -04002490static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002491{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002492 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002493 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002494 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002495
Vivien Didelotd78343d2016-11-04 03:23:36 +01002496 /* MAC Forcing register: don't force link, speed, duplex or flow control
2497 * state to any particular values on physical ports, but force the CPU
2498 * port and all DSA ports to their maximum bandwidth and full duplex.
2499 */
2500 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2501 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2502 SPEED_MAX, DUPLEX_FULL,
2503 PHY_INTERFACE_MODE_NA);
2504 else
2505 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2506 SPEED_UNFORCED, DUPLEX_UNFORCED,
2507 PHY_INTERFACE_MODE_NA);
2508 if (err)
2509 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002510
2511 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2512 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2513 * tunneling, determine priority by looking at 802.1p and IP
2514 * priority fields (IP prio has precedence), and set STP state
2515 * to Forwarding.
2516 *
2517 * If this is the CPU link, use DSA or EDSA tagging depending
2518 * on which tagging mode was configured.
2519 *
2520 * If this is a link to another switch, use DSA tagging mode.
2521 *
2522 * If this is the upstream port for this switch, enable
2523 * forwarding of unknown unicasts and multicasts.
2524 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002525 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002526 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2527 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002528 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2529 if (err)
2530 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002531
Andrew Lunn56995cb2016-12-03 04:35:19 +01002532 if (dsa_is_cpu_port(ds, port)) {
2533 err = mv88e6xxx_setup_port_cpu(chip, port);
2534 } else if (dsa_is_dsa_port(ds, port)) {
2535 err = mv88e6xxx_setup_port_dsa(chip, port,
2536 dsa_upstream_port(ds));
2537 } else {
2538 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002539 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002540 if (err)
2541 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002542
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002543 /* If this port is connected to a SerDes, make sure the SerDes is not
2544 * powered down.
2545 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002546 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002547 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2548 if (err)
2549 return err;
2550 reg &= PORT_STATUS_CMODE_MASK;
2551 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2552 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2553 (reg == PORT_STATUS_CMODE_SGMII)) {
2554 err = mv88e6xxx_serdes_power_on(chip);
2555 if (err < 0)
2556 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002557 }
2558 }
2559
Vivien Didelot8efdda42015-08-13 12:52:23 -04002560 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002561 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002562 * untagged frames on this port, do a destination address lookup on all
2563 * received packets as usual, disable ARP mirroring and don't send a
2564 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002565 */
2566 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002567 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2568 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2569 mv88e6xxx_6095_family(chip) || mv88e6xxx_6320_family(chip) ||
2570 mv88e6xxx_6185_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002571 reg = PORT_CONTROL_2_MAP_DA;
2572
Vivien Didelotfad09c72016-06-21 12:28:20 -04002573 if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002574 /* Set the upstream port this port should use */
2575 reg |= dsa_upstream_port(ds);
2576 /* enable forwarding of unknown multicast addresses to
2577 * the upstream port
2578 */
2579 if (port == dsa_upstream_port(ds))
2580 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
2581 }
2582
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002583 reg |= PORT_CONTROL_2_8021Q_DISABLED;
Vivien Didelot8efdda42015-08-13 12:52:23 -04002584
Andrew Lunn54d792f2015-05-06 01:09:47 +02002585 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002586 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
2587 if (err)
2588 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002589 }
2590
Andrew Lunn5f436662016-12-03 04:45:17 +01002591 if (chip->info->ops->port_jumbo_config) {
2592 err = chip->info->ops->port_jumbo_config(chip, port);
2593 if (err)
2594 return err;
2595 }
2596
Andrew Lunn54d792f2015-05-06 01:09:47 +02002597 /* Port Association Vector: when learning source addresses
2598 * of packets, add the address to the address database using
2599 * a port bitmap that has only the bit for this port set and
2600 * the other bits clear.
2601 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002602 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002603 /* Disable learning for CPU port */
2604 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002605 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002606
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002607 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2608 if (err)
2609 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002610
2611 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002612 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2613 if (err)
2614 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002615
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002616 if (chip->info->ops->port_pause_config) {
2617 err = chip->info->ops->port_pause_config(chip, port);
2618 if (err)
2619 return err;
2620 }
2621
Vivien Didelotfad09c72016-06-21 12:28:20 -04002622 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2623 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2624 mv88e6xxx_6320_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002625 /* Port ATU control: disable limiting the number of
2626 * address database entries that this port is allowed
2627 * to use.
2628 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002629 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2630 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002631 /* Priority Override: disable DA, SA and VTU priority
2632 * override.
2633 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002634 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2635 0x0000);
2636 if (err)
2637 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002638 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002639
Andrew Lunnef0a7312016-12-03 04:35:16 +01002640 if (chip->info->ops->port_tag_remap) {
2641 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002642 if (err)
2643 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002644 }
2645
Andrew Lunnef70b112016-12-03 04:45:18 +01002646 if (chip->info->ops->port_egress_rate_limiting) {
2647 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002648 if (err)
2649 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002650 }
2651
Guenter Roeck366f0a02015-03-26 18:36:30 -07002652 /* Port Control 1: disable trunking, disable sending
2653 * learning messages to this port.
Guenter Roeckd827e882015-03-26 18:36:29 -07002654 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002655 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_1, 0x0000);
2656 if (err)
2657 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002658
Vivien Didelot207afda2016-04-14 14:42:09 -04002659 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002660 * database, and allow bidirectional communication between the
2661 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002662 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002663 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002664 if (err)
2665 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002666
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002667 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2668 if (err)
2669 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002670
2671 /* Default VLAN ID and priority: don't set a default VLAN
2672 * ID, and set the default packet priority to zero.
2673 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002674 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002675}
2676
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002677static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002678{
2679 int err;
2680
Vivien Didelota935c052016-09-29 12:21:53 -04002681 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002682 if (err)
2683 return err;
2684
Vivien Didelota935c052016-09-29 12:21:53 -04002685 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002686 if (err)
2687 return err;
2688
Vivien Didelota935c052016-09-29 12:21:53 -04002689 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2690 if (err)
2691 return err;
2692
2693 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002694}
2695
Vivien Didelotacddbd22016-07-18 20:45:39 -04002696static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
2697 unsigned int msecs)
2698{
2699 const unsigned int coeff = chip->info->age_time_coeff;
2700 const unsigned int min = 0x01 * coeff;
2701 const unsigned int max = 0xff * coeff;
2702 u8 age_time;
2703 u16 val;
2704 int err;
2705
2706 if (msecs < min || msecs > max)
2707 return -ERANGE;
2708
2709 /* Round to nearest multiple of coeff */
2710 age_time = (msecs + coeff / 2) / coeff;
2711
Vivien Didelota935c052016-09-29 12:21:53 -04002712 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002713 if (err)
2714 return err;
2715
2716 /* AgeTime is 11:4 bits */
2717 val &= ~0xff0;
2718 val |= age_time << 4;
2719
Vivien Didelota935c052016-09-29 12:21:53 -04002720 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002721}
2722
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002723static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2724 unsigned int ageing_time)
2725{
Vivien Didelot04bed142016-08-31 18:06:13 -04002726 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002727 int err;
2728
2729 mutex_lock(&chip->reg_lock);
2730 err = mv88e6xxx_g1_set_age_time(chip, ageing_time);
2731 mutex_unlock(&chip->reg_lock);
2732
2733 return err;
2734}
2735
Vivien Didelot97299342016-07-18 20:45:30 -04002736static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002737{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002738 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002739 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002740 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002741
Vivien Didelot119477b2016-05-09 13:22:51 -04002742 /* Enable the PHY Polling Unit if present, don't discard any packets,
2743 * and mask all interrupt sources.
2744 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002745 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002746 if (err)
2747 return err;
2748
Andrew Lunn33641992016-12-03 04:35:17 +01002749 if (chip->info->ops->g1_set_cpu_port) {
2750 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2751 if (err)
2752 return err;
2753 }
2754
2755 if (chip->info->ops->g1_set_egress_port) {
2756 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2757 if (err)
2758 return err;
2759 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002760
Vivien Didelot50484ff2016-05-09 13:22:54 -04002761 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002762 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2763 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2764 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002765 if (err)
2766 return err;
2767
Vivien Didelotacddbd22016-07-18 20:45:39 -04002768 /* Clear all the VTU and STU entries */
2769 err = _mv88e6xxx_vtu_stu_flush(chip);
2770 if (err < 0)
2771 return err;
2772
Vivien Didelot08a01262016-05-09 13:22:50 -04002773 /* Set the default address aging time to 5 minutes, and
2774 * enable address learn messages to be sent to all message
2775 * ports.
2776 */
Vivien Didelota935c052016-09-29 12:21:53 -04002777 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2778 GLOBAL_ATU_CONTROL_LEARN2ALL);
Vivien Didelot08a01262016-05-09 13:22:50 -04002779 if (err)
2780 return err;
2781
Vivien Didelotacddbd22016-07-18 20:45:39 -04002782 err = mv88e6xxx_g1_set_age_time(chip, 300000);
2783 if (err)
Vivien Didelot97299342016-07-18 20:45:30 -04002784 return err;
2785
2786 /* Clear all ATU entries */
2787 err = _mv88e6xxx_atu_flush(chip, 0, true);
2788 if (err)
2789 return err;
2790
Vivien Didelot08a01262016-05-09 13:22:50 -04002791 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002792 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002793 if (err)
2794 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002795 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002796 if (err)
2797 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002798 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002799 if (err)
2800 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002801 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002802 if (err)
2803 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002804 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002805 if (err)
2806 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002807 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002808 if (err)
2809 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002810 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002811 if (err)
2812 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002813 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002814 if (err)
2815 return err;
2816
2817 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002818 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002819 if (err)
2820 return err;
2821
Andrew Lunnde2273872016-11-21 23:27:01 +01002822 /* Initialize the statistics unit */
2823 err = mv88e6xxx_stats_set_histogram(chip);
2824 if (err)
2825 return err;
2826
Vivien Didelot97299342016-07-18 20:45:30 -04002827 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002828 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2829 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002830 if (err)
2831 return err;
2832
2833 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002834 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002835 if (err)
2836 return err;
2837
2838 return 0;
2839}
2840
Vivien Didelotf81ec902016-05-09 13:22:58 -04002841static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002842{
Vivien Didelot04bed142016-08-31 18:06:13 -04002843 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002844 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002845 int i;
2846
Vivien Didelotfad09c72016-06-21 12:28:20 -04002847 chip->ds = ds;
2848 ds->slave_mii_bus = chip->mdio_bus;
Vivien Didelot552238b2016-05-09 13:22:49 -04002849
Vivien Didelotfad09c72016-06-21 12:28:20 -04002850 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002851
Vivien Didelot97299342016-07-18 20:45:30 -04002852 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002853 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002854 err = mv88e6xxx_setup_port(chip, i);
2855 if (err)
2856 goto unlock;
2857 }
2858
2859 /* Setup Switch Global 1 Registers */
2860 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002861 if (err)
2862 goto unlock;
2863
Vivien Didelot97299342016-07-18 20:45:30 -04002864 /* Setup Switch Global 2 Registers */
2865 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2866 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002867 if (err)
2868 goto unlock;
2869 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002870
Andrew Lunn6e55f692016-12-03 04:45:16 +01002871 /* Some generations have the configuration of sending reserved
2872 * management frames to the CPU in global2, others in
2873 * global1. Hence it does not fit the two setup functions
2874 * above.
2875 */
2876 if (chip->info->ops->mgmt_rsvd2cpu) {
2877 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2878 if (err)
2879 goto unlock;
2880 }
2881
Vivien Didelot6b17e862015-08-13 12:52:18 -04002882unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002883 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002884
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002885 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002886}
2887
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002888static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2889{
Vivien Didelot04bed142016-08-31 18:06:13 -04002890 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002891 int err;
2892
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002893 if (!chip->info->ops->set_switch_mac)
2894 return -EOPNOTSUPP;
2895
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002896 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002897 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002898 mutex_unlock(&chip->reg_lock);
2899
2900 return err;
2901}
2902
Vivien Didelote57e5e72016-08-15 17:19:00 -04002903static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002904{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002905 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2906 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002907 u16 val;
2908 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002909
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002910 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002911 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002912
Andrew Lunnee26a222017-01-24 14:53:48 +01002913 if (!chip->info->ops->phy_read)
2914 return -EOPNOTSUPP;
2915
Vivien Didelotfad09c72016-06-21 12:28:20 -04002916 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002917 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002918 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002919
2920 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002921}
2922
Vivien Didelote57e5e72016-08-15 17:19:00 -04002923static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002924{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002925 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2926 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002927 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002928
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002929 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002930 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002931
Andrew Lunnee26a222017-01-24 14:53:48 +01002932 if (!chip->info->ops->phy_write)
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_write(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
2939 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002940}
2941
Vivien Didelotfad09c72016-06-21 12:28:20 -04002942static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunnb516d452016-06-04 21:17:06 +02002943 struct device_node *np)
2944{
2945 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002946 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002947 struct mii_bus *bus;
2948 int err;
2949
Andrew Lunnb516d452016-06-04 21:17:06 +02002950 if (np)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002951 chip->mdio_np = of_get_child_by_name(np, "mdio");
Andrew Lunnb516d452016-06-04 21:17:06 +02002952
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002953 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002954 if (!bus)
2955 return -ENOMEM;
2956
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002957 mdio_bus = bus->priv;
2958 mdio_bus->chip = chip;
2959
Andrew Lunnb516d452016-06-04 21:17:06 +02002960 if (np) {
2961 bus->name = np->full_name;
2962 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2963 } else {
2964 bus->name = "mv88e6xxx SMI";
2965 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2966 }
2967
2968 bus->read = mv88e6xxx_mdio_read;
2969 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002970 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002971
Vivien Didelotfad09c72016-06-21 12:28:20 -04002972 if (chip->mdio_np)
2973 err = of_mdiobus_register(bus, chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002974 else
2975 err = mdiobus_register(bus);
2976 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002977 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunnb516d452016-06-04 21:17:06 +02002978 goto out;
2979 }
Vivien Didelotfad09c72016-06-21 12:28:20 -04002980 chip->mdio_bus = bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002981
2982 return 0;
2983
2984out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002985 if (chip->mdio_np)
2986 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002987
2988 return err;
2989}
2990
Vivien Didelotfad09c72016-06-21 12:28:20 -04002991static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002992
2993{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002994 struct mii_bus *bus = chip->mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002995
2996 mdiobus_unregister(bus);
2997
Vivien Didelotfad09c72016-06-21 12:28:20 -04002998 if (chip->mdio_np)
2999 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003000}
3001
Vivien Didelot855b1932016-07-20 18:18:35 -04003002static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3003{
Vivien Didelot04bed142016-08-31 18:06:13 -04003004 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003005
3006 return chip->eeprom_len;
3007}
3008
Vivien Didelot855b1932016-07-20 18:18:35 -04003009static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3010 struct ethtool_eeprom *eeprom, u8 *data)
3011{
Vivien Didelot04bed142016-08-31 18:06:13 -04003012 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003013 int err;
3014
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003015 if (!chip->info->ops->get_eeprom)
3016 return -EOPNOTSUPP;
3017
Vivien Didelot855b1932016-07-20 18:18:35 -04003018 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003019 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003020 mutex_unlock(&chip->reg_lock);
3021
3022 if (err)
3023 return err;
3024
3025 eeprom->magic = 0xc3ec4951;
3026
3027 return 0;
3028}
3029
Vivien Didelot855b1932016-07-20 18:18:35 -04003030static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3031 struct ethtool_eeprom *eeprom, u8 *data)
3032{
Vivien Didelot04bed142016-08-31 18:06:13 -04003033 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003034 int err;
3035
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003036 if (!chip->info->ops->set_eeprom)
3037 return -EOPNOTSUPP;
3038
Vivien Didelot855b1932016-07-20 18:18:35 -04003039 if (eeprom->magic != 0xc3ec4951)
3040 return -EINVAL;
3041
3042 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003043 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003044 mutex_unlock(&chip->reg_lock);
3045
3046 return err;
3047}
3048
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003049static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003050 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003051 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003052 .phy_read = mv88e6xxx_phy_ppu_read,
3053 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003054 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003055 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003056 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003057 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003058 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3059 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3060 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003061 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003062 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003063 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003064 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3065 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003066 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003067 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3068 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003069 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003070 .ppu_enable = mv88e6185_g1_ppu_enable,
3071 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003072 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003073};
3074
3075static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003076 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003077 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003078 .phy_read = mv88e6xxx_phy_ppu_read,
3079 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003080 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003081 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003082 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003083 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3084 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003085 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003086 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3087 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003088 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003089 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003090 .ppu_enable = mv88e6185_g1_ppu_enable,
3091 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003092 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003093};
3094
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003095static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003096 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003097 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3098 .phy_read = mv88e6xxx_g2_smi_phy_read,
3099 .phy_write = mv88e6xxx_g2_smi_phy_write,
3100 .port_set_link = mv88e6xxx_port_set_link,
3101 .port_set_duplex = mv88e6xxx_port_set_duplex,
3102 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003103 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003104 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3105 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3106 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003107 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003108 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003109 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003110 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3111 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3112 .stats_get_strings = mv88e6095_stats_get_strings,
3113 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003114 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3115 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003116 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003117 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003118};
3119
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003120static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003121 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003122 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003123 .phy_read = mv88e6165_phy_read,
3124 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003125 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003126 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003127 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003128 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3129 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003130 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003131 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3132 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003133 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003134 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3135 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003136 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003137 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003138};
3139
3140static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003141 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003142 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003143 .phy_read = mv88e6xxx_phy_ppu_read,
3144 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003145 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003146 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003147 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003148 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003149 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3150 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3151 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003152 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003153 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003154 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003155 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003156 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3157 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003158 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003159 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3160 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003161 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003162 .ppu_enable = mv88e6185_g1_ppu_enable,
3163 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003164 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003165};
3166
3167static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003168 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003169 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003170 .phy_read = mv88e6165_phy_read,
3171 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003172 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003173 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003174 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003175 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003176 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3177 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3178 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003179 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003180 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003181 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003182 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003183 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3184 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003185 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003186 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3187 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003188 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003189 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003190};
3191
3192static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003193 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003194 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003195 .phy_read = mv88e6165_phy_read,
3196 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003197 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003198 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003199 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003200 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003201 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3202 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003203 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003204 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3205 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003206 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003207 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003208};
3209
3210static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003211 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003212 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003213 .phy_read = mv88e6xxx_g2_smi_phy_read,
3214 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003215 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003216 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003217 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003218 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003219 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003220 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3221 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3222 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003223 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003224 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003225 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003226 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003227 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3228 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003229 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003230 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3231 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003232 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003233 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003234};
3235
3236static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003237 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003238 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3239 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003240 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003241 .phy_read = mv88e6xxx_g2_smi_phy_read,
3242 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003243 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003244 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003245 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003246 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003247 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003248 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3249 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3250 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003251 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003252 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003253 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003254 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003255 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3256 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003257 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003258 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3259 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003260 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003261 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003262};
3263
3264static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003265 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003266 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003267 .phy_read = mv88e6xxx_g2_smi_phy_read,
3268 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003269 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003270 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003271 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003272 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003273 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003274 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3275 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3276 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003277 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003278 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003279 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003280 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003281 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3282 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003283 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003284 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3285 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003286 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003287 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003288};
3289
3290static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003291 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003292 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3293 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003294 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003295 .phy_read = mv88e6xxx_g2_smi_phy_read,
3296 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003297 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003298 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003299 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003300 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003301 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003302 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3303 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3304 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003305 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003306 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003307 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003308 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003309 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3310 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003311 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003312 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3313 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003314 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003315 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003316};
3317
3318static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003319 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003320 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003321 .phy_read = mv88e6xxx_phy_ppu_read,
3322 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003323 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003324 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003325 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003326 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3327 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003328 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003329 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003330 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3331 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003332 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003333 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3334 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003335 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003336 .ppu_enable = mv88e6185_g1_ppu_enable,
3337 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003338 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003339};
3340
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003341static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003342 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003343 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3344 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003345 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3346 .phy_read = mv88e6xxx_g2_smi_phy_read,
3347 .phy_write = mv88e6xxx_g2_smi_phy_write,
3348 .port_set_link = mv88e6xxx_port_set_link,
3349 .port_set_duplex = mv88e6xxx_port_set_duplex,
3350 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3351 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003352 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003353 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3354 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3355 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003356 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003357 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003358 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003359 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3360 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003361 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003362 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3363 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003364 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003365 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003366};
3367
3368static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003369 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003370 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3371 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003372 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3373 .phy_read = mv88e6xxx_g2_smi_phy_read,
3374 .phy_write = mv88e6xxx_g2_smi_phy_write,
3375 .port_set_link = mv88e6xxx_port_set_link,
3376 .port_set_duplex = mv88e6xxx_port_set_duplex,
3377 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3378 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003379 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003380 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3381 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3382 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003383 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003384 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003385 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003386 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3387 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003388 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003389 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3390 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003391 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003392 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003393};
3394
3395static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003396 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003397 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3398 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003399 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3400 .phy_read = mv88e6xxx_g2_smi_phy_read,
3401 .phy_write = mv88e6xxx_g2_smi_phy_write,
3402 .port_set_link = mv88e6xxx_port_set_link,
3403 .port_set_duplex = mv88e6xxx_port_set_duplex,
3404 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3405 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003406 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003407 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3408 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3409 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003410 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003411 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003412 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003413 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3414 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003415 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003416 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3417 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003418 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003419 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003420};
3421
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003422static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003423 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003424 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3425 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003426 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003427 .phy_read = mv88e6xxx_g2_smi_phy_read,
3428 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003429 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003430 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003431 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003432 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003433 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003434 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3435 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3436 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003437 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003438 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003439 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003440 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003441 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3442 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003443 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003444 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3445 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003446 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003447 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003448};
3449
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003450static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003451 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003452 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3453 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003454 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3455 .phy_read = mv88e6xxx_g2_smi_phy_read,
3456 .phy_write = mv88e6xxx_g2_smi_phy_write,
3457 .port_set_link = mv88e6xxx_port_set_link,
3458 .port_set_duplex = mv88e6xxx_port_set_duplex,
3459 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3460 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003461 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003462 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3463 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3464 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003465 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003466 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003467 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003468 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3469 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003470 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003471 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3472 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003473 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003474 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003475};
3476
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003477static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003478 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003479 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3480 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003481 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003482 .phy_read = mv88e6xxx_g2_smi_phy_read,
3483 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003484 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003485 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003486 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003487 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003488 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3489 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3490 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003491 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003492 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003493 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003494 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003495 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3496 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003497 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003498 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3499 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003500 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003501 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003502};
3503
3504static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003505 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003506 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3507 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003508 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003509 .phy_read = mv88e6xxx_g2_smi_phy_read,
3510 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003511 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003512 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003513 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003514 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003515 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3516 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3517 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003518 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003519 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003520 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003521 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003522 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3523 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003524 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003525 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3526 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003527 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003528};
3529
3530static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003531 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003532 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003533 .phy_read = mv88e6xxx_g2_smi_phy_read,
3534 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003535 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003536 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003537 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003538 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003539 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003540 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3541 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3542 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003543 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003544 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003545 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003546 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003547 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3548 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003549 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003550 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3551 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003552 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003553 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003554};
3555
3556static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003557 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003558 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003559 .phy_read = mv88e6xxx_g2_smi_phy_read,
3560 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003561 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003562 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003563 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003564 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003565 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003566 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3567 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3568 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003569 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003570 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003571 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003572 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003573 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3574 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003575 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003576 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3577 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003578 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003579 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003580};
3581
3582static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003583 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003584 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3585 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003586 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003587 .phy_read = mv88e6xxx_g2_smi_phy_read,
3588 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003589 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003590 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003591 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003592 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003593 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003594 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3595 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3596 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003597 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003598 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003599 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003600 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003601 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3602 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003603 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003604 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3605 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003606 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003607 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003608};
3609
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003610static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003611 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003612 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3613 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003614 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3615 .phy_read = mv88e6xxx_g2_smi_phy_read,
3616 .phy_write = mv88e6xxx_g2_smi_phy_write,
3617 .port_set_link = mv88e6xxx_port_set_link,
3618 .port_set_duplex = mv88e6xxx_port_set_duplex,
3619 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3620 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003621 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003622 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3623 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3624 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003625 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003626 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003627 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003628 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003629 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003630 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3631 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003632 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003633 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3634 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003635 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003636 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003637};
3638
3639static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003640 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003641 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3642 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003643 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3644 .phy_read = mv88e6xxx_g2_smi_phy_read,
3645 .phy_write = mv88e6xxx_g2_smi_phy_write,
3646 .port_set_link = mv88e6xxx_port_set_link,
3647 .port_set_duplex = mv88e6xxx_port_set_duplex,
3648 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3649 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003650 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003651 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3652 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3653 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003654 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003655 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003656 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003657 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003658 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003659 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3660 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003661 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003662 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3663 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003664 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003665 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003666};
3667
3668static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003669 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003670 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3671 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003672 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3673 .phy_read = mv88e6xxx_g2_smi_phy_read,
3674 .phy_write = mv88e6xxx_g2_smi_phy_write,
3675 .port_set_link = mv88e6xxx_port_set_link,
3676 .port_set_duplex = mv88e6xxx_port_set_duplex,
3677 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3678 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003679 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003680 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3681 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3682 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003683 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003684 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003685 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003686 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3687 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003688 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003689 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3690 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003691 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003692 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003693};
3694
Andrew Lunn56995cb2016-12-03 04:35:19 +01003695static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3696 const struct mv88e6xxx_ops *ops)
3697{
3698 if (!ops->port_set_frame_mode) {
3699 dev_err(chip->dev, "Missing port_set_frame_mode");
3700 return -EINVAL;
3701 }
3702
3703 if (!ops->port_set_egress_unknowns) {
3704 dev_err(chip->dev, "Missing port_set_egress_mode");
3705 return -EINVAL;
3706 }
3707
3708 return 0;
3709}
3710
Vivien Didelotf81ec902016-05-09 13:22:58 -04003711static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3712 [MV88E6085] = {
3713 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3714 .family = MV88E6XXX_FAMILY_6097,
3715 .name = "Marvell 88E6085",
3716 .num_databases = 4096,
3717 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003718 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003719 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003720 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003721 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003722 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003723 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003724 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003725 },
3726
3727 [MV88E6095] = {
3728 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3729 .family = MV88E6XXX_FAMILY_6095,
3730 .name = "Marvell 88E6095/88E6095F",
3731 .num_databases = 256,
3732 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003733 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003734 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003735 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003736 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003737 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003738 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003739 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003740 },
3741
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003742 [MV88E6097] = {
3743 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3744 .family = MV88E6XXX_FAMILY_6097,
3745 .name = "Marvell 88E6097/88E6097F",
3746 .num_databases = 4096,
3747 .num_ports = 11,
3748 .port_base_addr = 0x10,
3749 .global1_addr = 0x1b,
3750 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003751 .g1_irqs = 8,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003752 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003753 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3754 .ops = &mv88e6097_ops,
3755 },
3756
Vivien Didelotf81ec902016-05-09 13:22:58 -04003757 [MV88E6123] = {
3758 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3759 .family = MV88E6XXX_FAMILY_6165,
3760 .name = "Marvell 88E6123",
3761 .num_databases = 4096,
3762 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003763 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003764 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003765 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003766 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003767 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003768 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003769 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003770 },
3771
3772 [MV88E6131] = {
3773 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3774 .family = MV88E6XXX_FAMILY_6185,
3775 .name = "Marvell 88E6131",
3776 .num_databases = 256,
3777 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003778 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003779 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003780 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003781 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003782 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003783 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003784 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003785 },
3786
3787 [MV88E6161] = {
3788 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3789 .family = MV88E6XXX_FAMILY_6165,
3790 .name = "Marvell 88E6161",
3791 .num_databases = 4096,
3792 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003793 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003794 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003795 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003796 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003797 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003798 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003799 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003800 },
3801
3802 [MV88E6165] = {
3803 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3804 .family = MV88E6XXX_FAMILY_6165,
3805 .name = "Marvell 88E6165",
3806 .num_databases = 4096,
3807 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003808 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003809 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003810 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003811 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003812 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003813 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003814 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003815 },
3816
3817 [MV88E6171] = {
3818 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3819 .family = MV88E6XXX_FAMILY_6351,
3820 .name = "Marvell 88E6171",
3821 .num_databases = 4096,
3822 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003823 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003824 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003825 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003826 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003827 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003828 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003829 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003830 },
3831
3832 [MV88E6172] = {
3833 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3834 .family = MV88E6XXX_FAMILY_6352,
3835 .name = "Marvell 88E6172",
3836 .num_databases = 4096,
3837 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003838 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003839 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003840 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003841 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003842 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003843 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003844 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003845 },
3846
3847 [MV88E6175] = {
3848 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3849 .family = MV88E6XXX_FAMILY_6351,
3850 .name = "Marvell 88E6175",
3851 .num_databases = 4096,
3852 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003853 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003854 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003855 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003856 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003857 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003858 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003859 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003860 },
3861
3862 [MV88E6176] = {
3863 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3864 .family = MV88E6XXX_FAMILY_6352,
3865 .name = "Marvell 88E6176",
3866 .num_databases = 4096,
3867 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003868 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003869 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003870 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003871 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003872 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003873 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003874 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003875 },
3876
3877 [MV88E6185] = {
3878 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3879 .family = MV88E6XXX_FAMILY_6185,
3880 .name = "Marvell 88E6185",
3881 .num_databases = 256,
3882 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003883 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003884 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003885 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003886 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003887 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003888 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003889 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003890 },
3891
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003892 [MV88E6190] = {
3893 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3894 .family = MV88E6XXX_FAMILY_6390,
3895 .name = "Marvell 88E6190",
3896 .num_databases = 4096,
3897 .num_ports = 11, /* 10 + Z80 */
3898 .port_base_addr = 0x0,
3899 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003900 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003901 .age_time_coeff = 15000,
3902 .g1_irqs = 9,
3903 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3904 .ops = &mv88e6190_ops,
3905 },
3906
3907 [MV88E6190X] = {
3908 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3909 .family = MV88E6XXX_FAMILY_6390,
3910 .name = "Marvell 88E6190X",
3911 .num_databases = 4096,
3912 .num_ports = 11, /* 10 + Z80 */
3913 .port_base_addr = 0x0,
3914 .global1_addr = 0x1b,
3915 .age_time_coeff = 15000,
3916 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003917 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003918 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3919 .ops = &mv88e6190x_ops,
3920 },
3921
3922 [MV88E6191] = {
3923 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3924 .family = MV88E6XXX_FAMILY_6390,
3925 .name = "Marvell 88E6191",
3926 .num_databases = 4096,
3927 .num_ports = 11, /* 10 + Z80 */
3928 .port_base_addr = 0x0,
3929 .global1_addr = 0x1b,
3930 .age_time_coeff = 15000,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003931 .g1_irqs = 9,
3932 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003933 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3934 .ops = &mv88e6391_ops,
3935 },
3936
Vivien Didelotf81ec902016-05-09 13:22:58 -04003937 [MV88E6240] = {
3938 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3939 .family = MV88E6XXX_FAMILY_6352,
3940 .name = "Marvell 88E6240",
3941 .num_databases = 4096,
3942 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003943 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003944 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003945 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003946 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003947 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003948 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003949 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003950 },
3951
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003952 [MV88E6290] = {
3953 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3954 .family = MV88E6XXX_FAMILY_6390,
3955 .name = "Marvell 88E6290",
3956 .num_databases = 4096,
3957 .num_ports = 11, /* 10 + Z80 */
3958 .port_base_addr = 0x0,
3959 .global1_addr = 0x1b,
3960 .age_time_coeff = 15000,
3961 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003962 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003963 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3964 .ops = &mv88e6290_ops,
3965 },
3966
Vivien Didelotf81ec902016-05-09 13:22:58 -04003967 [MV88E6320] = {
3968 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3969 .family = MV88E6XXX_FAMILY_6320,
3970 .name = "Marvell 88E6320",
3971 .num_databases = 4096,
3972 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003973 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003974 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003975 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003976 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003977 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003978 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003979 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003980 },
3981
3982 [MV88E6321] = {
3983 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3984 .family = MV88E6XXX_FAMILY_6320,
3985 .name = "Marvell 88E6321",
3986 .num_databases = 4096,
3987 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003988 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003989 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003990 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003991 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003992 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003993 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003994 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003995 },
3996
3997 [MV88E6350] = {
3998 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3999 .family = MV88E6XXX_FAMILY_6351,
4000 .name = "Marvell 88E6350",
4001 .num_databases = 4096,
4002 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004003 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004004 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004005 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004006 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004007 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004008 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004009 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004010 },
4011
4012 [MV88E6351] = {
4013 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4014 .family = MV88E6XXX_FAMILY_6351,
4015 .name = "Marvell 88E6351",
4016 .num_databases = 4096,
4017 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004018 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004019 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004020 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004021 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004022 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004023 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004024 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004025 },
4026
4027 [MV88E6352] = {
4028 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4029 .family = MV88E6XXX_FAMILY_6352,
4030 .name = "Marvell 88E6352",
4031 .num_databases = 4096,
4032 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004033 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004034 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004035 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004036 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004037 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004038 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004039 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004040 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004041 [MV88E6390] = {
4042 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4043 .family = MV88E6XXX_FAMILY_6390,
4044 .name = "Marvell 88E6390",
4045 .num_databases = 4096,
4046 .num_ports = 11, /* 10 + Z80 */
4047 .port_base_addr = 0x0,
4048 .global1_addr = 0x1b,
4049 .age_time_coeff = 15000,
4050 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004051 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004052 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4053 .ops = &mv88e6390_ops,
4054 },
4055 [MV88E6390X] = {
4056 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4057 .family = MV88E6XXX_FAMILY_6390,
4058 .name = "Marvell 88E6390X",
4059 .num_databases = 4096,
4060 .num_ports = 11, /* 10 + Z80 */
4061 .port_base_addr = 0x0,
4062 .global1_addr = 0x1b,
4063 .age_time_coeff = 15000,
4064 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004065 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004066 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4067 .ops = &mv88e6390x_ops,
4068 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004069};
4070
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004071static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004072{
Vivien Didelota439c062016-04-17 13:23:58 -04004073 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004074
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004075 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4076 if (mv88e6xxx_table[i].prod_num == prod_num)
4077 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004078
Vivien Didelotb9b37712015-10-30 19:39:48 -04004079 return NULL;
4080}
4081
Vivien Didelotfad09c72016-06-21 12:28:20 -04004082static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004083{
4084 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004085 unsigned int prod_num, rev;
4086 u16 id;
4087 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004088
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004089 mutex_lock(&chip->reg_lock);
4090 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4091 mutex_unlock(&chip->reg_lock);
4092 if (err)
4093 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004094
4095 prod_num = (id & 0xfff0) >> 4;
4096 rev = id & 0x000f;
4097
4098 info = mv88e6xxx_lookup_info(prod_num);
4099 if (!info)
4100 return -ENODEV;
4101
Vivien Didelotcaac8542016-06-20 13:14:09 -04004102 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004103 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004104
Vivien Didelotca070c12016-09-02 14:45:34 -04004105 err = mv88e6xxx_g2_require(chip);
4106 if (err)
4107 return err;
4108
Vivien Didelotfad09c72016-06-21 12:28:20 -04004109 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4110 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004111
4112 return 0;
4113}
4114
Vivien Didelotfad09c72016-06-21 12:28:20 -04004115static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004116{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004117 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004118
Vivien Didelotfad09c72016-06-21 12:28:20 -04004119 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4120 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004121 return NULL;
4122
Vivien Didelotfad09c72016-06-21 12:28:20 -04004123 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004124
Vivien Didelotfad09c72016-06-21 12:28:20 -04004125 mutex_init(&chip->reg_lock);
Vivien Didelot469d7292016-06-20 13:14:06 -04004126
Vivien Didelotfad09c72016-06-21 12:28:20 -04004127 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004128}
4129
Vivien Didelote57e5e72016-08-15 17:19:00 -04004130static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4131{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004132 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004133 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004134}
4135
Andrew Lunn930188c2016-08-22 16:01:03 +02004136static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4137{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004138 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004139 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004140}
4141
Vivien Didelotfad09c72016-06-21 12:28:20 -04004142static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004143 struct mii_bus *bus, int sw_addr)
4144{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004145 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004146 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004147 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004148 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004149 else
4150 return -EINVAL;
4151
Vivien Didelotfad09c72016-06-21 12:28:20 -04004152 chip->bus = bus;
4153 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004154
4155 return 0;
4156}
4157
Andrew Lunn7b314362016-08-22 16:01:01 +02004158static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4159{
Vivien Didelot04bed142016-08-31 18:06:13 -04004160 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004161
Andrew Lunn443d5a12016-12-03 04:35:18 +01004162 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004163}
4164
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004165static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4166 struct device *host_dev, int sw_addr,
4167 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004168{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004169 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004170 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004171 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004172
Vivien Didelota439c062016-04-17 13:23:58 -04004173 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004174 if (!bus)
4175 return NULL;
4176
Vivien Didelotfad09c72016-06-21 12:28:20 -04004177 chip = mv88e6xxx_alloc_chip(dsa_dev);
4178 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004179 return NULL;
4180
Vivien Didelotcaac8542016-06-20 13:14:09 -04004181 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004182 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004183
Vivien Didelotfad09c72016-06-21 12:28:20 -04004184 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004185 if (err)
4186 goto free;
4187
Vivien Didelotfad09c72016-06-21 12:28:20 -04004188 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004189 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004190 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004191
Andrew Lunndc30c352016-10-16 19:56:49 +02004192 mutex_lock(&chip->reg_lock);
4193 err = mv88e6xxx_switch_reset(chip);
4194 mutex_unlock(&chip->reg_lock);
4195 if (err)
4196 goto free;
4197
Vivien Didelote57e5e72016-08-15 17:19:00 -04004198 mv88e6xxx_phy_init(chip);
4199
Vivien Didelotfad09c72016-06-21 12:28:20 -04004200 err = mv88e6xxx_mdio_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004201 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004202 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004203
Vivien Didelotfad09c72016-06-21 12:28:20 -04004204 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004205
Vivien Didelotfad09c72016-06-21 12:28:20 -04004206 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004207free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004208 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004209
4210 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004211}
4212
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004213static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4214 const struct switchdev_obj_port_mdb *mdb,
4215 struct switchdev_trans *trans)
4216{
4217 /* We don't need any dynamic resource from the kernel (yet),
4218 * so skip the prepare phase.
4219 */
4220
4221 return 0;
4222}
4223
4224static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4225 const struct switchdev_obj_port_mdb *mdb,
4226 struct switchdev_trans *trans)
4227{
Vivien Didelot04bed142016-08-31 18:06:13 -04004228 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004229
4230 mutex_lock(&chip->reg_lock);
4231 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4232 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4233 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4234 mutex_unlock(&chip->reg_lock);
4235}
4236
4237static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4238 const struct switchdev_obj_port_mdb *mdb)
4239{
Vivien Didelot04bed142016-08-31 18:06:13 -04004240 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004241 int err;
4242
4243 mutex_lock(&chip->reg_lock);
4244 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4245 GLOBAL_ATU_DATA_STATE_UNUSED);
4246 mutex_unlock(&chip->reg_lock);
4247
4248 return err;
4249}
4250
4251static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4252 struct switchdev_obj_port_mdb *mdb,
4253 int (*cb)(struct switchdev_obj *obj))
4254{
Vivien Didelot04bed142016-08-31 18:06:13 -04004255 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004256 int err;
4257
4258 mutex_lock(&chip->reg_lock);
4259 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4260 mutex_unlock(&chip->reg_lock);
4261
4262 return err;
4263}
4264
Florian Fainellia82f67a2017-01-08 14:52:08 -08004265static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004266 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004267 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004268 .setup = mv88e6xxx_setup,
4269 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004270 .adjust_link = mv88e6xxx_adjust_link,
4271 .get_strings = mv88e6xxx_get_strings,
4272 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4273 .get_sset_count = mv88e6xxx_get_sset_count,
4274 .set_eee = mv88e6xxx_set_eee,
4275 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004276 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004277 .get_eeprom = mv88e6xxx_get_eeprom,
4278 .set_eeprom = mv88e6xxx_set_eeprom,
4279 .get_regs_len = mv88e6xxx_get_regs_len,
4280 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004281 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004282 .port_bridge_join = mv88e6xxx_port_bridge_join,
4283 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4284 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004285 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004286 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4287 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4288 .port_vlan_add = mv88e6xxx_port_vlan_add,
4289 .port_vlan_del = mv88e6xxx_port_vlan_del,
4290 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4291 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4292 .port_fdb_add = mv88e6xxx_port_fdb_add,
4293 .port_fdb_del = mv88e6xxx_port_fdb_del,
4294 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004295 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4296 .port_mdb_add = mv88e6xxx_port_mdb_add,
4297 .port_mdb_del = mv88e6xxx_port_mdb_del,
4298 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004299};
4300
Florian Fainelliab3d4082017-01-08 14:52:07 -08004301static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4302 .ops = &mv88e6xxx_switch_ops,
4303};
4304
Vivien Didelotfad09c72016-06-21 12:28:20 -04004305static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004306 struct device_node *np)
4307{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004308 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004309 struct dsa_switch *ds;
4310
4311 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
4312 if (!ds)
4313 return -ENOMEM;
4314
4315 ds->dev = dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004316 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004317 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004318
4319 dev_set_drvdata(dev, ds);
4320
4321 return dsa_register_switch(ds, np);
4322}
4323
Vivien Didelotfad09c72016-06-21 12:28:20 -04004324static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004325{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004326 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004327}
4328
Vivien Didelot57d32312016-06-20 13:13:58 -04004329static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004330{
4331 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004332 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004333 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004334 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004335 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004336 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004337
Vivien Didelotcaac8542016-06-20 13:14:09 -04004338 compat_info = of_device_get_match_data(dev);
4339 if (!compat_info)
4340 return -EINVAL;
4341
Vivien Didelotfad09c72016-06-21 12:28:20 -04004342 chip = mv88e6xxx_alloc_chip(dev);
4343 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004344 return -ENOMEM;
4345
Vivien Didelotfad09c72016-06-21 12:28:20 -04004346 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004347
Andrew Lunn56995cb2016-12-03 04:35:19 +01004348 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4349 if (err)
4350 return err;
4351
Vivien Didelotfad09c72016-06-21 12:28:20 -04004352 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004353 if (err)
4354 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004355
Andrew Lunnb4308f02016-11-21 23:26:55 +01004356 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4357 if (IS_ERR(chip->reset))
4358 return PTR_ERR(chip->reset);
4359
Vivien Didelotfad09c72016-06-21 12:28:20 -04004360 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004361 if (err)
4362 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004363
Vivien Didelote57e5e72016-08-15 17:19:00 -04004364 mv88e6xxx_phy_init(chip);
4365
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004366 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004367 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004368 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004369
Andrew Lunndc30c352016-10-16 19:56:49 +02004370 mutex_lock(&chip->reg_lock);
4371 err = mv88e6xxx_switch_reset(chip);
4372 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004373 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004374 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004375
Andrew Lunndc30c352016-10-16 19:56:49 +02004376 chip->irq = of_irq_get(np, 0);
4377 if (chip->irq == -EPROBE_DEFER) {
4378 err = chip->irq;
4379 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004380 }
4381
Andrew Lunndc30c352016-10-16 19:56:49 +02004382 if (chip->irq > 0) {
4383 /* Has to be performed before the MDIO bus is created,
4384 * because the PHYs will link there interrupts to these
4385 * interrupt controllers
4386 */
4387 mutex_lock(&chip->reg_lock);
4388 err = mv88e6xxx_g1_irq_setup(chip);
4389 mutex_unlock(&chip->reg_lock);
4390
4391 if (err)
4392 goto out;
4393
4394 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4395 err = mv88e6xxx_g2_irq_setup(chip);
4396 if (err)
4397 goto out_g1_irq;
4398 }
4399 }
4400
4401 err = mv88e6xxx_mdio_register(chip, np);
4402 if (err)
4403 goto out_g2_irq;
4404
4405 err = mv88e6xxx_register_switch(chip, np);
4406 if (err)
4407 goto out_mdio;
4408
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004409 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004410
4411out_mdio:
4412 mv88e6xxx_mdio_unregister(chip);
4413out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004414 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004415 mv88e6xxx_g2_irq_free(chip);
4416out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004417 if (chip->irq > 0) {
4418 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004419 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004420 mutex_unlock(&chip->reg_lock);
4421 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004422out:
4423 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004424}
4425
4426static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4427{
4428 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004429 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004430
Andrew Lunn930188c2016-08-22 16:01:03 +02004431 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004432 mv88e6xxx_unregister_switch(chip);
4433 mv88e6xxx_mdio_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004434
Andrew Lunn467126442016-11-20 20:14:15 +01004435 if (chip->irq > 0) {
4436 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4437 mv88e6xxx_g2_irq_free(chip);
4438 mv88e6xxx_g1_irq_free(chip);
4439 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004440}
4441
4442static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004443 {
4444 .compatible = "marvell,mv88e6085",
4445 .data = &mv88e6xxx_table[MV88E6085],
4446 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004447 {
4448 .compatible = "marvell,mv88e6190",
4449 .data = &mv88e6xxx_table[MV88E6190],
4450 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004451 { /* sentinel */ },
4452};
4453
4454MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4455
4456static struct mdio_driver mv88e6xxx_driver = {
4457 .probe = mv88e6xxx_probe,
4458 .remove = mv88e6xxx_remove,
4459 .mdiodrv.driver = {
4460 .name = "mv88e6085",
4461 .of_match_table = mv88e6xxx_of_match,
4462 },
4463};
4464
Ben Hutchings98e67302011-11-25 14:36:19 +00004465static int __init mv88e6xxx_init(void)
4466{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004467 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004468 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004469}
4470module_init(mv88e6xxx_init);
4471
4472static void __exit mv88e6xxx_cleanup(void)
4473{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004474 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004475 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004476}
4477module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004478
4479MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4480MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4481MODULE_LICENSE("GPL");