Subject: port-i386/26899: i386 PS/2 MCA: Driver for Tiara LANCard / Fujitsu mb86950 EtherStar
To: None <gnats-bugs@gnats.NetBSD.org>
From: at <djb_pizza@www.netbsd.org, ieee.org@www.netbsd.org>
List: netbsd-bugs
Date: 09/09/2004 21:15:56
>Number:         26899
>Category:       port-i386
>Synopsis:       i386 PS/2 MCA: Driver for Tiara LANCard / Fujitsu mb86950 EtherStar
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    port-i386-maintainer
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 09 21:17:02 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Dave Barnes
>Release:        2.0_BETA
>Organization:
Consult Engr
>Environment:
PS/2 mod 50z with PowerBoard Upgrade
>Description:
Attached are files and diffs to add a driver for the Tiara LANCard and friends based on the Fujitsu mb86950 EtherStar chip.  Code is included to ID and attach the Microchannel version of the SMC 3016.  This code for the 3016 has not been tested.

There may be some minor pieces missing here and there that should be in a NetBSD ethernet driver.  I put in only what was necessary to get the Tiara LANCard to work.  

Limitations:
  Multicast is not supported

The Tiara adf file (@6000.adf) lists IRQ6 as an interrupt choice.  IRQ6 is incorrect. The hardware can interrupt on IRQ7 not IRQ6. Nobody ever changed the adf file.

(Please excuse style mistakes -- it's been a long time since I've done C ..)


>How-To-Repeat:
Dmesg with Tiara LANCard = tra0
-----
NetBSD 2.0_BETA (2004/08/16 DJB.ps2:2.0_BETA) #7: Mon Sep  6 21:01:05 CDT 2004
	root@PapaJohn:/usr/src/sys/arch/i386/compile/DJB
total memory = 32380 KB
avail memory = 30136 KB
mainbus0 (root)
cpu0 at mainbus0: (uniprocessor)
cpu0: AMD Am5x86 W/T 133/160 (486-class), id 0x4e4
cpu0: features 1<FPU>
mca0 at mainbus0
tra0 at mca0 slot 1 ports 0x1200-0x1220 irq 9: Tiara LANCard/E2
tra0: Ethernet address 08:00:1a:02:81:ed
we0 at mca0 slot 3 port 0x800-0x81f mem 0xd0000-0xd1fff irq 3: EtherCard PLUS Elite/A (8013EP/A)
we0: WD8013EP/A Ethernet (16-bit)
we0: Ethernet address 00:00:c0:fb:dd:09
isa0 at mainbus0
com0 at isa0 port 0x3f8-0x3ff irq 4: ns16550a, working fifo
pckbc0 at isa0 port 0x60-0x64
pckbd0 at pckbc0 (kbd slot)
pckbc0: using irq 1 for kbd slot
wskbd0 at pckbd0: console keyboard
wdc0 at isa0 port 0x1f0-0x1f7 irq 14
atabus0 at wdc0 channel 0
vga0 at isa0 port 0x3b0-0x3df iomem 0xa0000-0xbffff
wsdisplay0 at vga0 kbdmux 1: console (80x25, vt100 emulation), using wskbd0
wsmux1: connecting to wsdisplay0
pcppi0 at isa0 port 0x61
sysbeep0 at pcppi0
npx0 at isa0 port 0xf0-0xff: using exception 16
wd0 at atabus0 drive 0: <ST3491A>
wd0: drive supports 16-sector PIO transfers, chs addressing
wd0: 408 MB, 899 cyl, 15 head, 62 sec, 512 bytes/sect x 836070 sectors
wd0: drive supports PIO mode 3, DMA mode 1
boot device: wd0
root on wd0a dumps on wd0b
root file system type: ffs
wsdisplay0: screen 1 added (80x25, vt100 emulation)
wsdisplay0: screen 2 added (80x25, vt100 emulation)
wsdisplay0: screen 3 added (80x25, vt100 emulation)
wsdisplay0: screen 4 added (80x25, vt100 emulation)
-------------

# ping -f 10.0.0.104
PING anchovy (10.0.0.104): 56 data bytes
^C

----anchovy PING Statistics----
8981 packets transmitted, 8981 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.133/1.260/7.457/0.233 ms
  742.3 packets/sec sent,  742.1 packets/sec received
# netstat -I tra0
Name  Mtu   Network       Address              Ipkts Ierrs    Opkts Oerrs Colls
tra0  1500  <Link>        08:00:1a:02:81:ed     9149     1    18314     0     5
tra0  1500  10/24         PS2                   9149     1    18314     0     5
# ifconfig tra0
tra0: flags=863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX> mtu 1500
        address: 08:00:1a:02:81:ed
        media: Ethernet manual
        inet 10.0.0.99 netmask 0xffffff00 broadcast 10.0.0.255
#
------

>Fix:
======================= /usr/src/sys/dev/mca/if_tra_mca.c =============
*	$NetBSD: if_tra_mca.c,v 1.00 2004/09/01 00:00:00 djbarnes Exp $	*/

/*-
 * Copyright (c) 2004 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Jaromir Dolecek.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the NetBSD
 *	Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Driver for Tiara LANCard/E II and friends adapted from if_ate_mca.c by Dave J. Barnes 2004.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_tra_mca.c,v 1.00 2004/09/01 00:00:00 djbarnes Exp $");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/socket.h>
#include <sys/syslog.h>

#include <net/if.h>
#include <net/if_ether.h>
#include <net/if_media.h>

#include <machine/bus.h>
#include <machine/intr.h>

#include <dev/ic/mb86950reg.h>
#include <dev/ic/mb86950var.h>

#include <dev/mca/mcavar.h>
#include <dev/mca/mcadevs.h>

int	tiara_mca_match __P((struct device *, struct cfdata *, void *));
void	tiara_mca_attach __P((struct device *, struct device *, void *));

#define TIARA_NPORTS 0x20 /* 32 */
#define TIARA_PROM_ID 24 /* offset to mac addr stored in prom */

struct tiara_softc {
	struct	mb86950_softc sc_mb86950;	/* real "mb86950" softc */

	/* MCA-specific goo. */
	void	*sc_ih;				/* interrupt cookie */
};

CFATTACH_DECL(tra_mca, sizeof(struct tiara_softc),
    tiara_mca_match, tiara_mca_attach, NULL, NULL);

static const struct tiara_mca_product {
	u_int32_t	tra_prodid;	/* MCA product ID */
	const char	*tra_name;	/* device name */
} tiara_mca_products[] = {
	{ MCA_PRODUCT_TIARA,	"Tiara LANCard/E2"},
	{ MCA_PRODUCT_TIARA_TP,	"Tiara LANCard/E2 TP"},
	{ MCA_PRODUCT_SMC3016,  "SMC 3016/MC"},
	{ 0	}
};

static const struct tiara_mca_product *tiara_mca_lookup __P((u_int32_t));

