blob: eea8e0176e33819fdf2dcdf2191f390ad5c0f52b [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
Vivien Didelot0d3cd4b2016-06-21 12:28:19 -04002 * Marvell 88e6xxx Ethernet switch single-chip support
3 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00004 * Copyright (c) 2008 Marvell Semiconductor
5 *
Vivien Didelotb8fee952015-08-13 12:52:19 -04006 * Copyright (c) 2015 CMC Electronics, Inc.
7 * Added support for VLAN Table Unit operations
8 *
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02009 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
10 *
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
Barry Grussling19b2f972013-01-08 16:05:54 +000017#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070018#include <linux/etherdevice.h>
Andrew Lunndea87022015-08-31 15:56:47 +020019#include <linux/ethtool.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070020#include <linux/if_bridge.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020021#include <linux/interrupt.h>
22#include <linux/irq.h>
23#include <linux/irqdomain.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000024#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000025#include <linux/list.h>
Andrew Lunn14c7b3c2016-05-10 23:27:21 +020026#include <linux/mdio.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000027#include <linux/module.h>
Vivien Didelotcaac8542016-06-20 13:14:09 -040028#include <linux/of_device.h>
Andrew Lunndc30c352016-10-16 19:56:49 +020029#include <linux/of_irq.h>
Andrew Lunnb516d452016-06-04 21:17:06 +020030#include <linux/of_mdio.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000031#include <linux/netdevice.h>
Andrew Lunnc8c1b39a2015-11-20 03:56:24 +010032#include <linux/gpio/consumer.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000033#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000034#include <net/dsa.h>
Vivien Didelot1f36faf2015-10-08 11:35:13 -040035#include <net/switchdev.h>
Vivien Didelotec561272016-09-02 14:45:33 -040036
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000037#include "mv88e6xxx.h"
Vivien Didelota935c052016-09-29 12:21:53 -040038#include "global1.h"
Vivien Didelotec561272016-09-02 14:45:33 -040039#include "global2.h"
Vivien Didelot18abed22016-11-04 03:23:26 +010040#include "port.h"
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000041
Vivien Didelotfad09c72016-06-21 12:28:20 -040042static void assert_reg_lock(struct mv88e6xxx_chip *chip)
Vivien Didelot3996a4f2015-10-30 18:56:45 -040043{
Vivien Didelotfad09c72016-06-21 12:28:20 -040044 if (unlikely(!mutex_is_locked(&chip->reg_lock))) {
45 dev_err(chip->dev, "Switch registers lock not held!\n");
Vivien Didelot3996a4f2015-10-30 18:56:45 -040046 dump_stack();
47 }
48}
49
Vivien Didelot914b32f2016-06-20 13:14:11 -040050/* The switch ADDR[4:1] configuration pins define the chip SMI device address
51 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
52 *
53 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
54 * is the only device connected to the SMI master. In this mode it responds to
55 * all 32 possible SMI addresses, and thus maps directly the internal devices.
56 *
57 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
58 * multiple devices to share the SMI interface. In this mode it responds to only
59 * 2 registers, used to indirectly access the internal SMI devices.
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000060 */
Vivien Didelot914b32f2016-06-20 13:14:11 -040061
Vivien Didelotfad09c72016-06-21 12:28:20 -040062static int mv88e6xxx_smi_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040063 int addr, int reg, u16 *val)
64{
Vivien Didelotfad09c72016-06-21 12:28:20 -040065 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040066 return -EOPNOTSUPP;
67
Vivien Didelotfad09c72016-06-21 12:28:20 -040068 return chip->smi_ops->read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040069}
70
Vivien Didelotfad09c72016-06-21 12:28:20 -040071static int mv88e6xxx_smi_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040072 int addr, int reg, u16 val)
73{
Vivien Didelotfad09c72016-06-21 12:28:20 -040074 if (!chip->smi_ops)
Vivien Didelot914b32f2016-06-20 13:14:11 -040075 return -EOPNOTSUPP;
76
Vivien Didelotfad09c72016-06-21 12:28:20 -040077 return chip->smi_ops->write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -040078}
79
Vivien Didelotfad09c72016-06-21 12:28:20 -040080static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040081 int addr, int reg, u16 *val)
82{
83 int ret;
84
Vivien Didelotfad09c72016-06-21 12:28:20 -040085 ret = mdiobus_read_nested(chip->bus, addr, reg);
Vivien Didelot914b32f2016-06-20 13:14:11 -040086 if (ret < 0)
87 return ret;
88
89 *val = ret & 0xffff;
90
91 return 0;
92}
93
Vivien Didelotfad09c72016-06-21 12:28:20 -040094static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -040095 int addr, int reg, u16 val)
96{
97 int ret;
98
Vivien Didelotfad09c72016-06-21 12:28:20 -040099 ret = mdiobus_write_nested(chip->bus, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400100 if (ret < 0)
101 return ret;
102
103 return 0;
104}
105
Vivien Didelotc08026a2016-09-29 12:21:59 -0400106static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400107 .read = mv88e6xxx_smi_single_chip_read,
108 .write = mv88e6xxx_smi_single_chip_write,
109};
110
Vivien Didelotfad09c72016-06-21 12:28:20 -0400111static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000112{
113 int ret;
114 int i;
115
116 for (i = 0; i < 16; i++) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400117 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000118 if (ret < 0)
119 return ret;
120
Andrew Lunncca8b132015-04-02 04:06:39 +0200121 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000122 return 0;
123 }
124
125 return -ETIMEDOUT;
126}
127
Vivien Didelotfad09c72016-06-21 12:28:20 -0400128static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400129 int addr, int reg, u16 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000130{
131 int ret;
132
Barry Grussling3675c8d2013-01-08 16:05:53 +0000133 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400134 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000135 if (ret < 0)
136 return ret;
137
Barry Grussling3675c8d2013-01-08 16:05:53 +0000138 /* Transmit the read command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400139 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Neil Armstrong6e899e62015-10-22 10:37:53 +0200140 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000141 if (ret < 0)
142 return ret;
143
Barry Grussling3675c8d2013-01-08 16:05:53 +0000144 /* Wait for the read command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400145 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000146 if (ret < 0)
147 return ret;
148
Barry Grussling3675c8d2013-01-08 16:05:53 +0000149 /* Read the data. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400150 ret = mdiobus_read_nested(chip->bus, chip->sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000151 if (ret < 0)
152 return ret;
153
Vivien Didelot914b32f2016-06-20 13:14:11 -0400154 *val = ret & 0xffff;
155
156 return 0;
157}
158
Vivien Didelotfad09c72016-06-21 12:28:20 -0400159static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400160 int addr, int reg, u16 val)
161{
162 int ret;
163
164 /* Wait for the bus to become free. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400165 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400166 if (ret < 0)
167 return ret;
168
169 /* Transmit the data to write. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400170 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_DATA, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400171 if (ret < 0)
172 return ret;
173
174 /* Transmit the write command. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400175 ret = mdiobus_write_nested(chip->bus, chip->sw_addr, SMI_CMD,
Vivien Didelot914b32f2016-06-20 13:14:11 -0400176 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
177 if (ret < 0)
178 return ret;
179
180 /* Wait for the write command to complete. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400181 ret = mv88e6xxx_smi_multi_chip_wait(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400182 if (ret < 0)
183 return ret;
184
185 return 0;
186}
187
Vivien Didelotc08026a2016-09-29 12:21:59 -0400188static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
Vivien Didelot914b32f2016-06-20 13:14:11 -0400189 .read = mv88e6xxx_smi_multi_chip_read,
190 .write = mv88e6xxx_smi_multi_chip_write,
191};
192
Vivien Didelotec561272016-09-02 14:45:33 -0400193int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400194{
195 int err;
196
Vivien Didelotfad09c72016-06-21 12:28:20 -0400197 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400198
Vivien Didelotfad09c72016-06-21 12:28:20 -0400199 err = mv88e6xxx_smi_read(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400200 if (err)
201 return err;
202
Vivien Didelotfad09c72016-06-21 12:28:20 -0400203 dev_dbg(chip->dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400204 addr, reg, *val);
205
206 return 0;
207}
208
Vivien Didelotec561272016-09-02 14:45:33 -0400209int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val)
Vivien Didelot914b32f2016-06-20 13:14:11 -0400210{
211 int err;
212
Vivien Didelotfad09c72016-06-21 12:28:20 -0400213 assert_reg_lock(chip);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400214
Vivien Didelotfad09c72016-06-21 12:28:20 -0400215 err = mv88e6xxx_smi_write(chip, addr, reg, val);
Vivien Didelot914b32f2016-06-20 13:14:11 -0400216 if (err)
217 return err;
218
Vivien Didelotfad09c72016-06-21 12:28:20 -0400219 dev_dbg(chip->dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
Vivien Didelot914b32f2016-06-20 13:14:11 -0400220 addr, reg, val);
221
222 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000223}
224
Vivien Didelote57e5e72016-08-15 17:19:00 -0400225static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
226 int reg, u16 *val)
227{
228 int addr = phy; /* PHY devices addresses start at 0x0 */
229
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400230 if (!chip->info->ops->phy_read)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400231 return -EOPNOTSUPP;
232
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400233 return chip->info->ops->phy_read(chip, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400234}
235
236static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
237 int reg, u16 val)
238{
239 int addr = phy; /* PHY devices addresses start at 0x0 */
240
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400241 if (!chip->info->ops->phy_write)
Vivien Didelote57e5e72016-08-15 17:19:00 -0400242 return -EOPNOTSUPP;
243
Vivien Didelotb3469dd2016-09-29 12:22:00 -0400244 return chip->info->ops->phy_write(chip, addr, reg, val);
Vivien Didelote57e5e72016-08-15 17:19:00 -0400245}
246
Vivien Didelot09cb7df2016-08-15 17:19:01 -0400247static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
248{
249 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_PHY_PAGE))
250 return -EOPNOTSUPP;
251
252 return mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
253}
254
255static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip *chip, int phy)
256{
257 int err;
258
259 /* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
260 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, PHY_PAGE_COPPER);
261 if (unlikely(err)) {
262 dev_err(chip->dev, "failed to restore PHY %d page Copper (%d)\n",
263 phy, err);
264 }
265}
266
267static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy,
268 u8 page, int reg, u16 *val)
269{
270 int err;
271
272 /* There is no paging for registers 22 */
273 if (reg == PHY_PAGE)
274 return -EINVAL;
275
276 err = mv88e6xxx_phy_page_get(chip, phy, page);
277 if (!err) {
278 err = mv88e6xxx_phy_read(chip, phy, reg, val);
279 mv88e6xxx_phy_page_put(chip, phy);
280 }
281
282 return err;
283}
284
285static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy,
286 u8 page, int reg, u16 val)
287{
288 int err;
289
290 /* There is no paging for registers 22 */
291 if (reg == PHY_PAGE)
292 return -EINVAL;
293
294 err = mv88e6xxx_phy_page_get(chip, phy, page);
295 if (!err) {
296 err = mv88e6xxx_phy_write(chip, phy, PHY_PAGE, page);
297 mv88e6xxx_phy_page_put(chip, phy);
298 }
299
300 return err;
301}
302
303static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
304{
305 return mv88e6xxx_phy_page_read(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
306 reg, val);
307}
308
309static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
310{
311 return mv88e6xxx_phy_page_write(chip, ADDR_SERDES, SERDES_PAGE_FIBER,
312 reg, val);
313}
314
Andrew Lunndc30c352016-10-16 19:56:49 +0200315static void mv88e6xxx_g1_irq_mask(struct irq_data *d)
316{
317 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
318 unsigned int n = d->hwirq;
319
320 chip->g1_irq.masked |= (1 << n);
321}
322
323static void mv88e6xxx_g1_irq_unmask(struct irq_data *d)
324{
325 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
326 unsigned int n = d->hwirq;
327
328 chip->g1_irq.masked &= ~(1 << n);
329}
330
331static irqreturn_t mv88e6xxx_g1_irq_thread_fn(int irq, void *dev_id)
332{
333 struct mv88e6xxx_chip *chip = dev_id;
334 unsigned int nhandled = 0;
335 unsigned int sub_irq;
336 unsigned int n;
337 u16 reg;
338 int err;
339
340 mutex_lock(&chip->reg_lock);
341 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
342 mutex_unlock(&chip->reg_lock);
343
344 if (err)
345 goto out;
346
347 for (n = 0; n < chip->g1_irq.nirqs; ++n) {
348 if (reg & (1 << n)) {
349 sub_irq = irq_find_mapping(chip->g1_irq.domain, n);
350 handle_nested_irq(sub_irq);
351 ++nhandled;
352 }
353 }
354out:
355 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
356}
357
358static void mv88e6xxx_g1_irq_bus_lock(struct irq_data *d)
359{
360 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
361
362 mutex_lock(&chip->reg_lock);
363}
364
365static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data *d)
366{
367 struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);
368 u16 mask = GENMASK(chip->g1_irq.nirqs, 0);
369 u16 reg;
370 int err;
371
372 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &reg);
373 if (err)
374 goto out;
375
376 reg &= ~mask;
377 reg |= (~chip->g1_irq.masked & mask);
378
379 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
380 if (err)
381 goto out;
382
383out:
384 mutex_unlock(&chip->reg_lock);
385}
386
387static struct irq_chip mv88e6xxx_g1_irq_chip = {
388 .name = "mv88e6xxx-g1",
389 .irq_mask = mv88e6xxx_g1_irq_mask,
390 .irq_unmask = mv88e6xxx_g1_irq_unmask,
391 .irq_bus_lock = mv88e6xxx_g1_irq_bus_lock,
392 .irq_bus_sync_unlock = mv88e6xxx_g1_irq_bus_sync_unlock,
393};
394
395static int mv88e6xxx_g1_irq_domain_map(struct irq_domain *d,
396 unsigned int irq,
397 irq_hw_number_t hwirq)
398{
399 struct mv88e6xxx_chip *chip = d->host_data;
400
401 irq_set_chip_data(irq, d->host_data);
402 irq_set_chip_and_handler(irq, &chip->g1_irq.chip, handle_level_irq);
403 irq_set_noprobe(irq);
404
405 return 0;
406}
407
408static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops = {
409 .map = mv88e6xxx_g1_irq_domain_map,
410 .xlate = irq_domain_xlate_twocell,
411};
412
413static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip *chip)
414{
415 int irq, virq;
Andrew Lunn3460a572016-11-20 20:14:16 +0100416 u16 mask;
417
418 mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
419 mask |= GENMASK(chip->g1_irq.nirqs, 0);
420 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
421
422 free_irq(chip->irq, chip);
Andrew Lunndc30c352016-10-16 19:56:49 +0200423
Andreas Färber5edef2f2016-11-27 23:26:28 +0100424 for (irq = 0; irq < chip->g1_irq.nirqs; irq++) {
Andrew Lunna3db3d32016-11-20 20:14:14 +0100425 virq = irq_find_mapping(chip->g1_irq.domain, irq);
Andrew Lunndc30c352016-10-16 19:56:49 +0200426 irq_dispose_mapping(virq);
427 }
428
Andrew Lunna3db3d32016-11-20 20:14:14 +0100429 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200430}
431
432static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
433{
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100434 int err, irq, virq;
435 u16 reg, mask;
Andrew Lunndc30c352016-10-16 19:56:49 +0200436
437 chip->g1_irq.nirqs = chip->info->g1_irqs;
438 chip->g1_irq.domain = irq_domain_add_simple(
439 NULL, chip->g1_irq.nirqs, 0,
440 &mv88e6xxx_g1_irq_domain_ops, chip);
441 if (!chip->g1_irq.domain)
442 return -ENOMEM;
443
444 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
445 irq_create_mapping(chip->g1_irq.domain, irq);
446
447 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
448 chip->g1_irq.masked = ~0;
449
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100450 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200451 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100452 goto out_mapping;
Andrew Lunndc30c352016-10-16 19:56:49 +0200453
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100454 mask &= ~GENMASK(chip->g1_irq.nirqs, 0);
Andrew Lunndc30c352016-10-16 19:56:49 +0200455
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100456 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
Andrew Lunndc30c352016-10-16 19:56:49 +0200457 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100458 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200459
460 /* Reading the interrupt status clears (most of) them */
461 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &reg);
462 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100463 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200464
465 err = request_threaded_irq(chip->irq, NULL,
466 mv88e6xxx_g1_irq_thread_fn,
467 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
468 dev_name(chip->dev), chip);
469 if (err)
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100470 goto out_disable;
Andrew Lunndc30c352016-10-16 19:56:49 +0200471
472 return 0;
473
Andrew Lunn3dd0ef02016-11-20 20:14:17 +0100474out_disable:
475 mask |= GENMASK(chip->g1_irq.nirqs, 0);
476 mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, mask);
477
478out_mapping:
479 for (irq = 0; irq < 16; irq++) {
480 virq = irq_find_mapping(chip->g1_irq.domain, irq);
481 irq_dispose_mapping(virq);
482 }
483
484 irq_domain_remove(chip->g1_irq.domain);
Andrew Lunndc30c352016-10-16 19:56:49 +0200485
486 return err;
487}
488
Vivien Didelotec561272016-09-02 14:45:33 -0400489int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
Vivien Didelot2d79af62016-08-15 17:18:57 -0400490{
Andrew Lunn6441e6692016-08-19 00:01:55 +0200491 int i;
Vivien Didelot2d79af62016-08-15 17:18:57 -0400492
Andrew Lunn6441e6692016-08-19 00:01:55 +0200493 for (i = 0; i < 16; i++) {
Vivien Didelot2d79af62016-08-15 17:18:57 -0400494 u16 val;
495 int err;
496
497 err = mv88e6xxx_read(chip, addr, reg, &val);
498 if (err)
499 return err;
500
501 if (!(val & mask))
502 return 0;
503
504 usleep_range(1000, 2000);
505 }
506
Andrew Lunn30853552016-08-19 00:01:57 +0200507 dev_err(chip->dev, "Timeout while waiting for switch\n");
Vivien Didelot2d79af62016-08-15 17:18:57 -0400508 return -ETIMEDOUT;
509}
510
Vivien Didelotf22ab642016-07-18 20:45:31 -0400511/* Indirect write to single pointer-data register with an Update bit */
Vivien Didelotec561272016-09-02 14:45:33 -0400512int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
Vivien Didelotf22ab642016-07-18 20:45:31 -0400513{
514 u16 val;
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200515 int err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400516
517 /* Wait until the previous operation is completed */
Andrew Lunn0f02b4f2016-08-19 00:01:56 +0200518 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
519 if (err)
520 return err;
Vivien Didelotf22ab642016-07-18 20:45:31 -0400521
522 /* Set the Update bit to trigger a write operation */
523 val = BIT(15) | update;
524
525 return mv88e6xxx_write(chip, addr, reg, val);
526}
527
Vivien Didelota935c052016-09-29 12:21:53 -0400528static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000529{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500530 if (!chip->info->ops->ppu_disable)
531 return 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000532
Vivien Didelota199d8b2016-12-05 17:30:28 -0500533 return chip->info->ops->ppu_disable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000534}
535
Vivien Didelotfad09c72016-06-21 12:28:20 -0400536static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000537{
Vivien Didelota199d8b2016-12-05 17:30:28 -0500538 if (!chip->info->ops->ppu_enable)
539 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000540
Vivien Didelota199d8b2016-12-05 17:30:28 -0500541 return chip->info->ops->ppu_enable(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000542}
543
544static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
545{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400546 struct mv88e6xxx_chip *chip;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000547
Vivien Didelotfad09c72016-06-21 12:28:20 -0400548 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
Vivien Didelot762eb672016-06-04 21:16:54 +0200549
Vivien Didelotfad09c72016-06-21 12:28:20 -0400550 mutex_lock(&chip->reg_lock);
Vivien Didelot762eb672016-06-04 21:16:54 +0200551
Vivien Didelotfad09c72016-06-21 12:28:20 -0400552 if (mutex_trylock(&chip->ppu_mutex)) {
553 if (mv88e6xxx_ppu_enable(chip) == 0)
554 chip->ppu_disabled = 0;
555 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000556 }
Vivien Didelot762eb672016-06-04 21:16:54 +0200557
Vivien Didelotfad09c72016-06-21 12:28:20 -0400558 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000559}
560
561static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
562{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400563 struct mv88e6xxx_chip *chip = (void *)_ps;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000564
Vivien Didelotfad09c72016-06-21 12:28:20 -0400565 schedule_work(&chip->ppu_work);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000566}
567
Vivien Didelotfad09c72016-06-21 12:28:20 -0400568static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000569{
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000570 int ret;
571
Vivien Didelotfad09c72016-06-21 12:28:20 -0400572 mutex_lock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000573
Barry Grussling3675c8d2013-01-08 16:05:53 +0000574 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000575 * we can access the PHY registers. If it was already
576 * disabled, cancel the timer that is going to re-enable
577 * it.
578 */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400579 if (!chip->ppu_disabled) {
580 ret = mv88e6xxx_ppu_disable(chip);
Barry Grussling85686582013-01-08 16:05:56 +0000581 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400582 mutex_unlock(&chip->ppu_mutex);
Barry Grussling85686582013-01-08 16:05:56 +0000583 return ret;
584 }
Vivien Didelotfad09c72016-06-21 12:28:20 -0400585 chip->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000586 } else {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400587 del_timer(&chip->ppu_timer);
Barry Grussling85686582013-01-08 16:05:56 +0000588 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000589 }
590
591 return ret;
592}
593
Vivien Didelotfad09c72016-06-21 12:28:20 -0400594static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000595{
Barry Grussling3675c8d2013-01-08 16:05:53 +0000596 /* Schedule a timer to re-enable the PHY polling unit. */
Vivien Didelotfad09c72016-06-21 12:28:20 -0400597 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
598 mutex_unlock(&chip->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000599}
600
Vivien Didelotfad09c72016-06-21 12:28:20 -0400601static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000602{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400603 mutex_init(&chip->ppu_mutex);
604 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
Wei Yongjun68497a82016-10-22 14:28:00 +0000605 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
606 (unsigned long)chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000607}
608
Andrew Lunn930188c2016-08-22 16:01:03 +0200609static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
610{
611 del_timer_sync(&chip->ppu_timer);
612}
613
Vivien Didelote57e5e72016-08-15 17:19:00 -0400614static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip, int addr,
615 int reg, u16 *val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000616{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400617 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000618
Vivien Didelote57e5e72016-08-15 17:19:00 -0400619 err = mv88e6xxx_ppu_access_get(chip);
620 if (!err) {
621 err = mv88e6xxx_read(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400622 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000623 }
624
Vivien Didelote57e5e72016-08-15 17:19:00 -0400625 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000626}
627
Vivien Didelote57e5e72016-08-15 17:19:00 -0400628static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip, int addr,
629 int reg, u16 val)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000630{
Vivien Didelote57e5e72016-08-15 17:19:00 -0400631 int err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000632
Vivien Didelote57e5e72016-08-15 17:19:00 -0400633 err = mv88e6xxx_ppu_access_get(chip);
634 if (!err) {
635 err = mv88e6xxx_write(chip, addr, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400636 mv88e6xxx_ppu_access_put(chip);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000637 }
638
Vivien Didelote57e5e72016-08-15 17:19:00 -0400639 return err;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000640}
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000641
Vivien Didelotfad09c72016-06-21 12:28:20 -0400642static bool mv88e6xxx_6095_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200643{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400644 return chip->info->family == MV88E6XXX_FAMILY_6095;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200645}
646
Vivien Didelotfad09c72016-06-21 12:28:20 -0400647static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200648{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400649 return chip->info->family == MV88E6XXX_FAMILY_6097;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200650}
651
Vivien Didelotfad09c72016-06-21 12:28:20 -0400652static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200653{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400654 return chip->info->family == MV88E6XXX_FAMILY_6165;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200655}
656
Vivien Didelotfad09c72016-06-21 12:28:20 -0400657static bool mv88e6xxx_6185_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200658{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400659 return chip->info->family == MV88E6XXX_FAMILY_6185;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200660}
661
Vivien Didelotfad09c72016-06-21 12:28:20 -0400662static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700663{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400664 return chip->info->family == MV88E6XXX_FAMILY_6320;
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700665}
666
Vivien Didelotfad09c72016-06-21 12:28:20 -0400667static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
Andrew Lunn54d792f2015-05-06 01:09:47 +0200668{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400669 return chip->info->family == MV88E6XXX_FAMILY_6351;
Andrew Lunn54d792f2015-05-06 01:09:47 +0200670}
671
Vivien Didelotfad09c72016-06-21 12:28:20 -0400672static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200673{
Vivien Didelotfad09c72016-06-21 12:28:20 -0400674 return chip->info->family == MV88E6XXX_FAMILY_6352;
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200675}
676
Vivien Didelotd78343d2016-11-04 03:23:36 +0100677static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
678 int link, int speed, int duplex,
679 phy_interface_t mode)
680{
681 int err;
682
683 if (!chip->info->ops->port_set_link)
684 return 0;
685
686 /* Port's MAC control must not be changed unless the link is down */
687 err = chip->info->ops->port_set_link(chip, port, 0);
688 if (err)
689 return err;
690
691 if (chip->info->ops->port_set_speed) {
692 err = chip->info->ops->port_set_speed(chip, port, speed);
693 if (err && err != -EOPNOTSUPP)
694 goto restore_link;
695 }
696
697 if (chip->info->ops->port_set_duplex) {
698 err = chip->info->ops->port_set_duplex(chip, port, duplex);
699 if (err && err != -EOPNOTSUPP)
700 goto restore_link;
701 }
702
703 if (chip->info->ops->port_set_rgmii_delay) {
704 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
705 if (err && err != -EOPNOTSUPP)
706 goto restore_link;
707 }
708
709 err = 0;
710restore_link:
711 if (chip->info->ops->port_set_link(chip, port, link))
712 netdev_err(chip->ds->ports[port].netdev,
713 "failed to restore MAC's link\n");
714
715 return err;
716}
717
Andrew Lunndea87022015-08-31 15:56:47 +0200718/* We expect the switch to perform auto negotiation if there is a real
719 * phy. However, in the case of a fixed link phy, we force the port
720 * settings from the fixed link settings.
721 */
Vivien Didelotf81ec902016-05-09 13:22:58 -0400722static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
723 struct phy_device *phydev)
Andrew Lunndea87022015-08-31 15:56:47 +0200724{
Vivien Didelot04bed142016-08-31 18:06:13 -0400725 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200726 int err;
Andrew Lunndea87022015-08-31 15:56:47 +0200727
728 if (!phy_is_pseudo_fixed_link(phydev))
729 return;
730
Vivien Didelotfad09c72016-06-21 12:28:20 -0400731 mutex_lock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100732 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
733 phydev->duplex, phydev->interface);
Vivien Didelotfad09c72016-06-21 12:28:20 -0400734 mutex_unlock(&chip->reg_lock);
Vivien Didelotd78343d2016-11-04 03:23:36 +0100735
736 if (err && err != -EOPNOTSUPP)
737 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
Andrew Lunndea87022015-08-31 15:56:47 +0200738}
739
Andrew Lunna605a0f2016-11-21 23:26:58 +0100740static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000741{
Andrew Lunna605a0f2016-11-21 23:26:58 +0100742 if (!chip->info->ops->stats_snapshot)
743 return -EOPNOTSUPP;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000744
Andrew Lunna605a0f2016-11-21 23:26:58 +0100745 return chip->info->ops->stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000746}
747
Andrew Lunne413e7e2015-04-02 04:06:38 +0200748static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
Andrew Lunndfafe442016-11-21 23:27:02 +0100749 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, },
750 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, },
751 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, },
752 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, },
753 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, },
754 { "in_pause", 4, 0x16, STATS_TYPE_BANK0, },
755 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, },
756 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, },
757 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, },
758 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, },
759 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, },
760 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, },
761 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, },
762 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, },
763 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, },
764 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, },
765 { "out_pause", 4, 0x15, STATS_TYPE_BANK0, },
766 { "excessive", 4, 0x11, STATS_TYPE_BANK0, },
767 { "collisions", 4, 0x1e, STATS_TYPE_BANK0, },
768 { "deferred", 4, 0x05, STATS_TYPE_BANK0, },
769 { "single", 4, 0x14, STATS_TYPE_BANK0, },
770 { "multiple", 4, 0x17, STATS_TYPE_BANK0, },
771 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, },
772 { "late", 4, 0x1f, STATS_TYPE_BANK0, },
773 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, },
774 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, },
775 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, },
776 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, },
777 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, },
778 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, },
779 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, },
780 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, },
781 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, },
782 { "in_discards", 4, 0x00, STATS_TYPE_BANK1, },
783 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, },
784 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, },
785 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, },
786 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, },
787 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, },
788 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, },
789 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, },
790 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, },
791 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, },
792 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, },
793 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, },
794 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, },
795 { "in_management", 4, 0x0f, STATS_TYPE_BANK1, },
796 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, },
797 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, },
798 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, },
799 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, },
800 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, },
801 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, },
802 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, },
803 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, },
804 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, },
805 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, },
806 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, },
807 { "out_management", 4, 0x1f, STATS_TYPE_BANK1, },
Andrew Lunne413e7e2015-04-02 04:06:38 +0200808};
809
Vivien Didelotfad09c72016-06-21 12:28:20 -0400810static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100811 struct mv88e6xxx_hw_stat *s,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100812 int port, u16 bank1_select,
813 u16 histogram)
Andrew Lunn80c46272015-06-20 18:42:30 +0200814{
Andrew Lunn80c46272015-06-20 18:42:30 +0200815 u32 low;
816 u32 high = 0;
Andrew Lunndfafe442016-11-21 23:27:02 +0100817 u16 reg = 0;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200818 int err;
Andrew Lunn80c46272015-06-20 18:42:30 +0200819 u64 value;
820
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100821 switch (s->type) {
Andrew Lunndfafe442016-11-21 23:27:02 +0100822 case STATS_TYPE_PORT:
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200823 err = mv88e6xxx_port_read(chip, port, s->reg, &reg);
824 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200825 return UINT64_MAX;
826
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200827 low = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200828 if (s->sizeof_stat == 4) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200829 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
830 if (err)
Andrew Lunn80c46272015-06-20 18:42:30 +0200831 return UINT64_MAX;
Andrew Lunn0e7b9922016-09-21 01:40:31 +0200832 high = reg;
Andrew Lunn80c46272015-06-20 18:42:30 +0200833 }
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100834 break;
Andrew Lunndfafe442016-11-21 23:27:02 +0100835 case STATS_TYPE_BANK1:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100836 reg = bank1_select;
Andrew Lunndfafe442016-11-21 23:27:02 +0100837 /* fall through */
838 case STATS_TYPE_BANK0:
Andrew Lunne0d8b612016-11-21 23:27:04 +0100839 reg |= s->reg | histogram;
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100840 mv88e6xxx_g1_stats_read(chip, reg, &low);
Andrew Lunn80c46272015-06-20 18:42:30 +0200841 if (s->sizeof_stat == 8)
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +0100842 mv88e6xxx_g1_stats_read(chip, reg + 1, &high);
Andrew Lunn80c46272015-06-20 18:42:30 +0200843 }
844 value = (((u64)high) << 16) | low;
845 return value;
846}
847
Andrew Lunndfafe442016-11-21 23:27:02 +0100848static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
849 uint8_t *data, int types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100850{
851 struct mv88e6xxx_hw_stat *stat;
852 int i, j;
853
854 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
855 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100856 if (stat->type & types) {
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100857 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
858 ETH_GSTRING_LEN);
859 j++;
860 }
861 }
862}
863
Andrew Lunndfafe442016-11-21 23:27:02 +0100864static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
865 uint8_t *data)
866{
867 mv88e6xxx_stats_get_strings(chip, data,
868 STATS_TYPE_BANK0 | STATS_TYPE_PORT);
869}
870
871static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
872 uint8_t *data)
873{
874 mv88e6xxx_stats_get_strings(chip, data,
875 STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
876}
877
878static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
879 uint8_t *data)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100880{
Vivien Didelot04bed142016-08-31 18:06:13 -0400881 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunndfafe442016-11-21 23:27:02 +0100882
883 if (chip->info->ops->stats_get_strings)
884 chip->info->ops->stats_get_strings(chip, data);
885}
886
887static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip,
888 int types)
889{
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100890 struct mv88e6xxx_hw_stat *stat;
891 int i, j;
892
893 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
894 stat = &mv88e6xxx_hw_stats[i];
Andrew Lunndfafe442016-11-21 23:27:02 +0100895 if (stat->type & types)
Andrew Lunnf5e2ed02015-12-23 13:23:17 +0100896 j++;
897 }
898 return j;
899}
900
Andrew Lunndfafe442016-11-21 23:27:02 +0100901static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip *chip)
902{
903 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
904 STATS_TYPE_PORT);
905}
906
907static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip *chip)
908{
909 return mv88e6xxx_stats_get_sset_count(chip, STATS_TYPE_BANK0 |
910 STATS_TYPE_BANK1);
911}
912
913static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
914{
915 struct mv88e6xxx_chip *chip = ds->priv;
916
917 if (chip->info->ops->stats_get_sset_count)
918 return chip->info->ops->stats_get_sset_count(chip);
919
920 return 0;
921}
922
Andrew Lunn052f9472016-11-21 23:27:03 +0100923static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100924 uint64_t *data, int types,
925 u16 bank1_select, u16 histogram)
Andrew Lunn052f9472016-11-21 23:27:03 +0100926{
927 struct mv88e6xxx_hw_stat *stat;
928 int i, j;
929
930 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
931 stat = &mv88e6xxx_hw_stats[i];
932 if (stat->type & types) {
Andrew Lunne0d8b612016-11-21 23:27:04 +0100933 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port,
934 bank1_select,
935 histogram);
Andrew Lunn052f9472016-11-21 23:27:03 +0100936 j++;
937 }
938 }
939}
940
941static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
942 uint64_t *data)
943{
944 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100945 STATS_TYPE_BANK0 | STATS_TYPE_PORT,
946 0, GLOBAL_STATS_OP_HIST_RX_TX);
Andrew Lunn052f9472016-11-21 23:27:03 +0100947}
948
949static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
950 uint64_t *data)
951{
952 return mv88e6xxx_stats_get_stats(chip, port, data,
Andrew Lunne0d8b612016-11-21 23:27:04 +0100953 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
954 GLOBAL_STATS_OP_BANK_1_BIT_9,
955 GLOBAL_STATS_OP_HIST_RX_TX);
956}
957
958static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port,
959 uint64_t *data)
960{
961 return mv88e6xxx_stats_get_stats(chip, port, data,
962 STATS_TYPE_BANK0 | STATS_TYPE_BANK1,
963 GLOBAL_STATS_OP_BANK_1_BIT_10, 0);
Andrew Lunn052f9472016-11-21 23:27:03 +0100964}
965
966static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port,
967 uint64_t *data)
968{
969 if (chip->info->ops->stats_get_stats)
970 chip->info->ops->stats_get_stats(chip, port, data);
971}
972
Vivien Didelotf81ec902016-05-09 13:22:58 -0400973static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
974 uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000975{
Vivien Didelot04bed142016-08-31 18:06:13 -0400976 struct mv88e6xxx_chip *chip = ds->priv;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000977 int ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000978
Vivien Didelotfad09c72016-06-21 12:28:20 -0400979 mutex_lock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000980
Andrew Lunna605a0f2016-11-21 23:26:58 +0100981 ret = mv88e6xxx_stats_snapshot(chip, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000982 if (ret < 0) {
Vivien Didelotfad09c72016-06-21 12:28:20 -0400983 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000984 return;
985 }
Andrew Lunn052f9472016-11-21 23:27:03 +0100986
987 mv88e6xxx_get_stats(chip, port, data);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000988
Vivien Didelotfad09c72016-06-21 12:28:20 -0400989 mutex_unlock(&chip->reg_lock);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000990}
Ben Hutchings98e67302011-11-25 14:36:19 +0000991
Andrew Lunnde2273872016-11-21 23:27:01 +0100992static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip *chip)
993{
994 if (chip->info->ops->stats_set_histogram)
995 return chip->info->ops->stats_set_histogram(chip);
996
997 return 0;
998}
999
Vivien Didelotf81ec902016-05-09 13:22:58 -04001000static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001001{
1002 return 32 * sizeof(u16);
1003}
1004
Vivien Didelotf81ec902016-05-09 13:22:58 -04001005static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1006 struct ethtool_regs *regs, void *_p)
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001007{
Vivien Didelot04bed142016-08-31 18:06:13 -04001008 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001009 int err;
1010 u16 reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001011 u16 *p = _p;
1012 int i;
1013
1014 regs->version = 0;
1015
1016 memset(p, 0xff, 32 * sizeof(u16));
1017
Vivien Didelotfad09c72016-06-21 12:28:20 -04001018 mutex_lock(&chip->reg_lock);
Vivien Didelot23062512016-05-09 13:22:45 -04001019
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001020 for (i = 0; i < 32; i++) {
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001021
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001022 err = mv88e6xxx_port_read(chip, port, i, &reg);
1023 if (!err)
1024 p[i] = reg;
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001025 }
Vivien Didelot23062512016-05-09 13:22:45 -04001026
Vivien Didelotfad09c72016-06-21 12:28:20 -04001027 mutex_unlock(&chip->reg_lock);
Guenter Roecka1ab91f2014-10-29 10:45:05 -07001028}
1029
Vivien Didelotfad09c72016-06-21 12:28:20 -04001030static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001031{
Vivien Didelota935c052016-09-29 12:21:53 -04001032 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001033}
1034
Vivien Didelotf81ec902016-05-09 13:22:58 -04001035static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1036 struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001037{
Vivien Didelot04bed142016-08-31 18:06:13 -04001038 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001039 u16 reg;
1040 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001041
Vivien Didelotfad09c72016-06-21 12:28:20 -04001042 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001043 return -EOPNOTSUPP;
1044
Vivien Didelotfad09c72016-06-21 12:28:20 -04001045 mutex_lock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001046
Vivien Didelot9c938292016-08-15 17:19:02 -04001047 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1048 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001049 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001050
1051 e->eee_enabled = !!(reg & 0x0200);
1052 e->tx_lpi_enabled = !!(reg & 0x0100);
1053
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001054 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
Vivien Didelot9c938292016-08-15 17:19:02 -04001055 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001056 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001057
Andrew Lunncca8b132015-04-02 04:06:39 +02001058 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001059out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001060 mutex_unlock(&chip->reg_lock);
Vivien Didelot9c938292016-08-15 17:19:02 -04001061
1062 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001063}
1064
Vivien Didelotf81ec902016-05-09 13:22:58 -04001065static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1066 struct phy_device *phydev, struct ethtool_eee *e)
Guenter Roeck11b3b452015-03-06 22:23:51 -08001067{
Vivien Didelot04bed142016-08-31 18:06:13 -04001068 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04001069 u16 reg;
1070 int err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001071
Vivien Didelotfad09c72016-06-21 12:28:20 -04001072 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
Vivien Didelotaadbdb82016-05-09 13:22:44 -04001073 return -EOPNOTSUPP;
1074
Vivien Didelotfad09c72016-06-21 12:28:20 -04001075 mutex_lock(&chip->reg_lock);
Guenter Roeck11b3b452015-03-06 22:23:51 -08001076
Vivien Didelot9c938292016-08-15 17:19:02 -04001077 err = mv88e6xxx_phy_read(chip, port, 16, &reg);
1078 if (err)
Andrew Lunn2f40c692015-04-02 04:06:37 +02001079 goto out;
1080
Vivien Didelot9c938292016-08-15 17:19:02 -04001081 reg &= ~0x0300;
Andrew Lunn2f40c692015-04-02 04:06:37 +02001082 if (e->eee_enabled)
1083 reg |= 0x0200;
1084 if (e->tx_lpi_enabled)
1085 reg |= 0x0100;
1086
Vivien Didelot9c938292016-08-15 17:19:02 -04001087 err = mv88e6xxx_phy_write(chip, port, 16, reg);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001088out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001089 mutex_unlock(&chip->reg_lock);
Andrew Lunn2f40c692015-04-02 04:06:37 +02001090
Vivien Didelot9c938292016-08-15 17:19:02 -04001091 return err;
Guenter Roeck11b3b452015-03-06 22:23:51 -08001092}
1093
Vivien Didelotfad09c72016-06-21 12:28:20 -04001094static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001095{
Vivien Didelota935c052016-09-29 12:21:53 -04001096 u16 val;
1097 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001098
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001099 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001100 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1101 if (err)
1102 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001103 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001104 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
Vivien Didelota935c052016-09-29 12:21:53 -04001105 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1106 if (err)
1107 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001108
Vivien Didelota935c052016-09-29 12:21:53 -04001109 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1110 (val & 0xfff) | ((fid << 8) & 0xf000));
1111 if (err)
1112 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001113
1114 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1115 cmd |= fid & 0xf;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001116 }
1117
Vivien Didelota935c052016-09-29 12:21:53 -04001118 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1119 if (err)
1120 return err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001121
Vivien Didelotfad09c72016-06-21 12:28:20 -04001122 return _mv88e6xxx_atu_wait(chip);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001123}
1124
Vivien Didelotfad09c72016-06-21 12:28:20 -04001125static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelot37705b72015-09-04 14:34:11 -04001126 struct mv88e6xxx_atu_entry *entry)
1127{
1128 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1129
1130 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1131 unsigned int mask, shift;
1132
1133 if (entry->trunk) {
1134 data |= GLOBAL_ATU_DATA_TRUNK;
1135 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1136 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1137 } else {
1138 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1139 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1140 }
1141
1142 data |= (entry->portv_trunkid << shift) & mask;
1143 }
1144
Vivien Didelota935c052016-09-29 12:21:53 -04001145 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
Vivien Didelot37705b72015-09-04 14:34:11 -04001146}
1147
Vivien Didelotfad09c72016-06-21 12:28:20 -04001148static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001149 struct mv88e6xxx_atu_entry *entry,
1150 bool static_too)
1151{
1152 int op;
1153 int err;
1154
Vivien Didelotfad09c72016-06-21 12:28:20 -04001155 err = _mv88e6xxx_atu_wait(chip);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001156 if (err)
1157 return err;
1158
Vivien Didelotfad09c72016-06-21 12:28:20 -04001159 err = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001160 if (err)
1161 return err;
1162
1163 if (entry->fid) {
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001164 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1165 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1166 } else {
1167 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1168 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1169 }
1170
Vivien Didelotfad09c72016-06-21 12:28:20 -04001171 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001172}
1173
Vivien Didelotfad09c72016-06-21 12:28:20 -04001174static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001175 u16 fid, bool static_too)
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001176{
1177 struct mv88e6xxx_atu_entry entry = {
1178 .fid = fid,
1179 .state = 0, /* EntryState bits must be 0 */
1180 };
1181
Vivien Didelotfad09c72016-06-21 12:28:20 -04001182 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot7fb5e752015-09-04 14:34:12 -04001183}
1184
Vivien Didelotfad09c72016-06-21 12:28:20 -04001185static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001186 int from_port, int to_port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001187{
1188 struct mv88e6xxx_atu_entry entry = {
1189 .trunk = false,
1190 .fid = fid,
1191 };
1192
1193 /* EntryState bits must be 0xF */
1194 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1195
1196 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1197 entry.portv_trunkid = (to_port & 0x0f) << 4;
1198 entry.portv_trunkid |= from_port & 0x0f;
1199
Vivien Didelotfad09c72016-06-21 12:28:20 -04001200 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001201}
1202
Vivien Didelotfad09c72016-06-21 12:28:20 -04001203static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
Andrew Lunn158bc062016-04-28 21:24:06 -04001204 int port, bool static_too)
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001205{
1206 /* Destination port 0xF means remove the entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001207 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
Vivien Didelot9f4d55d2015-09-04 14:34:15 -04001208}
1209
Vivien Didelotfad09c72016-06-21 12:28:20 -04001210static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001211{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001212 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001213 struct dsa_switch *ds = chip->ds;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001214 u16 output_ports = 0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001215 int i;
1216
1217 /* allow CPU port or DSA link(s) to send frames to every port */
1218 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001219 output_ports = ~0;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001220 } else {
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001221 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001222 /* allow sending frames to every group member */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001223 if (bridge && chip->ports[i].bridge_dev == bridge)
Vivien Didelotb7666ef2016-02-26 13:16:06 -05001224 output_ports |= BIT(i);
1225
1226 /* allow sending frames to CPU port and DSA link(s) */
1227 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1228 output_ports |= BIT(i);
1229 }
1230 }
1231
1232 /* prevent frames from going back out of the port they came in on */
1233 output_ports &= ~BIT(port);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001234
Vivien Didelot5a7921f2016-11-04 03:23:28 +01001235 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001236}
1237
Vivien Didelotf81ec902016-05-09 13:22:58 -04001238static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1239 u8 state)
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001240{
Vivien Didelot04bed142016-08-31 18:06:13 -04001241 struct mv88e6xxx_chip *chip = ds->priv;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001242 int stp_state;
Vivien Didelot553eb542016-05-13 20:38:23 -04001243 int err;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001244
1245 switch (state) {
1246 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001247 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001248 break;
1249 case BR_STATE_BLOCKING:
1250 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001251 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001252 break;
1253 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001254 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001255 break;
1256 case BR_STATE_FORWARDING:
1257 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001258 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001259 break;
1260 }
1261
Vivien Didelotfad09c72016-06-21 12:28:20 -04001262 mutex_lock(&chip->reg_lock);
Vivien Didelote28def332016-11-04 03:23:27 +01001263 err = mv88e6xxx_port_set_state(chip, port, stp_state);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001264 mutex_unlock(&chip->reg_lock);
Vivien Didelot553eb542016-05-13 20:38:23 -04001265
1266 if (err)
Vivien Didelote28def332016-11-04 03:23:27 +01001267 netdev_err(ds->ports[port].netdev, "failed to update state\n");
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001268}
1269
Vivien Didelot749efcb2016-09-22 16:49:24 -04001270static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1271{
1272 struct mv88e6xxx_chip *chip = ds->priv;
1273 int err;
1274
1275 mutex_lock(&chip->reg_lock);
1276 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1277 mutex_unlock(&chip->reg_lock);
1278
1279 if (err)
1280 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1281}
1282
Vivien Didelotfad09c72016-06-21 12:28:20 -04001283static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001284{
Vivien Didelota935c052016-09-29 12:21:53 -04001285 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001286}
1287
Vivien Didelotfad09c72016-06-21 12:28:20 -04001288static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001289{
Vivien Didelota935c052016-09-29 12:21:53 -04001290 int err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001291
Vivien Didelota935c052016-09-29 12:21:53 -04001292 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1293 if (err)
1294 return err;
Vivien Didelot6b17e862015-08-13 12:52:18 -04001295
Vivien Didelotfad09c72016-06-21 12:28:20 -04001296 return _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001297}
1298
Vivien Didelotfad09c72016-06-21 12:28:20 -04001299static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
Vivien Didelot6b17e862015-08-13 12:52:18 -04001300{
1301 int ret;
1302
Vivien Didelotfad09c72016-06-21 12:28:20 -04001303 ret = _mv88e6xxx_vtu_wait(chip);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001304 if (ret < 0)
1305 return ret;
1306
Vivien Didelotfad09c72016-06-21 12:28:20 -04001307 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
Vivien Didelot6b17e862015-08-13 12:52:18 -04001308}
1309
Vivien Didelotfad09c72016-06-21 12:28:20 -04001310static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001311 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelotb8fee952015-08-13 12:52:19 -04001312 unsigned int nibble_offset)
1313{
Vivien Didelotb8fee952015-08-13 12:52:19 -04001314 u16 regs[3];
Vivien Didelota935c052016-09-29 12:21:53 -04001315 int i, err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001316
1317 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001318 u16 *reg = &regs[i];
Vivien Didelotb8fee952015-08-13 12:52:19 -04001319
Vivien Didelota935c052016-09-29 12:21:53 -04001320 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1321 if (err)
1322 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001323 }
1324
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001325 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb8fee952015-08-13 12:52:19 -04001326 unsigned int shift = (i % 4) * 4 + nibble_offset;
1327 u16 reg = regs[i / 4];
1328
1329 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1330 }
1331
1332 return 0;
1333}
1334
Vivien Didelotfad09c72016-06-21 12:28:20 -04001335static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001336 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001337{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001338 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001339}
1340
Vivien Didelotfad09c72016-06-21 12:28:20 -04001341static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001342 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001343{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001344 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001345}
1346
Vivien Didelotfad09c72016-06-21 12:28:20 -04001347static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001348 struct mv88e6xxx_vtu_entry *entry,
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001349 unsigned int nibble_offset)
1350{
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001351 u16 regs[3] = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001352 int i, err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001353
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001354 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001355 unsigned int shift = (i % 4) * 4 + nibble_offset;
1356 u8 data = entry->data[i];
1357
1358 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1359 }
1360
1361 for (i = 0; i < 3; ++i) {
Vivien Didelota935c052016-09-29 12:21:53 -04001362 u16 reg = regs[i];
1363
1364 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1365 if (err)
1366 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001367 }
1368
1369 return 0;
1370}
1371
Vivien Didelotfad09c72016-06-21 12:28:20 -04001372static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001373 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001374{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001375 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001376}
1377
Vivien Didelotfad09c72016-06-21 12:28:20 -04001378static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001379 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001380{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001381 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
Vivien Didelot15d7d7d2016-05-10 15:44:28 -04001382}
1383
Vivien Didelotfad09c72016-06-21 12:28:20 -04001384static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001385{
Vivien Didelota935c052016-09-29 12:21:53 -04001386 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1387 vid & GLOBAL_VTU_VID_MASK);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001388}
1389
Vivien Didelotfad09c72016-06-21 12:28:20 -04001390static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001391 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelotb8fee952015-08-13 12:52:19 -04001392{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001393 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001394 u16 val;
1395 int err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001396
Vivien Didelota935c052016-09-29 12:21:53 -04001397 err = _mv88e6xxx_vtu_wait(chip);
1398 if (err)
1399 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001400
Vivien Didelota935c052016-09-29 12:21:53 -04001401 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1402 if (err)
1403 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001404
Vivien Didelota935c052016-09-29 12:21:53 -04001405 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1406 if (err)
1407 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001408
Vivien Didelota935c052016-09-29 12:21:53 -04001409 next.vid = val & GLOBAL_VTU_VID_MASK;
1410 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelotb8fee952015-08-13 12:52:19 -04001411
1412 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001413 err = mv88e6xxx_vtu_data_read(chip, &next);
1414 if (err)
1415 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001416
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001417 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001418 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1419 if (err)
1420 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001421
Vivien Didelota935c052016-09-29 12:21:53 -04001422 next.fid = val & GLOBAL_VTU_FID_MASK;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001423 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001424 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1425 * VTU DBNum[3:0] are located in VTU Operation 3:0
1426 */
Vivien Didelota935c052016-09-29 12:21:53 -04001427 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1428 if (err)
1429 return err;
Vivien Didelot11ea8092016-03-31 16:53:44 -04001430
Vivien Didelota935c052016-09-29 12:21:53 -04001431 next.fid = (val & 0xf00) >> 4;
1432 next.fid |= val & 0xf;
Vivien Didelot2e7bd5e2016-03-31 16:53:41 -04001433 }
Vivien Didelotb8fee952015-08-13 12:52:19 -04001434
Vivien Didelotfad09c72016-06-21 12:28:20 -04001435 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelota935c052016-09-29 12:21:53 -04001436 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1437 if (err)
1438 return err;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001439
Vivien Didelota935c052016-09-29 12:21:53 -04001440 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelotb8fee952015-08-13 12:52:19 -04001441 }
1442 }
1443
1444 *entry = next;
1445 return 0;
1446}
1447
Vivien Didelotf81ec902016-05-09 13:22:58 -04001448static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1449 struct switchdev_obj_port_vlan *vlan,
1450 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001451{
Vivien Didelot04bed142016-08-31 18:06:13 -04001452 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001453 struct mv88e6xxx_vtu_entry next;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001454 u16 pvid;
1455 int err;
1456
Vivien Didelotfad09c72016-06-21 12:28:20 -04001457 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001458 return -EOPNOTSUPP;
1459
Vivien Didelotfad09c72016-06-21 12:28:20 -04001460 mutex_lock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001461
Vivien Didelot77064f32016-11-04 03:23:30 +01001462 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001463 if (err)
1464 goto unlock;
1465
Vivien Didelotfad09c72016-06-21 12:28:20 -04001466 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001467 if (err)
1468 goto unlock;
1469
1470 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001471 err = _mv88e6xxx_vtu_getnext(chip, &next);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001472 if (err)
1473 break;
1474
1475 if (!next.valid)
1476 break;
1477
1478 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1479 continue;
1480
1481 /* reinit and dump this VLAN obj */
Vivien Didelot57d32312016-06-20 13:13:58 -04001482 vlan->vid_begin = next.vid;
1483 vlan->vid_end = next.vid;
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001484 vlan->flags = 0;
1485
1486 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1487 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1488
1489 if (next.vid == pvid)
1490 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1491
1492 err = cb(&vlan->obj);
1493 if (err)
1494 break;
1495 } while (next.vid < GLOBAL_VTU_VID_MASK);
1496
1497unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001498 mutex_unlock(&chip->reg_lock);
Vivien Didelotceff5ef2016-02-23 12:13:55 -05001499
1500 return err;
1501}
1502
Vivien Didelotfad09c72016-06-21 12:28:20 -04001503static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001504 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001505{
Vivien Didelot11ea8092016-03-31 16:53:44 -04001506 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001507 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001508 int err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001509
Vivien Didelota935c052016-09-29 12:21:53 -04001510 err = _mv88e6xxx_vtu_wait(chip);
1511 if (err)
1512 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001513
1514 if (!entry->valid)
1515 goto loadpurge;
1516
1517 /* Write port member tags */
Vivien Didelota935c052016-09-29 12:21:53 -04001518 err = mv88e6xxx_vtu_data_write(chip, entry);
1519 if (err)
1520 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001521
Vivien Didelotfad09c72016-06-21 12:28:20 -04001522 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001523 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001524 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1525 if (err)
1526 return err;
Vivien Didelotb426e5f2016-03-31 16:53:42 -04001527 }
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001528
Vivien Didelot6dc10bb2016-09-29 12:21:55 -04001529 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001530 reg = entry->fid & GLOBAL_VTU_FID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001531 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1532 if (err)
1533 return err;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001534 } else if (mv88e6xxx_num_databases(chip) == 256) {
Vivien Didelot11ea8092016-03-31 16:53:44 -04001535 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1536 * VTU DBNum[3:0] are located in VTU Operation 3:0
1537 */
1538 op |= (entry->fid & 0xf0) << 8;
1539 op |= entry->fid & 0xf;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001540 }
1541
1542 reg = GLOBAL_VTU_VID_VALID;
1543loadpurge:
1544 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001545 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1546 if (err)
1547 return err;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001548
Vivien Didelotfad09c72016-06-21 12:28:20 -04001549 return _mv88e6xxx_vtu_cmd(chip, op);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001550}
1551
Vivien Didelotfad09c72016-06-21 12:28:20 -04001552static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001553 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001554{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001555 struct mv88e6xxx_vtu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04001556 u16 val;
1557 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001558
Vivien Didelota935c052016-09-29 12:21:53 -04001559 err = _mv88e6xxx_vtu_wait(chip);
1560 if (err)
1561 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001562
Vivien Didelota935c052016-09-29 12:21:53 -04001563 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1564 sid & GLOBAL_VTU_SID_MASK);
1565 if (err)
1566 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001567
Vivien Didelota935c052016-09-29 12:21:53 -04001568 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1569 if (err)
1570 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001571
Vivien Didelota935c052016-09-29 12:21:53 -04001572 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1573 if (err)
1574 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001575
Vivien Didelota935c052016-09-29 12:21:53 -04001576 next.sid = val & GLOBAL_VTU_SID_MASK;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001577
Vivien Didelota935c052016-09-29 12:21:53 -04001578 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1579 if (err)
1580 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001581
Vivien Didelota935c052016-09-29 12:21:53 -04001582 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001583
1584 if (next.valid) {
Vivien Didelota935c052016-09-29 12:21:53 -04001585 err = mv88e6xxx_stu_data_read(chip, &next);
1586 if (err)
1587 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001588 }
1589
1590 *entry = next;
1591 return 0;
1592}
1593
Vivien Didelotfad09c72016-06-21 12:28:20 -04001594static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001595 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001596{
1597 u16 reg = 0;
Vivien Didelota935c052016-09-29 12:21:53 -04001598 int err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001599
Vivien Didelota935c052016-09-29 12:21:53 -04001600 err = _mv88e6xxx_vtu_wait(chip);
1601 if (err)
1602 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001603
1604 if (!entry->valid)
1605 goto loadpurge;
1606
1607 /* Write port states */
Vivien Didelota935c052016-09-29 12:21:53 -04001608 err = mv88e6xxx_stu_data_write(chip, entry);
1609 if (err)
1610 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001611
1612 reg = GLOBAL_VTU_VID_VALID;
1613loadpurge:
Vivien Didelota935c052016-09-29 12:21:53 -04001614 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1615 if (err)
1616 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001617
1618 reg = entry->sid & GLOBAL_VTU_SID_MASK;
Vivien Didelota935c052016-09-29 12:21:53 -04001619 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1620 if (err)
1621 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001622
Vivien Didelotfad09c72016-06-21 12:28:20 -04001623 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001624}
1625
Vivien Didelotfad09c72016-06-21 12:28:20 -04001626static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001627{
1628 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001629 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001630 int i, err;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001631
1632 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1633
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001634 /* Set every FID bit used by the (un)bridged ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001635 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotb4e48c52016-11-04 03:23:29 +01001636 err = mv88e6xxx_port_get_fid(chip, i, fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05001637 if (err)
1638 return err;
1639
1640 set_bit(*fid, fid_bitmap);
1641 }
1642
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001643 /* Set every FID bit used by the VLAN entries */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001644 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001645 if (err)
1646 return err;
1647
1648 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001649 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001650 if (err)
1651 return err;
1652
1653 if (!vlan.valid)
1654 break;
1655
1656 set_bit(vlan.fid, fid_bitmap);
1657 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1658
1659 /* The reset value 0x000 is used to indicate that multiple address
1660 * databases are not needed. Return the next positive available.
1661 */
1662 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001663 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001664 return -ENOSPC;
1665
1666 /* Clear the database */
Vivien Didelotfad09c72016-06-21 12:28:20 -04001667 return _mv88e6xxx_atu_flush(chip, *fid, true);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001668}
1669
Vivien Didelotfad09c72016-06-21 12:28:20 -04001670static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001671 struct mv88e6xxx_vtu_entry *entry)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001672{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001673 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001674 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001675 .valid = true,
1676 .vid = vid,
1677 };
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001678 int i, err;
1679
Vivien Didelotfad09c72016-06-21 12:28:20 -04001680 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05001681 if (err)
1682 return err;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001683
Vivien Didelot3d131f02015-11-03 10:52:52 -05001684 /* exclude all ports except the CPU and DSA ports */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001685 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelot3d131f02015-11-03 10:52:52 -05001686 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1687 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1688 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001689
Vivien Didelotfad09c72016-06-21 12:28:20 -04001690 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
1691 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip)) {
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001692 struct mv88e6xxx_vtu_entry vstp;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001693
1694 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1695 * implemented, only one STU entry is needed to cover all VTU
1696 * entries. Thus, validate the SID 0.
1697 */
1698 vlan.sid = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04001699 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001700 if (err)
1701 return err;
1702
1703 if (vstp.sid != vlan.sid || !vstp.valid) {
1704 memset(&vstp, 0, sizeof(vstp));
1705 vstp.valid = true;
1706 vstp.sid = vlan.sid;
1707
Vivien Didelotfad09c72016-06-21 12:28:20 -04001708 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001709 if (err)
1710 return err;
1711 }
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001712 }
1713
1714 *entry = vlan;
1715 return 0;
1716}
1717
Vivien Didelotfad09c72016-06-21 12:28:20 -04001718static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001719 struct mv88e6xxx_vtu_entry *entry, bool creat)
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001720{
1721 int err;
1722
1723 if (!vid)
1724 return -EINVAL;
1725
Vivien Didelotfad09c72016-06-21 12:28:20 -04001726 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001727 if (err)
1728 return err;
1729
Vivien Didelotfad09c72016-06-21 12:28:20 -04001730 err = _mv88e6xxx_vtu_getnext(chip, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001731 if (err)
1732 return err;
1733
1734 if (entry->vid != vid || !entry->valid) {
1735 if (!creat)
1736 return -EOPNOTSUPP;
1737 /* -ENOENT would've been more appropriate, but switchdev expects
1738 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1739 */
1740
Vivien Didelotfad09c72016-06-21 12:28:20 -04001741 err = _mv88e6xxx_vtu_new(chip, vid, entry);
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001742 }
1743
1744 return err;
1745}
1746
Vivien Didelotda9c3592016-02-12 12:09:40 -05001747static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1748 u16 vid_begin, u16 vid_end)
1749{
Vivien Didelot04bed142016-08-31 18:06:13 -04001750 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001751 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001752 int i, err;
1753
1754 if (!vid_begin)
1755 return -EOPNOTSUPP;
1756
Vivien Didelotfad09c72016-06-21 12:28:20 -04001757 mutex_lock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001758
Vivien Didelotfad09c72016-06-21 12:28:20 -04001759 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001760 if (err)
1761 goto unlock;
1762
1763 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001764 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001765 if (err)
1766 goto unlock;
1767
1768 if (!vlan.valid)
1769 break;
1770
1771 if (vlan.vid > vid_end)
1772 break;
1773
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001774 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotda9c3592016-02-12 12:09:40 -05001775 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1776 continue;
1777
Andrew Lunn66e28092016-12-11 21:07:19 +01001778 if (!ds->ports[port].netdev)
1779 continue;
1780
Vivien Didelotda9c3592016-02-12 12:09:40 -05001781 if (vlan.data[i] ==
1782 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1783 continue;
1784
Vivien Didelotfad09c72016-06-21 12:28:20 -04001785 if (chip->ports[i].bridge_dev ==
1786 chip->ports[port].bridge_dev)
Vivien Didelotda9c3592016-02-12 12:09:40 -05001787 break; /* same bridge, check next VLAN */
1788
Andrew Lunn66e28092016-12-11 21:07:19 +01001789 if (!chip->ports[i].bridge_dev)
1790 continue;
1791
Andrew Lunnc8b09802016-06-04 21:16:57 +02001792 netdev_warn(ds->ports[port].netdev,
Vivien Didelotda9c3592016-02-12 12:09:40 -05001793 "hardware VLAN %d already used by %s\n",
1794 vlan.vid,
Vivien Didelotfad09c72016-06-21 12:28:20 -04001795 netdev_name(chip->ports[i].bridge_dev));
Vivien Didelotda9c3592016-02-12 12:09:40 -05001796 err = -EOPNOTSUPP;
1797 goto unlock;
1798 }
1799 } while (vlan.vid < vid_end);
1800
1801unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001802 mutex_unlock(&chip->reg_lock);
Vivien Didelotda9c3592016-02-12 12:09:40 -05001803
1804 return err;
1805}
1806
Vivien Didelotf81ec902016-05-09 13:22:58 -04001807static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1808 bool vlan_filtering)
Vivien Didelot214cdb92016-02-26 13:16:08 -05001809{
Vivien Didelot04bed142016-08-31 18:06:13 -04001810 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot385a0992016-11-04 03:23:31 +01001811 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
Vivien Didelot214cdb92016-02-26 13:16:08 -05001812 PORT_CONTROL_2_8021Q_DISABLED;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001813 int err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001814
Vivien Didelotfad09c72016-06-21 12:28:20 -04001815 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001816 return -EOPNOTSUPP;
1817
Vivien Didelotfad09c72016-06-21 12:28:20 -04001818 mutex_lock(&chip->reg_lock);
Vivien Didelot385a0992016-11-04 03:23:31 +01001819 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
Vivien Didelotfad09c72016-06-21 12:28:20 -04001820 mutex_unlock(&chip->reg_lock);
Vivien Didelot214cdb92016-02-26 13:16:08 -05001821
Andrew Lunn0e7b9922016-09-21 01:40:31 +02001822 return err;
Vivien Didelot214cdb92016-02-26 13:16:08 -05001823}
1824
Vivien Didelot57d32312016-06-20 13:13:58 -04001825static int
1826mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1827 const struct switchdev_obj_port_vlan *vlan,
1828 struct switchdev_trans *trans)
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001829{
Vivien Didelot04bed142016-08-31 18:06:13 -04001830 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotda9c3592016-02-12 12:09:40 -05001831 int err;
1832
Vivien Didelotfad09c72016-06-21 12:28:20 -04001833 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001834 return -EOPNOTSUPP;
1835
Vivien Didelotda9c3592016-02-12 12:09:40 -05001836 /* If the requested port doesn't belong to the same bridge as the VLAN
1837 * members, do not support it (yet) and fallback to software VLAN.
1838 */
1839 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1840 vlan->vid_end);
1841 if (err)
1842 return err;
1843
Vivien Didelot76e398a2015-11-01 12:33:55 -05001844 /* We don't need any dynamic resource from the kernel (yet),
1845 * so skip the prepare phase.
1846 */
1847 return 0;
1848}
1849
Vivien Didelotfad09c72016-06-21 12:28:20 -04001850static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
Andrew Lunn158bc062016-04-28 21:24:06 -04001851 u16 vid, bool untagged)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001852{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001853 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001854 int err;
1855
Vivien Didelotfad09c72016-06-21 12:28:20 -04001856 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001857 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001858 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001859
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001860 vlan.data[port] = untagged ?
1861 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1862 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1863
Vivien Didelotfad09c72016-06-21 12:28:20 -04001864 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001865}
1866
Vivien Didelotf81ec902016-05-09 13:22:58 -04001867static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1868 const struct switchdev_obj_port_vlan *vlan,
1869 struct switchdev_trans *trans)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001870{
Vivien Didelot04bed142016-08-31 18:06:13 -04001871 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001872 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1873 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1874 u16 vid;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001875
Vivien Didelotfad09c72016-06-21 12:28:20 -04001876 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001877 return;
1878
Vivien Didelotfad09c72016-06-21 12:28:20 -04001879 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001880
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001881 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
Vivien Didelotfad09c72016-06-21 12:28:20 -04001882 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001883 netdev_err(ds->ports[port].netdev,
1884 "failed to add VLAN %d%c\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001885 vid, untagged ? 'u' : 't');
Vivien Didelot76e398a2015-11-01 12:33:55 -05001886
Vivien Didelot77064f32016-11-04 03:23:30 +01001887 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
Andrew Lunnc8b09802016-06-04 21:16:57 +02001888 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
Vivien Didelot4d5770b2016-04-06 11:55:05 -04001889 vlan->vid_end);
1890
Vivien Didelotfad09c72016-06-21 12:28:20 -04001891 mutex_unlock(&chip->reg_lock);
Vivien Didelot0d3b33e2015-08-13 12:52:22 -04001892}
1893
Vivien Didelotfad09c72016-06-21 12:28:20 -04001894static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001895 int port, u16 vid)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001896{
Vivien Didelotfad09c72016-06-21 12:28:20 -04001897 struct dsa_switch *ds = chip->ds;
Vivien Didelotb4e47c02016-09-29 12:21:58 -04001898 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001899 int i, err;
1900
Vivien Didelotfad09c72016-06-21 12:28:20 -04001901 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001902 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001903 return err;
Vivien Didelot36d04ba2015-10-22 09:34:39 -04001904
Vivien Didelot2fb5ef02016-02-26 13:16:01 -05001905 /* Tell switchdev if this VLAN is handled in software */
1906 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
Vivien Didelot3c06f082016-02-05 14:04:39 -05001907 return -EOPNOTSUPP;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001908
1909 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1910
1911 /* keep the VLAN unless all ports are excluded */
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001912 vlan.valid = false;
Vivien Didelot370b4ff2016-09-29 12:21:57 -04001913 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelot3d131f02015-11-03 10:52:52 -05001914 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001915 continue;
1916
1917 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
Vivien Didelotf02bdff2015-10-11 18:08:36 -04001918 vlan.valid = true;
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001919 break;
1920 }
1921 }
1922
Vivien Didelotfad09c72016-06-21 12:28:20 -04001923 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001924 if (err)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001925 return err;
1926
Vivien Didelotfad09c72016-06-21 12:28:20 -04001927 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001928}
1929
Vivien Didelotf81ec902016-05-09 13:22:58 -04001930static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1931 const struct switchdev_obj_port_vlan *vlan)
Vivien Didelot76e398a2015-11-01 12:33:55 -05001932{
Vivien Didelot04bed142016-08-31 18:06:13 -04001933 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot76e398a2015-11-01 12:33:55 -05001934 u16 pvid, vid;
1935 int err = 0;
1936
Vivien Didelotfad09c72016-06-21 12:28:20 -04001937 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
Vivien Didelot54d77b52016-05-09 13:22:47 -04001938 return -EOPNOTSUPP;
1939
Vivien Didelotfad09c72016-06-21 12:28:20 -04001940 mutex_lock(&chip->reg_lock);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001941
Vivien Didelot77064f32016-11-04 03:23:30 +01001942 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001943 if (err)
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001944 goto unlock;
1945
Vivien Didelot76e398a2015-11-01 12:33:55 -05001946 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04001947 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001948 if (err)
1949 goto unlock;
1950
1951 if (vid == pvid) {
Vivien Didelot77064f32016-11-04 03:23:30 +01001952 err = mv88e6xxx_port_set_pvid(chip, port, 0);
Vivien Didelot76e398a2015-11-01 12:33:55 -05001953 if (err)
1954 goto unlock;
1955 }
1956 }
1957
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001958unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04001959 mutex_unlock(&chip->reg_lock);
Vivien Didelot7dad08d2015-08-13 12:52:21 -04001960
1961 return err;
1962}
1963
Vivien Didelotfad09c72016-06-21 12:28:20 -04001964static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
Vivien Didelotc5723ac2015-08-10 09:09:48 -04001965 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001966{
Vivien Didelota935c052016-09-29 12:21:53 -04001967 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001968
1969 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04001970 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
1971 (addr[i * 2] << 8) | addr[i * 2 + 1]);
1972 if (err)
1973 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001974 }
1975
1976 return 0;
1977}
1978
Vivien Didelotfad09c72016-06-21 12:28:20 -04001979static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
Andrew Lunn158bc062016-04-28 21:24:06 -04001980 unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001981{
Vivien Didelota935c052016-09-29 12:21:53 -04001982 u16 val;
1983 int i, err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001984
1985 for (i = 0; i < 3; i++) {
Vivien Didelota935c052016-09-29 12:21:53 -04001986 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
1987 if (err)
1988 return err;
1989
1990 addr[i * 2] = val >> 8;
1991 addr[i * 2 + 1] = val & 0xff;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001992 }
1993
1994 return 0;
1995}
1996
Vivien Didelotfad09c72016-06-21 12:28:20 -04001997static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
Vivien Didelotfd231c82015-08-10 09:09:50 -04001998 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001999{
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002000 int ret;
2001
Vivien Didelotfad09c72016-06-21 12:28:20 -04002002 ret = _mv88e6xxx_atu_wait(chip);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002003 if (ret < 0)
2004 return ret;
2005
Vivien Didelotfad09c72016-06-21 12:28:20 -04002006 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002007 if (ret < 0)
2008 return ret;
2009
Vivien Didelotfad09c72016-06-21 12:28:20 -04002010 ret = _mv88e6xxx_atu_data_write(chip, entry);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002011 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002012 return ret;
2013
Vivien Didelotfad09c72016-06-21 12:28:20 -04002014 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
Vivien Didelotfd231c82015-08-10 09:09:50 -04002015}
David S. Millercdf09692015-08-11 12:00:37 -07002016
Vivien Didelot88472932016-09-19 19:56:11 -04002017static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2018 struct mv88e6xxx_atu_entry *entry);
2019
2020static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2021 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2022{
2023 struct mv88e6xxx_atu_entry next;
2024 int err;
2025
Andrew Lunn59527582017-01-04 19:56:24 +01002026 memcpy(next.mac, addr, ETH_ALEN);
2027 eth_addr_dec(next.mac);
Vivien Didelot88472932016-09-19 19:56:11 -04002028
2029 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2030 if (err)
2031 return err;
2032
2033 do {
2034 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2035 if (err)
2036 return err;
2037
2038 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2039 break;
2040
2041 if (ether_addr_equal(next.mac, addr)) {
2042 *entry = next;
2043 return 0;
2044 }
Andrew Lunn59527582017-01-04 19:56:24 +01002045 } while (ether_addr_greater(addr, next.mac));
Vivien Didelot88472932016-09-19 19:56:11 -04002046
2047 memset(entry, 0, sizeof(*entry));
2048 entry->fid = fid;
2049 ether_addr_copy(entry->mac, addr);
2050
2051 return 0;
2052}
2053
Vivien Didelot83dabd12016-08-31 11:50:04 -04002054static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2055 const unsigned char *addr, u16 vid,
2056 u8 state)
Vivien Didelotfd231c82015-08-10 09:09:50 -04002057{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002058 struct mv88e6xxx_vtu_entry vlan;
Vivien Didelot88472932016-09-19 19:56:11 -04002059 struct mv88e6xxx_atu_entry entry;
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002060 int err;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002061
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002062 /* Null VLAN ID corresponds to the port private database */
2063 if (vid == 0)
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002064 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002065 else
Vivien Didelotfad09c72016-06-21 12:28:20 -04002066 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
Vivien Didelot3285f9e2016-02-26 13:16:03 -05002067 if (err)
2068 return err;
2069
Vivien Didelot88472932016-09-19 19:56:11 -04002070 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2071 if (err)
2072 return err;
2073
2074 /* Purge the ATU entry only if no port is using it anymore */
2075 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2076 entry.portv_trunkid &= ~BIT(port);
2077 if (!entry.portv_trunkid)
2078 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2079 } else {
2080 entry.portv_trunkid |= BIT(port);
2081 entry.state = state;
Vivien Didelotfd231c82015-08-10 09:09:50 -04002082 }
2083
Vivien Didelotfad09c72016-06-21 12:28:20 -04002084 return _mv88e6xxx_atu_load(chip, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002085}
2086
Vivien Didelotf81ec902016-05-09 13:22:58 -04002087static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2088 const struct switchdev_obj_port_fdb *fdb,
2089 struct switchdev_trans *trans)
Vivien Didelot146a3202015-10-08 11:35:12 -04002090{
2091 /* We don't need any dynamic resource from the kernel (yet),
2092 * so skip the prepare phase.
2093 */
2094 return 0;
2095}
2096
Vivien Didelotf81ec902016-05-09 13:22:58 -04002097static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2098 const struct switchdev_obj_port_fdb *fdb,
2099 struct switchdev_trans *trans)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002100{
Vivien Didelot04bed142016-08-31 18:06:13 -04002101 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot6630e232015-08-06 01:44:07 -04002102
Vivien Didelotfad09c72016-06-21 12:28:20 -04002103 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002104 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2105 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2106 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
Vivien Didelotfad09c72016-06-21 12:28:20 -04002107 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002108}
2109
Vivien Didelotf81ec902016-05-09 13:22:58 -04002110static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2111 const struct switchdev_obj_port_fdb *fdb)
David S. Millercdf09692015-08-11 12:00:37 -07002112{
Vivien Didelot04bed142016-08-31 18:06:13 -04002113 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot83dabd12016-08-31 11:50:04 -04002114 int err;
David S. Millercdf09692015-08-11 12:00:37 -07002115
Vivien Didelotfad09c72016-06-21 12:28:20 -04002116 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002117 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2118 GLOBAL_ATU_DATA_STATE_UNUSED);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002119 mutex_unlock(&chip->reg_lock);
David S. Millercdf09692015-08-11 12:00:37 -07002120
Vivien Didelot83dabd12016-08-31 11:50:04 -04002121 return err;
David S. Millercdf09692015-08-11 12:00:37 -07002122}
2123
Vivien Didelotfad09c72016-06-21 12:28:20 -04002124static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
Vivien Didelot1d194042015-08-10 09:09:51 -04002125 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07002126{
Vivien Didelot1d194042015-08-10 09:09:51 -04002127 struct mv88e6xxx_atu_entry next = { 0 };
Vivien Didelota935c052016-09-29 12:21:53 -04002128 u16 val;
2129 int err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002130
2131 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002132
Vivien Didelota935c052016-09-29 12:21:53 -04002133 err = _mv88e6xxx_atu_wait(chip);
2134 if (err)
2135 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002136
Vivien Didelota935c052016-09-29 12:21:53 -04002137 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2138 if (err)
2139 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002140
Vivien Didelota935c052016-09-29 12:21:53 -04002141 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2142 if (err)
2143 return err;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002144
Vivien Didelota935c052016-09-29 12:21:53 -04002145 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2146 if (err)
2147 return err;
Vivien Didelot1d194042015-08-10 09:09:51 -04002148
Vivien Didelota935c052016-09-29 12:21:53 -04002149 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
Vivien Didelot1d194042015-08-10 09:09:51 -04002150 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2151 unsigned int mask, shift;
2152
Vivien Didelota935c052016-09-29 12:21:53 -04002153 if (val & GLOBAL_ATU_DATA_TRUNK) {
Vivien Didelot1d194042015-08-10 09:09:51 -04002154 next.trunk = true;
2155 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2156 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2157 } else {
2158 next.trunk = false;
2159 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2160 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2161 }
2162
Vivien Didelota935c052016-09-29 12:21:53 -04002163 next.portv_trunkid = (val & mask) >> shift;
Vivien Didelot1d194042015-08-10 09:09:51 -04002164 }
2165
2166 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07002167 return 0;
2168}
2169
Vivien Didelot83dabd12016-08-31 11:50:04 -04002170static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2171 u16 fid, u16 vid, int port,
2172 struct switchdev_obj *obj,
2173 int (*cb)(struct switchdev_obj *obj))
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002174{
2175 struct mv88e6xxx_atu_entry addr = {
2176 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2177 };
2178 int err;
2179
Vivien Didelotfad09c72016-06-21 12:28:20 -04002180 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002181 if (err)
2182 return err;
2183
2184 do {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002185 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002186 if (err)
Vivien Didelot83dabd12016-08-31 11:50:04 -04002187 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002188
2189 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2190 break;
2191
Vivien Didelot83dabd12016-08-31 11:50:04 -04002192 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2193 continue;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002194
Vivien Didelot83dabd12016-08-31 11:50:04 -04002195 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2196 struct switchdev_obj_port_fdb *fdb;
2197
2198 if (!is_unicast_ether_addr(addr.mac))
2199 continue;
2200
2201 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002202 fdb->vid = vid;
2203 ether_addr_copy(fdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002204 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2205 fdb->ndm_state = NUD_NOARP;
2206 else
2207 fdb->ndm_state = NUD_REACHABLE;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04002208 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2209 struct switchdev_obj_port_mdb *mdb;
2210
2211 if (!is_multicast_ether_addr(addr.mac))
2212 continue;
2213
2214 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2215 mdb->vid = vid;
2216 ether_addr_copy(mdb->addr, addr.mac);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002217 } else {
2218 return -EOPNOTSUPP;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002219 }
Vivien Didelot83dabd12016-08-31 11:50:04 -04002220
2221 err = cb(obj);
2222 if (err)
2223 return err;
Vivien Didelot74b6ba02016-02-26 13:16:02 -05002224 } while (!is_broadcast_ether_addr(addr.mac));
2225
2226 return err;
2227}
2228
Vivien Didelot83dabd12016-08-31 11:50:04 -04002229static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2230 struct switchdev_obj *obj,
2231 int (*cb)(struct switchdev_obj *obj))
2232{
Vivien Didelotb4e47c02016-09-29 12:21:58 -04002233 struct mv88e6xxx_vtu_entry vlan = {
Vivien Didelot83dabd12016-08-31 11:50:04 -04002234 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2235 };
2236 u16 fid;
2237 int err;
2238
2239 /* Dump port's default Filtering Information Database (VLAN ID 0) */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002240 err = mv88e6xxx_port_get_fid(chip, port, &fid);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002241 if (err)
2242 return err;
2243
2244 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2245 if (err)
2246 return err;
2247
2248 /* Dump VLANs' Filtering Information Databases */
2249 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2250 if (err)
2251 return err;
2252
2253 do {
2254 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2255 if (err)
2256 return err;
2257
2258 if (!vlan.valid)
2259 break;
2260
2261 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2262 obj, cb);
2263 if (err)
2264 return err;
2265 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2266
2267 return err;
2268}
2269
Vivien Didelotf81ec902016-05-09 13:22:58 -04002270static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2271 struct switchdev_obj_port_fdb *fdb,
2272 int (*cb)(struct switchdev_obj *obj))
Vivien Didelotf33475b2015-10-22 09:34:41 -04002273{
Vivien Didelot04bed142016-08-31 18:06:13 -04002274 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotf33475b2015-10-22 09:34:41 -04002275 int err;
2276
Vivien Didelotfad09c72016-06-21 12:28:20 -04002277 mutex_lock(&chip->reg_lock);
Vivien Didelot83dabd12016-08-31 11:50:04 -04002278 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002279 mutex_unlock(&chip->reg_lock);
Vivien Didelotf33475b2015-10-22 09:34:41 -04002280
2281 return err;
2282}
2283
Vivien Didelotf81ec902016-05-09 13:22:58 -04002284static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
2285 struct net_device *bridge)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002286{
Vivien Didelot04bed142016-08-31 18:06:13 -04002287 struct mv88e6xxx_chip *chip = ds->priv;
Colin Ian King1d9619d2016-04-25 23:11:22 +01002288 int i, err = 0;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002289
Vivien Didelotfad09c72016-06-21 12:28:20 -04002290 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002291
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002292 /* Assign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002293 chip->ports[port].bridge_dev = bridge;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002294
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002295 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002296 if (chip->ports[i].bridge_dev == bridge) {
2297 err = _mv88e6xxx_port_based_vlan_map(chip, i);
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002298 if (err)
2299 break;
2300 }
2301 }
2302
Vivien Didelotfad09c72016-06-21 12:28:20 -04002303 mutex_unlock(&chip->reg_lock);
Vivien Didelota6692752016-02-12 12:09:39 -05002304
Vivien Didelot466dfa02016-02-26 13:16:05 -05002305 return err;
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002306}
2307
Vivien Didelotf81ec902016-05-09 13:22:58 -04002308static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
Vivien Didelote79a8bc2015-11-04 17:23:40 -05002309{
Vivien Didelot04bed142016-08-31 18:06:13 -04002310 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002311 struct net_device *bridge = chip->ports[port].bridge_dev;
Vivien Didelot16bfa702016-03-13 16:21:33 -04002312 int i;
Vivien Didelot466dfa02016-02-26 13:16:05 -05002313
Vivien Didelotfad09c72016-06-21 12:28:20 -04002314 mutex_lock(&chip->reg_lock);
Vivien Didelot466dfa02016-02-26 13:16:05 -05002315
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002316 /* Unassign the bridge and remap each port's VLANTable */
Vivien Didelotfad09c72016-06-21 12:28:20 -04002317 chip->ports[port].bridge_dev = NULL;
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002318
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002319 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002320 if (i == port || chip->ports[i].bridge_dev == bridge)
2321 if (_mv88e6xxx_port_based_vlan_map(chip, i))
Andrew Lunnc8b09802016-06-04 21:16:57 +02002322 netdev_warn(ds->ports[i].netdev,
2323 "failed to remap\n");
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002324
Vivien Didelotfad09c72016-06-21 12:28:20 -04002325 mutex_unlock(&chip->reg_lock);
Vivien Didelot66d9cd02016-02-05 14:07:14 -05002326}
2327
Vivien Didelot17e708b2016-12-05 17:30:27 -05002328static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip)
2329{
2330 if (chip->info->ops->reset)
2331 return chip->info->ops->reset(chip);
2332
2333 return 0;
2334}
2335
Vivien Didelot309eca62016-12-05 17:30:26 -05002336static void mv88e6xxx_hardware_reset(struct mv88e6xxx_chip *chip)
2337{
2338 struct gpio_desc *gpiod = chip->reset;
2339
2340 /* If there is a GPIO connected to the reset pin, toggle it */
2341 if (gpiod) {
2342 gpiod_set_value_cansleep(gpiod, 1);
2343 usleep_range(10000, 20000);
2344 gpiod_set_value_cansleep(gpiod, 0);
2345 usleep_range(10000, 20000);
2346 }
2347}
2348
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002349static int mv88e6xxx_disable_ports(struct mv88e6xxx_chip *chip)
2350{
2351 int i, err;
2352
2353 /* Set all ports to the Disabled state */
2354 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2355 err = mv88e6xxx_port_set_state(chip, i,
2356 PORT_CONTROL_STATE_DISABLED);
2357 if (err)
2358 return err;
2359 }
2360
2361 /* Wait for transmit queues to drain,
2362 * i.e. 2ms for a maximum frame to be transmitted at 10 Mbps.
2363 */
2364 usleep_range(2000, 4000);
2365
2366 return 0;
2367}
2368
Vivien Didelotfad09c72016-06-21 12:28:20 -04002369static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
Vivien Didelot552238b2016-05-09 13:22:49 -04002370{
Vivien Didelota935c052016-09-29 12:21:53 -04002371 int err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002372
Vivien Didelot4ac4b5a2016-12-05 17:30:25 -05002373 err = mv88e6xxx_disable_ports(chip);
2374 if (err)
2375 return err;
Vivien Didelot552238b2016-05-09 13:22:49 -04002376
Vivien Didelot309eca62016-12-05 17:30:26 -05002377 mv88e6xxx_hardware_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002378
Vivien Didelot17e708b2016-12-05 17:30:27 -05002379 return mv88e6xxx_software_reset(chip);
Vivien Didelot552238b2016-05-09 13:22:49 -04002380}
2381
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002382static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002383{
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002384 u16 val;
2385 int err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002386
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002387 /* Clear Power Down bit */
2388 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2389 if (err)
2390 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002391
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002392 if (val & BMCR_PDOWN) {
2393 val &= ~BMCR_PDOWN;
2394 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002395 }
2396
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002397 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002398}
2399
Andrew Lunn56995cb2016-12-03 04:35:19 +01002400static int mv88e6xxx_setup_port_dsa(struct mv88e6xxx_chip *chip, int port,
2401 int upstream_port)
2402{
2403 int err;
2404
2405 err = chip->info->ops->port_set_frame_mode(
2406 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2407 if (err)
2408 return err;
2409
2410 return chip->info->ops->port_set_egress_unknowns(
2411 chip, port, port == upstream_port);
2412}
2413
2414static int mv88e6xxx_setup_port_cpu(struct mv88e6xxx_chip *chip, int port)
2415{
2416 int err;
2417
2418 switch (chip->info->tag_protocol) {
2419 case DSA_TAG_PROTO_EDSA:
2420 err = chip->info->ops->port_set_frame_mode(
2421 chip, port, MV88E6XXX_FRAME_MODE_ETHERTYPE);
2422 if (err)
2423 return err;
2424
2425 err = mv88e6xxx_port_set_egress_mode(
2426 chip, port, PORT_CONTROL_EGRESS_ADD_TAG);
2427 if (err)
2428 return err;
2429
2430 if (chip->info->ops->port_set_ether_type)
2431 err = chip->info->ops->port_set_ether_type(
2432 chip, port, ETH_P_EDSA);
2433 break;
2434
2435 case DSA_TAG_PROTO_DSA:
2436 err = chip->info->ops->port_set_frame_mode(
2437 chip, port, MV88E6XXX_FRAME_MODE_DSA);
2438 if (err)
2439 return err;
2440
2441 err = mv88e6xxx_port_set_egress_mode(
2442 chip, port, PORT_CONTROL_EGRESS_UNMODIFIED);
2443 break;
2444 default:
2445 err = -EINVAL;
2446 }
2447
2448 if (err)
2449 return err;
2450
2451 return chip->info->ops->port_set_egress_unknowns(chip, port, true);
2452}
2453
2454static int mv88e6xxx_setup_port_normal(struct mv88e6xxx_chip *chip, int port)
2455{
2456 int err;
2457
2458 err = chip->info->ops->port_set_frame_mode(
2459 chip, port, MV88E6XXX_FRAME_MODE_NORMAL);
2460 if (err)
2461 return err;
2462
2463 return chip->info->ops->port_set_egress_unknowns(chip, port, false);
2464}
2465
Vivien Didelotfad09c72016-06-21 12:28:20 -04002466static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07002467{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002468 struct dsa_switch *ds = chip->ds;
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002469 int err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002470 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07002471
Vivien Didelotd78343d2016-11-04 03:23:36 +01002472 /* MAC Forcing register: don't force link, speed, duplex or flow control
2473 * state to any particular values on physical ports, but force the CPU
2474 * port and all DSA ports to their maximum bandwidth and full duplex.
2475 */
2476 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2477 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2478 SPEED_MAX, DUPLEX_FULL,
2479 PHY_INTERFACE_MODE_NA);
2480 else
2481 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2482 SPEED_UNFORCED, DUPLEX_UNFORCED,
2483 PHY_INTERFACE_MODE_NA);
2484 if (err)
2485 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002486
2487 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2488 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2489 * tunneling, determine priority by looking at 802.1p and IP
2490 * priority fields (IP prio has precedence), and set STP state
2491 * to Forwarding.
2492 *
2493 * If this is the CPU link, use DSA or EDSA tagging depending
2494 * on which tagging mode was configured.
2495 *
2496 * If this is a link to another switch, use DSA tagging mode.
2497 *
2498 * If this is the upstream port for this switch, enable
2499 * forwarding of unknown unicasts and multicasts.
2500 */
Andrew Lunn56995cb2016-12-03 04:35:19 +01002501 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
Andrew Lunn54d792f2015-05-06 01:09:47 +02002502 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2503 PORT_CONTROL_STATE_FORWARDING;
Andrew Lunn56995cb2016-12-03 04:35:19 +01002504 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2505 if (err)
2506 return err;
Andrew Lunn6083ce72015-08-17 23:52:52 +02002507
Andrew Lunn56995cb2016-12-03 04:35:19 +01002508 if (dsa_is_cpu_port(ds, port)) {
2509 err = mv88e6xxx_setup_port_cpu(chip, port);
2510 } else if (dsa_is_dsa_port(ds, port)) {
2511 err = mv88e6xxx_setup_port_dsa(chip, port,
2512 dsa_upstream_port(ds));
2513 } else {
2514 err = mv88e6xxx_setup_port_normal(chip, port);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002515 }
Andrew Lunn56995cb2016-12-03 04:35:19 +01002516 if (err)
2517 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002518
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002519 /* If this port is connected to a SerDes, make sure the SerDes is not
2520 * powered down.
2521 */
Vivien Didelot09cb7df2016-08-15 17:19:01 -04002522 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002523 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, &reg);
2524 if (err)
2525 return err;
2526 reg &= PORT_STATUS_CMODE_MASK;
2527 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2528 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2529 (reg == PORT_STATUS_CMODE_SGMII)) {
2530 err = mv88e6xxx_serdes_power_on(chip);
2531 if (err < 0)
2532 return err;
Patrick Uiterwijk13a7ebb2016-03-30 01:39:41 +00002533 }
2534 }
2535
Vivien Didelot8efdda42015-08-13 12:52:23 -04002536 /* Port Control 2: don't force a good FCS, set the maximum frame size to
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002537 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
Vivien Didelot8efdda42015-08-13 12:52:23 -04002538 * untagged frames on this port, do a destination address lookup on all
2539 * received packets as usual, disable ARP mirroring and don't send a
2540 * copy of all transmitted/received frames on this port to the CPU.
Andrew Lunn54d792f2015-05-06 01:09:47 +02002541 */
2542 reg = 0;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002543 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2544 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2545 mv88e6xxx_6095_family(chip) || mv88e6xxx_6320_family(chip) ||
2546 mv88e6xxx_6185_family(chip))
Andrew Lunn54d792f2015-05-06 01:09:47 +02002547 reg = PORT_CONTROL_2_MAP_DA;
2548
Vivien Didelotfad09c72016-06-21 12:28:20 -04002549 if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002550 /* Set the upstream port this port should use */
2551 reg |= dsa_upstream_port(ds);
2552 /* enable forwarding of unknown multicast addresses to
2553 * the upstream port
2554 */
2555 if (port == dsa_upstream_port(ds))
2556 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
2557 }
2558
Vivien Didelot46fbe5e2016-02-26 13:16:07 -05002559 reg |= PORT_CONTROL_2_8021Q_DISABLED;
Vivien Didelot8efdda42015-08-13 12:52:23 -04002560
Andrew Lunn54d792f2015-05-06 01:09:47 +02002561 if (reg) {
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002562 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
2563 if (err)
2564 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002565 }
2566
Andrew Lunn5f436662016-12-03 04:45:17 +01002567 if (chip->info->ops->port_jumbo_config) {
2568 err = chip->info->ops->port_jumbo_config(chip, port);
2569 if (err)
2570 return err;
2571 }
2572
Andrew Lunn54d792f2015-05-06 01:09:47 +02002573 /* Port Association Vector: when learning source addresses
2574 * of packets, add the address to the address database using
2575 * a port bitmap that has only the bit for this port set and
2576 * the other bits clear.
2577 */
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002578 reg = 1 << port;
Vivien Didelot996ecb82016-04-14 14:42:08 -04002579 /* Disable learning for CPU port */
2580 if (dsa_is_cpu_port(ds, port))
Vivien Didelot65fa4022016-04-14 14:42:07 -04002581 reg = 0;
Andrew Lunn4c7ea3c2015-11-03 10:52:36 -05002582
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002583 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2584 if (err)
2585 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002586
2587 /* Egress rate control 2: disable egress rate control. */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002588 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2589 if (err)
2590 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002591
Andrew Lunnb35d322a2016-12-03 04:45:19 +01002592 if (chip->info->ops->port_pause_config) {
2593 err = chip->info->ops->port_pause_config(chip, port);
2594 if (err)
2595 return err;
2596 }
2597
Vivien Didelotfad09c72016-06-21 12:28:20 -04002598 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2599 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2600 mv88e6xxx_6320_family(chip)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002601 /* Port ATU control: disable limiting the number of
2602 * address database entries that this port is allowed
2603 * to use.
2604 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002605 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2606 0x0000);
Andrew Lunn54d792f2015-05-06 01:09:47 +02002607 /* Priority Override: disable DA, SA and VTU priority
2608 * override.
2609 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002610 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2611 0x0000);
2612 if (err)
2613 return err;
Andrew Lunnef0a7312016-12-03 04:35:16 +01002614 }
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02002615
Andrew Lunnef0a7312016-12-03 04:35:16 +01002616 if (chip->info->ops->port_tag_remap) {
2617 err = chip->info->ops->port_tag_remap(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002618 if (err)
2619 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002620 }
2621
Andrew Lunnef70b112016-12-03 04:45:18 +01002622 if (chip->info->ops->port_egress_rate_limiting) {
2623 err = chip->info->ops->port_egress_rate_limiting(chip, port);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002624 if (err)
2625 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002626 }
2627
Guenter Roeck366f0a02015-03-26 18:36:30 -07002628 /* Port Control 1: disable trunking, disable sending
2629 * learning messages to this port.
Guenter Roeckd827e882015-03-26 18:36:29 -07002630 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002631 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_1, 0x0000);
2632 if (err)
2633 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002634
Vivien Didelot207afda2016-04-14 14:42:09 -04002635 /* Port based VLAN map: give each port the same default address
Vivien Didelotb7666ef2016-02-26 13:16:06 -05002636 * database, and allow bidirectional communication between the
2637 * CPU and DSA port(s), and the other ports.
Guenter Roeckd827e882015-03-26 18:36:29 -07002638 */
Vivien Didelotb4e48c52016-11-04 03:23:29 +01002639 err = mv88e6xxx_port_set_fid(chip, port, 0);
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002640 if (err)
2641 return err;
Vivien Didelot2db9ce12016-02-26 13:16:04 -05002642
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002643 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2644 if (err)
2645 return err;
Guenter Roeckd827e882015-03-26 18:36:29 -07002646
2647 /* Default VLAN ID and priority: don't set a default VLAN
2648 * ID, and set the default packet priority to zero.
2649 */
Andrew Lunn0e7b9922016-09-21 01:40:31 +02002650 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
Andrew Lunndbde9e62015-05-06 01:09:48 +02002651}
2652
Wei Yongjunaa0938c2016-10-18 15:53:37 +00002653static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002654{
2655 int err;
2656
Vivien Didelota935c052016-09-29 12:21:53 -04002657 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002658 if (err)
2659 return err;
2660
Vivien Didelota935c052016-09-29 12:21:53 -04002661 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002662 if (err)
2663 return err;
2664
Vivien Didelota935c052016-09-29 12:21:53 -04002665 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2666 if (err)
2667 return err;
2668
2669 return 0;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002670}
2671
Vivien Didelotacddbd22016-07-18 20:45:39 -04002672static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
2673 unsigned int msecs)
2674{
2675 const unsigned int coeff = chip->info->age_time_coeff;
2676 const unsigned int min = 0x01 * coeff;
2677 const unsigned int max = 0xff * coeff;
2678 u8 age_time;
2679 u16 val;
2680 int err;
2681
2682 if (msecs < min || msecs > max)
2683 return -ERANGE;
2684
2685 /* Round to nearest multiple of coeff */
2686 age_time = (msecs + coeff / 2) / coeff;
2687
Vivien Didelota935c052016-09-29 12:21:53 -04002688 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002689 if (err)
2690 return err;
2691
2692 /* AgeTime is 11:4 bits */
2693 val &= ~0xff0;
2694 val |= age_time << 4;
2695
Vivien Didelota935c052016-09-29 12:21:53 -04002696 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
Vivien Didelotacddbd22016-07-18 20:45:39 -04002697}
2698
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002699static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2700 unsigned int ageing_time)
2701{
Vivien Didelot04bed142016-08-31 18:06:13 -04002702 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot2cfcd962016-07-18 20:45:40 -04002703 int err;
2704
2705 mutex_lock(&chip->reg_lock);
2706 err = mv88e6xxx_g1_set_age_time(chip, ageing_time);
2707 mutex_unlock(&chip->reg_lock);
2708
2709 return err;
2710}
2711
Vivien Didelot97299342016-07-18 20:45:30 -04002712static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
Vivien Didelot08a01262016-05-09 13:22:50 -04002713{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002714 struct dsa_switch *ds = chip->ds;
Vivien Didelotb0745e872016-05-09 13:22:53 -04002715 u32 upstream_port = dsa_upstream_port(ds);
Vivien Didelot08a01262016-05-09 13:22:50 -04002716 int err;
Vivien Didelot08a01262016-05-09 13:22:50 -04002717
Vivien Didelot119477b2016-05-09 13:22:51 -04002718 /* Enable the PHY Polling Unit if present, don't discard any packets,
2719 * and mask all interrupt sources.
2720 */
Vivien Didelota199d8b2016-12-05 17:30:28 -05002721 err = mv88e6xxx_ppu_enable(chip);
Vivien Didelot119477b2016-05-09 13:22:51 -04002722 if (err)
2723 return err;
2724
Andrew Lunn33641992016-12-03 04:35:17 +01002725 if (chip->info->ops->g1_set_cpu_port) {
2726 err = chip->info->ops->g1_set_cpu_port(chip, upstream_port);
2727 if (err)
2728 return err;
2729 }
2730
2731 if (chip->info->ops->g1_set_egress_port) {
2732 err = chip->info->ops->g1_set_egress_port(chip, upstream_port);
2733 if (err)
2734 return err;
2735 }
Vivien Didelotb0745e872016-05-09 13:22:53 -04002736
Vivien Didelot50484ff2016-05-09 13:22:54 -04002737 /* Disable remote management, and set the switch's DSA device number. */
Vivien Didelota935c052016-09-29 12:21:53 -04002738 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2739 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2740 (ds->index & 0x1f));
Vivien Didelot50484ff2016-05-09 13:22:54 -04002741 if (err)
2742 return err;
2743
Vivien Didelotacddbd22016-07-18 20:45:39 -04002744 /* Clear all the VTU and STU entries */
2745 err = _mv88e6xxx_vtu_stu_flush(chip);
2746 if (err < 0)
2747 return err;
2748
Vivien Didelot08a01262016-05-09 13:22:50 -04002749 /* Set the default address aging time to 5 minutes, and
2750 * enable address learn messages to be sent to all message
2751 * ports.
2752 */
Vivien Didelota935c052016-09-29 12:21:53 -04002753 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2754 GLOBAL_ATU_CONTROL_LEARN2ALL);
Vivien Didelot08a01262016-05-09 13:22:50 -04002755 if (err)
2756 return err;
2757
Vivien Didelotacddbd22016-07-18 20:45:39 -04002758 err = mv88e6xxx_g1_set_age_time(chip, 300000);
2759 if (err)
Vivien Didelot97299342016-07-18 20:45:30 -04002760 return err;
2761
2762 /* Clear all ATU entries */
2763 err = _mv88e6xxx_atu_flush(chip, 0, true);
2764 if (err)
2765 return err;
2766
Vivien Didelot08a01262016-05-09 13:22:50 -04002767 /* Configure the IP ToS mapping registers. */
Vivien Didelota935c052016-09-29 12:21:53 -04002768 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002769 if (err)
2770 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002771 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
Vivien Didelot08a01262016-05-09 13:22:50 -04002772 if (err)
2773 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002774 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002775 if (err)
2776 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002777 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
Vivien Didelot08a01262016-05-09 13:22:50 -04002778 if (err)
2779 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002780 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002781 if (err)
2782 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002783 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
Vivien Didelot08a01262016-05-09 13:22:50 -04002784 if (err)
2785 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002786 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002787 if (err)
2788 return err;
Vivien Didelota935c052016-09-29 12:21:53 -04002789 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
Vivien Didelot08a01262016-05-09 13:22:50 -04002790 if (err)
2791 return err;
2792
2793 /* Configure the IEEE 802.1p priority mapping register. */
Vivien Didelota935c052016-09-29 12:21:53 -04002794 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
Vivien Didelot08a01262016-05-09 13:22:50 -04002795 if (err)
2796 return err;
2797
Andrew Lunnde2273872016-11-21 23:27:01 +01002798 /* Initialize the statistics unit */
2799 err = mv88e6xxx_stats_set_histogram(chip);
2800 if (err)
2801 return err;
2802
Vivien Didelot97299342016-07-18 20:45:30 -04002803 /* Clear the statistics counters for all ports */
Vivien Didelota935c052016-09-29 12:21:53 -04002804 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2805 GLOBAL_STATS_OP_FLUSH_ALL);
Vivien Didelot97299342016-07-18 20:45:30 -04002806 if (err)
2807 return err;
2808
2809 /* Wait for the flush to complete. */
Andrew Lunn7f9ef3a2016-11-21 23:27:05 +01002810 err = mv88e6xxx_g1_stats_wait(chip);
Vivien Didelot97299342016-07-18 20:45:30 -04002811 if (err)
2812 return err;
2813
2814 return 0;
2815}
2816
Vivien Didelotf81ec902016-05-09 13:22:58 -04002817static int mv88e6xxx_setup(struct dsa_switch *ds)
Guenter Roeckacdaffc2015-03-26 18:36:28 -07002818{
Vivien Didelot04bed142016-08-31 18:06:13 -04002819 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot552238b2016-05-09 13:22:49 -04002820 int err;
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002821 int i;
2822
Vivien Didelotfad09c72016-06-21 12:28:20 -04002823 chip->ds = ds;
2824 ds->slave_mii_bus = chip->mdio_bus;
Vivien Didelot552238b2016-05-09 13:22:49 -04002825
Vivien Didelotfad09c72016-06-21 12:28:20 -04002826 mutex_lock(&chip->reg_lock);
Vivien Didelot552238b2016-05-09 13:22:49 -04002827
Vivien Didelot97299342016-07-18 20:45:30 -04002828 /* Setup Switch Port Registers */
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002829 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
Vivien Didelot97299342016-07-18 20:45:30 -04002830 err = mv88e6xxx_setup_port(chip, i);
2831 if (err)
2832 goto unlock;
2833 }
2834
2835 /* Setup Switch Global 1 Registers */
2836 err = mv88e6xxx_g1_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002837 if (err)
2838 goto unlock;
2839
Vivien Didelot97299342016-07-18 20:45:30 -04002840 /* Setup Switch Global 2 Registers */
2841 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2842 err = mv88e6xxx_g2_setup(chip);
Vivien Didelota1a6a4d2016-05-09 13:22:56 -04002843 if (err)
2844 goto unlock;
2845 }
Andrew Lunn54d792f2015-05-06 01:09:47 +02002846
Andrew Lunn6e55f692016-12-03 04:45:16 +01002847 /* Some generations have the configuration of sending reserved
2848 * management frames to the CPU in global2, others in
2849 * global1. Hence it does not fit the two setup functions
2850 * above.
2851 */
2852 if (chip->info->ops->mgmt_rsvd2cpu) {
2853 err = chip->info->ops->mgmt_rsvd2cpu(chip);
2854 if (err)
2855 goto unlock;
2856 }
2857
Vivien Didelot6b17e862015-08-13 12:52:18 -04002858unlock:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002859 mutex_unlock(&chip->reg_lock);
Andrew Lunndb687a52015-06-20 21:31:29 +02002860
Andrew Lunn48ace4e2016-04-14 23:47:12 +02002861 return err;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002862}
2863
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002864static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2865{
Vivien Didelot04bed142016-08-31 18:06:13 -04002866 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002867 int err;
2868
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002869 if (!chip->info->ops->set_switch_mac)
2870 return -EOPNOTSUPP;
2871
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002872 mutex_lock(&chip->reg_lock);
Vivien Didelotb073d4e2016-09-29 12:22:01 -04002873 err = chip->info->ops->set_switch_mac(chip, addr);
Vivien Didelot3b4caa12016-07-18 20:45:34 -04002874 mutex_unlock(&chip->reg_lock);
2875
2876 return err;
2877}
2878
Vivien Didelote57e5e72016-08-15 17:19:00 -04002879static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002880{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002881 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002882 u16 val;
2883 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002884
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002885 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002886 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002887
Vivien Didelotfad09c72016-06-21 12:28:20 -04002888 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002889 err = mv88e6xxx_phy_read(chip, phy, reg, &val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002890 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002891
2892 return err ? err : val;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002893}
2894
Vivien Didelote57e5e72016-08-15 17:19:00 -04002895static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002896{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002897 struct mv88e6xxx_chip *chip = bus->priv;
Vivien Didelote57e5e72016-08-15 17:19:00 -04002898 int err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002899
Vivien Didelot370b4ff2016-09-29 12:21:57 -04002900 if (phy >= mv88e6xxx_num_ports(chip))
Andrew Lunn158bc062016-04-28 21:24:06 -04002901 return 0xffff;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002902
Vivien Didelotfad09c72016-06-21 12:28:20 -04002903 mutex_lock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002904 err = mv88e6xxx_phy_write(chip, phy, reg, val);
Vivien Didelotfad09c72016-06-21 12:28:20 -04002905 mutex_unlock(&chip->reg_lock);
Vivien Didelote57e5e72016-08-15 17:19:00 -04002906
2907 return err;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002908}
2909
Vivien Didelotfad09c72016-06-21 12:28:20 -04002910static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
Andrew Lunnb516d452016-06-04 21:17:06 +02002911 struct device_node *np)
2912{
2913 static int index;
2914 struct mii_bus *bus;
2915 int err;
2916
Andrew Lunnb516d452016-06-04 21:17:06 +02002917 if (np)
Vivien Didelotfad09c72016-06-21 12:28:20 -04002918 chip->mdio_np = of_get_child_by_name(np, "mdio");
Andrew Lunnb516d452016-06-04 21:17:06 +02002919
Vivien Didelotfad09c72016-06-21 12:28:20 -04002920 bus = devm_mdiobus_alloc(chip->dev);
Andrew Lunnb516d452016-06-04 21:17:06 +02002921 if (!bus)
2922 return -ENOMEM;
2923
Vivien Didelotfad09c72016-06-21 12:28:20 -04002924 bus->priv = (void *)chip;
Andrew Lunnb516d452016-06-04 21:17:06 +02002925 if (np) {
2926 bus->name = np->full_name;
2927 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2928 } else {
2929 bus->name = "mv88e6xxx SMI";
2930 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2931 }
2932
2933 bus->read = mv88e6xxx_mdio_read;
2934 bus->write = mv88e6xxx_mdio_write;
Vivien Didelotfad09c72016-06-21 12:28:20 -04002935 bus->parent = chip->dev;
Andrew Lunnb516d452016-06-04 21:17:06 +02002936
Vivien Didelotfad09c72016-06-21 12:28:20 -04002937 if (chip->mdio_np)
2938 err = of_mdiobus_register(bus, chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002939 else
2940 err = mdiobus_register(bus);
2941 if (err) {
Vivien Didelotfad09c72016-06-21 12:28:20 -04002942 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
Andrew Lunnb516d452016-06-04 21:17:06 +02002943 goto out;
2944 }
Vivien Didelotfad09c72016-06-21 12:28:20 -04002945 chip->mdio_bus = bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002946
2947 return 0;
2948
2949out:
Vivien Didelotfad09c72016-06-21 12:28:20 -04002950 if (chip->mdio_np)
2951 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002952
2953 return err;
2954}
2955
Vivien Didelotfad09c72016-06-21 12:28:20 -04002956static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip)
Andrew Lunnb516d452016-06-04 21:17:06 +02002957
2958{
Vivien Didelotfad09c72016-06-21 12:28:20 -04002959 struct mii_bus *bus = chip->mdio_bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02002960
2961 mdiobus_unregister(bus);
2962
Vivien Didelotfad09c72016-06-21 12:28:20 -04002963 if (chip->mdio_np)
2964 of_node_put(chip->mdio_np);
Andrew Lunnb516d452016-06-04 21:17:06 +02002965}
2966
Guenter Roeckc22995c2015-07-25 09:42:28 -07002967#ifdef CONFIG_NET_DSA_HWMON
2968
2969static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp)
2970{
Vivien Didelot04bed142016-08-31 18:06:13 -04002971 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot9c938292016-08-15 17:19:02 -04002972 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07002973 int ret;
Guenter Roeckc22995c2015-07-25 09:42:28 -07002974
2975 *temp = 0;
2976
Vivien Didelotfad09c72016-06-21 12:28:20 -04002977 mutex_lock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07002978
Vivien Didelot9c938292016-08-15 17:19:02 -04002979 ret = mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x6);
Guenter Roeckc22995c2015-07-25 09:42:28 -07002980 if (ret < 0)
2981 goto error;
2982
2983 /* Enable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04002984 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
Guenter Roeckc22995c2015-07-25 09:42:28 -07002985 if (ret < 0)
2986 goto error;
2987
Vivien Didelot9c938292016-08-15 17:19:02 -04002988 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val | (1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07002989 if (ret < 0)
2990 goto error;
2991
2992 /* Wait for temperature to stabilize */
2993 usleep_range(10000, 12000);
2994
Vivien Didelot9c938292016-08-15 17:19:02 -04002995 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
2996 if (ret < 0)
Guenter Roeckc22995c2015-07-25 09:42:28 -07002997 goto error;
Guenter Roeckc22995c2015-07-25 09:42:28 -07002998
2999 /* Disable temperature sensor */
Vivien Didelot9c938292016-08-15 17:19:02 -04003000 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val & ~(1 << 5));
Guenter Roeckc22995c2015-07-25 09:42:28 -07003001 if (ret < 0)
3002 goto error;
3003
3004 *temp = ((val & 0x1f) - 5) * 5;
3005
3006error:
Vivien Didelot9c938292016-08-15 17:19:02 -04003007 mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x0);
Vivien Didelotfad09c72016-06-21 12:28:20 -04003008 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003009 return ret;
3010}
3011
3012static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp)
3013{
Vivien Didelot04bed142016-08-31 18:06:13 -04003014 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003015 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003016 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003017 int ret;
3018
3019 *temp = 0;
3020
Vivien Didelot9c938292016-08-15 17:19:02 -04003021 mutex_lock(&chip->reg_lock);
3022 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 27, &val);
3023 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003024 if (ret < 0)
3025 return ret;
3026
Vivien Didelot9c938292016-08-15 17:19:02 -04003027 *temp = (val & 0xff) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003028
3029 return 0;
3030}
3031
Vivien Didelotf81ec902016-05-09 13:22:58 -04003032static int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003033{
Vivien Didelot04bed142016-08-31 18:06:13 -04003034 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn158bc062016-04-28 21:24:06 -04003035
Vivien Didelotfad09c72016-06-21 12:28:20 -04003036 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP))
Vivien Didelot6594f612016-05-09 13:22:42 -04003037 return -EOPNOTSUPP;
3038
Vivien Didelotfad09c72016-06-21 12:28:20 -04003039 if (mv88e6xxx_6320_family(chip) || mv88e6xxx_6352_family(chip))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003040 return mv88e63xx_get_temp(ds, temp);
3041
3042 return mv88e61xx_get_temp(ds, temp);
3043}
3044
Vivien Didelotf81ec902016-05-09 13:22:58 -04003045static int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003046{
Vivien Didelot04bed142016-08-31 18:06:13 -04003047 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003048 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003049 u16 val;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003050 int ret;
3051
Vivien Didelotfad09c72016-06-21 12:28:20 -04003052 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003053 return -EOPNOTSUPP;
3054
3055 *temp = 0;
3056
Vivien Didelot9c938292016-08-15 17:19:02 -04003057 mutex_lock(&chip->reg_lock);
3058 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3059 mutex_unlock(&chip->reg_lock);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003060 if (ret < 0)
3061 return ret;
3062
Vivien Didelot9c938292016-08-15 17:19:02 -04003063 *temp = (((val >> 8) & 0x1f) * 5) - 25;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003064
3065 return 0;
3066}
3067
Vivien Didelotf81ec902016-05-09 13:22:58 -04003068static int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp)
Guenter Roeckc22995c2015-07-25 09:42:28 -07003069{
Vivien Didelot04bed142016-08-31 18:06:13 -04003070 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelotfad09c72016-06-21 12:28:20 -04003071 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
Vivien Didelot9c938292016-08-15 17:19:02 -04003072 u16 val;
3073 int err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003074
Vivien Didelotfad09c72016-06-21 12:28:20 -04003075 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
Guenter Roeckc22995c2015-07-25 09:42:28 -07003076 return -EOPNOTSUPP;
3077
Vivien Didelot9c938292016-08-15 17:19:02 -04003078 mutex_lock(&chip->reg_lock);
3079 err = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3080 if (err)
3081 goto unlock;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003082 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
Vivien Didelot9c938292016-08-15 17:19:02 -04003083 err = mv88e6xxx_phy_page_write(chip, phy, 6, 26,
3084 (val & 0xe0ff) | (temp << 8));
3085unlock:
3086 mutex_unlock(&chip->reg_lock);
3087
3088 return err;
Guenter Roeckc22995c2015-07-25 09:42:28 -07003089}
3090
Vivien Didelotf81ec902016-05-09 13:22:58 -04003091static int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
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 *alarm = false;
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 *alarm = !!(val & 0x40);
Guenter Roeckc22995c2015-07-25 09:42:28 -07003110
3111 return 0;
3112}
3113#endif /* CONFIG_NET_DSA_HWMON */
3114
Vivien Didelot855b1932016-07-20 18:18:35 -04003115static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3116{
Vivien Didelot04bed142016-08-31 18:06:13 -04003117 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003118
3119 return chip->eeprom_len;
3120}
3121
Vivien Didelot855b1932016-07-20 18:18:35 -04003122static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3123 struct ethtool_eeprom *eeprom, u8 *data)
3124{
Vivien Didelot04bed142016-08-31 18:06:13 -04003125 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003126 int err;
3127
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003128 if (!chip->info->ops->get_eeprom)
3129 return -EOPNOTSUPP;
3130
Vivien Didelot855b1932016-07-20 18:18:35 -04003131 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003132 err = chip->info->ops->get_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003133 mutex_unlock(&chip->reg_lock);
3134
3135 if (err)
3136 return err;
3137
3138 eeprom->magic = 0xc3ec4951;
3139
3140 return 0;
3141}
3142
Vivien Didelot855b1932016-07-20 18:18:35 -04003143static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3144 struct ethtool_eeprom *eeprom, u8 *data)
3145{
Vivien Didelot04bed142016-08-31 18:06:13 -04003146 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot855b1932016-07-20 18:18:35 -04003147 int err;
3148
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003149 if (!chip->info->ops->set_eeprom)
3150 return -EOPNOTSUPP;
3151
Vivien Didelot855b1932016-07-20 18:18:35 -04003152 if (eeprom->magic != 0xc3ec4951)
3153 return -EINVAL;
3154
3155 mutex_lock(&chip->reg_lock);
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003156 err = chip->info->ops->set_eeprom(chip, eeprom, data);
Vivien Didelot855b1932016-07-20 18:18:35 -04003157 mutex_unlock(&chip->reg_lock);
3158
3159 return err;
3160}
3161
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003162static const struct mv88e6xxx_ops mv88e6085_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003163 /* MV88E6XXX_FAMILY_6097 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003164 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003165 .phy_read = mv88e6xxx_phy_ppu_read,
3166 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003167 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003168 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003169 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003170 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003171 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3172 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3173 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunnef70b112016-12-03 04:45:18 +01003174 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003175 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003176 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003177 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3178 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003179 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003180 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3181 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003182 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003183 .ppu_enable = mv88e6185_g1_ppu_enable,
3184 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003185 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003186};
3187
3188static const struct mv88e6xxx_ops mv88e6095_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003189 /* MV88E6XXX_FAMILY_6095 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003190 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003191 .phy_read = mv88e6xxx_phy_ppu_read,
3192 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003193 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003194 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003195 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003196 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3197 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003198 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003199 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3200 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003201 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003202 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003203 .ppu_enable = mv88e6185_g1_ppu_enable,
3204 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003205 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003206};
3207
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003208static const struct mv88e6xxx_ops mv88e6097_ops = {
Stefan Eichenberger15da3cc2016-11-25 09:41:30 +01003209 /* MV88E6XXX_FAMILY_6097 */
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003210 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3211 .phy_read = mv88e6xxx_g2_smi_phy_read,
3212 .phy_write = mv88e6xxx_g2_smi_phy_write,
3213 .port_set_link = mv88e6xxx_port_set_link,
3214 .port_set_duplex = mv88e6xxx_port_set_duplex,
3215 .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 Lunn5f436662016-12-03 04:45:17 +01003220 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003221 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003222 .port_pause_config = mv88e6097_port_pause_config,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003223 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
3224 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3225 .stats_get_strings = mv88e6095_stats_get_strings,
3226 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003227 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3228 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003229 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003230 .reset = mv88e6352_g1_reset,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003231};
3232
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003233static const struct mv88e6xxx_ops mv88e6123_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003234 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003235 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003236 .phy_read = mv88e6xxx_read,
3237 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003238 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003239 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003240 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003241 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3242 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003243 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003244 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3245 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003246 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003247 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3248 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003249 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003250 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003251};
3252
3253static const struct mv88e6xxx_ops mv88e6131_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003254 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003255 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003256 .phy_read = mv88e6xxx_phy_ppu_read,
3257 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003258 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003259 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003260 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003261 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003262 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3263 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3264 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003265 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003266 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003267 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003268 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003269 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3270 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003271 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003272 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3273 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003274 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003275 .ppu_enable = mv88e6185_g1_ppu_enable,
3276 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003277 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003278};
3279
3280static const struct mv88e6xxx_ops mv88e6161_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003281 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003282 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003283 .phy_read = mv88e6xxx_read,
3284 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003285 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003286 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003287 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003288 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003289 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3290 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3291 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003292 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003293 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003294 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003295 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003296 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3297 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003298 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003299 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3300 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003301 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003302 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003303};
3304
3305static const struct mv88e6xxx_ops mv88e6165_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003306 /* MV88E6XXX_FAMILY_6165 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003307 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003308 .phy_read = mv88e6xxx_read,
3309 .phy_write = mv88e6xxx_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003310 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003311 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003312 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003313 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003314 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3315 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003316 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003317 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3318 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003319 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003320 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003321};
3322
3323static const struct mv88e6xxx_ops mv88e6171_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003324 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003325 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003326 .phy_read = mv88e6xxx_g2_smi_phy_read,
3327 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003328 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003329 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003330 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003331 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003332 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003333 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3334 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3335 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003336 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003337 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003338 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003339 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003340 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3341 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003342 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003343 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3344 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003345 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003346 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003347};
3348
3349static const struct mv88e6xxx_ops mv88e6172_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003350 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003351 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3352 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003353 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003354 .phy_read = mv88e6xxx_g2_smi_phy_read,
3355 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003356 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003357 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003358 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003359 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003360 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003361 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3362 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3363 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003364 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003365 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003366 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003367 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003368 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3369 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003370 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003371 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3372 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003373 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003374 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003375};
3376
3377static const struct mv88e6xxx_ops mv88e6175_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003378 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003379 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003380 .phy_read = mv88e6xxx_g2_smi_phy_read,
3381 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003382 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003383 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003384 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003385 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003386 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003387 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3388 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3389 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003390 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003391 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003392 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003393 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003394 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3395 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003396 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003397 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3398 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003399 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003400 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003401};
3402
3403static const struct mv88e6xxx_ops mv88e6176_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003404 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003405 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3406 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003407 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003408 .phy_read = mv88e6xxx_g2_smi_phy_read,
3409 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003410 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003411 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003412 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003413 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003414 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003415 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3416 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3417 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003418 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003419 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003420 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003421 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003422 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3423 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003424 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003425 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3426 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003427 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003428 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003429};
3430
3431static const struct mv88e6xxx_ops mv88e6185_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003432 /* MV88E6XXX_FAMILY_6185 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003433 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003434 .phy_read = mv88e6xxx_phy_ppu_read,
3435 .phy_write = mv88e6xxx_phy_ppu_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003436 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003437 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003438 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003439 .port_set_frame_mode = mv88e6085_port_set_frame_mode,
3440 .port_set_egress_unknowns = mv88e6085_port_set_egress_unknowns,
Andrew Lunnef70b112016-12-03 04:45:18 +01003441 .port_egress_rate_limiting = mv88e6095_port_egress_rate_limiting,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003442 .stats_snapshot = mv88e6xxx_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003443 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3444 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003445 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003446 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3447 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003448 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelota199d8b2016-12-05 17:30:28 -05003449 .ppu_enable = mv88e6185_g1_ppu_enable,
3450 .ppu_disable = mv88e6185_g1_ppu_disable,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003451 .reset = mv88e6185_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003452};
3453
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003454static const struct mv88e6xxx_ops mv88e6190_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003455 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003456 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3457 .phy_read = mv88e6xxx_g2_smi_phy_read,
3458 .phy_write = mv88e6xxx_g2_smi_phy_write,
3459 .port_set_link = mv88e6xxx_port_set_link,
3460 .port_set_duplex = mv88e6xxx_port_set_duplex,
3461 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3462 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003463 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003464 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3465 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3466 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003467 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003468 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003469 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003470 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3471 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003472 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003473 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3474 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003475 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003476 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003477};
3478
3479static const struct mv88e6xxx_ops mv88e6190x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003480 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003481 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3482 .phy_read = mv88e6xxx_g2_smi_phy_read,
3483 .phy_write = mv88e6xxx_g2_smi_phy_write,
3484 .port_set_link = mv88e6xxx_port_set_link,
3485 .port_set_duplex = mv88e6xxx_port_set_duplex,
3486 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3487 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003488 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003489 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3490 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3491 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003492 .port_pause_config = mv88e6390_port_pause_config,
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,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003501 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003502};
3503
3504static const struct mv88e6xxx_ops mv88e6191_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003505 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003506 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3507 .phy_read = mv88e6xxx_g2_smi_phy_read,
3508 .phy_write = mv88e6xxx_g2_smi_phy_write,
3509 .port_set_link = mv88e6xxx_port_set_link,
3510 .port_set_duplex = mv88e6xxx_port_set_duplex,
3511 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3512 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003513 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003514 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3515 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3516 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003517 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003518 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003519 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003520 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3521 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003522 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003523 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3524 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003525 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003526 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003527};
3528
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003529static const struct mv88e6xxx_ops mv88e6240_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003530 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003531 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3532 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003533 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003534 .phy_read = mv88e6xxx_g2_smi_phy_read,
3535 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003536 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003537 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003538 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003539 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003540 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003541 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3542 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3543 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003544 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003545 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003546 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003547 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003548 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3549 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003550 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003551 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3552 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003553 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003554 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003555};
3556
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003557static const struct mv88e6xxx_ops mv88e6290_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003558 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003559 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3560 .phy_read = mv88e6xxx_g2_smi_phy_read,
3561 .phy_write = mv88e6xxx_g2_smi_phy_write,
3562 .port_set_link = mv88e6xxx_port_set_link,
3563 .port_set_duplex = mv88e6xxx_port_set_duplex,
3564 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3565 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003566 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003567 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3568 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3569 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003570 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003571 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003572 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003573 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3574 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003575 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003576 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3577 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003578 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003579 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003580};
3581
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003582static const struct mv88e6xxx_ops mv88e6320_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003583 /* MV88E6XXX_FAMILY_6320 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003584 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3585 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003586 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003587 .phy_read = mv88e6xxx_g2_smi_phy_read,
3588 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003589 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003590 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003591 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003592 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003593 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3594 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3595 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003596 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003597 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003598 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003599 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003600 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3601 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003602 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003603 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3604 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003605 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003606 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003607};
3608
3609static const struct mv88e6xxx_ops mv88e6321_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003610 /* MV88E6XXX_FAMILY_6321 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003611 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3612 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003613 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003614 .phy_read = mv88e6xxx_g2_smi_phy_read,
3615 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003616 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003617 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003618 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003619 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003620 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3621 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3622 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003623 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003624 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003625 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003626 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003627 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3628 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003629 .stats_get_stats = mv88e6320_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003630 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3631 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003632 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003633};
3634
3635static const struct mv88e6xxx_ops mv88e6350_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003636 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003637 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003638 .phy_read = mv88e6xxx_g2_smi_phy_read,
3639 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003640 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003641 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003642 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003643 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003644 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003645 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3646 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3647 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003648 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003649 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003650 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003651 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003652 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3653 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003654 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003655 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3656 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003657 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003658 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003659};
3660
3661static const struct mv88e6xxx_ops mv88e6351_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003662 /* MV88E6XXX_FAMILY_6351 */
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003663 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003664 .phy_read = mv88e6xxx_g2_smi_phy_read,
3665 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003666 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003667 .port_set_duplex = mv88e6xxx_port_set_duplex,
Andrew Lunn94d66ae2016-11-10 15:44:01 +01003668 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003669 .port_set_speed = mv88e6185_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003670 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003671 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3672 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3673 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003674 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003675 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003676 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003677 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003678 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3679 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003680 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003681 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3682 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003683 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003684 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003685};
3686
3687static const struct mv88e6xxx_ops mv88e6352_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003688 /* MV88E6XXX_FAMILY_6352 */
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04003689 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3690 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
Vivien Didelotb073d4e2016-09-29 12:22:01 -04003691 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003692 .phy_read = mv88e6xxx_g2_smi_phy_read,
3693 .phy_write = mv88e6xxx_g2_smi_phy_write,
Vivien Didelot08ef7f12016-11-04 03:23:32 +01003694 .port_set_link = mv88e6xxx_port_set_link,
Vivien Didelot7f1ae072016-11-04 03:23:33 +01003695 .port_set_duplex = mv88e6xxx_port_set_duplex,
Vivien Didelota0a0f622016-11-04 03:23:34 +01003696 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
Vivien Didelot96a2b402016-11-04 03:23:35 +01003697 .port_set_speed = mv88e6352_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003698 .port_tag_remap = mv88e6095_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003699 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3700 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3701 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003702 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003703 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunnb35d322a2016-12-03 04:45:19 +01003704 .port_pause_config = mv88e6097_port_pause_config,
Andrew Lunna605a0f2016-11-21 23:26:58 +01003705 .stats_snapshot = mv88e6320_g1_stats_snapshot,
Andrew Lunndfafe442016-11-21 23:27:02 +01003706 .stats_get_sset_count = mv88e6095_stats_get_sset_count,
3707 .stats_get_strings = mv88e6095_stats_get_strings,
Andrew Lunn052f9472016-11-21 23:27:03 +01003708 .stats_get_stats = mv88e6095_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003709 .g1_set_cpu_port = mv88e6095_g1_set_cpu_port,
3710 .g1_set_egress_port = mv88e6095_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003711 .mgmt_rsvd2cpu = mv88e6095_g2_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003712 .reset = mv88e6352_g1_reset,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003713};
3714
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003715static const struct mv88e6xxx_ops mv88e6390_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003716 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003717 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3718 .phy_read = mv88e6xxx_g2_smi_phy_read,
3719 .phy_write = mv88e6xxx_g2_smi_phy_write,
3720 .port_set_link = mv88e6xxx_port_set_link,
3721 .port_set_duplex = mv88e6xxx_port_set_duplex,
3722 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3723 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003724 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003725 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3726 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3727 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003728 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003729 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003730 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003731 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003732 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003733 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3734 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003735 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003736 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3737 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003738 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003739 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003740};
3741
3742static const struct mv88e6xxx_ops mv88e6390x_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003743 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003744 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3745 .phy_read = mv88e6xxx_g2_smi_phy_read,
3746 .phy_write = mv88e6xxx_g2_smi_phy_write,
3747 .port_set_link = mv88e6xxx_port_set_link,
3748 .port_set_duplex = mv88e6xxx_port_set_duplex,
3749 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3750 .port_set_speed = mv88e6390x_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003751 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003752 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3753 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3754 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn5f436662016-12-03 04:45:17 +01003755 .port_jumbo_config = mv88e6165_port_jumbo_config,
Andrew Lunnef70b112016-12-03 04:45:18 +01003756 .port_egress_rate_limiting = mv88e6097_port_egress_rate_limiting,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003757 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003758 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003759 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003760 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3761 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003762 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003763 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3764 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003765 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003766 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003767};
3768
3769static const struct mv88e6xxx_ops mv88e6391_ops = {
Andrew Lunn4b325d82016-11-21 23:26:59 +01003770 /* MV88E6XXX_FAMILY_6390 */
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003771 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3772 .phy_read = mv88e6xxx_g2_smi_phy_read,
3773 .phy_write = mv88e6xxx_g2_smi_phy_write,
3774 .port_set_link = mv88e6xxx_port_set_link,
3775 .port_set_duplex = mv88e6xxx_port_set_duplex,
3776 .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
3777 .port_set_speed = mv88e6390_port_set_speed,
Andrew Lunnef0a7312016-12-03 04:35:16 +01003778 .port_tag_remap = mv88e6390_port_tag_remap,
Andrew Lunn56995cb2016-12-03 04:35:19 +01003779 .port_set_frame_mode = mv88e6351_port_set_frame_mode,
3780 .port_set_egress_unknowns = mv88e6351_port_set_egress_unknowns,
3781 .port_set_ether_type = mv88e6351_port_set_ether_type,
Andrew Lunn3ce0e652016-12-03 04:45:20 +01003782 .port_pause_config = mv88e6390_port_pause_config,
Andrew Lunn79523472016-11-21 23:27:00 +01003783 .stats_snapshot = mv88e6390_g1_stats_snapshot,
Andrew Lunnde2273872016-11-21 23:27:01 +01003784 .stats_set_histogram = mv88e6390_g1_stats_set_histogram,
Andrew Lunndfafe442016-11-21 23:27:02 +01003785 .stats_get_sset_count = mv88e6320_stats_get_sset_count,
3786 .stats_get_strings = mv88e6320_stats_get_strings,
Andrew Lunne0d8b612016-11-21 23:27:04 +01003787 .stats_get_stats = mv88e6390_stats_get_stats,
Andrew Lunn33641992016-12-03 04:35:17 +01003788 .g1_set_cpu_port = mv88e6390_g1_set_cpu_port,
3789 .g1_set_egress_port = mv88e6390_g1_set_egress_port,
Andrew Lunn6e55f692016-12-03 04:45:16 +01003790 .mgmt_rsvd2cpu = mv88e6390_g1_mgmt_rsvd2cpu,
Vivien Didelot17e708b2016-12-05 17:30:27 -05003791 .reset = mv88e6352_g1_reset,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003792};
3793
Andrew Lunn56995cb2016-12-03 04:35:19 +01003794static int mv88e6xxx_verify_madatory_ops(struct mv88e6xxx_chip *chip,
3795 const struct mv88e6xxx_ops *ops)
3796{
3797 if (!ops->port_set_frame_mode) {
3798 dev_err(chip->dev, "Missing port_set_frame_mode");
3799 return -EINVAL;
3800 }
3801
3802 if (!ops->port_set_egress_unknowns) {
3803 dev_err(chip->dev, "Missing port_set_egress_mode");
3804 return -EINVAL;
3805 }
3806
3807 return 0;
3808}
3809
Vivien Didelotf81ec902016-05-09 13:22:58 -04003810static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3811 [MV88E6085] = {
3812 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3813 .family = MV88E6XXX_FAMILY_6097,
3814 .name = "Marvell 88E6085",
3815 .num_databases = 4096,
3816 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003817 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003818 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003819 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003820 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003821 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003822 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003823 .ops = &mv88e6085_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003824 },
3825
3826 [MV88E6095] = {
3827 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3828 .family = MV88E6XXX_FAMILY_6095,
3829 .name = "Marvell 88E6095/88E6095F",
3830 .num_databases = 256,
3831 .num_ports = 11,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003832 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003833 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003834 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003835 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003836 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003837 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003838 .ops = &mv88e6095_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003839 },
3840
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003841 [MV88E6097] = {
3842 .prod_num = PORT_SWITCH_ID_PROD_NUM_6097,
3843 .family = MV88E6XXX_FAMILY_6097,
3844 .name = "Marvell 88E6097/88E6097F",
3845 .num_databases = 4096,
3846 .num_ports = 11,
3847 .port_base_addr = 0x10,
3848 .global1_addr = 0x1b,
3849 .age_time_coeff = 15000,
Stefan Eichenbergerc5341782016-11-25 09:41:29 +01003850 .g1_irqs = 8,
Stefan Eichenberger2bfcfcd2016-12-05 14:12:42 +01003851 .tag_protocol = DSA_TAG_PROTO_EDSA,
Stefan Eichenberger7d381a02016-11-22 17:47:21 +01003852 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3853 .ops = &mv88e6097_ops,
3854 },
3855
Vivien Didelotf81ec902016-05-09 13:22:58 -04003856 [MV88E6123] = {
3857 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3858 .family = MV88E6XXX_FAMILY_6165,
3859 .name = "Marvell 88E6123",
3860 .num_databases = 4096,
3861 .num_ports = 3,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003862 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003863 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003864 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003865 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003866 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003867 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003868 .ops = &mv88e6123_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003869 },
3870
3871 [MV88E6131] = {
3872 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3873 .family = MV88E6XXX_FAMILY_6185,
3874 .name = "Marvell 88E6131",
3875 .num_databases = 256,
3876 .num_ports = 8,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003877 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003878 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003879 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003880 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003881 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003882 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003883 .ops = &mv88e6131_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003884 },
3885
3886 [MV88E6161] = {
3887 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3888 .family = MV88E6XXX_FAMILY_6165,
3889 .name = "Marvell 88E6161",
3890 .num_databases = 4096,
3891 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003892 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003893 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003894 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003895 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003896 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003897 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003898 .ops = &mv88e6161_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003899 },
3900
3901 [MV88E6165] = {
3902 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3903 .family = MV88E6XXX_FAMILY_6165,
3904 .name = "Marvell 88E6165",
3905 .num_databases = 4096,
3906 .num_ports = 6,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003907 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003908 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003909 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003910 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003911 .tag_protocol = DSA_TAG_PROTO_DSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003912 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003913 .ops = &mv88e6165_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003914 },
3915
3916 [MV88E6171] = {
3917 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3918 .family = MV88E6XXX_FAMILY_6351,
3919 .name = "Marvell 88E6171",
3920 .num_databases = 4096,
3921 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003922 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003923 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003924 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003925 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003926 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003927 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003928 .ops = &mv88e6171_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003929 },
3930
3931 [MV88E6172] = {
3932 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3933 .family = MV88E6XXX_FAMILY_6352,
3934 .name = "Marvell 88E6172",
3935 .num_databases = 4096,
3936 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003937 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003938 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003939 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003940 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003941 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003942 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003943 .ops = &mv88e6172_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003944 },
3945
3946 [MV88E6175] = {
3947 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3948 .family = MV88E6XXX_FAMILY_6351,
3949 .name = "Marvell 88E6175",
3950 .num_databases = 4096,
3951 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003952 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003953 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003954 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003955 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003956 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003957 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003958 .ops = &mv88e6175_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003959 },
3960
3961 [MV88E6176] = {
3962 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3963 .family = MV88E6XXX_FAMILY_6352,
3964 .name = "Marvell 88E6176",
3965 .num_databases = 4096,
3966 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003967 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003968 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003969 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003970 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003971 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003972 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003973 .ops = &mv88e6176_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003974 },
3975
3976 [MV88E6185] = {
3977 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3978 .family = MV88E6XXX_FAMILY_6185,
3979 .name = "Marvell 88E6185",
3980 .num_databases = 256,
3981 .num_ports = 10,
Vivien Didelot9dddd472016-06-20 13:14:10 -04003982 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04003983 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04003984 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02003985 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003986 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003987 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04003988 .ops = &mv88e6185_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04003989 },
3990
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01003991 [MV88E6190] = {
3992 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190,
3993 .family = MV88E6XXX_FAMILY_6390,
3994 .name = "Marvell 88E6190",
3995 .num_databases = 4096,
3996 .num_ports = 11, /* 10 + Z80 */
3997 .port_base_addr = 0x0,
3998 .global1_addr = 0x1b,
Andrew Lunn443d5a12016-12-03 04:35:18 +01003999 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004000 .age_time_coeff = 15000,
4001 .g1_irqs = 9,
4002 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4003 .ops = &mv88e6190_ops,
4004 },
4005
4006 [MV88E6190X] = {
4007 .prod_num = PORT_SWITCH_ID_PROD_NUM_6190X,
4008 .family = MV88E6XXX_FAMILY_6390,
4009 .name = "Marvell 88E6190X",
4010 .num_databases = 4096,
4011 .num_ports = 11, /* 10 + Z80 */
4012 .port_base_addr = 0x0,
4013 .global1_addr = 0x1b,
4014 .age_time_coeff = 15000,
4015 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004016 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004017 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4018 .ops = &mv88e6190x_ops,
4019 },
4020
4021 [MV88E6191] = {
4022 .prod_num = PORT_SWITCH_ID_PROD_NUM_6191,
4023 .family = MV88E6XXX_FAMILY_6390,
4024 .name = "Marvell 88E6191",
4025 .num_databases = 4096,
4026 .num_ports = 11, /* 10 + Z80 */
4027 .port_base_addr = 0x0,
4028 .global1_addr = 0x1b,
4029 .age_time_coeff = 15000,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004030 .g1_irqs = 9,
4031 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004032 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4033 .ops = &mv88e6391_ops,
4034 },
4035
Vivien Didelotf81ec902016-05-09 13:22:58 -04004036 [MV88E6240] = {
4037 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
4038 .family = MV88E6XXX_FAMILY_6352,
4039 .name = "Marvell 88E6240",
4040 .num_databases = 4096,
4041 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004042 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004043 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004044 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004045 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004046 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004047 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004048 .ops = &mv88e6240_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004049 },
4050
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004051 [MV88E6290] = {
4052 .prod_num = PORT_SWITCH_ID_PROD_NUM_6290,
4053 .family = MV88E6XXX_FAMILY_6390,
4054 .name = "Marvell 88E6290",
4055 .num_databases = 4096,
4056 .num_ports = 11, /* 10 + Z80 */
4057 .port_base_addr = 0x0,
4058 .global1_addr = 0x1b,
4059 .age_time_coeff = 15000,
4060 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004061 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004062 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4063 .ops = &mv88e6290_ops,
4064 },
4065
Vivien Didelotf81ec902016-05-09 13:22:58 -04004066 [MV88E6320] = {
4067 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
4068 .family = MV88E6XXX_FAMILY_6320,
4069 .name = "Marvell 88E6320",
4070 .num_databases = 4096,
4071 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004072 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004073 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004074 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004075 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004076 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004077 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004078 .ops = &mv88e6320_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004079 },
4080
4081 [MV88E6321] = {
4082 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
4083 .family = MV88E6XXX_FAMILY_6320,
4084 .name = "Marvell 88E6321",
4085 .num_databases = 4096,
4086 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004087 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004088 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004089 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004090 .g1_irqs = 8,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004091 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004092 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004093 .ops = &mv88e6321_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004094 },
4095
4096 [MV88E6350] = {
4097 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
4098 .family = MV88E6XXX_FAMILY_6351,
4099 .name = "Marvell 88E6350",
4100 .num_databases = 4096,
4101 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004102 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004103 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004104 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004105 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004106 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004107 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004108 .ops = &mv88e6350_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004109 },
4110
4111 [MV88E6351] = {
4112 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
4113 .family = MV88E6XXX_FAMILY_6351,
4114 .name = "Marvell 88E6351",
4115 .num_databases = 4096,
4116 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004117 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004118 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004119 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004120 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004121 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004122 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004123 .ops = &mv88e6351_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004124 },
4125
4126 [MV88E6352] = {
4127 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
4128 .family = MV88E6XXX_FAMILY_6352,
4129 .name = "Marvell 88E6352",
4130 .num_databases = 4096,
4131 .num_ports = 7,
Vivien Didelot9dddd472016-06-20 13:14:10 -04004132 .port_base_addr = 0x10,
Vivien Didelota935c052016-09-29 12:21:53 -04004133 .global1_addr = 0x1b,
Vivien Didelotacddbd22016-07-18 20:45:39 -04004134 .age_time_coeff = 15000,
Andrew Lunndc30c352016-10-16 19:56:49 +02004135 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004136 .tag_protocol = DSA_TAG_PROTO_EDSA,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004137 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
Vivien Didelotb3469dd2016-09-29 12:22:00 -04004138 .ops = &mv88e6352_ops,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004139 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004140 [MV88E6390] = {
4141 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390,
4142 .family = MV88E6XXX_FAMILY_6390,
4143 .name = "Marvell 88E6390",
4144 .num_databases = 4096,
4145 .num_ports = 11, /* 10 + Z80 */
4146 .port_base_addr = 0x0,
4147 .global1_addr = 0x1b,
4148 .age_time_coeff = 15000,
4149 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004150 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004151 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4152 .ops = &mv88e6390_ops,
4153 },
4154 [MV88E6390X] = {
4155 .prod_num = PORT_SWITCH_ID_PROD_NUM_6390X,
4156 .family = MV88E6XXX_FAMILY_6390,
4157 .name = "Marvell 88E6390X",
4158 .num_databases = 4096,
4159 .num_ports = 11, /* 10 + Z80 */
4160 .port_base_addr = 0x0,
4161 .global1_addr = 0x1b,
4162 .age_time_coeff = 15000,
4163 .g1_irqs = 9,
Andrew Lunn443d5a12016-12-03 04:35:18 +01004164 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004165 .flags = MV88E6XXX_FLAGS_FAMILY_6390,
4166 .ops = &mv88e6390x_ops,
4167 },
Vivien Didelotf81ec902016-05-09 13:22:58 -04004168};
4169
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004170static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
Vivien Didelotb9b37712015-10-30 19:39:48 -04004171{
Vivien Didelota439c062016-04-17 13:23:58 -04004172 int i;
Vivien Didelotb9b37712015-10-30 19:39:48 -04004173
Vivien Didelot5f7c0362016-06-20 13:14:04 -04004174 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
4175 if (mv88e6xxx_table[i].prod_num == prod_num)
4176 return &mv88e6xxx_table[i];
Vivien Didelotb9b37712015-10-30 19:39:48 -04004177
Vivien Didelotb9b37712015-10-30 19:39:48 -04004178 return NULL;
4179}
4180
Vivien Didelotfad09c72016-06-21 12:28:20 -04004181static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004182{
4183 const struct mv88e6xxx_info *info;
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004184 unsigned int prod_num, rev;
4185 u16 id;
4186 int err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004187
Vivien Didelot8f6345b2016-07-20 18:18:36 -04004188 mutex_lock(&chip->reg_lock);
4189 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
4190 mutex_unlock(&chip->reg_lock);
4191 if (err)
4192 return err;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004193
4194 prod_num = (id & 0xfff0) >> 4;
4195 rev = id & 0x000f;
4196
4197 info = mv88e6xxx_lookup_info(prod_num);
4198 if (!info)
4199 return -ENODEV;
4200
Vivien Didelotcaac8542016-06-20 13:14:09 -04004201 /* Update the compatible info with the probed one */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004202 chip->info = info;
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004203
Vivien Didelotca070c12016-09-02 14:45:34 -04004204 err = mv88e6xxx_g2_require(chip);
4205 if (err)
4206 return err;
4207
Vivien Didelotfad09c72016-06-21 12:28:20 -04004208 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
4209 chip->info->prod_num, chip->info->name, rev);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004210
4211 return 0;
4212}
4213
Vivien Didelotfad09c72016-06-21 12:28:20 -04004214static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
Vivien Didelot469d7292016-06-20 13:14:06 -04004215{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004216 struct mv88e6xxx_chip *chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004217
Vivien Didelotfad09c72016-06-21 12:28:20 -04004218 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
4219 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004220 return NULL;
4221
Vivien Didelotfad09c72016-06-21 12:28:20 -04004222 chip->dev = dev;
Vivien Didelot469d7292016-06-20 13:14:06 -04004223
Vivien Didelotfad09c72016-06-21 12:28:20 -04004224 mutex_init(&chip->reg_lock);
Vivien Didelot469d7292016-06-20 13:14:06 -04004225
Vivien Didelotfad09c72016-06-21 12:28:20 -04004226 return chip;
Vivien Didelot469d7292016-06-20 13:14:06 -04004227}
4228
Vivien Didelote57e5e72016-08-15 17:19:00 -04004229static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
4230{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004231 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Vivien Didelote57e5e72016-08-15 17:19:00 -04004232 mv88e6xxx_ppu_state_init(chip);
Vivien Didelote57e5e72016-08-15 17:19:00 -04004233}
4234
Andrew Lunn930188c2016-08-22 16:01:03 +02004235static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
4236{
Vivien Didelota199d8b2016-12-05 17:30:28 -05004237 if (chip->info->ops->ppu_enable && chip->info->ops->ppu_disable)
Andrew Lunn930188c2016-08-22 16:01:03 +02004238 mv88e6xxx_ppu_state_destroy(chip);
Andrew Lunn930188c2016-08-22 16:01:03 +02004239}
4240
Vivien Didelotfad09c72016-06-21 12:28:20 -04004241static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004242 struct mii_bus *bus, int sw_addr)
4243{
Vivien Didelot914b32f2016-06-20 13:14:11 -04004244 if (sw_addr == 0)
Vivien Didelotfad09c72016-06-21 12:28:20 -04004245 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
Vivien Didelota0ffff22016-08-15 17:18:58 -04004246 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004247 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
Vivien Didelot914b32f2016-06-20 13:14:11 -04004248 else
4249 return -EINVAL;
4250
Vivien Didelotfad09c72016-06-21 12:28:20 -04004251 chip->bus = bus;
4252 chip->sw_addr = sw_addr;
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004253
4254 return 0;
4255}
4256
Andrew Lunn7b314362016-08-22 16:01:01 +02004257static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
4258{
Vivien Didelot04bed142016-08-31 18:06:13 -04004259 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn2bbb33b2016-08-22 16:01:02 +02004260
Andrew Lunn443d5a12016-12-03 04:35:18 +01004261 return chip->info->tag_protocol;
Andrew Lunn7b314362016-08-22 16:01:01 +02004262}
4263
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004264static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
4265 struct device *host_dev, int sw_addr,
4266 void **priv)
Andrew Lunna77d43f2016-04-13 02:40:42 +02004267{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004268 struct mv88e6xxx_chip *chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004269 struct mii_bus *bus;
Andrew Lunnb516d452016-06-04 21:17:06 +02004270 int err;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004271
Vivien Didelota439c062016-04-17 13:23:58 -04004272 bus = dsa_host_dev_to_mii_bus(host_dev);
Andrew Lunnc1569132016-04-13 02:40:45 +02004273 if (!bus)
4274 return NULL;
4275
Vivien Didelotfad09c72016-06-21 12:28:20 -04004276 chip = mv88e6xxx_alloc_chip(dsa_dev);
4277 if (!chip)
Vivien Didelot469d7292016-06-20 13:14:06 -04004278 return NULL;
4279
Vivien Didelotcaac8542016-06-20 13:14:09 -04004280 /* Legacy SMI probing will only support chips similar to 88E6085 */
Vivien Didelotfad09c72016-06-21 12:28:20 -04004281 chip->info = &mv88e6xxx_table[MV88E6085];
Vivien Didelotcaac8542016-06-20 13:14:09 -04004282
Vivien Didelotfad09c72016-06-21 12:28:20 -04004283 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004284 if (err)
4285 goto free;
4286
Vivien Didelotfad09c72016-06-21 12:28:20 -04004287 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004288 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004289 goto free;
Vivien Didelota439c062016-04-17 13:23:58 -04004290
Andrew Lunndc30c352016-10-16 19:56:49 +02004291 mutex_lock(&chip->reg_lock);
4292 err = mv88e6xxx_switch_reset(chip);
4293 mutex_unlock(&chip->reg_lock);
4294 if (err)
4295 goto free;
4296
Vivien Didelote57e5e72016-08-15 17:19:00 -04004297 mv88e6xxx_phy_init(chip);
4298
Vivien Didelotfad09c72016-06-21 12:28:20 -04004299 err = mv88e6xxx_mdio_register(chip, NULL);
Andrew Lunnb516d452016-06-04 21:17:06 +02004300 if (err)
Vivien Didelot469d7292016-06-20 13:14:06 -04004301 goto free;
Andrew Lunnb516d452016-06-04 21:17:06 +02004302
Vivien Didelotfad09c72016-06-21 12:28:20 -04004303 *priv = chip;
Vivien Didelota439c062016-04-17 13:23:58 -04004304
Vivien Didelotfad09c72016-06-21 12:28:20 -04004305 return chip->info->name;
Vivien Didelot469d7292016-06-20 13:14:06 -04004306free:
Vivien Didelotfad09c72016-06-21 12:28:20 -04004307 devm_kfree(dsa_dev, chip);
Vivien Didelot469d7292016-06-20 13:14:06 -04004308
4309 return NULL;
Andrew Lunna77d43f2016-04-13 02:40:42 +02004310}
4311
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004312static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
4313 const struct switchdev_obj_port_mdb *mdb,
4314 struct switchdev_trans *trans)
4315{
4316 /* We don't need any dynamic resource from the kernel (yet),
4317 * so skip the prepare phase.
4318 */
4319
4320 return 0;
4321}
4322
4323static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
4324 const struct switchdev_obj_port_mdb *mdb,
4325 struct switchdev_trans *trans)
4326{
Vivien Didelot04bed142016-08-31 18:06:13 -04004327 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004328
4329 mutex_lock(&chip->reg_lock);
4330 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4331 GLOBAL_ATU_DATA_STATE_MC_STATIC))
4332 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
4333 mutex_unlock(&chip->reg_lock);
4334}
4335
4336static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
4337 const struct switchdev_obj_port_mdb *mdb)
4338{
Vivien Didelot04bed142016-08-31 18:06:13 -04004339 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004340 int err;
4341
4342 mutex_lock(&chip->reg_lock);
4343 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
4344 GLOBAL_ATU_DATA_STATE_UNUSED);
4345 mutex_unlock(&chip->reg_lock);
4346
4347 return err;
4348}
4349
4350static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
4351 struct switchdev_obj_port_mdb *mdb,
4352 int (*cb)(struct switchdev_obj *obj))
4353{
Vivien Didelot04bed142016-08-31 18:06:13 -04004354 struct mv88e6xxx_chip *chip = ds->priv;
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004355 int err;
4356
4357 mutex_lock(&chip->reg_lock);
4358 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
4359 mutex_unlock(&chip->reg_lock);
4360
4361 return err;
4362}
4363
Florian Fainellia82f67a2017-01-08 14:52:08 -08004364static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
Andrew Lunnfcdce7d2016-05-10 23:27:20 +02004365 .probe = mv88e6xxx_drv_probe,
Andrew Lunn7b314362016-08-22 16:01:01 +02004366 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004367 .setup = mv88e6xxx_setup,
4368 .set_addr = mv88e6xxx_set_addr,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004369 .adjust_link = mv88e6xxx_adjust_link,
4370 .get_strings = mv88e6xxx_get_strings,
4371 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
4372 .get_sset_count = mv88e6xxx_get_sset_count,
4373 .set_eee = mv88e6xxx_set_eee,
4374 .get_eee = mv88e6xxx_get_eee,
4375#ifdef CONFIG_NET_DSA_HWMON
4376 .get_temp = mv88e6xxx_get_temp,
4377 .get_temp_limit = mv88e6xxx_get_temp_limit,
4378 .set_temp_limit = mv88e6xxx_set_temp_limit,
4379 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
4380#endif
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004381 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004382 .get_eeprom = mv88e6xxx_get_eeprom,
4383 .set_eeprom = mv88e6xxx_set_eeprom,
4384 .get_regs_len = mv88e6xxx_get_regs_len,
4385 .get_regs = mv88e6xxx_get_regs,
Vivien Didelot2cfcd962016-07-18 20:45:40 -04004386 .set_ageing_time = mv88e6xxx_set_ageing_time,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004387 .port_bridge_join = mv88e6xxx_port_bridge_join,
4388 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
4389 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
Vivien Didelot749efcb2016-09-22 16:49:24 -04004390 .port_fast_age = mv88e6xxx_port_fast_age,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004391 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
4392 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
4393 .port_vlan_add = mv88e6xxx_port_vlan_add,
4394 .port_vlan_del = mv88e6xxx_port_vlan_del,
4395 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
4396 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
4397 .port_fdb_add = mv88e6xxx_port_fdb_add,
4398 .port_fdb_del = mv88e6xxx_port_fdb_del,
4399 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Vivien Didelot7df8fbd2016-08-31 11:50:05 -04004400 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
4401 .port_mdb_add = mv88e6xxx_port_mdb_add,
4402 .port_mdb_del = mv88e6xxx_port_mdb_del,
4403 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
Vivien Didelotf81ec902016-05-09 13:22:58 -04004404};
4405
Florian Fainelliab3d4082017-01-08 14:52:07 -08004406static struct dsa_switch_driver mv88e6xxx_switch_drv = {
4407 .ops = &mv88e6xxx_switch_ops,
4408};
4409
Vivien Didelotfad09c72016-06-21 12:28:20 -04004410static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004411 struct device_node *np)
4412{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004413 struct device *dev = chip->dev;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004414 struct dsa_switch *ds;
4415
4416 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
4417 if (!ds)
4418 return -ENOMEM;
4419
4420 ds->dev = dev;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004421 ds->priv = chip;
Vivien Didelot9d490b42016-08-23 12:38:56 -04004422 ds->ops = &mv88e6xxx_switch_ops;
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004423
4424 dev_set_drvdata(dev, ds);
4425
4426 return dsa_register_switch(ds, np);
4427}
4428
Vivien Didelotfad09c72016-06-21 12:28:20 -04004429static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004430{
Vivien Didelotfad09c72016-06-21 12:28:20 -04004431 dsa_unregister_switch(chip->ds);
Vivien Didelotb7e66a52016-06-20 13:14:02 -04004432}
4433
Vivien Didelot57d32312016-06-20 13:13:58 -04004434static int mv88e6xxx_probe(struct mdio_device *mdiodev)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004435{
4436 struct device *dev = &mdiodev->dev;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004437 struct device_node *np = dev->of_node;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004438 const struct mv88e6xxx_info *compat_info;
Vivien Didelotfad09c72016-06-21 12:28:20 -04004439 struct mv88e6xxx_chip *chip;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004440 u32 eeprom_len;
Andrew Lunn52638f72016-05-10 23:27:22 +02004441 int err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004442
Vivien Didelotcaac8542016-06-20 13:14:09 -04004443 compat_info = of_device_get_match_data(dev);
4444 if (!compat_info)
4445 return -EINVAL;
4446
Vivien Didelotfad09c72016-06-21 12:28:20 -04004447 chip = mv88e6xxx_alloc_chip(dev);
4448 if (!chip)
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004449 return -ENOMEM;
4450
Vivien Didelotfad09c72016-06-21 12:28:20 -04004451 chip->info = compat_info;
Vivien Didelotcaac8542016-06-20 13:14:09 -04004452
Andrew Lunn56995cb2016-12-03 04:35:19 +01004453 err = mv88e6xxx_verify_madatory_ops(chip, chip->info->ops);
4454 if (err)
4455 return err;
4456
Vivien Didelotfad09c72016-06-21 12:28:20 -04004457 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
Vivien Didelot4a70c4a2016-06-20 13:14:07 -04004458 if (err)
4459 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004460
Andrew Lunnb4308f02016-11-21 23:26:55 +01004461 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
4462 if (IS_ERR(chip->reset))
4463 return PTR_ERR(chip->reset);
4464
Vivien Didelotfad09c72016-06-21 12:28:20 -04004465 err = mv88e6xxx_detect(chip);
Vivien Didelotbc46a3d2016-06-20 13:14:08 -04004466 if (err)
4467 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004468
Vivien Didelote57e5e72016-08-15 17:19:00 -04004469 mv88e6xxx_phy_init(chip);
4470
Vivien Didelotee4dc2e72016-09-29 12:22:02 -04004471 if (chip->info->ops->get_eeprom &&
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004472 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
Vivien Didelotfad09c72016-06-21 12:28:20 -04004473 chip->eeprom_len = eeprom_len;
Andrew Lunnf8cd8752016-05-10 23:27:25 +02004474
Andrew Lunndc30c352016-10-16 19:56:49 +02004475 mutex_lock(&chip->reg_lock);
4476 err = mv88e6xxx_switch_reset(chip);
4477 mutex_unlock(&chip->reg_lock);
Andrew Lunnb516d452016-06-04 21:17:06 +02004478 if (err)
Andrew Lunndc30c352016-10-16 19:56:49 +02004479 goto out;
Andrew Lunnb516d452016-06-04 21:17:06 +02004480
Andrew Lunndc30c352016-10-16 19:56:49 +02004481 chip->irq = of_irq_get(np, 0);
4482 if (chip->irq == -EPROBE_DEFER) {
4483 err = chip->irq;
4484 goto out;
Andrew Lunn83c0afa2016-06-04 21:17:07 +02004485 }
4486
Andrew Lunndc30c352016-10-16 19:56:49 +02004487 if (chip->irq > 0) {
4488 /* Has to be performed before the MDIO bus is created,
4489 * because the PHYs will link there interrupts to these
4490 * interrupt controllers
4491 */
4492 mutex_lock(&chip->reg_lock);
4493 err = mv88e6xxx_g1_irq_setup(chip);
4494 mutex_unlock(&chip->reg_lock);
4495
4496 if (err)
4497 goto out;
4498
4499 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
4500 err = mv88e6xxx_g2_irq_setup(chip);
4501 if (err)
4502 goto out_g1_irq;
4503 }
4504 }
4505
4506 err = mv88e6xxx_mdio_register(chip, np);
4507 if (err)
4508 goto out_g2_irq;
4509
4510 err = mv88e6xxx_register_switch(chip, np);
4511 if (err)
4512 goto out_mdio;
4513
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004514 return 0;
Andrew Lunndc30c352016-10-16 19:56:49 +02004515
4516out_mdio:
4517 mv88e6xxx_mdio_unregister(chip);
4518out_g2_irq:
Andrew Lunn467126442016-11-20 20:14:15 +01004519 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
Andrew Lunndc30c352016-10-16 19:56:49 +02004520 mv88e6xxx_g2_irq_free(chip);
4521out_g1_irq:
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004522 if (chip->irq > 0) {
4523 mutex_lock(&chip->reg_lock);
Andrew Lunn467126442016-11-20 20:14:15 +01004524 mv88e6xxx_g1_irq_free(chip);
Andrew Lunn61f7c3f2016-11-20 20:14:19 +01004525 mutex_unlock(&chip->reg_lock);
4526 }
Andrew Lunndc30c352016-10-16 19:56:49 +02004527out:
4528 return err;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004529}
4530
4531static void mv88e6xxx_remove(struct mdio_device *mdiodev)
4532{
4533 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
Vivien Didelot04bed142016-08-31 18:06:13 -04004534 struct mv88e6xxx_chip *chip = ds->priv;
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004535
Andrew Lunn930188c2016-08-22 16:01:03 +02004536 mv88e6xxx_phy_destroy(chip);
Vivien Didelotfad09c72016-06-21 12:28:20 -04004537 mv88e6xxx_unregister_switch(chip);
4538 mv88e6xxx_mdio_unregister(chip);
Andrew Lunndc30c352016-10-16 19:56:49 +02004539
Andrew Lunn467126442016-11-20 20:14:15 +01004540 if (chip->irq > 0) {
4541 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
4542 mv88e6xxx_g2_irq_free(chip);
4543 mv88e6xxx_g1_irq_free(chip);
4544 }
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004545}
4546
4547static const struct of_device_id mv88e6xxx_of_match[] = {
Vivien Didelotcaac8542016-06-20 13:14:09 -04004548 {
4549 .compatible = "marvell,mv88e6085",
4550 .data = &mv88e6xxx_table[MV88E6085],
4551 },
Andrew Lunn1a3b39e2016-11-21 23:26:57 +01004552 {
4553 .compatible = "marvell,mv88e6190",
4554 .data = &mv88e6xxx_table[MV88E6190],
4555 },
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004556 { /* sentinel */ },
4557};
4558
4559MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
4560
4561static struct mdio_driver mv88e6xxx_driver = {
4562 .probe = mv88e6xxx_probe,
4563 .remove = mv88e6xxx_remove,
4564 .mdiodrv.driver = {
4565 .name = "mv88e6085",
4566 .of_match_table = mv88e6xxx_of_match,
4567 },
4568};
4569
Ben Hutchings98e67302011-11-25 14:36:19 +00004570static int __init mv88e6xxx_init(void)
4571{
Florian Fainelliab3d4082017-01-08 14:52:07 -08004572 register_switch_driver(&mv88e6xxx_switch_drv);
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004573 return mdio_driver_register(&mv88e6xxx_driver);
Ben Hutchings98e67302011-11-25 14:36:19 +00004574}
4575module_init(mv88e6xxx_init);
4576
4577static void __exit mv88e6xxx_cleanup(void)
4578{
Andrew Lunn14c7b3c2016-05-10 23:27:21 +02004579 mdio_driver_unregister(&mv88e6xxx_driver);
Florian Fainelliab3d4082017-01-08 14:52:07 -08004580 unregister_switch_driver(&mv88e6xxx_switch_drv);
Ben Hutchings98e67302011-11-25 14:36:19 +00004581}
4582module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00004583
4584MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4585MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4586MODULE_LICENSE("GPL");