blob: 374d887e8256f8c67a02053daad537cea2faa7c2 [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04002 * Marvell 88e6xxx Ethernet switch single-chip support
3 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 * Copyright (c) 2008 Marvell Semiconductor
5 *
Vivien Didelotb8fee952015-08-13 12:52:19 -04006 * Copyright (c) 2015 CMC Electronics, Inc.
7 * Added support for VLAN Table Unit operations
8 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02009 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
10 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
Barry Grussling19b2f972013-01-08 16:05:54 +000017#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070018#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020019#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070020#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020021#include <linux/interrupt.h>
22#include <linux/irq.h>
23#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000024#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000025#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020026#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000027#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040028#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020029#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020030#include <linux/of_mdio.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000031#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010032#include <linux/gpio/consumer.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000033#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000034#include <net/dsa.h>
Vivien Didelot1f36faf2015-10-08 11:35:13 -040035#include <net/switchdev.h>
Vivien Didelotec561272016-09-02 14:45:33 -040036
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000037#include "mv88e6xxx.h"
Vivien Didelota935c052016-09-29 12:21:53 -040038#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040039#include "global2.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010040#include "port.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000041
Vivien Didelotfad09c72016-06-21 12:28:20 -040042static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040043{
Vivien Didelotfad09c72016-06-21 12:28:20 -040044 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
45 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040046 dump_stack();
47 }
48}
49
Vivien Didelot914b32f2016-06-20 13:14:11 -040050/* The switch ADDR[4:1] configuration pins define the chip SMI device address
51 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
52 *
53 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
54 * is the only device connected to the SMI master. In this mode it responds to
55 * all 32 possible SMI addresses, and thus maps directly the internal devices.
56 *
57 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
58 * multiple devices to share the SMI interface. In this mode it responds to only
59 * 2 registers, used to indirectly access the internal SMI devices.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000060 */
Vivien Didelot914b32f2016-06-20 13:14:11 -040061
Vivien Didelotfad09c72016-06-21 12:28:20 -040062static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040063 int addr, int reg, u16 *val)
64{
Vivien Didelotfad09c72016-06-21 12:28:20 -040065 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040066 return -EOPNOTSUPP;
67
Vivien Didelotfad09c72016-06-21 12:28:20 -040068 return chip->smi_ops->read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040069}
70
Vivien Didelotfad09c72016-06-21 12:28:20 -040071static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040072 int addr, int reg, u16 val)
73{
Vivien Didelotfad09c72016-06-21 12:28:20 -040074 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040075 return -EOPNOTSUPP;
76
Vivien Didelotfad09c72016-06-21 12:28:20 -040077 return chip->smi_ops->write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040078}
79
Vivien Didelotfad09c72016-06-21 12:28:20 -040080static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040081 int addr, int reg, u16 *val)
82{
83 int ret;
84
Vivien Didelotfad09c72016-06-21 12:28:20 -040085 ret = mdiobus_read_nested(chip->bus, addr, reg);
Vivien Didelot914b32f2016-06-20 13:14:11 -040086 if (ret < 0)
87 return ret;
88
89 *val = ret & 0xffff;
90
91 return 0;
92}
93
Vivien Didelotfad09c72016-06-21 12:28:20 -040094static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040095 int addr, int reg, u16 val)
96{
97 int ret;
98
Vivien Didelotfad09c72016-06-21 12:28:20 -040099 ret = mdiobus_write_nested(chip->bus, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400100 if (ret < 0)
101 return ret;
102
103 return 0;
104}
105
Vivien Didelotc08026a2016-09-29 12:21:59 -0400106static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400107 .read = mv88e6xxx_smi_single_chip_read,
108 .write = mv88e6xxx_smi_single_chip_write,
109};
110
Vivien Didelotfad09c72016-06-21 12:28:20 -0400111static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000112{
113 int ret;
114 int i;
115
116 for (i = 0; i < 16; i++) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400117 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000118 if (ret < 0)
119 return ret;
120
Andrew Lunncca8b132015-04-02 04:06:39 +0200121 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000122 return 0;
123 }
124
125 return -ETIMEDOUT;
126}
127
Vivien Didelotfad09c72016-06-21 12:28:20 -0400128static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400129 int addr, int reg, u16 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000130{
131 int ret;
132
Barry Grussling3675c8d2013-01-08 16:05:53 +0000133 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400134 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000135 if (ret < 0)
136 return ret;
137
Barry Grussling3675c8d2013-01-08 16:05:53 +0000138 /* Transmit the read command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400139 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Neil Armstrong6e899e62015-10-22 10:37:53 +0200140 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000141 if (ret < 0)
142 return ret;
143
Barry Grussling3675c8d2013-01-08 16:05:53 +0000144 /* Wait for the read command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400145 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000146 if (ret < 0)
147 return ret;
148
Barry Grussling3675c8d2013-01-08 16:05:53 +0000149 /* Read the data. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400150 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000151 if (ret < 0)
152 return ret;
153
Vivien Didelot914b32f2016-06-20 13:14:11 -0400154 *val = ret & 0xffff;
155
156 return 0;
157}
158
Vivien Didelotfad09c72016-06-21 12:28:20 -0400159static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400160 int addr, int reg, u16 val)
161{
162 int ret;
163
164 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400165 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400166 if (ret < 0)
167 return ret;
168
169 /* Transmit the data to write. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400170 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400171 if (ret < 0)
172 return ret;
173
174 /* Transmit the write command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400175 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400176 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
177 if (ret < 0)
178 return ret;
179
180 /* Wait for the write command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400181 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400182 if (ret < 0)
183 return ret;
184
185 return 0;
186}
187
Vivien Didelotc08026a2016-09-29 12:21:59 -0400188static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400189 .read = mv88e6xxx_smi_multi_chip_read,
190 .write = mv88e6xxx_smi_multi_chip_write,
191};
192
Vivien Didelotec561272016-09-02 14:45:33 -0400193int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400194{
195 int err;
196
Vivien Didelotfad09c72016-06-21 12:28:20 -0400197 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400198
Vivien Didelotfad09c72016-06-21 12:28:20 -0400199 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400200 if (err)
201 return err;
202
Vivien Didelotfad09c72016-06-21 12:28:20 -0400203 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400204 addr, reg, *val);
205
206 return 0;
207}
208
Vivien Didelotec561272016-09-02 14:45:33 -0400209int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400210{
211 int err;
212
Vivien Didelotfad09c72016-06-21 12:28:20 -0400213 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400214
Vivien Didelotfad09c72016-06-21 12:28:20 -0400215 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400216 if (err)
217 return err;
218
Vivien Didelotfad09c72016-06-21 12:28:20 -0400219 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400220 addr, reg, val);
221
222 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000223}
224
Andrew Lunnefb3e742017-01-24 14:53:47 +0100225static int mv88e6165_phy_read(struct mv88e6xxx_chip *chip, int addr,
226 int reg, u16 *val)
227{
228 return mv88e6xxx_read(chip, addr, reg, val);
229}
230
231static int mv88e6165_phy_write(struct mv88e6xxx_chip *chip, int addr,
232 int reg, u16 val)
233{
234 return mv88e6xxx_write(chip, addr, reg, val);
235}
236
Vivien Didelote57e5e72016-08-15 17:19:00 -0400237static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
238 int reg, u16 *val)
239{
240 int addr = phy; /* PHY devices addresses start at 0x0 */
241
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400242 if (!chip->info->ops->phy_read)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400243 return -EOPNOTSUPP;
244
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400245 return chip->info->ops->phy_read(chip, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400246}
247
248static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
249 int reg, u16 val)
250{
251 int addr = phy; /* PHY devices addresses start at 0x0 */
252
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400253 if (!chip->info->ops->phy_write)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400254 return -EOPNOTSUPP;
255
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400256 return chip->info->ops->phy_write(chip, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400257}
258
Vivien Didelot09cb7df2016-08-15 17:19:01 -0400259static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
260{
261 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_PHY_PAGE))
262 return -EOPNOTSUPP;
263
264 return mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
265}
266
267static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip *chip, int phy)
268{
269 int err;
270
271 /* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
272 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, PHY_PAGE_COPPER);
273 if (unlikely(err)) {
274 dev_err(chip->dev, "failed to restore PHY %d page Copper (%d)\n",
275 phy, err);
276 }
277}
278
279static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy,
280 u8 page, int reg, u16 *val)
281{
282 int err;
283
284 /* There is no paging for registers 22 */
285 if (reg == PHY_PAGE)
286 return -EINVAL;
287
288 err = mv88e6xxx_phy_page_get(chip, phy, page);
289 if (!err) {
290 err = mv88e6xxx_phy_read(chip, phy, reg, val);
291 mv88e6xxx_phy_page_put(chip, phy);
292 }
293
294 return err;
295}
296
297static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy,
298 u8 page, int reg, u16 val)
299{
300 int err;
301
302 /* There is no paging for registers 22 */
303 if (reg == PHY_PAGE)
304 return -EINVAL;
305
306 err = mv88e6xxx_phy_page_get(chip, phy, page);
307 if (!err) {
308 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
309 mv88e6xxx_phy_page_put(chip, phy);
310 }
311
312 return err;
313}
314
315static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
316{
317 return mv88e6xxx_phy_page_read(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
318 reg, val);
319}
320
321static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
322{
323 return mv88e6xxx_phy_page_write(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
324 reg, val);
325}
326
Andrew Lunndc30c352016-10-16 19:56:49 +0200327static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
328{
329 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
330 unsigned int n = d->hwirq;
331
332 chip->g1_irq.masked |= (1 << n);
333}
334
335static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
336{
337 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
338 unsigned int n = d->hwirq;
339
340 chip->g1_irq.masked &= ~(1 << n);
341}
342
343static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
344{
345 struct mv88e6xxx_chip *chip = dev_id;
346 unsigned int nhandled = 0;
347 unsigned int sub_irq;
348 unsigned int n;
349 u16 reg;
350 int err;
351
352 mutex_lock(&chip->reg_lock);
353 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
354 mutex_unlock(&chip->reg_lock);
355
356 if (err)
357 goto out;
358
359 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
360 if (reg & (1 << n)) {
361 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
362 handle_nested_irq(sub_irq);
363 ++nhandled;
364 }
365 }
366out:
367 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
368}
369
370static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
371{
372 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
373
374 mutex_lock(&chip->reg_lock);
375}
376
377static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
378{
379 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
380 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
381 u16 reg;
382 int err;
383
384 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
385 if (err)
386 goto out;
387
388 reg &= ~mask;
389 reg |= (~chip->g1_irq.masked & mask);
390
391 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
392 if (err)
393 goto out;
394
395out:
396 mutex_unlock(&chip->reg_lock);
397}
398
399static struct irq_chip mv88e6xxx_g1_irq_chip = {
400 .name = "mv88e6xxx-g1",
401 .irq_mask = mv88e6xxx_g1_irq_mask,
402 .irq_unmask = mv88e6xxx_g1_irq_unmask,
403 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
404 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
405};
406
407static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
408 unsigned int irq,
409 irq_hw_number_t hwirq)
410{
411 struct mv88e6xxx_chip *chip = d->host_data;
412
413 irq_set_chip_data(irq, d->host_data);
414 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
415 irq_set_noprobe(irq);
416
417 return 0;
418}
419
420static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
421 .map = mv88e6xxx_g1_irq_domain_map,
422 .xlate = irq_domain_xlate_twocell,
423};
424
425static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
426{
427 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100428 u16 mask;
429
430 mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
431 mask |= GENMASK(chip->g1_irq.nirqs, 0);
432 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
433
434 free_irq(chip->irq, chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200435
Andreas Färber5edef2f2016-11-27 23:26:28 +0100436 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100437 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200438 irq_dispose_mapping(virq);
439 }
440
Andrew Lunna3db3d32016-11-20 20:14:14 +0100441 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200442}
443
444static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
445{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100446 int err, irq, virq;
447 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200448
449 chip->g1_irq.nirqs = chip->info->g1_irqs;
450 chip->g1_irq.domain = irq_domain_add_simple(
451 NULL, chip->g1_irq.nirqs, 0,
452 &mv88e6xxx_g1_irq_domain_ops, chip);
453 if (!chip->g1_irq.domain)
454 return -ENOMEM;
455
456 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
457 irq_create_mapping(chip->g1_irq.domain, irq);
458
459 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
460 chip->g1_irq.masked = ~0;
461
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100462 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200463 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100464 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200465
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100466 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200467
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100468 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200469 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100470 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200471
472 /* Reading the interrupt status clears (most of) them */
473 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
474 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100475 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200476
477 err = request_threaded_irq(chip->irq, NULL,
478 mv88e6xxx_g1_irq_thread_fn,
479 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
480 dev_name(chip->dev), chip);
481 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100482 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200483
484 return 0;
485
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100486out_disable:
487 mask |= GENMASK(chip->g1_irq.nirqs, 0);
488 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
489
490out_mapping:
491 for (irq = 0; irq < 16; irq++) {
492 virq = irq_find_mapping(chip->g1_irq.domain, irq);
493 irq_dispose_mapping(virq);
494 }
495
496 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200497
498 return err;
499}
500
Vivien Didelotec561272016-09-02 14:45:33 -0400501int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400502{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200503 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400504
Andrew Lunn6441e6692016-08-19 00:01:55 +0200505 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400506 u16 val;
507 int err;
508
509 err = mv88e6xxx_read(chip, addr, reg, &val);
510 if (err)
511 return err;
512
513 if (!(val & mask))
514 return 0;
515
516 usleep_range(1000, 2000);
517 }
518
Andrew Lunn30853552016-08-19 00:01:57 +0200519 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400520 return -ETIMEDOUT;
521}
522
Vivien Didelotf22ab642016-07-18 20:45:31 -0400523/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400524int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400525{
526 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200527 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400528
529 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200530 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
531 if (err)
532 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400533
534 /* Set the Update bit to trigger a write operation */
535 val = BIT(15) | update;
536
537 return mv88e6xxx_write(chip, addr, reg, val);
538}
539
Vivien Didelota935c052016-09-29 12:21:53 -0400540static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000541{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500542 if (!chip->info->ops->ppu_disable)
543 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000544
Vivien Didelota199d8b2016-12-05 17:30:28 -0500545 return chip->info->ops->ppu_disable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000546}
547
Vivien Didelotfad09c72016-06-21 12:28:20 -0400548static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000549{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500550 if (!chip->info->ops->ppu_enable)
551 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000552
Vivien Didelota199d8b2016-12-05 17:30:28 -0500553 return chip->info->ops->ppu_enable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000554}
555
556static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
557{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400558 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000559
Vivien Didelotfad09c72016-06-21 12:28:20 -0400560 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200561
Vivien Didelotfad09c72016-06-21 12:28:20 -0400562 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200563
Vivien Didelotfad09c72016-06-21 12:28:20 -0400564 if (mutex_trylock(&chip->ppu_mutex)) {
565 if (mv88e6xxx_ppu_enable(chip) == 0)
566 chip->ppu_disabled = 0;
567 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000568 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200569
Vivien Didelotfad09c72016-06-21 12:28:20 -0400570 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000571}
572
573static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
574{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400575 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000576
Vivien Didelotfad09c72016-06-21 12:28:20 -0400577 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000578}
579
Vivien Didelotfad09c72016-06-21 12:28:20 -0400580static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000581{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000582 int ret;
583
Vivien Didelotfad09c72016-06-21 12:28:20 -0400584 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000585
Barry Grussling3675c8d2013-01-08 16:05:53 +0000586 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000587 * we can access the PHY registers. If it was already
588 * disabled, cancel the timer that is going to re-enable
589 * it.
590 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400591 if (!chip->ppu_disabled) {
592 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000593 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400594 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000595 return ret;
596 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400597 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000598 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400599 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000600 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000601 }
602
603 return ret;
604}
605
Vivien Didelotfad09c72016-06-21 12:28:20 -0400606static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000607{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000608 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400609 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
610 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000611}
612
Vivien Didelotfad09c72016-06-21 12:28:20 -0400613static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000614{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400615 mutex_init(&chip->ppu_mutex);
616 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000617 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
618 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000619}
620
Andrew Lunn930188c2016-08-22 16:01:03 +0200621static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
622{
623 del_timer_sync(&chip->ppu_timer);
624}
625
Vivien Didelote57e5e72016-08-15 17:19:00 -0400626static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip, int addr,
627 int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000628{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400629 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000630
Vivien Didelote57e5e72016-08-15 17:19:00 -0400631 err = mv88e6xxx_ppu_access_get(chip);
632 if (!err) {
633 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400634 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000635 }
636
Vivien Didelote57e5e72016-08-15 17:19:00 -0400637 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000638}
639
Vivien Didelote57e5e72016-08-15 17:19:00 -0400640static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip, int addr,
641 int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000642{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400643 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000644
Vivien Didelote57e5e72016-08-15 17:19:00 -0400645 err = mv88e6xxx_ppu_access_get(chip);
646 if (!err) {
647 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400648 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000649 }
650
Vivien Didelote57e5e72016-08-15 17:19:00 -0400651 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000652}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000653
Vivien Didelotfad09c72016-06-21 12:28:20 -0400654static bool mv88e6xxx_6095_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200655{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400656 return chip->info->family == MV88E6XXX_FAMILY_6095;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200657}
658
Vivien Didelotfad09c72016-06-21 12:28:20 -0400659static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200660{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400661 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200662}
663
Vivien Didelotfad09c72016-06-21 12:28:20 -0400664static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200665{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400666 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200667}
668
Vivien Didelotfad09c72016-06-21 12:28:20 -0400669static bool mv88e6xxx_6185_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200670{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400671 return chip->info->family == MV88E6XXX_FAMILY_6185;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200672}
673
Vivien Didelotfad09c72016-06-21 12:28:20 -0400674static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700675{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400676 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700677}
678
Vivien Didelotfad09c72016-06-21 12:28:20 -0400679static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200680{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400681 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200682}
683
Vivien Didelotfad09c72016-06-21 12:28:20 -0400684static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200685{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400686 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200687}
688
Vivien Didelotd78343d2016-11-04 03:23:36 +0100689static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
690 int link, int speed, int duplex,
691 phy_interface_t mode)
692{
693 int err;
694
695 if (!chip->info->ops->port_set_link)
696 return 0;
697
698 /* Port's MAC control must not be changed unless the link is down */
699 err = chip->info->ops->port_set_link(chip, port, 0);
700 if (err)
701 return err;
702
703 if (chip->info->ops->port_set_speed) {
704 err = chip->info->ops->port_set_speed(chip, port, speed);
705 if (err && err != -EOPNOTSUPP)
706 goto restore_link;
707 }
708
709 if (chip->info->ops->port_set_duplex) {
710 err = chip->info->ops->port_set_duplex(chip, port, duplex);
711 if (err && err != -EOPNOTSUPP)
712 goto restore_link;
713 }
714
715 if (chip->info->ops->port_set_rgmii_delay) {
716 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
717 if (err && err != -EOPNOTSUPP)
718 goto restore_link;
719 }
720
721 err = 0;
722restore_link:
723 if (chip->info->ops->port_set_link(chip, port, link))
724 netdev_err(chip->ds->ports[port].netdev,
725 "failed to restore MAC's link\n");
726
727 return err;
728}
729
Andrew Lunndea87022015-08-31 15:56:47 +0200730/* We expect the switch to perform auto negotiation if there is a real
731 * phy. However, in the case of a fixed link phy, we force the port
732 * settings from the fixed link settings.
733 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400734static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
735 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200736{
Vivien Didelot04bed142016-08-31 18:06:13 -0400737 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200738 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200739
740 if (!phy_is_pseudo_fixed_link(phydev))
741 return;
742
Vivien Didelotfad09c72016-06-21 12:28:20 -0400743 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100744 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
745 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400746 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100747
748 if (err && err != -EOPNOTSUPP)
749 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200750}
751
Andrew Lunna605a0f2016-11-21 23:26:58 +0100752static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000753{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100754 if (!chip->info->ops->stats_snapshot)
755 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000756
Andrew Lunna605a0f2016-11-21 23:26:58 +0100757 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000758}
759
Andrew Lunne413e7e2015-04-02 04:06:38 +0200760static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100761 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
762 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
763 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
764 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
765 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
766 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
767 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
768 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
769 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
770 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
771 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
772 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
773 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
774 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
775 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
776 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
777 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
778 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
779 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
780 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
781 { "single", 4, 0x14, STATS_TYPE_BANK0, },
782 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
783 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
784 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
785 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
786 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
787 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
788 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
789 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
790 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
791 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
792 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
793 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
794 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
795 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
796 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
797 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
798 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
799 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
800 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
801 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
802 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
803 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
804 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
805 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
806 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
807 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
808 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
809 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
810 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
811 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
812 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
813 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
814 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
815 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
816 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
817 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
818 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
819 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200820};
821
Vivien Didelotfad09c72016-06-21 12:28:20 -0400822static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100823 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100824 int port, u16 bank1_select,
825 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200826{
Andrew Lunn80c46272015-06-20 18:42:30 +0200827 u32 low;
828 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100829 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200830 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200831 u64 value;
832
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100833 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100834 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200835 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
836 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200837 return UINT64_MAX;
838
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200839 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200840 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200841 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
842 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200843 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200844 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200845 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100846 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100847 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100848 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100849 /* fall through */
850 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100851 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100852 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200853 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100854 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200855 }
856 value = (((u64)high) << 16) | low;
857 return value;
858}
859
Andrew Lunndfafe442016-11-21 23:27:02 +0100860static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
861 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100862{
863 struct mv88e6xxx_hw_stat *stat;
864 int i, j;
865
866 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
867 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100868 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100869 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
870 ETH_GSTRING_LEN);
871 j++;
872 }
873 }
874}
875
Andrew Lunndfafe442016-11-21 23:27:02 +0100876static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
877 uint8_t *data)
878{
879 mv88e6xxx_stats_get_strings(chip, data,
880 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
881}
882
883static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
884 uint8_t *data)
885{
886 mv88e6xxx_stats_get_strings(chip, data,
887 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
888}
889
890static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
891 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100892{
Vivien Didelot04bed142016-08-31 18:06:13 -0400893 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100894
895 if (chip->info->ops->stats_get_strings)
896 chip->info->ops->stats_get_strings(chip, data);
897}
898
899static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
900 int types)
901{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100902 struct mv88e6xxx_hw_stat *stat;
903 int i, j;
904
905 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
906 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100907 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100908 j++;
909 }
910 return j;
911}
912
Andrew Lunndfafe442016-11-21 23:27:02 +0100913static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
914{
915 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
916 STATS_TYPE_PORT);
917}
918
919static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
920{
921 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
922 STATS_TYPE_BANK1);
923}
924
925static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
926{
927 struct mv88e6xxx_chip *chip = ds->priv;
928
929 if (chip->info->ops->stats_get_sset_count)
930 return chip->info->ops->stats_get_sset_count(chip);
931
932 return 0;
933}
934
Andrew Lunn052f9472016-11-21 23:27:03 +0100935static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100936 uint64_t *data, int types,
937 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100938{
939 struct mv88e6xxx_hw_stat *stat;
940 int i, j;
941
942 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
943 stat = &mv88e6xxx_hw_stats[i];
944 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100945 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
946 bank1_select,
947 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100948 j++;
949 }
950 }
951}
952
953static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
954 uint64_t *data)
955{
956 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100957 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
958 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100959}
960
961static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
962 uint64_t *data)
963{
964 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100965 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
966 GLOBAL_STATS_OP_BANK_1_BIT_9,
967 GLOBAL_STATS_OP_HIST_RX_TX);
968}
969
970static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
971 uint64_t *data)
972{
973 return mv88e6xxx_stats_get_stats(chip, port, data,
974 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
975 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100976}
977
978static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
979 uint64_t *data)
980{
981 if (chip->info->ops->stats_get_stats)
982 chip->info->ops->stats_get_stats(chip, port, data);
983}
984
Vivien Didelotf81ec902016-05-09 13:22:58 -0400985static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
986 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000987{
Vivien Didelot04bed142016-08-31 18:06:13 -0400988 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000989 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000990
Vivien Didelotfad09c72016-06-21 12:28:20 -0400991 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000992
Andrew Lunna605a0f2016-11-21 23:26:58 +0100993 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000994 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400995 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000996 return;
997 }
Andrew Lunn052f9472016-11-21 23:27:03 +0100998
999 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001000
Vivien Didelotfad09c72016-06-21 12:28:20 -04001001 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001002}
Ben Hutchings98e67302011-11-25 14:36:19 +00001003
Andrew Lunnde2273872016-11-21 23:27:01 +01001004static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1005{
1006 if (chip->info->ops->stats_set_histogram)
1007 return chip->info->ops->stats_set_histogram(chip);
1008
1009 return 0;
1010}
1011
Vivien Didelotf81ec902016-05-09 13:22:58 -04001012static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001013{
1014 return 32 * sizeof(u16);
1015}
1016
Vivien Didelotf81ec902016-05-09 13:22:58 -04001017static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1018 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001019{
Vivien Didelot04bed142016-08-31 18:06:13 -04001020 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001021 int err;
1022 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001023 u16 *p = _p;
1024 int i;
1025
1026 regs->version = 0;
1027
1028 memset(p, 0xff, 32 * sizeof(u16));
1029
Vivien Didelotfad09c72016-06-21 12:28:20 -04001030 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001031
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001032 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001033
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001034 err = mv88e6xxx_port_read(chip, port, i, &reg);
1035 if (!err)
1036 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001037 }
Vivien Didelot23062512016-05-09 13:22:45 -04001038
Vivien Didelotfad09c72016-06-21 12:28:20 -04001039 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001040}
1041
Vivien Didelotfad09c72016-06-21 12:28:20 -04001042static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001043{
Vivien Didelota935c052016-09-29 12:21:53 -04001044 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001045}
1046
Vivien Didelotf81ec902016-05-09 13:22:58 -04001047static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1048 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001049{
Vivien Didelot04bed142016-08-31 18:06:13 -04001050 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001051 u16 reg;
1052 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001053
Vivien Didelotfad09c72016-06-21 12:28:20 -04001054 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001055 return -EOPNOTSUPP;
1056
Vivien Didelotfad09c72016-06-21 12:28:20 -04001057 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001058
Vivien Didelot9c938292016-08-15 17:19:02 -04001059 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1060 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001061 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001062
1063 e->eee_enabled = !!(reg & 0x0200);
1064 e->tx_lpi_enabled = !!(reg & 0x0100);
1065
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001066 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001067 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001068 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001069
Andrew Lunncca8b132015-04-02 04:06:39 +02001070 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001071out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001072 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001073
1074 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001075}
1076
Vivien Didelotf81ec902016-05-09 13:22:58 -04001077static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1078 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001079{
Vivien Didelot04bed142016-08-31 18:06:13 -04001080 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001081 u16 reg;
1082 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001083
Vivien Didelotfad09c72016-06-21 12:28:20 -04001084 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001085 return -EOPNOTSUPP;
1086
Vivien Didelotfad09c72016-06-21 12:28:20 -04001087 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001088
Vivien Didelot9c938292016-08-15 17:19:02 -04001089 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1090 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001091 goto out;
1092
Vivien Didelot9c938292016-08-15 17:19:02 -04001093 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001094 if (e->eee_enabled)
1095 reg |= 0x0200;
1096 if (e->tx_lpi_enabled)
1097 reg |= 0x0100;
1098
Vivien Didelot9c938292016-08-15 17:19:02 -04001099 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001100out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001101 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001102
Vivien Didelot9c938292016-08-15 17:19:02 -04001103 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001104}
1105
Vivien Didelotfad09c72016-06-21 12:28:20 -04001106static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001107{
Vivien Didelota935c052016-09-29 12:21:53 -04001108 u16 val;
1109 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001110
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001111 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001112 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1113 if (err)
1114 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001115 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001116 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001117 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1118 if (err)
1119 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001120
Vivien Didelota935c052016-09-29 12:21:53 -04001121 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1122 (val & 0xfff) | ((fid << 8) & 0xf000));
1123 if (err)
1124 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001125
1126 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1127 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001128 }
1129
Vivien Didelota935c052016-09-29 12:21:53 -04001130 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1131 if (err)
1132 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001133
Vivien Didelotfad09c72016-06-21 12:28:20 -04001134 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001135}
1136
Vivien Didelotfad09c72016-06-21 12:28:20 -04001137static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001138 struct mv88e6xxx_atu_entry *entry)
1139{
1140 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1141
1142 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1143 unsigned int mask, shift;
1144
1145 if (entry->trunk) {
1146 data |= GLOBAL_ATU_DATA_TRUNK;
1147 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1148 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1149 } else {
1150 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1151 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1152 }
1153
1154 data |= (entry->portv_trunkid << shift) & mask;
1155 }
1156
Vivien Didelota935c052016-09-29 12:21:53 -04001157 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001158}
1159
Vivien Didelotfad09c72016-06-21 12:28:20 -04001160static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001161 struct mv88e6xxx_atu_entry *entry,
1162 bool static_too)
1163{
1164 int op;
1165 int err;
1166
Vivien Didelotfad09c72016-06-21 12:28:20 -04001167 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001168 if (err)
1169 return err;
1170
Vivien Didelotfad09c72016-06-21 12:28:20 -04001171 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001172 if (err)
1173 return err;
1174
1175 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001176 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1177 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1178 } else {
1179 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1180 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1181 }
1182
Vivien Didelotfad09c72016-06-21 12:28:20 -04001183 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001184}
1185
Vivien Didelotfad09c72016-06-21 12:28:20 -04001186static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001187 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001188{
1189 struct mv88e6xxx_atu_entry entry = {
1190 .fid = fid,
1191 .state = 0, /* EntryState bits must be 0 */
1192 };
1193
Vivien Didelotfad09c72016-06-21 12:28:20 -04001194 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001195}
1196
Vivien Didelotfad09c72016-06-21 12:28:20 -04001197static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001198 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001199{
1200 struct mv88e6xxx_atu_entry entry = {
1201 .trunk = false,
1202 .fid = fid,
1203 };
1204
1205 /* EntryState bits must be 0xF */
1206 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1207
1208 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1209 entry.portv_trunkid = (to_port & 0x0f) << 4;
1210 entry.portv_trunkid |= from_port & 0x0f;
1211
Vivien Didelotfad09c72016-06-21 12:28:20 -04001212 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001213}
1214
Vivien Didelotfad09c72016-06-21 12:28:20 -04001215static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001216 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001217{
1218 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001219 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001220}
1221
Vivien Didelotfad09c72016-06-21 12:28:20 -04001222static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001223{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001224 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001225 struct dsa_switch *ds = chip->ds;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001226 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001227 int i;
1228
1229 /* allow CPU port or DSA link(s) to send frames to every port */
1230 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001231 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001232 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001233 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001234 /* allow sending frames to every group member */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001235 if (bridge && chip->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001236 output_ports |= BIT(i);
1237
1238 /* allow sending frames to CPU port and DSA link(s) */
1239 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1240 output_ports |= BIT(i);
1241 }
1242 }
1243
1244 /* prevent frames from going back out of the port they came in on */
1245 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001246
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001247 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001248}
1249
Vivien Didelotf81ec902016-05-09 13:22:58 -04001250static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1251 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001252{
Vivien Didelot04bed142016-08-31 18:06:13 -04001253 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001254 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001255 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001256
1257 switch (state) {
1258 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001259 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001260 break;
1261 case BR_STATE_BLOCKING:
1262 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001263 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001264 break;
1265 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001266 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001267 break;
1268 case BR_STATE_FORWARDING:
1269 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001270 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001271 break;
1272 }
1273
Vivien Didelotfad09c72016-06-21 12:28:20 -04001274 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001275 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001276 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001277
1278 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001279 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001280}
1281
Vivien Didelot749efcb2016-09-22 16:49:24 -04001282static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1283{
1284 struct mv88e6xxx_chip *chip = ds->priv;
1285 int err;
1286
1287 mutex_lock(&chip->reg_lock);
1288 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1289 mutex_unlock(&chip->reg_lock);
1290
1291 if (err)
1292 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1293}
1294
Vivien Didelotfad09c72016-06-21 12:28:20 -04001295static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001296{
Vivien Didelota935c052016-09-29 12:21:53 -04001297 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001298}
1299
Vivien Didelotfad09c72016-06-21 12:28:20 -04001300static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001301{
Vivien Didelota935c052016-09-29 12:21:53 -04001302 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001303
Vivien Didelota935c052016-09-29 12:21:53 -04001304 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1305 if (err)
1306 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001307
Vivien Didelotfad09c72016-06-21 12:28:20 -04001308 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001309}
1310
Vivien Didelotfad09c72016-06-21 12:28:20 -04001311static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001312{
1313 int ret;
1314
Vivien Didelotfad09c72016-06-21 12:28:20 -04001315 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001316 if (ret < 0)
1317 return ret;
1318
Vivien Didelotfad09c72016-06-21 12:28:20 -04001319 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001320}
1321
Vivien Didelotfad09c72016-06-21 12:28:20 -04001322static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001323 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001324 unsigned int nibble_offset)
1325{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001326 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001327 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001328
1329 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001330 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001331
Vivien Didelota935c052016-09-29 12:21:53 -04001332 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1333 if (err)
1334 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001335 }
1336
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001337 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001338 unsigned int shift = (i % 4) * 4 + nibble_offset;
1339 u16 reg = regs[i / 4];
1340
1341 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1342 }
1343
1344 return 0;
1345}
1346
Vivien Didelotfad09c72016-06-21 12:28:20 -04001347static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001348 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001349{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001350 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001351}
1352
Vivien Didelotfad09c72016-06-21 12:28:20 -04001353static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001354 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001355{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001356 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001357}
1358
Vivien Didelotfad09c72016-06-21 12:28:20 -04001359static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001360 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001361 unsigned int nibble_offset)
1362{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001363 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001364 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001365
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001366 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001367 unsigned int shift = (i % 4) * 4 + nibble_offset;
1368 u8 data = entry->data[i];
1369
1370 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1371 }
1372
1373 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001374 u16 reg = regs[i];
1375
1376 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1377 if (err)
1378 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001379 }
1380
1381 return 0;
1382}
1383
Vivien Didelotfad09c72016-06-21 12:28:20 -04001384static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001385 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001386{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001387 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001388}
1389
Vivien Didelotfad09c72016-06-21 12:28:20 -04001390static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001391 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001392{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001393 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001394}
1395
Vivien Didelotfad09c72016-06-21 12:28:20 -04001396static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001397{
Vivien Didelota935c052016-09-29 12:21:53 -04001398 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1399 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001400}
1401
Vivien Didelotfad09c72016-06-21 12:28:20 -04001402static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001403 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001404{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001405 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001406 u16 val;
1407 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001408
Vivien Didelota935c052016-09-29 12:21:53 -04001409 err = _mv88e6xxx_vtu_wait(chip);
1410 if (err)
1411 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001412
Vivien Didelota935c052016-09-29 12:21:53 -04001413 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1414 if (err)
1415 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001416
Vivien Didelota935c052016-09-29 12:21:53 -04001417 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1418 if (err)
1419 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001420
Vivien Didelota935c052016-09-29 12:21:53 -04001421 next.vid = val & GLOBAL_VTU_VID_MASK;
1422 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001423
1424 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001425 err = mv88e6xxx_vtu_data_read(chip, &next);
1426 if (err)
1427 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001428
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001429 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001430 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1431 if (err)
1432 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001433
Vivien Didelota935c052016-09-29 12:21:53 -04001434 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001435 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001436 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1437 * VTU DBNum[3:0] are located in VTU Operation 3:0
1438 */
Vivien Didelota935c052016-09-29 12:21:53 -04001439 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1440 if (err)
1441 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001442
Vivien Didelota935c052016-09-29 12:21:53 -04001443 next.fid = (val & 0xf00) >> 4;
1444 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001445 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001446
Vivien Didelotfad09c72016-06-21 12:28:20 -04001447 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001448 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1449 if (err)
1450 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001451
Vivien Didelota935c052016-09-29 12:21:53 -04001452 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001453 }
1454 }
1455
1456 *entry = next;
1457 return 0;
1458}
1459
Vivien Didelotf81ec902016-05-09 13:22:58 -04001460static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1461 struct switchdev_obj_port_vlan *vlan,
1462 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001463{
Vivien Didelot04bed142016-08-31 18:06:13 -04001464 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001465 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001466 u16 pvid;
1467 int err;
1468
Vivien Didelotfad09c72016-06-21 12:28:20 -04001469 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001470 return -EOPNOTSUPP;
1471
Vivien Didelotfad09c72016-06-21 12:28:20 -04001472 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001473
Vivien Didelot77064f32016-11-04 03:23:30 +01001474 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001475 if (err)
1476 goto unlock;
1477
Vivien Didelotfad09c72016-06-21 12:28:20 -04001478 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001479 if (err)
1480 goto unlock;
1481
1482 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001483 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001484 if (err)
1485 break;
1486
1487 if (!next.valid)
1488 break;
1489
1490 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1491 continue;
1492
1493 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001494 vlan->vid_begin = next.vid;
1495 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001496 vlan->flags = 0;
1497
1498 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1499 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1500
1501 if (next.vid == pvid)
1502 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1503
1504 err = cb(&vlan->obj);
1505 if (err)
1506 break;
1507 } while (next.vid < GLOBAL_VTU_VID_MASK);
1508
1509unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001510 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001511
1512 return err;
1513}
1514
Vivien Didelotfad09c72016-06-21 12:28:20 -04001515static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001516 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001517{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001518 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001519 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001520 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001521
Vivien Didelota935c052016-09-29 12:21:53 -04001522 err = _mv88e6xxx_vtu_wait(chip);
1523 if (err)
1524 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001525
1526 if (!entry->valid)
1527 goto loadpurge;
1528
1529 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001530 err = mv88e6xxx_vtu_data_write(chip, entry);
1531 if (err)
1532 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001533
Vivien Didelotfad09c72016-06-21 12:28:20 -04001534 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001535 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001536 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1537 if (err)
1538 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001539 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001540
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001541 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001542 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001543 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1544 if (err)
1545 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001546 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001547 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1548 * VTU DBNum[3:0] are located in VTU Operation 3:0
1549 */
1550 op |= (entry->fid & 0xf0) << 8;
1551 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001552 }
1553
1554 reg = GLOBAL_VTU_VID_VALID;
1555loadpurge:
1556 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001557 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1558 if (err)
1559 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001560
Vivien Didelotfad09c72016-06-21 12:28:20 -04001561 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001562}
1563
Vivien Didelotfad09c72016-06-21 12:28:20 -04001564static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001565 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001566{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001567 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001568 u16 val;
1569 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001570
Vivien Didelota935c052016-09-29 12:21:53 -04001571 err = _mv88e6xxx_vtu_wait(chip);
1572 if (err)
1573 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001574
Vivien Didelota935c052016-09-29 12:21:53 -04001575 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1576 sid & GLOBAL_VTU_SID_MASK);
1577 if (err)
1578 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001579
Vivien Didelota935c052016-09-29 12:21:53 -04001580 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1581 if (err)
1582 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001583
Vivien Didelota935c052016-09-29 12:21:53 -04001584 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1585 if (err)
1586 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001587
Vivien Didelota935c052016-09-29 12:21:53 -04001588 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001589
Vivien Didelota935c052016-09-29 12:21:53 -04001590 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1591 if (err)
1592 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001593
Vivien Didelota935c052016-09-29 12:21:53 -04001594 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001595
1596 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001597 err = mv88e6xxx_stu_data_read(chip, &next);
1598 if (err)
1599 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001600 }
1601
1602 *entry = next;
1603 return 0;
1604}
1605
Vivien Didelotfad09c72016-06-21 12:28:20 -04001606static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001607 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001608{
1609 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001610 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001611
Vivien Didelota935c052016-09-29 12:21:53 -04001612 err = _mv88e6xxx_vtu_wait(chip);
1613 if (err)
1614 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001615
1616 if (!entry->valid)
1617 goto loadpurge;
1618
1619 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001620 err = mv88e6xxx_stu_data_write(chip, entry);
1621 if (err)
1622 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001623
1624 reg = GLOBAL_VTU_VID_VALID;
1625loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001626 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1627 if (err)
1628 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001629
1630 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001631 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1632 if (err)
1633 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001634
Vivien Didelotfad09c72016-06-21 12:28:20 -04001635 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001636}
1637
Vivien Didelotfad09c72016-06-21 12:28:20 -04001638static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001639{
1640 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001641 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001642 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001643
1644 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1645
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001646 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001647 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001648 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001649 if (err)
1650 return err;
1651
1652 set_bit(*fid, fid_bitmap);
1653 }
1654
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001655 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001656 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001657 if (err)
1658 return err;
1659
1660 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001661 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001662 if (err)
1663 return err;
1664
1665 if (!vlan.valid)
1666 break;
1667
1668 set_bit(vlan.fid, fid_bitmap);
1669 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1670
1671 /* The reset value 0x000 is used to indicate that multiple address
1672 * databases are not needed. Return the next positive available.
1673 */
1674 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001675 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001676 return -ENOSPC;
1677
1678 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001679 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001680}
1681
Vivien Didelotfad09c72016-06-21 12:28:20 -04001682static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001683 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001684{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001685 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001686 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001687 .valid = true,
1688 .vid = vid,
1689 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001690 int i, err;
1691
Vivien Didelotfad09c72016-06-21 12:28:20 -04001692 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001693 if (err)
1694 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001695
Vivien Didelot3d131f02015-11-03 10:52:52 -05001696 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001697 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001698 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1699 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1700 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001701
Vivien Didelotfad09c72016-06-21 12:28:20 -04001702 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
1703 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001704 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001705
1706 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1707 * implemented, only one STU entry is needed to cover all VTU
1708 * entries. Thus, validate the SID 0.
1709 */
1710 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001711 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001712 if (err)
1713 return err;
1714
1715 if (vstp.sid != vlan.sid || !vstp.valid) {
1716 memset(&vstp, 0, sizeof(vstp));
1717 vstp.valid = true;
1718 vstp.sid = vlan.sid;
1719
Vivien Didelotfad09c72016-06-21 12:28:20 -04001720 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001721 if (err)
1722 return err;
1723 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001724 }
1725
1726 *entry = vlan;
1727 return 0;
1728}
1729
Vivien Didelotfad09c72016-06-21 12:28:20 -04001730static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001731 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001732{
1733 int err;
1734
1735 if (!vid)
1736 return -EINVAL;
1737
Vivien Didelotfad09c72016-06-21 12:28:20 -04001738 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001739 if (err)
1740 return err;
1741
Vivien Didelotfad09c72016-06-21 12:28:20 -04001742 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001743 if (err)
1744 return err;
1745
1746 if (entry->vid != vid || !entry->valid) {
1747 if (!creat)
1748 return -EOPNOTSUPP;
1749 /* -ENOENT would've been more appropriate, but switchdev expects
1750 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1751 */
1752
Vivien Didelotfad09c72016-06-21 12:28:20 -04001753 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001754 }
1755
1756 return err;
1757}
1758
Vivien Didelotda9c3592016-02-12 12:09:40 -05001759static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1760 u16 vid_begin, u16 vid_end)
1761{
Vivien Didelot04bed142016-08-31 18:06:13 -04001762 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001763 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001764 int i, err;
1765
1766 if (!vid_begin)
1767 return -EOPNOTSUPP;
1768
Vivien Didelotfad09c72016-06-21 12:28:20 -04001769 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001770
Vivien Didelotfad09c72016-06-21 12:28:20 -04001771 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001772 if (err)
1773 goto unlock;
1774
1775 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001776 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001777 if (err)
1778 goto unlock;
1779
1780 if (!vlan.valid)
1781 break;
1782
1783 if (vlan.vid > vid_end)
1784 break;
1785
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001786 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001787 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1788 continue;
1789
Andrew Lunn66e28092016-12-11 21:07:19 +01001790 if (!ds->ports[port].netdev)
1791 continue;
1792
Vivien Didelotda9c3592016-02-12 12:09:40 -05001793 if (vlan.data[i] ==
1794 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1795 continue;
1796
Vivien Didelotfad09c72016-06-21 12:28:20 -04001797 if (chip->ports[i].bridge_dev ==
1798 chip->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001799 break; /* same bridge, check next VLAN */
1800
Andrew Lunn66e28092016-12-11 21:07:19 +01001801 if (!chip->ports[i].bridge_dev)
1802 continue;
1803
Andrew Lunnc8b09802016-06-04 21:16:57 +02001804 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001805 "hardware VLAN %d already used by %s\n",
1806 vlan.vid,
Vivien Didelotfad09c72016-06-21 12:28:20 -04001807 netdev_name(chip->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001808 err = -EOPNOTSUPP;
1809 goto unlock;
1810 }
1811 } while (vlan.vid < vid_end);
1812
1813unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001814 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001815
1816 return err;
1817}
1818
Vivien Didelotf81ec902016-05-09 13:22:58 -04001819static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1820 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001821{
Vivien Didelot04bed142016-08-31 18:06:13 -04001822 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001823 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001824 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001825 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001826
Vivien Didelotfad09c72016-06-21 12:28:20 -04001827 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001828 return -EOPNOTSUPP;
1829
Vivien Didelotfad09c72016-06-21 12:28:20 -04001830 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001831 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001832 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001833
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001834 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001835}
1836
Vivien Didelot57d32312016-06-20 13:13:58 -04001837static int
1838mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1839 const struct switchdev_obj_port_vlan *vlan,
1840 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001841{
Vivien Didelot04bed142016-08-31 18:06:13 -04001842 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001843 int err;
1844
Vivien Didelotfad09c72016-06-21 12:28:20 -04001845 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001846 return -EOPNOTSUPP;
1847
Vivien Didelotda9c3592016-02-12 12:09:40 -05001848 /* If the requested port doesn't belong to the same bridge as the VLAN
1849 * members, do not support it (yet) and fallback to software VLAN.
1850 */
1851 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1852 vlan->vid_end);
1853 if (err)
1854 return err;
1855
Vivien Didelot76e398a2015-11-01 12:33:55 -05001856 /* We don't need any dynamic resource from the kernel (yet),
1857 * so skip the prepare phase.
1858 */
1859 return 0;
1860}
1861
Vivien Didelotfad09c72016-06-21 12:28:20 -04001862static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001863 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001864{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001865 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001866 int err;
1867
Vivien Didelotfad09c72016-06-21 12:28:20 -04001868 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001869 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001870 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001871
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001872 vlan.data[port] = untagged ?
1873 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1874 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1875
Vivien Didelotfad09c72016-06-21 12:28:20 -04001876 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001877}
1878
Vivien Didelotf81ec902016-05-09 13:22:58 -04001879static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1880 const struct switchdev_obj_port_vlan *vlan,
1881 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001882{
Vivien Didelot04bed142016-08-31 18:06:13 -04001883 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001884 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1885 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1886 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001887
Vivien Didelotfad09c72016-06-21 12:28:20 -04001888 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001889 return;
1890
Vivien Didelotfad09c72016-06-21 12:28:20 -04001891 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001892
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001893 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001894 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001895 netdev_err(ds->ports[port].netdev,
1896 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001897 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001898
Vivien Didelot77064f32016-11-04 03:23:30 +01001899 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001900 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001901 vlan->vid_end);
1902
Vivien Didelotfad09c72016-06-21 12:28:20 -04001903 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001904}
1905
Vivien Didelotfad09c72016-06-21 12:28:20 -04001906static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001907 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001908{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001909 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001910 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001911 int i, err;
1912
Vivien Didelotfad09c72016-06-21 12:28:20 -04001913 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001914 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001915 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001916
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001917 /* Tell switchdev if this VLAN is handled in software */
1918 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001919 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001920
1921 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1922
1923 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001924 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001925 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001926 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001927 continue;
1928
1929 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001930 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001931 break;
1932 }
1933 }
1934
Vivien Didelotfad09c72016-06-21 12:28:20 -04001935 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001936 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001937 return err;
1938
Vivien Didelotfad09c72016-06-21 12:28:20 -04001939 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001940}
1941
Vivien Didelotf81ec902016-05-09 13:22:58 -04001942static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1943 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001944{
Vivien Didelot04bed142016-08-31 18:06:13 -04001945 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001946 u16 pvid, vid;
1947 int err = 0;
1948
Vivien Didelotfad09c72016-06-21 12:28:20 -04001949 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001950 return -EOPNOTSUPP;
1951
Vivien Didelotfad09c72016-06-21 12:28:20 -04001952 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001953
Vivien Didelot77064f32016-11-04 03:23:30 +01001954 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001955 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001956 goto unlock;
1957
Vivien Didelot76e398a2015-11-01 12:33:55 -05001958 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001959 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001960 if (err)
1961 goto unlock;
1962
1963 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001964 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001965 if (err)
1966 goto unlock;
1967 }
1968 }
1969
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001970unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001971 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001972
1973 return err;
1974}
1975
Vivien Didelotfad09c72016-06-21 12:28:20 -04001976static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04001977 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001978{
Vivien Didelota935c052016-09-29 12:21:53 -04001979 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001980
1981 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04001982 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
1983 (addr[i * 2] << 8) | addr[i * 2 + 1]);
1984 if (err)
1985 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001986 }
1987
1988 return 0;
1989}
1990
Vivien Didelotfad09c72016-06-21 12:28:20 -04001991static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001992 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001993{
Vivien Didelota935c052016-09-29 12:21:53 -04001994 u16 val;
1995 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001996
1997 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04001998 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
1999 if (err)
2000 return err;
2001
2002 addr[i * 2] = val >> 8;
2003 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002004 }
2005
2006 return 0;
2007}
2008
Vivien Didelotfad09c72016-06-21 12:28:20 -04002009static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04002010 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002011{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002012 int ret;
2013
Vivien Didelotfad09c72016-06-21 12:28:20 -04002014 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002015 if (ret < 0)
2016 return ret;
2017
Vivien Didelotfad09c72016-06-21 12:28:20 -04002018 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002019 if (ret < 0)
2020 return ret;
2021
Vivien Didelotfad09c72016-06-21 12:28:20 -04002022 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002023 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002024 return ret;
2025
Vivien Didelotfad09c72016-06-21 12:28:20 -04002026 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002027}
David S. Millercdf09692015-08-11 12:00:37 -07002028
Vivien Didelot88472932016-09-19 19:56:11 -04002029static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2030 struct mv88e6xxx_atu_entry *entry);
2031
2032static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2033 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2034{
2035 struct mv88e6xxx_atu_entry next;
2036 int err;
2037
Andrew Lunn59527582017-01-04 19:56:24 +01002038 memcpy(next.mac, addr, ETH_ALEN);
2039 eth_addr_dec(next.mac);
Vivien Didelot88472932016-09-19 19:56:11 -04002040
2041 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2042 if (err)
2043 return err;
2044
2045 do {
2046 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2047 if (err)
2048 return err;
2049
2050 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2051 break;
2052
2053 if (ether_addr_equal(next.mac, addr)) {
2054 *entry = next;
2055 return 0;
2056 }
Andrew Lunn59527582017-01-04 19:56:24 +01002057 } while (ether_addr_greater(addr, next.mac));
Vivien Didelot88472932016-09-19 19:56:11 -04002058
2059 memset(entry, 0, sizeof(*entry));
2060 entry->fid = fid;
2061 ether_addr_copy(entry->mac, addr);
2062
2063 return 0;
2064}
2065
Vivien Didelot83dabd12016-08-31 11:50:04 -04002066static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2067 const unsigned char *addr, u16 vid,
2068 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002069{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002070 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002071 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002072 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002073
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002074 /* Null VLAN ID corresponds to the port private database */
2075 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002076 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002077 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002078 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002079 if (err)
2080 return err;
2081
Vivien Didelot88472932016-09-19 19:56:11 -04002082 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2083 if (err)
2084 return err;
2085
2086 /* Purge the ATU entry only if no port is using it anymore */
2087 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2088 entry.portv_trunkid &= ~BIT(port);
2089 if (!entry.portv_trunkid)
2090 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2091 } else {
2092 entry.portv_trunkid |= BIT(port);
2093 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002094 }
2095
Vivien Didelotfad09c72016-06-21 12:28:20 -04002096 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002097}
2098
Vivien Didelotf81ec902016-05-09 13:22:58 -04002099static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2100 const struct switchdev_obj_port_fdb *fdb,
2101 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002102{
2103 /* We don't need any dynamic resource from the kernel (yet),
2104 * so skip the prepare phase.
2105 */
2106 return 0;
2107}
2108
Vivien Didelotf81ec902016-05-09 13:22:58 -04002109static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2110 const struct switchdev_obj_port_fdb *fdb,
2111 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002112{
Vivien Didelot04bed142016-08-31 18:06:13 -04002113 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002114
Vivien Didelotfad09c72016-06-21 12:28:20 -04002115 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002116 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2117 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2118 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002119 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002120}
2121
Vivien Didelotf81ec902016-05-09 13:22:58 -04002122static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2123 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002124{
Vivien Didelot04bed142016-08-31 18:06:13 -04002125 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002126 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002127
Vivien Didelotfad09c72016-06-21 12:28:20 -04002128 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002129 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2130 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002131 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002132
Vivien Didelot83dabd12016-08-31 11:50:04 -04002133 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002134}
2135
Vivien Didelotfad09c72016-06-21 12:28:20 -04002136static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002137 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002138{
Vivien Didelot1d194042015-08-10 09:09:51 -04002139 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002140 u16 val;
2141 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002142
2143 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002144
Vivien Didelota935c052016-09-29 12:21:53 -04002145 err = _mv88e6xxx_atu_wait(chip);
2146 if (err)
2147 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002148
Vivien Didelota935c052016-09-29 12:21:53 -04002149 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2150 if (err)
2151 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002152
Vivien Didelota935c052016-09-29 12:21:53 -04002153 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2154 if (err)
2155 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002156
Vivien Didelota935c052016-09-29 12:21:53 -04002157 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2158 if (err)
2159 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002160
Vivien Didelota935c052016-09-29 12:21:53 -04002161 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002162 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2163 unsigned int mask, shift;
2164
Vivien Didelota935c052016-09-29 12:21:53 -04002165 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002166 next.trunk = true;
2167 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2168 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2169 } else {
2170 next.trunk = false;
2171 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2172 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2173 }
2174
Vivien Didelota935c052016-09-29 12:21:53 -04002175 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002176 }
2177
2178 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002179 return 0;
2180}
2181
Vivien Didelot83dabd12016-08-31 11:50:04 -04002182static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2183 u16 fid, u16 vid, int port,
2184 struct switchdev_obj *obj,
2185 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002186{
2187 struct mv88e6xxx_atu_entry addr = {
2188 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2189 };
2190 int err;
2191
Vivien Didelotfad09c72016-06-21 12:28:20 -04002192 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002193 if (err)
2194 return err;
2195
2196 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002197 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002198 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002199 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002200
2201 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2202 break;
2203
Vivien Didelot83dabd12016-08-31 11:50:04 -04002204 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2205 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002206
Vivien Didelot83dabd12016-08-31 11:50:04 -04002207 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2208 struct switchdev_obj_port_fdb *fdb;
2209
2210 if (!is_unicast_ether_addr(addr.mac))
2211 continue;
2212
2213 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002214 fdb->vid = vid;
2215 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002216 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2217 fdb->ndm_state = NUD_NOARP;
2218 else
2219 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002220 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2221 struct switchdev_obj_port_mdb *mdb;
2222
2223 if (!is_multicast_ether_addr(addr.mac))
2224 continue;
2225
2226 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2227 mdb->vid = vid;
2228 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002229 } else {
2230 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002231 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002232
2233 err = cb(obj);
2234 if (err)
2235 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002236 } while (!is_broadcast_ether_addr(addr.mac));
2237
2238 return err;
2239}
2240
Vivien Didelot83dabd12016-08-31 11:50:04 -04002241static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2242 struct switchdev_obj *obj,
2243 int (*cb)(struct switchdev_obj *obj))
2244{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002245 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002246 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2247 };
2248 u16 fid;
2249 int err;
2250
2251 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002252 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002253 if (err)
2254 return err;
2255
2256 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2257 if (err)
2258 return err;
2259
2260 /* Dump VLANs' Filtering Information Databases */
2261 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2262 if (err)
2263 return err;
2264
2265 do {
2266 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2267 if (err)
2268 return err;
2269
2270 if (!vlan.valid)
2271 break;
2272
2273 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2274 obj, cb);
2275 if (err)
2276 return err;
2277 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2278
2279 return err;
2280}
2281
Vivien Didelotf81ec902016-05-09 13:22:58 -04002282static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2283 struct switchdev_obj_port_fdb *fdb,
2284 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002285{
Vivien Didelot04bed142016-08-31 18:06:13 -04002286 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002287 int err;
2288
Vivien Didelotfad09c72016-06-21 12:28:20 -04002289 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002290 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002291 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002292
2293 return err;
2294}
2295
Vivien Didelotf81ec902016-05-09 13:22:58 -04002296static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
2297 struct net_device *bridge)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002298{
Vivien Didelot04bed142016-08-31 18:06:13 -04002299 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002300 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002301
Vivien Didelotfad09c72016-06-21 12:28:20 -04002302 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002303
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002304 /* Assign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002305 chip->ports[port].bridge_dev = bridge;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002306
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002307 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002308 if (chip->ports[i].bridge_dev == bridge) {
2309 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002310 if (err)
2311 break;
2312 }
2313 }
2314
Vivien Didelotfad09c72016-06-21 12:28:20 -04002315 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002316
Vivien Didelot466dfa02016-02-26 13:16:05 -05002317 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002318}
2319
Vivien Didelotf81ec902016-05-09 13:22:58 -04002320static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002321{
Vivien Didelot04bed142016-08-31 18:06:13 -04002322 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002323 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002324 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002325
Vivien Didelotfad09c72016-06-21 12:28:20 -04002326 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002327
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002328 /* Unassign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002329 chip->ports[port].bridge_dev = NULL;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002330
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002331 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002332 if (i == port || chip->ports[i].bridge_dev == bridge)
2333 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002334 netdev_warn(ds->ports[i].netdev,
2335 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002336
Vivien Didelotfad09c72016-06-21 12:28:20 -04002337 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002338}
2339
Vivien Didelot17e708b2016-12-05 17:30:27 -05002340static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2341{
2342 if (chip->info->ops->reset)
2343 return chip->info->ops->reset(chip);
2344
2345 return 0;
2346}
2347
Vivien Didelot309eca62016-12-05 17:30:26 -05002348static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2349{
2350 struct gpio_desc *gpiod = chip->reset;
2351
2352 /* If there is a GPIO connected to the reset pin, toggle it */
2353 if (gpiod) {
2354 gpiod_set_value_cansleep(gpiod, 1);
2355 usleep_range(10000, 20000);
2356 gpiod_set_value_cansleep(gpiod, 0);
2357 usleep_range(10000, 20000);
2358 }
2359}
2360
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002361static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2362{
2363 int i, err;
2364
2365 /* Set all ports to the Disabled state */
2366 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2367 err = mv88e6xxx_port_set_state(chip, i,
2368 PORT_CONTROL_STATE_DISABLED);
2369 if (err)
2370 return err;
2371 }
2372
2373 /* Wait for transmit queues to drain,
2374 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2375 */
2376 usleep_range(2000, 4000);
2377
2378 return 0;
2379}
2380
Vivien Didelotfad09c72016-06-21 12:28:20 -04002381static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002382{
Vivien Didelota935c052016-09-29 12:21:53 -04002383 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002384
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002385 err = mv88e6xxx_disable_ports(chip);
2386 if (err)
2387 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002388
Vivien Didelot309eca62016-12-05 17:30:26 -05002389 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002390
Vivien Didelot17e708b2016-12-05 17:30:27 -05002391 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002392}
2393
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002394static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002395{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002396 u16 val;
2397 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002398
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002399 /* Clear Power Down bit */
2400 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2401 if (err)
2402 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002403
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002404 if (val & BMCR_PDOWN) {
2405 val &= ~BMCR_PDOWN;
2406 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002407 }
2408
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002409 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002410}
2411
Andrew Lunn56995cb2016-12-03 04:35:19 +01002412static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2413 int upstream_port)
2414{
2415 int err;
2416
2417 err = chip->info->ops->port_set_frame_mode(
2418 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2419 if (err)
2420 return err;
2421
2422 return chip->info->ops->port_set_egress_unknowns(
2423 chip, port, port == upstream_port);
2424}
2425
2426static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2427{
2428 int err;
2429
2430 switch (chip->info->tag_protocol) {
2431 case DSA_TAG_PROTO_EDSA:
2432 err = chip->info->ops->port_set_frame_mode(
2433 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2434 if (err)
2435 return err;
2436
2437 err = mv88e6xxx_port_set_egress_mode(
2438 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2439 if (err)
2440 return err;
2441
2442 if (chip->info->ops->port_set_ether_type)
2443 err = chip->info->ops->port_set_ether_type(
2444 chip, port, ETH_P_EDSA);
2445 break;
2446
2447 case DSA_TAG_PROTO_DSA:
2448 err = chip->info->ops->port_set_frame_mode(
2449 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2450 if (err)
2451 return err;
2452
2453 err = mv88e6xxx_port_set_egress_mode(
2454 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2455 break;
2456 default:
2457 err = -EINVAL;
2458 }
2459
2460 if (err)
2461 return err;
2462
2463 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2464}
2465
2466static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2467{
2468 int err;
2469
2470 err = chip->info->ops->port_set_frame_mode(
2471 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2472 if (err)
2473 return err;
2474
2475 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2476}
2477
Vivien Didelotfad09c72016-06-21 12:28:20 -04002478static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002479{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002480 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002481 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002482 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002483
Vivien Didelotd78343d2016-11-04 03:23:36 +01002484 /* MAC Forcing register: don't force link, speed, duplex or flow control
2485 * state to any particular values on physical ports, but force the CPU
2486 * port and all DSA ports to their maximum bandwidth and full duplex.
2487 */
2488 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2489 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2490 SPEED_MAX, DUPLEX_FULL,
2491 PHY_INTERFACE_MODE_NA);
2492 else
2493 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2494 SPEED_UNFORCED, DUPLEX_UNFORCED,
2495 PHY_INTERFACE_MODE_NA);
2496 if (err)
2497 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002498
2499 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2500 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2501 * tunneling, determine priority by looking at 802.1p and IP
2502 * priority fields (IP prio has precedence), and set STP state
2503 * to Forwarding.
2504 *
2505 * If this is the CPU link, use DSA or EDSA tagging depending
2506 * on which tagging mode was configured.
2507 *
2508 * If this is a link to another switch, use DSA tagging mode.
2509 *
2510 * If this is the upstream port for this switch, enable
2511 * forwarding of unknown unicasts and multicasts.
2512 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002513 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002514 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2515 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002516 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2517 if (err)
2518 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002519
Andrew Lunn56995cb2016-12-03 04:35:19 +01002520 if (dsa_is_cpu_port(ds, port)) {
2521 err = mv88e6xxx_setup_port_cpu(chip, port);
2522 } else if (dsa_is_dsa_port(ds, port)) {
2523 err = mv88e6xxx_setup_port_dsa(chip, port,
2524 dsa_upstream_port(ds));
2525 } else {
2526 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002527 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002528 if (err)
2529 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002530
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002531 /* If this port is connected to a SerDes, make sure the SerDes is not
2532 * powered down.
2533 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002534 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002535 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2536 if (err)
2537 return err;
2538 reg &= PORT_STATUS_CMODE_MASK;
2539 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2540 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2541 (reg == PORT_STATUS_CMODE_SGMII)) {
2542 err = mv88e6xxx_serdes_power_on(chip);
2543 if (err < 0)
2544 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002545 }
2546 }
2547
Vivien Didelot8efdda42015-08-13 12:52:23 -04002548 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002549 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002550 * untagged frames on this port, do a destination address lookup on all
2551 * received packets as usual, disable ARP mirroring and don't send a
2552 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002553 */
2554 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002555 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2556 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2557 mv88e6xxx_6095_family(chip) || mv88e6xxx_6320_family(chip) ||
2558 mv88e6xxx_6185_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002559 reg = PORT_CONTROL_2_MAP_DA;
2560
Vivien Didelotfad09c72016-06-21 12:28:20 -04002561 if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002562 /* Set the upstream port this port should use */
2563 reg |= dsa_upstream_port(ds);
2564 /* enable forwarding of unknown multicast addresses to
2565 * the upstream port
2566 */
2567 if (port == dsa_upstream_port(ds))
2568 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
2569 }
2570
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002571 reg |= PORT_CONTROL_2_8021Q_DISABLED;
Vivien Didelot8efdda42015-08-13 12:52:23 -04002572
Andrew Lunn54d792f2015-05-06 01:09:47 +02002573 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002574 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
2575 if (err)
2576 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002577 }
2578
Andrew Lunn5f436662016-12-03 04:45:17 +01002579 if (chip->info->ops->port_jumbo_config) {
2580 err = chip->info->ops->port_jumbo_config(chip, port);
2581 if (err)
2582 return err;
2583 }
2584
Andrew Lunn54d792f2015-05-06 01:09:47 +02002585 /* Port Association Vector: when learning source addresses
2586 * of packets, add the address to the address database using
2587 * a port bitmap that has only the bit for this port set and
2588 * the other bits clear.
2589 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002590 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002591 /* Disable learning for CPU port */
2592 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002593 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002594
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002595 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2596 if (err)
2597 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002598
2599 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002600 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2601 if (err)
2602 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002603
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002604 if (chip->info->ops->port_pause_config) {
2605 err = chip->info->ops->port_pause_config(chip, port);
2606 if (err)
2607 return err;
2608 }
2609
Vivien Didelotfad09c72016-06-21 12:28:20 -04002610 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2611 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2612 mv88e6xxx_6320_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002613 /* Port ATU control: disable limiting the number of
2614 * address database entries that this port is allowed
2615 * to use.
2616 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002617 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2618 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002619 /* Priority Override: disable DA, SA and VTU priority
2620 * override.
2621 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002622 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2623 0x0000);
2624 if (err)
2625 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002626 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002627
Andrew Lunnef0a7312016-12-03 04:35:16 +01002628 if (chip->info->ops->port_tag_remap) {
2629 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002630 if (err)
2631 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002632 }
2633
Andrew Lunnef70b112016-12-03 04:45:18 +01002634 if (chip->info->ops->port_egress_rate_limiting) {
2635 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002636 if (err)
2637 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002638 }
2639
Guenter Roeck366f0a02015-03-26 18:36:30 -07002640 /* Port Control 1: disable trunking, disable sending
2641 * learning messages to this port.
Guenter Roeckd827e882015-03-26 18:36:29 -07002642 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002643 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_1, 0x0000);
2644 if (err)
2645 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002646
Vivien Didelot207afda2016-04-14 14:42:09 -04002647 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002648 * database, and allow bidirectional communication between the
2649 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002650 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002651 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002652 if (err)
2653 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002654
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002655 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2656 if (err)
2657 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002658
2659 /* Default VLAN ID and priority: don't set a default VLAN
2660 * ID, and set the default packet priority to zero.
2661 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002662 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002663}
2664
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002665static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002666{
2667 int err;
2668
Vivien Didelota935c052016-09-29 12:21:53 -04002669 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002670 if (err)
2671 return err;
2672
Vivien Didelota935c052016-09-29 12:21:53 -04002673 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002674 if (err)
2675 return err;
2676
Vivien Didelota935c052016-09-29 12:21:53 -04002677 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2678 if (err)
2679 return err;
2680
2681 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002682}
2683
Vivien Didelotacddbd22016-07-18 20:45:39 -04002684static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
2685 unsigned int msecs)
2686{
2687 const unsigned int coeff = chip->info->age_time_coeff;
2688 const unsigned int min = 0x01 * coeff;
2689 const unsigned int max = 0xff * coeff;
2690 u8 age_time;
2691 u16 val;
2692 int err;
2693
2694 if (msecs < min || msecs > max)
2695 return -ERANGE;
2696
2697 /* Round to nearest multiple of coeff */
2698 age_time = (msecs + coeff / 2) / coeff;
2699
Vivien Didelota935c052016-09-29 12:21:53 -04002700 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002701 if (err)
2702 return err;
2703
2704 /* AgeTime is 11:4 bits */
2705 val &= ~0xff0;
2706 val |= age_time << 4;
2707
Vivien Didelota935c052016-09-29 12:21:53 -04002708 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002709}
2710
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002711static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2712 unsigned int ageing_time)
2713{
Vivien Didelot04bed142016-08-31 18:06:13 -04002714 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002715 int err;
2716
2717 mutex_lock(&chip->reg_lock);
2718 err = mv88e6xxx_g1_set_age_time(chip, ageing_time);
2719 mutex_unlock(&chip->reg_lock);
2720
2721 return err;
2722}
2723
Vivien Didelot97299342016-07-18 20:45:30 -04002724static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002725{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002726 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002727 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002728 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002729
Vivien Didelot119477b2016-05-09 13:22:51 -04002730 /* Enable the PHY Polling Unit if present, don't discard any packets,
2731 * and mask all interrupt sources.
2732 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002733 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002734 if (err)
2735 return err;
2736
Andrew Lunn33641992016-12-03 04:35:17 +01002737 if (chip->info->ops->g1_set_cpu_port) {
2738 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2739 if (err)
2740 return err;
2741 }
2742
2743 if (chip->info->ops->g1_set_egress_port) {
2744 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2745 if (err)
2746 return err;
2747 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002748
Vivien Didelot50484ff2016-05-09 13:22:54 -04002749 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002750 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2751 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2752 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002753 if (err)
2754 return err;
2755
Vivien Didelotacddbd22016-07-18 20:45:39 -04002756 /* Clear all the VTU and STU entries */
2757 err = _mv88e6xxx_vtu_stu_flush(chip);
2758 if (err < 0)
2759 return err;
2760
Vivien Didelot08a01262016-05-09 13:22:50 -04002761 /* Set the default address aging time to 5 minutes, and
2762 * enable address learn messages to be sent to all message
2763 * ports.
2764 */
Vivien Didelota935c052016-09-29 12:21:53 -04002765 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2766 GLOBAL_ATU_CONTROL_LEARN2ALL);
Vivien Didelot08a01262016-05-09 13:22:50 -04002767 if (err)
2768 return err;
2769
Vivien Didelotacddbd22016-07-18 20:45:39 -04002770 err = mv88e6xxx_g1_set_age_time(chip, 300000);
2771 if (err)
Vivien Didelot97299342016-07-18 20:45:30 -04002772 return err;
2773
2774 /* Clear all ATU entries */
2775 err = _mv88e6xxx_atu_flush(chip, 0, true);
2776 if (err)
2777 return err;
2778
Vivien Didelot08a01262016-05-09 13:22:50 -04002779 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002780 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002781 if (err)
2782 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002783 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002784 if (err)
2785 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002786 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002787 if (err)
2788 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002789 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002790 if (err)
2791 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002792 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002793 if (err)
2794 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002795 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002796 if (err)
2797 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002798 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002799 if (err)
2800 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002801 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002802 if (err)
2803 return err;
2804
2805 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002806 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002807 if (err)
2808 return err;
2809
Andrew Lunnde2273872016-11-21 23:27:01 +01002810 /* Initialize the statistics unit */
2811 err = mv88e6xxx_stats_set_histogram(chip);
2812 if (err)
2813 return err;
2814
Vivien Didelot97299342016-07-18 20:45:30 -04002815 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002816 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2817 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002818 if (err)
2819 return err;
2820
2821 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002822 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002823 if (err)
2824 return err;
2825
2826 return 0;
2827}
2828
Vivien Didelotf81ec902016-05-09 13:22:58 -04002829static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002830{
Vivien Didelot04bed142016-08-31 18:06:13 -04002831 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002832 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002833 int i;
2834
Vivien Didelotfad09c72016-06-21 12:28:20 -04002835 chip->ds = ds;
2836 ds->slave_mii_bus = chip->mdio_bus;
Vivien Didelot552238b2016-05-09 13:22:49 -04002837
Vivien Didelotfad09c72016-06-21 12:28:20 -04002838 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002839
Vivien Didelot97299342016-07-18 20:45:30 -04002840 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002841 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002842 err = mv88e6xxx_setup_port(chip, i);
2843 if (err)
2844 goto unlock;
2845 }
2846
2847 /* Setup Switch Global 1 Registers */
2848 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002849 if (err)
2850 goto unlock;
2851
Vivien Didelot97299342016-07-18 20:45:30 -04002852 /* Setup Switch Global 2 Registers */
2853 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2854 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002855 if (err)
2856 goto unlock;
2857 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002858
Andrew Lunn6e55f692016-12-03 04:45:16 +01002859 /* Some generations have the configuration of sending reserved
2860 * management frames to the CPU in global2, others in
2861 * global1. Hence it does not fit the two setup functions
2862 * above.
2863 */
2864 if (chip->info->ops->mgmt_rsvd2cpu) {
2865 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2866 if (err)
2867 goto unlock;
2868 }
2869
Vivien Didelot6b17e862015-08-13 12:52:18 -04002870unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002871 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002872
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002873 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002874}
2875
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002876static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2877{
Vivien Didelot04bed142016-08-31 18:06:13 -04002878 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002879 int err;
2880
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002881 if (!chip->info->ops->set_switch_mac)
2882 return -EOPNOTSUPP;
2883
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002884 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002885 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002886 mutex_unlock(&chip->reg_lock);
2887
2888 return err;
2889}
2890
Vivien Didelote57e5e72016-08-15 17:19:00 -04002891static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002892{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002893 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002894 u16 val;
2895 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002896
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002897 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002898 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002899
Vivien Didelotfad09c72016-06-21 12:28:20 -04002900 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002901 err = mv88e6xxx_phy_read(chip, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002902 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002903
2904 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002905}
2906
Vivien Didelote57e5e72016-08-15 17:19:00 -04002907static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002908{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002909 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002910 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002911
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002912 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002913 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002914
Vivien Didelotfad09c72016-06-21 12:28:20 -04002915 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002916 err = mv88e6xxx_phy_write(chip, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002917 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002918
2919 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002920}
2921
Vivien Didelotfad09c72016-06-21 12:28:20 -04002922static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunnb516d452016-06-04 21:17:06 +02002923 struct device_node *np)
2924{
2925 static int index;
2926 struct mii_bus *bus;
2927 int err;
2928
Andrew Lunnb516d452016-06-04 21:17:06 +02002929 if (np)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002930 chip->mdio_np = of_get_child_by_name(np, "mdio");
Andrew Lunnb516d452016-06-04 21:17:06 +02002931
Vivien Didelotfad09c72016-06-21 12:28:20 -04002932 bus = devm_mdiobus_alloc(chip->dev);
Andrew Lunnb516d452016-06-04 21:17:06 +02002933 if (!bus)
2934 return -ENOMEM;
2935
Vivien Didelotfad09c72016-06-21 12:28:20 -04002936 bus->priv = (void *)chip;
Andrew Lunnb516d452016-06-04 21:17:06 +02002937 if (np) {
2938 bus->name = np->full_name;
2939 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2940 } else {
2941 bus->name = "mv88e6xxx SMI";
2942 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2943 }
2944
2945 bus->read = mv88e6xxx_mdio_read;
2946 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002947 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002948
Vivien Didelotfad09c72016-06-21 12:28:20 -04002949 if (chip->mdio_np)
2950 err = of_mdiobus_register(bus, chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002951 else
2952 err = mdiobus_register(bus);
2953 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002954 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunnb516d452016-06-04 21:17:06 +02002955 goto out;
2956 }
Vivien Didelotfad09c72016-06-21 12:28:20 -04002957 chip->mdio_bus = bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002958
2959 return 0;
2960
2961out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002962 if (chip->mdio_np)
2963 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002964
2965 return err;
2966}
2967
Vivien Didelotfad09c72016-06-21 12:28:20 -04002968static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002969
2970{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002971 struct mii_bus *bus = chip->mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002972
2973 mdiobus_unregister(bus);
2974
Vivien Didelotfad09c72016-06-21 12:28:20 -04002975 if (chip->mdio_np)
2976 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002977}
2978
Vivien Didelot855b1932016-07-20 18:18:35 -04002979static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
2980{
Vivien Didelot04bed142016-08-31 18:06:13 -04002981 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002982
2983 return chip->eeprom_len;
2984}
2985
Vivien Didelot855b1932016-07-20 18:18:35 -04002986static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
2987 struct ethtool_eeprom *eeprom, u8 *data)
2988{
Vivien Didelot04bed142016-08-31 18:06:13 -04002989 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04002990 int err;
2991
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002992 if (!chip->info->ops->get_eeprom)
2993 return -EOPNOTSUPP;
2994
Vivien Didelot855b1932016-07-20 18:18:35 -04002995 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04002996 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04002997 mutex_unlock(&chip->reg_lock);
2998
2999 if (err)
3000 return err;
3001
3002 eeprom->magic = 0xc3ec4951;
3003
3004 return 0;
3005}
3006
Vivien Didelot855b1932016-07-20 18:18:35 -04003007static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3008 struct ethtool_eeprom *eeprom, u8 *data)
3009{
Vivien Didelot04bed142016-08-31 18:06:13 -04003010 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003011 int err;
3012
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003013 if (!chip->info->ops->set_eeprom)
3014 return -EOPNOTSUPP;
3015
Vivien Didelot855b1932016-07-20 18:18:35 -04003016 if (eeprom->magic != 0xc3ec4951)
3017 return -EINVAL;
3018
3019 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003020 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003021 mutex_unlock(&chip->reg_lock);
3022
3023 return err;
3024}
3025
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003026static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003027 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003028 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003029 .phy_read = mv88e6xxx_phy_ppu_read,
3030 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003031 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003032 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003033 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003034 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003035 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3036 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3037 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003038 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003039 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003040 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003041 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3042 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003043 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003044 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3045 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003046 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003047 .ppu_enable = mv88e6185_g1_ppu_enable,
3048 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003049 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003050};
3051
3052static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003053 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003054 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003055 .phy_read = mv88e6xxx_phy_ppu_read,
3056 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003057 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003058 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003059 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003060 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3061 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003062 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003063 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3064 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003065 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003066 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003067 .ppu_enable = mv88e6185_g1_ppu_enable,
3068 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003069 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003070};
3071
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003072static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003073 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003074 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3075 .phy_read = mv88e6xxx_g2_smi_phy_read,
3076 .phy_write = mv88e6xxx_g2_smi_phy_write,
3077 .port_set_link = mv88e6xxx_port_set_link,
3078 .port_set_duplex = mv88e6xxx_port_set_duplex,
3079 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003080 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003081 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3082 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3083 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003084 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003085 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003086 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003087 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3088 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3089 .stats_get_strings = mv88e6095_stats_get_strings,
3090 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003091 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3092 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003093 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003094 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003095};
3096
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003097static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003098 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003099 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003100 .phy_read = mv88e6165_phy_read,
3101 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003102 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003103 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003104 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003105 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3106 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003107 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003108 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3109 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003110 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003111 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3112 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003113 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003114 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003115};
3116
3117static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003118 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003119 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003120 .phy_read = mv88e6xxx_phy_ppu_read,
3121 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003122 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003123 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003124 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003125 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003126 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3127 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3128 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003129 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003130 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003131 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003132 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003133 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3134 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003135 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003136 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3137 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003138 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003139 .ppu_enable = mv88e6185_g1_ppu_enable,
3140 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003141 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003142};
3143
3144static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003145 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003146 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003147 .phy_read = mv88e6165_phy_read,
3148 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003149 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003150 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003151 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003152 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003153 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3154 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3155 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003156 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003157 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003158 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003159 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003160 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3161 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003162 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003163 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3164 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003165 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003166 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003167};
3168
3169static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003170 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003171 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Andrew Lunnefb3e742017-01-24 14:53:47 +01003172 .phy_read = mv88e6165_phy_read,
3173 .phy_write = mv88e6165_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003174 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003175 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003176 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003177 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003178 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3179 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003180 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003181 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3182 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003183 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003184 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003185};
3186
3187static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003188 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003189 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003190 .phy_read = mv88e6xxx_g2_smi_phy_read,
3191 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003192 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003193 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003194 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003195 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003196 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003197 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3198 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3199 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003200 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003201 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003202 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003203 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003204 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3205 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003206 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003207 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3208 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003209 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003210 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003211};
3212
3213static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003214 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003215 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3216 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003217 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003218 .phy_read = mv88e6xxx_g2_smi_phy_read,
3219 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003220 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003221 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003222 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003223 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003224 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003225 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3226 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3227 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003228 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003229 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003230 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003231 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003232 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3233 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003234 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003235 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3236 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003237 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003238 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003239};
3240
3241static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003242 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003243 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003244 .phy_read = mv88e6xxx_g2_smi_phy_read,
3245 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003246 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003247 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003248 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003249 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003250 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003251 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3252 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3253 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003254 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003255 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003256 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003257 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003258 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3259 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003260 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003261 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3262 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003263 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003264 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003265};
3266
3267static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003268 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003269 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3270 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003271 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003272 .phy_read = mv88e6xxx_g2_smi_phy_read,
3273 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003274 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003275 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003276 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003277 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003278 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003279 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3280 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3281 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003282 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003283 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003284 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003285 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003286 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3287 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003288 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003289 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3290 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003291 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003292 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003293};
3294
3295static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003296 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003297 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003298 .phy_read = mv88e6xxx_phy_ppu_read,
3299 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003300 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003301 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003302 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003303 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3304 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003305 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003306 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003307 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3308 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003309 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003310 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3311 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003312 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003313 .ppu_enable = mv88e6185_g1_ppu_enable,
3314 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003315 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003316};
3317
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003318static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003319 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003320 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3321 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003322 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3323 .phy_read = mv88e6xxx_g2_smi_phy_read,
3324 .phy_write = mv88e6xxx_g2_smi_phy_write,
3325 .port_set_link = mv88e6xxx_port_set_link,
3326 .port_set_duplex = mv88e6xxx_port_set_duplex,
3327 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3328 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003329 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003330 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3331 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3332 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003333 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003334 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003335 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003336 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3337 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003338 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003339 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3340 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003341 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003342 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003343};
3344
3345static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003346 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003347 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3348 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003349 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3350 .phy_read = mv88e6xxx_g2_smi_phy_read,
3351 .phy_write = mv88e6xxx_g2_smi_phy_write,
3352 .port_set_link = mv88e6xxx_port_set_link,
3353 .port_set_duplex = mv88e6xxx_port_set_duplex,
3354 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3355 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003356 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003357 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3358 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3359 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003360 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003361 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003362 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003363 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3364 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003365 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003366 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3367 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003368 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003369 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003370};
3371
3372static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003373 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003374 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3375 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003376 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3377 .phy_read = mv88e6xxx_g2_smi_phy_read,
3378 .phy_write = mv88e6xxx_g2_smi_phy_write,
3379 .port_set_link = mv88e6xxx_port_set_link,
3380 .port_set_duplex = mv88e6xxx_port_set_duplex,
3381 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3382 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003383 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003384 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3385 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3386 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003387 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003388 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003389 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003390 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3391 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003392 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003393 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3394 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003395 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003396 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003397};
3398
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003399static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003400 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003401 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3402 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003403 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003404 .phy_read = mv88e6xxx_g2_smi_phy_read,
3405 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003406 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003407 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003408 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003409 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003410 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003411 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3412 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3413 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003414 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003415 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003416 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003417 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003418 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3419 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003420 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003421 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3422 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003423 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003424 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003425};
3426
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003427static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003428 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003429 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3430 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003431 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3432 .phy_read = mv88e6xxx_g2_smi_phy_read,
3433 .phy_write = mv88e6xxx_g2_smi_phy_write,
3434 .port_set_link = mv88e6xxx_port_set_link,
3435 .port_set_duplex = mv88e6xxx_port_set_duplex,
3436 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3437 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003438 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003439 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3440 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3441 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003442 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003443 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003444 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003445 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3446 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003447 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003448 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3449 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003450 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003451 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003452};
3453
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003454static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003455 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003456 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3457 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003458 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003459 .phy_read = mv88e6xxx_g2_smi_phy_read,
3460 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003461 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003462 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003463 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003464 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003465 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3466 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3467 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003468 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003469 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003470 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003471 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003472 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3473 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003474 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003475 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3476 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003477 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003478 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003479};
3480
3481static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003482 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003483 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3484 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003485 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003486 .phy_read = mv88e6xxx_g2_smi_phy_read,
3487 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003488 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003489 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003490 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003491 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003492 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3493 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3494 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003495 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003496 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003497 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003498 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003499 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3500 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003501 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003502 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3503 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003504 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003505};
3506
3507static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003508 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003509 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003510 .phy_read = mv88e6xxx_g2_smi_phy_read,
3511 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003512 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003513 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003514 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003515 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003516 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003517 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3518 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3519 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003520 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003521 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003522 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003523 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003524 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3525 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003526 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003527 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3528 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003529 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003530 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003531};
3532
3533static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003534 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003535 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003536 .phy_read = mv88e6xxx_g2_smi_phy_read,
3537 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003538 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003539 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003540 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003541 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003542 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003543 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3544 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3545 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003546 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003547 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003548 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003549 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003550 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3551 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003552 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003553 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3554 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003555 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003556 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003557};
3558
3559static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003560 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003561 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3562 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003563 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003564 .phy_read = mv88e6xxx_g2_smi_phy_read,
3565 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003566 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003567 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003568 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003569 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003570 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003571 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3572 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3573 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003574 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003575 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003576 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003577 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003578 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3579 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003580 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003581 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3582 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003583 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003584 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003585};
3586
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003587static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003588 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003589 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3590 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003591 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3592 .phy_read = mv88e6xxx_g2_smi_phy_read,
3593 .phy_write = mv88e6xxx_g2_smi_phy_write,
3594 .port_set_link = mv88e6xxx_port_set_link,
3595 .port_set_duplex = mv88e6xxx_port_set_duplex,
3596 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3597 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003598 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003599 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3600 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3601 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003602 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003603 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003604 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003605 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003606 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003607 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3608 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003609 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003610 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3611 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003612 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003613 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003614};
3615
3616static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003617 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003618 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3619 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003620 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3621 .phy_read = mv88e6xxx_g2_smi_phy_read,
3622 .phy_write = mv88e6xxx_g2_smi_phy_write,
3623 .port_set_link = mv88e6xxx_port_set_link,
3624 .port_set_duplex = mv88e6xxx_port_set_duplex,
3625 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3626 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003627 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003628 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3629 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3630 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003631 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003632 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003633 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003634 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003635 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003636 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3637 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003638 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003639 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3640 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003641 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003642 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003643};
3644
3645static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003646 /* MV88E6XXX_FAMILY_6390 */
Vivien Didelot98fc3c62017-01-12 18:07:16 -05003647 .get_eeprom = mv88e6xxx_g2_get_eeprom8,
3648 .set_eeprom = mv88e6xxx_g2_set_eeprom8,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003649 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3650 .phy_read = mv88e6xxx_g2_smi_phy_read,
3651 .phy_write = mv88e6xxx_g2_smi_phy_write,
3652 .port_set_link = mv88e6xxx_port_set_link,
3653 .port_set_duplex = mv88e6xxx_port_set_duplex,
3654 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3655 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003656 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003657 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3658 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3659 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003660 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003661 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003662 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003663 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3664 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003665 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003666 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3667 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003668 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003669 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003670};
3671
Andrew Lunn56995cb2016-12-03 04:35:19 +01003672static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3673 const struct mv88e6xxx_ops *ops)
3674{
3675 if (!ops->port_set_frame_mode) {
3676 dev_err(chip->dev, "Missing port_set_frame_mode");
3677 return -EINVAL;
3678 }
3679
3680 if (!ops->port_set_egress_unknowns) {
3681 dev_err(chip->dev, "Missing port_set_egress_mode");
3682 return -EINVAL;
3683 }
3684
3685 return 0;
3686}
3687
Vivien Didelotf81ec902016-05-09 13:22:58 -04003688static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3689 [MV88E6085] = {
3690 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3691 .family = MV88E6XXX_FAMILY_6097,
3692 .name = "Marvell 88E6085",
3693 .num_databases = 4096,
3694 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003695 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003696 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003697 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003698 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003699 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003700 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003701 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003702 },
3703
3704 [MV88E6095] = {
3705 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3706 .family = MV88E6XXX_FAMILY_6095,
3707 .name = "Marvell 88E6095/88E6095F",
3708 .num_databases = 256,
3709 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003710 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003711 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003712 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003713 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003714 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003715 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003716 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003717 },
3718
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003719 [MV88E6097] = {
3720 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3721 .family = MV88E6XXX_FAMILY_6097,
3722 .name = "Marvell 88E6097/88E6097F",
3723 .num_databases = 4096,
3724 .num_ports = 11,
3725 .port_base_addr = 0x10,
3726 .global1_addr = 0x1b,
3727 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003728 .g1_irqs = 8,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003729 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003730 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3731 .ops = &mv88e6097_ops,
3732 },
3733
Vivien Didelotf81ec902016-05-09 13:22:58 -04003734 [MV88E6123] = {
3735 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3736 .family = MV88E6XXX_FAMILY_6165,
3737 .name = "Marvell 88E6123",
3738 .num_databases = 4096,
3739 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003740 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003741 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003742 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003743 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003744 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003745 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003746 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003747 },
3748
3749 [MV88E6131] = {
3750 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3751 .family = MV88E6XXX_FAMILY_6185,
3752 .name = "Marvell 88E6131",
3753 .num_databases = 256,
3754 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003755 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003756 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003757 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003758 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003759 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003760 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003761 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003762 },
3763
3764 [MV88E6161] = {
3765 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3766 .family = MV88E6XXX_FAMILY_6165,
3767 .name = "Marvell 88E6161",
3768 .num_databases = 4096,
3769 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003770 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003771 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003772 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003773 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003774 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003775 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003776 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003777 },
3778
3779 [MV88E6165] = {
3780 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3781 .family = MV88E6XXX_FAMILY_6165,
3782 .name = "Marvell 88E6165",
3783 .num_databases = 4096,
3784 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003785 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003786 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003787 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003788 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003789 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003790 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003791 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003792 },
3793
3794 [MV88E6171] = {
3795 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3796 .family = MV88E6XXX_FAMILY_6351,
3797 .name = "Marvell 88E6171",
3798 .num_databases = 4096,
3799 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003800 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003801 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003802 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003803 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003804 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003805 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003806 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003807 },
3808
3809 [MV88E6172] = {
3810 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3811 .family = MV88E6XXX_FAMILY_6352,
3812 .name = "Marvell 88E6172",
3813 .num_databases = 4096,
3814 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003815 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003816 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003817 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003818 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003819 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003820 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003821 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003822 },
3823
3824 [MV88E6175] = {
3825 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3826 .family = MV88E6XXX_FAMILY_6351,
3827 .name = "Marvell 88E6175",
3828 .num_databases = 4096,
3829 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003830 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003831 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003832 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003833 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003834 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003835 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003836 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003837 },
3838
3839 [MV88E6176] = {
3840 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3841 .family = MV88E6XXX_FAMILY_6352,
3842 .name = "Marvell 88E6176",
3843 .num_databases = 4096,
3844 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003845 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003846 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003847 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003848 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003849 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003850 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003851 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003852 },
3853
3854 [MV88E6185] = {
3855 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3856 .family = MV88E6XXX_FAMILY_6185,
3857 .name = "Marvell 88E6185",
3858 .num_databases = 256,
3859 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003860 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003861 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003862 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003863 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003864 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003865 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003866 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003867 },
3868
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003869 [MV88E6190] = {
3870 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3871 .family = MV88E6XXX_FAMILY_6390,
3872 .name = "Marvell 88E6190",
3873 .num_databases = 4096,
3874 .num_ports = 11, /* 10 + Z80 */
3875 .port_base_addr = 0x0,
3876 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003877 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003878 .age_time_coeff = 15000,
3879 .g1_irqs = 9,
3880 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3881 .ops = &mv88e6190_ops,
3882 },
3883
3884 [MV88E6190X] = {
3885 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3886 .family = MV88E6XXX_FAMILY_6390,
3887 .name = "Marvell 88E6190X",
3888 .num_databases = 4096,
3889 .num_ports = 11, /* 10 + Z80 */
3890 .port_base_addr = 0x0,
3891 .global1_addr = 0x1b,
3892 .age_time_coeff = 15000,
3893 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003894 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003895 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3896 .ops = &mv88e6190x_ops,
3897 },
3898
3899 [MV88E6191] = {
3900 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3901 .family = MV88E6XXX_FAMILY_6390,
3902 .name = "Marvell 88E6191",
3903 .num_databases = 4096,
3904 .num_ports = 11, /* 10 + Z80 */
3905 .port_base_addr = 0x0,
3906 .global1_addr = 0x1b,
3907 .age_time_coeff = 15000,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003908 .g1_irqs = 9,
3909 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003910 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3911 .ops = &mv88e6391_ops,
3912 },
3913
Vivien Didelotf81ec902016-05-09 13:22:58 -04003914 [MV88E6240] = {
3915 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3916 .family = MV88E6XXX_FAMILY_6352,
3917 .name = "Marvell 88E6240",
3918 .num_databases = 4096,
3919 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003920 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003921 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003922 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003923 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003924 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003925 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003926 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003927 },
3928
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003929 [MV88E6290] = {
3930 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3931 .family = MV88E6XXX_FAMILY_6390,
3932 .name = "Marvell 88E6290",
3933 .num_databases = 4096,
3934 .num_ports = 11, /* 10 + Z80 */
3935 .port_base_addr = 0x0,
3936 .global1_addr = 0x1b,
3937 .age_time_coeff = 15000,
3938 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003939 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003940 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3941 .ops = &mv88e6290_ops,
3942 },
3943
Vivien Didelotf81ec902016-05-09 13:22:58 -04003944 [MV88E6320] = {
3945 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3946 .family = MV88E6XXX_FAMILY_6320,
3947 .name = "Marvell 88E6320",
3948 .num_databases = 4096,
3949 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003950 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003951 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003952 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003953 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003954 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003955 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003956 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003957 },
3958
3959 [MV88E6321] = {
3960 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3961 .family = MV88E6XXX_FAMILY_6320,
3962 .name = "Marvell 88E6321",
3963 .num_databases = 4096,
3964 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003965 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003966 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003967 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003968 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003969 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003970 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003971 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003972 },
3973
3974 [MV88E6350] = {
3975 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3976 .family = MV88E6XXX_FAMILY_6351,
3977 .name = "Marvell 88E6350",
3978 .num_databases = 4096,
3979 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003980 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003981 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003982 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003983 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003984 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003985 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003986 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003987 },
3988
3989 [MV88E6351] = {
3990 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3991 .family = MV88E6XXX_FAMILY_6351,
3992 .name = "Marvell 88E6351",
3993 .num_databases = 4096,
3994 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003995 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003996 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003997 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003998 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003999 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004000 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004001 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004002 },
4003
4004 [MV88E6352] = {
4005 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4006 .family = MV88E6XXX_FAMILY_6352,
4007 .name = "Marvell 88E6352",
4008 .num_databases = 4096,
4009 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004010 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004011 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004012 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004013 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004014 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004015 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004016 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004017 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004018 [MV88E6390] = {
4019 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4020 .family = MV88E6XXX_FAMILY_6390,
4021 .name = "Marvell 88E6390",
4022 .num_databases = 4096,
4023 .num_ports = 11, /* 10 + Z80 */
4024 .port_base_addr = 0x0,
4025 .global1_addr = 0x1b,
4026 .age_time_coeff = 15000,
4027 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004028 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004029 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4030 .ops = &mv88e6390_ops,
4031 },
4032 [MV88E6390X] = {
4033 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4034 .family = MV88E6XXX_FAMILY_6390,
4035 .name = "Marvell 88E6390X",
4036 .num_databases = 4096,
4037 .num_ports = 11, /* 10 + Z80 */
4038 .port_base_addr = 0x0,
4039 .global1_addr = 0x1b,
4040 .age_time_coeff = 15000,
4041 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004042 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004043 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4044 .ops = &mv88e6390x_ops,
4045 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004046};
4047
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004048static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004049{
Vivien Didelota439c062016-04-17 13:23:58 -04004050 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004051
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004052 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4053 if (mv88e6xxx_table[i].prod_num == prod_num)
4054 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004055
Vivien Didelotb9b37712015-10-30 19:39:48 -04004056 return NULL;
4057}
4058
Vivien Didelotfad09c72016-06-21 12:28:20 -04004059static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004060{
4061 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004062 unsigned int prod_num, rev;
4063 u16 id;
4064 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004065
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004066 mutex_lock(&chip->reg_lock);
4067 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4068 mutex_unlock(&chip->reg_lock);
4069 if (err)
4070 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004071
4072 prod_num = (id & 0xfff0) >> 4;
4073 rev = id & 0x000f;
4074
4075 info = mv88e6xxx_lookup_info(prod_num);
4076 if (!info)
4077 return -ENODEV;
4078
Vivien Didelotcaac8542016-06-20 13:14:09 -04004079 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004080 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004081
Vivien Didelotca070c12016-09-02 14:45:34 -04004082 err = mv88e6xxx_g2_require(chip);
4083 if (err)
4084 return err;
4085
Vivien Didelotfad09c72016-06-21 12:28:20 -04004086 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4087 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004088
4089 return 0;
4090}
4091
Vivien Didelotfad09c72016-06-21 12:28:20 -04004092static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004093{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004094 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004095
Vivien Didelotfad09c72016-06-21 12:28:20 -04004096 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4097 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004098 return NULL;
4099
Vivien Didelotfad09c72016-06-21 12:28:20 -04004100 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004101
Vivien Didelotfad09c72016-06-21 12:28:20 -04004102 mutex_init(&chip->reg_lock);
Vivien Didelot469d7292016-06-20 13:14:06 -04004103
Vivien Didelotfad09c72016-06-21 12:28:20 -04004104 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004105}
4106
Vivien Didelote57e5e72016-08-15 17:19:00 -04004107static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4108{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004109 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004110 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004111}
4112
Andrew Lunn930188c2016-08-22 16:01:03 +02004113static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4114{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004115 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004116 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004117}
4118
Vivien Didelotfad09c72016-06-21 12:28:20 -04004119static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004120 struct mii_bus *bus, int sw_addr)
4121{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004122 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004123 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004124 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004125 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004126 else
4127 return -EINVAL;
4128
Vivien Didelotfad09c72016-06-21 12:28:20 -04004129 chip->bus = bus;
4130 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004131
4132 return 0;
4133}
4134
Andrew Lunn7b314362016-08-22 16:01:01 +02004135static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4136{
Vivien Didelot04bed142016-08-31 18:06:13 -04004137 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004138
Andrew Lunn443d5a12016-12-03 04:35:18 +01004139 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004140}
4141
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004142static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4143 struct device *host_dev, int sw_addr,
4144 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004145{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004146 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004147 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004148 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004149
Vivien Didelota439c062016-04-17 13:23:58 -04004150 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004151 if (!bus)
4152 return NULL;
4153
Vivien Didelotfad09c72016-06-21 12:28:20 -04004154 chip = mv88e6xxx_alloc_chip(dsa_dev);
4155 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004156 return NULL;
4157
Vivien Didelotcaac8542016-06-20 13:14:09 -04004158 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004159 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004160
Vivien Didelotfad09c72016-06-21 12:28:20 -04004161 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004162 if (err)
4163 goto free;
4164
Vivien Didelotfad09c72016-06-21 12:28:20 -04004165 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004166 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004167 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004168
Andrew Lunndc30c352016-10-16 19:56:49 +02004169 mutex_lock(&chip->reg_lock);
4170 err = mv88e6xxx_switch_reset(chip);
4171 mutex_unlock(&chip->reg_lock);
4172 if (err)
4173 goto free;
4174
Vivien Didelote57e5e72016-08-15 17:19:00 -04004175 mv88e6xxx_phy_init(chip);
4176
Vivien Didelotfad09c72016-06-21 12:28:20 -04004177 err = mv88e6xxx_mdio_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004178 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004179 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004180
Vivien Didelotfad09c72016-06-21 12:28:20 -04004181 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004182
Vivien Didelotfad09c72016-06-21 12:28:20 -04004183 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004184free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004185 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004186
4187 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004188}
4189
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004190static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4191 const struct switchdev_obj_port_mdb *mdb,
4192 struct switchdev_trans *trans)
4193{
4194 /* We don't need any dynamic resource from the kernel (yet),
4195 * so skip the prepare phase.
4196 */
4197
4198 return 0;
4199}
4200
4201static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4202 const struct switchdev_obj_port_mdb *mdb,
4203 struct switchdev_trans *trans)
4204{
Vivien Didelot04bed142016-08-31 18:06:13 -04004205 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004206
4207 mutex_lock(&chip->reg_lock);
4208 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4209 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4210 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4211 mutex_unlock(&chip->reg_lock);
4212}
4213
4214static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4215 const struct switchdev_obj_port_mdb *mdb)
4216{
Vivien Didelot04bed142016-08-31 18:06:13 -04004217 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004218 int err;
4219
4220 mutex_lock(&chip->reg_lock);
4221 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4222 GLOBAL_ATU_DATA_STATE_UNUSED);
4223 mutex_unlock(&chip->reg_lock);
4224
4225 return err;
4226}
4227
4228static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4229 struct switchdev_obj_port_mdb *mdb,
4230 int (*cb)(struct switchdev_obj *obj))
4231{
Vivien Didelot04bed142016-08-31 18:06:13 -04004232 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004233 int err;
4234
4235 mutex_lock(&chip->reg_lock);
4236 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4237 mutex_unlock(&chip->reg_lock);
4238
4239 return err;
4240}
4241
Florian Fainellia82f67a2017-01-08 14:52:08 -08004242static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004243 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004244 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004245 .setup = mv88e6xxx_setup,
4246 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004247 .adjust_link = mv88e6xxx_adjust_link,
4248 .get_strings = mv88e6xxx_get_strings,
4249 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4250 .get_sset_count = mv88e6xxx_get_sset_count,
4251 .set_eee = mv88e6xxx_set_eee,
4252 .get_eee = mv88e6xxx_get_eee,
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004253 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004254 .get_eeprom = mv88e6xxx_get_eeprom,
4255 .set_eeprom = mv88e6xxx_set_eeprom,
4256 .get_regs_len = mv88e6xxx_get_regs_len,
4257 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004258 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004259 .port_bridge_join = mv88e6xxx_port_bridge_join,
4260 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4261 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004262 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004263 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4264 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4265 .port_vlan_add = mv88e6xxx_port_vlan_add,
4266 .port_vlan_del = mv88e6xxx_port_vlan_del,
4267 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4268 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4269 .port_fdb_add = mv88e6xxx_port_fdb_add,
4270 .port_fdb_del = mv88e6xxx_port_fdb_del,
4271 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004272 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4273 .port_mdb_add = mv88e6xxx_port_mdb_add,
4274 .port_mdb_del = mv88e6xxx_port_mdb_del,
4275 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004276};
4277
Florian Fainelliab3d4082017-01-08 14:52:07 -08004278static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4279 .ops = &mv88e6xxx_switch_ops,
4280};
4281
Vivien Didelotfad09c72016-06-21 12:28:20 -04004282static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004283 struct device_node *np)
4284{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004285 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004286 struct dsa_switch *ds;
4287
4288 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
4289 if (!ds)
4290 return -ENOMEM;
4291
4292 ds->dev = dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004293 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004294 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004295
4296 dev_set_drvdata(dev, ds);
4297
4298 return dsa_register_switch(ds, np);
4299}
4300
Vivien Didelotfad09c72016-06-21 12:28:20 -04004301static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004302{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004303 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004304}
4305
Vivien Didelot57d32312016-06-20 13:13:58 -04004306static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004307{
4308 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004309 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004310 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004311 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004312 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004313 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004314
Vivien Didelotcaac8542016-06-20 13:14:09 -04004315 compat_info = of_device_get_match_data(dev);
4316 if (!compat_info)
4317 return -EINVAL;
4318
Vivien Didelotfad09c72016-06-21 12:28:20 -04004319 chip = mv88e6xxx_alloc_chip(dev);
4320 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004321 return -ENOMEM;
4322
Vivien Didelotfad09c72016-06-21 12:28:20 -04004323 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004324
Andrew Lunn56995cb2016-12-03 04:35:19 +01004325 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4326 if (err)
4327 return err;
4328
Vivien Didelotfad09c72016-06-21 12:28:20 -04004329 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004330 if (err)
4331 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004332
Andrew Lunnb4308f02016-11-21 23:26:55 +01004333 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4334 if (IS_ERR(chip->reset))
4335 return PTR_ERR(chip->reset);
4336
Vivien Didelotfad09c72016-06-21 12:28:20 -04004337 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004338 if (err)
4339 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004340
Vivien Didelote57e5e72016-08-15 17:19:00 -04004341 mv88e6xxx_phy_init(chip);
4342
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004343 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004344 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004345 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004346
Andrew Lunndc30c352016-10-16 19:56:49 +02004347 mutex_lock(&chip->reg_lock);
4348 err = mv88e6xxx_switch_reset(chip);
4349 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004350 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004351 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004352
Andrew Lunndc30c352016-10-16 19:56:49 +02004353 chip->irq = of_irq_get(np, 0);
4354 if (chip->irq == -EPROBE_DEFER) {
4355 err = chip->irq;
4356 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004357 }
4358
Andrew Lunndc30c352016-10-16 19:56:49 +02004359 if (chip->irq > 0) {
4360 /* Has to be performed before the MDIO bus is created,
4361 * because the PHYs will link there interrupts to these
4362 * interrupt controllers
4363 */
4364 mutex_lock(&chip->reg_lock);
4365 err = mv88e6xxx_g1_irq_setup(chip);
4366 mutex_unlock(&chip->reg_lock);
4367
4368 if (err)
4369 goto out;
4370
4371 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4372 err = mv88e6xxx_g2_irq_setup(chip);
4373 if (err)
4374 goto out_g1_irq;
4375 }
4376 }
4377
4378 err = mv88e6xxx_mdio_register(chip, np);
4379 if (err)
4380 goto out_g2_irq;
4381
4382 err = mv88e6xxx_register_switch(chip, np);
4383 if (err)
4384 goto out_mdio;
4385
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004386 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004387
4388out_mdio:
4389 mv88e6xxx_mdio_unregister(chip);
4390out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004391 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004392 mv88e6xxx_g2_irq_free(chip);
4393out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004394 if (chip->irq > 0) {
4395 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004396 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004397 mutex_unlock(&chip->reg_lock);
4398 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004399out:
4400 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004401}
4402
4403static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4404{
4405 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004406 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004407
Andrew Lunn930188c2016-08-22 16:01:03 +02004408 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004409 mv88e6xxx_unregister_switch(chip);
4410 mv88e6xxx_mdio_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004411
Andrew Lunn467126442016-11-20 20:14:15 +01004412 if (chip->irq > 0) {
4413 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4414 mv88e6xxx_g2_irq_free(chip);
4415 mv88e6xxx_g1_irq_free(chip);
4416 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004417}
4418
4419static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004420 {
4421 .compatible = "marvell,mv88e6085",
4422 .data = &mv88e6xxx_table[MV88E6085],
4423 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004424 {
4425 .compatible = "marvell,mv88e6190",
4426 .data = &mv88e6xxx_table[MV88E6190],
4427 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004428 { /* sentinel */ },
4429};
4430
4431MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4432
4433static struct mdio_driver mv88e6xxx_driver = {
4434 .probe = mv88e6xxx_probe,
4435 .remove = mv88e6xxx_remove,
4436 .mdiodrv.driver = {
4437 .name = "mv88e6085",
4438 .of_match_table = mv88e6xxx_of_match,
4439 },
4440};
4441
Ben Hutchings98e67302011-11-25 14:36:19 +00004442static int __init mv88e6xxx_init(void)
4443{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004444 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004445 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004446}
4447module_init(mv88e6xxx_init);
4448
4449static void __exit mv88e6xxx_cleanup(void)
4450{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004451 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004452 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004453}
4454module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004455
4456MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4457MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4458MODULE_LICENSE("GPL");