static const struct tiara_mca_product *
tiara_mca_lookup(id)
	u_int32_t id;
{
	const struct tiara_mca_product *tra_p;

	for (tra_p = tiara_mca_products; tra_p->tra_name != NULL; tra_p++)
		if (id == tra_p->tra_prodid)
			return (tra_p);

	return (NULL);
}

int
tiara_mca_match(parent, match, aux)
	struct device *parent;
	struct cfdata *match;
	void *aux;
{
	struct mca_attach_args *ma = (struct mca_attach_args *) aux;

	if (tiara_mca_lookup(ma->ma_id) != NULL)
		return (1);

	return (0);
}

/* see POS diagrams below for explanation */
static const int tiara_irq[] = {
	3, 4, 7, 9
};
static const int smc_iobase[] = {
	0x300, 0x340, 0x360, 0x1980, 0x2000, 0x5680, 0x5900, 0x8080
};
static const int smc_irq[] = {
	9, 10, 11, 15, 3, 5, 7, 4
};

void
tiara_mca_attach(parent, self, aux)
	struct device *parent, *self;
	void *aux;
{
	struct tiara_softc *isc = (struct tiara_softc *)self;
	struct mb86950_softc *sc = &isc->sc_mb86950;
	struct mca_attach_args *ma = aux;
	bus_space_tag_t iot = ma->ma_iot;
	bus_space_handle_t ioh;
	u_int8_t myea[ETHER_ADDR_LEN];
	int pos2;
	int iobase = 0, irq = 0;
	const struct tiara_mca_product *tra_p;

    pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);

	tra_p = tiara_mca_lookup(ma->ma_id);

    switch (tra_p->tra_prodid) {

    case MCA_PRODUCT_TIARA:
    case MCA_PRODUCT_TIARA_TP:

		/*
		 * POS register 2: (adf pos0)
		 * 7 6 5 4 3 2 1 0
		 * \_____/ \_/  \ \__ enable: 0=adapter disabled, 1=adapter enabled
		 *       \   \   \___ boot rom: 0=disabled, 1=enabled
		 *        \   \______ IRQ 00=3 01=4 10=7 11=9
		 *         \_________ Base I/O Port
		 *						0000=0x1200 0001=0x1220 ... 1110=0x13c0 1111=0x13e0
		 *
		 * POS register 3: (adf pos1) not used
		 * POS register 4: (adf pos2) not used
		 *
		 * POS register 5: (adf pos3) ignored
		 *
		 * 7 6 5 4 3 2 1 0
		 * 1 1 0 X \____/
		 *              \____EPROM Address
		 */
	    iobase = 0x1200 + ((pos2 & 0xf0) << 1);
	    irq = tiara_irq[((pos2 & 0x0c) >> 2)];

		/* XXX SWAG for number pkts. */
		/* My Tiara LANCard has 128K memory ?!? */
		sc->txb_num_pkt = 4;
		sc->rxb_num_pkt = (65535 - 8192 - 4) / 64;
		/* XXX                       */

    	break;

	case MCA_PRODUCT_SMC3016:
		/*
		 * POS register 2: (adf pos0)
		 * 7 6 5 4 3 2 1 0
		 * \_____/ \___/  \__ enable: 0=adapter disabled, 1=adapter enabled
		 *       \     \_____ I/O Address (see ioaddr table)
		 *        \__________ IRQ (see irq table)
		 *
		 * POS register 3: (adf pos1) ignored
         * 7 6 5 4 3 2 1 0
		 * X X X X \____/
		 *              \____EPROM Address (0000 = not used)
         */
		iobase = smc_iobase[((pos2 & 0x0e) >> 1)];
		if ((pos2 & 0x80) != 0) irq = smc_irq[((pos2 & 0x70) >> 4)];
		else printf("%s: unsupported irq selected\n",sc->sc_dev.dv_xname);

		/* XXX SWAG for number pkts. */
		/* The SMC3016 has a 12K rx buffer and a 4k tx buffer */
		sc->txb_num_pkt = 2;
		sc->rxb_num_pkt = (12288 - 4) / 64;
		/* XXX                       */

    	break;
    }


#ifdef DIAGNOSTIC
	tra_p = tiara_mca_lookup(ma->ma_id);
	if (tra_p == NULL) {
		printf("\n%s: where did the card go?\n", sc->sc_dev.dv_xname);
		return;
	}
#endif

	printf(" slot %d ports %#x-%#x irq %d: %s\n", ma->ma_slot + 1,iobase, iobase + TIARA_NPORTS, irq, tra_p->tra_name);

	/* Map i/o space. */
	if (bus_space_map(iot, iobase, TIARA_NPORTS, 0, &ioh)) {
		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
		return;
	}

	sc->sc_bst = iot;
	sc->sc_bsh = ioh;

	/* Get ethernet address from PROM */
	bus_space_read_region_1(iot, ioh, TIARA_PROM_ID, myea, ETHER_ADDR_LEN);

	/* This interface is always enabled. */
/* XXX
	sc->sc_stat |= NIC_STAT_ENABLED;
*/
	/*
	 * Do generic MB86950 attach.
	 */
	mb86950_attach(sc, myea);


	mb86950_config(sc, NULL, 0, 0);

	/* Establish the interrupt handler. */
	isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET,
			mb86950_intr, sc);
	if (isc->sc_ih == NULL) {
		printf("%s: couldn't establish interrupt handler\n",
		    sc->sc_dev.dv_xname);
		return;
	}
}

==================================== /usr/src/sys/dev/ic/mb86950.c =====
*	$NetBSD: mb86950.c,v 1.00 2004/09/01 00:00:00 djbarnes Exp $	*/

/*
 * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
 *
 * This software may be used, modified, copied, distributed, and sold, in
 * both source and binary form provided that the above copyright, these
 * terms and the following disclaimer are retained.  The name of the author
 * and/or the contributor may not be used to endorse or promote products
 * derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION.
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * Portions copyright (C) 1993, David Greenman.  This software may be used,
 * modified, copied, distributed, and sold, in both source and binary form
 * provided that the above copyright and these terms are retained.  Under no
 * circumstances is the author responsible for the proper functioning of this
 * software, nor does the author assume any responsibility for damages
 * incurred with its use.
 */

 /*
  * Portions copyright (c) 1995 Mika Kortelainen
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software
  *    must display the following acknowledgement:
  *      This product includes software developed by  Mika Kortelainen
  * 4. The name of the author may not be used to endorse or promote products
  *    derived from this software without specific prior written permission
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */

 /*
  * Device driver for Fujitsu MB86960A/MB86965A based Ethernet cards.
  * Contributed by M.S. <seki@sysrap.cs.fujitsu.co.jp>
  */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mb86950.c,v 1.00 2004/09/01 00:00:00 djbarnes Exp $");

/*
 * Device driver for Fujitsu mb86950 based Ethernet cards.
 * Adapted by Dave J. Barnes from various Internet sources including
 * mb86960.c (NetBSD), if_qn.c (NetBSD/Amiga), DOS Packet Driver (Brian Fisher,
 * Queens University), EtherBoot Driver (Ken Yap).
 */

