2 * Marvell 88e6xxx Ethernet switch single-chip support
4 * Copyright (c) 2008 Marvell Semiconductor
6 * Copyright (c) 2015 CMC Electronics, Inc.
7 * Added support for VLAN Table Unit operations
9 * Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
17 #include <linux/delay.h>
18 #include <linux/etherdevice.h>
19 #include <linux/ethtool.h>
20 #include <linux/if_bridge.h>
21 #include <linux/interrupt.h>
22 #include <linux/irq.h>
23 #include <linux/irqdomain.h>
24 #include <linux/jiffies.h>
25 #include <linux/list.h>
26 #include <linux/mdio.h>
27 #include <linux/module.h>
28 #include <linux/of_device.h>
29 #include <linux/of_irq.h>
30 #include <linux/of_mdio.h>
31 #include <linux/netdevice.h>
32 #include <linux/gpio/consumer.h>
33 #include <linux/phy.h>
35 #include <net/switchdev.h>
37 #include "mv88e6xxx.h"
42 static void assert_reg_lock(struct mv88e6xxx_chip
*chip
)
44 if (unlikely(!mutex_is_locked(&chip
->reg_lock
))) {
45 dev_err(chip
->dev
, "Switch registers lock not held!\n");
50 /* The switch ADDR[4:1] configuration pins define the chip SMI device address
51 * (ADDR[0] is always zero, thus only even SMI addresses can be strapped).
53 * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it
54 * is the only device connected to the SMI master. In this mode it responds to
55 * all 32 possible SMI addresses, and thus maps directly the internal devices.
57 * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing
58 * multiple devices to share the SMI interface. In this mode it responds to only
59 * 2 registers, used to indirectly access the internal SMI devices.
62 static int mv88e6xxx_smi_read(struct mv88e6xxx_chip
*chip
,
63 int addr
, int reg
, u16
*val
)
68 return chip
->smi_ops
->read(chip
, addr
, reg
, val
);
71 static int mv88e6xxx_smi_write(struct mv88e6xxx_chip
*chip
,
72 int addr
, int reg
, u16 val
)
77 return chip
->smi_ops
->write(chip
, addr
, reg
, val
);
80 static int mv88e6xxx_smi_single_chip_read(struct mv88e6xxx_chip
*chip
,
81 int addr
, int reg
, u16
*val
)
85 ret
= mdiobus_read_nested(chip
->bus
, addr
, reg
);
94 static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip
*chip
,
95 int addr
, int reg
, u16 val
)
99 ret
= mdiobus_write_nested(chip
->bus
, addr
, reg
, val
);
106 static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops
= {
107 .read
= mv88e6xxx_smi_single_chip_read
,
108 .write
= mv88e6xxx_smi_single_chip_write
,
111 static int mv88e6xxx_smi_multi_chip_wait(struct mv88e6xxx_chip
*chip
)
116 for (i
= 0; i
< 16; i
++) {
117 ret
= mdiobus_read_nested(chip
->bus
, chip
->sw_addr
, SMI_CMD
);
121 if ((ret
& SMI_CMD_BUSY
) == 0)
128 static int mv88e6xxx_smi_multi_chip_read(struct mv88e6xxx_chip
*chip
,
129 int addr
, int reg
, u16
*val
)
133 /* Wait for the bus to become free. */
134 ret
= mv88e6xxx_smi_multi_chip_wait(chip
);
138 /* Transmit the read command. */
139 ret
= mdiobus_write_nested(chip
->bus
, chip
->sw_addr
, SMI_CMD
,
140 SMI_CMD_OP_22_READ
| (addr
<< 5) | reg
);
144 /* Wait for the read command to complete. */
145 ret
= mv88e6xxx_smi_multi_chip_wait(chip
);
150 ret
= mdiobus_read_nested(chip
->bus
, chip
->sw_addr
, SMI_DATA
);
159 static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip
*chip
,
160 int addr
, int reg
, u16 val
)
164 /* Wait for the bus to become free. */
165 ret
= mv88e6xxx_smi_multi_chip_wait(chip
);
169 /* Transmit the data to write. */
170 ret
= mdiobus_write_nested(chip
->bus
, chip
->sw_addr
, SMI_DATA
, val
);
174 /* Transmit the write command. */
175 ret
= mdiobus_write_nested(chip
->bus
, chip
->sw_addr
, SMI_CMD
,
176 SMI_CMD_OP_22_WRITE
| (addr
<< 5) | reg
);
180 /* Wait for the write command to complete. */
181 ret
= mv88e6xxx_smi_multi_chip_wait(chip
);
188 static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops
= {
189 .read
= mv88e6xxx_smi_multi_chip_read
,
190 .write
= mv88e6xxx_smi_multi_chip_write
,
193 int mv88e6xxx_read(struct mv88e6xxx_chip
*chip
, int addr
, int reg
, u16
*val
)
197 assert_reg_lock(chip
);
199 err
= mv88e6xxx_smi_read(chip
, addr
, reg
, val
);
203 dev_dbg(chip
->dev
, "<- addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
209 int mv88e6xxx_write(struct mv88e6xxx_chip
*chip
, int addr
, int reg
, u16 val
)
213 assert_reg_lock(chip
);
215 err
= mv88e6xxx_smi_write(chip
, addr
, reg
, val
);
219 dev_dbg(chip
->dev
, "-> addr: 0x%.2x reg: 0x%.2x val: 0x%.4x\n",
225 static int mv88e6xxx_phy_read(struct mv88e6xxx_chip
*chip
, int phy
,
228 int addr
= phy
; /* PHY devices addresses start at 0x0 */
230 if (!chip
->info
->ops
->phy_read
)
233 return chip
->info
->ops
->phy_read(chip
, addr
, reg
, val
);
236 static int mv88e6xxx_phy_write(struct mv88e6xxx_chip
*chip
, int phy
,
239 int addr
= phy
; /* PHY devices addresses start at 0x0 */
241 if (!chip
->info
->ops
->phy_write
)
244 return chip
->info
->ops
->phy_write(chip
, addr
, reg
, val
);
247 static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip
*chip
, int phy
, u8 page
)
249 if (!mv88e6xxx_has(chip
, MV88E6XXX_FLAG_PHY_PAGE
))
252 return mv88e6xxx_phy_write(chip
, phy
, PHY_PAGE
, page
);
255 static void mv88e6xxx_phy_page_put(struct mv88e6xxx_chip
*chip
, int phy
)
259 /* Restore PHY page Copper 0x0 for access via the registered MDIO bus */
260 err
= mv88e6xxx_phy_write(chip
, phy
, PHY_PAGE
, PHY_PAGE_COPPER
);
262 dev_err(chip
->dev
, "failed to restore PHY %d page Copper (%d)\n",
267 static int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip
*chip
, int phy
,
268 u8 page
, int reg
, u16
*val
)
272 /* There is no paging for registers 22 */
276 err
= mv88e6xxx_phy_page_get(chip
, phy
, page
);
278 err
= mv88e6xxx_phy_read(chip
, phy
, reg
, val
);
279 mv88e6xxx_phy_page_put(chip
, phy
);
285 static int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip
*chip
, int phy
,
286 u8 page
, int reg
, u16 val
)
290 /* There is no paging for registers 22 */
294 err
= mv88e6xxx_phy_page_get(chip
, phy
, page
);
296 err
= mv88e6xxx_phy_write(chip
, phy
, PHY_PAGE
, page
);
297 mv88e6xxx_phy_page_put(chip
, phy
);
303 static int mv88e6xxx_serdes_read(struct mv88e6xxx_chip
*chip
, int reg
, u16
*val
)
305 return mv88e6xxx_phy_page_read(chip
, ADDR_SERDES
, SERDES_PAGE_FIBER
,
309 static int mv88e6xxx_serdes_write(struct mv88e6xxx_chip
*chip
, int reg
, u16 val
)
311 return mv88e6xxx_phy_page_write(chip
, ADDR_SERDES
, SERDES_PAGE_FIBER
,
315 static void mv88e6xxx_g1_irq_mask(struct irq_data
*d
)
317 struct mv88e6xxx_chip
*chip
= irq_data_get_irq_chip_data(d
);
318 unsigned int n
= d
->hwirq
;
320 chip
->g1_irq
.masked
|= (1 << n
);
323 static void mv88e6xxx_g1_irq_unmask(struct irq_data
*d
)
325 struct mv88e6xxx_chip
*chip
= irq_data_get_irq_chip_data(d
);
326 unsigned int n
= d
->hwirq
;
328 chip
->g1_irq
.masked
&= ~(1 << n
);
331 static irqreturn_t
mv88e6xxx_g1_irq_thread_fn(int irq
, void *dev_id
)
333 struct mv88e6xxx_chip
*chip
= dev_id
;
334 unsigned int nhandled
= 0;
335 unsigned int sub_irq
;
340 mutex_lock(&chip
->reg_lock
);
341 err
= mv88e6xxx_g1_read(chip
, GLOBAL_STATUS
, ®
);
342 mutex_unlock(&chip
->reg_lock
);
347 for (n
= 0; n
< chip
->g1_irq
.nirqs
; ++n
) {
348 if (reg
& (1 << n
)) {
349 sub_irq
= irq_find_mapping(chip
->g1_irq
.domain
, n
);
350 handle_nested_irq(sub_irq
);
355 return (nhandled
> 0 ? IRQ_HANDLED
: IRQ_NONE
);
358 static void mv88e6xxx_g1_irq_bus_lock(struct irq_data
*d
)
360 struct mv88e6xxx_chip
*chip
= irq_data_get_irq_chip_data(d
);
362 mutex_lock(&chip
->reg_lock
);
365 static void mv88e6xxx_g1_irq_bus_sync_unlock(struct irq_data
*d
)
367 struct mv88e6xxx_chip
*chip
= irq_data_get_irq_chip_data(d
);
368 u16 mask
= GENMASK(chip
->g1_irq
.nirqs
, 0);
372 err
= mv88e6xxx_g1_read(chip
, GLOBAL_CONTROL
, ®
);
377 reg
|= (~chip
->g1_irq
.masked
& mask
);
379 err
= mv88e6xxx_g1_write(chip
, GLOBAL_CONTROL
, reg
);
384 mutex_unlock(&chip
->reg_lock
);
387 static struct irq_chip mv88e6xxx_g1_irq_chip
= {
388 .name
= "mv88e6xxx-g1",
389 .irq_mask
= mv88e6xxx_g1_irq_mask
,
390 .irq_unmask
= mv88e6xxx_g1_irq_unmask
,
391 .irq_bus_lock
= mv88e6xxx_g1_irq_bus_lock
,
392 .irq_bus_sync_unlock
= mv88e6xxx_g1_irq_bus_sync_unlock
,
395 static int mv88e6xxx_g1_irq_domain_map(struct irq_domain
*d
,
397 irq_hw_number_t hwirq
)
399 struct mv88e6xxx_chip
*chip
= d
->host_data
;
401 irq_set_chip_data(irq
, d
->host_data
);
402 irq_set_chip_and_handler(irq
, &chip
->g1_irq
.chip
, handle_level_irq
);
403 irq_set_noprobe(irq
);
408 static const struct irq_domain_ops mv88e6xxx_g1_irq_domain_ops
= {
409 .map
= mv88e6xxx_g1_irq_domain_map
,
410 .xlate
= irq_domain_xlate_twocell
,
413 static void mv88e6xxx_g1_irq_free(struct mv88e6xxx_chip
*chip
)
418 mv88e6xxx_g1_read(chip
, GLOBAL_CONTROL
, &mask
);
419 mask
|= GENMASK(chip
->g1_irq
.nirqs
, 0);
420 mv88e6xxx_g1_write(chip
, GLOBAL_CONTROL
, mask
);
422 free_irq(chip
->irq
, chip
);
424 for (irq
= 0; irq
< 16; irq
++) {
425 virq
= irq_find_mapping(chip
->g1_irq
.domain
, irq
);
426 irq_dispose_mapping(virq
);
429 irq_domain_remove(chip
->g1_irq
.domain
);
432 static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip
*chip
)
437 chip
->g1_irq
.nirqs
= chip
->info
->g1_irqs
;
438 chip
->g1_irq
.domain
= irq_domain_add_simple(
439 NULL
, chip
->g1_irq
.nirqs
, 0,
440 &mv88e6xxx_g1_irq_domain_ops
, chip
);
441 if (!chip
->g1_irq
.domain
)
444 for (irq
= 0; irq
< chip
->g1_irq
.nirqs
; irq
++)
445 irq_create_mapping(chip
->g1_irq
.domain
, irq
);
447 chip
->g1_irq
.chip
= mv88e6xxx_g1_irq_chip
;
448 chip
->g1_irq
.masked
= ~0;
450 err
= mv88e6xxx_g1_read(chip
, GLOBAL_CONTROL
, &mask
);
454 mask
&= ~GENMASK(chip
->g1_irq
.nirqs
, 0);
456 err
= mv88e6xxx_g1_write(chip
, GLOBAL_CONTROL
, mask
);
460 /* Reading the interrupt status clears (most of) them */
461 err
= mv88e6xxx_g1_read(chip
, GLOBAL_STATUS
, ®
);
465 err
= request_threaded_irq(chip
->irq
, NULL
,
466 mv88e6xxx_g1_irq_thread_fn
,
467 IRQF_ONESHOT
| IRQF_TRIGGER_FALLING
,
468 dev_name(chip
->dev
), chip
);
475 mask
|= GENMASK(chip
->g1_irq
.nirqs
, 0);
476 mv88e6xxx_g1_write(chip
, GLOBAL_CONTROL
, mask
);
479 for (irq
= 0; irq
< 16; irq
++) {
480 virq
= irq_find_mapping(chip
->g1_irq
.domain
, irq
);
481 irq_dispose_mapping(virq
);
484 irq_domain_remove(chip
->g1_irq
.domain
);
489 int mv88e6xxx_wait(struct mv88e6xxx_chip
*chip
, int addr
, int reg
, u16 mask
)
493 for (i
= 0; i
< 16; i
++) {
497 err
= mv88e6xxx_read(chip
, addr
, reg
, &val
);
504 usleep_range(1000, 2000);
507 dev_err(chip
->dev
, "Timeout while waiting for switch\n");
511 /* Indirect write to single pointer-data register with an Update bit */
512 int mv88e6xxx_update(struct mv88e6xxx_chip
*chip
, int addr
, int reg
, u16 update
)
517 /* Wait until the previous operation is completed */
518 err
= mv88e6xxx_wait(chip
, addr
, reg
, BIT(15));
522 /* Set the Update bit to trigger a write operation */
523 val
= BIT(15) | update
;
525 return mv88e6xxx_write(chip
, addr
, reg
, val
);
528 static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip
*chip
)
533 err
= mv88e6xxx_g1_read(chip
, GLOBAL_CONTROL
, &val
);
537 err
= mv88e6xxx_g1_write(chip
, GLOBAL_CONTROL
,
538 val
& ~GLOBAL_CONTROL_PPU_ENABLE
);
542 for (i
= 0; i
< 16; i
++) {
543 err
= mv88e6xxx_g1_read(chip
, GLOBAL_STATUS
, &val
);
547 usleep_range(1000, 2000);
548 if ((val
& GLOBAL_STATUS_PPU_MASK
) != GLOBAL_STATUS_PPU_POLLING
)
555 static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip
*chip
)
560 err
= mv88e6xxx_g1_read(chip
, GLOBAL_CONTROL
, &val
);
564 err
= mv88e6xxx_g1_write(chip
, GLOBAL_CONTROL
,
565 val
| GLOBAL_CONTROL_PPU_ENABLE
);
569 for (i
= 0; i
< 16; i
++) {
570 err
= mv88e6xxx_g1_read(chip
, GLOBAL_STATUS
, &val
);
574 usleep_range(1000, 2000);
575 if ((val
& GLOBAL_STATUS_PPU_MASK
) == GLOBAL_STATUS_PPU_POLLING
)
582 static void mv88e6xxx_ppu_reenable_work(struct work_struct
*ugly
)
584 struct mv88e6xxx_chip
*chip
;
586 chip
= container_of(ugly
, struct mv88e6xxx_chip
, ppu_work
);
588 mutex_lock(&chip
->reg_lock
);
590 if (mutex_trylock(&chip
->ppu_mutex
)) {
591 if (mv88e6xxx_ppu_enable(chip
) == 0)
592 chip
->ppu_disabled
= 0;
593 mutex_unlock(&chip
->ppu_mutex
);
596 mutex_unlock(&chip
->reg_lock
);
599 static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps
)
601 struct mv88e6xxx_chip
*chip
= (void *)_ps
;
603 schedule_work(&chip
->ppu_work
);
606 static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip
*chip
)
610 mutex_lock(&chip
->ppu_mutex
);
612 /* If the PHY polling unit is enabled, disable it so that
613 * we can access the PHY registers. If it was already
614 * disabled, cancel the timer that is going to re-enable
617 if (!chip
->ppu_disabled
) {
618 ret
= mv88e6xxx_ppu_disable(chip
);
620 mutex_unlock(&chip
->ppu_mutex
);
623 chip
->ppu_disabled
= 1;
625 del_timer(&chip
->ppu_timer
);
632 static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip
*chip
)
634 /* Schedule a timer to re-enable the PHY polling unit. */
635 mod_timer(&chip
->ppu_timer
, jiffies
+ msecs_to_jiffies(10));
636 mutex_unlock(&chip
->ppu_mutex
);
639 static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip
*chip
)
641 mutex_init(&chip
->ppu_mutex
);
642 INIT_WORK(&chip
->ppu_work
, mv88e6xxx_ppu_reenable_work
);
643 setup_timer(&chip
->ppu_timer
, mv88e6xxx_ppu_reenable_timer
,
644 (unsigned long)chip
);
647 static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip
*chip
)
649 del_timer_sync(&chip
->ppu_timer
);
652 static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip
*chip
, int addr
,
657 err
= mv88e6xxx_ppu_access_get(chip
);
659 err
= mv88e6xxx_read(chip
, addr
, reg
, val
);
660 mv88e6xxx_ppu_access_put(chip
);
666 static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip
*chip
, int addr
,
671 err
= mv88e6xxx_ppu_access_get(chip
);
673 err
= mv88e6xxx_write(chip
, addr
, reg
, val
);
674 mv88e6xxx_ppu_access_put(chip
);
680 static bool mv88e6xxx_6065_family(struct mv88e6xxx_chip
*chip
)
682 return chip
->info
->family
== MV88E6XXX_FAMILY_6065
;
685 static bool mv88e6xxx_6095_family(struct mv88e6xxx_chip
*chip
)
687 return chip
->info
->family
== MV88E6XXX_FAMILY_6095
;
690 static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip
*chip
)
692 return chip
->info
->family
== MV88E6XXX_FAMILY_6097
;
695 static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip
*chip
)
697 return chip
->info
->family
== MV88E6XXX_FAMILY_6165
;
700 static bool mv88e6xxx_6185_family(struct mv88e6xxx_chip
*chip
)
702 return chip
->info
->family
== MV88E6XXX_FAMILY_6185
;
705 static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip
*chip
)
707 return chip
->info
->family
== MV88E6XXX_FAMILY_6320
;
710 static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip
*chip
)
712 return chip
->info
->family
== MV88E6XXX_FAMILY_6351
;
715 static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip
*chip
)
717 return chip
->info
->family
== MV88E6XXX_FAMILY_6352
;
720 static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip
*chip
, int port
,
721 int link
, int speed
, int duplex
,
722 phy_interface_t mode
)
726 if (!chip
->info
->ops
->port_set_link
)
729 /* Port's MAC control must not be changed unless the link is down */
730 err
= chip
->info
->ops
->port_set_link(chip
, port
, 0);
734 if (chip
->info
->ops
->port_set_speed
) {
735 err
= chip
->info
->ops
->port_set_speed(chip
, port
, speed
);
736 if (err
&& err
!= -EOPNOTSUPP
)
740 if (chip
->info
->ops
->port_set_duplex
) {
741 err
= chip
->info
->ops
->port_set_duplex(chip
, port
, duplex
);
742 if (err
&& err
!= -EOPNOTSUPP
)
746 if (chip
->info
->ops
->port_set_rgmii_delay
) {
747 err
= chip
->info
->ops
->port_set_rgmii_delay(chip
, port
, mode
);
748 if (err
&& err
!= -EOPNOTSUPP
)
754 if (chip
->info
->ops
->port_set_link(chip
, port
, link
))
755 netdev_err(chip
->ds
->ports
[port
].netdev
,
756 "failed to restore MAC's link\n");
761 /* We expect the switch to perform auto negotiation if there is a real
762 * phy. However, in the case of a fixed link phy, we force the port
763 * settings from the fixed link settings.
765 static void mv88e6xxx_adjust_link(struct dsa_switch
*ds
, int port
,
766 struct phy_device
*phydev
)
768 struct mv88e6xxx_chip
*chip
= ds
->priv
;
771 if (!phy_is_pseudo_fixed_link(phydev
))
774 mutex_lock(&chip
->reg_lock
);
775 err
= mv88e6xxx_port_setup_mac(chip
, port
, phydev
->link
, phydev
->speed
,
776 phydev
->duplex
, phydev
->interface
);
777 mutex_unlock(&chip
->reg_lock
);
779 if (err
&& err
!= -EOPNOTSUPP
)
780 netdev_err(ds
->ports
[port
].netdev
, "failed to configure MAC\n");
783 static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip
*chip
, int port
)
785 if (!chip
->info
->ops
->stats_snapshot
)
788 return chip
->info
->ops
->stats_snapshot(chip
, port
);
791 static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats
[] = {
792 { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0
, },
793 { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0
, },
794 { "in_unicast", 4, 0x04, STATS_TYPE_BANK0
, },
795 { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0
, },
796 { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0
, },
797 { "in_pause", 4, 0x16, STATS_TYPE_BANK0
, },
798 { "in_undersize", 4, 0x18, STATS_TYPE_BANK0
, },
799 { "in_fragments", 4, 0x19, STATS_TYPE_BANK0
, },
800 { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0
, },
801 { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0
, },
802 { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0
, },
803 { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0
, },
804 { "out_octets", 8, 0x0e, STATS_TYPE_BANK0
, },
805 { "out_unicast", 4, 0x10, STATS_TYPE_BANK0
, },
806 { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0
, },
807 { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0
, },
808 { "out_pause", 4, 0x15, STATS_TYPE_BANK0
, },
809 { "excessive", 4, 0x11, STATS_TYPE_BANK0
, },
810 { "collisions", 4, 0x1e, STATS_TYPE_BANK0
, },
811 { "deferred", 4, 0x05, STATS_TYPE_BANK0
, },
812 { "single", 4, 0x14, STATS_TYPE_BANK0
, },
813 { "multiple", 4, 0x17, STATS_TYPE_BANK0
, },
814 { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0
, },
815 { "late", 4, 0x1f, STATS_TYPE_BANK0
, },
816 { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0
, },
817 { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0
, },
818 { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0
, },
819 { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0
, },
820 { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0
, },
821 { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0
, },
822 { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT
, },
823 { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT
, },
824 { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT
, },
825 { "in_discards", 4, 0x00, STATS_TYPE_BANK1
, },
826 { "in_filtered", 4, 0x01, STATS_TYPE_BANK1
, },
827 { "in_accepted", 4, 0x02, STATS_TYPE_BANK1
, },
828 { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1
, },
829 { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1
, },
830 { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1
, },
831 { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1
, },
832 { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1
, },
833 { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1
, },
834 { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1
, },
835 { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1
, },
836 { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1
, },
837 { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1
, },
838 { "in_management", 4, 0x0f, STATS_TYPE_BANK1
, },
839 { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1
, },
840 { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1
, },
841 { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1
, },
842 { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1
, },
843 { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1
, },
844 { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1
, },
845 { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1
, },
846 { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1
, },
847 { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1
, },
848 { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1
, },
849 { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1
, },
850 { "out_management", 4, 0x1f, STATS_TYPE_BANK1
, },
853 static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip
*chip
,
854 struct mv88e6xxx_hw_stat
*s
,
855 int port
, u16 bank1_select
,
865 case STATS_TYPE_PORT
:
866 err
= mv88e6xxx_port_read(chip
, port
, s
->reg
, ®
);
871 if (s
->sizeof_stat
== 4) {
872 err
= mv88e6xxx_port_read(chip
, port
, s
->reg
+ 1, ®
);
878 case STATS_TYPE_BANK1
:
881 case STATS_TYPE_BANK0
:
882 reg
|= s
->reg
| histogram
;
883 mv88e6xxx_g1_stats_read(chip
, reg
, &low
);
884 if (s
->sizeof_stat
== 8)
885 mv88e6xxx_g1_stats_read(chip
, reg
+ 1, &high
);
887 value
= (((u64
)high
) << 16) | low
;
891 static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip
*chip
,
892 uint8_t *data
, int types
)
894 struct mv88e6xxx_hw_stat
*stat
;
897 for (i
= 0, j
= 0; i
< ARRAY_SIZE(mv88e6xxx_hw_stats
); i
++) {
898 stat
= &mv88e6xxx_hw_stats
[i
];
899 if (stat
->type
& types
) {
900 memcpy(data
+ j
* ETH_GSTRING_LEN
, stat
->string
,
907 static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip
*chip
,
910 mv88e6xxx_stats_get_strings(chip
, data
,
911 STATS_TYPE_BANK0
| STATS_TYPE_PORT
);
914 static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip
*chip
,
917 mv88e6xxx_stats_get_strings(chip
, data
,
918 STATS_TYPE_BANK0
| STATS_TYPE_BANK1
);
921 static void mv88e6xxx_get_strings(struct dsa_switch
*ds
, int port
,
924 struct mv88e6xxx_chip
*chip
= ds
->priv
;
926 if (chip
->info
->ops
->stats_get_strings
)
927 chip
->info
->ops
->stats_get_strings(chip
, data
);
930 static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip
*chip
,
933 struct mv88e6xxx_hw_stat
*stat
;
936 for (i
= 0, j
= 0; i
< ARRAY_SIZE(mv88e6xxx_hw_stats
); i
++) {
937 stat
= &mv88e6xxx_hw_stats
[i
];
938 if (stat
->type
& types
)
944 static int mv88e6095_stats_get_sset_count(struct mv88e6xxx_chip
*chip
)
946 return mv88e6xxx_stats_get_sset_count(chip
, STATS_TYPE_BANK0
|
950 static int mv88e6320_stats_get_sset_count(struct mv88e6xxx_chip
*chip
)
952 return mv88e6xxx_stats_get_sset_count(chip
, STATS_TYPE_BANK0
|
956 static int mv88e6xxx_get_sset_count(struct dsa_switch
*ds
)
958 struct mv88e6xxx_chip
*chip
= ds
->priv
;
960 if (chip
->info
->ops
->stats_get_sset_count
)
961 return chip
->info
->ops
->stats_get_sset_count(chip
);
966 static void mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip
*chip
, int port
,
967 uint64_t *data
, int types
,
968 u16 bank1_select
, u16 histogram
)
970 struct mv88e6xxx_hw_stat
*stat
;
973 for (i
= 0, j
= 0; i
< ARRAY_SIZE(mv88e6xxx_hw_stats
); i
++) {
974 stat
= &mv88e6xxx_hw_stats
[i
];
975 if (stat
->type
& types
) {
976 data
[j
] = _mv88e6xxx_get_ethtool_stat(chip
, stat
, port
,
984 static void mv88e6095_stats_get_stats(struct mv88e6xxx_chip
*chip
, int port
,
987 return mv88e6xxx_stats_get_stats(chip
, port
, data
,
988 STATS_TYPE_BANK0
| STATS_TYPE_PORT
,
989 0, GLOBAL_STATS_OP_HIST_RX_TX
);
992 static void mv88e6320_stats_get_stats(struct mv88e6xxx_chip
*chip
, int port
,
995 return mv88e6xxx_stats_get_stats(chip
, port
, data
,
996 STATS_TYPE_BANK0
| STATS_TYPE_BANK1
,
997 GLOBAL_STATS_OP_BANK_1_BIT_9
,
998 GLOBAL_STATS_OP_HIST_RX_TX
);
1001 static void mv88e6390_stats_get_stats(struct mv88e6xxx_chip
*chip
, int port
,
1004 return mv88e6xxx_stats_get_stats(chip
, port
, data
,
1005 STATS_TYPE_BANK0
| STATS_TYPE_BANK1
,
1006 GLOBAL_STATS_OP_BANK_1_BIT_10
, 0);
1009 static void mv88e6xxx_get_stats(struct mv88e6xxx_chip
*chip
, int port
,
1012 if (chip
->info
->ops
->stats_get_stats
)
1013 chip
->info
->ops
->stats_get_stats(chip
, port
, data
);
1016 static void mv88e6xxx_get_ethtool_stats(struct dsa_switch
*ds
, int port
,
1019 struct mv88e6xxx_chip
*chip
= ds
->priv
;
1022 mutex_lock(&chip
->reg_lock
);
1024 ret
= mv88e6xxx_stats_snapshot(chip
, port
);
1026 mutex_unlock(&chip
->reg_lock
);
1030 mv88e6xxx_get_stats(chip
, port
, data
);
1032 mutex_unlock(&chip
->reg_lock
);
1035 static int mv88e6xxx_stats_set_histogram(struct mv88e6xxx_chip
*chip
)
1037 if (chip
->info
->ops
->stats_set_histogram
)
1038 return chip
->info
->ops
->stats_set_histogram(chip
);
1043 static int mv88e6xxx_get_regs_len(struct dsa_switch
*ds
, int port
)
1045 return 32 * sizeof(u16
);
1048 static void mv88e6xxx_get_regs(struct dsa_switch
*ds
, int port
,
1049 struct ethtool_regs
*regs
, void *_p
)
1051 struct mv88e6xxx_chip
*chip
= ds
->priv
;
1059 memset(p
, 0xff, 32 * sizeof(u16
));
1061 mutex_lock(&chip
->reg_lock
);
1063 for (i
= 0; i
< 32; i
++) {
1065 err
= mv88e6xxx_port_read(chip
, port
, i
, ®
);
1070 mutex_unlock(&chip
->reg_lock
);
1073 static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip
*chip
)
1075 return mv88e6xxx_g1_wait(chip
, GLOBAL_ATU_OP
, GLOBAL_ATU_OP_BUSY
);
1078 static int mv88e6xxx_get_eee(struct dsa_switch
*ds
, int port
,
1079 struct ethtool_eee
*e
)
1081 struct mv88e6xxx_chip
*chip
= ds
->priv
;
1085 if (!mv88e6xxx_has(chip
, MV88E6XXX_FLAG_EEE
))
1088 mutex_lock(&chip
->reg_lock
);
1090 err
= mv88e6xxx_phy_read(chip
, port
, 16, ®
);
1094 e
->eee_enabled
= !!(reg
& 0x0200);
1095 e
->tx_lpi_enabled
= !!(reg
& 0x0100);
1097 err
= mv88e6xxx_port_read(chip
, port
, PORT_STATUS
, ®
);
1101 e
->eee_active
= !!(reg
& PORT_STATUS_EEE
);
1103 mutex_unlock(&chip
->reg_lock
);
1108 static int mv88e6xxx_set_eee(struct dsa_switch
*ds
, int port
,
1109 struct phy_device
*phydev
, struct ethtool_eee
*e
)
1111 struct mv88e6xxx_chip
*chip
= ds
->priv
;
1115 if (!mv88e6xxx_has(chip
, MV88E6XXX_FLAG_EEE
))
1118 mutex_lock(&chip
->reg_lock
);
1120 err
= mv88e6xxx_phy_read(chip
, port
, 16, ®
);
1127 if (e
->tx_lpi_enabled
)
1130 err
= mv88e6xxx_phy_write(chip
, port
, 16, reg
);
1132 mutex_unlock(&chip
->reg_lock
);
1137 static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip
*chip
, u16 fid
, u16 cmd
)
1142 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_G1_ATU_FID
)) {
1143 err
= mv88e6xxx_g1_write(chip
, GLOBAL_ATU_FID
, fid
);
1146 } else if (mv88e6xxx_num_databases(chip
) == 256) {
1147 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
1148 err
= mv88e6xxx_g1_read(chip
, GLOBAL_ATU_CONTROL
, &val
);
1152 err
= mv88e6xxx_g1_write(chip
, GLOBAL_ATU_CONTROL
,
1153 (val
& 0xfff) | ((fid
<< 8) & 0xf000));
1157 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1161 err
= mv88e6xxx_g1_write(chip
, GLOBAL_ATU_OP
, cmd
);
1165 return _mv88e6xxx_atu_wait(chip
);
1168 static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip
*chip
,
1169 struct mv88e6xxx_atu_entry
*entry
)
1171 u16 data
= entry
->state
& GLOBAL_ATU_DATA_STATE_MASK
;
1173 if (entry
->state
!= GLOBAL_ATU_DATA_STATE_UNUSED
) {
1174 unsigned int mask
, shift
;
1177 data
|= GLOBAL_ATU_DATA_TRUNK
;
1178 mask
= GLOBAL_ATU_DATA_TRUNK_ID_MASK
;
1179 shift
= GLOBAL_ATU_DATA_TRUNK_ID_SHIFT
;
1181 mask
= GLOBAL_ATU_DATA_PORT_VECTOR_MASK
;
1182 shift
= GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT
;
1185 data
|= (entry
->portv_trunkid
<< shift
) & mask
;
1188 return mv88e6xxx_g1_write(chip
, GLOBAL_ATU_DATA
, data
);
1191 static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip
*chip
,
1192 struct mv88e6xxx_atu_entry
*entry
,
1198 err
= _mv88e6xxx_atu_wait(chip
);
1202 err
= _mv88e6xxx_atu_data_write(chip
, entry
);
1207 op
= static_too
? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB
:
1208 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB
;
1210 op
= static_too
? GLOBAL_ATU_OP_FLUSH_MOVE_ALL
:
1211 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC
;
1214 return _mv88e6xxx_atu_cmd(chip
, entry
->fid
, op
);
1217 static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip
*chip
,
1218 u16 fid
, bool static_too
)
1220 struct mv88e6xxx_atu_entry entry
= {
1222 .state
= 0, /* EntryState bits must be 0 */
1225 return _mv88e6xxx_atu_flush_move(chip
, &entry
, static_too
);
1228 static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip
*chip
, u16 fid
,
1229 int from_port
, int to_port
, bool static_too
)
1231 struct mv88e6xxx_atu_entry entry
= {
1236 /* EntryState bits must be 0xF */
1237 entry
.state
= GLOBAL_ATU_DATA_STATE_MASK
;
1239 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1240 entry
.portv_trunkid
= (to_port
& 0x0f) << 4;
1241 entry
.portv_trunkid
|= from_port
& 0x0f;
1243 return _mv88e6xxx_atu_flush_move(chip
, &entry
, static_too
);
1246 static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip
*chip
, u16 fid
,
1247 int port
, bool static_too
)
1249 /* Destination port 0xF means remove the entries */
1250 return _mv88e6xxx_atu_move(chip
, fid
, port
, 0x0f, static_too
);
1253 static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip
*chip
, int port
)
1255 struct net_device
*bridge
= chip
->ports
[port
].bridge_dev
;
1256 struct dsa_switch
*ds
= chip
->ds
;
1257 u16 output_ports
= 0;
1260 /* allow CPU port or DSA link(s) to send frames to every port */
1261 if (dsa_is_cpu_port(ds
, port
) || dsa_is_dsa_port(ds
, port
)) {
1264 for (i
= 0; i
< mv88e6xxx_num_ports(chip
); ++i
) {
1265 /* allow sending frames to every group member */
1266 if (bridge
&& chip
->ports
[i
].bridge_dev
== bridge
)
1267 output_ports
|= BIT(i
);
1269 /* allow sending frames to CPU port and DSA link(s) */
1270 if (dsa_is_cpu_port(ds
, i
) || dsa_is_dsa_port(ds
, i
))
1271 output_ports
|= BIT(i
);
1275 /* prevent frames from going back out of the port they came in on */
1276 output_ports
&= ~BIT(port
);
1278 return mv88e6xxx_port_set_vlan_map(chip
, port
, output_ports
);
1281 static void mv88e6xxx_port_stp_state_set(struct dsa_switch
*ds
, int port
,
1284 struct mv88e6xxx_chip
*chip
= ds
->priv
;
1289 case BR_STATE_DISABLED
:
1290 stp_state
= PORT_CONTROL_STATE_DISABLED
;
1292 case BR_STATE_BLOCKING
:
1293 case BR_STATE_LISTENING
:
1294 stp_state
= PORT_CONTROL_STATE_BLOCKING
;
1296 case BR_STATE_LEARNING
:
1297 stp_state
= PORT_CONTROL_STATE_LEARNING
;
1299 case BR_STATE_FORWARDING
:
1301 stp_state
= PORT_CONTROL_STATE_FORWARDING
;
1305 mutex_lock(&chip
->reg_lock
);
1306 err
= mv88e6xxx_port_set_state(chip
, port
, stp_state
);
1307 mutex_unlock(&chip
->reg_lock
);
1310 netdev_err(ds
->ports
[port
].netdev
, "failed to update state\n");
1313 static void mv88e6xxx_port_fast_age(struct dsa_switch
*ds
, int port
)
1315 struct mv88e6xxx_chip
*chip
= ds
->priv
;
1318 mutex_lock(&chip
->reg_lock
);
1319 err
= _mv88e6xxx_atu_remove(chip
, 0, port
, false);
1320 mutex_unlock(&chip
->reg_lock
);
1323 netdev_err(ds
->ports
[port
].netdev
, "failed to flush ATU\n");
1326 static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip
*chip
)
1328 return mv88e6xxx_g1_wait(chip
, GLOBAL_VTU_OP
, GLOBAL_VTU_OP_BUSY
);
1331 static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip
*chip
, u16 op
)
1335 err
= mv88e6xxx_g1_write(chip
, GLOBAL_VTU_OP
, op
);
1339 return _mv88e6xxx_vtu_wait(chip
);
1342 static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip
*chip
)
1346 ret
= _mv88e6xxx_vtu_wait(chip
);
1350 return _mv88e6xxx_vtu_cmd(chip
, GLOBAL_VTU_OP_FLUSH_ALL
);
1353 static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip
*chip
,
1354 struct mv88e6xxx_vtu_entry
*entry
,
1355 unsigned int nibble_offset
)
1360 for (i
= 0; i
< 3; ++i
) {
1361 u16
*reg
= ®s
[i
];
1363 err
= mv88e6xxx_g1_read(chip
, GLOBAL_VTU_DATA_0_3
+ i
, reg
);
1368 for (i
= 0; i
< mv88e6xxx_num_ports(chip
); ++i
) {
1369 unsigned int shift
= (i
% 4) * 4 + nibble_offset
;
1370 u16 reg
= regs
[i
/ 4];
1372 entry
->data
[i
] = (reg
>> shift
) & GLOBAL_VTU_STU_DATA_MASK
;
1378 static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip
*chip
,
1379 struct mv88e6xxx_vtu_entry
*entry
)
1381 return _mv88e6xxx_vtu_stu_data_read(chip
, entry
, 0);
1384 static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip
*chip
,
1385 struct mv88e6xxx_vtu_entry
*entry
)
1387 return _mv88e6xxx_vtu_stu_data_read(chip
, entry
, 2);
1390 static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip
*chip
,
1391 struct mv88e6xxx_vtu_entry
*entry
,
1392 unsigned int nibble_offset
)
1394 u16 regs
[3] = { 0 };
1397 for (i
= 0; i
< mv88e6xxx_num_ports(chip
); ++i
) {
1398 unsigned int shift
= (i
% 4) * 4 + nibble_offset
;
1399 u8 data
= entry
->data
[i
];
1401 regs
[i
/ 4] |= (data
& GLOBAL_VTU_STU_DATA_MASK
) << shift
;
1404 for (i
= 0; i
< 3; ++i
) {
1407 err
= mv88e6xxx_g1_write(chip
, GLOBAL_VTU_DATA_0_3
+ i
, reg
);
1415 static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip
*chip
,
1416 struct mv88e6xxx_vtu_entry
*entry
)
1418 return _mv88e6xxx_vtu_stu_data_write(chip
, entry
, 0);
1421 static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip
*chip
,
1422 struct mv88e6xxx_vtu_entry
*entry
)
1424 return _mv88e6xxx_vtu_stu_data_write(chip
, entry
, 2);
1427 static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip
*chip
, u16 vid
)
1429 return mv88e6xxx_g1_write(chip
, GLOBAL_VTU_VID
,
1430 vid
& GLOBAL_VTU_VID_MASK
);
1433 static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip
*chip
,
1434 struct mv88e6xxx_vtu_entry
*entry
)
1436 struct mv88e6xxx_vtu_entry next
= { 0 };
1440 err
= _mv88e6xxx_vtu_wait(chip
);
1444 err
= _mv88e6xxx_vtu_cmd(chip
, GLOBAL_VTU_OP_VTU_GET_NEXT
);
1448 err
= mv88e6xxx_g1_read(chip
, GLOBAL_VTU_VID
, &val
);
1452 next
.vid
= val
& GLOBAL_VTU_VID_MASK
;
1453 next
.valid
= !!(val
& GLOBAL_VTU_VID_VALID
);
1456 err
= mv88e6xxx_vtu_data_read(chip
, &next
);
1460 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_G1_VTU_FID
)) {
1461 err
= mv88e6xxx_g1_read(chip
, GLOBAL_VTU_FID
, &val
);
1465 next
.fid
= val
& GLOBAL_VTU_FID_MASK
;
1466 } else if (mv88e6xxx_num_databases(chip
) == 256) {
1467 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1468 * VTU DBNum[3:0] are located in VTU Operation 3:0
1470 err
= mv88e6xxx_g1_read(chip
, GLOBAL_VTU_OP
, &val
);
1474 next
.fid
= (val
& 0xf00) >> 4;
1475 next
.fid
|= val
& 0xf;
1478 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_STU
)) {
1479 err
= mv88e6xxx_g1_read(chip
, GLOBAL_VTU_SID
, &val
);
1483 next
.sid
= val
& GLOBAL_VTU_SID_MASK
;
1491 static int mv88e6xxx_port_vlan_dump(struct dsa_switch
*ds
, int port
,
1492 struct switchdev_obj_port_vlan
*vlan
,
1493 int (*cb
)(struct switchdev_obj
*obj
))
1495 struct mv88e6xxx_chip
*chip
= ds
->priv
;
1496 struct mv88e6xxx_vtu_entry next
;
1500 if (!mv88e6xxx_has(chip
, MV88E6XXX_FLAG_VTU
))
1503 mutex_lock(&chip
->reg_lock
);
1505 err
= mv88e6xxx_port_get_pvid(chip
, port
, &pvid
);
1509 err
= _mv88e6xxx_vtu_vid_write(chip
, GLOBAL_VTU_VID_MASK
);
1514 err
= _mv88e6xxx_vtu_getnext(chip
, &next
);
1521 if (next
.data
[port
] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER
)
1524 /* reinit and dump this VLAN obj */
1525 vlan
->vid_begin
= next
.vid
;
1526 vlan
->vid_end
= next
.vid
;
1529 if (next
.data
[port
] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED
)
1530 vlan
->flags
|= BRIDGE_VLAN_INFO_UNTAGGED
;
1532 if (next
.vid
== pvid
)
1533 vlan
->flags
|= BRIDGE_VLAN_INFO_PVID
;
1535 err
= cb(&vlan
->obj
);
1538 } while (next
.vid
< GLOBAL_VTU_VID_MASK
);
1541 mutex_unlock(&chip
->reg_lock
);
1546 static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip
*chip
,
1547 struct mv88e6xxx_vtu_entry
*entry
)
1549 u16 op
= GLOBAL_VTU_OP_VTU_LOAD_PURGE
;
1553 err
= _mv88e6xxx_vtu_wait(chip
);
1560 /* Write port member tags */
1561 err
= mv88e6xxx_vtu_data_write(chip
, entry
);
1565 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_STU
)) {
1566 reg
= entry
->sid
& GLOBAL_VTU_SID_MASK
;
1567 err
= mv88e6xxx_g1_write(chip
, GLOBAL_VTU_SID
, reg
);
1572 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_G1_VTU_FID
)) {
1573 reg
= entry
->fid
& GLOBAL_VTU_FID_MASK
;
1574 err
= mv88e6xxx_g1_write(chip
, GLOBAL_VTU_FID
, reg
);
1577 } else if (mv88e6xxx_num_databases(chip
) == 256) {
1578 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1579 * VTU DBNum[3:0] are located in VTU Operation 3:0
1581 op
|= (entry
->fid
& 0xf0) << 8;
1582 op
|= entry
->fid
& 0xf;
1585 reg
= GLOBAL_VTU_VID_VALID
;
1587 reg
|= entry
->vid
& GLOBAL_VTU_VID_MASK
;
1588 err
= mv88e6xxx_g1_write(chip
, GLOBAL_VTU_VID
, reg
);
1592 return _mv88e6xxx_vtu_cmd(chip
, op
);
1595 static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip
*chip
, u8 sid
,
1596 struct mv88e6xxx_vtu_entry
*entry
)
1598 struct mv88e6xxx_vtu_entry next
= { 0 };
1602 err
= _mv88e6xxx_vtu_wait(chip
);
1606 err
= mv88e6xxx_g1_write(chip
, GLOBAL_VTU_SID
,
1607 sid
& GLOBAL_VTU_SID_MASK
);
1611 err
= _mv88e6xxx_vtu_cmd(chip
, GLOBAL_VTU_OP_STU_GET_NEXT
);
1615 err
= mv88e6xxx_g1_read(chip
, GLOBAL_VTU_SID
, &val
);
1619 next
.sid
= val
& GLOBAL_VTU_SID_MASK
;
1621 err
= mv88e6xxx_g1_read(chip
, GLOBAL_VTU_VID
, &val
);
1625 next
.valid
= !!(val
& GLOBAL_VTU_VID_VALID
);
1628 err
= mv88e6xxx_stu_data_read(chip
, &next
);
1637 static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip
*chip
,
1638 struct mv88e6xxx_vtu_entry
*entry
)
1643 err
= _mv88e6xxx_vtu_wait(chip
);
1650 /* Write port states */
1651 err
= mv88e6xxx_stu_data_write(chip
, entry
);
1655 reg
= GLOBAL_VTU_VID_VALID
;
1657 err
= mv88e6xxx_g1_write(chip
, GLOBAL_VTU_VID
, reg
);
1661 reg
= entry
->sid
& GLOBAL_VTU_SID_MASK
;
1662 err
= mv88e6xxx_g1_write(chip
, GLOBAL_VTU_SID
, reg
);
1666 return _mv88e6xxx_vtu_cmd(chip
, GLOBAL_VTU_OP_STU_LOAD_PURGE
);
1669 static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip
*chip
, u16
*fid
)
1671 DECLARE_BITMAP(fid_bitmap
, MV88E6XXX_N_FID
);
1672 struct mv88e6xxx_vtu_entry vlan
;
1675 bitmap_zero(fid_bitmap
, MV88E6XXX_N_FID
);
1677 /* Set every FID bit used by the (un)bridged ports */
1678 for (i
= 0; i
< mv88e6xxx_num_ports(chip
); ++i
) {
1679 err
= mv88e6xxx_port_get_fid(chip
, i
, fid
);
1683 set_bit(*fid
, fid_bitmap
);
1686 /* Set every FID bit used by the VLAN entries */
1687 err
= _mv88e6xxx_vtu_vid_write(chip
, GLOBAL_VTU_VID_MASK
);
1692 err
= _mv88e6xxx_vtu_getnext(chip
, &vlan
);
1699 set_bit(vlan
.fid
, fid_bitmap
);
1700 } while (vlan
.vid
< GLOBAL_VTU_VID_MASK
);
1702 /* The reset value 0x000 is used to indicate that multiple address
1703 * databases are not needed. Return the next positive available.
1705 *fid
= find_next_zero_bit(fid_bitmap
, MV88E6XXX_N_FID
, 1);
1706 if (unlikely(*fid
>= mv88e6xxx_num_databases(chip
)))
1709 /* Clear the database */
1710 return _mv88e6xxx_atu_flush(chip
, *fid
, true);
1713 static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip
*chip
, u16 vid
,
1714 struct mv88e6xxx_vtu_entry
*entry
)
1716 struct dsa_switch
*ds
= chip
->ds
;
1717 struct mv88e6xxx_vtu_entry vlan
= {
1723 err
= _mv88e6xxx_fid_new(chip
, &vlan
.fid
);
1727 /* exclude all ports except the CPU and DSA ports */
1728 for (i
= 0; i
< mv88e6xxx_num_ports(chip
); ++i
)
1729 vlan
.data
[i
] = dsa_is_cpu_port(ds
, i
) || dsa_is_dsa_port(ds
, i
)
1730 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1731 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER
;
1733 if (mv88e6xxx_6097_family(chip
) || mv88e6xxx_6165_family(chip
) ||
1734 mv88e6xxx_6351_family(chip
) || mv88e6xxx_6352_family(chip
)) {
1735 struct mv88e6xxx_vtu_entry vstp
;
1737 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1738 * implemented, only one STU entry is needed to cover all VTU
1739 * entries. Thus, validate the SID 0.
1742 err
= _mv88e6xxx_stu_getnext(chip
, GLOBAL_VTU_SID_MASK
, &vstp
);
1746 if (vstp
.sid
!= vlan
.sid
|| !vstp
.valid
) {
1747 memset(&vstp
, 0, sizeof(vstp
));
1749 vstp
.sid
= vlan
.sid
;
1751 err
= _mv88e6xxx_stu_loadpurge(chip
, &vstp
);
1761 static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip
*chip
, u16 vid
,
1762 struct mv88e6xxx_vtu_entry
*entry
, bool creat
)
1769 err
= _mv88e6xxx_vtu_vid_write(chip
, vid
- 1);
1773 err
= _mv88e6xxx_vtu_getnext(chip
, entry
);
1777 if (entry
->vid
!= vid
|| !entry
->valid
) {
1780 /* -ENOENT would've been more appropriate, but switchdev expects
1781 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1784 err
= _mv88e6xxx_vtu_new(chip
, vid
, entry
);
1790 static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch
*ds
, int port
,
1791 u16 vid_begin
, u16 vid_end
)
1793 struct mv88e6xxx_chip
*chip
= ds
->priv
;
1794 struct mv88e6xxx_vtu_entry vlan
;
1800 mutex_lock(&chip
->reg_lock
);
1802 err
= _mv88e6xxx_vtu_vid_write(chip
, vid_begin
- 1);
1807 err
= _mv88e6xxx_vtu_getnext(chip
, &vlan
);
1814 if (vlan
.vid
> vid_end
)
1817 for (i
= 0; i
< mv88e6xxx_num_ports(chip
); ++i
) {
1818 if (dsa_is_dsa_port(ds
, i
) || dsa_is_cpu_port(ds
, i
))
1822 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER
)
1825 if (chip
->ports
[i
].bridge_dev
==
1826 chip
->ports
[port
].bridge_dev
)
1827 break; /* same bridge, check next VLAN */
1829 netdev_warn(ds
->ports
[port
].netdev
,
1830 "hardware VLAN %d already used by %s\n",
1832 netdev_name(chip
->ports
[i
].bridge_dev
));
1836 } while (vlan
.vid
< vid_end
);
1839 mutex_unlock(&chip
->reg_lock
);
1844 static int mv88e6xxx_port_vlan_filtering(struct dsa_switch
*ds
, int port
,
1845 bool vlan_filtering
)
1847 struct mv88e6xxx_chip
*chip
= ds
->priv
;
1848 u16 mode
= vlan_filtering
? PORT_CONTROL_2_8021Q_SECURE
:
1849 PORT_CONTROL_2_8021Q_DISABLED
;
1852 if (!mv88e6xxx_has(chip
, MV88E6XXX_FLAG_VTU
))
1855 mutex_lock(&chip
->reg_lock
);
1856 err
= mv88e6xxx_port_set_8021q_mode(chip
, port
, mode
);
1857 mutex_unlock(&chip
->reg_lock
);
1863 mv88e6xxx_port_vlan_prepare(struct dsa_switch
*ds
, int port
,
1864 const struct switchdev_obj_port_vlan
*vlan
,
1865 struct switchdev_trans
*trans
)
1867 struct mv88e6xxx_chip
*chip
= ds
->priv
;
1870 if (!mv88e6xxx_has(chip
, MV88E6XXX_FLAG_VTU
))
1873 /* If the requested port doesn't belong to the same bridge as the VLAN
1874 * members, do not support it (yet) and fallback to software VLAN.
1876 err
= mv88e6xxx_port_check_hw_vlan(ds
, port
, vlan
->vid_begin
,
1881 /* We don't need any dynamic resource from the kernel (yet),
1882 * so skip the prepare phase.
1887 static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip
*chip
, int port
,
1888 u16 vid
, bool untagged
)
1890 struct mv88e6xxx_vtu_entry vlan
;
1893 err
= _mv88e6xxx_vtu_get(chip
, vid
, &vlan
, true);
1897 vlan
.data
[port
] = untagged
?
1898 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED
:
1899 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED
;
1901 return _mv88e6xxx_vtu_loadpurge(chip
, &vlan
);
1904 static void mv88e6xxx_port_vlan_add(struct dsa_switch
*ds
, int port
,
1905 const struct switchdev_obj_port_vlan
*vlan
,
1906 struct switchdev_trans
*trans
)
1908 struct mv88e6xxx_chip
*chip
= ds
->priv
;
1909 bool untagged
= vlan
->flags
& BRIDGE_VLAN_INFO_UNTAGGED
;
1910 bool pvid
= vlan
->flags
& BRIDGE_VLAN_INFO_PVID
;
1913 if (!mv88e6xxx_has(chip
, MV88E6XXX_FLAG_VTU
))
1916 mutex_lock(&chip
->reg_lock
);
1918 for (vid
= vlan
->vid_begin
; vid
<= vlan
->vid_end
; ++vid
)
1919 if (_mv88e6xxx_port_vlan_add(chip
, port
, vid
, untagged
))
1920 netdev_err(ds
->ports
[port
].netdev
,
1921 "failed to add VLAN %d%c\n",
1922 vid
, untagged
? 'u' : 't');
1924 if (pvid
&& mv88e6xxx_port_set_pvid(chip
, port
, vlan
->vid_end
))
1925 netdev_err(ds
->ports
[port
].netdev
, "failed to set PVID %d\n",
1928 mutex_unlock(&chip
->reg_lock
);
1931 static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip
*chip
,
1934 struct dsa_switch
*ds
= chip
->ds
;
1935 struct mv88e6xxx_vtu_entry vlan
;
1938 err
= _mv88e6xxx_vtu_get(chip
, vid
, &vlan
, false);
1942 /* Tell switchdev if this VLAN is handled in software */
1943 if (vlan
.data
[port
] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER
)
1946 vlan
.data
[port
] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER
;
1948 /* keep the VLAN unless all ports are excluded */
1950 for (i
= 0; i
< mv88e6xxx_num_ports(chip
); ++i
) {
1951 if (dsa_is_cpu_port(ds
, i
) || dsa_is_dsa_port(ds
, i
))
1954 if (vlan
.data
[i
] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER
) {
1960 err
= _mv88e6xxx_vtu_loadpurge(chip
, &vlan
);
1964 return _mv88e6xxx_atu_remove(chip
, vlan
.fid
, port
, false);
1967 static int mv88e6xxx_port_vlan_del(struct dsa_switch
*ds
, int port
,
1968 const struct switchdev_obj_port_vlan
*vlan
)
1970 struct mv88e6xxx_chip
*chip
= ds
->priv
;
1974 if (!mv88e6xxx_has(chip
, MV88E6XXX_FLAG_VTU
))
1977 mutex_lock(&chip
->reg_lock
);
1979 err
= mv88e6xxx_port_get_pvid(chip
, port
, &pvid
);
1983 for (vid
= vlan
->vid_begin
; vid
<= vlan
->vid_end
; ++vid
) {
1984 err
= _mv88e6xxx_port_vlan_del(chip
, port
, vid
);
1989 err
= mv88e6xxx_port_set_pvid(chip
, port
, 0);
1996 mutex_unlock(&chip
->reg_lock
);
2001 static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip
*chip
,
2002 const unsigned char *addr
)
2006 for (i
= 0; i
< 3; i
++) {
2007 err
= mv88e6xxx_g1_write(chip
, GLOBAL_ATU_MAC_01
+ i
,
2008 (addr
[i
* 2] << 8) | addr
[i
* 2 + 1]);
2016 static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip
*chip
,
2017 unsigned char *addr
)
2022 for (i
= 0; i
< 3; i
++) {
2023 err
= mv88e6xxx_g1_read(chip
, GLOBAL_ATU_MAC_01
+ i
, &val
);
2027 addr
[i
* 2] = val
>> 8;
2028 addr
[i
* 2 + 1] = val
& 0xff;
2034 static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip
*chip
,
2035 struct mv88e6xxx_atu_entry
*entry
)
2039 ret
= _mv88e6xxx_atu_wait(chip
);
2043 ret
= _mv88e6xxx_atu_mac_write(chip
, entry
->mac
);
2047 ret
= _mv88e6xxx_atu_data_write(chip
, entry
);
2051 return _mv88e6xxx_atu_cmd(chip
, entry
->fid
, GLOBAL_ATU_OP_LOAD_DB
);
2054 static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip
*chip
, u16 fid
,
2055 struct mv88e6xxx_atu_entry
*entry
);
2057 static int mv88e6xxx_atu_get(struct mv88e6xxx_chip
*chip
, int fid
,
2058 const u8
*addr
, struct mv88e6xxx_atu_entry
*entry
)
2060 struct mv88e6xxx_atu_entry next
;
2063 eth_broadcast_addr(next
.mac
);
2065 err
= _mv88e6xxx_atu_mac_write(chip
, next
.mac
);
2070 err
= _mv88e6xxx_atu_getnext(chip
, fid
, &next
);
2074 if (next
.state
== GLOBAL_ATU_DATA_STATE_UNUSED
)
2077 if (ether_addr_equal(next
.mac
, addr
)) {
2081 } while (!is_broadcast_ether_addr(next
.mac
));
2083 memset(entry
, 0, sizeof(*entry
));
2085 ether_addr_copy(entry
->mac
, addr
);
2090 static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip
*chip
, int port
,
2091 const unsigned char *addr
, u16 vid
,
2094 struct mv88e6xxx_vtu_entry vlan
;
2095 struct mv88e6xxx_atu_entry entry
;
2098 /* Null VLAN ID corresponds to the port private database */
2100 err
= mv88e6xxx_port_get_fid(chip
, port
, &vlan
.fid
);
2102 err
= _mv88e6xxx_vtu_get(chip
, vid
, &vlan
, false);
2106 err
= mv88e6xxx_atu_get(chip
, vlan
.fid
, addr
, &entry
);
2110 /* Purge the ATU entry only if no port is using it anymore */
2111 if (state
== GLOBAL_ATU_DATA_STATE_UNUSED
) {
2112 entry
.portv_trunkid
&= ~BIT(port
);
2113 if (!entry
.portv_trunkid
)
2114 entry
.state
= GLOBAL_ATU_DATA_STATE_UNUSED
;
2116 entry
.portv_trunkid
|= BIT(port
);
2117 entry
.state
= state
;
2120 return _mv88e6xxx_atu_load(chip
, &entry
);
2123 static int mv88e6xxx_port_fdb_prepare(struct dsa_switch
*ds
, int port
,
2124 const struct switchdev_obj_port_fdb
*fdb
,
2125 struct switchdev_trans
*trans
)
2127 /* We don't need any dynamic resource from the kernel (yet),
2128 * so skip the prepare phase.
2133 static void mv88e6xxx_port_fdb_add(struct dsa_switch
*ds
, int port
,
2134 const struct switchdev_obj_port_fdb
*fdb
,
2135 struct switchdev_trans
*trans
)
2137 struct mv88e6xxx_chip
*chip
= ds
->priv
;
2139 mutex_lock(&chip
->reg_lock
);
2140 if (mv88e6xxx_port_db_load_purge(chip
, port
, fdb
->addr
, fdb
->vid
,
2141 GLOBAL_ATU_DATA_STATE_UC_STATIC
))
2142 netdev_err(ds
->ports
[port
].netdev
, "failed to load unicast MAC address\n");
2143 mutex_unlock(&chip
->reg_lock
);
2146 static int mv88e6xxx_port_fdb_del(struct dsa_switch
*ds
, int port
,
2147 const struct switchdev_obj_port_fdb
*fdb
)
2149 struct mv88e6xxx_chip
*chip
= ds
->priv
;
2152 mutex_lock(&chip
->reg_lock
);
2153 err
= mv88e6xxx_port_db_load_purge(chip
, port
, fdb
->addr
, fdb
->vid
,
2154 GLOBAL_ATU_DATA_STATE_UNUSED
);
2155 mutex_unlock(&chip
->reg_lock
);
2160 static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip
*chip
, u16 fid
,
2161 struct mv88e6xxx_atu_entry
*entry
)
2163 struct mv88e6xxx_atu_entry next
= { 0 };
2169 err
= _mv88e6xxx_atu_wait(chip
);
2173 err
= _mv88e6xxx_atu_cmd(chip
, fid
, GLOBAL_ATU_OP_GET_NEXT_DB
);
2177 err
= _mv88e6xxx_atu_mac_read(chip
, next
.mac
);
2181 err
= mv88e6xxx_g1_read(chip
, GLOBAL_ATU_DATA
, &val
);
2185 next
.state
= val
& GLOBAL_ATU_DATA_STATE_MASK
;
2186 if (next
.state
!= GLOBAL_ATU_DATA_STATE_UNUSED
) {
2187 unsigned int mask
, shift
;
2189 if (val
& GLOBAL_ATU_DATA_TRUNK
) {
2191 mask
= GLOBAL_ATU_DATA_TRUNK_ID_MASK
;
2192 shift
= GLOBAL_ATU_DATA_TRUNK_ID_SHIFT
;
2195 mask
= GLOBAL_ATU_DATA_PORT_VECTOR_MASK
;
2196 shift
= GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT
;
2199 next
.portv_trunkid
= (val
& mask
) >> shift
;
2206 static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip
*chip
,
2207 u16 fid
, u16 vid
, int port
,
2208 struct switchdev_obj
*obj
,
2209 int (*cb
)(struct switchdev_obj
*obj
))
2211 struct mv88e6xxx_atu_entry addr
= {
2212 .mac
= { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2216 err
= _mv88e6xxx_atu_mac_write(chip
, addr
.mac
);
2221 err
= _mv88e6xxx_atu_getnext(chip
, fid
, &addr
);
2225 if (addr
.state
== GLOBAL_ATU_DATA_STATE_UNUSED
)
2228 if (addr
.trunk
|| (addr
.portv_trunkid
& BIT(port
)) == 0)
2231 if (obj
->id
== SWITCHDEV_OBJ_ID_PORT_FDB
) {
2232 struct switchdev_obj_port_fdb
*fdb
;
2234 if (!is_unicast_ether_addr(addr
.mac
))
2237 fdb
= SWITCHDEV_OBJ_PORT_FDB(obj
);
2239 ether_addr_copy(fdb
->addr
, addr
.mac
);
2240 if (addr
.state
== GLOBAL_ATU_DATA_STATE_UC_STATIC
)
2241 fdb
->ndm_state
= NUD_NOARP
;
2243 fdb
->ndm_state
= NUD_REACHABLE
;
2244 } else if (obj
->id
== SWITCHDEV_OBJ_ID_PORT_MDB
) {
2245 struct switchdev_obj_port_mdb
*mdb
;
2247 if (!is_multicast_ether_addr(addr
.mac
))
2250 mdb
= SWITCHDEV_OBJ_PORT_MDB(obj
);
2252 ether_addr_copy(mdb
->addr
, addr
.mac
);
2260 } while (!is_broadcast_ether_addr(addr
.mac
));
2265 static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip
*chip
, int port
,
2266 struct switchdev_obj
*obj
,
2267 int (*cb
)(struct switchdev_obj
*obj
))
2269 struct mv88e6xxx_vtu_entry vlan
= {
2270 .vid
= GLOBAL_VTU_VID_MASK
, /* all ones */
2275 /* Dump port's default Filtering Information Database (VLAN ID 0) */
2276 err
= mv88e6xxx_port_get_fid(chip
, port
, &fid
);
2280 err
= mv88e6xxx_port_db_dump_fid(chip
, fid
, 0, port
, obj
, cb
);
2284 /* Dump VLANs' Filtering Information Databases */
2285 err
= _mv88e6xxx_vtu_vid_write(chip
, vlan
.vid
);
2290 err
= _mv88e6xxx_vtu_getnext(chip
, &vlan
);
2297 err
= mv88e6xxx_port_db_dump_fid(chip
, vlan
.fid
, vlan
.vid
, port
,
2301 } while (vlan
.vid
< GLOBAL_VTU_VID_MASK
);
2306 static int mv88e6xxx_port_fdb_dump(struct dsa_switch
*ds
, int port
,
2307 struct switchdev_obj_port_fdb
*fdb
,
2308 int (*cb
)(struct switchdev_obj
*obj
))
2310 struct mv88e6xxx_chip
*chip
= ds
->priv
;
2313 mutex_lock(&chip
->reg_lock
);
2314 err
= mv88e6xxx_port_db_dump(chip
, port
, &fdb
->obj
, cb
);
2315 mutex_unlock(&chip
->reg_lock
);
2320 static int mv88e6xxx_port_bridge_join(struct dsa_switch
*ds
, int port
,
2321 struct net_device
*bridge
)
2323 struct mv88e6xxx_chip
*chip
= ds
->priv
;
2326 mutex_lock(&chip
->reg_lock
);
2328 /* Assign the bridge and remap each port's VLANTable */
2329 chip
->ports
[port
].bridge_dev
= bridge
;
2331 for (i
= 0; i
< mv88e6xxx_num_ports(chip
); ++i
) {
2332 if (chip
->ports
[i
].bridge_dev
== bridge
) {
2333 err
= _mv88e6xxx_port_based_vlan_map(chip
, i
);
2339 mutex_unlock(&chip
->reg_lock
);
2344 static void mv88e6xxx_port_bridge_leave(struct dsa_switch
*ds
, int port
)
2346 struct mv88e6xxx_chip
*chip
= ds
->priv
;
2347 struct net_device
*bridge
= chip
->ports
[port
].bridge_dev
;
2350 mutex_lock(&chip
->reg_lock
);
2352 /* Unassign the bridge and remap each port's VLANTable */
2353 chip
->ports
[port
].bridge_dev
= NULL
;
2355 for (i
= 0; i
< mv88e6xxx_num_ports(chip
); ++i
)
2356 if (i
== port
|| chip
->ports
[i
].bridge_dev
== bridge
)
2357 if (_mv88e6xxx_port_based_vlan_map(chip
, i
))
2358 netdev_warn(ds
->ports
[i
].netdev
,
2359 "failed to remap\n");
2361 mutex_unlock(&chip
->reg_lock
);
2364 static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip
*chip
)
2366 bool ppu_active
= mv88e6xxx_has(chip
, MV88E6XXX_FLAG_PPU_ACTIVE
);
2367 u16 is_reset
= (ppu_active
? 0x8800 : 0xc800);
2368 struct gpio_desc
*gpiod
= chip
->reset
;
2369 unsigned long timeout
;
2374 /* Set all ports to the disabled state. */
2375 for (i
= 0; i
< mv88e6xxx_num_ports(chip
); i
++) {
2376 err
= mv88e6xxx_port_set_state(chip
, i
,
2377 PORT_CONTROL_STATE_DISABLED
);
2382 /* Wait for transmit queues to drain. */
2383 usleep_range(2000, 4000);
2385 /* If there is a gpio connected to the reset pin, toggle it */
2387 gpiod_set_value_cansleep(gpiod
, 1);
2388 usleep_range(10000, 20000);
2389 gpiod_set_value_cansleep(gpiod
, 0);
2390 usleep_range(10000, 20000);
2393 /* Reset the switch. Keep the PPU active if requested. The PPU
2394 * needs to be active to support indirect phy register access
2395 * through global registers 0x18 and 0x19.
2398 err
= mv88e6xxx_g1_write(chip
, 0x04, 0xc000);
2400 err
= mv88e6xxx_g1_write(chip
, 0x04, 0xc400);
2404 /* Wait up to one second for reset to complete. */
2405 timeout
= jiffies
+ 1 * HZ
;
2406 while (time_before(jiffies
, timeout
)) {
2407 err
= mv88e6xxx_g1_read(chip
, 0x00, ®
);
2411 if ((reg
& is_reset
) == is_reset
)
2413 usleep_range(1000, 2000);
2415 if (time_after(jiffies
, timeout
))
2423 static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip
*chip
)
2428 /* Clear Power Down bit */
2429 err
= mv88e6xxx_serdes_read(chip
, MII_BMCR
, &val
);
2433 if (val
& BMCR_PDOWN
) {
2435 err
= mv88e6xxx_serdes_write(chip
, MII_BMCR
, val
);
2441 static int mv88e6xxx_setup_port(struct mv88e6xxx_chip
*chip
, int port
)
2443 struct dsa_switch
*ds
= chip
->ds
;
2447 /* MAC Forcing register: don't force link, speed, duplex or flow control
2448 * state to any particular values on physical ports, but force the CPU
2449 * port and all DSA ports to their maximum bandwidth and full duplex.
2451 if (dsa_is_cpu_port(ds
, port
) || dsa_is_dsa_port(ds
, port
))
2452 err
= mv88e6xxx_port_setup_mac(chip
, port
, LINK_FORCED_UP
,
2453 SPEED_MAX
, DUPLEX_FULL
,
2454 PHY_INTERFACE_MODE_NA
);
2456 err
= mv88e6xxx_port_setup_mac(chip
, port
, LINK_UNFORCED
,
2457 SPEED_UNFORCED
, DUPLEX_UNFORCED
,
2458 PHY_INTERFACE_MODE_NA
);
2462 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2463 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2464 * tunneling, determine priority by looking at 802.1p and IP
2465 * priority fields (IP prio has precedence), and set STP state
2468 * If this is the CPU link, use DSA or EDSA tagging depending
2469 * on which tagging mode was configured.
2471 * If this is a link to another switch, use DSA tagging mode.
2473 * If this is the upstream port for this switch, enable
2474 * forwarding of unknown unicasts and multicasts.
2477 if (mv88e6xxx_6352_family(chip
) || mv88e6xxx_6351_family(chip
) ||
2478 mv88e6xxx_6165_family(chip
) || mv88e6xxx_6097_family(chip
) ||
2479 mv88e6xxx_6095_family(chip
) || mv88e6xxx_6065_family(chip
) ||
2480 mv88e6xxx_6185_family(chip
) || mv88e6xxx_6320_family(chip
))
2481 reg
= PORT_CONTROL_IGMP_MLD_SNOOP
|
2482 PORT_CONTROL_USE_TAG
| PORT_CONTROL_USE_IP
|
2483 PORT_CONTROL_STATE_FORWARDING
;
2484 if (dsa_is_cpu_port(ds
, port
)) {
2485 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_EDSA
))
2486 reg
|= PORT_CONTROL_FRAME_ETHER_TYPE_DSA
|
2487 PORT_CONTROL_FORWARD_UNKNOWN_MC
;
2489 reg
|= PORT_CONTROL_DSA_TAG
;
2490 reg
|= PORT_CONTROL_EGRESS_ADD_TAG
|
2491 PORT_CONTROL_FORWARD_UNKNOWN
;
2493 if (dsa_is_dsa_port(ds
, port
)) {
2494 if (mv88e6xxx_6095_family(chip
) ||
2495 mv88e6xxx_6185_family(chip
))
2496 reg
|= PORT_CONTROL_DSA_TAG
;
2497 if (mv88e6xxx_6352_family(chip
) ||
2498 mv88e6xxx_6351_family(chip
) ||
2499 mv88e6xxx_6165_family(chip
) ||
2500 mv88e6xxx_6097_family(chip
) ||
2501 mv88e6xxx_6320_family(chip
)) {
2502 reg
|= PORT_CONTROL_FRAME_MODE_DSA
;
2505 if (port
== dsa_upstream_port(ds
))
2506 reg
|= PORT_CONTROL_FORWARD_UNKNOWN
|
2507 PORT_CONTROL_FORWARD_UNKNOWN_MC
;
2510 err
= mv88e6xxx_port_write(chip
, port
, PORT_CONTROL
, reg
);
2515 /* If this port is connected to a SerDes, make sure the SerDes is not
2518 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAGS_SERDES
)) {
2519 err
= mv88e6xxx_port_read(chip
, port
, PORT_STATUS
, ®
);
2522 reg
&= PORT_STATUS_CMODE_MASK
;
2523 if ((reg
== PORT_STATUS_CMODE_100BASE_X
) ||
2524 (reg
== PORT_STATUS_CMODE_1000BASE_X
) ||
2525 (reg
== PORT_STATUS_CMODE_SGMII
)) {
2526 err
= mv88e6xxx_serdes_power_on(chip
);
2532 /* Port Control 2: don't force a good FCS, set the maximum frame size to
2533 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2534 * untagged frames on this port, do a destination address lookup on all
2535 * received packets as usual, disable ARP mirroring and don't send a
2536 * copy of all transmitted/received frames on this port to the CPU.
2539 if (mv88e6xxx_6352_family(chip
) || mv88e6xxx_6351_family(chip
) ||
2540 mv88e6xxx_6165_family(chip
) || mv88e6xxx_6097_family(chip
) ||
2541 mv88e6xxx_6095_family(chip
) || mv88e6xxx_6320_family(chip
) ||
2542 mv88e6xxx_6185_family(chip
))
2543 reg
= PORT_CONTROL_2_MAP_DA
;
2545 if (mv88e6xxx_6352_family(chip
) || mv88e6xxx_6351_family(chip
) ||
2546 mv88e6xxx_6165_family(chip
) || mv88e6xxx_6320_family(chip
))
2547 reg
|= PORT_CONTROL_2_JUMBO_10240
;
2549 if (mv88e6xxx_6095_family(chip
) || mv88e6xxx_6185_family(chip
)) {
2550 /* Set the upstream port this port should use */
2551 reg
|= dsa_upstream_port(ds
);
2552 /* enable forwarding of unknown multicast addresses to
2555 if (port
== dsa_upstream_port(ds
))
2556 reg
|= PORT_CONTROL_2_FORWARD_UNKNOWN
;
2559 reg
|= PORT_CONTROL_2_8021Q_DISABLED
;
2562 err
= mv88e6xxx_port_write(chip
, port
, PORT_CONTROL_2
, reg
);
2567 /* Port Association Vector: when learning source addresses
2568 * of packets, add the address to the address database using
2569 * a port bitmap that has only the bit for this port set and
2570 * the other bits clear.
2573 /* Disable learning for CPU port */
2574 if (dsa_is_cpu_port(ds
, port
))
2577 err
= mv88e6xxx_port_write(chip
, port
, PORT_ASSOC_VECTOR
, reg
);
2581 /* Egress rate control 2: disable egress rate control. */
2582 err
= mv88e6xxx_port_write(chip
, port
, PORT_RATE_CONTROL_2
, 0x0000);
2586 if (mv88e6xxx_6352_family(chip
) || mv88e6xxx_6351_family(chip
) ||
2587 mv88e6xxx_6165_family(chip
) || mv88e6xxx_6097_family(chip
) ||
2588 mv88e6xxx_6320_family(chip
)) {
2589 /* Do not limit the period of time that this port can
2590 * be paused for by the remote end or the period of
2591 * time that this port can pause the remote end.
2593 err
= mv88e6xxx_port_write(chip
, port
, PORT_PAUSE_CTRL
, 0x0000);
2597 /* Port ATU control: disable limiting the number of
2598 * address database entries that this port is allowed
2601 err
= mv88e6xxx_port_write(chip
, port
, PORT_ATU_CONTROL
,
2603 /* Priority Override: disable DA, SA and VTU priority
2606 err
= mv88e6xxx_port_write(chip
, port
, PORT_PRI_OVERRIDE
,
2611 /* Port Ethertype: use the Ethertype DSA Ethertype
2614 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_EDSA
)) {
2615 err
= mv88e6xxx_port_write(chip
, port
, PORT_ETH_TYPE
,
2621 /* Tag Remap: use an identity 802.1p prio -> switch
2624 err
= mv88e6xxx_port_write(chip
, port
, PORT_TAG_REGMAP_0123
,
2629 /* Tag Remap 2: use an identity 802.1p prio -> switch
2632 err
= mv88e6xxx_port_write(chip
, port
, PORT_TAG_REGMAP_4567
,
2638 /* Rate Control: disable ingress rate limiting. */
2639 if (mv88e6xxx_6352_family(chip
) || mv88e6xxx_6351_family(chip
) ||
2640 mv88e6xxx_6165_family(chip
) || mv88e6xxx_6097_family(chip
) ||
2641 mv88e6xxx_6320_family(chip
)) {
2642 err
= mv88e6xxx_port_write(chip
, port
, PORT_RATE_CONTROL
,
2646 } else if (mv88e6xxx_6185_family(chip
) || mv88e6xxx_6095_family(chip
)) {
2647 err
= mv88e6xxx_port_write(chip
, port
, PORT_RATE_CONTROL
,
2653 /* Port Control 1: disable trunking, disable sending
2654 * learning messages to this port.
2656 err
= mv88e6xxx_port_write(chip
, port
, PORT_CONTROL_1
, 0x0000);
2660 /* Port based VLAN map: give each port the same default address
2661 * database, and allow bidirectional communication between the
2662 * CPU and DSA port(s), and the other ports.
2664 err
= mv88e6xxx_port_set_fid(chip
, port
, 0);
2668 err
= _mv88e6xxx_port_based_vlan_map(chip
, port
);
2672 /* Default VLAN ID and priority: don't set a default VLAN
2673 * ID, and set the default packet priority to zero.
2675 return mv88e6xxx_port_write(chip
, port
, PORT_DEFAULT_VLAN
, 0x0000);
2678 static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip
*chip
, u8
*addr
)
2682 err
= mv88e6xxx_g1_write(chip
, GLOBAL_MAC_01
, (addr
[0] << 8) | addr
[1]);
2686 err
= mv88e6xxx_g1_write(chip
, GLOBAL_MAC_23
, (addr
[2] << 8) | addr
[3]);
2690 err
= mv88e6xxx_g1_write(chip
, GLOBAL_MAC_45
, (addr
[4] << 8) | addr
[5]);
2697 static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip
*chip
,
2700 const unsigned int coeff
= chip
->info
->age_time_coeff
;
2701 const unsigned int min
= 0x01 * coeff
;
2702 const unsigned int max
= 0xff * coeff
;
2707 if (msecs
< min
|| msecs
> max
)
2710 /* Round to nearest multiple of coeff */
2711 age_time
= (msecs
+ coeff
/ 2) / coeff
;
2713 err
= mv88e6xxx_g1_read(chip
, GLOBAL_ATU_CONTROL
, &val
);
2717 /* AgeTime is 11:4 bits */
2719 val
|= age_time
<< 4;
2721 return mv88e6xxx_g1_write(chip
, GLOBAL_ATU_CONTROL
, val
);
2724 static int mv88e6xxx_set_ageing_time(struct dsa_switch
*ds
,
2725 unsigned int ageing_time
)
2727 struct mv88e6xxx_chip
*chip
= ds
->priv
;
2730 mutex_lock(&chip
->reg_lock
);
2731 err
= mv88e6xxx_g1_set_age_time(chip
, ageing_time
);
2732 mutex_unlock(&chip
->reg_lock
);
2737 static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip
*chip
)
2739 struct dsa_switch
*ds
= chip
->ds
;
2740 u32 upstream_port
= dsa_upstream_port(ds
);
2744 /* Enable the PHY Polling Unit if present, don't discard any packets,
2745 * and mask all interrupt sources.
2747 err
= mv88e6xxx_g1_read(chip
, GLOBAL_CONTROL
, ®
);
2751 reg
&= ~GLOBAL_CONTROL_PPU_ENABLE
;
2752 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_PPU
) ||
2753 mv88e6xxx_has(chip
, MV88E6XXX_FLAG_PPU_ACTIVE
))
2754 reg
|= GLOBAL_CONTROL_PPU_ENABLE
;
2756 err
= mv88e6xxx_g1_write(chip
, GLOBAL_CONTROL
, reg
);
2760 /* Configure the upstream port, and configure it as the port to which
2761 * ingress and egress and ARP monitor frames are to be sent.
2763 reg
= upstream_port
<< GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT
|
2764 upstream_port
<< GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT
|
2765 upstream_port
<< GLOBAL_MONITOR_CONTROL_ARP_SHIFT
;
2766 err
= mv88e6xxx_g1_write(chip
, GLOBAL_MONITOR_CONTROL
, reg
);
2770 /* Disable remote management, and set the switch's DSA device number. */
2771 err
= mv88e6xxx_g1_write(chip
, GLOBAL_CONTROL_2
,
2772 GLOBAL_CONTROL_2_MULTIPLE_CASCADE
|
2773 (ds
->index
& 0x1f));
2777 /* Clear all the VTU and STU entries */
2778 err
= _mv88e6xxx_vtu_stu_flush(chip
);
2782 /* Set the default address aging time to 5 minutes, and
2783 * enable address learn messages to be sent to all message
2786 err
= mv88e6xxx_g1_write(chip
, GLOBAL_ATU_CONTROL
,
2787 GLOBAL_ATU_CONTROL_LEARN2ALL
);
2791 err
= mv88e6xxx_g1_set_age_time(chip
, 300000);
2795 /* Clear all ATU entries */
2796 err
= _mv88e6xxx_atu_flush(chip
, 0, true);
2800 /* Configure the IP ToS mapping registers. */
2801 err
= mv88e6xxx_g1_write(chip
, GLOBAL_IP_PRI_0
, 0x0000);
2804 err
= mv88e6xxx_g1_write(chip
, GLOBAL_IP_PRI_1
, 0x0000);
2807 err
= mv88e6xxx_g1_write(chip
, GLOBAL_IP_PRI_2
, 0x5555);
2810 err
= mv88e6xxx_g1_write(chip
, GLOBAL_IP_PRI_3
, 0x5555);
2813 err
= mv88e6xxx_g1_write(chip
, GLOBAL_IP_PRI_4
, 0xaaaa);
2816 err
= mv88e6xxx_g1_write(chip
, GLOBAL_IP_PRI_5
, 0xaaaa);
2819 err
= mv88e6xxx_g1_write(chip
, GLOBAL_IP_PRI_6
, 0xffff);
2822 err
= mv88e6xxx_g1_write(chip
, GLOBAL_IP_PRI_7
, 0xffff);
2826 /* Configure the IEEE 802.1p priority mapping register. */
2827 err
= mv88e6xxx_g1_write(chip
, GLOBAL_IEEE_PRI
, 0xfa41);
2831 /* Initialize the statistics unit */
2832 err
= mv88e6xxx_stats_set_histogram(chip
);
2836 /* Clear the statistics counters for all ports */
2837 err
= mv88e6xxx_g1_write(chip
, GLOBAL_STATS_OP
,
2838 GLOBAL_STATS_OP_FLUSH_ALL
);
2842 /* Wait for the flush to complete. */
2843 err
= mv88e6xxx_g1_stats_wait(chip
);
2850 static int mv88e6xxx_setup(struct dsa_switch
*ds
)
2852 struct mv88e6xxx_chip
*chip
= ds
->priv
;
2857 ds
->slave_mii_bus
= chip
->mdio_bus
;
2859 mutex_lock(&chip
->reg_lock
);
2861 /* Setup Switch Port Registers */
2862 for (i
= 0; i
< mv88e6xxx_num_ports(chip
); i
++) {
2863 err
= mv88e6xxx_setup_port(chip
, i
);
2868 /* Setup Switch Global 1 Registers */
2869 err
= mv88e6xxx_g1_setup(chip
);
2873 /* Setup Switch Global 2 Registers */
2874 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_GLOBAL2
)) {
2875 err
= mv88e6xxx_g2_setup(chip
);
2881 mutex_unlock(&chip
->reg_lock
);
2886 static int mv88e6xxx_set_addr(struct dsa_switch
*ds
, u8
*addr
)
2888 struct mv88e6xxx_chip
*chip
= ds
->priv
;
2891 if (!chip
->info
->ops
->set_switch_mac
)
2894 mutex_lock(&chip
->reg_lock
);
2895 err
= chip
->info
->ops
->set_switch_mac(chip
, addr
);
2896 mutex_unlock(&chip
->reg_lock
);
2901 static int mv88e6xxx_mdio_read(struct mii_bus
*bus
, int phy
, int reg
)
2903 struct mv88e6xxx_chip
*chip
= bus
->priv
;
2907 if (phy
>= mv88e6xxx_num_ports(chip
))
2910 mutex_lock(&chip
->reg_lock
);
2911 err
= mv88e6xxx_phy_read(chip
, phy
, reg
, &val
);
2912 mutex_unlock(&chip
->reg_lock
);
2914 return err
? err
: val
;
2917 static int mv88e6xxx_mdio_write(struct mii_bus
*bus
, int phy
, int reg
, u16 val
)
2919 struct mv88e6xxx_chip
*chip
= bus
->priv
;
2922 if (phy
>= mv88e6xxx_num_ports(chip
))
2925 mutex_lock(&chip
->reg_lock
);
2926 err
= mv88e6xxx_phy_write(chip
, phy
, reg
, val
);
2927 mutex_unlock(&chip
->reg_lock
);
2932 static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip
*chip
,
2933 struct device_node
*np
)
2936 struct mii_bus
*bus
;
2940 chip
->mdio_np
= of_get_child_by_name(np
, "mdio");
2942 bus
= devm_mdiobus_alloc(chip
->dev
);
2946 bus
->priv
= (void *)chip
;
2948 bus
->name
= np
->full_name
;
2949 snprintf(bus
->id
, MII_BUS_ID_SIZE
, "%s", np
->full_name
);
2951 bus
->name
= "mv88e6xxx SMI";
2952 snprintf(bus
->id
, MII_BUS_ID_SIZE
, "mv88e6xxx-%d", index
++);
2955 bus
->read
= mv88e6xxx_mdio_read
;
2956 bus
->write
= mv88e6xxx_mdio_write
;
2957 bus
->parent
= chip
->dev
;
2960 err
= of_mdiobus_register(bus
, chip
->mdio_np
);
2962 err
= mdiobus_register(bus
);
2964 dev_err(chip
->dev
, "Cannot register MDIO bus (%d)\n", err
);
2967 chip
->mdio_bus
= bus
;
2973 of_node_put(chip
->mdio_np
);
2978 static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip
*chip
)
2981 struct mii_bus
*bus
= chip
->mdio_bus
;
2983 mdiobus_unregister(bus
);
2986 of_node_put(chip
->mdio_np
);
2989 #ifdef CONFIG_NET_DSA_HWMON
2991 static int mv88e61xx_get_temp(struct dsa_switch
*ds
, int *temp
)
2993 struct mv88e6xxx_chip
*chip
= ds
->priv
;
2999 mutex_lock(&chip
->reg_lock
);
3001 ret
= mv88e6xxx_phy_write(chip
, 0x0, 0x16, 0x6);
3005 /* Enable temperature sensor */
3006 ret
= mv88e6xxx_phy_read(chip
, 0x0, 0x1a, &val
);
3010 ret
= mv88e6xxx_phy_write(chip
, 0x0, 0x1a, val
| (1 << 5));
3014 /* Wait for temperature to stabilize */
3015 usleep_range(10000, 12000);
3017 ret
= mv88e6xxx_phy_read(chip
, 0x0, 0x1a, &val
);
3021 /* Disable temperature sensor */
3022 ret
= mv88e6xxx_phy_write(chip
, 0x0, 0x1a, val
& ~(1 << 5));
3026 *temp
= ((val
& 0x1f) - 5) * 5;
3029 mv88e6xxx_phy_write(chip
, 0x0, 0x16, 0x0);
3030 mutex_unlock(&chip
->reg_lock
);
3034 static int mv88e63xx_get_temp(struct dsa_switch
*ds
, int *temp
)
3036 struct mv88e6xxx_chip
*chip
= ds
->priv
;
3037 int phy
= mv88e6xxx_6320_family(chip
) ? 3 : 0;
3043 mutex_lock(&chip
->reg_lock
);
3044 ret
= mv88e6xxx_phy_page_read(chip
, phy
, 6, 27, &val
);
3045 mutex_unlock(&chip
->reg_lock
);
3049 *temp
= (val
& 0xff) - 25;
3054 static int mv88e6xxx_get_temp(struct dsa_switch
*ds
, int *temp
)
3056 struct mv88e6xxx_chip
*chip
= ds
->priv
;
3058 if (!mv88e6xxx_has(chip
, MV88E6XXX_FLAG_TEMP
))
3061 if (mv88e6xxx_6320_family(chip
) || mv88e6xxx_6352_family(chip
))
3062 return mv88e63xx_get_temp(ds
, temp
);
3064 return mv88e61xx_get_temp(ds
, temp
);
3067 static int mv88e6xxx_get_temp_limit(struct dsa_switch
*ds
, int *temp
)
3069 struct mv88e6xxx_chip
*chip
= ds
->priv
;
3070 int phy
= mv88e6xxx_6320_family(chip
) ? 3 : 0;
3074 if (!mv88e6xxx_has(chip
, MV88E6XXX_FLAG_TEMP_LIMIT
))
3079 mutex_lock(&chip
->reg_lock
);
3080 ret
= mv88e6xxx_phy_page_read(chip
, phy
, 6, 26, &val
);
3081 mutex_unlock(&chip
->reg_lock
);
3085 *temp
= (((val
>> 8) & 0x1f) * 5) - 25;
3090 static int mv88e6xxx_set_temp_limit(struct dsa_switch
*ds
, int temp
)
3092 struct mv88e6xxx_chip
*chip
= ds
->priv
;
3093 int phy
= mv88e6xxx_6320_family(chip
) ? 3 : 0;
3097 if (!mv88e6xxx_has(chip
, MV88E6XXX_FLAG_TEMP_LIMIT
))
3100 mutex_lock(&chip
->reg_lock
);
3101 err
= mv88e6xxx_phy_page_read(chip
, phy
, 6, 26, &val
);
3104 temp
= clamp_val(DIV_ROUND_CLOSEST(temp
, 5) + 5, 0, 0x1f);
3105 err
= mv88e6xxx_phy_page_write(chip
, phy
, 6, 26,
3106 (val
& 0xe0ff) | (temp
<< 8));
3108 mutex_unlock(&chip
->reg_lock
);
3113 static int mv88e6xxx_get_temp_alarm(struct dsa_switch
*ds
, bool *alarm
)
3115 struct mv88e6xxx_chip
*chip
= ds
->priv
;
3116 int phy
= mv88e6xxx_6320_family(chip
) ? 3 : 0;
3120 if (!mv88e6xxx_has(chip
, MV88E6XXX_FLAG_TEMP_LIMIT
))
3125 mutex_lock(&chip
->reg_lock
);
3126 ret
= mv88e6xxx_phy_page_read(chip
, phy
, 6, 26, &val
);
3127 mutex_unlock(&chip
->reg_lock
);
3131 *alarm
= !!(val
& 0x40);
3135 #endif /* CONFIG_NET_DSA_HWMON */
3137 static int mv88e6xxx_get_eeprom_len(struct dsa_switch
*ds
)
3139 struct mv88e6xxx_chip
*chip
= ds
->priv
;
3141 return chip
->eeprom_len
;
3144 static int mv88e6xxx_get_eeprom(struct dsa_switch
*ds
,
3145 struct ethtool_eeprom
*eeprom
, u8
*data
)
3147 struct mv88e6xxx_chip
*chip
= ds
->priv
;
3150 if (!chip
->info
->ops
->get_eeprom
)
3153 mutex_lock(&chip
->reg_lock
);
3154 err
= chip
->info
->ops
->get_eeprom(chip
, eeprom
, data
);
3155 mutex_unlock(&chip
->reg_lock
);
3160 eeprom
->magic
= 0xc3ec4951;
3165 static int mv88e6xxx_set_eeprom(struct dsa_switch
*ds
,
3166 struct ethtool_eeprom
*eeprom
, u8
*data
)
3168 struct mv88e6xxx_chip
*chip
= ds
->priv
;
3171 if (!chip
->info
->ops
->set_eeprom
)
3174 if (eeprom
->magic
!= 0xc3ec4951)
3177 mutex_lock(&chip
->reg_lock
);
3178 err
= chip
->info
->ops
->set_eeprom(chip
, eeprom
, data
);
3179 mutex_unlock(&chip
->reg_lock
);
3184 static const struct mv88e6xxx_ops mv88e6085_ops
= {
3185 /* MV88E6XXX_FAMILY_6097 */
3186 .set_switch_mac
= mv88e6xxx_g1_set_switch_mac
,
3187 .phy_read
= mv88e6xxx_phy_ppu_read
,
3188 .phy_write
= mv88e6xxx_phy_ppu_write
,
3189 .port_set_link
= mv88e6xxx_port_set_link
,
3190 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3191 .port_set_speed
= mv88e6185_port_set_speed
,
3192 .stats_snapshot
= mv88e6xxx_g1_stats_snapshot
,
3193 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3194 .stats_get_strings
= mv88e6095_stats_get_strings
,
3195 .stats_get_stats
= mv88e6095_stats_get_stats
,
3198 static const struct mv88e6xxx_ops mv88e6095_ops
= {
3199 /* MV88E6XXX_FAMILY_6095 */
3200 .set_switch_mac
= mv88e6xxx_g1_set_switch_mac
,
3201 .phy_read
= mv88e6xxx_phy_ppu_read
,
3202 .phy_write
= mv88e6xxx_phy_ppu_write
,
3203 .port_set_link
= mv88e6xxx_port_set_link
,
3204 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3205 .port_set_speed
= mv88e6185_port_set_speed
,
3206 .stats_snapshot
= mv88e6xxx_g1_stats_snapshot
,
3207 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3208 .stats_get_strings
= mv88e6095_stats_get_strings
,
3209 .stats_get_stats
= mv88e6095_stats_get_stats
,
3212 static const struct mv88e6xxx_ops mv88e6123_ops
= {
3213 /* MV88E6XXX_FAMILY_6165 */
3214 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3215 .phy_read
= mv88e6xxx_read
,
3216 .phy_write
= mv88e6xxx_write
,
3217 .port_set_link
= mv88e6xxx_port_set_link
,
3218 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3219 .port_set_speed
= mv88e6185_port_set_speed
,
3220 .stats_snapshot
= mv88e6xxx_g1_stats_snapshot
,
3221 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3222 .stats_get_strings
= mv88e6095_stats_get_strings
,
3223 .stats_get_stats
= mv88e6095_stats_get_stats
,
3226 static const struct mv88e6xxx_ops mv88e6131_ops
= {
3227 /* MV88E6XXX_FAMILY_6185 */
3228 .set_switch_mac
= mv88e6xxx_g1_set_switch_mac
,
3229 .phy_read
= mv88e6xxx_phy_ppu_read
,
3230 .phy_write
= mv88e6xxx_phy_ppu_write
,
3231 .port_set_link
= mv88e6xxx_port_set_link
,
3232 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3233 .port_set_speed
= mv88e6185_port_set_speed
,
3234 .stats_snapshot
= mv88e6xxx_g1_stats_snapshot
,
3235 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3236 .stats_get_strings
= mv88e6095_stats_get_strings
,
3237 .stats_get_stats
= mv88e6095_stats_get_stats
,
3240 static const struct mv88e6xxx_ops mv88e6161_ops
= {
3241 /* MV88E6XXX_FAMILY_6165 */
3242 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3243 .phy_read
= mv88e6xxx_read
,
3244 .phy_write
= mv88e6xxx_write
,
3245 .port_set_link
= mv88e6xxx_port_set_link
,
3246 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3247 .port_set_speed
= mv88e6185_port_set_speed
,
3248 .stats_snapshot
= mv88e6xxx_g1_stats_snapshot
,
3249 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3250 .stats_get_strings
= mv88e6095_stats_get_strings
,
3251 .stats_get_stats
= mv88e6095_stats_get_stats
,
3254 static const struct mv88e6xxx_ops mv88e6165_ops
= {
3255 /* MV88E6XXX_FAMILY_6165 */
3256 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3257 .phy_read
= mv88e6xxx_read
,
3258 .phy_write
= mv88e6xxx_write
,
3259 .port_set_link
= mv88e6xxx_port_set_link
,
3260 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3261 .port_set_speed
= mv88e6185_port_set_speed
,
3262 .stats_snapshot
= mv88e6xxx_g1_stats_snapshot
,
3263 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3264 .stats_get_strings
= mv88e6095_stats_get_strings
,
3265 .stats_get_stats
= mv88e6095_stats_get_stats
,
3268 static const struct mv88e6xxx_ops mv88e6171_ops
= {
3269 /* MV88E6XXX_FAMILY_6351 */
3270 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3271 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3272 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3273 .port_set_link
= mv88e6xxx_port_set_link
,
3274 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3275 .port_set_rgmii_delay
= mv88e6352_port_set_rgmii_delay
,
3276 .port_set_speed
= mv88e6185_port_set_speed
,
3277 .stats_snapshot
= mv88e6320_g1_stats_snapshot
,
3278 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3279 .stats_get_strings
= mv88e6095_stats_get_strings
,
3280 .stats_get_stats
= mv88e6095_stats_get_stats
,
3283 static const struct mv88e6xxx_ops mv88e6172_ops
= {
3284 /* MV88E6XXX_FAMILY_6352 */
3285 .get_eeprom
= mv88e6xxx_g2_get_eeprom16
,
3286 .set_eeprom
= mv88e6xxx_g2_set_eeprom16
,
3287 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3288 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3289 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3290 .port_set_link
= mv88e6xxx_port_set_link
,
3291 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3292 .port_set_rgmii_delay
= mv88e6352_port_set_rgmii_delay
,
3293 .port_set_speed
= mv88e6352_port_set_speed
,
3294 .stats_snapshot
= mv88e6320_g1_stats_snapshot
,
3295 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3296 .stats_get_strings
= mv88e6095_stats_get_strings
,
3297 .stats_get_stats
= mv88e6095_stats_get_stats
,
3300 static const struct mv88e6xxx_ops mv88e6175_ops
= {
3301 /* MV88E6XXX_FAMILY_6351 */
3302 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3303 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3304 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3305 .port_set_link
= mv88e6xxx_port_set_link
,
3306 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3307 .port_set_rgmii_delay
= mv88e6352_port_set_rgmii_delay
,
3308 .port_set_speed
= mv88e6185_port_set_speed
,
3309 .stats_snapshot
= mv88e6320_g1_stats_snapshot
,
3310 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3311 .stats_get_strings
= mv88e6095_stats_get_strings
,
3312 .stats_get_stats
= mv88e6095_stats_get_stats
,
3315 static const struct mv88e6xxx_ops mv88e6176_ops
= {
3316 /* MV88E6XXX_FAMILY_6352 */
3317 .get_eeprom
= mv88e6xxx_g2_get_eeprom16
,
3318 .set_eeprom
= mv88e6xxx_g2_set_eeprom16
,
3319 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3320 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3321 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3322 .port_set_link
= mv88e6xxx_port_set_link
,
3323 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3324 .port_set_rgmii_delay
= mv88e6352_port_set_rgmii_delay
,
3325 .port_set_speed
= mv88e6352_port_set_speed
,
3326 .stats_snapshot
= mv88e6320_g1_stats_snapshot
,
3327 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3328 .stats_get_strings
= mv88e6095_stats_get_strings
,
3329 .stats_get_stats
= mv88e6095_stats_get_stats
,
3332 static const struct mv88e6xxx_ops mv88e6185_ops
= {
3333 /* MV88E6XXX_FAMILY_6185 */
3334 .set_switch_mac
= mv88e6xxx_g1_set_switch_mac
,
3335 .phy_read
= mv88e6xxx_phy_ppu_read
,
3336 .phy_write
= mv88e6xxx_phy_ppu_write
,
3337 .port_set_link
= mv88e6xxx_port_set_link
,
3338 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3339 .port_set_speed
= mv88e6185_port_set_speed
,
3340 .stats_snapshot
= mv88e6xxx_g1_stats_snapshot
,
3341 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3342 .stats_get_strings
= mv88e6095_stats_get_strings
,
3343 .stats_get_stats
= mv88e6095_stats_get_stats
,
3346 static const struct mv88e6xxx_ops mv88e6190_ops
= {
3347 /* MV88E6XXX_FAMILY_6390 */
3348 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3349 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3350 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3351 .port_set_link
= mv88e6xxx_port_set_link
,
3352 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3353 .port_set_rgmii_delay
= mv88e6390_port_set_rgmii_delay
,
3354 .port_set_speed
= mv88e6390_port_set_speed
,
3355 .stats_snapshot
= mv88e6390_g1_stats_snapshot
,
3356 .stats_set_histogram
= mv88e6390_g1_stats_set_histogram
,
3357 .stats_get_sset_count
= mv88e6320_stats_get_sset_count
,
3358 .stats_get_strings
= mv88e6320_stats_get_strings
,
3359 .stats_get_stats
= mv88e6390_stats_get_stats
,
3362 static const struct mv88e6xxx_ops mv88e6190x_ops
= {
3363 /* MV88E6XXX_FAMILY_6390 */
3364 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3365 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3366 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3367 .port_set_link
= mv88e6xxx_port_set_link
,
3368 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3369 .port_set_rgmii_delay
= mv88e6390_port_set_rgmii_delay
,
3370 .port_set_speed
= mv88e6390x_port_set_speed
,
3371 .stats_snapshot
= mv88e6390_g1_stats_snapshot
,
3372 .stats_set_histogram
= mv88e6390_g1_stats_set_histogram
,
3373 .stats_get_sset_count
= mv88e6320_stats_get_sset_count
,
3374 .stats_get_strings
= mv88e6320_stats_get_strings
,
3375 .stats_get_stats
= mv88e6390_stats_get_stats
,
3378 static const struct mv88e6xxx_ops mv88e6191_ops
= {
3379 /* MV88E6XXX_FAMILY_6390 */
3380 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3381 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3382 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3383 .port_set_link
= mv88e6xxx_port_set_link
,
3384 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3385 .port_set_rgmii_delay
= mv88e6390_port_set_rgmii_delay
,
3386 .port_set_speed
= mv88e6390_port_set_speed
,
3387 .stats_snapshot
= mv88e6390_g1_stats_snapshot
,
3388 .stats_set_histogram
= mv88e6390_g1_stats_set_histogram
,
3389 .stats_get_sset_count
= mv88e6320_stats_get_sset_count
,
3390 .stats_get_strings
= mv88e6320_stats_get_strings
,
3391 .stats_get_stats
= mv88e6390_stats_get_stats
,
3394 static const struct mv88e6xxx_ops mv88e6240_ops
= {
3395 /* MV88E6XXX_FAMILY_6352 */
3396 .get_eeprom
= mv88e6xxx_g2_get_eeprom16
,
3397 .set_eeprom
= mv88e6xxx_g2_set_eeprom16
,
3398 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3399 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3400 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3401 .port_set_link
= mv88e6xxx_port_set_link
,
3402 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3403 .port_set_rgmii_delay
= mv88e6352_port_set_rgmii_delay
,
3404 .port_set_speed
= mv88e6352_port_set_speed
,
3405 .stats_snapshot
= mv88e6320_g1_stats_snapshot
,
3406 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3407 .stats_get_strings
= mv88e6095_stats_get_strings
,
3408 .stats_get_stats
= mv88e6095_stats_get_stats
,
3411 static const struct mv88e6xxx_ops mv88e6290_ops
= {
3412 /* MV88E6XXX_FAMILY_6390 */
3413 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3414 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3415 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3416 .port_set_link
= mv88e6xxx_port_set_link
,
3417 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3418 .port_set_rgmii_delay
= mv88e6390_port_set_rgmii_delay
,
3419 .port_set_speed
= mv88e6390_port_set_speed
,
3420 .stats_snapshot
= mv88e6390_g1_stats_snapshot
,
3421 .stats_set_histogram
= mv88e6390_g1_stats_set_histogram
,
3422 .stats_get_sset_count
= mv88e6320_stats_get_sset_count
,
3423 .stats_get_strings
= mv88e6320_stats_get_strings
,
3424 .stats_get_stats
= mv88e6390_stats_get_stats
,
3427 static const struct mv88e6xxx_ops mv88e6320_ops
= {
3428 /* MV88E6XXX_FAMILY_6320 */
3429 .get_eeprom
= mv88e6xxx_g2_get_eeprom16
,
3430 .set_eeprom
= mv88e6xxx_g2_set_eeprom16
,
3431 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3432 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3433 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3434 .port_set_link
= mv88e6xxx_port_set_link
,
3435 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3436 .port_set_speed
= mv88e6185_port_set_speed
,
3437 .stats_snapshot
= mv88e6320_g1_stats_snapshot
,
3438 .stats_get_sset_count
= mv88e6320_stats_get_sset_count
,
3439 .stats_get_strings
= mv88e6320_stats_get_strings
,
3440 .stats_get_stats
= mv88e6320_stats_get_stats
,
3443 static const struct mv88e6xxx_ops mv88e6321_ops
= {
3444 /* MV88E6XXX_FAMILY_6321 */
3445 .get_eeprom
= mv88e6xxx_g2_get_eeprom16
,
3446 .set_eeprom
= mv88e6xxx_g2_set_eeprom16
,
3447 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3448 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3449 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3450 .port_set_link
= mv88e6xxx_port_set_link
,
3451 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3452 .port_set_speed
= mv88e6185_port_set_speed
,
3453 .stats_snapshot
= mv88e6320_g1_stats_snapshot
,
3454 .stats_get_sset_count
= mv88e6320_stats_get_sset_count
,
3455 .stats_get_strings
= mv88e6320_stats_get_strings
,
3456 .stats_get_stats
= mv88e6320_stats_get_stats
,
3459 static const struct mv88e6xxx_ops mv88e6350_ops
= {
3460 /* MV88E6XXX_FAMILY_6351 */
3461 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3462 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3463 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3464 .port_set_link
= mv88e6xxx_port_set_link
,
3465 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3466 .port_set_rgmii_delay
= mv88e6352_port_set_rgmii_delay
,
3467 .port_set_speed
= mv88e6185_port_set_speed
,
3468 .stats_snapshot
= mv88e6320_g1_stats_snapshot
,
3469 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3470 .stats_get_strings
= mv88e6095_stats_get_strings
,
3471 .stats_get_stats
= mv88e6095_stats_get_stats
,
3474 static const struct mv88e6xxx_ops mv88e6351_ops
= {
3475 /* MV88E6XXX_FAMILY_6351 */
3476 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3477 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3478 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3479 .port_set_link
= mv88e6xxx_port_set_link
,
3480 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3481 .port_set_rgmii_delay
= mv88e6352_port_set_rgmii_delay
,
3482 .port_set_speed
= mv88e6185_port_set_speed
,
3483 .stats_snapshot
= mv88e6320_g1_stats_snapshot
,
3484 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3485 .stats_get_strings
= mv88e6095_stats_get_strings
,
3486 .stats_get_stats
= mv88e6095_stats_get_stats
,
3489 static const struct mv88e6xxx_ops mv88e6352_ops
= {
3490 /* MV88E6XXX_FAMILY_6352 */
3491 .get_eeprom
= mv88e6xxx_g2_get_eeprom16
,
3492 .set_eeprom
= mv88e6xxx_g2_set_eeprom16
,
3493 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3494 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3495 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3496 .port_set_link
= mv88e6xxx_port_set_link
,
3497 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3498 .port_set_rgmii_delay
= mv88e6352_port_set_rgmii_delay
,
3499 .port_set_speed
= mv88e6352_port_set_speed
,
3500 .stats_snapshot
= mv88e6320_g1_stats_snapshot
,
3501 .stats_get_sset_count
= mv88e6095_stats_get_sset_count
,
3502 .stats_get_strings
= mv88e6095_stats_get_strings
,
3503 .stats_get_stats
= mv88e6095_stats_get_stats
,
3506 static const struct mv88e6xxx_ops mv88e6390_ops
= {
3507 /* MV88E6XXX_FAMILY_6390 */
3508 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3509 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3510 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3511 .port_set_link
= mv88e6xxx_port_set_link
,
3512 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3513 .port_set_rgmii_delay
= mv88e6390_port_set_rgmii_delay
,
3514 .port_set_speed
= mv88e6390_port_set_speed
,
3515 .stats_snapshot
= mv88e6390_g1_stats_snapshot
,
3516 .stats_set_histogram
= mv88e6390_g1_stats_set_histogram
,
3517 .stats_get_sset_count
= mv88e6320_stats_get_sset_count
,
3518 .stats_get_strings
= mv88e6320_stats_get_strings
,
3519 .stats_get_stats
= mv88e6390_stats_get_stats
,
3522 static const struct mv88e6xxx_ops mv88e6390x_ops
= {
3523 /* MV88E6XXX_FAMILY_6390 */
3524 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3525 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3526 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3527 .port_set_link
= mv88e6xxx_port_set_link
,
3528 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3529 .port_set_rgmii_delay
= mv88e6390_port_set_rgmii_delay
,
3530 .port_set_speed
= mv88e6390x_port_set_speed
,
3531 .stats_snapshot
= mv88e6390_g1_stats_snapshot
,
3532 .stats_set_histogram
= mv88e6390_g1_stats_set_histogram
,
3533 .stats_get_sset_count
= mv88e6320_stats_get_sset_count
,
3534 .stats_get_strings
= mv88e6320_stats_get_strings
,
3535 .stats_get_stats
= mv88e6390_stats_get_stats
,
3538 static const struct mv88e6xxx_ops mv88e6391_ops
= {
3539 /* MV88E6XXX_FAMILY_6390 */
3540 .set_switch_mac
= mv88e6xxx_g2_set_switch_mac
,
3541 .phy_read
= mv88e6xxx_g2_smi_phy_read
,
3542 .phy_write
= mv88e6xxx_g2_smi_phy_write
,
3543 .port_set_link
= mv88e6xxx_port_set_link
,
3544 .port_set_duplex
= mv88e6xxx_port_set_duplex
,
3545 .port_set_rgmii_delay
= mv88e6390_port_set_rgmii_delay
,
3546 .port_set_speed
= mv88e6390_port_set_speed
,
3547 .stats_snapshot
= mv88e6390_g1_stats_snapshot
,
3548 .stats_set_histogram
= mv88e6390_g1_stats_set_histogram
,
3549 .stats_get_sset_count
= mv88e6320_stats_get_sset_count
,
3550 .stats_get_strings
= mv88e6320_stats_get_strings
,
3551 .stats_get_stats
= mv88e6390_stats_get_stats
,
3554 static const struct mv88e6xxx_info mv88e6xxx_table
[] = {
3556 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6085
,
3557 .family
= MV88E6XXX_FAMILY_6097
,
3558 .name
= "Marvell 88E6085",
3559 .num_databases
= 4096,
3561 .port_base_addr
= 0x10,
3562 .global1_addr
= 0x1b,
3563 .age_time_coeff
= 15000,
3565 .flags
= MV88E6XXX_FLAGS_FAMILY_6097
,
3566 .ops
= &mv88e6085_ops
,
3570 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6095
,
3571 .family
= MV88E6XXX_FAMILY_6095
,
3572 .name
= "Marvell 88E6095/88E6095F",
3573 .num_databases
= 256,
3575 .port_base_addr
= 0x10,
3576 .global1_addr
= 0x1b,
3577 .age_time_coeff
= 15000,
3579 .flags
= MV88E6XXX_FLAGS_FAMILY_6095
,
3580 .ops
= &mv88e6095_ops
,
3584 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6123
,
3585 .family
= MV88E6XXX_FAMILY_6165
,
3586 .name
= "Marvell 88E6123",
3587 .num_databases
= 4096,
3589 .port_base_addr
= 0x10,
3590 .global1_addr
= 0x1b,
3591 .age_time_coeff
= 15000,
3593 .flags
= MV88E6XXX_FLAGS_FAMILY_6165
,
3594 .ops
= &mv88e6123_ops
,
3598 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6131
,
3599 .family
= MV88E6XXX_FAMILY_6185
,
3600 .name
= "Marvell 88E6131",
3601 .num_databases
= 256,
3603 .port_base_addr
= 0x10,
3604 .global1_addr
= 0x1b,
3605 .age_time_coeff
= 15000,
3607 .flags
= MV88E6XXX_FLAGS_FAMILY_6185
,
3608 .ops
= &mv88e6131_ops
,
3612 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6161
,
3613 .family
= MV88E6XXX_FAMILY_6165
,
3614 .name
= "Marvell 88E6161",
3615 .num_databases
= 4096,
3617 .port_base_addr
= 0x10,
3618 .global1_addr
= 0x1b,
3619 .age_time_coeff
= 15000,
3621 .flags
= MV88E6XXX_FLAGS_FAMILY_6165
,
3622 .ops
= &mv88e6161_ops
,
3626 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6165
,
3627 .family
= MV88E6XXX_FAMILY_6165
,
3628 .name
= "Marvell 88E6165",
3629 .num_databases
= 4096,
3631 .port_base_addr
= 0x10,
3632 .global1_addr
= 0x1b,
3633 .age_time_coeff
= 15000,
3635 .flags
= MV88E6XXX_FLAGS_FAMILY_6165
,
3636 .ops
= &mv88e6165_ops
,
3640 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6171
,
3641 .family
= MV88E6XXX_FAMILY_6351
,
3642 .name
= "Marvell 88E6171",
3643 .num_databases
= 4096,
3645 .port_base_addr
= 0x10,
3646 .global1_addr
= 0x1b,
3647 .age_time_coeff
= 15000,
3649 .flags
= MV88E6XXX_FLAGS_FAMILY_6351
,
3650 .ops
= &mv88e6171_ops
,
3654 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6172
,
3655 .family
= MV88E6XXX_FAMILY_6352
,
3656 .name
= "Marvell 88E6172",
3657 .num_databases
= 4096,
3659 .port_base_addr
= 0x10,
3660 .global1_addr
= 0x1b,
3661 .age_time_coeff
= 15000,
3663 .flags
= MV88E6XXX_FLAGS_FAMILY_6352
,
3664 .ops
= &mv88e6172_ops
,
3668 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6175
,
3669 .family
= MV88E6XXX_FAMILY_6351
,
3670 .name
= "Marvell 88E6175",
3671 .num_databases
= 4096,
3673 .port_base_addr
= 0x10,
3674 .global1_addr
= 0x1b,
3675 .age_time_coeff
= 15000,
3677 .flags
= MV88E6XXX_FLAGS_FAMILY_6351
,
3678 .ops
= &mv88e6175_ops
,
3682 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6176
,
3683 .family
= MV88E6XXX_FAMILY_6352
,
3684 .name
= "Marvell 88E6176",
3685 .num_databases
= 4096,
3687 .port_base_addr
= 0x10,
3688 .global1_addr
= 0x1b,
3689 .age_time_coeff
= 15000,
3691 .flags
= MV88E6XXX_FLAGS_FAMILY_6352
,
3692 .ops
= &mv88e6176_ops
,
3696 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6185
,
3697 .family
= MV88E6XXX_FAMILY_6185
,
3698 .name
= "Marvell 88E6185",
3699 .num_databases
= 256,
3701 .port_base_addr
= 0x10,
3702 .global1_addr
= 0x1b,
3703 .age_time_coeff
= 15000,
3705 .flags
= MV88E6XXX_FLAGS_FAMILY_6185
,
3706 .ops
= &mv88e6185_ops
,
3710 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6190
,
3711 .family
= MV88E6XXX_FAMILY_6390
,
3712 .name
= "Marvell 88E6190",
3713 .num_databases
= 4096,
3714 .num_ports
= 11, /* 10 + Z80 */
3715 .port_base_addr
= 0x0,
3716 .global1_addr
= 0x1b,
3717 .age_time_coeff
= 15000,
3719 .flags
= MV88E6XXX_FLAGS_FAMILY_6390
,
3720 .ops
= &mv88e6190_ops
,
3724 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6190X
,
3725 .family
= MV88E6XXX_FAMILY_6390
,
3726 .name
= "Marvell 88E6190X",
3727 .num_databases
= 4096,
3728 .num_ports
= 11, /* 10 + Z80 */
3729 .port_base_addr
= 0x0,
3730 .global1_addr
= 0x1b,
3731 .age_time_coeff
= 15000,
3733 .flags
= MV88E6XXX_FLAGS_FAMILY_6390
,
3734 .ops
= &mv88e6190x_ops
,
3738 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6191
,
3739 .family
= MV88E6XXX_FAMILY_6390
,
3740 .name
= "Marvell 88E6191",
3741 .num_databases
= 4096,
3742 .num_ports
= 11, /* 10 + Z80 */
3743 .port_base_addr
= 0x0,
3744 .global1_addr
= 0x1b,
3745 .age_time_coeff
= 15000,
3746 .flags
= MV88E6XXX_FLAGS_FAMILY_6390
,
3747 .ops
= &mv88e6391_ops
,
3751 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6240
,
3752 .family
= MV88E6XXX_FAMILY_6352
,
3753 .name
= "Marvell 88E6240",
3754 .num_databases
= 4096,
3756 .port_base_addr
= 0x10,
3757 .global1_addr
= 0x1b,
3758 .age_time_coeff
= 15000,
3760 .flags
= MV88E6XXX_FLAGS_FAMILY_6352
,
3761 .ops
= &mv88e6240_ops
,
3765 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6290
,
3766 .family
= MV88E6XXX_FAMILY_6390
,
3767 .name
= "Marvell 88E6290",
3768 .num_databases
= 4096,
3769 .num_ports
= 11, /* 10 + Z80 */
3770 .port_base_addr
= 0x0,
3771 .global1_addr
= 0x1b,
3772 .age_time_coeff
= 15000,
3774 .flags
= MV88E6XXX_FLAGS_FAMILY_6390
,
3775 .ops
= &mv88e6290_ops
,
3779 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6320
,
3780 .family
= MV88E6XXX_FAMILY_6320
,
3781 .name
= "Marvell 88E6320",
3782 .num_databases
= 4096,
3784 .port_base_addr
= 0x10,
3785 .global1_addr
= 0x1b,
3786 .age_time_coeff
= 15000,
3788 .flags
= MV88E6XXX_FLAGS_FAMILY_6320
,
3789 .ops
= &mv88e6320_ops
,
3793 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6321
,
3794 .family
= MV88E6XXX_FAMILY_6320
,
3795 .name
= "Marvell 88E6321",
3796 .num_databases
= 4096,
3798 .port_base_addr
= 0x10,
3799 .global1_addr
= 0x1b,
3800 .age_time_coeff
= 15000,
3802 .flags
= MV88E6XXX_FLAGS_FAMILY_6320
,
3803 .ops
= &mv88e6321_ops
,
3807 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6350
,
3808 .family
= MV88E6XXX_FAMILY_6351
,
3809 .name
= "Marvell 88E6350",
3810 .num_databases
= 4096,
3812 .port_base_addr
= 0x10,
3813 .global1_addr
= 0x1b,
3814 .age_time_coeff
= 15000,
3816 .flags
= MV88E6XXX_FLAGS_FAMILY_6351
,
3817 .ops
= &mv88e6350_ops
,
3821 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6351
,
3822 .family
= MV88E6XXX_FAMILY_6351
,
3823 .name
= "Marvell 88E6351",
3824 .num_databases
= 4096,
3826 .port_base_addr
= 0x10,
3827 .global1_addr
= 0x1b,
3828 .age_time_coeff
= 15000,
3830 .flags
= MV88E6XXX_FLAGS_FAMILY_6351
,
3831 .ops
= &mv88e6351_ops
,
3835 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6352
,
3836 .family
= MV88E6XXX_FAMILY_6352
,
3837 .name
= "Marvell 88E6352",
3838 .num_databases
= 4096,
3840 .port_base_addr
= 0x10,
3841 .global1_addr
= 0x1b,
3842 .age_time_coeff
= 15000,
3844 .flags
= MV88E6XXX_FLAGS_FAMILY_6352
,
3845 .ops
= &mv88e6352_ops
,
3848 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6390
,
3849 .family
= MV88E6XXX_FAMILY_6390
,
3850 .name
= "Marvell 88E6390",
3851 .num_databases
= 4096,
3852 .num_ports
= 11, /* 10 + Z80 */
3853 .port_base_addr
= 0x0,
3854 .global1_addr
= 0x1b,
3855 .age_time_coeff
= 15000,
3857 .flags
= MV88E6XXX_FLAGS_FAMILY_6390
,
3858 .ops
= &mv88e6390_ops
,
3861 .prod_num
= PORT_SWITCH_ID_PROD_NUM_6390X
,
3862 .family
= MV88E6XXX_FAMILY_6390
,
3863 .name
= "Marvell 88E6390X",
3864 .num_databases
= 4096,
3865 .num_ports
= 11, /* 10 + Z80 */
3866 .port_base_addr
= 0x0,
3867 .global1_addr
= 0x1b,
3868 .age_time_coeff
= 15000,
3870 .flags
= MV88E6XXX_FLAGS_FAMILY_6390
,
3871 .ops
= &mv88e6390x_ops
,
3875 static const struct mv88e6xxx_info
*mv88e6xxx_lookup_info(unsigned int prod_num
)
3879 for (i
= 0; i
< ARRAY_SIZE(mv88e6xxx_table
); ++i
)
3880 if (mv88e6xxx_table
[i
].prod_num
== prod_num
)
3881 return &mv88e6xxx_table
[i
];
3886 static int mv88e6xxx_detect(struct mv88e6xxx_chip
*chip
)
3888 const struct mv88e6xxx_info
*info
;
3889 unsigned int prod_num
, rev
;
3893 mutex_lock(&chip
->reg_lock
);
3894 err
= mv88e6xxx_port_read(chip
, 0, PORT_SWITCH_ID
, &id
);
3895 mutex_unlock(&chip
->reg_lock
);
3899 prod_num
= (id
& 0xfff0) >> 4;
3902 info
= mv88e6xxx_lookup_info(prod_num
);
3906 /* Update the compatible info with the probed one */
3909 err
= mv88e6xxx_g2_require(chip
);
3913 dev_info(chip
->dev
, "switch 0x%x detected: %s, revision %u\n",
3914 chip
->info
->prod_num
, chip
->info
->name
, rev
);
3919 static struct mv88e6xxx_chip
*mv88e6xxx_alloc_chip(struct device
*dev
)
3921 struct mv88e6xxx_chip
*chip
;
3923 chip
= devm_kzalloc(dev
, sizeof(*chip
), GFP_KERNEL
);
3929 mutex_init(&chip
->reg_lock
);
3934 static void mv88e6xxx_phy_init(struct mv88e6xxx_chip
*chip
)
3936 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_PPU
))
3937 mv88e6xxx_ppu_state_init(chip
);
3940 static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip
*chip
)
3942 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_PPU
))
3943 mv88e6xxx_ppu_state_destroy(chip
);
3946 static int mv88e6xxx_smi_init(struct mv88e6xxx_chip
*chip
,
3947 struct mii_bus
*bus
, int sw_addr
)
3949 /* ADDR[0] pin is unavailable externally and considered zero */
3954 chip
->smi_ops
= &mv88e6xxx_smi_single_chip_ops
;
3955 else if (mv88e6xxx_has(chip
, MV88E6XXX_FLAGS_MULTI_CHIP
))
3956 chip
->smi_ops
= &mv88e6xxx_smi_multi_chip_ops
;
3961 chip
->sw_addr
= sw_addr
;
3966 static enum dsa_tag_protocol
mv88e6xxx_get_tag_protocol(struct dsa_switch
*ds
)
3968 struct mv88e6xxx_chip
*chip
= ds
->priv
;
3970 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_EDSA
))
3971 return DSA_TAG_PROTO_EDSA
;
3973 return DSA_TAG_PROTO_DSA
;
3976 static const char *mv88e6xxx_drv_probe(struct device
*dsa_dev
,
3977 struct device
*host_dev
, int sw_addr
,
3980 struct mv88e6xxx_chip
*chip
;
3981 struct mii_bus
*bus
;
3984 bus
= dsa_host_dev_to_mii_bus(host_dev
);
3988 chip
= mv88e6xxx_alloc_chip(dsa_dev
);
3992 /* Legacy SMI probing will only support chips similar to 88E6085 */
3993 chip
->info
= &mv88e6xxx_table
[MV88E6085
];
3995 err
= mv88e6xxx_smi_init(chip
, bus
, sw_addr
);
3999 err
= mv88e6xxx_detect(chip
);
4003 mutex_lock(&chip
->reg_lock
);
4004 err
= mv88e6xxx_switch_reset(chip
);
4005 mutex_unlock(&chip
->reg_lock
);
4009 mv88e6xxx_phy_init(chip
);
4011 err
= mv88e6xxx_mdio_register(chip
, NULL
);
4017 return chip
->info
->name
;
4019 devm_kfree(dsa_dev
, chip
);
4024 static int mv88e6xxx_port_mdb_prepare(struct dsa_switch
*ds
, int port
,
4025 const struct switchdev_obj_port_mdb
*mdb
,
4026 struct switchdev_trans
*trans
)
4028 /* We don't need any dynamic resource from the kernel (yet),
4029 * so skip the prepare phase.
4035 static void mv88e6xxx_port_mdb_add(struct dsa_switch
*ds
, int port
,
4036 const struct switchdev_obj_port_mdb
*mdb
,
4037 struct switchdev_trans
*trans
)
4039 struct mv88e6xxx_chip
*chip
= ds
->priv
;
4041 mutex_lock(&chip
->reg_lock
);
4042 if (mv88e6xxx_port_db_load_purge(chip
, port
, mdb
->addr
, mdb
->vid
,
4043 GLOBAL_ATU_DATA_STATE_MC_STATIC
))
4044 netdev_err(ds
->ports
[port
].netdev
, "failed to load multicast MAC address\n");
4045 mutex_unlock(&chip
->reg_lock
);
4048 static int mv88e6xxx_port_mdb_del(struct dsa_switch
*ds
, int port
,
4049 const struct switchdev_obj_port_mdb
*mdb
)
4051 struct mv88e6xxx_chip
*chip
= ds
->priv
;
4054 mutex_lock(&chip
->reg_lock
);
4055 err
= mv88e6xxx_port_db_load_purge(chip
, port
, mdb
->addr
, mdb
->vid
,
4056 GLOBAL_ATU_DATA_STATE_UNUSED
);
4057 mutex_unlock(&chip
->reg_lock
);
4062 static int mv88e6xxx_port_mdb_dump(struct dsa_switch
*ds
, int port
,
4063 struct switchdev_obj_port_mdb
*mdb
,
4064 int (*cb
)(struct switchdev_obj
*obj
))
4066 struct mv88e6xxx_chip
*chip
= ds
->priv
;
4069 mutex_lock(&chip
->reg_lock
);
4070 err
= mv88e6xxx_port_db_dump(chip
, port
, &mdb
->obj
, cb
);
4071 mutex_unlock(&chip
->reg_lock
);
4076 static struct dsa_switch_ops mv88e6xxx_switch_ops
= {
4077 .probe
= mv88e6xxx_drv_probe
,
4078 .get_tag_protocol
= mv88e6xxx_get_tag_protocol
,
4079 .setup
= mv88e6xxx_setup
,
4080 .set_addr
= mv88e6xxx_set_addr
,
4081 .adjust_link
= mv88e6xxx_adjust_link
,
4082 .get_strings
= mv88e6xxx_get_strings
,
4083 .get_ethtool_stats
= mv88e6xxx_get_ethtool_stats
,
4084 .get_sset_count
= mv88e6xxx_get_sset_count
,
4085 .set_eee
= mv88e6xxx_set_eee
,
4086 .get_eee
= mv88e6xxx_get_eee
,
4087 #ifdef CONFIG_NET_DSA_HWMON
4088 .get_temp
= mv88e6xxx_get_temp
,
4089 .get_temp_limit
= mv88e6xxx_get_temp_limit
,
4090 .set_temp_limit
= mv88e6xxx_set_temp_limit
,
4091 .get_temp_alarm
= mv88e6xxx_get_temp_alarm
,
4093 .get_eeprom_len
= mv88e6xxx_get_eeprom_len
,
4094 .get_eeprom
= mv88e6xxx_get_eeprom
,
4095 .set_eeprom
= mv88e6xxx_set_eeprom
,
4096 .get_regs_len
= mv88e6xxx_get_regs_len
,
4097 .get_regs
= mv88e6xxx_get_regs
,
4098 .set_ageing_time
= mv88e6xxx_set_ageing_time
,
4099 .port_bridge_join
= mv88e6xxx_port_bridge_join
,
4100 .port_bridge_leave
= mv88e6xxx_port_bridge_leave
,
4101 .port_stp_state_set
= mv88e6xxx_port_stp_state_set
,
4102 .port_fast_age
= mv88e6xxx_port_fast_age
,
4103 .port_vlan_filtering
= mv88e6xxx_port_vlan_filtering
,
4104 .port_vlan_prepare
= mv88e6xxx_port_vlan_prepare
,
4105 .port_vlan_add
= mv88e6xxx_port_vlan_add
,
4106 .port_vlan_del
= mv88e6xxx_port_vlan_del
,
4107 .port_vlan_dump
= mv88e6xxx_port_vlan_dump
,
4108 .port_fdb_prepare
= mv88e6xxx_port_fdb_prepare
,
4109 .port_fdb_add
= mv88e6xxx_port_fdb_add
,
4110 .port_fdb_del
= mv88e6xxx_port_fdb_del
,
4111 .port_fdb_dump
= mv88e6xxx_port_fdb_dump
,
4112 .port_mdb_prepare
= mv88e6xxx_port_mdb_prepare
,
4113 .port_mdb_add
= mv88e6xxx_port_mdb_add
,
4114 .port_mdb_del
= mv88e6xxx_port_mdb_del
,
4115 .port_mdb_dump
= mv88e6xxx_port_mdb_dump
,
4118 static int mv88e6xxx_register_switch(struct mv88e6xxx_chip
*chip
,
4119 struct device_node
*np
)
4121 struct device
*dev
= chip
->dev
;
4122 struct dsa_switch
*ds
;
4124 ds
= devm_kzalloc(dev
, sizeof(*ds
), GFP_KERNEL
);
4130 ds
->ops
= &mv88e6xxx_switch_ops
;
4132 dev_set_drvdata(dev
, ds
);
4134 return dsa_register_switch(ds
, np
);
4137 static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip
*chip
)
4139 dsa_unregister_switch(chip
->ds
);
4142 static int mv88e6xxx_probe(struct mdio_device
*mdiodev
)
4144 struct device
*dev
= &mdiodev
->dev
;
4145 struct device_node
*np
= dev
->of_node
;
4146 const struct mv88e6xxx_info
*compat_info
;
4147 struct mv88e6xxx_chip
*chip
;
4151 compat_info
= of_device_get_match_data(dev
);
4155 chip
= mv88e6xxx_alloc_chip(dev
);
4159 chip
->info
= compat_info
;
4161 err
= mv88e6xxx_smi_init(chip
, mdiodev
->bus
, mdiodev
->addr
);
4165 chip
->reset
= devm_gpiod_get_optional(dev
, "reset", GPIOD_OUT_LOW
);
4166 if (IS_ERR(chip
->reset
))
4167 return PTR_ERR(chip
->reset
);
4169 err
= mv88e6xxx_detect(chip
);
4173 mv88e6xxx_phy_init(chip
);
4175 if (chip
->info
->ops
->get_eeprom
&&
4176 !of_property_read_u32(np
, "eeprom-length", &eeprom_len
))
4177 chip
->eeprom_len
= eeprom_len
;
4179 mutex_lock(&chip
->reg_lock
);
4180 err
= mv88e6xxx_switch_reset(chip
);
4181 mutex_unlock(&chip
->reg_lock
);
4185 chip
->irq
= of_irq_get(np
, 0);
4186 if (chip
->irq
== -EPROBE_DEFER
) {
4191 if (chip
->irq
> 0) {
4192 /* Has to be performed before the MDIO bus is created,
4193 * because the PHYs will link there interrupts to these
4194 * interrupt controllers
4196 mutex_lock(&chip
->reg_lock
);
4197 err
= mv88e6xxx_g1_irq_setup(chip
);
4198 mutex_unlock(&chip
->reg_lock
);
4203 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_G2_INT
)) {
4204 err
= mv88e6xxx_g2_irq_setup(chip
);
4210 err
= mv88e6xxx_mdio_register(chip
, np
);
4214 err
= mv88e6xxx_register_switch(chip
, np
);
4221 mv88e6xxx_mdio_unregister(chip
);
4223 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_G2_INT
) && chip
->irq
> 0)
4224 mv88e6xxx_g2_irq_free(chip
);
4226 if (chip
->irq
> 0) {
4227 mutex_lock(&chip
->reg_lock
);
4228 mv88e6xxx_g1_irq_free(chip
);
4229 mutex_unlock(&chip
->reg_lock
);
4235 static void mv88e6xxx_remove(struct mdio_device
*mdiodev
)
4237 struct dsa_switch
*ds
= dev_get_drvdata(&mdiodev
->dev
);
4238 struct mv88e6xxx_chip
*chip
= ds
->priv
;
4240 mv88e6xxx_phy_destroy(chip
);
4241 mv88e6xxx_unregister_switch(chip
);
4242 mv88e6xxx_mdio_unregister(chip
);
4244 if (chip
->irq
> 0) {
4245 if (mv88e6xxx_has(chip
, MV88E6XXX_FLAG_G2_INT
))
4246 mv88e6xxx_g2_irq_free(chip
);
4247 mv88e6xxx_g1_irq_free(chip
);
4251 static const struct of_device_id mv88e6xxx_of_match
[] = {
4253 .compatible
= "marvell,mv88e6085",
4254 .data
= &mv88e6xxx_table
[MV88E6085
],
4257 .compatible
= "marvell,mv88e6190",
4258 .data
= &mv88e6xxx_table
[MV88E6190
],
4263 MODULE_DEVICE_TABLE(of
, mv88e6xxx_of_match
);
4265 static struct mdio_driver mv88e6xxx_driver
= {
4266 .probe
= mv88e6xxx_probe
,
4267 .remove
= mv88e6xxx_remove
,
4269 .name
= "mv88e6085",
4270 .of_match_table
= mv88e6xxx_of_match
,
4274 static int __init
mv88e6xxx_init(void)
4276 register_switch_driver(&mv88e6xxx_switch_ops
);
4277 return mdio_driver_register(&mv88e6xxx_driver
);
4279 module_init(mv88e6xxx_init
);
4281 static void __exit
mv88e6xxx_cleanup(void)
4283 mdio_driver_unregister(&mv88e6xxx_driver
);
4284 unregister_switch_driver(&mv88e6xxx_switch_ops
);
4286 module_exit(mv88e6xxx_cleanup
);
4288 MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
4289 MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
4290 MODULE_LICENSE("GPL");