📄 rtl_rtl8139_drv.h
字号:
/* 8139too.c: A RealTek RTL-8139 Fast Ethernet driver for Linux. Maintained by Jeff Garzik <jgarzik@mandrakesoft.com> Copyright 2000,2001 Jeff Garzik Much code comes from Donald Becker's rtl8139.c driver, versions 1.13 and older. This driver was originally based on rtl8139.c version 1.07. Header of rtl8139.c version 1.13: -----<snip>----- Written 1997-2001 by Donald Becker. This software may be used and distributed according to the terms of the GNU General Public License (GPL), incorporated herein by reference. Drivers based on or derived from this code fall under the GPL and must retain the authorship, copyright and license notice. This file is not a complete program and may only be used when the entire operating system is licensed under the GPL. This driver is for boards based on the RTL8129 and RTL8139 PCI ethernet chips. The author may be reached as becker@scyld.com, or C/O Scyld Computing Corporation 410 Severn Ave., Suite 210 Annapolis MD 21403 Support and updates available at http://www.scyld.com/network/rtl8139.html Twister-tuning table provided by Kinston <shangh@realtek.com.tw>. -----<snip>----- This software may be used and distributed according to the terms of the GNU General Public License, incorporated herein by reference. Contributors: Donald Becker - he wrote the original driver, kudos to him! (but please don't e-mail him for support, this isn't his driver) Tigran Aivazian - bug fixes, skbuff free cleanup Martin Mares - suggestions for PCI cleanup David S. Miller - PCI DMA and softnet updates Ernst Gill - fixes ported from BSD driver Daniel Kobras - identified specific locations of posted MMIO write bugginess Gerard Sharp - bug fix, testing and feedback David Ford - Rx ring wrap fix Dan DeMaggio - swapped RTL8139 cards with me, and allowed me to find and fix a crucial bug on older chipsets. Donald Becker/Chris Butterworth/Marcus Westergren - Noticed various Rx packet size-related buglets. Santiago Garcia Mantinan - testing and feedback Jens David - 2.2.x kernel backports Martin Dennett - incredibly helpful insight on undocumented features of the 8139 chips Jean-Jacques Michel - bug fix Tobias Ringstr鰉 - Rx interrupt status checking suggestion Andrew Morton - Clear blocked signals, avoid buffer overrun setting current->comm. Submitting bug reports: "rtl8139-diag -mmmaaavvveefN" output enable RTL8139_DEBUG below, and look at 'dmesg' or kernel log See 8139too.txt for more details.-----------------------------------------------------------------------------2001/09/21Comments by ShuChen Shao 1.This driver is originally based on 8139too.c version "0.9.15". 2.It has been enhanced to support RTL8139C+ PCI ethernet chips and tested in 2.4.2 kernel. 3.RTL8139C+ PCI ethernet chips is set to support C+ mode by default. If FORCE_C_Mode below is enable, the RTL8139C+ chip will be forced to support C mode after reboot. 4.This program can be compiled at /usr/src/linux-2.4.2/drivers/net/ using the attached Makefile. And the object file named 8139too.o should be moved to the directory /lib/modules/2.4.2-2/kernel/drivers/net/-----------------------------------------------------------------------------===================================================================================== PORTING TO RT-LINUX===================================================================================== 15 May 2003ByungGi Baek <gi@realtimewave.com||weapon100@empal.com> 1. This driver is originally based on 8139too.c 2. This file is also based in one file part of the RTL-lwIP TCP/IP stack. The file is: rt_3c905x_phys.c which author is: Sergio Perez Alca駃z <serpeal@upvnet.upv.es> 3. This file is compiled and tested on RTL-lwIP-0.2.1 4. Unload the original 8139 linux driver then load this driver. ===================================================================================== */#include <linux/kernel.h>#include <linux/module.h>#include <linux/pci.h>#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/errno.h>#include <linux/in.h>#include <linux/ioport.h>#include <linux/slab.h>#include <linux/interrupt.h>#include <linux/mii.h>#include <linux/init.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/ethtool.h>#include <linux/highmem.h>#include <asm/irq.h> /* For NR_IRQS only. */#include <asm/bitops.h>#include <asm/io.h>#include <asm/uaccess.h>#include <rtl_sched.h>#include <signal.h>#include <time.h> #define DRV_NAME "rtl8139"#define DRV_VERSION "0.1"#define DRV_RELDATE " 4 2003"#undef USE_IO_OPS#ifdef USE_IO_OPS #define RTL_R8(reg) inb (((unsigned long)ioaddr) + (reg))#define RTL_R16(reg) inw (((unsigned long)ioaddr) + (reg))#define RTL_R32(reg) ((unsigned long) inl (((unsigned long)ioaddr) + (reg)))#define RTL_W8(reg, val8) outb ((val8), ((unsigned long)ioaddr) + (reg))#define RTL_W16(reg, val16) outw ((val16), ((unsigned long)ioaddr) + (reg))#define RTL_W32(reg, val32) outl ((val32), ((unsigned long)ioaddr) + (reg))#define RTL_W8_F RTL_W8#define RTL_W16_F RTL_W16#define RTL_W32_F RTL_W32#undef readb#undef readw#undef readl#undef writeb#undef writew#undef writel#define readb(addr) inb((unsigned long)(addr))#define readw(addr) inw((unsigned long)(addr))#define readl(addr) inl((unsigned long)(addr))#define writeb(val,addr) outb((val),(unsigned long)(addr))#define writew(val,addr) outw((val),(unsigned long)(addr))#define writel(val,addr) outl((val),(unsigned long)(addr))#else /* write MMIO register, with flush *//* Flush avoids rtl8139 bug w/ posted MMIO writes */#define RTL_W8_F(reg, val8) do { writeb ((val8), ioaddr + (reg)); readb (ioaddr + (reg)); } while (0)#define RTL_W16_F(reg, val16) do { writew ((val16), ioaddr + (reg)); readw (ioaddr + (reg)); } while (0)#define RTL_W32_F(reg, val32) do { writel ((val32), ioaddr + (reg)); readl (ioaddr + (reg)); } while (0) #if MMIO_FLUSH_AUDIT_COMPLETE /* write MMIO register */#define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg))#define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg))#define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg)) #else /* write MMIO register, then flush */#define RTL_W8 RTL_W8_F#define RTL_W16 RTL_W16_F#define RTL_W32 RTL_W32_F #endif /* MMIO_FLUSH_AUDIT_COMPLETE */ /* read MMIO register */#define RTL_R8(reg) readb (ioaddr + (reg))#define RTL_R16(reg) readw (ioaddr + (reg))#define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg))) #endif /* USE_IO_OPS */ #define MAX_THREADS 10 #define RTL8139_VENDOR_ID 0x10EC#define RTL8139_DEVICE_ID 0X8139#define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*//* Size of the in-memory receive ring. */#define RX_BUF_LEN_IDX 2 /* 0==8K, 1==16K, 2==32K, 3==64K */#define RX_BUF_LEN (8192 << RX_BUF_LEN_IDX)#define RX_BUF_PAD 16#define RX_BUF_WRAP_PAD 2048 /* spare padding to handle lack of packet wrap */#define RX_BUF_TOT_LEN (RX_BUF_LEN + RX_BUF_PAD + RX_BUF_WRAP_PAD)#define MAX_ADDR_LEN 8 /* Largest hardware address length */ /* Number of Tx descriptor registers. */#define NUM_TX_DESC 4 /* max supported ethernet frame size -- must be at least (dev->mtu+14+4).*/#define MAX_ETH_FRAME_SIZE 1536 /* Size of the Tx bounce buffers -- must be at least (dev->mtu+14+4). */#define TX_BUF_SIZE MAX_ETH_FRAME_SIZE#define TX_BUF_TOT_LEN (TX_BUF_SIZE * NUM_TX_DESC)/* Number of Tx descriptor registers. */#define NUM_TX_DESC 4 /* max supported ethernet frame size -- must be at least (dev->mtu+14+4).*/#define MAX_ETH_FRAME_SIZE 1536 /* Size of the Tx bounce buffers -- must be at least (dev->mtu+14+4). */#define TX_BUF_SIZE MAX_ETH_FRAME_SIZE#define TX_BUF_TOT_LEN (TX_BUF_SIZE * NUM_TX_DESC) /* PCI Tuning Parameters Threshold is bytes transferred to chip before transmission starts. */#define TX_FIFO_THRESH 256 /* In bytes, rounded down to 32 byte units. */ /* The following settings are log_2(bytes)-4: 0 == 16 bytes .. 6==1024, 7==end of packet. */#define RX_FIFO_THRESH 6 /* Rx buffer level before first PCI xfer. */#define RX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */#define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ /* Operational parameters that usually are not changed. *//* Time in jiffies before concluding the transmitter is hung. */#define TX_TIMEOUT (6*HZ)/* for 8139C+ only */#define NUM_CP_TX_DESC 64 /* Number of Tx descriptor registers for C*+/#define NUM_CP_RX_DESC 64 /* Number of Rx descriptor registers for C*+/#define CP_RX_BUF_SIZE 2000struct ring_info { struct sk_buff *skb; dma_addr_t mapping;}; typedef enum { CH_8139 = 0, CH_8139_K, CH_8139A, CH_8139B, CH_8130, CH_8139C, CH_8139CP,} chip_t; #define TX_RING_SIZE 16#define RX_RING_SIZE 32enum { HAS_MII_XCVR = 0x010000, HAS_CHIP_XCVR = 0x020000, HAS_LNK_CHNG = 0x040000,}; #define RTL_MIN_IO_SIZE 0x80#define RTL8139B_IO_SIZE 256 #define RTL8129_CAPS HAS_MII_XCVR#define RTL8139_CAPS HAS_CHIP_XCVR|HAS_LNK_CHNG typedef enum { RTL8139 = 0, RTL8139_CB, SMC1211TX, /*MPX5030,*/ DELTA8139, ADDTRON8139, DFE538TX, RTL8129,} board_t;/* indexed by board_t, above */static struct { const char *name; u32 hw_flags;} board_info[] __devinitdata = { { "RealTek RTL8139CP Fast Ethernet", RTL8139_CAPS }, { "RealTek RTL8139B PCI/CardBus", RTL8139_CAPS }, { "SMC1211TX EZCard 10/100 (RealTek RTL8139)", RTL8139_CAPS },/* { MPX5030, "Accton MPX5030 (RealTek RTL8139)", RTL8139_CAPS },*/ { "Delta Electronics 8139 10/100BaseTX", RTL8139_CAPS }, { "Addtron Technolgy 8139 10/100BaseTX", RTL8139_CAPS }, { "D-Link DFE-538TX (RealTek RTL8139)", RTL8139_CAPS }, { "RealTek RTL8129", RTL8129_CAPS },};/* directly indexed by chip_t, above */const static struct { const char *name; u8 version; /* from RTL8139C docs */ u32 RxConfigMask; /* should clear the bits supported by this chip */} rtl_chip_info[] = { { "RTL-8139", 0x40, 0xf0fe0040, /* XXX copied from RTL8139A, verify */ }, { "RTL-8139 rev K", 0x60, 0xf0fe0040, }, { "RTL-8139A", 0x70, 0xf0fe0040, }, { "RTL-8139B", 0x78, 0xf0fc0040 }, { "RTL-8130", 0x7C, 0xf0fe0040, /* XXX copied from RTL8139A, verify */ }, { "RTL-8139C", 0x74, 0xf0fc0040, /* XXX copied from RTL8139B, verify */ }, { "RTL-8139CP", 0x76,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -