Home | History | Annotate | Line # | Download | only in isa
if_ate.c revision 1.21
      1  1.21    enami /*	$NetBSD: if_ate.c,v 1.21 1998/03/22 04:25:37 enami Exp $	*/
      2  1.19    perry 
      3   1.1  mycroft /*
      4   1.1  mycroft  * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
      5   1.1  mycroft  *
      6   1.1  mycroft  * This software may be used, modified, copied, distributed, and sold, in
      7   1.1  mycroft  * both source and binary form provided that the above copyright, these
      8   1.1  mycroft  * terms and the following disclaimer are retained.  The name of the author
      9   1.1  mycroft  * and/or the contributor may not be used to endorse or promote products
     10   1.1  mycroft  * derived from this software without specific prior written permission.
     11   1.1  mycroft  *
     12   1.1  mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND
     13   1.1  mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     14   1.1  mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     15   1.1  mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE
     16   1.1  mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     17   1.1  mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     18   1.1  mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION.
     19   1.1  mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     20   1.1  mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     21   1.1  mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     22   1.1  mycroft  * SUCH DAMAGE.
     23   1.1  mycroft  */
     24   1.1  mycroft 
     25   1.1  mycroft /*
     26   1.1  mycroft  * Portions copyright (C) 1993, David Greenman.  This software may be used,
     27   1.1  mycroft  * modified, copied, distributed, and sold, in both source and binary form
     28   1.1  mycroft  * provided that the above copyright and these terms are retained.  Under no
     29   1.1  mycroft  * circumstances is the author responsible for the proper functioning of this
     30   1.1  mycroft  * software, nor does the author assume any responsibility for damages
     31   1.1  mycroft  * incurred with its use.
     32   1.1  mycroft  */
     33   1.1  mycroft 
     34   1.1  mycroft #include <sys/param.h>
     35   1.1  mycroft #include <sys/systm.h>
     36  1.21    enami #include <sys/device.h>
     37   1.1  mycroft #include <sys/socket.h>
     38   1.1  mycroft #include <sys/syslog.h>
     39   1.1  mycroft 
     40   1.1  mycroft #include <net/if.h>
     41  1.17       is #include <net/if_ether.h>
     42  1.21    enami #include <net/if_media.h>
     43   1.1  mycroft 
     44  1.21    enami #include <machine/bus.h>
     45  1.13  mycroft #include <machine/intr.h>
     46   1.1  mycroft 
     47   1.3      cgd #include <dev/ic/mb86960reg.h>
     48  1.21    enami #include <dev/ic/mb86960var.h>
     49   1.1  mycroft 
     50  1.21    enami #include <dev/isa/isavar.h>
     51  1.21    enami #include <dev/isa/if_fereg.h>	/* XXX */
     52   1.1  mycroft 
     53  1.21    enami #ifdef __BROKEN_INDIRECT_CONFIG
     54  1.21    enami int	ate_match __P((struct device *, void *, void *));
     55  1.21    enami #else
     56  1.21    enami int	ate_match __P((struct device *, struct cfdata *, void *));
     57   1.1  mycroft #endif
     58  1.21    enami void	ate_attach __P((struct device *, struct device *, void *));
     59   1.1  mycroft 
     60  1.21    enami struct ate_softc {
     61  1.21    enami 	struct	mb86960_softc sc_mb86960;	/* real "mb86960" softc */
     62   1.1  mycroft 
     63  1.21    enami 	/* ISA-specific goo. */
     64  1.21    enami 	void	*sc_ih;				/* interrupt cookie */
     65  1.21    enami };
     66   1.1  mycroft 
     67  1.21    enami struct cfattach ate_ca = {
     68  1.21    enami 	sizeof(struct ate_softc), ate_match, ate_attach
     69   1.1  mycroft };
     70   1.1  mycroft 
     71  1.21    enami #if NetBSD <= 199712
     72  1.21    enami struct cfdriver ate_cd = {
     73  1.21    enami 	NULL, "ate", DV_IFNET
     74   1.1  mycroft };
     75   1.1  mycroft #endif
     76   1.1  mycroft 
     77  1.21    enami struct fe_simple_probe_struct {
     78  1.21    enami 	u_char port;	/* Offset from the base I/O address. */
     79  1.21    enami 	u_char mask;	/* Bits to be checked. */
     80  1.21    enami 	u_char bits;	/* Values to be compared against. */
     81   1.1  mycroft };
     82   1.1  mycroft 
     83  1.21    enami static __inline__ int fe_simple_probe __P((bus_space_tag_t,
     84  1.21    enami     bus_space_handle_t, struct fe_simple_probe_struct const *));
     85  1.21    enami static __inline__ void ate_strobe __P((bus_space_tag_t, bus_space_handle_t));
     86  1.21    enami static void ate_read_eeprom __P((bus_space_tag_t, bus_space_handle_t,
     87  1.21    enami     u_char *));
     88  1.21    enami static int ate_find __P((bus_space_tag_t, bus_space_handle_t, int *,
     89  1.21    enami     int *));
     90  1.21    enami static int ate_detect __P((bus_space_tag_t, bus_space_handle_t,
     91  1.21    enami     u_int8_t enaddr[ETHER_ADDR_LEN]));
     92   1.1  mycroft 
     93  1.21    enami static int const ate_iomap[8] = {
     94  1.21    enami 	0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300
     95  1.21    enami };
     96  1.21    enami #define NATE_IOMAP (sizeof (ate_iomap) / sizeof (ate_iomap[0]))
     97  1.21    enami #define ATE_NPORTS 0x20
     98   1.1  mycroft 
     99   1.1  mycroft /*
    100   1.1  mycroft  * Hardware probe routines.
    101   1.1  mycroft  */
    102   1.1  mycroft 
    103   1.1  mycroft /*
    104   1.1  mycroft  * Determine if the device is present.
    105   1.1  mycroft  */
    106   1.1  mycroft int
    107  1.21    enami ate_match(parent, match, aux)
    108   1.1  mycroft 	struct device *parent;
    109  1.21    enami #ifdef __BROKEN_INDIRECT_CONFIG
    110  1.21    enami 	void *match;
    111  1.21    enami #else
    112  1.21    enami 	struct cfdata *match;
    113  1.21    enami #endif
    114  1.21    enami 	void *aux;
    115   1.1  mycroft {
    116   1.1  mycroft 	struct isa_attach_args *ia = aux;
    117  1.21    enami 	bus_space_tag_t iot = ia->ia_iot;
    118  1.21    enami 	bus_space_handle_t ioh;
    119  1.21    enami 	int i, iobase, irq, rv = 0;
    120  1.21    enami 	u_int8_t myea[ETHER_ADDR_LEN];
    121  1.21    enami 
    122  1.21    enami 	/* Disallow wildcarded values. */
    123  1.21    enami 	if (ia->ia_iobase == ISACF_PORT_DEFAULT)
    124  1.21    enami 		return (0);
    125  1.21    enami 
    126  1.21    enami 	/*
    127  1.21    enami 	 * See if the sepcified address is valid for MB86965A JLI mode.
    128  1.21    enami 	 */
    129  1.21    enami 	for (i = 0; i < NATE_IOMAP; i++)
    130  1.21    enami 		if (ate_iomap[i] == ia->ia_iobase)
    131  1.21    enami 			break;
    132  1.21    enami 	if (i == NATE_IOMAP) {
    133  1.21    enami #ifdef DIAGNOSTIC
    134  1.21    enami 		printf("ate_match: unknown iobase 0x%x\n", ia->ia_iobase);
    135  1.21    enami #endif
    136  1.21    enami 		return (0);
    137  1.21    enami 	}
    138  1.21    enami 
    139  1.21    enami 	/* Map i/o space. */
    140  1.21    enami 	if (bus_space_map(iot, ia->ia_iobase, ATE_NPORTS, 0, &ioh)) {
    141  1.21    enami #ifdef DIAGNOSTIC
    142  1.21    enami 		printf("ate_match: couldn't map iospace 0x%x\n",
    143  1.21    enami 		    ia->ia_iobase);
    144  1.21    enami #endif
    145  1.21    enami 		return (0);
    146  1.21    enami 	}
    147   1.1  mycroft 
    148  1.21    enami 	if (ate_find(iot, ioh, &iobase, &irq) == 0) {
    149  1.21    enami #ifdef DIAGNOSTIC
    150  1.21    enami 		printf("ate_match: ate_find failed\n");
    151   1.1  mycroft #endif
    152  1.21    enami 		goto out;
    153  1.21    enami 	}
    154  1.21    enami 
    155  1.21    enami 	if (iobase != ia->ia_iobase) {
    156  1.21    enami #ifdef DIAGNOSTIC
    157  1.21    enami 		printf("ate_match: unexpected iobase in board: 0x%x\n",
    158  1.21    enami 		    ia->ia_iobase);
    159  1.21    enami #endif
    160  1.21    enami 		goto out;
    161  1.21    enami 	}
    162  1.21    enami 
    163  1.21    enami 	if (ate_detect(iot, ioh, myea) == 0) { /* XXX necessary? */
    164  1.21    enami #ifdef DIAGNOSTIC
    165  1.21    enami 		printf("ate_match: ate_detect failed\n");
    166  1.21    enami #endif
    167  1.21    enami 		goto out;
    168  1.21    enami 	}
    169  1.21    enami 
    170  1.21    enami 	if (ia->ia_irq != ISACF_IRQ_DEFAULT) {
    171  1.21    enami 		if (ia->ia_irq != irq) {
    172  1.21    enami 			printf("ate_match: irq mismatch; "
    173  1.21    enami 			    "kernel configured %d != board configured %d\n",
    174  1.21    enami 			    ia->ia_irq, irq);
    175  1.21    enami 			goto out;
    176  1.21    enami 		}
    177  1.21    enami 	} else
    178  1.21    enami 		ia->ia_irq = irq;
    179   1.1  mycroft 
    180  1.21    enami 	ia->ia_iosize = ATE_NPORTS;
    181  1.21    enami 	ia->ia_msize = 0;
    182  1.21    enami 	rv = 1;
    183   1.1  mycroft 
    184  1.21    enami  out:
    185  1.21    enami 	bus_space_unmap(iot, ioh, ATE_NPORTS);
    186  1.21    enami 	return (rv);
    187   1.1  mycroft }
    188   1.1  mycroft 
    189   1.1  mycroft /*
    190   1.1  mycroft  * Check for specific bits in specific registers have specific values.
    191   1.1  mycroft  */
    192  1.21    enami static __inline__ int
    193  1.21    enami fe_simple_probe (iot, ioh, sp)
    194  1.21    enami 	bus_space_tag_t iot;
    195  1.21    enami 	bus_space_handle_t ioh;
    196  1.21    enami 	struct fe_simple_probe_struct const *sp;
    197   1.1  mycroft {
    198  1.21    enami 	u_int8_t val;
    199  1.21    enami 	struct fe_simple_probe_struct const *p;
    200   1.1  mycroft 
    201   1.1  mycroft 	for (p = sp; p->mask != 0; p++) {
    202  1.21    enami 		val = bus_space_read_1(iot, ioh, p->port);
    203  1.21    enami 		if ((val & p->mask) != p->bits) {
    204  1.21    enami #ifdef DIAGNOSTIC
    205  1.21    enami 			printf("fe_simple_probe: %x & %x != %x\n",
    206  1.21    enami 			    val, p->mask, p->bits);
    207  1.21    enami #endif
    208   1.1  mycroft 			return (0);
    209   1.1  mycroft 		}
    210   1.1  mycroft 	}
    211  1.21    enami 
    212   1.1  mycroft 	return (1);
    213   1.1  mycroft }
    214   1.1  mycroft 
    215   1.1  mycroft /*
    216   1.1  mycroft  * Routines to read all bytes from the config EEPROM through MB86965A.
    217   1.1  mycroft  * I'm not sure what exactly I'm doing here...  I was told just to follow
    218   1.1  mycroft  * the steps, and it worked.  Could someone tell me why the following
    219   1.1  mycroft  * code works?  (Or, why all similar codes I tried previously doesn't
    220   1.1  mycroft  * work.)  FIXME.
    221   1.1  mycroft  */
    222   1.1  mycroft 
    223  1.21    enami static __inline__ void
    224  1.21    enami ate_strobe (iot, ioh)
    225  1.21    enami 	bus_space_tag_t iot;
    226  1.21    enami 	bus_space_handle_t ioh;
    227   1.1  mycroft {
    228  1.21    enami 
    229   1.1  mycroft 	/*
    230   1.1  mycroft 	 * Output same value twice.  To speed-down execution?
    231   1.1  mycroft 	 */
    232  1.21    enami 	bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT);
    233  1.21    enami 	bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT);
    234  1.21    enami 	bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT | FE_B16_CLOCK);
    235  1.21    enami 	bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT | FE_B16_CLOCK);
    236  1.21    enami 	bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT);
    237  1.21    enami 	bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT);
    238   1.1  mycroft }
    239   1.1  mycroft 
    240  1.21    enami static void
    241  1.21    enami ate_read_eeprom(iot, ioh, data)
    242  1.21    enami 	bus_space_tag_t iot;
    243  1.21    enami 	bus_space_handle_t ioh;
    244   1.1  mycroft 	u_char *data;
    245   1.1  mycroft {
    246  1.21    enami 	int n, count;
    247  1.21    enami 	u_char val, bit;
    248   1.1  mycroft 
    249   1.1  mycroft 	/* Read bytes from EEPROM; two bytes per an iterration. */
    250   1.1  mycroft 	for (n = 0; n < FE_EEPROM_SIZE / 2; n++) {
    251   1.1  mycroft 		/* Reset the EEPROM interface. */
    252  1.21    enami 		bus_space_write_1(iot, ioh, FE_BMPR16, 0x00);
    253  1.21    enami 		bus_space_write_1(iot, ioh, FE_BMPR17, 0x00);
    254  1.21    enami 		bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT);
    255   1.1  mycroft 
    256   1.1  mycroft 		/* Start EEPROM access. */
    257  1.21    enami 		bus_space_write_1(iot, ioh, FE_BMPR17, FE_B17_DATA);
    258  1.21    enami 		ate_strobe(iot, ioh);
    259   1.1  mycroft 
    260   1.1  mycroft 		/* Pass the iterration count to the chip. */
    261  1.21    enami 		count = 0x80 | n;
    262   1.1  mycroft 		for (bit = 0x80; bit != 0x00; bit >>= 1) {
    263  1.21    enami 			bus_space_write_1(iot, ioh, FE_BMPR17,
    264  1.21    enami 			    (count & bit) ? FE_B17_DATA : 0);
    265  1.21    enami 			ate_strobe(iot, ioh);
    266   1.1  mycroft 		}
    267  1.21    enami 		bus_space_write_1(iot, ioh, FE_BMPR17, 0x00);
    268   1.1  mycroft 
    269   1.1  mycroft 		/* Read a byte. */
    270   1.1  mycroft 		val = 0;
    271   1.1  mycroft 		for (bit = 0x80; bit != 0x00; bit >>= 1) {
    272  1.21    enami 			ate_strobe(iot, ioh);
    273  1.21    enami 			if (bus_space_read_1(iot, ioh, FE_BMPR17) &
    274  1.21    enami 			    FE_B17_DATA)
    275   1.1  mycroft 				val |= bit;
    276   1.1  mycroft 		}
    277   1.1  mycroft 		*data++ = val;
    278   1.1  mycroft 
    279   1.1  mycroft 		/* Read one more byte. */
    280   1.1  mycroft 		val = 0;
    281   1.1  mycroft 		for (bit = 0x80; bit != 0x00; bit >>= 1) {
    282  1.21    enami 			ate_strobe(iot, ioh);
    283  1.21    enami 			if (bus_space_read_1(iot, ioh, FE_BMPR17) &
    284  1.21    enami 			    FE_B17_DATA)
    285   1.1  mycroft 				val |= bit;
    286   1.1  mycroft 		}
    287   1.1  mycroft 		*data++ = val;
    288   1.1  mycroft 	}
    289   1.1  mycroft 
    290  1.21    enami 	/* Make sure the EEPROM is turned off. */
    291  1.21    enami 	bus_space_write_1(iot, ioh, FE_BMPR16, 0);
    292  1.21    enami 	bus_space_write_1(iot, ioh, FE_BMPR17, 0);
    293  1.21    enami 
    294   1.1  mycroft #if FE_DEBUG >= 3
    295   1.1  mycroft 	/* Report what we got. */
    296   1.1  mycroft 	data -= FE_EEPROM_SIZE;
    297  1.21    enami 	log(LOG_INFO, "ate_read_eeprom: EEPROM at %04x:"
    298   1.1  mycroft 	    " %02x%02x%02x%02x %02x%02x%02x%02x -"
    299   1.1  mycroft 	    " %02x%02x%02x%02x %02x%02x%02x%02x -"
    300   1.1  mycroft 	    " %02x%02x%02x%02x %02x%02x%02x%02x -"
    301   1.1  mycroft 	    " %02x%02x%02x%02x %02x%02x%02x%02x\n",
    302  1.21    enami 	    (int) ioh,		/* XXX */
    303   1.1  mycroft 	    data[ 0], data[ 1], data[ 2], data[ 3],
    304   1.1  mycroft 	    data[ 4], data[ 5], data[ 6], data[ 7],
    305   1.1  mycroft 	    data[ 8], data[ 9], data[10], data[11],
    306   1.1  mycroft 	    data[12], data[13], data[14], data[15],
    307   1.1  mycroft 	    data[16], data[17], data[18], data[19],
    308   1.1  mycroft 	    data[20], data[21], data[22], data[23],
    309   1.1  mycroft 	    data[24], data[25], data[26], data[27],
    310   1.1  mycroft 	    data[28], data[29], data[30], data[31]);
    311   1.1  mycroft #endif
    312   1.1  mycroft }
    313   1.1  mycroft 
    314   1.1  mycroft /*
    315   1.1  mycroft  * Hardware (vendor) specific probe routines.
    316   1.1  mycroft  */
    317   1.1  mycroft 
    318   1.1  mycroft /*
    319   1.1  mycroft  * Probe and initialization for Allied-Telesis AT1700/RE2000 series.
    320   1.1  mycroft  */
    321  1.21    enami static int
    322  1.21    enami ate_find(iot, ioh, iobase, irq)
    323  1.21    enami 	bus_space_tag_t iot;
    324  1.21    enami 	bus_space_handle_t ioh;
    325  1.21    enami 	int *iobase, *irq;
    326   1.1  mycroft {
    327   1.1  mycroft 	u_char eeprom[FE_EEPROM_SIZE];
    328  1.21    enami 	int n;
    329   1.1  mycroft 
    330   1.1  mycroft 	static int const irqmap[4][4] = {
    331   1.1  mycroft 		{  3,  4,  5,  9 },
    332   1.1  mycroft 		{ 10, 11, 12, 15 },
    333   1.1  mycroft 		{  3, 11,  5, 15 },
    334   1.1  mycroft 		{ 10, 11, 14, 15 },
    335   1.1  mycroft 	};
    336   1.1  mycroft 	static struct fe_simple_probe_struct const probe_table[] = {
    337   1.1  mycroft 		{ FE_DLCR2,  0x70, 0x00 },
    338   1.1  mycroft 		{ FE_DLCR4,  0x08, 0x00 },
    339   1.1  mycroft 		{ FE_DLCR5,  0x80, 0x00 },
    340   1.1  mycroft #if 0
    341   1.1  mycroft 		{ FE_BMPR16, 0x1B, 0x00 },
    342   1.1  mycroft 		{ FE_BMPR17, 0x7F, 0x00 },
    343   1.1  mycroft #endif
    344   1.1  mycroft 		{ 0 }
    345   1.1  mycroft 	};
    346   1.1  mycroft 
    347  1.21    enami #if FE_DEBUG >= 4
    348  1.21    enami 	log(LOG_INFO, "ate_find: probe (0x%x) for ATI\n", iobase);
    349   1.1  mycroft #if 0
    350  1.21    enami 	fe_dump(LOG_INFO, sc);
    351   1.1  mycroft #endif
    352   1.1  mycroft #endif
    353   1.1  mycroft 
    354   1.1  mycroft 	/*
    355   1.1  mycroft 	 * We should test if MB86965A is on the base address now.
    356   1.1  mycroft 	 * Unfortunately, it is very hard to probe it reliably, since
    357   1.1  mycroft 	 * we have no way to reset the chip under software control.
    358   1.1  mycroft 	 * On cold boot, we could check the "signature" bit patterns
    359   1.1  mycroft 	 * described in the Fujitsu document.  On warm boot, however,
    360   1.1  mycroft 	 * we can predict almost nothing about register values.
    361   1.1  mycroft 	 */
    362  1.21    enami 	if (!fe_simple_probe(iot, ioh, probe_table))
    363   1.1  mycroft 		return (0);
    364   1.1  mycroft 
    365   1.1  mycroft 	/* Check if our I/O address matches config info on 86965. */
    366  1.21    enami 	n = (bus_space_read_1(iot, ioh, FE_BMPR19) & FE_B19_ADDR)
    367  1.21    enami 	    >> FE_B19_ADDR_SHIFT;
    368  1.21    enami 	*iobase = ate_iomap[n];
    369   1.1  mycroft 
    370   1.1  mycroft 	/*
    371   1.1  mycroft 	 * We are now almost sure we have an AT1700 at the given
    372   1.1  mycroft 	 * address.  So, read EEPROM through 86965.  We have to write
    373   1.1  mycroft 	 * into LSI registers to read from EEPROM.  I want to avoid it
    374   1.1  mycroft 	 * at this stage, but I cannot test the presense of the chip
    375   1.1  mycroft 	 * any further without reading EEPROM.  FIXME.
    376   1.1  mycroft 	 */
    377  1.21    enami 	ate_read_eeprom(iot, ioh, eeprom);
    378   1.1  mycroft 
    379   1.1  mycroft 	/* Make sure that config info in EEPROM and 86965 agree. */
    380  1.21    enami 	if (eeprom[FE_EEPROM_CONF] != bus_space_read_1(iot, ioh, FE_BMPR19)) {
    381  1.21    enami #ifdef DIAGNOSTIC
    382  1.21    enami 		printf("ate_find: "
    383  1.21    enami 		    "incorrect configration in eeprom and chip\n");
    384  1.21    enami #endif
    385  1.21    enami 		return (0);
    386   1.1  mycroft 	}
    387   1.1  mycroft 
    388   1.1  mycroft 	/*
    389   1.1  mycroft 	 * Try to determine IRQ settings.
    390   1.1  mycroft 	 * Different models use different ranges of IRQs.
    391   1.1  mycroft 	 */
    392  1.21    enami 	n = (bus_space_read_1(iot, ioh, FE_BMPR19) & FE_B19_IRQ)
    393  1.21    enami 	    >> FE_B19_IRQ_SHIFT;
    394   1.1  mycroft 	switch (eeprom[FE_ATI_EEP_REVISION] & 0xf0) {
    395   1.1  mycroft 	case 0x30:
    396  1.21    enami 		*irq = irqmap[3][n];
    397   1.1  mycroft 		break;
    398   1.1  mycroft 	case 0x10:
    399   1.1  mycroft 	case 0x50:
    400  1.21    enami 		*irq = irqmap[2][n];
    401   1.1  mycroft 		break;
    402   1.1  mycroft 	case 0x40:
    403   1.1  mycroft 	case 0x60:
    404   1.1  mycroft 		if (eeprom[FE_ATI_EEP_MAGIC] & 0x04) {
    405  1.21    enami 			*irq = irqmap[1][n];
    406   1.1  mycroft 			break;
    407   1.1  mycroft 		}
    408   1.1  mycroft 	default:
    409  1.21    enami 		*irq = irqmap[0][n];
    410   1.1  mycroft 		break;
    411   1.1  mycroft 	}
    412   1.1  mycroft 
    413  1.21    enami 	return (1);
    414  1.21    enami }
    415   1.1  mycroft 
    416  1.21    enami /*
    417  1.21    enami  * Determine type and ethernet address.
    418  1.21    enami  */
    419  1.21    enami static int
    420  1.21    enami ate_detect(iot, ioh, enaddr)
    421  1.21    enami 	bus_space_tag_t iot;
    422  1.21    enami 	bus_space_handle_t ioh;
    423  1.21    enami 	u_int8_t enaddr[ETHER_ADDR_LEN];
    424  1.21    enami {
    425  1.21    enami 	u_char eeprom[FE_EEPROM_SIZE];
    426  1.21    enami 	int type;
    427   1.1  mycroft 
    428   1.1  mycroft 	/* Get our station address from EEPROM. */
    429  1.21    enami 	ate_read_eeprom(iot, ioh, eeprom);
    430  1.21    enami 	bcopy(eeprom + FE_ATI_EEP_ADDR, enaddr, ETHER_ADDR_LEN);
    431   1.1  mycroft 
    432   1.1  mycroft 	/* Make sure we got a valid station address. */
    433  1.21    enami 	if ((enaddr[0] & 0x03) != 0x00 ||
    434  1.21    enami 	    (enaddr[0] == 0x00 && enaddr[1] == 0x00 && enaddr[2] == 0x00)) {
    435  1.21    enami #ifdef DIAGNOSTIC
    436  1.21    enami 		printf("fmv_detect: invalid ethernet address\n");
    437   1.1  mycroft #endif
    438  1.21    enami 		return (0);
    439  1.21    enami 	}
    440   1.1  mycroft 
    441   1.1  mycroft 	/*
    442  1.21    enami 	 * Determine the card type.
    443   1.1  mycroft 	 */
    444  1.21    enami 	switch (eeprom[FE_ATI_EEP_MODEL]) {
    445  1.21    enami 	case FE_ATI_MODEL_AT1700T:
    446  1.21    enami 		type = FE_TYPE_AT1700T;
    447  1.21    enami 		break;
    448  1.21    enami 	case FE_ATI_MODEL_AT1700BT:
    449  1.21    enami 		type = FE_TYPE_AT1700BT;
    450  1.21    enami 		break;
    451  1.21    enami 	case FE_ATI_MODEL_AT1700FT:
    452  1.21    enami 		type = FE_TYPE_AT1700FT;
    453  1.21    enami 		break;
    454  1.21    enami 	case FE_ATI_MODEL_AT1700AT:
    455  1.21    enami 		type = FE_TYPE_AT1700AT;
    456  1.21    enami 		break;
    457  1.21    enami 	default:
    458  1.21    enami 		type = FE_TYPE_RE2000;
    459  1.21    enami 		break;
    460  1.21    enami 	}
    461   1.1  mycroft 
    462  1.21    enami 	return (type);
    463  1.21    enami }
    464   1.1  mycroft 
    465  1.21    enami void
    466  1.21    enami ate_attach(parent, self, aux)
    467  1.21    enami 	struct device *parent, *self;
    468  1.21    enami 	void *aux;
    469  1.21    enami {
    470  1.21    enami 	struct ate_softc *isc = (struct ate_softc *)self;
    471  1.21    enami 	struct mb86960_softc *sc = &isc->sc_mb86960;
    472  1.21    enami 	struct isa_attach_args *ia = aux;
    473  1.21    enami 	bus_space_tag_t iot = ia->ia_iot;
    474  1.21    enami 	bus_space_handle_t ioh;
    475  1.21    enami 	u_int8_t myea[ETHER_ADDR_LEN];
    476  1.21    enami 	const char *typestr;
    477  1.21    enami 	int type;
    478  1.21    enami 
    479  1.21    enami 	printf("\n");
    480  1.21    enami 
    481  1.21    enami 	/* Map i/o space. */
    482  1.21    enami 	if (bus_space_map(iot, ia->ia_iobase, ATE_NPORTS, 0, &ioh)) {
    483  1.21    enami 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    484  1.21    enami 		return;
    485  1.21    enami 	}
    486   1.1  mycroft 
    487  1.21    enami 	sc->sc_bst = iot;
    488  1.21    enami 	sc->sc_bsh = ioh;
    489   1.1  mycroft 
    490  1.21    enami 	/* Determine the card type and get ehternet address. */
    491  1.21    enami 	type = ate_detect(iot, ioh, myea);
    492  1.21    enami 	switch (type) {
    493  1.21    enami 	case FE_TYPE_AT1700T:
    494  1.21    enami 		typestr = "AT-1700T";
    495  1.21    enami 		break;
    496  1.21    enami 	case FE_TYPE_AT1700BT:
    497  1.21    enami 		typestr = "AT-1700BT";
    498  1.21    enami 		break;
    499  1.21    enami 	case FE_TYPE_AT1700FT:
    500  1.21    enami 		typestr = "AT-1700FT";
    501  1.21    enami 		break;
    502  1.21    enami 	case FE_TYPE_AT1700AT:
    503  1.21    enami 		typestr = "AT-1700AT";
    504  1.21    enami 		break;
    505  1.21    enami 	case FE_TYPE_RE2000:
    506  1.21    enami 		typestr = "unknown (RE-2000?)";
    507   1.1  mycroft 		break;
    508   1.1  mycroft 
    509   1.1  mycroft 	default:
    510  1.21    enami 	  	/* Unknown card type: maybe a new model, but... */
    511  1.21    enami 		printf("%s: where did the card go?!\n", sc->sc_dev.dv_xname);
    512  1.21    enami 		panic("unknown card");
    513   1.1  mycroft 	}
    514   1.1  mycroft 
    515  1.21    enami 	printf("%s: %s Ethernet\n", sc->sc_dev.dv_xname, typestr);
    516   1.1  mycroft 
    517  1.21    enami 	/* This interface is always enabled. */
    518  1.21    enami 	sc->sc_enabled = 1;
    519   1.1  mycroft 
    520   1.1  mycroft 	/*
    521  1.21    enami 	 * Do generic MB86960 attach.
    522   1.1  mycroft 	 */
    523  1.21    enami 	mb86960_attach(sc, MB86960_TYPE_86965, myea);
    524   1.1  mycroft 
    525  1.21    enami 	mb86960_config(sc, NULL, 0, 0);
    526   1.1  mycroft 
    527  1.21    enami 	/* Establish the interrupt handler. */
    528  1.21    enami 	isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    529  1.21    enami 	    IPL_NET, mb86960_intr, sc);
    530  1.21    enami 	if (isc->sc_ih == NULL)
    531  1.21    enami 		printf("%s: couldn't establish interrupt handler\n",
    532  1.21    enami 		    sc->sc_dev.dv_xname);
    533   1.1  mycroft }
    534