blob: ac99e5b0ea758b01463579baebc089a88ec00641 [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 uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100903 struct mv88e6xxx_hw_stat *s,
Andrew Lunn80c46272015-06-20 18:42:30 +0200904 int port)
905{
Andrew Lunn80c46272015-06-20 18:42:30 +0200906 u32 low;
907 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100908 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200909 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200910 u64 value;
911
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100912 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100913 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200914 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
915 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200916 return UINT64_MAX;
917
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200918 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200919 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200920 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
921 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200922 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200923 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200924 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100925 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100926 case STATS_TYPE_BANK1:
927 reg = GLOBAL_STATS_OP_BANK_1;
928 /* fall through */
929 case STATS_TYPE_BANK0:
930 reg |= s->reg;
931 _mv88e6xxx_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200932 if (s->sizeof_stat == 8)
Andrew Lunndfafe442016-11-21 23:27:02 +0100933 _mv88e6xxx_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200934 }
935 value = (((u64)high) << 16) | low;
936 return value;
937}
938
Andrew Lunndfafe442016-11-21 23:27:02 +0100939static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
940 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100941{
942 struct mv88e6xxx_hw_stat *stat;
943 int i, j;
944
945 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
946 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100947 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100948 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
949 ETH_GSTRING_LEN);
950 j++;
951 }
952 }
953}
954
Andrew Lunndfafe442016-11-21 23:27:02 +0100955static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
956 uint8_t *data)
957{
958 mv88e6xxx_stats_get_strings(chip, data,
959 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
960}
961
962static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
963 uint8_t *data)
964{
965 mv88e6xxx_stats_get_strings(chip, data,
966 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
967}
968
969static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
970 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100971{
Vivien Didelot04bed142016-08-31 18:06:13 -0400972 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100973
974 if (chip->info->ops->stats_get_strings)
975 chip->info->ops->stats_get_strings(chip, data);
976}
977
978static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
979 int types)
980{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100981 struct mv88e6xxx_hw_stat *stat;
982 int i, j;
983
984 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
985 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100986 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100987 j++;
988 }
989 return j;
990}
991
Andrew Lunndfafe442016-11-21 23:27:02 +0100992static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
993{
994 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
995 STATS_TYPE_PORT);
996}
997
998static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
999{
1000 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
1001 STATS_TYPE_BANK1);
1002}
1003
1004static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
1005{
1006 struct mv88e6xxx_chip *chip = ds->priv;
1007
1008 if (chip->info->ops->stats_get_sset_count)
1009 return chip->info->ops->stats_get_sset_count(chip);
1010
1011 return 0;
1012}
1013
Andrew Lunn052f9472016-11-21 23:27:03 +01001014static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1015 uint64_t *data, int types)
1016{
1017 struct mv88e6xxx_hw_stat *stat;
1018 int i, j;
1019
1020 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
1021 stat = &mv88e6xxx_hw_stats[i];
1022 if (stat->type & types) {
1023 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port);
1024 j++;
1025 }
1026 }
1027}
1028
1029static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1030 uint64_t *data)
1031{
1032 return mv88e6xxx_stats_get_stats(chip, port, data,
1033 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
1034}
1035
1036static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
1037 uint64_t *data)
1038{
1039 return mv88e6xxx_stats_get_stats(chip, port, data,
1040 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
1041}
1042
1043static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1044 uint64_t *data)
1045{
1046 if (chip->info->ops->stats_get_stats)
1047 chip->info->ops->stats_get_stats(chip, port, data);
1048}
1049
Vivien Didelotf81ec902016-05-09 13:22:58 -04001050static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1051 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001052{
Vivien Didelot04bed142016-08-31 18:06:13 -04001053 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001054 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001055
Vivien Didelotfad09c72016-06-21 12:28:20 -04001056 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001057
Andrew Lunna605a0f2016-11-21 23:26:58 +01001058 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001059 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001060 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001061 return;
1062 }
Andrew Lunn052f9472016-11-21 23:27:03 +01001063
1064 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001065
Vivien Didelotfad09c72016-06-21 12:28:20 -04001066 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001067}
Ben Hutchings98e67302011-11-25 14:36:19 +00001068
Andrew Lunnde2273872016-11-21 23:27:01 +01001069static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1070{
1071 if (chip->info->ops->stats_set_histogram)
1072 return chip->info->ops->stats_set_histogram(chip);
1073
1074 return 0;
1075}
1076
Vivien Didelotf81ec902016-05-09 13:22:58 -04001077static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001078{
1079 return 32 * sizeof(u16);
1080}
1081
Vivien Didelotf81ec902016-05-09 13:22:58 -04001082static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1083 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001084{
Vivien Didelot04bed142016-08-31 18:06:13 -04001085 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001086 int err;
1087 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001088 u16 *p = _p;
1089 int i;
1090
1091 regs->version = 0;
1092
1093 memset(p, 0xff, 32 * sizeof(u16));
1094
Vivien Didelotfad09c72016-06-21 12:28:20 -04001095 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001096
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001097 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001098
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001099 err = mv88e6xxx_port_read(chip, port, i, &reg);
1100 if (!err)
1101 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001102 }
Vivien Didelot23062512016-05-09 13:22:45 -04001103
Vivien Didelotfad09c72016-06-21 12:28:20 -04001104 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001105}
1106
Vivien Didelotfad09c72016-06-21 12:28:20 -04001107static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001108{
Vivien Didelota935c052016-09-29 12:21:53 -04001109 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001110}
1111
Vivien Didelotf81ec902016-05-09 13:22:58 -04001112static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1113 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001114{
Vivien Didelot04bed142016-08-31 18:06:13 -04001115 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001116 u16 reg;
1117 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001118
Vivien Didelotfad09c72016-06-21 12:28:20 -04001119 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001120 return -EOPNOTSUPP;
1121
Vivien Didelotfad09c72016-06-21 12:28:20 -04001122 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001123
Vivien Didelot9c938292016-08-15 17:19:02 -04001124 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1125 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001126 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001127
1128 e->eee_enabled = !!(reg & 0x0200);
1129 e->tx_lpi_enabled = !!(reg & 0x0100);
1130
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001131 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001132 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001133 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001134
Andrew Lunncca8b132015-04-02 04:06:39 +02001135 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001136out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001137 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001138
1139 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001140}
1141
Vivien Didelotf81ec902016-05-09 13:22:58 -04001142static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1143 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001144{
Vivien Didelot04bed142016-08-31 18:06:13 -04001145 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001146 u16 reg;
1147 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001148
Vivien Didelotfad09c72016-06-21 12:28:20 -04001149 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001150 return -EOPNOTSUPP;
1151
Vivien Didelotfad09c72016-06-21 12:28:20 -04001152 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001153
Vivien Didelot9c938292016-08-15 17:19:02 -04001154 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1155 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001156 goto out;
1157
Vivien Didelot9c938292016-08-15 17:19:02 -04001158 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001159 if (e->eee_enabled)
1160 reg |= 0x0200;
1161 if (e->tx_lpi_enabled)
1162 reg |= 0x0100;
1163
Vivien Didelot9c938292016-08-15 17:19:02 -04001164 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001165out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001166 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001167
Vivien Didelot9c938292016-08-15 17:19:02 -04001168 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001169}
1170
Vivien Didelotfad09c72016-06-21 12:28:20 -04001171static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001172{
Vivien Didelota935c052016-09-29 12:21:53 -04001173 u16 val;
1174 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001175
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001176 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001177 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1178 if (err)
1179 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001180 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001181 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001182 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1183 if (err)
1184 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001185
Vivien Didelota935c052016-09-29 12:21:53 -04001186 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1187 (val & 0xfff) | ((fid << 8) & 0xf000));
1188 if (err)
1189 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001190
1191 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1192 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001193 }
1194
Vivien Didelota935c052016-09-29 12:21:53 -04001195 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1196 if (err)
1197 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001198
Vivien Didelotfad09c72016-06-21 12:28:20 -04001199 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001200}
1201
Vivien Didelotfad09c72016-06-21 12:28:20 -04001202static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001203 struct mv88e6xxx_atu_entry *entry)
1204{
1205 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1206
1207 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1208 unsigned int mask, shift;
1209
1210 if (entry->trunk) {
1211 data |= GLOBAL_ATU_DATA_TRUNK;
1212 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1213 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1214 } else {
1215 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1216 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1217 }
1218
1219 data |= (entry->portv_trunkid << shift) & mask;
1220 }
1221
Vivien Didelota935c052016-09-29 12:21:53 -04001222 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001223}
1224
Vivien Didelotfad09c72016-06-21 12:28:20 -04001225static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001226 struct mv88e6xxx_atu_entry *entry,
1227 bool static_too)
1228{
1229 int op;
1230 int err;
1231
Vivien Didelotfad09c72016-06-21 12:28:20 -04001232 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001233 if (err)
1234 return err;
1235
Vivien Didelotfad09c72016-06-21 12:28:20 -04001236 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001237 if (err)
1238 return err;
1239
1240 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001241 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1242 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1243 } else {
1244 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1245 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1246 }
1247
Vivien Didelotfad09c72016-06-21 12:28:20 -04001248 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001249}
1250
Vivien Didelotfad09c72016-06-21 12:28:20 -04001251static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001252 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001253{
1254 struct mv88e6xxx_atu_entry entry = {
1255 .fid = fid,
1256 .state = 0, /* EntryState bits must be 0 */
1257 };
1258
Vivien Didelotfad09c72016-06-21 12:28:20 -04001259 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001260}
1261
Vivien Didelotfad09c72016-06-21 12:28:20 -04001262static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001263 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001264{
1265 struct mv88e6xxx_atu_entry entry = {
1266 .trunk = false,
1267 .fid = fid,
1268 };
1269
1270 /* EntryState bits must be 0xF */
1271 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1272
1273 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1274 entry.portv_trunkid = (to_port & 0x0f) << 4;
1275 entry.portv_trunkid |= from_port & 0x0f;
1276
Vivien Didelotfad09c72016-06-21 12:28:20 -04001277 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001278}
1279
Vivien Didelotfad09c72016-06-21 12:28:20 -04001280static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001281 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001282{
1283 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001284 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001285}
1286
Vivien Didelotfad09c72016-06-21 12:28:20 -04001287static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001288{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001289 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001290 struct dsa_switch *ds = chip->ds;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001291 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001292 int i;
1293
1294 /* allow CPU port or DSA link(s) to send frames to every port */
1295 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001296 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001297 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001298 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001299 /* allow sending frames to every group member */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001300 if (bridge && chip->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001301 output_ports |= BIT(i);
1302
1303 /* allow sending frames to CPU port and DSA link(s) */
1304 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1305 output_ports |= BIT(i);
1306 }
1307 }
1308
1309 /* prevent frames from going back out of the port they came in on */
1310 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001311
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001312 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001313}
1314
Vivien Didelotf81ec902016-05-09 13:22:58 -04001315static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1316 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001317{
Vivien Didelot04bed142016-08-31 18:06:13 -04001318 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001319 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001320 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001321
1322 switch (state) {
1323 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001324 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001325 break;
1326 case BR_STATE_BLOCKING:
1327 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001328 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001329 break;
1330 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001331 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001332 break;
1333 case BR_STATE_FORWARDING:
1334 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001335 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001336 break;
1337 }
1338
Vivien Didelotfad09c72016-06-21 12:28:20 -04001339 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001340 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001341 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001342
1343 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001344 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001345}
1346
Vivien Didelot749efcb2016-09-22 16:49:24 -04001347static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1348{
1349 struct mv88e6xxx_chip *chip = ds->priv;
1350 int err;
1351
1352 mutex_lock(&chip->reg_lock);
1353 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1354 mutex_unlock(&chip->reg_lock);
1355
1356 if (err)
1357 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1358}
1359
Vivien Didelotfad09c72016-06-21 12:28:20 -04001360static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001361{
Vivien Didelota935c052016-09-29 12:21:53 -04001362 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001363}
1364
Vivien Didelotfad09c72016-06-21 12:28:20 -04001365static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001366{
Vivien Didelota935c052016-09-29 12:21:53 -04001367 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001368
Vivien Didelota935c052016-09-29 12:21:53 -04001369 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1370 if (err)
1371 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001372
Vivien Didelotfad09c72016-06-21 12:28:20 -04001373 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001374}
1375
Vivien Didelotfad09c72016-06-21 12:28:20 -04001376static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001377{
1378 int ret;
1379
Vivien Didelotfad09c72016-06-21 12:28:20 -04001380 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001381 if (ret < 0)
1382 return ret;
1383
Vivien Didelotfad09c72016-06-21 12:28:20 -04001384 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001385}
1386
Vivien Didelotfad09c72016-06-21 12:28:20 -04001387static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001388 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001389 unsigned int nibble_offset)
1390{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001391 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001392 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001393
1394 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001395 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001396
Vivien Didelota935c052016-09-29 12:21:53 -04001397 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1398 if (err)
1399 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001400 }
1401
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001402 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001403 unsigned int shift = (i % 4) * 4 + nibble_offset;
1404 u16 reg = regs[i / 4];
1405
1406 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1407 }
1408
1409 return 0;
1410}
1411
Vivien Didelotfad09c72016-06-21 12:28:20 -04001412static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001413 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001414{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001415 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001416}
1417
Vivien Didelotfad09c72016-06-21 12:28:20 -04001418static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001419 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001420{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001421 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001422}
1423
Vivien Didelotfad09c72016-06-21 12:28:20 -04001424static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001425 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001426 unsigned int nibble_offset)
1427{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001428 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001429 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001430
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001431 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001432 unsigned int shift = (i % 4) * 4 + nibble_offset;
1433 u8 data = entry->data[i];
1434
1435 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1436 }
1437
1438 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001439 u16 reg = regs[i];
1440
1441 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1442 if (err)
1443 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001444 }
1445
1446 return 0;
1447}
1448
Vivien Didelotfad09c72016-06-21 12:28:20 -04001449static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001450 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001451{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001452 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001453}
1454
Vivien Didelotfad09c72016-06-21 12:28:20 -04001455static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001456 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001457{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001458 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001459}
1460
Vivien Didelotfad09c72016-06-21 12:28:20 -04001461static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001462{
Vivien Didelota935c052016-09-29 12:21:53 -04001463 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1464 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001465}
1466
Vivien Didelotfad09c72016-06-21 12:28:20 -04001467static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001468 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001469{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001470 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001471 u16 val;
1472 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001473
Vivien Didelota935c052016-09-29 12:21:53 -04001474 err = _mv88e6xxx_vtu_wait(chip);
1475 if (err)
1476 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001477
Vivien Didelota935c052016-09-29 12:21:53 -04001478 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1479 if (err)
1480 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001481
Vivien Didelota935c052016-09-29 12:21:53 -04001482 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1483 if (err)
1484 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001485
Vivien Didelota935c052016-09-29 12:21:53 -04001486 next.vid = val & GLOBAL_VTU_VID_MASK;
1487 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001488
1489 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001490 err = mv88e6xxx_vtu_data_read(chip, &next);
1491 if (err)
1492 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001493
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001494 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001495 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1496 if (err)
1497 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001498
Vivien Didelota935c052016-09-29 12:21:53 -04001499 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001500 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001501 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1502 * VTU DBNum[3:0] are located in VTU Operation 3:0
1503 */
Vivien Didelota935c052016-09-29 12:21:53 -04001504 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1505 if (err)
1506 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001507
Vivien Didelota935c052016-09-29 12:21:53 -04001508 next.fid = (val & 0xf00) >> 4;
1509 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001510 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001511
Vivien Didelotfad09c72016-06-21 12:28:20 -04001512 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001513 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1514 if (err)
1515 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001516
Vivien Didelota935c052016-09-29 12:21:53 -04001517 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001518 }
1519 }
1520
1521 *entry = next;
1522 return 0;
1523}
1524
Vivien Didelotf81ec902016-05-09 13:22:58 -04001525static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1526 struct switchdev_obj_port_vlan *vlan,
1527 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001528{
Vivien Didelot04bed142016-08-31 18:06:13 -04001529 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001530 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001531 u16 pvid;
1532 int err;
1533
Vivien Didelotfad09c72016-06-21 12:28:20 -04001534 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001535 return -EOPNOTSUPP;
1536
Vivien Didelotfad09c72016-06-21 12:28:20 -04001537 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001538
Vivien Didelot77064f32016-11-04 03:23:30 +01001539 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001540 if (err)
1541 goto unlock;
1542
Vivien Didelotfad09c72016-06-21 12:28:20 -04001543 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001544 if (err)
1545 goto unlock;
1546
1547 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001548 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001549 if (err)
1550 break;
1551
1552 if (!next.valid)
1553 break;
1554
1555 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1556 continue;
1557
1558 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001559 vlan->vid_begin = next.vid;
1560 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001561 vlan->flags = 0;
1562
1563 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1564 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1565
1566 if (next.vid == pvid)
1567 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1568
1569 err = cb(&vlan->obj);
1570 if (err)
1571 break;
1572 } while (next.vid < GLOBAL_VTU_VID_MASK);
1573
1574unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001575 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001576
1577 return err;
1578}
1579
Vivien Didelotfad09c72016-06-21 12:28:20 -04001580static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001581 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001582{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001583 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001584 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001585 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001586
Vivien Didelota935c052016-09-29 12:21:53 -04001587 err = _mv88e6xxx_vtu_wait(chip);
1588 if (err)
1589 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001590
1591 if (!entry->valid)
1592 goto loadpurge;
1593
1594 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001595 err = mv88e6xxx_vtu_data_write(chip, entry);
1596 if (err)
1597 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001598
Vivien Didelotfad09c72016-06-21 12:28:20 -04001599 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001600 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001601 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1602 if (err)
1603 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001604 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001605
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001606 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001607 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001608 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1609 if (err)
1610 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001611 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001612 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1613 * VTU DBNum[3:0] are located in VTU Operation 3:0
1614 */
1615 op |= (entry->fid & 0xf0) << 8;
1616 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001617 }
1618
1619 reg = GLOBAL_VTU_VID_VALID;
1620loadpurge:
1621 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001622 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1623 if (err)
1624 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001625
Vivien Didelotfad09c72016-06-21 12:28:20 -04001626 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001627}
1628
Vivien Didelotfad09c72016-06-21 12:28:20 -04001629static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001630 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001631{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001632 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001633 u16 val;
1634 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001635
Vivien Didelota935c052016-09-29 12:21:53 -04001636 err = _mv88e6xxx_vtu_wait(chip);
1637 if (err)
1638 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001639
Vivien Didelota935c052016-09-29 12:21:53 -04001640 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1641 sid & GLOBAL_VTU_SID_MASK);
1642 if (err)
1643 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001644
Vivien Didelota935c052016-09-29 12:21:53 -04001645 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1646 if (err)
1647 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001648
Vivien Didelota935c052016-09-29 12:21:53 -04001649 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1650 if (err)
1651 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001652
Vivien Didelota935c052016-09-29 12:21:53 -04001653 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001654
Vivien Didelota935c052016-09-29 12:21:53 -04001655 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1656 if (err)
1657 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001658
Vivien Didelota935c052016-09-29 12:21:53 -04001659 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001660
1661 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001662 err = mv88e6xxx_stu_data_read(chip, &next);
1663 if (err)
1664 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001665 }
1666
1667 *entry = next;
1668 return 0;
1669}
1670
Vivien Didelotfad09c72016-06-21 12:28:20 -04001671static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001672 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001673{
1674 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001675 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001676
Vivien Didelota935c052016-09-29 12:21:53 -04001677 err = _mv88e6xxx_vtu_wait(chip);
1678 if (err)
1679 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001680
1681 if (!entry->valid)
1682 goto loadpurge;
1683
1684 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001685 err = mv88e6xxx_stu_data_write(chip, entry);
1686 if (err)
1687 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001688
1689 reg = GLOBAL_VTU_VID_VALID;
1690loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001691 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1692 if (err)
1693 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001694
1695 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001696 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1697 if (err)
1698 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001699
Vivien Didelotfad09c72016-06-21 12:28:20 -04001700 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001701}
1702
Vivien Didelotfad09c72016-06-21 12:28:20 -04001703static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001704{
1705 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001706 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001707 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001708
1709 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1710
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001711 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001712 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001713 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001714 if (err)
1715 return err;
1716
1717 set_bit(*fid, fid_bitmap);
1718 }
1719
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001720 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001721 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001722 if (err)
1723 return err;
1724
1725 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001726 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001727 if (err)
1728 return err;
1729
1730 if (!vlan.valid)
1731 break;
1732
1733 set_bit(vlan.fid, fid_bitmap);
1734 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1735
1736 /* The reset value 0x000 is used to indicate that multiple address
1737 * databases are not needed. Return the next positive available.
1738 */
1739 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001740 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001741 return -ENOSPC;
1742
1743 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001744 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001745}
1746
Vivien Didelotfad09c72016-06-21 12:28:20 -04001747static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001748 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001749{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001750 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001751 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001752 .valid = true,
1753 .vid = vid,
1754 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001755 int i, err;
1756
Vivien Didelotfad09c72016-06-21 12:28:20 -04001757 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001758 if (err)
1759 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001760
Vivien Didelot3d131f02015-11-03 10:52:52 -05001761 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001762 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001763 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1764 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1765 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001766
Vivien Didelotfad09c72016-06-21 12:28:20 -04001767 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
1768 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001769 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001770
1771 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1772 * implemented, only one STU entry is needed to cover all VTU
1773 * entries. Thus, validate the SID 0.
1774 */
1775 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001776 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001777 if (err)
1778 return err;
1779
1780 if (vstp.sid != vlan.sid || !vstp.valid) {
1781 memset(&vstp, 0, sizeof(vstp));
1782 vstp.valid = true;
1783 vstp.sid = vlan.sid;
1784
Vivien Didelotfad09c72016-06-21 12:28:20 -04001785 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001786 if (err)
1787 return err;
1788 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001789 }
1790
1791 *entry = vlan;
1792 return 0;
1793}
1794
Vivien Didelotfad09c72016-06-21 12:28:20 -04001795static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001796 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001797{
1798 int err;
1799
1800 if (!vid)
1801 return -EINVAL;
1802
Vivien Didelotfad09c72016-06-21 12:28:20 -04001803 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001804 if (err)
1805 return err;
1806
Vivien Didelotfad09c72016-06-21 12:28:20 -04001807 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001808 if (err)
1809 return err;
1810
1811 if (entry->vid != vid || !entry->valid) {
1812 if (!creat)
1813 return -EOPNOTSUPP;
1814 /* -ENOENT would've been more appropriate, but switchdev expects
1815 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1816 */
1817
Vivien Didelotfad09c72016-06-21 12:28:20 -04001818 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001819 }
1820
1821 return err;
1822}
1823
Vivien Didelotda9c3592016-02-12 12:09:40 -05001824static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1825 u16 vid_begin, u16 vid_end)
1826{
Vivien Didelot04bed142016-08-31 18:06:13 -04001827 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001828 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001829 int i, err;
1830
1831 if (!vid_begin)
1832 return -EOPNOTSUPP;
1833
Vivien Didelotfad09c72016-06-21 12:28:20 -04001834 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001835
Vivien Didelotfad09c72016-06-21 12:28:20 -04001836 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001837 if (err)
1838 goto unlock;
1839
1840 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001841 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001842 if (err)
1843 goto unlock;
1844
1845 if (!vlan.valid)
1846 break;
1847
1848 if (vlan.vid > vid_end)
1849 break;
1850
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001851 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001852 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1853 continue;
1854
1855 if (vlan.data[i] ==
1856 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1857 continue;
1858
Vivien Didelotfad09c72016-06-21 12:28:20 -04001859 if (chip->ports[i].bridge_dev ==
1860 chip->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001861 break; /* same bridge, check next VLAN */
1862
Andrew Lunnc8b09802016-06-04 21:16:57 +02001863 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001864 "hardware VLAN %d already used by %s\n",
1865 vlan.vid,
Vivien Didelotfad09c72016-06-21 12:28:20 -04001866 netdev_name(chip->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001867 err = -EOPNOTSUPP;
1868 goto unlock;
1869 }
1870 } while (vlan.vid < vid_end);
1871
1872unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001873 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001874
1875 return err;
1876}
1877
Vivien Didelotf81ec902016-05-09 13:22:58 -04001878static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1879 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001880{
Vivien Didelot04bed142016-08-31 18:06:13 -04001881 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001882 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001883 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001884 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001885
Vivien Didelotfad09c72016-06-21 12:28:20 -04001886 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001887 return -EOPNOTSUPP;
1888
Vivien Didelotfad09c72016-06-21 12:28:20 -04001889 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001890 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001891 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001892
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001893 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001894}
1895
Vivien Didelot57d32312016-06-20 13:13:58 -04001896static int
1897mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1898 const struct switchdev_obj_port_vlan *vlan,
1899 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001900{
Vivien Didelot04bed142016-08-31 18:06:13 -04001901 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001902 int err;
1903
Vivien Didelotfad09c72016-06-21 12:28:20 -04001904 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001905 return -EOPNOTSUPP;
1906
Vivien Didelotda9c3592016-02-12 12:09:40 -05001907 /* If the requested port doesn't belong to the same bridge as the VLAN
1908 * members, do not support it (yet) and fallback to software VLAN.
1909 */
1910 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1911 vlan->vid_end);
1912 if (err)
1913 return err;
1914
Vivien Didelot76e398a2015-11-01 12:33:55 -05001915 /* We don't need any dynamic resource from the kernel (yet),
1916 * so skip the prepare phase.
1917 */
1918 return 0;
1919}
1920
Vivien Didelotfad09c72016-06-21 12:28:20 -04001921static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001922 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001923{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001924 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001925 int err;
1926
Vivien Didelotfad09c72016-06-21 12:28:20 -04001927 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001928 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001929 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001930
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001931 vlan.data[port] = untagged ?
1932 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1933 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1934
Vivien Didelotfad09c72016-06-21 12:28:20 -04001935 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001936}
1937
Vivien Didelotf81ec902016-05-09 13:22:58 -04001938static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1939 const struct switchdev_obj_port_vlan *vlan,
1940 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001941{
Vivien Didelot04bed142016-08-31 18:06:13 -04001942 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001943 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1944 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1945 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001946
Vivien Didelotfad09c72016-06-21 12:28:20 -04001947 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001948 return;
1949
Vivien Didelotfad09c72016-06-21 12:28:20 -04001950 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001951
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001952 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001953 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001954 netdev_err(ds->ports[port].netdev,
1955 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001956 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001957
Vivien Didelot77064f32016-11-04 03:23:30 +01001958 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001959 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001960 vlan->vid_end);
1961
Vivien Didelotfad09c72016-06-21 12:28:20 -04001962 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001963}
1964
Vivien Didelotfad09c72016-06-21 12:28:20 -04001965static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001966 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001967{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001968 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001969 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001970 int i, err;
1971
Vivien Didelotfad09c72016-06-21 12:28:20 -04001972 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001973 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001974 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001975
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001976 /* Tell switchdev if this VLAN is handled in software */
1977 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001978 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001979
1980 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1981
1982 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001983 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001984 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001985 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001986 continue;
1987
1988 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001989 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001990 break;
1991 }
1992 }
1993
Vivien Didelotfad09c72016-06-21 12:28:20 -04001994 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001995 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001996 return err;
1997
Vivien Didelotfad09c72016-06-21 12:28:20 -04001998 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001999}
2000
Vivien Didelotf81ec902016-05-09 13:22:58 -04002001static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
2002 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05002003{
Vivien Didelot04bed142016-08-31 18:06:13 -04002004 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05002005 u16 pvid, vid;
2006 int err = 0;
2007
Vivien Didelotfad09c72016-06-21 12:28:20 -04002008 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04002009 return -EOPNOTSUPP;
2010
Vivien Didelotfad09c72016-06-21 12:28:20 -04002011 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002012
Vivien Didelot77064f32016-11-04 03:23:30 +01002013 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002014 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002015 goto unlock;
2016
Vivien Didelot76e398a2015-11-01 12:33:55 -05002017 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002018 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002019 if (err)
2020 goto unlock;
2021
2022 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01002023 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05002024 if (err)
2025 goto unlock;
2026 }
2027 }
2028
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002029unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002030 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04002031
2032 return err;
2033}
2034
Vivien Didelotfad09c72016-06-21 12:28:20 -04002035static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04002036 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002037{
Vivien Didelota935c052016-09-29 12:21:53 -04002038 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002039
2040 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002041 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
2042 (addr[i * 2] << 8) | addr[i * 2 + 1]);
2043 if (err)
2044 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002045 }
2046
2047 return 0;
2048}
2049
Vivien Didelotfad09c72016-06-21 12:28:20 -04002050static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04002051 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002052{
Vivien Didelota935c052016-09-29 12:21:53 -04002053 u16 val;
2054 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002055
2056 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002057 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
2058 if (err)
2059 return err;
2060
2061 addr[i * 2] = val >> 8;
2062 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002063 }
2064
2065 return 0;
2066}
2067
Vivien Didelotfad09c72016-06-21 12:28:20 -04002068static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04002069 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002070{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002071 int ret;
2072
Vivien Didelotfad09c72016-06-21 12:28:20 -04002073 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002074 if (ret < 0)
2075 return ret;
2076
Vivien Didelotfad09c72016-06-21 12:28:20 -04002077 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002078 if (ret < 0)
2079 return ret;
2080
Vivien Didelotfad09c72016-06-21 12:28:20 -04002081 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002082 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002083 return ret;
2084
Vivien Didelotfad09c72016-06-21 12:28:20 -04002085 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002086}
David S. Millercdf09692015-08-11 12:00:37 -07002087
Vivien Didelot88472932016-09-19 19:56:11 -04002088static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2089 struct mv88e6xxx_atu_entry *entry);
2090
2091static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2092 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2093{
2094 struct mv88e6xxx_atu_entry next;
2095 int err;
2096
2097 eth_broadcast_addr(next.mac);
2098
2099 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2100 if (err)
2101 return err;
2102
2103 do {
2104 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2105 if (err)
2106 return err;
2107
2108 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2109 break;
2110
2111 if (ether_addr_equal(next.mac, addr)) {
2112 *entry = next;
2113 return 0;
2114 }
2115 } while (!is_broadcast_ether_addr(next.mac));
2116
2117 memset(entry, 0, sizeof(*entry));
2118 entry->fid = fid;
2119 ether_addr_copy(entry->mac, addr);
2120
2121 return 0;
2122}
2123
Vivien Didelot83dabd12016-08-31 11:50:04 -04002124static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2125 const unsigned char *addr, u16 vid,
2126 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002127{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002128 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002129 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002130 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002131
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002132 /* Null VLAN ID corresponds to the port private database */
2133 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002134 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002135 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002136 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002137 if (err)
2138 return err;
2139
Vivien Didelot88472932016-09-19 19:56:11 -04002140 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2141 if (err)
2142 return err;
2143
2144 /* Purge the ATU entry only if no port is using it anymore */
2145 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2146 entry.portv_trunkid &= ~BIT(port);
2147 if (!entry.portv_trunkid)
2148 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2149 } else {
2150 entry.portv_trunkid |= BIT(port);
2151 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002152 }
2153
Vivien Didelotfad09c72016-06-21 12:28:20 -04002154 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002155}
2156
Vivien Didelotf81ec902016-05-09 13:22:58 -04002157static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2158 const struct switchdev_obj_port_fdb *fdb,
2159 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002160{
2161 /* We don't need any dynamic resource from the kernel (yet),
2162 * so skip the prepare phase.
2163 */
2164 return 0;
2165}
2166
Vivien Didelotf81ec902016-05-09 13:22:58 -04002167static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2168 const struct switchdev_obj_port_fdb *fdb,
2169 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002170{
Vivien Didelot04bed142016-08-31 18:06:13 -04002171 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002172
Vivien Didelotfad09c72016-06-21 12:28:20 -04002173 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002174 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2175 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2176 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002177 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002178}
2179
Vivien Didelotf81ec902016-05-09 13:22:58 -04002180static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2181 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002182{
Vivien Didelot04bed142016-08-31 18:06:13 -04002183 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002184 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002185
Vivien Didelotfad09c72016-06-21 12:28:20 -04002186 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002187 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2188 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002189 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002190
Vivien Didelot83dabd12016-08-31 11:50:04 -04002191 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002192}
2193
Vivien Didelotfad09c72016-06-21 12:28:20 -04002194static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002195 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002196{
Vivien Didelot1d194042015-08-10 09:09:51 -04002197 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002198 u16 val;
2199 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002200
2201 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002202
Vivien Didelota935c052016-09-29 12:21:53 -04002203 err = _mv88e6xxx_atu_wait(chip);
2204 if (err)
2205 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002206
Vivien Didelota935c052016-09-29 12:21:53 -04002207 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2208 if (err)
2209 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002210
Vivien Didelota935c052016-09-29 12:21:53 -04002211 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2212 if (err)
2213 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002214
Vivien Didelota935c052016-09-29 12:21:53 -04002215 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2216 if (err)
2217 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002218
Vivien Didelota935c052016-09-29 12:21:53 -04002219 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002220 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2221 unsigned int mask, shift;
2222
Vivien Didelota935c052016-09-29 12:21:53 -04002223 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002224 next.trunk = true;
2225 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2226 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2227 } else {
2228 next.trunk = false;
2229 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2230 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2231 }
2232
Vivien Didelota935c052016-09-29 12:21:53 -04002233 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002234 }
2235
2236 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002237 return 0;
2238}
2239
Vivien Didelot83dabd12016-08-31 11:50:04 -04002240static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2241 u16 fid, u16 vid, int port,
2242 struct switchdev_obj *obj,
2243 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002244{
2245 struct mv88e6xxx_atu_entry addr = {
2246 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2247 };
2248 int err;
2249
Vivien Didelotfad09c72016-06-21 12:28:20 -04002250 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002251 if (err)
2252 return err;
2253
2254 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002255 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002256 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002257 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002258
2259 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2260 break;
2261
Vivien Didelot83dabd12016-08-31 11:50:04 -04002262 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2263 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002264
Vivien Didelot83dabd12016-08-31 11:50:04 -04002265 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2266 struct switchdev_obj_port_fdb *fdb;
2267
2268 if (!is_unicast_ether_addr(addr.mac))
2269 continue;
2270
2271 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002272 fdb->vid = vid;
2273 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002274 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2275 fdb->ndm_state = NUD_NOARP;
2276 else
2277 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002278 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2279 struct switchdev_obj_port_mdb *mdb;
2280
2281 if (!is_multicast_ether_addr(addr.mac))
2282 continue;
2283
2284 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2285 mdb->vid = vid;
2286 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002287 } else {
2288 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002289 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002290
2291 err = cb(obj);
2292 if (err)
2293 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002294 } while (!is_broadcast_ether_addr(addr.mac));
2295
2296 return err;
2297}
2298
Vivien Didelot83dabd12016-08-31 11:50:04 -04002299static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2300 struct switchdev_obj *obj,
2301 int (*cb)(struct switchdev_obj *obj))
2302{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002303 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002304 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2305 };
2306 u16 fid;
2307 int err;
2308
2309 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002310 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002311 if (err)
2312 return err;
2313
2314 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2315 if (err)
2316 return err;
2317
2318 /* Dump VLANs' Filtering Information Databases */
2319 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2320 if (err)
2321 return err;
2322
2323 do {
2324 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2325 if (err)
2326 return err;
2327
2328 if (!vlan.valid)
2329 break;
2330
2331 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2332 obj, cb);
2333 if (err)
2334 return err;
2335 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2336
2337 return err;
2338}
2339
Vivien Didelotf81ec902016-05-09 13:22:58 -04002340static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2341 struct switchdev_obj_port_fdb *fdb,
2342 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002343{
Vivien Didelot04bed142016-08-31 18:06:13 -04002344 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002345 int err;
2346
Vivien Didelotfad09c72016-06-21 12:28:20 -04002347 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002348 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002349 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002350
2351 return err;
2352}
2353
Vivien Didelotf81ec902016-05-09 13:22:58 -04002354static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
2355 struct net_device *bridge)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002356{
Vivien Didelot04bed142016-08-31 18:06:13 -04002357 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002358 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002359
Vivien Didelotfad09c72016-06-21 12:28:20 -04002360 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002361
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002362 /* Assign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002363 chip->ports[port].bridge_dev = bridge;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002364
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002365 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002366 if (chip->ports[i].bridge_dev == bridge) {
2367 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002368 if (err)
2369 break;
2370 }
2371 }
2372
Vivien Didelotfad09c72016-06-21 12:28:20 -04002373 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002374
Vivien Didelot466dfa02016-02-26 13:16:05 -05002375 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002376}
2377
Vivien Didelotf81ec902016-05-09 13:22:58 -04002378static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002379{
Vivien Didelot04bed142016-08-31 18:06:13 -04002380 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002381 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002382 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002383
Vivien Didelotfad09c72016-06-21 12:28:20 -04002384 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002385
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002386 /* Unassign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002387 chip->ports[port].bridge_dev = NULL;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002388
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002389 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002390 if (i == port || chip->ports[i].bridge_dev == bridge)
2391 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002392 netdev_warn(ds->ports[i].netdev,
2393 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002394
Vivien Didelotfad09c72016-06-21 12:28:20 -04002395 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002396}
2397
Vivien Didelotfad09c72016-06-21 12:28:20 -04002398static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002399{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002400 bool ppu_active = mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE);
Vivien Didelot552238b2016-05-09 13:22:49 -04002401 u16 is_reset = (ppu_active ? 0x8800 : 0xc800);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002402 struct gpio_desc *gpiod = chip->reset;
Vivien Didelot552238b2016-05-09 13:22:49 -04002403 unsigned long timeout;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002404 u16 reg;
Vivien Didelota935c052016-09-29 12:21:53 -04002405 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002406 int i;
2407
2408 /* Set all ports to the disabled state. */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002409 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelote28def332016-11-04 03:23:27 +01002410 err = mv88e6xxx_port_set_state(chip, i,
2411 PORT_CONTROL_STATE_DISABLED);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002412 if (err)
2413 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002414 }
2415
2416 /* Wait for transmit queues to drain. */
2417 usleep_range(2000, 4000);
2418
2419 /* If there is a gpio connected to the reset pin, toggle it */
2420 if (gpiod) {
2421 gpiod_set_value_cansleep(gpiod, 1);
2422 usleep_range(10000, 20000);
2423 gpiod_set_value_cansleep(gpiod, 0);
2424 usleep_range(10000, 20000);
2425 }
2426
2427 /* Reset the switch. Keep the PPU active if requested. The PPU
2428 * needs to be active to support indirect phy register access
2429 * through global registers 0x18 and 0x19.
2430 */
2431 if (ppu_active)
Vivien Didelota935c052016-09-29 12:21:53 -04002432 err = mv88e6xxx_g1_write(chip, 0x04, 0xc000);
Vivien Didelot552238b2016-05-09 13:22:49 -04002433 else
Vivien Didelota935c052016-09-29 12:21:53 -04002434 err = mv88e6xxx_g1_write(chip, 0x04, 0xc400);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002435 if (err)
2436 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002437
2438 /* Wait up to one second for reset to complete. */
2439 timeout = jiffies + 1 * HZ;
2440 while (time_before(jiffies, timeout)) {
Vivien Didelota935c052016-09-29 12:21:53 -04002441 err = mv88e6xxx_g1_read(chip, 0x00, &reg);
2442 if (err)
2443 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002444
Vivien Didelota935c052016-09-29 12:21:53 -04002445 if ((reg & is_reset) == is_reset)
Vivien Didelot552238b2016-05-09 13:22:49 -04002446 break;
2447 usleep_range(1000, 2000);
2448 }
2449 if (time_after(jiffies, timeout))
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002450 err = -ETIMEDOUT;
Vivien Didelot552238b2016-05-09 13:22:49 -04002451 else
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002452 err = 0;
Vivien Didelot552238b2016-05-09 13:22:49 -04002453
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002454 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002455}
2456
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002457static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002458{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002459 u16 val;
2460 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002461
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002462 /* Clear Power Down bit */
2463 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2464 if (err)
2465 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002466
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002467 if (val & BMCR_PDOWN) {
2468 val &= ~BMCR_PDOWN;
2469 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002470 }
2471
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002472 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002473}
2474
Vivien Didelotfad09c72016-06-21 12:28:20 -04002475static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002476{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002477 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002478 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002479 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002480
Vivien Didelotd78343d2016-11-04 03:23:36 +01002481 /* MAC Forcing register: don't force link, speed, duplex or flow control
2482 * state to any particular values on physical ports, but force the CPU
2483 * port and all DSA ports to their maximum bandwidth and full duplex.
2484 */
2485 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2486 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2487 SPEED_MAX, DUPLEX_FULL,
2488 PHY_INTERFACE_MODE_NA);
2489 else
2490 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2491 SPEED_UNFORCED, DUPLEX_UNFORCED,
2492 PHY_INTERFACE_MODE_NA);
2493 if (err)
2494 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002495
2496 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2497 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2498 * tunneling, determine priority by looking at 802.1p and IP
2499 * priority fields (IP prio has precedence), and set STP state
2500 * to Forwarding.
2501 *
2502 * If this is the CPU link, use DSA or EDSA tagging depending
2503 * on which tagging mode was configured.
2504 *
2505 * If this is a link to another switch, use DSA tagging mode.
2506 *
2507 * If this is the upstream port for this switch, enable
2508 * forwarding of unknown unicasts and multicasts.
2509 */
2510 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002511 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2512 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2513 mv88e6xxx_6095_family(chip) || mv88e6xxx_6065_family(chip) ||
2514 mv88e6xxx_6185_family(chip) || mv88e6xxx_6320_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002515 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
2516 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2517 PORT_CONTROL_STATE_FORWARDING;
2518 if (dsa_is_cpu_port(ds, port)) {
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002519 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA))
Andrew Lunn5377b802016-06-04 21:17:02 +02002520 reg |= PORT_CONTROL_FRAME_ETHER_TYPE_DSA |
Andrew Lunnc047a1f2015-09-29 01:50:56 +02002521 PORT_CONTROL_FORWARD_UNKNOWN_MC;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002522 else
2523 reg |= PORT_CONTROL_DSA_TAG;
Jamie Lentinf027e0c2016-08-22 16:01:04 +02002524 reg |= PORT_CONTROL_EGRESS_ADD_TAG |
2525 PORT_CONTROL_FORWARD_UNKNOWN;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002526 }
Andrew Lunn6083ce72015-08-17 23:52:52 +02002527 if (dsa_is_dsa_port(ds, port)) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002528 if (mv88e6xxx_6095_family(chip) ||
2529 mv88e6xxx_6185_family(chip))
Andrew Lunn6083ce72015-08-17 23:52:52 +02002530 reg |= PORT_CONTROL_DSA_TAG;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002531 if (mv88e6xxx_6352_family(chip) ||
2532 mv88e6xxx_6351_family(chip) ||
2533 mv88e6xxx_6165_family(chip) ||
2534 mv88e6xxx_6097_family(chip) ||
2535 mv88e6xxx_6320_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002536 reg |= PORT_CONTROL_FRAME_MODE_DSA;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002537 }
2538
Andrew Lunn54d792f2015-05-06 01:09:47 +02002539 if (port == dsa_upstream_port(ds))
2540 reg |= PORT_CONTROL_FORWARD_UNKNOWN |
2541 PORT_CONTROL_FORWARD_UNKNOWN_MC;
2542 }
2543 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002544 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2545 if (err)
2546 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002547 }
2548
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002549 /* If this port is connected to a SerDes, make sure the SerDes is not
2550 * powered down.
2551 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002552 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002553 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2554 if (err)
2555 return err;
2556 reg &= PORT_STATUS_CMODE_MASK;
2557 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2558 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2559 (reg == PORT_STATUS_CMODE_SGMII)) {
2560 err = mv88e6xxx_serdes_power_on(chip);
2561 if (err < 0)
2562 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002563 }
2564 }
2565
Vivien Didelot8efdda42015-08-13 12:52:23 -04002566 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002567 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002568 * untagged frames on this port, do a destination address lookup on all
2569 * received packets as usual, disable ARP mirroring and don't send a
2570 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002571 */
2572 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002573 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2574 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2575 mv88e6xxx_6095_family(chip) || mv88e6xxx_6320_family(chip) ||
2576 mv88e6xxx_6185_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002577 reg = PORT_CONTROL_2_MAP_DA;
2578
Vivien Didelotfad09c72016-06-21 12:28:20 -04002579 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2580 mv88e6xxx_6165_family(chip) || mv88e6xxx_6320_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002581 reg |= PORT_CONTROL_2_JUMBO_10240;
2582
Vivien Didelotfad09c72016-06-21 12:28:20 -04002583 if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002584 /* Set the upstream port this port should use */
2585 reg |= dsa_upstream_port(ds);
2586 /* enable forwarding of unknown multicast addresses to
2587 * the upstream port
2588 */
2589 if (port == dsa_upstream_port(ds))
2590 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
2591 }
2592
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002593 reg |= PORT_CONTROL_2_8021Q_DISABLED;
Vivien Didelot8efdda42015-08-13 12:52:23 -04002594
Andrew Lunn54d792f2015-05-06 01:09:47 +02002595 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002596 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
2597 if (err)
2598 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002599 }
2600
2601 /* Port Association Vector: when learning source addresses
2602 * of packets, add the address to the address database using
2603 * a port bitmap that has only the bit for this port set and
2604 * the other bits clear.
2605 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002606 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002607 /* Disable learning for CPU port */
2608 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002609 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002610
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002611 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2612 if (err)
2613 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002614
2615 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002616 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2617 if (err)
2618 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002619
Vivien Didelotfad09c72016-06-21 12:28:20 -04002620 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2621 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2622 mv88e6xxx_6320_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002623 /* Do not limit the period of time that this port can
2624 * be paused for by the remote end or the period of
2625 * time that this port can pause the remote end.
2626 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002627 err = mv88e6xxx_port_write(chip, port, PORT_PAUSE_CTRL, 0x0000);
2628 if (err)
2629 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002630
2631 /* Port ATU control: disable limiting the number of
2632 * address database entries that this port is allowed
2633 * to use.
2634 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002635 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2636 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002637 /* Priority Override: disable DA, SA and VTU priority
2638 * override.
2639 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002640 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2641 0x0000);
2642 if (err)
2643 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002644
2645 /* Port Ethertype: use the Ethertype DSA Ethertype
2646 * value.
2647 */
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002648 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002649 err = mv88e6xxx_port_write(chip, port, PORT_ETH_TYPE,
2650 ETH_P_EDSA);
2651 if (err)
2652 return err;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002653 }
2654
Andrew Lunn54d792f2015-05-06 01:09:47 +02002655 /* Tag Remap: use an identity 802.1p prio -> switch
2656 * prio mapping.
2657 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002658 err = mv88e6xxx_port_write(chip, port, PORT_TAG_REGMAP_0123,
2659 0x3210);
2660 if (err)
2661 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002662
2663 /* Tag Remap 2: use an identity 802.1p prio -> switch
2664 * prio mapping.
2665 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002666 err = mv88e6xxx_port_write(chip, port, PORT_TAG_REGMAP_4567,
2667 0x7654);
2668 if (err)
2669 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002670 }
2671
Jamie Lentin1bc261f2016-08-22 22:47:08 +01002672 /* Rate Control: disable ingress rate limiting. */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002673 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2674 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
Vivien Didelotfad09c72016-06-21 12:28:20 -04002675 mv88e6xxx_6320_family(chip)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002676 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL,
2677 0x0001);
2678 if (err)
2679 return err;
Jamie Lentin1bc261f2016-08-22 22:47:08 +01002680 } else if (mv88e6xxx_6185_family(chip) || mv88e6xxx_6095_family(chip)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002681 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL,
2682 0x0000);
2683 if (err)
2684 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002685 }
2686
Guenter Roeck366f0a02015-03-26 18:36:30 -07002687 /* Port Control 1: disable trunking, disable sending
2688 * learning messages to this port.
Guenter Roeckd827e882015-03-26 18:36:29 -07002689 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002690 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_1, 0x0000);
2691 if (err)
2692 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002693
Vivien Didelot207afda2016-04-14 14:42:09 -04002694 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002695 * database, and allow bidirectional communication between the
2696 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002697 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002698 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002699 if (err)
2700 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002701
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002702 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2703 if (err)
2704 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002705
2706 /* Default VLAN ID and priority: don't set a default VLAN
2707 * ID, and set the default packet priority to zero.
2708 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002709 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002710}
2711
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002712static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002713{
2714 int err;
2715
Vivien Didelota935c052016-09-29 12:21:53 -04002716 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002717 if (err)
2718 return err;
2719
Vivien Didelota935c052016-09-29 12:21:53 -04002720 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002721 if (err)
2722 return err;
2723
Vivien Didelota935c052016-09-29 12:21:53 -04002724 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2725 if (err)
2726 return err;
2727
2728 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002729}
2730
Vivien Didelotacddbd22016-07-18 20:45:39 -04002731static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
2732 unsigned int msecs)
2733{
2734 const unsigned int coeff = chip->info->age_time_coeff;
2735 const unsigned int min = 0x01 * coeff;
2736 const unsigned int max = 0xff * coeff;
2737 u8 age_time;
2738 u16 val;
2739 int err;
2740
2741 if (msecs < min || msecs > max)
2742 return -ERANGE;
2743
2744 /* Round to nearest multiple of coeff */
2745 age_time = (msecs + coeff / 2) / coeff;
2746
Vivien Didelota935c052016-09-29 12:21:53 -04002747 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002748 if (err)
2749 return err;
2750
2751 /* AgeTime is 11:4 bits */
2752 val &= ~0xff0;
2753 val |= age_time << 4;
2754
Vivien Didelota935c052016-09-29 12:21:53 -04002755 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002756}
2757
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002758static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2759 unsigned int ageing_time)
2760{
Vivien Didelot04bed142016-08-31 18:06:13 -04002761 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002762 int err;
2763
2764 mutex_lock(&chip->reg_lock);
2765 err = mv88e6xxx_g1_set_age_time(chip, ageing_time);
2766 mutex_unlock(&chip->reg_lock);
2767
2768 return err;
2769}
2770
Vivien Didelot97299342016-07-18 20:45:30 -04002771static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002772{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002773 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002774 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot119477b2016-05-09 13:22:51 -04002775 u16 reg;
Vivien Didelot08a01262016-05-09 13:22:50 -04002776 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002777
Vivien Didelot119477b2016-05-09 13:22:51 -04002778 /* Enable the PHY Polling Unit if present, don't discard any packets,
2779 * and mask all interrupt sources.
2780 */
Andrew Lunndc30c352016-10-16 19:56:49 +02002781 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
2782 if (err < 0)
2783 return err;
2784
2785 reg &= ~GLOBAL_CONTROL_PPU_ENABLE;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002786 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU) ||
2787 mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE))
Vivien Didelot119477b2016-05-09 13:22:51 -04002788 reg |= GLOBAL_CONTROL_PPU_ENABLE;
2789
Vivien Didelota935c052016-09-29 12:21:53 -04002790 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
Vivien Didelot119477b2016-05-09 13:22:51 -04002791 if (err)
2792 return err;
2793
Vivien Didelotb0745e872016-05-09 13:22:53 -04002794 /* Configure the upstream port, and configure it as the port to which
2795 * ingress and egress and ARP monitor frames are to be sent.
2796 */
2797 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
2798 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
2799 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
Vivien Didelota935c052016-09-29 12:21:53 -04002800 err = mv88e6xxx_g1_write(chip, GLOBAL_MONITOR_CONTROL, reg);
Vivien Didelotb0745e872016-05-09 13:22:53 -04002801 if (err)
2802 return err;
2803
Vivien Didelot50484ff2016-05-09 13:22:54 -04002804 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002805 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2806 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2807 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002808 if (err)
2809 return err;
2810
Vivien Didelotacddbd22016-07-18 20:45:39 -04002811 /* Clear all the VTU and STU entries */
2812 err = _mv88e6xxx_vtu_stu_flush(chip);
2813 if (err < 0)
2814 return err;
2815
Vivien Didelot08a01262016-05-09 13:22:50 -04002816 /* Set the default address aging time to 5 minutes, and
2817 * enable address learn messages to be sent to all message
2818 * ports.
2819 */
Vivien Didelota935c052016-09-29 12:21:53 -04002820 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2821 GLOBAL_ATU_CONTROL_LEARN2ALL);
Vivien Didelot08a01262016-05-09 13:22:50 -04002822 if (err)
2823 return err;
2824
Vivien Didelotacddbd22016-07-18 20:45:39 -04002825 err = mv88e6xxx_g1_set_age_time(chip, 300000);
2826 if (err)
Vivien Didelot97299342016-07-18 20:45:30 -04002827 return err;
2828
2829 /* Clear all ATU entries */
2830 err = _mv88e6xxx_atu_flush(chip, 0, true);
2831 if (err)
2832 return err;
2833
Vivien Didelot08a01262016-05-09 13:22:50 -04002834 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002835 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002836 if (err)
2837 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002838 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002839 if (err)
2840 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002841 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002842 if (err)
2843 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002844 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002845 if (err)
2846 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002847 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002848 if (err)
2849 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002850 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002851 if (err)
2852 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002853 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002854 if (err)
2855 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002856 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002857 if (err)
2858 return err;
2859
2860 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002861 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002862 if (err)
2863 return err;
2864
Andrew Lunnde2273872016-11-21 23:27:01 +01002865 /* Initialize the statistics unit */
2866 err = mv88e6xxx_stats_set_histogram(chip);
2867 if (err)
2868 return err;
2869
Vivien Didelot97299342016-07-18 20:45:30 -04002870 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002871 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2872 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002873 if (err)
2874 return err;
2875
2876 /* Wait for the flush to complete. */
2877 err = _mv88e6xxx_stats_wait(chip);
2878 if (err)
2879 return err;
2880
2881 return 0;
2882}
2883
Vivien Didelotf81ec902016-05-09 13:22:58 -04002884static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002885{
Vivien Didelot04bed142016-08-31 18:06:13 -04002886 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002887 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002888 int i;
2889
Vivien Didelotfad09c72016-06-21 12:28:20 -04002890 chip->ds = ds;
2891 ds->slave_mii_bus = chip->mdio_bus;
Vivien Didelot552238b2016-05-09 13:22:49 -04002892
Vivien Didelotfad09c72016-06-21 12:28:20 -04002893 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002894
Vivien Didelot97299342016-07-18 20:45:30 -04002895 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002896 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002897 err = mv88e6xxx_setup_port(chip, i);
2898 if (err)
2899 goto unlock;
2900 }
2901
2902 /* Setup Switch Global 1 Registers */
2903 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002904 if (err)
2905 goto unlock;
2906
Vivien Didelot97299342016-07-18 20:45:30 -04002907 /* Setup Switch Global 2 Registers */
2908 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2909 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002910 if (err)
2911 goto unlock;
2912 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002913
Vivien Didelot6b17e862015-08-13 12:52:18 -04002914unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002915 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002916
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002917 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002918}
2919
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002920static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2921{
Vivien Didelot04bed142016-08-31 18:06:13 -04002922 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002923 int err;
2924
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002925 if (!chip->info->ops->set_switch_mac)
2926 return -EOPNOTSUPP;
2927
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002928 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002929 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002930 mutex_unlock(&chip->reg_lock);
2931
2932 return err;
2933}
2934
Vivien Didelote57e5e72016-08-15 17:19:00 -04002935static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002936{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002937 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002938 u16 val;
2939 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002940
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002941 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002942 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002943
Vivien Didelotfad09c72016-06-21 12:28:20 -04002944 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002945 err = mv88e6xxx_phy_read(chip, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002946 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002947
2948 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002949}
2950
Vivien Didelote57e5e72016-08-15 17:19:00 -04002951static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002952{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002953 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002954 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002955
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002956 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002957 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002958
Vivien Didelotfad09c72016-06-21 12:28:20 -04002959 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002960 err = mv88e6xxx_phy_write(chip, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002961 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002962
2963 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002964}
2965
Vivien Didelotfad09c72016-06-21 12:28:20 -04002966static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunnb516d452016-06-04 21:17:06 +02002967 struct device_node *np)
2968{
2969 static int index;
2970 struct mii_bus *bus;
2971 int err;
2972
Andrew Lunnb516d452016-06-04 21:17:06 +02002973 if (np)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002974 chip->mdio_np = of_get_child_by_name(np, "mdio");
Andrew Lunnb516d452016-06-04 21:17:06 +02002975
Vivien Didelotfad09c72016-06-21 12:28:20 -04002976 bus = devm_mdiobus_alloc(chip->dev);
Andrew Lunnb516d452016-06-04 21:17:06 +02002977 if (!bus)
2978 return -ENOMEM;
2979
Vivien Didelotfad09c72016-06-21 12:28:20 -04002980 bus->priv = (void *)chip;
Andrew Lunnb516d452016-06-04 21:17:06 +02002981 if (np) {
2982 bus->name = np->full_name;
2983 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2984 } else {
2985 bus->name = "mv88e6xxx SMI";
2986 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2987 }
2988
2989 bus->read = mv88e6xxx_mdio_read;
2990 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002991 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002992
Vivien Didelotfad09c72016-06-21 12:28:20 -04002993 if (chip->mdio_np)
2994 err = of_mdiobus_register(bus, chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002995 else
2996 err = mdiobus_register(bus);
2997 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002998 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunnb516d452016-06-04 21:17:06 +02002999 goto out;
3000 }
Vivien Didelotfad09c72016-06-21 12:28:20 -04003001 chip->mdio_bus = bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003002
3003 return 0;
3004
3005out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04003006 if (chip->mdio_np)
3007 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003008
3009 return err;
3010}
3011
Vivien Didelotfad09c72016-06-21 12:28:20 -04003012static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02003013
3014{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003015 struct mii_bus *bus = chip->mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003016
3017 mdiobus_unregister(bus);
3018
Vivien Didelotfad09c72016-06-21 12:28:20 -04003019 if (chip->mdio_np)
3020 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003021}
3022
Guenter Roeckc22995c2015-07-25 09:42:28 -07003023#ifdef CONFIG_NET_DSA_HWMON
3024
3025static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp)
3026{
Vivien Didelot04bed142016-08-31 18:06:13 -04003027 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04003028 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003029 int ret;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003030
3031 *temp = 0;
3032
Vivien Didelotfad09c72016-06-21 12:28:20 -04003033 mutex_lock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003034
Vivien Didelot9c938292016-08-15 17:19:02 -04003035 ret = mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x6);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003036 if (ret < 0)
3037 goto error;
3038
3039 /* Enable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04003040 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003041 if (ret < 0)
3042 goto error;
3043
Vivien Didelot9c938292016-08-15 17:19:02 -04003044 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val | (1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07003045 if (ret < 0)
3046 goto error;
3047
3048 /* Wait for temperature to stabilize */
3049 usleep_range(10000, 12000);
3050
Vivien Didelot9c938292016-08-15 17:19:02 -04003051 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
3052 if (ret < 0)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003053 goto error;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003054
3055 /* Disable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04003056 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val & ~(1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07003057 if (ret < 0)
3058 goto error;
3059
3060 *temp = ((val & 0x1f) - 5) * 5;
3061
3062error:
Vivien Didelot9c938292016-08-15 17:19:02 -04003063 mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x0);
Vivien Didelotfad09c72016-06-21 12:28:20 -04003064 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003065 return ret;
3066}
3067
3068static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp)
3069{
Vivien Didelot04bed142016-08-31 18:06:13 -04003070 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003071 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003072 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003073 int ret;
3074
3075 *temp = 0;
3076
Vivien Didelot9c938292016-08-15 17:19:02 -04003077 mutex_lock(&chip->reg_lock);
3078 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 27, &val);
3079 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003080 if (ret < 0)
3081 return ret;
3082
Vivien Didelot9c938292016-08-15 17:19:02 -04003083 *temp = (val & 0xff) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003084
3085 return 0;
3086}
3087
Vivien Didelotf81ec902016-05-09 13:22:58 -04003088static int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003089{
Vivien Didelot04bed142016-08-31 18:06:13 -04003090 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn158bc062016-04-28 21:24:06 -04003091
Vivien Didelotfad09c72016-06-21 12:28:20 -04003092 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP))
Vivien Didelot6594f612016-05-09 13:22:42 -04003093 return -EOPNOTSUPP;
3094
Vivien Didelotfad09c72016-06-21 12:28:20 -04003095 if (mv88e6xxx_6320_family(chip) || mv88e6xxx_6352_family(chip))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003096 return mv88e63xx_get_temp(ds, temp);
3097
3098 return mv88e61xx_get_temp(ds, temp);
3099}
3100
Vivien Didelotf81ec902016-05-09 13:22:58 -04003101static int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003102{
Vivien Didelot04bed142016-08-31 18:06:13 -04003103 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003104 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003105 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003106 int ret;
3107
Vivien Didelotfad09c72016-06-21 12:28:20 -04003108 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003109 return -EOPNOTSUPP;
3110
3111 *temp = 0;
3112
Vivien Didelot9c938292016-08-15 17:19:02 -04003113 mutex_lock(&chip->reg_lock);
3114 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3115 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003116 if (ret < 0)
3117 return ret;
3118
Vivien Didelot9c938292016-08-15 17:19:02 -04003119 *temp = (((val >> 8) & 0x1f) * 5) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003120
3121 return 0;
3122}
3123
Vivien Didelotf81ec902016-05-09 13:22:58 -04003124static int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003125{
Vivien Didelot04bed142016-08-31 18:06:13 -04003126 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003127 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003128 u16 val;
3129 int err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003130
Vivien Didelotfad09c72016-06-21 12:28:20 -04003131 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003132 return -EOPNOTSUPP;
3133
Vivien Didelot9c938292016-08-15 17:19:02 -04003134 mutex_lock(&chip->reg_lock);
3135 err = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3136 if (err)
3137 goto unlock;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003138 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
Vivien Didelot9c938292016-08-15 17:19:02 -04003139 err = mv88e6xxx_phy_page_write(chip, phy, 6, 26,
3140 (val & 0xe0ff) | (temp << 8));
3141unlock:
3142 mutex_unlock(&chip->reg_lock);
3143
3144 return err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003145}
3146
Vivien Didelotf81ec902016-05-09 13:22:58 -04003147static int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003148{
Vivien Didelot04bed142016-08-31 18:06:13 -04003149 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003150 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003151 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003152 int ret;
3153
Vivien Didelotfad09c72016-06-21 12:28:20 -04003154 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003155 return -EOPNOTSUPP;
3156
3157 *alarm = false;
3158
Vivien Didelot9c938292016-08-15 17:19:02 -04003159 mutex_lock(&chip->reg_lock);
3160 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3161 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003162 if (ret < 0)
3163 return ret;
3164
Vivien Didelot9c938292016-08-15 17:19:02 -04003165 *alarm = !!(val & 0x40);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003166
3167 return 0;
3168}
3169#endif /* CONFIG_NET_DSA_HWMON */
3170
Vivien Didelot855b1932016-07-20 18:18:35 -04003171static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3172{
Vivien Didelot04bed142016-08-31 18:06:13 -04003173 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003174
3175 return chip->eeprom_len;
3176}
3177
Vivien Didelot855b1932016-07-20 18:18:35 -04003178static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3179 struct ethtool_eeprom *eeprom, u8 *data)
3180{
Vivien Didelot04bed142016-08-31 18:06:13 -04003181 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003182 int err;
3183
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003184 if (!chip->info->ops->get_eeprom)
3185 return -EOPNOTSUPP;
3186
Vivien Didelot855b1932016-07-20 18:18:35 -04003187 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003188 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003189 mutex_unlock(&chip->reg_lock);
3190
3191 if (err)
3192 return err;
3193
3194 eeprom->magic = 0xc3ec4951;
3195
3196 return 0;
3197}
3198
Vivien Didelot855b1932016-07-20 18:18:35 -04003199static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3200 struct ethtool_eeprom *eeprom, u8 *data)
3201{
Vivien Didelot04bed142016-08-31 18:06:13 -04003202 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003203 int err;
3204
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003205 if (!chip->info->ops->set_eeprom)
3206 return -EOPNOTSUPP;
3207
Vivien Didelot855b1932016-07-20 18:18:35 -04003208 if (eeprom->magic != 0xc3ec4951)
3209 return -EINVAL;
3210
3211 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003212 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003213 mutex_unlock(&chip->reg_lock);
3214
3215 return err;
3216}
3217
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003218static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003219 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003220 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003221 .phy_read = mv88e6xxx_phy_ppu_read,
3222 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003223 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003224 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003225 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003226 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003227 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3228 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003229 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003230};
3231
3232static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003233 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003234 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003235 .phy_read = mv88e6xxx_phy_ppu_read,
3236 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003237 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003238 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003239 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003240 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003241 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3242 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003243 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003244};
3245
3246static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003247 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003248 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003249 .phy_read = mv88e6xxx_read,
3250 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003251 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003252 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003253 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003254 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003255 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3256 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003257 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003258};
3259
3260static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003261 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003262 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003263 .phy_read = mv88e6xxx_phy_ppu_read,
3264 .phy_write = mv88e6xxx_phy_ppu_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,
Andrew Lunn052f9472016-11-21 23:27:03 +01003271 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003272};
3273
3274static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003275 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003276 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003277 .phy_read = mv88e6xxx_read,
3278 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003279 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003280 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003281 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003282 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003283 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3284 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003285 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003286};
3287
3288static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003289 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003290 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003291 .phy_read = mv88e6xxx_read,
3292 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003293 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003294 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003295 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003296 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003297 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3298 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003299 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003300};
3301
3302static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003303 /* MV88E6XXX_FAMILY_6351 */
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,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003309 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003310 .port_set_speed = mv88e6185_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,
Andrew Lunn052f9472016-11-21 23:27:03 +01003314 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003315};
3316
3317static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003318 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003319 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3320 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003321 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003322 .phy_read = mv88e6xxx_g2_smi_phy_read,
3323 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003324 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003325 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003326 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003327 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003328 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003329 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3330 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003331 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003332};
3333
3334static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003335 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003336 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003337 .phy_read = mv88e6xxx_g2_smi_phy_read,
3338 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003339 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003340 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003341 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003342 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003343 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003344 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3345 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003346 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003347};
3348
3349static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003350 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003351 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3352 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003353 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003354 .phy_read = mv88e6xxx_g2_smi_phy_read,
3355 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003356 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003357 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003358 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003359 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003360 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003361 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3362 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003363 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003364};
3365
3366static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003367 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003368 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003369 .phy_read = mv88e6xxx_phy_ppu_read,
3370 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003371 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003372 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003373 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003374 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003375 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3376 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003377 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003378};
3379
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003380static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003381 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003382 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3383 .phy_read = mv88e6xxx_g2_smi_phy_read,
3384 .phy_write = mv88e6xxx_g2_smi_phy_write,
3385 .port_set_link = mv88e6xxx_port_set_link,
3386 .port_set_duplex = mv88e6xxx_port_set_duplex,
3387 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3388 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003389 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003390 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003391 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3392 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003393};
3394
3395static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003396 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003397 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3398 .phy_read = mv88e6xxx_g2_smi_phy_read,
3399 .phy_write = mv88e6xxx_g2_smi_phy_write,
3400 .port_set_link = mv88e6xxx_port_set_link,
3401 .port_set_duplex = mv88e6xxx_port_set_duplex,
3402 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3403 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003404 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003405 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003406 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3407 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003408};
3409
3410static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003411 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003412 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3413 .phy_read = mv88e6xxx_g2_smi_phy_read,
3414 .phy_write = mv88e6xxx_g2_smi_phy_write,
3415 .port_set_link = mv88e6xxx_port_set_link,
3416 .port_set_duplex = mv88e6xxx_port_set_duplex,
3417 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3418 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003419 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003420 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003421 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3422 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003423};
3424
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003425static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003426 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003427 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3428 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003429 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003430 .phy_read = mv88e6xxx_g2_smi_phy_read,
3431 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003432 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003433 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003434 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003435 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003436 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003437 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3438 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003439 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003440};
3441
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003442static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003443 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003444 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3445 .phy_read = mv88e6xxx_g2_smi_phy_read,
3446 .phy_write = mv88e6xxx_g2_smi_phy_write,
3447 .port_set_link = mv88e6xxx_port_set_link,
3448 .port_set_duplex = mv88e6xxx_port_set_duplex,
3449 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3450 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003451 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003452 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003453 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3454 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003455};
3456
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003457static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003458 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003459 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3460 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003461 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003462 .phy_read = mv88e6xxx_g2_smi_phy_read,
3463 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003464 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003465 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003466 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003467 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003468 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3469 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003470 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003471};
3472
3473static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003474 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003475 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3476 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003477 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003478 .phy_read = mv88e6xxx_g2_smi_phy_read,
3479 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003480 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003481 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003482 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003483 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003484 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3485 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003486 .stats_get_stats = mv88e6320_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003487};
3488
3489static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003490 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003491 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003492 .phy_read = mv88e6xxx_g2_smi_phy_read,
3493 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003494 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003495 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003496 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003497 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003498 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003499 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3500 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003501 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003502};
3503
3504static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003505 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003506 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003507 .phy_read = mv88e6xxx_g2_smi_phy_read,
3508 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003509 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003510 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003511 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003512 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003513 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003514 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3515 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003516 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003517};
3518
3519static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003520 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003521 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3522 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003523 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003524 .phy_read = mv88e6xxx_g2_smi_phy_read,
3525 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003526 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003527 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003528 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003529 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003530 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003531 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3532 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003533 .stats_get_stats = mv88e6095_stats_get_stats,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003534};
3535
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003536static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003537 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003538 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3539 .phy_read = mv88e6xxx_g2_smi_phy_read,
3540 .phy_write = mv88e6xxx_g2_smi_phy_write,
3541 .port_set_link = mv88e6xxx_port_set_link,
3542 .port_set_duplex = mv88e6xxx_port_set_duplex,
3543 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3544 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003545 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003546 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003547 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3548 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003549};
3550
3551static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003552 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003553 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3554 .phy_read = mv88e6xxx_g2_smi_phy_read,
3555 .phy_write = mv88e6xxx_g2_smi_phy_write,
3556 .port_set_link = mv88e6xxx_port_set_link,
3557 .port_set_duplex = mv88e6xxx_port_set_duplex,
3558 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3559 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003560 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003561 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003562 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3563 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003564};
3565
3566static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003567 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003568 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3569 .phy_read = mv88e6xxx_g2_smi_phy_read,
3570 .phy_write = mv88e6xxx_g2_smi_phy_write,
3571 .port_set_link = mv88e6xxx_port_set_link,
3572 .port_set_duplex = mv88e6xxx_port_set_duplex,
3573 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3574 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunn79523472016-11-21 23:27:00 +01003575 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003576 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003577 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3578 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003579};
3580
Vivien Didelotf81ec902016-05-09 13:22:58 -04003581static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3582 [MV88E6085] = {
3583 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3584 .family = MV88E6XXX_FAMILY_6097,
3585 .name = "Marvell 88E6085",
3586 .num_databases = 4096,
3587 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003588 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003589 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003590 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003591 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003592 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003593 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003594 },
3595
3596 [MV88E6095] = {
3597 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3598 .family = MV88E6XXX_FAMILY_6095,
3599 .name = "Marvell 88E6095/88E6095F",
3600 .num_databases = 256,
3601 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003602 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003603 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003604 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003605 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003606 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003607 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003608 },
3609
3610 [MV88E6123] = {
3611 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3612 .family = MV88E6XXX_FAMILY_6165,
3613 .name = "Marvell 88E6123",
3614 .num_databases = 4096,
3615 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003616 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003617 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003618 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003619 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003620 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003621 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003622 },
3623
3624 [MV88E6131] = {
3625 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3626 .family = MV88E6XXX_FAMILY_6185,
3627 .name = "Marvell 88E6131",
3628 .num_databases = 256,
3629 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003630 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003631 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003632 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003633 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003634 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003635 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003636 },
3637
3638 [MV88E6161] = {
3639 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3640 .family = MV88E6XXX_FAMILY_6165,
3641 .name = "Marvell 88E6161",
3642 .num_databases = 4096,
3643 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003644 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003645 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003646 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003647 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003648 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003649 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003650 },
3651
3652 [MV88E6165] = {
3653 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3654 .family = MV88E6XXX_FAMILY_6165,
3655 .name = "Marvell 88E6165",
3656 .num_databases = 4096,
3657 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003658 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003659 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003660 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003661 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003662 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003663 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003664 },
3665
3666 [MV88E6171] = {
3667 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3668 .family = MV88E6XXX_FAMILY_6351,
3669 .name = "Marvell 88E6171",
3670 .num_databases = 4096,
3671 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003672 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003673 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003674 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003675 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003676 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003677 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003678 },
3679
3680 [MV88E6172] = {
3681 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3682 .family = MV88E6XXX_FAMILY_6352,
3683 .name = "Marvell 88E6172",
3684 .num_databases = 4096,
3685 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003686 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003687 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003688 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003689 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003690 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003691 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003692 },
3693
3694 [MV88E6175] = {
3695 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3696 .family = MV88E6XXX_FAMILY_6351,
3697 .name = "Marvell 88E6175",
3698 .num_databases = 4096,
3699 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003700 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003701 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003702 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003703 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003704 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003705 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003706 },
3707
3708 [MV88E6176] = {
3709 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3710 .family = MV88E6XXX_FAMILY_6352,
3711 .name = "Marvell 88E6176",
3712 .num_databases = 4096,
3713 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003714 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003715 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003716 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003717 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003718 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003719 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003720 },
3721
3722 [MV88E6185] = {
3723 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3724 .family = MV88E6XXX_FAMILY_6185,
3725 .name = "Marvell 88E6185",
3726 .num_databases = 256,
3727 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003728 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003729 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003730 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003731 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003732 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003733 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003734 },
3735
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003736 [MV88E6190] = {
3737 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3738 .family = MV88E6XXX_FAMILY_6390,
3739 .name = "Marvell 88E6190",
3740 .num_databases = 4096,
3741 .num_ports = 11, /* 10 + Z80 */
3742 .port_base_addr = 0x0,
3743 .global1_addr = 0x1b,
3744 .age_time_coeff = 15000,
3745 .g1_irqs = 9,
3746 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3747 .ops = &mv88e6190_ops,
3748 },
3749
3750 [MV88E6190X] = {
3751 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
3752 .family = MV88E6XXX_FAMILY_6390,
3753 .name = "Marvell 88E6190X",
3754 .num_databases = 4096,
3755 .num_ports = 11, /* 10 + Z80 */
3756 .port_base_addr = 0x0,
3757 .global1_addr = 0x1b,
3758 .age_time_coeff = 15000,
3759 .g1_irqs = 9,
3760 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3761 .ops = &mv88e6190x_ops,
3762 },
3763
3764 [MV88E6191] = {
3765 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
3766 .family = MV88E6XXX_FAMILY_6390,
3767 .name = "Marvell 88E6191",
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 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3774 .ops = &mv88e6391_ops,
3775 },
3776
Vivien Didelotf81ec902016-05-09 13:22:58 -04003777 [MV88E6240] = {
3778 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3779 .family = MV88E6XXX_FAMILY_6352,
3780 .name = "Marvell 88E6240",
3781 .num_databases = 4096,
3782 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003783 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003784 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003785 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003786 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003787 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003788 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003789 },
3790
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003791 [MV88E6290] = {
3792 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
3793 .family = MV88E6XXX_FAMILY_6390,
3794 .name = "Marvell 88E6290",
3795 .num_databases = 4096,
3796 .num_ports = 11, /* 10 + Z80 */
3797 .port_base_addr = 0x0,
3798 .global1_addr = 0x1b,
3799 .age_time_coeff = 15000,
3800 .g1_irqs = 9,
3801 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3802 .ops = &mv88e6290_ops,
3803 },
3804
Vivien Didelotf81ec902016-05-09 13:22:58 -04003805 [MV88E6320] = {
3806 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3807 .family = MV88E6XXX_FAMILY_6320,
3808 .name = "Marvell 88E6320",
3809 .num_databases = 4096,
3810 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003811 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003812 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003813 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003814 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003815 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003816 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003817 },
3818
3819 [MV88E6321] = {
3820 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3821 .family = MV88E6XXX_FAMILY_6320,
3822 .name = "Marvell 88E6321",
3823 .num_databases = 4096,
3824 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003825 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003826 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003827 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003828 .g1_irqs = 8,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003829 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003830 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003831 },
3832
3833 [MV88E6350] = {
3834 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3835 .family = MV88E6XXX_FAMILY_6351,
3836 .name = "Marvell 88E6350",
3837 .num_databases = 4096,
3838 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003839 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003840 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003841 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003842 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003843 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003844 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003845 },
3846
3847 [MV88E6351] = {
3848 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3849 .family = MV88E6XXX_FAMILY_6351,
3850 .name = "Marvell 88E6351",
3851 .num_databases = 4096,
3852 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003853 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003854 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003855 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003856 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003857 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003858 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003859 },
3860
3861 [MV88E6352] = {
3862 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
3863 .family = MV88E6XXX_FAMILY_6352,
3864 .name = "Marvell 88E6352",
3865 .num_databases = 4096,
3866 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003867 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003868 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003869 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003870 .g1_irqs = 9,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003871 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003872 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003873 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003874 [MV88E6390] = {
3875 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
3876 .family = MV88E6XXX_FAMILY_6390,
3877 .name = "Marvell 88E6390",
3878 .num_databases = 4096,
3879 .num_ports = 11, /* 10 + Z80 */
3880 .port_base_addr = 0x0,
3881 .global1_addr = 0x1b,
3882 .age_time_coeff = 15000,
3883 .g1_irqs = 9,
3884 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3885 .ops = &mv88e6390_ops,
3886 },
3887 [MV88E6390X] = {
3888 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
3889 .family = MV88E6XXX_FAMILY_6390,
3890 .name = "Marvell 88E6390X",
3891 .num_databases = 4096,
3892 .num_ports = 11, /* 10 + Z80 */
3893 .port_base_addr = 0x0,
3894 .global1_addr = 0x1b,
3895 .age_time_coeff = 15000,
3896 .g1_irqs = 9,
3897 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3898 .ops = &mv88e6390x_ops,
3899 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04003900};
3901
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003902static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04003903{
Vivien Didelota439c062016-04-17 13:23:58 -04003904 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04003905
Vivien Didelot5f7c0362016-06-20 13:14:04 -04003906 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3907 if (mv88e6xxx_table[i].prod_num == prod_num)
3908 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04003909
Vivien Didelotb9b37712015-10-30 19:39:48 -04003910 return NULL;
3911}
3912
Vivien Didelotfad09c72016-06-21 12:28:20 -04003913static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003914{
3915 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003916 unsigned int prod_num, rev;
3917 u16 id;
3918 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003919
Vivien Didelot8f6345b2016-07-20 18:18:36 -04003920 mutex_lock(&chip->reg_lock);
3921 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
3922 mutex_unlock(&chip->reg_lock);
3923 if (err)
3924 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003925
3926 prod_num = (id & 0xfff0) >> 4;
3927 rev = id & 0x000f;
3928
3929 info = mv88e6xxx_lookup_info(prod_num);
3930 if (!info)
3931 return -ENODEV;
3932
Vivien Didelotcaac8542016-06-20 13:14:09 -04003933 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04003934 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003935
Vivien Didelotca070c12016-09-02 14:45:34 -04003936 err = mv88e6xxx_g2_require(chip);
3937 if (err)
3938 return err;
3939
Vivien Didelotfad09c72016-06-21 12:28:20 -04003940 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3941 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04003942
3943 return 0;
3944}
3945
Vivien Didelotfad09c72016-06-21 12:28:20 -04003946static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04003947{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003948 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003949
Vivien Didelotfad09c72016-06-21 12:28:20 -04003950 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3951 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04003952 return NULL;
3953
Vivien Didelotfad09c72016-06-21 12:28:20 -04003954 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04003955
Vivien Didelotfad09c72016-06-21 12:28:20 -04003956 mutex_init(&chip->reg_lock);
Vivien Didelot469d7292016-06-20 13:14:06 -04003957
Vivien Didelotfad09c72016-06-21 12:28:20 -04003958 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04003959}
3960
Vivien Didelote57e5e72016-08-15 17:19:00 -04003961static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
3962{
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003963 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
Vivien Didelote57e5e72016-08-15 17:19:00 -04003964 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04003965}
3966
Andrew Lunn930188c2016-08-22 16:01:03 +02003967static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
3968{
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003969 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
Andrew Lunn930188c2016-08-22 16:01:03 +02003970 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02003971}
3972
Vivien Didelotfad09c72016-06-21 12:28:20 -04003973static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003974 struct mii_bus *bus, int sw_addr)
3975{
3976 /* ADDR[0] pin is unavailable externally and considered zero */
3977 if (sw_addr & 0x1)
3978 return -EINVAL;
3979
Vivien Didelot914b32f2016-06-20 13:14:11 -04003980 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04003981 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04003982 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04003983 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04003984 else
3985 return -EINVAL;
3986
Vivien Didelotfad09c72016-06-21 12:28:20 -04003987 chip->bus = bus;
3988 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04003989
3990 return 0;
3991}
3992
Andrew Lunn7b314362016-08-22 16:01:01 +02003993static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
3994{
Vivien Didelot04bed142016-08-31 18:06:13 -04003995 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02003996
3997 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA))
3998 return DSA_TAG_PROTO_EDSA;
3999
4000 return DSA_TAG_PROTO_DSA;
Andrew Lunn7b314362016-08-22 16:01:01 +02004001}
4002
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004003static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4004 struct device *host_dev, int sw_addr,
4005 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004006{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004007 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004008 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004009 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004010
Vivien Didelota439c062016-04-17 13:23:58 -04004011 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004012 if (!bus)
4013 return NULL;
4014
Vivien Didelotfad09c72016-06-21 12:28:20 -04004015 chip = mv88e6xxx_alloc_chip(dsa_dev);
4016 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004017 return NULL;
4018
Vivien Didelotcaac8542016-06-20 13:14:09 -04004019 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004020 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004021
Vivien Didelotfad09c72016-06-21 12:28:20 -04004022 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004023 if (err)
4024 goto free;
4025
Vivien Didelotfad09c72016-06-21 12:28:20 -04004026 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004027 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004028 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004029
Andrew Lunndc30c352016-10-16 19:56:49 +02004030 mutex_lock(&chip->reg_lock);
4031 err = mv88e6xxx_switch_reset(chip);
4032 mutex_unlock(&chip->reg_lock);
4033 if (err)
4034 goto free;
4035
Vivien Didelote57e5e72016-08-15 17:19:00 -04004036 mv88e6xxx_phy_init(chip);
4037
Vivien Didelotfad09c72016-06-21 12:28:20 -04004038 err = mv88e6xxx_mdio_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004039 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004040 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004041
Vivien Didelotfad09c72016-06-21 12:28:20 -04004042 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004043
Vivien Didelotfad09c72016-06-21 12:28:20 -04004044 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004045free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004046 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004047
4048 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004049}
4050
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004051static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4052 const struct switchdev_obj_port_mdb *mdb,
4053 struct switchdev_trans *trans)
4054{
4055 /* We don't need any dynamic resource from the kernel (yet),
4056 * so skip the prepare phase.
4057 */
4058
4059 return 0;
4060}
4061
4062static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4063 const struct switchdev_obj_port_mdb *mdb,
4064 struct switchdev_trans *trans)
4065{
Vivien Didelot04bed142016-08-31 18:06:13 -04004066 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004067
4068 mutex_lock(&chip->reg_lock);
4069 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4070 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4071 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4072 mutex_unlock(&chip->reg_lock);
4073}
4074
4075static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4076 const struct switchdev_obj_port_mdb *mdb)
4077{
Vivien Didelot04bed142016-08-31 18:06:13 -04004078 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004079 int err;
4080
4081 mutex_lock(&chip->reg_lock);
4082 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4083 GLOBAL_ATU_DATA_STATE_UNUSED);
4084 mutex_unlock(&chip->reg_lock);
4085
4086 return err;
4087}
4088
4089static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4090 struct switchdev_obj_port_mdb *mdb,
4091 int (*cb)(struct switchdev_obj *obj))
4092{
Vivien Didelot04bed142016-08-31 18:06:13 -04004093 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004094 int err;
4095
4096 mutex_lock(&chip->reg_lock);
4097 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4098 mutex_unlock(&chip->reg_lock);
4099
4100 return err;
4101}
4102
Vivien Didelot9d490b42016-08-23 12:38:56 -04004103static struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004104 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004105 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004106 .setup = mv88e6xxx_setup,
4107 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004108 .adjust_link = mv88e6xxx_adjust_link,
4109 .get_strings = mv88e6xxx_get_strings,
4110 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4111 .get_sset_count = mv88e6xxx_get_sset_count,
4112 .set_eee = mv88e6xxx_set_eee,
4113 .get_eee = mv88e6xxx_get_eee,
4114#ifdef CONFIG_NET_DSA_HWMON
4115 .get_temp = mv88e6xxx_get_temp,
4116 .get_temp_limit = mv88e6xxx_get_temp_limit,
4117 .set_temp_limit = mv88e6xxx_set_temp_limit,
4118 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
4119#endif
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004120 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004121 .get_eeprom = mv88e6xxx_get_eeprom,
4122 .set_eeprom = mv88e6xxx_set_eeprom,
4123 .get_regs_len = mv88e6xxx_get_regs_len,
4124 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004125 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004126 .port_bridge_join = mv88e6xxx_port_bridge_join,
4127 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4128 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004129 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004130 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4131 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4132 .port_vlan_add = mv88e6xxx_port_vlan_add,
4133 .port_vlan_del = mv88e6xxx_port_vlan_del,
4134 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4135 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4136 .port_fdb_add = mv88e6xxx_port_fdb_add,
4137 .port_fdb_del = mv88e6xxx_port_fdb_del,
4138 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004139 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4140 .port_mdb_add = mv88e6xxx_port_mdb_add,
4141 .port_mdb_del = mv88e6xxx_port_mdb_del,
4142 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004143};
4144
Vivien Didelotfad09c72016-06-21 12:28:20 -04004145static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004146 struct device_node *np)
4147{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004148 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004149 struct dsa_switch *ds;
4150
4151 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
4152 if (!ds)
4153 return -ENOMEM;
4154
4155 ds->dev = dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004156 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004157 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004158
4159 dev_set_drvdata(dev, ds);
4160
4161 return dsa_register_switch(ds, np);
4162}
4163
Vivien Didelotfad09c72016-06-21 12:28:20 -04004164static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004165{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004166 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004167}
4168
Vivien Didelot57d32312016-06-20 13:13:58 -04004169static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004170{
4171 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004172 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004173 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004174 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004175 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004176 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004177
Vivien Didelotcaac8542016-06-20 13:14:09 -04004178 compat_info = of_device_get_match_data(dev);
4179 if (!compat_info)
4180 return -EINVAL;
4181
Vivien Didelotfad09c72016-06-21 12:28:20 -04004182 chip = mv88e6xxx_alloc_chip(dev);
4183 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004184 return -ENOMEM;
4185
Vivien Didelotfad09c72016-06-21 12:28:20 -04004186 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004187
Vivien Didelotfad09c72016-06-21 12:28:20 -04004188 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004189 if (err)
4190 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004191
Andrew Lunnb4308f02016-11-21 23:26:55 +01004192 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4193 if (IS_ERR(chip->reset))
4194 return PTR_ERR(chip->reset);
4195
Vivien Didelotfad09c72016-06-21 12:28:20 -04004196 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004197 if (err)
4198 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004199
Vivien Didelote57e5e72016-08-15 17:19:00 -04004200 mv88e6xxx_phy_init(chip);
4201
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004202 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004203 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004204 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004205
Andrew Lunndc30c352016-10-16 19:56:49 +02004206 mutex_lock(&chip->reg_lock);
4207 err = mv88e6xxx_switch_reset(chip);
4208 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004209 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004210 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004211
Andrew Lunndc30c352016-10-16 19:56:49 +02004212 chip->irq = of_irq_get(np, 0);
4213 if (chip->irq == -EPROBE_DEFER) {
4214 err = chip->irq;
4215 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004216 }
4217
Andrew Lunndc30c352016-10-16 19:56:49 +02004218 if (chip->irq > 0) {
4219 /* Has to be performed before the MDIO bus is created,
4220 * because the PHYs will link there interrupts to these
4221 * interrupt controllers
4222 */
4223 mutex_lock(&chip->reg_lock);
4224 err = mv88e6xxx_g1_irq_setup(chip);
4225 mutex_unlock(&chip->reg_lock);
4226
4227 if (err)
4228 goto out;
4229
4230 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4231 err = mv88e6xxx_g2_irq_setup(chip);
4232 if (err)
4233 goto out_g1_irq;
4234 }
4235 }
4236
4237 err = mv88e6xxx_mdio_register(chip, np);
4238 if (err)
4239 goto out_g2_irq;
4240
4241 err = mv88e6xxx_register_switch(chip, np);
4242 if (err)
4243 goto out_mdio;
4244
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004245 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004246
4247out_mdio:
4248 mv88e6xxx_mdio_unregister(chip);
4249out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004250 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004251 mv88e6xxx_g2_irq_free(chip);
4252out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004253 if (chip->irq > 0) {
4254 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004255 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004256 mutex_unlock(&chip->reg_lock);
4257 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004258out:
4259 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004260}
4261
4262static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4263{
4264 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004265 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004266
Andrew Lunn930188c2016-08-22 16:01:03 +02004267 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004268 mv88e6xxx_unregister_switch(chip);
4269 mv88e6xxx_mdio_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004270
Andrew Lunn467126442016-11-20 20:14:15 +01004271 if (chip->irq > 0) {
4272 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4273 mv88e6xxx_g2_irq_free(chip);
4274 mv88e6xxx_g1_irq_free(chip);
4275 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004276}
4277
4278static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004279 {
4280 .compatible = "marvell,mv88e6085",
4281 .data = &mv88e6xxx_table[MV88E6085],
4282 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004283 {
4284 .compatible = "marvell,mv88e6190",
4285 .data = &mv88e6xxx_table[MV88E6190],
4286 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004287 { /* sentinel */ },
4288};
4289
4290MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4291
4292static struct mdio_driver mv88e6xxx_driver = {
4293 .probe = mv88e6xxx_probe,
4294 .remove = mv88e6xxx_remove,
4295 .mdiodrv.driver = {
4296 .name = "mv88e6085",
4297 .of_match_table = mv88e6xxx_of_match,
4298 },
4299};
4300
Ben Hutchings98e67302011-11-25 14:36:19 +00004301static int __init mv88e6xxx_init(void)
4302{
Vivien Didelot9d490b42016-08-23 12:38:56 -04004303 register_switch_driver(&mv88e6xxx_switch_ops);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004304 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004305}
4306module_init(mv88e6xxx_init);
4307
4308static void __exit mv88e6xxx_cleanup(void)
4309{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004310 mdio_driver_unregister(&mv88e6xxx_driver);
Vivien Didelot9d490b42016-08-23 12:38:56 -04004311 unregister_switch_driver(&mv88e6xxx_switch_ops);
Ben Hutchings98e67302011-11-25 14:36:19 +00004312}
4313module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004314
4315MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4316MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4317MODULE_LICENSE("GPL");