err = register_netdev(dev); if (err) goto out_dma; 
static int __init lance_probe1(struct net_device *dev, int ioaddr, int irq, int options){	struct lance_private *lp;	long dma_channels;			/* Mark spuriously-busy DMA channels */	int i, reset_val, lance_version;	const char *chipname;	/* Flags for specific chips or boards. */	unsigned char hpJ2405A = 0;		/* HP ISA adaptor */	int hp_builtin = 0;			/* HP on-board ethernet. */	static int did_version;			/* Already printed version info. */	unsigned long flags;	int err = -ENOMEM;	/* First we look for special cases.	   Check for HP's on-board ethernet by looking for 'HP' in the BIOS.	   There are two HP versions, check the BIOS for the configuration port.	   This method provided by L. Julliard, Laurent_Julliard@grenoble.hp.com.	   */	if (isa_readw(0x000f0102) == 0x5048)  {		static const short ioaddr_table[] = { 0x300, 0x320, 0x340, 0x360};		int hp_port = (isa_readl(0x000f00f1) & 1)  ? 0x499 : 0x99;		/* We can have boards other than the built-in!  Verify this is on-board. */		if ((inb(hp_port) & 0xc0) == 0x80			&& ioaddr_table[inb(hp_port) & 3] == ioaddr)			hp_builtin = hp_port;	}	/* We also recognize the HP Vectra on-board here, but check below. */	hpJ2405A = (inb(ioaddr) == 0x08 && inb(ioaddr+1) == 0x00				&& inb(ioaddr+2) == 0x09);	/* Reset the LANCE.	 */	reset_val = inw(ioaddr+LANCE_RESET); /* Reset the LANCE */	/* The Un-Reset needed is only needed for the real NE2100, and will	   confuse the HP board. */	if (!hpJ2405A)		outw(reset_val, ioaddr+LANCE_RESET);	outw(0x0000, ioaddr+LANCE_ADDR); /* Switch to window 0 */	if (inw(ioaddr+LANCE_DATA) != 0x0004)		return -ENODEV;	/* Get the version of the chip. */	outw(88, ioaddr+LANCE_ADDR);	if (inw(ioaddr+LANCE_ADDR) != 88) {		lance_version = 0;	} else {			/* Good, it's a newer chip. */		int chip_version = inw(ioaddr+LANCE_DATA);		outw(89, ioaddr+LANCE_ADDR);		chip_version |= inw(ioaddr+LANCE_DATA) << 16;		if (lance_debug > 2)			printk("  LANCE chip version is %#x.\n", chip_version);		if ((chip_version & 0xfff) != 0x003)			return -ENODEV;		chip_version = (chip_version >> 12) & 0xffff;		for (lance_version = 1; chip_table[lance_version].id_number; lance_version++) {			if (chip_table[lance_version].id_number == chip_version)				break;		}	}	/* We can't allocate dev->priv from alloc_etherdev() because it must	   a ISA DMA-able region. */	SET_MODULE_OWNER(dev);	chipname = chip_table[lance_version].name;	printk("%s: %s at %#3x,", dev->name, chipname, ioaddr);	/* There is a 16 byte station address PROM at the base address.	   The first six bytes are the station address. */	for (i = 0; i < 6; i++)		printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i));	dev->base_addr = ioaddr;	/* Make certain the data structures used by the LANCE are aligned and DMAble. */			lp = kmalloc(sizeof(*lp), GFP_DMA | GFP_KERNEL);	if(lp==NULL)		return -ENODEV;	if (lance_debug > 6) printk(" (#0x%05lx)", (unsigned long)lp);	memset(lp, 0, sizeof(*lp));	dev->priv = lp;	lp->name = chipname;	lp->rx_buffs = (unsigned long)kmalloc(PKT_BUF_SZ*RX_RING_SIZE,						  GFP_DMA | GFP_KERNEL);	if (!lp->rx_buffs)		goto out_lp;	if (lance_need_isa_bounce_buffers) {		lp->tx_bounce_buffs = kmalloc(PKT_BUF_SZ*TX_RING_SIZE,						  GFP_DMA | GFP_KERNEL);		if (!lp->tx_bounce_buffs)			goto out_rx;	} else		lp->tx_bounce_buffs = NULL;	lp->chip_version = lance_version;	spin_lock_init(&lp->devlock);	lp->init_block.mode = 0x0003;		/* Disable Rx and Tx. */	for (i = 0; i < 6; i++)		lp->init_block.phys_addr[i] = dev->dev_addr[i];	lp->init_block.filter[0] = 0x00000000;	lp->init_block.filter[1] = 0x00000000;	lp->init_block.rx_ring = ((u32)isa_virt_to_bus(lp->rx_ring) & 0xffffff) | RX_RING_LEN_BITS;	lp->init_block.tx_ring = ((u32)isa_virt_to_bus(lp->tx_ring) & 0xffffff) | TX_RING_LEN_BITS;	outw(0x0001, ioaddr+LANCE_ADDR);	inw(ioaddr+LANCE_ADDR);	outw((short) (u32) isa_virt_to_bus(&lp->init_block), ioaddr+LANCE_DATA);	outw(0x0002, ioaddr+LANCE_ADDR);	inw(ioaddr+LANCE_ADDR);	outw(((u32)isa_virt_to_bus(&lp->init_block)) >> 16, ioaddr+LANCE_DATA);	outw(0x0000, ioaddr+LANCE_ADDR);	inw(ioaddr+LANCE_ADDR);	if (irq) {					/* Set iff PCI card. */		dev->dma = 4;			/* Native bus-master, no DMA channel needed. */		dev->irq = irq;	} else if (hp_builtin) {		static const char dma_tbl[4] = {3, 5, 6, 0};		static const char irq_tbl[4] = {3, 4, 5, 9};		unsigned char port_val = inb(hp_builtin);		dev->dma = dma_tbl[(port_val >> 4) & 3];		dev->irq = irq_tbl[(port_val >> 2) & 3];		printk(" HP Vectra IRQ %d DMA %d.\n", dev->irq, dev->dma);	} else if (hpJ2405A) {		static const char dma_tbl[4] = {3, 5, 6, 7};		static const char irq_tbl[8] = {3, 4, 5, 9, 10, 11, 12, 15};		short reset_val = inw(ioaddr+LANCE_RESET);		dev->dma = dma_tbl[(reset_val >> 2) & 3];		dev->irq = irq_tbl[(reset_val >> 4) & 7];		printk(" HP J2405A IRQ %d DMA %d.\n", dev->irq, dev->dma);	} else if (lance_version == PCNET_ISAP) {		/* The plug-n-play version. */		short bus_info;		outw(8, ioaddr+LANCE_ADDR);		bus_info = inw(ioaddr+LANCE_BUS_IF);		dev->dma = bus_info & 0x07;		dev->irq = (bus_info >> 4) & 0x0F;	} else {		/* The DMA channel may be passed in PARAM1. */		if (dev->mem_start & 0x07)			dev->dma = dev->mem_start & 0x07;	}	if (dev->dma == 0) {		/* Read the DMA channel status register, so that we can avoid		   stuck DMA channels in the DMA detection below. */		dma_channels = ((inb(DMA1_STAT_REG) >> 4) & 0x0f) |			(inb(DMA2_STAT_REG) & 0xf0);	}	err = -ENODEV;	if (dev->irq >= 2)		printk(" assigned IRQ %d", dev->irq);	else if (lance_version != 0)  {	/* 7990 boards need DMA detection first. */		unsigned long irq_mask;		/* To auto-IRQ we enable the initialization-done and DMA error		   interrupts. For ISA boards we get a DMA error, but VLB and PCI		   boards will work. */		irq_mask = probe_irq_on();		/* Trigger an initialization just for the interrupt. */		outw(0x0041, ioaddr+LANCE_DATA);		mdelay(20);		dev->irq = probe_irq_off(irq_mask);		if (dev->irq)			printk(", probed IRQ %d", dev->irq);		else {			printk(", failed to detect IRQ line.\n");			goto out_tx;		}		/* Check for the initialization done bit, 0x0100, which means		   that we don't need a DMA channel. */		if (inw(ioaddr+LANCE_DATA) & 0x0100)			dev->dma = 4;	}	if (dev->dma == 4) {		printk(", no DMA needed.\n");	} else if (dev->dma) {		if (request_dma(dev->dma, chipname)) {			printk("DMA %d allocation failed.\n", dev->dma);			goto out_tx;		} else			printk(", assigned DMA %d.\n", dev->dma);	} else {			/* OK, we have to auto-DMA. */		for (i = 0; i < 4; i++) {			static const char dmas[] = { 5, 6, 7, 3 };			int dma = dmas[i];			int boguscnt;			/* Don't enable a permanently busy DMA channel, or the machine			   will hang. */			if (test_bit(dma, &dma_channels))				continue;			outw(0x7f04, ioaddr+LANCE_DATA); /* Clear the memory error bits. */			if (request_dma(dma, chipname))				continue;							flags=claim_dma_lock();			set_dma_mode(dma, DMA_MODE_CASCADE);			enable_dma(dma);			release_dma_lock(flags);			/* Trigger an initialization. */			outw(0x0001, ioaddr+LANCE_DATA);			for (boguscnt = 100; boguscnt > 0; --boguscnt)				if (inw(ioaddr+LANCE_DATA) & 0x0900)					break;			if (inw(ioaddr+LANCE_DATA) & 0x0100) {				dev->dma = dma;				printk(", DMA %d.\n", dev->dma);				break;			} else {				flags=claim_dma_lock();				disable_dma(dma);				release_dma_lock(flags);				free_dma(dma);			}		}		if (i == 4) {			/* Failure: bail. */			printk("DMA detection failed.\n");			goto out_tx;		}	}	if (lance_version == 0 && dev->irq == 0) {		/* We may auto-IRQ now that we have a DMA channel. */		/* Trigger an initialization just for the interrupt. */		unsigned long irq_mask;		irq_mask = probe_irq_on();		outw(0x0041, ioaddr+LANCE_DATA);		mdelay(40);		dev->irq = probe_irq_off(irq_mask);		if (dev->irq == 0) {			printk("  Failed to detect the 7990 IRQ line.\n");			goto out_dma;		}		printk("  Auto-IRQ detected IRQ%d.\n", dev->irq);	}	if (chip_table[lp->chip_version].flags & LANCE_ENABLE_AUTOSELECT) {		/* Turn on auto-select of media (10baseT or BNC) so that the user		   can watch the LEDs even if the board isn't opened. */		outw(0x0002, ioaddr+LANCE_ADDR);		/* Don't touch 10base2 power bit. */		outw(inw(ioaddr+LANCE_BUS_IF) | 0x0002, ioaddr+LANCE_BUS_IF);	}	if (lance_debug > 0  &&  did_version++ == 0)		printk(version);	/* The LANCE-specific entries in the device structure. */	dev->open = lance_open;	dev->hard_start_xmit = lance_start_xmit;	dev->stop = lance_close;	dev->get_stats = lance_get_stats;	dev->set_multicast_list = set_multicast_list;	dev->tx_timeout = lance_tx_timeout;	dev->watchdog_timeo = TX_TIMEOUT;	return 0;out_dma:	if (dev->dma != 4)		free_dma(dev->dma);out_tx:	kfree(lp->tx_bounce_buffs);out_rx:	kfree((void*)lp->rx_buffs);out_lp:	kfree(lp);	return err;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/b1fc5505e0dbcc3fd7c75bfe6bee39ec50080963/lance.c/clean/drivers/net/lance.c