aboutsummaryrefslogblamecommitdiffstats
path: root/drivers/net/82596.c
blob: da292e647eb117c496e3c4c6f6108e0e8c316c94 (plain) (tree)









































                                                                               
















                              
                           











































































































































































































































































                                                                                






























                                                                                  
                                                         
                                              



















































































                                                                                                    
 









                                                             
 












































                                                                                             
                                                    










































                                                                                   

                                                                

                                       
                                                                 






























































                                                                   
                                                                                            












































































































































































                                                                                             
 


























                                                                             

                                                                                   
                  
                                                                                    







                                                                                                                 
                                                        

                              







                                                                                           
                                                                         



                                                         

                                                             




                                                                                           
                                               
                                                 
                                                        
                                                 
                                                              
                                                 
                                                            
                                                 
                                                            
                                                 
                                                             
                                                 
                                                           
                                                 
                                                              
































                                                                          
                                                                             















                                                                              

                                                               













                                                                            

                                                                       







































































































                                                                                                 
                               

                                        
                                                        







                                                                      
                                                         














                                                                       

                                                                                

                                  
                                             










                                                                            
                                        























                                                                  

                                              








                                                    

                              
 


                                                                  







































                                                                                                
                           













                                                                                           
                           















                                                                                     

                                        










                                                                               
                                         




                                                                 
                              
                           

         



                      















                                                                                          


                                               






                                                     

                                                                        



































                                                                                
                                                        









                                                                  
                                                















































                                                                                                                                      
                                                               
                                                                   
                                                                        
                                                                      
                                                                                 
                                                                   
                                                                               
                                                                   
                                                                        
                                                                   
                                                                               





















































                                                                                                                                              

                                                            

















































































                                                                                          












































                                                                                                        
 



                                        
                                     









                                                                                                    

                                                                                         
















                                             
                            








                                          
                                


















                                                                        
 




                                                                                                                
/* 82596.c: A generic 82596 ethernet driver for linux. */
/*
   Based on Apricot.c
   Written 1994 by Mark Evans.
   This driver is for the Apricot 82596 bus-master interface

   Modularised 12/94 Mark Evans


   Modified to support the 82596 ethernet chips on 680x0 VME boards.
   by Richard Hirst <richard@sleepie.demon.co.uk>
   Renamed to be 82596.c

   980825:  Changed to receive directly in to sk_buffs which are
   allocated at open() time.  Eliminates copy on incoming frames
   (small ones are still copied).  Shared data now held in a
   non-cached page, so we can run on 68060 in copyback mode.

   TBD:
   * look at deferring rx frames rather than discarding (as per tulip)
   * handle tx ring full as per tulip
   * performace test to tune rx_copybreak

   Most of my modifications relate to the braindead big-endian
   implementation by Intel.  When the i596 is operating in
   'big-endian' mode, it thinks a 32 bit value of 0x12345678
   should be stored as 0x56781234.  This is a real pain, when
   you have linked lists which are shared by the 680x0 and the
   i596.

   Driver skeleton
   Written 1993 by Donald Becker.
   Copyright 1993 United States Government as represented by the Director,
   National Security Agency. This software may only be used and distributed
   according to the terms of the GNU General Public License as modified by SRC,
   incorporated herein by reference.

   The author may be reached as becker@scyld.com, or C/O
   Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403

 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/ioport.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/init.h>
#include <linux/bitops.h>

#include <asm/io.h>
#include <asm/dma.h>
#include <asm/pgtable.h>
#include <asm/cacheflush.h>

static char version[] __initdata =
	"82596.c $Revision: 1.5 $\n";

#define DRV_NAME	"82596"

/* DEBUG flags
 */

#define DEB_INIT	0x0001
#define DEB_PROBE	0x0002
#define DEB_SERIOUS	0x0004
#define DEB_ERRORS	0x0008
#define DEB_MULTI	0x0010
#define DEB_TDR		0x0020
#define DEB_OPEN	0x0040
#define DEB_RESET	0x0080
#define DEB_ADDCMD	0x0100
#define DEB_STATUS	0x0200
#define DEB_STARTTX	0x0400
#define DEB_RXADDR	0x0800
#define DEB_TXADDR	0x1000
#define DEB_RXFRAME	0x2000
#define DEB_INTS	0x4000
#define DEB_STRUCT	0x8000
#define DEB_ANY		0xffff


#define DEB(x,y)	if (i596_debug & (x)) y


#if defined(CONFIG_MVME16x_NET) || defined(CONFIG_MVME16x_NET_MODULE)
#define ENABLE_MVME16x_NET
#endif
#if defined(CONFIG_BVME6000_NET) || defined(CONFIG_BVME6000_NET_MODULE)
#define ENABLE_BVME6000_NET
#endif
#if defined(CONFIG_APRICOT) || defined(CONFIG_APRICOT_MODULE)
#define ENABLE_APRICOT
#endif

#ifdef ENABLE_MVME16x_NET
#include <asm/mvme16xhw.h>
#endif
#ifdef ENABLE_BVME6000_NET
#include <asm/bvme6000hw.h>
#endif

/*
 * Define various macros for Channel Attention, word swapping etc., dependent
 * on architecture.  MVME and BVME are 680x0 based, otherwise it is Intel.
 */

#ifdef __mc68000__
#define WSWAPrfd(x)  ((struct i596_rfd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define WSWAPrbd(x)  ((struct i596_rbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define WSWAPiscp(x) ((struct i596_iscp *)(((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define WSWAPscb(x)  ((struct i596_scb *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define WSWAPcmd(x)  ((struct i596_cmd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define WSWAPtbd(x)  ((struct i596_tbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define WSWAPchar(x) ((char *)            (((u32)(x)<<16) | ((((u32)(x)))>>16)))
#define ISCP_BUSY	0x00010000
#define MACH_IS_APRICOT	0
#else
#define WSWAPrfd(x)     ((struct i596_rfd *)(x))
#define WSWAPrbd(x)     ((struct i596_rbd *)(x))
#define WSWAPiscp(x)    ((struct i596_iscp *)(x))
#define WSWAPscb(x)     ((struct i596_scb *)(x))
#define WSWAPcmd(x)     ((struct i596_cmd *)(x))
#define WSWAPtbd(x)     ((struct i596_tbd *)(x))
#define WSWAPchar(x)    ((char *)(x))
#define ISCP_BUSY	0x0001
#define MACH_IS_APRICOT	1
#endif

/*
 * The MPU_PORT command allows direct access to the 82596. With PORT access
 * the following commands are available (p5-18). The 32-bit port command
 * must be word-swapped with the most significant word written first.
 * This only applies to VME boards.
 */
#define PORT_RESET		0x00	/* reset 82596 */
#define PORT_SELFTEST		0x01	/* selftest */
#define PORT_ALTSCP		0x02	/* alternate SCB address */
#define PORT_ALTDUMP		0x03	/* Alternate DUMP address */

static int i596_debug = (DEB_SERIOUS|DEB_PROBE);

MODULE_AUTHOR("Richard Hirst");
MODULE_DESCRIPTION("i82596 driver");
MODULE_LICENSE("GPL");

module_param(i596_debug, int, 0);
MODULE_PARM_DESC(i596_debug, "i82596 debug mask");


/* Copy frames shorter than rx_copybreak, otherwise pass on up in
 * a full sized sk_buff.  Value of 100 stolen from tulip.c (!alpha).
 */
static int rx_copybreak = 100;

#define PKT_BUF_SZ	1536
#define MAX_MC_CNT	64

#define I596_TOTAL_SIZE 17

#define I596_NULL ((void *)0xffffffff)

#define CMD_EOL		0x8000	/* The last command of the list, stop. */
#define CMD_SUSP	0x4000	/* Suspend after doing cmd. */
#define CMD_INTR	0x2000	/* Interrupt after doing cmd. */

#define CMD_FLEX	0x0008	/* Enable flexible memory model */

enum commands {
	CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
	CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7
};

#define STAT_C		0x8000	/* Set to 0 after execution */
#define STAT_B		0x4000	/* Command being executed */
#define STAT_OK		0x2000	/* Command executed ok */
#define STAT_A		0x1000	/* Command aborted */

#define	 CUC_START	0x0100
#define	 CUC_RESUME	0x0200
#define	 CUC_SUSPEND    0x0300
#define	 CUC_ABORT	0x0400
#define	 RX_START	0x0010
#define	 RX_RESUME	0x0020
#define	 RX_SUSPEND	0x0030
#define	 RX_ABORT	0x0040

#define TX_TIMEOUT	5


struct i596_reg {
	unsigned short porthi;
	unsigned short portlo;
	unsigned long ca;
};

#define EOF		0x8000
#define SIZE_MASK	0x3fff

struct i596_tbd {
	unsigned short size;
	unsigned short pad;
	struct i596_tbd *next;
	char *data;
};

/* The command structure has two 'next' pointers; v_next is the address of
 * the next command as seen by the CPU, b_next is the address of the next
 * command as seen by the 82596.  The b_next pointer, as used by the 82596
 * always references the status field of the next command, rather than the
 * v_next field, because the 82596 is unaware of v_next.  It may seem more
 * logical to put v_next at the end of the structure, but we cannot do that
 * because the 82596 expects other fields to be there, depending on command
 * type.
 */

struct i596_cmd {
	struct i596_cmd *v_next;	/* Address from CPUs viewpoint */
	unsigned short status;
	unsigned short command;
	struct i596_cmd *b_next;	/* Address from i596 viewpoint */
};

struct tx_cmd {
	struct i596_cmd cmd;
	struct i596_tbd *tbd;
	unsigned short size;
	unsigned short pad;
	struct sk_buff *skb;	/* So we can free it after tx */
};

struct tdr_cmd {
	struct i596_cmd cmd;
	unsigned short status;
	unsigned short pad;
};

struct mc_cmd {
	struct i596_cmd cmd;
	short mc_cnt;
	char mc_addrs[MAX_MC_CNT*6];
};

struct sa_cmd {
	struct i596_cmd cmd;
	char eth_addr[8];
};

struct cf_cmd {
	struct i596_cmd cmd;
	char i596_config[16];
};

struct i596_rfd {
	unsigned short stat;
	unsigned short cmd;
	struct i596_rfd *b_next;	/* Address from i596 viewpoint */
	struct i596_rbd *rbd;
	unsigned short count;
	unsigned short size;
	struct i596_rfd *v_next;	/* Address from CPUs viewpoint */
	struct i596_rfd *v_prev;
};

struct i596_rbd {
    unsigned short count;
    unsigned short zero1;
    struct i596_rbd *b_next;
    unsigned char *b_data;		/* Address from i596 viewpoint */
    unsigned short size;
    unsigned short zero2;
    struct sk_buff *skb;
    struct i596_rbd *v_next;
    struct i596_rbd *b_addr;		/* This rbd addr from i596 view */
    unsigned char *v_data;		/* Address from CPUs viewpoint */
};

#define TX_RING_SIZE 64
#define RX_RING_SIZE 16

struct i596_scb {
	unsigned short status;
	unsigned short command;
	struct i596_cmd *cmd;
	struct i596_rfd *rfd;
	unsigned long crc_err;
	unsigned long align_err;
	unsigned long resource_err;
	unsigned long over_err;
	unsigned long rcvdt_err;
	unsigned long short_err;
	unsigned short t_on;
	unsigned short t_off;
};

struct i596_iscp {
	unsigned long stat;
	struct i596_scb *scb;
};

struct i596_scp {
	unsigned long sysbus;
	unsigned long pad;
	struct i596_iscp *iscp;
};

struct i596_private {
	volatile struct i596_scp scp;
	volatile struct i596_iscp iscp;
	volatile struct i596_scb scb;
	struct sa_cmd sa_cmd;
	struct cf_cmd cf_cmd;
	struct tdr_cmd tdr_cmd;
	struct mc_cmd mc_cmd;
	unsigned long stat;
	int last_restart __attribute__((aligned(4)));
	struct i596_rfd *rfd_head;
	struct i596_rbd *rbd_head;
	struct i596_cmd *cmd_tail;
	struct i596_cmd *cmd_head;
	int cmd_backlog;
	unsigned long last_cmd;
	struct i596_rfd rfds[RX_RING_SIZE];
	struct i596_rbd rbds[RX_RING_SIZE];
	struct tx_cmd tx_cmds[TX_RING_SIZE];
	struct i596_tbd tbds[TX_RING_SIZE];
	int next_tx_cmd;
	spinlock_t lock;
};

