Lines Matching +full:rx +full:- +full:pcs +full:- +full:m
1 // SPDX-License-Identifier: GPL-2.0
2 /* Realtek SMI subdriver for the Realtek RTL8365MB-VC ethernet switch.
4 * Copyright (C) 2021 Alvin Šipraga <alsi@bang-olufsen.dk>
5 * Copyright (C) 2021 Michael Rasmussen <mir@bang-olufsen.dk>
7 * The RTL8365MB-VC is a 4+1 port 10/100/1000M switch controller. It includes 4
9 * can be connected to the CPU - or another PHY - via either MII, RMII, or
15 * .-----------------------------------.
17 * UTP <---------------> Giga PHY <-> PCS <-> P0 GMAC |
18 * UTP <---------------> Giga PHY <-> PCS <-> P1 GMAC |
19 * UTP <---------------> Giga PHY <-> PCS <-> P2 GMAC |
20 * UTP <---------------> Giga PHY <-> PCS <-> P3 GMAC |
22 * CPU/PHY <-MII/RMII/RGMII---> Extension <---> Extension |
25 * SMI driver/ <-MDC/SCL---> Management ~~~~~~~~~~~~~~ |
26 * EEPROM <-MDIO/SDA--> interface ~REALTEK ~~~~~ |
29 * GPIO <--------------> Reset ~~~~~~~~~~~~~~ |
31 * Interrupt <----------> Link UP/DOWN events |
33 * '-----------------------------------'
38 * partner of the extension port - either via a fixed-link or other phy-handle.
40 * driver has only been tested with a fixed-link, but in principle it should not
55 * This Linux driver is written based on an OS-agnostic vendor driver from
56 * Realtek. The reference GPL-licensed sources can be found in the OpenWrt
59 * have is the RTL8365MB-VC. Moreover, there does not seem to be any chip under
61 * common hardware revision, there exist examples of chips with the suffix -VC
72 * - RTL8363NB
73 * - RTL8363NB-VB
74 * - RTL8363SC
75 * - RTL8363SC-VB
76 * - RTL8364NB
77 * - RTL8364NB-VB
78 * - RTL8365MB-VC
79 * - RTL8366SC
80 * - RTL8367RB-VB
81 * - RTL8367SB
82 * - RTL8367S
83 * - RTL8370MB
84 * - RTL8310SR
88 * things will work out-of-the-box for other chips, and a careful review of the
89 * vendor driver may be needed to expand support. The RTL8365MB-VC seems to be
104 #include "realtek-smi.h"
105 #include "realtek-mdio.h"
108 /* Family-specific data and limits */
111 #define RTL8365MB_PHYREGMAX (RTL8365MB_NUM_PHYREGS - 1)
135 /* Interrupt control/status register - enable/check specific interrupt types */
164 /* Per-port interrupt type status registers */
195 /* External interface port mode values - used in DIGITAL_INTERFACE_SELECT */
223 /* External interface RGMII TX/RX delay configuration registers 0~2 */
235 /* External interface port speed values - used in DIGITAL_INTERFACE_FORCE */
257 /* CPU port mask register - controls which ports are treated as CPU ports */
287 /* MSTP port state registers - indexed by tree instance */
485 * struct rtl8365mb_extint - external interface info
490 * Represents a mapping: port -> { id, supported_interfaces }. To be embedded
500 * struct rtl8365mb_chip_info - static chip-specific info
501 * @name: human-readable chip name
505 * @jam_table: chip-specific initialization jam table
525 .name = "RTL8365MB-VC",
548 .name = "RTL8367RB-VB",
591 * struct rtl8365mb_cpu - CPU port configuration
592 * @enable: enable/disable hardware insertion of CPU tag in switch->CPU frames
595 * @insert: CPU tag insertion mode in switch->CPU frames
597 * @rx_length: minimum CPU RX length
614 * struct rtl8365mb_port - private per-port data
631 * struct rtl8365mb - driver private data
634 * @chip_info: chip-specific info about the attached switch
637 * @ports: per-port data
654 return regmap_read_poll_timeout(priv->map_nolock, in rtl8365mb_phy_poll_busy()
668 priv->map_nolock, RTL8365MB_GPHY_OCP_MSB_0_REG, in rtl8365mb_phy_ocp_prepare()
681 ret = regmap_write(priv->map_nolock, in rtl8365mb_phy_ocp_prepare()
710 ret = regmap_write(priv->map_nolock, RTL8365MB_INDIRECT_ACCESS_CTRL_REG, in rtl8365mb_phy_ocp_read()
720 ret = regmap_read(priv->map_nolock, in rtl8365mb_phy_ocp_read()
750 ret = regmap_write(priv->map_nolock, in rtl8365mb_phy_ocp_write()
760 ret = regmap_write(priv->map_nolock, RTL8365MB_INDIRECT_ACCESS_CTRL_REG, in rtl8365mb_phy_ocp_write()
782 return -EINVAL; in rtl8365mb_phy_read()
785 return -EINVAL; in rtl8365mb_phy_read()
791 dev_err(priv->dev, in rtl8365mb_phy_read()
797 dev_dbg(priv->dev, "read PHY%d register 0x%02x @ %04x, val <- %04x\n", in rtl8365mb_phy_read()
810 return -EINVAL; in rtl8365mb_phy_write()
813 return -EINVAL; in rtl8365mb_phy_write()
819 dev_err(priv->dev, in rtl8365mb_phy_write()
825 dev_dbg(priv->dev, "write PHY%d register 0x%02x @ %04x, val -> %04x\n", in rtl8365mb_phy_write()
834 struct rtl8365mb *mb = priv->chip_data; in rtl8365mb_get_port_extint()
839 &mb->chip_info->extints[i]; in rtl8365mb_get_port_extint()
841 if (!extint->supported_interfaces) in rtl8365mb_get_port_extint()
844 if (extint->port == port) in rtl8365mb_get_port_extint()
855 struct realtek_priv *priv = ds->priv; in rtl8365mb_get_tag_protocol()
859 mb = priv->chip_data; in rtl8365mb_get_tag_protocol()
860 cpu = &mb->cpu; in rtl8365mb_get_tag_protocol()
862 if (cpu->position == RTL8365MB_CPU_POS_BEFORE_CRC) in rtl8365mb_get_tag_protocol()
873 struct dsa_switch *ds = &priv->ds; in rtl8365mb_ext_config_rgmii()
882 return -ENODEV; in rtl8365mb_ext_config_rgmii()
885 dn = dp->dn; in rtl8365mb_ext_config_rgmii()
887 /* Set the RGMII TX/RX delay in rtl8365mb_ext_config_rgmii()
894 * RX delay: in rtl8365mb_ext_config_rgmii()
903 * Only configure an RGMII TX (resp. RX) delay if the in rtl8365mb_ext_config_rgmii()
904 * tx-internal-delay-ps (resp. rx-internal-delay-ps) OF property is in rtl8365mb_ext_config_rgmii()
906 * (RGMII_{RXID, TXID, etc.}), as this is considered to be a PHY-only in rtl8365mb_ext_config_rgmii()
909 if (!of_property_read_u32(dn, "tx-internal-delay-ps", &val)) { in rtl8365mb_ext_config_rgmii()
915 dev_warn(priv->dev, in rtl8365mb_ext_config_rgmii()
919 if (!of_property_read_u32(dn, "rx-internal-delay-ps", &val)) { in rtl8365mb_ext_config_rgmii()
925 dev_warn(priv->dev, in rtl8365mb_ext_config_rgmii()
926 "RGMII RX delay must be 0 to 2.1 ns\n"); in rtl8365mb_ext_config_rgmii()
930 priv->map, RTL8365MB_EXT_RGMXF_REG(extint->id), in rtl8365mb_ext_config_rgmii()
939 priv->map, RTL8365MB_DIGITAL_INTERFACE_SELECT_REG(extint->id), in rtl8365mb_ext_config_rgmii()
940 RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK(extint->id), in rtl8365mb_ext_config_rgmii()
943 extint->id)); in rtl8365mb_ext_config_rgmii()
965 return -ENODEV; in rtl8365mb_ext_config_forcemode()
980 dev_err(priv->dev, "unsupported port speed %s\n", in rtl8365mb_ext_config_forcemode()
982 return -EINVAL; in rtl8365mb_ext_config_forcemode()
990 dev_err(priv->dev, "unsupported duplex %s\n", in rtl8365mb_ext_config_forcemode()
992 return -EINVAL; in rtl8365mb_ext_config_forcemode()
1012 ret = regmap_write(priv->map, in rtl8365mb_ext_config_forcemode()
1013 RTL8365MB_DIGITAL_INTERFACE_FORCE_REG(extint->id), in rtl8365mb_ext_config_forcemode()
1025 rtl8365mb_get_port_extint(ds->priv, port); in rtl8365mb_phylink_get_caps()
1027 config->mac_capabilities = MAC_SYM_PAUSE | MAC_ASYM_PAUSE | in rtl8365mb_phylink_get_caps()
1032 config->supported_interfaces); in rtl8365mb_phylink_get_caps()
1038 config->supported_interfaces); in rtl8365mb_phylink_get_caps()
1047 if (extint->supported_interfaces & RTL8365MB_PHY_INTERFACE_MODE_RGMII) in rtl8365mb_phylink_get_caps()
1048 phy_interface_set_rgmii(config->supported_interfaces); in rtl8365mb_phylink_get_caps()
1056 struct realtek_priv *priv = dp->ds->priv; in rtl8365mb_phylink_mac_config()
1057 u8 port = dp->index; in rtl8365mb_phylink_mac_config()
1061 dev_err(priv->dev, in rtl8365mb_phylink_mac_config()
1062 "port %d supports only conventional PHY or fixed-link\n", in rtl8365mb_phylink_mac_config()
1067 if (phy_interface_mode_is_rgmii(state->interface)) { in rtl8365mb_phylink_mac_config()
1068 ret = rtl8365mb_ext_config_rgmii(priv, port, state->interface); in rtl8365mb_phylink_mac_config()
1070 dev_err(priv->dev, in rtl8365mb_phylink_mac_config()
1076 /* TODO: Implement MII and RMII modes, which the RTL8365MB-VC also in rtl8365mb_phylink_mac_config()
1086 struct realtek_priv *priv = dp->ds->priv; in rtl8365mb_phylink_mac_link_down()
1089 u8 port = dp->index; in rtl8365mb_phylink_mac_link_down()
1092 mb = priv->chip_data; in rtl8365mb_phylink_mac_link_down()
1093 p = &mb->ports[port]; in rtl8365mb_phylink_mac_link_down()
1094 cancel_delayed_work_sync(&p->mib_work); in rtl8365mb_phylink_mac_link_down()
1100 dev_err(priv->dev, in rtl8365mb_phylink_mac_link_down()
1116 struct realtek_priv *priv = dp->ds->priv; in rtl8365mb_phylink_mac_link_up()
1119 u8 port = dp->index; in rtl8365mb_phylink_mac_link_up()
1122 mb = priv->chip_data; in rtl8365mb_phylink_mac_link_up()
1123 p = &mb->ports[port]; in rtl8365mb_phylink_mac_link_up()
1124 schedule_delayed_work(&p->mib_work, 0); in rtl8365mb_phylink_mac_link_up()
1131 dev_err(priv->dev, in rtl8365mb_phylink_mac_link_up()
1142 struct realtek_priv *priv = ds->priv; in rtl8365mb_port_change_mtu()
1147 * RX length register, only allowing CPU port here is enough. in rtl8365mb_port_change_mtu()
1154 dev_dbg(priv->dev, "changing mtu to %d (frame size: %d)\n", in rtl8365mb_port_change_mtu()
1157 return regmap_update_bits(priv->map, RTL8365MB_CFG0_MAX_LEN_REG, in rtl8365mb_port_change_mtu()
1165 return RTL8365MB_CFG0_MAX_LEN_MAX - VLAN_ETH_HLEN - ETH_FCS_LEN; in rtl8365mb_port_max_mtu()
1171 struct realtek_priv *priv = ds->priv; in rtl8365mb_port_stp_state_set()
1190 dev_err(priv->dev, "invalid STP state: %u\n", state); in rtl8365mb_port_stp_state_set()
1194 regmap_update_bits(priv->map, RTL8365MB_MSTI_CTRL_REG(msti, port), in rtl8365mb_port_stp_state_set()
1207 return regmap_write(priv->map, RTL8365MB_LUT_PORT_LEARN_LIMIT_REG(port), in rtl8365mb_port_set_learning()
1214 return regmap_write(priv->map, RTL8365MB_PORT_ISOLATION_REG(port), mask); in rtl8365mb_port_set_isolation()
1229 ret = regmap_write(priv->map, RTL8365MB_MIB_ADDRESS_REG, in rtl8365mb_mib_counter_read()
1235 ret = regmap_read_poll_timeout(priv->map, RTL8365MB_MIB_CTRL0_REG, val, in rtl8365mb_mib_counter_read()
1243 return -EIO; in rtl8365mb_mib_counter_read()
1257 ret = regmap_read(priv->map, in rtl8365mb_mib_counter_read()
1258 RTL8365MB_MIB_COUNTER_REG(offset - i), &val); in rtl8365mb_mib_counter_read()
1273 struct realtek_priv *priv = ds->priv; in rtl8365mb_get_ethtool_stats()
1278 mb = priv->chip_data; in rtl8365mb_get_ethtool_stats()
1280 mutex_lock(&mb->mib_lock); in rtl8365mb_get_ethtool_stats()
1284 ret = rtl8365mb_mib_counter_read(priv, port, mib->offset, in rtl8365mb_get_ethtool_stats()
1285 mib->length, &data[i]); in rtl8365mb_get_ethtool_stats()
1287 dev_err(priv->dev, in rtl8365mb_get_ethtool_stats()
1293 mutex_unlock(&mb->mib_lock); in rtl8365mb_get_ethtool_stats()
1305 ethtool_puts(&data, mib->name); in rtl8365mb_get_strings()
1312 return -EOPNOTSUPP; in rtl8365mb_get_sset_count()
1320 struct realtek_priv *priv = ds->priv; in rtl8365mb_get_phy_stats()
1324 mb = priv->chip_data; in rtl8365mb_get_phy_stats()
1327 mutex_lock(&mb->mib_lock); in rtl8365mb_get_phy_stats()
1328 rtl8365mb_mib_counter_read(priv, port, mib->offset, mib->length, in rtl8365mb_get_phy_stats()
1329 &phy_stats->SymbolErrorDuringCarrier); in rtl8365mb_get_phy_stats()
1330 mutex_unlock(&mb->mib_lock); in rtl8365mb_get_phy_stats()
1356 struct realtek_priv *priv = ds->priv; in rtl8365mb_get_mac_stats()
1361 mb = priv->chip_data; in rtl8365mb_get_mac_stats()
1363 mutex_lock(&mb->mib_lock); in rtl8365mb_get_mac_stats()
1371 ret = rtl8365mb_mib_counter_read(priv, port, mib->offset, in rtl8365mb_get_mac_stats()
1372 mib->length, &cnt[i]); in rtl8365mb_get_mac_stats()
1376 mutex_unlock(&mb->mib_lock); in rtl8365mb_get_mac_stats()
1378 /* The RTL8365MB-VC exposes MIB objects, which we have to translate into in rtl8365mb_get_mac_stats()
1384 mac_stats->FramesTransmittedOK = cnt[RTL8365MB_MIB_ifOutUcastPkts] + in rtl8365mb_get_mac_stats()
1387 cnt[RTL8365MB_MIB_dot3OutPauseFrames] - in rtl8365mb_get_mac_stats()
1389 mac_stats->SingleCollisionFrames = in rtl8365mb_get_mac_stats()
1391 mac_stats->MultipleCollisionFrames = in rtl8365mb_get_mac_stats()
1393 mac_stats->FramesReceivedOK = cnt[RTL8365MB_MIB_ifInUcastPkts] + in rtl8365mb_get_mac_stats()
1397 mac_stats->FrameCheckSequenceErrors = in rtl8365mb_get_mac_stats()
1399 mac_stats->OctetsTransmittedOK = cnt[RTL8365MB_MIB_ifOutOctets] - in rtl8365mb_get_mac_stats()
1400 18 * mac_stats->FramesTransmittedOK; in rtl8365mb_get_mac_stats()
1401 mac_stats->FramesWithDeferredXmissions = in rtl8365mb_get_mac_stats()
1403 mac_stats->LateCollisions = cnt[RTL8365MB_MIB_dot3StatsLateCollisions]; in rtl8365mb_get_mac_stats()
1404 mac_stats->FramesAbortedDueToXSColls = in rtl8365mb_get_mac_stats()
1406 mac_stats->OctetsReceivedOK = cnt[RTL8365MB_MIB_ifInOctets] - in rtl8365mb_get_mac_stats()
1407 18 * mac_stats->FramesReceivedOK; in rtl8365mb_get_mac_stats()
1408 mac_stats->MulticastFramesXmittedOK = in rtl8365mb_get_mac_stats()
1410 mac_stats->BroadcastFramesXmittedOK = in rtl8365mb_get_mac_stats()
1412 mac_stats->MulticastFramesReceivedOK = in rtl8365mb_get_mac_stats()
1414 mac_stats->BroadcastFramesReceivedOK = in rtl8365mb_get_mac_stats()
1421 struct realtek_priv *priv = ds->priv; in rtl8365mb_get_ctrl_stats()
1425 mb = priv->chip_data; in rtl8365mb_get_ctrl_stats()
1428 mutex_lock(&mb->mib_lock); in rtl8365mb_get_ctrl_stats()
1429 rtl8365mb_mib_counter_read(priv, port, mib->offset, mib->length, in rtl8365mb_get_ctrl_stats()
1430 &ctrl_stats->UnsupportedOpcodesReceived); in rtl8365mb_get_ctrl_stats()
1431 mutex_unlock(&mb->mib_lock); in rtl8365mb_get_ctrl_stats()
1453 struct rtl8365mb *mb = priv->chip_data; in rtl8365mb_stats_update()
1458 stats = &mb->ports[port].stats; in rtl8365mb_stats_update()
1460 mutex_lock(&mb->mib_lock); in rtl8365mb_stats_update()
1468 ret = rtl8365mb_mib_counter_read(priv, port, c->offset, in rtl8365mb_stats_update()
1469 c->length, &cnt[i]); in rtl8365mb_stats_update()
1473 mutex_unlock(&mb->mib_lock); in rtl8365mb_stats_update()
1479 spin_lock(&mb->ports[port].stats_lock); in rtl8365mb_stats_update()
1481 stats->rx_packets = cnt[RTL8365MB_MIB_ifInUcastPkts] + in rtl8365mb_stats_update()
1483 cnt[RTL8365MB_MIB_ifInBroadcastPkts] - in rtl8365mb_stats_update()
1486 stats->tx_packets = cnt[RTL8365MB_MIB_ifOutUcastPkts] + in rtl8365mb_stats_update()
1490 /* if{In,Out}Octets includes FCS - remove it */ in rtl8365mb_stats_update()
1491 stats->rx_bytes = cnt[RTL8365MB_MIB_ifInOctets] - 4 * stats->rx_packets; in rtl8365mb_stats_update()
1492 stats->tx_bytes = in rtl8365mb_stats_update()
1493 cnt[RTL8365MB_MIB_ifOutOctets] - 4 * stats->tx_packets; in rtl8365mb_stats_update()
1495 stats->rx_dropped = cnt[RTL8365MB_MIB_etherStatsDropEvents]; in rtl8365mb_stats_update()
1496 stats->tx_dropped = cnt[RTL8365MB_MIB_ifOutDiscards]; in rtl8365mb_stats_update()
1498 stats->multicast = cnt[RTL8365MB_MIB_ifInMulticastPkts]; in rtl8365mb_stats_update()
1499 stats->collisions = cnt[RTL8365MB_MIB_etherStatsCollisions]; in rtl8365mb_stats_update()
1501 stats->rx_length_errors = cnt[RTL8365MB_MIB_etherStatsFragments] + in rtl8365mb_stats_update()
1503 stats->rx_crc_errors = cnt[RTL8365MB_MIB_dot3StatsFCSErrors]; in rtl8365mb_stats_update()
1504 stats->rx_errors = stats->rx_length_errors + stats->rx_crc_errors; in rtl8365mb_stats_update()
1506 stats->tx_aborted_errors = cnt[RTL8365MB_MIB_ifOutDiscards]; in rtl8365mb_stats_update()
1507 stats->tx_window_errors = cnt[RTL8365MB_MIB_dot3StatsLateCollisions]; in rtl8365mb_stats_update()
1508 stats->tx_errors = stats->tx_aborted_errors + stats->tx_window_errors; in rtl8365mb_stats_update()
1510 spin_unlock(&mb->ports[port].stats_lock); in rtl8365mb_stats_update()
1518 struct realtek_priv *priv = p->priv; in rtl8365mb_stats_poll()
1520 rtl8365mb_stats_update(priv, p->index); in rtl8365mb_stats_poll()
1522 schedule_delayed_work(&p->mib_work, RTL8365MB_STATS_INTERVAL_JIFFIES); in rtl8365mb_stats_poll()
1528 struct realtek_priv *priv = ds->priv; in rtl8365mb_get_stats64()
1532 mb = priv->chip_data; in rtl8365mb_get_stats64()
1533 p = &mb->ports[port]; in rtl8365mb_get_stats64()
1535 spin_lock(&p->stats_lock); in rtl8365mb_get_stats64()
1536 memcpy(s, &p->stats, sizeof(*s)); in rtl8365mb_get_stats64()
1537 spin_unlock(&p->stats_lock); in rtl8365mb_get_stats64()
1542 struct rtl8365mb *mb = priv->chip_data; in rtl8365mb_stats_setup()
1543 struct dsa_switch *ds = &priv->ds; in rtl8365mb_stats_setup()
1546 /* Per-chip global mutex to protect MIB counter access, since doing in rtl8365mb_stats_setup()
1549 mutex_init(&mb->mib_lock); in rtl8365mb_stats_setup()
1551 for (i = 0; i < priv->num_ports; i++) { in rtl8365mb_stats_setup()
1552 struct rtl8365mb_port *p = &mb->ports[i]; in rtl8365mb_stats_setup()
1557 /* Per-port spinlock to protect the stats64 data */ in rtl8365mb_stats_setup()
1558 spin_lock_init(&p->stats_lock); in rtl8365mb_stats_setup()
1561 * up-to-date. in rtl8365mb_stats_setup()
1563 INIT_DELAYED_WORK(&p->mib_work, rtl8365mb_stats_poll); in rtl8365mb_stats_setup()
1569 struct rtl8365mb *mb = priv->chip_data; in rtl8365mb_stats_teardown()
1570 struct dsa_switch *ds = &priv->ds; in rtl8365mb_stats_teardown()
1573 for (i = 0; i < priv->num_ports; i++) { in rtl8365mb_stats_teardown()
1574 struct rtl8365mb_port *p = &mb->ports[i]; in rtl8365mb_stats_teardown()
1579 cancel_delayed_work_sync(&p->mib_work); in rtl8365mb_stats_teardown()
1588 ret = regmap_read(priv->map, reg, val); in rtl8365mb_get_and_clear_status_reg()
1592 return regmap_write(priv->map, reg, *val); in rtl8365mb_get_and_clear_status_reg()
1633 for_each_set_bit(line, &line_changes, priv->num_ports) { in rtl8365mb_irq()
1634 int child_irq = irq_find_mapping(priv->irqdomain, line); in rtl8365mb_irq()
1642 dev_err(priv->dev, "failed to read interrupt status: %d\n", ret); in rtl8365mb_irq()
1650 /* The hardware doesn't support masking IRQs on a per-port basis */
1656 irq_set_chip_data(irq, domain->host_data); in rtl8365mb_irq_map()
1679 return regmap_update_bits(priv->map, RTL8365MB_INTR_CTRL_REG, in rtl8365mb_set_irq_enable()
1697 struct rtl8365mb *mb = priv->chip_data; in rtl8365mb_irq_setup()
1706 intc = of_get_child_by_name(priv->dev->of_node, "interrupt-controller"); in rtl8365mb_irq_setup()
1708 dev_err(priv->dev, "missing child interrupt-controller node\n"); in rtl8365mb_irq_setup()
1709 return -EINVAL; in rtl8365mb_irq_setup()
1715 if (irq != -EPROBE_DEFER) in rtl8365mb_irq_setup()
1716 dev_err(priv->dev, "failed to get parent irq: %d\n", in rtl8365mb_irq_setup()
1718 ret = irq ? irq : -EINVAL; in rtl8365mb_irq_setup()
1722 priv->irqdomain = irq_domain_add_linear(intc, priv->num_ports, in rtl8365mb_irq_setup()
1724 if (!priv->irqdomain) { in rtl8365mb_irq_setup()
1725 dev_err(priv->dev, "failed to add irq domain\n"); in rtl8365mb_irq_setup()
1726 ret = -ENOMEM; in rtl8365mb_irq_setup()
1730 for (i = 0; i < priv->num_ports; i++) { in rtl8365mb_irq_setup()
1731 virq = irq_create_mapping(priv->irqdomain, i); in rtl8365mb_irq_setup()
1733 dev_err(priv->dev, in rtl8365mb_irq_setup()
1735 ret = -EINVAL; in rtl8365mb_irq_setup()
1754 dev_err(priv->dev, "unsupported irq trigger type %u\n", in rtl8365mb_irq_setup()
1756 ret = -EINVAL; in rtl8365mb_irq_setup()
1760 ret = regmap_update_bits(priv->map, RTL8365MB_INTR_POLARITY_REG, in rtl8365mb_irq_setup()
1772 ret = regmap_write(priv->map, RTL8365MB_INTR_STATUS_REG, in rtl8365mb_irq_setup()
1780 dev_err(priv->dev, "failed to request irq: %d\n", ret); in rtl8365mb_irq_setup()
1785 mb->irq = irq; in rtl8365mb_irq_setup()
1796 free_irq(mb->irq, priv); in rtl8365mb_irq_setup()
1797 mb->irq = 0; in rtl8365mb_irq_setup()
1800 for (i = 0; i < priv->num_ports; i++) { in rtl8365mb_irq_setup()
1801 virq = irq_find_mapping(priv->irqdomain, i); in rtl8365mb_irq_setup()
1805 irq_domain_remove(priv->irqdomain); in rtl8365mb_irq_setup()
1806 priv->irqdomain = NULL; in rtl8365mb_irq_setup()
1816 struct rtl8365mb *mb = priv->chip_data; in rtl8365mb_irq_teardown()
1820 if (mb->irq) { in rtl8365mb_irq_teardown()
1821 free_irq(mb->irq, priv); in rtl8365mb_irq_teardown()
1822 mb->irq = 0; in rtl8365mb_irq_teardown()
1825 if (priv->irqdomain) { in rtl8365mb_irq_teardown()
1826 for (i = 0; i < priv->num_ports; i++) { in rtl8365mb_irq_teardown()
1827 virq = irq_find_mapping(priv->irqdomain, i); in rtl8365mb_irq_teardown()
1831 irq_domain_remove(priv->irqdomain); in rtl8365mb_irq_teardown()
1832 priv->irqdomain = NULL; in rtl8365mb_irq_teardown()
1838 struct rtl8365mb *mb = priv->chip_data; in rtl8365mb_cpu_config()
1839 struct rtl8365mb_cpu *cpu = &mb->cpu; in rtl8365mb_cpu_config()
1843 ret = regmap_update_bits(priv->map, RTL8365MB_CPU_PORT_MASK_REG, in rtl8365mb_cpu_config()
1846 cpu->mask)); in rtl8365mb_cpu_config()
1850 val = FIELD_PREP(RTL8365MB_CPU_CTRL_EN_MASK, cpu->enable ? 1 : 0) | in rtl8365mb_cpu_config()
1851 FIELD_PREP(RTL8365MB_CPU_CTRL_INSERTMODE_MASK, cpu->insert) | in rtl8365mb_cpu_config()
1852 FIELD_PREP(RTL8365MB_CPU_CTRL_TAG_POSITION_MASK, cpu->position) | in rtl8365mb_cpu_config()
1853 FIELD_PREP(RTL8365MB_CPU_CTRL_RXBYTECOUNT_MASK, cpu->rx_length) | in rtl8365mb_cpu_config()
1854 FIELD_PREP(RTL8365MB_CPU_CTRL_TAG_FORMAT_MASK, cpu->format) | in rtl8365mb_cpu_config()
1855 FIELD_PREP(RTL8365MB_CPU_CTRL_TRAP_PORT_MASK, cpu->trap_port & 0x7) | in rtl8365mb_cpu_config()
1857 cpu->trap_port >> 3 & 0x1); in rtl8365mb_cpu_config()
1858 ret = regmap_write(priv->map, RTL8365MB_CPU_CTRL_REG, val); in rtl8365mb_cpu_config()
1868 struct realtek_priv *priv = ds->priv; in rtl8365mb_change_tag_protocol()
1872 mb = priv->chip_data; in rtl8365mb_change_tag_protocol()
1873 cpu = &mb->cpu; in rtl8365mb_change_tag_protocol()
1877 cpu->format = RTL8365MB_CPU_FORMAT_8BYTES; in rtl8365mb_change_tag_protocol()
1878 cpu->position = RTL8365MB_CPU_POS_AFTER_SA; in rtl8365mb_change_tag_protocol()
1881 cpu->format = RTL8365MB_CPU_FORMAT_8BYTES; in rtl8365mb_change_tag_protocol()
1882 cpu->position = RTL8365MB_CPU_POS_BEFORE_CRC; in rtl8365mb_change_tag_protocol()
1884 /* The switch also supports a 4-byte format, similar to rtl4a but with in rtl8365mb_change_tag_protocol()
1885 * the same 0x04 8-bit version and probably 8-bit port source/dest. in rtl8365mb_change_tag_protocol()
1890 return -EPROTONOSUPPORT; in rtl8365mb_change_tag_protocol()
1898 struct rtl8365mb *mb = priv->chip_data; in rtl8365mb_switch_init()
1903 ci = mb->chip_info; in rtl8365mb_switch_init()
1905 /* Do any chip-specific init jam before getting to the common stuff */ in rtl8365mb_switch_init()
1906 if (ci->jam_table) { in rtl8365mb_switch_init()
1907 for (i = 0; i < ci->jam_size; i++) { in rtl8365mb_switch_init()
1908 ret = regmap_write(priv->map, ci->jam_table[i].reg, in rtl8365mb_switch_init()
1909 ci->jam_table[i].val); in rtl8365mb_switch_init()
1917 ret = regmap_write(priv->map, rtl8365mb_init_jam_common[i].reg, in rtl8365mb_switch_init()
1930 priv->write_reg_noack(priv, RTL8365MB_CHIP_RESET_REG, in rtl8365mb_reset_chip()
1937 return regmap_read_poll_timeout(priv->map, RTL8365MB_CHIP_RESET_REG, val, in rtl8365mb_reset_chip()
1944 struct realtek_priv *priv = ds->priv; in rtl8365mb_setup()
1951 mb = priv->chip_data; in rtl8365mb_setup()
1952 cpu = &mb->cpu; in rtl8365mb_setup()
1956 dev_err(priv->dev, "failed to reset chip: %d\n", ret); in rtl8365mb_setup()
1960 /* Configure switch to vendor-defined initial state */ in rtl8365mb_setup()
1963 dev_err(priv->dev, "failed to initialize switch: %d\n", ret); in rtl8365mb_setup()
1969 if (ret == -EPROBE_DEFER) in rtl8365mb_setup()
1972 dev_info(priv->dev, "no interrupt support\n"); in rtl8365mb_setup()
1976 cpu->mask |= BIT(cpu_dp->index); in rtl8365mb_setup()
1978 if (cpu->trap_port == RTL8365MB_MAX_NUM_PORTS) in rtl8365mb_setup()
1979 cpu->trap_port = cpu_dp->index; in rtl8365mb_setup()
1981 cpu->enable = cpu->mask > 0; in rtl8365mb_setup()
1987 for (i = 0; i < priv->num_ports; i++) { in rtl8365mb_setup()
1988 struct rtl8365mb_port *p = &mb->ports[i]; in rtl8365mb_setup()
1994 ret = rtl8365mb_port_set_isolation(priv, i, cpu->mask); in rtl8365mb_setup()
2009 /* Set up per-port private data */ in rtl8365mb_setup()
2010 p->priv = priv; in rtl8365mb_setup()
2011 p->index = i; in rtl8365mb_setup()
2014 ret = rtl8365mb_port_change_mtu(ds, cpu->trap_port, ETH_DATA_LEN); in rtl8365mb_setup()
2020 dev_err(priv->dev, "could not set up MDIO bus\n"); in rtl8365mb_setup()
2038 struct realtek_priv *priv = ds->priv; in rtl8365mb_teardown()
2073 struct rtl8365mb *mb = priv->chip_data; in rtl8365mb_detect()
2079 ret = rtl8365mb_get_chip_id_and_ver(priv->map, &chip_id, &chip_ver); in rtl8365mb_detect()
2081 dev_err(priv->dev, "failed to read chip id and version: %d\n", in rtl8365mb_detect()
2089 if (ci->chip_id == chip_id && ci->chip_ver == chip_ver) { in rtl8365mb_detect()
2090 mb->chip_info = ci; in rtl8365mb_detect()
2095 if (!mb->chip_info) { in rtl8365mb_detect()
2096 dev_err(priv->dev, in rtl8365mb_detect()
2099 return -ENODEV; in rtl8365mb_detect()
2102 dev_info(priv->dev, "found an %s switch\n", mb->chip_info->name); in rtl8365mb_detect()
2104 priv->num_ports = RTL8365MB_MAX_NUM_PORTS; in rtl8365mb_detect()
2105 mb->priv = priv; in rtl8365mb_detect()
2106 mb->cpu.trap_port = RTL8365MB_MAX_NUM_PORTS; in rtl8365mb_detect()
2107 mb->cpu.insert = RTL8365MB_CPU_INSERT_TO_ALL; in rtl8365mb_detect()
2108 mb->cpu.position = RTL8365MB_CPU_POS_AFTER_SA; in rtl8365mb_detect()
2109 mb->cpu.rx_length = RTL8365MB_CPU_RXLEN_64BYTES; in rtl8365mb_detect()
2110 mb->cpu.format = RTL8365MB_CPU_FORMAT_8BYTES; in rtl8365mb_detect()
2163 .name = "rtl8365mb-smi",
2173 .name = "rtl8365mb-mdio",
2206 MODULE_AUTHOR("Alvin Šipraga <alsi@bang-olufsen.dk>");
2207 MODULE_DESCRIPTION("Driver for RTL8365MB-VC ethernet switch");