Home | History | Annotate | Line # | Download | only in isa
if_we_isa.c revision 1.19.4.2
      1  1.19.4.2      yamt /*	$NetBSD: if_we_isa.c,v 1.19.4.2 2010/08/11 22:53:36 yamt Exp $	*/
      2       1.1  jdolecek 
      3       1.1  jdolecek /*-
      4       1.1  jdolecek  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5       1.1  jdolecek  * All rights reserved.
      6       1.1  jdolecek  *
      7       1.1  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1  jdolecek  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9       1.1  jdolecek  * NASA Ames Research Center.
     10       1.1  jdolecek  *
     11       1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     12       1.1  jdolecek  * modification, are permitted provided that the following conditions
     13       1.1  jdolecek  * are met:
     14       1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     15       1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     16       1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     18       1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     19       1.1  jdolecek  *
     20       1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21       1.1  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22       1.1  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23       1.1  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24       1.1  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25       1.1  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26       1.1  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27       1.1  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28       1.1  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29       1.1  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30       1.1  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     31       1.1  jdolecek  */
     32       1.1  jdolecek 
     33       1.1  jdolecek /*
     34       1.1  jdolecek  * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
     35       1.1  jdolecek  * adapters.
     36       1.1  jdolecek  *
     37       1.1  jdolecek  * Copyright (c) 1994, 1995 Charles M. Hannum.  All rights reserved.
     38       1.1  jdolecek  *
     39       1.1  jdolecek  * Copyright (C) 1993, David Greenman.  This software may be used, modified,
     40       1.1  jdolecek  * copied, distributed, and sold, in both source and binary form provided that
     41       1.1  jdolecek  * the above copyright and these terms are retained.  Under no circumstances is
     42       1.1  jdolecek  * the author responsible for the proper functioning of this software, nor does
     43       1.1  jdolecek  * the author assume any responsibility for damages incurred with its use.
     44       1.1  jdolecek  */
     45       1.1  jdolecek 
     46       1.1  jdolecek /*
     47       1.1  jdolecek  * Device driver for the Western Digital/SMC 8003 and 8013 series,
     48       1.1  jdolecek  * and the SMC Elite Ultra (8216).
     49       1.1  jdolecek  */
     50       1.4     lukem 
     51       1.4     lukem #include <sys/cdefs.h>
     52  1.19.4.2      yamt __KERNEL_RCSID(0, "$NetBSD: if_we_isa.c,v 1.19.4.2 2010/08/11 22:53:36 yamt Exp $");
     53       1.1  jdolecek 
     54       1.1  jdolecek #include <sys/param.h>
     55       1.1  jdolecek #include <sys/systm.h>
     56       1.1  jdolecek #include <sys/device.h>
     57       1.1  jdolecek #include <sys/socket.h>
     58       1.1  jdolecek #include <sys/mbuf.h>
     59       1.1  jdolecek #include <sys/syslog.h>
     60       1.1  jdolecek 
     61       1.1  jdolecek #include <net/if.h>
     62       1.1  jdolecek #include <net/if_dl.h>
     63       1.1  jdolecek #include <net/if_types.h>
     64       1.1  jdolecek #include <net/if_media.h>
     65       1.1  jdolecek 
     66       1.1  jdolecek #include <net/if_ether.h>
     67       1.1  jdolecek 
     68      1.18        ad #include <sys/bus.h>
     69      1.14       dsl #include <sys/bswap.h>
     70      1.18        ad #include <sys/intr.h>
     71       1.1  jdolecek 
     72       1.1  jdolecek #include <dev/isa/isareg.h>
     73       1.1  jdolecek #include <dev/isa/isavar.h>
     74       1.1  jdolecek 
     75       1.1  jdolecek #include <dev/ic/dp8390reg.h>
     76       1.1  jdolecek #include <dev/ic/dp8390var.h>
     77       1.1  jdolecek #include <dev/ic/wereg.h>
     78       1.1  jdolecek #include <dev/ic/wevar.h>
     79       1.1  jdolecek 
     80  1.19.4.2      yamt #include "ioconf.h"
     81  1.19.4.2      yamt 
     82       1.1  jdolecek #ifndef __BUS_SPACE_HAS_STREAM_METHODS
     83       1.1  jdolecek #define	bus_space_read_region_stream_2	bus_space_read_region_2
     84       1.1  jdolecek #define	bus_space_write_stream_2	bus_space_write_2
     85       1.1  jdolecek #define	bus_space_write_region_stream_2	bus_space_write_region_2
     86       1.1  jdolecek #endif
     87       1.1  jdolecek 
     88      1.19      cube int	we_isa_probe(device_t, cfdata_t , void *);
     89      1.19      cube void	we_isa_attach(device_t, device_t, void *);
     90       1.1  jdolecek 
     91      1.19      cube CFATTACH_DECL_NEW(we_isa, sizeof(struct we_softc),
     92       1.8   thorpej     we_isa_probe, we_isa_attach, NULL, NULL);
     93       1.1  jdolecek 
     94      1.10     perry static const char *we_params(bus_space_tag_t, bus_space_handle_t,
     95  1.19.4.2      yamt     uint8_t *, bus_size_t *, uint8_t *, int *);
     96       1.1  jdolecek 
     97       1.1  jdolecek static const int we_584_irq[] = {
     98       1.1  jdolecek 	9, 3, 5, 7, 10, 11, 15, 4,
     99       1.1  jdolecek };
    100       1.1  jdolecek 
    101       1.1  jdolecek static const int we_790_irq[] = {
    102       1.9  drochner 	ISA_UNKNOWN_IRQ, 9, 3, 5, 7, 10, 11, 15,
    103       1.1  jdolecek };
    104       1.1  jdolecek 
    105       1.1  jdolecek int
    106      1.19      cube we_isa_probe(device_t parent, cfdata_t cf, void *aux)
    107       1.1  jdolecek {
    108       1.1  jdolecek 	struct isa_attach_args *ia = aux;
    109       1.1  jdolecek 	bus_space_tag_t asict, memt;
    110       1.1  jdolecek 	bus_space_handle_t asich, memh;
    111       1.1  jdolecek 	bus_size_t memsize;
    112       1.1  jdolecek 	int asich_valid, memh_valid;
    113       1.1  jdolecek 	int i, is790, rv = 0;
    114  1.19.4.2      yamt 	uint8_t x, type;
    115       1.1  jdolecek 
    116       1.1  jdolecek 	asict = ia->ia_iot;
    117       1.1  jdolecek 	memt = ia->ia_memt;
    118       1.1  jdolecek 
    119       1.1  jdolecek 	asich_valid = memh_valid = 0;
    120       1.1  jdolecek 
    121       1.5   thorpej 	if (ia->ia_nio < 1)
    122  1.19.4.2      yamt 		return 0;
    123       1.5   thorpej 	if (ia->ia_niomem < 1)
    124  1.19.4.2      yamt 		return 0;
    125       1.5   thorpej 	if (ia->ia_nirq < 1)
    126  1.19.4.2      yamt 		return 0;
    127       1.5   thorpej 
    128       1.5   thorpej 	if (ISA_DIRECT_CONFIG(ia))
    129  1.19.4.2      yamt 		return 0;
    130       1.5   thorpej 
    131       1.1  jdolecek 	/* Disallow wildcarded i/o addresses. */
    132       1.9  drochner 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
    133  1.19.4.2      yamt 		return 0;
    134       1.1  jdolecek 
    135       1.1  jdolecek 	/* Disallow wildcarded mem address. */
    136       1.9  drochner 	if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM)
    137  1.19.4.2      yamt 		return 0;
    138       1.1  jdolecek 
    139       1.1  jdolecek 	/* Attempt to map the device. */
    140       1.5   thorpej 	if (bus_space_map(asict, ia->ia_io[0].ir_addr, WE_NPORTS, 0, &asich))
    141       1.1  jdolecek 		goto out;
    142       1.1  jdolecek 	asich_valid = 1;
    143       1.1  jdolecek 
    144       1.1  jdolecek #ifdef TOSH_ETHER
    145       1.1  jdolecek 	bus_space_write_1(asict, asich, WE_MSR, WE_MSR_POW);
    146       1.1  jdolecek #endif
    147       1.1  jdolecek 
    148       1.1  jdolecek 	/*
    149       1.1  jdolecek 	 * Attempt to do a checksum over the station address PROM.
    150       1.1  jdolecek 	 * If it fails, it's probably not a WD/SMC board.  There is
    151       1.1  jdolecek 	 * a problem with this, though.  Some clone WD8003E boards
    152       1.1  jdolecek 	 * (e.g. Danpex) won't pass the checksum.  In this case,
    153       1.1  jdolecek 	 * the checksum byte always seems to be 0.
    154       1.1  jdolecek 	 */
    155       1.1  jdolecek 	for (x = 0, i = 0; i < 8; i++)
    156       1.1  jdolecek 		x += bus_space_read_1(asict, asich, WE_PROM + i);
    157       1.1  jdolecek 
    158       1.1  jdolecek 	if (x != WE_ROM_CHECKSUM_TOTAL) {
    159       1.1  jdolecek 		/* Make sure it's an 8003E clone... */
    160       1.1  jdolecek 		if (bus_space_read_1(asict, asich, WE_CARD_ID) !=
    161       1.1  jdolecek 		    WE_TYPE_WD8003E)
    162       1.1  jdolecek 			goto out;
    163       1.1  jdolecek 
    164       1.1  jdolecek 		/* Check the checksum byte. */
    165       1.1  jdolecek 		if (bus_space_read_1(asict, asich, WE_PROM + 7) != 0)
    166       1.1  jdolecek 			goto out;
    167       1.1  jdolecek 	}
    168       1.1  jdolecek 
    169       1.1  jdolecek 	/*
    170       1.1  jdolecek 	 * Reset the card to force it into a known state.
    171       1.1  jdolecek 	 */
    172       1.1  jdolecek #ifdef TOSH_ETHER
    173       1.1  jdolecek 	bus_space_write_1(asict, asich, WE_MSR, WE_MSR_RST | WE_MSR_POW);
    174       1.1  jdolecek #else
    175       1.1  jdolecek 	bus_space_write_1(asict, asich, WE_MSR, WE_MSR_RST);
    176       1.1  jdolecek #endif
    177       1.1  jdolecek 	delay(100);
    178       1.1  jdolecek 
    179       1.1  jdolecek 	bus_space_write_1(asict, asich, WE_MSR,
    180       1.1  jdolecek 	    bus_space_read_1(asict, asich, WE_MSR) & ~WE_MSR_RST);
    181       1.1  jdolecek 
    182       1.1  jdolecek 	/* Wait in case the card is reading it's EEPROM. */
    183       1.1  jdolecek 	delay(5000);
    184       1.1  jdolecek 
    185       1.1  jdolecek 	/*
    186       1.1  jdolecek 	 * Get parameters.
    187       1.1  jdolecek 	 */
    188       1.1  jdolecek 	if (we_params(asict, asich, &type, &memsize, NULL, &is790) == NULL)
    189       1.1  jdolecek 		goto out;
    190       1.1  jdolecek 
    191       1.1  jdolecek 	/* Allow user to override probed value. */
    192       1.5   thorpej 	if (ia->ia_iomem[0].ir_size)
    193       1.5   thorpej 		memsize = ia->ia_iomem[0].ir_size;
    194       1.1  jdolecek 
    195       1.1  jdolecek 	/* Attempt to map the memory space. */
    196       1.5   thorpej 	if (bus_space_map(memt, ia->ia_iomem[0].ir_addr, memsize, 0, &memh))
    197       1.1  jdolecek 		goto out;
    198       1.1  jdolecek 	memh_valid = 1;
    199       1.1  jdolecek 
    200       1.1  jdolecek 	/*
    201       1.1  jdolecek 	 * If possible, get the assigned interrupt number from the card
    202       1.1  jdolecek 	 * and use it.
    203       1.1  jdolecek 	 */
    204       1.1  jdolecek 	if (is790) {
    205  1.19.4.2      yamt 		uint8_t hwr;
    206       1.1  jdolecek 
    207       1.1  jdolecek 		/* Assemble together the encoded interrupt number. */
    208       1.1  jdolecek 		hwr = bus_space_read_1(asict, asich, WE790_HWR);
    209       1.1  jdolecek 		bus_space_write_1(asict, asich, WE790_HWR,
    210       1.1  jdolecek 		    hwr | WE790_HWR_SWH);
    211       1.1  jdolecek 
    212       1.1  jdolecek 		x = bus_space_read_1(asict, asich, WE790_GCR);
    213       1.1  jdolecek 		i = ((x & WE790_GCR_IR2) >> 4) |
    214       1.1  jdolecek 		    ((x & (WE790_GCR_IR1|WE790_GCR_IR0)) >> 2);
    215       1.1  jdolecek 		bus_space_write_1(asict, asich, WE790_HWR,
    216       1.1  jdolecek 		    hwr & ~WE790_HWR_SWH);
    217       1.1  jdolecek 
    218       1.9  drochner 		if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
    219       1.5   thorpej 		    ia->ia_irq[0].ir_irq != we_790_irq[i])
    220      1.19      cube 			aprint_error("%s%d: overriding configured "
    221      1.19      cube 			    "IRQ %d to %d\n", we_cd.cd_name, cf->cf_unit,
    222      1.19      cube 			    ia->ia_irq[0].ir_irq, we_790_irq[i]);
    223       1.5   thorpej 		ia->ia_irq[0].ir_irq = we_790_irq[i];
    224       1.1  jdolecek 	} else if (type & WE_SOFTCONFIG) {
    225       1.1  jdolecek 		/* Assemble together the encoded interrupt number. */
    226       1.1  jdolecek 		i = (bus_space_read_1(asict, asich, WE_ICR) & WE_ICR_IR2) |
    227       1.1  jdolecek 		    ((bus_space_read_1(asict, asich, WE_IRR) &
    228       1.1  jdolecek 		      (WE_IRR_IR0 | WE_IRR_IR1)) >> 5);
    229       1.1  jdolecek 
    230       1.9  drochner 		if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
    231       1.5   thorpej 		    ia->ia_irq[0].ir_irq != we_584_irq[i])
    232      1.19      cube 			aprint_error("%s%d: overriding configured "
    233      1.19      cube 			    "IRQ %d to %d\n", we_cd.cd_name, cf->cf_unit,
    234      1.19      cube 			    ia->ia_irq[0].ir_irq, we_584_irq[i]);
    235       1.5   thorpej 		ia->ia_irq[0].ir_irq = we_584_irq[i];
    236       1.1  jdolecek 	}
    237       1.1  jdolecek 
    238       1.1  jdolecek 	/* So, we say we've found it! */
    239       1.5   thorpej 	ia->ia_nio = 1;
    240       1.5   thorpej 	ia->ia_io[0].ir_size = WE_NPORTS;
    241       1.5   thorpej 
    242       1.5   thorpej 	ia->ia_niomem = 1;
    243       1.5   thorpej 	ia->ia_iomem[0].ir_size = memsize;
    244       1.5   thorpej 
    245       1.5   thorpej 	ia->ia_nirq = 1;
    246       1.5   thorpej 
    247       1.5   thorpej 	ia->ia_ndrq = 0;
    248       1.5   thorpej 
    249       1.1  jdolecek 	rv = 1;
    250       1.1  jdolecek 
    251       1.1  jdolecek  out:
    252       1.1  jdolecek 	if (asich_valid)
    253       1.1  jdolecek 		bus_space_unmap(asict, asich, WE_NPORTS);
    254       1.1  jdolecek 	if (memh_valid)
    255       1.1  jdolecek 		bus_space_unmap(memt, memh, memsize);
    256  1.19.4.2      yamt 	return rv;
    257       1.1  jdolecek }
    258       1.1  jdolecek 
    259       1.1  jdolecek void
    260      1.19      cube we_isa_attach(device_t parent, device_t self, void *aux)
    261       1.1  jdolecek {
    262      1.19      cube 	struct we_softc *wsc = device_private(self);
    263       1.1  jdolecek 	struct dp8390_softc *sc = &wsc->sc_dp8390;
    264       1.1  jdolecek 	struct isa_attach_args *ia = aux;
    265       1.1  jdolecek 	bus_space_tag_t nict, asict, memt;
    266       1.1  jdolecek 	bus_space_handle_t nich, asich, memh;
    267       1.1  jdolecek 	const char *typestr;
    268       1.1  jdolecek 
    269      1.19      cube 	aprint_normal("\n");
    270       1.1  jdolecek 
    271      1.19      cube 	sc->sc_dev = self;
    272       1.1  jdolecek 	nict = asict = ia->ia_iot;
    273       1.1  jdolecek 	memt = ia->ia_memt;
    274       1.1  jdolecek 
    275       1.1  jdolecek 	/* Map the device. */
    276       1.5   thorpej 	if (bus_space_map(asict, ia->ia_io[0].ir_addr, WE_NPORTS, 0, &asich)) {
    277      1.19      cube 		aprint_error_dev(self, "can't map nic i/o space\n");
    278       1.1  jdolecek 		return;
    279       1.1  jdolecek 	}
    280       1.1  jdolecek 
    281       1.1  jdolecek 	if (bus_space_subregion(asict, asich, WE_NIC_OFFSET, WE_NIC_NPORTS,
    282       1.1  jdolecek 	    &nich)) {
    283      1.19      cube 		aprint_error_dev(self, "can't subregion i/o space\n");
    284       1.1  jdolecek 		return;
    285       1.1  jdolecek 	}
    286       1.1  jdolecek 
    287       1.1  jdolecek 	typestr = we_params(asict, asich, &wsc->sc_type, NULL,
    288      1.12  jdolecek 	    &wsc->sc_flags, &sc->is790);
    289       1.1  jdolecek 	if (typestr == NULL) {
    290      1.19      cube 		aprint_error_dev(self, "where did the card go?\n");
    291       1.1  jdolecek 		return;
    292       1.1  jdolecek 	}
    293       1.1  jdolecek 
    294       1.1  jdolecek 	/*
    295       1.1  jdolecek 	 * Map memory space.  Note we use the size that might have
    296       1.1  jdolecek 	 * been overridden by the user.
    297       1.1  jdolecek 	 */
    298       1.5   thorpej 	if (bus_space_map(memt, ia->ia_iomem[0].ir_addr,
    299       1.5   thorpej 	    ia->ia_iomem[0].ir_size, 0, &memh)) {
    300      1.19      cube 		aprint_error_dev(self, "can't map shared memory\n");
    301       1.1  jdolecek 		return;
    302       1.1  jdolecek 	}
    303       1.1  jdolecek 
    304       1.1  jdolecek 	wsc->sc_asict = asict;
    305       1.1  jdolecek 	wsc->sc_asich = asich;
    306       1.1  jdolecek 
    307       1.1  jdolecek 	sc->sc_regt = nict;
    308       1.1  jdolecek 	sc->sc_regh = nich;
    309       1.1  jdolecek 
    310       1.1  jdolecek 	sc->sc_buft = memt;
    311       1.1  jdolecek 	sc->sc_bufh = memh;
    312       1.1  jdolecek 
    313       1.5   thorpej 	wsc->sc_maddr = ia->ia_iomem[0].ir_addr;
    314       1.5   thorpej 	sc->mem_size = ia->ia_iomem[0].ir_size;
    315       1.1  jdolecek 
    316       1.1  jdolecek 	/* Interface is always enabled. */
    317       1.1  jdolecek 	sc->sc_enabled = 1;
    318       1.1  jdolecek 
    319       1.1  jdolecek 	if (we_config(self, wsc, typestr))
    320       1.1  jdolecek 		return;
    321       1.1  jdolecek 
    322       1.1  jdolecek 	/*
    323       1.1  jdolecek 	 * Enable the configured interrupt.
    324       1.1  jdolecek 	 */
    325       1.1  jdolecek 	if (sc->is790)
    326       1.1  jdolecek 		bus_space_write_1(asict, asich, WE790_ICR,
    327       1.1  jdolecek 		    bus_space_read_1(asict, asich, WE790_ICR) |
    328       1.1  jdolecek 		    WE790_ICR_EIL);
    329       1.1  jdolecek 	else if (wsc->sc_type & WE_SOFTCONFIG)
    330       1.1  jdolecek 		bus_space_write_1(asict, asich, WE_IRR,
    331       1.1  jdolecek 		    bus_space_read_1(asict, asich, WE_IRR) | WE_IRR_IEN);
    332       1.9  drochner 	else if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) {
    333      1.19      cube 		aprint_error_dev(self, "can't wildcard IRQ on a %s\n",
    334      1.19      cube 		    typestr);
    335       1.1  jdolecek 		return;
    336       1.1  jdolecek 	}
    337       1.1  jdolecek 
    338       1.1  jdolecek 	/* Establish interrupt handler. */
    339       1.5   thorpej 	wsc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    340       1.5   thorpej 	    IST_EDGE, IPL_NET, dp8390_intr, sc);
    341       1.1  jdolecek 	if (wsc->sc_ih == NULL)
    342      1.19      cube 		aprint_error_dev(self, "can't establish interrupt\n");
    343       1.1  jdolecek }
    344       1.1  jdolecek 
    345       1.1  jdolecek static const char *
    346  1.19.4.2      yamt we_params(bus_space_tag_t asict, bus_space_handle_t asich, uint8_t *typep,
    347  1.19.4.2      yamt     bus_size_t *memsizep, uint8_t *flagp, int *is790p)
    348       1.1  jdolecek {
    349       1.1  jdolecek 	const char *typestr;
    350       1.1  jdolecek 	bus_size_t memsize;
    351       1.1  jdolecek 	int is16bit, is790;
    352  1.19.4.2      yamt 	uint8_t type;
    353       1.1  jdolecek 
    354       1.1  jdolecek 	memsize = 8192;
    355       1.1  jdolecek 	is16bit = is790 = 0;
    356       1.1  jdolecek 
    357       1.1  jdolecek 	type = bus_space_read_1(asict, asich, WE_CARD_ID);
    358       1.1  jdolecek 	switch (type) {
    359      1.11     perry 	case WE_TYPE_WD8003S:
    360      1.11     perry 		typestr = "WD8003S";
    361       1.1  jdolecek 		break;
    362       1.1  jdolecek 	case WE_TYPE_WD8003E:
    363       1.1  jdolecek 		typestr = "WD8003E";
    364       1.1  jdolecek 		break;
    365      1.11     perry 	case WE_TYPE_WD8003EB:
    366       1.1  jdolecek 		typestr = "WD8003EB";
    367       1.1  jdolecek 		break;
    368       1.1  jdolecek 	case WE_TYPE_WD8003W:
    369       1.1  jdolecek 		typestr = "WD8003W";
    370       1.1  jdolecek 		break;
    371      1.11     perry 	case WE_TYPE_WD8013EBT:
    372       1.1  jdolecek 		typestr = "WD8013EBT";
    373       1.1  jdolecek 		memsize = 16384;
    374       1.1  jdolecek 		is16bit = 1;
    375       1.1  jdolecek 		break;
    376       1.1  jdolecek 	case WE_TYPE_WD8013W:
    377       1.1  jdolecek 		typestr = "WD8013W";
    378       1.1  jdolecek 		memsize = 16384;
    379       1.1  jdolecek 		is16bit = 1;
    380       1.1  jdolecek 		break;
    381       1.1  jdolecek 	case WE_TYPE_WD8013EP:		/* also WD8003EP */
    382       1.1  jdolecek 		if (bus_space_read_1(asict, asich, WE_ICR) & WE_ICR_16BIT) {
    383       1.1  jdolecek 			is16bit = 1;
    384       1.1  jdolecek 			memsize = 16384;
    385       1.1  jdolecek 			typestr = "WD8013EP";
    386       1.1  jdolecek 		} else
    387       1.1  jdolecek 			typestr = "WD8003EP";
    388       1.1  jdolecek 		break;
    389       1.1  jdolecek 	case WE_TYPE_WD8013WC:
    390       1.1  jdolecek 		typestr = "WD8013WC";
    391       1.1  jdolecek 		memsize = 16384;
    392       1.1  jdolecek 		is16bit = 1;
    393       1.1  jdolecek 		break;
    394       1.1  jdolecek 	case WE_TYPE_WD8013EBP:
    395       1.1  jdolecek 		typestr = "WD8013EBP";
    396       1.1  jdolecek 		memsize = 16384;
    397       1.1  jdolecek 		is16bit = 1;
    398       1.1  jdolecek 		break;
    399       1.1  jdolecek 	case WE_TYPE_WD8013EPC:
    400       1.1  jdolecek 		typestr = "WD8013EPC";
    401       1.1  jdolecek 		memsize = 16384;
    402       1.1  jdolecek 		is16bit = 1;
    403       1.1  jdolecek 		break;
    404       1.1  jdolecek 	case WE_TYPE_SMC8216C:
    405       1.1  jdolecek 	case WE_TYPE_SMC8216T:
    406       1.1  jdolecek 	    {
    407  1.19.4.2      yamt 		uint8_t hwr;
    408       1.1  jdolecek 
    409       1.1  jdolecek 		typestr = (type == WE_TYPE_SMC8216C) ?
    410       1.1  jdolecek 		    "SMC8216/SMC8216C" : "SMC8216T";
    411       1.1  jdolecek 
    412       1.1  jdolecek 		hwr = bus_space_read_1(asict, asich, WE790_HWR);
    413       1.1  jdolecek 		bus_space_write_1(asict, asich, WE790_HWR,
    414       1.1  jdolecek 		    hwr | WE790_HWR_SWH);
    415       1.1  jdolecek 		switch (bus_space_read_1(asict, asich, WE790_RAR) &
    416       1.1  jdolecek 		    WE790_RAR_SZ64) {
    417       1.1  jdolecek 		case WE790_RAR_SZ64:
    418       1.1  jdolecek 			memsize = 65536;
    419       1.1  jdolecek 			break;
    420       1.1  jdolecek 		case WE790_RAR_SZ32:
    421       1.1  jdolecek 			memsize = 32768;
    422       1.1  jdolecek 			break;
    423       1.1  jdolecek 		case WE790_RAR_SZ16:
    424       1.1  jdolecek 			memsize = 16384;
    425       1.1  jdolecek 			break;
    426       1.1  jdolecek 		case WE790_RAR_SZ8:
    427       1.1  jdolecek 			/* 8216 has 16K shared mem -- 8416 has 8K */
    428       1.1  jdolecek 			typestr = (type == WE_TYPE_SMC8216C) ?
    429       1.1  jdolecek 			    "SMC8416C/SMC8416BT" : "SMC8416T";
    430       1.1  jdolecek 			memsize = 8192;
    431       1.1  jdolecek 			break;
    432       1.1  jdolecek 		}
    433       1.1  jdolecek 		bus_space_write_1(asict, asich, WE790_HWR, hwr);
    434       1.1  jdolecek 
    435       1.1  jdolecek 		is16bit = 1;
    436       1.1  jdolecek 		is790 = 1;
    437       1.1  jdolecek 		break;
    438       1.1  jdolecek 	    }
    439       1.1  jdolecek #ifdef TOSH_ETHER
    440       1.1  jdolecek 	case WE_TYPE_TOSHIBA1:
    441       1.1  jdolecek 		typestr = "Toshiba1";
    442       1.1  jdolecek 		memsize = 32768;
    443       1.1  jdolecek 		is16bit = 1;
    444       1.1  jdolecek 		break;
    445       1.1  jdolecek 	case WE_TYPE_TOSHIBA4:
    446       1.1  jdolecek 		typestr = "Toshiba4";
    447       1.1  jdolecek 		memsize = 32768;
    448       1.1  jdolecek 		is16bit = 1;
    449       1.1  jdolecek 		break;
    450       1.1  jdolecek #endif
    451       1.1  jdolecek 	default:
    452       1.1  jdolecek 		/* Not one we recognize. */
    453  1.19.4.2      yamt 		return NULL;
    454       1.1  jdolecek 	}
    455       1.1  jdolecek 
    456       1.1  jdolecek 	/*
    457       1.1  jdolecek 	 * Make some adjustments to initial values depending on what is
    458       1.1  jdolecek 	 * found in the ICR.
    459       1.1  jdolecek 	 */
    460       1.1  jdolecek 	if (is16bit && (type != WE_TYPE_WD8013EBT) &&
    461       1.1  jdolecek #ifdef TOSH_ETHER
    462       1.1  jdolecek 	    (type != WE_TYPE_TOSHIBA1 && type != WE_TYPE_TOSHIBA4) &&
    463       1.1  jdolecek #endif
    464       1.1  jdolecek 	    (bus_space_read_1(asict, asich, WE_ICR) & WE_ICR_16BIT) == 0) {
    465       1.1  jdolecek 		is16bit = 0;
    466       1.1  jdolecek 		memsize = 8192;
    467       1.1  jdolecek 	}
    468       1.1  jdolecek 
    469       1.1  jdolecek #ifdef WE_DEBUG
    470       1.1  jdolecek 	{
    471       1.1  jdolecek 		int i;
    472       1.1  jdolecek 
    473       1.1  jdolecek 		printf("we_params: type = 0x%x, typestr = %s, is16bit = %d, "
    474      1.15  christos 		    "memsize = %ld\n", type, typestr, is16bit, (u_long)memsize);
    475       1.1  jdolecek 		for (i = 0; i < 8; i++)
    476       1.1  jdolecek 			printf("     %d -> 0x%x\n", i,
    477       1.1  jdolecek 			    bus_space_read_1(asict, asich, i));
    478       1.1  jdolecek 	}
    479       1.1  jdolecek #endif
    480       1.1  jdolecek 
    481       1.1  jdolecek 	if (typep != NULL)
    482       1.1  jdolecek 		*typep = type;
    483       1.1  jdolecek 	if (memsizep != NULL)
    484       1.1  jdolecek 		*memsizep = memsize;
    485      1.12  jdolecek 	if (flagp != NULL && is16bit)
    486      1.12  jdolecek 		*flagp |= WE_16BIT_ENABLE;
    487       1.1  jdolecek 	if (is790p != NULL)
    488       1.1  jdolecek 		*is790p = is790;
    489  1.19.4.2      yamt 	return typestr;
    490       1.1  jdolecek }
    491