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)
417 for (irq = 0; irq < 16; irq++) {
418 virq = irq_find_mapping(chip->g1_irq.domain, irq);
419 irq_dispose_mapping(virq);
422 irq_domain_remove(chip->g1_irq.domain);
425 static int mv88e6xxx_g1_irq_setup(struct mv88e6xxx_chip *chip)
430 chip->g1_irq.nirqs = chip->info->g1_irqs;
431 chip->g1_irq.domain = irq_domain_add_simple(
432 NULL, chip->g1_irq.nirqs, 0,
433 &mv88e6xxx_g1_irq_domain_ops, chip);
434 if (!chip->g1_irq.domain)
437 for (irq = 0; irq < chip->g1_irq.nirqs; irq++)
438 irq_create_mapping(chip->g1_irq.domain, irq);
440 chip->g1_irq.chip = mv88e6xxx_g1_irq_chip;
441 chip->g1_irq.masked = ~0;
443 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, ®);
447 reg &= ~GENMASK(chip->g1_irq.nirqs, 0);
449 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
453 /* Reading the interrupt status clears (most of) them */
454 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, ®);
458 err = request_threaded_irq(chip->irq, NULL,
459 mv88e6xxx_g1_irq_thread_fn,
460 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
461 dev_name(chip->dev), chip);
468 mv88e6xxx_g1_irq_free(chip);
473 int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask)
477 for (i = 0; i < 16; i++) {
481 err = mv88e6xxx_read(chip, addr, reg, &val);
488 usleep_range(1000, 2000);
491 dev_err(chip->dev, "Timeout while waiting for switch\n");
495 /* Indirect write to single pointer-data register with an Update bit */
496 int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
501 /* Wait until the previous operation is completed */
502 err = mv88e6xxx_wait(chip, addr, reg, BIT(15));
506 /* Set the Update bit to trigger a write operation */
507 val = BIT(15) | update;
509 return mv88e6xxx_write(chip, addr, reg, val);
512 static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
517 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &val);
521 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL,
522 val & ~GLOBAL_CONTROL_PPU_ENABLE);
526 for (i = 0; i < 16; i++) {
527 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &val);
531 usleep_range(1000, 2000);
532 if ((val & GLOBAL_STATUS_PPU_MASK) != GLOBAL_STATUS_PPU_POLLING)
539 static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
544 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &val);
548 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL,
549 val | GLOBAL_CONTROL_PPU_ENABLE);
553 for (i = 0; i < 16; i++) {
554 err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &val);
558 usleep_range(1000, 2000);
559 if ((val & GLOBAL_STATUS_PPU_MASK) == GLOBAL_STATUS_PPU_POLLING)
566 static void mv88e6xxx_ppu_reenable_work(struct work_struct *ugly)
568 struct mv88e6xxx_chip *chip;
570 chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);
572 mutex_lock(&chip->reg_lock);
574 if (mutex_trylock(&chip->ppu_mutex)) {
575 if (mv88e6xxx_ppu_enable(chip) == 0)
576 chip->ppu_disabled = 0;
577 mutex_unlock(&chip->ppu_mutex);
580 mutex_unlock(&chip->reg_lock);
583 static void mv88e6xxx_ppu_reenable_timer(unsigned long _ps)
585 struct mv88e6xxx_chip *chip = (void *)_ps;
587 schedule_work(&chip->ppu_work);
590 static int mv88e6xxx_ppu_access_get(struct mv88e6xxx_chip *chip)
594 mutex_lock(&chip->ppu_mutex);
596 /* If the PHY polling unit is enabled, disable it so that
597 * we can access the PHY registers. If it was already
598 * disabled, cancel the timer that is going to re-enable
601 if (!chip->ppu_disabled) {
602 ret = mv88e6xxx_ppu_disable(chip);
604 mutex_unlock(&chip->ppu_mutex);
607 chip->ppu_disabled = 1;
609 del_timer(&chip->ppu_timer);
616 static void mv88e6xxx_ppu_access_put(struct mv88e6xxx_chip *chip)
618 /* Schedule a timer to re-enable the PHY polling unit. */
619 mod_timer(&chip->ppu_timer, jiffies + msecs_to_jiffies(10));
620 mutex_unlock(&chip->ppu_mutex);
623 static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
625 mutex_init(&chip->ppu_mutex);
626 INIT_WORK(&chip->ppu_work, mv88e6xxx_ppu_reenable_work);
627 setup_timer(&chip->ppu_timer, mv88e6xxx_ppu_reenable_timer,
628 (unsigned long)chip);
631 static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
633 del_timer_sync(&chip->ppu_timer);
636 static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip, int addr,
641 err = mv88e6xxx_ppu_access_get(chip);
643 err = mv88e6xxx_read(chip, addr, reg, val);
644 mv88e6xxx_ppu_access_put(chip);
650 static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip, int addr,
655 err = mv88e6xxx_ppu_access_get(chip);
657 err = mv88e6xxx_write(chip, addr, reg, val);
658 mv88e6xxx_ppu_access_put(chip);
664 static bool mv88e6xxx_6065_family(struct mv88e6xxx_chip *chip)
666 return chip->info->family == MV88E6XXX_FAMILY_6065;
669 static bool mv88e6xxx_6095_family(struct mv88e6xxx_chip *chip)
671 return chip->info->family == MV88E6XXX_FAMILY_6095;
674 static bool mv88e6xxx_6097_family(struct mv88e6xxx_chip *chip)
676 return chip->info->family == MV88E6XXX_FAMILY_6097;
679 static bool mv88e6xxx_6165_family(struct mv88e6xxx_chip *chip)
681 return chip->info->family == MV88E6XXX_FAMILY_6165;
684 static bool mv88e6xxx_6185_family(struct mv88e6xxx_chip *chip)
686 return chip->info->family == MV88E6XXX_FAMILY_6185;
689 static bool mv88e6xxx_6320_family(struct mv88e6xxx_chip *chip)
691 return chip->info->family == MV88E6XXX_FAMILY_6320;
694 static bool mv88e6xxx_6351_family(struct mv88e6xxx_chip *chip)
696 return chip->info->family == MV88E6XXX_FAMILY_6351;
699 static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
701 return chip->info->family == MV88E6XXX_FAMILY_6352;
704 static int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port,
705 int link, int speed, int duplex,
706 phy_interface_t mode)
710 if (!chip->info->ops->port_set_link)
713 /* Port's MAC control must not be changed unless the link is down */
714 err = chip->info->ops->port_set_link(chip, port, 0);
718 if (chip->info->ops->port_set_speed) {
719 err = chip->info->ops->port_set_speed(chip, port, speed);
720 if (err && err != -EOPNOTSUPP)
724 if (chip->info->ops->port_set_duplex) {
725 err = chip->info->ops->port_set_duplex(chip, port, duplex);
726 if (err && err != -EOPNOTSUPP)
730 if (chip->info->ops->port_set_rgmii_delay) {
731 err = chip->info->ops->port_set_rgmii_delay(chip, port, mode);
732 if (err && err != -EOPNOTSUPP)
738 if (chip->info->ops->port_set_link(chip, port, link))
739 netdev_err(chip->ds->ports[port].netdev,
740 "failed to restore MAC's link\n");
745 /* We expect the switch to perform auto negotiation if there is a real
746 * phy. However, in the case of a fixed link phy, we force the port
747 * settings from the fixed link settings.
749 static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
750 struct phy_device *phydev)
752 struct mv88e6xxx_chip *chip = ds->priv;
755 if (!phy_is_pseudo_fixed_link(phydev))
758 mutex_lock(&chip->reg_lock);
759 err = mv88e6xxx_port_setup_mac(chip, port, phydev->link, phydev->speed,
760 phydev->duplex, phydev->interface);
761 mutex_unlock(&chip->reg_lock);
763 if (err && err != -EOPNOTSUPP)
764 netdev_err(ds->ports[port].netdev, "failed to configure MAC\n");
767 static int _mv88e6xxx_stats_wait(struct mv88e6xxx_chip *chip)
772 for (i = 0; i < 10; i++) {
773 err = mv88e6xxx_g1_read(chip, GLOBAL_STATS_OP, &val);
774 if ((val & GLOBAL_STATS_OP_BUSY) == 0)
781 static int _mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
785 if (mv88e6xxx_6320_family(chip) || mv88e6xxx_6352_family(chip))
786 port = (port + 1) << 5;
788 /* Snapshot the hardware statistics counters for this port. */
789 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
790 GLOBAL_STATS_OP_CAPTURE_PORT |
791 GLOBAL_STATS_OP_HIST_RX_TX | port);
795 /* Wait for the snapshotting to complete. */
796 return _mv88e6xxx_stats_wait(chip);
799 static void _mv88e6xxx_stats_read(struct mv88e6xxx_chip *chip,
808 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
809 GLOBAL_STATS_OP_READ_CAPTURED |
810 GLOBAL_STATS_OP_HIST_RX_TX | stat);
814 err = _mv88e6xxx_stats_wait(chip);
818 err = mv88e6xxx_g1_read(chip, GLOBAL_STATS_COUNTER_32, ®);
824 err = mv88e6xxx_g1_read(chip, GLOBAL_STATS_COUNTER_01, ®);
831 static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
832 { "in_good_octets", 8, 0x00, BANK0, },
833 { "in_bad_octets", 4, 0x02, BANK0, },
834 { "in_unicast", 4, 0x04, BANK0, },
835 { "in_broadcasts", 4, 0x06, BANK0, },
836 { "in_multicasts", 4, 0x07, BANK0, },
837 { "in_pause", 4, 0x16, BANK0, },
838 { "in_undersize", 4, 0x18, BANK0, },
839 { "in_fragments", 4, 0x19, BANK0, },
840 { "in_oversize", 4, 0x1a, BANK0, },
841 { "in_jabber", 4, 0x1b, BANK0, },
842 { "in_rx_error", 4, 0x1c, BANK0, },
843 { "in_fcs_error", 4, 0x1d, BANK0, },
844 { "out_octets", 8, 0x0e, BANK0, },
845 { "out_unicast", 4, 0x10, BANK0, },
846 { "out_broadcasts", 4, 0x13, BANK0, },
847 { "out_multicasts", 4, 0x12, BANK0, },
848 { "out_pause", 4, 0x15, BANK0, },
849 { "excessive", 4, 0x11, BANK0, },
850 { "collisions", 4, 0x1e, BANK0, },
851 { "deferred", 4, 0x05, BANK0, },
852 { "single", 4, 0x14, BANK0, },
853 { "multiple", 4, 0x17, BANK0, },
854 { "out_fcs_error", 4, 0x03, BANK0, },
855 { "late", 4, 0x1f, BANK0, },
856 { "hist_64bytes", 4, 0x08, BANK0, },
857 { "hist_65_127bytes", 4, 0x09, BANK0, },
858 { "hist_128_255bytes", 4, 0x0a, BANK0, },
859 { "hist_256_511bytes", 4, 0x0b, BANK0, },
860 { "hist_512_1023bytes", 4, 0x0c, BANK0, },
861 { "hist_1024_max_bytes", 4, 0x0d, BANK0, },
862 { "sw_in_discards", 4, 0x10, PORT, },
863 { "sw_in_filtered", 2, 0x12, PORT, },
864 { "sw_out_filtered", 2, 0x13, PORT, },
865 { "in_discards", 4, 0x00 | GLOBAL_STATS_OP_BANK_1, BANK1, },
866 { "in_filtered", 4, 0x01 | GLOBAL_STATS_OP_BANK_1, BANK1, },
867 { "in_accepted", 4, 0x02 | GLOBAL_STATS_OP_BANK_1, BANK1, },
868 { "in_bad_accepted", 4, 0x03 | GLOBAL_STATS_OP_BANK_1, BANK1, },
869 { "in_good_avb_class_a", 4, 0x04 | GLOBAL_STATS_OP_BANK_1, BANK1, },
870 { "in_good_avb_class_b", 4, 0x05 | GLOBAL_STATS_OP_BANK_1, BANK1, },
871 { "in_bad_avb_class_a", 4, 0x06 | GLOBAL_STATS_OP_BANK_1, BANK1, },
872 { "in_bad_avb_class_b", 4, 0x07 | GLOBAL_STATS_OP_BANK_1, BANK1, },
873 { "tcam_counter_0", 4, 0x08 | GLOBAL_STATS_OP_BANK_1, BANK1, },
874 { "tcam_counter_1", 4, 0x09 | GLOBAL_STATS_OP_BANK_1, BANK1, },
875 { "tcam_counter_2", 4, 0x0a | GLOBAL_STATS_OP_BANK_1, BANK1, },
876 { "tcam_counter_3", 4, 0x0b | GLOBAL_STATS_OP_BANK_1, BANK1, },
877 { "in_da_unknown", 4, 0x0e | GLOBAL_STATS_OP_BANK_1, BANK1, },
878 { "in_management", 4, 0x0f | GLOBAL_STATS_OP_BANK_1, BANK1, },
879 { "out_queue_0", 4, 0x10 | GLOBAL_STATS_OP_BANK_1, BANK1, },
880 { "out_queue_1", 4, 0x11 | GLOBAL_STATS_OP_BANK_1, BANK1, },
881 { "out_queue_2", 4, 0x12 | GLOBAL_STATS_OP_BANK_1, BANK1, },
882 { "out_queue_3", 4, 0x13 | GLOBAL_STATS_OP_BANK_1, BANK1, },
883 { "out_queue_4", 4, 0x14 | GLOBAL_STATS_OP_BANK_1, BANK1, },
884 { "out_queue_5", 4, 0x15 | GLOBAL_STATS_OP_BANK_1, BANK1, },
885 { "out_queue_6", 4, 0x16 | GLOBAL_STATS_OP_BANK_1, BANK1, },
886 { "out_queue_7", 4, 0x17 | GLOBAL_STATS_OP_BANK_1, BANK1, },
887 { "out_cut_through", 4, 0x18 | GLOBAL_STATS_OP_BANK_1, BANK1, },
888 { "out_octets_a", 4, 0x1a | GLOBAL_STATS_OP_BANK_1, BANK1, },
889 { "out_octets_b", 4, 0x1b | GLOBAL_STATS_OP_BANK_1, BANK1, },
890 { "out_management", 4, 0x1f | GLOBAL_STATS_OP_BANK_1, BANK1, },
893 static bool mv88e6xxx_has_stat(struct mv88e6xxx_chip *chip,
894 struct mv88e6xxx_hw_stat *stat)
896 switch (stat->type) {
900 return mv88e6xxx_6320_family(chip);
902 return mv88e6xxx_6095_family(chip) ||
903 mv88e6xxx_6185_family(chip) ||
904 mv88e6xxx_6097_family(chip) ||
905 mv88e6xxx_6165_family(chip) ||
906 mv88e6xxx_6351_family(chip) ||
907 mv88e6xxx_6352_family(chip);
912 static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
913 struct mv88e6xxx_hw_stat *s,
924 err = mv88e6xxx_port_read(chip, port, s->reg, ®);
929 if (s->sizeof_stat == 4) {
930 err = mv88e6xxx_port_read(chip, port, s->reg + 1, ®);
938 _mv88e6xxx_stats_read(chip, s->reg, &low);
939 if (s->sizeof_stat == 8)
940 _mv88e6xxx_stats_read(chip, s->reg + 1, &high);
942 value = (((u64)high) << 16) | low;
946 static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
949 struct mv88e6xxx_chip *chip = ds->priv;
950 struct mv88e6xxx_hw_stat *stat;
953 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
954 stat = &mv88e6xxx_hw_stats[i];
955 if (mv88e6xxx_has_stat(chip, stat)) {
956 memcpy(data + j * ETH_GSTRING_LEN, stat->string,
963 static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
965 struct mv88e6xxx_chip *chip = ds->priv;
966 struct mv88e6xxx_hw_stat *stat;
969 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
970 stat = &mv88e6xxx_hw_stats[i];
971 if (mv88e6xxx_has_stat(chip, stat))
977 static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
980 struct mv88e6xxx_chip *chip = ds->priv;
981 struct mv88e6xxx_hw_stat *stat;
985 mutex_lock(&chip->reg_lock);
987 ret = _mv88e6xxx_stats_snapshot(chip, port);
989 mutex_unlock(&chip->reg_lock);
992 for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
993 stat = &mv88e6xxx_hw_stats[i];
994 if (mv88e6xxx_has_stat(chip, stat)) {
995 data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port);
1000 mutex_unlock(&chip->reg_lock);
1003 static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
1005 return 32 * sizeof(u16);
1008 static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
1009 struct ethtool_regs *regs, void *_p)
1011 struct mv88e6xxx_chip *chip = ds->priv;
1019 memset(p, 0xff, 32 * sizeof(u16));
1021 mutex_lock(&chip->reg_lock);
1023 for (i = 0; i < 32; i++) {
1025 err = mv88e6xxx_port_read(chip, port, i, ®);
1030 mutex_unlock(&chip->reg_lock);
1033 static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
1035 return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
1038 static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
1039 struct ethtool_eee *e)
1041 struct mv88e6xxx_chip *chip = ds->priv;
1045 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
1048 mutex_lock(&chip->reg_lock);
1050 err = mv88e6xxx_phy_read(chip, port, 16, ®);
1054 e->eee_enabled = !!(reg & 0x0200);
1055 e->tx_lpi_enabled = !!(reg & 0x0100);
1057 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, ®);
1061 e->eee_active = !!(reg & PORT_STATUS_EEE);
1063 mutex_unlock(&chip->reg_lock);
1068 static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
1069 struct phy_device *phydev, struct ethtool_eee *e)
1071 struct mv88e6xxx_chip *chip = ds->priv;
1075 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_EEE))
1078 mutex_lock(&chip->reg_lock);
1080 err = mv88e6xxx_phy_read(chip, port, 16, ®);
1087 if (e->tx_lpi_enabled)
1090 err = mv88e6xxx_phy_write(chip, port, 16, reg);
1092 mutex_unlock(&chip->reg_lock);
1097 static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
1102 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
1103 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
1106 } else if (mv88e6xxx_num_databases(chip) == 256) {
1107 /* ATU DBNum[7:4] are located in ATU Control 15:12 */
1108 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
1112 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
1113 (val & 0xfff) | ((fid << 8) & 0xf000));
1117 /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
1121 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
1125 return _mv88e6xxx_atu_wait(chip);
1128 static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
1129 struct mv88e6xxx_atu_entry *entry)
1131 u16 data = entry->state & GLOBAL_ATU_DATA_STATE_MASK;
1133 if (entry->state != GLOBAL_ATU_DATA_STATE_UNUSED) {
1134 unsigned int mask, shift;
1137 data |= GLOBAL_ATU_DATA_TRUNK;
1138 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
1139 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
1141 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
1142 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
1145 data |= (entry->portv_trunkid << shift) & mask;
1148 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
1151 static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
1152 struct mv88e6xxx_atu_entry *entry,
1158 err = _mv88e6xxx_atu_wait(chip);
1162 err = _mv88e6xxx_atu_data_write(chip, entry);
1167 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL_DB :
1168 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC_DB;
1170 op = static_too ? GLOBAL_ATU_OP_FLUSH_MOVE_ALL :
1171 GLOBAL_ATU_OP_FLUSH_MOVE_NON_STATIC;
1174 return _mv88e6xxx_atu_cmd(chip, entry->fid, op);
1177 static int _mv88e6xxx_atu_flush(struct mv88e6xxx_chip *chip,
1178 u16 fid, bool static_too)
1180 struct mv88e6xxx_atu_entry entry = {
1182 .state = 0, /* EntryState bits must be 0 */
1185 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
1188 static int _mv88e6xxx_atu_move(struct mv88e6xxx_chip *chip, u16 fid,
1189 int from_port, int to_port, bool static_too)
1191 struct mv88e6xxx_atu_entry entry = {
1196 /* EntryState bits must be 0xF */
1197 entry.state = GLOBAL_ATU_DATA_STATE_MASK;
1199 /* ToPort and FromPort are respectively in PortVec bits 7:4 and 3:0 */
1200 entry.portv_trunkid = (to_port & 0x0f) << 4;
1201 entry.portv_trunkid |= from_port & 0x0f;
1203 return _mv88e6xxx_atu_flush_move(chip, &entry, static_too);
1206 static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
1207 int port, bool static_too)
1209 /* Destination port 0xF means remove the entries */
1210 return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
1213 static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
1215 struct net_device *bridge = chip->ports[port].bridge_dev;
1216 struct dsa_switch *ds = chip->ds;
1217 u16 output_ports = 0;
1220 /* allow CPU port or DSA link(s) to send frames to every port */
1221 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) {
1224 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1225 /* allow sending frames to every group member */
1226 if (bridge && chip->ports[i].bridge_dev == bridge)
1227 output_ports |= BIT(i);
1229 /* allow sending frames to CPU port and DSA link(s) */
1230 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1231 output_ports |= BIT(i);
1235 /* prevent frames from going back out of the port they came in on */
1236 output_ports &= ~BIT(port);
1238 return mv88e6xxx_port_set_vlan_map(chip, port, output_ports);
1241 static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
1244 struct mv88e6xxx_chip *chip = ds->priv;
1249 case BR_STATE_DISABLED:
1250 stp_state = PORT_CONTROL_STATE_DISABLED;
1252 case BR_STATE_BLOCKING:
1253 case BR_STATE_LISTENING:
1254 stp_state = PORT_CONTROL_STATE_BLOCKING;
1256 case BR_STATE_LEARNING:
1257 stp_state = PORT_CONTROL_STATE_LEARNING;
1259 case BR_STATE_FORWARDING:
1261 stp_state = PORT_CONTROL_STATE_FORWARDING;
1265 mutex_lock(&chip->reg_lock);
1266 err = mv88e6xxx_port_set_state(chip, port, stp_state);
1267 mutex_unlock(&chip->reg_lock);
1270 netdev_err(ds->ports[port].netdev, "failed to update state\n");
1273 static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
1275 struct mv88e6xxx_chip *chip = ds->priv;
1278 mutex_lock(&chip->reg_lock);
1279 err = _mv88e6xxx_atu_remove(chip, 0, port, false);
1280 mutex_unlock(&chip->reg_lock);
1283 netdev_err(ds->ports[port].netdev, "failed to flush ATU\n");
1286 static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
1288 return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
1291 static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
1295 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
1299 return _mv88e6xxx_vtu_wait(chip);
1302 static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
1306 ret = _mv88e6xxx_vtu_wait(chip);
1310 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_FLUSH_ALL);
1313 static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
1314 struct mv88e6xxx_vtu_entry *entry,
1315 unsigned int nibble_offset)
1320 for (i = 0; i < 3; ++i) {
1321 u16 *reg = ®s[i];
1323 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1328 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1329 unsigned int shift = (i % 4) * 4 + nibble_offset;
1330 u16 reg = regs[i / 4];
1332 entry->data[i] = (reg >> shift) & GLOBAL_VTU_STU_DATA_MASK;
1338 static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
1339 struct mv88e6xxx_vtu_entry *entry)
1341 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
1344 static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
1345 struct mv88e6xxx_vtu_entry *entry)
1347 return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
1350 static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
1351 struct mv88e6xxx_vtu_entry *entry,
1352 unsigned int nibble_offset)
1354 u16 regs[3] = { 0 };
1357 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1358 unsigned int shift = (i % 4) * 4 + nibble_offset;
1359 u8 data = entry->data[i];
1361 regs[i / 4] |= (data & GLOBAL_VTU_STU_DATA_MASK) << shift;
1364 for (i = 0; i < 3; ++i) {
1367 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
1375 static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
1376 struct mv88e6xxx_vtu_entry *entry)
1378 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
1381 static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
1382 struct mv88e6xxx_vtu_entry *entry)
1384 return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
1387 static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
1389 return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
1390 vid & GLOBAL_VTU_VID_MASK);
1393 static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
1394 struct mv88e6xxx_vtu_entry *entry)
1396 struct mv88e6xxx_vtu_entry next = { 0 };
1400 err = _mv88e6xxx_vtu_wait(chip);
1404 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
1408 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1412 next.vid = val & GLOBAL_VTU_VID_MASK;
1413 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
1416 err = mv88e6xxx_vtu_data_read(chip, &next);
1420 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
1421 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
1425 next.fid = val & GLOBAL_VTU_FID_MASK;
1426 } else if (mv88e6xxx_num_databases(chip) == 256) {
1427 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1428 * VTU DBNum[3:0] are located in VTU Operation 3:0
1430 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
1434 next.fid = (val & 0xf00) >> 4;
1435 next.fid |= val & 0xf;
1438 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
1439 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1443 next.sid = val & GLOBAL_VTU_SID_MASK;
1451 static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
1452 struct switchdev_obj_port_vlan *vlan,
1453 int (*cb)(struct switchdev_obj *obj))
1455 struct mv88e6xxx_chip *chip = ds->priv;
1456 struct mv88e6xxx_vtu_entry next;
1460 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
1463 mutex_lock(&chip->reg_lock);
1465 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1469 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
1474 err = _mv88e6xxx_vtu_getnext(chip, &next);
1481 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1484 /* reinit and dump this VLAN obj */
1485 vlan->vid_begin = next.vid;
1486 vlan->vid_end = next.vid;
1489 if (next.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED)
1490 vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
1492 if (next.vid == pvid)
1493 vlan->flags |= BRIDGE_VLAN_INFO_PVID;
1495 err = cb(&vlan->obj);
1498 } while (next.vid < GLOBAL_VTU_VID_MASK);
1501 mutex_unlock(&chip->reg_lock);
1506 static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
1507 struct mv88e6xxx_vtu_entry *entry)
1509 u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
1513 err = _mv88e6xxx_vtu_wait(chip);
1520 /* Write port member tags */
1521 err = mv88e6xxx_vtu_data_write(chip, entry);
1525 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
1526 reg = entry->sid & GLOBAL_VTU_SID_MASK;
1527 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1532 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
1533 reg = entry->fid & GLOBAL_VTU_FID_MASK;
1534 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
1537 } else if (mv88e6xxx_num_databases(chip) == 256) {
1538 /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
1539 * VTU DBNum[3:0] are located in VTU Operation 3:0
1541 op |= (entry->fid & 0xf0) << 8;
1542 op |= entry->fid & 0xf;
1545 reg = GLOBAL_VTU_VID_VALID;
1547 reg |= entry->vid & GLOBAL_VTU_VID_MASK;
1548 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1552 return _mv88e6xxx_vtu_cmd(chip, op);
1555 static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
1556 struct mv88e6xxx_vtu_entry *entry)
1558 struct mv88e6xxx_vtu_entry next = { 0 };
1562 err = _mv88e6xxx_vtu_wait(chip);
1566 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
1567 sid & GLOBAL_VTU_SID_MASK);
1571 err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
1575 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
1579 next.sid = val & GLOBAL_VTU_SID_MASK;
1581 err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
1585 next.valid = !!(val & GLOBAL_VTU_VID_VALID);
1588 err = mv88e6xxx_stu_data_read(chip, &next);
1597 static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
1598 struct mv88e6xxx_vtu_entry *entry)
1603 err = _mv88e6xxx_vtu_wait(chip);
1610 /* Write port states */
1611 err = mv88e6xxx_stu_data_write(chip, entry);
1615 reg = GLOBAL_VTU_VID_VALID;
1617 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
1621 reg = entry->sid & GLOBAL_VTU_SID_MASK;
1622 err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
1626 return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
1629 static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
1631 DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
1632 struct mv88e6xxx_vtu_entry vlan;
1635 bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
1637 /* Set every FID bit used by the (un)bridged ports */
1638 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1639 err = mv88e6xxx_port_get_fid(chip, i, fid);
1643 set_bit(*fid, fid_bitmap);
1646 /* Set every FID bit used by the VLAN entries */
1647 err = _mv88e6xxx_vtu_vid_write(chip, GLOBAL_VTU_VID_MASK);
1652 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
1659 set_bit(vlan.fid, fid_bitmap);
1660 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
1662 /* The reset value 0x000 is used to indicate that multiple address
1663 * databases are not needed. Return the next positive available.
1665 *fid = find_next_zero_bit(fid_bitmap, MV88E6XXX_N_FID, 1);
1666 if (unlikely(*fid >= mv88e6xxx_num_databases(chip)))
1669 /* Clear the database */
1670 return _mv88e6xxx_atu_flush(chip, *fid, true);
1673 static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
1674 struct mv88e6xxx_vtu_entry *entry)
1676 struct dsa_switch *ds = chip->ds;
1677 struct mv88e6xxx_vtu_entry vlan = {
1683 err = _mv88e6xxx_fid_new(chip, &vlan.fid);
1687 /* exclude all ports except the CPU and DSA ports */
1688 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
1689 vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
1690 ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
1691 : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1693 if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
1694 mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip)) {
1695 struct mv88e6xxx_vtu_entry vstp;
1697 /* Adding a VTU entry requires a valid STU entry. As VSTP is not
1698 * implemented, only one STU entry is needed to cover all VTU
1699 * entries. Thus, validate the SID 0.
1702 err = _mv88e6xxx_stu_getnext(chip, GLOBAL_VTU_SID_MASK, &vstp);
1706 if (vstp.sid != vlan.sid || !vstp.valid) {
1707 memset(&vstp, 0, sizeof(vstp));
1709 vstp.sid = vlan.sid;
1711 err = _mv88e6xxx_stu_loadpurge(chip, &vstp);
1721 static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
1722 struct mv88e6xxx_vtu_entry *entry, bool creat)
1729 err = _mv88e6xxx_vtu_vid_write(chip, vid - 1);
1733 err = _mv88e6xxx_vtu_getnext(chip, entry);
1737 if (entry->vid != vid || !entry->valid) {
1740 /* -ENOENT would've been more appropriate, but switchdev expects
1741 * -EOPNOTSUPP to inform bridge about an eventual software VLAN.
1744 err = _mv88e6xxx_vtu_new(chip, vid, entry);
1750 static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
1751 u16 vid_begin, u16 vid_end)
1753 struct mv88e6xxx_chip *chip = ds->priv;
1754 struct mv88e6xxx_vtu_entry vlan;
1760 mutex_lock(&chip->reg_lock);
1762 err = _mv88e6xxx_vtu_vid_write(chip, vid_begin - 1);
1767 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
1774 if (vlan.vid > vid_end)
1777 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1778 if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
1782 GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1785 if (chip->ports[i].bridge_dev ==
1786 chip->ports[port].bridge_dev)
1787 break; /* same bridge, check next VLAN */
1789 netdev_warn(ds->ports[port].netdev,
1790 "hardware VLAN %d already used by %s\n",
1792 netdev_name(chip->ports[i].bridge_dev));
1796 } while (vlan.vid < vid_end);
1799 mutex_unlock(&chip->reg_lock);
1804 static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
1805 bool vlan_filtering)
1807 struct mv88e6xxx_chip *chip = ds->priv;
1808 u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
1809 PORT_CONTROL_2_8021Q_DISABLED;
1812 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
1815 mutex_lock(&chip->reg_lock);
1816 err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
1817 mutex_unlock(&chip->reg_lock);
1823 mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
1824 const struct switchdev_obj_port_vlan *vlan,
1825 struct switchdev_trans *trans)
1827 struct mv88e6xxx_chip *chip = ds->priv;
1830 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
1833 /* If the requested port doesn't belong to the same bridge as the VLAN
1834 * members, do not support it (yet) and fallback to software VLAN.
1836 err = mv88e6xxx_port_check_hw_vlan(ds, port, vlan->vid_begin,
1841 /* We don't need any dynamic resource from the kernel (yet),
1842 * so skip the prepare phase.
1847 static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
1848 u16 vid, bool untagged)
1850 struct mv88e6xxx_vtu_entry vlan;
1853 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
1857 vlan.data[port] = untagged ?
1858 GLOBAL_VTU_DATA_MEMBER_TAG_UNTAGGED :
1859 GLOBAL_VTU_DATA_MEMBER_TAG_TAGGED;
1861 return _mv88e6xxx_vtu_loadpurge(chip, &vlan);
1864 static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
1865 const struct switchdev_obj_port_vlan *vlan,
1866 struct switchdev_trans *trans)
1868 struct mv88e6xxx_chip *chip = ds->priv;
1869 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1870 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1873 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
1876 mutex_lock(&chip->reg_lock);
1878 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1879 if (_mv88e6xxx_port_vlan_add(chip, port, vid, untagged))
1880 netdev_err(ds->ports[port].netdev,
1881 "failed to add VLAN %d%c\n",
1882 vid, untagged ? 'u' : 't');
1884 if (pvid && mv88e6xxx_port_set_pvid(chip, port, vlan->vid_end))
1885 netdev_err(ds->ports[port].netdev, "failed to set PVID %d\n",
1888 mutex_unlock(&chip->reg_lock);
1891 static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
1894 struct dsa_switch *ds = chip->ds;
1895 struct mv88e6xxx_vtu_entry vlan;
1898 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
1902 /* Tell switchdev if this VLAN is handled in software */
1903 if (vlan.data[port] == GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
1906 vlan.data[port] = GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
1908 /* keep the VLAN unless all ports are excluded */
1910 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
1911 if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
1914 if (vlan.data[i] != GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER) {
1920 err = _mv88e6xxx_vtu_loadpurge(chip, &vlan);
1924 return _mv88e6xxx_atu_remove(chip, vlan.fid, port, false);
1927 static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
1928 const struct switchdev_obj_port_vlan *vlan)
1930 struct mv88e6xxx_chip *chip = ds->priv;
1934 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
1937 mutex_lock(&chip->reg_lock);
1939 err = mv88e6xxx_port_get_pvid(chip, port, &pvid);
1943 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1944 err = _mv88e6xxx_port_vlan_del(chip, port, vid);
1949 err = mv88e6xxx_port_set_pvid(chip, port, 0);
1956 mutex_unlock(&chip->reg_lock);
1961 static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
1962 const unsigned char *addr)
1966 for (i = 0; i < 3; i++) {
1967 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
1968 (addr[i * 2] << 8) | addr[i * 2 + 1]);
1976 static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
1977 unsigned char *addr)
1982 for (i = 0; i < 3; i++) {
1983 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
1987 addr[i * 2] = val >> 8;
1988 addr[i * 2 + 1] = val & 0xff;
1994 static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
1995 struct mv88e6xxx_atu_entry *entry)
1999 ret = _mv88e6xxx_atu_wait(chip);
2003 ret = _mv88e6xxx_atu_mac_write(chip, entry->mac);
2007 ret = _mv88e6xxx_atu_data_write(chip, entry);
2011 return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
2014 static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2015 struct mv88e6xxx_atu_entry *entry);
2017 static int mv88e6xxx_atu_get(struct mv88e6xxx_chip *chip, int fid,
2018 const u8 *addr, struct mv88e6xxx_atu_entry *entry)
2020 struct mv88e6xxx_atu_entry next;
2023 eth_broadcast_addr(next.mac);
2025 err = _mv88e6xxx_atu_mac_write(chip, next.mac);
2030 err = _mv88e6xxx_atu_getnext(chip, fid, &next);
2034 if (next.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2037 if (ether_addr_equal(next.mac, addr)) {
2041 } while (!is_broadcast_ether_addr(next.mac));
2043 memset(entry, 0, sizeof(*entry));
2045 ether_addr_copy(entry->mac, addr);
2050 static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
2051 const unsigned char *addr, u16 vid,
2054 struct mv88e6xxx_vtu_entry vlan;
2055 struct mv88e6xxx_atu_entry entry;
2058 /* Null VLAN ID corresponds to the port private database */
2060 err = mv88e6xxx_port_get_fid(chip, port, &vlan.fid);
2062 err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
2066 err = mv88e6xxx_atu_get(chip, vlan.fid, addr, &entry);
2070 /* Purge the ATU entry only if no port is using it anymore */
2071 if (state == GLOBAL_ATU_DATA_STATE_UNUSED) {
2072 entry.portv_trunkid &= ~BIT(port);
2073 if (!entry.portv_trunkid)
2074 entry.state = GLOBAL_ATU_DATA_STATE_UNUSED;
2076 entry.portv_trunkid |= BIT(port);
2077 entry.state = state;
2080 return _mv88e6xxx_atu_load(chip, &entry);
2083 static int mv88e6xxx_port_fdb_prepare(struct dsa_switch *ds, int port,
2084 const struct switchdev_obj_port_fdb *fdb,
2085 struct switchdev_trans *trans)
2087 /* We don't need any dynamic resource from the kernel (yet),
2088 * so skip the prepare phase.
2093 static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
2094 const struct switchdev_obj_port_fdb *fdb,
2095 struct switchdev_trans *trans)
2097 struct mv88e6xxx_chip *chip = ds->priv;
2099 mutex_lock(&chip->reg_lock);
2100 if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2101 GLOBAL_ATU_DATA_STATE_UC_STATIC))
2102 netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
2103 mutex_unlock(&chip->reg_lock);
2106 static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
2107 const struct switchdev_obj_port_fdb *fdb)
2109 struct mv88e6xxx_chip *chip = ds->priv;
2112 mutex_lock(&chip->reg_lock);
2113 err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
2114 GLOBAL_ATU_DATA_STATE_UNUSED);
2115 mutex_unlock(&chip->reg_lock);
2120 static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
2121 struct mv88e6xxx_atu_entry *entry)
2123 struct mv88e6xxx_atu_entry next = { 0 };
2129 err = _mv88e6xxx_atu_wait(chip);
2133 err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
2137 err = _mv88e6xxx_atu_mac_read(chip, next.mac);
2141 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
2145 next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
2146 if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
2147 unsigned int mask, shift;
2149 if (val & GLOBAL_ATU_DATA_TRUNK) {
2151 mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
2152 shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
2155 mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
2156 shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
2159 next.portv_trunkid = (val & mask) >> shift;
2166 static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
2167 u16 fid, u16 vid, int port,
2168 struct switchdev_obj *obj,
2169 int (*cb)(struct switchdev_obj *obj))
2171 struct mv88e6xxx_atu_entry addr = {
2172 .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
2176 err = _mv88e6xxx_atu_mac_write(chip, addr.mac);
2181 err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
2185 if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
2188 if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
2191 if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
2192 struct switchdev_obj_port_fdb *fdb;
2194 if (!is_unicast_ether_addr(addr.mac))
2197 fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
2199 ether_addr_copy(fdb->addr, addr.mac);
2200 if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
2201 fdb->ndm_state = NUD_NOARP;
2203 fdb->ndm_state = NUD_REACHABLE;
2204 } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
2205 struct switchdev_obj_port_mdb *mdb;
2207 if (!is_multicast_ether_addr(addr.mac))
2210 mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
2212 ether_addr_copy(mdb->addr, addr.mac);
2220 } while (!is_broadcast_ether_addr(addr.mac));
2225 static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
2226 struct switchdev_obj *obj,
2227 int (*cb)(struct switchdev_obj *obj))
2229 struct mv88e6xxx_vtu_entry vlan = {
2230 .vid = GLOBAL_VTU_VID_MASK, /* all ones */
2235 /* Dump port's default Filtering Information Database (VLAN ID 0) */
2236 err = mv88e6xxx_port_get_fid(chip, port, &fid);
2240 err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
2244 /* Dump VLANs' Filtering Information Databases */
2245 err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
2250 err = _mv88e6xxx_vtu_getnext(chip, &vlan);
2257 err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
2261 } while (vlan.vid < GLOBAL_VTU_VID_MASK);
2266 static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
2267 struct switchdev_obj_port_fdb *fdb,
2268 int (*cb)(struct switchdev_obj *obj))
2270 struct mv88e6xxx_chip *chip = ds->priv;
2273 mutex_lock(&chip->reg_lock);
2274 err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
2275 mutex_unlock(&chip->reg_lock);
2280 static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
2281 struct net_device *bridge)
2283 struct mv88e6xxx_chip *chip = ds->priv;
2286 mutex_lock(&chip->reg_lock);
2288 /* Assign the bridge and remap each port's VLANTable */
2289 chip->ports[port].bridge_dev = bridge;
2291 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
2292 if (chip->ports[i].bridge_dev == bridge) {
2293 err = _mv88e6xxx_port_based_vlan_map(chip, i);
2299 mutex_unlock(&chip->reg_lock);
2304 static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
2306 struct mv88e6xxx_chip *chip = ds->priv;
2307 struct net_device *bridge = chip->ports[port].bridge_dev;
2310 mutex_lock(&chip->reg_lock);
2312 /* Unassign the bridge and remap each port's VLANTable */
2313 chip->ports[port].bridge_dev = NULL;
2315 for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
2316 if (i == port || chip->ports[i].bridge_dev == bridge)
2317 if (_mv88e6xxx_port_based_vlan_map(chip, i))
2318 netdev_warn(ds->ports[i].netdev,
2319 "failed to remap\n");
2321 mutex_unlock(&chip->reg_lock);
2324 static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
2326 bool ppu_active = mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE);
2327 u16 is_reset = (ppu_active ? 0x8800 : 0xc800);
2328 struct gpio_desc *gpiod = chip->reset;
2329 unsigned long timeout;
2334 /* Set all ports to the disabled state. */
2335 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2336 err = mv88e6xxx_port_set_state(chip, i,
2337 PORT_CONTROL_STATE_DISABLED);
2342 /* Wait for transmit queues to drain. */
2343 usleep_range(2000, 4000);
2345 /* If there is a gpio connected to the reset pin, toggle it */
2347 gpiod_set_value_cansleep(gpiod, 1);
2348 usleep_range(10000, 20000);
2349 gpiod_set_value_cansleep(gpiod, 0);
2350 usleep_range(10000, 20000);
2353 /* Reset the switch. Keep the PPU active if requested. The PPU
2354 * needs to be active to support indirect phy register access
2355 * through global registers 0x18 and 0x19.
2358 err = mv88e6xxx_g1_write(chip, 0x04, 0xc000);
2360 err = mv88e6xxx_g1_write(chip, 0x04, 0xc400);
2364 /* Wait up to one second for reset to complete. */
2365 timeout = jiffies + 1 * HZ;
2366 while (time_before(jiffies, timeout)) {
2367 err = mv88e6xxx_g1_read(chip, 0x00, ®);
2371 if ((reg & is_reset) == is_reset)
2373 usleep_range(1000, 2000);
2375 if (time_after(jiffies, timeout))
2383 static int mv88e6xxx_serdes_power_on(struct mv88e6xxx_chip *chip)
2388 /* Clear Power Down bit */
2389 err = mv88e6xxx_serdes_read(chip, MII_BMCR, &val);
2393 if (val & BMCR_PDOWN) {
2395 err = mv88e6xxx_serdes_write(chip, MII_BMCR, val);
2401 static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
2403 struct dsa_switch *ds = chip->ds;
2407 /* MAC Forcing register: don't force link, speed, duplex or flow control
2408 * state to any particular values on physical ports, but force the CPU
2409 * port and all DSA ports to their maximum bandwidth and full duplex.
2411 if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
2412 err = mv88e6xxx_port_setup_mac(chip, port, LINK_FORCED_UP,
2413 SPEED_MAX, DUPLEX_FULL,
2414 PHY_INTERFACE_MODE_NA);
2416 err = mv88e6xxx_port_setup_mac(chip, port, LINK_UNFORCED,
2417 SPEED_UNFORCED, DUPLEX_UNFORCED,
2418 PHY_INTERFACE_MODE_NA);
2422 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
2423 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
2424 * tunneling, determine priority by looking at 802.1p and IP
2425 * priority fields (IP prio has precedence), and set STP state
2428 * If this is the CPU link, use DSA or EDSA tagging depending
2429 * on which tagging mode was configured.
2431 * If this is a link to another switch, use DSA tagging mode.
2433 * If this is the upstream port for this switch, enable
2434 * forwarding of unknown unicasts and multicasts.
2437 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2438 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2439 mv88e6xxx_6095_family(chip) || mv88e6xxx_6065_family(chip) ||
2440 mv88e6xxx_6185_family(chip) || mv88e6xxx_6320_family(chip))
2441 reg = PORT_CONTROL_IGMP_MLD_SNOOP |
2442 PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
2443 PORT_CONTROL_STATE_FORWARDING;
2444 if (dsa_is_cpu_port(ds, port)) {
2445 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA))
2446 reg |= PORT_CONTROL_FRAME_ETHER_TYPE_DSA |
2447 PORT_CONTROL_FORWARD_UNKNOWN_MC;
2449 reg |= PORT_CONTROL_DSA_TAG;
2450 reg |= PORT_CONTROL_EGRESS_ADD_TAG |
2451 PORT_CONTROL_FORWARD_UNKNOWN;
2453 if (dsa_is_dsa_port(ds, port)) {
2454 if (mv88e6xxx_6095_family(chip) ||
2455 mv88e6xxx_6185_family(chip))
2456 reg |= PORT_CONTROL_DSA_TAG;
2457 if (mv88e6xxx_6352_family(chip) ||
2458 mv88e6xxx_6351_family(chip) ||
2459 mv88e6xxx_6165_family(chip) ||
2460 mv88e6xxx_6097_family(chip) ||
2461 mv88e6xxx_6320_family(chip)) {
2462 reg |= PORT_CONTROL_FRAME_MODE_DSA;
2465 if (port == dsa_upstream_port(ds))
2466 reg |= PORT_CONTROL_FORWARD_UNKNOWN |
2467 PORT_CONTROL_FORWARD_UNKNOWN_MC;
2470 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
2475 /* If this port is connected to a SerDes, make sure the SerDes is not
2478 if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SERDES)) {
2479 err = mv88e6xxx_port_read(chip, port, PORT_STATUS, ®);
2482 reg &= PORT_STATUS_CMODE_MASK;
2483 if ((reg == PORT_STATUS_CMODE_100BASE_X) ||
2484 (reg == PORT_STATUS_CMODE_1000BASE_X) ||
2485 (reg == PORT_STATUS_CMODE_SGMII)) {
2486 err = mv88e6xxx_serdes_power_on(chip);
2492 /* Port Control 2: don't force a good FCS, set the maximum frame size to
2493 * 10240 bytes, disable 802.1q tags checking, don't discard tagged or
2494 * untagged frames on this port, do a destination address lookup on all
2495 * received packets as usual, disable ARP mirroring and don't send a
2496 * copy of all transmitted/received frames on this port to the CPU.
2499 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2500 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2501 mv88e6xxx_6095_family(chip) || mv88e6xxx_6320_family(chip) ||
2502 mv88e6xxx_6185_family(chip))
2503 reg = PORT_CONTROL_2_MAP_DA;
2505 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2506 mv88e6xxx_6165_family(chip) || mv88e6xxx_6320_family(chip))
2507 reg |= PORT_CONTROL_2_JUMBO_10240;
2509 if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip)) {
2510 /* Set the upstream port this port should use */
2511 reg |= dsa_upstream_port(ds);
2512 /* enable forwarding of unknown multicast addresses to
2515 if (port == dsa_upstream_port(ds))
2516 reg |= PORT_CONTROL_2_FORWARD_UNKNOWN;
2519 reg |= PORT_CONTROL_2_8021Q_DISABLED;
2522 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
2527 /* Port Association Vector: when learning source addresses
2528 * of packets, add the address to the address database using
2529 * a port bitmap that has only the bit for this port set and
2530 * the other bits clear.
2533 /* Disable learning for CPU port */
2534 if (dsa_is_cpu_port(ds, port))
2537 err = mv88e6xxx_port_write(chip, port, PORT_ASSOC_VECTOR, reg);
2541 /* Egress rate control 2: disable egress rate control. */
2542 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL_2, 0x0000);
2546 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2547 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2548 mv88e6xxx_6320_family(chip)) {
2549 /* Do not limit the period of time that this port can
2550 * be paused for by the remote end or the period of
2551 * time that this port can pause the remote end.
2553 err = mv88e6xxx_port_write(chip, port, PORT_PAUSE_CTRL, 0x0000);
2557 /* Port ATU control: disable limiting the number of
2558 * address database entries that this port is allowed
2561 err = mv88e6xxx_port_write(chip, port, PORT_ATU_CONTROL,
2563 /* Priority Override: disable DA, SA and VTU priority
2566 err = mv88e6xxx_port_write(chip, port, PORT_PRI_OVERRIDE,
2571 /* Port Ethertype: use the Ethertype DSA Ethertype
2574 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA)) {
2575 err = mv88e6xxx_port_write(chip, port, PORT_ETH_TYPE,
2581 /* Tag Remap: use an identity 802.1p prio -> switch
2584 err = mv88e6xxx_port_write(chip, port, PORT_TAG_REGMAP_0123,
2589 /* Tag Remap 2: use an identity 802.1p prio -> switch
2592 err = mv88e6xxx_port_write(chip, port, PORT_TAG_REGMAP_4567,
2598 /* Rate Control: disable ingress rate limiting. */
2599 if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
2600 mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
2601 mv88e6xxx_6320_family(chip)) {
2602 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL,
2606 } else if (mv88e6xxx_6185_family(chip) || mv88e6xxx_6095_family(chip)) {
2607 err = mv88e6xxx_port_write(chip, port, PORT_RATE_CONTROL,
2613 /* Port Control 1: disable trunking, disable sending
2614 * learning messages to this port.
2616 err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_1, 0x0000);
2620 /* Port based VLAN map: give each port the same default address
2621 * database, and allow bidirectional communication between the
2622 * CPU and DSA port(s), and the other ports.
2624 err = mv88e6xxx_port_set_fid(chip, port, 0);
2628 err = _mv88e6xxx_port_based_vlan_map(chip, port);
2632 /* Default VLAN ID and priority: don't set a default VLAN
2633 * ID, and set the default packet priority to zero.
2635 return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
2638 static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
2642 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
2646 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
2650 err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
2657 static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
2660 const unsigned int coeff = chip->info->age_time_coeff;
2661 const unsigned int min = 0x01 * coeff;
2662 const unsigned int max = 0xff * coeff;
2667 if (msecs < min || msecs > max)
2670 /* Round to nearest multiple of coeff */
2671 age_time = (msecs + coeff / 2) / coeff;
2673 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
2677 /* AgeTime is 11:4 bits */
2679 val |= age_time << 4;
2681 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
2684 static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
2685 unsigned int ageing_time)
2687 struct mv88e6xxx_chip *chip = ds->priv;
2690 mutex_lock(&chip->reg_lock);
2691 err = mv88e6xxx_g1_set_age_time(chip, ageing_time);
2692 mutex_unlock(&chip->reg_lock);
2697 static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
2699 struct dsa_switch *ds = chip->ds;
2700 u32 upstream_port = dsa_upstream_port(ds);
2704 /* Enable the PHY Polling Unit if present, don't discard any packets,
2705 * and mask all interrupt sources.
2707 err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, ®);
2711 reg &= ~GLOBAL_CONTROL_PPU_ENABLE;
2712 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU) ||
2713 mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE))
2714 reg |= GLOBAL_CONTROL_PPU_ENABLE;
2716 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
2720 /* Configure the upstream port, and configure it as the port to which
2721 * ingress and egress and ARP monitor frames are to be sent.
2723 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
2724 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
2725 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
2726 err = mv88e6xxx_g1_write(chip, GLOBAL_MONITOR_CONTROL, reg);
2730 /* Disable remote management, and set the switch's DSA device number. */
2731 err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
2732 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
2733 (ds->index & 0x1f));
2737 /* Clear all the VTU and STU entries */
2738 err = _mv88e6xxx_vtu_stu_flush(chip);
2742 /* Set the default address aging time to 5 minutes, and
2743 * enable address learn messages to be sent to all message
2746 err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
2747 GLOBAL_ATU_CONTROL_LEARN2ALL);
2751 err = mv88e6xxx_g1_set_age_time(chip, 300000);
2755 /* Clear all ATU entries */
2756 err = _mv88e6xxx_atu_flush(chip, 0, true);
2760 /* Configure the IP ToS mapping registers. */
2761 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
2764 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
2767 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
2770 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
2773 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
2776 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
2779 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
2782 err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
2786 /* Configure the IEEE 802.1p priority mapping register. */
2787 err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
2791 /* Clear the statistics counters for all ports */
2792 err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
2793 GLOBAL_STATS_OP_FLUSH_ALL);
2797 /* Wait for the flush to complete. */
2798 err = _mv88e6xxx_stats_wait(chip);
2805 static int mv88e6xxx_setup(struct dsa_switch *ds)
2807 struct mv88e6xxx_chip *chip = ds->priv;
2812 ds->slave_mii_bus = chip->mdio_bus;
2814 mutex_lock(&chip->reg_lock);
2816 /* Setup Switch Port Registers */
2817 for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
2818 err = mv88e6xxx_setup_port(chip, i);
2823 /* Setup Switch Global 1 Registers */
2824 err = mv88e6xxx_g1_setup(chip);
2828 /* Setup Switch Global 2 Registers */
2829 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_GLOBAL2)) {
2830 err = mv88e6xxx_g2_setup(chip);
2836 mutex_unlock(&chip->reg_lock);
2841 static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
2843 struct mv88e6xxx_chip *chip = ds->priv;
2846 if (!chip->info->ops->set_switch_mac)
2849 mutex_lock(&chip->reg_lock);
2850 err = chip->info->ops->set_switch_mac(chip, addr);
2851 mutex_unlock(&chip->reg_lock);
2856 static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
2858 struct mv88e6xxx_chip *chip = bus->priv;
2862 if (phy >= mv88e6xxx_num_ports(chip))
2865 mutex_lock(&chip->reg_lock);
2866 err = mv88e6xxx_phy_read(chip, phy, reg, &val);
2867 mutex_unlock(&chip->reg_lock);
2869 return err ? err : val;
2872 static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
2874 struct mv88e6xxx_chip *chip = bus->priv;
2877 if (phy >= mv88e6xxx_num_ports(chip))
2880 mutex_lock(&chip->reg_lock);
2881 err = mv88e6xxx_phy_write(chip, phy, reg, val);
2882 mutex_unlock(&chip->reg_lock);
2887 static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
2888 struct device_node *np)
2891 struct mii_bus *bus;
2895 chip->mdio_np = of_get_child_by_name(np, "mdio");
2897 bus = devm_mdiobus_alloc(chip->dev);
2901 bus->priv = (void *)chip;
2903 bus->name = np->full_name;
2904 snprintf(bus->id, MII_BUS_ID_SIZE, "%s", np->full_name);
2906 bus->name = "mv88e6xxx SMI";
2907 snprintf(bus->id, MII_BUS_ID_SIZE, "mv88e6xxx-%d", index++);
2910 bus->read = mv88e6xxx_mdio_read;
2911 bus->write = mv88e6xxx_mdio_write;
2912 bus->parent = chip->dev;
2915 err = of_mdiobus_register(bus, chip->mdio_np);
2917 err = mdiobus_register(bus);
2919 dev_err(chip->dev, "Cannot register MDIO bus (%d)\n", err);
2922 chip->mdio_bus = bus;
2928 of_node_put(chip->mdio_np);
2933 static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip)
2936 struct mii_bus *bus = chip->mdio_bus;
2938 mdiobus_unregister(bus);
2941 of_node_put(chip->mdio_np);
2944 #ifdef CONFIG_NET_DSA_HWMON
2946 static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp)
2948 struct mv88e6xxx_chip *chip = ds->priv;
2954 mutex_lock(&chip->reg_lock);
2956 ret = mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x6);
2960 /* Enable temperature sensor */
2961 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
2965 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val | (1 << 5));
2969 /* Wait for temperature to stabilize */
2970 usleep_range(10000, 12000);
2972 ret = mv88e6xxx_phy_read(chip, 0x0, 0x1a, &val);
2976 /* Disable temperature sensor */
2977 ret = mv88e6xxx_phy_write(chip, 0x0, 0x1a, val & ~(1 << 5));
2981 *temp = ((val & 0x1f) - 5) * 5;
2984 mv88e6xxx_phy_write(chip, 0x0, 0x16, 0x0);
2985 mutex_unlock(&chip->reg_lock);
2989 static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp)
2991 struct mv88e6xxx_chip *chip = ds->priv;
2992 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
2998 mutex_lock(&chip->reg_lock);
2999 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 27, &val);
3000 mutex_unlock(&chip->reg_lock);
3004 *temp = (val & 0xff) - 25;
3009 static int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp)
3011 struct mv88e6xxx_chip *chip = ds->priv;
3013 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP))
3016 if (mv88e6xxx_6320_family(chip) || mv88e6xxx_6352_family(chip))
3017 return mv88e63xx_get_temp(ds, temp);
3019 return mv88e61xx_get_temp(ds, temp);
3022 static int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp)
3024 struct mv88e6xxx_chip *chip = ds->priv;
3025 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
3029 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
3034 mutex_lock(&chip->reg_lock);
3035 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3036 mutex_unlock(&chip->reg_lock);
3040 *temp = (((val >> 8) & 0x1f) * 5) - 25;
3045 static int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp)
3047 struct mv88e6xxx_chip *chip = ds->priv;
3048 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
3052 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
3055 mutex_lock(&chip->reg_lock);
3056 err = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3059 temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
3060 err = mv88e6xxx_phy_page_write(chip, phy, 6, 26,
3061 (val & 0xe0ff) | (temp << 8));
3063 mutex_unlock(&chip->reg_lock);
3068 static int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
3070 struct mv88e6xxx_chip *chip = ds->priv;
3071 int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
3075 if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP_LIMIT))
3080 mutex_lock(&chip->reg_lock);
3081 ret = mv88e6xxx_phy_page_read(chip, phy, 6, 26, &val);
3082 mutex_unlock(&chip->reg_lock);
3086 *alarm = !!(val & 0x40);
3090 #endif /* CONFIG_NET_DSA_HWMON */
3092 static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
3094 struct mv88e6xxx_chip *chip = ds->priv;
3096 return chip->eeprom_len;
3099 static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
3100 struct ethtool_eeprom *eeprom, u8 *data)
3102 struct mv88e6xxx_chip *chip = ds->priv;
3105 if (!chip->info->ops->get_eeprom)
3108 mutex_lock(&chip->reg_lock);
3109 err = chip->info->ops->get_eeprom(chip, eeprom, data);
3110 mutex_unlock(&chip->reg_lock);
3115 eeprom->magic = 0xc3ec4951;
3120 static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
3121 struct ethtool_eeprom *eeprom, u8 *data)
3123 struct mv88e6xxx_chip *chip = ds->priv;
3126 if (!chip->info->ops->set_eeprom)
3129 if (eeprom->magic != 0xc3ec4951)
3132 mutex_lock(&chip->reg_lock);
3133 err = chip->info->ops->set_eeprom(chip, eeprom, data);
3134 mutex_unlock(&chip->reg_lock);
3139 static const struct mv88e6xxx_ops mv88e6085_ops = {
3140 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3141 .phy_read = mv88e6xxx_phy_ppu_read,
3142 .phy_write = mv88e6xxx_phy_ppu_write,
3143 .port_set_link = mv88e6xxx_port_set_link,
3144 .port_set_duplex = mv88e6xxx_port_set_duplex,
3145 .port_set_speed = mv88e6185_port_set_speed,
3148 static const struct mv88e6xxx_ops mv88e6095_ops = {
3149 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3150 .phy_read = mv88e6xxx_phy_ppu_read,
3151 .phy_write = mv88e6xxx_phy_ppu_write,
3152 .port_set_link = mv88e6xxx_port_set_link,
3153 .port_set_duplex = mv88e6xxx_port_set_duplex,
3154 .port_set_speed = mv88e6185_port_set_speed,
3157 static const struct mv88e6xxx_ops mv88e6123_ops = {
3158 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3159 .phy_read = mv88e6xxx_read,
3160 .phy_write = mv88e6xxx_write,
3161 .port_set_link = mv88e6xxx_port_set_link,
3162 .port_set_duplex = mv88e6xxx_port_set_duplex,
3163 .port_set_speed = mv88e6185_port_set_speed,
3166 static const struct mv88e6xxx_ops mv88e6131_ops = {
3167 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3168 .phy_read = mv88e6xxx_phy_ppu_read,
3169 .phy_write = mv88e6xxx_phy_ppu_write,
3170 .port_set_link = mv88e6xxx_port_set_link,
3171 .port_set_duplex = mv88e6xxx_port_set_duplex,
3172 .port_set_speed = mv88e6185_port_set_speed,
3175 static const struct mv88e6xxx_ops mv88e6161_ops = {
3176 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3177 .phy_read = mv88e6xxx_read,
3178 .phy_write = mv88e6xxx_write,
3179 .port_set_link = mv88e6xxx_port_set_link,
3180 .port_set_duplex = mv88e6xxx_port_set_duplex,
3181 .port_set_speed = mv88e6185_port_set_speed,
3184 static const struct mv88e6xxx_ops mv88e6165_ops = {
3185 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3186 .phy_read = mv88e6xxx_read,
3187 .phy_write = mv88e6xxx_write,
3188 .port_set_link = mv88e6xxx_port_set_link,
3189 .port_set_duplex = mv88e6xxx_port_set_duplex,
3190 .port_set_speed = mv88e6185_port_set_speed,
3193 static const struct mv88e6xxx_ops mv88e6171_ops = {
3194 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3195 .phy_read = mv88e6xxx_g2_smi_phy_read,
3196 .phy_write = mv88e6xxx_g2_smi_phy_write,
3197 .port_set_link = mv88e6xxx_port_set_link,
3198 .port_set_duplex = mv88e6xxx_port_set_duplex,
3199 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3200 .port_set_speed = mv88e6185_port_set_speed,
3203 static const struct mv88e6xxx_ops mv88e6172_ops = {
3204 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3205 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
3206 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3207 .phy_read = mv88e6xxx_g2_smi_phy_read,
3208 .phy_write = mv88e6xxx_g2_smi_phy_write,
3209 .port_set_link = mv88e6xxx_port_set_link,
3210 .port_set_duplex = mv88e6xxx_port_set_duplex,
3211 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3212 .port_set_speed = mv88e6352_port_set_speed,
3215 static const struct mv88e6xxx_ops mv88e6175_ops = {
3216 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3217 .phy_read = mv88e6xxx_g2_smi_phy_read,
3218 .phy_write = mv88e6xxx_g2_smi_phy_write,
3219 .port_set_link = mv88e6xxx_port_set_link,
3220 .port_set_duplex = mv88e6xxx_port_set_duplex,
3221 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3222 .port_set_speed = mv88e6185_port_set_speed,
3225 static const struct mv88e6xxx_ops mv88e6176_ops = {
3226 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3227 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
3228 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3229 .phy_read = mv88e6xxx_g2_smi_phy_read,
3230 .phy_write = mv88e6xxx_g2_smi_phy_write,
3231 .port_set_link = mv88e6xxx_port_set_link,
3232 .port_set_duplex = mv88e6xxx_port_set_duplex,
3233 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3234 .port_set_speed = mv88e6352_port_set_speed,
3237 static const struct mv88e6xxx_ops mv88e6185_ops = {
3238 .set_switch_mac = mv88e6xxx_g1_set_switch_mac,
3239 .phy_read = mv88e6xxx_phy_ppu_read,
3240 .phy_write = mv88e6xxx_phy_ppu_write,
3241 .port_set_link = mv88e6xxx_port_set_link,
3242 .port_set_duplex = mv88e6xxx_port_set_duplex,
3243 .port_set_speed = mv88e6185_port_set_speed,
3246 static const struct mv88e6xxx_ops mv88e6240_ops = {
3247 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3248 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
3249 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3250 .phy_read = mv88e6xxx_g2_smi_phy_read,
3251 .phy_write = mv88e6xxx_g2_smi_phy_write,
3252 .port_set_link = mv88e6xxx_port_set_link,
3253 .port_set_duplex = mv88e6xxx_port_set_duplex,
3254 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3255 .port_set_speed = mv88e6352_port_set_speed,
3258 static const struct mv88e6xxx_ops mv88e6320_ops = {
3259 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3260 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
3261 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3262 .phy_read = mv88e6xxx_g2_smi_phy_read,
3263 .phy_write = mv88e6xxx_g2_smi_phy_write,
3264 .port_set_link = mv88e6xxx_port_set_link,
3265 .port_set_duplex = mv88e6xxx_port_set_duplex,
3266 .port_set_speed = mv88e6185_port_set_speed,
3269 static const struct mv88e6xxx_ops mv88e6321_ops = {
3270 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3271 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
3272 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3273 .phy_read = mv88e6xxx_g2_smi_phy_read,
3274 .phy_write = mv88e6xxx_g2_smi_phy_write,
3275 .port_set_link = mv88e6xxx_port_set_link,
3276 .port_set_duplex = mv88e6xxx_port_set_duplex,
3277 .port_set_speed = mv88e6185_port_set_speed,
3280 static const struct mv88e6xxx_ops mv88e6350_ops = {
3281 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3282 .phy_read = mv88e6xxx_g2_smi_phy_read,
3283 .phy_write = mv88e6xxx_g2_smi_phy_write,
3284 .port_set_link = mv88e6xxx_port_set_link,
3285 .port_set_duplex = mv88e6xxx_port_set_duplex,
3286 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3287 .port_set_speed = mv88e6185_port_set_speed,
3290 static const struct mv88e6xxx_ops mv88e6351_ops = {
3291 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3292 .phy_read = mv88e6xxx_g2_smi_phy_read,
3293 .phy_write = mv88e6xxx_g2_smi_phy_write,
3294 .port_set_link = mv88e6xxx_port_set_link,
3295 .port_set_duplex = mv88e6xxx_port_set_duplex,
3296 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3297 .port_set_speed = mv88e6185_port_set_speed,
3300 static const struct mv88e6xxx_ops mv88e6352_ops = {
3301 .get_eeprom = mv88e6xxx_g2_get_eeprom16,
3302 .set_eeprom = mv88e6xxx_g2_set_eeprom16,
3303 .set_switch_mac = mv88e6xxx_g2_set_switch_mac,
3304 .phy_read = mv88e6xxx_g2_smi_phy_read,
3305 .phy_write = mv88e6xxx_g2_smi_phy_write,
3306 .port_set_link = mv88e6xxx_port_set_link,
3307 .port_set_duplex = mv88e6xxx_port_set_duplex,
3308 .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay,
3309 .port_set_speed = mv88e6352_port_set_speed,
3312 static const struct mv88e6xxx_info mv88e6xxx_table[] = {
3314 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
3315 .family = MV88E6XXX_FAMILY_6097,
3316 .name = "Marvell 88E6085",
3317 .num_databases = 4096,
3319 .port_base_addr = 0x10,
3320 .global1_addr = 0x1b,
3321 .age_time_coeff = 15000,
3323 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
3324 .ops = &mv88e6085_ops,
3328 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
3329 .family = MV88E6XXX_FAMILY_6095,
3330 .name = "Marvell 88E6095/88E6095F",
3331 .num_databases = 256,
3333 .port_base_addr = 0x10,
3334 .global1_addr = 0x1b,
3335 .age_time_coeff = 15000,
3337 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
3338 .ops = &mv88e6095_ops,
3342 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
3343 .family = MV88E6XXX_FAMILY_6165,
3344 .name = "Marvell 88E6123",
3345 .num_databases = 4096,
3347 .port_base_addr = 0x10,
3348 .global1_addr = 0x1b,
3349 .age_time_coeff = 15000,
3351 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
3352 .ops = &mv88e6123_ops,
3356 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
3357 .family = MV88E6XXX_FAMILY_6185,
3358 .name = "Marvell 88E6131",
3359 .num_databases = 256,
3361 .port_base_addr = 0x10,
3362 .global1_addr = 0x1b,
3363 .age_time_coeff = 15000,
3365 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
3366 .ops = &mv88e6131_ops,
3370 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
3371 .family = MV88E6XXX_FAMILY_6165,
3372 .name = "Marvell 88E6161",
3373 .num_databases = 4096,
3375 .port_base_addr = 0x10,
3376 .global1_addr = 0x1b,
3377 .age_time_coeff = 15000,
3379 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
3380 .ops = &mv88e6161_ops,
3384 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
3385 .family = MV88E6XXX_FAMILY_6165,
3386 .name = "Marvell 88E6165",
3387 .num_databases = 4096,
3389 .port_base_addr = 0x10,
3390 .global1_addr = 0x1b,
3391 .age_time_coeff = 15000,
3393 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
3394 .ops = &mv88e6165_ops,
3398 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
3399 .family = MV88E6XXX_FAMILY_6351,
3400 .name = "Marvell 88E6171",
3401 .num_databases = 4096,
3403 .port_base_addr = 0x10,
3404 .global1_addr = 0x1b,
3405 .age_time_coeff = 15000,
3407 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
3408 .ops = &mv88e6171_ops,
3412 .prod_num = PORT_SWITCH_ID_PROD_NUM_6172,
3413 .family = MV88E6XXX_FAMILY_6352,
3414 .name = "Marvell 88E6172",
3415 .num_databases = 4096,
3417 .port_base_addr = 0x10,
3418 .global1_addr = 0x1b,
3419 .age_time_coeff = 15000,
3421 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
3422 .ops = &mv88e6172_ops,
3426 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
3427 .family = MV88E6XXX_FAMILY_6351,
3428 .name = "Marvell 88E6175",
3429 .num_databases = 4096,
3431 .port_base_addr = 0x10,
3432 .global1_addr = 0x1b,
3433 .age_time_coeff = 15000,
3435 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
3436 .ops = &mv88e6175_ops,
3440 .prod_num = PORT_SWITCH_ID_PROD_NUM_6176,
3441 .family = MV88E6XXX_FAMILY_6352,
3442 .name = "Marvell 88E6176",
3443 .num_databases = 4096,
3445 .port_base_addr = 0x10,
3446 .global1_addr = 0x1b,
3447 .age_time_coeff = 15000,
3449 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
3450 .ops = &mv88e6176_ops,
3454 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
3455 .family = MV88E6XXX_FAMILY_6185,
3456 .name = "Marvell 88E6185",
3457 .num_databases = 256,
3459 .port_base_addr = 0x10,
3460 .global1_addr = 0x1b,
3461 .age_time_coeff = 15000,
3463 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
3464 .ops = &mv88e6185_ops,
3468 .prod_num = PORT_SWITCH_ID_PROD_NUM_6240,
3469 .family = MV88E6XXX_FAMILY_6352,
3470 .name = "Marvell 88E6240",
3471 .num_databases = 4096,
3473 .port_base_addr = 0x10,
3474 .global1_addr = 0x1b,
3475 .age_time_coeff = 15000,
3477 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
3478 .ops = &mv88e6240_ops,
3482 .prod_num = PORT_SWITCH_ID_PROD_NUM_6320,
3483 .family = MV88E6XXX_FAMILY_6320,
3484 .name = "Marvell 88E6320",
3485 .num_databases = 4096,
3487 .port_base_addr = 0x10,
3488 .global1_addr = 0x1b,
3489 .age_time_coeff = 15000,
3491 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
3492 .ops = &mv88e6320_ops,
3496 .prod_num = PORT_SWITCH_ID_PROD_NUM_6321,
3497 .family = MV88E6XXX_FAMILY_6320,
3498 .name = "Marvell 88E6321",
3499 .num_databases = 4096,
3501 .port_base_addr = 0x10,
3502 .global1_addr = 0x1b,
3503 .age_time_coeff = 15000,
3505 .flags = MV88E6XXX_FLAGS_FAMILY_6320,
3506 .ops = &mv88e6321_ops,
3510 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
3511 .family = MV88E6XXX_FAMILY_6351,
3512 .name = "Marvell 88E6350",
3513 .num_databases = 4096,
3515 .port_base_addr = 0x10,
3516 .global1_addr = 0x1b,
3517 .age_time_coeff = 15000,
3519 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
3520 .ops = &mv88e6350_ops,
3524 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
3525 .family = MV88E6XXX_FAMILY_6351,
3526 .name = "Marvell 88E6351",
3527 .num_databases = 4096,
3529 .port_base_addr = 0x10,
3530 .global1_addr = 0x1b,
3531 .age_time_coeff = 15000,
3533 .flags = MV88E6XXX_FLAGS_FAMILY_6351,
3534 .ops = &mv88e6351_ops,
3538 .prod_num = PORT_SWITCH_ID_PROD_NUM_6352,
3539 .family = MV88E6XXX_FAMILY_6352,
3540 .name = "Marvell 88E6352",
3541 .num_databases = 4096,
3543 .port_base_addr = 0x10,
3544 .global1_addr = 0x1b,
3545 .age_time_coeff = 15000,
3547 .flags = MV88E6XXX_FLAGS_FAMILY_6352,
3548 .ops = &mv88e6352_ops,
3552 static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3556 for (i = 0; i < ARRAY_SIZE(mv88e6xxx_table); ++i)
3557 if (mv88e6xxx_table[i].prod_num == prod_num)
3558 return &mv88e6xxx_table[i];
3563 static int mv88e6xxx_detect(struct mv88e6xxx_chip *chip)
3565 const struct mv88e6xxx_info *info;
3566 unsigned int prod_num, rev;
3570 mutex_lock(&chip->reg_lock);
3571 err = mv88e6xxx_port_read(chip, 0, PORT_SWITCH_ID, &id);
3572 mutex_unlock(&chip->reg_lock);
3576 prod_num = (id & 0xfff0) >> 4;
3579 info = mv88e6xxx_lookup_info(prod_num);
3583 /* Update the compatible info with the probed one */
3586 err = mv88e6xxx_g2_require(chip);
3590 dev_info(chip->dev, "switch 0x%x detected: %s, revision %u\n",
3591 chip->info->prod_num, chip->info->name, rev);
3596 static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
3598 struct mv88e6xxx_chip *chip;
3600 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
3606 mutex_init(&chip->reg_lock);
3611 static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
3613 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
3614 mv88e6xxx_ppu_state_init(chip);
3617 static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
3619 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
3620 mv88e6xxx_ppu_state_destroy(chip);
3623 static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
3624 struct mii_bus *bus, int sw_addr)
3626 /* ADDR[0] pin is unavailable externally and considered zero */
3631 chip->smi_ops = &mv88e6xxx_smi_single_chip_ops;
3632 else if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_MULTI_CHIP))
3633 chip->smi_ops = &mv88e6xxx_smi_multi_chip_ops;
3638 chip->sw_addr = sw_addr;
3643 static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
3645 struct mv88e6xxx_chip *chip = ds->priv;
3647 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA))
3648 return DSA_TAG_PROTO_EDSA;
3650 return DSA_TAG_PROTO_DSA;
3653 static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3654 struct device *host_dev, int sw_addr,
3657 struct mv88e6xxx_chip *chip;
3658 struct mii_bus *bus;
3661 bus = dsa_host_dev_to_mii_bus(host_dev);
3665 chip = mv88e6xxx_alloc_chip(dsa_dev);
3669 /* Legacy SMI probing will only support chips similar to 88E6085 */
3670 chip->info = &mv88e6xxx_table[MV88E6085];
3672 err = mv88e6xxx_smi_init(chip, bus, sw_addr);
3676 err = mv88e6xxx_detect(chip);
3680 mutex_lock(&chip->reg_lock);
3681 err = mv88e6xxx_switch_reset(chip);
3682 mutex_unlock(&chip->reg_lock);
3686 mv88e6xxx_phy_init(chip);
3688 err = mv88e6xxx_mdio_register(chip, NULL);
3694 return chip->info->name;
3696 devm_kfree(dsa_dev, chip);
3701 static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
3702 const struct switchdev_obj_port_mdb *mdb,
3703 struct switchdev_trans *trans)
3705 /* We don't need any dynamic resource from the kernel (yet),
3706 * so skip the prepare phase.
3712 static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
3713 const struct switchdev_obj_port_mdb *mdb,
3714 struct switchdev_trans *trans)
3716 struct mv88e6xxx_chip *chip = ds->priv;
3718 mutex_lock(&chip->reg_lock);
3719 if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3720 GLOBAL_ATU_DATA_STATE_MC_STATIC))
3721 netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
3722 mutex_unlock(&chip->reg_lock);
3725 static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
3726 const struct switchdev_obj_port_mdb *mdb)
3728 struct mv88e6xxx_chip *chip = ds->priv;
3731 mutex_lock(&chip->reg_lock);
3732 err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
3733 GLOBAL_ATU_DATA_STATE_UNUSED);
3734 mutex_unlock(&chip->reg_lock);
3739 static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
3740 struct switchdev_obj_port_mdb *mdb,
3741 int (*cb)(struct switchdev_obj *obj))
3743 struct mv88e6xxx_chip *chip = ds->priv;
3746 mutex_lock(&chip->reg_lock);
3747 err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
3748 mutex_unlock(&chip->reg_lock);
3753 static struct dsa_switch_ops mv88e6xxx_switch_ops = {
3754 .probe = mv88e6xxx_drv_probe,
3755 .get_tag_protocol = mv88e6xxx_get_tag_protocol,
3756 .setup = mv88e6xxx_setup,
3757 .set_addr = mv88e6xxx_set_addr,
3758 .adjust_link = mv88e6xxx_adjust_link,
3759 .get_strings = mv88e6xxx_get_strings,
3760 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
3761 .get_sset_count = mv88e6xxx_get_sset_count,
3762 .set_eee = mv88e6xxx_set_eee,
3763 .get_eee = mv88e6xxx_get_eee,
3764 #ifdef CONFIG_NET_DSA_HWMON
3765 .get_temp = mv88e6xxx_get_temp,
3766 .get_temp_limit = mv88e6xxx_get_temp_limit,
3767 .set_temp_limit = mv88e6xxx_set_temp_limit,
3768 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
3770 .get_eeprom_len = mv88e6xxx_get_eeprom_len,
3771 .get_eeprom = mv88e6xxx_get_eeprom,
3772 .set_eeprom = mv88e6xxx_set_eeprom,
3773 .get_regs_len = mv88e6xxx_get_regs_len,
3774 .get_regs = mv88e6xxx_get_regs,
3775 .set_ageing_time = mv88e6xxx_set_ageing_time,
3776 .port_bridge_join = mv88e6xxx_port_bridge_join,
3777 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
3778 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
3779 .port_fast_age = mv88e6xxx_port_fast_age,
3780 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
3781 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
3782 .port_vlan_add = mv88e6xxx_port_vlan_add,
3783 .port_vlan_del = mv88e6xxx_port_vlan_del,
3784 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
3785 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
3786 .port_fdb_add = mv88e6xxx_port_fdb_add,
3787 .port_fdb_del = mv88e6xxx_port_fdb_del,
3788 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
3789 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
3790 .port_mdb_add = mv88e6xxx_port_mdb_add,
3791 .port_mdb_del = mv88e6xxx_port_mdb_del,
3792 .port_mdb_dump = mv88e6xxx_port_mdb_dump,
3795 static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
3796 struct device_node *np)
3798 struct device *dev = chip->dev;
3799 struct dsa_switch *ds;
3801 ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
3807 ds->ops = &mv88e6xxx_switch_ops;
3809 dev_set_drvdata(dev, ds);
3811 return dsa_register_switch(ds, np);
3814 static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
3816 dsa_unregister_switch(chip->ds);
3819 static int mv88e6xxx_probe(struct mdio_device *mdiodev)
3821 struct device *dev = &mdiodev->dev;
3822 struct device_node *np = dev->of_node;
3823 const struct mv88e6xxx_info *compat_info;
3824 struct mv88e6xxx_chip *chip;
3828 compat_info = of_device_get_match_data(dev);
3832 chip = mv88e6xxx_alloc_chip(dev);
3836 chip->info = compat_info;
3838 err = mv88e6xxx_smi_init(chip, mdiodev->bus, mdiodev->addr);
3842 err = mv88e6xxx_detect(chip);
3846 mv88e6xxx_phy_init(chip);
3848 chip->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
3849 if (IS_ERR(chip->reset))
3850 return PTR_ERR(chip->reset);
3852 if (chip->info->ops->get_eeprom &&
3853 !of_property_read_u32(np, "eeprom-length", &eeprom_len))
3854 chip->eeprom_len = eeprom_len;
3856 mutex_lock(&chip->reg_lock);
3857 err = mv88e6xxx_switch_reset(chip);
3858 mutex_unlock(&chip->reg_lock);
3862 chip->irq = of_irq_get(np, 0);
3863 if (chip->irq == -EPROBE_DEFER) {
3868 if (chip->irq > 0) {
3869 /* Has to be performed before the MDIO bus is created,
3870 * because the PHYs will link there interrupts to these
3871 * interrupt controllers
3873 mutex_lock(&chip->reg_lock);
3874 err = mv88e6xxx_g1_irq_setup(chip);
3875 mutex_unlock(&chip->reg_lock);
3880 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT)) {
3881 err = mv88e6xxx_g2_irq_setup(chip);
3887 err = mv88e6xxx_mdio_register(chip, np);
3891 err = mv88e6xxx_register_switch(chip, np);
3898 mv88e6xxx_mdio_unregister(chip);
3900 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT) && chip->irq > 0)
3901 mv88e6xxx_g2_irq_free(chip);
3904 mv88e6xxx_g1_irq_free(chip);
3909 static void mv88e6xxx_remove(struct mdio_device *mdiodev)
3911 struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
3912 struct mv88e6xxx_chip *chip = ds->priv;
3914 mv88e6xxx_phy_destroy(chip);
3915 mv88e6xxx_unregister_switch(chip);
3916 mv88e6xxx_mdio_unregister(chip);
3918 if (chip->irq > 0) {
3919 if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_INT))
3920 mv88e6xxx_g2_irq_free(chip);
3921 mv88e6xxx_g1_irq_free(chip);
3925 static const struct of_device_id mv88e6xxx_of_match[] = {
3927 .compatible = "marvell,mv88e6085",
3928 .data = &mv88e6xxx_table[MV88E6085],
3933 MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match);
3935 static struct mdio_driver mv88e6xxx_driver = {
3936 .probe = mv88e6xxx_probe,
3937 .remove = mv88e6xxx_remove,
3939 .name = "mv88e6085",
3940 .of_match_table = mv88e6xxx_of_match,
3944 static int __init mv88e6xxx_init(void)
3946 register_switch_driver(&mv88e6xxx_switch_ops);
3947 return mdio_driver_register(&mv88e6xxx_driver);
3949 module_init(mv88e6xxx_init);
3951 static void __exit mv88e6xxx_cleanup(void)
3953 mdio_driver_unregister(&mv88e6xxx_driver);
3954 unregister_switch_driver(&mv88e6xxx_switch_ops);
3956 module_exit(mv88e6xxx_cleanup);
3958 MODULE_AUTHOR("Lennert Buytenhek <buytenh@wantstofly.org>");
3959 MODULE_DESCRIPTION("Driver for Marvell 88E6XXX ethernet switch chips");
3960 MODULE_LICENSE("GPL");