xref: /linux/drivers/net/ethernet/i825xx/sun3_82586.c (revision d44cd8226449114780a8554fd253c7e3d171a0a6)
14f693a8fSBagas Sanjaya // SPDX-License-Identifier: GPL-2.0-only
211597885SJeff Kirsher /*
311597885SJeff Kirsher  * Sun3 i82586 Ethernet driver
411597885SJeff Kirsher  *
511597885SJeff Kirsher  * Cloned from ni52.c for the Sun3 by Sam Creasey (sammy@sammy.net)
611597885SJeff Kirsher  *
711597885SJeff Kirsher  * Original copyright follows:
811597885SJeff Kirsher  * --------------------------
911597885SJeff Kirsher  *
1011597885SJeff Kirsher  * net-3-driver for the NI5210 card (i82586 Ethernet chip)
1111597885SJeff Kirsher  *
1211597885SJeff Kirsher  * This is an extension to the Linux operating system, and is covered by the
1311597885SJeff Kirsher  * same Gnu Public License that covers that work.
1411597885SJeff Kirsher  *
1511597885SJeff Kirsher  * Alphacode 0.82 (96/09/29) for Linux 2.0.0 (or later)
1611597885SJeff Kirsher  * Copyrights (c) 1994,1995,1996 by M.Hipp (hippm@informatik.uni-tuebingen.de)
1711597885SJeff Kirsher  * --------------------------
1811597885SJeff Kirsher  *
1911597885SJeff Kirsher  * Consult ni52.c for further notes from the original driver.
2011597885SJeff Kirsher  *
2111597885SJeff Kirsher  * This incarnation currently supports the OBIO version of the i82586 chip
2211597885SJeff Kirsher  * used in certain sun3 models.  It should be fairly doable to expand this
2311597885SJeff Kirsher  * to support VME if I should every acquire such a board.
2411597885SJeff Kirsher  *
2511597885SJeff Kirsher  */
2611597885SJeff Kirsher 
2711597885SJeff Kirsher static int debuglevel = 0; /* debug-printk 0: off 1: a few 2: more */
2811597885SJeff Kirsher static int automatic_resume = 0; /* experimental .. better should be zero */
2911597885SJeff Kirsher static int rfdadd = 0; /* rfdadd=1 may be better for 8K MEM cards */
3011597885SJeff Kirsher static int fifo=0x8;	/* don't change */
3111597885SJeff Kirsher 
3211597885SJeff Kirsher #include <linux/kernel.h>
33e179d78eSArnd Bergmann #include <linux/module.h>
3411597885SJeff Kirsher #include <linux/string.h>
3511597885SJeff Kirsher #include <linux/errno.h>
3611597885SJeff Kirsher #include <linux/ioport.h>
3711597885SJeff Kirsher #include <linux/interrupt.h>
3811597885SJeff Kirsher #include <linux/delay.h>
3911597885SJeff Kirsher #include <linux/init.h>
4011597885SJeff Kirsher #include <linux/bitops.h>
4111597885SJeff Kirsher #include <asm/io.h>
4211597885SJeff Kirsher #include <asm/idprom.h>
4311597885SJeff Kirsher #include <asm/machines.h>
4411597885SJeff Kirsher #include <asm/sun3mmu.h>
4511597885SJeff Kirsher #include <asm/dvma.h>
4611597885SJeff Kirsher #include <asm/byteorder.h>
4711597885SJeff Kirsher 
4811597885SJeff Kirsher #include <linux/netdevice.h>
4911597885SJeff Kirsher #include <linux/etherdevice.h>
5011597885SJeff Kirsher #include <linux/skbuff.h>
5111597885SJeff Kirsher 
5211597885SJeff Kirsher #include "sun3_82586.h"
5311597885SJeff Kirsher 
5411597885SJeff Kirsher #define DRV_NAME "sun3_82586"
5511597885SJeff Kirsher 
5611597885SJeff Kirsher #define DEBUG       /* debug on */
5711597885SJeff Kirsher #define SYSBUSVAL 0 /* 16 Bit */
5811597885SJeff Kirsher #define SUN3_82586_TOTAL_SIZE	PAGE_SIZE
5911597885SJeff Kirsher 
6011597885SJeff Kirsher #define sun3_attn586()  {*(volatile unsigned char *)(dev->base_addr) |= IEOB_ATTEN; *(volatile unsigned char *)(dev->base_addr) &= ~IEOB_ATTEN;}
6111597885SJeff Kirsher #define sun3_reset586() {*(volatile unsigned char *)(dev->base_addr) = 0; udelay(100); *(volatile unsigned char *)(dev->base_addr) = IEOB_NORSET;}
6211597885SJeff Kirsher #define sun3_disint()   {*(volatile unsigned char *)(dev->base_addr) &= ~IEOB_IENAB;}
6311597885SJeff Kirsher #define sun3_enaint()   {*(volatile unsigned char *)(dev->base_addr) |= IEOB_IENAB;}
6411597885SJeff Kirsher #define sun3_active()   {*(volatile unsigned char *)(dev->base_addr) |= (IEOB_IENAB|IEOB_ONAIR|IEOB_NORSET);}
6511597885SJeff Kirsher 
6611597885SJeff Kirsher #define make32(ptr16) (p->memtop + (swab16((unsigned short) (ptr16))) )
6711597885SJeff Kirsher #define make24(ptr32) (char *)swab32(( ((unsigned long) (ptr32)) - p->base))
6811597885SJeff Kirsher #define make16(ptr32) (swab16((unsigned short) ((unsigned long)(ptr32) - (unsigned long) p->memtop )))
6911597885SJeff Kirsher 
7011597885SJeff Kirsher /******************* how to calculate the buffers *****************************
7111597885SJeff Kirsher 
7211597885SJeff Kirsher   * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
7311597885SJeff Kirsher   * --------------- in a different (more stable?) mode. Only in this mode it's
7411597885SJeff Kirsher   *                 possible to configure the driver with 'NO_NOPCOMMANDS'
7511597885SJeff Kirsher 
7611597885SJeff Kirsher sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
7711597885SJeff Kirsher sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
7811597885SJeff Kirsher sizeof(rfd) = 24; sizeof(rbd) = 12;
7911597885SJeff Kirsher sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
8011597885SJeff Kirsher sizeof(nop_cmd) = 8;
8111597885SJeff Kirsher 
8211597885SJeff Kirsher   * if you don't know the driver, better do not change these values: */
8311597885SJeff Kirsher 
8411597885SJeff Kirsher #define RECV_BUFF_SIZE 1536 /* slightly oversized */
8511597885SJeff Kirsher #define XMIT_BUFF_SIZE 1536 /* slightly oversized */
8611597885SJeff Kirsher #define NUM_XMIT_BUFFS 1    /* config for 32K shmem */
8711597885SJeff Kirsher #define NUM_RECV_BUFFS_8 4 /* config for 32K shared mem */
8811597885SJeff Kirsher #define NUM_RECV_BUFFS_16 9 /* config for 32K shared mem */
8911597885SJeff Kirsher #define NUM_RECV_BUFFS_32 16 /* config for 32K shared mem */
9011597885SJeff Kirsher #define NO_NOPCOMMANDS      /* only possible with NUM_XMIT_BUFFS=1 */
9111597885SJeff Kirsher 
9211597885SJeff Kirsher /**************************************************************************/
9311597885SJeff Kirsher 
9411597885SJeff Kirsher /* different DELAYs */
9511597885SJeff Kirsher #define DELAY(x) mdelay(32 * x);
9611597885SJeff Kirsher #define DELAY_16(); { udelay(16); }
9711597885SJeff Kirsher #define DELAY_18(); { udelay(4); }
9811597885SJeff Kirsher 
9911597885SJeff Kirsher /* wait for command with timeout: */
10011597885SJeff Kirsher #define WAIT_4_SCB_CMD() \
10111597885SJeff Kirsher { int i; \
10211597885SJeff Kirsher   for(i=0;i<16384;i++) { \
10311597885SJeff Kirsher     if(!p->scb->cmd_cuc) break; \
10411597885SJeff Kirsher     DELAY_18(); \
10511597885SJeff Kirsher     if(i == 16383) { \
10611597885SJeff Kirsher       printk("%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_cuc,p->scb->cus); \
10711597885SJeff Kirsher        if(!p->reseted) { p->reseted = 1; sun3_reset586(); } } } }
10811597885SJeff Kirsher 
10911597885SJeff Kirsher #define WAIT_4_SCB_CMD_RUC() { int i; \
11011597885SJeff Kirsher   for(i=0;i<16384;i++) { \
11111597885SJeff Kirsher     if(!p->scb->cmd_ruc) break; \
11211597885SJeff Kirsher     DELAY_18(); \
11311597885SJeff Kirsher     if(i == 16383) { \
11411597885SJeff Kirsher       printk("%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_ruc,p->scb->rus); \
11511597885SJeff Kirsher        if(!p->reseted) { p->reseted = 1; sun3_reset586(); } } } }
11611597885SJeff Kirsher 
11711597885SJeff Kirsher #define WAIT_4_STAT_COMPL(addr) { int i; \
11811597885SJeff Kirsher    for(i=0;i<32767;i++) { \
11911597885SJeff Kirsher      if(swab16((addr)->cmd_status) & STAT_COMPL) break; \
12011597885SJeff Kirsher      DELAY_16(); DELAY_16(); } }
12111597885SJeff Kirsher 
12211597885SJeff Kirsher static int     sun3_82586_probe1(struct net_device *dev,int ioaddr);
12311597885SJeff Kirsher static irqreturn_t sun3_82586_interrupt(int irq,void *dev_id);
12411597885SJeff Kirsher static int     sun3_82586_open(struct net_device *dev);
12511597885SJeff Kirsher static int     sun3_82586_close(struct net_device *dev);
126648c361aSYueHaibing static netdev_tx_t     sun3_82586_send_packet(struct sk_buff *,
127648c361aSYueHaibing 					      struct net_device *);
12811597885SJeff Kirsher static struct  net_device_stats *sun3_82586_get_stats(struct net_device *dev);
12911597885SJeff Kirsher static void    set_multicast_list(struct net_device *dev);
1300290bd29SMichael S. Tsirkin static void    sun3_82586_timeout(struct net_device *dev, unsigned int txqueue);
13111597885SJeff Kirsher #if 0
13211597885SJeff Kirsher static void    sun3_82586_dump(struct net_device *,void *);
13311597885SJeff Kirsher #endif
13411597885SJeff Kirsher 
13511597885SJeff Kirsher /* helper-functions */
13611597885SJeff Kirsher static int     init586(struct net_device *dev);
13711597885SJeff Kirsher static int     check586(struct net_device *dev,char *where,unsigned size);
13811597885SJeff Kirsher static void    alloc586(struct net_device *dev);
13911597885SJeff Kirsher static void    startrecv586(struct net_device *dev);
14011597885SJeff Kirsher static void   *alloc_rfa(struct net_device *dev,void *ptr);
14111597885SJeff Kirsher static void    sun3_82586_rcv_int(struct net_device *dev);
14211597885SJeff Kirsher static void    sun3_82586_xmt_int(struct net_device *dev);
14311597885SJeff Kirsher static void    sun3_82586_rnr_int(struct net_device *dev);
14411597885SJeff Kirsher 
14511597885SJeff Kirsher struct priv
14611597885SJeff Kirsher {
14711597885SJeff Kirsher 	unsigned long base;
14811597885SJeff Kirsher 	char *memtop;
14911597885SJeff Kirsher 	long int lock;
15011597885SJeff Kirsher 	int reseted;
15111597885SJeff Kirsher 	volatile struct rfd_struct	*rfd_last,*rfd_top,*rfd_first;
15211597885SJeff Kirsher 	volatile struct scp_struct	*scp;	/* volatile is important */
15311597885SJeff Kirsher 	volatile struct iscp_struct	*iscp;	/* volatile is important */
15411597885SJeff Kirsher 	volatile struct scb_struct	*scb;	/* volatile is important */
15511597885SJeff Kirsher 	volatile struct tbd_struct	*xmit_buffs[NUM_XMIT_BUFFS];
15611597885SJeff Kirsher 	volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
15711597885SJeff Kirsher #if (NUM_XMIT_BUFFS == 1)
15811597885SJeff Kirsher 	volatile struct nop_cmd_struct *nop_cmds[2];
15911597885SJeff Kirsher #else
16011597885SJeff Kirsher 	volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
16111597885SJeff Kirsher #endif
16211597885SJeff Kirsher 	volatile int		nop_point,num_recv_buffs;
16311597885SJeff Kirsher 	volatile char		*xmit_cbuffs[NUM_XMIT_BUFFS];
16411597885SJeff Kirsher 	volatile int		xmit_count,xmit_last;
16511597885SJeff Kirsher };
16611597885SJeff Kirsher 
16711597885SJeff Kirsher /**********************************************
16811597885SJeff Kirsher  * close device
16911597885SJeff Kirsher  */
sun3_82586_close(struct net_device * dev)17011597885SJeff Kirsher static int sun3_82586_close(struct net_device *dev)
17111597885SJeff Kirsher {
17211597885SJeff Kirsher 	free_irq(dev->irq, dev);
17311597885SJeff Kirsher 
17411597885SJeff Kirsher 	sun3_reset586(); /* the hard way to stop the receiver */
17511597885SJeff Kirsher 
17611597885SJeff Kirsher 	netif_stop_queue(dev);
17711597885SJeff Kirsher 
17811597885SJeff Kirsher 	return 0;
17911597885SJeff Kirsher }
18011597885SJeff Kirsher 
18111597885SJeff Kirsher /**********************************************
18211597885SJeff Kirsher  * open device
18311597885SJeff Kirsher  */
sun3_82586_open(struct net_device * dev)18411597885SJeff Kirsher static int sun3_82586_open(struct net_device *dev)
18511597885SJeff Kirsher {
18611597885SJeff Kirsher 	int ret;
18711597885SJeff Kirsher 
18811597885SJeff Kirsher 	sun3_disint();
18911597885SJeff Kirsher 	alloc586(dev);
19011597885SJeff Kirsher 	init586(dev);
19111597885SJeff Kirsher 	startrecv586(dev);
19211597885SJeff Kirsher 	sun3_enaint();
19311597885SJeff Kirsher 
19411597885SJeff Kirsher 	ret = request_irq(dev->irq, sun3_82586_interrupt,0,dev->name,dev);
19511597885SJeff Kirsher 	if (ret)
19611597885SJeff Kirsher 	{
19711597885SJeff Kirsher 		sun3_reset586();
19811597885SJeff Kirsher 		return ret;
19911597885SJeff Kirsher 	}
20011597885SJeff Kirsher 
20111597885SJeff Kirsher 	netif_start_queue(dev);
20211597885SJeff Kirsher 
20311597885SJeff Kirsher 	return 0; /* most done by init */
20411597885SJeff Kirsher }
20511597885SJeff Kirsher 
20611597885SJeff Kirsher /**********************************************
20711597885SJeff Kirsher  * Check to see if there's an 82586 out there.
20811597885SJeff Kirsher  */
check586(struct net_device * dev,char * where,unsigned size)20911597885SJeff Kirsher static int check586(struct net_device *dev,char *where,unsigned size)
21011597885SJeff Kirsher {
21111597885SJeff Kirsher 	struct priv pb;
21211597885SJeff Kirsher 	struct priv *p = &pb;
21311597885SJeff Kirsher 	char *iscp_addr;
21411597885SJeff Kirsher 	int i;
21511597885SJeff Kirsher 
21611597885SJeff Kirsher 	p->base = (unsigned long) dvma_btov(0);
21711597885SJeff Kirsher 	p->memtop = (char *)dvma_btov((unsigned long)where);
21811597885SJeff Kirsher 	p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
21911597885SJeff Kirsher 	memset((char *)p->scp,0, sizeof(struct scp_struct));
22011597885SJeff Kirsher 	for(i=0;i<sizeof(struct scp_struct);i++) /* memory was writeable? */
22111597885SJeff Kirsher 		if(((char *)p->scp)[i])
22211597885SJeff Kirsher 			return 0;
22311597885SJeff Kirsher 	p->scp->sysbus = SYSBUSVAL;				/* 1 = 8Bit-Bus, 0 = 16 Bit */
22411597885SJeff Kirsher 	if(p->scp->sysbus != SYSBUSVAL)
22511597885SJeff Kirsher 		return 0;
22611597885SJeff Kirsher 
22711597885SJeff Kirsher 	iscp_addr = (char *)dvma_btov((unsigned long)where);
22811597885SJeff Kirsher 
22911597885SJeff Kirsher 	p->iscp = (struct iscp_struct *) iscp_addr;
23011597885SJeff Kirsher 	memset((char *)p->iscp,0, sizeof(struct iscp_struct));
23111597885SJeff Kirsher 
23211597885SJeff Kirsher 	p->scp->iscp = make24(p->iscp);
23311597885SJeff Kirsher 	p->iscp->busy = 1;
23411597885SJeff Kirsher 
23511597885SJeff Kirsher 	sun3_reset586();
23611597885SJeff Kirsher 	sun3_attn586();
23711597885SJeff Kirsher 	DELAY(1);	/* wait a while... */
23811597885SJeff Kirsher 
23911597885SJeff Kirsher 	if(p->iscp->busy) /* i82586 clears 'busy' after successful init */
24011597885SJeff Kirsher 		return 0;
24111597885SJeff Kirsher 
24211597885SJeff Kirsher 	return 1;
24311597885SJeff Kirsher }
24411597885SJeff Kirsher 
24511597885SJeff Kirsher /******************************************************************
24611597885SJeff Kirsher  * set iscp at the right place, called by sun3_82586_probe1 and open586.
24711597885SJeff Kirsher  */
alloc586(struct net_device * dev)24811597885SJeff Kirsher static void alloc586(struct net_device *dev)
24911597885SJeff Kirsher {
25011597885SJeff Kirsher 	struct priv *p = netdev_priv(dev);
25111597885SJeff Kirsher 
25211597885SJeff Kirsher 	sun3_reset586();
25311597885SJeff Kirsher 	DELAY(1);
25411597885SJeff Kirsher 
25511597885SJeff Kirsher 	p->scp	= (struct scp_struct *)	(p->base + SCP_DEFAULT_ADDRESS);
25611597885SJeff Kirsher 	p->iscp	= (struct iscp_struct *) dvma_btov(dev->mem_start);
25711597885SJeff Kirsher 	p->scb  = (struct scb_struct *)  ((char *)p->iscp + sizeof(struct iscp_struct));
25811597885SJeff Kirsher 
25911597885SJeff Kirsher 	memset((char *) p->iscp,0,sizeof(struct iscp_struct));
26011597885SJeff Kirsher 	memset((char *) p->scp ,0,sizeof(struct scp_struct));
26111597885SJeff Kirsher 
26211597885SJeff Kirsher 	p->scp->iscp = make24(p->iscp);
26311597885SJeff Kirsher 	p->scp->sysbus = SYSBUSVAL;
26411597885SJeff Kirsher 	p->iscp->scb_offset = make16(p->scb);
26511597885SJeff Kirsher 	p->iscp->scb_base = make24(dvma_btov(dev->mem_start));
26611597885SJeff Kirsher 
26711597885SJeff Kirsher 	p->iscp->busy = 1;
26811597885SJeff Kirsher 	sun3_reset586();
26911597885SJeff Kirsher 	sun3_attn586();
27011597885SJeff Kirsher 
27111597885SJeff Kirsher 	DELAY(1);
27211597885SJeff Kirsher 
27311597885SJeff Kirsher 	if(p->iscp->busy)
27411597885SJeff Kirsher 		printk("%s: Init-Problems (alloc).\n",dev->name);
27511597885SJeff Kirsher 
27611597885SJeff Kirsher 	p->reseted = 0;
27711597885SJeff Kirsher 
27811597885SJeff Kirsher 	memset((char *)p->scb,0,sizeof(struct scb_struct));
27911597885SJeff Kirsher }
28011597885SJeff Kirsher 
sun3_82586_probe(void)281e179d78eSArnd Bergmann static int __init sun3_82586_probe(void)
28211597885SJeff Kirsher {
28311597885SJeff Kirsher 	struct net_device *dev;
28411597885SJeff Kirsher 	unsigned long ioaddr;
28511597885SJeff Kirsher 	static int found = 0;
28611597885SJeff Kirsher 	int err = -ENOMEM;
28711597885SJeff Kirsher 
28811597885SJeff Kirsher 	/* check that this machine has an onboard 82586 */
28911597885SJeff Kirsher 	switch(idprom->id_machtype) {
29011597885SJeff Kirsher 	case SM_SUN3|SM_3_160:
29111597885SJeff Kirsher 	case SM_SUN3|SM_3_260:
29211597885SJeff Kirsher 		/* these machines have 82586 */
29311597885SJeff Kirsher 		break;
29411597885SJeff Kirsher 
29511597885SJeff Kirsher 	default:
296e179d78eSArnd Bergmann 		return -ENODEV;
29711597885SJeff Kirsher 	}
29811597885SJeff Kirsher 
29911597885SJeff Kirsher 	if (found)
300e179d78eSArnd Bergmann 		return -ENODEV;
30111597885SJeff Kirsher 
30211597885SJeff Kirsher 	ioaddr = (unsigned long)ioremap(IE_OBIO, SUN3_82586_TOTAL_SIZE);
30311597885SJeff Kirsher 	if (!ioaddr)
304e179d78eSArnd Bergmann 		return -ENOMEM;
30511597885SJeff Kirsher 	found = 1;
30611597885SJeff Kirsher 
30711597885SJeff Kirsher 	dev = alloc_etherdev(sizeof(struct priv));
30811597885SJeff Kirsher 	if (!dev)
30911597885SJeff Kirsher 		goto out;
31011597885SJeff Kirsher 	dev->irq = IE_IRQ;
31111597885SJeff Kirsher 	dev->base_addr = ioaddr;
31211597885SJeff Kirsher 	err = sun3_82586_probe1(dev, ioaddr);
31311597885SJeff Kirsher 	if (err)
31411597885SJeff Kirsher 		goto out1;
31511597885SJeff Kirsher 	err = register_netdev(dev);
31611597885SJeff Kirsher 	if (err)
31711597885SJeff Kirsher 		goto out2;
31866abf5fbSGeert Uytterhoeven 	return 0;
31911597885SJeff Kirsher 
32011597885SJeff Kirsher out2:
32111597885SJeff Kirsher 	release_region(ioaddr, SUN3_82586_TOTAL_SIZE);
32211597885SJeff Kirsher out1:
32311597885SJeff Kirsher 	free_netdev(dev);
32411597885SJeff Kirsher out:
32511597885SJeff Kirsher 	iounmap((void __iomem *)ioaddr);
326e179d78eSArnd Bergmann 	return err;
32711597885SJeff Kirsher }
328e179d78eSArnd Bergmann module_init(sun3_82586_probe);
32911597885SJeff Kirsher 
33011597885SJeff Kirsher static const struct net_device_ops sun3_82586_netdev_ops = {
33111597885SJeff Kirsher 	.ndo_open		= sun3_82586_open,
33211597885SJeff Kirsher 	.ndo_stop		= sun3_82586_close,
33311597885SJeff Kirsher 	.ndo_start_xmit		= sun3_82586_send_packet,
334afc4b13dSJiri Pirko 	.ndo_set_rx_mode	= set_multicast_list,
33511597885SJeff Kirsher 	.ndo_tx_timeout		= sun3_82586_timeout,
33611597885SJeff Kirsher 	.ndo_get_stats		= sun3_82586_get_stats,
33711597885SJeff Kirsher 	.ndo_validate_addr	= eth_validate_addr,
33811597885SJeff Kirsher 	.ndo_set_mac_address	= eth_mac_addr,
33911597885SJeff Kirsher };
34011597885SJeff Kirsher 
sun3_82586_probe1(struct net_device * dev,int ioaddr)34111597885SJeff Kirsher static int __init sun3_82586_probe1(struct net_device *dev,int ioaddr)
34211597885SJeff Kirsher {
343562ef98aSJakub Kicinski 	int size, retval;
34411597885SJeff Kirsher 
34511597885SJeff Kirsher 	if (!request_region(ioaddr, SUN3_82586_TOTAL_SIZE, DRV_NAME))
34611597885SJeff Kirsher 		return -EBUSY;
34711597885SJeff Kirsher 
34811597885SJeff Kirsher 	/* copy in the ethernet address from the prom */
349562ef98aSJakub Kicinski 	eth_hw_addr_set(dev, idprom->id_ethaddr);
35011597885SJeff Kirsher 
35111597885SJeff Kirsher 	printk("%s: SUN3 Intel 82586 found at %lx, ",dev->name,dev->base_addr);
35211597885SJeff Kirsher 
35311597885SJeff Kirsher 	/*
35411597885SJeff Kirsher 	 * check (or search) IO-Memory, 32K
35511597885SJeff Kirsher 	 */
35611597885SJeff Kirsher 	size = 0x8000;
35711597885SJeff Kirsher 
35811597885SJeff Kirsher 	dev->mem_start = (unsigned long)dvma_malloc_align(0x8000, 0x1000);
35911597885SJeff Kirsher 	dev->mem_end = dev->mem_start + size;
36011597885SJeff Kirsher 
36111597885SJeff Kirsher 	if(size != 0x2000 && size != 0x4000 && size != 0x8000) {
36211597885SJeff Kirsher 		printk("\n%s: Illegal memory size %d. Allowed is 0x2000 or 0x4000 or 0x8000 bytes.\n",dev->name,size);
36311597885SJeff Kirsher 		retval = -ENODEV;
36411597885SJeff Kirsher 		goto out;
36511597885SJeff Kirsher 	}
36611597885SJeff Kirsher 	if(!check586(dev,(char *) dev->mem_start,size)) {
36711597885SJeff Kirsher 		printk("?memcheck, Can't find memory at 0x%lx with size %d!\n",dev->mem_start,size);
36811597885SJeff Kirsher 		retval = -ENODEV;
36911597885SJeff Kirsher 		goto out;
37011597885SJeff Kirsher 	}
37111597885SJeff Kirsher 
37211597885SJeff Kirsher 	((struct priv *)netdev_priv(dev))->memtop =
37311597885SJeff Kirsher 					(char *)dvma_btov(dev->mem_start);
37411597885SJeff Kirsher 	((struct priv *)netdev_priv(dev))->base = (unsigned long) dvma_btov(0);
37511597885SJeff Kirsher 	alloc586(dev);
37611597885SJeff Kirsher 
37711597885SJeff Kirsher 	/* set number of receive-buffs according to memsize */
37811597885SJeff Kirsher 	if(size == 0x2000)
37911597885SJeff Kirsher 		((struct priv *)netdev_priv(dev))->num_recv_buffs =
38011597885SJeff Kirsher 							NUM_RECV_BUFFS_8;
38111597885SJeff Kirsher 	else if(size == 0x4000)
38211597885SJeff Kirsher 		((struct priv *)netdev_priv(dev))->num_recv_buffs =
38311597885SJeff Kirsher 							NUM_RECV_BUFFS_16;
38411597885SJeff Kirsher 	else
38511597885SJeff Kirsher 		((struct priv *)netdev_priv(dev))->num_recv_buffs =
38611597885SJeff Kirsher 							NUM_RECV_BUFFS_32;
38711597885SJeff Kirsher 
38811597885SJeff Kirsher 	printk("Memaddr: 0x%lx, Memsize: %d, IRQ %d\n",dev->mem_start,size, dev->irq);
38911597885SJeff Kirsher 
39011597885SJeff Kirsher 	dev->netdev_ops		= &sun3_82586_netdev_ops;
39111597885SJeff Kirsher 	dev->watchdog_timeo	= HZ/20;
39211597885SJeff Kirsher 
39311597885SJeff Kirsher 	dev->if_port 		= 0;
39411597885SJeff Kirsher 	return 0;
39511597885SJeff Kirsher out:
39611597885SJeff Kirsher 	release_region(ioaddr, SUN3_82586_TOTAL_SIZE);
39711597885SJeff Kirsher 	return retval;
39811597885SJeff Kirsher }
39911597885SJeff Kirsher 
40011597885SJeff Kirsher 
init586(struct net_device * dev)40111597885SJeff Kirsher static int init586(struct net_device *dev)
40211597885SJeff Kirsher {
40311597885SJeff Kirsher 	void *ptr;
40411597885SJeff Kirsher 	int i,result=0;
40511597885SJeff Kirsher 	struct priv *p = netdev_priv(dev);
40611597885SJeff Kirsher 	volatile struct configure_cmd_struct	*cfg_cmd;
40711597885SJeff Kirsher 	volatile struct iasetup_cmd_struct *ias_cmd;
40811597885SJeff Kirsher 	volatile struct tdr_cmd_struct *tdr_cmd;
40911597885SJeff Kirsher 	volatile struct mcsetup_cmd_struct *mc_cmd;
41011597885SJeff Kirsher 	struct netdev_hw_addr *ha;
41111597885SJeff Kirsher 	int num_addrs=netdev_mc_count(dev);
41211597885SJeff Kirsher 
41311597885SJeff Kirsher 	ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct));
41411597885SJeff Kirsher 
41511597885SJeff Kirsher 	cfg_cmd = (struct configure_cmd_struct *)ptr; /* configure-command */
41611597885SJeff Kirsher 	cfg_cmd->cmd_status	= 0;
41711597885SJeff Kirsher 	cfg_cmd->cmd_cmd	= swab16(CMD_CONFIGURE | CMD_LAST);
41811597885SJeff Kirsher 	cfg_cmd->cmd_link	= 0xffff;
41911597885SJeff Kirsher 
42011597885SJeff Kirsher 	cfg_cmd->byte_cnt	= 0x0a; /* number of cfg bytes */
42111597885SJeff Kirsher 	cfg_cmd->fifo		= fifo; /* fifo-limit (8=tx:32/rx:64) */
42211597885SJeff Kirsher 	cfg_cmd->sav_bf		= 0x40; /* hold or discard bad recv frames (bit 7) */
42311597885SJeff Kirsher 	cfg_cmd->adr_len	= 0x2e; /* addr_len |!src_insert |pre-len |loopback */
42411597885SJeff Kirsher 	cfg_cmd->priority	= 0x00;
42511597885SJeff Kirsher 	cfg_cmd->ifs		= 0x60;
42611597885SJeff Kirsher 	cfg_cmd->time_low	= 0x00;
42711597885SJeff Kirsher 	cfg_cmd->time_high	= 0xf2;
42811597885SJeff Kirsher 	cfg_cmd->promisc	= 0;
42911597885SJeff Kirsher 	if(dev->flags & IFF_ALLMULTI) {
43011597885SJeff Kirsher 		int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
43111597885SJeff Kirsher 		if(num_addrs > len)	{
43211597885SJeff Kirsher 			printk("%s: switching to promisc. mode\n",dev->name);
43311597885SJeff Kirsher 			cfg_cmd->promisc = 1;
43411597885SJeff Kirsher 		}
43511597885SJeff Kirsher 	}
43611597885SJeff Kirsher 	if(dev->flags&IFF_PROMISC)
43711597885SJeff Kirsher 		cfg_cmd->promisc = 1;
43811597885SJeff Kirsher 	cfg_cmd->carr_coll	= 0x00;
43911597885SJeff Kirsher 
44011597885SJeff Kirsher 	p->scb->cbl_offset	= make16(cfg_cmd);
44111597885SJeff Kirsher 	p->scb->cmd_ruc		= 0;
44211597885SJeff Kirsher 
44311597885SJeff Kirsher 	p->scb->cmd_cuc		= CUC_START; /* cmd.-unit start */
44411597885SJeff Kirsher 	sun3_attn586();
44511597885SJeff Kirsher 
44611597885SJeff Kirsher 	WAIT_4_STAT_COMPL(cfg_cmd);
44711597885SJeff Kirsher 
44811597885SJeff Kirsher 	if((swab16(cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != (STAT_COMPL|STAT_OK))
44911597885SJeff Kirsher 	{
45011597885SJeff Kirsher 		printk("%s: configure command failed: %x\n",dev->name,swab16(cfg_cmd->cmd_status));
45111597885SJeff Kirsher 		return 1;
45211597885SJeff Kirsher 	}
45311597885SJeff Kirsher 
45411597885SJeff Kirsher 	/*
45511597885SJeff Kirsher 	 * individual address setup
45611597885SJeff Kirsher 	 */
45711597885SJeff Kirsher 
45811597885SJeff Kirsher 	ias_cmd = (struct iasetup_cmd_struct *)ptr;
45911597885SJeff Kirsher 
46011597885SJeff Kirsher 	ias_cmd->cmd_status	= 0;
46111597885SJeff Kirsher 	ias_cmd->cmd_cmd	= swab16(CMD_IASETUP | CMD_LAST);
46211597885SJeff Kirsher 	ias_cmd->cmd_link	= 0xffff;
46311597885SJeff Kirsher 
46476660757SJakub Kicinski 	memcpy((char *)&ias_cmd->iaddr,(const char *) dev->dev_addr,ETH_ALEN);
46511597885SJeff Kirsher 
46611597885SJeff Kirsher 	p->scb->cbl_offset = make16(ias_cmd);
46711597885SJeff Kirsher 
46811597885SJeff Kirsher 	p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
46911597885SJeff Kirsher 	sun3_attn586();
47011597885SJeff Kirsher 
47111597885SJeff Kirsher 	WAIT_4_STAT_COMPL(ias_cmd);
47211597885SJeff Kirsher 
47311597885SJeff Kirsher 	if((swab16(ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != (STAT_OK|STAT_COMPL)) {
47411597885SJeff Kirsher 		printk("%s (82586): individual address setup command failed: %04x\n",dev->name,swab16(ias_cmd->cmd_status));
47511597885SJeff Kirsher 		return 1;
47611597885SJeff Kirsher 	}
47711597885SJeff Kirsher 
47811597885SJeff Kirsher 	/*
47911597885SJeff Kirsher 	 * TDR, wire check .. e.g. no resistor e.t.c
48011597885SJeff Kirsher 	 */
48111597885SJeff Kirsher 
48211597885SJeff Kirsher 	tdr_cmd = (struct tdr_cmd_struct *)ptr;
48311597885SJeff Kirsher 
48411597885SJeff Kirsher 	tdr_cmd->cmd_status	= 0;
48511597885SJeff Kirsher 	tdr_cmd->cmd_cmd	= swab16(CMD_TDR | CMD_LAST);
48611597885SJeff Kirsher 	tdr_cmd->cmd_link	= 0xffff;
48711597885SJeff Kirsher 	tdr_cmd->status		= 0;
48811597885SJeff Kirsher 
48911597885SJeff Kirsher 	p->scb->cbl_offset = make16(tdr_cmd);
49011597885SJeff Kirsher 	p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
49111597885SJeff Kirsher 	sun3_attn586();
49211597885SJeff Kirsher 
49311597885SJeff Kirsher 	WAIT_4_STAT_COMPL(tdr_cmd);
49411597885SJeff Kirsher 
49511597885SJeff Kirsher 	if(!(swab16(tdr_cmd->cmd_status) & STAT_COMPL))
49611597885SJeff Kirsher 	{
49711597885SJeff Kirsher 		printk("%s: Problems while running the TDR.\n",dev->name);
49811597885SJeff Kirsher 	}
49911597885SJeff Kirsher 	else
50011597885SJeff Kirsher 	{
50111597885SJeff Kirsher 		DELAY_16(); /* wait for result */
50211597885SJeff Kirsher 		result = swab16(tdr_cmd->status);
50311597885SJeff Kirsher 
50411597885SJeff Kirsher 		p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
50511597885SJeff Kirsher 		sun3_attn586(); /* ack the interrupts */
50611597885SJeff Kirsher 
50711597885SJeff Kirsher 		if(result & TDR_LNK_OK)
50811597885SJeff Kirsher 			;
50911597885SJeff Kirsher 		else if(result & TDR_XCVR_PRB)
51011597885SJeff Kirsher 			printk("%s: TDR: Transceiver problem. Check the cable(s)!\n",dev->name);
51111597885SJeff Kirsher 		else if(result & TDR_ET_OPN)
51211597885SJeff Kirsher 			printk("%s: TDR: No correct termination %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
51311597885SJeff Kirsher 		else if(result & TDR_ET_SRT)
51411597885SJeff Kirsher 		{
51511597885SJeff Kirsher 			if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */
51611597885SJeff Kirsher 				printk("%s: TDR: Detected a short circuit %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
51711597885SJeff Kirsher 		}
51811597885SJeff Kirsher 		else
51911597885SJeff Kirsher 			printk("%s: TDR: Unknown status %04x\n",dev->name,result);
52011597885SJeff Kirsher 	}
52111597885SJeff Kirsher 
52211597885SJeff Kirsher 	/*
52311597885SJeff Kirsher 	 * Multicast setup
52411597885SJeff Kirsher 	 */
52511597885SJeff Kirsher 	if(num_addrs && !(dev->flags & IFF_PROMISC) )
52611597885SJeff Kirsher 	{
52711597885SJeff Kirsher 		mc_cmd = (struct mcsetup_cmd_struct *) ptr;
52811597885SJeff Kirsher 		mc_cmd->cmd_status = 0;
52911597885SJeff Kirsher 		mc_cmd->cmd_cmd = swab16(CMD_MCSETUP | CMD_LAST);
53011597885SJeff Kirsher 		mc_cmd->cmd_link = 0xffff;
53111597885SJeff Kirsher 		mc_cmd->mc_cnt = swab16(num_addrs * 6);
53211597885SJeff Kirsher 
53311597885SJeff Kirsher 		i = 0;
53411597885SJeff Kirsher 		netdev_for_each_mc_addr(ha, dev)
53511597885SJeff Kirsher 			memcpy((char *) mc_cmd->mc_list[i++],
53611597885SJeff Kirsher 			       ha->addr, ETH_ALEN);
53711597885SJeff Kirsher 
53811597885SJeff Kirsher 		p->scb->cbl_offset = make16(mc_cmd);
53911597885SJeff Kirsher 		p->scb->cmd_cuc = CUC_START;
54011597885SJeff Kirsher 		sun3_attn586();
54111597885SJeff Kirsher 
54211597885SJeff Kirsher 		WAIT_4_STAT_COMPL(mc_cmd);
54311597885SJeff Kirsher 
54411597885SJeff Kirsher 		if( (swab16(mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
54511597885SJeff Kirsher 			printk("%s: Can't apply multicast-address-list.\n",dev->name);
54611597885SJeff Kirsher 	}
54711597885SJeff Kirsher 
54811597885SJeff Kirsher 	/*
54911597885SJeff Kirsher 	 * alloc nop/xmit-cmds
55011597885SJeff Kirsher 	 */
55111597885SJeff Kirsher #if (NUM_XMIT_BUFFS == 1)
55211597885SJeff Kirsher 	for(i=0;i<2;i++)
55311597885SJeff Kirsher 	{
55411597885SJeff Kirsher 		p->nop_cmds[i] 			= (struct nop_cmd_struct *)ptr;
55511597885SJeff Kirsher 		p->nop_cmds[i]->cmd_cmd		= swab16(CMD_NOP);
55611597885SJeff Kirsher 		p->nop_cmds[i]->cmd_status 	= 0;
55711597885SJeff Kirsher 		p->nop_cmds[i]->cmd_link	= make16((p->nop_cmds[i]));
55811597885SJeff Kirsher 		ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
55911597885SJeff Kirsher 	}
56011597885SJeff Kirsher #else
56111597885SJeff Kirsher 	for(i=0;i<NUM_XMIT_BUFFS;i++)
56211597885SJeff Kirsher 	{
56311597885SJeff Kirsher 		p->nop_cmds[i]			= (struct nop_cmd_struct *)ptr;
56411597885SJeff Kirsher 		p->nop_cmds[i]->cmd_cmd		= swab16(CMD_NOP);
56511597885SJeff Kirsher 		p->nop_cmds[i]->cmd_status	= 0;
56611597885SJeff Kirsher 		p->nop_cmds[i]->cmd_link	= make16((p->nop_cmds[i]));
56711597885SJeff Kirsher 		ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
56811597885SJeff Kirsher 	}
56911597885SJeff Kirsher #endif
57011597885SJeff Kirsher 
57164699336SJoe Perches 	ptr = alloc_rfa(dev,ptr); /* init receive-frame-area */
57211597885SJeff Kirsher 
57311597885SJeff Kirsher 	/*
57411597885SJeff Kirsher 	 * alloc xmit-buffs / init xmit_cmds
57511597885SJeff Kirsher 	 */
57611597885SJeff Kirsher 	for(i=0;i<NUM_XMIT_BUFFS;i++)
57711597885SJeff Kirsher 	{
57811597885SJeff Kirsher 		p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr; /*transmit cmd/buff 0*/
57911597885SJeff Kirsher 		ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
58011597885SJeff Kirsher 		p->xmit_cbuffs[i] = (char *)ptr; /* char-buffs */
58111597885SJeff Kirsher 		ptr = (char *) ptr + XMIT_BUFF_SIZE;
58211597885SJeff Kirsher 		p->xmit_buffs[i] = (struct tbd_struct *)ptr; /* TBD */
58311597885SJeff Kirsher 		ptr = (char *) ptr + sizeof(struct tbd_struct);
58464699336SJoe Perches 		if(ptr > (void *)dev->mem_end)
58511597885SJeff Kirsher 		{
58611597885SJeff Kirsher 			printk("%s: not enough shared-mem for your configuration!\n",dev->name);
58711597885SJeff Kirsher 			return 1;
58811597885SJeff Kirsher 		}
58911597885SJeff Kirsher 		memset((char *)(p->xmit_cmds[i]) ,0, sizeof(struct transmit_cmd_struct));
59011597885SJeff Kirsher 		memset((char *)(p->xmit_buffs[i]),0, sizeof(struct tbd_struct));
59111597885SJeff Kirsher 		p->xmit_cmds[i]->cmd_link = make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]);
59211597885SJeff Kirsher 		p->xmit_cmds[i]->cmd_status = swab16(STAT_COMPL);
59311597885SJeff Kirsher 		p->xmit_cmds[i]->cmd_cmd = swab16(CMD_XMIT | CMD_INT);
59411597885SJeff Kirsher 		p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i]));
59511597885SJeff Kirsher 		p->xmit_buffs[i]->next = 0xffff;
59611597885SJeff Kirsher 		p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i]));
59711597885SJeff Kirsher 	}
59811597885SJeff Kirsher 
59911597885SJeff Kirsher 	p->xmit_count = 0;
60011597885SJeff Kirsher 	p->xmit_last	= 0;
60111597885SJeff Kirsher #ifndef NO_NOPCOMMANDS
60211597885SJeff Kirsher 	p->nop_point	= 0;
60311597885SJeff Kirsher #endif
60411597885SJeff Kirsher 
60511597885SJeff Kirsher 	 /*
60611597885SJeff Kirsher 		* 'start transmitter'
60711597885SJeff Kirsher 		*/
60811597885SJeff Kirsher #ifndef NO_NOPCOMMANDS
60911597885SJeff Kirsher 	p->scb->cbl_offset = make16(p->nop_cmds[0]);
61011597885SJeff Kirsher 	p->scb->cmd_cuc = CUC_START;
61111597885SJeff Kirsher 	sun3_attn586();
61211597885SJeff Kirsher 	WAIT_4_SCB_CMD();
61311597885SJeff Kirsher #else
61411597885SJeff Kirsher 	p->xmit_cmds[0]->cmd_link = make16(p->xmit_cmds[0]);
61511597885SJeff Kirsher 	p->xmit_cmds[0]->cmd_cmd	= swab16(CMD_XMIT | CMD_SUSPEND | CMD_INT);
61611597885SJeff Kirsher #endif
61711597885SJeff Kirsher 
61811597885SJeff Kirsher 	/*
61911597885SJeff Kirsher 	 * ack. interrupts
62011597885SJeff Kirsher 	 */
62111597885SJeff Kirsher 	p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
62211597885SJeff Kirsher 	sun3_attn586();
62311597885SJeff Kirsher 	DELAY_16();
62411597885SJeff Kirsher 
62511597885SJeff Kirsher 	sun3_enaint();
62611597885SJeff Kirsher 	sun3_active();
62711597885SJeff Kirsher 
62811597885SJeff Kirsher 	return 0;
62911597885SJeff Kirsher }
63011597885SJeff Kirsher 
63111597885SJeff Kirsher /******************************************************
63211597885SJeff Kirsher  * This is a helper routine for sun3_82586_rnr_int() and init586().
63311597885SJeff Kirsher  * It sets up the Receive Frame Area (RFA).
63411597885SJeff Kirsher  */
63511597885SJeff Kirsher 
alloc_rfa(struct net_device * dev,void * ptr)63611597885SJeff Kirsher static void *alloc_rfa(struct net_device *dev,void *ptr)
63711597885SJeff Kirsher {
63811597885SJeff Kirsher 	volatile struct rfd_struct *rfd = (struct rfd_struct *)ptr;
63911597885SJeff Kirsher 	volatile struct rbd_struct *rbd;
64011597885SJeff Kirsher 	int i;
64111597885SJeff Kirsher 	struct priv *p = netdev_priv(dev);
64211597885SJeff Kirsher 
64311597885SJeff Kirsher 	memset((char *) rfd,0,sizeof(struct rfd_struct)*(p->num_recv_buffs+rfdadd));
64411597885SJeff Kirsher 	p->rfd_first = rfd;
64511597885SJeff Kirsher 
64611597885SJeff Kirsher 	for(i = 0; i < (p->num_recv_buffs+rfdadd); i++) {
64711597885SJeff Kirsher 		rfd[i].next = make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd) );
64811597885SJeff Kirsher 		rfd[i].rbd_offset = 0xffff;
64911597885SJeff Kirsher 	}
65011597885SJeff Kirsher 	rfd[p->num_recv_buffs-1+rfdadd].last = RFD_SUSP;	 /* RU suspend */
65111597885SJeff Kirsher 
65211597885SJeff Kirsher 	ptr = (void *) (rfd + (p->num_recv_buffs + rfdadd) );
65311597885SJeff Kirsher 
65411597885SJeff Kirsher 	rbd = (struct rbd_struct *) ptr;
65511597885SJeff Kirsher 	ptr = (void *) (rbd + p->num_recv_buffs);
65611597885SJeff Kirsher 
65711597885SJeff Kirsher 	 /* clr descriptors */
65811597885SJeff Kirsher 	memset((char *) rbd,0,sizeof(struct rbd_struct)*(p->num_recv_buffs));
65911597885SJeff Kirsher 
66011597885SJeff Kirsher 	for(i=0;i<p->num_recv_buffs;i++)
66111597885SJeff Kirsher 	{
66211597885SJeff Kirsher 		rbd[i].next = make16((rbd + (i+1) % p->num_recv_buffs));
66311597885SJeff Kirsher 		rbd[i].size = swab16(RECV_BUFF_SIZE);
66411597885SJeff Kirsher 		rbd[i].buffer = make24(ptr);
66511597885SJeff Kirsher 		ptr = (char *) ptr + RECV_BUFF_SIZE;
66611597885SJeff Kirsher 	}
66711597885SJeff Kirsher 
66811597885SJeff Kirsher 	p->rfd_top	= p->rfd_first;
66911597885SJeff Kirsher 	p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
67011597885SJeff Kirsher 
67111597885SJeff Kirsher 	p->scb->rfa_offset		= make16(p->rfd_first);
67211597885SJeff Kirsher 	p->rfd_first->rbd_offset	= make16(rbd);
67311597885SJeff Kirsher 
67411597885SJeff Kirsher 	return ptr;
67511597885SJeff Kirsher }
67611597885SJeff Kirsher 
67711597885SJeff Kirsher 
67811597885SJeff Kirsher /**************************************************
67911597885SJeff Kirsher  * Interrupt Handler ...
68011597885SJeff Kirsher  */
68111597885SJeff Kirsher 
sun3_82586_interrupt(int irq,void * dev_id)68211597885SJeff Kirsher static irqreturn_t sun3_82586_interrupt(int irq,void *dev_id)
68311597885SJeff Kirsher {
68411597885SJeff Kirsher 	struct net_device *dev = dev_id;
68511597885SJeff Kirsher 	unsigned short stat;
68611597885SJeff Kirsher 	int cnt=0;
68711597885SJeff Kirsher 	struct priv *p;
68811597885SJeff Kirsher 
68911597885SJeff Kirsher 	if (!dev) {
69011597885SJeff Kirsher 		printk ("sun3_82586-interrupt: irq %d for unknown device.\n",irq);
69111597885SJeff Kirsher 		return IRQ_NONE;
69211597885SJeff Kirsher 	}
69311597885SJeff Kirsher 	p = netdev_priv(dev);
69411597885SJeff Kirsher 
69511597885SJeff Kirsher 	if(debuglevel > 1)
69611597885SJeff Kirsher 		printk("I");
69711597885SJeff Kirsher 
69811597885SJeff Kirsher 	WAIT_4_SCB_CMD(); /* wait for last command	*/
69911597885SJeff Kirsher 
70011597885SJeff Kirsher 	while((stat=p->scb->cus & STAT_MASK))
70111597885SJeff Kirsher 	{
70211597885SJeff Kirsher 		p->scb->cmd_cuc = stat;
70311597885SJeff Kirsher 		sun3_attn586();
70411597885SJeff Kirsher 
70511597885SJeff Kirsher 		if(stat & STAT_FR)	 /* received a frame */
70611597885SJeff Kirsher 			sun3_82586_rcv_int(dev);
70711597885SJeff Kirsher 
70811597885SJeff Kirsher 		if(stat & STAT_RNR) /* RU went 'not ready' */
70911597885SJeff Kirsher 		{
71011597885SJeff Kirsher 			printk("(R)");
71111597885SJeff Kirsher 			if(p->scb->rus & RU_SUSPEND) /* special case: RU_SUSPEND */
71211597885SJeff Kirsher 			{
71311597885SJeff Kirsher 				WAIT_4_SCB_CMD();
71411597885SJeff Kirsher 				p->scb->cmd_ruc = RUC_RESUME;
71511597885SJeff Kirsher 				sun3_attn586();
71611597885SJeff Kirsher 				WAIT_4_SCB_CMD_RUC();
71711597885SJeff Kirsher 			}
71811597885SJeff Kirsher 			else
71911597885SJeff Kirsher 			{
72011597885SJeff Kirsher 				printk("%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->rus);
72111597885SJeff Kirsher 				sun3_82586_rnr_int(dev);
72211597885SJeff Kirsher 			}
72311597885SJeff Kirsher 		}
72411597885SJeff Kirsher 
72511597885SJeff Kirsher 		if(stat & STAT_CX)		/* command with I-bit set complete */
72611597885SJeff Kirsher 			 sun3_82586_xmt_int(dev);
72711597885SJeff Kirsher 
72811597885SJeff Kirsher #ifndef NO_NOPCOMMANDS
72911597885SJeff Kirsher 		if(stat & STAT_CNA)	/* CU went 'not ready' */
73011597885SJeff Kirsher 		{
73111597885SJeff Kirsher 			if(netif_running(dev))
73211597885SJeff Kirsher 				printk("%s: oops! CU has left active state. stat: %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->cus);
73311597885SJeff Kirsher 		}
73411597885SJeff Kirsher #endif
73511597885SJeff Kirsher 
73611597885SJeff Kirsher 		if(debuglevel > 1)
73711597885SJeff Kirsher 			printk("%d",cnt++);
73811597885SJeff Kirsher 
73911597885SJeff Kirsher 		WAIT_4_SCB_CMD(); /* wait for ack. (sun3_82586_xmt_int can be faster than ack!!) */
74011597885SJeff Kirsher 		if(p->scb->cmd_cuc)	 /* timed out? */
74111597885SJeff Kirsher 		{
74211597885SJeff Kirsher 			printk("%s: Acknowledge timed out.\n",dev->name);
74311597885SJeff Kirsher 			sun3_disint();
74411597885SJeff Kirsher 			break;
74511597885SJeff Kirsher 		}
74611597885SJeff Kirsher 	}
74711597885SJeff Kirsher 
74811597885SJeff Kirsher 	if(debuglevel > 1)
74911597885SJeff Kirsher 		printk("i");
75011597885SJeff Kirsher 	return IRQ_HANDLED;
75111597885SJeff Kirsher }
75211597885SJeff Kirsher 
75311597885SJeff Kirsher /*******************************************************
75411597885SJeff Kirsher  * receive-interrupt
75511597885SJeff Kirsher  */
75611597885SJeff Kirsher 
sun3_82586_rcv_int(struct net_device * dev)75711597885SJeff Kirsher static void sun3_82586_rcv_int(struct net_device *dev)
75811597885SJeff Kirsher {
75911597885SJeff Kirsher 	int status,cnt=0;
76011597885SJeff Kirsher 	unsigned short totlen;
76111597885SJeff Kirsher 	struct sk_buff *skb;
76211597885SJeff Kirsher 	struct rbd_struct *rbd;
76311597885SJeff Kirsher 	struct priv *p = netdev_priv(dev);
76411597885SJeff Kirsher 
76511597885SJeff Kirsher 	if(debuglevel > 0)
76611597885SJeff Kirsher 		printk("R");
76711597885SJeff Kirsher 
76811597885SJeff Kirsher 	for(;(status = p->rfd_top->stat_high) & RFD_COMPL;)
76911597885SJeff Kirsher 	{
77011597885SJeff Kirsher 			rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
77111597885SJeff Kirsher 
77211597885SJeff Kirsher 			if(status & RFD_OK) /* frame received without error? */
77311597885SJeff Kirsher 			{
77411597885SJeff Kirsher 				if( (totlen = swab16(rbd->status)) & RBD_LAST) /* the first and the last buffer? */
77511597885SJeff Kirsher 				{
77611597885SJeff Kirsher 					totlen &= RBD_MASK; /* length of this frame */
77711597885SJeff Kirsher 					rbd->status = 0;
778c056b734SPradeep A Dalvi 					skb = netdev_alloc_skb(dev, totlen + 2);
77911597885SJeff Kirsher 					if(skb != NULL)
78011597885SJeff Kirsher 					{
78111597885SJeff Kirsher 						skb_reserve(skb,2);
78211597885SJeff Kirsher 						skb_put(skb,totlen);
78311597885SJeff Kirsher 						skb_copy_to_linear_data(skb,(char *) p->base+swab32((unsigned long) rbd->buffer),totlen);
78411597885SJeff Kirsher 						skb->protocol=eth_type_trans(skb,dev);
78511597885SJeff Kirsher 						netif_rx(skb);
78611597885SJeff Kirsher 						dev->stats.rx_packets++;
78711597885SJeff Kirsher 					}
78811597885SJeff Kirsher 					else
78911597885SJeff Kirsher 						dev->stats.rx_dropped++;
79011597885SJeff Kirsher 				}
79111597885SJeff Kirsher 				else
79211597885SJeff Kirsher 				{
79311597885SJeff Kirsher 					int rstat;
79411597885SJeff Kirsher 						 /* free all RBD's until RBD_LAST is set */
79511597885SJeff Kirsher 					totlen = 0;
79611597885SJeff Kirsher 					while(!((rstat=swab16(rbd->status)) & RBD_LAST))
79711597885SJeff Kirsher 					{
79811597885SJeff Kirsher 						totlen += rstat & RBD_MASK;
79911597885SJeff Kirsher 						if(!rstat)
80011597885SJeff Kirsher 						{
80111597885SJeff Kirsher 							printk("%s: Whoops .. no end mark in RBD list\n",dev->name);
80211597885SJeff Kirsher 							break;
80311597885SJeff Kirsher 						}
80411597885SJeff Kirsher 						rbd->status = 0;
80511597885SJeff Kirsher 						rbd = (struct rbd_struct *) make32(rbd->next);
80611597885SJeff Kirsher 					}
80711597885SJeff Kirsher 					totlen += rstat & RBD_MASK;
80811597885SJeff Kirsher 					rbd->status = 0;
80911597885SJeff Kirsher 					printk("%s: received oversized frame! length: %d\n",dev->name,totlen);
81011597885SJeff Kirsher 					dev->stats.rx_dropped++;
81111597885SJeff Kirsher 			 }
81211597885SJeff Kirsher 		}
81311597885SJeff Kirsher 		else /* frame !(ok), only with 'save-bad-frames' */
81411597885SJeff Kirsher 		{
81511597885SJeff Kirsher 			printk("%s: oops! rfd-error-status: %04x\n",dev->name,status);
81611597885SJeff Kirsher 			dev->stats.rx_errors++;
81711597885SJeff Kirsher 		}
81811597885SJeff Kirsher 		p->rfd_top->stat_high = 0;
81911597885SJeff Kirsher 		p->rfd_top->last = RFD_SUSP; /* maybe exchange by RFD_LAST */
82011597885SJeff Kirsher 		p->rfd_top->rbd_offset = 0xffff;
82111597885SJeff Kirsher 		p->rfd_last->last = 0;				/* delete RFD_SUSP	*/
82211597885SJeff Kirsher 		p->rfd_last = p->rfd_top;
82311597885SJeff Kirsher 		p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */
82411597885SJeff Kirsher 		p->scb->rfa_offset = make16(p->rfd_top);
82511597885SJeff Kirsher 
82611597885SJeff Kirsher 		if(debuglevel > 0)
82711597885SJeff Kirsher 			printk("%d",cnt++);
82811597885SJeff Kirsher 	}
82911597885SJeff Kirsher 
83011597885SJeff Kirsher 	if(automatic_resume)
83111597885SJeff Kirsher 	{
83211597885SJeff Kirsher 		WAIT_4_SCB_CMD();
83311597885SJeff Kirsher 		p->scb->cmd_ruc = RUC_RESUME;
83411597885SJeff Kirsher 		sun3_attn586();
83511597885SJeff Kirsher 		WAIT_4_SCB_CMD_RUC();
83611597885SJeff Kirsher 	}
83711597885SJeff Kirsher 
83811597885SJeff Kirsher #ifdef WAIT_4_BUSY
83911597885SJeff Kirsher 	{
84011597885SJeff Kirsher 		int i;
84111597885SJeff Kirsher 		for(i=0;i<1024;i++)
84211597885SJeff Kirsher 		{
84311597885SJeff Kirsher 			if(p->rfd_top->status)
84411597885SJeff Kirsher 				break;
84511597885SJeff Kirsher 			DELAY_16();
84611597885SJeff Kirsher 			if(i == 1023)
84711597885SJeff Kirsher 				printk("%s: RU hasn't fetched next RFD (not busy/complete)\n",dev->name);
84811597885SJeff Kirsher 		}
84911597885SJeff Kirsher 	}
85011597885SJeff Kirsher #endif
85111597885SJeff Kirsher 
85211597885SJeff Kirsher #if 0
85311597885SJeff Kirsher 	if(!at_least_one)
85411597885SJeff Kirsher 	{
85511597885SJeff Kirsher 		int i;
85611597885SJeff Kirsher 		volatile struct rfd_struct *rfds=p->rfd_top;
85711597885SJeff Kirsher 		volatile struct rbd_struct *rbds;
85811597885SJeff Kirsher 		printk("%s: received a FC intr. without having a frame: %04x %d\n",dev->name,status,old_at_least);
85911597885SJeff Kirsher 		for(i=0;i< (p->num_recv_buffs+4);i++)
86011597885SJeff Kirsher 		{
86111597885SJeff Kirsher 			rbds = (struct rbd_struct *) make32(rfds->rbd_offset);
86211597885SJeff Kirsher 			printk("%04x:%04x ",rfds->status,rbds->status);
86311597885SJeff Kirsher 			rfds = (struct rfd_struct *) make32(rfds->next);
86411597885SJeff Kirsher 		}
86511597885SJeff Kirsher 		printk("\nerrs: %04x %04x stat: %04x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->status);
86611597885SJeff Kirsher 		printk("\nerrs: %04x %04x rus: %02x, cus: %02x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->rus,(int)p->scb->cus);
86711597885SJeff Kirsher 	}
86811597885SJeff Kirsher 	old_at_least = at_least_one;
86911597885SJeff Kirsher #endif
87011597885SJeff Kirsher 
87111597885SJeff Kirsher 	if(debuglevel > 0)
87211597885SJeff Kirsher 		printk("r");
87311597885SJeff Kirsher }
87411597885SJeff Kirsher 
87511597885SJeff Kirsher /**********************************************************
87611597885SJeff Kirsher  * handle 'Receiver went not ready'.
87711597885SJeff Kirsher  */
87811597885SJeff Kirsher 
sun3_82586_rnr_int(struct net_device * dev)87911597885SJeff Kirsher static void sun3_82586_rnr_int(struct net_device *dev)
88011597885SJeff Kirsher {
88111597885SJeff Kirsher 	struct priv *p = netdev_priv(dev);
88211597885SJeff Kirsher 
88311597885SJeff Kirsher 	dev->stats.rx_errors++;
88411597885SJeff Kirsher 
88511597885SJeff Kirsher 	WAIT_4_SCB_CMD();		/* wait for the last cmd, WAIT_4_FULLSTAT?? */
88611597885SJeff Kirsher 	p->scb->cmd_ruc = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */
88711597885SJeff Kirsher 	sun3_attn586();
88811597885SJeff Kirsher 	WAIT_4_SCB_CMD_RUC();		/* wait for accept cmd. */
88911597885SJeff Kirsher 
89011597885SJeff Kirsher 	alloc_rfa(dev,(char *)p->rfd_first);
89111597885SJeff Kirsher /* maybe add a check here, before restarting the RU */
89211597885SJeff Kirsher 	startrecv586(dev); /* restart RU */
89311597885SJeff Kirsher 
89411597885SJeff Kirsher 	printk("%s: Receive-Unit restarted. Status: %04x\n",dev->name,p->scb->rus);
89511597885SJeff Kirsher 
89611597885SJeff Kirsher }
89711597885SJeff Kirsher 
89811597885SJeff Kirsher /**********************************************************
89911597885SJeff Kirsher  * handle xmit - interrupt
90011597885SJeff Kirsher  */
90111597885SJeff Kirsher 
sun3_82586_xmt_int(struct net_device * dev)90211597885SJeff Kirsher static void sun3_82586_xmt_int(struct net_device *dev)
90311597885SJeff Kirsher {
90411597885SJeff Kirsher 	int status;
90511597885SJeff Kirsher 	struct priv *p = netdev_priv(dev);
90611597885SJeff Kirsher 
90711597885SJeff Kirsher 	if(debuglevel > 0)
90811597885SJeff Kirsher 		printk("X");
90911597885SJeff Kirsher 
91011597885SJeff Kirsher 	status = swab16(p->xmit_cmds[p->xmit_last]->cmd_status);
91111597885SJeff Kirsher 	if(!(status & STAT_COMPL))
91211597885SJeff Kirsher 		printk("%s: strange .. xmit-int without a 'COMPLETE'\n",dev->name);
91311597885SJeff Kirsher 
91411597885SJeff Kirsher 	if(status & STAT_OK)
91511597885SJeff Kirsher 	{
91611597885SJeff Kirsher 		dev->stats.tx_packets++;
91711597885SJeff Kirsher 		dev->stats.collisions += (status & TCMD_MAXCOLLMASK);
91811597885SJeff Kirsher 	}
91911597885SJeff Kirsher 	else
92011597885SJeff Kirsher 	{
92111597885SJeff Kirsher 		dev->stats.tx_errors++;
92211597885SJeff Kirsher 		if(status & TCMD_LATECOLL) {
92311597885SJeff Kirsher 			printk("%s: late collision detected.\n",dev->name);
92411597885SJeff Kirsher 			dev->stats.collisions++;
92511597885SJeff Kirsher 		}
92611597885SJeff Kirsher 		else if(status & TCMD_NOCARRIER) {
92711597885SJeff Kirsher 			dev->stats.tx_carrier_errors++;
92811597885SJeff Kirsher 			printk("%s: no carrier detected.\n",dev->name);
92911597885SJeff Kirsher 		}
93011597885SJeff Kirsher 		else if(status & TCMD_LOSTCTS)
93111597885SJeff Kirsher 			printk("%s: loss of CTS detected.\n",dev->name);
93211597885SJeff Kirsher 		else if(status & TCMD_UNDERRUN) {
93311597885SJeff Kirsher 			dev->stats.tx_fifo_errors++;
93411597885SJeff Kirsher 			printk("%s: DMA underrun detected.\n",dev->name);
93511597885SJeff Kirsher 		}
93611597885SJeff Kirsher 		else if(status & TCMD_MAXCOLL) {
93711597885SJeff Kirsher 			printk("%s: Max. collisions exceeded.\n",dev->name);
93811597885SJeff Kirsher 			dev->stats.collisions += 16;
93911597885SJeff Kirsher 		}
94011597885SJeff Kirsher 	}
94111597885SJeff Kirsher 
94211597885SJeff Kirsher #if (NUM_XMIT_BUFFS > 1)
94311597885SJeff Kirsher 	if( (++p->xmit_last) == NUM_XMIT_BUFFS)
94411597885SJeff Kirsher 		p->xmit_last = 0;
94511597885SJeff Kirsher #endif
94611597885SJeff Kirsher 	netif_wake_queue(dev);
94711597885SJeff Kirsher }
94811597885SJeff Kirsher 
94911597885SJeff Kirsher /***********************************************************
95011597885SJeff Kirsher  * (re)start the receiver
95111597885SJeff Kirsher  */
95211597885SJeff Kirsher 
startrecv586(struct net_device * dev)95311597885SJeff Kirsher static void startrecv586(struct net_device *dev)
95411597885SJeff Kirsher {
95511597885SJeff Kirsher 	struct priv *p = netdev_priv(dev);
95611597885SJeff Kirsher 
95711597885SJeff Kirsher 	WAIT_4_SCB_CMD();
95811597885SJeff Kirsher 	WAIT_4_SCB_CMD_RUC();
95911597885SJeff Kirsher 	p->scb->rfa_offset = make16(p->rfd_first);
96011597885SJeff Kirsher 	p->scb->cmd_ruc = RUC_START;
96111597885SJeff Kirsher 	sun3_attn586();		/* start cmd. */
96211597885SJeff Kirsher 	WAIT_4_SCB_CMD_RUC();	/* wait for accept cmd. (no timeout!!) */
96311597885SJeff Kirsher }
96411597885SJeff Kirsher 
sun3_82586_timeout(struct net_device * dev,unsigned int txqueue)9650290bd29SMichael S. Tsirkin static void sun3_82586_timeout(struct net_device *dev, unsigned int txqueue)
96611597885SJeff Kirsher {
96711597885SJeff Kirsher 	struct priv *p = netdev_priv(dev);
96811597885SJeff Kirsher #ifndef NO_NOPCOMMANDS
96911597885SJeff Kirsher 	if(p->scb->cus & CU_ACTIVE) /* COMMAND-UNIT active? */
97011597885SJeff Kirsher 	{
97111597885SJeff Kirsher 		netif_wake_queue(dev);
97211597885SJeff Kirsher #ifdef DEBUG
97311597885SJeff Kirsher 		printk("%s: strange ... timeout with CU active?!?\n",dev->name);
97411597885SJeff Kirsher 		printk("%s: X0: %04x N0: %04x N1: %04x %d\n",dev->name,(int)swab16(p->xmit_cmds[0]->cmd_status),(int)swab16(p->nop_cmds[0]->cmd_status),(int)swab16(p->nop_cmds[1]->cmd_status),(int)p->nop_point);
97511597885SJeff Kirsher #endif
97611597885SJeff Kirsher 		p->scb->cmd_cuc = CUC_ABORT;
97711597885SJeff Kirsher 		sun3_attn586();
97811597885SJeff Kirsher 		WAIT_4_SCB_CMD();
97911597885SJeff Kirsher 		p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
98011597885SJeff Kirsher 		p->scb->cmd_cuc = CUC_START;
98111597885SJeff Kirsher 		sun3_attn586();
98211597885SJeff Kirsher 		WAIT_4_SCB_CMD();
983860e9538SFlorian Westphal 		netif_trans_update(dev); /* prevent tx timeout */
98411597885SJeff Kirsher 		return 0;
98511597885SJeff Kirsher 	}
98611597885SJeff Kirsher #endif
98711597885SJeff Kirsher 	{
98811597885SJeff Kirsher #ifdef DEBUG
98911597885SJeff Kirsher 		printk("%s: xmitter timed out, try to restart! stat: %02x\n",dev->name,p->scb->cus);
9904bea747fSKees Cook 		printk("%s: command-stats: %04x\n", dev->name, swab16(p->xmit_cmds[0]->cmd_status));
99111597885SJeff Kirsher 		printk("%s: check, whether you set the right interrupt number!\n",dev->name);
99211597885SJeff Kirsher #endif
99311597885SJeff Kirsher 		sun3_82586_close(dev);
99411597885SJeff Kirsher 		sun3_82586_open(dev);
99511597885SJeff Kirsher 	}
996860e9538SFlorian Westphal 	netif_trans_update(dev); /* prevent tx timeout */
99711597885SJeff Kirsher }
99811597885SJeff Kirsher 
99911597885SJeff Kirsher /******************************************************
100011597885SJeff Kirsher  * send frame
100111597885SJeff Kirsher  */
100211597885SJeff Kirsher 
1003648c361aSYueHaibing static netdev_tx_t
sun3_82586_send_packet(struct sk_buff * skb,struct net_device * dev)1004648c361aSYueHaibing sun3_82586_send_packet(struct sk_buff *skb, struct net_device *dev)
100511597885SJeff Kirsher {
100611597885SJeff Kirsher 	int len,i;
100711597885SJeff Kirsher #ifndef NO_NOPCOMMANDS
100811597885SJeff Kirsher 	int next_nop;
100911597885SJeff Kirsher #endif
101011597885SJeff Kirsher 	struct priv *p = netdev_priv(dev);
101111597885SJeff Kirsher 
101211597885SJeff Kirsher 	if(skb->len > XMIT_BUFF_SIZE)
101311597885SJeff Kirsher 	{
101411597885SJeff Kirsher 		printk("%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n",dev->name,XMIT_BUFF_SIZE,skb->len);
1015*2cb3f56eSWang Hai 		dev_kfree_skb(skb);
101611597885SJeff Kirsher 		return NETDEV_TX_OK;
101711597885SJeff Kirsher 	}
101811597885SJeff Kirsher 
101911597885SJeff Kirsher 	netif_stop_queue(dev);
102011597885SJeff Kirsher 
102111597885SJeff Kirsher #if(NUM_XMIT_BUFFS > 1)
102211597885SJeff Kirsher 	if(test_and_set_bit(0,(void *) &p->lock)) {
102311597885SJeff Kirsher 		printk("%s: Queue was locked\n",dev->name);
102411597885SJeff Kirsher 		return NETDEV_TX_BUSY;
102511597885SJeff Kirsher 	}
102611597885SJeff Kirsher 	else
102711597885SJeff Kirsher #endif
102811597885SJeff Kirsher 	{
102911597885SJeff Kirsher 		len = skb->len;
103011597885SJeff Kirsher 		if (len < ETH_ZLEN) {
103111597885SJeff Kirsher 			memset((void *)p->xmit_cbuffs[p->xmit_count], 0,
103211597885SJeff Kirsher 			       ETH_ZLEN);
103311597885SJeff Kirsher 			len = ETH_ZLEN;
103411597885SJeff Kirsher 		}
103511597885SJeff Kirsher 		skb_copy_from_linear_data(skb, (void *)p->xmit_cbuffs[p->xmit_count], skb->len);
103611597885SJeff Kirsher 
103711597885SJeff Kirsher #if (NUM_XMIT_BUFFS == 1)
103811597885SJeff Kirsher #	ifdef NO_NOPCOMMANDS
103911597885SJeff Kirsher 
104011597885SJeff Kirsher #ifdef DEBUG
104111597885SJeff Kirsher 		if(p->scb->cus & CU_ACTIVE)
104211597885SJeff Kirsher 		{
104311597885SJeff Kirsher 			printk("%s: Hmmm .. CU is still running and we wanna send a new packet.\n",dev->name);
104411597885SJeff Kirsher 			printk("%s: stat: %04x %04x\n",dev->name,p->scb->cus,swab16(p->xmit_cmds[0]->cmd_status));
104511597885SJeff Kirsher 		}
104611597885SJeff Kirsher #endif
104711597885SJeff Kirsher 
104811597885SJeff Kirsher 		p->xmit_buffs[0]->size = swab16(TBD_LAST | len);
104911597885SJeff Kirsher 		for(i=0;i<16;i++)
105011597885SJeff Kirsher 		{
105111597885SJeff Kirsher 			p->xmit_cmds[0]->cmd_status = 0;
105211597885SJeff Kirsher 			WAIT_4_SCB_CMD();
105311597885SJeff Kirsher 			if( (p->scb->cus & CU_STATUS) == CU_SUSPEND)
105411597885SJeff Kirsher 				p->scb->cmd_cuc = CUC_RESUME;
105511597885SJeff Kirsher 			else
105611597885SJeff Kirsher 			{
105711597885SJeff Kirsher 				p->scb->cbl_offset = make16(p->xmit_cmds[0]);
105811597885SJeff Kirsher 				p->scb->cmd_cuc = CUC_START;
105911597885SJeff Kirsher 			}
106011597885SJeff Kirsher 
106111597885SJeff Kirsher 			sun3_attn586();
106211597885SJeff Kirsher 			if(!i)
106311597885SJeff Kirsher 				dev_kfree_skb(skb);
106411597885SJeff Kirsher 			WAIT_4_SCB_CMD();
106511597885SJeff Kirsher 			if( (p->scb->cus & CU_ACTIVE)) /* test it, because CU sometimes doesn't start immediately */
106611597885SJeff Kirsher 				break;
106711597885SJeff Kirsher 			if(p->xmit_cmds[0]->cmd_status)
106811597885SJeff Kirsher 				break;
106911597885SJeff Kirsher 			if(i==15)
107011597885SJeff Kirsher 				printk("%s: Can't start transmit-command.\n",dev->name);
107111597885SJeff Kirsher 		}
107211597885SJeff Kirsher #	else
107311597885SJeff Kirsher 		next_nop = (p->nop_point + 1) & 0x1;
107411597885SJeff Kirsher 		p->xmit_buffs[0]->size = swab16(TBD_LAST | len);
107511597885SJeff Kirsher 
107611597885SJeff Kirsher 		p->xmit_cmds[0]->cmd_link	 = p->nop_cmds[next_nop]->cmd_link
107711597885SJeff Kirsher 			= make16((p->nop_cmds[next_nop]));
107811597885SJeff Kirsher 		p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
107911597885SJeff Kirsher 
108011597885SJeff Kirsher 		p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
108111597885SJeff Kirsher 		p->nop_point = next_nop;
108211597885SJeff Kirsher 		dev_kfree_skb(skb);
108311597885SJeff Kirsher #	endif
108411597885SJeff Kirsher #else
108511597885SJeff Kirsher 		p->xmit_buffs[p->xmit_count]->size = swab16(TBD_LAST | len);
108611597885SJeff Kirsher 		if( (next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS )
108711597885SJeff Kirsher 			next_nop = 0;
108811597885SJeff Kirsher 
108911597885SJeff Kirsher 		p->xmit_cmds[p->xmit_count]->cmd_status	= 0;
109011597885SJeff Kirsher 		/* linkpointer of xmit-command already points to next nop cmd */
109111597885SJeff Kirsher 		p->nop_cmds[next_nop]->cmd_link = make16((p->nop_cmds[next_nop]));
109211597885SJeff Kirsher 		p->nop_cmds[next_nop]->cmd_status = 0;
109311597885SJeff Kirsher 
109411597885SJeff Kirsher 		p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count]));
109511597885SJeff Kirsher 		p->xmit_count = next_nop;
109611597885SJeff Kirsher 
109711597885SJeff Kirsher 		{
109811597885SJeff Kirsher 			unsigned long flags;
109911597885SJeff Kirsher 			local_irq_save(flags);
110011597885SJeff Kirsher 			if(p->xmit_count != p->xmit_last)
110111597885SJeff Kirsher 				netif_wake_queue(dev);
110211597885SJeff Kirsher 			p->lock = 0;
110311597885SJeff Kirsher 			local_irq_restore(flags);
110411597885SJeff Kirsher 		}
110511597885SJeff Kirsher 		dev_kfree_skb(skb);
110611597885SJeff Kirsher #endif
110711597885SJeff Kirsher 	}
110811597885SJeff Kirsher 	return NETDEV_TX_OK;
110911597885SJeff Kirsher }
111011597885SJeff Kirsher 
111111597885SJeff Kirsher /*******************************************
111211597885SJeff Kirsher  * Someone wanna have the statistics
111311597885SJeff Kirsher  */
111411597885SJeff Kirsher 
sun3_82586_get_stats(struct net_device * dev)111511597885SJeff Kirsher static struct net_device_stats *sun3_82586_get_stats(struct net_device *dev)
111611597885SJeff Kirsher {
111711597885SJeff Kirsher 	struct priv *p = netdev_priv(dev);
111811597885SJeff Kirsher 	unsigned short crc,aln,rsc,ovrn;
111911597885SJeff Kirsher 
112011597885SJeff Kirsher 	crc = swab16(p->scb->crc_errs); /* get error-statistic from the ni82586 */
112111597885SJeff Kirsher 	p->scb->crc_errs = 0;
112211597885SJeff Kirsher 	aln = swab16(p->scb->aln_errs);
112311597885SJeff Kirsher 	p->scb->aln_errs = 0;
112411597885SJeff Kirsher 	rsc = swab16(p->scb->rsc_errs);
112511597885SJeff Kirsher 	p->scb->rsc_errs = 0;
112611597885SJeff Kirsher 	ovrn = swab16(p->scb->ovrn_errs);
112711597885SJeff Kirsher 	p->scb->ovrn_errs = 0;
112811597885SJeff Kirsher 
112911597885SJeff Kirsher 	dev->stats.rx_crc_errors += crc;
113011597885SJeff Kirsher 	dev->stats.rx_fifo_errors += ovrn;
113111597885SJeff Kirsher 	dev->stats.rx_frame_errors += aln;
113211597885SJeff Kirsher 	dev->stats.rx_dropped += rsc;
113311597885SJeff Kirsher 
113411597885SJeff Kirsher 	return &dev->stats;
113511597885SJeff Kirsher }
113611597885SJeff Kirsher 
113711597885SJeff Kirsher /********************************************************
113811597885SJeff Kirsher  * Set MC list ..
113911597885SJeff Kirsher  */
114011597885SJeff Kirsher 
set_multicast_list(struct net_device * dev)114111597885SJeff Kirsher static void set_multicast_list(struct net_device *dev)
114211597885SJeff Kirsher {
114311597885SJeff Kirsher 	netif_stop_queue(dev);
114411597885SJeff Kirsher 	sun3_disint();
114511597885SJeff Kirsher 	alloc586(dev);
114611597885SJeff Kirsher 	init586(dev);
114711597885SJeff Kirsher 	startrecv586(dev);
114811597885SJeff Kirsher 	sun3_enaint();
114911597885SJeff Kirsher 	netif_wake_queue(dev);
115011597885SJeff Kirsher }
115111597885SJeff Kirsher 
115211597885SJeff Kirsher #if 0
115311597885SJeff Kirsher /*
115411597885SJeff Kirsher  * DUMP .. we expect a not running CMD unit and enough space
115511597885SJeff Kirsher  */
115611597885SJeff Kirsher void sun3_82586_dump(struct net_device *dev,void *ptr)
115711597885SJeff Kirsher {
115811597885SJeff Kirsher 	struct priv *p = netdev_priv(dev);
115911597885SJeff Kirsher 	struct dump_cmd_struct *dump_cmd = (struct dump_cmd_struct *) ptr;
116011597885SJeff Kirsher 	int i;
116111597885SJeff Kirsher 
116211597885SJeff Kirsher 	p->scb->cmd_cuc = CUC_ABORT;
116311597885SJeff Kirsher 	sun3_attn586();
116411597885SJeff Kirsher 	WAIT_4_SCB_CMD();
116511597885SJeff Kirsher 	WAIT_4_SCB_CMD_RUC();
116611597885SJeff Kirsher 
116711597885SJeff Kirsher 	dump_cmd->cmd_status = 0;
116811597885SJeff Kirsher 	dump_cmd->cmd_cmd = CMD_DUMP | CMD_LAST;
116911597885SJeff Kirsher 	dump_cmd->dump_offset = make16((dump_cmd + 1));
117011597885SJeff Kirsher 	dump_cmd->cmd_link = 0xffff;
117111597885SJeff Kirsher 
117211597885SJeff Kirsher 	p->scb->cbl_offset = make16(dump_cmd);
117311597885SJeff Kirsher 	p->scb->cmd_cuc = CUC_START;
117411597885SJeff Kirsher 	sun3_attn586();
117511597885SJeff Kirsher 	WAIT_4_STAT_COMPL(dump_cmd);
117611597885SJeff Kirsher 
117711597885SJeff Kirsher 	if( (dump_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
117811597885SJeff Kirsher 				printk("%s: Can't get dump information.\n",dev->name);
117911597885SJeff Kirsher 
118011597885SJeff Kirsher 	for(i=0;i<170;i++) {
118111597885SJeff Kirsher 		printk("%02x ",(int) ((unsigned char *) (dump_cmd + 1))[i]);
118211597885SJeff Kirsher 		if(i % 24 == 23)
118311597885SJeff Kirsher 			printk("\n");
118411597885SJeff Kirsher 	}
118511597885SJeff Kirsher 	printk("\n");
118611597885SJeff Kirsher }
118711597885SJeff Kirsher #endif
1188