blob: ef6d3574062d4591e69759dd18de4fbfd6ae5b19 [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;
Andrew Lunn3460a572016-11-20 20:14:16 +0100416 u16 mask;
417
418 mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
419 mask |= GENMASK(chip->g1_irq.nirqs, 0);
420 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
421
422 free_irq(chip->irq, chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200423
424 for (irq = 0; irq < 16; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100425 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200426 irq_dispose_mapping(virq);
427 }
428
Andrew Lunna3db3d32016-11-20 20:14:14 +0100429 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200430}
431
432static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
433{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100434 int err, irq, virq;
435 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200436
437 chip->g1_irq.nirqs = chip->info->g1_irqs;
438 chip->g1_irq.domain = irq_domain_add_simple(
439 NULL, chip->g1_irq.nirqs, 0,
440 &mv88e6xxx_g1_irq_domain_ops, chip);
441 if (!chip->g1_irq.domain)
442 return -ENOMEM;
443
444 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
445 irq_create_mapping(chip->g1_irq.domain, irq);
446
447 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
448 chip->g1_irq.masked = ~0;
449
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100450 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200451 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100452 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200453
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100454 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200455
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100456 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200457 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100458 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200459
460 /* Reading the interrupt status clears (most of) them */
461 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
462 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100463 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200464
465 err = request_threaded_irq(chip->irq, NULL,
466 mv88e6xxx_g1_irq_thread_fn,
467 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
468 dev_name(chip->dev), chip);
469 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100470 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200471
472 return 0;
473
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100474out_disable:
475 mask |= GENMASK(chip->g1_irq.nirqs, 0);
476 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
477
478out_mapping:
479 for (irq = 0; irq < 16; irq++) {
480 virq = irq_find_mapping(chip->g1_irq.domain, irq);
481 irq_dispose_mapping(virq);
482 }
483
484 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200485
486 return err;
487}
488
Vivien Didelotec561272016-09-02 14:45:33 -0400489int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400490{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200491 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400492
Andrew Lunn6441e6692016-08-19 00:01:55 +0200493 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400494 u16 val;
495 int err;
496
497 err = mv88e6xxx_read(chip, addr, reg, &val);
498 if (err)
499 return err;
500
501 if (!(val & mask))
502 return 0;
503
504 usleep_range(1000, 2000);
505 }
506
Andrew Lunn30853552016-08-19 00:01:57 +0200507 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400508 return -ETIMEDOUT;
509}
510
Vivien Didelotf22ab642016-07-18 20:45:31 -0400511/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400512int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400513{
514 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200515 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400516
517 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200518 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
519 if (err)
520 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400521
522 /* Set the Update bit to trigger a write operation */
523 val = BIT(15) | update;
524
525 return mv88e6xxx_write(chip, addr, reg, val);
526}
527
Vivien Didelota935c052016-09-29 12:21:53 -0400528static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000529{
Vivien Didelot914b32f2016-06-20 13:14:11 -0400530 u16 val;
Vivien Didelota935c052016-09-29 12:21:53 -0400531 int i, err;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000532
Vivien Didelota935c052016-09-29 12:21:53 -0400533 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400534 if (err)
535 return err;
Vivien Didelot3996a4f2015-10-30 18:56:45 -0400536
Vivien Didelota935c052016-09-29 12:21:53 -0400537 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL,
538 val & ~GLOBAL_CONTROL_PPU_ENABLE);
539 if (err)
540 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000541
Andrew Lunn6441e6692016-08-19 00:01:55 +0200542 for (i = 0; i < 16; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -0400543 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &val);
544 if (err)
545 return err;
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200546
Barry Grussling19b2f972013-01-08 16:05:54 +0000547 usleep_range(1000, 2000);
Vivien Didelota935c052016-09-29 12:21:53 -0400548 if ((val & GLOBAL_STATUS_PPU_MASK) != GLOBAL_STATUS_PPU_POLLING)
Barry Grussling85686582013-01-08 16:05:56 +0000549 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000550 }
551
552 return -ETIMEDOUT;
553}
554
Vivien Didelotfad09c72016-06-21 12:28:20 -0400555static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000556{
Vivien Didelota935c052016-09-29 12:21:53 -0400557 u16 val;
558 int i, err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000559
Vivien Didelota935c052016-09-29 12:21:53 -0400560 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &val);
561 if (err)
562 return err;
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200563
Vivien Didelota935c052016-09-29 12:21:53 -0400564 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL,
565 val | GLOBAL_CONTROL_PPU_ENABLE);
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200566 if (err)
567 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000568
Andrew Lunn6441e6692016-08-19 00:01:55 +0200569 for (i = 0; i < 16; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -0400570 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &val);
571 if (err)
572 return err;
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200573
Barry Grussling19b2f972013-01-08 16:05:54 +0000574 usleep_range(1000, 2000);
Vivien Didelota935c052016-09-29 12:21:53 -0400575 if ((val & GLOBAL_STATUS_PPU_MASK) == GLOBAL_STATUS_PPU_POLLING)
Barry Grussling85686582013-01-08 16:05:56 +0000576 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000577 }
578
579 return -ETIMEDOUT;
580}
581
582static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
583{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400584 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000585
Vivien Didelotfad09c72016-06-21 12:28:20 -0400586 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200587
Vivien Didelotfad09c72016-06-21 12:28:20 -0400588 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200589
Vivien Didelotfad09c72016-06-21 12:28:20 -0400590 if (mutex_trylock(&chip->ppu_mutex)) {
591 if (mv88e6xxx_ppu_enable(chip) == 0)
592 chip->ppu_disabled = 0;
593 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000594 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200595
Vivien Didelotfad09c72016-06-21 12:28:20 -0400596 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000597}
598
599static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
600{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400601 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000602
Vivien Didelotfad09c72016-06-21 12:28:20 -0400603 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000604}
605
Vivien Didelotfad09c72016-06-21 12:28:20 -0400606static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000607{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000608 int ret;
609
Vivien Didelotfad09c72016-06-21 12:28:20 -0400610 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000611
Barry Grussling3675c8d2013-01-08 16:05:53 +0000612 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000613 * we can access the PHY registers. If it was already
614 * disabled, cancel the timer that is going to re-enable
615 * it.
616 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400617 if (!chip->ppu_disabled) {
618 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000619 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400620 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000621 return ret;
622 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400623 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000624 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400625 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000626 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000627 }
628
629 return ret;
630}
631
Vivien Didelotfad09c72016-06-21 12:28:20 -0400632static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000633{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000634 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400635 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
636 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000637}
638
Vivien Didelotfad09c72016-06-21 12:28:20 -0400639static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000640{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400641 mutex_init(&chip->ppu_mutex);
642 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000643 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
644 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000645}
646
Andrew Lunn930188c2016-08-22 16:01:03 +0200647static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
648{
649 del_timer_sync(&chip->ppu_timer);
650}
651
Vivien Didelote57e5e72016-08-15 17:19:00 -0400652static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip, int addr,
653 int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000654{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400655 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000656
Vivien Didelote57e5e72016-08-15 17:19:00 -0400657 err = mv88e6xxx_ppu_access_get(chip);
658 if (!err) {
659 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400660 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000661 }
662
Vivien Didelote57e5e72016-08-15 17:19:00 -0400663 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000664}
665
Vivien Didelote57e5e72016-08-15 17:19:00 -0400666static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip, int addr,
667 int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000668{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400669 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000670
Vivien Didelote57e5e72016-08-15 17:19:00 -0400671 err = mv88e6xxx_ppu_access_get(chip);
672 if (!err) {
673 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400674 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000675 }
676
Vivien Didelote57e5e72016-08-15 17:19:00 -0400677 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000678}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000679
Vivien Didelotfad09c72016-06-21 12:28:20 -0400680static bool mv88e6xxx_6065_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200681{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400682 return chip->info->family == MV88E6XXX_FAMILY_6065;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200683}
684
Vivien Didelotfad09c72016-06-21 12:28:20 -0400685static bool mv88e6xxx_6095_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200686{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400687 return chip->info->family == MV88E6XXX_FAMILY_6095;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200688}
689
Vivien Didelotfad09c72016-06-21 12:28:20 -0400690static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200691{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400692 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200693}
694
Vivien Didelotfad09c72016-06-21 12:28:20 -0400695static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200696{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400697 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200698}
699
Vivien Didelotfad09c72016-06-21 12:28:20 -0400700static bool mv88e6xxx_6185_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200701{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400702 return chip->info->family == MV88E6XXX_FAMILY_6185;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200703}
704
Vivien Didelotfad09c72016-06-21 12:28:20 -0400705static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700706{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400707 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700708}
709
Vivien Didelotfad09c72016-06-21 12:28:20 -0400710static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200711{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400712 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200713}
714
Vivien Didelotfad09c72016-06-21 12:28:20 -0400715static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200716{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400717 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200718}
719
Vivien Didelotd78343d2016-11-04 03:23:36 +0100720static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
721 int link, int speed, int duplex,
722 phy_interface_t mode)
723{
724 int err;
725
726 if (!chip->info->ops->port_set_link)
727 return 0;
728
729 /* Port's MAC control must not be changed unless the link is down */
730 err = chip->info->ops->port_set_link(chip, port, 0);
731 if (err)
732 return err;
733
734 if (chip->info->ops->port_set_speed) {
735 err = chip->info->ops->port_set_speed(chip, port, speed);
736 if (err && err != -EOPNOTSUPP)
737 goto restore_link;
738 }
739
740 if (chip->info->ops->port_set_duplex) {
741 err = chip->info->ops->port_set_duplex(chip, port, duplex);
742 if (err && err != -EOPNOTSUPP)
743 goto restore_link;
744 }
745
746 if (chip->info->ops->port_set_rgmii_delay) {
747 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
748 if (err && err != -EOPNOTSUPP)
749 goto restore_link;
750 }
751
752 err = 0;
753restore_link:
754 if (chip->info->ops->port_set_link(chip, port, link))
755 netdev_err(chip->ds->ports[port].netdev,
756 "failed to restore MAC's link\n");
757
758 return err;
759}
760
Andrew Lunndea87022015-08-31 15:56:47 +0200761/* We expect the switch to perform auto negotiation if there is a real
762 * phy. However, in the case of a fixed link phy, we force the port
763 * settings from the fixed link settings.
764 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400765static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
766 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200767{
Vivien Didelot04bed142016-08-31 18:06:13 -0400768 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200769 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200770
771 if (!phy_is_pseudo_fixed_link(phydev))
772 return;
773
Vivien Didelotfad09c72016-06-21 12:28:20 -0400774 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100775 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
776 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400777 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100778
779 if (err && err != -EOPNOTSUPP)
780 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200781}
782
Vivien Didelotfad09c72016-06-21 12:28:20 -0400783static int _mv88e6xxx_stats_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000784{
Vivien Didelota935c052016-09-29 12:21:53 -0400785 u16 val;
786 int i, err;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000787
788 for (i = 0; i < 10; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -0400789 err = mv88e6xxx_g1_read(chip, GLOBAL_STATS_OP, &val);
Andrew Lunn096eea02016-11-21 23:26:56 +0100790 if (err)
791 return err;
792
Vivien Didelota935c052016-09-29 12:21:53 -0400793 if ((val & GLOBAL_STATS_OP_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000794 return 0;
795 }
796
797 return -ETIMEDOUT;
798}
799
Andrew Lunna605a0f2016-11-21 23:26:58 +0100800static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000801{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100802 if (!chip->info->ops->stats_snapshot)
803 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000804
Andrew Lunna605a0f2016-11-21 23:26:58 +0100805 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000806}
807
Vivien Didelotfad09c72016-06-21 12:28:20 -0400808static void _mv88e6xxx_stats_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -0400809 int stat, u32 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000810{
Vivien Didelota935c052016-09-29 12:21:53 -0400811 u32 value;
812 u16 reg;
813 int err;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000814
815 *val = 0;
816
Vivien Didelota935c052016-09-29 12:21:53 -0400817 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
818 GLOBAL_STATS_OP_READ_CAPTURED |
819 GLOBAL_STATS_OP_HIST_RX_TX | stat);
820 if (err)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000821 return;
822
Vivien Didelota935c052016-09-29 12:21:53 -0400823 err = _mv88e6xxx_stats_wait(chip);
824 if (err)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000825 return;
826
Vivien Didelota935c052016-09-29 12:21:53 -0400827 err = mv88e6xxx_g1_read(chip, GLOBAL_STATS_COUNTER_32, &reg);
828 if (err)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000829 return;
830
Vivien Didelota935c052016-09-29 12:21:53 -0400831 value = reg << 16;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000832
Vivien Didelota935c052016-09-29 12:21:53 -0400833 err = mv88e6xxx_g1_read(chip, GLOBAL_STATS_COUNTER_01, &reg);
834 if (err)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000835 return;
836
Vivien Didelota935c052016-09-29 12:21:53 -0400837 *val = value | reg;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000838}
839
Andrew Lunne413e7e2015-04-02 04:06:38 +0200840static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100841 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
842 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
843 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
844 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
845 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
846 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
847 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
848 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
849 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
850 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
851 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
852 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
853 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
854 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
855 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
856 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
857 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
858 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
859 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
860 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
861 { "single", 4, 0x14, STATS_TYPE_BANK0, },
862 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
863 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
864 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
865 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
866 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
867 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
868 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
869 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
870 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
871 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
872 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
873 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
874 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
875 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
876 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
877 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
878 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
879 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
880 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
881 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
882 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
883 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
884 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
885 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
886 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
887 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
888 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
889 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
890 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
891 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
892 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
893 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
894 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
895 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
896 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
897 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
898 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
899 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200900};
901
Vivien Didelotfad09c72016-06-21 12:28:20 -0400902static bool mv88e6xxx_has_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100903 struct mv88e6xxx_hw_stat *stat)
Andrew Lunne413e7e2015-04-02 04:06:38 +0200904{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100905 switch (stat->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100906 case STATS_TYPE_BANK0:
Andrew Lunne413e7e2015-04-02 04:06:38 +0200907 return true;
Andrew Lunndfafe442016-11-21 23:27:02 +0100908 case STATS_TYPE_BANK1:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400909 return mv88e6xxx_6320_family(chip);
Andrew Lunndfafe442016-11-21 23:27:02 +0100910 case STATS_TYPE_PORT:
Vivien Didelotfad09c72016-06-21 12:28:20 -0400911 return mv88e6xxx_6095_family(chip) ||
912 mv88e6xxx_6185_family(chip) ||
913 mv88e6xxx_6097_family(chip) ||
914 mv88e6xxx_6165_family(chip) ||
915 mv88e6xxx_6351_family(chip) ||
916 mv88e6xxx_6352_family(chip);
Andrew Lunne413e7e2015-04-02 04:06:38 +0200917 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100918 return false;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000919}
920
Vivien Didelotfad09c72016-06-21 12:28:20 -0400921static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100922 struct mv88e6xxx_hw_stat *s,
Andrew Lunn80c46272015-06-20 18:42:30 +0200923 int port)
924{
Andrew Lunn80c46272015-06-20 18:42:30 +0200925 u32 low;
926 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100927 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200928 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200929 u64 value;
930
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100931 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100932 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200933 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
934 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200935 return UINT64_MAX;
936
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200937 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200938 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200939 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
940 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200941 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200942 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200943 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100944 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100945 case STATS_TYPE_BANK1:
946 reg = GLOBAL_STATS_OP_BANK_1;
947 /* fall through */
948 case STATS_TYPE_BANK0:
949 reg |= s->reg;
950 _mv88e6xxx_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200951 if (s->sizeof_stat == 8)
Andrew Lunndfafe442016-11-21 23:27:02 +0100952 _mv88e6xxx_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200953 }
954 value = (((u64)high) << 16) | low;
955 return value;
956}
957
Andrew Lunndfafe442016-11-21 23:27:02 +0100958static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
959 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100960{
961 struct mv88e6xxx_hw_stat *stat;
962 int i, j;
963
964 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
965 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100966 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100967 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
968 ETH_GSTRING_LEN);
969 j++;
970 }
971 }
972}
973
Andrew Lunndfafe442016-11-21 23:27:02 +0100974static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
975 uint8_t *data)
976{
977 mv88e6xxx_stats_get_strings(chip, data,
978 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
979}
980
981static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
982 uint8_t *data)
983{
984 mv88e6xxx_stats_get_strings(chip, data,
985 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
986}
987
988static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
989 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100990{
Vivien Didelot04bed142016-08-31 18:06:13 -0400991 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100992
993 if (chip->info->ops->stats_get_strings)
994 chip->info->ops->stats_get_strings(chip, data);
995}
996
997static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
998 int types)
999{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001000 struct mv88e6xxx_hw_stat *stat;
1001 int i, j;
1002
1003 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1004 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +01001005 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001006 j++;
1007 }
1008 return j;
1009}
1010
Andrew Lunndfafe442016-11-21 23:27:02 +01001011static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1012{
1013 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1014 STATS_TYPE_PORT);
1015}
1016
1017static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
1018{
1019 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1020 STATS_TYPE_BANK1);
1021}
1022
1023static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
1024{
1025 struct mv88e6xxx_chip *chip = ds->priv;
1026
1027 if (chip->info->ops->stats_get_sset_count)
1028 return chip->info->ops->stats_get_sset_count(chip);
1029
1030 return 0;
1031}
1032
Vivien Didelotf81ec902016-05-09 13:22:58 -04001033static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1034 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001035{
Vivien Didelot04bed142016-08-31 18:06:13 -04001036 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001037 struct mv88e6xxx_hw_stat *stat;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001038 int ret;
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001039 int i, j;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001040
Vivien Didelotfad09c72016-06-21 12:28:20 -04001041 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001042
Andrew Lunna605a0f2016-11-21 23:26:58 +01001043 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001044 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001045 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001046 return;
1047 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001048 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1049 stat = &mv88e6xxx_hw_stats[i];
Vivien Didelotfad09c72016-06-21 12:28:20 -04001050 if (mv88e6xxx_has_stat(chip, stat)) {
1051 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port);
Andrew Lunnf5e2ed02015-12-23 13:23:17 +01001052 j++;
1053 }
1054 }
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001055
Vivien Didelotfad09c72016-06-21 12:28:20 -04001056 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001057}
Ben Hutchings98e67302011-11-25 14:36:19 +00001058
Andrew Lunnde2273872016-11-21 23:27:01 +01001059static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1060{
1061 if (chip->info->ops->stats_set_histogram)
1062 return chip->info->ops->stats_set_histogram(chip);
1063
1064 return 0;
1065}
1066
Vivien Didelotf81ec902016-05-09 13:22:58 -04001067static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001068{
1069 return 32 * sizeof(u16);
1070}
1071
Vivien Didelotf81ec902016-05-09 13:22:58 -04001072static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1073 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001074{
Vivien Didelot04bed142016-08-31 18:06:13 -04001075 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001076 int err;
1077 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001078 u16 *p = _p;
1079 int i;
1080
1081 regs->version = 0;
1082
1083 memset(p, 0xff, 32 * sizeof(u16));
1084
Vivien Didelotfad09c72016-06-21 12:28:20 -04001085 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001086
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001087 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001088
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001089 err = mv88e6xxx_port_read(chip, port, i, &reg);
1090 if (!err)
1091 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001092 }
Vivien Didelot23062512016-05-09 13:22:45 -04001093
Vivien Didelotfad09c72016-06-21 12:28:20 -04001094 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001095}
1096
Vivien Didelotfad09c72016-06-21 12:28:20 -04001097static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001098{
Vivien Didelota935c052016-09-29 12:21:53 -04001099 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001100}
1101
Vivien Didelotf81ec902016-05-09 13:22:58 -04001102static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1103 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001104{
Vivien Didelot04bed142016-08-31 18:06:13 -04001105 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001106 u16 reg;
1107 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001108
Vivien Didelotfad09c72016-06-21 12:28:20 -04001109 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001110 return -EOPNOTSUPP;
1111
Vivien Didelotfad09c72016-06-21 12:28:20 -04001112 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001113
Vivien Didelot9c938292016-08-15 17:19:02 -04001114 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1115 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001116 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001117
1118 e->eee_enabled = !!(reg & 0x0200);
1119 e->tx_lpi_enabled = !!(reg & 0x0100);
1120
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001121 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001122 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001123 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001124
Andrew Lunncca8b132015-04-02 04:06:39 +02001125 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001126out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001127 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001128
1129 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001130}
1131
Vivien Didelotf81ec902016-05-09 13:22:58 -04001132static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1133 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001134{
Vivien Didelot04bed142016-08-31 18:06:13 -04001135 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001136 u16 reg;
1137 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001138
Vivien Didelotfad09c72016-06-21 12:28:20 -04001139 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001140 return -EOPNOTSUPP;
1141
Vivien Didelotfad09c72016-06-21 12:28:20 -04001142 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001143
Vivien Didelot9c938292016-08-15 17:19:02 -04001144 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1145 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001146 goto out;
1147
Vivien Didelot9c938292016-08-15 17:19:02 -04001148 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001149 if (e->eee_enabled)
1150 reg |= 0x0200;
1151 if (e->tx_lpi_enabled)
1152 reg |= 0x0100;
1153
Vivien Didelot9c938292016-08-15 17:19:02 -04001154 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001155out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001156 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001157
Vivien Didelot9c938292016-08-15 17:19:02 -04001158 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001159}
1160
Vivien Didelotfad09c72016-06-21 12:28:20 -04001161static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001162{
Vivien Didelota935c052016-09-29 12:21:53 -04001163 u16 val;
1164 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001165
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001166 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001167 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1168 if (err)
1169 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001170 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001171 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001172 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1173 if (err)
1174 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001175
Vivien Didelota935c052016-09-29 12:21:53 -04001176 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1177 (val & 0xfff) | ((fid << 8) & 0xf000));
1178 if (err)
1179 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001180
1181 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1182 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001183 }
1184
Vivien Didelota935c052016-09-29 12:21:53 -04001185 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1186 if (err)
1187 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001188
Vivien Didelotfad09c72016-06-21 12:28:20 -04001189 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001190}
1191
Vivien Didelotfad09c72016-06-21 12:28:20 -04001192static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001193 struct mv88e6xxx_atu_entry *entry)
1194{
1195 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1196
1197 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1198 unsigned int mask, shift;
1199
1200 if (entry->trunk) {
1201 data |= GLOBAL_ATU_DATA_TRUNK;
1202 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1203 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1204 } else {
1205 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1206 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1207 }
1208
1209 data |= (entry->portv_trunkid << shift) & mask;
1210 }
1211
Vivien Didelota935c052016-09-29 12:21:53 -04001212 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001213}
1214
Vivien Didelotfad09c72016-06-21 12:28:20 -04001215static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001216 struct mv88e6xxx_atu_entry *entry,
1217 bool static_too)
1218{
1219 int op;
1220 int err;
1221
Vivien Didelotfad09c72016-06-21 12:28:20 -04001222 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001223 if (err)
1224 return err;
1225
Vivien Didelotfad09c72016-06-21 12:28:20 -04001226 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001227 if (err)
1228 return err;
1229
1230 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001231 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1232 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1233 } else {
1234 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1235 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1236 }
1237
Vivien Didelotfad09c72016-06-21 12:28:20 -04001238 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001239}
1240
Vivien Didelotfad09c72016-06-21 12:28:20 -04001241static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001242 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001243{
1244 struct mv88e6xxx_atu_entry entry = {
1245 .fid = fid,
1246 .state = 0, /* EntryState bits must be 0 */
1247 };
1248
Vivien Didelotfad09c72016-06-21 12:28:20 -04001249 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001250}
1251
Vivien Didelotfad09c72016-06-21 12:28:20 -04001252static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001253 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001254{
1255 struct mv88e6xxx_atu_entry entry = {
1256 .trunk = false,
1257 .fid = fid,
1258 };
1259
1260 /* EntryState bits must be 0xF */
1261 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1262
1263 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1264 entry.portv_trunkid = (to_port & 0x0f) << 4;
1265 entry.portv_trunkid |= from_port & 0x0f;
1266
Vivien Didelotfad09c72016-06-21 12:28:20 -04001267 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001268}
1269
Vivien Didelotfad09c72016-06-21 12:28:20 -04001270static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001271 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001272{
1273 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001274 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001275}
1276
Vivien Didelotfad09c72016-06-21 12:28:20 -04001277static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001278{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001279 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001280 struct dsa_switch *ds = chip->ds;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001281 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001282 int i;
1283
1284 /* allow CPU port or DSA link(s) to send frames to every port */
1285 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001286 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001287 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001288 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001289 /* allow sending frames to every group member */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001290 if (bridge && chip->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001291 output_ports |= BIT(i);
1292
1293 /* allow sending frames to CPU port and DSA link(s) */
1294 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1295 output_ports |= BIT(i);
1296 }
1297 }
1298
1299 /* prevent frames from going back out of the port they came in on */
1300 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001301
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001302 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001303}
1304
Vivien Didelotf81ec902016-05-09 13:22:58 -04001305static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1306 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001307{
Vivien Didelot04bed142016-08-31 18:06:13 -04001308 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001309 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001310 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001311
1312 switch (state) {
1313 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001314 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001315 break;
1316 case BR_STATE_BLOCKING:
1317 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001318 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001319 break;
1320 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001321 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001322 break;
1323 case BR_STATE_FORWARDING:
1324 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001325 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001326 break;
1327 }
1328
Vivien Didelotfad09c72016-06-21 12:28:20 -04001329 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001330 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001331 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001332
1333 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001334 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001335}
1336
Vivien Didelot749efcb2016-09-22 16:49:24 -04001337static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1338{
1339 struct mv88e6xxx_chip *chip = ds->priv;
1340 int err;
1341
1342 mutex_lock(&chip->reg_lock);
1343 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1344 mutex_unlock(&chip->reg_lock);
1345
1346 if (err)
1347 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1348}
1349
Vivien Didelotfad09c72016-06-21 12:28:20 -04001350static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001351{
Vivien Didelota935c052016-09-29 12:21:53 -04001352 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001353}
1354
Vivien Didelotfad09c72016-06-21 12:28:20 -04001355static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001356{
Vivien Didelota935c052016-09-29 12:21:53 -04001357 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001358
Vivien Didelota935c052016-09-29 12:21:53 -04001359 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1360 if (err)
1361 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001362
Vivien Didelotfad09c72016-06-21 12:28:20 -04001363 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001364}
1365
Vivien Didelotfad09c72016-06-21 12:28:20 -04001366static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001367{
1368 int ret;
1369
Vivien Didelotfad09c72016-06-21 12:28:20 -04001370 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001371 if (ret < 0)
1372 return ret;
1373
Vivien Didelotfad09c72016-06-21 12:28:20 -04001374 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001375}
1376
Vivien Didelotfad09c72016-06-21 12:28:20 -04001377static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001378 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001379 unsigned int nibble_offset)
1380{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001381 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001382 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001383
1384 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001385 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001386
Vivien Didelota935c052016-09-29 12:21:53 -04001387 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1388 if (err)
1389 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001390 }
1391
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001392 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001393 unsigned int shift = (i % 4) * 4 + nibble_offset;
1394 u16 reg = regs[i / 4];
1395
1396 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1397 }
1398
1399 return 0;
1400}
1401
Vivien Didelotfad09c72016-06-21 12:28:20 -04001402static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001403 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001404{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001405 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001406}
1407
Vivien Didelotfad09c72016-06-21 12:28:20 -04001408static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001409 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001410{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001411 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001412}
1413
Vivien Didelotfad09c72016-06-21 12:28:20 -04001414static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001415 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001416 unsigned int nibble_offset)
1417{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001418 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001419 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001420
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001421 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001422 unsigned int shift = (i % 4) * 4 + nibble_offset;
1423 u8 data = entry->data[i];
1424
1425 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1426 }
1427
1428 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001429 u16 reg = regs[i];
1430
1431 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1432 if (err)
1433 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001434 }
1435
1436 return 0;
1437}
1438
Vivien Didelotfad09c72016-06-21 12:28:20 -04001439static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001440 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001441{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001442 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001443}
1444
Vivien Didelotfad09c72016-06-21 12:28:20 -04001445static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001446 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001447{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001448 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001449}
1450
Vivien Didelotfad09c72016-06-21 12:28:20 -04001451static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001452{
Vivien Didelota935c052016-09-29 12:21:53 -04001453 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1454 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001455}
1456
Vivien Didelotfad09c72016-06-21 12:28:20 -04001457static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001458 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001459{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001460 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001461 u16 val;
1462 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001463
Vivien Didelota935c052016-09-29 12:21:53 -04001464 err = _mv88e6xxx_vtu_wait(chip);
1465 if (err)
1466 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001467
Vivien Didelota935c052016-09-29 12:21:53 -04001468 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1469 if (err)
1470 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001471
Vivien Didelota935c052016-09-29 12:21:53 -04001472 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1473 if (err)
1474 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001475
Vivien Didelota935c052016-09-29 12:21:53 -04001476 next.vid = val & GLOBAL_VTU_VID_MASK;
1477 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001478
1479 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001480 err = mv88e6xxx_vtu_data_read(chip, &next);
1481 if (err)
1482 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001483
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001484 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001485 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1486 if (err)
1487 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001488
Vivien Didelota935c052016-09-29 12:21:53 -04001489 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001490 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001491 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1492 * VTU DBNum[3:0] are located in VTU Operation 3:0
1493 */
Vivien Didelota935c052016-09-29 12:21:53 -04001494 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1495 if (err)
1496 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001497
Vivien Didelota935c052016-09-29 12:21:53 -04001498 next.fid = (val & 0xf00) >> 4;
1499 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001500 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001501
Vivien Didelotfad09c72016-06-21 12:28:20 -04001502 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001503 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1504 if (err)
1505 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001506
Vivien Didelota935c052016-09-29 12:21:53 -04001507 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001508 }
1509 }
1510
1511 *entry = next;
1512 return 0;
1513}
1514
Vivien Didelotf81ec902016-05-09 13:22:58 -04001515static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1516 struct switchdev_obj_port_vlan *vlan,
1517 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001518{
Vivien Didelot04bed142016-08-31 18:06:13 -04001519 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001520 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001521 u16 pvid;
1522 int err;
1523
Vivien Didelotfad09c72016-06-21 12:28:20 -04001524 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001525 return -EOPNOTSUPP;
1526
Vivien Didelotfad09c72016-06-21 12:28:20 -04001527 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001528
Vivien Didelot77064f32016-11-04 03:23:30 +01001529 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001530 if (err)
1531 goto unlock;
1532
Vivien Didelotfad09c72016-06-21 12:28:20 -04001533 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001534 if (err)
1535 goto unlock;
1536
1537 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001538 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001539 if (err)
1540 break;
1541
1542 if (!next.valid)
1543 break;
1544
1545 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1546 continue;
1547
1548 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001549 vlan->vid_begin = next.vid;
1550 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001551 vlan->flags = 0;
1552
1553 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1554 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1555
1556 if (next.vid == pvid)
1557 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1558
1559 err = cb(&vlan->obj);
1560 if (err)
1561 break;
1562 } while (next.vid < GLOBAL_VTU_VID_MASK);
1563
1564unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001565 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001566
1567 return err;
1568}
1569
Vivien Didelotfad09c72016-06-21 12:28:20 -04001570static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001571 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001572{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001573 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001574 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001575 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001576
Vivien Didelota935c052016-09-29 12:21:53 -04001577 err = _mv88e6xxx_vtu_wait(chip);
1578 if (err)
1579 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001580
1581 if (!entry->valid)
1582 goto loadpurge;
1583
1584 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001585 err = mv88e6xxx_vtu_data_write(chip, entry);
1586 if (err)
1587 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001588
Vivien Didelotfad09c72016-06-21 12:28:20 -04001589 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001590 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001591 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1592 if (err)
1593 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001594 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001595
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001596 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001597 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001598 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1599 if (err)
1600 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001601 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001602 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1603 * VTU DBNum[3:0] are located in VTU Operation 3:0
1604 */
1605 op |= (entry->fid & 0xf0) << 8;
1606 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001607 }
1608
1609 reg = GLOBAL_VTU_VID_VALID;
1610loadpurge:
1611 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001612 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1613 if (err)
1614 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001615
Vivien Didelotfad09c72016-06-21 12:28:20 -04001616 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001617}
1618
Vivien Didelotfad09c72016-06-21 12:28:20 -04001619static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001620 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001621{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001622 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001623 u16 val;
1624 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001625
Vivien Didelota935c052016-09-29 12:21:53 -04001626 err = _mv88e6xxx_vtu_wait(chip);
1627 if (err)
1628 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001629
Vivien Didelota935c052016-09-29 12:21:53 -04001630 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1631 sid & GLOBAL_VTU_SID_MASK);
1632 if (err)
1633 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001634
Vivien Didelota935c052016-09-29 12:21:53 -04001635 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1636 if (err)
1637 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001638
Vivien Didelota935c052016-09-29 12:21:53 -04001639 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1640 if (err)
1641 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001642
Vivien Didelota935c052016-09-29 12:21:53 -04001643 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001644
Vivien Didelota935c052016-09-29 12:21:53 -04001645 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1646 if (err)
1647 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001648
Vivien Didelota935c052016-09-29 12:21:53 -04001649 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001650
1651 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001652 err = mv88e6xxx_stu_data_read(chip, &next);
1653 if (err)
1654 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001655 }
1656
1657 *entry = next;
1658 return 0;
1659}
1660
Vivien Didelotfad09c72016-06-21 12:28:20 -04001661static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001662 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001663{
1664 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001665 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001666
Vivien Didelota935c052016-09-29 12:21:53 -04001667 err = _mv88e6xxx_vtu_wait(chip);
1668 if (err)
1669 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001670
1671 if (!entry->valid)
1672 goto loadpurge;
1673
1674 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001675 err = mv88e6xxx_stu_data_write(chip, entry);
1676 if (err)
1677 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001678
1679 reg = GLOBAL_VTU_VID_VALID;
1680loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001681 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1682 if (err)
1683 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001684
1685 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001686 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1687 if (err)
1688 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001689
Vivien Didelotfad09c72016-06-21 12:28:20 -04001690 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001691}
1692
Vivien Didelotfad09c72016-06-21 12:28:20 -04001693static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001694{
1695 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001696 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001697 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001698
1699 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1700
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001701 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001702 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001703 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001704 if (err)
1705 return err;
1706
1707 set_bit(*fid, fid_bitmap);
1708 }
1709
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001710 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001711 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001712 if (err)
1713 return err;
1714
1715 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001716 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001717 if (err)
1718 return err;
1719
1720 if (!vlan.valid)
1721 break;
1722
1723 set_bit(vlan.fid, fid_bitmap);
1724 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1725
1726 /* The reset value 0x000 is used to indicate that multiple address
1727 * databases are not needed. Return the next positive available.
1728 */
1729 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001730 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001731 return -ENOSPC;
1732
1733 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001734 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001735}
1736
Vivien Didelotfad09c72016-06-21 12:28:20 -04001737static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001738 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001739{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001740 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001741 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001742 .valid = true,
1743 .vid = vid,
1744 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001745 int i, err;
1746
Vivien Didelotfad09c72016-06-21 12:28:20 -04001747 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001748 if (err)
1749 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001750
Vivien Didelot3d131f02015-11-03 10:52:52 -05001751 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001752 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001753 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1754 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1755 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001756
Vivien Didelotfad09c72016-06-21 12:28:20 -04001757 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
1758 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001759 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001760
1761 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1762 * implemented, only one STU entry is needed to cover all VTU
1763 * entries. Thus, validate the SID 0.
1764 */
1765 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001766 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001767 if (err)
1768 return err;
1769
1770 if (vstp.sid != vlan.sid || !vstp.valid) {
1771 memset(&vstp, 0, sizeof(vstp));
1772 vstp.valid = true;
1773 vstp.sid = vlan.sid;
1774
Vivien Didelotfad09c72016-06-21 12:28:20 -04001775 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001776 if (err)
1777 return err;
1778 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001779 }
1780
1781 *entry = vlan;
1782 return 0;
1783}
1784
Vivien Didelotfad09c72016-06-21 12:28:20 -04001785static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001786 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001787{
1788 int err;
1789
1790 if (!vid)
1791 return -EINVAL;
1792
Vivien Didelotfad09c72016-06-21 12:28:20 -04001793 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001794 if (err)
1795 return err;
1796
Vivien Didelotfad09c72016-06-21 12:28:20 -04001797 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001798 if (err)
1799 return err;
1800
1801 if (entry->vid != vid || !entry->valid) {
1802 if (!creat)
1803 return -EOPNOTSUPP;
1804 /* -ENOENT would've been more appropriate, but switchdev expects
1805 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1806 */
1807
Vivien Didelotfad09c72016-06-21 12:28:20 -04001808 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001809 }
1810
1811 return err;
1812}
1813
Vivien Didelotda9c3592016-02-12 12:09:40 -05001814static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1815 u16 vid_begin, u16 vid_end)
1816{
Vivien Didelot04bed142016-08-31 18:06:13 -04001817 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001818 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001819 int i, err;
1820
1821 if (!vid_begin)
1822 return -EOPNOTSUPP;
1823
Vivien Didelotfad09c72016-06-21 12:28:20 -04001824 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001825
Vivien Didelotfad09c72016-06-21 12:28:20 -04001826 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001827 if (err)
1828 goto unlock;
1829
1830 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001831 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001832 if (err)
1833 goto unlock;
1834
1835 if (!vlan.valid)
1836 break;
1837
1838 if (vlan.vid > vid_end)
1839 break;
1840
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001841 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001842 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1843 continue;
1844
1845 if (vlan.data[i] ==
1846 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1847 continue;
1848
Vivien Didelotfad09c72016-06-21 12:28:20 -04001849 if (chip->ports[i].bridge_dev ==
1850 chip->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001851 break; /* same bridge, check next VLAN */
1852
Andrew Lunnc8b09802016-06-04 21:16:57 +02001853 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001854 "hardware VLAN %d already used by %s\n",
1855 vlan.vid,
Vivien Didelotfad09c72016-06-21 12:28:20 -04001856 netdev_name(chip->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001857 err = -EOPNOTSUPP;
1858 goto unlock;
1859 }
1860 } while (vlan.vid < vid_end);
1861
1862unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001863 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001864
1865 return err;
1866}
1867
Vivien Didelotf81ec902016-05-09 13:22:58 -04001868static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1869 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001870{
Vivien Didelot04bed142016-08-31 18:06:13 -04001871 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001872 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001873 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001874 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001875
Vivien Didelotfad09c72016-06-21 12:28:20 -04001876 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001877 return -EOPNOTSUPP;
1878
Vivien Didelotfad09c72016-06-21 12:28:20 -04001879 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001880 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001881 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001882
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001883 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001884}
1885
Vivien Didelot57d32312016-06-20 13:13:58 -04001886static int
1887mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1888 const struct switchdev_obj_port_vlan *vlan,
1889 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001890{
Vivien Didelot04bed142016-08-31 18:06:13 -04001891 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001892 int err;
1893
Vivien Didelotfad09c72016-06-21 12:28:20 -04001894 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001895 return -EOPNOTSUPP;
1896
Vivien Didelotda9c3592016-02-12 12:09:40 -05001897 /* If the requested port doesn't belong to the same bridge as the VLAN
1898 * members, do not support it (yet) and fallback to software VLAN.
1899 */
1900 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1901 vlan->vid_end);
1902 if (err)
1903 return err;
1904
Vivien Didelot76e398a2015-11-01 12:33:55 -05001905 /* We don't need any dynamic resource from the kernel (yet),
1906 * so skip the prepare phase.
1907 */
1908 return 0;
1909}
1910
Vivien Didelotfad09c72016-06-21 12:28:20 -04001911static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001912 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001913{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001914 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001915 int err;
1916
Vivien Didelotfad09c72016-06-21 12:28:20 -04001917 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001918 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001919 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001920
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001921 vlan.data[port] = untagged ?
1922 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1923 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1924
Vivien Didelotfad09c72016-06-21 12:28:20 -04001925 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001926}
1927
Vivien Didelotf81ec902016-05-09 13:22:58 -04001928static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1929 const struct switchdev_obj_port_vlan *vlan,
1930 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001931{
Vivien Didelot04bed142016-08-31 18:06:13 -04001932 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001933 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1934 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1935 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001936
Vivien Didelotfad09c72016-06-21 12:28:20 -04001937 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001938 return;
1939
Vivien Didelotfad09c72016-06-21 12:28:20 -04001940 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001941
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001942 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001943 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001944 netdev_err(ds->ports[port].netdev,
1945 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001946 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001947
Vivien Didelot77064f32016-11-04 03:23:30 +01001948 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001949 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001950 vlan->vid_end);
1951
Vivien Didelotfad09c72016-06-21 12:28:20 -04001952 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001953}
1954
Vivien Didelotfad09c72016-06-21 12:28:20 -04001955static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001956 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001957{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001958 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001959 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001960 int i, err;
1961
Vivien Didelotfad09c72016-06-21 12:28:20 -04001962 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001963 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001964 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001965
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001966 /* Tell switchdev if this VLAN is handled in software */
1967 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001968 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001969
1970 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1971
1972 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001973 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001974 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001975 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001976 continue;
1977
1978 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001979 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001980 break;
1981 }
1982 }
1983
Vivien Didelotfad09c72016-06-21 12:28:20 -04001984 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001985 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001986 return err;
1987
Vivien Didelotfad09c72016-06-21 12:28:20 -04001988 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001989}
1990
Vivien Didelotf81ec902016-05-09 13:22:58 -04001991static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1992 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001993{
Vivien Didelot04bed142016-08-31 18:06:13 -04001994 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001995 u16 pvid, vid;
1996 int err = 0;
1997
Vivien Didelotfad09c72016-06-21 12:28:20 -04001998 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001999 return -EOPNOTSUPP;
2000
Vivien Didelotfad09c72016-06-21 12:28:20 -04002001 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002002
Vivien Didelot77064f32016-11-04 03:23:30 +01002003 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002004 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002005 goto unlock;
2006
Vivien Didelot76e398a2015-11-01 12:33:55 -05002007 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002008 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002009 if (err)
2010 goto unlock;
2011
2012 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01002013 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002014 if (err)
2015 goto unlock;
2016 }
2017 }
2018
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002019unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002020 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002021
2022 return err;
2023}
2024
Vivien Didelotfad09c72016-06-21 12:28:20 -04002025static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04002026 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002027{
Vivien Didelota935c052016-09-29 12:21:53 -04002028 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002029
2030 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002031 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
2032 (addr[i * 2] << 8) | addr[i * 2 + 1]);
2033 if (err)
2034 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002035 }
2036
2037 return 0;
2038}
2039
Vivien Didelotfad09c72016-06-21 12:28:20 -04002040static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04002041 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002042{
Vivien Didelota935c052016-09-29 12:21:53 -04002043 u16 val;
2044 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002045
2046 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002047 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
2048 if (err)
2049 return err;
2050
2051 addr[i * 2] = val >> 8;
2052 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002053 }
2054
2055 return 0;
2056}
2057
Vivien Didelotfad09c72016-06-21 12:28:20 -04002058static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04002059 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002060{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002061 int ret;
2062
Vivien Didelotfad09c72016-06-21 12:28:20 -04002063 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002064 if (ret < 0)
2065 return ret;
2066
Vivien Didelotfad09c72016-06-21 12:28:20 -04002067 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002068 if (ret < 0)
2069 return ret;
2070
Vivien Didelotfad09c72016-06-21 12:28:20 -04002071 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002072 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002073 return ret;
2074
Vivien Didelotfad09c72016-06-21 12:28:20 -04002075 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002076}
David S. Millercdf09692015-08-11 12:00:37 -07002077
Vivien Didelot88472932016-09-19 19:56:11 -04002078static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2079 struct mv88e6xxx_atu_entry *entry);
2080
2081static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2082 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2083{
2084 struct mv88e6xxx_atu_entry next;
2085 int err;
2086
2087 eth_broadcast_addr(next.mac);
2088
2089 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2090 if (err)
2091 return err;
2092
2093 do {
2094 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2095 if (err)
2096 return err;
2097
2098 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2099 break;
2100
2101 if (ether_addr_equal(next.mac, addr)) {
2102 *entry = next;
2103 return 0;
2104 }
2105 } while (!is_broadcast_ether_addr(next.mac));
2106
2107 memset(entry, 0, sizeof(*entry));
2108 entry->fid = fid;
2109 ether_addr_copy(entry->mac, addr);
2110
2111 return 0;
2112}
2113
Vivien Didelot83dabd12016-08-31 11:50:04 -04002114static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2115 const unsigned char *addr, u16 vid,
2116 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002117{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002118 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002119 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002120 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002121
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002122 /* Null VLAN ID corresponds to the port private database */
2123 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002124 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002125 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002126 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002127 if (err)
2128 return err;
2129
Vivien Didelot88472932016-09-19 19:56:11 -04002130 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2131 if (err)
2132 return err;
2133
2134 /* Purge the ATU entry only if no port is using it anymore */
2135 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2136 entry.portv_trunkid &= ~BIT(port);
2137 if (!entry.portv_trunkid)
2138 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2139 } else {
2140 entry.portv_trunkid |= BIT(port);
2141 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002142 }
2143
Vivien Didelotfad09c72016-06-21 12:28:20 -04002144 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002145}
2146
Vivien Didelotf81ec902016-05-09 13:22:58 -04002147static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2148 const struct switchdev_obj_port_fdb *fdb,
2149 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002150{
2151 /* We don't need any dynamic resource from the kernel (yet),
2152 * so skip the prepare phase.
2153 */
2154 return 0;
2155}
2156
Vivien Didelotf81ec902016-05-09 13:22:58 -04002157static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2158 const struct switchdev_obj_port_fdb *fdb,
2159 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002160{
Vivien Didelot04bed142016-08-31 18:06:13 -04002161 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002162
Vivien Didelotfad09c72016-06-21 12:28:20 -04002163 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002164 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2165 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2166 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002167 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002168}
2169
Vivien Didelotf81ec902016-05-09 13:22:58 -04002170static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2171 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002172{
Vivien Didelot04bed142016-08-31 18:06:13 -04002173 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002174 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002175
Vivien Didelotfad09c72016-06-21 12:28:20 -04002176 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002177 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2178 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002179 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002180
Vivien Didelot83dabd12016-08-31 11:50:04 -04002181 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002182}
2183
Vivien Didelotfad09c72016-06-21 12:28:20 -04002184static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002185 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002186{
Vivien Didelot1d194042015-08-10 09:09:51 -04002187 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002188 u16 val;
2189 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002190
2191 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002192
Vivien Didelota935c052016-09-29 12:21:53 -04002193 err = _mv88e6xxx_atu_wait(chip);
2194 if (err)
2195 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002196
Vivien Didelota935c052016-09-29 12:21:53 -04002197 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2198 if (err)
2199 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002200
Vivien Didelota935c052016-09-29 12:21:53 -04002201 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2202 if (err)
2203 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002204
Vivien Didelota935c052016-09-29 12:21:53 -04002205 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2206 if (err)
2207 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002208
Vivien Didelota935c052016-09-29 12:21:53 -04002209 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002210 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2211 unsigned int mask, shift;
2212
Vivien Didelota935c052016-09-29 12:21:53 -04002213 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002214 next.trunk = true;
2215 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2216 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2217 } else {
2218 next.trunk = false;
2219 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2220 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2221 }
2222
Vivien Didelota935c052016-09-29 12:21:53 -04002223 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002224 }
2225
2226 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002227 return 0;
2228}
2229
Vivien Didelot83dabd12016-08-31 11:50:04 -04002230static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2231 u16 fid, u16 vid, int port,
2232 struct switchdev_obj *obj,
2233 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002234{
2235 struct mv88e6xxx_atu_entry addr = {
2236 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2237 };
2238 int err;
2239
Vivien Didelotfad09c72016-06-21 12:28:20 -04002240 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002241 if (err)
2242 return err;
2243
2244 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002245 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002246 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002247 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002248
2249 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2250 break;
2251
Vivien Didelot83dabd12016-08-31 11:50:04 -04002252 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2253 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002254
Vivien Didelot83dabd12016-08-31 11:50:04 -04002255 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2256 struct switchdev_obj_port_fdb *fdb;
2257
2258 if (!is_unicast_ether_addr(addr.mac))
2259 continue;
2260
2261 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002262 fdb->vid = vid;
2263 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002264 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2265 fdb->ndm_state = NUD_NOARP;
2266 else
2267 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002268 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2269 struct switchdev_obj_port_mdb *mdb;
2270
2271 if (!is_multicast_ether_addr(addr.mac))
2272 continue;
2273
2274 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2275 mdb->vid = vid;
2276 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002277 } else {
2278 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002279 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002280
2281 err = cb(obj);
2282 if (err)
2283 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002284 } while (!is_broadcast_ether_addr(addr.mac));
2285
2286 return err;
2287}
2288
Vivien Didelot83dabd12016-08-31 11:50:04 -04002289static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2290 struct switchdev_obj *obj,
2291 int (*cb)(struct switchdev_obj *obj))
2292{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002293 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002294 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2295 };
2296 u16 fid;
2297 int err;
2298
2299 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002300 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002301 if (err)
2302 return err;
2303
2304 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2305 if (err)
2306 return err;
2307
2308 /* Dump VLANs' Filtering Information Databases */
2309 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2310 if (err)
2311 return err;
2312
2313 do {
2314 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2315 if (err)
2316 return err;
2317
2318 if (!vlan.valid)
2319 break;
2320
2321 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2322 obj, cb);
2323 if (err)
2324 return err;
2325 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2326
2327 return err;
2328}
2329
Vivien Didelotf81ec902016-05-09 13:22:58 -04002330static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2331 struct switchdev_obj_port_fdb *fdb,
2332 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002333{
Vivien Didelot04bed142016-08-31 18:06:13 -04002334 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002335 int err;
2336
Vivien Didelotfad09c72016-06-21 12:28:20 -04002337 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002338 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002339 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002340
2341 return err;
2342}
2343
Vivien Didelotf81ec902016-05-09 13:22:58 -04002344static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
2345 struct net_device *bridge)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002346{
Vivien Didelot04bed142016-08-31 18:06:13 -04002347 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002348 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002349
Vivien Didelotfad09c72016-06-21 12:28:20 -04002350 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002351
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002352 /* Assign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002353 chip->ports[port].bridge_dev = bridge;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002354
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002355 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002356 if (chip->ports[i].bridge_dev == bridge) {
2357 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002358 if (err)
2359 break;
2360 }
2361 }
2362
Vivien Didelotfad09c72016-06-21 12:28:20 -04002363 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002364
Vivien Didelot466dfa02016-02-26 13:16:05 -05002365 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002366}
2367
Vivien Didelotf81ec902016-05-09 13:22:58 -04002368static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002369{
Vivien Didelot04bed142016-08-31 18:06:13 -04002370 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002371 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002372 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002373
Vivien Didelotfad09c72016-06-21 12:28:20 -04002374 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002375
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002376 /* Unassign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002377 chip->ports[port].bridge_dev = NULL;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002378
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002379 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002380 if (i == port || chip->ports[i].bridge_dev == bridge)
2381 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002382 netdev_warn(ds->ports[i].netdev,
2383 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002384
Vivien Didelotfad09c72016-06-21 12:28:20 -04002385 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002386}
2387
Vivien Didelotfad09c72016-06-21 12:28:20 -04002388static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002389{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002390 bool ppu_active = mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE);
Vivien Didelot552238b2016-05-09 13:22:49 -04002391 u16 is_reset = (ppu_active ? 0x8800 : 0xc800);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002392 struct gpio_desc *gpiod = chip->reset;
Vivien Didelot552238b2016-05-09 13:22:49 -04002393 unsigned long timeout;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002394 u16 reg;
Vivien Didelota935c052016-09-29 12:21:53 -04002395 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002396 int i;
2397
2398 /* Set all ports to the disabled state. */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002399 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelote28def332016-11-04 03:23:27 +01002400 err = mv88e6xxx_port_set_state(chip, i,
2401 PORT_CONTROL_STATE_DISABLED);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002402 if (err)
2403 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002404 }
2405
2406 /* Wait for transmit queues to drain. */
2407 usleep_range(2000, 4000);
2408
2409 /* If there is a gpio connected to the reset pin, toggle it */
2410 if (gpiod) {
2411 gpiod_set_value_cansleep(gpiod, 1);
2412 usleep_range(10000, 20000);
2413 gpiod_set_value_cansleep(gpiod, 0);
2414 usleep_range(10000, 20000);
2415 }
2416
2417 /* Reset the switch. Keep the PPU active if requested. The PPU
2418 * needs to be active to support indirect phy register access
2419 * through global registers 0x18 and 0x19.
2420 */
2421 if (ppu_active)
Vivien Didelota935c052016-09-29 12:21:53 -04002422 err = mv88e6xxx_g1_write(chip, 0x04, 0xc000);
Vivien Didelot552238b2016-05-09 13:22:49 -04002423 else
Vivien Didelota935c052016-09-29 12:21:53 -04002424 err = mv88e6xxx_g1_write(chip, 0x04, 0xc400);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002425 if (err)
2426 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002427
2428 /* Wait up to one second for reset to complete. */
2429 timeout = jiffies + 1 * HZ;
2430 while (time_before(jiffies, timeout)) {
Vivien Didelota935c052016-09-29 12:21:53 -04002431 err = mv88e6xxx_g1_read(chip, 0x00, &reg);
2432 if (err)
2433 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002434
Vivien Didelota935c052016-09-29 12:21:53 -04002435 if ((reg & is_reset) == is_reset)
Vivien Didelot552238b2016-05-09 13:22:49 -04002436 break;
2437 usleep_range(1000, 2000);
2438 }
2439 if (time_after(jiffies, timeout))
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002440 err = -ETIMEDOUT;
Vivien Didelot552238b2016-05-09 13:22:49 -04002441 else
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002442 err = 0;
Vivien Didelot552238b2016-05-09 13:22:49 -04002443
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002444 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002445}
2446
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002447static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002448{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002449 u16 val;
2450 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002451
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002452 /* Clear Power Down bit */
2453 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2454 if (err)
2455 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002456
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002457 if (val & BMCR_PDOWN) {
2458 val &= ~BMCR_PDOWN;
2459 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002460 }
2461
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002462 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002463}
2464
Vivien Didelotfad09c72016-06-21 12:28:20 -04002465static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002466{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002467 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002468 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002469 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002470
Vivien Didelotd78343d2016-11-04 03:23:36 +01002471 /* MAC Forcing register: don't force link, speed, duplex or flow control
2472 * state to any particular values on physical ports, but force the CPU
2473 * port and all DSA ports to their maximum bandwidth and full duplex.
2474 */
2475 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2476 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2477 SPEED_MAX, DUPLEX_FULL,
2478 PHY_INTERFACE_MODE_NA);
2479 else
2480 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2481 SPEED_UNFORCED, DUPLEX_UNFORCED,
2482 PHY_INTERFACE_MODE_NA);
2483 if (err)
2484 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002485
2486 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2487 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2488 * tunneling, determine priority by looking at 802.1p and IP
2489 * priority fields (IP prio has precedence), and set STP state
2490 * to Forwarding.
2491 *
2492 * If this is the CPU link, use DSA or EDSA tagging depending
2493 * on which tagging mode was configured.
2494 *
2495 * If this is a link to another switch, use DSA tagging mode.
2496 *
2497 * If this is the upstream port for this switch, enable
2498 * forwarding of unknown unicasts and multicasts.
2499 */
2500 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002501 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2502 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2503 mv88e6xxx_6095_family(chip) || mv88e6xxx_6065_family(chip) ||
2504 mv88e6xxx_6185_family(chip) || mv88e6xxx_6320_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002505 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
2506 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2507 PORT_CONTROL_STATE_FORWARDING;
2508 if (dsa_is_cpu_port(ds, port)) {
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002509 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA))
Andrew Lunn5377b802016-06-04 21:17:02 +02002510 reg |= PORT_CONTROL_FRAME_ETHER_TYPE_DSA |
Andrew Lunnc047a1f2015-09-29 01:50:56 +02002511 PORT_CONTROL_FORWARD_UNKNOWN_MC;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002512 else
2513 reg |= PORT_CONTROL_DSA_TAG;
Jamie Lentinf027e0c2016-08-22 16:01:04 +02002514 reg |= PORT_CONTROL_EGRESS_ADD_TAG |
2515 PORT_CONTROL_FORWARD_UNKNOWN;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002516 }
Andrew Lunn6083ce72015-08-17 23:52:52 +02002517 if (dsa_is_dsa_port(ds, port)) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002518 if (mv88e6xxx_6095_family(chip) ||
2519 mv88e6xxx_6185_family(chip))
Andrew Lunn6083ce72015-08-17 23:52:52 +02002520 reg |= PORT_CONTROL_DSA_TAG;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002521 if (mv88e6xxx_6352_family(chip) ||
2522 mv88e6xxx_6351_family(chip) ||
2523 mv88e6xxx_6165_family(chip) ||
2524 mv88e6xxx_6097_family(chip) ||
2525 mv88e6xxx_6320_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002526 reg |= PORT_CONTROL_FRAME_MODE_DSA;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002527 }
2528
Andrew Lunn54d792f2015-05-06 01:09:47 +02002529 if (port == dsa_upstream_port(ds))
2530 reg |= PORT_CONTROL_FORWARD_UNKNOWN |
2531 PORT_CONTROL_FORWARD_UNKNOWN_MC;
2532 }
2533 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002534 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2535 if (err)
2536 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002537 }
2538
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002539 /* If this port is connected to a SerDes, make sure the SerDes is not
2540 * powered down.
2541 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002542 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002543 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2544 if (err)
2545 return err;
2546 reg &= PORT_STATUS_CMODE_MASK;
2547 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2548 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2549 (reg == PORT_STATUS_CMODE_SGMII)) {
2550 err = mv88e6xxx_serdes_power_on(chip);
2551 if (err < 0)
2552 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002553 }
2554 }
2555
Vivien Didelot8efdda42015-08-13 12:52:23 -04002556 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002557 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002558 * untagged frames on this port, do a destination address lookup on all
2559 * received packets as usual, disable ARP mirroring and don't send a
2560 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002561 */
2562 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002563 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2564 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2565 mv88e6xxx_6095_family(chip) || mv88e6xxx_6320_family(chip) ||
2566 mv88e6xxx_6185_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002567 reg = PORT_CONTROL_2_MAP_DA;
2568
Vivien Didelotfad09c72016-06-21 12:28:20 -04002569 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2570 mv88e6xxx_6165_family(chip) || mv88e6xxx_6320_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002571 reg |= PORT_CONTROL_2_JUMBO_10240;
2572
Vivien Didelotfad09c72016-06-21 12:28:20 -04002573 if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002574 /* Set the upstream port this port should use */
2575 reg |= dsa_upstream_port(ds);
2576 /* enable forwarding of unknown multicast addresses to
2577 * the upstream port
2578 */
2579 if (port == dsa_upstream_port(ds))
2580 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
2581 }
2582
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002583 reg |= PORT_CONTROL_2_8021Q_DISABLED;
Vivien Didelot8efdda42015-08-13 12:52:23 -04002584
Andrew Lunn54d792f2015-05-06 01:09:47 +02002585 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002586 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
2587 if (err)
2588 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002589 }
2590
2591 /* Port Association Vector: when learning source addresses
2592 * of packets, add the address to the address database using
2593 * a port bitmap that has only the bit for this port set and
2594 * the other bits clear.
2595 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002596 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002597 /* Disable learning for CPU port */
2598 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002599 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002600
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002601 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2602 if (err)
2603 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002604
2605 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002606 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2607 if (err)
2608 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002609
Vivien Didelotfad09c72016-06-21 12:28:20 -04002610 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2611 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2612 mv88e6xxx_6320_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002613 /* Do not limit the period of time that this port can
2614 * be paused for by the remote end or the period of
2615 * time that this port can pause the remote end.
2616 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002617 err = mv88e6xxx_port_write(chip, port, PORT_PAUSE_CTRL, 0x0000);
2618 if (err)
2619 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002620
2621 /* Port ATU control: disable limiting the number of
2622 * address database entries that this port is allowed
2623 * to use.
2624 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002625 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2626 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002627 /* Priority Override: disable DA, SA and VTU priority
2628 * override.
2629 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002630 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2631 0x0000);
2632 if (err)
2633 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002634
2635 /* Port Ethertype: use the Ethertype DSA Ethertype
2636 * value.
2637 */
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002638 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002639 err = mv88e6xxx_port_write(chip, port, PORT_ETH_TYPE,
2640 ETH_P_EDSA);
2641 if (err)
2642 return err;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002643 }
2644
Andrew Lunn54d792f2015-05-06 01:09:47 +02002645 /* Tag Remap: use an identity 802.1p prio -> switch
2646 * prio mapping.
2647 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002648 err = mv88e6xxx_port_write(chip, port, PORT_TAG_REGMAP_0123,
2649 0x3210);
2650 if (err)
2651 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002652
2653 /* Tag Remap 2: use an identity 802.1p prio -> switch
2654 * prio mapping.
2655 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002656 err = mv88e6xxx_port_write(chip, port, PORT_TAG_REGMAP_4567,
2657 0x7654);
2658 if (err)
2659 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002660 }
2661
Jamie Lentin1bc261f2016-08-22 22:47:08 +01002662 /* Rate Control: disable ingress rate limiting. */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002663 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2664 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
Vivien Didelotfad09c72016-06-21 12:28:20 -04002665 mv88e6xxx_6320_family(chip)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002666 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL,
2667 0x0001);
2668 if (err)
2669 return err;
Jamie Lentin1bc261f2016-08-22 22:47:08 +01002670 } else if (mv88e6xxx_6185_family(chip) || mv88e6xxx_6095_family(chip)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002671 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL,
2672 0x0000);
2673 if (err)
2674 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002675 }
2676
Guenter Roeck366f0a02015-03-26 18:36:30 -07002677 /* Port Control 1: disable trunking, disable sending
2678 * learning messages to this port.
Guenter Roeckd827e882015-03-26 18:36:29 -07002679 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002680 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_1, 0x0000);
2681 if (err)
2682 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002683
Vivien Didelot207afda2016-04-14 14:42:09 -04002684 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002685 * database, and allow bidirectional communication between the
2686 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002687 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002688 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002689 if (err)
2690 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002691
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002692 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2693 if (err)
2694 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002695
2696 /* Default VLAN ID and priority: don't set a default VLAN
2697 * ID, and set the default packet priority to zero.
2698 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002699 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002700}
2701
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002702static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002703{
2704 int err;
2705
Vivien Didelota935c052016-09-29 12:21:53 -04002706 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002707 if (err)
2708 return err;
2709
Vivien Didelota935c052016-09-29 12:21:53 -04002710 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002711 if (err)
2712 return err;
2713
Vivien Didelota935c052016-09-29 12:21:53 -04002714 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2715 if (err)
2716 return err;
2717
2718 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002719}
2720
Vivien Didelotacddbd22016-07-18 20:45:39 -04002721static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
2722 unsigned int msecs)
2723{
2724 const unsigned int coeff = chip->info->age_time_coeff;
2725 const unsigned int min = 0x01 * coeff;
2726 const unsigned int max = 0xff * coeff;
2727 u8 age_time;
2728 u16 val;
2729 int err;
2730
2731 if (msecs < min || msecs > max)
2732 return -ERANGE;
2733
2734 /* Round to nearest multiple of coeff */
2735 age_time = (msecs + coeff / 2) / coeff;
2736
Vivien Didelota935c052016-09-29 12:21:53 -04002737 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002738 if (err)
2739 return err;
2740
2741 /* AgeTime is 11:4 bits */
2742 val &= ~0xff0;
2743 val |= age_time << 4;
2744
Vivien Didelota935c052016-09-29 12:21:53 -04002745 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002746}
2747
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002748static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2749 unsigned int ageing_time)
2750{
Vivien Didelot04bed142016-08-31 18:06:13 -04002751 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002752 int err;
2753
2754 mutex_lock(&chip->reg_lock);
2755 err = mv88e6xxx_g1_set_age_time(chip, ageing_time);
2756 mutex_unlock(&chip->reg_lock);
2757
2758 return err;
2759}
2760
Vivien Didelot97299342016-07-18 20:45:30 -04002761static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002762{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002763 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002764 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot119477b2016-05-09 13:22:51 -04002765 u16 reg;
Vivien Didelot08a01262016-05-09 13:22:50 -04002766 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002767
Vivien Didelot119477b2016-05-09 13:22:51 -04002768 /* Enable the PHY Polling Unit if present, don't discard any packets,
2769 * and mask all interrupt sources.
2770 */
Andrew Lunndc30c352016-10-16 19:56:49 +02002771 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
2772 if (err < 0)
2773 return err;
2774
2775 reg &= ~GLOBAL_CONTROL_PPU_ENABLE;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002776 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU) ||
2777 mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE))
Vivien Didelot119477b2016-05-09 13:22:51 -04002778 reg |= GLOBAL_CONTROL_PPU_ENABLE;
2779
Vivien Didelota935c052016-09-29 12:21:53 -04002780 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
Vivien Didelot119477b2016-05-09 13:22:51 -04002781 if (err)
2782 return err;
2783
Vivien Didelotb0745e872016-05-09 13:22:53 -04002784 /* Configure the upstream port, and configure it as the port to which
2785 * ingress and egress and ARP monitor frames are to be sent.
2786 */
2787 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
2788 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
2789 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
Vivien Didelota935c052016-09-29 12:21:53 -04002790 err = mv88e6xxx_g1_write(chip, GLOBAL_MONITOR_CONTROL, reg);
Vivien Didelotb0745e872016-05-09 13:22:53 -04002791 if (err)
2792 return err;
2793
Vivien Didelot50484ff2016-05-09 13:22:54 -04002794 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002795 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2796 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2797 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002798 if (err)
2799 return err;
2800
Vivien Didelotacddbd22016-07-18 20:45:39 -04002801 /* Clear all the VTU and STU entries */
2802 err = _mv88e6xxx_vtu_stu_flush(chip);
2803 if (err < 0)
2804 return err;
2805
Vivien Didelot08a01262016-05-09 13:22:50 -04002806 /* Set the default address aging time to 5 minutes, and
2807 * enable address learn messages to be sent to all message
2808 * ports.
2809 */
Vivien Didelota935c052016-09-29 12:21:53 -04002810 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2811 GLOBAL_ATU_CONTROL_LEARN2ALL);
Vivien Didelot08a01262016-05-09 13:22:50 -04002812 if (err)
2813 return err;
2814
Vivien Didelotacddbd22016-07-18 20:45:39 -04002815 err = mv88e6xxx_g1_set_age_time(chip, 300000);
2816 if (err)
Vivien Didelot97299342016-07-18 20:45:30 -04002817 return err;
2818
2819 /* Clear all ATU entries */
2820 err = _mv88e6xxx_atu_flush(chip, 0, true);
2821 if (err)
2822 return err;
2823
Vivien Didelot08a01262016-05-09 13:22:50 -04002824 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002825 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002826 if (err)
2827 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002828 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002829 if (err)
2830 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002831 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002832 if (err)
2833 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002834 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002835 if (err)
2836 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002837 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002838 if (err)
2839 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002840 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002841 if (err)
2842 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002843 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002844 if (err)
2845 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002846 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002847 if (err)
2848 return err;
2849
2850 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002851 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002852 if (err)
2853 return err;
2854
Andrew Lunnde2273872016-11-21 23:27:01 +01002855 /* Initialize the statistics unit */
2856 err = mv88e6xxx_stats_set_histogram(chip);
2857 if (err)
2858 return err;
2859
Vivien Didelot97299342016-07-18 20:45:30 -04002860 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002861 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2862 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002863 if (err)
2864 return err;
2865
2866 /* Wait for the flush to complete. */
2867 err = _mv88e6xxx_stats_wait(chip);
2868 if (err)
2869 return err;
2870
2871 return 0;
2872}
2873
Vivien Didelotf81ec902016-05-09 13:22:58 -04002874static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002875{
Vivien Didelot04bed142016-08-31 18:06:13 -04002876 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002877 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002878 int i;
2879
Vivien Didelotfad09c72016-06-21 12:28:20 -04002880 chip->ds = ds;
2881 ds->slave_mii_bus = chip->mdio_bus;
Vivien Didelot552238b2016-05-09 13:22:49 -04002882
Vivien Didelotfad09c72016-06-21 12:28:20 -04002883 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002884
Vivien Didelot97299342016-07-18 20:45:30 -04002885 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002886 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002887 err = mv88e6xxx_setup_port(chip, i);
2888 if (err)
2889 goto unlock;
2890 }
2891
2892 /* Setup Switch Global 1 Registers */
2893 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002894 if (err)
2895 goto unlock;
2896
Vivien Didelot97299342016-07-18 20:45:30 -04002897 /* Setup Switch Global 2 Registers */
2898 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2899 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002900 if (err)
2901 goto unlock;
2902 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002903
Vivien Didelot6b17e862015-08-13 12:52:18 -04002904unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002905 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002906
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002907 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002908}
2909
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002910static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2911{
Vivien Didelot04bed142016-08-31 18:06:13 -04002912 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002913 int err;
2914
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002915 if (!chip->info->ops->set_switch_mac)
2916 return -EOPNOTSUPP;
2917
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002918 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002919 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002920 mutex_unlock(&chip->reg_lock);
2921
2922 return err;
2923}
2924
Vivien Didelote57e5e72016-08-15 17:19:00 -04002925static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002926{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002927 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002928 u16 val;
2929 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002930
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002931 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002932 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002933
Vivien Didelotfad09c72016-06-21 12:28:20 -04002934 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002935 err = mv88e6xxx_phy_read(chip, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002936 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002937
2938 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002939}
2940
Vivien Didelote57e5e72016-08-15 17:19:00 -04002941static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002942{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002943 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002944 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002945
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002946 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002947 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002948
Vivien Didelotfad09c72016-06-21 12:28:20 -04002949 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002950 err = mv88e6xxx_phy_write(chip, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002951 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002952
2953 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002954}
2955
Vivien Didelotfad09c72016-06-21 12:28:20 -04002956static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunnb516d452016-06-04 21:17:06 +02002957 struct device_node *np)
2958{
2959 static int index;
2960 struct mii_bus *bus;
2961 int err;
2962
Andrew Lunnb516d452016-06-04 21:17:06 +02002963 if (np)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002964 chip->mdio_np = of_get_child_by_name(np, "mdio");
Andrew Lunnb516d452016-06-04 21:17:06 +02002965
Vivien Didelotfad09c72016-06-21 12:28:20 -04002966 bus = devm_mdiobus_alloc(chip->dev);
Andrew Lunnb516d452016-06-04 21:17:06 +02002967 if (!bus)
2968 return -ENOMEM;
2969
Vivien Didelotfad09c72016-06-21 12:28:20 -04002970 bus->priv = (void *)chip;
Andrew Lunnb516d452016-06-04 21:17:06 +02002971 if (np) {
2972 bus->name = np->full_name;
2973 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2974 } else {
2975 bus->name = "mv88e6xxx SMI";
2976 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2977 }
2978
2979 bus->read = mv88e6xxx_mdio_read;
2980 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002981 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002982
Vivien Didelotfad09c72016-06-21 12:28:20 -04002983 if (chip->mdio_np)
2984 err = of_mdiobus_register(bus, chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002985 else
2986 err = mdiobus_register(bus);
2987 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002988 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunnb516d452016-06-04 21:17:06 +02002989 goto out;
2990 }
Vivien Didelotfad09c72016-06-21 12:28:20 -04002991 chip->mdio_bus = bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002992
2993 return 0;
2994
2995out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002996 if (chip->mdio_np)
2997 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002998
2999 return err;
3000}
3001
Vivien Didelotfad09c72016-06-21 12:28:20 -04003002static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02003003
3004{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003005 struct mii_bus *bus = chip->mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003006
3007 mdiobus_unregister(bus);
3008
Vivien Didelotfad09c72016-06-21 12:28:20 -04003009 if (chip->mdio_np)
3010 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003011}
3012
Guenter Roeckc22995c2015-07-25 09:42:28 -07003013#ifdef CONFIG_NET_DSA_HWMON
3014
3015static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp)
3016{
Vivien Didelot04bed142016-08-31 18:06:13 -04003017 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04003018 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003019 int ret;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003020
3021 *temp = 0;
3022
Vivien Didelotfad09c72016-06-21 12:28:20 -04003023 mutex_lock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003024
Vivien Didelot9c938292016-08-15 17:19:02 -04003025 ret = mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x6);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003026 if (ret < 0)
3027 goto error;
3028
3029 /* Enable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04003030 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003031 if (ret < 0)
3032 goto error;
3033
Vivien Didelot9c938292016-08-15 17:19:02 -04003034 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val | (1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07003035 if (ret < 0)
3036 goto error;
3037
3038 /* Wait for temperature to stabilize */
3039 usleep_range(10000, 12000);
3040
Vivien Didelot9c938292016-08-15 17:19:02 -04003041 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
3042 if (ret < 0)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003043 goto error;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003044
3045 /* Disable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04003046 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val & ~(1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07003047 if (ret < 0)
3048 goto error;
3049
3050 *temp = ((val & 0x1f) - 5) * 5;
3051
3052error:
Vivien Didelot9c938292016-08-15 17:19:02 -04003053 mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x0);
Vivien Didelotfad09c72016-06-21 12:28:20 -04003054 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003055 return ret;
3056}
3057
3058static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp)
3059{
Vivien Didelot04bed142016-08-31 18:06:13 -04003060 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003061 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003062 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003063 int ret;
3064
3065 *temp = 0;
3066
Vivien Didelot9c938292016-08-15 17:19:02 -04003067 mutex_lock(&chip->reg_lock);
3068 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 27, &val);
3069 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003070 if (ret < 0)
3071 return ret;
3072
Vivien Didelot9c938292016-08-15 17:19:02 -04003073 *temp = (val & 0xff) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003074
3075 return 0;
3076}
3077
Vivien Didelotf81ec902016-05-09 13:22:58 -04003078static int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003079{
Vivien Didelot04bed142016-08-31 18:06:13 -04003080 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn158bc062016-04-28 21:24:06 -04003081
Vivien Didelotfad09c72016-06-21 12:28:20 -04003082 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP))
Vivien Didelot6594f612016-05-09 13:22:42 -04003083 return -EOPNOTSUPP;
3084
Vivien Didelotfad09c72016-06-21 12:28:20 -04003085 if (mv88e6xxx_6320_family(chip) || mv88e6xxx_6352_family(chip))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003086 return mv88e63xx_get_temp(ds, temp);
3087
3088 return mv88e61xx_get_temp(ds, temp);
3089}
3090
Vivien Didelotf81ec902016-05-09 13:22:58 -04003091static int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003092{
Vivien Didelot04bed142016-08-31 18:06:13 -04003093 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003094 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003095 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003096 int ret;
3097
Vivien Didelotfad09c72016-06-21 12:28:20 -04003098 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003099 return -EOPNOTSUPP;
3100
3101 *temp = 0;
3102
Vivien Didelot9c938292016-08-15 17:19:02 -04003103 mutex_lock(&chip->reg_lock);
3104 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3105 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003106 if (ret < 0)
3107 return ret;
3108
Vivien Didelot9c938292016-08-15 17:19:02 -04003109 *temp = (((val >> 8) & 0x1f) * 5) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003110
3111 return 0;
3112}
3113
Vivien Didelotf81ec902016-05-09 13:22:58 -04003114static int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003115{
Vivien Didelot04bed142016-08-31 18:06:13 -04003116 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003117 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003118 u16 val;
3119 int err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003120
Vivien Didelotfad09c72016-06-21 12:28:20 -04003121 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003122 return -EOPNOTSUPP;
3123
Vivien Didelot9c938292016-08-15 17:19:02 -04003124 mutex_lock(&chip->reg_lock);
3125 err = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3126 if (err)
3127 goto unlock;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003128 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
Vivien Didelot9c938292016-08-15 17:19:02 -04003129 err = mv88e6xxx_phy_page_write(chip, phy, 6, 26,
3130 (val & 0xe0ff) | (temp << 8));
3131unlock:
3132 mutex_unlock(&chip->reg_lock);
3133
3134 return err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003135}
3136
Vivien Didelotf81ec902016-05-09 13:22:58 -04003137static int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003138{
Vivien Didelot04bed142016-08-31 18:06:13 -04003139 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003140 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003141 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003142 int ret;
3143
Vivien Didelotfad09c72016-06-21 12:28:20 -04003144 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003145 return -EOPNOTSUPP;
3146
3147 *alarm = false;
3148
Vivien Didelot9c938292016-08-15 17:19:02 -04003149 mutex_lock(&chip->reg_lock);
3150 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3151 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003152 if (ret < 0)
3153 return ret;
3154
Vivien Didelot9c938292016-08-15 17:19:02 -04003155 *alarm = !!(val & 0x40);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003156
3157 return 0;
3158}
3159#endif /* CONFIG_NET_DSA_HWMON */
3160
Vivien Didelot855b1932016-07-20 18:18:35 -04003161static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3162{
Vivien Didelot04bed142016-08-31 18:06:13 -04003163 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003164
3165 return chip->eeprom_len;
3166}
3167
Vivien Didelot855b1932016-07-20 18:18:35 -04003168static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3169 struct ethtool_eeprom *eeprom, u8 *data)
3170{
Vivien Didelot04bed142016-08-31 18:06:13 -04003171 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003172 int err;
3173
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003174 if (!chip->info->ops->get_eeprom)
3175 return -EOPNOTSUPP;
3176
Vivien Didelot855b1932016-07-20 18:18:35 -04003177 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003178 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003179 mutex_unlock(&chip->reg_lock);
3180
3181 if (err)
3182 return err;
3183
3184 eeprom->magic = 0xc3ec4951;
3185
3186 return 0;
3187}
3188
Vivien Didelot855b1932016-07-20 18:18:35 -04003189static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3190 struct ethtool_eeprom *eeprom, u8 *data)
3191{
Vivien Didelot04bed142016-08-31 18:06:13 -04003192 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003193 int err;
3194
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003195 if (!chip->info->ops->set_eeprom)
3196 return -EOPNOTSUPP;
3197
Vivien Didelot855b1932016-07-20 18:18:35 -04003198 if (eeprom->magic != 0xc3ec4951)
3199 return -EINVAL;
3200
3201 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003202 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003203 mutex_unlock(&chip->reg_lock);
3204
3205 return err;
3206}
3207
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003208static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003209 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003210 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003211 .phy_read = mv88e6xxx_phy_ppu_read,
3212 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003213 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003214 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003215 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003216 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003217 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3218 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003219};
3220
3221static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003222 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003223 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003224 .phy_read = mv88e6xxx_phy_ppu_read,
3225 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003226 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003227 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003228 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003229 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003230 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3231 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003232};
3233
3234static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003235 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003236 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003237 .phy_read = mv88e6xxx_read,
3238 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003239 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003240 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003241 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003242 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003243 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3244 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003245};
3246
3247static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003248 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003249 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003250 .phy_read = mv88e6xxx_phy_ppu_read,
3251 .phy_write = mv88e6xxx_phy_ppu_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 Didelot96a2b402016-11-04 03:23:35 +01003254 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003255 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003256 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3257 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003258};
3259
3260static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003261 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003262 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003263 .phy_read = mv88e6xxx_read,
3264 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003265 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003266 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003267 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003268 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003269 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3270 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003271};
3272
3273static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003274 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003275 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003276 .phy_read = mv88e6xxx_read,
3277 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003278 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003279 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003280 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003281 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003282 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3283 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003284};
3285
3286static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003287 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003288 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003289 .phy_read = mv88e6xxx_g2_smi_phy_read,
3290 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003291 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003292 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003293 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003294 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003295 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003296 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3297 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003298};
3299
3300static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003301 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003302 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3303 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003304 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003305 .phy_read = mv88e6xxx_g2_smi_phy_read,
3306 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003307 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003308 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003309 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003310 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003311 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003312 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3313 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003314};
3315
3316static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003317 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003318 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003319 .phy_read = mv88e6xxx_g2_smi_phy_read,
3320 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003321 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003322 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003323 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003324 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003325 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003326 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3327 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003328};
3329
3330static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003331 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003332 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3333 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003334 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003335 .phy_read = mv88e6xxx_g2_smi_phy_read,
3336 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003337 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003338 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003339 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003340 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003341 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003342 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3343 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003344};
3345
3346static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003347 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003348 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003349 .phy_read = mv88e6xxx_phy_ppu_read,
3350 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003351 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003352 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003353 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003354 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003355 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3356 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003357};
3358
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003359static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003360 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003361 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3362 .phy_read = mv88e6xxx_g2_smi_phy_read,
3363 .phy_write = mv88e6xxx_g2_smi_phy_write,
3364 .port_set_link = mv88e6xxx_port_set_link,
3365 .port_set_duplex = mv88e6xxx_port_set_duplex,
3366 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3367 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003368 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003369 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003370 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3371 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003372};
3373
3374static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003375 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003376 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3377 .phy_read = mv88e6xxx_g2_smi_phy_read,
3378 .phy_write = mv88e6xxx_g2_smi_phy_write,
3379 .port_set_link = mv88e6xxx_port_set_link,
3380 .port_set_duplex = mv88e6xxx_port_set_duplex,
3381 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3382 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003383 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003384 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003385 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3386 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003387};
3388
3389static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003390 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003391 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3392 .phy_read = mv88e6xxx_g2_smi_phy_read,
3393 .phy_write = mv88e6xxx_g2_smi_phy_write,
3394 .port_set_link = mv88e6xxx_port_set_link,
3395 .port_set_duplex = mv88e6xxx_port_set_duplex,
3396 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3397 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003398 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003399 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003400 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3401 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003402};
3403
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003404static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003405 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003406 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3407 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003408 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003409 .phy_read = mv88e6xxx_g2_smi_phy_read,
3410 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003411 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003412 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003413 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003414 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003415 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003416 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3417 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003418};
3419
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003420static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003421 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003422 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3423 .phy_read = mv88e6xxx_g2_smi_phy_read,
3424 .phy_write = mv88e6xxx_g2_smi_phy_write,
3425 .port_set_link = mv88e6xxx_port_set_link,
3426 .port_set_duplex = mv88e6xxx_port_set_duplex,
3427 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3428 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003429 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003430 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003431 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3432 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003433};
3434
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003435static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003436 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003437 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3438 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003439 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003440 .phy_read = mv88e6xxx_g2_smi_phy_read,
3441 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003442 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003443 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003444 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003445 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003446 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3447 .stats_get_strings = mv88e6320_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003448};
3449
3450static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003451 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003452 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3453 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003454 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003455 .phy_read = mv88e6xxx_g2_smi_phy_read,
3456 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003457 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003458 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003459 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003460 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003461 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3462 .stats_get_strings = mv88e6320_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003463};
3464
3465static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003466 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003467 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003468 .phy_read = mv88e6xxx_g2_smi_phy_read,
3469 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003470 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003471 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003472 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003473 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003474 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003475 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3476 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003477};
3478
3479static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003480 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003481 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003482 .phy_read = mv88e6xxx_g2_smi_phy_read,
3483 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003484 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003485 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003486 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003487 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003488 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003489 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3490 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003491};
3492
3493static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003494 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003495 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3496 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003497 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003498 .phy_read = mv88e6xxx_g2_smi_phy_read,
3499 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003500 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003501 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003502 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003503 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003504 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003505 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3506 .stats_get_strings = mv88e6095_stats_get_strings,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003507};
3508
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003509static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003510 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003511 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3512 .phy_read = mv88e6xxx_g2_smi_phy_read,
3513 .phy_write = mv88e6xxx_g2_smi_phy_write,
3514 .port_set_link = mv88e6xxx_port_set_link,
3515 .port_set_duplex = mv88e6xxx_port_set_duplex,
3516 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3517 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003518 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003519 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003520 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3521 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003522};
3523
3524static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003525 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003526 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3527 .phy_read = mv88e6xxx_g2_smi_phy_read,
3528 .phy_write = mv88e6xxx_g2_smi_phy_write,
3529 .port_set_link = mv88e6xxx_port_set_link,
3530 .port_set_duplex = mv88e6xxx_port_set_duplex,
3531 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3532 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003533 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003534 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003535 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3536 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003537};
3538
3539static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003540 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003541 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3542 .phy_read = mv88e6xxx_g2_smi_phy_read,
3543 .phy_write = mv88e6xxx_g2_smi_phy_write,
3544 .port_set_link = mv88e6xxx_port_set_link,
3545 .port_set_duplex = mv88e6xxx_port_set_duplex,
3546 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3547 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003548 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003549 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003550 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3551 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003552};
3553
Vivien Didelotf81ec902016-05-09 13:22:58 -04003554static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3555 [MV88E6085] = {
3556 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3557 .family = MV88E6XXX_FAMILY_6097,
3558 .name = "Marvell 88E6085",
3559 .num_databases = 4096,
3560 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003561 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003562 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003563 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003564 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003565 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003566 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003567 },
3568
3569 [MV88E6095] = {
3570 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3571 .family = MV88E6XXX_FAMILY_6095,
3572 .name = "Marvell 88E6095/88E6095F",
3573 .num_databases = 256,
3574 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003575 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003576 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003577 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003578 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003579 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003580 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003581 },
3582
3583 [MV88E6123] = {
3584 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3585 .family = MV88E6XXX_FAMILY_6165,
3586 .name = "Marvell 88E6123",
3587 .num_databases = 4096,
3588 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003589 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003590 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003591 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003592 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003593 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003594 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003595 },
3596
3597 [MV88E6131] = {
3598 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3599 .family = MV88E6XXX_FAMILY_6185,
3600 .name = "Marvell 88E6131",
3601 .num_databases = 256,
3602 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003603 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003604 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003605 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003606 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003607 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003608 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003609 },
3610
3611 [MV88E6161] = {
3612 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3613 .family = MV88E6XXX_FAMILY_6165,
3614 .name = "Marvell 88E6161",
3615 .num_databases = 4096,
3616 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003617 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003618 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003619 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003620 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003621 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003622 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003623 },
3624
3625 [MV88E6165] = {
3626 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3627 .family = MV88E6XXX_FAMILY_6165,
3628 .name = "Marvell 88E6165",
3629 .num_databases = 4096,
3630 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003631 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003632 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003633 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003634 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003635 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003636 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003637 },
3638
3639 [MV88E6171] = {
3640 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3641 .family = MV88E6XXX_FAMILY_6351,
3642 .name = "Marvell 88E6171",
3643 .num_databases = 4096,
3644 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003645 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003646 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003647 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003648 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003649 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003650 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003651 },
3652
3653 [MV88E6172] = {
3654 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3655 .family = MV88E6XXX_FAMILY_6352,
3656 .name = "Marvell 88E6172",
3657 .num_databases = 4096,
3658 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003659 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003660 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003661 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003662 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003663 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003664 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003665 },
3666
3667 [MV88E6175] = {
3668 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3669 .family = MV88E6XXX_FAMILY_6351,
3670 .name = "Marvell 88E6175",
3671 .num_databases = 4096,
3672 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003673 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003674 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003675 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003676 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003677 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003678 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003679 },
3680
3681 [MV88E6176] = {
3682 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3683 .family = MV88E6XXX_FAMILY_6352,
3684 .name = "Marvell 88E6176",
3685 .num_databases = 4096,
3686 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003687 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003688 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003689 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003690 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003691 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003692 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003693 },
3694
3695 [MV88E6185] = {
3696 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3697 .family = MV88E6XXX_FAMILY_6185,
3698 .name = "Marvell 88E6185",
3699 .num_databases = 256,
3700 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003701 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003702 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003703 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003704 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003705 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003706 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003707 },
3708
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003709 [MV88E6190] = {
3710 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3711 .family = MV88E6XXX_FAMILY_6390,
3712 .name = "Marvell 88E6190",
3713 .num_databases = 4096,
3714 .num_ports = 11, /* 10 + Z80 */
3715 .port_base_addr = 0x0,
3716 .global1_addr = 0x1b,
3717 .age_time_coeff = 15000,
3718 .g1_irqs = 9,
3719 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3720 .ops = &mv88e6190_ops,
3721 },
3722
3723 [MV88E6190X] = {
3724 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3725 .family = MV88E6XXX_FAMILY_6390,
3726 .name = "Marvell 88E6190X",
3727 .num_databases = 4096,
3728 .num_ports = 11, /* 10 + Z80 */
3729 .port_base_addr = 0x0,
3730 .global1_addr = 0x1b,
3731 .age_time_coeff = 15000,
3732 .g1_irqs = 9,
3733 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3734 .ops = &mv88e6190x_ops,
3735 },
3736
3737 [MV88E6191] = {
3738 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3739 .family = MV88E6XXX_FAMILY_6390,
3740 .name = "Marvell 88E6191",
3741 .num_databases = 4096,
3742 .num_ports = 11, /* 10 + Z80 */
3743 .port_base_addr = 0x0,
3744 .global1_addr = 0x1b,
3745 .age_time_coeff = 15000,
3746 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3747 .ops = &mv88e6391_ops,
3748 },
3749
Vivien Didelotf81ec902016-05-09 13:22:58 -04003750 [MV88E6240] = {
3751 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3752 .family = MV88E6XXX_FAMILY_6352,
3753 .name = "Marvell 88E6240",
3754 .num_databases = 4096,
3755 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003756 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003757 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003758 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003759 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003760 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003761 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003762 },
3763
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003764 [MV88E6290] = {
3765 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3766 .family = MV88E6XXX_FAMILY_6390,
3767 .name = "Marvell 88E6290",
3768 .num_databases = 4096,
3769 .num_ports = 11, /* 10 + Z80 */
3770 .port_base_addr = 0x0,
3771 .global1_addr = 0x1b,
3772 .age_time_coeff = 15000,
3773 .g1_irqs = 9,
3774 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3775 .ops = &mv88e6290_ops,
3776 },
3777
Vivien Didelotf81ec902016-05-09 13:22:58 -04003778 [MV88E6320] = {
3779 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3780 .family = MV88E6XXX_FAMILY_6320,
3781 .name = "Marvell 88E6320",
3782 .num_databases = 4096,
3783 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003784 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003785 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003786 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003787 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003788 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003789 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003790 },
3791
3792 [MV88E6321] = {
3793 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3794 .family = MV88E6XXX_FAMILY_6320,
3795 .name = "Marvell 88E6321",
3796 .num_databases = 4096,
3797 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003798 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003799 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003800 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003801 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003802 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003803 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003804 },
3805
3806 [MV88E6350] = {
3807 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3808 .family = MV88E6XXX_FAMILY_6351,
3809 .name = "Marvell 88E6350",
3810 .num_databases = 4096,
3811 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003812 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003813 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003814 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003815 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003816 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003817 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003818 },
3819
3820 [MV88E6351] = {
3821 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3822 .family = MV88E6XXX_FAMILY_6351,
3823 .name = "Marvell 88E6351",
3824 .num_databases = 4096,
3825 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003826 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003827 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003828 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003829 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003830 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003831 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003832 },
3833
3834 [MV88E6352] = {
3835 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
3836 .family = MV88E6XXX_FAMILY_6352,
3837 .name = "Marvell 88E6352",
3838 .num_databases = 4096,
3839 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003840 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003841 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003842 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003843 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003844 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003845 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003846 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003847 [MV88E6390] = {
3848 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
3849 .family = MV88E6XXX_FAMILY_6390,
3850 .name = "Marvell 88E6390",
3851 .num_databases = 4096,
3852 .num_ports = 11, /* 10 + Z80 */
3853 .port_base_addr = 0x0,
3854 .global1_addr = 0x1b,
3855 .age_time_coeff = 15000,
3856 .g1_irqs = 9,
3857 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3858 .ops = &mv88e6390_ops,
3859 },
3860 [MV88E6390X] = {
3861 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
3862 .family = MV88E6XXX_FAMILY_6390,
3863 .name = "Marvell 88E6390X",
3864 .num_databases = 4096,
3865 .num_ports = 11, /* 10 + Z80 */
3866 .port_base_addr = 0x0,
3867 .global1_addr = 0x1b,
3868 .age_time_coeff = 15000,
3869 .g1_irqs = 9,
3870 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3871 .ops = &mv88e6390x_ops,
3872 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003873};
3874
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003875static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003876{
Vivien Didelota439c062016-04-17 13:23:58 -04003877 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003878
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003879 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3880 if (mv88e6xxx_table[i].prod_num == prod_num)
3881 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003882
Vivien Didelotb9b37712015-10-30 19:39:48 -04003883 return NULL;
3884}
3885
Vivien Didelotfad09c72016-06-21 12:28:20 -04003886static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003887{
3888 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003889 unsigned int prod_num, rev;
3890 u16 id;
3891 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003892
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003893 mutex_lock(&chip->reg_lock);
3894 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
3895 mutex_unlock(&chip->reg_lock);
3896 if (err)
3897 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003898
3899 prod_num = (id & 0xfff0) >> 4;
3900 rev = id & 0x000f;
3901
3902 info = mv88e6xxx_lookup_info(prod_num);
3903 if (!info)
3904 return -ENODEV;
3905
Vivien Didelotcaac8542016-06-20 13:14:09 -04003906 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003907 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003908
Vivien Didelotca070c12016-09-02 14:45:34 -04003909 err = mv88e6xxx_g2_require(chip);
3910 if (err)
3911 return err;
3912
Vivien Didelotfad09c72016-06-21 12:28:20 -04003913 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3914 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003915
3916 return 0;
3917}
3918
Vivien Didelotfad09c72016-06-21 12:28:20 -04003919static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003920{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003921 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003922
Vivien Didelotfad09c72016-06-21 12:28:20 -04003923 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3924 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003925 return NULL;
3926
Vivien Didelotfad09c72016-06-21 12:28:20 -04003927 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003928
Vivien Didelotfad09c72016-06-21 12:28:20 -04003929 mutex_init(&chip->reg_lock);
Vivien Didelot469d7292016-06-20 13:14:06 -04003930
Vivien Didelotfad09c72016-06-21 12:28:20 -04003931 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003932}
3933
Vivien Didelote57e5e72016-08-15 17:19:00 -04003934static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
3935{
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003936 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
Vivien Didelote57e5e72016-08-15 17:19:00 -04003937 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003938}
3939
Andrew Lunn930188c2016-08-22 16:01:03 +02003940static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
3941{
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003942 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
Andrew Lunn930188c2016-08-22 16:01:03 +02003943 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02003944}
3945
Vivien Didelotfad09c72016-06-21 12:28:20 -04003946static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003947 struct mii_bus *bus, int sw_addr)
3948{
3949 /* ADDR[0] pin is unavailable externally and considered zero */
3950 if (sw_addr & 0x1)
3951 return -EINVAL;
3952
Vivien Didelot914b32f2016-06-20 13:14:11 -04003953 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003954 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04003955 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003956 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003957 else
3958 return -EINVAL;
3959
Vivien Didelotfad09c72016-06-21 12:28:20 -04003960 chip->bus = bus;
3961 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003962
3963 return 0;
3964}
3965
Andrew Lunn7b314362016-08-22 16:01:01 +02003966static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
3967{
Vivien Didelot04bed142016-08-31 18:06:13 -04003968 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003969
3970 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA))
3971 return DSA_TAG_PROTO_EDSA;
3972
3973 return DSA_TAG_PROTO_DSA;
Andrew Lunn7b314362016-08-22 16:01:01 +02003974}
3975
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02003976static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3977 struct device *host_dev, int sw_addr,
3978 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02003979{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003980 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04003981 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003982 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02003983
Vivien Didelota439c062016-04-17 13:23:58 -04003984 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02003985 if (!bus)
3986 return NULL;
3987
Vivien Didelotfad09c72016-06-21 12:28:20 -04003988 chip = mv88e6xxx_alloc_chip(dsa_dev);
3989 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003990 return NULL;
3991
Vivien Didelotcaac8542016-06-20 13:14:09 -04003992 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003993 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04003994
Vivien Didelotfad09c72016-06-21 12:28:20 -04003995 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003996 if (err)
3997 goto free;
3998
Vivien Didelotfad09c72016-06-21 12:28:20 -04003999 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004000 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004001 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004002
Andrew Lunndc30c352016-10-16 19:56:49 +02004003 mutex_lock(&chip->reg_lock);
4004 err = mv88e6xxx_switch_reset(chip);
4005 mutex_unlock(&chip->reg_lock);
4006 if (err)
4007 goto free;
4008
Vivien Didelote57e5e72016-08-15 17:19:00 -04004009 mv88e6xxx_phy_init(chip);
4010
Vivien Didelotfad09c72016-06-21 12:28:20 -04004011 err = mv88e6xxx_mdio_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004012 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004013 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004014
Vivien Didelotfad09c72016-06-21 12:28:20 -04004015 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004016
Vivien Didelotfad09c72016-06-21 12:28:20 -04004017 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004018free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004019 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004020
4021 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004022}
4023
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004024static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4025 const struct switchdev_obj_port_mdb *mdb,
4026 struct switchdev_trans *trans)
4027{
4028 /* We don't need any dynamic resource from the kernel (yet),
4029 * so skip the prepare phase.
4030 */
4031
4032 return 0;
4033}
4034
4035static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4036 const struct switchdev_obj_port_mdb *mdb,
4037 struct switchdev_trans *trans)
4038{
Vivien Didelot04bed142016-08-31 18:06:13 -04004039 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004040
4041 mutex_lock(&chip->reg_lock);
4042 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4043 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4044 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4045 mutex_unlock(&chip->reg_lock);
4046}
4047
4048static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4049 const struct switchdev_obj_port_mdb *mdb)
4050{
Vivien Didelot04bed142016-08-31 18:06:13 -04004051 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004052 int err;
4053
4054 mutex_lock(&chip->reg_lock);
4055 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4056 GLOBAL_ATU_DATA_STATE_UNUSED);
4057 mutex_unlock(&chip->reg_lock);
4058
4059 return err;
4060}
4061
4062static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4063 struct switchdev_obj_port_mdb *mdb,
4064 int (*cb)(struct switchdev_obj *obj))
4065{
Vivien Didelot04bed142016-08-31 18:06:13 -04004066 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004067 int err;
4068
4069 mutex_lock(&chip->reg_lock);
4070 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4071 mutex_unlock(&chip->reg_lock);
4072
4073 return err;
4074}
4075
Vivien Didelot9d490b42016-08-23 12:38:56 -04004076static struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004077 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004078 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004079 .setup = mv88e6xxx_setup,
4080 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004081 .adjust_link = mv88e6xxx_adjust_link,
4082 .get_strings = mv88e6xxx_get_strings,
4083 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4084 .get_sset_count = mv88e6xxx_get_sset_count,
4085 .set_eee = mv88e6xxx_set_eee,
4086 .get_eee = mv88e6xxx_get_eee,
4087#ifdef CONFIG_NET_DSA_HWMON
4088 .get_temp = mv88e6xxx_get_temp,
4089 .get_temp_limit = mv88e6xxx_get_temp_limit,
4090 .set_temp_limit = mv88e6xxx_set_temp_limit,
4091 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
4092#endif
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004093 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004094 .get_eeprom = mv88e6xxx_get_eeprom,
4095 .set_eeprom = mv88e6xxx_set_eeprom,
4096 .get_regs_len = mv88e6xxx_get_regs_len,
4097 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004098 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004099 .port_bridge_join = mv88e6xxx_port_bridge_join,
4100 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4101 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004102 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004103 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4104 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4105 .port_vlan_add = mv88e6xxx_port_vlan_add,
4106 .port_vlan_del = mv88e6xxx_port_vlan_del,
4107 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4108 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4109 .port_fdb_add = mv88e6xxx_port_fdb_add,
4110 .port_fdb_del = mv88e6xxx_port_fdb_del,
4111 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004112 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4113 .port_mdb_add = mv88e6xxx_port_mdb_add,
4114 .port_mdb_del = mv88e6xxx_port_mdb_del,
4115 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004116};
4117
Vivien Didelotfad09c72016-06-21 12:28:20 -04004118static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004119 struct device_node *np)
4120{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004121 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004122 struct dsa_switch *ds;
4123
4124 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
4125 if (!ds)
4126 return -ENOMEM;
4127
4128 ds->dev = dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004129 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004130 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004131
4132 dev_set_drvdata(dev, ds);
4133
4134 return dsa_register_switch(ds, np);
4135}
4136
Vivien Didelotfad09c72016-06-21 12:28:20 -04004137static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004138{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004139 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004140}
4141
Vivien Didelot57d32312016-06-20 13:13:58 -04004142static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004143{
4144 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004145 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004146 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004147 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004148 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004149 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004150
Vivien Didelotcaac8542016-06-20 13:14:09 -04004151 compat_info = of_device_get_match_data(dev);
4152 if (!compat_info)
4153 return -EINVAL;
4154
Vivien Didelotfad09c72016-06-21 12:28:20 -04004155 chip = mv88e6xxx_alloc_chip(dev);
4156 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004157 return -ENOMEM;
4158
Vivien Didelotfad09c72016-06-21 12:28:20 -04004159 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004160
Vivien Didelotfad09c72016-06-21 12:28:20 -04004161 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004162 if (err)
4163 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004164
Andrew Lunnb4308f02016-11-21 23:26:55 +01004165 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4166 if (IS_ERR(chip->reset))
4167 return PTR_ERR(chip->reset);
4168
Vivien Didelotfad09c72016-06-21 12:28:20 -04004169 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004170 if (err)
4171 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004172
Vivien Didelote57e5e72016-08-15 17:19:00 -04004173 mv88e6xxx_phy_init(chip);
4174
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004175 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004176 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004177 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004178
Andrew Lunndc30c352016-10-16 19:56:49 +02004179 mutex_lock(&chip->reg_lock);
4180 err = mv88e6xxx_switch_reset(chip);
4181 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004182 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004183 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004184
Andrew Lunndc30c352016-10-16 19:56:49 +02004185 chip->irq = of_irq_get(np, 0);
4186 if (chip->irq == -EPROBE_DEFER) {
4187 err = chip->irq;
4188 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004189 }
4190
Andrew Lunndc30c352016-10-16 19:56:49 +02004191 if (chip->irq > 0) {
4192 /* Has to be performed before the MDIO bus is created,
4193 * because the PHYs will link there interrupts to these
4194 * interrupt controllers
4195 */
4196 mutex_lock(&chip->reg_lock);
4197 err = mv88e6xxx_g1_irq_setup(chip);
4198 mutex_unlock(&chip->reg_lock);
4199
4200 if (err)
4201 goto out;
4202
4203 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4204 err = mv88e6xxx_g2_irq_setup(chip);
4205 if (err)
4206 goto out_g1_irq;
4207 }
4208 }
4209
4210 err = mv88e6xxx_mdio_register(chip, np);
4211 if (err)
4212 goto out_g2_irq;
4213
4214 err = mv88e6xxx_register_switch(chip, np);
4215 if (err)
4216 goto out_mdio;
4217
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004218 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004219
4220out_mdio:
4221 mv88e6xxx_mdio_unregister(chip);
4222out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004223 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004224 mv88e6xxx_g2_irq_free(chip);
4225out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004226 if (chip->irq > 0) {
4227 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004228 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004229 mutex_unlock(&chip->reg_lock);
4230 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004231out:
4232 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004233}
4234
4235static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4236{
4237 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004238 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004239
Andrew Lunn930188c2016-08-22 16:01:03 +02004240 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004241 mv88e6xxx_unregister_switch(chip);
4242 mv88e6xxx_mdio_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004243
Andrew Lunn467126442016-11-20 20:14:15 +01004244 if (chip->irq > 0) {
4245 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4246 mv88e6xxx_g2_irq_free(chip);
4247 mv88e6xxx_g1_irq_free(chip);
4248 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004249}
4250
4251static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004252 {
4253 .compatible = "marvell,mv88e6085",
4254 .data = &mv88e6xxx_table[MV88E6085],
4255 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004256 {
4257 .compatible = "marvell,mv88e6190",
4258 .data = &mv88e6xxx_table[MV88E6190],
4259 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004260 { /* sentinel */ },
4261};
4262
4263MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4264
4265static struct mdio_driver mv88e6xxx_driver = {
4266 .probe = mv88e6xxx_probe,
4267 .remove = mv88e6xxx_remove,
4268 .mdiodrv.driver = {
4269 .name = "mv88e6085",
4270 .of_match_table = mv88e6xxx_of_match,
4271 },
4272};
4273
Ben Hutchings98e67302011-11-25 14:36:19 +00004274static int __init mv88e6xxx_init(void)
4275{
Vivien Didelot9d490b42016-08-23 12:38:56 -04004276 register_switch_driver(&mv88e6xxx_switch_ops);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004277 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004278}
4279module_init(mv88e6xxx_init);
4280
4281static void __exit mv88e6xxx_cleanup(void)
4282{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004283 mdio_driver_unregister(&mv88e6xxx_driver);
Vivien Didelot9d490b42016-08-23 12:38:56 -04004284 unregister_switch_driver(&mv88e6xxx_switch_ops);
Ben Hutchings98e67302011-11-25 14:36:19 +00004285}
4286module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004287
4288MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4289MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4290MODULE_LICENSE("GPL");