blob: 6aa81d2d8f63b8b09cffcf4a9108c54b68233a63 [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
Vivien Didelote57e5e72016-08-15 17:19:00 -0400225static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
226 int reg, u16 *val)
227{
228 int addr = phy; /* PHY devices addresses start at 0x0 */
229
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400230 if (!chip->info->ops->phy_read)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400231 return -EOPNOTSUPP;
232
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400233 return chip->info->ops->phy_read(chip, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400234}
235
236static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
237 int reg, u16 val)
238{
239 int addr = phy; /* PHY devices addresses start at 0x0 */
240
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400241 if (!chip->info->ops->phy_write)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400242 return -EOPNOTSUPP;
243
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400244 return chip->info->ops->phy_write(chip, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400245}
246
Vivien Didelot09cb7df2016-08-15 17:19:01 -0400247static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
248{
249 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_PHY_PAGE))
250 return -EOPNOTSUPP;
251
252 return mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
253}
254
255static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip *chip, int phy)
256{
257 int err;
258
259 /* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
260 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, PHY_PAGE_COPPER);
261 if (unlikely(err)) {
262 dev_err(chip->dev, "failed to restore PHY %d page Copper (%d)\n",
263 phy, err);
264 }
265}
266
267static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy,
268 u8 page, int reg, u16 *val)
269{
270 int err;
271
272 /* There is no paging for registers 22 */
273 if (reg == PHY_PAGE)
274 return -EINVAL;
275
276 err = mv88e6xxx_phy_page_get(chip, phy, page);
277 if (!err) {
278 err = mv88e6xxx_phy_read(chip, phy, reg, val);
279 mv88e6xxx_phy_page_put(chip, phy);
280 }
281
282 return err;
283}
284
285static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy,
286 u8 page, int reg, u16 val)
287{
288 int err;
289
290 /* There is no paging for registers 22 */
291 if (reg == PHY_PAGE)
292 return -EINVAL;
293
294 err = mv88e6xxx_phy_page_get(chip, phy, page);
295 if (!err) {
296 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
297 mv88e6xxx_phy_page_put(chip, phy);
298 }
299
300 return err;
301}
302
303static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
304{
305 return mv88e6xxx_phy_page_read(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
306 reg, val);
307}
308
309static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
310{
311 return mv88e6xxx_phy_page_write(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
312 reg, val);
313}
314
Andrew Lunndc30c352016-10-16 19:56:49 +0200315static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
316{
317 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
318 unsigned int n = d->hwirq;
319
320 chip->g1_irq.masked |= (1 << n);
321}
322
323static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
324{
325 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
326 unsigned int n = d->hwirq;
327
328 chip->g1_irq.masked &= ~(1 << n);
329}
330
331static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
332{
333 struct mv88e6xxx_chip *chip = dev_id;
334 unsigned int nhandled = 0;
335 unsigned int sub_irq;
336 unsigned int n;
337 u16 reg;
338 int err;
339
340 mutex_lock(&chip->reg_lock);
341 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
342 mutex_unlock(&chip->reg_lock);
343
344 if (err)
345 goto out;
346
347 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
348 if (reg & (1 << n)) {
349 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
350 handle_nested_irq(sub_irq);
351 ++nhandled;
352 }
353 }
354out:
355 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
356}
357
358static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
359{
360 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
361
362 mutex_lock(&chip->reg_lock);
363}
364
365static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
366{
367 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
368 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
369 u16 reg;
370 int err;
371
372 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
373 if (err)
374 goto out;
375
376 reg &= ~mask;
377 reg |= (~chip->g1_irq.masked & mask);
378
379 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
380 if (err)
381 goto out;
382
383out:
384 mutex_unlock(&chip->reg_lock);
385}
386
387static struct irq_chip mv88e6xxx_g1_irq_chip = {
388 .name = "mv88e6xxx-g1",
389 .irq_mask = mv88e6xxx_g1_irq_mask,
390 .irq_unmask = mv88e6xxx_g1_irq_unmask,
391 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
392 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
393};
394
395static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
396 unsigned int irq,
397 irq_hw_number_t hwirq)
398{
399 struct mv88e6xxx_chip *chip = d->host_data;
400
401 irq_set_chip_data(irq, d->host_data);
402 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
403 irq_set_noprobe(irq);
404
405 return 0;
406}
407
408static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
409 .map = mv88e6xxx_g1_irq_domain_map,
410 .xlate = irq_domain_xlate_twocell,
411};
412
413static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
414{
415 int irq, virq;
416
417 for (irq = 0; irq < 16; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100418 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200419 irq_dispose_mapping(virq);
420 }
421
Andrew Lunna3db3d32016-11-20 20:14:14 +0100422 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200423}
424
425static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
426{
427 int err, irq;
428 u16 reg;
429
430 chip->g1_irq.nirqs = chip->info->g1_irqs;
431 chip->g1_irq.domain = irq_domain_add_simple(
432 NULL, chip->g1_irq.nirqs, 0,
433 &mv88e6xxx_g1_irq_domain_ops, chip);
434 if (!chip->g1_irq.domain)
435 return -ENOMEM;
436
437 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
438 irq_create_mapping(chip->g1_irq.domain, irq);
439
440 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
441 chip->g1_irq.masked = ~0;
442
443 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
444 if (err)
445 goto out;
446
447 reg &= ~GENMASK(chip->g1_irq.nirqs, 0);
448
449 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
450 if (err)
451 goto out;
452
453 /* Reading the interrupt status clears (most of) them */
454 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
455 if (err)
456 goto out;
457
458 err = request_threaded_irq(chip->irq, NULL,
459 mv88e6xxx_g1_irq_thread_fn,
460 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
461 dev_name(chip->dev), chip);
462 if (err)
463 goto out;
464
465 return 0;
466
467out:
468 mv88e6xxx_g1_irq_free(chip);
469
470 return err;
471}
472
Vivien Didelotec561272016-09-02 14:45:33 -0400473int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400474{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200475 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400476
Andrew Lunn6441e6692016-08-19 00:01:55 +0200477 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400478 u16 val;
479 int err;
480
481 err = mv88e6xxx_read(chip, addr, reg, &val);
482 if (err)
483 return err;
484
485 if (!(val & mask))
486 return 0;
487
488 usleep_range(1000, 2000);
489 }
490
Andrew Lunn30853552016-08-19 00:01:57 +0200491 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400492 return -ETIMEDOUT;
493}
494
Vivien Didelotf22ab642016-07-18 20:45:31 -0400495/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400496int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400497{
498 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200499 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400500
501 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200502 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
503 if (err)
504 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400505
506 /* Set the Update bit to trigger a write operation */
507 val = BIT(15) | update;
508
509 return mv88e6xxx_write(chip, addr, reg, val);
510}
511
Vivien Didelota935c052016-09-29 12:21:53 -0400512static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000513{
Vivien Didelot914b32f2016-06-20 13:14:11 -0400514 u16 val;
Vivien Didelota935c052016-09-29 12:21:53 -0400515 int i, err;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000516
Vivien Didelota935c052016-09-29 12:21:53 -0400517 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400518 if (err)
519 return err;
Vivien Didelot3996a4f2015-10-30 18:56:45 -0400520
Vivien Didelota935c052016-09-29 12:21:53 -0400521 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL,
522 val & ~GLOBAL_CONTROL_PPU_ENABLE);
523 if (err)
524 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000525
Andrew Lunn6441e6692016-08-19 00:01:55 +0200526 for (i = 0; i < 16; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -0400527 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &val);
528 if (err)
529 return err;
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200530
Barry Grussling19b2f972013-01-08 16:05:54 +0000531 usleep_range(1000, 2000);
Vivien Didelota935c052016-09-29 12:21:53 -0400532 if ((val & GLOBAL_STATUS_PPU_MASK) != GLOBAL_STATUS_PPU_POLLING)
Barry Grussling85686582013-01-08 16:05:56 +0000533 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000534 }
535
536 return -ETIMEDOUT;
537}
538
Vivien Didelotfad09c72016-06-21 12:28:20 -0400539static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000540{
Vivien Didelota935c052016-09-29 12:21:53 -0400541 u16 val;
542 int i, err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000543
Vivien Didelota935c052016-09-29 12:21:53 -0400544 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &val);
545 if (err)
546 return err;
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200547
Vivien Didelota935c052016-09-29 12:21:53 -0400548 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL,
549 val | GLOBAL_CONTROL_PPU_ENABLE);
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200550 if (err)
551 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000552
Andrew Lunn6441e6692016-08-19 00:01:55 +0200553 for (i = 0; i < 16; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -0400554 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &val);
555 if (err)
556 return err;
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200557
Barry Grussling19b2f972013-01-08 16:05:54 +0000558 usleep_range(1000, 2000);
Vivien Didelota935c052016-09-29 12:21:53 -0400559 if ((val & GLOBAL_STATUS_PPU_MASK) == GLOBAL_STATUS_PPU_POLLING)
Barry Grussling85686582013-01-08 16:05:56 +0000560 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000561 }
562
563 return -ETIMEDOUT;
564}
565
566static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
567{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400568 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000569
Vivien Didelotfad09c72016-06-21 12:28:20 -0400570 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200571
Vivien Didelotfad09c72016-06-21 12:28:20 -0400572 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200573
Vivien Didelotfad09c72016-06-21 12:28:20 -0400574 if (mutex_trylock(&chip->ppu_mutex)) {
575 if (mv88e6xxx_ppu_enable(chip) == 0)
576 chip->ppu_disabled = 0;
577 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000578 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200579
Vivien Didelotfad09c72016-06-21 12:28:20 -0400580 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000581}
582
583static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
584{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400585 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000586
Vivien Didelotfad09c72016-06-21 12:28:20 -0400587 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000588}
589
Vivien Didelotfad09c72016-06-21 12:28:20 -0400590static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000591{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000592 int ret;
593
Vivien Didelotfad09c72016-06-21 12:28:20 -0400594 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000595
Barry Grussling3675c8d2013-01-08 16:05:53 +0000596 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000597 * we can access the PHY registers. If it was already
598 * disabled, cancel the timer that is going to re-enable
599 * it.
600 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400601 if (!chip->ppu_disabled) {
602 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000603 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400604 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000605 return ret;
606 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400607 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000608 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400609 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000610 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000611 }
612
613 return ret;
614}
615
Vivien Didelotfad09c72016-06-21 12:28:20 -0400616static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000617{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000618 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400619 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
620 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000621}
622
Vivien Didelotfad09c72016-06-21 12:28:20 -0400623static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000624{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400625 mutex_init(&chip->ppu_mutex);
626 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000627 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
628 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000629}
630
Andrew Lunn930188c2016-08-22 16:01:03 +0200631static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
632{
633 del_timer_sync(&chip->ppu_timer);
634}
635
Vivien Didelote57e5e72016-08-15 17:19:00 -0400636static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip, int addr,
637 int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000638{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400639 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000640
Vivien Didelote57e5e72016-08-15 17:19:00 -0400641 err = mv88e6xxx_ppu_access_get(chip);
642 if (!err) {
643 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400644 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000645 }
646
Vivien Didelote57e5e72016-08-15 17:19:00 -0400647 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000648}
649
Vivien Didelote57e5e72016-08-15 17:19:00 -0400650static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip, int addr,
651 int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000652{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400653 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000654
Vivien Didelote57e5e72016-08-15 17:19:00 -0400655 err = mv88e6xxx_ppu_access_get(chip);
656 if (!err) {
657 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400658 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000659 }
660
Vivien Didelote57e5e72016-08-15 17:19:00 -0400661 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000662}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000663
Vivien Didelotfad09c72016-06-21 12:28:20 -0400664static bool mv88e6xxx_6065_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_6065;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200667}
668
Vivien Didelotfad09c72016-06-21 12:28:20 -0400669static bool mv88e6xxx_6095_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_6095;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200672}
673
Vivien Didelotfad09c72016-06-21 12:28:20 -0400674static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200675{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400676 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200677}
678
Vivien Didelotfad09c72016-06-21 12:28:20 -0400679static bool mv88e6xxx_6165_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_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200682}
683
Vivien Didelotfad09c72016-06-21 12:28:20 -0400684static bool mv88e6xxx_6185_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200685{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400686 return chip->info->family == MV88E6XXX_FAMILY_6185;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200687}
688
Vivien Didelotfad09c72016-06-21 12:28:20 -0400689static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700690{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400691 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700692}
693
Vivien Didelotfad09c72016-06-21 12:28:20 -0400694static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200695{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400696 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200697}
698
Vivien Didelotfad09c72016-06-21 12:28:20 -0400699static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200700{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400701 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200702}
703
Vivien Didelotd78343d2016-11-04 03:23:36 +0100704static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
705 int link, int speed, int duplex,
706 phy_interface_t mode)
707{
708 int err;
709
710 if (!chip->info->ops->port_set_link)
711 return 0;
712
713 /* Port's MAC control must not be changed unless the link is down */
714 err = chip->info->ops->port_set_link(chip, port, 0);
715 if (err)
716 return err;
717
718 if (chip->info->ops->port_set_speed) {
719 err = chip->info->ops->port_set_speed(chip, port, speed);
720 if (err && err != -EOPNOTSUPP)
721 goto restore_link;
722 }
723
724 if (chip->info->ops->port_set_duplex) {
725 err = chip->info->ops->port_set_duplex(chip, port, duplex);
726 if (err && err != -EOPNOTSUPP)
727 goto restore_link;
728 }
729
730 if (chip->info->ops->port_set_rgmii_delay) {
731 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
732 if (err && err != -EOPNOTSUPP)
733 goto restore_link;
734 }
735
736 err = 0;
737restore_link:
738 if (chip->info->ops->port_set_link(chip, port, link))
739 netdev_err(chip->ds->ports[port].netdev,
740 "failed to restore MAC's link\n");
741
742 return err;
743}
744
Andrew Lunndea87022015-08-31 15:56:47 +0200745/* We expect the switch to perform auto negotiation if there is a real
746 * phy. However, in the case of a fixed link phy, we force the port
747 * settings from the fixed link settings.
748 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400749static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
750 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200751{
Vivien Didelot04bed142016-08-31 18:06:13 -0400752 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200753 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200754
755 if (!phy_is_pseudo_fixed_link(phydev))
756 return;
757
Vivien Didelotfad09c72016-06-21 12:28:20 -0400758 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100759 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
760 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400761 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100762
763 if (err && err != -EOPNOTSUPP)
764 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200765}
766
Vivien Didelotfad09c72016-06-21 12:28:20 -0400767static int _mv88e6xxx_stats_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000768{
Vivien Didelota935c052016-09-29 12:21:53 -0400769 u16 val;
770 int i, err;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000771
772 for (i = 0; i < 10; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -0400773 err = mv88e6xxx_g1_read(chip, GLOBAL_STATS_OP, &val);
774 if ((val & GLOBAL_STATS_OP_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000775 return 0;
776 }
777
778 return -ETIMEDOUT;
779}
780
Vivien Didelotfad09c72016-06-21 12:28:20 -0400781static int _mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000782{
Vivien Didelota935c052016-09-29 12:21:53 -0400783 int err;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000784
Vivien Didelotfad09c72016-06-21 12:28:20 -0400785 if (mv88e6xxx_6320_family(chip) || mv88e6xxx_6352_family(chip))
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200786 port = (port + 1) << 5;
787
Barry Grussling3675c8d2013-01-08 16:05:53 +0000788 /* Snapshot the hardware statistics counters for this port. */
Vivien Didelota935c052016-09-29 12:21:53 -0400789 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
790 GLOBAL_STATS_OP_CAPTURE_PORT |
791 GLOBAL_STATS_OP_HIST_RX_TX | port);
792 if (err)
793 return err;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000794
Barry Grussling3675c8d2013-01-08 16:05:53 +0000795 /* Wait for the snapshotting to complete. */
Vivien Didelota935c052016-09-29 12:21:53 -0400796 return _mv88e6xxx_stats_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000797}
798
Vivien Didelotfad09c72016-06-21 12:28:20 -0400799static void _mv88e6xxx_stats_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -0400800 int stat, u32 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000801{
Vivien Didelota935c052016-09-29 12:21:53 -0400802 u32 value;
803 u16 reg;
804 int err;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000805
806 *val = 0;
807
Vivien Didelota935c052016-09-29 12:21:53 -0400808 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
809 GLOBAL_STATS_OP_READ_CAPTURED |
810 GLOBAL_STATS_OP_HIST_RX_TX | stat);
811 if (err)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000812 return;
813
Vivien Didelota935c052016-09-29 12:21:53 -0400814 err = _mv88e6xxx_stats_wait(chip);
815 if (err)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000816 return;
817
Vivien Didelota935c052016-09-29 12:21:53 -0400818 err = mv88e6xxx_g1_read(chip, GLOBAL_STATS_COUNTER_32, &reg);
819 if (err)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000820 return;
821
Vivien Didelota935c052016-09-29 12:21:53 -0400822 value = reg << 16;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000823
Vivien Didelota935c052016-09-29 12:21:53 -0400824 err = mv88e6xxx_g1_read(chip, GLOBAL_STATS_COUNTER_01, &reg);
825 if (err)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000826 return;
827
Vivien Didelota935c052016-09-29 12:21:53 -0400828 *val = value | reg;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000829}
830
Andrew Lunne413e7e2015-04-02 04:06:38 +0200831static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100832 { "in_good_octets", 8, 0x00, BANK0, },
833 { "in_bad_octets", 4, 0x02, BANK0, },
834 { "in_unicast", 4, 0x04, BANK0, },
835 { "in_broadcasts", 4, 0x06, BANK0, },
836 { "in_multicasts", 4, 0x07, BANK0, },
837 { "in_pause", 4, 0x16, BANK0, },
838 { "in_undersize", 4, 0x18, BANK0, },
839 { "in_fragments", 4, 0x19, BANK0, },
840 { "in_oversize", 4, 0x1a, BANK0, },
841 { "in_jabber", 4, 0x1b, BANK0, },
842 { "in_rx_error", 4, 0x1c, BANK0, },
843 { "in_fcs_error", 4, 0x1d, BANK0, },
844 { "out_octets", 8, 0x0e, BANK0, },
845 { "out_unicast", 4, 0x10, BANK0, },
846 { "out_broadcasts", 4, 0x13, BANK0, },
847 { "out_multicasts", 4, 0x12, BANK0, },
848 { "out_pause", 4, 0x15, BANK0, },
849 { "excessive", 4, 0x11, BANK0, },
850 { "collisions", 4, 0x1e, BANK0, },
851 { "deferred", 4, 0x05, BANK0, },
852 { "single", 4, 0x14, BANK0, },
853 { "multiple", 4, 0x17, BANK0, },
854 { "out_fcs_error", 4, 0x03, BANK0, },
855 { "late", 4, 0x1f, BANK0, },
856 { "hist_64bytes", 4, 0x08, BANK0, },
857 { "hist_65_127bytes", 4, 0x09, BANK0, },
858 { "hist_128_255bytes", 4, 0x0a, BANK0, },
859 { "hist_256_511bytes", 4, 0x0b, BANK0, },
860 { "hist_512_1023bytes", 4, 0x0c, BANK0, },
861 { "hist_1024_max_bytes", 4, 0x0d, BANK0, },
862 { "sw_in_discards", 4, 0x10, PORT, },
863 { "sw_in_filtered", 2, 0x12, PORT, },
864 { "sw_out_filtered", 2, 0x13, PORT, },
865 { "in_discards", 4, 0x00 | GLOBAL_STATS_OP_BANK_1, BANK1, },
866 { "in_filtered", 4, 0x01 | GLOBAL_STATS_OP_BANK_1, BANK1, },
867 { "in_accepted", 4, 0x02 | GLOBAL_STATS_OP_BANK_1, BANK1, },
868 { "in_bad_accepted", 4, 0x03 | GLOBAL_STATS_OP_BANK_1, BANK1, },
869 { "in_good_avb_class_a", 4, 0x04 | GLOBAL_STATS_OP_BANK_1, BANK1, },
870 { "in_good_avb_class_b", 4, 0x05 | GLOBAL_STATS_OP_BANK_1, BANK1, },
871 { "in_bad_avb_class_a", 4, 0x06 | GLOBAL_STATS_OP_BANK_1, BANK1, },
872 { "in_bad_avb_class_b", 4, 0x07 | GLOBAL_STATS_OP_BANK_1, BANK1, },
873 { "tcam_counter_0", 4, 0x08 | GLOBAL_STATS_OP_BANK_1, BANK1, },
874 { "tcam_counter_1", 4, 0x09 | GLOBAL_STATS_OP_BANK_1, BANK1, },
875 { "tcam_counter_2", 4, 0x0a | GLOBAL_STATS_OP_BANK_1, BANK1, },
876 { "tcam_counter_3", 4, 0x0b | GLOBAL_STATS_OP_BANK_1, BANK1, },
877 { "in_da_unknown", 4, 0x0e | GLOBAL_STATS_OP_BANK_1, BANK1, },
878 { "in_management", 4, 0x0f | GLOBAL_STATS_OP_BANK_1, BANK1, },
879 { "out_queue_0", 4, 0x10 | GLOBAL_STATS_OP_BANK_1, BANK1, },
880 { "out_queue_1", 4, 0x11 | GLOBAL_STATS_OP_BANK_1, BANK1, },
881 { "out_queue_2", 4, 0x12 | GLOBAL_STATS_OP_BANK_1, BANK1, },
882 { "out_queue_3", 4, 0x13 | GLOBAL_STATS_OP_BANK_1, BANK1, },
883 { "out_queue_4", 4, 0x14 | GLOBAL_STATS_OP_BANK_1, BANK1, },
884 { "out_queue_5", 4, 0x15 | GLOBAL_STATS_OP_BANK_1, BANK1, },
885 { "out_queue_6", 4, 0x16 | GLOBAL_STATS_OP_BANK_1, BANK1, },
886 { "out_queue_7", 4, 0x17 | GLOBAL_STATS_OP_BANK_1, BANK1, },
887 { "out_cut_through", 4, 0x18 | GLOBAL_STATS_OP_BANK_1, BANK1, },
888 { "out_octets_a", 4, 0x1a | GLOBAL_STATS_OP_BANK_1, BANK1, },
889 { "out_octets_b", 4, 0x1b | GLOBAL_STATS_OP_BANK_1, BANK1, },
890 { "out_management", 4, 0x1f | GLOBAL_STATS_OP_BANK_1, BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200891};
892
Vivien Didelotfad09c72016-06-21 12:28:20 -0400893static bool mv88e6xxx_has_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100894 struct mv88e6xxx_hw_stat *stat)
Andrew Lunne413e7e2015-04-02 04:06:38 +0200895{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100896 switch (stat->type) {
897 case BANK0:
Andrew Lunne413e7e2015-04-02 04:06:38 +0200898 return true;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100899 case BANK1:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400900 return mv88e6xxx_6320_family(chip);
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100901 case PORT:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400902 return mv88e6xxx_6095_family(chip) ||
903 mv88e6xxx_6185_family(chip) ||
904 mv88e6xxx_6097_family(chip) ||
905 mv88e6xxx_6165_family(chip) ||
906 mv88e6xxx_6351_family(chip) ||
907 mv88e6xxx_6352_family(chip);
Andrew Lunne413e7e2015-04-02 04:06:38 +0200908 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100909 return false;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000910}
911
Vivien Didelotfad09c72016-06-21 12:28:20 -0400912static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100913 struct mv88e6xxx_hw_stat *s,
Andrew Lunn80c46272015-06-20 18:42:30 +0200914 int port)
915{
Andrew Lunn80c46272015-06-20 18:42:30 +0200916 u32 low;
917 u32 high = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200918 int err;
919 u16 reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200920 u64 value;
921
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100922 switch (s->type) {
923 case PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200924 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
925 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200926 return UINT64_MAX;
927
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200928 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200929 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200930 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
931 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200932 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200933 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200934 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100935 break;
936 case BANK0:
937 case BANK1:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400938 _mv88e6xxx_stats_read(chip, s->reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200939 if (s->sizeof_stat == 8)
Vivien Didelotfad09c72016-06-21 12:28:20 -0400940 _mv88e6xxx_stats_read(chip, s->reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200941 }
942 value = (((u64)high) << 16) | low;
943 return value;
944}
945
Vivien Didelotf81ec902016-05-09 13:22:58 -0400946static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
947 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100948{
Vivien Didelot04bed142016-08-31 18:06:13 -0400949 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100950 struct mv88e6xxx_hw_stat *stat;
951 int i, j;
952
953 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
954 stat = &mv88e6xxx_hw_stats[i];
Vivien Didelotfad09c72016-06-21 12:28:20 -0400955 if (mv88e6xxx_has_stat(chip, stat)) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100956 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
957 ETH_GSTRING_LEN);
958 j++;
959 }
960 }
961}
962
Vivien Didelotf81ec902016-05-09 13:22:58 -0400963static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100964{
Vivien Didelot04bed142016-08-31 18:06:13 -0400965 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100966 struct mv88e6xxx_hw_stat *stat;
967 int i, j;
968
969 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
970 stat = &mv88e6xxx_hw_stats[i];
Vivien Didelotfad09c72016-06-21 12:28:20 -0400971 if (mv88e6xxx_has_stat(chip, stat))
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100972 j++;
973 }
974 return j;
975}
976
Vivien Didelotf81ec902016-05-09 13:22:58 -0400977static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
978 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000979{
Vivien Didelot04bed142016-08-31 18:06:13 -0400980 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100981 struct mv88e6xxx_hw_stat *stat;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000982 int ret;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100983 int i, j;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000984
Vivien Didelotfad09c72016-06-21 12:28:20 -0400985 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000986
Vivien Didelotfad09c72016-06-21 12:28:20 -0400987 ret = _mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000988 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400989 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000990 return;
991 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100992 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
993 stat = &mv88e6xxx_hw_stats[i];
Vivien Didelotfad09c72016-06-21 12:28:20 -0400994 if (mv88e6xxx_has_stat(chip, stat)) {
995 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port);
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100996 j++;
997 }
998 }
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000999
Vivien Didelotfad09c72016-06-21 12:28:20 -04001000 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001001}
Ben Hutchings98e67302011-11-25 14:36:19 +00001002
Vivien Didelotf81ec902016-05-09 13:22:58 -04001003static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001004{
1005 return 32 * sizeof(u16);
1006}
1007
Vivien Didelotf81ec902016-05-09 13:22:58 -04001008static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1009 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001010{
Vivien Didelot04bed142016-08-31 18:06:13 -04001011 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001012 int err;
1013 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001014 u16 *p = _p;
1015 int i;
1016
1017 regs->version = 0;
1018
1019 memset(p, 0xff, 32 * sizeof(u16));
1020
Vivien Didelotfad09c72016-06-21 12:28:20 -04001021 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001022
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001023 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001024
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001025 err = mv88e6xxx_port_read(chip, port, i, &reg);
1026 if (!err)
1027 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001028 }
Vivien Didelot23062512016-05-09 13:22:45 -04001029
Vivien Didelotfad09c72016-06-21 12:28:20 -04001030 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001031}
1032
Vivien Didelotfad09c72016-06-21 12:28:20 -04001033static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001034{
Vivien Didelota935c052016-09-29 12:21:53 -04001035 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001036}
1037
Vivien Didelotf81ec902016-05-09 13:22:58 -04001038static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1039 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001040{
Vivien Didelot04bed142016-08-31 18:06:13 -04001041 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001042 u16 reg;
1043 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001044
Vivien Didelotfad09c72016-06-21 12:28:20 -04001045 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001046 return -EOPNOTSUPP;
1047
Vivien Didelotfad09c72016-06-21 12:28:20 -04001048 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001049
Vivien Didelot9c938292016-08-15 17:19:02 -04001050 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1051 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001052 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001053
1054 e->eee_enabled = !!(reg & 0x0200);
1055 e->tx_lpi_enabled = !!(reg & 0x0100);
1056
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001057 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001058 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001059 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001060
Andrew Lunncca8b132015-04-02 04:06:39 +02001061 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001062out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001063 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001064
1065 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001066}
1067
Vivien Didelotf81ec902016-05-09 13:22:58 -04001068static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1069 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001070{
Vivien Didelot04bed142016-08-31 18:06:13 -04001071 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001072 u16 reg;
1073 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001074
Vivien Didelotfad09c72016-06-21 12:28:20 -04001075 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001076 return -EOPNOTSUPP;
1077
Vivien Didelotfad09c72016-06-21 12:28:20 -04001078 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001079
Vivien Didelot9c938292016-08-15 17:19:02 -04001080 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1081 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001082 goto out;
1083
Vivien Didelot9c938292016-08-15 17:19:02 -04001084 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001085 if (e->eee_enabled)
1086 reg |= 0x0200;
1087 if (e->tx_lpi_enabled)
1088 reg |= 0x0100;
1089
Vivien Didelot9c938292016-08-15 17:19:02 -04001090 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001091out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001092 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001093
Vivien Didelot9c938292016-08-15 17:19:02 -04001094 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001095}
1096
Vivien Didelotfad09c72016-06-21 12:28:20 -04001097static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001098{
Vivien Didelota935c052016-09-29 12:21:53 -04001099 u16 val;
1100 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001101
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001102 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001103 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1104 if (err)
1105 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001106 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001107 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001108 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1109 if (err)
1110 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001111
Vivien Didelota935c052016-09-29 12:21:53 -04001112 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1113 (val & 0xfff) | ((fid << 8) & 0xf000));
1114 if (err)
1115 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001116
1117 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1118 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001119 }
1120
Vivien Didelota935c052016-09-29 12:21:53 -04001121 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1122 if (err)
1123 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001124
Vivien Didelotfad09c72016-06-21 12:28:20 -04001125 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001126}
1127
Vivien Didelotfad09c72016-06-21 12:28:20 -04001128static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001129 struct mv88e6xxx_atu_entry *entry)
1130{
1131 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1132
1133 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1134 unsigned int mask, shift;
1135
1136 if (entry->trunk) {
1137 data |= GLOBAL_ATU_DATA_TRUNK;
1138 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1139 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1140 } else {
1141 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1142 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1143 }
1144
1145 data |= (entry->portv_trunkid << shift) & mask;
1146 }
1147
Vivien Didelota935c052016-09-29 12:21:53 -04001148 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001149}
1150
Vivien Didelotfad09c72016-06-21 12:28:20 -04001151static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001152 struct mv88e6xxx_atu_entry *entry,
1153 bool static_too)
1154{
1155 int op;
1156 int err;
1157
Vivien Didelotfad09c72016-06-21 12:28:20 -04001158 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001159 if (err)
1160 return err;
1161
Vivien Didelotfad09c72016-06-21 12:28:20 -04001162 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001163 if (err)
1164 return err;
1165
1166 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001167 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1168 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1169 } else {
1170 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1171 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1172 }
1173
Vivien Didelotfad09c72016-06-21 12:28:20 -04001174 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001175}
1176
Vivien Didelotfad09c72016-06-21 12:28:20 -04001177static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001178 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001179{
1180 struct mv88e6xxx_atu_entry entry = {
1181 .fid = fid,
1182 .state = 0, /* EntryState bits must be 0 */
1183 };
1184
Vivien Didelotfad09c72016-06-21 12:28:20 -04001185 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001186}
1187
Vivien Didelotfad09c72016-06-21 12:28:20 -04001188static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001189 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001190{
1191 struct mv88e6xxx_atu_entry entry = {
1192 .trunk = false,
1193 .fid = fid,
1194 };
1195
1196 /* EntryState bits must be 0xF */
1197 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1198
1199 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1200 entry.portv_trunkid = (to_port & 0x0f) << 4;
1201 entry.portv_trunkid |= from_port & 0x0f;
1202
Vivien Didelotfad09c72016-06-21 12:28:20 -04001203 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001204}
1205
Vivien Didelotfad09c72016-06-21 12:28:20 -04001206static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001207 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001208{
1209 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001210 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001211}
1212
Vivien Didelotfad09c72016-06-21 12:28:20 -04001213static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001214{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001215 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001216 struct dsa_switch *ds = chip->ds;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001217 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001218 int i;
1219
1220 /* allow CPU port or DSA link(s) to send frames to every port */
1221 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001222 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001223 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001224 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001225 /* allow sending frames to every group member */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001226 if (bridge && chip->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001227 output_ports |= BIT(i);
1228
1229 /* allow sending frames to CPU port and DSA link(s) */
1230 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1231 output_ports |= BIT(i);
1232 }
1233 }
1234
1235 /* prevent frames from going back out of the port they came in on */
1236 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001237
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001238 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001239}
1240
Vivien Didelotf81ec902016-05-09 13:22:58 -04001241static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1242 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001243{
Vivien Didelot04bed142016-08-31 18:06:13 -04001244 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001245 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001246 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001247
1248 switch (state) {
1249 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001250 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001251 break;
1252 case BR_STATE_BLOCKING:
1253 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001254 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001255 break;
1256 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001257 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001258 break;
1259 case BR_STATE_FORWARDING:
1260 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001261 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001262 break;
1263 }
1264
Vivien Didelotfad09c72016-06-21 12:28:20 -04001265 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001266 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001267 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001268
1269 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001270 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001271}
1272
Vivien Didelot749efcb2016-09-22 16:49:24 -04001273static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1274{
1275 struct mv88e6xxx_chip *chip = ds->priv;
1276 int err;
1277
1278 mutex_lock(&chip->reg_lock);
1279 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1280 mutex_unlock(&chip->reg_lock);
1281
1282 if (err)
1283 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1284}
1285
Vivien Didelotfad09c72016-06-21 12:28:20 -04001286static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001287{
Vivien Didelota935c052016-09-29 12:21:53 -04001288 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001289}
1290
Vivien Didelotfad09c72016-06-21 12:28:20 -04001291static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001292{
Vivien Didelota935c052016-09-29 12:21:53 -04001293 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001294
Vivien Didelota935c052016-09-29 12:21:53 -04001295 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1296 if (err)
1297 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001298
Vivien Didelotfad09c72016-06-21 12:28:20 -04001299 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001300}
1301
Vivien Didelotfad09c72016-06-21 12:28:20 -04001302static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001303{
1304 int ret;
1305
Vivien Didelotfad09c72016-06-21 12:28:20 -04001306 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001307 if (ret < 0)
1308 return ret;
1309
Vivien Didelotfad09c72016-06-21 12:28:20 -04001310 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001311}
1312
Vivien Didelotfad09c72016-06-21 12:28:20 -04001313static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001314 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001315 unsigned int nibble_offset)
1316{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001317 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001318 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001319
1320 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001321 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001322
Vivien Didelota935c052016-09-29 12:21:53 -04001323 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1324 if (err)
1325 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001326 }
1327
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001328 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001329 unsigned int shift = (i % 4) * 4 + nibble_offset;
1330 u16 reg = regs[i / 4];
1331
1332 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1333 }
1334
1335 return 0;
1336}
1337
Vivien Didelotfad09c72016-06-21 12:28:20 -04001338static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001339 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001340{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001341 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001342}
1343
Vivien Didelotfad09c72016-06-21 12:28:20 -04001344static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001345 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001346{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001347 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001348}
1349
Vivien Didelotfad09c72016-06-21 12:28:20 -04001350static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001351 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001352 unsigned int nibble_offset)
1353{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001354 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001355 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001356
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001357 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001358 unsigned int shift = (i % 4) * 4 + nibble_offset;
1359 u8 data = entry->data[i];
1360
1361 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1362 }
1363
1364 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001365 u16 reg = regs[i];
1366
1367 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1368 if (err)
1369 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001370 }
1371
1372 return 0;
1373}
1374
Vivien Didelotfad09c72016-06-21 12:28:20 -04001375static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001376 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001377{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001378 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001379}
1380
Vivien Didelotfad09c72016-06-21 12:28:20 -04001381static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001382 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001383{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001384 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001385}
1386
Vivien Didelotfad09c72016-06-21 12:28:20 -04001387static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001388{
Vivien Didelota935c052016-09-29 12:21:53 -04001389 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1390 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001391}
1392
Vivien Didelotfad09c72016-06-21 12:28:20 -04001393static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001394 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001395{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001396 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001397 u16 val;
1398 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001399
Vivien Didelota935c052016-09-29 12:21:53 -04001400 err = _mv88e6xxx_vtu_wait(chip);
1401 if (err)
1402 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001403
Vivien Didelota935c052016-09-29 12:21:53 -04001404 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1405 if (err)
1406 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001407
Vivien Didelota935c052016-09-29 12:21:53 -04001408 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1409 if (err)
1410 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001411
Vivien Didelota935c052016-09-29 12:21:53 -04001412 next.vid = val & GLOBAL_VTU_VID_MASK;
1413 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001414
1415 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001416 err = mv88e6xxx_vtu_data_read(chip, &next);
1417 if (err)
1418 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001419
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001420 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001421 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1422 if (err)
1423 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001424
Vivien Didelota935c052016-09-29 12:21:53 -04001425 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001426 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001427 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1428 * VTU DBNum[3:0] are located in VTU Operation 3:0
1429 */
Vivien Didelota935c052016-09-29 12:21:53 -04001430 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1431 if (err)
1432 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001433
Vivien Didelota935c052016-09-29 12:21:53 -04001434 next.fid = (val & 0xf00) >> 4;
1435 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001436 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001437
Vivien Didelotfad09c72016-06-21 12:28:20 -04001438 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001439 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1440 if (err)
1441 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001442
Vivien Didelota935c052016-09-29 12:21:53 -04001443 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001444 }
1445 }
1446
1447 *entry = next;
1448 return 0;
1449}
1450
Vivien Didelotf81ec902016-05-09 13:22:58 -04001451static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1452 struct switchdev_obj_port_vlan *vlan,
1453 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001454{
Vivien Didelot04bed142016-08-31 18:06:13 -04001455 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001456 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001457 u16 pvid;
1458 int err;
1459
Vivien Didelotfad09c72016-06-21 12:28:20 -04001460 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001461 return -EOPNOTSUPP;
1462
Vivien Didelotfad09c72016-06-21 12:28:20 -04001463 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001464
Vivien Didelot77064f32016-11-04 03:23:30 +01001465 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001466 if (err)
1467 goto unlock;
1468
Vivien Didelotfad09c72016-06-21 12:28:20 -04001469 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001470 if (err)
1471 goto unlock;
1472
1473 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001474 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001475 if (err)
1476 break;
1477
1478 if (!next.valid)
1479 break;
1480
1481 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1482 continue;
1483
1484 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001485 vlan->vid_begin = next.vid;
1486 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001487 vlan->flags = 0;
1488
1489 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1490 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1491
1492 if (next.vid == pvid)
1493 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1494
1495 err = cb(&vlan->obj);
1496 if (err)
1497 break;
1498 } while (next.vid < GLOBAL_VTU_VID_MASK);
1499
1500unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001501 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001502
1503 return err;
1504}
1505
Vivien Didelotfad09c72016-06-21 12:28:20 -04001506static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001507 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001508{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001509 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001510 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001511 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001512
Vivien Didelota935c052016-09-29 12:21:53 -04001513 err = _mv88e6xxx_vtu_wait(chip);
1514 if (err)
1515 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001516
1517 if (!entry->valid)
1518 goto loadpurge;
1519
1520 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001521 err = mv88e6xxx_vtu_data_write(chip, entry);
1522 if (err)
1523 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001524
Vivien Didelotfad09c72016-06-21 12:28:20 -04001525 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001526 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001527 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1528 if (err)
1529 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001530 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001531
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001532 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001533 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001534 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1535 if (err)
1536 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001537 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001538 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1539 * VTU DBNum[3:0] are located in VTU Operation 3:0
1540 */
1541 op |= (entry->fid & 0xf0) << 8;
1542 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001543 }
1544
1545 reg = GLOBAL_VTU_VID_VALID;
1546loadpurge:
1547 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001548 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1549 if (err)
1550 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001551
Vivien Didelotfad09c72016-06-21 12:28:20 -04001552 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001553}
1554
Vivien Didelotfad09c72016-06-21 12:28:20 -04001555static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001556 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001557{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001558 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001559 u16 val;
1560 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001561
Vivien Didelota935c052016-09-29 12:21:53 -04001562 err = _mv88e6xxx_vtu_wait(chip);
1563 if (err)
1564 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001565
Vivien Didelota935c052016-09-29 12:21:53 -04001566 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1567 sid & GLOBAL_VTU_SID_MASK);
1568 if (err)
1569 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001570
Vivien Didelota935c052016-09-29 12:21:53 -04001571 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
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_read(chip, GLOBAL_VTU_SID, &val);
1576 if (err)
1577 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001578
Vivien Didelota935c052016-09-29 12:21:53 -04001579 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001580
Vivien Didelota935c052016-09-29 12:21:53 -04001581 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1582 if (err)
1583 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001584
Vivien Didelota935c052016-09-29 12:21:53 -04001585 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001586
1587 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001588 err = mv88e6xxx_stu_data_read(chip, &next);
1589 if (err)
1590 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001591 }
1592
1593 *entry = next;
1594 return 0;
1595}
1596
Vivien Didelotfad09c72016-06-21 12:28:20 -04001597static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001598 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001599{
1600 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001601 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001602
Vivien Didelota935c052016-09-29 12:21:53 -04001603 err = _mv88e6xxx_vtu_wait(chip);
1604 if (err)
1605 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001606
1607 if (!entry->valid)
1608 goto loadpurge;
1609
1610 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001611 err = mv88e6xxx_stu_data_write(chip, entry);
1612 if (err)
1613 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001614
1615 reg = GLOBAL_VTU_VID_VALID;
1616loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001617 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1618 if (err)
1619 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001620
1621 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001622 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1623 if (err)
1624 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001625
Vivien Didelotfad09c72016-06-21 12:28:20 -04001626 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001627}
1628
Vivien Didelotfad09c72016-06-21 12:28:20 -04001629static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001630{
1631 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001632 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001633 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001634
1635 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1636
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001637 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001638 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001639 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001640 if (err)
1641 return err;
1642
1643 set_bit(*fid, fid_bitmap);
1644 }
1645
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001646 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001647 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001648 if (err)
1649 return err;
1650
1651 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001652 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001653 if (err)
1654 return err;
1655
1656 if (!vlan.valid)
1657 break;
1658
1659 set_bit(vlan.fid, fid_bitmap);
1660 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1661
1662 /* The reset value 0x000 is used to indicate that multiple address
1663 * databases are not needed. Return the next positive available.
1664 */
1665 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001666 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001667 return -ENOSPC;
1668
1669 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001670 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001671}
1672
Vivien Didelotfad09c72016-06-21 12:28:20 -04001673static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001674 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001675{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001676 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001677 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001678 .valid = true,
1679 .vid = vid,
1680 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001681 int i, err;
1682
Vivien Didelotfad09c72016-06-21 12:28:20 -04001683 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001684 if (err)
1685 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001686
Vivien Didelot3d131f02015-11-03 10:52:52 -05001687 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001688 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001689 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1690 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1691 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001692
Vivien Didelotfad09c72016-06-21 12:28:20 -04001693 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
1694 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001695 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001696
1697 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1698 * implemented, only one STU entry is needed to cover all VTU
1699 * entries. Thus, validate the SID 0.
1700 */
1701 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001702 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001703 if (err)
1704 return err;
1705
1706 if (vstp.sid != vlan.sid || !vstp.valid) {
1707 memset(&vstp, 0, sizeof(vstp));
1708 vstp.valid = true;
1709 vstp.sid = vlan.sid;
1710
Vivien Didelotfad09c72016-06-21 12:28:20 -04001711 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001712 if (err)
1713 return err;
1714 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001715 }
1716
1717 *entry = vlan;
1718 return 0;
1719}
1720
Vivien Didelotfad09c72016-06-21 12:28:20 -04001721static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001722 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001723{
1724 int err;
1725
1726 if (!vid)
1727 return -EINVAL;
1728
Vivien Didelotfad09c72016-06-21 12:28:20 -04001729 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001730 if (err)
1731 return err;
1732
Vivien Didelotfad09c72016-06-21 12:28:20 -04001733 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001734 if (err)
1735 return err;
1736
1737 if (entry->vid != vid || !entry->valid) {
1738 if (!creat)
1739 return -EOPNOTSUPP;
1740 /* -ENOENT would've been more appropriate, but switchdev expects
1741 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1742 */
1743
Vivien Didelotfad09c72016-06-21 12:28:20 -04001744 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001745 }
1746
1747 return err;
1748}
1749
Vivien Didelotda9c3592016-02-12 12:09:40 -05001750static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1751 u16 vid_begin, u16 vid_end)
1752{
Vivien Didelot04bed142016-08-31 18:06:13 -04001753 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001754 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001755 int i, err;
1756
1757 if (!vid_begin)
1758 return -EOPNOTSUPP;
1759
Vivien Didelotfad09c72016-06-21 12:28:20 -04001760 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001761
Vivien Didelotfad09c72016-06-21 12:28:20 -04001762 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001763 if (err)
1764 goto unlock;
1765
1766 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001767 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001768 if (err)
1769 goto unlock;
1770
1771 if (!vlan.valid)
1772 break;
1773
1774 if (vlan.vid > vid_end)
1775 break;
1776
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001777 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001778 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1779 continue;
1780
1781 if (vlan.data[i] ==
1782 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1783 continue;
1784
Vivien Didelotfad09c72016-06-21 12:28:20 -04001785 if (chip->ports[i].bridge_dev ==
1786 chip->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001787 break; /* same bridge, check next VLAN */
1788
Andrew Lunnc8b09802016-06-04 21:16:57 +02001789 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001790 "hardware VLAN %d already used by %s\n",
1791 vlan.vid,
Vivien Didelotfad09c72016-06-21 12:28:20 -04001792 netdev_name(chip->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001793 err = -EOPNOTSUPP;
1794 goto unlock;
1795 }
1796 } while (vlan.vid < vid_end);
1797
1798unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001799 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001800
1801 return err;
1802}
1803
Vivien Didelotf81ec902016-05-09 13:22:58 -04001804static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1805 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001806{
Vivien Didelot04bed142016-08-31 18:06:13 -04001807 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001808 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001809 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001810 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001811
Vivien Didelotfad09c72016-06-21 12:28:20 -04001812 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001813 return -EOPNOTSUPP;
1814
Vivien Didelotfad09c72016-06-21 12:28:20 -04001815 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001816 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001817 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001818
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001819 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001820}
1821
Vivien Didelot57d32312016-06-20 13:13:58 -04001822static int
1823mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1824 const struct switchdev_obj_port_vlan *vlan,
1825 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001826{
Vivien Didelot04bed142016-08-31 18:06:13 -04001827 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001828 int err;
1829
Vivien Didelotfad09c72016-06-21 12:28:20 -04001830 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001831 return -EOPNOTSUPP;
1832
Vivien Didelotda9c3592016-02-12 12:09:40 -05001833 /* If the requested port doesn't belong to the same bridge as the VLAN
1834 * members, do not support it (yet) and fallback to software VLAN.
1835 */
1836 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1837 vlan->vid_end);
1838 if (err)
1839 return err;
1840
Vivien Didelot76e398a2015-11-01 12:33:55 -05001841 /* We don't need any dynamic resource from the kernel (yet),
1842 * so skip the prepare phase.
1843 */
1844 return 0;
1845}
1846
Vivien Didelotfad09c72016-06-21 12:28:20 -04001847static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001848 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001849{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001850 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001851 int err;
1852
Vivien Didelotfad09c72016-06-21 12:28:20 -04001853 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001854 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001855 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001856
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001857 vlan.data[port] = untagged ?
1858 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1859 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1860
Vivien Didelotfad09c72016-06-21 12:28:20 -04001861 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001862}
1863
Vivien Didelotf81ec902016-05-09 13:22:58 -04001864static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1865 const struct switchdev_obj_port_vlan *vlan,
1866 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001867{
Vivien Didelot04bed142016-08-31 18:06:13 -04001868 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001869 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1870 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1871 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001872
Vivien Didelotfad09c72016-06-21 12:28:20 -04001873 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001874 return;
1875
Vivien Didelotfad09c72016-06-21 12:28:20 -04001876 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001877
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001878 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001879 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001880 netdev_err(ds->ports[port].netdev,
1881 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001882 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001883
Vivien Didelot77064f32016-11-04 03:23:30 +01001884 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001885 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001886 vlan->vid_end);
1887
Vivien Didelotfad09c72016-06-21 12:28:20 -04001888 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001889}
1890
Vivien Didelotfad09c72016-06-21 12:28:20 -04001891static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001892 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001893{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001894 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001895 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001896 int i, err;
1897
Vivien Didelotfad09c72016-06-21 12:28:20 -04001898 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001899 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001900 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001901
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001902 /* Tell switchdev if this VLAN is handled in software */
1903 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001904 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001905
1906 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1907
1908 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001909 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001910 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001911 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001912 continue;
1913
1914 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001915 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001916 break;
1917 }
1918 }
1919
Vivien Didelotfad09c72016-06-21 12:28:20 -04001920 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001921 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001922 return err;
1923
Vivien Didelotfad09c72016-06-21 12:28:20 -04001924 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001925}
1926
Vivien Didelotf81ec902016-05-09 13:22:58 -04001927static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1928 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001929{
Vivien Didelot04bed142016-08-31 18:06:13 -04001930 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001931 u16 pvid, vid;
1932 int err = 0;
1933
Vivien Didelotfad09c72016-06-21 12:28:20 -04001934 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001935 return -EOPNOTSUPP;
1936
Vivien Didelotfad09c72016-06-21 12:28:20 -04001937 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001938
Vivien Didelot77064f32016-11-04 03:23:30 +01001939 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001940 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001941 goto unlock;
1942
Vivien Didelot76e398a2015-11-01 12:33:55 -05001943 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001944 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001945 if (err)
1946 goto unlock;
1947
1948 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001949 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001950 if (err)
1951 goto unlock;
1952 }
1953 }
1954
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001955unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001956 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001957
1958 return err;
1959}
1960
Vivien Didelotfad09c72016-06-21 12:28:20 -04001961static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04001962 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001963{
Vivien Didelota935c052016-09-29 12:21:53 -04001964 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001965
1966 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04001967 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
1968 (addr[i * 2] << 8) | addr[i * 2 + 1]);
1969 if (err)
1970 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001971 }
1972
1973 return 0;
1974}
1975
Vivien Didelotfad09c72016-06-21 12:28:20 -04001976static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001977 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001978{
Vivien Didelota935c052016-09-29 12:21:53 -04001979 u16 val;
1980 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001981
1982 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04001983 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
1984 if (err)
1985 return err;
1986
1987 addr[i * 2] = val >> 8;
1988 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001989 }
1990
1991 return 0;
1992}
1993
Vivien Didelotfad09c72016-06-21 12:28:20 -04001994static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04001995 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001996{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001997 int ret;
1998
Vivien Didelotfad09c72016-06-21 12:28:20 -04001999 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002000 if (ret < 0)
2001 return ret;
2002
Vivien Didelotfad09c72016-06-21 12:28:20 -04002003 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002004 if (ret < 0)
2005 return ret;
2006
Vivien Didelotfad09c72016-06-21 12:28:20 -04002007 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002008 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002009 return ret;
2010
Vivien Didelotfad09c72016-06-21 12:28:20 -04002011 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002012}
David S. Millercdf09692015-08-11 12:00:37 -07002013
Vivien Didelot88472932016-09-19 19:56:11 -04002014static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2015 struct mv88e6xxx_atu_entry *entry);
2016
2017static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2018 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2019{
2020 struct mv88e6xxx_atu_entry next;
2021 int err;
2022
2023 eth_broadcast_addr(next.mac);
2024
2025 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2026 if (err)
2027 return err;
2028
2029 do {
2030 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2031 if (err)
2032 return err;
2033
2034 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2035 break;
2036
2037 if (ether_addr_equal(next.mac, addr)) {
2038 *entry = next;
2039 return 0;
2040 }
2041 } while (!is_broadcast_ether_addr(next.mac));
2042
2043 memset(entry, 0, sizeof(*entry));
2044 entry->fid = fid;
2045 ether_addr_copy(entry->mac, addr);
2046
2047 return 0;
2048}
2049
Vivien Didelot83dabd12016-08-31 11:50:04 -04002050static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2051 const unsigned char *addr, u16 vid,
2052 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002053{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002054 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002055 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002056 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002057
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002058 /* Null VLAN ID corresponds to the port private database */
2059 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002060 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002061 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002062 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002063 if (err)
2064 return err;
2065
Vivien Didelot88472932016-09-19 19:56:11 -04002066 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2067 if (err)
2068 return err;
2069
2070 /* Purge the ATU entry only if no port is using it anymore */
2071 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2072 entry.portv_trunkid &= ~BIT(port);
2073 if (!entry.portv_trunkid)
2074 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2075 } else {
2076 entry.portv_trunkid |= BIT(port);
2077 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002078 }
2079
Vivien Didelotfad09c72016-06-21 12:28:20 -04002080 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002081}
2082
Vivien Didelotf81ec902016-05-09 13:22:58 -04002083static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2084 const struct switchdev_obj_port_fdb *fdb,
2085 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002086{
2087 /* We don't need any dynamic resource from the kernel (yet),
2088 * so skip the prepare phase.
2089 */
2090 return 0;
2091}
2092
Vivien Didelotf81ec902016-05-09 13:22:58 -04002093static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2094 const struct switchdev_obj_port_fdb *fdb,
2095 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002096{
Vivien Didelot04bed142016-08-31 18:06:13 -04002097 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002098
Vivien Didelotfad09c72016-06-21 12:28:20 -04002099 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002100 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2101 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2102 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002103 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002104}
2105
Vivien Didelotf81ec902016-05-09 13:22:58 -04002106static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2107 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002108{
Vivien Didelot04bed142016-08-31 18:06:13 -04002109 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002110 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002111
Vivien Didelotfad09c72016-06-21 12:28:20 -04002112 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002113 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2114 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002115 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002116
Vivien Didelot83dabd12016-08-31 11:50:04 -04002117 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002118}
2119
Vivien Didelotfad09c72016-06-21 12:28:20 -04002120static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002121 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002122{
Vivien Didelot1d194042015-08-10 09:09:51 -04002123 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002124 u16 val;
2125 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002126
2127 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002128
Vivien Didelota935c052016-09-29 12:21:53 -04002129 err = _mv88e6xxx_atu_wait(chip);
2130 if (err)
2131 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002132
Vivien Didelota935c052016-09-29 12:21:53 -04002133 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2134 if (err)
2135 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002136
Vivien Didelota935c052016-09-29 12:21:53 -04002137 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2138 if (err)
2139 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002140
Vivien Didelota935c052016-09-29 12:21:53 -04002141 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2142 if (err)
2143 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002144
Vivien Didelota935c052016-09-29 12:21:53 -04002145 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002146 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2147 unsigned int mask, shift;
2148
Vivien Didelota935c052016-09-29 12:21:53 -04002149 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002150 next.trunk = true;
2151 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2152 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2153 } else {
2154 next.trunk = false;
2155 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2156 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2157 }
2158
Vivien Didelota935c052016-09-29 12:21:53 -04002159 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002160 }
2161
2162 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002163 return 0;
2164}
2165
Vivien Didelot83dabd12016-08-31 11:50:04 -04002166static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2167 u16 fid, u16 vid, int port,
2168 struct switchdev_obj *obj,
2169 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002170{
2171 struct mv88e6xxx_atu_entry addr = {
2172 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2173 };
2174 int err;
2175
Vivien Didelotfad09c72016-06-21 12:28:20 -04002176 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002177 if (err)
2178 return err;
2179
2180 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002181 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002182 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002183 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002184
2185 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2186 break;
2187
Vivien Didelot83dabd12016-08-31 11:50:04 -04002188 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2189 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002190
Vivien Didelot83dabd12016-08-31 11:50:04 -04002191 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2192 struct switchdev_obj_port_fdb *fdb;
2193
2194 if (!is_unicast_ether_addr(addr.mac))
2195 continue;
2196
2197 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002198 fdb->vid = vid;
2199 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002200 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2201 fdb->ndm_state = NUD_NOARP;
2202 else
2203 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002204 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2205 struct switchdev_obj_port_mdb *mdb;
2206
2207 if (!is_multicast_ether_addr(addr.mac))
2208 continue;
2209
2210 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2211 mdb->vid = vid;
2212 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002213 } else {
2214 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002215 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002216
2217 err = cb(obj);
2218 if (err)
2219 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002220 } while (!is_broadcast_ether_addr(addr.mac));
2221
2222 return err;
2223}
2224
Vivien Didelot83dabd12016-08-31 11:50:04 -04002225static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2226 struct switchdev_obj *obj,
2227 int (*cb)(struct switchdev_obj *obj))
2228{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002229 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002230 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2231 };
2232 u16 fid;
2233 int err;
2234
2235 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002236 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002237 if (err)
2238 return err;
2239
2240 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2241 if (err)
2242 return err;
2243
2244 /* Dump VLANs' Filtering Information Databases */
2245 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2246 if (err)
2247 return err;
2248
2249 do {
2250 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2251 if (err)
2252 return err;
2253
2254 if (!vlan.valid)
2255 break;
2256
2257 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2258 obj, cb);
2259 if (err)
2260 return err;
2261 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2262
2263 return err;
2264}
2265
Vivien Didelotf81ec902016-05-09 13:22:58 -04002266static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2267 struct switchdev_obj_port_fdb *fdb,
2268 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002269{
Vivien Didelot04bed142016-08-31 18:06:13 -04002270 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002271 int err;
2272
Vivien Didelotfad09c72016-06-21 12:28:20 -04002273 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002274 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002275 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002276
2277 return err;
2278}
2279
Vivien Didelotf81ec902016-05-09 13:22:58 -04002280static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
2281 struct net_device *bridge)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002282{
Vivien Didelot04bed142016-08-31 18:06:13 -04002283 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002284 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002285
Vivien Didelotfad09c72016-06-21 12:28:20 -04002286 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002287
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002288 /* Assign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002289 chip->ports[port].bridge_dev = bridge;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002290
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002291 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002292 if (chip->ports[i].bridge_dev == bridge) {
2293 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002294 if (err)
2295 break;
2296 }
2297 }
2298
Vivien Didelotfad09c72016-06-21 12:28:20 -04002299 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002300
Vivien Didelot466dfa02016-02-26 13:16:05 -05002301 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002302}
2303
Vivien Didelotf81ec902016-05-09 13:22:58 -04002304static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002305{
Vivien Didelot04bed142016-08-31 18:06:13 -04002306 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002307 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002308 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002309
Vivien Didelotfad09c72016-06-21 12:28:20 -04002310 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002311
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002312 /* Unassign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002313 chip->ports[port].bridge_dev = NULL;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002314
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002315 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002316 if (i == port || chip->ports[i].bridge_dev == bridge)
2317 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002318 netdev_warn(ds->ports[i].netdev,
2319 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002320
Vivien Didelotfad09c72016-06-21 12:28:20 -04002321 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002322}
2323
Vivien Didelotfad09c72016-06-21 12:28:20 -04002324static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002325{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002326 bool ppu_active = mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE);
Vivien Didelot552238b2016-05-09 13:22:49 -04002327 u16 is_reset = (ppu_active ? 0x8800 : 0xc800);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002328 struct gpio_desc *gpiod = chip->reset;
Vivien Didelot552238b2016-05-09 13:22:49 -04002329 unsigned long timeout;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002330 u16 reg;
Vivien Didelota935c052016-09-29 12:21:53 -04002331 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002332 int i;
2333
2334 /* Set all ports to the disabled state. */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002335 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelote28def332016-11-04 03:23:27 +01002336 err = mv88e6xxx_port_set_state(chip, i,
2337 PORT_CONTROL_STATE_DISABLED);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002338 if (err)
2339 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002340 }
2341
2342 /* Wait for transmit queues to drain. */
2343 usleep_range(2000, 4000);
2344
2345 /* If there is a gpio connected to the reset pin, toggle it */
2346 if (gpiod) {
2347 gpiod_set_value_cansleep(gpiod, 1);
2348 usleep_range(10000, 20000);
2349 gpiod_set_value_cansleep(gpiod, 0);
2350 usleep_range(10000, 20000);
2351 }
2352
2353 /* Reset the switch. Keep the PPU active if requested. The PPU
2354 * needs to be active to support indirect phy register access
2355 * through global registers 0x18 and 0x19.
2356 */
2357 if (ppu_active)
Vivien Didelota935c052016-09-29 12:21:53 -04002358 err = mv88e6xxx_g1_write(chip, 0x04, 0xc000);
Vivien Didelot552238b2016-05-09 13:22:49 -04002359 else
Vivien Didelota935c052016-09-29 12:21:53 -04002360 err = mv88e6xxx_g1_write(chip, 0x04, 0xc400);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002361 if (err)
2362 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002363
2364 /* Wait up to one second for reset to complete. */
2365 timeout = jiffies + 1 * HZ;
2366 while (time_before(jiffies, timeout)) {
Vivien Didelota935c052016-09-29 12:21:53 -04002367 err = mv88e6xxx_g1_read(chip, 0x00, &reg);
2368 if (err)
2369 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002370
Vivien Didelota935c052016-09-29 12:21:53 -04002371 if ((reg & is_reset) == is_reset)
Vivien Didelot552238b2016-05-09 13:22:49 -04002372 break;
2373 usleep_range(1000, 2000);
2374 }
2375 if (time_after(jiffies, timeout))
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002376 err = -ETIMEDOUT;
Vivien Didelot552238b2016-05-09 13:22:49 -04002377 else
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002378 err = 0;
Vivien Didelot552238b2016-05-09 13:22:49 -04002379
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002380 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002381}
2382
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002383static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002384{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002385 u16 val;
2386 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002387
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002388 /* Clear Power Down bit */
2389 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2390 if (err)
2391 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002392
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002393 if (val & BMCR_PDOWN) {
2394 val &= ~BMCR_PDOWN;
2395 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002396 }
2397
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002398 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002399}
2400
Vivien Didelotfad09c72016-06-21 12:28:20 -04002401static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002402{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002403 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002404 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002405 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002406
Vivien Didelotd78343d2016-11-04 03:23:36 +01002407 /* MAC Forcing register: don't force link, speed, duplex or flow control
2408 * state to any particular values on physical ports, but force the CPU
2409 * port and all DSA ports to their maximum bandwidth and full duplex.
2410 */
2411 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2412 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2413 SPEED_MAX, DUPLEX_FULL,
2414 PHY_INTERFACE_MODE_NA);
2415 else
2416 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2417 SPEED_UNFORCED, DUPLEX_UNFORCED,
2418 PHY_INTERFACE_MODE_NA);
2419 if (err)
2420 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002421
2422 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2423 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2424 * tunneling, determine priority by looking at 802.1p and IP
2425 * priority fields (IP prio has precedence), and set STP state
2426 * to Forwarding.
2427 *
2428 * If this is the CPU link, use DSA or EDSA tagging depending
2429 * on which tagging mode was configured.
2430 *
2431 * If this is a link to another switch, use DSA tagging mode.
2432 *
2433 * If this is the upstream port for this switch, enable
2434 * forwarding of unknown unicasts and multicasts.
2435 */
2436 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002437 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2438 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2439 mv88e6xxx_6095_family(chip) || mv88e6xxx_6065_family(chip) ||
2440 mv88e6xxx_6185_family(chip) || mv88e6xxx_6320_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002441 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
2442 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2443 PORT_CONTROL_STATE_FORWARDING;
2444 if (dsa_is_cpu_port(ds, port)) {
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002445 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA))
Andrew Lunn5377b802016-06-04 21:17:02 +02002446 reg |= PORT_CONTROL_FRAME_ETHER_TYPE_DSA |
Andrew Lunnc047a1f2015-09-29 01:50:56 +02002447 PORT_CONTROL_FORWARD_UNKNOWN_MC;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002448 else
2449 reg |= PORT_CONTROL_DSA_TAG;
Jamie Lentinf027e0c2016-08-22 16:01:04 +02002450 reg |= PORT_CONTROL_EGRESS_ADD_TAG |
2451 PORT_CONTROL_FORWARD_UNKNOWN;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002452 }
Andrew Lunn6083ce72015-08-17 23:52:52 +02002453 if (dsa_is_dsa_port(ds, port)) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002454 if (mv88e6xxx_6095_family(chip) ||
2455 mv88e6xxx_6185_family(chip))
Andrew Lunn6083ce72015-08-17 23:52:52 +02002456 reg |= PORT_CONTROL_DSA_TAG;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002457 if (mv88e6xxx_6352_family(chip) ||
2458 mv88e6xxx_6351_family(chip) ||
2459 mv88e6xxx_6165_family(chip) ||
2460 mv88e6xxx_6097_family(chip) ||
2461 mv88e6xxx_6320_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002462 reg |= PORT_CONTROL_FRAME_MODE_DSA;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002463 }
2464
Andrew Lunn54d792f2015-05-06 01:09:47 +02002465 if (port == dsa_upstream_port(ds))
2466 reg |= PORT_CONTROL_FORWARD_UNKNOWN |
2467 PORT_CONTROL_FORWARD_UNKNOWN_MC;
2468 }
2469 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002470 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2471 if (err)
2472 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002473 }
2474
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002475 /* If this port is connected to a SerDes, make sure the SerDes is not
2476 * powered down.
2477 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002478 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002479 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2480 if (err)
2481 return err;
2482 reg &= PORT_STATUS_CMODE_MASK;
2483 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2484 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2485 (reg == PORT_STATUS_CMODE_SGMII)) {
2486 err = mv88e6xxx_serdes_power_on(chip);
2487 if (err < 0)
2488 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002489 }
2490 }
2491
Vivien Didelot8efdda42015-08-13 12:52:23 -04002492 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002493 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002494 * untagged frames on this port, do a destination address lookup on all
2495 * received packets as usual, disable ARP mirroring and don't send a
2496 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002497 */
2498 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002499 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2500 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2501 mv88e6xxx_6095_family(chip) || mv88e6xxx_6320_family(chip) ||
2502 mv88e6xxx_6185_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002503 reg = PORT_CONTROL_2_MAP_DA;
2504
Vivien Didelotfad09c72016-06-21 12:28:20 -04002505 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2506 mv88e6xxx_6165_family(chip) || mv88e6xxx_6320_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002507 reg |= PORT_CONTROL_2_JUMBO_10240;
2508
Vivien Didelotfad09c72016-06-21 12:28:20 -04002509 if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002510 /* Set the upstream port this port should use */
2511 reg |= dsa_upstream_port(ds);
2512 /* enable forwarding of unknown multicast addresses to
2513 * the upstream port
2514 */
2515 if (port == dsa_upstream_port(ds))
2516 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
2517 }
2518
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002519 reg |= PORT_CONTROL_2_8021Q_DISABLED;
Vivien Didelot8efdda42015-08-13 12:52:23 -04002520
Andrew Lunn54d792f2015-05-06 01:09:47 +02002521 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002522 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
2523 if (err)
2524 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002525 }
2526
2527 /* Port Association Vector: when learning source addresses
2528 * of packets, add the address to the address database using
2529 * a port bitmap that has only the bit for this port set and
2530 * the other bits clear.
2531 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002532 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002533 /* Disable learning for CPU port */
2534 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002535 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002536
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002537 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2538 if (err)
2539 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002540
2541 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002542 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2543 if (err)
2544 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002545
Vivien Didelotfad09c72016-06-21 12:28:20 -04002546 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2547 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2548 mv88e6xxx_6320_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002549 /* Do not limit the period of time that this port can
2550 * be paused for by the remote end or the period of
2551 * time that this port can pause the remote end.
2552 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002553 err = mv88e6xxx_port_write(chip, port, PORT_PAUSE_CTRL, 0x0000);
2554 if (err)
2555 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002556
2557 /* Port ATU control: disable limiting the number of
2558 * address database entries that this port is allowed
2559 * to use.
2560 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002561 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2562 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002563 /* Priority Override: disable DA, SA and VTU priority
2564 * override.
2565 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002566 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2567 0x0000);
2568 if (err)
2569 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002570
2571 /* Port Ethertype: use the Ethertype DSA Ethertype
2572 * value.
2573 */
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002574 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002575 err = mv88e6xxx_port_write(chip, port, PORT_ETH_TYPE,
2576 ETH_P_EDSA);
2577 if (err)
2578 return err;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002579 }
2580
Andrew Lunn54d792f2015-05-06 01:09:47 +02002581 /* Tag Remap: use an identity 802.1p prio -> switch
2582 * prio mapping.
2583 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002584 err = mv88e6xxx_port_write(chip, port, PORT_TAG_REGMAP_0123,
2585 0x3210);
2586 if (err)
2587 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002588
2589 /* Tag Remap 2: use an identity 802.1p prio -> switch
2590 * prio mapping.
2591 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002592 err = mv88e6xxx_port_write(chip, port, PORT_TAG_REGMAP_4567,
2593 0x7654);
2594 if (err)
2595 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002596 }
2597
Jamie Lentin1bc261f2016-08-22 22:47:08 +01002598 /* Rate Control: disable ingress rate limiting. */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002599 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2600 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
Vivien Didelotfad09c72016-06-21 12:28:20 -04002601 mv88e6xxx_6320_family(chip)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002602 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL,
2603 0x0001);
2604 if (err)
2605 return err;
Jamie Lentin1bc261f2016-08-22 22:47:08 +01002606 } else if (mv88e6xxx_6185_family(chip) || mv88e6xxx_6095_family(chip)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002607 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL,
2608 0x0000);
2609 if (err)
2610 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002611 }
2612
Guenter Roeck366f0a02015-03-26 18:36:30 -07002613 /* Port Control 1: disable trunking, disable sending
2614 * learning messages to this port.
Guenter Roeckd827e882015-03-26 18:36:29 -07002615 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002616 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_1, 0x0000);
2617 if (err)
2618 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002619
Vivien Didelot207afda2016-04-14 14:42:09 -04002620 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002621 * database, and allow bidirectional communication between the
2622 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002623 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002624 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002625 if (err)
2626 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002627
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002628 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2629 if (err)
2630 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002631
2632 /* Default VLAN ID and priority: don't set a default VLAN
2633 * ID, and set the default packet priority to zero.
2634 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002635 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002636}
2637
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002638static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002639{
2640 int err;
2641
Vivien Didelota935c052016-09-29 12:21:53 -04002642 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002643 if (err)
2644 return err;
2645
Vivien Didelota935c052016-09-29 12:21:53 -04002646 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002647 if (err)
2648 return err;
2649
Vivien Didelota935c052016-09-29 12:21:53 -04002650 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2651 if (err)
2652 return err;
2653
2654 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002655}
2656
Vivien Didelotacddbd22016-07-18 20:45:39 -04002657static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
2658 unsigned int msecs)
2659{
2660 const unsigned int coeff = chip->info->age_time_coeff;
2661 const unsigned int min = 0x01 * coeff;
2662 const unsigned int max = 0xff * coeff;
2663 u8 age_time;
2664 u16 val;
2665 int err;
2666
2667 if (msecs < min || msecs > max)
2668 return -ERANGE;
2669
2670 /* Round to nearest multiple of coeff */
2671 age_time = (msecs + coeff / 2) / coeff;
2672
Vivien Didelota935c052016-09-29 12:21:53 -04002673 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002674 if (err)
2675 return err;
2676
2677 /* AgeTime is 11:4 bits */
2678 val &= ~0xff0;
2679 val |= age_time << 4;
2680
Vivien Didelota935c052016-09-29 12:21:53 -04002681 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002682}
2683
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002684static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2685 unsigned int ageing_time)
2686{
Vivien Didelot04bed142016-08-31 18:06:13 -04002687 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002688 int err;
2689
2690 mutex_lock(&chip->reg_lock);
2691 err = mv88e6xxx_g1_set_age_time(chip, ageing_time);
2692 mutex_unlock(&chip->reg_lock);
2693
2694 return err;
2695}
2696
Vivien Didelot97299342016-07-18 20:45:30 -04002697static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002698{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002699 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002700 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot119477b2016-05-09 13:22:51 -04002701 u16 reg;
Vivien Didelot08a01262016-05-09 13:22:50 -04002702 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002703
Vivien Didelot119477b2016-05-09 13:22:51 -04002704 /* Enable the PHY Polling Unit if present, don't discard any packets,
2705 * and mask all interrupt sources.
2706 */
Andrew Lunndc30c352016-10-16 19:56:49 +02002707 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
2708 if (err < 0)
2709 return err;
2710
2711 reg &= ~GLOBAL_CONTROL_PPU_ENABLE;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002712 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU) ||
2713 mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE))
Vivien Didelot119477b2016-05-09 13:22:51 -04002714 reg |= GLOBAL_CONTROL_PPU_ENABLE;
2715
Vivien Didelota935c052016-09-29 12:21:53 -04002716 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
Vivien Didelot119477b2016-05-09 13:22:51 -04002717 if (err)
2718 return err;
2719
Vivien Didelotb0745e872016-05-09 13:22:53 -04002720 /* Configure the upstream port, and configure it as the port to which
2721 * ingress and egress and ARP monitor frames are to be sent.
2722 */
2723 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
2724 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
2725 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
Vivien Didelota935c052016-09-29 12:21:53 -04002726 err = mv88e6xxx_g1_write(chip, GLOBAL_MONITOR_CONTROL, reg);
Vivien Didelotb0745e872016-05-09 13:22:53 -04002727 if (err)
2728 return err;
2729
Vivien Didelot50484ff2016-05-09 13:22:54 -04002730 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002731 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2732 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2733 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002734 if (err)
2735 return err;
2736
Vivien Didelotacddbd22016-07-18 20:45:39 -04002737 /* Clear all the VTU and STU entries */
2738 err = _mv88e6xxx_vtu_stu_flush(chip);
2739 if (err < 0)
2740 return err;
2741
Vivien Didelot08a01262016-05-09 13:22:50 -04002742 /* Set the default address aging time to 5 minutes, and
2743 * enable address learn messages to be sent to all message
2744 * ports.
2745 */
Vivien Didelota935c052016-09-29 12:21:53 -04002746 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2747 GLOBAL_ATU_CONTROL_LEARN2ALL);
Vivien Didelot08a01262016-05-09 13:22:50 -04002748 if (err)
2749 return err;
2750
Vivien Didelotacddbd22016-07-18 20:45:39 -04002751 err = mv88e6xxx_g1_set_age_time(chip, 300000);
2752 if (err)
Vivien Didelot97299342016-07-18 20:45:30 -04002753 return err;
2754
2755 /* Clear all ATU entries */
2756 err = _mv88e6xxx_atu_flush(chip, 0, true);
2757 if (err)
2758 return err;
2759
Vivien Didelot08a01262016-05-09 13:22:50 -04002760 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002761 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002762 if (err)
2763 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002764 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002765 if (err)
2766 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002767 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002768 if (err)
2769 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002770 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002771 if (err)
2772 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002773 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002774 if (err)
2775 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002776 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002777 if (err)
2778 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002779 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002780 if (err)
2781 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002782 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002783 if (err)
2784 return err;
2785
2786 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002787 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002788 if (err)
2789 return err;
2790
Vivien Didelot97299342016-07-18 20:45:30 -04002791 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002792 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2793 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002794 if (err)
2795 return err;
2796
2797 /* Wait for the flush to complete. */
2798 err = _mv88e6xxx_stats_wait(chip);
2799 if (err)
2800 return err;
2801
2802 return 0;
2803}
2804
Vivien Didelotf81ec902016-05-09 13:22:58 -04002805static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002806{
Vivien Didelot04bed142016-08-31 18:06:13 -04002807 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002808 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002809 int i;
2810
Vivien Didelotfad09c72016-06-21 12:28:20 -04002811 chip->ds = ds;
2812 ds->slave_mii_bus = chip->mdio_bus;
Vivien Didelot552238b2016-05-09 13:22:49 -04002813
Vivien Didelotfad09c72016-06-21 12:28:20 -04002814 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002815
Vivien Didelot97299342016-07-18 20:45:30 -04002816 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002817 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002818 err = mv88e6xxx_setup_port(chip, i);
2819 if (err)
2820 goto unlock;
2821 }
2822
2823 /* Setup Switch Global 1 Registers */
2824 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002825 if (err)
2826 goto unlock;
2827
Vivien Didelot97299342016-07-18 20:45:30 -04002828 /* Setup Switch Global 2 Registers */
2829 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2830 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002831 if (err)
2832 goto unlock;
2833 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002834
Vivien Didelot6b17e862015-08-13 12:52:18 -04002835unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002836 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002837
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002838 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002839}
2840
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002841static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2842{
Vivien Didelot04bed142016-08-31 18:06:13 -04002843 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002844 int err;
2845
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002846 if (!chip->info->ops->set_switch_mac)
2847 return -EOPNOTSUPP;
2848
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002849 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002850 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002851 mutex_unlock(&chip->reg_lock);
2852
2853 return err;
2854}
2855
Vivien Didelote57e5e72016-08-15 17:19:00 -04002856static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002857{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002858 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002859 u16 val;
2860 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002861
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002862 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002863 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002864
Vivien Didelotfad09c72016-06-21 12:28:20 -04002865 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002866 err = mv88e6xxx_phy_read(chip, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002867 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002868
2869 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002870}
2871
Vivien Didelote57e5e72016-08-15 17:19:00 -04002872static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002873{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002874 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002875 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002876
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002877 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002878 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002879
Vivien Didelotfad09c72016-06-21 12:28:20 -04002880 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002881 err = mv88e6xxx_phy_write(chip, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002882 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002883
2884 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002885}
2886
Vivien Didelotfad09c72016-06-21 12:28:20 -04002887static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunnb516d452016-06-04 21:17:06 +02002888 struct device_node *np)
2889{
2890 static int index;
2891 struct mii_bus *bus;
2892 int err;
2893
Andrew Lunnb516d452016-06-04 21:17:06 +02002894 if (np)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002895 chip->mdio_np = of_get_child_by_name(np, "mdio");
Andrew Lunnb516d452016-06-04 21:17:06 +02002896
Vivien Didelotfad09c72016-06-21 12:28:20 -04002897 bus = devm_mdiobus_alloc(chip->dev);
Andrew Lunnb516d452016-06-04 21:17:06 +02002898 if (!bus)
2899 return -ENOMEM;
2900
Vivien Didelotfad09c72016-06-21 12:28:20 -04002901 bus->priv = (void *)chip;
Andrew Lunnb516d452016-06-04 21:17:06 +02002902 if (np) {
2903 bus->name = np->full_name;
2904 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2905 } else {
2906 bus->name = "mv88e6xxx SMI";
2907 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2908 }
2909
2910 bus->read = mv88e6xxx_mdio_read;
2911 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002912 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002913
Vivien Didelotfad09c72016-06-21 12:28:20 -04002914 if (chip->mdio_np)
2915 err = of_mdiobus_register(bus, chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002916 else
2917 err = mdiobus_register(bus);
2918 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002919 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunnb516d452016-06-04 21:17:06 +02002920 goto out;
2921 }
Vivien Didelotfad09c72016-06-21 12:28:20 -04002922 chip->mdio_bus = bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002923
2924 return 0;
2925
2926out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002927 if (chip->mdio_np)
2928 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002929
2930 return err;
2931}
2932
Vivien Didelotfad09c72016-06-21 12:28:20 -04002933static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002934
2935{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002936 struct mii_bus *bus = chip->mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002937
2938 mdiobus_unregister(bus);
2939
Vivien Didelotfad09c72016-06-21 12:28:20 -04002940 if (chip->mdio_np)
2941 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002942}
2943
Guenter Roeckc22995c2015-07-25 09:42:28 -07002944#ifdef CONFIG_NET_DSA_HWMON
2945
2946static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp)
2947{
Vivien Didelot04bed142016-08-31 18:06:13 -04002948 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04002949 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07002950 int ret;
Guenter Roeckc22995c2015-07-25 09:42:28 -07002951
2952 *temp = 0;
2953
Vivien Didelotfad09c72016-06-21 12:28:20 -04002954 mutex_lock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07002955
Vivien Didelot9c938292016-08-15 17:19:02 -04002956 ret = mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x6);
Guenter Roeckc22995c2015-07-25 09:42:28 -07002957 if (ret < 0)
2958 goto error;
2959
2960 /* Enable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04002961 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
Guenter Roeckc22995c2015-07-25 09:42:28 -07002962 if (ret < 0)
2963 goto error;
2964
Vivien Didelot9c938292016-08-15 17:19:02 -04002965 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val | (1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07002966 if (ret < 0)
2967 goto error;
2968
2969 /* Wait for temperature to stabilize */
2970 usleep_range(10000, 12000);
2971
Vivien Didelot9c938292016-08-15 17:19:02 -04002972 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
2973 if (ret < 0)
Guenter Roeckc22995c2015-07-25 09:42:28 -07002974 goto error;
Guenter Roeckc22995c2015-07-25 09:42:28 -07002975
2976 /* Disable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04002977 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val & ~(1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07002978 if (ret < 0)
2979 goto error;
2980
2981 *temp = ((val & 0x1f) - 5) * 5;
2982
2983error:
Vivien Didelot9c938292016-08-15 17:19:02 -04002984 mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x0);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002985 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07002986 return ret;
2987}
2988
2989static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp)
2990{
Vivien Didelot04bed142016-08-31 18:06:13 -04002991 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002992 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04002993 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07002994 int ret;
2995
2996 *temp = 0;
2997
Vivien Didelot9c938292016-08-15 17:19:02 -04002998 mutex_lock(&chip->reg_lock);
2999 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 27, &val);
3000 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003001 if (ret < 0)
3002 return ret;
3003
Vivien Didelot9c938292016-08-15 17:19:02 -04003004 *temp = (val & 0xff) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003005
3006 return 0;
3007}
3008
Vivien Didelotf81ec902016-05-09 13:22:58 -04003009static int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003010{
Vivien Didelot04bed142016-08-31 18:06:13 -04003011 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn158bc062016-04-28 21:24:06 -04003012
Vivien Didelotfad09c72016-06-21 12:28:20 -04003013 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP))
Vivien Didelot6594f612016-05-09 13:22:42 -04003014 return -EOPNOTSUPP;
3015
Vivien Didelotfad09c72016-06-21 12:28:20 -04003016 if (mv88e6xxx_6320_family(chip) || mv88e6xxx_6352_family(chip))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003017 return mv88e63xx_get_temp(ds, temp);
3018
3019 return mv88e61xx_get_temp(ds, temp);
3020}
3021
Vivien Didelotf81ec902016-05-09 13:22:58 -04003022static int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003023{
Vivien Didelot04bed142016-08-31 18:06:13 -04003024 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003025 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003026 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003027 int ret;
3028
Vivien Didelotfad09c72016-06-21 12:28:20 -04003029 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003030 return -EOPNOTSUPP;
3031
3032 *temp = 0;
3033
Vivien Didelot9c938292016-08-15 17:19:02 -04003034 mutex_lock(&chip->reg_lock);
3035 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3036 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003037 if (ret < 0)
3038 return ret;
3039
Vivien Didelot9c938292016-08-15 17:19:02 -04003040 *temp = (((val >> 8) & 0x1f) * 5) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003041
3042 return 0;
3043}
3044
Vivien Didelotf81ec902016-05-09 13:22:58 -04003045static int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003046{
Vivien Didelot04bed142016-08-31 18:06:13 -04003047 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003048 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003049 u16 val;
3050 int err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003051
Vivien Didelotfad09c72016-06-21 12:28:20 -04003052 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003053 return -EOPNOTSUPP;
3054
Vivien Didelot9c938292016-08-15 17:19:02 -04003055 mutex_lock(&chip->reg_lock);
3056 err = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3057 if (err)
3058 goto unlock;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003059 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
Vivien Didelot9c938292016-08-15 17:19:02 -04003060 err = mv88e6xxx_phy_page_write(chip, phy, 6, 26,
3061 (val & 0xe0ff) | (temp << 8));
3062unlock:
3063 mutex_unlock(&chip->reg_lock);
3064
3065 return err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003066}
3067
Vivien Didelotf81ec902016-05-09 13:22:58 -04003068static int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003069{
Vivien Didelot04bed142016-08-31 18:06:13 -04003070 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003071 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003072 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003073 int ret;
3074
Vivien Didelotfad09c72016-06-21 12:28:20 -04003075 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003076 return -EOPNOTSUPP;
3077
3078 *alarm = false;
3079
Vivien Didelot9c938292016-08-15 17:19:02 -04003080 mutex_lock(&chip->reg_lock);
3081 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3082 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003083 if (ret < 0)
3084 return ret;
3085
Vivien Didelot9c938292016-08-15 17:19:02 -04003086 *alarm = !!(val & 0x40);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003087
3088 return 0;
3089}
3090#endif /* CONFIG_NET_DSA_HWMON */
3091
Vivien Didelot855b1932016-07-20 18:18:35 -04003092static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3093{
Vivien Didelot04bed142016-08-31 18:06:13 -04003094 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003095
3096 return chip->eeprom_len;
3097}
3098
Vivien Didelot855b1932016-07-20 18:18:35 -04003099static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3100 struct ethtool_eeprom *eeprom, u8 *data)
3101{
Vivien Didelot04bed142016-08-31 18:06:13 -04003102 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003103 int err;
3104
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003105 if (!chip->info->ops->get_eeprom)
3106 return -EOPNOTSUPP;
3107
Vivien Didelot855b1932016-07-20 18:18:35 -04003108 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003109 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003110 mutex_unlock(&chip->reg_lock);
3111
3112 if (err)
3113 return err;
3114
3115 eeprom->magic = 0xc3ec4951;
3116
3117 return 0;
3118}
3119
Vivien Didelot855b1932016-07-20 18:18:35 -04003120static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3121 struct ethtool_eeprom *eeprom, u8 *data)
3122{
Vivien Didelot04bed142016-08-31 18:06:13 -04003123 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003124 int err;
3125
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003126 if (!chip->info->ops->set_eeprom)
3127 return -EOPNOTSUPP;
3128
Vivien Didelot855b1932016-07-20 18:18:35 -04003129 if (eeprom->magic != 0xc3ec4951)
3130 return -EINVAL;
3131
3132 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003133 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003134 mutex_unlock(&chip->reg_lock);
3135
3136 return err;
3137}
3138
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003139static const struct mv88e6xxx_ops mv88e6085_ops = {
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003140 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003141 .phy_read = mv88e6xxx_phy_ppu_read,
3142 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003143 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003144 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003145 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003146};
3147
3148static const struct mv88e6xxx_ops mv88e6095_ops = {
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003149 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003150 .phy_read = mv88e6xxx_phy_ppu_read,
3151 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003152 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003153 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003154 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003155};
3156
3157static const struct mv88e6xxx_ops mv88e6123_ops = {
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003158 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003159 .phy_read = mv88e6xxx_read,
3160 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003161 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003162 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003163 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003164};
3165
3166static const struct mv88e6xxx_ops mv88e6131_ops = {
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003167 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003168 .phy_read = mv88e6xxx_phy_ppu_read,
3169 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003170 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003171 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003172 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003173};
3174
3175static const struct mv88e6xxx_ops mv88e6161_ops = {
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003176 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003177 .phy_read = mv88e6xxx_read,
3178 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003179 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003180 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003181 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003182};
3183
3184static const struct mv88e6xxx_ops mv88e6165_ops = {
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003185 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003186 .phy_read = mv88e6xxx_read,
3187 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003188 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003189 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003190 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003191};
3192
3193static const struct mv88e6xxx_ops mv88e6171_ops = {
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003194 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003195 .phy_read = mv88e6xxx_g2_smi_phy_read,
3196 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003197 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003198 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003199 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003200 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003201};
3202
3203static const struct mv88e6xxx_ops mv88e6172_ops = {
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003204 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3205 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003206 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003207 .phy_read = mv88e6xxx_g2_smi_phy_read,
3208 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003209 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003210 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003211 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003212 .port_set_speed = mv88e6352_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003213};
3214
3215static const struct mv88e6xxx_ops mv88e6175_ops = {
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003216 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003217 .phy_read = mv88e6xxx_g2_smi_phy_read,
3218 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003219 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003220 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003221 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003222 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003223};
3224
3225static const struct mv88e6xxx_ops mv88e6176_ops = {
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003226 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3227 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003228 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003229 .phy_read = mv88e6xxx_g2_smi_phy_read,
3230 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003231 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003232 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003233 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003234 .port_set_speed = mv88e6352_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003235};
3236
3237static const struct mv88e6xxx_ops mv88e6185_ops = {
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003238 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003239 .phy_read = mv88e6xxx_phy_ppu_read,
3240 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003241 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003242 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003243 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003244};
3245
3246static const struct mv88e6xxx_ops mv88e6240_ops = {
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003247 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3248 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003249 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003250 .phy_read = mv88e6xxx_g2_smi_phy_read,
3251 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003252 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003253 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003254 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003255 .port_set_speed = mv88e6352_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003256};
3257
3258static const struct mv88e6xxx_ops mv88e6320_ops = {
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003259 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3260 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003261 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003262 .phy_read = mv88e6xxx_g2_smi_phy_read,
3263 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003264 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003265 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003266 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003267};
3268
3269static const struct mv88e6xxx_ops mv88e6321_ops = {
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003270 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3271 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003272 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003273 .phy_read = mv88e6xxx_g2_smi_phy_read,
3274 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003275 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003276 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003277 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003278};
3279
3280static const struct mv88e6xxx_ops mv88e6350_ops = {
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003281 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003282 .phy_read = mv88e6xxx_g2_smi_phy_read,
3283 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003284 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003285 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003286 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003287 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003288};
3289
3290static const struct mv88e6xxx_ops mv88e6351_ops = {
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003291 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003292 .phy_read = mv88e6xxx_g2_smi_phy_read,
3293 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003294 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003295 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003296 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003297 .port_set_speed = mv88e6185_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003298};
3299
3300static const struct mv88e6xxx_ops mv88e6352_ops = {
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003301 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3302 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003303 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003304 .phy_read = mv88e6xxx_g2_smi_phy_read,
3305 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003306 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003307 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003308 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003309 .port_set_speed = mv88e6352_port_set_speed,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003310};
3311
Vivien Didelotf81ec902016-05-09 13:22:58 -04003312static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3313 [MV88E6085] = {
3314 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3315 .family = MV88E6XXX_FAMILY_6097,
3316 .name = "Marvell 88E6085",
3317 .num_databases = 4096,
3318 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003319 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003320 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003321 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003322 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003323 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003324 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003325 },
3326
3327 [MV88E6095] = {
3328 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3329 .family = MV88E6XXX_FAMILY_6095,
3330 .name = "Marvell 88E6095/88E6095F",
3331 .num_databases = 256,
3332 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003333 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003334 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003335 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003336 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003337 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003338 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003339 },
3340
3341 [MV88E6123] = {
3342 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3343 .family = MV88E6XXX_FAMILY_6165,
3344 .name = "Marvell 88E6123",
3345 .num_databases = 4096,
3346 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003347 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003348 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003349 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003350 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003351 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003352 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003353 },
3354
3355 [MV88E6131] = {
3356 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3357 .family = MV88E6XXX_FAMILY_6185,
3358 .name = "Marvell 88E6131",
3359 .num_databases = 256,
3360 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003361 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003362 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003363 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003364 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003365 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003366 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003367 },
3368
3369 [MV88E6161] = {
3370 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3371 .family = MV88E6XXX_FAMILY_6165,
3372 .name = "Marvell 88E6161",
3373 .num_databases = 4096,
3374 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003375 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003376 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003377 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003378 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003379 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003380 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003381 },
3382
3383 [MV88E6165] = {
3384 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3385 .family = MV88E6XXX_FAMILY_6165,
3386 .name = "Marvell 88E6165",
3387 .num_databases = 4096,
3388 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003389 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003390 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003391 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003392 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003393 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003394 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003395 },
3396
3397 [MV88E6171] = {
3398 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3399 .family = MV88E6XXX_FAMILY_6351,
3400 .name = "Marvell 88E6171",
3401 .num_databases = 4096,
3402 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003403 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003404 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003405 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003406 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003407 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003408 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003409 },
3410
3411 [MV88E6172] = {
3412 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3413 .family = MV88E6XXX_FAMILY_6352,
3414 .name = "Marvell 88E6172",
3415 .num_databases = 4096,
3416 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003417 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003418 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003419 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003420 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003421 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003422 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003423 },
3424
3425 [MV88E6175] = {
3426 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3427 .family = MV88E6XXX_FAMILY_6351,
3428 .name = "Marvell 88E6175",
3429 .num_databases = 4096,
3430 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003431 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003432 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003433 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003434 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003435 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003436 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003437 },
3438
3439 [MV88E6176] = {
3440 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3441 .family = MV88E6XXX_FAMILY_6352,
3442 .name = "Marvell 88E6176",
3443 .num_databases = 4096,
3444 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003445 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003446 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003447 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003448 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003449 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003450 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003451 },
3452
3453 [MV88E6185] = {
3454 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3455 .family = MV88E6XXX_FAMILY_6185,
3456 .name = "Marvell 88E6185",
3457 .num_databases = 256,
3458 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003459 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003460 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003461 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003462 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003463 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003464 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003465 },
3466
3467 [MV88E6240] = {
3468 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3469 .family = MV88E6XXX_FAMILY_6352,
3470 .name = "Marvell 88E6240",
3471 .num_databases = 4096,
3472 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003473 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003474 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003475 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003476 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003477 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003478 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003479 },
3480
3481 [MV88E6320] = {
3482 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3483 .family = MV88E6XXX_FAMILY_6320,
3484 .name = "Marvell 88E6320",
3485 .num_databases = 4096,
3486 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003487 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003488 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003489 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003490 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003491 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003492 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003493 },
3494
3495 [MV88E6321] = {
3496 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3497 .family = MV88E6XXX_FAMILY_6320,
3498 .name = "Marvell 88E6321",
3499 .num_databases = 4096,
3500 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003501 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003502 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003503 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003504 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003505 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003506 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003507 },
3508
3509 [MV88E6350] = {
3510 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3511 .family = MV88E6XXX_FAMILY_6351,
3512 .name = "Marvell 88E6350",
3513 .num_databases = 4096,
3514 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003515 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003516 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003517 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003518 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003519 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003520 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003521 },
3522
3523 [MV88E6351] = {
3524 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3525 .family = MV88E6XXX_FAMILY_6351,
3526 .name = "Marvell 88E6351",
3527 .num_databases = 4096,
3528 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003529 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003530 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003531 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003532 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003533 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003534 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003535 },
3536
3537 [MV88E6352] = {
3538 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
3539 .family = MV88E6XXX_FAMILY_6352,
3540 .name = "Marvell 88E6352",
3541 .num_databases = 4096,
3542 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003543 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003544 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003545 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003546 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003547 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003548 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003549 },
3550};
3551
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003552static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003553{
Vivien Didelota439c062016-04-17 13:23:58 -04003554 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003555
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003556 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3557 if (mv88e6xxx_table[i].prod_num == prod_num)
3558 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003559
Vivien Didelotb9b37712015-10-30 19:39:48 -04003560 return NULL;
3561}
3562
Vivien Didelotfad09c72016-06-21 12:28:20 -04003563static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003564{
3565 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003566 unsigned int prod_num, rev;
3567 u16 id;
3568 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003569
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003570 mutex_lock(&chip->reg_lock);
3571 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
3572 mutex_unlock(&chip->reg_lock);
3573 if (err)
3574 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003575
3576 prod_num = (id & 0xfff0) >> 4;
3577 rev = id & 0x000f;
3578
3579 info = mv88e6xxx_lookup_info(prod_num);
3580 if (!info)
3581 return -ENODEV;
3582
Vivien Didelotcaac8542016-06-20 13:14:09 -04003583 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003584 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003585
Vivien Didelotca070c12016-09-02 14:45:34 -04003586 err = mv88e6xxx_g2_require(chip);
3587 if (err)
3588 return err;
3589
Vivien Didelotfad09c72016-06-21 12:28:20 -04003590 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3591 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003592
3593 return 0;
3594}
3595
Vivien Didelotfad09c72016-06-21 12:28:20 -04003596static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003597{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003598 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003599
Vivien Didelotfad09c72016-06-21 12:28:20 -04003600 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3601 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003602 return NULL;
3603
Vivien Didelotfad09c72016-06-21 12:28:20 -04003604 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003605
Vivien Didelotfad09c72016-06-21 12:28:20 -04003606 mutex_init(&chip->reg_lock);
Vivien Didelot469d7292016-06-20 13:14:06 -04003607
Vivien Didelotfad09c72016-06-21 12:28:20 -04003608 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003609}
3610
Vivien Didelote57e5e72016-08-15 17:19:00 -04003611static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
3612{
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003613 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
Vivien Didelote57e5e72016-08-15 17:19:00 -04003614 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003615}
3616
Andrew Lunn930188c2016-08-22 16:01:03 +02003617static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
3618{
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003619 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
Andrew Lunn930188c2016-08-22 16:01:03 +02003620 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02003621}
3622
Vivien Didelotfad09c72016-06-21 12:28:20 -04003623static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003624 struct mii_bus *bus, int sw_addr)
3625{
3626 /* ADDR[0] pin is unavailable externally and considered zero */
3627 if (sw_addr & 0x1)
3628 return -EINVAL;
3629
Vivien Didelot914b32f2016-06-20 13:14:11 -04003630 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003631 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04003632 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003633 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003634 else
3635 return -EINVAL;
3636
Vivien Didelotfad09c72016-06-21 12:28:20 -04003637 chip->bus = bus;
3638 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003639
3640 return 0;
3641}
3642
Andrew Lunn7b314362016-08-22 16:01:01 +02003643static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
3644{
Vivien Didelot04bed142016-08-31 18:06:13 -04003645 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003646
3647 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA))
3648 return DSA_TAG_PROTO_EDSA;
3649
3650 return DSA_TAG_PROTO_DSA;
Andrew Lunn7b314362016-08-22 16:01:01 +02003651}
3652
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003653static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3654 struct device *host_dev, int sw_addr,
3655 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003656{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003657 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003658 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003659 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003660
Vivien Didelota439c062016-04-17 13:23:58 -04003661 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003662 if (!bus)
3663 return NULL;
3664
Vivien Didelotfad09c72016-06-21 12:28:20 -04003665 chip = mv88e6xxx_alloc_chip(dsa_dev);
3666 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003667 return NULL;
3668
Vivien Didelotcaac8542016-06-20 13:14:09 -04003669 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003670 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003671
Vivien Didelotfad09c72016-06-21 12:28:20 -04003672 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003673 if (err)
3674 goto free;
3675
Vivien Didelotfad09c72016-06-21 12:28:20 -04003676 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003677 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003678 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04003679
Andrew Lunndc30c352016-10-16 19:56:49 +02003680 mutex_lock(&chip->reg_lock);
3681 err = mv88e6xxx_switch_reset(chip);
3682 mutex_unlock(&chip->reg_lock);
3683 if (err)
3684 goto free;
3685
Vivien Didelote57e5e72016-08-15 17:19:00 -04003686 mv88e6xxx_phy_init(chip);
3687
Vivien Didelotfad09c72016-06-21 12:28:20 -04003688 err = mv88e6xxx_mdio_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02003689 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04003690 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02003691
Vivien Didelotfad09c72016-06-21 12:28:20 -04003692 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003693
Vivien Didelotfad09c72016-06-21 12:28:20 -04003694 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04003695free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04003696 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04003697
3698 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003699}
3700
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003701static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3702 const struct switchdev_obj_port_mdb *mdb,
3703 struct switchdev_trans *trans)
3704{
3705 /* We don't need any dynamic resource from the kernel (yet),
3706 * so skip the prepare phase.
3707 */
3708
3709 return 0;
3710}
3711
3712static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
3713 const struct switchdev_obj_port_mdb *mdb,
3714 struct switchdev_trans *trans)
3715{
Vivien Didelot04bed142016-08-31 18:06:13 -04003716 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003717
3718 mutex_lock(&chip->reg_lock);
3719 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3720 GLOBAL_ATU_DATA_STATE_MC_STATIC))
3721 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
3722 mutex_unlock(&chip->reg_lock);
3723}
3724
3725static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
3726 const struct switchdev_obj_port_mdb *mdb)
3727{
Vivien Didelot04bed142016-08-31 18:06:13 -04003728 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003729 int err;
3730
3731 mutex_lock(&chip->reg_lock);
3732 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3733 GLOBAL_ATU_DATA_STATE_UNUSED);
3734 mutex_unlock(&chip->reg_lock);
3735
3736 return err;
3737}
3738
3739static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
3740 struct switchdev_obj_port_mdb *mdb,
3741 int (*cb)(struct switchdev_obj *obj))
3742{
Vivien Didelot04bed142016-08-31 18:06:13 -04003743 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003744 int err;
3745
3746 mutex_lock(&chip->reg_lock);
3747 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
3748 mutex_unlock(&chip->reg_lock);
3749
3750 return err;
3751}
3752
Vivien Didelot9d490b42016-08-23 12:38:56 -04003753static struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003754 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02003755 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003756 .setup = mv88e6xxx_setup,
3757 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003758 .adjust_link = mv88e6xxx_adjust_link,
3759 .get_strings = mv88e6xxx_get_strings,
3760 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
3761 .get_sset_count = mv88e6xxx_get_sset_count,
3762 .set_eee = mv88e6xxx_set_eee,
3763 .get_eee = mv88e6xxx_get_eee,
3764#ifdef CONFIG_NET_DSA_HWMON
3765 .get_temp = mv88e6xxx_get_temp,
3766 .get_temp_limit = mv88e6xxx_get_temp_limit,
3767 .set_temp_limit = mv88e6xxx_set_temp_limit,
3768 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
3769#endif
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003770 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003771 .get_eeprom = mv88e6xxx_get_eeprom,
3772 .set_eeprom = mv88e6xxx_set_eeprom,
3773 .get_regs_len = mv88e6xxx_get_regs_len,
3774 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04003775 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003776 .port_bridge_join = mv88e6xxx_port_bridge_join,
3777 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
3778 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04003779 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003780 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
3781 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
3782 .port_vlan_add = mv88e6xxx_port_vlan_add,
3783 .port_vlan_del = mv88e6xxx_port_vlan_del,
3784 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
3785 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
3786 .port_fdb_add = mv88e6xxx_port_fdb_add,
3787 .port_fdb_del = mv88e6xxx_port_fdb_del,
3788 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04003789 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
3790 .port_mdb_add = mv88e6xxx_port_mdb_add,
3791 .port_mdb_del = mv88e6xxx_port_mdb_del,
3792 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003793};
3794
Vivien Didelotfad09c72016-06-21 12:28:20 -04003795static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003796 struct device_node *np)
3797{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003798 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003799 struct dsa_switch *ds;
3800
3801 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
3802 if (!ds)
3803 return -ENOMEM;
3804
3805 ds->dev = dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003806 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04003807 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003808
3809 dev_set_drvdata(dev, ds);
3810
3811 return dsa_register_switch(ds, np);
3812}
3813
Vivien Didelotfad09c72016-06-21 12:28:20 -04003814static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003815{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003816 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04003817}
3818
Vivien Didelot57d32312016-06-20 13:13:58 -04003819static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003820{
3821 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003822 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04003823 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003824 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003825 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02003826 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003827
Vivien Didelotcaac8542016-06-20 13:14:09 -04003828 compat_info = of_device_get_match_data(dev);
3829 if (!compat_info)
3830 return -EINVAL;
3831
Vivien Didelotfad09c72016-06-21 12:28:20 -04003832 chip = mv88e6xxx_alloc_chip(dev);
3833 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003834 return -ENOMEM;
3835
Vivien Didelotfad09c72016-06-21 12:28:20 -04003836 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04003837
Vivien Didelotfad09c72016-06-21 12:28:20 -04003838 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003839 if (err)
3840 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003841
Vivien Didelotfad09c72016-06-21 12:28:20 -04003842 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003843 if (err)
3844 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003845
Vivien Didelote57e5e72016-08-15 17:19:00 -04003846 mv88e6xxx_phy_init(chip);
3847
Vivien Didelotfad09c72016-06-21 12:28:20 -04003848 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
3849 if (IS_ERR(chip->reset))
3850 return PTR_ERR(chip->reset);
Andrew Lunn52638f72016-05-10 23:27:22 +02003851
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003852 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003853 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003854 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02003855
Andrew Lunndc30c352016-10-16 19:56:49 +02003856 mutex_lock(&chip->reg_lock);
3857 err = mv88e6xxx_switch_reset(chip);
3858 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02003859 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02003860 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02003861
Andrew Lunndc30c352016-10-16 19:56:49 +02003862 chip->irq = of_irq_get(np, 0);
3863 if (chip->irq == -EPROBE_DEFER) {
3864 err = chip->irq;
3865 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02003866 }
3867
Andrew Lunndc30c352016-10-16 19:56:49 +02003868 if (chip->irq > 0) {
3869 /* Has to be performed before the MDIO bus is created,
3870 * because the PHYs will link there interrupts to these
3871 * interrupt controllers
3872 */
3873 mutex_lock(&chip->reg_lock);
3874 err = mv88e6xxx_g1_irq_setup(chip);
3875 mutex_unlock(&chip->reg_lock);
3876
3877 if (err)
3878 goto out;
3879
3880 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
3881 err = mv88e6xxx_g2_irq_setup(chip);
3882 if (err)
3883 goto out_g1_irq;
3884 }
3885 }
3886
3887 err = mv88e6xxx_mdio_register(chip, np);
3888 if (err)
3889 goto out_g2_irq;
3890
3891 err = mv88e6xxx_register_switch(chip, np);
3892 if (err)
3893 goto out_mdio;
3894
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003895 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02003896
3897out_mdio:
3898 mv88e6xxx_mdio_unregister(chip);
3899out_g2_irq:
3900 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
3901 mv88e6xxx_g2_irq_free(chip);
3902out_g1_irq:
3903 mv88e6xxx_g1_irq_free(chip);
3904out:
3905 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003906}
3907
3908static void mv88e6xxx_remove(struct mdio_device *mdiodev)
3909{
3910 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04003911 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003912
Andrew Lunn930188c2016-08-22 16:01:03 +02003913 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04003914 mv88e6xxx_unregister_switch(chip);
3915 mv88e6xxx_mdio_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02003916
3917 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
3918 mv88e6xxx_g2_irq_free(chip);
3919 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003920}
3921
3922static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04003923 {
3924 .compatible = "marvell,mv88e6085",
3925 .data = &mv88e6xxx_table[MV88E6085],
3926 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003927 { /* sentinel */ },
3928};
3929
3930MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
3931
3932static struct mdio_driver mv88e6xxx_driver = {
3933 .probe = mv88e6xxx_probe,
3934 .remove = mv88e6xxx_remove,
3935 .mdiodrv.driver = {
3936 .name = "mv88e6085",
3937 .of_match_table = mv88e6xxx_of_match,
3938 },
3939};
3940
Ben Hutchings98e67302011-11-25 14:36:19 +00003941static int __init mv88e6xxx_init(void)
3942{
Vivien Didelot9d490b42016-08-23 12:38:56 -04003943 register_switch_driver(&mv88e6xxx_switch_ops);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003944 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00003945}
3946module_init(mv88e6xxx_init);
3947
3948static void __exit mv88e6xxx_cleanup(void)
3949{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02003950 mdio_driver_unregister(&mv88e6xxx_driver);
Vivien Didelot9d490b42016-08-23 12:38:56 -04003951 unregister_switch_driver(&mv88e6xxx_switch_ops);
Ben Hutchings98e67302011-11-25 14:36:19 +00003952}
3953module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00003954
3955MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
3956MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
3957MODULE_LICENSE("GPL");