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

📄 eepro.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
				if (i & 0x20) { /* command ABORTed */					printk("%s: multicast setup failed.\n", 						dev->name);					break;				} else if ((i & 0x0f) == 0x03)	{ /* MC-Done */					printk("%s: set Rx mode to %d address%s.\n",						dev->name, dev->mc_count,						dev->mc_count > 1 ? "es":"");					break;				}			}		} while (++boguscount < 100);		/* Re-enable RX and TX interrupts */		eepro_en_int(ioaddr);	}	eepro_complete_selreset(ioaddr);}/* The horrible routine to read a word from the serial EEPROM. *//* IMPORTANT - the 82595 will be set to Bank 0 after the eeprom is read *//* The delay between EEPROM clock transitions. */#define eeprom_delay() { udelay(40); }#define EE_READ_CMD (6 << 6)intread_eeprom(int ioaddr, int location, struct net_device *dev){	int i;	unsigned short retval = 0;	short ee_addr = ioaddr + eeprom_reg;	struct eepro_local *lp = (struct eepro_local *)dev->priv;	int read_cmd = location | EE_READ_CMD;	short ctrl_val = EECS ;	/* XXXX - this is not the final version. We must test this on other	 *	  boards other than eepro10. I think that it won't let other	 *	  boards to fail. (aris)	 */	if (lp->eepro == LAN595FX_10ISA) {		eepro_sw2bank1(ioaddr);		outb(0x00, ioaddr + STATUS_REG);	}		eepro_sw2bank2(ioaddr);	outb(ctrl_val, ee_addr);		/* Shift the read command bits out. */	for (i = 8; i >= 0; i--) {		short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI			: ctrl_val;		outb(outval, ee_addr);		outb(outval | EESK, ee_addr);	/* EEPROM clock tick. */		eeprom_delay();		outb(outval, ee_addr);	/* Finish EEPROM a clock tick. */		eeprom_delay();	}	outb(ctrl_val, ee_addr);		for (i = 16; i > 0; i--) {		outb(ctrl_val | EESK, ee_addr);	 eeprom_delay();		retval = (retval << 1) | ((inb(ee_addr) & EEDO) ? 1 : 0);		outb(ctrl_val, ee_addr);  eeprom_delay();	}	/* Terminate the EEPROM access. */	ctrl_val &= ~EECS;	outb(ctrl_val | EESK, ee_addr);	eeprom_delay();	outb(ctrl_val, ee_addr);	eeprom_delay();	eepro_sw2bank0(ioaddr);	return retval;}static voidhardware_send_packet(struct net_device *dev, void *buf, short length){	struct eepro_local *lp = (struct eepro_local *)dev->priv;	short ioaddr = dev->base_addr;	unsigned status, tx_available, last, end, boguscount = 100;	if (net_debug > 5)		printk(KERN_DEBUG "%s: entering hardware_send_packet routine.\n", dev->name);	while (boguscount-- > 0) {		/* Disable RX and TX interrupts.  Necessary to avoid		corruption of the HOST_ADDRESS_REG by interrupt		service routines. */		eepro_dis_int(ioaddr);		/* determine how much of the transmit buffer space is available */		if (lp->tx_end > lp->tx_start)			tx_available = XMT_RAM - (lp->tx_end - lp->tx_start);		else if (lp->tx_end < lp->tx_start)			tx_available = lp->tx_start - lp->tx_end;		else tx_available = XMT_RAM;		if (((((length + 3) >> 1) << 1) + 2*XMT_HEADER) 			>= tx_available)   /* No space available ??? */			{			eepro_transmit_interrupt(dev); /* Clean up the transmiting queue */			/* Enable RX and TX interrupts */			eepro_en_int(ioaddr);			continue;		}		last = lp->tx_end;		end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;		if (end >= (XMT_UPPER_LIMIT << 8)) { /* the transmit buffer is wrapped around */			if (((XMT_UPPER_LIMIT << 8) - last) <= XMT_HEADER) {					/* Arrrr!!!, must keep the xmt header together,				several days were lost to chase this one down. */								last = (XMT_LOWER_LIMIT << 8);				end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;			}						else end = (XMT_LOWER_LIMIT << 8) + (end -						(XMT_UPPER_LIMIT <<8));		}		outw(last, ioaddr + HOST_ADDRESS_REG);		outw(XMT_CMD, ioaddr + IO_PORT); 		outw(0, ioaddr + IO_PORT);		outw(end, ioaddr + IO_PORT);		outw(length, ioaddr + IO_PORT);		if (lp->version == LAN595)			outsw(ioaddr + IO_PORT, buf, (length + 3) >> 1);		else {	/* LAN595TX or LAN595FX, capable of 32-bit I/O processing */			unsigned short temp = inb(ioaddr + INT_MASK_REG);			outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);			outsl(ioaddr + IO_PORT_32_BIT, buf, (length + 3) >> 2);			outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);		}		/* A dummy read to flush the DRAM write pipeline */		status = inw(ioaddr + IO_PORT); 		if (lp->tx_start == lp->tx_end) {				outw(last, ioaddr + xmt_bar);			outb(XMT_CMD, ioaddr);			lp->tx_start = last;   /* I don't like to change tx_start here */		}		else {			/* update the next address and the chain bit in the 			last packet */						if (lp->tx_end != last) {				outw(lp->tx_last + XMT_CHAIN, ioaddr + HOST_ADDRESS_REG);				outw(last, ioaddr + IO_PORT); 			}						outw(lp->tx_last + XMT_COUNT, ioaddr + HOST_ADDRESS_REG);			status = inw(ioaddr + IO_PORT); 			outw(status | CHAIN_BIT, ioaddr + IO_PORT);			/* Continue the transmit command */			outb(RESUME_XMT_CMD, ioaddr);		}		lp->tx_last = last;		lp->tx_end = end;		if (netif_queue_stopped(dev))			netif_wake_queue(dev);		/* now we are serializing tx. queue won't come back until		 * the tx interrupt		 */		if (lp->eepro == LAN595FX_10ISA)			netif_stop_queue(dev);				/* Enable RX and TX interrupts */		eepro_en_int(ioaddr);		if (net_debug > 5)			printk(KERN_DEBUG "%s: exiting hardware_send_packet routine.\n", dev->name);		return;	}	netif_stop_queue(dev);	if (net_debug > 5)		printk(KERN_DEBUG "%s: exiting hardware_send_packet routine.\n", dev->name);}static voideepro_rx(struct net_device *dev){	struct eepro_local *lp = (struct eepro_local *)dev->priv;	short ioaddr = dev->base_addr;	short boguscount = 20;	unsigned rcv_car = lp->rx_start;	unsigned rcv_event, rcv_status, rcv_next_frame, rcv_size;	if (net_debug > 5)		printk(KERN_DEBUG "%s: entering eepro_rx routine.\n", dev->name);	/* Set the read pointer to the start of the RCV */	outw(rcv_car, ioaddr + HOST_ADDRESS_REG);		rcv_event = inw(ioaddr + IO_PORT);	while (rcv_event == RCV_DONE) {			rcv_status = inw(ioaddr + IO_PORT); 		rcv_next_frame = inw(ioaddr + IO_PORT);		rcv_size = inw(ioaddr + IO_PORT); 		if ((rcv_status & (RX_OK | RX_ERROR)) == RX_OK) {					/* Malloc up new buffer. */			struct sk_buff *skb;			lp->stats.rx_bytes+=rcv_size;			rcv_size &= 0x3fff;			skb = dev_alloc_skb(rcv_size+5);			if (skb == NULL) {				printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);				lp->stats.rx_dropped++;				break;			}			skb->dev = dev;			skb_reserve(skb,2);			if (lp->version == LAN595)				insw(ioaddr+IO_PORT, skb_put(skb,rcv_size), (rcv_size + 3) >> 1);			else { /* LAN595TX or LAN595FX, capable of 32-bit I/O processing */				unsigned short temp = inb(ioaddr + INT_MASK_REG);				outb(temp | IO_32_BIT, ioaddr + INT_MASK_REG);				insl(ioaddr+IO_PORT_32_BIT, skb_put(skb,rcv_size), 					(rcv_size + 3) >> 2);				outb(temp & ~(IO_32_BIT), ioaddr + INT_MASK_REG);			}				skb->protocol = eth_type_trans(skb,dev);				netif_rx(skb);			lp->stats.rx_packets++;		}				else { /* Not sure will ever reach here, 			I set the 595 to discard bad received frames */			lp->stats.rx_errors++;						if (rcv_status & 0x0100)				lp->stats.rx_over_errors++;						else if (rcv_status & 0x0400)				lp->stats.rx_frame_errors++;						else if (rcv_status & 0x0800)				lp->stats.rx_crc_errors++;						printk("%s: event = %#x, status = %#x, next = %#x, size = %#x\n", 				dev->name, rcv_event, rcv_status, rcv_next_frame, rcv_size);		}		if (rcv_status & 0x1000)			lp->stats.rx_length_errors++;		if (--boguscount == 0)			break;		rcv_car = lp->rx_start + RCV_HEADER + rcv_size;		lp->rx_start = rcv_next_frame;		outw(rcv_next_frame, ioaddr + HOST_ADDRESS_REG);		rcv_event = inw(ioaddr + IO_PORT);	} 	if (rcv_car == 0)		rcv_car = (RCV_UPPER_LIMIT << 8) | 0xff;			outw(rcv_car - 1, ioaddr + RCV_STOP);	if (net_debug > 5)		printk(KERN_DEBUG "%s: exiting eepro_rx routine.\n", dev->name);}static voideepro_transmit_interrupt(struct net_device *dev){	struct eepro_local *lp = (struct eepro_local *)dev->priv;	short ioaddr = dev->base_addr;	short boguscount = 20; 	unsigned xmt_status;		/*	if (dev->tbusy == 0) {		printk("%s: transmit_interrupt called with tbusy = 0 ??\n",			dev->name);		printk(KERN_DEBUG "%s: transmit_interrupt called with tbusy = 0 ??\n",			dev->name);	}	*/	while (lp->tx_start != lp->tx_end && boguscount) { 		outw(lp->tx_start, ioaddr + HOST_ADDRESS_REG); 		xmt_status = inw(ioaddr+IO_PORT);				if ((xmt_status & TX_DONE_BIT) == 0) {			udelay(40);			boguscount--;			continue;		}		xmt_status = inw(ioaddr+IO_PORT); 		lp->tx_start = inw(ioaddr+IO_PORT);		if (lp->eepro == LAN595FX_10ISA) {			lp->tx_start = (XMT_LOWER_LIMIT << 8);			lp->tx_end = lp->tx_start;				/* yeah, black magic :( */			eepro_sw2bank0(ioaddr);			eepro_en_int(ioaddr);			/* disabling rx */			eepro_dis_rx(ioaddr);						/* enabling rx */			eepro_en_rx(ioaddr);		}		netif_wake_queue (dev);		if (xmt_status & 0x2000)			lp->stats.tx_packets++; 		else {			lp->stats.tx_errors++;			if (xmt_status & 0x0400) {				lp->stats.tx_carrier_errors++;				printk(KERN_DEBUG "%s: carrier error\n",					dev->name);				printk(KERN_DEBUG "%s: XMT status = %#x\n",					dev->name, xmt_status);			}			else {				printk(KERN_DEBUG "%s: XMT status = %#x\n",					dev->name, xmt_status);				printk(KERN_DEBUG "%s: XMT status = %#x\n",					dev->name, xmt_status);			}			if (lp->eepro == LAN595FX_10ISA) {							/* Try to restart the adaptor. */				/* We are supposed to wait for 2 us after a SEL_RESET */				eepro_sel_reset(ioaddr);				/* first enable interrupts */				eepro_sw2bank0(ioaddr);				outb(ALL_MASK & ~(RX_INT | TX_INT), ioaddr + STATUS_REG);							/* enabling rx */				eepro_en_rx(ioaddr);			}		}		if (xmt_status & 0x000f) {			lp->stats.collisions += (xmt_status & 0x000f);		}				if ((xmt_status & 0x0040) == 0x0) {			lp->stats.tx_heartbeat_errors++;		}		boguscount--;	}	/* if it reached here then it's probable that the adapter won't	 * interrupt again for tx. in other words: tx timeout what will take	 * a lot of time to happen, so we'll do a complete selreset.	 */	if (!boguscount)		eepro_complete_selreset(ioaddr);}#define MAX_EEPRO 8static struct net_device dev_eepro[MAX_EEPRO];static int io[MAX_EEPRO];static int irq[MAX_EEPRO];static int mem[MAX_EEPRO] = {	/* Size of the rx buffer in KB */  [0 ... MAX_EEPRO-1] = RCV_DEFAULT_RAM/1024};static int autodetect;static int n_eepro = 0;/* For linux 2.1.xx */MODULE_AUTHOR("Pascal Dupuis <dupuis@lei.ucl.ac.be> for the 2.1 stuff (locking,...)");MODULE_DESCRIPTION("Intel i82595 ISA EtherExpressPro10/10+ driver");MODULE_PARM(io, "1-" __MODULE_STRING(MAX_EEPRO) "i");MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_EEPRO) "i");MODULE_PARM(mem, "1-" __MODULE_STRING(MAX_EEPRO) "i");MODULE_PARM(autodetect, "1-" __MODULE_STRING(1) "i");#ifdef MODULEint init_module(void){	int i;	if (io[0] == 0 && autodetect == 0) {		printk("eepro_init_module: Probe is very dangerous in ISA boards!\n");		printk("eepro_init_module: Please add \"autodetect=1\" to force probe\n");		return 1;	}	else if (autodetect) {		/* if autodetect is set then we must force detection */		io[0] = 0;				printk("eepro_init_module: Auto-detecting boards (May God protect us...)\n");	}		for (i = 0; i < MAX_EEPRO; i++) {		struct net_device *d = &dev_eepro[n_eepro];		d->mem_end	= mem[n_eepro];		d->base_addr	= io[0];		d->irq		= irq[n_eepro];		d->init		= eepro_probe;		if (register_netdev(d) == 0)			n_eepro++;		else			break;	}		return n_eepro ? 0 : -ENODEV;}voidcleanup_module(void){	int i;		for (i=0; i<n_eepro; i++) {		struct net_device *d = &dev_eepro[i];		unregister_netdev(d);		kfree(d->priv);		d->priv=NULL;		/* If we don't do this, we can't re-insmod it later. */		release_region(d->base_addr, EEPRO_IO_EXTENT);			}}#endif /* MODULE */

⌨️ 快捷键说明

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