static char init_setup[] =
{
	0x8E,			/* length, prefetch on */
	0xC8,			/* fifo to 8, monitor off */
#ifdef CONFIG_VME
	0xc0,			/* don't save bad frames */
#else
	0x80,			/* don't save bad frames */
#endif
	0x2E,			/* No source address insertion, 8 byte preamble */
	0x00,			/* priority and backoff defaults */
	0x60,			/* interframe spacing */
	0x00,			/* slot time LSB */
	0xf2,			/* slot time and retries */
	0x00,			/* promiscuous mode */
	0x00,			/* collision detect */
	0x40,			/* minimum frame length */
	0xff,
	0x00,
	0x7f /*  *multi IA */ };

static int i596_open(struct net_device *dev);
static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev);
static irqreturn_t i596_interrupt(int irq, void *dev_id);
static int i596_close(struct net_device *dev);
static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);
static void i596_tx_timeout (struct net_device *dev);
static void print_eth(unsigned char *buf, char *str);
static void set_multicast_list(struct net_device *dev);

static int rx_ring_size = RX_RING_SIZE;
static int ticks_limit = 25;
static int max_cmd_backlog = TX_RING_SIZE-1;


static inline void CA(struct net_device *dev)
{
#ifdef ENABLE_MVME16x_NET
	if (MACH_IS_MVME16x) {
		((struct i596_reg *) dev->base_addr)->ca = 1;
	}
#endif
#ifdef ENABLE_BVME6000_NET
	if (MACH_IS_BVME6000) {
		volatile u32 i;

		i = *(volatile u32 *) (dev->base_addr);
	}
#endif
#ifdef ENABLE_APRICOT
	if (MACH_IS_APRICOT) {
		outw(0, (short) (dev->base_addr) + 4);
	}
#endif
}


static inline void MPU_PORT(struct net_device *dev, int c, volatile void *x)
{
#ifdef ENABLE_MVME16x_NET
	if (MACH_IS_MVME16x) {
		struct i596_reg *p = (struct i596_reg *) (dev->base_addr);
		p->porthi = ((c) | (u32) (x)) & 0xffff;
		p->portlo = ((c) | (u32) (x)) >> 16;
	}
#endif
#ifdef ENABLE_BVME6000_NET
	if (MACH_IS_BVME6000) {
		u32 v = (u32) (c) | (u32) (x);
		v = ((u32) (v) << 16) | ((u32) (v) >> 16);
		*(volatile u32 *) dev->base_addr = v;
		udelay(1);
		*(volatile u32 *) dev->base_addr = v;
	}
#endif
}


static inline int wait_istat(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
{
	while (--delcnt && lp->iscp.stat)
		udelay(10);
	if (!delcnt) {
		printk(KERN_ERR "%s: %s, status %4.4x, cmd %4.4x.\n",
		     dev->name, str, lp->scb.status, lp->scb.command);
		return -1;
	}
	else
		return 0;
}


static inline int wait_cmd(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
{
	while (--delcnt && lp->scb.command)
		udelay(10);
	if (!delcnt) {
		printk(KERN_ERR "%s: %s, status %4.4x, cmd %4.4x.\n",
		     dev->name, str, lp->scb.status, lp->scb.command);
		return -1;
	}
	else
		return 0;
}


static inline int wait_cfg(struct net_device *dev, struct i596_cmd *cmd, int delcnt, char *str)
{
	volatile struct i596_cmd *c = cmd;

	while (--delcnt && c->command)
		udelay(10);
	if (!delcnt) {
		printk(KERN_ERR "%s: %s.\n", dev->name, str);
		return -1;
	}
	else
		return 0;
}


static void i596_display_data(struct net_device *dev)
{
	struct i596_private *lp = dev->priv;
	struct i596_cmd *cmd;
	struct i596_rfd *rfd;
	struct i596_rbd *rbd;

	printk(KERN_ERR "lp and scp at %p, .sysbus = %08lx, .iscp = %p\n",
	       &lp->scp, lp->scp.sysbus, lp->scp.iscp);
	printk(KERN_ERR "iscp at %p, iscp.stat = %08lx, .scb = %p\n",
	       &lp->iscp, lp->iscp.stat, lp->iscp.scb);
	printk(KERN_ERR "scb at %p, scb.status = %04x, .command = %04x,"
		" .cmd = %p, .rfd = %p\n",
	       &lp->scb, lp->scb.status, lp->scb.command,
		lp->scb.cmd, lp->scb.rfd);
	printk(KERN_ERR "   errors: crc %lx, align %lx, resource %lx,"
               " over %lx, rcvdt %lx, short %lx\n",
		lp->scb.crc_err, lp->scb.align_err, lp->scb.resource_err,
		lp->scb.over_err, lp->scb.rcvdt_err, lp->scb.short_err);
	cmd = lp->cmd_head;
	while (cmd != I596_NULL) {
		printk(KERN_ERR "cmd at %p, .status = %04x, .command = %04x, .b_next = %p\n",
		  cmd, cmd->status, cmd->command, cmd->b_next);
		cmd = cmd->v_next;
	}
	rfd = lp->rfd_head;
	printk(KERN_ERR "rfd_head = %p\n", rfd);
	do {
		printk(KERN_ERR "   %p .stat %04x, .cmd %04x, b_next %p, rbd %p,"
                        " count %04x\n",
			rfd, rfd->stat, rfd->cmd, rfd->b_next, rfd->rbd,
			rfd->count);
		rfd = rfd->v_next;
	} while (rfd != lp->rfd_head);
	rbd = lp->rbd_head;
	printk(KERN_ERR "rbd_head = %p\n", rbd);
	do {
		printk(KERN_ERR "   %p .count %04x, b_next %p, b_data %p, size %04x\n",
			rbd, rbd->count, rbd->b_next, rbd->b_data, rbd->size);
		rbd = rbd->v_next;
	} while (rbd != lp->rbd_head);
}


#if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
static irqreturn_t i596_error(int irq, void *dev_id)
{
	struct net_device *dev = dev_id;
#ifdef ENABLE_MVME16x_NET
	if (MACH_IS_MVME16x) {
		volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;

		pcc2[0x28] = 1;
		pcc2[0x2b] = 0x1d;
	}
#endif
#ifdef ENABLE_BVME6000_NET
	if (MACH_IS_BVME6000) {
		volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;

		*ethirq = 1;
		*ethirq = 3;
	}
#endif
	printk(KERN_ERR "%s: Error interrupt\n", dev->name);
	i596_display_data(dev);
	return IRQ_HANDLED;
}
#endif

static inline void init_rx_bufs(struct net_device *dev)
{
	struct i596_private *lp = dev->priv;
	int i;
	struct i596_rfd *rfd;
	struct i596_rbd *rbd;

	/* First build the Receive Buffer Descriptor List */

	for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
		struct sk_buff *skb = dev_alloc_skb(PKT_BUF_SZ);

		if (skb == NULL)
			panic("82596: alloc_skb() failed");
		skb->dev = dev;
		rbd->v_next = rbd+1;
		rbd->b_next = WSWAPrbd(virt_to_bus(rbd+1));
		rbd->b_addr = WSWAPrbd(virt_to_bus(rbd));
		rbd->skb = skb;
		rbd->v_data = skb->data;
		rbd->b_data = WSWAPchar(virt_to_bus(skb->data));
		rbd->size = PKT_BUF_SZ;
#ifdef __mc68000__
		cache_clear(virt_to_phys(skb->data), PKT_BUF_SZ);
#endif
	}
	lp->rbd_head = lp->rbds;
	rbd = lp->rbds + rx_ring_size - 1;
	rbd->v_next = lp->rbds;
	rbd->b_next = WSWAPrbd(virt_to_bus(lp->rbds));

	/* Now build the Receive Frame Descriptor List */

	for (i = 0, rfd = lp->rfds; i < rx_ring_size; i++, rfd++) {
		rfd->rbd = I596_NULL;
		rfd->v_next = rfd+1;
		rfd->v_prev = rfd-1;
		rfd->b_next = WSWAPrfd(virt_to_bus(rfd+1));
		rfd->cmd = CMD_FLEX;
	}
	lp->rfd_head = lp->rfds;
	lp->scb.rfd = WSWAPrfd(virt_to_bus(lp->rfds));
	rfd = lp->rfds;
	rfd->rbd = lp->rbd_head;
	rfd->v_prev = lp->rfds + rx_ring_size - 1;
	rfd = lp->rfds + rx_ring_size - 1;
	rfd->v_next = lp->rfds;
	rfd->b_next = WSWAPrfd(virt_to_bus(lp->rfds));
	rfd->cmd = CMD_EOL|CMD_FLEX;
}

static inline void remove_rx_bufs(struct net_device *dev)
{
	struct i596_private *lp = dev->priv;
	struct i596_rbd *rbd;
	int i;

	for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
		if (rbd->skb == NULL)
			break;
		dev_kfree_skb(rbd->skb);
	}
}


static void rebuild_rx_bufs(struct net_device *dev)
{
	struct i596_private *lp = dev->priv;
	int i;

	/* Ensure rx frame/buffer descriptors are tidy */

	for (i = 0; i < rx_ring_size; i++) {
		lp->rfds[i].rbd = I596_NULL;
		lp->rfds[i].cmd = CMD_FLEX;
	}
	lp->rfds[rx_ring_size-1].cmd = CMD_EOL|CMD_FLEX;
	lp->rfd_head = lp->rfds;
	lp->scb.rfd = WSWAPrfd(virt_to_bus(lp->rfds));
	lp->rbd_head = lp->rbds;
	lp->rfds[0].rbd = WSWAPrbd(virt_to_bus(lp->rbds));
}


static int init_i596_mem(struct net_device *dev)
{
	struct i596_private *lp = dev->priv;
#if !defined(ENABLE_MVME16x_NET) && !defined(ENABLE_BVME6000_NET) || defined(ENABLE_APRICOT)
	short ioaddr = dev->base_addr;
#endif
	unsigned long flags;

	MPU_PORT(dev, PORT_RESET, NULL);

	udelay(100);		/* Wait 100us - seems to help */

#if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
#ifdef ENABLE_MVME16x_NET
	if (MACH_IS_MVME16x) {
		volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;

		/* Disable all ints for now */
		pcc2[0x28] = 1;
		pcc2[0x2a] = 0x48;
		/* Following disables snooping.  Snooping is not required
		 * as we make appropriate use of non-cached pages for
		 * shared data, and cache_push/cache_clear.
		 */
		pcc2[0x2b] = 0x08;
	}
#endif
#ifdef ENABLE_BVME6000_NET
	if (MACH_IS_BVME6000) {
		volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;

		*ethirq = 1;
	}
#endif

	/* change the scp address */

	MPU_PORT(dev, PORT_ALTSCP, (void *)virt_to_bus((void *)&lp->scp));

#elif defined(ENABLE_APRICOT)

	{
		u32 scp = virt_to_bus(&lp->scp);

		/* change the scp address */
		outw(0, ioaddr);
		outw(0, ioaddr);
		outb(4, ioaddr + 0xf);
		outw(scp | 2, ioaddr);
		outw(scp >> 16, ioaddr);
	}
#endif

	lp->last_cmd = jiffies;

#ifdef ENABLE_MVME16x_NET
	if (MACH_IS_MVME16x)
		lp->scp.sysbus = 0x00000054;
#endif
#ifdef ENABLE_BVME6000_NET
	if (MACH_IS_BVME6000)
		lp->scp.sysbus = 0x0000004c;
#endif
#ifdef ENABLE_APRICOT
	if (MACH_IS_APRICOT)
		lp->scp.sysbus = 0x00440000;
#endif

	lp->scp.iscp = WSWAPiscp(virt_to_bus((void *)&lp->iscp));
	lp->iscp.scb = WSWAPscb(virt_to_bus((void *)&lp->scb));
	lp->iscp.stat = ISCP_BUSY;
	lp->cmd_backlog = 0;

	lp->cmd_head = lp->scb.cmd = I596_NULL;

#ifdef ENABLE_BVME6000_NET
	if (MACH_IS_BVME6000) {
		lp->scb.t_on  = 7 * 25;
		lp->scb.t_off = 1 * 25;
	}
#endif

	DEB(DEB_INIT,printk(KERN_DEBUG "%s: starting i82596.\n", dev->name));

#if defined(ENABLE_APRICOT)
	(void) inb(ioaddr + 0x10);
	outb(4, ioaddr + 0xf);
#endif
	CA(dev);

	if (wait_istat(dev,lp,1000,"initialization timed out"))
		goto failed;
	DEB(DEB_INIT,printk(KERN_DEBUG "%s: i82596 initialization successful\n", dev->name));

	/* Ensure rx frame/buffer descriptors are tidy */
	rebuild_rx_bufs(dev);
	lp->scb.command = 0;

#ifdef ENABLE_MVME16x_NET
	if (MACH_IS_MVME16x) {
		volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;

		/* Enable ints, etc. now */
		pcc2[0x2a] = 0x55;	/* Edge sensitive */
		pcc2[0x2b] = 0x15;
	}
#endif
#ifdef ENABLE_BVME6000_NET
	if (MACH_IS_BVME6000) {
		volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;

		*ethirq = 3;
	}
#endif


	DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdConfigure\n", dev->name));
	memcpy(lp->cf_cmd.i596_config, init_setup, 14);
	lp->cf_cmd.cmd.command = CmdConfigure;
	i596_add_cmd(dev, &lp->cf_cmd.cmd);

	DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdSASetup\n", dev->name));
	memcpy(lp->sa_cmd.eth_addr, dev->dev_addr, 6);
	lp->sa_cmd.cmd.command = CmdSASetup;
	i596_add_cmd(dev, &lp->sa_cmd.cmd);

	DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdTDR\n", dev->name));
	lp->tdr_cmd.cmd.command = CmdTDR;
	i596_add_cmd(dev, &lp->tdr_cmd.cmd);

	spin_lock_irqsave (&lp->lock, flags);

	if (wait_cmd(dev,lp,1000,"timed out waiting to issue RX_START")) {
		spin_unlock_irqrestore (&lp->lock, flags);
		goto failed;
	}
	DEB(DEB_INIT,printk(KERN_DEBUG "%s: Issuing RX_START\n", dev->name));
	lp->scb.command = RX_START;
	CA(dev);

	spin_unlock_irqrestore (&lp->lock, flags);

	if (wait_cmd(dev,lp,1000,"RX_START not processed"))
		goto failed;
	DEB(DEB_INIT,printk(KERN_DEBUG "%s: Receive unit started OK\n", dev->name));
	return 0;

failed:
	printk(KERN_CRIT "%s: Failed to initialise 82596\n", dev->name);
	MPU_PORT(dev, PORT_RESET, NULL);
	return -1;
}

