drivers/net/ethernet/microchip/lan743x_main.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/microchip/lan743x_main.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/microchip/lan743x_main.c
Extension
.c
Size
114664 bytes
Lines
4037
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 lan743x_netdev_ops = {
	.ndo_open		= lan743x_netdev_open,
	.ndo_stop		= lan743x_netdev_close,
	.ndo_start_xmit		= lan743x_netdev_xmit_frame,
	.ndo_eth_ioctl		= lan743x_netdev_ioctl,
	.ndo_set_rx_mode	= lan743x_netdev_set_multicast,
	.ndo_change_mtu		= lan743x_netdev_change_mtu,
	.ndo_get_stats64	= lan743x_netdev_get_stats64,
	.ndo_set_mac_address	= lan743x_netdev_set_mac_address,
	.ndo_hwtstamp_get	= lan743x_ptp_hwtstamp_get,
	.ndo_hwtstamp_set	= lan743x_ptp_hwtstamp_set,
};

static void lan743x_hardware_cleanup(struct lan743x_adapter *adapter)
{
	lan743x_csr_write(adapter, INT_EN_CLR, 0xFFFFFFFF);
}

static void lan743x_mdiobus_cleanup(struct lan743x_adapter *adapter)
{
	mdiobus_unregister(adapter->mdiobus);
}

static void lan743x_destroy_phylink(struct lan743x_adapter *adapter)
{
	phylink_destroy(adapter->phylink);
	adapter->phylink = NULL;
}

static void lan743x_full_cleanup(struct lan743x_adapter *adapter)
{
	unregister_netdev(adapter->netdev);

	lan743x_destroy_phylink(adapter);
	lan743x_mdiobus_cleanup(adapter);
	lan743x_hardware_cleanup(adapter);
	lan743x_pci_cleanup(adapter);
}

static void pci11x1x_set_rfe_rd_fifo_threshold(struct lan743x_adapter *adapter)
{
	u16 rev = adapter->csr.id_rev & ID_REV_CHIP_REV_MASK_;

	if (rev == ID_REV_CHIP_REV_PCI11X1X_B0_) {
		u32 misc_ctl;

		misc_ctl = lan743x_csr_read(adapter, MISC_CTL_0);
		misc_ctl &= ~MISC_CTL_0_RFE_READ_FIFO_MASK_;
		misc_ctl |= FIELD_PREP(MISC_CTL_0_RFE_READ_FIFO_MASK_,
				       RFE_RD_FIFO_TH_3_DWORDS);
		lan743x_csr_write(adapter, MISC_CTL_0, misc_ctl);
	}
}

static int lan743x_hardware_init(struct lan743x_adapter *adapter,
				 struct pci_dev *pdev)
{
	struct lan743x_tx *tx;
	u32 sgmii_ctl;
	int index;
	int ret;

	adapter->is_pci11x1x = is_pci11x1x_chip(adapter);
	if (adapter->is_pci11x1x) {
		adapter->max_tx_channels = PCI11X1X_MAX_TX_CHANNELS;
		adapter->used_tx_channels = PCI11X1X_USED_TX_CHANNELS;
		adapter->max_vector_count = PCI11X1X_MAX_VECTOR_COUNT;
		pci11x1x_strap_get_status(adapter);
		spin_lock_init(&adapter->eth_syslock_spinlock);
		mutex_init(&adapter->sgmii_rw_lock);
		pci11x1x_set_rfe_rd_fifo_threshold(adapter);
		sgmii_ctl = lan743x_csr_read(adapter, SGMII_CTL);
		if (adapter->is_sgmii_en) {
			sgmii_ctl |= SGMII_CTL_SGMII_ENABLE_;
			sgmii_ctl &= ~SGMII_CTL_SGMII_POWER_DN_;
		} else {
			sgmii_ctl &= ~SGMII_CTL_SGMII_ENABLE_;
			sgmii_ctl |= SGMII_CTL_SGMII_POWER_DN_;
		}
		lan743x_csr_write(adapter, SGMII_CTL, sgmii_ctl);
	} else {
		adapter->max_tx_channels = LAN743X_MAX_TX_CHANNELS;
		adapter->used_tx_channels = LAN743X_USED_TX_CHANNELS;
		adapter->max_vector_count = LAN743X_MAX_VECTOR_COUNT;
	}

	adapter->intr.irq = adapter->pdev->irq;
	lan743x_csr_write(adapter, INT_EN_CLR, 0xFFFFFFFF);

	ret = lan743x_gpio_init(adapter);

Annotation

Implementation Notes