drivers/net/dsa/mt7530.c
Source file repositories/reference/linux-study-clean/drivers/net/dsa/mt7530.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/dsa/mt7530.c- Extension
.c- Size
- 99552 bytes
- Lines
- 3514
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/etherdevice.hlinux/if_bridge.hlinux/iopoll.hlinux/mdio.hlinux/mfd/syscon.hlinux/module.hlinux/netdevice.hlinux/of_irq.hlinux/of_mdio.hlinux/of_net.hlinux/of_platform.hlinux/phylink.hlinux/regmap.hlinux/regulator/consumer.hlinux/reset.hlinux/gpio/consumer.hlinux/gpio/driver.hnet/dsa.hnet/pkt_cls.hmt7530.h
Detected Declarations
function Copyrightfunction mt7530_mutex_lockfunction mt7530_mutex_unlockfunction core_writefunction core_rmwfunction core_setfunction core_clearfunction mt7530_mii_writefunction mt7530_mii_readfunction mt7530_writefunction _mt7530_unlocked_readfunction _mt7530_readfunction mt7530_readfunction mt7530_rmwfunction mt7530_setfunction mt7530_clearfunction mt7530_fdb_cmdfunction mt7530_fdb_readfunction mt7530_fdb_writefunction mt7530_pll_setupfunction mt753x_preferred_default_local_cpu_portfunction mt7530_setup_port6function mt7531_pll_setupfunction mt7530_mib_resetfunction mt7530_phy_read_c22function mt7530_phy_write_c22function mt7530_phy_read_c45function mt7530_phy_write_c45function mt7531_ind_c45_phy_readfunction mt7531_ind_c45_phy_writefunction mt7531_ind_c22_phy_readfunction mt7531_ind_c22_phy_writefunction mt753x_phy_read_c22function mt753x_phy_read_c45function mt753x_phy_write_c22function mt753x_phy_write_c45function mt7530_get_stringsfunction mt7530_read_port_statsfunction mt7530_get_ethtool_statsfunction mt7530_get_sset_countfunction mt7530_get_eth_mac_statsfunction mt7530_get_rmon_statsfunction mt7530_read_port_stats64function mt7530_stats_refreshfunction dsa_switch_for_each_user_portfunction mt7530_stats_pollfunction mt7530_get_stats64function mt7530_get_eth_ctrl_stats
Annotated Snippet
if (tmp_age_unit <= AGE_UNIT_MAX) {
unsigned int tmp_error = secs -
(tmp_age_count + 1) * (tmp_age_unit + 1);
/* found a closer pair */
if (error > tmp_error) {
error = tmp_error;
age_count = tmp_age_count;
age_unit = tmp_age_unit;
}
/* found the exact match, so break the loop */
if (!error)
break;
}
}
mt7530_write(priv, MT7530_AAC, AGE_CNT(age_count) | AGE_UNIT(age_unit));
return 0;
}
static const char *mt7530_p5_mode_str(unsigned int mode)
{
switch (mode) {
case MUX_PHY_P0:
return "MUX PHY P0";
case MUX_PHY_P4:
return "MUX PHY P4";
default:
return "GMAC5";
}
}
static void mt7530_setup_port5(struct dsa_switch *ds, phy_interface_t interface)
{
struct mt7530_priv *priv = ds->priv;
u8 tx_delay = 0;
int val;
mutex_lock(&priv->reg_mutex);
val = mt7530_read(priv, MT753X_MTRAP);
val &= ~MT7530_P5_PHY0_SEL & ~MT7530_P5_MAC_SEL & ~MT7530_P5_RGMII_MODE;
switch (priv->p5_mode) {
/* MUX_PHY_P0: P0 -> P5 -> SoC MAC */
case MUX_PHY_P0:
val |= MT7530_P5_PHY0_SEL;
fallthrough;
/* MUX_PHY_P4: P4 -> P5 -> SoC MAC */
case MUX_PHY_P4:
/* Setup the MAC by default for the cpu port */
mt7530_write(priv, MT753X_PMCR_P(5), 0x56300);
break;
/* GMAC5: P5 -> SoC MAC or external PHY */
default:
val |= MT7530_P5_MAC_SEL;
break;
}
/* Setup RGMII settings */
if (phy_interface_mode_is_rgmii(interface)) {
val |= MT7530_P5_RGMII_MODE;
/* P5 RGMII RX Clock Control: delay setting for 1000M */
mt7530_write(priv, MT7530_P5RGMIIRXCR, CSR_RGMII_EDGE_ALIGN);
/* Don't set delay in DSA mode */
if (!dsa_is_dsa_port(priv->ds, 5) &&
(interface == PHY_INTERFACE_MODE_RGMII_TXID ||
interface == PHY_INTERFACE_MODE_RGMII_ID))
tx_delay = 4; /* n * 0.5 ns */
/* P5 RGMII TX Clock Control: delay x */
mt7530_write(priv, MT7530_P5RGMIITXCR,
CSR_RGMII_TXC_CFG(0x10 + tx_delay));
/* reduce P5 RGMII Tx driving, 8mA */
mt7530_write(priv, MT7530_IO_DRV_CR,
P5_IO_CLK_DRV(1) | P5_IO_DATA_DRV(1));
}
mt7530_write(priv, MT753X_MTRAP, val);
dev_dbg(ds->dev, "Setup P5, HWTRAP=0x%x, mode=%s, phy-mode=%s\n", val,
mt7530_p5_mode_str(priv->p5_mode), phy_modes(interface));
Annotation
- Immediate include surface: `linux/etherdevice.h`, `linux/if_bridge.h`, `linux/iopoll.h`, `linux/mdio.h`, `linux/mfd/syscon.h`, `linux/module.h`, `linux/netdevice.h`, `linux/of_irq.h`.
- Detected declarations: `function Copyright`, `function mt7530_mutex_lock`, `function mt7530_mutex_unlock`, `function core_write`, `function core_rmw`, `function core_set`, `function core_clear`, `function mt7530_mii_write`, `function mt7530_mii_read`, `function mt7530_write`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.