/* XXX There are still rough edges......

 * (1) There is no watchdog timer for the transmitter. It's doubtful that
 * transmit from the chip could be restarted without a hardware reset though.
Fixed - not fully tested

 * (2) The media interface callback goo is broke.  No big deal since to change
 * from aui to bnc on the old Tiara LANCard requires moving 8 board jumpers.
 * Other cards (SMC ?) using the EtherStar chip may support media change via software.
Fixed - tested

 * (3) The maximum outstanding transmit packets is set to 4.  What is a good limit
 * of outstanding transmit packets for the EtherStar?  Is there a way to tell how
 * many bytes are remaining to be transmitted? [no]
---
	When the EtherStar was designed, CPU power was a fraction of what it is now.  The
	single EtherStar transmit buffer was fine.  It was unlikely that the CPU could
	outrun the EtherStar. However, things in 2004 are quite different.  sc->txb_size
	is used to keep the CPU from overrunning the EtherStar.  At most allow one packet
	transmitting and one going into the fifo.
---
    No, that isn't right either :(

 * (4) Multicast isn't supported.  Feel free to add multicast code if you know how
 * to make the EtherStar do multicast.  Otherwise you'd have to use promiscuous mode
 * and do multicast in software. OUCH!

 * (5) There are no bus_space_barrier calls used. Are they needed? Maybe not.

 * (6) Access to the fifo assumes word (16 bit) mode.  Cards configured for byte
 * wide fifo access will require driver code changes.

 * Only the minimum code necessary to make the Tiara LANCard work has been tested.
 * Other cards may require more work, especially byte mode fifo and if DMA is used.

 * djb / 2004

 */

#include "opt_inet.h"
#include "opt_ns.h"
#include "bpfilter.h"
#include "rnd.h"

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/syslog.h>
#include <sys/device.h>
#if NRND > 0
#include <sys/rnd.h>
#endif

#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/if_media.h>
#include <net/if_ether.h>

#ifdef INET
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/if_inarp.h>
#endif

#ifdef NS
#include <netns/ns.h>
#include <netns/ns_if.h>
#endif

#if NBPFILTER > 0
#include <net/bpf.h>
#include <net/bpfdesc.h>
#endif

#include <machine/bus.h>

#include <dev/ic/mb86950reg.h>
#include <dev/ic/mb86950var.h>

#ifndef __BUS_SPACE_HAS_STREAM_METHODS
#define bus_space_write_stream_2	bus_space_write_2
#define bus_space_write_multi_stream_2	bus_space_write_multi_2
#define bus_space_read_multi_stream_2	bus_space_read_multi_2
#endif /* __BUS_SPACE_HAS_STREAM_METHODS */

/* Standard driver entry points.  These can be static. */
int		mb86950_ioctl	__P((struct ifnet *, u_long, caddr_t));
void	mb86950_init	__P((struct mb86950_softc *));
void	mb86950_start	__P((struct ifnet *));
void	mb86950_watchdog __P((struct ifnet *));
void	mb86950_reset	__P((struct mb86950_softc *));

/* Local functions. */
void	mb86950_stop __P((struct mb86950_softc *));
void	mb86950_tint __P((struct mb86950_softc *, u_int8_t));
void	mb86950_rint __P((struct mb86950_softc *, u_int8_t));
int		mb86950_get_fifo __P((struct mb86950_softc *, u_int));
ushort	mb86950_put_fifo __P((struct mb86950_softc *, struct mbuf *));
void	mb86950_drain_fifo __P((struct mb86950_softc *));

int		mb86950_mediachange __P((struct ifnet *));
void	mb86950_mediastatus __P((struct ifnet *, struct ifmediareq *));


#if ESTAR_DEBUG >= 1
void	mb86950_dump __P((int, struct mb86950_softc *));
#endif

/********************************************************************/

void
mb86950_attach(sc, myea)
	struct mb86950_softc *sc;
	u_int8_t *myea;
{

#ifdef DIAGNOSTIC
	if (myea == NULL) {
		printf("%s: ethernet address shouldn't be NULL\n",
		    sc->sc_dev.dv_xname);
		panic("NULL ethernet address");
	}
#endif

	/* Initialize 86950. */
	mb86950_stop(sc);

	memcpy(sc->sc_enaddr, myea, sizeof(sc->sc_enaddr));

	sc->sc_stat |= ESTAR_STAT_ENABLED;
}

/*
 * Stop everything on the interface.
 *
 * All buffered packets, both transmitting and receiving,
 * if any, will be lost by stopping the interface.
 */
void
mb86950_stop(sc)
	struct mb86950_softc *sc;
{
	bus_space_tag_t bst = sc->sc_bst;
	bus_space_handle_t bsh = sc->sc_bsh;

	/* Stop interface hardware. */
	bus_space_write_1(bst, bsh, DLCR_CONFIG, DISABLE_DLC);
	delay(200);

	/* Disable interrupts. */
	bus_space_write_1(bst, bsh, DLCR_TX_INT_EN, 0);
	bus_space_write_1(bst, bsh, DLCR_RX_INT_EN, 0);

	/* Ack / Clear all interrupt status. */
	bus_space_write_1(bst, bsh, DLCR_TX_STAT, 0xff);
	bus_space_write_1(bst, bsh, DLCR_RX_STAT, 0xff);

	/* Clear DMA Bit */
    bus_space_write_2(bst, bsh, BMPR_DMA, 0);

    /* accept no packets */
	bus_space_write_1(bst, bsh, DLCR_TX_MODE, 0);
	bus_space_write_1(bst, bsh, DLCR_RX_MODE, 0);

    mb86950_drain_fifo(sc);

}

void
mb86950_drain_fifo(sc)
	struct mb86950_softc *sc;
{
	bus_space_tag_t bst = sc->sc_bst;
	bus_space_handle_t bsh = sc->sc_bsh;

/* XXX There ought to be a better way, eats CPU and bothers the chip ....... */
	/* Read data until bus read error (i.e. buffer empty). */
	while (!(bus_space_read_1(bst, bsh, DLCR_RX_STAT) & RX_BUS_RD_ERR))
		bus_space_read_2(bst, bsh, BMPR_FIFO);
/* XXX                                        */

	/* Clear Bus Rd Error */
	bus_space_write_1(bst, bsh, DLCR_RX_STAT, RX_BUS_RD_ERR);
}

/*
 * Install interface into kernel networking data structures
 */
void
mb86950_config(sc, media, nmedia, defmedia)
	struct mb86950_softc *sc;
	int *media, nmedia, defmedia;
{
/* XXX
	struct cfdata *cf = sc->sc_dev.dv_cfdata;
*/
	struct ifnet *ifp = &sc->sc_ec.ec_if;
	bus_space_tag_t bst = sc->sc_bst;
	bus_space_handle_t bsh = sc->sc_bsh;
/*
	int buf_config;
*/

	/* Initialize ifnet structure. */
	strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
	ifp->if_softc = sc;
	ifp->if_start = mb86950_start;
	ifp->if_ioctl = mb86950_ioctl;
	ifp->if_watchdog = mb86950_watchdog;
	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;

	IFQ_SET_READY(&ifp->if_snd);

	/* Initialize media goo. */
	/* XXX The Tiara LANCard uses board jumpers to change media.
	 *       This code may have to be changed for other cards.
	 */
	ifmedia_init(&sc->sc_media, 0, mb86950_mediachange, mb86950_mediastatus);
	ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_MANUAL, 0, NULL);
	ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_MANUAL);

	/* Attach the interface. */
	if_attach(ifp);

	/* Feed the chip the station address. */
	bus_space_write_region_1(bst, bsh, DLCR_NODE_ID, sc->sc_enaddr, ETHER_ADDR_LEN);

	ether_ifattach(ifp, sc->sc_enaddr);

