blob: fb6a723c213787410cdc0231a904ad96de419049 [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 Didelot17a15942017-03-30 17:37:09 -04001201static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1202{
1203 u16 pvlan = 0;
1204
1205 if (!mv88e6xxx_has_pvt(chip))
1206 return -EOPNOTSUPP;
1207
1208 /* Skip the local source device, which uses in-chip port VLAN */
1209 if (dev != chip->ds->index)
1210 pvlan = mv88e6xxx_port_mask(chip);
1211
1212 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1213}
1214
Vivien Didelot81228992017-03-30 17:37:08 -04001215static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1216{
Vivien Didelot17a15942017-03-30 17:37:09 -04001217 int dev, port;
1218 int err;
1219
Vivien Didelot81228992017-03-30 17:37:08 -04001220 if (!mv88e6xxx_has_pvt(chip))
1221 return 0;
1222
1223 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1224 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1225 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001226 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1227 if (err)
1228 return err;
1229
1230 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1231 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1232 err = mv88e6xxx_pvt_map(chip, dev, port);
1233 if (err)
1234 return err;
1235 }
1236 }
1237
1238 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001239}
1240
Vivien Didelot749efcb2016-09-22 16:49:24 -04001241static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1242{
1243 struct mv88e6xxx_chip *chip = ds->priv;
1244 int err;
1245
1246 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001247 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001248 mutex_unlock(&chip->reg_lock);
1249
1250 if (err)
1251 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1252}
1253
Vivien Didelotfad09c72016-06-21 12:28:20 -04001254static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001255{
Vivien Didelota935c052016-09-29 12:21:53 -04001256 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001257}
1258
Vivien Didelotfad09c72016-06-21 12:28:20 -04001259static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001260{
Vivien Didelota935c052016-09-29 12:21:53 -04001261 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001262
Vivien Didelota935c052016-09-29 12:21:53 -04001263 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1264 if (err)
1265 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001266
Vivien Didelotfad09c72016-06-21 12:28:20 -04001267 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001268}
1269
Vivien Didelotfad09c72016-06-21 12:28:20 -04001270static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001271{
1272 int ret;
1273
Vivien Didelotfad09c72016-06-21 12:28:20 -04001274 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001275 if (ret < 0)
1276 return ret;
1277
Vivien Didelotfad09c72016-06-21 12:28:20 -04001278 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001279}
1280
Vivien Didelotfad09c72016-06-21 12:28:20 -04001281static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001282 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001283 unsigned int nibble_offset)
1284{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001285 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001286 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001287
1288 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001289 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001290
Vivien Didelota935c052016-09-29 12:21:53 -04001291 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1292 if (err)
1293 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001294 }
1295
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001296 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001297 unsigned int shift = (i % 4) * 4 + nibble_offset;
1298 u16 reg = regs[i / 4];
1299
1300 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1301 }
1302
1303 return 0;
1304}
1305
Vivien Didelotfad09c72016-06-21 12:28:20 -04001306static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001307 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001308{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001309 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001310}
1311
Vivien Didelotfad09c72016-06-21 12:28:20 -04001312static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001313 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001314{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001315 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001316}
1317
Vivien Didelotfad09c72016-06-21 12:28:20 -04001318static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001319 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001320 unsigned int nibble_offset)
1321{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001322 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001323 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001324
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001325 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001326 unsigned int shift = (i % 4) * 4 + nibble_offset;
1327 u8 data = entry->data[i];
1328
1329 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1330 }
1331
1332 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001333 u16 reg = regs[i];
1334
1335 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1336 if (err)
1337 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001338 }
1339
1340 return 0;
1341}
1342
Vivien Didelotfad09c72016-06-21 12:28:20 -04001343static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001344 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001345{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001346 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001347}
1348
Vivien Didelotfad09c72016-06-21 12:28:20 -04001349static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001350 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001351{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001352 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001353}
1354
Vivien Didelotfad09c72016-06-21 12:28:20 -04001355static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001356{
Vivien Didelota935c052016-09-29 12:21:53 -04001357 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1358 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001359}
1360
Vivien Didelotfad09c72016-06-21 12:28:20 -04001361static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001362 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001363{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001364 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001365 u16 val;
1366 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001367
Vivien Didelota935c052016-09-29 12:21:53 -04001368 err = _mv88e6xxx_vtu_wait(chip);
1369 if (err)
1370 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001371
Vivien Didelota935c052016-09-29 12:21:53 -04001372 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1373 if (err)
1374 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001375
Vivien Didelota935c052016-09-29 12:21:53 -04001376 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1377 if (err)
1378 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001379
Vivien Didelota935c052016-09-29 12:21:53 -04001380 next.vid = val & GLOBAL_VTU_VID_MASK;
1381 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001382
1383 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001384 err = mv88e6xxx_vtu_data_read(chip, &next);
1385 if (err)
1386 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001387
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001388 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001389 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1390 if (err)
1391 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001392
Vivien Didelota935c052016-09-29 12:21:53 -04001393 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001394 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001395 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1396 * VTU DBNum[3:0] are located in VTU Operation 3:0
1397 */
Vivien Didelota935c052016-09-29 12:21:53 -04001398 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1399 if (err)
1400 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001401
Vivien Didelota935c052016-09-29 12:21:53 -04001402 next.fid = (val & 0xf00) >> 4;
1403 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001404 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001405
Vivien Didelotfad09c72016-06-21 12:28:20 -04001406 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001407 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1408 if (err)
1409 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001410
Vivien Didelota935c052016-09-29 12:21:53 -04001411 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001412 }
1413 }
1414
1415 *entry = next;
1416 return 0;
1417}
1418
Vivien Didelotf81ec902016-05-09 13:22:58 -04001419static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1420 struct switchdev_obj_port_vlan *vlan,
1421 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001422{
Vivien Didelot04bed142016-08-31 18:06:13 -04001423 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001424 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001425 u16 pvid;
1426 int err;
1427
Vivien Didelotfad09c72016-06-21 12:28:20 -04001428 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001429 return -EOPNOTSUPP;
1430
Vivien Didelotfad09c72016-06-21 12:28:20 -04001431 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001432
Vivien Didelot77064f32016-11-04 03:23:30 +01001433 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001434 if (err)
1435 goto unlock;
1436
Vivien Didelotfad09c72016-06-21 12:28:20 -04001437 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001438 if (err)
1439 goto unlock;
1440
1441 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001442 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001443 if (err)
1444 break;
1445
1446 if (!next.valid)
1447 break;
1448
1449 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1450 continue;
1451
1452 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001453 vlan->vid_begin = next.vid;
1454 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001455 vlan->flags = 0;
1456
1457 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1458 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1459
1460 if (next.vid == pvid)
1461 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1462
1463 err = cb(&vlan->obj);
1464 if (err)
1465 break;
1466 } while (next.vid < GLOBAL_VTU_VID_MASK);
1467
1468unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001469 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001470
1471 return err;
1472}
1473
Vivien Didelotfad09c72016-06-21 12:28:20 -04001474static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001475 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001476{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001477 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001478 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001479 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001480
Vivien Didelota935c052016-09-29 12:21:53 -04001481 err = _mv88e6xxx_vtu_wait(chip);
1482 if (err)
1483 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001484
1485 if (!entry->valid)
1486 goto loadpurge;
1487
1488 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001489 err = mv88e6xxx_vtu_data_write(chip, entry);
1490 if (err)
1491 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001492
Vivien Didelotfad09c72016-06-21 12:28:20 -04001493 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001494 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001495 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1496 if (err)
1497 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001498 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001499
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001500 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001501 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001502 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1503 if (err)
1504 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001505 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001506 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1507 * VTU DBNum[3:0] are located in VTU Operation 3:0
1508 */
1509 op |= (entry->fid & 0xf0) << 8;
1510 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001511 }
1512
1513 reg = GLOBAL_VTU_VID_VALID;
1514loadpurge:
1515 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001516 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1517 if (err)
1518 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001519
Vivien Didelotfad09c72016-06-21 12:28:20 -04001520 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001521}
1522
Vivien Didelotfad09c72016-06-21 12:28:20 -04001523static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001524 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001525{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001526 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001527 u16 val;
1528 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001529
Vivien Didelota935c052016-09-29 12:21:53 -04001530 err = _mv88e6xxx_vtu_wait(chip);
1531 if (err)
1532 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001533
Vivien Didelota935c052016-09-29 12:21:53 -04001534 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1535 sid & GLOBAL_VTU_SID_MASK);
1536 if (err)
1537 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001538
Vivien Didelota935c052016-09-29 12:21:53 -04001539 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1540 if (err)
1541 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001542
Vivien Didelota935c052016-09-29 12:21:53 -04001543 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1544 if (err)
1545 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001546
Vivien Didelota935c052016-09-29 12:21:53 -04001547 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001548
Vivien Didelota935c052016-09-29 12:21:53 -04001549 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1550 if (err)
1551 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001552
Vivien Didelota935c052016-09-29 12:21:53 -04001553 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001554
1555 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001556 err = mv88e6xxx_stu_data_read(chip, &next);
1557 if (err)
1558 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001559 }
1560
1561 *entry = next;
1562 return 0;
1563}
1564
Vivien Didelotfad09c72016-06-21 12:28:20 -04001565static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001566 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001567{
1568 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001569 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001570
Vivien Didelota935c052016-09-29 12:21:53 -04001571 err = _mv88e6xxx_vtu_wait(chip);
1572 if (err)
1573 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001574
1575 if (!entry->valid)
1576 goto loadpurge;
1577
1578 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001579 err = mv88e6xxx_stu_data_write(chip, entry);
1580 if (err)
1581 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001582
1583 reg = GLOBAL_VTU_VID_VALID;
1584loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001585 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1586 if (err)
1587 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001588
1589 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001590 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1591 if (err)
1592 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001593
Vivien Didelotfad09c72016-06-21 12:28:20 -04001594 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001595}
1596
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001597static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001598{
1599 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001600 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001601 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001602
1603 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1604
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001605 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001606 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001607 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001608 if (err)
1609 return err;
1610
1611 set_bit(*fid, fid_bitmap);
1612 }
1613
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001614 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001615 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001616 if (err)
1617 return err;
1618
1619 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001620 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001621 if (err)
1622 return err;
1623
1624 if (!vlan.valid)
1625 break;
1626
1627 set_bit(vlan.fid, fid_bitmap);
1628 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1629
1630 /* The reset value 0x000 is used to indicate that multiple address
1631 * databases are not needed. Return the next positive available.
1632 */
1633 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001634 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001635 return -ENOSPC;
1636
1637 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001638 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001639}
1640
Vivien Didelotfad09c72016-06-21 12:28:20 -04001641static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001642 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001643{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001644 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001645 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001646 .valid = true,
1647 .vid = vid,
1648 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001649 int i, err;
1650
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001651 err = mv88e6xxx_atu_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001652 if (err)
1653 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001654
Vivien Didelot3d131f02015-11-03 10:52:52 -05001655 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001656 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001657 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1658 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1659 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001660
Vivien Didelotfad09c72016-06-21 12:28:20 -04001661 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01001662 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip) ||
1663 mv88e6xxx_6341_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001664 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001665
1666 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1667 * implemented, only one STU entry is needed to cover all VTU
1668 * entries. Thus, validate the SID 0.
1669 */
1670 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001671 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001672 if (err)
1673 return err;
1674
1675 if (vstp.sid != vlan.sid || !vstp.valid) {
1676 memset(&vstp, 0, sizeof(vstp));
1677 vstp.valid = true;
1678 vstp.sid = vlan.sid;
1679
Vivien Didelotfad09c72016-06-21 12:28:20 -04001680 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001681 if (err)
1682 return err;
1683 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001684 }
1685
1686 *entry = vlan;
1687 return 0;
1688}
1689
Vivien Didelotfad09c72016-06-21 12:28:20 -04001690static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001691 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001692{
1693 int err;
1694
1695 if (!vid)
1696 return -EINVAL;
1697
Vivien Didelotfad09c72016-06-21 12:28:20 -04001698 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001699 if (err)
1700 return err;
1701
Vivien Didelotfad09c72016-06-21 12:28:20 -04001702 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001703 if (err)
1704 return err;
1705
1706 if (entry->vid != vid || !entry->valid) {
1707 if (!creat)
1708 return -EOPNOTSUPP;
1709 /* -ENOENT would've been more appropriate, but switchdev expects
1710 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1711 */
1712
Vivien Didelotfad09c72016-06-21 12:28:20 -04001713 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001714 }
1715
1716 return err;
1717}
1718
Vivien Didelotda9c3592016-02-12 12:09:40 -05001719static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1720 u16 vid_begin, u16 vid_end)
1721{
Vivien Didelot04bed142016-08-31 18:06:13 -04001722 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001723 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001724 int i, err;
1725
1726 if (!vid_begin)
1727 return -EOPNOTSUPP;
1728
Vivien Didelotfad09c72016-06-21 12:28:20 -04001729 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001730
Vivien Didelotfad09c72016-06-21 12:28:20 -04001731 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001732 if (err)
1733 goto unlock;
1734
1735 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001736 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001737 if (err)
1738 goto unlock;
1739
1740 if (!vlan.valid)
1741 break;
1742
1743 if (vlan.vid > vid_end)
1744 break;
1745
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001746 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001747 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1748 continue;
1749
Andrew Lunn66e28092016-12-11 21:07:19 +01001750 if (!ds->ports[port].netdev)
1751 continue;
1752
Vivien Didelotda9c3592016-02-12 12:09:40 -05001753 if (vlan.data[i] ==
1754 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1755 continue;
1756
Vivien Didelotfae8a252017-01-27 15:29:42 -05001757 if (ds->ports[i].bridge_dev ==
1758 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001759 break; /* same bridge, check next VLAN */
1760
Vivien Didelotfae8a252017-01-27 15:29:42 -05001761 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001762 continue;
1763
Andrew Lunnc8b09802016-06-04 21:16:57 +02001764 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001765 "hardware VLAN %d already used by %s\n",
1766 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001767 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001768 err = -EOPNOTSUPP;
1769 goto unlock;
1770 }
1771 } while (vlan.vid < vid_end);
1772
1773unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001774 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001775
1776 return err;
1777}
1778
Vivien Didelotf81ec902016-05-09 13:22:58 -04001779static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1780 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001781{
Vivien Didelot04bed142016-08-31 18:06:13 -04001782 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001783 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001784 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001785 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001786
Vivien Didelotfad09c72016-06-21 12:28:20 -04001787 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001788 return -EOPNOTSUPP;
1789
Vivien Didelotfad09c72016-06-21 12:28:20 -04001790 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001791 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001792 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001793
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001794 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001795}
1796
Vivien Didelot57d32312016-06-20 13:13:58 -04001797static int
1798mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1799 const struct switchdev_obj_port_vlan *vlan,
1800 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001801{
Vivien Didelot04bed142016-08-31 18:06:13 -04001802 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001803 int err;
1804
Vivien Didelotfad09c72016-06-21 12:28:20 -04001805 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001806 return -EOPNOTSUPP;
1807
Vivien Didelotda9c3592016-02-12 12:09:40 -05001808 /* If the requested port doesn't belong to the same bridge as the VLAN
1809 * members, do not support it (yet) and fallback to software VLAN.
1810 */
1811 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1812 vlan->vid_end);
1813 if (err)
1814 return err;
1815
Vivien Didelot76e398a2015-11-01 12:33:55 -05001816 /* We don't need any dynamic resource from the kernel (yet),
1817 * so skip the prepare phase.
1818 */
1819 return 0;
1820}
1821
Vivien Didelotfad09c72016-06-21 12:28:20 -04001822static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001823 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001824{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001825 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001826 int err;
1827
Vivien Didelotfad09c72016-06-21 12:28:20 -04001828 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001829 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001830 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001831
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001832 vlan.data[port] = untagged ?
1833 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1834 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1835
Vivien Didelotfad09c72016-06-21 12:28:20 -04001836 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001837}
1838
Vivien Didelotf81ec902016-05-09 13:22:58 -04001839static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1840 const struct switchdev_obj_port_vlan *vlan,
1841 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001842{
Vivien Didelot04bed142016-08-31 18:06:13 -04001843 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001844 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1845 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1846 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001847
Vivien Didelotfad09c72016-06-21 12:28:20 -04001848 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001849 return;
1850
Vivien Didelotfad09c72016-06-21 12:28:20 -04001851 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001852
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001853 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001854 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001855 netdev_err(ds->ports[port].netdev,
1856 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001857 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001858
Vivien Didelot77064f32016-11-04 03:23:30 +01001859 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001860 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001861 vlan->vid_end);
1862
Vivien Didelotfad09c72016-06-21 12:28:20 -04001863 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001864}
1865
Vivien Didelotfad09c72016-06-21 12:28:20 -04001866static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001867 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001868{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001869 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001870 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001871 int i, err;
1872
Vivien Didelotfad09c72016-06-21 12:28:20 -04001873 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001874 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001875 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001876
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001877 /* Tell switchdev if this VLAN is handled in software */
1878 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001879 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001880
1881 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1882
1883 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001884 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001885 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001886 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001887 continue;
1888
1889 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001890 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001891 break;
1892 }
1893 }
1894
Vivien Didelotfad09c72016-06-21 12:28:20 -04001895 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001896 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001897 return err;
1898
Vivien Didelote606ca32017-03-11 16:12:55 -05001899 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001900}
1901
Vivien Didelotf81ec902016-05-09 13:22:58 -04001902static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1903 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001904{
Vivien Didelot04bed142016-08-31 18:06:13 -04001905 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001906 u16 pvid, vid;
1907 int err = 0;
1908
Vivien Didelotfad09c72016-06-21 12:28:20 -04001909 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001910 return -EOPNOTSUPP;
1911
Vivien Didelotfad09c72016-06-21 12:28:20 -04001912 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001913
Vivien Didelot77064f32016-11-04 03:23:30 +01001914 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001915 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001916 goto unlock;
1917
Vivien Didelot76e398a2015-11-01 12:33:55 -05001918 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001919 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001920 if (err)
1921 goto unlock;
1922
1923 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001924 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001925 if (err)
1926 goto unlock;
1927 }
1928 }
1929
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001930unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001931 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001932
1933 return err;
1934}
1935
Vivien Didelot83dabd12016-08-31 11:50:04 -04001936static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1937 const unsigned char *addr, u16 vid,
1938 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001939{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001940 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001941 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001942 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001943
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001944 /* Null VLAN ID corresponds to the port private database */
1945 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001946 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001947 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04001948 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001949 if (err)
1950 return err;
1951
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001952 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1953 ether_addr_copy(entry.mac, addr);
1954 eth_addr_dec(entry.mac);
1955
1956 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001957 if (err)
1958 return err;
1959
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001960 /* Initialize a fresh ATU entry if it isn't found */
1961 if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
1962 !ether_addr_equal(entry.mac, addr)) {
1963 memset(&entry, 0, sizeof(entry));
1964 ether_addr_copy(entry.mac, addr);
1965 }
1966
Vivien Didelot88472932016-09-19 19:56:11 -04001967 /* Purge the ATU entry only if no port is using it anymore */
1968 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001969 entry.portvec &= ~BIT(port);
1970 if (!entry.portvec)
Vivien Didelot88472932016-09-19 19:56:11 -04001971 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1972 } else {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001973 entry.portvec |= BIT(port);
Vivien Didelot88472932016-09-19 19:56:11 -04001974 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001975 }
1976
Vivien Didelot9c13c022017-03-11 16:12:52 -05001977 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001978}
1979
Vivien Didelotf81ec902016-05-09 13:22:58 -04001980static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1981 const struct switchdev_obj_port_fdb *fdb,
1982 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001983{
1984 /* We don't need any dynamic resource from the kernel (yet),
1985 * so skip the prepare phase.
1986 */
1987 return 0;
1988}
1989
Vivien Didelotf81ec902016-05-09 13:22:58 -04001990static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1991 const struct switchdev_obj_port_fdb *fdb,
1992 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001993{
Vivien Didelot04bed142016-08-31 18:06:13 -04001994 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04001995
Vivien Didelotfad09c72016-06-21 12:28:20 -04001996 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04001997 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
1998 GLOBAL_ATU_DATA_STATE_UC_STATIC))
1999 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002000 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002001}
2002
Vivien Didelotf81ec902016-05-09 13:22:58 -04002003static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2004 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002005{
Vivien Didelot04bed142016-08-31 18:06:13 -04002006 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002007 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002008
Vivien Didelotfad09c72016-06-21 12:28:20 -04002009 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002010 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2011 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002012 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002013
Vivien Didelot83dabd12016-08-31 11:50:04 -04002014 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002015}
2016
Vivien Didelot83dabd12016-08-31 11:50:04 -04002017static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2018 u16 fid, u16 vid, int port,
2019 struct switchdev_obj *obj,
2020 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002021{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002022 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002023 int err;
2024
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002025 addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2026 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002027
2028 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002029 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002030 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002031 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002032
2033 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2034 break;
2035
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002036 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002037 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002038
Vivien Didelot83dabd12016-08-31 11:50:04 -04002039 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2040 struct switchdev_obj_port_fdb *fdb;
2041
2042 if (!is_unicast_ether_addr(addr.mac))
2043 continue;
2044
2045 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002046 fdb->vid = vid;
2047 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002048 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2049 fdb->ndm_state = NUD_NOARP;
2050 else
2051 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002052 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2053 struct switchdev_obj_port_mdb *mdb;
2054
2055 if (!is_multicast_ether_addr(addr.mac))
2056 continue;
2057
2058 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2059 mdb->vid = vid;
2060 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002061 } else {
2062 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002063 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002064
2065 err = cb(obj);
2066 if (err)
2067 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002068 } while (!is_broadcast_ether_addr(addr.mac));
2069
2070 return err;
2071}
2072
Vivien Didelot83dabd12016-08-31 11:50:04 -04002073static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2074 struct switchdev_obj *obj,
2075 int (*cb)(struct switchdev_obj *obj))
2076{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002077 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002078 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2079 };
2080 u16 fid;
2081 int err;
2082
2083 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002084 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002085 if (err)
2086 return err;
2087
2088 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2089 if (err)
2090 return err;
2091
2092 /* Dump VLANs' Filtering Information Databases */
2093 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2094 if (err)
2095 return err;
2096
2097 do {
2098 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2099 if (err)
2100 return err;
2101
2102 if (!vlan.valid)
2103 break;
2104
2105 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2106 obj, cb);
2107 if (err)
2108 return err;
2109 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2110
2111 return err;
2112}
2113
Vivien Didelotf81ec902016-05-09 13:22:58 -04002114static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2115 struct switchdev_obj_port_fdb *fdb,
2116 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002117{
Vivien Didelot04bed142016-08-31 18:06:13 -04002118 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002119 int err;
2120
Vivien Didelotfad09c72016-06-21 12:28:20 -04002121 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002122 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002123 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002124
2125 return err;
2126}
2127
Vivien Didelotf81ec902016-05-09 13:22:58 -04002128static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002129 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002130{
Vivien Didelot04bed142016-08-31 18:06:13 -04002131 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002132 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002133
Vivien Didelotfad09c72016-06-21 12:28:20 -04002134 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002135
Vivien Didelotfae8a252017-01-27 15:29:42 -05002136 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002137 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfae8a252017-01-27 15:29:42 -05002138 if (ds->ports[i].bridge_dev == br) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002139 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002140 if (err)
2141 break;
2142 }
2143 }
2144
Vivien Didelotfad09c72016-06-21 12:28:20 -04002145 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002146
Vivien Didelot466dfa02016-02-26 13:16:05 -05002147 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002148}
2149
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002150static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2151 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002152{
Vivien Didelot04bed142016-08-31 18:06:13 -04002153 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002154 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002155
Vivien Didelotfad09c72016-06-21 12:28:20 -04002156 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002157
Vivien Didelotfae8a252017-01-27 15:29:42 -05002158 /* Remap each port's VLANTable */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002159 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfae8a252017-01-27 15:29:42 -05002160 if (i == port || ds->ports[i].bridge_dev == br)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002161 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002162 netdev_warn(ds->ports[i].netdev,
2163 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002164
Vivien Didelotfad09c72016-06-21 12:28:20 -04002165 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002166}
2167
Vivien Didelot17e708b2016-12-05 17:30:27 -05002168static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2169{
2170 if (chip->info->ops->reset)
2171 return chip->info->ops->reset(chip);
2172
2173 return 0;
2174}
2175
Vivien Didelot309eca62016-12-05 17:30:26 -05002176static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2177{
2178 struct gpio_desc *gpiod = chip->reset;
2179
2180 /* If there is a GPIO connected to the reset pin, toggle it */
2181 if (gpiod) {
2182 gpiod_set_value_cansleep(gpiod, 1);
2183 usleep_range(10000, 20000);
2184 gpiod_set_value_cansleep(gpiod, 0);
2185 usleep_range(10000, 20000);
2186 }
2187}
2188
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002189static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2190{
2191 int i, err;
2192
2193 /* Set all ports to the Disabled state */
2194 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2195 err = mv88e6xxx_port_set_state(chip, i,
2196 PORT_CONTROL_STATE_DISABLED);
2197 if (err)
2198 return err;
2199 }
2200
2201 /* Wait for transmit queues to drain,
2202 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2203 */
2204 usleep_range(2000, 4000);
2205
2206 return 0;
2207}
2208
Vivien Didelotfad09c72016-06-21 12:28:20 -04002209static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002210{
Vivien Didelota935c052016-09-29 12:21:53 -04002211 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002212
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002213 err = mv88e6xxx_disable_ports(chip);
2214 if (err)
2215 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002216
Vivien Didelot309eca62016-12-05 17:30:26 -05002217 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002218
Vivien Didelot17e708b2016-12-05 17:30:27 -05002219 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002220}
2221
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002222static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002223{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002224 u16 val;
2225 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002226
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002227 /* Clear Power Down bit */
2228 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2229 if (err)
2230 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002231
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002232 if (val & BMCR_PDOWN) {
2233 val &= ~BMCR_PDOWN;
2234 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002235 }
2236
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002237 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002238}
2239
Vivien Didelot43145572017-03-11 16:12:59 -05002240static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2241 enum mv88e6xxx_frame_mode frame, u16 egress,
2242 u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002243{
2244 int err;
2245
Vivien Didelot43145572017-03-11 16:12:59 -05002246 if (!chip->info->ops->port_set_frame_mode)
2247 return -EOPNOTSUPP;
2248
2249 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002250 if (err)
2251 return err;
2252
Vivien Didelot43145572017-03-11 16:12:59 -05002253 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2254 if (err)
2255 return err;
2256
2257 if (chip->info->ops->port_set_ether_type)
2258 return chip->info->ops->port_set_ether_type(chip, port, etype);
2259
2260 return 0;
2261}
2262
2263static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2264{
2265 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2266 PORT_CONTROL_EGRESS_UNMODIFIED,
2267 PORT_ETH_TYPE_DEFAULT);
2268}
2269
2270static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2271{
2272 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2273 PORT_CONTROL_EGRESS_UNMODIFIED,
2274 PORT_ETH_TYPE_DEFAULT);
2275}
2276
2277static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2278{
2279 return mv88e6xxx_set_port_mode(chip, port,
2280 MV88E6XXX_FRAME_MODE_ETHERTYPE,
2281 PORT_CONTROL_EGRESS_ADD_TAG, ETH_P_EDSA);
2282}
2283
2284static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2285{
2286 if (dsa_is_dsa_port(chip->ds, port))
2287 return mv88e6xxx_set_port_mode_dsa(chip, port);
2288
2289 if (dsa_is_normal_port(chip->ds, port))
2290 return mv88e6xxx_set_port_mode_normal(chip, port);
2291
2292 /* Setup CPU port mode depending on its supported tag format */
2293 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2294 return mv88e6xxx_set_port_mode_dsa(chip, port);
2295
2296 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2297 return mv88e6xxx_set_port_mode_edsa(chip, port);
2298
2299 return -EINVAL;
2300}
2301
Vivien Didelotea698f42017-03-11 16:12:50 -05002302static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2303{
2304 bool message = dsa_is_dsa_port(chip->ds, port);
2305
2306 return mv88e6xxx_port_set_message_port(chip, port, message);
2307}
2308
Vivien Didelot601aeed2017-03-11 16:13:00 -05002309static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2310{
2311 bool flood = port == dsa_upstream_port(chip->ds);
2312
2313 /* Upstream ports flood frames with unknown unicast or multicast DA */
2314 if (chip->info->ops->port_set_egress_floods)
2315 return chip->info->ops->port_set_egress_floods(chip, port,
2316 flood, flood);
2317
2318 return 0;
2319}
2320
Vivien Didelotfad09c72016-06-21 12:28:20 -04002321static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002322{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002323 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002324 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002325 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002326
Vivien Didelotd78343d2016-11-04 03:23:36 +01002327 /* MAC Forcing register: don't force link, speed, duplex or flow control
2328 * state to any particular values on physical ports, but force the CPU
2329 * port and all DSA ports to their maximum bandwidth and full duplex.
2330 */
2331 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2332 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2333 SPEED_MAX, DUPLEX_FULL,
2334 PHY_INTERFACE_MODE_NA);
2335 else
2336 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2337 SPEED_UNFORCED, DUPLEX_UNFORCED,
2338 PHY_INTERFACE_MODE_NA);
2339 if (err)
2340 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002341
2342 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2343 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2344 * tunneling, determine priority by looking at 802.1p and IP
2345 * priority fields (IP prio has precedence), and set STP state
2346 * to Forwarding.
2347 *
2348 * If this is the CPU link, use DSA or EDSA tagging depending
2349 * on which tagging mode was configured.
2350 *
2351 * If this is a link to another switch, use DSA tagging mode.
2352 *
2353 * If this is the upstream port for this switch, enable
2354 * forwarding of unknown unicasts and multicasts.
2355 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002356 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002357 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2358 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002359 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2360 if (err)
2361 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002362
Vivien Didelot601aeed2017-03-11 16:13:00 -05002363 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002364 if (err)
2365 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002366
Vivien Didelot601aeed2017-03-11 16:13:00 -05002367 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002368 if (err)
2369 return err;
2370
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002371 /* If this port is connected to a SerDes, make sure the SerDes is not
2372 * powered down.
2373 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002374 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002375 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2376 if (err)
2377 return err;
2378 reg &= PORT_STATUS_CMODE_MASK;
2379 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2380 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2381 (reg == PORT_STATUS_CMODE_SGMII)) {
2382 err = mv88e6xxx_serdes_power_on(chip);
2383 if (err < 0)
2384 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002385 }
2386 }
2387
Vivien Didelot8efdda42015-08-13 12:52:23 -04002388 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002389 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002390 * untagged frames on this port, do a destination address lookup on all
2391 * received packets as usual, disable ARP mirroring and don't send a
2392 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002393 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002394 err = mv88e6xxx_port_set_map_da(chip, port);
2395 if (err)
2396 return err;
2397
Andrew Lunn54d792f2015-05-06 01:09:47 +02002398 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01002399 if (chip->info->ops->port_set_upstream_port) {
2400 err = chip->info->ops->port_set_upstream_port(
2401 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002402 if (err)
2403 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002404 }
2405
Andrew Lunna23b2962017-02-04 20:15:28 +01002406 err = mv88e6xxx_port_set_8021q_mode(chip, port,
2407 PORT_CONTROL_2_8021Q_DISABLED);
2408 if (err)
2409 return err;
2410
Andrew Lunn5f436662016-12-03 04:45:17 +01002411 if (chip->info->ops->port_jumbo_config) {
2412 err = chip->info->ops->port_jumbo_config(chip, port);
2413 if (err)
2414 return err;
2415 }
2416
Andrew Lunn54d792f2015-05-06 01:09:47 +02002417 /* Port Association Vector: when learning source addresses
2418 * of packets, add the address to the address database using
2419 * a port bitmap that has only the bit for this port set and
2420 * the other bits clear.
2421 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002422 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002423 /* Disable learning for CPU port */
2424 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002425 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002426
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002427 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2428 if (err)
2429 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002430
2431 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002432 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2433 if (err)
2434 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002435
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002436 if (chip->info->ops->port_pause_config) {
2437 err = chip->info->ops->port_pause_config(chip, port);
2438 if (err)
2439 return err;
2440 }
2441
Vivien Didelotc8c94892017-03-11 16:13:01 -05002442 if (chip->info->ops->port_disable_learn_limit) {
2443 err = chip->info->ops->port_disable_learn_limit(chip, port);
2444 if (err)
2445 return err;
2446 }
2447
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002448 if (chip->info->ops->port_disable_pri_override) {
2449 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002450 if (err)
2451 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002452 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002453
Andrew Lunnef0a7312016-12-03 04:35:16 +01002454 if (chip->info->ops->port_tag_remap) {
2455 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002456 if (err)
2457 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002458 }
2459
Andrew Lunnef70b112016-12-03 04:45:18 +01002460 if (chip->info->ops->port_egress_rate_limiting) {
2461 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002462 if (err)
2463 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002464 }
2465
Vivien Didelotea698f42017-03-11 16:12:50 -05002466 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002467 if (err)
2468 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002469
Vivien Didelot207afda2016-04-14 14:42:09 -04002470 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002471 * database, and allow bidirectional communication between the
2472 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002473 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002474 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002475 if (err)
2476 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002477
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002478 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2479 if (err)
2480 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002481
2482 /* Default VLAN ID and priority: don't set a default VLAN
2483 * ID, and set the default packet priority to zero.
2484 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002485 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002486}
2487
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002488static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002489{
2490 int err;
2491
Vivien Didelota935c052016-09-29 12:21:53 -04002492 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002493 if (err)
2494 return err;
2495
Vivien Didelota935c052016-09-29 12:21:53 -04002496 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002497 if (err)
2498 return err;
2499
Vivien Didelota935c052016-09-29 12:21:53 -04002500 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2501 if (err)
2502 return err;
2503
2504 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002505}
2506
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002507static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2508 unsigned int ageing_time)
2509{
Vivien Didelot04bed142016-08-31 18:06:13 -04002510 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002511 int err;
2512
2513 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002514 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002515 mutex_unlock(&chip->reg_lock);
2516
2517 return err;
2518}
2519
Vivien Didelot97299342016-07-18 20:45:30 -04002520static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002521{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002522 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002523 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002524 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002525
Vivien Didelot119477b2016-05-09 13:22:51 -04002526 /* Enable the PHY Polling Unit if present, don't discard any packets,
2527 * and mask all interrupt sources.
2528 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002529 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002530 if (err)
2531 return err;
2532
Andrew Lunn33641992016-12-03 04:35:17 +01002533 if (chip->info->ops->g1_set_cpu_port) {
2534 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2535 if (err)
2536 return err;
2537 }
2538
2539 if (chip->info->ops->g1_set_egress_port) {
2540 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2541 if (err)
2542 return err;
2543 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002544
Vivien Didelot50484ff2016-05-09 13:22:54 -04002545 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002546 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2547 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2548 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002549 if (err)
2550 return err;
2551
Vivien Didelotacddbd22016-07-18 20:45:39 -04002552 /* Clear all the VTU and STU entries */
2553 err = _mv88e6xxx_vtu_stu_flush(chip);
2554 if (err < 0)
2555 return err;
2556
Vivien Didelot08a01262016-05-09 13:22:50 -04002557 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002558 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002559 if (err)
2560 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002561 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002562 if (err)
2563 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002564 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002565 if (err)
2566 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002567 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002568 if (err)
2569 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002570 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002571 if (err)
2572 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002573 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002574 if (err)
2575 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002576 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002577 if (err)
2578 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002579 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002580 if (err)
2581 return err;
2582
2583 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002584 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002585 if (err)
2586 return err;
2587
Andrew Lunnde2273872016-11-21 23:27:01 +01002588 /* Initialize the statistics unit */
2589 err = mv88e6xxx_stats_set_histogram(chip);
2590 if (err)
2591 return err;
2592
Vivien Didelot97299342016-07-18 20:45:30 -04002593 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002594 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2595 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002596 if (err)
2597 return err;
2598
2599 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002600 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002601 if (err)
2602 return err;
2603
2604 return 0;
2605}
2606
Vivien Didelotf81ec902016-05-09 13:22:58 -04002607static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002608{
Vivien Didelot04bed142016-08-31 18:06:13 -04002609 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002610 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002611 int i;
2612
Vivien Didelotfad09c72016-06-21 12:28:20 -04002613 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002614 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002615
Vivien Didelotfad09c72016-06-21 12:28:20 -04002616 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002617
Vivien Didelot97299342016-07-18 20:45:30 -04002618 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002619 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002620 err = mv88e6xxx_setup_port(chip, i);
2621 if (err)
2622 goto unlock;
2623 }
2624
2625 /* Setup Switch Global 1 Registers */
2626 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002627 if (err)
2628 goto unlock;
2629
Vivien Didelot97299342016-07-18 20:45:30 -04002630 /* Setup Switch Global 2 Registers */
2631 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2632 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002633 if (err)
2634 goto unlock;
2635 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002636
Vivien Didelot81228992017-03-30 17:37:08 -04002637 err = mv88e6xxx_pvt_setup(chip);
2638 if (err)
2639 goto unlock;
2640
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002641 err = mv88e6xxx_atu_setup(chip);
2642 if (err)
2643 goto unlock;
2644
Andrew Lunn6e55f692016-12-03 04:45:16 +01002645 /* Some generations have the configuration of sending reserved
2646 * management frames to the CPU in global2, others in
2647 * global1. Hence it does not fit the two setup functions
2648 * above.
2649 */
2650 if (chip->info->ops->mgmt_rsvd2cpu) {
2651 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2652 if (err)
2653 goto unlock;
2654 }
2655
Vivien Didelot6b17e862015-08-13 12:52:18 -04002656unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002657 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002658
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002659 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002660}
2661
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002662static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2663{
Vivien Didelot04bed142016-08-31 18:06:13 -04002664 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002665 int err;
2666
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002667 if (!chip->info->ops->set_switch_mac)
2668 return -EOPNOTSUPP;
2669
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002670 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002671 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002672 mutex_unlock(&chip->reg_lock);
2673
2674 return err;
2675}
2676
Vivien Didelote57e5e72016-08-15 17:19:00 -04002677static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002678{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002679 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2680 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002681 u16 val;
2682 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002683
Andrew Lunnee26a222017-01-24 14:53:48 +01002684 if (!chip->info->ops->phy_read)
2685 return -EOPNOTSUPP;
2686
Vivien Didelotfad09c72016-06-21 12:28:20 -04002687 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002688 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002689 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002690
Andrew Lunnda9f3302017-02-01 03:40:05 +01002691 if (reg == MII_PHYSID2) {
2692 /* Some internal PHYS don't have a model number. Use
2693 * the mv88e6390 family model number instead.
2694 */
2695 if (!(val & 0x3f0))
2696 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2697 }
2698
Vivien Didelote57e5e72016-08-15 17:19:00 -04002699 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002700}
2701
Vivien Didelote57e5e72016-08-15 17:19:00 -04002702static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002703{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002704 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2705 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002706 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002707
Andrew Lunnee26a222017-01-24 14:53:48 +01002708 if (!chip->info->ops->phy_write)
2709 return -EOPNOTSUPP;
2710
Vivien Didelotfad09c72016-06-21 12:28:20 -04002711 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002712 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002713 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002714
2715 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002716}
2717
Vivien Didelotfad09c72016-06-21 12:28:20 -04002718static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002719 struct device_node *np,
2720 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002721{
2722 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002723 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002724 struct mii_bus *bus;
2725 int err;
2726
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002727 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002728 if (!bus)
2729 return -ENOMEM;
2730
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002731 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002732 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002733 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002734 INIT_LIST_HEAD(&mdio_bus->list);
2735 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002736
Andrew Lunnb516d452016-06-04 21:17:06 +02002737 if (np) {
2738 bus->name = np->full_name;
2739 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2740 } else {
2741 bus->name = "mv88e6xxx SMI";
2742 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2743 }
2744
2745 bus->read = mv88e6xxx_mdio_read;
2746 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002747 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002748
Andrew Lunna3c53be52017-01-24 14:53:50 +01002749 if (np)
2750 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002751 else
2752 err = mdiobus_register(bus);
2753 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002754 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002755 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002756 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002757
2758 if (external)
2759 list_add_tail(&mdio_bus->list, &chip->mdios);
2760 else
2761 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002762
2763 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002764}
2765
Andrew Lunna3c53be52017-01-24 14:53:50 +01002766static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2767 { .compatible = "marvell,mv88e6xxx-mdio-external",
2768 .data = (void *)true },
2769 { },
2770};
2771
2772static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2773 struct device_node *np)
2774{
2775 const struct of_device_id *match;
2776 struct device_node *child;
2777 int err;
2778
2779 /* Always register one mdio bus for the internal/default mdio
2780 * bus. This maybe represented in the device tree, but is
2781 * optional.
2782 */
2783 child = of_get_child_by_name(np, "mdio");
2784 err = mv88e6xxx_mdio_register(chip, child, false);
2785 if (err)
2786 return err;
2787
2788 /* Walk the device tree, and see if there are any other nodes
2789 * which say they are compatible with the external mdio
2790 * bus.
2791 */
2792 for_each_available_child_of_node(np, child) {
2793 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2794 if (match) {
2795 err = mv88e6xxx_mdio_register(chip, child, true);
2796 if (err)
2797 return err;
2798 }
2799 }
2800
2801 return 0;
2802}
2803
2804static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002805
2806{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002807 struct mv88e6xxx_mdio_bus *mdio_bus;
2808 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002809
Andrew Lunna3c53be52017-01-24 14:53:50 +01002810 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2811 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002812
Andrew Lunna3c53be52017-01-24 14:53:50 +01002813 mdiobus_unregister(bus);
2814 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002815}
2816
Vivien Didelot855b1932016-07-20 18:18:35 -04002817static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2818{
Vivien Didelot04bed142016-08-31 18:06:13 -04002819 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002820
2821 return chip->eeprom_len;
2822}
2823
Vivien Didelot855b1932016-07-20 18:18:35 -04002824static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2825 struct ethtool_eeprom *eeprom, u8 *data)
2826{
Vivien Didelot04bed142016-08-31 18:06:13 -04002827 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002828 int err;
2829
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002830 if (!chip->info->ops->get_eeprom)
2831 return -EOPNOTSUPP;
2832
Vivien Didelot855b1932016-07-20 18:18:35 -04002833 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002834 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002835 mutex_unlock(&chip->reg_lock);
2836
2837 if (err)
2838 return err;
2839
2840 eeprom->magic = 0xc3ec4951;
2841
2842 return 0;
2843}
2844
Vivien Didelot855b1932016-07-20 18:18:35 -04002845static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2846 struct ethtool_eeprom *eeprom, u8 *data)
2847{
Vivien Didelot04bed142016-08-31 18:06:13 -04002848 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002849 int err;
2850
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002851 if (!chip->info->ops->set_eeprom)
2852 return -EOPNOTSUPP;
2853
Vivien Didelot855b1932016-07-20 18:18:35 -04002854 if (eeprom->magic != 0xc3ec4951)
2855 return -EINVAL;
2856
2857 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002858 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002859 mutex_unlock(&chip->reg_lock);
2860
2861 return err;
2862}
2863
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002864static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002865 /* MV88E6XXX_FAMILY_6097 */
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 Lunnef0a7312016-12-03 04:35:16 +01002872 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002873 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002874 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002875 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002876 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002877 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002878 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002879 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002880 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002881 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2882 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002883 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002884 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2885 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002886 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002887 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002888 .ppu_enable = mv88e6185_g1_ppu_enable,
2889 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002890 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002891};
2892
2893static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002894 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002895 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002896 .phy_read = mv88e6xxx_phy_ppu_read,
2897 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002898 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002899 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002900 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002901 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002902 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002903 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002904 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002905 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2906 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002907 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002908 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002909 .ppu_enable = mv88e6185_g1_ppu_enable,
2910 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002911 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002912};
2913
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002914static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002915 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002916 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2917 .phy_read = mv88e6xxx_g2_smi_phy_read,
2918 .phy_write = mv88e6xxx_g2_smi_phy_write,
2919 .port_set_link = mv88e6xxx_port_set_link,
2920 .port_set_duplex = mv88e6xxx_port_set_duplex,
2921 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002922 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002923 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002924 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002925 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002926 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002927 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002928 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002929 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002930 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002931 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2932 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2933 .stats_get_strings = mv88e6095_stats_get_strings,
2934 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002935 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2936 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002937 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002938 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002939 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002940};
2941
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002942static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002943 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002944 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002945 .phy_read = mv88e6165_phy_read,
2946 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002947 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002948 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002949 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002950 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002951 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002952 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002953 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002954 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002955 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2956 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002957 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002958 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2959 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002960 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002961 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002962 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002963};
2964
2965static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002966 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002967 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002968 .phy_read = mv88e6xxx_phy_ppu_read,
2969 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002970 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002971 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002972 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002973 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002974 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002975 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002976 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002977 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01002978 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002979 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002980 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002981 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002982 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2983 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002984 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002985 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2986 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002987 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002988 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002989 .ppu_enable = mv88e6185_g1_ppu_enable,
2990 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002991 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002992};
2993
Vivien Didelot990e27b2017-03-28 13:50:32 -04002994static const struct mv88e6xxx_ops mv88e6141_ops = {
2995 /* MV88E6XXX_FAMILY_6341 */
2996 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
2997 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
2998 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2999 .phy_read = mv88e6xxx_g2_smi_phy_read,
3000 .phy_write = mv88e6xxx_g2_smi_phy_write,
3001 .port_set_link = mv88e6xxx_port_set_link,
3002 .port_set_duplex = mv88e6xxx_port_set_duplex,
3003 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3004 .port_set_speed = mv88e6390_port_set_speed,
3005 .port_tag_remap = mv88e6095_port_tag_remap,
3006 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3007 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3008 .port_set_ether_type = mv88e6351_port_set_ether_type,
3009 .port_jumbo_config = mv88e6165_port_jumbo_config,
3010 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3011 .port_pause_config = mv88e6097_port_pause_config,
3012 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3013 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3014 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3015 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3016 .stats_get_strings = mv88e6320_stats_get_strings,
3017 .stats_get_stats = mv88e6390_stats_get_stats,
3018 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3019 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3020 .watchdog_ops = &mv88e6390_watchdog_ops,
3021 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3022 .reset = mv88e6352_g1_reset,
3023};
3024
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003025static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003026 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003027 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003028 .phy_read = mv88e6165_phy_read,
3029 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003030 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003031 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003032 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003033 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003034 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003035 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003036 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003037 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003038 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003039 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003040 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003041 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003042 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003043 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3044 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003045 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003046 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3047 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003048 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003049 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003050 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003051};
3052
3053static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003054 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003055 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003056 .phy_read = mv88e6165_phy_read,
3057 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003058 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003059 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003060 .port_set_speed = mv88e6185_port_set_speed,
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 = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003064 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3065 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003066 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003067 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3068 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew 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 mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003075 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003076 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003077 .phy_read = mv88e6xxx_g2_smi_phy_read,
3078 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003079 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003080 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003081 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003082 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003083 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003084 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003085 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003086 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003087 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003088 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003089 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003090 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003091 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003092 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003093 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3094 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003095 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003096 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3097 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003098 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003099 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003100 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003101};
3102
3103static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003104 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003105 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3106 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
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,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003112 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003113 .port_set_speed = mv88e6352_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 mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003135 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003136 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003137 .phy_read = mv88e6xxx_g2_smi_phy_read,
3138 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003139 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003140 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003141 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003142 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003143 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003144 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003145 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003146 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003147 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003148 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003149 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003150 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003151 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003152 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003153 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3154 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003155 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003156 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3157 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003158 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003159 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003160 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003161};
3162
3163static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003164 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003165 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3166 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003167 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003168 .phy_read = mv88e6xxx_g2_smi_phy_read,
3169 .phy_write = mv88e6xxx_g2_smi_phy_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 Didelota0a0f622016-11-04 03:23:34 +01003172 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003173 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003174 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003175 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003176 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003177 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003178 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003179 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003180 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003181 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003182 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003183 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003184 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3185 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003186 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003187 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3188 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003189 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003190 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003191 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003192};
3193
3194static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003195 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003196 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003197 .phy_read = mv88e6xxx_phy_ppu_read,
3198 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003199 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003200 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003201 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003202 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003203 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003204 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003205 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003206 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003207 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3208 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003209 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003210 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3211 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003212 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003213 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003214 .ppu_enable = mv88e6185_g1_ppu_enable,
3215 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003216 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003217};
3218
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003219static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003220 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003221 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3222 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003223 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3224 .phy_read = mv88e6xxx_g2_smi_phy_read,
3225 .phy_write = mv88e6xxx_g2_smi_phy_write,
3226 .port_set_link = mv88e6xxx_port_set_link,
3227 .port_set_duplex = mv88e6xxx_port_set_duplex,
3228 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3229 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003230 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003231 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003232 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003233 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003234 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003235 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003236 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003237 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003238 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003239 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3240 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003241 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003242 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3243 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003244 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003245 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003246 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003247};
3248
3249static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003250 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003251 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3252 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003253 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3254 .phy_read = mv88e6xxx_g2_smi_phy_read,
3255 .phy_write = mv88e6xxx_g2_smi_phy_write,
3256 .port_set_link = mv88e6xxx_port_set_link,
3257 .port_set_duplex = mv88e6xxx_port_set_duplex,
3258 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3259 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003260 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003261 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003262 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003263 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003264 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003265 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003266 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003267 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003268 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003269 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3270 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003271 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003272 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3273 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003274 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003275 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003276 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003277};
3278
3279static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003280 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003281 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3282 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003283 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3284 .phy_read = mv88e6xxx_g2_smi_phy_read,
3285 .phy_write = mv88e6xxx_g2_smi_phy_write,
3286 .port_set_link = mv88e6xxx_port_set_link,
3287 .port_set_duplex = mv88e6xxx_port_set_duplex,
3288 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3289 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003290 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003291 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003292 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003293 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003294 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003295 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003296 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003297 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003298 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003299 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3300 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003301 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003302 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3303 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003304 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003305 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003306 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003307};
3308
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003309static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003310 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003311 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3312 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003313 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003314 .phy_read = mv88e6xxx_g2_smi_phy_read,
3315 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003316 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003317 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003318 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003319 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003320 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003321 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003322 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003323 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003324 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003325 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003326 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003327 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003328 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003329 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003330 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3331 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003332 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003333 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3334 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003335 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003336 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003337 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003338};
3339
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003340static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003341 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003342 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3343 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003344 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3345 .phy_read = mv88e6xxx_g2_smi_phy_read,
3346 .phy_write = mv88e6xxx_g2_smi_phy_write,
3347 .port_set_link = mv88e6xxx_port_set_link,
3348 .port_set_duplex = mv88e6xxx_port_set_duplex,
3349 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3350 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003351 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003352 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003353 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003354 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003355 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003356 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003357 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003358 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003359 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003360 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003361 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3362 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003363 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003364 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3365 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003366 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003367 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003368 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003369};
3370
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003371static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003372 /* MV88E6XXX_FAMILY_6320 */
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,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003396 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003397 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003398};
3399
3400static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003401 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003402 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3403 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003404 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003405 .phy_read = mv88e6xxx_g2_smi_phy_read,
3406 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003407 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003408 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003409 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003410 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003411 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003412 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003413 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003414 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003415 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003416 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003417 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003418 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003419 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003420 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3421 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003422 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003423 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3424 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003425 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003426};
3427
Vivien Didelot16e329a2017-03-28 13:50:33 -04003428static const struct mv88e6xxx_ops mv88e6341_ops = {
3429 /* MV88E6XXX_FAMILY_6341 */
3430 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3431 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3432 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3433 .phy_read = mv88e6xxx_g2_smi_phy_read,
3434 .phy_write = mv88e6xxx_g2_smi_phy_write,
3435 .port_set_link = mv88e6xxx_port_set_link,
3436 .port_set_duplex = mv88e6xxx_port_set_duplex,
3437 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3438 .port_set_speed = mv88e6390_port_set_speed,
3439 .port_tag_remap = mv88e6095_port_tag_remap,
3440 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3441 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3442 .port_set_ether_type = mv88e6351_port_set_ether_type,
3443 .port_jumbo_config = mv88e6165_port_jumbo_config,
3444 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3445 .port_pause_config = mv88e6097_port_pause_config,
3446 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3447 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3448 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3449 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3450 .stats_get_strings = mv88e6320_stats_get_strings,
3451 .stats_get_stats = mv88e6390_stats_get_stats,
3452 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3453 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3454 .watchdog_ops = &mv88e6390_watchdog_ops,
3455 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3456 .reset = mv88e6352_g1_reset,
3457};
3458
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003459static const struct mv88e6xxx_ops mv88e6350_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 mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003489 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003490 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003491 .phy_read = mv88e6xxx_g2_smi_phy_read,
3492 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003493 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003494 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003495 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003496 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003497 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003498 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003499 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003500 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003501 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003502 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003503 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003504 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003505 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003506 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003507 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3508 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003509 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003510 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3511 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003512 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003513 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003514 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003515};
3516
3517static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003518 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003519 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3520 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003521 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003522 .phy_read = mv88e6xxx_g2_smi_phy_read,
3523 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003524 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003525 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003526 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003527 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003528 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003529 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003530 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003531 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003532 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003533 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003534 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003535 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003536 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003537 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003538 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3539 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003540 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003541 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3542 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003543 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003544 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003545 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003546};
3547
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003548static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003549 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003550 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3551 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003552 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3553 .phy_read = mv88e6xxx_g2_smi_phy_read,
3554 .phy_write = mv88e6xxx_g2_smi_phy_write,
3555 .port_set_link = mv88e6xxx_port_set_link,
3556 .port_set_duplex = mv88e6xxx_port_set_duplex,
3557 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3558 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003559 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003560 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003561 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003562 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003563 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003564 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003565 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003566 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003567 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003568 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003569 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003570 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003571 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3572 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003573 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003574 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3575 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003576 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003577 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003578 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003579};
3580
3581static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003582 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003583 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3584 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003585 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3586 .phy_read = mv88e6xxx_g2_smi_phy_read,
3587 .phy_write = mv88e6xxx_g2_smi_phy_write,
3588 .port_set_link = mv88e6xxx_port_set_link,
3589 .port_set_duplex = mv88e6xxx_port_set_duplex,
3590 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3591 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003592 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003593 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003594 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003595 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003596 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003597 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003598 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003599 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003600 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003601 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003602 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003603 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3604 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003605 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003606 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3607 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003608 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003609 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003610 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003611};
3612
Vivien Didelotf81ec902016-05-09 13:22:58 -04003613static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3614 [MV88E6085] = {
3615 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3616 .family = MV88E6XXX_FAMILY_6097,
3617 .name = "Marvell 88E6085",
3618 .num_databases = 4096,
3619 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003620 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003621 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003622 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003623 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003624 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003625 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003626 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003627 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003628 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003629 },
3630
3631 [MV88E6095] = {
3632 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3633 .family = MV88E6XXX_FAMILY_6095,
3634 .name = "Marvell 88E6095/88E6095F",
3635 .num_databases = 256,
3636 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003637 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003638 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003639 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003640 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003641 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003642 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003643 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003644 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003645 },
3646
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003647 [MV88E6097] = {
3648 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3649 .family = MV88E6XXX_FAMILY_6097,
3650 .name = "Marvell 88E6097/88E6097F",
3651 .num_databases = 4096,
3652 .num_ports = 11,
3653 .port_base_addr = 0x10,
3654 .global1_addr = 0x1b,
3655 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003656 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003657 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003658 .pvt = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003659 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003660 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3661 .ops = &mv88e6097_ops,
3662 },
3663
Vivien Didelotf81ec902016-05-09 13:22:58 -04003664 [MV88E6123] = {
3665 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3666 .family = MV88E6XXX_FAMILY_6165,
3667 .name = "Marvell 88E6123",
3668 .num_databases = 4096,
3669 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003670 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003671 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003672 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003673 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003674 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003675 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003676 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003677 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003678 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003679 },
3680
3681 [MV88E6131] = {
3682 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3683 .family = MV88E6XXX_FAMILY_6185,
3684 .name = "Marvell 88E6131",
3685 .num_databases = 256,
3686 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003687 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003688 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003689 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003690 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003691 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003692 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003693 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003694 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003695 },
3696
Vivien Didelot990e27b2017-03-28 13:50:32 -04003697 [MV88E6141] = {
3698 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
3699 .family = MV88E6XXX_FAMILY_6341,
3700 .name = "Marvell 88E6341",
3701 .num_databases = 4096,
3702 .num_ports = 6,
3703 .port_base_addr = 0x10,
3704 .global1_addr = 0x1b,
3705 .age_time_coeff = 3750,
3706 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003707 .pvt = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003708 .tag_protocol = DSA_TAG_PROTO_EDSA,
3709 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3710 .ops = &mv88e6141_ops,
3711 },
3712
Vivien Didelotf81ec902016-05-09 13:22:58 -04003713 [MV88E6161] = {
3714 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3715 .family = MV88E6XXX_FAMILY_6165,
3716 .name = "Marvell 88E6161",
3717 .num_databases = 4096,
3718 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003719 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003720 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003721 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003722 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003723 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003724 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003725 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003726 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003727 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003728 },
3729
3730 [MV88E6165] = {
3731 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3732 .family = MV88E6XXX_FAMILY_6165,
3733 .name = "Marvell 88E6165",
3734 .num_databases = 4096,
3735 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003736 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003737 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003738 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003739 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003740 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003741 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003742 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003743 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003744 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003745 },
3746
3747 [MV88E6171] = {
3748 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3749 .family = MV88E6XXX_FAMILY_6351,
3750 .name = "Marvell 88E6171",
3751 .num_databases = 4096,
3752 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003753 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003754 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003755 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003756 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003757 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003758 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003759 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003760 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003761 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003762 },
3763
3764 [MV88E6172] = {
3765 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3766 .family = MV88E6XXX_FAMILY_6352,
3767 .name = "Marvell 88E6172",
3768 .num_databases = 4096,
3769 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003770 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003771 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003772 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003773 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003774 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003775 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003776 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003777 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003778 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003779 },
3780
3781 [MV88E6175] = {
3782 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3783 .family = MV88E6XXX_FAMILY_6351,
3784 .name = "Marvell 88E6175",
3785 .num_databases = 4096,
3786 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003787 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003788 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003789 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003790 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003791 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003792 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003793 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003794 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003795 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003796 },
3797
3798 [MV88E6176] = {
3799 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3800 .family = MV88E6XXX_FAMILY_6352,
3801 .name = "Marvell 88E6176",
3802 .num_databases = 4096,
3803 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003804 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003805 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003806 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003807 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003808 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003809 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003810 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003811 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003812 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003813 },
3814
3815 [MV88E6185] = {
3816 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3817 .family = MV88E6XXX_FAMILY_6185,
3818 .name = "Marvell 88E6185",
3819 .num_databases = 256,
3820 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003821 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003822 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003823 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003824 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003825 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003826 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003827 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003828 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003829 },
3830
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003831 [MV88E6190] = {
3832 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3833 .family = MV88E6XXX_FAMILY_6390,
3834 .name = "Marvell 88E6190",
3835 .num_databases = 4096,
3836 .num_ports = 11, /* 10 + Z80 */
3837 .port_base_addr = 0x0,
3838 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003839 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003840 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003841 .g1_irqs = 9,
Vivien Didelotf3645652017-03-30 17:37:07 -04003842 .pvt = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003843 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003844 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3845 .ops = &mv88e6190_ops,
3846 },
3847
3848 [MV88E6190X] = {
3849 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3850 .family = MV88E6XXX_FAMILY_6390,
3851 .name = "Marvell 88E6190X",
3852 .num_databases = 4096,
3853 .num_ports = 11, /* 10 + Z80 */
3854 .port_base_addr = 0x0,
3855 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003856 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003857 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003858 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003859 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003860 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003861 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3862 .ops = &mv88e6190x_ops,
3863 },
3864
3865 [MV88E6191] = {
3866 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3867 .family = MV88E6XXX_FAMILY_6390,
3868 .name = "Marvell 88E6191",
3869 .num_databases = 4096,
3870 .num_ports = 11, /* 10 + Z80 */
3871 .port_base_addr = 0x0,
3872 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003873 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003874 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003875 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003876 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003877 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003878 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003879 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003880 },
3881
Vivien Didelotf81ec902016-05-09 13:22:58 -04003882 [MV88E6240] = {
3883 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3884 .family = MV88E6XXX_FAMILY_6352,
3885 .name = "Marvell 88E6240",
3886 .num_databases = 4096,
3887 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003888 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003889 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003890 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003891 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003892 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003893 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003894 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003895 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003896 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003897 },
3898
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003899 [MV88E6290] = {
3900 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3901 .family = MV88E6XXX_FAMILY_6390,
3902 .name = "Marvell 88E6290",
3903 .num_databases = 4096,
3904 .num_ports = 11, /* 10 + Z80 */
3905 .port_base_addr = 0x0,
3906 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003907 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003908 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003909 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003910 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003911 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003912 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3913 .ops = &mv88e6290_ops,
3914 },
3915
Vivien Didelotf81ec902016-05-09 13:22:58 -04003916 [MV88E6320] = {
3917 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3918 .family = MV88E6XXX_FAMILY_6320,
3919 .name = "Marvell 88E6320",
3920 .num_databases = 4096,
3921 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003922 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003923 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003924 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003925 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003926 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003927 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003928 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003929 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003930 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003931 },
3932
3933 [MV88E6321] = {
3934 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3935 .family = MV88E6XXX_FAMILY_6320,
3936 .name = "Marvell 88E6321",
3937 .num_databases = 4096,
3938 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003939 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003940 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003941 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003942 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003943 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003944 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003945 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003946 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003947 },
3948
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003949 [MV88E6341] = {
3950 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
3951 .family = MV88E6XXX_FAMILY_6341,
3952 .name = "Marvell 88E6341",
3953 .num_databases = 4096,
3954 .num_ports = 6,
3955 .port_base_addr = 0x10,
3956 .global1_addr = 0x1b,
3957 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003958 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003959 .pvt = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003960 .tag_protocol = DSA_TAG_PROTO_EDSA,
3961 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3962 .ops = &mv88e6341_ops,
3963 },
3964
Vivien Didelotf81ec902016-05-09 13:22:58 -04003965 [MV88E6350] = {
3966 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3967 .family = MV88E6XXX_FAMILY_6351,
3968 .name = "Marvell 88E6350",
3969 .num_databases = 4096,
3970 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003971 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003972 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003973 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003974 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003975 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003976 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003977 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003978 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003979 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003980 },
3981
3982 [MV88E6351] = {
3983 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3984 .family = MV88E6XXX_FAMILY_6351,
3985 .name = "Marvell 88E6351",
3986 .num_databases = 4096,
3987 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003988 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003989 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003990 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003991 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003992 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003993 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003994 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003995 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003996 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003997 },
3998
3999 [MV88E6352] = {
4000 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4001 .family = MV88E6XXX_FAMILY_6352,
4002 .name = "Marvell 88E6352",
4003 .num_databases = 4096,
4004 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004005 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004006 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004007 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004008 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004009 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004010 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004011 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004012 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004013 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004014 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004015 [MV88E6390] = {
4016 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4017 .family = MV88E6XXX_FAMILY_6390,
4018 .name = "Marvell 88E6390",
4019 .num_databases = 4096,
4020 .num_ports = 11, /* 10 + Z80 */
4021 .port_base_addr = 0x0,
4022 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004023 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004024 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004025 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004026 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004027 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004028 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4029 .ops = &mv88e6390_ops,
4030 },
4031 [MV88E6390X] = {
4032 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4033 .family = MV88E6XXX_FAMILY_6390,
4034 .name = "Marvell 88E6390X",
4035 .num_databases = 4096,
4036 .num_ports = 11, /* 10 + Z80 */
4037 .port_base_addr = 0x0,
4038 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004039 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004040 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004041 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004042 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004043 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004044 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4045 .ops = &mv88e6390x_ops,
4046 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004047};
4048
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004049static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004050{
Vivien Didelota439c062016-04-17 13:23:58 -04004051 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004052
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004053 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4054 if (mv88e6xxx_table[i].prod_num == prod_num)
4055 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004056
Vivien Didelotb9b37712015-10-30 19:39:48 -04004057 return NULL;
4058}
4059
Vivien Didelotfad09c72016-06-21 12:28:20 -04004060static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004061{
4062 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004063 unsigned int prod_num, rev;
4064 u16 id;
4065 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004066
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004067 mutex_lock(&chip->reg_lock);
4068 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4069 mutex_unlock(&chip->reg_lock);
4070 if (err)
4071 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004072
4073 prod_num = (id & 0xfff0) >> 4;
4074 rev = id & 0x000f;
4075
4076 info = mv88e6xxx_lookup_info(prod_num);
4077 if (!info)
4078 return -ENODEV;
4079
Vivien Didelotcaac8542016-06-20 13:14:09 -04004080 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004081 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004082
Vivien Didelotca070c12016-09-02 14:45:34 -04004083 err = mv88e6xxx_g2_require(chip);
4084 if (err)
4085 return err;
4086
Vivien Didelotfad09c72016-06-21 12:28:20 -04004087 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4088 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004089
4090 return 0;
4091}
4092
Vivien Didelotfad09c72016-06-21 12:28:20 -04004093static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004094{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004095 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004096
Vivien Didelotfad09c72016-06-21 12:28:20 -04004097 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4098 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004099 return NULL;
4100
Vivien Didelotfad09c72016-06-21 12:28:20 -04004101 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004102
Vivien Didelotfad09c72016-06-21 12:28:20 -04004103 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004104 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004105
Vivien Didelotfad09c72016-06-21 12:28:20 -04004106 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004107}
4108
Vivien Didelote57e5e72016-08-15 17:19:00 -04004109static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4110{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004111 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004112 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004113}
4114
Andrew Lunn930188c2016-08-22 16:01:03 +02004115static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4116{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004117 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004118 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004119}
4120
Vivien Didelotfad09c72016-06-21 12:28:20 -04004121static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004122 struct mii_bus *bus, int sw_addr)
4123{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004124 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004125 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004126 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004127 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004128 else
4129 return -EINVAL;
4130
Vivien Didelotfad09c72016-06-21 12:28:20 -04004131 chip->bus = bus;
4132 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004133
4134 return 0;
4135}
4136
Andrew Lunn7b314362016-08-22 16:01:01 +02004137static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4138{
Vivien Didelot04bed142016-08-31 18:06:13 -04004139 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004140
Andrew Lunn443d5a12016-12-03 04:35:18 +01004141 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004142}
4143
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004144static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4145 struct device *host_dev, int sw_addr,
4146 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004147{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004148 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004149 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004150 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004151
Vivien Didelota439c062016-04-17 13:23:58 -04004152 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004153 if (!bus)
4154 return NULL;
4155
Vivien Didelotfad09c72016-06-21 12:28:20 -04004156 chip = mv88e6xxx_alloc_chip(dsa_dev);
4157 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004158 return NULL;
4159
Vivien Didelotcaac8542016-06-20 13:14:09 -04004160 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004161 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004162
Vivien Didelotfad09c72016-06-21 12:28:20 -04004163 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004164 if (err)
4165 goto free;
4166
Vivien Didelotfad09c72016-06-21 12:28:20 -04004167 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004168 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004169 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004170
Andrew Lunndc30c352016-10-16 19:56:49 +02004171 mutex_lock(&chip->reg_lock);
4172 err = mv88e6xxx_switch_reset(chip);
4173 mutex_unlock(&chip->reg_lock);
4174 if (err)
4175 goto free;
4176
Vivien Didelote57e5e72016-08-15 17:19:00 -04004177 mv88e6xxx_phy_init(chip);
4178
Andrew Lunna3c53be52017-01-24 14:53:50 +01004179 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004180 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004181 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004182
Vivien Didelotfad09c72016-06-21 12:28:20 -04004183 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004184
Vivien Didelotfad09c72016-06-21 12:28:20 -04004185 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004186free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004187 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004188
4189 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004190}
4191
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004192static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4193 const struct switchdev_obj_port_mdb *mdb,
4194 struct switchdev_trans *trans)
4195{
4196 /* We don't need any dynamic resource from the kernel (yet),
4197 * so skip the prepare phase.
4198 */
4199
4200 return 0;
4201}
4202
4203static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4204 const struct switchdev_obj_port_mdb *mdb,
4205 struct switchdev_trans *trans)
4206{
Vivien Didelot04bed142016-08-31 18:06:13 -04004207 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004208
4209 mutex_lock(&chip->reg_lock);
4210 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4211 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4212 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4213 mutex_unlock(&chip->reg_lock);
4214}
4215
4216static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4217 const struct switchdev_obj_port_mdb *mdb)
4218{
Vivien Didelot04bed142016-08-31 18:06:13 -04004219 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004220 int err;
4221
4222 mutex_lock(&chip->reg_lock);
4223 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4224 GLOBAL_ATU_DATA_STATE_UNUSED);
4225 mutex_unlock(&chip->reg_lock);
4226
4227 return err;
4228}
4229
4230static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4231 struct switchdev_obj_port_mdb *mdb,
4232 int (*cb)(struct switchdev_obj *obj))
4233{
Vivien Didelot04bed142016-08-31 18:06:13 -04004234 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004235 int err;
4236
4237 mutex_lock(&chip->reg_lock);
4238 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4239 mutex_unlock(&chip->reg_lock);
4240
4241 return err;
4242}
4243
Florian Fainellia82f67a2017-01-08 14:52:08 -08004244static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004245 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004246 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004247 .setup = mv88e6xxx_setup,
4248 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004249 .adjust_link = mv88e6xxx_adjust_link,
4250 .get_strings = mv88e6xxx_get_strings,
4251 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4252 .get_sset_count = mv88e6xxx_get_sset_count,
4253 .set_eee = mv88e6xxx_set_eee,
4254 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004255 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004256 .get_eeprom = mv88e6xxx_get_eeprom,
4257 .set_eeprom = mv88e6xxx_set_eeprom,
4258 .get_regs_len = mv88e6xxx_get_regs_len,
4259 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004260 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004261 .port_bridge_join = mv88e6xxx_port_bridge_join,
4262 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4263 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004264 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004265 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4266 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4267 .port_vlan_add = mv88e6xxx_port_vlan_add,
4268 .port_vlan_del = mv88e6xxx_port_vlan_del,
4269 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4270 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4271 .port_fdb_add = mv88e6xxx_port_fdb_add,
4272 .port_fdb_del = mv88e6xxx_port_fdb_del,
4273 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004274 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4275 .port_mdb_add = mv88e6xxx_port_mdb_add,
4276 .port_mdb_del = mv88e6xxx_port_mdb_del,
4277 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004278};
4279
Florian Fainelliab3d4082017-01-08 14:52:07 -08004280static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4281 .ops = &mv88e6xxx_switch_ops,
4282};
4283
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004284static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004285{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004286 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004287 struct dsa_switch *ds;
4288
Vivien Didelota0c02162017-01-27 15:29:36 -05004289 ds = dsa_switch_alloc(dev, DSA_MAX_PORTS);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004290 if (!ds)
4291 return -ENOMEM;
4292
Vivien Didelotfad09c72016-06-21 12:28:20 -04004293 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004294 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004295 ds->ageing_time_min = chip->info->age_time_coeff;
4296 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004297
4298 dev_set_drvdata(dev, ds);
4299
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004300 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004301}
4302
Vivien Didelotfad09c72016-06-21 12:28:20 -04004303static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004304{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004305 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004306}
4307
Vivien Didelot57d32312016-06-20 13:13:58 -04004308static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004309{
4310 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004311 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004312 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004313 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004314 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004315 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004316
Vivien Didelotcaac8542016-06-20 13:14:09 -04004317 compat_info = of_device_get_match_data(dev);
4318 if (!compat_info)
4319 return -EINVAL;
4320
Vivien Didelotfad09c72016-06-21 12:28:20 -04004321 chip = mv88e6xxx_alloc_chip(dev);
4322 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004323 return -ENOMEM;
4324
Vivien Didelotfad09c72016-06-21 12:28:20 -04004325 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004326
Vivien Didelotfad09c72016-06-21 12:28:20 -04004327 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004328 if (err)
4329 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004330
Andrew Lunnb4308f02016-11-21 23:26:55 +01004331 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4332 if (IS_ERR(chip->reset))
4333 return PTR_ERR(chip->reset);
4334
Vivien Didelotfad09c72016-06-21 12:28:20 -04004335 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004336 if (err)
4337 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004338
Vivien Didelote57e5e72016-08-15 17:19:00 -04004339 mv88e6xxx_phy_init(chip);
4340
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004341 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004342 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004343 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004344
Andrew Lunndc30c352016-10-16 19:56:49 +02004345 mutex_lock(&chip->reg_lock);
4346 err = mv88e6xxx_switch_reset(chip);
4347 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004348 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004349 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004350
Andrew Lunndc30c352016-10-16 19:56:49 +02004351 chip->irq = of_irq_get(np, 0);
4352 if (chip->irq == -EPROBE_DEFER) {
4353 err = chip->irq;
4354 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004355 }
4356
Andrew Lunndc30c352016-10-16 19:56:49 +02004357 if (chip->irq > 0) {
4358 /* Has to be performed before the MDIO bus is created,
4359 * because the PHYs will link there interrupts to these
4360 * interrupt controllers
4361 */
4362 mutex_lock(&chip->reg_lock);
4363 err = mv88e6xxx_g1_irq_setup(chip);
4364 mutex_unlock(&chip->reg_lock);
4365
4366 if (err)
4367 goto out;
4368
4369 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4370 err = mv88e6xxx_g2_irq_setup(chip);
4371 if (err)
4372 goto out_g1_irq;
4373 }
4374 }
4375
Andrew Lunna3c53be52017-01-24 14:53:50 +01004376 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004377 if (err)
4378 goto out_g2_irq;
4379
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004380 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004381 if (err)
4382 goto out_mdio;
4383
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004384 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004385
4386out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004387 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004388out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004389 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004390 mv88e6xxx_g2_irq_free(chip);
4391out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004392 if (chip->irq > 0) {
4393 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004394 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004395 mutex_unlock(&chip->reg_lock);
4396 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004397out:
4398 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004399}
4400
4401static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4402{
4403 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004404 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004405
Andrew Lunn930188c2016-08-22 16:01:03 +02004406 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004407 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004408 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004409
Andrew Lunn467126442016-11-20 20:14:15 +01004410 if (chip->irq > 0) {
4411 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4412 mv88e6xxx_g2_irq_free(chip);
4413 mv88e6xxx_g1_irq_free(chip);
4414 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004415}
4416
4417static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004418 {
4419 .compatible = "marvell,mv88e6085",
4420 .data = &mv88e6xxx_table[MV88E6085],
4421 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004422 {
4423 .compatible = "marvell,mv88e6190",
4424 .data = &mv88e6xxx_table[MV88E6190],
4425 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004426 { /* sentinel */ },
4427};
4428
4429MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4430
4431static struct mdio_driver mv88e6xxx_driver = {
4432 .probe = mv88e6xxx_probe,
4433 .remove = mv88e6xxx_remove,
4434 .mdiodrv.driver = {
4435 .name = "mv88e6085",
4436 .of_match_table = mv88e6xxx_of_match,
4437 },
4438};
4439
Ben Hutchings98e67302011-11-25 14:36:19 +00004440static int __init mv88e6xxx_init(void)
4441{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004442 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004443 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004444}
4445module_init(mv88e6xxx_init);
4446
4447static void __exit mv88e6xxx_cleanup(void)
4448{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004449 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004450 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004451}
4452module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004453
4454MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4455MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4456MODULE_LICENSE("GPL");