drivers/net/ethernet/cirrus/cs89x0.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/cirrus/cs89x0.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/cirrus/cs89x0.c
Extension
.c
Size
35931 bytes
Lines
1286
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 net_ops = {
	.ndo_open		= net_open,
	.ndo_stop		= net_close,
	.ndo_tx_timeout		= net_timeout,
	.ndo_start_xmit		= net_send_packet,
	.ndo_get_stats		= net_get_stats,
	.ndo_set_rx_mode	= set_multicast_list,
	.ndo_set_mac_address	= set_mac_address,
#ifdef CONFIG_NET_POLL_CONTROLLER
	.ndo_poll_controller	= net_poll_controller,
#endif
	.ndo_validate_addr	= eth_validate_addr,
};

static void __init reset_chip(struct net_device *dev)
{
	struct net_local *lp = netdev_priv(dev);
	unsigned long reset_start_time;

	writereg(dev, PP_SelfCTL, readreg(dev, PP_SelfCTL) | POWER_ON_RESET);

	/* wait 30 ms */
	msleep(30);

	if (lp->chip_type != CS8900) {
		/* Hardware problem requires PNP registers to be reconfigured after a reset */
		iowrite16(PP_CS8920_ISAINT, lp->virt_addr + ADD_PORT);
		iowrite8(dev->irq, lp->virt_addr + DATA_PORT);
		iowrite8(0, lp->virt_addr + DATA_PORT + 1);

		iowrite16(PP_CS8920_ISAMemB, lp->virt_addr + ADD_PORT);
		iowrite8((dev->mem_start >> 16) & 0xff,
			 lp->virt_addr + DATA_PORT);
		iowrite8((dev->mem_start >> 8) & 0xff,
			 lp->virt_addr + DATA_PORT + 1);
	}

	/* Wait until the chip is reset */
	reset_start_time = jiffies;
	while ((readreg(dev, PP_SelfST) & INIT_DONE) == 0 &&
	       time_before(jiffies, reset_start_time + 2))
		;
}

/* This is the real probe routine.
 * Linux has a history of friendly device probes on the ISA bus.
 * A good device probes avoids doing writes, and
 * verifies that the correct device exists and functions.
 * Return 0 on success.
 */
static int __init
cs89x0_probe1(struct net_device *dev, void __iomem *ioaddr, int modular)
{
	struct net_local *lp = netdev_priv(dev);
	int i;
	int tmp;
	unsigned rev_type = 0;
	int eeprom_buff[CHKSUM_LEN];
	u8 addr[ETH_ALEN];
	int retval;

	/* Initialize the device structure. */
	if (!modular) {
		memset(lp, 0, sizeof(*lp));
		spin_lock_init(&lp->lock);
#ifndef MODULE
		lp->force = g_cs89x0_media__force;
#endif
	}

	pr_debug("PP_addr at %p[%x]: 0x%x\n",
		 ioaddr, ADD_PORT, ioread16(ioaddr + ADD_PORT));
	iowrite16(PP_ChipID, ioaddr + ADD_PORT);

	tmp = ioread16(ioaddr + DATA_PORT);
	if (tmp != CHIP_EISA_ID_SIG) {
		pr_debug("%s: incorrect signature at %p[%x]: 0x%x!="
			 CHIP_EISA_ID_SIG_STR "\n",
			 dev->name, ioaddr, DATA_PORT, tmp);
		retval = -ENODEV;
		goto out1;
	}

	lp->virt_addr = ioaddr;

	/* get the chip type */
	rev_type = readreg(dev, PRODUCT_ID_ADD);
	lp->chip_type = rev_type & ~REVISON_BITS;
	lp->chip_revision = ((rev_type & REVISON_BITS) >> 8) + 'A';

Annotation

Implementation Notes