#if NRND > 0
	rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
	    RND_TYPE_NET, 0);
#endif

/* XXX No! This doesn't work - DLCR6 of the mb86950 is different

	bus_space_write_1(bst, bsh, DLCR_CONFIG, 0x0f);
	buf_config = bus_space_read_1(bst, bsh, DLCR_CONFIG);

	sc->txb_count = ((buf_config & 0x0c) ? 2 : 1);
	sc->txb_size = 1024 * (2 << ((buf_config & 0x0c) ? (((buf_config & 0x0c) >> 2) - 1) : 0));
	sc->txb_free = (sc->txb_size * sc->txb_count) / 1500;

  	sc->rxb_size = ((8 << (buf_config & 3)) * 1024) - (sc->txb_size * sc->txb_count);
	sc->rxb_max = sc->rxb_size / 64;

	printf("mb86950: Buffer Size %dKB with %d transmit buffer(s) %dKB each.\n",
		(8 << (buf_config & 3)), sc->txb_count,	(sc->txb_size / 1024));
	printf("         Transmit Buffer Space for %d maximum sized packet(s).\n",sc->txb_free);
	printf("         System Bus Width %d bits, Buffer Memory %d bits.\n",
		((buf_config & 0x20) ? 8 : 16),
		((buf_config & 0x10) ? 8 : 16));

*/

/* Set reasonable values for number of packet flow control if not set elsewhere */
	if (sc->txb_num_pkt == 0) sc->txb_num_pkt = 1;
	if (sc->rxb_num_pkt == 0) sc->rxb_num_pkt = 100;

	/* Print additional info when attached. */
	printf("%s: Ethernet address %s\n", sc->sc_dev.dv_xname, ether_sprintf(sc->sc_enaddr));

	/* The attach is successful. */
	sc->sc_stat |= ESTAR_STAT_ATTACHED;
}

/*
 * Media change callback.
 */
int
mb86950_mediachange(ifp)
	struct ifnet *ifp;
{

	struct mb86950_softc *sc = ifp->if_softc;

	if (sc->sc_mediachange)
		return ((*sc->sc_mediachange)(sc));

	return (0);
}

/*
 * Media status callback.
 */
void
mb86950_mediastatus(ifp, ifmr)
	struct ifnet *ifp;
	struct ifmediareq *ifmr;
{
	struct mb86950_softc *sc = ifp->if_softc;

	if ((sc->sc_stat & ESTAR_STAT_ENABLED) == 0) {
		ifmr->ifm_active = IFM_ETHER | IFM_NONE;
		ifmr->ifm_status = 0;
		return;
	}

	if (sc->sc_mediastatus)
		(*sc->sc_mediastatus)(sc, ifmr);

}

/*
 * Reset interface.
 */
void
mb86950_reset(sc)
	struct mb86950_softc *sc;
{
	int s;

	s = splnet();
	log(LOG_ERR, "%s: device reset\n", sc->sc_dev.dv_xname);
	mb86950_stop(sc);
	mb86950_init(sc);
	splx(s);
}

/*
 * Device timeout/watchdog routine. Entered if the device neglects to
 * generate an interrupt after a transmit has been started on it.
 */
void
mb86950_watchdog(ifp)
	struct ifnet *ifp;
{
	struct mb86950_softc *sc = ifp->if_softc;
	bus_space_tag_t bst = sc->sc_bst;
	bus_space_handle_t bsh = sc->sc_bsh;
	u_int8_t tstat;

	/* verbose watchdog messages for debugging timeouts */
    if ((tstat = bus_space_read_1(bst, bsh, DLCR_TX_STAT)) != 0) {
		if (tstat & TX_CR_LOST) {
			if ((tstat & (TX_COL | TX_16COL)) == 0) log(LOG_ERR, "%s: carrier lost\n", sc->sc_dev.dv_xname);
			else log(LOG_ERR, "%s: excessive collisions\n", sc->sc_dev.dv_xname);
		}
		else if ((tstat & (TX_UNDERFLO | TX_BUS_WR_ERR)) != 0) log(LOG_ERR, "%s: tx fifo underflow/overflow\n", sc->sc_dev.dv_xname);
		else log(LOG_ERR, "%s: transmit error\n", sc->sc_dev.dv_xname);
	}
	else
		log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);

	/* Don't know how many packets are lost by this accident.
	 *  ... So just errors = errors + 1
	 */
	ifp->if_oerrors++;

	mb86950_reset(sc);

}

/*
 ******************** IOCTL
 * Process an ioctl request.
 */
int
mb86950_ioctl(ifp, cmd, data)
	struct ifnet *ifp;
	u_long cmd;
	caddr_t data;
{
	struct mb86950_softc *sc = ifp->if_softc;
	struct ifaddr *ifa = (struct ifaddr *)data;
	struct ifreq *ifr = (struct ifreq *)data;

	int s, error = 0;

	s = splnet();

	switch (cmd) {
	case SIOCSIFADDR:
		/* XXX depreciated ? What should I use instead? */
		if ((error = mb86950_enable(sc)) != 0)
			break;

		ifp->if_flags |= IFF_UP;

		switch (ifa->ifa_addr->sa_family) {

#ifdef INET
		case AF_INET:
			mb86950_init(sc);
			arp_ifinit(ifp, ifa);
			break;
#endif

#ifdef NS
		case AF_NS:
		    {
			struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;

			if (ns_nullhost(*ina))
				ina->x_host = *(union ns_host *)LLADDR(ifp->if_sadl);
			else {
				memcpy(LLADDR(ifp->if_sadl), ina->x_host.c_host, ETHER_ADDR_LEN);
			}
			/* Set new address. */
			mb86950_init(sc);
			break;
		    }
#endif

		default:
			mb86950_init(sc);
			break;
		}
		break;

	case SIOCSIFFLAGS:
		if ((ifp->if_flags & IFF_UP) == 0 &&
		    (ifp->if_flags & IFF_RUNNING) != 0) {
			/*
			 * If interface is marked down and it is running, then
			 * stop it.
			 */
			mb86950_stop(sc);
			ifp->if_flags &= ~IFF_RUNNING;
			mb86950_disable(sc);

		} else if ((ifp->if_flags & IFF_UP) != 0 &&
			(ifp->if_flags & IFF_RUNNING) == 0) {
			/*
			 * If interface is marked up and it is stopped, then
			 * start it.
			 */
			if ((error = mb86950_enable(sc)) != 0)
				break;
			mb86950_init(sc);

		} else if ((ifp->if_flags & IFF_UP) != 0) {
			/*
			 * Reset the interface to pick up changes in any other
			 * flags that affect hardware registers.
			 */
/* Setmode not supported
			mb86950_setmode(sc);
*/
		}

#if ESTAR_DEBUG >= 1
		/* "ifconfig fe0 debug" to print register dump. */
		if (ifp->if_flags & IFF_DEBUG) {
			log(LOG_INFO, "%s: SIOCSIFFLAGS(DEBUG)\n",
			    sc->sc_dev.dv_xname);
			mb86950_dump(LOG_DEBUG, sc);
		}
#endif
		break;

	case SIOCGIFMEDIA:
	case SIOCSIFMEDIA:
		error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
		break;

	default:
		error = EINVAL;
		break;
	}

	splx(s);
	return (error);
}

