ia64/xen-unstable

changeset 135:d3aad71a5893

bitkeeper revision 1.22.2.11 (3e465c080oDmXRHMT2ue0NRHdbJL3g)

ne.c, Makefile, 8390.h, 8390.c, in.h, config.h, kernel.c, Rules.mk:
Ported NE2K driver for Bochs development. Also some minor cleanups.
ne.c, Makefile, 8390.h, 8390.c:
new file
author kaf24@labyrinth.cl.cam.ac.uk
date Sun Feb 09 13:47:52 2003 +0000 (2003-02-09)
parents dcbfc020bfa9
children 0e7853339ecd
files .rootkeys xen-2.4.16/Makefile xen-2.4.16/arch/i386/Rules.mk xen-2.4.16/common/kernel.c xen-2.4.16/drivers/net/Makefile xen-2.4.16/drivers/net/ne/8390.c xen-2.4.16/drivers/net/ne/8390.h xen-2.4.16/drivers/net/ne/Makefile xen-2.4.16/drivers/net/ne/ne.c xen-2.4.16/include/xeno/config.h xen-2.4.16/include/xeno/in.h
line diff
     1.1 --- a/.rootkeys	Sun Feb 09 11:48:49 2003 +0000
     1.2 +++ b/.rootkeys	Sun Feb 09 13:47:52 2003 +0000
     1.3 @@ -83,6 +83,10 @@ 3e4540ccvQ9Dtoh9tV-L3ULUwN9X7g xen-2.4.1
     1.4  3e4540cc3t7_y-YLeyMG2pX9xtdXPA xen-2.4.16/drivers/net/e1000/e1000_osdep.h
     1.5  3e4540cct_8Ig-Y1W_vM2gS_u7mC0A xen-2.4.16/drivers/net/e1000/e1000_param.c
     1.6  3ddb79c0GejJrp1U6W4G6dYi-RiH4A xen-2.4.16/drivers/net/eepro100.c
     1.7 +3e465c00t2nochqR27eEY_FBjxsUCw xen-2.4.16/drivers/net/ne/8390.c
     1.8 +3e465c00AIRmk20x1vYETtnL71eGvA xen-2.4.16/drivers/net/ne/8390.h
     1.9 +3e465c00UIvPTAtAcgcQWCVFa2bwww xen-2.4.16/drivers/net/ne/Makefile
    1.10 +3e465c00rWSHiXmHuOWLRf7r2n8S3g xen-2.4.16/drivers/net/ne/ne.c
    1.11  3ddb79bfKvn9mt0kofpkw0QaWjxO6A xen-2.4.16/drivers/net/net_init.c
    1.12  3ddb79c0fQgORkFlqWZdP-6cDHyFIQ xen-2.4.16/drivers/net/pcnet32.c
    1.13  3ddb79bf_CBcu3QWYwq4bNAOnM2RqQ xen-2.4.16/drivers/net/setup.c
     2.1 --- a/xen-2.4.16/Makefile	Sun Feb 09 11:48:49 2003 +0000
     2.2 +++ b/xen-2.4.16/Makefile	Sun Feb 09 13:47:52 2003 +0000
     2.3 @@ -5,7 +5,7 @@ include Rules.mk
     2.4  
     2.5  default: $(TARGET)
     2.6  	gzip -f -9 < $(TARGET) > $(TARGET).gz
     2.7 -	objdump -D -S image >image.s
     2.8 +#	objdump -D -S image >image.s
     2.9  
    2.10  install: $(TARGET)
    2.11  	gzip -f -9 < $(TARGET) > $(TARGET).gz
     3.1 --- a/xen-2.4.16/arch/i386/Rules.mk	Sun Feb 09 11:48:49 2003 +0000
     3.2 +++ b/xen-2.4.16/arch/i386/Rules.mk	Sun Feb 09 13:47:52 2003 +0000
     3.3 @@ -8,7 +8,7 @@ MONITOR_BASE := 0xFC500000
     3.4  # Bootloader should load monitor to this real address
     3.5  LOAD_BASE    := 0x00100000
     3.6  CFLAGS  := -nostdinc -fno-builtin -O3 -Wall -DMONITOR_BASE=$(MONITOR_BASE) 
     3.7 -CFLAGS  += -I$(BASEDIR)/include -D__KERNEL__ -DNDEBUG
     3.8 +CFLAGS  += -fomit-frame-pointer -I$(BASEDIR)/include -D__KERNEL__ -DNDEBUG
     3.9  LDFLAGS := -T xeno.lds -N
    3.10  
    3.11  
     4.1 --- a/xen-2.4.16/common/kernel.c	Sun Feb 09 11:48:49 2003 +0000
     4.2 +++ b/xen-2.4.16/common/kernel.c	Sun Feb 09 13:47:52 2003 +0000
     4.3 @@ -43,6 +43,7 @@ void start_of_day(void);
     4.4  unsigned long opt_ipbase=0, opt_nfsserv=0, opt_gateway=0, opt_netmask=0;
     4.5  unsigned char opt_nfsroot[50]="";
     4.6  unsigned int opt_dom0_mem = 16000; /* default kbytes for DOM0 */
     4.7 +unsigned int opt_ne_base = 0; /* NE2k NICs cannot be probed */
     4.8  enum { OPT_IP, OPT_STR, OPT_UINT };
     4.9  static struct {
    4.10      unsigned char *name;
    4.11 @@ -55,6 +56,7 @@ static struct {
    4.12      { "netmask",  OPT_IP,   &opt_netmask },
    4.13      { "nfsroot",  OPT_STR,  &opt_nfsroot },
    4.14      { "dom0_mem", OPT_UINT, &opt_dom0_mem }, 
    4.15 +    { "ne_base",  OPT_UINT, &opt_ne_base },
    4.16      { NULL,       0,        NULL     }
    4.17  };
    4.18  
    4.19 @@ -143,7 +145,8 @@ void cmain (unsigned long magic, multibo
    4.20                      }
    4.21                      else /* opts[i].type == OPT_UINT */
    4.22                      {
    4.23 -                        *(unsigned int *)opts[i].var = simple_strtol(opt, (char **)&opt, 10);
    4.24 +                        *(unsigned int *)opts[i].var =
    4.25 +                            simple_strtol(opt, (char **)&opt, 0);
    4.26                      }
    4.27                      break;
    4.28                  }
     5.1 --- a/xen-2.4.16/drivers/net/Makefile	Sun Feb 09 11:48:49 2003 +0000
     5.2 +++ b/xen-2.4.16/drivers/net/Makefile	Sun Feb 09 13:47:52 2003 +0000
     5.3 @@ -2,11 +2,15 @@
     5.4  include $(BASEDIR)/Rules.mk
     5.5  
     5.6  default: $(OBJS)
     5.7 +	$(MAKE) -C ne
     5.8  	$(MAKE) -C tulip
     5.9  	$(MAKE) -C e1000
    5.10 -	$(LD) -r -o driver.o $(OBJS) tulip/tulip.o e1000/e1000.o
    5.11 +	$(LD) -r -o driver.o $(OBJS) tulip/tulip.o e1000/e1000.o ne/ne_drv.o
    5.12  
    5.13  clean:
    5.14 +	$(MAKE) -C ne clean
    5.15  	$(MAKE) -C tulip clean
    5.16  	$(MAKE) -C e1000 clean
    5.17  	rm -f *.o *~ core
    5.18 +
    5.19 +.PHONY: default clean
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/xen-2.4.16/drivers/net/ne/8390.c	Sun Feb 09 13:47:52 2003 +0000
     6.3 @@ -0,0 +1,1158 @@
     6.4 +/* 8390.c: A general NS8390 ethernet driver core for linux. */
     6.5 +/*
     6.6 +	Written 1992-94 by Donald Becker.
     6.7 +  
     6.8 +	Copyright 1993 United States Government as represented by the
     6.9 +	Director, National Security Agency.
    6.10 +
    6.11 +	This software may be used and distributed according to the terms
    6.12 +	of the GNU General Public License, incorporated herein by reference.
    6.13 +
    6.14 +	The author may be reached as becker@scyld.com, or C/O
    6.15 +	Scyld Computing Corporation
    6.16 +	410 Severn Ave., Suite 210
    6.17 +	Annapolis MD 21403
    6.18 +
    6.19 +  
    6.20 +  This is the chip-specific code for many 8390-based ethernet adaptors.
    6.21 +  This is not a complete driver, it must be combined with board-specific
    6.22 +  code such as ne.c, wd.c, 3c503.c, etc.
    6.23 +
    6.24 +  Seeing how at least eight drivers use this code, (not counting the
    6.25 +  PCMCIA ones either) it is easy to break some card by what seems like
    6.26 +  a simple innocent change. Please contact me or Donald if you think
    6.27 +  you have found something that needs changing. -- PG
    6.28 +
    6.29 +
    6.30 +  Changelog:
    6.31 +
    6.32 +  Paul Gortmaker	: remove set_bit lock, other cleanups.
    6.33 +  Paul Gortmaker	: add ei_get_8390_hdr() so we can pass skb's to 
    6.34 +			  ei_block_input() for eth_io_copy_and_sum().
    6.35 +  Paul Gortmaker	: exchange static int ei_pingpong for a #define,
    6.36 +			  also add better Tx error handling.
    6.37 +  Paul Gortmaker	: rewrite Rx overrun handling as per NS specs.
    6.38 +  Alexey Kuznetsov	: use the 8390's six bit hash multicast filter.
    6.39 +  Paul Gortmaker	: tweak ANK's above multicast changes a bit.
    6.40 +  Paul Gortmaker	: update packet statistics for v2.1.x
    6.41 +  Alan Cox		: support arbitary stupid port mappings on the
    6.42 +  			  68K Macintosh. Support >16bit I/O spaces
    6.43 +  Paul Gortmaker	: add kmod support for auto-loading of the 8390
    6.44 +			  module by all drivers that require it.
    6.45 +  Alan Cox		: Spinlocking work, added 'BUG_83C690'
    6.46 +  Paul Gortmaker	: Separate out Tx timeout code from Tx path.
    6.47 +
    6.48 +  Sources:
    6.49 +  The National Semiconductor LAN Databook, and the 3Com 3c503 databook.
    6.50 +
    6.51 +  */
    6.52 +
    6.53 +static const char version[] =
    6.54 +    "8390.c:v1.10cvs 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
    6.55 +
    6.56 +#include <xeno/module.h>
    6.57 +#include <xeno/kernel.h>
    6.58 +#include <xeno/sched.h>
    6.59 +//#include <xeno/fs.h>
    6.60 +#include <xeno/types.h>
    6.61 +//#include <xeno/ptrace.h>
    6.62 +#include <xeno/lib.h>
    6.63 +#include <asm/system.h>
    6.64 +#include <asm/uaccess.h>
    6.65 +#include <asm/bitops.h>
    6.66 +#include <asm/io.h>
    6.67 +#include <asm/irq.h>
    6.68 +#include <xeno/delay.h>
    6.69 +#include <xeno/errno.h>
    6.70 +//#include <xeno/fcntl.h>
    6.71 +#include <xeno/in.h>
    6.72 +#include <xeno/interrupt.h>
    6.73 +#include <xeno/init.h>
    6.74 +
    6.75 +#include <xeno/netdevice.h>
    6.76 +#include <xeno/etherdevice.h>
    6.77 +
    6.78 +#define NS8390_CORE
    6.79 +#include "8390.h"
    6.80 +
    6.81 +#define BUG_83C690
    6.82 +
    6.83 +/* These are the operational function interfaces to board-specific
    6.84 +   routines.
    6.85 +	void reset_8390(struct net_device *dev)
    6.86 +		Resets the board associated with DEV, including a hardware reset of
    6.87 +		the 8390.  This is only called when there is a transmit timeout, and
    6.88 +		it is always followed by 8390_init().
    6.89 +	void block_output(struct net_device *dev, int count, const unsigned char *buf,
    6.90 +					  int start_page)
    6.91 +		Write the COUNT bytes of BUF to the packet buffer at START_PAGE.  The
    6.92 +		"page" value uses the 8390's 256-byte pages.
    6.93 +	void get_8390_hdr(struct net_device *dev, struct e8390_hdr *hdr, int ring_page)
    6.94 +		Read the 4 byte, page aligned 8390 header. *If* there is a
    6.95 +		subsequent read, it will be of the rest of the packet.
    6.96 +	void block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
    6.97 +		Read COUNT bytes from the packet buffer into the skb data area. Start 
    6.98 +		reading from RING_OFFSET, the address as the 8390 sees it.  This will always
    6.99 +		follow the read of the 8390 header. 
   6.100 +*/
   6.101 +#define ei_reset_8390 (ei_local->reset_8390)
   6.102 +#define ei_block_output (ei_local->block_output)
   6.103 +#define ei_block_input (ei_local->block_input)
   6.104 +#define ei_get_8390_hdr (ei_local->get_8390_hdr)
   6.105 +
   6.106 +/* use 0 for production, 1 for verification, >2 for debug */
   6.107 +#ifndef ei_debug
   6.108 +int ei_debug = 1;
   6.109 +#endif
   6.110 +
   6.111 +/* Index to functions. */
   6.112 +static void ei_tx_intr(struct net_device *dev);
   6.113 +static void ei_tx_err(struct net_device *dev);
   6.114 +static void ei_tx_timeout(struct net_device *dev);
   6.115 +static void ei_receive(struct net_device *dev);
   6.116 +static void ei_rx_overrun(struct net_device *dev);
   6.117 +
   6.118 +/* Routines generic to NS8390-based boards. */
   6.119 +static void NS8390_trigger_send(struct net_device *dev, unsigned int length,
   6.120 +								int start_page);
   6.121 +static void set_multicast_list(struct net_device *dev);
   6.122 +static void do_set_multicast_list(struct net_device *dev);
   6.123 +
   6.124 +/*
   6.125 + *	SMP and the 8390 setup.
   6.126 + *
   6.127 + *	The 8390 isnt exactly designed to be multithreaded on RX/TX. There is
   6.128 + *	a page register that controls bank and packet buffer access. We guard
   6.129 + *	this with ei_local->page_lock. Nobody should assume or set the page other
   6.130 + *	than zero when the lock is not held. Lock holders must restore page 0
   6.131 + *	before unlocking. Even pure readers must take the lock to protect in 
   6.132 + *	page 0.
   6.133 + *
   6.134 + *	To make life difficult the chip can also be very slow. We therefore can't
   6.135 + *	just use spinlocks. For the longer lockups we disable the irq the device
   6.136 + *	sits on and hold the lock. We must hold the lock because there is a dual
   6.137 + *	processor case other than interrupts (get stats/set multicast list in
   6.138 + *	parallel with each other and transmit).
   6.139 + *
   6.140 + *	Note: in theory we can just disable the irq on the card _but_ there is
   6.141 + *	a latency on SMP irq delivery. So we can easily go "disable irq" "sync irqs"
   6.142 + *	enter lock, take the queued irq. So we waddle instead of flying.
   6.143 + *
   6.144 + *	Finally by special arrangement for the purpose of being generally 
   6.145 + *	annoying the transmit function is called bh atomic. That places
   6.146 + *	restrictions on the user context callers as disable_irq won't save
   6.147 + *	them.
   6.148 + */
   6.149 + 
   6.150 +
   6.151 +
   6.152 +/**
   6.153 + * ei_open - Open/initialize the board.
   6.154 + * @dev: network device to initialize
   6.155 + *
   6.156 + * This routine goes all-out, setting everything
   6.157 + * up anew at each open, even though many of these registers should only
   6.158 + * need to be set once at boot.
   6.159 + */
   6.160 +int ei_open(struct net_device *dev)
   6.161 +{
   6.162 +	unsigned long flags;
   6.163 +	struct ei_device *ei_local = (struct ei_device *) dev->priv;
   6.164 +
   6.165 +	/* This can't happen unless somebody forgot to call ethdev_init(). */
   6.166 +	if (ei_local == NULL) 
   6.167 +	{
   6.168 +		printk(KERN_EMERG "%s: ei_open passed a non-existent device!\n", dev->name);
   6.169 +		return -ENXIO;
   6.170 +	}
   6.171 +	
   6.172 +	/* The card I/O part of the driver (e.g. 3c503) can hook a Tx timeout
   6.173 +	    wrapper that does e.g. media check & then calls ei_tx_timeout. */
   6.174 +	if (dev->tx_timeout == NULL)
   6.175 +		 dev->tx_timeout = ei_tx_timeout;
   6.176 +	if (dev->watchdog_timeo <= 0)
   6.177 +		 dev->watchdog_timeo = TX_TIMEOUT;
   6.178 +    
   6.179 +	/*
   6.180 +	 *	Grab the page lock so we own the register set, then call
   6.181 +	 *	the init function.
   6.182 +	 */
   6.183 +      
   6.184 +      	spin_lock_irqsave(&ei_local->page_lock, flags);
   6.185 +	NS8390_init(dev, 1);
   6.186 +	/* Set the flag before we drop the lock, That way the IRQ arrives
   6.187 +	   after its set and we get no silly warnings */
   6.188 +	netif_start_queue(dev);
   6.189 +      	spin_unlock_irqrestore(&ei_local->page_lock, flags);
   6.190 +	ei_local->irqlock = 0;
   6.191 +	return 0;
   6.192 +}
   6.193 +
   6.194 +/**
   6.195 + * ei_close - shut down network device
   6.196 + * @dev: network device to close
   6.197 + *
   6.198 + * Opposite of ei_open(). Only used when "ifconfig <devname> down" is done.
   6.199 + */
   6.200 +int ei_close(struct net_device *dev)
   6.201 +{
   6.202 +	struct ei_device *ei_local = (struct ei_device *) dev->priv;
   6.203 +	unsigned long flags;
   6.204 +
   6.205 +	/*
   6.206 +	 *	Hold the page lock during close
   6.207 +	 */
   6.208 +	 	
   6.209 +      	spin_lock_irqsave(&ei_local->page_lock, flags);
   6.210 +	NS8390_init(dev, 0);
   6.211 +      	spin_unlock_irqrestore(&ei_local->page_lock, flags);
   6.212 +	netif_stop_queue(dev);
   6.213 +	return 0;
   6.214 +}
   6.215 +
   6.216 +/**
   6.217 + * ei_tx_timeout - handle transmit time out condition
   6.218 + * @dev: network device which has apparently fallen asleep
   6.219 + *
   6.220 + * Called by kernel when device never acknowledges a transmit has
   6.221 + * completed (or failed) - i.e. never posted a Tx related interrupt.
   6.222 + */
   6.223 +
   6.224 +void ei_tx_timeout(struct net_device *dev)
   6.225 +{
   6.226 +	long e8390_base = dev->base_addr;
   6.227 +	struct ei_device *ei_local = (struct ei_device *) dev->priv;
   6.228 +	int txsr, isr, tickssofar = jiffies - dev->trans_start;
   6.229 +	unsigned long flags;
   6.230 +
   6.231 +	ei_local->stat.tx_errors++;
   6.232 +
   6.233 +	spin_lock_irqsave(&ei_local->page_lock, flags);
   6.234 +	txsr = inb(e8390_base+EN0_TSR);
   6.235 +	isr = inb(e8390_base+EN0_ISR);
   6.236 +	spin_unlock_irqrestore(&ei_local->page_lock, flags);
   6.237 +
   6.238 +	printk(KERN_DEBUG "%s: Tx timed out, %s TSR=%#2x, ISR=%#2x, t=%d.\n",
   6.239 +		dev->name, (txsr & ENTSR_ABT) ? "excess collisions." :
   6.240 +		(isr) ? "lost interrupt?" : "cable problem?", txsr, isr, tickssofar);
   6.241 +
   6.242 +	if (!isr && !ei_local->stat.tx_packets) 
   6.243 +	{
   6.244 +		/* The 8390 probably hasn't gotten on the cable yet. */
   6.245 +		ei_local->interface_num ^= 1;   /* Try a different xcvr.  */
   6.246 +	}
   6.247 +
   6.248 +	/* Ugly but a reset can be slow, yet must be protected */
   6.249 +		
   6.250 +	disable_irq_nosync(dev->irq);
   6.251 +	spin_lock(&ei_local->page_lock);
   6.252 +		
   6.253 +	/* Try to restart the card.  Perhaps the user has fixed something. */
   6.254 +	ei_reset_8390(dev);
   6.255 +	NS8390_init(dev, 1);
   6.256 +		
   6.257 +	spin_unlock(&ei_local->page_lock);
   6.258 +	enable_irq(dev->irq);
   6.259 +	netif_wake_queue(dev);
   6.260 +}
   6.261 +    
   6.262 +/**
   6.263 + * ei_start_xmit - begin packet transmission
   6.264 + * @skb: packet to be sent
   6.265 + * @dev: network device to which packet is sent
   6.266 + *
   6.267 + * Sends a packet to an 8390 network device.
   6.268 + */
   6.269 + 
   6.270 +static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
   6.271 +{
   6.272 +	long e8390_base = dev->base_addr;
   6.273 +	struct ei_device *ei_local = (struct ei_device *) dev->priv;
   6.274 +	int length, send_length, output_page;
   6.275 +	unsigned long flags;
   6.276 +
   6.277 +	length = skb->len;
   6.278 +
   6.279 +	/* Mask interrupts from the ethercard. 
   6.280 +	   SMP: We have to grab the lock here otherwise the IRQ handler
   6.281 +	   on another CPU can flip window and race the IRQ mask set. We end
   6.282 +	   up trashing the mcast filter not disabling irqs if we dont lock */
   6.283 +	   
   6.284 +	spin_lock_irqsave(&ei_local->page_lock, flags);
   6.285 +	outb_p(0x00, e8390_base + EN0_IMR);
   6.286 +	spin_unlock_irqrestore(&ei_local->page_lock, flags);
   6.287 +	
   6.288 +	
   6.289 +	/*
   6.290 +	 *	Slow phase with lock held.
   6.291 +	 */
   6.292 +	 
   6.293 +	disable_irq_nosync(dev->irq);
   6.294 +	
   6.295 +	spin_lock(&ei_local->page_lock);
   6.296 +	
   6.297 +	ei_local->irqlock = 1;
   6.298 +
   6.299 +	send_length = ETH_ZLEN < length ? length : ETH_ZLEN;
   6.300 +    
   6.301 +#ifdef EI_PINGPONG
   6.302 +
   6.303 +	/*
   6.304 +	 * We have two Tx slots available for use. Find the first free
   6.305 +	 * slot, and then perform some sanity checks. With two Tx bufs,
   6.306 +	 * you get very close to transmitting back-to-back packets. With
   6.307 +	 * only one Tx buf, the transmitter sits idle while you reload the
   6.308 +	 * card, leaving a substantial gap between each transmitted packet.
   6.309 +	 */
   6.310 +
   6.311 +	if (ei_local->tx1 == 0) 
   6.312 +	{
   6.313 +		output_page = ei_local->tx_start_page;
   6.314 +		ei_local->tx1 = send_length;
   6.315 +		if (ei_debug  &&  ei_local->tx2 > 0)
   6.316 +			printk(KERN_DEBUG "%s: idle transmitter tx2=%d, lasttx=%d, txing=%d.\n",
   6.317 +				dev->name, ei_local->tx2, ei_local->lasttx, ei_local->txing);
   6.318 +	}
   6.319 +	else if (ei_local->tx2 == 0) 
   6.320 +	{
   6.321 +		output_page = ei_local->tx_start_page + TX_1X_PAGES;
   6.322 +		ei_local->tx2 = send_length;
   6.323 +		if (ei_debug  &&  ei_local->tx1 > 0)
   6.324 +			printk(KERN_DEBUG "%s: idle transmitter, tx1=%d, lasttx=%d, txing=%d.\n",
   6.325 +				dev->name, ei_local->tx1, ei_local->lasttx, ei_local->txing);
   6.326 +	}
   6.327 +	else
   6.328 +	{	/* We should never get here. */
   6.329 +		if (ei_debug)
   6.330 +			printk(KERN_DEBUG "%s: No Tx buffers free! tx1=%d tx2=%d last=%d\n",
   6.331 +				dev->name, ei_local->tx1, ei_local->tx2, ei_local->lasttx);
   6.332 +		ei_local->irqlock = 0;
   6.333 +		netif_stop_queue(dev);
   6.334 +		outb_p(ENISR_ALL, e8390_base + EN0_IMR);
   6.335 +		spin_unlock(&ei_local->page_lock);
   6.336 +		enable_irq(dev->irq);
   6.337 +		ei_local->stat.tx_errors++;
   6.338 +		return 1;
   6.339 +	}
   6.340 +
   6.341 +	/*
   6.342 +	 * Okay, now upload the packet and trigger a send if the transmitter
   6.343 +	 * isn't already sending. If it is busy, the interrupt handler will
   6.344 +	 * trigger the send later, upon receiving a Tx done interrupt.
   6.345 +	 */
   6.346 +
   6.347 +	ei_block_output(dev, length, skb->data, output_page);
   6.348 +	if (! ei_local->txing) 
   6.349 +	{
   6.350 +		ei_local->txing = 1;
   6.351 +		NS8390_trigger_send(dev, send_length, output_page);
   6.352 +		dev->trans_start = jiffies;
   6.353 +		if (output_page == ei_local->tx_start_page) 
   6.354 +		{
   6.355 +			ei_local->tx1 = -1;
   6.356 +			ei_local->lasttx = -1;
   6.357 +		}
   6.358 +		else 
   6.359 +		{
   6.360 +			ei_local->tx2 = -1;
   6.361 +			ei_local->lasttx = -2;
   6.362 +		}
   6.363 +	}
   6.364 +	else ei_local->txqueue++;
   6.365 +
   6.366 +	if (ei_local->tx1  &&  ei_local->tx2)
   6.367 +		netif_stop_queue(dev);
   6.368 +	else
   6.369 +		netif_start_queue(dev);
   6.370 +
   6.371 +#else	/* EI_PINGPONG */
   6.372 +
   6.373 +	/*
   6.374 +	 * Only one Tx buffer in use. You need two Tx bufs to come close to
   6.375 +	 * back-to-back transmits. Expect a 20 -> 25% performance hit on
   6.376 +	 * reasonable hardware if you only use one Tx buffer.
   6.377 +	 */
   6.378 +
   6.379 +	ei_block_output(dev, length, skb->data, ei_local->tx_start_page);
   6.380 +	ei_local->txing = 1;
   6.381 +	NS8390_trigger_send(dev, send_length, ei_local->tx_start_page);
   6.382 +	dev->trans_start = jiffies;
   6.383 +	netif_stop_queue(dev);
   6.384 +
   6.385 +#endif	/* EI_PINGPONG */
   6.386 +
   6.387 +	/* Turn 8390 interrupts back on. */
   6.388 +	ei_local->irqlock = 0;
   6.389 +	outb_p(ENISR_ALL, e8390_base + EN0_IMR);
   6.390 +	
   6.391 +	spin_unlock(&ei_local->page_lock);
   6.392 +	enable_irq(dev->irq);
   6.393 +
   6.394 +	dev_kfree_skb (skb);
   6.395 +	ei_local->stat.tx_bytes += send_length;
   6.396 +    
   6.397 +	return 0;
   6.398 +}
   6.399 +
   6.400 +/**
   6.401 + * ei_interrupt - handle the interrupts from an 8390
   6.402 + * @irq: interrupt number
   6.403 + * @dev_id: a pointer to the net_device
   6.404 + * @regs: unused
   6.405 + *
   6.406 + * Handle the ether interface interrupts. We pull packets from
   6.407 + * the 8390 via the card specific functions and fire them at the networking
   6.408 + * stack. We also handle transmit completions and wake the transmit path if
   6.409 + * neccessary. We also update the counters and do other housekeeping as
   6.410 + * needed.
   6.411 + */
   6.412 +
   6.413 +void ei_interrupt(int irq, void *dev_id, struct pt_regs * regs)
   6.414 +{
   6.415 +	struct net_device *dev = dev_id;
   6.416 +	long e8390_base;
   6.417 +	int interrupts, nr_serviced = 0;
   6.418 +	struct ei_device *ei_local;
   6.419 +    
   6.420 +	if (dev == NULL) 
   6.421 +	{
   6.422 +		printk ("net_interrupt(): irq %d for unknown device.\n", irq);
   6.423 +		return;
   6.424 +	}
   6.425 +    
   6.426 +	e8390_base = dev->base_addr;
   6.427 +	ei_local = (struct ei_device *) dev->priv;
   6.428 +
   6.429 +	/*
   6.430 +	 *	Protect the irq test too.
   6.431 +	 */
   6.432 +	 
   6.433 +	spin_lock(&ei_local->page_lock);
   6.434 +
   6.435 +	if (ei_local->irqlock) 
   6.436 +	{
   6.437 +#if 1 /* This might just be an interrupt for a PCI device sharing this line */
   6.438 +		/* The "irqlock" check is only for testing. */
   6.439 +		printk(ei_local->irqlock
   6.440 +			   ? "%s: Interrupted while interrupts are masked! isr=%#2x imr=%#2x.\n"
   6.441 +			   : "%s: Reentering the interrupt handler! isr=%#2x imr=%#2x.\n",
   6.442 +			   dev->name, inb_p(e8390_base + EN0_ISR),
   6.443 +			   inb_p(e8390_base + EN0_IMR));
   6.444 +#endif
   6.445 +		spin_unlock(&ei_local->page_lock);
   6.446 +		return;
   6.447 +	}
   6.448 +    
   6.449 +	/* Change to page 0 and read the intr status reg. */
   6.450 +	outb_p(E8390_NODMA+E8390_PAGE0, e8390_base + E8390_CMD);
   6.451 +	if (ei_debug > 3)
   6.452 +		printk(KERN_DEBUG "%s: interrupt(isr=%#2.2x).\n", dev->name,
   6.453 +			   inb_p(e8390_base + EN0_ISR));
   6.454 +    
   6.455 +	/* !!Assumption!! -- we stay in page 0.	 Don't break this. */
   6.456 +	while ((interrupts = inb_p(e8390_base + EN0_ISR)) != 0
   6.457 +		   && ++nr_serviced < MAX_SERVICE) 
   6.458 +	{
   6.459 +		if (!netif_running(dev)) {
   6.460 +			printk(KERN_WARNING "%s: interrupt from stopped card\n", dev->name);
   6.461 +			/* rmk - acknowledge the interrupts */
   6.462 +			outb_p(interrupts, e8390_base + EN0_ISR);
   6.463 +			interrupts = 0;
   6.464 +			break;
   6.465 +		}
   6.466 +		if (interrupts & ENISR_OVER) 
   6.467 +			ei_rx_overrun(dev);
   6.468 +		else if (interrupts & (ENISR_RX+ENISR_RX_ERR)) 
   6.469 +		{
   6.470 +			/* Got a good (?) packet. */
   6.471 +			ei_receive(dev);
   6.472 +		}
   6.473 +		/* Push the next to-transmit packet through. */
   6.474 +		if (interrupts & ENISR_TX)
   6.475 +			ei_tx_intr(dev);
   6.476 +		else if (interrupts & ENISR_TX_ERR)
   6.477 +			ei_tx_err(dev);
   6.478 +
   6.479 +		if (interrupts & ENISR_COUNTERS) 
   6.480 +		{
   6.481 +			ei_local->stat.rx_frame_errors += inb_p(e8390_base + EN0_COUNTER0);
   6.482 +			ei_local->stat.rx_crc_errors   += inb_p(e8390_base + EN0_COUNTER1);
   6.483 +			ei_local->stat.rx_missed_errors+= inb_p(e8390_base + EN0_COUNTER2);
   6.484 +			outb_p(ENISR_COUNTERS, e8390_base + EN0_ISR); /* Ack intr. */
   6.485 +		}
   6.486 +		
   6.487 +		/* Ignore any RDC interrupts that make it back to here. */
   6.488 +		if (interrupts & ENISR_RDC) 
   6.489 +		{
   6.490 +			outb_p(ENISR_RDC, e8390_base + EN0_ISR);
   6.491 +		}
   6.492 +
   6.493 +		outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base + E8390_CMD);
   6.494 +	}
   6.495 +    
   6.496 +	if (interrupts && ei_debug) 
   6.497 +	{
   6.498 +		outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base + E8390_CMD);
   6.499 +		if (nr_serviced >= MAX_SERVICE) 
   6.500 +		{
   6.501 +			/* 0xFF is valid for a card removal */
   6.502 +			if(interrupts!=0xFF)
   6.503 +				printk(KERN_WARNING "%s: Too much work at interrupt, status %#2.2x\n",
   6.504 +				   dev->name, interrupts);
   6.505 +			outb_p(ENISR_ALL, e8390_base + EN0_ISR); /* Ack. most intrs. */
   6.506 +		} else {
   6.507 +			printk(KERN_WARNING "%s: unknown interrupt %#2x\n", dev->name, interrupts);
   6.508 +			outb_p(0xff, e8390_base + EN0_ISR); /* Ack. all intrs. */
   6.509 +		}
   6.510 +	}
   6.511 +	spin_unlock(&ei_local->page_lock);
   6.512 +	return;
   6.513 +}
   6.514 +
   6.515 +/**
   6.516 + * ei_tx_err - handle transmitter error
   6.517 + * @dev: network device which threw the exception
   6.518 + *
   6.519 + * A transmitter error has happened. Most likely excess collisions (which
   6.520 + * is a fairly normal condition). If the error is one where the Tx will
   6.521 + * have been aborted, we try and send another one right away, instead of
   6.522 + * letting the failed packet sit and collect dust in the Tx buffer. This
   6.523 + * is a much better solution as it avoids kernel based Tx timeouts, and
   6.524 + * an unnecessary card reset.
   6.525 + *
   6.526 + * Called with lock held.
   6.527 + */
   6.528 +
   6.529 +static void ei_tx_err(struct net_device *dev)
   6.530 +{
   6.531 +	long e8390_base = dev->base_addr;
   6.532 +	struct ei_device *ei_local = (struct ei_device *) dev->priv;
   6.533 +	unsigned char txsr = inb_p(e8390_base+EN0_TSR);
   6.534 +	unsigned char tx_was_aborted = txsr & (ENTSR_ABT+ENTSR_FU);
   6.535 +
   6.536 +#ifdef VERBOSE_ERROR_DUMP
   6.537 +	printk(KERN_DEBUG "%s: transmitter error (%#2x): ", dev->name, txsr);
   6.538 +	if (txsr & ENTSR_ABT)
   6.539 +		printk("excess-collisions ");
   6.540 +	if (txsr & ENTSR_ND)
   6.541 +		printk("non-deferral ");
   6.542 +	if (txsr & ENTSR_CRS)
   6.543 +		printk("lost-carrier ");
   6.544 +	if (txsr & ENTSR_FU)
   6.545 +		printk("FIFO-underrun ");
   6.546 +	if (txsr & ENTSR_CDH)
   6.547 +		printk("lost-heartbeat ");
   6.548 +	printk("\n");
   6.549 +#endif
   6.550 +
   6.551 +	outb_p(ENISR_TX_ERR, e8390_base + EN0_ISR); /* Ack intr. */
   6.552 +
   6.553 +	if (tx_was_aborted)
   6.554 +		ei_tx_intr(dev);
   6.555 +	else 
   6.556 +	{
   6.557 +		ei_local->stat.tx_errors++;
   6.558 +		if (txsr & ENTSR_CRS) ei_local->stat.tx_carrier_errors++;
   6.559 +		if (txsr & ENTSR_CDH) ei_local->stat.tx_heartbeat_errors++;
   6.560 +		if (txsr & ENTSR_OWC) ei_local->stat.tx_window_errors++;
   6.561 +	}
   6.562 +}
   6.563 +
   6.564 +/**
   6.565 + * ei_tx_intr - transmit interrupt handler
   6.566 + * @dev: network device for which tx intr is handled
   6.567 + *
   6.568 + * We have finished a transmit: check for errors and then trigger the next
   6.569 + * packet to be sent. Called with lock held.
   6.570 + */
   6.571 +
   6.572 +static void ei_tx_intr(struct net_device *dev)
   6.573 +{
   6.574 +	long e8390_base = dev->base_addr;
   6.575 +	struct ei_device *ei_local = (struct ei_device *) dev->priv;
   6.576 +	int status = inb(e8390_base + EN0_TSR);
   6.577 +    
   6.578 +	outb_p(ENISR_TX, e8390_base + EN0_ISR); /* Ack intr. */
   6.579 +
   6.580 +#ifdef EI_PINGPONG
   6.581 +
   6.582 +	/*
   6.583 +	 * There are two Tx buffers, see which one finished, and trigger
   6.584 +	 * the send of another one if it exists.
   6.585 +	 */
   6.586 +	ei_local->txqueue--;
   6.587 +
   6.588 +	if (ei_local->tx1 < 0) 
   6.589 +	{
   6.590 +		if (ei_local->lasttx != 1 && ei_local->lasttx != -1)
   6.591 +			printk(KERN_ERR "%s: bogus last_tx_buffer %d, tx1=%d.\n",
   6.592 +				ei_local->name, ei_local->lasttx, ei_local->tx1);
   6.593 +		ei_local->tx1 = 0;
   6.594 +		if (ei_local->tx2 > 0) 
   6.595 +		{
   6.596 +			ei_local->txing = 1;
   6.597 +			NS8390_trigger_send(dev, ei_local->tx2, ei_local->tx_start_page + 6);
   6.598 +			dev->trans_start = jiffies;
   6.599 +			ei_local->tx2 = -1,
   6.600 +			ei_local->lasttx = 2;
   6.601 +		}
   6.602 +		else ei_local->lasttx = 20, ei_local->txing = 0;	
   6.603 +	}
   6.604 +	else if (ei_local->tx2 < 0) 
   6.605 +	{
   6.606 +		if (ei_local->lasttx != 2  &&  ei_local->lasttx != -2)
   6.607 +			printk("%s: bogus last_tx_buffer %d, tx2=%d.\n",
   6.608 +				ei_local->name, ei_local->lasttx, ei_local->tx2);
   6.609 +		ei_local->tx2 = 0;
   6.610 +		if (ei_local->tx1 > 0) 
   6.611 +		{
   6.612 +			ei_local->txing = 1;
   6.613 +			NS8390_trigger_send(dev, ei_local->tx1, ei_local->tx_start_page);
   6.614 +			dev->trans_start = jiffies;
   6.615 +			ei_local->tx1 = -1;
   6.616 +			ei_local->lasttx = 1;
   6.617 +		}
   6.618 +		else
   6.619 +			ei_local->lasttx = 10, ei_local->txing = 0;
   6.620 +	}
   6.621 +//	else printk(KERN_WARNING "%s: unexpected TX-done interrupt, lasttx=%d.\n",
   6.622 +//			dev->name, ei_local->lasttx);
   6.623 +
   6.624 +#else	/* EI_PINGPONG */
   6.625 +	/*
   6.626 +	 *  Single Tx buffer: mark it free so another packet can be loaded.
   6.627 +	 */
   6.628 +	ei_local->txing = 0;
   6.629 +#endif
   6.630 +
   6.631 +	/* Minimize Tx latency: update the statistics after we restart TXing. */
   6.632 +	if (status & ENTSR_COL)
   6.633 +		ei_local->stat.collisions++;
   6.634 +	if (status & ENTSR_PTX)
   6.635 +		ei_local->stat.tx_packets++;
   6.636 +	else 
   6.637 +	{
   6.638 +		ei_local->stat.tx_errors++;
   6.639 +		if (status & ENTSR_ABT) 
   6.640 +		{
   6.641 +			ei_local->stat.tx_aborted_errors++;
   6.642 +			ei_local->stat.collisions += 16;
   6.643 +		}
   6.644 +		if (status & ENTSR_CRS) 
   6.645 +			ei_local->stat.tx_carrier_errors++;
   6.646 +		if (status & ENTSR_FU) 
   6.647 +			ei_local->stat.tx_fifo_errors++;
   6.648 +		if (status & ENTSR_CDH)
   6.649 +			ei_local->stat.tx_heartbeat_errors++;
   6.650 +		if (status & ENTSR_OWC)
   6.651 +			ei_local->stat.tx_window_errors++;
   6.652 +	}
   6.653 +	netif_wake_queue(dev);
   6.654 +}
   6.655 +
   6.656 +/**
   6.657 + * ei_receive - receive some packets
   6.658 + * @dev: network device with which receive will be run
   6.659 + *
   6.660 + * We have a good packet(s), get it/them out of the buffers. 
   6.661 + * Called with lock held.
   6.662 + */
   6.663 +
   6.664 +static void ei_receive(struct net_device *dev)
   6.665 +{
   6.666 +	long e8390_base = dev->base_addr;
   6.667 +	struct ei_device *ei_local = (struct ei_device *) dev->priv;
   6.668 +	unsigned char rxing_page, this_frame, next_frame;
   6.669 +	unsigned short current_offset;
   6.670 +	int rx_pkt_count = 0;
   6.671 +	struct e8390_pkt_hdr rx_frame;
   6.672 +	int num_rx_pages = ei_local->stop_page-ei_local->rx_start_page;
   6.673 +    
   6.674 +	while (++rx_pkt_count < 10) 
   6.675 +	{
   6.676 +		int pkt_len, pkt_stat;
   6.677 +		
   6.678 +		/* Get the rx page (incoming packet pointer). */
   6.679 +		outb_p(E8390_NODMA+E8390_PAGE1, e8390_base + E8390_CMD);
   6.680 +		rxing_page = inb_p(e8390_base + EN1_CURPAG);
   6.681 +		outb_p(E8390_NODMA+E8390_PAGE0, e8390_base + E8390_CMD);
   6.682 +		
   6.683 +		/* Remove one frame from the ring.  Boundary is always a page behind. */
   6.684 +		this_frame = inb_p(e8390_base + EN0_BOUNDARY) + 1;
   6.685 +		if (this_frame >= ei_local->stop_page)
   6.686 +			this_frame = ei_local->rx_start_page;
   6.687 +		
   6.688 +		/* Someday we'll omit the previous, iff we never get this message.
   6.689 +		   (There is at least one clone claimed to have a problem.)  
   6.690 +		   
   6.691 +		   Keep quiet if it looks like a card removal. One problem here
   6.692 +		   is that some clones crash in roughly the same way.
   6.693 +		 */
   6.694 +		if (ei_debug > 0  &&  this_frame != ei_local->current_page && (this_frame!=0x0 || rxing_page!=0xFF))
   6.695 +			printk(KERN_ERR "%s: mismatched read page pointers %2x vs %2x.\n",
   6.696 +				   dev->name, this_frame, ei_local->current_page);
   6.697 +		
   6.698 +		if (this_frame == rxing_page)	/* Read all the frames? */
   6.699 +			break;				/* Done for now */
   6.700 +		
   6.701 +		current_offset = this_frame << 8;
   6.702 +		ei_get_8390_hdr(dev, &rx_frame, this_frame);
   6.703 +		
   6.704 +		pkt_len = rx_frame.count - sizeof(struct e8390_pkt_hdr);
   6.705 +		pkt_stat = rx_frame.status;
   6.706 +		
   6.707 +		next_frame = this_frame + 1 + ((pkt_len+4)>>8);
   6.708 +		
   6.709 +		/* Check for bogosity warned by 3c503 book: the status byte is never
   6.710 +		   written.  This happened a lot during testing! This code should be
   6.711 +		   cleaned up someday. */
   6.712 +		if (rx_frame.next != next_frame
   6.713 +			&& rx_frame.next != next_frame + 1
   6.714 +			&& rx_frame.next != next_frame - num_rx_pages
   6.715 +			&& rx_frame.next != next_frame + 1 - num_rx_pages) {
   6.716 +			ei_local->current_page = rxing_page;
   6.717 +			outb(ei_local->current_page-1, e8390_base+EN0_BOUNDARY);
   6.718 +			ei_local->stat.rx_errors++;
   6.719 +			continue;
   6.720 +		}
   6.721 +
   6.722 +		if (pkt_len < 60  ||  pkt_len > 1518) 
   6.723 +		{
   6.724 +			if (ei_debug)
   6.725 +				printk(KERN_DEBUG "%s: bogus packet size: %d, status=%#2x nxpg=%#2x.\n",
   6.726 +					   dev->name, rx_frame.count, rx_frame.status,
   6.727 +					   rx_frame.next);
   6.728 +			ei_local->stat.rx_errors++;
   6.729 +			ei_local->stat.rx_length_errors++;
   6.730 +		}
   6.731 +		 else if ((pkt_stat & 0x0F) == ENRSR_RXOK) 
   6.732 +		{
   6.733 +			struct sk_buff *skb;
   6.734 +			
   6.735 +			skb = dev_alloc_skb(pkt_len+2);
   6.736 +			if (skb == NULL) 
   6.737 +			{
   6.738 +				if (ei_debug > 1)
   6.739 +					printk(KERN_DEBUG "%s: Couldn't allocate a sk_buff of size %d.\n",
   6.740 +						   dev->name, pkt_len);
   6.741 +				ei_local->stat.rx_dropped++;
   6.742 +				break;
   6.743 +			}
   6.744 +			else
   6.745 +			{
   6.746 +				skb_reserve(skb,2);	/* IP headers on 16 byte boundaries */
   6.747 +				skb->dev = dev;
   6.748 +				skb_put(skb, pkt_len);	/* Make room */
   6.749 +				ei_block_input(dev, pkt_len, skb, current_offset + sizeof(rx_frame));
   6.750 +				skb->protocol=eth_type_trans(skb,dev);
   6.751 +				netif_rx(skb);
   6.752 +				dev->last_rx = jiffies;
   6.753 +				ei_local->stat.rx_packets++;
   6.754 +				ei_local->stat.rx_bytes += pkt_len;
   6.755 +				if (pkt_stat & ENRSR_PHY)
   6.756 +					ei_local->stat.multicast++;
   6.757 +			}
   6.758 +		} 
   6.759 +		else 
   6.760 +		{
   6.761 +			if (ei_debug)
   6.762 +				printk(KERN_DEBUG "%s: bogus packet: status=%#2x nxpg=%#2x size=%d\n",
   6.763 +					   dev->name, rx_frame.status, rx_frame.next,
   6.764 +					   rx_frame.count);
   6.765 +			ei_local->stat.rx_errors++;
   6.766 +			/* NB: The NIC counts CRC, frame and missed errors. */
   6.767 +			if (pkt_stat & ENRSR_FO)
   6.768 +				ei_local->stat.rx_fifo_errors++;
   6.769 +		}
   6.770 +		next_frame = rx_frame.next;
   6.771 +		
   6.772 +		/* This _should_ never happen: it's here for avoiding bad clones. */
   6.773 +		if (next_frame >= ei_local->stop_page) {
   6.774 +			printk("%s: next frame inconsistency, %#2x\n", dev->name,
   6.775 +				   next_frame);
   6.776 +			next_frame = ei_local->rx_start_page;
   6.777 +		}
   6.778 +		ei_local->current_page = next_frame;
   6.779 +		outb_p(next_frame-1, e8390_base+EN0_BOUNDARY);
   6.780 +	}
   6.781 +
   6.782 +	/* We used to also ack ENISR_OVER here, but that would sometimes mask
   6.783 +	   a real overrun, leaving the 8390 in a stopped state with rec'vr off. */
   6.784 +	outb_p(ENISR_RX+ENISR_RX_ERR, e8390_base+EN0_ISR);
   6.785 +	return;
   6.786 +}
   6.787 +
   6.788 +/**
   6.789 + * ei_rx_overrun - handle receiver overrun
   6.790 + * @dev: network device which threw exception
   6.791 + *
   6.792 + * We have a receiver overrun: we have to kick the 8390 to get it started
   6.793 + * again. Problem is that you have to kick it exactly as NS prescribes in
   6.794 + * the updated datasheets, or "the NIC may act in an unpredictable manner."
   6.795 + * This includes causing "the NIC to defer indefinitely when it is stopped
   6.796 + * on a busy network."  Ugh.
   6.797 + * Called with lock held. Don't call this with the interrupts off or your
   6.798 + * computer will hate you - it takes 10ms or so. 
   6.799 + */
   6.800 +
   6.801 +static void ei_rx_overrun(struct net_device *dev)
   6.802 +{
   6.803 +	long e8390_base = dev->base_addr;
   6.804 +	unsigned char was_txing, must_resend = 0;
   6.805 +	struct ei_device *ei_local = (struct ei_device *) dev->priv;
   6.806 +    
   6.807 +	/*
   6.808 +	 * Record whether a Tx was in progress and then issue the
   6.809 +	 * stop command.
   6.810 +	 */
   6.811 +	was_txing = inb_p(e8390_base+E8390_CMD) & E8390_TRANS;
   6.812 +	outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
   6.813 +    
   6.814 +	if (ei_debug > 1)
   6.815 +		printk(KERN_DEBUG "%s: Receiver overrun.\n", dev->name);
   6.816 +	ei_local->stat.rx_over_errors++;
   6.817 +    
   6.818 +	/* 
   6.819 +	 * Wait a full Tx time (1.2ms) + some guard time, NS says 1.6ms total.
   6.820 +	 * Early datasheets said to poll the reset bit, but now they say that
   6.821 +	 * it "is not a reliable indicator and subsequently should be ignored."
   6.822 +	 * We wait at least 10ms.
   6.823 +	 */
   6.824 +
   6.825 +	udelay(10*1000);
   6.826 +
   6.827 +	/*
   6.828 +	 * Reset RBCR[01] back to zero as per magic incantation.
   6.829 +	 */
   6.830 +	outb_p(0x00, e8390_base+EN0_RCNTLO);
   6.831 +	outb_p(0x00, e8390_base+EN0_RCNTHI);
   6.832 +
   6.833 +	/*
   6.834 +	 * See if any Tx was interrupted or not. According to NS, this
   6.835 +	 * step is vital, and skipping it will cause no end of havoc.
   6.836 +	 */
   6.837 +
   6.838 +	if (was_txing)
   6.839 +	{ 
   6.840 +		unsigned char tx_completed = inb_p(e8390_base+EN0_ISR) & (ENISR_TX+ENISR_TX_ERR);
   6.841 +		if (!tx_completed)
   6.842 +			must_resend = 1;
   6.843 +	}
   6.844 +
   6.845 +	/*
   6.846 +	 * Have to enter loopback mode and then restart the NIC before
   6.847 +	 * you are allowed to slurp packets up off the ring.
   6.848 +	 */
   6.849 +	outb_p(E8390_TXOFF, e8390_base + EN0_TXCR);
   6.850 +	outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START, e8390_base + E8390_CMD);
   6.851 +
   6.852 +	/*
   6.853 +	 * Clear the Rx ring of all the debris, and ack the interrupt.
   6.854 +	 */
   6.855 +	ei_receive(dev);
   6.856 +	outb_p(ENISR_OVER, e8390_base+EN0_ISR);
   6.857 +
   6.858 +	/*
   6.859 +	 * Leave loopback mode, and resend any packet that got stopped.
   6.860 +	 */
   6.861 +	outb_p(E8390_TXCONFIG, e8390_base + EN0_TXCR); 
   6.862 +	if (must_resend)
   6.863 +    		outb_p(E8390_NODMA + E8390_PAGE0 + E8390_START + E8390_TRANS, e8390_base + E8390_CMD);
   6.864 +}
   6.865 +
   6.866 +/*
   6.867 + *	Collect the stats. This is called unlocked and from several contexts.
   6.868 + */
   6.869 + 
   6.870 +static struct net_device_stats *get_stats(struct net_device *dev)
   6.871 +{
   6.872 +	long ioaddr = dev->base_addr;
   6.873 +	struct ei_device *ei_local = (struct ei_device *) dev->priv;
   6.874 +	unsigned long flags;
   6.875 +    
   6.876 +	/* If the card is stopped, just return the present stats. */
   6.877 +	if (!netif_running(dev))
   6.878 +		return &ei_local->stat;
   6.879 +
   6.880 +	spin_lock_irqsave(&ei_local->page_lock,flags);
   6.881 +	/* Read the counter registers, assuming we are in page 0. */
   6.882 +	ei_local->stat.rx_frame_errors += inb_p(ioaddr + EN0_COUNTER0);
   6.883 +	ei_local->stat.rx_crc_errors   += inb_p(ioaddr + EN0_COUNTER1);
   6.884 +	ei_local->stat.rx_missed_errors+= inb_p(ioaddr + EN0_COUNTER2);
   6.885 +	spin_unlock_irqrestore(&ei_local->page_lock, flags);
   6.886 +    
   6.887 +	return &ei_local->stat;
   6.888 +}
   6.889 +
   6.890 +/*
   6.891 + * Update the given Autodin II CRC value with another data byte.
   6.892 + */
   6.893 +
   6.894 +static inline u32 update_crc(u8 byte, u32 current_crc)
   6.895 +{
   6.896 +	int bit;
   6.897 +	u8 ah = 0;
   6.898 +	for (bit=0; bit<8; bit++) 
   6.899 +	{
   6.900 +		u8 carry = (current_crc>>31);
   6.901 +		current_crc <<= 1;
   6.902 +		ah = ((ah<<1) | carry) ^ byte;
   6.903 +		if (ah&1)
   6.904 +			current_crc ^= 0x04C11DB7;	/* CRC polynomial */
   6.905 +		ah >>= 1;
   6.906 +		byte >>= 1;
   6.907 +	}
   6.908 +	return current_crc;
   6.909 +}
   6.910 +
   6.911 +/*
   6.912 + * Form the 64 bit 8390 multicast table from the linked list of addresses
   6.913 + * associated with this dev structure.
   6.914 + */
   6.915 + 
   6.916 +static inline void make_mc_bits(u8 *bits, struct net_device *dev)
   6.917 +{
   6.918 +	struct dev_mc_list *dmi;
   6.919 +
   6.920 +	for (dmi=dev->mc_list; dmi; dmi=dmi->next) 
   6.921 +	{
   6.922 +		int i;
   6.923 +		u32 crc;
   6.924 +		if (dmi->dmi_addrlen != ETH_ALEN) 
   6.925 +		{
   6.926 +			printk(KERN_INFO "%s: invalid multicast address length given.\n", dev->name);
   6.927 +			continue;
   6.928 +		}
   6.929 +		crc = 0xffffffff;	/* initial CRC value */
   6.930 +		for (i=0; i<ETH_ALEN; i++)
   6.931 +			crc = update_crc(dmi->dmi_addr[i], crc);
   6.932 +		/* 
   6.933 +		 * The 8390 uses the 6 most significant bits of the
   6.934 +		 * CRC to index the multicast table.
   6.935 +		 */
   6.936 +		bits[crc>>29] |= (1<<((crc>>26)&7));
   6.937 +	}
   6.938 +}
   6.939 +
   6.940 +/**
   6.941 + * do_set_multicast_list - set/clear multicast filter
   6.942 + * @dev: net device for which multicast filter is adjusted
   6.943 + *
   6.944 + *	Set or clear the multicast filter for this adaptor. May be called
   6.945 + *	from a BH in 2.1.x. Must be called with lock held. 
   6.946 + */
   6.947 + 
   6.948 +static void do_set_multicast_list(struct net_device *dev)
   6.949 +{
   6.950 +	long e8390_base = dev->base_addr;
   6.951 +	int i;
   6.952 +	struct ei_device *ei_local = (struct ei_device*)dev->priv;
   6.953 +
   6.954 +	if (!(dev->flags&(IFF_PROMISC|IFF_ALLMULTI))) 
   6.955 +	{
   6.956 +		memset(ei_local->mcfilter, 0, 8);
   6.957 +		if (dev->mc_list)
   6.958 +			make_mc_bits(ei_local->mcfilter, dev);
   6.959 +	}
   6.960 +	else
   6.961 +		memset(ei_local->mcfilter, 0xFF, 8);	/* mcast set to accept-all */
   6.962 +
   6.963 +	/* 
   6.964 +	 * DP8390 manuals don't specify any magic sequence for altering
   6.965 +	 * the multicast regs on an already running card. To be safe, we
   6.966 +	 * ensure multicast mode is off prior to loading up the new hash
   6.967 +	 * table. If this proves to be not enough, we can always resort
   6.968 +	 * to stopping the NIC, loading the table and then restarting.
   6.969 +	 *
   6.970 +	 * Bug Alert!  The MC regs on the SMC 83C690 (SMC Elite and SMC 
   6.971 +	 * Elite16) appear to be write-only. The NS 8390 data sheet lists
   6.972 +	 * them as r/w so this is a bug.  The SMC 83C790 (SMC Ultra and
   6.973 +	 * Ultra32 EISA) appears to have this bug fixed.
   6.974 +	 */
   6.975 +	 
   6.976 +	if (netif_running(dev))
   6.977 +		outb_p(E8390_RXCONFIG, e8390_base + EN0_RXCR);
   6.978 +	outb_p(E8390_NODMA + E8390_PAGE1, e8390_base + E8390_CMD);
   6.979 +	for(i = 0; i < 8; i++) 
   6.980 +	{
   6.981 +		outb_p(ei_local->mcfilter[i], e8390_base + EN1_MULT_SHIFT(i));
   6.982 +#ifndef BUG_83C690
   6.983 +		if(inb_p(e8390_base + EN1_MULT_SHIFT(i))!=ei_local->mcfilter[i])
   6.984 +			printk(KERN_ERR "Multicast filter read/write mismap %d\n",i);
   6.985 +#endif
   6.986 +	}
   6.987 +	outb_p(E8390_NODMA + E8390_PAGE0, e8390_base + E8390_CMD);
   6.988 +
   6.989 +  	if(dev->flags&IFF_PROMISC)
   6.990 +  		outb_p(E8390_RXCONFIG | 0x18, e8390_base + EN0_RXCR);
   6.991 +	else if(dev->flags&IFF_ALLMULTI || dev->mc_list)
   6.992 +  		outb_p(E8390_RXCONFIG | 0x08, e8390_base + EN0_RXCR);
   6.993 +  	else
   6.994 +  		outb_p(E8390_RXCONFIG, e8390_base + EN0_RXCR);
   6.995 + }
   6.996 +
   6.997 +/*
   6.998 + *	Called without lock held. This is invoked from user context and may
   6.999 + *	be parallel to just about everything else. Its also fairly quick and
  6.1000 + *	not called too often. Must protect against both bh and irq users
  6.1001 + */
  6.1002 + 
  6.1003 +static void set_multicast_list(struct net_device *dev)
  6.1004 +{
  6.1005 +	unsigned long flags;
  6.1006 +	struct ei_device *ei_local = (struct ei_device*)dev->priv;
  6.1007 +	
  6.1008 +	spin_lock_irqsave(&ei_local->page_lock, flags);
  6.1009 +	do_set_multicast_list(dev);
  6.1010 +	spin_unlock_irqrestore(&ei_local->page_lock, flags);
  6.1011 +}	
  6.1012 +
  6.1013 +/**
  6.1014 + * ethdev_init - init rest of 8390 device struct
  6.1015 + * @dev: network device structure to init
  6.1016 + *
  6.1017 + * Initialize the rest of the 8390 device structure.  Do NOT __init
  6.1018 + * this, as it is used by 8390 based modular drivers too.
  6.1019 + */
  6.1020 +
  6.1021 +int ethdev_init(struct net_device *dev)
  6.1022 +{
  6.1023 +	if (ei_debug > 1)
  6.1024 +		printk(version);
  6.1025 +    
  6.1026 +	if (dev->priv == NULL) 
  6.1027 +	{
  6.1028 +		struct ei_device *ei_local;
  6.1029 +		
  6.1030 +		dev->priv = kmalloc(sizeof(struct ei_device), GFP_KERNEL);
  6.1031 +		if (dev->priv == NULL)
  6.1032 +			return -ENOMEM;
  6.1033 +		memset(dev->priv, 0, sizeof(struct ei_device));
  6.1034 +		ei_local = (struct ei_device *)dev->priv;
  6.1035 +		spin_lock_init(&ei_local->page_lock);
  6.1036 +	}
  6.1037 +    
  6.1038 +	dev->hard_start_xmit = &ei_start_xmit;
  6.1039 +	dev->get_stats	= get_stats;
  6.1040 +	dev->set_multicast_list = &set_multicast_list;
  6.1041 +
  6.1042 +	ether_setup(dev);
  6.1043 +        
  6.1044 +	return 0;
  6.1045 +}
  6.1046 +
  6.1047 +
  6.1048 +
  6.1049 +/* This page of functions should be 8390 generic */
  6.1050 +/* Follow National Semi's recommendations for initializing the "NIC". */
  6.1051 +
  6.1052 +/**
  6.1053 + * NS8390_init - initialize 8390 hardware
  6.1054 + * @dev: network device to initialize
  6.1055 + * @startp: boolean.  non-zero value to initiate chip processing
  6.1056 + *
  6.1057 + *	Must be called with lock held.
  6.1058 + */
  6.1059 +
  6.1060 +void NS8390_init(struct net_device *dev, int startp)
  6.1061 +{
  6.1062 +	long e8390_base = dev->base_addr;
  6.1063 +	struct ei_device *ei_local = (struct ei_device *) dev->priv;
  6.1064 +	int i;
  6.1065 +	int endcfg = ei_local->word16
  6.1066 +	    ? (0x48 | ENDCFG_WTS | (ei_local->bigendian ? ENDCFG_BOS : 0))
  6.1067 +	    : 0x48;
  6.1068 +    
  6.1069 +	if(sizeof(struct e8390_pkt_hdr)!=4)
  6.1070 +    		panic("8390.c: header struct mispacked\n");    
  6.1071 +	/* Follow National Semi's recommendations for initing the DP83902. */
  6.1072 +	outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD); /* 0x21 */
  6.1073 +	outb_p(endcfg, e8390_base + EN0_DCFG);	/* 0x48 or 0x49 */
  6.1074 +	/* Clear the remote byte count registers. */
  6.1075 +	outb_p(0x00,  e8390_base + EN0_RCNTLO);
  6.1076 +	outb_p(0x00,  e8390_base + EN0_RCNTHI);
  6.1077 +	/* Set to monitor and loopback mode -- this is vital!. */
  6.1078 +	outb_p(E8390_RXOFF, e8390_base + EN0_RXCR); /* 0x20 */
  6.1079 +	outb_p(E8390_TXOFF, e8390_base + EN0_TXCR); /* 0x02 */
  6.1080 +	/* Set the transmit page and receive ring. */
  6.1081 +	outb_p(ei_local->tx_start_page, e8390_base + EN0_TPSR);
  6.1082 +	ei_local->tx1 = ei_local->tx2 = 0;
  6.1083 +	outb_p(ei_local->rx_start_page, e8390_base + EN0_STARTPG);
  6.1084 +	outb_p(ei_local->stop_page-1, e8390_base + EN0_BOUNDARY);	/* 3c503 says 0x3f,NS0x26*/
  6.1085 +	ei_local->current_page = ei_local->rx_start_page;		/* assert boundary+1 */
  6.1086 +	outb_p(ei_local->stop_page, e8390_base + EN0_STOPPG);
  6.1087 +	/* Clear the pending interrupts and mask. */
  6.1088 +	outb_p(0xFF, e8390_base + EN0_ISR);
  6.1089 +	outb_p(0x00,  e8390_base + EN0_IMR);
  6.1090 +    
  6.1091 +	/* Copy the station address into the DS8390 registers. */
  6.1092 +
  6.1093 +	outb_p(E8390_NODMA + E8390_PAGE1 + E8390_STOP, e8390_base+E8390_CMD); /* 0x61 */
  6.1094 +	for(i = 0; i < 6; i++) 
  6.1095 +	{
  6.1096 +		outb_p(dev->dev_addr[i], e8390_base + EN1_PHYS_SHIFT(i));
  6.1097 +		if(inb_p(e8390_base + EN1_PHYS_SHIFT(i))!=dev->dev_addr[i])
  6.1098 +			printk(KERN_ERR "Hw. address read/write mismap %d\n",i);
  6.1099 +	}
  6.1100 +
  6.1101 +	outb_p(ei_local->rx_start_page, e8390_base + EN1_CURPAG);
  6.1102 +	outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
  6.1103 +
  6.1104 +	netif_start_queue(dev);
  6.1105 +	ei_local->tx1 = ei_local->tx2 = 0;
  6.1106 +	ei_local->txing = 0;
  6.1107 +
  6.1108 +	if (startp) 
  6.1109 +	{
  6.1110 +		outb_p(0xff,  e8390_base + EN0_ISR);
  6.1111 +		outb_p(ENISR_ALL,  e8390_base + EN0_IMR);
  6.1112 +		outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, e8390_base+E8390_CMD);
  6.1113 +		outb_p(E8390_TXCONFIG, e8390_base + EN0_TXCR); /* xmit on. */
  6.1114 +		/* 3c503 TechMan says rxconfig only after the NIC is started. */
  6.1115 +		outb_p(E8390_RXCONFIG, e8390_base + EN0_RXCR); /* rx on,  */
  6.1116 +		do_set_multicast_list(dev);	/* (re)load the mcast table */
  6.1117 +	}
  6.1118 +}
  6.1119 +
  6.1120 +/* Trigger a transmit start, assuming the length is valid. 
  6.1121 +   Always called with the page lock held */
  6.1122 +   
  6.1123 +static void NS8390_trigger_send(struct net_device *dev, unsigned int length,
  6.1124 +								int start_page)
  6.1125 +{
  6.1126 +	long e8390_base = dev->base_addr;
  6.1127 + 	struct ei_device *ei_local __attribute((unused)) = (struct ei_device *) dev->priv;
  6.1128 +   
  6.1129 +	outb_p(E8390_NODMA+E8390_PAGE0, e8390_base+E8390_CMD);
  6.1130 +    
  6.1131 +	if (inb_p(e8390_base) & E8390_TRANS) 
  6.1132 +	{
  6.1133 +		printk(KERN_WARNING "%s: trigger_send() called with the transmitter busy.\n",
  6.1134 +			dev->name);
  6.1135 +		return;
  6.1136 +	}
  6.1137 +	outb_p(length & 0xff, e8390_base + EN0_TCNTLO);
  6.1138 +	outb_p(length >> 8, e8390_base + EN0_TCNTHI);
  6.1139 +	outb_p(start_page, e8390_base + EN0_TPSR);
  6.1140 +	outb_p(E8390_NODMA+E8390_TRANS+E8390_START, e8390_base+E8390_CMD);
  6.1141 +}
  6.1142 +
  6.1143 +EXPORT_SYMBOL(ei_open);
  6.1144 +EXPORT_SYMBOL(ei_close);
  6.1145 +EXPORT_SYMBOL(ei_interrupt);
  6.1146 +EXPORT_SYMBOL(ei_tx_timeout);
  6.1147 +EXPORT_SYMBOL(ethdev_init);
  6.1148 +EXPORT_SYMBOL(NS8390_init);
  6.1149 +
  6.1150 +#if defined(MODULE)
  6.1151 +
  6.1152 +int init_module(void)
  6.1153 +{
  6.1154 +	return 0;
  6.1155 +}
  6.1156 +
  6.1157 +void cleanup_module(void)
  6.1158 +{
  6.1159 +}
  6.1160 +
  6.1161 +#endif /* MODULE */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/xen-2.4.16/drivers/net/ne/8390.h	Sun Feb 09 13:47:52 2003 +0000
     7.3 @@ -0,0 +1,197 @@
     7.4 +/* Generic NS8390 register definitions. */
     7.5 +/* This file is part of Donald Becker's 8390 drivers, and is distributed
     7.6 +   under the same license. Auto-loading of 8390.o only in v2.2 - Paul G.
     7.7 +   Some of these names and comments originated from the Crynwr
     7.8 +   packet drivers, which are distributed under the GPL. */
     7.9 +
    7.10 +#ifndef _8390_h
    7.11 +#define _8390_h
    7.12 +
    7.13 +#include <xeno/config.h>
    7.14 +#include <xeno/if_ether.h>
    7.15 +#include <xeno/ioport.h>
    7.16 +#include <xeno/skbuff.h>
    7.17 +
    7.18 +#define TX_2X_PAGES 12
    7.19 +#define TX_1X_PAGES 6
    7.20 +
    7.21 +/* Should always use two Tx slots to get back-to-back transmits. */
    7.22 +#define EI_PINGPONG
    7.23 +
    7.24 +#ifdef EI_PINGPONG
    7.25 +#define TX_PAGES TX_2X_PAGES
    7.26 +#else
    7.27 +#define TX_PAGES TX_1X_PAGES
    7.28 +#endif
    7.29 +
    7.30 +#define ETHER_ADDR_LEN 6
    7.31 +
    7.32 +/* The 8390 specific per-packet-header format. */
    7.33 +struct e8390_pkt_hdr {
    7.34 +  unsigned char status; /* status */
    7.35 +  unsigned char next;   /* pointer to next packet. */
    7.36 +  unsigned short count; /* header + packet length in bytes */
    7.37 +};
    7.38 +
    7.39 +#ifdef notdef
    7.40 +extern int ei_debug;
    7.41 +#else
    7.42 +#define ei_debug 1
    7.43 +#endif
    7.44 +
    7.45 +#ifndef HAVE_AUTOIRQ
    7.46 +/* From auto_irq.c */
    7.47 +extern void autoirq_setup(int waittime);
    7.48 +extern unsigned long autoirq_report(int waittime);
    7.49 +#endif
    7.50 +
    7.51 +extern int ethdev_init(struct net_device *dev);
    7.52 +extern void NS8390_init(struct net_device *dev, int startp);
    7.53 +extern int ei_open(struct net_device *dev);
    7.54 +extern int ei_close(struct net_device *dev);
    7.55 +extern void ei_interrupt(int irq, void *dev_id, struct pt_regs *regs);
    7.56 +
    7.57 +/* Most of these entries should be in 'struct net_device' (or most of the
    7.58 +   things in there should be here!) */
    7.59 +/* You have one of these per-board */
    7.60 +struct ei_device {
    7.61 +	const char *name;
    7.62 +	void (*reset_8390)(struct net_device *);
    7.63 +	void (*get_8390_hdr)(struct net_device *, struct e8390_pkt_hdr *, int);
    7.64 +	void (*block_output)(struct net_device *, int, const unsigned char *, int);
    7.65 +	void (*block_input)(struct net_device *, int, struct sk_buff *, int);
    7.66 +	unsigned char mcfilter[8];
    7.67 +	unsigned open:1;
    7.68 +	unsigned word16:1;  		/* We have the 16-bit (vs 8-bit) version of the card. */
    7.69 +	unsigned bigendian:1;		/* 16-bit big endian mode. Do NOT */
    7.70 +					/* set this on random 8390 clones! */
    7.71 +	unsigned txing:1;		/* Transmit Active */
    7.72 +	unsigned irqlock:1;		/* 8390's intrs disabled when '1'. */
    7.73 +	unsigned dmaing:1;		/* Remote DMA Active */
    7.74 +	unsigned char tx_start_page, rx_start_page, stop_page;
    7.75 +	unsigned char current_page;	/* Read pointer in buffer  */
    7.76 +	unsigned char interface_num;	/* Net port (AUI, 10bT.) to use. */
    7.77 +	unsigned char txqueue;		/* Tx Packet buffer queue length. */
    7.78 +	short tx1, tx2;			/* Packet lengths for ping-pong tx. */
    7.79 +	short lasttx;			/* Alpha version consistency check. */
    7.80 +	unsigned char reg0;		/* Register '0' in a WD8013 */
    7.81 +	unsigned char reg5;		/* Register '5' in a WD8013 */
    7.82 +	unsigned char saved_irq;	/* Original dev->irq value. */
    7.83 +	struct net_device_stats stat;	/* The new statistics table. */
    7.84 +	u32 *reg_offset;		/* Register mapping table */
    7.85 +	spinlock_t page_lock;		/* Page register locks */
    7.86 +	unsigned long priv;		/* Private field to store bus IDs etc. */
    7.87 +};
    7.88 +
    7.89 +/* The maximum number of 8390 interrupt service routines called per IRQ. */
    7.90 +#define MAX_SERVICE 12
    7.91 +
    7.92 +/* The maximum time waited (in jiffies) before assuming a Tx failed. (20ms) */
    7.93 +#define TX_TIMEOUT (20*HZ/100)
    7.94 +
    7.95 +#define ei_status (*(struct ei_device *)(dev->priv))
    7.96 +
    7.97 +/* Some generic ethernet register configurations. */
    7.98 +#define E8390_TX_IRQ_MASK	0xa	/* For register EN0_ISR */
    7.99 +#define E8390_RX_IRQ_MASK	0x5
   7.100 +#define E8390_RXCONFIG		0x4	/* EN0_RXCR: broadcasts, no multicast,errors */
   7.101 +#define E8390_RXOFF		0x20	/* EN0_RXCR: Accept no packets */
   7.102 +#define E8390_TXCONFIG		0x00	/* EN0_TXCR: Normal transmit mode */
   7.103 +#define E8390_TXOFF		0x02	/* EN0_TXCR: Transmitter off */
   7.104 +
   7.105 +/*  Register accessed at EN_CMD, the 8390 base addr.  */
   7.106 +#define E8390_STOP	0x01	/* Stop and reset the chip */
   7.107 +#define E8390_START	0x02	/* Start the chip, clear reset */
   7.108 +#define E8390_TRANS	0x04	/* Transmit a frame */
   7.109 +#define E8390_RREAD	0x08	/* Remote read */
   7.110 +#define E8390_RWRITE	0x10	/* Remote write  */
   7.111 +#define E8390_NODMA	0x20	/* Remote DMA */
   7.112 +#define E8390_PAGE0	0x00	/* Select page chip registers */
   7.113 +#define E8390_PAGE1	0x40	/* using the two high-order bits */
   7.114 +#define E8390_PAGE2	0x80	/* Page 3 is invalid. */
   7.115 +
   7.116 +/*
   7.117 + *	Only generate indirect loads given a machine that needs them.
   7.118 + */
   7.119 + 
   7.120 +#if defined(CONFIG_MAC) || defined(CONFIG_AMIGA_PCMCIA) || \
   7.121 +    defined(CONFIG_ARIADNE2) || defined(CONFIG_ARIADNE2_MODULE) || \
   7.122 +    defined(CONFIG_HYDRA) || defined(CONFIG_HYDRA_MODULE) || \
   7.123 +    defined(CONFIG_ARM_ETHERH) || defined(CONFIG_ARM_ETHERH_MODULE)
   7.124 +#define EI_SHIFT(x)	(ei_local->reg_offset[x])
   7.125 +#else
   7.126 +#define EI_SHIFT(x)	(x)
   7.127 +#endif
   7.128 +
   7.129 +#define E8390_CMD	EI_SHIFT(0x00)  /* The command register (for all pages) */
   7.130 +/* Page 0 register offsets. */
   7.131 +#define EN0_CLDALO	EI_SHIFT(0x01)	/* Low byte of current local dma addr  RD */
   7.132 +#define EN0_STARTPG	EI_SHIFT(0x01)	/* Starting page of ring bfr WR */
   7.133 +#define EN0_CLDAHI	EI_SHIFT(0x02)	/* High byte of current local dma addr  RD */
   7.134 +#define EN0_STOPPG	EI_SHIFT(0x02)	/* Ending page +1 of ring bfr WR */
   7.135 +#define EN0_BOUNDARY	EI_SHIFT(0x03)	/* Boundary page of ring bfr RD WR */
   7.136 +#define EN0_TSR		EI_SHIFT(0x04)	/* Transmit status reg RD */
   7.137 +#define EN0_TPSR	EI_SHIFT(0x04)	/* Transmit starting page WR */
   7.138 +#define EN0_NCR		EI_SHIFT(0x05)	/* Number of collision reg RD */
   7.139 +#define EN0_TCNTLO	EI_SHIFT(0x05)	/* Low  byte of tx byte count WR */
   7.140 +#define EN0_FIFO	EI_SHIFT(0x06)	/* FIFO RD */
   7.141 +#define EN0_TCNTHI	EI_SHIFT(0x06)	/* High byte of tx byte count WR */
   7.142 +#define EN0_ISR		EI_SHIFT(0x07)	/* Interrupt status reg RD WR */
   7.143 +#define EN0_CRDALO	EI_SHIFT(0x08)	/* low byte of current remote dma address RD */
   7.144 +#define EN0_RSARLO	EI_SHIFT(0x08)	/* Remote start address reg 0 */
   7.145 +#define EN0_CRDAHI	EI_SHIFT(0x09)	/* high byte, current remote dma address RD */
   7.146 +#define EN0_RSARHI	EI_SHIFT(0x09)	/* Remote start address reg 1 */
   7.147 +#define EN0_RCNTLO	EI_SHIFT(0x0a)	/* Remote byte count reg WR */
   7.148 +#define EN0_RCNTHI	EI_SHIFT(0x0b)	/* Remote byte count reg WR */
   7.149 +#define EN0_RSR		EI_SHIFT(0x0c)	/* rx status reg RD */
   7.150 +#define EN0_RXCR	EI_SHIFT(0x0c)	/* RX configuration reg WR */
   7.151 +#define EN0_TXCR	EI_SHIFT(0x0d)	/* TX configuration reg WR */
   7.152 +#define EN0_COUNTER0	EI_SHIFT(0x0d)	/* Rcv alignment error counter RD */
   7.153 +#define EN0_DCFG	EI_SHIFT(0x0e)	/* Data configuration reg WR */
   7.154 +#define EN0_COUNTER1	EI_SHIFT(0x0e)	/* Rcv CRC error counter RD */
   7.155 +#define EN0_IMR		EI_SHIFT(0x0f)	/* Interrupt mask reg WR */
   7.156 +#define EN0_COUNTER2	EI_SHIFT(0x0f)	/* Rcv missed frame error counter RD */
   7.157 +
   7.158 +/* Bits in EN0_ISR - Interrupt status register */
   7.159 +#define ENISR_RX	0x01	/* Receiver, no error */
   7.160 +#define ENISR_TX	0x02	/* Transmitter, no error */
   7.161 +#define ENISR_RX_ERR	0x04	/* Receiver, with error */
   7.162 +#define ENISR_TX_ERR	0x08	/* Transmitter, with error */
   7.163 +#define ENISR_OVER	0x10	/* Receiver overwrote the ring */
   7.164 +#define ENISR_COUNTERS	0x20	/* Counters need emptying */
   7.165 +#define ENISR_RDC	0x40	/* remote dma complete */
   7.166 +#define ENISR_RESET	0x80	/* Reset completed */
   7.167 +#define ENISR_ALL	0x3f	/* Interrupts we will enable */
   7.168 +
   7.169 +/* Bits in EN0_DCFG - Data config register */
   7.170 +#define ENDCFG_WTS	0x01	/* word transfer mode selection */
   7.171 +#define ENDCFG_BOS	0x02	/* byte order selection */
   7.172 +
   7.173 +/* Page 1 register offsets. */
   7.174 +#define EN1_PHYS   EI_SHIFT(0x01)	/* This board's physical enet addr RD WR */
   7.175 +#define EN1_PHYS_SHIFT(i)  EI_SHIFT(i+1) /* Get and set mac address */
   7.176 +#define EN1_CURPAG EI_SHIFT(0x07)	/* Current memory page RD WR */
   7.177 +#define EN1_MULT   EI_SHIFT(0x08)	/* Multicast filter mask array (8 bytes) RD WR */
   7.178 +#define EN1_MULT_SHIFT(i)  EI_SHIFT(8+i) /* Get and set multicast filter */
   7.179 +
   7.180 +/* Bits in received packet status byte and EN0_RSR*/
   7.181 +#define ENRSR_RXOK	0x01	/* Received a good packet */
   7.182 +#define ENRSR_CRC	0x02	/* CRC error */
   7.183 +#define ENRSR_FAE	0x04	/* frame alignment error */
   7.184 +#define ENRSR_FO	0x08	/* FIFO overrun */
   7.185 +#define ENRSR_MPA	0x10	/* missed pkt */
   7.186 +#define ENRSR_PHY	0x20	/* physical/multicast address */
   7.187 +#define ENRSR_DIS	0x40	/* receiver disable. set in monitor mode */
   7.188 +#define ENRSR_DEF	0x80	/* deferring */
   7.189 +
   7.190 +/* Transmitted packet status, EN0_TSR. */
   7.191 +#define ENTSR_PTX 0x01	/* Packet transmitted without error */
   7.192 +#define ENTSR_ND  0x02	/* The transmit wasn't deferred. */
   7.193 +#define ENTSR_COL 0x04	/* The transmit collided at least once. */
   7.194 +#define ENTSR_ABT 0x08  /* The transmit collided 16 times, and was deferred. */
   7.195 +#define ENTSR_CRS 0x10	/* The carrier sense was lost. */
   7.196 +#define ENTSR_FU  0x20  /* A "FIFO underrun" occurred during transmit. */
   7.197 +#define ENTSR_CDH 0x40	/* The collision detect "heartbeat" signal was lost. */
   7.198 +#define ENTSR_OWC 0x80  /* There was an out-of-window collision. */
   7.199 +
   7.200 +#endif /* _8390_h */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/xen-2.4.16/drivers/net/ne/Makefile	Sun Feb 09 13:47:52 2003 +0000
     8.3 @@ -0,0 +1,8 @@
     8.4 +
     8.5 +include $(BASEDIR)/Rules.mk
     8.6 +
     8.7 +default: $(OBJS)
     8.8 +	$(LD) -r -o ne_drv.o $(OBJS)
     8.9 +
    8.10 +clean:
    8.11 +	rm -f *.o *~ core
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/xen-2.4.16/drivers/net/ne/ne.c	Sun Feb 09 13:47:52 2003 +0000
     9.3 @@ -0,0 +1,685 @@
     9.4 +/* ne.c: A general non-shared-memory NS8390 ethernet driver for linux. */
     9.5 +/*
     9.6 +    Written 1992-94 by Donald Becker.
     9.7 +
     9.8 +    Copyright 1993 United States Government as represented by the
     9.9 +    Director, National Security Agency.
    9.10 +
    9.11 +    This software may be used and distributed according to the terms
    9.12 +    of the GNU General Public License, incorporated herein by reference.
    9.13 +
    9.14 +    The author may be reached as becker@scyld.com, or C/O
    9.15 +    Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403
    9.16 +
    9.17 +    This driver should work with many programmed-I/O 8390-based ethernet
    9.18 +    boards.  Currently it supports the NE1000, NE2000, many clones,
    9.19 +    and some Cabletron products.
    9.20 +
    9.21 +    Changelog:
    9.22 +
    9.23 +    Paul Gortmaker	: use ENISR_RDC to monitor Tx PIO uploads, made
    9.24 +			  sanity checks and bad clone support optional.
    9.25 +    Paul Gortmaker	: new reset code, reset card after probe at boot.
    9.26 +    Paul Gortmaker	: multiple card support for module users.
    9.27 +    Paul Gortmaker	: Support for PCI ne2k clones, similar to lance.c
    9.28 +    Paul Gortmaker	: Allow users with bad cards to avoid full probe.
    9.29 +    Paul Gortmaker	: PCI probe changes, more PCI cards supported.
    9.30 +    rjohnson@analogic.com : Changed init order so an interrupt will only
    9.31 +    occur after memory is allocated for dev->priv. Deallocated memory
    9.32 +    last in cleanup_modue()
    9.33 +    Richard Guenther    : Added support for ISAPnP cards
    9.34 +    Paul Gortmaker	: Discontinued PCI support - use ne2k-pci.c instead.
    9.35 +
    9.36 +*/
    9.37 +
    9.38 +/* Routines for the NatSemi-based designs (NE[12]000). */
    9.39 +
    9.40 +static const char version1[] =
    9.41 +"ne.c:v1.10 9/23/94 Donald Becker (becker@scyld.com)\n";
    9.42 +static const char version2[] =
    9.43 +"Last modified Nov 1, 2000 by Paul Gortmaker\n";
    9.44 +
    9.45 +
    9.46 +#include <xeno/module.h>
    9.47 +#include <xeno/kernel.h>
    9.48 +#include <xeno/sched.h>
    9.49 +#include <xeno/errno.h>
    9.50 +#include <xeno/init.h>
    9.51 +#include <xeno/delay.h>
    9.52 +#include <asm/system.h>
    9.53 +#include <asm/io.h>
    9.54 +
    9.55 +#include <xeno/netdevice.h>
    9.56 +#include <xeno/etherdevice.h>
    9.57 +#include "8390.h"
    9.58 +
    9.59 +/* Some defines that people can play with if so inclined. */
    9.60 +
    9.61 +/* Do we support clones that don't adhere to 14,15 of the SAprom ? */
    9.62 +#define SUPPORT_NE_BAD_CLONES
    9.63 +
    9.64 +/* Do we perform extra sanity checks on stuff ? */
    9.65 +/* #define NE_SANITY_CHECK */
    9.66 +
    9.67 +/* Do we implement the read before write bugfix ? */
    9.68 +/* #define NE_RW_BUGFIX */
    9.69 +
    9.70 +/* Do we have a non std. amount of memory? (in units of 256 byte pages) */
    9.71 +/* #define PACKETBUF_MEMSIZE	0x40 */
    9.72 +
    9.73 +#ifdef SUPPORT_NE_BAD_CLONES
    9.74 +/* A list of bad clones that we none-the-less recognize. */
    9.75 +static struct { const char *name8, *name16; unsigned char SAprefix[4];}
    9.76 +bad_clone_list[] __initdata = {
    9.77 +    {"DE100", "DE200", {0x00, 0xDE, 0x01,}},
    9.78 +    {"DE120", "DE220", {0x00, 0x80, 0xc8,}},
    9.79 +    {"DFI1000", "DFI2000", {'D', 'F', 'I',}}, /* Original, eh?  */
    9.80 +    {"EtherNext UTP8", "EtherNext UTP16", {0x00, 0x00, 0x79}},
    9.81 +    {"NE1000","NE2000-invalid", {0x00, 0x00, 0xd8}}, /* Ancient real NE1000. */
    9.82 +    {"NN1000", "NN2000",  {0x08, 0x03, 0x08}}, /* Outlaw no-name clone. */
    9.83 +    {"4-DIM8","4-DIM16", {0x00,0x00,0x4d,}},  /* Outlaw 4-Dimension cards. */
    9.84 +    {"Con-Intl_8", "Con-Intl_16", {0x00, 0x00, 0x24}}, /* Connect Int'nl */
    9.85 +    {"ET-100","ET-200", {0x00, 0x45, 0x54}}, /* YANG and YA clone */
    9.86 +    {"COMPEX","COMPEX16",{0x00,0x80,0x48}}, /* Broken ISA Compex cards */
    9.87 +    {"E-LAN100", "E-LAN200", {0x00, 0x00, 0x5d}}, /* Broken ne1000 clones */
    9.88 +    {"PCM-4823", "PCM-4823", {0x00, 0xc0, 0x6c}}, /* Broken Advantech MoBo */
    9.89 +    {"REALTEK", "RTL8019", {0x00, 0x00, 0xe8}}, /* no-name with Realtek chip */
    9.90 +    {"LCS-8834", "LCS-8836", {0x04, 0x04, 0x37}}, /* ShinyNet (SET) */
    9.91 +    {0,}
    9.92 +};
    9.93 +#endif
    9.94 +
    9.95 +/* ---- No user-serviceable parts below ---- */
    9.96 +
    9.97 +#define NE_BASE	 (dev->base_addr)
    9.98 +#define NE_CMD	 	0x00
    9.99 +#define NE_DATAPORT	0x10	/* NatSemi-defined port window offset. */
   9.100 +#define NE_RESET	0x1f	/* Issue a read to reset, a write to clear. */
   9.101 +#define NE_IO_EXTENT	0x20
   9.102 +
   9.103 +#define NE1SM_START_PG	0x20	/* First page of TX buffer */
   9.104 +#define NE1SM_STOP_PG 	0x40	/* Last page +1 of RX ring */
   9.105 +#define NESM_START_PG	0x40	/* First page of TX buffer */
   9.106 +#define NESM_STOP_PG	0x80	/* Last page +1 of RX ring */
   9.107 +
   9.108 +int ne_probe(struct net_device *dev);
   9.109 +static int ne_probe1(struct net_device *dev, int ioaddr);
   9.110 +
   9.111 +static int ne_open(struct net_device *dev);
   9.112 +static int ne_close(struct net_device *dev);
   9.113 +
   9.114 +static void ne_reset_8390(struct net_device *dev);
   9.115 +static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
   9.116 +			  int ring_page);
   9.117 +static void ne_block_input(struct net_device *dev, int count,
   9.118 +			  struct sk_buff *skb, int ring_offset);
   9.119 +static void ne_block_output(struct net_device *dev, const int count,
   9.120 +		const unsigned char *buf, const int start_page);
   9.121 +
   9.122 +
   9.123 +/*  Probe for various non-shared-memory ethercards.
   9.124 +
   9.125 +   NEx000-clone boards have a Station Address PROM (SAPROM) in the packet
   9.126 +   buffer memory space.  NE2000 clones have 0x57,0x57 in bytes 0x0e,0x0f of
   9.127 +   the SAPROM, while other supposed NE2000 clones must be detected by their
   9.128 +   SA prefix.
   9.129 +
   9.130 +   Reading the SAPROM from a word-wide card with the 8390 set in byte-wide
   9.131 +   mode results in doubled values, which can be detected and compensated for.
   9.132 +
   9.133 +   The probe is also responsible for initializing the card and filling
   9.134 +   in the 'dev' and 'ei_status' structures.
   9.135 +
   9.136 +   We use the minimum memory size for some ethercard product lines, iff we can't
   9.137 +   distinguish models.  You can increase the packet buffer size by setting
   9.138 +   PACKETBUF_MEMSIZE.  Reported Cabletron packet buffer locations are:
   9.139 +	E1010   starts at 0x100 and ends at 0x2000.
   9.140 +	E1010-x starts at 0x100 and ends at 0x8000. ("-x" means "more memory")
   9.141 +	E2010	 starts at 0x100 and ends at 0x4000.
   9.142 +	E2010-x starts at 0x100 and ends at 0xffff.  */
   9.143 +
   9.144 +int __init ne_probe(struct net_device *dev)
   9.145 +{
   9.146 +	unsigned int base_addr = dev->base_addr;
   9.147 +
   9.148 +	SET_MODULE_OWNER(dev);
   9.149 +
   9.150 +	/* First check any supplied i/o locations. User knows best. <cough> */
   9.151 +	if (base_addr > 0x1ff)	/* Check a single specified location. */
   9.152 +		return ne_probe1(dev, base_addr);
   9.153 +
   9.154 +	return -ENODEV;
   9.155 +}
   9.156 +
   9.157 +static int __init ne_probe1(struct net_device *dev, int ioaddr)
   9.158 +{
   9.159 +	int i;
   9.160 +	unsigned char SA_prom[32];
   9.161 +	int wordlength = 2;
   9.162 +	const char *name = NULL;
   9.163 +	int start_page, stop_page;
   9.164 +	int neX000, ctron, copam, bad_card;
   9.165 +	int reg0, ret;
   9.166 +	static unsigned version_printed;
   9.167 +
   9.168 +	if (!request_region(ioaddr, NE_IO_EXTENT, dev->name))
   9.169 +		return -EBUSY;
   9.170 +
   9.171 +	reg0 = inb_p(ioaddr);
   9.172 +	if (reg0 == 0xFF) {
   9.173 +		ret = -ENODEV;
   9.174 +		goto err_out;
   9.175 +	}
   9.176 +
   9.177 +	/* Do a preliminary verification that we have a 8390. */
   9.178 +	{
   9.179 +		int regd;
   9.180 +		outb_p(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
   9.181 +		regd = inb_p(ioaddr + 0x0d);
   9.182 +		outb_p(0xff, ioaddr + 0x0d);
   9.183 +		outb_p(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
   9.184 +		inb_p(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
   9.185 +		if (inb_p(ioaddr + EN0_COUNTER0) != 0) {
   9.186 +			outb_p(reg0, ioaddr);
   9.187 +			outb_p(regd, ioaddr + 0x0d);	/* Restore the old values. */
   9.188 +			ret = -ENODEV;
   9.189 +			goto err_out;
   9.190 +		}
   9.191 +	}
   9.192 +
   9.193 +	if (ei_debug  &&  version_printed++ == 0)
   9.194 +		printk(KERN_INFO "%s" KERN_INFO "%s", version1, version2);
   9.195 +
   9.196 +	printk(KERN_INFO "NE*000 ethercard probe at %#3x:", ioaddr);
   9.197 +
   9.198 +	/* A user with a poor card that fails to ack the reset, or that
   9.199 +	   does not have a valid 0x57,0x57 signature can still use this
   9.200 +	   without having to recompile. Specifying an i/o address along
   9.201 +	   with an otherwise unused dev->mem_end value of "0xBAD" will
   9.202 +	   cause the driver to skip these parts of the probe. */
   9.203 +
   9.204 +	bad_card = ((dev->base_addr != 0) && (dev->mem_end == 0xbad));
   9.205 +
   9.206 +	/* Reset card. Who knows what dain-bramaged state it was left in. */
   9.207 +
   9.208 +	{
   9.209 +		unsigned long reset_start_time = jiffies;
   9.210 +
   9.211 +		/* DON'T change these to inb_p/outb_p or reset will fail on clones. */
   9.212 +		outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
   9.213 +
   9.214 +		while ((inb_p(ioaddr + EN0_ISR) & ENISR_RESET) == 0)
   9.215 +		if (jiffies - reset_start_time > 2*HZ/100) {
   9.216 +			if (bad_card) {
   9.217 +				printk(" (warning: no reset ack)");
   9.218 +				break;
   9.219 +			} else {
   9.220 +				printk(" not found (no reset ack).\n");
   9.221 +				ret = -ENODEV;
   9.222 +				goto err_out;
   9.223 +			}
   9.224 +		}
   9.225 +
   9.226 +		outb_p(0xff, ioaddr + EN0_ISR);		/* Ack all intr. */
   9.227 +	}
   9.228 +
   9.229 +	/* Read the 16 bytes of station address PROM.
   9.230 +	   We must first initialize registers, similar to NS8390_init(eifdev, 0).
   9.231 +	   We can't reliably read the SAPROM address without this.
   9.232 +	   (I learned the hard way!). */
   9.233 +	{
   9.234 +		struct {unsigned char value, offset; } program_seq[] =
   9.235 +		{
   9.236 +			{E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
   9.237 +			{0x48,	EN0_DCFG},	/* Set byte-wide (0x48) access. */
   9.238 +			{0x00,	EN0_RCNTLO},	/* Clear the count regs. */
   9.239 +			{0x00,	EN0_RCNTHI},
   9.240 +			{0x00,	EN0_IMR},	/* Mask completion irq. */
   9.241 +			{0xFF,	EN0_ISR},
   9.242 +			{E8390_RXOFF, EN0_RXCR},	/* 0x20  Set to monitor */
   9.243 +			{E8390_TXOFF, EN0_TXCR},	/* 0x02  and loopback mode. */
   9.244 +			{32,	EN0_RCNTLO},
   9.245 +			{0x00,	EN0_RCNTHI},
   9.246 +			{0x00,	EN0_RSARLO},	/* DMA starting at 0x0000. */
   9.247 +			{0x00,	EN0_RSARHI},
   9.248 +			{E8390_RREAD+E8390_START, E8390_CMD},
   9.249 +		};
   9.250 +
   9.251 +		for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
   9.252 +			outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
   9.253 +
   9.254 +	}
   9.255 +	for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) {
   9.256 +		SA_prom[i] = inb(ioaddr + NE_DATAPORT);
   9.257 +		SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
   9.258 +		if (SA_prom[i] != SA_prom[i+1])
   9.259 +			wordlength = 1;
   9.260 +	}
   9.261 +
   9.262 +	if (wordlength == 2)
   9.263 +	{
   9.264 +		for (i = 0; i < 16; i++)
   9.265 +			SA_prom[i] = SA_prom[i+i];
   9.266 +		/* We must set the 8390 for word mode. */
   9.267 +		outb_p(0x49, ioaddr + EN0_DCFG);
   9.268 +		start_page = NESM_START_PG;
   9.269 +		stop_page = NESM_STOP_PG;
   9.270 +	} else {
   9.271 +		start_page = NE1SM_START_PG;
   9.272 +		stop_page = NE1SM_STOP_PG;
   9.273 +	}
   9.274 +
   9.275 +	neX000 = (SA_prom[14] == 0x57  &&  SA_prom[15] == 0x57);
   9.276 +	ctron =  (SA_prom[0] == 0x00 && SA_prom[1] == 0x00 && SA_prom[2] == 0x1d);
   9.277 +	copam =  (SA_prom[14] == 0x49 && SA_prom[15] == 0x00);
   9.278 +
   9.279 +	/* Set up the rest of the parameters. */
   9.280 +	if (neX000 || bad_card || copam) {
   9.281 +		name = (wordlength == 2) ? "NE2000" : "NE1000";
   9.282 +	}
   9.283 +	else if (ctron)
   9.284 +	{
   9.285 +		name = (wordlength == 2) ? "Ctron-8" : "Ctron-16";
   9.286 +		start_page = 0x01;
   9.287 +		stop_page = (wordlength == 2) ? 0x40 : 0x20;
   9.288 +	}
   9.289 +	else
   9.290 +	{
   9.291 +#ifdef SUPPORT_NE_BAD_CLONES
   9.292 +		/* Ack!  Well, there might be a *bad* NE*000 clone there.
   9.293 +		   Check for total bogus addresses. */
   9.294 +		for (i = 0; bad_clone_list[i].name8; i++)
   9.295 +		{
   9.296 +			if (SA_prom[0] == bad_clone_list[i].SAprefix[0] &&
   9.297 +				SA_prom[1] == bad_clone_list[i].SAprefix[1] &&
   9.298 +				SA_prom[2] == bad_clone_list[i].SAprefix[2])
   9.299 +			{
   9.300 +				if (wordlength == 2)
   9.301 +				{
   9.302 +					name = bad_clone_list[i].name16;
   9.303 +				} else {
   9.304 +					name = bad_clone_list[i].name8;
   9.305 +				}
   9.306 +				break;
   9.307 +			}
   9.308 +		}
   9.309 +		if (bad_clone_list[i].name8 == NULL)
   9.310 +		{
   9.311 +			printk(" not found (invalid signature %2.2x %2.2x).\n",
   9.312 +				SA_prom[14], SA_prom[15]);
   9.313 +			ret = -ENXIO;
   9.314 +			goto err_out;
   9.315 +		}
   9.316 +#else
   9.317 +		printk(" not found.\n");
   9.318 +		ret = -ENXIO;
   9.319 +		goto err_out;
   9.320 +#endif
   9.321 +	}
   9.322 +
   9.323 +	if (dev->irq < 2)
   9.324 +	{
   9.325 +		unsigned long cookie = probe_irq_on();
   9.326 +		outb_p(0x50, ioaddr + EN0_IMR);	/* Enable one interrupt. */
   9.327 +		outb_p(0x00, ioaddr + EN0_RCNTLO);
   9.328 +		outb_p(0x00, ioaddr + EN0_RCNTHI);
   9.329 +		outb_p(E8390_RREAD+E8390_START, ioaddr); /* Trigger it... */
   9.330 +		mdelay(10);		/* wait 10ms for interrupt to propagate */
   9.331 +		outb_p(0x00, ioaddr + EN0_IMR); 		/* Mask it again. */
   9.332 +		dev->irq = probe_irq_off(cookie);
   9.333 +		if (ei_debug > 2)
   9.334 +			printk(" autoirq is %d\n", dev->irq);
   9.335 +	} else if (dev->irq == 2)
   9.336 +		/* Fixup for users that don't know that IRQ 2 is really IRQ 9,
   9.337 +		   or don't know which one to set. */
   9.338 +		dev->irq = 9;
   9.339 +
   9.340 +	if (! dev->irq) {
   9.341 +		printk(" failed to detect IRQ line.\n");
   9.342 +		ret = -EAGAIN;
   9.343 +		goto err_out;
   9.344 +	}
   9.345 +
   9.346 +	/* Allocate dev->priv and fill in 8390 specific dev fields. */
   9.347 +	if (ethdev_init(dev))
   9.348 +	{
   9.349 +        	printk (" unable to get memory for dev->priv.\n");
   9.350 +        	ret = -ENOMEM;
   9.351 +		goto err_out;
   9.352 +	}
   9.353 +
   9.354 +	/* Snarf the interrupt now.  There's no point in waiting since we cannot
   9.355 +	   share and the board will usually be enabled. */
   9.356 +	ret = request_irq(dev->irq, ei_interrupt, 0, name, dev);
   9.357 +	if (ret) {
   9.358 +		printk (" unable to get IRQ %d (errno=%d).\n", dev->irq, ret);
   9.359 +		goto err_out_kfree;
   9.360 +	}
   9.361 +
   9.362 +	dev->base_addr = ioaddr;
   9.363 +
   9.364 +	for(i = 0; i < ETHER_ADDR_LEN; i++) {
   9.365 +		printk(" %2.2x", SA_prom[i]);
   9.366 +		dev->dev_addr[i] = SA_prom[i];
   9.367 +	}
   9.368 +
   9.369 +	printk("\n%s: %s found at %#x, using IRQ %d.\n",
   9.370 +		dev->name, name, ioaddr, dev->irq);
   9.371 +
   9.372 +	ei_status.name = name;
   9.373 +	ei_status.tx_start_page = start_page;
   9.374 +	ei_status.stop_page = stop_page;
   9.375 +	ei_status.word16 = (wordlength == 2);
   9.376 +
   9.377 +	ei_status.rx_start_page = start_page + TX_PAGES;
   9.378 +#ifdef PACKETBUF_MEMSIZE
   9.379 +	 /* Allow the packet buffer size to be overridden by know-it-alls. */
   9.380 +	ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
   9.381 +#endif
   9.382 +
   9.383 +	ei_status.reset_8390 = &ne_reset_8390;
   9.384 +	ei_status.block_input = &ne_block_input;
   9.385 +	ei_status.block_output = &ne_block_output;
   9.386 +	ei_status.get_8390_hdr = &ne_get_8390_hdr;
   9.387 +	ei_status.priv = 0;
   9.388 +	dev->open = &ne_open;
   9.389 +	dev->stop = &ne_close;
   9.390 +	NS8390_init(dev, 0);
   9.391 +	return 0;
   9.392 +
   9.393 +err_out_kfree:
   9.394 +	kfree(dev->priv);
   9.395 +	dev->priv = NULL;
   9.396 +err_out:
   9.397 +	release_region(ioaddr, NE_IO_EXTENT);
   9.398 +	return ret;
   9.399 +}
   9.400 +
   9.401 +static int ne_open(struct net_device *dev)
   9.402 +{
   9.403 +	ei_open(dev);
   9.404 +	return 0;
   9.405 +}
   9.406 +
   9.407 +static int ne_close(struct net_device *dev)
   9.408 +{
   9.409 +	if (ei_debug > 1)
   9.410 +		printk(KERN_DEBUG "%s: Shutting down ethercard.\n", dev->name);
   9.411 +	ei_close(dev);
   9.412 +	return 0;
   9.413 +}
   9.414 +
   9.415 +/* Hard reset the card.  This used to pause for the same period that a
   9.416 +   8390 reset command required, but that shouldn't be necessary. */
   9.417 +
   9.418 +static void ne_reset_8390(struct net_device *dev)
   9.419 +{
   9.420 +	unsigned long reset_start_time = jiffies;
   9.421 +
   9.422 +	if (ei_debug > 1)
   9.423 +		printk(KERN_DEBUG "resetting the 8390 t=%ld...", jiffies);
   9.424 +
   9.425 +	/* DON'T change these to inb_p/outb_p or reset will fail on clones. */
   9.426 +	outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
   9.427 +
   9.428 +	ei_status.txing = 0;
   9.429 +	ei_status.dmaing = 0;
   9.430 +
   9.431 +	/* This check _should_not_ be necessary, omit eventually. */
   9.432 +	while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
   9.433 +		if (jiffies - reset_start_time > 2*HZ/100) {
   9.434 +			printk(KERN_WARNING "%s: ne_reset_8390() did not complete.\n", dev->name);
   9.435 +			break;
   9.436 +		}
   9.437 +	outb_p(ENISR_RESET, NE_BASE + EN0_ISR);	/* Ack intr. */
   9.438 +}
   9.439 +
   9.440 +/* Grab the 8390 specific header. Similar to the block_input routine, but
   9.441 +   we don't need to be concerned with ring wrap as the header will be at
   9.442 +   the start of a page, so we optimize accordingly. */
   9.443 +
   9.444 +static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
   9.445 +{
   9.446 +	int nic_base = dev->base_addr;
   9.447 +
   9.448 +	/* This *shouldn't* happen. If it does, it's the last thing you'll see */
   9.449 +
   9.450 +	if (ei_status.dmaing)
   9.451 +	{
   9.452 +		printk(KERN_EMERG "%s: DMAing conflict in ne_get_8390_hdr "
   9.453 +			"[DMAstat:%d][irqlock:%d].\n",
   9.454 +			dev->name, ei_status.dmaing, ei_status.irqlock);
   9.455 +		return;
   9.456 +	}
   9.457 +
   9.458 +	ei_status.dmaing |= 0x01;
   9.459 +	outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
   9.460 +	outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
   9.461 +	outb_p(0, nic_base + EN0_RCNTHI);
   9.462 +	outb_p(0, nic_base + EN0_RSARLO);		/* On page boundary */
   9.463 +	outb_p(ring_page, nic_base + EN0_RSARHI);
   9.464 +	outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
   9.465 +
   9.466 +	if (ei_status.word16)
   9.467 +		insw(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
   9.468 +	else
   9.469 +		insb(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr));
   9.470 +
   9.471 +	outb_p(ENISR_RDC, nic_base + EN0_ISR);	/* Ack intr. */
   9.472 +	ei_status.dmaing &= ~0x01;
   9.473 +
   9.474 +	le16_to_cpus(&hdr->count);
   9.475 +}
   9.476 +
   9.477 +/* Block input and output, similar to the Crynwr packet driver.  If you
   9.478 +   are porting to a new ethercard, look at the packet driver source for hints.
   9.479 +   The NEx000 doesn't share the on-board packet memory -- you have to put
   9.480 +   the packet out through the "remote DMA" dataport using outb. */
   9.481 +
   9.482 +static void ne_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
   9.483 +{
   9.484 +#ifdef NE_SANITY_CHECK
   9.485 +	int xfer_count = count;
   9.486 +#endif
   9.487 +	int nic_base = dev->base_addr;
   9.488 +	char *buf = skb->data;
   9.489 +
   9.490 +	/* This *shouldn't* happen. If it does, it's the last thing you'll see */
   9.491 +	if (ei_status.dmaing)
   9.492 +	{
   9.493 +		printk(KERN_EMERG "%s: DMAing conflict in ne_block_input "
   9.494 +			"[DMAstat:%d][irqlock:%d].\n",
   9.495 +			dev->name, ei_status.dmaing, ei_status.irqlock);
   9.496 +		return;
   9.497 +	}
   9.498 +	ei_status.dmaing |= 0x01;
   9.499 +	outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
   9.500 +	outb_p(count & 0xff, nic_base + EN0_RCNTLO);
   9.501 +	outb_p(count >> 8, nic_base + EN0_RCNTHI);
   9.502 +	outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
   9.503 +	outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
   9.504 +	outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
   9.505 +	if (ei_status.word16)
   9.506 +	{
   9.507 +		insw(NE_BASE + NE_DATAPORT,buf,count>>1);
   9.508 +		if (count & 0x01)
   9.509 +		{
   9.510 +			buf[count-1] = inb(NE_BASE + NE_DATAPORT);
   9.511 +#ifdef NE_SANITY_CHECK
   9.512 +			xfer_count++;
   9.513 +#endif
   9.514 +		}
   9.515 +	} else {
   9.516 +		insb(NE_BASE + NE_DATAPORT, buf, count);
   9.517 +	}
   9.518 +
   9.519 +#ifdef NE_SANITY_CHECK
   9.520 +	/* This was for the ALPHA version only, but enough people have
   9.521 +	   been encountering problems so it is still here.  If you see
   9.522 +	   this message you either 1) have a slightly incompatible clone
   9.523 +	   or 2) have noise/speed problems with your bus. */
   9.524 +
   9.525 +	if (ei_debug > 1)
   9.526 +	{
   9.527 +		/* DMA termination address check... */
   9.528 +		int addr, tries = 20;
   9.529 +		do {
   9.530 +			/* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
   9.531 +			   -- it's broken for Rx on some cards! */
   9.532 +			int high = inb_p(nic_base + EN0_RSARHI);
   9.533 +			int low = inb_p(nic_base + EN0_RSARLO);
   9.534 +			addr = (high << 8) + low;
   9.535 +			if (((ring_offset + xfer_count) & 0xff) == low)
   9.536 +				break;
   9.537 +		} while (--tries > 0);
   9.538 +	 	if (tries <= 0)
   9.539 +			printk(KERN_WARNING "%s: RX transfer address mismatch,"
   9.540 +				"%#4.4x (expected) vs. %#4.4x (actual).\n",
   9.541 +				dev->name, ring_offset + xfer_count, addr);
   9.542 +	}
   9.543 +#endif
   9.544 +	outb_p(ENISR_RDC, nic_base + EN0_ISR);	/* Ack intr. */
   9.545 +	ei_status.dmaing &= ~0x01;
   9.546 +}
   9.547 +
   9.548 +static void ne_block_output(struct net_device *dev, int count,
   9.549 +		const unsigned char *buf, const int start_page)
   9.550 +{
   9.551 +	int nic_base = NE_BASE;
   9.552 +	unsigned long dma_start;
   9.553 +#ifdef NE_SANITY_CHECK
   9.554 +	int retries = 0;
   9.555 +#endif
   9.556 +
   9.557 +	/* Round the count up for word writes.  Do we need to do this?
   9.558 +	   What effect will an odd byte count have on the 8390?
   9.559 +	   I should check someday. */
   9.560 +
   9.561 +	if (ei_status.word16 && (count & 0x01))
   9.562 +		count++;
   9.563 +
   9.564 +	/* This *shouldn't* happen. If it does, it's the last thing you'll see */
   9.565 +	if (ei_status.dmaing)
   9.566 +	{
   9.567 +		printk(KERN_EMERG "%s: DMAing conflict in ne_block_output."
   9.568 +			"[DMAstat:%d][irqlock:%d]\n",
   9.569 +			dev->name, ei_status.dmaing, ei_status.irqlock);
   9.570 +		return;
   9.571 +	}
   9.572 +	ei_status.dmaing |= 0x01;
   9.573 +	/* We should already be in page 0, but to be safe... */
   9.574 +	outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
   9.575 +
   9.576 +#ifdef NE_SANITY_CHECK
   9.577 +retry:
   9.578 +#endif
   9.579 +
   9.580 +#ifdef NE8390_RW_BUGFIX
   9.581 +	/* Handle the read-before-write bug the same way as the
   9.582 +	   Crynwr packet driver -- the NatSemi method doesn't work.
   9.583 +	   Actually this doesn't always work either, but if you have
   9.584 +	   problems with your NEx000 this is better than nothing! */
   9.585 +
   9.586 +	outb_p(0x42, nic_base + EN0_RCNTLO);
   9.587 +	outb_p(0x00,   nic_base + EN0_RCNTHI);
   9.588 +	outb_p(0x42, nic_base + EN0_RSARLO);
   9.589 +	outb_p(0x00, nic_base + EN0_RSARHI);
   9.590 +	outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
   9.591 +	/* Make certain that the dummy read has occurred. */
   9.592 +	udelay(6);
   9.593 +#endif
   9.594 +
   9.595 +	outb_p(ENISR_RDC, nic_base + EN0_ISR);
   9.596 +
   9.597 +	/* Now the normal output. */
   9.598 +	outb_p(count & 0xff, nic_base + EN0_RCNTLO);
   9.599 +	outb_p(count >> 8,   nic_base + EN0_RCNTHI);
   9.600 +	outb_p(0x00, nic_base + EN0_RSARLO);
   9.601 +	outb_p(start_page, nic_base + EN0_RSARHI);
   9.602 +
   9.603 +	outb_p(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
   9.604 +	if (ei_status.word16) {
   9.605 +		outsw(NE_BASE + NE_DATAPORT, buf, count>>1);
   9.606 +	} else {
   9.607 +		outsb(NE_BASE + NE_DATAPORT, buf, count);
   9.608 +	}
   9.609 +
   9.610 +	dma_start = jiffies;
   9.611 +
   9.612 +#ifdef NE_SANITY_CHECK
   9.613 +	/* This was for the ALPHA version only, but enough people have
   9.614 +	   been encountering problems so it is still here. */
   9.615 +
   9.616 +	if (ei_debug > 1)
   9.617 +	{
   9.618 +		/* DMA termination address check... */
   9.619 +		int addr, tries = 20;
   9.620 +		do {
   9.621 +			int high = inb_p(nic_base + EN0_RSARHI);
   9.622 +			int low = inb_p(nic_base + EN0_RSARLO);
   9.623 +			addr = (high << 8) + low;
   9.624 +			if ((start_page << 8) + count == addr)
   9.625 +				break;
   9.626 +		} while (--tries > 0);
   9.627 +
   9.628 +		if (tries <= 0)
   9.629 +		{
   9.630 +			printk(KERN_WARNING "%s: Tx packet transfer address mismatch,"
   9.631 +				"%#4.4x (expected) vs. %#4.4x (actual).\n",
   9.632 +				dev->name, (start_page << 8) + count, addr);
   9.633 +			if (retries++ == 0)
   9.634 +				goto retry;
   9.635 +		}
   9.636 +	}
   9.637 +#endif
   9.638 +
   9.639 +	while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
   9.640 +		if (jiffies - dma_start > 2*HZ/100) {		/* 20ms */
   9.641 +			printk(KERN_WARNING "%s: timeout waiting for Tx RDC.\n", dev->name);
   9.642 +			ne_reset_8390(dev);
   9.643 +			NS8390_init(dev,1);
   9.644 +			break;
   9.645 +		}
   9.646 +
   9.647 +	outb_p(ENISR_RDC, nic_base + EN0_ISR);	/* Ack intr. */
   9.648 +	ei_status.dmaing &= ~0x01;
   9.649 +	return;
   9.650 +}
   9.651 +
   9.652 +static struct net_device dev_ne;
   9.653 +
   9.654 +static int __init init_module(void)
   9.655 +{
   9.656 +    struct net_device *dev = &dev_ne;
   9.657 +    extern unsigned int opt_ne_base;
   9.658 +
   9.659 +    if ( opt_ne_base == 0 ) return 0;
   9.660 +
   9.661 +    dev->irq = 0;
   9.662 +    dev->mem_end = 0;
   9.663 +    dev->base_addr = opt_ne_base;
   9.664 +    dev->init = ne_probe;
   9.665 +
   9.666 +    if ( register_netdev(dev) != 0 )
   9.667 +    {
   9.668 +        printk(KERN_WARNING "ne.c: No card found at io %#x\n", opt_ne_base);
   9.669 +    }
   9.670 +
   9.671 +    return 0;
   9.672 +}
   9.673 +
   9.674 +static void __exit cleanup_module(void)
   9.675 +{
   9.676 +    struct net_device *dev = &dev_ne;
   9.677 +    if ( dev->priv != NULL )
   9.678 +    {
   9.679 +        void *priv = dev->priv;
   9.680 +        free_irq(dev->irq, dev);
   9.681 +        release_region(dev->base_addr, NE_IO_EXTENT);
   9.682 +        unregister_netdev(dev);
   9.683 +        kfree(priv);
   9.684 +    }
   9.685 +}
   9.686 +
   9.687 +module_init(init_module);
   9.688 +module_exit(cleanup_module);
    10.1 --- a/xen-2.4.16/include/xeno/config.h	Sun Feb 09 11:48:49 2003 +0000
    10.2 +++ b/xen-2.4.16/include/xeno/config.h	Sun Feb 09 13:47:52 2003 +0000
    10.3 @@ -7,6 +7,8 @@
    10.4  #ifndef __XENO_CONFIG_H__
    10.5  #define __XENO_CONFIG_H__
    10.6  
    10.7 +#define CONFIG_X86 1
    10.8 +
    10.9  #define CONFIG_SMP 1
   10.10  #define CONFIG_X86_LOCAL_APIC 1
   10.11  #define CONFIG_X86_IO_APIC 1
    11.1 --- a/xen-2.4.16/include/xeno/in.h	Sun Feb 09 11:48:49 2003 +0000
    11.2 +++ b/xen-2.4.16/include/xeno/in.h	Sun Feb 09 13:47:52 2003 +0000
    11.3 @@ -18,7 +18,8 @@
    11.4  #ifndef _LINUX_IN_H
    11.5  #define _LINUX_IN_H
    11.6  
    11.7 -#include <linux/types.h>
    11.8 +#include <xeno/types.h>
    11.9 +#include <xeno/socket.h>
   11.10  
   11.11  /* Standard well-defined IP protocols.  */
   11.12  enum {