ia64/xen-unstable

changeset 691:3744aa0643ce

bitkeeper revision 1.405 (3f576749oUqfWqUHieN31fCpXGcUcQ)

interrupt.c, pcnet32.c, time.c, setup.c:
More fixes, to network code and to timer code.
.del-8139too.c~2cde387fe3225d91:
Delete: xen/drivers/net/8139too.c
.del-via-rhine.c~6bd6f82d46529478:
Delete: xen/drivers/net/via-rhine.c
author kaf24@scramble.cl.cam.ac.uk
date Thu Sep 04 16:24:41 2003 +0000 (2003-09-04)
parents cf5bddb3603e
children 1f4e3a24e225
files .rootkeys xen/arch/i386/setup.c xen/arch/i386/time.c xen/drivers/net/8139too.c xen/drivers/net/pcnet32.c xen/drivers/net/tulip/interrupt.c xen/drivers/net/via-rhine.c
line diff
     1.1 --- a/.rootkeys	Thu Sep 04 15:55:41 2003 +0000
     1.2 +++ b/.rootkeys	Thu Sep 04 16:24:41 2003 +0000
     1.3 @@ -230,7 +230,6 @@ 3ddb79bdkDY1bSOYkToP1Cc49VdBxg xen/drive
     1.4  3ddb79bdPyAvT_WZTAFhaX0jp-yXSw xen/drivers/ide/ide_modes.h
     1.5  3e4a8d401aSwOzCScQXR3lsmNlAwUQ xen/drivers/ide/piix.c
     1.6  3ddb79bfMlOcWUwjtg6oMYhGySHDDw xen/drivers/net/3c59x.c
     1.7 -3f0c423bjmEpn1Nbk1Q8fv8ElccwAA xen/drivers/net/8139too.c
     1.8  3ddb79c0tWiE8xIFHszxipeVCGKTSA xen/drivers/net/Makefile
     1.9  3f0c4247730LYUgz3p5ziYqy-s_glw xen/drivers/net/SUPPORTED_CARDS
    1.10  3ddb79bfU-H1Hms4BuJEPPydjXUEaQ xen/drivers/net/Space.c
    1.11 @@ -271,7 +270,6 @@ 3f0c428eyyo0-aI_fj4gDBiNYe-Idw xen/drive
    1.12  3f0c428eZQhoTueBPxOO5YbuzoTofw xen/drivers/net/tulip/timer.c
    1.13  3f0c428eoDFGJZJrBRnA7918Yovt0A xen/drivers/net/tulip/tulip.h
    1.14  3f0c428e46klSV-upTm6D8tCdzQs8Q xen/drivers/net/tulip/tulip_core.c
    1.15 -3f0c428eu_CTRPhmTgGIjoiGI_PmrA xen/drivers/net/via-rhine.c
    1.16  3ddb79beUWngyIhMHgyPtuTem4o4JA xen/drivers/pci/Makefile
    1.17  3ddb79beU9td0Mnm0VUMklerBa37qQ xen/drivers/pci/compat.c
    1.18  3ddb79beHkGQE58z5t5gyUCYiwOxvw xen/drivers/pci/gen-devlist.c
     2.1 --- a/xen/arch/i386/setup.c	Thu Sep 04 15:55:41 2003 +0000
     2.2 +++ b/xen/arch/i386/setup.c	Thu Sep 04 16:24:41 2003 +0000
     2.3 @@ -330,6 +330,7 @@ void __init start_of_day(void)
     2.4      extern void initialize_serial(void);
     2.5      extern void initialize_keyboard(void);
     2.6      extern int opt_nosmp, opt_watchdog;
     2.7 +    extern int do_timer_lists_from_pit;
     2.8      unsigned long low_mem_size;
     2.9      
    2.10      if ( opt_watchdog ) 
    2.11 @@ -388,6 +389,8 @@ void __init start_of_day(void)
    2.12          disable_pit();
    2.13      else if ( smp_num_cpus != 1 )
    2.14          panic("We really need local APICs on SMP machines!");
    2.15 +    else
    2.16 +        do_timer_lists_from_pit = 1;
    2.17  
    2.18      ac_timer_init();    /* init accurate timers */
    2.19      init_xeno_time();	/* initialise the time */
     3.1 --- a/xen/arch/i386/time.c	Thu Sep 04 15:55:41 2003 +0000
     3.2 +++ b/xen/arch/i386/time.c	Thu Sep 04 16:24:41 2003 +0000
     3.3 @@ -49,6 +49,7 @@ unsigned long cpu_khz;  /* Detected as w
     3.4  unsigned long ticks_per_usec; /* TSC ticks per microsecond. */
     3.5  spinlock_t rtc_lock = SPIN_LOCK_UNLOCKED;
     3.6  int timer_ack = 0;
     3.7 +int do_timer_lists_from_pit = 0;
     3.8  
     3.9  /* PRIVATE */
    3.10  
    3.11 @@ -92,8 +93,11 @@ static inline void do_timer_interrupt(
    3.12          spin_unlock(&i8259A_lock);
    3.13      }
    3.14  #endif
    3.15 +
    3.16      do_timer(regs);
    3.17 -    do_ac_timer();
    3.18 +
    3.19 +    if ( do_timer_lists_from_pit )
    3.20 +        do_ac_timer();
    3.21  }
    3.22  
    3.23  /*
     4.1 --- a/xen/drivers/net/8139too.c	Thu Sep 04 15:55:41 2003 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,2671 +0,0 @@
     4.4 -/*
     4.5 -
     4.6 -	8139too.c: A RealTek RTL-8139 Fast Ethernet driver for Linux.
     4.7 -
     4.8 -	Maintained by Jeff Garzik <jgarzik@pobox.com>
     4.9 -	Copyright 2000-2002 Jeff Garzik
    4.10 -
    4.11 -	Much code comes from Donald Becker's rtl8139.c driver,
    4.12 -	versions 1.13 and older.  This driver was originally based
    4.13 -	on rtl8139.c version 1.07.  Header of rtl8139.c version 1.13:
    4.14 -
    4.15 -	-----<snip>-----
    4.16 -
    4.17 -        	Written 1997-2001 by Donald Becker.
    4.18 -		This software may be used and distributed according to the
    4.19 -		terms of the GNU General Public License (GPL), incorporated
    4.20 -		herein by reference.  Drivers based on or derived from this
    4.21 -		code fall under the GPL and must retain the authorship,
    4.22 -		copyright and license notice.  This file is not a complete
    4.23 -		program and may only be used when the entire operating
    4.24 -		system is licensed under the GPL.
    4.25 -
    4.26 -		This driver is for boards based on the RTL8129 and RTL8139
    4.27 -		PCI ethernet chips.
    4.28 -
    4.29 -		The author may be reached as becker@scyld.com, or C/O Scyld
    4.30 -		Computing Corporation 410 Severn Ave., Suite 210 Annapolis
    4.31 -		MD 21403
    4.32 -
    4.33 -		Support and updates available at
    4.34 -		http://www.scyld.com/network/rtl8139.html
    4.35 -
    4.36 -		Twister-tuning table provided by Kinston
    4.37 -		<shangh@realtek.com.tw>.
    4.38 -
    4.39 -	-----<snip>-----
    4.40 -
    4.41 -	This software may be used and distributed according to the terms
    4.42 -	of the GNU General Public License, incorporated herein by reference.
    4.43 -
    4.44 -	Contributors:
    4.45 -
    4.46 -		Donald Becker - he wrote the original driver, kudos to him!
    4.47 -		(but please don't e-mail him for support, this isn't his driver)
    4.48 -
    4.49 -		Tigran Aivazian - bug fixes, skbuff free cleanup
    4.50 -
    4.51 -		Martin Mares - suggestions for PCI cleanup
    4.52 -
    4.53 -		David S. Miller - PCI DMA and softnet updates
    4.54 -
    4.55 -		Ernst Gill - fixes ported from BSD driver
    4.56 -
    4.57 -		Daniel Kobras - identified specific locations of
    4.58 -			posted MMIO write bugginess
    4.59 -
    4.60 -		Gerard Sharp - bug fix, testing and feedback
    4.61 -
    4.62 -		David Ford - Rx ring wrap fix
    4.63 -
    4.64 -		Dan DeMaggio - swapped RTL8139 cards with me, and allowed me
    4.65 -		to find and fix a crucial bug on older chipsets.
    4.66 -
    4.67 -		Donald Becker/Chris Butterworth/Marcus Westergren -
    4.68 -		Noticed various Rx packet size-related buglets.
    4.69 -
    4.70 -		Santiago Garcia Mantinan - testing and feedback
    4.71 -
    4.72 -		Jens David - 2.2.x kernel backports
    4.73 -
    4.74 -		Martin Dennett - incredibly helpful insight on undocumented
    4.75 -		features of the 8139 chips
    4.76 -
    4.77 -		Jean-Jacques Michel - bug fix
    4.78 -
    4.79 -		Tobias Ringström - Rx interrupt status checking suggestion
    4.80 -
    4.81 -		Andrew Morton - Clear blocked signals, avoid
    4.82 -		buffer overrun setting current->comm.
    4.83 -
    4.84 -		Kalle Olavi Niemitalo - Wake-on-LAN ioctls
    4.85 -
    4.86 -		Robert Kuebel - Save kernel thread from dying on any signal.
    4.87 -
    4.88 -	Submitting bug reports:
    4.89 -
    4.90 -		"rtl8139-diag -mmmaaavvveefN" output
    4.91 -		enable RTL8139_DEBUG below, and look at 'dmesg' or kernel log
    4.92 -
    4.93 -		See 8139too.txt for more details.
    4.94 -
    4.95 -*/
    4.96 -
    4.97 -#define DRV_NAME	"8139too"
    4.98 -#define DRV_VERSION	"0.9.26"
    4.99 -
   4.100 -#include <linux/config.h>
   4.101 -#include <linux/module.h>
   4.102 -#include <linux/kernel.h>
   4.103 -#include <linux/lib.h>
   4.104 -#include <linux/timer.h>
   4.105 -#include <linux/pci.h>
   4.106 -#include <linux/init.h>
   4.107 -#include <linux/ioport.h>
   4.108 -#include <linux/netdevice.h>
   4.109 -#include <linux/etherdevice.h>
   4.110 -#include <linux/delay.h>
   4.111 -#include <linux/ethtool.h>
   4.112 -#include <linux/mii.h>
   4.113 -#include <linux/crc32.h>
   4.114 -#include <asm/io.h>
   4.115 -#include <asm/uaccess.h>
   4.116 -
   4.117 -/* This must be global for CONFIG_8139TOO_TUNE_TWISTER case */
   4.118 -static int next_tick = 3 * HZ;
   4.119 -
   4.120 -#define RTL8139_DRIVER_NAME   DRV_NAME " Fast Ethernet driver " DRV_VERSION
   4.121 -#define PFX DRV_NAME ": "
   4.122 -
   4.123 -
   4.124 -/* enable PIO instead of MMIO, if CONFIG_8139TOO_PIO is selected */
   4.125 -#ifdef CONFIG_8139TOO_PIO
   4.126 -#define USE_IO_OPS 1
   4.127 -#endif
   4.128 -
   4.129 -/* define to 1 to enable copious debugging info */
   4.130 -#undef RTL8139_DEBUG
   4.131 -
   4.132 -/* define to 1 to disable lightweight runtime debugging checks */
   4.133 -#undef RTL8139_NDEBUG
   4.134 -
   4.135 -
   4.136 -#ifdef RTL8139_DEBUG
   4.137 -/* note: prints function name for you */
   4.138 -#  define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
   4.139 -#else
   4.140 -#  define DPRINTK(fmt, args...)
   4.141 -#endif
   4.142 -
   4.143 -#ifdef RTL8139_NDEBUG
   4.144 -#  define assert(expr) do {} while (0)
   4.145 -#else
   4.146 -#  define assert(expr) \
   4.147 -        if(!(expr)) {					\
   4.148 -        printk( "Assertion failed! %s,%s,%s,line=%d\n",	\
   4.149 -        #expr,__FILE__,__FUNCTION__,__LINE__);		\
   4.150 -        }
   4.151 -#endif
   4.152 -
   4.153 -
   4.154 -/* A few user-configurable values. */
   4.155 -/* media options */
   4.156 -#define MAX_UNITS 8
   4.157 -static int media[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
   4.158 -static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
   4.159 -
   4.160 -/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
   4.161 -static int max_interrupt_work = 20;
   4.162 -
   4.163 -/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
   4.164 -   The RTL chips use a 64 element hash table based on the Ethernet CRC.  */
   4.165 -static int multicast_filter_limit = 32;
   4.166 -
   4.167 -#if 0
   4.168 -/* bitmapped message enable number */
   4.169 -static int debug = -1;
   4.170 -#endif
   4.171 -
   4.172 -/* Size of the in-memory receive ring. */
   4.173 -#define RX_BUF_LEN_IDX	2	/* 0==8K, 1==16K, 2==32K, 3==64K */
   4.174 -#define RX_BUF_LEN	(8192 << RX_BUF_LEN_IDX)
   4.175 -#define RX_BUF_PAD	16
   4.176 -#define RX_BUF_WRAP_PAD 2048 /* spare padding to handle lack of packet wrap */
   4.177 -#define RX_BUF_TOT_LEN	(RX_BUF_LEN + RX_BUF_PAD + RX_BUF_WRAP_PAD)
   4.178 -
   4.179 -/* Number of Tx descriptor registers. */
   4.180 -#define NUM_TX_DESC	4
   4.181 -
   4.182 -/* max supported ethernet frame size -- must be at least (dev->mtu+14+4).*/
   4.183 -#define MAX_ETH_FRAME_SIZE	1536
   4.184 -
   4.185 -/* Size of the Tx bounce buffers -- must be at least (dev->mtu+14+4). */
   4.186 -#define TX_BUF_SIZE	MAX_ETH_FRAME_SIZE
   4.187 -#define TX_BUF_TOT_LEN	(TX_BUF_SIZE * NUM_TX_DESC)
   4.188 -
   4.189 -/* PCI Tuning Parameters
   4.190 -   Threshold is bytes transferred to chip before transmission starts. */
   4.191 -#define TX_FIFO_THRESH 256	/* In bytes, rounded down to 32 byte units. */
   4.192 -
   4.193 -/* The following settings are log_2(bytes)-4:  0 == 16 bytes .. 6==1024, 7==end of packet. */
   4.194 -#define RX_FIFO_THRESH	7	/* Rx buffer level before first PCI xfer.  */
   4.195 -#define RX_DMA_BURST	7	/* Maximum PCI burst, '6' is 1024 */
   4.196 -#define TX_DMA_BURST	6	/* Maximum PCI burst, '6' is 1024 */
   4.197 -#define TX_RETRY	8	/* 0-15.  retries = 16 + (TX_RETRY * 16) */
   4.198 -
   4.199 -/* Operational parameters that usually are not changed. */
   4.200 -/* Time in jiffies before concluding the transmitter is hung. */
   4.201 -#define TX_TIMEOUT  (6*HZ)
   4.202 -
   4.203 -
   4.204 -enum {
   4.205 -	HAS_MII_XCVR = 0x010000,
   4.206 -	HAS_CHIP_XCVR = 0x020000,
   4.207 -	HAS_LNK_CHNG = 0x040000,
   4.208 -};
   4.209 -
   4.210 -#define RTL_NUM_STATS 4		/* number of ETHTOOL_GSTATS u64's */
   4.211 -#define RTL_REGS_VER 1		/* version of reg. data in ETHTOOL_GREGS */
   4.212 -#define RTL_MIN_IO_SIZE 0x80
   4.213 -#define RTL8139B_IO_SIZE 256
   4.214 -
   4.215 -#define RTL8129_CAPS	HAS_MII_XCVR
   4.216 -#define RTL8139_CAPS	HAS_CHIP_XCVR|HAS_LNK_CHNG
   4.217 -
   4.218 -typedef enum {
   4.219 -	RTL8139 = 0,
   4.220 -	RTL8139_CB,
   4.221 -	SMC1211TX,
   4.222 -	/*MPX5030,*/
   4.223 -	DELTA8139,
   4.224 -	ADDTRON8139,
   4.225 -	DFE538TX,
   4.226 -	DFE690TXD,
   4.227 -	FE2000VX,
   4.228 -	ALLIED8139,
   4.229 -	RTL8129,
   4.230 -	FNW3603TX,
   4.231 -	FNW3800TX,
   4.232 -} board_t;
   4.233 -
   4.234 -
   4.235 -/* indexed by board_t, above */
   4.236 -static struct {
   4.237 -	const char *name;
   4.238 -	u32 hw_flags;
   4.239 -} board_info[] __devinitdata = {
   4.240 -	{ "RealTek RTL8139 Fast Ethernet", RTL8139_CAPS },
   4.241 -	{ "RealTek RTL8139B PCI/CardBus", RTL8139_CAPS },
   4.242 -	{ "SMC1211TX EZCard 10/100 (RealTek RTL8139)", RTL8139_CAPS },
   4.243 -/*	{ MPX5030, "Accton MPX5030 (RealTek RTL8139)", RTL8139_CAPS },*/
   4.244 -	{ "Delta Electronics 8139 10/100BaseTX", RTL8139_CAPS },
   4.245 -	{ "Addtron Technolgy 8139 10/100BaseTX", RTL8139_CAPS },
   4.246 -	{ "D-Link DFE-538TX (RealTek RTL8139)", RTL8139_CAPS },
   4.247 -	{ "D-Link DFE-690TXD (RealTek RTL8139)", RTL8139_CAPS },
   4.248 -	{ "AboCom FE2000VX (RealTek RTL8139)", RTL8139_CAPS },
   4.249 -	{ "Allied Telesyn 8139 CardBus", RTL8139_CAPS },
   4.250 -	{ "RealTek RTL8129", RTL8129_CAPS },
   4.251 -	{ "Planex FNW-3603-TX 10/100 CardBus", RTL8139_CAPS },
   4.252 -	{ "Planex FNW-3800-TX 10/100 CardBus", RTL8139_CAPS },
   4.253 -};
   4.254 -
   4.255 -
   4.256 -static struct pci_device_id rtl8139_pci_tbl[] __devinitdata = {
   4.257 -	{0x10ec, 0x8139, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 },
   4.258 -	{0x10ec, 0x8138, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139_CB },
   4.259 -	{0x1113, 0x1211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SMC1211TX },
   4.260 -/*	{0x1113, 0x1211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MPX5030 },*/
   4.261 -	{0x1500, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DELTA8139 },
   4.262 -	{0x4033, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ADDTRON8139 },
   4.263 -	{0x1186, 0x1300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DFE538TX },
   4.264 -	{0x1186, 0x1340, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DFE690TXD },
   4.265 -	{0x13d1, 0xab06, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FE2000VX },
   4.266 -	{0x1259, 0xa117, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ALLIED8139 },
   4.267 -	{0x14ea, 0xab06, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FNW3603TX },
   4.268 -	{0x14ea, 0xab07, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FNW3800TX },
   4.269 -
   4.270 -#ifdef CONFIG_8139TOO_8129
   4.271 -	{0x10ec, 0x8129, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8129 },
   4.272 -#endif
   4.273 -
   4.274 -	/* some crazy cards report invalid vendor ids like
   4.275 -	 * 0x0001 here.  The other ids are valid and constant,
   4.276 -	 * so we simply don't match on the main vendor id.
   4.277 -	 */
   4.278 -	{PCI_ANY_ID, 0x8139, 0x10ec, 0x8139, 0, 0, RTL8139 },
   4.279 -	{PCI_ANY_ID, 0x8139, 0x1186, 0x1300, 0, 0, DFE538TX },
   4.280 -	{PCI_ANY_ID, 0x8139, 0x13d1, 0xab06, 0, 0, FE2000VX },
   4.281 -
   4.282 -	{0,}
   4.283 -};
   4.284 -MODULE_DEVICE_TABLE (pci, rtl8139_pci_tbl);
   4.285 -
   4.286 -#if 0
   4.287 -static struct {
   4.288 -	const char str[ETH_GSTRING_LEN];
   4.289 -} ethtool_stats_keys[] = {
   4.290 -	{ "early_rx" },
   4.291 -	{ "tx_buf_mapped" },
   4.292 -	{ "tx_timeouts" },
   4.293 -	{ "rx_lost_in_ring" },
   4.294 -};
   4.295 -#endif
   4.296 -
   4.297 -/* The rest of these values should never change. */
   4.298 -
   4.299 -/* Symbolic offsets to registers. */
   4.300 -enum RTL8139_registers {
   4.301 -	MAC0 = 0,		/* Ethernet hardware address. */
   4.302 -	MAR0 = 8,		/* Multicast filter. */
   4.303 -	TxStatus0 = 0x10,	/* Transmit status (Four 32bit registers). */
   4.304 -	TxAddr0 = 0x20,		/* Tx descriptors (also four 32bit). */
   4.305 -	RxBuf = 0x30,
   4.306 -	ChipCmd = 0x37,
   4.307 -	RxBufPtr = 0x38,
   4.308 -	RxBufAddr = 0x3A,
   4.309 -	IntrMask = 0x3C,
   4.310 -	IntrStatus = 0x3E,
   4.311 -	TxConfig = 0x40,
   4.312 -	ChipVersion = 0x43,
   4.313 -	RxConfig = 0x44,
   4.314 -	Timer = 0x48,		/* A general-purpose counter. */
   4.315 -	RxMissed = 0x4C,	/* 24 bits valid, write clears. */
   4.316 -	Cfg9346 = 0x50,
   4.317 -	Config0 = 0x51,
   4.318 -	Config1 = 0x52,
   4.319 -	FlashReg = 0x54,
   4.320 -	MediaStatus = 0x58,
   4.321 -	Config3 = 0x59,
   4.322 -	Config4 = 0x5A,		/* absent on RTL-8139A */
   4.323 -	HltClk = 0x5B,
   4.324 -	MultiIntr = 0x5C,
   4.325 -	TxSummary = 0x60,
   4.326 -	BasicModeCtrl = 0x62,
   4.327 -	BasicModeStatus = 0x64,
   4.328 -	NWayAdvert = 0x66,
   4.329 -	NWayLPAR = 0x68,
   4.330 -	NWayExpansion = 0x6A,
   4.331 -	/* Undocumented registers, but required for proper operation. */
   4.332 -	FIFOTMS = 0x70,		/* FIFO Control and test. */
   4.333 -	CSCR = 0x74,		/* Chip Status and Configuration Register. */
   4.334 -	PARA78 = 0x78,
   4.335 -	PARA7c = 0x7c,		/* Magic transceiver parameter register. */
   4.336 -	Config5 = 0xD8,		/* absent on RTL-8139A */
   4.337 -};
   4.338 -
   4.339 -enum ClearBitMasks {
   4.340 -	MultiIntrClear = 0xF000,
   4.341 -	ChipCmdClear = 0xE2,
   4.342 -	Config1Clear = (1<<7)|(1<<6)|(1<<3)|(1<<2)|(1<<1),
   4.343 -};
   4.344 -
   4.345 -enum ChipCmdBits {
   4.346 -	CmdReset = 0x10,
   4.347 -	CmdRxEnb = 0x08,
   4.348 -	CmdTxEnb = 0x04,
   4.349 -	RxBufEmpty = 0x01,
   4.350 -};
   4.351 -
   4.352 -/* Interrupt register bits, using my own meaningful names. */
   4.353 -enum IntrStatusBits {
   4.354 -	PCIErr = 0x8000,
   4.355 -	PCSTimeout = 0x4000,
   4.356 -	RxFIFOOver = 0x40,
   4.357 -	RxUnderrun = 0x20,
   4.358 -	RxOverflow = 0x10,
   4.359 -	TxErr = 0x08,
   4.360 -	TxOK = 0x04,
   4.361 -	RxErr = 0x02,
   4.362 -	RxOK = 0x01,
   4.363 -
   4.364 -	RxAckBits = RxFIFOOver | RxOverflow | RxOK,
   4.365 -};
   4.366 -
   4.367 -enum TxStatusBits {
   4.368 -	TxHostOwns = 0x2000,
   4.369 -	TxUnderrun = 0x4000,
   4.370 -	TxStatOK = 0x8000,
   4.371 -	TxOutOfWindow = 0x20000000,
   4.372 -	TxAborted = 0x40000000,
   4.373 -	TxCarrierLost = 0x80000000,
   4.374 -};
   4.375 -enum RxStatusBits {
   4.376 -	RxMulticast = 0x8000,
   4.377 -	RxPhysical = 0x4000,
   4.378 -	RxBroadcast = 0x2000,
   4.379 -	RxBadSymbol = 0x0020,
   4.380 -	RxRunt = 0x0010,
   4.381 -	RxTooLong = 0x0008,
   4.382 -	RxCRCErr = 0x0004,
   4.383 -	RxBadAlign = 0x0002,
   4.384 -	RxStatusOK = 0x0001,
   4.385 -};
   4.386 -
   4.387 -/* Bits in RxConfig. */
   4.388 -enum rx_mode_bits {
   4.389 -	AcceptErr = 0x20,
   4.390 -	AcceptRunt = 0x10,
   4.391 -	AcceptBroadcast = 0x08,
   4.392 -	AcceptMulticast = 0x04,
   4.393 -	AcceptMyPhys = 0x02,
   4.394 -	AcceptAllPhys = 0x01,
   4.395 -};
   4.396 -
   4.397 -/* Bits in TxConfig. */
   4.398 -enum tx_config_bits {
   4.399 -	TxIFG1 = (1 << 25),	/* Interframe Gap Time */
   4.400 -	TxIFG0 = (1 << 24),	/* Enabling these bits violates IEEE 802.3 */
   4.401 -	TxLoopBack = (1 << 18) | (1 << 17), /* enable loopback test mode */
   4.402 -	TxCRC = (1 << 16),	/* DISABLE appending CRC to end of Tx packets */
   4.403 -	TxClearAbt = (1 << 0),	/* Clear abort (WO) */
   4.404 -	TxDMAShift = 8,		/* DMA burst value (0-7) is shifted this many bits */
   4.405 -	TxRetryShift = 4,	/* TXRR value (0-15) is shifted this many bits */
   4.406 -
   4.407 -	TxVersionMask = 0x7C800000, /* mask out version bits 30-26, 23 */
   4.408 -};
   4.409 -
   4.410 -/* Bits in Config1 */
   4.411 -enum Config1Bits {
   4.412 -	Cfg1_PM_Enable = 0x01,
   4.413 -	Cfg1_VPD_Enable = 0x02,
   4.414 -	Cfg1_PIO = 0x04,
   4.415 -	Cfg1_MMIO = 0x08,
   4.416 -	LWAKE = 0x10,		/* not on 8139, 8139A */
   4.417 -	Cfg1_Driver_Load = 0x20,
   4.418 -	Cfg1_LED0 = 0x40,
   4.419 -	Cfg1_LED1 = 0x80,
   4.420 -	SLEEP = (1 << 1),	/* only on 8139, 8139A */
   4.421 -	PWRDN = (1 << 0),	/* only on 8139, 8139A */
   4.422 -};
   4.423 -
   4.424 -/* Bits in Config3 */
   4.425 -enum Config3Bits {
   4.426 -	Cfg3_FBtBEn    = (1 << 0), /* 1 = Fast Back to Back */
   4.427 -	Cfg3_FuncRegEn = (1 << 1), /* 1 = enable CardBus Function registers */
   4.428 -	Cfg3_CLKRUN_En = (1 << 2), /* 1 = enable CLKRUN */
   4.429 -	Cfg3_CardB_En  = (1 << 3), /* 1 = enable CardBus registers */
   4.430 -	Cfg3_LinkUp    = (1 << 4), /* 1 = wake up on link up */
   4.431 -	Cfg3_Magic     = (1 << 5), /* 1 = wake up on Magic Packet (tm) */
   4.432 -	Cfg3_PARM_En   = (1 << 6), /* 0 = software can set twister parameters */
   4.433 -	Cfg3_GNTSel    = (1 << 7), /* 1 = delay 1 clock from PCI GNT signal */
   4.434 -};
   4.435 -
   4.436 -/* Bits in Config4 */
   4.437 -enum Config4Bits {
   4.438 -	LWPTN = (1 << 2),	/* not on 8139, 8139A */
   4.439 -};
   4.440 -
   4.441 -/* Bits in Config5 */
   4.442 -enum Config5Bits {
   4.443 -	Cfg5_PME_STS     = (1 << 0), /* 1 = PCI reset resets PME_Status */
   4.444 -	Cfg5_LANWake     = (1 << 1), /* 1 = enable LANWake signal */
   4.445 -	Cfg5_LDPS        = (1 << 2), /* 0 = save power when link is down */
   4.446 -	Cfg5_FIFOAddrPtr = (1 << 3), /* Realtek internal SRAM testing */
   4.447 -	Cfg5_UWF         = (1 << 4), /* 1 = accept unicast wakeup frame */
   4.448 -	Cfg5_MWF         = (1 << 5), /* 1 = accept multicast wakeup frame */
   4.449 -	Cfg5_BWF         = (1 << 6), /* 1 = accept broadcast wakeup frame */
   4.450 -};
   4.451 -
   4.452 -enum RxConfigBits {
   4.453 -	/* rx fifo threshold */
   4.454 -	RxCfgFIFOShift = 13,
   4.455 -	RxCfgFIFONone = (7 << RxCfgFIFOShift),
   4.456 -
   4.457 -	/* Max DMA burst */
   4.458 -	RxCfgDMAShift = 8,
   4.459 -	RxCfgDMAUnlimited = (7 << RxCfgDMAShift),
   4.460 -
   4.461 -	/* rx ring buffer length */
   4.462 -	RxCfgRcv8K = 0,
   4.463 -	RxCfgRcv16K = (1 << 11),
   4.464 -	RxCfgRcv32K = (1 << 12),
   4.465 -	RxCfgRcv64K = (1 << 11) | (1 << 12),
   4.466 -
   4.467 -	/* Disable packet wrap at end of Rx buffer */
   4.468 -	RxNoWrap = (1 << 7),
   4.469 -};
   4.470 -
   4.471 -
   4.472 -/* Twister tuning parameters from RealTek.
   4.473 -   Completely undocumented, but required to tune bad links on some boards. */
   4.474 -enum CSCRBits {
   4.475 -	CSCR_LinkOKBit = 0x0400,
   4.476 -	CSCR_LinkChangeBit = 0x0800,
   4.477 -	CSCR_LinkStatusBits = 0x0f000,
   4.478 -	CSCR_LinkDownOffCmd = 0x003c0,
   4.479 -	CSCR_LinkDownCmd = 0x0f3c0,
   4.480 -};
   4.481 -
   4.482 -
   4.483 -enum Cfg9346Bits {
   4.484 -	Cfg9346_Lock = 0x00,
   4.485 -	Cfg9346_Unlock = 0xC0,
   4.486 -};
   4.487 -
   4.488 -#ifdef CONFIG_8139TOO_TUNE_TWISTER
   4.489 -
   4.490 -enum TwisterParamVals {
   4.491 -	PARA78_default	= 0x78fa8388,
   4.492 -	PARA7c_default	= 0xcb38de43,	/* param[0][3] */
   4.493 -	PARA7c_xxx	= 0xcb38de43,
   4.494 -};
   4.495 -
   4.496 -static const unsigned long param[4][4] = {
   4.497 -	{0xcb39de43, 0xcb39ce43, 0xfb38de03, 0xcb38de43},
   4.498 -	{0xcb39de43, 0xcb39ce43, 0xcb39ce83, 0xcb39ce83},
   4.499 -	{0xcb39de43, 0xcb39ce43, 0xcb39ce83, 0xcb39ce83},
   4.500 -	{0xbb39de43, 0xbb39ce43, 0xbb39ce83, 0xbb39ce83}
   4.501 -};
   4.502 -
   4.503 -#endif /* CONFIG_8139TOO_TUNE_TWISTER */
   4.504 -
   4.505 -typedef enum {
   4.506 -	CH_8139 = 0,
   4.507 -	CH_8139_K,
   4.508 -	CH_8139A,
   4.509 -	CH_8139B,
   4.510 -	CH_8130,
   4.511 -	CH_8139C,
   4.512 -} chip_t;
   4.513 -
   4.514 -enum chip_flags {
   4.515 -	HasHltClk = (1 << 0),
   4.516 -	HasLWake = (1 << 1),
   4.517 -};
   4.518 -
   4.519 -
   4.520 -/* directly indexed by chip_t, above */
   4.521 -const static struct {
   4.522 -	const char *name;
   4.523 -	u8 version; /* from RTL8139C docs */
   4.524 -	u32 RxConfigMask; /* should clear the bits supported by this chip */
   4.525 -	u32 flags;
   4.526 -} rtl_chip_info[] = {
   4.527 -	{ "RTL-8139",
   4.528 -	  0x40,
   4.529 -	  0xf0fe0040, /* XXX copied from RTL8139A, verify */
   4.530 -	  HasHltClk,
   4.531 -	},
   4.532 -
   4.533 -	{ "RTL-8139 rev K",
   4.534 -	  0x60,
   4.535 -	  0xf0fe0040,
   4.536 -	  HasHltClk,
   4.537 -	},
   4.538 -
   4.539 -	{ "RTL-8139A",
   4.540 -	  0x70,
   4.541 -	  0xf0fe0040,
   4.542 -	  HasHltClk, /* XXX undocumented? */
   4.543 -	},
   4.544 -
   4.545 -	{ "RTL-8139B",
   4.546 -	  0x78,
   4.547 -	  0xf0fc0040,
   4.548 -	  HasLWake,
   4.549 -	},
   4.550 -
   4.551 -	{ "RTL-8130",
   4.552 -	  0x7C,
   4.553 -	  0xf0fe0040, /* XXX copied from RTL8139A, verify */
   4.554 -	  HasLWake,
   4.555 -	},
   4.556 -
   4.557 -	{ "RTL-8139C",
   4.558 -	  0x74,
   4.559 -	  0xf0fc0040, /* XXX copied from RTL8139B, verify */
   4.560 -	  HasLWake,
   4.561 -	},
   4.562 -
   4.563 -};
   4.564 -
   4.565 -struct rtl_extra_stats {
   4.566 -	unsigned long early_rx;
   4.567 -	unsigned long tx_buf_mapped;
   4.568 -	unsigned long tx_timeouts;
   4.569 -	unsigned long rx_lost_in_ring;
   4.570 -};
   4.571 -
   4.572 -struct rtl8139_private {
   4.573 -	void *mmio_addr;
   4.574 -	int drv_flags;
   4.575 -	struct pci_dev *pci_dev;
   4.576 -	struct net_device_stats stats;
   4.577 -	unsigned char *rx_ring;
   4.578 -	unsigned int cur_rx;	/* Index into the Rx buffer of next Rx pkt. */
   4.579 -	unsigned int tx_flag;
   4.580 -	unsigned long cur_tx;
   4.581 -	unsigned long dirty_tx;
   4.582 -	unsigned char *tx_buf[NUM_TX_DESC];	/* Tx bounce buffers */
   4.583 -	unsigned char *tx_bufs;	/* Tx bounce buffer region. */
   4.584 -	dma_addr_t rx_ring_dma;
   4.585 -	dma_addr_t tx_bufs_dma;
   4.586 -	signed char phys[4];		/* MII device addresses. */
   4.587 -	char twistie, twist_row, twist_col;	/* Twister tune state. */
   4.588 -	unsigned int default_port:4;	/* Last dev->if_port value. */
   4.589 -	spinlock_t lock;
   4.590 -	chip_t chipset;
   4.591 -#if 0
   4.592 -	pid_t thr_pid;
   4.593 -	wait_queue_head_t thr_wait;
   4.594 -	struct completion thr_exited;
   4.595 -#else
   4.596 -	struct timer_list timer;
   4.597 -#endif
   4.598 -	u32 rx_config;
   4.599 -	struct rtl_extra_stats xstats;
   4.600 -	int time_to_die;
   4.601 -	struct mii_if_info mii;
   4.602 -	unsigned int regs_len;
   4.603 -};
   4.604 -
   4.605 -MODULE_AUTHOR ("Jeff Garzik <jgarzik@pobox.com>");
   4.606 -MODULE_DESCRIPTION ("RealTek RTL-8139 Fast Ethernet driver");
   4.607 -MODULE_LICENSE("GPL");
   4.608 -
   4.609 -MODULE_PARM (multicast_filter_limit, "i");
   4.610 -MODULE_PARM (max_interrupt_work, "i");
   4.611 -MODULE_PARM (media, "1-" __MODULE_STRING(MAX_UNITS) "i");
   4.612 -MODULE_PARM (full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
   4.613 -MODULE_PARM (debug, "i");
   4.614 -MODULE_PARM_DESC (debug, "8139too bitmapped message enable number");
   4.615 -MODULE_PARM_DESC (multicast_filter_limit, "8139too maximum number of filtered multicast addresses");
   4.616 -MODULE_PARM_DESC (max_interrupt_work, "8139too maximum events handled per interrupt");
   4.617 -MODULE_PARM_DESC (media, "8139too: Bits 4+9: force full duplex, bit 5: 100Mbps");
   4.618 -MODULE_PARM_DESC (full_duplex, "8139too: Force full duplex for board(s) (1)");
   4.619 -
   4.620 -static int read_eeprom (void *ioaddr, int location, int addr_len);
   4.621 -static int rtl8139_open (struct net_device *dev);
   4.622 -static int mdio_read (struct net_device *dev, int phy_id, int location);
   4.623 -static void mdio_write (struct net_device *dev, int phy_id, int location,
   4.624 -			int val);
   4.625 -#if 0
   4.626 -static int rtl8139_thread (void *data);
   4.627 -#else
   4.628 -static void rtl8139_timer (unsigned long arg);
   4.629 -#endif
   4.630 -static void rtl8139_tx_timeout (struct net_device *dev);
   4.631 -static void rtl8139_init_ring (struct net_device *dev);
   4.632 -static int rtl8139_start_xmit (struct sk_buff *skb,
   4.633 -			       struct net_device *dev);
   4.634 -static void rtl8139_interrupt (int irq, void *dev_instance,
   4.635 -			       struct pt_regs *regs);
   4.636 -static int rtl8139_close (struct net_device *dev);
   4.637 -#if 0
   4.638 -static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd);
   4.639 -#endif
   4.640 -static struct net_device_stats *rtl8139_get_stats (struct net_device *dev);
   4.641 -static void rtl8139_set_rx_mode (struct net_device *dev);
   4.642 -static void __set_rx_mode (struct net_device *dev);
   4.643 -static void rtl8139_hw_start (struct net_device *dev);
   4.644 -
   4.645 -#ifdef USE_IO_OPS
   4.646 -
   4.647 -#define RTL_R8(reg)		inb (((unsigned long)ioaddr) + (reg))
   4.648 -#define RTL_R16(reg)		inw (((unsigned long)ioaddr) + (reg))
   4.649 -#define RTL_R32(reg)		((unsigned long) inl (((unsigned long)ioaddr) + (reg)))
   4.650 -#define RTL_W8(reg, val8)	outb ((val8), ((unsigned long)ioaddr) + (reg))
   4.651 -#define RTL_W16(reg, val16)	outw ((val16), ((unsigned long)ioaddr) + (reg))
   4.652 -#define RTL_W32(reg, val32)	outl ((val32), ((unsigned long)ioaddr) + (reg))
   4.653 -#define RTL_W8_F		RTL_W8
   4.654 -#define RTL_W16_F		RTL_W16
   4.655 -#define RTL_W32_F		RTL_W32
   4.656 -#undef readb
   4.657 -#undef readw
   4.658 -#undef readl
   4.659 -#undef writeb
   4.660 -#undef writew
   4.661 -#undef writel
   4.662 -#define readb(addr) inb((unsigned long)(addr))
   4.663 -#define readw(addr) inw((unsigned long)(addr))
   4.664 -#define readl(addr) inl((unsigned long)(addr))
   4.665 -#define writeb(val,addr) outb((val),(unsigned long)(addr))
   4.666 -#define writew(val,addr) outw((val),(unsigned long)(addr))
   4.667 -#define writel(val,addr) outl((val),(unsigned long)(addr))
   4.668 -
   4.669 -#else
   4.670 -
   4.671 -/* write MMIO register, with flush */
   4.672 -/* Flush avoids rtl8139 bug w/ posted MMIO writes */
   4.673 -#define RTL_W8_F(reg, val8)	do { writeb ((val8), ioaddr + (reg)); readb (ioaddr + (reg)); } while (0)
   4.674 -#define RTL_W16_F(reg, val16)	do { writew ((val16), ioaddr + (reg)); readw (ioaddr + (reg)); } while (0)
   4.675 -#define RTL_W32_F(reg, val32)	do { writel ((val32), ioaddr + (reg)); readl (ioaddr + (reg)); } while (0)
   4.676 -
   4.677 -
   4.678 -#define MMIO_FLUSH_AUDIT_COMPLETE 1
   4.679 -#if MMIO_FLUSH_AUDIT_COMPLETE
   4.680 -
   4.681 -/* write MMIO register */
   4.682 -#define RTL_W8(reg, val8)	writeb ((val8), ioaddr + (reg))
   4.683 -#define RTL_W16(reg, val16)	writew ((val16), ioaddr + (reg))
   4.684 -#define RTL_W32(reg, val32)	writel ((val32), ioaddr + (reg))
   4.685 -
   4.686 -#else
   4.687 -
   4.688 -/* write MMIO register, then flush */
   4.689 -#define RTL_W8		RTL_W8_F
   4.690 -#define RTL_W16		RTL_W16_F
   4.691 -#define RTL_W32		RTL_W32_F
   4.692 -
   4.693 -#endif /* MMIO_FLUSH_AUDIT_COMPLETE */
   4.694 -
   4.695 -/* read MMIO register */
   4.696 -#define RTL_R8(reg)		readb (ioaddr + (reg))
   4.697 -#define RTL_R16(reg)		readw (ioaddr + (reg))
   4.698 -#define RTL_R32(reg)		((unsigned long) readl (ioaddr + (reg)))
   4.699 -
   4.700 -#endif /* USE_IO_OPS */
   4.701 -
   4.702 -
   4.703 -static const u16 rtl8139_intr_mask =
   4.704 -	PCIErr | PCSTimeout | RxUnderrun | RxOverflow | RxFIFOOver |
   4.705 -	TxErr | TxOK | RxErr | RxOK;
   4.706 -
   4.707 -static const unsigned int rtl8139_rx_config =
   4.708 -	RxCfgRcv32K | RxNoWrap |
   4.709 -	(RX_FIFO_THRESH << RxCfgFIFOShift) |
   4.710 -	(RX_DMA_BURST << RxCfgDMAShift);
   4.711 -
   4.712 -static const unsigned int rtl8139_tx_config =
   4.713 -	(TX_DMA_BURST << TxDMAShift) | (TX_RETRY << TxRetryShift);
   4.714 -
   4.715 -static void __rtl8139_cleanup_dev (struct net_device *dev)
   4.716 -{
   4.717 -	struct rtl8139_private *tp;
   4.718 -	struct pci_dev *pdev;
   4.719 -
   4.720 -	assert (dev != NULL);
   4.721 -	assert (dev->priv != NULL);
   4.722 -
   4.723 -	tp = dev->priv;
   4.724 -	assert (tp->pci_dev != NULL);
   4.725 -	pdev = tp->pci_dev;
   4.726 -
   4.727 -#ifndef USE_IO_OPS
   4.728 -	if (tp->mmio_addr)
   4.729 -		iounmap (tp->mmio_addr);
   4.730 -#endif /* !USE_IO_OPS */
   4.731 -
   4.732 -	/* it's ok to call this even if we have no regions to free */
   4.733 -	pci_release_regions (pdev);
   4.734 -
   4.735 -#ifndef RTL8139_NDEBUG
   4.736 -	/* poison memory before freeing */
   4.737 -	memset (dev, 0xBC,
   4.738 -		sizeof (struct net_device) +
   4.739 -		sizeof (struct rtl8139_private));
   4.740 -#endif /* RTL8139_NDEBUG */
   4.741 -
   4.742 -	kfree (dev);
   4.743 -
   4.744 -	pci_set_drvdata (pdev, NULL);
   4.745 -}
   4.746 -
   4.747 -
   4.748 -static void rtl8139_chip_reset (void *ioaddr)
   4.749 -{
   4.750 -	int i;
   4.751 -
   4.752 -	/* Soft reset the chip. */
   4.753 -	RTL_W8 (ChipCmd, CmdReset);
   4.754 -
   4.755 -	/* Check that the chip has finished the reset. */
   4.756 -	for (i = 1000; i > 0; i--) {
   4.757 -		barrier();
   4.758 -		if ((RTL_R8 (ChipCmd) & CmdReset) == 0)
   4.759 -			break;
   4.760 -		udelay (10);
   4.761 -	}
   4.762 -}
   4.763 -
   4.764 -
   4.765 -static int __devinit rtl8139_init_board (struct pci_dev *pdev,
   4.766 -					 struct net_device **dev_out)
   4.767 -{
   4.768 -	void *ioaddr;
   4.769 -	struct net_device *dev;
   4.770 -	struct rtl8139_private *tp;
   4.771 -	u8 tmp8;
   4.772 -	int rc;
   4.773 -	unsigned int i;
   4.774 -	u32 pio_start, pio_end, pio_flags, pio_len;
   4.775 -	unsigned long mmio_start, mmio_end, mmio_flags, mmio_len;
   4.776 -	u32 tmp;
   4.777 -
   4.778 -	assert (pdev != NULL);
   4.779 -
   4.780 -	*dev_out = NULL;
   4.781 -
   4.782 -	/* dev and dev->priv zeroed in alloc_etherdev */
   4.783 -	dev = alloc_etherdev (sizeof (*tp));
   4.784 -	if (dev == NULL) {
   4.785 -		printk (KERN_ERR PFX "%s: Unable to alloc new net device\n", pdev->slot_name);
   4.786 -		return -ENOMEM;
   4.787 -	}
   4.788 -	SET_MODULE_OWNER(dev);
   4.789 -	tp = dev->priv;
   4.790 -	tp->pci_dev = pdev;
   4.791 -
   4.792 -	/* enable device (incl. PCI PM wakeup and hotplug setup) */
   4.793 -	rc = pci_enable_device (pdev);
   4.794 -	if (rc)
   4.795 -		goto err_out;
   4.796 -
   4.797 -	pio_start = pci_resource_start (pdev, 0);
   4.798 -	pio_end = pci_resource_end (pdev, 0);
   4.799 -	pio_flags = pci_resource_flags (pdev, 0);
   4.800 -	pio_len = pci_resource_len (pdev, 0);
   4.801 -
   4.802 -	mmio_start = pci_resource_start (pdev, 1);
   4.803 -	mmio_end = pci_resource_end (pdev, 1);
   4.804 -	mmio_flags = pci_resource_flags (pdev, 1);
   4.805 -	mmio_len = pci_resource_len (pdev, 1);
   4.806 -
   4.807 -	/* set this immediately, we need to know before
   4.808 -	 * we talk to the chip directly */
   4.809 -	DPRINTK("PIO region size == 0x%02X\n", pio_len);
   4.810 -	DPRINTK("MMIO region size == 0x%02lX\n", mmio_len);
   4.811 -
   4.812 -#ifdef USE_IO_OPS
   4.813 -	/* make sure PCI base addr 0 is PIO */
   4.814 -	if (!(pio_flags & IORESOURCE_IO)) {
   4.815 -		printk (KERN_ERR PFX "%s: region #0 not a PIO resource, aborting\n", pdev->slot_name);
   4.816 -		rc = -ENODEV;
   4.817 -		goto err_out;
   4.818 -	}
   4.819 -	/* check for weird/broken PCI region reporting */
   4.820 -	if (pio_len < RTL_MIN_IO_SIZE) {
   4.821 -		printk (KERN_ERR PFX "%s: Invalid PCI I/O region size(s), aborting\n", pdev->slot_name);
   4.822 -		rc = -ENODEV;
   4.823 -		goto err_out;
   4.824 -	}
   4.825 -#else
   4.826 -	/* make sure PCI base addr 1 is MMIO */
   4.827 -	if (!(mmio_flags & IORESOURCE_MEM)) {
   4.828 -		printk (KERN_ERR PFX "%s: region #1 not an MMIO resource, aborting\n", pdev->slot_name);
   4.829 -		rc = -ENODEV;
   4.830 -		goto err_out;
   4.831 -	}
   4.832 -	if (mmio_len < RTL_MIN_IO_SIZE) {
   4.833 -		printk (KERN_ERR PFX "%s: Invalid PCI mem region size(s), aborting\n", pdev->slot_name);
   4.834 -		rc = -ENODEV;
   4.835 -		goto err_out;
   4.836 -	}
   4.837 -#endif
   4.838 -
   4.839 -	rc = pci_request_regions (pdev, "8139too");
   4.840 -	if (rc)
   4.841 -		goto err_out;
   4.842 -
   4.843 -	/* enable PCI bus-mastering */
   4.844 -	pci_set_master (pdev);
   4.845 -
   4.846 -#ifdef USE_IO_OPS
   4.847 -	ioaddr = (void *) pio_start;
   4.848 -	dev->base_addr = pio_start;
   4.849 -	tp->mmio_addr = ioaddr;
   4.850 -	tp->regs_len = pio_len;
   4.851 -#else
   4.852 -	/* ioremap MMIO region */
   4.853 -	ioaddr = ioremap (mmio_start, mmio_len);
   4.854 -	if (ioaddr == NULL) {
   4.855 -		printk (KERN_ERR PFX "%s: cannot remap MMIO, aborting\n", pdev->slot_name);
   4.856 -		rc = -EIO;
   4.857 -		goto err_out;
   4.858 -	}
   4.859 -	dev->base_addr = (long) ioaddr;
   4.860 -	tp->mmio_addr = ioaddr;
   4.861 -	tp->regs_len = mmio_len;
   4.862 -#endif /* USE_IO_OPS */
   4.863 -
   4.864 -	/* Bring old chips out of low-power mode. */
   4.865 -	RTL_W8 (HltClk, 'R');
   4.866 -
   4.867 -	/* check for missing/broken hardware */
   4.868 -	if (RTL_R32 (TxConfig) == 0xFFFFFFFF) {
   4.869 -		printk (KERN_ERR PFX "%s: Chip not responding, ignoring board\n",
   4.870 -			pdev->slot_name);
   4.871 -		rc = -EIO;
   4.872 -		goto err_out;
   4.873 -	}
   4.874 -
   4.875 -	/* identify chip attached to board */
   4.876 -	tmp = RTL_R8 (ChipVersion);
   4.877 -	for (i = 0; i < ARRAY_SIZE (rtl_chip_info); i++)
   4.878 -		if (tmp == rtl_chip_info[i].version) {
   4.879 -			tp->chipset = i;
   4.880 -			goto match;
   4.881 -		}
   4.882 -
   4.883 -	/* if unknown chip, assume array element #0, original RTL-8139 in this case */
   4.884 -	printk (KERN_DEBUG PFX "%s: unknown chip version, assuming RTL-8139\n",
   4.885 -		pdev->slot_name);
   4.886 -	printk (KERN_DEBUG PFX "%s: TxConfig = 0x%lx\n", pdev->slot_name, RTL_R32 (TxConfig));
   4.887 -	tp->chipset = 0;
   4.888 -
   4.889 -match:
   4.890 -	DPRINTK ("chipset id (%d) == index %d, '%s'\n",
   4.891 -		tmp,
   4.892 -		tp->chipset,
   4.893 -		rtl_chip_info[tp->chipset].name);
   4.894 -
   4.895 -	if (tp->chipset >= CH_8139B) {
   4.896 -		u8 new_tmp8 = tmp8 = RTL_R8 (Config1);
   4.897 -		DPRINTK("PCI PM wakeup\n");
   4.898 -		if ((rtl_chip_info[tp->chipset].flags & HasLWake) &&
   4.899 -		    (tmp8 & LWAKE))
   4.900 -			new_tmp8 &= ~LWAKE;
   4.901 -		new_tmp8 |= Cfg1_PM_Enable;
   4.902 -		if (new_tmp8 != tmp8) {
   4.903 -			RTL_W8 (Cfg9346, Cfg9346_Unlock);
   4.904 -			RTL_W8 (Config1, tmp8);
   4.905 -			RTL_W8 (Cfg9346, Cfg9346_Lock);
   4.906 -		}
   4.907 -		if (rtl_chip_info[tp->chipset].flags & HasLWake) {
   4.908 -			tmp8 = RTL_R8 (Config4);
   4.909 -			if (tmp8 & LWPTN)
   4.910 -				RTL_W8 (Config4, tmp8 & ~LWPTN);
   4.911 -		}
   4.912 -	} else {
   4.913 -		DPRINTK("Old chip wakeup\n");
   4.914 -		tmp8 = RTL_R8 (Config1);
   4.915 -		tmp8 &= ~(SLEEP | PWRDN);
   4.916 -		RTL_W8 (Config1, tmp8);
   4.917 -	}
   4.918 -
   4.919 -	rtl8139_chip_reset (ioaddr);
   4.920 -
   4.921 -	*dev_out = dev;
   4.922 -	return 0;
   4.923 -
   4.924 -err_out:
   4.925 -	__rtl8139_cleanup_dev (dev);
   4.926 -	return rc;
   4.927 -}
   4.928 -
   4.929 -
   4.930 -static int __devinit rtl8139_init_one (struct pci_dev *pdev,
   4.931 -				       const struct pci_device_id *ent)
   4.932 -{
   4.933 -	struct net_device *dev = NULL;
   4.934 -	struct rtl8139_private *tp;
   4.935 -	int i, addr_len, option;
   4.936 -	void *ioaddr;
   4.937 -	static int board_idx = -1;
   4.938 -	u8 pci_rev;
   4.939 -
   4.940 -	assert (pdev != NULL);
   4.941 -	assert (ent != NULL);
   4.942 -
   4.943 -	board_idx++;
   4.944 -
   4.945 -	/* when we're built into the kernel, the driver version message
   4.946 -	 * is only printed if at least one 8139 board has been found
   4.947 -	 */
   4.948 -#ifndef MODULE
   4.949 -	{
   4.950 -		static int printed_version;
   4.951 -		if (!printed_version++)
   4.952 -			printk (KERN_INFO RTL8139_DRIVER_NAME "\n");
   4.953 -	}
   4.954 -#endif
   4.955 -
   4.956 -	pci_read_config_byte(pdev, PCI_REVISION_ID, &pci_rev);
   4.957 -
   4.958 -	if (pdev->vendor == PCI_VENDOR_ID_REALTEK &&
   4.959 -	    pdev->device == PCI_DEVICE_ID_REALTEK_8139 && pci_rev >= 0x20) {
   4.960 -		printk(KERN_INFO PFX "pci dev %s (id %04x:%04x rev %02x) is an enhanced 8139C+ chip\n",
   4.961 -		       pdev->slot_name, pdev->vendor, pdev->device, pci_rev);
   4.962 -		printk(KERN_INFO PFX "Use the \"8139cp\" driver for improved performance and stability.\n");
   4.963 -	}
   4.964 -
   4.965 -	i = rtl8139_init_board (pdev, &dev);
   4.966 -	if (i < 0)
   4.967 -		return i;
   4.968 -
   4.969 -	tp = dev->priv;
   4.970 -	ioaddr = tp->mmio_addr;
   4.971 -
   4.972 -	assert (ioaddr != NULL);
   4.973 -	assert (dev != NULL);
   4.974 -	assert (tp != NULL);
   4.975 -
   4.976 -	addr_len = read_eeprom (ioaddr, 0, 8) == 0x8129 ? 8 : 6;
   4.977 -	for (i = 0; i < 3; i++)
   4.978 -		((u16 *) (dev->dev_addr))[i] =
   4.979 -		    le16_to_cpu (read_eeprom (ioaddr, i + 7, addr_len));
   4.980 -
   4.981 -	/* The Rtl8139-specific entries in the device structure. */
   4.982 -	dev->open = rtl8139_open;
   4.983 -	dev->hard_start_xmit = rtl8139_start_xmit;
   4.984 -	dev->stop = rtl8139_close;
   4.985 -	dev->get_stats = rtl8139_get_stats;
   4.986 -	dev->set_multicast_list = rtl8139_set_rx_mode;
   4.987 -#if 0
   4.988 -	dev->do_ioctl = netdev_ioctl;
   4.989 -#endif
   4.990 -	dev->tx_timeout = rtl8139_tx_timeout;
   4.991 -	dev->watchdog_timeo = TX_TIMEOUT;
   4.992 -
   4.993 -	/* note: the hardware is not capable of sg/csum/highdma, however
   4.994 -	 * through the use of skb_copy_and_csum_dev we enable these
   4.995 -	 * features
   4.996 -	 */
   4.997 -	dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_HIGHDMA;
   4.998 -
   4.999 -	dev->irq = pdev->irq;
  4.1000 -
  4.1001 -	/* dev->priv/tp zeroed and aligned in init_etherdev */
  4.1002 -	tp = dev->priv;
  4.1003 -
  4.1004 -	/* note: tp->chipset set in rtl8139_init_board */
  4.1005 -	tp->drv_flags = board_info[ent->driver_data].hw_flags;
  4.1006 -	tp->mmio_addr = ioaddr;
  4.1007 -	spin_lock_init (&tp->lock);
  4.1008 -#if 0
  4.1009 -	init_waitqueue_head (&tp->thr_wait);
  4.1010 -	init_completion (&tp->thr_exited);
  4.1011 -#endif
  4.1012 -	tp->mii.dev = dev;
  4.1013 -	tp->mii.mdio_read = mdio_read;
  4.1014 -	tp->mii.mdio_write = mdio_write;
  4.1015 -	tp->mii.phy_id_mask = 0x3f;
  4.1016 -	tp->mii.reg_num_mask = 0x1f;
  4.1017 -
  4.1018 -	/* dev is fully set up and ready to use now */
  4.1019 -	DPRINTK("about to register device named %s (%p)...\n", dev->name, dev);
  4.1020 -	i = register_netdev (dev);
  4.1021 -	if (i) goto err_out;
  4.1022 -
  4.1023 -	pci_set_drvdata (pdev, dev);
  4.1024 -
  4.1025 -	printk (KERN_INFO "%s: %s at 0x%lx, "
  4.1026 -		"%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, "
  4.1027 -		"IRQ %d\n",
  4.1028 -		dev->name,
  4.1029 -		board_info[ent->driver_data].name,
  4.1030 -		dev->base_addr,
  4.1031 -		dev->dev_addr[0], dev->dev_addr[1],
  4.1032 -		dev->dev_addr[2], dev->dev_addr[3],
  4.1033 -		dev->dev_addr[4], dev->dev_addr[5],
  4.1034 -		dev->irq);
  4.1035 -
  4.1036 -	printk (KERN_DEBUG "%s:  Identified 8139 chip type '%s'\n",
  4.1037 -		dev->name, rtl_chip_info[tp->chipset].name);
  4.1038 -
  4.1039 -	/* Find the connected MII xcvrs.
  4.1040 -	   Doing this in open() would allow detecting external xcvrs later, but
  4.1041 -	   takes too much time. */
  4.1042 -#ifdef CONFIG_8139TOO_8129
  4.1043 -	if (tp->drv_flags & HAS_MII_XCVR) {
  4.1044 -		int phy, phy_idx = 0;
  4.1045 -		for (phy = 0; phy < 32 && phy_idx < sizeof(tp->phys); phy++) {
  4.1046 -			int mii_status = mdio_read(dev, phy, 1);
  4.1047 -			if (mii_status != 0xffff  &&  mii_status != 0x0000) {
  4.1048 -				u16 advertising = mdio_read(dev, phy, 4);
  4.1049 -				tp->phys[phy_idx++] = phy;
  4.1050 -				printk(KERN_INFO "%s: MII transceiver %d status 0x%4.4x "
  4.1051 -					   "advertising %4.4x.\n",
  4.1052 -					   dev->name, phy, mii_status, advertising);
  4.1053 -			}
  4.1054 -		}
  4.1055 -		if (phy_idx == 0) {
  4.1056 -			printk(KERN_INFO "%s: No MII transceivers found!  Assuming SYM "
  4.1057 -				   "transceiver.\n",
  4.1058 -				   dev->name);
  4.1059 -			tp->phys[0] = 32;
  4.1060 -		}
  4.1061 -	} else
  4.1062 -#endif
  4.1063 -		tp->phys[0] = 32;
  4.1064 -	tp->mii.phy_id = tp->phys[0];
  4.1065 -
  4.1066 -	/* The lower four bits are the media type. */
  4.1067 -	option = (board_idx >= MAX_UNITS) ? 0 : media[board_idx];
  4.1068 -	if (option > 0) {
  4.1069 -		tp->mii.full_duplex = (option & 0x210) ? 1 : 0;
  4.1070 -		tp->default_port = option & 0xFF;
  4.1071 -		if (tp->default_port)
  4.1072 -			tp->mii.force_media = 1;
  4.1073 -	}
  4.1074 -	if (board_idx < MAX_UNITS  &&  full_duplex[board_idx] > 0)
  4.1075 -		tp->mii.full_duplex = full_duplex[board_idx];
  4.1076 -	if (tp->mii.full_duplex) {
  4.1077 -		printk(KERN_INFO "%s: Media type forced to Full Duplex.\n", dev->name);
  4.1078 -		/* Changing the MII-advertised media because might prevent
  4.1079 -		   re-connection. */
  4.1080 -		tp->mii.force_media = 1;
  4.1081 -	}
  4.1082 -	if (tp->default_port) {
  4.1083 -		printk(KERN_INFO "  Forcing %dMbps %s-duplex operation.\n",
  4.1084 -			   (option & 0x20 ? 100 : 10),
  4.1085 -			   (option & 0x10 ? "full" : "half"));
  4.1086 -		mdio_write(dev, tp->phys[0], 0,
  4.1087 -				   ((option & 0x20) ? 0x2000 : 0) | 	/* 100Mbps? */
  4.1088 -				   ((option & 0x10) ? 0x0100 : 0)); /* Full duplex? */
  4.1089 -	}
  4.1090 -
  4.1091 -	/* Put the chip into low-power mode. */
  4.1092 -	if (rtl_chip_info[tp->chipset].flags & HasHltClk)
  4.1093 -		RTL_W8 (HltClk, 'H');	/* 'R' would leave the clock running. */
  4.1094 -
  4.1095 -        alert_slow_netdevice(dev, (char *)board_info[ent->driver_data].name);
  4.1096 -
  4.1097 -	return 0;
  4.1098 -
  4.1099 -err_out:
  4.1100 -	__rtl8139_cleanup_dev (dev);
  4.1101 -	return i;
  4.1102 -}
  4.1103 -
  4.1104 -
  4.1105 -static void __devexit rtl8139_remove_one (struct pci_dev *pdev)
  4.1106 -{
  4.1107 -	struct net_device *dev = pci_get_drvdata (pdev);
  4.1108 -	struct rtl8139_private *np;
  4.1109 -
  4.1110 -	assert (dev != NULL);
  4.1111 -	np = dev->priv;
  4.1112 -	assert (np != NULL);
  4.1113 -
  4.1114 -	unregister_netdev (dev);
  4.1115 -
  4.1116 -	__rtl8139_cleanup_dev (dev);
  4.1117 -}
  4.1118 -
  4.1119 -
  4.1120 -/* Serial EEPROM section. */
  4.1121 -
  4.1122 -/*  EEPROM_Ctrl bits. */
  4.1123 -#define EE_SHIFT_CLK	0x04	/* EEPROM shift clock. */
  4.1124 -#define EE_CS			0x08	/* EEPROM chip select. */
  4.1125 -#define EE_DATA_WRITE	0x02	/* EEPROM chip data in. */
  4.1126 -#define EE_WRITE_0		0x00
  4.1127 -#define EE_WRITE_1		0x02
  4.1128 -#define EE_DATA_READ	0x01	/* EEPROM chip data out. */
  4.1129 -#define EE_ENB			(0x80 | EE_CS)
  4.1130 -
  4.1131 -/* Delay between EEPROM clock transitions.
  4.1132 -   No extra delay is needed with 33Mhz PCI, but 66Mhz may change this.
  4.1133 - */
  4.1134 -
  4.1135 -#define eeprom_delay()	readl(ee_addr)
  4.1136 -
  4.1137 -/* The EEPROM commands include the alway-set leading bit. */
  4.1138 -#define EE_WRITE_CMD	(5)
  4.1139 -#define EE_READ_CMD		(6)
  4.1140 -#define EE_ERASE_CMD	(7)
  4.1141 -
  4.1142 -static int __devinit read_eeprom (void *ioaddr, int location, int addr_len)
  4.1143 -{
  4.1144 -	int i;
  4.1145 -	unsigned retval = 0;
  4.1146 -	void *ee_addr = ioaddr + Cfg9346;
  4.1147 -	int read_cmd = location | (EE_READ_CMD << addr_len);
  4.1148 -
  4.1149 -	writeb (EE_ENB & ~EE_CS, ee_addr);
  4.1150 -	writeb (EE_ENB, ee_addr);
  4.1151 -	eeprom_delay ();
  4.1152 -
  4.1153 -	/* Shift the read command bits out. */
  4.1154 -	for (i = 4 + addr_len; i >= 0; i--) {
  4.1155 -		int dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
  4.1156 -		writeb (EE_ENB | dataval, ee_addr);
  4.1157 -		eeprom_delay ();
  4.1158 -		writeb (EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
  4.1159 -		eeprom_delay ();
  4.1160 -	}
  4.1161 -	writeb (EE_ENB, ee_addr);
  4.1162 -	eeprom_delay ();
  4.1163 -
  4.1164 -	for (i = 16; i > 0; i--) {
  4.1165 -		writeb (EE_ENB | EE_SHIFT_CLK, ee_addr);
  4.1166 -		eeprom_delay ();
  4.1167 -		retval =
  4.1168 -		    (retval << 1) | ((readb (ee_addr) & EE_DATA_READ) ? 1 :
  4.1169 -				     0);
  4.1170 -		writeb (EE_ENB, ee_addr);
  4.1171 -		eeprom_delay ();
  4.1172 -	}
  4.1173 -
  4.1174 -	/* Terminate the EEPROM access. */
  4.1175 -	writeb (~EE_CS, ee_addr);
  4.1176 -	eeprom_delay ();
  4.1177 -
  4.1178 -	return retval;
  4.1179 -}
  4.1180 -
  4.1181 -/* MII serial management: mostly bogus for now. */
  4.1182 -/* Read and write the MII management registers using software-generated
  4.1183 -   serial MDIO protocol.
  4.1184 -   The maximum data clock rate is 2.5 Mhz.  The minimum timing is usually
  4.1185 -   met by back-to-back PCI I/O cycles, but we insert a delay to avoid
  4.1186 -   "overclocking" issues. */
  4.1187 -#define MDIO_DIR		0x80
  4.1188 -#define MDIO_DATA_OUT	0x04
  4.1189 -#define MDIO_DATA_IN	0x02
  4.1190 -#define MDIO_CLK		0x01
  4.1191 -#define MDIO_WRITE0 (MDIO_DIR)
  4.1192 -#define MDIO_WRITE1 (MDIO_DIR | MDIO_DATA_OUT)
  4.1193 -
  4.1194 -#define mdio_delay(mdio_addr)	readb(mdio_addr)
  4.1195 -
  4.1196 -
  4.1197 -static char mii_2_8139_map[8] = {
  4.1198 -	BasicModeCtrl,
  4.1199 -	BasicModeStatus,
  4.1200 -	0,
  4.1201 -	0,
  4.1202 -	NWayAdvert,
  4.1203 -	NWayLPAR,
  4.1204 -	NWayExpansion,
  4.1205 -	0
  4.1206 -};
  4.1207 -
  4.1208 -
  4.1209 -#ifdef CONFIG_8139TOO_8129
  4.1210 -/* Syncronize the MII management interface by shifting 32 one bits out. */
  4.1211 -static void mdio_sync (void *mdio_addr)
  4.1212 -{
  4.1213 -	int i;
  4.1214 -
  4.1215 -	for (i = 32; i >= 0; i--) {
  4.1216 -		writeb (MDIO_WRITE1, mdio_addr);
  4.1217 -		mdio_delay (mdio_addr);
  4.1218 -		writeb (MDIO_WRITE1 | MDIO_CLK, mdio_addr);
  4.1219 -		mdio_delay (mdio_addr);
  4.1220 -	}
  4.1221 -}
  4.1222 -#endif
  4.1223 -
  4.1224 -static int mdio_read (struct net_device *dev, int phy_id, int location)
  4.1225 -{
  4.1226 -	struct rtl8139_private *tp = dev->priv;
  4.1227 -	int retval = 0;
  4.1228 -#ifdef CONFIG_8139TOO_8129
  4.1229 -	void *mdio_addr = tp->mmio_addr + Config4;
  4.1230 -	int mii_cmd = (0xf6 << 10) | (phy_id << 5) | location;
  4.1231 -	int i;
  4.1232 -#endif
  4.1233 -
  4.1234 -	if (phy_id > 31) {	/* Really a 8139.  Use internal registers. */
  4.1235 -		return location < 8 && mii_2_8139_map[location] ?
  4.1236 -		    readw (tp->mmio_addr + mii_2_8139_map[location]) : 0;
  4.1237 -	}
  4.1238 -
  4.1239 -#ifdef CONFIG_8139TOO_8129
  4.1240 -	mdio_sync (mdio_addr);
  4.1241 -	/* Shift the read command bits out. */
  4.1242 -	for (i = 15; i >= 0; i--) {
  4.1243 -		int dataval = (mii_cmd & (1 << i)) ? MDIO_DATA_OUT : 0;
  4.1244 -
  4.1245 -		writeb (MDIO_DIR | dataval, mdio_addr);
  4.1246 -		mdio_delay (mdio_addr);
  4.1247 -		writeb (MDIO_DIR | dataval | MDIO_CLK, mdio_addr);
  4.1248 -		mdio_delay (mdio_addr);
  4.1249 -	}
  4.1250 -
  4.1251 -	/* Read the two transition, 16 data, and wire-idle bits. */
  4.1252 -	for (i = 19; i > 0; i--) {
  4.1253 -		writeb (0, mdio_addr);
  4.1254 -		mdio_delay (mdio_addr);
  4.1255 -		retval = (retval << 1) | ((readb (mdio_addr) & MDIO_DATA_IN) ? 1 : 0);
  4.1256 -		writeb (MDIO_CLK, mdio_addr);
  4.1257 -		mdio_delay (mdio_addr);
  4.1258 -	}
  4.1259 -#endif
  4.1260 -
  4.1261 -	return (retval >> 1) & 0xffff;
  4.1262 -}
  4.1263 -
  4.1264 -
  4.1265 -static void mdio_write (struct net_device *dev, int phy_id, int location,
  4.1266 -			int value)
  4.1267 -{
  4.1268 -	struct rtl8139_private *tp = dev->priv;
  4.1269 -#ifdef CONFIG_8139TOO_8129
  4.1270 -	void *mdio_addr = tp->mmio_addr + Config4;
  4.1271 -	int mii_cmd = (0x5002 << 16) | (phy_id << 23) | (location << 18) | value;
  4.1272 -	int i;
  4.1273 -#endif
  4.1274 -
  4.1275 -	if (phy_id > 31) {	/* Really a 8139.  Use internal registers. */
  4.1276 -		void *ioaddr = tp->mmio_addr;
  4.1277 -		if (location == 0) {
  4.1278 -			RTL_W8 (Cfg9346, Cfg9346_Unlock);
  4.1279 -			RTL_W16 (BasicModeCtrl, value);
  4.1280 -			RTL_W8 (Cfg9346, Cfg9346_Lock);
  4.1281 -		} else if (location < 8 && mii_2_8139_map[location])
  4.1282 -			RTL_W16 (mii_2_8139_map[location], value);
  4.1283 -		return;
  4.1284 -	}
  4.1285 -
  4.1286 -#ifdef CONFIG_8139TOO_8129
  4.1287 -	mdio_sync (mdio_addr);
  4.1288 -
  4.1289 -	/* Shift the command bits out. */
  4.1290 -	for (i = 31; i >= 0; i--) {
  4.1291 -		int dataval =
  4.1292 -		    (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0;
  4.1293 -		writeb (dataval, mdio_addr);
  4.1294 -		mdio_delay (mdio_addr);
  4.1295 -		writeb (dataval | MDIO_CLK, mdio_addr);
  4.1296 -		mdio_delay (mdio_addr);
  4.1297 -	}
  4.1298 -	/* Clear out extra bits. */
  4.1299 -	for (i = 2; i > 0; i--) {
  4.1300 -		writeb (0, mdio_addr);
  4.1301 -		mdio_delay (mdio_addr);
  4.1302 -		writeb (MDIO_CLK, mdio_addr);
  4.1303 -		mdio_delay (mdio_addr);
  4.1304 -	}
  4.1305 -#endif
  4.1306 -}
  4.1307 -
  4.1308 -
  4.1309 -static int rtl8139_open (struct net_device *dev)
  4.1310 -{
  4.1311 -	struct rtl8139_private *tp = dev->priv;
  4.1312 -	int retval;
  4.1313 -#ifdef RTL8139_DEBUG
  4.1314 -	void *ioaddr = tp->mmio_addr;
  4.1315 -#endif
  4.1316 -
  4.1317 -	retval = request_irq (dev->irq, rtl8139_interrupt, SA_SHIRQ, dev->name, dev);
  4.1318 -	if (retval)
  4.1319 -		return retval;
  4.1320 -
  4.1321 -	tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  4.1322 -					   &tp->tx_bufs_dma);
  4.1323 -	tp->rx_ring = pci_alloc_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  4.1324 -					   &tp->rx_ring_dma);
  4.1325 -	if (tp->tx_bufs == NULL || tp->rx_ring == NULL) {
  4.1326 -		free_irq(dev->irq, dev);
  4.1327 -
  4.1328 -		if (tp->tx_bufs)
  4.1329 -			pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  4.1330 -					    tp->tx_bufs, tp->tx_bufs_dma);
  4.1331 -		if (tp->rx_ring)
  4.1332 -			pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  4.1333 -					    tp->rx_ring, tp->rx_ring_dma);
  4.1334 -
  4.1335 -		return -ENOMEM;
  4.1336 -
  4.1337 -	}
  4.1338 -
  4.1339 -	tp->mii.full_duplex = tp->mii.force_media;
  4.1340 -	tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000;
  4.1341 -	tp->twistie = (tp->chipset == CH_8139_K) ? 1 : 0;
  4.1342 -	tp->time_to_die = 0;
  4.1343 -
  4.1344 -	rtl8139_init_ring (dev);
  4.1345 -	rtl8139_hw_start (dev);
  4.1346 -
  4.1347 -	DPRINTK ("%s: rtl8139_open() ioaddr %#lx IRQ %d"
  4.1348 -			" GP Pins %2.2x %s-duplex.\n",
  4.1349 -			dev->name, pci_resource_start (tp->pci_dev, 1),
  4.1350 -			dev->irq, RTL_R8 (MediaStatus),
  4.1351 -			tp->mii.full_duplex ? "full" : "half");
  4.1352 -
  4.1353 -#if 0
  4.1354 -	tp->thr_pid = kernel_thread (rtl8139_thread, dev, CLONE_FS | CLONE_FILES);
  4.1355 -	if (tp->thr_pid < 0)
  4.1356 -		printk (KERN_WARNING "%s: unable to start kernel thread\n",
  4.1357 -			dev->name);
  4.1358 -#else
  4.1359 -	init_timer(&tp->timer);
  4.1360 -	tp->timer.expires = jiffies + next_tick;
  4.1361 -	tp->timer.data = (unsigned long)dev;
  4.1362 -	tp->timer.function = rtl8139_timer;
  4.1363 -	add_timer(&tp->timer);
  4.1364 -#endif
  4.1365 -
  4.1366 -	return 0;
  4.1367 -}
  4.1368 -
  4.1369 -
  4.1370 -static void rtl_check_media (struct net_device *dev)
  4.1371 -{
  4.1372 -	struct rtl8139_private *tp = dev->priv;
  4.1373 -
  4.1374 -	if (tp->phys[0] >= 0) {
  4.1375 -		u16 mii_lpa = mdio_read(dev, tp->phys[0], MII_LPA);
  4.1376 -		if (mii_lpa == 0xffff)
  4.1377 -			;					/* Not there */
  4.1378 -		else if ((mii_lpa & LPA_100FULL) == LPA_100FULL
  4.1379 -				 || (mii_lpa & 0x00C0) == LPA_10FULL)
  4.1380 -			tp->mii.full_duplex = 1;
  4.1381 -
  4.1382 -		printk (KERN_INFO"%s: Setting %s%s-duplex based on"
  4.1383 -				" auto-negotiated partner ability %4.4x.\n",
  4.1384 -		        dev->name, mii_lpa == 0 ? "" :
  4.1385 -				(mii_lpa & 0x0180) ? "100mbps " : "10mbps ",
  4.1386 -			tp->mii.full_duplex ? "full" : "half", mii_lpa);
  4.1387 -	}
  4.1388 -}
  4.1389 -
  4.1390 -/* Start the hardware at open or resume. */
  4.1391 -static void rtl8139_hw_start (struct net_device *dev)
  4.1392 -{
  4.1393 -	struct rtl8139_private *tp = dev->priv;
  4.1394 -	void *ioaddr = tp->mmio_addr;
  4.1395 -	u32 i;
  4.1396 -	u8 tmp;
  4.1397 -
  4.1398 -	/* Bring old chips out of low-power mode. */
  4.1399 -	if (rtl_chip_info[tp->chipset].flags & HasHltClk)
  4.1400 -		RTL_W8 (HltClk, 'R');
  4.1401 -
  4.1402 -	rtl8139_chip_reset (ioaddr);
  4.1403 -
  4.1404 -	/* unlock Config[01234] and BMCR register writes */
  4.1405 -	RTL_W8_F (Cfg9346, Cfg9346_Unlock);
  4.1406 -	/* Restore our idea of the MAC address. */
  4.1407 -	RTL_W32_F (MAC0 + 0, cpu_to_le32 (*(u32 *) (dev->dev_addr + 0)));
  4.1408 -	RTL_W32_F (MAC0 + 4, cpu_to_le32 (*(u32 *) (dev->dev_addr + 4)));
  4.1409 -
  4.1410 -	/* Must enable Tx/Rx before setting transfer thresholds! */
  4.1411 -	RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
  4.1412 -
  4.1413 -	tp->rx_config = rtl8139_rx_config | AcceptBroadcast | AcceptMyPhys;
  4.1414 -	RTL_W32 (RxConfig, tp->rx_config);
  4.1415 -
  4.1416 -	/* Check this value: the documentation for IFG contradicts ifself. */
  4.1417 -	RTL_W32 (TxConfig, rtl8139_tx_config);
  4.1418 -
  4.1419 -	tp->cur_rx = 0;
  4.1420 -
  4.1421 -	rtl_check_media (dev);
  4.1422 -
  4.1423 -	if (tp->chipset >= CH_8139B) {
  4.1424 -		/* Disable magic packet scanning, which is enabled
  4.1425 -		 * when PM is enabled in Config1.  It can be reenabled
  4.1426 -		 * via ETHTOOL_SWOL if desired.  */
  4.1427 -		RTL_W8 (Config3, RTL_R8 (Config3) & ~Cfg3_Magic);
  4.1428 -	}
  4.1429 -
  4.1430 -	DPRINTK("init buffer addresses\n");
  4.1431 -
  4.1432 -	/* Lock Config[01234] and BMCR register writes */
  4.1433 -	RTL_W8 (Cfg9346, Cfg9346_Lock);
  4.1434 -
  4.1435 -	/* init Rx ring buffer DMA address */
  4.1436 -	RTL_W32_F (RxBuf, tp->rx_ring_dma);
  4.1437 -
  4.1438 -	/* init Tx buffer DMA addresses */
  4.1439 -	for (i = 0; i < NUM_TX_DESC; i++)
  4.1440 -		RTL_W32_F (TxAddr0 + (i * 4), tp->tx_bufs_dma + (tp->tx_buf[i] - tp->tx_bufs));
  4.1441 -
  4.1442 -	RTL_W32 (RxMissed, 0);
  4.1443 -
  4.1444 -	rtl8139_set_rx_mode (dev);
  4.1445 -
  4.1446 -	/* no early-rx interrupts */
  4.1447 -	RTL_W16 (MultiIntr, RTL_R16 (MultiIntr) & MultiIntrClear);
  4.1448 -
  4.1449 -	/* make sure RxTx has started */
  4.1450 -	tmp = RTL_R8 (ChipCmd);
  4.1451 -	if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb)))
  4.1452 -		RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
  4.1453 -
  4.1454 -	/* Enable all known interrupts by setting the interrupt mask. */
  4.1455 -	RTL_W16 (IntrMask, rtl8139_intr_mask);
  4.1456 -
  4.1457 -	netif_start_queue (dev);
  4.1458 -}
  4.1459 -
  4.1460 -
  4.1461 -/* Initialize the Rx and Tx rings, along with various 'dev' bits. */
  4.1462 -static void rtl8139_init_ring (struct net_device *dev)
  4.1463 -{
  4.1464 -	struct rtl8139_private *tp = dev->priv;
  4.1465 -	int i;
  4.1466 -
  4.1467 -	tp->cur_rx = 0;
  4.1468 -	tp->cur_tx = 0;
  4.1469 -	tp->dirty_tx = 0;
  4.1470 -
  4.1471 -	for (i = 0; i < NUM_TX_DESC; i++)
  4.1472 -		tp->tx_buf[i] = &tp->tx_bufs[i * TX_BUF_SIZE];
  4.1473 -}
  4.1474 -
  4.1475 -
  4.1476 -#ifndef CONFIG_8139TOO_TUNE_TWISTER
  4.1477 -static inline void rtl8139_tune_twister (struct net_device *dev,
  4.1478 -				  struct rtl8139_private *tp) {}
  4.1479 -#else
  4.1480 -static void rtl8139_tune_twister (struct net_device *dev,
  4.1481 -				  struct rtl8139_private *tp)
  4.1482 -{
  4.1483 -	int linkcase;
  4.1484 -	void *ioaddr = tp->mmio_addr;
  4.1485 -
  4.1486 -	/* This is a complicated state machine to configure the "twister" for
  4.1487 -	   impedance/echos based on the cable length.
  4.1488 -	   All of this is magic and undocumented.
  4.1489 -	 */
  4.1490 -	switch (tp->twistie) {
  4.1491 -	case 1:
  4.1492 -		if (RTL_R16 (CSCR) & CSCR_LinkOKBit) {
  4.1493 -			/* We have link beat, let us tune the twister. */
  4.1494 -			RTL_W16 (CSCR, CSCR_LinkDownOffCmd);
  4.1495 -			tp->twistie = 2;	/* Change to state 2. */
  4.1496 -			next_tick = HZ / 10;
  4.1497 -		} else {
  4.1498 -			/* Just put in some reasonable defaults for when beat returns. */
  4.1499 -			RTL_W16 (CSCR, CSCR_LinkDownCmd);
  4.1500 -			RTL_W32 (FIFOTMS, 0x20);	/* Turn on cable test mode. */
  4.1501 -			RTL_W32 (PARA78, PARA78_default);
  4.1502 -			RTL_W32 (PARA7c, PARA7c_default);
  4.1503 -			tp->twistie = 0;	/* Bail from future actions. */
  4.1504 -		}
  4.1505 -		break;
  4.1506 -	case 2:
  4.1507 -		/* Read how long it took to hear the echo. */
  4.1508 -		linkcase = RTL_R16 (CSCR) & CSCR_LinkStatusBits;
  4.1509 -		if (linkcase == 0x7000)
  4.1510 -			tp->twist_row = 3;
  4.1511 -		else if (linkcase == 0x3000)
  4.1512 -			tp->twist_row = 2;
  4.1513 -		else if (linkcase == 0x1000)
  4.1514 -			tp->twist_row = 1;
  4.1515 -		else
  4.1516 -			tp->twist_row = 0;
  4.1517 -		tp->twist_col = 0;
  4.1518 -		tp->twistie = 3;	/* Change to state 2. */
  4.1519 -		next_tick = HZ / 10;
  4.1520 -		break;
  4.1521 -	case 3:
  4.1522 -		/* Put out four tuning parameters, one per 100msec. */
  4.1523 -		if (tp->twist_col == 0)
  4.1524 -			RTL_W16 (FIFOTMS, 0);
  4.1525 -		RTL_W32 (PARA7c, param[(int) tp->twist_row]
  4.1526 -			 [(int) tp->twist_col]);
  4.1527 -		next_tick = HZ / 10;
  4.1528 -		if (++tp->twist_col >= 4) {
  4.1529 -			/* For short cables we are done.
  4.1530 -			   For long cables (row == 3) check for mistune. */
  4.1531 -			tp->twistie =
  4.1532 -			    (tp->twist_row == 3) ? 4 : 0;
  4.1533 -		}
  4.1534 -		break;
  4.1535 -	case 4:
  4.1536 -		/* Special case for long cables: check for mistune. */
  4.1537 -		if ((RTL_R16 (CSCR) &
  4.1538 -		     CSCR_LinkStatusBits) == 0x7000) {
  4.1539 -			tp->twistie = 0;
  4.1540 -			break;
  4.1541 -		} else {
  4.1542 -			RTL_W32 (PARA7c, 0xfb38de03);
  4.1543 -			tp->twistie = 5;
  4.1544 -			next_tick = HZ / 10;
  4.1545 -		}
  4.1546 -		break;
  4.1547 -	case 5:
  4.1548 -		/* Retune for shorter cable (column 2). */
  4.1549 -		RTL_W32 (FIFOTMS, 0x20);
  4.1550 -		RTL_W32 (PARA78, PARA78_default);
  4.1551 -		RTL_W32 (PARA7c, PARA7c_default);
  4.1552 -		RTL_W32 (FIFOTMS, 0x00);
  4.1553 -		tp->twist_row = 2;
  4.1554 -		tp->twist_col = 0;
  4.1555 -		tp->twistie = 3;
  4.1556 -		next_tick = HZ / 10;
  4.1557 -		break;
  4.1558 -
  4.1559 -	default:
  4.1560 -		/* do nothing */
  4.1561 -		break;
  4.1562 -	}
  4.1563 -}
  4.1564 -#endif /* CONFIG_8139TOO_TUNE_TWISTER */
  4.1565 -
  4.1566 -
  4.1567 -static inline void rtl8139_thread_iter (struct net_device *dev,
  4.1568 -				 struct rtl8139_private *tp,
  4.1569 -				 void *ioaddr)
  4.1570 -{
  4.1571 -	int mii_lpa;
  4.1572 -
  4.1573 -	mii_lpa = mdio_read (dev, tp->phys[0], MII_LPA);
  4.1574 -
  4.1575 -	if (!tp->mii.force_media && mii_lpa != 0xffff) {
  4.1576 -		int duplex = (mii_lpa & LPA_100FULL)
  4.1577 -		    || (mii_lpa & 0x01C0) == 0x0040;
  4.1578 -		if (tp->mii.full_duplex != duplex) {
  4.1579 -			tp->mii.full_duplex = duplex;
  4.1580 -
  4.1581 -			if (mii_lpa) {
  4.1582 -				printk (KERN_INFO
  4.1583 -					"%s: Setting %s-duplex based on MII #%d link"
  4.1584 -					" partner ability of %4.4x.\n",
  4.1585 -					dev->name,
  4.1586 -					tp->mii.full_duplex ? "full" : "half",
  4.1587 -					tp->phys[0], mii_lpa);
  4.1588 -			} else {
  4.1589 -				printk(KERN_INFO"%s: media is unconnected, link down, or incompatible connection\n",
  4.1590 -				       dev->name);
  4.1591 -			}
  4.1592 -#if 0
  4.1593 -			RTL_W8 (Cfg9346, Cfg9346_Unlock);
  4.1594 -			RTL_W8 (Config1, tp->mii.full_duplex ? 0x60 : 0x20);
  4.1595 -			RTL_W8 (Cfg9346, Cfg9346_Lock);
  4.1596 -#endif
  4.1597 -		}
  4.1598 -	}
  4.1599 -
  4.1600 -	next_tick = HZ * 60;
  4.1601 -
  4.1602 -	rtl8139_tune_twister (dev, tp);
  4.1603 -
  4.1604 -	DPRINTK ("%s: Media selection tick, Link partner %4.4x.\n",
  4.1605 -		 dev->name, RTL_R16 (NWayLPAR));
  4.1606 -	DPRINTK ("%s:  Other registers are IntMask %4.4x IntStatus %4.4x\n",
  4.1607 -		 dev->name, RTL_R16 (IntrMask), RTL_R16 (IntrStatus));
  4.1608 -	DPRINTK ("%s:  Chip config %2.2x %2.2x.\n",
  4.1609 -		 dev->name, RTL_R8 (Config0),
  4.1610 -		 RTL_R8 (Config1));
  4.1611 -}
  4.1612 -
  4.1613 -
  4.1614 -#if 0
  4.1615 -static int rtl8139_thread (void *data)
  4.1616 -{
  4.1617 -	struct net_device *dev = data;
  4.1618 -	struct rtl8139_private *tp = dev->priv;
  4.1619 -	unsigned long timeout;
  4.1620 -
  4.1621 -	daemonize ();
  4.1622 -	reparent_to_init();
  4.1623 -	spin_lock_irq(&current->sigmask_lock);
  4.1624 -	sigemptyset(&current->blocked);
  4.1625 -	recalc_sigpending(current);
  4.1626 -	spin_unlock_irq(&current->sigmask_lock);
  4.1627 -
  4.1628 -	strncpy (current->comm, dev->name, sizeof(current->comm) - 1);
  4.1629 -	current->comm[sizeof(current->comm) - 1] = '\0';
  4.1630 -
  4.1631 -	while (1) {
  4.1632 -		timeout = next_tick;
  4.1633 -		do {
  4.1634 -			timeout = interruptible_sleep_on_timeout (&tp->thr_wait, timeout);
  4.1635 -		} while (!signal_pending (current) && (timeout > 0));
  4.1636 -
  4.1637 -		if (signal_pending (current)) {
  4.1638 -			spin_lock_irq(&current->sigmask_lock);
  4.1639 -			flush_signals(current);
  4.1640 -			spin_unlock_irq(&current->sigmask_lock);
  4.1641 -		}
  4.1642 -
  4.1643 -		if (tp->time_to_die)
  4.1644 -			break;
  4.1645 -
  4.1646 -		rtnl_lock ();
  4.1647 -		rtl8139_thread_iter (dev, tp, tp->mmio_addr);
  4.1648 -		rtnl_unlock ();
  4.1649 -	}
  4.1650 -
  4.1651 -	complete_and_exit (&tp->thr_exited, 0);
  4.1652 -}
  4.1653 -#else
  4.1654 -static void rtl8139_timer(unsigned long arg)
  4.1655 -{
  4.1656 -	struct net_device *dev = (struct net_device *)arg;
  4.1657 -	struct rtl8139_private *tp = dev->priv;
  4.1658 -	rtl8139_thread_iter (dev, tp, tp->mmio_addr);
  4.1659 -	mod_timer(&tp->timer, jiffies + next_tick);
  4.1660 -}
  4.1661 -#endif
  4.1662 -
  4.1663 -
  4.1664 -static void rtl8139_tx_clear (struct rtl8139_private *tp)
  4.1665 -{
  4.1666 -	tp->cur_tx = 0;
  4.1667 -	tp->dirty_tx = 0;
  4.1668 -
  4.1669 -	/* XXX account for unsent Tx packets in tp->stats.tx_dropped */
  4.1670 -}
  4.1671 -
  4.1672 -
  4.1673 -static void rtl8139_tx_timeout (struct net_device *dev)
  4.1674 -{
  4.1675 -	struct rtl8139_private *tp = dev->priv;
  4.1676 -	void *ioaddr = tp->mmio_addr;
  4.1677 -	int i;
  4.1678 -	u8 tmp8;
  4.1679 -	unsigned long flags;
  4.1680 -
  4.1681 -	DPRINTK ("%s: Transmit timeout, status %2.2x %4.4x "
  4.1682 -		 "media %2.2x.\n", dev->name,
  4.1683 -		 RTL_R8 (ChipCmd),
  4.1684 -		 RTL_R16 (IntrStatus),
  4.1685 -		 RTL_R8 (MediaStatus));
  4.1686 -
  4.1687 -	tp->xstats.tx_timeouts++;
  4.1688 -
  4.1689 -	/* disable Tx ASAP, if not already */
  4.1690 -	tmp8 = RTL_R8 (ChipCmd);
  4.1691 -	if (tmp8 & CmdTxEnb)
  4.1692 -		RTL_W8 (ChipCmd, CmdRxEnb);
  4.1693 -
  4.1694 -	/* Disable interrupts by clearing the interrupt mask. */
  4.1695 -	RTL_W16 (IntrMask, 0x0000);
  4.1696 -
  4.1697 -	/* Emit info to figure out what went wrong. */
  4.1698 -	printk (KERN_DEBUG "%s: Tx queue start entry %ld  dirty entry %ld.\n",
  4.1699 -		dev->name, tp->cur_tx, tp->dirty_tx);
  4.1700 -	for (i = 0; i < NUM_TX_DESC; i++)
  4.1701 -		printk (KERN_DEBUG "%s:  Tx descriptor %d is %8.8lx.%s\n",
  4.1702 -			dev->name, i, RTL_R32 (TxStatus0 + (i * 4)),
  4.1703 -			i == tp->dirty_tx % NUM_TX_DESC ?
  4.1704 -				" (queue head)" : "");
  4.1705 -
  4.1706 -	/* Stop a shared interrupt from scavenging while we are. */
  4.1707 -	spin_lock_irqsave (&tp->lock, flags);
  4.1708 -	rtl8139_tx_clear (tp);
  4.1709 -	spin_unlock_irqrestore (&tp->lock, flags);
  4.1710 -
  4.1711 -	/* ...and finally, reset everything */
  4.1712 -	rtl8139_hw_start (dev);
  4.1713 -
  4.1714 -	netif_wake_queue (dev);
  4.1715 -}
  4.1716 -
  4.1717 -
  4.1718 -static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
  4.1719 -{
  4.1720 -	struct rtl8139_private *tp = dev->priv;
  4.1721 -	void *ioaddr = tp->mmio_addr;
  4.1722 -	unsigned int entry;
  4.1723 -	unsigned int len = skb->len;
  4.1724 -
  4.1725 -	/* Calculate the next Tx descriptor entry. */
  4.1726 -	entry = tp->cur_tx % NUM_TX_DESC;
  4.1727 -
  4.1728 -	if (likely(len < TX_BUF_SIZE)) {
  4.1729 -		if(len < ETH_ZLEN)
  4.1730 -			memset(tp->tx_buf[entry], 0, ETH_ZLEN);
  4.1731 -#if 0
  4.1732 -		skb_copy_and_csum_dev(skb, tp->tx_buf[entry]);
  4.1733 -#else
  4.1734 -		skb_copy_bits(skb, 0, tp->tx_buf[entry], skb->len);
  4.1735 -#endif
  4.1736 -		dev_kfree_skb(skb);
  4.1737 -	} else {
  4.1738 -		dev_kfree_skb(skb);
  4.1739 -		tp->stats.tx_dropped++;
  4.1740 -		return 0;
  4.1741 -	}
  4.1742 -
  4.1743 -	/* Note: the chip doesn't have auto-pad! */
  4.1744 -	spin_lock_irq(&tp->lock);
  4.1745 -	RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
  4.1746 -		   tp->tx_flag | max(len, (unsigned int)ETH_ZLEN));
  4.1747 -
  4.1748 -	dev->trans_start = jiffies;
  4.1749 -
  4.1750 -	tp->cur_tx++;
  4.1751 -	wmb();
  4.1752 -
  4.1753 -	if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx)
  4.1754 -		netif_stop_queue (dev);
  4.1755 -	spin_unlock_irq(&tp->lock);
  4.1756 -
  4.1757 -	DPRINTK ("%s: Queued Tx packet size %u to slot %d.\n",
  4.1758 -		 dev->name, len, entry);
  4.1759 -
  4.1760 -	return 0;
  4.1761 -}
  4.1762 -
  4.1763 -
  4.1764 -static void rtl8139_tx_interrupt (struct net_device *dev,
  4.1765 -				  struct rtl8139_private *tp,
  4.1766 -				  void *ioaddr)
  4.1767 -{
  4.1768 -	unsigned long dirty_tx, tx_left;
  4.1769 -
  4.1770 -	assert (dev != NULL);
  4.1771 -	assert (tp != NULL);
  4.1772 -	assert (ioaddr != NULL);
  4.1773 -
  4.1774 -	dirty_tx = tp->dirty_tx;
  4.1775 -	tx_left = tp->cur_tx - dirty_tx;
  4.1776 -	while (tx_left > 0) {
  4.1777 -		int entry = dirty_tx % NUM_TX_DESC;
  4.1778 -		int txstatus;
  4.1779 -
  4.1780 -		txstatus = RTL_R32 (TxStatus0 + (entry * sizeof (u32)));
  4.1781 -
  4.1782 -		if (!(txstatus & (TxStatOK | TxUnderrun | TxAborted)))
  4.1783 -			break;	/* It still hasn't been Txed */
  4.1784 -
  4.1785 -		/* Note: TxCarrierLost is always asserted at 100mbps. */
  4.1786 -		if (txstatus & (TxOutOfWindow | TxAborted)) {
  4.1787 -			/* There was an major error, log it. */
  4.1788 -			DPRINTK ("%s: Transmit error, Tx status %8.8x.\n",
  4.1789 -				 dev->name, txstatus);
  4.1790 -			tp->stats.tx_errors++;
  4.1791 -			if (txstatus & TxAborted) {
  4.1792 -				tp->stats.tx_aborted_errors++;
  4.1793 -				RTL_W32 (TxConfig, TxClearAbt);
  4.1794 -				RTL_W16 (IntrStatus, TxErr);
  4.1795 -				wmb();
  4.1796 -			}
  4.1797 -			if (txstatus & TxCarrierLost)
  4.1798 -				tp->stats.tx_carrier_errors++;
  4.1799 -			if (txstatus & TxOutOfWindow)
  4.1800 -				tp->stats.tx_window_errors++;
  4.1801 -		} else {
  4.1802 -			if (txstatus & TxUnderrun) {
  4.1803 -				/* Add 64 to the Tx FIFO threshold. */
  4.1804 -				if (tp->tx_flag < 0x00300000)
  4.1805 -					tp->tx_flag += 0x00020000;
  4.1806 -				tp->stats.tx_fifo_errors++;
  4.1807 -			}
  4.1808 -			tp->stats.collisions += (txstatus >> 24) & 15;
  4.1809 -			tp->stats.tx_bytes += txstatus & 0x7ff;
  4.1810 -			tp->stats.tx_packets++;
  4.1811 -		}
  4.1812 -
  4.1813 -		dirty_tx++;
  4.1814 -		tx_left--;
  4.1815 -	}
  4.1816 -
  4.1817 -#ifndef RTL8139_NDEBUG
  4.1818 -	if (tp->cur_tx - dirty_tx > NUM_TX_DESC) {
  4.1819 -		printk (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n",
  4.1820 -		        dev->name, dirty_tx, tp->cur_tx);
  4.1821 -		dirty_tx += NUM_TX_DESC;
  4.1822 -	}
  4.1823 -#endif /* RTL8139_NDEBUG */
  4.1824 -
  4.1825 -	/* only wake the queue if we did work, and the queue is stopped */
  4.1826 -	if (tp->dirty_tx != dirty_tx) {
  4.1827 -		tp->dirty_tx = dirty_tx;
  4.1828 -		mb();
  4.1829 -		if (netif_queue_stopped (dev))
  4.1830 -			netif_wake_queue (dev);
  4.1831 -	}
  4.1832 -}
  4.1833 -
  4.1834 -
  4.1835 -/* TODO: clean this up!  Rx reset need not be this intensive */
  4.1836 -static void rtl8139_rx_err (u32 rx_status, struct net_device *dev,
  4.1837 -			    struct rtl8139_private *tp, void *ioaddr)
  4.1838 -{
  4.1839 -	u8 tmp8;
  4.1840 -#ifdef CONFIG_8139_OLD_RX_RESET
  4.1841 -	int tmp_work;
  4.1842 -#endif
  4.1843 -
  4.1844 -	DPRINTK ("%s: Ethernet frame had errors, status %8.8x.\n",
  4.1845 -	         dev->name, rx_status);
  4.1846 -	tp->stats.rx_errors++;
  4.1847 -	if (!(rx_status & RxStatusOK)) {
  4.1848 -		if (rx_status & RxTooLong) {
  4.1849 -			DPRINTK ("%s: Oversized Ethernet frame, status %4.4x!\n",
  4.1850 -			 	dev->name, rx_status);
  4.1851 -			/* A.C.: The chip hangs here. */
  4.1852 -		}
  4.1853 -		if (rx_status & (RxBadSymbol | RxBadAlign))
  4.1854 -			tp->stats.rx_frame_errors++;
  4.1855 -		if (rx_status & (RxRunt | RxTooLong))
  4.1856 -			tp->stats.rx_length_errors++;
  4.1857 -		if (rx_status & RxCRCErr)
  4.1858 -			tp->stats.rx_crc_errors++;
  4.1859 -	} else {
  4.1860 -		tp->xstats.rx_lost_in_ring++;
  4.1861 -	}
  4.1862 -
  4.1863 -#ifndef CONFIG_8139_OLD_RX_RESET
  4.1864 -	tmp8 = RTL_R8 (ChipCmd);
  4.1865 -	RTL_W8 (ChipCmd, tmp8 & ~CmdRxEnb);
  4.1866 -	RTL_W8 (ChipCmd, tmp8);
  4.1867 -	RTL_W32 (RxConfig, tp->rx_config);
  4.1868 -	tp->cur_rx = 0;
  4.1869 -#else
  4.1870 -	/* Reset the receiver, based on RealTek recommendation. (Bug?) */
  4.1871 -
  4.1872 -	/* disable receive */
  4.1873 -	RTL_W8_F (ChipCmd, CmdTxEnb);
  4.1874 -	tmp_work = 200;
  4.1875 -	while (--tmp_work > 0) {
  4.1876 -		udelay(1);
  4.1877 -		tmp8 = RTL_R8 (ChipCmd);
  4.1878 -		if (!(tmp8 & CmdRxEnb))
  4.1879 -			break;
  4.1880 -	}
  4.1881 -	if (tmp_work <= 0)
  4.1882 -		printk (KERN_WARNING PFX "rx stop wait too long\n");
  4.1883 -	/* restart receive */
  4.1884 -	tmp_work = 200;
  4.1885 -	while (--tmp_work > 0) {
  4.1886 -		RTL_W8_F (ChipCmd, CmdRxEnb | CmdTxEnb);
  4.1887 -		udelay(1);
  4.1888 -		tmp8 = RTL_R8 (ChipCmd);
  4.1889 -		if ((tmp8 & CmdRxEnb) && (tmp8 & CmdTxEnb))
  4.1890 -			break;
  4.1891 -	}
  4.1892 -	if (tmp_work <= 0)
  4.1893 -		printk (KERN_WARNING PFX "tx/rx enable wait too long\n");
  4.1894 -
  4.1895 -	/* and reinitialize all rx related registers */
  4.1896 -	RTL_W8_F (Cfg9346, Cfg9346_Unlock);
  4.1897 -	/* Must enable Tx/Rx before setting transfer thresholds! */
  4.1898 -	RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
  4.1899 -
  4.1900 -	tp->rx_config = rtl8139_rx_config | AcceptBroadcast | AcceptMyPhys;
  4.1901 -	RTL_W32 (RxConfig, tp->rx_config);
  4.1902 -	tp->cur_rx = 0;
  4.1903 -
  4.1904 -	DPRINTK("init buffer addresses\n");
  4.1905 -
  4.1906 -	/* Lock Config[01234] and BMCR register writes */
  4.1907 -	RTL_W8 (Cfg9346, Cfg9346_Lock);
  4.1908 -
  4.1909 -	/* init Rx ring buffer DMA address */
  4.1910 -	RTL_W32_F (RxBuf, tp->rx_ring_dma);
  4.1911 -
  4.1912 -	/* A.C.: Reset the multicast list. */
  4.1913 -	__set_rx_mode (dev);
  4.1914 -#endif
  4.1915 -}
  4.1916 -
  4.1917 -static void rtl8139_rx_interrupt (struct net_device *dev,
  4.1918 -				  struct rtl8139_private *tp, void *ioaddr)
  4.1919 -{
  4.1920 -	unsigned char *rx_ring;
  4.1921 -	u16 cur_rx;
  4.1922 -
  4.1923 -	assert (dev != NULL);
  4.1924 -	assert (tp != NULL);
  4.1925 -	assert (ioaddr != NULL);
  4.1926 -
  4.1927 -	rx_ring = tp->rx_ring;
  4.1928 -	cur_rx = tp->cur_rx;
  4.1929 -
  4.1930 -	DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x,"
  4.1931 -		 " free to %4.4x, Cmd %2.2x.\n", dev->name, cur_rx,
  4.1932 -		 RTL_R16 (RxBufAddr),
  4.1933 -		 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
  4.1934 -
  4.1935 -	while ((RTL_R8 (ChipCmd) & RxBufEmpty) == 0) {
  4.1936 -		int ring_offset = cur_rx % RX_BUF_LEN;
  4.1937 -		u32 rx_status;
  4.1938 -		unsigned int rx_size;
  4.1939 -		unsigned int pkt_size;
  4.1940 -		struct sk_buff *skb;
  4.1941 -
  4.1942 -		rmb();
  4.1943 -
  4.1944 -		/* read size+status of next frame from DMA ring buffer */
  4.1945 -		rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset));
  4.1946 -		rx_size = rx_status >> 16;
  4.1947 -		pkt_size = rx_size - 4;
  4.1948 -
  4.1949 -		DPRINTK ("%s:  rtl8139_rx() status %4.4x, size %4.4x,"
  4.1950 -			 " cur %4.4x.\n", dev->name, rx_status,
  4.1951 -			 rx_size, cur_rx);
  4.1952 -#if RTL8139_DEBUG > 2
  4.1953 -		{
  4.1954 -			int i;
  4.1955 -			DPRINTK ("%s: Frame contents ", dev->name);
  4.1956 -			for (i = 0; i < 70; i++)
  4.1957 -				printk (" %2.2x",
  4.1958 -					rx_ring[ring_offset + i]);
  4.1959 -			printk (".\n");
  4.1960 -		}
  4.1961 -#endif
  4.1962 -
  4.1963 -		/* Packet copy from FIFO still in progress.
  4.1964 -		 * Theoretically, this should never happen
  4.1965 -		 * since EarlyRx is disabled.
  4.1966 -		 */
  4.1967 -		if (rx_size == 0xfff0) {
  4.1968 -			tp->xstats.early_rx++;
  4.1969 -			break;
  4.1970 -		}
  4.1971 -
  4.1972 -		/* If Rx err or invalid rx_size/rx_status received
  4.1973 -		 * (which happens if we get lost in the ring),
  4.1974 -		 * Rx process gets reset, so we abort any further
  4.1975 -		 * Rx processing.
  4.1976 -		 */
  4.1977 -		if ((rx_size > (MAX_ETH_FRAME_SIZE+4)) ||
  4.1978 -		    (rx_size < 8) ||
  4.1979 -		    (!(rx_status & RxStatusOK))) {
  4.1980 -			rtl8139_rx_err (rx_status, dev, tp, ioaddr);
  4.1981 -			return;
  4.1982 -		}
  4.1983 -
  4.1984 -		/* Malloc up new buffer, compatible with net-2e. */
  4.1985 -		/* Omit the four octet CRC from the length. */
  4.1986 -
  4.1987 -		/* TODO: consider allocating skb's outside of
  4.1988 -		 * interrupt context, both to speed interrupt processing,
  4.1989 -		 * and also to reduce the chances of having to
  4.1990 -		 * drop packets here under memory pressure.
  4.1991 -		 */
  4.1992 -
  4.1993 -		skb = dev_alloc_skb (pkt_size + 2);
  4.1994 -		if (skb) {
  4.1995 -			skb->dev = dev;
  4.1996 -			skb_reserve (skb, 2);	/* 16 byte align the IP fields. */
  4.1997 -
  4.1998 -			eth_copy_and_sum (skb, &rx_ring[ring_offset + 4], pkt_size, 0);
  4.1999 -			skb_put (skb, pkt_size);
  4.2000 -
  4.2001 -			skb->protocol = eth_type_trans (skb, dev);
  4.2002 -			netif_rx (skb);
  4.2003 -			dev->last_rx = jiffies;
  4.2004 -			tp->stats.rx_bytes += pkt_size;
  4.2005 -			tp->stats.rx_packets++;
  4.2006 -		} else {
  4.2007 -			printk (KERN_WARNING
  4.2008 -				"%s: Memory squeeze, dropping packet.\n",
  4.2009 -				dev->name);
  4.2010 -			tp->stats.rx_dropped++;
  4.2011 -		}
  4.2012 -
  4.2013 -		cur_rx = (cur_rx + rx_size + 4 + 3) & ~3;
  4.2014 -		RTL_W16 (RxBufPtr, cur_rx - 16);
  4.2015 -
  4.2016 -		if (RTL_R16 (IntrStatus) & RxAckBits)
  4.2017 -			RTL_W16_F (IntrStatus, RxAckBits);
  4.2018 -	}
  4.2019 -
  4.2020 -	DPRINTK ("%s: Done rtl8139_rx(), current %4.4x BufAddr %4.4x,"
  4.2021 -		 " free to %4.4x, Cmd %2.2x.\n", dev->name, cur_rx,
  4.2022 -		 RTL_R16 (RxBufAddr),
  4.2023 -		 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
  4.2024 -
  4.2025 -	tp->cur_rx = cur_rx;
  4.2026 -}
  4.2027 -
  4.2028 -
  4.2029 -static void rtl8139_weird_interrupt (struct net_device *dev,
  4.2030 -				     struct rtl8139_private *tp,
  4.2031 -				     void *ioaddr,
  4.2032 -				     int status, int link_changed)
  4.2033 -{
  4.2034 -	DPRINTK ("%s: Abnormal interrupt, status %8.8x.\n",
  4.2035 -		 dev->name, status);
  4.2036 -
  4.2037 -	assert (dev != NULL);
  4.2038 -	assert (tp != NULL);
  4.2039 -	assert (ioaddr != NULL);
  4.2040 -
  4.2041 -	/* Update the error count. */
  4.2042 -	tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  4.2043 -	RTL_W32 (RxMissed, 0);
  4.2044 -
  4.2045 -	if ((status & RxUnderrun) && link_changed &&
  4.2046 -	    (tp->drv_flags & HAS_LNK_CHNG)) {
  4.2047 -		/* Really link-change on new chips. */
  4.2048 -		int lpar = RTL_R16 (NWayLPAR);
  4.2049 -		int duplex = (lpar & LPA_100FULL) || (lpar & 0x01C0) == 0x0040
  4.2050 -				|| tp->mii.force_media;
  4.2051 -		if (tp->mii.full_duplex != duplex) {
  4.2052 -			tp->mii.full_duplex = duplex;
  4.2053 -#if 0
  4.2054 -			RTL_W8 (Cfg9346, Cfg9346_Unlock);
  4.2055 -			RTL_W8 (Config1, tp->mii.full_duplex ? 0x60 : 0x20);
  4.2056 -			RTL_W8 (Cfg9346, Cfg9346_Lock);
  4.2057 -#endif
  4.2058 -		}
  4.2059 -		status &= ~RxUnderrun;
  4.2060 -	}
  4.2061 -
  4.2062 -	/* XXX along with rtl8139_rx_err, are we double-counting errors? */
  4.2063 -	if (status &
  4.2064 -	    (RxUnderrun | RxOverflow | RxErr | RxFIFOOver))
  4.2065 -		tp->stats.rx_errors++;
  4.2066 -
  4.2067 -	if (status & PCSTimeout)
  4.2068 -		tp->stats.rx_length_errors++;
  4.2069 -	if (status & (RxUnderrun | RxFIFOOver))
  4.2070 -		tp->stats.rx_fifo_errors++;
  4.2071 -	if (status & PCIErr) {
  4.2072 -		u16 pci_cmd_status;
  4.2073 -		pci_read_config_word (tp->pci_dev, PCI_STATUS, &pci_cmd_status);
  4.2074 -		pci_write_config_word (tp->pci_dev, PCI_STATUS, pci_cmd_status);
  4.2075 -
  4.2076 -		printk (KERN_ERR "%s: PCI Bus error %4.4x.\n",
  4.2077 -			dev->name, pci_cmd_status);
  4.2078 -	}
  4.2079 -}
  4.2080 -
  4.2081 -
  4.2082 -/* The interrupt handler does all of the Rx thread work and cleans up
  4.2083 -   after the Tx thread. */
  4.2084 -static void rtl8139_interrupt (int irq, void *dev_instance,
  4.2085 -			       struct pt_regs *regs)
  4.2086 -{
  4.2087 -	struct net_device *dev = (struct net_device *) dev_instance;
  4.2088 -	struct rtl8139_private *tp = dev->priv;
  4.2089 -	int boguscnt = max_interrupt_work;
  4.2090 -	void *ioaddr = tp->mmio_addr;
  4.2091 -	int ackstat, status;
  4.2092 -	int link_changed = 0; /* avoid bogus "uninit" warning */
  4.2093 -
  4.2094 -	spin_lock (&tp->lock);
  4.2095 -
  4.2096 -	do {
  4.2097 -		status = RTL_R16 (IntrStatus);
  4.2098 -
  4.2099 -		/* h/w no longer present (hotplug?) or major error, bail */
  4.2100 -		if (status == 0xFFFF)
  4.2101 -			break;
  4.2102 -
  4.2103 -		if ((status &
  4.2104 -		     (PCIErr | PCSTimeout | RxUnderrun | RxOverflow |
  4.2105 -		      RxFIFOOver | TxErr | TxOK | RxErr | RxOK)) == 0)
  4.2106 -			break;
  4.2107 -
  4.2108 -		/* Acknowledge all of the current interrupt sources ASAP, but
  4.2109 -		   an first get an additional status bit from CSCR. */
  4.2110 -		if (status & RxUnderrun)
  4.2111 -			link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit;
  4.2112 -
  4.2113 -		/* The chip takes special action when we clear RxAckBits,
  4.2114 -		 * so we clear them later in rtl8139_rx_interrupt
  4.2115 -		 */
  4.2116 -		ackstat = status & ~(RxAckBits | TxErr);
  4.2117 -		RTL_W16 (IntrStatus, ackstat);
  4.2118 -
  4.2119 -		DPRINTK ("%s: interrupt  status=%#4.4x ackstat=%#4.4x new intstat=%#4.4x.\n",
  4.2120 -			 dev->name, ackstat, status, RTL_R16 (IntrStatus));
  4.2121 -
  4.2122 -		if (netif_running (dev) && (status & RxAckBits))
  4.2123 -			rtl8139_rx_interrupt (dev, tp, ioaddr);
  4.2124 -
  4.2125 -		/* Check uncommon events with one test. */
  4.2126 -		if (status & (PCIErr | PCSTimeout | RxUnderrun | RxOverflow |
  4.2127 -		  	      RxFIFOOver | RxErr))
  4.2128 -			rtl8139_weird_interrupt (dev, tp, ioaddr,
  4.2129 -						 status, link_changed);
  4.2130 -
  4.2131 -		if (netif_running (dev) && (status & (TxOK | TxErr))) {
  4.2132 -			rtl8139_tx_interrupt (dev, tp, ioaddr);
  4.2133 -			if (status & TxErr)
  4.2134 -				RTL_W16 (IntrStatus, TxErr);
  4.2135 -		}
  4.2136 -
  4.2137 -		boguscnt--;
  4.2138 -	} while (boguscnt > 0);
  4.2139 -
  4.2140 -	if (boguscnt <= 0) {
  4.2141 -		printk (KERN_WARNING "%s: Too much work at interrupt, "
  4.2142 -			"IntrStatus=0x%4.4x.\n", dev->name, status);
  4.2143 -
  4.2144 -		/* Clear all interrupt sources. */
  4.2145 -		RTL_W16 (IntrStatus, 0xffff);
  4.2146 -	}
  4.2147 -
  4.2148 -	spin_unlock (&tp->lock);
  4.2149 -
  4.2150 -	DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n",
  4.2151 -		 dev->name, RTL_R16 (IntrStatus));
  4.2152 -}
  4.2153 -
  4.2154 -
  4.2155 -static int rtl8139_close (struct net_device *dev)
  4.2156 -{
  4.2157 -	struct rtl8139_private *tp = dev->priv;
  4.2158 -	void *ioaddr = tp->mmio_addr;
  4.2159 -#if 0
  4.2160 -	int ret = 0;
  4.2161 -#endif
  4.2162 -	unsigned long flags;
  4.2163 -
  4.2164 -	netif_stop_queue (dev);
  4.2165 -
  4.2166 -#if 0
  4.2167 -	if (tp->thr_pid >= 0) {
  4.2168 -		tp->time_to_die = 1;
  4.2169 -		wmb();
  4.2170 -		ret = kill_proc (tp->thr_pid, SIGTERM, 1);
  4.2171 -		if (ret) {
  4.2172 -			printk (KERN_ERR "%s: unable to signal thread\n", dev->name);
  4.2173 -			return ret;
  4.2174 -		}
  4.2175 -		wait_for_completion (&tp->thr_exited);
  4.2176 -	}
  4.2177 -#else
  4.2178 -	del_timer_sync(&tp->timer);
  4.2179 -#endif
  4.2180 -
  4.2181 -	DPRINTK ("%s: Shutting down ethercard, status was 0x%4.4x.\n",
  4.2182 -			dev->name, RTL_R16 (IntrStatus));
  4.2183 -
  4.2184 -	spin_lock_irqsave (&tp->lock, flags);
  4.2185 -
  4.2186 -	/* Stop the chip's Tx and Rx DMA processes. */
  4.2187 -	RTL_W8 (ChipCmd, 0);
  4.2188 -
  4.2189 -	/* Disable interrupts by clearing the interrupt mask. */
  4.2190 -	RTL_W16 (IntrMask, 0);
  4.2191 -
  4.2192 -	/* Update the error counts. */
  4.2193 -	tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  4.2194 -	RTL_W32 (RxMissed, 0);
  4.2195 -
  4.2196 -	spin_unlock_irqrestore (&tp->lock, flags);
  4.2197 -
  4.2198 -	synchronize_irq ();
  4.2199 -	free_irq (dev->irq, dev);
  4.2200 -
  4.2201 -	rtl8139_tx_clear (tp);
  4.2202 -
  4.2203 -	pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  4.2204 -			    tp->rx_ring, tp->rx_ring_dma);
  4.2205 -	pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  4.2206 -			    tp->tx_bufs, tp->tx_bufs_dma);
  4.2207 -	tp->rx_ring = NULL;
  4.2208 -	tp->tx_bufs = NULL;
  4.2209 -
  4.2210 -	/* Green! Put the chip in low-power mode. */
  4.2211 -	RTL_W8 (Cfg9346, Cfg9346_Unlock);
  4.2212 -
  4.2213 -	if (rtl_chip_info[tp->chipset].flags & HasHltClk)
  4.2214 -		RTL_W8 (HltClk, 'H');	/* 'R' would leave the clock running. */
  4.2215 -
  4.2216 -	return 0;
  4.2217 -}
  4.2218 -
  4.2219 -
  4.2220 -/* Get the ethtool Wake-on-LAN settings.  Assumes that wol points to
  4.2221 -   kernel memory, *wol has been initialized as {ETHTOOL_GWOL}, and
  4.2222 -   other threads or interrupts aren't messing with the 8139.  */
  4.2223 -static void netdev_get_wol (struct net_device *dev, struct ethtool_wolinfo *wol)
  4.2224 -{
  4.2225 -	struct rtl8139_private *np = dev->priv;
  4.2226 -	void *ioaddr = np->mmio_addr;
  4.2227 -
  4.2228 -	if (rtl_chip_info[np->chipset].flags & HasLWake) {
  4.2229 -		u8 cfg3 = RTL_R8 (Config3);
  4.2230 -		u8 cfg5 = RTL_R8 (Config5);
  4.2231 -
  4.2232 -		wol->supported = WAKE_PHY | WAKE_MAGIC
  4.2233 -			| WAKE_UCAST | WAKE_MCAST | WAKE_BCAST;
  4.2234 -
  4.2235 -		wol->wolopts = 0;
  4.2236 -		if (cfg3 & Cfg3_LinkUp)
  4.2237 -			wol->wolopts |= WAKE_PHY;
  4.2238 -		if (cfg3 & Cfg3_Magic)
  4.2239 -			wol->wolopts |= WAKE_MAGIC;
  4.2240 -		/* (KON)FIXME: See how netdev_set_wol() handles the
  4.2241 -		   following constants.  */
  4.2242 -		if (cfg5 & Cfg5_UWF)
  4.2243 -			wol->wolopts |= WAKE_UCAST;
  4.2244 -		if (cfg5 & Cfg5_MWF)
  4.2245 -			wol->wolopts |= WAKE_MCAST;
  4.2246 -		if (cfg5 & Cfg5_BWF)
  4.2247 -			wol->wolopts |= WAKE_BCAST;
  4.2248 -	}
  4.2249 -}
  4.2250 -
  4.2251 -
  4.2252 -/* Set the ethtool Wake-on-LAN settings.  Return 0 or -errno.  Assumes
  4.2253 -   that wol points to kernel memory and other threads or interrupts
  4.2254 -   aren't messing with the 8139.  */
  4.2255 -static int netdev_set_wol (struct net_device *dev,
  4.2256 -			   const struct ethtool_wolinfo *wol)
  4.2257 -{
  4.2258 -	struct rtl8139_private *np = dev->priv;
  4.2259 -	void *ioaddr = np->mmio_addr;
  4.2260 -	u32 support;
  4.2261 -	u8 cfg3, cfg5;
  4.2262 -
  4.2263 -	support = ((rtl_chip_info[np->chipset].flags & HasLWake)
  4.2264 -		   ? (WAKE_PHY | WAKE_MAGIC
  4.2265 -		      | WAKE_UCAST | WAKE_MCAST | WAKE_BCAST)
  4.2266 -		   : 0);
  4.2267 -	if (wol->wolopts & ~support)
  4.2268 -		return -EINVAL;
  4.2269 -
  4.2270 -	cfg3 = RTL_R8 (Config3) & ~(Cfg3_LinkUp | Cfg3_Magic);
  4.2271 -	if (wol->wolopts & WAKE_PHY)
  4.2272 -		cfg3 |= Cfg3_LinkUp;
  4.2273 -	if (wol->wolopts & WAKE_MAGIC)
  4.2274 -		cfg3 |= Cfg3_Magic;
  4.2275 -	RTL_W8 (Cfg9346, Cfg9346_Unlock);
  4.2276 -	RTL_W8 (Config3, cfg3);
  4.2277 -	RTL_W8 (Cfg9346, Cfg9346_Lock);
  4.2278 -
  4.2279 -	cfg5 = RTL_R8 (Config5) & ~(Cfg5_UWF | Cfg5_MWF | Cfg5_BWF);
  4.2280 -	/* (KON)FIXME: These are untested.  We may have to set the
  4.2281 -	   CRC0, Wakeup0 and LSBCRC0 registers too, but I have no
  4.2282 -	   documentation.  */
  4.2283 -	if (wol->wolopts & WAKE_UCAST)
  4.2284 -		cfg5 |= Cfg5_UWF;
  4.2285 -	if (wol->wolopts & WAKE_MCAST)
  4.2286 -		cfg5 |= Cfg5_MWF;
  4.2287 -	if (wol->wolopts & WAKE_BCAST)
  4.2288 -		cfg5 |= Cfg5_BWF;
  4.2289 -	RTL_W8 (Config5, cfg5);	/* need not unlock via Cfg9346 */
  4.2290 -
  4.2291 -	return 0;
  4.2292 -}
  4.2293 -
  4.2294 -#if 0
  4.2295 -static int netdev_ethtool_ioctl (struct net_device *dev, void *useraddr)
  4.2296 -{
  4.2297 -	struct rtl8139_private *np = dev->priv;
  4.2298 -	u32 ethcmd;
  4.2299 -
  4.2300 -	/* dev_ioctl() in ../../net/core/dev.c has already checked
  4.2301 -	   capable(CAP_NET_ADMIN), so don't bother with that here.  */
  4.2302 -
  4.2303 -	if (get_user(ethcmd, (u32 *)useraddr))
  4.2304 -		return -EFAULT;
  4.2305 -
  4.2306 -	switch (ethcmd) {
  4.2307 -
  4.2308 -	case ETHTOOL_GDRVINFO: {
  4.2309 -		struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
  4.2310 -		strcpy (info.driver, DRV_NAME);
  4.2311 -		strcpy (info.version, DRV_VERSION);
  4.2312 -		strcpy (info.bus_info, np->pci_dev->slot_name);
  4.2313 -		info.regdump_len = np->regs_len;
  4.2314 -		if (copy_to_user (useraddr, &info, sizeof (info)))
  4.2315 -			return -EFAULT;
  4.2316 -		return 0;
  4.2317 -	}
  4.2318 -
  4.2319 -	/* get settings */
  4.2320 -	case ETHTOOL_GSET: {
  4.2321 -		struct ethtool_cmd ecmd = { ETHTOOL_GSET };
  4.2322 -		spin_lock_irq(&np->lock);
  4.2323 -		mii_ethtool_gset(&np->mii, &ecmd);
  4.2324 -		spin_unlock_irq(&np->lock);
  4.2325 -		if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
  4.2326 -			return -EFAULT;
  4.2327 -		return 0;
  4.2328 -	}
  4.2329 -	/* set settings */
  4.2330 -	case ETHTOOL_SSET: {
  4.2331 -		int r;
  4.2332 -		struct ethtool_cmd ecmd;
  4.2333 -		if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
  4.2334 -			return -EFAULT;
  4.2335 -		spin_lock_irq(&np->lock);
  4.2336 -		r = mii_ethtool_sset(&np->mii, &ecmd);
  4.2337 -		spin_unlock_irq(&np->lock);
  4.2338 -		return r;
  4.2339 -	}
  4.2340 -	/* restart autonegotiation */
  4.2341 -	case ETHTOOL_NWAY_RST: {
  4.2342 -		return mii_nway_restart(&np->mii);
  4.2343 -	}
  4.2344 -	/* get link status */
  4.2345 -	case ETHTOOL_GLINK: {
  4.2346 -		struct ethtool_value edata = {ETHTOOL_GLINK};
  4.2347 -		edata.data = mii_link_ok(&np->mii);
  4.2348 -		if (copy_to_user(useraddr, &edata, sizeof(edata)))
  4.2349 -			return -EFAULT;
  4.2350 -		return 0;
  4.2351 -	}
  4.2352 -
  4.2353 -	/* get message-level */
  4.2354 -	case ETHTOOL_GMSGLVL: {
  4.2355 -		struct ethtool_value edata = {ETHTOOL_GMSGLVL};
  4.2356 -		edata.data = debug;
  4.2357 -		if (copy_to_user(useraddr, &edata, sizeof(edata)))
  4.2358 -			return -EFAULT;
  4.2359 -		return 0;
  4.2360 -	}
  4.2361 -	/* set message-level */
  4.2362 -	case ETHTOOL_SMSGLVL: {
  4.2363 -		struct ethtool_value edata;
  4.2364 -		if (copy_from_user(&edata, useraddr, sizeof(edata)))
  4.2365 -			return -EFAULT;
  4.2366 -		debug = edata.data;
  4.2367 -		return 0;
  4.2368 -	}
  4.2369 -
  4.2370 -	case ETHTOOL_GWOL:
  4.2371 -		{
  4.2372 -			struct ethtool_wolinfo wol = { ETHTOOL_GWOL };
  4.2373 -			spin_lock_irq (&np->lock);
  4.2374 -			netdev_get_wol (dev, &wol);
  4.2375 -			spin_unlock_irq (&np->lock);
  4.2376 -			if (copy_to_user (useraddr, &wol, sizeof (wol)))
  4.2377 -				return -EFAULT;
  4.2378 -			return 0;
  4.2379 -		}
  4.2380 -
  4.2381 -	case ETHTOOL_SWOL:
  4.2382 -		{
  4.2383 -			struct ethtool_wolinfo wol;
  4.2384 -			int rc;
  4.2385 -			if (copy_from_user (&wol, useraddr, sizeof (wol)))
  4.2386 -				return -EFAULT;
  4.2387 -			spin_lock_irq (&np->lock);
  4.2388 -			rc = netdev_set_wol (dev, &wol);
  4.2389 -			spin_unlock_irq (&np->lock);
  4.2390 -			return rc;
  4.2391 -		}
  4.2392 -
  4.2393 -/* TODO: we are too slack to do reg dumping for pio, for now */
  4.2394 -#ifndef CONFIG_8139TOO_PIO
  4.2395 -	/* NIC register dump */
  4.2396 -	case ETHTOOL_GREGS: {
  4.2397 -                struct ethtool_regs regs;
  4.2398 -		unsigned int regs_len = np->regs_len;
  4.2399 -                u8 *regbuf = kmalloc(regs_len, GFP_KERNEL);
  4.2400 -                int rc;
  4.2401 -
  4.2402 -		if (!regbuf)
  4.2403 -			return -ENOMEM;
  4.2404 -		memset(regbuf, 0, regs_len);
  4.2405 -
  4.2406 -                rc = copy_from_user(&regs, useraddr, sizeof(regs));
  4.2407 -		if (rc) {
  4.2408 -			rc = -EFAULT;
  4.2409 -			goto err_out_gregs;
  4.2410 -		}
  4.2411 -                
  4.2412 -                if (regs.len > regs_len)
  4.2413 -                        regs.len = regs_len;
  4.2414 -                if (regs.len < regs_len) {
  4.2415 -			rc = -EINVAL;
  4.2416 -			goto err_out_gregs;
  4.2417 -		}
  4.2418 -
  4.2419 -                regs.version = RTL_REGS_VER;
  4.2420 -                rc = copy_to_user(useraddr, &regs, sizeof(regs));
  4.2421 -		if (rc) {
  4.2422 -			rc = -EFAULT;
  4.2423 -			goto err_out_gregs;
  4.2424 -		}
  4.2425 -
  4.2426 -                useraddr += offsetof(struct ethtool_regs, data);
  4.2427 -
  4.2428 -                spin_lock_irq(&np->lock);
  4.2429 -                memcpy_fromio(regbuf, np->mmio_addr, regs_len);
  4.2430 -                spin_unlock_irq(&np->lock);
  4.2431 -
  4.2432 -                if (copy_to_user(useraddr, regbuf, regs_len))
  4.2433 -                        rc = -EFAULT;
  4.2434 -
  4.2435 -err_out_gregs:
  4.2436 -		kfree(regbuf);
  4.2437 -		return rc;
  4.2438 -	}
  4.2439 -#endif /* CONFIG_8139TOO_PIO */
  4.2440 -
  4.2441 -	/* get string list(s) */
  4.2442 -	case ETHTOOL_GSTRINGS: {
  4.2443 -		struct ethtool_gstrings estr = { ETHTOOL_GSTRINGS };
  4.2444 -
  4.2445 -		if (copy_from_user(&estr, useraddr, sizeof(estr)))
  4.2446 -			return -EFAULT;
  4.2447 -		if (estr.string_set != ETH_SS_STATS)
  4.2448 -			return -EINVAL;
  4.2449 -
  4.2450 -		estr.len = RTL_NUM_STATS;
  4.2451 -		if (copy_to_user(useraddr, &estr, sizeof(estr)))
  4.2452 -			return -EFAULT;
  4.2453 -		if (copy_to_user(useraddr + sizeof(estr),
  4.2454 -				 &ethtool_stats_keys,
  4.2455 -				 sizeof(ethtool_stats_keys)))
  4.2456 -			return -EFAULT;
  4.2457 -		return 0;
  4.2458 -	}
  4.2459 -
  4.2460 -	/* get NIC-specific statistics */
  4.2461 -	case ETHTOOL_GSTATS: {
  4.2462 -		struct ethtool_stats estats = { ETHTOOL_GSTATS };
  4.2463 -		u64 *tmp_stats;
  4.2464 -		const unsigned int sz = sizeof(u64) * RTL_NUM_STATS;
  4.2465 -		int i;
  4.2466 -
  4.2467 -		estats.n_stats = RTL_NUM_STATS;
  4.2468 -		if (copy_to_user(useraddr, &estats, sizeof(estats)))
  4.2469 -			return -EFAULT;
  4.2470 -
  4.2471 -		tmp_stats = kmalloc(sz, GFP_KERNEL);
  4.2472 -		if (!tmp_stats)
  4.2473 -			return -ENOMEM;
  4.2474 -		memset(tmp_stats, 0, sz);
  4.2475 -
  4.2476 -		i = 0;
  4.2477 -		tmp_stats[i++] = np->xstats.early_rx;
  4.2478 -		tmp_stats[i++] = np->xstats.tx_buf_mapped;
  4.2479 -		tmp_stats[i++] = np->xstats.tx_timeouts;
  4.2480 -		tmp_stats[i++] = np->xstats.rx_lost_in_ring;
  4.2481 -		if (i != RTL_NUM_STATS)
  4.2482 -			BUG();
  4.2483 -
  4.2484 -		i = copy_to_user(useraddr + sizeof(estats), tmp_stats, sz);
  4.2485 -		kfree(tmp_stats);
  4.2486 -
  4.2487 -		if (i)
  4.2488 -			return -EFAULT;
  4.2489 -		return 0;
  4.2490 -	}
  4.2491 -	default:
  4.2492 -		break;
  4.2493 -	}
  4.2494 -
  4.2495 -	return -EOPNOTSUPP;
  4.2496 -}
  4.2497 -
  4.2498 -
  4.2499 -static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  4.2500 -{
  4.2501 -	struct rtl8139_private *np = dev->priv;
  4.2502 -	struct mii_ioctl_data *data = (struct mii_ioctl_data *) & rq->ifr_data;
  4.2503 -	int rc;
  4.2504 -
  4.2505 -	if (!netif_running(dev))
  4.2506 -		return -EINVAL;
  4.2507 -
  4.2508 -	if (cmd == SIOCETHTOOL)
  4.2509 -		rc = netdev_ethtool_ioctl(dev, (void *) rq->ifr_data);
  4.2510 -
  4.2511 -	else {
  4.2512 -		spin_lock_irq(&np->lock);
  4.2513 -		rc = generic_mii_ioctl(&np->mii, data, cmd, NULL);
  4.2514 -		spin_unlock_irq(&np->lock);
  4.2515 -	}
  4.2516 -
  4.2517 -	return rc;
  4.2518 -}
  4.2519 -#endif
  4.2520 -
  4.2521 -
  4.2522 -static struct net_device_stats *rtl8139_get_stats (struct net_device *dev)
  4.2523 -{
  4.2524 -	struct rtl8139_private *tp = dev->priv;
  4.2525 -	void *ioaddr = tp->mmio_addr;
  4.2526 -	unsigned long flags;
  4.2527 -
  4.2528 -	if (netif_running(dev)) {
  4.2529 -		spin_lock_irqsave (&tp->lock, flags);
  4.2530 -		tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  4.2531 -		RTL_W32 (RxMissed, 0);
  4.2532 -		spin_unlock_irqrestore (&tp->lock, flags);
  4.2533 -	}
  4.2534 -
  4.2535 -	return &tp->stats;
  4.2536 -}
  4.2537 -
  4.2538 -/* Set or clear the multicast filter for this adaptor.
  4.2539 -   This routine is not state sensitive and need not be SMP locked. */
  4.2540 -
  4.2541 -static void __set_rx_mode (struct net_device *dev)
  4.2542 -{
  4.2543 -	struct rtl8139_private *tp = dev->priv;
  4.2544 -	void *ioaddr = tp->mmio_addr;
  4.2545 -	u32 mc_filter[2];	/* Multicast hash filter */
  4.2546 -	int i, rx_mode;
  4.2547 -	u32 tmp;
  4.2548 -
  4.2549 -	DPRINTK ("%s:   rtl8139_set_rx_mode(%4.4x) done -- Rx config %8.8lx.\n",
  4.2550 -			dev->name, dev->flags, RTL_R32 (RxConfig));
  4.2551 -
  4.2552 -	/* Note: do not reorder, GCC is clever about common statements. */
  4.2553 -	if (dev->flags & IFF_PROMISC) {
  4.2554 -		/* Unconditionally log net taps. */
  4.2555 -		printk (KERN_NOTICE "%s: Promiscuous mode enabled.\n",
  4.2556 -			dev->name);
  4.2557 -		rx_mode =
  4.2558 -		    AcceptBroadcast | AcceptMulticast | AcceptMyPhys |
  4.2559 -		    AcceptAllPhys;
  4.2560 -		mc_filter[1] = mc_filter[0] = 0xffffffff;
  4.2561 -	} else if ((dev->mc_count > multicast_filter_limit)
  4.2562 -		   || (dev->flags & IFF_ALLMULTI)) {
  4.2563 -		/* Too many to filter perfectly -- accept all multicasts. */
  4.2564 -		rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
  4.2565 -		mc_filter[1] = mc_filter[0] = 0xffffffff;
  4.2566 -	} else {
  4.2567 -		struct dev_mc_list *mclist;
  4.2568 -		rx_mode = AcceptBroadcast | AcceptMyPhys;
  4.2569 -		mc_filter[1] = mc_filter[0] = 0;
  4.2570 -		for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  4.2571 -		     i++, mclist = mclist->next) {
  4.2572 -			int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
  4.2573 -
  4.2574 -			mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
  4.2575 -			rx_mode |= AcceptMulticast;
  4.2576 -		}
  4.2577 -	}
  4.2578 -
  4.2579 -	/* We can safely update without stopping the chip. */
  4.2580 -	tmp = rtl8139_rx_config | rx_mode;
  4.2581 -	if (tp->rx_config != tmp) {
  4.2582 -		RTL_W32_F (RxConfig, tmp);
  4.2583 -		tp->rx_config = tmp;
  4.2584 -	}
  4.2585 -	RTL_W32_F (MAR0 + 0, mc_filter[0]);
  4.2586 -	RTL_W32_F (MAR0 + 4, mc_filter[1]);
  4.2587 -}
  4.2588 -
  4.2589 -static void rtl8139_set_rx_mode (struct net_device *dev)
  4.2590 -{
  4.2591 -	unsigned long flags;
  4.2592 -	struct rtl8139_private *tp = dev->priv;
  4.2593 -
  4.2594 -	spin_lock_irqsave (&tp->lock, flags);
  4.2595 -	__set_rx_mode(dev);
  4.2596 -	spin_unlock_irqrestore (&tp->lock, flags);
  4.2597 -}
  4.2598 -
  4.2599 -#ifdef CONFIG_PM
  4.2600 -
  4.2601 -static int rtl8139_suspend (struct pci_dev *pdev, u32 state)
  4.2602 -{
  4.2603 -	struct net_device *dev = pci_get_drvdata (pdev);
  4.2604 -	struct rtl8139_private *tp = dev->priv;
  4.2605 -	void *ioaddr = tp->mmio_addr;
  4.2606 -	unsigned long flags;
  4.2607 -
  4.2608 -	if (!netif_running (dev))
  4.2609 -		return 0;
  4.2610 -
  4.2611 -	netif_device_detach (dev);
  4.2612 -
  4.2613 -	spin_lock_irqsave (&tp->lock, flags);
  4.2614 -
  4.2615 -	/* Disable interrupts, stop Tx and Rx. */
  4.2616 -	RTL_W16 (IntrMask, 0);
  4.2617 -	RTL_W8 (ChipCmd, 0);
  4.2618 -
  4.2619 -	/* Update the error counts. */
  4.2620 -	tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  4.2621 -	RTL_W32 (RxMissed, 0);
  4.2622 -
  4.2623 -	spin_unlock_irqrestore (&tp->lock, flags);
  4.2624 -	return 0;
  4.2625 -}
  4.2626 -
  4.2627 -
  4.2628 -static int rtl8139_resume (struct pci_dev *pdev)
  4.2629 -{
  4.2630 -	struct net_device *dev = pci_get_drvdata (pdev);
  4.2631 -
  4.2632 -	if (!netif_running (dev))
  4.2633 -		return 0;
  4.2634 -	netif_device_attach (dev);
  4.2635 -	rtl8139_hw_start (dev);
  4.2636 -	return 0;
  4.2637 -}
  4.2638 -
  4.2639 -#endif /* CONFIG_PM */
  4.2640 -
  4.2641 -
  4.2642 -static struct pci_driver rtl8139_pci_driver = {
  4.2643 -	.name		= DRV_NAME,
  4.2644 -	.id_table	= rtl8139_pci_tbl,
  4.2645 -	.probe		= rtl8139_init_one,
  4.2646 -	.remove		= __devexit_p(rtl8139_remove_one),
  4.2647 -#ifdef CONFIG_PM
  4.2648 -	.suspend	= rtl8139_suspend,
  4.2649 -	.resume		= rtl8139_resume,
  4.2650 -#endif /* CONFIG_PM */
  4.2651 -};
  4.2652 -
  4.2653 -
  4.2654 -static int __init rtl8139_init_module (void)
  4.2655 -{
  4.2656 -	/* when we're a module, we always print a version message,
  4.2657 -	 * even if no 8139 board is found.
  4.2658 -	 */
  4.2659 -#ifdef MODULE
  4.2660 -	printk (KERN_INFO RTL8139_DRIVER_NAME "\n");
  4.2661 -#endif
  4.2662 -
  4.2663 -	return pci_module_init (&rtl8139_pci_driver);
  4.2664 -}
  4.2665 -
  4.2666 -
  4.2667 -static void __exit rtl8139_cleanup_module (void)
  4.2668 -{
  4.2669 -	pci_unregister_driver (&rtl8139_pci_driver);
  4.2670 -}
  4.2671 -
  4.2672 -
  4.2673 -module_init(rtl8139_init_module);
  4.2674 -module_exit(rtl8139_cleanup_module);
     5.1 --- a/xen/drivers/net/pcnet32.c	Thu Sep 04 15:55:41 2003 +0000
     5.2 +++ b/xen/drivers/net/pcnet32.c	Thu Sep 04 16:24:41 2003 +0000
     5.3 @@ -85,7 +85,9 @@ static int pcnet32vlb;	 /* check for VLB
     5.4  static struct net_device *pcnet32_dev;
     5.5  
     5.6  static int max_interrupt_work = 80;
     5.7 +#ifdef COPYBREAK
     5.8  static int rx_copybreak = 200;
     5.9 +#endif
    5.10  
    5.11  #define PCNET32_PORT_AUI      0x00
    5.12  #define PCNET32_PORT_10BT     0x01
    5.13 @@ -1315,7 +1317,11 @@ pcnet32_rx(struct net_device *dev)
    5.14  	    } else {
    5.15  		int rx_in_place = 0;
    5.16  
    5.17 +#ifdef COPYBREAK
    5.18  		if (pkt_len > rx_copybreak) {
    5.19 +#else
    5.20 +		{
    5.21 +#endif
    5.22  		    struct sk_buff *newskb;
    5.23  				
    5.24  		    if ((newskb = dev_alloc_skb (PKT_BUF_SZ))) {
    5.25 @@ -1332,9 +1338,12 @@ pcnet32_rx(struct net_device *dev)
    5.26  			rx_in_place = 1;
    5.27  		    } else
    5.28  			skb = NULL;
    5.29 -		} else {
    5.30 +		} 
    5.31 +#ifdef COPYBREAK
    5.32 +		else {
    5.33  		    skb = dev_alloc_skb(pkt_len+2);
    5.34 -                }
    5.35 +		}
    5.36 +#endif
    5.37  			    
    5.38  		if (skb == NULL) {
    5.39                      int i;
    5.40 @@ -1351,6 +1360,7 @@ pcnet32_rx(struct net_device *dev)
    5.41  		    break;
    5.42  		}
    5.43  		skb->dev = dev;
    5.44 +#ifdef COPYBREAK
    5.45  		if (!rx_in_place) {
    5.46  		    skb_reserve(skb,2); /* 16 byte align */
    5.47  		    skb_put(skb,pkt_len);	/* Make room */
    5.48 @@ -1358,6 +1368,7 @@ pcnet32_rx(struct net_device *dev)
    5.49  				     (unsigned char *)(lp->rx_skbuff[entry]->tail),
    5.50  				     pkt_len,0);
    5.51  		}
    5.52 +#endif
    5.53  		lp->stats.rx_bytes += skb->len;
    5.54  		skb->protocol=eth_type_trans(skb,dev);
    5.55  		netif_rx(skb);
    5.56 @@ -1676,8 +1687,10 @@ MODULE_PARM(debug, "i");
    5.57  MODULE_PARM_DESC(debug, DRV_NAME " debug level (0-6)");
    5.58  MODULE_PARM(max_interrupt_work, "i");
    5.59  MODULE_PARM_DESC(max_interrupt_work, DRV_NAME " maximum events handled per interrupt");  
    5.60 +#ifdef COPYBREAK
    5.61  MODULE_PARM(rx_copybreak, "i");
    5.62  MODULE_PARM_DESC(rx_copybreak, DRV_NAME " copy breakpoint for copy-only-tiny-frames"); 
    5.63 +#endif
    5.64  MODULE_PARM(tx_start_pt, "i");
    5.65  MODULE_PARM_DESC(tx_start_pt, DRV_NAME " transmit start point (0-3)"); 
    5.66  MODULE_PARM(pcnet32vlb, "i");
     6.1 --- a/xen/drivers/net/tulip/interrupt.c	Thu Sep 04 15:55:41 2003 +0000
     6.2 +++ b/xen/drivers/net/tulip/interrupt.c	Thu Sep 04 16:24:41 2003 +0000
     6.3 @@ -168,6 +168,7 @@ static int tulip_rx(struct net_device *d
     6.4                          if (drop)
     6.5                                  goto throttle;
     6.6  #endif
     6.7 +#ifdef COPYBREAK
     6.8  			/* Check if the packet is long enough to accept without copying
     6.9  			   to a minimally-sized skbuff. */
    6.10  			if (pkt_len < tulip_rx_copybreak
    6.11 @@ -187,6 +188,9 @@ static int tulip_rx(struct net_device *d
    6.12  				       pkt_len);
    6.13  #endif
    6.14  			} else { 	/* Pass up the skb already on the Rx ring. */
    6.15 +#else
    6.16 +			{
    6.17 +#endif /* COPYBREAK */
    6.18  				char *temp = skb_put(skb = tp->rx_buffers[entry].skb,
    6.19  						     pkt_len);
    6.20  
     7.1 --- a/xen/drivers/net/via-rhine.c	Thu Sep 04 15:55:41 2003 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,1933 +0,0 @@
     7.4 -/* via-rhine.c: A Linux Ethernet device driver for VIA Rhine family chips. */
     7.5 -/*
     7.6 -	Written 1998-2001 by Donald Becker.
     7.7 -
     7.8 -	This software may be used and distributed according to the terms of
     7.9 -	the GNU General Public License (GPL), incorporated herein by reference.
    7.10 -	Drivers based on or derived from this code fall under the GPL and must
    7.11 -	retain the authorship, copyright and license notice.  This file is not
    7.12 -	a complete program and may only be used when the entire operating
    7.13 -	system is licensed under the GPL.
    7.14 -
    7.15 -	This driver is designed for the VIA VT86C100A Rhine-I. 
    7.16 -	It also works with the 6102 Rhine-II, and 6105/6105M Rhine-III.   
    7.17 -
    7.18 -	The author may be reached as becker@scyld.com, or C/O
    7.19 -	Scyld Computing Corporation
    7.20 -	410 Severn Ave., Suite 210
    7.21 -	Annapolis MD 21403
    7.22 -
    7.23 -
    7.24 -	This driver contains some changes from the original Donald Becker
    7.25 -	version. He may or may not be interested in bug reports on this
    7.26 -	code. You can find his versions at:
    7.27 -	http://www.scyld.com/network/via-rhine.html
    7.28 -
    7.29 -
    7.30 -	Linux kernel version history:
    7.31 -	
    7.32 -	LK1.1.0:
    7.33 -	- Jeff Garzik: softnet 'n stuff
    7.34 -	
    7.35 -	LK1.1.1:
    7.36 -	- Justin Guyett: softnet and locking fixes
    7.37 -	- Jeff Garzik: use PCI interface
    7.38 -
    7.39 -	LK1.1.2:
    7.40 -	- Urban Widmark: minor cleanups, merges from Becker 1.03a/1.04 versions
    7.41 -
    7.42 -	LK1.1.3:
    7.43 -	- Urban Widmark: use PCI DMA interface (with thanks to the eepro100.c
    7.44 -			 code) update "Theory of Operation" with
    7.45 -			 softnet/locking changes
    7.46 -	- Dave Miller: PCI DMA and endian fixups
    7.47 -	- Jeff Garzik: MOD_xxx race fixes, updated PCI resource allocation
    7.48 -
    7.49 -	LK1.1.4:
    7.50 -	- Urban Widmark: fix gcc 2.95.2 problem and
    7.51 -	                 remove writel's to fixed address 0x7c
    7.52 -
    7.53 -	LK1.1.5:
    7.54 -	- Urban Widmark: mdio locking, bounce buffer changes
    7.55 -	                 merges from Beckers 1.05 version
    7.56 -	                 added netif_running_on/off support
    7.57 -
    7.58 -	LK1.1.6:
    7.59 -	- Urban Widmark: merges from Beckers 1.08b version (VT6102 + mdio)
    7.60 -	                 set netif_running_on/off on startup, del_timer_sync
    7.61 -	
    7.62 -	LK1.1.7:
    7.63 -	- Manfred Spraul: added reset into tx_timeout
    7.64 -
    7.65 -	LK1.1.9:
    7.66 -	- Urban Widmark: merges from Beckers 1.10 version
    7.67 -	                 (media selection + eeprom reload)
    7.68 -	- David Vrabel:  merges from D-Link "1.11" version
    7.69 -	                 (disable WOL and PME on startup)
    7.70 -
    7.71 -	LK1.1.10:
    7.72 -	- Manfred Spraul: use "singlecopy" for unaligned buffers
    7.73 -	                  don't allocate bounce buffers for !ReqTxAlign cards
    7.74 -
    7.75 -	LK1.1.11:
    7.76 -	- David Woodhouse: Set dev->base_addr before the first time we call
    7.77 -					   wait_for_reset(). It's a lot happier that way.
    7.78 -					   Free np->tx_bufs only if we actually allocated it.
    7.79 -
    7.80 -	LK1.1.12:
    7.81 -	- Martin Eriksson: Allow Memory-Mapped IO to be enabled.
    7.82 -
    7.83 -	LK1.1.13 (jgarzik):
    7.84 -	- Add ethtool support
    7.85 -	- Replace some MII-related magic numbers with constants
    7.86 -	
    7.87 -	LK1.1.14 (Ivan G.):
    7.88 - 	- fixes comments for Rhine-III
    7.89 -	- removes W_MAX_TIMEOUT (unused)
    7.90 -	- adds HasDavicomPhy for Rhine-I (basis: linuxfet driver; my card
    7.91 -	  is R-I and has Davicom chip, flag is referenced in kernel driver)
    7.92 -	- sends chip_id as a parameter to wait_for_reset since np is not
    7.93 -	  initialized on first call
    7.94 -	- changes mmio "else if (chip_id==VT6102)" to "else" so it will work
    7.95 -	  for Rhine-III's (documentation says same bit is correct)		
    7.96 -	- transmit frame queue message is off by one - fixed
    7.97 -	- adds IntrNormalSummary to "Something Wicked" exclusion list
    7.98 -	  so normal interrupts will not trigger the message (src: Donald Becker)
    7.99 - 	(Roger Luethi)
   7.100 - 	- show confused chip where to continue after Tx error
   7.101 - 	- location of collision counter is chip specific
   7.102 - 	- allow selecting backoff algorithm (module parameter)
   7.103 -
   7.104 -	LK1.1.15 (jgarzik):
   7.105 -	- Use new MII lib helper generic_mii_ioctl
   7.106 -
   7.107 -	LK1.1.16 (Roger Luethi)
   7.108 -	- Etherleak fix
   7.109 -	- Handle Tx buffer underrun
   7.110 -	- Fix bugs in full duplex handling
   7.111 -	- New reset code uses "force reset" cmd on Rhine-II
   7.112 -	- Various clean ups
   7.113 -
   7.114 -	LK1.1.17 (Roger Luethi)
   7.115 -	- Fix race in via_rhine_start_tx()
   7.116 -	- On errors, wait for Tx engine to turn off before scavenging
   7.117 -	- Handle Tx descriptor write-back race on Rhine-II
   7.118 -	- Force flushing for PCI posted writes
   7.119 -	- More reset code changes
   7.120 -
   7.121 -*/
   7.122 -
   7.123 -#define DRV_NAME	"via-rhine"
   7.124 -#define DRV_VERSION	"1.1.17"
   7.125 -#define DRV_RELDATE	"March-1-2003"
   7.126 -
   7.127 -#include <linux/module.h>
   7.128 -#include <linux/kernel.h>
   7.129 -#include <linux/string.h>
   7.130 -#include <linux/timer.h>
   7.131 -#include <linux/errno.h>
   7.132 -#include <linux/ioport.h>
   7.133 -#include <linux/slab.h>
   7.134 -#include <linux/interrupt.h>
   7.135 -#include <linux/pci.h>
   7.136 -#include <linux/netdevice.h>
   7.137 -#include <linux/etherdevice.h>
   7.138 -#include <linux/skbuff.h>
   7.139 -#include <linux/init.h>
   7.140 -#include <linux/delay.h>
   7.141 -#include <linux/mii.h>
   7.142 -#include <linux/ethtool.h>
   7.143 -#include <linux/crc32.h>
   7.144 -#include <asm/processor.h>		/* Processor type for cache alignment. */
   7.145 -#include <asm/bitops.h>
   7.146 -#include <asm/io.h>
   7.147 -#include <asm/irq.h>
   7.148 -#include <asm/uaccess.h>
   7.149 -
   7.150 -#undef RX_RING_SIZE
   7.151 -#undef TX_RING_SIZE
   7.152 -
   7.153 -/* A few user-configurable values.
   7.154 -   These may be modified when a driver module is loaded. */
   7.155 -
   7.156 -static int debug = 1;			/* 1 normal messages, 0 quiet .. 7 verbose. */
   7.157 -static int max_interrupt_work = 20;
   7.158 -
   7.159 -/* Set the copy breakpoint for the copy-only-tiny-frames scheme.
   7.160 -   Setting to > 1518 effectively disables this feature. */
   7.161 -static int rx_copybreak;
   7.162 -
   7.163 -/* Select a backoff algorithm (Ethernet capture effect) */
   7.164 -static int backoff;
   7.165 -
   7.166 -/* Used to pass the media type, etc.
   7.167 -   Both 'options[]' and 'full_duplex[]' should exist for driver
   7.168 -   interoperability.
   7.169 -   The media type is usually passed in 'options[]'.
   7.170 -   The default is autonegotation for speed and duplex.
   7.171 -     This should rarely be overridden.
   7.172 -   Use option values 0x10/0x20 for 10Mbps, 0x100,0x200 for 100Mbps.
   7.173 -   Use option values 0x10 and 0x100 for forcing half duplex fixed speed.
   7.174 -   Use option values 0x20 and 0x200 for forcing full duplex operation.
   7.175 -*/
   7.176 -#define MAX_UNITS 8		/* More are supported, limit only on options */
   7.177 -static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
   7.178 -static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
   7.179 -
   7.180 -/* Maximum number of multicast addresses to filter (vs. rx-all-multicast).
   7.181 -   The Rhine has a 64 element 8390-like hash table.  */
   7.182 -static const int multicast_filter_limit = 32;
   7.183 -
   7.184 -
   7.185 -/* Operational parameters that are set at compile time. */
   7.186 -
   7.187 -/* Keep the ring sizes a power of two for compile efficiency.
   7.188 -   The compiler will convert <unsigned>'%'<2^N> into a bit mask.
   7.189 -   Making the Tx ring too large decreases the effectiveness of channel
   7.190 -   bonding and packet priority.
   7.191 -   There are no ill effects from too-large receive rings. */
   7.192 -#define TX_RING_SIZE	16
   7.193 -#define TX_QUEUE_LEN	10		/* Limit ring entries actually used.  */
   7.194 -#define RX_RING_SIZE	16
   7.195 -
   7.196 -
   7.197 -/* Operational parameters that usually are not changed. */
   7.198 -
   7.199 -/* Time in jiffies before concluding the transmitter is hung. */
   7.200 -#define TX_TIMEOUT  (2*HZ)
   7.201 -
   7.202 -#define PKT_BUF_SZ		1536			/* Size of each temporary Rx buffer.*/
   7.203 -
   7.204 -#if !defined(__OPTIMIZE__)  ||  !defined(__KERNEL__)
   7.205 -#warning  You must compile this file with the correct options!
   7.206 -#warning  See the last lines of the source file.
   7.207 -#error  You must compile this driver with "-O".
   7.208 -#endif
   7.209 -
   7.210 -/* These identify the driver base version and may not be removed. */
   7.211 -static char version[] __devinitdata =
   7.212 -KERN_INFO DRV_NAME ".c:v1.10-LK" DRV_VERSION "  " DRV_RELDATE "  Written by Donald Becker\n"
   7.213 -KERN_INFO "  http://www.scyld.com/network/via-rhine.html\n";
   7.214 -
   7.215 -static char shortname[] = DRV_NAME;
   7.216 -
   7.217 -
   7.218 -/* This driver was written to use PCI memory space, however most versions
   7.219 -   of the Rhine only work correctly with I/O space accesses. */
   7.220 -#ifdef CONFIG_VIA_RHINE_MMIO
   7.221 -#define USE_MEM
   7.222 -#else
   7.223 -#define USE_IO
   7.224 -#undef readb
   7.225 -#undef readw
   7.226 -#undef readl
   7.227 -#undef writeb
   7.228 -#undef writew
   7.229 -#undef writel
   7.230 -#define readb inb
   7.231 -#define readw inw
   7.232 -#define readl inl
   7.233 -#define writeb outb
   7.234 -#define writew outw
   7.235 -#define writel outl
   7.236 -#endif
   7.237 -
   7.238 -MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
   7.239 -MODULE_DESCRIPTION("VIA Rhine PCI Fast Ethernet driver");
   7.240 -MODULE_LICENSE("GPL");
   7.241 -
   7.242 -MODULE_PARM(max_interrupt_work, "i");
   7.243 -MODULE_PARM(debug, "i");
   7.244 -MODULE_PARM(rx_copybreak, "i");
   7.245 -MODULE_PARM(backoff, "i");
   7.246 -MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
   7.247 -MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
   7.248 -MODULE_PARM_DESC(max_interrupt_work, "VIA Rhine maximum events handled per interrupt");
   7.249 -MODULE_PARM_DESC(debug, "VIA Rhine debug level (0-7)");
   7.250 -MODULE_PARM_DESC(rx_copybreak, "VIA Rhine copy breakpoint for copy-only-tiny-frames");
   7.251 -MODULE_PARM_DESC(backoff, "VIA Rhine: Bits 0-3: backoff algorithm");
   7.252 -MODULE_PARM_DESC(options, "VIA Rhine: Bits 0-3: media type, bit 17: full duplex");
   7.253 -MODULE_PARM_DESC(full_duplex, "VIA Rhine full duplex setting(s) (1)");
   7.254 -
   7.255 -/*
   7.256 -				Theory of Operation
   7.257 -
   7.258 -I. Board Compatibility
   7.259 -
   7.260 -This driver is designed for the VIA 86c100A Rhine-II PCI Fast Ethernet
   7.261 -controller.
   7.262 -
   7.263 -II. Board-specific settings
   7.264 -
   7.265 -Boards with this chip are functional only in a bus-master PCI slot.
   7.266 -
   7.267 -Many operational settings are loaded from the EEPROM to the Config word at
   7.268 -offset 0x78. For most of these settings, this driver assumes that they are
   7.269 -correct.
   7.270 -If this driver is compiled to use PCI memory space operations the EEPROM
   7.271 -must be configured to enable memory ops.
   7.272 -
   7.273 -III. Driver operation
   7.274 -
   7.275 -IIIa. Ring buffers
   7.276 -
   7.277 -This driver uses two statically allocated fixed-size descriptor lists
   7.278 -formed into rings by a branch from the final descriptor to the beginning of
   7.279 -the list.  The ring sizes are set at compile time by RX/TX_RING_SIZE.
   7.280 -
   7.281 -IIIb/c. Transmit/Receive Structure
   7.282 -
   7.283 -This driver attempts to use a zero-copy receive and transmit scheme.
   7.284 -
   7.285 -Alas, all data buffers are required to start on a 32 bit boundary, so
   7.286 -the driver must often copy transmit packets into bounce buffers.
   7.287 -
   7.288 -The driver allocates full frame size skbuffs for the Rx ring buffers at
   7.289 -open() time and passes the skb->data field to the chip as receive data
   7.290 -buffers.  When an incoming frame is less than RX_COPYBREAK bytes long,
   7.291 -a fresh skbuff is allocated and the frame is copied to the new skbuff.
   7.292 -When the incoming frame is larger, the skbuff is passed directly up the
   7.293 -protocol stack.  Buffers consumed this way are replaced by newly allocated
   7.294 -skbuffs in the last phase of via_rhine_rx().
   7.295 -
   7.296 -The RX_COPYBREAK value is chosen to trade-off the memory wasted by
   7.297 -using a full-sized skbuff for small frames vs. the copying costs of larger
   7.298 -frames.  New boards are typically used in generously configured machines
   7.299 -and the underfilled buffers have negligible impact compared to the benefit of
   7.300 -a single allocation size, so the default value of zero results in never
   7.301 -copying packets.  When copying is done, the cost is usually mitigated by using
   7.302 -a combined copy/checksum routine.  Copying also preloads the cache, which is
   7.303 -most useful with small frames.
   7.304 -
   7.305 -Since the VIA chips are only able to transfer data to buffers on 32 bit
   7.306 -boundaries, the IP header at offset 14 in an ethernet frame isn't
   7.307 -longword aligned for further processing.  Copying these unaligned buffers
   7.308 -has the beneficial effect of 16-byte aligning the IP header.
   7.309 -
   7.310 -IIId. Synchronization
   7.311 -
   7.312 -The driver runs as two independent, single-threaded flows of control.  One
   7.313 -is the send-packet routine, which enforces single-threaded use by the
   7.314 -dev->priv->lock spinlock. The other thread is the interrupt handler, which 
   7.315 -is single threaded by the hardware and interrupt handling software.
   7.316 -
   7.317 -The send packet thread has partial control over the Tx ring. It locks the 
   7.318 -dev->priv->lock whenever it's queuing a Tx packet. If the next slot in the ring
   7.319 -is not available it stops the transmit queue by calling netif_stop_queue.
   7.320 -
   7.321 -The interrupt handler has exclusive control over the Rx ring and records stats
   7.322 -from the Tx ring.  After reaping the stats, it marks the Tx queue entry as
   7.323 -empty by incrementing the dirty_tx mark. If at least half of the entries in
   7.324 -the Rx ring are available the transmit queue is woken up if it was stopped.
   7.325 -
   7.326 -IV. Notes
   7.327 -
   7.328 -IVb. References
   7.329 -
   7.330 -Preliminary VT86C100A manual from http://www.via.com.tw/
   7.331 -http://www.scyld.com/expert/100mbps.html
   7.332 -http://www.scyld.com/expert/NWay.html
   7.333 -ftp://ftp.via.com.tw/public/lan/Products/NIC/VT86C100A/Datasheet/VT86C100A03.pdf
   7.334 -ftp://ftp.via.com.tw/public/lan/Products/NIC/VT6102/Datasheet/VT6102_021.PDF
   7.335 -
   7.336 -
   7.337 -IVc. Errata
   7.338 -
   7.339 -The VT86C100A manual is not reliable information.
   7.340 -The 3043 chip does not handle unaligned transmit or receive buffers, resulting
   7.341 -in significant performance degradation for bounce buffer copies on transmit
   7.342 -and unaligned IP headers on receive.
   7.343 -The chip does not pad to minimum transmit length.
   7.344 -
   7.345 -*/
   7.346 -
   7.347 -
   7.348 -/* This table drives the PCI probe routines.  It's mostly boilerplate in all
   7.349 -   of the drivers, and will likely be provided by some future kernel.
   7.350 -   Note the matching code -- the first table entry matchs all 56** cards but
   7.351 -   second only the 1234 card.
   7.352 -*/
   7.353 -
   7.354 -enum pci_flags_bit {
   7.355 -	PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
   7.356 -	PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,
   7.357 -};
   7.358 -
   7.359 -enum via_rhine_chips {
   7.360 -	VT86C100A = 0,
   7.361 -	VT6102,
   7.362 -	VT6105,
   7.363 -	VT6105M
   7.364 -};
   7.365 -
   7.366 -struct via_rhine_chip_info {
   7.367 -	const char *name;
   7.368 -	u16 pci_flags;
   7.369 -	int io_size;
   7.370 -	int drv_flags;
   7.371 -};
   7.372 -
   7.373 -
   7.374 -enum chip_capability_flags {
   7.375 -	CanHaveMII=1, HasESIPhy=2, HasDavicomPhy=4,
   7.376 -	ReqTxAlign=0x10, HasWOL=0x20, };
   7.377 -
   7.378 -#ifdef USE_MEM
   7.379 -#define RHINE_IOTYPE (PCI_USES_MEM | PCI_USES_MASTER | PCI_ADDR1)
   7.380 -#else
   7.381 -#define RHINE_IOTYPE (PCI_USES_IO  | PCI_USES_MASTER | PCI_ADDR0)
   7.382 -#endif
   7.383 -/* Beware of PCI posted writes */
   7.384 -#define IOSYNC	do { readb(dev->base_addr + StationAddr); } while (0)
   7.385 -
   7.386 -/* directly indexed by enum via_rhine_chips, above */
   7.387 -static struct via_rhine_chip_info via_rhine_chip_info[] __devinitdata =
   7.388 -{
   7.389 -	{ "VIA VT86C100A Rhine", RHINE_IOTYPE, 128,
   7.390 -	  CanHaveMII | ReqTxAlign | HasDavicomPhy },
   7.391 -	{ "VIA VT6102 Rhine-II", RHINE_IOTYPE, 256,
   7.392 -	  CanHaveMII | HasWOL },
   7.393 -	{ "VIA VT6105 Rhine-III", RHINE_IOTYPE, 256,
   7.394 -	  CanHaveMII | HasWOL },	  
   7.395 -	{ "VIA VT6105M Rhine-III", RHINE_IOTYPE, 256,
   7.396 -	  CanHaveMII | HasWOL },	  	  	 
   7.397 -};
   7.398 -
   7.399 -static struct pci_device_id via_rhine_pci_tbl[] __devinitdata =
   7.400 -{
   7.401 -	{0x1106, 0x3043, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VT86C100A},
   7.402 -	{0x1106, 0x3065, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VT6102},
   7.403 -	{0x1106, 0x3106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VT6105},
   7.404 -	{0x1106, 0x3053, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VT6105M},	
   7.405 -	{0,}			/* terminate list */
   7.406 -};
   7.407 -MODULE_DEVICE_TABLE(pci, via_rhine_pci_tbl);
   7.408 -
   7.409 -
   7.410 -/* Offsets to the device registers. */
   7.411 -enum register_offsets {
   7.412 -	StationAddr=0x00, RxConfig=0x06, TxConfig=0x07, ChipCmd=0x08,
   7.413 -	IntrStatus=0x0C, IntrEnable=0x0E,
   7.414 -	MulticastFilter0=0x10, MulticastFilter1=0x14,
   7.415 -	RxRingPtr=0x18, TxRingPtr=0x1C, GFIFOTest=0x54,
   7.416 -	MIIPhyAddr=0x6C, MIIStatus=0x6D, PCIBusConfig=0x6E,
   7.417 -	MIICmd=0x70, MIIRegAddr=0x71, MIIData=0x72, MACRegEEcsr=0x74,
   7.418 -	ConfigA=0x78, ConfigB=0x79, ConfigC=0x7A, ConfigD=0x7B,
   7.419 -	RxMissed=0x7C, RxCRCErrs=0x7E, MiscCmd=0x81,
   7.420 -	StickyHW=0x83, IntrStatus2=0x84, WOLcrClr=0xA4, WOLcgClr=0xA7,
   7.421 -	PwrcsrClr=0xAC,
   7.422 -};
   7.423 -
   7.424 -/* Bits in ConfigD */
   7.425 -enum backoff_bits {
   7.426 -	BackOptional=0x01, BackModify=0x02,
   7.427 -	BackCaptureEffect=0x04, BackRandom=0x08
   7.428 -};
   7.429 -
   7.430 -#ifdef USE_MEM
   7.431 -/* Registers we check that mmio and reg are the same. */
   7.432 -int mmio_verify_registers[] = {
   7.433 -	RxConfig, TxConfig, IntrEnable, ConfigA, ConfigB, ConfigC, ConfigD,
   7.434 -	0
   7.435 -};
   7.436 -#endif
   7.437 -
   7.438 -/* Bits in the interrupt status/mask registers. */
   7.439 -enum intr_status_bits {
   7.440 -	IntrRxDone=0x0001, IntrRxErr=0x0004, IntrRxEmpty=0x0020,
   7.441 -	IntrTxDone=0x0002, IntrTxError=0x0008, IntrTxUnderrun=0x0210,
   7.442 -	IntrPCIErr=0x0040,
   7.443 -	IntrStatsMax=0x0080, IntrRxEarly=0x0100,
   7.444 -	IntrRxOverflow=0x0400, IntrRxDropped=0x0800, IntrRxNoBuf=0x1000,
   7.445 -	IntrTxAborted=0x2000, IntrLinkChange=0x4000,
   7.446 -	IntrRxWakeUp=0x8000,
   7.447 -	IntrNormalSummary=0x0003, IntrAbnormalSummary=0xC260,
   7.448 -	IntrTxDescRace=0x080000,	/* mapped from IntrStatus2 */
   7.449 -	IntrTxErrSummary=0x082210,
   7.450 -};
   7.451 -
   7.452 -/* The Rx and Tx buffer descriptors. */
   7.453 -struct rx_desc {
   7.454 -	s32 rx_status;
   7.455 -	u32 desc_length; /* Chain flag, Buffer/frame length */
   7.456 -	u32 addr;
   7.457 -	u32 next_desc;
   7.458 -};
   7.459 -struct tx_desc {
   7.460 -	s32 tx_status;
   7.461 -	u32 desc_length; /* Chain flag, Tx Config, Frame length */
   7.462 -	u32 addr;
   7.463 -	u32 next_desc;
   7.464 -};
   7.465 -
   7.466 -/* Initial value for tx_desc.desc_length, Buffer size goes to bits 0-10 */
   7.467 -#define TXDESC 0x00e08000
   7.468 -
   7.469 -enum rx_status_bits {
   7.470 -	RxOK=0x8000, RxWholePkt=0x0300, RxErr=0x008F
   7.471 -};
   7.472 -
   7.473 -/* Bits in *_desc.*_status */
   7.474 -enum desc_status_bits {
   7.475 -	DescOwn=0x80000000
   7.476 -};
   7.477 -
   7.478 -/* Bits in ChipCmd. */
   7.479 -enum chip_cmd_bits {
   7.480 -	CmdInit=0x0001, CmdStart=0x0002, CmdStop=0x0004, CmdRxOn=0x0008,
   7.481 -	CmdTxOn=0x0010, CmdTxDemand=0x0020, CmdRxDemand=0x0040,
   7.482 -	CmdEarlyRx=0x0100, CmdEarlyTx=0x0200, CmdFDuplex=0x0400,
   7.483 -	CmdNoTxPoll=0x0800, CmdReset=0x8000,
   7.484 -};
   7.485 -
   7.486 -#define MAX_MII_CNT	4
   7.487 -struct netdev_private {
   7.488 -	/* Descriptor rings */
   7.489 -	struct rx_desc *rx_ring;
   7.490 -	struct tx_desc *tx_ring;
   7.491 -	dma_addr_t rx_ring_dma;
   7.492 -	dma_addr_t tx_ring_dma;
   7.493 -
   7.494 -	/* The addresses of receive-in-place skbuffs. */
   7.495 -	struct sk_buff *rx_skbuff[RX_RING_SIZE];
   7.496 -	dma_addr_t rx_skbuff_dma[RX_RING_SIZE];
   7.497 -
   7.498 -	/* The saved address of a sent-in-place packet/buffer, for later free(). */
   7.499 -	struct sk_buff *tx_skbuff[TX_RING_SIZE];
   7.500 -	dma_addr_t tx_skbuff_dma[TX_RING_SIZE];
   7.501 -
   7.502 -	/* Tx bounce buffers */
   7.503 -	unsigned char *tx_buf[TX_RING_SIZE];
   7.504 -	unsigned char *tx_bufs;
   7.505 -	dma_addr_t tx_bufs_dma;
   7.506 -
   7.507 -	struct pci_dev *pdev;
   7.508 -	struct net_device_stats stats;
   7.509 -	struct timer_list timer;	/* Media monitoring timer. */
   7.510 -	spinlock_t lock;
   7.511 -
   7.512 -	/* Frequently used values: keep some adjacent for cache effect. */
   7.513 -	int chip_id, drv_flags;
   7.514 -	struct rx_desc *rx_head_desc;
   7.515 -	unsigned int cur_rx, dirty_rx;		/* Producer/consumer ring indices */
   7.516 -	unsigned int cur_tx, dirty_tx;
   7.517 -	unsigned int rx_buf_sz;				/* Based on MTU+slack. */
   7.518 -	u16 chip_cmd;						/* Current setting for ChipCmd */
   7.519 -
   7.520 -	/* These values are keep track of the transceiver/media in use. */
   7.521 -	unsigned int default_port:4;		/* Last dev->if_port value. */
   7.522 -	u8 tx_thresh, rx_thresh;
   7.523 -
   7.524 -	/* MII transceiver section. */
   7.525 -	unsigned char phys[MAX_MII_CNT];			/* MII device addresses. */
   7.526 -	unsigned int mii_cnt;			/* number of MIIs found, but only the first one is used */
   7.527 -	u16 mii_status;						/* last read MII status */
   7.528 -	struct mii_if_info mii_if;
   7.529 -};
   7.530 -
   7.531 -static int  mdio_read(struct net_device *dev, int phy_id, int location);
   7.532 -static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
   7.533 -static int  via_rhine_open(struct net_device *dev);
   7.534 -static void via_rhine_check_duplex(struct net_device *dev);
   7.535 -static void via_rhine_timer(unsigned long data);
   7.536 -static void via_rhine_tx_timeout(struct net_device *dev);
   7.537 -static int  via_rhine_start_tx(struct sk_buff *skb, struct net_device *dev);
   7.538 -static void via_rhine_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
   7.539 -static void via_rhine_tx(struct net_device *dev);
   7.540 -static void via_rhine_rx(struct net_device *dev);
   7.541 -static void via_rhine_error(struct net_device *dev, int intr_status);
   7.542 -static void via_rhine_set_rx_mode(struct net_device *dev);
   7.543 -static struct net_device_stats *via_rhine_get_stats(struct net_device *dev);
   7.544 -#if 0
   7.545 -static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
   7.546 -#endif
   7.547 -static int  via_rhine_close(struct net_device *dev);
   7.548 -
   7.549 -static inline u32 get_intr_status(struct net_device *dev)
   7.550 -{
   7.551 -	long ioaddr = dev->base_addr;
   7.552 -	struct netdev_private *np = dev->priv;
   7.553 -	u32 intr_status;
   7.554 -
   7.555 -	intr_status = readw(ioaddr + IntrStatus);
   7.556 -	/* On Rhine-II, Bit 3 indicates Tx descriptor write-back race. */
   7.557 -	if (np->chip_id == VT6102)
   7.558 -		intr_status |= readb(ioaddr + IntrStatus2) << 16;
   7.559 -	return intr_status;
   7.560 -}
   7.561 -
   7.562 -static void wait_for_reset(struct net_device *dev, int chip_id, char *name)
   7.563 -{
   7.564 -	long ioaddr = dev->base_addr;
   7.565 -	int boguscnt = 20;
   7.566 -
   7.567 -	IOSYNC;
   7.568 -
   7.569 -	if (readw(ioaddr + ChipCmd) & CmdReset) {
   7.570 -		printk(KERN_INFO "%s: Reset not complete yet. "
   7.571 -			"Trying harder.\n", name);
   7.572 -
   7.573 -		/* Rhine-II needs to be forced sometimes */
   7.574 -		if (chip_id == VT6102)
   7.575 -			writeb(0x40, ioaddr + MiscCmd);
   7.576 -
   7.577 -		/* VT86C100A may need long delay after reset (dlink) */
   7.578 -		/* Seen on Rhine-II as well (rl) */
   7.579 -		while ((readw(ioaddr + ChipCmd) & CmdReset) && --boguscnt)
   7.580 -			udelay(5);
   7.581 -
   7.582 -	}
   7.583 -
   7.584 -	if (debug > 1)
   7.585 -		printk(KERN_INFO "%s: Reset %s.\n", name,
   7.586 -			boguscnt ? "succeeded" : "failed");
   7.587 -}
   7.588 -
   7.589 -#ifdef USE_MEM
   7.590 -static void __devinit enable_mmio(long ioaddr, int chip_id)
   7.591 -{
   7.592 -	int n;
   7.593 -	if (chip_id == VT86C100A) {
   7.594 -		/* More recent docs say that this bit is reserved ... */
   7.595 -		n = inb(ioaddr + ConfigA) | 0x20;
   7.596 -		outb(n, ioaddr + ConfigA);
   7.597 -	} else {
   7.598 -		n = inb(ioaddr + ConfigD) | 0x80;
   7.599 -		outb(n, ioaddr + ConfigD);
   7.600 -	}
   7.601 -}
   7.602 -#endif
   7.603 -
   7.604 -static void __devinit reload_eeprom(long ioaddr)
   7.605 -{
   7.606 -	int i;
   7.607 -	outb(0x20, ioaddr + MACRegEEcsr);
   7.608 -	/* Typically 2 cycles to reload. */
   7.609 -	for (i = 0; i < 150; i++)
   7.610 -		if (! (inb(ioaddr + MACRegEEcsr) & 0x20))
   7.611 -			break;
   7.612 -}
   7.613 -
   7.614 -static int __devinit via_rhine_init_one (struct pci_dev *pdev,
   7.615 -					 const struct pci_device_id *ent)
   7.616 -{
   7.617 -	struct net_device *dev;
   7.618 -	struct netdev_private *np;
   7.619 -	int i, option;
   7.620 -	int chip_id = (int) ent->driver_data;
   7.621 -	static int card_idx = -1;
   7.622 -	long ioaddr;
   7.623 -	long memaddr;
   7.624 -	int io_size;
   7.625 -	int pci_flags;
   7.626 -#ifdef USE_MEM
   7.627 -	long ioaddr0;
   7.628 -#endif
   7.629 -	
   7.630 -/* when built into the kernel, we only print version if device is found */
   7.631 -#ifndef MODULE
   7.632 -	static int printed_version;
   7.633 -	if (!printed_version++)
   7.634 -		printk(version);
   7.635 -#endif
   7.636 -
   7.637 -	card_idx++;
   7.638 -	option = card_idx < MAX_UNITS ? options[card_idx] : 0;
   7.639 -	io_size = via_rhine_chip_info[chip_id].io_size;
   7.640 -	pci_flags = via_rhine_chip_info[chip_id].pci_flags;
   7.641 -
   7.642 -	if (pci_enable_device (pdev))
   7.643 -		goto err_out;
   7.644 -
   7.645 -	/* this should always be supported */
   7.646 -	if (pci_set_dma_mask(pdev, 0xffffffff)) {
   7.647 -		printk(KERN_ERR "32-bit PCI DMA addresses not supported by the card!?\n");
   7.648 -		goto err_out;
   7.649 -	}
   7.650 -	
   7.651 -	/* sanity check */
   7.652 -	if ((pci_resource_len (pdev, 0) < io_size) ||
   7.653 -	    (pci_resource_len (pdev, 1) < io_size)) {
   7.654 -		printk (KERN_ERR "Insufficient PCI resources, aborting\n");
   7.655 -		goto err_out;
   7.656 -	}
   7.657 -
   7.658 -	ioaddr = pci_resource_start (pdev, 0);
   7.659 -	memaddr = pci_resource_start (pdev, 1);
   7.660 -
   7.661 -	if (pci_flags & PCI_USES_MASTER)
   7.662 -		pci_set_master (pdev);
   7.663 -
   7.664 -	dev = alloc_etherdev(sizeof(*np));
   7.665 -	if (dev == NULL) {
   7.666 -		printk (KERN_ERR "init_ethernet failed for card #%d\n", card_idx);
   7.667 -		goto err_out;
   7.668 -	}
   7.669 -	SET_MODULE_OWNER(dev);
   7.670 -	
   7.671 -	if (pci_request_regions(pdev, shortname))
   7.672 -		goto err_out_free_netdev;
   7.673 -
   7.674 -#ifdef USE_MEM
   7.675 -	ioaddr0 = ioaddr;
   7.676 -	enable_mmio(ioaddr0, chip_id);
   7.677 -
   7.678 -	ioaddr = (long) ioremap (memaddr, io_size);
   7.679 -	if (!ioaddr) {
   7.680 -		printk (KERN_ERR "ioremap failed for device %s, region 0x%X @ 0x%lX\n",
   7.681 -				pdev->slot_name, io_size, memaddr);
   7.682 -		goto err_out_free_res;
   7.683 -	}
   7.684 -
   7.685 -	/* Check that selected MMIO registers match the PIO ones */
   7.686 -	i = 0;
   7.687 -	while (mmio_verify_registers[i]) {
   7.688 -		int reg = mmio_verify_registers[i++];
   7.689 -		unsigned char a = inb(ioaddr0+reg);
   7.690 -		unsigned char b = readb(ioaddr+reg);
   7.691 -		if (a != b) {
   7.692 -			printk (KERN_ERR "MMIO do not match PIO [%02x] (%02x != %02x)\n",
   7.693 -					reg, a, b);
   7.694 -			goto err_out_unmap;
   7.695 -		}
   7.696 -	}
   7.697 -#endif
   7.698 -
   7.699 -	/* D-Link provided reset code (with comment additions) */
   7.700 -	if (via_rhine_chip_info[chip_id].drv_flags & HasWOL) {
   7.701 -		unsigned char byOrgValue;
   7.702 -
   7.703 -		/* clear sticky bit before reset & read ethernet address */
   7.704 -		byOrgValue = readb(ioaddr + StickyHW);
   7.705 -		byOrgValue = byOrgValue & 0xFC;
   7.706 -		writeb(byOrgValue, ioaddr + StickyHW);
   7.707 -
   7.708 -		/* (bits written are cleared?) */
   7.709 -		/* disable force PME-enable */
   7.710 -		writeb(0x80, ioaddr + WOLcgClr);
   7.711 -		/* disable power-event config bit */
   7.712 -		writeb(0xFF, ioaddr + WOLcrClr);
   7.713 -		/* clear power status (undocumented in vt6102 docs?) */
   7.714 -		writeb(0xFF, ioaddr + PwrcsrClr);
   7.715 -	}
   7.716 -
   7.717 -	/* Reset the chip to erase previous misconfiguration. */
   7.718 -	writew(CmdReset, ioaddr + ChipCmd);
   7.719 -
   7.720 -	dev->base_addr = ioaddr;
   7.721 -	wait_for_reset(dev, chip_id, shortname);
   7.722 -
   7.723 -	/* Reload the station address from the EEPROM. */
   7.724 -#ifdef USE_IO
   7.725 -	reload_eeprom(ioaddr);
   7.726 -#else
   7.727 -	reload_eeprom(ioaddr0);
   7.728 -	/* Reloading from eeprom overwrites cfgA-D, so we must re-enable MMIO.
   7.729 -	   If reload_eeprom() was done first this could be avoided, but it is
   7.730 -	   not known if that still works with the "win98-reboot" problem. */
   7.731 -	enable_mmio(ioaddr0, chip_id);
   7.732 -#endif
   7.733 -
   7.734 -	for (i = 0; i < 6; i++)
   7.735 -		dev->dev_addr[i] = readb(ioaddr + StationAddr + i);
   7.736 -
   7.737 -	if (!is_valid_ether_addr(dev->dev_addr)) {
   7.738 -		printk(KERN_ERR "Invalid MAC address for card #%d\n", card_idx);
   7.739 -		goto err_out_unmap;
   7.740 -	}
   7.741 -
   7.742 -	if (chip_id == VT6102) {
   7.743 -		/*
   7.744 -		 * for 3065D, EEPROM reloaded will cause bit 0 in MAC_REG_CFGA
   7.745 -		 * turned on.  it makes MAC receive magic packet
   7.746 -		 * automatically. So, we turn it off. (D-Link)
   7.747 -		 */
   7.748 -		writeb(readb(ioaddr + ConfigA) & 0xFE, ioaddr + ConfigA);
   7.749 -	}
   7.750 -
   7.751 -	/* Select backoff algorithm */
   7.752 -	if (backoff)
   7.753 -		writeb(readb(ioaddr + ConfigD) & (0xF0 | backoff),
   7.754 -			ioaddr + ConfigD);
   7.755 -
   7.756 -	dev->irq = pdev->irq;
   7.757 -
   7.758 -	np = dev->priv;
   7.759 -	spin_lock_init (&np->lock);
   7.760 -	np->chip_id = chip_id;
   7.761 -	np->drv_flags = via_rhine_chip_info[chip_id].drv_flags;
   7.762 -	np->pdev = pdev;
   7.763 -	np->mii_if.dev = dev;
   7.764 -	np->mii_if.mdio_read = mdio_read;
   7.765 -	np->mii_if.mdio_write = mdio_write;
   7.766 -	np->mii_if.phy_id_mask = 0x1f;
   7.767 -	np->mii_if.reg_num_mask = 0x1f;
   7.768 -
   7.769 -	if (dev->mem_start)
   7.770 -		option = dev->mem_start;
   7.771 -
   7.772 -	/* The chip-specific entries in the device structure. */
   7.773 -	dev->open = via_rhine_open;
   7.774 -	dev->hard_start_xmit = via_rhine_start_tx;
   7.775 -	dev->stop = via_rhine_close;
   7.776 -	dev->get_stats = via_rhine_get_stats;
   7.777 -	dev->set_multicast_list = via_rhine_set_rx_mode;
   7.778 -#if 0
   7.779 -	dev->do_ioctl = netdev_ioctl;
   7.780 -#endif
   7.781 -	dev->tx_timeout = via_rhine_tx_timeout;
   7.782 -	dev->watchdog_timeo = TX_TIMEOUT;
   7.783 -#if 0
   7.784 -	if (np->drv_flags & ReqTxAlign)
   7.785 -#endif
   7.786 -		dev->features |= NETIF_F_SG|NETIF_F_HW_CSUM;
   7.787 -
   7.788 -	/* dev->name not defined before register_netdev()! */
   7.789 -	i = register_netdev(dev);
   7.790 -	if (i)
   7.791 -		goto err_out_unmap;
   7.792 -
   7.793 -	/* The lower four bits are the media type. */
   7.794 -	if (option > 0) {
   7.795 -		if (option & 0x220)
   7.796 -			np->mii_if.full_duplex = 1;
   7.797 -		np->default_port = option & 15;
   7.798 -	}
   7.799 -	if (card_idx < MAX_UNITS  &&  full_duplex[card_idx] > 0)
   7.800 -		np->mii_if.full_duplex = 1;
   7.801 -
   7.802 -	if (np->mii_if.full_duplex) {
   7.803 -		printk(KERN_INFO "%s: Set to forced full duplex, autonegotiation"
   7.804 -			   " disabled.\n", dev->name);
   7.805 -		np->mii_if.force_media = 1;
   7.806 -	}
   7.807 -
   7.808 -	printk(KERN_INFO "%s: %s at 0x%lx, ",
   7.809 -		   dev->name, via_rhine_chip_info[chip_id].name,
   7.810 -		   (pci_flags & PCI_USES_IO) ? ioaddr : memaddr);
   7.811 -
   7.812 -	for (i = 0; i < 5; i++)
   7.813 -			printk("%2.2x:", dev->dev_addr[i]);
   7.814 -	printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], pdev->irq);
   7.815 -
   7.816 -	pci_set_drvdata(pdev, dev);
   7.817 -
   7.818 -	if (np->drv_flags & CanHaveMII) {
   7.819 -		int phy, phy_idx = 0;
   7.820 -		np->phys[0] = 1;		/* Standard for this chip. */
   7.821 -		for (phy = 1; phy < 32 && phy_idx < MAX_MII_CNT; phy++) {
   7.822 -			int mii_status = mdio_read(dev, phy, 1);
   7.823 -			if (mii_status != 0xffff  &&  mii_status != 0x0000) {
   7.824 -				np->phys[phy_idx++] = phy;
   7.825 -				np->mii_if.advertising = mdio_read(dev, phy, 4);
   7.826 -				printk(KERN_INFO "%s: MII PHY found at address %d, status "
   7.827 -					   "0x%4.4x advertising %4.4x Link %4.4x.\n",
   7.828 -					   dev->name, phy, mii_status, np->mii_if.advertising,
   7.829 -					   mdio_read(dev, phy, 5));
   7.830 -
   7.831 -				/* set IFF_RUNNING */
   7.832 -				if (mii_status & BMSR_LSTATUS)
   7.833 -					netif_carrier_on(dev);
   7.834 -				else
   7.835 -					netif_carrier_off(dev);
   7.836 -			}
   7.837 -		}
   7.838 -		np->mii_cnt = phy_idx;
   7.839 -		np->mii_if.phy_id = np->phys[0];
   7.840 -	}
   7.841 -
   7.842 -	/* Allow forcing the media type. */
   7.843 -	if (option > 0) {
   7.844 -		if (option & 0x220)
   7.845 -			np->mii_if.full_duplex = 1;
   7.846 -		np->default_port = option & 0x3ff;
   7.847 -		if (np->default_port & 0x330) {
   7.848 -			/* FIXME: shouldn't someone check this variable? */
   7.849 -			/* np->medialock = 1; */
   7.850 -			printk(KERN_INFO "  Forcing %dMbs %s-duplex operation.\n",
   7.851 -				   (option & 0x300 ? 100 : 10),
   7.852 -				   (option & 0x220 ? "full" : "half"));
   7.853 -			if (np->mii_cnt)
   7.854 -				mdio_write(dev, np->phys[0], MII_BMCR,
   7.855 -						   ((option & 0x300) ? 0x2000 : 0) |  /* 100mbps? */
   7.856 -						   ((option & 0x220) ? 0x0100 : 0));  /* Full duplex? */
   7.857 -		}
   7.858 -	}
   7.859 -
   7.860 -    alert_slow_netdevice(dev, (char *)via_rhine_chip_info[chip_id].name);
   7.861 -
   7.862 -	return 0;
   7.863 -
   7.864 -err_out_unmap:
   7.865 -#ifdef USE_MEM
   7.866 -	iounmap((void *)ioaddr);
   7.867 -err_out_free_res:
   7.868 -#endif
   7.869 -	pci_release_regions(pdev);
   7.870 -err_out_free_netdev:
   7.871 -	kfree (dev);
   7.872 -err_out:
   7.873 -	return -ENODEV;
   7.874 -}
   7.875 -
   7.876 -static int alloc_ring(struct net_device* dev)
   7.877 -{
   7.878 -	struct netdev_private *np = dev->priv;
   7.879 -	void *ring;
   7.880 -	dma_addr_t ring_dma;
   7.881 -
   7.882 -	ring = pci_alloc_consistent(np->pdev, 
   7.883 -				    RX_RING_SIZE * sizeof(struct rx_desc) +
   7.884 -				    TX_RING_SIZE * sizeof(struct tx_desc),
   7.885 -				    &ring_dma);
   7.886 -	if (!ring) {
   7.887 -		printk(KERN_ERR "Could not allocate DMA memory.\n");
   7.888 -		return -ENOMEM;
   7.889 -	}
   7.890 -	if (np->drv_flags & ReqTxAlign) {
   7.891 -		np->tx_bufs = pci_alloc_consistent(np->pdev, PKT_BUF_SZ * TX_RING_SIZE,
   7.892 -								   &np->tx_bufs_dma);
   7.893 -		if (np->tx_bufs == NULL) {
   7.894 -			pci_free_consistent(np->pdev, 
   7.895 -				    RX_RING_SIZE * sizeof(struct rx_desc) +
   7.896 -				    TX_RING_SIZE * sizeof(struct tx_desc),
   7.897 -				    ring, ring_dma);
   7.898 -			return -ENOMEM;
   7.899 -		}
   7.900 -	}
   7.901 -
   7.902 -	np->rx_ring = ring;
   7.903 -	np->tx_ring = ring + RX_RING_SIZE * sizeof(struct rx_desc);
   7.904 -	np->rx_ring_dma = ring_dma;
   7.905 -	np->tx_ring_dma = ring_dma + RX_RING_SIZE * sizeof(struct rx_desc);
   7.906 -
   7.907 -	return 0;
   7.908 -}
   7.909 -
   7.910 -void free_ring(struct net_device* dev)
   7.911 -{
   7.912 -	struct netdev_private *np = dev->priv;
   7.913 -
   7.914 -	pci_free_consistent(np->pdev, 
   7.915 -			    RX_RING_SIZE * sizeof(struct rx_desc) +
   7.916 -			    TX_RING_SIZE * sizeof(struct tx_desc),
   7.917 -			    np->rx_ring, np->rx_ring_dma);
   7.918 -	np->tx_ring = NULL;
   7.919 -
   7.920 -	if (np->tx_bufs)
   7.921 -		pci_free_consistent(np->pdev, PKT_BUF_SZ * TX_RING_SIZE,
   7.922 -							np->tx_bufs, np->tx_bufs_dma);
   7.923 -
   7.924 -	np->tx_bufs = NULL;
   7.925 -
   7.926 -}
   7.927 -
   7.928 -static void alloc_rbufs(struct net_device *dev)
   7.929 -{
   7.930 -	struct netdev_private *np = dev->priv;
   7.931 -	dma_addr_t next;
   7.932 -	int i;
   7.933 -
   7.934 -	np->dirty_rx = np->cur_rx = 0;
   7.935 -
   7.936 -	np->rx_buf_sz = (dev->mtu <= 1500 ? PKT_BUF_SZ : dev->mtu + 32);
   7.937 -	np->rx_head_desc = &np->rx_ring[0];
   7.938 -	next = np->rx_ring_dma;
   7.939 -	
   7.940 -	/* Init the ring entries */
   7.941 -	for (i = 0; i < RX_RING_SIZE; i++) {
   7.942 -		np->rx_ring[i].rx_status = 0;
   7.943 -		np->rx_ring[i].desc_length = cpu_to_le32(np->rx_buf_sz);
   7.944 -		next += sizeof(struct rx_desc);
   7.945 -		np->rx_ring[i].next_desc = cpu_to_le32(next);
   7.946 -		np->rx_skbuff[i] = 0;
   7.947 -	}
   7.948 -	/* Mark the last entry as wrapping the ring. */
   7.949 -	np->rx_ring[i-1].next_desc = cpu_to_le32(np->rx_ring_dma);
   7.950 -
   7.951 -	/* Fill in the Rx buffers.  Handle allocation failure gracefully. */
   7.952 -	for (i = 0; i < RX_RING_SIZE; i++) {
   7.953 -		struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz);
   7.954 -		np->rx_skbuff[i] = skb;
   7.955 -		if (skb == NULL)
   7.956 -			break;
   7.957 -		skb->dev = dev;                 /* Mark as being used by this device. */
   7.958 -
   7.959 -		np->rx_skbuff_dma[i] =
   7.960 -			pci_map_single(np->pdev, skb->tail, np->rx_buf_sz,
   7.961 -						   PCI_DMA_FROMDEVICE);
   7.962 -
   7.963 -		np->rx_ring[i].addr = cpu_to_le32(np->rx_skbuff_dma[i]);
   7.964 -		np->rx_ring[i].rx_status = cpu_to_le32(DescOwn);
   7.965 -	}
   7.966 -	np->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
   7.967 -}
   7.968 -
   7.969 -static void free_rbufs(struct net_device* dev)
   7.970 -{
   7.971 -	struct netdev_private *np = dev->priv;
   7.972 -	int i;
   7.973 -
   7.974 -	/* Free all the skbuffs in the Rx queue. */
   7.975 -	for (i = 0; i < RX_RING_SIZE; i++) {
   7.976 -		np->rx_ring[i].rx_status = 0;
   7.977 -		np->rx_ring[i].addr = cpu_to_le32(0xBADF00D0); /* An invalid address. */
   7.978 -		if (np->rx_skbuff[i]) {
   7.979 -			pci_unmap_single(np->pdev,
   7.980 -							 np->rx_skbuff_dma[i],
   7.981 -							 np->rx_buf_sz, PCI_DMA_FROMDEVICE);
   7.982 -			dev_kfree_skb(np->rx_skbuff[i]);
   7.983 -		}
   7.984 -		np->rx_skbuff[i] = 0;
   7.985 -	}
   7.986 -}
   7.987 -
   7.988 -static void alloc_tbufs(struct net_device* dev)
   7.989 -{
   7.990 -	struct netdev_private *np = dev->priv;
   7.991 -	dma_addr_t next;
   7.992 -	int i;
   7.993 -
   7.994 -	np->dirty_tx = np->cur_tx = 0;
   7.995 -	next = np->tx_ring_dma;
   7.996 -	for (i = 0; i < TX_RING_SIZE; i++) {
   7.997 -		np->tx_skbuff[i] = 0;
   7.998 -		np->tx_ring[i].tx_status = 0;
   7.999 -		np->tx_ring[i].desc_length = cpu_to_le32(TXDESC);
  7.1000 -		next += sizeof(struct tx_desc);
  7.1001 -		np->tx_ring[i].next_desc = cpu_to_le32(next);
  7.1002 -		np->tx_buf[i] = &np->tx_bufs[i * PKT_BUF_SZ];
  7.1003 -	}
  7.1004 -	np->tx_ring[i-1].next_desc = cpu_to_le32(np->tx_ring_dma);
  7.1005 -
  7.1006 -}
  7.1007 -
  7.1008 -static void free_tbufs(struct net_device* dev)
  7.1009 -{
  7.1010 -	struct netdev_private *np = dev->priv;
  7.1011 -	int i;
  7.1012 -
  7.1013 -	for (i = 0; i < TX_RING_SIZE; i++) {
  7.1014 -		np->tx_ring[i].tx_status = 0;
  7.1015 -		np->tx_ring[i].desc_length = cpu_to_le32(TXDESC);
  7.1016 -		np->tx_ring[i].addr = cpu_to_le32(0xBADF00D0); /* An invalid address. */
  7.1017 -		if (np->tx_skbuff[i]) {
  7.1018 -			if (np->tx_skbuff_dma[i]) {
  7.1019 -				pci_unmap_single(np->pdev,
  7.1020 -								 np->tx_skbuff_dma[i],
  7.1021 -								 np->tx_skbuff[i]->len, PCI_DMA_TODEVICE);
  7.1022 -			}
  7.1023 -			dev_kfree_skb(np->tx_skbuff[i]);
  7.1024 -		}
  7.1025 -		np->tx_skbuff[i] = 0;
  7.1026 -		np->tx_buf[i] = 0;
  7.1027 -	}
  7.1028 -}
  7.1029 -
  7.1030 -static void init_registers(struct net_device *dev)
  7.1031 -{
  7.1032 -	struct netdev_private *np = dev->priv;
  7.1033 -	long ioaddr = dev->base_addr;
  7.1034 -	int i;
  7.1035 -
  7.1036 -	for (i = 0; i < 6; i++)
  7.1037 -		writeb(dev->dev_addr[i], ioaddr + StationAddr + i);
  7.1038 -
  7.1039 -	/* Initialize other registers. */
  7.1040 -	writew(0x0006, ioaddr + PCIBusConfig);	/* Tune configuration??? */
  7.1041 -	/* Configure initial FIFO thresholds. */
  7.1042 -	writeb(0x20, ioaddr + TxConfig);
  7.1043 -	np->tx_thresh = 0x20;
  7.1044 -	np->rx_thresh = 0x60;			/* Written in via_rhine_set_rx_mode(). */
  7.1045 -	np->mii_if.full_duplex = 0;
  7.1046 -
  7.1047 -	if (dev->if_port == 0)
  7.1048 -		dev->if_port = np->default_port;
  7.1049 -
  7.1050 -	writel(np->rx_ring_dma, ioaddr + RxRingPtr);
  7.1051 -	writel(np->tx_ring_dma, ioaddr + TxRingPtr);
  7.1052 -
  7.1053 -	via_rhine_set_rx_mode(dev);
  7.1054 -
  7.1055 -	/* Enable interrupts by setting the interrupt mask. */
  7.1056 -	writew(IntrRxDone | IntrRxErr | IntrRxEmpty| IntrRxOverflow |
  7.1057 -		   IntrRxDropped | IntrRxNoBuf | IntrTxAborted |
  7.1058 -		   IntrTxDone | IntrTxError | IntrTxUnderrun |
  7.1059 -		   IntrPCIErr | IntrStatsMax | IntrLinkChange,
  7.1060 -		   ioaddr + IntrEnable);
  7.1061 -
  7.1062 -	np->chip_cmd = CmdStart|CmdTxOn|CmdRxOn|CmdNoTxPoll;
  7.1063 -	if (np->mii_if.force_media)
  7.1064 -		np->chip_cmd |= CmdFDuplex;
  7.1065 -	writew(np->chip_cmd, ioaddr + ChipCmd);
  7.1066 -
  7.1067 -	via_rhine_check_duplex(dev);
  7.1068 -
  7.1069 -	/* The LED outputs of various MII xcvrs should be configured.  */
  7.1070 -	/* For NS or Mison phys, turn on bit 1 in register 0x17 */
  7.1071 -	/* For ESI phys, turn on bit 7 in register 0x17. */
  7.1072 -	mdio_write(dev, np->phys[0], 0x17, mdio_read(dev, np->phys[0], 0x17) |
  7.1073 -			   (np->drv_flags & HasESIPhy) ? 0x0080 : 0x0001);
  7.1074 -}
  7.1075 -/* Read and write over the MII Management Data I/O (MDIO) interface. */
  7.1076 -
  7.1077 -static int mdio_read(struct net_device *dev, int phy_id, int regnum)
  7.1078 -{
  7.1079 -	long ioaddr = dev->base_addr;
  7.1080 -	int boguscnt = 1024;
  7.1081 -
  7.1082 -	/* Wait for a previous command to complete. */
  7.1083 -	while ((readb(ioaddr + MIICmd) & 0x60) && --boguscnt > 0)
  7.1084 -		;
  7.1085 -	writeb(0x00, ioaddr + MIICmd);
  7.1086 -	writeb(phy_id, ioaddr + MIIPhyAddr);
  7.1087 -	writeb(regnum, ioaddr + MIIRegAddr);
  7.1088 -	writeb(0x40, ioaddr + MIICmd);			/* Trigger read */
  7.1089 -	boguscnt = 1024;
  7.1090 -	while ((readb(ioaddr + MIICmd) & 0x40) && --boguscnt > 0)
  7.1091 -		;
  7.1092 -	return readw(ioaddr + MIIData);
  7.1093 -}
  7.1094 -
  7.1095 -static void mdio_write(struct net_device *dev, int phy_id, int regnum, int value)
  7.1096 -{
  7.1097 -	struct netdev_private *np = dev->priv;
  7.1098 -	long ioaddr = dev->base_addr;
  7.1099 -	int boguscnt = 1024;
  7.1100 -
  7.1101 -	if (phy_id == np->phys[0]) {
  7.1102 -		switch (regnum) {
  7.1103 -		case MII_BMCR:					/* Is user forcing speed/duplex? */
  7.1104 -			if (value & 0x9000)			/* Autonegotiation. */
  7.1105 -				np->mii_if.force_media = 0;
  7.1106 -			else
  7.1107 -				np->mii_if.full_duplex = (value & 0x0100) ? 1 : 0;
  7.1108 -			break;
  7.1109 -		case MII_ADVERTISE:
  7.1110 -			np->mii_if.advertising = value;
  7.1111 -			break;
  7.1112 -		}
  7.1113 -	}
  7.1114 -
  7.1115 -	/* Wait for a previous command to complete. */
  7.1116 -	while ((readb(ioaddr + MIICmd) & 0x60) && --boguscnt > 0)
  7.1117 -		;
  7.1118 -	writeb(0x00, ioaddr + MIICmd);
  7.1119 -	writeb(phy_id, ioaddr + MIIPhyAddr);
  7.1120 -	writeb(regnum, ioaddr + MIIRegAddr);
  7.1121 -	writew(value, ioaddr + MIIData);
  7.1122 -	writeb(0x20, ioaddr + MIICmd);			/* Trigger write. */
  7.1123 -}
  7.1124 -
  7.1125 -
  7.1126 -static int via_rhine_open(struct net_device *dev)
  7.1127 -{
  7.1128 -	struct netdev_private *np = dev->priv;
  7.1129 -	long ioaddr = dev->base_addr;
  7.1130 -	int i;
  7.1131 -
  7.1132 -	/* Reset the chip. */
  7.1133 -	writew(CmdReset, ioaddr + ChipCmd);
  7.1134 -
  7.1135 -	i = request_irq(np->pdev->irq, &via_rhine_interrupt, SA_SHIRQ, dev->name, dev);
  7.1136 -	if (i)
  7.1137 -		return i;
  7.1138 -
  7.1139 -	if (debug > 1)
  7.1140 -		printk(KERN_DEBUG "%s: via_rhine_open() irq %d.\n",
  7.1141 -			   dev->name, np->pdev->irq);
  7.1142 -	
  7.1143 -	i = alloc_ring(dev);
  7.1144 -	if (i)
  7.1145 -		return i;
  7.1146 -	alloc_rbufs(dev);
  7.1147 -	alloc_tbufs(dev);
  7.1148 -	wait_for_reset(dev, np->chip_id, dev->name);
  7.1149 -	init_registers(dev);
  7.1150 -	if (debug > 2)
  7.1151 -		printk(KERN_DEBUG "%s: Done via_rhine_open(), status %4.4x "
  7.1152 -			   "MII status: %4.4x.\n",
  7.1153 -			   dev->name, readw(ioaddr + ChipCmd),
  7.1154 -			   mdio_read(dev, np->phys[0], MII_BMSR));
  7.1155 -
  7.1156 -	netif_start_queue(dev);
  7.1157 -
  7.1158 -	/* Set the timer to check for link beat. */
  7.1159 -	init_timer(&np->timer);
  7.1160 -	np->timer.expires = jiffies + 2;
  7.1161 -	np->timer.data = (unsigned long)dev;
  7.1162 -	np->timer.function = &via_rhine_timer;				/* timer handler */
  7.1163 -	add_timer(&np->timer);
  7.1164 -
  7.1165 -	return 0;
  7.1166 -}
  7.1167 -
  7.1168 -static void via_rhine_check_duplex(struct net_device *dev)
  7.1169 -{
  7.1170 -	struct netdev_private *np = dev->priv;
  7.1171 -	long ioaddr = dev->base_addr;
  7.1172 -	int mii_lpa = mdio_read(dev, np->phys[0], MII_LPA);
  7.1173 -	int negotiated = mii_lpa & np->mii_if.advertising;
  7.1174 -	int duplex;
  7.1175 -
  7.1176 -	if (np->mii_if.force_media  ||  mii_lpa == 0xffff)
  7.1177 -		return;
  7.1178 -	duplex = (negotiated & 0x0100) || (negotiated & 0x01C0) == 0x0040;
  7.1179 -	if (np->mii_if.full_duplex != duplex) {
  7.1180 -		np->mii_if.full_duplex = duplex;
  7.1181 -		if (debug)
  7.1182 -			printk(KERN_INFO "%s: Setting %s-duplex based on MII #%d link"
  7.1183 -				   " partner capability of %4.4x.\n", dev->name,
  7.1184 -				   duplex ? "full" : "half", np->phys[0], mii_lpa);
  7.1185 -		if (duplex)
  7.1186 -			np->chip_cmd |= CmdFDuplex;
  7.1187 -		else
  7.1188 -			np->chip_cmd &= ~CmdFDuplex;
  7.1189 -		writew(np->chip_cmd, ioaddr + ChipCmd);
  7.1190 -	}
  7.1191 -}
  7.1192 -
  7.1193 -
  7.1194 -static void via_rhine_timer(unsigned long data)
  7.1195 -{
  7.1196 -	struct net_device *dev = (struct net_device *)data;
  7.1197 -	struct netdev_private *np = dev->priv;
  7.1198 -	long ioaddr = dev->base_addr;
  7.1199 -	int next_tick = 10*HZ;
  7.1200 -	int mii_status;
  7.1201 -
  7.1202 -	if (debug > 3) {
  7.1203 -		printk(KERN_DEBUG "%s: VIA Rhine monitor tick, status %4.4x.\n",
  7.1204 -			   dev->name, readw(ioaddr + IntrStatus));
  7.1205 -	}
  7.1206 -
  7.1207 -	spin_lock_irq (&np->lock);
  7.1208 -
  7.1209 -	via_rhine_check_duplex(dev);
  7.1210 -
  7.1211 -	/* make IFF_RUNNING follow the MII status bit "Link established" */
  7.1212 -	mii_status = mdio_read(dev, np->phys[0], MII_BMSR);
  7.1213 -	if ( (mii_status & BMSR_LSTATUS) != (np->mii_status & BMSR_LSTATUS) ) {
  7.1214 -		if (mii_status & BMSR_LSTATUS)
  7.1215 -			netif_carrier_on(dev);
  7.1216 -		else
  7.1217 -			netif_carrier_off(dev);
  7.1218 -	}
  7.1219 -	np->mii_status = mii_status;
  7.1220 -
  7.1221 -	spin_unlock_irq (&np->lock);
  7.1222 -
  7.1223 -	np->timer.expires = jiffies + next_tick;
  7.1224 -	add_timer(&np->timer);
  7.1225 -}
  7.1226 -
  7.1227 -
  7.1228 -static void via_rhine_tx_timeout (struct net_device *dev)
  7.1229 -{
  7.1230 -	struct netdev_private *np = dev->priv;
  7.1231 -	long ioaddr = dev->base_addr;
  7.1232 -
  7.1233 -	printk (KERN_WARNING "%s: Transmit timed out, status %4.4x, PHY status "
  7.1234 -		"%4.4x, resetting...\n",
  7.1235 -		dev->name, readw (ioaddr + IntrStatus),
  7.1236 -		mdio_read (dev, np->phys[0], MII_BMSR));
  7.1237 -
  7.1238 -	dev->if_port = 0;
  7.1239 -
  7.1240 -	/* protect against concurrent rx interrupts */
  7.1241 -	disable_irq(np->pdev->irq);
  7.1242 -
  7.1243 -	spin_lock(&np->lock);
  7.1244 -
  7.1245 -	/* Reset the chip. */
  7.1246 -	writew(CmdReset, ioaddr + ChipCmd);
  7.1247 -
  7.1248 -	/* clear all descriptors */
  7.1249 -	free_tbufs(dev);
  7.1250 -	free_rbufs(dev);
  7.1251 -	alloc_tbufs(dev);
  7.1252 -	alloc_rbufs(dev);
  7.1253 -
  7.1254 -	/* Reinitialize the hardware. */
  7.1255 -	wait_for_reset(dev, np->chip_id, dev->name);
  7.1256 -	init_registers(dev);
  7.1257 -	
  7.1258 -	spin_unlock(&np->lock);
  7.1259 -	enable_irq(np->pdev->irq);
  7.1260 -
  7.1261 -	dev->trans_start = jiffies;
  7.1262 -	np->stats.tx_errors++;
  7.1263 -	netif_wake_queue(dev);
  7.1264 -}
  7.1265 -
  7.1266 -static int via_rhine_start_tx(struct sk_buff *skb, struct net_device *dev)
  7.1267 -{
  7.1268 -	struct netdev_private *np = dev->priv;
  7.1269 -	unsigned entry;
  7.1270 -	u32 intr_status;
  7.1271 -
  7.1272 -	/* Caution: the write order is important here, set the field
  7.1273 -	   with the "ownership" bits last. */
  7.1274 -
  7.1275 -	/* Calculate the next Tx descriptor entry. */
  7.1276 -	entry = np->cur_tx % TX_RING_SIZE;
  7.1277 -
  7.1278 -	if (skb->len < ETH_ZLEN) {
  7.1279 -#if 0
  7.1280 -		skb = skb_padto(skb, ETH_ZLEN);
  7.1281 -		if(skb == NULL)
  7.1282 -			return 0;
  7.1283 -#else
  7.1284 -		memset(np->tx_buf[entry], 0, ETH_ZLEN);
  7.1285 -#endif
  7.1286 -	}
  7.1287 -
  7.1288 -	np->tx_skbuff[entry] = skb;
  7.1289 -
  7.1290 -#if 0
  7.1291 -	if ((np->drv_flags & ReqTxAlign) &&
  7.1292 -		(((long)skb->data & 3) || skb_shinfo(skb)->nr_frags != 0 || skb->ip_summed == CHECKSUM_HW)
  7.1293 -		) {
  7.1294 -#endif
  7.1295 -		/* Must use alignment buffer. */
  7.1296 -		if (skb->len > PKT_BUF_SZ) {
  7.1297 -			/* packet too long, drop it */
  7.1298 -			dev_kfree_skb(skb);
  7.1299 -			np->tx_skbuff[entry] = NULL;
  7.1300 -			np->stats.tx_dropped++;
  7.1301 -			return 0;
  7.1302 -		}
  7.1303 -#if 0
  7.1304 -		skb_copy_and_csum_dev(skb, np->tx_buf[entry]);
  7.1305 -#else
  7.1306 -		skb_copy_bits(skb, 0, np->tx_buf[entry], skb->len);
  7.1307 -#endif
  7.1308 -		np->tx_skbuff_dma[entry] = 0;
  7.1309 -		np->tx_ring[entry].addr = cpu_to_le32(np->tx_bufs_dma +
  7.1310 -										  (np->tx_buf[entry] - np->tx_bufs));
  7.1311 -#if 0
  7.1312 -	} else {
  7.1313 -		np->tx_skbuff_dma[entry] =
  7.1314 -			pci_map_single(np->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
  7.1315 -		np->tx_ring[entry].addr = cpu_to_le32(np->tx_skbuff_dma[entry]);
  7.1316 -	}
  7.1317 -#endif
  7.1318 -
  7.1319 -	np->tx_ring[entry].desc_length = 
  7.1320 -		cpu_to_le32(TXDESC | (skb->len >= ETH_ZLEN ? skb->len : ETH_ZLEN));
  7.1321 -
  7.1322 -	/* lock eth irq */
  7.1323 -	spin_lock_irq (&np->lock);
  7.1324 -	wmb();
  7.1325 -	np->tx_ring[entry].tx_status = cpu_to_le32(DescOwn);
  7.1326 -	wmb();
  7.1327 -
  7.1328 -	np->cur_tx++;
  7.1329 -
  7.1330 -	/* Non-x86 Todo: explicitly flush cache lines here. */
  7.1331 -
  7.1332 -	/*
  7.1333 -	 * Wake the potentially-idle transmit channel unless errors are
  7.1334 -	 * pending (the ISR must sort them out first).
  7.1335 -	 */
  7.1336 -	intr_status = get_intr_status(dev);
  7.1337 -	if ((intr_status & IntrTxErrSummary) == 0) {
  7.1338 -		writew(CmdTxDemand | np->chip_cmd, dev->base_addr + ChipCmd);
  7.1339 -	}
  7.1340 -	IOSYNC;
  7.1341 -
  7.1342 -	if (np->cur_tx == np->dirty_tx + TX_QUEUE_LEN)
  7.1343 -		netif_stop_queue(dev);
  7.1344 -
  7.1345 -	dev->trans_start = jiffies;
  7.1346 -
  7.1347 -	spin_unlock_irq (&np->lock);
  7.1348 -
  7.1349 -	if (debug > 4) {
  7.1350 -		printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n",
  7.1351 -			   dev->name, np->cur_tx-1, entry);
  7.1352 -	}
  7.1353 -	return 0;
  7.1354 -}
  7.1355 -
  7.1356 -/* The interrupt handler does all of the Rx thread work and cleans up
  7.1357 -   after the Tx thread. */
  7.1358 -static void via_rhine_interrupt(int irq, void *dev_instance, struct pt_regs *rgs)
  7.1359 -{
  7.1360 -	struct net_device *dev = dev_instance;
  7.1361 -	long ioaddr;
  7.1362 -	u32 intr_status;
  7.1363 -	int boguscnt = max_interrupt_work;
  7.1364 -
  7.1365 -	ioaddr = dev->base_addr;
  7.1366 -	
  7.1367 -	while ((intr_status = get_intr_status(dev))) {
  7.1368 -		/* Acknowledge all of the current interrupt sources ASAP. */
  7.1369 -		if (intr_status & IntrTxDescRace)
  7.1370 -			writeb(0x08, ioaddr + IntrStatus2);
  7.1371 -		writew(intr_status & 0xffff, ioaddr + IntrStatus);
  7.1372 -		IOSYNC;
  7.1373 -
  7.1374 -		if (debug > 4)
  7.1375 -			printk(KERN_DEBUG "%s: Interrupt, status %8.8x.\n",
  7.1376 -				   dev->name, intr_status);
  7.1377 -
  7.1378 -		if (intr_status & (IntrRxDone | IntrRxErr | IntrRxDropped |
  7.1379 -						   IntrRxWakeUp | IntrRxEmpty | IntrRxNoBuf))
  7.1380 -			via_rhine_rx(dev);
  7.1381 -
  7.1382 -		if (intr_status & (IntrTxErrSummary | IntrTxDone)) {
  7.1383 -			if (intr_status & IntrTxErrSummary) {
  7.1384 -				int cnt = 20;
  7.1385 -				/* Avoid scavenging before Tx engine turned off */
  7.1386 -				while ((readw(ioaddr+ChipCmd) & CmdTxOn) && --cnt)
  7.1387 -					udelay(5);
  7.1388 -				if (debug > 2 && !cnt)
  7.1389 -					printk(KERN_WARNING "%s: via_rhine_interrupt() "
  7.1390 -						   "Tx engine still on.\n",
  7.1391 -						   dev->name);
  7.1392 -			}
  7.1393 -			via_rhine_tx(dev);
  7.1394 -		}
  7.1395 -
  7.1396 -		/* Abnormal error summary/uncommon events handlers. */
  7.1397 -		if (intr_status & (IntrPCIErr | IntrLinkChange |
  7.1398 -				   IntrStatsMax | IntrTxError | IntrTxAborted |
  7.1399 -				   IntrTxUnderrun | IntrTxDescRace))
  7.1400 -			via_rhine_error(dev, intr_status);
  7.1401 -
  7.1402 -		if (--boguscnt < 0) {
  7.1403 -			printk(KERN_WARNING "%s: Too much work at interrupt, "
  7.1404 -				   "status=%#8.8x.\n",
  7.1405 -				   dev->name, intr_status);
  7.1406 -			break;
  7.1407 -		}
  7.1408 -	}
  7.1409 -
  7.1410 -	if (debug > 3)
  7.1411 -		printk(KERN_DEBUG "%s: exiting interrupt, status=%8.8x.\n",
  7.1412 -			   dev->name, readw(ioaddr + IntrStatus));
  7.1413 -}
  7.1414 -
  7.1415 -/* This routine is logically part of the interrupt handler, but isolated
  7.1416 -   for clarity. */
  7.1417 -static void via_rhine_tx(struct net_device *dev)
  7.1418 -{
  7.1419 -	struct netdev_private *np = dev->priv;
  7.1420 -	int txstatus = 0, entry = np->dirty_tx % TX_RING_SIZE;
  7.1421 -
  7.1422 -	spin_lock (&np->lock);
  7.1423 -
  7.1424 -	/* find and cleanup dirty tx descriptors */
  7.1425 -	while (np->dirty_tx != np->cur_tx) {
  7.1426 -		txstatus = le32_to_cpu(np->tx_ring[entry].tx_status);
  7.1427 -		if (debug > 6)
  7.1428 -			printk(KERN_DEBUG " Tx scavenge %d status %8.8x.\n",
  7.1429 -				   entry, txstatus);
  7.1430 -		if (txstatus & DescOwn)
  7.1431 -			break;
  7.1432 -		if (txstatus & 0x8000) {
  7.1433 -			if (debug > 1)
  7.1434 -				printk(KERN_DEBUG "%s: Transmit error, Tx status %8.8x.\n",
  7.1435 -					   dev->name, txstatus);
  7.1436 -			np->stats.tx_errors++;
  7.1437 -			if (txstatus & 0x0400) np->stats.tx_carrier_errors++;
  7.1438 -			if (txstatus & 0x0200) np->stats.tx_window_errors++;
  7.1439 -			if (txstatus & 0x0100) np->stats.tx_aborted_errors++;
  7.1440 -			if (txstatus & 0x0080) np->stats.tx_heartbeat_errors++;
  7.1441 -			if (((np->chip_id == VT86C100A) && txstatus & 0x0002) ||
  7.1442 -				(txstatus & 0x0800) || (txstatus & 0x1000)) {
  7.1443 -				np->stats.tx_fifo_errors++;
  7.1444 -				np->tx_ring[entry].tx_status = cpu_to_le32(DescOwn);
  7.1445 -				break; /* Keep the skb - we try again */
  7.1446 -			}
  7.1447 -			/* Transmitter restarted in 'abnormal' handler. */
  7.1448 -		} else {
  7.1449 -			if (np->chip_id == VT86C100A)
  7.1450 -				np->stats.collisions += (txstatus >> 3) & 0x0F;
  7.1451 -			else
  7.1452 -				np->stats.collisions += txstatus & 0x0F;
  7.1453 -			if (debug > 6)
  7.1454 -				printk(KERN_DEBUG "collisions: %1.1x:%1.1x\n",
  7.1455 -					(txstatus >> 3) & 0xF,
  7.1456 -					txstatus & 0xF);
  7.1457 -			np->stats.tx_bytes += np->tx_skbuff[entry]->len;
  7.1458 -			np->stats.tx_packets++;
  7.1459 -		}
  7.1460 -		/* Free the original skb. */
  7.1461 -		if (np->tx_skbuff_dma[entry]) {
  7.1462 -			pci_unmap_single(np->pdev,
  7.1463 -							 np->tx_skbuff_dma[entry],
  7.1464 -							 np->tx_skbuff[entry]->len, PCI_DMA_TODEVICE);
  7.1465 -		}
  7.1466 -		dev_kfree_skb_irq(np->tx_skbuff[entry]);
  7.1467 -		np->tx_skbuff[entry] = NULL;
  7.1468 -		entry = (++np->dirty_tx) % TX_RING_SIZE;
  7.1469 -	}
  7.1470 -	if ((np->cur_tx - np->dirty_tx) < TX_QUEUE_LEN - 4)
  7.1471 -		netif_wake_queue (dev);
  7.1472 -
  7.1473 -	spin_unlock (&np->lock);
  7.1474 -}
  7.1475 -
  7.1476 -/* This routine is logically part of the interrupt handler, but isolated
  7.1477 -   for clarity and better register allocation. */
  7.1478 -static void via_rhine_rx(struct net_device *dev)
  7.1479 -{
  7.1480 -	struct netdev_private *np = dev->priv;
  7.1481 -	int entry = np->cur_rx % RX_RING_SIZE;
  7.1482 -	int boguscnt = np->dirty_rx + RX_RING_SIZE - np->cur_rx;
  7.1483 -
  7.1484 -	if (debug > 4) {
  7.1485 -		printk(KERN_DEBUG "%s: via_rhine_rx(), entry %d status %8.8x.\n",
  7.1486 -			   dev->name, entry, le32_to_cpu(np->rx_head_desc->rx_status));
  7.1487 -	}
  7.1488 -
  7.1489 -	/* If EOP is set on the next entry, it's a new packet. Send it up. */
  7.1490 -	while ( ! (np->rx_head_desc->rx_status & cpu_to_le32(DescOwn))) {
  7.1491 -		struct rx_desc *desc = np->rx_head_desc;
  7.1492 -		u32 desc_status = le32_to_cpu(desc->rx_status);
  7.1493 -		int data_size = desc_status >> 16;
  7.1494 -
  7.1495 -		if (debug > 4)
  7.1496 -			printk(KERN_DEBUG "  via_rhine_rx() status is %8.8x.\n",
  7.1497 -				   desc_status);
  7.1498 -		if (--boguscnt < 0)
  7.1499 -			break;
  7.1500 -		if ( (desc_status & (RxWholePkt | RxErr)) !=  RxWholePkt) {
  7.1501 -			if ((desc_status & RxWholePkt) !=  RxWholePkt) {
  7.1502 -				printk(KERN_WARNING "%s: Oversized Ethernet frame spanned "
  7.1503 -					   "multiple buffers, entry %#x length %d status %8.8x!\n",
  7.1504 -					   dev->name, entry, data_size, desc_status);
  7.1505 -				printk(KERN_WARNING "%s: Oversized Ethernet frame %p vs %p.\n",
  7.1506 -					   dev->name, np->rx_head_desc, &np->rx_ring[entry]);
  7.1507 -				np->stats.rx_length_errors++;
  7.1508 -			} else if (desc_status & RxErr) {
  7.1509 -				/* There was a error. */
  7.1510 -				if (debug > 2)
  7.1511 -					printk(KERN_DEBUG "  via_rhine_rx() Rx error was %8.8x.\n",
  7.1512 -						   desc_status);
  7.1513 -				np->stats.rx_errors++;
  7.1514 -				if (desc_status & 0x0030) np->stats.rx_length_errors++;
  7.1515 -				if (desc_status & 0x0048) np->stats.rx_fifo_errors++;
  7.1516 -				if (desc_status & 0x0004) np->stats.rx_frame_errors++;
  7.1517 -				if (desc_status & 0x0002) {
  7.1518 -					/* this can also be updated outside the interrupt handler */
  7.1519 -					spin_lock (&np->lock);
  7.1520 -					np->stats.rx_crc_errors++;
  7.1521 -					spin_unlock (&np->lock);
  7.1522 -				}
  7.1523 -			}
  7.1524 -		} else {
  7.1525 -			struct sk_buff *skb;
  7.1526 -			/* Length should omit the CRC */
  7.1527 -			int pkt_len = data_size - 4;
  7.1528 -
  7.1529 -			/* Check if the packet is long enough to accept without copying
  7.1530 -			   to a minimally-sized skbuff. */
  7.1531 -			if (pkt_len < rx_copybreak &&
  7.1532 -				(skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
  7.1533 -				skb->dev = dev;
  7.1534 -				skb_reserve(skb, 2);	/* 16 byte align the IP header */
  7.1535 -				pci_dma_sync_single(np->pdev, np->rx_skbuff_dma[entry],
  7.1536 -						    np->rx_buf_sz, PCI_DMA_FROMDEVICE);
  7.1537 -
  7.1538 -				/* *_IP_COPYSUM isn't defined anywhere and eth_copy_and_sum
  7.1539 -				   is memcpy for all archs so this is kind of pointless right
  7.1540 -				   now ... or? */
  7.1541 -#if HAS_IP_COPYSUM                     /* Call copy + cksum if available. */
  7.1542 -				eth_copy_and_sum(skb, np->rx_skbuff[entry]->tail, pkt_len, 0);
  7.1543 -				skb_put(skb, pkt_len);
  7.1544 -#else
  7.1545 -				memcpy(skb_put(skb, pkt_len), np->rx_skbuff[entry]->tail,
  7.1546 -					   pkt_len);
  7.1547 -#endif
  7.1548 -			} else {
  7.1549 -				skb = np->rx_skbuff[entry];
  7.1550 -				if (skb == NULL) {
  7.1551 -					printk(KERN_ERR "%s: Inconsistent Rx descriptor chain.\n",
  7.1552 -						   dev->name);
  7.1553 -					break;
  7.1554 -				}
  7.1555 -				np->rx_skbuff[entry] = NULL;
  7.1556 -				skb_put(skb, pkt_len);
  7.1557 -				pci_unmap_single(np->pdev, np->rx_skbuff_dma[entry],
  7.1558 -								 np->rx_buf_sz, PCI_DMA_FROMDEVICE);
  7.1559 -			}
  7.1560 -			skb->protocol = eth_type_trans(skb, dev);
  7.1561 -			netif_rx(skb);
  7.1562 -			dev->last_rx = jiffies;
  7.1563 -			np->stats.rx_bytes += pkt_len;
  7.1564 -			np->stats.rx_packets++;
  7.1565 -		}
  7.1566 -		entry = (++np->cur_rx) % RX_RING_SIZE;
  7.1567 -		np->rx_head_desc = &np->rx_ring[entry];
  7.1568 -	}
  7.1569 -
  7.1570 -	/* Refill the Rx ring buffers. */
  7.1571 -	for (; np->cur_rx - np->dirty_rx > 0; np->dirty_rx++) {
  7.1572 -		struct sk_buff *skb;
  7.1573 -		entry = np->dirty_rx % RX_RING_SIZE;
  7.1574 -		if (np->rx_skbuff[entry] == NULL) {
  7.1575 -			skb = dev_alloc_skb(np->rx_buf_sz);
  7.1576 -			np->rx_skbuff[entry] = skb;
  7.1577 -			if (skb == NULL)
  7.1578 -				break;			/* Better luck next round. */
  7.1579 -			skb->dev = dev;			/* Mark as being used by this device. */
  7.1580 -			np->rx_skbuff_dma[entry] =
  7.1581 -				pci_map_single(np->pdev, skb->tail, np->rx_buf_sz, 
  7.1582 -							   PCI_DMA_FROMDEVICE);
  7.1583 -			np->rx_ring[entry].addr = cpu_to_le32(np->rx_skbuff_dma[entry]);
  7.1584 -		}
  7.1585 -		np->rx_ring[entry].rx_status = cpu_to_le32(DescOwn);
  7.1586 -	}
  7.1587 -
  7.1588 -	/* Pre-emptively restart Rx engine. */
  7.1589 -	writew(readw(dev->base_addr + ChipCmd) | CmdRxOn | CmdRxDemand,
  7.1590 -		   dev->base_addr + ChipCmd);
  7.1591 -}
  7.1592 -
  7.1593 -/* Clears the "tally counters" for CRC errors and missed frames(?).
  7.1594 -   It has been reported that some chips need a write of 0 to clear
  7.1595 -   these, for others the counters are set to 1 when written to and
  7.1596 -   instead cleared when read. So we clear them both ways ... */
  7.1597 -static inline void clear_tally_counters(const long ioaddr)
  7.1598 -{
  7.1599 -	writel(0, ioaddr + RxMissed);
  7.1600 -	readw(ioaddr + RxCRCErrs);
  7.1601 -	readw(ioaddr + RxMissed);
  7.1602 -}
  7.1603 -
  7.1604 -static void via_rhine_restart_tx(struct net_device *dev) {
  7.1605 -	struct netdev_private *np = dev->priv;
  7.1606 -	long ioaddr = dev->base_addr;
  7.1607 -	int entry = np->dirty_tx % TX_RING_SIZE;
  7.1608 -	u32 intr_status;
  7.1609 -
  7.1610 -	/*
  7.1611 -	 * If new errors occured, we need to sort them out before doing Tx.
  7.1612 -	 * In that case the ISR will be back here RSN anyway.
  7.1613 -	 */
  7.1614 -	intr_status = get_intr_status(dev);
  7.1615 -
  7.1616 -	if ((intr_status & IntrTxErrSummary) == 0) {
  7.1617 -
  7.1618 -		/* We know better than the chip where it should continue. */
  7.1619 -		writel(np->tx_ring_dma + entry * sizeof(struct tx_desc),
  7.1620 -			   ioaddr + TxRingPtr);
  7.1621 -
  7.1622 -		writew(CmdTxDemand | np->chip_cmd, ioaddr + ChipCmd);
  7.1623 -		IOSYNC;
  7.1624 -	}
  7.1625 -	else {
  7.1626 -		/* This should never happen */
  7.1627 -		if (debug > 1)
  7.1628 -			printk(KERN_WARNING "%s: via_rhine_restart_tx() "
  7.1629 -				   "Another error occured %8.8x.\n",
  7.1630 -				   dev->name, intr_status);
  7.1631 -	}
  7.1632 -
  7.1633 -}
  7.1634 -
  7.1635 -static void via_rhine_error(struct net_device *dev, int intr_status)
  7.1636 -{
  7.1637 -	struct netdev_private *np = dev->priv;
  7.1638 -	long ioaddr = dev->base_addr;
  7.1639 -
  7.1640 -	spin_lock (&np->lock);
  7.1641 -
  7.1642 -	if (intr_status & (IntrLinkChange)) {
  7.1643 -		if (readb(ioaddr + MIIStatus) & 0x02) {
  7.1644 -			/* Link failed, restart autonegotiation. */
  7.1645 -			if (np->drv_flags & HasDavicomPhy)
  7.1646 -				mdio_write(dev, np->phys[0], MII_BMCR, 0x3300);
  7.1647 -		} else
  7.1648 -			via_rhine_check_duplex(dev);
  7.1649 -		if (debug)
  7.1650 -			printk(KERN_ERR "%s: MII status changed: Autonegotiation "
  7.1651 -				   "advertising %4.4x  partner %4.4x.\n", dev->name,
  7.1652 -			   mdio_read(dev, np->phys[0], MII_ADVERTISE),
  7.1653 -			   mdio_read(dev, np->phys[0], MII_LPA));
  7.1654 -	}
  7.1655 -	if (intr_status & IntrStatsMax) {
  7.1656 -		np->stats.rx_crc_errors	+= readw(ioaddr + RxCRCErrs);
  7.1657 -		np->stats.rx_missed_errors	+= readw(ioaddr + RxMissed);
  7.1658 -		clear_tally_counters(ioaddr);
  7.1659 -	}
  7.1660 -	if (intr_status & IntrTxAborted) {
  7.1661 -		if (debug > 1)
  7.1662 -			printk(KERN_INFO "%s: Abort %8.8x, frame dropped.\n",
  7.1663 -				   dev->name, intr_status);
  7.1664 -	}
  7.1665 -	if (intr_status & IntrTxUnderrun) {
  7.1666 -		if (np->tx_thresh < 0xE0)
  7.1667 -			writeb(np->tx_thresh += 0x20, ioaddr + TxConfig);
  7.1668 -		if (debug > 1)
  7.1669 -			printk(KERN_INFO "%s: Transmitter underrun, Tx "
  7.1670 -				   "threshold now %2.2x.\n",
  7.1671 -				   dev->name, np->tx_thresh);
  7.1672 -	}
  7.1673 -	if (intr_status & IntrTxDescRace) {
  7.1674 -		if (debug > 2)
  7.1675 -			printk(KERN_INFO "%s: Tx descriptor write-back race.\n",
  7.1676 -				   dev->name);
  7.1677 -	}
  7.1678 -	if (intr_status & ( IntrTxAborted | IntrTxUnderrun | IntrTxDescRace ))
  7.1679 -		via_rhine_restart_tx(dev);
  7.1680 -
  7.1681 -	if (intr_status & ~( IntrLinkChange | IntrStatsMax | IntrTxUnderrun |
  7.1682 - 						 IntrTxError | IntrTxAborted | IntrNormalSummary |
  7.1683 -						 IntrTxDescRace )) {
  7.1684 -		if (debug > 1)
  7.1685 -			printk(KERN_ERR "%s: Something Wicked happened! %8.8x.\n",
  7.1686 -				   dev->name, intr_status);
  7.1687 -	}
  7.1688 -
  7.1689 -	spin_unlock (&np->lock);
  7.1690 -}
  7.1691 -
  7.1692 -static struct net_device_stats *via_rhine_get_stats(struct net_device *dev)
  7.1693 -{
  7.1694 -	struct netdev_private *np = dev->priv;
  7.1695 -	long ioaddr = dev->base_addr;
  7.1696 -	unsigned long flags;
  7.1697 -
  7.1698 -	spin_lock_irqsave(&np->lock, flags);
  7.1699 -	np->stats.rx_crc_errors	+= readw(ioaddr + RxCRCErrs);
  7.1700 -	np->stats.rx_missed_errors	+= readw(ioaddr + RxMissed);
  7.1701 -	clear_tally_counters(ioaddr);
  7.1702 -	spin_unlock_irqrestore(&np->lock, flags);
  7.1703 -
  7.1704 -	return &np->stats;
  7.1705 -}
  7.1706 -
  7.1707 -static void via_rhine_set_rx_mode(struct net_device *dev)
  7.1708 -{
  7.1709 -	struct netdev_private *np = dev->priv;
  7.1710 -	long ioaddr = dev->base_addr;
  7.1711 -	u32 mc_filter[2];			/* Multicast hash filter */
  7.1712 -	u8 rx_mode;					/* Note: 0x02=accept runt, 0x01=accept errs */
  7.1713 -
  7.1714 -	if (dev->flags & IFF_PROMISC) {			/* Set promiscuous. */
  7.1715 -		/* Unconditionally log net taps. */
  7.1716 -		printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
  7.1717 -		rx_mode = 0x1C;
  7.1718 -	} else if ((dev->mc_count > multicast_filter_limit)
  7.1719 -			   ||  (dev->flags & IFF_ALLMULTI)) {
  7.1720 -		/* Too many to match, or accept all multicasts. */
  7.1721 -		writel(0xffffffff, ioaddr + MulticastFilter0);
  7.1722 -		writel(0xffffffff, ioaddr + MulticastFilter1);
  7.1723 -		rx_mode = 0x0C;
  7.1724 -	} else {
  7.1725 -		struct dev_mc_list *mclist;
  7.1726 -		int i;
  7.1727 -		memset(mc_filter, 0, sizeof(mc_filter));
  7.1728 -		for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  7.1729 -			 i++, mclist = mclist->next) {
  7.1730 -			int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
  7.1731 -
  7.1732 -			mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
  7.1733 -		}
  7.1734 -		writel(mc_filter[0], ioaddr + MulticastFilter0);
  7.1735 -		writel(mc_filter[1], ioaddr + MulticastFilter1);
  7.1736 -		rx_mode = 0x0C;
  7.1737 -	}
  7.1738 -	writeb(np->rx_thresh | rx_mode, ioaddr + RxConfig);
  7.1739 -}
  7.1740 -
  7.1741 -#if 0
  7.1742 -static int netdev_ethtool_ioctl (struct net_device *dev, void *useraddr)
  7.1743 -{
  7.1744 -	struct netdev_private *np = dev->priv;
  7.1745 -	u32 ethcmd;
  7.1746 -
  7.1747 -	if (get_user(ethcmd, (u32 *)useraddr))
  7.1748 -		return -EFAULT;
  7.1749 -
  7.1750 -	switch (ethcmd) {
  7.1751 -	case ETHTOOL_GDRVINFO: {
  7.1752 -		struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
  7.1753 -		strcpy (info.driver, DRV_NAME);
  7.1754 -		strcpy (info.version, DRV_VERSION);
  7.1755 -		strcpy (info.bus_info, np->pdev->slot_name);
  7.1756 -		if (copy_to_user (useraddr, &info, sizeof (info)))
  7.1757 -			return -EFAULT;
  7.1758 -		return 0;
  7.1759 -	}
  7.1760 -
  7.1761 -	/* get settings */
  7.1762 -	case ETHTOOL_GSET: {
  7.1763 -		struct ethtool_cmd ecmd = { ETHTOOL_GSET };
  7.1764 -		if (!(np->drv_flags & CanHaveMII))
  7.1765 -			break;
  7.1766 -		spin_lock_irq(&np->lock);
  7.1767 -		mii_ethtool_gset(&np->mii_if, &ecmd);
  7.1768 -		spin_unlock_irq(&np->lock);
  7.1769 -		if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
  7.1770 -			return -EFAULT;
  7.1771 -		return 0;
  7.1772 -	}
  7.1773 -	/* set settings */
  7.1774 -	case ETHTOOL_SSET: {
  7.1775 -		int r;
  7.1776 -		struct ethtool_cmd ecmd;
  7.1777 -		if (!(np->drv_flags & CanHaveMII))
  7.1778 -			break;
  7.1779 -		if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
  7.1780 -			return -EFAULT;
  7.1781 -		spin_lock_irq(&np->lock);
  7.1782 -		r = mii_ethtool_sset(&np->mii_if, &ecmd);
  7.1783 -		spin_unlock_irq(&np->lock);
  7.1784 -		return r;
  7.1785 -	}
  7.1786 -	/* restart autonegotiation */
  7.1787 -	case ETHTOOL_NWAY_RST: {
  7.1788 -		if (!(np->drv_flags & CanHaveMII))
  7.1789 -			break;
  7.1790 -		return mii_nway_restart(&np->mii_if);
  7.1791 -	}
  7.1792 -	/* get link status */
  7.1793 -	case ETHTOOL_GLINK: {
  7.1794 -		struct ethtool_value edata = {ETHTOOL_GLINK};
  7.1795 -		if (!(np->drv_flags & CanHaveMII))
  7.1796 -			break;
  7.1797 -		edata.data = mii_link_ok(&np->mii_if);
  7.1798 -		if (copy_to_user(useraddr, &edata, sizeof(edata)))
  7.1799 -			return -EFAULT;
  7.1800 -		return 0;
  7.1801 -	}
  7.1802 -
  7.1803 -	/* get message-level */
  7.1804 -	case ETHTOOL_GMSGLVL: {
  7.1805 -		struct ethtool_value edata = {ETHTOOL_GMSGLVL};
  7.1806 -		edata.data = debug;
  7.1807 -		if (copy_to_user(useraddr, &edata, sizeof(edata)))
  7.1808 -			return -EFAULT;
  7.1809 -		return 0;
  7.1810 -	}
  7.1811 -	/* set message-level */
  7.1812 -	case ETHTOOL_SMSGLVL: {
  7.1813 -		struct ethtool_value edata;
  7.1814 -		if (copy_from_user(&edata, useraddr, sizeof(edata)))
  7.1815 -			return -EFAULT;
  7.1816 -		debug = edata.data;
  7.1817 -		return 0;
  7.1818 -	}
  7.1819 -	default:
  7.1820 -		break;
  7.1821 -	}
  7.1822 -
  7.1823 -	return -EOPNOTSUPP;
  7.1824 -}
  7.1825 -
  7.1826 -static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  7.1827 -{
  7.1828 -	struct netdev_private *np = dev->priv;
  7.1829 -	struct mii_ioctl_data *data = (struct mii_ioctl_data *) & rq->ifr_data;
  7.1830 -	int rc;
  7.1831 -
  7.1832 -	if (!netif_running(dev))
  7.1833 -		return -EINVAL;
  7.1834 -
  7.1835 -	if (cmd == SIOCETHTOOL)
  7.1836 -		rc = netdev_ethtool_ioctl(dev, (void *) rq->ifr_data);
  7.1837 -
  7.1838 -	else {
  7.1839 -		spin_lock_irq(&np->lock);
  7.1840 -		rc = generic_mii_ioctl(&np->mii_if, data, cmd, NULL);
  7.1841 -		spin_unlock_irq(&np->lock);
  7.1842 -	}
  7.1843 -
  7.1844 -	return rc;
  7.1845 -}
  7.1846 -#endif
  7.1847 -
  7.1848 -static int via_rhine_close(struct net_device *dev)
  7.1849 -{
  7.1850 -	long ioaddr = dev->base_addr;
  7.1851 -	struct netdev_private *np = dev->priv;
  7.1852 -
  7.1853 -	del_timer_sync(&np->timer);
  7.1854 -
  7.1855 -	spin_lock_irq(&np->lock);
  7.1856 -
  7.1857 -	netif_stop_queue(dev);
  7.1858 -
  7.1859 -	if (debug > 1)
  7.1860 -		printk(KERN_DEBUG "%s: Shutting down ethercard, status was %4.4x.\n",
  7.1861 -			   dev->name, readw(ioaddr + ChipCmd));
  7.1862 -
  7.1863 -	/* Switch to loopback mode to avoid hardware races. */
  7.1864 -	writeb(np->tx_thresh | 0x02, ioaddr + TxConfig);
  7.1865 -
  7.1866 -	/* Disable interrupts by clearing the interrupt mask. */
  7.1867 -	writew(0x0000, ioaddr + IntrEnable);
  7.1868 -
  7.1869 -	/* Stop the chip's Tx and Rx processes. */
  7.1870 -	writew(CmdStop, ioaddr + ChipCmd);
  7.1871 -
  7.1872 -	spin_unlock_irq(&np->lock);
  7.1873 -
  7.1874 -	free_irq(np->pdev->irq, dev);
  7.1875 -	free_rbufs(dev);
  7.1876 -	free_tbufs(dev);
  7.1877 -	free_ring(dev);
  7.1878 -
  7.1879 -	return 0;
  7.1880 -}
  7.1881 -
  7.1882 -
  7.1883 -static void __devexit via_rhine_remove_one (struct pci_dev *pdev)
  7.1884 -{
  7.1885 -	struct net_device *dev = pci_get_drvdata(pdev);
  7.1886 -	
  7.1887 -	unregister_netdev(dev);
  7.1888 -
  7.1889 -	pci_release_regions(pdev);
  7.1890 -
  7.1891 -#ifdef USE_MEM
  7.1892 -	iounmap((char *)(dev->base_addr));
  7.1893 -#endif
  7.1894 -
  7.1895 -	kfree(dev);
  7.1896 -	pci_disable_device(pdev);
  7.1897 -	pci_set_drvdata(pdev, NULL);
  7.1898 -}
  7.1899 -
  7.1900 -
  7.1901 -static struct pci_driver via_rhine_driver = {
  7.1902 -	.name		= "via-rhine",
  7.1903 -	.id_table	= via_rhine_pci_tbl,
  7.1904 -	.probe		= via_rhine_init_one,
  7.1905 -	.remove		= __devexit_p(via_rhine_remove_one),
  7.1906 -};
  7.1907 -
  7.1908 -
  7.1909 -static int __init via_rhine_init (void)
  7.1910 -{
  7.1911 -/* when a module, this is printed whether or not devices are found in probe */
  7.1912 -#ifdef MODULE
  7.1913 -	printk(version);
  7.1914 -#endif
  7.1915 -	return pci_module_init (&via_rhine_driver);
  7.1916 -}
  7.1917 -
  7.1918 -
  7.1919 -static void __exit via_rhine_cleanup (void)
  7.1920 -{
  7.1921 -	pci_unregister_driver (&via_rhine_driver);
  7.1922 -}
  7.1923 -
  7.1924 -
  7.1925 -module_init(via_rhine_init);
  7.1926 -module_exit(via_rhine_cleanup);
  7.1927 -
  7.1928 -
  7.1929 -/*
  7.1930 - * Local variables:
  7.1931 - *  compile-command: "gcc -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c via-rhine.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`"
  7.1932 - *  c-indent-level: 4
  7.1933 - *  c-basic-offset: 4
  7.1934 - *  tab-width: 4
  7.1935 - * End:
  7.1936 - */