ia64/xen-unstable

changeset 125:3549eb0ec2db

bitkeeper revision 1.22.1.9 (3e428de1nQwf1QUfwsp1nTiJP4ByhQ)

Zero-copy receive path now works over discontiguous memory with no guest-side pool.
author akw27@boulderdash.cl.cam.ac.uk
date Thu Feb 06 16:31:29 2003 +0000 (2003-02-06)
parents b1b1608f5d5c
children 4a4ae256b9b5
files .rootkeys xen-2.4.16/arch/i386/ioremap.c xen-2.4.16/common/domain.c xen-2.4.16/drivers/net/3c509.c xen-2.4.16/drivers/net/3c59x.c xen-2.4.16/drivers/net/8139cp.c xen-2.4.16/drivers/net/8139too.c xen-2.4.16/drivers/net/eepro100.c xen-2.4.16/drivers/net/pcnet32.c xen-2.4.16/drivers/net/tulip/interrupt.c xen-2.4.16/drivers/net/tulip/tulip_core.c xen-2.4.16/include/xeno/mm.h xen-2.4.16/net/dev.c xen-2.4.16/net/skbuff.c xenolinux-2.4.16-sparse/arch/xeno/drivers/network/network.c xenolinux-2.4.16-sparse/include/asm-xeno/io.h xenolinux-2.4.16-sparse/include/linux/skbuff.h xenolinux-2.4.16-sparse/net/core/skbuff.c
line diff
     1.1 --- a/.rootkeys	Wed Feb 05 13:56:14 2003 +0000
     1.2 +++ b/.rootkeys	Thu Feb 06 16:31:29 2003 +0000
     1.3 @@ -67,10 +67,8 @@ 3ddb79bdOXTbcImJo8DwmlNX88k78Q xen-2.4.1
     1.4  3ddb79bdDWFwINnKn29RlFDwGJhjYg xen-2.4.16/drivers/ide/ide-taskfile.c
     1.5  3ddb79bdkDY1bSOYkToP1Cc49VdBxg xen-2.4.16/drivers/ide/ide.c
     1.6  3ddb79bdPyAvT_WZTAFhaX0jp-yXSw xen-2.4.16/drivers/ide/ide_modes.h
     1.7 -3ddb79bfogeJNHTIepPjd8fy1TyoTw xen-2.4.16/drivers/net/3c509.c
     1.8  3ddb79bfMlOcWUwjtg6oMYhGySHDDw xen-2.4.16/drivers/net/3c59x.c
     1.9  3ddb79bfl_DWxZQFKiJ2BXrSedV4lg xen-2.4.16/drivers/net/8139cp.c
    1.10 -3ddb79bfLVGtyXNJS4NQg-lP21rndA xen-2.4.16/drivers/net/8139too.c
    1.11  3ddb79c0tWiE8xIFHszxipeVCGKTSA xen-2.4.16/drivers/net/Makefile
    1.12  3ddb79bfU-H1Hms4BuJEPPydjXUEaQ xen-2.4.16/drivers/net/Space.c
    1.13  3ddb79c0GejJrp1U6W4G6dYi-RiH4A xen-2.4.16/drivers/net/eepro100.c
     2.1 --- a/xen-2.4.16/arch/i386/ioremap.c	Wed Feb 05 13:56:14 2003 +0000
     2.2 +++ b/xen-2.4.16/arch/i386/ioremap.c	Thu Feb 06 16:31:29 2003 +0000
     2.3 @@ -15,8 +15,8 @@
     2.4  
     2.5  static unsigned long remap_base = 0;
     2.6  
     2.7 -#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
     2.8 -#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY)
     2.9 +#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
    2.10 +#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY)
    2.11  
    2.12  #define PAGE_ALIGN(addr)    (((addr)+PAGE_SIZE-1)&PAGE_MASK)
    2.13  
     3.1 --- a/xen-2.4.16/common/domain.c	Wed Feb 05 13:56:14 2003 +0000
     3.2 +++ b/xen-2.4.16/common/domain.c	Thu Feb 06 16:31:29 2003 +0000
     3.3 @@ -15,8 +15,8 @@
     3.4  #include <asm/msr.h>
     3.5  #include <xeno/multiboot.h>
     3.6  
     3.7 -#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_USER|_PAGE_ACCESSED)
     3.8 -#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_USER|_PAGE_ACCESSED|_PAGE_DIRTY)
     3.9 +#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_USER|_PAGE_ACCESSED)
    3.10 +#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_USER|_PAGE_ACCESSED|_PAGE_DIRTY)
    3.11  
    3.12  extern int nr_mods;
    3.13  extern module_t *mod;
     4.1 --- a/xen-2.4.16/drivers/net/3c509.c	Wed Feb 05 13:56:14 2003 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,1068 +0,0 @@
     4.4 -/* 3c509.c: A 3c509 EtherLink3 ethernet driver for linux. */
     4.5 -/*
     4.6 -	Written 1993-2000 by Donald Becker.
     4.7 -
     4.8 -	Copyright 1994-2000 by Donald Becker.
     4.9 -	Copyright 1993 United States Government as represented by the
    4.10 -	Director, National Security Agency.	 This software may be used and
    4.11 -	distributed according to the terms of the GNU General Public License,
    4.12 -	incorporated herein by reference.
    4.13 -
    4.14 -	This driver is for the 3Com EtherLinkIII series.
    4.15 -
    4.16 -	The author may be reached as becker@scyld.com, or C/O
    4.17 -	Scyld Computing Corporation
    4.18 -	410 Severn Ave., Suite 210
    4.19 -	Annapolis MD 21403
    4.20 -
    4.21 -	Known limitations:
    4.22 -	Because of the way 3c509 ISA detection works it's difficult to predict
    4.23 -	a priori which of several ISA-mode cards will be detected first.
    4.24 -
    4.25 -	This driver does not use predictive interrupt mode, resulting in higher
    4.26 -	packet latency but lower overhead.  If interrupts are disabled for an
    4.27 -	unusually long time it could also result in missed packets, but in
    4.28 -	practice this rarely happens.
    4.29 -
    4.30 -
    4.31 -	FIXES:
    4.32 -		Alan Cox:       Removed the 'Unexpected interrupt' bug.
    4.33 -		Michael Meskes:	Upgraded to Donald Becker's version 1.07.
    4.34 -		Alan Cox:	Increased the eeprom delay. Regardless of 
    4.35 -				what the docs say some people definitely
    4.36 -				get problems with lower (but in card spec)
    4.37 -				delays
    4.38 -		v1.10 4/21/97 Fixed module code so that multiple cards may be detected,
    4.39 -				other cleanups.  -djb
    4.40 -		Andrea Arcangeli:	Upgraded to Donald Becker's version 1.12.
    4.41 -		Rick Payne:	Fixed SMP race condition
    4.42 -		v1.13 9/8/97 Made 'max_interrupt_work' an insmod-settable variable -djb
    4.43 -		v1.14 10/15/97 Avoided waiting..discard message for fast machines -djb
    4.44 -		v1.15 1/31/98 Faster recovery for Tx errors. -djb
    4.45 -		v1.16 2/3/98 Different ID port handling to avoid sound cards. -djb
    4.46 -		v1.18 12Mar2001 Andrew Morton <andrewm@uow.edu.au>
    4.47 -			- Avoid bogus detect of 3c590's (Andrzej Krzysztofowicz)
    4.48 -			- Reviewed against 1.18 from scyld.com
    4.49 -*/
    4.50 -
    4.51 -/* A few values that may be tweaked. */
    4.52 -
    4.53 -/* Time in jiffies before concluding the transmitter is hung. */
    4.54 -#define TX_TIMEOUT  (400*HZ/1000)
    4.55 -/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
    4.56 -static int max_interrupt_work = 10;
    4.57 -
    4.58 -#include <linux/config.h>
    4.59 -#include <linux/module.h>
    4.60 -
    4.61 -//#include <linux/mca.h>
    4.62 -//#include <linux/isapnp.h>
    4.63 -#include <linux/sched.h>
    4.64 -//#include <linux/string.h>
    4.65 -#include <linux/lib.h>
    4.66 -#include <linux/interrupt.h>
    4.67 -#include <linux/errno.h>
    4.68 -//#include <linux/in.h>
    4.69 -#include <linux/slab.h>
    4.70 -#include <linux/ioport.h>
    4.71 -#include <linux/init.h>
    4.72 -#include <linux/netdevice.h>
    4.73 -#include <linux/etherdevice.h>
    4.74 -#include <linux/skbuff.h>
    4.75 -#include <linux/delay.h>	/* for udelay() */
    4.76 -#include <linux/spinlock.h>
    4.77 -
    4.78 -#include <asm/bitops.h>
    4.79 -#include <asm/io.h>
    4.80 -#include <asm/irq.h>
    4.81 -
    4.82 -static char versionA[] __initdata = "3c509.c:1.18 12Mar2001 becker@scyld.com\n";
    4.83 -static char versionB[] __initdata = "http://www.scyld.com/network/3c509.html\n";
    4.84 -
    4.85 -#ifdef EL3_DEBUG
    4.86 -static int el3_debug = EL3_DEBUG;
    4.87 -#else
    4.88 -static int el3_debug = 2;
    4.89 -#endif
    4.90 -
    4.91 -/* To minimize the size of the driver source I only define operating
    4.92 -   constants if they are used several times.  You'll need the manual
    4.93 -   anyway if you want to understand driver details. */
    4.94 -/* Offsets from base I/O address. */
    4.95 -#define EL3_DATA 0x00
    4.96 -#define EL3_CMD 0x0e
    4.97 -#define EL3_STATUS 0x0e
    4.98 -#define	 EEPROM_READ 0x80
    4.99 -
   4.100 -#define EL3_IO_EXTENT	16
   4.101 -
   4.102 -#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
   4.103 -
   4.104 -
   4.105 -/* The top five bits written to EL3_CMD are a command, the lower
   4.106 -   11 bits are the parameter, if applicable. */
   4.107 -enum c509cmd {
   4.108 -	TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
   4.109 -	RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, RxDiscard = 8<<11,
   4.110 -	TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
   4.111 -	FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
   4.112 -	SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
   4.113 -	SetTxThreshold = 18<<11, SetTxStart = 19<<11, StatsEnable = 21<<11,
   4.114 -	StatsDisable = 22<<11, StopCoax = 23<<11,};
   4.115 -
   4.116 -enum c509status {
   4.117 -	IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,
   4.118 -	TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
   4.119 -	IntReq = 0x0040, StatsFull = 0x0080, CmdBusy = 0x1000, };
   4.120 -
   4.121 -/* The SetRxFilter command accepts the following classes: */
   4.122 -enum RxFilter {
   4.123 -	RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
   4.124 -
   4.125 -/* Register window 1 offsets, the window used in normal operation. */
   4.126 -#define TX_FIFO		0x00
   4.127 -#define RX_FIFO		0x00
   4.128 -#define RX_STATUS 	0x08
   4.129 -#define TX_STATUS 	0x0B
   4.130 -#define TX_FREE		0x0C		/* Remaining free bytes in Tx buffer. */
   4.131 -
   4.132 -#define WN0_IRQ		0x08		/* Window 0: Set IRQ line in bits 12-15. */
   4.133 -#define WN4_MEDIA	0x0A		/* Window 4: Various transcvr/media bits. */
   4.134 -#define  MEDIA_TP	0x00C0		/* Enable link beat and jabber for 10baseT. */
   4.135 -
   4.136 -/*
   4.137 - * Must be a power of two (we use a binary and in the
   4.138 - * circular queue)
   4.139 - */
   4.140 -#define SKB_QUEUE_SIZE	64
   4.141 -
   4.142 -struct el3_private {
   4.143 -	struct net_device_stats stats;
   4.144 -	struct net_device *next_dev;
   4.145 -	spinlock_t lock;
   4.146 -	/* skb send-queue */
   4.147 -	int head, size;
   4.148 -	struct sk_buff *queue[SKB_QUEUE_SIZE];
   4.149 -	char mca_slot;
   4.150 -};
   4.151 -static int id_port __initdata = 0x110;	/* Start with 0x110 to avoid new sound cards.*/
   4.152 -static struct net_device *el3_root_dev;
   4.153 -
   4.154 -static ushort id_read_eeprom(int index);
   4.155 -static ushort read_eeprom(int ioaddr, int index);
   4.156 -static int el3_open(struct net_device *dev);
   4.157 -static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev);
   4.158 -static void el3_interrupt(int irq, void *dev_id, struct pt_regs *regs);
   4.159 -static void update_stats(struct net_device *dev);
   4.160 -static struct net_device_stats *el3_get_stats(struct net_device *dev);
   4.161 -static int el3_rx(struct net_device *dev);
   4.162 -static int el3_close(struct net_device *dev);
   4.163 -static void set_multicast_list(struct net_device *dev);
   4.164 -static void el3_tx_timeout (struct net_device *dev);
   4.165 -
   4.166 -#ifdef CONFIG_MCA
   4.167 -struct el3_mca_adapters_struct {
   4.168 -	char* name;
   4.169 -	int id;
   4.170 -};
   4.171 -
   4.172 -static struct el3_mca_adapters_struct el3_mca_adapters[] __initdata = {
   4.173 -	{ "3Com 3c529 EtherLink III (10base2)", 0x627c },
   4.174 -	{ "3Com 3c529 EtherLink III (10baseT)", 0x627d },
   4.175 -	{ "3Com 3c529 EtherLink III (test mode)", 0x62db },
   4.176 -	{ "3Com 3c529 EtherLink III (TP or coax)", 0x62f6 },
   4.177 -	{ "3Com 3c529 EtherLink III (TP)", 0x62f7 },
   4.178 -	{ NULL, 0 },
   4.179 -};
   4.180 -#endif /* CONFIG_MCA */
   4.181 -
   4.182 -#if defined(CONFIG_ISAPNP) || defined(CONFIG_ISAPNP_MODULE)
   4.183 -static struct isapnp_device_id el3_isapnp_adapters[] __initdata = {
   4.184 -	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,
   4.185 -		ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5090),
   4.186 -		(long) "3Com Etherlink III (TP)" },
   4.187 -	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,
   4.188 -		ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5091),
   4.189 -		(long) "3Com Etherlink III" },
   4.190 -	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,
   4.191 -		ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5094),
   4.192 -		(long) "3Com Etherlink III (combo)" },
   4.193 -	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,
   4.194 -		ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5095),
   4.195 -		(long) "3Com Etherlink III (TPO)" },
   4.196 -	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,
   4.197 -		ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5098),
   4.198 -		(long) "3Com Etherlink III (TPC)" },
   4.199 -	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,
   4.200 -		ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_FUNCTION(0x80f7),
   4.201 -		(long) "3Com Etherlink III compatible" },
   4.202 -	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,
   4.203 -		ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_FUNCTION(0x80f8),
   4.204 -		(long) "3Com Etherlink III compatible" },
   4.205 -	{ }	/* terminate list */
   4.206 -};
   4.207 -
   4.208 -MODULE_DEVICE_TABLE(isapnp, el3_isapnp_adapters);
   4.209 -MODULE_LICENSE("GPL");
   4.210 -
   4.211 -
   4.212 -static u16 el3_isapnp_phys_addr[8][3];
   4.213 -static int nopnp;
   4.214 -#endif /* CONFIG_ISAPNP || CONFIG_ISAPNP_MODULE */
   4.215 -
   4.216 -int __init el3_probe(struct net_device *dev)
   4.217 -{
   4.218 -	struct el3_private *lp;
   4.219 -	short lrs_state = 0xff, i;
   4.220 -	int ioaddr, irq, if_port;
   4.221 -	u16 phys_addr[3];
   4.222 -	static int current_tag;
   4.223 -	int mca_slot = -1;
   4.224 -#if defined(CONFIG_ISAPNP) || defined(CONFIG_ISAPNP_MODULE)
   4.225 -	static int pnp_cards;
   4.226 -#endif /* CONFIG_ISAPNP || CONFIG_ISAPNP_MODULE */
   4.227 -
   4.228 -	if (dev) SET_MODULE_OWNER(dev);
   4.229 -
   4.230 -	/* First check all slots of the EISA bus.  The next slot address to
   4.231 -	   probe is kept in 'eisa_addr' to support multiple probe() calls. */
   4.232 -	if (EISA_bus) {
   4.233 -		static int eisa_addr = 0x1000;
   4.234 -		while (eisa_addr < 0x9000) {
   4.235 -			int device_id;
   4.236 -
   4.237 -			ioaddr = eisa_addr;
   4.238 -			eisa_addr += 0x1000;
   4.239 -
   4.240 -			/* Check the standard EISA ID register for an encoded '3Com'. */
   4.241 -			if (inw(ioaddr + 0xC80) != 0x6d50)
   4.242 -				continue;
   4.243 -
   4.244 -			/* Avoid conflict with 3c590, 3c592, 3c597, etc */
   4.245 -			device_id = (inb(ioaddr + 0xC82)<<8) + inb(ioaddr + 0xC83);
   4.246 -			if ((device_id & 0xFF00) == 0x5900) {
   4.247 -				continue;
   4.248 -			}
   4.249 -
   4.250 -			/* Change the register set to the configuration window 0. */
   4.251 -			outw(SelectWindow | 0, ioaddr + 0xC80 + EL3_CMD);
   4.252 -
   4.253 -			irq = inw(ioaddr + WN0_IRQ) >> 12;
   4.254 -			if_port = inw(ioaddr + 6)>>14;
   4.255 -			for (i = 0; i < 3; i++)
   4.256 -				phys_addr[i] = htons(read_eeprom(ioaddr, i));
   4.257 -
   4.258 -			/* Restore the "Product ID" to the EEPROM read register. */
   4.259 -			read_eeprom(ioaddr, 3);
   4.260 -
   4.261 -			/* Was the EISA code an add-on hack?  Nahhhhh... */
   4.262 -			goto found;
   4.263 -		}
   4.264 -	}
   4.265 -
   4.266 -#ifdef CONFIG_MCA
   4.267 -	/* Based on Erik Nygren's (nygren@mit.edu) 3c529 patch, heavily
   4.268 -	 * modified by Chris Beauregard (cpbeaure@csclub.uwaterloo.ca)
   4.269 -	 * to support standard MCA probing.
   4.270 -	 *
   4.271 -	 * redone for multi-card detection by ZP Gu (zpg@castle.net)
   4.272 -	 * now works as a module
   4.273 -	 */
   4.274 -
   4.275 -	if( MCA_bus ) {
   4.276 -		int slot, j;
   4.277 -		u_char pos4, pos5;
   4.278 -
   4.279 -		for( j = 0; el3_mca_adapters[j].name != NULL; j ++ ) {
   4.280 -			slot = 0;
   4.281 -			while( slot != MCA_NOTFOUND ) {
   4.282 -				slot = mca_find_unused_adapter(
   4.283 -					el3_mca_adapters[j].id, slot );
   4.284 -				if( slot == MCA_NOTFOUND ) break;
   4.285 -
   4.286 -				/* if we get this far, an adapter has been
   4.287 -				 * detected and is enabled
   4.288 -				 */
   4.289 -
   4.290 -				pos4 = mca_read_stored_pos( slot, 4 );
   4.291 -				pos5 = mca_read_stored_pos( slot, 5 );
   4.292 -
   4.293 -				ioaddr = ((short)((pos4&0xfc)|0x02)) << 8;
   4.294 -				irq = pos5 & 0x0f;
   4.295 -
   4.296 -				/* probing for a card at a particular IO/IRQ */
   4.297 -				if(dev && ((dev->irq >= 1 && dev->irq != irq) ||
   4.298 -			   	(dev->base_addr >= 1 && dev->base_addr != ioaddr))) {
   4.299 -					slot++;         /* probing next slot */
   4.300 -					continue;
   4.301 -				}
   4.302 -
   4.303 -				printk("3c509: found %s at slot %d\n",
   4.304 -					el3_mca_adapters[j].name, slot + 1 );
   4.305 -
   4.306 -				/* claim the slot */
   4.307 -				mca_set_adapter_name(slot, el3_mca_adapters[j].name);
   4.308 -				mca_set_adapter_procfn(slot, NULL, NULL);
   4.309 -				mca_mark_as_used(slot);
   4.310 -
   4.311 -				if_port = pos4 & 0x03;
   4.312 -				if (el3_debug > 2) {
   4.313 -					printk("3c529: irq %d  ioaddr 0x%x  ifport %d\n", irq, ioaddr, if_port);
   4.314 -				}
   4.315 -				EL3WINDOW(0);
   4.316 -				for (i = 0; i < 3; i++) {
   4.317 -					phys_addr[i] = htons(read_eeprom(ioaddr, i));
   4.318 -				}
   4.319 -				
   4.320 -				mca_slot = slot;
   4.321 -
   4.322 -				goto found;
   4.323 -			}
   4.324 -		}
   4.325 -		/* if we get here, we didn't find an MCA adapter */
   4.326 -		return -ENODEV;
   4.327 -	}
   4.328 -#endif /* CONFIG_MCA */
   4.329 -
   4.330 -#if defined(CONFIG_ISAPNP) || defined(CONFIG_ISAPNP_MODULE)
   4.331 -	if (nopnp == 1)
   4.332 -		goto no_pnp;
   4.333 -
   4.334 -	for (i=0; el3_isapnp_adapters[i].vendor != 0; i++) {
   4.335 -		struct pci_dev *idev = NULL;
   4.336 -		int j;
   4.337 -		while ((idev = isapnp_find_dev(NULL,
   4.338 -						el3_isapnp_adapters[i].vendor,
   4.339 -						el3_isapnp_adapters[i].function,
   4.340 -						idev))) {
   4.341 -			idev->prepare(idev);
   4.342 -			/* Deactivation is needed if the driver was called
   4.343 -			   with "nopnp=1" before, does not harm if not. */
   4.344 -			idev->deactivate(idev);
   4.345 -			idev->activate(idev);
   4.346 -			if (!idev->resource[0].start || check_region(idev->resource[0].start, EL3_IO_EXTENT))
   4.347 -				continue;
   4.348 -			ioaddr = idev->resource[0].start;
   4.349 -			if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509 PnP"))
   4.350 -				return -EBUSY;
   4.351 -			irq = idev->irq_resource[0].start;
   4.352 -			if (el3_debug > 3)
   4.353 -				printk ("ISAPnP reports %s at i/o 0x%x, irq %d\n",
   4.354 -					(char*) el3_isapnp_adapters[i].driver_data, ioaddr, irq);
   4.355 -			EL3WINDOW(0);
   4.356 -			for (j = 0; j < 3; j++)
   4.357 -				el3_isapnp_phys_addr[pnp_cards][j] =
   4.358 -					phys_addr[j] =
   4.359 -						htons(read_eeprom(ioaddr, j));
   4.360 -			if_port = read_eeprom(ioaddr, 8) >> 14;
   4.361 -			pnp_cards++;
   4.362 -			goto found;
   4.363 -		}
   4.364 -	}
   4.365 -no_pnp:
   4.366 -#endif /* CONFIG_ISAPNP || CONFIG_ISAPNP_MODULE */
   4.367 -
   4.368 -	/* Select an open I/O location at 0x1*0 to do contention select. */
   4.369 -	for ( ; id_port < 0x200; id_port += 0x10) {
   4.370 -		if (check_region(id_port, 1))
   4.371 -			continue;
   4.372 -		outb(0x00, id_port);
   4.373 -		outb(0xff, id_port);
   4.374 -		if (inb(id_port) & 0x01)
   4.375 -			break;
   4.376 -	}
   4.377 -	if (id_port >= 0x200) {
   4.378 -		/* Rare -- do we really need a warning? */
   4.379 -		printk(" WARNING: No I/O port available for 3c509 activation.\n");
   4.380 -		return -ENODEV;
   4.381 -	}
   4.382 -	/* Next check for all ISA bus boards by sending the ID sequence to the
   4.383 -	   ID_PORT.  We find cards past the first by setting the 'current_tag'
   4.384 -	   on cards as they are found.  Cards with their tag set will not
   4.385 -	   respond to subsequent ID sequences. */
   4.386 -
   4.387 -	outb(0x00, id_port);
   4.388 -	outb(0x00, id_port);
   4.389 -	for(i = 0; i < 255; i++) {
   4.390 -		outb(lrs_state, id_port);
   4.391 -		lrs_state <<= 1;
   4.392 -		lrs_state = lrs_state & 0x100 ? lrs_state ^ 0xcf : lrs_state;
   4.393 -	}
   4.394 -
   4.395 -	/* For the first probe, clear all board's tag registers. */
   4.396 -	if (current_tag == 0)
   4.397 -		outb(0xd0, id_port);
   4.398 -	else				/* Otherwise kill off already-found boards. */
   4.399 -		outb(0xd8, id_port);
   4.400 -
   4.401 -	if (id_read_eeprom(7) != 0x6d50) {
   4.402 -		return -ENODEV;
   4.403 -	}
   4.404 -
   4.405 -	/* Read in EEPROM data, which does contention-select.
   4.406 -	   Only the lowest address board will stay "on-line".
   4.407 -	   3Com got the byte order backwards. */
   4.408 -	for (i = 0; i < 3; i++) {
   4.409 -		phys_addr[i] = htons(id_read_eeprom(i));
   4.410 -	}
   4.411 -
   4.412 -#if defined(CONFIG_ISAPNP) || defined(CONFIG_ISAPNP_MODULE)
   4.413 -	if (nopnp == 0) {
   4.414 -		/* The ISA PnP 3c509 cards respond to the ID sequence.
   4.415 -		   This check is needed in order not to register them twice. */
   4.416 -		for (i = 0; i < pnp_cards; i++) {
   4.417 -			if (phys_addr[0] == el3_isapnp_phys_addr[i][0] &&
   4.418 -			    phys_addr[1] == el3_isapnp_phys_addr[i][1] &&
   4.419 -			    phys_addr[2] == el3_isapnp_phys_addr[i][2])
   4.420 -			{
   4.421 -				if (el3_debug > 3)
   4.422 -					printk("3c509 with address %02x %02x %02x %02x %02x %02x was found by ISAPnP\n",
   4.423 -						phys_addr[0] & 0xff, phys_addr[0] >> 8,
   4.424 -						phys_addr[1] & 0xff, phys_addr[1] >> 8,
   4.425 -						phys_addr[2] & 0xff, phys_addr[2] >> 8);
   4.426 -				/* Set the adaptor tag so that the next card can be found. */
   4.427 -				outb(0xd0 + ++current_tag, id_port);
   4.428 -				goto no_pnp;
   4.429 -			}
   4.430 -		}
   4.431 -	}
   4.432 -#endif /* CONFIG_ISAPNP || CONFIG_ISAPNP_MODULE */
   4.433 -
   4.434 -	{
   4.435 -		unsigned int iobase = id_read_eeprom(8);
   4.436 -		if_port = iobase >> 14;
   4.437 -		ioaddr = 0x200 + ((iobase & 0x1f) << 4);
   4.438 -	}
   4.439 -	irq = id_read_eeprom(9) >> 12;
   4.440 -
   4.441 -	if (dev) {					/* Set passed-in IRQ or I/O Addr. */
   4.442 -		if (dev->irq > 1  &&  dev->irq < 16)
   4.443 -			irq = dev->irq;
   4.444 -
   4.445 -		if (dev->base_addr) {
   4.446 -			if (dev->mem_end == 0x3c509 			/* Magic key */
   4.447 -				&& dev->base_addr >= 0x200  &&  dev->base_addr <= 0x3e0)
   4.448 -				ioaddr = dev->base_addr & 0x3f0;
   4.449 -			else if (dev->base_addr != ioaddr)
   4.450 -				return -ENODEV;
   4.451 -		}
   4.452 -	}
   4.453 -
   4.454 -	if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509"))
   4.455 -		return -EBUSY;
   4.456 -
   4.457 -	/* Set the adaptor tag so that the next card can be found. */
   4.458 -	outb(0xd0 + ++current_tag, id_port);
   4.459 -
   4.460 -	/* Activate the adaptor at the EEPROM location. */
   4.461 -	outb((ioaddr >> 4) | 0xe0, id_port);
   4.462 -
   4.463 -	EL3WINDOW(0);
   4.464 -	if (inw(ioaddr) != 0x6d50) {
   4.465 -		release_region(ioaddr, EL3_IO_EXTENT);
   4.466 -		return -ENODEV;
   4.467 -	}
   4.468 -
   4.469 -	/* Free the interrupt so that some other card can use it. */
   4.470 -	outw(0x0f00, ioaddr + WN0_IRQ);
   4.471 - found:
   4.472 -	if (dev == NULL) {
   4.473 -		dev = init_etherdev(dev, sizeof(struct el3_private));
   4.474 -		if (dev == NULL) {
   4.475 -			release_region(ioaddr, EL3_IO_EXTENT);
   4.476 -			return -ENOMEM;
   4.477 -		}
   4.478 -		SET_MODULE_OWNER(dev);
   4.479 -	}
   4.480 -	memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr));
   4.481 -	dev->base_addr = ioaddr;
   4.482 -	dev->irq = irq;
   4.483 -	dev->if_port = (dev->mem_start & 0x1f) ? dev->mem_start & 3 : if_port;
   4.484 -
   4.485 -	{
   4.486 -		const char *if_names[] = {"10baseT", "AUI", "undefined", "BNC"};
   4.487 -		printk("%s: 3c5x9 at %#3.3lx, %s port, address ",
   4.488 -			   dev->name, dev->base_addr, if_names[dev->if_port]);
   4.489 -	}
   4.490 -
   4.491 -	/* Read in the station address. */
   4.492 -	for (i = 0; i < 6; i++)
   4.493 -		printk(" %2.2x", dev->dev_addr[i]);
   4.494 -	printk(", IRQ %d.\n", dev->irq);
   4.495 -
   4.496 -	/* Make up a EL3-specific-data structure. */
   4.497 -	if (dev->priv == NULL)
   4.498 -		dev->priv = kmalloc(sizeof(struct el3_private), GFP_KERNEL);
   4.499 -	if (dev->priv == NULL)
   4.500 -		return -ENOMEM;
   4.501 -	memset(dev->priv, 0, sizeof(struct el3_private));
   4.502 -	
   4.503 -	lp = dev->priv;
   4.504 -	lp->mca_slot = mca_slot;
   4.505 -	lp->next_dev = el3_root_dev;
   4.506 -	spin_lock_init(&lp->lock);
   4.507 -	el3_root_dev = dev;
   4.508 -
   4.509 -	if (el3_debug > 0)
   4.510 -		printk(KERN_INFO "%s" KERN_INFO "%s", versionA, versionB);
   4.511 -
   4.512 -	/* The EL3-specific entries in the device structure. */
   4.513 -	dev->open = &el3_open;
   4.514 -	dev->hard_start_xmit = &el3_start_xmit;
   4.515 -	dev->stop = &el3_close;
   4.516 -	dev->get_stats = &el3_get_stats;
   4.517 -	dev->set_multicast_list = &set_multicast_list;
   4.518 -	dev->tx_timeout = el3_tx_timeout;
   4.519 -	dev->watchdog_timeo = TX_TIMEOUT;
   4.520 -
   4.521 -	/* Fill in the generic fields of the device structure. */
   4.522 -	ether_setup(dev);
   4.523 -	return 0;
   4.524 -}
   4.525 -
   4.526 -/* Read a word from the EEPROM using the regular EEPROM access register.
   4.527 -   Assume that we are in register window zero.
   4.528 - */
   4.529 -static ushort __init read_eeprom(int ioaddr, int index)
   4.530 -{
   4.531 -	outw(EEPROM_READ + index, ioaddr + 10);
   4.532 -	/* Pause for at least 162 us. for the read to take place. */
   4.533 -	udelay (500);
   4.534 -	return inw(ioaddr + 12);
   4.535 -}
   4.536 -
   4.537 -/* Read a word from the EEPROM when in the ISA ID probe state. */
   4.538 -static ushort __init id_read_eeprom(int index)
   4.539 -{
   4.540 -	int bit, word = 0;
   4.541 -
   4.542 -	/* Issue read command, and pause for at least 162 us. for it to complete.
   4.543 -	   Assume extra-fast 16Mhz bus. */
   4.544 -	outb(EEPROM_READ + index, id_port);
   4.545 -
   4.546 -	/* Pause for at least 162 us. for the read to take place. */
   4.547 -	udelay (500);
   4.548 -	
   4.549 -	for (bit = 15; bit >= 0; bit--)
   4.550 -		word = (word << 1) + (inb(id_port) & 0x01);
   4.551 -
   4.552 -	if (el3_debug > 3)
   4.553 -		printk("  3c509 EEPROM word %d %#4.4x.\n", index, word);
   4.554 -
   4.555 -	return word;
   4.556 -}
   4.557 -
   4.558 -
   4.559 -static int
   4.560 -el3_open(struct net_device *dev)
   4.561 -{
   4.562 -	int ioaddr = dev->base_addr;
   4.563 -	int i;
   4.564 -
   4.565 -	outw(TxReset, ioaddr + EL3_CMD);
   4.566 -	outw(RxReset, ioaddr + EL3_CMD);
   4.567 -	outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
   4.568 -
   4.569 -	i = request_irq(dev->irq, &el3_interrupt, 0, dev->name, dev);
   4.570 -	if (i) return i;
   4.571 -
   4.572 -	EL3WINDOW(0);
   4.573 -	if (el3_debug > 3)
   4.574 -		printk("%s: Opening, IRQ %d	 status@%x %4.4x.\n", dev->name,
   4.575 -			   dev->irq, ioaddr + EL3_STATUS, inw(ioaddr + EL3_STATUS));
   4.576 -
   4.577 -	/* Activate board: this is probably unnecessary. */
   4.578 -	outw(0x0001, ioaddr + 4);
   4.579 -
   4.580 -	/* Set the IRQ line. */
   4.581 -	outw((dev->irq << 12) | 0x0f00, ioaddr + WN0_IRQ);
   4.582 -
   4.583 -	/* Set the station address in window 2 each time opened. */
   4.584 -	EL3WINDOW(2);
   4.585 -
   4.586 -	for (i = 0; i < 6; i++)
   4.587 -		outb(dev->dev_addr[i], ioaddr + i);
   4.588 -
   4.589 -	if (dev->if_port == 3)
   4.590 -		/* Start the thinnet transceiver. We should really wait 50ms...*/
   4.591 -		outw(StartCoax, ioaddr + EL3_CMD);
   4.592 -	else if (dev->if_port == 0) {
   4.593 -		/* 10baseT interface, enabled link beat and jabber check. */
   4.594 -		EL3WINDOW(4);
   4.595 -		outw(inw(ioaddr + WN4_MEDIA) | MEDIA_TP, ioaddr + WN4_MEDIA);
   4.596 -	}
   4.597 -
   4.598 -	/* Switch to the stats window, and clear all stats by reading. */
   4.599 -	outw(StatsDisable, ioaddr + EL3_CMD);
   4.600 -	EL3WINDOW(6);
   4.601 -	for (i = 0; i < 9; i++)
   4.602 -		inb(ioaddr + i);
   4.603 -	inw(ioaddr + 10);
   4.604 -	inw(ioaddr + 12);
   4.605 -
   4.606 -	/* Switch to register set 1 for normal use. */
   4.607 -	EL3WINDOW(1);
   4.608 -
   4.609 -	/* Accept b-case and phys addr only. */
   4.610 -	outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
   4.611 -	outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
   4.612 -
   4.613 -	netif_start_queue(dev);
   4.614 -
   4.615 -	outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
   4.616 -	outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
   4.617 -	/* Allow status bits to be seen. */
   4.618 -	outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
   4.619 -	/* Ack all pending events, and set active indicator mask. */
   4.620 -	outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
   4.621 -		 ioaddr + EL3_CMD);
   4.622 -	outw(SetIntrEnb | IntLatch|TxAvailable|TxComplete|RxComplete|StatsFull,
   4.623 -		 ioaddr + EL3_CMD);
   4.624 -
   4.625 -	if (el3_debug > 3)
   4.626 -		printk("%s: Opened 3c509  IRQ %d  status %4.4x.\n",
   4.627 -			   dev->name, dev->irq, inw(ioaddr + EL3_STATUS));
   4.628 -
   4.629 -	return 0;
   4.630 -}
   4.631 -
   4.632 -static void
   4.633 -el3_tx_timeout (struct net_device *dev)
   4.634 -{
   4.635 -	struct el3_private *lp = (struct el3_private *)dev->priv;
   4.636 -	int ioaddr = dev->base_addr;
   4.637 -
   4.638 -	/* Transmitter timeout, serious problems. */
   4.639 -	printk("%s: transmit timed out, Tx_status %2.2x status %4.4x "
   4.640 -		   "Tx FIFO room %d.\n",
   4.641 -		   dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS),
   4.642 -		   inw(ioaddr + TX_FREE));
   4.643 -	lp->stats.tx_errors++;
   4.644 -	dev->trans_start = jiffies;
   4.645 -	/* Issue TX_RESET and TX_START commands. */
   4.646 -	outw(TxReset, ioaddr + EL3_CMD);
   4.647 -	outw(TxEnable, ioaddr + EL3_CMD);
   4.648 -	netif_wake_queue(dev);
   4.649 -}
   4.650 -
   4.651 -
   4.652 -static int
   4.653 -el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
   4.654 -{
   4.655 -	struct el3_private *lp = (struct el3_private *)dev->priv;
   4.656 -	int ioaddr = dev->base_addr;
   4.657 -	unsigned long flags;
   4.658 -
   4.659 -	netif_stop_queue (dev);
   4.660 -
   4.661 -	lp->stats.tx_bytes += skb->len;
   4.662 -	
   4.663 -	if (el3_debug > 4) {
   4.664 -		printk("%s: el3_start_xmit(length = %u) called, status %4.4x.\n",
   4.665 -			   dev->name, skb->len, inw(ioaddr + EL3_STATUS));
   4.666 -	}
   4.667 -#if 0
   4.668 -#ifndef final_version
   4.669 -	{	/* Error-checking code, delete someday. */
   4.670 -		ushort status = inw(ioaddr + EL3_STATUS);
   4.671 -		if (status & 0x0001 		/* IRQ line active, missed one. */
   4.672 -			&& inw(ioaddr + EL3_STATUS) & 1) { 			/* Make sure. */
   4.673 -			printk("%s: Missed interrupt, status then %04x now %04x"
   4.674 -				   "  Tx %2.2x Rx %4.4x.\n", dev->name, status,
   4.675 -				   inw(ioaddr + EL3_STATUS), inb(ioaddr + TX_STATUS),
   4.676 -				   inw(ioaddr + RX_STATUS));
   4.677 -			/* Fake interrupt trigger by masking, acknowledge interrupts. */
   4.678 -			outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
   4.679 -			outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
   4.680 -				 ioaddr + EL3_CMD);
   4.681 -			outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
   4.682 -		}
   4.683 -	}
   4.684 -#endif
   4.685 -#endif
   4.686 -	/*
   4.687 -	 *	We lock the driver against other processors. Note
   4.688 -	 *	we don't need to lock versus the IRQ as we suspended
   4.689 -	 *	that. This means that we lose the ability to take
   4.690 -	 *	an RX during a TX upload. That sucks a bit with SMP
   4.691 -	 *	on an original 3c509 (2K buffer)
   4.692 -	 *
   4.693 -	 *	Using disable_irq stops us crapping on other
   4.694 -	 *	time sensitive devices.
   4.695 -	 */
   4.696 -
   4.697 -    	spin_lock_irqsave(&lp->lock, flags);
   4.698 -	    
   4.699 -	/* Put out the doubleword header... */
   4.700 -	outw(skb->len, ioaddr + TX_FIFO);
   4.701 -	outw(0x00, ioaddr + TX_FIFO);
   4.702 -	/* ... and the packet rounded to a doubleword. */
   4.703 -#ifdef  __powerpc__
   4.704 -	outsl_unswapped(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
   4.705 -#else
   4.706 -	outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
   4.707 -#endif
   4.708 -
   4.709 -	dev->trans_start = jiffies;
   4.710 -	if (inw(ioaddr + TX_FREE) > 1536)
   4.711 -		netif_start_queue(dev);
   4.712 -	else
   4.713 -		/* Interrupt us when the FIFO has room for max-sized packet. */
   4.714 -		outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);
   4.715 -
   4.716 -	spin_unlock_irqrestore(&lp->lock, flags);
   4.717 -
   4.718 -	dev_kfree_skb (skb);
   4.719 -
   4.720 -	/* Clear the Tx status stack. */
   4.721 -	{
   4.722 -		short tx_status;
   4.723 -		int i = 4;
   4.724 -
   4.725 -		while (--i > 0	&&	(tx_status = inb(ioaddr + TX_STATUS)) > 0) {
   4.726 -			if (tx_status & 0x38) lp->stats.tx_aborted_errors++;
   4.727 -			if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
   4.728 -			if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
   4.729 -			outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
   4.730 -		}
   4.731 -	}
   4.732 -	return 0;
   4.733 -}
   4.734 -
   4.735 -/* The EL3 interrupt handler. */
   4.736 -static void
   4.737 -el3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
   4.738 -{
   4.739 -	struct net_device *dev = (struct net_device *)dev_id;
   4.740 -	struct el3_private *lp;
   4.741 -	int ioaddr, status;
   4.742 -	int i = max_interrupt_work;
   4.743 -
   4.744 -	if (dev == NULL) {
   4.745 -		printk ("el3_interrupt(): irq %d for unknown device.\n", irq);
   4.746 -		return;
   4.747 -	}
   4.748 -
   4.749 -	lp = (struct el3_private *)dev->priv;
   4.750 -	spin_lock(&lp->lock);
   4.751 -
   4.752 -	ioaddr = dev->base_addr;
   4.753 -
   4.754 -	if (el3_debug > 4) {
   4.755 -		status = inw(ioaddr + EL3_STATUS);
   4.756 -		printk("%s: interrupt, status %4.4x.\n", dev->name, status);
   4.757 -	}
   4.758 -
   4.759 -	while ((status = inw(ioaddr + EL3_STATUS)) &
   4.760 -		   (IntLatch | RxComplete | StatsFull)) {
   4.761 -
   4.762 -		if (status & RxComplete)
   4.763 -			el3_rx(dev);
   4.764 -
   4.765 -		if (status & TxAvailable) {
   4.766 -			if (el3_debug > 5)
   4.767 -				printk("	TX room bit was handled.\n");
   4.768 -			/* There's room in the FIFO for a full-sized packet. */
   4.769 -			outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
   4.770 -			netif_wake_queue (dev);
   4.771 -		}
   4.772 -		if (status & (AdapterFailure | RxEarly | StatsFull | TxComplete)) {
   4.773 -			/* Handle all uncommon interrupts. */
   4.774 -			if (status & StatsFull)				/* Empty statistics. */
   4.775 -				update_stats(dev);
   4.776 -			if (status & RxEarly) {				/* Rx early is unused. */
   4.777 -				el3_rx(dev);
   4.778 -				outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
   4.779 -			}
   4.780 -			if (status & TxComplete) {			/* Really Tx error. */
   4.781 -				struct el3_private *lp = (struct el3_private *)dev->priv;
   4.782 -				short tx_status;
   4.783 -				int i = 4;
   4.784 -
   4.785 -				while (--i>0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
   4.786 -					if (tx_status & 0x38) lp->stats.tx_aborted_errors++;
   4.787 -					if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
   4.788 -					if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
   4.789 -					outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
   4.790 -				}
   4.791 -			}
   4.792 -			if (status & AdapterFailure) {
   4.793 -				/* Adapter failure requires Rx reset and reinit. */
   4.794 -				outw(RxReset, ioaddr + EL3_CMD);
   4.795 -				/* Set the Rx filter to the current state. */
   4.796 -				outw(SetRxFilter | RxStation | RxBroadcast
   4.797 -					 | (dev->flags & IFF_ALLMULTI ? RxMulticast : 0)
   4.798 -					 | (dev->flags & IFF_PROMISC ? RxProm : 0),
   4.799 -					 ioaddr + EL3_CMD);
   4.800 -				outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
   4.801 -				outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
   4.802 -			}
   4.803 -		}
   4.804 -
   4.805 -		if (--i < 0) {
   4.806 -			printk("%s: Infinite loop in interrupt, status %4.4x.\n",
   4.807 -				   dev->name, status);
   4.808 -			/* Clear all interrupts. */
   4.809 -			outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
   4.810 -			break;
   4.811 -		}
   4.812 -		/* Acknowledge the IRQ. */
   4.813 -		outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD); /* Ack IRQ */
   4.814 -	}
   4.815 -
   4.816 -	if (el3_debug > 4) {
   4.817 -		printk("%s: exiting interrupt, status %4.4x.\n", dev->name,
   4.818 -			   inw(ioaddr + EL3_STATUS));
   4.819 -	}
   4.820 -	spin_unlock(&lp->lock);
   4.821 -	return;
   4.822 -}
   4.823 -
   4.824 -
   4.825 -static struct net_device_stats *
   4.826 -el3_get_stats(struct net_device *dev)
   4.827 -{
   4.828 -	struct el3_private *lp = (struct el3_private *)dev->priv;
   4.829 -	unsigned long flags;
   4.830 -
   4.831 -	/*
   4.832 -	 *	This is fast enough not to bother with disable IRQ
   4.833 -	 *	stuff.
   4.834 -	 */
   4.835 -	 
   4.836 -	spin_lock_irqsave(&lp->lock, flags);
   4.837 -	update_stats(dev);
   4.838 -	spin_unlock_irqrestore(&lp->lock, flags);
   4.839 -	return &lp->stats;
   4.840 -}
   4.841 -
   4.842 -/*  Update statistics.  We change to register window 6, so this should be run
   4.843 -	single-threaded if the device is active. This is expected to be a rare
   4.844 -	operation, and it's simpler for the rest of the driver to assume that
   4.845 -	window 1 is always valid rather than use a special window-state variable.
   4.846 -	*/
   4.847 -static void update_stats(struct net_device *dev)
   4.848 -{
   4.849 -	struct el3_private *lp = (struct el3_private *)dev->priv;
   4.850 -	int ioaddr = dev->base_addr;
   4.851 -
   4.852 -	if (el3_debug > 5)
   4.853 -		printk("   Updating the statistics.\n");
   4.854 -	/* Turn off statistics updates while reading. */
   4.855 -	outw(StatsDisable, ioaddr + EL3_CMD);
   4.856 -	/* Switch to the stats window, and read everything. */
   4.857 -	EL3WINDOW(6);
   4.858 -	lp->stats.tx_carrier_errors 	+= inb(ioaddr + 0);
   4.859 -	lp->stats.tx_heartbeat_errors	+= inb(ioaddr + 1);
   4.860 -	/* Multiple collisions. */	   inb(ioaddr + 2);
   4.861 -	lp->stats.collisions		+= inb(ioaddr + 3);
   4.862 -	lp->stats.tx_window_errors	+= inb(ioaddr + 4);
   4.863 -	lp->stats.rx_fifo_errors	+= inb(ioaddr + 5);
   4.864 -	lp->stats.tx_packets		+= inb(ioaddr + 6);
   4.865 -	/* Rx packets	*/		   inb(ioaddr + 7);
   4.866 -	/* Tx deferrals */		   inb(ioaddr + 8);
   4.867 -	inw(ioaddr + 10);	/* Total Rx and Tx octets. */
   4.868 -	inw(ioaddr + 12);
   4.869 -
   4.870 -	/* Back to window 1, and turn statistics back on. */
   4.871 -	EL3WINDOW(1);
   4.872 -	outw(StatsEnable, ioaddr + EL3_CMD);
   4.873 -	return;
   4.874 -}
   4.875 -
   4.876 -static int
   4.877 -el3_rx(struct net_device *dev)
   4.878 -{
   4.879 -	struct el3_private *lp = (struct el3_private *)dev->priv;
   4.880 -	int ioaddr = dev->base_addr;
   4.881 -	short rx_status;
   4.882 -
   4.883 -	if (el3_debug > 5)
   4.884 -		printk("   In rx_packet(), status %4.4x, rx_status %4.4x.\n",
   4.885 -			   inw(ioaddr+EL3_STATUS), inw(ioaddr+RX_STATUS));
   4.886 -	while ((rx_status = inw(ioaddr + RX_STATUS)) > 0) {
   4.887 -		if (rx_status & 0x4000) { /* Error, update stats. */
   4.888 -			short error = rx_status & 0x3800;
   4.889 -
   4.890 -			outw(RxDiscard, ioaddr + EL3_CMD);
   4.891 -			lp->stats.rx_errors++;
   4.892 -			switch (error) {
   4.893 -			case 0x0000:		lp->stats.rx_over_errors++; break;
   4.894 -			case 0x0800:		lp->stats.rx_length_errors++; break;
   4.895 -			case 0x1000:		lp->stats.rx_frame_errors++; break;
   4.896 -			case 0x1800:		lp->stats.rx_length_errors++; break;
   4.897 -			case 0x2000:		lp->stats.rx_frame_errors++; break;
   4.898 -			case 0x2800:		lp->stats.rx_crc_errors++; break;
   4.899 -			}
   4.900 -		} else {
   4.901 -			short pkt_len = rx_status & 0x7ff;
   4.902 -			struct sk_buff *skb;
   4.903 -
   4.904 -			skb = dev_alloc_skb(pkt_len+5);
   4.905 -			lp->stats.rx_bytes += pkt_len;
   4.906 -			if (el3_debug > 4)
   4.907 -				printk("Receiving packet size %d status %4.4x.\n",
   4.908 -					   pkt_len, rx_status);
   4.909 -			if (skb != NULL) {
   4.910 -				skb->dev = dev;
   4.911 -				skb_reserve(skb, 2);     /* Align IP on 16 byte */
   4.912 -
   4.913 -				/* 'skb->data' points to the start of sk_buff data area. */
   4.914 -#ifdef  __powerpc__
   4.915 -				insl_unswapped(ioaddr+RX_FIFO, skb_put(skb,pkt_len),
   4.916 -							   (pkt_len + 3) >> 2);
   4.917 -#else
   4.918 -				insl(ioaddr + RX_FIFO, skb_put(skb,pkt_len),
   4.919 -					 (pkt_len + 3) >> 2);
   4.920 -#endif
   4.921 -
   4.922 -				outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
   4.923 -				skb->protocol = eth_type_trans(skb,dev);
   4.924 -				netif_rx(skb);
   4.925 -				dev->last_rx = jiffies;
   4.926 -				lp->stats.rx_packets++;
   4.927 -				continue;
   4.928 -			}
   4.929 -			outw(RxDiscard, ioaddr + EL3_CMD);
   4.930 -			lp->stats.rx_dropped++;
   4.931 -			if (el3_debug)
   4.932 -				printk("%s: Couldn't allocate a sk_buff of size %d.\n",
   4.933 -					   dev->name, pkt_len);
   4.934 -		}
   4.935 -		inw(ioaddr + EL3_STATUS); 				/* Delay. */
   4.936 -		while (inw(ioaddr + EL3_STATUS) & 0x1000)
   4.937 -			printk(KERN_DEBUG "	Waiting for 3c509 to discard packet, status %x.\n",
   4.938 -				   inw(ioaddr + EL3_STATUS) );
   4.939 -	}
   4.940 -
   4.941 -	return 0;
   4.942 -}
   4.943 -
   4.944 -/*
   4.945 - *     Set or clear the multicast filter for this adaptor.
   4.946 - */
   4.947 -static void
   4.948 -set_multicast_list(struct net_device *dev)
   4.949 -{
   4.950 -	unsigned long flags;
   4.951 -	struct el3_private *lp = (struct el3_private *)dev->priv;
   4.952 -	int ioaddr = dev->base_addr;
   4.953 -
   4.954 -	if (el3_debug > 1) {
   4.955 -		static int old;
   4.956 -		if (old != dev->mc_count) {
   4.957 -			old = dev->mc_count;
   4.958 -			printk("%s: Setting Rx mode to %d addresses.\n", dev->name, dev->mc_count);
   4.959 -		}
   4.960 -	}
   4.961 -	spin_lock_irqsave(&lp->lock, flags);
   4.962 -	if (dev->flags&IFF_PROMISC) {
   4.963 -		outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
   4.964 -			 ioaddr + EL3_CMD);
   4.965 -	}
   4.966 -	else if (dev->mc_count || (dev->flags&IFF_ALLMULTI)) {
   4.967 -		outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast, ioaddr + EL3_CMD);
   4.968 -	}
   4.969 -	else
   4.970 -                outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
   4.971 -	spin_unlock_irqrestore(&lp->lock, flags);
   4.972 -}
   4.973 -
   4.974 -static int
   4.975 -el3_close(struct net_device *dev)
   4.976 -{
   4.977 -	int ioaddr = dev->base_addr;
   4.978 -
   4.979 -	if (el3_debug > 2)
   4.980 -		printk("%s: Shutting down ethercard.\n", dev->name);
   4.981 -
   4.982 -	netif_stop_queue(dev);
   4.983 -
   4.984 -	/* Turn off statistics ASAP.  We update lp->stats below. */
   4.985 -	outw(StatsDisable, ioaddr + EL3_CMD);
   4.986 -
   4.987 -	/* Disable the receiver and transmitter. */
   4.988 -	outw(RxDisable, ioaddr + EL3_CMD);
   4.989 -	outw(TxDisable, ioaddr + EL3_CMD);
   4.990 -
   4.991 -	if (dev->if_port == 3)
   4.992 -		/* Turn off thinnet power.  Green! */
   4.993 -		outw(StopCoax, ioaddr + EL3_CMD);
   4.994 -	else if (dev->if_port == 0) {
   4.995 -		/* Disable link beat and jabber, if_port may change ere next open(). */
   4.996 -		EL3WINDOW(4);
   4.997 -		outw(inw(ioaddr + WN4_MEDIA) & ~MEDIA_TP, ioaddr + WN4_MEDIA);
   4.998 -	}
   4.999 -
  4.1000 -	free_irq(dev->irq, dev);
  4.1001 -	/* Switching back to window 0 disables the IRQ. */
  4.1002 -	EL3WINDOW(0);
  4.1003 -	/* But we explicitly zero the IRQ line select anyway. */
  4.1004 -	outw(0x0f00, ioaddr + WN0_IRQ);
  4.1005 -
  4.1006 -	update_stats(dev);
  4.1007 -	return 0;
  4.1008 -}
  4.1009 -
  4.1010 -/*#ifdef MODULE*/
  4.1011 -/* Parameters that may be passed into the module. */
  4.1012 -static int debug = -1;
  4.1013 -static int irq[] = {-1, -1, -1, -1, -1, -1, -1, -1};
  4.1014 -static int xcvr[] = {-1, -1, -1, -1, -1, -1, -1, -1};
  4.1015 -
  4.1016 -MODULE_PARM(debug,"i");
  4.1017 -MODULE_PARM(irq,"1-8i");
  4.1018 -MODULE_PARM(xcvr,"1-8i");
  4.1019 -MODULE_PARM(max_interrupt_work, "i");
  4.1020 -MODULE_PARM_DESC(debug, "EtherLink III debug level (0-6)");
  4.1021 -MODULE_PARM_DESC(irq, "EtherLink III IRQ number(s) (assigned)");
  4.1022 -MODULE_PARM_DESC(xcvr,"EtherLink III tranceiver(s) (0=internal, 1=external)");
  4.1023 -MODULE_PARM_DESC(max_interrupt_work, "EtherLink III maximum events handled per interrupt");
  4.1024 -#ifdef CONFIG_ISAPNP
  4.1025 -MODULE_PARM(nopnp, "i");
  4.1026 -MODULE_PARM_DESC(nopnp, "EtherLink III disable ISA PnP support (0-1)");
  4.1027 -#endif	/* CONFIG_ISAPNP */
  4.1028 -
  4.1029 -int
  4.1030 -init_module(void)
  4.1031 -{
  4.1032 -	int el3_cards = 0;
  4.1033 -
  4.1034 -	if (debug >= 0)
  4.1035 -		el3_debug = debug;
  4.1036 -
  4.1037 -	el3_root_dev = NULL;
  4.1038 -	while (el3_probe(0) == 0) {
  4.1039 -		if (irq[el3_cards] > 1)
  4.1040 -			el3_root_dev->irq = irq[el3_cards];
  4.1041 -		if (xcvr[el3_cards] >= 0)
  4.1042 -			el3_root_dev->if_port = xcvr[el3_cards];
  4.1043 -		el3_cards++;
  4.1044 -	}
  4.1045 -
  4.1046 -	return el3_cards ? 0 : -ENODEV;
  4.1047 -}
  4.1048 -
  4.1049 -void
  4.1050 -cleanup_module(void)
  4.1051 -{
  4.1052 -	struct net_device *next_dev;
  4.1053 -
  4.1054 -	/* No need to check MOD_IN_USE, as sys_delete_module() checks. */
  4.1055 -	while (el3_root_dev) {
  4.1056 -		struct el3_private *lp = (struct el3_private *)el3_root_dev->priv;
  4.1057 -#ifdef CONFIG_MCA		
  4.1058 -		if(lp->mca_slot!=-1)
  4.1059 -			mca_mark_as_unused(lp->mca_slot);
  4.1060 -#endif			
  4.1061 -		next_dev = lp->next_dev;
  4.1062 -		unregister_netdev(el3_root_dev);
  4.1063 -		release_region(el3_root_dev->base_addr, EL3_IO_EXTENT);
  4.1064 -		kfree(el3_root_dev);
  4.1065 -		el3_root_dev = next_dev;
  4.1066 -	}
  4.1067 -}
  4.1068 -/*#endif*/
  4.1069 -
  4.1070 -module_init(init_module);
  4.1071 -module_exit(cleanup_module);
     5.1 --- a/xen-2.4.16/drivers/net/3c59x.c	Wed Feb 05 13:56:14 2003 +0000
     5.2 +++ b/xen-2.4.16/drivers/net/3c59x.c	Thu Feb 06 16:31:29 2003 +0000
     5.3 @@ -188,13 +188,15 @@
     5.4  /* "Knobs" that adjust features and parameters. */
     5.5  /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
     5.6     Setting to > 1512 effectively disables this feature. */
     5.7 -#ifndef __arm__
     5.8 +/*#ifndef __arm__
     5.9  static const int rx_copybreak = 200;
    5.10 -#else
    5.11 +#else*/
    5.12  /* ARM systems perform better by disregarding the bus-master
    5.13     transfer capability of these cards. -- rmk */
    5.14 -static const int rx_copybreak = 1513;
    5.15 -#endif
    5.16 +/*static const int rx_copybreak = 1513;
    5.17 +#endif*/
    5.18 +static const int rx_copybreak = 0; /* Xen doesn't copybreak in drivers. */
    5.19 +
    5.20  /* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
    5.21  static const int mtu = 1500;
    5.22  /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
     6.1 --- a/xen-2.4.16/drivers/net/8139cp.c	Wed Feb 05 13:56:14 2003 +0000
     6.2 +++ b/xen-2.4.16/drivers/net/8139cp.c	Thu Feb 06 16:31:29 2003 +0000
     6.3 @@ -78,13 +78,17 @@ MODULE_PARM (multicast_filter_limit, "i"
     6.4  MODULE_PARM_DESC (multicast_filter_limit, "8139cp maximum number of filtered multicast addresses");
     6.5  
     6.6  /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
     6.7 -#if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \
     6.8 +/*#if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \
     6.9          || defined(__sparc_) || defined(__ia64__) \
    6.10          || defined(__sh__) || defined(__mips__)
    6.11  static int rx_copybreak = 1518;
    6.12  #else
    6.13  static int rx_copybreak = 100;
    6.14 -#endif
    6.15 +#endif*/
    6.16 +
    6.17 +/* Xen doesn't do rx_copybreak in drivers. */
    6.18 +static int rx_copybreak = 0;
    6.19 +        
    6.20  MODULE_PARM (rx_copybreak, "i");
    6.21  MODULE_PARM_DESC (rx_copybreak, "8139cp Breakpoint at which Rx packets are copied");
    6.22  
     7.1 --- a/xen-2.4.16/drivers/net/8139too.c	Wed Feb 05 13:56:14 2003 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,2324 +0,0 @@
     7.4 -
     7.5 -#define CONFIG_8139TOO_8129
     7.6 -
     7.7 -/*
     7.8 -
     7.9 -	8139too.c: A RealTek RTL-8139 Fast Ethernet driver for Linux.
    7.10 -
    7.11 -	Maintained by Jeff Garzik <jgarzik@mandrakesoft.com>
    7.12 -	Copyright 2000,2001 Jeff Garzik
    7.13 -
    7.14 -	Much code comes from Donald Becker's rtl8139.c driver,
    7.15 -	versions 1.13 and older.  This driver was originally based
    7.16 -	on rtl8139.c version 1.07.  Header of rtl8139.c version 1.13:
    7.17 -
    7.18 -	-----<snip>-----
    7.19 -
    7.20 -        	Written 1997-2001 by Donald Becker.
    7.21 -		This software may be used and distributed according to the
    7.22 -		terms of the GNU General Public License (GPL), incorporated
    7.23 -		herein by reference.  Drivers based on or derived from this
    7.24 -		code fall under the GPL and must retain the authorship,
    7.25 -		copyright and license notice.  This file is not a complete
    7.26 -		program and may only be used when the entire operating
    7.27 -		system is licensed under the GPL.
    7.28 -
    7.29 -		This driver is for boards based on the RTL8129 and RTL8139
    7.30 -		PCI ethernet chips.
    7.31 -
    7.32 -		The author may be reached as becker@scyld.com, or C/O Scyld
    7.33 -		Computing Corporation 410 Severn Ave., Suite 210 Annapolis
    7.34 -		MD 21403
    7.35 -
    7.36 -		Support and updates available at
    7.37 -		http://www.scyld.com/network/rtl8139.html
    7.38 -
    7.39 -		Twister-tuning table provided by Kinston
    7.40 -		<shangh@realtek.com.tw>.
    7.41 -
    7.42 -	-----<snip>-----
    7.43 -
    7.44 -	This software may be used and distributed according to the terms
    7.45 -	of the GNU General Public License, incorporated herein by reference.
    7.46 -
    7.47 -	Contributors:
    7.48 -
    7.49 -		Donald Becker - he wrote the original driver, kudos to him!
    7.50 -		(but please don't e-mail him for support, this isn't his driver)
    7.51 -
    7.52 -		Tigran Aivazian - bug fixes, skbuff free cleanup
    7.53 -
    7.54 -		Martin Mares - suggestions for PCI cleanup
    7.55 -
    7.56 -		David S. Miller - PCI DMA and softnet updates
    7.57 -
    7.58 -		Ernst Gill - fixes ported from BSD driver
    7.59 -
    7.60 -		Daniel Kobras - identified specific locations of
    7.61 -			posted MMIO write bugginess
    7.62 -
    7.63 -		Gerard Sharp - bug fix, testing and feedback
    7.64 -
    7.65 -		David Ford - Rx ring wrap fix
    7.66 -
    7.67 -		Dan DeMaggio - swapped RTL8139 cards with me, and allowed me
    7.68 -		to find and fix a crucial bug on older chipsets.
    7.69 -
    7.70 -		Donald Becker/Chris Butterworth/Marcus Westergren -
    7.71 -		Noticed various Rx packet size-related buglets.
    7.72 -
    7.73 -		Santiago Garcia Mantinan - testing and feedback
    7.74 -
    7.75 -		Jens David - 2.2.x kernel backports
    7.76 -
    7.77 -		Martin Dennett - incredibly helpful insight on undocumented
    7.78 -		features of the 8139 chips
    7.79 -
    7.80 -		Jean-Jacques Michel - bug fix
    7.81 -
    7.82 -		Tobias Ringström - Rx interrupt status checking suggestion
    7.83 -
    7.84 -		Andrew Morton - Clear blocked signals, avoid
    7.85 -		buffer overrun setting current->comm.
    7.86 -
    7.87 -		Kalle Olavi Niemitalo - Wake-on-LAN ioctls
    7.88 -
    7.89 -		Robert Kuebel - Save kernel thread from dying on any signal.
    7.90 -
    7.91 -	Submitting bug reports:
    7.92 -
    7.93 -		"rtl8139-diag -mmmaaavvveefN" output
    7.94 -		enable RTL8139_DEBUG below, and look at 'dmesg' or kernel log
    7.95 -
    7.96 -		See 8139too.txt for more details.
    7.97 -
    7.98 -*/
    7.99 -
   7.100 -#define DRV_NAME	"8139too"
   7.101 -#define DRV_VERSION	"0.9.22"
   7.102 -
   7.103 -
   7.104 -#include <linux/config.h>
   7.105 -#include <linux/module.h>
   7.106 -//#include <linux/kernel.h>
   7.107 -//#include <linux/compiler.h>
   7.108 -#include <linux/pci.h>
   7.109 -#include <linux/init.h>
   7.110 -#include <linux/ioport.h>
   7.111 -#include <linux/netdevice.h>
   7.112 -#include <linux/etherdevice.h>
   7.113 -//#include <linux/rtnetlink.h>
   7.114 -#include <linux/delay.h>
   7.115 -#include <linux/ethtool.h>
   7.116 -#include <linux/mii.h>
   7.117 -//#include <linux/completion.h>
   7.118 -#include <asm/io.h>
   7.119 -#include <asm/uaccess.h>
   7.120 -
   7.121 -#define RTL8139_DRIVER_NAME   DRV_NAME " Fast Ethernet driver " DRV_VERSION
   7.122 -#define PFX DRV_NAME ": "
   7.123 -
   7.124 -
   7.125 -/* enable PIO instead of MMIO, if CONFIG_8139TOO_PIO is selected */
   7.126 -#ifdef CONFIG_8139TOO_PIO
   7.127 -#define USE_IO_OPS 1
   7.128 -#endif
   7.129 -
   7.130 -/* define to 1 to enable copious debugging info */
   7.131 -#undef RTL8139_DEBUG
   7.132 -
   7.133 -/* define to 1 to disable lightweight runtime debugging checks */
   7.134 -#undef RTL8139_NDEBUG
   7.135 -
   7.136 -
   7.137 -#ifdef RTL8139_DEBUG
   7.138 -/* note: prints function name for you */
   7.139 -#  define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
   7.140 -#else
   7.141 -#  define DPRINTK(fmt, args...)
   7.142 -#endif
   7.143 -
   7.144 -#ifdef RTL8139_NDEBUG
   7.145 -#  define assert(expr) do {} while (0)
   7.146 -#else
   7.147 -#  define assert(expr) \
   7.148 -        if(!(expr)) {					\
   7.149 -        printk( "Assertion failed! %s,%s,%s,line=%d\n",	\
   7.150 -        #expr,__FILE__,__FUNCTION__,__LINE__);		\
   7.151 -        }
   7.152 -#endif
   7.153 -
   7.154 -
   7.155 -/* A few user-configurable values. */
   7.156 -/* media options */
   7.157 -#define MAX_UNITS 8
   7.158 -static int media[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
   7.159 -static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
   7.160 -
   7.161 -/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
   7.162 -static int max_interrupt_work = 20;
   7.163 -
   7.164 -/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
   7.165 -   The RTL chips use a 64 element hash table based on the Ethernet CRC.  */
   7.166 -static int multicast_filter_limit = 32;
   7.167 -
   7.168 -/* Size of the in-memory receive ring. */
   7.169 -#define RX_BUF_LEN_IDX	2	/* 0==8K, 1==16K, 2==32K, 3==64K */
   7.170 -#define RX_BUF_LEN	(8192 << RX_BUF_LEN_IDX)
   7.171 -#define RX_BUF_PAD	16
   7.172 -#define RX_BUF_WRAP_PAD 2048 /* spare padding to handle lack of packet wrap */
   7.173 -#define RX_BUF_TOT_LEN	(RX_BUF_LEN + RX_BUF_PAD + RX_BUF_WRAP_PAD)
   7.174 -
   7.175 -/* Number of Tx descriptor registers. */
   7.176 -#define NUM_TX_DESC	4
   7.177 -
   7.178 -/* max supported ethernet frame size -- must be at least (dev->mtu+14+4).*/
   7.179 -#define MAX_ETH_FRAME_SIZE	1536
   7.180 -
   7.181 -/* Size of the Tx bounce buffers -- must be at least (dev->mtu+14+4). */
   7.182 -#define TX_BUF_SIZE	MAX_ETH_FRAME_SIZE
   7.183 -#define TX_BUF_TOT_LEN	(TX_BUF_SIZE * NUM_TX_DESC)
   7.184 -
   7.185 -/* PCI Tuning Parameters
   7.186 -   Threshold is bytes transferred to chip before transmission starts. */
   7.187 -#define TX_FIFO_THRESH 256	/* In bytes, rounded down to 32 byte units. */
   7.188 -
   7.189 -/* The following settings are log_2(bytes)-4:  0 == 16 bytes .. 6==1024, 7==end of packet. */
   7.190 -#define RX_FIFO_THRESH	7	/* Rx buffer level before first PCI xfer.  */
   7.191 -#define RX_DMA_BURST	7	/* Maximum PCI burst, '6' is 1024 */
   7.192 -#define TX_DMA_BURST	6	/* Maximum PCI burst, '6' is 1024 */
   7.193 -#define TX_RETRY	8	/* 0-15.  retries = 16 + (TX_RETRY * 16) */
   7.194 -
   7.195 -/* Operational parameters that usually are not changed. */
   7.196 -/* Time in jiffies before concluding the transmitter is hung. */
   7.197 -#define TX_TIMEOUT  (6*HZ)
   7.198 -
   7.199 -
   7.200 -enum {
   7.201 -	HAS_MII_XCVR = 0x010000,
   7.202 -	HAS_CHIP_XCVR = 0x020000,
   7.203 -	HAS_LNK_CHNG = 0x040000,
   7.204 -};
   7.205 -
   7.206 -#define RTL_MIN_IO_SIZE 0x80
   7.207 -#define RTL8139B_IO_SIZE 256
   7.208 -
   7.209 -#define RTL8129_CAPS	HAS_MII_XCVR
   7.210 -#define RTL8139_CAPS	HAS_CHIP_XCVR|HAS_LNK_CHNG
   7.211 -
   7.212 -typedef enum {
   7.213 -	RTL8139 = 0,
   7.214 -	RTL8139_CB,
   7.215 -	SMC1211TX,
   7.216 -	/*MPX5030,*/
   7.217 -	DELTA8139,
   7.218 -	ADDTRON8139,
   7.219 -	DFE538TX,
   7.220 -	DFE690TXD,
   7.221 -	RTL8129,
   7.222 -} board_t;
   7.223 -
   7.224 -
   7.225 -/* indexed by board_t, above */
   7.226 -static struct {
   7.227 -	const char *name;
   7.228 -	u32 hw_flags;
   7.229 -} board_info[] __devinitdata = {
   7.230 -	{ "RealTek RTL8139 Fast Ethernet", RTL8139_CAPS },
   7.231 -	{ "RealTek RTL8139B PCI/CardBus", RTL8139_CAPS },
   7.232 -	{ "SMC1211TX EZCard 10/100 (RealTek RTL8139)", RTL8139_CAPS },
   7.233 -/*	{ MPX5030, "Accton MPX5030 (RealTek RTL8139)", RTL8139_CAPS },*/
   7.234 -	{ "Delta Electronics 8139 10/100BaseTX", RTL8139_CAPS },
   7.235 -	{ "Addtron Technolgy 8139 10/100BaseTX", RTL8139_CAPS },
   7.236 -	{ "D-Link DFE-538TX (RealTek RTL8139)", RTL8139_CAPS },
   7.237 -	{ "D-Link DFE-690TXD (RealTek RTL8139)", RTL8139_CAPS },
   7.238 -	{ "RealTek RTL8129", RTL8129_CAPS },
   7.239 -};
   7.240 -
   7.241 -
   7.242 -static struct pci_device_id rtl8139_pci_tbl[] __devinitdata = {
   7.243 -	{0x10ec, 0x8139, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 },
   7.244 -	{0x10ec, 0x8138, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139_CB },
   7.245 -	{0x1113, 0x1211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SMC1211TX },
   7.246 -/*	{0x1113, 0x1211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MPX5030 },*/
   7.247 -	{0x1500, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DELTA8139 },
   7.248 -	{0x4033, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ADDTRON8139 },
   7.249 -	{0x1186, 0x1300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DFE538TX },
   7.250 -	{0x1186, 0x1340, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DFE690TXD },
   7.251 -
   7.252 -#ifdef CONFIG_8139TOO_8129
   7.253 -	{0x10ec, 0x8129, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8129 },
   7.254 -#endif
   7.255 -
   7.256 -	/* some crazy cards report invalid vendor ids like
   7.257 -	 * 0x0001 here.  The other ids are valid and constant,
   7.258 -	 * so we simply don't match on the main vendor id.
   7.259 -	 */
   7.260 -	{PCI_ANY_ID, 0x8139, 0x10ec, 0x8139, 0, 0, RTL8139 },
   7.261 -	{PCI_ANY_ID, 0x8139, 0x1186, 0x1300, 0, 0, DFE538TX },
   7.262 -
   7.263 -	{0,}
   7.264 -};
   7.265 -MODULE_DEVICE_TABLE (pci, rtl8139_pci_tbl);
   7.266 -
   7.267 -
   7.268 -/* The rest of these values should never change. */
   7.269 -
   7.270 -/* Symbolic offsets to registers. */
   7.271 -enum RTL8139_registers {
   7.272 -	MAC0 = 0,		/* Ethernet hardware address. */
   7.273 -	MAR0 = 8,		/* Multicast filter. */
   7.274 -	TxStatus0 = 0x10,	/* Transmit status (Four 32bit registers). */
   7.275 -	TxAddr0 = 0x20,		/* Tx descriptors (also four 32bit). */
   7.276 -	RxBuf = 0x30,
   7.277 -	ChipCmd = 0x37,
   7.278 -	RxBufPtr = 0x38,
   7.279 -	RxBufAddr = 0x3A,
   7.280 -	IntrMask = 0x3C,
   7.281 -	IntrStatus = 0x3E,
   7.282 -	TxConfig = 0x40,
   7.283 -	ChipVersion = 0x43,
   7.284 -	RxConfig = 0x44,
   7.285 -	Timer = 0x48,		/* A general-purpose counter. */
   7.286 -	RxMissed = 0x4C,	/* 24 bits valid, write clears. */
   7.287 -	Cfg9346 = 0x50,
   7.288 -	Config0 = 0x51,
   7.289 -	Config1 = 0x52,
   7.290 -	FlashReg = 0x54,
   7.291 -	MediaStatus = 0x58,
   7.292 -	Config3 = 0x59,
   7.293 -	Config4 = 0x5A,		/* absent on RTL-8139A */
   7.294 -	HltClk = 0x5B,
   7.295 -	MultiIntr = 0x5C,
   7.296 -	TxSummary = 0x60,
   7.297 -	BasicModeCtrl = 0x62,
   7.298 -	BasicModeStatus = 0x64,
   7.299 -	NWayAdvert = 0x66,
   7.300 -	NWayLPAR = 0x68,
   7.301 -	NWayExpansion = 0x6A,
   7.302 -	/* Undocumented registers, but required for proper operation. */
   7.303 -	FIFOTMS = 0x70,		/* FIFO Control and test. */
   7.304 -	CSCR = 0x74,		/* Chip Status and Configuration Register. */
   7.305 -	PARA78 = 0x78,
   7.306 -	PARA7c = 0x7c,		/* Magic transceiver parameter register. */
   7.307 -	Config5 = 0xD8,		/* absent on RTL-8139A */
   7.308 -};
   7.309 -
   7.310 -enum ClearBitMasks {
   7.311 -	MultiIntrClear = 0xF000,
   7.312 -	ChipCmdClear = 0xE2,
   7.313 -	Config1Clear = (1<<7)|(1<<6)|(1<<3)|(1<<2)|(1<<1),
   7.314 -};
   7.315 -
   7.316 -enum ChipCmdBits {
   7.317 -	CmdReset = 0x10,
   7.318 -	CmdRxEnb = 0x08,
   7.319 -	CmdTxEnb = 0x04,
   7.320 -	RxBufEmpty = 0x01,
   7.321 -};
   7.322 -
   7.323 -/* Interrupt register bits, using my own meaningful names. */
   7.324 -enum IntrStatusBits {
   7.325 -	PCIErr = 0x8000,
   7.326 -	PCSTimeout = 0x4000,
   7.327 -	RxFIFOOver = 0x40,
   7.328 -	RxUnderrun = 0x20,
   7.329 -	RxOverflow = 0x10,
   7.330 -	TxErr = 0x08,
   7.331 -	TxOK = 0x04,
   7.332 -	RxErr = 0x02,
   7.333 -	RxOK = 0x01,
   7.334 -
   7.335 -	RxAckBits = RxFIFOOver | RxOverflow | RxOK,
   7.336 -};
   7.337 -
   7.338 -enum TxStatusBits {
   7.339 -	TxHostOwns = 0x2000,
   7.340 -	TxUnderrun = 0x4000,
   7.341 -	TxStatOK = 0x8000,
   7.342 -	TxOutOfWindow = 0x20000000,
   7.343 -	TxAborted = 0x40000000,
   7.344 -	TxCarrierLost = 0x80000000,
   7.345 -};
   7.346 -enum RxStatusBits {
   7.347 -	RxMulticast = 0x8000,
   7.348 -	RxPhysical = 0x4000,
   7.349 -	RxBroadcast = 0x2000,
   7.350 -	RxBadSymbol = 0x0020,
   7.351 -	RxRunt = 0x0010,
   7.352 -	RxTooLong = 0x0008,
   7.353 -	RxCRCErr = 0x0004,
   7.354 -	RxBadAlign = 0x0002,
   7.355 -	RxStatusOK = 0x0001,
   7.356 -};
   7.357 -
   7.358 -/* Bits in RxConfig. */
   7.359 -enum rx_mode_bits {
   7.360 -	AcceptErr = 0x20,
   7.361 -	AcceptRunt = 0x10,
   7.362 -	AcceptBroadcast = 0x08,
   7.363 -	AcceptMulticast = 0x04,
   7.364 -	AcceptMyPhys = 0x02,
   7.365 -	AcceptAllPhys = 0x01,
   7.366 -};
   7.367 -
   7.368 -/* Bits in TxConfig. */
   7.369 -enum tx_config_bits {
   7.370 -	TxIFG1 = (1 << 25),	/* Interframe Gap Time */
   7.371 -	TxIFG0 = (1 << 24),	/* Enabling these bits violates IEEE 802.3 */
   7.372 -	TxLoopBack = (1 << 18) | (1 << 17), /* enable loopback test mode */
   7.373 -	TxCRC = (1 << 16),	/* DISABLE appending CRC to end of Tx packets */
   7.374 -	TxClearAbt = (1 << 0),	/* Clear abort (WO) */
   7.375 -	TxDMAShift = 8,		/* DMA burst value (0-7) is shifted this many bits */
   7.376 -	TxRetryShift = 4,	/* TXRR value (0-15) is shifted this many bits */
   7.377 -
   7.378 -	TxVersionMask = 0x7C800000, /* mask out version bits 30-26, 23 */
   7.379 -};
   7.380 -
   7.381 -/* Bits in Config1 */
   7.382 -enum Config1Bits {
   7.383 -	Cfg1_PM_Enable = 0x01,
   7.384 -	Cfg1_VPD_Enable = 0x02,
   7.385 -	Cfg1_PIO = 0x04,
   7.386 -	Cfg1_MMIO = 0x08,
   7.387 -	LWAKE = 0x10,		/* not on 8139, 8139A */
   7.388 -	Cfg1_Driver_Load = 0x20,
   7.389 -	Cfg1_LED0 = 0x40,
   7.390 -	Cfg1_LED1 = 0x80,
   7.391 -	SLEEP = (1 << 1),	/* only on 8139, 8139A */
   7.392 -	PWRDN = (1 << 0),	/* only on 8139, 8139A */
   7.393 -};
   7.394 -
   7.395 -/* Bits in Config3 */
   7.396 -enum Config3Bits {
   7.397 -	Cfg3_FBtBEn    = (1 << 0), /* 1 = Fast Back to Back */
   7.398 -	Cfg3_FuncRegEn = (1 << 1), /* 1 = enable CardBus Function registers */
   7.399 -	Cfg3_CLKRUN_En = (1 << 2), /* 1 = enable CLKRUN */
   7.400 -	Cfg3_CardB_En  = (1 << 3), /* 1 = enable CardBus registers */
   7.401 -	Cfg3_LinkUp    = (1 << 4), /* 1 = wake up on link up */
   7.402 -	Cfg3_Magic     = (1 << 5), /* 1 = wake up on Magic Packet (tm) */
   7.403 -	Cfg3_PARM_En   = (1 << 6), /* 0 = software can set twister parameters */
   7.404 -	Cfg3_GNTSel    = (1 << 7), /* 1 = delay 1 clock from PCI GNT signal */
   7.405 -};
   7.406 -
   7.407 -/* Bits in Config4 */
   7.408 -enum Config4Bits {
   7.409 -	LWPTN = (1 << 2),	/* not on 8139, 8139A */
   7.410 -};
   7.411 -
   7.412 -/* Bits in Config5 */
   7.413 -enum Config5Bits {
   7.414 -	Cfg5_PME_STS     = (1 << 0), /* 1 = PCI reset resets PME_Status */
   7.415 -	Cfg5_LANWake     = (1 << 1), /* 1 = enable LANWake signal */
   7.416 -	Cfg5_LDPS        = (1 << 2), /* 0 = save power when link is down */
   7.417 -	Cfg5_FIFOAddrPtr = (1 << 3), /* Realtek internal SRAM testing */
   7.418 -	Cfg5_UWF         = (1 << 4), /* 1 = accept unicast wakeup frame */
   7.419 -	Cfg5_MWF         = (1 << 5), /* 1 = accept multicast wakeup frame */
   7.420 -	Cfg5_BWF         = (1 << 6), /* 1 = accept broadcast wakeup frame */
   7.421 -};
   7.422 -
   7.423 -enum RxConfigBits {
   7.424 -	/* rx fifo threshold */
   7.425 -	RxCfgFIFOShift = 13,
   7.426 -	RxCfgFIFONone = (7 << RxCfgFIFOShift),
   7.427 -
   7.428 -	/* Max DMA burst */
   7.429 -	RxCfgDMAShift = 8,
   7.430 -	RxCfgDMAUnlimited = (7 << RxCfgDMAShift),
   7.431 -
   7.432 -	/* rx ring buffer length */
   7.433 -	RxCfgRcv8K = 0,
   7.434 -	RxCfgRcv16K = (1 << 11),
   7.435 -	RxCfgRcv32K = (1 << 12),
   7.436 -	RxCfgRcv64K = (1 << 11) | (1 << 12),
   7.437 -
   7.438 -	/* Disable packet wrap at end of Rx buffer */
   7.439 -	RxNoWrap = (1 << 7),
   7.440 -};
   7.441 -
   7.442 -
   7.443 -/* Twister tuning parameters from RealTek.
   7.444 -   Completely undocumented, but required to tune bad links. */
   7.445 -enum CSCRBits {
   7.446 -	CSCR_LinkOKBit = 0x0400,
   7.447 -	CSCR_LinkChangeBit = 0x0800,
   7.448 -	CSCR_LinkStatusBits = 0x0f000,
   7.449 -	CSCR_LinkDownOffCmd = 0x003c0,
   7.450 -	CSCR_LinkDownCmd = 0x0f3c0,
   7.451 -};
   7.452 -
   7.453 -
   7.454 -enum Cfg9346Bits {
   7.455 -	Cfg9346_Lock = 0x00,
   7.456 -	Cfg9346_Unlock = 0xC0,
   7.457 -};
   7.458 -
   7.459 -
   7.460 -#define PARA78_default	0x78fa8388
   7.461 -#define PARA7c_default	0xcb38de43	/* param[0][3] */
   7.462 -#define PARA7c_xxx		0xcb38de43
   7.463 -static const unsigned long param[4][4] = {
   7.464 -	{0xcb39de43, 0xcb39ce43, 0xfb38de03, 0xcb38de43},
   7.465 -	{0xcb39de43, 0xcb39ce43, 0xcb39ce83, 0xcb39ce83},
   7.466 -	{0xcb39de43, 0xcb39ce43, 0xcb39ce83, 0xcb39ce83},
   7.467 -	{0xbb39de43, 0xbb39ce43, 0xbb39ce83, 0xbb39ce83}
   7.468 -};
   7.469 -
   7.470 -typedef enum {
   7.471 -	CH_8139 = 0,
   7.472 -	CH_8139_K,
   7.473 -	CH_8139A,
   7.474 -	CH_8139B,
   7.475 -	CH_8130,
   7.476 -	CH_8139C,
   7.477 -} chip_t;
   7.478 -
   7.479 -enum chip_flags {
   7.480 -	HasHltClk = (1 << 0),
   7.481 -	HasLWake = (1 << 1),
   7.482 -};
   7.483 -
   7.484 -
   7.485 -/* directly indexed by chip_t, above */
   7.486 -const static struct {
   7.487 -	const char *name;
   7.488 -	u8 version; /* from RTL8139C docs */
   7.489 -	u32 RxConfigMask; /* should clear the bits supported by this chip */
   7.490 -	u32 flags;
   7.491 -} rtl_chip_info[] = {
   7.492 -	{ "RTL-8139",
   7.493 -	  0x40,
   7.494 -	  0xf0fe0040, /* XXX copied from RTL8139A, verify */
   7.495 -	  HasHltClk,
   7.496 -	},
   7.497 -
   7.498 -	{ "RTL-8139 rev K",
   7.499 -	  0x60,
   7.500 -	  0xf0fe0040,
   7.501 -	  HasHltClk,
   7.502 -	},
   7.503 -
   7.504 -	{ "RTL-8139A",
   7.505 -	  0x70,
   7.506 -	  0xf0fe0040,
   7.507 -	  HasHltClk, /* XXX undocumented? */
   7.508 -	},
   7.509 -
   7.510 -	{ "RTL-8139B",
   7.511 -	  0x78,
   7.512 -	  0xf0fc0040,
   7.513 -	  HasLWake,
   7.514 -	},
   7.515 -
   7.516 -	{ "RTL-8130",
   7.517 -	  0x7C,
   7.518 -	  0xf0fe0040, /* XXX copied from RTL8139A, verify */
   7.519 -	  HasLWake,
   7.520 -	},
   7.521 -
   7.522 -	{ "RTL-8139C",
   7.523 -	  0x74,
   7.524 -	  0xf0fc0040, /* XXX copied from RTL8139B, verify */
   7.525 -	  HasLWake,
   7.526 -	},
   7.527 -
   7.528 -};
   7.529 -
   7.530 -struct rtl_extra_stats {
   7.531 -	unsigned long early_rx;
   7.532 -	unsigned long tx_buf_mapped;
   7.533 -	unsigned long tx_timeouts;
   7.534 -};
   7.535 -
   7.536 -struct rtl8139_private {
   7.537 -	void *mmio_addr;
   7.538 -	int drv_flags;
   7.539 -	struct pci_dev *pci_dev;
   7.540 -	struct net_device_stats stats;
   7.541 -	unsigned char *rx_ring;
   7.542 -	unsigned int cur_rx;	/* Index into the Rx buffer of next Rx pkt. */
   7.543 -	unsigned int tx_flag;
   7.544 -	unsigned long cur_tx;
   7.545 -	unsigned long dirty_tx;
   7.546 -	unsigned char *tx_buf[NUM_TX_DESC];	/* Tx bounce buffers */
   7.547 -	unsigned char *tx_bufs;	/* Tx bounce buffer region. */
   7.548 -	dma_addr_t rx_ring_dma;
   7.549 -	dma_addr_t tx_bufs_dma;
   7.550 -	signed char phys[4];		/* MII device addresses. */
   7.551 -	char twistie, twist_row, twist_col;	/* Twister tune state. */
   7.552 -	unsigned int full_duplex:1;	/* Full-duplex operation requested. */
   7.553 -	unsigned int duplex_lock:1;
   7.554 -	unsigned int default_port:4;	/* Last dev->if_port value. */
   7.555 -	unsigned int media2:4;	/* Secondary monitored media port. */
   7.556 -	unsigned int medialock:1;	/* Don't sense media type. */
   7.557 -	unsigned int mediasense:1;	/* Media sensing in progress. */
   7.558 -	spinlock_t lock;
   7.559 -	chip_t chipset;
   7.560 -	u32 rx_config;
   7.561 -	struct rtl_extra_stats xstats;
   7.562 -	int time_to_die;
   7.563 -};
   7.564 -
   7.565 -MODULE_AUTHOR ("Jeff Garzik <jgarzik@mandrakesoft.com>");
   7.566 -MODULE_DESCRIPTION ("RealTek RTL-8139 Fast Ethernet driver");
   7.567 -MODULE_LICENSE("GPL");
   7.568 -
   7.569 -MODULE_PARM (multicast_filter_limit, "i");
   7.570 -MODULE_PARM (max_interrupt_work, "i");
   7.571 -MODULE_PARM (media, "1-" __MODULE_STRING(MAX_UNITS) "i");
   7.572 -MODULE_PARM (full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
   7.573 -MODULE_PARM_DESC (multicast_filter_limit, "8139too maximum number of filtered multicast addresses");
   7.574 -MODULE_PARM_DESC (max_interrupt_work, "8139too maximum events handled per interrupt");
   7.575 -MODULE_PARM_DESC (media, "8139too: Bits 4+9: force full duplex, bit 5: 100Mbps");
   7.576 -MODULE_PARM_DESC (full_duplex, "8139too: Force full duplex for board(s) (1)");
   7.577 -
   7.578 -static int read_eeprom (void *ioaddr, int location, int addr_len);
   7.579 -static int rtl8139_open (struct net_device *dev);
   7.580 -static int mdio_read (struct net_device *dev, int phy_id, int location);
   7.581 -static void mdio_write (struct net_device *dev, int phy_id, int location,
   7.582 -			int val);
   7.583 -static void rtl8139_tx_timeout (struct net_device *dev);
   7.584 -static void rtl8139_init_ring (struct net_device *dev);
   7.585 -static int rtl8139_start_xmit (struct sk_buff *skb,
   7.586 -			       struct net_device *dev);
   7.587 -static void rtl8139_interrupt (int irq, void *dev_instance,
   7.588 -			       struct pt_regs *regs);
   7.589 -static int rtl8139_close (struct net_device *dev);
   7.590 -static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd);
   7.591 -static struct net_device_stats *rtl8139_get_stats (struct net_device *dev);
   7.592 -static inline u32 ether_crc (int length, unsigned char *data);
   7.593 -static void rtl8139_set_rx_mode (struct net_device *dev);
   7.594 -static void __set_rx_mode (struct net_device *dev);
   7.595 -static void rtl8139_hw_start (struct net_device *dev);
   7.596 -
   7.597 -#ifdef USE_IO_OPS
   7.598 -
   7.599 -#define RTL_R8(reg)		inb (((unsigned long)ioaddr) + (reg))
   7.600 -#define RTL_R16(reg)		inw (((unsigned long)ioaddr) + (reg))
   7.601 -#define RTL_R32(reg)		((unsigned long) inl (((unsigned long)ioaddr) + (reg)))
   7.602 -#define RTL_W8(reg, val8)	outb ((val8), ((unsigned long)ioaddr) + (reg))
   7.603 -#define RTL_W16(reg, val16)	outw ((val16), ((unsigned long)ioaddr) + (reg))
   7.604 -#define RTL_W32(reg, val32)	outl ((val32), ((unsigned long)ioaddr) + (reg))
   7.605 -#define RTL_W8_F		RTL_W8
   7.606 -#define RTL_W16_F		RTL_W16
   7.607 -#define RTL_W32_F		RTL_W32
   7.608 -#undef readb
   7.609 -#undef readw
   7.610 -#undef readl
   7.611 -#undef writeb
   7.612 -#undef writew
   7.613 -#undef writel
   7.614 -#define readb(addr) inb((unsigned long)(addr))
   7.615 -#define readw(addr) inw((unsigned long)(addr))
   7.616 -#define readl(addr) inl((unsigned long)(addr))
   7.617 -#define writeb(val,addr) outb((val),(unsigned long)(addr))
   7.618 -#define writew(val,addr) outw((val),(unsigned long)(addr))
   7.619 -#define writel(val,addr) outl((val),(unsigned long)(addr))
   7.620 -
   7.621 -#else
   7.622 -
   7.623 -/* write MMIO register, with flush */
   7.624 -/* Flush avoids rtl8139 bug w/ posted MMIO writes */
   7.625 -#define RTL_W8_F(reg, val8)	do { writeb ((val8), ioaddr + (reg)); readb (ioaddr + (reg)); } while (0)
   7.626 -#define RTL_W16_F(reg, val16)	do { writew ((val16), ioaddr + (reg)); readw (ioaddr + (reg)); } while (0)
   7.627 -#define RTL_W32_F(reg, val32)	do { writel ((val32), ioaddr + (reg)); readl (ioaddr + (reg)); } while (0)
   7.628 -
   7.629 -
   7.630 -#define MMIO_FLUSH_AUDIT_COMPLETE 1
   7.631 -#if MMIO_FLUSH_AUDIT_COMPLETE
   7.632 -
   7.633 -/* write MMIO register */
   7.634 -#define RTL_W8(reg, val8)	writeb ((val8), ioaddr + (reg))
   7.635 -#define RTL_W16(reg, val16)	writew ((val16), ioaddr + (reg))
   7.636 -#define RTL_W32(reg, val32)	writel ((val32), ioaddr + (reg))
   7.637 -
   7.638 -#else
   7.639 -
   7.640 -/* write MMIO register, then flush */
   7.641 -#define RTL_W8		RTL_W8_F
   7.642 -#define RTL_W16		RTL_W16_F
   7.643 -#define RTL_W32		RTL_W32_F
   7.644 -
   7.645 -#endif /* MMIO_FLUSH_AUDIT_COMPLETE */
   7.646 -
   7.647 -/* read MMIO register */
   7.648 -#define RTL_R8(reg)		readb (ioaddr + (reg))
   7.649 -#define RTL_R16(reg)		readw (ioaddr + (reg))
   7.650 -#define RTL_R32(reg)		((unsigned long) readl (ioaddr + (reg)))
   7.651 -
   7.652 -#endif /* USE_IO_OPS */
   7.653 -
   7.654 -
   7.655 -static const u16 rtl8139_intr_mask =
   7.656 -	PCIErr | PCSTimeout | RxUnderrun | RxOverflow | RxFIFOOver |
   7.657 -	TxErr | TxOK | RxErr | RxOK;
   7.658 -
   7.659 -static const unsigned int rtl8139_rx_config =
   7.660 -	RxCfgRcv32K | RxNoWrap |
   7.661 -	(RX_FIFO_THRESH << RxCfgFIFOShift) |
   7.662 -	(RX_DMA_BURST << RxCfgDMAShift);
   7.663 -
   7.664 -static const unsigned int rtl8139_tx_config =
   7.665 -	(TX_DMA_BURST << TxDMAShift) | (TX_RETRY << TxRetryShift);
   7.666 -
   7.667 -static void __rtl8139_cleanup_dev (struct net_device *dev)
   7.668 -{
   7.669 -	struct rtl8139_private *tp;
   7.670 -	struct pci_dev *pdev;
   7.671 -
   7.672 -	assert (dev != NULL);
   7.673 -	assert (dev->priv != NULL);
   7.674 -
   7.675 -	tp = dev->priv;
   7.676 -	assert (tp->pci_dev != NULL);
   7.677 -	pdev = tp->pci_dev;
   7.678 -
   7.679 -#ifndef USE_IO_OPS
   7.680 -	if (tp->mmio_addr)
   7.681 -		iounmap (tp->mmio_addr);
   7.682 -#endif /* !USE_IO_OPS */
   7.683 -
   7.684 -	/* it's ok to call this even if we have no regions to free */
   7.685 -	pci_release_regions (pdev);
   7.686 -
   7.687 -#ifndef RTL8139_NDEBUG
   7.688 -	/* poison memory before freeing */
   7.689 -	memset (dev, 0xBC,
   7.690 -		sizeof (struct net_device) +
   7.691 -		sizeof (struct rtl8139_private));
   7.692 -#endif /* RTL8139_NDEBUG */
   7.693 -
   7.694 -	kfree (dev);
   7.695 -
   7.696 -	pci_set_drvdata (pdev, NULL);
   7.697 -}
   7.698 -
   7.699 -
   7.700 -static void rtl8139_chip_reset (void *ioaddr)
   7.701 -{
   7.702 -	int i;
   7.703 -
   7.704 -	/* Soft reset the chip. */
   7.705 -	RTL_W8 (ChipCmd, CmdReset);
   7.706 -
   7.707 -	/* Check that the chip has finished the reset. */
   7.708 -	for (i = 1000; i > 0; i--) {
   7.709 -		barrier();
   7.710 -		if ((RTL_R8 (ChipCmd) & CmdReset) == 0)
   7.711 -			break;
   7.712 -		udelay (10);
   7.713 -	}
   7.714 -}
   7.715 -
   7.716 -
   7.717 -static int __devinit rtl8139_init_board (struct pci_dev *pdev,
   7.718 -					 struct net_device **dev_out)
   7.719 -{
   7.720 -	void *ioaddr;
   7.721 -	struct net_device *dev;
   7.722 -	struct rtl8139_private *tp;
   7.723 -	u8 tmp8;
   7.724 -	int rc;
   7.725 -	unsigned int i;
   7.726 -	u32 pio_start, pio_end, pio_flags, pio_len;
   7.727 -	unsigned long mmio_start, mmio_end, mmio_flags, mmio_len;
   7.728 -	u32 tmp;
   7.729 -
   7.730 -	assert (pdev != NULL);
   7.731 -
   7.732 -	*dev_out = NULL;
   7.733 -
   7.734 -	/* dev and dev->priv zeroed in alloc_etherdev */
   7.735 -	dev = alloc_etherdev (sizeof (*tp));
   7.736 -	if (dev == NULL) {
   7.737 -		printk (KERN_ERR PFX "%s: Unable to alloc new net device\n", pdev->slot_name);
   7.738 -		return -ENOMEM;
   7.739 -	}
   7.740 -	SET_MODULE_OWNER(dev);
   7.741 -	tp = dev->priv;
   7.742 -	tp->pci_dev = pdev;
   7.743 -
   7.744 -	/* enable device (incl. PCI PM wakeup and hotplug setup) */
   7.745 -	rc = pci_enable_device (pdev);
   7.746 -	if (rc)
   7.747 -		goto err_out;
   7.748 -
   7.749 -	pio_start = pci_resource_start (pdev, 0);
   7.750 -	pio_end = pci_resource_end (pdev, 0);
   7.751 -	pio_flags = pci_resource_flags (pdev, 0);
   7.752 -	pio_len = pci_resource_len (pdev, 0);
   7.753 -
   7.754 -	mmio_start = pci_resource_start (pdev, 1);
   7.755 -	mmio_end = pci_resource_end (pdev, 1);
   7.756 -	mmio_flags = pci_resource_flags (pdev, 1);
   7.757 -	mmio_len = pci_resource_len (pdev, 1);
   7.758 -
   7.759 -	/* set this immediately, we need to know before
   7.760 -	 * we talk to the chip directly */
   7.761 -	DPRINTK("PIO region size == 0x%02X\n", pio_len);
   7.762 -	DPRINTK("MMIO region size == 0x%02lX\n", mmio_len);
   7.763 -
   7.764 -#ifdef USE_IO_OPS
   7.765 -	/* make sure PCI base addr 0 is PIO */
   7.766 -	if (!(pio_flags & IORESOURCE_IO)) {
   7.767 -		printk (KERN_ERR PFX "%s: region #0 not a PIO resource, aborting\n", pdev->slot_name);
   7.768 -		rc = -ENODEV;
   7.769 -		goto err_out;
   7.770 -	}
   7.771 -	/* check for weird/broken PCI region reporting */
   7.772 -	if (pio_len < RTL_MIN_IO_SIZE) {
   7.773 -		printk (KERN_ERR PFX "%s: Invalid PCI I/O region size(s), aborting\n", pdev->slot_name);
   7.774 -		rc = -ENODEV;
   7.775 -		goto err_out;
   7.776 -	}
   7.777 -#else
   7.778 -	/* make sure PCI base addr 1 is MMIO */
   7.779 -	if (!(mmio_flags & IORESOURCE_MEM)) {
   7.780 -		printk (KERN_ERR PFX "%s: region #1 not an MMIO resource, aborting\n", pdev->slot_name);
   7.781 -		rc = -ENODEV;
   7.782 -		goto err_out;
   7.783 -	}
   7.784 -	if (mmio_len < RTL_MIN_IO_SIZE) {
   7.785 -		printk (KERN_ERR PFX "%s: Invalid PCI mem region size(s), aborting\n", pdev->slot_name);
   7.786 -		rc = -ENODEV;
   7.787 -		goto err_out;
   7.788 -	}
   7.789 -#endif
   7.790 -
   7.791 -	rc = pci_request_regions (pdev, "8139too");
   7.792 -	if (rc)
   7.793 -		goto err_out;
   7.794 -
   7.795 -	/* enable PCI bus-mastering */
   7.796 -	pci_set_master (pdev);
   7.797 -
   7.798 -#ifdef USE_IO_OPS
   7.799 -	ioaddr = (void *) pio_start;
   7.800 -	dev->base_addr = pio_start;
   7.801 -	tp->mmio_addr = ioaddr;
   7.802 -#else
   7.803 -	/* ioremap MMIO region */
   7.804 -	ioaddr = ioremap (mmio_start, mmio_len);
   7.805 -	if (ioaddr == NULL) {
   7.806 -		printk (KERN_ERR PFX "%s: cannot remap MMIO, aborting\n", pdev->slot_name);
   7.807 -		rc = -EIO;
   7.808 -		goto err_out;
   7.809 -	}
   7.810 -	dev->base_addr = (long) ioaddr;
   7.811 -	tp->mmio_addr = ioaddr;
   7.812 -#endif /* USE_IO_OPS */
   7.813 -
   7.814 -	/* Bring old chips out of low-power mode. */
   7.815 -	RTL_W8 (HltClk, 'R');
   7.816 -
   7.817 -	/* check for missing/broken hardware */
   7.818 -	if (RTL_R32 (TxConfig) == 0xFFFFFFFF) {
   7.819 -		printk (KERN_ERR PFX "%s: Chip not responding, ignoring board\n",
   7.820 -			pdev->slot_name);
   7.821 -		rc = -EIO;
   7.822 -		goto err_out;
   7.823 -	}
   7.824 -
   7.825 -	/* identify chip attached to board */
   7.826 -	tmp = RTL_R8 (ChipVersion);
   7.827 -	for (i = 0; i < ARRAY_SIZE (rtl_chip_info); i++)
   7.828 -		if (tmp == rtl_chip_info[i].version) {
   7.829 -			tp->chipset = i;
   7.830 -			goto match;
   7.831 -		}
   7.832 -
   7.833 -	/* if unknown chip, assume array element #0, original RTL-8139 in this case */
   7.834 -	printk (KERN_DEBUG PFX "%s: unknown chip version, assuming RTL-8139\n",
   7.835 -		pdev->slot_name);
   7.836 -	printk (KERN_DEBUG PFX "%s: TxConfig = 0x%lx\n", pdev->slot_name, RTL_R32 (TxConfig));
   7.837 -	tp->chipset = 0;
   7.838 -
   7.839 -match:
   7.840 -	DPRINTK ("chipset id (%d) == index %d, '%s'\n",
   7.841 -		tmp,
   7.842 -		tp->chipset,
   7.843 -		rtl_chip_info[tp->chipset].name);
   7.844 -
   7.845 -	if (tp->chipset >= CH_8139B) {
   7.846 -		u8 new_tmp8 = tmp8 = RTL_R8 (Config1);
   7.847 -		DPRINTK("PCI PM wakeup\n");
   7.848 -		if ((rtl_chip_info[tp->chipset].flags & HasLWake) &&
   7.849 -		    (tmp8 & LWAKE))
   7.850 -			new_tmp8 &= ~LWAKE;
   7.851 -		new_tmp8 |= Cfg1_PM_Enable;
   7.852 -		if (new_tmp8 != tmp8) {
   7.853 -			RTL_W8 (Cfg9346, Cfg9346_Unlock);
   7.854 -			RTL_W8 (Config1, tmp8);
   7.855 -			RTL_W8 (Cfg9346, Cfg9346_Lock);
   7.856 -		}
   7.857 -		if (rtl_chip_info[tp->chipset].flags & HasLWake) {
   7.858 -			tmp8 = RTL_R8 (Config4);
   7.859 -			if (tmp8 & LWPTN)
   7.860 -				RTL_W8 (Config4, tmp8 & ~LWPTN);
   7.861 -		}
   7.862 -	} else {
   7.863 -		DPRINTK("Old chip wakeup\n");
   7.864 -		tmp8 = RTL_R8 (Config1);
   7.865 -		tmp8 &= ~(SLEEP | PWRDN);
   7.866 -		RTL_W8 (Config1, tmp8);
   7.867 -	}
   7.868 -
   7.869 -	rtl8139_chip_reset (ioaddr);
   7.870 -
   7.871 -	*dev_out = dev;
   7.872 -	return 0;
   7.873 -
   7.874 -err_out:
   7.875 -	__rtl8139_cleanup_dev (dev);
   7.876 -	return rc;
   7.877 -}
   7.878 -
   7.879 -
   7.880 -static int __devinit rtl8139_init_one (struct pci_dev *pdev,
   7.881 -				       const struct pci_device_id *ent)
   7.882 -{
   7.883 -	struct net_device *dev = NULL;
   7.884 -	struct rtl8139_private *tp;
   7.885 -	int i, addr_len, option;
   7.886 -	void *ioaddr;
   7.887 -	static int board_idx = -1;
   7.888 -	u8 pci_rev;
   7.889 -
   7.890 -	assert (pdev != NULL);
   7.891 -	assert (ent != NULL);
   7.892 -
   7.893 -	board_idx++;
   7.894 -
   7.895 -	/* when we're built into the kernel, the driver version message
   7.896 -	 * is only printed if at least one 8139 board has been found
   7.897 -	 */
   7.898 -#ifndef MODULE
   7.899 -	{
   7.900 -		static int printed_version;
   7.901 -		if (!printed_version++)
   7.902 -			printk (KERN_INFO RTL8139_DRIVER_NAME "\n");
   7.903 -	}
   7.904 -#endif
   7.905 -
   7.906 -	pci_read_config_byte(pdev, PCI_REVISION_ID, &pci_rev);
   7.907 -
   7.908 -	if (pdev->vendor == PCI_VENDOR_ID_REALTEK &&
   7.909 -	    pdev->device == PCI_DEVICE_ID_REALTEK_8139 && pci_rev >= 0x20) {
   7.910 -		printk(KERN_INFO PFX "pci dev %s (id %04x:%04x rev %02x) is an enhanced 8139C+ chip\n",
   7.911 -		       pdev->slot_name, pdev->vendor, pdev->device, pci_rev);
   7.912 -		printk(KERN_INFO PFX "Ensure the \"8139cp\" driver is installed!\n");
   7.913 -                return -ENODEV; /* force use of better driver */
   7.914 -	}
   7.915 -
   7.916 -	i = rtl8139_init_board (pdev, &dev);
   7.917 -	if (i < 0)
   7.918 -		return i;
   7.919 -
   7.920 -	tp = dev->priv;
   7.921 -	ioaddr = tp->mmio_addr;
   7.922 -
   7.923 -	assert (ioaddr != NULL);
   7.924 -	assert (dev != NULL);
   7.925 -	assert (tp != NULL);
   7.926 -
   7.927 -	addr_len = read_eeprom (ioaddr, 0, 8) == 0x8129 ? 8 : 6;
   7.928 -	for (i = 0; i < 3; i++)
   7.929 -		((u16 *) (dev->dev_addr))[i] =
   7.930 -		    le16_to_cpu (read_eeprom (ioaddr, i + 7, addr_len));
   7.931 -
   7.932 -	/* The Rtl8139-specific entries in the device structure. */
   7.933 -	dev->open = rtl8139_open;
   7.934 -	dev->hard_start_xmit = rtl8139_start_xmit;
   7.935 -	dev->stop = rtl8139_close;
   7.936 -	dev->get_stats = rtl8139_get_stats;
   7.937 -	dev->set_multicast_list = rtl8139_set_rx_mode;
   7.938 -	dev->do_ioctl = netdev_ioctl;
   7.939 -	dev->tx_timeout = rtl8139_tx_timeout;
   7.940 -	dev->watchdog_timeo = TX_TIMEOUT;
   7.941 -	dev->features |= NETIF_F_SG;
   7.942 -
   7.943 -	dev->irq = pdev->irq;
   7.944 -
   7.945 -	/* dev->priv/tp zeroed and aligned in init_etherdev */
   7.946 -	tp = dev->priv;
   7.947 -
   7.948 -	/* note: tp->chipset set in rtl8139_init_board */
   7.949 -	tp->drv_flags = board_info[ent->driver_data].hw_flags;
   7.950 -	tp->mmio_addr = ioaddr;
   7.951 -	spin_lock_init (&tp->lock);
   7.952 -
   7.953 -	/* dev is fully set up and ready to use now */
   7.954 -	DPRINTK("about to register device named %s (%p)...\n", dev->name, dev);
   7.955 -	i = register_netdev (dev);
   7.956 -	if (i) goto err_out;
   7.957 -
   7.958 -	pci_set_drvdata (pdev, dev);
   7.959 -
   7.960 -	printk (KERN_INFO "%s: %s at 0x%lx, "
   7.961 -		"%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, "
   7.962 -		"IRQ %d\n",
   7.963 -		dev->name,
   7.964 -		board_info[ent->driver_data].name,
   7.965 -		dev->base_addr,
   7.966 -		dev->dev_addr[0], dev->dev_addr[1],
   7.967 -		dev->dev_addr[2], dev->dev_addr[3],
   7.968 -		dev->dev_addr[4], dev->dev_addr[5],
   7.969 -		dev->irq);
   7.970 -
   7.971 -	printk (KERN_DEBUG "%s:  Identified 8139 chip type '%s'\n",
   7.972 -		dev->name, rtl_chip_info[tp->chipset].name);
   7.973 -
   7.974 -	/* Find the connected MII xcvrs.
   7.975 -	   Doing this in open() would allow detecting external xcvrs later, but
   7.976 -	   takes too much time. */
   7.977 -#ifdef CONFIG_8139TOO_8129
   7.978 -	if (tp->drv_flags & HAS_MII_XCVR) {
   7.979 -		int phy, phy_idx = 0;
   7.980 -		for (phy = 0; phy < 32 && phy_idx < sizeof(tp->phys); phy++) {
   7.981 -			int mii_status = mdio_read(dev, phy, 1);
   7.982 -			if (mii_status != 0xffff  &&  mii_status != 0x0000) {
   7.983 -				u16 advertising = mdio_read(dev, phy, 4);
   7.984 -				tp->phys[phy_idx++] = phy;
   7.985 -				printk(KERN_INFO "%s: MII transceiver %d status 0x%4.4x "
   7.986 -					   "advertising %4.4x.\n",
   7.987 -					   dev->name, phy, mii_status, advertising);
   7.988 -			}
   7.989 -		}
   7.990 -		if (phy_idx == 0) {
   7.991 -			printk(KERN_INFO "%s: No MII transceivers found!  Assuming SYM "
   7.992 -				   "transceiver.\n",
   7.993 -				   dev->name);
   7.994 -			tp->phys[0] = 32;
   7.995 -		}
   7.996 -	} else
   7.997 -#endif
   7.998 -		tp->phys[0] = 32;
   7.999 -
  7.1000 -	/* The lower four bits are the media type. */
  7.1001 -	option = (board_idx >= MAX_UNITS) ? 0 : media[board_idx];
  7.1002 -	if (option > 0) {
  7.1003 -		tp->full_duplex = (option & 0x210) ? 1 : 0;
  7.1004 -		tp->default_port = option & 0xFF;
  7.1005 -		if (tp->default_port)
  7.1006 -			tp->medialock = 1;
  7.1007 -	}
  7.1008 -	if (board_idx < MAX_UNITS  &&  full_duplex[board_idx] > 0)
  7.1009 -		tp->full_duplex = full_duplex[board_idx];
  7.1010 -	if (tp->full_duplex) {
  7.1011 -		printk(KERN_INFO "%s: Media type forced to Full Duplex.\n", dev->name);
  7.1012 -		/* Changing the MII-advertised media because might prevent
  7.1013 -		   re-connection. */
  7.1014 -		tp->duplex_lock = 1;
  7.1015 -	}
  7.1016 -	if (tp->default_port) {
  7.1017 -		printk(KERN_INFO "  Forcing %dMbps %s-duplex operation.\n",
  7.1018 -			   (option & 0x20 ? 100 : 10),
  7.1019 -			   (option & 0x10 ? "full" : "half"));
  7.1020 -		mdio_write(dev, tp->phys[0], 0,
  7.1021 -				   ((option & 0x20) ? 0x2000 : 0) | 	/* 100Mbps? */
  7.1022 -				   ((option & 0x10) ? 0x0100 : 0)); /* Full duplex? */
  7.1023 -	}
  7.1024 -
  7.1025 -	/* Put the chip into low-power mode. */
  7.1026 -	if (rtl_chip_info[tp->chipset].flags & HasHltClk)
  7.1027 -		RTL_W8 (HltClk, 'H');	/* 'R' would leave the clock running. */
  7.1028 -
  7.1029 -	return 0;
  7.1030 -
  7.1031 -err_out:
  7.1032 -	__rtl8139_cleanup_dev (dev);
  7.1033 -	return i;
  7.1034 -}
  7.1035 -
  7.1036 -
  7.1037 -static void __devexit rtl8139_remove_one (struct pci_dev *pdev)
  7.1038 -{
  7.1039 -	struct net_device *dev = pci_get_drvdata (pdev);
  7.1040 -	struct rtl8139_private *np;
  7.1041 -
  7.1042 -	assert (dev != NULL);
  7.1043 -	np = dev->priv;
  7.1044 -	assert (np != NULL);
  7.1045 -
  7.1046 -	unregister_netdev (dev);
  7.1047 -
  7.1048 -	__rtl8139_cleanup_dev (dev);
  7.1049 -}
  7.1050 -
  7.1051 -
  7.1052 -/* Serial EEPROM section. */
  7.1053 -
  7.1054 -/*  EEPROM_Ctrl bits. */
  7.1055 -#define EE_SHIFT_CLK	0x04	/* EEPROM shift clock. */
  7.1056 -#define EE_CS			0x08	/* EEPROM chip select. */
  7.1057 -#define EE_DATA_WRITE	0x02	/* EEPROM chip data in. */
  7.1058 -#define EE_WRITE_0		0x00
  7.1059 -#define EE_WRITE_1		0x02
  7.1060 -#define EE_DATA_READ	0x01	/* EEPROM chip data out. */
  7.1061 -#define EE_ENB			(0x80 | EE_CS)
  7.1062 -
  7.1063 -/* Delay between EEPROM clock transitions.
  7.1064 -   No extra delay is needed with 33Mhz PCI, but 66Mhz may change this.
  7.1065 - */
  7.1066 -
  7.1067 -#define eeprom_delay()	readl(ee_addr)
  7.1068 -
  7.1069 -/* The EEPROM commands include the alway-set leading bit. */
  7.1070 -#define EE_WRITE_CMD	(5)
  7.1071 -#define EE_READ_CMD		(6)
  7.1072 -#define EE_ERASE_CMD	(7)
  7.1073 -
  7.1074 -static int __devinit read_eeprom (void *ioaddr, int location, int addr_len)
  7.1075 -{
  7.1076 -	int i;
  7.1077 -	unsigned retval = 0;
  7.1078 -	void *ee_addr = ioaddr + Cfg9346;
  7.1079 -	int read_cmd = location | (EE_READ_CMD << addr_len);
  7.1080 -
  7.1081 -	writeb (EE_ENB & ~EE_CS, ee_addr);
  7.1082 -	writeb (EE_ENB, ee_addr);
  7.1083 -	eeprom_delay ();
  7.1084 -
  7.1085 -	/* Shift the read command bits out. */
  7.1086 -	for (i = 4 + addr_len; i >= 0; i--) {
  7.1087 -		int dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
  7.1088 -		writeb (EE_ENB | dataval, ee_addr);
  7.1089 -		eeprom_delay ();
  7.1090 -		writeb (EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
  7.1091 -		eeprom_delay ();
  7.1092 -	}
  7.1093 -	writeb (EE_ENB, ee_addr);
  7.1094 -	eeprom_delay ();
  7.1095 -
  7.1096 -	for (i = 16; i > 0; i--) {
  7.1097 -		writeb (EE_ENB | EE_SHIFT_CLK, ee_addr);
  7.1098 -		eeprom_delay ();
  7.1099 -		retval =
  7.1100 -		    (retval << 1) | ((readb (ee_addr) & EE_DATA_READ) ? 1 :
  7.1101 -				     0);
  7.1102 -		writeb (EE_ENB, ee_addr);
  7.1103 -		eeprom_delay ();
  7.1104 -	}
  7.1105 -
  7.1106 -	/* Terminate the EEPROM access. */
  7.1107 -	writeb (~EE_CS, ee_addr);
  7.1108 -	eeprom_delay ();
  7.1109 -
  7.1110 -	return retval;
  7.1111 -}
  7.1112 -
  7.1113 -/* MII serial management: mostly bogus for now. */
  7.1114 -/* Read and write the MII management registers using software-generated
  7.1115 -   serial MDIO protocol.
  7.1116 -   The maximum data clock rate is 2.5 Mhz.  The minimum timing is usually
  7.1117 -   met by back-to-back PCI I/O cycles, but we insert a delay to avoid
  7.1118 -   "overclocking" issues. */
  7.1119 -#define MDIO_DIR		0x80
  7.1120 -#define MDIO_DATA_OUT	0x04
  7.1121 -#define MDIO_DATA_IN	0x02
  7.1122 -#define MDIO_CLK		0x01
  7.1123 -#define MDIO_WRITE0 (MDIO_DIR)
  7.1124 -#define MDIO_WRITE1 (MDIO_DIR | MDIO_DATA_OUT)
  7.1125 -
  7.1126 -#define mdio_delay(mdio_addr)	readb(mdio_addr)
  7.1127 -
  7.1128 -
  7.1129 -static char mii_2_8139_map[8] = {
  7.1130 -	BasicModeCtrl,
  7.1131 -	BasicModeStatus,
  7.1132 -	0,
  7.1133 -	0,
  7.1134 -	NWayAdvert,
  7.1135 -	NWayLPAR,
  7.1136 -	NWayExpansion,
  7.1137 -	0
  7.1138 -};
  7.1139 -
  7.1140 -
  7.1141 -#ifdef CONFIG_8139TOO_8129
  7.1142 -/* Syncronize the MII management interface by shifting 32 one bits out. */
  7.1143 -static void mdio_sync (void *mdio_addr)
  7.1144 -{
  7.1145 -	int i;
  7.1146 -
  7.1147 -	for (i = 32; i >= 0; i--) {
  7.1148 -		writeb (MDIO_WRITE1, mdio_addr);
  7.1149 -		mdio_delay (mdio_addr);
  7.1150 -		writeb (MDIO_WRITE1 | MDIO_CLK, mdio_addr);
  7.1151 -		mdio_delay (mdio_addr);
  7.1152 -	}
  7.1153 -}
  7.1154 -#endif
  7.1155 -
  7.1156 -static int mdio_read (struct net_device *dev, int phy_id, int location)
  7.1157 -{
  7.1158 -	struct rtl8139_private *tp = dev->priv;
  7.1159 -	int retval = 0;
  7.1160 -#ifdef CONFIG_8139TOO_8129
  7.1161 -	void *mdio_addr = tp->mmio_addr + Config4;
  7.1162 -	int mii_cmd = (0xf6 << 10) | (phy_id << 5) | location;
  7.1163 -	int i;
  7.1164 -#endif
  7.1165 -
  7.1166 -	if (phy_id > 31) {	/* Really a 8139.  Use internal registers. */
  7.1167 -		return location < 8 && mii_2_8139_map[location] ?
  7.1168 -		    readw (tp->mmio_addr + mii_2_8139_map[location]) : 0;
  7.1169 -	}
  7.1170 -
  7.1171 -#ifdef CONFIG_8139TOO_8129
  7.1172 -	mdio_sync (mdio_addr);
  7.1173 -	/* Shift the read command bits out. */
  7.1174 -	for (i = 15; i >= 0; i--) {
  7.1175 -		int dataval = (mii_cmd & (1 << i)) ? MDIO_DATA_OUT : 0;
  7.1176 -
  7.1177 -		writeb (MDIO_DIR | dataval, mdio_addr);
  7.1178 -		mdio_delay (mdio_addr);
  7.1179 -		writeb (MDIO_DIR | dataval | MDIO_CLK, mdio_addr);
  7.1180 -		mdio_delay (mdio_addr);
  7.1181 -	}
  7.1182 -
  7.1183 -	/* Read the two transition, 16 data, and wire-idle bits. */
  7.1184 -	for (i = 19; i > 0; i--) {
  7.1185 -		writeb (0, mdio_addr);
  7.1186 -		mdio_delay (mdio_addr);
  7.1187 -		retval = (retval << 1) | ((readb (mdio_addr) & MDIO_DATA_IN) ? 1 : 0);
  7.1188 -		writeb (MDIO_CLK, mdio_addr);
  7.1189 -		mdio_delay (mdio_addr);
  7.1190 -	}
  7.1191 -#endif
  7.1192 -
  7.1193 -	return (retval >> 1) & 0xffff;
  7.1194 -}
  7.1195 -
  7.1196 -
  7.1197 -static void mdio_write (struct net_device *dev, int phy_id, int location,
  7.1198 -			int value)
  7.1199 -{
  7.1200 -	struct rtl8139_private *tp = dev->priv;
  7.1201 -#ifdef CONFIG_8139TOO_8129
  7.1202 -	void *mdio_addr = tp->mmio_addr + Config4;
  7.1203 -	int mii_cmd = (0x5002 << 16) | (phy_id << 23) | (location << 18) | value;
  7.1204 -	int i;
  7.1205 -#endif
  7.1206 -
  7.1207 -	if (phy_id > 31) {	/* Really a 8139.  Use internal registers. */
  7.1208 -		void *ioaddr = tp->mmio_addr;
  7.1209 -		if (location == 0) {
  7.1210 -			RTL_W8 (Cfg9346, Cfg9346_Unlock);
  7.1211 -			RTL_W16 (BasicModeCtrl, value);
  7.1212 -			RTL_W8 (Cfg9346, Cfg9346_Lock);
  7.1213 -		} else if (location < 8 && mii_2_8139_map[location])
  7.1214 -			RTL_W16 (mii_2_8139_map[location], value);
  7.1215 -		return;
  7.1216 -	}
  7.1217 -
  7.1218 -#ifdef CONFIG_8139TOO_8129
  7.1219 -	mdio_sync (mdio_addr);
  7.1220 -
  7.1221 -	/* Shift the command bits out. */
  7.1222 -	for (i = 31; i >= 0; i--) {
  7.1223 -		int dataval =
  7.1224 -		    (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0;
  7.1225 -		writeb (dataval, mdio_addr);
  7.1226 -		mdio_delay (mdio_addr);
  7.1227 -		writeb (dataval | MDIO_CLK, mdio_addr);
  7.1228 -		mdio_delay (mdio_addr);
  7.1229 -	}
  7.1230 -	/* Clear out extra bits. */
  7.1231 -	for (i = 2; i > 0; i--) {
  7.1232 -		writeb (0, mdio_addr);
  7.1233 -		mdio_delay (mdio_addr);
  7.1234 -		writeb (MDIO_CLK, mdio_addr);
  7.1235 -		mdio_delay (mdio_addr);
  7.1236 -	}
  7.1237 -#endif
  7.1238 -}
  7.1239 -
  7.1240 -
  7.1241 -static int rtl8139_open (struct net_device *dev)
  7.1242 -{
  7.1243 -	struct rtl8139_private *tp = dev->priv;
  7.1244 -	int retval;
  7.1245 -#ifdef RTL8139_DEBUG
  7.1246 -	void *ioaddr = tp->mmio_addr;
  7.1247 -#endif
  7.1248 -
  7.1249 -	retval = request_irq (dev->irq, rtl8139_interrupt, SA_SHIRQ, dev->name, dev);
  7.1250 -	if (retval)
  7.1251 -		return retval;
  7.1252 -
  7.1253 -	tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  7.1254 -					   &tp->tx_bufs_dma);
  7.1255 -	tp->rx_ring = pci_alloc_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  7.1256 -					   &tp->rx_ring_dma);
  7.1257 -	if (tp->tx_bufs == NULL || tp->rx_ring == NULL) {
  7.1258 -		free_irq(dev->irq, dev);
  7.1259 -
  7.1260 -		if (tp->tx_bufs)
  7.1261 -			pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  7.1262 -					    tp->tx_bufs, tp->tx_bufs_dma);
  7.1263 -		if (tp->rx_ring)
  7.1264 -			pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  7.1265 -					    tp->rx_ring, tp->rx_ring_dma);
  7.1266 -
  7.1267 -		return -ENOMEM;
  7.1268 -
  7.1269 -	}
  7.1270 -
  7.1271 -	tp->full_duplex = tp->duplex_lock;
  7.1272 -	tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000;
  7.1273 -	tp->twistie = 1;
  7.1274 -	tp->time_to_die = 0;
  7.1275 -
  7.1276 -	rtl8139_init_ring (dev);
  7.1277 -	rtl8139_hw_start (dev);
  7.1278 -
  7.1279 -	DPRINTK ("%s: rtl8139_open() ioaddr %#lx IRQ %d"
  7.1280 -			" GP Pins %2.2x %s-duplex.\n",
  7.1281 -			dev->name, pci_resource_start (tp->pci_dev, 1),
  7.1282 -			dev->irq, RTL_R8 (MediaStatus),
  7.1283 -			tp->full_duplex ? "full" : "half");
  7.1284 -
  7.1285 -	return 0;
  7.1286 -}
  7.1287 -
  7.1288 -
  7.1289 -static void rtl_check_media (struct net_device *dev)
  7.1290 -{
  7.1291 -	struct rtl8139_private *tp = dev->priv;
  7.1292 -
  7.1293 -	if (tp->phys[0] >= 0) {
  7.1294 -		u16 mii_reg5 = mdio_read(dev, tp->phys[0], 5);
  7.1295 -		if (mii_reg5 == 0xffff)
  7.1296 -			;					/* Not there */
  7.1297 -		else if ((mii_reg5 & 0x0100) == 0x0100
  7.1298 -				 || (mii_reg5 & 0x00C0) == 0x0040)
  7.1299 -			tp->full_duplex = 1;
  7.1300 -
  7.1301 -		printk (KERN_INFO"%s: Setting %s%s-duplex based on"
  7.1302 -				" auto-negotiated partner ability %4.4x.\n",
  7.1303 -		        dev->name, mii_reg5 == 0 ? "" :
  7.1304 -				(mii_reg5 & 0x0180) ? "100mbps " : "10mbps ",
  7.1305 -			tp->full_duplex ? "full" : "half", mii_reg5);
  7.1306 -	}
  7.1307 -}
  7.1308 -
  7.1309 -/* Start the hardware at open or resume. */
  7.1310 -static void rtl8139_hw_start (struct net_device *dev)
  7.1311 -{
  7.1312 -	struct rtl8139_private *tp = dev->priv;
  7.1313 -	void *ioaddr = tp->mmio_addr;
  7.1314 -	u32 i;
  7.1315 -	u8 tmp;
  7.1316 -
  7.1317 -	/* Bring old chips out of low-power mode. */
  7.1318 -	if (rtl_chip_info[tp->chipset].flags & HasHltClk)
  7.1319 -		RTL_W8 (HltClk, 'R');
  7.1320 -
  7.1321 -	rtl8139_chip_reset (ioaddr);
  7.1322 -
  7.1323 -	/* unlock Config[01234] and BMCR register writes */
  7.1324 -	RTL_W8_F (Cfg9346, Cfg9346_Unlock);
  7.1325 -	/* Restore our idea of the MAC address. */
  7.1326 -	RTL_W32_F (MAC0 + 0, cpu_to_le32 (*(u32 *) (dev->dev_addr + 0)));
  7.1327 -	RTL_W32_F (MAC0 + 4, cpu_to_le32 (*(u32 *) (dev->dev_addr + 4)));
  7.1328 -
  7.1329 -	/* Must enable Tx/Rx before setting transfer thresholds! */
  7.1330 -	RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
  7.1331 -
  7.1332 -	tp->rx_config = rtl8139_rx_config | AcceptBroadcast | AcceptMyPhys;
  7.1333 -	RTL_W32 (RxConfig, tp->rx_config);
  7.1334 -
  7.1335 -	/* Check this value: the documentation for IFG contradicts ifself. */
  7.1336 -	RTL_W32 (TxConfig, rtl8139_tx_config);
  7.1337 -
  7.1338 -	tp->cur_rx = 0;
  7.1339 -
  7.1340 -	rtl_check_media (dev);
  7.1341 -
  7.1342 -	if (tp->chipset >= CH_8139B) {
  7.1343 -		/* Disable magic packet scanning, which is enabled
  7.1344 -		 * when PM is enabled in Config1.  It can be reenabled
  7.1345 -		 * via ETHTOOL_SWOL if desired.  */
  7.1346 -		RTL_W8 (Config3, RTL_R8 (Config3) & ~Cfg3_Magic);
  7.1347 -	}
  7.1348 -
  7.1349 -	DPRINTK("init buffer addresses\n");
  7.1350 -
  7.1351 -	/* Lock Config[01234] and BMCR register writes */
  7.1352 -	RTL_W8 (Cfg9346, Cfg9346_Lock);
  7.1353 -
  7.1354 -	/* init Rx ring buffer DMA address */
  7.1355 -	RTL_W32_F (RxBuf, tp->rx_ring_dma);
  7.1356 -
  7.1357 -	/* init Tx buffer DMA addresses */
  7.1358 -	for (i = 0; i < NUM_TX_DESC; i++)
  7.1359 -		RTL_W32_F (TxAddr0 + (i * 4), tp->tx_bufs_dma + (tp->tx_buf[i] - tp->tx_bufs));
  7.1360 -
  7.1361 -	RTL_W32 (RxMissed, 0);
  7.1362 -
  7.1363 -	rtl8139_set_rx_mode (dev);
  7.1364 -
  7.1365 -	/* no early-rx interrupts */
  7.1366 -	RTL_W16 (MultiIntr, RTL_R16 (MultiIntr) & MultiIntrClear);
  7.1367 -
  7.1368 -	/* make sure RxTx has started */
  7.1369 -	tmp = RTL_R8 (ChipCmd);
  7.1370 -	if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb)))
  7.1371 -		RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
  7.1372 -
  7.1373 -	/* Enable all known interrupts by setting the interrupt mask. */
  7.1374 -	RTL_W16 (IntrMask, rtl8139_intr_mask);
  7.1375 -
  7.1376 -	netif_start_queue (dev);
  7.1377 -}
  7.1378 -
  7.1379 -
  7.1380 -/* Initialize the Rx and Tx rings, along with various 'dev' bits. */
  7.1381 -static void rtl8139_init_ring (struct net_device *dev)
  7.1382 -{
  7.1383 -	struct rtl8139_private *tp = dev->priv;
  7.1384 -	int i;
  7.1385 -
  7.1386 -	tp->cur_rx = 0;
  7.1387 -	tp->cur_tx = 0;
  7.1388 -	tp->dirty_tx = 0;
  7.1389 -
  7.1390 -	for (i = 0; i < NUM_TX_DESC; i++)
  7.1391 -		tp->tx_buf[i] = &tp->tx_bufs[i * TX_BUF_SIZE];
  7.1392 -}
  7.1393 -
  7.1394 -
  7.1395 -static void rtl8139_tx_clear (struct rtl8139_private *tp)
  7.1396 -{
  7.1397 -	tp->cur_tx = 0;
  7.1398 -	tp->dirty_tx = 0;
  7.1399 -
  7.1400 -	/* XXX account for unsent Tx packets in tp->stats.tx_dropped */
  7.1401 -}
  7.1402 -
  7.1403 -
  7.1404 -static void rtl8139_tx_timeout (struct net_device *dev)
  7.1405 -{
  7.1406 -	struct rtl8139_private *tp = dev->priv;
  7.1407 -	void *ioaddr = tp->mmio_addr;
  7.1408 -	int i;
  7.1409 -	u8 tmp8;
  7.1410 -	unsigned long flags;
  7.1411 -
  7.1412 -	DPRINTK ("%s: Transmit timeout, status %2.2x %4.4x "
  7.1413 -		 "media %2.2x.\n", dev->name,
  7.1414 -		 RTL_R8 (ChipCmd),
  7.1415 -		 RTL_R16 (IntrStatus),
  7.1416 -		 RTL_R8 (MediaStatus));
  7.1417 -
  7.1418 -	tp->xstats.tx_timeouts++;
  7.1419 -
  7.1420 -	/* disable Tx ASAP, if not already */
  7.1421 -	tmp8 = RTL_R8 (ChipCmd);
  7.1422 -	if (tmp8 & CmdTxEnb)
  7.1423 -		RTL_W8 (ChipCmd, CmdRxEnb);
  7.1424 -
  7.1425 -	/* Disable interrupts by clearing the interrupt mask. */
  7.1426 -	RTL_W16 (IntrMask, 0x0000);
  7.1427 -
  7.1428 -	/* Emit info to figure out what went wrong. */
  7.1429 -	printk (KERN_DEBUG "%s: Tx queue start entry %ld  dirty entry %ld.\n",
  7.1430 -		dev->name, tp->cur_tx, tp->dirty_tx);
  7.1431 -	for (i = 0; i < NUM_TX_DESC; i++)
  7.1432 -		printk (KERN_DEBUG "%s:  Tx descriptor %d is %8.8lx.%s\n",
  7.1433 -			dev->name, i, RTL_R32 (TxStatus0 + (i * 4)),
  7.1434 -			i == tp->dirty_tx % NUM_TX_DESC ?
  7.1435 -				" (queue head)" : "");
  7.1436 -
  7.1437 -	/* Stop a shared interrupt from scavenging while we are. */
  7.1438 -	spin_lock_irqsave (&tp->lock, flags);
  7.1439 -	rtl8139_tx_clear (tp);
  7.1440 -	spin_unlock_irqrestore (&tp->lock, flags);
  7.1441 -
  7.1442 -	/* ...and finally, reset everything */
  7.1443 -	rtl8139_hw_start (dev);
  7.1444 -
  7.1445 -	netif_wake_queue (dev);
  7.1446 -}
  7.1447 -
  7.1448 -
  7.1449 -static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
  7.1450 -{
  7.1451 -	struct rtl8139_private *tp = dev->priv;
  7.1452 -	void *ioaddr = tp->mmio_addr;
  7.1453 -	unsigned int entry;
  7.1454 -
  7.1455 -	/* Calculate the next Tx descriptor entry. */
  7.1456 -	entry = tp->cur_tx % NUM_TX_DESC;
  7.1457 -
  7.1458 -	if (likely(skb->len < TX_BUF_SIZE)) {
  7.1459 -		skb_copy_bits(skb, 0, tp->tx_buf[entry], skb->len);
  7.1460 -		dev_kfree_skb(skb);
  7.1461 -	} else {
  7.1462 -		dev_kfree_skb(skb);
  7.1463 -		tp->stats.tx_dropped++;
  7.1464 -		return 0;
  7.1465 -  	}
  7.1466 -
  7.1467 -	/* Note: the chip doesn't have auto-pad! */
  7.1468 -	spin_lock_irq(&tp->lock);
  7.1469 -	RTL_W32_F (TxStatus0 + (entry * sizeof (u32)),
  7.1470 -		   tp->tx_flag | (skb->len >= ETH_ZLEN ? skb->len : ETH_ZLEN));
  7.1471 -
  7.1472 -	dev->trans_start = jiffies;
  7.1473 -
  7.1474 -	tp->cur_tx++;
  7.1475 -	wmb();
  7.1476 -
  7.1477 -	if ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx)
  7.1478 -		netif_stop_queue (dev);
  7.1479 -	spin_unlock_irq(&tp->lock);
  7.1480 -
  7.1481 -	DPRINTK ("%s: Queued Tx packet at %p size %u to slot %d.\n",
  7.1482 -		 dev->name, skb->data, skb->len, entry);
  7.1483 -
  7.1484 -	return 0;
  7.1485 -}
  7.1486 -
  7.1487 -
  7.1488 -static void rtl8139_tx_interrupt (struct net_device *dev,
  7.1489 -				  struct rtl8139_private *tp,
  7.1490 -				  void *ioaddr)
  7.1491 -{
  7.1492 -	unsigned long dirty_tx, tx_left;
  7.1493 -
  7.1494 -	assert (dev != NULL);
  7.1495 -	assert (tp != NULL);
  7.1496 -	assert (ioaddr != NULL);
  7.1497 -
  7.1498 -	dirty_tx = tp->dirty_tx;
  7.1499 -	tx_left = tp->cur_tx - dirty_tx;
  7.1500 -	while (tx_left > 0) {
  7.1501 -		int entry = dirty_tx % NUM_TX_DESC;
  7.1502 -		int txstatus;
  7.1503 -
  7.1504 -		txstatus = RTL_R32 (TxStatus0 + (entry * sizeof (u32)));
  7.1505 -
  7.1506 -		if (!(txstatus & (TxStatOK | TxUnderrun | TxAborted)))
  7.1507 -			break;	/* It still hasn't been Txed */
  7.1508 -
  7.1509 -		/* Note: TxCarrierLost is always asserted at 100mbps. */
  7.1510 -		if (txstatus & (TxOutOfWindow | TxAborted)) {
  7.1511 -			/* There was an major error, log it. */
  7.1512 -			DPRINTK ("%s: Transmit error, Tx status %8.8x.\n",
  7.1513 -				 dev->name, txstatus);
  7.1514 -			tp->stats.tx_errors++;
  7.1515 -			if (txstatus & TxAborted) {
  7.1516 -				tp->stats.tx_aborted_errors++;
  7.1517 -				RTL_W32 (TxConfig, TxClearAbt);
  7.1518 -				RTL_W16 (IntrStatus, TxErr);
  7.1519 -				wmb();
  7.1520 -			}
  7.1521 -			if (txstatus & TxCarrierLost)
  7.1522 -				tp->stats.tx_carrier_errors++;
  7.1523 -			if (txstatus & TxOutOfWindow)
  7.1524 -				tp->stats.tx_window_errors++;
  7.1525 -#ifdef ETHER_STATS
  7.1526 -			if ((txstatus & 0x0f000000) == 0x0f000000)
  7.1527 -				tp->stats.collisions16++;
  7.1528 -#endif
  7.1529 -		} else {
  7.1530 -			if (txstatus & TxUnderrun) {
  7.1531 -				/* Add 64 to the Tx FIFO threshold. */
  7.1532 -				if (tp->tx_flag < 0x00300000)
  7.1533 -					tp->tx_flag += 0x00020000;
  7.1534 -				tp->stats.tx_fifo_errors++;
  7.1535 -			}
  7.1536 -			tp->stats.collisions += (txstatus >> 24) & 15;
  7.1537 -			tp->stats.tx_bytes += txstatus & 0x7ff;
  7.1538 -			tp->stats.tx_packets++;
  7.1539 -		}
  7.1540 -
  7.1541 -		dirty_tx++;
  7.1542 -		tx_left--;
  7.1543 -	}
  7.1544 -
  7.1545 -#ifndef RTL8139_NDEBUG
  7.1546 -	if (tp->cur_tx - dirty_tx > NUM_TX_DESC) {
  7.1547 -		printk (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n",
  7.1548 -		        dev->name, dirty_tx, tp->cur_tx);
  7.1549 -		dirty_tx += NUM_TX_DESC;
  7.1550 -	}
  7.1551 -#endif /* RTL8139_NDEBUG */
  7.1552 -
  7.1553 -	/* only wake the queue if we did work, and the queue is stopped */
  7.1554 -	if (tp->dirty_tx != dirty_tx) {
  7.1555 -		tp->dirty_tx = dirty_tx;
  7.1556 -		mb();
  7.1557 -		if (netif_queue_stopped (dev))
  7.1558 -			netif_wake_queue (dev);
  7.1559 -	}
  7.1560 -}
  7.1561 -
  7.1562 -
  7.1563 -/* TODO: clean this up!  Rx reset need not be this intensive */
  7.1564 -static void rtl8139_rx_err (u32 rx_status, struct net_device *dev,
  7.1565 -			    struct rtl8139_private *tp, void *ioaddr)
  7.1566 -{
  7.1567 -	u8 tmp8;
  7.1568 -	int tmp_work;
  7.1569 -
  7.1570 -	DPRINTK ("%s: Ethernet frame had errors, status %8.8x.\n",
  7.1571 -	         dev->name, rx_status);
  7.1572 -	if (rx_status & RxTooLong) {
  7.1573 -		DPRINTK ("%s: Oversized Ethernet frame, status %4.4x!\n",
  7.1574 -			 dev->name, rx_status);
  7.1575 -		/* A.C.: The chip hangs here. */
  7.1576 -	}
  7.1577 -	tp->stats.rx_errors++;
  7.1578 -	if (rx_status & (RxBadSymbol | RxBadAlign))
  7.1579 -		tp->stats.rx_frame_errors++;
  7.1580 -	if (rx_status & (RxRunt | RxTooLong))
  7.1581 -		tp->stats.rx_length_errors++;
  7.1582 -	if (rx_status & RxCRCErr)
  7.1583 -		tp->stats.rx_crc_errors++;
  7.1584 -
  7.1585 -	/* Reset the receiver, based on RealTek recommendation. (Bug?) */
  7.1586 -
  7.1587 -	/* disable receive */
  7.1588 -	RTL_W8_F (ChipCmd, CmdTxEnb);
  7.1589 -	tmp_work = 200;
  7.1590 -	while (--tmp_work > 0) {
  7.1591 -		udelay(1);
  7.1592 -		tmp8 = RTL_R8 (ChipCmd);
  7.1593 -		if (!(tmp8 & CmdRxEnb))
  7.1594 -			break;
  7.1595 -	}
  7.1596 -	if (tmp_work <= 0)
  7.1597 -		printk (KERN_WARNING PFX "rx stop wait too long\n");
  7.1598 -	/* restart receive */
  7.1599 -	tmp_work = 200;
  7.1600 -	while (--tmp_work > 0) {
  7.1601 -		RTL_W8_F (ChipCmd, CmdRxEnb | CmdTxEnb);
  7.1602 -		udelay(1);
  7.1603 -		tmp8 = RTL_R8 (ChipCmd);
  7.1604 -		if ((tmp8 & CmdRxEnb) && (tmp8 & CmdTxEnb))
  7.1605 -			break;
  7.1606 -	}
  7.1607 -	if (tmp_work <= 0)
  7.1608 -		printk (KERN_WARNING PFX "tx/rx enable wait too long\n");
  7.1609 -
  7.1610 -	/* and reinitialize all rx related registers */
  7.1611 -	RTL_W8_F (Cfg9346, Cfg9346_Unlock);
  7.1612 -	/* Must enable Tx/Rx before setting transfer thresholds! */
  7.1613 -	RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
  7.1614 -
  7.1615 -	tp->rx_config = rtl8139_rx_config | AcceptBroadcast | AcceptMyPhys;
  7.1616 -	RTL_W32 (RxConfig, tp->rx_config);
  7.1617 -	tp->cur_rx = 0;
  7.1618 -
  7.1619 -	DPRINTK("init buffer addresses\n");
  7.1620 -
  7.1621 -	/* Lock Config[01234] and BMCR register writes */
  7.1622 -	RTL_W8 (Cfg9346, Cfg9346_Lock);
  7.1623 -
  7.1624 -	/* init Rx ring buffer DMA address */
  7.1625 -	RTL_W32_F (RxBuf, tp->rx_ring_dma);
  7.1626 -
  7.1627 -	/* A.C.: Reset the multicast list. */
  7.1628 -	__set_rx_mode (dev);
  7.1629 -}
  7.1630 -
  7.1631 -static void rtl8139_rx_interrupt (struct net_device *dev,
  7.1632 -				  struct rtl8139_private *tp, void *ioaddr)
  7.1633 -{
  7.1634 -	unsigned char *rx_ring;
  7.1635 -	u16 cur_rx;
  7.1636 -
  7.1637 -	assert (dev != NULL);
  7.1638 -	assert (tp != NULL);
  7.1639 -	assert (ioaddr != NULL);
  7.1640 -
  7.1641 -	rx_ring = tp->rx_ring;
  7.1642 -	cur_rx = tp->cur_rx;
  7.1643 -
  7.1644 -	DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x,"
  7.1645 -		 " free to %4.4x, Cmd %2.2x.\n", dev->name, cur_rx,
  7.1646 -		 RTL_R16 (RxBufAddr),
  7.1647 -		 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
  7.1648 -
  7.1649 -	while ((RTL_R8 (ChipCmd) & RxBufEmpty) == 0) {
  7.1650 -		int ring_offset = cur_rx % RX_BUF_LEN;
  7.1651 -		u32 rx_status;
  7.1652 -		unsigned int rx_size;
  7.1653 -		unsigned int pkt_size;
  7.1654 -		struct sk_buff *skb;
  7.1655 -
  7.1656 -		rmb();
  7.1657 -
  7.1658 -		/* read size+status of next frame from DMA ring buffer */
  7.1659 -		rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset));
  7.1660 -		rx_size = rx_status >> 16;
  7.1661 -		pkt_size = rx_size - 4;
  7.1662 -
  7.1663 -		DPRINTK ("%s:  rtl8139_rx() status %4.4x, size %4.4x,"
  7.1664 -			 " cur %4.4x.\n", dev->name, rx_status,
  7.1665 -			 rx_size, cur_rx);
  7.1666 -#if RTL8139_DEBUG > 2
  7.1667 -		{
  7.1668 -			int i;
  7.1669 -			DPRINTK ("%s: Frame contents ", dev->name);
  7.1670 -			for (i = 0; i < 70; i++)
  7.1671 -				printk (" %2.2x",
  7.1672 -					rx_ring[ring_offset + i]);
  7.1673 -			printk (".\n");
  7.1674 -		}
  7.1675 -#endif
  7.1676 -
  7.1677 -		/* Packet copy from FIFO still in progress.
  7.1678 -		 * Theoretically, this should never happen
  7.1679 -		 * since EarlyRx is disabled.
  7.1680 -		 */
  7.1681 -		if (rx_size == 0xfff0) {
  7.1682 -			tp->xstats.early_rx++;
  7.1683 -			break;
  7.1684 -		}
  7.1685 -
  7.1686 -		/* If Rx err or invalid rx_size/rx_status received
  7.1687 -		 * (which happens if we get lost in the ring),
  7.1688 -		 * Rx process gets reset, so we abort any further
  7.1689 -		 * Rx processing.
  7.1690 -		 */
  7.1691 -		if ((rx_size > (MAX_ETH_FRAME_SIZE+4)) ||
  7.1692 -		    (rx_size < 8) ||
  7.1693 -		    (!(rx_status & RxStatusOK))) {
  7.1694 -			rtl8139_rx_err (rx_status, dev, tp, ioaddr);
  7.1695 -			return;
  7.1696 -		}
  7.1697 -
  7.1698 -		/* Malloc up new buffer, compatible with net-2e. */
  7.1699 -		/* Omit the four octet CRC from the length. */
  7.1700 -
  7.1701 -		/* TODO: consider allocating skb's outside of
  7.1702 -		 * interrupt context, both to speed interrupt processing,
  7.1703 -		 * and also to reduce the chances of having to
  7.1704 -		 * drop packets here under memory pressure.
  7.1705 -		 */
  7.1706 -
  7.1707 -		skb = dev_alloc_skb (pkt_size + 2);
  7.1708 -		if (skb) {
  7.1709 -			skb->dev = dev;
  7.1710 -			skb_reserve (skb, 2);	/* 16 byte align the IP fields. */
  7.1711 -
  7.1712 -			eth_copy_and_sum (skb, &rx_ring[ring_offset + 4], pkt_size, 0);
  7.1713 -			skb_put (skb, pkt_size);
  7.1714 -
  7.1715 -			skb->protocol = eth_type_trans (skb, dev);
  7.1716 -			netif_rx (skb);
  7.1717 -			dev->last_rx = jiffies;
  7.1718 -			tp->stats.rx_bytes += pkt_size;
  7.1719 -			tp->stats.rx_packets++;
  7.1720 -		} else {
  7.1721 -			printk (KERN_WARNING
  7.1722 -				"%s: Memory squeeze, dropping packet.\n",
  7.1723 -				dev->name);
  7.1724 -			tp->stats.rx_dropped++;
  7.1725 -		}
  7.1726 -
  7.1727 -		cur_rx = (cur_rx + rx_size + 4 + 3) & ~3;
  7.1728 -		RTL_W16 (RxBufPtr, cur_rx - 16);
  7.1729 -
  7.1730 -		if (RTL_R16 (IntrStatus) & RxAckBits)
  7.1731 -			RTL_W16_F (IntrStatus, RxAckBits);
  7.1732 -	}
  7.1733 -
  7.1734 -	DPRINTK ("%s: Done rtl8139_rx(), current %4.4x BufAddr %4.4x,"
  7.1735 -		 " free to %4.4x, Cmd %2.2x.\n", dev->name, cur_rx,
  7.1736 -		 RTL_R16 (RxBufAddr),
  7.1737 -		 RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd));
  7.1738 -
  7.1739 -	tp->cur_rx = cur_rx;
  7.1740 -}
  7.1741 -
  7.1742 -
  7.1743 -static void rtl8139_weird_interrupt (struct net_device *dev,
  7.1744 -				     struct rtl8139_private *tp,
  7.1745 -				     void *ioaddr,
  7.1746 -				     int status, int link_changed)
  7.1747 -{
  7.1748 -	DPRINTK ("%s: Abnormal interrupt, status %8.8x.\n",
  7.1749 -		 dev->name, status);
  7.1750 -
  7.1751 -	assert (dev != NULL);
  7.1752 -	assert (tp != NULL);
  7.1753 -	assert (ioaddr != NULL);
  7.1754 -
  7.1755 -	/* Update the error count. */
  7.1756 -	tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  7.1757 -	RTL_W32 (RxMissed, 0);
  7.1758 -
  7.1759 -	if ((status & RxUnderrun) && link_changed &&
  7.1760 -	    (tp->drv_flags & HAS_LNK_CHNG)) {
  7.1761 -		/* Really link-change on new chips. */
  7.1762 -		int lpar = RTL_R16 (NWayLPAR);
  7.1763 -		int duplex = (lpar & 0x0100) || (lpar & 0x01C0) == 0x0040
  7.1764 -				|| tp->duplex_lock;
  7.1765 -		if (tp->full_duplex != duplex) {
  7.1766 -			tp->full_duplex = duplex;
  7.1767 -#if 0
  7.1768 -			RTL_W8 (Cfg9346, Cfg9346_Unlock);
  7.1769 -			RTL_W8 (Config1, tp->full_duplex ? 0x60 : 0x20);
  7.1770 -			RTL_W8 (Cfg9346, Cfg9346_Lock);
  7.1771 -#endif
  7.1772 -		}
  7.1773 -		status &= ~RxUnderrun;
  7.1774 -	}
  7.1775 -
  7.1776 -	/* XXX along with rtl8139_rx_err, are we double-counting errors? */
  7.1777 -	if (status &
  7.1778 -	    (RxUnderrun | RxOverflow | RxErr | RxFIFOOver))
  7.1779 -		tp->stats.rx_errors++;
  7.1780 -
  7.1781 -	if (status & PCSTimeout)
  7.1782 -		tp->stats.rx_length_errors++;
  7.1783 -	if (status & (RxUnderrun | RxFIFOOver))
  7.1784 -		tp->stats.rx_fifo_errors++;
  7.1785 -	if (status & PCIErr) {
  7.1786 -		u16 pci_cmd_status;
  7.1787 -		pci_read_config_word (tp->pci_dev, PCI_STATUS, &pci_cmd_status);
  7.1788 -		pci_write_config_word (tp->pci_dev, PCI_STATUS, pci_cmd_status);
  7.1789 -
  7.1790 -		printk (KERN_ERR "%s: PCI Bus error %4.4x.\n",
  7.1791 -			dev->name, pci_cmd_status);
  7.1792 -	}
  7.1793 -}
  7.1794 -
  7.1795 -
  7.1796 -/* The interrupt handler does all of the Rx thread work and cleans up
  7.1797 -   after the Tx thread. */
  7.1798 -static void rtl8139_interrupt (int irq, void *dev_instance,
  7.1799 -			       struct pt_regs *regs)
  7.1800 -{
  7.1801 -	struct net_device *dev = (struct net_device *) dev_instance;
  7.1802 -	struct rtl8139_private *tp = dev->priv;
  7.1803 -	int boguscnt = max_interrupt_work;
  7.1804 -	void *ioaddr = tp->mmio_addr;
  7.1805 -	int ackstat, status;
  7.1806 -	int link_changed = 0; /* avoid bogus "uninit" warning */
  7.1807 -
  7.1808 -	spin_lock (&tp->lock);
  7.1809 -
  7.1810 -	do {
  7.1811 -		status = RTL_R16 (IntrStatus);
  7.1812 -
  7.1813 -		/* h/w no longer present (hotplug?) or major error, bail */
  7.1814 -		if (status == 0xFFFF)
  7.1815 -			break;
  7.1816 -
  7.1817 -		if ((status &
  7.1818 -		     (PCIErr | PCSTimeout | RxUnderrun | RxOverflow |
  7.1819 -		      RxFIFOOver | TxErr | TxOK | RxErr | RxOK)) == 0)
  7.1820 -			break;
  7.1821 -
  7.1822 -		/* Acknowledge all of the current interrupt sources ASAP, but
  7.1823 -		   an first get an additional status bit from CSCR. */
  7.1824 -		if (status & RxUnderrun)
  7.1825 -			link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit;
  7.1826 -
  7.1827 -		/* The chip takes special action when we clear RxAckBits,
  7.1828 -		 * so we clear them later in rtl8139_rx_interrupt
  7.1829 -		 */
  7.1830 -		ackstat = status & ~(RxAckBits | TxErr);
  7.1831 -		RTL_W16 (IntrStatus, ackstat);
  7.1832 -
  7.1833 -		DPRINTK ("%s: interrupt  status=%#4.4x ackstat=%#4.4x new intstat=%#4.4x.\n",
  7.1834 -			 dev->name, ackstat, status, RTL_R16 (IntrStatus));
  7.1835 -
  7.1836 -		if (netif_running (dev) && (status & RxAckBits))
  7.1837 -			rtl8139_rx_interrupt (dev, tp, ioaddr);
  7.1838 -
  7.1839 -		/* Check uncommon events with one test. */
  7.1840 -		if (status & (PCIErr | PCSTimeout | RxUnderrun | RxOverflow |
  7.1841 -		  	      RxFIFOOver | RxErr))
  7.1842 -			rtl8139_weird_interrupt (dev, tp, ioaddr,
  7.1843 -						 status, link_changed);
  7.1844 -
  7.1845 -		if (netif_running (dev) && (status & (TxOK | TxErr))) {
  7.1846 -			rtl8139_tx_interrupt (dev, tp, ioaddr);
  7.1847 -			if (status & TxErr)
  7.1848 -				RTL_W16 (IntrStatus, TxErr);
  7.1849 -		}
  7.1850 -
  7.1851 -		boguscnt--;
  7.1852 -	} while (boguscnt > 0);
  7.1853 -
  7.1854 -	if (boguscnt <= 0) {
  7.1855 -		printk (KERN_WARNING "%s: Too much work at interrupt, "
  7.1856 -			"IntrStatus=0x%4.4x.\n", dev->name, status);
  7.1857 -
  7.1858 -		/* Clear all interrupt sources. */
  7.1859 -		RTL_W16 (IntrStatus, 0xffff);
  7.1860 -	}
  7.1861 -
  7.1862 -	spin_unlock (&tp->lock);
  7.1863 -
  7.1864 -	DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n",
  7.1865 -		 dev->name, RTL_R16 (IntrStatus));
  7.1866 -}
  7.1867 -
  7.1868 -
  7.1869 -static int rtl8139_close (struct net_device *dev)
  7.1870 -{
  7.1871 -	struct rtl8139_private *tp = dev->priv;
  7.1872 -	void *ioaddr = tp->mmio_addr;
  7.1873 -	unsigned long flags;
  7.1874 -
  7.1875 -	netif_stop_queue (dev);
  7.1876 -
  7.1877 -	DPRINTK ("%s: Shutting down ethercard, status was 0x%4.4x.\n",
  7.1878 -			dev->name, RTL_R16 (IntrStatus));
  7.1879 -
  7.1880 -	spin_lock_irqsave (&tp->lock, flags);
  7.1881 -
  7.1882 -	/* Stop the chip's Tx and Rx DMA processes. */
  7.1883 -	RTL_W8 (ChipCmd, 0);
  7.1884 -
  7.1885 -	/* Disable interrupts by clearing the interrupt mask. */
  7.1886 -	RTL_W16 (IntrMask, 0);
  7.1887 -
  7.1888 -	/* Update the error counts. */
  7.1889 -	tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  7.1890 -	RTL_W32 (RxMissed, 0);
  7.1891 -
  7.1892 -	spin_unlock_irqrestore (&tp->lock, flags);
  7.1893 -
  7.1894 -	synchronize_irq ();
  7.1895 -	free_irq (dev->irq, dev);
  7.1896 -
  7.1897 -	rtl8139_tx_clear (tp);
  7.1898 -
  7.1899 -	pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN,
  7.1900 -			    tp->rx_ring, tp->rx_ring_dma);
  7.1901 -	pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN,
  7.1902 -			    tp->tx_bufs, tp->tx_bufs_dma);
  7.1903 -	tp->rx_ring = NULL;
  7.1904 -	tp->tx_bufs = NULL;
  7.1905 -
  7.1906 -	/* Green! Put the chip in low-power mode. */
  7.1907 -	RTL_W8 (Cfg9346, Cfg9346_Unlock);
  7.1908 -
  7.1909 -	if (rtl_chip_info[tp->chipset].flags & HasHltClk)
  7.1910 -		RTL_W8 (HltClk, 'H');	/* 'R' would leave the clock running. */
  7.1911 -
  7.1912 -	return 0;
  7.1913 -}
  7.1914 -
  7.1915 -
  7.1916 -/* Get the ethtool settings.  Assumes that eset points to kernel
  7.1917 -   memory, *eset has been initialized as {ETHTOOL_GSET}, and other
  7.1918 -   threads or interrupts aren't messing with the 8139.  */
  7.1919 -static void netdev_get_eset (struct net_device *dev, struct ethtool_cmd *eset)
  7.1920 -{
  7.1921 -	struct rtl8139_private *np = dev->priv;
  7.1922 -	void *ioaddr = np->mmio_addr;
  7.1923 -	u16 advert;
  7.1924 -
  7.1925 -	eset->supported = SUPPORTED_10baseT_Half
  7.1926 -		      	| SUPPORTED_10baseT_Full
  7.1927 -		      	| SUPPORTED_100baseT_Half
  7.1928 -		      	| SUPPORTED_100baseT_Full
  7.1929 -		      	| SUPPORTED_Autoneg
  7.1930 -		      	| SUPPORTED_TP;
  7.1931 -
  7.1932 -	eset->advertising = ADVERTISED_TP | ADVERTISED_Autoneg;
  7.1933 -	advert = mdio_read (dev, np->phys[0], 4);
  7.1934 -	if (advert & 0x0020)
  7.1935 -		eset->advertising |= ADVERTISED_10baseT_Half;
  7.1936 -	if (advert & 0x0040)
  7.1937 -		eset->advertising |= ADVERTISED_10baseT_Full;
  7.1938 -	if (advert & 0x0080)
  7.1939 -		eset->advertising |= ADVERTISED_100baseT_Half;
  7.1940 -	if (advert & 0x0100)
  7.1941 -		eset->advertising |= ADVERTISED_100baseT_Full;
  7.1942 -
  7.1943 -	eset->speed = (RTL_R8 (MediaStatus) & 0x08) ? 10 : 100;
  7.1944 -	/* (KON)FIXME: np->full_duplex is set or reset by the thread,
  7.1945 -	   which means this always shows half duplex if the interface
  7.1946 -	   isn't up yet, even if it has already autonegotiated.  */
  7.1947 -	eset->duplex = np->full_duplex ? DUPLEX_FULL : DUPLEX_HALF;
  7.1948 -	eset->port = PORT_TP;
  7.1949 -	/* (KON)FIXME: Is np->phys[0] correct?  starfire.c uses that.  */
  7.1950 -	eset->phy_address = np->phys[0];
  7.1951 -	eset->transceiver = XCVR_INTERNAL;
  7.1952 -	eset->autoneg = (mdio_read (dev, np->phys[0], 0) & 0x1000) != 0;
  7.1953 -	eset->maxtxpkt = 1;
  7.1954 -	eset->maxrxpkt = 1;
  7.1955 -}
  7.1956 -
  7.1957 -
  7.1958 -/* Get the ethtool Wake-on-LAN settings.  Assumes that wol points to
  7.1959 -   kernel memory, *wol has been initialized as {ETHTOOL_GWOL}, and
  7.1960 -   other threads or interrupts aren't messing with the 8139.  */
  7.1961 -static void netdev_get_wol (struct net_device *dev, struct ethtool_wolinfo *wol)
  7.1962 -{
  7.1963 -	struct rtl8139_private *np = dev->priv;
  7.1964 -	void *ioaddr = np->mmio_addr;
  7.1965 -
  7.1966 -	if (rtl_chip_info[np->chipset].flags & HasLWake) {
  7.1967 -		u8 cfg3 = RTL_R8 (Config3);
  7.1968 -		u8 cfg5 = RTL_R8 (Config5);
  7.1969 -
  7.1970 -		wol->supported = WAKE_PHY | WAKE_MAGIC
  7.1971 -			| WAKE_UCAST | WAKE_MCAST | WAKE_BCAST;
  7.1972 -
  7.1973 -		wol->wolopts = 0;
  7.1974 -		if (cfg3 & Cfg3_LinkUp)
  7.1975 -			wol->wolopts |= WAKE_PHY;
  7.1976 -		if (cfg3 & Cfg3_Magic)
  7.1977 -			wol->wolopts |= WAKE_MAGIC;
  7.1978 -		/* (KON)FIXME: See how netdev_set_wol() handles the
  7.1979 -		   following constants.  */
  7.1980 -		if (cfg5 & Cfg5_UWF)
  7.1981 -			wol->wolopts |= WAKE_UCAST;
  7.1982 -		if (cfg5 & Cfg5_MWF)
  7.1983 -			wol->wolopts |= WAKE_MCAST;
  7.1984 -		if (cfg5 & Cfg5_BWF)
  7.1985 -			wol->wolopts |= WAKE_BCAST;
  7.1986 -	}
  7.1987 -}
  7.1988 -
  7.1989 -
  7.1990 -/* Set the ethtool Wake-on-LAN settings.  Return 0 or -errno.  Assumes
  7.1991 -   that wol points to kernel memory and other threads or interrupts
  7.1992 -   aren't messing with the 8139.  */
  7.1993 -static int netdev_set_wol (struct net_device *dev,
  7.1994 -			   const struct ethtool_wolinfo *wol)
  7.1995 -{
  7.1996 -	struct rtl8139_private *np = dev->priv;
  7.1997 -	void *ioaddr = np->mmio_addr;
  7.1998 -	u32 support;
  7.1999 -	u8 cfg3, cfg5;
  7.2000 -
  7.2001 -	support = ((rtl_chip_info[np->chipset].flags & HasLWake)
  7.2002 -		   ? (WAKE_PHY | WAKE_MAGIC
  7.2003 -		      | WAKE_UCAST | WAKE_MCAST | WAKE_BCAST)
  7.2004 -		   : 0);
  7.2005 -	if (wol->wolopts & ~support)
  7.2006 -		return -EINVAL;
  7.2007 -
  7.2008 -	cfg3 = RTL_R8 (Config3) & ~(Cfg3_LinkUp | Cfg3_Magic);
  7.2009 -	if (wol->wolopts & WAKE_PHY)
  7.2010 -		cfg3 |= Cfg3_LinkUp;
  7.2011 -	if (wol->wolopts & WAKE_MAGIC)
  7.2012 -		cfg3 |= Cfg3_Magic;
  7.2013 -	RTL_W8 (Cfg9346, Cfg9346_Unlock);
  7.2014 -	RTL_W8 (Config3, cfg3);
  7.2015 -	RTL_W8 (Cfg9346, Cfg9346_Lock);
  7.2016 -
  7.2017 -	cfg5 = RTL_R8 (Config5) & ~(Cfg5_UWF | Cfg5_MWF | Cfg5_BWF);
  7.2018 -	/* (KON)FIXME: These are untested.  We may have to set the
  7.2019 -	   CRC0, Wakeup0 and LSBCRC0 registers too, but I have no
  7.2020 -	   documentation.  */
  7.2021 -	if (wol->wolopts & WAKE_UCAST)
  7.2022 -		cfg5 |= Cfg5_UWF;
  7.2023 -	if (wol->wolopts & WAKE_MCAST)
  7.2024 -		cfg5 |= Cfg5_MWF;
  7.2025 -	if (wol->wolopts & WAKE_BCAST)
  7.2026 -		cfg5 |= Cfg5_BWF;
  7.2027 -	RTL_W8 (Config5, cfg5);	/* need not unlock via Cfg9346 */
  7.2028 -
  7.2029 -	return 0;
  7.2030 -}
  7.2031 -
  7.2032 -
  7.2033 -static int netdev_ethtool_ioctl (struct net_device *dev, void *useraddr)
  7.2034 -{
  7.2035 -	struct rtl8139_private *np = dev->priv;
  7.2036 -	u32 ethcmd;
  7.2037 -
  7.2038 -	/* dev_ioctl() in ../../net/core/dev.c has already checked
  7.2039 -	   capable(CAP_NET_ADMIN), so don't bother with that here.  */
  7.2040 -
  7.2041 -	if (copy_from_user (&ethcmd, useraddr, sizeof (ethcmd)))
  7.2042 -		return -EFAULT;
  7.2043 -
  7.2044 -	switch (ethcmd) {
  7.2045 -	case ETHTOOL_GSET:
  7.2046 -		{
  7.2047 -			struct ethtool_cmd eset = { ETHTOOL_GSET };
  7.2048 -			spin_lock_irq (&np->lock);
  7.2049 -			netdev_get_eset (dev, &eset);
  7.2050 -			spin_unlock_irq (&np->lock);
  7.2051 -			if (copy_to_user (useraddr, &eset, sizeof (eset)))
  7.2052 -				return -EFAULT;
  7.2053 -			return 0;
  7.2054 -		}
  7.2055 -
  7.2056 -	/* TODO: ETHTOOL_SSET */
  7.2057 -
  7.2058 -	case ETHTOOL_GDRVINFO:
  7.2059 -		{
  7.2060 -			struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
  7.2061 -			strcpy (info.driver, DRV_NAME);
  7.2062 -			strcpy (info.version, DRV_VERSION);
  7.2063 -			strcpy (info.bus_info, np->pci_dev->slot_name);
  7.2064 -			if (copy_to_user (useraddr, &info, sizeof (info)))
  7.2065 -				return -EFAULT;
  7.2066 -			return 0;
  7.2067 -		}
  7.2068 -
  7.2069 -	case ETHTOOL_GWOL:
  7.2070 -		{
  7.2071 -			struct ethtool_wolinfo wol = { ETHTOOL_GWOL };
  7.2072 -			spin_lock_irq (&np->lock);
  7.2073 -			netdev_get_wol (dev, &wol);
  7.2074 -			spin_unlock_irq (&np->lock);
  7.2075 -			if (copy_to_user (useraddr, &wol, sizeof (wol)))
  7.2076 -				return -EFAULT;
  7.2077 -			return 0;
  7.2078 -		}
  7.2079 -
  7.2080 -	case ETHTOOL_SWOL:
  7.2081 -		{
  7.2082 -			struct ethtool_wolinfo wol;
  7.2083 -			int rc;
  7.2084 -			if (copy_from_user (&wol, useraddr, sizeof (wol)))
  7.2085 -				return -EFAULT;
  7.2086 -			spin_lock_irq (&np->lock);
  7.2087 -			rc = netdev_set_wol (dev, &wol);
  7.2088 -			spin_unlock_irq (&np->lock);
  7.2089 -			return rc;
  7.2090 -		}
  7.2091 -
  7.2092 -	default:
  7.2093 -		break;
  7.2094 -	}
  7.2095 -
  7.2096 -	return -EOPNOTSUPP;
  7.2097 -}
  7.2098 -
  7.2099 -
  7.2100 -static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
  7.2101 -{
  7.2102 -	struct rtl8139_private *tp = dev->priv;
  7.2103 -	struct mii_ioctl_data *data = (struct mii_ioctl_data *)&rq->ifr_data;
  7.2104 -	int rc = 0;
  7.2105 -	int phy = tp->phys[0] & 0x3f;
  7.2106 -
  7.2107 -	if (cmd != SIOCETHTOOL) {
  7.2108 -		/* With SIOCETHTOOL, this would corrupt the pointer.  */
  7.2109 -		data->phy_id &= 0x1f;
  7.2110 -		data->reg_num &= 0x1f;
  7.2111 -	}
  7.2112 -
  7.2113 -	switch (cmd) {
  7.2114 -	case SIOCETHTOOL:
  7.2115 -		return netdev_ethtool_ioctl(dev, (void *) rq->ifr_data);
  7.2116 -
  7.2117 -	case SIOCGMIIPHY:	/* Get the address of the PHY in use. */
  7.2118 -	case SIOCDEVPRIVATE:	/* binary compat, remove in 2.5 */
  7.2119 -		data->phy_id = phy;
  7.2120 -		/* Fall Through */
  7.2121 -
  7.2122 -	case SIOCGMIIREG:	/* Read the specified MII register. */
  7.2123 -	case SIOCDEVPRIVATE+1:	/* binary compat, remove in 2.5 */
  7.2124 -		data->val_out = mdio_read (dev, data->phy_id, data->reg_num);
  7.2125 -		break;
  7.2126 -
  7.2127 -	case SIOCSMIIREG:	/* Write the specified MII register */
  7.2128 -	case SIOCDEVPRIVATE+2:	/* binary compat, remove in 2.5 */
  7.2129 -		if (!capable (CAP_NET_ADMIN)) {
  7.2130 -			rc = -EPERM;
  7.2131 -			break;
  7.2132 -		}
  7.2133 -
  7.2134 -		if (data->phy_id == phy) {
  7.2135 -			u16 value = data->val_in;
  7.2136 -			switch (data->reg_num) {
  7.2137 -			case 0:
  7.2138 -				/* Check for autonegotiation on or reset. */
  7.2139 -				tp->medialock = (value & 0x9000) ? 0 : 1;
  7.2140 -				if (tp->medialock)
  7.2141 -					tp->full_duplex = (value & 0x0100) ? 1 : 0;
  7.2142 -				break;
  7.2143 -			case 4: /* tp->advertising = value; */ break;
  7.2144 -			}
  7.2145 -		}
  7.2146 -		mdio_write(dev, data->phy_id, data->reg_num, data->val_in);
  7.2147 -		break;
  7.2148 -
  7.2149 -	default:
  7.2150 -		rc = -EOPNOTSUPP;
  7.2151 -		break;
  7.2152 -	}
  7.2153 -
  7.2154 -	return rc;
  7.2155 -}
  7.2156 -
  7.2157 -
  7.2158 -static struct net_device_stats *rtl8139_get_stats (struct net_device *dev)
  7.2159 -{
  7.2160 -	struct rtl8139_private *tp = dev->priv;
  7.2161 -	void *ioaddr = tp->mmio_addr;
  7.2162 -	unsigned long flags;
  7.2163 -
  7.2164 -	if (netif_running(dev)) {
  7.2165 -		spin_lock_irqsave (&tp->lock, flags);
  7.2166 -		tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  7.2167 -		RTL_W32 (RxMissed, 0);
  7.2168 -		spin_unlock_irqrestore (&tp->lock, flags);
  7.2169 -	}
  7.2170 -
  7.2171 -	return &tp->stats;
  7.2172 -}
  7.2173 -
  7.2174 -/* Set or clear the multicast filter for this adaptor.
  7.2175 -   This routine is not state sensitive and need not be SMP locked. */
  7.2176 -
  7.2177 -static unsigned const ethernet_polynomial = 0x04c11db7U;
  7.2178 -static inline u32 ether_crc (int length, unsigned char *data)
  7.2179 -{
  7.2180 -	int crc = -1;
  7.2181 -
  7.2182 -	while (--length >= 0) {
  7.2183 -		unsigned char current_octet = *data++;
  7.2184 -		int bit;
  7.2185 -		for (bit = 0; bit < 8; bit++, current_octet >>= 1)
  7.2186 -			crc = (crc << 1) ^ ((crc < 0) ^ (current_octet & 1) ?
  7.2187 -			     ethernet_polynomial : 0);
  7.2188 -	}
  7.2189 -
  7.2190 -	return crc;
  7.2191 -}
  7.2192 -
  7.2193 -
  7.2194 -static void __set_rx_mode (struct net_device *dev)
  7.2195 -{
  7.2196 -	struct rtl8139_private *tp = dev->priv;
  7.2197 -	void *ioaddr = tp->mmio_addr;
  7.2198 -	u32 mc_filter[2];	/* Multicast hash filter */
  7.2199 -	int i, rx_mode;
  7.2200 -	u32 tmp;
  7.2201 -
  7.2202 -	DPRINTK ("%s:   rtl8139_set_rx_mode(%4.4x) done -- Rx config %8.8lx.\n",
  7.2203 -			dev->name, dev->flags, RTL_R32 (RxConfig));
  7.2204 -
  7.2205 -	/* Note: do not reorder, GCC is clever about common statements. */
  7.2206 -	if (dev->flags & IFF_PROMISC) {
  7.2207 -		/* Unconditionally log net taps. */
  7.2208 -		printk (KERN_NOTICE "%s: Promiscuous mode enabled.\n",
  7.2209 -			dev->name);
  7.2210 -		rx_mode =
  7.2211 -		    AcceptBroadcast | AcceptMulticast | AcceptMyPhys |
  7.2212 -		    AcceptAllPhys;
  7.2213 -		mc_filter[1] = mc_filter[0] = 0xffffffff;
  7.2214 -	} else if ((dev->mc_count > multicast_filter_limit)
  7.2215 -		   || (dev->flags & IFF_ALLMULTI)) {
  7.2216 -		/* Too many to filter perfectly -- accept all multicasts. */
  7.2217 -		rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
  7.2218 -		mc_filter[1] = mc_filter[0] = 0xffffffff;
  7.2219 -	} else {
  7.2220 -		struct dev_mc_list *mclist;
  7.2221 -		rx_mode = AcceptBroadcast | AcceptMyPhys;
  7.2222 -		mc_filter[1] = mc_filter[0] = 0;
  7.2223 -		for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  7.2224 -		     i++, mclist = mclist->next) {
  7.2225 -			int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
  7.2226 -
  7.2227 -			mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
  7.2228 -			rx_mode |= AcceptMulticast;
  7.2229 -		}
  7.2230 -	}
  7.2231 -
  7.2232 -	/* We can safely update without stopping the chip. */
  7.2233 -	tmp = rtl8139_rx_config | rx_mode;
  7.2234 -	if (tp->rx_config != tmp) {
  7.2235 -		RTL_W32_F (RxConfig, tmp);
  7.2236 -		tp->rx_config = tmp;
  7.2237 -	}
  7.2238 -	RTL_W32_F (MAR0 + 0, mc_filter[0]);
  7.2239 -	RTL_W32_F (MAR0 + 4, mc_filter[1]);
  7.2240 -}
  7.2241 -
  7.2242 -static void rtl8139_set_rx_mode (struct net_device *dev)
  7.2243 -{
  7.2244 -	unsigned long flags;
  7.2245 -	struct rtl8139_private *tp = dev->priv;
  7.2246 -
  7.2247 -	spin_lock_irqsave (&tp->lock, flags);
  7.2248 -	__set_rx_mode(dev);
  7.2249 -	spin_unlock_irqrestore (&tp->lock, flags);
  7.2250 -}
  7.2251 -
  7.2252 -#ifdef CONFIG_PM
  7.2253 -
  7.2254 -static int rtl8139_suspend (struct pci_dev *pdev, u32 state)
  7.2255 -{
  7.2256 -	struct net_device *dev = pci_get_drvdata (pdev);
  7.2257 -	struct rtl8139_private *tp = dev->priv;
  7.2258 -	void *ioaddr = tp->mmio_addr;
  7.2259 -	unsigned long flags;
  7.2260 -
  7.2261 -	if (!netif_running (dev))
  7.2262 -		return 0;
  7.2263 -
  7.2264 -	netif_device_detach (dev);
  7.2265 -
  7.2266 -	spin_lock_irqsave (&tp->lock, flags);
  7.2267 -
  7.2268 -	/* Disable interrupts, stop Tx and Rx. */
  7.2269 -	RTL_W16 (IntrMask, 0);
  7.2270 -	RTL_W8 (ChipCmd, 0);
  7.2271 -
  7.2272 -	/* Update the error counts. */
  7.2273 -	tp->stats.rx_missed_errors += RTL_R32 (RxMissed);
  7.2274 -	RTL_W32 (RxMissed, 0);
  7.2275 -
  7.2276 -	spin_unlock_irqrestore (&tp->lock, flags);
  7.2277 -	return 0;
  7.2278 -}
  7.2279 -
  7.2280 -
  7.2281 -static int rtl8139_resume (struct pci_dev *pdev)
  7.2282 -{
  7.2283 -	struct net_device *dev = pci_get_drvdata (pdev);
  7.2284 -
  7.2285 -	if (!netif_running (dev))
  7.2286 -		return 0;
  7.2287 -	netif_device_attach (dev);
  7.2288 -	rtl8139_hw_start (dev);
  7.2289 -	return 0;
  7.2290 -}
  7.2291 -
  7.2292 -#endif /* CONFIG_PM */
  7.2293 -
  7.2294 -
  7.2295 -static struct pci_driver rtl8139_pci_driver = {
  7.2296 -	name:		DRV_NAME,
  7.2297 -	id_table:	rtl8139_pci_tbl,
  7.2298 -	probe:		rtl8139_init_one,
  7.2299 -	remove:		__devexit_p(rtl8139_remove_one),
  7.2300 -#ifdef CONFIG_PM
  7.2301 -	suspend:	rtl8139_suspend,
  7.2302 -	resume:		rtl8139_resume,
  7.2303 -#endif /* CONFIG_PM */
  7.2304 -};
  7.2305 -
  7.2306 -
  7.2307 -static int __init rtl8139_init_module (void)
  7.2308 -{
  7.2309 -	/* when we're a module, we always print a version message,
  7.2310 -	 * even if no 8139 board is found.
  7.2311 -	 */
  7.2312 -#ifdef MODULE
  7.2313 -	printk (KERN_INFO RTL8139_DRIVER_NAME "\n");
  7.2314 -#endif
  7.2315 -
  7.2316 -	return pci_module_init (&rtl8139_pci_driver);
  7.2317 -}
  7.2318 -
  7.2319 -
  7.2320 -static void __exit rtl8139_cleanup_module (void)
  7.2321 -{
  7.2322 -	pci_unregister_driver (&rtl8139_pci_driver);
  7.2323 -}
  7.2324 -
  7.2325 -
  7.2326 -module_init(rtl8139_init_module);
  7.2327 -module_exit(rtl8139_cleanup_module);
     8.1 --- a/xen-2.4.16/drivers/net/eepro100.c	Wed Feb 05 13:56:14 2003 +0000
     8.2 +++ b/xen-2.4.16/drivers/net/eepro100.c	Thu Feb 06 16:31:29 2003 +0000
     8.3 @@ -43,12 +43,15 @@ static int rxdmacount /* = 0 */;
     8.4  
     8.5  /* Set the copy breakpoint for the copy-only-tiny-buffer Rx method.
     8.6     Lower values use more memory, but are faster. */
     8.7 -#if defined(__alpha__) || defined(__sparc__) || defined(__mips__) || \
     8.8 +/*#if defined(__alpha__) || defined(__sparc__) || defined(__mips__) || \
     8.9      defined(__arm__)
    8.10  static int rx_copybreak = 1518;
    8.11  #else
    8.12  static int rx_copybreak = 200;
    8.13 -#endif
    8.14 +#endif*/
    8.15 +
    8.16 +/* Xen doesn't do rx_copybreak in drivers. */
    8.17 +static int rx_copybreak = 0;
    8.18  
    8.19  /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
    8.20  static int max_interrupt_work = 20;
     9.1 --- a/xen-2.4.16/drivers/net/pcnet32.c	Wed Feb 05 13:56:14 2003 +0000
     9.2 +++ b/xen-2.4.16/drivers/net/pcnet32.c	Thu Feb 06 16:31:29 2003 +0000
     9.3 @@ -66,7 +66,7 @@ static int tx_start = 1; /* Mapping -- 0
     9.4  static struct net_device *pcnet32_dev;
     9.5  
     9.6  static const int max_interrupt_work = 80;
     9.7 -static const int rx_copybreak = 200;
     9.8 +static const int rx_copybreak = 0; /* 200; Xen doesn't do in-driver copybreak. */
     9.9  
    9.10  #define PORT_AUI      0x00
    9.11  #define PORT_10BT     0x01
    10.1 --- a/xen-2.4.16/drivers/net/tulip/interrupt.c	Wed Feb 05 13:56:14 2003 +0000
    10.2 +++ b/xen-2.4.16/drivers/net/tulip/interrupt.c	Thu Feb 06 16:31:29 2003 +0000
    10.3 @@ -170,9 +170,9 @@ static int tulip_rx(struct net_device *d
    10.4  #endif
    10.5  			/* Check if the packet is long enough to accept without copying
    10.6  			   to a minimally-sized skbuff. */
    10.7 -			//if (pkt_len < tulip_rx_copybreak
    10.8 -			//	&& (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
    10.9 -                        if (0) {
   10.10 +			if (pkt_len < tulip_rx_copybreak
   10.11 +				&& (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
   10.12 +                        //if (0) {
   10.13  				skb->dev = dev;
   10.14  				skb_reserve(skb, 2);	/* 16 byte align the IP header */
   10.15  				pci_dma_sync_single(tp->pdev,
    11.1 --- a/xen-2.4.16/drivers/net/tulip/tulip_core.c	Wed Feb 05 13:56:14 2003 +0000
    11.2 +++ b/xen-2.4.16/drivers/net/tulip/tulip_core.c	Thu Feb 06 16:31:29 2003 +0000
    11.3 @@ -60,13 +60,16 @@ const char * const medianame[32] = {
    11.4  };
    11.5  
    11.6  /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
    11.7 -#if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \
    11.8 +/*#if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \
    11.9  	|| defined(__sparc_) || defined(__ia64__) \
   11.10  	|| defined(__sh__) || defined(__mips__)
   11.11  static int rx_copybreak = 1518;
   11.12  #else
   11.13  static int rx_copybreak = 100;
   11.14  #endif
   11.15 +*/
   11.16 +/* Xen doesn't do rx_copybreak in drivers. */
   11.17 +static int rx_copybreak = 0;
   11.18  
   11.19  /*
   11.20    Set the bus performance register.
    12.1 --- a/xen-2.4.16/include/xeno/mm.h	Wed Feb 05 13:56:14 2003 +0000
    12.2 +++ b/xen-2.4.16/include/xeno/mm.h	Thu Feb 06 16:31:29 2003 +0000
    12.3 @@ -89,7 +89,7 @@ typedef struct pfn_info {
    12.4   * references exist of teh current type. A change in type can only occur
    12.5   * when type_count == 0.
    12.6   */
    12.7 -#define PG_type_mask        (7<<24) /* bits 24-26 */
    12.8 +#define PG_type_mask        (15<<24) /* bits 24-27 */
    12.9  #define PGT_none            (0<<24) /* no special uses of this page */
   12.10  #define PGT_l1_page_table   (1<<24) /* using this page as an L1 page table? */
   12.11  #define PGT_l2_page_table   (2<<24) /* using this page as an L2 page table? */
   12.12 @@ -98,6 +98,7 @@ typedef struct pfn_info {
   12.13  #define PGT_gdt_page        (5<<24) /* using this page in a GDT? */
   12.14  #define PGT_ldt_page        (6<<24) /* using this page in an LDT? */
   12.15  #define PGT_writeable_page  (7<<24) /* has writable mappings of this page? */
   12.16 +#define PGT_net_rx_buf      (8<<24) /* this page has been pirated by the net code. */
   12.17  
   12.18  #define PageSlab(page)		test_bit(PG_slab, &(page)->flags)
   12.19  #define PageSetSlab(page)	set_bit(PG_slab, &(page)->flags)
   12.20 @@ -120,6 +121,7 @@ void init_frametable(unsigned long nr_pa
   12.21   * will use it to store a "physical" frame number to give the appearance of
   12.22   * contiguous (or near contiguous) physical memory.
   12.23   */
   12.24 +#undef machine_to_phys_mapping
   12.25  #define machine_to_phys_mapping ((unsigned long *)RDWR_MPT_VIRT_START)
   12.26  
   12.27  /* Part of the domain API. */
    13.1 --- a/xen-2.4.16/net/dev.c	Wed Feb 05 13:56:14 2003 +0000
    13.2 +++ b/xen-2.4.16/net/dev.c	Thu Feb 06 16:31:29 2003 +0000
    13.3 @@ -714,8 +714,7 @@ void deliver_packet(struct sk_buff *skb,
    13.4              if ( (skb->len + ETH_HLEN) < rx->size )
    13.5                  rx->size = skb->len + ETH_HLEN;
    13.6                          
    13.7 -            if (rx->flush_count == tlb_flush_count[smp_processor_id()])
    13.8 -                flush_tlb_all();
    13.9 +            
   13.10              
   13.11              g_pte = map_domain_mem(rx->addr);
   13.12  
   13.13 @@ -723,15 +722,21 @@ void deliver_packet(struct sk_buff *skb,
   13.14              h_pfn = skb->pf;
   13.15  
   13.16              //flip and/or set relevant pf_info fields.
   13.17 -            tmp = g_pfn->next; g_pfn->next = h_pfn->next; h_pfn->next = tmp;
   13.18 -            tmp = g_pfn->prev; g_pfn->prev = h_pfn->prev; h_pfn->prev = tmp;
   13.19 +            //tmp = g_pfn->next; g_pfn->next = h_pfn->next; h_pfn->next = tmp;
   13.20 +            //tmp = g_pfn->prev; g_pfn->prev = h_pfn->prev; h_pfn->prev = tmp;
   13.21              tmp = g_pfn->flags; g_pfn->flags = h_pfn->flags; h_pfn->flags = tmp;
   13.22 -            h_pfn->tot_count = 1;
   13.23 -            h_pfn->type_count = g_pfn->type_count;
   13.24 +            h_pfn->tot_count = h_pfn->type_count = 1;
   13.25              g_pfn->tot_count = g_pfn->type_count = 0;
   13.26 -            h_pfn->flags = current->domain | PGT_l1_page_table;
   13.27 -            g_pfn->flags = PGT_l1_page_table;
   13.28 +            h_pfn->flags = g_pfn->flags & ~ PG_type_mask;
   13.29 +            if (*g_pte & _PAGE_RW) h_pfn->flags |= PGT_writeable_page;
   13.30 +            g_pfn->flags = 0;
   13.31              //point guest pte at the new page:
   13.32 +
   13.33 +//printk("newmpfn: %lx, old mpfn: %lx,  old:(%lx) new:(%lx)\n", h_pfn - frame_table, *g_pte >> PAGE_SHIFT, machine_to_phys_mapping[h_pfn - frame_table], machine_to_phys_mapping[*g_pte >> PAGE_SHIFT]);
   13.34 +
   13.35 +            machine_to_phys_mapping[h_pfn - frame_table] 
   13.36 +                    = machine_to_phys_mapping[g_pfn - frame_table];
   13.37 +
   13.38              *g_pte = (*g_pte & ~PAGE_MASK) 
   13.39                  | (((h_pfn - frame_table) << PAGE_SHIFT) & PAGE_MASK);
   13.40              *g_pte |= _PAGE_PRESENT;
   13.41 @@ -1000,6 +1005,9 @@ void update_shared_ring(void)
   13.42              shadow_ring->rx_idx = RX_RING_INC(shadow_ring->rx_idx);
   13.43              net_ring->rx_cons   = RX_RING_INC(net_ring->rx_cons);
   13.44  
   13.45 +            if (rx->flush_count == tlb_flush_count[smp_processor_id()])
   13.46 +                __flush_tlb();
   13.47 +
   13.48              if ( net_ring->rx_cons == net_ring->rx_event )
   13.49                  set_bit(_EVENT_NET_RX_FOR_VIF(nvif), &s->events);
   13.50              
   13.51 @@ -1124,8 +1132,8 @@ void flush_rx_queue(void)
   13.52                          h_pfn = skb->pf;
   13.53  
   13.54  
   13.55 -                        tmp = g_pfn->next; g_pfn->next = h_pfn->next; h_pfn->next = tmp;
   13.56 -                        tmp = g_pfn->prev; g_pfn->prev = h_pfn->prev; h_pfn->prev = tmp;
   13.57 +                        //tmp = g_pfn->next; g_pfn->next = h_pfn->next; h_pfn->next = tmp;
   13.58 +                        //tmp = g_pfn->prev; g_pfn->prev = h_pfn->prev; h_pfn->prev = tmp;
   13.59                          tmp = g_pfn->flags; g_pfn->flags = h_pfn->flags; h_pfn->flags = tmp;
   13.60                          
   13.61                          h_pfn->tot_count = 1;
   13.62 @@ -2244,23 +2252,39 @@ printk("LOCAL DELIVERY!\n");
   13.63                  pfn = rx->addr >> PAGE_SHIFT;
   13.64                  page = frame_table + pfn;
   13.65                  
   13.66 -                shadow_ring->rx_ring[i].status = RING_STATUS_OK;
   13.67 +                shadow_ring->rx_ring[i].status = RING_STATUS_BAD_PAGE;
   13.68  
   13.69 -               if  (!(page->flags & PGT_l1_page_table) 
   13.70 -                    || !((page->flags & PG_domain_mask) == current->domain))
   13.71 -                       shadow_ring->rx_ring[i].status = RING_STATUS_BAD_PAGE; 
   13.72 +                if  ( page->flags != (PGT_l1_page_table | current->domain) ) 
   13.73 +                {
   13.74 +BUG();
   13.75 +                       continue;
   13.76 +                }
   13.77  
   13.78  
   13.79                  g_pte = map_domain_mem(rx->addr);
   13.80  
   13.81                  if (!(*g_pte & _PAGE_PRESENT))
   13.82 -                        shadow_ring->rx_ring[i].status = RING_STATUS_BAD_PAGE;
   13.83 +                {
   13.84 +BUG();
   13.85 +                        unmap_domain_mem(g_pte);
   13.86 +                        continue;
   13.87 +                }
   13.88 +                
   13.89                  page = (*g_pte >> PAGE_SHIFT) + frame_table;
   13.90 +                
   13.91                  if (page->tot_count != 1) 
   13.92 -                        shadow_ring->rx_ring[i].status = RING_STATUS_BAD_PAGE;
   13.93 +                {
   13.94 +printk("!\n");
   13.95 +                        unmap_domain_mem(g_pte);
   13.96 +                        continue;
   13.97 +                }
   13.98                  
   13.99 +                // The pte they passed was good, so we take it away from them.
  13.100 +                shadow_ring->rx_ring[i].status = RING_STATUS_OK;
  13.101                  *g_pte &= ~_PAGE_PRESENT;
  13.102 +                page->flags = (page->flags & ~PG_type_mask) | PGT_net_rx_buf;
  13.103                  rx->flush_count = tlb_flush_count[smp_processor_id()];
  13.104 +
  13.105                  unmap_domain_mem(g_pte);
  13.106              }
  13.107          }
    14.1 --- a/xen-2.4.16/net/skbuff.c	Wed Feb 05 13:56:14 2003 +0000
    14.2 +++ b/xen-2.4.16/net/skbuff.c	Thu Feb 06 16:31:29 2003 +0000
    14.3 @@ -163,7 +163,7 @@ static inline u8 *alloc_skb_data_page(st
    14.4          pf = list_entry(list_ptr, struct pfn_info, list);
    14.5          pf->flags = 0; // owned by dom0
    14.6          list_del(&pf->list);
    14.7 -        pf->next = pf->prev = (pf - frame_table);
    14.8 +        //pf->next = pf->prev = (pf - frame_table);
    14.9          free_pfns--;
   14.10  
   14.11          spin_unlock_irqrestore(&free_list_lock, flags);
    15.1 --- a/xenolinux-2.4.16-sparse/arch/xeno/drivers/network/network.c	Wed Feb 05 13:56:14 2003 +0000
    15.2 +++ b/xenolinux-2.4.16-sparse/arch/xeno/drivers/network/network.c	Thu Feb 06 16:31:29 2003 +0000
    15.3 @@ -21,6 +21,7 @@
    15.4  #include <linux/skbuff.h>
    15.5  #include <linux/init.h>
    15.6  
    15.7 +#include <asm/io.h>
    15.8  #include <net/sock.h>
    15.9  
   15.10  #define NET_TX_IRQ _EVENT_NET_TX
   15.11 @@ -48,6 +49,8 @@ static void cleanup_module(void);
   15.12  
   15.13  static struct list_head dev_list;
   15.14  
   15.15 +static unsigned int net_countx;
   15.16 +
   15.17  /*
   15.18   * RX RING:   RX_IDX <= rx_cons <= rx_prod
   15.19   * TX RING:   TX_IDX <= tx_cons <= tx_prod
   15.20 @@ -72,7 +75,7 @@ struct net_private
   15.21  static int network_open(struct net_device *dev)
   15.22  {
   15.23      struct net_private *np = dev->priv;
   15.24 -    int error;
   15.25 +    int error = 0;
   15.26      char *rxlabel, *txlabel;
   15.27  
   15.28      // This is inevitably not the right way to allocate a couple of static strings.
   15.29 @@ -179,13 +182,59 @@ static void network_tx_buf_gc(struct net
   15.30      spin_unlock_irqrestore(&np->tx_lock, flags);
   15.31  }
   15.32  
   15.33 +inline unsigned long get_ppte(unsigned long addr)
   15.34 +{
   15.35 +        unsigned long ppte = 0xdeadbeef;
   15.36 +        pgd_t *pgd; pmd_t *pmd; pte_t *ptep;
   15.37 +        pgd = pgd_offset_k(addr);
   15.38  
   15.39 +        if (pgd_none(*pgd) || pgd_bad(*pgd)) BUG();
   15.40 +        
   15.41 +        pmd = pmd_offset(pgd, addr);
   15.42 +        if (pmd_none(*pmd)) BUG(); 
   15.43 +        if (pmd_bad(*pmd)) BUG();
   15.44 +        
   15.45 +        ptep = pte_offset(pmd, addr);
   15.46 +        ppte = (unsigned long)phys_to_machine(virt_to_phys(ptep));
   15.47 +
   15.48 +        return ppte;
   15.49 +}
   15.50 +/*
   15.51 +static void validate_free_list(void)
   15.52 +{
   15.53 +    unsigned long addr, ppfn, mpfn, mpfn2, flags;
   15.54 +    struct list_head *i;
   15.55 +    struct net_page_info *np;
   15.56 +
   15.57 +    printk(KERN_ALERT "Walking free pages:\n");
   15.58 +   
   15.59 +    spin_lock_irqsave(&net_page_list_lock, flags);
   15.60 +    
   15.61 +    list_for_each(i, &net_page_list) 
   15.62 +    {
   15.63 +        np = list_entry(i, struct net_page_info, list);
   15.64 +        addr = np->virt_addr;
   15.65 +        ppfn = virt_to_phys(addr) >> PAGE_SHIFT;
   15.66 +        mpfn = get_ppte(addr);
   15.67 +        mpfn2 = phys_to_machine_mapping[ppfn];
   15.68 +
   15.69 +        mpfn = (*(unsigned long *)phys_to_virt(machine_to_phys(mpfn))) >> PAGE_SHIFT;
   15.70 +        if (mpfn != mpfn2) printk(KERN_ALERT "mpfn %lu != %lu\n", mpfn, mpfn2);
   15.71 +
   15.72 +        if (machine_to_phys_mapping[mpfn] != ppfn) printk(KERN_ALERT "ppfn %lu != %lu\n", machine_to_phys_mapping[mpfn], ppfn);
   15.73 +    }
   15.74 +
   15.75 +    spin_unlock_irqrestore(&net_page_list_lock, flags);
   15.76 +    
   15.77 +}
   15.78 +*/
   15.79  static void network_alloc_rx_buffers(struct net_device *dev)
   15.80  {
   15.81      unsigned int i;
   15.82      struct net_private *np = dev->priv;
   15.83      struct sk_buff *skb;
   15.84      unsigned int end = RX_RING_ADD(np->rx_idx, RX_MAX_ENTRIES);
   15.85 +    
   15.86  
   15.87      for ( i = np->net_ring->rx_prod; i != end; i = RX_RING_INC(i) )
   15.88      {
   15.89 @@ -194,8 +243,9 @@ static void network_alloc_rx_buffers(str
   15.90          skb->dev = dev;
   15.91          //skb_reserve(skb, 2); /* word align the IP header */
   15.92          np->rx_skb_ring[i] = skb;
   15.93 -        np->net_ring->rx_ring[i].addr = (unsigned long)skb->net_page->ppte; //data;
   15.94 +        np->net_ring->rx_ring[i].addr = get_ppte(skb->head); 
   15.95          np->net_ring->rx_ring[i].size = RX_BUF_SIZE - 16; /* arbitrary */
   15.96 +//printk(KERN_ALERT "[%p]\n", phys_to_machine(virt_to_phys(skb->page_ptr)));
   15.97      }
   15.98  
   15.99      np->net_ring->rx_prod = i;
  15.100 @@ -273,6 +323,8 @@ static void network_rx_int(int irq, void
  15.101      struct net_private *np = dev->priv;
  15.102      struct sk_buff *skb;
  15.103      
  15.104 +    /*if (net_countx++ % 100 == 0) validate_free_list();*/
  15.105 +    
  15.106   again:
  15.107      for ( i = np->rx_idx; i != np->net_ring->rx_cons; i = RX_RING_INC(i) )
  15.108      {
  15.109 @@ -283,7 +335,14 @@ static void network_rx_int(int irq, void
  15.110                  continue;
  15.111          }
  15.112          skb = np->rx_skb_ring[i];
  15.113 -        
  15.114 +
  15.115 +//printk(KERN_ALERT "[%u]: ptmm[%lx] old:(%lx) new:(%lx)\n", i , virt_to_phys(skb->head) >> PAGE_SHIFT, phys_to_machine_mapping[virt_to_phys(skb->head) >> PAGE_SHIFT], (*(unsigned long *)phys_to_virt(machine_to_phys(np->net_ring->rx_ring[i].addr))) >> PAGE_SHIFT);
  15.116 +
  15.117 +        phys_to_machine_mapping[virt_to_phys(skb->head) >> PAGE_SHIFT] =
  15.118 +            (*(unsigned long *)phys_to_virt(
  15.119 +                    machine_to_phys(np->net_ring->rx_ring[i].addr))
  15.120 +             ) >> PAGE_SHIFT;
  15.121 +
  15.122          skb_put(skb, np->net_ring->rx_ring[i].size);
  15.123          skb->protocol = eth_type_trans(skb, dev);
  15.124          np->stats.rx_packets++;
    16.1 --- a/xenolinux-2.4.16-sparse/include/asm-xeno/io.h	Wed Feb 05 13:56:14 2003 +0000
    16.2 +++ b/xenolinux-2.4.16-sparse/include/asm-xeno/io.h	Thu Feb 06 16:31:29 2003 +0000
    16.3 @@ -78,17 +78,6 @@ static inline void * phys_to_virt(unsign
    16.4   * These are equally trivial.
    16.5   */
    16.6  
    16.7 -static inline unsigned long virt_to_mach(volatile void * address)
    16.8 -{
    16.9 -       return __pa(address) + (unsigned long) start_info.phys_base;
   16.10 -}
   16.11 -
   16.12 -static inline void *mach_to_virt(unsigned long address)
   16.13 -{
   16.14 -        return __va(address) - (unsigned long) start_info.phys_base;
   16.15 -}
   16.16 -
   16.17 -
   16.18  /*
   16.19   * Change "struct page" to physical address.
   16.20   */
    17.1 --- a/xenolinux-2.4.16-sparse/include/linux/skbuff.h	Wed Feb 05 13:56:14 2003 +0000
    17.2 +++ b/xenolinux-2.4.16-sparse/include/linux/skbuff.h	Thu Feb 06 16:31:29 2003 +0000
    17.3 @@ -43,7 +43,8 @@
    17.4  #define SKB_ZERO_COPY       1
    17.5  
    17.6  #define NUM_NET_PAGES       9 // about 1Meg of buffers. (2^9)
    17.7 -struct net_page_info {
    17.8 +
    17.9 +/*struct net_page_info {
   17.10          struct list_head list;
   17.11          unsigned long   virt_addr;
   17.12          unsigned long   ppte;
   17.13 @@ -54,7 +55,7 @@ extern struct net_page_info *net_page_ta
   17.14  extern struct list_head net_page_list;
   17.15  extern spinlock_t net_page_list_lock;
   17.16  extern unsigned int net_pages;
   17.17 -
   17.18 +*/
   17.19  /* End zero copy additions */
   17.20  
   17.21  #define HAVE_ALLOC_SKB		/* For the drivers to know */
    18.1 --- a/xenolinux-2.4.16-sparse/net/core/skbuff.c	Wed Feb 05 13:56:14 2003 +0000
    18.2 +++ b/xenolinux-2.4.16-sparse/net/core/skbuff.c	Thu Feb 06 16:31:29 2003 +0000
    18.3 @@ -64,12 +64,13 @@
    18.4  #include <asm/system.h>
    18.5  
    18.6  /* zc globals: */
    18.7 +/*
    18.8  char *net_page_chunk;
    18.9  struct net_page_info *net_page_table;
   18.10  struct list_head net_page_list;
   18.11  spinlock_t net_page_list_lock = SPIN_LOCK_UNLOCKED;
   18.12  unsigned int net_pages;
   18.13 -
   18.14 +*/
   18.15  
   18.16  
   18.17  int sysctl_hot_list_len = 128;
   18.18 @@ -229,7 +230,7 @@ nohead:
   18.19  }
   18.20  
   18.21  /* begin zc code additions: */
   18.22 -
   18.23 +/*
   18.24  void init_net_pages(unsigned long order_pages)
   18.25  {
   18.26          int i;
   18.27 @@ -248,16 +249,16 @@ void init_net_pages(unsigned long order_
   18.28                  np->virt_addr = (unsigned long)net_page_chunk + (i * PAGE_SIZE);
   18.29  
   18.30                  // now fill the pte pointer:
   18.31 -                np->ppte = 0xdeadbeef;
   18.32 -                pgd = pgd_offset_k(np->virt_addr);
   18.33 -                if (pgd_none(*pgd) || pgd_bad(*pgd)) BUG();
   18.34 +                //np->ppte = 0xdeadbeef;
   18.35 +                //pgd = pgd_offset_k(np->virt_addr);
   18.36 +                //if (pgd_none(*pgd) || pgd_bad(*pgd)) BUG();
   18.37  
   18.38 -                if (pmd_none(*pmd)) BUG(); 
   18.39 -                if (pmd_bad(*pmd)) BUG();
   18.40 +                //if (pmd_none(*pmd)) BUG(); 
   18.41 +                //if (pmd_bad(*pmd)) BUG();
   18.42  
   18.43 -                ptep = pte_offset(pmd, np->virt_addr);
   18.44 -                np->ppte = (unsigned long)virt_to_mach(ptep);
   18.45 -
   18.46 +                //ptep = pte_offset(pmd, np->virt_addr);
   18.47 +                //np->ppte = phys_to_machine(virt_to_phys(ptep));
   18.48 +                
   18.49                  list_add_tail(&np->list, &net_page_list);
   18.50          }
   18.51          net_pages = nr_pages;
   18.52 @@ -267,6 +268,7 @@ void init_net_pages(unsigned long order_
   18.53  
   18.54  struct net_page_info *get_net_page(void)
   18.55  {
   18.56 +
   18.57      struct list_head *list_ptr;
   18.58      struct net_page_info *np;
   18.59      unsigned long flags;
   18.60 @@ -301,7 +303,7 @@ void free_net_page(struct net_page_info 
   18.61      spin_unlock_irqrestore(&net_page_list_lock, flags);
   18.62  
   18.63  }
   18.64 -
   18.65 +*/
   18.66  struct sk_buff *alloc_zc_skb(unsigned int size,int gfp_mask)
   18.67  {
   18.68  	struct sk_buff *skb;
   18.69 @@ -332,12 +334,13 @@ struct sk_buff *alloc_zc_skb(unsigned in
   18.70                  printk("alloc_zc_skb called with unruly size.\n");
   18.71                  size = PAGE_SIZE;
   18.72          }
   18.73 -	skb->net_page = get_net_page();
   18.74 +	/*skb->net_page = get_net_page();
   18.75          if (skb->net_page == NULL)
   18.76          {
   18.77                  goto nodata;
   18.78          }
   18.79 -        data = (u8 *)skb->net_page->virt_addr;
   18.80 +        data = (u8 *)skb->net_page->virt_addr;*/
   18.81 +        data = (char *)__get_free_page(gfp_mask);
   18.82  	if (data == NULL)
   18.83  		goto nodata;
   18.84  	/* XXX: does not include slab overhead */ 
   18.85 @@ -443,7 +446,9 @@ static void skb_release_data(struct sk_b
   18.86                  {
   18.87  		    kfree(skb->head);
   18.88                  } else {// SKB_ZERO_COPY
   18.89 -                    free_net_page(skb->net_page);
   18.90 +                    //free_net_page(skb->net_page);
   18.91 +//printk(KERN_ALERT "<%p>\n", phys_to_machine(virt_to_phys(skb->head)));
   18.92 +                    free_page((void *)skb->head);
   18.93                  }
   18.94  	}
   18.95  
   18.96 @@ -559,7 +564,7 @@ struct sk_buff *skb_clone(struct sk_buff
   18.97  	C(tc_index);
   18.98  #endif
   18.99          C(skb_type);
  18.100 -        C(net_page);
  18.101 +        //C(net_page);
  18.102  	atomic_inc(&(skb_shinfo(skb)->dataref));
  18.103  	skb->cloned = 1;
  18.104  #ifdef CONFIG_NETFILTER
  18.105 @@ -1361,7 +1366,7 @@ void __init skb_init(void)
  18.106  	if (!skbuff_head_cache)
  18.107  		panic("cannot create skbuff cache");
  18.108  
  18.109 -        init_net_pages(NUM_NET_PAGES);
  18.110 +        //init_net_pages(NUM_NET_PAGES);
  18.111  
  18.112  	for (i=0; i<NR_CPUS; i++)
  18.113  		skb_queue_head_init(&skb_head_pool[i].list);