drivers/net/usb/r8152.c
Source file repositories/reference/linux-study-clean/drivers/net/usb/r8152.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/usb/r8152.c- Extension
.c- Size
- 257920 bytes
- Lines
- 10521
- 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.
- 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/signal.hlinux/slab.hlinux/module.hlinux/netdevice.hlinux/etherdevice.hlinux/mii.hlinux/ethtool.hlinux/hex.hlinux/phy.hlinux/usb.hlinux/crc32.hlinux/if_vlan.hlinux/uaccess.hlinux/list.hlinux/ip.hlinux/ipv6.hnet/ip6_checksum.huapi/linux/mdio.hlinux/mdio.hlinux/usb/cdc.hlinux/suspend.hlinux/atomic.hlinux/acpi.hlinux/firmware.hcrypto/sha2.hlinux/usb/r8152.hnet/gso.h
Detected Declarations
struct tally_counterstruct rx_descstruct tx_descstruct rx_desc_v2struct tx_desc_v2struct r8152struct rx_aggstruct tx_aggstruct r8152struct rtl_opsstruct ups_infostruct desc_infostruct desc_opsstruct rtl_fwstruct fw_blockstruct fw_headerstruct fw_phy_setstruct fw_phy_speed_upstruct fw_phy_verstruct fw_phy_fixupstruct fw_phy_unionstruct fw_macstruct fw_phy_patch_keystruct fw_phy_ncenum spd_duplexenum rtl_register_contentenum rtl8152_flagsenum rtl8152_fw_flagsenum rtl8152_fw_fixup_cmdenum rtl_fw_typeenum rtl_versionenum tx_csum_statfunction rtl_set_inaccessiblefunction rtl_set_accessiblefunction r8152_control_msgfunction get_registersfunction set_registersfunction rtl_set_unplugfunction generic_ocp_readfunction generic_ocp_writefunction pla_ocp_readfunction pla_ocp_writefunction usb_ocp_writefunction ocp_read_dwordfunction ocp_write_dwordfunction ocp_read_wordfunction ocp_write_wordfunction ocp_read_byte
Annotated Snippet
static const struct net_device_ops rtl8152_netdev_ops = {
.ndo_open = rtl8152_open,
.ndo_stop = rtl8152_close,
.ndo_eth_ioctl = rtl8152_ioctl,
.ndo_start_xmit = rtl8152_start_xmit,
.ndo_tx_timeout = rtl8152_tx_timeout,
.ndo_set_features = rtl8152_set_features,
.ndo_set_rx_mode = rtl8152_set_rx_mode,
.ndo_set_mac_address = rtl8152_set_mac_address,
.ndo_change_mtu = rtl8152_change_mtu,
.ndo_validate_addr = eth_validate_addr,
.ndo_features_check = rtl8152_features_check,
};
static void rtl8152_unload(struct r8152 *tp)
{
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return;
if (tp->version != RTL_VER_01)
r8152_power_cut_en(tp, true);
}
static void rtl8153_unload(struct r8152 *tp)
{
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return;
r8153_power_cut_en(tp, false);
if (tp->version >= RTL_VER_16) {
/* Disable Interrupt Mitigation */
ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04, BIT(0) | BIT(1) | BIT(2) | BIT(7));
}
}
static void rtl8153b_unload(struct r8152 *tp)
{
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return;
r8153b_power_cut_en(tp, false);
}
static int r8152_desc_init(struct r8152 *tp)
{
tp->rx_desc.size = sizeof(struct rx_desc);
tp->rx_desc.align = 8;
tp->rx_desc.vlan_tag = r8152_rx_vlan_tag;
tp->desc_ops.rx_csum = r8152_rx_csum;
tp->desc_ops.rx_len = r8152_rx_len;
tp->tx_desc.size = sizeof(struct tx_desc);
tp->tx_desc.align = 4;
tp->tx_desc.vlan_tag = r8152_tx_vlan_tag;
tp->desc_ops.tx_csum = r8152_tx_csum;
tp->desc_ops.tx_len = r8152_tx_len;
return 0;
}
static int r8157_desc_init(struct r8152 *tp)
{
tp->rx_desc.size = sizeof(struct rx_desc_v2);
tp->rx_desc.align = 16;
tp->rx_desc.vlan_tag = r8157_rx_vlan_tag;
tp->desc_ops.rx_csum = r8157_rx_csum;
tp->desc_ops.rx_len = r8157_rx_len;
tp->tx_desc.size = sizeof(struct tx_desc_v2);
tp->tx_desc.align = 16;
tp->tx_desc.vlan_tag = r8152_tx_vlan_tag;
tp->desc_ops.tx_csum = r8157_tx_csum;
tp->desc_ops.tx_len = r8157_tx_len;
return 0;
}
static int rtl_ops_init(struct r8152 *tp)
{
struct rtl_ops *ops = &tp->rtl_ops;
int ret = 0;
switch (tp->version) {
case RTL_VER_01:
case RTL_VER_02:
case RTL_VER_07:
ops->init = r8152b_init;
ops->enable = rtl8152_enable;
ops->disable = rtl8152_disable;
ops->up = rtl8152_up;
ops->down = rtl8152_down;
Annotation
- Immediate include surface: `linux/signal.h`, `linux/slab.h`, `linux/module.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/mii.h`, `linux/ethtool.h`, `linux/hex.h`.
- Detected declarations: `struct tally_counter`, `struct rx_desc`, `struct tx_desc`, `struct rx_desc_v2`, `struct tx_desc_v2`, `struct r8152`, `struct rx_agg`, `struct tx_agg`, `struct r8152`, `struct rtl_ops`.
- 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.
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.