blob: 2a32bb490f927acbf495c5dfa284e3bc93241e96 [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 *
Vivien Didelot4333d612017-03-28 15:10:36 -040011 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
12 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
13 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000014 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 */
19
Barry Grussling19b2f972013-01-08 16:05:54 +000020#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070021#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020022#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070023#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020024#include <linux/interrupt.h>
25#include <linux/irq.h>
26#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000027#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000028#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020029#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000030#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040031#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020032#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020033#include <linux/of_mdio.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000034#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010035#include <linux/gpio/consumer.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000036#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000037#include <net/dsa.h>
Vivien Didelot1f36faf2015-10-08 11:35:13 -040038#include <net/switchdev.h>
Vivien Didelotec561272016-09-02 14:45:33 -040039
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000040#include "mv88e6xxx.h"
Vivien Didelota935c052016-09-29 12:21:53 -040041#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040042#include "global2.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010043#include "port.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000044
Vivien Didelotfad09c72016-06-21 12:28:20 -040045static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040046{
Vivien Didelotfad09c72016-06-21 12:28:20 -040047 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
48 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040049 dump_stack();
50 }
51}
52
Vivien Didelot914b32f2016-06-20 13:14:11 -040053/* The switch ADDR[4:1] configuration pins define the chip SMI device address
54 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
55 *
56 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
57 * is the only device connected to the SMI master. In this mode it responds to
58 * all 32 possible SMI addresses, and thus maps directly the internal devices.
59 *
60 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
61 * multiple devices to share the SMI interface. In this mode it responds to only
62 * 2 registers, used to indirectly access the internal SMI devices.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000063 */
Vivien Didelot914b32f2016-06-20 13:14:11 -040064
Vivien Didelotfad09c72016-06-21 12:28:20 -040065static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040066 int addr, int reg, u16 *val)
67{
Vivien Didelotfad09c72016-06-21 12:28:20 -040068 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040069 return -EOPNOTSUPP;
70
Vivien Didelotfad09c72016-06-21 12:28:20 -040071 return chip->smi_ops->read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040072}
73
Vivien Didelotfad09c72016-06-21 12:28:20 -040074static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040075 int addr, int reg, u16 val)
76{
Vivien Didelotfad09c72016-06-21 12:28:20 -040077 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040078 return -EOPNOTSUPP;
79
Vivien Didelotfad09c72016-06-21 12:28:20 -040080 return chip->smi_ops->write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040081}
82
Vivien Didelotfad09c72016-06-21 12:28:20 -040083static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040084 int addr, int reg, u16 *val)
85{
86 int ret;
87
Vivien Didelotfad09c72016-06-21 12:28:20 -040088 ret = mdiobus_read_nested(chip->bus, addr, reg);
Vivien Didelot914b32f2016-06-20 13:14:11 -040089 if (ret < 0)
90 return ret;
91
92 *val = ret & 0xffff;
93
94 return 0;
95}
96
Vivien Didelotfad09c72016-06-21 12:28:20 -040097static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040098 int addr, int reg, u16 val)
99{
100 int ret;
101
Vivien Didelotfad09c72016-06-21 12:28:20 -0400102 ret = mdiobus_write_nested(chip->bus, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400103 if (ret < 0)
104 return ret;
105
106 return 0;
107}
108
Vivien Didelotc08026a2016-09-29 12:21:59 -0400109static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400110 .read = mv88e6xxx_smi_single_chip_read,
111 .write = mv88e6xxx_smi_single_chip_write,
112};
113
Vivien Didelotfad09c72016-06-21 12:28:20 -0400114static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000115{
116 int ret;
117 int i;
118
119 for (i = 0; i < 16; i++) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400120 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000121 if (ret < 0)
122 return ret;
123
Andrew Lunncca8b132015-04-02 04:06:39 +0200124 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000125 return 0;
126 }
127
128 return -ETIMEDOUT;
129}
130
Vivien Didelotfad09c72016-06-21 12:28:20 -0400131static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400132 int addr, int reg, u16 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000133{
134 int ret;
135
Barry Grussling3675c8d2013-01-08 16:05:53 +0000136 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400137 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000138 if (ret < 0)
139 return ret;
140
Barry Grussling3675c8d2013-01-08 16:05:53 +0000141 /* Transmit the read command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400142 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Neil Armstrong6e899e62015-10-22 10:37:53 +0200143 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000144 if (ret < 0)
145 return ret;
146
Barry Grussling3675c8d2013-01-08 16:05:53 +0000147 /* Wait for the read command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400148 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000149 if (ret < 0)
150 return ret;
151
Barry Grussling3675c8d2013-01-08 16:05:53 +0000152 /* Read the data. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400153 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000154 if (ret < 0)
155 return ret;
156
Vivien Didelot914b32f2016-06-20 13:14:11 -0400157 *val = ret & 0xffff;
158
159 return 0;
160}
161
Vivien Didelotfad09c72016-06-21 12:28:20 -0400162static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400163 int addr, int reg, u16 val)
164{
165 int ret;
166
167 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400168 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400169 if (ret < 0)
170 return ret;
171
172 /* Transmit the data to write. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400173 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400174 if (ret < 0)
175 return ret;
176
177 /* Transmit the write command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400178 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400179 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
180 if (ret < 0)
181 return ret;
182
183 /* Wait for the write command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400184 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400185 if (ret < 0)
186 return ret;
187
188 return 0;
189}
190
Vivien Didelotc08026a2016-09-29 12:21:59 -0400191static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400192 .read = mv88e6xxx_smi_multi_chip_read,
193 .write = mv88e6xxx_smi_multi_chip_write,
194};
195
Vivien Didelotec561272016-09-02 14:45:33 -0400196int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400197{
198 int err;
199
Vivien Didelotfad09c72016-06-21 12:28:20 -0400200 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400201
Vivien Didelotfad09c72016-06-21 12:28:20 -0400202 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400203 if (err)
204 return err;
205
Vivien Didelotfad09c72016-06-21 12:28:20 -0400206 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400207 addr, reg, *val);
208
209 return 0;
210}
211
Vivien Didelotec561272016-09-02 14:45:33 -0400212int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400213{
214 int err;
215
Vivien Didelotfad09c72016-06-21 12:28:20 -0400216 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400217
Vivien Didelotfad09c72016-06-21 12:28:20 -0400218 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400219 if (err)
220 return err;
221
Vivien Didelotfad09c72016-06-21 12:28:20 -0400222 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400223 addr, reg, val);
224
225 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000226}
227
Andrew Lunnee26a222017-01-24 14:53:48 +0100228static int mv88e6165_phy_read(struct mv88e6xxx_chip *chip,
229 struct mii_bus *bus,
230 int addr, int reg, u16 *val)
Andrew Lunnefb3e742017-01-24 14:53:47 +0100231{
232 return mv88e6xxx_read(chip, addr, reg, val);
233}
234
Andrew Lunnee26a222017-01-24 14:53:48 +0100235static int mv88e6165_phy_write(struct mv88e6xxx_chip *chip,
236 struct mii_bus *bus,
237 int addr, int reg, u16 val)
Andrew Lunnefb3e742017-01-24 14:53:47 +0100238{
239 return mv88e6xxx_write(chip, addr, reg, val);
240}
241
Andrew Lunna3c53be52017-01-24 14:53:50 +0100242static struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
243{
244 struct mv88e6xxx_mdio_bus *mdio_bus;
245
246 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
247 list);
248 if (!mdio_bus)
249 return NULL;
250
251 return mdio_bus->bus;
252}
253
Vivien Didelote57e5e72016-08-15 17:19:00 -0400254static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
255 int reg, u16 *val)
256{
257 int addr = phy; /* PHY devices addresses start at 0x0 */
Andrew Lunna3c53be52017-01-24 14:53:50 +0100258 struct mii_bus *bus;
Vivien Didelote57e5e72016-08-15 17:19:00 -0400259
Andrew Lunna3c53be52017-01-24 14:53:50 +0100260 bus = mv88e6xxx_default_mdio_bus(chip);
261 if (!bus)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400262 return -EOPNOTSUPP;
263
Andrew Lunna3c53be52017-01-24 14:53:50 +0100264 if (!chip->info->ops->phy_read)
Andrew Lunnee26a222017-01-24 14:53:48 +0100265 return -EOPNOTSUPP;
266
267 return chip->info->ops->phy_read(chip, bus, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400268}
269
270static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
271 int reg, u16 val)
272{
273 int addr = phy; /* PHY devices addresses start at 0x0 */
Andrew Lunna3c53be52017-01-24 14:53:50 +0100274 struct mii_bus *bus;
Vivien Didelote57e5e72016-08-15 17:19:00 -0400275
Andrew Lunna3c53be52017-01-24 14:53:50 +0100276 bus = mv88e6xxx_default_mdio_bus(chip);
277 if (!bus)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400278 return -EOPNOTSUPP;
279
Andrew Lunna3c53be52017-01-24 14:53:50 +0100280 if (!chip->info->ops->phy_write)
Andrew Lunnee26a222017-01-24 14:53:48 +0100281 return -EOPNOTSUPP;
282
283 return chip->info->ops->phy_write(chip, bus, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400284}
285
Vivien Didelot09cb7df2016-08-15 17:19:01 -0400286static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
287{
288 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_PHY_PAGE))
289 return -EOPNOTSUPP;
290
291 return mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
292}
293
294static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip *chip, int phy)
295{
296 int err;
297
298 /* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
299 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, PHY_PAGE_COPPER);
300 if (unlikely(err)) {
301 dev_err(chip->dev, "failed to restore PHY %d page Copper (%d)\n",
302 phy, err);
303 }
304}
305
306static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy,
307 u8 page, int reg, u16 *val)
308{
309 int err;
310
311 /* There is no paging for registers 22 */
312 if (reg == PHY_PAGE)
313 return -EINVAL;
314
315 err = mv88e6xxx_phy_page_get(chip, phy, page);
316 if (!err) {
317 err = mv88e6xxx_phy_read(chip, phy, reg, val);
318 mv88e6xxx_phy_page_put(chip, phy);
319 }
320
321 return err;
322}
323
324static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy,
325 u8 page, int reg, u16 val)
326{
327 int err;
328
329 /* There is no paging for registers 22 */
330 if (reg == PHY_PAGE)
331 return -EINVAL;
332
333 err = mv88e6xxx_phy_page_get(chip, phy, page);
334 if (!err) {
335 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
336 mv88e6xxx_phy_page_put(chip, phy);
337 }
338
339 return err;
340}
341
342static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
343{
344 return mv88e6xxx_phy_page_read(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
345 reg, val);
346}
347
348static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
349{
350 return mv88e6xxx_phy_page_write(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
351 reg, val);
352}
353
Andrew Lunndc30c352016-10-16 19:56:49 +0200354static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
355{
356 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
357 unsigned int n = d->hwirq;
358
359 chip->g1_irq.masked |= (1 << n);
360}
361
362static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
363{
364 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
365 unsigned int n = d->hwirq;
366
367 chip->g1_irq.masked &= ~(1 << n);
368}
369
370static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
371{
372 struct mv88e6xxx_chip *chip = dev_id;
373 unsigned int nhandled = 0;
374 unsigned int sub_irq;
375 unsigned int n;
376 u16 reg;
377 int err;
378
379 mutex_lock(&chip->reg_lock);
380 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
381 mutex_unlock(&chip->reg_lock);
382
383 if (err)
384 goto out;
385
386 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
387 if (reg & (1 << n)) {
388 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
389 handle_nested_irq(sub_irq);
390 ++nhandled;
391 }
392 }
393out:
394 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
395}
396
397static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
398{
399 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
400
401 mutex_lock(&chip->reg_lock);
402}
403
404static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
405{
406 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
407 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
408 u16 reg;
409 int err;
410
411 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
412 if (err)
413 goto out;
414
415 reg &= ~mask;
416 reg |= (~chip->g1_irq.masked & mask);
417
418 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
419 if (err)
420 goto out;
421
422out:
423 mutex_unlock(&chip->reg_lock);
424}
425
426static struct irq_chip mv88e6xxx_g1_irq_chip = {
427 .name = "mv88e6xxx-g1",
428 .irq_mask = mv88e6xxx_g1_irq_mask,
429 .irq_unmask = mv88e6xxx_g1_irq_unmask,
430 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
431 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
432};
433
434static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
435 unsigned int irq,
436 irq_hw_number_t hwirq)
437{
438 struct mv88e6xxx_chip *chip = d->host_data;
439
440 irq_set_chip_data(irq, d->host_data);
441 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
442 irq_set_noprobe(irq);
443
444 return 0;
445}
446
447static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
448 .map = mv88e6xxx_g1_irq_domain_map,
449 .xlate = irq_domain_xlate_twocell,
450};
451
452static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
453{
454 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100455 u16 mask;
456
457 mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
458 mask |= GENMASK(chip->g1_irq.nirqs, 0);
459 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
460
461 free_irq(chip->irq, chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200462
Andreas Färber5edef2f2016-11-27 23:26:28 +0100463 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100464 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200465 irq_dispose_mapping(virq);
466 }
467
Andrew Lunna3db3d32016-11-20 20:14:14 +0100468 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200469}
470
471static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
472{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100473 int err, irq, virq;
474 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200475
476 chip->g1_irq.nirqs = chip->info->g1_irqs;
477 chip->g1_irq.domain = irq_domain_add_simple(
478 NULL, chip->g1_irq.nirqs, 0,
479 &mv88e6xxx_g1_irq_domain_ops, chip);
480 if (!chip->g1_irq.domain)
481 return -ENOMEM;
482
483 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
484 irq_create_mapping(chip->g1_irq.domain, irq);
485
486 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
487 chip->g1_irq.masked = ~0;
488
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100489 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200490 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100491 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200492
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100493 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200494
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100495 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200496 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100497 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200498
499 /* Reading the interrupt status clears (most of) them */
500 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
501 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100502 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200503
504 err = request_threaded_irq(chip->irq, NULL,
505 mv88e6xxx_g1_irq_thread_fn,
506 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
507 dev_name(chip->dev), chip);
508 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100509 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200510
511 return 0;
512
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100513out_disable:
514 mask |= GENMASK(chip->g1_irq.nirqs, 0);
515 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
516
517out_mapping:
518 for (irq = 0; irq < 16; irq++) {
519 virq = irq_find_mapping(chip->g1_irq.domain, irq);
520 irq_dispose_mapping(virq);
521 }
522
523 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200524
525 return err;
526}
527
Vivien Didelotec561272016-09-02 14:45:33 -0400528int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400529{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200530 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400531
Andrew Lunn6441e6692016-08-19 00:01:55 +0200532 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400533 u16 val;
534 int err;
535
536 err = mv88e6xxx_read(chip, addr, reg, &val);
537 if (err)
538 return err;
539
540 if (!(val & mask))
541 return 0;
542
543 usleep_range(1000, 2000);
544 }
545
Andrew Lunn30853552016-08-19 00:01:57 +0200546 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400547 return -ETIMEDOUT;
548}
549
Vivien Didelotf22ab642016-07-18 20:45:31 -0400550/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400551int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400552{
553 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200554 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400555
556 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200557 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
558 if (err)
559 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400560
561 /* Set the Update bit to trigger a write operation */
562 val = BIT(15) | update;
563
564 return mv88e6xxx_write(chip, addr, reg, val);
565}
566
Vivien Didelota935c052016-09-29 12:21:53 -0400567static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000568{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500569 if (!chip->info->ops->ppu_disable)
570 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000571
Vivien Didelota199d8b2016-12-05 17:30:28 -0500572 return chip->info->ops->ppu_disable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000573}
574
Vivien Didelotfad09c72016-06-21 12:28:20 -0400575static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000576{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500577 if (!chip->info->ops->ppu_enable)
578 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000579
Vivien Didelota199d8b2016-12-05 17:30:28 -0500580 return chip->info->ops->ppu_enable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000581}
582
583static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
584{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400585 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000586
Vivien Didelotfad09c72016-06-21 12:28:20 -0400587 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200588
Vivien Didelotfad09c72016-06-21 12:28:20 -0400589 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200590
Vivien Didelotfad09c72016-06-21 12:28:20 -0400591 if (mutex_trylock(&chip->ppu_mutex)) {
592 if (mv88e6xxx_ppu_enable(chip) == 0)
593 chip->ppu_disabled = 0;
594 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000595 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200596
Vivien Didelotfad09c72016-06-21 12:28:20 -0400597 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000598}
599
600static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
601{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400602 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000603
Vivien Didelotfad09c72016-06-21 12:28:20 -0400604 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000605}
606
Vivien Didelotfad09c72016-06-21 12:28:20 -0400607static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000608{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000609 int ret;
610
Vivien Didelotfad09c72016-06-21 12:28:20 -0400611 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000612
Barry Grussling3675c8d2013-01-08 16:05:53 +0000613 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000614 * we can access the PHY registers. If it was already
615 * disabled, cancel the timer that is going to re-enable
616 * it.
617 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400618 if (!chip->ppu_disabled) {
619 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000620 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400621 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000622 return ret;
623 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400624 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000625 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400626 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000627 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000628 }
629
630 return ret;
631}
632
Vivien Didelotfad09c72016-06-21 12:28:20 -0400633static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000634{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000635 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400636 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
637 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000638}
639
Vivien Didelotfad09c72016-06-21 12:28:20 -0400640static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000641{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400642 mutex_init(&chip->ppu_mutex);
643 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000644 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
645 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000646}
647
Andrew Lunn930188c2016-08-22 16:01:03 +0200648static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
649{
650 del_timer_sync(&chip->ppu_timer);
651}
652
Andrew Lunnee26a222017-01-24 14:53:48 +0100653static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip,
654 struct mii_bus *bus,
655 int addr, int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000656{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400657 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000658
Vivien Didelote57e5e72016-08-15 17:19:00 -0400659 err = mv88e6xxx_ppu_access_get(chip);
660 if (!err) {
661 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400662 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000663 }
664
Vivien Didelote57e5e72016-08-15 17:19:00 -0400665 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000666}
667
Andrew Lunnee26a222017-01-24 14:53:48 +0100668static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip,
669 struct mii_bus *bus,
670 int addr, int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000671{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400672 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000673
Vivien Didelote57e5e72016-08-15 17:19:00 -0400674 err = mv88e6xxx_ppu_access_get(chip);
675 if (!err) {
676 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400677 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000678 }
679
Vivien Didelote57e5e72016-08-15 17:19:00 -0400680 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000681}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000682
Vivien Didelotfad09c72016-06-21 12:28:20 -0400683static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200684{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400685 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200686}
687
Vivien Didelotfad09c72016-06-21 12:28:20 -0400688static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200689{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400690 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200691}
692
Gregory CLEMENTa75961d2017-01-30 20:29:34 +0100693static bool mv88e6xxx_6341_family(struct mv88e6xxx_chip *chip)
694{
695 return chip->info->family == MV88E6XXX_FAMILY_6341;
696}
697
Vivien Didelotfad09c72016-06-21 12:28:20 -0400698static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200699{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400700 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200701}
702
Vivien Didelotfad09c72016-06-21 12:28:20 -0400703static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200704{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400705 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200706}
707
Vivien Didelotd78343d2016-11-04 03:23:36 +0100708static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
709 int link, int speed, int duplex,
710 phy_interface_t mode)
711{
712 int err;
713
714 if (!chip->info->ops->port_set_link)
715 return 0;
716
717 /* Port's MAC control must not be changed unless the link is down */
718 err = chip->info->ops->port_set_link(chip, port, 0);
719 if (err)
720 return err;
721
722 if (chip->info->ops->port_set_speed) {
723 err = chip->info->ops->port_set_speed(chip, port, speed);
724 if (err && err != -EOPNOTSUPP)
725 goto restore_link;
726 }
727
728 if (chip->info->ops->port_set_duplex) {
729 err = chip->info->ops->port_set_duplex(chip, port, duplex);
730 if (err && err != -EOPNOTSUPP)
731 goto restore_link;
732 }
733
734 if (chip->info->ops->port_set_rgmii_delay) {
735 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
736 if (err && err != -EOPNOTSUPP)
737 goto restore_link;
738 }
739
Andrew Lunnf39908d2017-02-04 20:02:50 +0100740 if (chip->info->ops->port_set_cmode) {
741 err = chip->info->ops->port_set_cmode(chip, port, mode);
742 if (err && err != -EOPNOTSUPP)
743 goto restore_link;
744 }
745
Vivien Didelotd78343d2016-11-04 03:23:36 +0100746 err = 0;
747restore_link:
748 if (chip->info->ops->port_set_link(chip, port, link))
749 netdev_err(chip->ds->ports[port].netdev,
750 "failed to restore MAC's link\n");
751
752 return err;
753}
754
Andrew Lunndea87022015-08-31 15:56:47 +0200755/* We expect the switch to perform auto negotiation if there is a real
756 * phy. However, in the case of a fixed link phy, we force the port
757 * settings from the fixed link settings.
758 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400759static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
760 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200761{
Vivien Didelot04bed142016-08-31 18:06:13 -0400762 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200763 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200764
765 if (!phy_is_pseudo_fixed_link(phydev))
766 return;
767
Vivien Didelotfad09c72016-06-21 12:28:20 -0400768 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100769 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
770 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400771 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100772
773 if (err && err != -EOPNOTSUPP)
774 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200775}
776
Andrew Lunna605a0f2016-11-21 23:26:58 +0100777static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000778{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100779 if (!chip->info->ops->stats_snapshot)
780 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000781
Andrew Lunna605a0f2016-11-21 23:26:58 +0100782 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000783}
784
Andrew Lunne413e7e2015-04-02 04:06:38 +0200785static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100786 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
787 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
788 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
789 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
790 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
791 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
792 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
793 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
794 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
795 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
796 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
797 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
798 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
799 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
800 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
801 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
802 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
803 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
804 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
805 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
806 { "single", 4, 0x14, STATS_TYPE_BANK0, },
807 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
808 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
809 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
810 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
811 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
812 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
813 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
814 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
815 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
816 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
817 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
818 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
819 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
820 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
821 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
822 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
823 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
824 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
825 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
826 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
827 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
828 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
829 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
830 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
831 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
832 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
833 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
834 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
835 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
836 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
837 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
838 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
839 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
840 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
841 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
842 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
843 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
844 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200845};
846
Vivien Didelotfad09c72016-06-21 12:28:20 -0400847static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100848 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100849 int port, u16 bank1_select,
850 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200851{
Andrew Lunn80c46272015-06-20 18:42:30 +0200852 u32 low;
853 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100854 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200855 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200856 u64 value;
857
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100858 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100859 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200860 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
861 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200862 return UINT64_MAX;
863
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200864 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200865 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200866 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
867 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200868 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200869 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200870 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100871 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100872 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100873 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100874 /* fall through */
875 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100876 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100877 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200878 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100879 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200880 }
881 value = (((u64)high) << 16) | low;
882 return value;
883}
884
Andrew Lunndfafe442016-11-21 23:27:02 +0100885static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
886 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100887{
888 struct mv88e6xxx_hw_stat *stat;
889 int i, j;
890
891 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
892 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100893 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100894 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
895 ETH_GSTRING_LEN);
896 j++;
897 }
898 }
899}
900
Andrew Lunndfafe442016-11-21 23:27:02 +0100901static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
902 uint8_t *data)
903{
904 mv88e6xxx_stats_get_strings(chip, data,
905 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
906}
907
908static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
909 uint8_t *data)
910{
911 mv88e6xxx_stats_get_strings(chip, data,
912 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
913}
914
915static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
916 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100917{
Vivien Didelot04bed142016-08-31 18:06:13 -0400918 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100919
920 if (chip->info->ops->stats_get_strings)
921 chip->info->ops->stats_get_strings(chip, data);
922}
923
924static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
925 int types)
926{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100927 struct mv88e6xxx_hw_stat *stat;
928 int i, j;
929
930 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
931 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100932 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100933 j++;
934 }
935 return j;
936}
937
Andrew Lunndfafe442016-11-21 23:27:02 +0100938static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
939{
940 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
941 STATS_TYPE_PORT);
942}
943
944static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
945{
946 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
947 STATS_TYPE_BANK1);
948}
949
950static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
951{
952 struct mv88e6xxx_chip *chip = ds->priv;
953
954 if (chip->info->ops->stats_get_sset_count)
955 return chip->info->ops->stats_get_sset_count(chip);
956
957 return 0;
958}
959
Andrew Lunn052f9472016-11-21 23:27:03 +0100960static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100961 uint64_t *data, int types,
962 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100963{
964 struct mv88e6xxx_hw_stat *stat;
965 int i, j;
966
967 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
968 stat = &mv88e6xxx_hw_stats[i];
969 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100970 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
971 bank1_select,
972 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100973 j++;
974 }
975 }
976}
977
978static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
979 uint64_t *data)
980{
981 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100982 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
983 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100984}
985
986static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
987 uint64_t *data)
988{
989 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100990 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
991 GLOBAL_STATS_OP_BANK_1_BIT_9,
992 GLOBAL_STATS_OP_HIST_RX_TX);
993}
994
995static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
996 uint64_t *data)
997{
998 return mv88e6xxx_stats_get_stats(chip, port, data,
999 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1000 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001001}
1002
1003static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1004 uint64_t *data)
1005{
1006 if (chip->info->ops->stats_get_stats)
1007 chip->info->ops->stats_get_stats(chip, port, data);
1008}
1009
Vivien Didelotf81ec902016-05-09 13:22:58 -04001010static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1011 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001012{
Vivien Didelot04bed142016-08-31 18:06:13 -04001013 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001014 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001015
Vivien Didelotfad09c72016-06-21 12:28:20 -04001016 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001017
Andrew Lunna605a0f2016-11-21 23:26:58 +01001018 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001019 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001020 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001021 return;
1022 }
Andrew Lunn052f9472016-11-21 23:27:03 +01001023
1024 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001025
Vivien Didelotfad09c72016-06-21 12:28:20 -04001026 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001027}
Ben Hutchings98e67302011-11-25 14:36:19 +00001028
Andrew Lunnde2273872016-11-21 23:27:01 +01001029static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1030{
1031 if (chip->info->ops->stats_set_histogram)
1032 return chip->info->ops->stats_set_histogram(chip);
1033
1034 return 0;
1035}
1036
Vivien Didelotf81ec902016-05-09 13:22:58 -04001037static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001038{
1039 return 32 * sizeof(u16);
1040}
1041
Vivien Didelotf81ec902016-05-09 13:22:58 -04001042static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1043 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001044{
Vivien Didelot04bed142016-08-31 18:06:13 -04001045 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001046 int err;
1047 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001048 u16 *p = _p;
1049 int i;
1050
1051 regs->version = 0;
1052
1053 memset(p, 0xff, 32 * sizeof(u16));
1054
Vivien Didelotfad09c72016-06-21 12:28:20 -04001055 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001056
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001057 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001058
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001059 err = mv88e6xxx_port_read(chip, port, i, &reg);
1060 if (!err)
1061 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001062 }
Vivien Didelot23062512016-05-09 13:22:45 -04001063
Vivien Didelotfad09c72016-06-21 12:28:20 -04001064 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001065}
1066
Vivien Didelotf81ec902016-05-09 13:22:58 -04001067static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1068 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001069{
Vivien Didelot04bed142016-08-31 18:06:13 -04001070 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001071 u16 reg;
1072 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001073
Vivien Didelotfad09c72016-06-21 12:28:20 -04001074 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001075 return -EOPNOTSUPP;
1076
Vivien Didelotfad09c72016-06-21 12:28:20 -04001077 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001078
Vivien Didelot9c938292016-08-15 17:19:02 -04001079 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1080 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001081 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001082
1083 e->eee_enabled = !!(reg & 0x0200);
1084 e->tx_lpi_enabled = !!(reg & 0x0100);
1085
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001086 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001087 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001088 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001089
Andrew Lunncca8b132015-04-02 04:06:39 +02001090 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001091out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001092 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001093
1094 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001095}
1096
Vivien Didelotf81ec902016-05-09 13:22:58 -04001097static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1098 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001099{
Vivien Didelot04bed142016-08-31 18:06:13 -04001100 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001101 u16 reg;
1102 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001103
Vivien Didelotfad09c72016-06-21 12:28:20 -04001104 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001105 return -EOPNOTSUPP;
1106
Vivien Didelotfad09c72016-06-21 12:28:20 -04001107 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001108
Vivien Didelot9c938292016-08-15 17:19:02 -04001109 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1110 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001111 goto out;
1112
Vivien Didelot9c938292016-08-15 17:19:02 -04001113 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001114 if (e->eee_enabled)
1115 reg |= 0x0200;
1116 if (e->tx_lpi_enabled)
1117 reg |= 0x0100;
1118
Vivien Didelot9c938292016-08-15 17:19:02 -04001119 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001120out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001121 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001122
Vivien Didelot9c938292016-08-15 17:19:02 -04001123 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001124}
1125
Vivien Didelotfad09c72016-06-21 12:28:20 -04001126static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001127{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001128 struct dsa_switch *ds = chip->ds;
Vivien Didelotfae8a252017-01-27 15:29:42 -05001129 struct net_device *bridge = ds->ports[port].bridge_dev;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001130 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001131 int i;
1132
1133 /* allow CPU port or DSA link(s) to send frames to every port */
1134 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001135 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001136 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001137 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001138 /* allow sending frames to every group member */
Vivien Didelotfae8a252017-01-27 15:29:42 -05001139 if (bridge && ds->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001140 output_ports |= BIT(i);
1141
1142 /* allow sending frames to CPU port and DSA link(s) */
1143 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1144 output_ports |= BIT(i);
1145 }
1146 }
1147
1148 /* prevent frames from going back out of the port they came in on */
1149 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001150
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001151 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001152}
1153
Vivien Didelotf81ec902016-05-09 13:22:58 -04001154static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1155 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001156{
Vivien Didelot04bed142016-08-31 18:06:13 -04001157 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001158 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001159 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001160
1161 switch (state) {
1162 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001163 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001164 break;
1165 case BR_STATE_BLOCKING:
1166 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001167 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001168 break;
1169 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001170 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001171 break;
1172 case BR_STATE_FORWARDING:
1173 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001174 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001175 break;
1176 }
1177
Vivien Didelotfad09c72016-06-21 12:28:20 -04001178 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001179 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001180 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001181
1182 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001183 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001184}
1185
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001186static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1187{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001188 int err;
1189
Vivien Didelotdaefc942017-03-11 16:12:54 -05001190 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1191 if (err)
1192 return err;
1193
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001194 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1195 if (err)
1196 return err;
1197
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001198 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1199}
1200
Vivien Didelot81228992017-03-30 17:37:08 -04001201static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1202{
1203 if (!mv88e6xxx_has_pvt(chip))
1204 return 0;
1205
1206 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1207 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1208 */
1209 return mv88e6xxx_g2_misc_4_bit_port(chip);
1210}
1211
Vivien Didelot749efcb2016-09-22 16:49:24 -04001212static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1213{
1214 struct mv88e6xxx_chip *chip = ds->priv;
1215 int err;
1216
1217 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001218 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001219 mutex_unlock(&chip->reg_lock);
1220
1221 if (err)
1222 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1223}
1224
Vivien Didelotfad09c72016-06-21 12:28:20 -04001225static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001226{
Vivien Didelota935c052016-09-29 12:21:53 -04001227 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001228}
1229
Vivien Didelotfad09c72016-06-21 12:28:20 -04001230static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001231{
Vivien Didelota935c052016-09-29 12:21:53 -04001232 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001233
Vivien Didelota935c052016-09-29 12:21:53 -04001234 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1235 if (err)
1236 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001237
Vivien Didelotfad09c72016-06-21 12:28:20 -04001238 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001239}
1240
Vivien Didelotfad09c72016-06-21 12:28:20 -04001241static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001242{
1243 int ret;
1244
Vivien Didelotfad09c72016-06-21 12:28:20 -04001245 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001246 if (ret < 0)
1247 return ret;
1248
Vivien Didelotfad09c72016-06-21 12:28:20 -04001249 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001250}
1251
Vivien Didelotfad09c72016-06-21 12:28:20 -04001252static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001253 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001254 unsigned int nibble_offset)
1255{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001256 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001257 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001258
1259 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001260 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001261
Vivien Didelota935c052016-09-29 12:21:53 -04001262 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1263 if (err)
1264 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001265 }
1266
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001267 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001268 unsigned int shift = (i % 4) * 4 + nibble_offset;
1269 u16 reg = regs[i / 4];
1270
1271 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1272 }
1273
1274 return 0;
1275}
1276
Vivien Didelotfad09c72016-06-21 12:28:20 -04001277static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001278 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001279{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001280 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001281}
1282
Vivien Didelotfad09c72016-06-21 12:28:20 -04001283static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001284 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001285{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001286 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001287}
1288
Vivien Didelotfad09c72016-06-21 12:28:20 -04001289static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001290 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001291 unsigned int nibble_offset)
1292{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001293 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001294 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001295
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001296 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001297 unsigned int shift = (i % 4) * 4 + nibble_offset;
1298 u8 data = entry->data[i];
1299
1300 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1301 }
1302
1303 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001304 u16 reg = regs[i];
1305
1306 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1307 if (err)
1308 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001309 }
1310
1311 return 0;
1312}
1313
Vivien Didelotfad09c72016-06-21 12:28:20 -04001314static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001315 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001316{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001317 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001318}
1319
Vivien Didelotfad09c72016-06-21 12:28:20 -04001320static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001321 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001322{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001323 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001324}
1325
Vivien Didelotfad09c72016-06-21 12:28:20 -04001326static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001327{
Vivien Didelota935c052016-09-29 12:21:53 -04001328 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1329 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001330}
1331
Vivien Didelotfad09c72016-06-21 12:28:20 -04001332static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001333 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001334{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001335 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001336 u16 val;
1337 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001338
Vivien Didelota935c052016-09-29 12:21:53 -04001339 err = _mv88e6xxx_vtu_wait(chip);
1340 if (err)
1341 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001342
Vivien Didelota935c052016-09-29 12:21:53 -04001343 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1344 if (err)
1345 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001346
Vivien Didelota935c052016-09-29 12:21:53 -04001347 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1348 if (err)
1349 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001350
Vivien Didelota935c052016-09-29 12:21:53 -04001351 next.vid = val & GLOBAL_VTU_VID_MASK;
1352 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001353
1354 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001355 err = mv88e6xxx_vtu_data_read(chip, &next);
1356 if (err)
1357 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001358
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001359 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001360 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1361 if (err)
1362 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001363
Vivien Didelota935c052016-09-29 12:21:53 -04001364 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001365 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001366 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1367 * VTU DBNum[3:0] are located in VTU Operation 3:0
1368 */
Vivien Didelota935c052016-09-29 12:21:53 -04001369 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1370 if (err)
1371 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001372
Vivien Didelota935c052016-09-29 12:21:53 -04001373 next.fid = (val & 0xf00) >> 4;
1374 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001375 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001376
Vivien Didelotfad09c72016-06-21 12:28:20 -04001377 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001378 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1379 if (err)
1380 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001381
Vivien Didelota935c052016-09-29 12:21:53 -04001382 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001383 }
1384 }
1385
1386 *entry = next;
1387 return 0;
1388}
1389
Vivien Didelotf81ec902016-05-09 13:22:58 -04001390static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1391 struct switchdev_obj_port_vlan *vlan,
1392 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001393{
Vivien Didelot04bed142016-08-31 18:06:13 -04001394 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001395 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001396 u16 pvid;
1397 int err;
1398
Vivien Didelotfad09c72016-06-21 12:28:20 -04001399 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001400 return -EOPNOTSUPP;
1401
Vivien Didelotfad09c72016-06-21 12:28:20 -04001402 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001403
Vivien Didelot77064f32016-11-04 03:23:30 +01001404 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001405 if (err)
1406 goto unlock;
1407
Vivien Didelotfad09c72016-06-21 12:28:20 -04001408 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001409 if (err)
1410 goto unlock;
1411
1412 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001413 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001414 if (err)
1415 break;
1416
1417 if (!next.valid)
1418 break;
1419
1420 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1421 continue;
1422
1423 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001424 vlan->vid_begin = next.vid;
1425 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001426 vlan->flags = 0;
1427
1428 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1429 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1430
1431 if (next.vid == pvid)
1432 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1433
1434 err = cb(&vlan->obj);
1435 if (err)
1436 break;
1437 } while (next.vid < GLOBAL_VTU_VID_MASK);
1438
1439unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001440 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001441
1442 return err;
1443}
1444
Vivien Didelotfad09c72016-06-21 12:28:20 -04001445static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001446 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001447{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001448 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001449 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001450 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001451
Vivien Didelota935c052016-09-29 12:21:53 -04001452 err = _mv88e6xxx_vtu_wait(chip);
1453 if (err)
1454 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001455
1456 if (!entry->valid)
1457 goto loadpurge;
1458
1459 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001460 err = mv88e6xxx_vtu_data_write(chip, entry);
1461 if (err)
1462 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001463
Vivien Didelotfad09c72016-06-21 12:28:20 -04001464 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001465 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001466 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1467 if (err)
1468 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001469 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001470
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001471 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001472 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001473 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1474 if (err)
1475 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001476 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001477 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1478 * VTU DBNum[3:0] are located in VTU Operation 3:0
1479 */
1480 op |= (entry->fid & 0xf0) << 8;
1481 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001482 }
1483
1484 reg = GLOBAL_VTU_VID_VALID;
1485loadpurge:
1486 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001487 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1488 if (err)
1489 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001490
Vivien Didelotfad09c72016-06-21 12:28:20 -04001491 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001492}
1493
Vivien Didelotfad09c72016-06-21 12:28:20 -04001494static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001495 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001496{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001497 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001498 u16 val;
1499 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001500
Vivien Didelota935c052016-09-29 12:21:53 -04001501 err = _mv88e6xxx_vtu_wait(chip);
1502 if (err)
1503 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001504
Vivien Didelota935c052016-09-29 12:21:53 -04001505 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1506 sid & GLOBAL_VTU_SID_MASK);
1507 if (err)
1508 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001509
Vivien Didelota935c052016-09-29 12:21:53 -04001510 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1511 if (err)
1512 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001513
Vivien Didelota935c052016-09-29 12:21:53 -04001514 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1515 if (err)
1516 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001517
Vivien Didelota935c052016-09-29 12:21:53 -04001518 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001519
Vivien Didelota935c052016-09-29 12:21:53 -04001520 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1521 if (err)
1522 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001523
Vivien Didelota935c052016-09-29 12:21:53 -04001524 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001525
1526 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001527 err = mv88e6xxx_stu_data_read(chip, &next);
1528 if (err)
1529 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001530 }
1531
1532 *entry = next;
1533 return 0;
1534}
1535
Vivien Didelotfad09c72016-06-21 12:28:20 -04001536static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001537 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001538{
1539 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001540 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001541
Vivien Didelota935c052016-09-29 12:21:53 -04001542 err = _mv88e6xxx_vtu_wait(chip);
1543 if (err)
1544 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001545
1546 if (!entry->valid)
1547 goto loadpurge;
1548
1549 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001550 err = mv88e6xxx_stu_data_write(chip, entry);
1551 if (err)
1552 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001553
1554 reg = GLOBAL_VTU_VID_VALID;
1555loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001556 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1557 if (err)
1558 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001559
1560 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001561 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1562 if (err)
1563 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001564
Vivien Didelotfad09c72016-06-21 12:28:20 -04001565 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001566}
1567
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001568static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001569{
1570 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001571 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001572 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001573
1574 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1575
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001576 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001577 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001578 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001579 if (err)
1580 return err;
1581
1582 set_bit(*fid, fid_bitmap);
1583 }
1584
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001585 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001586 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001587 if (err)
1588 return err;
1589
1590 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001591 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001592 if (err)
1593 return err;
1594
1595 if (!vlan.valid)
1596 break;
1597
1598 set_bit(vlan.fid, fid_bitmap);
1599 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1600
1601 /* The reset value 0x000 is used to indicate that multiple address
1602 * databases are not needed. Return the next positive available.
1603 */
1604 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001605 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001606 return -ENOSPC;
1607
1608 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001609 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001610}
1611
Vivien Didelotfad09c72016-06-21 12:28:20 -04001612static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001613 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001614{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001615 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001616 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001617 .valid = true,
1618 .vid = vid,
1619 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001620 int i, err;
1621
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001622 err = mv88e6xxx_atu_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001623 if (err)
1624 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001625
Vivien Didelot3d131f02015-11-03 10:52:52 -05001626 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001627 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001628 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1629 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1630 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001631
Vivien Didelotfad09c72016-06-21 12:28:20 -04001632 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01001633 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip) ||
1634 mv88e6xxx_6341_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001635 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001636
1637 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1638 * implemented, only one STU entry is needed to cover all VTU
1639 * entries. Thus, validate the SID 0.
1640 */
1641 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001642 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001643 if (err)
1644 return err;
1645
1646 if (vstp.sid != vlan.sid || !vstp.valid) {
1647 memset(&vstp, 0, sizeof(vstp));
1648 vstp.valid = true;
1649 vstp.sid = vlan.sid;
1650
Vivien Didelotfad09c72016-06-21 12:28:20 -04001651 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001652 if (err)
1653 return err;
1654 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001655 }
1656
1657 *entry = vlan;
1658 return 0;
1659}
1660
Vivien Didelotfad09c72016-06-21 12:28:20 -04001661static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001662 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001663{
1664 int err;
1665
1666 if (!vid)
1667 return -EINVAL;
1668
Vivien Didelotfad09c72016-06-21 12:28:20 -04001669 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001670 if (err)
1671 return err;
1672
Vivien Didelotfad09c72016-06-21 12:28:20 -04001673 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001674 if (err)
1675 return err;
1676
1677 if (entry->vid != vid || !entry->valid) {
1678 if (!creat)
1679 return -EOPNOTSUPP;
1680 /* -ENOENT would've been more appropriate, but switchdev expects
1681 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1682 */
1683
Vivien Didelotfad09c72016-06-21 12:28:20 -04001684 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001685 }
1686
1687 return err;
1688}
1689
Vivien Didelotda9c3592016-02-12 12:09:40 -05001690static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1691 u16 vid_begin, u16 vid_end)
1692{
Vivien Didelot04bed142016-08-31 18:06:13 -04001693 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001694 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001695 int i, err;
1696
1697 if (!vid_begin)
1698 return -EOPNOTSUPP;
1699
Vivien Didelotfad09c72016-06-21 12:28:20 -04001700 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001701
Vivien Didelotfad09c72016-06-21 12:28:20 -04001702 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001703 if (err)
1704 goto unlock;
1705
1706 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001707 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001708 if (err)
1709 goto unlock;
1710
1711 if (!vlan.valid)
1712 break;
1713
1714 if (vlan.vid > vid_end)
1715 break;
1716
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001717 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001718 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1719 continue;
1720
Andrew Lunn66e28092016-12-11 21:07:19 +01001721 if (!ds->ports[port].netdev)
1722 continue;
1723
Vivien Didelotda9c3592016-02-12 12:09:40 -05001724 if (vlan.data[i] ==
1725 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1726 continue;
1727
Vivien Didelotfae8a252017-01-27 15:29:42 -05001728 if (ds->ports[i].bridge_dev ==
1729 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001730 break; /* same bridge, check next VLAN */
1731
Vivien Didelotfae8a252017-01-27 15:29:42 -05001732 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001733 continue;
1734
Andrew Lunnc8b09802016-06-04 21:16:57 +02001735 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001736 "hardware VLAN %d already used by %s\n",
1737 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001738 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001739 err = -EOPNOTSUPP;
1740 goto unlock;
1741 }
1742 } while (vlan.vid < vid_end);
1743
1744unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001745 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001746
1747 return err;
1748}
1749
Vivien Didelotf81ec902016-05-09 13:22:58 -04001750static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1751 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001752{
Vivien Didelot04bed142016-08-31 18:06:13 -04001753 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001754 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001755 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001756 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001757
Vivien Didelotfad09c72016-06-21 12:28:20 -04001758 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001759 return -EOPNOTSUPP;
1760
Vivien Didelotfad09c72016-06-21 12:28:20 -04001761 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001762 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001763 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001764
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001765 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001766}
1767
Vivien Didelot57d32312016-06-20 13:13:58 -04001768static int
1769mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1770 const struct switchdev_obj_port_vlan *vlan,
1771 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001772{
Vivien Didelot04bed142016-08-31 18:06:13 -04001773 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001774 int err;
1775
Vivien Didelotfad09c72016-06-21 12:28:20 -04001776 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001777 return -EOPNOTSUPP;
1778
Vivien Didelotda9c3592016-02-12 12:09:40 -05001779 /* If the requested port doesn't belong to the same bridge as the VLAN
1780 * members, do not support it (yet) and fallback to software VLAN.
1781 */
1782 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1783 vlan->vid_end);
1784 if (err)
1785 return err;
1786
Vivien Didelot76e398a2015-11-01 12:33:55 -05001787 /* We don't need any dynamic resource from the kernel (yet),
1788 * so skip the prepare phase.
1789 */
1790 return 0;
1791}
1792
Vivien Didelotfad09c72016-06-21 12:28:20 -04001793static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001794 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001795{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001796 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001797 int err;
1798
Vivien Didelotfad09c72016-06-21 12:28:20 -04001799 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001800 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001801 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001802
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001803 vlan.data[port] = untagged ?
1804 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1805 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1806
Vivien Didelotfad09c72016-06-21 12:28:20 -04001807 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001808}
1809
Vivien Didelotf81ec902016-05-09 13:22:58 -04001810static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1811 const struct switchdev_obj_port_vlan *vlan,
1812 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001813{
Vivien Didelot04bed142016-08-31 18:06:13 -04001814 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001815 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1816 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1817 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001818
Vivien Didelotfad09c72016-06-21 12:28:20 -04001819 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001820 return;
1821
Vivien Didelotfad09c72016-06-21 12:28:20 -04001822 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001823
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001824 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001825 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001826 netdev_err(ds->ports[port].netdev,
1827 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001828 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001829
Vivien Didelot77064f32016-11-04 03:23:30 +01001830 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001831 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001832 vlan->vid_end);
1833
Vivien Didelotfad09c72016-06-21 12:28:20 -04001834 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001835}
1836
Vivien Didelotfad09c72016-06-21 12:28:20 -04001837static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001838 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001839{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001840 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001841 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001842 int i, err;
1843
Vivien Didelotfad09c72016-06-21 12:28:20 -04001844 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001845 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001846 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001847
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001848 /* Tell switchdev if this VLAN is handled in software */
1849 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001850 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001851
1852 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1853
1854 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001855 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001856 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001857 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001858 continue;
1859
1860 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001861 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001862 break;
1863 }
1864 }
1865
Vivien Didelotfad09c72016-06-21 12:28:20 -04001866 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001867 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001868 return err;
1869
Vivien Didelote606ca32017-03-11 16:12:55 -05001870 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001871}
1872
Vivien Didelotf81ec902016-05-09 13:22:58 -04001873static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1874 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001875{
Vivien Didelot04bed142016-08-31 18:06:13 -04001876 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001877 u16 pvid, vid;
1878 int err = 0;
1879
Vivien Didelotfad09c72016-06-21 12:28:20 -04001880 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001881 return -EOPNOTSUPP;
1882
Vivien Didelotfad09c72016-06-21 12:28:20 -04001883 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001884
Vivien Didelot77064f32016-11-04 03:23:30 +01001885 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001886 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001887 goto unlock;
1888
Vivien Didelot76e398a2015-11-01 12:33:55 -05001889 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001890 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001891 if (err)
1892 goto unlock;
1893
1894 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001895 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001896 if (err)
1897 goto unlock;
1898 }
1899 }
1900
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001901unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001902 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001903
1904 return err;
1905}
1906
Vivien Didelot83dabd12016-08-31 11:50:04 -04001907static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1908 const unsigned char *addr, u16 vid,
1909 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001910{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001911 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001912 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001913 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001914
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001915 /* Null VLAN ID corresponds to the port private database */
1916 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001917 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001918 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04001919 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001920 if (err)
1921 return err;
1922
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001923 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1924 ether_addr_copy(entry.mac, addr);
1925 eth_addr_dec(entry.mac);
1926
1927 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001928 if (err)
1929 return err;
1930
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001931 /* Initialize a fresh ATU entry if it isn't found */
1932 if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
1933 !ether_addr_equal(entry.mac, addr)) {
1934 memset(&entry, 0, sizeof(entry));
1935 ether_addr_copy(entry.mac, addr);
1936 }
1937
Vivien Didelot88472932016-09-19 19:56:11 -04001938 /* Purge the ATU entry only if no port is using it anymore */
1939 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001940 entry.portvec &= ~BIT(port);
1941 if (!entry.portvec)
Vivien Didelot88472932016-09-19 19:56:11 -04001942 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1943 } else {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001944 entry.portvec |= BIT(port);
Vivien Didelot88472932016-09-19 19:56:11 -04001945 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001946 }
1947
Vivien Didelot9c13c022017-03-11 16:12:52 -05001948 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001949}
1950
Vivien Didelotf81ec902016-05-09 13:22:58 -04001951static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1952 const struct switchdev_obj_port_fdb *fdb,
1953 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001954{
1955 /* We don't need any dynamic resource from the kernel (yet),
1956 * so skip the prepare phase.
1957 */
1958 return 0;
1959}
1960
Vivien Didelotf81ec902016-05-09 13:22:58 -04001961static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1962 const struct switchdev_obj_port_fdb *fdb,
1963 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001964{
Vivien Didelot04bed142016-08-31 18:06:13 -04001965 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04001966
Vivien Didelotfad09c72016-06-21 12:28:20 -04001967 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001968 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1969 GLOBAL_ATU_DATA_STATE_UC_STATIC))
1970 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04001971 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001972}
1973
Vivien Didelotf81ec902016-05-09 13:22:58 -04001974static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1975 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07001976{
Vivien Didelot04bed142016-08-31 18:06:13 -04001977 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04001978 int err;
David S. Millercdf09692015-08-11 12:00:37 -07001979
Vivien Didelotfad09c72016-06-21 12:28:20 -04001980 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001981 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1982 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001983 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07001984
Vivien Didelot83dabd12016-08-31 11:50:04 -04001985 return err;
David S. Millercdf09692015-08-11 12:00:37 -07001986}
1987
Vivien Didelot83dabd12016-08-31 11:50:04 -04001988static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
1989 u16 fid, u16 vid, int port,
1990 struct switchdev_obj *obj,
1991 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001992{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001993 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001994 int err;
1995
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001996 addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1997 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05001998
1999 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002000 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002001 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002002 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002003
2004 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2005 break;
2006
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002007 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002008 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002009
Vivien Didelot83dabd12016-08-31 11:50:04 -04002010 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2011 struct switchdev_obj_port_fdb *fdb;
2012
2013 if (!is_unicast_ether_addr(addr.mac))
2014 continue;
2015
2016 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002017 fdb->vid = vid;
2018 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002019 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2020 fdb->ndm_state = NUD_NOARP;
2021 else
2022 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002023 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2024 struct switchdev_obj_port_mdb *mdb;
2025
2026 if (!is_multicast_ether_addr(addr.mac))
2027 continue;
2028
2029 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2030 mdb->vid = vid;
2031 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002032 } else {
2033 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002034 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002035
2036 err = cb(obj);
2037 if (err)
2038 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002039 } while (!is_broadcast_ether_addr(addr.mac));
2040
2041 return err;
2042}
2043
Vivien Didelot83dabd12016-08-31 11:50:04 -04002044static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2045 struct switchdev_obj *obj,
2046 int (*cb)(struct switchdev_obj *obj))
2047{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002048 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002049 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2050 };
2051 u16 fid;
2052 int err;
2053
2054 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002055 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002056 if (err)
2057 return err;
2058
2059 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2060 if (err)
2061 return err;
2062
2063 /* Dump VLANs' Filtering Information Databases */
2064 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2065 if (err)
2066 return err;
2067
2068 do {
2069 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2070 if (err)
2071 return err;
2072
2073 if (!vlan.valid)
2074 break;
2075
2076 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2077 obj, cb);
2078 if (err)
2079 return err;
2080 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2081
2082 return err;
2083}
2084
Vivien Didelotf81ec902016-05-09 13:22:58 -04002085static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2086 struct switchdev_obj_port_fdb *fdb,
2087 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002088{
Vivien Didelot04bed142016-08-31 18:06:13 -04002089 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002090 int err;
2091
Vivien Didelotfad09c72016-06-21 12:28:20 -04002092 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002093 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002094 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002095
2096 return err;
2097}
2098
Vivien Didelotf81ec902016-05-09 13:22:58 -04002099static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002100 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002101{
Vivien Didelot04bed142016-08-31 18:06:13 -04002102 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002103 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002104
Vivien Didelotfad09c72016-06-21 12:28:20 -04002105 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002106
Vivien Didelotfae8a252017-01-27 15:29:42 -05002107 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002108 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfae8a252017-01-27 15:29:42 -05002109 if (ds->ports[i].bridge_dev == br) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002110 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002111 if (err)
2112 break;
2113 }
2114 }
2115
Vivien Didelotfad09c72016-06-21 12:28:20 -04002116 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002117
Vivien Didelot466dfa02016-02-26 13:16:05 -05002118 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002119}
2120
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002121static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2122 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002123{
Vivien Didelot04bed142016-08-31 18:06:13 -04002124 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002125 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002126
Vivien Didelotfad09c72016-06-21 12:28:20 -04002127 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002128
Vivien Didelotfae8a252017-01-27 15:29:42 -05002129 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002130 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfae8a252017-01-27 15:29:42 -05002131 if (i == port || ds->ports[i].bridge_dev == br)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002132 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002133 netdev_warn(ds->ports[i].netdev,
2134 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002135
Vivien Didelotfad09c72016-06-21 12:28:20 -04002136 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002137}
2138
Vivien Didelot17e708b2016-12-05 17:30:27 -05002139static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2140{
2141 if (chip->info->ops->reset)
2142 return chip->info->ops->reset(chip);
2143
2144 return 0;
2145}
2146
Vivien Didelot309eca62016-12-05 17:30:26 -05002147static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2148{
2149 struct gpio_desc *gpiod = chip->reset;
2150
2151 /* If there is a GPIO connected to the reset pin, toggle it */
2152 if (gpiod) {
2153 gpiod_set_value_cansleep(gpiod, 1);
2154 usleep_range(10000, 20000);
2155 gpiod_set_value_cansleep(gpiod, 0);
2156 usleep_range(10000, 20000);
2157 }
2158}
2159
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002160static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2161{
2162 int i, err;
2163
2164 /* Set all ports to the Disabled state */
2165 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2166 err = mv88e6xxx_port_set_state(chip, i,
2167 PORT_CONTROL_STATE_DISABLED);
2168 if (err)
2169 return err;
2170 }
2171
2172 /* Wait for transmit queues to drain,
2173 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2174 */
2175 usleep_range(2000, 4000);
2176
2177 return 0;
2178}
2179
Vivien Didelotfad09c72016-06-21 12:28:20 -04002180static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002181{
Vivien Didelota935c052016-09-29 12:21:53 -04002182 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002183
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002184 err = mv88e6xxx_disable_ports(chip);
2185 if (err)
2186 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002187
Vivien Didelot309eca62016-12-05 17:30:26 -05002188 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002189
Vivien Didelot17e708b2016-12-05 17:30:27 -05002190 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002191}
2192
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002193static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002194{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002195 u16 val;
2196 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002197
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002198 /* Clear Power Down bit */
2199 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2200 if (err)
2201 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002202
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002203 if (val & BMCR_PDOWN) {
2204 val &= ~BMCR_PDOWN;
2205 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002206 }
2207
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002208 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002209}
2210
Vivien Didelot43145572017-03-11 16:12:59 -05002211static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2212 enum mv88e6xxx_frame_mode frame, u16 egress,
2213 u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002214{
2215 int err;
2216
Vivien Didelot43145572017-03-11 16:12:59 -05002217 if (!chip->info->ops->port_set_frame_mode)
2218 return -EOPNOTSUPP;
2219
2220 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002221 if (err)
2222 return err;
2223
Vivien Didelot43145572017-03-11 16:12:59 -05002224 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2225 if (err)
2226 return err;
2227
2228 if (chip->info->ops->port_set_ether_type)
2229 return chip->info->ops->port_set_ether_type(chip, port, etype);
2230
2231 return 0;
2232}
2233
2234static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2235{
2236 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2237 PORT_CONTROL_EGRESS_UNMODIFIED,
2238 PORT_ETH_TYPE_DEFAULT);
2239}
2240
2241static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2242{
2243 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2244 PORT_CONTROL_EGRESS_UNMODIFIED,
2245 PORT_ETH_TYPE_DEFAULT);
2246}
2247
2248static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2249{
2250 return mv88e6xxx_set_port_mode(chip, port,
2251 MV88E6XXX_FRAME_MODE_ETHERTYPE,
2252 PORT_CONTROL_EGRESS_ADD_TAG, ETH_P_EDSA);
2253}
2254
2255static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2256{
2257 if (dsa_is_dsa_port(chip->ds, port))
2258 return mv88e6xxx_set_port_mode_dsa(chip, port);
2259
2260 if (dsa_is_normal_port(chip->ds, port))
2261 return mv88e6xxx_set_port_mode_normal(chip, port);
2262
2263 /* Setup CPU port mode depending on its supported tag format */
2264 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2265 return mv88e6xxx_set_port_mode_dsa(chip, port);
2266
2267 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2268 return mv88e6xxx_set_port_mode_edsa(chip, port);
2269
2270 return -EINVAL;
2271}
2272
Vivien Didelotea698f42017-03-11 16:12:50 -05002273static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2274{
2275 bool message = dsa_is_dsa_port(chip->ds, port);
2276
2277 return mv88e6xxx_port_set_message_port(chip, port, message);
2278}
2279
Vivien Didelot601aeed2017-03-11 16:13:00 -05002280static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2281{
2282 bool flood = port == dsa_upstream_port(chip->ds);
2283
2284 /* Upstream ports flood frames with unknown unicast or multicast DA */
2285 if (chip->info->ops->port_set_egress_floods)
2286 return chip->info->ops->port_set_egress_floods(chip, port,
2287 flood, flood);
2288
2289 return 0;
2290}
2291
Vivien Didelotfad09c72016-06-21 12:28:20 -04002292static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002293{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002294 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002295 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002296 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002297
Vivien Didelotd78343d2016-11-04 03:23:36 +01002298 /* MAC Forcing register: don't force link, speed, duplex or flow control
2299 * state to any particular values on physical ports, but force the CPU
2300 * port and all DSA ports to their maximum bandwidth and full duplex.
2301 */
2302 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2303 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2304 SPEED_MAX, DUPLEX_FULL,
2305 PHY_INTERFACE_MODE_NA);
2306 else
2307 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2308 SPEED_UNFORCED, DUPLEX_UNFORCED,
2309 PHY_INTERFACE_MODE_NA);
2310 if (err)
2311 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002312
2313 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2314 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2315 * tunneling, determine priority by looking at 802.1p and IP
2316 * priority fields (IP prio has precedence), and set STP state
2317 * to Forwarding.
2318 *
2319 * If this is the CPU link, use DSA or EDSA tagging depending
2320 * on which tagging mode was configured.
2321 *
2322 * If this is a link to another switch, use DSA tagging mode.
2323 *
2324 * If this is the upstream port for this switch, enable
2325 * forwarding of unknown unicasts and multicasts.
2326 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002327 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002328 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2329 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002330 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2331 if (err)
2332 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002333
Vivien Didelot601aeed2017-03-11 16:13:00 -05002334 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002335 if (err)
2336 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002337
Vivien Didelot601aeed2017-03-11 16:13:00 -05002338 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002339 if (err)
2340 return err;
2341
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002342 /* If this port is connected to a SerDes, make sure the SerDes is not
2343 * powered down.
2344 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002345 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002346 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2347 if (err)
2348 return err;
2349 reg &= PORT_STATUS_CMODE_MASK;
2350 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2351 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2352 (reg == PORT_STATUS_CMODE_SGMII)) {
2353 err = mv88e6xxx_serdes_power_on(chip);
2354 if (err < 0)
2355 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002356 }
2357 }
2358
Vivien Didelot8efdda42015-08-13 12:52:23 -04002359 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002360 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002361 * untagged frames on this port, do a destination address lookup on all
2362 * received packets as usual, disable ARP mirroring and don't send a
2363 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002364 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002365 err = mv88e6xxx_port_set_map_da(chip, port);
2366 if (err)
2367 return err;
2368
Andrew Lunn54d792f2015-05-06 01:09:47 +02002369 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01002370 if (chip->info->ops->port_set_upstream_port) {
2371 err = chip->info->ops->port_set_upstream_port(
2372 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002373 if (err)
2374 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002375 }
2376
Andrew Lunna23b2962017-02-04 20:15:28 +01002377 err = mv88e6xxx_port_set_8021q_mode(chip, port,
2378 PORT_CONTROL_2_8021Q_DISABLED);
2379 if (err)
2380 return err;
2381
Andrew Lunn5f436662016-12-03 04:45:17 +01002382 if (chip->info->ops->port_jumbo_config) {
2383 err = chip->info->ops->port_jumbo_config(chip, port);
2384 if (err)
2385 return err;
2386 }
2387
Andrew Lunn54d792f2015-05-06 01:09:47 +02002388 /* Port Association Vector: when learning source addresses
2389 * of packets, add the address to the address database using
2390 * a port bitmap that has only the bit for this port set and
2391 * the other bits clear.
2392 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002393 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002394 /* Disable learning for CPU port */
2395 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002396 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002397
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002398 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2399 if (err)
2400 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002401
2402 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002403 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2404 if (err)
2405 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002406
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002407 if (chip->info->ops->port_pause_config) {
2408 err = chip->info->ops->port_pause_config(chip, port);
2409 if (err)
2410 return err;
2411 }
2412
Vivien Didelotc8c94892017-03-11 16:13:01 -05002413 if (chip->info->ops->port_disable_learn_limit) {
2414 err = chip->info->ops->port_disable_learn_limit(chip, port);
2415 if (err)
2416 return err;
2417 }
2418
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002419 if (chip->info->ops->port_disable_pri_override) {
2420 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002421 if (err)
2422 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002423 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002424
Andrew Lunnef0a7312016-12-03 04:35:16 +01002425 if (chip->info->ops->port_tag_remap) {
2426 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002427 if (err)
2428 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002429 }
2430
Andrew Lunnef70b112016-12-03 04:45:18 +01002431 if (chip->info->ops->port_egress_rate_limiting) {
2432 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002433 if (err)
2434 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002435 }
2436
Vivien Didelotea698f42017-03-11 16:12:50 -05002437 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002438 if (err)
2439 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002440
Vivien Didelot207afda2016-04-14 14:42:09 -04002441 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002442 * database, and allow bidirectional communication between the
2443 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002444 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002445 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002446 if (err)
2447 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002448
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002449 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2450 if (err)
2451 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002452
2453 /* Default VLAN ID and priority: don't set a default VLAN
2454 * ID, and set the default packet priority to zero.
2455 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002456 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002457}
2458
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002459static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002460{
2461 int err;
2462
Vivien Didelota935c052016-09-29 12:21:53 -04002463 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002464 if (err)
2465 return err;
2466
Vivien Didelota935c052016-09-29 12:21:53 -04002467 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002468 if (err)
2469 return err;
2470
Vivien Didelota935c052016-09-29 12:21:53 -04002471 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2472 if (err)
2473 return err;
2474
2475 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002476}
2477
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002478static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2479 unsigned int ageing_time)
2480{
Vivien Didelot04bed142016-08-31 18:06:13 -04002481 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002482 int err;
2483
2484 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002485 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002486 mutex_unlock(&chip->reg_lock);
2487
2488 return err;
2489}
2490
Vivien Didelot97299342016-07-18 20:45:30 -04002491static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002492{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002493 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002494 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002495 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002496
Vivien Didelot119477b2016-05-09 13:22:51 -04002497 /* Enable the PHY Polling Unit if present, don't discard any packets,
2498 * and mask all interrupt sources.
2499 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002500 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002501 if (err)
2502 return err;
2503
Andrew Lunn33641992016-12-03 04:35:17 +01002504 if (chip->info->ops->g1_set_cpu_port) {
2505 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2506 if (err)
2507 return err;
2508 }
2509
2510 if (chip->info->ops->g1_set_egress_port) {
2511 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2512 if (err)
2513 return err;
2514 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002515
Vivien Didelot50484ff2016-05-09 13:22:54 -04002516 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002517 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2518 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2519 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002520 if (err)
2521 return err;
2522
Vivien Didelotacddbd22016-07-18 20:45:39 -04002523 /* Clear all the VTU and STU entries */
2524 err = _mv88e6xxx_vtu_stu_flush(chip);
2525 if (err < 0)
2526 return err;
2527
Vivien Didelot08a01262016-05-09 13:22:50 -04002528 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002529 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002530 if (err)
2531 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002532 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002533 if (err)
2534 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002535 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002536 if (err)
2537 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002538 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002539 if (err)
2540 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002541 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002542 if (err)
2543 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002544 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002545 if (err)
2546 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002547 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002548 if (err)
2549 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002550 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002551 if (err)
2552 return err;
2553
2554 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002555 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002556 if (err)
2557 return err;
2558
Andrew Lunnde2273872016-11-21 23:27:01 +01002559 /* Initialize the statistics unit */
2560 err = mv88e6xxx_stats_set_histogram(chip);
2561 if (err)
2562 return err;
2563
Vivien Didelot97299342016-07-18 20:45:30 -04002564 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002565 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2566 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002567 if (err)
2568 return err;
2569
2570 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002571 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002572 if (err)
2573 return err;
2574
2575 return 0;
2576}
2577
Vivien Didelotf81ec902016-05-09 13:22:58 -04002578static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002579{
Vivien Didelot04bed142016-08-31 18:06:13 -04002580 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002581 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002582 int i;
2583
Vivien Didelotfad09c72016-06-21 12:28:20 -04002584 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002585 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002586
Vivien Didelotfad09c72016-06-21 12:28:20 -04002587 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002588
Vivien Didelot97299342016-07-18 20:45:30 -04002589 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002590 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002591 err = mv88e6xxx_setup_port(chip, i);
2592 if (err)
2593 goto unlock;
2594 }
2595
2596 /* Setup Switch Global 1 Registers */
2597 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002598 if (err)
2599 goto unlock;
2600
Vivien Didelot97299342016-07-18 20:45:30 -04002601 /* Setup Switch Global 2 Registers */
2602 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2603 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002604 if (err)
2605 goto unlock;
2606 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002607
Vivien Didelot81228992017-03-30 17:37:08 -04002608 err = mv88e6xxx_pvt_setup(chip);
2609 if (err)
2610 goto unlock;
2611
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002612 err = mv88e6xxx_atu_setup(chip);
2613 if (err)
2614 goto unlock;
2615
Andrew Lunn6e55f692016-12-03 04:45:16 +01002616 /* Some generations have the configuration of sending reserved
2617 * management frames to the CPU in global2, others in
2618 * global1. Hence it does not fit the two setup functions
2619 * above.
2620 */
2621 if (chip->info->ops->mgmt_rsvd2cpu) {
2622 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2623 if (err)
2624 goto unlock;
2625 }
2626
Vivien Didelot6b17e862015-08-13 12:52:18 -04002627unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002628 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002629
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002630 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002631}
2632
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002633static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2634{
Vivien Didelot04bed142016-08-31 18:06:13 -04002635 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002636 int err;
2637
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002638 if (!chip->info->ops->set_switch_mac)
2639 return -EOPNOTSUPP;
2640
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002641 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002642 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002643 mutex_unlock(&chip->reg_lock);
2644
2645 return err;
2646}
2647
Vivien Didelote57e5e72016-08-15 17:19:00 -04002648static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002649{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002650 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2651 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002652 u16 val;
2653 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002654
Andrew Lunnee26a222017-01-24 14:53:48 +01002655 if (!chip->info->ops->phy_read)
2656 return -EOPNOTSUPP;
2657
Vivien Didelotfad09c72016-06-21 12:28:20 -04002658 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002659 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002660 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002661
Andrew Lunnda9f3302017-02-01 03:40:05 +01002662 if (reg == MII_PHYSID2) {
2663 /* Some internal PHYS don't have a model number. Use
2664 * the mv88e6390 family model number instead.
2665 */
2666 if (!(val & 0x3f0))
2667 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2668 }
2669
Vivien Didelote57e5e72016-08-15 17:19:00 -04002670 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002671}
2672
Vivien Didelote57e5e72016-08-15 17:19:00 -04002673static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002674{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002675 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2676 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002677 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002678
Andrew Lunnee26a222017-01-24 14:53:48 +01002679 if (!chip->info->ops->phy_write)
2680 return -EOPNOTSUPP;
2681
Vivien Didelotfad09c72016-06-21 12:28:20 -04002682 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002683 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002684 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002685
2686 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002687}
2688
Vivien Didelotfad09c72016-06-21 12:28:20 -04002689static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002690 struct device_node *np,
2691 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002692{
2693 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002694 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002695 struct mii_bus *bus;
2696 int err;
2697
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002698 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002699 if (!bus)
2700 return -ENOMEM;
2701
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002702 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002703 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002704 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002705 INIT_LIST_HEAD(&mdio_bus->list);
2706 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002707
Andrew Lunnb516d452016-06-04 21:17:06 +02002708 if (np) {
2709 bus->name = np->full_name;
2710 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2711 } else {
2712 bus->name = "mv88e6xxx SMI";
2713 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2714 }
2715
2716 bus->read = mv88e6xxx_mdio_read;
2717 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002718 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002719
Andrew Lunna3c53be52017-01-24 14:53:50 +01002720 if (np)
2721 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002722 else
2723 err = mdiobus_register(bus);
2724 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002725 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002726 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002727 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002728
2729 if (external)
2730 list_add_tail(&mdio_bus->list, &chip->mdios);
2731 else
2732 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002733
2734 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002735}
2736
Andrew Lunna3c53be52017-01-24 14:53:50 +01002737static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2738 { .compatible = "marvell,mv88e6xxx-mdio-external",
2739 .data = (void *)true },
2740 { },
2741};
2742
2743static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2744 struct device_node *np)
2745{
2746 const struct of_device_id *match;
2747 struct device_node *child;
2748 int err;
2749
2750 /* Always register one mdio bus for the internal/default mdio
2751 * bus. This maybe represented in the device tree, but is
2752 * optional.
2753 */
2754 child = of_get_child_by_name(np, "mdio");
2755 err = mv88e6xxx_mdio_register(chip, child, false);
2756 if (err)
2757 return err;
2758
2759 /* Walk the device tree, and see if there are any other nodes
2760 * which say they are compatible with the external mdio
2761 * bus.
2762 */
2763 for_each_available_child_of_node(np, child) {
2764 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2765 if (match) {
2766 err = mv88e6xxx_mdio_register(chip, child, true);
2767 if (err)
2768 return err;
2769 }
2770 }
2771
2772 return 0;
2773}
2774
2775static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002776
2777{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002778 struct mv88e6xxx_mdio_bus *mdio_bus;
2779 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002780
Andrew Lunna3c53be52017-01-24 14:53:50 +01002781 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2782 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002783
Andrew Lunna3c53be52017-01-24 14:53:50 +01002784 mdiobus_unregister(bus);
2785 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002786}
2787
Vivien Didelot855b1932016-07-20 18:18:35 -04002788static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2789{
Vivien Didelot04bed142016-08-31 18:06:13 -04002790 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002791
2792 return chip->eeprom_len;
2793}
2794
Vivien Didelot855b1932016-07-20 18:18:35 -04002795static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2796 struct ethtool_eeprom *eeprom, u8 *data)
2797{
Vivien Didelot04bed142016-08-31 18:06:13 -04002798 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002799 int err;
2800
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002801 if (!chip->info->ops->get_eeprom)
2802 return -EOPNOTSUPP;
2803
Vivien Didelot855b1932016-07-20 18:18:35 -04002804 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002805 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002806 mutex_unlock(&chip->reg_lock);
2807
2808 if (err)
2809 return err;
2810
2811 eeprom->magic = 0xc3ec4951;
2812
2813 return 0;
2814}
2815
Vivien Didelot855b1932016-07-20 18:18:35 -04002816static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2817 struct ethtool_eeprom *eeprom, u8 *data)
2818{
Vivien Didelot04bed142016-08-31 18:06:13 -04002819 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002820 int err;
2821
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002822 if (!chip->info->ops->set_eeprom)
2823 return -EOPNOTSUPP;
2824
Vivien Didelot855b1932016-07-20 18:18:35 -04002825 if (eeprom->magic != 0xc3ec4951)
2826 return -EINVAL;
2827
2828 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002829 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002830 mutex_unlock(&chip->reg_lock);
2831
2832 return err;
2833}
2834
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002835static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002836 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002837 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002838 .phy_read = mv88e6xxx_phy_ppu_read,
2839 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002840 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002841 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002842 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002843 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002844 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002845 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002846 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002847 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002848 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002849 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002850 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002851 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002852 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2853 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002854 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002855 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2856 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002857 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002858 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002859 .ppu_enable = mv88e6185_g1_ppu_enable,
2860 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002861 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002862};
2863
2864static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002865 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002866 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002867 .phy_read = mv88e6xxx_phy_ppu_read,
2868 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002869 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002870 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002871 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002872 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002873 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002874 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002875 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002876 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2877 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002878 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002879 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002880 .ppu_enable = mv88e6185_g1_ppu_enable,
2881 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002882 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002883};
2884
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002885static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002886 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002887 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2888 .phy_read = mv88e6xxx_g2_smi_phy_read,
2889 .phy_write = mv88e6xxx_g2_smi_phy_write,
2890 .port_set_link = mv88e6xxx_port_set_link,
2891 .port_set_duplex = mv88e6xxx_port_set_duplex,
2892 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002893 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002894 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002895 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002896 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002897 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002898 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002899 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002900 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002901 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002902 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2903 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2904 .stats_get_strings = mv88e6095_stats_get_strings,
2905 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002906 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2907 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002908 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002909 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002910 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002911};
2912
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002913static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002914 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002915 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002916 .phy_read = mv88e6165_phy_read,
2917 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002918 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002919 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002920 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002921 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002922 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002923 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002924 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002925 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002926 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2927 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002928 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002929 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2930 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002931 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002932 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002933 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002934};
2935
2936static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002937 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002938 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002939 .phy_read = mv88e6xxx_phy_ppu_read,
2940 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002941 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002942 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002943 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002944 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002945 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002946 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002947 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002948 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01002949 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002950 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002951 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002952 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002953 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2954 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002955 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002956 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2957 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002958 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002959 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002960 .ppu_enable = mv88e6185_g1_ppu_enable,
2961 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002962 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002963};
2964
Vivien Didelot990e27b2017-03-28 13:50:32 -04002965static const struct mv88e6xxx_ops mv88e6141_ops = {
2966 /* MV88E6XXX_FAMILY_6341 */
2967 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2968 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2969 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2970 .phy_read = mv88e6xxx_g2_smi_phy_read,
2971 .phy_write = mv88e6xxx_g2_smi_phy_write,
2972 .port_set_link = mv88e6xxx_port_set_link,
2973 .port_set_duplex = mv88e6xxx_port_set_duplex,
2974 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2975 .port_set_speed = mv88e6390_port_set_speed,
2976 .port_tag_remap = mv88e6095_port_tag_remap,
2977 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2978 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2979 .port_set_ether_type = mv88e6351_port_set_ether_type,
2980 .port_jumbo_config = mv88e6165_port_jumbo_config,
2981 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
2982 .port_pause_config = mv88e6097_port_pause_config,
2983 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
2984 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
2985 .stats_snapshot = mv88e6390_g1_stats_snapshot,
2986 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
2987 .stats_get_strings = mv88e6320_stats_get_strings,
2988 .stats_get_stats = mv88e6390_stats_get_stats,
2989 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
2990 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
2991 .watchdog_ops = &mv88e6390_watchdog_ops,
2992 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
2993 .reset = mv88e6352_g1_reset,
2994};
2995
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002996static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002997 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002998 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002999 .phy_read = mv88e6165_phy_read,
3000 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003001 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003002 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003003 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003004 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003005 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003006 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003007 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003008 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003009 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003010 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003011 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003012 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003013 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003014 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3015 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003016 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003017 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3018 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003019 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003020 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003021 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003022};
3023
3024static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003025 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003026 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003027 .phy_read = mv88e6165_phy_read,
3028 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003029 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003030 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003031 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003032 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003033 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003034 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003035 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3036 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003037 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003038 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3039 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003040 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003041 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003042 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003043};
3044
3045static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003046 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003047 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003048 .phy_read = mv88e6xxx_g2_smi_phy_read,
3049 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003050 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003051 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003052 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003053 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003054 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003055 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003056 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003057 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003058 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003059 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003060 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003061 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003062 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003063 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003064 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3065 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003066 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003067 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3068 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003069 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003070 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003071 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003072};
3073
3074static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003075 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003076 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3077 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003078 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003079 .phy_read = mv88e6xxx_g2_smi_phy_read,
3080 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003081 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003082 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003083 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003084 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003085 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003086 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003087 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003088 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003089 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003090 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003091 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003092 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003093 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003094 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003095 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3096 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003097 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003098 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3099 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003100 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003101 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003102 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003103};
3104
3105static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003106 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003107 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003108 .phy_read = mv88e6xxx_g2_smi_phy_read,
3109 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003110 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003111 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003112 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003113 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003114 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003115 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003116 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003117 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003118 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003119 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003120 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003121 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003122 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003123 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003124 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3125 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003126 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003127 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3128 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003129 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003130 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003131 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003132};
3133
3134static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003135 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003136 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3137 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003138 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003139 .phy_read = mv88e6xxx_g2_smi_phy_read,
3140 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003141 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003142 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003143 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003144 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003145 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003146 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003147 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003148 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003149 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003150 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003151 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003152 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003153 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003154 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003155 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3156 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003157 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003158 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3159 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003160 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003161 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003162 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003163};
3164
3165static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003166 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003167 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003168 .phy_read = mv88e6xxx_phy_ppu_read,
3169 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003170 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003171 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003172 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003173 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003174 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003175 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003176 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
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 Lunnfcd25162017-02-09 00:03:42 +01003183 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003184 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003185 .ppu_enable = mv88e6185_g1_ppu_enable,
3186 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003187 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003188};
3189
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003190static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003191 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003192 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3193 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003194 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3195 .phy_read = mv88e6xxx_g2_smi_phy_read,
3196 .phy_write = mv88e6xxx_g2_smi_phy_write,
3197 .port_set_link = mv88e6xxx_port_set_link,
3198 .port_set_duplex = mv88e6xxx_port_set_duplex,
3199 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3200 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003201 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003202 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003203 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003204 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003205 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003206 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003207 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003208 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003209 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003210 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3211 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003212 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003213 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3214 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003215 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003216 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003217 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003218};
3219
3220static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003221 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003222 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3223 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003224 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3225 .phy_read = mv88e6xxx_g2_smi_phy_read,
3226 .phy_write = mv88e6xxx_g2_smi_phy_write,
3227 .port_set_link = mv88e6xxx_port_set_link,
3228 .port_set_duplex = mv88e6xxx_port_set_duplex,
3229 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3230 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003231 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003232 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003233 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003234 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003235 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003236 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003237 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003238 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003239 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003240 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3241 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003242 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003243 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3244 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003245 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003246 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003247 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003248};
3249
3250static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003251 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003252 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3253 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003254 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3255 .phy_read = mv88e6xxx_g2_smi_phy_read,
3256 .phy_write = mv88e6xxx_g2_smi_phy_write,
3257 .port_set_link = mv88e6xxx_port_set_link,
3258 .port_set_duplex = mv88e6xxx_port_set_duplex,
3259 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3260 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003261 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003262 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003263 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003264 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003265 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003266 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003267 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003268 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003269 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003270 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3271 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003272 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003273 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3274 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003275 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003276 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003277 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003278};
3279
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003280static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003281 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003282 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3283 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003284 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003285 .phy_read = mv88e6xxx_g2_smi_phy_read,
3286 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003287 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003288 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003289 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003290 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003291 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003292 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003293 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003294 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003295 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003296 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003297 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003298 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003299 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003300 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003301 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3302 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003303 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003304 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3305 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003306 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003307 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003308 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003309};
3310
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003311static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003312 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003313 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3314 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003315 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3316 .phy_read = mv88e6xxx_g2_smi_phy_read,
3317 .phy_write = mv88e6xxx_g2_smi_phy_write,
3318 .port_set_link = mv88e6xxx_port_set_link,
3319 .port_set_duplex = mv88e6xxx_port_set_duplex,
3320 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3321 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003322 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003323 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003324 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003325 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003326 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003327 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003328 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003329 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003330 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003331 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003332 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3333 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003334 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003335 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3336 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003337 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003338 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003339 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003340};
3341
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003342static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003343 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003344 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3345 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003346 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003347 .phy_read = mv88e6xxx_g2_smi_phy_read,
3348 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003349 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003350 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003351 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003352 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003353 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003354 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003355 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003356 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003357 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003358 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003359 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003360 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003361 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003362 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3363 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003364 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003365 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3366 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003367 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003368 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003369};
3370
3371static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003372 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003373 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3374 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003375 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003376 .phy_read = mv88e6xxx_g2_smi_phy_read,
3377 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003378 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003379 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003380 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003381 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003382 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003383 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003384 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003385 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003386 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003387 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003388 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003389 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003390 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003391 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3392 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003393 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003394 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3395 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003396 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003397};
3398
Vivien Didelot16e329a2017-03-28 13:50:33 -04003399static const struct mv88e6xxx_ops mv88e6341_ops = {
3400 /* MV88E6XXX_FAMILY_6341 */
3401 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3402 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3403 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3404 .phy_read = mv88e6xxx_g2_smi_phy_read,
3405 .phy_write = mv88e6xxx_g2_smi_phy_write,
3406 .port_set_link = mv88e6xxx_port_set_link,
3407 .port_set_duplex = mv88e6xxx_port_set_duplex,
3408 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3409 .port_set_speed = mv88e6390_port_set_speed,
3410 .port_tag_remap = mv88e6095_port_tag_remap,
3411 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3412 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3413 .port_set_ether_type = mv88e6351_port_set_ether_type,
3414 .port_jumbo_config = mv88e6165_port_jumbo_config,
3415 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3416 .port_pause_config = mv88e6097_port_pause_config,
3417 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3418 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3419 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3420 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3421 .stats_get_strings = mv88e6320_stats_get_strings,
3422 .stats_get_stats = mv88e6390_stats_get_stats,
3423 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3424 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3425 .watchdog_ops = &mv88e6390_watchdog_ops,
3426 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3427 .reset = mv88e6352_g1_reset,
3428};
3429
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003430static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003431 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003432 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003433 .phy_read = mv88e6xxx_g2_smi_phy_read,
3434 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003435 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003436 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003437 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003438 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003439 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003440 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003441 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003442 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003443 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003444 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003445 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003446 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003447 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003448 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003449 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3450 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003451 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003452 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3453 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003454 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003455 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003456 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003457};
3458
3459static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003460 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003461 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003462 .phy_read = mv88e6xxx_g2_smi_phy_read,
3463 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003464 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003465 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003466 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003467 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003468 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003469 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003470 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003471 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003472 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003473 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003474 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003475 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003476 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003477 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003478 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3479 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003480 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003481 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3482 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003483 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003484 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003485 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003486};
3487
3488static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003489 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003490 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3491 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003492 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003493 .phy_read = mv88e6xxx_g2_smi_phy_read,
3494 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003495 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003496 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003497 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003498 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003499 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003500 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003501 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003502 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003503 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003504 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003505 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003506 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003507 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003508 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003509 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3510 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003511 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003512 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3513 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003514 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003515 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003516 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003517};
3518
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003519static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003520 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003521 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3522 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003523 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3524 .phy_read = mv88e6xxx_g2_smi_phy_read,
3525 .phy_write = mv88e6xxx_g2_smi_phy_write,
3526 .port_set_link = mv88e6xxx_port_set_link,
3527 .port_set_duplex = mv88e6xxx_port_set_duplex,
3528 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3529 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003530 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003531 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003532 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003533 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003534 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003535 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003536 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003537 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003538 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003539 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003540 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003541 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003542 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3543 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003544 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003545 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3546 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003547 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003548 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003549 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003550};
3551
3552static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003553 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003554 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3555 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003556 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3557 .phy_read = mv88e6xxx_g2_smi_phy_read,
3558 .phy_write = mv88e6xxx_g2_smi_phy_write,
3559 .port_set_link = mv88e6xxx_port_set_link,
3560 .port_set_duplex = mv88e6xxx_port_set_duplex,
3561 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3562 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003563 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003564 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003565 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003566 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003567 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003568 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003569 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003570 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003571 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003572 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003573 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003574 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3575 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003576 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003577 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3578 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003579 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003580 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003581 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003582};
3583
Vivien Didelotf81ec902016-05-09 13:22:58 -04003584static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3585 [MV88E6085] = {
3586 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3587 .family = MV88E6XXX_FAMILY_6097,
3588 .name = "Marvell 88E6085",
3589 .num_databases = 4096,
3590 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003591 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003592 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003593 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003594 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003595 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003596 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003597 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003598 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003599 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003600 },
3601
3602 [MV88E6095] = {
3603 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3604 .family = MV88E6XXX_FAMILY_6095,
3605 .name = "Marvell 88E6095/88E6095F",
3606 .num_databases = 256,
3607 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003608 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003609 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003610 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003611 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003612 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003613 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003614 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003615 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003616 },
3617
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003618 [MV88E6097] = {
3619 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3620 .family = MV88E6XXX_FAMILY_6097,
3621 .name = "Marvell 88E6097/88E6097F",
3622 .num_databases = 4096,
3623 .num_ports = 11,
3624 .port_base_addr = 0x10,
3625 .global1_addr = 0x1b,
3626 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003627 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003628 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003629 .pvt = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003630 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003631 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3632 .ops = &mv88e6097_ops,
3633 },
3634
Vivien Didelotf81ec902016-05-09 13:22:58 -04003635 [MV88E6123] = {
3636 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3637 .family = MV88E6XXX_FAMILY_6165,
3638 .name = "Marvell 88E6123",
3639 .num_databases = 4096,
3640 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003641 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003642 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003643 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003644 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003645 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003646 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003647 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003648 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003649 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003650 },
3651
3652 [MV88E6131] = {
3653 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3654 .family = MV88E6XXX_FAMILY_6185,
3655 .name = "Marvell 88E6131",
3656 .num_databases = 256,
3657 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003658 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003659 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003660 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003661 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003662 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003663 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003664 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003665 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003666 },
3667
Vivien Didelot990e27b2017-03-28 13:50:32 -04003668 [MV88E6141] = {
3669 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
3670 .family = MV88E6XXX_FAMILY_6341,
3671 .name = "Marvell 88E6341",
3672 .num_databases = 4096,
3673 .num_ports = 6,
3674 .port_base_addr = 0x10,
3675 .global1_addr = 0x1b,
3676 .age_time_coeff = 3750,
3677 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003678 .pvt = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003679 .tag_protocol = DSA_TAG_PROTO_EDSA,
3680 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3681 .ops = &mv88e6141_ops,
3682 },
3683
Vivien Didelotf81ec902016-05-09 13:22:58 -04003684 [MV88E6161] = {
3685 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3686 .family = MV88E6XXX_FAMILY_6165,
3687 .name = "Marvell 88E6161",
3688 .num_databases = 4096,
3689 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003690 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003691 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003692 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003693 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003694 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003695 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003696 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003697 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003698 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003699 },
3700
3701 [MV88E6165] = {
3702 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3703 .family = MV88E6XXX_FAMILY_6165,
3704 .name = "Marvell 88E6165",
3705 .num_databases = 4096,
3706 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003707 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003708 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003709 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003710 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003711 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003712 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003713 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003714 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003715 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003716 },
3717
3718 [MV88E6171] = {
3719 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3720 .family = MV88E6XXX_FAMILY_6351,
3721 .name = "Marvell 88E6171",
3722 .num_databases = 4096,
3723 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003724 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003725 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003726 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003727 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003728 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003729 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003730 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003731 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003732 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003733 },
3734
3735 [MV88E6172] = {
3736 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3737 .family = MV88E6XXX_FAMILY_6352,
3738 .name = "Marvell 88E6172",
3739 .num_databases = 4096,
3740 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003741 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003742 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003743 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003744 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003745 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003746 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003747 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003748 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003749 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003750 },
3751
3752 [MV88E6175] = {
3753 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3754 .family = MV88E6XXX_FAMILY_6351,
3755 .name = "Marvell 88E6175",
3756 .num_databases = 4096,
3757 .num_ports = 7,
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,
Vivien Didelote606ca32017-03-11 16:12:55 -05003762 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003763 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003764 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003765 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003766 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003767 },
3768
3769 [MV88E6176] = {
3770 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3771 .family = MV88E6XXX_FAMILY_6352,
3772 .name = "Marvell 88E6176",
3773 .num_databases = 4096,
3774 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003775 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003776 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003777 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003778 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003779 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003780 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003781 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003782 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003783 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003784 },
3785
3786 [MV88E6185] = {
3787 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3788 .family = MV88E6XXX_FAMILY_6185,
3789 .name = "Marvell 88E6185",
3790 .num_databases = 256,
3791 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003792 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003793 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003794 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003795 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003796 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003797 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003798 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003799 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003800 },
3801
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003802 [MV88E6190] = {
3803 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3804 .family = MV88E6XXX_FAMILY_6390,
3805 .name = "Marvell 88E6190",
3806 .num_databases = 4096,
3807 .num_ports = 11, /* 10 + Z80 */
3808 .port_base_addr = 0x0,
3809 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003810 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003811 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003812 .g1_irqs = 9,
Vivien Didelotf3645652017-03-30 17:37:07 -04003813 .pvt = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003814 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003815 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3816 .ops = &mv88e6190_ops,
3817 },
3818
3819 [MV88E6190X] = {
3820 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3821 .family = MV88E6XXX_FAMILY_6390,
3822 .name = "Marvell 88E6190X",
3823 .num_databases = 4096,
3824 .num_ports = 11, /* 10 + Z80 */
3825 .port_base_addr = 0x0,
3826 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003827 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003828 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003829 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003830 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003831 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003832 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3833 .ops = &mv88e6190x_ops,
3834 },
3835
3836 [MV88E6191] = {
3837 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3838 .family = MV88E6XXX_FAMILY_6390,
3839 .name = "Marvell 88E6191",
3840 .num_databases = 4096,
3841 .num_ports = 11, /* 10 + Z80 */
3842 .port_base_addr = 0x0,
3843 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003844 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003845 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003846 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003847 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003848 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003849 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003850 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003851 },
3852
Vivien Didelotf81ec902016-05-09 13:22:58 -04003853 [MV88E6240] = {
3854 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3855 .family = MV88E6XXX_FAMILY_6352,
3856 .name = "Marvell 88E6240",
3857 .num_databases = 4096,
3858 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003859 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003860 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003861 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003862 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003863 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003864 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003865 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003866 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003867 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003868 },
3869
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003870 [MV88E6290] = {
3871 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3872 .family = MV88E6XXX_FAMILY_6390,
3873 .name = "Marvell 88E6290",
3874 .num_databases = 4096,
3875 .num_ports = 11, /* 10 + Z80 */
3876 .port_base_addr = 0x0,
3877 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003878 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003879 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003880 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003881 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003882 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003883 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3884 .ops = &mv88e6290_ops,
3885 },
3886
Vivien Didelotf81ec902016-05-09 13:22:58 -04003887 [MV88E6320] = {
3888 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3889 .family = MV88E6XXX_FAMILY_6320,
3890 .name = "Marvell 88E6320",
3891 .num_databases = 4096,
3892 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003893 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003894 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003895 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003896 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003897 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003898 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003899 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003900 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003901 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003902 },
3903
3904 [MV88E6321] = {
3905 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3906 .family = MV88E6XXX_FAMILY_6320,
3907 .name = "Marvell 88E6321",
3908 .num_databases = 4096,
3909 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003910 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003911 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003912 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003913 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003914 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003915 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003916 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003917 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003918 },
3919
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003920 [MV88E6341] = {
3921 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
3922 .family = MV88E6XXX_FAMILY_6341,
3923 .name = "Marvell 88E6341",
3924 .num_databases = 4096,
3925 .num_ports = 6,
3926 .port_base_addr = 0x10,
3927 .global1_addr = 0x1b,
3928 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003929 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003930 .pvt = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003931 .tag_protocol = DSA_TAG_PROTO_EDSA,
3932 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3933 .ops = &mv88e6341_ops,
3934 },
3935
Vivien Didelotf81ec902016-05-09 13:22:58 -04003936 [MV88E6350] = {
3937 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3938 .family = MV88E6XXX_FAMILY_6351,
3939 .name = "Marvell 88E6350",
3940 .num_databases = 4096,
3941 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003942 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003943 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003944 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003945 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003946 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003947 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003948 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003949 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003950 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003951 },
3952
3953 [MV88E6351] = {
3954 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3955 .family = MV88E6XXX_FAMILY_6351,
3956 .name = "Marvell 88E6351",
3957 .num_databases = 4096,
3958 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003959 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003960 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003961 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003962 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003963 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003964 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003965 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003966 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003967 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003968 },
3969
3970 [MV88E6352] = {
3971 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
3972 .family = MV88E6XXX_FAMILY_6352,
3973 .name = "Marvell 88E6352",
3974 .num_databases = 4096,
3975 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003976 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003977 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003978 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003979 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003980 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003981 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003982 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003983 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003984 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003985 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003986 [MV88E6390] = {
3987 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
3988 .family = MV88E6XXX_FAMILY_6390,
3989 .name = "Marvell 88E6390",
3990 .num_databases = 4096,
3991 .num_ports = 11, /* 10 + Z80 */
3992 .port_base_addr = 0x0,
3993 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003994 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003995 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003996 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003997 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003998 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003999 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4000 .ops = &mv88e6390_ops,
4001 },
4002 [MV88E6390X] = {
4003 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4004 .family = MV88E6XXX_FAMILY_6390,
4005 .name = "Marvell 88E6390X",
4006 .num_databases = 4096,
4007 .num_ports = 11, /* 10 + Z80 */
4008 .port_base_addr = 0x0,
4009 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004010 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004011 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004012 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004013 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004014 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004015 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4016 .ops = &mv88e6390x_ops,
4017 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004018};
4019
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004020static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004021{
Vivien Didelota439c062016-04-17 13:23:58 -04004022 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004023
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004024 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4025 if (mv88e6xxx_table[i].prod_num == prod_num)
4026 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004027
Vivien Didelotb9b37712015-10-30 19:39:48 -04004028 return NULL;
4029}
4030
Vivien Didelotfad09c72016-06-21 12:28:20 -04004031static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004032{
4033 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004034 unsigned int prod_num, rev;
4035 u16 id;
4036 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004037
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004038 mutex_lock(&chip->reg_lock);
4039 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4040 mutex_unlock(&chip->reg_lock);
4041 if (err)
4042 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004043
4044 prod_num = (id & 0xfff0) >> 4;
4045 rev = id & 0x000f;
4046
4047 info = mv88e6xxx_lookup_info(prod_num);
4048 if (!info)
4049 return -ENODEV;
4050
Vivien Didelotcaac8542016-06-20 13:14:09 -04004051 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004052 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004053
Vivien Didelotca070c12016-09-02 14:45:34 -04004054 err = mv88e6xxx_g2_require(chip);
4055 if (err)
4056 return err;
4057
Vivien Didelotfad09c72016-06-21 12:28:20 -04004058 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4059 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004060
4061 return 0;
4062}
4063
Vivien Didelotfad09c72016-06-21 12:28:20 -04004064static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004065{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004066 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004067
Vivien Didelotfad09c72016-06-21 12:28:20 -04004068 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4069 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004070 return NULL;
4071
Vivien Didelotfad09c72016-06-21 12:28:20 -04004072 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004073
Vivien Didelotfad09c72016-06-21 12:28:20 -04004074 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004075 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004076
Vivien Didelotfad09c72016-06-21 12:28:20 -04004077 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004078}
4079
Vivien Didelote57e5e72016-08-15 17:19:00 -04004080static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4081{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004082 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004083 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004084}
4085
Andrew Lunn930188c2016-08-22 16:01:03 +02004086static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4087{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004088 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004089 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004090}
4091
Vivien Didelotfad09c72016-06-21 12:28:20 -04004092static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004093 struct mii_bus *bus, int sw_addr)
4094{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004095 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004096 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004097 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004098 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004099 else
4100 return -EINVAL;
4101
Vivien Didelotfad09c72016-06-21 12:28:20 -04004102 chip->bus = bus;
4103 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004104
4105 return 0;
4106}
4107
Andrew Lunn7b314362016-08-22 16:01:01 +02004108static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4109{
Vivien Didelot04bed142016-08-31 18:06:13 -04004110 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004111
Andrew Lunn443d5a12016-12-03 04:35:18 +01004112 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004113}
4114
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004115static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4116 struct device *host_dev, int sw_addr,
4117 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004118{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004119 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004120 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004121 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004122
Vivien Didelota439c062016-04-17 13:23:58 -04004123 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004124 if (!bus)
4125 return NULL;
4126
Vivien Didelotfad09c72016-06-21 12:28:20 -04004127 chip = mv88e6xxx_alloc_chip(dsa_dev);
4128 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004129 return NULL;
4130
Vivien Didelotcaac8542016-06-20 13:14:09 -04004131 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004132 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004133
Vivien Didelotfad09c72016-06-21 12:28:20 -04004134 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004135 if (err)
4136 goto free;
4137
Vivien Didelotfad09c72016-06-21 12:28:20 -04004138 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004139 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004140 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004141
Andrew Lunndc30c352016-10-16 19:56:49 +02004142 mutex_lock(&chip->reg_lock);
4143 err = mv88e6xxx_switch_reset(chip);
4144 mutex_unlock(&chip->reg_lock);
4145 if (err)
4146 goto free;
4147
Vivien Didelote57e5e72016-08-15 17:19:00 -04004148 mv88e6xxx_phy_init(chip);
4149
Andrew Lunna3c53be52017-01-24 14:53:50 +01004150 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004151 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004152 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004153
Vivien Didelotfad09c72016-06-21 12:28:20 -04004154 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004155
Vivien Didelotfad09c72016-06-21 12:28:20 -04004156 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004157free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004158 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004159
4160 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004161}
4162
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004163static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4164 const struct switchdev_obj_port_mdb *mdb,
4165 struct switchdev_trans *trans)
4166{
4167 /* We don't need any dynamic resource from the kernel (yet),
4168 * so skip the prepare phase.
4169 */
4170
4171 return 0;
4172}
4173
4174static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4175 const struct switchdev_obj_port_mdb *mdb,
4176 struct switchdev_trans *trans)
4177{
Vivien Didelot04bed142016-08-31 18:06:13 -04004178 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004179
4180 mutex_lock(&chip->reg_lock);
4181 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4182 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4183 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4184 mutex_unlock(&chip->reg_lock);
4185}
4186
4187static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4188 const struct switchdev_obj_port_mdb *mdb)
4189{
Vivien Didelot04bed142016-08-31 18:06:13 -04004190 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004191 int err;
4192
4193 mutex_lock(&chip->reg_lock);
4194 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4195 GLOBAL_ATU_DATA_STATE_UNUSED);
4196 mutex_unlock(&chip->reg_lock);
4197
4198 return err;
4199}
4200
4201static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4202 struct switchdev_obj_port_mdb *mdb,
4203 int (*cb)(struct switchdev_obj *obj))
4204{
Vivien Didelot04bed142016-08-31 18:06:13 -04004205 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004206 int err;
4207
4208 mutex_lock(&chip->reg_lock);
4209 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4210 mutex_unlock(&chip->reg_lock);
4211
4212 return err;
4213}
4214
Florian Fainellia82f67a2017-01-08 14:52:08 -08004215static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004216 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004217 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004218 .setup = mv88e6xxx_setup,
4219 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004220 .adjust_link = mv88e6xxx_adjust_link,
4221 .get_strings = mv88e6xxx_get_strings,
4222 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4223 .get_sset_count = mv88e6xxx_get_sset_count,
4224 .set_eee = mv88e6xxx_set_eee,
4225 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004226 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004227 .get_eeprom = mv88e6xxx_get_eeprom,
4228 .set_eeprom = mv88e6xxx_set_eeprom,
4229 .get_regs_len = mv88e6xxx_get_regs_len,
4230 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004231 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004232 .port_bridge_join = mv88e6xxx_port_bridge_join,
4233 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4234 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004235 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004236 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4237 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4238 .port_vlan_add = mv88e6xxx_port_vlan_add,
4239 .port_vlan_del = mv88e6xxx_port_vlan_del,
4240 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4241 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4242 .port_fdb_add = mv88e6xxx_port_fdb_add,
4243 .port_fdb_del = mv88e6xxx_port_fdb_del,
4244 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004245 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4246 .port_mdb_add = mv88e6xxx_port_mdb_add,
4247 .port_mdb_del = mv88e6xxx_port_mdb_del,
4248 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004249};
4250
Florian Fainelliab3d4082017-01-08 14:52:07 -08004251static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4252 .ops = &mv88e6xxx_switch_ops,
4253};
4254
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004255static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004256{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004257 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004258 struct dsa_switch *ds;
4259
Vivien Didelota0c02162017-01-27 15:29:36 -05004260 ds = dsa_switch_alloc(dev, DSA_MAX_PORTS);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004261 if (!ds)
4262 return -ENOMEM;
4263
Vivien Didelotfad09c72016-06-21 12:28:20 -04004264 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004265 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004266 ds->ageing_time_min = chip->info->age_time_coeff;
4267 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004268
4269 dev_set_drvdata(dev, ds);
4270
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004271 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004272}
4273
Vivien Didelotfad09c72016-06-21 12:28:20 -04004274static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004275{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004276 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004277}
4278
Vivien Didelot57d32312016-06-20 13:13:58 -04004279static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004280{
4281 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004282 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004283 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004284 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004285 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004286 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004287
Vivien Didelotcaac8542016-06-20 13:14:09 -04004288 compat_info = of_device_get_match_data(dev);
4289 if (!compat_info)
4290 return -EINVAL;
4291
Vivien Didelotfad09c72016-06-21 12:28:20 -04004292 chip = mv88e6xxx_alloc_chip(dev);
4293 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004294 return -ENOMEM;
4295
Vivien Didelotfad09c72016-06-21 12:28:20 -04004296 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004297
Vivien Didelotfad09c72016-06-21 12:28:20 -04004298 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004299 if (err)
4300 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004301
Andrew Lunnb4308f02016-11-21 23:26:55 +01004302 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4303 if (IS_ERR(chip->reset))
4304 return PTR_ERR(chip->reset);
4305
Vivien Didelotfad09c72016-06-21 12:28:20 -04004306 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004307 if (err)
4308 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004309
Vivien Didelote57e5e72016-08-15 17:19:00 -04004310 mv88e6xxx_phy_init(chip);
4311
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004312 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004313 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004314 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004315
Andrew Lunndc30c352016-10-16 19:56:49 +02004316 mutex_lock(&chip->reg_lock);
4317 err = mv88e6xxx_switch_reset(chip);
4318 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004319 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004320 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004321
Andrew Lunndc30c352016-10-16 19:56:49 +02004322 chip->irq = of_irq_get(np, 0);
4323 if (chip->irq == -EPROBE_DEFER) {
4324 err = chip->irq;
4325 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004326 }
4327
Andrew Lunndc30c352016-10-16 19:56:49 +02004328 if (chip->irq > 0) {
4329 /* Has to be performed before the MDIO bus is created,
4330 * because the PHYs will link there interrupts to these
4331 * interrupt controllers
4332 */
4333 mutex_lock(&chip->reg_lock);
4334 err = mv88e6xxx_g1_irq_setup(chip);
4335 mutex_unlock(&chip->reg_lock);
4336
4337 if (err)
4338 goto out;
4339
4340 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4341 err = mv88e6xxx_g2_irq_setup(chip);
4342 if (err)
4343 goto out_g1_irq;
4344 }
4345 }
4346
Andrew Lunna3c53be52017-01-24 14:53:50 +01004347 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004348 if (err)
4349 goto out_g2_irq;
4350
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004351 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004352 if (err)
4353 goto out_mdio;
4354
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004355 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004356
4357out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004358 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004359out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004360 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004361 mv88e6xxx_g2_irq_free(chip);
4362out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004363 if (chip->irq > 0) {
4364 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004365 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004366 mutex_unlock(&chip->reg_lock);
4367 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004368out:
4369 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004370}
4371
4372static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4373{
4374 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004375 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004376
Andrew Lunn930188c2016-08-22 16:01:03 +02004377 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004378 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004379 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004380
Andrew Lunn467126442016-11-20 20:14:15 +01004381 if (chip->irq > 0) {
4382 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4383 mv88e6xxx_g2_irq_free(chip);
4384 mv88e6xxx_g1_irq_free(chip);
4385 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004386}
4387
4388static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004389 {
4390 .compatible = "marvell,mv88e6085",
4391 .data = &mv88e6xxx_table[MV88E6085],
4392 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004393 {
4394 .compatible = "marvell,mv88e6190",
4395 .data = &mv88e6xxx_table[MV88E6190],
4396 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004397 { /* sentinel */ },
4398};
4399
4400MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4401
4402static struct mdio_driver mv88e6xxx_driver = {
4403 .probe = mv88e6xxx_probe,
4404 .remove = mv88e6xxx_remove,
4405 .mdiodrv.driver = {
4406 .name = "mv88e6085",
4407 .of_match_table = mv88e6xxx_of_match,
4408 },
4409};
4410
Ben Hutchings98e67302011-11-25 14:36:19 +00004411static int __init mv88e6xxx_init(void)
4412{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004413 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004414 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004415}
4416module_init(mv88e6xxx_init);
4417
4418static void __exit mv88e6xxx_cleanup(void)
4419{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004420 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004421 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004422}
4423module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004424
4425MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4426MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4427MODULE_LICENSE("GPL");