static inline int i596_rx(struct net_device *dev)
{
	struct i596_private *lp = dev->priv;
	struct i596_rfd *rfd;
	struct i596_rbd *rbd;
	int frames = 0;

	DEB(DEB_RXFRAME,printk(KERN_DEBUG "i596_rx(), rfd_head %p, rbd_head %p\n",
			lp->rfd_head, lp->rbd_head));

	rfd = lp->rfd_head;		/* Ref next frame to check */

	while ((rfd->stat) & STAT_C) {	/* Loop while complete frames */
		if (rfd->rbd == I596_NULL)
			rbd = I596_NULL;
		else if (rfd->rbd == lp->rbd_head->b_addr)
			rbd = lp->rbd_head;
		else {
			printk(KERN_CRIT "%s: rbd chain broken!\n", dev->name);
			/* XXX Now what? */
			rbd = I596_NULL;
		}
		DEB(DEB_RXFRAME, printk(KERN_DEBUG "  rfd %p, rfd.rbd %p, rfd.stat %04x\n",
			rfd, rfd->rbd, rfd->stat));

		if (rbd != I596_NULL && ((rfd->stat) & STAT_OK)) {
			/* a good frame */
			int pkt_len = rbd->count & 0x3fff;
			struct sk_buff *skb = rbd->skb;
			int rx_in_place = 0;

			DEB(DEB_RXADDR,print_eth(rbd->v_data, "received"));
			frames++;

			/* Check if the packet is long enough to just accept
			 * without copying to a properly sized skbuff.
			 */

			if (pkt_len > rx_copybreak) {
				struct sk_buff *newskb;

				/* Get fresh skbuff to replace filled one. */
				newskb = dev_alloc_skb(PKT_BUF_SZ);
				if (newskb == NULL) {
					skb = NULL;	/* drop pkt */
					goto memory_squeeze;
				}
				/* Pass up the skb already on the Rx ring. */
				skb_put(skb, pkt_len);
				rx_in_place = 1;
				rbd->skb = newskb;
				newskb->dev = dev;
				rbd->v_data = newskb->data;
				rbd->b_data = WSWAPchar(virt_to_bus(newskb->data));
#ifdef __mc68000__
				cache_clear(virt_to_phys(newskb->data), PKT_BUF_SZ);
#endif
			}
			else
				skb = dev_alloc_skb(pkt_len + 2);
memory_squeeze:
			if (skb == NULL) {
				/* XXX tulip.c can defer packets here!! */
				printk(KERN_WARNING "%s: i596_rx Memory squeeze, dropping packet.\n", dev->name);
				dev->stats.rx_dropped++;
			}
			else {
				if (!rx_in_place) {
					/* 16 byte align the data fields */
					skb_reserve(skb, 2);
					memcpy(skb_put(skb,pkt_len), rbd->v_data, pkt_len);
				}
				skb->protocol=eth_type_trans(skb,dev);
				skb->len = pkt_len;
#ifdef __mc68000__
				cache_clear(virt_to_phys(rbd->skb->data),
						pkt_len);
#endif
				netif_rx(skb);
				dev->last_rx = jiffies;
				dev->stats.rx_packets++;
				dev->stats.rx_bytes+=pkt_len;
			}
		}
		else {
			DEB(DEB_ERRORS, printk(KERN_DEBUG "%s: Error, rfd.stat = 0x%04x\n",
					dev->name, rfd->stat));
			dev->stats.rx_errors++;
			if ((rfd->stat) & 0x0001)
				dev->stats.collisions++;
			if ((rfd->stat) & 0x0080)
				dev->stats.rx_length_errors++;
			if ((rfd->stat) & 0x0100)
				dev->stats.rx_over_errors++;
			if ((rfd->stat) & 0x0200)
				dev->stats.rx_fifo_errors++;
			if ((rfd->stat) & 0x0400)
				dev->stats.rx_frame_errors++;
			if ((rfd->stat) & 0x0800)
				dev->stats.rx_crc_errors++;
			if ((rfd->stat) & 0x1000)
				dev->stats.rx_length_errors++;
		}

		/* Clear the buffer descriptor count and EOF + F flags */

		if (rbd != I596_NULL && (rbd->count & 0x4000)) {
			rbd->count = 0;
			lp->rbd_head = rbd->v_next;
		}

		/* Tidy the frame descriptor, marking it as end of list */

		rfd->rbd = I596_NULL;
		rfd->stat = 0;
		rfd->cmd = CMD_EOL|CMD_FLEX;
		rfd->count = 0;

		/* Remove end-of-list from old end descriptor */

		rfd->v_prev->cmd = CMD_FLEX;

		/* Update record of next frame descriptor to process */

		lp->scb.rfd = rfd->b_next;
		lp->rfd_head = rfd->v_next;
		rfd = lp->rfd_head;
	}

	DEB(DEB_RXFRAME,printk(KERN_DEBUG "frames %d\n", frames));

	return 0;
}


static void i596_cleanup_cmd(struct net_device *dev, struct i596_private *lp)
{
	struct i596_cmd *ptr;

	while (lp->cmd_head != I596_NULL) {
		ptr = lp->cmd_head;
		lp->cmd_head = ptr->v_next;
		lp->cmd_backlog--;

		switch ((ptr->command) & 0x7) {
		case CmdTx:
			{
				struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
				struct sk_buff *skb = tx_cmd->skb;

				dev_kfree_skb(skb);

				dev->stats.tx_errors++;
				dev->stats.tx_aborted_errors++;

				ptr->v_next = ptr->b_next = I596_NULL;
				tx_cmd->cmd.command = 0;  /* Mark as free */
				break;
			}
		default:
			ptr->v_next = ptr->b_next = I596_NULL;
		}
	}

	wait_cmd(dev,lp,100,"i596_cleanup_cmd timed out");
	lp->scb.cmd = I596_NULL;
}

static void i596_reset(struct net_device *dev, struct i596_private *lp,
			int ioaddr)
{
	unsigned long flags;

	DEB(DEB_RESET,printk(KERN_DEBUG "i596_reset\n"));

	spin_lock_irqsave (&lp->lock, flags);

	wait_cmd(dev,lp,100,"i596_reset timed out");

	netif_stop_queue(dev);

	lp->scb.command = CUC_ABORT | RX_ABORT;
	CA(dev);

	/* wait for shutdown */
	wait_cmd(dev,lp,1000,"i596_reset 2 timed out");
	spin_unlock_irqrestore (&lp->lock, flags);

	i596_cleanup_cmd(dev,lp);
	i596_rx(dev);

	netif_start_queue(dev);
	init_i596_mem(dev);
}

static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd)
{
	struct i596_private *lp = dev->priv;
	int ioaddr = dev->base_addr;
	unsigned long flags;

	DEB(DEB_ADDCMD,printk(KERN_DEBUG "i596_add_cmd\n"));

	cmd->status = 0;
	cmd->command |= (CMD_EOL | CMD_INTR);
	cmd->v_next = cmd->b_next = I596_NULL;

	spin_lock_irqsave (&lp->lock, flags);

	if (lp->cmd_head != I596_NULL) {
		lp->cmd_tail->v_next = cmd;
		lp->cmd_tail->b_next = WSWAPcmd(virt_to_bus(&cmd->status));
	} else {
		lp->cmd_head = cmd;
		wait_cmd(dev,lp,100,"i596_add_cmd timed out");
		lp->scb.cmd = WSWAPcmd(virt_to_bus(&cmd->status));
		lp->scb.command = CUC_START;
		CA(dev);
	}
	lp->cmd_tail = cmd;
	lp->cmd_backlog++;

	spin_unlock_irqrestore (&lp->lock, flags);

	if (lp->cmd_backlog > max_cmd_backlog) {
		unsigned long tickssofar = jiffies - lp->last_cmd;

		if (tickssofar < ticks_limit)
			return;

		printk(KERN_NOTICE "%s: command unit timed out, status resetting.\n", dev->name);

		i596_reset(dev, lp, ioaddr);
	}
}

static int i596_open(struct net_device *dev)
{
	int res = 0;

	DEB(DEB_OPEN,printk(KERN_DEBUG "%s: i596_open() irq %d.\n", dev->name, dev->irq));

	if (request_irq(dev->irq, i596_interrupt, 0, "i82596", dev)) {
		printk(KERN_ERR "%s: IRQ %d not free\n", dev->name, dev->irq);
		return -EAGAIN;
	}
#ifdef ENABLE_MVME16x_NET
	if (MACH_IS_MVME16x) {
		if (request_irq(0x56, i596_error, 0, "i82596_error", dev))
			return -EAGAIN;
	}
#endif
	init_rx_bufs(dev);

	netif_start_queue(dev);

	/* Initialize the 82596 memory */
	if (init_i596_mem(dev)) {
		res = -EAGAIN;
		free_irq(dev->irq, dev);
	}

	return res;
}

static void i596_tx_timeout (struct net_device *dev)
{
	struct i596_private *lp = dev->priv;
	int ioaddr = dev->base_addr;

	/* Transmitter timeout, serious problems. */
	DEB(DEB_ERRORS,printk(KERN_ERR "%s: transmit timed out, status resetting.\n",
			dev->name));

	dev->stats.tx_errors++;

	/* Try to restart the adaptor */
	if (lp->last_restart == dev->stats.tx_packets) {
		DEB(DEB_ERRORS,printk(KERN_ERR "Resetting board.\n"));
		/* Shutdown and restart */
		i596_reset (dev, lp, ioaddr);
	} else {
		/* Issue a channel attention signal */
		DEB(DEB_ERRORS,printk(KERN_ERR "Kicking board.\n"));
		lp->scb.command = CUC_START | RX_START;
		CA (dev);
		lp->last_restart = dev->stats.tx_packets;
	}

	dev->trans_start = jiffies;
	netif_wake_queue (dev);
}


