drivers/net/mdio.c
Source file repositories/reference/linux-study-clean/drivers/net/mdio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/mdio.c- Extension
.c- Size
- 12232 bytes
- Lines
- 427
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/capability.hlinux/errno.hlinux/ethtool.hlinux/mdio.hlinux/module.h
Detected Declarations
function mdio45_probefunction mdio_set_flagfunction mdio45_links_okfunction mdio45_nway_restartfunction mdio45_get_anfunction mdio45_ethtool_ksettings_get_npagefunction mdio_mii_ioctlfunction mdio_phy_id_is_c45export mdio45_probeexport mdio_set_flagexport mdio45_links_okexport mdio45_nway_restartexport mdio45_ethtool_ksettings_get_npageexport mdio_mii_ioctl
Annotated Snippet
if (mmd_mask & (1 << devad)) {
mmd_mask &= ~(1 << devad);
/* Reset the latched status and fault flags */
mdio->mdio_read(mdio->dev, mdio->prtad,
devad, MDIO_STAT1);
if (devad == MDIO_MMD_PMAPMD || devad == MDIO_MMD_PCS ||
devad == MDIO_MMD_PHYXS || devad == MDIO_MMD_DTEXS)
mdio->mdio_read(mdio->dev, mdio->prtad,
devad, MDIO_STAT2);
/* Check the current status and fault flags */
reg = mdio->mdio_read(mdio->dev, mdio->prtad,
devad, MDIO_STAT1);
if (reg < 0 ||
(reg & (MDIO_STAT1_FAULT | MDIO_STAT1_LSTATUS)) !=
MDIO_STAT1_LSTATUS)
return false;
}
}
return true;
}
EXPORT_SYMBOL(mdio45_links_ok);
/**
* mdio45_nway_restart - restart auto-negotiation for this interface
* @mdio: MDIO interface
*
* Returns 0 on success, negative on error.
*/
int mdio45_nway_restart(const struct mdio_if_info *mdio)
{
if (!(mdio->mmds & MDIO_DEVS_AN))
return -EOPNOTSUPP;
mdio_set_flag(mdio, mdio->prtad, MDIO_MMD_AN, MDIO_CTRL1,
MDIO_AN_CTRL1_RESTART, true);
return 0;
}
EXPORT_SYMBOL(mdio45_nway_restart);
static u32 mdio45_get_an(const struct mdio_if_info *mdio, u16 addr)
{
u32 result = 0;
int reg;
reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_AN, addr);
if (reg & ADVERTISE_10HALF)
result |= ADVERTISED_10baseT_Half;
if (reg & ADVERTISE_10FULL)
result |= ADVERTISED_10baseT_Full;
if (reg & ADVERTISE_100HALF)
result |= ADVERTISED_100baseT_Half;
if (reg & ADVERTISE_100FULL)
result |= ADVERTISED_100baseT_Full;
if (reg & ADVERTISE_PAUSE_CAP)
result |= ADVERTISED_Pause;
if (reg & ADVERTISE_PAUSE_ASYM)
result |= ADVERTISED_Asym_Pause;
return result;
}
/**
* mdio45_ethtool_ksettings_get_npage - get settings for ETHTOOL_GLINKSETTINGS
* @mdio: MDIO interface
* @cmd: Ethtool request structure
* @npage_adv: Modes currently advertised on next pages
* @npage_lpa: Modes advertised by link partner on next pages
*
* The @cmd parameter is expected to have been cleared before calling
* mdio45_ethtool_ksettings_get_npage().
*
* Since the CSRs for auto-negotiation using next pages are not fully
* standardised, this function does not attempt to decode them. The
* caller must pass them in.
*/
void mdio45_ethtool_ksettings_get_npage(const struct mdio_if_info *mdio,
struct ethtool_link_ksettings *cmd,
u32 npage_adv, u32 npage_lpa)
{
int reg;
u32 speed, supported = 0, advertising = 0, lp_advertising = 0;
BUILD_BUG_ON(MDIO_SUPPORTS_C22 != ETH_MDIO_SUPPORTS_C22);
BUILD_BUG_ON(MDIO_SUPPORTS_C45 != ETH_MDIO_SUPPORTS_C45);
cmd->base.phy_address = mdio->prtad;
cmd->base.mdio_support =
mdio->mode_support & (MDIO_SUPPORTS_C45 | MDIO_SUPPORTS_C22);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/capability.h`, `linux/errno.h`, `linux/ethtool.h`, `linux/mdio.h`, `linux/module.h`.
- Detected declarations: `function mdio45_probe`, `function mdio_set_flag`, `function mdio45_links_ok`, `function mdio45_nway_restart`, `function mdio45_get_an`, `function mdio45_ethtool_ksettings_get_npage`, `function mdio_mii_ioctl`, `function mdio_phy_id_is_c45`, `export mdio45_probe`, `export mdio_set_flag`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
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.