blob: 953c677e7b8e803d66c77bf0555a52d7fa031039 [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
Andreas Färber5edef2f2016-11-27 23:26:28 +0100424 for (irq = 0; irq < chip->g1_irq.nirqs; 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 Didelot17e708b2016-12-05 17:30:27 -0500548 val &= GLOBAL_STATUS_PPU_STATE_MASK;
549 if (val != GLOBAL_STATUS_PPU_STATE_POLLING)
Barry Grussling85686582013-01-08 16:05:56 +0000550 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000551 }
552
553 return -ETIMEDOUT;
554}
555
Vivien Didelotfad09c72016-06-21 12:28:20 -0400556static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000557{
Vivien Didelota935c052016-09-29 12:21:53 -0400558 u16 val;
559 int i, err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000560
Vivien Didelota935c052016-09-29 12:21:53 -0400561 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &val);
562 if (err)
563 return err;
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200564
Vivien Didelota935c052016-09-29 12:21:53 -0400565 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL,
566 val | GLOBAL_CONTROL_PPU_ENABLE);
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200567 if (err)
568 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000569
Andrew Lunn6441e6692016-08-19 00:01:55 +0200570 for (i = 0; i < 16; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -0400571 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &val);
572 if (err)
573 return err;
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200574
Barry Grussling19b2f972013-01-08 16:05:54 +0000575 usleep_range(1000, 2000);
Vivien Didelot17e708b2016-12-05 17:30:27 -0500576 val &= GLOBAL_STATUS_PPU_STATE_MASK;
577 if (val == GLOBAL_STATUS_PPU_STATE_POLLING)
Barry Grussling85686582013-01-08 16:05:56 +0000578 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000579 }
580
581 return -ETIMEDOUT;
582}
583
584static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
585{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400586 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000587
Vivien Didelotfad09c72016-06-21 12:28:20 -0400588 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200589
Vivien Didelotfad09c72016-06-21 12:28:20 -0400590 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200591
Vivien Didelotfad09c72016-06-21 12:28:20 -0400592 if (mutex_trylock(&chip->ppu_mutex)) {
593 if (mv88e6xxx_ppu_enable(chip) == 0)
594 chip->ppu_disabled = 0;
595 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000596 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200597
Vivien Didelotfad09c72016-06-21 12:28:20 -0400598 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000599}
600
601static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
602{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400603 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000604
Vivien Didelotfad09c72016-06-21 12:28:20 -0400605 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000606}
607
Vivien Didelotfad09c72016-06-21 12:28:20 -0400608static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000609{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000610 int ret;
611
Vivien Didelotfad09c72016-06-21 12:28:20 -0400612 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000613
Barry Grussling3675c8d2013-01-08 16:05:53 +0000614 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000615 * we can access the PHY registers. If it was already
616 * disabled, cancel the timer that is going to re-enable
617 * it.
618 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400619 if (!chip->ppu_disabled) {
620 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000621 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400622 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000623 return ret;
624 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400625 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000626 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400627 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000628 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000629 }
630
631 return ret;
632}
633
Vivien Didelotfad09c72016-06-21 12:28:20 -0400634static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000635{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000636 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400637 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
638 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000639}
640
Vivien Didelotfad09c72016-06-21 12:28:20 -0400641static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000642{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400643 mutex_init(&chip->ppu_mutex);
644 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000645 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
646 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000647}
648
Andrew Lunn930188c2016-08-22 16:01:03 +0200649static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
650{
651 del_timer_sync(&chip->ppu_timer);
652}
653
Vivien Didelote57e5e72016-08-15 17:19:00 -0400654static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip, int addr,
655 int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000656{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400657 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000658
Vivien Didelote57e5e72016-08-15 17:19:00 -0400659 err = mv88e6xxx_ppu_access_get(chip);
660 if (!err) {
661 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400662 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000663 }
664
Vivien Didelote57e5e72016-08-15 17:19:00 -0400665 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000666}
667
Vivien Didelote57e5e72016-08-15 17:19:00 -0400668static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip, int addr,
669 int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000670{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400671 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000672
Vivien Didelote57e5e72016-08-15 17:19:00 -0400673 err = mv88e6xxx_ppu_access_get(chip);
674 if (!err) {
675 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400676 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000677 }
678
Vivien Didelote57e5e72016-08-15 17:19:00 -0400679 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000680}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000681
Vivien Didelotfad09c72016-06-21 12:28:20 -0400682static bool mv88e6xxx_6095_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200683{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400684 return chip->info->family == MV88E6XXX_FAMILY_6095;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200685}
686
Vivien Didelotfad09c72016-06-21 12:28:20 -0400687static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200688{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400689 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200690}
691
Vivien Didelotfad09c72016-06-21 12:28:20 -0400692static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200693{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400694 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200695}
696
Vivien Didelotfad09c72016-06-21 12:28:20 -0400697static bool mv88e6xxx_6185_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200698{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400699 return chip->info->family == MV88E6XXX_FAMILY_6185;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200700}
701
Vivien Didelotfad09c72016-06-21 12:28:20 -0400702static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700703{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400704 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700705}
706
Vivien Didelotfad09c72016-06-21 12:28:20 -0400707static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200708{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400709 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200710}
711
Vivien Didelotfad09c72016-06-21 12:28:20 -0400712static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200713{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400714 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200715}
716
Vivien Didelotd78343d2016-11-04 03:23:36 +0100717static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
718 int link, int speed, int duplex,
719 phy_interface_t mode)
720{
721 int err;
722
723 if (!chip->info->ops->port_set_link)
724 return 0;
725
726 /* Port's MAC control must not be changed unless the link is down */
727 err = chip->info->ops->port_set_link(chip, port, 0);
728 if (err)
729 return err;
730
731 if (chip->info->ops->port_set_speed) {
732 err = chip->info->ops->port_set_speed(chip, port, speed);
733 if (err && err != -EOPNOTSUPP)
734 goto restore_link;
735 }
736
737 if (chip->info->ops->port_set_duplex) {
738 err = chip->info->ops->port_set_duplex(chip, port, duplex);
739 if (err && err != -EOPNOTSUPP)
740 goto restore_link;
741 }
742
743 if (chip->info->ops->port_set_rgmii_delay) {
744 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
745 if (err && err != -EOPNOTSUPP)
746 goto restore_link;
747 }
748
749 err = 0;
750restore_link:
751 if (chip->info->ops->port_set_link(chip, port, link))
752 netdev_err(chip->ds->ports[port].netdev,
753 "failed to restore MAC's link\n");
754
755 return err;
756}
757
Andrew Lunndea87022015-08-31 15:56:47 +0200758/* We expect the switch to perform auto negotiation if there is a real
759 * phy. However, in the case of a fixed link phy, we force the port
760 * settings from the fixed link settings.
761 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400762static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
763 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200764{
Vivien Didelot04bed142016-08-31 18:06:13 -0400765 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200766 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200767
768 if (!phy_is_pseudo_fixed_link(phydev))
769 return;
770
Vivien Didelotfad09c72016-06-21 12:28:20 -0400771 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100772 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
773 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400774 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100775
776 if (err && err != -EOPNOTSUPP)
777 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200778}
779
Andrew Lunna605a0f2016-11-21 23:26:58 +0100780static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000781{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100782 if (!chip->info->ops->stats_snapshot)
783 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000784
Andrew Lunna605a0f2016-11-21 23:26:58 +0100785 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000786}
787
Andrew Lunne413e7e2015-04-02 04:06:38 +0200788static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100789 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
790 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
791 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
792 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
793 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
794 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
795 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
796 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
797 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
798 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
799 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
800 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
801 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
802 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
803 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
804 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
805 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
806 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
807 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
808 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
809 { "single", 4, 0x14, STATS_TYPE_BANK0, },
810 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
811 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
812 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
813 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
814 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
815 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
816 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
817 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
818 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
819 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
820 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
821 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
822 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
823 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
824 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
825 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
826 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
827 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
828 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
829 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
830 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
831 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
832 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
833 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
834 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
835 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
836 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
837 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
838 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
839 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
840 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
841 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
842 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
843 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
844 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
845 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
846 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
847 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200848};
849
Vivien Didelotfad09c72016-06-21 12:28:20 -0400850static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100851 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100852 int port, u16 bank1_select,
853 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200854{
Andrew Lunn80c46272015-06-20 18:42:30 +0200855 u32 low;
856 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100857 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200858 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200859 u64 value;
860
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100861 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100862 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200863 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
864 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200865 return UINT64_MAX;
866
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200867 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200868 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200869 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
870 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200871 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200872 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200873 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100874 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100875 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100876 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100877 /* fall through */
878 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100879 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100880 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200881 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100882 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200883 }
884 value = (((u64)high) << 16) | low;
885 return value;
886}
887
Andrew Lunndfafe442016-11-21 23:27:02 +0100888static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
889 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100890{
891 struct mv88e6xxx_hw_stat *stat;
892 int i, j;
893
894 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
895 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100896 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100897 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
898 ETH_GSTRING_LEN);
899 j++;
900 }
901 }
902}
903
Andrew Lunndfafe442016-11-21 23:27:02 +0100904static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
905 uint8_t *data)
906{
907 mv88e6xxx_stats_get_strings(chip, data,
908 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
909}
910
911static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
912 uint8_t *data)
913{
914 mv88e6xxx_stats_get_strings(chip, data,
915 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
916}
917
918static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
919 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100920{
Vivien Didelot04bed142016-08-31 18:06:13 -0400921 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100922
923 if (chip->info->ops->stats_get_strings)
924 chip->info->ops->stats_get_strings(chip, data);
925}
926
927static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
928 int types)
929{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100930 struct mv88e6xxx_hw_stat *stat;
931 int i, j;
932
933 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
934 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100935 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100936 j++;
937 }
938 return j;
939}
940
Andrew Lunndfafe442016-11-21 23:27:02 +0100941static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
942{
943 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
944 STATS_TYPE_PORT);
945}
946
947static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
948{
949 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
950 STATS_TYPE_BANK1);
951}
952
953static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
954{
955 struct mv88e6xxx_chip *chip = ds->priv;
956
957 if (chip->info->ops->stats_get_sset_count)
958 return chip->info->ops->stats_get_sset_count(chip);
959
960 return 0;
961}
962
Andrew Lunn052f9472016-11-21 23:27:03 +0100963static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100964 uint64_t *data, int types,
965 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100966{
967 struct mv88e6xxx_hw_stat *stat;
968 int i, j;
969
970 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
971 stat = &mv88e6xxx_hw_stats[i];
972 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100973 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
974 bank1_select,
975 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100976 j++;
977 }
978 }
979}
980
981static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
982 uint64_t *data)
983{
984 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100985 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
986 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100987}
988
989static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
990 uint64_t *data)
991{
992 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100993 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
994 GLOBAL_STATS_OP_BANK_1_BIT_9,
995 GLOBAL_STATS_OP_HIST_RX_TX);
996}
997
998static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
999 uint64_t *data)
1000{
1001 return mv88e6xxx_stats_get_stats(chip, port, data,
1002 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1003 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001004}
1005
1006static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1007 uint64_t *data)
1008{
1009 if (chip->info->ops->stats_get_stats)
1010 chip->info->ops->stats_get_stats(chip, port, data);
1011}
1012
Vivien Didelotf81ec902016-05-09 13:22:58 -04001013static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1014 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001015{
Vivien Didelot04bed142016-08-31 18:06:13 -04001016 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001017 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001018
Vivien Didelotfad09c72016-06-21 12:28:20 -04001019 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001020
Andrew Lunna605a0f2016-11-21 23:26:58 +01001021 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001022 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001023 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001024 return;
1025 }
Andrew Lunn052f9472016-11-21 23:27:03 +01001026
1027 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001028
Vivien Didelotfad09c72016-06-21 12:28:20 -04001029 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001030}
Ben Hutchings98e67302011-11-25 14:36:19 +00001031
Andrew Lunnde2273872016-11-21 23:27:01 +01001032static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1033{
1034 if (chip->info->ops->stats_set_histogram)
1035 return chip->info->ops->stats_set_histogram(chip);
1036
1037 return 0;
1038}
1039
Vivien Didelotf81ec902016-05-09 13:22:58 -04001040static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001041{
1042 return 32 * sizeof(u16);
1043}
1044
Vivien Didelotf81ec902016-05-09 13:22:58 -04001045static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1046 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001047{
Vivien Didelot04bed142016-08-31 18:06:13 -04001048 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001049 int err;
1050 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001051 u16 *p = _p;
1052 int i;
1053
1054 regs->version = 0;
1055
1056 memset(p, 0xff, 32 * sizeof(u16));
1057
Vivien Didelotfad09c72016-06-21 12:28:20 -04001058 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001059
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001060 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001061
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001062 err = mv88e6xxx_port_read(chip, port, i, &reg);
1063 if (!err)
1064 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001065 }
Vivien Didelot23062512016-05-09 13:22:45 -04001066
Vivien Didelotfad09c72016-06-21 12:28:20 -04001067 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001068}
1069
Vivien Didelotfad09c72016-06-21 12:28:20 -04001070static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001071{
Vivien Didelota935c052016-09-29 12:21:53 -04001072 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001073}
1074
Vivien Didelotf81ec902016-05-09 13:22:58 -04001075static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1076 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001077{
Vivien Didelot04bed142016-08-31 18:06:13 -04001078 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001079 u16 reg;
1080 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001081
Vivien Didelotfad09c72016-06-21 12:28:20 -04001082 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001083 return -EOPNOTSUPP;
1084
Vivien Didelotfad09c72016-06-21 12:28:20 -04001085 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001086
Vivien Didelot9c938292016-08-15 17:19:02 -04001087 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1088 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001089 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001090
1091 e->eee_enabled = !!(reg & 0x0200);
1092 e->tx_lpi_enabled = !!(reg & 0x0100);
1093
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001094 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001095 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001096 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001097
Andrew Lunncca8b132015-04-02 04:06:39 +02001098 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001099out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001100 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001101
1102 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001103}
1104
Vivien Didelotf81ec902016-05-09 13:22:58 -04001105static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1106 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001107{
Vivien Didelot04bed142016-08-31 18:06:13 -04001108 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001109 u16 reg;
1110 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001111
Vivien Didelotfad09c72016-06-21 12:28:20 -04001112 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001113 return -EOPNOTSUPP;
1114
Vivien Didelotfad09c72016-06-21 12:28:20 -04001115 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001116
Vivien Didelot9c938292016-08-15 17:19:02 -04001117 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1118 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001119 goto out;
1120
Vivien Didelot9c938292016-08-15 17:19:02 -04001121 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001122 if (e->eee_enabled)
1123 reg |= 0x0200;
1124 if (e->tx_lpi_enabled)
1125 reg |= 0x0100;
1126
Vivien Didelot9c938292016-08-15 17:19:02 -04001127 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001128out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001129 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001130
Vivien Didelot9c938292016-08-15 17:19:02 -04001131 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001132}
1133
Vivien Didelotfad09c72016-06-21 12:28:20 -04001134static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001135{
Vivien Didelota935c052016-09-29 12:21:53 -04001136 u16 val;
1137 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001138
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001139 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001140 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1141 if (err)
1142 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001143 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001144 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001145 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1146 if (err)
1147 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001148
Vivien Didelota935c052016-09-29 12:21:53 -04001149 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1150 (val & 0xfff) | ((fid << 8) & 0xf000));
1151 if (err)
1152 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001153
1154 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1155 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001156 }
1157
Vivien Didelota935c052016-09-29 12:21:53 -04001158 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1159 if (err)
1160 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001161
Vivien Didelotfad09c72016-06-21 12:28:20 -04001162 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001163}
1164
Vivien Didelotfad09c72016-06-21 12:28:20 -04001165static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001166 struct mv88e6xxx_atu_entry *entry)
1167{
1168 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1169
1170 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1171 unsigned int mask, shift;
1172
1173 if (entry->trunk) {
1174 data |= GLOBAL_ATU_DATA_TRUNK;
1175 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1176 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1177 } else {
1178 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1179 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1180 }
1181
1182 data |= (entry->portv_trunkid << shift) & mask;
1183 }
1184
Vivien Didelota935c052016-09-29 12:21:53 -04001185 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001186}
1187
Vivien Didelotfad09c72016-06-21 12:28:20 -04001188static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001189 struct mv88e6xxx_atu_entry *entry,
1190 bool static_too)
1191{
1192 int op;
1193 int err;
1194
Vivien Didelotfad09c72016-06-21 12:28:20 -04001195 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001196 if (err)
1197 return err;
1198
Vivien Didelotfad09c72016-06-21 12:28:20 -04001199 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001200 if (err)
1201 return err;
1202
1203 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001204 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1205 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1206 } else {
1207 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1208 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1209 }
1210
Vivien Didelotfad09c72016-06-21 12:28:20 -04001211 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001212}
1213
Vivien Didelotfad09c72016-06-21 12:28:20 -04001214static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001215 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001216{
1217 struct mv88e6xxx_atu_entry entry = {
1218 .fid = fid,
1219 .state = 0, /* EntryState bits must be 0 */
1220 };
1221
Vivien Didelotfad09c72016-06-21 12:28:20 -04001222 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001223}
1224
Vivien Didelotfad09c72016-06-21 12:28:20 -04001225static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001226 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001227{
1228 struct mv88e6xxx_atu_entry entry = {
1229 .trunk = false,
1230 .fid = fid,
1231 };
1232
1233 /* EntryState bits must be 0xF */
1234 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1235
1236 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1237 entry.portv_trunkid = (to_port & 0x0f) << 4;
1238 entry.portv_trunkid |= from_port & 0x0f;
1239
Vivien Didelotfad09c72016-06-21 12:28:20 -04001240 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001241}
1242
Vivien Didelotfad09c72016-06-21 12:28:20 -04001243static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001244 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001245{
1246 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001247 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001248}
1249
Vivien Didelotfad09c72016-06-21 12:28:20 -04001250static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001251{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001252 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001253 struct dsa_switch *ds = chip->ds;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001254 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001255 int i;
1256
1257 /* allow CPU port or DSA link(s) to send frames to every port */
1258 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001259 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001260 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001261 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001262 /* allow sending frames to every group member */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001263 if (bridge && chip->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001264 output_ports |= BIT(i);
1265
1266 /* allow sending frames to CPU port and DSA link(s) */
1267 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1268 output_ports |= BIT(i);
1269 }
1270 }
1271
1272 /* prevent frames from going back out of the port they came in on */
1273 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001274
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001275 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001276}
1277
Vivien Didelotf81ec902016-05-09 13:22:58 -04001278static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1279 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001280{
Vivien Didelot04bed142016-08-31 18:06:13 -04001281 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001282 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001283 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001284
1285 switch (state) {
1286 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001287 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001288 break;
1289 case BR_STATE_BLOCKING:
1290 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001291 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001292 break;
1293 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001294 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001295 break;
1296 case BR_STATE_FORWARDING:
1297 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001298 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001299 break;
1300 }
1301
Vivien Didelotfad09c72016-06-21 12:28:20 -04001302 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001303 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001304 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001305
1306 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001307 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001308}
1309
Vivien Didelot749efcb2016-09-22 16:49:24 -04001310static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1311{
1312 struct mv88e6xxx_chip *chip = ds->priv;
1313 int err;
1314
1315 mutex_lock(&chip->reg_lock);
1316 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1317 mutex_unlock(&chip->reg_lock);
1318
1319 if (err)
1320 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1321}
1322
Vivien Didelotfad09c72016-06-21 12:28:20 -04001323static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001324{
Vivien Didelota935c052016-09-29 12:21:53 -04001325 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001326}
1327
Vivien Didelotfad09c72016-06-21 12:28:20 -04001328static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001329{
Vivien Didelota935c052016-09-29 12:21:53 -04001330 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001331
Vivien Didelota935c052016-09-29 12:21:53 -04001332 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1333 if (err)
1334 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001335
Vivien Didelotfad09c72016-06-21 12:28:20 -04001336 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001337}
1338
Vivien Didelotfad09c72016-06-21 12:28:20 -04001339static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001340{
1341 int ret;
1342
Vivien Didelotfad09c72016-06-21 12:28:20 -04001343 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001344 if (ret < 0)
1345 return ret;
1346
Vivien Didelotfad09c72016-06-21 12:28:20 -04001347 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001348}
1349
Vivien Didelotfad09c72016-06-21 12:28:20 -04001350static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001351 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001352 unsigned int nibble_offset)
1353{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001354 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001355 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001356
1357 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001358 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001359
Vivien Didelota935c052016-09-29 12:21:53 -04001360 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1361 if (err)
1362 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001363 }
1364
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001365 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001366 unsigned int shift = (i % 4) * 4 + nibble_offset;
1367 u16 reg = regs[i / 4];
1368
1369 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1370 }
1371
1372 return 0;
1373}
1374
Vivien Didelotfad09c72016-06-21 12:28:20 -04001375static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001376 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001377{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001378 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001379}
1380
Vivien Didelotfad09c72016-06-21 12:28:20 -04001381static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001382 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001383{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001384 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001385}
1386
Vivien Didelotfad09c72016-06-21 12:28:20 -04001387static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001388 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001389 unsigned int nibble_offset)
1390{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001391 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001392 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001393
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001394 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001395 unsigned int shift = (i % 4) * 4 + nibble_offset;
1396 u8 data = entry->data[i];
1397
1398 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1399 }
1400
1401 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001402 u16 reg = regs[i];
1403
1404 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1405 if (err)
1406 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001407 }
1408
1409 return 0;
1410}
1411
Vivien Didelotfad09c72016-06-21 12:28:20 -04001412static int mv88e6xxx_vtu_data_write(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_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001416}
1417
Vivien Didelotfad09c72016-06-21 12:28:20 -04001418static int mv88e6xxx_stu_data_write(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_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001422}
1423
Vivien Didelotfad09c72016-06-21 12:28:20 -04001424static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001425{
Vivien Didelota935c052016-09-29 12:21:53 -04001426 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1427 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001428}
1429
Vivien Didelotfad09c72016-06-21 12:28:20 -04001430static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001431 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001432{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001433 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001434 u16 val;
1435 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001436
Vivien Didelota935c052016-09-29 12:21:53 -04001437 err = _mv88e6xxx_vtu_wait(chip);
1438 if (err)
1439 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001440
Vivien Didelota935c052016-09-29 12:21:53 -04001441 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1442 if (err)
1443 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001444
Vivien Didelota935c052016-09-29 12:21:53 -04001445 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1446 if (err)
1447 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001448
Vivien Didelota935c052016-09-29 12:21:53 -04001449 next.vid = val & GLOBAL_VTU_VID_MASK;
1450 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001451
1452 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001453 err = mv88e6xxx_vtu_data_read(chip, &next);
1454 if (err)
1455 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001456
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001457 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001458 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1459 if (err)
1460 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001461
Vivien Didelota935c052016-09-29 12:21:53 -04001462 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001463 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001464 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1465 * VTU DBNum[3:0] are located in VTU Operation 3:0
1466 */
Vivien Didelota935c052016-09-29 12:21:53 -04001467 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1468 if (err)
1469 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001470
Vivien Didelota935c052016-09-29 12:21:53 -04001471 next.fid = (val & 0xf00) >> 4;
1472 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001473 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001474
Vivien Didelotfad09c72016-06-21 12:28:20 -04001475 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001476 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1477 if (err)
1478 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001479
Vivien Didelota935c052016-09-29 12:21:53 -04001480 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001481 }
1482 }
1483
1484 *entry = next;
1485 return 0;
1486}
1487
Vivien Didelotf81ec902016-05-09 13:22:58 -04001488static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1489 struct switchdev_obj_port_vlan *vlan,
1490 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001491{
Vivien Didelot04bed142016-08-31 18:06:13 -04001492 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001493 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001494 u16 pvid;
1495 int err;
1496
Vivien Didelotfad09c72016-06-21 12:28:20 -04001497 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001498 return -EOPNOTSUPP;
1499
Vivien Didelotfad09c72016-06-21 12:28:20 -04001500 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001501
Vivien Didelot77064f32016-11-04 03:23:30 +01001502 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001503 if (err)
1504 goto unlock;
1505
Vivien Didelotfad09c72016-06-21 12:28:20 -04001506 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001507 if (err)
1508 goto unlock;
1509
1510 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001511 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001512 if (err)
1513 break;
1514
1515 if (!next.valid)
1516 break;
1517
1518 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1519 continue;
1520
1521 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001522 vlan->vid_begin = next.vid;
1523 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001524 vlan->flags = 0;
1525
1526 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1527 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1528
1529 if (next.vid == pvid)
1530 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1531
1532 err = cb(&vlan->obj);
1533 if (err)
1534 break;
1535 } while (next.vid < GLOBAL_VTU_VID_MASK);
1536
1537unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001538 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001539
1540 return err;
1541}
1542
Vivien Didelotfad09c72016-06-21 12:28:20 -04001543static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001544 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001545{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001546 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001547 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001548 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001549
Vivien Didelota935c052016-09-29 12:21:53 -04001550 err = _mv88e6xxx_vtu_wait(chip);
1551 if (err)
1552 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001553
1554 if (!entry->valid)
1555 goto loadpurge;
1556
1557 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001558 err = mv88e6xxx_vtu_data_write(chip, entry);
1559 if (err)
1560 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001561
Vivien Didelotfad09c72016-06-21 12:28:20 -04001562 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001563 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001564 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1565 if (err)
1566 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001567 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001568
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001569 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001570 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001571 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1572 if (err)
1573 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001574 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001575 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1576 * VTU DBNum[3:0] are located in VTU Operation 3:0
1577 */
1578 op |= (entry->fid & 0xf0) << 8;
1579 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001580 }
1581
1582 reg = GLOBAL_VTU_VID_VALID;
1583loadpurge:
1584 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001585 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1586 if (err)
1587 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001588
Vivien Didelotfad09c72016-06-21 12:28:20 -04001589 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001590}
1591
Vivien Didelotfad09c72016-06-21 12:28:20 -04001592static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001593 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001594{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001595 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001596 u16 val;
1597 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001598
Vivien Didelota935c052016-09-29 12:21:53 -04001599 err = _mv88e6xxx_vtu_wait(chip);
1600 if (err)
1601 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001602
Vivien Didelota935c052016-09-29 12:21:53 -04001603 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1604 sid & GLOBAL_VTU_SID_MASK);
1605 if (err)
1606 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001607
Vivien Didelota935c052016-09-29 12:21:53 -04001608 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1609 if (err)
1610 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001611
Vivien Didelota935c052016-09-29 12:21:53 -04001612 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1613 if (err)
1614 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001615
Vivien Didelota935c052016-09-29 12:21:53 -04001616 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001617
Vivien Didelota935c052016-09-29 12:21:53 -04001618 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1619 if (err)
1620 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001621
Vivien Didelota935c052016-09-29 12:21:53 -04001622 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001623
1624 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001625 err = mv88e6xxx_stu_data_read(chip, &next);
1626 if (err)
1627 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001628 }
1629
1630 *entry = next;
1631 return 0;
1632}
1633
Vivien Didelotfad09c72016-06-21 12:28:20 -04001634static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001635 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001636{
1637 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001638 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001639
Vivien Didelota935c052016-09-29 12:21:53 -04001640 err = _mv88e6xxx_vtu_wait(chip);
1641 if (err)
1642 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001643
1644 if (!entry->valid)
1645 goto loadpurge;
1646
1647 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001648 err = mv88e6xxx_stu_data_write(chip, entry);
1649 if (err)
1650 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001651
1652 reg = GLOBAL_VTU_VID_VALID;
1653loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001654 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1655 if (err)
1656 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001657
1658 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001659 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1660 if (err)
1661 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001662
Vivien Didelotfad09c72016-06-21 12:28:20 -04001663 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001664}
1665
Vivien Didelotfad09c72016-06-21 12:28:20 -04001666static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001667{
1668 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001669 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001670 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001671
1672 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1673
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001674 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001675 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001676 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001677 if (err)
1678 return err;
1679
1680 set_bit(*fid, fid_bitmap);
1681 }
1682
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001683 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001684 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001685 if (err)
1686 return err;
1687
1688 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001689 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001690 if (err)
1691 return err;
1692
1693 if (!vlan.valid)
1694 break;
1695
1696 set_bit(vlan.fid, fid_bitmap);
1697 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1698
1699 /* The reset value 0x000 is used to indicate that multiple address
1700 * databases are not needed. Return the next positive available.
1701 */
1702 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001703 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001704 return -ENOSPC;
1705
1706 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001707 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001708}
1709
Vivien Didelotfad09c72016-06-21 12:28:20 -04001710static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001711 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001712{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001713 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001714 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001715 .valid = true,
1716 .vid = vid,
1717 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001718 int i, err;
1719
Vivien Didelotfad09c72016-06-21 12:28:20 -04001720 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001721 if (err)
1722 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001723
Vivien Didelot3d131f02015-11-03 10:52:52 -05001724 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001725 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001726 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1727 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1728 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001729
Vivien Didelotfad09c72016-06-21 12:28:20 -04001730 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
1731 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001732 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001733
1734 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1735 * implemented, only one STU entry is needed to cover all VTU
1736 * entries. Thus, validate the SID 0.
1737 */
1738 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001739 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001740 if (err)
1741 return err;
1742
1743 if (vstp.sid != vlan.sid || !vstp.valid) {
1744 memset(&vstp, 0, sizeof(vstp));
1745 vstp.valid = true;
1746 vstp.sid = vlan.sid;
1747
Vivien Didelotfad09c72016-06-21 12:28:20 -04001748 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001749 if (err)
1750 return err;
1751 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001752 }
1753
1754 *entry = vlan;
1755 return 0;
1756}
1757
Vivien Didelotfad09c72016-06-21 12:28:20 -04001758static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001759 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001760{
1761 int err;
1762
1763 if (!vid)
1764 return -EINVAL;
1765
Vivien Didelotfad09c72016-06-21 12:28:20 -04001766 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001767 if (err)
1768 return err;
1769
Vivien Didelotfad09c72016-06-21 12:28:20 -04001770 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001771 if (err)
1772 return err;
1773
1774 if (entry->vid != vid || !entry->valid) {
1775 if (!creat)
1776 return -EOPNOTSUPP;
1777 /* -ENOENT would've been more appropriate, but switchdev expects
1778 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1779 */
1780
Vivien Didelotfad09c72016-06-21 12:28:20 -04001781 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001782 }
1783
1784 return err;
1785}
1786
Vivien Didelotda9c3592016-02-12 12:09:40 -05001787static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1788 u16 vid_begin, u16 vid_end)
1789{
Vivien Didelot04bed142016-08-31 18:06:13 -04001790 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001791 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001792 int i, err;
1793
1794 if (!vid_begin)
1795 return -EOPNOTSUPP;
1796
Vivien Didelotfad09c72016-06-21 12:28:20 -04001797 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001798
Vivien Didelotfad09c72016-06-21 12:28:20 -04001799 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001800 if (err)
1801 goto unlock;
1802
1803 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001804 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001805 if (err)
1806 goto unlock;
1807
1808 if (!vlan.valid)
1809 break;
1810
1811 if (vlan.vid > vid_end)
1812 break;
1813
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001814 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001815 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1816 continue;
1817
1818 if (vlan.data[i] ==
1819 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1820 continue;
1821
Vivien Didelotfad09c72016-06-21 12:28:20 -04001822 if (chip->ports[i].bridge_dev ==
1823 chip->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001824 break; /* same bridge, check next VLAN */
1825
Andrew Lunnc8b09802016-06-04 21:16:57 +02001826 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001827 "hardware VLAN %d already used by %s\n",
1828 vlan.vid,
Vivien Didelotfad09c72016-06-21 12:28:20 -04001829 netdev_name(chip->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001830 err = -EOPNOTSUPP;
1831 goto unlock;
1832 }
1833 } while (vlan.vid < vid_end);
1834
1835unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001836 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001837
1838 return err;
1839}
1840
Vivien Didelotf81ec902016-05-09 13:22:58 -04001841static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1842 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001843{
Vivien Didelot04bed142016-08-31 18:06:13 -04001844 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001845 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001846 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001847 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001848
Vivien Didelotfad09c72016-06-21 12:28:20 -04001849 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001850 return -EOPNOTSUPP;
1851
Vivien Didelotfad09c72016-06-21 12:28:20 -04001852 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001853 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001854 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001855
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001856 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001857}
1858
Vivien Didelot57d32312016-06-20 13:13:58 -04001859static int
1860mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1861 const struct switchdev_obj_port_vlan *vlan,
1862 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001863{
Vivien Didelot04bed142016-08-31 18:06:13 -04001864 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001865 int err;
1866
Vivien Didelotfad09c72016-06-21 12:28:20 -04001867 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001868 return -EOPNOTSUPP;
1869
Vivien Didelotda9c3592016-02-12 12:09:40 -05001870 /* If the requested port doesn't belong to the same bridge as the VLAN
1871 * members, do not support it (yet) and fallback to software VLAN.
1872 */
1873 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1874 vlan->vid_end);
1875 if (err)
1876 return err;
1877
Vivien Didelot76e398a2015-11-01 12:33:55 -05001878 /* We don't need any dynamic resource from the kernel (yet),
1879 * so skip the prepare phase.
1880 */
1881 return 0;
1882}
1883
Vivien Didelotfad09c72016-06-21 12:28:20 -04001884static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001885 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001886{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001887 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001888 int err;
1889
Vivien Didelotfad09c72016-06-21 12:28:20 -04001890 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001891 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001892 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001893
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001894 vlan.data[port] = untagged ?
1895 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1896 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1897
Vivien Didelotfad09c72016-06-21 12:28:20 -04001898 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001899}
1900
Vivien Didelotf81ec902016-05-09 13:22:58 -04001901static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1902 const struct switchdev_obj_port_vlan *vlan,
1903 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001904{
Vivien Didelot04bed142016-08-31 18:06:13 -04001905 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001906 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1907 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1908 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001909
Vivien Didelotfad09c72016-06-21 12:28:20 -04001910 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001911 return;
1912
Vivien Didelotfad09c72016-06-21 12:28:20 -04001913 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001914
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001915 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001916 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001917 netdev_err(ds->ports[port].netdev,
1918 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001919 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001920
Vivien Didelot77064f32016-11-04 03:23:30 +01001921 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001922 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001923 vlan->vid_end);
1924
Vivien Didelotfad09c72016-06-21 12:28:20 -04001925 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001926}
1927
Vivien Didelotfad09c72016-06-21 12:28:20 -04001928static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001929 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001930{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001931 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001932 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001933 int i, err;
1934
Vivien Didelotfad09c72016-06-21 12:28:20 -04001935 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001936 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001937 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001938
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001939 /* Tell switchdev if this VLAN is handled in software */
1940 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001941 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001942
1943 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1944
1945 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001946 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001947 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001948 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001949 continue;
1950
1951 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001952 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001953 break;
1954 }
1955 }
1956
Vivien Didelotfad09c72016-06-21 12:28:20 -04001957 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001958 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001959 return err;
1960
Vivien Didelotfad09c72016-06-21 12:28:20 -04001961 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001962}
1963
Vivien Didelotf81ec902016-05-09 13:22:58 -04001964static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1965 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001966{
Vivien Didelot04bed142016-08-31 18:06:13 -04001967 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001968 u16 pvid, vid;
1969 int err = 0;
1970
Vivien Didelotfad09c72016-06-21 12:28:20 -04001971 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001972 return -EOPNOTSUPP;
1973
Vivien Didelotfad09c72016-06-21 12:28:20 -04001974 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001975
Vivien Didelot77064f32016-11-04 03:23:30 +01001976 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001977 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001978 goto unlock;
1979
Vivien Didelot76e398a2015-11-01 12:33:55 -05001980 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001981 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001982 if (err)
1983 goto unlock;
1984
1985 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001986 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001987 if (err)
1988 goto unlock;
1989 }
1990 }
1991
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001992unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001993 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001994
1995 return err;
1996}
1997
Vivien Didelotfad09c72016-06-21 12:28:20 -04001998static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04001999 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002000{
Vivien Didelota935c052016-09-29 12:21:53 -04002001 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002002
2003 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002004 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
2005 (addr[i * 2] << 8) | addr[i * 2 + 1]);
2006 if (err)
2007 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002008 }
2009
2010 return 0;
2011}
2012
Vivien Didelotfad09c72016-06-21 12:28:20 -04002013static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04002014 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002015{
Vivien Didelota935c052016-09-29 12:21:53 -04002016 u16 val;
2017 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002018
2019 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002020 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
2021 if (err)
2022 return err;
2023
2024 addr[i * 2] = val >> 8;
2025 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002026 }
2027
2028 return 0;
2029}
2030
Vivien Didelotfad09c72016-06-21 12:28:20 -04002031static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04002032 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002033{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002034 int ret;
2035
Vivien Didelotfad09c72016-06-21 12:28:20 -04002036 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002037 if (ret < 0)
2038 return ret;
2039
Vivien Didelotfad09c72016-06-21 12:28:20 -04002040 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002041 if (ret < 0)
2042 return ret;
2043
Vivien Didelotfad09c72016-06-21 12:28:20 -04002044 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002045 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002046 return ret;
2047
Vivien Didelotfad09c72016-06-21 12:28:20 -04002048 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002049}
David S. Millercdf09692015-08-11 12:00:37 -07002050
Vivien Didelot88472932016-09-19 19:56:11 -04002051static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2052 struct mv88e6xxx_atu_entry *entry);
2053
2054static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2055 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2056{
2057 struct mv88e6xxx_atu_entry next;
2058 int err;
2059
2060 eth_broadcast_addr(next.mac);
2061
2062 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2063 if (err)
2064 return err;
2065
2066 do {
2067 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2068 if (err)
2069 return err;
2070
2071 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2072 break;
2073
2074 if (ether_addr_equal(next.mac, addr)) {
2075 *entry = next;
2076 return 0;
2077 }
2078 } while (!is_broadcast_ether_addr(next.mac));
2079
2080 memset(entry, 0, sizeof(*entry));
2081 entry->fid = fid;
2082 ether_addr_copy(entry->mac, addr);
2083
2084 return 0;
2085}
2086
Vivien Didelot83dabd12016-08-31 11:50:04 -04002087static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2088 const unsigned char *addr, u16 vid,
2089 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002090{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002091 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002092 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002093 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002094
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002095 /* Null VLAN ID corresponds to the port private database */
2096 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002097 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002098 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002099 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002100 if (err)
2101 return err;
2102
Vivien Didelot88472932016-09-19 19:56:11 -04002103 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2104 if (err)
2105 return err;
2106
2107 /* Purge the ATU entry only if no port is using it anymore */
2108 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2109 entry.portv_trunkid &= ~BIT(port);
2110 if (!entry.portv_trunkid)
2111 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2112 } else {
2113 entry.portv_trunkid |= BIT(port);
2114 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002115 }
2116
Vivien Didelotfad09c72016-06-21 12:28:20 -04002117 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002118}
2119
Vivien Didelotf81ec902016-05-09 13:22:58 -04002120static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2121 const struct switchdev_obj_port_fdb *fdb,
2122 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002123{
2124 /* We don't need any dynamic resource from the kernel (yet),
2125 * so skip the prepare phase.
2126 */
2127 return 0;
2128}
2129
Vivien Didelotf81ec902016-05-09 13:22:58 -04002130static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2131 const struct switchdev_obj_port_fdb *fdb,
2132 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002133{
Vivien Didelot04bed142016-08-31 18:06:13 -04002134 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002135
Vivien Didelotfad09c72016-06-21 12:28:20 -04002136 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002137 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2138 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2139 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002140 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002141}
2142
Vivien Didelotf81ec902016-05-09 13:22:58 -04002143static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2144 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002145{
Vivien Didelot04bed142016-08-31 18:06:13 -04002146 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002147 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002148
Vivien Didelotfad09c72016-06-21 12:28:20 -04002149 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002150 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2151 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002152 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002153
Vivien Didelot83dabd12016-08-31 11:50:04 -04002154 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002155}
2156
Vivien Didelotfad09c72016-06-21 12:28:20 -04002157static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002158 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002159{
Vivien Didelot1d194042015-08-10 09:09:51 -04002160 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002161 u16 val;
2162 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002163
2164 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002165
Vivien Didelota935c052016-09-29 12:21:53 -04002166 err = _mv88e6xxx_atu_wait(chip);
2167 if (err)
2168 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002169
Vivien Didelota935c052016-09-29 12:21:53 -04002170 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2171 if (err)
2172 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002173
Vivien Didelota935c052016-09-29 12:21:53 -04002174 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2175 if (err)
2176 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002177
Vivien Didelota935c052016-09-29 12:21:53 -04002178 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2179 if (err)
2180 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002181
Vivien Didelota935c052016-09-29 12:21:53 -04002182 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002183 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2184 unsigned int mask, shift;
2185
Vivien Didelota935c052016-09-29 12:21:53 -04002186 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002187 next.trunk = true;
2188 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2189 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2190 } else {
2191 next.trunk = false;
2192 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2193 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2194 }
2195
Vivien Didelota935c052016-09-29 12:21:53 -04002196 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002197 }
2198
2199 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002200 return 0;
2201}
2202
Vivien Didelot83dabd12016-08-31 11:50:04 -04002203static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2204 u16 fid, u16 vid, int port,
2205 struct switchdev_obj *obj,
2206 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002207{
2208 struct mv88e6xxx_atu_entry addr = {
2209 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2210 };
2211 int err;
2212
Vivien Didelotfad09c72016-06-21 12:28:20 -04002213 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002214 if (err)
2215 return err;
2216
2217 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002218 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002219 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002220 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002221
2222 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2223 break;
2224
Vivien Didelot83dabd12016-08-31 11:50:04 -04002225 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2226 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002227
Vivien Didelot83dabd12016-08-31 11:50:04 -04002228 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2229 struct switchdev_obj_port_fdb *fdb;
2230
2231 if (!is_unicast_ether_addr(addr.mac))
2232 continue;
2233
2234 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002235 fdb->vid = vid;
2236 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002237 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2238 fdb->ndm_state = NUD_NOARP;
2239 else
2240 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002241 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2242 struct switchdev_obj_port_mdb *mdb;
2243
2244 if (!is_multicast_ether_addr(addr.mac))
2245 continue;
2246
2247 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2248 mdb->vid = vid;
2249 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002250 } else {
2251 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002252 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002253
2254 err = cb(obj);
2255 if (err)
2256 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002257 } while (!is_broadcast_ether_addr(addr.mac));
2258
2259 return err;
2260}
2261
Vivien Didelot83dabd12016-08-31 11:50:04 -04002262static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2263 struct switchdev_obj *obj,
2264 int (*cb)(struct switchdev_obj *obj))
2265{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002266 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002267 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2268 };
2269 u16 fid;
2270 int err;
2271
2272 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002273 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002274 if (err)
2275 return err;
2276
2277 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2278 if (err)
2279 return err;
2280
2281 /* Dump VLANs' Filtering Information Databases */
2282 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2283 if (err)
2284 return err;
2285
2286 do {
2287 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2288 if (err)
2289 return err;
2290
2291 if (!vlan.valid)
2292 break;
2293
2294 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2295 obj, cb);
2296 if (err)
2297 return err;
2298 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2299
2300 return err;
2301}
2302
Vivien Didelotf81ec902016-05-09 13:22:58 -04002303static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2304 struct switchdev_obj_port_fdb *fdb,
2305 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002306{
Vivien Didelot04bed142016-08-31 18:06:13 -04002307 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002308 int err;
2309
Vivien Didelotfad09c72016-06-21 12:28:20 -04002310 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002311 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002312 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002313
2314 return err;
2315}
2316
Vivien Didelotf81ec902016-05-09 13:22:58 -04002317static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
2318 struct net_device *bridge)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002319{
Vivien Didelot04bed142016-08-31 18:06:13 -04002320 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002321 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002322
Vivien Didelotfad09c72016-06-21 12:28:20 -04002323 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002324
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002325 /* Assign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002326 chip->ports[port].bridge_dev = bridge;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002327
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002328 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002329 if (chip->ports[i].bridge_dev == bridge) {
2330 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002331 if (err)
2332 break;
2333 }
2334 }
2335
Vivien Didelotfad09c72016-06-21 12:28:20 -04002336 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002337
Vivien Didelot466dfa02016-02-26 13:16:05 -05002338 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002339}
2340
Vivien Didelotf81ec902016-05-09 13:22:58 -04002341static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002342{
Vivien Didelot04bed142016-08-31 18:06:13 -04002343 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002344 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002345 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002346
Vivien Didelotfad09c72016-06-21 12:28:20 -04002347 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002348
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002349 /* Unassign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002350 chip->ports[port].bridge_dev = NULL;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002351
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002352 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002353 if (i == port || chip->ports[i].bridge_dev == bridge)
2354 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002355 netdev_warn(ds->ports[i].netdev,
2356 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002357
Vivien Didelotfad09c72016-06-21 12:28:20 -04002358 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002359}
2360
Vivien Didelot17e708b2016-12-05 17:30:27 -05002361static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2362{
2363 if (chip->info->ops->reset)
2364 return chip->info->ops->reset(chip);
2365
2366 return 0;
2367}
2368
Vivien Didelot309eca62016-12-05 17:30:26 -05002369static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2370{
2371 struct gpio_desc *gpiod = chip->reset;
2372
2373 /* If there is a GPIO connected to the reset pin, toggle it */
2374 if (gpiod) {
2375 gpiod_set_value_cansleep(gpiod, 1);
2376 usleep_range(10000, 20000);
2377 gpiod_set_value_cansleep(gpiod, 0);
2378 usleep_range(10000, 20000);
2379 }
2380}
2381
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002382static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2383{
2384 int i, err;
2385
2386 /* Set all ports to the Disabled state */
2387 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2388 err = mv88e6xxx_port_set_state(chip, i,
2389 PORT_CONTROL_STATE_DISABLED);
2390 if (err)
2391 return err;
2392 }
2393
2394 /* Wait for transmit queues to drain,
2395 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2396 */
2397 usleep_range(2000, 4000);
2398
2399 return 0;
2400}
2401
Vivien Didelotfad09c72016-06-21 12:28:20 -04002402static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002403{
Vivien Didelota935c052016-09-29 12:21:53 -04002404 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002405
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002406 err = mv88e6xxx_disable_ports(chip);
2407 if (err)
2408 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002409
Vivien Didelot309eca62016-12-05 17:30:26 -05002410 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002411
Vivien Didelot17e708b2016-12-05 17:30:27 -05002412 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002413}
2414
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002415static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002416{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002417 u16 val;
2418 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002419
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002420 /* Clear Power Down bit */
2421 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2422 if (err)
2423 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002424
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002425 if (val & BMCR_PDOWN) {
2426 val &= ~BMCR_PDOWN;
2427 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002428 }
2429
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002430 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002431}
2432
Andrew Lunn56995cb2016-12-03 04:35:19 +01002433static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2434 int upstream_port)
2435{
2436 int err;
2437
2438 err = chip->info->ops->port_set_frame_mode(
2439 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2440 if (err)
2441 return err;
2442
2443 return chip->info->ops->port_set_egress_unknowns(
2444 chip, port, port == upstream_port);
2445}
2446
2447static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2448{
2449 int err;
2450
2451 switch (chip->info->tag_protocol) {
2452 case DSA_TAG_PROTO_EDSA:
2453 err = chip->info->ops->port_set_frame_mode(
2454 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2455 if (err)
2456 return err;
2457
2458 err = mv88e6xxx_port_set_egress_mode(
2459 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2460 if (err)
2461 return err;
2462
2463 if (chip->info->ops->port_set_ether_type)
2464 err = chip->info->ops->port_set_ether_type(
2465 chip, port, ETH_P_EDSA);
2466 break;
2467
2468 case DSA_TAG_PROTO_DSA:
2469 err = chip->info->ops->port_set_frame_mode(
2470 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2471 if (err)
2472 return err;
2473
2474 err = mv88e6xxx_port_set_egress_mode(
2475 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2476 break;
2477 default:
2478 err = -EINVAL;
2479 }
2480
2481 if (err)
2482 return err;
2483
2484 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2485}
2486
2487static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2488{
2489 int err;
2490
2491 err = chip->info->ops->port_set_frame_mode(
2492 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2493 if (err)
2494 return err;
2495
2496 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2497}
2498
Vivien Didelotfad09c72016-06-21 12:28:20 -04002499static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002500{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002501 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002502 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002503 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002504
Vivien Didelotd78343d2016-11-04 03:23:36 +01002505 /* MAC Forcing register: don't force link, speed, duplex or flow control
2506 * state to any particular values on physical ports, but force the CPU
2507 * port and all DSA ports to their maximum bandwidth and full duplex.
2508 */
2509 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2510 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2511 SPEED_MAX, DUPLEX_FULL,
2512 PHY_INTERFACE_MODE_NA);
2513 else
2514 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2515 SPEED_UNFORCED, DUPLEX_UNFORCED,
2516 PHY_INTERFACE_MODE_NA);
2517 if (err)
2518 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002519
2520 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2521 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2522 * tunneling, determine priority by looking at 802.1p and IP
2523 * priority fields (IP prio has precedence), and set STP state
2524 * to Forwarding.
2525 *
2526 * If this is the CPU link, use DSA or EDSA tagging depending
2527 * on which tagging mode was configured.
2528 *
2529 * If this is a link to another switch, use DSA tagging mode.
2530 *
2531 * If this is the upstream port for this switch, enable
2532 * forwarding of unknown unicasts and multicasts.
2533 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002534 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002535 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2536 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002537 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2538 if (err)
2539 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002540
Andrew Lunn56995cb2016-12-03 04:35:19 +01002541 if (dsa_is_cpu_port(ds, port)) {
2542 err = mv88e6xxx_setup_port_cpu(chip, port);
2543 } else if (dsa_is_dsa_port(ds, port)) {
2544 err = mv88e6xxx_setup_port_dsa(chip, port,
2545 dsa_upstream_port(ds));
2546 } else {
2547 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002548 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002549 if (err)
2550 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002551
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002552 /* If this port is connected to a SerDes, make sure the SerDes is not
2553 * powered down.
2554 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002555 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002556 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2557 if (err)
2558 return err;
2559 reg &= PORT_STATUS_CMODE_MASK;
2560 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2561 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2562 (reg == PORT_STATUS_CMODE_SGMII)) {
2563 err = mv88e6xxx_serdes_power_on(chip);
2564 if (err < 0)
2565 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002566 }
2567 }
2568
Vivien Didelot8efdda42015-08-13 12:52:23 -04002569 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002570 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002571 * untagged frames on this port, do a destination address lookup on all
2572 * received packets as usual, disable ARP mirroring and don't send a
2573 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002574 */
2575 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002576 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2577 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2578 mv88e6xxx_6095_family(chip) || mv88e6xxx_6320_family(chip) ||
2579 mv88e6xxx_6185_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002580 reg = PORT_CONTROL_2_MAP_DA;
2581
Vivien Didelotfad09c72016-06-21 12:28:20 -04002582 if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002583 /* Set the upstream port this port should use */
2584 reg |= dsa_upstream_port(ds);
2585 /* enable forwarding of unknown multicast addresses to
2586 * the upstream port
2587 */
2588 if (port == dsa_upstream_port(ds))
2589 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
2590 }
2591
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002592 reg |= PORT_CONTROL_2_8021Q_DISABLED;
Vivien Didelot8efdda42015-08-13 12:52:23 -04002593
Andrew Lunn54d792f2015-05-06 01:09:47 +02002594 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002595 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
2596 if (err)
2597 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002598 }
2599
Andrew Lunn5f436662016-12-03 04:45:17 +01002600 if (chip->info->ops->port_jumbo_config) {
2601 err = chip->info->ops->port_jumbo_config(chip, port);
2602 if (err)
2603 return err;
2604 }
2605
Andrew Lunn54d792f2015-05-06 01:09:47 +02002606 /* Port Association Vector: when learning source addresses
2607 * of packets, add the address to the address database using
2608 * a port bitmap that has only the bit for this port set and
2609 * the other bits clear.
2610 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002611 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002612 /* Disable learning for CPU port */
2613 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002614 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002615
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002616 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2617 if (err)
2618 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002619
2620 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002621 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2622 if (err)
2623 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002624
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002625 if (chip->info->ops->port_pause_config) {
2626 err = chip->info->ops->port_pause_config(chip, port);
2627 if (err)
2628 return err;
2629 }
2630
Vivien Didelotfad09c72016-06-21 12:28:20 -04002631 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2632 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2633 mv88e6xxx_6320_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002634 /* Port ATU control: disable limiting the number of
2635 * address database entries that this port is allowed
2636 * to use.
2637 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002638 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2639 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002640 /* Priority Override: disable DA, SA and VTU priority
2641 * override.
2642 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002643 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2644 0x0000);
2645 if (err)
2646 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002647 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002648
Andrew Lunnef0a7312016-12-03 04:35:16 +01002649 if (chip->info->ops->port_tag_remap) {
2650 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002651 if (err)
2652 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002653 }
2654
Andrew Lunnef70b112016-12-03 04:45:18 +01002655 if (chip->info->ops->port_egress_rate_limiting) {
2656 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002657 if (err)
2658 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002659 }
2660
Guenter Roeck366f0a02015-03-26 18:36:30 -07002661 /* Port Control 1: disable trunking, disable sending
2662 * learning messages to this port.
Guenter Roeckd827e882015-03-26 18:36:29 -07002663 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002664 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_1, 0x0000);
2665 if (err)
2666 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002667
Vivien Didelot207afda2016-04-14 14:42:09 -04002668 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002669 * database, and allow bidirectional communication between the
2670 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002671 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002672 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002673 if (err)
2674 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002675
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002676 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2677 if (err)
2678 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002679
2680 /* Default VLAN ID and priority: don't set a default VLAN
2681 * ID, and set the default packet priority to zero.
2682 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002683 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002684}
2685
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002686static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002687{
2688 int err;
2689
Vivien Didelota935c052016-09-29 12:21:53 -04002690 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002691 if (err)
2692 return err;
2693
Vivien Didelota935c052016-09-29 12:21:53 -04002694 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002695 if (err)
2696 return err;
2697
Vivien Didelota935c052016-09-29 12:21:53 -04002698 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2699 if (err)
2700 return err;
2701
2702 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002703}
2704
Vivien Didelotacddbd22016-07-18 20:45:39 -04002705static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
2706 unsigned int msecs)
2707{
2708 const unsigned int coeff = chip->info->age_time_coeff;
2709 const unsigned int min = 0x01 * coeff;
2710 const unsigned int max = 0xff * coeff;
2711 u8 age_time;
2712 u16 val;
2713 int err;
2714
2715 if (msecs < min || msecs > max)
2716 return -ERANGE;
2717
2718 /* Round to nearest multiple of coeff */
2719 age_time = (msecs + coeff / 2) / coeff;
2720
Vivien Didelota935c052016-09-29 12:21:53 -04002721 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002722 if (err)
2723 return err;
2724
2725 /* AgeTime is 11:4 bits */
2726 val &= ~0xff0;
2727 val |= age_time << 4;
2728
Vivien Didelota935c052016-09-29 12:21:53 -04002729 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002730}
2731
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002732static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2733 unsigned int ageing_time)
2734{
Vivien Didelot04bed142016-08-31 18:06:13 -04002735 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002736 int err;
2737
2738 mutex_lock(&chip->reg_lock);
2739 err = mv88e6xxx_g1_set_age_time(chip, ageing_time);
2740 mutex_unlock(&chip->reg_lock);
2741
2742 return err;
2743}
2744
Vivien Didelot97299342016-07-18 20:45:30 -04002745static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002746{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002747 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002748 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot119477b2016-05-09 13:22:51 -04002749 u16 reg;
Vivien Didelot08a01262016-05-09 13:22:50 -04002750 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002751
Vivien Didelot119477b2016-05-09 13:22:51 -04002752 /* Enable the PHY Polling Unit if present, don't discard any packets,
2753 * and mask all interrupt sources.
2754 */
Andrew Lunndc30c352016-10-16 19:56:49 +02002755 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
2756 if (err < 0)
2757 return err;
2758
2759 reg &= ~GLOBAL_CONTROL_PPU_ENABLE;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002760 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU) ||
2761 mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE))
Vivien Didelot119477b2016-05-09 13:22:51 -04002762 reg |= GLOBAL_CONTROL_PPU_ENABLE;
2763
Vivien Didelota935c052016-09-29 12:21:53 -04002764 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
Vivien Didelot119477b2016-05-09 13:22:51 -04002765 if (err)
2766 return err;
2767
Andrew Lunn33641992016-12-03 04:35:17 +01002768 if (chip->info->ops->g1_set_cpu_port) {
2769 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2770 if (err)
2771 return err;
2772 }
2773
2774 if (chip->info->ops->g1_set_egress_port) {
2775 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2776 if (err)
2777 return err;
2778 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002779
Vivien Didelot50484ff2016-05-09 13:22:54 -04002780 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002781 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2782 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2783 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002784 if (err)
2785 return err;
2786
Vivien Didelotacddbd22016-07-18 20:45:39 -04002787 /* Clear all the VTU and STU entries */
2788 err = _mv88e6xxx_vtu_stu_flush(chip);
2789 if (err < 0)
2790 return err;
2791
Vivien Didelot08a01262016-05-09 13:22:50 -04002792 /* Set the default address aging time to 5 minutes, and
2793 * enable address learn messages to be sent to all message
2794 * ports.
2795 */
Vivien Didelota935c052016-09-29 12:21:53 -04002796 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2797 GLOBAL_ATU_CONTROL_LEARN2ALL);
Vivien Didelot08a01262016-05-09 13:22:50 -04002798 if (err)
2799 return err;
2800
Vivien Didelotacddbd22016-07-18 20:45:39 -04002801 err = mv88e6xxx_g1_set_age_time(chip, 300000);
2802 if (err)
Vivien Didelot97299342016-07-18 20:45:30 -04002803 return err;
2804
2805 /* Clear all ATU entries */
2806 err = _mv88e6xxx_atu_flush(chip, 0, true);
2807 if (err)
2808 return err;
2809
Vivien Didelot08a01262016-05-09 13:22:50 -04002810 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002811 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002812 if (err)
2813 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002814 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002815 if (err)
2816 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002817 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002818 if (err)
2819 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002820 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002821 if (err)
2822 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002823 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002824 if (err)
2825 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002826 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002827 if (err)
2828 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002829 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002830 if (err)
2831 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002832 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002833 if (err)
2834 return err;
2835
2836 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002837 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002838 if (err)
2839 return err;
2840
Andrew Lunnde2273872016-11-21 23:27:01 +01002841 /* Initialize the statistics unit */
2842 err = mv88e6xxx_stats_set_histogram(chip);
2843 if (err)
2844 return err;
2845
Vivien Didelot97299342016-07-18 20:45:30 -04002846 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002847 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2848 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002849 if (err)
2850 return err;
2851
2852 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002853 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002854 if (err)
2855 return err;
2856
2857 return 0;
2858}
2859
Vivien Didelotf81ec902016-05-09 13:22:58 -04002860static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002861{
Vivien Didelot04bed142016-08-31 18:06:13 -04002862 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002863 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002864 int i;
2865
Vivien Didelotfad09c72016-06-21 12:28:20 -04002866 chip->ds = ds;
2867 ds->slave_mii_bus = chip->mdio_bus;
Vivien Didelot552238b2016-05-09 13:22:49 -04002868
Vivien Didelotfad09c72016-06-21 12:28:20 -04002869 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002870
Vivien Didelot97299342016-07-18 20:45:30 -04002871 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002872 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002873 err = mv88e6xxx_setup_port(chip, i);
2874 if (err)
2875 goto unlock;
2876 }
2877
2878 /* Setup Switch Global 1 Registers */
2879 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002880 if (err)
2881 goto unlock;
2882
Vivien Didelot97299342016-07-18 20:45:30 -04002883 /* Setup Switch Global 2 Registers */
2884 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2885 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002886 if (err)
2887 goto unlock;
2888 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002889
Andrew Lunn6e55f692016-12-03 04:45:16 +01002890 /* Some generations have the configuration of sending reserved
2891 * management frames to the CPU in global2, others in
2892 * global1. Hence it does not fit the two setup functions
2893 * above.
2894 */
2895 if (chip->info->ops->mgmt_rsvd2cpu) {
2896 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2897 if (err)
2898 goto unlock;
2899 }
2900
Vivien Didelot6b17e862015-08-13 12:52:18 -04002901unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002902 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002903
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002904 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002905}
2906
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002907static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2908{
Vivien Didelot04bed142016-08-31 18:06:13 -04002909 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002910 int err;
2911
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002912 if (!chip->info->ops->set_switch_mac)
2913 return -EOPNOTSUPP;
2914
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002915 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002916 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002917 mutex_unlock(&chip->reg_lock);
2918
2919 return err;
2920}
2921
Vivien Didelote57e5e72016-08-15 17:19:00 -04002922static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002923{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002924 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002925 u16 val;
2926 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002927
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002928 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002929 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002930
Vivien Didelotfad09c72016-06-21 12:28:20 -04002931 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002932 err = mv88e6xxx_phy_read(chip, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002933 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002934
2935 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002936}
2937
Vivien Didelote57e5e72016-08-15 17:19:00 -04002938static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002939{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002940 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002941 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002942
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002943 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002944 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002945
Vivien Didelotfad09c72016-06-21 12:28:20 -04002946 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002947 err = mv88e6xxx_phy_write(chip, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002948 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002949
2950 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002951}
2952
Vivien Didelotfad09c72016-06-21 12:28:20 -04002953static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunnb516d452016-06-04 21:17:06 +02002954 struct device_node *np)
2955{
2956 static int index;
2957 struct mii_bus *bus;
2958 int err;
2959
Andrew Lunnb516d452016-06-04 21:17:06 +02002960 if (np)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002961 chip->mdio_np = of_get_child_by_name(np, "mdio");
Andrew Lunnb516d452016-06-04 21:17:06 +02002962
Vivien Didelotfad09c72016-06-21 12:28:20 -04002963 bus = devm_mdiobus_alloc(chip->dev);
Andrew Lunnb516d452016-06-04 21:17:06 +02002964 if (!bus)
2965 return -ENOMEM;
2966
Vivien Didelotfad09c72016-06-21 12:28:20 -04002967 bus->priv = (void *)chip;
Andrew Lunnb516d452016-06-04 21:17:06 +02002968 if (np) {
2969 bus->name = np->full_name;
2970 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2971 } else {
2972 bus->name = "mv88e6xxx SMI";
2973 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2974 }
2975
2976 bus->read = mv88e6xxx_mdio_read;
2977 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002978 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002979
Vivien Didelotfad09c72016-06-21 12:28:20 -04002980 if (chip->mdio_np)
2981 err = of_mdiobus_register(bus, chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002982 else
2983 err = mdiobus_register(bus);
2984 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002985 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunnb516d452016-06-04 21:17:06 +02002986 goto out;
2987 }
Vivien Didelotfad09c72016-06-21 12:28:20 -04002988 chip->mdio_bus = bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002989
2990 return 0;
2991
2992out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002993 if (chip->mdio_np)
2994 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002995
2996 return err;
2997}
2998
Vivien Didelotfad09c72016-06-21 12:28:20 -04002999static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02003000
3001{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003002 struct mii_bus *bus = chip->mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003003
3004 mdiobus_unregister(bus);
3005
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
Guenter Roeckc22995c2015-07-25 09:42:28 -07003010#ifdef CONFIG_NET_DSA_HWMON
3011
3012static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp)
3013{
Vivien Didelot04bed142016-08-31 18:06:13 -04003014 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04003015 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003016 int ret;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003017
3018 *temp = 0;
3019
Vivien Didelotfad09c72016-06-21 12:28:20 -04003020 mutex_lock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003021
Vivien Didelot9c938292016-08-15 17:19:02 -04003022 ret = mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x6);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003023 if (ret < 0)
3024 goto error;
3025
3026 /* Enable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04003027 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003028 if (ret < 0)
3029 goto error;
3030
Vivien Didelot9c938292016-08-15 17:19:02 -04003031 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val | (1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07003032 if (ret < 0)
3033 goto error;
3034
3035 /* Wait for temperature to stabilize */
3036 usleep_range(10000, 12000);
3037
Vivien Didelot9c938292016-08-15 17:19:02 -04003038 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
3039 if (ret < 0)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003040 goto error;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003041
3042 /* Disable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04003043 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val & ~(1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07003044 if (ret < 0)
3045 goto error;
3046
3047 *temp = ((val & 0x1f) - 5) * 5;
3048
3049error:
Vivien Didelot9c938292016-08-15 17:19:02 -04003050 mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x0);
Vivien Didelotfad09c72016-06-21 12:28:20 -04003051 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003052 return ret;
3053}
3054
3055static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp)
3056{
Vivien Didelot04bed142016-08-31 18:06:13 -04003057 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003058 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003059 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003060 int ret;
3061
3062 *temp = 0;
3063
Vivien Didelot9c938292016-08-15 17:19:02 -04003064 mutex_lock(&chip->reg_lock);
3065 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 27, &val);
3066 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003067 if (ret < 0)
3068 return ret;
3069
Vivien Didelot9c938292016-08-15 17:19:02 -04003070 *temp = (val & 0xff) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003071
3072 return 0;
3073}
3074
Vivien Didelotf81ec902016-05-09 13:22:58 -04003075static int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003076{
Vivien Didelot04bed142016-08-31 18:06:13 -04003077 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn158bc062016-04-28 21:24:06 -04003078
Vivien Didelotfad09c72016-06-21 12:28:20 -04003079 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP))
Vivien Didelot6594f612016-05-09 13:22:42 -04003080 return -EOPNOTSUPP;
3081
Vivien Didelotfad09c72016-06-21 12:28:20 -04003082 if (mv88e6xxx_6320_family(chip) || mv88e6xxx_6352_family(chip))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003083 return mv88e63xx_get_temp(ds, temp);
3084
3085 return mv88e61xx_get_temp(ds, temp);
3086}
3087
Vivien Didelotf81ec902016-05-09 13:22:58 -04003088static int mv88e6xxx_get_temp_limit(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;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003091 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003092 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003093 int ret;
3094
Vivien Didelotfad09c72016-06-21 12:28:20 -04003095 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003096 return -EOPNOTSUPP;
3097
3098 *temp = 0;
3099
Vivien Didelot9c938292016-08-15 17:19:02 -04003100 mutex_lock(&chip->reg_lock);
3101 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3102 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003103 if (ret < 0)
3104 return ret;
3105
Vivien Didelot9c938292016-08-15 17:19:02 -04003106 *temp = (((val >> 8) & 0x1f) * 5) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003107
3108 return 0;
3109}
3110
Vivien Didelotf81ec902016-05-09 13:22:58 -04003111static int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003112{
Vivien Didelot04bed142016-08-31 18:06:13 -04003113 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003114 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003115 u16 val;
3116 int err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003117
Vivien Didelotfad09c72016-06-21 12:28:20 -04003118 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003119 return -EOPNOTSUPP;
3120
Vivien Didelot9c938292016-08-15 17:19:02 -04003121 mutex_lock(&chip->reg_lock);
3122 err = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3123 if (err)
3124 goto unlock;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003125 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
Vivien Didelot9c938292016-08-15 17:19:02 -04003126 err = mv88e6xxx_phy_page_write(chip, phy, 6, 26,
3127 (val & 0xe0ff) | (temp << 8));
3128unlock:
3129 mutex_unlock(&chip->reg_lock);
3130
3131 return err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003132}
3133
Vivien Didelotf81ec902016-05-09 13:22:58 -04003134static int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003135{
Vivien Didelot04bed142016-08-31 18:06:13 -04003136 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003137 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003138 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003139 int ret;
3140
Vivien Didelotfad09c72016-06-21 12:28:20 -04003141 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003142 return -EOPNOTSUPP;
3143
3144 *alarm = false;
3145
Vivien Didelot9c938292016-08-15 17:19:02 -04003146 mutex_lock(&chip->reg_lock);
3147 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3148 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003149 if (ret < 0)
3150 return ret;
3151
Vivien Didelot9c938292016-08-15 17:19:02 -04003152 *alarm = !!(val & 0x40);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003153
3154 return 0;
3155}
3156#endif /* CONFIG_NET_DSA_HWMON */
3157
Vivien Didelot855b1932016-07-20 18:18:35 -04003158static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3159{
Vivien Didelot04bed142016-08-31 18:06:13 -04003160 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003161
3162 return chip->eeprom_len;
3163}
3164
Vivien Didelot855b1932016-07-20 18:18:35 -04003165static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3166 struct ethtool_eeprom *eeprom, u8 *data)
3167{
Vivien Didelot04bed142016-08-31 18:06:13 -04003168 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003169 int err;
3170
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003171 if (!chip->info->ops->get_eeprom)
3172 return -EOPNOTSUPP;
3173
Vivien Didelot855b1932016-07-20 18:18:35 -04003174 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003175 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003176 mutex_unlock(&chip->reg_lock);
3177
3178 if (err)
3179 return err;
3180
3181 eeprom->magic = 0xc3ec4951;
3182
3183 return 0;
3184}
3185
Vivien Didelot855b1932016-07-20 18:18:35 -04003186static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3187 struct ethtool_eeprom *eeprom, u8 *data)
3188{
Vivien Didelot04bed142016-08-31 18:06:13 -04003189 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003190 int err;
3191
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003192 if (!chip->info->ops->set_eeprom)
3193 return -EOPNOTSUPP;
3194
Vivien Didelot855b1932016-07-20 18:18:35 -04003195 if (eeprom->magic != 0xc3ec4951)
3196 return -EINVAL;
3197
3198 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003199 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003200 mutex_unlock(&chip->reg_lock);
3201
3202 return err;
3203}
3204
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003205static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003206 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003207 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003208 .phy_read = mv88e6xxx_phy_ppu_read,
3209 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003210 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003211 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003212 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003213 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003214 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3215 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3216 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003217 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003218 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003219 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003220 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3221 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003222 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003223 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3224 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003225 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003226 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003227};
3228
3229static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003230 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003231 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003232 .phy_read = mv88e6xxx_phy_ppu_read,
3233 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003234 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003235 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003236 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003237 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3238 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003239 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003240 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3241 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003242 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003243 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003244 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003245};
3246
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003247static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003248 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003249 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3250 .phy_read = mv88e6xxx_g2_smi_phy_read,
3251 .phy_write = mv88e6xxx_g2_smi_phy_write,
3252 .port_set_link = mv88e6xxx_port_set_link,
3253 .port_set_duplex = mv88e6xxx_port_set_duplex,
3254 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003255 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003256 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3257 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3258 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003259 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003260 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003261 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003262 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3263 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3264 .stats_get_strings = mv88e6095_stats_get_strings,
3265 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003266 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3267 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003268 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003269 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003270};
3271
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003272static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003273 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003274 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003275 .phy_read = mv88e6xxx_read,
3276 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003277 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003278 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003279 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003280 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3281 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
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,
Andrew Lunn33641992016-12-03 04:35:17 +01003286 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3287 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003288 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003289 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003290};
3291
3292static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003293 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003294 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003295 .phy_read = mv88e6xxx_phy_ppu_read,
3296 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003297 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003298 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003299 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003300 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003301 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3302 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3303 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003304 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003305 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003306 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003307 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003308 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3309 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003310 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003311 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3312 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003313 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003314 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003315};
3316
3317static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003318 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003319 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003320 .phy_read = mv88e6xxx_read,
3321 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003322 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003323 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003324 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003325 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003326 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3327 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3328 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003329 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003330 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003331 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003332 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003333 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3334 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003335 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003336 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3337 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003338 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003339 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003340};
3341
3342static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003343 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003344 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003345 .phy_read = mv88e6xxx_read,
3346 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003347 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003348 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003349 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003350 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003351 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3352 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003353 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003354 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3355 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003356 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003357 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003358};
3359
3360static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003361 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003362 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003363 .phy_read = mv88e6xxx_g2_smi_phy_read,
3364 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003365 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003366 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003367 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003368 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003369 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003370 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3371 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3372 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003373 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003374 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003375 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003376 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003377 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3378 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003379 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003380 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3381 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003382 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003383 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003384};
3385
3386static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003387 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003388 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3389 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003390 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003391 .phy_read = mv88e6xxx_g2_smi_phy_read,
3392 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003393 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003394 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003395 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003396 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003397 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003398 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3399 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3400 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003401 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003402 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003403 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003404 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003405 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3406 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003407 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003408 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3409 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003410 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003411 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003412};
3413
3414static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003415 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003416 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003417 .phy_read = mv88e6xxx_g2_smi_phy_read,
3418 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003419 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003420 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003421 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003422 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003423 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003424 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3425 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3426 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003427 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003428 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003429 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003430 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003431 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3432 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003433 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003434 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3435 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003436 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003437 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003438};
3439
3440static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003441 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003442 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3443 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003444 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003445 .phy_read = mv88e6xxx_g2_smi_phy_read,
3446 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003447 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003448 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003449 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003450 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003451 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003452 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3453 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3454 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003455 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003456 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003457 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003458 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003459 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3460 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003461 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003462 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3463 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003464 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003465 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003466};
3467
3468static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003469 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003470 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003471 .phy_read = mv88e6xxx_phy_ppu_read,
3472 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003473 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003474 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003475 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003476 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3477 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003478 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003479 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003480 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3481 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003482 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003483 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3484 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003485 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003486 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003487};
3488
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003489static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003490 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003491 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3492 .phy_read = mv88e6xxx_g2_smi_phy_read,
3493 .phy_write = mv88e6xxx_g2_smi_phy_write,
3494 .port_set_link = mv88e6xxx_port_set_link,
3495 .port_set_duplex = mv88e6xxx_port_set_duplex,
3496 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3497 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003498 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003499 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3500 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3501 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003502 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003503 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003504 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003505 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3506 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003507 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003508 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3509 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003510 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003511 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003512};
3513
3514static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003515 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003516 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3517 .phy_read = mv88e6xxx_g2_smi_phy_read,
3518 .phy_write = mv88e6xxx_g2_smi_phy_write,
3519 .port_set_link = mv88e6xxx_port_set_link,
3520 .port_set_duplex = mv88e6xxx_port_set_duplex,
3521 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3522 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003523 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003524 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3525 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3526 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003527 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003528 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003529 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003530 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3531 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003532 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003533 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3534 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003535 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003536 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003537};
3538
3539static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003540 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003541 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3542 .phy_read = mv88e6xxx_g2_smi_phy_read,
3543 .phy_write = mv88e6xxx_g2_smi_phy_write,
3544 .port_set_link = mv88e6xxx_port_set_link,
3545 .port_set_duplex = mv88e6xxx_port_set_duplex,
3546 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3547 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003548 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003549 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3550 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3551 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003552 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003553 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003554 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003555 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3556 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003557 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003558 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3559 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003560 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003561 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003562};
3563
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003564static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003565 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003566 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3567 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003568 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003569 .phy_read = mv88e6xxx_g2_smi_phy_read,
3570 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003571 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003572 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003573 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003574 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003575 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003576 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3577 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3578 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003579 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003580 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003581 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003582 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003583 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3584 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003585 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003586 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3587 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003588 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003589 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003590};
3591
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003592static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003593 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003594 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3595 .phy_read = mv88e6xxx_g2_smi_phy_read,
3596 .phy_write = mv88e6xxx_g2_smi_phy_write,
3597 .port_set_link = mv88e6xxx_port_set_link,
3598 .port_set_duplex = mv88e6xxx_port_set_duplex,
3599 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3600 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003601 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003602 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3603 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3604 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003605 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003606 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003607 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003608 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3609 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003610 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003611 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3612 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003613 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003614 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003615};
3616
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003617static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003618 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003619 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3620 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003621 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003622 .phy_read = mv88e6xxx_g2_smi_phy_read,
3623 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003624 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003625 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003626 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003627 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003628 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3629 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3630 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003631 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003632 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003633 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003634 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003635 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3636 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003637 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003638 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3639 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003640 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003641 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003642};
3643
3644static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003645 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003646 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3647 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003648 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003649 .phy_read = mv88e6xxx_g2_smi_phy_read,
3650 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003651 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003652 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003653 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003654 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003655 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3656 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3657 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003658 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003659 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003660 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003661 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003662 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3663 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003664 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003665 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3666 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003667 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003668};
3669
3670static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003671 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003672 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003673 .phy_read = mv88e6xxx_g2_smi_phy_read,
3674 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003675 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003676 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003677 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003678 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003679 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003680 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3681 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3682 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003683 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003684 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003685 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003686 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003687 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3688 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003689 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003690 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3691 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003692 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003693 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003694};
3695
3696static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003697 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003698 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003699 .phy_read = mv88e6xxx_g2_smi_phy_read,
3700 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003701 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003702 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003703 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003704 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003705 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003706 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3707 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3708 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003709 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003710 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003711 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003712 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003713 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3714 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003715 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003716 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3717 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003718 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003719 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003720};
3721
3722static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003723 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003724 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3725 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003726 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003727 .phy_read = mv88e6xxx_g2_smi_phy_read,
3728 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003729 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003730 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003731 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003732 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003733 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003734 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3735 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3736 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003737 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003738 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003739 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003740 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003741 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3742 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003743 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003744 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3745 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003746 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003747 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003748};
3749
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003750static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003751 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003752 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3753 .phy_read = mv88e6xxx_g2_smi_phy_read,
3754 .phy_write = mv88e6xxx_g2_smi_phy_write,
3755 .port_set_link = mv88e6xxx_port_set_link,
3756 .port_set_duplex = mv88e6xxx_port_set_duplex,
3757 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3758 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003759 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003760 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3761 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3762 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003763 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003764 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003765 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003766 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003767 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003768 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3769 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003770 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003771 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3772 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003773 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003774 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003775};
3776
3777static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003778 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003779 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3780 .phy_read = mv88e6xxx_g2_smi_phy_read,
3781 .phy_write = mv88e6xxx_g2_smi_phy_write,
3782 .port_set_link = mv88e6xxx_port_set_link,
3783 .port_set_duplex = mv88e6xxx_port_set_duplex,
3784 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3785 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003786 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003787 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3788 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3789 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003790 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003791 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003792 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003793 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003794 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003795 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3796 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003797 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003798 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3799 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003800 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003801 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003802};
3803
3804static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003805 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003806 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3807 .phy_read = mv88e6xxx_g2_smi_phy_read,
3808 .phy_write = mv88e6xxx_g2_smi_phy_write,
3809 .port_set_link = mv88e6xxx_port_set_link,
3810 .port_set_duplex = mv88e6xxx_port_set_duplex,
3811 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3812 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003813 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003814 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3815 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3816 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003817 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003818 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003819 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003820 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3821 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003822 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003823 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3824 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003825 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003826 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003827};
3828
Andrew Lunn56995cb2016-12-03 04:35:19 +01003829static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3830 const struct mv88e6xxx_ops *ops)
3831{
3832 if (!ops->port_set_frame_mode) {
3833 dev_err(chip->dev, "Missing port_set_frame_mode");
3834 return -EINVAL;
3835 }
3836
3837 if (!ops->port_set_egress_unknowns) {
3838 dev_err(chip->dev, "Missing port_set_egress_mode");
3839 return -EINVAL;
3840 }
3841
3842 return 0;
3843}
3844
Vivien Didelotf81ec902016-05-09 13:22:58 -04003845static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3846 [MV88E6085] = {
3847 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3848 .family = MV88E6XXX_FAMILY_6097,
3849 .name = "Marvell 88E6085",
3850 .num_databases = 4096,
3851 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003852 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003853 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003854 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003855 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003856 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003857 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003858 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003859 },
3860
3861 [MV88E6095] = {
3862 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3863 .family = MV88E6XXX_FAMILY_6095,
3864 .name = "Marvell 88E6095/88E6095F",
3865 .num_databases = 256,
3866 .num_ports = 11,
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 = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003871 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003872 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003873 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003874 },
3875
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003876 [MV88E6097] = {
3877 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3878 .family = MV88E6XXX_FAMILY_6097,
3879 .name = "Marvell 88E6097/88E6097F",
3880 .num_databases = 4096,
3881 .num_ports = 11,
3882 .port_base_addr = 0x10,
3883 .global1_addr = 0x1b,
3884 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003885 .g1_irqs = 8,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003886 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003887 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3888 .ops = &mv88e6097_ops,
3889 },
3890
Vivien Didelotf81ec902016-05-09 13:22:58 -04003891 [MV88E6123] = {
3892 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3893 .family = MV88E6XXX_FAMILY_6165,
3894 .name = "Marvell 88E6123",
3895 .num_databases = 4096,
3896 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003897 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003898 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003899 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003900 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003901 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003902 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003903 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003904 },
3905
3906 [MV88E6131] = {
3907 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3908 .family = MV88E6XXX_FAMILY_6185,
3909 .name = "Marvell 88E6131",
3910 .num_databases = 256,
3911 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003912 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003913 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003914 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003915 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003916 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003917 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003918 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003919 },
3920
3921 [MV88E6161] = {
3922 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3923 .family = MV88E6XXX_FAMILY_6165,
3924 .name = "Marvell 88E6161",
3925 .num_databases = 4096,
3926 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003927 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003928 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003929 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003930 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003931 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003932 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003933 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003934 },
3935
3936 [MV88E6165] = {
3937 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3938 .family = MV88E6XXX_FAMILY_6165,
3939 .name = "Marvell 88E6165",
3940 .num_databases = 4096,
3941 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003942 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003943 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003944 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003945 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003946 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003947 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003948 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003949 },
3950
3951 [MV88E6171] = {
3952 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3953 .family = MV88E6XXX_FAMILY_6351,
3954 .name = "Marvell 88E6171",
3955 .num_databases = 4096,
3956 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003957 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003958 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003959 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003960 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003961 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003962 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003963 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003964 },
3965
3966 [MV88E6172] = {
3967 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3968 .family = MV88E6XXX_FAMILY_6352,
3969 .name = "Marvell 88E6172",
3970 .num_databases = 4096,
3971 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003972 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003973 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003974 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003975 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003976 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003977 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003978 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003979 },
3980
3981 [MV88E6175] = {
3982 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3983 .family = MV88E6XXX_FAMILY_6351,
3984 .name = "Marvell 88E6175",
3985 .num_databases = 4096,
3986 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003987 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003988 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003989 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003990 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003991 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003992 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003993 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003994 },
3995
3996 [MV88E6176] = {
3997 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3998 .family = MV88E6XXX_FAMILY_6352,
3999 .name = "Marvell 88E6176",
4000 .num_databases = 4096,
4001 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004002 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004003 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004004 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004005 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004006 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004007 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004008 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004009 },
4010
4011 [MV88E6185] = {
4012 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
4013 .family = MV88E6XXX_FAMILY_6185,
4014 .name = "Marvell 88E6185",
4015 .num_databases = 256,
4016 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004017 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004018 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004019 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004020 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004021 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004022 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004023 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004024 },
4025
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004026 [MV88E6190] = {
4027 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
4028 .family = MV88E6XXX_FAMILY_6390,
4029 .name = "Marvell 88E6190",
4030 .num_databases = 4096,
4031 .num_ports = 11, /* 10 + Z80 */
4032 .port_base_addr = 0x0,
4033 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004034 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004035 .age_time_coeff = 15000,
4036 .g1_irqs = 9,
4037 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4038 .ops = &mv88e6190_ops,
4039 },
4040
4041 [MV88E6190X] = {
4042 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
4043 .family = MV88E6XXX_FAMILY_6390,
4044 .name = "Marvell 88E6190X",
4045 .num_databases = 4096,
4046 .num_ports = 11, /* 10 + Z80 */
4047 .port_base_addr = 0x0,
4048 .global1_addr = 0x1b,
4049 .age_time_coeff = 15000,
4050 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004051 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004052 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4053 .ops = &mv88e6190x_ops,
4054 },
4055
4056 [MV88E6191] = {
4057 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
4058 .family = MV88E6XXX_FAMILY_6390,
4059 .name = "Marvell 88E6191",
4060 .num_databases = 4096,
4061 .num_ports = 11, /* 10 + Z80 */
4062 .port_base_addr = 0x0,
4063 .global1_addr = 0x1b,
4064 .age_time_coeff = 15000,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004065 .g1_irqs = 9,
4066 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004067 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4068 .ops = &mv88e6391_ops,
4069 },
4070
Vivien Didelotf81ec902016-05-09 13:22:58 -04004071 [MV88E6240] = {
4072 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
4073 .family = MV88E6XXX_FAMILY_6352,
4074 .name = "Marvell 88E6240",
4075 .num_databases = 4096,
4076 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004077 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004078 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004079 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004080 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004081 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004082 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004083 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004084 },
4085
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004086 [MV88E6290] = {
4087 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
4088 .family = MV88E6XXX_FAMILY_6390,
4089 .name = "Marvell 88E6290",
4090 .num_databases = 4096,
4091 .num_ports = 11, /* 10 + Z80 */
4092 .port_base_addr = 0x0,
4093 .global1_addr = 0x1b,
4094 .age_time_coeff = 15000,
4095 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004096 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004097 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4098 .ops = &mv88e6290_ops,
4099 },
4100
Vivien Didelotf81ec902016-05-09 13:22:58 -04004101 [MV88E6320] = {
4102 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
4103 .family = MV88E6XXX_FAMILY_6320,
4104 .name = "Marvell 88E6320",
4105 .num_databases = 4096,
4106 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004107 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004108 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004109 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004110 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004111 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004112 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004113 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004114 },
4115
4116 [MV88E6321] = {
4117 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
4118 .family = MV88E6XXX_FAMILY_6320,
4119 .name = "Marvell 88E6321",
4120 .num_databases = 4096,
4121 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004122 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004123 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004124 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004125 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004126 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004127 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004128 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004129 },
4130
4131 [MV88E6350] = {
4132 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
4133 .family = MV88E6XXX_FAMILY_6351,
4134 .name = "Marvell 88E6350",
4135 .num_databases = 4096,
4136 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004137 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004138 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004139 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004140 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004141 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004142 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004143 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004144 },
4145
4146 [MV88E6351] = {
4147 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4148 .family = MV88E6XXX_FAMILY_6351,
4149 .name = "Marvell 88E6351",
4150 .num_databases = 4096,
4151 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004152 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004153 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004154 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004155 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004156 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004157 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004158 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004159 },
4160
4161 [MV88E6352] = {
4162 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4163 .family = MV88E6XXX_FAMILY_6352,
4164 .name = "Marvell 88E6352",
4165 .num_databases = 4096,
4166 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004167 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004168 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004169 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004170 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004171 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004172 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004173 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004174 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004175 [MV88E6390] = {
4176 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4177 .family = MV88E6XXX_FAMILY_6390,
4178 .name = "Marvell 88E6390",
4179 .num_databases = 4096,
4180 .num_ports = 11, /* 10 + Z80 */
4181 .port_base_addr = 0x0,
4182 .global1_addr = 0x1b,
4183 .age_time_coeff = 15000,
4184 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004185 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004186 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4187 .ops = &mv88e6390_ops,
4188 },
4189 [MV88E6390X] = {
4190 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4191 .family = MV88E6XXX_FAMILY_6390,
4192 .name = "Marvell 88E6390X",
4193 .num_databases = 4096,
4194 .num_ports = 11, /* 10 + Z80 */
4195 .port_base_addr = 0x0,
4196 .global1_addr = 0x1b,
4197 .age_time_coeff = 15000,
4198 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004199 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004200 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4201 .ops = &mv88e6390x_ops,
4202 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004203};
4204
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004205static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004206{
Vivien Didelota439c062016-04-17 13:23:58 -04004207 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004208
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004209 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4210 if (mv88e6xxx_table[i].prod_num == prod_num)
4211 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004212
Vivien Didelotb9b37712015-10-30 19:39:48 -04004213 return NULL;
4214}
4215
Vivien Didelotfad09c72016-06-21 12:28:20 -04004216static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004217{
4218 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004219 unsigned int prod_num, rev;
4220 u16 id;
4221 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004222
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004223 mutex_lock(&chip->reg_lock);
4224 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4225 mutex_unlock(&chip->reg_lock);
4226 if (err)
4227 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004228
4229 prod_num = (id & 0xfff0) >> 4;
4230 rev = id & 0x000f;
4231
4232 info = mv88e6xxx_lookup_info(prod_num);
4233 if (!info)
4234 return -ENODEV;
4235
Vivien Didelotcaac8542016-06-20 13:14:09 -04004236 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004237 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004238
Vivien Didelotca070c12016-09-02 14:45:34 -04004239 err = mv88e6xxx_g2_require(chip);
4240 if (err)
4241 return err;
4242
Vivien Didelotfad09c72016-06-21 12:28:20 -04004243 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4244 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004245
4246 return 0;
4247}
4248
Vivien Didelotfad09c72016-06-21 12:28:20 -04004249static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004250{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004251 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004252
Vivien Didelotfad09c72016-06-21 12:28:20 -04004253 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4254 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004255 return NULL;
4256
Vivien Didelotfad09c72016-06-21 12:28:20 -04004257 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004258
Vivien Didelotfad09c72016-06-21 12:28:20 -04004259 mutex_init(&chip->reg_lock);
Vivien Didelot469d7292016-06-20 13:14:06 -04004260
Vivien Didelotfad09c72016-06-21 12:28:20 -04004261 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004262}
4263
Vivien Didelote57e5e72016-08-15 17:19:00 -04004264static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4265{
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004266 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
Vivien Didelote57e5e72016-08-15 17:19:00 -04004267 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004268}
4269
Andrew Lunn930188c2016-08-22 16:01:03 +02004270static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4271{
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004272 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
Andrew Lunn930188c2016-08-22 16:01:03 +02004273 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004274}
4275
Vivien Didelotfad09c72016-06-21 12:28:20 -04004276static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004277 struct mii_bus *bus, int sw_addr)
4278{
4279 /* ADDR[0] pin is unavailable externally and considered zero */
4280 if (sw_addr & 0x1)
4281 return -EINVAL;
4282
Vivien Didelot914b32f2016-06-20 13:14:11 -04004283 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004284 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004285 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004286 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004287 else
4288 return -EINVAL;
4289
Vivien Didelotfad09c72016-06-21 12:28:20 -04004290 chip->bus = bus;
4291 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004292
4293 return 0;
4294}
4295
Andrew Lunn7b314362016-08-22 16:01:01 +02004296static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4297{
Vivien Didelot04bed142016-08-31 18:06:13 -04004298 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004299
Andrew Lunn443d5a12016-12-03 04:35:18 +01004300 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004301}
4302
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004303static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4304 struct device *host_dev, int sw_addr,
4305 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004306{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004307 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004308 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004309 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004310
Vivien Didelota439c062016-04-17 13:23:58 -04004311 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004312 if (!bus)
4313 return NULL;
4314
Vivien Didelotfad09c72016-06-21 12:28:20 -04004315 chip = mv88e6xxx_alloc_chip(dsa_dev);
4316 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004317 return NULL;
4318
Vivien Didelotcaac8542016-06-20 13:14:09 -04004319 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004320 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004321
Vivien Didelotfad09c72016-06-21 12:28:20 -04004322 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004323 if (err)
4324 goto free;
4325
Vivien Didelotfad09c72016-06-21 12:28:20 -04004326 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004327 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004328 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004329
Andrew Lunndc30c352016-10-16 19:56:49 +02004330 mutex_lock(&chip->reg_lock);
4331 err = mv88e6xxx_switch_reset(chip);
4332 mutex_unlock(&chip->reg_lock);
4333 if (err)
4334 goto free;
4335
Vivien Didelote57e5e72016-08-15 17:19:00 -04004336 mv88e6xxx_phy_init(chip);
4337
Vivien Didelotfad09c72016-06-21 12:28:20 -04004338 err = mv88e6xxx_mdio_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004339 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004340 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004341
Vivien Didelotfad09c72016-06-21 12:28:20 -04004342 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004343
Vivien Didelotfad09c72016-06-21 12:28:20 -04004344 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004345free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004346 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004347
4348 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004349}
4350
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004351static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4352 const struct switchdev_obj_port_mdb *mdb,
4353 struct switchdev_trans *trans)
4354{
4355 /* We don't need any dynamic resource from the kernel (yet),
4356 * so skip the prepare phase.
4357 */
4358
4359 return 0;
4360}
4361
4362static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4363 const struct switchdev_obj_port_mdb *mdb,
4364 struct switchdev_trans *trans)
4365{
Vivien Didelot04bed142016-08-31 18:06:13 -04004366 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004367
4368 mutex_lock(&chip->reg_lock);
4369 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4370 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4371 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4372 mutex_unlock(&chip->reg_lock);
4373}
4374
4375static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4376 const struct switchdev_obj_port_mdb *mdb)
4377{
Vivien Didelot04bed142016-08-31 18:06:13 -04004378 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004379 int err;
4380
4381 mutex_lock(&chip->reg_lock);
4382 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4383 GLOBAL_ATU_DATA_STATE_UNUSED);
4384 mutex_unlock(&chip->reg_lock);
4385
4386 return err;
4387}
4388
4389static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4390 struct switchdev_obj_port_mdb *mdb,
4391 int (*cb)(struct switchdev_obj *obj))
4392{
Vivien Didelot04bed142016-08-31 18:06:13 -04004393 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004394 int err;
4395
4396 mutex_lock(&chip->reg_lock);
4397 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4398 mutex_unlock(&chip->reg_lock);
4399
4400 return err;
4401}
4402
Vivien Didelot9d490b42016-08-23 12:38:56 -04004403static struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004404 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004405 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004406 .setup = mv88e6xxx_setup,
4407 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004408 .adjust_link = mv88e6xxx_adjust_link,
4409 .get_strings = mv88e6xxx_get_strings,
4410 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4411 .get_sset_count = mv88e6xxx_get_sset_count,
4412 .set_eee = mv88e6xxx_set_eee,
4413 .get_eee = mv88e6xxx_get_eee,
4414#ifdef CONFIG_NET_DSA_HWMON
4415 .get_temp = mv88e6xxx_get_temp,
4416 .get_temp_limit = mv88e6xxx_get_temp_limit,
4417 .set_temp_limit = mv88e6xxx_set_temp_limit,
4418 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
4419#endif
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004420 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004421 .get_eeprom = mv88e6xxx_get_eeprom,
4422 .set_eeprom = mv88e6xxx_set_eeprom,
4423 .get_regs_len = mv88e6xxx_get_regs_len,
4424 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004425 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004426 .port_bridge_join = mv88e6xxx_port_bridge_join,
4427 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4428 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004429 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004430 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4431 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4432 .port_vlan_add = mv88e6xxx_port_vlan_add,
4433 .port_vlan_del = mv88e6xxx_port_vlan_del,
4434 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4435 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4436 .port_fdb_add = mv88e6xxx_port_fdb_add,
4437 .port_fdb_del = mv88e6xxx_port_fdb_del,
4438 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004439 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4440 .port_mdb_add = mv88e6xxx_port_mdb_add,
4441 .port_mdb_del = mv88e6xxx_port_mdb_del,
4442 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004443};
4444
Vivien Didelotfad09c72016-06-21 12:28:20 -04004445static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004446 struct device_node *np)
4447{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004448 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004449 struct dsa_switch *ds;
4450
4451 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
4452 if (!ds)
4453 return -ENOMEM;
4454
4455 ds->dev = dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004456 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004457 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004458
4459 dev_set_drvdata(dev, ds);
4460
4461 return dsa_register_switch(ds, np);
4462}
4463
Vivien Didelotfad09c72016-06-21 12:28:20 -04004464static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004465{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004466 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004467}
4468
Vivien Didelot57d32312016-06-20 13:13:58 -04004469static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004470{
4471 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004472 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004473 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004474 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004475 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004476 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004477
Vivien Didelotcaac8542016-06-20 13:14:09 -04004478 compat_info = of_device_get_match_data(dev);
4479 if (!compat_info)
4480 return -EINVAL;
4481
Vivien Didelotfad09c72016-06-21 12:28:20 -04004482 chip = mv88e6xxx_alloc_chip(dev);
4483 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004484 return -ENOMEM;
4485
Vivien Didelotfad09c72016-06-21 12:28:20 -04004486 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004487
Andrew Lunn56995cb2016-12-03 04:35:19 +01004488 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4489 if (err)
4490 return err;
4491
Vivien Didelotfad09c72016-06-21 12:28:20 -04004492 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004493 if (err)
4494 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004495
Andrew Lunnb4308f02016-11-21 23:26:55 +01004496 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4497 if (IS_ERR(chip->reset))
4498 return PTR_ERR(chip->reset);
4499
Vivien Didelotfad09c72016-06-21 12:28:20 -04004500 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004501 if (err)
4502 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004503
Vivien Didelote57e5e72016-08-15 17:19:00 -04004504 mv88e6xxx_phy_init(chip);
4505
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004506 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004507 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004508 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004509
Andrew Lunndc30c352016-10-16 19:56:49 +02004510 mutex_lock(&chip->reg_lock);
4511 err = mv88e6xxx_switch_reset(chip);
4512 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004513 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004514 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004515
Andrew Lunndc30c352016-10-16 19:56:49 +02004516 chip->irq = of_irq_get(np, 0);
4517 if (chip->irq == -EPROBE_DEFER) {
4518 err = chip->irq;
4519 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004520 }
4521
Andrew Lunndc30c352016-10-16 19:56:49 +02004522 if (chip->irq > 0) {
4523 /* Has to be performed before the MDIO bus is created,
4524 * because the PHYs will link there interrupts to these
4525 * interrupt controllers
4526 */
4527 mutex_lock(&chip->reg_lock);
4528 err = mv88e6xxx_g1_irq_setup(chip);
4529 mutex_unlock(&chip->reg_lock);
4530
4531 if (err)
4532 goto out;
4533
4534 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4535 err = mv88e6xxx_g2_irq_setup(chip);
4536 if (err)
4537 goto out_g1_irq;
4538 }
4539 }
4540
4541 err = mv88e6xxx_mdio_register(chip, np);
4542 if (err)
4543 goto out_g2_irq;
4544
4545 err = mv88e6xxx_register_switch(chip, np);
4546 if (err)
4547 goto out_mdio;
4548
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004549 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004550
4551out_mdio:
4552 mv88e6xxx_mdio_unregister(chip);
4553out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004554 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004555 mv88e6xxx_g2_irq_free(chip);
4556out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004557 if (chip->irq > 0) {
4558 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004559 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004560 mutex_unlock(&chip->reg_lock);
4561 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004562out:
4563 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004564}
4565
4566static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4567{
4568 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004569 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004570
Andrew Lunn930188c2016-08-22 16:01:03 +02004571 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004572 mv88e6xxx_unregister_switch(chip);
4573 mv88e6xxx_mdio_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004574
Andrew Lunn467126442016-11-20 20:14:15 +01004575 if (chip->irq > 0) {
4576 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4577 mv88e6xxx_g2_irq_free(chip);
4578 mv88e6xxx_g1_irq_free(chip);
4579 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004580}
4581
4582static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004583 {
4584 .compatible = "marvell,mv88e6085",
4585 .data = &mv88e6xxx_table[MV88E6085],
4586 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004587 {
4588 .compatible = "marvell,mv88e6190",
4589 .data = &mv88e6xxx_table[MV88E6190],
4590 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004591 { /* sentinel */ },
4592};
4593
4594MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4595
4596static struct mdio_driver mv88e6xxx_driver = {
4597 .probe = mv88e6xxx_probe,
4598 .remove = mv88e6xxx_remove,
4599 .mdiodrv.driver = {
4600 .name = "mv88e6085",
4601 .of_match_table = mv88e6xxx_of_match,
4602 },
4603};
4604
Ben Hutchings98e67302011-11-25 14:36:19 +00004605static int __init mv88e6xxx_init(void)
4606{
Vivien Didelot9d490b42016-08-23 12:38:56 -04004607 register_switch_driver(&mv88e6xxx_switch_ops);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004608 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004609}
4610module_init(mv88e6xxx_init);
4611
4612static void __exit mv88e6xxx_cleanup(void)
4613{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004614 mdio_driver_unregister(&mv88e6xxx_driver);
Vivien Didelot9d490b42016-08-23 12:38:56 -04004615 unregister_switch_driver(&mv88e6xxx_switch_ops);
Ben Hutchings98e67302011-11-25 14:36:19 +00004616}
4617module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004618
4619MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4620MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4621MODULE_LICENSE("GPL");