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.

Dependency Surface

Detected Declarations

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

Implementation Notes