/*
 * Initialize device.
 */
void
mb86950_init(sc)
	struct mb86950_softc *sc;
{
	bus_space_tag_t bst = sc->sc_bst;
	bus_space_handle_t bsh = sc->sc_bsh;
	struct ifnet *ifp = &sc->sc_ec.ec_if;

	/* Reset transmitter flags. */
	ifp->if_flags &= ~IFF_OACTIVE;
	ifp->if_timer = 0;
	sc->txb_sched = 0;

	bus_space_write_1(bst, bsh, DLCR_TX_MODE, LBC);
	bus_space_write_1(bst, bsh, DLCR_RX_MODE, NORMAL_MODE);

	/* Enable interrupts. */
	bus_space_write_1(bst, bsh, DLCR_TX_INT_EN, TX_MASK);
	bus_space_write_1(bst, bsh, DLCR_RX_INT_EN, RX_MASK);

	/* Enable transmitter and receiver. */
	bus_space_write_1(bst, bsh, DLCR_CONFIG, ENABLE_DLC);
	delay(200);

	/* Set 'running' flag. */
	ifp->if_flags |= IFF_RUNNING;

	/* ...and attempt to start output. */
	mb86950_start(ifp);

}

void
mb86950_start(ifp)
	struct ifnet *ifp;
{
	struct mb86950_softc *sc = ifp->if_softc;
    bus_space_tag_t bst = sc->sc_bst;
    bus_space_handle_t bsh = sc->sc_bsh;
	struct mbuf *m;
	int len;

	if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
		return;

	IF_DEQUEUE(&ifp->if_snd, m);
	if (m == 0)
		return;

#if NBPFILTER > 0
	/* Tap off here if there is a BPF listener. */
	if (ifp->if_bpf)
		bpf_mtap(ifp->if_bpf, m);
#endif

    /* Send the packet to the mb86950 */
	len = mb86950_put_fifo(sc,m);
	m_freem(m);

/* XXX bus_space_barrier here ? */
	if (bus_space_read_1(bst, bsh, DLCR_TX_STAT) & (TX_UNDERFLO | TX_BUS_WR_ERR)) {
		log(LOG_ERR, "%s: tx fifo underflow/overflow\n", sc->sc_dev.dv_xname);
	}

	bus_space_write_2(bst, bsh, BMPR_TX_LENGTH, len | TRANSMIT_START);

	bus_space_write_1(bst, bsh, DLCR_TX_INT_EN, TX_MASK);
/* XXX                          */
	sc->txb_sched++;

	/* We have space for 'n' transmit packets of size 'mtu. */
	if (sc->txb_sched > sc->txb_num_pkt) {
		ifp->if_flags |= IFF_OACTIVE;
		ifp->if_timer = 2;
	}
}

/*
 * ********************  SEND PACKET
 * Copy packet from mbuf to the fifo
 */
u_short
mb86950_put_fifo(sc, m)
	struct mb86950_softc *sc;
	struct mbuf *m;
{
	bus_space_tag_t bst = sc->sc_bst;
	bus_space_handle_t bsh = sc->sc_bsh;
	u_short *data;
	u_char savebyte[2];
	int len, len1, wantbyte;
	u_short totlen;

	totlen = wantbyte = 0;

	for (; m != NULL; m = m->m_next) {
		data = mtod(m, u_short *);
		len = m->m_len;
		if (len > 0) {
			totlen += len;

			/* Finish the last word. */
			if (wantbyte) {
				savebyte[1] = *((u_char *)data);
				bus_space_write_2(bst, bsh, BMPR_FIFO, *savebyte);
				((u_char *)data)++;
				len--;
				wantbyte = 0;
			}
			/* Output contiguous words. */
			if (len > 1) {
				len1 = len/2;
				bus_space_write_multi_stream_2(bst, bsh, BMPR_FIFO, data, len1);
				data += len1;
				len &= 1;
			}
			/* Save last byte, if necessary. */
			if (len == 1) {
				savebyte[0] = *((u_char *)data);
				wantbyte = 1;
			}
		}
	}

	if (wantbyte) {
		savebyte[1] = 0;
		bus_space_write_2(bst, bsh, BMPR_FIFO, *savebyte);
	}

	if (totlen < (ETHER_MIN_LEN - ETHER_CRC_LEN)) {

		/* Fill the rest of the packet with zeros. */
/*
		len1 = (ETHER_MIN_LEN - ETHER_CRC_LEN - totlen + 1) / 2;
*/
/* XXX Replace this mess with something else, eats CPU */
/* The zero fill and last byte ought to be combined somehow */
		for(len = totlen + 1; len < (ETHER_MIN_LEN - ETHER_CRC_LEN); len += 2)
	  		bus_space_write_2(bst, bsh, BMPR_FIFO, 0);
/* XXX                                       */

		totlen = (ETHER_MIN_LEN - ETHER_CRC_LEN);
	}

	return (totlen);
}

/*
 ****************************  INTERRUPTS
 * Ethernet interface interrupt processor
 */
int
mb86950_intr(arg)
	void *arg;
{
	struct mb86950_softc *sc = arg;
	bus_space_tag_t bst = sc->sc_bst;
	bus_space_handle_t bsh = sc->sc_bsh;
	struct ifnet *ifp = &sc->sc_ec.ec_if;
	u_int8_t tstat, rstat;

	/* Get interrupt status. */
	tstat = bus_space_read_1(bst, bsh, DLCR_TX_STAT);
	rstat = bus_space_read_1(bst, bsh, DLCR_RX_STAT);

	if (tstat == 0 && rstat == 0) return (0);

	/* Disable etherstar interrupts so that we won't miss anything. */
	bus_space_write_1(bst, bsh, DLCR_TX_INT_EN, 0);
	bus_space_write_1(bst, bsh, DLCR_RX_INT_EN, 0);

	/*
	 * Handle transmitter interrupts. Handle these first because
	 * the receiver will reset the board under some conditions.
	 */
	if (tstat != 0) {

		mb86950_tint(sc, tstat);

		/* acknowledge transmit interrupt status. */
		bus_space_write_1(bst, bsh, DLCR_TX_STAT, tstat);

	}

	/* Handle receiver interrupts. */
	if (rstat != 0) {

		mb86950_rint(sc, rstat);

		/* acknowledge receive interrupt status. */
		bus_space_write_1(bst, bsh, DLCR_RX_STAT, rstat);

	}

	/* If tx still pending reset tx interrupt mask */
	if (sc->txb_sched > 0) bus_space_write_1(bst, bsh, DLCR_TX_INT_EN, TX_MASK);

	/*
	 * If it looks like the transmitter can take more data,
	 * attempt to start output on the interface. This is done
	 * after handling the receiver interrupt to give the
	 * receive operation priority.
	 */

	if ((ifp->if_flags & IFF_OACTIVE) == 0)
		mb86950_start(ifp);

	/* Set receive interrupts back */
	bus_space_write_1(bst, bsh, DLCR_RX_INT_EN, RX_MASK);

	return(1);
}

