drivers/net/ethernet/microchip/encx24j600.c

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

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/microchip/encx24j600.c
Extension
.c
Size
29726 bytes
Lines
1129
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 encx24j600_netdev_ops = {
	.ndo_open = encx24j600_open,
	.ndo_stop = encx24j600_stop,
	.ndo_start_xmit = encx24j600_tx,
	.ndo_set_rx_mode = encx24j600_set_multicast_list,
	.ndo_set_mac_address = encx24j600_set_mac_address,
	.ndo_tx_timeout = encx24j600_tx_timeout,
	.ndo_validate_addr = eth_validate_addr,
};

static int encx24j600_spi_probe(struct spi_device *spi)
{
	int ret;

	struct net_device *ndev;
	struct encx24j600_priv *priv;
	u16 eidled;
	u8 addr[ETH_ALEN];

	ndev = alloc_etherdev(sizeof(struct encx24j600_priv));

	if (!ndev) {
		ret = -ENOMEM;
		goto error_out;
	}

	priv = netdev_priv(ndev);
	spi_set_drvdata(spi, priv);
	dev_set_drvdata(&spi->dev, priv);
	SET_NETDEV_DEV(ndev, &spi->dev);

	priv->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
	priv->ndev = ndev;

	/* Default configuration PHY configuration */
	priv->full_duplex = true;
	priv->autoneg = AUTONEG_ENABLE;
	priv->speed = SPEED_100;

	priv->ctx.spi = spi;
	ndev->irq = spi->irq;
	ndev->netdev_ops = &encx24j600_netdev_ops;

	ret = devm_regmap_init_encx24j600(&spi->dev, &priv->ctx);
	if (ret)
		goto out_free;

	mutex_init(&priv->lock);

	/* Reset device and check if it is connected */
	if (encx24j600_hw_reset(priv)) {
		netif_err(priv, probe, ndev,
			  DRV_NAME ": Chip is not detected\n");
		ret = -EIO;
		goto out_free;
	}

	/* Initialize the device HW to the consistent state */
	encx24j600_hw_init(priv);

	kthread_init_worker(&priv->kworker);
	kthread_init_work(&priv->tx_work, encx24j600_tx_proc);
	kthread_init_work(&priv->setrx_work, encx24j600_setrx_proc);

	priv->kworker_task = kthread_run(kthread_worker_fn, &priv->kworker,
					 "encx24j600");

	if (IS_ERR(priv->kworker_task)) {
		ret = PTR_ERR(priv->kworker_task);
		goto out_free;
	}

	/* Get the MAC address from the chip */
	encx24j600_hw_get_macaddr(priv, addr);
	eth_hw_addr_set(ndev, addr);

	ndev->ethtool_ops = &encx24j600_ethtool_ops;

	ret = register_netdev(ndev);
	if (unlikely(ret)) {
		netif_err(priv, probe, ndev, "Error %d initializing card encx24j600 card\n",
			  ret);
		goto out_stop;
	}

	eidled = encx24j600_read_reg(priv, EIDLED);
	if (((eidled & DEVID_MASK) >> DEVID_SHIFT) != ENCX24J600_DEV_ID) {
		ret = -EINVAL;
		goto out_unregister;
	}

Annotation

Implementation Notes