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