17c478bd9Sstevel@tonic-gate /**************************************************************************
27c478bd9Sstevel@tonic-gate ETHERBOOT -  BOOTP/TFTP Bootstrap Program
37c478bd9Sstevel@tonic-gate 
47c478bd9Sstevel@tonic-gate Author: Martin Renters
57c478bd9Sstevel@tonic-gate   Date: May/94
67c478bd9Sstevel@tonic-gate 
77c478bd9Sstevel@tonic-gate  This code is based heavily on David Greenman's if_ed.c driver
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate  Copyright (C) 1993-1994, David Greenman, Martin Renters.
107c478bd9Sstevel@tonic-gate   This software may be used, modified, copied, distributed, and sold, in
117c478bd9Sstevel@tonic-gate   both source and binary form provided that the above copyright and these
127c478bd9Sstevel@tonic-gate   terms are retained. Under no circumstances are the authors responsible for
137c478bd9Sstevel@tonic-gate   the proper functioning of this software, nor do the authors assume any
147c478bd9Sstevel@tonic-gate   responsibility for damages incurred with its use.
157c478bd9Sstevel@tonic-gate 
167c478bd9Sstevel@tonic-gate Multicast support added by Timothy Legge (timlegge@users.sourceforge.net) 09/28/2003
177c478bd9Sstevel@tonic-gate Relocation support added by Ken Yap (ken_yap@users.sourceforge.net) 28/12/02
187c478bd9Sstevel@tonic-gate 3c503 support added by Bill Paul (wpaul@ctr.columbia.edu) on 11/15/94
197c478bd9Sstevel@tonic-gate SMC8416 support added by Bill Paul (wpaul@ctr.columbia.edu) on 12/25/94
207c478bd9Sstevel@tonic-gate 3c503 PIO support added by Jim Hague (jim.hague@acm.org) on 2/17/98
217c478bd9Sstevel@tonic-gate RX overrun by Klaus Espenlaub (espenlaub@informatik.uni-ulm.de) on 3/10/99
227c478bd9Sstevel@tonic-gate   parts taken from the Linux 8390 driver (by Donald Becker and Paul Gortmaker)
237c478bd9Sstevel@tonic-gate SMC8416 PIO support added by Andrew Bettison (andrewb@zip.com.au) on 4/3/02
247c478bd9Sstevel@tonic-gate   based on the Linux 8390 driver (by Donald Becker and Paul Gortmaker)
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate **************************************************************************/
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include "etherboot.h"
297c478bd9Sstevel@tonic-gate #include "nic.h"
307c478bd9Sstevel@tonic-gate #include "ns8390.h"
317c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_NS8390
327c478bd9Sstevel@tonic-gate #include "pci.h"
337c478bd9Sstevel@tonic-gate #else
347c478bd9Sstevel@tonic-gate #include "isa.h"
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate static unsigned char	eth_vendor, eth_flags;
387c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
397c478bd9Sstevel@tonic-gate static unsigned char	eth_laar;
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate static unsigned short	eth_nic_base, eth_asic_base;
427c478bd9Sstevel@tonic-gate static unsigned char	eth_memsize, eth_rx_start, eth_tx_start;
437c478bd9Sstevel@tonic-gate static Address		eth_bmem, eth_rmem;
447c478bd9Sstevel@tonic-gate static unsigned char	eth_drain_receiver;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
477c478bd9Sstevel@tonic-gate static struct wd_board {
487c478bd9Sstevel@tonic-gate 	const char *name;
497c478bd9Sstevel@tonic-gate 	char id;
507c478bd9Sstevel@tonic-gate 	char flags;
517c478bd9Sstevel@tonic-gate 	char memsize;
527c478bd9Sstevel@tonic-gate } wd_boards[] = {
537c478bd9Sstevel@tonic-gate 	{"WD8003S",	TYPE_WD8003S,	0,			MEM_8192},
547c478bd9Sstevel@tonic-gate 	{"WD8003E",	TYPE_WD8003E,	0,			MEM_8192},
557c478bd9Sstevel@tonic-gate 	{"WD8013EBT",	TYPE_WD8013EBT,	FLAG_16BIT,		MEM_16384},
567c478bd9Sstevel@tonic-gate 	{"WD8003W",	TYPE_WD8003W,	0,			MEM_8192},
577c478bd9Sstevel@tonic-gate 	{"WD8003EB",	TYPE_WD8003EB,	0,			MEM_8192},
587c478bd9Sstevel@tonic-gate 	{"WD8013W",	TYPE_WD8013W,	FLAG_16BIT,		MEM_16384},
597c478bd9Sstevel@tonic-gate 	{"WD8003EP/WD8013EP",
607c478bd9Sstevel@tonic-gate 			TYPE_WD8013EP,	0,			MEM_8192},
617c478bd9Sstevel@tonic-gate 	{"WD8013WC",	TYPE_WD8013WC,	FLAG_16BIT,		MEM_16384},
627c478bd9Sstevel@tonic-gate 	{"WD8013EPC",	TYPE_WD8013EPC,	FLAG_16BIT,		MEM_16384},
637c478bd9Sstevel@tonic-gate 	{"SMC8216T",	TYPE_SMC8216T,	FLAG_16BIT | FLAG_790,	MEM_16384},
647c478bd9Sstevel@tonic-gate 	{"SMC8216C",	TYPE_SMC8216C,	FLAG_16BIT | FLAG_790,	MEM_16384},
657c478bd9Sstevel@tonic-gate 	{"SMC8416T",	TYPE_SMC8416T,	FLAG_16BIT | FLAG_790,	MEM_8192},
667c478bd9Sstevel@tonic-gate 	{"SMC8416C/BT",	TYPE_SMC8416C,	FLAG_16BIT | FLAG_790,	MEM_8192},
677c478bd9Sstevel@tonic-gate 	{"SMC8013EBP",	TYPE_SMC8013EBP,FLAG_16BIT,		MEM_16384},
687c478bd9Sstevel@tonic-gate 	{NULL,		0,		0,			0}
697c478bd9Sstevel@tonic-gate };
707c478bd9Sstevel@tonic-gate #endif
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_3C503
737c478bd9Sstevel@tonic-gate static unsigned char	t503_output;	/* AUI or internal xcvr (Thinnet) */
747c478bd9Sstevel@tonic-gate #endif
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_WD)
777c478bd9Sstevel@tonic-gate #define	ASIC_PIO	WD_IAR
787c478bd9Sstevel@tonic-gate #define	eth_probe	wd_probe
797c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_3C503) || defined(INCLUDE_NE) || defined(INCLUDE_NS8390)
807c478bd9Sstevel@tonic-gate Error you must only define one of INCLUDE_WD, INCLUDE_3C503, INCLUDE_NE, INCLUDE_NS8390
817c478bd9Sstevel@tonic-gate #endif
827c478bd9Sstevel@tonic-gate #endif
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_3C503)
857c478bd9Sstevel@tonic-gate #define	eth_probe	t503_probe
867c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_NE) || defined(INCLUDE_NS8390) || defined(INCLUDE_WD)
877c478bd9Sstevel@tonic-gate Error you must only define one of INCLUDE_WD, INCLUDE_3C503, INCLUDE_NE, INCLUDE_NS8390
887c478bd9Sstevel@tonic-gate #endif
897c478bd9Sstevel@tonic-gate #endif
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_NE)
927c478bd9Sstevel@tonic-gate #define	eth_probe	ne_probe
937c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_NS8390) || defined(INCLUDE_3C503) || defined(INCLUDE_WD)
947c478bd9Sstevel@tonic-gate Error you must only define one of INCLUDE_WD, INCLUDE_3C503, INCLUDE_NE, INCLUDE_NS8390
957c478bd9Sstevel@tonic-gate #endif
967c478bd9Sstevel@tonic-gate #endif
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_NS8390)
997c478bd9Sstevel@tonic-gate #define	eth_probe	nepci_probe
1007c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_NE) || defined(INCLUDE_3C503) || defined(INCLUDE_WD)
1017c478bd9Sstevel@tonic-gate Error you must only define one of INCLUDE_WD, INCLUDE_3C503, INCLUDE_NE, INCLUDE_NS8390
1027c478bd9Sstevel@tonic-gate #endif
1037c478bd9Sstevel@tonic-gate #endif
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_3C503)
1067c478bd9Sstevel@tonic-gate #define	ASIC_PIO	_3COM_RFMSB
1077c478bd9Sstevel@tonic-gate #else
1087c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_NE) || defined(INCLUDE_NS8390)
1097c478bd9Sstevel@tonic-gate #define	ASIC_PIO	NE_DATA
1107c478bd9Sstevel@tonic-gate #endif
1117c478bd9Sstevel@tonic-gate #endif
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_NE) || defined(INCLUDE_NS8390) || (defined(INCLUDE_3C503) && !defined(T503_SHMEM)) || (defined(INCLUDE_WD) && defined(WD_790_PIO))
1147c478bd9Sstevel@tonic-gate /**************************************************************************
1157c478bd9Sstevel@tonic-gate ETH_PIO_READ - Read a frame via Programmed I/O
1167c478bd9Sstevel@tonic-gate **************************************************************************/
1177c478bd9Sstevel@tonic-gate static void eth_pio_read(unsigned int src, unsigned char *dst, unsigned int cnt)
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
1207c478bd9Sstevel@tonic-gate 	outb(src & 0xff, eth_asic_base + WD_GP2);
1217c478bd9Sstevel@tonic-gate 	outb(src >> 8, eth_asic_base + WD_GP2);
1227c478bd9Sstevel@tonic-gate #else
1237c478bd9Sstevel@tonic-gate 	outb(D8390_COMMAND_RD2 |
1247c478bd9Sstevel@tonic-gate 		D8390_COMMAND_STA, eth_nic_base + D8390_P0_COMMAND);
1257c478bd9Sstevel@tonic-gate 	outb(cnt, eth_nic_base + D8390_P0_RBCR0);
1267c478bd9Sstevel@tonic-gate 	outb(cnt>>8, eth_nic_base + D8390_P0_RBCR1);
1277c478bd9Sstevel@tonic-gate 	outb(src, eth_nic_base + D8390_P0_RSAR0);
1287c478bd9Sstevel@tonic-gate 	outb(src>>8, eth_nic_base + D8390_P0_RSAR1);
1297c478bd9Sstevel@tonic-gate 	outb(D8390_COMMAND_RD0 |
1307c478bd9Sstevel@tonic-gate 		D8390_COMMAND_STA, eth_nic_base + D8390_P0_COMMAND);
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_3C503
1337c478bd9Sstevel@tonic-gate 	outb(src & 0xff, eth_asic_base + _3COM_DALSB);
1347c478bd9Sstevel@tonic-gate 	outb(src >> 8, eth_asic_base + _3COM_DAMSB);
1357c478bd9Sstevel@tonic-gate 	outb(t503_output | _3COM_CR_START, eth_asic_base + _3COM_CR);
1367c478bd9Sstevel@tonic-gate #endif
1377c478bd9Sstevel@tonic-gate #endif
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_16BIT)
1407c478bd9Sstevel@tonic-gate 		cnt = (cnt + 1) >> 1;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	while(cnt--) {
1437c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_3C503
1447c478bd9Sstevel@tonic-gate 		while((inb(eth_asic_base + _3COM_STREG) & _3COM_STREG_DPRDY) == 0)
1457c478bd9Sstevel@tonic-gate 			;
1467c478bd9Sstevel@tonic-gate #endif
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 		if (eth_flags & FLAG_16BIT) {
1497c478bd9Sstevel@tonic-gate 			*((unsigned short *)dst) = inw(eth_asic_base + ASIC_PIO);
1507c478bd9Sstevel@tonic-gate 			dst += 2;
1517c478bd9Sstevel@tonic-gate 		}
1527c478bd9Sstevel@tonic-gate 		else
1537c478bd9Sstevel@tonic-gate 			*(dst++) = inb(eth_asic_base + ASIC_PIO);
1547c478bd9Sstevel@tonic-gate 	}
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_3C503
1577c478bd9Sstevel@tonic-gate 	outb(t503_output, eth_asic_base + _3COM_CR);
1587c478bd9Sstevel@tonic-gate #endif
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /**************************************************************************
1627c478bd9Sstevel@tonic-gate ETH_PIO_WRITE - Write a frame via Programmed I/O
1637c478bd9Sstevel@tonic-gate **************************************************************************/
eth_pio_write(const unsigned char * src,unsigned int dst,unsigned int cnt)1647c478bd9Sstevel@tonic-gate static void eth_pio_write(const unsigned char *src, unsigned int dst, unsigned int cnt)
1657c478bd9Sstevel@tonic-gate {
1667c478bd9Sstevel@tonic-gate #ifdef	COMPEX_RL2000_FIX
1677c478bd9Sstevel@tonic-gate 	unsigned int x;
1687c478bd9Sstevel@tonic-gate #endif	/* COMPEX_RL2000_FIX */
1697c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
1707c478bd9Sstevel@tonic-gate 	outb(dst & 0xff, eth_asic_base + WD_GP2);
1717c478bd9Sstevel@tonic-gate 	outb(dst >> 8, eth_asic_base + WD_GP2);
1727c478bd9Sstevel@tonic-gate #else
1737c478bd9Sstevel@tonic-gate 	outb(D8390_COMMAND_RD2 |
1747c478bd9Sstevel@tonic-gate 		D8390_COMMAND_STA, eth_nic_base + D8390_P0_COMMAND);
1757c478bd9Sstevel@tonic-gate 	outb(D8390_ISR_RDC, eth_nic_base + D8390_P0_ISR);
1767c478bd9Sstevel@tonic-gate 	outb(cnt, eth_nic_base + D8390_P0_RBCR0);
1777c478bd9Sstevel@tonic-gate 	outb(cnt>>8, eth_nic_base + D8390_P0_RBCR1);
1787c478bd9Sstevel@tonic-gate 	outb(dst, eth_nic_base + D8390_P0_RSAR0);
1797c478bd9Sstevel@tonic-gate 	outb(dst>>8, eth_nic_base + D8390_P0_RSAR1);
1807c478bd9Sstevel@tonic-gate 	outb(D8390_COMMAND_RD1 |
1817c478bd9Sstevel@tonic-gate 		D8390_COMMAND_STA, eth_nic_base + D8390_P0_COMMAND);
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_3C503
1847c478bd9Sstevel@tonic-gate 	outb(dst & 0xff, eth_asic_base + _3COM_DALSB);
1857c478bd9Sstevel@tonic-gate 	outb(dst >> 8, eth_asic_base + _3COM_DAMSB);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	outb(t503_output | _3COM_CR_DDIR | _3COM_CR_START, eth_asic_base + _3COM_CR);
1887c478bd9Sstevel@tonic-gate #endif
1897c478bd9Sstevel@tonic-gate #endif
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_16BIT)
1927c478bd9Sstevel@tonic-gate 		cnt = (cnt + 1) >> 1;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	while(cnt--)
1957c478bd9Sstevel@tonic-gate 	{
1967c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_3C503
1977c478bd9Sstevel@tonic-gate 		while((inb(eth_asic_base + _3COM_STREG) & _3COM_STREG_DPRDY) == 0)
1987c478bd9Sstevel@tonic-gate 			;
1997c478bd9Sstevel@tonic-gate #endif
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 		if (eth_flags & FLAG_16BIT) {
2027c478bd9Sstevel@tonic-gate 			outw(*((unsigned short *)src), eth_asic_base + ASIC_PIO);
2037c478bd9Sstevel@tonic-gate 			src += 2;
2047c478bd9Sstevel@tonic-gate 		}
2057c478bd9Sstevel@tonic-gate 		else
2067c478bd9Sstevel@tonic-gate 			outb(*(src++), eth_asic_base + ASIC_PIO);
2077c478bd9Sstevel@tonic-gate 	}
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_3C503
2107c478bd9Sstevel@tonic-gate 	outb(t503_output, eth_asic_base + _3COM_CR);
2117c478bd9Sstevel@tonic-gate #else
2127c478bd9Sstevel@tonic-gate #ifdef	COMPEX_RL2000_FIX
2137c478bd9Sstevel@tonic-gate 	for (x = 0;
2147c478bd9Sstevel@tonic-gate 		x < COMPEX_RL2000_TRIES &&
2157c478bd9Sstevel@tonic-gate 		(inb(eth_nic_base + D8390_P0_ISR) & D8390_ISR_RDC)
2167c478bd9Sstevel@tonic-gate 		!= D8390_ISR_RDC;
2177c478bd9Sstevel@tonic-gate 		++x);
2187c478bd9Sstevel@tonic-gate 	if (x >= COMPEX_RL2000_TRIES)
2197c478bd9Sstevel@tonic-gate 		printf("Warning: Compex RL2000 aborted wait!\n");
2207c478bd9Sstevel@tonic-gate #endif	/* COMPEX_RL2000_FIX */
2217c478bd9Sstevel@tonic-gate #ifndef	INCLUDE_WD
2227c478bd9Sstevel@tonic-gate 	while((inb(eth_nic_base + D8390_P0_ISR) & D8390_ISR_RDC)
2237c478bd9Sstevel@tonic-gate 		!= D8390_ISR_RDC);
2247c478bd9Sstevel@tonic-gate #endif
2257c478bd9Sstevel@tonic-gate #endif
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate #else
2287c478bd9Sstevel@tonic-gate /**************************************************************************
2297c478bd9Sstevel@tonic-gate ETH_PIO_READ - Dummy routine when NE2000 not compiled in
2307c478bd9Sstevel@tonic-gate **************************************************************************/
2317c478bd9Sstevel@tonic-gate static void eth_pio_read(unsigned int src __unused, unsigned char *dst  __unused, unsigned int cnt __unused) {}
2327c478bd9Sstevel@tonic-gate #endif
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /**************************************************************************
2367c478bd9Sstevel@tonic-gate enable_multycast - Enable Multicast
2377c478bd9Sstevel@tonic-gate **************************************************************************/
enable_multicast(unsigned short eth_nic_base)2387c478bd9Sstevel@tonic-gate static void enable_multicast(unsigned short eth_nic_base)
2397c478bd9Sstevel@tonic-gate {
2407c478bd9Sstevel@tonic-gate 	unsigned char mcfilter[8];
2417c478bd9Sstevel@tonic-gate 	int i;
2427c478bd9Sstevel@tonic-gate 	memset(mcfilter, 0xFF, 8);
2437c478bd9Sstevel@tonic-gate 	outb(4, eth_nic_base+D8390_P0_RCR);
2447c478bd9Sstevel@tonic-gate 	outb(D8390_COMMAND_RD2 + D8390_COMMAND_PS1, eth_nic_base + D8390_P0_COMMAND);
2457c478bd9Sstevel@tonic-gate 	for(i=0;i<8;i++)
2467c478bd9Sstevel@tonic-gate 	{
2477c478bd9Sstevel@tonic-gate 		outb(mcfilter[i], eth_nic_base + 8 + i);
2487c478bd9Sstevel@tonic-gate 		if(inb(eth_nic_base + 8 + i)!=mcfilter[i])
2497c478bd9Sstevel@tonic-gate 			printf("Error SMC 83C690 Multicast filter read/write mishap %d\n",i);
2507c478bd9Sstevel@tonic-gate 	}
2517c478bd9Sstevel@tonic-gate 	outb(D8390_COMMAND_RD2 + D8390_COMMAND_PS0, eth_nic_base + D8390_P0_COMMAND);
2527c478bd9Sstevel@tonic-gate 	outb(4 | 0x08, eth_nic_base+D8390_P0_RCR);
2537c478bd9Sstevel@tonic-gate }
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate /**************************************************************************
2567c478bd9Sstevel@tonic-gate NS8390_RESET - Reset adapter
2577c478bd9Sstevel@tonic-gate **************************************************************************/
ns8390_reset(struct nic * nic)2587c478bd9Sstevel@tonic-gate static void ns8390_reset(struct nic *nic)
2597c478bd9Sstevel@tonic-gate {
2607c478bd9Sstevel@tonic-gate 	int i;
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate 	eth_drain_receiver = 0;
2637c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
2647c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790)
2657c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS0 | D8390_COMMAND_STP, eth_nic_base+D8390_P0_COMMAND);
2667c478bd9Sstevel@tonic-gate 	else
2677c478bd9Sstevel@tonic-gate #endif
2687c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS0 | D8390_COMMAND_RD2 |
2697c478bd9Sstevel@tonic-gate 			D8390_COMMAND_STP, eth_nic_base+D8390_P0_COMMAND);
2707c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_16BIT)
2717c478bd9Sstevel@tonic-gate 		outb(0x49, eth_nic_base+D8390_P0_DCR);
2727c478bd9Sstevel@tonic-gate 	else
2737c478bd9Sstevel@tonic-gate 		outb(0x48, eth_nic_base+D8390_P0_DCR);
2747c478bd9Sstevel@tonic-gate 	outb(0, eth_nic_base+D8390_P0_RBCR0);
2757c478bd9Sstevel@tonic-gate 	outb(0, eth_nic_base+D8390_P0_RBCR1);
2767c478bd9Sstevel@tonic-gate 	outb(0x20, eth_nic_base+D8390_P0_RCR);	/* monitor mode */
2777c478bd9Sstevel@tonic-gate 	outb(2, eth_nic_base+D8390_P0_TCR);
2787c478bd9Sstevel@tonic-gate 	outb(eth_tx_start, eth_nic_base+D8390_P0_TPSR);
2797c478bd9Sstevel@tonic-gate 	outb(eth_rx_start, eth_nic_base+D8390_P0_PSTART);
2807c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
2817c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790) {
2827c478bd9Sstevel@tonic-gate #ifdef	WD_790_PIO
2837c478bd9Sstevel@tonic-gate 		outb(0x10, eth_asic_base + 0x06); /* disable interrupts, enable PIO */
2847c478bd9Sstevel@tonic-gate 		outb(0x01, eth_nic_base + 0x09); /* enable ring read auto-wrap */
2857c478bd9Sstevel@tonic-gate #else
2867c478bd9Sstevel@tonic-gate 		outb(0, eth_nic_base + 0x09);
2877c478bd9Sstevel@tonic-gate #endif
2887c478bd9Sstevel@tonic-gate 	}
2897c478bd9Sstevel@tonic-gate #endif
2907c478bd9Sstevel@tonic-gate 	outb(eth_memsize, eth_nic_base+D8390_P0_PSTOP);
2917c478bd9Sstevel@tonic-gate 	outb(eth_memsize - 1, eth_nic_base+D8390_P0_BOUND);
2927c478bd9Sstevel@tonic-gate 	outb(0xFF, eth_nic_base+D8390_P0_ISR);
2937c478bd9Sstevel@tonic-gate 	outb(0, eth_nic_base+D8390_P0_IMR);
2947c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
2957c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790)
2967c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS1 |
2977c478bd9Sstevel@tonic-gate 			D8390_COMMAND_STP, eth_nic_base+D8390_P0_COMMAND);
2987c478bd9Sstevel@tonic-gate 	else
2997c478bd9Sstevel@tonic-gate #endif
3007c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS1 |
3017c478bd9Sstevel@tonic-gate 			D8390_COMMAND_RD2 | D8390_COMMAND_STP, eth_nic_base+D8390_P0_COMMAND);
3027c478bd9Sstevel@tonic-gate 	for (i=0; i<ETH_ALEN; i++)
3037c478bd9Sstevel@tonic-gate 		outb(nic->node_addr[i], eth_nic_base+D8390_P1_PAR0+i);
3047c478bd9Sstevel@tonic-gate 	for (i=0; i<ETH_ALEN; i++)
3057c478bd9Sstevel@tonic-gate 		outb(0xFF, eth_nic_base+D8390_P1_MAR0+i);
3067c478bd9Sstevel@tonic-gate 	outb(eth_rx_start, eth_nic_base+D8390_P1_CURR);
3077c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
3087c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790)
3097c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS0 |
3107c478bd9Sstevel@tonic-gate 			D8390_COMMAND_STA, eth_nic_base+D8390_P0_COMMAND);
3117c478bd9Sstevel@tonic-gate 	else
3127c478bd9Sstevel@tonic-gate #endif
3137c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS0 |
3147c478bd9Sstevel@tonic-gate 			D8390_COMMAND_RD2 | D8390_COMMAND_STA, eth_nic_base+D8390_P0_COMMAND);
3157c478bd9Sstevel@tonic-gate 	outb(0xFF, eth_nic_base+D8390_P0_ISR);
3167c478bd9Sstevel@tonic-gate 	outb(0, eth_nic_base+D8390_P0_TCR);	/* transmitter on */
3177c478bd9Sstevel@tonic-gate 	outb(4, eth_nic_base+D8390_P0_RCR);	/* allow rx broadcast frames */
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	enable_multicast(eth_nic_base);
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_3C503
3227c478bd9Sstevel@tonic-gate         /*
3237c478bd9Sstevel@tonic-gate          * No way to tell whether or not we're supposed to use
3247c478bd9Sstevel@tonic-gate          * the 3Com's transceiver unless the user tells us.
3257c478bd9Sstevel@tonic-gate          * 'flags' should have some compile time default value
3267c478bd9Sstevel@tonic-gate          * which can be changed from the command menu.
3277c478bd9Sstevel@tonic-gate          */
3287c478bd9Sstevel@tonic-gate 	t503_output = (nic->flags) ? 0 : _3COM_CR_XSEL;
3297c478bd9Sstevel@tonic-gate 	outb(t503_output, eth_asic_base + _3COM_CR);
3307c478bd9Sstevel@tonic-gate #endif
3317c478bd9Sstevel@tonic-gate }
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate static int ns8390_poll(struct nic *nic, int retrieve);
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate #ifndef	INCLUDE_3C503
3367c478bd9Sstevel@tonic-gate /**************************************************************************
3377c478bd9Sstevel@tonic-gate ETH_RX_OVERRUN - Bring adapter back to work after an RX overrun
3387c478bd9Sstevel@tonic-gate **************************************************************************/
eth_rx_overrun(struct nic * nic)3397c478bd9Sstevel@tonic-gate static void eth_rx_overrun(struct nic *nic)
3407c478bd9Sstevel@tonic-gate {
3417c478bd9Sstevel@tonic-gate 	int start_time;
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
3447c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790)
3457c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS0 | D8390_COMMAND_STP, eth_nic_base+D8390_P0_COMMAND);
3467c478bd9Sstevel@tonic-gate 	else
3477c478bd9Sstevel@tonic-gate #endif
3487c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS0 | D8390_COMMAND_RD2 |
3497c478bd9Sstevel@tonic-gate 			D8390_COMMAND_STP, eth_nic_base+D8390_P0_COMMAND);
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	/* wait for at least 1.6ms - we wait one timer tick */
3527c478bd9Sstevel@tonic-gate 	start_time = currticks();
3537c478bd9Sstevel@tonic-gate 	while (currticks() - start_time <= 1)
3547c478bd9Sstevel@tonic-gate 		/* Nothing */;
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	outb(0, eth_nic_base+D8390_P0_RBCR0);	/* reset byte counter */
3577c478bd9Sstevel@tonic-gate 	outb(0, eth_nic_base+D8390_P0_RBCR1);
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	/*
3607c478bd9Sstevel@tonic-gate 	 * Linux driver checks for interrupted TX here. This is not necessary,
3617c478bd9Sstevel@tonic-gate 	 * because the transmit routine waits until the frame is sent.
3627c478bd9Sstevel@tonic-gate 	 */
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 	/* enter loopback mode and restart NIC */
3657c478bd9Sstevel@tonic-gate 	outb(2, eth_nic_base+D8390_P0_TCR);
3667c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
3677c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790)
3687c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS0 | D8390_COMMAND_STA, eth_nic_base+D8390_P0_COMMAND);
3697c478bd9Sstevel@tonic-gate 	else
3707c478bd9Sstevel@tonic-gate #endif
3717c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS0 | D8390_COMMAND_RD2 |
3727c478bd9Sstevel@tonic-gate 			D8390_COMMAND_STA, eth_nic_base+D8390_P0_COMMAND);
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 	/* clear the RX ring, acknowledge overrun interrupt */
3757c478bd9Sstevel@tonic-gate 	eth_drain_receiver = 1;
3767c478bd9Sstevel@tonic-gate 	while (ns8390_poll(nic, 1))
3777c478bd9Sstevel@tonic-gate 		/* Nothing */;
3787c478bd9Sstevel@tonic-gate 	eth_drain_receiver = 0;
3797c478bd9Sstevel@tonic-gate 	outb(D8390_ISR_OVW, eth_nic_base+D8390_P0_ISR);
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate 	/* leave loopback mode - no packets to be resent (see Linux driver) */
3827c478bd9Sstevel@tonic-gate 	outb(0, eth_nic_base+D8390_P0_TCR);
3837c478bd9Sstevel@tonic-gate }
3847c478bd9Sstevel@tonic-gate #endif	/* INCLUDE_3C503 */
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate /**************************************************************************
3877c478bd9Sstevel@tonic-gate NS8390_TRANSMIT - Transmit a frame
3887c478bd9Sstevel@tonic-gate **************************************************************************/
ns8390_transmit(struct nic * nic,const char * d,unsigned int t,unsigned int s,const char * p)3897c478bd9Sstevel@tonic-gate static void ns8390_transmit(
3907c478bd9Sstevel@tonic-gate 	struct nic *nic,
3917c478bd9Sstevel@tonic-gate 	const char *d,			/* Destination */
3927c478bd9Sstevel@tonic-gate 	unsigned int t,			/* Type */
3937c478bd9Sstevel@tonic-gate 	unsigned int s,			/* size */
3947c478bd9Sstevel@tonic-gate 	const char *p)			/* Packet */
3957c478bd9Sstevel@tonic-gate {
3967c478bd9Sstevel@tonic-gate #if defined(INCLUDE_3C503) || (defined(INCLUDE_WD) && ! defined(WD_790_PIO))
3977c478bd9Sstevel@tonic-gate 	Address		eth_vmem = bus_to_virt(eth_bmem);
3987c478bd9Sstevel@tonic-gate #endif
3997c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_3C503
4007c478bd9Sstevel@tonic-gate         if (!(eth_flags & FLAG_PIO)) {
4017c478bd9Sstevel@tonic-gate                 memcpy((char *)eth_vmem, d, ETH_ALEN);	/* dst */
4027c478bd9Sstevel@tonic-gate                 memcpy((char *)eth_vmem+ETH_ALEN, nic->node_addr, ETH_ALEN); /* src */
4037c478bd9Sstevel@tonic-gate                 *((char *)eth_vmem+12) = t>>8;		/* type */
4047c478bd9Sstevel@tonic-gate                 *((char *)eth_vmem+13) = t;
4057c478bd9Sstevel@tonic-gate                 memcpy((char *)eth_vmem+ETH_HLEN, p, s);
4067c478bd9Sstevel@tonic-gate                 s += ETH_HLEN;
4077c478bd9Sstevel@tonic-gate                 while (s < ETH_ZLEN) *((char *)eth_vmem+(s++)) = 0;
4087c478bd9Sstevel@tonic-gate         }
4097c478bd9Sstevel@tonic-gate #endif
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
4127c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_16BIT) {
4137c478bd9Sstevel@tonic-gate 		outb(eth_laar | WD_LAAR_M16EN, eth_asic_base + WD_LAAR);
4147c478bd9Sstevel@tonic-gate 		inb(0x84);
4157c478bd9Sstevel@tonic-gate 	}
4167c478bd9Sstevel@tonic-gate #ifndef	WD_790_PIO
4177c478bd9Sstevel@tonic-gate 	/* Memory interface */
4187c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790) {
4197c478bd9Sstevel@tonic-gate 		outb(WD_MSR_MENB, eth_asic_base + WD_MSR);
4207c478bd9Sstevel@tonic-gate 		inb(0x84);
4217c478bd9Sstevel@tonic-gate 	}
4227c478bd9Sstevel@tonic-gate 	inb(0x84);
4237c478bd9Sstevel@tonic-gate 	memcpy((char *)eth_vmem, d, ETH_ALEN);	/* dst */
4247c478bd9Sstevel@tonic-gate 	memcpy((char *)eth_vmem+ETH_ALEN, nic->node_addr, ETH_ALEN); /* src */
4257c478bd9Sstevel@tonic-gate 	*((char *)eth_vmem+12) = t>>8;		/* type */
4267c478bd9Sstevel@tonic-gate 	*((char *)eth_vmem+13) = t;
4277c478bd9Sstevel@tonic-gate 	memcpy((char *)eth_vmem+ETH_HLEN, p, s);
4287c478bd9Sstevel@tonic-gate 	s += ETH_HLEN;
4297c478bd9Sstevel@tonic-gate 	while (s < ETH_ZLEN) *((char *)eth_vmem+(s++)) = 0;
4307c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790) {
4317c478bd9Sstevel@tonic-gate 		outb(0, eth_asic_base + WD_MSR);
4327c478bd9Sstevel@tonic-gate 		inb(0x84);
4337c478bd9Sstevel@tonic-gate 	}
4347c478bd9Sstevel@tonic-gate #else
4357c478bd9Sstevel@tonic-gate 	inb(0x84);
4367c478bd9Sstevel@tonic-gate #endif
4377c478bd9Sstevel@tonic-gate #endif
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_3C503)
4407c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_PIO)
4417c478bd9Sstevel@tonic-gate #endif
4427c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_NE) || defined(INCLUDE_NS8390) || (defined(INCLUDE_3C503) && !defined(T503_SHMEM)) || (defined(INCLUDE_WD) && defined(WD_790_PIO))
4437c478bd9Sstevel@tonic-gate 	{
4447c478bd9Sstevel@tonic-gate 		/* Programmed I/O */
4457c478bd9Sstevel@tonic-gate 		unsigned short type;
4467c478bd9Sstevel@tonic-gate 		type = (t >> 8) | (t << 8);
4477c478bd9Sstevel@tonic-gate 		eth_pio_write(d, eth_tx_start<<8, ETH_ALEN);
4487c478bd9Sstevel@tonic-gate 		eth_pio_write(nic->node_addr, (eth_tx_start<<8)+ETH_ALEN, ETH_ALEN);
4497c478bd9Sstevel@tonic-gate 		/* bcc generates worse code without (const+const) below */
4507c478bd9Sstevel@tonic-gate 		eth_pio_write((unsigned char *)&type, (eth_tx_start<<8)+(ETH_ALEN+ETH_ALEN), 2);
4517c478bd9Sstevel@tonic-gate 		eth_pio_write(p, (eth_tx_start<<8)+ETH_HLEN, s);
4527c478bd9Sstevel@tonic-gate 		s += ETH_HLEN;
4537c478bd9Sstevel@tonic-gate 		if (s < ETH_ZLEN) s = ETH_ZLEN;
4547c478bd9Sstevel@tonic-gate 	}
4557c478bd9Sstevel@tonic-gate #endif
4567c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_3C503)
4577c478bd9Sstevel@tonic-gate #endif
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
4607c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_16BIT) {
4617c478bd9Sstevel@tonic-gate 		outb(eth_laar & ~WD_LAAR_M16EN, eth_asic_base + WD_LAAR);
4627c478bd9Sstevel@tonic-gate 		inb(0x84);
4637c478bd9Sstevel@tonic-gate 	}
4647c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790)
4657c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS0 |
4667c478bd9Sstevel@tonic-gate 			D8390_COMMAND_STA, eth_nic_base+D8390_P0_COMMAND);
4677c478bd9Sstevel@tonic-gate 	else
4687c478bd9Sstevel@tonic-gate #endif
4697c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS0 |
4707c478bd9Sstevel@tonic-gate 			D8390_COMMAND_RD2 | D8390_COMMAND_STA, eth_nic_base+D8390_P0_COMMAND);
4717c478bd9Sstevel@tonic-gate 	outb(eth_tx_start, eth_nic_base+D8390_P0_TPSR);
4727c478bd9Sstevel@tonic-gate 	outb(s, eth_nic_base+D8390_P0_TBCR0);
4737c478bd9Sstevel@tonic-gate 	outb(s>>8, eth_nic_base+D8390_P0_TBCR1);
4747c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
4757c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790)
4767c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS0 |
4777c478bd9Sstevel@tonic-gate 			D8390_COMMAND_TXP | D8390_COMMAND_STA, eth_nic_base+D8390_P0_COMMAND);
4787c478bd9Sstevel@tonic-gate 	else
4797c478bd9Sstevel@tonic-gate #endif
4807c478bd9Sstevel@tonic-gate 		outb(D8390_COMMAND_PS0 |
4817c478bd9Sstevel@tonic-gate 			D8390_COMMAND_TXP | D8390_COMMAND_RD2 |
4827c478bd9Sstevel@tonic-gate 			D8390_COMMAND_STA, eth_nic_base+D8390_P0_COMMAND);
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate /**************************************************************************
4867c478bd9Sstevel@tonic-gate NS8390_POLL - Wait for a frame
4877c478bd9Sstevel@tonic-gate **************************************************************************/
ns8390_poll(struct nic * nic,int retrieve)4887c478bd9Sstevel@tonic-gate static int ns8390_poll(struct nic *nic, int retrieve)
4897c478bd9Sstevel@tonic-gate {
4907c478bd9Sstevel@tonic-gate 	int ret = 0;
4917c478bd9Sstevel@tonic-gate 	unsigned char rstat, curr, next;
4927c478bd9Sstevel@tonic-gate 	unsigned short len, frag;
4937c478bd9Sstevel@tonic-gate 	unsigned short pktoff;
4947c478bd9Sstevel@tonic-gate 	unsigned char *p;
4957c478bd9Sstevel@tonic-gate 	struct ringbuffer pkthdr;
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate #ifndef	INCLUDE_3C503
4987c478bd9Sstevel@tonic-gate 	/* avoid infinite recursion: see eth_rx_overrun() */
4997c478bd9Sstevel@tonic-gate 	if (!eth_drain_receiver && (inb(eth_nic_base+D8390_P0_ISR) & D8390_ISR_OVW)) {
5007c478bd9Sstevel@tonic-gate 		eth_rx_overrun(nic);
5017c478bd9Sstevel@tonic-gate 		return(0);
5027c478bd9Sstevel@tonic-gate 	}
5037c478bd9Sstevel@tonic-gate #endif	/* INCLUDE_3C503 */
5047c478bd9Sstevel@tonic-gate 	rstat = inb(eth_nic_base+D8390_P0_RSR);
5057c478bd9Sstevel@tonic-gate 	if (!(rstat & D8390_RSTAT_PRX)) return(0);
5067c478bd9Sstevel@tonic-gate 	next = inb(eth_nic_base+D8390_P0_BOUND)+1;
5077c478bd9Sstevel@tonic-gate 	if (next >= eth_memsize) next = eth_rx_start;
5087c478bd9Sstevel@tonic-gate 	outb(D8390_COMMAND_PS1, eth_nic_base+D8390_P0_COMMAND);
5097c478bd9Sstevel@tonic-gate 	curr = inb(eth_nic_base+D8390_P1_CURR);
5107c478bd9Sstevel@tonic-gate 	outb(D8390_COMMAND_PS0, eth_nic_base+D8390_P0_COMMAND);
5117c478bd9Sstevel@tonic-gate 	if (curr >= eth_memsize) curr=eth_rx_start;
5127c478bd9Sstevel@tonic-gate 	if (curr == next) return(0);
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 	if ( ! retrieve ) return 1;
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
5177c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_16BIT) {
5187c478bd9Sstevel@tonic-gate 		outb(eth_laar | WD_LAAR_M16EN, eth_asic_base + WD_LAAR);
5197c478bd9Sstevel@tonic-gate 		inb(0x84);
5207c478bd9Sstevel@tonic-gate 	}
5217c478bd9Sstevel@tonic-gate #ifndef	WD_790_PIO
5227c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790) {
5237c478bd9Sstevel@tonic-gate 		outb(WD_MSR_MENB, eth_asic_base + WD_MSR);
5247c478bd9Sstevel@tonic-gate 		inb(0x84);
5257c478bd9Sstevel@tonic-gate 	}
5267c478bd9Sstevel@tonic-gate #endif
5277c478bd9Sstevel@tonic-gate 	inb(0x84);
5287c478bd9Sstevel@tonic-gate #endif
5297c478bd9Sstevel@tonic-gate 	pktoff = next << 8;
5307c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_PIO)
5317c478bd9Sstevel@tonic-gate 		eth_pio_read(pktoff, (char *)&pkthdr, 4);
5327c478bd9Sstevel@tonic-gate 	else
5337c478bd9Sstevel@tonic-gate 		memcpy(&pkthdr, bus_to_virt(eth_rmem + pktoff), 4);
5347c478bd9Sstevel@tonic-gate 	pktoff += sizeof(pkthdr);
5357c478bd9Sstevel@tonic-gate 	/* incoming length includes FCS so must sub 4 */
5367c478bd9Sstevel@tonic-gate 	len = pkthdr.len - 4;
5377c478bd9Sstevel@tonic-gate 	if ((pkthdr.status & D8390_RSTAT_PRX) == 0 || len < ETH_ZLEN
5387c478bd9Sstevel@tonic-gate 		|| len > ETH_FRAME_LEN) {
5397c478bd9Sstevel@tonic-gate 		printf("Bogus packet, ignoring\n");
5407c478bd9Sstevel@tonic-gate 		return (0);
5417c478bd9Sstevel@tonic-gate 	}
5427c478bd9Sstevel@tonic-gate 	else {
5437c478bd9Sstevel@tonic-gate 		p = nic->packet;
5447c478bd9Sstevel@tonic-gate 		nic->packetlen = len;		/* available to caller */
5457c478bd9Sstevel@tonic-gate 		frag = (eth_memsize << 8) - pktoff;
5467c478bd9Sstevel@tonic-gate 		if (len > frag) {		/* We have a wrap-around */
5477c478bd9Sstevel@tonic-gate 			/* read first part */
5487c478bd9Sstevel@tonic-gate 			if (eth_flags & FLAG_PIO)
5497c478bd9Sstevel@tonic-gate 				eth_pio_read(pktoff, p, frag);
5507c478bd9Sstevel@tonic-gate 			else
5517c478bd9Sstevel@tonic-gate 				memcpy(p, bus_to_virt(eth_rmem + pktoff), frag);
5527c478bd9Sstevel@tonic-gate 			pktoff = eth_rx_start << 8;
5537c478bd9Sstevel@tonic-gate 			p += frag;
5547c478bd9Sstevel@tonic-gate 			len -= frag;
5557c478bd9Sstevel@tonic-gate 		}
5567c478bd9Sstevel@tonic-gate 		/* read second part */
5577c478bd9Sstevel@tonic-gate 		if (eth_flags & FLAG_PIO)
5587c478bd9Sstevel@tonic-gate 			eth_pio_read(pktoff, p, len);
5597c478bd9Sstevel@tonic-gate 		else
5607c478bd9Sstevel@tonic-gate 			memcpy(p, bus_to_virt(eth_rmem + pktoff), len);
5617c478bd9Sstevel@tonic-gate 		ret = 1;
5627c478bd9Sstevel@tonic-gate 	}
5637c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
5647c478bd9Sstevel@tonic-gate #ifndef	WD_790_PIO
5657c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790) {
5667c478bd9Sstevel@tonic-gate 		outb(0, eth_asic_base + WD_MSR);
5677c478bd9Sstevel@tonic-gate 		inb(0x84);
5687c478bd9Sstevel@tonic-gate 	}
5697c478bd9Sstevel@tonic-gate #endif
5707c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_16BIT) {
5717c478bd9Sstevel@tonic-gate 		outb(eth_laar & ~WD_LAAR_M16EN, eth_asic_base + WD_LAAR);
5727c478bd9Sstevel@tonic-gate 		inb(0x84);
5737c478bd9Sstevel@tonic-gate 	}
5747c478bd9Sstevel@tonic-gate 	inb(0x84);
5757c478bd9Sstevel@tonic-gate #endif
5767c478bd9Sstevel@tonic-gate 	next = pkthdr.next;		/* frame number of next packet */
5777c478bd9Sstevel@tonic-gate 	if (next == eth_rx_start)
5787c478bd9Sstevel@tonic-gate 		next = eth_memsize;
5797c478bd9Sstevel@tonic-gate 	outb(next-1, eth_nic_base+D8390_P0_BOUND);
5807c478bd9Sstevel@tonic-gate 	return(ret);
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate /**************************************************************************
5847c478bd9Sstevel@tonic-gate NS8390_DISABLE - Turn off adapter
5857c478bd9Sstevel@tonic-gate **************************************************************************/
ns8390_disable(struct dev * dev)5867c478bd9Sstevel@tonic-gate static void ns8390_disable(struct dev *dev)
5877c478bd9Sstevel@tonic-gate {
5887c478bd9Sstevel@tonic-gate 	struct nic *nic = (struct nic *)dev;
5897c478bd9Sstevel@tonic-gate 	/* reset and disable merge */
5907c478bd9Sstevel@tonic-gate 	ns8390_reset(nic);
5917c478bd9Sstevel@tonic-gate }
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate /**************************************************************************
5947c478bd9Sstevel@tonic-gate NS8390_IRQ - Enable, Disable, or Force interrupts
5957c478bd9Sstevel@tonic-gate **************************************************************************/
ns8390_irq(struct nic * nic __unused,irq_action_t action __unused)5967c478bd9Sstevel@tonic-gate static void ns8390_irq(struct nic *nic __unused, irq_action_t action __unused)
5977c478bd9Sstevel@tonic-gate {
5987c478bd9Sstevel@tonic-gate   switch ( action ) {
5997c478bd9Sstevel@tonic-gate   case DISABLE :
6007c478bd9Sstevel@tonic-gate     break;
6017c478bd9Sstevel@tonic-gate   case ENABLE :
6027c478bd9Sstevel@tonic-gate     break;
6037c478bd9Sstevel@tonic-gate   case FORCE :
6047c478bd9Sstevel@tonic-gate     break;
6057c478bd9Sstevel@tonic-gate   }
6067c478bd9Sstevel@tonic-gate }
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate /**************************************************************************
6097c478bd9Sstevel@tonic-gate ETH_PROBE - Look for an adapter
6107c478bd9Sstevel@tonic-gate **************************************************************************/
6117c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_NS8390
eth_probe(struct dev * dev,struct pci_device * pci)6127c478bd9Sstevel@tonic-gate static int eth_probe (struct dev *dev, struct pci_device *pci)
6137c478bd9Sstevel@tonic-gate #else
6147c478bd9Sstevel@tonic-gate static int eth_probe (struct dev *dev, unsigned short *probe_addrs __unused)
6157c478bd9Sstevel@tonic-gate #endif
6167c478bd9Sstevel@tonic-gate {
6177c478bd9Sstevel@tonic-gate 	struct nic *nic = (struct nic *)dev;
6187c478bd9Sstevel@tonic-gate 	int i;
6197c478bd9Sstevel@tonic-gate #ifdef INCLUDE_NS8390
6207c478bd9Sstevel@tonic-gate 	unsigned short pci_probe_addrs[] = { pci->ioaddr, 0 };
6217c478bd9Sstevel@tonic-gate 	unsigned short *probe_addrs = pci_probe_addrs;
6227c478bd9Sstevel@tonic-gate #endif
6237c478bd9Sstevel@tonic-gate 	eth_vendor = VENDOR_NONE;
6247c478bd9Sstevel@tonic-gate 	eth_drain_receiver = 0;
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 	nic->irqno  = 0;
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
6297c478bd9Sstevel@tonic-gate {
6307c478bd9Sstevel@tonic-gate 	/******************************************************************
6317c478bd9Sstevel@tonic-gate 	Search for WD/SMC cards
6327c478bd9Sstevel@tonic-gate 	******************************************************************/
6337c478bd9Sstevel@tonic-gate 	struct wd_board *brd;
6347c478bd9Sstevel@tonic-gate 	unsigned short chksum;
6357c478bd9Sstevel@tonic-gate 	unsigned char c;
6367c478bd9Sstevel@tonic-gate 	for (eth_asic_base = WD_LOW_BASE; eth_asic_base <= WD_HIGH_BASE;
6377c478bd9Sstevel@tonic-gate 		eth_asic_base += 0x20) {
6387c478bd9Sstevel@tonic-gate 		chksum = 0;
6397c478bd9Sstevel@tonic-gate 		for (i=8; i<16; i++)
6407c478bd9Sstevel@tonic-gate 			chksum += inb(eth_asic_base+i);
6417c478bd9Sstevel@tonic-gate 		/* Extra checks to avoid soundcard */
6427c478bd9Sstevel@tonic-gate 		if ((chksum & 0xFF) == 0xFF &&
6437c478bd9Sstevel@tonic-gate 			inb(eth_asic_base+8) != 0xFF &&
6447c478bd9Sstevel@tonic-gate 			inb(eth_asic_base+9) != 0xFF)
6457c478bd9Sstevel@tonic-gate 			break;
6467c478bd9Sstevel@tonic-gate 	}
6477c478bd9Sstevel@tonic-gate 	if (eth_asic_base > WD_HIGH_BASE)
6487c478bd9Sstevel@tonic-gate 		return (0);
6497c478bd9Sstevel@tonic-gate 	/* We've found a board */
6507c478bd9Sstevel@tonic-gate 	eth_vendor = VENDOR_WD;
6517c478bd9Sstevel@tonic-gate 	eth_nic_base = eth_asic_base + WD_NIC_ADDR;
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate 	nic->ioaddr = eth_nic_base;
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate 	c = inb(eth_asic_base+WD_BID);	/* Get board id */
6567c478bd9Sstevel@tonic-gate 	for (brd = wd_boards; brd->name; brd++)
6577c478bd9Sstevel@tonic-gate 		if (brd->id == c) break;
6587c478bd9Sstevel@tonic-gate 	if (!brd->name) {
6597c478bd9Sstevel@tonic-gate 		printf("Unknown WD/SMC NIC type %hhX\n", c);
6607c478bd9Sstevel@tonic-gate 		return (0);	/* Unknown type */
6617c478bd9Sstevel@tonic-gate 	}
6627c478bd9Sstevel@tonic-gate 	eth_flags = brd->flags;
6637c478bd9Sstevel@tonic-gate 	eth_memsize = brd->memsize;
6647c478bd9Sstevel@tonic-gate 	eth_tx_start = 0;
6657c478bd9Sstevel@tonic-gate 	eth_rx_start = D8390_TXBUF_SIZE;
6667c478bd9Sstevel@tonic-gate 	if ((c == TYPE_WD8013EP) &&
6677c478bd9Sstevel@tonic-gate 		(inb(eth_asic_base + WD_ICR) & WD_ICR_16BIT)) {
6687c478bd9Sstevel@tonic-gate 			eth_flags = FLAG_16BIT;
6697c478bd9Sstevel@tonic-gate 			eth_memsize = MEM_16384;
6707c478bd9Sstevel@tonic-gate 	}
6717c478bd9Sstevel@tonic-gate 	if ((c & WD_SOFTCONFIG) && (!(eth_flags & FLAG_790))) {
6727c478bd9Sstevel@tonic-gate 		eth_bmem = (0x80000 |
6737c478bd9Sstevel@tonic-gate 		 ((inb(eth_asic_base + WD_MSR) & 0x3F) << 13));
6747c478bd9Sstevel@tonic-gate 	} else
6757c478bd9Sstevel@tonic-gate 		eth_bmem = WD_DEFAULT_MEM;
6767c478bd9Sstevel@tonic-gate 	if (brd->id == TYPE_SMC8216T || brd->id == TYPE_SMC8216C) {
6777c478bd9Sstevel@tonic-gate 		/* from Linux driver, 8416BT detects as 8216 sometimes */
6787c478bd9Sstevel@tonic-gate 		unsigned int addr = inb(eth_asic_base + 0xb);
6797c478bd9Sstevel@tonic-gate 		if (((addr >> 4) & 3) == 0) {
6807c478bd9Sstevel@tonic-gate 			brd += 2;
6817c478bd9Sstevel@tonic-gate 			eth_memsize = brd->memsize;
6827c478bd9Sstevel@tonic-gate 		}
6837c478bd9Sstevel@tonic-gate 	}
6847c478bd9Sstevel@tonic-gate 	outb(0x80, eth_asic_base + WD_MSR);	/* Reset */
6857c478bd9Sstevel@tonic-gate 	for (i=0; i<ETH_ALEN; i++) {
6867c478bd9Sstevel@tonic-gate 		nic->node_addr[i] = inb(i+eth_asic_base+WD_LAR);
6877c478bd9Sstevel@tonic-gate 	}
6887c478bd9Sstevel@tonic-gate 	printf("\n%s base %#hx", brd->name, eth_asic_base);
6897c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_790) {
6907c478bd9Sstevel@tonic-gate #ifdef	WD_790_PIO
6917c478bd9Sstevel@tonic-gate 		printf(", PIO mode, addr %!\n", nic->node_addr);
6927c478bd9Sstevel@tonic-gate 		eth_bmem = 0;
6937c478bd9Sstevel@tonic-gate 		eth_flags |= FLAG_PIO;		/* force PIO mode */
6947c478bd9Sstevel@tonic-gate 		outb(0, eth_asic_base+WD_MSR);
6957c478bd9Sstevel@tonic-gate #else
6967c478bd9Sstevel@tonic-gate 		printf(", memory %#x, addr %!\n", eth_bmem, nic->node_addr);
6977c478bd9Sstevel@tonic-gate 		outb(WD_MSR_MENB, eth_asic_base+WD_MSR);
6987c478bd9Sstevel@tonic-gate 		outb((inb(eth_asic_base+0x04) |
6997c478bd9Sstevel@tonic-gate 			0x80), eth_asic_base+0x04);
7007c478bd9Sstevel@tonic-gate 		outb(((unsigned)(eth_bmem >> 13) & 0x0F) |
7017c478bd9Sstevel@tonic-gate 			((unsigned)(eth_bmem >> 11) & 0x40) |
7027c478bd9Sstevel@tonic-gate 			(inb(eth_asic_base+0x0B) & 0xB0), eth_asic_base+0x0B);
7037c478bd9Sstevel@tonic-gate 		outb((inb(eth_asic_base+0x04) &
7047c478bd9Sstevel@tonic-gate 			~0x80), eth_asic_base+0x04);
7057c478bd9Sstevel@tonic-gate #endif
7067c478bd9Sstevel@tonic-gate 	} else {
7077c478bd9Sstevel@tonic-gate 		printf(", memory %#x, addr %!\n", eth_bmem, nic->node_addr);
7087c478bd9Sstevel@tonic-gate 		outb(((unsigned)(eth_bmem >> 13) & 0x3F) | 0x40, eth_asic_base+WD_MSR);
7097c478bd9Sstevel@tonic-gate 	}
7107c478bd9Sstevel@tonic-gate 	if (eth_flags & FLAG_16BIT) {
7117c478bd9Sstevel@tonic-gate 		if (eth_flags & FLAG_790) {
7127c478bd9Sstevel@tonic-gate 			eth_laar = inb(eth_asic_base + WD_LAAR);
7137c478bd9Sstevel@tonic-gate 			outb(WD_LAAR_M16EN, eth_asic_base + WD_LAAR);
7147c478bd9Sstevel@tonic-gate 		} else {
7157c478bd9Sstevel@tonic-gate 			outb((eth_laar =
7167c478bd9Sstevel@tonic-gate 				WD_LAAR_L16EN | 1), eth_asic_base + WD_LAAR);
7177c478bd9Sstevel@tonic-gate /*
7187c478bd9Sstevel@tonic-gate 	The previous line used to be
7197c478bd9Sstevel@tonic-gate 				WD_LAAR_M16EN | WD_LAAR_L16EN | 1));
7207c478bd9Sstevel@tonic-gate 	jluke@deakin.edu.au reported that removing WD_LAAR_M16EN made
7217c478bd9Sstevel@tonic-gate 	it work for WD8013s.  This seems to work for my 8013 boards. I
7227c478bd9Sstevel@tonic-gate 	don't know what is really happening.  I wish I had data sheets
7237c478bd9Sstevel@tonic-gate 	or more time to decode the Linux driver. - Ken
7247c478bd9Sstevel@tonic-gate */
7257c478bd9Sstevel@tonic-gate 		}
7267c478bd9Sstevel@tonic-gate 		inb(0x84);
7277c478bd9Sstevel@tonic-gate 	}
7287c478bd9Sstevel@tonic-gate }
7297c478bd9Sstevel@tonic-gate #endif
7307c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_3C503
7317c478bd9Sstevel@tonic-gate #ifdef	T503_AUI
7327c478bd9Sstevel@tonic-gate 	nic->flags = 1;		/* aui */
7337c478bd9Sstevel@tonic-gate #else
7347c478bd9Sstevel@tonic-gate 	nic->flags = 0;		/* no aui */
7357c478bd9Sstevel@tonic-gate #endif
7367c478bd9Sstevel@tonic-gate         /******************************************************************
7377c478bd9Sstevel@tonic-gate         Search for 3Com 3c503 if no WD/SMC cards
7387c478bd9Sstevel@tonic-gate         ******************************************************************/
7397c478bd9Sstevel@tonic-gate 	if (eth_vendor == VENDOR_NONE) {
7407c478bd9Sstevel@tonic-gate 		int	idx;
7417c478bd9Sstevel@tonic-gate 		int	iobase_reg, membase_reg;
7427c478bd9Sstevel@tonic-gate 		static unsigned short	base[] = {
7437c478bd9Sstevel@tonic-gate 			0x300, 0x310, 0x330, 0x350,
7447c478bd9Sstevel@tonic-gate 			0x250, 0x280, 0x2A0, 0x2E0, 0 };
7457c478bd9Sstevel@tonic-gate 
7467c478bd9Sstevel@tonic-gate 		/* Loop through possible addresses checking each one */
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate 		for (idx = 0; (eth_nic_base = base[idx]) != 0; ++idx) {
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate 			eth_asic_base = eth_nic_base + _3COM_ASIC_OFFSET;
7517c478bd9Sstevel@tonic-gate /*
7527c478bd9Sstevel@tonic-gate  * Note that we use the same settings for both 8 and 16 bit cards:
7537c478bd9Sstevel@tonic-gate  * both have an 8K bank of memory at page 1 while only the 16 bit
7547c478bd9Sstevel@tonic-gate  * cards have a bank at page 0.
7557c478bd9Sstevel@tonic-gate  */
7567c478bd9Sstevel@tonic-gate 			eth_memsize = MEM_16384;
7577c478bd9Sstevel@tonic-gate 			eth_tx_start = 32;
7587c478bd9Sstevel@tonic-gate 			eth_rx_start = 32 + D8390_TXBUF_SIZE;
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate 		/* Check our base address. iobase and membase should */
7617c478bd9Sstevel@tonic-gate 		/* both have a maximum of 1 bit set or be 0. */
7627c478bd9Sstevel@tonic-gate 
7637c478bd9Sstevel@tonic-gate 			iobase_reg = inb(eth_asic_base + _3COM_BCFR);
7647c478bd9Sstevel@tonic-gate 			membase_reg = inb(eth_asic_base + _3COM_PCFR);
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate 			if ((iobase_reg & (iobase_reg - 1)) ||
7677c478bd9Sstevel@tonic-gate 				(membase_reg & (membase_reg - 1)))
7687c478bd9Sstevel@tonic-gate 				continue;		/* nope */
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate 		/* Now get the shared memory address */
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate 			eth_flags = 0;
7737c478bd9Sstevel@tonic-gate 
7747c478bd9Sstevel@tonic-gate 			switch (membase_reg) {
7757c478bd9Sstevel@tonic-gate 				case _3COM_PCFR_DC000:
7767c478bd9Sstevel@tonic-gate 					eth_bmem = 0xdc000;
7777c478bd9Sstevel@tonic-gate 					break;
7787c478bd9Sstevel@tonic-gate 				case _3COM_PCFR_D8000:
7797c478bd9Sstevel@tonic-gate 					eth_bmem = 0xd8000;
7807c478bd9Sstevel@tonic-gate 					break;
7817c478bd9Sstevel@tonic-gate 				case _3COM_PCFR_CC000:
7827c478bd9Sstevel@tonic-gate 					eth_bmem = 0xcc000;
7837c478bd9Sstevel@tonic-gate 					break;
7847c478bd9Sstevel@tonic-gate 				case _3COM_PCFR_C8000:
7857c478bd9Sstevel@tonic-gate 					eth_bmem = 0xc8000;
7867c478bd9Sstevel@tonic-gate 					break;
7877c478bd9Sstevel@tonic-gate 				case _3COM_PCFR_PIO:
7887c478bd9Sstevel@tonic-gate 					eth_flags |= FLAG_PIO;
7897c478bd9Sstevel@tonic-gate 					eth_bmem = 0;
7907c478bd9Sstevel@tonic-gate 					break;
7917c478bd9Sstevel@tonic-gate 				default:
7927c478bd9Sstevel@tonic-gate 					continue;	/* nope */
7937c478bd9Sstevel@tonic-gate 				}
7947c478bd9Sstevel@tonic-gate 			break;
7957c478bd9Sstevel@tonic-gate 		}
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate 		if (base[idx] == 0)		/* not found */
7987c478bd9Sstevel@tonic-gate 			return (0);
7997c478bd9Sstevel@tonic-gate #ifndef	T503_SHMEM
8007c478bd9Sstevel@tonic-gate 		eth_flags |= FLAG_PIO;		/* force PIO mode */
8017c478bd9Sstevel@tonic-gate 		eth_bmem = 0;
8027c478bd9Sstevel@tonic-gate #endif
8037c478bd9Sstevel@tonic-gate 		eth_vendor = VENDOR_3COM;
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate 
8067c478bd9Sstevel@tonic-gate         /* Need this to make ns8390_poll() happy. */
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate                 eth_rmem = eth_bmem - 0x2000;
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate         /* Reset NIC and ASIC */
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate                 outb(_3COM_CR_RST | _3COM_CR_XSEL, eth_asic_base + _3COM_CR );
8137c478bd9Sstevel@tonic-gate                 outb(_3COM_CR_XSEL, eth_asic_base + _3COM_CR );
8147c478bd9Sstevel@tonic-gate 
8157c478bd9Sstevel@tonic-gate         /* Get our ethernet address */
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate                 outb(_3COM_CR_EALO | _3COM_CR_XSEL, eth_asic_base + _3COM_CR);
8187c478bd9Sstevel@tonic-gate 		nic->ioaddr = eth_nic_base;
8197c478bd9Sstevel@tonic-gate                 printf("\n3Com 3c503 base %#hx, ", eth_nic_base);
8207c478bd9Sstevel@tonic-gate                 if (eth_flags & FLAG_PIO)
8217c478bd9Sstevel@tonic-gate 			printf("PIO mode");
8227c478bd9Sstevel@tonic-gate                 else
8237c478bd9Sstevel@tonic-gate 			printf("memory %#x", eth_bmem);
8247c478bd9Sstevel@tonic-gate                 for (i=0; i<ETH_ALEN; i++) {
8257c478bd9Sstevel@tonic-gate                         nic->node_addr[i] = inb(eth_nic_base+i);
8267c478bd9Sstevel@tonic-gate                 }
8277c478bd9Sstevel@tonic-gate                 printf(", %s, addr %!\n", nic->flags ? "AUI" : "internal xcvr",
8287c478bd9Sstevel@tonic-gate 			nic->node_addr);
8297c478bd9Sstevel@tonic-gate                 outb(_3COM_CR_XSEL, eth_asic_base + _3COM_CR);
8307c478bd9Sstevel@tonic-gate         /*
8317c478bd9Sstevel@tonic-gate          * Initialize GA configuration register. Set bank and enable shared
8327c478bd9Sstevel@tonic-gate          * mem. We always use bank 1. Disable interrupts.
8337c478bd9Sstevel@tonic-gate          */
8347c478bd9Sstevel@tonic-gate                 outb(_3COM_GACFR_RSEL |
8357c478bd9Sstevel@tonic-gate 			_3COM_GACFR_MBS0 | _3COM_GACFR_TCM | _3COM_GACFR_NIM, eth_asic_base + _3COM_GACFR);
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate                 outb(0xff, eth_asic_base + _3COM_VPTR2);
8387c478bd9Sstevel@tonic-gate                 outb(0xff, eth_asic_base + _3COM_VPTR1);
8397c478bd9Sstevel@tonic-gate                 outb(0x00, eth_asic_base + _3COM_VPTR0);
8407c478bd9Sstevel@tonic-gate         /*
8417c478bd9Sstevel@tonic-gate          * Clear memory and verify that it worked (we use only 8K)
8427c478bd9Sstevel@tonic-gate          */
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate 		if (!(eth_flags & FLAG_PIO)) {
8457c478bd9Sstevel@tonic-gate 			memset(bus_to_virt(eth_bmem), 0, 0x2000);
8467c478bd9Sstevel@tonic-gate 			for(i = 0; i < 0x2000; ++i)
8477c478bd9Sstevel@tonic-gate 				if (*((char *)(bus_to_virt(eth_bmem+i)))) {
8487c478bd9Sstevel@tonic-gate 					printf ("Failed to clear 3c503 shared mem.\n");
8497c478bd9Sstevel@tonic-gate 					return (0);
8507c478bd9Sstevel@tonic-gate 				}
8517c478bd9Sstevel@tonic-gate 		}
8527c478bd9Sstevel@tonic-gate         /*
8537c478bd9Sstevel@tonic-gate          * Initialize GA page/start/stop registers.
8547c478bd9Sstevel@tonic-gate          */
8557c478bd9Sstevel@tonic-gate                 outb(eth_tx_start, eth_asic_base + _3COM_PSTR);
8567c478bd9Sstevel@tonic-gate                 outb(eth_memsize, eth_asic_base + _3COM_PSPR);
8577c478bd9Sstevel@tonic-gate         }
8587c478bd9Sstevel@tonic-gate #endif
8597c478bd9Sstevel@tonic-gate #if	defined(INCLUDE_NE) || defined(INCLUDE_NS8390)
8607c478bd9Sstevel@tonic-gate {
8617c478bd9Sstevel@tonic-gate 	/******************************************************************
8627c478bd9Sstevel@tonic-gate 	Search for NE1000/2000 if no WD/SMC or 3com cards
8637c478bd9Sstevel@tonic-gate 	******************************************************************/
8647c478bd9Sstevel@tonic-gate 	unsigned char c;
8657c478bd9Sstevel@tonic-gate 	if (eth_vendor == VENDOR_NONE) {
8667c478bd9Sstevel@tonic-gate 		char romdata[16], testbuf[32];
8677c478bd9Sstevel@tonic-gate 		int idx;
8687c478bd9Sstevel@tonic-gate 		static char test[] = "NE*000 memory";
8697c478bd9Sstevel@tonic-gate 		static unsigned short base[] = {
8707c478bd9Sstevel@tonic-gate #ifdef	NE_SCAN
8717c478bd9Sstevel@tonic-gate 			NE_SCAN,
8727c478bd9Sstevel@tonic-gate #endif
8737c478bd9Sstevel@tonic-gate 			0 };
8747c478bd9Sstevel@tonic-gate 		/* if no addresses supplied, fall back on defaults */
8757c478bd9Sstevel@tonic-gate 		if (probe_addrs == 0 || probe_addrs[0] == 0)
8767c478bd9Sstevel@tonic-gate 			probe_addrs = base;
8777c478bd9Sstevel@tonic-gate 		eth_bmem = 0;		/* No shared memory */
8787c478bd9Sstevel@tonic-gate 		for (idx = 0; (eth_nic_base = probe_addrs[idx]) != 0; ++idx) {
8797c478bd9Sstevel@tonic-gate 			eth_flags = FLAG_PIO;
8807c478bd9Sstevel@tonic-gate 			eth_asic_base = eth_nic_base + NE_ASIC_OFFSET;
8817c478bd9Sstevel@tonic-gate 			eth_memsize = MEM_16384;
8827c478bd9Sstevel@tonic-gate 			eth_tx_start = 32;
8837c478bd9Sstevel@tonic-gate 			eth_rx_start = 32 + D8390_TXBUF_SIZE;
8847c478bd9Sstevel@tonic-gate 			c = inb(eth_asic_base + NE_RESET);
8857c478bd9Sstevel@tonic-gate 			outb(c, eth_asic_base + NE_RESET);
8867c478bd9Sstevel@tonic-gate 			inb(0x84);
8877c478bd9Sstevel@tonic-gate 			outb(D8390_COMMAND_STP |
8887c478bd9Sstevel@tonic-gate 				D8390_COMMAND_RD2, eth_nic_base + D8390_P0_COMMAND);
8897c478bd9Sstevel@tonic-gate 			outb(D8390_RCR_MON, eth_nic_base + D8390_P0_RCR);
8907c478bd9Sstevel@tonic-gate 			outb(D8390_DCR_FT1 | D8390_DCR_LS, eth_nic_base + D8390_P0_DCR);
8917c478bd9Sstevel@tonic-gate 			outb(MEM_8192, eth_nic_base + D8390_P0_PSTART);
8927c478bd9Sstevel@tonic-gate 			outb(MEM_16384, eth_nic_base + D8390_P0_PSTOP);
8937c478bd9Sstevel@tonic-gate #ifdef	NS8390_FORCE_16BIT
8947c478bd9Sstevel@tonic-gate 			eth_flags |= FLAG_16BIT;	/* force 16-bit mode */
8957c478bd9Sstevel@tonic-gate #endif
8967c478bd9Sstevel@tonic-gate 
8977c478bd9Sstevel@tonic-gate 			eth_pio_write(test, 8192, sizeof(test));
8987c478bd9Sstevel@tonic-gate 			eth_pio_read(8192, testbuf, sizeof(test));
8997c478bd9Sstevel@tonic-gate 			if (!memcmp(test, testbuf, sizeof(test)))
9007c478bd9Sstevel@tonic-gate 				break;
9017c478bd9Sstevel@tonic-gate 			eth_flags |= FLAG_16BIT;
9027c478bd9Sstevel@tonic-gate 			eth_memsize = MEM_32768;
9037c478bd9Sstevel@tonic-gate 			eth_tx_start = 64;
9047c478bd9Sstevel@tonic-gate 			eth_rx_start = 64 + D8390_TXBUF_SIZE;
9057c478bd9Sstevel@tonic-gate 			outb(D8390_DCR_WTS |
9067c478bd9Sstevel@tonic-gate 				D8390_DCR_FT1 | D8390_DCR_LS, eth_nic_base + D8390_P0_DCR);
9077c478bd9Sstevel@tonic-gate 			outb(MEM_16384, eth_nic_base + D8390_P0_PSTART);
9087c478bd9Sstevel@tonic-gate 			outb(MEM_32768, eth_nic_base + D8390_P0_PSTOP);
9097c478bd9Sstevel@tonic-gate 			eth_pio_write(test, 16384, sizeof(test));
9107c478bd9Sstevel@tonic-gate 			eth_pio_read(16384, testbuf, sizeof(test));
9117c478bd9Sstevel@tonic-gate 			if (!memcmp(testbuf, test, sizeof(test)))
9127c478bd9Sstevel@tonic-gate 				break;
9137c478bd9Sstevel@tonic-gate 		}
9147c478bd9Sstevel@tonic-gate 		if (eth_nic_base == 0)
9157c478bd9Sstevel@tonic-gate 			return (0);
9167c478bd9Sstevel@tonic-gate 		if (eth_nic_base > ISA_MAX_ADDR)	/* PCI probably */
9177c478bd9Sstevel@tonic-gate 			eth_flags |= FLAG_16BIT;
9187c478bd9Sstevel@tonic-gate 		eth_vendor = VENDOR_NOVELL;
9197c478bd9Sstevel@tonic-gate 		eth_pio_read(0, romdata, sizeof(romdata));
9207c478bd9Sstevel@tonic-gate 		for (i=0; i<ETH_ALEN; i++) {
9217c478bd9Sstevel@tonic-gate 			nic->node_addr[i] = romdata[i + ((eth_flags & FLAG_16BIT) ? i : 0)];
9227c478bd9Sstevel@tonic-gate 		}
9237c478bd9Sstevel@tonic-gate 		nic->ioaddr = eth_nic_base;
9247c478bd9Sstevel@tonic-gate 		printf("\nNE%c000 base %#hx, addr %!\n",
9257c478bd9Sstevel@tonic-gate 			(eth_flags & FLAG_16BIT) ? '2' : '1', eth_nic_base,
9267c478bd9Sstevel@tonic-gate 			nic->node_addr);
9277c478bd9Sstevel@tonic-gate 	}
9287c478bd9Sstevel@tonic-gate }
9297c478bd9Sstevel@tonic-gate #endif
9307c478bd9Sstevel@tonic-gate 	if (eth_vendor == VENDOR_NONE)
9317c478bd9Sstevel@tonic-gate 		return(0);
9327c478bd9Sstevel@tonic-gate         if (eth_vendor != VENDOR_3COM)
9337c478bd9Sstevel@tonic-gate 		eth_rmem = eth_bmem;
9347c478bd9Sstevel@tonic-gate 	ns8390_reset(nic);
9357c478bd9Sstevel@tonic-gate 
9367c478bd9Sstevel@tonic-gate 	dev->disable  = ns8390_disable;
9377c478bd9Sstevel@tonic-gate 	nic->poll     = ns8390_poll;
9387c478bd9Sstevel@tonic-gate 	nic->transmit = ns8390_transmit;
9397c478bd9Sstevel@tonic-gate 	nic->irq      = ns8390_irq;
9407c478bd9Sstevel@tonic-gate 
9417c478bd9Sstevel@tonic-gate         /* Based on PnP ISA map */
9427c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
9437c478bd9Sstevel@tonic-gate         dev->devid.vendor_id = htons(GENERIC_ISAPNP_VENDOR);
9447c478bd9Sstevel@tonic-gate         dev->devid.device_id = htons(0x812a);
9457c478bd9Sstevel@tonic-gate #endif
9467c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_3C503
9477c478bd9Sstevel@tonic-gate         dev->devid.vendor_id = htons(GENERIC_ISAPNP_VENDOR);
9487c478bd9Sstevel@tonic-gate         dev->devid.device_id = htons(0x80f3);
9497c478bd9Sstevel@tonic-gate #endif
9507c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_NE
9517c478bd9Sstevel@tonic-gate         dev->devid.vendor_id = htons(GENERIC_ISAPNP_VENDOR);
9527c478bd9Sstevel@tonic-gate         dev->devid.device_id = htons(0x80d6);
9537c478bd9Sstevel@tonic-gate #endif
9547c478bd9Sstevel@tonic-gate 	return 1;
9557c478bd9Sstevel@tonic-gate }
9567c478bd9Sstevel@tonic-gate 
9577c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_WD
9587c478bd9Sstevel@tonic-gate static struct isa_driver wd_driver __isa_driver = {
9597c478bd9Sstevel@tonic-gate 	.type    = NIC_DRIVER,
9607c478bd9Sstevel@tonic-gate 	.name    = "WD",
9617c478bd9Sstevel@tonic-gate 	.probe   = wd_probe,
9627c478bd9Sstevel@tonic-gate 	.ioaddrs = 0,
9637c478bd9Sstevel@tonic-gate };
9647c478bd9Sstevel@tonic-gate #endif
9657c478bd9Sstevel@tonic-gate 
9667c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_3C503
9677c478bd9Sstevel@tonic-gate static struct isa_driver t503_driver __isa_driver = {
9687c478bd9Sstevel@tonic-gate 	.type    = NIC_DRIVER,
9697c478bd9Sstevel@tonic-gate 	.name    = "3C503",
9707c478bd9Sstevel@tonic-gate 	.probe   = t503_probe,
9717c478bd9Sstevel@tonic-gate 	.ioaddrs = 0,
9727c478bd9Sstevel@tonic-gate };
9737c478bd9Sstevel@tonic-gate #endif
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_NE
9767c478bd9Sstevel@tonic-gate static struct isa_driver ne_driver __isa_driver = {
9777c478bd9Sstevel@tonic-gate 	.type    = NIC_DRIVER,
9787c478bd9Sstevel@tonic-gate 	.name    = "NE*000",
9797c478bd9Sstevel@tonic-gate 	.probe   = ne_probe,
9807c478bd9Sstevel@tonic-gate 	.ioaddrs = 0,
9817c478bd9Sstevel@tonic-gate };
9827c478bd9Sstevel@tonic-gate #endif
9837c478bd9Sstevel@tonic-gate 
9847c478bd9Sstevel@tonic-gate #ifdef	INCLUDE_NS8390
9857c478bd9Sstevel@tonic-gate static struct pci_id nepci_nics[] = {
9867c478bd9Sstevel@tonic-gate /* A few NE2000 PCI clones, list not exhaustive */
9877c478bd9Sstevel@tonic-gate PCI_ROM(0x10ec, 0x8029, "rtl8029",      "Realtek 8029"),
9887c478bd9Sstevel@tonic-gate PCI_ROM(0x1186, 0x0300, "dlink-528",    "D-Link DE-528"),
9897c478bd9Sstevel@tonic-gate PCI_ROM(0x1050, 0x0940, "winbond940",   "Winbond NE2000-PCI"),		/* Winbond 86C940 / 89C940 */
9907c478bd9Sstevel@tonic-gate PCI_ROM(0x1050, 0x5a5a, "winbond940f",  "Winbond W89c940F"),		/* Winbond 89C940F */
9917c478bd9Sstevel@tonic-gate PCI_ROM(0x11f6, 0x1401, "compexrl2000", "Compex ReadyLink 2000"),
9927c478bd9Sstevel@tonic-gate PCI_ROM(0x8e2e, 0x3000, "ktiet32p2",    "KTI ET32P2"),
9937c478bd9Sstevel@tonic-gate PCI_ROM(0x4a14, 0x5000, "nv5000sc",     "NetVin NV5000SC"),
9947c478bd9Sstevel@tonic-gate PCI_ROM(0x12c3, 0x0058, "holtek80232",  "Holtek HT80232"),
9957c478bd9Sstevel@tonic-gate PCI_ROM(0x12c3, 0x5598, "holtek80229",  "Holtek HT80229"),
9967c478bd9Sstevel@tonic-gate PCI_ROM(0x10bd, 0x0e34, "surecom-ne34", "Surecom NE34"),
9977c478bd9Sstevel@tonic-gate PCI_ROM(0x1106, 0x0926, "via86c926",    "Via 86c926"),
9987c478bd9Sstevel@tonic-gate };
9997c478bd9Sstevel@tonic-gate 
10007c478bd9Sstevel@tonic-gate struct pci_driver nepci_driver = {
10017c478bd9Sstevel@tonic-gate 	.type     = NIC_DRIVER,
10027c478bd9Sstevel@tonic-gate 	.name     = "NE2000/PCI",
10037c478bd9Sstevel@tonic-gate 	.probe    = nepci_probe,
10047c478bd9Sstevel@tonic-gate 	.ids      = nepci_nics,
10057c478bd9Sstevel@tonic-gate 	.id_count = sizeof(nepci_nics)/sizeof(nepci_nics[0]),
10067c478bd9Sstevel@tonic-gate 	.class    = 0,
10077c478bd9Sstevel@tonic-gate };
10087c478bd9Sstevel@tonic-gate 
10097c478bd9Sstevel@tonic-gate #endif /* INCLUDE_NS8390 */
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate /*
10127c478bd9Sstevel@tonic-gate  * Local variables:
10137c478bd9Sstevel@tonic-gate  *  c-basic-offset: 8
10147c478bd9Sstevel@tonic-gate  * End:
10157c478bd9Sstevel@tonic-gate  */
10167c478bd9Sstevel@tonic-gate 
1017