/* Transmission interrupt handler */
void
mb86950_tint(sc, tstat)
	struct mb86950_softc *sc;
	u_int8_t tstat;
{
	bus_space_tag_t bst = sc->sc_bst;
	bus_space_handle_t bsh = sc->sc_bsh;
	struct ifnet *ifp = &sc->sc_ec.ec_if;
	int col;

	if (tstat & (TX_UNDERFLO | TX_BUS_WR_ERR)) {
		/* XXX What do we need to do here? reset ? */
		ifp->if_oerrors++;
	}

	/* excessive collision */
	if (tstat & TX_16COL) {
		ifp->if_collisions += 16;
		/* 16 collisions means that the packet has been thrown away. */
		if (sc->txb_sched > 0) sc->txb_sched--;
	}

	/* transmission complete. */
	if (tstat & TX_DONE) {
		/* successfully transmitted packets ++. */
		ifp->if_opackets++;
		if (sc->txb_sched > 0) sc->txb_sched--;

		/* Collision count valid only when TX_DONE is set */
		if (tstat & TX_COL) {
			col = (bus_space_read_1(bst, bsh, DLCR_TX_MODE) & COL_MASK) >> 4;
			ifp->if_collisions = ifp->if_collisions + col;
		}
	}

	if (sc->txb_sched == 0) {
		 /* Reset output active flag and stop timer. */
		 ifp->if_flags &= ~IFF_OACTIVE;
		 ifp->if_timer = 0;
	}
}

/* receiver interrupt. */
void
mb86950_rint(sc, rstat)
	struct mb86950_softc *sc;
	u_int8_t rstat;
{
	bus_space_tag_t bst = sc->sc_bst;
	bus_space_handle_t bsh = sc->sc_bsh;
	struct ifnet *ifp = &sc->sc_ec.ec_if;
	u_int status, len;
	int i;

	 /* Update statistics if this interrupt is caused by an error. */
	 if (rstat & RX_ERR_MASK) {

		/* tried to read past end of fifo, should be harmless
		 * count everything else
		 */
		if ((rstat & RX_BUS_RD_ERR) == 0) {
			ifp->if_ierrors++;
		}
	}

	/*
	 * mb86950 has a flag indicating "receive buffer empty."
	 * We just loop checking the flag to pull out all received
	 * packets.
	 *
	 * We limit the number of iterrations to avoid infinite loop.
	 * It can be caused by a very slow CPU (some broken
	 * peripheral may insert incredible number of wait cycles)
	 * or, worse, by a broken mb86950 chip.
	 */
	for (i = 0; i < sc->rxb_num_pkt; i++) {
		/* Stop the iterration if 86950 indicates no packets. */
		if (bus_space_read_1(bst, bsh, DLCR_RX_MODE) & RX_BUF_EMTY)
			break;

		/* receive packet status */
		status = bus_space_read_2(bst, bsh, BMPR_FIFO);

		/* bad packet? */
		if ((status & GOOD_PKT) == 0) {
			ifp->if_ierrors++;
			mb86950_drain_fifo(sc);
			continue;
		}

		/* Length valid ? */
		len = bus_space_read_2(bst, bsh, BMPR_FIFO);

		if (len > (ETHER_MAX_LEN - ETHER_CRC_LEN) || len < ETHER_HDR_LEN) {
			ifp->if_ierrors++;
			mb86950_drain_fifo(sc);
			continue;
		}

		if (mb86950_get_fifo(sc, len) != 0) {
			/* No mbufs? Drop packet. */
			ifp->if_ierrors++;
			mb86950_drain_fifo(sc);
			return;
		}

		/* Successfully received a packet.  Update stat. */
		ifp->if_ipackets++;
	}
}

/*
 * *********************  RECEIVE PACKET
 * Retrieve packet from receive buffer and send to the next level up via
 * ether_input(). If there is a BPF listener, give a copy to BPF, too.
 * Returns 0 if success, -1 if error (i.e., mbuf allocation failure).
 */
int
mb86950_get_fifo(sc, len)
	struct mb86950_softc *sc;
	u_int len;
{
	bus_space_tag_t bst = sc->sc_bst;
	bus_space_handle_t bsh = sc->sc_bsh;
	struct ifnet *ifp = &sc->sc_ec.ec_if;
	struct mbuf *m;

	/* Allocate a header mbuf. */
	MGETHDR(m, M_DONTWAIT, MT_DATA);
	if (m == 0)
		return (-1);

	/*
	 * Round len to even value.
	 */
	if (len & 1)
		len++;

	m->m_pkthdr.rcvif = ifp;
	m->m_pkthdr.len = len;

	/* The following silliness is to make NFS happy. */
#define	EROUND	((sizeof(struct ether_header) + 3) & ~3)
#define	EOFF	(EROUND - sizeof(struct ether_header))

	/*
	 * Our strategy has one more problem.  There is a policy on
	 * mbuf cluster allocation.  It says that we must have at
	 * least MINCLSIZE (208 bytes) to allocate a cluster.  For a
	 * packet of a size between (MHLEN - 2) to (MINCLSIZE - 2),
	 * our code violates the rule...
	 * On the other hand, the current code is short, simple,
	 * and fast, however.  It does no harmful thing, just wastes
	 * some memory.  Any comments?  FIXME.
	 */

	/* Attach a cluster if this packet doesn't fit in a normal mbuf. */
	if (len > MHLEN - EOFF) {
		MCLGET(m, M_DONTWAIT);
		if ((m->m_flags & M_EXT) == 0) {
			m_freem(m);
			return (-1);
		}
	}

	/*
	 * The following assumes there is room for the ether header in the
	 * header mbuf.
	 */
	m->m_data += EOFF;

	/* Set the length of this packet. */
	m->m_len = len;

	/* Get a packet. */
	bus_space_read_multi_stream_2(bst, bsh, BMPR_FIFO, mtod(m, u_int16_t *), (len + 1) >> 1);

#if NBPFILTER > 0
	/*
	 * Check if there's a BPF listener on this interface.  If so, hand off
	 * the raw packet to bpf.
	 */
	if (ifp->if_bpf)
		bpf_mtap(ifp->if_bpf, m);
#endif

	(*ifp->if_input)(ifp, m);
	return (0);
}