static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
	struct i596_private *lp = dev->priv;
	struct tx_cmd *tx_cmd;
	struct i596_tbd *tbd;
	short length = skb->len;
	dev->trans_start = jiffies;

	DEB(DEB_STARTTX,printk(KERN_DEBUG "%s: i596_start_xmit(%x,%p) called\n",
				dev->name, skb->len, skb->data));

	if (skb->len < ETH_ZLEN) {
		if (skb_padto(skb, ETH_ZLEN))
			return 0;
		length = ETH_ZLEN;
	}
	netif_stop_queue(dev);

	tx_cmd = lp->tx_cmds + lp->next_tx_cmd;
	tbd = lp->tbds + lp->next_tx_cmd;

	if (tx_cmd->cmd.command) {
		printk(KERN_NOTICE "%s: xmit ring full, dropping packet.\n",
				dev->name);
		dev->stats.tx_dropped++;

		dev_kfree_skb(skb);
	} else {
		if (++lp->next_tx_cmd == TX_RING_SIZE)
			lp->next_tx_cmd = 0;
		tx_cmd->tbd = WSWAPtbd(virt_to_bus(tbd));
		tbd->next = I596_NULL;

		tx_cmd->cmd.command = CMD_FLEX | CmdTx;
		tx_cmd->skb = skb;

		tx_cmd->pad = 0;
		tx_cmd->size = 0;
		tbd->pad = 0;
		tbd->size = EOF | length;

		tbd->data = WSWAPchar(virt_to_bus(skb->data));

#ifdef __mc68000__
		cache_push(virt_to_phys(skb->data), length);
#endif
		DEB(DEB_TXADDR,print_eth(skb->data, "tx-queued"));
		i596_add_cmd(dev, &tx_cmd->cmd);

		dev->stats.tx_packets++;
		dev->stats.tx_bytes += length;
	}

	netif_start_queue(dev);

	return 0;
}

static void print_eth(unsigned char *add, char *str)
{
	DECLARE_MAC_BUF(mac);
	DECLARE_MAC_BUF(mac2);

	printk(KERN_DEBUG "i596 0x%p, %s --> %s %02X%02X, %s\n",
	       add, print_mac(mac, add + 6), print_mac(mac2, add),
	       add[12], add[13], str);
}

static int io = 0x300;
static int irq = 10;

struct net_device * __init i82596_probe(int unit)
{
	struct net_device *dev;
	int i;
	struct i596_private *lp;
	char eth_addr[8];
	static int probed;
	int err;

	if (probed)
		return ERR_PTR(-ENODEV);
	probed++;

	dev = alloc_etherdev(0);
	if (!dev)
		return ERR_PTR(-ENOMEM);

	if (unit >= 0) {
		sprintf(dev->name, "eth%d", unit);
		netdev_boot_setup_check(dev);
	} else {
		dev->base_addr = io;
		dev->irq = irq;
	}

#ifdef ENABLE_MVME16x_NET
	if (MACH_IS_MVME16x) {
		if (mvme16x_config & MVME16x_CONFIG_NO_ETHERNET) {
			printk(KERN_NOTICE "Ethernet probe disabled - chip not present\n");
			err = -ENODEV;
			goto out;
		}
		memcpy(eth_addr, (void *) 0xfffc1f2c, 6);	/* YUCK! Get addr from NOVRAM */
		dev->base_addr = MVME_I596_BASE;
		dev->irq = (unsigned) MVME16x_IRQ_I596;
		goto found;
	}
#endif
#ifdef ENABLE_BVME6000_NET
	if (MACH_IS_BVME6000) {
		volatile unsigned char *rtc = (unsigned char *) BVME_RTC_BASE;
		unsigned char msr = rtc[3];
		int i;

		rtc[3] |= 0x80;
		for (i = 0; i < 6; i++)
			eth_addr[i] = rtc[i * 4 + 7];	/* Stored in RTC RAM at offset 1 */
		rtc[3] = msr;
		dev->base_addr = BVME_I596_BASE;
		dev->irq = (unsigned) BVME_IRQ_I596;
		goto found;
	}
#endif
#ifdef ENABLE_APRICOT
	{
		int checksum = 0;
		int ioaddr = 0x300;

		/* this is easy the ethernet interface can only be at 0x300 */
		/* first check nothing is already registered here */

		if (!request_region(ioaddr, I596_TOTAL_SIZE, DRV_NAME)) {
			printk(KERN_ERR "82596: IO address 0x%04x in use\n", ioaddr);
			err = -EBUSY;
			goto out;
		}

		dev->base_addr = ioaddr;

		for (i = 0; i < 8; i++) {
			eth_addr[i] = inb(ioaddr + 8 + i);
			checksum += eth_addr[i];
		}

		/* checksum is a multiple of 0x100, got this wrong first time
		   some machines have 0x100, some 0x200. The DOS driver doesn't
		   even bother with the checksum.
		   Some other boards trip the checksum.. but then appear as
		   ether address 0. Trap these - AC */

		if ((checksum % 0x100) ||
		    (memcmp(eth_addr, "\x00\x00\x49", 3) != 0)) {
			err = -ENODEV;
			goto out1;
		}

		dev->irq = 10;
		goto found;
	}
#endif
	err = -ENODEV;
	goto out;

found:
	dev->mem_start = (int)__get_free_pages(GFP_ATOMIC, 0);
	if (!dev->mem_start) {
		err = -ENOMEM;
		goto out1;
	}

	DEB(DEB_PROBE,printk(KERN_INFO "%s: 82596 at %#3lx,", dev->name, dev->base_addr));

	for (i = 0; i < 6; i++)
		DEB(DEB_PROBE,printk(" %2.2X", dev->dev_addr[i] = eth_addr[i]));

	DEB(DEB_PROBE,printk(" IRQ %d.\n", dev->irq));

	DEB(DEB_PROBE,printk(KERN_INFO "%s", version));

	/* The 82596-specific entries in the device structure. */
	dev->open = i596_open;
	dev->stop = i596_close;
	dev->hard_start_xmit = i596_start_xmit;
	dev->set_multicast_list = set_multicast_list;
	dev->tx_timeout = i596_tx_timeout;
	dev->watchdog_timeo = TX_TIMEOUT;

	dev->priv = (void *)(dev->mem_start);

	lp = dev->priv;
	DEB(DEB_INIT,printk(KERN_DEBUG "%s: lp at 0x%08lx (%zd bytes), "
			"lp->scb at 0x%08lx\n",
			dev->name, (unsigned long)lp,
			sizeof(struct i596_private), (unsigned long)&lp->scb));
	memset((void *) lp, 0, sizeof(struct i596_private));

#ifdef __mc68000__
	cache_push(virt_to_phys((void *)(dev->mem_start)), 4096);
	cache_clear(virt_to_phys((void *)(dev->mem_start)), 4096);
	kernel_set_cachemode((void *)(dev->mem_start), 4096, IOMAP_NOCACHE_SER);
#endif
	lp->scb.command = 0;
	lp->scb.cmd = I596_NULL;
	lp->scb.rfd = I596_NULL;
	spin_lock_init(&lp->lock);

	err = register_netdev(dev);
	if (err)
		goto out2;
	return dev;
out2:
#ifdef __mc68000__
	/* XXX This assumes default cache mode to be IOMAP_FULL_CACHING,
	 * XXX which may be invalid (CONFIG_060_WRITETHROUGH)
	 */
	kernel_set_cachemode((void *)(dev->mem_start), 4096,
			IOMAP_FULL_CACHING);
#endif
	free_page ((u32)(dev->mem_start));
out1:
#ifdef ENABLE_APRICOT
	release_region(dev->base_addr, I596_TOTAL_SIZE);
#endif
out:
	free_netdev(dev);
	return ERR_PTR(err);
}

static irqreturn_t i596_interrupt(int irq, void *dev_id)
{
	struct net_device *dev = dev_id;
	struct i596_private *lp;
	short ioaddr;
	unsigned short status, ack_cmd = 0;
	int handled = 0;

#ifdef ENABLE_BVME6000_NET
	if (MACH_IS_BVME6000) {
		if (*(char *) BVME_LOCAL_IRQ_STAT & BVME_ETHERR) {
			i596_error(irq, dev_id);
			return IRQ_HANDLED;
		}
	}
#endif
	if (dev == NULL) {
		printk(KERN_ERR "i596_interrupt(): irq %d for unknown device.\n", irq);
		return IRQ_NONE;
	}

	ioaddr = dev->base_addr;
	lp = dev->priv;

	spin_lock (&lp->lock);

	wait_cmd(dev,lp,100,"i596 interrupt, timeout");
	status = lp->scb.status;

	DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt, IRQ %d, status %4.4x.\n",
			dev->name, irq, status));

	ack_cmd = status & 0xf000;

	if ((status & 0x8000) || (status & 0x2000)) {
		struct i596_cmd *ptr;

		handled = 1;
		if ((status & 0x8000))
			DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt completed command.\n", dev->name));
		if ((status & 0x2000))
			DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700));

		while ((lp->cmd_head != I596_NULL) && (lp->cmd_head->status & STAT_C)) {
			ptr = lp->cmd_head;

			DEB(DEB_STATUS,printk(KERN_DEBUG "cmd_head->status = %04x, ->command = %04x\n",
				       lp->cmd_head->status, lp->cmd_head->command));
			lp->cmd_head = ptr->v_next;
			lp->cmd_backlog--;

			switch ((ptr->command) & 0x7) {
			case CmdTx:
			    {
				struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
				struct sk_buff *skb = tx_cmd->skb;

				if ((ptr->status) & STAT_OK) {
					DEB(DEB_TXADDR,print_eth(skb->data, "tx-done"));
				} else {
					dev->stats.tx_errors++;
					if ((ptr->status) & 0x0020)
						dev->stats.collisions++;
					if (!((ptr->status) & 0x0040))
						dev->stats.tx_heartbeat_errors++;
					if ((ptr->status) & 0x0400)
						dev->stats.tx_carrier_errors++;
					if ((ptr->status) & 0x0800)
						dev->stats.collisions++;
					if ((ptr->status) & 0x1000)
						dev->stats.tx_aborted_errors++;
				}

				dev_kfree_skb_irq(skb);

				tx_cmd->cmd.command = 0; /* Mark free */
				break;
			    }
			case CmdTDR:
			    {
				unsigned short status = ((struct tdr_cmd *)ptr)->status;

				if (status & 0x8000) {
					DEB(DEB_TDR,printk(KERN_INFO "%s: link ok.\n", dev->name));
				} else {
					if (status & 0x4000)
						printk(KERN_ERR "%s: Transceiver problem.\n", dev->name);
					if (status & 0x2000)
						printk(KERN_ERR "%s: Termination problem.\n", dev->name);
					if (status & 0x1000)
						printk(KERN_ERR "%s: Short circuit.\n", dev->name);

					DEB(DEB_TDR,printk(KERN_INFO "%s: Time %d.\n", dev->name, status & 0x07ff));
				}
				break;
			    }
			case CmdConfigure:
			case CmdMulticastList:
				/* Zap command so set_multicast_list() knows it is free */
				ptr->command = 0;
				break;
			}
			ptr->v_next = ptr->b_next = I596_NULL;
			lp->last_cmd = jiffies;
		}

		ptr = lp->cmd_head;
		while ((ptr != I596_NULL) && (ptr != lp->cmd_tail)) {
			ptr->command &= 0x1fff;
			ptr = ptr->v_next;
		}

		if ((lp->cmd_head != I596_NULL))
			ack_cmd |= CUC_START;
		lp->scb.cmd = WSWAPcmd(virt_to_bus(&lp->cmd_head->status));
	}
	if ((status & 0x1000) || (status & 0x4000)) {
		if ((status & 0x4000))
			DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt received a frame.\n", dev->name));
		i596_rx(dev);
		/* Only RX_START if stopped - RGH 07-07-96 */
		if (status & 0x1000) {
			if (netif_running(dev)) {
				DEB(DEB_ERRORS,printk(KERN_ERR "%s: i596 interrupt receive unit inactive, status 0x%x\n", dev->name, status));
				ack_cmd |= RX_START;
				dev->stats.rx_errors++;
				dev->stats.rx_fifo_errors++;
				rebuild_rx_bufs(dev);
			}
		}
	}
	wait_cmd(dev,lp,100,"i596 interrupt, timeout");
	lp->scb.command = ack_cmd;

#ifdef ENABLE_MVME16x_NET
	if (MACH_IS_MVME16x) {
		/* Ack the interrupt */

		volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;

		pcc2[0x2a] |= 0x08;
	}
#endif
#ifdef ENABLE_BVME6000_NET
	if (MACH_IS_BVME6000) {
		volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;

		*ethirq = 1;
		*ethirq = 3;
	}
#endif
#ifdef ENABLE_APRICOT
	(void) inb(ioaddr + 0x10);
	outb(4, ioaddr + 0xf);
