drivers/net/ethernet/realtek/r8169_main.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/realtek/r8169_main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/realtek/r8169_main.c- Extension
.c- Size
- 154898 bytes
- Lines
- 5836
- 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/module.hlinux/pci.hlinux/netdevice.hlinux/etherdevice.hlinux/clk.hlinux/delay.hlinux/ethtool.hlinux/phy.hlinux/if_vlan.hlinux/in.hlinux/io.hlinux/ip.hlinux/tcp.hlinux/interrupt.hlinux/dma-mapping.hlinux/pm_runtime.hlinux/bitfield.hlinux/prefetch.hlinux/ipv6.hlinux/unaligned.hnet/ip6_checksum.hnet/netdev_queues.hnet/phy/realtek_phy.hr8169.hr8169_firmware.h
Detected Declarations
struct TxDescstruct RxDescstruct ring_infostruct rtl8169_countersstruct rtl8169_tc_offsetsstruct rtl8169_privatestruct rtl_condstruct rtl_coalesce_infostruct ephy_infoenum rtl_registersenum rtl8168_8101_registersenum rtl8168_registersenum rtl8125_registersenum rtl_register_contentenum rtl_desc_bitenum rtl_tx_desc_bitenum rtl_tx_desc_bit_0enum rtl_tx_desc_bit_1enum rtl_rx_desc_bitenum rtl_flagenum rtl_dash_typefunction rtl_lock_config_regsfunction rtl_unlock_config_regsfunction rtl_pci_commitfunction rtl_mod_config2function rtl_mod_config5function r8169_mod_reg8_condfunction rtl_is_8125function rtl_is_8168evl_upfunction rtl_supports_eeefunction rtl_read_mac_from_regfunction rtl_loop_waitfunction rtl_loop_wait_highfunction rtl_loop_wait_lowfunction rtl8168_led_mod_ctrlfunction rtl8168_get_led_modefunction rtl8125_get_led_regfunction rtl8125_set_led_modefunction rtl8125_get_led_modefunction r8169_get_led_namefunction r8168fp_adjust_ocp_cmdfunction _rtl_eri_writefunction rtl_eri_writefunction _rtl_eri_readfunction rtl_eri_readfunction rtl_w0w1_erifunction rtl_eri_set_bitsfunction rtl_eri_clear_bits
Annotated Snippet
static const struct net_device_ops rtl_netdev_ops = {
.ndo_open = rtl_open,
.ndo_stop = rtl8169_close,
.ndo_get_stats64 = rtl8169_get_stats64,
.ndo_start_xmit = rtl8169_start_xmit,
.ndo_features_check = rtl8169_features_check,
.ndo_tx_timeout = rtl8169_tx_timeout,
.ndo_validate_addr = eth_validate_addr,
.ndo_change_mtu = rtl8169_change_mtu,
.ndo_fix_features = rtl8169_fix_features,
.ndo_set_features = rtl8169_set_features,
.ndo_set_mac_address = rtl_set_mac_address,
.ndo_eth_ioctl = phy_do_ioctl_running,
.ndo_set_rx_mode = rtl_set_rx_mode,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = rtl8169_netpoll,
#endif
};
static void rtl_set_irq_mask(struct rtl8169_private *tp)
{
tp->irq_mask = RxOK | RxErr | TxOK | TxErr | LinkChg;
if (tp->mac_version <= RTL_GIGA_MAC_VER_06)
tp->irq_mask |= SYSErr | RxFIFOOver;
}
static int rtl_alloc_irq(struct rtl8169_private *tp)
{
unsigned int flags;
switch (tp->mac_version) {
case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06:
rtl_unlock_config_regs(tp);
RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable);
rtl_lock_config_regs(tp);
fallthrough;
case RTL_GIGA_MAC_VER_07 ... RTL_GIGA_MAC_VER_17:
flags = PCI_IRQ_INTX;
break;
default:
flags = PCI_IRQ_ALL_TYPES;
break;
}
return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags);
}
static void rtl_read_mac_address(struct rtl8169_private *tp,
u8 mac_addr[ETH_ALEN])
{
/* Get MAC address */
if (rtl_is_8168evl_up(tp) && tp->mac_version != RTL_GIGA_MAC_VER_34) {
u32 value;
value = rtl_eri_read(tp, 0xe0);
put_unaligned_le32(value, mac_addr);
value = rtl_eri_read(tp, 0xe4);
put_unaligned_le16(value, mac_addr + 4);
} else if (rtl_is_8125(tp)) {
rtl_read_mac_from_reg(tp, mac_addr, MAC0_BKP);
}
}
DECLARE_RTL_COND(rtl_link_list_ready_cond)
{
return RTL_R8(tp, MCU) & LINK_LIST_RDY;
}
static void r8168g_wait_ll_share_fifo_ready(struct rtl8169_private *tp)
{
rtl_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42);
}
static int r8169_mdio_read_reg(struct mii_bus *mii_bus, int phyaddr, int phyreg)
{
struct rtl8169_private *tp = mii_bus->priv;
if (phyaddr > 0)
return -ENODEV;
return rtl_readphy(tp, phyreg);
}
static int r8169_mdio_write_reg(struct mii_bus *mii_bus, int phyaddr,
int phyreg, u16 val)
{
struct rtl8169_private *tp = mii_bus->priv;
Annotation
- Immediate include surface: `linux/module.h`, `linux/pci.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/clk.h`, `linux/delay.h`, `linux/ethtool.h`, `linux/phy.h`.
- Detected declarations: `struct TxDesc`, `struct RxDesc`, `struct ring_info`, `struct rtl8169_counters`, `struct rtl8169_tc_offsets`, `struct rtl8169_private`, `struct rtl_cond`, `struct rtl_coalesce_info`, `struct ephy_info`, `enum rtl_registers`.
- 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.