/*
 * Enable power on the interface.
 */
int
mb86950_enable(sc)
	struct mb86950_softc *sc;
{

	if ((sc->sc_stat & ESTAR_STAT_ENABLED) == 0 && sc->sc_enable != NULL) {
		if ((*sc->sc_enable)(sc) != 0) {
			printf("%s: device enable failed\n",
			    sc->sc_dev.dv_xname);
			return (EIO);
		}
	}

	sc->sc_stat |= ESTAR_STAT_ENABLED;
	return (0);
}

/*
 * Disable power on the interface.
 */
void
mb86950_disable(sc)
	struct mb86950_softc *sc;
{

	if ((sc->sc_stat & ESTAR_STAT_ENABLED) != 0 && sc->sc_disable != NULL) {
		(*sc->sc_disable)(sc);
		sc->sc_stat &= ~ESTAR_STAT_ENABLED;
	}
}

/*
 * mbe_activate:
 *
 *	Handle device activation/deactivation requests.
 */
int
mb86950_activate(self, act)
	struct device *self;
	enum devact act;
{
	struct mb86950_softc *sc = (struct mb86950_softc *)self;
	int rv, s;

	rv = 0;
	s = splnet();
	switch (act) {
	case DVACT_ACTIVATE:
		rv = EOPNOTSUPP;
		break;

	case DVACT_DEACTIVATE:
		if_deactivate(&sc->sc_ec.ec_if);
		break;
	}
	splx(s);
	return (rv);
}

/*
 * mb86950_detach:
 *
 *	Detach a mb86950 interface.
 */
int
mb86950_detach(sc)
	struct mb86950_softc *sc;
{
	struct ifnet *ifp = &sc->sc_ec.ec_if;

	/* Succeed now if there's no work to do. */
	if ((sc->sc_stat & ESTAR_STAT_ATTACHED) == 0)
		return (0);

	/* Delete all media. */
	ifmedia_delete_instance(&sc->sc_media, IFM_INST_ANY);

#if NRND > 0
	/* Unhook the entropy source. */
	rnd_detach_source(&sc->rnd_source);
#endif
	ether_ifdetach(ifp);
	if_detach(ifp);

	return (0);
}

#if ESTAR_DEBUG >= 1
void
mb86950_dump(level, sc)
	int level;
	struct mb86950_softc *sc;
{
	bus_space_tag_t bst = sc->sc_bst;
	bus_space_handle_t bsh = sc->sc_bsh;

	log(level, "\tDLCR = %02x %02x %02x %02x %02x %02x %02x\n",
	    bus_space_read_1(bst, bsh, DLCR_TX_STAT),
	    bus_space_read_1(bst, bsh, DLCR_TX_INT_EN),
	    bus_space_read_1(bst, bsh, DLCR_RX_STAT),
	    bus_space_read_1(bst, bsh, DLCR_RX_INT_EN),
	    bus_space_read_1(bst, bsh, DLCR_TX_MODE),
	    bus_space_read_1(bst, bsh, DLCR_RX_MODE),
	    bus_space_read_1(bst, bsh, DLCR_CONFIG));

/* XXX BMPR2, 4 write only ?
	log(level, "\tBMPR = xxxx %04x %04x\n",
		bus_space_read_2(bst, bsh, BMPR_TX_LENGTH),
		bus_space_read_2(bst, bsh, BMPR_DMA));
*/

}
#endif

========================= /usr/src/sys/dev/ic/mb86950reg.h =============
/*	$NetBSD: mb86950reg.h,v 1.0 2004/09/01 00:00:00 djbarnes Exp $	*/

/*
 * Copyright (c) 1995 Mika Kortelainen
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by  Mika Kortelainen
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Adapted from if_qnreg.h for the amiga port of NetBSD by Dave J. Barnes, 2004.
 */

/*
 *  The Fujitsu mb86950, "EtherStar", is the predecessor to the mb8696x NICE supported
 *  by the ate driver.  While similar in function and programming to the mb8696x, the register offset
 *  differences and quirks make it nearly impossible to have one driver for both the
 *  EtherStar and NICE chips.
 *
 *  Definitions from Fujitsu documentation.
 */

#define ESTAR_DLCR0		0 /* Transmit status */
#define DLCR_TX_STAT	ESTAR_DLCR0

#define ESTAR_DLCR1		1 /* Transmit masks  */
#define DLCR_TX_INT_EN	ESTAR_DLCR1

/* DLCR0/1 - Transmit Status & Masks */
#define TX_DONE			0x80 /* Transmit okay         */
/* bit 6 - Net Busy, carrier sense ? */
/* bit 5 - Transmit packet received ? */
#define TX_CR_LOST		0x10 /* Carrier lost while attempting to transmit */
#define TX_UNDERFLO		0x08 /* fifo underflow */
#define TX_COL			0x04 /* Collision             */
#define TX_16COL		0x02 /* 16 collision          */
#define TX_BUS_WR_ERR	0x01 /* Bus write error, fifo overflo */
#define CLEAR_TX_ERR	(TX_UNDERFLO | TX_COL | TX_16COL | TX_BUS_WR_ERR) /* Clear transmit errors */
#define TX_MASK         (TX_DONE | TX_16COL)

#define ESTAR_DLCR2		2 /* Receive status  */
#define DLCR_RX_STAT	ESTAR_DLCR2

#define ESTAR_DLCR3		3 /* Receive masks   */
#define DLCR_RX_INT_EN	ESTAR_DLCR3

/* DLCR2/3 - Receive Status & Masks */
#define RX_PKT			0x80 /* Packet ready          */
#define RX_BUS_RD_ERR   0x40 /* fifo underflow, harmless, normally masked off */
/* bit 5 - DMA end of process ? */
/* bit 4 - remote control packet rx ? */
#define RX_SHORT_ERR	0x08 /* Short packet          */
#define RX_ALIGN_ERR	0x04 /* Alignment error       */
#define RX_CRC_ERR		0x02 /* CRC error             */
#define RX_OVERFLO		0x01 /* Receive buf overflow  */
#define CLEAR_RX_ERR	RX_MASK /* Clear receive and errors  */
#define	RX_MASK			(RX_PKT | RX_SHORT_ERR | RX_ALIGN_ERR | RX_CRC_ERR | RX_OVERFLO | RX_BUS_RD_ERR)
#define RX_ERR_MASK  	(RX_SHORT_ERR | RX_ALIGN_ERR | RX_CRC_ERR | RX_OVERFLO | RX_BUS_RD_ERR)

#define ESTAR_DLCR4		4 /* Transmit mode   */
#define DLCR_TX_MODE	ESTAR_DLCR4

/* DLCR4 - Transmit Mode */
/* bits 7, 6, 5, 4 - collision count ? */
#define COL_MASK		0xf0
/* bit 3 - nc */
/* bit 2 - gen output ? */
#define LBC				0x02 /* Loopback control      */
/* bit 0 - defer ?, normally 0 */

