blob: 4da379f28d5d1b798ca09ddb0f71ca42ad18ccd0 [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 Didelota199d8b2016-12-05 17:30:28 -0500530 if (!chip->info->ops->ppu_disable)
531 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000532
Vivien Didelota199d8b2016-12-05 17:30:28 -0500533 return chip->info->ops->ppu_disable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000534}
535
Vivien Didelotfad09c72016-06-21 12:28:20 -0400536static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000537{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500538 if (!chip->info->ops->ppu_enable)
539 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000540
Vivien Didelota199d8b2016-12-05 17:30:28 -0500541 return chip->info->ops->ppu_enable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000542}
543
544static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
545{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400546 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000547
Vivien Didelotfad09c72016-06-21 12:28:20 -0400548 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200549
Vivien Didelotfad09c72016-06-21 12:28:20 -0400550 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200551
Vivien Didelotfad09c72016-06-21 12:28:20 -0400552 if (mutex_trylock(&chip->ppu_mutex)) {
553 if (mv88e6xxx_ppu_enable(chip) == 0)
554 chip->ppu_disabled = 0;
555 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000556 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200557
Vivien Didelotfad09c72016-06-21 12:28:20 -0400558 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000559}
560
561static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
562{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400563 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000564
Vivien Didelotfad09c72016-06-21 12:28:20 -0400565 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000566}
567
Vivien Didelotfad09c72016-06-21 12:28:20 -0400568static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000569{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000570 int ret;
571
Vivien Didelotfad09c72016-06-21 12:28:20 -0400572 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000573
Barry Grussling3675c8d2013-01-08 16:05:53 +0000574 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000575 * we can access the PHY registers. If it was already
576 * disabled, cancel the timer that is going to re-enable
577 * it.
578 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400579 if (!chip->ppu_disabled) {
580 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000581 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400582 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000583 return ret;
584 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400585 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000586 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400587 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000588 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000589 }
590
591 return ret;
592}
593
Vivien Didelotfad09c72016-06-21 12:28:20 -0400594static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000595{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000596 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400597 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
598 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000599}
600
Vivien Didelotfad09c72016-06-21 12:28:20 -0400601static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000602{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400603 mutex_init(&chip->ppu_mutex);
604 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000605 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
606 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000607}
608
Andrew Lunn930188c2016-08-22 16:01:03 +0200609static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
610{
611 del_timer_sync(&chip->ppu_timer);
612}
613
Vivien Didelote57e5e72016-08-15 17:19:00 -0400614static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip, int addr,
615 int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000616{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400617 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000618
Vivien Didelote57e5e72016-08-15 17:19:00 -0400619 err = mv88e6xxx_ppu_access_get(chip);
620 if (!err) {
621 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400622 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000623 }
624
Vivien Didelote57e5e72016-08-15 17:19:00 -0400625 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000626}
627
Vivien Didelote57e5e72016-08-15 17:19:00 -0400628static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip, int addr,
629 int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000630{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400631 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000632
Vivien Didelote57e5e72016-08-15 17:19:00 -0400633 err = mv88e6xxx_ppu_access_get(chip);
634 if (!err) {
635 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400636 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000637 }
638
Vivien Didelote57e5e72016-08-15 17:19:00 -0400639 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000640}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000641
Vivien Didelotfad09c72016-06-21 12:28:20 -0400642static bool mv88e6xxx_6095_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200643{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400644 return chip->info->family == MV88E6XXX_FAMILY_6095;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200645}
646
Vivien Didelotfad09c72016-06-21 12:28:20 -0400647static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200648{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400649 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200650}
651
Vivien Didelotfad09c72016-06-21 12:28:20 -0400652static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200653{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400654 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200655}
656
Vivien Didelotfad09c72016-06-21 12:28:20 -0400657static bool mv88e6xxx_6185_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200658{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400659 return chip->info->family == MV88E6XXX_FAMILY_6185;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200660}
661
Vivien Didelotfad09c72016-06-21 12:28:20 -0400662static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700663{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400664 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700665}
666
Vivien Didelotfad09c72016-06-21 12:28:20 -0400667static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200668{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400669 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200670}
671
Vivien Didelotfad09c72016-06-21 12:28:20 -0400672static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200673{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400674 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200675}
676
Vivien Didelotd78343d2016-11-04 03:23:36 +0100677static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
678 int link, int speed, int duplex,
679 phy_interface_t mode)
680{
681 int err;
682
683 if (!chip->info->ops->port_set_link)
684 return 0;
685
686 /* Port's MAC control must not be changed unless the link is down */
687 err = chip->info->ops->port_set_link(chip, port, 0);
688 if (err)
689 return err;
690
691 if (chip->info->ops->port_set_speed) {
692 err = chip->info->ops->port_set_speed(chip, port, speed);
693 if (err && err != -EOPNOTSUPP)
694 goto restore_link;
695 }
696
697 if (chip->info->ops->port_set_duplex) {
698 err = chip->info->ops->port_set_duplex(chip, port, duplex);
699 if (err && err != -EOPNOTSUPP)
700 goto restore_link;
701 }
702
703 if (chip->info->ops->port_set_rgmii_delay) {
704 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
705 if (err && err != -EOPNOTSUPP)
706 goto restore_link;
707 }
708
709 err = 0;
710restore_link:
711 if (chip->info->ops->port_set_link(chip, port, link))
712 netdev_err(chip->ds->ports[port].netdev,
713 "failed to restore MAC's link\n");
714
715 return err;
716}
717
Andrew Lunndea87022015-08-31 15:56:47 +0200718/* We expect the switch to perform auto negotiation if there is a real
719 * phy. However, in the case of a fixed link phy, we force the port
720 * settings from the fixed link settings.
721 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400722static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
723 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200724{
Vivien Didelot04bed142016-08-31 18:06:13 -0400725 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200726 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200727
728 if (!phy_is_pseudo_fixed_link(phydev))
729 return;
730
Vivien Didelotfad09c72016-06-21 12:28:20 -0400731 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100732 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
733 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400734 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100735
736 if (err && err != -EOPNOTSUPP)
737 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200738}
739
Andrew Lunna605a0f2016-11-21 23:26:58 +0100740static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000741{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100742 if (!chip->info->ops->stats_snapshot)
743 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000744
Andrew Lunna605a0f2016-11-21 23:26:58 +0100745 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000746}
747
Andrew Lunne413e7e2015-04-02 04:06:38 +0200748static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100749 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
750 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
751 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
752 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
753 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
754 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
755 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
756 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
757 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
758 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
759 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
760 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
761 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
762 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
763 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
764 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
765 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
766 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
767 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
768 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
769 { "single", 4, 0x14, STATS_TYPE_BANK0, },
770 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
771 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
772 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
773 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
774 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
775 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
776 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
777 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
778 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
779 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
780 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
781 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
782 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
783 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
784 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
785 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
786 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
787 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
788 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
789 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
790 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
791 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
792 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
793 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
794 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
795 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
796 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
797 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
798 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
799 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
800 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
801 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
802 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
803 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
804 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
805 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
806 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
807 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200808};
809
Vivien Didelotfad09c72016-06-21 12:28:20 -0400810static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100811 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100812 int port, u16 bank1_select,
813 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200814{
Andrew Lunn80c46272015-06-20 18:42:30 +0200815 u32 low;
816 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100817 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200818 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200819 u64 value;
820
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100821 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100822 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200823 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
824 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200825 return UINT64_MAX;
826
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200827 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200828 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200829 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
830 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200831 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200832 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200833 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100834 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100835 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100836 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100837 /* fall through */
838 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100839 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100840 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200841 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100842 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200843 }
844 value = (((u64)high) << 16) | low;
845 return value;
846}
847
Andrew Lunndfafe442016-11-21 23:27:02 +0100848static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
849 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100850{
851 struct mv88e6xxx_hw_stat *stat;
852 int i, j;
853
854 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
855 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100856 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100857 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
858 ETH_GSTRING_LEN);
859 j++;
860 }
861 }
862}
863
Andrew Lunndfafe442016-11-21 23:27:02 +0100864static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
865 uint8_t *data)
866{
867 mv88e6xxx_stats_get_strings(chip, data,
868 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
869}
870
871static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
872 uint8_t *data)
873{
874 mv88e6xxx_stats_get_strings(chip, data,
875 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
876}
877
878static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
879 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100880{
Vivien Didelot04bed142016-08-31 18:06:13 -0400881 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100882
883 if (chip->info->ops->stats_get_strings)
884 chip->info->ops->stats_get_strings(chip, data);
885}
886
887static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
888 int types)
889{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100890 struct mv88e6xxx_hw_stat *stat;
891 int i, j;
892
893 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
894 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100895 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100896 j++;
897 }
898 return j;
899}
900
Andrew Lunndfafe442016-11-21 23:27:02 +0100901static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
902{
903 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
904 STATS_TYPE_PORT);
905}
906
907static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
908{
909 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
910 STATS_TYPE_BANK1);
911}
912
913static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
914{
915 struct mv88e6xxx_chip *chip = ds->priv;
916
917 if (chip->info->ops->stats_get_sset_count)
918 return chip->info->ops->stats_get_sset_count(chip);
919
920 return 0;
921}
922
Andrew Lunn052f9472016-11-21 23:27:03 +0100923static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100924 uint64_t *data, int types,
925 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100926{
927 struct mv88e6xxx_hw_stat *stat;
928 int i, j;
929
930 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
931 stat = &mv88e6xxx_hw_stats[i];
932 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100933 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
934 bank1_select,
935 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100936 j++;
937 }
938 }
939}
940
941static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
942 uint64_t *data)
943{
944 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100945 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
946 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100947}
948
949static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
950 uint64_t *data)
951{
952 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100953 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
954 GLOBAL_STATS_OP_BANK_1_BIT_9,
955 GLOBAL_STATS_OP_HIST_RX_TX);
956}
957
958static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
959 uint64_t *data)
960{
961 return mv88e6xxx_stats_get_stats(chip, port, data,
962 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
963 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100964}
965
966static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
967 uint64_t *data)
968{
969 if (chip->info->ops->stats_get_stats)
970 chip->info->ops->stats_get_stats(chip, port, data);
971}
972
Vivien Didelotf81ec902016-05-09 13:22:58 -0400973static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
974 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000975{
Vivien Didelot04bed142016-08-31 18:06:13 -0400976 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000977 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000978
Vivien Didelotfad09c72016-06-21 12:28:20 -0400979 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000980
Andrew Lunna605a0f2016-11-21 23:26:58 +0100981 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000982 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400983 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000984 return;
985 }
Andrew Lunn052f9472016-11-21 23:27:03 +0100986
987 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000988
Vivien Didelotfad09c72016-06-21 12:28:20 -0400989 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000990}
Ben Hutchings98e67302011-11-25 14:36:19 +0000991
Andrew Lunnde2273872016-11-21 23:27:01 +0100992static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
993{
994 if (chip->info->ops->stats_set_histogram)
995 return chip->info->ops->stats_set_histogram(chip);
996
997 return 0;
998}
999
Vivien Didelotf81ec902016-05-09 13:22:58 -04001000static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001001{
1002 return 32 * sizeof(u16);
1003}
1004
Vivien Didelotf81ec902016-05-09 13:22:58 -04001005static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1006 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001007{
Vivien Didelot04bed142016-08-31 18:06:13 -04001008 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001009 int err;
1010 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001011 u16 *p = _p;
1012 int i;
1013
1014 regs->version = 0;
1015
1016 memset(p, 0xff, 32 * sizeof(u16));
1017
Vivien Didelotfad09c72016-06-21 12:28:20 -04001018 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001019
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001020 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001021
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001022 err = mv88e6xxx_port_read(chip, port, i, &reg);
1023 if (!err)
1024 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001025 }
Vivien Didelot23062512016-05-09 13:22:45 -04001026
Vivien Didelotfad09c72016-06-21 12:28:20 -04001027 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001028}
1029
Vivien Didelotfad09c72016-06-21 12:28:20 -04001030static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001031{
Vivien Didelota935c052016-09-29 12:21:53 -04001032 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001033}
1034
Vivien Didelotf81ec902016-05-09 13:22:58 -04001035static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1036 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001037{
Vivien Didelot04bed142016-08-31 18:06:13 -04001038 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001039 u16 reg;
1040 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001041
Vivien Didelotfad09c72016-06-21 12:28:20 -04001042 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001043 return -EOPNOTSUPP;
1044
Vivien Didelotfad09c72016-06-21 12:28:20 -04001045 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001046
Vivien Didelot9c938292016-08-15 17:19:02 -04001047 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1048 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001049 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001050
1051 e->eee_enabled = !!(reg & 0x0200);
1052 e->tx_lpi_enabled = !!(reg & 0x0100);
1053
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001054 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001055 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001056 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001057
Andrew Lunncca8b132015-04-02 04:06:39 +02001058 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001059out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001060 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001061
1062 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001063}
1064
Vivien Didelotf81ec902016-05-09 13:22:58 -04001065static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1066 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001067{
Vivien Didelot04bed142016-08-31 18:06:13 -04001068 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001069 u16 reg;
1070 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001071
Vivien Didelotfad09c72016-06-21 12:28:20 -04001072 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001073 return -EOPNOTSUPP;
1074
Vivien Didelotfad09c72016-06-21 12:28:20 -04001075 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001076
Vivien Didelot9c938292016-08-15 17:19:02 -04001077 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1078 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001079 goto out;
1080
Vivien Didelot9c938292016-08-15 17:19:02 -04001081 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001082 if (e->eee_enabled)
1083 reg |= 0x0200;
1084 if (e->tx_lpi_enabled)
1085 reg |= 0x0100;
1086
Vivien Didelot9c938292016-08-15 17:19:02 -04001087 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001088out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001089 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001090
Vivien Didelot9c938292016-08-15 17:19:02 -04001091 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001092}
1093
Vivien Didelotfad09c72016-06-21 12:28:20 -04001094static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001095{
Vivien Didelota935c052016-09-29 12:21:53 -04001096 u16 val;
1097 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001098
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001099 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001100 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1101 if (err)
1102 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001103 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001104 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001105 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1106 if (err)
1107 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001108
Vivien Didelota935c052016-09-29 12:21:53 -04001109 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1110 (val & 0xfff) | ((fid << 8) & 0xf000));
1111 if (err)
1112 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001113
1114 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1115 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001116 }
1117
Vivien Didelota935c052016-09-29 12:21:53 -04001118 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1119 if (err)
1120 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001121
Vivien Didelotfad09c72016-06-21 12:28:20 -04001122 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001123}
1124
Vivien Didelotfad09c72016-06-21 12:28:20 -04001125static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001126 struct mv88e6xxx_atu_entry *entry)
1127{
1128 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1129
1130 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1131 unsigned int mask, shift;
1132
1133 if (entry->trunk) {
1134 data |= GLOBAL_ATU_DATA_TRUNK;
1135 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1136 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1137 } else {
1138 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1139 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1140 }
1141
1142 data |= (entry->portv_trunkid << shift) & mask;
1143 }
1144
Vivien Didelota935c052016-09-29 12:21:53 -04001145 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001146}
1147
Vivien Didelotfad09c72016-06-21 12:28:20 -04001148static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001149 struct mv88e6xxx_atu_entry *entry,
1150 bool static_too)
1151{
1152 int op;
1153 int err;
1154
Vivien Didelotfad09c72016-06-21 12:28:20 -04001155 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001156 if (err)
1157 return err;
1158
Vivien Didelotfad09c72016-06-21 12:28:20 -04001159 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001160 if (err)
1161 return err;
1162
1163 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001164 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1165 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1166 } else {
1167 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1168 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1169 }
1170
Vivien Didelotfad09c72016-06-21 12:28:20 -04001171 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001172}
1173
Vivien Didelotfad09c72016-06-21 12:28:20 -04001174static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001175 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001176{
1177 struct mv88e6xxx_atu_entry entry = {
1178 .fid = fid,
1179 .state = 0, /* EntryState bits must be 0 */
1180 };
1181
Vivien Didelotfad09c72016-06-21 12:28:20 -04001182 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001183}
1184
Vivien Didelotfad09c72016-06-21 12:28:20 -04001185static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001186 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001187{
1188 struct mv88e6xxx_atu_entry entry = {
1189 .trunk = false,
1190 .fid = fid,
1191 };
1192
1193 /* EntryState bits must be 0xF */
1194 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1195
1196 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1197 entry.portv_trunkid = (to_port & 0x0f) << 4;
1198 entry.portv_trunkid |= from_port & 0x0f;
1199
Vivien Didelotfad09c72016-06-21 12:28:20 -04001200 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001201}
1202
Vivien Didelotfad09c72016-06-21 12:28:20 -04001203static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001204 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001205{
1206 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001207 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001208}
1209
Vivien Didelotfad09c72016-06-21 12:28:20 -04001210static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001211{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001212 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001213 struct dsa_switch *ds = chip->ds;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001214 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001215 int i;
1216
1217 /* allow CPU port or DSA link(s) to send frames to every port */
1218 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001219 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001220 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001221 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001222 /* allow sending frames to every group member */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001223 if (bridge && chip->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001224 output_ports |= BIT(i);
1225
1226 /* allow sending frames to CPU port and DSA link(s) */
1227 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1228 output_ports |= BIT(i);
1229 }
1230 }
1231
1232 /* prevent frames from going back out of the port they came in on */
1233 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001234
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001235 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001236}
1237
Vivien Didelotf81ec902016-05-09 13:22:58 -04001238static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1239 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001240{
Vivien Didelot04bed142016-08-31 18:06:13 -04001241 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001242 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001243 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001244
1245 switch (state) {
1246 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001247 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001248 break;
1249 case BR_STATE_BLOCKING:
1250 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001251 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001252 break;
1253 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001254 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001255 break;
1256 case BR_STATE_FORWARDING:
1257 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001258 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001259 break;
1260 }
1261
Vivien Didelotfad09c72016-06-21 12:28:20 -04001262 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001263 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001264 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001265
1266 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001267 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001268}
1269
Vivien Didelot749efcb2016-09-22 16:49:24 -04001270static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1271{
1272 struct mv88e6xxx_chip *chip = ds->priv;
1273 int err;
1274
1275 mutex_lock(&chip->reg_lock);
1276 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1277 mutex_unlock(&chip->reg_lock);
1278
1279 if (err)
1280 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1281}
1282
Vivien Didelotfad09c72016-06-21 12:28:20 -04001283static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001284{
Vivien Didelota935c052016-09-29 12:21:53 -04001285 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001286}
1287
Vivien Didelotfad09c72016-06-21 12:28:20 -04001288static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001289{
Vivien Didelota935c052016-09-29 12:21:53 -04001290 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001291
Vivien Didelota935c052016-09-29 12:21:53 -04001292 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1293 if (err)
1294 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001295
Vivien Didelotfad09c72016-06-21 12:28:20 -04001296 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001297}
1298
Vivien Didelotfad09c72016-06-21 12:28:20 -04001299static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001300{
1301 int ret;
1302
Vivien Didelotfad09c72016-06-21 12:28:20 -04001303 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001304 if (ret < 0)
1305 return ret;
1306
Vivien Didelotfad09c72016-06-21 12:28:20 -04001307 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001308}
1309
Vivien Didelotfad09c72016-06-21 12:28:20 -04001310static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001311 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001312 unsigned int nibble_offset)
1313{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001314 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001315 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001316
1317 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001318 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001319
Vivien Didelota935c052016-09-29 12:21:53 -04001320 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1321 if (err)
1322 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001323 }
1324
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001325 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001326 unsigned int shift = (i % 4) * 4 + nibble_offset;
1327 u16 reg = regs[i / 4];
1328
1329 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1330 }
1331
1332 return 0;
1333}
1334
Vivien Didelotfad09c72016-06-21 12:28:20 -04001335static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001336 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001337{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001338 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001339}
1340
Vivien Didelotfad09c72016-06-21 12:28:20 -04001341static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001342 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001343{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001344 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001345}
1346
Vivien Didelotfad09c72016-06-21 12:28:20 -04001347static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001348 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001349 unsigned int nibble_offset)
1350{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001351 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001352 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001353
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001354 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001355 unsigned int shift = (i % 4) * 4 + nibble_offset;
1356 u8 data = entry->data[i];
1357
1358 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1359 }
1360
1361 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001362 u16 reg = regs[i];
1363
1364 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1365 if (err)
1366 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001367 }
1368
1369 return 0;
1370}
1371
Vivien Didelotfad09c72016-06-21 12:28:20 -04001372static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001373 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001374{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001375 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001376}
1377
Vivien Didelotfad09c72016-06-21 12:28:20 -04001378static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001379 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001380{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001381 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001382}
1383
Vivien Didelotfad09c72016-06-21 12:28:20 -04001384static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001385{
Vivien Didelota935c052016-09-29 12:21:53 -04001386 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1387 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001388}
1389
Vivien Didelotfad09c72016-06-21 12:28:20 -04001390static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001391 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001392{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001393 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001394 u16 val;
1395 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001396
Vivien Didelota935c052016-09-29 12:21:53 -04001397 err = _mv88e6xxx_vtu_wait(chip);
1398 if (err)
1399 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001400
Vivien Didelota935c052016-09-29 12:21:53 -04001401 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1402 if (err)
1403 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001404
Vivien Didelota935c052016-09-29 12:21:53 -04001405 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1406 if (err)
1407 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001408
Vivien Didelota935c052016-09-29 12:21:53 -04001409 next.vid = val & GLOBAL_VTU_VID_MASK;
1410 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001411
1412 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001413 err = mv88e6xxx_vtu_data_read(chip, &next);
1414 if (err)
1415 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001416
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001417 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001418 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1419 if (err)
1420 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001421
Vivien Didelota935c052016-09-29 12:21:53 -04001422 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001423 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001424 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1425 * VTU DBNum[3:0] are located in VTU Operation 3:0
1426 */
Vivien Didelota935c052016-09-29 12:21:53 -04001427 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1428 if (err)
1429 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001430
Vivien Didelota935c052016-09-29 12:21:53 -04001431 next.fid = (val & 0xf00) >> 4;
1432 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001433 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001434
Vivien Didelotfad09c72016-06-21 12:28:20 -04001435 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001436 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1437 if (err)
1438 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001439
Vivien Didelota935c052016-09-29 12:21:53 -04001440 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001441 }
1442 }
1443
1444 *entry = next;
1445 return 0;
1446}
1447
Vivien Didelotf81ec902016-05-09 13:22:58 -04001448static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1449 struct switchdev_obj_port_vlan *vlan,
1450 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001451{
Vivien Didelot04bed142016-08-31 18:06:13 -04001452 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001453 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001454 u16 pvid;
1455 int err;
1456
Vivien Didelotfad09c72016-06-21 12:28:20 -04001457 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001458 return -EOPNOTSUPP;
1459
Vivien Didelotfad09c72016-06-21 12:28:20 -04001460 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001461
Vivien Didelot77064f32016-11-04 03:23:30 +01001462 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001463 if (err)
1464 goto unlock;
1465
Vivien Didelotfad09c72016-06-21 12:28:20 -04001466 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001467 if (err)
1468 goto unlock;
1469
1470 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001471 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001472 if (err)
1473 break;
1474
1475 if (!next.valid)
1476 break;
1477
1478 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1479 continue;
1480
1481 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001482 vlan->vid_begin = next.vid;
1483 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001484 vlan->flags = 0;
1485
1486 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1487 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1488
1489 if (next.vid == pvid)
1490 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1491
1492 err = cb(&vlan->obj);
1493 if (err)
1494 break;
1495 } while (next.vid < GLOBAL_VTU_VID_MASK);
1496
1497unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001498 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001499
1500 return err;
1501}
1502
Vivien Didelotfad09c72016-06-21 12:28:20 -04001503static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001504 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001505{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001506 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001507 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001508 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001509
Vivien Didelota935c052016-09-29 12:21:53 -04001510 err = _mv88e6xxx_vtu_wait(chip);
1511 if (err)
1512 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001513
1514 if (!entry->valid)
1515 goto loadpurge;
1516
1517 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001518 err = mv88e6xxx_vtu_data_write(chip, entry);
1519 if (err)
1520 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001521
Vivien Didelotfad09c72016-06-21 12:28:20 -04001522 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001523 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001524 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1525 if (err)
1526 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001527 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001528
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001529 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001530 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001531 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1532 if (err)
1533 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001534 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001535 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1536 * VTU DBNum[3:0] are located in VTU Operation 3:0
1537 */
1538 op |= (entry->fid & 0xf0) << 8;
1539 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001540 }
1541
1542 reg = GLOBAL_VTU_VID_VALID;
1543loadpurge:
1544 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001545 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1546 if (err)
1547 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001548
Vivien Didelotfad09c72016-06-21 12:28:20 -04001549 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001550}
1551
Vivien Didelotfad09c72016-06-21 12:28:20 -04001552static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001553 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001554{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001555 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001556 u16 val;
1557 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001558
Vivien Didelota935c052016-09-29 12:21:53 -04001559 err = _mv88e6xxx_vtu_wait(chip);
1560 if (err)
1561 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001562
Vivien Didelota935c052016-09-29 12:21:53 -04001563 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1564 sid & GLOBAL_VTU_SID_MASK);
1565 if (err)
1566 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001567
Vivien Didelota935c052016-09-29 12:21:53 -04001568 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1569 if (err)
1570 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001571
Vivien Didelota935c052016-09-29 12:21:53 -04001572 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1573 if (err)
1574 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001575
Vivien Didelota935c052016-09-29 12:21:53 -04001576 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001577
Vivien Didelota935c052016-09-29 12:21:53 -04001578 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1579 if (err)
1580 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001581
Vivien Didelota935c052016-09-29 12:21:53 -04001582 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001583
1584 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001585 err = mv88e6xxx_stu_data_read(chip, &next);
1586 if (err)
1587 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001588 }
1589
1590 *entry = next;
1591 return 0;
1592}
1593
Vivien Didelotfad09c72016-06-21 12:28:20 -04001594static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001595 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001596{
1597 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001598 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001599
Vivien Didelota935c052016-09-29 12:21:53 -04001600 err = _mv88e6xxx_vtu_wait(chip);
1601 if (err)
1602 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001603
1604 if (!entry->valid)
1605 goto loadpurge;
1606
1607 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001608 err = mv88e6xxx_stu_data_write(chip, entry);
1609 if (err)
1610 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001611
1612 reg = GLOBAL_VTU_VID_VALID;
1613loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001614 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1615 if (err)
1616 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001617
1618 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001619 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1620 if (err)
1621 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001622
Vivien Didelotfad09c72016-06-21 12:28:20 -04001623 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001624}
1625
Vivien Didelotfad09c72016-06-21 12:28:20 -04001626static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001627{
1628 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001629 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001630 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001631
1632 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1633
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001634 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001635 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001636 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001637 if (err)
1638 return err;
1639
1640 set_bit(*fid, fid_bitmap);
1641 }
1642
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001643 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001644 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001645 if (err)
1646 return err;
1647
1648 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001649 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001650 if (err)
1651 return err;
1652
1653 if (!vlan.valid)
1654 break;
1655
1656 set_bit(vlan.fid, fid_bitmap);
1657 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1658
1659 /* The reset value 0x000 is used to indicate that multiple address
1660 * databases are not needed. Return the next positive available.
1661 */
1662 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001663 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001664 return -ENOSPC;
1665
1666 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001667 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001668}
1669
Vivien Didelotfad09c72016-06-21 12:28:20 -04001670static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001671 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001672{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001673 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001674 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001675 .valid = true,
1676 .vid = vid,
1677 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001678 int i, err;
1679
Vivien Didelotfad09c72016-06-21 12:28:20 -04001680 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001681 if (err)
1682 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001683
Vivien Didelot3d131f02015-11-03 10:52:52 -05001684 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001685 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001686 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1687 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1688 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001689
Vivien Didelotfad09c72016-06-21 12:28:20 -04001690 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
1691 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001692 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001693
1694 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1695 * implemented, only one STU entry is needed to cover all VTU
1696 * entries. Thus, validate the SID 0.
1697 */
1698 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001699 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001700 if (err)
1701 return err;
1702
1703 if (vstp.sid != vlan.sid || !vstp.valid) {
1704 memset(&vstp, 0, sizeof(vstp));
1705 vstp.valid = true;
1706 vstp.sid = vlan.sid;
1707
Vivien Didelotfad09c72016-06-21 12:28:20 -04001708 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001709 if (err)
1710 return err;
1711 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001712 }
1713
1714 *entry = vlan;
1715 return 0;
1716}
1717
Vivien Didelotfad09c72016-06-21 12:28:20 -04001718static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001719 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001720{
1721 int err;
1722
1723 if (!vid)
1724 return -EINVAL;
1725
Vivien Didelotfad09c72016-06-21 12:28:20 -04001726 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001727 if (err)
1728 return err;
1729
Vivien Didelotfad09c72016-06-21 12:28:20 -04001730 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001731 if (err)
1732 return err;
1733
1734 if (entry->vid != vid || !entry->valid) {
1735 if (!creat)
1736 return -EOPNOTSUPP;
1737 /* -ENOENT would've been more appropriate, but switchdev expects
1738 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1739 */
1740
Vivien Didelotfad09c72016-06-21 12:28:20 -04001741 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001742 }
1743
1744 return err;
1745}
1746
Vivien Didelotda9c3592016-02-12 12:09:40 -05001747static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1748 u16 vid_begin, u16 vid_end)
1749{
Vivien Didelot04bed142016-08-31 18:06:13 -04001750 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001751 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001752 int i, err;
1753
1754 if (!vid_begin)
1755 return -EOPNOTSUPP;
1756
Vivien Didelotfad09c72016-06-21 12:28:20 -04001757 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001758
Vivien Didelotfad09c72016-06-21 12:28:20 -04001759 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001760 if (err)
1761 goto unlock;
1762
1763 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001764 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001765 if (err)
1766 goto unlock;
1767
1768 if (!vlan.valid)
1769 break;
1770
1771 if (vlan.vid > vid_end)
1772 break;
1773
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001774 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001775 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1776 continue;
1777
1778 if (vlan.data[i] ==
1779 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1780 continue;
1781
Vivien Didelotfad09c72016-06-21 12:28:20 -04001782 if (chip->ports[i].bridge_dev ==
1783 chip->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001784 break; /* same bridge, check next VLAN */
1785
Andrew Lunnc8b09802016-06-04 21:16:57 +02001786 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001787 "hardware VLAN %d already used by %s\n",
1788 vlan.vid,
Vivien Didelotfad09c72016-06-21 12:28:20 -04001789 netdev_name(chip->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001790 err = -EOPNOTSUPP;
1791 goto unlock;
1792 }
1793 } while (vlan.vid < vid_end);
1794
1795unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001796 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001797
1798 return err;
1799}
1800
Vivien Didelotf81ec902016-05-09 13:22:58 -04001801static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1802 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001803{
Vivien Didelot04bed142016-08-31 18:06:13 -04001804 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001805 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001806 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001807 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001808
Vivien Didelotfad09c72016-06-21 12:28:20 -04001809 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001810 return -EOPNOTSUPP;
1811
Vivien Didelotfad09c72016-06-21 12:28:20 -04001812 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001813 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001814 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001815
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001816 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001817}
1818
Vivien Didelot57d32312016-06-20 13:13:58 -04001819static int
1820mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1821 const struct switchdev_obj_port_vlan *vlan,
1822 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001823{
Vivien Didelot04bed142016-08-31 18:06:13 -04001824 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001825 int err;
1826
Vivien Didelotfad09c72016-06-21 12:28:20 -04001827 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001828 return -EOPNOTSUPP;
1829
Vivien Didelotda9c3592016-02-12 12:09:40 -05001830 /* If the requested port doesn't belong to the same bridge as the VLAN
1831 * members, do not support it (yet) and fallback to software VLAN.
1832 */
1833 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1834 vlan->vid_end);
1835 if (err)
1836 return err;
1837
Vivien Didelot76e398a2015-11-01 12:33:55 -05001838 /* We don't need any dynamic resource from the kernel (yet),
1839 * so skip the prepare phase.
1840 */
1841 return 0;
1842}
1843
Vivien Didelotfad09c72016-06-21 12:28:20 -04001844static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001845 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001846{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001847 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001848 int err;
1849
Vivien Didelotfad09c72016-06-21 12:28:20 -04001850 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001851 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001852 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001853
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001854 vlan.data[port] = untagged ?
1855 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1856 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1857
Vivien Didelotfad09c72016-06-21 12:28:20 -04001858 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001859}
1860
Vivien Didelotf81ec902016-05-09 13:22:58 -04001861static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1862 const struct switchdev_obj_port_vlan *vlan,
1863 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001864{
Vivien Didelot04bed142016-08-31 18:06:13 -04001865 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001866 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1867 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1868 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001869
Vivien Didelotfad09c72016-06-21 12:28:20 -04001870 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001871 return;
1872
Vivien Didelotfad09c72016-06-21 12:28:20 -04001873 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001874
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001875 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001876 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001877 netdev_err(ds->ports[port].netdev,
1878 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001879 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001880
Vivien Didelot77064f32016-11-04 03:23:30 +01001881 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001882 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001883 vlan->vid_end);
1884
Vivien Didelotfad09c72016-06-21 12:28:20 -04001885 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001886}
1887
Vivien Didelotfad09c72016-06-21 12:28:20 -04001888static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001889 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001890{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001891 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001892 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001893 int i, err;
1894
Vivien Didelotfad09c72016-06-21 12:28:20 -04001895 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001896 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001897 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001898
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001899 /* Tell switchdev if this VLAN is handled in software */
1900 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001901 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001902
1903 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1904
1905 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001906 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001907 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001908 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001909 continue;
1910
1911 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001912 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001913 break;
1914 }
1915 }
1916
Vivien Didelotfad09c72016-06-21 12:28:20 -04001917 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001918 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001919 return err;
1920
Vivien Didelotfad09c72016-06-21 12:28:20 -04001921 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001922}
1923
Vivien Didelotf81ec902016-05-09 13:22:58 -04001924static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1925 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001926{
Vivien Didelot04bed142016-08-31 18:06:13 -04001927 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001928 u16 pvid, vid;
1929 int err = 0;
1930
Vivien Didelotfad09c72016-06-21 12:28:20 -04001931 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001932 return -EOPNOTSUPP;
1933
Vivien Didelotfad09c72016-06-21 12:28:20 -04001934 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001935
Vivien Didelot77064f32016-11-04 03:23:30 +01001936 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001937 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001938 goto unlock;
1939
Vivien Didelot76e398a2015-11-01 12:33:55 -05001940 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001941 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001942 if (err)
1943 goto unlock;
1944
1945 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001946 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001947 if (err)
1948 goto unlock;
1949 }
1950 }
1951
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001952unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001953 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001954
1955 return err;
1956}
1957
Vivien Didelotfad09c72016-06-21 12:28:20 -04001958static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04001959 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001960{
Vivien Didelota935c052016-09-29 12:21:53 -04001961 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001962
1963 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04001964 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
1965 (addr[i * 2] << 8) | addr[i * 2 + 1]);
1966 if (err)
1967 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001968 }
1969
1970 return 0;
1971}
1972
Vivien Didelotfad09c72016-06-21 12:28:20 -04001973static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001974 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001975{
Vivien Didelota935c052016-09-29 12:21:53 -04001976 u16 val;
1977 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001978
1979 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04001980 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
1981 if (err)
1982 return err;
1983
1984 addr[i * 2] = val >> 8;
1985 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001986 }
1987
1988 return 0;
1989}
1990
Vivien Didelotfad09c72016-06-21 12:28:20 -04001991static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04001992 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001993{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001994 int ret;
1995
Vivien Didelotfad09c72016-06-21 12:28:20 -04001996 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001997 if (ret < 0)
1998 return ret;
1999
Vivien Didelotfad09c72016-06-21 12:28:20 -04002000 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002001 if (ret < 0)
2002 return ret;
2003
Vivien Didelotfad09c72016-06-21 12:28:20 -04002004 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002005 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002006 return ret;
2007
Vivien Didelotfad09c72016-06-21 12:28:20 -04002008 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002009}
David S. Millercdf09692015-08-11 12:00:37 -07002010
Vivien Didelot88472932016-09-19 19:56:11 -04002011static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2012 struct mv88e6xxx_atu_entry *entry);
2013
2014static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2015 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2016{
2017 struct mv88e6xxx_atu_entry next;
2018 int err;
2019
2020 eth_broadcast_addr(next.mac);
2021
2022 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2023 if (err)
2024 return err;
2025
2026 do {
2027 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2028 if (err)
2029 return err;
2030
2031 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2032 break;
2033
2034 if (ether_addr_equal(next.mac, addr)) {
2035 *entry = next;
2036 return 0;
2037 }
2038 } while (!is_broadcast_ether_addr(next.mac));
2039
2040 memset(entry, 0, sizeof(*entry));
2041 entry->fid = fid;
2042 ether_addr_copy(entry->mac, addr);
2043
2044 return 0;
2045}
2046
Vivien Didelot83dabd12016-08-31 11:50:04 -04002047static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2048 const unsigned char *addr, u16 vid,
2049 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002050{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002051 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002052 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002053 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002054
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002055 /* Null VLAN ID corresponds to the port private database */
2056 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002057 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002058 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002059 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002060 if (err)
2061 return err;
2062
Vivien Didelot88472932016-09-19 19:56:11 -04002063 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2064 if (err)
2065 return err;
2066
2067 /* Purge the ATU entry only if no port is using it anymore */
2068 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2069 entry.portv_trunkid &= ~BIT(port);
2070 if (!entry.portv_trunkid)
2071 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2072 } else {
2073 entry.portv_trunkid |= BIT(port);
2074 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002075 }
2076
Vivien Didelotfad09c72016-06-21 12:28:20 -04002077 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002078}
2079
Vivien Didelotf81ec902016-05-09 13:22:58 -04002080static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2081 const struct switchdev_obj_port_fdb *fdb,
2082 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002083{
2084 /* We don't need any dynamic resource from the kernel (yet),
2085 * so skip the prepare phase.
2086 */
2087 return 0;
2088}
2089
Vivien Didelotf81ec902016-05-09 13:22:58 -04002090static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2091 const struct switchdev_obj_port_fdb *fdb,
2092 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002093{
Vivien Didelot04bed142016-08-31 18:06:13 -04002094 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002095
Vivien Didelotfad09c72016-06-21 12:28:20 -04002096 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002097 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2098 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2099 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002100 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002101}
2102
Vivien Didelotf81ec902016-05-09 13:22:58 -04002103static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2104 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002105{
Vivien Didelot04bed142016-08-31 18:06:13 -04002106 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002107 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002108
Vivien Didelotfad09c72016-06-21 12:28:20 -04002109 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002110 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2111 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002112 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002113
Vivien Didelot83dabd12016-08-31 11:50:04 -04002114 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002115}
2116
Vivien Didelotfad09c72016-06-21 12:28:20 -04002117static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002118 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002119{
Vivien Didelot1d194042015-08-10 09:09:51 -04002120 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002121 u16 val;
2122 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002123
2124 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002125
Vivien Didelota935c052016-09-29 12:21:53 -04002126 err = _mv88e6xxx_atu_wait(chip);
2127 if (err)
2128 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002129
Vivien Didelota935c052016-09-29 12:21:53 -04002130 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2131 if (err)
2132 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002133
Vivien Didelota935c052016-09-29 12:21:53 -04002134 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2135 if (err)
2136 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002137
Vivien Didelota935c052016-09-29 12:21:53 -04002138 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2139 if (err)
2140 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002141
Vivien Didelota935c052016-09-29 12:21:53 -04002142 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002143 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2144 unsigned int mask, shift;
2145
Vivien Didelota935c052016-09-29 12:21:53 -04002146 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002147 next.trunk = true;
2148 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2149 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2150 } else {
2151 next.trunk = false;
2152 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2153 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2154 }
2155
Vivien Didelota935c052016-09-29 12:21:53 -04002156 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002157 }
2158
2159 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002160 return 0;
2161}
2162
Vivien Didelot83dabd12016-08-31 11:50:04 -04002163static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2164 u16 fid, u16 vid, int port,
2165 struct switchdev_obj *obj,
2166 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002167{
2168 struct mv88e6xxx_atu_entry addr = {
2169 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2170 };
2171 int err;
2172
Vivien Didelotfad09c72016-06-21 12:28:20 -04002173 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002174 if (err)
2175 return err;
2176
2177 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002178 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002179 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002180 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002181
2182 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2183 break;
2184
Vivien Didelot83dabd12016-08-31 11:50:04 -04002185 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2186 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002187
Vivien Didelot83dabd12016-08-31 11:50:04 -04002188 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2189 struct switchdev_obj_port_fdb *fdb;
2190
2191 if (!is_unicast_ether_addr(addr.mac))
2192 continue;
2193
2194 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002195 fdb->vid = vid;
2196 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002197 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2198 fdb->ndm_state = NUD_NOARP;
2199 else
2200 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002201 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2202 struct switchdev_obj_port_mdb *mdb;
2203
2204 if (!is_multicast_ether_addr(addr.mac))
2205 continue;
2206
2207 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2208 mdb->vid = vid;
2209 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002210 } else {
2211 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002212 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002213
2214 err = cb(obj);
2215 if (err)
2216 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002217 } while (!is_broadcast_ether_addr(addr.mac));
2218
2219 return err;
2220}
2221
Vivien Didelot83dabd12016-08-31 11:50:04 -04002222static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2223 struct switchdev_obj *obj,
2224 int (*cb)(struct switchdev_obj *obj))
2225{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002226 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002227 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2228 };
2229 u16 fid;
2230 int err;
2231
2232 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002233 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002234 if (err)
2235 return err;
2236
2237 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2238 if (err)
2239 return err;
2240
2241 /* Dump VLANs' Filtering Information Databases */
2242 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2243 if (err)
2244 return err;
2245
2246 do {
2247 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2248 if (err)
2249 return err;
2250
2251 if (!vlan.valid)
2252 break;
2253
2254 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2255 obj, cb);
2256 if (err)
2257 return err;
2258 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2259
2260 return err;
2261}
2262
Vivien Didelotf81ec902016-05-09 13:22:58 -04002263static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2264 struct switchdev_obj_port_fdb *fdb,
2265 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002266{
Vivien Didelot04bed142016-08-31 18:06:13 -04002267 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002268 int err;
2269
Vivien Didelotfad09c72016-06-21 12:28:20 -04002270 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002271 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002272 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002273
2274 return err;
2275}
2276
Vivien Didelotf81ec902016-05-09 13:22:58 -04002277static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
2278 struct net_device *bridge)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002279{
Vivien Didelot04bed142016-08-31 18:06:13 -04002280 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002281 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002282
Vivien Didelotfad09c72016-06-21 12:28:20 -04002283 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002284
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002285 /* Assign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002286 chip->ports[port].bridge_dev = bridge;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002287
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002288 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002289 if (chip->ports[i].bridge_dev == bridge) {
2290 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002291 if (err)
2292 break;
2293 }
2294 }
2295
Vivien Didelotfad09c72016-06-21 12:28:20 -04002296 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002297
Vivien Didelot466dfa02016-02-26 13:16:05 -05002298 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002299}
2300
Vivien Didelotf81ec902016-05-09 13:22:58 -04002301static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002302{
Vivien Didelot04bed142016-08-31 18:06:13 -04002303 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002304 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002305 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002306
Vivien Didelotfad09c72016-06-21 12:28:20 -04002307 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002308
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002309 /* Unassign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002310 chip->ports[port].bridge_dev = NULL;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002311
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002312 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002313 if (i == port || chip->ports[i].bridge_dev == bridge)
2314 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002315 netdev_warn(ds->ports[i].netdev,
2316 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002317
Vivien Didelotfad09c72016-06-21 12:28:20 -04002318 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002319}
2320
Vivien Didelot17e708b2016-12-05 17:30:27 -05002321static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2322{
2323 if (chip->info->ops->reset)
2324 return chip->info->ops->reset(chip);
2325
2326 return 0;
2327}
2328
Vivien Didelot309eca62016-12-05 17:30:26 -05002329static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2330{
2331 struct gpio_desc *gpiod = chip->reset;
2332
2333 /* If there is a GPIO connected to the reset pin, toggle it */
2334 if (gpiod) {
2335 gpiod_set_value_cansleep(gpiod, 1);
2336 usleep_range(10000, 20000);
2337 gpiod_set_value_cansleep(gpiod, 0);
2338 usleep_range(10000, 20000);
2339 }
2340}
2341
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002342static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2343{
2344 int i, err;
2345
2346 /* Set all ports to the Disabled state */
2347 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2348 err = mv88e6xxx_port_set_state(chip, i,
2349 PORT_CONTROL_STATE_DISABLED);
2350 if (err)
2351 return err;
2352 }
2353
2354 /* Wait for transmit queues to drain,
2355 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2356 */
2357 usleep_range(2000, 4000);
2358
2359 return 0;
2360}
2361
Vivien Didelotfad09c72016-06-21 12:28:20 -04002362static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002363{
Vivien Didelota935c052016-09-29 12:21:53 -04002364 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002365
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002366 err = mv88e6xxx_disable_ports(chip);
2367 if (err)
2368 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002369
Vivien Didelot309eca62016-12-05 17:30:26 -05002370 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002371
Vivien Didelot17e708b2016-12-05 17:30:27 -05002372 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002373}
2374
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002375static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002376{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002377 u16 val;
2378 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002379
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002380 /* Clear Power Down bit */
2381 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2382 if (err)
2383 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002384
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002385 if (val & BMCR_PDOWN) {
2386 val &= ~BMCR_PDOWN;
2387 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002388 }
2389
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002390 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002391}
2392
Andrew Lunn56995cb2016-12-03 04:35:19 +01002393static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2394 int upstream_port)
2395{
2396 int err;
2397
2398 err = chip->info->ops->port_set_frame_mode(
2399 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2400 if (err)
2401 return err;
2402
2403 return chip->info->ops->port_set_egress_unknowns(
2404 chip, port, port == upstream_port);
2405}
2406
2407static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2408{
2409 int err;
2410
2411 switch (chip->info->tag_protocol) {
2412 case DSA_TAG_PROTO_EDSA:
2413 err = chip->info->ops->port_set_frame_mode(
2414 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2415 if (err)
2416 return err;
2417
2418 err = mv88e6xxx_port_set_egress_mode(
2419 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2420 if (err)
2421 return err;
2422
2423 if (chip->info->ops->port_set_ether_type)
2424 err = chip->info->ops->port_set_ether_type(
2425 chip, port, ETH_P_EDSA);
2426 break;
2427
2428 case DSA_TAG_PROTO_DSA:
2429 err = chip->info->ops->port_set_frame_mode(
2430 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2431 if (err)
2432 return err;
2433
2434 err = mv88e6xxx_port_set_egress_mode(
2435 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2436 break;
2437 default:
2438 err = -EINVAL;
2439 }
2440
2441 if (err)
2442 return err;
2443
2444 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2445}
2446
2447static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2448{
2449 int err;
2450
2451 err = chip->info->ops->port_set_frame_mode(
2452 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2453 if (err)
2454 return err;
2455
2456 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2457}
2458
Vivien Didelotfad09c72016-06-21 12:28:20 -04002459static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002460{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002461 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002462 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002463 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002464
Vivien Didelotd78343d2016-11-04 03:23:36 +01002465 /* MAC Forcing register: don't force link, speed, duplex or flow control
2466 * state to any particular values on physical ports, but force the CPU
2467 * port and all DSA ports to their maximum bandwidth and full duplex.
2468 */
2469 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2470 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2471 SPEED_MAX, DUPLEX_FULL,
2472 PHY_INTERFACE_MODE_NA);
2473 else
2474 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2475 SPEED_UNFORCED, DUPLEX_UNFORCED,
2476 PHY_INTERFACE_MODE_NA);
2477 if (err)
2478 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002479
2480 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2481 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2482 * tunneling, determine priority by looking at 802.1p and IP
2483 * priority fields (IP prio has precedence), and set STP state
2484 * to Forwarding.
2485 *
2486 * If this is the CPU link, use DSA or EDSA tagging depending
2487 * on which tagging mode was configured.
2488 *
2489 * If this is a link to another switch, use DSA tagging mode.
2490 *
2491 * If this is the upstream port for this switch, enable
2492 * forwarding of unknown unicasts and multicasts.
2493 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002494 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002495 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2496 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002497 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2498 if (err)
2499 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002500
Andrew Lunn56995cb2016-12-03 04:35:19 +01002501 if (dsa_is_cpu_port(ds, port)) {
2502 err = mv88e6xxx_setup_port_cpu(chip, port);
2503 } else if (dsa_is_dsa_port(ds, port)) {
2504 err = mv88e6xxx_setup_port_dsa(chip, port,
2505 dsa_upstream_port(ds));
2506 } else {
2507 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002508 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002509 if (err)
2510 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002511
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002512 /* If this port is connected to a SerDes, make sure the SerDes is not
2513 * powered down.
2514 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002515 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002516 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2517 if (err)
2518 return err;
2519 reg &= PORT_STATUS_CMODE_MASK;
2520 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2521 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2522 (reg == PORT_STATUS_CMODE_SGMII)) {
2523 err = mv88e6xxx_serdes_power_on(chip);
2524 if (err < 0)
2525 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002526 }
2527 }
2528
Vivien Didelot8efdda42015-08-13 12:52:23 -04002529 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002530 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002531 * untagged frames on this port, do a destination address lookup on all
2532 * received packets as usual, disable ARP mirroring and don't send a
2533 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002534 */
2535 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002536 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2537 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2538 mv88e6xxx_6095_family(chip) || mv88e6xxx_6320_family(chip) ||
2539 mv88e6xxx_6185_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002540 reg = PORT_CONTROL_2_MAP_DA;
2541
Vivien Didelotfad09c72016-06-21 12:28:20 -04002542 if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002543 /* Set the upstream port this port should use */
2544 reg |= dsa_upstream_port(ds);
2545 /* enable forwarding of unknown multicast addresses to
2546 * the upstream port
2547 */
2548 if (port == dsa_upstream_port(ds))
2549 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
2550 }
2551
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002552 reg |= PORT_CONTROL_2_8021Q_DISABLED;
Vivien Didelot8efdda42015-08-13 12:52:23 -04002553
Andrew Lunn54d792f2015-05-06 01:09:47 +02002554 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002555 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
2556 if (err)
2557 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002558 }
2559
Andrew Lunn5f436662016-12-03 04:45:17 +01002560 if (chip->info->ops->port_jumbo_config) {
2561 err = chip->info->ops->port_jumbo_config(chip, port);
2562 if (err)
2563 return err;
2564 }
2565
Andrew Lunn54d792f2015-05-06 01:09:47 +02002566 /* Port Association Vector: when learning source addresses
2567 * of packets, add the address to the address database using
2568 * a port bitmap that has only the bit for this port set and
2569 * the other bits clear.
2570 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002571 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002572 /* Disable learning for CPU port */
2573 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002574 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002575
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002576 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2577 if (err)
2578 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002579
2580 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002581 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2582 if (err)
2583 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002584
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002585 if (chip->info->ops->port_pause_config) {
2586 err = chip->info->ops->port_pause_config(chip, port);
2587 if (err)
2588 return err;
2589 }
2590
Vivien Didelotfad09c72016-06-21 12:28:20 -04002591 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2592 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2593 mv88e6xxx_6320_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002594 /* Port ATU control: disable limiting the number of
2595 * address database entries that this port is allowed
2596 * to use.
2597 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002598 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2599 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002600 /* Priority Override: disable DA, SA and VTU priority
2601 * override.
2602 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002603 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2604 0x0000);
2605 if (err)
2606 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002607 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002608
Andrew Lunnef0a7312016-12-03 04:35:16 +01002609 if (chip->info->ops->port_tag_remap) {
2610 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002611 if (err)
2612 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002613 }
2614
Andrew Lunnef70b112016-12-03 04:45:18 +01002615 if (chip->info->ops->port_egress_rate_limiting) {
2616 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002617 if (err)
2618 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002619 }
2620
Guenter Roeck366f0a02015-03-26 18:36:30 -07002621 /* Port Control 1: disable trunking, disable sending
2622 * learning messages to this port.
Guenter Roeckd827e882015-03-26 18:36:29 -07002623 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002624 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_1, 0x0000);
2625 if (err)
2626 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002627
Vivien Didelot207afda2016-04-14 14:42:09 -04002628 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002629 * database, and allow bidirectional communication between the
2630 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002631 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002632 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002633 if (err)
2634 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002635
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002636 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2637 if (err)
2638 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002639
2640 /* Default VLAN ID and priority: don't set a default VLAN
2641 * ID, and set the default packet priority to zero.
2642 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002643 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002644}
2645
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002646static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002647{
2648 int err;
2649
Vivien Didelota935c052016-09-29 12:21:53 -04002650 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002651 if (err)
2652 return err;
2653
Vivien Didelota935c052016-09-29 12:21:53 -04002654 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002655 if (err)
2656 return err;
2657
Vivien Didelota935c052016-09-29 12:21:53 -04002658 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2659 if (err)
2660 return err;
2661
2662 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002663}
2664
Vivien Didelotacddbd22016-07-18 20:45:39 -04002665static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
2666 unsigned int msecs)
2667{
2668 const unsigned int coeff = chip->info->age_time_coeff;
2669 const unsigned int min = 0x01 * coeff;
2670 const unsigned int max = 0xff * coeff;
2671 u8 age_time;
2672 u16 val;
2673 int err;
2674
2675 if (msecs < min || msecs > max)
2676 return -ERANGE;
2677
2678 /* Round to nearest multiple of coeff */
2679 age_time = (msecs + coeff / 2) / coeff;
2680
Vivien Didelota935c052016-09-29 12:21:53 -04002681 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002682 if (err)
2683 return err;
2684
2685 /* AgeTime is 11:4 bits */
2686 val &= ~0xff0;
2687 val |= age_time << 4;
2688
Vivien Didelota935c052016-09-29 12:21:53 -04002689 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002690}
2691
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002692static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2693 unsigned int ageing_time)
2694{
Vivien Didelot04bed142016-08-31 18:06:13 -04002695 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002696 int err;
2697
2698 mutex_lock(&chip->reg_lock);
2699 err = mv88e6xxx_g1_set_age_time(chip, ageing_time);
2700 mutex_unlock(&chip->reg_lock);
2701
2702 return err;
2703}
2704
Vivien Didelot97299342016-07-18 20:45:30 -04002705static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002706{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002707 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002708 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002709 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002710
Vivien Didelot119477b2016-05-09 13:22:51 -04002711 /* Enable the PHY Polling Unit if present, don't discard any packets,
2712 * and mask all interrupt sources.
2713 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002714 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002715 if (err)
2716 return err;
2717
Andrew Lunn33641992016-12-03 04:35:17 +01002718 if (chip->info->ops->g1_set_cpu_port) {
2719 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2720 if (err)
2721 return err;
2722 }
2723
2724 if (chip->info->ops->g1_set_egress_port) {
2725 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2726 if (err)
2727 return err;
2728 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002729
Vivien Didelot50484ff2016-05-09 13:22:54 -04002730 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002731 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2732 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2733 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002734 if (err)
2735 return err;
2736
Vivien Didelotacddbd22016-07-18 20:45:39 -04002737 /* Clear all the VTU and STU entries */
2738 err = _mv88e6xxx_vtu_stu_flush(chip);
2739 if (err < 0)
2740 return err;
2741
Vivien Didelot08a01262016-05-09 13:22:50 -04002742 /* Set the default address aging time to 5 minutes, and
2743 * enable address learn messages to be sent to all message
2744 * ports.
2745 */
Vivien Didelota935c052016-09-29 12:21:53 -04002746 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2747 GLOBAL_ATU_CONTROL_LEARN2ALL);
Vivien Didelot08a01262016-05-09 13:22:50 -04002748 if (err)
2749 return err;
2750
Vivien Didelotacddbd22016-07-18 20:45:39 -04002751 err = mv88e6xxx_g1_set_age_time(chip, 300000);
2752 if (err)
Vivien Didelot97299342016-07-18 20:45:30 -04002753 return err;
2754
2755 /* Clear all ATU entries */
2756 err = _mv88e6xxx_atu_flush(chip, 0, true);
2757 if (err)
2758 return err;
2759
Vivien Didelot08a01262016-05-09 13:22:50 -04002760 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002761 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002762 if (err)
2763 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002764 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002765 if (err)
2766 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002767 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002768 if (err)
2769 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002770 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002771 if (err)
2772 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002773 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002774 if (err)
2775 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002776 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002777 if (err)
2778 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002779 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002780 if (err)
2781 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002782 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002783 if (err)
2784 return err;
2785
2786 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002787 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002788 if (err)
2789 return err;
2790
Andrew Lunnde2273872016-11-21 23:27:01 +01002791 /* Initialize the statistics unit */
2792 err = mv88e6xxx_stats_set_histogram(chip);
2793 if (err)
2794 return err;
2795
Vivien Didelot97299342016-07-18 20:45:30 -04002796 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002797 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2798 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002799 if (err)
2800 return err;
2801
2802 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002803 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002804 if (err)
2805 return err;
2806
2807 return 0;
2808}
2809
Vivien Didelotf81ec902016-05-09 13:22:58 -04002810static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002811{
Vivien Didelot04bed142016-08-31 18:06:13 -04002812 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002813 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002814 int i;
2815
Vivien Didelotfad09c72016-06-21 12:28:20 -04002816 chip->ds = ds;
2817 ds->slave_mii_bus = chip->mdio_bus;
Vivien Didelot552238b2016-05-09 13:22:49 -04002818
Vivien Didelotfad09c72016-06-21 12:28:20 -04002819 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002820
Vivien Didelot97299342016-07-18 20:45:30 -04002821 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002822 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002823 err = mv88e6xxx_setup_port(chip, i);
2824 if (err)
2825 goto unlock;
2826 }
2827
2828 /* Setup Switch Global 1 Registers */
2829 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002830 if (err)
2831 goto unlock;
2832
Vivien Didelot97299342016-07-18 20:45:30 -04002833 /* Setup Switch Global 2 Registers */
2834 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2835 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002836 if (err)
2837 goto unlock;
2838 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002839
Andrew Lunn6e55f692016-12-03 04:45:16 +01002840 /* Some generations have the configuration of sending reserved
2841 * management frames to the CPU in global2, others in
2842 * global1. Hence it does not fit the two setup functions
2843 * above.
2844 */
2845 if (chip->info->ops->mgmt_rsvd2cpu) {
2846 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2847 if (err)
2848 goto unlock;
2849 }
2850
Vivien Didelot6b17e862015-08-13 12:52:18 -04002851unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002852 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002853
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002854 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002855}
2856
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002857static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2858{
Vivien Didelot04bed142016-08-31 18:06:13 -04002859 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002860 int err;
2861
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002862 if (!chip->info->ops->set_switch_mac)
2863 return -EOPNOTSUPP;
2864
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002865 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002866 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002867 mutex_unlock(&chip->reg_lock);
2868
2869 return err;
2870}
2871
Vivien Didelote57e5e72016-08-15 17:19:00 -04002872static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002873{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002874 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002875 u16 val;
2876 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002877
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002878 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002879 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002880
Vivien Didelotfad09c72016-06-21 12:28:20 -04002881 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002882 err = mv88e6xxx_phy_read(chip, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002883 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002884
2885 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002886}
2887
Vivien Didelote57e5e72016-08-15 17:19:00 -04002888static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002889{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002890 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002891 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002892
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002893 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002894 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002895
Vivien Didelotfad09c72016-06-21 12:28:20 -04002896 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002897 err = mv88e6xxx_phy_write(chip, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002898 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002899
2900 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002901}
2902
Vivien Didelotfad09c72016-06-21 12:28:20 -04002903static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunnb516d452016-06-04 21:17:06 +02002904 struct device_node *np)
2905{
2906 static int index;
2907 struct mii_bus *bus;
2908 int err;
2909
Andrew Lunnb516d452016-06-04 21:17:06 +02002910 if (np)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002911 chip->mdio_np = of_get_child_by_name(np, "mdio");
Andrew Lunnb516d452016-06-04 21:17:06 +02002912
Vivien Didelotfad09c72016-06-21 12:28:20 -04002913 bus = devm_mdiobus_alloc(chip->dev);
Andrew Lunnb516d452016-06-04 21:17:06 +02002914 if (!bus)
2915 return -ENOMEM;
2916
Vivien Didelotfad09c72016-06-21 12:28:20 -04002917 bus->priv = (void *)chip;
Andrew Lunnb516d452016-06-04 21:17:06 +02002918 if (np) {
2919 bus->name = np->full_name;
2920 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2921 } else {
2922 bus->name = "mv88e6xxx SMI";
2923 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2924 }
2925
2926 bus->read = mv88e6xxx_mdio_read;
2927 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002928 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002929
Vivien Didelotfad09c72016-06-21 12:28:20 -04002930 if (chip->mdio_np)
2931 err = of_mdiobus_register(bus, chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002932 else
2933 err = mdiobus_register(bus);
2934 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002935 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunnb516d452016-06-04 21:17:06 +02002936 goto out;
2937 }
Vivien Didelotfad09c72016-06-21 12:28:20 -04002938 chip->mdio_bus = bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002939
2940 return 0;
2941
2942out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002943 if (chip->mdio_np)
2944 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002945
2946 return err;
2947}
2948
Vivien Didelotfad09c72016-06-21 12:28:20 -04002949static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002950
2951{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002952 struct mii_bus *bus = chip->mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002953
2954 mdiobus_unregister(bus);
2955
Vivien Didelotfad09c72016-06-21 12:28:20 -04002956 if (chip->mdio_np)
2957 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002958}
2959
Guenter Roeckc22995c2015-07-25 09:42:28 -07002960#ifdef CONFIG_NET_DSA_HWMON
2961
2962static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp)
2963{
Vivien Didelot04bed142016-08-31 18:06:13 -04002964 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04002965 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07002966 int ret;
Guenter Roeckc22995c2015-07-25 09:42:28 -07002967
2968 *temp = 0;
2969
Vivien Didelotfad09c72016-06-21 12:28:20 -04002970 mutex_lock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07002971
Vivien Didelot9c938292016-08-15 17:19:02 -04002972 ret = mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x6);
Guenter Roeckc22995c2015-07-25 09:42:28 -07002973 if (ret < 0)
2974 goto error;
2975
2976 /* Enable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04002977 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
Guenter Roeckc22995c2015-07-25 09:42:28 -07002978 if (ret < 0)
2979 goto error;
2980
Vivien Didelot9c938292016-08-15 17:19:02 -04002981 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val | (1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07002982 if (ret < 0)
2983 goto error;
2984
2985 /* Wait for temperature to stabilize */
2986 usleep_range(10000, 12000);
2987
Vivien Didelot9c938292016-08-15 17:19:02 -04002988 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
2989 if (ret < 0)
Guenter Roeckc22995c2015-07-25 09:42:28 -07002990 goto error;
Guenter Roeckc22995c2015-07-25 09:42:28 -07002991
2992 /* Disable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04002993 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val & ~(1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07002994 if (ret < 0)
2995 goto error;
2996
2997 *temp = ((val & 0x1f) - 5) * 5;
2998
2999error:
Vivien Didelot9c938292016-08-15 17:19:02 -04003000 mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x0);
Vivien Didelotfad09c72016-06-21 12:28:20 -04003001 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003002 return ret;
3003}
3004
3005static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp)
3006{
Vivien Didelot04bed142016-08-31 18:06:13 -04003007 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003008 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003009 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003010 int ret;
3011
3012 *temp = 0;
3013
Vivien Didelot9c938292016-08-15 17:19:02 -04003014 mutex_lock(&chip->reg_lock);
3015 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 27, &val);
3016 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003017 if (ret < 0)
3018 return ret;
3019
Vivien Didelot9c938292016-08-15 17:19:02 -04003020 *temp = (val & 0xff) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003021
3022 return 0;
3023}
3024
Vivien Didelotf81ec902016-05-09 13:22:58 -04003025static int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003026{
Vivien Didelot04bed142016-08-31 18:06:13 -04003027 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn158bc062016-04-28 21:24:06 -04003028
Vivien Didelotfad09c72016-06-21 12:28:20 -04003029 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP))
Vivien Didelot6594f612016-05-09 13:22:42 -04003030 return -EOPNOTSUPP;
3031
Vivien Didelotfad09c72016-06-21 12:28:20 -04003032 if (mv88e6xxx_6320_family(chip) || mv88e6xxx_6352_family(chip))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003033 return mv88e63xx_get_temp(ds, temp);
3034
3035 return mv88e61xx_get_temp(ds, temp);
3036}
3037
Vivien Didelotf81ec902016-05-09 13:22:58 -04003038static int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003039{
Vivien Didelot04bed142016-08-31 18:06:13 -04003040 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003041 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003042 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003043 int ret;
3044
Vivien Didelotfad09c72016-06-21 12:28:20 -04003045 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003046 return -EOPNOTSUPP;
3047
3048 *temp = 0;
3049
Vivien Didelot9c938292016-08-15 17:19:02 -04003050 mutex_lock(&chip->reg_lock);
3051 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3052 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003053 if (ret < 0)
3054 return ret;
3055
Vivien Didelot9c938292016-08-15 17:19:02 -04003056 *temp = (((val >> 8) & 0x1f) * 5) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003057
3058 return 0;
3059}
3060
Vivien Didelotf81ec902016-05-09 13:22:58 -04003061static int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003062{
Vivien Didelot04bed142016-08-31 18:06:13 -04003063 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003064 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003065 u16 val;
3066 int err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003067
Vivien Didelotfad09c72016-06-21 12:28:20 -04003068 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003069 return -EOPNOTSUPP;
3070
Vivien Didelot9c938292016-08-15 17:19:02 -04003071 mutex_lock(&chip->reg_lock);
3072 err = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3073 if (err)
3074 goto unlock;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003075 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
Vivien Didelot9c938292016-08-15 17:19:02 -04003076 err = mv88e6xxx_phy_page_write(chip, phy, 6, 26,
3077 (val & 0xe0ff) | (temp << 8));
3078unlock:
3079 mutex_unlock(&chip->reg_lock);
3080
3081 return err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003082}
3083
Vivien Didelotf81ec902016-05-09 13:22:58 -04003084static int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003085{
Vivien Didelot04bed142016-08-31 18:06:13 -04003086 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003087 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003088 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003089 int ret;
3090
Vivien Didelotfad09c72016-06-21 12:28:20 -04003091 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003092 return -EOPNOTSUPP;
3093
3094 *alarm = false;
3095
Vivien Didelot9c938292016-08-15 17:19:02 -04003096 mutex_lock(&chip->reg_lock);
3097 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3098 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003099 if (ret < 0)
3100 return ret;
3101
Vivien Didelot9c938292016-08-15 17:19:02 -04003102 *alarm = !!(val & 0x40);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003103
3104 return 0;
3105}
3106#endif /* CONFIG_NET_DSA_HWMON */
3107
Vivien Didelot855b1932016-07-20 18:18:35 -04003108static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3109{
Vivien Didelot04bed142016-08-31 18:06:13 -04003110 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003111
3112 return chip->eeprom_len;
3113}
3114
Vivien Didelot855b1932016-07-20 18:18:35 -04003115static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3116 struct ethtool_eeprom *eeprom, u8 *data)
3117{
Vivien Didelot04bed142016-08-31 18:06:13 -04003118 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003119 int err;
3120
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003121 if (!chip->info->ops->get_eeprom)
3122 return -EOPNOTSUPP;
3123
Vivien Didelot855b1932016-07-20 18:18:35 -04003124 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003125 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003126 mutex_unlock(&chip->reg_lock);
3127
3128 if (err)
3129 return err;
3130
3131 eeprom->magic = 0xc3ec4951;
3132
3133 return 0;
3134}
3135
Vivien Didelot855b1932016-07-20 18:18:35 -04003136static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3137 struct ethtool_eeprom *eeprom, u8 *data)
3138{
Vivien Didelot04bed142016-08-31 18:06:13 -04003139 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003140 int err;
3141
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003142 if (!chip->info->ops->set_eeprom)
3143 return -EOPNOTSUPP;
3144
Vivien Didelot855b1932016-07-20 18:18:35 -04003145 if (eeprom->magic != 0xc3ec4951)
3146 return -EINVAL;
3147
3148 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003149 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003150 mutex_unlock(&chip->reg_lock);
3151
3152 return err;
3153}
3154
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003155static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003156 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003157 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003158 .phy_read = mv88e6xxx_phy_ppu_read,
3159 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003160 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003161 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003162 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003163 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003164 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3165 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3166 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003167 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003168 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003169 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003170 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3171 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003172 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003173 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3174 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003175 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003176 .ppu_enable = mv88e6185_g1_ppu_enable,
3177 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003178 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003179};
3180
3181static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003182 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003183 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003184 .phy_read = mv88e6xxx_phy_ppu_read,
3185 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003186 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003187 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003188 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003189 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3190 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003191 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003192 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3193 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003194 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003195 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003196 .ppu_enable = mv88e6185_g1_ppu_enable,
3197 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003198 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003199};
3200
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003201static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003202 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003203 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3204 .phy_read = mv88e6xxx_g2_smi_phy_read,
3205 .phy_write = mv88e6xxx_g2_smi_phy_write,
3206 .port_set_link = mv88e6xxx_port_set_link,
3207 .port_set_duplex = mv88e6xxx_port_set_duplex,
3208 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003209 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003210 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3211 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3212 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003213 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003214 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003215 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003216 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3217 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3218 .stats_get_strings = mv88e6095_stats_get_strings,
3219 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003220 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3221 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003222 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003223 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003224};
3225
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003226static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003227 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003228 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003229 .phy_read = mv88e6xxx_read,
3230 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003231 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003232 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003233 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003234 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3235 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003236 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003237 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3238 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003239 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003240 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3241 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003242 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003243 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003244};
3245
3246static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003247 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003248 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003249 .phy_read = mv88e6xxx_phy_ppu_read,
3250 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003251 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003252 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003253 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003254 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003255 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3256 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3257 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003258 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003259 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003260 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003261 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003262 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3263 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003264 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003265 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3266 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003267 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003268 .ppu_enable = mv88e6185_g1_ppu_enable,
3269 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003270 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003271};
3272
3273static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003274 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003275 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003276 .phy_read = mv88e6xxx_read,
3277 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003278 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003279 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003280 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003281 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003282 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3283 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3284 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003285 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003286 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003287 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003288 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003289 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3290 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003291 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003292 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3293 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003294 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003295 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003296};
3297
3298static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003299 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003300 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003301 .phy_read = mv88e6xxx_read,
3302 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003303 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003304 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003305 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003306 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003307 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3308 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003309 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003310 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3311 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003312 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003313 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003314};
3315
3316static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003317 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003318 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003319 .phy_read = mv88e6xxx_g2_smi_phy_read,
3320 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003321 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003322 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003323 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003324 .port_set_speed = mv88e6185_port_set_speed,
Andrew 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 = mv88e6320_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 mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003343 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003344 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3345 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003346 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003347 .phy_read = mv88e6xxx_g2_smi_phy_read,
3348 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003349 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003350 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003351 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003352 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003353 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003354 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3355 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3356 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003357 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003358 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003359 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003360 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003361 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3362 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003363 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003364 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3365 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003366 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003367 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003368};
3369
3370static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003371 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003372 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003373 .phy_read = mv88e6xxx_g2_smi_phy_read,
3374 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003375 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003376 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003377 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003378 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003379 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003380 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3381 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3382 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003383 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003384 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003385 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003386 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003387 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3388 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003389 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003390 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3391 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003392 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003393 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003394};
3395
3396static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003397 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003398 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3399 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003400 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003401 .phy_read = mv88e6xxx_g2_smi_phy_read,
3402 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003403 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003404 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003405 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003406 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003407 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003408 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3409 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3410 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003411 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003412 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003413 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003414 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003415 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3416 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003417 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003418 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3419 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003420 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003421 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003422};
3423
3424static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003425 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003426 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003427 .phy_read = mv88e6xxx_phy_ppu_read,
3428 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003429 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003430 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003431 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003432 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3433 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003434 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003435 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003436 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3437 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003438 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003439 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3440 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003441 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003442 .ppu_enable = mv88e6185_g1_ppu_enable,
3443 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003444 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003445};
3446
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003447static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003448 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003449 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3450 .phy_read = mv88e6xxx_g2_smi_phy_read,
3451 .phy_write = mv88e6xxx_g2_smi_phy_write,
3452 .port_set_link = mv88e6xxx_port_set_link,
3453 .port_set_duplex = mv88e6xxx_port_set_duplex,
3454 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3455 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003456 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003457 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3458 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3459 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003460 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003461 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003462 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003463 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3464 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003465 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003466 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3467 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003468 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003469 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003470};
3471
3472static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003473 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003474 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3475 .phy_read = mv88e6xxx_g2_smi_phy_read,
3476 .phy_write = mv88e6xxx_g2_smi_phy_write,
3477 .port_set_link = mv88e6xxx_port_set_link,
3478 .port_set_duplex = mv88e6xxx_port_set_duplex,
3479 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3480 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003481 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003482 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3483 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3484 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003485 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003486 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003487 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003488 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3489 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003490 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003491 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3492 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003493 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003494 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003495};
3496
3497static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003498 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003499 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3500 .phy_read = mv88e6xxx_g2_smi_phy_read,
3501 .phy_write = mv88e6xxx_g2_smi_phy_write,
3502 .port_set_link = mv88e6xxx_port_set_link,
3503 .port_set_duplex = mv88e6xxx_port_set_duplex,
3504 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3505 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003506 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003507 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3508 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3509 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003510 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003511 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003512 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003513 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3514 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003515 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003516 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3517 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003518 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003519 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003520};
3521
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003522static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003523 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003524 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3525 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003526 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003527 .phy_read = mv88e6xxx_g2_smi_phy_read,
3528 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003529 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003530 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003531 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003532 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003533 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003534 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3535 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3536 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003537 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003538 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003539 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003540 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003541 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3542 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003543 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003544 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3545 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003546 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003547 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003548};
3549
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003550static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003551 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003552 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3553 .phy_read = mv88e6xxx_g2_smi_phy_read,
3554 .phy_write = mv88e6xxx_g2_smi_phy_write,
3555 .port_set_link = mv88e6xxx_port_set_link,
3556 .port_set_duplex = mv88e6xxx_port_set_duplex,
3557 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3558 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003559 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003560 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3561 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3562 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003563 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003564 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003565 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003566 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3567 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003568 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003569 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3570 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003571 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003572 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003573};
3574
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003575static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003576 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003577 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3578 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003579 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003580 .phy_read = mv88e6xxx_g2_smi_phy_read,
3581 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003582 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003583 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003584 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003585 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003586 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3587 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3588 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003589 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003590 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003591 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003592 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003593 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3594 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003595 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003596 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3597 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003598 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003599 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003600};
3601
3602static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003603 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003604 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3605 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003606 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003607 .phy_read = mv88e6xxx_g2_smi_phy_read,
3608 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003609 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003610 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003611 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003612 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003613 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3614 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3615 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003616 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003617 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003618 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003619 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003620 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3621 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003622 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003623 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3624 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003625 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003626};
3627
3628static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003629 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003630 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003631 .phy_read = mv88e6xxx_g2_smi_phy_read,
3632 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003633 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003634 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003635 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003636 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003637 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003638 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3639 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3640 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003641 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003642 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003643 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003644 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003645 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3646 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003647 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003648 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3649 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003650 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003651 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003652};
3653
3654static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003655 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003656 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003657 .phy_read = mv88e6xxx_g2_smi_phy_read,
3658 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003659 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003660 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003661 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003662 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003663 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003664 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3665 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3666 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003667 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003668 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003669 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003670 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003671 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3672 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003673 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003674 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3675 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003676 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003677 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003678};
3679
3680static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003681 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003682 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3683 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003684 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003685 .phy_read = mv88e6xxx_g2_smi_phy_read,
3686 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003687 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003688 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003689 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003690 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003691 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003692 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3693 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3694 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003695 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003696 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003697 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003698 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003699 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3700 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003701 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003702 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3703 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003704 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003705 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003706};
3707
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003708static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003709 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003710 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3711 .phy_read = mv88e6xxx_g2_smi_phy_read,
3712 .phy_write = mv88e6xxx_g2_smi_phy_write,
3713 .port_set_link = mv88e6xxx_port_set_link,
3714 .port_set_duplex = mv88e6xxx_port_set_duplex,
3715 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3716 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003717 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003718 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3719 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3720 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003721 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003722 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003723 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003724 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003725 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003726 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3727 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003728 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003729 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3730 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003731 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003732 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003733};
3734
3735static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003736 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003737 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3738 .phy_read = mv88e6xxx_g2_smi_phy_read,
3739 .phy_write = mv88e6xxx_g2_smi_phy_write,
3740 .port_set_link = mv88e6xxx_port_set_link,
3741 .port_set_duplex = mv88e6xxx_port_set_duplex,
3742 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3743 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003744 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003745 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3746 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3747 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003748 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003749 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003750 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003751 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003752 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003753 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3754 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003755 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003756 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3757 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003758 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003759 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003760};
3761
3762static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003763 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003764 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3765 .phy_read = mv88e6xxx_g2_smi_phy_read,
3766 .phy_write = mv88e6xxx_g2_smi_phy_write,
3767 .port_set_link = mv88e6xxx_port_set_link,
3768 .port_set_duplex = mv88e6xxx_port_set_duplex,
3769 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3770 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003771 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003772 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3773 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3774 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003775 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003776 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003777 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003778 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3779 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003780 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003781 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3782 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003783 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003784 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003785};
3786
Andrew Lunn56995cb2016-12-03 04:35:19 +01003787static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3788 const struct mv88e6xxx_ops *ops)
3789{
3790 if (!ops->port_set_frame_mode) {
3791 dev_err(chip->dev, "Missing port_set_frame_mode");
3792 return -EINVAL;
3793 }
3794
3795 if (!ops->port_set_egress_unknowns) {
3796 dev_err(chip->dev, "Missing port_set_egress_mode");
3797 return -EINVAL;
3798 }
3799
3800 return 0;
3801}
3802
Vivien Didelotf81ec902016-05-09 13:22:58 -04003803static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3804 [MV88E6085] = {
3805 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3806 .family = MV88E6XXX_FAMILY_6097,
3807 .name = "Marvell 88E6085",
3808 .num_databases = 4096,
3809 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003810 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003811 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003812 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003813 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003814 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003815 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003816 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003817 },
3818
3819 [MV88E6095] = {
3820 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3821 .family = MV88E6XXX_FAMILY_6095,
3822 .name = "Marvell 88E6095/88E6095F",
3823 .num_databases = 256,
3824 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003825 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003826 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003827 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003828 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003829 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003830 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003831 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003832 },
3833
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003834 [MV88E6097] = {
3835 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3836 .family = MV88E6XXX_FAMILY_6097,
3837 .name = "Marvell 88E6097/88E6097F",
3838 .num_databases = 4096,
3839 .num_ports = 11,
3840 .port_base_addr = 0x10,
3841 .global1_addr = 0x1b,
3842 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003843 .g1_irqs = 8,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003844 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003845 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3846 .ops = &mv88e6097_ops,
3847 },
3848
Vivien Didelotf81ec902016-05-09 13:22:58 -04003849 [MV88E6123] = {
3850 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3851 .family = MV88E6XXX_FAMILY_6165,
3852 .name = "Marvell 88E6123",
3853 .num_databases = 4096,
3854 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003855 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003856 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003857 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003858 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003859 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003860 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003861 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003862 },
3863
3864 [MV88E6131] = {
3865 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3866 .family = MV88E6XXX_FAMILY_6185,
3867 .name = "Marvell 88E6131",
3868 .num_databases = 256,
3869 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003870 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003871 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003872 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003873 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003874 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003875 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003876 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003877 },
3878
3879 [MV88E6161] = {
3880 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3881 .family = MV88E6XXX_FAMILY_6165,
3882 .name = "Marvell 88E6161",
3883 .num_databases = 4096,
3884 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003885 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003886 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003887 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003888 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003889 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003890 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003891 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003892 },
3893
3894 [MV88E6165] = {
3895 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3896 .family = MV88E6XXX_FAMILY_6165,
3897 .name = "Marvell 88E6165",
3898 .num_databases = 4096,
3899 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003900 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003901 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003902 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003903 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003904 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003905 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003906 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003907 },
3908
3909 [MV88E6171] = {
3910 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3911 .family = MV88E6XXX_FAMILY_6351,
3912 .name = "Marvell 88E6171",
3913 .num_databases = 4096,
3914 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003915 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003916 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003917 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003918 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003919 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003920 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003921 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003922 },
3923
3924 [MV88E6172] = {
3925 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3926 .family = MV88E6XXX_FAMILY_6352,
3927 .name = "Marvell 88E6172",
3928 .num_databases = 4096,
3929 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003930 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003931 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003932 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003933 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003934 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003935 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003936 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003937 },
3938
3939 [MV88E6175] = {
3940 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3941 .family = MV88E6XXX_FAMILY_6351,
3942 .name = "Marvell 88E6175",
3943 .num_databases = 4096,
3944 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003945 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003946 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003947 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003948 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003949 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003950 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003951 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003952 },
3953
3954 [MV88E6176] = {
3955 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3956 .family = MV88E6XXX_FAMILY_6352,
3957 .name = "Marvell 88E6176",
3958 .num_databases = 4096,
3959 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003960 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003961 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003962 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003963 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003964 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003965 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003966 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003967 },
3968
3969 [MV88E6185] = {
3970 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3971 .family = MV88E6XXX_FAMILY_6185,
3972 .name = "Marvell 88E6185",
3973 .num_databases = 256,
3974 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003975 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003976 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003977 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003978 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003979 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003980 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003981 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003982 },
3983
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003984 [MV88E6190] = {
3985 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3986 .family = MV88E6XXX_FAMILY_6390,
3987 .name = "Marvell 88E6190",
3988 .num_databases = 4096,
3989 .num_ports = 11, /* 10 + Z80 */
3990 .port_base_addr = 0x0,
3991 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003992 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003993 .age_time_coeff = 15000,
3994 .g1_irqs = 9,
3995 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
3996 .ops = &mv88e6190_ops,
3997 },
3998
3999 [MV88E6190X] = {
4000 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
4001 .family = MV88E6XXX_FAMILY_6390,
4002 .name = "Marvell 88E6190X",
4003 .num_databases = 4096,
4004 .num_ports = 11, /* 10 + Z80 */
4005 .port_base_addr = 0x0,
4006 .global1_addr = 0x1b,
4007 .age_time_coeff = 15000,
4008 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004009 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004010 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4011 .ops = &mv88e6190x_ops,
4012 },
4013
4014 [MV88E6191] = {
4015 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
4016 .family = MV88E6XXX_FAMILY_6390,
4017 .name = "Marvell 88E6191",
4018 .num_databases = 4096,
4019 .num_ports = 11, /* 10 + Z80 */
4020 .port_base_addr = 0x0,
4021 .global1_addr = 0x1b,
4022 .age_time_coeff = 15000,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004023 .g1_irqs = 9,
4024 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004025 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4026 .ops = &mv88e6391_ops,
4027 },
4028
Vivien Didelotf81ec902016-05-09 13:22:58 -04004029 [MV88E6240] = {
4030 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
4031 .family = MV88E6XXX_FAMILY_6352,
4032 .name = "Marvell 88E6240",
4033 .num_databases = 4096,
4034 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004035 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004036 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004037 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004038 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004039 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004040 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004041 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004042 },
4043
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004044 [MV88E6290] = {
4045 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
4046 .family = MV88E6XXX_FAMILY_6390,
4047 .name = "Marvell 88E6290",
4048 .num_databases = 4096,
4049 .num_ports = 11, /* 10 + Z80 */
4050 .port_base_addr = 0x0,
4051 .global1_addr = 0x1b,
4052 .age_time_coeff = 15000,
4053 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004054 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004055 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4056 .ops = &mv88e6290_ops,
4057 },
4058
Vivien Didelotf81ec902016-05-09 13:22:58 -04004059 [MV88E6320] = {
4060 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
4061 .family = MV88E6XXX_FAMILY_6320,
4062 .name = "Marvell 88E6320",
4063 .num_databases = 4096,
4064 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004065 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004066 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004067 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004068 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004069 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004070 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004071 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004072 },
4073
4074 [MV88E6321] = {
4075 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
4076 .family = MV88E6XXX_FAMILY_6320,
4077 .name = "Marvell 88E6321",
4078 .num_databases = 4096,
4079 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004080 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004081 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004082 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004083 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004084 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004085 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004086 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004087 },
4088
4089 [MV88E6350] = {
4090 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
4091 .family = MV88E6XXX_FAMILY_6351,
4092 .name = "Marvell 88E6350",
4093 .num_databases = 4096,
4094 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004095 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004096 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004097 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004098 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004099 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004100 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004101 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004102 },
4103
4104 [MV88E6351] = {
4105 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4106 .family = MV88E6XXX_FAMILY_6351,
4107 .name = "Marvell 88E6351",
4108 .num_databases = 4096,
4109 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004110 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004111 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004112 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004113 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004114 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004115 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004116 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004117 },
4118
4119 [MV88E6352] = {
4120 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4121 .family = MV88E6XXX_FAMILY_6352,
4122 .name = "Marvell 88E6352",
4123 .num_databases = 4096,
4124 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004125 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004126 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004127 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004128 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004129 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004130 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004131 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004132 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004133 [MV88E6390] = {
4134 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4135 .family = MV88E6XXX_FAMILY_6390,
4136 .name = "Marvell 88E6390",
4137 .num_databases = 4096,
4138 .num_ports = 11, /* 10 + Z80 */
4139 .port_base_addr = 0x0,
4140 .global1_addr = 0x1b,
4141 .age_time_coeff = 15000,
4142 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004143 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004144 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4145 .ops = &mv88e6390_ops,
4146 },
4147 [MV88E6390X] = {
4148 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4149 .family = MV88E6XXX_FAMILY_6390,
4150 .name = "Marvell 88E6390X",
4151 .num_databases = 4096,
4152 .num_ports = 11, /* 10 + Z80 */
4153 .port_base_addr = 0x0,
4154 .global1_addr = 0x1b,
4155 .age_time_coeff = 15000,
4156 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004157 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004158 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4159 .ops = &mv88e6390x_ops,
4160 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004161};
4162
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004163static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004164{
Vivien Didelota439c062016-04-17 13:23:58 -04004165 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004166
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004167 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4168 if (mv88e6xxx_table[i].prod_num == prod_num)
4169 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004170
Vivien Didelotb9b37712015-10-30 19:39:48 -04004171 return NULL;
4172}
4173
Vivien Didelotfad09c72016-06-21 12:28:20 -04004174static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004175{
4176 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004177 unsigned int prod_num, rev;
4178 u16 id;
4179 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004180
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004181 mutex_lock(&chip->reg_lock);
4182 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4183 mutex_unlock(&chip->reg_lock);
4184 if (err)
4185 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004186
4187 prod_num = (id & 0xfff0) >> 4;
4188 rev = id & 0x000f;
4189
4190 info = mv88e6xxx_lookup_info(prod_num);
4191 if (!info)
4192 return -ENODEV;
4193
Vivien Didelotcaac8542016-06-20 13:14:09 -04004194 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004195 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004196
Vivien Didelotca070c12016-09-02 14:45:34 -04004197 err = mv88e6xxx_g2_require(chip);
4198 if (err)
4199 return err;
4200
Vivien Didelotfad09c72016-06-21 12:28:20 -04004201 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4202 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004203
4204 return 0;
4205}
4206
Vivien Didelotfad09c72016-06-21 12:28:20 -04004207static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004208{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004209 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004210
Vivien Didelotfad09c72016-06-21 12:28:20 -04004211 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4212 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004213 return NULL;
4214
Vivien Didelotfad09c72016-06-21 12:28:20 -04004215 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004216
Vivien Didelotfad09c72016-06-21 12:28:20 -04004217 mutex_init(&chip->reg_lock);
Vivien Didelot469d7292016-06-20 13:14:06 -04004218
Vivien Didelotfad09c72016-06-21 12:28:20 -04004219 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004220}
4221
Vivien Didelote57e5e72016-08-15 17:19:00 -04004222static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4223{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004224 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004225 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004226}
4227
Andrew Lunn930188c2016-08-22 16:01:03 +02004228static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4229{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004230 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004231 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004232}
4233
Vivien Didelotfad09c72016-06-21 12:28:20 -04004234static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004235 struct mii_bus *bus, int sw_addr)
4236{
4237 /* ADDR[0] pin is unavailable externally and considered zero */
4238 if (sw_addr & 0x1)
4239 return -EINVAL;
4240
Vivien Didelot914b32f2016-06-20 13:14:11 -04004241 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004242 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004243 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004244 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004245 else
4246 return -EINVAL;
4247
Vivien Didelotfad09c72016-06-21 12:28:20 -04004248 chip->bus = bus;
4249 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004250
4251 return 0;
4252}
4253
Andrew Lunn7b314362016-08-22 16:01:01 +02004254static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4255{
Vivien Didelot04bed142016-08-31 18:06:13 -04004256 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004257
Andrew Lunn443d5a12016-12-03 04:35:18 +01004258 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004259}
4260
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004261static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4262 struct device *host_dev, int sw_addr,
4263 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004264{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004265 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004266 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004267 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004268
Vivien Didelota439c062016-04-17 13:23:58 -04004269 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004270 if (!bus)
4271 return NULL;
4272
Vivien Didelotfad09c72016-06-21 12:28:20 -04004273 chip = mv88e6xxx_alloc_chip(dsa_dev);
4274 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004275 return NULL;
4276
Vivien Didelotcaac8542016-06-20 13:14:09 -04004277 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004278 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004279
Vivien Didelotfad09c72016-06-21 12:28:20 -04004280 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004281 if (err)
4282 goto free;
4283
Vivien Didelotfad09c72016-06-21 12:28:20 -04004284 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004285 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004286 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004287
Andrew Lunndc30c352016-10-16 19:56:49 +02004288 mutex_lock(&chip->reg_lock);
4289 err = mv88e6xxx_switch_reset(chip);
4290 mutex_unlock(&chip->reg_lock);
4291 if (err)
4292 goto free;
4293
Vivien Didelote57e5e72016-08-15 17:19:00 -04004294 mv88e6xxx_phy_init(chip);
4295
Vivien Didelotfad09c72016-06-21 12:28:20 -04004296 err = mv88e6xxx_mdio_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004297 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004298 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004299
Vivien Didelotfad09c72016-06-21 12:28:20 -04004300 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004301
Vivien Didelotfad09c72016-06-21 12:28:20 -04004302 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004303free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004304 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004305
4306 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004307}
4308
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004309static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4310 const struct switchdev_obj_port_mdb *mdb,
4311 struct switchdev_trans *trans)
4312{
4313 /* We don't need any dynamic resource from the kernel (yet),
4314 * so skip the prepare phase.
4315 */
4316
4317 return 0;
4318}
4319
4320static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4321 const struct switchdev_obj_port_mdb *mdb,
4322 struct switchdev_trans *trans)
4323{
Vivien Didelot04bed142016-08-31 18:06:13 -04004324 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004325
4326 mutex_lock(&chip->reg_lock);
4327 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4328 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4329 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4330 mutex_unlock(&chip->reg_lock);
4331}
4332
4333static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4334 const struct switchdev_obj_port_mdb *mdb)
4335{
Vivien Didelot04bed142016-08-31 18:06:13 -04004336 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004337 int err;
4338
4339 mutex_lock(&chip->reg_lock);
4340 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4341 GLOBAL_ATU_DATA_STATE_UNUSED);
4342 mutex_unlock(&chip->reg_lock);
4343
4344 return err;
4345}
4346
4347static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4348 struct switchdev_obj_port_mdb *mdb,
4349 int (*cb)(struct switchdev_obj *obj))
4350{
Vivien Didelot04bed142016-08-31 18:06:13 -04004351 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004352 int err;
4353
4354 mutex_lock(&chip->reg_lock);
4355 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4356 mutex_unlock(&chip->reg_lock);
4357
4358 return err;
4359}
4360
Vivien Didelot9d490b42016-08-23 12:38:56 -04004361static struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004362 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004363 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004364 .setup = mv88e6xxx_setup,
4365 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004366 .adjust_link = mv88e6xxx_adjust_link,
4367 .get_strings = mv88e6xxx_get_strings,
4368 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4369 .get_sset_count = mv88e6xxx_get_sset_count,
4370 .set_eee = mv88e6xxx_set_eee,
4371 .get_eee = mv88e6xxx_get_eee,
4372#ifdef CONFIG_NET_DSA_HWMON
4373 .get_temp = mv88e6xxx_get_temp,
4374 .get_temp_limit = mv88e6xxx_get_temp_limit,
4375 .set_temp_limit = mv88e6xxx_set_temp_limit,
4376 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
4377#endif
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004378 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004379 .get_eeprom = mv88e6xxx_get_eeprom,
4380 .set_eeprom = mv88e6xxx_set_eeprom,
4381 .get_regs_len = mv88e6xxx_get_regs_len,
4382 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004383 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004384 .port_bridge_join = mv88e6xxx_port_bridge_join,
4385 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4386 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004387 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004388 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4389 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4390 .port_vlan_add = mv88e6xxx_port_vlan_add,
4391 .port_vlan_del = mv88e6xxx_port_vlan_del,
4392 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4393 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4394 .port_fdb_add = mv88e6xxx_port_fdb_add,
4395 .port_fdb_del = mv88e6xxx_port_fdb_del,
4396 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004397 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4398 .port_mdb_add = mv88e6xxx_port_mdb_add,
4399 .port_mdb_del = mv88e6xxx_port_mdb_del,
4400 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004401};
4402
Vivien Didelotfad09c72016-06-21 12:28:20 -04004403static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004404 struct device_node *np)
4405{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004406 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004407 struct dsa_switch *ds;
4408
4409 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
4410 if (!ds)
4411 return -ENOMEM;
4412
4413 ds->dev = dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004414 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004415 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004416
4417 dev_set_drvdata(dev, ds);
4418
4419 return dsa_register_switch(ds, np);
4420}
4421
Vivien Didelotfad09c72016-06-21 12:28:20 -04004422static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004423{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004424 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004425}
4426
Vivien Didelot57d32312016-06-20 13:13:58 -04004427static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004428{
4429 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004430 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004431 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004432 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004433 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004434 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004435
Vivien Didelotcaac8542016-06-20 13:14:09 -04004436 compat_info = of_device_get_match_data(dev);
4437 if (!compat_info)
4438 return -EINVAL;
4439
Vivien Didelotfad09c72016-06-21 12:28:20 -04004440 chip = mv88e6xxx_alloc_chip(dev);
4441 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004442 return -ENOMEM;
4443
Vivien Didelotfad09c72016-06-21 12:28:20 -04004444 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004445
Andrew Lunn56995cb2016-12-03 04:35:19 +01004446 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4447 if (err)
4448 return err;
4449
Vivien Didelotfad09c72016-06-21 12:28:20 -04004450 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004451 if (err)
4452 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004453
Andrew Lunnb4308f02016-11-21 23:26:55 +01004454 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4455 if (IS_ERR(chip->reset))
4456 return PTR_ERR(chip->reset);
4457
Vivien Didelotfad09c72016-06-21 12:28:20 -04004458 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004459 if (err)
4460 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004461
Vivien Didelote57e5e72016-08-15 17:19:00 -04004462 mv88e6xxx_phy_init(chip);
4463
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004464 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004465 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004466 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004467
Andrew Lunndc30c352016-10-16 19:56:49 +02004468 mutex_lock(&chip->reg_lock);
4469 err = mv88e6xxx_switch_reset(chip);
4470 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004471 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004472 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004473
Andrew Lunndc30c352016-10-16 19:56:49 +02004474 chip->irq = of_irq_get(np, 0);
4475 if (chip->irq == -EPROBE_DEFER) {
4476 err = chip->irq;
4477 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004478 }
4479
Andrew Lunndc30c352016-10-16 19:56:49 +02004480 if (chip->irq > 0) {
4481 /* Has to be performed before the MDIO bus is created,
4482 * because the PHYs will link there interrupts to these
4483 * interrupt controllers
4484 */
4485 mutex_lock(&chip->reg_lock);
4486 err = mv88e6xxx_g1_irq_setup(chip);
4487 mutex_unlock(&chip->reg_lock);
4488
4489 if (err)
4490 goto out;
4491
4492 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4493 err = mv88e6xxx_g2_irq_setup(chip);
4494 if (err)
4495 goto out_g1_irq;
4496 }
4497 }
4498
4499 err = mv88e6xxx_mdio_register(chip, np);
4500 if (err)
4501 goto out_g2_irq;
4502
4503 err = mv88e6xxx_register_switch(chip, np);
4504 if (err)
4505 goto out_mdio;
4506
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004507 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004508
4509out_mdio:
4510 mv88e6xxx_mdio_unregister(chip);
4511out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004512 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004513 mv88e6xxx_g2_irq_free(chip);
4514out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004515 if (chip->irq > 0) {
4516 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004517 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004518 mutex_unlock(&chip->reg_lock);
4519 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004520out:
4521 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004522}
4523
4524static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4525{
4526 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004527 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004528
Andrew Lunn930188c2016-08-22 16:01:03 +02004529 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004530 mv88e6xxx_unregister_switch(chip);
4531 mv88e6xxx_mdio_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004532
Andrew Lunn467126442016-11-20 20:14:15 +01004533 if (chip->irq > 0) {
4534 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4535 mv88e6xxx_g2_irq_free(chip);
4536 mv88e6xxx_g1_irq_free(chip);
4537 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004538}
4539
4540static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004541 {
4542 .compatible = "marvell,mv88e6085",
4543 .data = &mv88e6xxx_table[MV88E6085],
4544 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004545 {
4546 .compatible = "marvell,mv88e6190",
4547 .data = &mv88e6xxx_table[MV88E6190],
4548 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004549 { /* sentinel */ },
4550};
4551
4552MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4553
4554static struct mdio_driver mv88e6xxx_driver = {
4555 .probe = mv88e6xxx_probe,
4556 .remove = mv88e6xxx_remove,
4557 .mdiodrv.driver = {
4558 .name = "mv88e6085",
4559 .of_match_table = mv88e6xxx_of_match,
4560 },
4561};
4562
Ben Hutchings98e67302011-11-25 14:36:19 +00004563static int __init mv88e6xxx_init(void)
4564{
Vivien Didelot9d490b42016-08-23 12:38:56 -04004565 register_switch_driver(&mv88e6xxx_switch_ops);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004566 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004567}
4568module_init(mv88e6xxx_init);
4569
4570static void __exit mv88e6xxx_cleanup(void)
4571{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004572 mdio_driver_unregister(&mv88e6xxx_driver);
Vivien Didelot9d490b42016-08-23 12:38:56 -04004573 unregister_switch_driver(&mv88e6xxx_switch_ops);
Ben Hutchings98e67302011-11-25 14:36:19 +00004574}
4575module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004576
4577MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4578MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4579MODULE_LICENSE("GPL");