blob: 175353a659d4ff904e8972ae27af3f385c3d9401 [file] [log] [blame]
Lennert Buytenhek91da11f2008-10-07 13:44:02 +00001/*
2 * net/dsa/mv88e6xxx.c - Marvell 88e6xxx switch chip support
3 * Copyright (c) 2008 Marvell Semiconductor
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
10
Andrew Lunn87c8cef2015-06-20 18:42:28 +020011#include <linux/debugfs.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000012#include <linux/delay.h>
Guenter Roeckdefb05b2015-03-26 18:36:38 -070013#include <linux/etherdevice.h>
Guenter Roeckfacd95b2015-03-26 18:36:35 -070014#include <linux/if_bridge.h>
Barry Grussling19b2f972013-01-08 16:05:54 +000015#include <linux/jiffies.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000016#include <linux/list.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000017#include <linux/module.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000018#include <linux/netdevice.h>
19#include <linux/phy.h>
Andrew Lunn87c8cef2015-06-20 18:42:28 +020020#include <linux/seq_file.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000021#include <net/dsa.h>
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000022#include "mv88e6xxx.h"
23
Andrew Lunn16fe24f2015-05-06 01:09:55 +020024/* MDIO bus access can be nested in the case of PHYs connected to the
25 * internal MDIO bus of the switch, which is accessed via MDIO bus of
26 * the Ethernet interface. Avoid lockdep false positives by using
27 * mutex_lock_nested().
28 */
29static int mv88e6xxx_mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
30{
31 int ret;
32
33 mutex_lock_nested(&bus->mdio_lock, SINGLE_DEPTH_NESTING);
34 ret = bus->read(bus, addr, regnum);
35 mutex_unlock(&bus->mdio_lock);
36
37 return ret;
38}
39
40static int mv88e6xxx_mdiobus_write(struct mii_bus *bus, int addr, u32 regnum,
41 u16 val)
42{
43 int ret;
44
45 mutex_lock_nested(&bus->mdio_lock, SINGLE_DEPTH_NESTING);
46 ret = bus->write(bus, addr, regnum, val);
47 mutex_unlock(&bus->mdio_lock);
48
49 return ret;
50}
51
Barry Grussling3675c8d2013-01-08 16:05:53 +000052/* If the switch's ADDR[4:0] strap pins are strapped to zero, it will
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000053 * use all 32 SMI bus addresses on its SMI bus, and all switch registers
54 * will be directly accessible on some {device address,register address}
55 * pair. If the ADDR[4:0] pins are not strapped to zero, the switch
56 * will only respond to SMI transactions to that specific address, and
57 * an indirect addressing mechanism needs to be used to access its
58 * registers.
59 */
60static int mv88e6xxx_reg_wait_ready(struct mii_bus *bus, int sw_addr)
61{
62 int ret;
63 int i;
64
65 for (i = 0; i < 16; i++) {
Andrew Lunn16fe24f2015-05-06 01:09:55 +020066 ret = mv88e6xxx_mdiobus_read(bus, sw_addr, SMI_CMD);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000067 if (ret < 0)
68 return ret;
69
Andrew Lunncca8b132015-04-02 04:06:39 +020070 if ((ret & SMI_CMD_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000071 return 0;
72 }
73
74 return -ETIMEDOUT;
75}
76
77int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, int reg)
78{
79 int ret;
80
81 if (sw_addr == 0)
Andrew Lunn16fe24f2015-05-06 01:09:55 +020082 return mv88e6xxx_mdiobus_read(bus, addr, reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000083
Barry Grussling3675c8d2013-01-08 16:05:53 +000084 /* Wait for the bus to become free. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000085 ret = mv88e6xxx_reg_wait_ready(bus, sw_addr);
86 if (ret < 0)
87 return ret;
88
Barry Grussling3675c8d2013-01-08 16:05:53 +000089 /* Transmit the read command. */
Andrew Lunn16fe24f2015-05-06 01:09:55 +020090 ret = mv88e6xxx_mdiobus_write(bus, sw_addr, SMI_CMD,
91 SMI_CMD_OP_22_READ | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000092 if (ret < 0)
93 return ret;
94
Barry Grussling3675c8d2013-01-08 16:05:53 +000095 /* Wait for the read command to complete. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +000096 ret = mv88e6xxx_reg_wait_ready(bus, sw_addr);
97 if (ret < 0)
98 return ret;
99
Barry Grussling3675c8d2013-01-08 16:05:53 +0000100 /* Read the data. */
Andrew Lunn16fe24f2015-05-06 01:09:55 +0200101 ret = mv88e6xxx_mdiobus_read(bus, sw_addr, SMI_DATA);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000102 if (ret < 0)
103 return ret;
104
105 return ret & 0xffff;
106}
107
Guenter Roeck8d6d09e2015-03-26 18:36:31 -0700108/* Must be called with SMI mutex held */
109static int _mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000110{
Guenter Roeckb184e492014-10-17 12:30:58 -0700111 struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000112 int ret;
113
Guenter Roeckb184e492014-10-17 12:30:58 -0700114 if (bus == NULL)
115 return -EINVAL;
116
Guenter Roeckb184e492014-10-17 12:30:58 -0700117 ret = __mv88e6xxx_reg_read(bus, ds->pd->sw_addr, addr, reg);
Vivien Didelotbb92ea52015-01-23 16:10:36 -0500118 if (ret < 0)
119 return ret;
120
121 dev_dbg(ds->master_dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
122 addr, reg, ret);
123
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000124 return ret;
125}
126
Guenter Roeck8d6d09e2015-03-26 18:36:31 -0700127int mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg)
128{
129 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
130 int ret;
131
132 mutex_lock(&ps->smi_mutex);
133 ret = _mv88e6xxx_reg_read(ds, addr, reg);
134 mutex_unlock(&ps->smi_mutex);
135
136 return ret;
137}
138
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000139int __mv88e6xxx_reg_write(struct mii_bus *bus, int sw_addr, int addr,
140 int reg, u16 val)
141{
142 int ret;
143
144 if (sw_addr == 0)
Andrew Lunn16fe24f2015-05-06 01:09:55 +0200145 return mv88e6xxx_mdiobus_write(bus, addr, reg, val);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000146
Barry Grussling3675c8d2013-01-08 16:05:53 +0000147 /* Wait for the bus to become free. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000148 ret = mv88e6xxx_reg_wait_ready(bus, sw_addr);
149 if (ret < 0)
150 return ret;
151
Barry Grussling3675c8d2013-01-08 16:05:53 +0000152 /* Transmit the data to write. */
Andrew Lunn16fe24f2015-05-06 01:09:55 +0200153 ret = mv88e6xxx_mdiobus_write(bus, sw_addr, SMI_DATA, val);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000154 if (ret < 0)
155 return ret;
156
Barry Grussling3675c8d2013-01-08 16:05:53 +0000157 /* Transmit the write command. */
Andrew Lunn16fe24f2015-05-06 01:09:55 +0200158 ret = mv88e6xxx_mdiobus_write(bus, sw_addr, SMI_CMD,
159 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000160 if (ret < 0)
161 return ret;
162
Barry Grussling3675c8d2013-01-08 16:05:53 +0000163 /* Wait for the write command to complete. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000164 ret = mv88e6xxx_reg_wait_ready(bus, sw_addr);
165 if (ret < 0)
166 return ret;
167
168 return 0;
169}
170
Guenter Roeck8d6d09e2015-03-26 18:36:31 -0700171/* Must be called with SMI mutex held */
172static int _mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg,
173 u16 val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000174{
Guenter Roeckb184e492014-10-17 12:30:58 -0700175 struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000176
Guenter Roeckb184e492014-10-17 12:30:58 -0700177 if (bus == NULL)
178 return -EINVAL;
179
Vivien Didelotbb92ea52015-01-23 16:10:36 -0500180 dev_dbg(ds->master_dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
181 addr, reg, val);
182
Guenter Roeck8d6d09e2015-03-26 18:36:31 -0700183 return __mv88e6xxx_reg_write(bus, ds->pd->sw_addr, addr, reg, val);
184}
185
186int mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg, u16 val)
187{
188 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
189 int ret;
190
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000191 mutex_lock(&ps->smi_mutex);
Guenter Roeck8d6d09e2015-03-26 18:36:31 -0700192 ret = _mv88e6xxx_reg_write(ds, addr, reg, val);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000193 mutex_unlock(&ps->smi_mutex);
194
195 return ret;
196}
197
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000198int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr)
199{
Andrew Lunncca8b132015-04-02 04:06:39 +0200200 REG_WRITE(REG_GLOBAL, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
201 REG_WRITE(REG_GLOBAL, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
202 REG_WRITE(REG_GLOBAL, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000203
204 return 0;
205}
206
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000207int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr)
208{
209 int i;
210 int ret;
211
212 for (i = 0; i < 6; i++) {
213 int j;
214
Barry Grussling3675c8d2013-01-08 16:05:53 +0000215 /* Write the MAC address byte. */
Andrew Lunncca8b132015-04-02 04:06:39 +0200216 REG_WRITE(REG_GLOBAL2, GLOBAL2_SWITCH_MAC,
217 GLOBAL2_SWITCH_MAC_BUSY | (i << 8) | addr[i]);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000218
Barry Grussling3675c8d2013-01-08 16:05:53 +0000219 /* Wait for the write to complete. */
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000220 for (j = 0; j < 16; j++) {
Andrew Lunncca8b132015-04-02 04:06:39 +0200221 ret = REG_READ(REG_GLOBAL2, GLOBAL2_SWITCH_MAC);
222 if ((ret & GLOBAL2_SWITCH_MAC_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000223 break;
224 }
225 if (j == 16)
226 return -ETIMEDOUT;
227 }
228
229 return 0;
230}
231
Andrew Lunn3898c142015-05-06 01:09:53 +0200232/* Must be called with SMI mutex held */
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +0200233static int _mv88e6xxx_phy_read(struct dsa_switch *ds, int addr, int regnum)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000234{
235 if (addr >= 0)
Andrew Lunn3898c142015-05-06 01:09:53 +0200236 return _mv88e6xxx_reg_read(ds, addr, regnum);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000237 return 0xffff;
238}
239
Andrew Lunn3898c142015-05-06 01:09:53 +0200240/* Must be called with SMI mutex held */
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +0200241static int _mv88e6xxx_phy_write(struct dsa_switch *ds, int addr, int regnum,
242 u16 val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000243{
244 if (addr >= 0)
Andrew Lunn3898c142015-05-06 01:09:53 +0200245 return _mv88e6xxx_reg_write(ds, addr, regnum, val);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000246 return 0;
247}
248
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000249#ifdef CONFIG_NET_DSA_MV88E6XXX_NEED_PPU
250static int mv88e6xxx_ppu_disable(struct dsa_switch *ds)
251{
252 int ret;
Barry Grussling19b2f972013-01-08 16:05:54 +0000253 unsigned long timeout;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000254
Andrew Lunncca8b132015-04-02 04:06:39 +0200255 ret = REG_READ(REG_GLOBAL, GLOBAL_CONTROL);
256 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL,
257 ret & ~GLOBAL_CONTROL_PPU_ENABLE);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000258
Barry Grussling19b2f972013-01-08 16:05:54 +0000259 timeout = jiffies + 1 * HZ;
260 while (time_before(jiffies, timeout)) {
Andrew Lunncca8b132015-04-02 04:06:39 +0200261 ret = REG_READ(REG_GLOBAL, GLOBAL_STATUS);
Barry Grussling19b2f972013-01-08 16:05:54 +0000262 usleep_range(1000, 2000);
Andrew Lunncca8b132015-04-02 04:06:39 +0200263 if ((ret & GLOBAL_STATUS_PPU_MASK) !=
264 GLOBAL_STATUS_PPU_POLLING)
Barry Grussling85686582013-01-08 16:05:56 +0000265 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000266 }
267
268 return -ETIMEDOUT;
269}
270
271static int mv88e6xxx_ppu_enable(struct dsa_switch *ds)
272{
273 int ret;
Barry Grussling19b2f972013-01-08 16:05:54 +0000274 unsigned long timeout;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000275
Andrew Lunncca8b132015-04-02 04:06:39 +0200276 ret = REG_READ(REG_GLOBAL, GLOBAL_CONTROL);
277 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL, ret | GLOBAL_CONTROL_PPU_ENABLE);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000278
Barry Grussling19b2f972013-01-08 16:05:54 +0000279 timeout = jiffies + 1 * HZ;
280 while (time_before(jiffies, timeout)) {
Andrew Lunncca8b132015-04-02 04:06:39 +0200281 ret = REG_READ(REG_GLOBAL, GLOBAL_STATUS);
Barry Grussling19b2f972013-01-08 16:05:54 +0000282 usleep_range(1000, 2000);
Andrew Lunncca8b132015-04-02 04:06:39 +0200283 if ((ret & GLOBAL_STATUS_PPU_MASK) ==
284 GLOBAL_STATUS_PPU_POLLING)
Barry Grussling85686582013-01-08 16:05:56 +0000285 return 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000286 }
287
288 return -ETIMEDOUT;
289}
290
291static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
292{
293 struct mv88e6xxx_priv_state *ps;
294
295 ps = container_of(ugly, struct mv88e6xxx_priv_state, ppu_work);
296 if (mutex_trylock(&ps->ppu_mutex)) {
Barry Grussling85686582013-01-08 16:05:56 +0000297 struct dsa_switch *ds = ((struct dsa_switch *)ps) - 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000298
Barry Grussling85686582013-01-08 16:05:56 +0000299 if (mv88e6xxx_ppu_enable(ds) == 0)
300 ps->ppu_disabled = 0;
301 mutex_unlock(&ps->ppu_mutex);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000302 }
303}
304
305static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
306{
307 struct mv88e6xxx_priv_state *ps = (void *)_ps;
308
309 schedule_work(&ps->ppu_work);
310}
311
312static int mv88e6xxx_ppu_access_get(struct dsa_switch *ds)
313{
Florian Fainellia22adce2014-04-28 11:14:28 -0700314 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000315 int ret;
316
317 mutex_lock(&ps->ppu_mutex);
318
Barry Grussling3675c8d2013-01-08 16:05:53 +0000319 /* If the PHY polling unit is enabled, disable it so that
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000320 * we can access the PHY registers. If it was already
321 * disabled, cancel the timer that is going to re-enable
322 * it.
323 */
324 if (!ps->ppu_disabled) {
Barry Grussling85686582013-01-08 16:05:56 +0000325 ret = mv88e6xxx_ppu_disable(ds);
326 if (ret < 0) {
327 mutex_unlock(&ps->ppu_mutex);
328 return ret;
329 }
330 ps->ppu_disabled = 1;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000331 } else {
Barry Grussling85686582013-01-08 16:05:56 +0000332 del_timer(&ps->ppu_timer);
333 ret = 0;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000334 }
335
336 return ret;
337}
338
339static void mv88e6xxx_ppu_access_put(struct dsa_switch *ds)
340{
Florian Fainellia22adce2014-04-28 11:14:28 -0700341 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000342
Barry Grussling3675c8d2013-01-08 16:05:53 +0000343 /* Schedule a timer to re-enable the PHY polling unit. */
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000344 mod_timer(&ps->ppu_timer, jiffies + msecs_to_jiffies(10));
345 mutex_unlock(&ps->ppu_mutex);
346}
347
348void mv88e6xxx_ppu_state_init(struct dsa_switch *ds)
349{
Florian Fainellia22adce2014-04-28 11:14:28 -0700350 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000351
352 mutex_init(&ps->ppu_mutex);
353 INIT_WORK(&ps->ppu_work, mv88e6xxx_ppu_reenable_work);
354 init_timer(&ps->ppu_timer);
355 ps->ppu_timer.data = (unsigned long)ps;
356 ps->ppu_timer.function = mv88e6xxx_ppu_reenable_timer;
357}
358
359int mv88e6xxx_phy_read_ppu(struct dsa_switch *ds, int addr, int regnum)
360{
361 int ret;
362
363 ret = mv88e6xxx_ppu_access_get(ds);
364 if (ret >= 0) {
Barry Grussling85686582013-01-08 16:05:56 +0000365 ret = mv88e6xxx_reg_read(ds, addr, regnum);
366 mv88e6xxx_ppu_access_put(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000367 }
368
369 return ret;
370}
371
372int mv88e6xxx_phy_write_ppu(struct dsa_switch *ds, int addr,
373 int regnum, u16 val)
374{
375 int ret;
376
377 ret = mv88e6xxx_ppu_access_get(ds);
378 if (ret >= 0) {
Barry Grussling85686582013-01-08 16:05:56 +0000379 ret = mv88e6xxx_reg_write(ds, addr, regnum, val);
380 mv88e6xxx_ppu_access_put(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000381 }
382
383 return ret;
384}
385#endif
386
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000387void mv88e6xxx_poll_link(struct dsa_switch *ds)
388{
389 int i;
390
391 for (i = 0; i < DSA_MAX_PORTS; i++) {
392 struct net_device *dev;
Ingo Molnar2a9e7972008-11-25 16:50:49 -0800393 int uninitialized_var(port_status);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000394 int link;
395 int speed;
396 int duplex;
397 int fc;
398
399 dev = ds->ports[i];
400 if (dev == NULL)
401 continue;
402
403 link = 0;
404 if (dev->flags & IFF_UP) {
Andrew Lunncca8b132015-04-02 04:06:39 +0200405 port_status = mv88e6xxx_reg_read(ds, REG_PORT(i),
406 PORT_STATUS);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000407 if (port_status < 0)
408 continue;
409
Andrew Lunncca8b132015-04-02 04:06:39 +0200410 link = !!(port_status & PORT_STATUS_LINK);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000411 }
412
413 if (!link) {
414 if (netif_carrier_ok(dev)) {
Barry Grusslingab381a92013-01-08 16:05:55 +0000415 netdev_info(dev, "link down\n");
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000416 netif_carrier_off(dev);
417 }
418 continue;
419 }
420
Andrew Lunncca8b132015-04-02 04:06:39 +0200421 switch (port_status & PORT_STATUS_SPEED_MASK) {
422 case PORT_STATUS_SPEED_10:
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000423 speed = 10;
424 break;
Andrew Lunncca8b132015-04-02 04:06:39 +0200425 case PORT_STATUS_SPEED_100:
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000426 speed = 100;
427 break;
Andrew Lunncca8b132015-04-02 04:06:39 +0200428 case PORT_STATUS_SPEED_1000:
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000429 speed = 1000;
430 break;
431 default:
432 speed = -1;
433 break;
434 }
Andrew Lunncca8b132015-04-02 04:06:39 +0200435 duplex = (port_status & PORT_STATUS_DUPLEX) ? 1 : 0;
436 fc = (port_status & PORT_STATUS_PAUSE_EN) ? 1 : 0;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000437
438 if (!netif_carrier_ok(dev)) {
Barry Grusslingab381a92013-01-08 16:05:55 +0000439 netdev_info(dev,
440 "link up, %d Mb/s, %s duplex, flow control %sabled\n",
441 speed,
442 duplex ? "full" : "half",
443 fc ? "en" : "dis");
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000444 netif_carrier_on(dev);
445 }
446 }
447}
448
Andrew Lunn54d792f2015-05-06 01:09:47 +0200449static bool mv88e6xxx_6065_family(struct dsa_switch *ds)
450{
451 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
452
453 switch (ps->id) {
454 case PORT_SWITCH_ID_6031:
455 case PORT_SWITCH_ID_6061:
456 case PORT_SWITCH_ID_6035:
457 case PORT_SWITCH_ID_6065:
458 return true;
459 }
460 return false;
461}
462
463static bool mv88e6xxx_6095_family(struct dsa_switch *ds)
464{
465 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
466
467 switch (ps->id) {
468 case PORT_SWITCH_ID_6092:
469 case PORT_SWITCH_ID_6095:
470 return true;
471 }
472 return false;
473}
474
475static bool mv88e6xxx_6097_family(struct dsa_switch *ds)
476{
477 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
478
479 switch (ps->id) {
480 case PORT_SWITCH_ID_6046:
481 case PORT_SWITCH_ID_6085:
482 case PORT_SWITCH_ID_6096:
483 case PORT_SWITCH_ID_6097:
484 return true;
485 }
486 return false;
487}
488
489static bool mv88e6xxx_6165_family(struct dsa_switch *ds)
490{
491 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
492
493 switch (ps->id) {
494 case PORT_SWITCH_ID_6123:
495 case PORT_SWITCH_ID_6161:
496 case PORT_SWITCH_ID_6165:
497 return true;
498 }
499 return false;
500}
501
502static bool mv88e6xxx_6185_family(struct dsa_switch *ds)
503{
504 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
505
506 switch (ps->id) {
507 case PORT_SWITCH_ID_6121:
508 case PORT_SWITCH_ID_6122:
509 case PORT_SWITCH_ID_6152:
510 case PORT_SWITCH_ID_6155:
511 case PORT_SWITCH_ID_6182:
512 case PORT_SWITCH_ID_6185:
513 case PORT_SWITCH_ID_6108:
514 case PORT_SWITCH_ID_6131:
515 return true;
516 }
517 return false;
518}
519
Guenter Roeckc22995c2015-07-25 09:42:28 -0700520static bool mv88e6xxx_6320_family(struct dsa_switch *ds)
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700521{
522 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
523
524 switch (ps->id) {
525 case PORT_SWITCH_ID_6320:
526 case PORT_SWITCH_ID_6321:
527 return true;
528 }
529 return false;
530}
531
Andrew Lunn54d792f2015-05-06 01:09:47 +0200532static bool mv88e6xxx_6351_family(struct dsa_switch *ds)
533{
534 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
535
536 switch (ps->id) {
537 case PORT_SWITCH_ID_6171:
538 case PORT_SWITCH_ID_6175:
539 case PORT_SWITCH_ID_6350:
540 case PORT_SWITCH_ID_6351:
541 return true;
542 }
543 return false;
544}
545
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200546static bool mv88e6xxx_6352_family(struct dsa_switch *ds)
547{
548 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
549
550 switch (ps->id) {
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200551 case PORT_SWITCH_ID_6172:
552 case PORT_SWITCH_ID_6176:
Andrew Lunn54d792f2015-05-06 01:09:47 +0200553 case PORT_SWITCH_ID_6240:
554 case PORT_SWITCH_ID_6352:
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200555 return true;
556 }
557 return false;
558}
559
Andrew Lunn31888232015-05-06 01:09:54 +0200560/* Must be called with SMI mutex held */
561static int _mv88e6xxx_stats_wait(struct dsa_switch *ds)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000562{
563 int ret;
564 int i;
565
566 for (i = 0; i < 10; i++) {
Andrew Lunn31888232015-05-06 01:09:54 +0200567 ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_STATS_OP);
Andrew Lunncca8b132015-04-02 04:06:39 +0200568 if ((ret & GLOBAL_STATS_OP_BUSY) == 0)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000569 return 0;
570 }
571
572 return -ETIMEDOUT;
573}
574
Andrew Lunn31888232015-05-06 01:09:54 +0200575/* Must be called with SMI mutex held */
576static int _mv88e6xxx_stats_snapshot(struct dsa_switch *ds, int port)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000577{
578 int ret;
579
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -0700580 if (mv88e6xxx_6320_family(ds) || mv88e6xxx_6352_family(ds))
Andrew Lunnf3a8b6b2015-04-02 04:06:40 +0200581 port = (port + 1) << 5;
582
Barry Grussling3675c8d2013-01-08 16:05:53 +0000583 /* Snapshot the hardware statistics counters for this port. */
Andrew Lunn31888232015-05-06 01:09:54 +0200584 ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_STATS_OP,
585 GLOBAL_STATS_OP_CAPTURE_PORT |
586 GLOBAL_STATS_OP_HIST_RX_TX | port);
587 if (ret < 0)
588 return ret;
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000589
Barry Grussling3675c8d2013-01-08 16:05:53 +0000590 /* Wait for the snapshotting to complete. */
Andrew Lunn31888232015-05-06 01:09:54 +0200591 ret = _mv88e6xxx_stats_wait(ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000592 if (ret < 0)
593 return ret;
594
595 return 0;
596}
597
Andrew Lunn31888232015-05-06 01:09:54 +0200598/* Must be called with SMI mutex held */
599static void _mv88e6xxx_stats_read(struct dsa_switch *ds, int stat, u32 *val)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000600{
601 u32 _val;
602 int ret;
603
604 *val = 0;
605
Andrew Lunn31888232015-05-06 01:09:54 +0200606 ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_STATS_OP,
607 GLOBAL_STATS_OP_READ_CAPTURED |
608 GLOBAL_STATS_OP_HIST_RX_TX | stat);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000609 if (ret < 0)
610 return;
611
Andrew Lunn31888232015-05-06 01:09:54 +0200612 ret = _mv88e6xxx_stats_wait(ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000613 if (ret < 0)
614 return;
615
Andrew Lunn31888232015-05-06 01:09:54 +0200616 ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_STATS_COUNTER_32);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000617 if (ret < 0)
618 return;
619
620 _val = ret << 16;
621
Andrew Lunn31888232015-05-06 01:09:54 +0200622 ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_STATS_COUNTER_01);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000623 if (ret < 0)
624 return;
625
626 *val = _val | ret;
627}
628
Andrew Lunne413e7e2015-04-02 04:06:38 +0200629static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
630 { "in_good_octets", 8, 0x00, },
631 { "in_bad_octets", 4, 0x02, },
632 { "in_unicast", 4, 0x04, },
633 { "in_broadcasts", 4, 0x06, },
634 { "in_multicasts", 4, 0x07, },
635 { "in_pause", 4, 0x16, },
636 { "in_undersize", 4, 0x18, },
637 { "in_fragments", 4, 0x19, },
638 { "in_oversize", 4, 0x1a, },
639 { "in_jabber", 4, 0x1b, },
640 { "in_rx_error", 4, 0x1c, },
641 { "in_fcs_error", 4, 0x1d, },
642 { "out_octets", 8, 0x0e, },
643 { "out_unicast", 4, 0x10, },
644 { "out_broadcasts", 4, 0x13, },
645 { "out_multicasts", 4, 0x12, },
646 { "out_pause", 4, 0x15, },
647 { "excessive", 4, 0x11, },
648 { "collisions", 4, 0x1e, },
649 { "deferred", 4, 0x05, },
650 { "single", 4, 0x14, },
651 { "multiple", 4, 0x17, },
652 { "out_fcs_error", 4, 0x03, },
653 { "late", 4, 0x1f, },
654 { "hist_64bytes", 4, 0x08, },
655 { "hist_65_127bytes", 4, 0x09, },
656 { "hist_128_255bytes", 4, 0x0a, },
657 { "hist_256_511bytes", 4, 0x0b, },
658 { "hist_512_1023bytes", 4, 0x0c, },
659 { "hist_1024_max_bytes", 4, 0x0d, },
660 /* Not all devices have the following counters */
661 { "sw_in_discards", 4, 0x110, },
662 { "sw_in_filtered", 2, 0x112, },
663 { "sw_out_filtered", 2, 0x113, },
664
665};
666
667static bool have_sw_in_discards(struct dsa_switch *ds)
668{
669 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
670
671 switch (ps->id) {
Andrew Lunncca8b132015-04-02 04:06:39 +0200672 case PORT_SWITCH_ID_6095: case PORT_SWITCH_ID_6161:
673 case PORT_SWITCH_ID_6165: case PORT_SWITCH_ID_6171:
674 case PORT_SWITCH_ID_6172: case PORT_SWITCH_ID_6176:
675 case PORT_SWITCH_ID_6182: case PORT_SWITCH_ID_6185:
676 case PORT_SWITCH_ID_6352:
Andrew Lunne413e7e2015-04-02 04:06:38 +0200677 return true;
678 default:
679 return false;
680 }
681}
682
683static void _mv88e6xxx_get_strings(struct dsa_switch *ds,
684 int nr_stats,
685 struct mv88e6xxx_hw_stat *stats,
686 int port, uint8_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000687{
688 int i;
689
690 for (i = 0; i < nr_stats; i++) {
691 memcpy(data + i * ETH_GSTRING_LEN,
692 stats[i].string, ETH_GSTRING_LEN);
693 }
694}
695
Andrew Lunn80c46272015-06-20 18:42:30 +0200696static uint64_t _mv88e6xxx_get_ethtool_stat(struct dsa_switch *ds,
697 int stat,
698 struct mv88e6xxx_hw_stat *stats,
699 int port)
700{
701 struct mv88e6xxx_hw_stat *s = stats + stat;
702 u32 low;
703 u32 high = 0;
704 int ret;
705 u64 value;
706
707 if (s->reg >= 0x100) {
708 ret = _mv88e6xxx_reg_read(ds, REG_PORT(port),
709 s->reg - 0x100);
710 if (ret < 0)
711 return UINT64_MAX;
712
713 low = ret;
714 if (s->sizeof_stat == 4) {
715 ret = _mv88e6xxx_reg_read(ds, REG_PORT(port),
716 s->reg - 0x100 + 1);
717 if (ret < 0)
718 return UINT64_MAX;
719 high = ret;
720 }
721 } else {
722 _mv88e6xxx_stats_read(ds, s->reg, &low);
723 if (s->sizeof_stat == 8)
724 _mv88e6xxx_stats_read(ds, s->reg + 1, &high);
725 }
726 value = (((u64)high) << 16) | low;
727 return value;
728}
729
Andrew Lunne413e7e2015-04-02 04:06:38 +0200730static void _mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds,
731 int nr_stats,
732 struct mv88e6xxx_hw_stat *stats,
733 int port, uint64_t *data)
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000734{
Florian Fainellia22adce2014-04-28 11:14:28 -0700735 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000736 int ret;
737 int i;
738
Andrew Lunn31888232015-05-06 01:09:54 +0200739 mutex_lock(&ps->smi_mutex);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000740
Andrew Lunn31888232015-05-06 01:09:54 +0200741 ret = _mv88e6xxx_stats_snapshot(ds, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000742 if (ret < 0) {
Andrew Lunn31888232015-05-06 01:09:54 +0200743 mutex_unlock(&ps->smi_mutex);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000744 return;
745 }
746
Barry Grussling3675c8d2013-01-08 16:05:53 +0000747 /* Read each of the counters. */
Andrew Lunn80c46272015-06-20 18:42:30 +0200748 for (i = 0; i < nr_stats; i++)
749 data[i] = _mv88e6xxx_get_ethtool_stat(ds, i, stats, port);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000750
Andrew Lunn31888232015-05-06 01:09:54 +0200751 mutex_unlock(&ps->smi_mutex);
Lennert Buytenhek91da11f2008-10-07 13:44:02 +0000752}
Ben Hutchings98e67302011-11-25 14:36:19 +0000753
Andrew Lunne413e7e2015-04-02 04:06:38 +0200754/* All the statistics in the table */
755void
756mv88e6xxx_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
757{
758 if (have_sw_in_discards(ds))
759 _mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6xxx_hw_stats),
760 mv88e6xxx_hw_stats, port, data);
761 else
762 _mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6xxx_hw_stats) - 3,
763 mv88e6xxx_hw_stats, port, data);
764}
765
766int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
767{
768 if (have_sw_in_discards(ds))
769 return ARRAY_SIZE(mv88e6xxx_hw_stats);
770 return ARRAY_SIZE(mv88e6xxx_hw_stats) - 3;
771}
772
773void
774mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds,
775 int port, uint64_t *data)
776{
777 if (have_sw_in_discards(ds))
778 _mv88e6xxx_get_ethtool_stats(
779 ds, ARRAY_SIZE(mv88e6xxx_hw_stats),
780 mv88e6xxx_hw_stats, port, data);
781 else
782 _mv88e6xxx_get_ethtool_stats(
783 ds, ARRAY_SIZE(mv88e6xxx_hw_stats) - 3,
784 mv88e6xxx_hw_stats, port, data);
785}
786
Guenter Roecka1ab91f2014-10-29 10:45:05 -0700787int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
788{
789 return 32 * sizeof(u16);
790}
791
792void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
793 struct ethtool_regs *regs, void *_p)
794{
795 u16 *p = _p;
796 int i;
797
798 regs->version = 0;
799
800 memset(p, 0xff, 32 * sizeof(u16));
801
802 for (i = 0; i < 32; i++) {
803 int ret;
804
805 ret = mv88e6xxx_reg_read(ds, REG_PORT(port), i);
806 if (ret >= 0)
807 p[i] = ret;
808 }
809}
810
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700811/* Must be called with SMI lock held */
Andrew Lunn3898c142015-05-06 01:09:53 +0200812static int _mv88e6xxx_wait(struct dsa_switch *ds, int reg, int offset,
813 u16 mask)
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700814{
815 unsigned long timeout = jiffies + HZ / 10;
816
817 while (time_before(jiffies, timeout)) {
818 int ret;
819
820 ret = _mv88e6xxx_reg_read(ds, reg, offset);
821 if (ret < 0)
822 return ret;
823 if (!(ret & mask))
824 return 0;
825
826 usleep_range(1000, 2000);
827 }
828 return -ETIMEDOUT;
829}
830
Andrew Lunn3898c142015-05-06 01:09:53 +0200831static int mv88e6xxx_wait(struct dsa_switch *ds, int reg, int offset, u16 mask)
832{
833 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
834 int ret;
835
836 mutex_lock(&ps->smi_mutex);
837 ret = _mv88e6xxx_wait(ds, reg, offset, mask);
838 mutex_unlock(&ps->smi_mutex);
839
840 return ret;
841}
842
843static int _mv88e6xxx_phy_wait(struct dsa_switch *ds)
844{
845 return _mv88e6xxx_wait(ds, REG_GLOBAL2, GLOBAL2_SMI_OP,
846 GLOBAL2_SMI_OP_BUSY);
847}
848
849int mv88e6xxx_eeprom_load_wait(struct dsa_switch *ds)
850{
851 return mv88e6xxx_wait(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
852 GLOBAL2_EEPROM_OP_LOAD);
853}
854
855int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds)
856{
857 return mv88e6xxx_wait(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
858 GLOBAL2_EEPROM_OP_BUSY);
859}
860
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700861/* Must be called with SMI lock held */
862static int _mv88e6xxx_atu_wait(struct dsa_switch *ds)
863{
Andrew Lunncca8b132015-04-02 04:06:39 +0200864 return _mv88e6xxx_wait(ds, REG_GLOBAL, GLOBAL_ATU_OP,
865 GLOBAL_ATU_OP_BUSY);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700866}
867
Andrew Lunn56d95e22015-06-20 18:42:33 +0200868/* Must be called with SMI lock held */
869static int _mv88e6xxx_scratch_wait(struct dsa_switch *ds)
870{
871 return _mv88e6xxx_wait(ds, REG_GLOBAL2, GLOBAL2_SCRATCH_MISC,
872 GLOBAL2_SCRATCH_BUSY);
873}
874
Andrew Lunn3898c142015-05-06 01:09:53 +0200875/* Must be called with SMI mutex held */
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +0200876static int _mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr,
877 int regnum)
Andrew Lunnf3044682015-02-14 19:17:50 +0100878{
879 int ret;
880
Andrew Lunn3898c142015-05-06 01:09:53 +0200881 ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_SMI_OP,
882 GLOBAL2_SMI_OP_22_READ | (addr << 5) |
883 regnum);
Andrew Lunnf3044682015-02-14 19:17:50 +0100884 if (ret < 0)
885 return ret;
886
Andrew Lunn3898c142015-05-06 01:09:53 +0200887 ret = _mv88e6xxx_phy_wait(ds);
888 if (ret < 0)
889 return ret;
890
891 return _mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_SMI_DATA);
Andrew Lunnf3044682015-02-14 19:17:50 +0100892}
893
Andrew Lunn3898c142015-05-06 01:09:53 +0200894/* Must be called with SMI mutex held */
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +0200895static int _mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr,
896 int regnum, u16 val)
Andrew Lunnf3044682015-02-14 19:17:50 +0100897{
Andrew Lunn3898c142015-05-06 01:09:53 +0200898 int ret;
Andrew Lunnf3044682015-02-14 19:17:50 +0100899
Andrew Lunn3898c142015-05-06 01:09:53 +0200900 ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_SMI_DATA, val);
901 if (ret < 0)
902 return ret;
903
904 ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_SMI_OP,
905 GLOBAL2_SMI_OP_22_WRITE | (addr << 5) |
906 regnum);
907
908 return _mv88e6xxx_phy_wait(ds);
Andrew Lunnf3044682015-02-14 19:17:50 +0100909}
910
Guenter Roeck11b3b452015-03-06 22:23:51 -0800911int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
912{
Andrew Lunn2f40c692015-04-02 04:06:37 +0200913 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Guenter Roeck11b3b452015-03-06 22:23:51 -0800914 int reg;
915
Andrew Lunn3898c142015-05-06 01:09:53 +0200916 mutex_lock(&ps->smi_mutex);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200917
918 reg = _mv88e6xxx_phy_read_indirect(ds, port, 16);
Guenter Roeck11b3b452015-03-06 22:23:51 -0800919 if (reg < 0)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200920 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800921
922 e->eee_enabled = !!(reg & 0x0200);
923 e->tx_lpi_enabled = !!(reg & 0x0100);
924
Andrew Lunn3898c142015-05-06 01:09:53 +0200925 reg = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_STATUS);
Guenter Roeck11b3b452015-03-06 22:23:51 -0800926 if (reg < 0)
Andrew Lunn2f40c692015-04-02 04:06:37 +0200927 goto out;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800928
Andrew Lunncca8b132015-04-02 04:06:39 +0200929 e->eee_active = !!(reg & PORT_STATUS_EEE);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200930 reg = 0;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800931
Andrew Lunn2f40c692015-04-02 04:06:37 +0200932out:
Andrew Lunn3898c142015-05-06 01:09:53 +0200933 mutex_unlock(&ps->smi_mutex);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200934 return reg;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800935}
936
937int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
938 struct phy_device *phydev, struct ethtool_eee *e)
939{
Andrew Lunn2f40c692015-04-02 04:06:37 +0200940 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
941 int reg;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800942 int ret;
943
Andrew Lunn3898c142015-05-06 01:09:53 +0200944 mutex_lock(&ps->smi_mutex);
Guenter Roeck11b3b452015-03-06 22:23:51 -0800945
Andrew Lunn2f40c692015-04-02 04:06:37 +0200946 ret = _mv88e6xxx_phy_read_indirect(ds, port, 16);
947 if (ret < 0)
948 goto out;
949
950 reg = ret & ~0x0300;
951 if (e->eee_enabled)
952 reg |= 0x0200;
953 if (e->tx_lpi_enabled)
954 reg |= 0x0100;
955
956 ret = _mv88e6xxx_phy_write_indirect(ds, port, 16, reg);
957out:
Andrew Lunn3898c142015-05-06 01:09:53 +0200958 mutex_unlock(&ps->smi_mutex);
Andrew Lunn2f40c692015-04-02 04:06:37 +0200959
960 return ret;
Guenter Roeck11b3b452015-03-06 22:23:51 -0800961}
962
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700963static int _mv88e6xxx_atu_cmd(struct dsa_switch *ds, int fid, u16 cmd)
964{
965 int ret;
966
Vivien Didelota08df0f2015-08-10 09:09:46 -0400967 ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_FID, fid);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700968 if (ret < 0)
969 return ret;
970
Andrew Lunncca8b132015-04-02 04:06:39 +0200971 ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_OP, cmd);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700972 if (ret < 0)
973 return ret;
974
975 return _mv88e6xxx_atu_wait(ds);
976}
977
978static int _mv88e6xxx_flush_fid(struct dsa_switch *ds, int fid)
979{
980 int ret;
981
982 ret = _mv88e6xxx_atu_wait(ds);
983 if (ret < 0)
984 return ret;
985
Andrew Lunncca8b132015-04-02 04:06:39 +0200986 return _mv88e6xxx_atu_cmd(ds, fid, GLOBAL_ATU_OP_FLUSH_NON_STATIC_DB);
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700987}
988
989static int mv88e6xxx_set_port_state(struct dsa_switch *ds, int port, u8 state)
990{
991 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Geert Uytterhoevenc3ffe6d2015-04-16 20:49:14 +0200992 int reg, ret = 0;
Guenter Roeckfacd95b2015-03-26 18:36:35 -0700993 u8 oldstate;
994
995 mutex_lock(&ps->smi_mutex);
996
Andrew Lunncca8b132015-04-02 04:06:39 +0200997 reg = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_CONTROL);
Guenter Roeck538cc282015-04-15 22:12:42 -0700998 if (reg < 0) {
999 ret = reg;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001000 goto abort;
Guenter Roeck538cc282015-04-15 22:12:42 -07001001 }
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001002
Andrew Lunncca8b132015-04-02 04:06:39 +02001003 oldstate = reg & PORT_CONTROL_STATE_MASK;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001004 if (oldstate != state) {
1005 /* Flush forwarding database if we're moving a port
1006 * from Learning or Forwarding state to Disabled or
1007 * Blocking or Listening state.
1008 */
Andrew Lunncca8b132015-04-02 04:06:39 +02001009 if (oldstate >= PORT_CONTROL_STATE_LEARNING &&
1010 state <= PORT_CONTROL_STATE_BLOCKING) {
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001011 ret = _mv88e6xxx_flush_fid(ds, ps->fid[port]);
1012 if (ret)
1013 goto abort;
1014 }
Andrew Lunncca8b132015-04-02 04:06:39 +02001015 reg = (reg & ~PORT_CONTROL_STATE_MASK) | state;
1016 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_CONTROL,
1017 reg);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001018 }
1019
1020abort:
1021 mutex_unlock(&ps->smi_mutex);
1022 return ret;
1023}
1024
1025/* Must be called with smi lock held */
1026static int _mv88e6xxx_update_port_config(struct dsa_switch *ds, int port)
1027{
1028 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1029 u8 fid = ps->fid[port];
1030 u16 reg = fid << 12;
1031
1032 if (dsa_is_cpu_port(ds, port))
1033 reg |= ds->phys_port_mask;
1034 else
1035 reg |= (ps->bridge_mask[fid] |
1036 (1 << dsa_upstream_port(ds))) & ~(1 << port);
1037
Andrew Lunncca8b132015-04-02 04:06:39 +02001038 return _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_BASE_VLAN, reg);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001039}
1040
1041/* Must be called with smi lock held */
1042static int _mv88e6xxx_update_bridge_config(struct dsa_switch *ds, int fid)
1043{
1044 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1045 int port;
1046 u32 mask;
1047 int ret;
1048
1049 mask = ds->phys_port_mask;
1050 while (mask) {
1051 port = __ffs(mask);
1052 mask &= ~(1 << port);
1053 if (ps->fid[port] != fid)
1054 continue;
1055
1056 ret = _mv88e6xxx_update_port_config(ds, port);
1057 if (ret)
1058 return ret;
1059 }
1060
1061 return _mv88e6xxx_flush_fid(ds, fid);
1062}
1063
1064/* Bridge handling functions */
1065
1066int mv88e6xxx_join_bridge(struct dsa_switch *ds, int port, u32 br_port_mask)
1067{
1068 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1069 int ret = 0;
1070 u32 nmask;
1071 int fid;
1072
1073 /* If the bridge group is not empty, join that group.
1074 * Otherwise create a new group.
1075 */
1076 fid = ps->fid[port];
1077 nmask = br_port_mask & ~(1 << port);
1078 if (nmask)
1079 fid = ps->fid[__ffs(nmask)];
1080
1081 nmask = ps->bridge_mask[fid] | (1 << port);
1082 if (nmask != br_port_mask) {
1083 netdev_err(ds->ports[port],
1084 "join: Bridge port mask mismatch fid=%d mask=0x%x expected 0x%x\n",
1085 fid, br_port_mask, nmask);
1086 return -EINVAL;
1087 }
1088
1089 mutex_lock(&ps->smi_mutex);
1090
1091 ps->bridge_mask[fid] = br_port_mask;
1092
1093 if (fid != ps->fid[port]) {
Vivien Didelot194fea72015-08-10 09:09:47 -04001094 clear_bit(ps->fid[port], ps->fid_bitmap);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001095 ps->fid[port] = fid;
1096 ret = _mv88e6xxx_update_bridge_config(ds, fid);
1097 }
1098
1099 mutex_unlock(&ps->smi_mutex);
1100
1101 return ret;
1102}
1103
1104int mv88e6xxx_leave_bridge(struct dsa_switch *ds, int port, u32 br_port_mask)
1105{
1106 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1107 u8 fid, newfid;
1108 int ret;
1109
1110 fid = ps->fid[port];
1111
1112 if (ps->bridge_mask[fid] != br_port_mask) {
1113 netdev_err(ds->ports[port],
1114 "leave: Bridge port mask mismatch fid=%d mask=0x%x expected 0x%x\n",
1115 fid, br_port_mask, ps->bridge_mask[fid]);
1116 return -EINVAL;
1117 }
1118
1119 /* If the port was the last port of a bridge, we are done.
1120 * Otherwise assign a new fid to the port, and fix up
1121 * the bridge configuration.
1122 */
1123 if (br_port_mask == (1 << port))
1124 return 0;
1125
1126 mutex_lock(&ps->smi_mutex);
1127
Vivien Didelot194fea72015-08-10 09:09:47 -04001128 newfid = find_next_zero_bit(ps->fid_bitmap, VLAN_N_VID, 1);
1129 if (unlikely(newfid > ps->num_ports)) {
1130 netdev_err(ds->ports[port], "all first %d FIDs are used\n",
1131 ps->num_ports);
1132 ret = -ENOSPC;
1133 goto unlock;
1134 }
1135
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001136 ps->fid[port] = newfid;
Vivien Didelot194fea72015-08-10 09:09:47 -04001137 set_bit(newfid, ps->fid_bitmap);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001138 ps->bridge_mask[fid] &= ~(1 << port);
1139 ps->bridge_mask[newfid] = 1 << port;
1140
1141 ret = _mv88e6xxx_update_bridge_config(ds, fid);
1142 if (!ret)
1143 ret = _mv88e6xxx_update_bridge_config(ds, newfid);
1144
Vivien Didelot194fea72015-08-10 09:09:47 -04001145unlock:
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001146 mutex_unlock(&ps->smi_mutex);
1147
1148 return ret;
1149}
1150
1151int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state)
1152{
1153 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1154 int stp_state;
1155
1156 switch (state) {
1157 case BR_STATE_DISABLED:
Andrew Lunncca8b132015-04-02 04:06:39 +02001158 stp_state = PORT_CONTROL_STATE_DISABLED;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001159 break;
1160 case BR_STATE_BLOCKING:
1161 case BR_STATE_LISTENING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001162 stp_state = PORT_CONTROL_STATE_BLOCKING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001163 break;
1164 case BR_STATE_LEARNING:
Andrew Lunncca8b132015-04-02 04:06:39 +02001165 stp_state = PORT_CONTROL_STATE_LEARNING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001166 break;
1167 case BR_STATE_FORWARDING:
1168 default:
Andrew Lunncca8b132015-04-02 04:06:39 +02001169 stp_state = PORT_CONTROL_STATE_FORWARDING;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001170 break;
1171 }
1172
1173 netdev_dbg(ds->ports[port], "port state %d [%d]\n", state, stp_state);
1174
1175 /* mv88e6xxx_port_stp_update may be called with softirqs disabled,
1176 * so we can not update the port state directly but need to schedule it.
1177 */
1178 ps->port_state[port] = stp_state;
1179 set_bit(port, &ps->port_state_update_mask);
1180 schedule_work(&ps->bridge_work);
1181
1182 return 0;
1183}
1184
Vivien Didelot6b17e862015-08-13 12:52:18 -04001185static int _mv88e6xxx_vtu_wait(struct dsa_switch *ds)
1186{
1187 return _mv88e6xxx_wait(ds, REG_GLOBAL, GLOBAL_VTU_OP,
1188 GLOBAL_VTU_OP_BUSY);
1189}
1190
1191static int _mv88e6xxx_vtu_cmd(struct dsa_switch *ds, u16 op)
1192{
1193 int ret;
1194
1195 ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_OP, op);
1196 if (ret < 0)
1197 return ret;
1198
1199 return _mv88e6xxx_vtu_wait(ds);
1200}
1201
1202static int _mv88e6xxx_vtu_stu_flush(struct dsa_switch *ds)
1203{
1204 int ret;
1205
1206 ret = _mv88e6xxx_vtu_wait(ds);
1207 if (ret < 0)
1208 return ret;
1209
1210 return _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_FLUSH_ALL);
1211}
1212
Vivien Didelotc5723ac2015-08-10 09:09:48 -04001213static int _mv88e6xxx_atu_mac_write(struct dsa_switch *ds,
1214 const unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001215{
1216 int i, ret;
1217
1218 for (i = 0; i < 3; i++) {
Andrew Lunncca8b132015-04-02 04:06:39 +02001219 ret = _mv88e6xxx_reg_write(
1220 ds, REG_GLOBAL, GLOBAL_ATU_MAC_01 + i,
1221 (addr[i * 2] << 8) | addr[i * 2 + 1]);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001222 if (ret < 0)
1223 return ret;
1224 }
1225
1226 return 0;
1227}
1228
Vivien Didelotc5723ac2015-08-10 09:09:48 -04001229static int _mv88e6xxx_atu_mac_read(struct dsa_switch *ds, unsigned char *addr)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001230{
1231 int i, ret;
1232
1233 for (i = 0; i < 3; i++) {
Andrew Lunncca8b132015-04-02 04:06:39 +02001234 ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL,
1235 GLOBAL_ATU_MAC_01 + i);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001236 if (ret < 0)
1237 return ret;
1238 addr[i * 2] = ret >> 8;
1239 addr[i * 2 + 1] = ret & 0xff;
1240 }
1241
1242 return 0;
1243}
1244
Vivien Didelotfd231c82015-08-10 09:09:50 -04001245static int _mv88e6xxx_atu_load(struct dsa_switch *ds,
1246 struct mv88e6xxx_atu_entry *entry)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001247{
Vivien Didelotfd231c82015-08-10 09:09:50 -04001248 u16 reg = 0;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001249 int ret;
1250
1251 ret = _mv88e6xxx_atu_wait(ds);
1252 if (ret < 0)
1253 return ret;
1254
Vivien Didelotfd231c82015-08-10 09:09:50 -04001255 ret = _mv88e6xxx_atu_mac_write(ds, entry->mac);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001256 if (ret < 0)
1257 return ret;
1258
Vivien Didelotfd231c82015-08-10 09:09:50 -04001259 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1260 unsigned int mask, shift;
1261
1262 if (entry->trunk) {
1263 reg |= GLOBAL_ATU_DATA_TRUNK;
1264 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1265 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1266 } else {
1267 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1268 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1269 }
1270
1271 reg |= (entry->portv_trunkid << shift) & mask;
1272 }
1273
1274 reg |= entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1275
1276 ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_DATA, reg);
1277 if (ret < 0)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001278 return ret;
1279
Vivien Didelotfd231c82015-08-10 09:09:50 -04001280 return _mv88e6xxx_atu_cmd(ds, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
1281}
David S. Millercdf09692015-08-11 12:00:37 -07001282
Vivien Didelotfd231c82015-08-10 09:09:50 -04001283static int _mv88e6xxx_port_vid_to_fid(struct dsa_switch *ds, int port, u16 vid)
1284{
1285 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1286
1287 if (vid == 0)
1288 return ps->fid[port];
1289
1290 return -ENOENT;
1291}
1292
1293static int _mv88e6xxx_port_fdb_load(struct dsa_switch *ds, int port,
1294 const unsigned char *addr, u16 vid,
1295 u8 state)
1296{
1297 struct mv88e6xxx_atu_entry entry = { 0 };
1298 int ret;
1299
1300 ret = _mv88e6xxx_port_vid_to_fid(ds, port, vid);
1301 if (ret < 0)
1302 return ret;
1303
1304 entry.fid = ret;
1305 entry.state = state;
1306 ether_addr_copy(entry.mac, addr);
1307 if (state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1308 entry.trunk = false;
1309 entry.portv_trunkid = BIT(port);
1310 }
1311
1312 return _mv88e6xxx_atu_load(ds, &entry);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001313}
1314
David S. Millercdf09692015-08-11 12:00:37 -07001315int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1316 const unsigned char *addr, u16 vid)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001317{
David S. Millercdf09692015-08-11 12:00:37 -07001318 int state = is_multicast_ether_addr(addr) ?
1319 GLOBAL_ATU_DATA_STATE_MC_STATIC :
1320 GLOBAL_ATU_DATA_STATE_UC_STATIC;
1321 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Vivien Didelot6630e232015-08-06 01:44:07 -04001322 int ret;
1323
David S. Millercdf09692015-08-11 12:00:37 -07001324 mutex_lock(&ps->smi_mutex);
Vivien Didelotfd231c82015-08-10 09:09:50 -04001325 ret = _mv88e6xxx_port_fdb_load(ds, port, addr, vid, state);
David S. Millercdf09692015-08-11 12:00:37 -07001326 mutex_unlock(&ps->smi_mutex);
1327
1328 return ret;
1329}
1330
1331int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1332 const unsigned char *addr, u16 vid)
1333{
1334 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1335 int ret;
1336
1337 mutex_lock(&ps->smi_mutex);
Vivien Didelotfd231c82015-08-10 09:09:50 -04001338 ret = _mv88e6xxx_port_fdb_load(ds, port, addr, vid,
David S. Millercdf09692015-08-11 12:00:37 -07001339 GLOBAL_ATU_DATA_STATE_UNUSED);
1340 mutex_unlock(&ps->smi_mutex);
1341
1342 return ret;
1343}
1344
Vivien Didelot1d194042015-08-10 09:09:51 -04001345static int _mv88e6xxx_atu_getnext(struct dsa_switch *ds, u16 fid,
1346 const unsigned char *addr,
1347 struct mv88e6xxx_atu_entry *entry)
David S. Millercdf09692015-08-11 12:00:37 -07001348{
Vivien Didelot1d194042015-08-10 09:09:51 -04001349 struct mv88e6xxx_atu_entry next = { 0 };
1350 int ret;
1351
1352 next.fid = fid;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001353
1354 ret = _mv88e6xxx_atu_wait(ds);
1355 if (ret < 0)
1356 return ret;
1357
Vivien Didelotc5723ac2015-08-10 09:09:48 -04001358 ret = _mv88e6xxx_atu_mac_write(ds, addr);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001359 if (ret < 0)
1360 return ret;
1361
Vivien Didelot1d194042015-08-10 09:09:51 -04001362 ret = _mv88e6xxx_atu_cmd(ds, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001363 if (ret < 0)
1364 return ret;
1365
Vivien Didelot1d194042015-08-10 09:09:51 -04001366 ret = _mv88e6xxx_atu_mac_read(ds, next.mac);
1367 if (ret < 0)
1368 return ret;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001369
Vivien Didelot1d194042015-08-10 09:09:51 -04001370 ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_ATU_DATA);
1371 if (ret < 0)
1372 return ret;
1373
1374 next.state = ret & GLOBAL_ATU_DATA_STATE_MASK;
1375 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1376 unsigned int mask, shift;
1377
1378 if (ret & GLOBAL_ATU_DATA_TRUNK) {
1379 next.trunk = true;
1380 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1381 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1382 } else {
1383 next.trunk = false;
1384 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1385 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1386 }
1387
1388 next.portv_trunkid = (ret & mask) >> shift;
1389 }
1390
1391 *entry = next;
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001392 return 0;
1393}
1394
David S. Millercdf09692015-08-11 12:00:37 -07001395/* get next entry for port */
1396int mv88e6xxx_port_fdb_getnext(struct dsa_switch *ds, int port,
Vivien Didelot2a778e12015-08-10 09:09:49 -04001397 unsigned char *addr, u16 *vid, bool *is_static)
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001398{
1399 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Vivien Didelot1d194042015-08-10 09:09:51 -04001400 struct mv88e6xxx_atu_entry next;
1401 u16 fid;
Vivien Didelot87820512015-08-06 01:44:08 -04001402 int ret;
1403
1404 mutex_lock(&ps->smi_mutex);
Vivien Didelot1d194042015-08-10 09:09:51 -04001405
1406 ret = _mv88e6xxx_port_vid_to_fid(ds, port, *vid);
1407 if (ret < 0)
1408 goto unlock;
1409 fid = ret;
1410
1411 do {
1412 if (is_broadcast_ether_addr(addr)) {
1413 ret = -ENOENT;
1414 goto unlock;
1415 }
1416
1417 ret = _mv88e6xxx_atu_getnext(ds, fid, addr, &next);
1418 if (ret < 0)
1419 goto unlock;
1420
1421 ether_addr_copy(addr, next.mac);
1422
1423 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
1424 continue;
1425 } while (next.trunk || (next.portv_trunkid & BIT(port)) == 0);
1426
1427 *is_static = next.state == (is_multicast_ether_addr(addr) ?
1428 GLOBAL_ATU_DATA_STATE_MC_STATIC :
1429 GLOBAL_ATU_DATA_STATE_UC_STATIC);
1430unlock:
Guenter Roeckdefb05b2015-03-26 18:36:38 -07001431 mutex_unlock(&ps->smi_mutex);
1432
1433 return ret;
1434}
1435
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001436static void mv88e6xxx_bridge_work(struct work_struct *work)
1437{
1438 struct mv88e6xxx_priv_state *ps;
1439 struct dsa_switch *ds;
1440 int port;
1441
1442 ps = container_of(work, struct mv88e6xxx_priv_state, bridge_work);
1443 ds = ((struct dsa_switch *)ps) - 1;
1444
1445 while (ps->port_state_update_mask) {
1446 port = __ffs(ps->port_state_update_mask);
1447 clear_bit(port, &ps->port_state_update_mask);
1448 mv88e6xxx_set_port_state(ds, port, ps->port_state[port]);
1449 }
1450}
1451
Andrew Lunndbde9e62015-05-06 01:09:48 +02001452static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
Guenter Roeckd827e882015-03-26 18:36:29 -07001453{
1454 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001455 int ret, fid;
Andrew Lunn54d792f2015-05-06 01:09:47 +02001456 u16 reg;
Guenter Roeckd827e882015-03-26 18:36:29 -07001457
1458 mutex_lock(&ps->smi_mutex);
1459
Andrew Lunn54d792f2015-05-06 01:09:47 +02001460 if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) ||
1461 mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) ||
1462 mv88e6xxx_6185_family(ds) || mv88e6xxx_6095_family(ds) ||
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -07001463 mv88e6xxx_6065_family(ds) || mv88e6xxx_6320_family(ds)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02001464 /* MAC Forcing register: don't force link, speed,
1465 * duplex or flow control state to any particular
1466 * values on physical ports, but force the CPU port
1467 * and all DSA ports to their maximum bandwidth and
1468 * full duplex.
1469 */
1470 reg = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_PCS_CTRL);
1471 if (dsa_is_cpu_port(ds, port) ||
1472 ds->dsa_port_mask & (1 << port)) {
1473 reg |= PORT_PCS_CTRL_FORCE_LINK |
1474 PORT_PCS_CTRL_LINK_UP |
1475 PORT_PCS_CTRL_DUPLEX_FULL |
1476 PORT_PCS_CTRL_FORCE_DUPLEX;
1477 if (mv88e6xxx_6065_family(ds))
1478 reg |= PORT_PCS_CTRL_100;
1479 else
1480 reg |= PORT_PCS_CTRL_1000;
1481 } else {
1482 reg |= PORT_PCS_CTRL_UNFORCED;
1483 }
1484
1485 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port),
1486 PORT_PCS_CTRL, reg);
1487 if (ret)
1488 goto abort;
1489 }
1490
1491 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
1492 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
1493 * tunneling, determine priority by looking at 802.1p and IP
1494 * priority fields (IP prio has precedence), and set STP state
1495 * to Forwarding.
1496 *
1497 * If this is the CPU link, use DSA or EDSA tagging depending
1498 * on which tagging mode was configured.
1499 *
1500 * If this is a link to another switch, use DSA tagging mode.
1501 *
1502 * If this is the upstream port for this switch, enable
1503 * forwarding of unknown unicasts and multicasts.
1504 */
1505 reg = 0;
1506 if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) ||
1507 mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) ||
1508 mv88e6xxx_6095_family(ds) || mv88e6xxx_6065_family(ds) ||
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -07001509 mv88e6xxx_6185_family(ds) || mv88e6xxx_6320_family(ds))
Andrew Lunn54d792f2015-05-06 01:09:47 +02001510 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
1511 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
1512 PORT_CONTROL_STATE_FORWARDING;
1513 if (dsa_is_cpu_port(ds, port)) {
1514 if (mv88e6xxx_6095_family(ds) || mv88e6xxx_6185_family(ds))
1515 reg |= PORT_CONTROL_DSA_TAG;
1516 if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) ||
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -07001517 mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) ||
1518 mv88e6xxx_6320_family(ds)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02001519 if (ds->dst->tag_protocol == DSA_TAG_PROTO_EDSA)
1520 reg |= PORT_CONTROL_FRAME_ETHER_TYPE_DSA;
1521 else
1522 reg |= PORT_CONTROL_FRAME_MODE_DSA;
1523 }
1524
1525 if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) ||
1526 mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) ||
1527 mv88e6xxx_6095_family(ds) || mv88e6xxx_6065_family(ds) ||
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -07001528 mv88e6xxx_6185_family(ds) || mv88e6xxx_6320_family(ds)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02001529 if (ds->dst->tag_protocol == DSA_TAG_PROTO_EDSA)
1530 reg |= PORT_CONTROL_EGRESS_ADD_TAG;
1531 }
1532 }
1533 if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) ||
1534 mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) ||
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -07001535 mv88e6xxx_6095_family(ds) || mv88e6xxx_6065_family(ds) ||
1536 mv88e6xxx_6320_family(ds)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02001537 if (ds->dsa_port_mask & (1 << port))
1538 reg |= PORT_CONTROL_FRAME_MODE_DSA;
1539 if (port == dsa_upstream_port(ds))
1540 reg |= PORT_CONTROL_FORWARD_UNKNOWN |
1541 PORT_CONTROL_FORWARD_UNKNOWN_MC;
1542 }
1543 if (reg) {
1544 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port),
1545 PORT_CONTROL, reg);
1546 if (ret)
1547 goto abort;
1548 }
1549
1550 /* Port Control 2: don't force a good FCS, set the maximum
1551 * frame size to 10240 bytes, don't let the switch add or
1552 * strip 802.1q tags, don't discard tagged or untagged frames
1553 * on this port, do a destination address lookup on all
1554 * received packets as usual, disable ARP mirroring and don't
1555 * send a copy of all transmitted/received frames on this port
1556 * to the CPU.
1557 */
1558 reg = 0;
1559 if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) ||
1560 mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) ||
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -07001561 mv88e6xxx_6095_family(ds) || mv88e6xxx_6320_family(ds))
Andrew Lunn54d792f2015-05-06 01:09:47 +02001562 reg = PORT_CONTROL_2_MAP_DA;
1563
1564 if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) ||
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -07001565 mv88e6xxx_6165_family(ds) || mv88e6xxx_6320_family(ds))
Andrew Lunn54d792f2015-05-06 01:09:47 +02001566 reg |= PORT_CONTROL_2_JUMBO_10240;
1567
1568 if (mv88e6xxx_6095_family(ds) || mv88e6xxx_6185_family(ds)) {
1569 /* Set the upstream port this port should use */
1570 reg |= dsa_upstream_port(ds);
1571 /* enable forwarding of unknown multicast addresses to
1572 * the upstream port
1573 */
1574 if (port == dsa_upstream_port(ds))
1575 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
1576 }
1577
1578 if (reg) {
1579 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port),
1580 PORT_CONTROL_2, reg);
1581 if (ret)
1582 goto abort;
1583 }
1584
1585 /* Port Association Vector: when learning source addresses
1586 * of packets, add the address to the address database using
1587 * a port bitmap that has only the bit for this port set and
1588 * the other bits clear.
1589 */
1590 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_ASSOC_VECTOR,
1591 1 << port);
1592 if (ret)
1593 goto abort;
1594
1595 /* Egress rate control 2: disable egress rate control. */
1596 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_RATE_CONTROL_2,
1597 0x0000);
1598 if (ret)
1599 goto abort;
1600
1601 if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) ||
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -07001602 mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) ||
1603 mv88e6xxx_6320_family(ds)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02001604 /* Do not limit the period of time that this port can
1605 * be paused for by the remote end or the period of
1606 * time that this port can pause the remote end.
1607 */
1608 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port),
1609 PORT_PAUSE_CTRL, 0x0000);
1610 if (ret)
1611 goto abort;
1612
1613 /* Port ATU control: disable limiting the number of
1614 * address database entries that this port is allowed
1615 * to use.
1616 */
1617 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port),
1618 PORT_ATU_CONTROL, 0x0000);
1619 /* Priority Override: disable DA, SA and VTU priority
1620 * override.
1621 */
1622 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port),
1623 PORT_PRI_OVERRIDE, 0x0000);
1624 if (ret)
1625 goto abort;
1626
1627 /* Port Ethertype: use the Ethertype DSA Ethertype
1628 * value.
1629 */
1630 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port),
1631 PORT_ETH_TYPE, ETH_P_EDSA);
1632 if (ret)
1633 goto abort;
1634 /* Tag Remap: use an identity 802.1p prio -> switch
1635 * prio mapping.
1636 */
1637 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port),
1638 PORT_TAG_REGMAP_0123, 0x3210);
1639 if (ret)
1640 goto abort;
1641
1642 /* Tag Remap 2: use an identity 802.1p prio -> switch
1643 * prio mapping.
1644 */
1645 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port),
1646 PORT_TAG_REGMAP_4567, 0x7654);
1647 if (ret)
1648 goto abort;
1649 }
1650
1651 if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) ||
1652 mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) ||
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -07001653 mv88e6xxx_6185_family(ds) || mv88e6xxx_6095_family(ds) ||
1654 mv88e6xxx_6320_family(ds)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02001655 /* Rate Control: disable ingress rate limiting. */
1656 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port),
1657 PORT_RATE_CONTROL, 0x0001);
1658 if (ret)
1659 goto abort;
1660 }
1661
Guenter Roeck366f0a02015-03-26 18:36:30 -07001662 /* Port Control 1: disable trunking, disable sending
1663 * learning messages to this port.
Guenter Roeckd827e882015-03-26 18:36:29 -07001664 */
Vivien Didelot614f03f2015-04-20 17:19:23 -04001665 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_CONTROL_1, 0x0000);
Guenter Roeckd827e882015-03-26 18:36:29 -07001666 if (ret)
1667 goto abort;
1668
1669 /* Port based VLAN map: give each port its own address
1670 * database, allow the CPU port to talk to each of the 'real'
1671 * ports, and allow each of the 'real' ports to only talk to
1672 * the upstream port.
1673 */
Vivien Didelot194fea72015-08-10 09:09:47 -04001674 fid = port + 1;
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001675 ps->fid[port] = fid;
Vivien Didelot194fea72015-08-10 09:09:47 -04001676 set_bit(fid, ps->fid_bitmap);
Guenter Roeckd827e882015-03-26 18:36:29 -07001677
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001678 if (!dsa_is_cpu_port(ds, port))
1679 ps->bridge_mask[fid] = 1 << port;
1680
1681 ret = _mv88e6xxx_update_port_config(ds, port);
Guenter Roeckd827e882015-03-26 18:36:29 -07001682 if (ret)
1683 goto abort;
1684
1685 /* Default VLAN ID and priority: don't set a default VLAN
1686 * ID, and set the default packet priority to zero.
1687 */
Vivien Didelot47cf1e652015-04-20 17:43:26 -04001688 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_DEFAULT_VLAN,
1689 0x0000);
Guenter Roeckd827e882015-03-26 18:36:29 -07001690abort:
1691 mutex_unlock(&ps->smi_mutex);
1692 return ret;
1693}
1694
Andrew Lunndbde9e62015-05-06 01:09:48 +02001695int mv88e6xxx_setup_ports(struct dsa_switch *ds)
1696{
1697 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1698 int ret;
1699 int i;
1700
1701 for (i = 0; i < ps->num_ports; i++) {
1702 ret = mv88e6xxx_setup_port(ds, i);
1703 if (ret < 0)
1704 return ret;
1705 }
1706 return 0;
1707}
1708
Andrew Lunn87c8cef2015-06-20 18:42:28 +02001709static int mv88e6xxx_regs_show(struct seq_file *s, void *p)
1710{
1711 struct dsa_switch *ds = s->private;
1712
1713 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1714 int reg, port;
1715
1716 seq_puts(s, " GLOBAL GLOBAL2 ");
1717 for (port = 0 ; port < ps->num_ports; port++)
1718 seq_printf(s, " %2d ", port);
1719 seq_puts(s, "\n");
1720
1721 for (reg = 0; reg < 32; reg++) {
1722 seq_printf(s, "%2x: ", reg);
1723 seq_printf(s, " %4x %4x ",
1724 mv88e6xxx_reg_read(ds, REG_GLOBAL, reg),
1725 mv88e6xxx_reg_read(ds, REG_GLOBAL2, reg));
1726
1727 for (port = 0 ; port < ps->num_ports; port++)
1728 seq_printf(s, "%4x ",
1729 mv88e6xxx_reg_read(ds, REG_PORT(port), reg));
1730 seq_puts(s, "\n");
1731 }
1732
1733 return 0;
1734}
1735
1736static int mv88e6xxx_regs_open(struct inode *inode, struct file *file)
1737{
1738 return single_open(file, mv88e6xxx_regs_show, inode->i_private);
1739}
1740
1741static const struct file_operations mv88e6xxx_regs_fops = {
1742 .open = mv88e6xxx_regs_open,
1743 .read = seq_read,
1744 .llseek = no_llseek,
1745 .release = single_release,
1746 .owner = THIS_MODULE,
1747};
1748
Andrew Lunn8a0a2652015-06-20 18:42:29 +02001749static void mv88e6xxx_atu_show_header(struct seq_file *s)
1750{
1751 seq_puts(s, "DB T/P Vec State Addr\n");
1752}
1753
1754static void mv88e6xxx_atu_show_entry(struct seq_file *s, int dbnum,
1755 unsigned char *addr, int data)
1756{
1757 bool trunk = !!(data & GLOBAL_ATU_DATA_TRUNK);
1758 int portvec = ((data & GLOBAL_ATU_DATA_PORT_VECTOR_MASK) >>
1759 GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT);
1760 int state = data & GLOBAL_ATU_DATA_STATE_MASK;
1761
1762 seq_printf(s, "%03x %5s %10pb %x %pM\n",
1763 dbnum, (trunk ? "Trunk" : "Port"), &portvec, state, addr);
1764}
1765
1766static int mv88e6xxx_atu_show_db(struct seq_file *s, struct dsa_switch *ds,
1767 int dbnum)
1768{
1769 unsigned char bcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1770 unsigned char addr[6];
1771 int ret, data, state;
1772
Vivien Didelotc5723ac2015-08-10 09:09:48 -04001773 ret = _mv88e6xxx_atu_mac_write(ds, bcast);
Andrew Lunn8a0a2652015-06-20 18:42:29 +02001774 if (ret < 0)
1775 return ret;
1776
1777 do {
1778 ret = _mv88e6xxx_atu_cmd(ds, dbnum, GLOBAL_ATU_OP_GET_NEXT_DB);
1779 if (ret < 0)
1780 return ret;
1781 data = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_ATU_DATA);
1782 if (data < 0)
1783 return data;
1784
1785 state = data & GLOBAL_ATU_DATA_STATE_MASK;
1786 if (state == GLOBAL_ATU_DATA_STATE_UNUSED)
1787 break;
Vivien Didelotc5723ac2015-08-10 09:09:48 -04001788 ret = _mv88e6xxx_atu_mac_read(ds, addr);
Andrew Lunn8a0a2652015-06-20 18:42:29 +02001789 if (ret < 0)
1790 return ret;
1791 mv88e6xxx_atu_show_entry(s, dbnum, addr, data);
1792 } while (state != GLOBAL_ATU_DATA_STATE_UNUSED);
1793
1794 return 0;
1795}
1796
1797static int mv88e6xxx_atu_show(struct seq_file *s, void *p)
1798{
1799 struct dsa_switch *ds = s->private;
1800 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1801 int dbnum;
1802
1803 mv88e6xxx_atu_show_header(s);
1804
1805 for (dbnum = 0; dbnum < 255; dbnum++) {
1806 mutex_lock(&ps->smi_mutex);
1807 mv88e6xxx_atu_show_db(s, ds, dbnum);
1808 mutex_unlock(&ps->smi_mutex);
1809 }
1810
1811 return 0;
1812}
1813
1814static int mv88e6xxx_atu_open(struct inode *inode, struct file *file)
1815{
1816 return single_open(file, mv88e6xxx_atu_show, inode->i_private);
1817}
1818
1819static const struct file_operations mv88e6xxx_atu_fops = {
1820 .open = mv88e6xxx_atu_open,
1821 .read = seq_read,
1822 .llseek = no_llseek,
1823 .release = single_release,
1824 .owner = THIS_MODULE,
1825};
1826
Andrew Lunn532c7a32015-06-20 18:42:31 +02001827static void mv88e6xxx_stats_show_header(struct seq_file *s,
1828 struct mv88e6xxx_priv_state *ps)
1829{
1830 int port;
1831
1832 seq_puts(s, " Statistic ");
1833 for (port = 0 ; port < ps->num_ports; port++)
1834 seq_printf(s, "Port %2d ", port);
1835 seq_puts(s, "\n");
1836}
1837
1838static int mv88e6xxx_stats_show(struct seq_file *s, void *p)
1839{
1840 struct dsa_switch *ds = s->private;
1841 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1842 struct mv88e6xxx_hw_stat *stats = mv88e6xxx_hw_stats;
1843 int port, stat, max_stats;
1844 uint64_t value;
1845
1846 if (have_sw_in_discards(ds))
1847 max_stats = ARRAY_SIZE(mv88e6xxx_hw_stats);
1848 else
1849 max_stats = ARRAY_SIZE(mv88e6xxx_hw_stats) - 3;
1850
1851 mv88e6xxx_stats_show_header(s, ps);
1852
1853 mutex_lock(&ps->smi_mutex);
1854
1855 for (stat = 0; stat < max_stats; stat++) {
1856 seq_printf(s, "%19s: ", stats[stat].string);
1857 for (port = 0 ; port < ps->num_ports; port++) {
1858 _mv88e6xxx_stats_snapshot(ds, port);
1859 value = _mv88e6xxx_get_ethtool_stat(ds, stat, stats,
1860 port);
1861 seq_printf(s, "%8llu ", value);
1862 }
1863 seq_puts(s, "\n");
1864 }
1865 mutex_unlock(&ps->smi_mutex);
1866
1867 return 0;
1868}
1869
1870static int mv88e6xxx_stats_open(struct inode *inode, struct file *file)
1871{
1872 return single_open(file, mv88e6xxx_stats_show, inode->i_private);
1873}
1874
1875static const struct file_operations mv88e6xxx_stats_fops = {
1876 .open = mv88e6xxx_stats_open,
1877 .read = seq_read,
1878 .llseek = no_llseek,
1879 .release = single_release,
1880 .owner = THIS_MODULE,
1881};
1882
Andrew Lunnd35bd872015-06-20 18:42:32 +02001883static int mv88e6xxx_device_map_show(struct seq_file *s, void *p)
1884{
1885 struct dsa_switch *ds = s->private;
1886 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1887 int target, ret;
1888
1889 seq_puts(s, "Target Port\n");
1890
1891 mutex_lock(&ps->smi_mutex);
1892 for (target = 0; target < 32; target++) {
1893 ret = _mv88e6xxx_reg_write(
1894 ds, REG_GLOBAL2, GLOBAL2_DEVICE_MAPPING,
1895 target << GLOBAL2_DEVICE_MAPPING_TARGET_SHIFT);
1896 if (ret < 0)
1897 goto out;
1898 ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL2,
1899 GLOBAL2_DEVICE_MAPPING);
1900 seq_printf(s, " %2d %2d\n", target,
1901 ret & GLOBAL2_DEVICE_MAPPING_PORT_MASK);
1902 }
1903out:
1904 mutex_unlock(&ps->smi_mutex);
1905
1906 return 0;
1907}
1908
1909static int mv88e6xxx_device_map_open(struct inode *inode, struct file *file)
1910{
1911 return single_open(file, mv88e6xxx_device_map_show, inode->i_private);
1912}
1913
1914static const struct file_operations mv88e6xxx_device_map_fops = {
1915 .open = mv88e6xxx_device_map_open,
1916 .read = seq_read,
1917 .llseek = no_llseek,
1918 .release = single_release,
1919 .owner = THIS_MODULE,
1920};
1921
Andrew Lunn56d95e22015-06-20 18:42:33 +02001922static int mv88e6xxx_scratch_show(struct seq_file *s, void *p)
1923{
1924 struct dsa_switch *ds = s->private;
1925 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1926 int reg, ret;
1927
1928 seq_puts(s, "Register Value\n");
1929
1930 mutex_lock(&ps->smi_mutex);
1931 for (reg = 0; reg < 0x80; reg++) {
1932 ret = _mv88e6xxx_reg_write(
1933 ds, REG_GLOBAL2, GLOBAL2_SCRATCH_MISC,
1934 reg << GLOBAL2_SCRATCH_REGISTER_SHIFT);
1935 if (ret < 0)
1936 goto out;
1937
1938 ret = _mv88e6xxx_scratch_wait(ds);
1939 if (ret < 0)
1940 goto out;
1941
1942 ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL2,
1943 GLOBAL2_SCRATCH_MISC);
1944 seq_printf(s, " %2x %2x\n", reg,
1945 ret & GLOBAL2_SCRATCH_VALUE_MASK);
1946 }
1947out:
1948 mutex_unlock(&ps->smi_mutex);
1949
1950 return 0;
1951}
1952
1953static int mv88e6xxx_scratch_open(struct inode *inode, struct file *file)
1954{
1955 return single_open(file, mv88e6xxx_scratch_show, inode->i_private);
1956}
1957
1958static const struct file_operations mv88e6xxx_scratch_fops = {
1959 .open = mv88e6xxx_scratch_open,
1960 .read = seq_read,
1961 .llseek = no_llseek,
1962 .release = single_release,
1963 .owner = THIS_MODULE,
1964};
1965
Guenter Roeckacdaffc2015-03-26 18:36:28 -07001966int mv88e6xxx_setup_common(struct dsa_switch *ds)
1967{
1968 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Andrew Lunn87c8cef2015-06-20 18:42:28 +02001969 char *name;
Guenter Roeckacdaffc2015-03-26 18:36:28 -07001970
1971 mutex_init(&ps->smi_mutex);
Guenter Roeckacdaffc2015-03-26 18:36:28 -07001972
Andrew Lunncca8b132015-04-02 04:06:39 +02001973 ps->id = REG_READ(REG_PORT(0), PORT_SWITCH_ID) & 0xfff0;
Andrew Lunna8f064c2015-03-26 18:36:40 -07001974
Guenter Roeckfacd95b2015-03-26 18:36:35 -07001975 INIT_WORK(&ps->bridge_work, mv88e6xxx_bridge_work);
1976
Andrew Lunn87c8cef2015-06-20 18:42:28 +02001977 name = kasprintf(GFP_KERNEL, "dsa%d", ds->index);
1978 ps->dbgfs = debugfs_create_dir(name, NULL);
1979 kfree(name);
1980
1981 debugfs_create_file("regs", S_IRUGO, ps->dbgfs, ds,
1982 &mv88e6xxx_regs_fops);
1983
Andrew Lunn8a0a2652015-06-20 18:42:29 +02001984 debugfs_create_file("atu", S_IRUGO, ps->dbgfs, ds,
1985 &mv88e6xxx_atu_fops);
1986
Andrew Lunn532c7a32015-06-20 18:42:31 +02001987 debugfs_create_file("stats", S_IRUGO, ps->dbgfs, ds,
1988 &mv88e6xxx_stats_fops);
1989
Andrew Lunnd35bd872015-06-20 18:42:32 +02001990 debugfs_create_file("device_map", S_IRUGO, ps->dbgfs, ds,
1991 &mv88e6xxx_device_map_fops);
Andrew Lunn56d95e22015-06-20 18:42:33 +02001992
1993 debugfs_create_file("scratch", S_IRUGO, ps->dbgfs, ds,
1994 &mv88e6xxx_scratch_fops);
Guenter Roeckacdaffc2015-03-26 18:36:28 -07001995 return 0;
1996}
1997
Andrew Lunn54d792f2015-05-06 01:09:47 +02001998int mv88e6xxx_setup_global(struct dsa_switch *ds)
1999{
2000 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Vivien Didelot24751e22015-08-03 09:17:44 -04002001 int ret;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002002 int i;
2003
2004 /* Set the default address aging time to 5 minutes, and
2005 * enable address learn messages to be sent to all message
2006 * ports.
2007 */
2008 REG_WRITE(REG_GLOBAL, GLOBAL_ATU_CONTROL,
2009 0x0140 | GLOBAL_ATU_CONTROL_LEARN2ALL);
2010
2011 /* Configure the IP ToS mapping registers. */
2012 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_0, 0x0000);
2013 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_1, 0x0000);
2014 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_2, 0x5555);
2015 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_3, 0x5555);
2016 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_4, 0xaaaa);
2017 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_5, 0xaaaa);
2018 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_6, 0xffff);
2019 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_7, 0xffff);
2020
2021 /* Configure the IEEE 802.1p priority mapping register. */
2022 REG_WRITE(REG_GLOBAL, GLOBAL_IEEE_PRI, 0xfa41);
2023
2024 /* Send all frames with destination addresses matching
2025 * 01:80:c2:00:00:0x to the CPU port.
2026 */
2027 REG_WRITE(REG_GLOBAL2, GLOBAL2_MGMT_EN_0X, 0xffff);
2028
2029 /* Ignore removed tag data on doubly tagged packets, disable
2030 * flow control messages, force flow control priority to the
2031 * highest, and send all special multicast frames to the CPU
2032 * port at the highest priority.
2033 */
2034 REG_WRITE(REG_GLOBAL2, GLOBAL2_SWITCH_MGMT,
2035 0x7 | GLOBAL2_SWITCH_MGMT_RSVD2CPU | 0x70 |
2036 GLOBAL2_SWITCH_MGMT_FORCE_FLOW_CTRL_PRI);
2037
2038 /* Program the DSA routing table. */
2039 for (i = 0; i < 32; i++) {
2040 int nexthop = 0x1f;
2041
2042 if (ds->pd->rtable &&
2043 i != ds->index && i < ds->dst->pd->nr_chips)
2044 nexthop = ds->pd->rtable[i] & 0x1f;
2045
2046 REG_WRITE(REG_GLOBAL2, GLOBAL2_DEVICE_MAPPING,
2047 GLOBAL2_DEVICE_MAPPING_UPDATE |
2048 (i << GLOBAL2_DEVICE_MAPPING_TARGET_SHIFT) |
2049 nexthop);
2050 }
2051
2052 /* Clear all trunk masks. */
2053 for (i = 0; i < 8; i++)
2054 REG_WRITE(REG_GLOBAL2, GLOBAL2_TRUNK_MASK,
2055 0x8000 | (i << GLOBAL2_TRUNK_MASK_NUM_SHIFT) |
2056 ((1 << ps->num_ports) - 1));
2057
2058 /* Clear all trunk mappings. */
2059 for (i = 0; i < 16; i++)
2060 REG_WRITE(REG_GLOBAL2, GLOBAL2_TRUNK_MAPPING,
2061 GLOBAL2_TRUNK_MAPPING_UPDATE |
2062 (i << GLOBAL2_TRUNK_MAPPING_ID_SHIFT));
2063
2064 if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) ||
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -07002065 mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) ||
2066 mv88e6xxx_6320_family(ds)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002067 /* Send all frames with destination addresses matching
2068 * 01:80:c2:00:00:2x to the CPU port.
2069 */
2070 REG_WRITE(REG_GLOBAL2, GLOBAL2_MGMT_EN_2X, 0xffff);
2071
2072 /* Initialise cross-chip port VLAN table to reset
2073 * defaults.
2074 */
2075 REG_WRITE(REG_GLOBAL2, GLOBAL2_PVT_ADDR, 0x9000);
2076
2077 /* Clear the priority override table. */
2078 for (i = 0; i < 16; i++)
2079 REG_WRITE(REG_GLOBAL2, GLOBAL2_PRIO_OVERRIDE,
2080 0x8000 | (i << 8));
2081 }
2082
2083 if (mv88e6xxx_6352_family(ds) || mv88e6xxx_6351_family(ds) ||
2084 mv88e6xxx_6165_family(ds) || mv88e6xxx_6097_family(ds) ||
Aleksey S. Kazantsev7c3d0d62015-07-07 20:38:15 -07002085 mv88e6xxx_6185_family(ds) || mv88e6xxx_6095_family(ds) ||
2086 mv88e6xxx_6320_family(ds)) {
Andrew Lunn54d792f2015-05-06 01:09:47 +02002087 /* Disable ingress rate limiting by resetting all
2088 * ingress rate limit registers to their initial
2089 * state.
2090 */
2091 for (i = 0; i < ps->num_ports; i++)
2092 REG_WRITE(REG_GLOBAL2, GLOBAL2_INGRESS_OP,
2093 0x9000 | (i << 8));
2094 }
2095
Andrew Lunndb687a52015-06-20 21:31:29 +02002096 /* Clear the statistics counters for all ports */
2097 REG_WRITE(REG_GLOBAL, GLOBAL_STATS_OP, GLOBAL_STATS_OP_FLUSH_ALL);
2098
2099 /* Wait for the flush to complete. */
Vivien Didelot24751e22015-08-03 09:17:44 -04002100 mutex_lock(&ps->smi_mutex);
2101 ret = _mv88e6xxx_stats_wait(ds);
Vivien Didelot6b17e862015-08-13 12:52:18 -04002102 if (ret < 0)
2103 goto unlock;
2104
2105 /* Clear all the VTU and STU entries */
2106 ret = _mv88e6xxx_vtu_stu_flush(ds);
2107unlock:
Vivien Didelot24751e22015-08-03 09:17:44 -04002108 mutex_unlock(&ps->smi_mutex);
Andrew Lunndb687a52015-06-20 21:31:29 +02002109
Vivien Didelot24751e22015-08-03 09:17:44 -04002110 return ret;
Andrew Lunn54d792f2015-05-06 01:09:47 +02002111}
2112
Andrew Lunn143a8302015-04-02 04:06:34 +02002113int mv88e6xxx_switch_reset(struct dsa_switch *ds, bool ppu_active)
2114{
2115 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
2116 u16 is_reset = (ppu_active ? 0x8800 : 0xc800);
2117 unsigned long timeout;
2118 int ret;
2119 int i;
2120
2121 /* Set all ports to the disabled state. */
2122 for (i = 0; i < ps->num_ports; i++) {
Andrew Lunncca8b132015-04-02 04:06:39 +02002123 ret = REG_READ(REG_PORT(i), PORT_CONTROL);
2124 REG_WRITE(REG_PORT(i), PORT_CONTROL, ret & 0xfffc);
Andrew Lunn143a8302015-04-02 04:06:34 +02002125 }
2126
2127 /* Wait for transmit queues to drain. */
2128 usleep_range(2000, 4000);
2129
2130 /* Reset the switch. Keep the PPU active if requested. The PPU
2131 * needs to be active to support indirect phy register access
2132 * through global registers 0x18 and 0x19.
2133 */
2134 if (ppu_active)
2135 REG_WRITE(REG_GLOBAL, 0x04, 0xc000);
2136 else
2137 REG_WRITE(REG_GLOBAL, 0x04, 0xc400);
2138
2139 /* Wait up to one second for reset to complete. */
2140 timeout = jiffies + 1 * HZ;
2141 while (time_before(jiffies, timeout)) {
2142 ret = REG_READ(REG_GLOBAL, 0x00);
2143 if ((ret & is_reset) == is_reset)
2144 break;
2145 usleep_range(1000, 2000);
2146 }
2147 if (time_after(jiffies, timeout))
2148 return -ETIMEDOUT;
2149
2150 return 0;
2151}
2152
Andrew Lunn491435852015-04-02 04:06:35 +02002153int mv88e6xxx_phy_page_read(struct dsa_switch *ds, int port, int page, int reg)
2154{
2155 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
2156 int ret;
2157
Andrew Lunn3898c142015-05-06 01:09:53 +02002158 mutex_lock(&ps->smi_mutex);
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002159 ret = _mv88e6xxx_phy_write_indirect(ds, port, 0x16, page);
Andrew Lunn491435852015-04-02 04:06:35 +02002160 if (ret < 0)
2161 goto error;
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002162 ret = _mv88e6xxx_phy_read_indirect(ds, port, reg);
Andrew Lunn491435852015-04-02 04:06:35 +02002163error:
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002164 _mv88e6xxx_phy_write_indirect(ds, port, 0x16, 0x0);
Andrew Lunn3898c142015-05-06 01:09:53 +02002165 mutex_unlock(&ps->smi_mutex);
Andrew Lunn491435852015-04-02 04:06:35 +02002166 return ret;
2167}
2168
2169int mv88e6xxx_phy_page_write(struct dsa_switch *ds, int port, int page,
2170 int reg, int val)
2171{
2172 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
2173 int ret;
2174
Andrew Lunn3898c142015-05-06 01:09:53 +02002175 mutex_lock(&ps->smi_mutex);
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002176 ret = _mv88e6xxx_phy_write_indirect(ds, port, 0x16, page);
Andrew Lunn491435852015-04-02 04:06:35 +02002177 if (ret < 0)
2178 goto error;
2179
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002180 ret = _mv88e6xxx_phy_write_indirect(ds, port, reg, val);
Andrew Lunn491435852015-04-02 04:06:35 +02002181error:
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002182 _mv88e6xxx_phy_write_indirect(ds, port, 0x16, 0x0);
Andrew Lunn3898c142015-05-06 01:09:53 +02002183 mutex_unlock(&ps->smi_mutex);
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002184 return ret;
2185}
2186
2187static int mv88e6xxx_port_to_phy_addr(struct dsa_switch *ds, int port)
2188{
2189 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
2190
2191 if (port >= 0 && port < ps->num_ports)
2192 return port;
2193 return -EINVAL;
2194}
2195
2196int
2197mv88e6xxx_phy_read(struct dsa_switch *ds, int port, int regnum)
2198{
2199 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
2200 int addr = mv88e6xxx_port_to_phy_addr(ds, port);
2201 int ret;
2202
2203 if (addr < 0)
2204 return addr;
2205
Andrew Lunn3898c142015-05-06 01:09:53 +02002206 mutex_lock(&ps->smi_mutex);
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002207 ret = _mv88e6xxx_phy_read(ds, addr, regnum);
Andrew Lunn3898c142015-05-06 01:09:53 +02002208 mutex_unlock(&ps->smi_mutex);
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002209 return ret;
2210}
2211
2212int
2213mv88e6xxx_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val)
2214{
2215 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
2216 int addr = mv88e6xxx_port_to_phy_addr(ds, port);
2217 int ret;
2218
2219 if (addr < 0)
2220 return addr;
2221
Andrew Lunn3898c142015-05-06 01:09:53 +02002222 mutex_lock(&ps->smi_mutex);
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002223 ret = _mv88e6xxx_phy_write(ds, addr, regnum, val);
Andrew Lunn3898c142015-05-06 01:09:53 +02002224 mutex_unlock(&ps->smi_mutex);
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002225 return ret;
2226}
2227
2228int
2229mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int port, int regnum)
2230{
2231 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
2232 int addr = mv88e6xxx_port_to_phy_addr(ds, port);
2233 int ret;
2234
2235 if (addr < 0)
2236 return addr;
2237
Andrew Lunn3898c142015-05-06 01:09:53 +02002238 mutex_lock(&ps->smi_mutex);
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002239 ret = _mv88e6xxx_phy_read_indirect(ds, addr, regnum);
Andrew Lunn3898c142015-05-06 01:09:53 +02002240 mutex_unlock(&ps->smi_mutex);
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002241 return ret;
2242}
2243
2244int
2245mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int port, int regnum,
2246 u16 val)
2247{
2248 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
2249 int addr = mv88e6xxx_port_to_phy_addr(ds, port);
2250 int ret;
2251
2252 if (addr < 0)
2253 return addr;
2254
Andrew Lunn3898c142015-05-06 01:09:53 +02002255 mutex_lock(&ps->smi_mutex);
Andrew Lunnfd3a0ee2015-04-02 04:06:36 +02002256 ret = _mv88e6xxx_phy_write_indirect(ds, addr, regnum, val);
Andrew Lunn3898c142015-05-06 01:09:53 +02002257 mutex_unlock(&ps->smi_mutex);
Andrew Lunn491435852015-04-02 04:06:35 +02002258 return ret;
2259}
2260
Guenter Roeckc22995c2015-07-25 09:42:28 -07002261#ifdef CONFIG_NET_DSA_HWMON
2262
2263static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp)
2264{
2265 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
2266 int ret;
2267 int val;
2268
2269 *temp = 0;
2270
2271 mutex_lock(&ps->smi_mutex);
2272
2273 ret = _mv88e6xxx_phy_write(ds, 0x0, 0x16, 0x6);
2274 if (ret < 0)
2275 goto error;
2276
2277 /* Enable temperature sensor */
2278 ret = _mv88e6xxx_phy_read(ds, 0x0, 0x1a);
2279 if (ret < 0)
2280 goto error;
2281
2282 ret = _mv88e6xxx_phy_write(ds, 0x0, 0x1a, ret | (1 << 5));
2283 if (ret < 0)
2284 goto error;
2285
2286 /* Wait for temperature to stabilize */
2287 usleep_range(10000, 12000);
2288
2289 val = _mv88e6xxx_phy_read(ds, 0x0, 0x1a);
2290 if (val < 0) {
2291 ret = val;
2292 goto error;
2293 }
2294
2295 /* Disable temperature sensor */
2296 ret = _mv88e6xxx_phy_write(ds, 0x0, 0x1a, ret & ~(1 << 5));
2297 if (ret < 0)
2298 goto error;
2299
2300 *temp = ((val & 0x1f) - 5) * 5;
2301
2302error:
2303 _mv88e6xxx_phy_write(ds, 0x0, 0x16, 0x0);
2304 mutex_unlock(&ps->smi_mutex);
2305 return ret;
2306}
2307
2308static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp)
2309{
2310 int phy = mv88e6xxx_6320_family(ds) ? 3 : 0;
2311 int ret;
2312
2313 *temp = 0;
2314
2315 ret = mv88e6xxx_phy_page_read(ds, phy, 6, 27);
2316 if (ret < 0)
2317 return ret;
2318
2319 *temp = (ret & 0xff) - 25;
2320
2321 return 0;
2322}
2323
2324int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp)
2325{
2326 if (mv88e6xxx_6320_family(ds) || mv88e6xxx_6352_family(ds))
2327 return mv88e63xx_get_temp(ds, temp);
2328
2329 return mv88e61xx_get_temp(ds, temp);
2330}
2331
2332int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp)
2333{
2334 int phy = mv88e6xxx_6320_family(ds) ? 3 : 0;
2335 int ret;
2336
2337 if (!mv88e6xxx_6320_family(ds) && !mv88e6xxx_6352_family(ds))
2338 return -EOPNOTSUPP;
2339
2340 *temp = 0;
2341
2342 ret = mv88e6xxx_phy_page_read(ds, phy, 6, 26);
2343 if (ret < 0)
2344 return ret;
2345
2346 *temp = (((ret >> 8) & 0x1f) * 5) - 25;
2347
2348 return 0;
2349}
2350
2351int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp)
2352{
2353 int phy = mv88e6xxx_6320_family(ds) ? 3 : 0;
2354 int ret;
2355
2356 if (!mv88e6xxx_6320_family(ds) && !mv88e6xxx_6352_family(ds))
2357 return -EOPNOTSUPP;
2358
2359 ret = mv88e6xxx_phy_page_read(ds, phy, 6, 26);
2360 if (ret < 0)
2361 return ret;
2362 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
2363 return mv88e6xxx_phy_page_write(ds, phy, 6, 26,
2364 (ret & 0xe0ff) | (temp << 8));
2365}
2366
2367int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
2368{
2369 int phy = mv88e6xxx_6320_family(ds) ? 3 : 0;
2370 int ret;
2371
2372 if (!mv88e6xxx_6320_family(ds) && !mv88e6xxx_6352_family(ds))
2373 return -EOPNOTSUPP;
2374
2375 *alarm = false;
2376
2377 ret = mv88e6xxx_phy_page_read(ds, phy, 6, 26);
2378 if (ret < 0)
2379 return ret;
2380
2381 *alarm = !!(ret & 0x40);
2382
2383 return 0;
2384}
2385#endif /* CONFIG_NET_DSA_HWMON */
2386
Ben Hutchings98e67302011-11-25 14:36:19 +00002387static int __init mv88e6xxx_init(void)
2388{
2389#if IS_ENABLED(CONFIG_NET_DSA_MV88E6131)
2390 register_switch_driver(&mv88e6131_switch_driver);
2391#endif
2392#if IS_ENABLED(CONFIG_NET_DSA_MV88E6123_61_65)
2393 register_switch_driver(&mv88e6123_61_65_switch_driver);
2394#endif
Guenter Roeck3ad50cc2014-10-29 10:44:56 -07002395#if IS_ENABLED(CONFIG_NET_DSA_MV88E6352)
2396 register_switch_driver(&mv88e6352_switch_driver);
2397#endif
Andrew Lunn42f27252014-09-12 23:58:44 +02002398#if IS_ENABLED(CONFIG_NET_DSA_MV88E6171)
2399 register_switch_driver(&mv88e6171_switch_driver);
2400#endif
Ben Hutchings98e67302011-11-25 14:36:19 +00002401 return 0;
2402}
2403module_init(mv88e6xxx_init);
2404
2405static void __exit mv88e6xxx_cleanup(void)
2406{
Andrew Lunn42f27252014-09-12 23:58:44 +02002407#if IS_ENABLED(CONFIG_NET_DSA_MV88E6171)
2408 unregister_switch_driver(&mv88e6171_switch_driver);
2409#endif
Vivien Didelot4212b542015-05-01 10:43:52 -04002410#if IS_ENABLED(CONFIG_NET_DSA_MV88E6352)
2411 unregister_switch_driver(&mv88e6352_switch_driver);
2412#endif
Ben Hutchings98e67302011-11-25 14:36:19 +00002413#if IS_ENABLED(CONFIG_NET_DSA_MV88E6123_61_65)
2414 unregister_switch_driver(&mv88e6123_61_65_switch_driver);
2415#endif
2416#if IS_ENABLED(CONFIG_NET_DSA_MV88E6131)
2417 unregister_switch_driver(&mv88e6131_switch_driver);
2418#endif
2419}
2420module_exit(mv88e6xxx_cleanup);
Ben Hutchings3d825ed2011-11-25 14:37:16 +00002421
2422MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
2423MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
2424MODULE_LICENSE("GPL");