#define ESTAR_DLCR5		5 /* Receive mode    */
#define DLCR_RX_MODE	ESTAR_DLCR5

/* DLCR5 - Receive Mode */
/* Normal mode: accept physical address, broadcast address.
 */
/* bit 7 - Disable CRC test mode */
#define RX_BUF_EMTY		0x40 /* Buffer empty          */
/* bit 5 - accept packet with errors or nc ?, normally set to 0 */
/* bit 4 - 40 bit address ?, normally set to 0 */
/* bit 3 - accept runts ?, normally set to 0 */
/* bit 2 - remote reset ? normally set to 0 */
/* bit 1 & 0 - address filter mode */

/*  00 = reject */
/*  01 = normal mode */
#define NORMAL_MODE		0x01
/*  10 = ? */
/*  11 = promiscuous mode */
#define PROMISCUOUS_MODE	0x03 /* Accept all packets    */

#define ESTAR_DLCR6		6 /* Software reset  */
#define DLCR_CONFIG		ESTAR_DLCR6

/* DLCR6 - Enable Data Link Controller */
#define DISABLE_DLC		0x80 /* Disable data link controller */
#define ENABLE_DLC		0x00 /* Enable data link controller  */

#define ESTAR_DLCR7		7 /* TDR (LSB)       */

#define ESTAR_DLCR8		8 /* Node ID0        */
#define DLCR_NODE_ID	ESTAR_DLCR8

#define ESTAR_DLCR9		9 /* Node ID1        */
#define ESTAR_DLCR10	10 /* Node ID2        */
#define ESTAR_DLCR11	11 /* Node ID3        */
#define ESTAR_DLCR12	12 /* Node ID4        */
#define ESTAR_DLCR13	13 /* Node ID5        */

#define ESTAR_DLCR15	15 /* TDR (MSB)       */

/* The next three are usually accessed as words */
#define ESTAR_BMPR0		16 /* Buffer memory port (FIFO) */
#define BMPR_FIFO		ESTAR_BMPR0

#define ESTAR_BMPR2		18 /* Packet length   */
#define BMPR_TX_LENGTH	ESTAR_BMPR2
/* BMPR2:BMPR3 - Packet Length Registers (Write-only) */
#define TRANSMIT_START	0x8000

#define ESTAR_BMPR4		20 /* DMA enable      */
#define BMPR_DMA		ESTAR_BMPR4

========================= /usr/src/sys/dev/ic/mb86950var.h =============
/*	$NetBSD: mb86950var.h,v 1.0 2004/09/01 00:00:00 djbarnes Exp $	*/

/*
 * Copyright (c) 1995 Mika Kortelainen
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by  Mika Kortelainen
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Adapted from if_qnreg.h for the amiga port of NetBSD by Dave J. Barnes, 2004.
 */

/*
 * EStar_softc: per line info and status
 */
struct mb86950_softc {
	struct device sc_dev;
	struct ethercom sc_ec;		/* ethernet common */
	struct ifmedia sc_media;	/* supported media information */

	bus_space_tag_t sc_bst;		/* bus space */
	bus_space_handle_t sc_bsh;

	/* Transmission buffer management. */
    /* XXX not used */
	int	txb_free;	/* free TX buffers */
	int	txb_size;	/* total size of TX buffer */
	int	txb_count;	/* number of TX buffers in use */
	int	txb_sched;	/* number of scheduled packets */
	int	rxb_size;   /* size of receive buffer */
	/* XXX          */
	int txb_num_pkt;    /* max number of outstanding transmit packets allowed */
	int rxb_num_pkt;    /* max number of packets that could be in receive buffer */

	u_int8_t sc_enaddr[ETHER_ADDR_LEN];

#if NRND > 0
	rndsource_element_t rnd_source;
#endif

	u_int32_t sc_stat;	/* driver status */

#define ESTAR_STAT_ENABLED		0x0001	/* power enabled on interface */
#define ESTAR_STAT_ATTACHED	0x0002	/* attach has succeeded */

	int	(*sc_enable) __P((struct mb86950_softc *));
	void	(*sc_disable) __P((struct mb86950_softc *));

	int	(*sc_mediachange) __P((struct mb86950_softc *));
	void	(*sc_mediastatus) __P((struct mb86950_softc *,
		    struct ifmediareq *));

};

/* Size (in bytes) of a "packet length" word in transmission buffer.  */
#define ESTAR_TXLEN_SIZE 2

#define GOOD_PKT 0x20

void    mb86950_attach  __P((struct mb86950_softc *, u_int8_t *));
void    mb86950_config  __P((struct mb86950_softc *, int *, int, int));
int     mb86950_intr    __P((void *));
int     mb86950_enable  __P((struct mb86950_softc *));
void    mb86950_disable __P((struct mb86950_softc *));
int     mb86950_activate __P((struct device *, enum devact));
int     mb86950_detach  __P((struct mb86950_softc *));

============================== diffs ===================================
--- dev/mca/mcadevs.orig	2004-09-05 20:04:18.000000000 -0500
+++ dev/mca/mcadevs	2004-09-05 20:03:49.000000000 -0500
@@ -116,8 +116,10 @@
 product 0x5EEE "Hitachi CD-ROM Adapter"					[5]
 product 0x5F77 "Future Domain SCSI Adapter"				[5]
 product 0x5FF8 "Plus Passport MC Adapter"				[5]
-product 0x6001 "Tiara LANcard/E Ethernet Adapter"			[1]
+product 0x6000 TIARA "Tiara LANCard/E"
+product 0x6001 TIARA_TP "Tiara LANcard/E Ethernet Adapter"			[1]
 product 0x6014 "Standard Microsystems ARCNET-PS110 Adapter"		[6]
+product 0x6016 SMC3016 "Standard MicroSystems 3016/MC Ethernet"
 product 0x6018 "Gateway Comms. G/Ethernet Adapter"			[6]
 product 0x601F "HP Scanner Interface Adapter"				[5]
 product 0x602F "Arcmaster ARCnet Adapter"				[6]
--- dev/mca/files.mca.orig	2004-09-02 21:47:37.000000000 -0500
+++ dev/mca/files.mca	2004-08-31 10:28:02.000000000 -0500
@@ -60,3 +60,8 @@
 # NCR 53C90
 attach	esp at mca with esp_mca
 file	dev/mca/esp_mca.c		esp_mca
+
+# Tiara LANCard
+device  tra:  ether, ifnet, arp, mb86950
+attach  tra at mca with tra_mca
+file    dev/mca/if_tra_mca.c            tra_mca

--- conf/files.orig	2004-09-05 22:21:34.000000000 -0500
+++ conf/files	2004-09-05 22:20:54.000000000 -0500
@@ -640,6 +640,11 @@
 define	sgec
 file	dev/ic/sgec.c			sgec
 
+# MB86950 Ethernet Controller   
+#
+define  mb86950
+file    dev/ic/mb86950.c                mb86950
+
 # MB8696x Ethernet Controller
 #
 define	mb86960

================================ END ==================================

>Release-Note:
>Audit-Trail:
>Unformatted: