blob: 3802e1bdd1110ec3b02bf818649d7f5320bfb282 [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 Didelote5887a22017-03-30 17:37:11 -04001126static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001127{
Vivien Didelote5887a22017-03-30 17:37:11 -04001128 struct dsa_switch *ds = NULL;
1129 struct net_device *br;
1130 u16 pvlan;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001131 int i;
1132
Vivien Didelote5887a22017-03-30 17:37:11 -04001133 if (dev < DSA_MAX_SWITCHES)
1134 ds = chip->ds->dst->ds[dev];
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001135
Vivien Didelote5887a22017-03-30 17:37:11 -04001136 /* Prevent frames from unknown switch or port */
1137 if (!ds || port >= ds->num_ports)
1138 return 0;
1139
1140 /* Frames from DSA links and CPU ports can egress any local port */
1141 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
1142 return mv88e6xxx_port_mask(chip);
1143
1144 br = ds->ports[port].bridge_dev;
1145 pvlan = 0;
1146
1147 /* Frames from user ports can egress any local DSA links and CPU ports,
1148 * as well as any local member of their bridge group.
1149 */
1150 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1151 if (dsa_is_cpu_port(chip->ds, i) ||
1152 dsa_is_dsa_port(chip->ds, i) ||
1153 (br && chip->ds->ports[i].bridge_dev == br))
1154 pvlan |= BIT(i);
1155
1156 return pvlan;
1157}
1158
Vivien Didelot240ea3e2017-03-30 17:37:12 -04001159static int mv88e6xxx_port_vlan_map(struct mv88e6xxx_chip *chip, int port)
Vivien Didelote5887a22017-03-30 17:37:11 -04001160{
1161 u16 output_ports = mv88e6xxx_port_vlan(chip, chip->ds->index, port);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001162
1163 /* prevent frames from going back out of the port they came in on */
1164 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001165
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001166 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001167}
1168
Vivien Didelotf81ec902016-05-09 13:22:58 -04001169static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1170 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001171{
Vivien Didelot04bed142016-08-31 18:06:13 -04001172 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001173 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001174 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001175
1176 switch (state) {
1177 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001178 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001179 break;
1180 case BR_STATE_BLOCKING:
1181 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001182 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001183 break;
1184 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001185 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001186 break;
1187 case BR_STATE_FORWARDING:
1188 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001189 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001190 break;
1191 }
1192
Vivien Didelotfad09c72016-06-21 12:28:20 -04001193 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001194 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001195 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001196
1197 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001198 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001199}
1200
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001201static int mv88e6xxx_atu_setup(struct mv88e6xxx_chip *chip)
1202{
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001203 int err;
1204
Vivien Didelotdaefc942017-03-11 16:12:54 -05001205 err = mv88e6xxx_g1_atu_flush(chip, 0, true);
1206 if (err)
1207 return err;
1208
Vivien Didelotc3a7d4a2017-03-11 16:12:51 -05001209 err = mv88e6xxx_g1_atu_set_learn2all(chip, true);
1210 if (err)
1211 return err;
1212
Vivien Didelota2ac29d2017-03-11 16:12:49 -05001213 return mv88e6xxx_g1_atu_set_age_time(chip, 300000);
1214}
1215
Vivien Didelot17a15942017-03-30 17:37:09 -04001216static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
1217{
1218 u16 pvlan = 0;
1219
1220 if (!mv88e6xxx_has_pvt(chip))
1221 return -EOPNOTSUPP;
1222
1223 /* Skip the local source device, which uses in-chip port VLAN */
1224 if (dev != chip->ds->index)
1225 pvlan = mv88e6xxx_port_mask(chip);
1226
1227 return mv88e6xxx_g2_pvt_write(chip, dev, port, pvlan);
1228}
1229
Vivien Didelot81228992017-03-30 17:37:08 -04001230static int mv88e6xxx_pvt_setup(struct mv88e6xxx_chip *chip)
1231{
Vivien Didelot17a15942017-03-30 17:37:09 -04001232 int dev, port;
1233 int err;
1234
Vivien Didelot81228992017-03-30 17:37:08 -04001235 if (!mv88e6xxx_has_pvt(chip))
1236 return 0;
1237
1238 /* Clear 5 Bit Port for usage with Marvell Link Street devices:
1239 * use 4 bits for the Src_Port/Src_Trunk and 5 bits for the Src_Dev.
1240 */
Vivien Didelot17a15942017-03-30 17:37:09 -04001241 err = mv88e6xxx_g2_misc_4_bit_port(chip);
1242 if (err)
1243 return err;
1244
1245 for (dev = 0; dev < MV88E6XXX_MAX_PVT_SWITCHES; ++dev) {
1246 for (port = 0; port < MV88E6XXX_MAX_PVT_PORTS; ++port) {
1247 err = mv88e6xxx_pvt_map(chip, dev, port);
1248 if (err)
1249 return err;
1250 }
1251 }
1252
1253 return 0;
Vivien Didelot81228992017-03-30 17:37:08 -04001254}
1255
Vivien Didelot749efcb2016-09-22 16:49:24 -04001256static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1257{
1258 struct mv88e6xxx_chip *chip = ds->priv;
1259 int err;
1260
1261 mutex_lock(&chip->reg_lock);
Vivien Didelote606ca32017-03-11 16:12:55 -05001262 err = mv88e6xxx_g1_atu_remove(chip, 0, port, false);
Vivien Didelot749efcb2016-09-22 16:49:24 -04001263 mutex_unlock(&chip->reg_lock);
1264
1265 if (err)
1266 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1267}
1268
Vivien Didelotfad09c72016-06-21 12:28:20 -04001269static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001270{
Vivien Didelota935c052016-09-29 12:21:53 -04001271 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001272}
1273
Vivien Didelotfad09c72016-06-21 12:28:20 -04001274static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001275{
Vivien Didelota935c052016-09-29 12:21:53 -04001276 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001277
Vivien Didelota935c052016-09-29 12:21:53 -04001278 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1279 if (err)
1280 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001281
Vivien Didelotfad09c72016-06-21 12:28:20 -04001282 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001283}
1284
Vivien Didelotfad09c72016-06-21 12:28:20 -04001285static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001286{
1287 int ret;
1288
Vivien Didelotfad09c72016-06-21 12:28:20 -04001289 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001290 if (ret < 0)
1291 return ret;
1292
Vivien Didelotfad09c72016-06-21 12:28:20 -04001293 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001294}
1295
Vivien Didelotfad09c72016-06-21 12:28:20 -04001296static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001297 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001298 unsigned int nibble_offset)
1299{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001300 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001301 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001302
1303 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001304 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001305
Vivien Didelota935c052016-09-29 12:21:53 -04001306 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1307 if (err)
1308 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001309 }
1310
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001311 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001312 unsigned int shift = (i % 4) * 4 + nibble_offset;
1313 u16 reg = regs[i / 4];
1314
1315 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1316 }
1317
1318 return 0;
1319}
1320
Vivien Didelotfad09c72016-06-21 12:28:20 -04001321static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001322 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001323{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001324 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001325}
1326
Vivien Didelotfad09c72016-06-21 12:28:20 -04001327static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001328 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001329{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001330 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001331}
1332
Vivien Didelotfad09c72016-06-21 12:28:20 -04001333static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001334 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001335 unsigned int nibble_offset)
1336{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001337 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001338 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001339
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001340 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001341 unsigned int shift = (i % 4) * 4 + nibble_offset;
1342 u8 data = entry->data[i];
1343
1344 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1345 }
1346
1347 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001348 u16 reg = regs[i];
1349
1350 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1351 if (err)
1352 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001353 }
1354
1355 return 0;
1356}
1357
Vivien Didelotfad09c72016-06-21 12:28:20 -04001358static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001359 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001360{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001361 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001362}
1363
Vivien Didelotfad09c72016-06-21 12:28:20 -04001364static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001365 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001366{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001367 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001368}
1369
Vivien Didelotfad09c72016-06-21 12:28:20 -04001370static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001371{
Vivien Didelota935c052016-09-29 12:21:53 -04001372 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1373 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001374}
1375
Vivien Didelotfad09c72016-06-21 12:28:20 -04001376static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001377 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001378{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001379 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001380 u16 val;
1381 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001382
Vivien Didelota935c052016-09-29 12:21:53 -04001383 err = _mv88e6xxx_vtu_wait(chip);
1384 if (err)
1385 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001386
Vivien Didelota935c052016-09-29 12:21:53 -04001387 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1388 if (err)
1389 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001390
Vivien Didelota935c052016-09-29 12:21:53 -04001391 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1392 if (err)
1393 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001394
Vivien Didelota935c052016-09-29 12:21:53 -04001395 next.vid = val & GLOBAL_VTU_VID_MASK;
1396 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001397
1398 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001399 err = mv88e6xxx_vtu_data_read(chip, &next);
1400 if (err)
1401 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001402
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001403 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001404 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1405 if (err)
1406 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001407
Vivien Didelota935c052016-09-29 12:21:53 -04001408 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001409 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001410 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1411 * VTU DBNum[3:0] are located in VTU Operation 3:0
1412 */
Vivien Didelota935c052016-09-29 12:21:53 -04001413 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1414 if (err)
1415 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001416
Vivien Didelota935c052016-09-29 12:21:53 -04001417 next.fid = (val & 0xf00) >> 4;
1418 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001419 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001420
Vivien Didelotfad09c72016-06-21 12:28:20 -04001421 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001422 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1423 if (err)
1424 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001425
Vivien Didelota935c052016-09-29 12:21:53 -04001426 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001427 }
1428 }
1429
1430 *entry = next;
1431 return 0;
1432}
1433
Vivien Didelotf81ec902016-05-09 13:22:58 -04001434static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1435 struct switchdev_obj_port_vlan *vlan,
1436 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001437{
Vivien Didelot04bed142016-08-31 18:06:13 -04001438 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001439 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001440 u16 pvid;
1441 int err;
1442
Vivien Didelotfad09c72016-06-21 12:28:20 -04001443 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001444 return -EOPNOTSUPP;
1445
Vivien Didelotfad09c72016-06-21 12:28:20 -04001446 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001447
Vivien Didelot77064f32016-11-04 03:23:30 +01001448 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001449 if (err)
1450 goto unlock;
1451
Vivien Didelotfad09c72016-06-21 12:28:20 -04001452 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001453 if (err)
1454 goto unlock;
1455
1456 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001457 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001458 if (err)
1459 break;
1460
1461 if (!next.valid)
1462 break;
1463
1464 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1465 continue;
1466
1467 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001468 vlan->vid_begin = next.vid;
1469 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001470 vlan->flags = 0;
1471
1472 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1473 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1474
1475 if (next.vid == pvid)
1476 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1477
1478 err = cb(&vlan->obj);
1479 if (err)
1480 break;
1481 } while (next.vid < GLOBAL_VTU_VID_MASK);
1482
1483unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001484 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001485
1486 return err;
1487}
1488
Vivien Didelotfad09c72016-06-21 12:28:20 -04001489static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001490 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001491{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001492 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001493 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001494 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001495
Vivien Didelota935c052016-09-29 12:21:53 -04001496 err = _mv88e6xxx_vtu_wait(chip);
1497 if (err)
1498 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001499
1500 if (!entry->valid)
1501 goto loadpurge;
1502
1503 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001504 err = mv88e6xxx_vtu_data_write(chip, entry);
1505 if (err)
1506 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001507
Vivien Didelotfad09c72016-06-21 12:28:20 -04001508 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001509 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001510 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1511 if (err)
1512 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001513 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001514
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001515 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001516 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001517 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1518 if (err)
1519 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001520 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001521 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1522 * VTU DBNum[3:0] are located in VTU Operation 3:0
1523 */
1524 op |= (entry->fid & 0xf0) << 8;
1525 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001526 }
1527
1528 reg = GLOBAL_VTU_VID_VALID;
1529loadpurge:
1530 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001531 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1532 if (err)
1533 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001534
Vivien Didelotfad09c72016-06-21 12:28:20 -04001535 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001536}
1537
Vivien Didelotfad09c72016-06-21 12:28:20 -04001538static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001539 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001540{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001541 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001542 u16 val;
1543 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001544
Vivien Didelota935c052016-09-29 12:21:53 -04001545 err = _mv88e6xxx_vtu_wait(chip);
1546 if (err)
1547 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001548
Vivien Didelota935c052016-09-29 12:21:53 -04001549 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1550 sid & GLOBAL_VTU_SID_MASK);
1551 if (err)
1552 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001553
Vivien Didelota935c052016-09-29 12:21:53 -04001554 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1555 if (err)
1556 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001557
Vivien Didelota935c052016-09-29 12:21:53 -04001558 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1559 if (err)
1560 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001561
Vivien Didelota935c052016-09-29 12:21:53 -04001562 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001563
Vivien Didelota935c052016-09-29 12:21:53 -04001564 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1565 if (err)
1566 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001567
Vivien Didelota935c052016-09-29 12:21:53 -04001568 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001569
1570 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001571 err = mv88e6xxx_stu_data_read(chip, &next);
1572 if (err)
1573 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001574 }
1575
1576 *entry = next;
1577 return 0;
1578}
1579
Vivien Didelotfad09c72016-06-21 12:28:20 -04001580static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001581 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001582{
1583 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001584 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001585
Vivien Didelota935c052016-09-29 12:21:53 -04001586 err = _mv88e6xxx_vtu_wait(chip);
1587 if (err)
1588 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001589
1590 if (!entry->valid)
1591 goto loadpurge;
1592
1593 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001594 err = mv88e6xxx_stu_data_write(chip, entry);
1595 if (err)
1596 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001597
1598 reg = GLOBAL_VTU_VID_VALID;
1599loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001600 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1601 if (err)
1602 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001603
1604 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001605 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1606 if (err)
1607 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001608
Vivien Didelotfad09c72016-06-21 12:28:20 -04001609 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001610}
1611
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001612static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001613{
1614 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001615 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001616 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001617
1618 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1619
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001620 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001621 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001622 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001623 if (err)
1624 return err;
1625
1626 set_bit(*fid, fid_bitmap);
1627 }
1628
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001629 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001630 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001631 if (err)
1632 return err;
1633
1634 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001635 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001636 if (err)
1637 return err;
1638
1639 if (!vlan.valid)
1640 break;
1641
1642 set_bit(vlan.fid, fid_bitmap);
1643 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1644
1645 /* The reset value 0x000 is used to indicate that multiple address
1646 * databases are not needed. Return the next positive available.
1647 */
1648 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001649 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001650 return -ENOSPC;
1651
1652 /* Clear the database */
Vivien Didelotdaefc942017-03-11 16:12:54 -05001653 return mv88e6xxx_g1_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001654}
1655
Vivien Didelotfad09c72016-06-21 12:28:20 -04001656static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001657 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001658{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001659 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001660 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001661 .valid = true,
1662 .vid = vid,
1663 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001664 int i, err;
1665
Vivien Didelotd7f435f2017-03-11 16:12:56 -05001666 err = mv88e6xxx_atu_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001667 if (err)
1668 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001669
Vivien Didelot3d131f02015-11-03 10:52:52 -05001670 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001671 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001672 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1673 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1674 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001675
Vivien Didelotfad09c72016-06-21 12:28:20 -04001676 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01001677 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip) ||
1678 mv88e6xxx_6341_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001679 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001680
1681 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1682 * implemented, only one STU entry is needed to cover all VTU
1683 * entries. Thus, validate the SID 0.
1684 */
1685 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001686 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001687 if (err)
1688 return err;
1689
1690 if (vstp.sid != vlan.sid || !vstp.valid) {
1691 memset(&vstp, 0, sizeof(vstp));
1692 vstp.valid = true;
1693 vstp.sid = vlan.sid;
1694
Vivien Didelotfad09c72016-06-21 12:28:20 -04001695 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001696 if (err)
1697 return err;
1698 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001699 }
1700
1701 *entry = vlan;
1702 return 0;
1703}
1704
Vivien Didelotfad09c72016-06-21 12:28:20 -04001705static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001706 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001707{
1708 int err;
1709
1710 if (!vid)
1711 return -EINVAL;
1712
Vivien Didelotfad09c72016-06-21 12:28:20 -04001713 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001714 if (err)
1715 return err;
1716
Vivien Didelotfad09c72016-06-21 12:28:20 -04001717 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001718 if (err)
1719 return err;
1720
1721 if (entry->vid != vid || !entry->valid) {
1722 if (!creat)
1723 return -EOPNOTSUPP;
1724 /* -ENOENT would've been more appropriate, but switchdev expects
1725 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1726 */
1727
Vivien Didelotfad09c72016-06-21 12:28:20 -04001728 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001729 }
1730
1731 return err;
1732}
1733
Vivien Didelotda9c3592016-02-12 12:09:40 -05001734static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1735 u16 vid_begin, u16 vid_end)
1736{
Vivien Didelot04bed142016-08-31 18:06:13 -04001737 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001738 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001739 int i, err;
1740
1741 if (!vid_begin)
1742 return -EOPNOTSUPP;
1743
Vivien Didelotfad09c72016-06-21 12:28:20 -04001744 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001745
Vivien Didelotfad09c72016-06-21 12:28:20 -04001746 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001747 if (err)
1748 goto unlock;
1749
1750 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001751 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001752 if (err)
1753 goto unlock;
1754
1755 if (!vlan.valid)
1756 break;
1757
1758 if (vlan.vid > vid_end)
1759 break;
1760
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001761 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001762 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1763 continue;
1764
Andrew Lunn66e28092016-12-11 21:07:19 +01001765 if (!ds->ports[port].netdev)
1766 continue;
1767
Vivien Didelotda9c3592016-02-12 12:09:40 -05001768 if (vlan.data[i] ==
1769 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1770 continue;
1771
Vivien Didelotfae8a252017-01-27 15:29:42 -05001772 if (ds->ports[i].bridge_dev ==
1773 ds->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001774 break; /* same bridge, check next VLAN */
1775
Vivien Didelotfae8a252017-01-27 15:29:42 -05001776 if (!ds->ports[i].bridge_dev)
Andrew Lunn66e28092016-12-11 21:07:19 +01001777 continue;
1778
Andrew Lunnc8b09802016-06-04 21:16:57 +02001779 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001780 "hardware VLAN %d already used by %s\n",
1781 vlan.vid,
Vivien Didelotfae8a252017-01-27 15:29:42 -05001782 netdev_name(ds->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001783 err = -EOPNOTSUPP;
1784 goto unlock;
1785 }
1786 } while (vlan.vid < vid_end);
1787
1788unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001789 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001790
1791 return err;
1792}
1793
Vivien Didelotf81ec902016-05-09 13:22:58 -04001794static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1795 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001796{
Vivien Didelot04bed142016-08-31 18:06:13 -04001797 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001798 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001799 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001800 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001801
Vivien Didelotfad09c72016-06-21 12:28:20 -04001802 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001803 return -EOPNOTSUPP;
1804
Vivien Didelotfad09c72016-06-21 12:28:20 -04001805 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001806 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001807 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001808
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001809 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001810}
1811
Vivien Didelot57d32312016-06-20 13:13:58 -04001812static int
1813mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1814 const struct switchdev_obj_port_vlan *vlan,
1815 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001816{
Vivien Didelot04bed142016-08-31 18:06:13 -04001817 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001818 int err;
1819
Vivien Didelotfad09c72016-06-21 12:28:20 -04001820 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001821 return -EOPNOTSUPP;
1822
Vivien Didelotda9c3592016-02-12 12:09:40 -05001823 /* If the requested port doesn't belong to the same bridge as the VLAN
1824 * members, do not support it (yet) and fallback to software VLAN.
1825 */
1826 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1827 vlan->vid_end);
1828 if (err)
1829 return err;
1830
Vivien Didelot76e398a2015-11-01 12:33:55 -05001831 /* We don't need any dynamic resource from the kernel (yet),
1832 * so skip the prepare phase.
1833 */
1834 return 0;
1835}
1836
Vivien Didelotfad09c72016-06-21 12:28:20 -04001837static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001838 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001839{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001840 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001841 int err;
1842
Vivien Didelotfad09c72016-06-21 12:28:20 -04001843 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001844 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001845 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001846
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001847 vlan.data[port] = untagged ?
1848 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1849 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1850
Vivien Didelotfad09c72016-06-21 12:28:20 -04001851 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001852}
1853
Vivien Didelotf81ec902016-05-09 13:22:58 -04001854static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1855 const struct switchdev_obj_port_vlan *vlan,
1856 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001857{
Vivien Didelot04bed142016-08-31 18:06:13 -04001858 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001859 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1860 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1861 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001862
Vivien Didelotfad09c72016-06-21 12:28:20 -04001863 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001864 return;
1865
Vivien Didelotfad09c72016-06-21 12:28:20 -04001866 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001867
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001868 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001869 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001870 netdev_err(ds->ports[port].netdev,
1871 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001872 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001873
Vivien Didelot77064f32016-11-04 03:23:30 +01001874 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001875 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001876 vlan->vid_end);
1877
Vivien Didelotfad09c72016-06-21 12:28:20 -04001878 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001879}
1880
Vivien Didelotfad09c72016-06-21 12:28:20 -04001881static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001882 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001883{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001884 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001885 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001886 int i, err;
1887
Vivien Didelotfad09c72016-06-21 12:28:20 -04001888 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001889 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001890 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001891
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001892 /* Tell switchdev if this VLAN is handled in software */
1893 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001894 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001895
1896 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1897
1898 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001899 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001900 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001901 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001902 continue;
1903
1904 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001905 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001906 break;
1907 }
1908 }
1909
Vivien Didelotfad09c72016-06-21 12:28:20 -04001910 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001911 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001912 return err;
1913
Vivien Didelote606ca32017-03-11 16:12:55 -05001914 return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001915}
1916
Vivien Didelotf81ec902016-05-09 13:22:58 -04001917static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1918 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001919{
Vivien Didelot04bed142016-08-31 18:06:13 -04001920 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001921 u16 pvid, vid;
1922 int err = 0;
1923
Vivien Didelotfad09c72016-06-21 12:28:20 -04001924 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001925 return -EOPNOTSUPP;
1926
Vivien Didelotfad09c72016-06-21 12:28:20 -04001927 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001928
Vivien Didelot77064f32016-11-04 03:23:30 +01001929 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001930 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001931 goto unlock;
1932
Vivien Didelot76e398a2015-11-01 12:33:55 -05001933 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001934 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001935 if (err)
1936 goto unlock;
1937
1938 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001939 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001940 if (err)
1941 goto unlock;
1942 }
1943 }
1944
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001945unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001946 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001947
1948 return err;
1949}
1950
Vivien Didelot83dabd12016-08-31 11:50:04 -04001951static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
1952 const unsigned char *addr, u16 vid,
1953 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04001954{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001955 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04001956 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001957 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001958
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001959 /* Null VLAN ID corresponds to the port private database */
1960 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001961 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001962 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04001963 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001964 if (err)
1965 return err;
1966
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001967 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1968 ether_addr_copy(entry.mac, addr);
1969 eth_addr_dec(entry.mac);
1970
1971 err = mv88e6xxx_g1_atu_getnext(chip, vlan.fid, &entry);
Vivien Didelot88472932016-09-19 19:56:11 -04001972 if (err)
1973 return err;
1974
Vivien Didelotdabc1a92017-03-11 16:12:53 -05001975 /* Initialize a fresh ATU entry if it isn't found */
1976 if (entry.state == GLOBAL_ATU_DATA_STATE_UNUSED ||
1977 !ether_addr_equal(entry.mac, addr)) {
1978 memset(&entry, 0, sizeof(entry));
1979 ether_addr_copy(entry.mac, addr);
1980 }
1981
Vivien Didelot88472932016-09-19 19:56:11 -04001982 /* Purge the ATU entry only if no port is using it anymore */
1983 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001984 entry.portvec &= ~BIT(port);
1985 if (!entry.portvec)
Vivien Didelot88472932016-09-19 19:56:11 -04001986 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
1987 } else {
Vivien Didelot01bd96c2017-03-11 16:12:57 -05001988 entry.portvec |= BIT(port);
Vivien Didelot88472932016-09-19 19:56:11 -04001989 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04001990 }
1991
Vivien Didelot9c13c022017-03-11 16:12:52 -05001992 return mv88e6xxx_g1_atu_loadpurge(chip, vlan.fid, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001993}
1994
Vivien Didelotf81ec902016-05-09 13:22:58 -04001995static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
1996 const struct switchdev_obj_port_fdb *fdb,
1997 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04001998{
1999 /* We don't need any dynamic resource from the kernel (yet),
2000 * so skip the prepare phase.
2001 */
2002 return 0;
2003}
2004
Vivien Didelotf81ec902016-05-09 13:22:58 -04002005static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2006 const struct switchdev_obj_port_fdb *fdb,
2007 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002008{
Vivien Didelot04bed142016-08-31 18:06:13 -04002009 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002010
Vivien Didelotfad09c72016-06-21 12:28:20 -04002011 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002012 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2013 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2014 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002015 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002016}
2017
Vivien Didelotf81ec902016-05-09 13:22:58 -04002018static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2019 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002020{
Vivien Didelot04bed142016-08-31 18:06:13 -04002021 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002022 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002023
Vivien Didelotfad09c72016-06-21 12:28:20 -04002024 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002025 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2026 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002027 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002028
Vivien Didelot83dabd12016-08-31 11:50:04 -04002029 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002030}
2031
Vivien Didelot83dabd12016-08-31 11:50:04 -04002032static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2033 u16 fid, u16 vid, int port,
2034 struct switchdev_obj *obj,
2035 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002036{
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002037 struct mv88e6xxx_atu_entry addr;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002038 int err;
2039
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002040 addr.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2041 eth_broadcast_addr(addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002042
2043 do {
Vivien Didelotdabc1a92017-03-11 16:12:53 -05002044 err = mv88e6xxx_g1_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002045 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002046 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002047
2048 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2049 break;
2050
Vivien Didelot01bd96c2017-03-11 16:12:57 -05002051 if (addr.trunk || (addr.portvec & BIT(port)) == 0)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002052 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002053
Vivien Didelot83dabd12016-08-31 11:50:04 -04002054 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2055 struct switchdev_obj_port_fdb *fdb;
2056
2057 if (!is_unicast_ether_addr(addr.mac))
2058 continue;
2059
2060 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002061 fdb->vid = vid;
2062 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002063 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2064 fdb->ndm_state = NUD_NOARP;
2065 else
2066 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002067 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2068 struct switchdev_obj_port_mdb *mdb;
2069
2070 if (!is_multicast_ether_addr(addr.mac))
2071 continue;
2072
2073 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2074 mdb->vid = vid;
2075 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002076 } else {
2077 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002078 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002079
2080 err = cb(obj);
2081 if (err)
2082 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002083 } while (!is_broadcast_ether_addr(addr.mac));
2084
2085 return err;
2086}
2087
Vivien Didelot83dabd12016-08-31 11:50:04 -04002088static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2089 struct switchdev_obj *obj,
2090 int (*cb)(struct switchdev_obj *obj))
2091{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002092 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002093 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2094 };
2095 u16 fid;
2096 int err;
2097
2098 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002099 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002100 if (err)
2101 return err;
2102
2103 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2104 if (err)
2105 return err;
2106
2107 /* Dump VLANs' Filtering Information Databases */
2108 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2109 if (err)
2110 return err;
2111
2112 do {
2113 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2114 if (err)
2115 return err;
2116
2117 if (!vlan.valid)
2118 break;
2119
2120 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2121 obj, cb);
2122 if (err)
2123 return err;
2124 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2125
2126 return err;
2127}
2128
Vivien Didelotf81ec902016-05-09 13:22:58 -04002129static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2130 struct switchdev_obj_port_fdb *fdb,
2131 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002132{
Vivien Didelot04bed142016-08-31 18:06:13 -04002133 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002134 int err;
2135
Vivien Didelotfad09c72016-06-21 12:28:20 -04002136 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002137 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002138 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002139
2140 return err;
2141}
2142
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002143static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
2144 struct net_device *br)
2145{
2146 int port;
2147 int err;
2148
2149 /* Remap the Port VLAN of each local bridge group member */
2150 for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
2151 if (chip->ds->ports[port].bridge_dev == br) {
2152 err = mv88e6xxx_port_vlan_map(chip, port);
2153 if (err)
2154 return err;
2155 }
2156 }
2157
2158 return 0;
2159}
2160
Vivien Didelotf81ec902016-05-09 13:22:58 -04002161static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
Vivien Didelotfae8a252017-01-27 15:29:42 -05002162 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002163{
Vivien Didelot04bed142016-08-31 18:06:13 -04002164 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002165 int err;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002166
Vivien Didelotfad09c72016-06-21 12:28:20 -04002167 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002168 err = mv88e6xxx_bridge_map(chip, br);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002169 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002170
Vivien Didelot466dfa02016-02-26 13:16:05 -05002171 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002172}
2173
Vivien Didelotf123f2f2017-01-27 15:29:41 -05002174static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port,
2175 struct net_device *br)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002176{
Vivien Didelot04bed142016-08-31 18:06:13 -04002177 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002178
Vivien Didelotfad09c72016-06-21 12:28:20 -04002179 mutex_lock(&chip->reg_lock);
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002180 if (mv88e6xxx_bridge_map(chip, br) ||
2181 mv88e6xxx_port_vlan_map(chip, port))
2182 dev_err(ds->dev, "failed to remap in-chip Port VLAN\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002183 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002184}
2185
Vivien Didelot17e708b2016-12-05 17:30:27 -05002186static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2187{
2188 if (chip->info->ops->reset)
2189 return chip->info->ops->reset(chip);
2190
2191 return 0;
2192}
2193
Vivien Didelot309eca62016-12-05 17:30:26 -05002194static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2195{
2196 struct gpio_desc *gpiod = chip->reset;
2197
2198 /* If there is a GPIO connected to the reset pin, toggle it */
2199 if (gpiod) {
2200 gpiod_set_value_cansleep(gpiod, 1);
2201 usleep_range(10000, 20000);
2202 gpiod_set_value_cansleep(gpiod, 0);
2203 usleep_range(10000, 20000);
2204 }
2205}
2206
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002207static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2208{
2209 int i, err;
2210
2211 /* Set all ports to the Disabled state */
2212 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2213 err = mv88e6xxx_port_set_state(chip, i,
2214 PORT_CONTROL_STATE_DISABLED);
2215 if (err)
2216 return err;
2217 }
2218
2219 /* Wait for transmit queues to drain,
2220 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2221 */
2222 usleep_range(2000, 4000);
2223
2224 return 0;
2225}
2226
Vivien Didelotfad09c72016-06-21 12:28:20 -04002227static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002228{
Vivien Didelota935c052016-09-29 12:21:53 -04002229 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002230
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002231 err = mv88e6xxx_disable_ports(chip);
2232 if (err)
2233 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002234
Vivien Didelot309eca62016-12-05 17:30:26 -05002235 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002236
Vivien Didelot17e708b2016-12-05 17:30:27 -05002237 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002238}
2239
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002240static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002241{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002242 u16 val;
2243 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002244
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002245 /* Clear Power Down bit */
2246 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2247 if (err)
2248 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002249
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002250 if (val & BMCR_PDOWN) {
2251 val &= ~BMCR_PDOWN;
2252 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002253 }
2254
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002255 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002256}
2257
Vivien Didelot43145572017-03-11 16:12:59 -05002258static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
2259 enum mv88e6xxx_frame_mode frame, u16 egress,
2260 u16 etype)
Andrew Lunn56995cb2016-12-03 04:35:19 +01002261{
2262 int err;
2263
Vivien Didelot43145572017-03-11 16:12:59 -05002264 if (!chip->info->ops->port_set_frame_mode)
2265 return -EOPNOTSUPP;
2266
2267 err = mv88e6xxx_port_set_egress_mode(chip, port, egress);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002268 if (err)
2269 return err;
2270
Vivien Didelot43145572017-03-11 16:12:59 -05002271 err = chip->info->ops->port_set_frame_mode(chip, port, frame);
2272 if (err)
2273 return err;
2274
2275 if (chip->info->ops->port_set_ether_type)
2276 return chip->info->ops->port_set_ether_type(chip, port, etype);
2277
2278 return 0;
2279}
2280
2281static int mv88e6xxx_set_port_mode_normal(struct mv88e6xxx_chip *chip, int port)
2282{
2283 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_NORMAL,
2284 PORT_CONTROL_EGRESS_UNMODIFIED,
2285 PORT_ETH_TYPE_DEFAULT);
2286}
2287
2288static int mv88e6xxx_set_port_mode_dsa(struct mv88e6xxx_chip *chip, int port)
2289{
2290 return mv88e6xxx_set_port_mode(chip, port, MV88E6XXX_FRAME_MODE_DSA,
2291 PORT_CONTROL_EGRESS_UNMODIFIED,
2292 PORT_ETH_TYPE_DEFAULT);
2293}
2294
2295static int mv88e6xxx_set_port_mode_edsa(struct mv88e6xxx_chip *chip, int port)
2296{
2297 return mv88e6xxx_set_port_mode(chip, port,
2298 MV88E6XXX_FRAME_MODE_ETHERTYPE,
2299 PORT_CONTROL_EGRESS_ADD_TAG, ETH_P_EDSA);
2300}
2301
2302static int mv88e6xxx_setup_port_mode(struct mv88e6xxx_chip *chip, int port)
2303{
2304 if (dsa_is_dsa_port(chip->ds, port))
2305 return mv88e6xxx_set_port_mode_dsa(chip, port);
2306
2307 if (dsa_is_normal_port(chip->ds, port))
2308 return mv88e6xxx_set_port_mode_normal(chip, port);
2309
2310 /* Setup CPU port mode depending on its supported tag format */
2311 if (chip->info->tag_protocol == DSA_TAG_PROTO_DSA)
2312 return mv88e6xxx_set_port_mode_dsa(chip, port);
2313
2314 if (chip->info->tag_protocol == DSA_TAG_PROTO_EDSA)
2315 return mv88e6xxx_set_port_mode_edsa(chip, port);
2316
2317 return -EINVAL;
2318}
2319
Vivien Didelotea698f42017-03-11 16:12:50 -05002320static int mv88e6xxx_setup_message_port(struct mv88e6xxx_chip *chip, int port)
2321{
2322 bool message = dsa_is_dsa_port(chip->ds, port);
2323
2324 return mv88e6xxx_port_set_message_port(chip, port, message);
2325}
2326
Vivien Didelot601aeed2017-03-11 16:13:00 -05002327static int mv88e6xxx_setup_egress_floods(struct mv88e6xxx_chip *chip, int port)
2328{
2329 bool flood = port == dsa_upstream_port(chip->ds);
2330
2331 /* Upstream ports flood frames with unknown unicast or multicast DA */
2332 if (chip->info->ops->port_set_egress_floods)
2333 return chip->info->ops->port_set_egress_floods(chip, port,
2334 flood, flood);
2335
2336 return 0;
2337}
2338
Vivien Didelotfad09c72016-06-21 12:28:20 -04002339static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002340{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002341 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002342 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002343 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002344
Vivien Didelotd78343d2016-11-04 03:23:36 +01002345 /* MAC Forcing register: don't force link, speed, duplex or flow control
2346 * state to any particular values on physical ports, but force the CPU
2347 * port and all DSA ports to their maximum bandwidth and full duplex.
2348 */
2349 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2350 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2351 SPEED_MAX, DUPLEX_FULL,
2352 PHY_INTERFACE_MODE_NA);
2353 else
2354 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2355 SPEED_UNFORCED, DUPLEX_UNFORCED,
2356 PHY_INTERFACE_MODE_NA);
2357 if (err)
2358 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002359
2360 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2361 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2362 * tunneling, determine priority by looking at 802.1p and IP
2363 * priority fields (IP prio has precedence), and set STP state
2364 * to Forwarding.
2365 *
2366 * If this is the CPU link, use DSA or EDSA tagging depending
2367 * on which tagging mode was configured.
2368 *
2369 * If this is a link to another switch, use DSA tagging mode.
2370 *
2371 * If this is the upstream port for this switch, enable
2372 * forwarding of unknown unicasts and multicasts.
2373 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002374 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002375 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2376 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002377 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2378 if (err)
2379 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002380
Vivien Didelot601aeed2017-03-11 16:13:00 -05002381 err = mv88e6xxx_setup_port_mode(chip, port);
Andrew Lunn56995cb2016-12-03 04:35:19 +01002382 if (err)
2383 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002384
Vivien Didelot601aeed2017-03-11 16:13:00 -05002385 err = mv88e6xxx_setup_egress_floods(chip, port);
Vivien Didelot43145572017-03-11 16:12:59 -05002386 if (err)
2387 return err;
2388
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002389 /* If this port is connected to a SerDes, make sure the SerDes is not
2390 * powered down.
2391 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002392 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002393 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2394 if (err)
2395 return err;
2396 reg &= PORT_STATUS_CMODE_MASK;
2397 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2398 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2399 (reg == PORT_STATUS_CMODE_SGMII)) {
2400 err = mv88e6xxx_serdes_power_on(chip);
2401 if (err < 0)
2402 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002403 }
2404 }
2405
Vivien Didelot8efdda42015-08-13 12:52:23 -04002406 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002407 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002408 * untagged frames on this port, do a destination address lookup on all
2409 * received packets as usual, disable ARP mirroring and don't send a
2410 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002411 */
Andrew Lunna23b2962017-02-04 20:15:28 +01002412 err = mv88e6xxx_port_set_map_da(chip, port);
2413 if (err)
2414 return err;
2415
Andrew Lunn54d792f2015-05-06 01:09:47 +02002416 reg = 0;
Andrew Lunna23b2962017-02-04 20:15:28 +01002417 if (chip->info->ops->port_set_upstream_port) {
2418 err = chip->info->ops->port_set_upstream_port(
2419 chip, port, dsa_upstream_port(ds));
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002420 if (err)
2421 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002422 }
2423
Andrew Lunna23b2962017-02-04 20:15:28 +01002424 err = mv88e6xxx_port_set_8021q_mode(chip, port,
2425 PORT_CONTROL_2_8021Q_DISABLED);
2426 if (err)
2427 return err;
2428
Andrew Lunn5f436662016-12-03 04:45:17 +01002429 if (chip->info->ops->port_jumbo_config) {
2430 err = chip->info->ops->port_jumbo_config(chip, port);
2431 if (err)
2432 return err;
2433 }
2434
Andrew Lunn54d792f2015-05-06 01:09:47 +02002435 /* Port Association Vector: when learning source addresses
2436 * of packets, add the address to the address database using
2437 * a port bitmap that has only the bit for this port set and
2438 * the other bits clear.
2439 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002440 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002441 /* Disable learning for CPU port */
2442 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002443 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002444
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002445 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2446 if (err)
2447 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002448
2449 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002450 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2451 if (err)
2452 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002453
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002454 if (chip->info->ops->port_pause_config) {
2455 err = chip->info->ops->port_pause_config(chip, port);
2456 if (err)
2457 return err;
2458 }
2459
Vivien Didelotc8c94892017-03-11 16:13:01 -05002460 if (chip->info->ops->port_disable_learn_limit) {
2461 err = chip->info->ops->port_disable_learn_limit(chip, port);
2462 if (err)
2463 return err;
2464 }
2465
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002466 if (chip->info->ops->port_disable_pri_override) {
2467 err = chip->info->ops->port_disable_pri_override(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002468 if (err)
2469 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002470 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002471
Andrew Lunnef0a7312016-12-03 04:35:16 +01002472 if (chip->info->ops->port_tag_remap) {
2473 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002474 if (err)
2475 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002476 }
2477
Andrew Lunnef70b112016-12-03 04:45:18 +01002478 if (chip->info->ops->port_egress_rate_limiting) {
2479 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002480 if (err)
2481 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002482 }
2483
Vivien Didelotea698f42017-03-11 16:12:50 -05002484 err = mv88e6xxx_setup_message_port(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002485 if (err)
2486 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002487
Vivien Didelot207afda2016-04-14 14:42:09 -04002488 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002489 * database, and allow bidirectional communication between the
2490 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002491 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002492 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002493 if (err)
2494 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002495
Vivien Didelot240ea3e2017-03-30 17:37:12 -04002496 err = mv88e6xxx_port_vlan_map(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002497 if (err)
2498 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002499
2500 /* Default VLAN ID and priority: don't set a default VLAN
2501 * ID, and set the default packet priority to zero.
2502 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002503 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002504}
2505
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002506static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002507{
2508 int err;
2509
Vivien Didelota935c052016-09-29 12:21:53 -04002510 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002511 if (err)
2512 return err;
2513
Vivien Didelota935c052016-09-29 12:21:53 -04002514 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002515 if (err)
2516 return err;
2517
Vivien Didelota935c052016-09-29 12:21:53 -04002518 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2519 if (err)
2520 return err;
2521
2522 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002523}
2524
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002525static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2526 unsigned int ageing_time)
2527{
Vivien Didelot04bed142016-08-31 18:06:13 -04002528 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002529 int err;
2530
2531 mutex_lock(&chip->reg_lock);
Vivien Didelot720c6342017-03-11 16:12:48 -05002532 err = mv88e6xxx_g1_atu_set_age_time(chip, ageing_time);
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002533 mutex_unlock(&chip->reg_lock);
2534
2535 return err;
2536}
2537
Vivien Didelot97299342016-07-18 20:45:30 -04002538static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002539{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002540 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002541 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002542 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002543
Vivien Didelot119477b2016-05-09 13:22:51 -04002544 /* Enable the PHY Polling Unit if present, don't discard any packets,
2545 * and mask all interrupt sources.
2546 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002547 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002548 if (err)
2549 return err;
2550
Andrew Lunn33641992016-12-03 04:35:17 +01002551 if (chip->info->ops->g1_set_cpu_port) {
2552 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2553 if (err)
2554 return err;
2555 }
2556
2557 if (chip->info->ops->g1_set_egress_port) {
2558 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2559 if (err)
2560 return err;
2561 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002562
Vivien Didelot50484ff2016-05-09 13:22:54 -04002563 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002564 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2565 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2566 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002567 if (err)
2568 return err;
2569
Vivien Didelotacddbd22016-07-18 20:45:39 -04002570 /* Clear all the VTU and STU entries */
2571 err = _mv88e6xxx_vtu_stu_flush(chip);
2572 if (err < 0)
2573 return err;
2574
Vivien Didelot08a01262016-05-09 13:22:50 -04002575 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002576 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
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_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002580 if (err)
2581 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002582 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002583 if (err)
2584 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002585 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002586 if (err)
2587 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002588 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002589 if (err)
2590 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002591 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002592 if (err)
2593 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002594 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002595 if (err)
2596 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002597 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002598 if (err)
2599 return err;
2600
2601 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002602 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002603 if (err)
2604 return err;
2605
Andrew Lunnde2273872016-11-21 23:27:01 +01002606 /* Initialize the statistics unit */
2607 err = mv88e6xxx_stats_set_histogram(chip);
2608 if (err)
2609 return err;
2610
Vivien Didelot97299342016-07-18 20:45:30 -04002611 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002612 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2613 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002614 if (err)
2615 return err;
2616
2617 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002618 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002619 if (err)
2620 return err;
2621
2622 return 0;
2623}
2624
Vivien Didelotf81ec902016-05-09 13:22:58 -04002625static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002626{
Vivien Didelot04bed142016-08-31 18:06:13 -04002627 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002628 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002629 int i;
2630
Vivien Didelotfad09c72016-06-21 12:28:20 -04002631 chip->ds = ds;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002632 ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002633
Vivien Didelotfad09c72016-06-21 12:28:20 -04002634 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002635
Vivien Didelot97299342016-07-18 20:45:30 -04002636 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002637 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002638 err = mv88e6xxx_setup_port(chip, i);
2639 if (err)
2640 goto unlock;
2641 }
2642
2643 /* Setup Switch Global 1 Registers */
2644 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002645 if (err)
2646 goto unlock;
2647
Vivien Didelot97299342016-07-18 20:45:30 -04002648 /* Setup Switch Global 2 Registers */
2649 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2650 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002651 if (err)
2652 goto unlock;
2653 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002654
Vivien Didelot81228992017-03-30 17:37:08 -04002655 err = mv88e6xxx_pvt_setup(chip);
2656 if (err)
2657 goto unlock;
2658
Vivien Didelota2ac29d2017-03-11 16:12:49 -05002659 err = mv88e6xxx_atu_setup(chip);
2660 if (err)
2661 goto unlock;
2662
Andrew Lunn6e55f692016-12-03 04:45:16 +01002663 /* Some generations have the configuration of sending reserved
2664 * management frames to the CPU in global2, others in
2665 * global1. Hence it does not fit the two setup functions
2666 * above.
2667 */
2668 if (chip->info->ops->mgmt_rsvd2cpu) {
2669 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2670 if (err)
2671 goto unlock;
2672 }
2673
Vivien Didelot6b17e862015-08-13 12:52:18 -04002674unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002675 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002676
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002677 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002678}
2679
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002680static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2681{
Vivien Didelot04bed142016-08-31 18:06:13 -04002682 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002683 int err;
2684
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002685 if (!chip->info->ops->set_switch_mac)
2686 return -EOPNOTSUPP;
2687
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002688 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002689 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002690 mutex_unlock(&chip->reg_lock);
2691
2692 return err;
2693}
2694
Vivien Didelote57e5e72016-08-15 17:19:00 -04002695static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002696{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002697 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2698 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002699 u16 val;
2700 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002701
Andrew Lunnee26a222017-01-24 14:53:48 +01002702 if (!chip->info->ops->phy_read)
2703 return -EOPNOTSUPP;
2704
Vivien Didelotfad09c72016-06-21 12:28:20 -04002705 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002706 err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002707 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002708
Andrew Lunnda9f3302017-02-01 03:40:05 +01002709 if (reg == MII_PHYSID2) {
2710 /* Some internal PHYS don't have a model number. Use
2711 * the mv88e6390 family model number instead.
2712 */
2713 if (!(val & 0x3f0))
2714 val |= PORT_SWITCH_ID_PROD_NUM_6390;
2715 }
2716
Vivien Didelote57e5e72016-08-15 17:19:00 -04002717 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002718}
2719
Vivien Didelote57e5e72016-08-15 17:19:00 -04002720static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002721{
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002722 struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
2723 struct mv88e6xxx_chip *chip = mdio_bus->chip;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002724 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002725
Andrew Lunnee26a222017-01-24 14:53:48 +01002726 if (!chip->info->ops->phy_write)
2727 return -EOPNOTSUPP;
2728
Vivien Didelotfad09c72016-06-21 12:28:20 -04002729 mutex_lock(&chip->reg_lock);
Andrew Lunnee26a222017-01-24 14:53:48 +01002730 err = chip->info->ops->phy_write(chip, bus, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002731 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002732
2733 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002734}
2735
Vivien Didelotfad09c72016-06-21 12:28:20 -04002736static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunna3c53be52017-01-24 14:53:50 +01002737 struct device_node *np,
2738 bool external)
Andrew Lunnb516d452016-06-04 21:17:06 +02002739{
2740 static int index;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002741 struct mv88e6xxx_mdio_bus *mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002742 struct mii_bus *bus;
2743 int err;
2744
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002745 bus = devm_mdiobus_alloc_size(chip->dev, sizeof(*mdio_bus));
Andrew Lunnb516d452016-06-04 21:17:06 +02002746 if (!bus)
2747 return -ENOMEM;
2748
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002749 mdio_bus = bus->priv;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002750 mdio_bus->bus = bus;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002751 mdio_bus->chip = chip;
Andrew Lunna3c53be52017-01-24 14:53:50 +01002752 INIT_LIST_HEAD(&mdio_bus->list);
2753 mdio_bus->external = external;
Andrew Lunn0dd12d52017-01-24 14:53:49 +01002754
Andrew Lunnb516d452016-06-04 21:17:06 +02002755 if (np) {
2756 bus->name = np->full_name;
2757 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2758 } else {
2759 bus->name = "mv88e6xxx SMI";
2760 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2761 }
2762
2763 bus->read = mv88e6xxx_mdio_read;
2764 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002765 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002766
Andrew Lunna3c53be52017-01-24 14:53:50 +01002767 if (np)
2768 err = of_mdiobus_register(bus, np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002769 else
2770 err = mdiobus_register(bus);
2771 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002772 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunna3c53be52017-01-24 14:53:50 +01002773 return err;
Andrew Lunnb516d452016-06-04 21:17:06 +02002774 }
Andrew Lunna3c53be52017-01-24 14:53:50 +01002775
2776 if (external)
2777 list_add_tail(&mdio_bus->list, &chip->mdios);
2778 else
2779 list_add(&mdio_bus->list, &chip->mdios);
Andrew Lunnb516d452016-06-04 21:17:06 +02002780
2781 return 0;
Andrew Lunnb516d452016-06-04 21:17:06 +02002782}
2783
Andrew Lunna3c53be52017-01-24 14:53:50 +01002784static const struct of_device_id mv88e6xxx_mdio_external_match[] = {
2785 { .compatible = "marvell,mv88e6xxx-mdio-external",
2786 .data = (void *)true },
2787 { },
2788};
2789
2790static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
2791 struct device_node *np)
2792{
2793 const struct of_device_id *match;
2794 struct device_node *child;
2795 int err;
2796
2797 /* Always register one mdio bus for the internal/default mdio
2798 * bus. This maybe represented in the device tree, but is
2799 * optional.
2800 */
2801 child = of_get_child_by_name(np, "mdio");
2802 err = mv88e6xxx_mdio_register(chip, child, false);
2803 if (err)
2804 return err;
2805
2806 /* Walk the device tree, and see if there are any other nodes
2807 * which say they are compatible with the external mdio
2808 * bus.
2809 */
2810 for_each_available_child_of_node(np, child) {
2811 match = of_match_node(mv88e6xxx_mdio_external_match, child);
2812 if (match) {
2813 err = mv88e6xxx_mdio_register(chip, child, true);
2814 if (err)
2815 return err;
2816 }
2817 }
2818
2819 return 0;
2820}
2821
2822static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002823
2824{
Andrew Lunna3c53be52017-01-24 14:53:50 +01002825 struct mv88e6xxx_mdio_bus *mdio_bus;
2826 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002827
Andrew Lunna3c53be52017-01-24 14:53:50 +01002828 list_for_each_entry(mdio_bus, &chip->mdios, list) {
2829 bus = mdio_bus->bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002830
Andrew Lunna3c53be52017-01-24 14:53:50 +01002831 mdiobus_unregister(bus);
2832 }
Andrew Lunnb516d452016-06-04 21:17:06 +02002833}
2834
Vivien Didelot855b1932016-07-20 18:18:35 -04002835static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2836{
Vivien Didelot04bed142016-08-31 18:06:13 -04002837 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002838
2839 return chip->eeprom_len;
2840}
2841
Vivien Didelot855b1932016-07-20 18:18:35 -04002842static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2843 struct ethtool_eeprom *eeprom, u8 *data)
2844{
Vivien Didelot04bed142016-08-31 18:06:13 -04002845 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002846 int err;
2847
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002848 if (!chip->info->ops->get_eeprom)
2849 return -EOPNOTSUPP;
2850
Vivien Didelot855b1932016-07-20 18:18:35 -04002851 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002852 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002853 mutex_unlock(&chip->reg_lock);
2854
2855 if (err)
2856 return err;
2857
2858 eeprom->magic = 0xc3ec4951;
2859
2860 return 0;
2861}
2862
Vivien Didelot855b1932016-07-20 18:18:35 -04002863static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
2864 struct ethtool_eeprom *eeprom, u8 *data)
2865{
Vivien Didelot04bed142016-08-31 18:06:13 -04002866 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002867 int err;
2868
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002869 if (!chip->info->ops->set_eeprom)
2870 return -EOPNOTSUPP;
2871
Vivien Didelot855b1932016-07-20 18:18:35 -04002872 if (eeprom->magic != 0xc3ec4951)
2873 return -EINVAL;
2874
2875 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002876 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002877 mutex_unlock(&chip->reg_lock);
2878
2879 return err;
2880}
2881
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002882static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002883 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002884 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002885 .phy_read = mv88e6xxx_phy_ppu_read,
2886 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002887 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002888 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002889 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002890 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002891 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002892 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002893 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01002894 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002895 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002896 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002897 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002898 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002899 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2900 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002901 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002902 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2903 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002904 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002905 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002906 .ppu_enable = mv88e6185_g1_ppu_enable,
2907 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002908 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002909};
2910
2911static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002912 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002913 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002914 .phy_read = mv88e6xxx_phy_ppu_read,
2915 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002916 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002917 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002918 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002919 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002920 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunna23b2962017-02-04 20:15:28 +01002921 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002922 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002923 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2924 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002925 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002926 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05002927 .ppu_enable = mv88e6185_g1_ppu_enable,
2928 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002929 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002930};
2931
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002932static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01002933 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002934 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
2935 .phy_read = mv88e6xxx_g2_smi_phy_read,
2936 .phy_write = mv88e6xxx_g2_smi_phy_write,
2937 .port_set_link = mv88e6xxx_port_set_link,
2938 .port_set_duplex = mv88e6xxx_port_set_duplex,
2939 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002940 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002941 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002942 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002943 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01002944 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002945 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002946 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002947 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002948 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002949 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
2950 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2951 .stats_get_strings = mv88e6095_stats_get_strings,
2952 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002953 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2954 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Volodymyr Bendiuga91eaa472017-02-14 11:29:30 +01002955 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002956 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002957 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01002958};
2959
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002960static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002961 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002962 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01002963 .phy_read = mv88e6165_phy_read,
2964 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002965 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002966 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002967 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002968 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002969 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Vivien Didelotc8c94892017-03-11 16:13:01 -05002970 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05002971 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002972 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01002973 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
2974 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01002975 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01002976 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
2977 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01002978 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01002979 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05002980 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002981};
2982
2983static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01002984 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002985 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04002986 .phy_read = mv88e6xxx_phy_ppu_read,
2987 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01002988 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01002989 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01002990 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01002991 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002992 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05002993 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01002994 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunna23b2962017-02-04 20:15:28 +01002995 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunn5f436662016-12-03 04:45:17 +01002996 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01002997 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002998 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01002999 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003000 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3001 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003002 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003003 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3004 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003005 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003006 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003007 .ppu_enable = mv88e6185_g1_ppu_enable,
3008 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003009 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003010};
3011
Vivien Didelot990e27b2017-03-28 13:50:32 -04003012static const struct mv88e6xxx_ops mv88e6141_ops = {
3013 /* MV88E6XXX_FAMILY_6341 */
3014 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3015 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3016 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3017 .phy_read = mv88e6xxx_g2_smi_phy_read,
3018 .phy_write = mv88e6xxx_g2_smi_phy_write,
3019 .port_set_link = mv88e6xxx_port_set_link,
3020 .port_set_duplex = mv88e6xxx_port_set_duplex,
3021 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3022 .port_set_speed = mv88e6390_port_set_speed,
3023 .port_tag_remap = mv88e6095_port_tag_remap,
3024 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3025 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3026 .port_set_ether_type = mv88e6351_port_set_ether_type,
3027 .port_jumbo_config = mv88e6165_port_jumbo_config,
3028 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3029 .port_pause_config = mv88e6097_port_pause_config,
3030 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3031 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3032 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3033 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3034 .stats_get_strings = mv88e6320_stats_get_strings,
3035 .stats_get_stats = mv88e6390_stats_get_stats,
3036 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3037 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3038 .watchdog_ops = &mv88e6390_watchdog_ops,
3039 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3040 .reset = mv88e6352_g1_reset,
3041};
3042
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003043static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003044 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003045 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003046 .phy_read = mv88e6165_phy_read,
3047 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003048 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003049 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003050 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003051 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003052 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003053 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003054 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003055 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003056 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003057 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003058 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003059 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003060 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003061 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3062 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003063 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003064 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3065 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003066 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003067 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003068 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003069};
3070
3071static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003072 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003073 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003074 .phy_read = mv88e6165_phy_read,
3075 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003076 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003077 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003078 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003079 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003080 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003081 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003082 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3083 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003084 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003085 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3086 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003087 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003088 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003089 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003090};
3091
3092static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003093 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003094 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003095 .phy_read = mv88e6xxx_g2_smi_phy_read,
3096 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003097 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003098 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003099 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003100 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003101 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003102 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003103 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003104 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003105 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003106 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003107 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003108 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003109 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003110 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003111 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3112 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003113 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003114 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3115 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003116 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003117 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003118 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003119};
3120
3121static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003122 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003123 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3124 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003125 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003126 .phy_read = mv88e6xxx_g2_smi_phy_read,
3127 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003128 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003129 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003130 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003131 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003132 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003133 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003134 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003135 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003136 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003137 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003138 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003139 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003140 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003141 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003142 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3143 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003144 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003145 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3146 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003147 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003148 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003149 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003150};
3151
3152static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003153 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003154 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003155 .phy_read = mv88e6xxx_g2_smi_phy_read,
3156 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003157 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003158 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003159 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003160 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003161 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003162 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003163 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003164 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003165 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003166 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003167 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003168 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003169 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003170 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003171 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3172 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003173 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003174 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3175 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003176 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003177 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003178 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003179};
3180
3181static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003182 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003183 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3184 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003185 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003186 .phy_read = mv88e6xxx_g2_smi_phy_read,
3187 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003188 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003189 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003190 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003191 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003192 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003193 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003194 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003195 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003196 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003197 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003198 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003199 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003200 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003201 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003202 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3203 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003204 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003205 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3206 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003207 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003208 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003209 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003210};
3211
3212static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003213 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003214 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003215 .phy_read = mv88e6xxx_phy_ppu_read,
3216 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003217 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003218 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003219 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003220 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003221 .port_set_egress_floods = mv88e6185_port_set_egress_floods,
Andrew Lunnef70b112016-12-03 04:45:18 +01003222 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna23b2962017-02-04 20:15:28 +01003223 .port_set_upstream_port = mv88e6095_port_set_upstream_port,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003224 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003225 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3226 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003227 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003228 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3229 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003230 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003231 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003232 .ppu_enable = mv88e6185_g1_ppu_enable,
3233 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003234 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003235};
3236
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003237static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003238 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003239 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3240 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003241 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3242 .phy_read = mv88e6xxx_g2_smi_phy_read,
3243 .phy_write = mv88e6xxx_g2_smi_phy_write,
3244 .port_set_link = mv88e6xxx_port_set_link,
3245 .port_set_duplex = mv88e6xxx_port_set_duplex,
3246 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3247 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003248 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003249 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003250 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003251 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003252 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003253 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003254 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003255 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003256 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003257 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3258 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003259 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003260 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3261 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003262 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003263 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003264 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003265};
3266
3267static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003268 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003269 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3270 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003271 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3272 .phy_read = mv88e6xxx_g2_smi_phy_read,
3273 .phy_write = mv88e6xxx_g2_smi_phy_write,
3274 .port_set_link = mv88e6xxx_port_set_link,
3275 .port_set_duplex = mv88e6xxx_port_set_duplex,
3276 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3277 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003278 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003279 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003280 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003281 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003282 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003283 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003284 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003285 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003286 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003287 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3288 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003289 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003290 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3291 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003292 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003293 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003294 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003295};
3296
3297static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003298 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003299 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3300 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003301 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3302 .phy_read = mv88e6xxx_g2_smi_phy_read,
3303 .phy_write = mv88e6xxx_g2_smi_phy_write,
3304 .port_set_link = mv88e6xxx_port_set_link,
3305 .port_set_duplex = mv88e6xxx_port_set_duplex,
3306 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3307 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003308 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003309 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003310 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003311 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003312 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003313 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003314 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003315 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003316 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003317 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3318 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003319 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003320 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3321 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003322 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003323 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003324 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003325};
3326
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003327static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003328 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003329 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3330 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003331 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003332 .phy_read = mv88e6xxx_g2_smi_phy_read,
3333 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003334 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003335 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003336 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003337 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003338 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003339 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003340 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003341 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003342 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003343 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003344 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003345 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003346 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003347 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003348 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3349 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003350 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003351 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3352 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003353 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003354 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003355 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003356};
3357
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003358static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003359 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003360 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3361 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003362 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3363 .phy_read = mv88e6xxx_g2_smi_phy_read,
3364 .phy_write = mv88e6xxx_g2_smi_phy_write,
3365 .port_set_link = mv88e6xxx_port_set_link,
3366 .port_set_duplex = mv88e6xxx_port_set_duplex,
3367 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3368 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003369 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003370 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003371 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003372 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003373 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003374 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003375 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003376 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003377 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003378 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003379 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3380 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003381 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003382 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3383 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003384 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003385 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003386 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003387};
3388
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003389static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003390 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003391 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3392 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003393 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003394 .phy_read = mv88e6xxx_g2_smi_phy_read,
3395 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003396 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003397 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003398 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003399 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003400 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003401 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003402 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003403 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003404 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003405 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003406 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003407 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003408 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003409 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3410 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003411 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003412 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3413 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003414 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003415 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003416};
3417
3418static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003419 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003420 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3421 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003422 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003423 .phy_read = mv88e6xxx_g2_smi_phy_read,
3424 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003425 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003426 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003427 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003428 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003429 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003430 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003431 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003432 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003433 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003434 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003435 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003436 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003437 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003438 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3439 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003440 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003441 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3442 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003443 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003444};
3445
Vivien Didelot16e329a2017-03-28 13:50:33 -04003446static const struct mv88e6xxx_ops mv88e6341_ops = {
3447 /* MV88E6XXX_FAMILY_6341 */
3448 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3449 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
3450 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3451 .phy_read = mv88e6xxx_g2_smi_phy_read,
3452 .phy_write = mv88e6xxx_g2_smi_phy_write,
3453 .port_set_link = mv88e6xxx_port_set_link,
3454 .port_set_duplex = mv88e6xxx_port_set_duplex,
3455 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3456 .port_set_speed = mv88e6390_port_set_speed,
3457 .port_tag_remap = mv88e6095_port_tag_remap,
3458 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3459 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
3460 .port_set_ether_type = mv88e6351_port_set_ether_type,
3461 .port_jumbo_config = mv88e6165_port_jumbo_config,
3462 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
3463 .port_pause_config = mv88e6097_port_pause_config,
3464 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
3465 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
3466 .stats_snapshot = mv88e6390_g1_stats_snapshot,
3467 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3468 .stats_get_strings = mv88e6320_stats_get_strings,
3469 .stats_get_stats = mv88e6390_stats_get_stats,
3470 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3471 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
3472 .watchdog_ops = &mv88e6390_watchdog_ops,
3473 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
3474 .reset = mv88e6352_g1_reset,
3475};
3476
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003477static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003478 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003479 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003480 .phy_read = mv88e6xxx_g2_smi_phy_read,
3481 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003482 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003483 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003484 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003485 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003486 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003487 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003488 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003489 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003490 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003491 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003492 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003493 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003494 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003495 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003496 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3497 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003498 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003499 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3500 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003501 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003502 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003503 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003504};
3505
3506static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003507 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003508 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003509 .phy_read = mv88e6xxx_g2_smi_phy_read,
3510 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003511 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003512 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003513 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003514 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003515 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003516 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003517 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003518 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003519 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003520 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003521 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003522 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003523 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003524 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003525 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3526 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003527 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003528 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3529 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003530 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003531 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003532 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003533};
3534
3535static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003536 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003537 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3538 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003539 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003540 .phy_read = mv88e6xxx_g2_smi_phy_read,
3541 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003542 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003543 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003544 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003545 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003546 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003547 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003548 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003549 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003550 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003551 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003552 .port_pause_config = mv88e6097_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003553 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003554 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003555 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003556 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3557 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003558 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003559 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3560 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunnfcd25162017-02-09 00:03:42 +01003561 .watchdog_ops = &mv88e6097_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003562 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003563 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003564};
3565
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003566static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003567 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003568 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3569 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003570 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3571 .phy_read = mv88e6xxx_g2_smi_phy_read,
3572 .phy_write = mv88e6xxx_g2_smi_phy_write,
3573 .port_set_link = mv88e6xxx_port_set_link,
3574 .port_set_duplex = mv88e6xxx_port_set_duplex,
3575 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3576 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003577 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003578 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003579 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003580 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003581 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003582 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003583 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunnf39908d2017-02-04 20:02:50 +01003584 .port_set_cmode = mv88e6390x_port_set_cmode,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003585 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003586 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003587 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003588 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003589 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3590 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003591 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003592 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3593 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003594 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003595 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003596 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003597};
3598
3599static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003600 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003601 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3602 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003603 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3604 .phy_read = mv88e6xxx_g2_smi_phy_read,
3605 .phy_write = mv88e6xxx_g2_smi_phy_write,
3606 .port_set_link = mv88e6xxx_port_set_link,
3607 .port_set_duplex = mv88e6xxx_port_set_duplex,
3608 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3609 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003610 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003611 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
Vivien Didelot601aeed2017-03-11 16:13:00 -05003612 .port_set_egress_floods = mv88e6352_port_set_egress_floods,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003613 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003614 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003615 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003616 .port_pause_config = mv88e6390_port_pause_config,
Vivien Didelotc8c94892017-03-11 16:13:01 -05003617 .port_disable_learn_limit = mv88e6xxx_port_disable_learn_limit,
Vivien Didelot9dbfb4e2017-03-11 16:13:02 -05003618 .port_disable_pri_override = mv88e6xxx_port_disable_pri_override,
Andrew Lunn79523472016-11-21 23:27:00 +01003619 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003620 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003621 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3622 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003623 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003624 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3625 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn61303732017-02-09 00:03:43 +01003626 .watchdog_ops = &mv88e6390_watchdog_ops,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003627 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003628 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003629};
3630
Vivien Didelotf81ec902016-05-09 13:22:58 -04003631static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3632 [MV88E6085] = {
3633 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3634 .family = MV88E6XXX_FAMILY_6097,
3635 .name = "Marvell 88E6085",
3636 .num_databases = 4096,
3637 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003638 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003639 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003640 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003641 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003642 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003643 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003644 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003645 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003646 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003647 },
3648
3649 [MV88E6095] = {
3650 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3651 .family = MV88E6XXX_FAMILY_6095,
3652 .name = "Marvell 88E6095/88E6095F",
3653 .num_databases = 256,
3654 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003655 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003656 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003657 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003658 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003659 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003660 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003661 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003662 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003663 },
3664
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003665 [MV88E6097] = {
3666 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3667 .family = MV88E6XXX_FAMILY_6097,
3668 .name = "Marvell 88E6097/88E6097F",
3669 .num_databases = 4096,
3670 .num_ports = 11,
3671 .port_base_addr = 0x10,
3672 .global1_addr = 0x1b,
3673 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003674 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003675 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003676 .pvt = true,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003677 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003678 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3679 .ops = &mv88e6097_ops,
3680 },
3681
Vivien Didelotf81ec902016-05-09 13:22:58 -04003682 [MV88E6123] = {
3683 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3684 .family = MV88E6XXX_FAMILY_6165,
3685 .name = "Marvell 88E6123",
3686 .num_databases = 4096,
3687 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003688 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003689 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003690 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003691 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003692 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003693 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003694 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003695 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003696 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003697 },
3698
3699 [MV88E6131] = {
3700 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3701 .family = MV88E6XXX_FAMILY_6185,
3702 .name = "Marvell 88E6131",
3703 .num_databases = 256,
3704 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003705 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003706 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003707 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003708 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003709 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003710 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003711 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003712 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003713 },
3714
Vivien Didelot990e27b2017-03-28 13:50:32 -04003715 [MV88E6141] = {
3716 .prod_num = PORT_SWITCH_ID_PROD_NUM_6141,
3717 .family = MV88E6XXX_FAMILY_6341,
3718 .name = "Marvell 88E6341",
3719 .num_databases = 4096,
3720 .num_ports = 6,
3721 .port_base_addr = 0x10,
3722 .global1_addr = 0x1b,
3723 .age_time_coeff = 3750,
3724 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003725 .pvt = true,
Vivien Didelot990e27b2017-03-28 13:50:32 -04003726 .tag_protocol = DSA_TAG_PROTO_EDSA,
3727 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3728 .ops = &mv88e6141_ops,
3729 },
3730
Vivien Didelotf81ec902016-05-09 13:22:58 -04003731 [MV88E6161] = {
3732 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3733 .family = MV88E6XXX_FAMILY_6165,
3734 .name = "Marvell 88E6161",
3735 .num_databases = 4096,
3736 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003737 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003738 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003739 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003740 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003741 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003742 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003743 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003744 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003745 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003746 },
3747
3748 [MV88E6165] = {
3749 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3750 .family = MV88E6XXX_FAMILY_6165,
3751 .name = "Marvell 88E6165",
3752 .num_databases = 4096,
3753 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003754 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003755 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003756 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003757 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003758 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003759 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003760 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003761 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003762 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003763 },
3764
3765 [MV88E6171] = {
3766 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3767 .family = MV88E6XXX_FAMILY_6351,
3768 .name = "Marvell 88E6171",
3769 .num_databases = 4096,
3770 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003771 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003772 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003773 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003774 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003775 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003776 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003777 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003778 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003779 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003780 },
3781
3782 [MV88E6172] = {
3783 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3784 .family = MV88E6XXX_FAMILY_6352,
3785 .name = "Marvell 88E6172",
3786 .num_databases = 4096,
3787 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003788 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003789 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003790 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003791 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003792 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003793 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003794 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003795 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003796 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003797 },
3798
3799 [MV88E6175] = {
3800 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3801 .family = MV88E6XXX_FAMILY_6351,
3802 .name = "Marvell 88E6175",
3803 .num_databases = 4096,
3804 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003805 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003806 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003807 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003808 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003809 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003810 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003811 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003812 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003813 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003814 },
3815
3816 [MV88E6176] = {
3817 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3818 .family = MV88E6XXX_FAMILY_6352,
3819 .name = "Marvell 88E6176",
3820 .num_databases = 4096,
3821 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003822 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003823 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003824 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003825 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003826 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003827 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003828 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003829 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003830 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003831 },
3832
3833 [MV88E6185] = {
3834 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3835 .family = MV88E6XXX_FAMILY_6185,
3836 .name = "Marvell 88E6185",
3837 .num_databases = 256,
3838 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003839 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003840 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003841 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003842 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003843 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003844 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003845 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003846 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003847 },
3848
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003849 [MV88E6190] = {
3850 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3851 .family = MV88E6XXX_FAMILY_6390,
3852 .name = "Marvell 88E6190",
3853 .num_databases = 4096,
3854 .num_ports = 11, /* 10 + Z80 */
3855 .port_base_addr = 0x0,
3856 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003857 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003858 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003859 .g1_irqs = 9,
Vivien Didelotf3645652017-03-30 17:37:07 -04003860 .pvt = true,
Vivien Didelote606ca32017-03-11 16:12:55 -05003861 .atu_move_port_mask = 0x1f,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003862 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3863 .ops = &mv88e6190_ops,
3864 },
3865
3866 [MV88E6190X] = {
3867 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3868 .family = MV88E6XXX_FAMILY_6390,
3869 .name = "Marvell 88E6190X",
3870 .num_databases = 4096,
3871 .num_ports = 11, /* 10 + Z80 */
3872 .port_base_addr = 0x0,
3873 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003874 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003875 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003876 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003877 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003878 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003879 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3880 .ops = &mv88e6190x_ops,
3881 },
3882
3883 [MV88E6191] = {
3884 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3885 .family = MV88E6XXX_FAMILY_6390,
3886 .name = "Marvell 88E6191",
3887 .num_databases = 4096,
3888 .num_ports = 11, /* 10 + Z80 */
3889 .port_base_addr = 0x0,
3890 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003891 .age_time_coeff = 3750,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003892 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003893 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003894 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003895 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003896 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
Vivien Didelot2cf4cefb2017-03-28 13:50:34 -04003897 .ops = &mv88e6191_ops,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003898 },
3899
Vivien Didelotf81ec902016-05-09 13:22:58 -04003900 [MV88E6240] = {
3901 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3902 .family = MV88E6XXX_FAMILY_6352,
3903 .name = "Marvell 88E6240",
3904 .num_databases = 4096,
3905 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003906 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003907 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003908 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003909 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003910 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003911 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003912 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003913 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003914 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003915 },
3916
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003917 [MV88E6290] = {
3918 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3919 .family = MV88E6XXX_FAMILY_6390,
3920 .name = "Marvell 88E6290",
3921 .num_databases = 4096,
3922 .num_ports = 11, /* 10 + Z80 */
3923 .port_base_addr = 0x0,
3924 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01003925 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003926 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003927 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003928 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003929 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003930 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3931 .ops = &mv88e6290_ops,
3932 },
3933
Vivien Didelotf81ec902016-05-09 13:22:58 -04003934 [MV88E6320] = {
3935 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3936 .family = MV88E6XXX_FAMILY_6320,
3937 .name = "Marvell 88E6320",
3938 .num_databases = 4096,
3939 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003940 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003941 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003942 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003943 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003944 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003945 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003946 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003947 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003948 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003949 },
3950
3951 [MV88E6321] = {
3952 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3953 .family = MV88E6XXX_FAMILY_6320,
3954 .name = "Marvell 88E6321",
3955 .num_databases = 4096,
3956 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003957 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003958 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003959 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003960 .g1_irqs = 8,
Vivien Didelote606ca32017-03-11 16:12:55 -05003961 .atu_move_port_mask = 0xf,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003962 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003963 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003964 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003965 },
3966
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003967 [MV88E6341] = {
3968 .prod_num = PORT_SWITCH_ID_PROD_NUM_6341,
3969 .family = MV88E6XXX_FAMILY_6341,
3970 .name = "Marvell 88E6341",
3971 .num_databases = 4096,
3972 .num_ports = 6,
3973 .port_base_addr = 0x10,
3974 .global1_addr = 0x1b,
3975 .age_time_coeff = 3750,
Vivien Didelote606ca32017-03-11 16:12:55 -05003976 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04003977 .pvt = true,
Gregory CLEMENTa75961d2017-01-30 20:29:34 +01003978 .tag_protocol = DSA_TAG_PROTO_EDSA,
3979 .flags = MV88E6XXX_FLAGS_FAMILY_6341,
3980 .ops = &mv88e6341_ops,
3981 },
3982
Vivien Didelotf81ec902016-05-09 13:22:58 -04003983 [MV88E6350] = {
3984 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3985 .family = MV88E6XXX_FAMILY_6351,
3986 .name = "Marvell 88E6350",
3987 .num_databases = 4096,
3988 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003989 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003990 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003991 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003992 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05003993 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04003994 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003995 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003996 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003997 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003998 },
3999
4000 [MV88E6351] = {
4001 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4002 .family = MV88E6XXX_FAMILY_6351,
4003 .name = "Marvell 88E6351",
4004 .num_databases = 4096,
4005 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004006 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004007 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004008 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004009 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004010 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004011 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004012 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004013 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004014 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004015 },
4016
4017 [MV88E6352] = {
4018 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4019 .family = MV88E6XXX_FAMILY_6352,
4020 .name = "Marvell 88E6352",
4021 .num_databases = 4096,
4022 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004023 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004024 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004025 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004026 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004027 .atu_move_port_mask = 0xf,
Vivien Didelotf3645652017-03-30 17:37:07 -04004028 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004029 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004030 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004031 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004032 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004033 [MV88E6390] = {
4034 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4035 .family = MV88E6XXX_FAMILY_6390,
4036 .name = "Marvell 88E6390",
4037 .num_databases = 4096,
4038 .num_ports = 11, /* 10 + Z80 */
4039 .port_base_addr = 0x0,
4040 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004041 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004042 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004043 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004044 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004045 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004046 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4047 .ops = &mv88e6390_ops,
4048 },
4049 [MV88E6390X] = {
4050 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4051 .family = MV88E6XXX_FAMILY_6390,
4052 .name = "Marvell 88E6390X",
4053 .num_databases = 4096,
4054 .num_ports = 11, /* 10 + Z80 */
4055 .port_base_addr = 0x0,
4056 .global1_addr = 0x1b,
Andrew Lunnb91e0552017-02-02 00:46:15 +01004057 .age_time_coeff = 3750,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004058 .g1_irqs = 9,
Vivien Didelote606ca32017-03-11 16:12:55 -05004059 .atu_move_port_mask = 0x1f,
Vivien Didelotf3645652017-03-30 17:37:07 -04004060 .pvt = true,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004061 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004062 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4063 .ops = &mv88e6390x_ops,
4064 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004065};
4066
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004067static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004068{
Vivien Didelota439c062016-04-17 13:23:58 -04004069 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004070
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004071 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4072 if (mv88e6xxx_table[i].prod_num == prod_num)
4073 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004074
Vivien Didelotb9b37712015-10-30 19:39:48 -04004075 return NULL;
4076}
4077
Vivien Didelotfad09c72016-06-21 12:28:20 -04004078static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004079{
4080 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004081 unsigned int prod_num, rev;
4082 u16 id;
4083 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004084
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004085 mutex_lock(&chip->reg_lock);
4086 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4087 mutex_unlock(&chip->reg_lock);
4088 if (err)
4089 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004090
4091 prod_num = (id & 0xfff0) >> 4;
4092 rev = id & 0x000f;
4093
4094 info = mv88e6xxx_lookup_info(prod_num);
4095 if (!info)
4096 return -ENODEV;
4097
Vivien Didelotcaac8542016-06-20 13:14:09 -04004098 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004099 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004100
Vivien Didelotca070c12016-09-02 14:45:34 -04004101 err = mv88e6xxx_g2_require(chip);
4102 if (err)
4103 return err;
4104
Vivien Didelotfad09c72016-06-21 12:28:20 -04004105 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4106 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004107
4108 return 0;
4109}
4110
Vivien Didelotfad09c72016-06-21 12:28:20 -04004111static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004112{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004113 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004114
Vivien Didelotfad09c72016-06-21 12:28:20 -04004115 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4116 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004117 return NULL;
4118
Vivien Didelotfad09c72016-06-21 12:28:20 -04004119 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004120
Vivien Didelotfad09c72016-06-21 12:28:20 -04004121 mutex_init(&chip->reg_lock);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004122 INIT_LIST_HEAD(&chip->mdios);
Vivien Didelot469d7292016-06-20 13:14:06 -04004123
Vivien Didelotfad09c72016-06-21 12:28:20 -04004124 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004125}
4126
Vivien Didelote57e5e72016-08-15 17:19:00 -04004127static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4128{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004129 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004130 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004131}
4132
Andrew Lunn930188c2016-08-22 16:01:03 +02004133static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4134{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004135 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004136 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004137}
4138
Vivien Didelotfad09c72016-06-21 12:28:20 -04004139static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004140 struct mii_bus *bus, int sw_addr)
4141{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004142 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004143 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004144 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004145 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004146 else
4147 return -EINVAL;
4148
Vivien Didelotfad09c72016-06-21 12:28:20 -04004149 chip->bus = bus;
4150 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004151
4152 return 0;
4153}
4154
Andrew Lunn7b314362016-08-22 16:01:01 +02004155static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4156{
Vivien Didelot04bed142016-08-31 18:06:13 -04004157 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004158
Andrew Lunn443d5a12016-12-03 04:35:18 +01004159 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004160}
4161
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004162static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4163 struct device *host_dev, int sw_addr,
4164 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004165{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004166 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004167 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004168 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004169
Vivien Didelota439c062016-04-17 13:23:58 -04004170 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004171 if (!bus)
4172 return NULL;
4173
Vivien Didelotfad09c72016-06-21 12:28:20 -04004174 chip = mv88e6xxx_alloc_chip(dsa_dev);
4175 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004176 return NULL;
4177
Vivien Didelotcaac8542016-06-20 13:14:09 -04004178 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004179 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004180
Vivien Didelotfad09c72016-06-21 12:28:20 -04004181 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004182 if (err)
4183 goto free;
4184
Vivien Didelotfad09c72016-06-21 12:28:20 -04004185 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004186 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004187 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004188
Andrew Lunndc30c352016-10-16 19:56:49 +02004189 mutex_lock(&chip->reg_lock);
4190 err = mv88e6xxx_switch_reset(chip);
4191 mutex_unlock(&chip->reg_lock);
4192 if (err)
4193 goto free;
4194
Vivien Didelote57e5e72016-08-15 17:19:00 -04004195 mv88e6xxx_phy_init(chip);
4196
Andrew Lunna3c53be52017-01-24 14:53:50 +01004197 err = mv88e6xxx_mdios_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004198 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004199 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004200
Vivien Didelotfad09c72016-06-21 12:28:20 -04004201 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004202
Vivien Didelotfad09c72016-06-21 12:28:20 -04004203 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004204free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004205 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004206
4207 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004208}
4209
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004210static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4211 const struct switchdev_obj_port_mdb *mdb,
4212 struct switchdev_trans *trans)
4213{
4214 /* We don't need any dynamic resource from the kernel (yet),
4215 * so skip the prepare phase.
4216 */
4217
4218 return 0;
4219}
4220
4221static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4222 const struct switchdev_obj_port_mdb *mdb,
4223 struct switchdev_trans *trans)
4224{
Vivien Didelot04bed142016-08-31 18:06:13 -04004225 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004226
4227 mutex_lock(&chip->reg_lock);
4228 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4229 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4230 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4231 mutex_unlock(&chip->reg_lock);
4232}
4233
4234static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4235 const struct switchdev_obj_port_mdb *mdb)
4236{
Vivien Didelot04bed142016-08-31 18:06:13 -04004237 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004238 int err;
4239
4240 mutex_lock(&chip->reg_lock);
4241 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4242 GLOBAL_ATU_DATA_STATE_UNUSED);
4243 mutex_unlock(&chip->reg_lock);
4244
4245 return err;
4246}
4247
4248static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4249 struct switchdev_obj_port_mdb *mdb,
4250 int (*cb)(struct switchdev_obj *obj))
4251{
Vivien Didelot04bed142016-08-31 18:06:13 -04004252 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004253 int err;
4254
4255 mutex_lock(&chip->reg_lock);
4256 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4257 mutex_unlock(&chip->reg_lock);
4258
4259 return err;
4260}
4261
Florian Fainellia82f67a2017-01-08 14:52:08 -08004262static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004263 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004264 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004265 .setup = mv88e6xxx_setup,
4266 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004267 .adjust_link = mv88e6xxx_adjust_link,
4268 .get_strings = mv88e6xxx_get_strings,
4269 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4270 .get_sset_count = mv88e6xxx_get_sset_count,
4271 .set_eee = mv88e6xxx_set_eee,
4272 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004273 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004274 .get_eeprom = mv88e6xxx_get_eeprom,
4275 .set_eeprom = mv88e6xxx_set_eeprom,
4276 .get_regs_len = mv88e6xxx_get_regs_len,
4277 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004278 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004279 .port_bridge_join = mv88e6xxx_port_bridge_join,
4280 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4281 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004282 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004283 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4284 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4285 .port_vlan_add = mv88e6xxx_port_vlan_add,
4286 .port_vlan_del = mv88e6xxx_port_vlan_del,
4287 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4288 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4289 .port_fdb_add = mv88e6xxx_port_fdb_add,
4290 .port_fdb_del = mv88e6xxx_port_fdb_del,
4291 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004292 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4293 .port_mdb_add = mv88e6xxx_port_mdb_add,
4294 .port_mdb_del = mv88e6xxx_port_mdb_del,
4295 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004296};
4297
Florian Fainelliab3d4082017-01-08 14:52:07 -08004298static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4299 .ops = &mv88e6xxx_switch_ops,
4300};
4301
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004302static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004303{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004304 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004305 struct dsa_switch *ds;
4306
Vivien Didelot73b12042017-03-30 17:37:10 -04004307 ds = dsa_switch_alloc(dev, mv88e6xxx_num_ports(chip));
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004308 if (!ds)
4309 return -ENOMEM;
4310
Vivien Didelotfad09c72016-06-21 12:28:20 -04004311 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004312 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelot9ff74f22017-03-15 15:53:50 -04004313 ds->ageing_time_min = chip->info->age_time_coeff;
4314 ds->ageing_time_max = chip->info->age_time_coeff * U8_MAX;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004315
4316 dev_set_drvdata(dev, ds);
4317
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004318 return dsa_register_switch(ds, dev);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004319}
4320
Vivien Didelotfad09c72016-06-21 12:28:20 -04004321static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004322{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004323 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004324}
4325
Vivien Didelot57d32312016-06-20 13:13:58 -04004326static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004327{
4328 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004329 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004330 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004331 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004332 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004333 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004334
Vivien Didelotcaac8542016-06-20 13:14:09 -04004335 compat_info = of_device_get_match_data(dev);
4336 if (!compat_info)
4337 return -EINVAL;
4338
Vivien Didelotfad09c72016-06-21 12:28:20 -04004339 chip = mv88e6xxx_alloc_chip(dev);
4340 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004341 return -ENOMEM;
4342
Vivien Didelotfad09c72016-06-21 12:28:20 -04004343 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004344
Vivien Didelotfad09c72016-06-21 12:28:20 -04004345 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004346 if (err)
4347 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004348
Andrew Lunnb4308f02016-11-21 23:26:55 +01004349 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4350 if (IS_ERR(chip->reset))
4351 return PTR_ERR(chip->reset);
4352
Vivien Didelotfad09c72016-06-21 12:28:20 -04004353 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004354 if (err)
4355 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004356
Vivien Didelote57e5e72016-08-15 17:19:00 -04004357 mv88e6xxx_phy_init(chip);
4358
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004359 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004360 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004361 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004362
Andrew Lunndc30c352016-10-16 19:56:49 +02004363 mutex_lock(&chip->reg_lock);
4364 err = mv88e6xxx_switch_reset(chip);
4365 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004366 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004367 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004368
Andrew Lunndc30c352016-10-16 19:56:49 +02004369 chip->irq = of_irq_get(np, 0);
4370 if (chip->irq == -EPROBE_DEFER) {
4371 err = chip->irq;
4372 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004373 }
4374
Andrew Lunndc30c352016-10-16 19:56:49 +02004375 if (chip->irq > 0) {
4376 /* Has to be performed before the MDIO bus is created,
4377 * because the PHYs will link there interrupts to these
4378 * interrupt controllers
4379 */
4380 mutex_lock(&chip->reg_lock);
4381 err = mv88e6xxx_g1_irq_setup(chip);
4382 mutex_unlock(&chip->reg_lock);
4383
4384 if (err)
4385 goto out;
4386
4387 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4388 err = mv88e6xxx_g2_irq_setup(chip);
4389 if (err)
4390 goto out_g1_irq;
4391 }
4392 }
4393
Andrew Lunna3c53be52017-01-24 14:53:50 +01004394 err = mv88e6xxx_mdios_register(chip, np);
Andrew Lunndc30c352016-10-16 19:56:49 +02004395 if (err)
4396 goto out_g2_irq;
4397
Florian Fainelli55ed0ce2017-01-26 10:45:51 -08004398 err = mv88e6xxx_register_switch(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004399 if (err)
4400 goto out_mdio;
4401
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004402 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004403
4404out_mdio:
Andrew Lunna3c53be52017-01-24 14:53:50 +01004405 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004406out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004407 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004408 mv88e6xxx_g2_irq_free(chip);
4409out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004410 if (chip->irq > 0) {
4411 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004412 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004413 mutex_unlock(&chip->reg_lock);
4414 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004415out:
4416 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004417}
4418
4419static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4420{
4421 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004422 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004423
Andrew Lunn930188c2016-08-22 16:01:03 +02004424 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004425 mv88e6xxx_unregister_switch(chip);
Andrew Lunna3c53be52017-01-24 14:53:50 +01004426 mv88e6xxx_mdios_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004427
Andrew Lunn467126442016-11-20 20:14:15 +01004428 if (chip->irq > 0) {
4429 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4430 mv88e6xxx_g2_irq_free(chip);
4431 mv88e6xxx_g1_irq_free(chip);
4432 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004433}
4434
4435static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004436 {
4437 .compatible = "marvell,mv88e6085",
4438 .data = &mv88e6xxx_table[MV88E6085],
4439 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004440 {
4441 .compatible = "marvell,mv88e6190",
4442 .data = &mv88e6xxx_table[MV88E6190],
4443 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004444 { /* sentinel */ },
4445};
4446
4447MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4448
4449static struct mdio_driver mv88e6xxx_driver = {
4450 .probe = mv88e6xxx_probe,
4451 .remove = mv88e6xxx_remove,
4452 .mdiodrv.driver = {
4453 .name = "mv88e6085",
4454 .of_match_table = mv88e6xxx_of_match,
4455 },
4456};
4457
Ben Hutchings98e67302011-11-25 14:36:19 +00004458static int __init mv88e6xxx_init(void)
4459{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004460 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004461 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004462}
4463module_init(mv88e6xxx_init);
4464
4465static void __exit mv88e6xxx_cleanup(void)
4466{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004467 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004468 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004469}
4470module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004471
4472MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4473MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4474MODULE_LICENSE("GPL");