Bluetooth: hci_uart: Use generic functionality from Broadcom module
[linux/fpc-iii.git] / drivers / net / dsa / mv88e6xxx.c
blobfc8d3b6ffe8e0b35e64ed2aaa78b342a1b86f66a
1 /*
2 * net/dsa/mv88e6xxx.c - Marvell 88e6xxx switch chip support
3 * Copyright (c) 2008 Marvell Semiconductor
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 */
11 #include <linux/delay.h>
12 #include <linux/etherdevice.h>
13 #include <linux/if_bridge.h>
14 #include <linux/jiffies.h>
15 #include <linux/list.h>
16 #include <linux/module.h>
17 #include <linux/netdevice.h>
18 #include <linux/phy.h>
19 #include <net/dsa.h>
20 #include "mv88e6xxx.h"
22 /* If the switch's ADDR[4:0] strap pins are strapped to zero, it will
23 * use all 32 SMI bus addresses on its SMI bus, and all switch registers
24 * will be directly accessible on some {device address,register address}
25 * pair. If the ADDR[4:0] pins are not strapped to zero, the switch
26 * will only respond to SMI transactions to that specific address, and
27 * an indirect addressing mechanism needs to be used to access its
28 * registers.
30 static int mv88e6xxx_reg_wait_ready(struct mii_bus *bus, int sw_addr)
32 int ret;
33 int i;
35 for (i = 0; i < 16; i++) {
36 ret = mdiobus_read(bus, sw_addr, SMI_CMD);
37 if (ret < 0)
38 return ret;
40 if ((ret & SMI_CMD_BUSY) == 0)
41 return 0;
44 return -ETIMEDOUT;
47 int __mv88e6xxx_reg_read(struct mii_bus *bus, int sw_addr, int addr, int reg)
49 int ret;
51 if (sw_addr == 0)
52 return mdiobus_read(bus, addr, reg);
54 /* Wait for the bus to become free. */
55 ret = mv88e6xxx_reg_wait_ready(bus, sw_addr);
56 if (ret < 0)
57 return ret;
59 /* Transmit the read command. */
60 ret = mdiobus_write(bus, sw_addr, SMI_CMD,
61 SMI_CMD_OP_22_READ | (addr << 5) | reg);
62 if (ret < 0)
63 return ret;
65 /* Wait for the read command to complete. */
66 ret = mv88e6xxx_reg_wait_ready(bus, sw_addr);
67 if (ret < 0)
68 return ret;
70 /* Read the data. */
71 ret = mdiobus_read(bus, sw_addr, SMI_DATA);
72 if (ret < 0)
73 return ret;
75 return ret & 0xffff;
78 /* Must be called with SMI mutex held */
79 static int _mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg)
81 struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev);
82 int ret;
84 if (bus == NULL)
85 return -EINVAL;
87 ret = __mv88e6xxx_reg_read(bus, ds->pd->sw_addr, addr, reg);
88 if (ret < 0)
89 return ret;
91 dev_dbg(ds->master_dev, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
92 addr, reg, ret);
94 return ret;
97 int mv88e6xxx_reg_read(struct dsa_switch *ds, int addr, int reg)
99 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
100 int ret;
102 mutex_lock(&ps->smi_mutex);
103 ret = _mv88e6xxx_reg_read(ds, addr, reg);
104 mutex_unlock(&ps->smi_mutex);
106 return ret;
109 int __mv88e6xxx_reg_write(struct mii_bus *bus, int sw_addr, int addr,
110 int reg, u16 val)
112 int ret;
114 if (sw_addr == 0)
115 return mdiobus_write(bus, addr, reg, val);
117 /* Wait for the bus to become free. */
118 ret = mv88e6xxx_reg_wait_ready(bus, sw_addr);
119 if (ret < 0)
120 return ret;
122 /* Transmit the data to write. */
123 ret = mdiobus_write(bus, sw_addr, SMI_DATA, val);
124 if (ret < 0)
125 return ret;
127 /* Transmit the write command. */
128 ret = mdiobus_write(bus, sw_addr, SMI_CMD,
129 SMI_CMD_OP_22_WRITE | (addr << 5) | reg);
130 if (ret < 0)
131 return ret;
133 /* Wait for the write command to complete. */
134 ret = mv88e6xxx_reg_wait_ready(bus, sw_addr);
135 if (ret < 0)
136 return ret;
138 return 0;
141 /* Must be called with SMI mutex held */
142 static int _mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg,
143 u16 val)
145 struct mii_bus *bus = dsa_host_dev_to_mii_bus(ds->master_dev);
147 if (bus == NULL)
148 return -EINVAL;
150 dev_dbg(ds->master_dev, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
151 addr, reg, val);
153 return __mv88e6xxx_reg_write(bus, ds->pd->sw_addr, addr, reg, val);
156 int mv88e6xxx_reg_write(struct dsa_switch *ds, int addr, int reg, u16 val)
158 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
159 int ret;
161 mutex_lock(&ps->smi_mutex);
162 ret = _mv88e6xxx_reg_write(ds, addr, reg, val);
163 mutex_unlock(&ps->smi_mutex);
165 return ret;
168 int mv88e6xxx_config_prio(struct dsa_switch *ds)
170 /* Configure the IP ToS mapping registers. */
171 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_0, 0x0000);
172 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_1, 0x0000);
173 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_2, 0x5555);
174 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_3, 0x5555);
175 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_4, 0xaaaa);
176 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_5, 0xaaaa);
177 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_6, 0xffff);
178 REG_WRITE(REG_GLOBAL, GLOBAL_IP_PRI_7, 0xffff);
180 /* Configure the IEEE 802.1p priority mapping register. */
181 REG_WRITE(REG_GLOBAL, GLOBAL_IEEE_PRI, 0xfa41);
183 return 0;
186 int mv88e6xxx_set_addr_direct(struct dsa_switch *ds, u8 *addr)
188 REG_WRITE(REG_GLOBAL, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
189 REG_WRITE(REG_GLOBAL, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
190 REG_WRITE(REG_GLOBAL, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
192 return 0;
195 int mv88e6xxx_set_addr_indirect(struct dsa_switch *ds, u8 *addr)
197 int i;
198 int ret;
200 for (i = 0; i < 6; i++) {
201 int j;
203 /* Write the MAC address byte. */
204 REG_WRITE(REG_GLOBAL2, GLOBAL2_SWITCH_MAC,
205 GLOBAL2_SWITCH_MAC_BUSY | (i << 8) | addr[i]);
207 /* Wait for the write to complete. */
208 for (j = 0; j < 16; j++) {
209 ret = REG_READ(REG_GLOBAL2, GLOBAL2_SWITCH_MAC);
210 if ((ret & GLOBAL2_SWITCH_MAC_BUSY) == 0)
211 break;
213 if (j == 16)
214 return -ETIMEDOUT;
217 return 0;
220 /* Must be called with phy mutex held */
221 static int _mv88e6xxx_phy_read(struct dsa_switch *ds, int addr, int regnum)
223 if (addr >= 0)
224 return mv88e6xxx_reg_read(ds, addr, regnum);
225 return 0xffff;
228 /* Must be called with phy mutex held */
229 static int _mv88e6xxx_phy_write(struct dsa_switch *ds, int addr, int regnum,
230 u16 val)
232 if (addr >= 0)
233 return mv88e6xxx_reg_write(ds, addr, regnum, val);
234 return 0;
237 #ifdef CONFIG_NET_DSA_MV88E6XXX_NEED_PPU
238 static int mv88e6xxx_ppu_disable(struct dsa_switch *ds)
240 int ret;
241 unsigned long timeout;
243 ret = REG_READ(REG_GLOBAL, GLOBAL_CONTROL);
244 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL,
245 ret & ~GLOBAL_CONTROL_PPU_ENABLE);
247 timeout = jiffies + 1 * HZ;
248 while (time_before(jiffies, timeout)) {
249 ret = REG_READ(REG_GLOBAL, GLOBAL_STATUS);
250 usleep_range(1000, 2000);
251 if ((ret & GLOBAL_STATUS_PPU_MASK) !=
252 GLOBAL_STATUS_PPU_POLLING)
253 return 0;
256 return -ETIMEDOUT;
259 static int mv88e6xxx_ppu_enable(struct dsa_switch *ds)
261 int ret;
262 unsigned long timeout;
264 ret = REG_READ(REG_GLOBAL, GLOBAL_CONTROL);
265 REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL, ret | GLOBAL_CONTROL_PPU_ENABLE);
267 timeout = jiffies + 1 * HZ;
268 while (time_before(jiffies, timeout)) {
269 ret = REG_READ(REG_GLOBAL, GLOBAL_STATUS);
270 usleep_range(1000, 2000);
271 if ((ret & GLOBAL_STATUS_PPU_MASK) ==
272 GLOBAL_STATUS_PPU_POLLING)
273 return 0;
276 return -ETIMEDOUT;
279 static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
281 struct mv88e6xxx_priv_state *ps;
283 ps = container_of(ugly, struct mv88e6xxx_priv_state, ppu_work);
284 if (mutex_trylock(&ps->ppu_mutex)) {
285 struct dsa_switch *ds = ((struct dsa_switch *)ps) - 1;
287 if (mv88e6xxx_ppu_enable(ds) == 0)
288 ps->ppu_disabled = 0;
289 mutex_unlock(&ps->ppu_mutex);
293 static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
295 struct mv88e6xxx_priv_state *ps = (void *)_ps;
297 schedule_work(&ps->ppu_work);
300 static int mv88e6xxx_ppu_access_get(struct dsa_switch *ds)
302 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
303 int ret;
305 mutex_lock(&ps->ppu_mutex);
307 /* If the PHY polling unit is enabled, disable it so that
308 * we can access the PHY registers. If it was already
309 * disabled, cancel the timer that is going to re-enable
310 * it.
312 if (!ps->ppu_disabled) {
313 ret = mv88e6xxx_ppu_disable(ds);
314 if (ret < 0) {
315 mutex_unlock(&ps->ppu_mutex);
316 return ret;
318 ps->ppu_disabled = 1;
319 } else {
320 del_timer(&ps->ppu_timer);
321 ret = 0;
324 return ret;
327 static void mv88e6xxx_ppu_access_put(struct dsa_switch *ds)
329 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
331 /* Schedule a timer to re-enable the PHY polling unit. */
332 mod_timer(&ps->ppu_timer, jiffies + msecs_to_jiffies(10));
333 mutex_unlock(&ps->ppu_mutex);
336 void mv88e6xxx_ppu_state_init(struct dsa_switch *ds)
338 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
340 mutex_init(&ps->ppu_mutex);
341 INIT_WORK(&ps->ppu_work, mv88e6xxx_ppu_reenable_work);
342 init_timer(&ps->ppu_timer);
343 ps->ppu_timer.data = (unsigned long)ps;
344 ps->ppu_timer.function = mv88e6xxx_ppu_reenable_timer;
347 int mv88e6xxx_phy_read_ppu(struct dsa_switch *ds, int addr, int regnum)
349 int ret;
351 ret = mv88e6xxx_ppu_access_get(ds);
352 if (ret >= 0) {
353 ret = mv88e6xxx_reg_read(ds, addr, regnum);
354 mv88e6xxx_ppu_access_put(ds);
357 return ret;
360 int mv88e6xxx_phy_write_ppu(struct dsa_switch *ds, int addr,
361 int regnum, u16 val)
363 int ret;
365 ret = mv88e6xxx_ppu_access_get(ds);
366 if (ret >= 0) {
367 ret = mv88e6xxx_reg_write(ds, addr, regnum, val);
368 mv88e6xxx_ppu_access_put(ds);
371 return ret;
373 #endif
375 void mv88e6xxx_poll_link(struct dsa_switch *ds)
377 int i;
379 for (i = 0; i < DSA_MAX_PORTS; i++) {
380 struct net_device *dev;
381 int uninitialized_var(port_status);
382 int link;
383 int speed;
384 int duplex;
385 int fc;
387 dev = ds->ports[i];
388 if (dev == NULL)
389 continue;
391 link = 0;
392 if (dev->flags & IFF_UP) {
393 port_status = mv88e6xxx_reg_read(ds, REG_PORT(i),
394 PORT_STATUS);
395 if (port_status < 0)
396 continue;
398 link = !!(port_status & PORT_STATUS_LINK);
401 if (!link) {
402 if (netif_carrier_ok(dev)) {
403 netdev_info(dev, "link down\n");
404 netif_carrier_off(dev);
406 continue;
409 switch (port_status & PORT_STATUS_SPEED_MASK) {
410 case PORT_STATUS_SPEED_10:
411 speed = 10;
412 break;
413 case PORT_STATUS_SPEED_100:
414 speed = 100;
415 break;
416 case PORT_STATUS_SPEED_1000:
417 speed = 1000;
418 break;
419 default:
420 speed = -1;
421 break;
423 duplex = (port_status & PORT_STATUS_DUPLEX) ? 1 : 0;
424 fc = (port_status & PORT_STATUS_PAUSE_EN) ? 1 : 0;
426 if (!netif_carrier_ok(dev)) {
427 netdev_info(dev,
428 "link up, %d Mb/s, %s duplex, flow control %sabled\n",
429 speed,
430 duplex ? "full" : "half",
431 fc ? "en" : "dis");
432 netif_carrier_on(dev);
437 static bool mv88e6xxx_6352_family(struct dsa_switch *ds)
439 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
441 switch (ps->id) {
442 case PORT_SWITCH_ID_6352:
443 case PORT_SWITCH_ID_6172:
444 case PORT_SWITCH_ID_6176:
445 return true;
447 return false;
450 static int mv88e6xxx_stats_wait(struct dsa_switch *ds)
452 int ret;
453 int i;
455 for (i = 0; i < 10; i++) {
456 ret = REG_READ(REG_GLOBAL, GLOBAL_STATS_OP);
457 if ((ret & GLOBAL_STATS_OP_BUSY) == 0)
458 return 0;
461 return -ETIMEDOUT;
464 static int mv88e6xxx_stats_snapshot(struct dsa_switch *ds, int port)
466 int ret;
468 if (mv88e6xxx_6352_family(ds))
469 port = (port + 1) << 5;
471 /* Snapshot the hardware statistics counters for this port. */
472 REG_WRITE(REG_GLOBAL, GLOBAL_STATS_OP,
473 GLOBAL_STATS_OP_CAPTURE_PORT |
474 GLOBAL_STATS_OP_HIST_RX_TX | port);
476 /* Wait for the snapshotting to complete. */
477 ret = mv88e6xxx_stats_wait(ds);
478 if (ret < 0)
479 return ret;
481 return 0;
484 static void mv88e6xxx_stats_read(struct dsa_switch *ds, int stat, u32 *val)
486 u32 _val;
487 int ret;
489 *val = 0;
491 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_STATS_OP,
492 GLOBAL_STATS_OP_READ_CAPTURED |
493 GLOBAL_STATS_OP_HIST_RX_TX | stat);
494 if (ret < 0)
495 return;
497 ret = mv88e6xxx_stats_wait(ds);
498 if (ret < 0)
499 return;
501 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_STATS_COUNTER_32);
502 if (ret < 0)
503 return;
505 _val = ret << 16;
507 ret = mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_STATS_COUNTER_01);
508 if (ret < 0)
509 return;
511 *val = _val | ret;
514 static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
515 { "in_good_octets", 8, 0x00, },
516 { "in_bad_octets", 4, 0x02, },
517 { "in_unicast", 4, 0x04, },
518 { "in_broadcasts", 4, 0x06, },
519 { "in_multicasts", 4, 0x07, },
520 { "in_pause", 4, 0x16, },
521 { "in_undersize", 4, 0x18, },
522 { "in_fragments", 4, 0x19, },
523 { "in_oversize", 4, 0x1a, },
524 { "in_jabber", 4, 0x1b, },
525 { "in_rx_error", 4, 0x1c, },
526 { "in_fcs_error", 4, 0x1d, },
527 { "out_octets", 8, 0x0e, },
528 { "out_unicast", 4, 0x10, },
529 { "out_broadcasts", 4, 0x13, },
530 { "out_multicasts", 4, 0x12, },
531 { "out_pause", 4, 0x15, },
532 { "excessive", 4, 0x11, },
533 { "collisions", 4, 0x1e, },
534 { "deferred", 4, 0x05, },
535 { "single", 4, 0x14, },
536 { "multiple", 4, 0x17, },
537 { "out_fcs_error", 4, 0x03, },
538 { "late", 4, 0x1f, },
539 { "hist_64bytes", 4, 0x08, },
540 { "hist_65_127bytes", 4, 0x09, },
541 { "hist_128_255bytes", 4, 0x0a, },
542 { "hist_256_511bytes", 4, 0x0b, },
543 { "hist_512_1023bytes", 4, 0x0c, },
544 { "hist_1024_max_bytes", 4, 0x0d, },
545 /* Not all devices have the following counters */
546 { "sw_in_discards", 4, 0x110, },
547 { "sw_in_filtered", 2, 0x112, },
548 { "sw_out_filtered", 2, 0x113, },
552 static bool have_sw_in_discards(struct dsa_switch *ds)
554 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
556 switch (ps->id) {
557 case PORT_SWITCH_ID_6095: case PORT_SWITCH_ID_6161:
558 case PORT_SWITCH_ID_6165: case PORT_SWITCH_ID_6171:
559 case PORT_SWITCH_ID_6172: case PORT_SWITCH_ID_6176:
560 case PORT_SWITCH_ID_6182: case PORT_SWITCH_ID_6185:
561 case PORT_SWITCH_ID_6352:
562 return true;
563 default:
564 return false;
568 static void _mv88e6xxx_get_strings(struct dsa_switch *ds,
569 int nr_stats,
570 struct mv88e6xxx_hw_stat *stats,
571 int port, uint8_t *data)
573 int i;
575 for (i = 0; i < nr_stats; i++) {
576 memcpy(data + i * ETH_GSTRING_LEN,
577 stats[i].string, ETH_GSTRING_LEN);
581 static void _mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds,
582 int nr_stats,
583 struct mv88e6xxx_hw_stat *stats,
584 int port, uint64_t *data)
586 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
587 int ret;
588 int i;
590 mutex_lock(&ps->stats_mutex);
592 ret = mv88e6xxx_stats_snapshot(ds, port);
593 if (ret < 0) {
594 mutex_unlock(&ps->stats_mutex);
595 return;
598 /* Read each of the counters. */
599 for (i = 0; i < nr_stats; i++) {
600 struct mv88e6xxx_hw_stat *s = stats + i;
601 u32 low;
602 u32 high = 0;
604 if (s->reg >= 0x100) {
605 int ret;
607 ret = mv88e6xxx_reg_read(ds, REG_PORT(port),
608 s->reg - 0x100);
609 if (ret < 0)
610 goto error;
611 low = ret;
612 if (s->sizeof_stat == 4) {
613 ret = mv88e6xxx_reg_read(ds, REG_PORT(port),
614 s->reg - 0x100 + 1);
615 if (ret < 0)
616 goto error;
617 high = ret;
619 data[i] = (((u64)high) << 16) | low;
620 continue;
622 mv88e6xxx_stats_read(ds, s->reg, &low);
623 if (s->sizeof_stat == 8)
624 mv88e6xxx_stats_read(ds, s->reg + 1, &high);
626 data[i] = (((u64)high) << 32) | low;
628 error:
629 mutex_unlock(&ps->stats_mutex);
632 /* All the statistics in the table */
633 void
634 mv88e6xxx_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
636 if (have_sw_in_discards(ds))
637 _mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6xxx_hw_stats),
638 mv88e6xxx_hw_stats, port, data);
639 else
640 _mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6xxx_hw_stats) - 3,
641 mv88e6xxx_hw_stats, port, data);
644 int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
646 if (have_sw_in_discards(ds))
647 return ARRAY_SIZE(mv88e6xxx_hw_stats);
648 return ARRAY_SIZE(mv88e6xxx_hw_stats) - 3;
651 void
652 mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds,
653 int port, uint64_t *data)
655 if (have_sw_in_discards(ds))
656 _mv88e6xxx_get_ethtool_stats(
657 ds, ARRAY_SIZE(mv88e6xxx_hw_stats),
658 mv88e6xxx_hw_stats, port, data);
659 else
660 _mv88e6xxx_get_ethtool_stats(
661 ds, ARRAY_SIZE(mv88e6xxx_hw_stats) - 3,
662 mv88e6xxx_hw_stats, port, data);
665 int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
667 return 32 * sizeof(u16);
670 void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
671 struct ethtool_regs *regs, void *_p)
673 u16 *p = _p;
674 int i;
676 regs->version = 0;
678 memset(p, 0xff, 32 * sizeof(u16));
680 for (i = 0; i < 32; i++) {
681 int ret;
683 ret = mv88e6xxx_reg_read(ds, REG_PORT(port), i);
684 if (ret >= 0)
685 p[i] = ret;
689 #ifdef CONFIG_NET_DSA_HWMON
691 int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp)
693 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
694 int ret;
695 int val;
697 *temp = 0;
699 mutex_lock(&ps->phy_mutex);
701 ret = _mv88e6xxx_phy_write(ds, 0x0, 0x16, 0x6);
702 if (ret < 0)
703 goto error;
705 /* Enable temperature sensor */
706 ret = _mv88e6xxx_phy_read(ds, 0x0, 0x1a);
707 if (ret < 0)
708 goto error;
710 ret = _mv88e6xxx_phy_write(ds, 0x0, 0x1a, ret | (1 << 5));
711 if (ret < 0)
712 goto error;
714 /* Wait for temperature to stabilize */
715 usleep_range(10000, 12000);
717 val = _mv88e6xxx_phy_read(ds, 0x0, 0x1a);
718 if (val < 0) {
719 ret = val;
720 goto error;
723 /* Disable temperature sensor */
724 ret = _mv88e6xxx_phy_write(ds, 0x0, 0x1a, ret & ~(1 << 5));
725 if (ret < 0)
726 goto error;
728 *temp = ((val & 0x1f) - 5) * 5;
730 error:
731 _mv88e6xxx_phy_write(ds, 0x0, 0x16, 0x0);
732 mutex_unlock(&ps->phy_mutex);
733 return ret;
735 #endif /* CONFIG_NET_DSA_HWMON */
737 static int mv88e6xxx_wait(struct dsa_switch *ds, int reg, int offset, u16 mask)
739 unsigned long timeout = jiffies + HZ / 10;
741 while (time_before(jiffies, timeout)) {
742 int ret;
744 ret = REG_READ(reg, offset);
745 if (!(ret & mask))
746 return 0;
748 usleep_range(1000, 2000);
750 return -ETIMEDOUT;
753 int mv88e6xxx_phy_wait(struct dsa_switch *ds)
755 return mv88e6xxx_wait(ds, REG_GLOBAL2, GLOBAL2_SMI_OP,
756 GLOBAL2_SMI_OP_BUSY);
759 int mv88e6xxx_eeprom_load_wait(struct dsa_switch *ds)
761 return mv88e6xxx_wait(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
762 GLOBAL2_EEPROM_OP_LOAD);
765 int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds)
767 return mv88e6xxx_wait(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP,
768 GLOBAL2_EEPROM_OP_BUSY);
771 /* Must be called with SMI lock held */
772 static int _mv88e6xxx_wait(struct dsa_switch *ds, int reg, int offset, u16 mask)
774 unsigned long timeout = jiffies + HZ / 10;
776 while (time_before(jiffies, timeout)) {
777 int ret;
779 ret = _mv88e6xxx_reg_read(ds, reg, offset);
780 if (ret < 0)
781 return ret;
782 if (!(ret & mask))
783 return 0;
785 usleep_range(1000, 2000);
787 return -ETIMEDOUT;
790 /* Must be called with SMI lock held */
791 static int _mv88e6xxx_atu_wait(struct dsa_switch *ds)
793 return _mv88e6xxx_wait(ds, REG_GLOBAL, GLOBAL_ATU_OP,
794 GLOBAL_ATU_OP_BUSY);
797 /* Must be called with phy mutex held */
798 static int _mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr,
799 int regnum)
801 int ret;
803 REG_WRITE(REG_GLOBAL2, GLOBAL2_SMI_OP,
804 GLOBAL2_SMI_OP_22_READ | (addr << 5) | regnum);
806 ret = mv88e6xxx_phy_wait(ds);
807 if (ret < 0)
808 return ret;
810 return REG_READ(REG_GLOBAL2, GLOBAL2_SMI_DATA);
813 /* Must be called with phy mutex held */
814 static int _mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr,
815 int regnum, u16 val)
817 REG_WRITE(REG_GLOBAL2, GLOBAL2_SMI_DATA, val);
818 REG_WRITE(REG_GLOBAL2, GLOBAL2_SMI_OP,
819 GLOBAL2_SMI_OP_22_WRITE | (addr << 5) | regnum);
821 return mv88e6xxx_phy_wait(ds);
824 int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
826 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
827 int reg;
829 mutex_lock(&ps->phy_mutex);
831 reg = _mv88e6xxx_phy_read_indirect(ds, port, 16);
832 if (reg < 0)
833 goto out;
835 e->eee_enabled = !!(reg & 0x0200);
836 e->tx_lpi_enabled = !!(reg & 0x0100);
838 reg = mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_STATUS);
839 if (reg < 0)
840 goto out;
842 e->eee_active = !!(reg & PORT_STATUS_EEE);
843 reg = 0;
845 out:
846 mutex_unlock(&ps->phy_mutex);
847 return reg;
850 int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
851 struct phy_device *phydev, struct ethtool_eee *e)
853 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
854 int reg;
855 int ret;
857 mutex_lock(&ps->phy_mutex);
859 ret = _mv88e6xxx_phy_read_indirect(ds, port, 16);
860 if (ret < 0)
861 goto out;
863 reg = ret & ~0x0300;
864 if (e->eee_enabled)
865 reg |= 0x0200;
866 if (e->tx_lpi_enabled)
867 reg |= 0x0100;
869 ret = _mv88e6xxx_phy_write_indirect(ds, port, 16, reg);
870 out:
871 mutex_unlock(&ps->phy_mutex);
873 return ret;
876 static int _mv88e6xxx_atu_cmd(struct dsa_switch *ds, int fid, u16 cmd)
878 int ret;
880 ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, 0x01, fid);
881 if (ret < 0)
882 return ret;
884 ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_OP, cmd);
885 if (ret < 0)
886 return ret;
888 return _mv88e6xxx_atu_wait(ds);
891 static int _mv88e6xxx_flush_fid(struct dsa_switch *ds, int fid)
893 int ret;
895 ret = _mv88e6xxx_atu_wait(ds);
896 if (ret < 0)
897 return ret;
899 return _mv88e6xxx_atu_cmd(ds, fid, GLOBAL_ATU_OP_FLUSH_NON_STATIC_DB);
902 static int mv88e6xxx_set_port_state(struct dsa_switch *ds, int port, u8 state)
904 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
905 int reg, ret;
906 u8 oldstate;
908 mutex_lock(&ps->smi_mutex);
910 reg = _mv88e6xxx_reg_read(ds, REG_PORT(port), PORT_CONTROL);
911 if (reg < 0)
912 goto abort;
914 oldstate = reg & PORT_CONTROL_STATE_MASK;
915 if (oldstate != state) {
916 /* Flush forwarding database if we're moving a port
917 * from Learning or Forwarding state to Disabled or
918 * Blocking or Listening state.
920 if (oldstate >= PORT_CONTROL_STATE_LEARNING &&
921 state <= PORT_CONTROL_STATE_BLOCKING) {
922 ret = _mv88e6xxx_flush_fid(ds, ps->fid[port]);
923 if (ret)
924 goto abort;
926 reg = (reg & ~PORT_CONTROL_STATE_MASK) | state;
927 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_CONTROL,
928 reg);
931 abort:
932 mutex_unlock(&ps->smi_mutex);
933 return ret;
936 /* Must be called with smi lock held */
937 static int _mv88e6xxx_update_port_config(struct dsa_switch *ds, int port)
939 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
940 u8 fid = ps->fid[port];
941 u16 reg = fid << 12;
943 if (dsa_is_cpu_port(ds, port))
944 reg |= ds->phys_port_mask;
945 else
946 reg |= (ps->bridge_mask[fid] |
947 (1 << dsa_upstream_port(ds))) & ~(1 << port);
949 return _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_BASE_VLAN, reg);
952 /* Must be called with smi lock held */
953 static int _mv88e6xxx_update_bridge_config(struct dsa_switch *ds, int fid)
955 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
956 int port;
957 u32 mask;
958 int ret;
960 mask = ds->phys_port_mask;
961 while (mask) {
962 port = __ffs(mask);
963 mask &= ~(1 << port);
964 if (ps->fid[port] != fid)
965 continue;
967 ret = _mv88e6xxx_update_port_config(ds, port);
968 if (ret)
969 return ret;
972 return _mv88e6xxx_flush_fid(ds, fid);
975 /* Bridge handling functions */
977 int mv88e6xxx_join_bridge(struct dsa_switch *ds, int port, u32 br_port_mask)
979 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
980 int ret = 0;
981 u32 nmask;
982 int fid;
984 /* If the bridge group is not empty, join that group.
985 * Otherwise create a new group.
987 fid = ps->fid[port];
988 nmask = br_port_mask & ~(1 << port);
989 if (nmask)
990 fid = ps->fid[__ffs(nmask)];
992 nmask = ps->bridge_mask[fid] | (1 << port);
993 if (nmask != br_port_mask) {
994 netdev_err(ds->ports[port],
995 "join: Bridge port mask mismatch fid=%d mask=0x%x expected 0x%x\n",
996 fid, br_port_mask, nmask);
997 return -EINVAL;
1000 mutex_lock(&ps->smi_mutex);
1002 ps->bridge_mask[fid] = br_port_mask;
1004 if (fid != ps->fid[port]) {
1005 ps->fid_mask |= 1 << ps->fid[port];
1006 ps->fid[port] = fid;
1007 ret = _mv88e6xxx_update_bridge_config(ds, fid);
1010 mutex_unlock(&ps->smi_mutex);
1012 return ret;
1015 int mv88e6xxx_leave_bridge(struct dsa_switch *ds, int port, u32 br_port_mask)
1017 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1018 u8 fid, newfid;
1019 int ret;
1021 fid = ps->fid[port];
1023 if (ps->bridge_mask[fid] != br_port_mask) {
1024 netdev_err(ds->ports[port],
1025 "leave: Bridge port mask mismatch fid=%d mask=0x%x expected 0x%x\n",
1026 fid, br_port_mask, ps->bridge_mask[fid]);
1027 return -EINVAL;
1030 /* If the port was the last port of a bridge, we are done.
1031 * Otherwise assign a new fid to the port, and fix up
1032 * the bridge configuration.
1034 if (br_port_mask == (1 << port))
1035 return 0;
1037 mutex_lock(&ps->smi_mutex);
1039 newfid = __ffs(ps->fid_mask);
1040 ps->fid[port] = newfid;
1041 ps->fid_mask &= (1 << newfid);
1042 ps->bridge_mask[fid] &= ~(1 << port);
1043 ps->bridge_mask[newfid] = 1 << port;
1045 ret = _mv88e6xxx_update_bridge_config(ds, fid);
1046 if (!ret)
1047 ret = _mv88e6xxx_update_bridge_config(ds, newfid);
1049 mutex_unlock(&ps->smi_mutex);
1051 return ret;
1054 int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state)
1056 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1057 int stp_state;
1059 switch (state) {
1060 case BR_STATE_DISABLED:
1061 stp_state = PORT_CONTROL_STATE_DISABLED;
1062 break;
1063 case BR_STATE_BLOCKING:
1064 case BR_STATE_LISTENING:
1065 stp_state = PORT_CONTROL_STATE_BLOCKING;
1066 break;
1067 case BR_STATE_LEARNING:
1068 stp_state = PORT_CONTROL_STATE_LEARNING;
1069 break;
1070 case BR_STATE_FORWARDING:
1071 default:
1072 stp_state = PORT_CONTROL_STATE_FORWARDING;
1073 break;
1076 netdev_dbg(ds->ports[port], "port state %d [%d]\n", state, stp_state);
1078 /* mv88e6xxx_port_stp_update may be called with softirqs disabled,
1079 * so we can not update the port state directly but need to schedule it.
1081 ps->port_state[port] = stp_state;
1082 set_bit(port, &ps->port_state_update_mask);
1083 schedule_work(&ps->bridge_work);
1085 return 0;
1088 static int __mv88e6xxx_write_addr(struct dsa_switch *ds,
1089 const unsigned char *addr)
1091 int i, ret;
1093 for (i = 0; i < 3; i++) {
1094 ret = _mv88e6xxx_reg_write(
1095 ds, REG_GLOBAL, GLOBAL_ATU_MAC_01 + i,
1096 (addr[i * 2] << 8) | addr[i * 2 + 1]);
1097 if (ret < 0)
1098 return ret;
1101 return 0;
1104 static int __mv88e6xxx_read_addr(struct dsa_switch *ds, unsigned char *addr)
1106 int i, ret;
1108 for (i = 0; i < 3; i++) {
1109 ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL,
1110 GLOBAL_ATU_MAC_01 + i);
1111 if (ret < 0)
1112 return ret;
1113 addr[i * 2] = ret >> 8;
1114 addr[i * 2 + 1] = ret & 0xff;
1117 return 0;
1120 static int __mv88e6xxx_port_fdb_cmd(struct dsa_switch *ds, int port,
1121 const unsigned char *addr, int state)
1123 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1124 u8 fid = ps->fid[port];
1125 int ret;
1127 ret = _mv88e6xxx_atu_wait(ds);
1128 if (ret < 0)
1129 return ret;
1131 ret = __mv88e6xxx_write_addr(ds, addr);
1132 if (ret < 0)
1133 return ret;
1135 ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_ATU_DATA,
1136 (0x10 << port) | state);
1137 if (ret)
1138 return ret;
1140 ret = _mv88e6xxx_atu_cmd(ds, fid, GLOBAL_ATU_OP_LOAD_DB);
1142 return ret;
1145 int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
1146 const unsigned char *addr, u16 vid)
1148 int state = is_multicast_ether_addr(addr) ?
1149 GLOBAL_ATU_DATA_STATE_MC_STATIC :
1150 GLOBAL_ATU_DATA_STATE_UC_STATIC;
1151 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1152 int ret;
1154 mutex_lock(&ps->smi_mutex);
1155 ret = __mv88e6xxx_port_fdb_cmd(ds, port, addr, state);
1156 mutex_unlock(&ps->smi_mutex);
1158 return ret;
1161 int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
1162 const unsigned char *addr, u16 vid)
1164 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1165 int ret;
1167 mutex_lock(&ps->smi_mutex);
1168 ret = __mv88e6xxx_port_fdb_cmd(ds, port, addr,
1169 GLOBAL_ATU_DATA_STATE_UNUSED);
1170 mutex_unlock(&ps->smi_mutex);
1172 return ret;
1175 static int __mv88e6xxx_port_getnext(struct dsa_switch *ds, int port,
1176 unsigned char *addr, bool *is_static)
1178 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1179 u8 fid = ps->fid[port];
1180 int ret, state;
1182 ret = _mv88e6xxx_atu_wait(ds);
1183 if (ret < 0)
1184 return ret;
1186 ret = __mv88e6xxx_write_addr(ds, addr);
1187 if (ret < 0)
1188 return ret;
1190 do {
1191 ret = _mv88e6xxx_atu_cmd(ds, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
1192 if (ret < 0)
1193 return ret;
1195 ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_ATU_DATA);
1196 if (ret < 0)
1197 return ret;
1198 state = ret & GLOBAL_ATU_DATA_STATE_MASK;
1199 if (state == GLOBAL_ATU_DATA_STATE_UNUSED)
1200 return -ENOENT;
1201 } while (!(((ret >> 4) & 0xff) & (1 << port)));
1203 ret = __mv88e6xxx_read_addr(ds, addr);
1204 if (ret < 0)
1205 return ret;
1207 *is_static = state == (is_multicast_ether_addr(addr) ?
1208 GLOBAL_ATU_DATA_STATE_MC_STATIC :
1209 GLOBAL_ATU_DATA_STATE_UC_STATIC);
1211 return 0;
1214 /* get next entry for port */
1215 int mv88e6xxx_port_fdb_getnext(struct dsa_switch *ds, int port,
1216 unsigned char *addr, bool *is_static)
1218 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1219 int ret;
1221 mutex_lock(&ps->smi_mutex);
1222 ret = __mv88e6xxx_port_getnext(ds, port, addr, is_static);
1223 mutex_unlock(&ps->smi_mutex);
1225 return ret;
1228 static void mv88e6xxx_bridge_work(struct work_struct *work)
1230 struct mv88e6xxx_priv_state *ps;
1231 struct dsa_switch *ds;
1232 int port;
1234 ps = container_of(work, struct mv88e6xxx_priv_state, bridge_work);
1235 ds = ((struct dsa_switch *)ps) - 1;
1237 while (ps->port_state_update_mask) {
1238 port = __ffs(ps->port_state_update_mask);
1239 clear_bit(port, &ps->port_state_update_mask);
1240 mv88e6xxx_set_port_state(ds, port, ps->port_state[port]);
1244 int mv88e6xxx_setup_port_common(struct dsa_switch *ds, int port)
1246 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1247 int ret, fid;
1249 mutex_lock(&ps->smi_mutex);
1251 /* Port Control 1: disable trunking, disable sending
1252 * learning messages to this port.
1254 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), PORT_DEFAULT_VLAN,
1255 0x0000);
1256 if (ret)
1257 goto abort;
1259 /* Port based VLAN map: give each port its own address
1260 * database, allow the CPU port to talk to each of the 'real'
1261 * ports, and allow each of the 'real' ports to only talk to
1262 * the upstream port.
1264 fid = __ffs(ps->fid_mask);
1265 ps->fid[port] = fid;
1266 ps->fid_mask &= ~(1 << fid);
1268 if (!dsa_is_cpu_port(ds, port))
1269 ps->bridge_mask[fid] = 1 << port;
1271 ret = _mv88e6xxx_update_port_config(ds, port);
1272 if (ret)
1273 goto abort;
1275 /* Default VLAN ID and priority: don't set a default VLAN
1276 * ID, and set the default packet priority to zero.
1278 ret = _mv88e6xxx_reg_write(ds, REG_PORT(port), 0x07, 0x0000);
1279 abort:
1280 mutex_unlock(&ps->smi_mutex);
1281 return ret;
1284 int mv88e6xxx_setup_common(struct dsa_switch *ds)
1286 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1288 mutex_init(&ps->smi_mutex);
1289 mutex_init(&ps->stats_mutex);
1290 mutex_init(&ps->phy_mutex);
1292 ps->id = REG_READ(REG_PORT(0), PORT_SWITCH_ID) & 0xfff0;
1294 ps->fid_mask = (1 << DSA_MAX_PORTS) - 1;
1296 INIT_WORK(&ps->bridge_work, mv88e6xxx_bridge_work);
1298 return 0;
1301 int mv88e6xxx_switch_reset(struct dsa_switch *ds, bool ppu_active)
1303 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1304 u16 is_reset = (ppu_active ? 0x8800 : 0xc800);
1305 unsigned long timeout;
1306 int ret;
1307 int i;
1309 /* Set all ports to the disabled state. */
1310 for (i = 0; i < ps->num_ports; i++) {
1311 ret = REG_READ(REG_PORT(i), PORT_CONTROL);
1312 REG_WRITE(REG_PORT(i), PORT_CONTROL, ret & 0xfffc);
1315 /* Wait for transmit queues to drain. */
1316 usleep_range(2000, 4000);
1318 /* Reset the switch. Keep the PPU active if requested. The PPU
1319 * needs to be active to support indirect phy register access
1320 * through global registers 0x18 and 0x19.
1322 if (ppu_active)
1323 REG_WRITE(REG_GLOBAL, 0x04, 0xc000);
1324 else
1325 REG_WRITE(REG_GLOBAL, 0x04, 0xc400);
1327 /* Wait up to one second for reset to complete. */
1328 timeout = jiffies + 1 * HZ;
1329 while (time_before(jiffies, timeout)) {
1330 ret = REG_READ(REG_GLOBAL, 0x00);
1331 if ((ret & is_reset) == is_reset)
1332 break;
1333 usleep_range(1000, 2000);
1335 if (time_after(jiffies, timeout))
1336 return -ETIMEDOUT;
1338 return 0;
1341 int mv88e6xxx_phy_page_read(struct dsa_switch *ds, int port, int page, int reg)
1343 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1344 int ret;
1346 mutex_lock(&ps->phy_mutex);
1347 ret = _mv88e6xxx_phy_write_indirect(ds, port, 0x16, page);
1348 if (ret < 0)
1349 goto error;
1350 ret = _mv88e6xxx_phy_read_indirect(ds, port, reg);
1351 error:
1352 _mv88e6xxx_phy_write_indirect(ds, port, 0x16, 0x0);
1353 mutex_unlock(&ps->phy_mutex);
1354 return ret;
1357 int mv88e6xxx_phy_page_write(struct dsa_switch *ds, int port, int page,
1358 int reg, int val)
1360 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1361 int ret;
1363 mutex_lock(&ps->phy_mutex);
1364 ret = _mv88e6xxx_phy_write_indirect(ds, port, 0x16, page);
1365 if (ret < 0)
1366 goto error;
1368 ret = _mv88e6xxx_phy_write_indirect(ds, port, reg, val);
1369 error:
1370 _mv88e6xxx_phy_write_indirect(ds, port, 0x16, 0x0);
1371 mutex_unlock(&ps->phy_mutex);
1372 return ret;
1375 static int mv88e6xxx_port_to_phy_addr(struct dsa_switch *ds, int port)
1377 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1379 if (port >= 0 && port < ps->num_ports)
1380 return port;
1381 return -EINVAL;
1385 mv88e6xxx_phy_read(struct dsa_switch *ds, int port, int regnum)
1387 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1388 int addr = mv88e6xxx_port_to_phy_addr(ds, port);
1389 int ret;
1391 if (addr < 0)
1392 return addr;
1394 mutex_lock(&ps->phy_mutex);
1395 ret = _mv88e6xxx_phy_read(ds, addr, regnum);
1396 mutex_unlock(&ps->phy_mutex);
1397 return ret;
1401 mv88e6xxx_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val)
1403 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1404 int addr = mv88e6xxx_port_to_phy_addr(ds, port);
1405 int ret;
1407 if (addr < 0)
1408 return addr;
1410 mutex_lock(&ps->phy_mutex);
1411 ret = _mv88e6xxx_phy_write(ds, addr, regnum, val);
1412 mutex_unlock(&ps->phy_mutex);
1413 return ret;
1417 mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int port, int regnum)
1419 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1420 int addr = mv88e6xxx_port_to_phy_addr(ds, port);
1421 int ret;
1423 if (addr < 0)
1424 return addr;
1426 mutex_lock(&ps->phy_mutex);
1427 ret = _mv88e6xxx_phy_read_indirect(ds, addr, regnum);
1428 mutex_unlock(&ps->phy_mutex);
1429 return ret;
1433 mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int port, int regnum,
1434 u16 val)
1436 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
1437 int addr = mv88e6xxx_port_to_phy_addr(ds, port);
1438 int ret;
1440 if (addr < 0)
1441 return addr;
1443 mutex_lock(&ps->phy_mutex);
1444 ret = _mv88e6xxx_phy_write_indirect(ds, addr, regnum, val);
1445 mutex_unlock(&ps->phy_mutex);
1446 return ret;
1449 static int __init mv88e6xxx_init(void)
1451 #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131)
1452 register_switch_driver(&mv88e6131_switch_driver);
1453 #endif
1454 #if IS_ENABLED(CONFIG_NET_DSA_MV88E6123_61_65)
1455 register_switch_driver(&mv88e6123_61_65_switch_driver);
1456 #endif
1457 #if IS_ENABLED(CONFIG_NET_DSA_MV88E6352)
1458 register_switch_driver(&mv88e6352_switch_driver);
1459 #endif
1460 #if IS_ENABLED(CONFIG_NET_DSA_MV88E6171)
1461 register_switch_driver(&mv88e6171_switch_driver);
1462 #endif
1463 return 0;
1465 module_init(mv88e6xxx_init);
1467 static void __exit mv88e6xxx_cleanup(void)
1469 #if IS_ENABLED(CONFIG_NET_DSA_MV88E6171)
1470 unregister_switch_driver(&mv88e6171_switch_driver);
1471 #endif
1472 #if IS_ENABLED(CONFIG_NET_DSA_MV88E6123_61_65)
1473 unregister_switch_driver(&mv88e6123_61_65_switch_driver);
1474 #endif
1475 #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131)
1476 unregister_switch_driver(&mv88e6131_switch_driver);
1477 #endif
1479 module_exit(mv88e6xxx_cleanup);
1481 MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
1482 MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
1483 MODULE_LICENSE("GPL");