#endif
	CA(dev);

	DEB(DEB_INTS,printk(KERN_DEBUG "%s: exiting interrupt.\n", dev->name));

	spin_unlock (&lp->lock);
	return IRQ_RETVAL(handled);
}

static int i596_close(struct net_device *dev)
{
	struct i596_private *lp = dev->priv;
	unsigned long flags;

	netif_stop_queue(dev);

	DEB(DEB_INIT,printk(KERN_DEBUG "%s: Shutting down ethercard, status was %4.4x.\n",
		       dev->name, lp->scb.status));

	spin_lock_irqsave(&lp->lock, flags);

	wait_cmd(dev,lp,100,"close1 timed out");
	lp->scb.command = CUC_ABORT | RX_ABORT;
	CA(dev);

	wait_cmd(dev,lp,100,"close2 timed out");

	spin_unlock_irqrestore(&lp->lock, flags);
	DEB(DEB_STRUCT,i596_display_data(dev));
	i596_cleanup_cmd(dev,lp);

#ifdef ENABLE_MVME16x_NET
	if (MACH_IS_MVME16x) {
		volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;

		/* Disable all ints */
		pcc2[0x28] = 1;
		pcc2[0x2a] = 0x40;
		pcc2[0x2b] = 0x40;	/* Set snooping bits now! */
	}
#endif
#ifdef ENABLE_BVME6000_NET
	if (MACH_IS_BVME6000) {
		volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;

		*ethirq = 1;
	}
#endif

	free_irq(dev->irq, dev);
	remove_rx_bufs(dev);

	return 0;
}

/*
 *    Set or clear the multicast filter for this adaptor.
 */

static void set_multicast_list(struct net_device *dev)
{
	struct i596_private *lp = dev->priv;
	int config = 0, cnt;

	DEB(DEB_MULTI,printk(KERN_DEBUG "%s: set multicast list, %d entries, promisc %s, allmulti %s\n",
		dev->name, dev->mc_count,
		dev->flags & IFF_PROMISC  ? "ON" : "OFF",
		dev->flags & IFF_ALLMULTI ? "ON" : "OFF"));

	if (wait_cfg(dev, &lp->cf_cmd.cmd, 1000, "config change request timed out"))
		return;

	if ((dev->flags & IFF_PROMISC) && !(lp->cf_cmd.i596_config[8] & 0x01)) {
		lp->cf_cmd.i596_config[8] |= 0x01;
		config = 1;
	}
	if (!(dev->flags & IFF_PROMISC) && (lp->cf_cmd.i596_config[8] & 0x01)) {
		lp->cf_cmd.i596_config[8] &= ~0x01;
		config = 1;
	}
	if ((dev->flags & IFF_ALLMULTI) && (lp->cf_cmd.i596_config[11] & 0x20)) {
		lp->cf_cmd.i596_config[11] &= ~0x20;
		config = 1;
	}
	if (!(dev->flags & IFF_ALLMULTI) && !(lp->cf_cmd.i596_config[11] & 0x20)) {
		lp->cf_cmd.i596_config[11] |= 0x20;
		config = 1;
	}
	if (config) {
		lp->cf_cmd.cmd.command = CmdConfigure;
		i596_add_cmd(dev, &lp->cf_cmd.cmd);
	}

	cnt = dev->mc_count;
	if (cnt > MAX_MC_CNT)
	{
		cnt = MAX_MC_CNT;
		printk(KERN_ERR "%s: Only %d multicast addresses supported",
			dev->name, cnt);
	}

	if (dev->mc_count > 0) {
		struct dev_mc_list *dmi;
		unsigned char *cp;
		struct mc_cmd *cmd;
		DECLARE_MAC_BUF(mac);

		if (wait_cfg(dev, &lp->mc_cmd.cmd, 1000, "multicast list change request timed out"))
			return;
		cmd = &lp->mc_cmd;
		cmd->cmd.command = CmdMulticastList;
		cmd->mc_cnt = dev->mc_count * 6;
		cp = cmd->mc_addrs;
		for (dmi = dev->mc_list; cnt && dmi != NULL; dmi = dmi->next, cnt--, cp += 6) {
			memcpy(cp, dmi->dmi_addr, 6);
			if (i596_debug > 1)
				DEB(DEB_MULTI,printk(KERN_INFO "%s: Adding address %s\n",
						dev->name, print_mac(mac, cp)));
		}
		i596_add_cmd(dev, &cmd->cmd);
	}
}

#ifdef MODULE
static struct net_device *dev_82596;

#ifdef ENABLE_APRICOT
module_param(irq, int, 0);
MODULE_PARM_DESC(irq, "Apricot IRQ number");
#endif

static int debug = -1;
module_param(debug, int, 0);
MODULE_PARM_DESC(debug, "i82596 debug mask");

int __init init_module(void)
{
	if (debug >= 0)
		i596_debug = debug;
	dev_82596 = i82596_probe(-1);
	if (IS_ERR(dev_82596))
		return PTR_ERR(dev_82596);
	return 0;
}

void __exit cleanup_module(void)
{
	unregister_netdev(dev_82596);
#ifdef __mc68000__
	/* XXX This assumes default cache mode to be IOMAP_FULL_CACHING,
	 * XXX which may be invalid (CONFIG_060_WRITETHROUGH)
	 */

	kernel_set_cachemode((void *)(dev_82596->mem_start), 4096,
			IOMAP_FULL_CACHING);
#endif
	free_page ((u32)(dev_82596->mem_start));
#ifdef ENABLE_APRICOT
	/* If we don't do this, we can't re-insmod it later. */
	release_region(dev_82596->base_addr, I596_TOTAL_SIZE);
#endif
	free_netdev(dev_82596);
}

#endif				/* MODULE */

/*
 * Local variables:
 *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c 82596.c"
 * End:
 */
