blob: dedccf201452d74386a19ce123ec635cbe553b5e [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{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002905 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002906 u16 val;
2907 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002908
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002909 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002910 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002911
Andrew Lunnee26a222017-01-24 14:53:48 +01002912 if (!chip->info->ops->phy_read)
2913 return -EOPNOTSUPP;
2914
Vivien Didelotfad09c72016-06-21 12:28:20 -04002915 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002916 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002917 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002918
2919 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002920}
2921
Vivien Didelote57e5e72016-08-15 17:19:00 -04002922static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002923{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002924 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002925 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002926
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002927 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002928 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002929
Andrew Lunnee26a222017-01-24 14:53:48 +01002930 if (!chip->info->ops->phy_write)
2931 return -EOPNOTSUPP;
2932
Vivien Didelotfad09c72016-06-21 12:28:20 -04002933 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002934 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002935 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002936
2937 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002938}
2939
Vivien Didelotfad09c72016-06-21 12:28:20 -04002940static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunnb516d452016-06-04 21:17:06 +02002941 struct device_node *np)
2942{
2943 static int index;
2944 struct mii_bus *bus;
2945 int err;
2946
Andrew Lunnb516d452016-06-04 21:17:06 +02002947 if (np)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002948 chip->mdio_np = of_get_child_by_name(np, "mdio");
Andrew Lunnb516d452016-06-04 21:17:06 +02002949
Vivien Didelotfad09c72016-06-21 12:28:20 -04002950 bus = devm_mdiobus_alloc(chip->dev);
Andrew Lunnb516d452016-06-04 21:17:06 +02002951 if (!bus)
2952 return -ENOMEM;
2953
Vivien Didelotfad09c72016-06-21 12:28:20 -04002954 bus->priv = (void *)chip;
Andrew Lunnb516d452016-06-04 21:17:06 +02002955 if (np) {
2956 bus->name = np->full_name;
2957 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2958 } else {
2959 bus->name = "mv88e6xxx SMI";
2960 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2961 }
2962
2963 bus->read = mv88e6xxx_mdio_read;
2964 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002965 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002966
Vivien Didelotfad09c72016-06-21 12:28:20 -04002967 if (chip->mdio_np)
2968 err = of_mdiobus_register(bus, chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002969 else
2970 err = mdiobus_register(bus);
2971 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002972 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunnb516d452016-06-04 21:17:06 +02002973 goto out;
2974 }
Vivien Didelotfad09c72016-06-21 12:28:20 -04002975 chip->mdio_bus = bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002976
2977 return 0;
2978
2979out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002980 if (chip->mdio_np)
2981 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002982
2983 return err;
2984}
2985
Vivien Didelotfad09c72016-06-21 12:28:20 -04002986static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002987
2988{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002989 struct mii_bus *bus = chip->mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002990
2991 mdiobus_unregister(bus);
2992
Vivien Didelotfad09c72016-06-21 12:28:20 -04002993 if (chip->mdio_np)
2994 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002995}
2996
Vivien Didelot855b1932016-07-20 18:18:35 -04002997static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2998{
Vivien Didelot04bed142016-08-31 18:06:13 -04002999 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003000
3001 return chip->eeprom_len;
3002}
3003
Vivien Didelot855b1932016-07-20 18:18:35 -04003004static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3005 struct ethtool_eeprom *eeprom, u8 *data)
3006{
Vivien Didelot04bed142016-08-31 18:06:13 -04003007 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003008 int err;
3009
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003010 if (!chip->info->ops->get_eeprom)
3011 return -EOPNOTSUPP;
3012
Vivien Didelot855b1932016-07-20 18:18:35 -04003013 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003014 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003015 mutex_unlock(&chip->reg_lock);
3016
3017 if (err)
3018 return err;
3019
3020 eeprom->magic = 0xc3ec4951;
3021
3022 return 0;
3023}
3024
Vivien Didelot855b1932016-07-20 18:18:35 -04003025static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3026 struct ethtool_eeprom *eeprom, u8 *data)
3027{
Vivien Didelot04bed142016-08-31 18:06:13 -04003028 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003029 int err;
3030
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003031 if (!chip->info->ops->set_eeprom)
3032 return -EOPNOTSUPP;
3033
Vivien Didelot855b1932016-07-20 18:18:35 -04003034 if (eeprom->magic != 0xc3ec4951)
3035 return -EINVAL;
3036
3037 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003038 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003039 mutex_unlock(&chip->reg_lock);
3040
3041 return err;
3042}
3043
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003044static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003045 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003046 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003047 .phy_read = mv88e6xxx_phy_ppu_read,
3048 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003049 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003050 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003051 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003052 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003053 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3054 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3055 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003056 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003057 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003058 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003059 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3060 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003061 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003062 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3063 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003064 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003065 .ppu_enable = mv88e6185_g1_ppu_enable,
3066 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003067 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003068};
3069
3070static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003071 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003072 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003073 .phy_read = mv88e6xxx_phy_ppu_read,
3074 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003075 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003076 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003077 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003078 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3079 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003080 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003081 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3082 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003083 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003084 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003085 .ppu_enable = mv88e6185_g1_ppu_enable,
3086 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003087 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003088};
3089
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003090static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003091 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003092 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3093 .phy_read = mv88e6xxx_g2_smi_phy_read,
3094 .phy_write = mv88e6xxx_g2_smi_phy_write,
3095 .port_set_link = mv88e6xxx_port_set_link,
3096 .port_set_duplex = mv88e6xxx_port_set_duplex,
3097 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003098 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003099 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3100 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3101 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003102 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003103 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003104 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003105 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3106 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3107 .stats_get_strings = mv88e6095_stats_get_strings,
3108 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003109 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3110 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003111 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003112 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003113};
3114
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003115static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003116 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003117 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003118 .phy_read = mv88e6165_phy_read,
3119 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003120 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003121 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003122 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003123 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3124 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003125 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003126 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3127 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003128 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003129 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3130 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003131 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003132 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003133};
3134
3135static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003136 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003137 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003138 .phy_read = mv88e6xxx_phy_ppu_read,
3139 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003140 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003141 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003142 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003143 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003144 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3145 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3146 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003147 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003148 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003149 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003150 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003151 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3152 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003153 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003154 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3155 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003156 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003157 .ppu_enable = mv88e6185_g1_ppu_enable,
3158 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003159 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003160};
3161
3162static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003163 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003164 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003165 .phy_read = mv88e6165_phy_read,
3166 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003167 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003168 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003169 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003170 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003171 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3172 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3173 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003174 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003175 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003176 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003177 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003178 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3179 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003180 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003181 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3182 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003183 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003184 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003185};
3186
3187static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003188 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003189 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003190 .phy_read = mv88e6165_phy_read,
3191 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003192 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003193 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003194 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003195 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003196 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3197 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003198 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003199 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3200 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003201 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003202 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003203};
3204
3205static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003206 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003207 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003208 .phy_read = mv88e6xxx_g2_smi_phy_read,
3209 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003210 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003211 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003212 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003213 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003214 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003215 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3216 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3217 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003218 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003219 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003220 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003221 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003222 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3223 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003224 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003225 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3226 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003227 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003228 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003229};
3230
3231static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003232 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003233 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3234 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003235 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003236 .phy_read = mv88e6xxx_g2_smi_phy_read,
3237 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003238 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003239 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003240 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003241 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003242 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003243 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3244 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3245 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003246 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003247 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003248 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003249 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003250 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3251 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003252 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003253 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3254 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003255 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003256 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003257};
3258
3259static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003260 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003261 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003262 .phy_read = mv88e6xxx_g2_smi_phy_read,
3263 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003264 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003265 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003266 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003267 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003268 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003269 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3270 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3271 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003272 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003273 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003274 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003275 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003276 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3277 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003278 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003279 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3280 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003281 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003282 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003283};
3284
3285static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003286 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003287 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3288 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003289 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003290 .phy_read = mv88e6xxx_g2_smi_phy_read,
3291 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003292 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003293 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003294 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003295 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003296 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003297 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3298 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3299 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003300 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003301 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003302 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003303 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003304 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3305 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003306 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003307 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3308 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003309 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003310 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003311};
3312
3313static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003314 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003315 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003316 .phy_read = mv88e6xxx_phy_ppu_read,
3317 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003318 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003319 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003320 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003321 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3322 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003323 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003324 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003325 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3326 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003327 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003328 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3329 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003330 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003331 .ppu_enable = mv88e6185_g1_ppu_enable,
3332 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003333 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003334};
3335
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003336static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003337 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003338 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3339 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003340 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3341 .phy_read = mv88e6xxx_g2_smi_phy_read,
3342 .phy_write = mv88e6xxx_g2_smi_phy_write,
3343 .port_set_link = mv88e6xxx_port_set_link,
3344 .port_set_duplex = mv88e6xxx_port_set_duplex,
3345 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3346 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003347 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003348 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3349 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3350 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003351 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003352 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003353 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003354 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3355 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003356 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003357 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3358 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003359 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003360 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003361};
3362
3363static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003364 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003365 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3366 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003367 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3368 .phy_read = mv88e6xxx_g2_smi_phy_read,
3369 .phy_write = mv88e6xxx_g2_smi_phy_write,
3370 .port_set_link = mv88e6xxx_port_set_link,
3371 .port_set_duplex = mv88e6xxx_port_set_duplex,
3372 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3373 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003374 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003375 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3376 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3377 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003378 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003379 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003380 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003381 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3382 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003383 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003384 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3385 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003386 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003387 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003388};
3389
3390static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003391 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003392 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3393 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003394 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3395 .phy_read = mv88e6xxx_g2_smi_phy_read,
3396 .phy_write = mv88e6xxx_g2_smi_phy_write,
3397 .port_set_link = mv88e6xxx_port_set_link,
3398 .port_set_duplex = mv88e6xxx_port_set_duplex,
3399 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3400 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003401 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003402 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3403 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3404 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003405 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003406 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003407 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003408 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3409 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003410 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003411 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3412 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003413 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003414 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003415};
3416
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003417static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003418 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003419 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3420 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003421 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003422 .phy_read = mv88e6xxx_g2_smi_phy_read,
3423 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003424 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003425 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003426 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003427 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003428 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003429 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3430 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3431 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003432 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003433 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003434 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003435 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003436 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3437 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003438 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003439 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3440 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003441 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003442 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003443};
3444
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003445static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003446 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003447 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3448 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003449 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3450 .phy_read = mv88e6xxx_g2_smi_phy_read,
3451 .phy_write = mv88e6xxx_g2_smi_phy_write,
3452 .port_set_link = mv88e6xxx_port_set_link,
3453 .port_set_duplex = mv88e6xxx_port_set_duplex,
3454 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3455 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003456 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003457 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3458 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3459 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003460 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003461 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003462 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003463 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3464 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003465 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003466 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3467 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003468 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003469 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003470};
3471
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003472static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003473 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003474 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3475 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003476 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003477 .phy_read = mv88e6xxx_g2_smi_phy_read,
3478 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003479 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003480 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003481 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003482 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003483 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3484 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3485 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003486 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003487 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003488 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003489 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003490 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3491 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003492 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003493 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3494 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003495 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003496 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003497};
3498
3499static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003500 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003501 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3502 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003503 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003504 .phy_read = mv88e6xxx_g2_smi_phy_read,
3505 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003506 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003507 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003508 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003509 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003510 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3511 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3512 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003513 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003514 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003515 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003516 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003517 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3518 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003519 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003520 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3521 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003522 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003523};
3524
3525static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003526 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003527 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003528 .phy_read = mv88e6xxx_g2_smi_phy_read,
3529 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003530 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003531 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003532 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003533 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003534 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003535 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3536 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3537 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003538 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003539 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003540 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003541 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003542 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3543 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003544 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003545 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3546 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003547 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003548 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003549};
3550
3551static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003552 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003553 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003554 .phy_read = mv88e6xxx_g2_smi_phy_read,
3555 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003556 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003557 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003558 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003559 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003560 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003561 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3562 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3563 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003564 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003565 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003566 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003567 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003568 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3569 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003570 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003571 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3572 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003573 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003574 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003575};
3576
3577static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003578 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003579 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3580 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003581 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003582 .phy_read = mv88e6xxx_g2_smi_phy_read,
3583 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003584 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003585 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003586 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003587 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003588 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003589 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3590 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3591 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003592 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003593 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003594 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003595 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003596 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3597 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003598 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003599 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3600 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003601 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003602 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003603};
3604
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003605static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003606 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003607 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3608 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003609 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3610 .phy_read = mv88e6xxx_g2_smi_phy_read,
3611 .phy_write = mv88e6xxx_g2_smi_phy_write,
3612 .port_set_link = mv88e6xxx_port_set_link,
3613 .port_set_duplex = mv88e6xxx_port_set_duplex,
3614 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3615 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003616 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003617 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3618 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3619 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003620 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003621 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003622 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003623 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003624 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003625 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3626 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003627 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003628 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3629 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003630 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003631 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003632};
3633
3634static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003635 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003636 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3637 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003638 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3639 .phy_read = mv88e6xxx_g2_smi_phy_read,
3640 .phy_write = mv88e6xxx_g2_smi_phy_write,
3641 .port_set_link = mv88e6xxx_port_set_link,
3642 .port_set_duplex = mv88e6xxx_port_set_duplex,
3643 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3644 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003645 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003646 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3647 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3648 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003649 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003650 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003651 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003652 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003653 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003654 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3655 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003656 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003657 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3658 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003659 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003660 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003661};
3662
3663static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003664 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003665 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3666 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003667 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3668 .phy_read = mv88e6xxx_g2_smi_phy_read,
3669 .phy_write = mv88e6xxx_g2_smi_phy_write,
3670 .port_set_link = mv88e6xxx_port_set_link,
3671 .port_set_duplex = mv88e6xxx_port_set_duplex,
3672 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3673 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003674 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003675 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3676 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3677 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003678 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003679 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003680 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003681 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3682 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003683 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003684 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3685 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003686 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003687 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003688};
3689
Andrew Lunn56995cb2016-12-03 04:35:19 +01003690static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3691 const struct mv88e6xxx_ops *ops)
3692{
3693 if (!ops->port_set_frame_mode) {
3694 dev_err(chip->dev, "Missing port_set_frame_mode");
3695 return -EINVAL;
3696 }
3697
3698 if (!ops->port_set_egress_unknowns) {
3699 dev_err(chip->dev, "Missing port_set_egress_mode");
3700 return -EINVAL;
3701 }
3702
3703 return 0;
3704}
3705
Vivien Didelotf81ec902016-05-09 13:22:58 -04003706static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3707 [MV88E6085] = {
3708 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3709 .family = MV88E6XXX_FAMILY_6097,
3710 .name = "Marvell 88E6085",
3711 .num_databases = 4096,
3712 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003713 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003714 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003715 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003716 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003717 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003718 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003719 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003720 },
3721
3722 [MV88E6095] = {
3723 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3724 .family = MV88E6XXX_FAMILY_6095,
3725 .name = "Marvell 88E6095/88E6095F",
3726 .num_databases = 256,
3727 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003728 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003729 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003730 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003731 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003732 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003733 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003734 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003735 },
3736
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003737 [MV88E6097] = {
3738 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3739 .family = MV88E6XXX_FAMILY_6097,
3740 .name = "Marvell 88E6097/88E6097F",
3741 .num_databases = 4096,
3742 .num_ports = 11,
3743 .port_base_addr = 0x10,
3744 .global1_addr = 0x1b,
3745 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003746 .g1_irqs = 8,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003747 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003748 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3749 .ops = &mv88e6097_ops,
3750 },
3751
Vivien Didelotf81ec902016-05-09 13:22:58 -04003752 [MV88E6123] = {
3753 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3754 .family = MV88E6XXX_FAMILY_6165,
3755 .name = "Marvell 88E6123",
3756 .num_databases = 4096,
3757 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003758 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003759 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003760 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003761 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003762 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003763 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003764 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003765 },
3766
3767 [MV88E6131] = {
3768 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3769 .family = MV88E6XXX_FAMILY_6185,
3770 .name = "Marvell 88E6131",
3771 .num_databases = 256,
3772 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003773 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003774 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003775 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003776 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003777 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003778 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003779 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003780 },
3781
3782 [MV88E6161] = {
3783 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3784 .family = MV88E6XXX_FAMILY_6165,
3785 .name = "Marvell 88E6161",
3786 .num_databases = 4096,
3787 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003788 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003789 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003790 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003791 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003792 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003793 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003794 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003795 },
3796
3797 [MV88E6165] = {
3798 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3799 .family = MV88E6XXX_FAMILY_6165,
3800 .name = "Marvell 88E6165",
3801 .num_databases = 4096,
3802 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003803 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003804 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003805 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003806 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003807 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003808 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003809 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003810 },
3811
3812 [MV88E6171] = {
3813 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3814 .family = MV88E6XXX_FAMILY_6351,
3815 .name = "Marvell 88E6171",
3816 .num_databases = 4096,
3817 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003818 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003819 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003820 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003821 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003822 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003823 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003824 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003825 },
3826
3827 [MV88E6172] = {
3828 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3829 .family = MV88E6XXX_FAMILY_6352,
3830 .name = "Marvell 88E6172",
3831 .num_databases = 4096,
3832 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003833 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003834 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003835 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003836 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003837 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003838 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003839 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003840 },
3841
3842 [MV88E6175] = {
3843 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3844 .family = MV88E6XXX_FAMILY_6351,
3845 .name = "Marvell 88E6175",
3846 .num_databases = 4096,
3847 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003848 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003849 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003850 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003851 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003852 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003853 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003854 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003855 },
3856
3857 [MV88E6176] = {
3858 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3859 .family = MV88E6XXX_FAMILY_6352,
3860 .name = "Marvell 88E6176",
3861 .num_databases = 4096,
3862 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003863 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003864 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003865 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003866 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003867 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003868 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003869 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003870 },
3871
3872 [MV88E6185] = {
3873 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3874 .family = MV88E6XXX_FAMILY_6185,
3875 .name = "Marvell 88E6185",
3876 .num_databases = 256,
3877 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003878 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003879 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003880 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003881 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003882 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003883 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003884 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003885 },
3886
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003887 [MV88E6190] = {
3888 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3889 .family = MV88E6XXX_FAMILY_6390,
3890 .name = "Marvell 88E6190",
3891 .num_databases = 4096,
3892 .num_ports = 11, /* 10 + Z80 */
3893 .port_base_addr = 0x0,
3894 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003895 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003896 .age_time_coeff = 15000,
3897 .g1_irqs = 9,
3898 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3899 .ops = &mv88e6190_ops,
3900 },
3901
3902 [MV88E6190X] = {
3903 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3904 .family = MV88E6XXX_FAMILY_6390,
3905 .name = "Marvell 88E6190X",
3906 .num_databases = 4096,
3907 .num_ports = 11, /* 10 + Z80 */
3908 .port_base_addr = 0x0,
3909 .global1_addr = 0x1b,
3910 .age_time_coeff = 15000,
3911 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003912 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003913 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3914 .ops = &mv88e6190x_ops,
3915 },
3916
3917 [MV88E6191] = {
3918 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3919 .family = MV88E6XXX_FAMILY_6390,
3920 .name = "Marvell 88E6191",
3921 .num_databases = 4096,
3922 .num_ports = 11, /* 10 + Z80 */
3923 .port_base_addr = 0x0,
3924 .global1_addr = 0x1b,
3925 .age_time_coeff = 15000,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003926 .g1_irqs = 9,
3927 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003928 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3929 .ops = &mv88e6391_ops,
3930 },
3931
Vivien Didelotf81ec902016-05-09 13:22:58 -04003932 [MV88E6240] = {
3933 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3934 .family = MV88E6XXX_FAMILY_6352,
3935 .name = "Marvell 88E6240",
3936 .num_databases = 4096,
3937 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003938 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003939 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003940 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003941 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003942 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003943 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003944 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003945 },
3946
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003947 [MV88E6290] = {
3948 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3949 .family = MV88E6XXX_FAMILY_6390,
3950 .name = "Marvell 88E6290",
3951 .num_databases = 4096,
3952 .num_ports = 11, /* 10 + Z80 */
3953 .port_base_addr = 0x0,
3954 .global1_addr = 0x1b,
3955 .age_time_coeff = 15000,
3956 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003957 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003958 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3959 .ops = &mv88e6290_ops,
3960 },
3961
Vivien Didelotf81ec902016-05-09 13:22:58 -04003962 [MV88E6320] = {
3963 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3964 .family = MV88E6XXX_FAMILY_6320,
3965 .name = "Marvell 88E6320",
3966 .num_databases = 4096,
3967 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003968 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003969 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003970 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003971 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003972 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003973 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003974 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003975 },
3976
3977 [MV88E6321] = {
3978 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3979 .family = MV88E6XXX_FAMILY_6320,
3980 .name = "Marvell 88E6321",
3981 .num_databases = 4096,
3982 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003983 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003984 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003985 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003986 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003987 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003988 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003989 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003990 },
3991
3992 [MV88E6350] = {
3993 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3994 .family = MV88E6XXX_FAMILY_6351,
3995 .name = "Marvell 88E6350",
3996 .num_databases = 4096,
3997 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003998 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003999 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004000 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004001 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004002 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004003 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004004 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004005 },
4006
4007 [MV88E6351] = {
4008 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4009 .family = MV88E6XXX_FAMILY_6351,
4010 .name = "Marvell 88E6351",
4011 .num_databases = 4096,
4012 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004013 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004014 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004015 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004016 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004017 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004018 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004019 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004020 },
4021
4022 [MV88E6352] = {
4023 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4024 .family = MV88E6XXX_FAMILY_6352,
4025 .name = "Marvell 88E6352",
4026 .num_databases = 4096,
4027 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004028 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004029 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004030 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004031 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004032 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004033 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004034 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004035 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004036 [MV88E6390] = {
4037 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4038 .family = MV88E6XXX_FAMILY_6390,
4039 .name = "Marvell 88E6390",
4040 .num_databases = 4096,
4041 .num_ports = 11, /* 10 + Z80 */
4042 .port_base_addr = 0x0,
4043 .global1_addr = 0x1b,
4044 .age_time_coeff = 15000,
4045 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004046 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004047 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4048 .ops = &mv88e6390_ops,
4049 },
4050 [MV88E6390X] = {
4051 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4052 .family = MV88E6XXX_FAMILY_6390,
4053 .name = "Marvell 88E6390X",
4054 .num_databases = 4096,
4055 .num_ports = 11, /* 10 + Z80 */
4056 .port_base_addr = 0x0,
4057 .global1_addr = 0x1b,
4058 .age_time_coeff = 15000,
4059 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004060 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004061 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4062 .ops = &mv88e6390x_ops,
4063 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004064};
4065
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004066static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004067{
Vivien Didelota439c062016-04-17 13:23:58 -04004068 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004069
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004070 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4071 if (mv88e6xxx_table[i].prod_num == prod_num)
4072 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004073
Vivien Didelotb9b37712015-10-30 19:39:48 -04004074 return NULL;
4075}
4076
Vivien Didelotfad09c72016-06-21 12:28:20 -04004077static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004078{
4079 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004080 unsigned int prod_num, rev;
4081 u16 id;
4082 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004083
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004084 mutex_lock(&chip->reg_lock);
4085 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4086 mutex_unlock(&chip->reg_lock);
4087 if (err)
4088 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004089
4090 prod_num = (id & 0xfff0) >> 4;
4091 rev = id & 0x000f;
4092
4093 info = mv88e6xxx_lookup_info(prod_num);
4094 if (!info)
4095 return -ENODEV;
4096
Vivien Didelotcaac8542016-06-20 13:14:09 -04004097 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004098 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004099
Vivien Didelotca070c12016-09-02 14:45:34 -04004100 err = mv88e6xxx_g2_require(chip);
4101 if (err)
4102 return err;
4103
Vivien Didelotfad09c72016-06-21 12:28:20 -04004104 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4105 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004106
4107 return 0;
4108}
4109
Vivien Didelotfad09c72016-06-21 12:28:20 -04004110static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004111{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004112 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004113
Vivien Didelotfad09c72016-06-21 12:28:20 -04004114 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4115 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004116 return NULL;
4117
Vivien Didelotfad09c72016-06-21 12:28:20 -04004118 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004119
Vivien Didelotfad09c72016-06-21 12:28:20 -04004120 mutex_init(&chip->reg_lock);
Vivien Didelot469d7292016-06-20 13:14:06 -04004121
Vivien Didelotfad09c72016-06-21 12:28:20 -04004122 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004123}
4124
Vivien Didelote57e5e72016-08-15 17:19:00 -04004125static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4126{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004127 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004128 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004129}
4130
Andrew Lunn930188c2016-08-22 16:01:03 +02004131static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4132{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004133 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004134 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004135}
4136
Vivien Didelotfad09c72016-06-21 12:28:20 -04004137static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004138 struct mii_bus *bus, int sw_addr)
4139{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004140 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004141 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004142 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004143 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004144 else
4145 return -EINVAL;
4146
Vivien Didelotfad09c72016-06-21 12:28:20 -04004147 chip->bus = bus;
4148 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004149
4150 return 0;
4151}
4152
Andrew Lunn7b314362016-08-22 16:01:01 +02004153static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4154{
Vivien Didelot04bed142016-08-31 18:06:13 -04004155 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004156
Andrew Lunn443d5a12016-12-03 04:35:18 +01004157 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004158}
4159
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004160static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4161 struct device *host_dev, int sw_addr,
4162 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004163{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004164 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004165 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004166 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004167
Vivien Didelota439c062016-04-17 13:23:58 -04004168 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004169 if (!bus)
4170 return NULL;
4171
Vivien Didelotfad09c72016-06-21 12:28:20 -04004172 chip = mv88e6xxx_alloc_chip(dsa_dev);
4173 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004174 return NULL;
4175
Vivien Didelotcaac8542016-06-20 13:14:09 -04004176 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004177 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004178
Vivien Didelotfad09c72016-06-21 12:28:20 -04004179 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004180 if (err)
4181 goto free;
4182
Vivien Didelotfad09c72016-06-21 12:28:20 -04004183 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004184 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004185 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004186
Andrew Lunndc30c352016-10-16 19:56:49 +02004187 mutex_lock(&chip->reg_lock);
4188 err = mv88e6xxx_switch_reset(chip);
4189 mutex_unlock(&chip->reg_lock);
4190 if (err)
4191 goto free;
4192
Vivien Didelote57e5e72016-08-15 17:19:00 -04004193 mv88e6xxx_phy_init(chip);
4194
Vivien Didelotfad09c72016-06-21 12:28:20 -04004195 err = mv88e6xxx_mdio_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004196 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004197 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004198
Vivien Didelotfad09c72016-06-21 12:28:20 -04004199 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004200
Vivien Didelotfad09c72016-06-21 12:28:20 -04004201 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004202free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004203 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004204
4205 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004206}
4207
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004208static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4209 const struct switchdev_obj_port_mdb *mdb,
4210 struct switchdev_trans *trans)
4211{
4212 /* We don't need any dynamic resource from the kernel (yet),
4213 * so skip the prepare phase.
4214 */
4215
4216 return 0;
4217}
4218
4219static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4220 const struct switchdev_obj_port_mdb *mdb,
4221 struct switchdev_trans *trans)
4222{
Vivien Didelot04bed142016-08-31 18:06:13 -04004223 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004224
4225 mutex_lock(&chip->reg_lock);
4226 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4227 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4228 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4229 mutex_unlock(&chip->reg_lock);
4230}
4231
4232static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4233 const struct switchdev_obj_port_mdb *mdb)
4234{
Vivien Didelot04bed142016-08-31 18:06:13 -04004235 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004236 int err;
4237
4238 mutex_lock(&chip->reg_lock);
4239 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4240 GLOBAL_ATU_DATA_STATE_UNUSED);
4241 mutex_unlock(&chip->reg_lock);
4242
4243 return err;
4244}
4245
4246static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4247 struct switchdev_obj_port_mdb *mdb,
4248 int (*cb)(struct switchdev_obj *obj))
4249{
Vivien Didelot04bed142016-08-31 18:06:13 -04004250 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004251 int err;
4252
4253 mutex_lock(&chip->reg_lock);
4254 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4255 mutex_unlock(&chip->reg_lock);
4256
4257 return err;
4258}
4259
Florian Fainellia82f67a2017-01-08 14:52:08 -08004260static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004261 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004262 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004263 .setup = mv88e6xxx_setup,
4264 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004265 .adjust_link = mv88e6xxx_adjust_link,
4266 .get_strings = mv88e6xxx_get_strings,
4267 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4268 .get_sset_count = mv88e6xxx_get_sset_count,
4269 .set_eee = mv88e6xxx_set_eee,
4270 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004271 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004272 .get_eeprom = mv88e6xxx_get_eeprom,
4273 .set_eeprom = mv88e6xxx_set_eeprom,
4274 .get_regs_len = mv88e6xxx_get_regs_len,
4275 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004276 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004277 .port_bridge_join = mv88e6xxx_port_bridge_join,
4278 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4279 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004280 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004281 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4282 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4283 .port_vlan_add = mv88e6xxx_port_vlan_add,
4284 .port_vlan_del = mv88e6xxx_port_vlan_del,
4285 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4286 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4287 .port_fdb_add = mv88e6xxx_port_fdb_add,
4288 .port_fdb_del = mv88e6xxx_port_fdb_del,
4289 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004290 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4291 .port_mdb_add = mv88e6xxx_port_mdb_add,
4292 .port_mdb_del = mv88e6xxx_port_mdb_del,
4293 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004294};
4295
Florian Fainelliab3d4082017-01-08 14:52:07 -08004296static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4297 .ops = &mv88e6xxx_switch_ops,
4298};
4299
Vivien Didelotfad09c72016-06-21 12:28:20 -04004300static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004301 struct device_node *np)
4302{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004303 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004304 struct dsa_switch *ds;
4305
4306 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
4307 if (!ds)
4308 return -ENOMEM;
4309
4310 ds->dev = dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004311 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004312 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004313
4314 dev_set_drvdata(dev, ds);
4315
4316 return dsa_register_switch(ds, np);
4317}
4318
Vivien Didelotfad09c72016-06-21 12:28:20 -04004319static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004320{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004321 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004322}
4323
Vivien Didelot57d32312016-06-20 13:13:58 -04004324static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004325{
4326 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004327 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004328 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004329 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004330 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004331 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004332
Vivien Didelotcaac8542016-06-20 13:14:09 -04004333 compat_info = of_device_get_match_data(dev);
4334 if (!compat_info)
4335 return -EINVAL;
4336
Vivien Didelotfad09c72016-06-21 12:28:20 -04004337 chip = mv88e6xxx_alloc_chip(dev);
4338 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004339 return -ENOMEM;
4340
Vivien Didelotfad09c72016-06-21 12:28:20 -04004341 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004342
Andrew Lunn56995cb2016-12-03 04:35:19 +01004343 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4344 if (err)
4345 return err;
4346
Vivien Didelotfad09c72016-06-21 12:28:20 -04004347 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004348 if (err)
4349 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004350
Andrew Lunnb4308f02016-11-21 23:26:55 +01004351 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4352 if (IS_ERR(chip->reset))
4353 return PTR_ERR(chip->reset);
4354
Vivien Didelotfad09c72016-06-21 12:28:20 -04004355 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004356 if (err)
4357 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004358
Vivien Didelote57e5e72016-08-15 17:19:00 -04004359 mv88e6xxx_phy_init(chip);
4360
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004361 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004362 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004363 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004364
Andrew Lunndc30c352016-10-16 19:56:49 +02004365 mutex_lock(&chip->reg_lock);
4366 err = mv88e6xxx_switch_reset(chip);
4367 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004368 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004369 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004370
Andrew Lunndc30c352016-10-16 19:56:49 +02004371 chip->irq = of_irq_get(np, 0);
4372 if (chip->irq == -EPROBE_DEFER) {
4373 err = chip->irq;
4374 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004375 }
4376
Andrew Lunndc30c352016-10-16 19:56:49 +02004377 if (chip->irq > 0) {
4378 /* Has to be performed before the MDIO bus is created,
4379 * because the PHYs will link there interrupts to these
4380 * interrupt controllers
4381 */
4382 mutex_lock(&chip->reg_lock);
4383 err = mv88e6xxx_g1_irq_setup(chip);
4384 mutex_unlock(&chip->reg_lock);
4385
4386 if (err)
4387 goto out;
4388
4389 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4390 err = mv88e6xxx_g2_irq_setup(chip);
4391 if (err)
4392 goto out_g1_irq;
4393 }
4394 }
4395
4396 err = mv88e6xxx_mdio_register(chip, np);
4397 if (err)
4398 goto out_g2_irq;
4399
4400 err = mv88e6xxx_register_switch(chip, np);
4401 if (err)
4402 goto out_mdio;
4403
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004404 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004405
4406out_mdio:
4407 mv88e6xxx_mdio_unregister(chip);
4408out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004409 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004410 mv88e6xxx_g2_irq_free(chip);
4411out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004412 if (chip->irq > 0) {
4413 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004414 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004415 mutex_unlock(&chip->reg_lock);
4416 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004417out:
4418 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004419}
4420
4421static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4422{
4423 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004424 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004425
Andrew Lunn930188c2016-08-22 16:01:03 +02004426 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004427 mv88e6xxx_unregister_switch(chip);
4428 mv88e6xxx_mdio_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004429
Andrew Lunn467126442016-11-20 20:14:15 +01004430 if (chip->irq > 0) {
4431 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4432 mv88e6xxx_g2_irq_free(chip);
4433 mv88e6xxx_g1_irq_free(chip);
4434 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004435}
4436
4437static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004438 {
4439 .compatible = "marvell,mv88e6085",
4440 .data = &mv88e6xxx_table[MV88E6085],
4441 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004442 {
4443 .compatible = "marvell,mv88e6190",
4444 .data = &mv88e6xxx_table[MV88E6190],
4445 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004446 { /* sentinel */ },
4447};
4448
4449MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4450
4451static struct mdio_driver mv88e6xxx_driver = {
4452 .probe = mv88e6xxx_probe,
4453 .remove = mv88e6xxx_remove,
4454 .mdiodrv.driver = {
4455 .name = "mv88e6085",
4456 .of_match_table = mv88e6xxx_of_match,
4457 },
4458};
4459
Ben Hutchings98e67302011-11-25 14:36:19 +00004460static int __init mv88e6xxx_init(void)
4461{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004462 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004463 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004464}
4465module_init(mv88e6xxx_init);
4466
4467static void __exit mv88e6xxx_cleanup(void)
4468{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004469 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004470 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004471}
4472module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004473
4474MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4475MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4476MODULE_LICENSE("GPL");