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

📄 interrupt.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*	drivers/net/tulip/interrupt.c	Maintained by Jeff Garzik <jgarzik@pobox.com>	Copyright 2000,2001  The Linux Kernel Team	Written/copyright 1994-2001 by Donald Becker.	This software may be used and distributed according to the terms	of the GNU General Public License, incorporated herein by reference.	Please refer to Documentation/DocBook/tulip.{pdf,ps,html}	for more information on this driver, or visit the project	Web page at http://sourceforge.net/projects/tulip/*/#include "tulip.h"#include <linux/config.h>#include <linux/etherdevice.h>#include <linux/pci.h>int tulip_rx_copybreak;unsigned int tulip_max_interrupt_work;#ifdef CONFIG_NET_HW_FLOWCONTROL#define MIT_SIZE 15unsigned int mit_table[MIT_SIZE+1] ={        /*  CRS11 21143 hardware Mitigation Control Interrupt            We use only RX mitigation we other techniques for            TX intr. mitigation.           31    Cycle Size (timer control)           30:27 TX timer in 16 * Cycle size           26:24 TX No pkts before Int.           23:20 RX timer in Cycle size           19:17 RX No pkts before Int.           16       Continues Mode (CM)        */        0x0,             /* IM disabled */        0x80150000,      /* RX time = 1, RX pkts = 2, CM = 1 */        0x80150000,        0x80270000,        0x80370000,        0x80490000,        0x80590000,        0x80690000,        0x807B0000,        0x808B0000,        0x809D0000,        0x80AD0000,        0x80BD0000,        0x80CF0000,        0x80DF0000,//       0x80FF0000      /* RX time = 16, RX pkts = 7, CM = 1 */        0x80F10000      /* RX time = 16, RX pkts = 0, CM = 1 */};#endifint tulip_refill_rx(struct net_device *dev){	struct tulip_private *tp = (struct tulip_private *)dev->priv;	int entry;	int refilled = 0;	/* Refill the Rx ring buffers. */	for (; tp->cur_rx - tp->dirty_rx > 0; tp->dirty_rx++) {		entry = tp->dirty_rx % RX_RING_SIZE;		if (tp->rx_buffers[entry].skb == NULL) {			struct sk_buff *skb;			dma_addr_t mapping;			skb = tp->rx_buffers[entry].skb = dev_alloc_skb(PKT_BUF_SZ);			if (skb == NULL)				break;			mapping = pci_map_single(tp->pdev, skb->tail, PKT_BUF_SZ,						 PCI_DMA_FROMDEVICE);			tp->rx_buffers[entry].mapping = mapping;			skb->dev = dev;			/* Mark as being used by this device. */			tp->rx_ring[entry].buffer1 = cpu_to_le32(mapping);			refilled++;		}		tp->rx_ring[entry].status = cpu_to_le32(DescOwned);	}	if(tp->chip_id == LC82C168) {		if(((inl(dev->base_addr + CSR5)>>17)&0x07) == 4) {			/* Rx stopped due to out of buffers,			 * restart it			 */			outl(0x01, dev->base_addr + CSR2);		}	}	return refilled;}static int tulip_rx(struct net_device *dev){	struct tulip_private *tp = (struct tulip_private *)dev->priv;	int entry = tp->cur_rx % RX_RING_SIZE;	int rx_work_limit = tp->dirty_rx + RX_RING_SIZE - tp->cur_rx;	int received = 0;#ifdef CONFIG_NET_HW_FLOWCONTROL        int drop = 0, mit_sel = 0;/* that one buffer is needed for mit activation; or might be a   bug in the ring buffer code; check later -- JHS*/        if (rx_work_limit >=RX_RING_SIZE) rx_work_limit--;#endif	if (tulip_debug > 4)		printk(KERN_DEBUG " In tulip_rx(), entry %d %8.8x.\n", entry,			   tp->rx_ring[entry].status);	/* If we own the next entry, it is a new packet. Send it up. */	while ( ! (tp->rx_ring[entry].status & cpu_to_le32(DescOwned))) {		s32 status = le32_to_cpu(tp->rx_ring[entry].status);		if (tulip_debug > 5)			printk(KERN_DEBUG "%s: In tulip_rx(), entry %d %8.8x.\n",				   dev->name, entry, status);		if (--rx_work_limit < 0)			break;		if ((status & 0x38008300) != 0x0300) {			if ((status & 0x38000300) != 0x0300) {				/* Ingore earlier buffers. */				if ((status & 0xffff) != 0x7fff) {					if (tulip_debug > 1)						printk(KERN_WARNING "%s: Oversized Ethernet frame "							   "spanned multiple buffers, status %8.8x!\n",							   dev->name, status);					tp->stats.rx_length_errors++;				}			} else if (status & RxDescFatalErr) {				/* There was a fatal error. */				if (tulip_debug > 2)					printk(KERN_DEBUG "%s: Receive error, Rx status %8.8x.\n",						   dev->name, status);				tp->stats.rx_errors++; /* end of a packet.*/				if (status & 0x0890) tp->stats.rx_length_errors++;				if (status & 0x0004) tp->stats.rx_frame_errors++;				if (status & 0x0002) tp->stats.rx_crc_errors++;				if (status & 0x0001) tp->stats.rx_fifo_errors++;			}		} else {			/* Omit the four octet CRC from the length. */			short pkt_len = ((status >> 16) & 0x7ff) - 4;			struct sk_buff *skb;#ifndef final_version			if (pkt_len > 1518) {				printk(KERN_WARNING "%s: Bogus packet size of %d (%#x).\n",					   dev->name, pkt_len, pkt_len);				pkt_len = 1518;				tp->stats.rx_length_errors++;			}#endif#ifdef CONFIG_NET_HW_FLOWCONTROL                        drop = atomic_read(&netdev_dropping);                        if (drop)                                goto throttle;#endif			/* Check if the packet is long enough to accept without copying			   to a minimally-sized skbuff. */			if (pkt_len < tulip_rx_copybreak				&& (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {				skb->dev = dev;				skb_reserve(skb, 2);	/* 16 byte align the IP header */				pci_dma_sync_single(tp->pdev,						    tp->rx_buffers[entry].mapping,						    pkt_len, PCI_DMA_FROMDEVICE);#if ! defined(__alpha__)				eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->tail,						 pkt_len, 0);				skb_put(skb, pkt_len);#else				memcpy(skb_put(skb, pkt_len),				       tp->rx_buffers[entry].skb->tail,				       pkt_len);#endif			} else { 	/* Pass up the skb already on the Rx ring. */				char *temp = skb_put(skb = tp->rx_buffers[entry].skb,						     pkt_len);#ifndef final_version				if (tp->rx_buffers[entry].mapping !=				    le32_to_cpu(tp->rx_ring[entry].buffer1)) {					printk(KERN_ERR "%s: Internal fault: The skbuff addresses "					       "do not match in tulip_rx: %08x vs. %08x %p / %p.\n",					       dev->name,					       le32_to_cpu(tp->rx_ring[entry].buffer1),					       tp->rx_buffers[entry].mapping,					       skb->head, temp);				}#endif				pci_unmap_single(tp->pdev, tp->rx_buffers[entry].mapping,						 PKT_BUF_SZ, PCI_DMA_FROMDEVICE);				tp->rx_buffers[entry].skb = NULL;				tp->rx_buffers[entry].mapping = 0;			}			skb->protocol = eth_type_trans(skb, dev);#ifdef CONFIG_NET_HW_FLOWCONTROL                        mit_sel =#endif			netif_rx(skb);#ifdef CONFIG_NET_HW_FLOWCONTROL                        switch (mit_sel) {                        case NET_RX_SUCCESS:                        case NET_RX_CN_LOW:                        case NET_RX_CN_MOD:                                break;                        case NET_RX_CN_HIGH:                                rx_work_limit -= NET_RX_CN_HIGH; /* additional*/                                break;                        case NET_RX_DROP:                                rx_work_limit = -1;                                break;                        default:                                printk("unknown feedback return code %d\n", mit_sel);                                break;                        }                        drop = atomic_read(&netdev_dropping);                        if (drop) {throttle:                                rx_work_limit = -1;                                mit_sel = NET_RX_DROP;                                if (tp->fc_bit) {                                        long ioaddr = dev->base_addr;                                        /* disable Rx & RxNoBuf ints. */                                        outl(tulip_tbl[tp->chip_id].valid_intrs&RX_A_NBF_STOP, ioaddr + CSR7);                                        set_bit(tp->fc_bit, &netdev_fc_xoff);                                }                        }#endif			dev->last_rx = jiffies;			tp->stats.rx_packets++;			tp->stats.rx_bytes += pkt_len;		}		received++;		entry = (++tp->cur_rx) % RX_RING_SIZE;	}#ifdef CONFIG_NET_HW_FLOWCONTROL        /* We use this simplistic scheme for IM. It's proven by           real life installations. We can have IM enabled           continuesly but this would cause unnecessary latency.           Unfortunely we can't use all the NET_RX_* feedback here.           This would turn on IM for devices that is not contributing           to backlog congestion with unnecessary latency.           We monitor the device RX-ring and have:           HW Interrupt Mitigation either ON or OFF.           ON:  More then 1 pkt received (per intr.) OR we are dropping           OFF: Only 1 pkt received           Note. We only use min and max (0, 15) settings from mit_table */        if( tp->flags &  HAS_INTR_MITIGATION) {                if((received > 1 || mit_sel == NET_RX_DROP)                   && tp->mit_sel != 15 ) {                        tp->mit_sel = 15;                        tp->mit_change = 1; /* Force IM change */                }                if((received <= 1 && mit_sel != NET_RX_DROP) && tp->mit_sel != 0 ) {                        tp->mit_sel = 0;                        tp->mit_change = 1; /* Force IM change */                }        }        return RX_RING_SIZE+1; /* maxrx+1 */#else	return received;#endif

⌨️ 快捷键说明

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