blob: 3ddb1f79e7094d69a1be7dfa3563cdf1872487fc [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04002 * Marvell 88e6xxx Ethernet switch single-chip support
3 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 * Copyright (c) 2008 Marvell Semiconductor
5 *
Vivien Didelotb8fee952015-08-13 12:52:19 -04006 * Copyright (c) 2015 CMC Electronics, Inc.
7 * Added support for VLAN Table Unit operations
8 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02009 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
10 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
Barry Grussling19b2f972013-01-08 16:05:54 +000017#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070018#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020019#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070020#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020021#include <linux/interrupt.h>
22#include <linux/irq.h>
23#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000024#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000025#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020026#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000027#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040028#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020029#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020030#include <linux/of_mdio.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000031#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010032#include <linux/gpio/consumer.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000033#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000034#include <net/dsa.h>
Vivien Didelot1f36faf2015-10-08 11:35:13 -040035#include <net/switchdev.h>
Vivien Didelotec561272016-09-02 14:45:33 -040036
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000037#include "mv88e6xxx.h"
Vivien Didelota935c052016-09-29 12:21:53 -040038#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040039#include "global2.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010040#include "port.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000041
Vivien Didelotfad09c72016-06-21 12:28:20 -040042static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040043{
Vivien Didelotfad09c72016-06-21 12:28:20 -040044 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
45 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040046 dump_stack();
47 }
48}
49
Vivien Didelot914b32f2016-06-20 13:14:11 -040050/* The switch ADDR[4:1] configuration pins define the chip SMI device address
51 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
52 *
53 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
54 * is the only device connected to the SMI master. In this mode it responds to
55 * all 32 possible SMI addresses, and thus maps directly the internal devices.
56 *
57 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
58 * multiple devices to share the SMI interface. In this mode it responds to only
59 * 2 registers, used to indirectly access the internal SMI devices.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000060 */
Vivien Didelot914b32f2016-06-20 13:14:11 -040061
Vivien Didelotfad09c72016-06-21 12:28:20 -040062static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040063 int addr, int reg, u16 *val)
64{
Vivien Didelotfad09c72016-06-21 12:28:20 -040065 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040066 return -EOPNOTSUPP;
67
Vivien Didelotfad09c72016-06-21 12:28:20 -040068 return chip->smi_ops->read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040069}
70
Vivien Didelotfad09c72016-06-21 12:28:20 -040071static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040072 int addr, int reg, u16 val)
73{
Vivien Didelotfad09c72016-06-21 12:28:20 -040074 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040075 return -EOPNOTSUPP;
76
Vivien Didelotfad09c72016-06-21 12:28:20 -040077 return chip->smi_ops->write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040078}
79
Vivien Didelotfad09c72016-06-21 12:28:20 -040080static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040081 int addr, int reg, u16 *val)
82{
83 int ret;
84
Vivien Didelotfad09c72016-06-21 12:28:20 -040085 ret = mdiobus_read_nested(chip->bus, addr, reg);
Vivien Didelot914b32f2016-06-20 13:14:11 -040086 if (ret < 0)
87 return ret;
88
89 *val = ret & 0xffff;
90
91 return 0;
92}
93
Vivien Didelotfad09c72016-06-21 12:28:20 -040094static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040095 int addr, int reg, u16 val)
96{
97 int ret;
98
Vivien Didelotfad09c72016-06-21 12:28:20 -040099 ret = mdiobus_write_nested(chip->bus, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400100 if (ret < 0)
101 return ret;
102
103 return 0;
104}
105
Vivien Didelotc08026a2016-09-29 12:21:59 -0400106static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400107 .read = mv88e6xxx_smi_single_chip_read,
108 .write = mv88e6xxx_smi_single_chip_write,
109};
110
Vivien Didelotfad09c72016-06-21 12:28:20 -0400111static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000112{
113 int ret;
114 int i;
115
116 for (i = 0; i < 16; i++) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400117 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000118 if (ret < 0)
119 return ret;
120
Andrew Lunncca8b132015-04-02 04:06:39 +0200121 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000122 return 0;
123 }
124
125 return -ETIMEDOUT;
126}
127
Vivien Didelotfad09c72016-06-21 12:28:20 -0400128static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400129 int addr, int reg, u16 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000130{
131 int ret;
132
Barry Grussling3675c8d2013-01-08 16:05:53 +0000133 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400134 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000135 if (ret < 0)
136 return ret;
137
Barry Grussling3675c8d2013-01-08 16:05:53 +0000138 /* Transmit the read command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400139 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Neil Armstrong6e899e62015-10-22 10:37:53 +0200140 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000141 if (ret < 0)
142 return ret;
143
Barry Grussling3675c8d2013-01-08 16:05:53 +0000144 /* Wait for the read command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400145 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000146 if (ret < 0)
147 return ret;
148
Barry Grussling3675c8d2013-01-08 16:05:53 +0000149 /* Read the data. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400150 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000151 if (ret < 0)
152 return ret;
153
Vivien Didelot914b32f2016-06-20 13:14:11 -0400154 *val = ret & 0xffff;
155
156 return 0;
157}
158
Vivien Didelotfad09c72016-06-21 12:28:20 -0400159static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400160 int addr, int reg, u16 val)
161{
162 int ret;
163
164 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400165 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400166 if (ret < 0)
167 return ret;
168
169 /* Transmit the data to write. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400170 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400171 if (ret < 0)
172 return ret;
173
174 /* Transmit the write command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400175 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400176 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
177 if (ret < 0)
178 return ret;
179
180 /* Wait for the write command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400181 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400182 if (ret < 0)
183 return ret;
184
185 return 0;
186}
187
Vivien Didelotc08026a2016-09-29 12:21:59 -0400188static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400189 .read = mv88e6xxx_smi_multi_chip_read,
190 .write = mv88e6xxx_smi_multi_chip_write,
191};
192
Vivien Didelotec561272016-09-02 14:45:33 -0400193int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400194{
195 int err;
196
Vivien Didelotfad09c72016-06-21 12:28:20 -0400197 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400198
Vivien Didelotfad09c72016-06-21 12:28:20 -0400199 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400200 if (err)
201 return err;
202
Vivien Didelotfad09c72016-06-21 12:28:20 -0400203 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400204 addr, reg, *val);
205
206 return 0;
207}
208
Vivien Didelotec561272016-09-02 14:45:33 -0400209int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400210{
211 int err;
212
Vivien Didelotfad09c72016-06-21 12:28:20 -0400213 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400214
Vivien Didelotfad09c72016-06-21 12:28:20 -0400215 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400216 if (err)
217 return err;
218
Vivien Didelotfad09c72016-06-21 12:28:20 -0400219 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400220 addr, reg, val);
221
222 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000223}
224
Vivien Didelote57e5e72016-08-15 17:19:00 -0400225static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
226 int reg, u16 *val)
227{
228 int addr = phy; /* PHY devices addresses start at 0x0 */
229
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400230 if (!chip->info->ops->phy_read)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400231 return -EOPNOTSUPP;
232
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400233 return chip->info->ops->phy_read(chip, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400234}
235
236static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
237 int reg, u16 val)
238{
239 int addr = phy; /* PHY devices addresses start at 0x0 */
240
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400241 if (!chip->info->ops->phy_write)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400242 return -EOPNOTSUPP;
243
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400244 return chip->info->ops->phy_write(chip, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400245}
246
Vivien Didelot09cb7df2016-08-15 17:19:01 -0400247static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
248{
249 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_PHY_PAGE))
250 return -EOPNOTSUPP;
251
252 return mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
253}
254
255static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip *chip, int phy)
256{
257 int err;
258
259 /* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
260 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, PHY_PAGE_COPPER);
261 if (unlikely(err)) {
262 dev_err(chip->dev, "failed to restore PHY %d page Copper (%d)\n",
263 phy, err);
264 }
265}
266
267static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy,
268 u8 page, int reg, u16 *val)
269{
270 int err;
271
272 /* There is no paging for registers 22 */
273 if (reg == PHY_PAGE)
274 return -EINVAL;
275
276 err = mv88e6xxx_phy_page_get(chip, phy, page);
277 if (!err) {
278 err = mv88e6xxx_phy_read(chip, phy, reg, val);
279 mv88e6xxx_phy_page_put(chip, phy);
280 }
281
282 return err;
283}
284
285static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy,
286 u8 page, int reg, u16 val)
287{
288 int err;
289
290 /* There is no paging for registers 22 */
291 if (reg == PHY_PAGE)
292 return -EINVAL;
293
294 err = mv88e6xxx_phy_page_get(chip, phy, page);
295 if (!err) {
296 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
297 mv88e6xxx_phy_page_put(chip, phy);
298 }
299
300 return err;
301}
302
303static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
304{
305 return mv88e6xxx_phy_page_read(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
306 reg, val);
307}
308
309static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
310{
311 return mv88e6xxx_phy_page_write(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
312 reg, val);
313}
314
Andrew Lunndc30c352016-10-16 19:56:49 +0200315static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
316{
317 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
318 unsigned int n = d->hwirq;
319
320 chip->g1_irq.masked |= (1 << n);
321}
322
323static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
324{
325 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
326 unsigned int n = d->hwirq;
327
328 chip->g1_irq.masked &= ~(1 << n);
329}
330
331static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
332{
333 struct mv88e6xxx_chip *chip = dev_id;
334 unsigned int nhandled = 0;
335 unsigned int sub_irq;
336 unsigned int n;
337 u16 reg;
338 int err;
339
340 mutex_lock(&chip->reg_lock);
341 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
342 mutex_unlock(&chip->reg_lock);
343
344 if (err)
345 goto out;
346
347 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
348 if (reg & (1 << n)) {
349 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
350 handle_nested_irq(sub_irq);
351 ++nhandled;
352 }
353 }
354out:
355 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
356}
357
358static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
359{
360 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
361
362 mutex_lock(&chip->reg_lock);
363}
364
365static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
366{
367 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
368 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
369 u16 reg;
370 int err;
371
372 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
373 if (err)
374 goto out;
375
376 reg &= ~mask;
377 reg |= (~chip->g1_irq.masked & mask);
378
379 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
380 if (err)
381 goto out;
382
383out:
384 mutex_unlock(&chip->reg_lock);
385}
386
387static struct irq_chip mv88e6xxx_g1_irq_chip = {
388 .name = "mv88e6xxx-g1",
389 .irq_mask = mv88e6xxx_g1_irq_mask,
390 .irq_unmask = mv88e6xxx_g1_irq_unmask,
391 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
392 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
393};
394
395static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
396 unsigned int irq,
397 irq_hw_number_t hwirq)
398{
399 struct mv88e6xxx_chip *chip = d->host_data;
400
401 irq_set_chip_data(irq, d->host_data);
402 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
403 irq_set_noprobe(irq);
404
405 return 0;
406}
407
408static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
409 .map = mv88e6xxx_g1_irq_domain_map,
410 .xlate = irq_domain_xlate_twocell,
411};
412
413static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
414{
415 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100416 u16 mask;
417
418 mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
419 mask |= GENMASK(chip->g1_irq.nirqs, 0);
420 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
421
422 free_irq(chip->irq, chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200423
Andreas Färber5edef2f2016-11-27 23:26:28 +0100424 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100425 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200426 irq_dispose_mapping(virq);
427 }
428
Andrew Lunna3db3d32016-11-20 20:14:14 +0100429 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200430}
431
432static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
433{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100434 int err, irq, virq;
435 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200436
437 chip->g1_irq.nirqs = chip->info->g1_irqs;
438 chip->g1_irq.domain = irq_domain_add_simple(
439 NULL, chip->g1_irq.nirqs, 0,
440 &mv88e6xxx_g1_irq_domain_ops, chip);
441 if (!chip->g1_irq.domain)
442 return -ENOMEM;
443
444 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
445 irq_create_mapping(chip->g1_irq.domain, irq);
446
447 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
448 chip->g1_irq.masked = ~0;
449
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100450 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200451 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100452 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200453
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100454 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200455
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100456 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200457 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100458 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200459
460 /* Reading the interrupt status clears (most of) them */
461 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
462 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100463 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200464
465 err = request_threaded_irq(chip->irq, NULL,
466 mv88e6xxx_g1_irq_thread_fn,
467 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
468 dev_name(chip->dev), chip);
469 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100470 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200471
472 return 0;
473
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100474out_disable:
475 mask |= GENMASK(chip->g1_irq.nirqs, 0);
476 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
477
478out_mapping:
479 for (irq = 0; irq < 16; irq++) {
480 virq = irq_find_mapping(chip->g1_irq.domain, irq);
481 irq_dispose_mapping(virq);
482 }
483
484 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200485
486 return err;
487}
488
Vivien Didelotec561272016-09-02 14:45:33 -0400489int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400490{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200491 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400492
Andrew Lunn6441e6692016-08-19 00:01:55 +0200493 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400494 u16 val;
495 int err;
496
497 err = mv88e6xxx_read(chip, addr, reg, &val);
498 if (err)
499 return err;
500
501 if (!(val & mask))
502 return 0;
503
504 usleep_range(1000, 2000);
505 }
506
Andrew Lunn30853552016-08-19 00:01:57 +0200507 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400508 return -ETIMEDOUT;
509}
510
Vivien Didelotf22ab642016-07-18 20:45:31 -0400511/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400512int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400513{
514 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200515 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400516
517 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200518 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
519 if (err)
520 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400521
522 /* Set the Update bit to trigger a write operation */
523 val = BIT(15) | update;
524
525 return mv88e6xxx_write(chip, addr, reg, val);
526}
527
Vivien Didelota935c052016-09-29 12:21:53 -0400528static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000529{
Vivien Didelot914b32f2016-06-20 13:14:11 -0400530 u16 val;
Vivien Didelota935c052016-09-29 12:21:53 -0400531 int i, err;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000532
Vivien Didelota935c052016-09-29 12:21:53 -0400533 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400534 if (err)
535 return err;
Vivien Didelot3996a4f2015-10-30 18:56:45 -0400536
Vivien Didelota935c052016-09-29 12:21:53 -0400537 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL,
538 val & ~GLOBAL_CONTROL_PPU_ENABLE);
539 if (err)
540 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000541
Andrew Lunn6441e6692016-08-19 00:01:55 +0200542 for (i = 0; i < 16; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -0400543 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &val);
544 if (err)
545 return err;
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200546
Barry Grussling19b2f972013-01-08 16:05:54 +0000547 usleep_range(1000, 2000);
Vivien Didelota935c052016-09-29 12:21:53 -0400548 if ((val & GLOBAL_STATUS_PPU_MASK) != GLOBAL_STATUS_PPU_POLLING)
Barry Grussling85686582013-01-08 16:05:56 +0000549 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000550 }
551
552 return -ETIMEDOUT;
553}
554
Vivien Didelotfad09c72016-06-21 12:28:20 -0400555static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000556{
Vivien Didelota935c052016-09-29 12:21:53 -0400557 u16 val;
558 int i, err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000559
Vivien Didelota935c052016-09-29 12:21:53 -0400560 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &val);
561 if (err)
562 return err;
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200563
Vivien Didelota935c052016-09-29 12:21:53 -0400564 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL,
565 val | GLOBAL_CONTROL_PPU_ENABLE);
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200566 if (err)
567 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000568
Andrew Lunn6441e6692016-08-19 00:01:55 +0200569 for (i = 0; i < 16; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -0400570 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &val);
571 if (err)
572 return err;
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200573
Barry Grussling19b2f972013-01-08 16:05:54 +0000574 usleep_range(1000, 2000);
Vivien Didelota935c052016-09-29 12:21:53 -0400575 if ((val & GLOBAL_STATUS_PPU_MASK) == GLOBAL_STATUS_PPU_POLLING)
Barry Grussling85686582013-01-08 16:05:56 +0000576 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000577 }
578
579 return -ETIMEDOUT;
580}
581
582static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
583{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400584 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000585
Vivien Didelotfad09c72016-06-21 12:28:20 -0400586 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200587
Vivien Didelotfad09c72016-06-21 12:28:20 -0400588 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200589
Vivien Didelotfad09c72016-06-21 12:28:20 -0400590 if (mutex_trylock(&chip->ppu_mutex)) {
591 if (mv88e6xxx_ppu_enable(chip) == 0)
592 chip->ppu_disabled = 0;
593 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000594 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200595
Vivien Didelotfad09c72016-06-21 12:28:20 -0400596 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000597}
598
599static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
600{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400601 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000602
Vivien Didelotfad09c72016-06-21 12:28:20 -0400603 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000604}
605
Vivien Didelotfad09c72016-06-21 12:28:20 -0400606static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000607{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000608 int ret;
609
Vivien Didelotfad09c72016-06-21 12:28:20 -0400610 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000611
Barry Grussling3675c8d2013-01-08 16:05:53 +0000612 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000613 * we can access the PHY registers. If it was already
614 * disabled, cancel the timer that is going to re-enable
615 * it.
616 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400617 if (!chip->ppu_disabled) {
618 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000619 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400620 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000621 return ret;
622 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400623 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000624 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400625 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000626 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000627 }
628
629 return ret;
630}
631
Vivien Didelotfad09c72016-06-21 12:28:20 -0400632static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000633{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000634 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400635 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
636 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000637}
638
Vivien Didelotfad09c72016-06-21 12:28:20 -0400639static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000640{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400641 mutex_init(&chip->ppu_mutex);
642 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000643 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
644 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000645}
646
Andrew Lunn930188c2016-08-22 16:01:03 +0200647static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
648{
649 del_timer_sync(&chip->ppu_timer);
650}
651
Vivien Didelote57e5e72016-08-15 17:19:00 -0400652static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip, int addr,
653 int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000654{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400655 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000656
Vivien Didelote57e5e72016-08-15 17:19:00 -0400657 err = mv88e6xxx_ppu_access_get(chip);
658 if (!err) {
659 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400660 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000661 }
662
Vivien Didelote57e5e72016-08-15 17:19:00 -0400663 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000664}
665
Vivien Didelote57e5e72016-08-15 17:19:00 -0400666static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip, int addr,
667 int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000668{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400669 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000670
Vivien Didelote57e5e72016-08-15 17:19:00 -0400671 err = mv88e6xxx_ppu_access_get(chip);
672 if (!err) {
673 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400674 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000675 }
676
Vivien Didelote57e5e72016-08-15 17:19:00 -0400677 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000678}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000679
Vivien Didelotfad09c72016-06-21 12:28:20 -0400680static bool mv88e6xxx_6095_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200681{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400682 return chip->info->family == MV88E6XXX_FAMILY_6095;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200683}
684
Vivien Didelotfad09c72016-06-21 12:28:20 -0400685static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200686{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400687 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200688}
689
Vivien Didelotfad09c72016-06-21 12:28:20 -0400690static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200691{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400692 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200693}
694
Vivien Didelotfad09c72016-06-21 12:28:20 -0400695static bool mv88e6xxx_6185_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200696{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400697 return chip->info->family == MV88E6XXX_FAMILY_6185;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200698}
699
Vivien Didelotfad09c72016-06-21 12:28:20 -0400700static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700701{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400702 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700703}
704
Vivien Didelotfad09c72016-06-21 12:28:20 -0400705static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200706{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400707 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200708}
709
Vivien Didelotfad09c72016-06-21 12:28:20 -0400710static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200711{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400712 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200713}
714
Vivien Didelotd78343d2016-11-04 03:23:36 +0100715static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
716 int link, int speed, int duplex,
717 phy_interface_t mode)
718{
719 int err;
720
721 if (!chip->info->ops->port_set_link)
722 return 0;
723
724 /* Port's MAC control must not be changed unless the link is down */
725 err = chip->info->ops->port_set_link(chip, port, 0);
726 if (err)
727 return err;
728
729 if (chip->info->ops->port_set_speed) {
730 err = chip->info->ops->port_set_speed(chip, port, speed);
731 if (err && err != -EOPNOTSUPP)
732 goto restore_link;
733 }
734
735 if (chip->info->ops->port_set_duplex) {
736 err = chip->info->ops->port_set_duplex(chip, port, duplex);
737 if (err && err != -EOPNOTSUPP)
738 goto restore_link;
739 }
740
741 if (chip->info->ops->port_set_rgmii_delay) {
742 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
743 if (err && err != -EOPNOTSUPP)
744 goto restore_link;
745 }
746
747 err = 0;
748restore_link:
749 if (chip->info->ops->port_set_link(chip, port, link))
750 netdev_err(chip->ds->ports[port].netdev,
751 "failed to restore MAC's link\n");
752
753 return err;
754}
755
Andrew Lunndea87022015-08-31 15:56:47 +0200756/* We expect the switch to perform auto negotiation if there is a real
757 * phy. However, in the case of a fixed link phy, we force the port
758 * settings from the fixed link settings.
759 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400760static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
761 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200762{
Vivien Didelot04bed142016-08-31 18:06:13 -0400763 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200764 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200765
766 if (!phy_is_pseudo_fixed_link(phydev))
767 return;
768
Vivien Didelotfad09c72016-06-21 12:28:20 -0400769 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100770 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
771 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400772 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100773
774 if (err && err != -EOPNOTSUPP)
775 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200776}
777
Andrew Lunna605a0f2016-11-21 23:26:58 +0100778static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000779{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100780 if (!chip->info->ops->stats_snapshot)
781 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000782
Andrew Lunna605a0f2016-11-21 23:26:58 +0100783 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000784}
785
Andrew Lunne413e7e2015-04-02 04:06:38 +0200786static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100787 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
788 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
789 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
790 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
791 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
792 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
793 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
794 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
795 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
796 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
797 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
798 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
799 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
800 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
801 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
802 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
803 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
804 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
805 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
806 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
807 { "single", 4, 0x14, STATS_TYPE_BANK0, },
808 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
809 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
810 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
811 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
812 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
813 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
814 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
815 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
816 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
817 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
818 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
819 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
820 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
821 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
822 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
823 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
824 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
825 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
826 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
827 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
828 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
829 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
830 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
831 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
832 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
833 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
834 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
835 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
836 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
837 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
838 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
839 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
840 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
841 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
842 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
843 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
844 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
845 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200846};
847
Vivien Didelotfad09c72016-06-21 12:28:20 -0400848static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100849 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100850 int port, u16 bank1_select,
851 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200852{
Andrew Lunn80c46272015-06-20 18:42:30 +0200853 u32 low;
854 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100855 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200856 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200857 u64 value;
858
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100859 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100860 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200861 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
862 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200863 return UINT64_MAX;
864
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200865 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200866 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200867 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
868 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200869 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200870 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200871 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100872 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100873 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100874 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100875 /* fall through */
876 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100877 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100878 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200879 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100880 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200881 }
882 value = (((u64)high) << 16) | low;
883 return value;
884}
885
Andrew Lunndfafe442016-11-21 23:27:02 +0100886static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
887 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100888{
889 struct mv88e6xxx_hw_stat *stat;
890 int i, j;
891
892 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
893 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100894 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100895 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
896 ETH_GSTRING_LEN);
897 j++;
898 }
899 }
900}
901
Andrew Lunndfafe442016-11-21 23:27:02 +0100902static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
903 uint8_t *data)
904{
905 mv88e6xxx_stats_get_strings(chip, data,
906 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
907}
908
909static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
910 uint8_t *data)
911{
912 mv88e6xxx_stats_get_strings(chip, data,
913 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
914}
915
916static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
917 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100918{
Vivien Didelot04bed142016-08-31 18:06:13 -0400919 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100920
921 if (chip->info->ops->stats_get_strings)
922 chip->info->ops->stats_get_strings(chip, data);
923}
924
925static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
926 int types)
927{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100928 struct mv88e6xxx_hw_stat *stat;
929 int i, j;
930
931 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
932 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100933 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100934 j++;
935 }
936 return j;
937}
938
Andrew Lunndfafe442016-11-21 23:27:02 +0100939static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
940{
941 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
942 STATS_TYPE_PORT);
943}
944
945static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
946{
947 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
948 STATS_TYPE_BANK1);
949}
950
951static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
952{
953 struct mv88e6xxx_chip *chip = ds->priv;
954
955 if (chip->info->ops->stats_get_sset_count)
956 return chip->info->ops->stats_get_sset_count(chip);
957
958 return 0;
959}
960
Andrew Lunn052f9472016-11-21 23:27:03 +0100961static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100962 uint64_t *data, int types,
963 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100964{
965 struct mv88e6xxx_hw_stat *stat;
966 int i, j;
967
968 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
969 stat = &mv88e6xxx_hw_stats[i];
970 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100971 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
972 bank1_select,
973 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100974 j++;
975 }
976 }
977}
978
979static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
980 uint64_t *data)
981{
982 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100983 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
984 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100985}
986
987static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
988 uint64_t *data)
989{
990 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100991 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
992 GLOBAL_STATS_OP_BANK_1_BIT_9,
993 GLOBAL_STATS_OP_HIST_RX_TX);
994}
995
996static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
997 uint64_t *data)
998{
999 return mv88e6xxx_stats_get_stats(chip, port, data,
1000 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
1001 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +01001002}
1003
1004static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
1005 uint64_t *data)
1006{
1007 if (chip->info->ops->stats_get_stats)
1008 chip->info->ops->stats_get_stats(chip, port, data);
1009}
1010
Vivien Didelotf81ec902016-05-09 13:22:58 -04001011static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
1012 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001013{
Vivien Didelot04bed142016-08-31 18:06:13 -04001014 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001015 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001016
Vivien Didelotfad09c72016-06-21 12:28:20 -04001017 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001018
Andrew Lunna605a0f2016-11-21 23:26:58 +01001019 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001020 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001021 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001022 return;
1023 }
Andrew Lunn052f9472016-11-21 23:27:03 +01001024
1025 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001026
Vivien Didelotfad09c72016-06-21 12:28:20 -04001027 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001028}
Ben Hutchings98e67302011-11-25 14:36:19 +00001029
Andrew Lunnde2273872016-11-21 23:27:01 +01001030static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
1031{
1032 if (chip->info->ops->stats_set_histogram)
1033 return chip->info->ops->stats_set_histogram(chip);
1034
1035 return 0;
1036}
1037
Vivien Didelotf81ec902016-05-09 13:22:58 -04001038static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001039{
1040 return 32 * sizeof(u16);
1041}
1042
Vivien Didelotf81ec902016-05-09 13:22:58 -04001043static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1044 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001045{
Vivien Didelot04bed142016-08-31 18:06:13 -04001046 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001047 int err;
1048 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001049 u16 *p = _p;
1050 int i;
1051
1052 regs->version = 0;
1053
1054 memset(p, 0xff, 32 * sizeof(u16));
1055
Vivien Didelotfad09c72016-06-21 12:28:20 -04001056 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001057
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001058 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001059
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001060 err = mv88e6xxx_port_read(chip, port, i, &reg);
1061 if (!err)
1062 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001063 }
Vivien Didelot23062512016-05-09 13:22:45 -04001064
Vivien Didelotfad09c72016-06-21 12:28:20 -04001065 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001066}
1067
Vivien Didelotfad09c72016-06-21 12:28:20 -04001068static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001069{
Vivien Didelota935c052016-09-29 12:21:53 -04001070 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001071}
1072
Vivien Didelotf81ec902016-05-09 13:22:58 -04001073static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1074 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001075{
Vivien Didelot04bed142016-08-31 18:06:13 -04001076 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001077 u16 reg;
1078 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001079
Vivien Didelotfad09c72016-06-21 12:28:20 -04001080 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001081 return -EOPNOTSUPP;
1082
Vivien Didelotfad09c72016-06-21 12:28:20 -04001083 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001084
Vivien Didelot9c938292016-08-15 17:19:02 -04001085 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1086 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001087 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001088
1089 e->eee_enabled = !!(reg & 0x0200);
1090 e->tx_lpi_enabled = !!(reg & 0x0100);
1091
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001092 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001093 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001094 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001095
Andrew Lunncca8b132015-04-02 04:06:39 +02001096 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001097out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001098 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001099
1100 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001101}
1102
Vivien Didelotf81ec902016-05-09 13:22:58 -04001103static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1104 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001105{
Vivien Didelot04bed142016-08-31 18:06:13 -04001106 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001107 u16 reg;
1108 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001109
Vivien Didelotfad09c72016-06-21 12:28:20 -04001110 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001111 return -EOPNOTSUPP;
1112
Vivien Didelotfad09c72016-06-21 12:28:20 -04001113 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001114
Vivien Didelot9c938292016-08-15 17:19:02 -04001115 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1116 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001117 goto out;
1118
Vivien Didelot9c938292016-08-15 17:19:02 -04001119 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001120 if (e->eee_enabled)
1121 reg |= 0x0200;
1122 if (e->tx_lpi_enabled)
1123 reg |= 0x0100;
1124
Vivien Didelot9c938292016-08-15 17:19:02 -04001125 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001126out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001127 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001128
Vivien Didelot9c938292016-08-15 17:19:02 -04001129 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001130}
1131
Vivien Didelotfad09c72016-06-21 12:28:20 -04001132static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001133{
Vivien Didelota935c052016-09-29 12:21:53 -04001134 u16 val;
1135 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001136
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001137 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001138 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1139 if (err)
1140 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001141 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001142 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001143 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1144 if (err)
1145 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001146
Vivien Didelota935c052016-09-29 12:21:53 -04001147 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1148 (val & 0xfff) | ((fid << 8) & 0xf000));
1149 if (err)
1150 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001151
1152 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1153 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001154 }
1155
Vivien Didelota935c052016-09-29 12:21:53 -04001156 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1157 if (err)
1158 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001159
Vivien Didelotfad09c72016-06-21 12:28:20 -04001160 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001161}
1162
Vivien Didelotfad09c72016-06-21 12:28:20 -04001163static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001164 struct mv88e6xxx_atu_entry *entry)
1165{
1166 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1167
1168 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1169 unsigned int mask, shift;
1170
1171 if (entry->trunk) {
1172 data |= GLOBAL_ATU_DATA_TRUNK;
1173 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1174 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1175 } else {
1176 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1177 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1178 }
1179
1180 data |= (entry->portv_trunkid << shift) & mask;
1181 }
1182
Vivien Didelota935c052016-09-29 12:21:53 -04001183 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001184}
1185
Vivien Didelotfad09c72016-06-21 12:28:20 -04001186static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001187 struct mv88e6xxx_atu_entry *entry,
1188 bool static_too)
1189{
1190 int op;
1191 int err;
1192
Vivien Didelotfad09c72016-06-21 12:28:20 -04001193 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001194 if (err)
1195 return err;
1196
Vivien Didelotfad09c72016-06-21 12:28:20 -04001197 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001198 if (err)
1199 return err;
1200
1201 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001202 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1203 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1204 } else {
1205 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1206 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1207 }
1208
Vivien Didelotfad09c72016-06-21 12:28:20 -04001209 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001210}
1211
Vivien Didelotfad09c72016-06-21 12:28:20 -04001212static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001213 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001214{
1215 struct mv88e6xxx_atu_entry entry = {
1216 .fid = fid,
1217 .state = 0, /* EntryState bits must be 0 */
1218 };
1219
Vivien Didelotfad09c72016-06-21 12:28:20 -04001220 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001221}
1222
Vivien Didelotfad09c72016-06-21 12:28:20 -04001223static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001224 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001225{
1226 struct mv88e6xxx_atu_entry entry = {
1227 .trunk = false,
1228 .fid = fid,
1229 };
1230
1231 /* EntryState bits must be 0xF */
1232 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1233
1234 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1235 entry.portv_trunkid = (to_port & 0x0f) << 4;
1236 entry.portv_trunkid |= from_port & 0x0f;
1237
Vivien Didelotfad09c72016-06-21 12:28:20 -04001238 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001239}
1240
Vivien Didelotfad09c72016-06-21 12:28:20 -04001241static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001242 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001243{
1244 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001245 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001246}
1247
Vivien Didelotfad09c72016-06-21 12:28:20 -04001248static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001249{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001250 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001251 struct dsa_switch *ds = chip->ds;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001252 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001253 int i;
1254
1255 /* allow CPU port or DSA link(s) to send frames to every port */
1256 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001257 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001258 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001259 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001260 /* allow sending frames to every group member */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001261 if (bridge && chip->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001262 output_ports |= BIT(i);
1263
1264 /* allow sending frames to CPU port and DSA link(s) */
1265 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1266 output_ports |= BIT(i);
1267 }
1268 }
1269
1270 /* prevent frames from going back out of the port they came in on */
1271 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001272
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001273 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001274}
1275
Vivien Didelotf81ec902016-05-09 13:22:58 -04001276static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1277 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001278{
Vivien Didelot04bed142016-08-31 18:06:13 -04001279 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001280 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001281 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001282
1283 switch (state) {
1284 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001285 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001286 break;
1287 case BR_STATE_BLOCKING:
1288 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001289 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001290 break;
1291 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001292 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001293 break;
1294 case BR_STATE_FORWARDING:
1295 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001296 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001297 break;
1298 }
1299
Vivien Didelotfad09c72016-06-21 12:28:20 -04001300 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001301 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001302 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001303
1304 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001305 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001306}
1307
Vivien Didelot749efcb2016-09-22 16:49:24 -04001308static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1309{
1310 struct mv88e6xxx_chip *chip = ds->priv;
1311 int err;
1312
1313 mutex_lock(&chip->reg_lock);
1314 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1315 mutex_unlock(&chip->reg_lock);
1316
1317 if (err)
1318 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1319}
1320
Vivien Didelotfad09c72016-06-21 12:28:20 -04001321static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001322{
Vivien Didelota935c052016-09-29 12:21:53 -04001323 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001324}
1325
Vivien Didelotfad09c72016-06-21 12:28:20 -04001326static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001327{
Vivien Didelota935c052016-09-29 12:21:53 -04001328 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001329
Vivien Didelota935c052016-09-29 12:21:53 -04001330 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1331 if (err)
1332 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001333
Vivien Didelotfad09c72016-06-21 12:28:20 -04001334 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001335}
1336
Vivien Didelotfad09c72016-06-21 12:28:20 -04001337static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001338{
1339 int ret;
1340
Vivien Didelotfad09c72016-06-21 12:28:20 -04001341 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001342 if (ret < 0)
1343 return ret;
1344
Vivien Didelotfad09c72016-06-21 12:28:20 -04001345 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001346}
1347
Vivien Didelotfad09c72016-06-21 12:28:20 -04001348static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001349 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001350 unsigned int nibble_offset)
1351{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001352 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001353 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001354
1355 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001356 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001357
Vivien Didelota935c052016-09-29 12:21:53 -04001358 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1359 if (err)
1360 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001361 }
1362
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001363 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001364 unsigned int shift = (i % 4) * 4 + nibble_offset;
1365 u16 reg = regs[i / 4];
1366
1367 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1368 }
1369
1370 return 0;
1371}
1372
Vivien Didelotfad09c72016-06-21 12:28:20 -04001373static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001374 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001375{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001376 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001377}
1378
Vivien Didelotfad09c72016-06-21 12:28:20 -04001379static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001380 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001381{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001382 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001383}
1384
Vivien Didelotfad09c72016-06-21 12:28:20 -04001385static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001386 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001387 unsigned int nibble_offset)
1388{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001389 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001390 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001391
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001392 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001393 unsigned int shift = (i % 4) * 4 + nibble_offset;
1394 u8 data = entry->data[i];
1395
1396 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1397 }
1398
1399 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001400 u16 reg = regs[i];
1401
1402 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1403 if (err)
1404 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001405 }
1406
1407 return 0;
1408}
1409
Vivien Didelotfad09c72016-06-21 12:28:20 -04001410static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001411 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001412{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001413 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001414}
1415
Vivien Didelotfad09c72016-06-21 12:28:20 -04001416static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001417 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001418{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001419 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001420}
1421
Vivien Didelotfad09c72016-06-21 12:28:20 -04001422static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001423{
Vivien Didelota935c052016-09-29 12:21:53 -04001424 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1425 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001426}
1427
Vivien Didelotfad09c72016-06-21 12:28:20 -04001428static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001429 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001430{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001431 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001432 u16 val;
1433 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001434
Vivien Didelota935c052016-09-29 12:21:53 -04001435 err = _mv88e6xxx_vtu_wait(chip);
1436 if (err)
1437 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001438
Vivien Didelota935c052016-09-29 12:21:53 -04001439 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1440 if (err)
1441 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001442
Vivien Didelota935c052016-09-29 12:21:53 -04001443 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1444 if (err)
1445 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001446
Vivien Didelota935c052016-09-29 12:21:53 -04001447 next.vid = val & GLOBAL_VTU_VID_MASK;
1448 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001449
1450 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001451 err = mv88e6xxx_vtu_data_read(chip, &next);
1452 if (err)
1453 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001454
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001455 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001456 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1457 if (err)
1458 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001459
Vivien Didelota935c052016-09-29 12:21:53 -04001460 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001461 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001462 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1463 * VTU DBNum[3:0] are located in VTU Operation 3:0
1464 */
Vivien Didelota935c052016-09-29 12:21:53 -04001465 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1466 if (err)
1467 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001468
Vivien Didelota935c052016-09-29 12:21:53 -04001469 next.fid = (val & 0xf00) >> 4;
1470 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001471 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001472
Vivien Didelotfad09c72016-06-21 12:28:20 -04001473 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001474 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1475 if (err)
1476 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001477
Vivien Didelota935c052016-09-29 12:21:53 -04001478 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001479 }
1480 }
1481
1482 *entry = next;
1483 return 0;
1484}
1485
Vivien Didelotf81ec902016-05-09 13:22:58 -04001486static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1487 struct switchdev_obj_port_vlan *vlan,
1488 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001489{
Vivien Didelot04bed142016-08-31 18:06:13 -04001490 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001491 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001492 u16 pvid;
1493 int err;
1494
Vivien Didelotfad09c72016-06-21 12:28:20 -04001495 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001496 return -EOPNOTSUPP;
1497
Vivien Didelotfad09c72016-06-21 12:28:20 -04001498 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001499
Vivien Didelot77064f32016-11-04 03:23:30 +01001500 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001501 if (err)
1502 goto unlock;
1503
Vivien Didelotfad09c72016-06-21 12:28:20 -04001504 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001505 if (err)
1506 goto unlock;
1507
1508 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001509 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001510 if (err)
1511 break;
1512
1513 if (!next.valid)
1514 break;
1515
1516 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1517 continue;
1518
1519 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001520 vlan->vid_begin = next.vid;
1521 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001522 vlan->flags = 0;
1523
1524 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1525 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1526
1527 if (next.vid == pvid)
1528 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1529
1530 err = cb(&vlan->obj);
1531 if (err)
1532 break;
1533 } while (next.vid < GLOBAL_VTU_VID_MASK);
1534
1535unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001536 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001537
1538 return err;
1539}
1540
Vivien Didelotfad09c72016-06-21 12:28:20 -04001541static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001542 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001543{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001544 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001545 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001546 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001547
Vivien Didelota935c052016-09-29 12:21:53 -04001548 err = _mv88e6xxx_vtu_wait(chip);
1549 if (err)
1550 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001551
1552 if (!entry->valid)
1553 goto loadpurge;
1554
1555 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001556 err = mv88e6xxx_vtu_data_write(chip, entry);
1557 if (err)
1558 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001559
Vivien Didelotfad09c72016-06-21 12:28:20 -04001560 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001561 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001562 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1563 if (err)
1564 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001565 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001566
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001567 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001568 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001569 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1570 if (err)
1571 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001572 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001573 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1574 * VTU DBNum[3:0] are located in VTU Operation 3:0
1575 */
1576 op |= (entry->fid & 0xf0) << 8;
1577 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001578 }
1579
1580 reg = GLOBAL_VTU_VID_VALID;
1581loadpurge:
1582 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001583 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1584 if (err)
1585 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001586
Vivien Didelotfad09c72016-06-21 12:28:20 -04001587 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001588}
1589
Vivien Didelotfad09c72016-06-21 12:28:20 -04001590static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001591 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001592{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001593 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001594 u16 val;
1595 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001596
Vivien Didelota935c052016-09-29 12:21:53 -04001597 err = _mv88e6xxx_vtu_wait(chip);
1598 if (err)
1599 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001600
Vivien Didelota935c052016-09-29 12:21:53 -04001601 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1602 sid & GLOBAL_VTU_SID_MASK);
1603 if (err)
1604 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001605
Vivien Didelota935c052016-09-29 12:21:53 -04001606 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1607 if (err)
1608 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001609
Vivien Didelota935c052016-09-29 12:21:53 -04001610 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1611 if (err)
1612 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001613
Vivien Didelota935c052016-09-29 12:21:53 -04001614 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001615
Vivien Didelota935c052016-09-29 12:21:53 -04001616 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1617 if (err)
1618 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001619
Vivien Didelota935c052016-09-29 12:21:53 -04001620 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001621
1622 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001623 err = mv88e6xxx_stu_data_read(chip, &next);
1624 if (err)
1625 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001626 }
1627
1628 *entry = next;
1629 return 0;
1630}
1631
Vivien Didelotfad09c72016-06-21 12:28:20 -04001632static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001633 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001634{
1635 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001636 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001637
Vivien Didelota935c052016-09-29 12:21:53 -04001638 err = _mv88e6xxx_vtu_wait(chip);
1639 if (err)
1640 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001641
1642 if (!entry->valid)
1643 goto loadpurge;
1644
1645 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001646 err = mv88e6xxx_stu_data_write(chip, entry);
1647 if (err)
1648 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001649
1650 reg = GLOBAL_VTU_VID_VALID;
1651loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001652 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1653 if (err)
1654 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001655
1656 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001657 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1658 if (err)
1659 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001660
Vivien Didelotfad09c72016-06-21 12:28:20 -04001661 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001662}
1663
Vivien Didelotfad09c72016-06-21 12:28:20 -04001664static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001665{
1666 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001667 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001668 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001669
1670 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1671
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001672 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001673 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001674 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001675 if (err)
1676 return err;
1677
1678 set_bit(*fid, fid_bitmap);
1679 }
1680
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001681 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001682 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001683 if (err)
1684 return err;
1685
1686 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001687 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001688 if (err)
1689 return err;
1690
1691 if (!vlan.valid)
1692 break;
1693
1694 set_bit(vlan.fid, fid_bitmap);
1695 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1696
1697 /* The reset value 0x000 is used to indicate that multiple address
1698 * databases are not needed. Return the next positive available.
1699 */
1700 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001701 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001702 return -ENOSPC;
1703
1704 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001705 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001706}
1707
Vivien Didelotfad09c72016-06-21 12:28:20 -04001708static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001709 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001710{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001711 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001712 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001713 .valid = true,
1714 .vid = vid,
1715 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001716 int i, err;
1717
Vivien Didelotfad09c72016-06-21 12:28:20 -04001718 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001719 if (err)
1720 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001721
Vivien Didelot3d131f02015-11-03 10:52:52 -05001722 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001723 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001724 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1725 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1726 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001727
Vivien Didelotfad09c72016-06-21 12:28:20 -04001728 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
1729 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001730 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001731
1732 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1733 * implemented, only one STU entry is needed to cover all VTU
1734 * entries. Thus, validate the SID 0.
1735 */
1736 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001737 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001738 if (err)
1739 return err;
1740
1741 if (vstp.sid != vlan.sid || !vstp.valid) {
1742 memset(&vstp, 0, sizeof(vstp));
1743 vstp.valid = true;
1744 vstp.sid = vlan.sid;
1745
Vivien Didelotfad09c72016-06-21 12:28:20 -04001746 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001747 if (err)
1748 return err;
1749 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001750 }
1751
1752 *entry = vlan;
1753 return 0;
1754}
1755
Vivien Didelotfad09c72016-06-21 12:28:20 -04001756static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001757 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001758{
1759 int err;
1760
1761 if (!vid)
1762 return -EINVAL;
1763
Vivien Didelotfad09c72016-06-21 12:28:20 -04001764 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001765 if (err)
1766 return err;
1767
Vivien Didelotfad09c72016-06-21 12:28:20 -04001768 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001769 if (err)
1770 return err;
1771
1772 if (entry->vid != vid || !entry->valid) {
1773 if (!creat)
1774 return -EOPNOTSUPP;
1775 /* -ENOENT would've been more appropriate, but switchdev expects
1776 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1777 */
1778
Vivien Didelotfad09c72016-06-21 12:28:20 -04001779 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001780 }
1781
1782 return err;
1783}
1784
Vivien Didelotda9c3592016-02-12 12:09:40 -05001785static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1786 u16 vid_begin, u16 vid_end)
1787{
Vivien Didelot04bed142016-08-31 18:06:13 -04001788 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001789 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001790 int i, err;
1791
1792 if (!vid_begin)
1793 return -EOPNOTSUPP;
1794
Vivien Didelotfad09c72016-06-21 12:28:20 -04001795 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001796
Vivien Didelotfad09c72016-06-21 12:28:20 -04001797 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001798 if (err)
1799 goto unlock;
1800
1801 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001802 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001803 if (err)
1804 goto unlock;
1805
1806 if (!vlan.valid)
1807 break;
1808
1809 if (vlan.vid > vid_end)
1810 break;
1811
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001812 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001813 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1814 continue;
1815
1816 if (vlan.data[i] ==
1817 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1818 continue;
1819
Vivien Didelotfad09c72016-06-21 12:28:20 -04001820 if (chip->ports[i].bridge_dev ==
1821 chip->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001822 break; /* same bridge, check next VLAN */
1823
Andrew Lunnc8b09802016-06-04 21:16:57 +02001824 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001825 "hardware VLAN %d already used by %s\n",
1826 vlan.vid,
Vivien Didelotfad09c72016-06-21 12:28:20 -04001827 netdev_name(chip->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001828 err = -EOPNOTSUPP;
1829 goto unlock;
1830 }
1831 } while (vlan.vid < vid_end);
1832
1833unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001834 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001835
1836 return err;
1837}
1838
Vivien Didelotf81ec902016-05-09 13:22:58 -04001839static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1840 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001841{
Vivien Didelot04bed142016-08-31 18:06:13 -04001842 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001843 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001844 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001845 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001846
Vivien Didelotfad09c72016-06-21 12:28:20 -04001847 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001848 return -EOPNOTSUPP;
1849
Vivien Didelotfad09c72016-06-21 12:28:20 -04001850 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001851 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001852 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001853
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001854 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001855}
1856
Vivien Didelot57d32312016-06-20 13:13:58 -04001857static int
1858mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1859 const struct switchdev_obj_port_vlan *vlan,
1860 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001861{
Vivien Didelot04bed142016-08-31 18:06:13 -04001862 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001863 int err;
1864
Vivien Didelotfad09c72016-06-21 12:28:20 -04001865 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001866 return -EOPNOTSUPP;
1867
Vivien Didelotda9c3592016-02-12 12:09:40 -05001868 /* If the requested port doesn't belong to the same bridge as the VLAN
1869 * members, do not support it (yet) and fallback to software VLAN.
1870 */
1871 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1872 vlan->vid_end);
1873 if (err)
1874 return err;
1875
Vivien Didelot76e398a2015-11-01 12:33:55 -05001876 /* We don't need any dynamic resource from the kernel (yet),
1877 * so skip the prepare phase.
1878 */
1879 return 0;
1880}
1881
Vivien Didelotfad09c72016-06-21 12:28:20 -04001882static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001883 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001884{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001885 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001886 int err;
1887
Vivien Didelotfad09c72016-06-21 12:28:20 -04001888 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001889 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001890 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001891
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001892 vlan.data[port] = untagged ?
1893 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1894 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1895
Vivien Didelotfad09c72016-06-21 12:28:20 -04001896 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001897}
1898
Vivien Didelotf81ec902016-05-09 13:22:58 -04001899static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1900 const struct switchdev_obj_port_vlan *vlan,
1901 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001902{
Vivien Didelot04bed142016-08-31 18:06:13 -04001903 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001904 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1905 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1906 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001907
Vivien Didelotfad09c72016-06-21 12:28:20 -04001908 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001909 return;
1910
Vivien Didelotfad09c72016-06-21 12:28:20 -04001911 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001912
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001913 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001914 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001915 netdev_err(ds->ports[port].netdev,
1916 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001917 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001918
Vivien Didelot77064f32016-11-04 03:23:30 +01001919 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001920 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001921 vlan->vid_end);
1922
Vivien Didelotfad09c72016-06-21 12:28:20 -04001923 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001924}
1925
Vivien Didelotfad09c72016-06-21 12:28:20 -04001926static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001927 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001928{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001929 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001930 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001931 int i, err;
1932
Vivien Didelotfad09c72016-06-21 12:28:20 -04001933 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001934 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001935 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001936
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001937 /* Tell switchdev if this VLAN is handled in software */
1938 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001939 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001940
1941 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1942
1943 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001944 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001945 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001946 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001947 continue;
1948
1949 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001950 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001951 break;
1952 }
1953 }
1954
Vivien Didelotfad09c72016-06-21 12:28:20 -04001955 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001956 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001957 return err;
1958
Vivien Didelotfad09c72016-06-21 12:28:20 -04001959 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001960}
1961
Vivien Didelotf81ec902016-05-09 13:22:58 -04001962static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1963 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001964{
Vivien Didelot04bed142016-08-31 18:06:13 -04001965 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001966 u16 pvid, vid;
1967 int err = 0;
1968
Vivien Didelotfad09c72016-06-21 12:28:20 -04001969 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001970 return -EOPNOTSUPP;
1971
Vivien Didelotfad09c72016-06-21 12:28:20 -04001972 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001973
Vivien Didelot77064f32016-11-04 03:23:30 +01001974 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001975 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001976 goto unlock;
1977
Vivien Didelot76e398a2015-11-01 12:33:55 -05001978 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001979 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001980 if (err)
1981 goto unlock;
1982
1983 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001984 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001985 if (err)
1986 goto unlock;
1987 }
1988 }
1989
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001990unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001991 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001992
1993 return err;
1994}
1995
Vivien Didelotfad09c72016-06-21 12:28:20 -04001996static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04001997 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001998{
Vivien Didelota935c052016-09-29 12:21:53 -04001999 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002000
2001 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002002 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
2003 (addr[i * 2] << 8) | addr[i * 2 + 1]);
2004 if (err)
2005 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002006 }
2007
2008 return 0;
2009}
2010
Vivien Didelotfad09c72016-06-21 12:28:20 -04002011static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04002012 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002013{
Vivien Didelota935c052016-09-29 12:21:53 -04002014 u16 val;
2015 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002016
2017 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04002018 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
2019 if (err)
2020 return err;
2021
2022 addr[i * 2] = val >> 8;
2023 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002024 }
2025
2026 return 0;
2027}
2028
Vivien Didelotfad09c72016-06-21 12:28:20 -04002029static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04002030 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002031{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002032 int ret;
2033
Vivien Didelotfad09c72016-06-21 12:28:20 -04002034 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002035 if (ret < 0)
2036 return ret;
2037
Vivien Didelotfad09c72016-06-21 12:28:20 -04002038 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002039 if (ret < 0)
2040 return ret;
2041
Vivien Didelotfad09c72016-06-21 12:28:20 -04002042 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002043 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002044 return ret;
2045
Vivien Didelotfad09c72016-06-21 12:28:20 -04002046 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002047}
David S. Millercdf09692015-08-11 12:00:37 -07002048
Vivien Didelot88472932016-09-19 19:56:11 -04002049static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2050 struct mv88e6xxx_atu_entry *entry);
2051
2052static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2053 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2054{
2055 struct mv88e6xxx_atu_entry next;
2056 int err;
2057
2058 eth_broadcast_addr(next.mac);
2059
2060 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2061 if (err)
2062 return err;
2063
2064 do {
2065 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2066 if (err)
2067 return err;
2068
2069 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2070 break;
2071
2072 if (ether_addr_equal(next.mac, addr)) {
2073 *entry = next;
2074 return 0;
2075 }
2076 } while (!is_broadcast_ether_addr(next.mac));
2077
2078 memset(entry, 0, sizeof(*entry));
2079 entry->fid = fid;
2080 ether_addr_copy(entry->mac, addr);
2081
2082 return 0;
2083}
2084
Vivien Didelot83dabd12016-08-31 11:50:04 -04002085static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2086 const unsigned char *addr, u16 vid,
2087 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002088{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002089 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002090 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002091 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002092
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002093 /* Null VLAN ID corresponds to the port private database */
2094 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002095 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002096 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002097 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002098 if (err)
2099 return err;
2100
Vivien Didelot88472932016-09-19 19:56:11 -04002101 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2102 if (err)
2103 return err;
2104
2105 /* Purge the ATU entry only if no port is using it anymore */
2106 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2107 entry.portv_trunkid &= ~BIT(port);
2108 if (!entry.portv_trunkid)
2109 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2110 } else {
2111 entry.portv_trunkid |= BIT(port);
2112 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002113 }
2114
Vivien Didelotfad09c72016-06-21 12:28:20 -04002115 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002116}
2117
Vivien Didelotf81ec902016-05-09 13:22:58 -04002118static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2119 const struct switchdev_obj_port_fdb *fdb,
2120 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002121{
2122 /* We don't need any dynamic resource from the kernel (yet),
2123 * so skip the prepare phase.
2124 */
2125 return 0;
2126}
2127
Vivien Didelotf81ec902016-05-09 13:22:58 -04002128static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2129 const struct switchdev_obj_port_fdb *fdb,
2130 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002131{
Vivien Didelot04bed142016-08-31 18:06:13 -04002132 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002133
Vivien Didelotfad09c72016-06-21 12:28:20 -04002134 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002135 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2136 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2137 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002138 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002139}
2140
Vivien Didelotf81ec902016-05-09 13:22:58 -04002141static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2142 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002143{
Vivien Didelot04bed142016-08-31 18:06:13 -04002144 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002145 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002146
Vivien Didelotfad09c72016-06-21 12:28:20 -04002147 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002148 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2149 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002150 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002151
Vivien Didelot83dabd12016-08-31 11:50:04 -04002152 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002153}
2154
Vivien Didelotfad09c72016-06-21 12:28:20 -04002155static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002156 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002157{
Vivien Didelot1d194042015-08-10 09:09:51 -04002158 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002159 u16 val;
2160 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002161
2162 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002163
Vivien Didelota935c052016-09-29 12:21:53 -04002164 err = _mv88e6xxx_atu_wait(chip);
2165 if (err)
2166 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002167
Vivien Didelota935c052016-09-29 12:21:53 -04002168 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2169 if (err)
2170 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002171
Vivien Didelota935c052016-09-29 12:21:53 -04002172 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2173 if (err)
2174 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002175
Vivien Didelota935c052016-09-29 12:21:53 -04002176 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2177 if (err)
2178 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002179
Vivien Didelota935c052016-09-29 12:21:53 -04002180 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002181 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2182 unsigned int mask, shift;
2183
Vivien Didelota935c052016-09-29 12:21:53 -04002184 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002185 next.trunk = true;
2186 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2187 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2188 } else {
2189 next.trunk = false;
2190 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2191 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2192 }
2193
Vivien Didelota935c052016-09-29 12:21:53 -04002194 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002195 }
2196
2197 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002198 return 0;
2199}
2200
Vivien Didelot83dabd12016-08-31 11:50:04 -04002201static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2202 u16 fid, u16 vid, int port,
2203 struct switchdev_obj *obj,
2204 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002205{
2206 struct mv88e6xxx_atu_entry addr = {
2207 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2208 };
2209 int err;
2210
Vivien Didelotfad09c72016-06-21 12:28:20 -04002211 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002212 if (err)
2213 return err;
2214
2215 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002216 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002217 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002218 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002219
2220 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2221 break;
2222
Vivien Didelot83dabd12016-08-31 11:50:04 -04002223 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2224 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002225
Vivien Didelot83dabd12016-08-31 11:50:04 -04002226 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2227 struct switchdev_obj_port_fdb *fdb;
2228
2229 if (!is_unicast_ether_addr(addr.mac))
2230 continue;
2231
2232 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002233 fdb->vid = vid;
2234 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002235 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2236 fdb->ndm_state = NUD_NOARP;
2237 else
2238 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002239 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2240 struct switchdev_obj_port_mdb *mdb;
2241
2242 if (!is_multicast_ether_addr(addr.mac))
2243 continue;
2244
2245 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2246 mdb->vid = vid;
2247 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002248 } else {
2249 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002250 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002251
2252 err = cb(obj);
2253 if (err)
2254 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002255 } while (!is_broadcast_ether_addr(addr.mac));
2256
2257 return err;
2258}
2259
Vivien Didelot83dabd12016-08-31 11:50:04 -04002260static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2261 struct switchdev_obj *obj,
2262 int (*cb)(struct switchdev_obj *obj))
2263{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002264 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002265 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2266 };
2267 u16 fid;
2268 int err;
2269
2270 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002271 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002272 if (err)
2273 return err;
2274
2275 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2276 if (err)
2277 return err;
2278
2279 /* Dump VLANs' Filtering Information Databases */
2280 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2281 if (err)
2282 return err;
2283
2284 do {
2285 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2286 if (err)
2287 return err;
2288
2289 if (!vlan.valid)
2290 break;
2291
2292 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2293 obj, cb);
2294 if (err)
2295 return err;
2296 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2297
2298 return err;
2299}
2300
Vivien Didelotf81ec902016-05-09 13:22:58 -04002301static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2302 struct switchdev_obj_port_fdb *fdb,
2303 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002304{
Vivien Didelot04bed142016-08-31 18:06:13 -04002305 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002306 int err;
2307
Vivien Didelotfad09c72016-06-21 12:28:20 -04002308 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002309 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002310 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002311
2312 return err;
2313}
2314
Vivien Didelotf81ec902016-05-09 13:22:58 -04002315static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
2316 struct net_device *bridge)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002317{
Vivien Didelot04bed142016-08-31 18:06:13 -04002318 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002319 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002320
Vivien Didelotfad09c72016-06-21 12:28:20 -04002321 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002322
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002323 /* Assign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002324 chip->ports[port].bridge_dev = bridge;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002325
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002326 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002327 if (chip->ports[i].bridge_dev == bridge) {
2328 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002329 if (err)
2330 break;
2331 }
2332 }
2333
Vivien Didelotfad09c72016-06-21 12:28:20 -04002334 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002335
Vivien Didelot466dfa02016-02-26 13:16:05 -05002336 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002337}
2338
Vivien Didelotf81ec902016-05-09 13:22:58 -04002339static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002340{
Vivien Didelot04bed142016-08-31 18:06:13 -04002341 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002342 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002343 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002344
Vivien Didelotfad09c72016-06-21 12:28:20 -04002345 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002346
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002347 /* Unassign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002348 chip->ports[port].bridge_dev = NULL;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002349
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002350 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002351 if (i == port || chip->ports[i].bridge_dev == bridge)
2352 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002353 netdev_warn(ds->ports[i].netdev,
2354 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002355
Vivien Didelotfad09c72016-06-21 12:28:20 -04002356 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002357}
2358
Vivien Didelotfad09c72016-06-21 12:28:20 -04002359static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002360{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002361 bool ppu_active = mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE);
Vivien Didelot552238b2016-05-09 13:22:49 -04002362 u16 is_reset = (ppu_active ? 0x8800 : 0xc800);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002363 struct gpio_desc *gpiod = chip->reset;
Vivien Didelot552238b2016-05-09 13:22:49 -04002364 unsigned long timeout;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002365 u16 reg;
Vivien Didelota935c052016-09-29 12:21:53 -04002366 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002367 int i;
2368
2369 /* Set all ports to the disabled state. */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002370 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelote28def332016-11-04 03:23:27 +01002371 err = mv88e6xxx_port_set_state(chip, i,
2372 PORT_CONTROL_STATE_DISABLED);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002373 if (err)
2374 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002375 }
2376
2377 /* Wait for transmit queues to drain. */
2378 usleep_range(2000, 4000);
2379
2380 /* If there is a gpio connected to the reset pin, toggle it */
2381 if (gpiod) {
2382 gpiod_set_value_cansleep(gpiod, 1);
2383 usleep_range(10000, 20000);
2384 gpiod_set_value_cansleep(gpiod, 0);
2385 usleep_range(10000, 20000);
2386 }
2387
2388 /* Reset the switch. Keep the PPU active if requested. The PPU
2389 * needs to be active to support indirect phy register access
2390 * through global registers 0x18 and 0x19.
2391 */
2392 if (ppu_active)
Vivien Didelota935c052016-09-29 12:21:53 -04002393 err = mv88e6xxx_g1_write(chip, 0x04, 0xc000);
Vivien Didelot552238b2016-05-09 13:22:49 -04002394 else
Vivien Didelota935c052016-09-29 12:21:53 -04002395 err = mv88e6xxx_g1_write(chip, 0x04, 0xc400);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002396 if (err)
2397 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002398
2399 /* Wait up to one second for reset to complete. */
2400 timeout = jiffies + 1 * HZ;
2401 while (time_before(jiffies, timeout)) {
Vivien Didelota935c052016-09-29 12:21:53 -04002402 err = mv88e6xxx_g1_read(chip, 0x00, &reg);
2403 if (err)
2404 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002405
Vivien Didelota935c052016-09-29 12:21:53 -04002406 if ((reg & is_reset) == is_reset)
Vivien Didelot552238b2016-05-09 13:22:49 -04002407 break;
2408 usleep_range(1000, 2000);
2409 }
2410 if (time_after(jiffies, timeout))
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002411 err = -ETIMEDOUT;
Vivien Didelot552238b2016-05-09 13:22:49 -04002412 else
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002413 err = 0;
Vivien Didelot552238b2016-05-09 13:22:49 -04002414
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002415 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002416}
2417
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002418static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002419{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002420 u16 val;
2421 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002422
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002423 /* Clear Power Down bit */
2424 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2425 if (err)
2426 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002427
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002428 if (val & BMCR_PDOWN) {
2429 val &= ~BMCR_PDOWN;
2430 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002431 }
2432
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002433 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002434}
2435
Andrew Lunn56995cb2016-12-03 04:35:19 +01002436static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2437 int upstream_port)
2438{
2439 int err;
2440
2441 err = chip->info->ops->port_set_frame_mode(
2442 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2443 if (err)
2444 return err;
2445
2446 return chip->info->ops->port_set_egress_unknowns(
2447 chip, port, port == upstream_port);
2448}
2449
2450static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2451{
2452 int err;
2453
2454 switch (chip->info->tag_protocol) {
2455 case DSA_TAG_PROTO_EDSA:
2456 err = chip->info->ops->port_set_frame_mode(
2457 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2458 if (err)
2459 return err;
2460
2461 err = mv88e6xxx_port_set_egress_mode(
2462 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2463 if (err)
2464 return err;
2465
2466 if (chip->info->ops->port_set_ether_type)
2467 err = chip->info->ops->port_set_ether_type(
2468 chip, port, ETH_P_EDSA);
2469 break;
2470
2471 case DSA_TAG_PROTO_DSA:
2472 err = chip->info->ops->port_set_frame_mode(
2473 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2474 if (err)
2475 return err;
2476
2477 err = mv88e6xxx_port_set_egress_mode(
2478 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2479 break;
2480 default:
2481 err = -EINVAL;
2482 }
2483
2484 if (err)
2485 return err;
2486
2487 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2488}
2489
2490static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2491{
2492 int err;
2493
2494 err = chip->info->ops->port_set_frame_mode(
2495 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2496 if (err)
2497 return err;
2498
2499 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2500}
2501
Vivien Didelotfad09c72016-06-21 12:28:20 -04002502static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002503{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002504 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002505 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002506 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002507
Vivien Didelotd78343d2016-11-04 03:23:36 +01002508 /* MAC Forcing register: don't force link, speed, duplex or flow control
2509 * state to any particular values on physical ports, but force the CPU
2510 * port and all DSA ports to their maximum bandwidth and full duplex.
2511 */
2512 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2513 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2514 SPEED_MAX, DUPLEX_FULL,
2515 PHY_INTERFACE_MODE_NA);
2516 else
2517 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2518 SPEED_UNFORCED, DUPLEX_UNFORCED,
2519 PHY_INTERFACE_MODE_NA);
2520 if (err)
2521 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002522
2523 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2524 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2525 * tunneling, determine priority by looking at 802.1p and IP
2526 * priority fields (IP prio has precedence), and set STP state
2527 * to Forwarding.
2528 *
2529 * If this is the CPU link, use DSA or EDSA tagging depending
2530 * on which tagging mode was configured.
2531 *
2532 * If this is a link to another switch, use DSA tagging mode.
2533 *
2534 * If this is the upstream port for this switch, enable
2535 * forwarding of unknown unicasts and multicasts.
2536 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002537 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002538 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2539 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002540 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2541 if (err)
2542 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002543
Andrew Lunn56995cb2016-12-03 04:35:19 +01002544 if (dsa_is_cpu_port(ds, port)) {
2545 err = mv88e6xxx_setup_port_cpu(chip, port);
2546 } else if (dsa_is_dsa_port(ds, port)) {
2547 err = mv88e6xxx_setup_port_dsa(chip, port,
2548 dsa_upstream_port(ds));
2549 } else {
2550 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002551 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002552 if (err)
2553 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002554
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002555 /* If this port is connected to a SerDes, make sure the SerDes is not
2556 * powered down.
2557 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002558 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002559 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2560 if (err)
2561 return err;
2562 reg &= PORT_STATUS_CMODE_MASK;
2563 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2564 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2565 (reg == PORT_STATUS_CMODE_SGMII)) {
2566 err = mv88e6xxx_serdes_power_on(chip);
2567 if (err < 0)
2568 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002569 }
2570 }
2571
Vivien Didelot8efdda42015-08-13 12:52:23 -04002572 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002573 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002574 * untagged frames on this port, do a destination address lookup on all
2575 * received packets as usual, disable ARP mirroring and don't send a
2576 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002577 */
2578 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002579 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2580 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2581 mv88e6xxx_6095_family(chip) || mv88e6xxx_6320_family(chip) ||
2582 mv88e6xxx_6185_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002583 reg = PORT_CONTROL_2_MAP_DA;
2584
Vivien Didelotfad09c72016-06-21 12:28:20 -04002585 if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002586 /* Set the upstream port this port should use */
2587 reg |= dsa_upstream_port(ds);
2588 /* enable forwarding of unknown multicast addresses to
2589 * the upstream port
2590 */
2591 if (port == dsa_upstream_port(ds))
2592 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
2593 }
2594
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002595 reg |= PORT_CONTROL_2_8021Q_DISABLED;
Vivien Didelot8efdda42015-08-13 12:52:23 -04002596
Andrew Lunn54d792f2015-05-06 01:09:47 +02002597 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002598 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
2599 if (err)
2600 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002601 }
2602
Andrew Lunn5f436662016-12-03 04:45:17 +01002603 if (chip->info->ops->port_jumbo_config) {
2604 err = chip->info->ops->port_jumbo_config(chip, port);
2605 if (err)
2606 return err;
2607 }
2608
Andrew Lunn54d792f2015-05-06 01:09:47 +02002609 /* Port Association Vector: when learning source addresses
2610 * of packets, add the address to the address database using
2611 * a port bitmap that has only the bit for this port set and
2612 * the other bits clear.
2613 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002614 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002615 /* Disable learning for CPU port */
2616 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002617 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002618
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002619 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2620 if (err)
2621 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002622
2623 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002624 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2625 if (err)
2626 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002627
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002628 if (chip->info->ops->port_pause_config) {
2629 err = chip->info->ops->port_pause_config(chip, port);
2630 if (err)
2631 return err;
2632 }
2633
Vivien Didelotfad09c72016-06-21 12:28:20 -04002634 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2635 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2636 mv88e6xxx_6320_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002637 /* Port ATU control: disable limiting the number of
2638 * address database entries that this port is allowed
2639 * to use.
2640 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002641 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2642 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002643 /* Priority Override: disable DA, SA and VTU priority
2644 * override.
2645 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002646 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2647 0x0000);
2648 if (err)
2649 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002650 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002651
Andrew Lunnef0a7312016-12-03 04:35:16 +01002652 if (chip->info->ops->port_tag_remap) {
2653 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002654 if (err)
2655 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002656 }
2657
Andrew Lunnef70b112016-12-03 04:45:18 +01002658 if (chip->info->ops->port_egress_rate_limiting) {
2659 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002660 if (err)
2661 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002662 }
2663
Guenter Roeck366f0a02015-03-26 18:36:30 -07002664 /* Port Control 1: disable trunking, disable sending
2665 * learning messages to this port.
Guenter Roeckd827e882015-03-26 18:36:29 -07002666 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002667 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_1, 0x0000);
2668 if (err)
2669 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002670
Vivien Didelot207afda2016-04-14 14:42:09 -04002671 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002672 * database, and allow bidirectional communication between the
2673 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002674 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002675 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002676 if (err)
2677 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002678
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002679 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2680 if (err)
2681 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002682
2683 /* Default VLAN ID and priority: don't set a default VLAN
2684 * ID, and set the default packet priority to zero.
2685 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002686 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002687}
2688
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002689static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002690{
2691 int err;
2692
Vivien Didelota935c052016-09-29 12:21:53 -04002693 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002694 if (err)
2695 return err;
2696
Vivien Didelota935c052016-09-29 12:21:53 -04002697 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002698 if (err)
2699 return err;
2700
Vivien Didelota935c052016-09-29 12:21:53 -04002701 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2702 if (err)
2703 return err;
2704
2705 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002706}
2707
Vivien Didelotacddbd22016-07-18 20:45:39 -04002708static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
2709 unsigned int msecs)
2710{
2711 const unsigned int coeff = chip->info->age_time_coeff;
2712 const unsigned int min = 0x01 * coeff;
2713 const unsigned int max = 0xff * coeff;
2714 u8 age_time;
2715 u16 val;
2716 int err;
2717
2718 if (msecs < min || msecs > max)
2719 return -ERANGE;
2720
2721 /* Round to nearest multiple of coeff */
2722 age_time = (msecs + coeff / 2) / coeff;
2723
Vivien Didelota935c052016-09-29 12:21:53 -04002724 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002725 if (err)
2726 return err;
2727
2728 /* AgeTime is 11:4 bits */
2729 val &= ~0xff0;
2730 val |= age_time << 4;
2731
Vivien Didelota935c052016-09-29 12:21:53 -04002732 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002733}
2734
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002735static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2736 unsigned int ageing_time)
2737{
Vivien Didelot04bed142016-08-31 18:06:13 -04002738 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002739 int err;
2740
2741 mutex_lock(&chip->reg_lock);
2742 err = mv88e6xxx_g1_set_age_time(chip, ageing_time);
2743 mutex_unlock(&chip->reg_lock);
2744
2745 return err;
2746}
2747
Vivien Didelot97299342016-07-18 20:45:30 -04002748static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002749{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002750 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002751 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot119477b2016-05-09 13:22:51 -04002752 u16 reg;
Vivien Didelot08a01262016-05-09 13:22:50 -04002753 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002754
Vivien Didelot119477b2016-05-09 13:22:51 -04002755 /* Enable the PHY Polling Unit if present, don't discard any packets,
2756 * and mask all interrupt sources.
2757 */
Andrew Lunndc30c352016-10-16 19:56:49 +02002758 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
2759 if (err < 0)
2760 return err;
2761
2762 reg &= ~GLOBAL_CONTROL_PPU_ENABLE;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002763 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU) ||
2764 mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE))
Vivien Didelot119477b2016-05-09 13:22:51 -04002765 reg |= GLOBAL_CONTROL_PPU_ENABLE;
2766
Vivien Didelota935c052016-09-29 12:21:53 -04002767 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
Vivien Didelot119477b2016-05-09 13:22:51 -04002768 if (err)
2769 return err;
2770
Andrew Lunn33641992016-12-03 04:35:17 +01002771 if (chip->info->ops->g1_set_cpu_port) {
2772 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2773 if (err)
2774 return err;
2775 }
2776
2777 if (chip->info->ops->g1_set_egress_port) {
2778 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2779 if (err)
2780 return err;
2781 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002782
Vivien Didelot50484ff2016-05-09 13:22:54 -04002783 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002784 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2785 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2786 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002787 if (err)
2788 return err;
2789
Vivien Didelotacddbd22016-07-18 20:45:39 -04002790 /* Clear all the VTU and STU entries */
2791 err = _mv88e6xxx_vtu_stu_flush(chip);
2792 if (err < 0)
2793 return err;
2794
Vivien Didelot08a01262016-05-09 13:22:50 -04002795 /* Set the default address aging time to 5 minutes, and
2796 * enable address learn messages to be sent to all message
2797 * ports.
2798 */
Vivien Didelota935c052016-09-29 12:21:53 -04002799 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2800 GLOBAL_ATU_CONTROL_LEARN2ALL);
Vivien Didelot08a01262016-05-09 13:22:50 -04002801 if (err)
2802 return err;
2803
Vivien Didelotacddbd22016-07-18 20:45:39 -04002804 err = mv88e6xxx_g1_set_age_time(chip, 300000);
2805 if (err)
Vivien Didelot97299342016-07-18 20:45:30 -04002806 return err;
2807
2808 /* Clear all ATU entries */
2809 err = _mv88e6xxx_atu_flush(chip, 0, true);
2810 if (err)
2811 return err;
2812
Vivien Didelot08a01262016-05-09 13:22:50 -04002813 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002814 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002815 if (err)
2816 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002817 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002818 if (err)
2819 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002820 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002821 if (err)
2822 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002823 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002824 if (err)
2825 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002826 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002827 if (err)
2828 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002829 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002830 if (err)
2831 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002832 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002833 if (err)
2834 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002835 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002836 if (err)
2837 return err;
2838
2839 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002840 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002841 if (err)
2842 return err;
2843
Andrew Lunnde2273872016-11-21 23:27:01 +01002844 /* Initialize the statistics unit */
2845 err = mv88e6xxx_stats_set_histogram(chip);
2846 if (err)
2847 return err;
2848
Vivien Didelot97299342016-07-18 20:45:30 -04002849 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002850 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2851 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002852 if (err)
2853 return err;
2854
2855 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002856 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002857 if (err)
2858 return err;
2859
2860 return 0;
2861}
2862
Vivien Didelotf81ec902016-05-09 13:22:58 -04002863static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002864{
Vivien Didelot04bed142016-08-31 18:06:13 -04002865 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002866 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002867 int i;
2868
Vivien Didelotfad09c72016-06-21 12:28:20 -04002869 chip->ds = ds;
2870 ds->slave_mii_bus = chip->mdio_bus;
Vivien Didelot552238b2016-05-09 13:22:49 -04002871
Vivien Didelotfad09c72016-06-21 12:28:20 -04002872 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002873
Vivien Didelot97299342016-07-18 20:45:30 -04002874 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002875 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002876 err = mv88e6xxx_setup_port(chip, i);
2877 if (err)
2878 goto unlock;
2879 }
2880
2881 /* Setup Switch Global 1 Registers */
2882 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002883 if (err)
2884 goto unlock;
2885
Vivien Didelot97299342016-07-18 20:45:30 -04002886 /* Setup Switch Global 2 Registers */
2887 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2888 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002889 if (err)
2890 goto unlock;
2891 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002892
Andrew Lunn6e55f692016-12-03 04:45:16 +01002893 /* Some generations have the configuration of sending reserved
2894 * management frames to the CPU in global2, others in
2895 * global1. Hence it does not fit the two setup functions
2896 * above.
2897 */
2898 if (chip->info->ops->mgmt_rsvd2cpu) {
2899 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2900 if (err)
2901 goto unlock;
2902 }
2903
Vivien Didelot6b17e862015-08-13 12:52:18 -04002904unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002905 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002906
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002907 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002908}
2909
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002910static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2911{
Vivien Didelot04bed142016-08-31 18:06:13 -04002912 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002913 int err;
2914
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002915 if (!chip->info->ops->set_switch_mac)
2916 return -EOPNOTSUPP;
2917
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002918 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002919 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002920 mutex_unlock(&chip->reg_lock);
2921
2922 return err;
2923}
2924
Vivien Didelote57e5e72016-08-15 17:19:00 -04002925static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002926{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002927 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002928 u16 val;
2929 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002930
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002931 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002932 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002933
Vivien Didelotfad09c72016-06-21 12:28:20 -04002934 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002935 err = mv88e6xxx_phy_read(chip, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002936 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002937
2938 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002939}
2940
Vivien Didelote57e5e72016-08-15 17:19:00 -04002941static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002942{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002943 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002944 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002945
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002946 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002947 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002948
Vivien Didelotfad09c72016-06-21 12:28:20 -04002949 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002950 err = mv88e6xxx_phy_write(chip, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002951 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002952
2953 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002954}
2955
Vivien Didelotfad09c72016-06-21 12:28:20 -04002956static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunnb516d452016-06-04 21:17:06 +02002957 struct device_node *np)
2958{
2959 static int index;
2960 struct mii_bus *bus;
2961 int err;
2962
Andrew Lunnb516d452016-06-04 21:17:06 +02002963 if (np)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002964 chip->mdio_np = of_get_child_by_name(np, "mdio");
Andrew Lunnb516d452016-06-04 21:17:06 +02002965
Vivien Didelotfad09c72016-06-21 12:28:20 -04002966 bus = devm_mdiobus_alloc(chip->dev);
Andrew Lunnb516d452016-06-04 21:17:06 +02002967 if (!bus)
2968 return -ENOMEM;
2969
Vivien Didelotfad09c72016-06-21 12:28:20 -04002970 bus->priv = (void *)chip;
Andrew Lunnb516d452016-06-04 21:17:06 +02002971 if (np) {
2972 bus->name = np->full_name;
2973 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2974 } else {
2975 bus->name = "mv88e6xxx SMI";
2976 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2977 }
2978
2979 bus->read = mv88e6xxx_mdio_read;
2980 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002981 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002982
Vivien Didelotfad09c72016-06-21 12:28:20 -04002983 if (chip->mdio_np)
2984 err = of_mdiobus_register(bus, chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002985 else
2986 err = mdiobus_register(bus);
2987 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002988 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunnb516d452016-06-04 21:17:06 +02002989 goto out;
2990 }
Vivien Didelotfad09c72016-06-21 12:28:20 -04002991 chip->mdio_bus = bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002992
2993 return 0;
2994
2995out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002996 if (chip->mdio_np)
2997 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002998
2999 return err;
3000}
3001
Vivien Didelotfad09c72016-06-21 12:28:20 -04003002static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02003003
3004{
Vivien Didelotfad09c72016-06-21 12:28:20 -04003005 struct mii_bus *bus = chip->mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02003006
3007 mdiobus_unregister(bus);
3008
Vivien Didelotfad09c72016-06-21 12:28:20 -04003009 if (chip->mdio_np)
3010 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02003011}
3012
Guenter Roeckc22995c2015-07-25 09:42:28 -07003013#ifdef CONFIG_NET_DSA_HWMON
3014
3015static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp)
3016{
Vivien Didelot04bed142016-08-31 18:06:13 -04003017 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04003018 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003019 int ret;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003020
3021 *temp = 0;
3022
Vivien Didelotfad09c72016-06-21 12:28:20 -04003023 mutex_lock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003024
Vivien Didelot9c938292016-08-15 17:19:02 -04003025 ret = mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x6);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003026 if (ret < 0)
3027 goto error;
3028
3029 /* Enable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04003030 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003031 if (ret < 0)
3032 goto error;
3033
Vivien Didelot9c938292016-08-15 17:19:02 -04003034 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val | (1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07003035 if (ret < 0)
3036 goto error;
3037
3038 /* Wait for temperature to stabilize */
3039 usleep_range(10000, 12000);
3040
Vivien Didelot9c938292016-08-15 17:19:02 -04003041 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
3042 if (ret < 0)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003043 goto error;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003044
3045 /* Disable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04003046 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val & ~(1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07003047 if (ret < 0)
3048 goto error;
3049
3050 *temp = ((val & 0x1f) - 5) * 5;
3051
3052error:
Vivien Didelot9c938292016-08-15 17:19:02 -04003053 mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x0);
Vivien Didelotfad09c72016-06-21 12:28:20 -04003054 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003055 return ret;
3056}
3057
3058static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp)
3059{
Vivien Didelot04bed142016-08-31 18:06:13 -04003060 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003061 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003062 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003063 int ret;
3064
3065 *temp = 0;
3066
Vivien Didelot9c938292016-08-15 17:19:02 -04003067 mutex_lock(&chip->reg_lock);
3068 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 27, &val);
3069 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003070 if (ret < 0)
3071 return ret;
3072
Vivien Didelot9c938292016-08-15 17:19:02 -04003073 *temp = (val & 0xff) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003074
3075 return 0;
3076}
3077
Vivien Didelotf81ec902016-05-09 13:22:58 -04003078static int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003079{
Vivien Didelot04bed142016-08-31 18:06:13 -04003080 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn158bc062016-04-28 21:24:06 -04003081
Vivien Didelotfad09c72016-06-21 12:28:20 -04003082 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP))
Vivien Didelot6594f612016-05-09 13:22:42 -04003083 return -EOPNOTSUPP;
3084
Vivien Didelotfad09c72016-06-21 12:28:20 -04003085 if (mv88e6xxx_6320_family(chip) || mv88e6xxx_6352_family(chip))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003086 return mv88e63xx_get_temp(ds, temp);
3087
3088 return mv88e61xx_get_temp(ds, temp);
3089}
3090
Vivien Didelotf81ec902016-05-09 13:22:58 -04003091static int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003092{
Vivien Didelot04bed142016-08-31 18:06:13 -04003093 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003094 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003095 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003096 int ret;
3097
Vivien Didelotfad09c72016-06-21 12:28:20 -04003098 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003099 return -EOPNOTSUPP;
3100
3101 *temp = 0;
3102
Vivien Didelot9c938292016-08-15 17:19:02 -04003103 mutex_lock(&chip->reg_lock);
3104 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3105 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003106 if (ret < 0)
3107 return ret;
3108
Vivien Didelot9c938292016-08-15 17:19:02 -04003109 *temp = (((val >> 8) & 0x1f) * 5) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003110
3111 return 0;
3112}
3113
Vivien Didelotf81ec902016-05-09 13:22:58 -04003114static int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003115{
Vivien Didelot04bed142016-08-31 18:06:13 -04003116 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003117 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003118 u16 val;
3119 int err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003120
Vivien Didelotfad09c72016-06-21 12:28:20 -04003121 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003122 return -EOPNOTSUPP;
3123
Vivien Didelot9c938292016-08-15 17:19:02 -04003124 mutex_lock(&chip->reg_lock);
3125 err = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3126 if (err)
3127 goto unlock;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003128 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
Vivien Didelot9c938292016-08-15 17:19:02 -04003129 err = mv88e6xxx_phy_page_write(chip, phy, 6, 26,
3130 (val & 0xe0ff) | (temp << 8));
3131unlock:
3132 mutex_unlock(&chip->reg_lock);
3133
3134 return err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003135}
3136
Vivien Didelotf81ec902016-05-09 13:22:58 -04003137static int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003138{
Vivien Didelot04bed142016-08-31 18:06:13 -04003139 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003140 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003141 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003142 int ret;
3143
Vivien Didelotfad09c72016-06-21 12:28:20 -04003144 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003145 return -EOPNOTSUPP;
3146
3147 *alarm = false;
3148
Vivien Didelot9c938292016-08-15 17:19:02 -04003149 mutex_lock(&chip->reg_lock);
3150 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3151 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003152 if (ret < 0)
3153 return ret;
3154
Vivien Didelot9c938292016-08-15 17:19:02 -04003155 *alarm = !!(val & 0x40);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003156
3157 return 0;
3158}
3159#endif /* CONFIG_NET_DSA_HWMON */
3160
Vivien Didelot855b1932016-07-20 18:18:35 -04003161static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3162{
Vivien Didelot04bed142016-08-31 18:06:13 -04003163 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003164
3165 return chip->eeprom_len;
3166}
3167
Vivien Didelot855b1932016-07-20 18:18:35 -04003168static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3169 struct ethtool_eeprom *eeprom, u8 *data)
3170{
Vivien Didelot04bed142016-08-31 18:06:13 -04003171 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003172 int err;
3173
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003174 if (!chip->info->ops->get_eeprom)
3175 return -EOPNOTSUPP;
3176
Vivien Didelot855b1932016-07-20 18:18:35 -04003177 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003178 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003179 mutex_unlock(&chip->reg_lock);
3180
3181 if (err)
3182 return err;
3183
3184 eeprom->magic = 0xc3ec4951;
3185
3186 return 0;
3187}
3188
Vivien Didelot855b1932016-07-20 18:18:35 -04003189static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3190 struct ethtool_eeprom *eeprom, u8 *data)
3191{
Vivien Didelot04bed142016-08-31 18:06:13 -04003192 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003193 int err;
3194
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003195 if (!chip->info->ops->set_eeprom)
3196 return -EOPNOTSUPP;
3197
Vivien Didelot855b1932016-07-20 18:18:35 -04003198 if (eeprom->magic != 0xc3ec4951)
3199 return -EINVAL;
3200
3201 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003202 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003203 mutex_unlock(&chip->reg_lock);
3204
3205 return err;
3206}
3207
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003208static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003209 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003210 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003211 .phy_read = mv88e6xxx_phy_ppu_read,
3212 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003213 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003214 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003215 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003216 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003217 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3218 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3219 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003220 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003221 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003222 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003223 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3224 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003225 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003226 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3227 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003228 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003229};
3230
3231static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003232 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003233 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003234 .phy_read = mv88e6xxx_phy_ppu_read,
3235 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003236 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003237 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003238 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003239 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3240 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003241 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003242 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3243 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003244 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003245 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003246};
3247
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003248static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003249 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003250 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3251 .phy_read = mv88e6xxx_g2_smi_phy_read,
3252 .phy_write = mv88e6xxx_g2_smi_phy_write,
3253 .port_set_link = mv88e6xxx_port_set_link,
3254 .port_set_duplex = mv88e6xxx_port_set_duplex,
3255 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003256 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003257 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3258 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3259 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003260 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003261 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003262 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003263 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3264 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3265 .stats_get_strings = mv88e6095_stats_get_strings,
3266 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003267 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3268 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003269 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003270};
3271
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003272static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003273 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003274 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003275 .phy_read = mv88e6xxx_read,
3276 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003277 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003278 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003279 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003280 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3281 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003282 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003283 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3284 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003285 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003286 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3287 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003288 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003289};
3290
3291static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003292 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003293 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003294 .phy_read = mv88e6xxx_phy_ppu_read,
3295 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003296 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003297 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003298 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003299 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003300 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3301 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3302 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003303 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003304 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003305 .port_pause_config = mv88e6097_port_pause_config,
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 Didelotb3469dd2016-09-29 12:22:00 -04003313};
3314
3315static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003316 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003317 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003318 .phy_read = mv88e6xxx_read,
3319 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003320 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003321 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003322 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003323 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003324 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3325 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3326 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003327 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003328 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003329 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003330 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003331 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3332 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003333 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003334 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3335 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003336 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003337};
3338
3339static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003340 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003341 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003342 .phy_read = mv88e6xxx_read,
3343 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003344 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003345 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003346 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003347 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003348 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3349 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003350 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003351 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3352 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003353 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003354};
3355
3356static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003357 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003358 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003359 .phy_read = mv88e6xxx_g2_smi_phy_read,
3360 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003361 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003362 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003363 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003364 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003365 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003366 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3367 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3368 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003369 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003370 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003371 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003372 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003373 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3374 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003375 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003376 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3377 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003378 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003379};
3380
3381static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003382 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003383 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3384 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003385 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003386 .phy_read = mv88e6xxx_g2_smi_phy_read,
3387 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003388 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003389 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003390 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003391 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003392 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003393 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3394 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3395 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003396 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003397 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003398 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003399 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003400 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3401 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003402 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003403 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3404 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003405 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003406};
3407
3408static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003409 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003410 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003411 .phy_read = mv88e6xxx_g2_smi_phy_read,
3412 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003413 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003414 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003415 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003416 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003417 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003418 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3419 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3420 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003421 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003422 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003423 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003424 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003425 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3426 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003427 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003428 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3429 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003430 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003431};
3432
3433static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003434 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003435 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3436 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003437 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003438 .phy_read = mv88e6xxx_g2_smi_phy_read,
3439 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003440 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003441 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003442 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003443 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003444 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003445 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3446 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3447 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003448 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003449 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003450 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003451 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003452 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3453 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003454 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003455 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3456 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003457 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003458};
3459
3460static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003461 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003462 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003463 .phy_read = mv88e6xxx_phy_ppu_read,
3464 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003465 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003466 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003467 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003468 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3469 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003470 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003471 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003472 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3473 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003474 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003475 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3476 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003477 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003478};
3479
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003480static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003481 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003482 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3483 .phy_read = mv88e6xxx_g2_smi_phy_read,
3484 .phy_write = mv88e6xxx_g2_smi_phy_write,
3485 .port_set_link = mv88e6xxx_port_set_link,
3486 .port_set_duplex = mv88e6xxx_port_set_duplex,
3487 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3488 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003489 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003490 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3491 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3492 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn79523472016-11-21 23:27:00 +01003493 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003494 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003495 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3496 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003497 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003498 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3499 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003500 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003501};
3502
3503static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003504 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003505 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3506 .phy_read = mv88e6xxx_g2_smi_phy_read,
3507 .phy_write = mv88e6xxx_g2_smi_phy_write,
3508 .port_set_link = mv88e6xxx_port_set_link,
3509 .port_set_duplex = mv88e6xxx_port_set_duplex,
3510 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3511 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003512 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003513 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3514 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3515 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn79523472016-11-21 23:27:00 +01003516 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003517 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003518 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3519 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003520 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003521 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3522 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003523 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003524};
3525
3526static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003527 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003528 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3529 .phy_read = mv88e6xxx_g2_smi_phy_read,
3530 .phy_write = mv88e6xxx_g2_smi_phy_write,
3531 .port_set_link = mv88e6xxx_port_set_link,
3532 .port_set_duplex = mv88e6xxx_port_set_duplex,
3533 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3534 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003535 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003536 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3537 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3538 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn79523472016-11-21 23:27:00 +01003539 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003540 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003541 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3542 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003543 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003544 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3545 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003546 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003547};
3548
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003549static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003550 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003551 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3552 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003553 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003554 .phy_read = mv88e6xxx_g2_smi_phy_read,
3555 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003556 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003557 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003558 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003559 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003560 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003561 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3562 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3563 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003564 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003565 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003566 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003567 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003568 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3569 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003570 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003571 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3572 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003573 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003574};
3575
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003576static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003577 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003578 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3579 .phy_read = mv88e6xxx_g2_smi_phy_read,
3580 .phy_write = mv88e6xxx_g2_smi_phy_write,
3581 .port_set_link = mv88e6xxx_port_set_link,
3582 .port_set_duplex = mv88e6xxx_port_set_duplex,
3583 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3584 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003585 .port_tag_remap = mv88e6390_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 Lunn79523472016-11-21 23:27:00 +01003589 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003590 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003591 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3592 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003593 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003594 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3595 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003596 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003597};
3598
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003599static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003600 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003601 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3602 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003603 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003604 .phy_read = mv88e6xxx_g2_smi_phy_read,
3605 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003606 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003607 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003608 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003609 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003610 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3611 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3612 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003613 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003614 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003615 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003616 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003617 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3618 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003619 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003620 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3621 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003622 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003623};
3624
3625static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003626 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003627 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3628 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003629 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003630 .phy_read = mv88e6xxx_g2_smi_phy_read,
3631 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003632 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003633 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003634 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003635 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003636 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3637 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3638 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003639 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003640 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003641 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003642 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003643 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3644 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003645 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003646 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3647 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003648};
3649
3650static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003651 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003652 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003653 .phy_read = mv88e6xxx_g2_smi_phy_read,
3654 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003655 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003656 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003657 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003658 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003659 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003660 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3661 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3662 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003663 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003664 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003665 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003666 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003667 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3668 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003669 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003670 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3671 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003672 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003673};
3674
3675static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003676 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003677 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003678 .phy_read = mv88e6xxx_g2_smi_phy_read,
3679 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003680 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003681 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003682 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003683 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003684 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003685 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3686 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3687 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003688 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003689 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003690 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003691 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003692 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3693 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003694 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003695 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3696 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003697 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003698};
3699
3700static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003701 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003702 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3703 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003704 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003705 .phy_read = mv88e6xxx_g2_smi_phy_read,
3706 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003707 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003708 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003709 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003710 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003711 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003712 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3713 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3714 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003715 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003716 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003717 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003718 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003719 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3720 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003721 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003722 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3723 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003724 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003725};
3726
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003727static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003728 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003729 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3730 .phy_read = mv88e6xxx_g2_smi_phy_read,
3731 .phy_write = mv88e6xxx_g2_smi_phy_write,
3732 .port_set_link = mv88e6xxx_port_set_link,
3733 .port_set_duplex = mv88e6xxx_port_set_duplex,
3734 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3735 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003736 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003737 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3738 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3739 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003740 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003741 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn79523472016-11-21 23:27:00 +01003742 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003743 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003744 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3745 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003746 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003747 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3748 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003749 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003750};
3751
3752static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003753 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003754 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3755 .phy_read = mv88e6xxx_g2_smi_phy_read,
3756 .phy_write = mv88e6xxx_g2_smi_phy_write,
3757 .port_set_link = mv88e6xxx_port_set_link,
3758 .port_set_duplex = mv88e6xxx_port_set_duplex,
3759 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3760 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003761 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003762 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3763 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3764 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003765 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003766 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn79523472016-11-21 23:27:00 +01003767 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003768 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003769 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3770 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003771 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003772 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3773 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003774 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003775};
3776
3777static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003778 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003779 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3780 .phy_read = mv88e6xxx_g2_smi_phy_read,
3781 .phy_write = mv88e6xxx_g2_smi_phy_write,
3782 .port_set_link = mv88e6xxx_port_set_link,
3783 .port_set_duplex = mv88e6xxx_port_set_duplex,
3784 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3785 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003786 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003787 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3788 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3789 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn79523472016-11-21 23:27:00 +01003790 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003791 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003792 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3793 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003794 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003795 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3796 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003797 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003798};
3799
Andrew Lunn56995cb2016-12-03 04:35:19 +01003800static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3801 const struct mv88e6xxx_ops *ops)
3802{
3803 if (!ops->port_set_frame_mode) {
3804 dev_err(chip->dev, "Missing port_set_frame_mode");
3805 return -EINVAL;
3806 }
3807
3808 if (!ops->port_set_egress_unknowns) {
3809 dev_err(chip->dev, "Missing port_set_egress_mode");
3810 return -EINVAL;
3811 }
3812
3813 return 0;
3814}
3815
Vivien Didelotf81ec902016-05-09 13:22:58 -04003816static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3817 [MV88E6085] = {
3818 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3819 .family = MV88E6XXX_FAMILY_6097,
3820 .name = "Marvell 88E6085",
3821 .num_databases = 4096,
3822 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003823 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003824 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003825 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003826 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003827 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003828 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003829 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003830 },
3831
3832 [MV88E6095] = {
3833 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3834 .family = MV88E6XXX_FAMILY_6095,
3835 .name = "Marvell 88E6095/88E6095F",
3836 .num_databases = 256,
3837 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003838 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003839 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003840 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003841 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003842 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003843 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003844 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003845 },
3846
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003847 [MV88E6097] = {
3848 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3849 .family = MV88E6XXX_FAMILY_6097,
3850 .name = "Marvell 88E6097/88E6097F",
3851 .num_databases = 4096,
3852 .num_ports = 11,
3853 .port_base_addr = 0x10,
3854 .global1_addr = 0x1b,
3855 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003856 .g1_irqs = 8,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003857 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3858 .ops = &mv88e6097_ops,
3859 },
3860
Vivien Didelotf81ec902016-05-09 13:22:58 -04003861 [MV88E6123] = {
3862 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3863 .family = MV88E6XXX_FAMILY_6165,
3864 .name = "Marvell 88E6123",
3865 .num_databases = 4096,
3866 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003867 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003868 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003869 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003870 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003871 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003872 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003873 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003874 },
3875
3876 [MV88E6131] = {
3877 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3878 .family = MV88E6XXX_FAMILY_6185,
3879 .name = "Marvell 88E6131",
3880 .num_databases = 256,
3881 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003882 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003883 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003884 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003885 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003886 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003887 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003888 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003889 },
3890
3891 [MV88E6161] = {
3892 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3893 .family = MV88E6XXX_FAMILY_6165,
3894 .name = "Marvell 88E6161",
3895 .num_databases = 4096,
3896 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003897 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003898 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003899 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003900 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003901 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003902 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003903 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003904 },
3905
3906 [MV88E6165] = {
3907 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3908 .family = MV88E6XXX_FAMILY_6165,
3909 .name = "Marvell 88E6165",
3910 .num_databases = 4096,
3911 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003912 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003913 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003914 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003915 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003916 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003917 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003918 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003919 },
3920
3921 [MV88E6171] = {
3922 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3923 .family = MV88E6XXX_FAMILY_6351,
3924 .name = "Marvell 88E6171",
3925 .num_databases = 4096,
3926 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003927 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003928 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003929 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003930 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003931 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003932 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003933 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003934 },
3935
3936 [MV88E6172] = {
3937 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3938 .family = MV88E6XXX_FAMILY_6352,
3939 .name = "Marvell 88E6172",
3940 .num_databases = 4096,
3941 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003942 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003943 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003944 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003945 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003946 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003947 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003948 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003949 },
3950
3951 [MV88E6175] = {
3952 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3953 .family = MV88E6XXX_FAMILY_6351,
3954 .name = "Marvell 88E6175",
3955 .num_databases = 4096,
3956 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003957 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003958 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003959 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003960 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003961 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003962 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003963 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003964 },
3965
3966 [MV88E6176] = {
3967 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3968 .family = MV88E6XXX_FAMILY_6352,
3969 .name = "Marvell 88E6176",
3970 .num_databases = 4096,
3971 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003972 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003973 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003974 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003975 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003976 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003977 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003978 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003979 },
3980
3981 [MV88E6185] = {
3982 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3983 .family = MV88E6XXX_FAMILY_6185,
3984 .name = "Marvell 88E6185",
3985 .num_databases = 256,
3986 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003987 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003988 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003989 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003990 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003991 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003992 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003993 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003994 },
3995
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003996 [MV88E6190] = {
3997 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3998 .family = MV88E6XXX_FAMILY_6390,
3999 .name = "Marvell 88E6190",
4000 .num_databases = 4096,
4001 .num_ports = 11, /* 10 + Z80 */
4002 .port_base_addr = 0x0,
4003 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004004 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004005 .age_time_coeff = 15000,
4006 .g1_irqs = 9,
4007 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4008 .ops = &mv88e6190_ops,
4009 },
4010
4011 [MV88E6190X] = {
4012 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
4013 .family = MV88E6XXX_FAMILY_6390,
4014 .name = "Marvell 88E6190X",
4015 .num_databases = 4096,
4016 .num_ports = 11, /* 10 + Z80 */
4017 .port_base_addr = 0x0,
4018 .global1_addr = 0x1b,
4019 .age_time_coeff = 15000,
4020 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004021 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004022 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4023 .ops = &mv88e6190x_ops,
4024 },
4025
4026 [MV88E6191] = {
4027 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
4028 .family = MV88E6XXX_FAMILY_6390,
4029 .name = "Marvell 88E6191",
4030 .num_databases = 4096,
4031 .num_ports = 11, /* 10 + Z80 */
4032 .port_base_addr = 0x0,
4033 .global1_addr = 0x1b,
4034 .age_time_coeff = 15000,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004035 .g1_irqs = 9,
4036 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004037 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4038 .ops = &mv88e6391_ops,
4039 },
4040
Vivien Didelotf81ec902016-05-09 13:22:58 -04004041 [MV88E6240] = {
4042 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
4043 .family = MV88E6XXX_FAMILY_6352,
4044 .name = "Marvell 88E6240",
4045 .num_databases = 4096,
4046 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004047 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004048 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004049 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004050 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004051 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004052 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004053 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004054 },
4055
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004056 [MV88E6290] = {
4057 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
4058 .family = MV88E6XXX_FAMILY_6390,
4059 .name = "Marvell 88E6290",
4060 .num_databases = 4096,
4061 .num_ports = 11, /* 10 + Z80 */
4062 .port_base_addr = 0x0,
4063 .global1_addr = 0x1b,
4064 .age_time_coeff = 15000,
4065 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004066 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004067 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4068 .ops = &mv88e6290_ops,
4069 },
4070
Vivien Didelotf81ec902016-05-09 13:22:58 -04004071 [MV88E6320] = {
4072 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
4073 .family = MV88E6XXX_FAMILY_6320,
4074 .name = "Marvell 88E6320",
4075 .num_databases = 4096,
4076 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004077 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004078 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004079 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004080 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004081 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004082 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004083 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004084 },
4085
4086 [MV88E6321] = {
4087 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
4088 .family = MV88E6XXX_FAMILY_6320,
4089 .name = "Marvell 88E6321",
4090 .num_databases = 4096,
4091 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004092 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004093 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004094 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004095 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004096 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004097 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004098 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004099 },
4100
4101 [MV88E6350] = {
4102 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
4103 .family = MV88E6XXX_FAMILY_6351,
4104 .name = "Marvell 88E6350",
4105 .num_databases = 4096,
4106 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004107 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004108 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004109 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004110 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004111 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004112 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004113 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004114 },
4115
4116 [MV88E6351] = {
4117 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4118 .family = MV88E6XXX_FAMILY_6351,
4119 .name = "Marvell 88E6351",
4120 .num_databases = 4096,
4121 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004122 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004123 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004124 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004125 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004126 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004127 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004128 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004129 },
4130
4131 [MV88E6352] = {
4132 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4133 .family = MV88E6XXX_FAMILY_6352,
4134 .name = "Marvell 88E6352",
4135 .num_databases = 4096,
4136 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004137 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004138 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004139 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004140 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004141 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004142 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004143 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004144 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004145 [MV88E6390] = {
4146 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4147 .family = MV88E6XXX_FAMILY_6390,
4148 .name = "Marvell 88E6390",
4149 .num_databases = 4096,
4150 .num_ports = 11, /* 10 + Z80 */
4151 .port_base_addr = 0x0,
4152 .global1_addr = 0x1b,
4153 .age_time_coeff = 15000,
4154 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004155 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004156 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4157 .ops = &mv88e6390_ops,
4158 },
4159 [MV88E6390X] = {
4160 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4161 .family = MV88E6XXX_FAMILY_6390,
4162 .name = "Marvell 88E6390X",
4163 .num_databases = 4096,
4164 .num_ports = 11, /* 10 + Z80 */
4165 .port_base_addr = 0x0,
4166 .global1_addr = 0x1b,
4167 .age_time_coeff = 15000,
4168 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004169 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004170 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4171 .ops = &mv88e6390x_ops,
4172 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004173};
4174
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004175static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004176{
Vivien Didelota439c062016-04-17 13:23:58 -04004177 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004178
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004179 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4180 if (mv88e6xxx_table[i].prod_num == prod_num)
4181 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004182
Vivien Didelotb9b37712015-10-30 19:39:48 -04004183 return NULL;
4184}
4185
Vivien Didelotfad09c72016-06-21 12:28:20 -04004186static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004187{
4188 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004189 unsigned int prod_num, rev;
4190 u16 id;
4191 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004192
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004193 mutex_lock(&chip->reg_lock);
4194 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4195 mutex_unlock(&chip->reg_lock);
4196 if (err)
4197 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004198
4199 prod_num = (id & 0xfff0) >> 4;
4200 rev = id & 0x000f;
4201
4202 info = mv88e6xxx_lookup_info(prod_num);
4203 if (!info)
4204 return -ENODEV;
4205
Vivien Didelotcaac8542016-06-20 13:14:09 -04004206 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004207 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004208
Vivien Didelotca070c12016-09-02 14:45:34 -04004209 err = mv88e6xxx_g2_require(chip);
4210 if (err)
4211 return err;
4212
Vivien Didelotfad09c72016-06-21 12:28:20 -04004213 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4214 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004215
4216 return 0;
4217}
4218
Vivien Didelotfad09c72016-06-21 12:28:20 -04004219static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004220{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004221 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004222
Vivien Didelotfad09c72016-06-21 12:28:20 -04004223 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4224 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004225 return NULL;
4226
Vivien Didelotfad09c72016-06-21 12:28:20 -04004227 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004228
Vivien Didelotfad09c72016-06-21 12:28:20 -04004229 mutex_init(&chip->reg_lock);
Vivien Didelot469d7292016-06-20 13:14:06 -04004230
Vivien Didelotfad09c72016-06-21 12:28:20 -04004231 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004232}
4233
Vivien Didelote57e5e72016-08-15 17:19:00 -04004234static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4235{
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004236 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
Vivien Didelote57e5e72016-08-15 17:19:00 -04004237 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004238}
4239
Andrew Lunn930188c2016-08-22 16:01:03 +02004240static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4241{
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004242 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
Andrew Lunn930188c2016-08-22 16:01:03 +02004243 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004244}
4245
Vivien Didelotfad09c72016-06-21 12:28:20 -04004246static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004247 struct mii_bus *bus, int sw_addr)
4248{
4249 /* ADDR[0] pin is unavailable externally and considered zero */
4250 if (sw_addr & 0x1)
4251 return -EINVAL;
4252
Vivien Didelot914b32f2016-06-20 13:14:11 -04004253 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004254 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004255 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004256 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004257 else
4258 return -EINVAL;
4259
Vivien Didelotfad09c72016-06-21 12:28:20 -04004260 chip->bus = bus;
4261 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004262
4263 return 0;
4264}
4265
Andrew Lunn7b314362016-08-22 16:01:01 +02004266static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4267{
Vivien Didelot04bed142016-08-31 18:06:13 -04004268 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004269
Andrew Lunn443d5a12016-12-03 04:35:18 +01004270 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004271}
4272
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004273static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4274 struct device *host_dev, int sw_addr,
4275 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004276{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004277 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004278 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004279 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004280
Vivien Didelota439c062016-04-17 13:23:58 -04004281 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004282 if (!bus)
4283 return NULL;
4284
Vivien Didelotfad09c72016-06-21 12:28:20 -04004285 chip = mv88e6xxx_alloc_chip(dsa_dev);
4286 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004287 return NULL;
4288
Vivien Didelotcaac8542016-06-20 13:14:09 -04004289 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004290 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004291
Vivien Didelotfad09c72016-06-21 12:28:20 -04004292 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004293 if (err)
4294 goto free;
4295
Vivien Didelotfad09c72016-06-21 12:28:20 -04004296 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004297 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004298 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004299
Andrew Lunndc30c352016-10-16 19:56:49 +02004300 mutex_lock(&chip->reg_lock);
4301 err = mv88e6xxx_switch_reset(chip);
4302 mutex_unlock(&chip->reg_lock);
4303 if (err)
4304 goto free;
4305
Vivien Didelote57e5e72016-08-15 17:19:00 -04004306 mv88e6xxx_phy_init(chip);
4307
Vivien Didelotfad09c72016-06-21 12:28:20 -04004308 err = mv88e6xxx_mdio_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004309 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004310 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004311
Vivien Didelotfad09c72016-06-21 12:28:20 -04004312 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004313
Vivien Didelotfad09c72016-06-21 12:28:20 -04004314 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004315free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004316 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004317
4318 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004319}
4320
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004321static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4322 const struct switchdev_obj_port_mdb *mdb,
4323 struct switchdev_trans *trans)
4324{
4325 /* We don't need any dynamic resource from the kernel (yet),
4326 * so skip the prepare phase.
4327 */
4328
4329 return 0;
4330}
4331
4332static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4333 const struct switchdev_obj_port_mdb *mdb,
4334 struct switchdev_trans *trans)
4335{
Vivien Didelot04bed142016-08-31 18:06:13 -04004336 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004337
4338 mutex_lock(&chip->reg_lock);
4339 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4340 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4341 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4342 mutex_unlock(&chip->reg_lock);
4343}
4344
4345static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4346 const struct switchdev_obj_port_mdb *mdb)
4347{
Vivien Didelot04bed142016-08-31 18:06:13 -04004348 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004349 int err;
4350
4351 mutex_lock(&chip->reg_lock);
4352 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4353 GLOBAL_ATU_DATA_STATE_UNUSED);
4354 mutex_unlock(&chip->reg_lock);
4355
4356 return err;
4357}
4358
4359static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4360 struct switchdev_obj_port_mdb *mdb,
4361 int (*cb)(struct switchdev_obj *obj))
4362{
Vivien Didelot04bed142016-08-31 18:06:13 -04004363 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004364 int err;
4365
4366 mutex_lock(&chip->reg_lock);
4367 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4368 mutex_unlock(&chip->reg_lock);
4369
4370 return err;
4371}
4372
Vivien Didelot9d490b42016-08-23 12:38:56 -04004373static struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004374 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004375 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004376 .setup = mv88e6xxx_setup,
4377 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004378 .adjust_link = mv88e6xxx_adjust_link,
4379 .get_strings = mv88e6xxx_get_strings,
4380 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4381 .get_sset_count = mv88e6xxx_get_sset_count,
4382 .set_eee = mv88e6xxx_set_eee,
4383 .get_eee = mv88e6xxx_get_eee,
4384#ifdef CONFIG_NET_DSA_HWMON
4385 .get_temp = mv88e6xxx_get_temp,
4386 .get_temp_limit = mv88e6xxx_get_temp_limit,
4387 .set_temp_limit = mv88e6xxx_set_temp_limit,
4388 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
4389#endif
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004390 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004391 .get_eeprom = mv88e6xxx_get_eeprom,
4392 .set_eeprom = mv88e6xxx_set_eeprom,
4393 .get_regs_len = mv88e6xxx_get_regs_len,
4394 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004395 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004396 .port_bridge_join = mv88e6xxx_port_bridge_join,
4397 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4398 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004399 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004400 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4401 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4402 .port_vlan_add = mv88e6xxx_port_vlan_add,
4403 .port_vlan_del = mv88e6xxx_port_vlan_del,
4404 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4405 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4406 .port_fdb_add = mv88e6xxx_port_fdb_add,
4407 .port_fdb_del = mv88e6xxx_port_fdb_del,
4408 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004409 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4410 .port_mdb_add = mv88e6xxx_port_mdb_add,
4411 .port_mdb_del = mv88e6xxx_port_mdb_del,
4412 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004413};
4414
Vivien Didelotfad09c72016-06-21 12:28:20 -04004415static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004416 struct device_node *np)
4417{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004418 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004419 struct dsa_switch *ds;
4420
4421 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
4422 if (!ds)
4423 return -ENOMEM;
4424
4425 ds->dev = dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004426 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004427 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004428
4429 dev_set_drvdata(dev, ds);
4430
4431 return dsa_register_switch(ds, np);
4432}
4433
Vivien Didelotfad09c72016-06-21 12:28:20 -04004434static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004435{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004436 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004437}
4438
Vivien Didelot57d32312016-06-20 13:13:58 -04004439static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004440{
4441 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004442 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004443 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004444 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004445 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004446 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004447
Vivien Didelotcaac8542016-06-20 13:14:09 -04004448 compat_info = of_device_get_match_data(dev);
4449 if (!compat_info)
4450 return -EINVAL;
4451
Vivien Didelotfad09c72016-06-21 12:28:20 -04004452 chip = mv88e6xxx_alloc_chip(dev);
4453 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004454 return -ENOMEM;
4455
Vivien Didelotfad09c72016-06-21 12:28:20 -04004456 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004457
Andrew Lunn56995cb2016-12-03 04:35:19 +01004458 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4459 if (err)
4460 return err;
4461
Vivien Didelotfad09c72016-06-21 12:28:20 -04004462 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004463 if (err)
4464 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004465
Andrew Lunnb4308f02016-11-21 23:26:55 +01004466 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4467 if (IS_ERR(chip->reset))
4468 return PTR_ERR(chip->reset);
4469
Vivien Didelotfad09c72016-06-21 12:28:20 -04004470 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004471 if (err)
4472 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004473
Vivien Didelote57e5e72016-08-15 17:19:00 -04004474 mv88e6xxx_phy_init(chip);
4475
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004476 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004477 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004478 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004479
Andrew Lunndc30c352016-10-16 19:56:49 +02004480 mutex_lock(&chip->reg_lock);
4481 err = mv88e6xxx_switch_reset(chip);
4482 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004483 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004484 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004485
Andrew Lunndc30c352016-10-16 19:56:49 +02004486 chip->irq = of_irq_get(np, 0);
4487 if (chip->irq == -EPROBE_DEFER) {
4488 err = chip->irq;
4489 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004490 }
4491
Andrew Lunndc30c352016-10-16 19:56:49 +02004492 if (chip->irq > 0) {
4493 /* Has to be performed before the MDIO bus is created,
4494 * because the PHYs will link there interrupts to these
4495 * interrupt controllers
4496 */
4497 mutex_lock(&chip->reg_lock);
4498 err = mv88e6xxx_g1_irq_setup(chip);
4499 mutex_unlock(&chip->reg_lock);
4500
4501 if (err)
4502 goto out;
4503
4504 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4505 err = mv88e6xxx_g2_irq_setup(chip);
4506 if (err)
4507 goto out_g1_irq;
4508 }
4509 }
4510
4511 err = mv88e6xxx_mdio_register(chip, np);
4512 if (err)
4513 goto out_g2_irq;
4514
4515 err = mv88e6xxx_register_switch(chip, np);
4516 if (err)
4517 goto out_mdio;
4518
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004519 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004520
4521out_mdio:
4522 mv88e6xxx_mdio_unregister(chip);
4523out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004524 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004525 mv88e6xxx_g2_irq_free(chip);
4526out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004527 if (chip->irq > 0) {
4528 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004529 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004530 mutex_unlock(&chip->reg_lock);
4531 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004532out:
4533 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004534}
4535
4536static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4537{
4538 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004539 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004540
Andrew Lunn930188c2016-08-22 16:01:03 +02004541 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004542 mv88e6xxx_unregister_switch(chip);
4543 mv88e6xxx_mdio_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004544
Andrew Lunn467126442016-11-20 20:14:15 +01004545 if (chip->irq > 0) {
4546 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4547 mv88e6xxx_g2_irq_free(chip);
4548 mv88e6xxx_g1_irq_free(chip);
4549 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004550}
4551
4552static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004553 {
4554 .compatible = "marvell,mv88e6085",
4555 .data = &mv88e6xxx_table[MV88E6085],
4556 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004557 {
4558 .compatible = "marvell,mv88e6190",
4559 .data = &mv88e6xxx_table[MV88E6190],
4560 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004561 { /* sentinel */ },
4562};
4563
4564MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4565
4566static struct mdio_driver mv88e6xxx_driver = {
4567 .probe = mv88e6xxx_probe,
4568 .remove = mv88e6xxx_remove,
4569 .mdiodrv.driver = {
4570 .name = "mv88e6085",
4571 .of_match_table = mv88e6xxx_of_match,
4572 },
4573};
4574
Ben Hutchings98e67302011-11-25 14:36:19 +00004575static int __init mv88e6xxx_init(void)
4576{
Vivien Didelot9d490b42016-08-23 12:38:56 -04004577 register_switch_driver(&mv88e6xxx_switch_ops);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004578 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004579}
4580module_init(mv88e6xxx_init);
4581
4582static void __exit mv88e6xxx_cleanup(void)
4583{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004584 mdio_driver_unregister(&mv88e6xxx_driver);
Vivien Didelot9d490b42016-08-23 12:38:56 -04004585 unregister_switch_driver(&mv88e6xxx_switch_ops);
Ben Hutchings98e67302011-11-25 14:36:19 +00004586}
4587module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004588
4589MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4590MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4591MODULE_LICENSE("GPL");