eepro100.c

来自「基于组件方式开发操作系统的OSKIT源代码」· C语言 代码 · 共 1,918 行 · 第 1/5 页

C
1,918 行
字号
	spin_lock(&sp->lock);#ifndef final_version	dev->interrupt = 1;#endif	do {		status = inw(ioaddr + SCBStatus);		/* Acknowledge all of the current interrupt sources ASAP. */		outw(status & 0xfc00, ioaddr + SCBStatus);		if (speedo_debug > 4)			printk(KERN_DEBUG "%s: interrupt  status=%#4.4x.\n",				   dev->name, status);		if ((status & 0xfc00) == 0)			break;		if (status & 0x4000) {	 /* Packet received. */			speedo_rx(dev);		}		if (status & 0x1000) {#if defined(OSKIT) && defined(DEVICE_POLLING)		  if (sp->polling & POLLING_RX) {			sp->rx_stalled = 1;		  }		  else#endif		  if ((status & 0x003c) == 0x0028) /* No more Rx buffers. */			OUTSCBCMD(RX_RESUMENR, ioaddr);		  else if ((status & 0x003c) == 0x0008) { /* No resources (why?!) */			/* No idea of what went wrong.  Restart the receiver. */			outl(virt_to_bus(sp->rx_ringp[sp->cur_rx % RX_RING_SIZE]),				 ioaddr + SCBPointer);			OUTSCBCMD(RX_START, ioaddr);		  }		  sp->stats.rx_errors++;		}		/* User interrupt, Command/Tx unit interrupt or CU not active. */		if (status & 0xA400) {			speedo_tx_reap(dev);			if (sp->tx_full && dev->tbusy				&& sp->dirty_tx > sp->cur_tx - TX_RING_SIZE + 2) {				/* The ring is no longer full, clear tbusy. */				sp->tx_full = 0;				clear_bit(0, (void*)&dev->tbusy);				mark_bh(NET_BH);			}		}		if (--boguscnt < 0) {			printk(KERN_ERR "%s: Too much work at interrupt, status=0x%4.4x.\n",				   dev->name, status);			/* Clear all interrupt sources. */			outl(0xfc00, ioaddr + SCBStatus);			break;		}	} while (1);	if (speedo_debug > 3)		printk(KERN_DEBUG "%s: exiting interrupt, status=%#4.4x.\n",			   dev->name, inw(ioaddr + SCBStatus));	dev->interrupt = 0;	spin_unlock(&sp->lock);	return;}/* * Returns how many descriptors were sucessfully processed */static intspeedo_tx_reap(struct device *dev){	struct speedo_private *sp = (struct speedo_private *)dev->priv;	unsigned int dirty_tx = sp->dirty_tx;	int cleared = 0;	while (sp->cur_tx - dirty_tx > 0) {		int entry = dirty_tx % TX_RING_SIZE;		int status = sp->tx_ring[entry].status;		if (speedo_debug > 5)			printk(KERN_DEBUG " scavenge candidate %d status %4.4x.\n",				   entry, status);		if ((status & StatusComplete) == 0)			break;			/* It still hasn't been processed. */		/* Free the original skb. */		if (sp->tx_skbuff[entry]) {			sp->stats.tx_packets++;	/* Count only user packets. */			sp->stats.tx_bytes += sp->tx_skbuff[entry]->len; /* Count transmitted bytes */			dev_free_skb(sp->tx_skbuff[entry]);			sp->tx_skbuff[entry] = 0;		} else if ((sp->tx_ring[entry].status&0x70000) == CmdNOp << 16)			sp->mc_setup_busy = 0;		dirty_tx++;		cleared++;	}#ifndef final_version	if (sp->cur_tx - dirty_tx > TX_RING_SIZE) {		printk(KERN_ERR "out-of-sync dirty pointer, %d vs. %d,"			   " full=%d.\n",			   dirty_tx, sp->cur_tx, sp->tx_full);		dirty_tx += TX_RING_SIZE;	}#endif	sp->dirty_tx = dirty_tx;	return cleared;}static intspeedo_rx(struct device *dev){	struct speedo_private *sp = (struct speedo_private *)dev->priv;	int entry = sp->cur_rx % RX_RING_SIZE;	int status;	int rx_work_limit = sp->dirty_rx + RX_RING_SIZE - sp->cur_rx;#if defined(OSKIT) && defined(DEVICE_POLLING)	if (sp->polling & POLLING_RX)		return 0;#endif	if (speedo_debug > 4)		printk(KERN_DEBUG " In speedo_rx().\n");	/* If we own the next entry, it's a new packet. Send it up. */	while (sp->rx_ringp[entry] != NULL &&		   (status = sp->rx_ringp[entry]->status) & RxComplete) {		if (--rx_work_limit < 0)			break;		if (speedo_debug > 4)			printk(KERN_DEBUG "  speedo_rx() status %8.8x len %d.\n", status,				   sp->rx_ringp[entry]->count & 0x3fff);		if ((status & (RxErrTooBig|RxOK)) != RxOK) {			if (status & RxErrTooBig)				printk(KERN_ERR "%s: Ethernet frame overran the Rx buffer, "					   "status %8.8x!\n", dev->name, status);			else if ( ! (status & 0x2000)) {				/* There was a fatal error.  This *should* be impossible. */				sp->stats.rx_errors++;				printk(KERN_ERR "%s: Anomalous event in speedo_rx(), "					   "status %8.8x.\n",					   dev->name, status);			}		} else {			int pkt_len = sp->rx_ringp[entry]->count & 0x3fff;			struct sk_buff *skb;			/* Check if the packet is long enough to just accept without			   copying to a properly sized skbuff. */			if (pkt_len < rx_copybreak				&& (skb = dev_alloc_skb(pkt_len + 2)) != 0) {				skb->dev = dev;				skb_reserve(skb, 2);	/* Align IP on 16 byte boundaries */				/* 'skb_put()' points to the start of sk_buff data area. */#if 1 || USE_IP_CSUM				/* Packet is in one chunk -- we can copy + cksum. */				eth_copy_and_sum(skb,								 bus_to_virt(sp->rx_ringp[entry]->rx_buf_addr),								 pkt_len, 0);				skb_put(skb, pkt_len);#else				memcpy(skb_put(skb, pkt_len),					   bus_to_virt(sp->rx_ringp[entry]->rx_buf_addr), pkt_len);#endif			} else {				void *temp;				/* Pass up the already-filled skbuff. */				skb = sp->rx_skbuff[entry];				if (skb == NULL) {					printk(KERN_ERR "%s: Inconsistent Rx descriptor chain.\n",						   dev->name);					break;				}				sp->rx_skbuff[entry] = NULL;				temp = skb_put(skb, pkt_len);				if (bus_to_virt(sp->rx_ringp[entry]->rx_buf_addr) != temp)					printk(KERN_ERR "%s: Rx consistency error -- the skbuff "						   "addresses do not match in speedo_rx: %p vs. %p "						   "/ %p.\n", dev->name,						   bus_to_virt(sp->rx_ringp[entry]->rx_buf_addr),						   skb->head, temp);				sp->rx_ringp[entry] = NULL;			}			skb->protocol = eth_type_trans(skb, dev);			netif_rx(skb);			sp->stats.rx_packets++;			sp->stats.rx_bytes += pkt_len; /* Count received bytes */		}		entry = (++sp->cur_rx) % RX_RING_SIZE;	}	/* Refill the Rx ring buffers. */	for (; sp->dirty_rx < sp->cur_rx; sp->dirty_rx++) {		struct RxFD *rxf;		entry = sp->dirty_rx % RX_RING_SIZE;		if (sp->rx_skbuff[entry] == NULL) {			struct sk_buff *skb;			/* Get a fresh skbuff to replace the consumed one. */			skb = dev_alloc_skb(PKT_BUF_SZ + sizeof(struct RxFD));			sp->rx_skbuff[entry] = skb;			if (skb == NULL) {				sp->rx_ringp[entry] = NULL;				break;			/* Better luck next time!  */			}			rxf = sp->rx_ringp[entry] = (struct RxFD *)skb->tail;			skb->dev = dev;			skb_reserve(skb, sizeof(struct RxFD));			rxf->rx_buf_addr = virt_to_bus(skb->tail);		} else {			rxf = sp->rx_ringp[entry];		}		rxf->status = 0xC0000001; 	/* '1' for driver use only. */		rxf->link = 0;			/* None yet. */		rxf->count = 0;		rxf->size = PKT_BUF_SZ;		sp->last_rxf->link = virt_to_bus(rxf);		sp->last_rxf->status &= ~0xC0000000;		sp->last_rxf = rxf;	}	sp->last_rx_time = jiffies;	return 0;}#if defined(OSKIT) && defined(DEVICE_POLLING)static voidspeedo_setup_polling(struct device *dev, int rx, int tx){	struct speedo_private *sp = (struct speedo_private *)dev->priv;	long ioaddr = dev->base_addr;	sp->polling = 0;	if (rx) {		wait_for_cmd_done(ioaddr + SCBCmd);		outw(0x4000, ioaddr + SCBCmd);		sp->polling |= POLLING_RX;	}	if (tx) {		sp->polling |= POLLING_TX;	}}static intspeedo_rx_poll(struct device *dev, int count, struct sk_buff *skb_array[]){	struct speedo_private *sp = (struct speedo_private *)dev->priv;	int entry = sp->cur_rx % RX_RING_SIZE;	int status;	int rx_work_limit = sp->dirty_rx + RX_RING_SIZE - sp->cur_rx;	unsigned long flags;	spin_lock_irqsave(&sp->lock, flags);	/*	 * XXX hack: poll on TX device forces flush/reap of all TX requests	 */	if (skb_array == 0 && (sp->polling & POLLING_TX)) {		while (sp->cur_tx - sp->dirty_tx > 0) {			if (speedo_debug > 5)				printk(KERN_DEBUG "%s purging tx queue, cur=%d dirty=%d\n",					   dev->name, sp->cur_tx, sp->dirty_tx);			speedo_tx_reap(dev);		}		sp->tx_full = 0;		clear_bit(0, (void*)&dev->tbusy);		return 0;	}	if (rx_work_limit > count)		rx_work_limit = count;	count = 0;	/* If we own the next entry, it's a new packet. Send it up. */	while (sp->rx_ringp[entry] != NULL &&		   (status = sp->rx_ringp[entry]->status) & RxComplete) {		if (--rx_work_limit < 0)			break;		if (speedo_debug > 4)			printk(KERN_DEBUG "  speedo_rx() status %8.8x len %d.\n", status,				   sp->rx_ringp[entry]->count & 0x3fff);		if ((status & (RxErrTooBig|RxOK)) != RxOK) {			if (status & RxErrTooBig)				printk(KERN_ERR "%s: Ethernet frame overran the Rx buffer, "					   "status %8.8x!\n", dev->name, status);			else if ( ! (status & 0x2000)) {				/* There was a fatal error.  This *should* be impossible. */				sp->stats.rx_errors++;				printk(KERN_ERR "%s: Anomalous event in speedo_rx(), "					   "status %8.8x.\n",					   dev->name, status);			}		} else {			int pkt_len = sp->rx_ringp[entry]->count & 0x3fff;			struct sk_buff *skb;			/* Check if the packet is long enough to just accept without			   copying to a properly sized skbuff. */			if (pkt_len < rx_copybreak				&& (skb = dev_alloc_skb(pkt_len + 2)) != 0) {				skb->dev = dev;				skb_reserve(skb, 2);	/* Align IP on 16 byte boundaries */				/* 'skb_put()' points to the start of sk_buff data area. */#if 1 || USE_IP_CSUM				/* Packet is in one chunk -- we can copy + cksum. */				eth_copy_and_sum(skb,								 bus_to_virt(sp->rx_ringp[entry]->rx_buf_addr),								 pkt_len, 0);				skb_put(skb, pkt_len);#else				memcpy(skb_put(skb, pkt_len),					   bus_to_virt(sp->rx_ringp[entry]->rx_buf_addr), pkt_len);#endif			} else {				void *temp;				/* Pass up the already-filled skbuff. */				skb = sp->rx_skbuff[entry];				if (skb == NULL) {					printk(KERN_ERR "%s: Inconsistent Rx descriptor chain.\n",						   dev->name);					break;				}				sp->rx_skbuff[entry] = NULL;				temp = skb_put(skb, pkt_len);				if (bus_to_virt(sp->rx_ringp[entry]->rx_buf_addr) != temp)					printk(KERN_ERR "%s: Rx consistency error -- the skbuff "						   "addresses do not match in speedo_rx: %p vs. %p "						   "/ %p.\n", dev->name,						   bus_to_virt(sp->rx_ringp[entry]->rx_buf_addr),						   skb->head, temp);				sp->rx_ringp[entry] = NULL;			}			skb->protocol = eth_type_trans(skb, dev);			skb_array[count] = skb;			count += 1;			sp->stats.rx_packets++;			sp->stats.rx_bytes += pkt_len; /* Count received bytes */		}		entry = (++sp->cur_rx) % RX_RING_SIZE;	}	/* Refill the Rx ring buffers. */	for (; sp->dirty_rx < sp->cur_rx; sp->dirty_rx++) {		struct RxFD *rxf;		entry = sp->dirty_rx % RX_RING_SIZE;		if (sp->rx_skbuff[entry] == NULL) {			struct sk_buff *skb;			/* Get a fresh skbuff to replace the consumed one. */			skb = dev_alloc_skb(PKT_BUF_SZ + sizeof(struct RxFD));			sp->rx_skbuff[entry] = skb;			if (skb == NULL) {				sp->rx_ringp[entry] = NULL;				break;			/* Better luck next time!  */			}			rxf = sp->rx_ringp[entry] = (struct RxFD *)skb->tail;			skb->dev = dev;			skb_reserve(skb, sizeof(struct RxFD));			rxf->rx_buf_addr = virt_to_bus(skb->tail);		} else {			rxf = sp->rx_ringp[entry];		}		rxf->status = 0xC0000001; 	/* '1' for driver use only. */		rxf->link = 0;			/* None yet. */		rxf->count = 0;		rxf->size = PKT_BUF_SZ;		sp->last_rxf->link = virt_to_bus(rxf);		sp->last_rxf->status &= ~0xC0000000;		sp->last_rxf = rxf;	}	sp->last_rx_time = jiffies;	/*	 * Look for stalled RX, which was caught in the interrupt handler.	 */	if (sp->rx_stalled &&		!(sp->rx_ringp[sp->cur_rx % RX_RING_SIZE]->status & RxComplete)) {		long ioaddr = dev->base_addr;

⌨️ 快捷键说明

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