⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3c509.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 3 页
字号:
	   ID_PORT.  We find cards past the first by setting the 'current_tag'	   on cards as they are found.  Cards with their tag set will not	   respond to subsequent ID sequences. */	outb(0x00, id_port);	outb(0x00, id_port);	for(i = 0; i < 255; i++) {		outb(lrs_state, id_port);		lrs_state <<= 1;		lrs_state = lrs_state & 0x100 ? lrs_state ^ 0xcf : lrs_state;	}	/* For the first probe, clear all board's tag registers. */	if (current_tag == 0)		outb(0xd0, id_port);	else				/* Otherwise kill off already-found boards. */		outb(0xd8, id_port);	if (id_read_eeprom(7) != 0x6d50) {		return -ENODEV;	}	/* Read in EEPROM data, which does contention-select.	   Only the lowest address board will stay "on-line".	   3Com got the byte order backwards. */	for (i = 0; i < 3; i++) {		phys_addr[i] = htons(id_read_eeprom(i));	}#if defined(CONFIG_ISAPNP) || defined(CONFIG_ISAPNP_MODULE)	if (nopnp == 0) {		/* The ISA PnP 3c509 cards respond to the ID sequence.		   This check is needed in order not to register them twice. */		for (i = 0; i < pnp_cards; i++) {			if (phys_addr[0] == el3_isapnp_phys_addr[i][0] &&			    phys_addr[1] == el3_isapnp_phys_addr[i][1] &&			    phys_addr[2] == el3_isapnp_phys_addr[i][2])			{				if (el3_debug > 3)					printk("3c509 with address %02x %02x %02x %02x %02x %02x was found by ISAPnP\n",						phys_addr[0] & 0xff, phys_addr[0] >> 8,						phys_addr[1] & 0xff, phys_addr[1] >> 8,						phys_addr[2] & 0xff, phys_addr[2] >> 8);				/* Set the adaptor tag so that the next card can be found. */				outb(0xd0 + ++current_tag, id_port);				goto no_pnp;			}		}	}#endif /* CONFIG_ISAPNP || CONFIG_ISAPNP_MODULE */	{		unsigned int iobase = id_read_eeprom(8);		if_port = iobase >> 14;		ioaddr = 0x200 + ((iobase & 0x1f) << 4);	}	irq = id_read_eeprom(9) >> 12;	if (dev) {					/* Set passed-in IRQ or I/O Addr. */		if (dev->irq > 1  &&  dev->irq < 16)			irq = dev->irq;		if (dev->base_addr) {			if (dev->mem_end == 0x3c509 			/* Magic key */				&& dev->base_addr >= 0x200  &&  dev->base_addr <= 0x3e0)				ioaddr = dev->base_addr & 0x3f0;			else if (dev->base_addr != ioaddr)				return -ENODEV;		}	}	if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509"))		return -EBUSY;	/* Set the adaptor tag so that the next card can be found. */	outb(0xd0 + ++current_tag, id_port);	/* Activate the adaptor at the EEPROM location. */	outb((ioaddr >> 4) | 0xe0, id_port);	EL3WINDOW(0);	if (inw(ioaddr) != 0x6d50) {		release_region(ioaddr, EL3_IO_EXTENT);		return -ENODEV;	}	/* Free the interrupt so that some other card can use it. */	outw(0x0f00, ioaddr + WN0_IRQ); found:	if (dev == NULL) {		dev = init_etherdev(dev, sizeof(struct el3_private));		if (dev == NULL) {			release_region(ioaddr, EL3_IO_EXTENT);			return -ENOMEM;		}		SET_MODULE_OWNER(dev);	}	memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr));	dev->base_addr = ioaddr;	dev->irq = irq;	dev->if_port = (dev->mem_start & 0x1f) ? dev->mem_start & 3 : if_port;	{		const char *if_names[] = {"10baseT", "AUI", "undefined", "BNC"};		printk("%s: 3c5x9 at %#3.3lx, %s port, address ",			   dev->name, dev->base_addr, if_names[dev->if_port]);	}	/* Read in the station address. */	for (i = 0; i < 6; i++)		printk(" %2.2x", dev->dev_addr[i]);	printk(", IRQ %d.\n", dev->irq);	/* Make up a EL3-specific-data structure. */	if (dev->priv == NULL)		dev->priv = kmalloc(sizeof(struct el3_private), GFP_KERNEL);	if (dev->priv == NULL)		return -ENOMEM;	memset(dev->priv, 0, sizeof(struct el3_private));		lp = dev->priv;	lp->mca_slot = mca_slot;	lp->next_dev = el3_root_dev;	spin_lock_init(&lp->lock);	el3_root_dev = dev;	if (el3_debug > 0)		printk(KERN_INFO "%s" KERN_INFO "%s", versionA, versionB);	/* The EL3-specific entries in the device structure. */	dev->open = &el3_open;	dev->hard_start_xmit = &el3_start_xmit;	dev->stop = &el3_close;	dev->get_stats = &el3_get_stats;	dev->set_multicast_list = &set_multicast_list;	dev->tx_timeout = el3_tx_timeout;	dev->watchdog_timeo = TX_TIMEOUT;	dev->do_ioctl = netdev_ioctl;	/* Fill in the generic fields of the device structure. */	ether_setup(dev);	return 0;}/* Read a word from the EEPROM using the regular EEPROM access register.   Assume that we are in register window zero. */static ushort __init read_eeprom(int ioaddr, int index){	outw(EEPROM_READ + index, ioaddr + 10);	/* Pause for at least 162 us. for the read to take place. */	udelay (500);	return inw(ioaddr + 12);}/* Read a word from the EEPROM when in the ISA ID probe state. */static ushort __init id_read_eeprom(int index){	int bit, word = 0;	/* Issue read command, and pause for at least 162 us. for it to complete.	   Assume extra-fast 16Mhz bus. */	outb(EEPROM_READ + index, id_port);	/* Pause for at least 162 us. for the read to take place. */	udelay (500);		for (bit = 15; bit >= 0; bit--)		word = (word << 1) + (inb(id_port) & 0x01);	if (el3_debug > 3)		printk("  3c509 EEPROM word %d %#4.4x.\n", index, word);	return word;}static intel3_open(struct net_device *dev){	int ioaddr = dev->base_addr;	int i;	outw(TxReset, ioaddr + EL3_CMD);	outw(RxReset, ioaddr + EL3_CMD);	outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);	i = request_irq(dev->irq, &el3_interrupt, 0, dev->name, dev);	if (i) return i;	EL3WINDOW(0);	if (el3_debug > 3)		printk("%s: Opening, IRQ %d	 status@%x %4.4x.\n", dev->name,			   dev->irq, ioaddr + EL3_STATUS, inw(ioaddr + EL3_STATUS));	/* Activate board: this is probably unnecessary. */	outw(0x0001, ioaddr + 4);	/* Set the IRQ line. */	outw((dev->irq << 12) | 0x0f00, ioaddr + WN0_IRQ);	/* Set the station address in window 2 each time opened. */	EL3WINDOW(2);	for (i = 0; i < 6; i++)		outb(dev->dev_addr[i], ioaddr + i);	if (dev->if_port == 3)		/* Start the thinnet transceiver. We should really wait 50ms...*/		outw(StartCoax, ioaddr + EL3_CMD);	else if (dev->if_port == 0) {		/* 10baseT interface, enabled link beat and jabber check. */		EL3WINDOW(4);		outw(inw(ioaddr + WN4_MEDIA) | MEDIA_TP, ioaddr + WN4_MEDIA);	}	/* Switch to the stats window, and clear all stats by reading. */	outw(StatsDisable, ioaddr + EL3_CMD);	EL3WINDOW(6);	for (i = 0; i < 9; i++)		inb(ioaddr + i);	inw(ioaddr + 10);	inw(ioaddr + 12);	/* Switch to register set 1 for normal use. */	EL3WINDOW(1);	/* Accept b-case and phys addr only. */	outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);	outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */	netif_start_queue(dev);	outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */	outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */	/* Allow status bits to be seen. */	outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);	/* Ack all pending events, and set active indicator mask. */	outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,		 ioaddr + EL3_CMD);	outw(SetIntrEnb | IntLatch|TxAvailable|TxComplete|RxComplete|StatsFull,		 ioaddr + EL3_CMD);	if (el3_debug > 3)		printk("%s: Opened 3c509  IRQ %d  status %4.4x.\n",			   dev->name, dev->irq, inw(ioaddr + EL3_STATUS));	return 0;}static voidel3_tx_timeout (struct net_device *dev){	struct el3_private *lp = (struct el3_private *)dev->priv;	int ioaddr = dev->base_addr;	/* Transmitter timeout, serious problems. */	printk("%s: transmit timed out, Tx_status %2.2x status %4.4x "		   "Tx FIFO room %d.\n",		   dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS),		   inw(ioaddr + TX_FREE));	lp->stats.tx_errors++;	dev->trans_start = jiffies;	/* Issue TX_RESET and TX_START commands. */	outw(TxReset, ioaddr + EL3_CMD);	outw(TxEnable, ioaddr + EL3_CMD);	netif_wake_queue(dev);}static intel3_start_xmit(struct sk_buff *skb, struct net_device *dev){	struct el3_private *lp = (struct el3_private *)dev->priv;	int ioaddr = dev->base_addr;	unsigned long flags;	netif_stop_queue (dev);	lp->stats.tx_bytes += skb->len;		if (el3_debug > 4) {		printk("%s: el3_start_xmit(length = %u) called, status %4.4x.\n",			   dev->name, skb->len, inw(ioaddr + EL3_STATUS));	}#if 0#ifndef final_version	{	/* Error-checking code, delete someday. */		ushort status = inw(ioaddr + EL3_STATUS);		if (status & 0x0001 		/* IRQ line active, missed one. */			&& inw(ioaddr + EL3_STATUS) & 1) { 			/* Make sure. */			printk("%s: Missed interrupt, status then %04x now %04x"				   "  Tx %2.2x Rx %4.4x.\n", dev->name, status,				   inw(ioaddr + EL3_STATUS), inb(ioaddr + TX_STATUS),				   inw(ioaddr + RX_STATUS));			/* Fake interrupt trigger by masking, acknowledge interrupts. */			outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);			outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,				 ioaddr + EL3_CMD);			outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);		}	}#endif#endif	/*	 *	We lock the driver against other processors. Note	 *	we don't need to lock versus the IRQ as we suspended	 *	that. This means that we lose the ability to take	 *	an RX during a TX upload. That sucks a bit with SMP	 *	on an original 3c509 (2K buffer)	 *	 *	Using disable_irq stops us crapping on other	 *	time sensitive devices.	 */    	spin_lock_irqsave(&lp->lock, flags);	    	/* Put out the doubleword header... */	outw(skb->len, ioaddr + TX_FIFO);	outw(0x00, ioaddr + TX_FIFO);	/* ... and the packet rounded to a doubleword. */#ifdef  __powerpc__	outsl_unswapped(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);#else	outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);#endif	dev->trans_start = jiffies;	if (inw(ioaddr + TX_FREE) > 1536)		netif_start_queue(dev);	else		/* Interrupt us when the FIFO has room for max-sized packet. */		outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);	spin_unlock_irqrestore(&lp->lock, flags);	dev_kfree_skb (skb);	/* Clear the Tx status stack. */	{		short tx_status;		int i = 4;		while (--i > 0	&&	(tx_status = inb(ioaddr + TX_STATUS)) > 0) {			if (tx_status & 0x38) lp->stats.tx_aborted_errors++;			if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);			if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);			outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */		}	}	return 0;}/* The EL3 interrupt handler. */static voidel3_interrupt(int irq, void *dev_id, struct pt_regs *regs){	struct net_device *dev = (struct net_device *)dev_id;	struct el3_private *lp;	int ioaddr, status;	int i = max_interrupt_work;	if (dev == NULL) {		printk ("el3_interrupt(): irq %d for unknown device.\n", irq);		return;	}	lp = (struct el3_private *)dev->priv;	spin_lock(&lp->lock);	ioaddr = dev->base_addr;	if (el3_debug > 4) {		status = inw(ioaddr + EL3_STATUS);		printk("%s: interrupt, status %4.4x.\n", dev->name, status);	}	while ((status = inw(ioaddr + EL3_STATUS)) &		   (IntLatch | RxComplete | StatsFull)) {		if (status & RxComplete)			el3_rx(dev);		if (status & TxAvailable) {			if (el3_debug > 5)				printk("	TX room bit was handled.\n");			/* There's room in the FIFO for a full-sized packet. */			outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -