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