Home | History | Annotate | Line # | Download | only in isa
if_ate.c revision 1.1
      1  1.1  mycroft /*
      2  1.1  mycroft  * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
      3  1.1  mycroft  *
      4  1.1  mycroft  * This software may be used, modified, copied, distributed, and sold, in
      5  1.1  mycroft  * both source and binary form provided that the above copyright, these
      6  1.1  mycroft  * terms and the following disclaimer are retained.  The name of the author
      7  1.1  mycroft  * and/or the contributor may not be used to endorse or promote products
      8  1.1  mycroft  * derived from this software without specific prior written permission.
      9  1.1  mycroft  *
     10  1.1  mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND
     11  1.1  mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     12  1.1  mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     13  1.1  mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE
     14  1.1  mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     15  1.1  mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     16  1.1  mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION.
     17  1.1  mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     18  1.1  mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     19  1.1  mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     20  1.1  mycroft  * SUCH DAMAGE.
     21  1.1  mycroft  */
     22  1.1  mycroft 
     23  1.1  mycroft /*
     24  1.1  mycroft  * Portions copyright (C) 1993, David Greenman.  This software may be used,
     25  1.1  mycroft  * modified, copied, distributed, and sold, in both source and binary form
     26  1.1  mycroft  * provided that the above copyright and these terms are retained.  Under no
     27  1.1  mycroft  * circumstances is the author responsible for the proper functioning of this
     28  1.1  mycroft  * software, nor does the author assume any responsibility for damages
     29  1.1  mycroft  * incurred with its use.
     30  1.1  mycroft  */
     31  1.1  mycroft 
     32  1.1  mycroft #define FE_VERSION "if_fe.c ver. 0.8"
     33  1.1  mycroft 
     34  1.1  mycroft /*
     35  1.1  mycroft  * Device driver for Fujitsu MB86960A/MB86965A based Ethernet cards.
     36  1.1  mycroft  * Contributed by M.S. <seki (at) sysrap.cs.fujitsu.co.jp>
     37  1.1  mycroft  *
     38  1.1  mycroft  * This version is intended to be a generic template for various
     39  1.1  mycroft  * MB86960A/MB86965A based Ethernet cards.  It currently supports
     40  1.1  mycroft  * Fujitsu FMV-180 series (i.e., FMV-181 and FMV-182) and Allied-
     41  1.1  mycroft  * Telesis AT1700 series and RE2000 series.  There are some
     42  1.1  mycroft  * unnecessary hooks embedded, which are primarily intended to support
     43  1.1  mycroft  * other types of Ethernet cards, but the author is not sure whether
     44  1.1  mycroft  * they are useful.
     45  1.1  mycroft  */
     46  1.1  mycroft 
     47  1.1  mycroft #include "bpfilter.h"
     48  1.1  mycroft 
     49  1.1  mycroft #include <sys/param.h>
     50  1.1  mycroft #include <sys/systm.h>
     51  1.1  mycroft #include <sys/errno.h>
     52  1.1  mycroft #include <sys/ioctl.h>
     53  1.1  mycroft #include <sys/mbuf.h>
     54  1.1  mycroft #include <sys/socket.h>
     55  1.1  mycroft #include <sys/syslog.h>
     56  1.1  mycroft #include <sys/device.h>
     57  1.1  mycroft 
     58  1.1  mycroft #include <net/if.h>
     59  1.1  mycroft #include <net/if_dl.h>
     60  1.1  mycroft #include <net/if_types.h>
     61  1.1  mycroft #include <net/netisr.h>
     62  1.1  mycroft 
     63  1.1  mycroft #ifdef INET
     64  1.1  mycroft #include <netinet/in.h>
     65  1.1  mycroft #include <netinet/in_systm.h>
     66  1.1  mycroft #include <netinet/in_var.h>
     67  1.1  mycroft #include <netinet/ip.h>
     68  1.1  mycroft #include <netinet/if_ether.h>
     69  1.1  mycroft #endif
     70  1.1  mycroft 
     71  1.1  mycroft #ifdef NS
     72  1.1  mycroft #include <netns/ns.h>
     73  1.1  mycroft #include <netns/ns_if.h>
     74  1.1  mycroft #endif
     75  1.1  mycroft 
     76  1.1  mycroft #if NBPFILTER > 0
     77  1.1  mycroft #include <net/bpf.h>
     78  1.1  mycroft #include <net/bpfdesc.h>
     79  1.1  mycroft #endif
     80  1.1  mycroft 
     81  1.1  mycroft #include <machine/cpu.h>
     82  1.1  mycroft #include <machine/pio.h>
     83  1.1  mycroft 
     84  1.1  mycroft #include <dev/isa/isareg.h>
     85  1.1  mycroft #include <dev/isa/isavar.h>
     86  1.1  mycroft #include <dev/ic/mb86960.h>
     87  1.1  mycroft #include <dev/isa/if_fereg.h>
     88  1.1  mycroft 
     89  1.1  mycroft /*
     90  1.1  mycroft  * Default settings for fe driver specific options.
     91  1.1  mycroft  * They can be set in config file by "options" statements.
     92  1.1  mycroft  */
     93  1.1  mycroft 
     94  1.1  mycroft /*
     95  1.1  mycroft  * Debug control.
     96  1.1  mycroft  * 0: No debug at all.  All debug specific codes are stripped off.
     97  1.1  mycroft  * 1: Silent.  No debug messages are logged except emergent ones.
     98  1.1  mycroft  * 2: Brief.  Lair events and/or important information are logged.
     99  1.1  mycroft  * 3: Detailed.  Logs all information which *may* be useful for debugging.
    100  1.1  mycroft  * 4: Trace.  All actions in the driver is logged.  Super verbose.
    101  1.1  mycroft  */
    102  1.1  mycroft #ifndef FE_DEBUG
    103  1.1  mycroft #define FE_DEBUG		1
    104  1.1  mycroft #endif
    105  1.1  mycroft 
    106  1.1  mycroft /*
    107  1.1  mycroft  * Delay padding of short transmission packets to minimum Ethernet size.
    108  1.1  mycroft  * This may or may not gain performance.  An EXPERIMENTAL option.
    109  1.1  mycroft  */
    110  1.1  mycroft #ifndef FE_DELAYED_PADDING
    111  1.1  mycroft #define FE_DELAYED_PADDING	0
    112  1.1  mycroft #endif
    113  1.1  mycroft 
    114  1.1  mycroft /*
    115  1.1  mycroft  * Transmit just one packet per a "send" command to 86960.
    116  1.1  mycroft  * This option is intended for performance test.  An EXPERIMENTAL option.
    117  1.1  mycroft  */
    118  1.1  mycroft #ifndef FE_SINGLE_TRANSMISSION
    119  1.1  mycroft #define FE_SINGLE_TRANSMISSION	0
    120  1.1  mycroft #endif
    121  1.1  mycroft 
    122  1.1  mycroft /*
    123  1.1  mycroft  * Device configuration flags.
    124  1.1  mycroft  */
    125  1.1  mycroft 
    126  1.1  mycroft /* DLCR6 settings. */
    127  1.1  mycroft #define FE_FLAGS_DLCR6_VALUE	0x007F
    128  1.1  mycroft 
    129  1.1  mycroft /* Force DLCR6 override. */
    130  1.1  mycroft #define FE_FLAGS_OVERRIDE_DLCR6	0x0080
    131  1.1  mycroft 
    132  1.1  mycroft /* A cludge for PCMCIA support. */
    133  1.1  mycroft #define FE_FLAGS_PCMCIA		0x8000
    134  1.1  mycroft 
    135  1.1  mycroft /* Identification of the driver version. */
    136  1.1  mycroft static char const fe_version[] = FE_VERSION " / " FE_REG_VERSION;
    137  1.1  mycroft 
    138  1.1  mycroft /*
    139  1.1  mycroft  * Supported hardware (Ethernet card) types
    140  1.1  mycroft  * This information is currently used only for debugging
    141  1.1  mycroft  */
    142  1.1  mycroft enum fe_type {
    143  1.1  mycroft 	/* For cards which are successfully probed but not identified. */
    144  1.1  mycroft 	FE_TYPE_UNKNOWN,
    145  1.1  mycroft 
    146  1.1  mycroft 	/* Fujitsu FMV-180 series. */
    147  1.1  mycroft 	FE_TYPE_FMV181,
    148  1.1  mycroft 	FE_TYPE_FMV182,
    149  1.1  mycroft 
    150  1.1  mycroft 	/* Allied-Telesis AT1700 series and RE2000 series. */
    151  1.1  mycroft 	FE_TYPE_AT1700T,
    152  1.1  mycroft 	FE_TYPE_AT1700BT,
    153  1.1  mycroft 	FE_TYPE_AT1700FT,
    154  1.1  mycroft 	FE_TYPE_AT1700AT,
    155  1.1  mycroft 	FE_TYPE_RE2000,
    156  1.1  mycroft 
    157  1.1  mycroft 	/* PCMCIA by Fujitsu. */
    158  1.1  mycroft 	FE_TYPE_MBH10302,
    159  1.1  mycroft 	FE_TYPE_MBH10304,
    160  1.1  mycroft };
    161  1.1  mycroft 
    162  1.1  mycroft /*
    163  1.1  mycroft  * fe_softc: per line info and status
    164  1.1  mycroft  */
    165  1.1  mycroft struct fe_softc {
    166  1.1  mycroft 	struct	device sc_dev;
    167  1.1  mycroft 	void	*sc_ih;
    168  1.1  mycroft 
    169  1.1  mycroft 	struct	arpcom sc_arpcom;	/* ethernet common */
    170  1.1  mycroft 
    171  1.1  mycroft 	/* Set by probe() and not modified in later phases. */
    172  1.1  mycroft 	enum	fe_type type;	/* interface type code */
    173  1.1  mycroft 	char	*typestr;	/* printable name of the interface. */
    174  1.1  mycroft 	int	sc_iobase;	/* MB86960A I/O base address */
    175  1.1  mycroft 
    176  1.1  mycroft 	u_char	proto_dlcr4;	/* DLCR4 prototype. */
    177  1.1  mycroft 	u_char	proto_dlcr5;	/* DLCR5 prototype. */
    178  1.1  mycroft 	u_char	proto_dlcr6;	/* DLCR6 prototype. */
    179  1.1  mycroft 	u_char	proto_dlcr7;	/* DLCR7 prototype. */
    180  1.1  mycroft 	u_char	proto_bmpr13;	/* BMPR13 prototype. */
    181  1.1  mycroft 
    182  1.1  mycroft 	/* Vendor specific hooks. */
    183  1.1  mycroft 	void	(*init) __P((struct fe_softc *)); /* Just before fe_init(). */
    184  1.1  mycroft 	void	(*stop) __P((struct fe_softc *)); /* Just after fe_stop(). */
    185  1.1  mycroft 
    186  1.1  mycroft 	/* Transmission buffer management. */
    187  1.1  mycroft 	u_short	txb_size;	/* total bytes in TX buffer */
    188  1.1  mycroft 	u_short	txb_free;	/* free bytes in TX buffer */
    189  1.1  mycroft 	u_char	txb_count;	/* number of packets in TX buffer */
    190  1.1  mycroft 	u_char	txb_sched;	/* number of scheduled packets */
    191  1.1  mycroft 	u_char	txb_padding;	/* number of delayed padding bytes */
    192  1.1  mycroft 
    193  1.1  mycroft 	/* Multicast address filter management. */
    194  1.1  mycroft 	u_char	filter_change;	/* MARs must be changed ASAP. */
    195  1.1  mycroft 	u_char	filter[FE_FILTER_LEN];	/* new filter value. */
    196  1.1  mycroft };
    197  1.1  mycroft 
    198  1.1  mycroft /* Frequently accessed members in arpcom. */
    199  1.1  mycroft #define sc_enaddr	sc_arpcom.ac_enaddr
    200  1.1  mycroft 
    201  1.1  mycroft /* Standard driver entry points.  These can be static. */
    202  1.1  mycroft int	feprobe		__P((struct device *, void *, void *));
    203  1.1  mycroft void	feattach	__P((struct device *, struct device *, void *));
    204  1.1  mycroft int	feintr		__P((void *));
    205  1.1  mycroft void	fe_init		__P((struct fe_softc *));
    206  1.1  mycroft int	fe_ioctl	__P((struct ifnet *, u_long, caddr_t));
    207  1.1  mycroft void	fe_start	__P((struct ifnet *));
    208  1.1  mycroft void	fe_reset	__P((struct fe_softc *));
    209  1.1  mycroft void	fe_watchdog	__P((int));
    210  1.1  mycroft 
    211  1.1  mycroft /* Local functions.  Order of declaration is confused.  FIXME. */
    212  1.1  mycroft int	fe_probe_fmv	__P((struct fe_softc *, struct isa_attach_args *));
    213  1.1  mycroft int	fe_probe_ati	__P((struct fe_softc *, struct isa_attach_args *));
    214  1.1  mycroft int	fe_probe_mbh	__P((struct fe_softc *, struct isa_attach_args *));
    215  1.1  mycroft void	fe_init_mbh	__P((struct fe_softc *));
    216  1.1  mycroft int	fe_get_packet	__P((struct fe_softc *, int));
    217  1.1  mycroft void	fe_stop		__P((struct fe_softc *));
    218  1.1  mycroft void	fe_tint		__P((/*struct fe_softc *, u_char*/));
    219  1.1  mycroft void	fe_rint		__P((/*struct fe_softc *, u_char*/));
    220  1.1  mycroft static inline
    221  1.1  mycroft void	fe_xmit		__P((struct fe_softc *));
    222  1.1  mycroft void	fe_write_mbufs	__P((struct fe_softc *, struct mbuf *));
    223  1.1  mycroft void	fe_getmcaf	__P((struct arpcom *, u_char *));
    224  1.1  mycroft void	fe_setmode	__P((struct fe_softc *));
    225  1.1  mycroft void	fe_loadmar	__P((struct fe_softc *));
    226  1.1  mycroft #if FE_DEBUG >= 1
    227  1.1  mycroft void	fe_dump		__P((int, struct fe_softc *));
    228  1.1  mycroft #endif
    229  1.1  mycroft 
    230  1.1  mycroft struct cfdriver fecd = {
    231  1.1  mycroft 	NULL, "fe", feprobe, feattach, DV_IFNET, sizeof(struct fe_softc)
    232  1.1  mycroft };
    233  1.1  mycroft 
    234  1.1  mycroft /* Ethernet constants.  To be defined in if_ehter.h?  FIXME. */
    235  1.1  mycroft #define ETHER_MIN_LEN	60	/* with header, without CRC. */
    236  1.1  mycroft #define ETHER_MAX_LEN	1514	/* with header, without CRC. */
    237  1.1  mycroft #define ETHER_ADDR_LEN	6	/* number of bytes in an address. */
    238  1.1  mycroft #define ETHER_HDR_SIZE	14	/* src addr, dst addr, and data type. */
    239  1.1  mycroft 
    240  1.1  mycroft /*
    241  1.1  mycroft  * Fe driver specific constants which relate to 86960/86965.
    242  1.1  mycroft  * They are here (not in if_fereg.h), since selection of those
    243  1.1  mycroft  * values depend on driver design.  I want to keep definitions in
    244  1.1  mycroft  * if_fereg.h "clean", so that if someone wrote another driver
    245  1.1  mycroft  * for 86960/86965, if_fereg.h were usable unchanged.
    246  1.1  mycroft  *
    247  1.1  mycroft  * The above statement sounds somothing like it's better to name
    248  1.1  mycroft  * it "ic/mb86960.h" but "if_fereg.h"...  Should I do so?  FIXME.
    249  1.1  mycroft  */
    250  1.1  mycroft 
    251  1.1  mycroft /* Interrupt masks. */
    252  1.1  mycroft #define FE_TMASK (FE_D2_COLL16 | FE_D2_TXDONE)
    253  1.1  mycroft #define FE_RMASK (FE_D3_OVRFLO | FE_D3_CRCERR | \
    254  1.1  mycroft 		  FE_D3_ALGERR | FE_D3_SRTPKT | FE_D3_PKTRDY)
    255  1.1  mycroft 
    256  1.1  mycroft /* Maximum number of iterrations for a receive interrupt. */
    257  1.1  mycroft #define FE_MAX_RECV_COUNT ((65536 - 2048 * 2) / 64)
    258  1.1  mycroft 	/* Maximum size of SRAM is 65536,
    259  1.1  mycroft 	 * minimum size of transmission buffer in fe is 2x2KB,
    260  1.1  mycroft 	 * and minimum amount of received packet including headers
    261  1.1  mycroft 	 * added by the chip is 64 bytes.
    262  1.1  mycroft 	 * Hence FE_MAX_RECV_COUNT is the upper limit for number
    263  1.1  mycroft 	 * of packets in the receive buffer. */
    264  1.1  mycroft 
    265  1.1  mycroft /*
    266  1.1  mycroft  * Convenient routines to access contiguous I/O ports.
    267  1.1  mycroft  */
    268  1.1  mycroft 
    269  1.1  mycroft static inline void
    270  1.1  mycroft inblk (int addr, u_char * mem, int len)
    271  1.1  mycroft {
    272  1.1  mycroft 	while (--len >= 0) {
    273  1.1  mycroft 		*mem++ = inb(addr++);
    274  1.1  mycroft 	}
    275  1.1  mycroft }
    276  1.1  mycroft 
    277  1.1  mycroft static inline void
    278  1.1  mycroft outblk (int addr, u_char const * mem, int len)
    279  1.1  mycroft {
    280  1.1  mycroft 	while (--len >= 0) {
    281  1.1  mycroft 		outb(addr++, *mem++);
    282  1.1  mycroft 	}
    283  1.1  mycroft }
    284  1.1  mycroft 
    285  1.1  mycroft /*
    286  1.1  mycroft  * Hardware probe routines.
    287  1.1  mycroft  */
    288  1.1  mycroft 
    289  1.1  mycroft /*
    290  1.1  mycroft  * Determine if the device is present.
    291  1.1  mycroft  */
    292  1.1  mycroft int
    293  1.1  mycroft feprobe(parent, match, aux)
    294  1.1  mycroft 	struct device *parent;
    295  1.1  mycroft 	void *match, *aux;
    296  1.1  mycroft {
    297  1.1  mycroft 	struct fe_softc *sc = match;
    298  1.1  mycroft 	struct isa_attach_args *ia = aux;
    299  1.1  mycroft 
    300  1.1  mycroft #if FE_DEBUG >= 2
    301  1.1  mycroft 	log(LOG_INFO, "%s: %s\n", sc->sc_dev.dv_xname, fe_version);
    302  1.1  mycroft #endif
    303  1.1  mycroft 
    304  1.1  mycroft 	/* Probe an address. */
    305  1.1  mycroft 	sc->sc_iobase = ia->ia_iobase;
    306  1.1  mycroft 
    307  1.1  mycroft 	if (fe_probe_fmv(sc, ia))
    308  1.1  mycroft 		return (1);
    309  1.1  mycroft 	if (fe_probe_ati(sc, ia))
    310  1.1  mycroft 		return (1);
    311  1.1  mycroft 	if (fe_probe_mbh(sc, ia))
    312  1.1  mycroft 		return (1);
    313  1.1  mycroft 	return (0);
    314  1.1  mycroft }
    315  1.1  mycroft 
    316  1.1  mycroft /*
    317  1.1  mycroft  * Check for specific bits in specific registers have specific values.
    318  1.1  mycroft  */
    319  1.1  mycroft struct fe_simple_probe_struct {
    320  1.1  mycroft 	u_char port;	/* Offset from the base I/O address. */
    321  1.1  mycroft 	u_char mask;	/* Bits to be checked. */
    322  1.1  mycroft 	u_char bits;	/* Values to be compared against. */
    323  1.1  mycroft };
    324  1.1  mycroft 
    325  1.1  mycroft static inline int
    326  1.1  mycroft fe_simple_probe (int addr, struct fe_simple_probe_struct const * sp)
    327  1.1  mycroft {
    328  1.1  mycroft 	struct fe_simple_probe_struct const * p;
    329  1.1  mycroft 
    330  1.1  mycroft 	for (p = sp; p->mask != 0; p++) {
    331  1.1  mycroft 		if ((inb(addr + p->port) & p->mask) != p->bits) {
    332  1.1  mycroft 			return (0);
    333  1.1  mycroft 		}
    334  1.1  mycroft 	}
    335  1.1  mycroft 	return (1);
    336  1.1  mycroft }
    337  1.1  mycroft 
    338  1.1  mycroft /*
    339  1.1  mycroft  * Routines to read all bytes from the config EEPROM through MB86965A.
    340  1.1  mycroft  * I'm not sure what exactly I'm doing here...  I was told just to follow
    341  1.1  mycroft  * the steps, and it worked.  Could someone tell me why the following
    342  1.1  mycroft  * code works?  (Or, why all similar codes I tried previously doesn't
    343  1.1  mycroft  * work.)  FIXME.
    344  1.1  mycroft  */
    345  1.1  mycroft 
    346  1.1  mycroft static inline void
    347  1.1  mycroft strobe (int bmpr16)
    348  1.1  mycroft {
    349  1.1  mycroft 	/*
    350  1.1  mycroft 	 * Output same value twice.  To speed-down execution?
    351  1.1  mycroft 	 */
    352  1.1  mycroft 	outb(bmpr16, FE_B16_SELECT);
    353  1.1  mycroft 	outb(bmpr16, FE_B16_SELECT);
    354  1.1  mycroft 	outb(bmpr16, FE_B16_SELECT | FE_B16_CLOCK);
    355  1.1  mycroft 	outb(bmpr16, FE_B16_SELECT | FE_B16_CLOCK);
    356  1.1  mycroft 	outb(bmpr16, FE_B16_SELECT);
    357  1.1  mycroft 	outb(bmpr16, FE_B16_SELECT);
    358  1.1  mycroft }
    359  1.1  mycroft 
    360  1.1  mycroft void
    361  1.1  mycroft fe_read_eeprom(sc, data)
    362  1.1  mycroft 	struct fe_softc *sc;
    363  1.1  mycroft 	u_char *data;
    364  1.1  mycroft {
    365  1.1  mycroft 	int iobase = sc->sc_iobase;
    366  1.1  mycroft 	int bmpr16 = iobase + FE_BMPR16;
    367  1.1  mycroft 	int bmpr17 = iobase + FE_BMPR17;
    368  1.1  mycroft 	u_char n, val, bit;
    369  1.1  mycroft 
    370  1.1  mycroft 	/* Read bytes from EEPROM; two bytes per an iterration. */
    371  1.1  mycroft 	for (n = 0; n < FE_EEPROM_SIZE / 2; n++) {
    372  1.1  mycroft 		/* Reset the EEPROM interface. */
    373  1.1  mycroft 		outb(bmpr16, 0x00);
    374  1.1  mycroft 		outb(bmpr17, 0x00);
    375  1.1  mycroft 		outb(bmpr16, FE_B16_SELECT);
    376  1.1  mycroft 
    377  1.1  mycroft 		/* Start EEPROM access. */
    378  1.1  mycroft 		outb(bmpr17, FE_B17_DATA);
    379  1.1  mycroft 		strobe(bmpr16);
    380  1.1  mycroft 
    381  1.1  mycroft 		/* Pass the iterration count to the chip. */
    382  1.1  mycroft 		val = 0x80 | n;
    383  1.1  mycroft 		for (bit = 0x80; bit != 0x00; bit >>= 1) {
    384  1.1  mycroft 			outb(bmpr17, (val & bit) ? FE_B17_DATA : 0);
    385  1.1  mycroft 			strobe(bmpr16);
    386  1.1  mycroft 		}
    387  1.1  mycroft 		outb(bmpr17, 0x00);
    388  1.1  mycroft 
    389  1.1  mycroft 		/* Read a byte. */
    390  1.1  mycroft 		val = 0;
    391  1.1  mycroft 		for (bit = 0x80; bit != 0x00; bit >>= 1) {
    392  1.1  mycroft 			strobe(bmpr16);
    393  1.1  mycroft 			if (inb(bmpr17) & FE_B17_DATA)
    394  1.1  mycroft 				val |= bit;
    395  1.1  mycroft 		}
    396  1.1  mycroft 		*data++ = val;
    397  1.1  mycroft 
    398  1.1  mycroft 		/* Read one more byte. */
    399  1.1  mycroft 		val = 0;
    400  1.1  mycroft 		for (bit = 0x80; bit != 0x00; bit >>= 1) {
    401  1.1  mycroft 			strobe(bmpr16);
    402  1.1  mycroft 			if (inb(bmpr17) & FE_B17_DATA)
    403  1.1  mycroft 				val |= bit;
    404  1.1  mycroft 		}
    405  1.1  mycroft 		*data++ = val;
    406  1.1  mycroft 	}
    407  1.1  mycroft 
    408  1.1  mycroft #if FE_DEBUG >= 3
    409  1.1  mycroft 	/* Report what we got. */
    410  1.1  mycroft 	data -= FE_EEPROM_SIZE;
    411  1.1  mycroft 	log(LOG_INFO, "%s: EEPROM at %04x:"
    412  1.1  mycroft 	    " %02x%02x%02x%02x %02x%02x%02x%02x -"
    413  1.1  mycroft 	    " %02x%02x%02x%02x %02x%02x%02x%02x -"
    414  1.1  mycroft 	    " %02x%02x%02x%02x %02x%02x%02x%02x -"
    415  1.1  mycroft 	    " %02x%02x%02x%02x %02x%02x%02x%02x\n",
    416  1.1  mycroft 	    sc->sc_dev.dv_xname, iobase,
    417  1.1  mycroft 	    data[ 0], data[ 1], data[ 2], data[ 3],
    418  1.1  mycroft 	    data[ 4], data[ 5], data[ 6], data[ 7],
    419  1.1  mycroft 	    data[ 8], data[ 9], data[10], data[11],
    420  1.1  mycroft 	    data[12], data[13], data[14], data[15],
    421  1.1  mycroft 	    data[16], data[17], data[18], data[19],
    422  1.1  mycroft 	    data[20], data[21], data[22], data[23],
    423  1.1  mycroft 	    data[24], data[25], data[26], data[27],
    424  1.1  mycroft 	    data[28], data[29], data[30], data[31]);
    425  1.1  mycroft #endif
    426  1.1  mycroft }
    427  1.1  mycroft 
    428  1.1  mycroft /*
    429  1.1  mycroft  * Hardware (vendor) specific probe routines.
    430  1.1  mycroft  */
    431  1.1  mycroft 
    432  1.1  mycroft /*
    433  1.1  mycroft  * Probe and initialization for Fujitsu FMV-180 series boards
    434  1.1  mycroft  */
    435  1.1  mycroft int
    436  1.1  mycroft fe_probe_fmv(sc, ia)
    437  1.1  mycroft 	struct fe_softc *sc;
    438  1.1  mycroft 	struct isa_attach_args *ia;
    439  1.1  mycroft {
    440  1.1  mycroft 	int i, n;
    441  1.1  mycroft 	int iobase = sc->sc_iobase;
    442  1.1  mycroft 	int irq;
    443  1.1  mycroft 
    444  1.1  mycroft 	static int const iomap[8] =
    445  1.1  mycroft 		{ 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x300, 0x340 };
    446  1.1  mycroft 	static int const irqmap[4] =
    447  1.1  mycroft 		{ 3, 7, 10, 15 };
    448  1.1  mycroft 
    449  1.1  mycroft 	static struct fe_simple_probe_struct const probe_table[] = {
    450  1.1  mycroft 		{ FE_DLCR2, 0x70, 0x00 },
    451  1.1  mycroft 		{ FE_DLCR4, 0x08, 0x00 },
    452  1.1  mycroft 	    /*	{ FE_DLCR5, 0x80, 0x00 },	Doesn't work. */
    453  1.1  mycroft 
    454  1.1  mycroft 		{ FE_FMV0, FE_FMV0_MAGIC_MASK,  FE_FMV0_MAGIC_VALUE },
    455  1.1  mycroft 		{ FE_FMV1, FE_FMV1_CARDID_MASK, FE_FMV1_CARDID_ID   },
    456  1.1  mycroft 		{ FE_FMV3, FE_FMV3_EXTRA_MASK,  FE_FMV3_EXTRA_VALUE },
    457  1.1  mycroft #if 1
    458  1.1  mycroft 	/*
    459  1.1  mycroft 	 * Test *vendor* part of the station address for Fujitsu.
    460  1.1  mycroft 	 * The test will gain reliability of probe process, but
    461  1.1  mycroft 	 * it rejects FMV-180 clone boards manufactured by other vendors.
    462  1.1  mycroft 	 * We have to turn the test off when such cards are made available.
    463  1.1  mycroft 	 */
    464  1.1  mycroft 		{ FE_FMV4, 0xFF, 0x00 },
    465  1.1  mycroft 		{ FE_FMV5, 0xFF, 0x00 },
    466  1.1  mycroft 		{ FE_FMV6, 0xFF, 0x0E },
    467  1.1  mycroft #else
    468  1.1  mycroft 	/*
    469  1.1  mycroft 	 * We can always verify the *first* 2 bits (in Ehternet
    470  1.1  mycroft 	 * bit order) are "no multicast" and "no local" even for
    471  1.1  mycroft 	 * unknown vendors.
    472  1.1  mycroft 	 */
    473  1.1  mycroft 		{ FE_FMV4, 0x03, 0x00 },
    474  1.1  mycroft #endif
    475  1.1  mycroft 		{ 0 }
    476  1.1  mycroft 	};
    477  1.1  mycroft 
    478  1.1  mycroft #if 0
    479  1.1  mycroft 	/*
    480  1.1  mycroft 	 * Dont probe at all if the config says we are PCMCIA...
    481  1.1  mycroft 	 */
    482  1.1  mycroft 	if ((cf->cf_flags & FE_FLAGS_PCMCIA) != 0)
    483  1.1  mycroft 		return (0);
    484  1.1  mycroft #endif
    485  1.1  mycroft 
    486  1.1  mycroft 	/*
    487  1.1  mycroft 	 * See if the sepcified address is possible for FMV-180 series.
    488  1.1  mycroft 	 */
    489  1.1  mycroft 	for (i = 0; i < 8; i++) {
    490  1.1  mycroft 		if (iomap[i] == iobase)
    491  1.1  mycroft 			break;
    492  1.1  mycroft 	}
    493  1.1  mycroft 	if (i == 8)
    494  1.1  mycroft 		return (0);
    495  1.1  mycroft 
    496  1.1  mycroft 	/* Simple probe. */
    497  1.1  mycroft 	if (!fe_simple_probe(iobase, probe_table))
    498  1.1  mycroft 		return (0);
    499  1.1  mycroft 
    500  1.1  mycroft 	/* Check if our I/O address matches config info on EEPROM. */
    501  1.1  mycroft 	n = (inb(iobase + FE_FMV2) & FE_FMV2_ADDR) >> FE_FMV2_ADDR_SHIFT;
    502  1.1  mycroft 	if (iomap[n] != iobase)
    503  1.1  mycroft 		return (0);
    504  1.1  mycroft 
    505  1.1  mycroft 	/* Determine the card type. */
    506  1.1  mycroft 	switch (inb(iobase + FE_FMV0) & FE_FMV0_MODEL) {
    507  1.1  mycroft 	case FE_FMV0_MODEL_FMV181:
    508  1.1  mycroft 		sc->type = FE_TYPE_FMV181;
    509  1.1  mycroft 		sc->typestr = "FMV-181";
    510  1.1  mycroft 		break;
    511  1.1  mycroft 	case FE_FMV0_MODEL_FMV182:
    512  1.1  mycroft 		sc->type = FE_TYPE_FMV182;
    513  1.1  mycroft 		sc->typestr = "FMV-182";
    514  1.1  mycroft 		break;
    515  1.1  mycroft 	default:
    516  1.1  mycroft 	  	/* Unknown card type: maybe a new model, but... */
    517  1.1  mycroft 		return (0);
    518  1.1  mycroft 	}
    519  1.1  mycroft 
    520  1.1  mycroft 	/*
    521  1.1  mycroft 	 * An FMV-180 has successfully been proved.
    522  1.1  mycroft 	 * Determine which IRQ to be used.
    523  1.1  mycroft 	 *
    524  1.1  mycroft 	 * In this version, we always get an IRQ assignment from the
    525  1.1  mycroft 	 * FMV-180's configuration EEPROM, ignoring that specified in
    526  1.1  mycroft 	 * config file.
    527  1.1  mycroft 	 */
    528  1.1  mycroft 	n = (inb(iobase + FE_FMV2) & FE_FMV2_IRQ) >> FE_FMV2_IRQ_SHIFT;
    529  1.1  mycroft 	irq = irqmap[n];
    530  1.1  mycroft 
    531  1.1  mycroft 	if (ia->ia_irq != IRQUNK) {
    532  1.1  mycroft 		if (ia->ia_irq != irq) {
    533  1.1  mycroft 			printf("%s: irq mismatch; kernel configured %d != board configured %d\n",
    534  1.1  mycroft 			    sc->sc_dev.dv_xname, ia->ia_irq, irq);
    535  1.1  mycroft 			return (0);
    536  1.1  mycroft 		}
    537  1.1  mycroft 	} else
    538  1.1  mycroft 		ia->ia_irq = irq;
    539  1.1  mycroft 
    540  1.1  mycroft 	/*
    541  1.1  mycroft 	 * Initialize constants in the per-line structure.
    542  1.1  mycroft 	 */
    543  1.1  mycroft 
    544  1.1  mycroft 	/* Get our station address from EEPROM. */
    545  1.1  mycroft 	inblk(iobase + FE_FMV4, sc->sc_enaddr, ETHER_ADDR_LEN);
    546  1.1  mycroft 
    547  1.1  mycroft 	/* Make sure we got a valid station address. */
    548  1.1  mycroft 	if ((sc->sc_enaddr[0] & 0x03) != 0x00
    549  1.1  mycroft 	  || (sc->sc_enaddr[0] == 0x00
    550  1.1  mycroft 	    && sc->sc_enaddr[1] == 0x00
    551  1.1  mycroft 	    && sc->sc_enaddr[2] == 0x00))
    552  1.1  mycroft 		return (0);
    553  1.1  mycroft 
    554  1.1  mycroft 	/* Register values which depend on board design. */
    555  1.1  mycroft 	sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
    556  1.1  mycroft 	sc->proto_dlcr5 = 0;
    557  1.1  mycroft 	sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_EC;
    558  1.1  mycroft 	sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
    559  1.1  mycroft 
    560  1.1  mycroft 	/*
    561  1.1  mycroft 	 * Program the 86960 as follows:
    562  1.1  mycroft 	 *	SRAM: 32KB, 100ns, byte-wide access.
    563  1.1  mycroft 	 *	Transmission buffer: 4KB x 2.
    564  1.1  mycroft 	 *	System bus interface: 16 bits.
    565  1.1  mycroft 	 * We cannot change these values but TXBSIZE, because they
    566  1.1  mycroft 	 * are hard-wired on the board.  Modifying TXBSIZE will affect
    567  1.1  mycroft 	 * the driver performance.
    568  1.1  mycroft 	 */
    569  1.1  mycroft 	sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
    570  1.1  mycroft 		| FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
    571  1.1  mycroft 
    572  1.1  mycroft 	/*
    573  1.1  mycroft 	 * Minimum initialization of the hardware.
    574  1.1  mycroft 	 * We write into registers; hope I/O ports have no
    575  1.1  mycroft 	 * overlap with other boards.
    576  1.1  mycroft 	 */
    577  1.1  mycroft 
    578  1.1  mycroft 	/* Initialize ASIC. */
    579  1.1  mycroft 	outb(iobase + FE_FMV3, 0);
    580  1.1  mycroft 	outb(iobase + FE_FMV10, 0);
    581  1.1  mycroft 
    582  1.1  mycroft 	/* Wait for a while.  I'm not sure this is necessary.  FIXME. */
    583  1.1  mycroft 	delay(200);
    584  1.1  mycroft 
    585  1.1  mycroft 	/* Initialize 86960. */
    586  1.1  mycroft 	outb(iobase + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
    587  1.1  mycroft 	delay(200);
    588  1.1  mycroft 
    589  1.1  mycroft 	/* Disable all interrupts. */
    590  1.1  mycroft 	outb(iobase + FE_DLCR2, 0);
    591  1.1  mycroft 	outb(iobase + FE_DLCR3, 0);
    592  1.1  mycroft 
    593  1.1  mycroft 	/* Turn the "master interrupt control" flag of ASIC on. */
    594  1.1  mycroft 	outb(iobase + FE_FMV3, FE_FMV3_ENABLE_FLAG);
    595  1.1  mycroft 
    596  1.1  mycroft 	/*
    597  1.1  mycroft 	 * That's all.  FMV-180 occupies 32 I/O addresses, by the way.
    598  1.1  mycroft 	 */
    599  1.1  mycroft 	ia->ia_iosize = 32;
    600  1.1  mycroft 	ia->ia_msize = 0;
    601  1.1  mycroft 	return (1);
    602  1.1  mycroft }
    603  1.1  mycroft 
    604  1.1  mycroft /*
    605  1.1  mycroft  * Probe and initialization for Allied-Telesis AT1700/RE2000 series.
    606  1.1  mycroft  */
    607  1.1  mycroft int
    608  1.1  mycroft fe_probe_ati(sc, ia)
    609  1.1  mycroft 	struct fe_softc *sc;
    610  1.1  mycroft 	struct isa_attach_args *ia;
    611  1.1  mycroft {
    612  1.1  mycroft 	int i, n;
    613  1.1  mycroft 	int iobase = sc->sc_iobase;
    614  1.1  mycroft 	u_char eeprom[FE_EEPROM_SIZE];
    615  1.1  mycroft 	u_char save16, save17;
    616  1.1  mycroft 	int irq;
    617  1.1  mycroft 
    618  1.1  mycroft 	static int const iomap[8] =
    619  1.1  mycroft 		{ 0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300 };
    620  1.1  mycroft 	static int const irqmap[4][4] = {
    621  1.1  mycroft 		{  3,  4,  5,  9 },
    622  1.1  mycroft 		{ 10, 11, 12, 15 },
    623  1.1  mycroft 		{  3, 11,  5, 15 },
    624  1.1  mycroft 		{ 10, 11, 14, 15 },
    625  1.1  mycroft 	};
    626  1.1  mycroft 	static struct fe_simple_probe_struct const probe_table[] = {
    627  1.1  mycroft 		{ FE_DLCR2,  0x70, 0x00 },
    628  1.1  mycroft 		{ FE_DLCR4,  0x08, 0x00 },
    629  1.1  mycroft 		{ FE_DLCR5,  0x80, 0x00 },
    630  1.1  mycroft #if 0
    631  1.1  mycroft 		{ FE_BMPR16, 0x1B, 0x00 },
    632  1.1  mycroft 		{ FE_BMPR17, 0x7F, 0x00 },
    633  1.1  mycroft #endif
    634  1.1  mycroft 		{ 0 }
    635  1.1  mycroft 	};
    636  1.1  mycroft 
    637  1.1  mycroft #if 0
    638  1.1  mycroft 	/*
    639  1.1  mycroft 	 * Don't probe at all if the config says we are PCMCIA...
    640  1.1  mycroft 	 */
    641  1.1  mycroft 	if ((cf->cf_flags & FE_FLAGS_PCMCIA) != 0)
    642  1.1  mycroft 		return (0);
    643  1.1  mycroft #endif
    644  1.1  mycroft 
    645  1.1  mycroft #if FE_DEBUG >= 4
    646  1.1  mycroft 	log(LOG_INFO, "%s: probe (0x%x) for ATI\n", sc->sc_dev.dv_xname, iobase);
    647  1.1  mycroft 	fe_dump(LOG_INFO, sc);
    648  1.1  mycroft #endif
    649  1.1  mycroft 
    650  1.1  mycroft 	/*
    651  1.1  mycroft 	 * See if the sepcified address is possible for MB86965A JLI mode.
    652  1.1  mycroft 	 */
    653  1.1  mycroft 	for (i = 0; i < 8; i++) {
    654  1.1  mycroft 		if (iomap[i] == iobase)
    655  1.1  mycroft 			break;
    656  1.1  mycroft 	}
    657  1.1  mycroft 	if (i == 8)
    658  1.1  mycroft 		return (0);
    659  1.1  mycroft 
    660  1.1  mycroft 	/*
    661  1.1  mycroft 	 * We should test if MB86965A is on the base address now.
    662  1.1  mycroft 	 * Unfortunately, it is very hard to probe it reliably, since
    663  1.1  mycroft 	 * we have no way to reset the chip under software control.
    664  1.1  mycroft 	 * On cold boot, we could check the "signature" bit patterns
    665  1.1  mycroft 	 * described in the Fujitsu document.  On warm boot, however,
    666  1.1  mycroft 	 * we can predict almost nothing about register values.
    667  1.1  mycroft 	 */
    668  1.1  mycroft 	if (!fe_simple_probe(iobase, probe_table))
    669  1.1  mycroft 		return (0);
    670  1.1  mycroft 
    671  1.1  mycroft 	/* Save old values of the registers. */
    672  1.1  mycroft 	save16 = inb(iobase + FE_BMPR16);
    673  1.1  mycroft 	save17 = inb(iobase + FE_BMPR17);
    674  1.1  mycroft 
    675  1.1  mycroft 	/* Check if our I/O address matches config info on 86965. */
    676  1.1  mycroft 	n = (inb(iobase + FE_BMPR19) & FE_B19_ADDR) >> FE_B19_ADDR_SHIFT;
    677  1.1  mycroft 	if (iomap[n] != iobase)
    678  1.1  mycroft 		goto fail;
    679  1.1  mycroft 
    680  1.1  mycroft 	/*
    681  1.1  mycroft 	 * We are now almost sure we have an AT1700 at the given
    682  1.1  mycroft 	 * address.  So, read EEPROM through 86965.  We have to write
    683  1.1  mycroft 	 * into LSI registers to read from EEPROM.  I want to avoid it
    684  1.1  mycroft 	 * at this stage, but I cannot test the presense of the chip
    685  1.1  mycroft 	 * any further without reading EEPROM.  FIXME.
    686  1.1  mycroft 	 */
    687  1.1  mycroft 	fe_read_eeprom(sc, eeprom);
    688  1.1  mycroft 
    689  1.1  mycroft 	/* Make sure the EEPROM is turned off. */
    690  1.1  mycroft 	outb(iobase + FE_BMPR16, 0);
    691  1.1  mycroft 	outb(iobase + FE_BMPR17, 0);
    692  1.1  mycroft 
    693  1.1  mycroft 	/* Make sure that config info in EEPROM and 86965 agree. */
    694  1.1  mycroft 	if (eeprom[FE_EEPROM_CONF] != inb(iobase + FE_BMPR19))
    695  1.1  mycroft 		goto fail;
    696  1.1  mycroft 
    697  1.1  mycroft 	/*
    698  1.1  mycroft 	 * Determine the card type.
    699  1.1  mycroft 	 */
    700  1.1  mycroft 	switch (eeprom[FE_ATI_EEP_MODEL]) {
    701  1.1  mycroft 	case FE_ATI_MODEL_AT1700T:
    702  1.1  mycroft 		sc->type = FE_TYPE_AT1700T;
    703  1.1  mycroft 		sc->typestr = "AT-1700T";
    704  1.1  mycroft 		break;
    705  1.1  mycroft 	case FE_ATI_MODEL_AT1700BT:
    706  1.1  mycroft 		sc->type = FE_TYPE_AT1700BT;
    707  1.1  mycroft 		sc->typestr = "AT-1700BT";
    708  1.1  mycroft 		break;
    709  1.1  mycroft 	case FE_ATI_MODEL_AT1700FT:
    710  1.1  mycroft 		sc->type = FE_TYPE_AT1700FT;
    711  1.1  mycroft 		sc->typestr = "AT-1700FT";
    712  1.1  mycroft 		break;
    713  1.1  mycroft 	case FE_ATI_MODEL_AT1700AT:
    714  1.1  mycroft 		sc->type = FE_TYPE_AT1700AT;
    715  1.1  mycroft 		sc->typestr = "AT-1700AT";
    716  1.1  mycroft 		break;
    717  1.1  mycroft 	default:
    718  1.1  mycroft 		sc->type = FE_TYPE_RE2000;
    719  1.1  mycroft 		sc->typestr = "unknown (RE-2000?)";
    720  1.1  mycroft 		break;
    721  1.1  mycroft 	}
    722  1.1  mycroft 
    723  1.1  mycroft 	/*
    724  1.1  mycroft 	 * Try to determine IRQ settings.
    725  1.1  mycroft 	 * Different models use different ranges of IRQs.
    726  1.1  mycroft 	 */
    727  1.1  mycroft 	n = (inb(iobase + FE_BMPR19) & FE_B19_IRQ) >> FE_B19_IRQ_SHIFT;
    728  1.1  mycroft 	switch (eeprom[FE_ATI_EEP_REVISION] & 0xf0) {
    729  1.1  mycroft 	case 0x30:
    730  1.1  mycroft 		irq = irqmap[3][n];
    731  1.1  mycroft 		break;
    732  1.1  mycroft 	case 0x10:
    733  1.1  mycroft 	case 0x50:
    734  1.1  mycroft 		irq = irqmap[2][n];
    735  1.1  mycroft 		break;
    736  1.1  mycroft 	case 0x40:
    737  1.1  mycroft 	case 0x60:
    738  1.1  mycroft 		if (eeprom[FE_ATI_EEP_MAGIC] & 0x04) {
    739  1.1  mycroft 			irq = irqmap[1][n];
    740  1.1  mycroft 			break;
    741  1.1  mycroft 		}
    742  1.1  mycroft 	default:
    743  1.1  mycroft 		irq = irqmap[0][n];
    744  1.1  mycroft 		break;
    745  1.1  mycroft 	}
    746  1.1  mycroft 
    747  1.1  mycroft 	if (ia->ia_irq != IRQUNK) {
    748  1.1  mycroft 		if (ia->ia_irq != irq) {
    749  1.1  mycroft 			printf("%s: irq mismatch; kernel configured %d != board configured %d\n",
    750  1.1  mycroft 			    sc->sc_dev.dv_xname, ia->ia_irq, irq);
    751  1.1  mycroft 			return (0);
    752  1.1  mycroft 		}
    753  1.1  mycroft 	} else
    754  1.1  mycroft 		ia->ia_irq = irq;
    755  1.1  mycroft 
    756  1.1  mycroft 	/*
    757  1.1  mycroft 	 * Initialize constants in the per-line structure.
    758  1.1  mycroft 	 */
    759  1.1  mycroft 
    760  1.1  mycroft 	/* Get our station address from EEPROM. */
    761  1.1  mycroft 	bcopy(eeprom + FE_ATI_EEP_ADDR, sc->sc_enaddr, ETHER_ADDR_LEN);
    762  1.1  mycroft 
    763  1.1  mycroft 	/* Make sure we got a valid station address. */
    764  1.1  mycroft 	if ((sc->sc_enaddr[0] & 0x03) != 0x00
    765  1.1  mycroft 	  || (sc->sc_enaddr[0] == 0x00
    766  1.1  mycroft 	    && sc->sc_enaddr[1] == 0x00
    767  1.1  mycroft 	    && sc->sc_enaddr[2] == 0x00))
    768  1.1  mycroft 		goto fail;
    769  1.1  mycroft 
    770  1.1  mycroft 	/* Should find all register prototypes here.  FIXME. */
    771  1.1  mycroft 	sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;  /* FIXME */
    772  1.1  mycroft 	sc->proto_dlcr5 = 0;
    773  1.1  mycroft 	sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_EC;
    774  1.1  mycroft #if 0	/* XXXX Should we use this? */
    775  1.1  mycroft 	sc->proto_bmpr13 = eeprom[FE_ATI_EEP_MEDIA];
    776  1.1  mycroft #else
    777  1.1  mycroft 	sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
    778  1.1  mycroft #endif
    779  1.1  mycroft 
    780  1.1  mycroft 	/*
    781  1.1  mycroft 	 * Program the 86965 as follows:
    782  1.1  mycroft 	 *	SRAM: 32KB, 100ns, byte-wide access.
    783  1.1  mycroft 	 *	Transmission buffer: 4KB x 2.
    784  1.1  mycroft 	 *	System bus interface: 16 bits.
    785  1.1  mycroft 	 * We cannot change these values but TXBSIZE, because they
    786  1.1  mycroft 	 * are hard-wired on the board.  Modifying TXBSIZE will affect
    787  1.1  mycroft 	 * the driver performance.
    788  1.1  mycroft 	 */
    789  1.1  mycroft 	sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
    790  1.1  mycroft 		| FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
    791  1.1  mycroft 
    792  1.1  mycroft #if FE_DEBUG >= 3
    793  1.1  mycroft 	log(LOG_INFO, "%s: ATI found\n", sc->sc_dev.dv_xname);
    794  1.1  mycroft 	fe_dump(LOG_INFO, sc);
    795  1.1  mycroft #endif
    796  1.1  mycroft 
    797  1.1  mycroft 	/* Initialize 86965. */
    798  1.1  mycroft 	outb(iobase + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
    799  1.1  mycroft 	delay(200);
    800  1.1  mycroft 
    801  1.1  mycroft 	/* Disable all interrupts. */
    802  1.1  mycroft 	outb(iobase + FE_DLCR2, 0);
    803  1.1  mycroft 	outb(iobase + FE_DLCR3, 0);
    804  1.1  mycroft 
    805  1.1  mycroft #if FE_DEBUG >= 3
    806  1.1  mycroft 	log(LOG_INFO, "%s: end of fe_probe_ati()\n", sc->sc_dev.dv_xname);
    807  1.1  mycroft 	fe_dump(LOG_INFO, sc);
    808  1.1  mycroft #endif
    809  1.1  mycroft 
    810  1.1  mycroft 	/*
    811  1.1  mycroft 	 * That's all.  AT1700 occupies 32 I/O addresses, by the way.
    812  1.1  mycroft 	 */
    813  1.1  mycroft 	ia->ia_iosize = 32;
    814  1.1  mycroft 	ia->ia_msize = 0;
    815  1.1  mycroft 	return (1);
    816  1.1  mycroft 
    817  1.1  mycroft fail:
    818  1.1  mycroft 	/* Restore register values, in the case we had no 86965. */
    819  1.1  mycroft 	outb(iobase + FE_BMPR16, save16);
    820  1.1  mycroft 	outb(iobase + FE_BMPR17, save17);
    821  1.1  mycroft 	return (0);
    822  1.1  mycroft }
    823  1.1  mycroft 
    824  1.1  mycroft /*
    825  1.1  mycroft  * Probe and initialization for Fujitsu MBH10302 PCMCIA Ethernet interface.
    826  1.1  mycroft  */
    827  1.1  mycroft int
    828  1.1  mycroft fe_probe_mbh(sc, ia)
    829  1.1  mycroft 	struct fe_softc *sc;
    830  1.1  mycroft 	struct isa_attach_args *ia;
    831  1.1  mycroft {
    832  1.1  mycroft 	int iobase = sc->sc_iobase;
    833  1.1  mycroft 
    834  1.1  mycroft 	static struct fe_simple_probe_struct probe_table[] = {
    835  1.1  mycroft 		{ FE_DLCR2, 0x70, 0x00 },
    836  1.1  mycroft 		{ FE_DLCR4, 0x08, 0x00 },
    837  1.1  mycroft 	    /*	{ FE_DLCR5, 0x80, 0x00 },	Does not work well. */
    838  1.1  mycroft #if 0
    839  1.1  mycroft 	/*
    840  1.1  mycroft 	 * Test *vendor* part of the address for Fujitsu.
    841  1.1  mycroft 	 * The test will gain reliability of probe process, but
    842  1.1  mycroft 	 * it rejects clones by other vendors, or OEM product
    843  1.1  mycroft 	 * supplied by resalers other than Fujitsu.
    844  1.1  mycroft 	 */
    845  1.1  mycroft 		{ FE_MBH10, 0xFF, 0x00 },
    846  1.1  mycroft 		{ FE_MBH11, 0xFF, 0x00 },
    847  1.1  mycroft 		{ FE_MBH12, 0xFF, 0x0E },
    848  1.1  mycroft #else
    849  1.1  mycroft 	/*
    850  1.1  mycroft 	 * We can always verify the *first* 2 bits (in Ehternet
    851  1.1  mycroft 	 * bit order) are "global" and "unicast" even for
    852  1.1  mycroft 	 * unknown vendors.
    853  1.1  mycroft 	 */
    854  1.1  mycroft 		{ FE_MBH10, 0x03, 0x00 },
    855  1.1  mycroft #endif
    856  1.1  mycroft         /* Just a gap?  Seems reliable, anyway. */
    857  1.1  mycroft 		{ 0x12, 0xFF, 0x00 },
    858  1.1  mycroft 		{ 0x13, 0xFF, 0x00 },
    859  1.1  mycroft 		{ 0x14, 0xFF, 0x00 },
    860  1.1  mycroft 		{ 0x15, 0xFF, 0x00 },
    861  1.1  mycroft 		{ 0x16, 0xFF, 0x00 },
    862  1.1  mycroft 		{ 0x17, 0xFF, 0x00 },
    863  1.1  mycroft 		{ 0x18, 0xFF, 0xFF },
    864  1.1  mycroft 		{ 0x19, 0xFF, 0xFF },
    865  1.1  mycroft 
    866  1.1  mycroft 		{ 0 }
    867  1.1  mycroft 	};
    868  1.1  mycroft 
    869  1.1  mycroft #if 0
    870  1.1  mycroft 	/*
    871  1.1  mycroft 	 * We need a PCMCIA flag.
    872  1.1  mycroft 	 */
    873  1.1  mycroft 	if ((cf->cf_flags & FE_FLAGS_PCMCIA) == 0)
    874  1.1  mycroft 		return (0);
    875  1.1  mycroft #endif
    876  1.1  mycroft 
    877  1.1  mycroft 	/*
    878  1.1  mycroft 	 * We need explicit IRQ and supported address.
    879  1.1  mycroft 	 */
    880  1.1  mycroft 	if (ia->ia_irq == IRQUNK || (iobase & ~0x3E0) != 0)
    881  1.1  mycroft 		return (0);
    882  1.1  mycroft 
    883  1.1  mycroft #if FE_DEBUG >= 3
    884  1.1  mycroft 	log(LOG_INFO, "%s: top of fe_probe_mbh()\n", sc->sc_dev.dv_xname);
    885  1.1  mycroft 	fe_dump(LOG_INFO, sc);
    886  1.1  mycroft #endif
    887  1.1  mycroft 
    888  1.1  mycroft 	/*
    889  1.1  mycroft 	 * See if MBH10302 is on its address.
    890  1.1  mycroft 	 * I'm not sure the following probe code works.  FIXME.
    891  1.1  mycroft 	 */
    892  1.1  mycroft 	if (!fe_simple_probe(iobase, probe_table))
    893  1.1  mycroft 		return (0);
    894  1.1  mycroft 
    895  1.1  mycroft 	/* Determine the card type. */
    896  1.1  mycroft 	sc->type = FE_TYPE_MBH10302;
    897  1.1  mycroft 	sc->typestr = "MBH10302 (PCMCIA)";
    898  1.1  mycroft 
    899  1.1  mycroft 	/*
    900  1.1  mycroft 	 * Initialize constants in the per-line structure.
    901  1.1  mycroft 	 */
    902  1.1  mycroft 
    903  1.1  mycroft 	/* Get our station address from EEPROM. */
    904  1.1  mycroft 	inblk(iobase + FE_MBH10, sc->sc_enaddr, ETHER_ADDR_LEN);
    905  1.1  mycroft 
    906  1.1  mycroft 	/* Make sure we got a valid station address. */
    907  1.1  mycroft 	if ((sc->sc_enaddr[0] & 0x03) != 0x00
    908  1.1  mycroft 	  || (sc->sc_enaddr[0] == 0x00
    909  1.1  mycroft 	    && sc->sc_enaddr[1] == 0x00
    910  1.1  mycroft 	    && sc->sc_enaddr[2] == 0x00))
    911  1.1  mycroft 		return (0);
    912  1.1  mycroft 
    913  1.1  mycroft 	/* Should find all register prototypes here.  FIXME. */
    914  1.1  mycroft 	sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
    915  1.1  mycroft 	sc->proto_dlcr5 = 0;
    916  1.1  mycroft 	sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
    917  1.1  mycroft 	sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
    918  1.1  mycroft 
    919  1.1  mycroft 	/*
    920  1.1  mycroft 	 * Program the 86960 as follows:
    921  1.1  mycroft 	 *	SRAM: 32KB, 100ns, byte-wide access.
    922  1.1  mycroft 	 *	Transmission buffer: 4KB x 2.
    923  1.1  mycroft 	 *	System bus interface: 16 bits.
    924  1.1  mycroft 	 * We cannot change these values but TXBSIZE, because they
    925  1.1  mycroft 	 * are hard-wired on the board.  Modifying TXBSIZE will affect
    926  1.1  mycroft 	 * the driver performance.
    927  1.1  mycroft 	 */
    928  1.1  mycroft 	sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
    929  1.1  mycroft 		| FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
    930  1.1  mycroft 
    931  1.1  mycroft 	/* Setup hooks.  We need a special initialization procedure. */
    932  1.1  mycroft 	sc->init = fe_init_mbh;
    933  1.1  mycroft 
    934  1.1  mycroft 	/*
    935  1.1  mycroft 	 * Minimum initialization.
    936  1.1  mycroft 	 */
    937  1.1  mycroft 
    938  1.1  mycroft 	/* Wait for a while.  I'm not sure this is necessary.  FIXME. */
    939  1.1  mycroft 	delay(200);
    940  1.1  mycroft 
    941  1.1  mycroft 	/* Minimul initialization of 86960. */
    942  1.1  mycroft 	outb(iobase + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
    943  1.1  mycroft 	delay(200);
    944  1.1  mycroft 
    945  1.1  mycroft 	/* Disable all interrupts. */
    946  1.1  mycroft 	outb(iobase + FE_DLCR2, 0);
    947  1.1  mycroft 	outb(iobase + FE_DLCR3, 0);
    948  1.1  mycroft 
    949  1.1  mycroft #if 1	/* FIXME. */
    950  1.1  mycroft 	/* Initialize system bus interface and encoder/decoder operation. */
    951  1.1  mycroft 	outb(iobase + FE_MBH0, FE_MBH0_MAGIC | FE_MBH0_INTR_DISABLE);
    952  1.1  mycroft #endif
    953  1.1  mycroft 
    954  1.1  mycroft 	/*
    955  1.1  mycroft 	 * That's all.  MBH10302 occupies 32 I/O addresses, by the way.
    956  1.1  mycroft 	 */
    957  1.1  mycroft 	ia->ia_iosize = 32;
    958  1.1  mycroft 	ia->ia_msize = 0;
    959  1.1  mycroft 	return (1);
    960  1.1  mycroft }
    961  1.1  mycroft 
    962  1.1  mycroft /* MBH specific initialization routine. */
    963  1.1  mycroft void
    964  1.1  mycroft fe_init_mbh(sc)
    965  1.1  mycroft 	struct fe_softc *sc;
    966  1.1  mycroft {
    967  1.1  mycroft 
    968  1.1  mycroft 	/* Probably required after hot-insertion... */
    969  1.1  mycroft 
    970  1.1  mycroft 	/* Wait for a while.  I'm not sure this is necessary.  FIXME. */
    971  1.1  mycroft 	delay(200);
    972  1.1  mycroft 
    973  1.1  mycroft 	/* Minimul initialization of 86960. */
    974  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
    975  1.1  mycroft 	delay(200);
    976  1.1  mycroft 
    977  1.1  mycroft 	/* Disable all interrupts. */
    978  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR2, 0);
    979  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR3, 0);
    980  1.1  mycroft 
    981  1.1  mycroft 	/* Enable master interrupt flag. */
    982  1.1  mycroft 	outb(sc->sc_iobase + FE_MBH0, FE_MBH0_MAGIC | FE_MBH0_INTR_ENABLE);
    983  1.1  mycroft }
    984  1.1  mycroft 
    985  1.1  mycroft /*
    986  1.1  mycroft  * Install interface into kernel networking data structures
    987  1.1  mycroft  */
    988  1.1  mycroft void
    989  1.1  mycroft feattach(parent, self, aux)
    990  1.1  mycroft 	struct device *parent, *self;
    991  1.1  mycroft 	void *aux;
    992  1.1  mycroft {
    993  1.1  mycroft 	struct fe_softc *sc = (void *)self;
    994  1.1  mycroft 	struct isa_attach_args *ia = aux;
    995  1.1  mycroft 	struct cfdata *cf = sc->sc_dev.dv_cfdata;
    996  1.1  mycroft 	struct ifnet *ifp = &sc->sc_arpcom.ac_if;
    997  1.1  mycroft 
    998  1.1  mycroft 	/* Stop the 86960. */
    999  1.1  mycroft 	fe_stop(sc);
   1000  1.1  mycroft 
   1001  1.1  mycroft 	/* Initialize ifnet structure. */
   1002  1.1  mycroft 	ifp->if_unit = sc->sc_dev.dv_unit;
   1003  1.1  mycroft 	ifp->if_name = fecd.cd_name;
   1004  1.1  mycroft 	ifp->if_start = fe_start;
   1005  1.1  mycroft 	ifp->if_ioctl = fe_ioctl;
   1006  1.1  mycroft 	ifp->if_watchdog = fe_watchdog;
   1007  1.1  mycroft 	ifp->if_flags = IFF_BROADCAST | IFF_NOTRAILERS | IFF_MULTICAST;
   1008  1.1  mycroft 
   1009  1.1  mycroft 	/*
   1010  1.1  mycroft 	 * Set maximum size of output queue, if it has not been set.
   1011  1.1  mycroft 	 * It is done here as this driver may be started after the
   1012  1.1  mycroft 	 * system intialization (i.e., the interface is PCMCIA.)
   1013  1.1  mycroft 	 *
   1014  1.1  mycroft 	 * I'm not sure this is really necessary, but, even if it is,
   1015  1.1  mycroft 	 * it should be done somewhere else, e.g., in if_attach(),
   1016  1.1  mycroft 	 * since it must be a common workaround for all network drivers.
   1017  1.1  mycroft 	 * FIXME.
   1018  1.1  mycroft 	 */
   1019  1.1  mycroft 	if (ifp->if_snd.ifq_maxlen == 0) {
   1020  1.1  mycroft 		extern int ifqmaxlen;		/* Don't be so shocked... */
   1021  1.1  mycroft 		ifp->if_snd.ifq_maxlen = ifqmaxlen;
   1022  1.1  mycroft 	}
   1023  1.1  mycroft 
   1024  1.1  mycroft #if FE_DEBUG >= 3
   1025  1.1  mycroft 	log(LOG_INFO, "%s: feattach()\n", sc->sc_dev.dv_xname);
   1026  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1027  1.1  mycroft #endif
   1028  1.1  mycroft 
   1029  1.1  mycroft #if FE_SINGLE_TRANSMISSION
   1030  1.1  mycroft 	/* Override txb config to allocate minimum. */
   1031  1.1  mycroft 	sc->proto_dlcr6 &= ~FE_D6_TXBSIZ
   1032  1.1  mycroft 	sc->proto_dlcr6 |=  FE_D6_TXBSIZ_2x2KB;
   1033  1.1  mycroft #endif
   1034  1.1  mycroft 
   1035  1.1  mycroft 	/* Modify hardware config if it is requested. */
   1036  1.1  mycroft 	if ((cf->cf_flags & FE_FLAGS_OVERRIDE_DLCR6) != 0)
   1037  1.1  mycroft 		sc->proto_dlcr6 = cf->cf_flags & FE_FLAGS_DLCR6_VALUE;
   1038  1.1  mycroft 
   1039  1.1  mycroft 	/* Find TX buffer size, based on the hardware dependent proto. */
   1040  1.1  mycroft 	switch (sc->proto_dlcr6 & FE_D6_TXBSIZ) {
   1041  1.1  mycroft 	case FE_D6_TXBSIZ_2x2KB:
   1042  1.1  mycroft 		sc->txb_size = 2048;
   1043  1.1  mycroft 		break;
   1044  1.1  mycroft 	case FE_D6_TXBSIZ_2x4KB:
   1045  1.1  mycroft 		sc->txb_size = 4096;
   1046  1.1  mycroft 		break;
   1047  1.1  mycroft 	case FE_D6_TXBSIZ_2x8KB:
   1048  1.1  mycroft 		sc->txb_size = 8192;
   1049  1.1  mycroft 		break;
   1050  1.1  mycroft 	default:
   1051  1.1  mycroft 		/* Oops, we can't work with single buffer configuration. */
   1052  1.1  mycroft #if FE_DEBUG >= 2
   1053  1.1  mycroft 		log(LOG_WARNING, "%s: strange TXBSIZ config; fixing\n",
   1054  1.1  mycroft 		    sc->sc_dev.dv_xname);
   1055  1.1  mycroft #endif
   1056  1.1  mycroft 		sc->proto_dlcr6 &= ~FE_D6_TXBSIZ;
   1057  1.1  mycroft 		sc->proto_dlcr6 |=  FE_D6_TXBSIZ_2x2KB;
   1058  1.1  mycroft 		sc->txb_size = 2048;
   1059  1.1  mycroft 		break;
   1060  1.1  mycroft 	}
   1061  1.1  mycroft 
   1062  1.1  mycroft 	/* Attach the interface. */
   1063  1.1  mycroft 	if_attach(ifp);
   1064  1.1  mycroft 	ether_ifattach(ifp);
   1065  1.1  mycroft 
   1066  1.1  mycroft 	/* Print additional info when attached. */
   1067  1.1  mycroft 	printf(": address %s, type %s\n",
   1068  1.1  mycroft 	    ether_sprintf(sc->sc_arpcom.ac_enaddr), sc->typestr);
   1069  1.1  mycroft #if FE_DEBUG >= 3
   1070  1.1  mycroft 	{
   1071  1.1  mycroft 		int buf, txb, bbw, sbw, ram;
   1072  1.1  mycroft 
   1073  1.1  mycroft 		buf = txb = bbw = sbw = ram = -1;
   1074  1.1  mycroft 		switch (sc->proto_dlcr6 & FE_D6_BUFSIZ) {
   1075  1.1  mycroft 		case FE_D6_BUFSIZ_8KB:
   1076  1.1  mycroft 			buf = 8;
   1077  1.1  mycroft 			break;
   1078  1.1  mycroft 		case FE_D6_BUFSIZ_16KB:
   1079  1.1  mycroft 			buf = 16;
   1080  1.1  mycroft 			break;
   1081  1.1  mycroft 		case FE_D6_BUFSIZ_32KB:
   1082  1.1  mycroft 			buf = 32;
   1083  1.1  mycroft 			break;
   1084  1.1  mycroft 		case FE_D6_BUFSIZ_64KB:
   1085  1.1  mycroft 			buf = 64;
   1086  1.1  mycroft 			break;
   1087  1.1  mycroft 		}
   1088  1.1  mycroft 		switch (sc->proto_dlcr6 & FE_D6_TXBSIZ) {
   1089  1.1  mycroft 		case FE_D6_TXBSIZ_2x2KB:
   1090  1.1  mycroft 			txb = 2;
   1091  1.1  mycroft 			break;
   1092  1.1  mycroft 		case FE_D6_TXBSIZ_2x4KB:
   1093  1.1  mycroft 			txb = 4;
   1094  1.1  mycroft 			break;
   1095  1.1  mycroft 		case FE_D6_TXBSIZ_2x8KB:
   1096  1.1  mycroft 			txb = 8;
   1097  1.1  mycroft 			break;
   1098  1.1  mycroft 		}
   1099  1.1  mycroft 		switch (sc->proto_dlcr6 & FE_D6_BBW) {
   1100  1.1  mycroft 		case FE_D6_BBW_BYTE:
   1101  1.1  mycroft 			bbw = 8;
   1102  1.1  mycroft 			break;
   1103  1.1  mycroft 		case FE_D6_BBW_WORD:
   1104  1.1  mycroft 			bbw = 16;
   1105  1.1  mycroft 			break;
   1106  1.1  mycroft 		}
   1107  1.1  mycroft 		switch (sc->proto_dlcr6 & FE_D6_SBW) {
   1108  1.1  mycroft 		case FE_D6_SBW_BYTE:
   1109  1.1  mycroft 			sbw = 8;
   1110  1.1  mycroft 			break;
   1111  1.1  mycroft 		case FE_D6_SBW_WORD:
   1112  1.1  mycroft 			sbw = 16;
   1113  1.1  mycroft 			break;
   1114  1.1  mycroft 		}
   1115  1.1  mycroft 		switch (sc->proto_dlcr6 & FE_D6_SRAM) {
   1116  1.1  mycroft 		case FE_D6_SRAM_100ns:
   1117  1.1  mycroft 			ram = 100;
   1118  1.1  mycroft 			break;
   1119  1.1  mycroft 		case FE_D6_SRAM_150ns:
   1120  1.1  mycroft 			ram = 150;
   1121  1.1  mycroft 			break;
   1122  1.1  mycroft 		}
   1123  1.1  mycroft 		printf("%s: SRAM %dKB %dbit %dns, TXB %dKBx2, %dbit I/O\n",
   1124  1.1  mycroft 		    sc->sc_dev.dv_xname, buf, bbw, ram, txb, sbw);
   1125  1.1  mycroft 	}
   1126  1.1  mycroft #endif
   1127  1.1  mycroft 
   1128  1.1  mycroft #if NBPFILTER > 0
   1129  1.1  mycroft 	/* If BPF is in the kernel, call the attach for it. */
   1130  1.1  mycroft 	bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
   1131  1.1  mycroft #endif
   1132  1.1  mycroft 
   1133  1.1  mycroft 	sc->sc_ih = isa_intr_establish(ia->ia_irq, ISA_IST_EDGE, ISA_IPL_NET,
   1134  1.1  mycroft 	    feintr, sc);
   1135  1.1  mycroft }
   1136  1.1  mycroft 
   1137  1.1  mycroft /*
   1138  1.1  mycroft  * Reset interface.
   1139  1.1  mycroft  */
   1140  1.1  mycroft void
   1141  1.1  mycroft fe_reset(sc)
   1142  1.1  mycroft 	struct fe_softc *sc;
   1143  1.1  mycroft {
   1144  1.1  mycroft 	int s;
   1145  1.1  mycroft 
   1146  1.1  mycroft 	s = splimp();
   1147  1.1  mycroft 	fe_stop(sc);
   1148  1.1  mycroft 	fe_init(sc);
   1149  1.1  mycroft 	splx(s);
   1150  1.1  mycroft }
   1151  1.1  mycroft 
   1152  1.1  mycroft /*
   1153  1.1  mycroft  * Stop everything on the interface.
   1154  1.1  mycroft  *
   1155  1.1  mycroft  * All buffered packets, both transmitting and receiving,
   1156  1.1  mycroft  * if any, will be lost by stopping the interface.
   1157  1.1  mycroft  */
   1158  1.1  mycroft void
   1159  1.1  mycroft fe_stop(sc)
   1160  1.1  mycroft 	struct fe_softc *sc;
   1161  1.1  mycroft {
   1162  1.1  mycroft 
   1163  1.1  mycroft #if FE_DEBUG >= 3
   1164  1.1  mycroft 	log(LOG_INFO, "%s: top of fe_stop()\n", sc->sc_dev.dv_xname);
   1165  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1166  1.1  mycroft #endif
   1167  1.1  mycroft 
   1168  1.1  mycroft 	/* Disable interrupts. */
   1169  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR2, 0x00);
   1170  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR3, 0x00);
   1171  1.1  mycroft 
   1172  1.1  mycroft 	/* Stop interface hardware. */
   1173  1.1  mycroft 	delay(200);
   1174  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
   1175  1.1  mycroft 	delay(200);
   1176  1.1  mycroft 
   1177  1.1  mycroft 	/* Clear all interrupt status. */
   1178  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR0, 0xFF);
   1179  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR1, 0xFF);
   1180  1.1  mycroft 
   1181  1.1  mycroft 	/* Put the chip in stand-by mode. */
   1182  1.1  mycroft 	delay(200);
   1183  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR7, sc->proto_dlcr7 | FE_D7_POWER_DOWN);
   1184  1.1  mycroft 	delay(200);
   1185  1.1  mycroft 
   1186  1.1  mycroft 	/* MAR loading can be delayed. */
   1187  1.1  mycroft 	sc->filter_change = 0;
   1188  1.1  mycroft 
   1189  1.1  mycroft 	/* Call a hook. */
   1190  1.1  mycroft 	if (sc->stop)
   1191  1.1  mycroft 		sc->stop(sc);
   1192  1.1  mycroft 
   1193  1.1  mycroft #if DEBUG >= 3
   1194  1.1  mycroft 	log(LOG_INFO, "%s: end of fe_stop()\n", sc->sc_dev.dv_xname);
   1195  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1196  1.1  mycroft #endif
   1197  1.1  mycroft }
   1198  1.1  mycroft 
   1199  1.1  mycroft /*
   1200  1.1  mycroft  * Device timeout/watchdog routine. Entered if the device neglects to
   1201  1.1  mycroft  * generate an interrupt after a transmit has been started on it.
   1202  1.1  mycroft  */
   1203  1.1  mycroft void
   1204  1.1  mycroft fe_watchdog(unit)
   1205  1.1  mycroft 	int unit;
   1206  1.1  mycroft {
   1207  1.1  mycroft 	struct fe_softc *sc = fecd.cd_devs[unit];
   1208  1.1  mycroft 
   1209  1.1  mycroft 	log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
   1210  1.1  mycroft #if FE_DEBUG >= 3
   1211  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1212  1.1  mycroft #endif
   1213  1.1  mycroft 
   1214  1.1  mycroft 	/* Record how many packets are lost by this accident. */
   1215  1.1  mycroft 	sc->sc_arpcom.ac_if.if_oerrors += sc->txb_sched + sc->txb_count;
   1216  1.1  mycroft 
   1217  1.1  mycroft 	fe_reset(sc);
   1218  1.1  mycroft }
   1219  1.1  mycroft 
   1220  1.1  mycroft /*
   1221  1.1  mycroft  * Initialize device.
   1222  1.1  mycroft  */
   1223  1.1  mycroft void
   1224  1.1  mycroft fe_init(sc)
   1225  1.1  mycroft 	struct fe_softc *sc;
   1226  1.1  mycroft {
   1227  1.1  mycroft 	struct ifnet *ifp = &sc->sc_arpcom.ac_if;
   1228  1.1  mycroft 	int i, s;
   1229  1.1  mycroft 
   1230  1.1  mycroft #if FE_DEBUG >= 3
   1231  1.1  mycroft 	log(LOG_INFO, "%s: top of fe_init()\n", sc->sc_dev.dv_xname);
   1232  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1233  1.1  mycroft #endif
   1234  1.1  mycroft 
   1235  1.1  mycroft 	/* We need an address. */
   1236  1.1  mycroft 	if (ifp->if_addrlist == 0) {
   1237  1.1  mycroft #if FE_DEBUG >= 1
   1238  1.1  mycroft 		log(LOG_ERR, "%s: init() without any address\n",
   1239  1.1  mycroft 		    sc->sc_dev.dv_xname);
   1240  1.1  mycroft #endif
   1241  1.1  mycroft 		return;
   1242  1.1  mycroft 	}
   1243  1.1  mycroft 
   1244  1.1  mycroft 	/* Start initializing 86960. */
   1245  1.1  mycroft 	s = splimp();
   1246  1.1  mycroft 
   1247  1.1  mycroft 	/* Reset transmitter flags. */
   1248  1.1  mycroft 	ifp->if_flags &= ~IFF_OACTIVE;
   1249  1.1  mycroft 	ifp->if_timer = 0;
   1250  1.1  mycroft 
   1251  1.1  mycroft 	sc->txb_free = sc->txb_size;
   1252  1.1  mycroft 	sc->txb_count = 0;
   1253  1.1  mycroft 	sc->txb_sched = 0;
   1254  1.1  mycroft 
   1255  1.1  mycroft 	/* Call a hook. */
   1256  1.1  mycroft 	if (sc->init)
   1257  1.1  mycroft 		sc->init(sc);
   1258  1.1  mycroft 
   1259  1.1  mycroft #if FE_DEBUG >= 3
   1260  1.1  mycroft 	log(LOG_INFO, "%s: after init hook\n", sc->sc_dev.dv_xname);
   1261  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1262  1.1  mycroft #endif
   1263  1.1  mycroft 
   1264  1.1  mycroft 	/*
   1265  1.1  mycroft 	 * Make sure to disable the chip, also.
   1266  1.1  mycroft 	 * This may also help re-programming the chip after
   1267  1.1  mycroft 	 * hot insertion of PCMCIAs.
   1268  1.1  mycroft 	 */
   1269  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
   1270  1.1  mycroft 
   1271  1.1  mycroft 	/* Power up the chip and select register bank for DLCRs. */
   1272  1.1  mycroft 	delay(200);
   1273  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR7,
   1274  1.1  mycroft 	    sc->proto_dlcr7 | FE_D7_RBS_DLCR | FE_D7_POWER_UP);
   1275  1.1  mycroft 	delay(200);
   1276  1.1  mycroft 
   1277  1.1  mycroft 	/* Feed the station address. */
   1278  1.1  mycroft 	outblk(sc->sc_iobase + FE_DLCR8, sc->sc_enaddr, ETHER_ADDR_LEN);
   1279  1.1  mycroft 
   1280  1.1  mycroft 	/* Select the BMPR bank for runtime register access. */
   1281  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR7,
   1282  1.1  mycroft 	    sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP);
   1283  1.1  mycroft 
   1284  1.1  mycroft 	/* Initialize registers. */
   1285  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR0, 0xFF);	/* Clear all bits. */
   1286  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR1, 0xFF);	/* ditto. */
   1287  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR2, 0x00);
   1288  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR3, 0x00);
   1289  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR4, sc->proto_dlcr4);
   1290  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR5, sc->proto_dlcr5);
   1291  1.1  mycroft 	outb(sc->sc_iobase + FE_BMPR10, 0x00);
   1292  1.1  mycroft 	outb(sc->sc_iobase + FE_BMPR11, FE_B11_CTRL_SKIP);
   1293  1.1  mycroft 	outb(sc->sc_iobase + FE_BMPR12, 0x00);
   1294  1.1  mycroft 	outb(sc->sc_iobase + FE_BMPR13, sc->proto_bmpr13);
   1295  1.1  mycroft 	outb(sc->sc_iobase + FE_BMPR14, 0x00);
   1296  1.1  mycroft 	outb(sc->sc_iobase + FE_BMPR15, 0x00);
   1297  1.1  mycroft 
   1298  1.1  mycroft #if FE_DEBUG >= 3
   1299  1.1  mycroft 	log(LOG_INFO, "%s: just before enabling DLC\n", sc->sc_dev.dv_xname);
   1300  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1301  1.1  mycroft #endif
   1302  1.1  mycroft 
   1303  1.1  mycroft 	/* Enable interrupts. */
   1304  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR2, FE_TMASK);
   1305  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR3, FE_RMASK);
   1306  1.1  mycroft 
   1307  1.1  mycroft 	/* Enable transmitter and receiver. */
   1308  1.1  mycroft 	delay(200);
   1309  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_ENABLE);
   1310  1.1  mycroft 	delay(200);
   1311  1.1  mycroft 
   1312  1.1  mycroft #if FE_DEBUG >= 3
   1313  1.1  mycroft 	log(LOG_INFO, "%s: just after enabling DLC\n", sc->sc_dev.dv_xname);
   1314  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1315  1.1  mycroft #endif
   1316  1.1  mycroft 
   1317  1.1  mycroft 	/*
   1318  1.1  mycroft 	 * Make sure to empty the receive buffer.
   1319  1.1  mycroft 	 *
   1320  1.1  mycroft 	 * This may be redundant, but *if* the receive buffer were full
   1321  1.1  mycroft 	 * at this point, the driver would hang.  I have experienced
   1322  1.1  mycroft 	 * some strange hangups just after UP.  I hope the following
   1323  1.1  mycroft 	 * code solve the problem.
   1324  1.1  mycroft 	 *
   1325  1.1  mycroft 	 * I have changed the order of hardware initialization.
   1326  1.1  mycroft 	 * I think the receive buffer cannot have any packets at this
   1327  1.1  mycroft 	 * point in this version.  The following code *must* be
   1328  1.1  mycroft 	 * redundant now.  FIXME.
   1329  1.1  mycroft 	 */
   1330  1.1  mycroft 	for (i = 0; i < FE_MAX_RECV_COUNT; i++) {
   1331  1.1  mycroft 		if (inb(sc->sc_iobase + FE_DLCR5) & FE_D5_BUFEMP)
   1332  1.1  mycroft 			break;
   1333  1.1  mycroft 		outb(sc->sc_iobase + FE_BMPR14, FE_B14_SKIP);
   1334  1.1  mycroft 	}
   1335  1.1  mycroft #if FE_DEBUG >= 1
   1336  1.1  mycroft 	if (i >= FE_MAX_RECV_COUNT) {
   1337  1.1  mycroft 		log(LOG_ERR, "%s: cannot empty receive buffer\n",
   1338  1.1  mycroft 		    sc->sc_dev.dv_xname);
   1339  1.1  mycroft 	}
   1340  1.1  mycroft #endif
   1341  1.1  mycroft #if FE_DEBUG >= 3
   1342  1.1  mycroft 	if (i < FE_MAX_RECV_COUNT) {
   1343  1.1  mycroft 		log(LOG_INFO, "%s: receive buffer emptied (%d)\n",
   1344  1.1  mycroft 		    sc->sc_dev.dv_xname, i);
   1345  1.1  mycroft 	}
   1346  1.1  mycroft #endif
   1347  1.1  mycroft 
   1348  1.1  mycroft #if FE_DEBUG >= 3
   1349  1.1  mycroft 	log(LOG_INFO, "%s: after ERB loop\n", sc->sc_dev.dv_xname);
   1350  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1351  1.1  mycroft #endif
   1352  1.1  mycroft 
   1353  1.1  mycroft 	/* Do we need this here? */
   1354  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR0, 0xFF);	/* Clear all bits. */
   1355  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR1, 0xFF);	/* ditto. */
   1356  1.1  mycroft 
   1357  1.1  mycroft #if FE_DEBUG >= 3
   1358  1.1  mycroft 	log(LOG_INFO, "%s: after FIXME\n", sc->sc_dev.dv_xname);
   1359  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1360  1.1  mycroft #endif
   1361  1.1  mycroft 
   1362  1.1  mycroft 	/* Set 'running' flag. */
   1363  1.1  mycroft 	ifp->if_flags |= IFF_RUNNING;
   1364  1.1  mycroft 
   1365  1.1  mycroft 	/*
   1366  1.1  mycroft 	 * At this point, the interface is runnung properly,
   1367  1.1  mycroft 	 * except that it receives *no* packets.  we then call
   1368  1.1  mycroft 	 * fe_setmode() to tell the chip what packets to be
   1369  1.1  mycroft 	 * received, based on the if_flags and multicast group
   1370  1.1  mycroft 	 * list.  It completes the initialization process.
   1371  1.1  mycroft 	 */
   1372  1.1  mycroft 	fe_setmode(sc);
   1373  1.1  mycroft 
   1374  1.1  mycroft #if FE_DEBUG >= 3
   1375  1.1  mycroft 	log(LOG_INFO, "%s: after setmode\n", sc->sc_dev.dv_xname);
   1376  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1377  1.1  mycroft #endif
   1378  1.1  mycroft 
   1379  1.1  mycroft 	/* ...and attempt to start output. */
   1380  1.1  mycroft 	fe_start(ifp);
   1381  1.1  mycroft 
   1382  1.1  mycroft #if FE_DEBUG >= 3
   1383  1.1  mycroft 	log(LOG_INFO, "%s: end of fe_init()\n", sc->sc_dev.dv_xname);
   1384  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1385  1.1  mycroft #endif
   1386  1.1  mycroft 
   1387  1.1  mycroft 	splx(s);
   1388  1.1  mycroft }
   1389  1.1  mycroft 
   1390  1.1  mycroft /*
   1391  1.1  mycroft  * This routine actually starts the transmission on the interface
   1392  1.1  mycroft  */
   1393  1.1  mycroft static inline void
   1394  1.1  mycroft fe_xmit(sc)
   1395  1.1  mycroft 	struct fe_softc *sc;
   1396  1.1  mycroft {
   1397  1.1  mycroft 
   1398  1.1  mycroft 	/*
   1399  1.1  mycroft 	 * Set a timer just in case we never hear from the board again.
   1400  1.1  mycroft 	 * We use longer timeout for multiple packet transmission.
   1401  1.1  mycroft 	 * I'm not sure this timer value is appropriate.  FIXME.
   1402  1.1  mycroft 	 */
   1403  1.1  mycroft 	sc->sc_arpcom.ac_if.if_timer = 1 + sc->txb_count;
   1404  1.1  mycroft 
   1405  1.1  mycroft 	/* Update txb variables. */
   1406  1.1  mycroft 	sc->txb_sched = sc->txb_count;
   1407  1.1  mycroft 	sc->txb_count = 0;
   1408  1.1  mycroft 	sc->txb_free = sc->txb_size;
   1409  1.1  mycroft 
   1410  1.1  mycroft #if FE_DELAYED_PADDING
   1411  1.1  mycroft 	/* Omit the postponed padding process. */
   1412  1.1  mycroft 	sc->txb_padding = 0;
   1413  1.1  mycroft #endif
   1414  1.1  mycroft 
   1415  1.1  mycroft 	/* Start transmitter, passing packets in TX buffer. */
   1416  1.1  mycroft 	outb(sc->sc_iobase + FE_BMPR10, sc->txb_sched | FE_B10_START);
   1417  1.1  mycroft }
   1418  1.1  mycroft 
   1419  1.1  mycroft /*
   1420  1.1  mycroft  * Start output on interface.
   1421  1.1  mycroft  * We make two assumptions here:
   1422  1.1  mycroft  *  1) that the current priority is set to splimp _before_ this code
   1423  1.1  mycroft  *     is called *and* is returned to the appropriate priority after
   1424  1.1  mycroft  *     return
   1425  1.1  mycroft  *  2) that the IFF_OACTIVE flag is checked before this code is called
   1426  1.1  mycroft  *     (i.e. that the output part of the interface is idle)
   1427  1.1  mycroft  */
   1428  1.1  mycroft void
   1429  1.1  mycroft fe_start(ifp)
   1430  1.1  mycroft 	struct ifnet *ifp;
   1431  1.1  mycroft {
   1432  1.1  mycroft 	struct fe_softc *sc = fecd.cd_devs[ifp->if_unit];
   1433  1.1  mycroft 	struct mbuf *m;
   1434  1.1  mycroft 
   1435  1.1  mycroft #if FE_DEBUG >= 1
   1436  1.1  mycroft 	/* Just a sanity check. */
   1437  1.1  mycroft 	if ((sc->txb_count == 0) != (sc->txb_free == sc->txb_size)) {
   1438  1.1  mycroft 		/*
   1439  1.1  mycroft 		 * Txb_count and txb_free co-works to manage the
   1440  1.1  mycroft 		 * transmission buffer.  Txb_count keeps track of the
   1441  1.1  mycroft 		 * used potion of the buffer, while txb_free does unused
   1442  1.1  mycroft 		 * potion.  So, as long as the driver runs properly,
   1443  1.1  mycroft 		 * txb_count is zero if and only if txb_free is same
   1444  1.1  mycroft 		 * as txb_size (which represents whole buffer.)
   1445  1.1  mycroft 		 */
   1446  1.1  mycroft 		log(LOG_ERR, "%s: inconsistent txb variables (%d, %d)\n",
   1447  1.1  mycroft 		    sc->sc_dev.dv_xname, sc->txb_count, sc->txb_free);
   1448  1.1  mycroft 		/*
   1449  1.1  mycroft 		 * So, what should I do, then?
   1450  1.1  mycroft 		 *
   1451  1.1  mycroft 		 * We now know txb_count and txb_free contradicts.  We
   1452  1.1  mycroft 		 * cannot, however, tell which is wrong.  More
   1453  1.1  mycroft 		 * over, we cannot peek 86960 transmission buffer or
   1454  1.1  mycroft 		 * reset the transmission buffer.  (In fact, we can
   1455  1.1  mycroft 		 * reset the entire interface.  I don't want to do it.)
   1456  1.1  mycroft 		 *
   1457  1.1  mycroft 		 * If txb_count is incorrect, leaving it as is will cause
   1458  1.1  mycroft 		 * sending of gabages after next interrupt.  We have to
   1459  1.1  mycroft 		 * avoid it.  Hence, we reset the txb_count here.  If
   1460  1.1  mycroft 		 * txb_free was incorrect, resetting txb_count just loose
   1461  1.1  mycroft 		 * some packets.  We can live with it.
   1462  1.1  mycroft 		 */
   1463  1.1  mycroft 		sc->txb_count = 0;
   1464  1.1  mycroft 	}
   1465  1.1  mycroft #endif
   1466  1.1  mycroft 
   1467  1.1  mycroft #if FE_DEBUG >= 1
   1468  1.1  mycroft 	/*
   1469  1.1  mycroft 	 * First, see if there are buffered packets and an idle
   1470  1.1  mycroft 	 * transmitter - should never happen at this point.
   1471  1.1  mycroft 	 */
   1472  1.1  mycroft 	if ((sc->txb_count > 0) && (sc->txb_sched == 0)) {
   1473  1.1  mycroft 		log(LOG_ERR, "%s: transmitter idle with %d buffered packets\n",
   1474  1.1  mycroft 		    sc->sc_dev.dv_xname, sc->txb_count);
   1475  1.1  mycroft 		fe_xmit(sc);
   1476  1.1  mycroft 	}
   1477  1.1  mycroft #endif
   1478  1.1  mycroft 
   1479  1.1  mycroft 	/*
   1480  1.1  mycroft 	 * Stop accepting more transmission packets temporarily, when
   1481  1.1  mycroft 	 * a filter change request is delayed.  Updating the MARs on
   1482  1.1  mycroft 	 * 86960 flushes the transmisstion buffer, so it is delayed
   1483  1.1  mycroft 	 * until all buffered transmission packets have been sent
   1484  1.1  mycroft 	 * out.
   1485  1.1  mycroft 	 */
   1486  1.1  mycroft 	if (sc->filter_change) {
   1487  1.1  mycroft 		/*
   1488  1.1  mycroft 		 * Filter change requst is delayed only when the DLC is
   1489  1.1  mycroft 		 * working.  DLC soon raise an interrupt after finishing
   1490  1.1  mycroft 		 * the work.
   1491  1.1  mycroft 		 */
   1492  1.1  mycroft 		goto indicate_active;
   1493  1.1  mycroft 	}
   1494  1.1  mycroft 
   1495  1.1  mycroft 	for (;;) {
   1496  1.1  mycroft 		/*
   1497  1.1  mycroft 		 * See if there is room to put another packet in the buffer.
   1498  1.1  mycroft 		 * We *could* do better job by peeking the send queue to
   1499  1.1  mycroft 		 * know the length of the next packet.  Current version just
   1500  1.1  mycroft 		 * tests against the worst case (i.e., longest packet).  FIXME.
   1501  1.1  mycroft 		 *
   1502  1.1  mycroft 		 * When adding the packet-peek feature, don't forget adding a
   1503  1.1  mycroft 		 * test on txb_count against QUEUEING_MAX.
   1504  1.1  mycroft 		 * There is a little chance the packet count exceeds
   1505  1.1  mycroft 		 * the limit.  Assume transmission buffer is 8KB (2x8KB
   1506  1.1  mycroft 		 * configuration) and an application sends a bunch of small
   1507  1.1  mycroft 		 * (i.e., minimum packet sized) packets rapidly.  An 8KB
   1508  1.1  mycroft 		 * buffer can hold 130 blocks of 62 bytes long...
   1509  1.1  mycroft 		 */
   1510  1.1  mycroft 		if (sc->txb_free < ETHER_MAX_LEN + FE_DATA_LEN_LEN) {
   1511  1.1  mycroft 			/* No room. */
   1512  1.1  mycroft 			goto indicate_active;
   1513  1.1  mycroft 		}
   1514  1.1  mycroft 
   1515  1.1  mycroft #if FE_SINGLE_TRANSMISSION
   1516  1.1  mycroft 		if (sc->txb_count > 0) {
   1517  1.1  mycroft 			/* Just one packet per a transmission buffer. */
   1518  1.1  mycroft 			goto indicate_active;
   1519  1.1  mycroft 		}
   1520  1.1  mycroft #endif
   1521  1.1  mycroft 
   1522  1.1  mycroft 		/*
   1523  1.1  mycroft 		 * Get the next mbuf chain for a packet to send.
   1524  1.1  mycroft 		 */
   1525  1.1  mycroft 		IF_DEQUEUE(&ifp->if_snd, m);
   1526  1.1  mycroft 		if (m == 0) {
   1527  1.1  mycroft 			/* No more packets to send. */
   1528  1.1  mycroft 			goto indicate_inactive;
   1529  1.1  mycroft 		}
   1530  1.1  mycroft 
   1531  1.1  mycroft 		/*
   1532  1.1  mycroft 		 * Copy the mbuf chain into the transmission buffer.
   1533  1.1  mycroft 		 * txb_* variables are updated as necessary.
   1534  1.1  mycroft 		 */
   1535  1.1  mycroft 		fe_write_mbufs(sc, m);
   1536  1.1  mycroft 
   1537  1.1  mycroft 		/* Start transmitter if it's idle. */
   1538  1.1  mycroft 		if (sc->txb_sched == 0)
   1539  1.1  mycroft 			fe_xmit(sc);
   1540  1.1  mycroft 
   1541  1.1  mycroft #if 0 /* Turned of, since our interface is now duplex. */
   1542  1.1  mycroft 		/*
   1543  1.1  mycroft 		 * Tap off here if there is a bpf listener.
   1544  1.1  mycroft 		 */
   1545  1.1  mycroft #if NBPFILTER > 0
   1546  1.1  mycroft 		if (ifp->if_bpf)
   1547  1.1  mycroft 			bpf_mtap(ifp->if_bpf, m);
   1548  1.1  mycroft #endif
   1549  1.1  mycroft #endif
   1550  1.1  mycroft 
   1551  1.1  mycroft 		m_freem(m);
   1552  1.1  mycroft 	}
   1553  1.1  mycroft 
   1554  1.1  mycroft indicate_inactive:
   1555  1.1  mycroft 	/*
   1556  1.1  mycroft 	 * We are using the !OACTIVE flag to indicate to
   1557  1.1  mycroft 	 * the outside world that we can accept an
   1558  1.1  mycroft 	 * additional packet rather than that the
   1559  1.1  mycroft 	 * transmitter is _actually_ active.  Indeed, the
   1560  1.1  mycroft 	 * transmitter may be active, but if we haven't
   1561  1.1  mycroft 	 * filled all the buffers with data then we still
   1562  1.1  mycroft 	 * want to accept more.
   1563  1.1  mycroft 	 */
   1564  1.1  mycroft 	ifp->if_flags &= ~IFF_OACTIVE;
   1565  1.1  mycroft 	return;
   1566  1.1  mycroft 
   1567  1.1  mycroft indicate_active:
   1568  1.1  mycroft 	/*
   1569  1.1  mycroft 	 * The transmitter is active, and there are no room for
   1570  1.1  mycroft 	 * more outgoing packets in the transmission buffer.
   1571  1.1  mycroft 	 */
   1572  1.1  mycroft 	ifp->if_flags |= IFF_OACTIVE;
   1573  1.1  mycroft 	return;
   1574  1.1  mycroft }
   1575  1.1  mycroft 
   1576  1.1  mycroft /*
   1577  1.1  mycroft  * Drop (skip) a packet from receive buffer in 86960 memory.
   1578  1.1  mycroft  */
   1579  1.1  mycroft static inline void
   1580  1.1  mycroft fe_droppacket (struct fe_softc * sc)
   1581  1.1  mycroft {
   1582  1.1  mycroft 	outb(sc->sc_iobase + FE_BMPR14, FE_B14_SKIP);
   1583  1.1  mycroft }
   1584  1.1  mycroft 
   1585  1.1  mycroft /*
   1586  1.1  mycroft  * Transmission interrupt handler
   1587  1.1  mycroft  * The control flow of this function looks silly.  FIXME.
   1588  1.1  mycroft  */
   1589  1.1  mycroft void
   1590  1.1  mycroft fe_tint(sc, tstat)
   1591  1.1  mycroft 	struct fe_softc *sc;
   1592  1.1  mycroft 	u_char tstat;
   1593  1.1  mycroft {
   1594  1.1  mycroft 	struct ifnet *ifp = &sc->sc_arpcom.ac_if;
   1595  1.1  mycroft 	int left;
   1596  1.1  mycroft 	int col;
   1597  1.1  mycroft 
   1598  1.1  mycroft 	/*
   1599  1.1  mycroft 	 * Handle "excessive collision" interrupt.
   1600  1.1  mycroft 	 */
   1601  1.1  mycroft 	if (tstat & FE_D0_COLL16) {
   1602  1.1  mycroft 		/*
   1603  1.1  mycroft 		 * Find how many packets (including this collided one)
   1604  1.1  mycroft 		 * are left unsent in transmission buffer.
   1605  1.1  mycroft 		 */
   1606  1.1  mycroft 		left = inb(sc->sc_iobase + FE_BMPR10);
   1607  1.1  mycroft 
   1608  1.1  mycroft #if FE_DEBUG >= 2
   1609  1.1  mycroft 		log(LOG_WARNING, "%s: excessive collision (%d/%d)\n",
   1610  1.1  mycroft 		    sc->sc_dev.dv_xname, left, sc->txb_sched);
   1611  1.1  mycroft #endif
   1612  1.1  mycroft #if FE_DEBUG >= 3
   1613  1.1  mycroft 		fe_dump(LOG_INFO, sc);
   1614  1.1  mycroft #endif
   1615  1.1  mycroft 
   1616  1.1  mycroft 		/*
   1617  1.1  mycroft 		 * Update statistics.
   1618  1.1  mycroft 		 */
   1619  1.1  mycroft 		ifp->if_collisions += 16;
   1620  1.1  mycroft 		ifp->if_oerrors++;
   1621  1.1  mycroft 		ifp->if_opackets += sc->txb_sched - left;
   1622  1.1  mycroft 
   1623  1.1  mycroft 		/*
   1624  1.1  mycroft 		 * Collision statistics has been updated.
   1625  1.1  mycroft 		 * Clear the collision flag on 86960 now to avoid confusion.
   1626  1.1  mycroft 		 */
   1627  1.1  mycroft 		outb(sc->sc_iobase + FE_DLCR0, FE_D0_COLLID);
   1628  1.1  mycroft 
   1629  1.1  mycroft 		/*
   1630  1.1  mycroft 		 * Restart transmitter, skipping the
   1631  1.1  mycroft 		 * collided packet.
   1632  1.1  mycroft 		 *
   1633  1.1  mycroft 		 * We *must* skip the packet to keep network running
   1634  1.1  mycroft 		 * properly.  Excessive collision error is an
   1635  1.1  mycroft 		 * indication of the network overload.  If we
   1636  1.1  mycroft 		 * tried sending the same packet after excessive
   1637  1.1  mycroft 		 * collision, the network would be filled with
   1638  1.1  mycroft 		 * out-of-time packets.  Packets belonging
   1639  1.1  mycroft 		 * to reliable transport (such as TCP) are resent
   1640  1.1  mycroft 		 * by some upper layer.
   1641  1.1  mycroft 		 */
   1642  1.1  mycroft 		outb(sc->sc_iobase + FE_BMPR11,
   1643  1.1  mycroft 		    FE_B11_CTRL_SKIP | FE_B11_MODE1);
   1644  1.1  mycroft 		sc->txb_sched = left - 1;
   1645  1.1  mycroft 	}
   1646  1.1  mycroft 
   1647  1.1  mycroft 	/*
   1648  1.1  mycroft 	 * Handle "transmission complete" interrupt.
   1649  1.1  mycroft 	 */
   1650  1.1  mycroft 	if (tstat & FE_D0_TXDONE) {
   1651  1.1  mycroft 		/*
   1652  1.1  mycroft 		 * Add in total number of collisions on last
   1653  1.1  mycroft 		 * transmission.  We also clear "collision occurred" flag
   1654  1.1  mycroft 		 * here.
   1655  1.1  mycroft 		 *
   1656  1.1  mycroft 		 * 86960 has a design flow on collision count on multiple
   1657  1.1  mycroft 		 * packet transmission.  When we send two or more packets
   1658  1.1  mycroft 		 * with one start command (that's what we do when the
   1659  1.1  mycroft 		 * transmission queue is clauded), 86960 informs us number
   1660  1.1  mycroft 		 * of collisions occured on the last packet on the
   1661  1.1  mycroft 		 * transmission only.  Number of collisions on previous
   1662  1.1  mycroft 		 * packets are lost.  I have told that the fact is clearly
   1663  1.1  mycroft 		 * stated in the Fujitsu document.
   1664  1.1  mycroft 		 *
   1665  1.1  mycroft 		 * I considered not to mind it seriously.  Collision
   1666  1.1  mycroft 		 * count is not so important, anyway.  Any comments?  FIXME.
   1667  1.1  mycroft 		 */
   1668  1.1  mycroft 
   1669  1.1  mycroft 		if (inb(sc->sc_iobase + FE_DLCR0) & FE_D0_COLLID) {
   1670  1.1  mycroft 			/* Clear collision flag. */
   1671  1.1  mycroft 			outb(sc->sc_iobase + FE_DLCR0, FE_D0_COLLID);
   1672  1.1  mycroft 
   1673  1.1  mycroft 			/* Extract collision count from 86960. */
   1674  1.1  mycroft 			col = inb(sc->sc_iobase + FE_DLCR4) & FE_D4_COL;
   1675  1.1  mycroft 			if (col == 0) {
   1676  1.1  mycroft 				/*
   1677  1.1  mycroft 				 * Status register indicates collisions,
   1678  1.1  mycroft 				 * while the collision count is zero.
   1679  1.1  mycroft 				 * This can happen after multiple packet
   1680  1.1  mycroft 				 * transmission, indicating that one or more
   1681  1.1  mycroft 				 * previous packet(s) had been collided.
   1682  1.1  mycroft 				 *
   1683  1.1  mycroft 				 * Since the accurate number of collisions
   1684  1.1  mycroft 				 * has been lost, we just guess it as 1;
   1685  1.1  mycroft 				 * Am I too optimistic?  FIXME.
   1686  1.1  mycroft 				 */
   1687  1.1  mycroft 				col = 1;
   1688  1.1  mycroft 			} else
   1689  1.1  mycroft 				col >>= FE_D4_COL_SHIFT;
   1690  1.1  mycroft 			ifp->if_collisions += col;
   1691  1.1  mycroft #if FE_DEBUG >= 4
   1692  1.1  mycroft 			log(LOG_WARNING, "%s: %d collision%s (%d)\n",
   1693  1.1  mycroft 			    sc->sc_dev.dv_xname, col, col == 1 ? "" : "s",
   1694  1.1  mycroft 			    sc->txb_sched);
   1695  1.1  mycroft #endif
   1696  1.1  mycroft 		}
   1697  1.1  mycroft 
   1698  1.1  mycroft 		/*
   1699  1.1  mycroft 		 * Update total number of successfully
   1700  1.1  mycroft 		 * transmitted packets.
   1701  1.1  mycroft 		 */
   1702  1.1  mycroft 		ifp->if_opackets += sc->txb_sched;
   1703  1.1  mycroft 		sc->txb_sched = 0;
   1704  1.1  mycroft 
   1705  1.1  mycroft 		/*
   1706  1.1  mycroft 		 * The transmitter is no more active.
   1707  1.1  mycroft 		 * Reset output active flag and watchdog timer.
   1708  1.1  mycroft 		 */
   1709  1.1  mycroft 		ifp->if_flags &= ~IFF_OACTIVE;
   1710  1.1  mycroft 		ifp->if_timer = 0;
   1711  1.1  mycroft 
   1712  1.1  mycroft 		/*
   1713  1.1  mycroft 		 * If more data is ready to transmit in the buffer, start
   1714  1.1  mycroft 		 * transmitting them.  Otherwise keep transmitter idle,
   1715  1.1  mycroft 		 * even if more data is queued.  This gives receive
   1716  1.1  mycroft 		 * process a slight priority.
   1717  1.1  mycroft 		 */
   1718  1.1  mycroft 		if (sc->txb_count > 0)
   1719  1.1  mycroft 			fe_xmit(sc);
   1720  1.1  mycroft 	}
   1721  1.1  mycroft }
   1722  1.1  mycroft 
   1723  1.1  mycroft /*
   1724  1.1  mycroft  * Ethernet interface receiver interrupt.
   1725  1.1  mycroft  */
   1726  1.1  mycroft void
   1727  1.1  mycroft fe_rint(sc, rstat)
   1728  1.1  mycroft 	struct fe_softc *sc;
   1729  1.1  mycroft 	u_char rstat;
   1730  1.1  mycroft {
   1731  1.1  mycroft 	struct ifnet *ifp = &sc->sc_arpcom.ac_if;
   1732  1.1  mycroft 	int len;
   1733  1.1  mycroft 	u_char status;
   1734  1.1  mycroft 	int i;
   1735  1.1  mycroft 
   1736  1.1  mycroft 	/*
   1737  1.1  mycroft 	 * Update statistics if this interrupt is caused by an error.
   1738  1.1  mycroft 	 */
   1739  1.1  mycroft 	if (rstat & (FE_D1_OVRFLO | FE_D1_CRCERR |
   1740  1.1  mycroft 		     FE_D1_ALGERR | FE_D1_SRTPKT)) {
   1741  1.1  mycroft #if FE_DEBUG >= 3
   1742  1.1  mycroft 		log(LOG_WARNING, "%s: receive error: %b\n",
   1743  1.1  mycroft 		    sc->sc_dev.dv_xname, rstat, FE_D1_ERRBITS);
   1744  1.1  mycroft #endif
   1745  1.1  mycroft 		ifp->if_ierrors++;
   1746  1.1  mycroft 	}
   1747  1.1  mycroft 
   1748  1.1  mycroft 	/*
   1749  1.1  mycroft 	 * MB86960 has a flag indicating "receive queue empty."
   1750  1.1  mycroft 	 * We just loop cheking the flag to pull out all received
   1751  1.1  mycroft 	 * packets.
   1752  1.1  mycroft 	 *
   1753  1.1  mycroft 	 * We limit the number of iterrations to avoid infinite loop.
   1754  1.1  mycroft 	 * It can be caused by a very slow CPU (some broken
   1755  1.1  mycroft 	 * peripheral may insert incredible number of wait cycles)
   1756  1.1  mycroft 	 * or, worse, by a broken MB86960 chip.
   1757  1.1  mycroft 	 */
   1758  1.1  mycroft 	for (i = 0; i < FE_MAX_RECV_COUNT; i++) {
   1759  1.1  mycroft 		/* Stop the iterration if 86960 indicates no packets. */
   1760  1.1  mycroft 		if (inb(sc->sc_iobase + FE_DLCR5) & FE_D5_BUFEMP)
   1761  1.1  mycroft 			break;
   1762  1.1  mycroft 
   1763  1.1  mycroft 		/*
   1764  1.1  mycroft 		 * Extract A receive status byte.
   1765  1.1  mycroft 		 * As our 86960 is in 16 bit bus access mode, we have to
   1766  1.1  mycroft 		 * use inw() to get the status byte.  The significant
   1767  1.1  mycroft 		 * value is returned in lower 8 bits.
   1768  1.1  mycroft 		 */
   1769  1.1  mycroft 		status = (u_char)inw(sc->sc_iobase + FE_BMPR8);
   1770  1.1  mycroft #if FE_DEBUG >= 4
   1771  1.1  mycroft 		log(LOG_INFO, "%s: receive status = %02x\n",
   1772  1.1  mycroft 		    sc->sc_dev.dv_xname, status);
   1773  1.1  mycroft #endif
   1774  1.1  mycroft 
   1775  1.1  mycroft 		/*
   1776  1.1  mycroft 		 * If there was an error, update statistics and drop
   1777  1.1  mycroft 		 * the packet, unless the interface is in promiscuous
   1778  1.1  mycroft 		 * mode.
   1779  1.1  mycroft 		 */
   1780  1.1  mycroft 		if ((status & 0xF0) != 0x20) {	/* XXXX ? */
   1781  1.1  mycroft 			if ((ifp->if_flags & IFF_PROMISC) == 0) {
   1782  1.1  mycroft 				ifp->if_ierrors++;
   1783  1.1  mycroft 				fe_droppacket(sc);
   1784  1.1  mycroft 				continue;
   1785  1.1  mycroft 			}
   1786  1.1  mycroft 		}
   1787  1.1  mycroft 
   1788  1.1  mycroft 		/*
   1789  1.1  mycroft 		 * Extract the packet length.
   1790  1.1  mycroft 		 * It is a sum of a header (14 bytes) and a payload.
   1791  1.1  mycroft 		 * CRC has been stripped off by the 86960.
   1792  1.1  mycroft 		 */
   1793  1.1  mycroft 		len = inw(sc->sc_iobase + FE_BMPR8);
   1794  1.1  mycroft 
   1795  1.1  mycroft 		/*
   1796  1.1  mycroft 		 * MB86965 checks the packet length and drop big packet
   1797  1.1  mycroft 		 * before passing it to us.  There are no chance we can
   1798  1.1  mycroft 		 * get [crufty] packets.  Hence, if the length exceeds
   1799  1.1  mycroft 		 * the specified limit, it means some serious failure,
   1800  1.1  mycroft 		 * such as out-of-sync on receive buffer management.
   1801  1.1  mycroft 		 *
   1802  1.1  mycroft 		 * Is this statement true?  FIXME.
   1803  1.1  mycroft 		 */
   1804  1.1  mycroft 		if (len > ETHER_MAX_LEN || len < ETHER_HDR_SIZE) {
   1805  1.1  mycroft #if FE_DEBUG >= 2
   1806  1.1  mycroft 			log(LOG_WARNING,
   1807  1.1  mycroft 			    "%s: received a %s packet? (%u bytes)\n",
   1808  1.1  mycroft 			    sc->sc_dev.dv_xname,
   1809  1.1  mycroft 			    len < ETHER_HDR_SIZE ? "partial" : "big", len);
   1810  1.1  mycroft #endif
   1811  1.1  mycroft 			ifp->if_ierrors++;
   1812  1.1  mycroft 			fe_droppacket(sc);
   1813  1.1  mycroft 			continue;
   1814  1.1  mycroft 		}
   1815  1.1  mycroft 
   1816  1.1  mycroft 		/*
   1817  1.1  mycroft 		 * Check for a short (RUNT) packet.  We *do* check
   1818  1.1  mycroft 		 * but do nothing other than print a message.
   1819  1.1  mycroft 		 * Short packets are illegal, but does nothing bad
   1820  1.1  mycroft 		 * if it carries data for upper layer.
   1821  1.1  mycroft 		 */
   1822  1.1  mycroft #if FE_DEBUG >= 2
   1823  1.1  mycroft 		if (len < ETHER_MIN_LEN) {
   1824  1.1  mycroft 			log(LOG_WARNING,
   1825  1.1  mycroft 			     "%s: received a short packet? (%u bytes)\n",
   1826  1.1  mycroft 			     sc->sc_dev.dv_xname, len);
   1827  1.1  mycroft 		}
   1828  1.1  mycroft #endif
   1829  1.1  mycroft 
   1830  1.1  mycroft 		/*
   1831  1.1  mycroft 		 * Go get a packet.
   1832  1.1  mycroft 		 */
   1833  1.1  mycroft 		if (!fe_get_packet(sc, len)) {
   1834  1.1  mycroft 			/* Skip a packet, updating statistics. */
   1835  1.1  mycroft #if FE_DEBUG >= 2
   1836  1.1  mycroft 			log(LOG_WARNING,
   1837  1.1  mycroft 			    "%s: out of mbufs; dropping packet (%u bytes)\n",
   1838  1.1  mycroft 			    sc->sc_dev.dv_xname, len);
   1839  1.1  mycroft #endif
   1840  1.1  mycroft 			ifp->if_ierrors++;
   1841  1.1  mycroft 			fe_droppacket(sc);
   1842  1.1  mycroft 
   1843  1.1  mycroft 			/*
   1844  1.1  mycroft 			 * We stop receiving packets, even if there are
   1845  1.1  mycroft 			 * more in the buffer.  We hope we can get more
   1846  1.1  mycroft 			 * mbufs next time.
   1847  1.1  mycroft 			 */
   1848  1.1  mycroft 			return;
   1849  1.1  mycroft 		}
   1850  1.1  mycroft 
   1851  1.1  mycroft 		/* Successfully received a packet.  Update stat. */
   1852  1.1  mycroft 		ifp->if_ipackets++;
   1853  1.1  mycroft 	}
   1854  1.1  mycroft }
   1855  1.1  mycroft 
   1856  1.1  mycroft /*
   1857  1.1  mycroft  * Ethernet interface interrupt processor
   1858  1.1  mycroft  */
   1859  1.1  mycroft int
   1860  1.1  mycroft feintr(arg)
   1861  1.1  mycroft 	void *arg;
   1862  1.1  mycroft {
   1863  1.1  mycroft 	struct fe_softc *sc = arg;
   1864  1.1  mycroft 	u_char tstat, rstat;
   1865  1.1  mycroft 
   1866  1.1  mycroft #if FE_DEBUG >= 4
   1867  1.1  mycroft 	log(LOG_INFO, "%s: feintr()\n", sc->sc_dev.dv_xname);
   1868  1.1  mycroft 	fe_dump(LOG_INFO, sc);
   1869  1.1  mycroft #endif
   1870  1.1  mycroft 
   1871  1.1  mycroft 	/*
   1872  1.1  mycroft 	 * Get interrupt conditions, masking unneeded flags.
   1873  1.1  mycroft 	 */
   1874  1.1  mycroft 	tstat = inb(sc->sc_iobase + FE_DLCR0) & FE_TMASK;
   1875  1.1  mycroft 	rstat = inb(sc->sc_iobase + FE_DLCR1) & FE_RMASK;
   1876  1.1  mycroft 	if (tstat == 0 && rstat == 0)
   1877  1.1  mycroft 		return (0);
   1878  1.1  mycroft 
   1879  1.1  mycroft 	/*
   1880  1.1  mycroft 	 * Loop until there are no more new interrupt conditions.
   1881  1.1  mycroft 	 */
   1882  1.1  mycroft 	for (;;) {
   1883  1.1  mycroft 		/*
   1884  1.1  mycroft 		 * Reset the conditions we are acknowledging.
   1885  1.1  mycroft 		 */
   1886  1.1  mycroft 		outb(sc->sc_iobase + FE_DLCR0, tstat);
   1887  1.1  mycroft 		outb(sc->sc_iobase + FE_DLCR1, rstat);
   1888  1.1  mycroft 
   1889  1.1  mycroft 		/*
   1890  1.1  mycroft 		 * Handle transmitter interrupts. Handle these first because
   1891  1.1  mycroft 		 * the receiver will reset the board under some conditions.
   1892  1.1  mycroft 		 */
   1893  1.1  mycroft 		if (tstat != 0)
   1894  1.1  mycroft 			fe_tint(sc, tstat);
   1895  1.1  mycroft 
   1896  1.1  mycroft 		/*
   1897  1.1  mycroft 		 * Handle receiver interrupts.
   1898  1.1  mycroft 		 */
   1899  1.1  mycroft 		if (rstat != 0)
   1900  1.1  mycroft 			fe_rint(sc, rstat);
   1901  1.1  mycroft 
   1902  1.1  mycroft 		/*
   1903  1.1  mycroft 		 * Update the multicast address filter if it is
   1904  1.1  mycroft 		 * needed and possible.  We do it now, because
   1905  1.1  mycroft 		 * we can make sure the transmission buffer is empty,
   1906  1.1  mycroft 		 * and there is a good chance that the receive queue
   1907  1.1  mycroft 		 * is empty.  It will minimize the possibility of
   1908  1.1  mycroft 		 * packet lossage.
   1909  1.1  mycroft 		 */
   1910  1.1  mycroft 		if (sc->filter_change &&
   1911  1.1  mycroft 		    sc->txb_count == 0 && sc->txb_sched == 0) {
   1912  1.1  mycroft 			fe_loadmar(sc);
   1913  1.1  mycroft 			sc->sc_arpcom.ac_if.if_flags &= ~IFF_OACTIVE;
   1914  1.1  mycroft 		}
   1915  1.1  mycroft 
   1916  1.1  mycroft 		/*
   1917  1.1  mycroft 		 * If it looks like the transmitter can take more data,
   1918  1.1  mycroft 		 * attempt to start output on the interface. This is done
   1919  1.1  mycroft 		 * after handling the receiver interrupt to give the
   1920  1.1  mycroft 		 * receive operation priority.
   1921  1.1  mycroft 		 */
   1922  1.1  mycroft 		if ((sc->sc_arpcom.ac_if.if_flags & IFF_OACTIVE) == 0)
   1923  1.1  mycroft 			fe_start(&sc->sc_arpcom.ac_if);
   1924  1.1  mycroft 
   1925  1.1  mycroft 		/*
   1926  1.1  mycroft 		 * Get interrupt conditions, masking unneeded flags.
   1927  1.1  mycroft 		 */
   1928  1.1  mycroft 		tstat = inb(sc->sc_iobase + FE_DLCR0) & FE_TMASK;
   1929  1.1  mycroft 		rstat = inb(sc->sc_iobase + FE_DLCR1) & FE_RMASK;
   1930  1.1  mycroft 		if (tstat == 0 && rstat == 0)
   1931  1.1  mycroft 			return (1);
   1932  1.1  mycroft 	}
   1933  1.1  mycroft }
   1934  1.1  mycroft 
   1935  1.1  mycroft /*
   1936  1.1  mycroft  * Process an ioctl request.  This code needs some work - it looks pretty ugly.
   1937  1.1  mycroft  */
   1938  1.1  mycroft int
   1939  1.1  mycroft fe_ioctl(ifp, command, data)
   1940  1.1  mycroft 	register struct ifnet *ifp;
   1941  1.1  mycroft 	u_long command;
   1942  1.1  mycroft 	caddr_t data;
   1943  1.1  mycroft {
   1944  1.1  mycroft 	struct fe_softc *sc = fecd.cd_devs[ifp->if_unit];
   1945  1.1  mycroft 	register struct ifaddr *ifa = (struct ifaddr *)data;
   1946  1.1  mycroft 	struct ifreq *ifr = (struct ifreq *)data;
   1947  1.1  mycroft 	int s, error = 0;
   1948  1.1  mycroft 
   1949  1.1  mycroft #if FE_DEBUG >= 3
   1950  1.1  mycroft 	log(LOG_INFO, "%s: ioctl(%x)\n", sc->sc_dev.dv_xname, command);
   1951  1.1  mycroft #endif
   1952  1.1  mycroft 
   1953  1.1  mycroft 	s = splimp();
   1954  1.1  mycroft 
   1955  1.1  mycroft 	switch (command) {
   1956  1.1  mycroft 
   1957  1.1  mycroft 	case SIOCSIFADDR:
   1958  1.1  mycroft 		ifp->if_flags |= IFF_UP;
   1959  1.1  mycroft 
   1960  1.1  mycroft 		switch (ifa->ifa_addr->sa_family) {
   1961  1.1  mycroft #ifdef INET
   1962  1.1  mycroft 		case AF_INET:
   1963  1.1  mycroft 			fe_init(sc);
   1964  1.1  mycroft 			arp_ifinit(&sc->sc_arpcom, ifa);
   1965  1.1  mycroft 			break;
   1966  1.1  mycroft #endif
   1967  1.1  mycroft #ifdef NS
   1968  1.1  mycroft 		case AF_NS:
   1969  1.1  mycroft 		    {
   1970  1.1  mycroft 			register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
   1971  1.1  mycroft 
   1972  1.1  mycroft 			if (ns_nullhost(*ina))
   1973  1.1  mycroft 				ina->x_host =
   1974  1.1  mycroft 				    *(union ns_host *)(sc->sc_arpcom.ac_enaddr);
   1975  1.1  mycroft 			else
   1976  1.1  mycroft 				bcopy(ina->x_host.c_host,
   1977  1.1  mycroft 				    sc->sc_arpcom.ac_enaddr,
   1978  1.1  mycroft 				    sizeof(sc->sc_arpcom.ac_enaddr));
   1979  1.1  mycroft 			/* Set new address. */
   1980  1.1  mycroft 			fe_init(sc);
   1981  1.1  mycroft 			break;
   1982  1.1  mycroft 		    }
   1983  1.1  mycroft #endif
   1984  1.1  mycroft 		default:
   1985  1.1  mycroft 			fe_init(sc);
   1986  1.1  mycroft 			break;
   1987  1.1  mycroft 		}
   1988  1.1  mycroft 		break;
   1989  1.1  mycroft 
   1990  1.1  mycroft 	case SIOCSIFFLAGS:
   1991  1.1  mycroft 		if ((ifp->if_flags & IFF_UP) == 0 &&
   1992  1.1  mycroft 		    (ifp->if_flags & IFF_RUNNING) != 0) {
   1993  1.1  mycroft 			/*
   1994  1.1  mycroft 			 * If interface is marked down and it is running, then
   1995  1.1  mycroft 			 * stop it.
   1996  1.1  mycroft 			 */
   1997  1.1  mycroft 			fe_stop(sc);
   1998  1.1  mycroft 			ifp->if_flags &= ~IFF_RUNNING;
   1999  1.1  mycroft 		} else if ((ifp->if_flags & IFF_UP) != 0 &&
   2000  1.1  mycroft 			   (ifp->if_flags & IFF_RUNNING) == 0) {
   2001  1.1  mycroft 			/*
   2002  1.1  mycroft 			 * If interface is marked up and it is stopped, then
   2003  1.1  mycroft 			 * start it.
   2004  1.1  mycroft 			 */
   2005  1.1  mycroft 			fe_init(sc);
   2006  1.1  mycroft 		} else {
   2007  1.1  mycroft 			/*
   2008  1.1  mycroft 			 * Reset the interface to pick up changes in any other
   2009  1.1  mycroft 			 * flags that affect hardware registers.
   2010  1.1  mycroft 			 */
   2011  1.1  mycroft 			fe_setmode(sc);
   2012  1.1  mycroft 		}
   2013  1.1  mycroft #if DEBUG >= 1
   2014  1.1  mycroft 		/* "ifconfig fe0 debug" to print register dump. */
   2015  1.1  mycroft 		if (ifp->if_flags & IFF_DEBUG) {
   2016  1.1  mycroft 			log(LOG_INFO, "%s: SIOCSIFFLAGS(DEBUG)\n", sc->sc_dev.dv_xname);
   2017  1.1  mycroft 			fe_dump(LOG_DEBUG, sc);
   2018  1.1  mycroft 		}
   2019  1.1  mycroft #endif
   2020  1.1  mycroft 		break;
   2021  1.1  mycroft 
   2022  1.1  mycroft 	case SIOCADDMULTI:
   2023  1.1  mycroft 	case SIOCDELMULTI:
   2024  1.1  mycroft 		/* Update our multicast list. */
   2025  1.1  mycroft 		error = (command == SIOCADDMULTI) ?
   2026  1.1  mycroft 		    ether_addmulti(ifr, &sc->sc_arpcom) :
   2027  1.1  mycroft 		    ether_delmulti(ifr, &sc->sc_arpcom);
   2028  1.1  mycroft 
   2029  1.1  mycroft 		if (error == ENETRESET) {
   2030  1.1  mycroft 			/*
   2031  1.1  mycroft 			 * Multicast list has changed; set the hardware filter
   2032  1.1  mycroft 			 * accordingly.
   2033  1.1  mycroft 			 */
   2034  1.1  mycroft 			fe_setmode(sc);
   2035  1.1  mycroft 			error = 0;
   2036  1.1  mycroft 		}
   2037  1.1  mycroft 		break;
   2038  1.1  mycroft 
   2039  1.1  mycroft 	default:
   2040  1.1  mycroft 		error = EINVAL;
   2041  1.1  mycroft 	}
   2042  1.1  mycroft 
   2043  1.1  mycroft 	splx(s);
   2044  1.1  mycroft 	return (error);
   2045  1.1  mycroft }
   2046  1.1  mycroft 
   2047  1.1  mycroft /*
   2048  1.1  mycroft  * Retreive packet from receive buffer and send to the next level up via
   2049  1.1  mycroft  * ether_input(). If there is a BPF listener, give a copy to BPF, too.
   2050  1.1  mycroft  * Returns 0 if success, -1 if error (i.e., mbuf allocation failure).
   2051  1.1  mycroft  */
   2052  1.1  mycroft int
   2053  1.1  mycroft fe_get_packet(sc, len)
   2054  1.1  mycroft 	struct fe_softc *sc;
   2055  1.1  mycroft 	int len;
   2056  1.1  mycroft {
   2057  1.1  mycroft 	struct ether_header *eh;
   2058  1.1  mycroft 	struct mbuf *m;
   2059  1.1  mycroft 	struct ifnet *ifp = &sc->sc_arpcom.ac_if;
   2060  1.1  mycroft 
   2061  1.1  mycroft 	/* Allocate a header mbuf. */
   2062  1.1  mycroft 	MGETHDR(m, M_DONTWAIT, MT_DATA);
   2063  1.1  mycroft 	if (m == 0)
   2064  1.1  mycroft 		return (0);
   2065  1.1  mycroft 	m->m_pkthdr.rcvif = ifp;
   2066  1.1  mycroft 	m->m_pkthdr.len = len;
   2067  1.1  mycroft 
   2068  1.1  mycroft 	/* The following silliness is to make NFS happy. */
   2069  1.1  mycroft #define	EROUND	((sizeof(struct ether_header) + 3) & ~3)
   2070  1.1  mycroft #define	EOFF	(EROUND - sizeof(struct ether_header))
   2071  1.1  mycroft 
   2072  1.1  mycroft #if 0
   2073  1.1  mycroft 	/*
   2074  1.1  mycroft 	 * This function assumes that an Ethernet packet fits in an
   2075  1.1  mycroft 	 * mbuf (with a cluster attached when necessary.)  On FreeBSD
   2076  1.1  mycroft 	 * 2.0 for x86, which is the primary target of this driver, an
   2077  1.1  mycroft 	 * mbuf cluster has 4096 bytes, and we are happy.  On ancient
   2078  1.1  mycroft 	 * BSDs, such as vanilla 4.3 for 386, a cluster size was 1024,
   2079  1.1  mycroft 	 * however.  If the following #error message were printed upon
   2080  1.1  mycroft 	 * compile, you need to rewrite this function.
   2081  1.1  mycroft 	 */
   2082  1.1  mycroft #if (MCLBYTES < ETHER_MAX_LEN + EOFF)
   2083  1.1  mycroft #error "Too small MCLBYTES to use fe driver."
   2084  1.1  mycroft #endif
   2085  1.1  mycroft #endif
   2086  1.1  mycroft 
   2087  1.1  mycroft 	/*
   2088  1.1  mycroft 	 * Our strategy has one more problem.  There is a policy on
   2089  1.1  mycroft 	 * mbuf cluster allocation.  It says that we must have at
   2090  1.1  mycroft 	 * least MINCLSIZE (208 bytes on FreeBSD 2.0 for x86) to
   2091  1.1  mycroft 	 * allocate a cluster.  For a packet of a size between
   2092  1.1  mycroft 	 * (MHLEN - 2) to (MINCLSIZE - 2), our code violates the rule...
   2093  1.1  mycroft 	 * On the other hand, the current code is short, simle,
   2094  1.1  mycroft 	 * and fast, however.  It does no harmful thing, just waists
   2095  1.1  mycroft 	 * some memory.  Any comments?  FIXME.
   2096  1.1  mycroft 	 */
   2097  1.1  mycroft 
   2098  1.1  mycroft 	/* Attach a cluster if this packet doesn't fit in a normal mbuf. */
   2099  1.1  mycroft 	if (len > MHLEN - EOFF) {
   2100  1.1  mycroft 		MCLGET(m, M_DONTWAIT);
   2101  1.1  mycroft 		if ((m->m_flags & M_EXT) == 0) {
   2102  1.1  mycroft 			m_freem(m);
   2103  1.1  mycroft 			return (0);
   2104  1.1  mycroft 		}
   2105  1.1  mycroft 	}
   2106  1.1  mycroft 
   2107  1.1  mycroft 	/*
   2108  1.1  mycroft 	 * The following assumes there is room for the ether header in the
   2109  1.1  mycroft 	 * header mbuf.
   2110  1.1  mycroft 	 */
   2111  1.1  mycroft 	m->m_data += EOFF;
   2112  1.1  mycroft 	eh = mtod(m, struct ether_header *);
   2113  1.1  mycroft 
   2114  1.1  mycroft 	/* Set the length of this packet. */
   2115  1.1  mycroft 	m->m_len = len;
   2116  1.1  mycroft 
   2117  1.1  mycroft 	/* Get a packet. */
   2118  1.1  mycroft 	insw(sc->sc_iobase + FE_BMPR8, m->m_data, (len + 1) >> 1);
   2119  1.1  mycroft 
   2120  1.1  mycroft #if NBPFILTER > 0
   2121  1.1  mycroft 	/*
   2122  1.1  mycroft 	 * Check if there's a BPF listener on this interface.  If so, hand off
   2123  1.1  mycroft 	 * the raw packet to bpf.
   2124  1.1  mycroft 	 */
   2125  1.1  mycroft 	if (ifp->if_bpf) {
   2126  1.1  mycroft 		bpf_mtap(ifp->if_bpf, m);
   2127  1.1  mycroft 
   2128  1.1  mycroft 		/*
   2129  1.1  mycroft 		 * Note that the interface cannot be in promiscuous mode if
   2130  1.1  mycroft 		 * there are no BPF listeners.  And if we are in promiscuous
   2131  1.1  mycroft 		 * mode, we have to check if this packet is really ours.
   2132  1.1  mycroft 		 */
   2133  1.1  mycroft 		if ((ifp->if_flags & IFF_PROMISC) != 0 &&
   2134  1.1  mycroft 		    (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
   2135  1.1  mycroft 	  	    bcmp(eh->ether_dhost, sc->sc_arpcom.ac_enaddr,
   2136  1.1  mycroft 			    sizeof(eh->ether_dhost)) != 0) {
   2137  1.1  mycroft 			m_freem(m);
   2138  1.1  mycroft 			return (1);
   2139  1.1  mycroft 		}
   2140  1.1  mycroft 	}
   2141  1.1  mycroft #endif
   2142  1.1  mycroft 
   2143  1.1  mycroft 	/* Fix up data start offset in mbuf to point past ether header. */
   2144  1.1  mycroft 	m_adj(m, sizeof(struct ether_header));
   2145  1.1  mycroft 	ether_input(ifp, eh, m);
   2146  1.1  mycroft 	return (1);
   2147  1.1  mycroft }
   2148  1.1  mycroft 
   2149  1.1  mycroft /*
   2150  1.1  mycroft  * Write an mbuf chain to the transmission buffer memory using 16 bit PIO.
   2151  1.1  mycroft  * Returns number of bytes actually written, including length word.
   2152  1.1  mycroft  *
   2153  1.1  mycroft  * If an mbuf chain is too long for an Ethernet frame, it is not sent.
   2154  1.1  mycroft  * Packets shorter than Ethernet minimum are legal, and we pad them
   2155  1.1  mycroft  * before sending out.  An exception is "partial" packets which are
   2156  1.1  mycroft  * shorter than mandatory Ethernet header.
   2157  1.1  mycroft  *
   2158  1.1  mycroft  * I wrote a code for an experimental "delayed padding" technique.
   2159  1.1  mycroft  * When employed, it postpones the padding process for short packets.
   2160  1.1  mycroft  * If xmit() occured at the moment, the padding process is omitted, and
   2161  1.1  mycroft  * garbages are sent as pad data.  If next packet is stored in the
   2162  1.1  mycroft  * transmission buffer before xmit(), write_mbuf() pads the previous
   2163  1.1  mycroft  * packet before transmitting new packet.  This *may* gain the
   2164  1.1  mycroft  * system performance (slightly).
   2165  1.1  mycroft  */
   2166  1.1  mycroft void
   2167  1.1  mycroft fe_write_mbufs(sc, m)
   2168  1.1  mycroft 	struct fe_softc *sc;
   2169  1.1  mycroft 	struct mbuf *m;
   2170  1.1  mycroft {
   2171  1.1  mycroft 	int bmpr8 = sc->sc_iobase + FE_BMPR8;
   2172  1.1  mycroft 	struct mbuf *mp;
   2173  1.1  mycroft 	u_char *data;
   2174  1.1  mycroft 	u_short savebyte;	/* WARNING: Architecture dependent! */
   2175  1.1  mycroft 	int totlen, len, wantbyte;
   2176  1.1  mycroft 
   2177  1.1  mycroft #if FE_DELAYED_PADDING
   2178  1.1  mycroft 	/* Do the "delayed padding." */
   2179  1.1  mycroft 	len = sc->txb_padding >> 1;
   2180  1.1  mycroft 	if (len > 0) {
   2181  1.1  mycroft 		while (--len >= 0)
   2182  1.1  mycroft 			outw(bmpr8, 0);
   2183  1.1  mycroft 		sc->txb_padding = 0;
   2184  1.1  mycroft 	}
   2185  1.1  mycroft #endif
   2186  1.1  mycroft 
   2187  1.1  mycroft #if FE_DEBUG >= 2
   2188  1.1  mycroft 	/* First, count up the total number of bytes to copy. */
   2189  1.1  mycroft 	for (totlen = 0, mp = m; mp != 0; mp = mp->m_next)
   2190  1.1  mycroft 		totlen += mp->m_len;
   2191  1.1  mycroft 	/* Check if this matches the one in the packet header. */
   2192  1.1  mycroft 	if (totlen != m->m_pkthdr.len)
   2193  1.1  mycroft 		log(LOG_WARNING, "%s: packet length mismatch? (%d/%d)\n",
   2194  1.1  mycroft 		    sc->sc_dev.dv_xname, totlen, m->m_pkthdr.len);
   2195  1.1  mycroft #else
   2196  1.1  mycroft 	/* Just use the length value in the packet header. */
   2197  1.1  mycroft 	totlen = m->m_pkthdr.len;
   2198  1.1  mycroft #endif
   2199  1.1  mycroft 
   2200  1.1  mycroft #if FE_DEBUG >= 1
   2201  1.1  mycroft 	/*
   2202  1.1  mycroft 	 * Should never send big packets.  If such a packet is passed,
   2203  1.1  mycroft 	 * it should be a bug of upper layer.  We just ignore it.
   2204  1.1  mycroft 	 * ... Partial (too short) packets, neither.
   2205  1.1  mycroft 	 */
   2206  1.1  mycroft 	if (totlen > ETHER_MAX_LEN || totlen < ETHER_HDR_SIZE) {
   2207  1.1  mycroft 		log(LOG_ERR, "%s: got a %s packet (%u bytes) to send\n",
   2208  1.1  mycroft 		    sc->sc_dev.dv_xname,
   2209  1.1  mycroft 		    totlen < ETHER_HDR_SIZE ? "partial" : "big", totlen);
   2210  1.1  mycroft 		sc->sc_arpcom.ac_if.if_oerrors++;
   2211  1.1  mycroft 		return;
   2212  1.1  mycroft 	}
   2213  1.1  mycroft #endif
   2214  1.1  mycroft 
   2215  1.1  mycroft 	/*
   2216  1.1  mycroft 	 * Put the length word for this frame.
   2217  1.1  mycroft 	 * Does 86960 accept odd length?  -- Yes.
   2218  1.1  mycroft 	 * Do we need to pad the length to minimum size by ourselves?
   2219  1.1  mycroft 	 * -- Generally yes.  But for (or will be) the last
   2220  1.1  mycroft 	 * packet in the transmission buffer, we can skip the
   2221  1.1  mycroft 	 * padding process.  It may gain performance slightly.  FIXME.
   2222  1.1  mycroft 	 */
   2223  1.1  mycroft 	outw(bmpr8, max(totlen, ETHER_MIN_LEN));
   2224  1.1  mycroft 
   2225  1.1  mycroft 	/*
   2226  1.1  mycroft 	 * Update buffer status now.
   2227  1.1  mycroft 	 * Truncate the length up to an even number, since we use outw().
   2228  1.1  mycroft 	 */
   2229  1.1  mycroft 	totlen = (totlen + 1) & ~1;
   2230  1.1  mycroft 	sc->txb_free -= FE_DATA_LEN_LEN + max(totlen, ETHER_MIN_LEN);
   2231  1.1  mycroft 	sc->txb_count++;
   2232  1.1  mycroft 
   2233  1.1  mycroft #if FE_DELAYED_PADDING
   2234  1.1  mycroft 	/* Postpone the packet padding if necessary. */
   2235  1.1  mycroft 	if (totlen < ETHER_MIN_LEN)
   2236  1.1  mycroft 		sc->txb_padding = ETHER_MIN_LEN - totlen;
   2237  1.1  mycroft #endif
   2238  1.1  mycroft 
   2239  1.1  mycroft 	/*
   2240  1.1  mycroft 	 * Transfer the data from mbuf chain to the transmission buffer.
   2241  1.1  mycroft 	 * MB86960 seems to require that data be transferred as words, and
   2242  1.1  mycroft 	 * only words.  So that we require some extra code to patch
   2243  1.1  mycroft 	 * over odd-length mbufs.
   2244  1.1  mycroft 	 */
   2245  1.1  mycroft 	wantbyte = 0;
   2246  1.1  mycroft 	for (; m != 0; m = m->m_next) {
   2247  1.1  mycroft 		/* Ignore empty mbuf. */
   2248  1.1  mycroft 		len = m->m_len;
   2249  1.1  mycroft 		if (len == 0)
   2250  1.1  mycroft 			continue;
   2251  1.1  mycroft 
   2252  1.1  mycroft 		/* Find the actual data to send. */
   2253  1.1  mycroft 		data = mtod(m, caddr_t);
   2254  1.1  mycroft 
   2255  1.1  mycroft 		/* Finish the last byte. */
   2256  1.1  mycroft 		if (wantbyte) {
   2257  1.1  mycroft 			outw(bmpr8, savebyte | (*data << 8));
   2258  1.1  mycroft 			data++;
   2259  1.1  mycroft 			len--;
   2260  1.1  mycroft 			wantbyte = 0;
   2261  1.1  mycroft 		}
   2262  1.1  mycroft 
   2263  1.1  mycroft 		/* Output contiguous words. */
   2264  1.1  mycroft 		if (len > 1)
   2265  1.1  mycroft 			outsw(bmpr8, data, len >> 1);
   2266  1.1  mycroft 
   2267  1.1  mycroft 		/* Save remaining byte, if there is one. */
   2268  1.1  mycroft 		if (len & 1) {
   2269  1.1  mycroft 			data += len & ~1;
   2270  1.1  mycroft 			savebyte = *data;
   2271  1.1  mycroft 			wantbyte = 1;
   2272  1.1  mycroft 		}
   2273  1.1  mycroft 	}
   2274  1.1  mycroft 
   2275  1.1  mycroft 	/* Spit the last byte, if the length is odd. */
   2276  1.1  mycroft 	if (wantbyte)
   2277  1.1  mycroft 		outw(bmpr8, savebyte);
   2278  1.1  mycroft 
   2279  1.1  mycroft #if ! FE_DELAYED_PADDING
   2280  1.1  mycroft 	/*
   2281  1.1  mycroft 	 * Pad the packet to the minimum length if necessary.
   2282  1.1  mycroft 	 */
   2283  1.1  mycroft 	len = (ETHER_MIN_LEN >> 1) - (totlen >> 1);
   2284  1.1  mycroft 	while (--len >= 0)
   2285  1.1  mycroft 		outw(bmpr8, 0);
   2286  1.1  mycroft #endif
   2287  1.1  mycroft }
   2288  1.1  mycroft 
   2289  1.1  mycroft /*
   2290  1.1  mycroft  * Compute the multicast address filter from the
   2291  1.1  mycroft  * list of multicast addresses we need to listen to.
   2292  1.1  mycroft  */
   2293  1.1  mycroft void
   2294  1.1  mycroft fe_getmcaf(ac, af)
   2295  1.1  mycroft 	struct arpcom *ac;
   2296  1.1  mycroft 	u_char *af;
   2297  1.1  mycroft {
   2298  1.1  mycroft 	struct ifnet *ifp = &ac->ac_if;
   2299  1.1  mycroft 	struct ether_multi *enm;
   2300  1.1  mycroft 	register u_char *cp, c;
   2301  1.1  mycroft 	register u_long crc;
   2302  1.1  mycroft 	register int i, len;
   2303  1.1  mycroft 	struct ether_multistep step;
   2304  1.1  mycroft 
   2305  1.1  mycroft 	/*
   2306  1.1  mycroft 	 * Set up multicast address filter by passing all multicast addresses
   2307  1.1  mycroft 	 * through a crc generator, and then using the high order 6 bits as an
   2308  1.1  mycroft 	 * index into the 64 bit logical address filter.  The high order bit
   2309  1.1  mycroft 	 * selects the word, while the rest of the bits select the bit within
   2310  1.1  mycroft 	 * the word.
   2311  1.1  mycroft 	 */
   2312  1.1  mycroft 
   2313  1.1  mycroft 	if ((ifp->if_flags & IFF_PROMISC) != 0)
   2314  1.1  mycroft 		goto allmulti;
   2315  1.1  mycroft 
   2316  1.1  mycroft 	af[0] = af[1] = af[2] = af[3] = af[4] = af[5] = af[6] = af[7] = 0x00;
   2317  1.1  mycroft 	ETHER_FIRST_MULTI(step, ac, enm);
   2318  1.1  mycroft 	while (enm != NULL) {
   2319  1.1  mycroft 		if (bcmp(enm->enm_addrlo, enm->enm_addrhi,
   2320  1.1  mycroft 		    sizeof(enm->enm_addrlo)) != 0) {
   2321  1.1  mycroft 			/*
   2322  1.1  mycroft 			 * We must listen to a range of multicast addresses.
   2323  1.1  mycroft 			 * For now, just accept all multicasts, rather than
   2324  1.1  mycroft 			 * trying to set only those filter bits needed to match
   2325  1.1  mycroft 			 * the range.  (At this time, the only use of address
   2326  1.1  mycroft 			 * ranges is for IP multicast routing, for which the
   2327  1.1  mycroft 			 * range is big enough to require all bits set.)
   2328  1.1  mycroft 			 */
   2329  1.1  mycroft 			goto allmulti;
   2330  1.1  mycroft 		}
   2331  1.1  mycroft 
   2332  1.1  mycroft 		cp = enm->enm_addrlo;
   2333  1.1  mycroft 		crc = 0xffffffff;
   2334  1.1  mycroft 		for (len = sizeof(enm->enm_addrlo); --len >= 0;) {
   2335  1.1  mycroft 			c = *cp++;
   2336  1.1  mycroft 			for (i = 8; --i >= 0;) {
   2337  1.1  mycroft 				if ((crc & 0x01) ^ (c & 0x01)) {
   2338  1.1  mycroft 					crc >>= 1;
   2339  1.1  mycroft 					crc ^= 0xedb88320;
   2340  1.1  mycroft 				} else
   2341  1.1  mycroft 					crc >>= 1;
   2342  1.1  mycroft 				c >>= 1;
   2343  1.1  mycroft 			}
   2344  1.1  mycroft 		}
   2345  1.1  mycroft 		/* Just want the 6 most significant bits. */
   2346  1.1  mycroft 		crc >>= 26;
   2347  1.1  mycroft 
   2348  1.1  mycroft 		/* Turn on the corresponding bit in the filter. */
   2349  1.1  mycroft 		af[crc >> 3] |= 1 << (crc & 7);
   2350  1.1  mycroft 
   2351  1.1  mycroft 		ETHER_NEXT_MULTI(step, enm);
   2352  1.1  mycroft 	}
   2353  1.1  mycroft 	ifp->if_flags &= ~IFF_ALLMULTI;
   2354  1.1  mycroft 	return;
   2355  1.1  mycroft 
   2356  1.1  mycroft allmulti:
   2357  1.1  mycroft 	ifp->if_flags |= IFF_ALLMULTI;
   2358  1.1  mycroft 	af[0] = af[1] = af[2] = af[3] = af[4] = af[5] = af[6] = af[7] = 0xff;
   2359  1.1  mycroft }
   2360  1.1  mycroft 
   2361  1.1  mycroft /*
   2362  1.1  mycroft  * Calculate a new "multicast packet filter" and put the 86960
   2363  1.1  mycroft  * receiver in appropriate mode.
   2364  1.1  mycroft  */
   2365  1.1  mycroft void
   2366  1.1  mycroft fe_setmode(sc)
   2367  1.1  mycroft 	struct fe_softc *sc;
   2368  1.1  mycroft {
   2369  1.1  mycroft 	int flags = sc->sc_arpcom.ac_if.if_flags;
   2370  1.1  mycroft 
   2371  1.1  mycroft 	/*
   2372  1.1  mycroft 	 * If the interface is not running, we postpone the update
   2373  1.1  mycroft 	 * process for receive modes and multicast address filter
   2374  1.1  mycroft 	 * until the interface is restarted.  It reduces some
   2375  1.1  mycroft 	 * complicated job on maintaining chip states.  (Earlier versions
   2376  1.1  mycroft 	 * of this driver had a bug on that point...)
   2377  1.1  mycroft 	 *
   2378  1.1  mycroft 	 * To complete the trick, fe_init() calls fe_setmode() after
   2379  1.1  mycroft 	 * restarting the interface.
   2380  1.1  mycroft 	 */
   2381  1.1  mycroft 	if ((flags & IFF_RUNNING) == 0)
   2382  1.1  mycroft 		return;
   2383  1.1  mycroft 
   2384  1.1  mycroft 	/*
   2385  1.1  mycroft 	 * Promiscuous mode is handled separately.
   2386  1.1  mycroft 	 */
   2387  1.1  mycroft 	if ((flags & IFF_PROMISC) != 0) {
   2388  1.1  mycroft 		/*
   2389  1.1  mycroft 		 * Program 86960 to receive all packets on the segment
   2390  1.1  mycroft 		 * including those directed to other stations.
   2391  1.1  mycroft 		 * Multicast filter stored in MARs are ignored
   2392  1.1  mycroft 		 * under this setting, so we don't need to update it.
   2393  1.1  mycroft 		 *
   2394  1.1  mycroft 		 * Promiscuous mode in FreeBSD 2 is used solely by
   2395  1.1  mycroft 		 * BPF, and BPF only listens to valid (no error) packets.
   2396  1.1  mycroft 		 * So, we ignore errornous ones even in this mode.
   2397  1.1  mycroft 		 * (Older versions of fe driver mistook the point.)
   2398  1.1  mycroft 		 */
   2399  1.1  mycroft 		outb(sc->sc_iobase + FE_DLCR5,
   2400  1.1  mycroft 		    sc->proto_dlcr5 | FE_D5_AFM0 | FE_D5_AFM1);
   2401  1.1  mycroft 		sc->filter_change = 0;
   2402  1.1  mycroft 
   2403  1.1  mycroft #if FE_DEBUG >= 3
   2404  1.1  mycroft 		log(LOG_INFO, "%s: promiscuous mode\n", sc->sc_dev.dv_xname);
   2405  1.1  mycroft #endif
   2406  1.1  mycroft 		return;
   2407  1.1  mycroft 	}
   2408  1.1  mycroft 
   2409  1.1  mycroft 	/*
   2410  1.1  mycroft 	 * Turn the chip to the normal (non-promiscuous) mode.
   2411  1.1  mycroft 	 */
   2412  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR5, sc->proto_dlcr5 | FE_D5_AFM1);
   2413  1.1  mycroft 
   2414  1.1  mycroft 	/*
   2415  1.1  mycroft 	 * Find the new multicast filter value.
   2416  1.1  mycroft 	 */
   2417  1.1  mycroft 	fe_getmcaf(&sc->sc_arpcom, sc->filter);
   2418  1.1  mycroft 	sc->filter_change = 1;
   2419  1.1  mycroft 
   2420  1.1  mycroft #if FE_DEBUG >= 3
   2421  1.1  mycroft 	log(LOG_INFO,
   2422  1.1  mycroft 	    "%s: address filter: [%02x %02x %02x %02x %02x %02x %02x %02x]\n",
   2423  1.1  mycroft 	    sc->sc_dev.dv_xname,
   2424  1.1  mycroft 	    sc->filter[0], sc->filter[1], sc->filter[2], sc->filter[3],
   2425  1.1  mycroft 	    sc->filter[4], sc->filter[5], sc->filter[6], sc->filter[7]);
   2426  1.1  mycroft #endif
   2427  1.1  mycroft 
   2428  1.1  mycroft 	/*
   2429  1.1  mycroft 	 * We have to update the multicast filter in the 86960, A.S.A.P.
   2430  1.1  mycroft 	 *
   2431  1.1  mycroft 	 * Note that the DLC (Data Linc Control unit, i.e. transmitter
   2432  1.1  mycroft 	 * and receiver) must be stopped when feeding the filter, and
   2433  1.1  mycroft 	 * DLC trushes all packets in both transmission and receive
   2434  1.1  mycroft 	 * buffers when stopped.
   2435  1.1  mycroft 	 *
   2436  1.1  mycroft 	 * ... Are the above sentenses correct?  I have to check the
   2437  1.1  mycroft 	 *     manual of the MB86960A.  FIXME.
   2438  1.1  mycroft 	 *
   2439  1.1  mycroft 	 * To reduce the packet lossage, we delay the filter update
   2440  1.1  mycroft 	 * process until buffers are empty.
   2441  1.1  mycroft 	 */
   2442  1.1  mycroft 	if (sc->txb_sched == 0 && sc->txb_count == 0 &&
   2443  1.1  mycroft 	    (inb(sc->sc_iobase + FE_DLCR1) & FE_D1_PKTRDY) == 0) {
   2444  1.1  mycroft 		/*
   2445  1.1  mycroft 		 * Buffers are (apparently) empty.  Load
   2446  1.1  mycroft 		 * the new filter value into MARs now.
   2447  1.1  mycroft 		 */
   2448  1.1  mycroft 		fe_loadmar(sc);
   2449  1.1  mycroft 	} else {
   2450  1.1  mycroft 		/*
   2451  1.1  mycroft 		 * Buffers are not empty.  Mark that we have to update
   2452  1.1  mycroft 		 * the MARs.  The new filter will be loaded by feintr()
   2453  1.1  mycroft 		 * later.
   2454  1.1  mycroft 		 */
   2455  1.1  mycroft #if FE_DEBUG >= 4
   2456  1.1  mycroft 		log(LOG_INFO, "%s: filter change delayed\n", sc->sc_dev.dv_xname);
   2457  1.1  mycroft #endif
   2458  1.1  mycroft 	}
   2459  1.1  mycroft }
   2460  1.1  mycroft 
   2461  1.1  mycroft /*
   2462  1.1  mycroft  * Load a new multicast address filter into MARs.
   2463  1.1  mycroft  *
   2464  1.1  mycroft  * The caller must have splimp'ed befor fe_loadmar.
   2465  1.1  mycroft  * This function starts the DLC upon return.  So it can be called only
   2466  1.1  mycroft  * when the chip is working, i.e., from the driver's point of view, when
   2467  1.1  mycroft  * a device is RUNNING.  (I mistook the point in previous versions.)
   2468  1.1  mycroft  */
   2469  1.1  mycroft void
   2470  1.1  mycroft fe_loadmar(sc)
   2471  1.1  mycroft 	struct fe_softc *sc;
   2472  1.1  mycroft {
   2473  1.1  mycroft 
   2474  1.1  mycroft 	/* Stop the DLC (transmitter and receiver). */
   2475  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
   2476  1.1  mycroft 
   2477  1.1  mycroft 	/* Select register bank 1 for MARs. */
   2478  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR7,
   2479  1.1  mycroft 	    sc->proto_dlcr7 | FE_D7_RBS_MAR | FE_D7_POWER_UP);
   2480  1.1  mycroft 
   2481  1.1  mycroft 	/* Copy filter value into the registers. */
   2482  1.1  mycroft 	outblk(sc->sc_iobase + FE_MAR8, sc->filter, FE_FILTER_LEN);
   2483  1.1  mycroft 
   2484  1.1  mycroft 	/* Restore the bank selection for BMPRs (i.e., runtime registers). */
   2485  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR7,
   2486  1.1  mycroft 	    sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP);
   2487  1.1  mycroft 
   2488  1.1  mycroft 	/* Restart the DLC. */
   2489  1.1  mycroft 	outb(sc->sc_iobase + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_ENABLE);
   2490  1.1  mycroft 
   2491  1.1  mycroft 	/* We have just updated the filter. */
   2492  1.1  mycroft 	sc->filter_change = 0;
   2493  1.1  mycroft 
   2494  1.1  mycroft #if FE_DEBUG >= 3
   2495  1.1  mycroft 	log(LOG_INFO, "%s: address filter changed\n", sc->sc_dev.dv_xname);
   2496  1.1  mycroft #endif
   2497  1.1  mycroft }
   2498  1.1  mycroft 
   2499  1.1  mycroft #if FE_DEBUG >= 1
   2500  1.1  mycroft void
   2501  1.1  mycroft fe_dump(level, sc)
   2502  1.1  mycroft 	int level;
   2503  1.1  mycroft 	struct fe_softc *sc;
   2504  1.1  mycroft {
   2505  1.1  mycroft 	int iobase = sc->sc_iobase;
   2506  1.1  mycroft 	u_char save_dlcr7;
   2507  1.1  mycroft 
   2508  1.1  mycroft 	save_dlcr7 = inb(iobase + FE_DLCR7);
   2509  1.1  mycroft 
   2510  1.1  mycroft 	log(level, "\tDLCR = %02x %02x %02x %02x %02x %02x %02x %02x",
   2511  1.1  mycroft 	    inb(iobase + FE_DLCR0),  inb(iobase + FE_DLCR1),
   2512  1.1  mycroft 	    inb(iobase + FE_DLCR2),  inb(iobase + FE_DLCR3),
   2513  1.1  mycroft 	    inb(iobase + FE_DLCR4),  inb(iobase + FE_DLCR5),
   2514  1.1  mycroft 	    inb(iobase + FE_DLCR6),  inb(iobase + FE_DLCR7));
   2515  1.1  mycroft 
   2516  1.1  mycroft 	outb(iobase + FE_DLCR7, (save_dlcr7 & ~FE_D7_RBS) | FE_D7_RBS_DLCR);
   2517  1.1  mycroft 	log(level, "\t       %02x %02x %02x %02x %02x %02x %02x %02x,",
   2518  1.1  mycroft 	    inb(iobase + FE_DLCR8),  inb(iobase + FE_DLCR9),
   2519  1.1  mycroft 	    inb(iobase + FE_DLCR10), inb(iobase + FE_DLCR11),
   2520  1.1  mycroft 	    inb(iobase + FE_DLCR12), inb(iobase + FE_DLCR13),
   2521  1.1  mycroft 	    inb(iobase + FE_DLCR14), inb(iobase + FE_DLCR15));
   2522  1.1  mycroft 
   2523  1.1  mycroft 	outb(iobase + FE_DLCR7, (save_dlcr7 & ~FE_D7_RBS) | FE_D7_RBS_MAR);
   2524  1.1  mycroft 	log(level, "\tMAR  = %02x %02x %02x %02x %02x %02x %02x %02x,",
   2525  1.1  mycroft 	    inb(iobase + FE_MAR8),   inb(iobase + FE_MAR9),
   2526  1.1  mycroft 	    inb(iobase + FE_MAR10),  inb(iobase + FE_MAR11),
   2527  1.1  mycroft 	    inb(iobase + FE_MAR12),  inb(iobase + FE_MAR13),
   2528  1.1  mycroft 	    inb(iobase + FE_MAR14),  inb(iobase + FE_MAR15));
   2529  1.1  mycroft 
   2530  1.1  mycroft 	outb(iobase + FE_DLCR7, (save_dlcr7 & ~FE_D7_RBS) | FE_D7_RBS_BMPR);
   2531  1.1  mycroft 	log(level, "\tBMPR = xx xx %02x %02x %02x %02x %02x %02x %02x %02x xx %02x.",
   2532  1.1  mycroft 	    inb(iobase + FE_BMPR10), inb(iobase + FE_BMPR11),
   2533  1.1  mycroft 	    inb(iobase + FE_BMPR12), inb(iobase + FE_BMPR13),
   2534  1.1  mycroft 	    inb(iobase + FE_BMPR14), inb(iobase + FE_BMPR15),
   2535  1.1  mycroft 	    inb(iobase + FE_BMPR16), inb(iobase + FE_BMPR17),
   2536  1.1  mycroft 	    inb(iobase + FE_BMPR19));
   2537  1.1  mycroft 
   2538  1.1  mycroft 	outb(iobase + FE_DLCR7, save_dlcr7);
   2539  1.1  mycroft }
   2540  1.1  mycroft #endif
   2541