drivers/net/ethernet/microchip/enc28j60.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/microchip/enc28j60.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/microchip/enc28j60.c- Extension
.c- Size
- 45062 bytes
- Lines
- 1630
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/kernel.hlinux/types.hlinux/fcntl.hlinux/interrupt.hlinux/property.hlinux/string.hlinux/errno.hlinux/netdevice.hlinux/etherdevice.hlinux/ethtool.hlinux/tcp.hlinux/skbuff.hlinux/delay.hlinux/spi/spi.henc28j60_hw.h
Detected Declarations
struct enc28j60_netfunction spi_read_buffunction spi_write_buffunction spi_read_opfunction spi_write_opfunction enc28j60_soft_resetfunction enc28j60_set_bankfunction nolock_reg_bfsetfunction locked_reg_bfsetfunction nolock_reg_bfclrfunction locked_reg_bfclrfunction nolock_regb_readfunction locked_regb_readfunction nolock_regw_readfunction locked_regw_readfunction nolock_regb_writefunction locked_regb_writefunction nolock_regw_writefunction locked_regw_writefunction enc28j60_mem_readfunction enc28j60_packet_writefunction poll_readyfunction wait_phy_readyfunction enc28j60_phy_readfunction enc28j60_phy_writefunction enc28j60_set_hw_macaddrfunction enc28j60_set_mac_addressfunction enc28j60_dump_regsfunction erxrdpt_workaroundfunction rx_packet_startfunction nolock_rxfifo_initfunction nolock_txfifo_initfunction enc28j60_lowpowerfunction enc28j60_hw_initfunction enc28j60_hw_enablefunction enc28j60_hw_disablefunction enc28j60_setlinkfunction enc28j60_read_tsvfunction enc28j60_dump_tsvfunction enc28j60_dump_rsvfunction dump_packetfunction enc28j60_hw_rxfunction enc28j60_get_free_rxfifofunction enc28j60_check_link_statusfunction enc28j60_tx_clearfunction enc28j60_hw_rxfunction enc28j60_irqfunction enc28j60_hw_tx
Annotated Snippet
static const struct net_device_ops enc28j60_netdev_ops = {
.ndo_open = enc28j60_net_open,
.ndo_stop = enc28j60_net_close,
.ndo_start_xmit = enc28j60_send_packet,
.ndo_set_rx_mode = enc28j60_set_multicast_list,
.ndo_set_mac_address = enc28j60_set_mac_address,
.ndo_tx_timeout = enc28j60_tx_timeout,
.ndo_validate_addr = eth_validate_addr,
};
static int enc28j60_probe(struct spi_device *spi)
{
struct net_device *dev;
struct enc28j60_net *priv;
int ret = 0;
if (netif_msg_drv(&debug))
dev_info(&spi->dev, "Ethernet driver %s loaded\n", DRV_VERSION);
dev = alloc_etherdev(sizeof(struct enc28j60_net));
if (!dev) {
ret = -ENOMEM;
goto error_alloc;
}
priv = netdev_priv(dev);
priv->netdev = dev; /* priv to netdev reference */
priv->spi = spi; /* priv to spi reference */
priv->msg_enable = netif_msg_init(debug.msg_enable, ENC28J60_MSG_DEFAULT);
mutex_init(&priv->lock);
INIT_WORK(&priv->tx_work, enc28j60_tx_work_handler);
INIT_WORK(&priv->setrx_work, enc28j60_setrx_work_handler);
INIT_WORK(&priv->restart_work, enc28j60_restart_work_handler);
spi_set_drvdata(spi, priv); /* spi to priv reference */
SET_NETDEV_DEV(dev, &spi->dev);
if (!enc28j60_chipset_init(dev)) {
if (netif_msg_probe(priv))
dev_info(&spi->dev, "chip not found\n");
ret = -EIO;
goto error_irq;
}
if (device_get_ethdev_address(&spi->dev, dev))
eth_hw_addr_random(dev);
enc28j60_set_hw_macaddr(dev);
/* Board setup must set the relevant edge trigger type;
* level triggers won't currently work.
*/
ret = request_threaded_irq(spi->irq, NULL, enc28j60_irq, IRQF_ONESHOT,
DRV_NAME, priv);
if (ret < 0) {
if (netif_msg_probe(priv))
dev_err(&spi->dev, "request irq %d failed (ret = %d)\n",
spi->irq, ret);
goto error_irq;
}
dev->if_port = IF_PORT_10BASET;
dev->irq = spi->irq;
dev->netdev_ops = &enc28j60_netdev_ops;
dev->watchdog_timeo = TX_TIMEOUT;
dev->ethtool_ops = &enc28j60_ethtool_ops;
enc28j60_lowpower(priv, true);
ret = register_netdev(dev);
if (ret) {
if (netif_msg_probe(priv))
dev_err(&spi->dev, "register netdev failed (ret = %d)\n",
ret);
goto error_register;
}
return 0;
error_register:
free_irq(spi->irq, priv);
error_irq:
free_netdev(dev);
error_alloc:
return ret;
}
static void enc28j60_remove(struct spi_device *spi)
{
struct enc28j60_net *priv = spi_get_drvdata(spi);
unregister_netdev(priv->netdev);
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/types.h`, `linux/fcntl.h`, `linux/interrupt.h`, `linux/property.h`, `linux/string.h`, `linux/errno.h`.
- Detected declarations: `struct enc28j60_net`, `function spi_read_buf`, `function spi_write_buf`, `function spi_read_op`, `function spi_write_op`, `function enc28j60_soft_reset`, `function enc28j60_set_bank`, `function nolock_reg_bfset`, `function locked_reg_bfset`, `function nolock_reg_bfclr`.
- 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.