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

📄 eexpress.c

📁 LINUX1.0内核源代码,学习LINUX编程的一定要看。
💻 C
📖 第 1 页 / 共 3 页
字号:
	/* The station address is stored !backwards! in the EEPROM, reverse	   after reading.  (Hmmm, a little brain-damage there at Intel, eh?) */	station_addr[0] = read_eeprom(ioaddr, 2);	station_addr[1] = read_eeprom(ioaddr, 3);	station_addr[2] = read_eeprom(ioaddr, 4);	/* Check the first three octets of the S.A. for the manufactor's code. */	if (station_addr[2] != 0x00aa || (station_addr[1] & 0xff00) != 0x0000) {		printk(" rejected (invalid address %04x%04x%04x).\n",			   station_addr[2], station_addr[1], station_addr[0]);		return ENODEV;	}	/* We've committed to using the board, and can start filling in *dev. */	snarf_region(ioaddr, 16);	dev->base_addr = ioaddr;	for (i = 0; i < 6; i++) {		dev->dev_addr[i] = ((unsigned char*)station_addr)[5-i];		printk(" %02x", dev->dev_addr[i]);	}	/* There is no reason for the driver to care, but I print out the	   interface to minimize bogus bug reports. */	{		char irqmap[] = {0, 9, 3, 4, 5, 10, 11, 0};		char *ifmap[] = {"AUI", "BNC", "10baseT"};		enum iftype {AUI=0, BNC=1, TP=2};		unsigned short setupval = read_eeprom(ioaddr, 0);		dev->irq = irqmap[setupval >> 13];		dev->if_port = (setupval & 0x1000) == 0 ? AUI :			read_eeprom(ioaddr, 5) & 0x1 ? TP : BNC;		printk(", IRQ %d, Interface %s.\n", dev->irq, ifmap[dev->if_port]);		/* Release the IRQ line so that it can be shared if we don't use the		   ethercard. */		outb(0x00, ioaddr + SET_IRQ);	}	/* It's now OK to leave the board in reset, pending the open(). */	outb(ASIC_RESET, ioaddr + EEPROM_Ctrl);	if ((dev->mem_start & 0xf) > 0)		net_debug = dev->mem_start & 7;	if (net_debug)		printk(version);	/* Initialize the device structure. */	dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);	memset(dev->priv, 0, sizeof(struct net_local));	dev->open		= eexp_open;	dev->stop		= eexp_close;	dev->hard_start_xmit = eexp_send_packet;	dev->get_stats	= eexp_get_stats;#ifdef HAVE_MULTICAST	dev->set_multicast_list = &set_multicast_list;#endif	/* Fill in the fields of the device structure with ethernet-generic values.	   This should be in a common file instead of per-driver.  */	for (i = 0; i < DEV_NUMBUFFS; i++)		dev->buffs[i] = NULL;	dev->hard_header	= eth_header;	dev->add_arp	= eth_add_arp;	dev->queue_xmit = dev_queue_xmit;	dev->rebuild_header = eth_rebuild_header;	dev->type_trans = eth_type_trans;	dev->type		= ARPHRD_ETHER;	dev->hard_header_len = ETH_HLEN;	dev->mtu		= 1500; /* eth_mtu */	dev->addr_len	= ETH_ALEN;	for (i = 0; i < ETH_ALEN; i++) {		dev->broadcast[i]=0xff;	}	/* New-style flags. */	dev->flags		= IFF_BROADCAST;	dev->family		= AF_INET;	dev->pa_addr	= 0;	dev->pa_brdaddr = 0;	dev->pa_mask	= 0;	dev->pa_alen	= sizeof(unsigned long);	return 0;}/* Reverse IRQ map: the value to put in the SET_IRQ reg. for IRQ<index>. */static char irqrmap[]={0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0};static inteexp_open(struct device *dev){	int ioaddr = dev->base_addr;	if (dev->irq == 0  ||  irqrmap[dev->irq] == 0)		return -ENXIO;	if (irq2dev_map[dev->irq] != 0		/* This is always true, but avoid the false IRQ. */		|| (irq2dev_map[dev->irq] = dev) == 0		|| request_irq(dev->irq, &eexp_interrupt)) {		return -EAGAIN;	}	/* Initialize the 82586 memory and start it. */	init_82586_mem(dev);	/* Enable the interrupt line. */	outb(irqrmap[dev->irq] | 0x08, ioaddr + SET_IRQ);	dev->tbusy = 0;	dev->interrupt = 0;	dev->start = 1;	return 0;}static inteexp_send_packet(struct sk_buff *skb, struct device *dev){	struct net_local *lp = (struct net_local *)dev->priv;	int ioaddr = dev->base_addr;	if (dev->tbusy) {		/* If we get here, some higher level has decided we are broken.		   There should really be a "kick me" function call instead. */		int tickssofar = jiffies - dev->trans_start;		if (tickssofar < 5)			return 1;		if (net_debug > 1)			printk("%s: transmit timed out, %s?  ", dev->name,				   inw(ioaddr+SCB_STATUS) & 0x8000 ? "IRQ conflict" :				   "network cable problem");		lp->stats.tx_errors++;		/* Try to restart the adaptor. */		if (lp->last_restart == lp->stats.tx_packets) {			if (net_debug > 1) printk("Resetting board.\n");			/* Completely reset the adaptor. */			init_82586_mem(dev);		} else {			/* Issue the channel attention signal and hope it "gets better". */			if (net_debug > 1) printk("Kicking board.\n");			outw(0xf000|CUC_START|RX_START, ioaddr + SCB_CMD);			outb(0, ioaddr + SIGNAL_CA);			lp->last_restart = lp->stats.tx_packets;		}		dev->tbusy=0;		dev->trans_start = jiffies;	}	/* If some higher layer thinks we've missed an tx-done interrupt	   we are passed NULL. Caution: dev_tint() handles the cli()/sti()	   itself. */	if (skb == NULL) {		dev_tint(dev);		return 0;	}	/* For ethernet, fill in the header.  This should really be done by a	   higher level, rather than duplicated for each ethernet adaptor. */	if (!skb->arp  &&  dev->rebuild_header(skb->data, dev)) {		skb->dev = dev;		arp_queue (skb);		return 0;	}	skb->arp=1;	/* Block a timer-based transmit from overlapping. */	if (set_bit(0, (void*)&dev->tbusy) != 0)		printk("%s: Transmitter access conflict.\n", dev->name);	else {		short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;		unsigned char *buf = skb->data;		/* Disable the 82586's input to the interrupt line. */		outb(irqrmap[dev->irq], ioaddr + SET_IRQ);		hardware_send_packet(dev, buf, length);		dev->trans_start = jiffies;		/* Enable the 82586 interrupt input. */		outb(0x08 | irqrmap[dev->irq], ioaddr + SET_IRQ);	}	if (skb->free)		kfree_skb (skb, FREE_WRITE);	/* You might need to clean up and record Tx statistics here. */	lp->stats.tx_aborted_errors++;	return 0;}/*	The typical workload of the driver:	Handle the network interface interrupts. */static voideexp_interrupt(int reg_ptr){	int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);	struct device *dev = (struct device *)(irq2dev_map[irq]);	struct net_local *lp;	int ioaddr, status, boguscount = 0;	short ack_cmd;	if (dev == NULL) {		printk ("net_interrupt(): irq %d for unknown device.\n", irq);		return;	}	dev->interrupt = 1;		ioaddr = dev->base_addr;	lp = (struct net_local *)dev->priv;		status = inw(ioaddr + SCB_STATUS);	    if (net_debug > 4) {		printk("%s: EExp interrupt, status %4.4x.\n", dev->name, status);    }	/* Disable the 82586's input to the interrupt line. */	outb(irqrmap[dev->irq], ioaddr + SET_IRQ);	/* Reap the Tx packet buffers. */	while (lp->tx_reap != lp->tx_head) { 	/* if (status & 0x8000) */		unsigned short tx_status;		outw(lp->tx_reap, ioaddr + READ_PTR);		tx_status = inw(ioaddr);		if (tx_status == 0) {			if (net_debug > 5)  printk("Couldn't reap %#x.\n", lp->tx_reap);			break;		}		if (tx_status & 0x2000) {			lp->stats.tx_packets++;			lp->stats.collisions += tx_status & 0xf;			dev->tbusy = 0;			mark_bh(INET_BH);	/* Inform upper layers. */		} else {			lp->stats.tx_errors++;			if (tx_status & 0x0600)  lp->stats.tx_carrier_errors++;			if (tx_status & 0x0100)  lp->stats.tx_fifo_errors++;			if (!(tx_status & 0x0040))  lp->stats.tx_heartbeat_errors++;			if (tx_status & 0x0020)  lp->stats.tx_aborted_errors++;		}		if (net_debug > 5)			printk("Reaped %x, Tx status %04x.\n" , lp->tx_reap, tx_status);		lp->tx_reap += TX_BUF_SIZE;		if (lp->tx_reap > TX_BUF_END - TX_BUF_SIZE)			lp->tx_reap = TX_BUF_START;		if (++boguscount > 4)			break;	}	if (status & 0x4000) { /* Packet received. */		if (net_debug > 5)			printk("Received packet, rx_head %04x.\n", lp->rx_head);		eexp_rx(dev);	}	/* Acknowledge the interrupt sources. */	ack_cmd = status & 0xf000;	if ((status & 0x0700) != 0x0200  &&  dev->start) {		short saved_write_ptr = inw(ioaddr + WRITE_PTR);		if (net_debug > 1)			printk("%s: Command unit stopped, status %04x, restarting.\n",				   dev->name, status);		/* If this ever occurs we must re-write the idle loop, reset		   the Tx list, and do a complete restart of the command unit. */		outw(IDLELOOP, ioaddr + WRITE_PTR);		outw(0, ioaddr);		outw(CmdNOp, ioaddr);		outw(IDLELOOP, ioaddr);		outw(IDLELOOP, SCB_CBL);		lp->tx_cmd_link = IDLELOOP + 4;		lp->tx_head = lp->tx_reap = TX_BUF_START;		/* Restore the saved write pointer. */		outw(saved_write_ptr, ioaddr + WRITE_PTR);		ack_cmd |= CUC_START;	}	if ((status & 0x0070) != 0x0040  &&  dev->start) {		short saved_write_ptr = inw(ioaddr + WRITE_PTR);		/* The Rx unit is not ready, it must be hung.  Restart the receiver by		   initializing the rx buffers, and issuing an Rx start command. */		lp->stats.rx_errors++;		if (net_debug > 1) {			int cur_rxbuf = RX_BUF_START;			printk("%s: Rx unit stopped status %04x rx head %04x tail %04x.\n",				   dev->name, status, lp->rx_head, lp->rx_tail);			while (cur_rxbuf <= RX_BUF_END - RX_BUF_SIZE) {				int i;				printk("  Rx buf at %04x:", cur_rxbuf);				outw(cur_rxbuf, ioaddr + READ_PTR);				for (i = 0; i < 0x20; i += 2)					printk(" %04x", inw(ioaddr));				printk(".\n");				cur_rxbuf += RX_BUF_SIZE;			}		}		init_rx_bufs(dev);		outw(RX_BUF_START, SCB_RFA);		outw(saved_write_ptr, ioaddr + WRITE_PTR);		ack_cmd |= RX_START;	}	outw(ack_cmd, ioaddr + SCB_CMD);	outb(0, ioaddr + SIGNAL_CA);    if (net_debug > 5) {		printk("%s: EExp exiting interrupt, status %4.4x.\n", dev->name,			   inw(ioaddr + SCB_CMD));    }	/* Enable the 82586's input to the interrupt line. */	outb(irqrmap[dev->irq] | 0x08, ioaddr + SET_IRQ);	return;}static inteexp_close(struct device *dev){	int ioaddr = dev->base_addr;	dev->tbusy = 1;	dev->start = 0;	/* Flush the Tx and disable Rx. */	outw(RX_SUSPEND | CUC_SUSPEND, ioaddr + SCB_CMD);	outb(0, ioaddr + SIGNAL_CA);	/* Disable the physical interrupt line. */	outb(0, ioaddr + SET_IRQ);	free_irq(dev->irq);	irq2dev_map[dev->irq] = 0;	/* Update the statistics here. */	return 0;}/* Get the current statistics.	This may be called with the card open or   closed. */static struct enet_statistics *eexp_get_stats(struct device *dev){	struct net_local *lp = (struct net_local *)dev->priv;

⌨️ 快捷键说明

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