; HP100_MIN_PACKET_SIZE; i += 4) hp100_outl(0, DATA32); } hp100_outb(HP100_TX_CMD | HP100_SET_LB, OPTION_MSW); /* send packet */ lp->stats.tx_packets++; lp->stats.tx_bytes += skb->len; dev->trans_start = jiffies; hp100_ints_on(); spin_unlock_irqrestore(&lp->lock, flags); dev_kfree_skb_any(skb); #ifdef HP100_DEBUG_TX printk("hp100: %s: start_xmit: end\n", dev->name); #endif return 0; } /* * Receive Function (Non-Busmaster mode) * Called when an "Receive Packet" interrupt occurs, i.e. the receive * packet counter is non-zero. * For non-busmaster, this function does the whole work of transfering * the packet to the host memory and then up to higher layers via skb * and netif_rx. */ static void hp100_rx(struct net_device *dev) { int packets, pkt_len; int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); u_int header; struct sk_buff *skb; #ifdef DEBUG_B hp100_outw(0x4213, TRACE); printk("hp100: %s: rx\n", dev->name); #endif /* First get indication of received lan packet */ /* RX_PKT_CND indicates the number of packets which have been fully */ /* received onto the card but have not been fully transferred of the card */ packets = hp100_inb(RX_PKT_CNT); #ifdef HP100_DEBUG_RX if (packets > 1) printk("hp100: %s: rx: waiting packets = %d\n", dev->name, packets); #endif while (packets-- > 0) { /* If ADV_NXT_PKT is still set, we have to wait until the card has */ /* really advanced to the next packet. */ for (pkt_len = 0; pkt_len < 6000 && (hp100_inb(OPTION_MSW) & HP100_ADV_NXT_PKT); pkt_len++) { #ifdef HP100_DEBUG_RX printk ("hp100: %s: rx: busy, remaining packets = %d\n", dev->name, packets); #endif } /* First we get the header, which contains information about the */ /* actual length of the received packet. */ if (lp->mode == 2) { /* memory mapped mode */ header = readl(lp->mem_ptr_virt); } else /* programmed i/o */ header = hp100_inl(DATA32); pkt_len = ((header & HP100_PKT_LEN_MASK) + 3) & ~3; #ifdef HP100_DEBUG_RX printk("hp100: %s: rx: new packet - length=%d, errors=0x%x, dest=0x%x\n", dev->name, header & HP100_PKT_LEN_MASK, (header >> 16) & 0xfff8, (header >> 16) & 7); #endif /* Now we allocate the skb and transfer the data into it. */ skb = dev_alloc_skb(pkt_len+2); if (skb == NULL) { /* Not enough memory->drop packet */ #ifdef HP100_DEBUG printk("hp100: %s: rx: couldn't allocate a sk_buff of size %d\n", dev->name, pkt_len); #endif lp->stats.rx_dropped++; } else { /* skb successfully allocated */ u_char *ptr; skb_reserve(skb,2); /* ptr to start of the sk_buff data area */ skb_put(skb, pkt_len); ptr = skb->data; /* Now transfer the data from the card into that area */ if (lp->mode == 2) memcpy_fromio(ptr, lp->mem_ptr_virt,pkt_len); else /* io mapped */ insl(ioaddr + HP100_REG_DATA32, ptr, pkt_len >> 2); skb->protocol = eth_type_trans(skb, dev); #ifdef HP100_DEBUG_RX printk("hp100: %s: rx: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", dev->name, ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7], ptr[8], ptr[9], ptr[10], ptr[11]); #endif netif_rx(skb); dev->last_rx = jiffies; lp->stats.rx_packets++; lp->stats.rx_bytes += pkt_len; } /* Indicate the card that we have got the packet */ hp100_outb(HP100_ADV_NXT_PKT | HP100_SET_LB, OPTION_MSW); switch (header & 0x00070000) { case (HP100_MULTI_ADDR_HASH << 16): case (HP100_MULTI_ADDR_NO_HASH << 16): lp->stats.multicast++; break; } } /* end of while(there are packets) loop */ #ifdef HP100_DEBUG_RX printk("hp100_rx: %s: end\n", dev->name); #endif } /* * Receive Function for Busmaster Mode */ static void hp100_rx_bm(struct net_device *dev) { int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); hp100_ring_t *ptr; u_int header; int pkt_len; #ifdef HP100_DEBUG_B hp100_outw(0x4214, TRACE); printk("hp100: %s: rx_bm\n", dev->name); #endif #ifdef HP100_DEBUG if (0 == lp->rxrcommit) { printk("hp100: %s: rx_bm called although no PDLs were committed to adapter?\n", dev->name); return; } else /* RX_PKT_CNT states how many PDLs are currently formatted and available to * the cards BM engine */ if ((hp100_inw(RX_PKT_CNT) & 0x00ff) >= lp->rxrcommit) { printk("hp100: %s: More packets received than commited? RX_PKT_CNT=0x%x, commit=0x%x\n", dev->name, hp100_inw(RX_PKT_CNT) & 0x00ff, lp->rxrcommit); return; } #endif while ((lp->rxrcommit > hp100_inb(RX_PDL))) { /* * The packet was received into the pdl pointed to by lp->rxrhead ( * the oldest pdl in the ring */ /* First we get the header, which contains information about the */ /* actual length of the received packet. */ ptr = lp->rxrhead; header = *(ptr->pdl - 1); pkt_len = (header & HP100_PKT_LEN_MASK); /* Conversion to new PCI API : NOP */ pci_unmap_single(lp->pci_dev, (dma_addr_t) ptr->pdl[3], MAX_ETHER_SIZE, PCI_DMA_FROMDEVICE); #ifdef HP100_DEBUG_BM printk("hp100: %s: rx_bm: header@0x%x=0x%x length=%d, errors=0x%x, dest=0x%x\n", dev->name, (u_int) (ptr->pdl - 1), (u_int) header, pkt_len, (header >> 16) & 0xfff8, (header >> 16) & 7); printk("hp100: %s: RX_PDL_COUNT:0x%x TX_PDL_COUNT:0x%x, RX_PKT_CNT=0x%x PDH=0x%x, Data@0x%x len=0x%x\n", dev->name, hp100_inb(RX_PDL), hp100_inb(TX_PDL), hp100_inb(RX_PKT_CNT), (u_int) * (ptr->pdl), (u_int) * (ptr->pdl + 3), (u_int) * (ptr->pdl + 4)); #endif if ((pkt_len >= MIN_ETHER_SIZE) && (pkt_len <= MAX_ETHER_SIZE)) { if (ptr->skb == NULL) { printk("hp100: %s: rx_bm: skb null\n", dev->name); /* can happen if we only allocated room for the pdh due to memory shortage. */ lp->stats.rx_dropped++; } else { skb_trim(ptr->skb, pkt_len); /* Shorten it */ ptr->skb->protocol = eth_type_trans(ptr->skb, dev); netif_rx(ptr->skb); /* Up and away... */ dev->last_rx = jiffies; lp->stats.rx_packets++; lp->stats.rx_bytes += pkt_len; } switch (header & 0x00070000) { case (HP100_MULTI_ADDR_HASH << 16): case (HP100_MULTI_ADDR_NO_HASH << 16): lp->stats.multicast++; break; } } else { #ifdef HP100_DEBUG printk("hp100: %s: rx_bm: Received bad packet (length=%d)\n", dev->name, pkt_len); #endif if (ptr->skb != NULL) dev_kfree_skb_any(ptr->skb); lp->stats.rx_errors++; } lp->rxrhead = lp->rxrhead->next; /* Allocate a new rx PDL (so lp->rxrcommit stays the same) */ if (0 == hp100_build_rx_pdl(lp->rxrtail, dev)) { /* No space for skb, header can still be received. */ #ifdef HP100_DEBUG printk("hp100: %s: rx_bm: No space for new PDL.\n", dev->name); #endif return; } else { /* successfully allocated new PDL - put it in ringlist at tail. */ hp100_outl((u32) lp->rxrtail->pdl_paddr, RX_PDA); lp->rxrtail = lp->rxrtail->next; } } } /* * statistics */ static struct net_device_stats *hp100_get_stats(struct net_device *dev) { unsigned long flags; int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); #ifdef HP100_DEBUG_B hp100_outw(0x4215, TRACE); #endif spin_lock_irqsave(&lp->lock, flags); hp100_ints_off(); /* Useful ? Jean II */ hp100_update_stats(dev); hp100_ints_on(); spin_unlock_irqrestore(&lp->lock, flags); return &(lp->stats); } static void hp100_update_stats(struct net_device *dev) { int ioaddr = dev->base_addr; u_short val; struct hp100_private *lp = netdev_priv(dev); #ifdef HP100_DEBUG_B hp100_outw(0x4216, TRACE); printk("hp100: %s: update-stats\n", dev->name); #endif /* Note: Statistics counters clear when read. */ hp100_page(MAC_CTRL); val = hp100_inw(DROPPED) & 0x0fff; lp->stats.rx_errors += val; lp->stats.rx_over_errors += val; val = hp100_inb(CRC); lp->stats.rx_errors += val; lp->stats.rx_crc_errors += val; val = hp100_inb(ABORT); lp->stats.tx_errors += val; lp->stats.tx_aborted_errors += val; hp100_page(PERFORMANCE); } static void hp100_misc_interrupt(struct net_device *dev) { #ifdef HP100_DEBUG_B int ioaddr = dev->base_addr; #endif struct hp100_private *lp = netdev_priv(dev); #ifdef HP100_DEBUG_B int ioaddr = dev->base_addr; hp100_outw(0x4216, TRACE); printk("hp100: %s: misc_interrupt\n", dev->name); #endif /* Note: Statistics counters clear when read. */ lp->stats.rx_errors++; lp->stats.tx_errors++; } static void hp100_clear_stats(struct hp100_private *lp, int ioaddr) { unsigned long flags; #ifdef HP100_DEBUG_B hp100_outw(0x4217, TRACE); printk("hp100: %s: clear_stats\n", dev->name); #endif spin_lock_irqsave(&lp->lock, flags); hp100_page(MAC_CTRL); /* get all statistics bytes */ hp100_inw(DROPPED); hp100_inb(CRC); hp100_inb(ABORT); hp100_page(PERFORMANCE); spin_unlock_irqrestore(&lp->lock, flags); } /* * multicast setup */ /* * Set or clear the multicast filter for this adapter. */ static void hp100_set_multicast_list(struct net_device *dev) { unsigned long flags; int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); #ifdef HP100_DEBUG_B hp100_outw(0x4218, TRACE); printk("hp100: %s: set_mc_list\n", dev->name); #endif spin_lock_irqsave(&lp->lock, flags); hp100_ints_off(); hp100_page(MAC_CTRL); hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1); /* stop rx/tx */ if (dev->flags & IFF_PROMISC) { lp->mac2_mode = HP100_MAC2MODE6; /* promiscuous mode = get all good */ lp->mac1_mode = HP100_MAC1MODE6; /* packets on the net */ memset(&lp->hash_bytes, 0xff, 8); } else if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) { lp->mac2_mode = HP100_MAC2MODE5; /* multicast mode = get packets for */ lp->mac1_mode = HP100_MAC1MODE5; /* me, broadcasts and all multicasts */ #ifdef HP100_MULTICAST_FILTER /* doesn't work!!! */ if (dev->flags & IFF_ALLMULTI) { /* set hash filter to receive all multicast packets */ memset(&lp->hash_bytes, 0xff, 8); } else { int i, j, idx; u_char *addrs; struct dev_mc_list *dmi; memset(&lp->hash_bytes, 0x00, 8); #ifdef HP100_DEBUG printk("hp100: %s: computing hash filter - mc_count = %i\n", dev->name, dev->mc_count); #endif for (i = 0, dmi = dev->mc_list; i < dev->mc_count; i++, dmi = dmi->next) { addrs = dmi->dmi_addr; if ((*addrs & 0x01) == 0x01) { /* multicast address? */ #ifdef HP100_DEBUG DECLARE_MAC_BUF(mac); printk("hp100: %s: multicast = %s, ", dev->name, print_mac(mac, addrs)); #endif for (j = idx = 0; j < 6; j++) { idx ^= *addrs++ & 0x3f; printk(":%02x:", idx); } #ifdef HP100_DEBUG printk("idx = %i\n", idx); #endif lp->hash_bytes[idx >> 3] |= (1 << (idx & 7)); } } } #else memset(&lp->hash_bytes, 0xff, 8); #endif } else { lp->mac2_mode = HP100_MAC2MODE3; /* normal mode = get packets for me */ lp->mac1_mode = HP100_MAC1MODE3; /* and broadcasts */ memset(&lp->hash_bytes, 0x00, 8); } if (((hp100_inb(MAC_CFG_1) & 0x0f) != lp->mac1_mode) || (hp100_inb(MAC_CFG_2) != lp->mac2_mode)) { int i; hp100_outb(lp->mac2_mode, MAC_CFG_2); hp100_andb(HP100_MAC1MODEMASK, MAC_CFG_1); /* clear mac1 mode bits */ hp100_orb(lp->mac1_mode, MAC_CFG_1); /* and set the new mode */ hp100_page(MAC_ADDRESS); for (i = 0; i < 8; i++) hp100_outb(lp->hash_bytes[i], HASH_BYTE0 + i); #ifdef HP100_DEBUG printk("hp100: %s: mac1 = 0x%x, mac2 = 0x%x, multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, lp->mac1_mode, lp->mac2_mode, lp->hash_bytes[0], lp->hash_bytes[1], lp->hash_bytes[2], lp->hash_bytes[3], lp->hash_bytes[4], lp->hash_bytes[5], lp->hash_bytes[6], lp->hash_bytes[7]); #endif if (lp->lan_type == HP100_LAN_100) { #ifdef HP100_DEBUG printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name); #endif lp->hub_status = hp100_login_to_vg_hub(dev, 1); /* force a relogin to the hub */ } } else { int i; u_char old_hash_bytes[8]; hp100_page(MAC_ADDRESS); for (i = 0; i < 8; i++) old_hash_bytes[i] = hp100_inb(HASH_BYTE0 + i); if (memcmp(old_hash_bytes, &lp->hash_bytes, 8)) { for (i = 0; i < 8; i++) hp100_outb(lp->hash_bytes[i], HASH_BYTE0 + i); #ifdef HP100_DEBUG printk("hp100: %s: multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, lp->hash_bytes[0], lp->hash_bytes[1], lp->hash_bytes[2], lp->hash_bytes[3], lp->hash_bytes[4], lp->hash_bytes[5], lp->hash_bytes[6], lp->hash_bytes[7]); #endif if (lp->lan_type == HP100_LAN_100) { #ifdef HP100_DEBUG printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name); #endif lp->hub_status = hp100_login_to_vg_hub(dev, 1); /* force a relogin to the hub */ } } } hp100_page(MAC_CTRL); hp100_orb(HP100_RX_EN | HP100_RX_IDLE | /* enable rx */ HP100_TX_EN | HP100_TX_IDLE, MAC_CFG_1); /* enable tx */ hp100_page(PERFORMANCE); hp100_ints_on(); spin_unlock_irqrestore(&lp->lock, flags); } /* * hardware interrupt handling */ static irqreturn_t hp100_interrupt(int irq, void *dev_id) { struct net_device *dev = (struct net_device *) dev_id; struct hp100_private *lp = netdev_priv(dev); int ioaddr; u_int val; if (dev == NULL) return IRQ_NONE; ioaddr = dev->base_addr; spin_lock(&lp->lock); hp100_ints_off(); #ifdef HP100_DEBUG_B hp100_outw(0x4219, TRACE); #endif /* hp100_page( PERFORMANCE ); */ val = hp100_inw(IRQ_STATUS); #ifdef HP100_DEBUG_IRQ printk("hp100: %s: mode=%x,IRQ_STAT=0x%.4x,RXPKTCNT=0x%.2x RXPDL=0x%.2x TXPKTCNT=0x%.2x TXPDL=0x%.2x\n", dev->name, lp->mode, (u_int) val, hp100_inb(RX_PKT_CNT), hp100_inb(RX_PDL), hp100_inb(TX_PKT_CNT), hp100_inb(TX_PDL)); #endif if (val == 0) { /* might be a shared interrupt */ spin_unlock(&lp->lock); hp100_ints_on(); return IRQ_NONE; } /* We're only interested in those interrupts we really enabled. */ /* val &= hp100_inw( IRQ_MASK ); */ /* * RX_PDL_FILL_COMPL is set whenever a RX_PDL has been executed. A RX_PDL * is considered executed whenever the RX_PDL data structure is no longer * needed. */ if (val & HP100_RX_PDL_FILL_COMPL) { if (lp->mode == 1) hp100_rx_bm(dev); else { printk("hp100: %s: rx_pdl_fill_compl interrupt although not busmaster?\n", dev->name); } } /* * The RX_PACKET interrupt is set, when the receive packet counter is * non zero. We use this interrupt for receiving in slave mode. In * busmaster mode, we use it to make sure we did not miss any rx_pdl_fill * interrupts. If rx_pdl_fill_compl is not set and rx_packet is set, then * we somehow have missed a rx_pdl_fill_compl interrupt. */ if (val & HP100_RX_PACKET) { /* Receive Packet Counter is non zero */ if (lp->mode != 1) /* non busmaster */ hp100_rx(dev); else if (!(val & HP100_RX_PDL_FILL_COMPL)) { /* Shouldnt happen - maybe we missed a RX_PDL_FILL Interrupt? */ hp100_rx_bm(dev); } } /* * Ack. that we have noticed the interrupt and thereby allow next one. * Note that this is now done after the slave rx function, since first * acknowledging and then setting ADV_NXT_PKT caused an extra interrupt * on the J2573. */ hp100_outw(val, IRQ_STATUS); /* * RX_ERROR is set when a packet is dropped due to no memory resources on * the card or when a RCV_ERR occurs. * TX_ERROR is set when a TX_ABORT condition occurs in the MAC->exists * only in the 802.3 MAC and happens when 16 collisions occur during a TX */ if (val & (HP100_TX_ERROR | HP100_RX_ERROR)) { #ifdef HP100_DEBUG_IRQ printk("hp100: %s: TX/RX Error IRQ\n", dev->name); #endif hp100_update_stats(dev); if (lp->mode == 1) { hp100_rxfill(dev); hp100_clean_txring(dev); } } /* * RX_PDA_ZERO is set when the PDA count goes from non-zero to zero. */ if ((lp->mode == 1) && (val & (HP100_RX_PDA_ZERO))) hp100_rxfill(dev); /* * HP100_TX_COMPLETE interrupt occurs when packet transmitted on wire * is completed */ if ((lp->mode == 1) && (val & (HP100_TX_COMPLETE))) hp100_clean_txring(dev); /* * MISC_ERROR is set when either the LAN link goes down or a detected * bus error occurs. */ if (val & HP100_MISC_ERROR) { /* New for J2585B */ #ifdef HP100_DEBUG_IRQ printk ("hp100: %s: Misc. Error Interrupt - Check cabling.\n", dev->name); #endif if (lp->mode == 1) { hp100_clean_txring(dev); hp100_rxfill(dev); } hp100_misc_interrupt(dev); } spin_unlock(&lp->lock); hp100_ints_on(); return IRQ_HANDLED; } /* * some misc functions */ static void hp100_start_interface(struct net_device *dev) { unsigned long flags; int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); #ifdef HP100_DEBUG_B hp100_outw(0x4220, TRACE); printk("hp100: %s: hp100_start_interface\n", dev->name); #endif spin_lock_irqsave(&lp->lock, flags); /* Ensure the adapter does not want to request an interrupt when */ /* enabling the IRQ line to be active on the bus (i.e. not tri-stated) */ hp100_page(PERFORMANCE); hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */ hp100_outw(0xffff, IRQ_STATUS); /* ack all IRQs */ hp100_outw(HP100_FAKE_INT | HP100_INT_EN | HP100_RESET_LB, OPTION_LSW); /* Un Tri-state int. TODO: Check if shared interrupts can be realised? */ hp100_outw(HP100_TRI_INT | HP100_RESET_HB, OPTION_LSW); if (lp->mode == 1) { /* Make sure BM bit is set... */ hp100_page(HW_MAP); hp100_orb(HP100_BM_MASTER, BM); hp100_rxfill(dev); } else if (lp->mode == 2) { /* Enable memory mapping. Note: Don't do this when busmaster. */ hp100_outw(HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW); } hp100_page(PERFORMANCE); hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */ hp100_outw(0xffff, IRQ_STATUS); /* ack IRQ */ /* enable a few interrupts: */ if (lp->mode == 1) { /* busmaster mode */ hp100_outw(HP100_RX_PDL_FILL_COMPL | HP100_RX_PDA_ZERO | HP100_RX_ERROR | /* HP100_RX_PACKET | */ /* HP100_RX_EARLY_INT | */ HP100_SET_HB | /* HP100_TX_PDA_ZERO | */ HP100_TX_COMPLETE | /* HP100_MISC_ERROR | */ HP100_TX_ERROR | HP100_SET_LB, IRQ_MASK); } else { hp100_outw(HP100_RX_PACKET | HP100_RX_ERROR | HP100_SET_HB | HP100_TX_ERROR | HP100_SET_LB, IRQ_MASK); } /* Note : before hp100_set_multicast_list(), because it will play with * spinlock itself... Jean II */ spin_unlock_irqrestore(&lp->lock, flags); /* Enable MAC Tx and RX, set MAC modes, ... */ hp100_set_multicast_list(dev); } static void hp100_stop_interface(struct net_device *dev) { struct hp100_private *lp = netdev_priv(dev); int ioaddr = dev->base_addr; u_int val; #ifdef HP100_DEBUG_B printk("hp100: %s: hp100_stop_interface\n", dev->name); hp100_outw(0x4221, TRACE); #endif if (lp->mode == 1) hp100_BM_shutdown(dev); else { /* Note: MMAP_DIS will be reenabled by start_interface */ hp100_outw(HP100_INT_EN | HP100_RESET_LB | HP100_TRI_INT | HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW); val = hp100_inw(OPTION_LSW); hp100_page(MAC_CTRL); hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1); if (!(val & HP100_HW_RST)) return; /* If reset, imm. return ... */ /* ... else: busy wait until idle */ for (val = 0; val < 6000; val++) if ((hp100_inb(MAC_CFG_1) & (HP100_TX_IDLE | HP100_RX_IDLE)) == (HP100_TX_IDLE | HP100_RX_IDLE)) { hp100_page(PERFORMANCE); return; } printk("hp100: %s: hp100_stop_interface - timeout\n", dev->name); hp100_page(PERFORMANCE); } } static void hp100_load_eeprom(struct net_device *dev, u_short probe_ioaddr) { int i; int ioaddr = probe_ioaddr > 0 ? probe_ioaddr : dev->base_addr; #ifdef HP100_DEBUG_B hp100_outw(0x4222, TRACE); #endif hp100_page(EEPROM_CTRL); hp100_andw(~HP100_EEPROM_LOAD, EEPROM_CTRL); hp100_orw(HP100_EEPROM_LOAD, EEPROM_CTRL); for (i = 0; i < 10000; i++) if (!(hp100_inb(OPTION_MSW) & HP100_EE_LOAD)) return; printk("hp100: %s: hp100_load_eeprom - timeout\n", dev->name); } /* Sense connection status. * return values: LAN_10 - Connected to 10Mbit/s network * LAN_100 - Connected to 100Mbit/s network * LAN_ERR - not connected or 100Mbit/s Hub down */ static int hp100_sense_lan(struct net_device *dev) { int ioaddr = dev->base_addr; u_short val_VG, val_10; struct hp100_private *lp = netdev_priv(dev); #ifdef HP100_DEBUG_B hp100_outw(0x4223, TRACE); #endif hp100_page(MAC_CTRL); val_10 = hp100_inb(10_LAN_CFG_1); val_VG = hp100_inb(VG_LAN_CFG_1); hp100_page(PERFORMANCE); #ifdef HP100_DEBUG printk("hp100: %s: sense_lan: val_VG = 0x%04x, val_10 = 0x%04x\n", dev->name, val_VG, val_10); #endif if (val_10 & HP100_LINK_BEAT_ST) /* 10Mb connection is active */ return HP100_LAN_10; if (val_10 & HP100_AUI_ST) { /* have we BNC or AUI onboard? */ /* * This can be overriden by dos utility, so if this has no effect, * perhaps you need to download that utility from HP and set card * back to "auto detect". */ val_10 |= HP100_AUI_SEL | HP100_LOW_TH; hp100_page(MAC_CTRL); hp100_outb(val_10, 10_LAN_CFG_1); hp100_page(PERFORMANCE); return HP100_LAN_COAX; } /* Those cards don't have a 100 Mbit connector */ if ( !strcmp(lp->id, "HWP1920") || (lp->pci_dev && lp->pci_dev->vendor == PCI_VENDOR_ID && (lp->pci_dev->device == PCI_DEVICE_ID_HP_J2970A || lp->pci_dev->device == PCI_DEVICE_ID_HP_J2973A))) return HP100_LAN_ERR; if (val_VG & HP100_LINK_CABLE_ST) /* Can hear the HUBs tone. */ return HP100_LAN_100; return HP100_LAN_ERR; } static int hp100_down_vg_link(struct net_device *dev) { struct hp100_private *lp = netdev_priv(dev); int ioaddr = dev->base_addr; unsigned long time; long savelan, newlan; #ifdef HP100_DEBUG_B hp100_outw(0x4224, TRACE); printk("hp100: %s: down_vg_link\n", dev->name); #endif hp100_page(MAC_CTRL); time = jiffies + (HZ / 4); do { if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST) break; if (!in_interrupt()) schedule_timeout_interruptible(1); } while (time_after(time, jiffies)); if (time_after_eq(jiffies, time)) /* no signal->no logout */ return 0; /* Drop the VG Link by clearing the link up cmd and load addr. */ hp100_andb(~(HP100_LOAD_ADDR | HP100_LINK_CMD), VG_LAN_CFG_1); hp100_orb(HP100_VG_SEL, VG_LAN_CFG_1); /* Conditionally stall for >250ms on Link-Up Status (to go down) */ time = jiffies + (HZ / 2); do { if (!(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST)) break; if (!in_interrupt()) schedule_timeout_interruptible(1); } while (time_after(time, jiffies)); #ifdef HP100_DEBUG if (time_after_eq(jiffies, time)) printk("hp100: %s: down_vg_link: Link does not go down?\n", dev->name); #endif /* To prevent condition where Rev 1 VG MAC and old hubs do not complete */ /* logout under traffic (even though all the status bits are cleared), */ /* do this workaround to get the Rev 1 MAC in its idle state */ if (lp->chip == HP100_CHIPID_LASSEN) { /* Reset VG MAC to insure it leaves the logoff state even if */ /* the Hub is still emitting tones */ hp100_andb(~HP100_VG_RESET, VG_LAN_CFG_1); udelay(1500); /* wait for >1ms */ hp100_orb(HP100_VG_RESET, VG_LAN_CFG_1); /* Release Reset */ udelay(1500); } /* New: For lassen, switch to 10 Mbps mac briefly to clear training ACK */ /* to get the VG mac to full reset. This is not req.d with later chips */ /* Note: It will take the between 1 and 2 seconds for the VG mac to be */ /* selected again! This will be left to the connect hub function to */ /* perform if desired. */ if (lp->chip == HP100_CHIPID_LASSEN) { /* Have to write to 10 and 100VG control registers simultaneously */ savelan = newlan = hp100_inl(10_LAN_CFG_1); /* read 10+100 LAN_CFG regs */ newlan &= ~(HP100_VG_SEL << 16); newlan |= (HP100_DOT3_MAC) << 8; hp100_andb(~HP100_AUTO_MODE, MAC_CFG_3); /* Autosel off */ hp100_outl(newlan, 10_LAN_CFG_1); /* Conditionally stall for 5sec on VG selected. */ time = jiffies + (HZ * 5); do { if (!(hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST)) break; if (!in_interrupt()) schedule_timeout_interruptible(1); } while (time_after(time, jiffies)); hp100_orb(HP100_AUTO_MODE, MAC_CFG_3); /* Autosel back on */ hp100_outl(savelan, 10_LAN_CFG_1); } time = jiffies + (3 * HZ); /* Timeout 3s */ do { if ((hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST) == 0) break; if (!in_interrupt()) schedule_timeout_interruptible(1); } while (time_after(time, jiffies)); if (time_before_eq(time, jiffies)) { #ifdef HP100_DEBUG printk("hp100: %s: down_vg_link: timeout\n", dev->name); #endif return -EIO; } time = jiffies + (2 * HZ); /* This seems to take a while.... */ do { if (!in_interrupt()) schedule_timeout_interruptible(1); } while (time_after(time, jiffies)); return 0; } static int hp100_login_to_vg_hub(struct net_device *dev, u_short force_relogin) { int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); u_short val = 0; unsigned long time; int startst; #ifdef HP100_DEBUG_B hp100_outw(0x4225, TRACE); printk("hp100: %s: login_to_vg_hub\n", dev->name); #endif /* Initiate a login sequence iff VG MAC is enabled and either Load Address * bit is zero or the force relogin flag is set (e.g. due to MAC address or * promiscuous mode change) */ hp100_page(MAC_CTRL); startst = hp100_inb(VG_LAN_CFG_1); if ((force_relogin == 1) || (hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST)) { #ifdef HP100_DEBUG_TRAINING printk("hp100: %s: Start training\n", dev->name); #endif /* Ensure VG Reset bit is 1 (i.e., do not reset) */ hp100_orb(HP100_VG_RESET, VG_LAN_CFG_1); /* If Lassen AND auto-select-mode AND VG tones were sensed on */ /* entry then temporarily put them into force 100Mbit mode */ if ((lp->chip == HP100_CHIPID_LASSEN) && (startst & HP100_LINK_CABLE_ST)) hp100_andb(~HP100_DOT3_MAC, 10_LAN_CFG_2); /* Drop the VG link by zeroing Link Up Command and Load Address */ hp100_andb(~(HP100_LINK_CMD /* |HP100_LOAD_ADDR */ ), VG_LAN_CFG_1); #ifdef HP100_DEBUG_TRAINING printk("hp100: %s: Bring down the link\n", dev->name); #endif /* Wait for link to drop */ time = jiffies + (HZ / 10); do { if (~(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST)) break; if (!in_interrupt()) schedule_timeout_interruptible(1); } while (time_after(time, jiffies)); /* Start an addressed training and optionally request promiscuous port */ if ((dev->flags) & IFF_PROMISC) { hp100_orb(HP100_PROM_MODE, VG_LAN_CFG_2); if (lp->chip == HP100_CHIPID_LASSEN) hp100_orw(HP100_MACRQ_PROMSC, TRAIN_REQUEST); } else { hp100_andb(~HP100_PROM_MODE, VG_LAN_CFG_2); /* For ETR parts we need to reset the prom. bit in the training * register, otherwise promiscious mode won't be disabled. */ if (lp->chip == HP100_CHIPID_LASSEN) { hp100_andw(~HP100_MACRQ_PROMSC, TRAIN_REQUEST); } } /* With ETR parts, frame format request bits can be set. */ if (lp->chip == HP100_CHIPID_LASSEN) hp100_orb(HP100_MACRQ_FRAMEFMT_EITHER, TRAIN_REQUEST); hp100_orb(HP100_LINK_CMD | HP100_LOAD_ADDR | HP100_VG_RESET, VG_LAN_CFG_1); /* Note: Next wait could be omitted for Hood and earlier chips under */ /* certain circumstances */ /* TODO: check if hood/earlier and skip wait. */ /* Wait for either short timeout for VG tones or long for login */ /* Wait for the card hardware to signalise link cable status ok... */ hp100_page(MAC_CTRL); time = jiffies + (1 * HZ); /* 1 sec timeout for cable st */ do { if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST) break; if (!in_interrupt()) schedule_timeout_interruptible(1); } while (time_before(jiffies, time)); if (time_after_eq(jiffies, time)) { #ifdef HP100_DEBUG_TRAINING printk("hp100: %s: Link cable status not ok? Training aborted.\n", dev->name); #endif } else { #ifdef HP100_DEBUG_TRAINING printk ("hp100: %s: HUB tones detected. Trying to train.\n", dev->name); #endif time = jiffies + (2 * HZ); /* again a timeout */ do { val = hp100_inb(VG_LAN_CFG_1); if ((val & (HP100_LINK_UP_ST))) { #ifdef HP100_DEBUG_TRAINING printk("hp100: %s: Passed training.\n", dev->name); #endif break; } if (!in_interrupt()) schedule_timeout_interruptible(1); } while (time_after(time, jiffies)); } /* If LINK_UP_ST is set, then we are logged into the hub. */ if (time_before_eq(jiffies, time) && (val & HP100_LINK_UP_ST)) { #ifdef HP100_DEBUG_TRAINING printk("hp100: %s: Successfully logged into the HUB.\n", dev->name); if (lp->chip == HP100_CHIPID_LASSEN) { val = hp100_inw(TRAIN_ALLOW); printk("hp100: %s: Card supports 100VG MAC Version \"%s\" ", dev->name, (hp100_inw(TRAIN_REQUEST) & HP100_CARD_MACVER) ? "802.12" : "Pre"); printk("Driver will use MAC Version \"%s\"\n", (val & HP100_HUB_MACVER) ? "802.12" : "Pre"); printk("hp100: %s: Frame format is %s.\n", dev->name, (val & HP100_MALLOW_FRAMEFMT) ? "802.5" : "802.3"); } #endif } else { /* If LINK_UP_ST is not set, login was not successful */ printk("hp100: %s: Problem logging into the HUB.\n", dev->name); if (lp->chip == HP100_CHIPID_LASSEN) { /* Check allowed Register to find out why there is a problem. */ val = hp100_inw(TRAIN_ALLOW); /* won't work on non-ETR card */ #ifdef HP100_DEBUG_TRAINING printk("hp100: %s: MAC Configuration requested: 0x%04x, HUB allowed: 0x%04x\n", dev->name, hp100_inw(TRAIN_REQUEST), val); #endif if (val & HP100_MALLOW_ACCDENIED) printk("hp100: %s: HUB access denied.\n", dev->name); if (val & HP100_MALLOW_CONFIGURE) printk("hp100: %s: MAC Configuration is incompatible with the Network.\n", dev->name); if (val & HP100_MALLOW_DUPADDR) printk("hp100: %s: Duplicate MAC Address on the Network.\n", dev->name); } } /* If we have put the chip into forced 100 Mbit mode earlier, go back */ /* to auto-select mode */ if ((lp->chip == HP100_CHIPID_LASSEN) && (startst & HP100_LINK_CABLE_ST)) { hp100_page(MAC_CTRL); hp100_orb(HP100_DOT3_MAC, 10_LAN_CFG_2); } val = hp100_inb(VG_LAN_CFG_1); /* Clear the MISC_ERROR Interrupt, which might be generated when doing the relogin */ hp100_page(PERFORMANCE); hp100_outw(HP100_MISC_ERROR, IRQ_STATUS); if (val & HP100_LINK_UP_ST) return (0); /* login was ok */ else { printk("hp100: %s: Training failed.\n", dev->name); hp100_down_vg_link(dev); return -EIO; } } /* no forced relogin & already link there->no training. */ return -EIO; } static void hp100_cascade_reset(struct net_device *dev, u_short enable) { int ioaddr = dev->base_addr; struct hp100_private *lp = netdev_priv(dev); #ifdef HP100_DEBUG_B hp100_outw(0x4226, TRACE); printk("hp100: %s: cascade_reset\n", dev->name); #endif if (enable) { hp100_outw(HP100_HW_RST | HP100_RESET_LB, OPTION_LSW); if (lp->chip == HP100_CHIPID_LASSEN) { /* Lassen requires a PCI transmit fifo reset */ hp100_page(HW_MAP); hp100_andb(~HP100_PCI_RESET, PCICTRL2); hp100_orb(HP100_PCI_RESET, PCICTRL2); /* Wait for min. 300 ns */ /* we can't use jiffies here, because it may be */ /* that we have disabled the timer... */ udelay(400); hp100_andb(~HP100_PCI_RESET, PCICTRL2); hp100_page(PERFORMANCE); } } else { /* bring out of reset */ hp100_outw(HP100_HW_RST | HP100_SET_LB, OPTION_LSW); udelay(400); hp100_page(PERFORMANCE); } } #ifdef HP100_DEBUG void hp100_RegisterDump(struct net_device *dev) { int ioaddr = dev->base_addr; int Page; int Register; /* Dump common registers */ printk("hp100: %s: Cascade Register Dump\n", dev->name); printk("hardware id #1: 0x%.2x\n", hp100_inb(HW_ID)); printk("hardware id #2/paging: 0x%.2x\n", hp100_inb(PAGING)); printk("option #1: 0x%.4x\n", hp100_inw(OPTION_LSW)); printk("option #2: 0x%.4x\n", hp100_inw(OPTION_MSW)); /* Dump paged registers */ for (Page = 0; Page < 8; Page++) { /* Dump registers */ printk("page: 0x%.2x\n", Page); outw(Page, ioaddr + 0x02); for (Register = 0x8; Register < 0x22; Register += 2) { /* Display Register contents except data port */ if (((Register != 0x10) && (Register != 0x12)) || (Page > 0)) { printk("0x%.2x = 0x%.4x\n", Register, inw(ioaddr + Register)); } } } hp100_page(PERFORMANCE); } #endif static void cleanup_dev(struct net_device *d) { struct hp100_private *p = netdev_priv(d); unregister_netdev(d); release_region(d->base_addr, HP100_REGION_SIZE); if (p->mode == 1) /* busmaster */ pci_free_consistent(p->pci_dev, MAX_RINGSIZE + 0x0f, p->page_vaddr_algn, virt_to_whatever(d, p->page_vaddr_algn)); if (p->mem_ptr_virt) iounmap(p->mem_ptr_virt); free_netdev(d); } #ifdef CONFIG_EISA static int __init hp100_eisa_probe (struct device *gendev) { struct net_device *dev = alloc_etherdev(sizeof(struct hp100_private)); struct eisa_device *edev = to_eisa_device(gendev); int err; if (!dev) return -ENOMEM; SET_NETDEV_DEV(dev, &edev->dev); err = hp100_probe1(dev, edev->base_addr + 0xC38, HP100_BUS_EISA, NULL); if (err) goto out1; #ifdef HP100_DEBUG printk("hp100: %s: EISA adapter found at 0x%x\n", dev->name, dev->base_addr); #endif gendev->driver_data = dev; return 0; out1: free_netdev(dev); return err; } static int __devexit hp100_eisa_remove (struct device *gendev) { struct net_device *dev = gendev->driver_data; cleanup_dev(dev); return 0; } static struct eisa_driver hp100_eisa_driver = { .id_table = hp100_eisa_tbl, .driver = { .name = "hp100", .probe = hp100_eisa_probe, .remove = __devexit_p (hp100_eisa_remove), } }; #endif #ifdef CONFIG_PCI static int __devinit hp100_pci_probe (struct pci_dev *pdev, const struct pci_device_id *ent) { struct net_device *dev; int ioaddr; u_short pci_command; int err; if (pci_enable_device(pdev)) return -ENODEV; dev = alloc_etherdev(sizeof(struct hp100_private)); if (!dev) { err = -ENOMEM; goto out0; } SET_NETDEV_DEV(dev, &pdev->dev); pci_read_config_word(pdev, PCI_COMMAND, &pci_command); if (!(pci_command & PCI_COMMAND_IO)) { #ifdef HP100_DEBUG printk("hp100: %s: PCI I/O Bit has not been set. Setting...\n", dev->name); #endif pci_command |= PCI_COMMAND_IO; pci_write_config_word(pdev, PCI_COMMAND, pci_command); } if (!(pci_command & PCI_COMMAND_MASTER)) { #ifdef HP100_DEBUG printk("hp100: %s: PCI Master Bit has not been set. Setting...\n", dev->name); #endif pci_command |= PCI_COMMAND_MASTER; pci_write_config_word(pdev, PCI_COMMAND, pci_command); } ioaddr = pci_resource_start(pdev, 0); err = hp100_probe1(dev, ioaddr, HP100_BUS_PCI, pdev); if (err) goto out1; #ifdef HP100_DEBUG printk("hp100: %s: PCI adapter found at 0x%x\n", dev->name, ioaddr); #endif pci_set_drvdata(pdev, dev); return 0; out1: free_netdev(dev); out0: pci_disable_device(pdev); return err; } static void __devexit hp100_pci_remove (struct pci_dev *pdev) { struct net_device *dev = pci_get_drvdata(pdev); cleanup_dev(dev); pci_disable_device(pdev); } static struct pci_driver hp100_pci_driver = { .name = "hp100", .id_table = hp100_pci_tbl, .probe = hp100_pci_probe, .remove = __devexit_p(hp100_pci_remove), }; #endif /* * module section */ MODULE_LICENSE("GPL"); MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, " "Siegfried \"Frieder\" Loeffler (dg1sek) <floeff@mathematik.uni-stuttgart.de>"); MODULE_DESCRIPTION("HP CASCADE Architecture Driver for 100VG-AnyLan Network Adapters"); /* * Note: to register three isa devices, use: * option hp100 hp100_port=0,0,0 * to register one card at io 0x280 as eth239, use: * option hp100 hp100_port=0x280 */ #if defined(MODULE) && defined(CONFIG_ISA) #define HP100_DEVICES 5 /* Parameters set by insmod */ static int hp100_port[HP100_DEVICES] = { 0, [1 ... (HP100_DEVICES-1)] = -1 }; module_param_array(hp100_port, int, NULL, 0); /* List of devices */ static struct net_device *hp100_devlist[HP100_DEVICES]; static int __init hp100_isa_init(void) { struct net_device *dev; int i, err, cards = 0; /* Don't autoprobe ISA bus */ if (hp100_port[0] == 0) return -ENODEV; /* Loop on all possible base addresses */ for (i = 0; i < HP100_DEVICES && hp100_port[i] != -1; ++i) { dev = alloc_etherdev(sizeof(struct hp100_private)); if (!dev) { printk(KERN_WARNING "hp100: no memory for network device\n"); while (cards > 0) cleanup_dev(hp100_devlist[--cards]); return -ENOMEM; } err = hp100_isa_probe(dev, hp100_port[i]); if (!err) hp100_devlist[cards++] = dev; else free_netdev(dev); } return cards > 0 ? 0 : -ENODEV; } static void hp100_isa_cleanup(void) { int i; for (i = 0; i < HP100_DEVICES; i++) { struct net_device *dev = hp100_devlist[i]; if (dev) cleanup_dev(dev); } } #else #define hp100_isa_init() (0) #define hp100_isa_cleanup() do { } while(0) #endif static int __init hp100_module_init(void) { int err; err = hp100_isa_init(); if (err && err != -ENODEV) goto out; #ifdef CONFIG_EISA err = eisa_driver_register(&hp100_eisa_driver); if (err && err != -ENODEV) goto out2; #endif #ifdef CONFIG_PCI err = pci_register_driver(&hp100_pci_driver); if (err && err != -ENODEV) goto out3; #endif out: return err; out3: #ifdef CONFIG_EISA eisa_driver_unregister (&hp100_eisa_driver); out2: #endif hp100_isa_cleanup(); goto out; } static void __exit hp100_module_exit(void) { hp100_isa_cleanup(); #ifdef CONFIG_EISA eisa_driver_unregister (&hp100_eisa_driver); #endif #ifdef CONFIG_PCI pci_unregister_driver (&hp100_pci_driver); #endif } module_init(hp100_module_init) module_exit(hp100_module_exit) /* * Local variables: * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c hp100.c" * c-indent-level: 2 * tab-width: 8 * End: */