drivers/net/phy/phylink.c
Source file repositories/reference/linux-study-clean/drivers/net/phy/phylink.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/phy/phylink.c- Extension
.c- Size
- 126861 bytes
- Lines
- 4434
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/acpi.hlinux/ethtool.hlinux/export.hlinux/gpio/consumer.hlinux/netdevice.hlinux/of.hlinux/of_mdio.hlinux/phy.hlinux/phy_fixed.hlinux/phylink.hlinux/rtnetlink.hlinux/spinlock.hlinux/timer.hlinux/workqueue.hphy-caps.hsfp.hswphy.h
Detected Declarations
struct phylinkenum inband_typefunction phylink_set_port_modesfunction phylink_is_empty_linkmodefunction phylink_interface_signal_ratefunction phylink_interface_max_speedfunction phylink_caps_to_link_capsfunction phylink_link_caps_to_mac_capsfunction phylink_caps_to_linkmodesfunction phylink_limit_mac_speedfunction phylink_cap_from_speed_duplexfunction phylink_get_capabilitiesfunction phylink_validate_mask_capsfunction phylink_validate_mac_and_pcsfunction phylink_validate_onefunction phylink_validate_maskfunction phylink_validatefunction phylink_fill_fixedlink_supportedfunction phylink_parse_fixedlinkfunction phylink_parse_modefunction phylink_apply_manual_flowfunction phylink_resolve_an_pausefunction phylink_pcs_inband_capsfunction phylink_pcs_pre_configfunction phylink_pcs_post_configfunction phylink_pcs_disablefunction phylink_pcs_enablefunction phylink_pcs_configfunction phylink_pcs_link_upfunction phylink_pcs_disable_eeefunction phylink_pcs_enable_eeefunction phylink_inband_capsfunction phylink_pcs_poll_stopfunction phylink_pcs_poll_startfunction phylink_pcs_pre_initfunction phylink_mac_configfunction phylink_pcs_an_restartfunction phylink_get_inband_typefunction phylink_pcs_neg_modefunction phylink_major_configfunction phylink_change_inband_advertfunction phylink_mac_pcs_get_statefunction phylink_get_fixed_statefunction phylink_mac_initial_configfunction phylink_deactivate_lpifunction phylink_activate_lpifunction phylink_link_upfunction phylink_link_down
Annotated Snippet
* network device driver's &struct net_device_ops ndo_open() method.
*/
void phylink_start(struct phylink *pl)
{
bool poll = false;
ASSERT_RTNL();
phylink_info(pl, "configuring for %s/%s link mode\n",
phylink_an_mode_str(pl->req_link_an_mode),
phy_modes(pl->link_config.interface));
/* Always set the carrier off */
if (pl->netdev)
netif_carrier_off(pl->netdev);
pl->pcs_state = PCS_STATE_STARTING;
/* Apply the link configuration to the MAC when starting. This allows
* a fixed-link to start with the correct parameters, and also
* ensures that we set the appropriate advertisement for Serdes links.
*
* Restart autonegotiation if using 802.3z to ensure that the link
* parameters are properly negotiated. This is necessary for DSA
* switches using 802.3z negotiation to ensure they see our modes.
*/
phylink_mac_initial_config(pl, true);
pl->pcs_state = PCS_STATE_STARTED;
phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_STOPPED);
if (pl->cfg_link_an_mode == MLO_AN_FIXED && pl->link_gpio) {
int irq = gpiod_to_irq(pl->link_gpio);
if (irq > 0) {
if (!request_irq(irq, phylink_link_handler,
IRQF_TRIGGER_RISING |
IRQF_TRIGGER_FALLING,
"netdev link", pl))
pl->link_irq = irq;
else
irq = 0;
}
if (irq <= 0)
poll = true;
}
if (pl->cfg_link_an_mode == MLO_AN_FIXED)
poll |= pl->config->poll_fixed_state;
if (poll)
mod_timer(&pl->link_poll, jiffies + HZ);
if (pl->phydev)
phy_start(pl->phydev);
if (pl->sfp_bus)
sfp_upstream_start(pl->sfp_bus);
}
EXPORT_SYMBOL_GPL(phylink_start);
/**
* phylink_stop() - stop a phylink instance
* @pl: a pointer to a &struct phylink returned from phylink_create()
*
* Stop the phylink instance specified by @pl. This should be called from the
* network device driver's &struct net_device_ops ndo_stop() method. The
* network device's carrier state should not be changed prior to calling this
* function.
*
* This will synchronously bring down the link if the link is not already
* down (in other words, it will trigger a mac_link_down() method call.)
*/
void phylink_stop(struct phylink *pl)
{
ASSERT_RTNL();
if (pl->sfp_bus)
sfp_upstream_stop(pl->sfp_bus);
if (pl->phydev)
phy_stop(pl->phydev);
timer_delete_sync(&pl->link_poll);
if (pl->link_irq) {
free_irq(pl->link_irq, pl);
pl->link_irq = 0;
}
phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_STOPPED);
pl->pcs_state = PCS_STATE_DOWN;
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/ethtool.h`, `linux/export.h`, `linux/gpio/consumer.h`, `linux/netdevice.h`, `linux/of.h`, `linux/of_mdio.h`, `linux/phy.h`.
- Detected declarations: `struct phylink`, `enum inband_type`, `function phylink_set_port_modes`, `function phylink_is_empty_linkmode`, `function phylink_interface_signal_rate`, `function phylink_interface_max_speed`, `function phylink_caps_to_link_caps`, `function phylink_link_caps_to_mac_caps`, `function phylink_caps_to_linkmodes`, `function phylink_limit_mac_speed`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.