Lines Matching +full:rx +full:- +full:pcs +full:- +full:m
1 // SPDX-License-Identifier: GPL-2.0-only
28 static struct mt753x_pcs *pcs_to_mt753x_pcs(struct phylink_pcs *pcs) in pcs_to_mt753x_pcs() argument
30 return container_of(pcs, struct mt753x_pcs, pcs); in pcs_to_mt753x_pcs()
81 if (priv->bus) in mt7530_mutex_lock()
82 mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); in mt7530_mutex_lock()
88 if (priv->bus) in mt7530_mutex_unlock()
89 mutex_unlock(&priv->bus->mdio_lock); in mt7530_mutex_unlock()
95 struct mii_bus *bus = priv->bus; in core_write()
101 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr), in core_write()
107 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr), in core_write()
113 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr), in core_write()
119 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr), in core_write()
123 dev_err(&bus->dev, "failed to write mmd register\n"); in core_write()
131 struct mii_bus *bus = priv->bus; in core_rmw()
138 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr), in core_rmw()
144 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr), in core_rmw()
150 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr), in core_rmw()
156 val = bus->read(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr), in core_rmw()
161 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr), in core_rmw()
165 dev_err(&bus->dev, "failed to write mmd register\n"); in core_rmw()
187 ret = regmap_write(priv->regmap, reg, val); in mt7530_mii_write()
190 dev_err(priv->dev, in mt7530_mii_write()
202 ret = regmap_read(priv->regmap, reg, &val); in mt7530_mii_read()
205 dev_err(priv->dev, in mt7530_mii_read()
226 return mt7530_mii_read(p->priv, p->reg); in _mt7530_unlocked_read()
234 mt7530_mutex_lock(p->priv); in _mt7530_read()
236 val = mt7530_mii_read(p->priv, p->reg); in _mt7530_read()
238 mt7530_mutex_unlock(p->priv); in _mt7530_read()
258 regmap_update_bits(priv->regmap, reg, mask, set); in mt7530_rmw()
290 dev_err(priv->dev, "reset timeout\n"); in mt7530_fdb_cmd()
299 return -EINVAL; in mt7530_fdb_cmd()
317 dev_dbg(priv->dev, "%s(%d) reg[%d]=0x%x\n", in mt7530_fdb_read()
321 fdb->vid = (reg[1] >> CVID) & CVID_MASK; in mt7530_fdb_read()
322 fdb->aging = (reg[2] >> AGE_TIMER) & AGE_TIMER_MASK; in mt7530_fdb_read()
323 fdb->port_mask = (reg[2] >> PORT_MAP) & PORT_MAP_MASK; in mt7530_fdb_read()
324 fdb->mac[0] = (reg[0] >> MAC_BYTE_0) & MAC_BYTE_MASK; in mt7530_fdb_read()
325 fdb->mac[1] = (reg[0] >> MAC_BYTE_1) & MAC_BYTE_MASK; in mt7530_fdb_read()
326 fdb->mac[2] = (reg[0] >> MAC_BYTE_2) & MAC_BYTE_MASK; in mt7530_fdb_read()
327 fdb->mac[3] = (reg[0] >> MAC_BYTE_3) & MAC_BYTE_MASK; in mt7530_fdb_read()
328 fdb->mac[4] = (reg[1] >> MAC_BYTE_4) & MAC_BYTE_MASK; in mt7530_fdb_read()
329 fdb->mac[5] = (reg[1] >> MAC_BYTE_5) & MAC_BYTE_MASK; in mt7530_fdb_read()
330 fdb->noarp = ((reg[2] >> ENT_STATUS) & ENT_STATUS_MASK) == STATIC_ENT; in mt7530_fdb_read()
407 struct mt7530_priv *priv = ds->priv; in mt7530_setup_port6()
428 if (priv->id == ID_MT7621) { in mt7530_setup_port6()
528 /* Enable 325M clock for SGMII */ in mt7531_pll_setup()
548 struct mt7530_priv *priv = ds->priv; in mt7530_mib_reset()
556 return mdiobus_read_nested(priv->bus, port, regnum); in mt7530_phy_read_c22()
562 return mdiobus_write_nested(priv->bus, port, regnum, val); in mt7530_phy_write_c22()
568 return mdiobus_c45_read_nested(priv->bus, port, devad, regnum); in mt7530_phy_read_c45()
574 return mdiobus_c45_write_nested(priv->bus, port, devad, regnum, val); in mt7530_phy_write_c45()
592 dev_err(priv->dev, "poll timeout\n"); in mt7531_ind_c45_phy_read()
603 dev_err(priv->dev, "poll timeout\n"); in mt7531_ind_c45_phy_read()
614 dev_err(priv->dev, "poll timeout\n"); in mt7531_ind_c45_phy_read()
640 dev_err(priv->dev, "poll timeout\n"); in mt7531_ind_c45_phy_write()
651 dev_err(priv->dev, "poll timeout\n"); in mt7531_ind_c45_phy_write()
662 dev_err(priv->dev, "poll timeout\n"); in mt7531_ind_c45_phy_write()
686 dev_err(priv->dev, "poll timeout\n"); in mt7531_ind_c22_phy_read()
698 dev_err(priv->dev, "poll timeout\n"); in mt7531_ind_c22_phy_read()
724 dev_err(priv->dev, "poll timeout\n"); in mt7531_ind_c22_phy_write()
736 dev_err(priv->dev, "poll timeout\n"); in mt7531_ind_c22_phy_write()
749 struct mt7530_priv *priv = bus->priv; in mt753x_phy_read_c22()
751 return priv->info->phy_read_c22(priv, port, regnum); in mt753x_phy_read_c22()
757 struct mt7530_priv *priv = bus->priv; in mt753x_phy_read_c45()
759 return priv->info->phy_read_c45(priv, port, devad, regnum); in mt753x_phy_read_c45()
765 struct mt7530_priv *priv = bus->priv; in mt753x_phy_write_c22()
767 return priv->info->phy_write_c22(priv, port, regnum, val); in mt753x_phy_write_c22()
774 struct mt7530_priv *priv = bus->priv; in mt753x_phy_write_c45()
776 return priv->info->phy_write_c45(priv, port, devad, regnum, val); in mt753x_phy_write_c45()
796 struct mt7530_priv *priv = ds->priv; in mt7530_get_ethtool_stats()
803 reg = MT7530_PORT_MIB_COUNTER(port) + mib->offset; in mt7530_get_ethtool_stats()
806 if (mib->size == 2) { in mt7530_get_ethtool_stats()
825 struct mt7530_priv *priv = ds->priv; in mt7530_set_ageing_time()
828 unsigned int error = -1; in mt7530_set_ageing_time()
834 return -ERANGE; in mt7530_set_ageing_time()
838 unsigned int tmp_age_unit = secs / (tmp_age_count + 1) - 1; in mt7530_set_ageing_time()
841 unsigned int tmp_error = secs - in mt7530_set_ageing_time()
876 struct mt7530_priv *priv = ds->priv; in mt7530_setup_port5()
880 mutex_lock(&priv->reg_mutex); in mt7530_setup_port5()
886 switch (priv->p5_mode) { in mt7530_setup_port5()
887 /* MUX_PHY_P0: P0 -> P5 -> SoC MAC */ in mt7530_setup_port5()
892 /* MUX_PHY_P4: P4 -> P5 -> SoC MAC */ in mt7530_setup_port5()
898 /* GMAC5: P5 -> SoC MAC or external PHY */ in mt7530_setup_port5()
908 /* P5 RGMII RX Clock Control: delay setting for 1000M */ in mt7530_setup_port5()
912 if (!dsa_is_dsa_port(priv->ds, 5) && in mt7530_setup_port5()
928 dev_dbg(ds->dev, "Setup P5, HWTRAP=0x%x, mode=%s, phy-mode=%s\n", val, in mt7530_setup_port5()
929 mt7530_p5_mode_str(priv->p5_mode), phy_modes(interface)); in mt7530_setup_port5()
931 mutex_unlock(&priv->reg_mutex); in mt7530_setup_port5()
934 /* In Clause 5 of IEEE Std 802-2014, two sublayers of the data link layer (DLL)
939 * In 8.2 of IEEE Std 802.1Q-2022, the Bridge architecture is described. A
950 * It is described in 8.13.9 of IEEE Std 802.1Q-2022 that in a Bridge, the LLC
967 * Link Layer Discovery Protocol (LLDP), link-local frames. They are not
970 * Process. In 8.6.3 of IEEE Std 802.1Q-2022, this is described in detail:
972 * Each of the reserved MAC addresses specified in Table 8-1
973 * (01-80-C2-00-00-[00,01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F]) shall be
974 * permanently configured in the FDB in C-VLAN components and ERs.
976 * Each of the reserved MAC addresses specified in Table 8-2
977 * (01-80-C2-00-00-[01,02,03,04,05,06,07,08,09,0A,0E]) shall be permanently
978 * configured in the FDB in S-VLAN components.
980 * Each of the reserved MAC addresses specified in Table 8-3
981 * (01-80-C2-00-00-[01,02,04,0E]) shall be permanently configured in the FDB in
988 * The addresses in Table 8-1, Table 8-2, and Table 8-3 determine the scope of
991 * The Nearest Bridge group address (01-80-C2-00-00-0E) is an address that no
992 * conformant Two-Port MAC Relay (TPMR) component, Service VLAN (S-VLAN)
993 * component, Customer VLAN (C-VLAN) component, or MAC Bridge can forward.
995 * that appear in Table 8-1, Table 8-2, and Table 8-3
996 * (01-80-C2-00-00-[00,01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F]), can
1000 * The Nearest non-TPMR Bridge group address (01-80-C2-00-00-03), is an
1001 * address that no conformant S-VLAN component, C-VLAN component, or MAC
1004 * appear in both Table 8-1 and Table 8-2 but not in Table 8-3
1005 * (01-80-C2-00-00-[00,03,05,06,07,08,09,0A,0B,0C,0D,0F]), will be relayed by
1006 * any TPMRs but will propagate no further than the nearest S-VLAN component,
1007 * C-VLAN component, or MAC Bridge.
1009 * The Nearest Customer Bridge group address (01-80-C2-00-00-00) is an address
1010 * that no conformant C-VLAN component, MAC Bridge can forward; however, it is
1011 * relayed by TPMR components and S-VLAN components. PDUs using this
1012 * destination address, or any of the other addresses that appear in Table 8-1
1013 * but not in either Table 8-2 or Table 8-3 (01-80-C2-00-00-[00,0B,0C,0D,0F]),
1014 * will be relayed by TPMR components and S-VLAN components but will propagate
1015 * no further than the nearest C-VLAN component or MAC Bridge.
1022 * For link-local frames, only CPU port should be designated as destination port
1027 * Therefore, on the switch with CPU port architecture, link-local frames must
1028 * be trapped to CPU port, and certain link-local frames received by a Port of a
1029 * Bridge comprising a TPMR component or an S-VLAN component must be excluded
1032 * A Bridge of the switch with CPU port architecture cannot comprise a Two-Port
1038 * Therefore, a Bridge of this architecture can only comprise S-VLAN components,
1039 * C-VLAN components, or MAC Bridge components. Since there's no TPMR component,
1041 * Nearest non-TPMR section, and the proportion of the Nearest Customer Bridge
1044 * One option to trap link-local frames to CPU port is to add static FDB entries
1048 * Bridge component or a C-VLAN component, there would have to be 16 times 4096
1051 * link-local frames from being discarded when the spanning tree Port State of
1058 * remaining 01-80-C2-00-00-[04,05,06,07,08,09,0A,0B,0C,0D,0F] destination
1059 * addresses. It also includes the 01-80-C2-00-00-22 to 01-80-C2-00-00-FF
1064 * link-local frames with specific destination addresses to CPU port by Bridge,
1067 * Therefore, regardless of the type of the Bridge component, link-local frames
1070 * 01-80-C2-00-00-[00,01,02,03,0E]
1072 * In a Bridge comprising a MAC Bridge component or a C-VLAN component:
1074 * Link-local frames with these destination addresses won't be trapped to CPU
1075 * port which won't conform to IEEE Std 802.1Q-2022:
1077 * 01-80-C2-00-00-[04,05,06,07,08,09,0A,0B,0C,0D,0F]
1079 * In a Bridge comprising an S-VLAN component:
1081 * Link-local frames with these destination addresses will be trapped to CPU
1082 * port which won't conform to IEEE Std 802.1Q-2022:
1084 * 01-80-C2-00-00-00
1086 * Link-local frames with these destination addresses won't be trapped to CPU
1087 * port which won't conform to IEEE Std 802.1Q-2022:
1089 * 01-80-C2-00-00-[04,05,06,07,08,09,0A]
1091 * To trap link-local frames to CPU port as conformant as this switch
1092 * intellectual property can allow, link-local frames are made to be regarded as
1098 * has no PVID assigned on software, VLAN-untagged frames won't be allowed in.
1100 * have link-local frames bypass this function of the Forwarding Process.
1106 * VLAN-untagged. in mt753x_trap_frames()
1117 * them VLAN-untagged. in mt753x_trap_frames()
1128 * them VLAN-untagged. in mt753x_trap_frames()
1142 struct mt7530_priv *priv = ds->priv; in mt753x_cpu_port_enable()
1156 if (priv->id == ID_MT7531 || priv->id == ID_MT7988 || in mt753x_cpu_port_enable()
1157 priv->id == ID_EN7581) in mt753x_cpu_port_enable()
1164 PCR_MATRIX(dsa_user_ports(priv->ds))); in mt753x_cpu_port_enable()
1176 struct mt7530_priv *priv = ds->priv; in mt7530_port_enable()
1178 mutex_lock(&priv->reg_mutex); in mt7530_port_enable()
1185 struct dsa_port *cpu_dp = dp->cpu_dp; in mt7530_port_enable()
1187 priv->ports[port].pm |= PCR_MATRIX(BIT(cpu_dp->index)); in mt7530_port_enable()
1189 priv->ports[port].enable = true; in mt7530_port_enable()
1191 priv->ports[port].pm); in mt7530_port_enable()
1193 mutex_unlock(&priv->reg_mutex); in mt7530_port_enable()
1195 if (priv->id != ID_MT7530 && priv->id != ID_MT7621) in mt7530_port_enable()
1209 struct mt7530_priv *priv = ds->priv; in mt7530_port_disable()
1211 mutex_lock(&priv->reg_mutex); in mt7530_port_disable()
1216 priv->ports[port].enable = false; in mt7530_port_disable()
1220 mutex_unlock(&priv->reg_mutex); in mt7530_port_disable()
1222 if (priv->id != ID_MT7530 && priv->id != ID_MT7621) in mt7530_port_disable()
1226 if (port == 5 && priv->p5_mode == GMAC5) in mt7530_port_disable()
1235 struct mt7530_priv *priv = ds->priv; in mt7530_port_change_mtu()
1241 * RX length register, only allowing CPU port here is enough. in mt7530_port_change_mtu()
1251 /* RX length also includes Ethernet header, MTK tag, and FCS length */ in mt7530_port_change_mtu()
1281 struct mt7530_priv *priv = ds->priv; in mt7530_stp_state_set()
1309 bool join) __must_hold(&priv->reg_mutex) in mt7530_update_port_member()
1311 struct dsa_port *dp = dsa_to_port(priv->ds, port), *other_dp; in mt7530_update_port_member()
1312 struct mt7530_port *p = &priv->ports[port], *other_p; in mt7530_update_port_member()
1313 struct dsa_port *cpu_dp = dp->cpu_dp; in mt7530_update_port_member()
1314 u32 port_bitmap = BIT(cpu_dp->index); in mt7530_update_port_member()
1318 dsa_switch_for_each_user_port(other_dp, priv->ds) { in mt7530_update_port_member()
1319 other_port = other_dp->index; in mt7530_update_port_member()
1320 other_p = &priv->ports[other_port]; in mt7530_update_port_member()
1333 isolated = p->isolated && other_p->isolated; in mt7530_update_port_member()
1336 other_p->pm |= PCR_MATRIX(BIT(port)); in mt7530_update_port_member()
1339 other_p->pm &= ~PCR_MATRIX(BIT(port)); in mt7530_update_port_member()
1342 if (other_p->enable) in mt7530_update_port_member()
1344 PCR_MATRIX_MASK, other_p->pm); in mt7530_update_port_member()
1351 p->pm = PCR_MATRIX(port_bitmap); in mt7530_update_port_member()
1352 if (priv->ports[port].enable) in mt7530_update_port_member()
1353 mt7530_rmw(priv, MT7530_PCR_P(port), PCR_MATRIX_MASK, p->pm); in mt7530_update_port_member()
1363 return -EINVAL; in mt7530_port_pre_bridge_flags()
1373 struct mt7530_priv *priv = ds->priv; in mt7530_port_bridge_flags()
1395 priv->ports[port].isolated = !!(flags.val & BR_ISOLATED); in mt7530_port_bridge_flags()
1397 mutex_lock(&priv->reg_mutex); in mt7530_port_bridge_flags()
1399 mutex_unlock(&priv->reg_mutex); in mt7530_port_bridge_flags()
1410 struct mt7530_priv *priv = ds->priv; in mt7530_port_bridge_join()
1412 mutex_lock(&priv->reg_mutex); in mt7530_port_bridge_join()
1420 mutex_unlock(&priv->reg_mutex); in mt7530_port_bridge_join()
1428 struct mt7530_priv *priv = ds->priv; in mt7530_port_set_vlan_unaware()
1432 /* This is called after .port_bridge_leave when leaving a VLAN-aware in mt7530_port_set_vlan_unaware()
1449 for (i = 0; i < priv->ds->num_ports; i++) { in mt7530_port_set_vlan_unaware()
1462 struct dsa_port *cpu_dp = dp->cpu_dp; in mt7530_port_set_vlan_unaware()
1464 mt7530_write(priv, MT7530_PCR_P(cpu_dp->index), in mt7530_port_set_vlan_unaware()
1465 PCR_MATRIX(dsa_user_ports(priv->ds))); in mt7530_port_set_vlan_unaware()
1466 mt7530_write(priv, MT7530_PVC_P(cpu_dp->index), PORT_SPEC_TAG in mt7530_port_set_vlan_unaware()
1474 struct mt7530_priv *priv = ds->priv; in mt7530_port_set_vlan_aware()
1483 G0_PORT_VID(priv->ports[port].pvid)); in mt7530_port_set_vlan_aware()
1486 if (!priv->ports[port].pvid) in mt7530_port_set_vlan_aware()
1515 struct mt7530_priv *priv = ds->priv; in mt7530_port_bridge_leave()
1517 mutex_lock(&priv->reg_mutex); in mt7530_port_bridge_leave()
1522 * back to the default as is at initial boot which is a VLAN-unaware in mt7530_port_bridge_leave()
1528 mutex_unlock(&priv->reg_mutex); in mt7530_port_bridge_leave()
1536 struct mt7530_priv *priv = ds->priv; in mt7530_port_fdb_add()
1540 mutex_lock(&priv->reg_mutex); in mt7530_port_fdb_add()
1541 mt7530_fdb_write(priv, vid, port_mask, addr, -1, STATIC_ENT); in mt7530_port_fdb_add()
1543 mutex_unlock(&priv->reg_mutex); in mt7530_port_fdb_add()
1553 struct mt7530_priv *priv = ds->priv; in mt7530_port_fdb_del()
1557 mutex_lock(&priv->reg_mutex); in mt7530_port_fdb_del()
1558 mt7530_fdb_write(priv, vid, port_mask, addr, -1, STATIC_EMP); in mt7530_port_fdb_del()
1560 mutex_unlock(&priv->reg_mutex); in mt7530_port_fdb_del()
1569 struct mt7530_priv *priv = ds->priv; in mt7530_port_fdb_dump()
1575 mutex_lock(&priv->reg_mutex); in mt7530_port_fdb_dump()
1591 } while (--cnt && in mt7530_port_fdb_dump()
1595 mutex_unlock(&priv->reg_mutex); in mt7530_port_fdb_dump()
1605 struct mt7530_priv *priv = ds->priv; in mt7530_port_mdb_add()
1606 const u8 *addr = mdb->addr; in mt7530_port_mdb_add()
1607 u16 vid = mdb->vid; in mt7530_port_mdb_add()
1611 mutex_lock(&priv->reg_mutex); in mt7530_port_mdb_add()
1619 mt7530_fdb_write(priv, vid, port_mask, addr, -1, STATIC_ENT); in mt7530_port_mdb_add()
1622 mutex_unlock(&priv->reg_mutex); in mt7530_port_mdb_add()
1632 struct mt7530_priv *priv = ds->priv; in mt7530_port_mdb_del()
1633 const u8 *addr = mdb->addr; in mt7530_port_mdb_del()
1634 u16 vid = mdb->vid; in mt7530_port_mdb_del()
1638 mutex_lock(&priv->reg_mutex); in mt7530_port_mdb_del()
1646 mt7530_fdb_write(priv, vid, port_mask, addr, -1, in mt7530_port_mdb_del()
1650 mutex_unlock(&priv->reg_mutex); in mt7530_port_mdb_del()
1669 dev_err(priv->dev, "poll timeout\n"); in mt7530_vlan_cmd()
1675 dev_err(priv->dev, "read VTCR invalid\n"); in mt7530_vlan_cmd()
1676 return -EINVAL; in mt7530_vlan_cmd()
1687 struct dsa_port *cpu_dp = dp->cpu_dp; in mt7530_port_vlan_filtering()
1690 /* The port is being kept as VLAN-unaware port when bridge is in mt7530_port_vlan_filtering()
1693 * for becoming a VLAN-aware port. in mt7530_port_vlan_filtering()
1696 mt7530_port_set_vlan_aware(ds, cpu_dp->index); in mt7530_port_vlan_filtering()
1708 struct dsa_port *dp = dsa_to_port(priv->ds, entry->port); in mt7530_hw_vlan_add()
1712 new_members = entry->old_members | BIT(entry->port); in mt7530_hw_vlan_add()
1730 else if (entry->untagged) in mt7530_hw_vlan_add()
1735 ETAG_CTRL_P_MASK(entry->port), in mt7530_hw_vlan_add()
1736 ETAG_CTRL_P(entry->port, val)); in mt7530_hw_vlan_add()
1746 new_members = entry->old_members & ~BIT(entry->port); in mt7530_hw_vlan_del()
1750 dev_err(priv->dev, in mt7530_hw_vlan_del()
1777 entry->old_members = (val >> PORT_MEM_SHFT) & PORT_MEM_MASK; in mt7530_hw_vlan_update()
1806 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; in mt7530_port_vlan_add()
1807 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; in mt7530_port_vlan_add()
1809 struct mt7530_priv *priv = ds->priv; in mt7530_port_vlan_add()
1811 mutex_lock(&priv->reg_mutex); in mt7530_port_vlan_add()
1814 mt7530_hw_vlan_update(priv, vlan->vid, &new_entry, mt7530_hw_vlan_add); in mt7530_port_vlan_add()
1817 priv->ports[port].pvid = vlan->vid; in mt7530_port_vlan_add()
1827 G0_PORT_VID(vlan->vid)); in mt7530_port_vlan_add()
1828 } else if (vlan->vid && priv->ports[port].pvid == vlan->vid) { in mt7530_port_vlan_add()
1830 priv->ports[port].pvid = G0_PORT_VID_DEF; in mt7530_port_vlan_add()
1832 /* Only accept tagged frames if the port is VLAN-aware */ in mt7530_port_vlan_add()
1841 mutex_unlock(&priv->reg_mutex); in mt7530_port_vlan_add()
1851 struct mt7530_priv *priv = ds->priv; in mt7530_port_vlan_del()
1853 mutex_lock(&priv->reg_mutex); in mt7530_port_vlan_del()
1856 mt7530_hw_vlan_update(priv, vlan->vid, &target_entry, in mt7530_port_vlan_del()
1862 if (priv->ports[port].pvid == vlan->vid) { in mt7530_port_vlan_del()
1863 priv->ports[port].pvid = G0_PORT_VID_DEF; in mt7530_port_vlan_del()
1865 /* Only accept tagged frames if the port is VLAN-aware */ in mt7530_port_vlan_del()
1875 mutex_unlock(&priv->reg_mutex); in mt7530_port_vlan_del()
1884 struct mt7530_priv *priv = ds->priv; in mt753x_port_mirror_add()
1889 if ((ingress ? priv->mirror_rx : priv->mirror_tx) & BIT(port)) in mt753x_port_mirror_add()
1890 return -EEXIST; in mt753x_port_mirror_add()
1892 val = mt7530_read(priv, MT753X_MIRROR_REG(priv->id)); in mt753x_port_mirror_add()
1895 monitor_port = MT753X_MIRROR_PORT_GET(priv->id, val); in mt753x_port_mirror_add()
1896 if (val & MT753X_MIRROR_EN(priv->id) && in mt753x_port_mirror_add()
1897 monitor_port != mirror->to_local_port) in mt753x_port_mirror_add()
1898 return -EEXIST; in mt753x_port_mirror_add()
1900 val |= MT753X_MIRROR_EN(priv->id); in mt753x_port_mirror_add()
1901 val &= ~MT753X_MIRROR_PORT_MASK(priv->id); in mt753x_port_mirror_add()
1902 val |= MT753X_MIRROR_PORT_SET(priv->id, mirror->to_local_port); in mt753x_port_mirror_add()
1903 mt7530_write(priv, MT753X_MIRROR_REG(priv->id), val); in mt753x_port_mirror_add()
1908 priv->mirror_rx |= BIT(port); in mt753x_port_mirror_add()
1911 priv->mirror_tx |= BIT(port); in mt753x_port_mirror_add()
1921 struct mt7530_priv *priv = ds->priv; in mt753x_port_mirror_del()
1925 if (mirror->ingress) { in mt753x_port_mirror_del()
1927 priv->mirror_rx &= ~BIT(port); in mt753x_port_mirror_del()
1930 priv->mirror_tx &= ~BIT(port); in mt753x_port_mirror_del()
1934 if (!priv->mirror_rx && !priv->mirror_tx) { in mt753x_port_mirror_del()
1935 val = mt7530_read(priv, MT753X_MIRROR_REG(priv->id)); in mt753x_port_mirror_del()
1936 val &= ~MT753X_MIRROR_EN(priv->id); in mt753x_port_mirror_del()
1937 mt7530_write(priv, MT753X_MIRROR_REG(priv->id), val); in mt753x_port_mirror_del()
2026 struct device *dev = priv->dev; in mt7530_setup_gpio()
2031 return -ENOMEM; in mt7530_setup_gpio()
2037 gc->label = "mt7530"; in mt7530_setup_gpio()
2038 gc->parent = dev; in mt7530_setup_gpio()
2039 gc->owner = THIS_MODULE; in mt7530_setup_gpio()
2040 gc->get_direction = mt7530_gpio_get_direction; in mt7530_setup_gpio()
2041 gc->direction_input = mt7530_gpio_direction_input; in mt7530_setup_gpio()
2042 gc->direction_output = mt7530_gpio_direction_output; in mt7530_setup_gpio()
2043 gc->get = mt7530_gpio_get; in mt7530_setup_gpio()
2044 gc->set = mt7530_gpio_set; in mt7530_setup_gpio()
2045 gc->base = -1; in mt7530_setup_gpio()
2046 gc->ngpio = 15; in mt7530_setup_gpio()
2047 gc->can_sleep = true; in mt7530_setup_gpio()
2070 irq = irq_find_mapping(priv->irq_domain, p); in mt7530_irq_thread_fn()
2084 priv->irq_enable &= ~BIT(d->hwirq); in mt7530_irq_mask()
2092 priv->irq_enable |= BIT(d->hwirq); in mt7530_irq_unmask()
2108 mt7530_mii_write(priv, MT7530_SYS_INT_EN, priv->irq_enable); in mt7530_irq_bus_sync_unlock()
2124 irq_set_chip_data(irq, domain->host_data); in mt7530_irq_map()
2142 priv->irq_enable &= ~BIT(d->hwirq); in mt7988_irq_mask()
2143 mt7530_mii_write(priv, MT7530_SYS_INT_EN, priv->irq_enable); in mt7988_irq_mask()
2151 priv->irq_enable |= BIT(d->hwirq); in mt7988_irq_unmask()
2152 mt7530_mii_write(priv, MT7530_SYS_INT_EN, priv->irq_enable); in mt7988_irq_unmask()
2165 irq_set_chip_data(irq, domain->host_data); in mt7988_irq_map()
2181 struct dsa_switch *ds = priv->ds; in mt7530_setup_mdio_irq()
2185 if (BIT(p) & ds->phys_mii_mask) { in mt7530_setup_mdio_irq()
2188 irq = irq_create_mapping(priv->irq_domain, p); in mt7530_setup_mdio_irq()
2189 ds->user_mii_bus->irq[p] = irq; in mt7530_setup_mdio_irq()
2197 struct device *dev = priv->dev; in mt7530_setup_irq()
2198 struct device_node *np = dev->of_node; in mt7530_setup_irq()
2201 if (!of_property_read_bool(np, "interrupt-controller")) { in mt7530_setup_irq()
2206 priv->irq = of_irq_get(np, 0); in mt7530_setup_irq()
2207 if (priv->irq <= 0) { in mt7530_setup_irq()
2208 dev_err(dev, "failed to get parent IRQ: %d\n", priv->irq); in mt7530_setup_irq()
2209 return priv->irq ? : -EINVAL; in mt7530_setup_irq()
2212 if (priv->id == ID_MT7988 || priv->id == ID_EN7581) in mt7530_setup_irq()
2213 priv->irq_domain = irq_domain_add_linear(np, MT7530_NUM_PHYS, in mt7530_setup_irq()
2217 priv->irq_domain = irq_domain_add_linear(np, MT7530_NUM_PHYS, in mt7530_setup_irq()
2221 if (!priv->irq_domain) { in mt7530_setup_irq()
2223 return -ENOMEM; in mt7530_setup_irq()
2227 if (priv->id == ID_MT7530 || priv->id == ID_MT7621) in mt7530_setup_irq()
2230 ret = request_threaded_irq(priv->irq, NULL, mt7530_irq_thread_fn, in mt7530_setup_irq()
2233 irq_domain_remove(priv->irq_domain); in mt7530_setup_irq()
2247 if (BIT(p) & priv->ds->phys_mii_mask) { in mt7530_free_mdio_irq()
2250 irq = irq_find_mapping(priv->irq_domain, p); in mt7530_free_mdio_irq()
2259 free_irq(priv->irq, priv); in mt7530_free_irq_common()
2260 irq_domain_remove(priv->irq_domain); in mt7530_free_irq_common()
2266 struct device_node *mnp, *np = priv->dev->of_node; in mt7530_free_irq()
2279 struct device_node *mnp, *np = priv->dev->of_node; in mt7530_setup_mdio()
2280 struct dsa_switch *ds = priv->ds; in mt7530_setup_mdio()
2281 struct device *dev = priv->dev; in mt7530_setup_mdio()
2293 ret = -ENOMEM; in mt7530_setup_mdio()
2298 ds->user_mii_bus = bus; in mt7530_setup_mdio()
2300 bus->priv = priv; in mt7530_setup_mdio()
2301 bus->name = KBUILD_MODNAME "-mii"; in mt7530_setup_mdio()
2302 snprintf(bus->id, MII_BUS_ID_SIZE, KBUILD_MODNAME "-%d", idx++); in mt7530_setup_mdio()
2303 bus->read = mt753x_phy_read_c22; in mt7530_setup_mdio()
2304 bus->write = mt753x_phy_write_c22; in mt7530_setup_mdio()
2305 bus->read_c45 = mt753x_phy_read_c45; in mt7530_setup_mdio()
2306 bus->write_c45 = mt753x_phy_write_c45; in mt7530_setup_mdio()
2307 bus->parent = dev; in mt7530_setup_mdio()
2308 bus->phy_mask = ~ds->phys_mii_mask; in mt7530_setup_mdio()
2310 if (priv->irq && !mnp) in mt7530_setup_mdio()
2316 if (priv->irq && !mnp) in mt7530_setup_mdio()
2328 struct mt7530_priv *priv = ds->priv; in mt7530_setup()
2343 dn = cpu_dp->conduit->dev.of_node->parent; in mt7530_setup()
2351 dev_err(ds->dev, "parent OF node of DSA conduit not found"); in mt7530_setup()
2352 return -EINVAL; in mt7530_setup()
2355 ds->assisted_learning_on_cpu_port = true; in mt7530_setup()
2356 ds->mtu_enforcement_ingress = true; in mt7530_setup()
2358 if (priv->id == ID_MT7530) { in mt7530_setup()
2359 regulator_set_voltage(priv->core_pwr, 1000000, 1000000); in mt7530_setup()
2360 ret = regulator_enable(priv->core_pwr); in mt7530_setup()
2362 dev_err(priv->dev, in mt7530_setup()
2367 regulator_set_voltage(priv->io_pwr, 3300000, 3300000); in mt7530_setup()
2368 ret = regulator_enable(priv->io_pwr); in mt7530_setup()
2370 dev_err(priv->dev, "Failed to enable io pwr: %d\n", in mt7530_setup()
2376 /* Reset whole chip through gpio pin or memory-mapped registers for in mt7530_setup()
2379 if (priv->mcm) { in mt7530_setup()
2380 reset_control_assert(priv->rstc); in mt7530_setup()
2382 reset_control_deassert(priv->rstc); in mt7530_setup()
2384 gpiod_set_value_cansleep(priv->reset, 0); in mt7530_setup()
2386 gpiod_set_value_cansleep(priv->reset, 1); in mt7530_setup()
2394 dev_err(priv->dev, "reset timeout\n"); in mt7530_setup()
2401 dev_err(priv->dev, "chip %x can't be supported\n", id); in mt7530_setup()
2402 return -ENODEV; in mt7530_setup()
2406 dev_err(priv->dev, in mt7530_setup()
2408 return -EINVAL; in mt7530_setup()
2439 for (i = 0; i < priv->ds->num_ports; i++) { in mt7530_setup()
2445 MT753X_FORCE_MODE(priv->id), in mt7530_setup()
2446 MT753X_FORCE_MODE(priv->id)); in mt7530_setup()
2472 /* Setup VLAN ID 0 for VLAN-unaware bridges */ in mt7530_setup()
2480 * Set priv->p5_mode to the appropriate value if PHY muxing is in mt7530_setup()
2485 "mediatek,eth-mac")) in mt7530_setup()
2492 phy_node = of_parse_phandle(mac_np, "phy-handle", 0); in mt7530_setup()
2496 if (phy_node->parent == priv->dev->of_node->parent || in mt7530_setup()
2497 phy_node->parent->parent == priv->dev->of_node) { in mt7530_setup()
2499 if (ret && ret != -ENODEV) { in mt7530_setup()
2504 id = of_mdio_parse_addr(ds->dev, phy_node); in mt7530_setup()
2506 priv->p5_mode = MUX_PHY_P0; in mt7530_setup()
2508 priv->p5_mode = MUX_PHY_P4; in mt7530_setup()
2515 if (priv->p5_mode == MUX_PHY_P0 || in mt7530_setup()
2516 priv->p5_mode == MUX_PHY_P4) { in mt7530_setup()
2523 if (of_property_read_bool(priv->dev->of_node, "gpio-controller")) { in mt7530_setup()
2541 struct mt7530_priv *priv = ds->priv; in mt7531_setup_common()
2553 for (i = 0; i < priv->ds->num_ports; i++) { in mt7531_setup_common()
2559 MT753X_FORCE_MODE(priv->id), in mt7531_setup_common()
2560 MT753X_FORCE_MODE(priv->id)); in mt7531_setup_common()
2594 /* Setup VLAN ID 0 for VLAN-unaware bridges */ in mt7531_setup_common()
2601 struct mt7530_priv *priv = ds->priv; in mt7531_setup()
2606 /* Reset whole chip through gpio pin or memory-mapped registers for in mt7531_setup()
2609 if (priv->mcm) { in mt7531_setup()
2610 reset_control_assert(priv->rstc); in mt7531_setup()
2612 reset_control_deassert(priv->rstc); in mt7531_setup()
2614 gpiod_set_value_cansleep(priv->reset, 0); in mt7531_setup()
2616 gpiod_set_value_cansleep(priv->reset, 1); in mt7531_setup()
2624 dev_err(priv->dev, "reset timeout\n"); in mt7531_setup()
2632 dev_err(priv->dev, "chip %x can't be supported\n", id); in mt7531_setup()
2633 return -ENODEV; in mt7531_setup()
2640 priv->p5_sgmii = !!(val & PAD_DUAL_SGMII_EN); in mt7531_setup()
2643 for (i = 0; i < priv->ds->num_ports; i++) in mt7531_setup()
2649 if (!priv->p5_sgmii) { in mt7531_setup()
2652 /* Unlike MT7531BE, the GPIO 6-12 pins are not used for RGMII on in mt7531_setup()
2653 * MT7531AE. Set the GPIO 11-12 pins to function as MDC and MDIO in mt7531_setup()
2665 /* Enable Energy-Efficient Ethernet (EEE) and PHY core PLL, since in mt7531_setup()
2671 MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr), in mt7531_setup()
2676 MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr), in mt7531_setup()
2680 for (i = MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr); in mt7531_setup()
2681 i < MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr) + MT7530_NUM_PHYS; in mt7531_setup()
2691 ds->assisted_learning_on_cpu_port = true; in mt7531_setup()
2692 ds->mtu_enforcement_ingress = true; in mt7531_setup()
2700 config->mac_capabilities |= MAC_10 | MAC_100 | MAC_1000FD; in mt7530_mac_port_get_caps()
2706 config->supported_interfaces); in mt7530_mac_port_get_caps()
2711 phy_interface_set_rgmii(config->supported_interfaces); in mt7530_mac_port_get_caps()
2713 config->supported_interfaces); in mt7530_mac_port_get_caps()
2715 config->supported_interfaces); in mt7530_mac_port_get_caps()
2721 config->supported_interfaces); in mt7530_mac_port_get_caps()
2723 config->supported_interfaces); in mt7530_mac_port_get_caps()
2731 struct mt7530_priv *priv = ds->priv; in mt7531_mac_port_get_caps()
2733 config->mac_capabilities |= MAC_10 | MAC_100 | MAC_1000FD; in mt7531_mac_port_get_caps()
2739 config->supported_interfaces); in mt7531_mac_port_get_caps()
2746 if (!priv->p5_sgmii) { in mt7531_mac_port_get_caps()
2747 phy_interface_set_rgmii(config->supported_interfaces); in mt7531_mac_port_get_caps()
2755 config->supported_interfaces); in mt7531_mac_port_get_caps()
2757 config->supported_interfaces); in mt7531_mac_port_get_caps()
2759 config->supported_interfaces); in mt7531_mac_port_get_caps()
2761 config->mac_capabilities |= MAC_2500FD; in mt7531_mac_port_get_caps()
2773 config->supported_interfaces); in mt7988_mac_port_get_caps()
2775 config->mac_capabilities |= MAC_10 | MAC_100 | MAC_1000FD; in mt7988_mac_port_get_caps()
2781 config->supported_interfaces); in mt7988_mac_port_get_caps()
2783 config->mac_capabilities |= MAC_10000FD; in mt7988_mac_port_get_caps()
2795 config->supported_interfaces); in en7581_mac_port_get_caps()
2797 config->mac_capabilities |= MAC_10 | MAC_100 | MAC_1000FD; in en7581_mac_port_get_caps()
2803 config->supported_interfaces); in en7581_mac_port_get_caps()
2805 config->mac_capabilities |= MAC_10000FD; in en7581_mac_port_get_caps()
2814 struct mt7530_priv *priv = ds->priv; in mt7530_mac_config()
2817 mt7530_setup_port5(priv->ds, interface); in mt7530_mac_config()
2819 mt7530_setup_port6(priv->ds, interface); in mt7530_mac_config()
2866 struct mt7530_priv *priv = ds->priv; in mt7531_mac_config()
2872 phydev = dp->user->phydev; in mt7531_mac_config()
2882 struct mt7530_priv *priv = dp->ds->priv; in mt753x_phylink_mac_select_pcs()
2886 return &priv->pcs[dp->index].pcs; in mt753x_phylink_mac_select_pcs()
2890 return priv->ports[dp->index].sgmii_pcs; in mt753x_phylink_mac_select_pcs()
2901 struct dsa_switch *ds = dp->ds; in mt753x_phylink_mac_config()
2903 int port = dp->index; in mt753x_phylink_mac_config()
2905 priv = ds->priv; in mt753x_phylink_mac_config()
2907 if ((port == 5 || port == 6) && priv->info->mac_port_config) in mt753x_phylink_mac_config()
2908 priv->info->mac_port_config(ds, port, mode, state->interface); in mt753x_phylink_mac_config()
2920 struct mt7530_priv *priv = dp->ds->priv; in mt753x_phylink_mac_link_down()
2922 mt7530_clear(priv, MT753X_PMCR_P(dp->index), PMCR_LINK_SETTINGS_MASK); in mt753x_phylink_mac_link_down()
2933 struct mt7530_priv *priv = dp->ds->priv; in mt753x_phylink_mac_link_up()
2968 mt7530_set(priv, MT753X_PMCR_P(dp->index), mcr); in mt753x_phylink_mac_link_up()
2974 struct mt7530_priv *priv = ds->priv; in mt753x_phylink_get_caps()
2976 config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE; in mt753x_phylink_get_caps()
2978 priv->info->mac_port_get_caps(ds, port, config); in mt753x_phylink_get_caps()
2981 static int mt753x_pcs_validate(struct phylink_pcs *pcs, in mt753x_pcs_validate() argument
2986 if (state->interface == PHY_INTERFACE_MODE_TRGMII || in mt753x_pcs_validate()
2987 phy_interface_mode_is_8023z(state->interface)) in mt753x_pcs_validate()
2993 static void mt7530_pcs_get_state(struct phylink_pcs *pcs, unsigned int neg_mode, in mt7530_pcs_get_state() argument
2996 struct mt7530_priv *priv = pcs_to_mt753x_pcs(pcs)->priv; in mt7530_pcs_get_state()
2997 int port = pcs_to_mt753x_pcs(pcs)->port; in mt7530_pcs_get_state()
3002 state->link = (pmsr & PMSR_LINK); in mt7530_pcs_get_state()
3003 state->an_complete = state->link; in mt7530_pcs_get_state()
3004 state->duplex = !!(pmsr & PMSR_DPX); in mt7530_pcs_get_state()
3008 state->speed = SPEED_10; in mt7530_pcs_get_state()
3011 state->speed = SPEED_100; in mt7530_pcs_get_state()
3014 state->speed = SPEED_1000; in mt7530_pcs_get_state()
3017 state->speed = SPEED_UNKNOWN; in mt7530_pcs_get_state()
3021 state->pause &= ~(MLO_PAUSE_RX | MLO_PAUSE_TX); in mt7530_pcs_get_state()
3023 state->pause |= MLO_PAUSE_RX; in mt7530_pcs_get_state()
3025 state->pause |= MLO_PAUSE_TX; in mt7530_pcs_get_state()
3028 static int mt753x_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, in mt753x_pcs_config() argument
3036 static void mt7530_pcs_an_restart(struct phylink_pcs *pcs) in mt7530_pcs_an_restart() argument
3050 struct mt7530_priv *priv = ds->priv; in mt753x_setup()
3051 int ret = priv->info->sw_setup(ds); in mt753x_setup()
3062 if (ret && priv->irq) in mt753x_setup()
3067 /* Initialise the PCS devices */ in mt753x_setup()
3068 for (i = 0; i < priv->ds->num_ports; i++) { in mt753x_setup()
3069 priv->pcs[i].pcs.ops = priv->info->pcs_ops; in mt753x_setup()
3070 priv->pcs[i].pcs.neg_mode = true; in mt753x_setup()
3071 priv->pcs[i].priv = priv; in mt753x_setup()
3072 priv->pcs[i].port = i; in mt753x_setup()
3075 if (priv->create_sgmii) { in mt753x_setup()
3076 ret = priv->create_sgmii(priv); in mt753x_setup()
3077 if (ret && priv->irq) in mt753x_setup()
3087 struct mt7530_priv *priv = ds->priv; in mt753x_set_mac_eee()
3090 if (e->tx_lpi_timer > 0xFFF) in mt753x_set_mac_eee()
3091 return -EINVAL; in mt753x_set_mac_eee()
3093 set = LPI_THRESH_SET(e->tx_lpi_timer); in mt753x_set_mac_eee()
3094 if (!e->tx_lpi_enabled) in mt753x_set_mac_eee()
3107 struct dsa_port *cpu_dp = conduit->dsa_ptr; in mt753x_conduit_state_change()
3108 struct mt7530_priv *priv = ds->priv; in mt753x_conduit_state_change()
3116 if (priv->id != ID_MT7530 && priv->id != ID_MT7621) in mt753x_conduit_state_change()
3119 mask = BIT(cpu_dp->index); in mt753x_conduit_state_change()
3122 priv->active_cpu_ports |= mask; in mt753x_conduit_state_change()
3124 priv->active_cpu_ports &= ~mask; in mt753x_conduit_state_change()
3126 if (priv->active_cpu_ports) { in mt753x_conduit_state_change()
3128 MT7530_CPU_PORT(__ffs(priv->active_cpu_ports)); in mt753x_conduit_state_change()
3137 struct tc_tbf_qopt_offload_replace_params *p = &qopt->replace_params; in mt753x_tc_setup_qdisc_tbf()
3138 struct mt7530_priv *priv = ds->priv; in mt753x_tc_setup_qdisc_tbf()
3141 switch (qopt->command) { in mt753x_tc_setup_qdisc_tbf()
3143 rate = div_u64(p->rate.rate_bytes_ps, 1000) << 3; /* kbps */ in mt753x_tc_setup_qdisc_tbf()
3164 return -EOPNOTSUPP; in mt753x_tc_setup_qdisc_tbf()
3177 return -EOPNOTSUPP; in mt753x_setup_tc()
3183 struct mt7530_priv *priv = ds->priv; in mt7988_setup()
3186 reset_control_assert(priv->rstc); in mt7988_setup()
3188 reset_control_deassert(priv->rstc); in mt7988_setup()
3299 struct device *dev = priv->dev; in mt7530_probe_common()
3301 priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL); in mt7530_probe_common()
3302 if (!priv->ds) in mt7530_probe_common()
3303 return -ENOMEM; in mt7530_probe_common()
3305 priv->ds->dev = dev; in mt7530_probe_common()
3306 priv->ds->num_ports = MT7530_NUM_PORTS; in mt7530_probe_common()
3311 priv->info = of_device_get_match_data(dev); in mt7530_probe_common()
3312 if (!priv->info) in mt7530_probe_common()
3313 return -EINVAL; in mt7530_probe_common()
3315 priv->id = priv->info->id; in mt7530_probe_common()
3316 priv->dev = dev; in mt7530_probe_common()
3317 priv->ds->priv = priv; in mt7530_probe_common()
3318 priv->ds->ops = &mt7530_switch_ops; in mt7530_probe_common()
3319 priv->ds->phylink_mac_ops = &mt753x_phylink_mac_ops; in mt7530_probe_common()
3320 mutex_init(&priv->reg_mutex); in mt7530_probe_common()
3330 if (priv->irq) in mt7530_remove_common()
3333 dsa_unregister_switch(priv->ds); in mt7530_remove_common()
3335 mutex_destroy(&priv->reg_mutex); in mt7530_remove_common()