Home | History | Annotate | Line # | Download | only in isa
if_cs_isa.c revision 1.10.6.4
      1  1.10.6.4     skrll /*	$NetBSD: if_cs_isa.c,v 1.10.6.4 2005/02/04 11:46:08 skrll Exp $	*/
      2       1.1   thorpej 
      3       1.1   thorpej /*
      4       1.1   thorpej  * Copyright 1997
      5       1.1   thorpej  * Digital Equipment Corporation. All rights reserved.
      6       1.1   thorpej  *
      7       1.1   thorpej  * This software is furnished under license and may be used and
      8       1.1   thorpej  * copied only in accordance with the following terms and conditions.
      9       1.1   thorpej  * Subject to these conditions, you may download, copy, install,
     10       1.1   thorpej  * use, modify and distribute this software in source and/or binary
     11       1.1   thorpej  * form. No title or ownership is transferred hereby.
     12       1.1   thorpej  *
     13       1.1   thorpej  * 1) Any source code used, modified or distributed must reproduce
     14       1.1   thorpej  *    and retain this copyright notice and list of conditions as
     15       1.1   thorpej  *    they appear in the source file.
     16       1.1   thorpej  *
     17       1.1   thorpej  * 2) No right is granted to use any trade name, trademark, or logo of
     18       1.1   thorpej  *    Digital Equipment Corporation. Neither the "Digital Equipment
     19       1.1   thorpej  *    Corporation" name nor any trademark or logo of Digital Equipment
     20       1.1   thorpej  *    Corporation may be used to endorse or promote products derived
     21       1.1   thorpej  *    from this software without the prior written permission of
     22       1.1   thorpej  *    Digital Equipment Corporation.
     23       1.1   thorpej  *
     24       1.1   thorpej  * 3) This software is provided "AS-IS" and any express or implied
     25       1.1   thorpej  *    warranties, including but not limited to, any implied warranties
     26       1.1   thorpej  *    of merchantability, fitness for a particular purpose, or
     27       1.1   thorpej  *    non-infringement are disclaimed. In no event shall DIGITAL be
     28       1.1   thorpej  *    liable for any damages whatsoever, and in particular, DIGITAL
     29       1.1   thorpej  *    shall not be liable for special, indirect, consequential, or
     30       1.1   thorpej  *    incidental damages or damages for lost profits, loss of
     31       1.1   thorpej  *    revenue or loss of use, whether such damages arise in contract,
     32       1.1   thorpej  *    negligence, tort, under statute, in equity, at law or otherwise,
     33       1.1   thorpej  *    even if advised of the possibility of such damage.
     34       1.1   thorpej  */
     35       1.4     lukem 
     36       1.4     lukem #include <sys/cdefs.h>
     37  1.10.6.4     skrll __KERNEL_RCSID(0, "$NetBSD: if_cs_isa.c,v 1.10.6.4 2005/02/04 11:46:08 skrll Exp $");
     38       1.1   thorpej 
     39       1.1   thorpej #include <sys/param.h>
     40       1.1   thorpej #include <sys/systm.h>
     41       1.1   thorpej #include <sys/socket.h>
     42       1.1   thorpej #include <sys/device.h>
     43       1.3   mycroft 
     44       1.3   mycroft #include "rnd.h"
     45       1.3   mycroft #if NRND > 0
     46       1.3   mycroft #include <sys/rnd.h>
     47       1.3   mycroft #endif
     48       1.1   thorpej 
     49       1.1   thorpej #include <net/if.h>
     50       1.1   thorpej #include <net/if_ether.h>
     51       1.1   thorpej #include <net/if_media.h>
     52       1.1   thorpej 
     53       1.1   thorpej #include <machine/bus.h>
     54       1.1   thorpej #include <machine/intr.h>
     55       1.1   thorpej 
     56       1.1   thorpej #include <dev/isa/isareg.h>
     57       1.1   thorpej #include <dev/isa/isavar.h>
     58       1.1   thorpej #include <dev/isa/isadmavar.h>
     59       1.1   thorpej 
     60       1.5      yamt #include <dev/ic/cs89x0reg.h>
     61       1.5      yamt #include <dev/ic/cs89x0var.h>
     62       1.5      yamt #include <dev/isa/cs89x0isavar.h>
     63       1.1   thorpej 
     64  1.10.6.4     skrll int	cs_isa_probe(struct device *, struct cfdata *, void *);
     65  1.10.6.4     skrll void	cs_isa_attach(struct device *, struct device *, void *);
     66       1.1   thorpej 
     67      1.10   thorpej CFATTACH_DECL(cs_isa, sizeof(struct cs_softc),
     68      1.10   thorpej     cs_isa_probe, cs_isa_attach, NULL, NULL);
     69       1.1   thorpej 
     70       1.1   thorpej int
     71       1.1   thorpej cs_isa_probe(parent, cf, aux)
     72       1.1   thorpej 	struct device *parent;
     73       1.1   thorpej 	struct cfdata *cf;
     74       1.1   thorpej 	void *aux;
     75       1.1   thorpej {
     76       1.1   thorpej 	struct isa_attach_args *ia = aux;
     77       1.1   thorpej 	bus_space_tag_t iot = ia->ia_iot;
     78       1.1   thorpej 	bus_space_tag_t memt = ia->ia_memt;
     79       1.1   thorpej 	bus_space_handle_t ioh, memh;
     80       1.7  augustss 	struct cs_softc sc;
     81       1.1   thorpej 	int rv = 0, have_io = 0, have_mem = 0;
     82       1.1   thorpej 	u_int16_t isa_cfg, isa_membase;
     83       1.6   thorpej 	int maddr, irq;
     84       1.6   thorpej 
     85       1.6   thorpej 	if (ia->ia_nio < 1)
     86       1.6   thorpej 		return (0);
     87       1.6   thorpej 	if (ia->ia_nirq < 1)
     88       1.6   thorpej 		return (0);
     89       1.6   thorpej 
     90       1.6   thorpej 	if (ISA_DIRECT_CONFIG(ia))
     91       1.6   thorpej 		return (0);
     92       1.1   thorpej 
     93       1.1   thorpej 	/*
     94       1.1   thorpej 	 * Disallow wildcarded I/O base.
     95       1.1   thorpej 	 */
     96  1.10.6.2     skrll 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
     97       1.1   thorpej 		return (0);
     98       1.1   thorpej 
     99       1.6   thorpej 	if (ia->ia_niomem > 0)
    100       1.6   thorpej 		maddr = ia->ia_iomem[0].ir_addr;
    101       1.6   thorpej 	else
    102  1.10.6.2     skrll 		maddr = ISA_UNKNOWN_IOMEM;
    103       1.6   thorpej 
    104       1.1   thorpej 	/*
    105       1.1   thorpej 	 * Map the I/O space.
    106       1.1   thorpej 	 */
    107       1.6   thorpej 	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, CS8900_IOSIZE,
    108       1.6   thorpej 	    0, &ioh))
    109       1.1   thorpej 		goto out;
    110       1.1   thorpej 	have_io = 1;
    111       1.1   thorpej 
    112       1.7  augustss 	memset(&sc, 0, sizeof sc);
    113       1.7  augustss 	sc.sc_iot = iot;
    114       1.7  augustss 	sc.sc_ioh = ioh;
    115       1.1   thorpej 	/* Verify that it's a Crystal product. */
    116       1.7  augustss 	if (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_EISA_NUM) !=
    117       1.1   thorpej 	    EISA_NUM_CRYSTAL)
    118       1.1   thorpej 		goto out;
    119       1.1   thorpej 
    120       1.1   thorpej 	/*
    121       1.1   thorpej 	 * Verify that it's a supported chip.
    122       1.1   thorpej 	 */
    123       1.7  augustss 	switch (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_PRODUCT_ID) &
    124       1.1   thorpej 	    PROD_ID_MASK) {
    125       1.1   thorpej 	case PROD_ID_CS8900:
    126       1.1   thorpej #ifdef notyet
    127       1.1   thorpej 	case PROD_ID_CS8920:
    128       1.1   thorpej 	case PROD_ID_CS8920M:
    129       1.1   thorpej #endif
    130  1.10.6.1     skrll 		break;
    131  1.10.6.1     skrll 	default:
    132  1.10.6.1     skrll 		/* invalid product ID */
    133  1.10.6.1     skrll 		goto out;
    134       1.1   thorpej 	}
    135       1.1   thorpej 
    136       1.1   thorpej 	/*
    137       1.1   thorpej 	 * If the IRQ or memory address were not specified, read the
    138       1.1   thorpej 	 * ISA_CFG EEPROM location.
    139       1.1   thorpej 	 */
    140  1.10.6.2     skrll 	if (maddr == ISA_UNKNOWN_IOMEM ||
    141  1.10.6.2     skrll 	    ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) {
    142       1.7  augustss 		if (cs_verify_eeprom(&sc) == CS_ERROR) {
    143       1.1   thorpej 			printf("cs_isa_probe: EEPROM bad or missing\n");
    144       1.1   thorpej 			goto out;
    145       1.1   thorpej 		}
    146       1.7  augustss 		if (cs_read_eeprom(&sc, EEPROM_ISA_CFG, &isa_cfg)
    147       1.1   thorpej 		    == CS_ERROR) {
    148       1.1   thorpej 			printf("cs_isa_probe: unable to read ISA_CFG\n");
    149       1.1   thorpej 			goto out;
    150       1.1   thorpej 		}
    151       1.1   thorpej 	}
    152       1.1   thorpej 
    153       1.1   thorpej 	/*
    154       1.1   thorpej 	 * If the IRQ wasn't specified, get it from the EEPROM.
    155       1.1   thorpej 	 */
    156  1.10.6.2     skrll 	if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) {
    157       1.1   thorpej 		irq = isa_cfg & ISA_CFG_IRQ_MASK;
    158       1.1   thorpej 		if (irq == 3)
    159       1.1   thorpej 			irq = 5;
    160       1.1   thorpej 		else
    161       1.1   thorpej 			irq += 10;
    162       1.6   thorpej 	} else
    163       1.6   thorpej 		irq = ia->ia_irq[0].ir_irq;
    164       1.1   thorpej 
    165       1.1   thorpej 	/*
    166       1.1   thorpej 	 * If the memory address wasn't specified, get it from the EEPROM.
    167       1.1   thorpej 	 */
    168  1.10.6.2     skrll 	if (maddr == ISA_UNKNOWN_IOMEM) {
    169       1.1   thorpej 		if ((isa_cfg & ISA_CFG_MEM_MODE) == 0) {
    170       1.1   thorpej 			/* EEPROM says don't use memory mode. */
    171       1.1   thorpej 			goto out;
    172       1.1   thorpej 		}
    173       1.7  augustss 		if (cs_read_eeprom(&sc, EEPROM_MEM_BASE, &isa_membase)
    174       1.1   thorpej 		    == CS_ERROR) {
    175       1.1   thorpej 			printf("cs_isa_probe: unable to read MEM_BASE\n");
    176       1.1   thorpej 			goto out;
    177       1.1   thorpej 		}
    178       1.1   thorpej 
    179       1.1   thorpej 		isa_membase &= MEM_BASE_MASK;
    180       1.1   thorpej 		maddr = (int)isa_membase << 8;
    181       1.1   thorpej 	}
    182       1.1   thorpej 
    183       1.1   thorpej 	/*
    184       1.1   thorpej 	 * We now have a valid mem address; attempt to map it.
    185       1.1   thorpej 	 */
    186       1.1   thorpej 	if (bus_space_map(ia->ia_memt, maddr, CS8900_MEMSIZE, 0, &memh)) {
    187       1.1   thorpej 		/* Can't map it; fall back on i/o-only mode. */
    188       1.1   thorpej 		printf("cs_isa_probe: unable to map memory space\n");
    189  1.10.6.2     skrll 		maddr = ISA_UNKNOWN_IOMEM;
    190       1.1   thorpej 	} else
    191       1.1   thorpej 		have_mem = 1;
    192       1.1   thorpej 
    193  1.10.6.1     skrll 	ia->ia_nio = 1;
    194  1.10.6.1     skrll 	ia->ia_io[0].ir_size = CS8900_IOSIZE;
    195  1.10.6.1     skrll 
    196  1.10.6.2     skrll 	if (maddr == ISA_UNKNOWN_IOMEM)
    197  1.10.6.1     skrll 		ia->ia_niomem = 0;
    198  1.10.6.1     skrll 	else {
    199  1.10.6.1     skrll 		ia->ia_niomem = 1;
    200  1.10.6.1     skrll 		ia->ia_iomem[0].ir_addr = maddr;
    201  1.10.6.1     skrll 		ia->ia_iomem[0].ir_size = CS8900_MEMSIZE;
    202  1.10.6.1     skrll 	}
    203  1.10.6.1     skrll 
    204  1.10.6.1     skrll 	ia->ia_nirq = 1;
    205  1.10.6.1     skrll 	ia->ia_irq[0].ir_irq = irq;
    206  1.10.6.1     skrll 
    207  1.10.6.1     skrll 	rv = 1;
    208  1.10.6.1     skrll 
    209       1.1   thorpej  out:
    210       1.1   thorpej 	if (have_io)
    211       1.1   thorpej 		bus_space_unmap(iot, ioh, CS8900_IOSIZE);
    212       1.1   thorpej 	if (have_mem)
    213       1.1   thorpej 		bus_space_unmap(memt, memh, CS8900_MEMSIZE);
    214       1.1   thorpej 
    215       1.1   thorpej 	return (rv);
    216       1.1   thorpej }
    217       1.1   thorpej 
    218       1.1   thorpej void
    219       1.1   thorpej cs_isa_attach(parent, self, aux)
    220       1.1   thorpej 	struct device *parent, *self;
    221       1.1   thorpej 	void *aux;
    222       1.1   thorpej {
    223       1.1   thorpej 	struct cs_softc *sc = (struct cs_softc *) self;
    224       1.5      yamt 	struct cs_softc_isa *isc = (void *) self;
    225       1.1   thorpej 	struct isa_attach_args *ia = aux;
    226       1.1   thorpej 
    227       1.5      yamt 	isc->sc_ic = ia->ia_ic;
    228       1.1   thorpej 	sc->sc_iot = ia->ia_iot;
    229       1.1   thorpej 	sc->sc_memt = ia->ia_memt;
    230       1.1   thorpej 
    231       1.6   thorpej 	if (ia->ia_ndrq > 0)
    232       1.6   thorpej 		isc->sc_drq = ia->ia_drq[0].ir_drq;
    233       1.6   thorpej 	else
    234       1.6   thorpej 		isc->sc_drq = -1;
    235       1.6   thorpej 
    236       1.6   thorpej 	sc->sc_irq = ia->ia_irq[0].ir_irq;
    237       1.1   thorpej 
    238       1.1   thorpej 	printf("\n");
    239       1.1   thorpej 
    240       1.1   thorpej 	/*
    241       1.1   thorpej 	 * Map the device.
    242       1.1   thorpej 	 */
    243       1.6   thorpej 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, CS8900_IOSIZE,
    244       1.1   thorpej 	    0, &sc->sc_ioh)) {
    245       1.1   thorpej 		printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
    246       1.1   thorpej 		return;
    247       1.1   thorpej 	}
    248       1.1   thorpej 
    249       1.1   thorpej 	/*
    250       1.1   thorpej 	 * Validate IRQ.
    251       1.1   thorpej 	 */
    252       1.1   thorpej 	if (CS8900_IRQ_ISVALID(sc->sc_irq) == 0) {
    253       1.1   thorpej 		printf("%s: invalid IRQ %d\n", sc->sc_dev.dv_xname, sc->sc_irq);
    254       1.1   thorpej 		return;
    255       1.1   thorpej 	}
    256       1.1   thorpej 
    257       1.1   thorpej 	/*
    258       1.1   thorpej 	 * Map the memory space if it was specified.  If we can do this,
    259       1.1   thorpej 	 * we set ourselves up to use memory mode forever.  Otherwise,
    260       1.1   thorpej 	 * we fall back on I/O mode.
    261       1.1   thorpej 	 */
    262  1.10.6.2     skrll 	if (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM &&
    263       1.6   thorpej 	    ia->ia_iomem[0].ir_size == CS8900_MEMSIZE &&
    264       1.6   thorpej 	    CS8900_MEMBASE_ISVALID(ia->ia_iomem[0].ir_addr)) {
    265       1.6   thorpej 		if (bus_space_map(sc->sc_memt, ia->ia_iomem[0].ir_addr,
    266       1.6   thorpej 		    CS8900_MEMSIZE, 0, &sc->sc_memh)) {
    267       1.1   thorpej 			printf("%s: unable to map memory space\n",
    268       1.1   thorpej 			    sc->sc_dev.dv_xname);
    269       1.1   thorpej 		} else {
    270       1.1   thorpej 			sc->sc_cfgflags |= CFGFLG_MEM_MODE;
    271       1.6   thorpej 			sc->sc_pktpgaddr = ia->ia_iomem[0].ir_addr;
    272       1.1   thorpej 		}
    273       1.1   thorpej 	}
    274       1.1   thorpej 
    275       1.1   thorpej 	sc->sc_ih = isa_intr_establish(ia->ia_ic, sc->sc_irq, IST_EDGE,
    276       1.1   thorpej 	    IPL_NET, cs_intr, sc);
    277       1.1   thorpej 	if (sc->sc_ih == NULL) {
    278       1.1   thorpej 		printf("%s: unable to establish interrupt\n",
    279       1.1   thorpej 		    sc->sc_dev.dv_xname);
    280       1.1   thorpej 		return;
    281       1.1   thorpej 	}
    282       1.5      yamt 
    283       1.5      yamt 	sc->sc_dma_chipinit = cs_isa_dma_chipinit;
    284       1.5      yamt 	sc->sc_dma_attach = cs_isa_dma_attach;
    285       1.5      yamt 	sc->sc_dma_process_rx = cs_process_rx_dma;
    286       1.1   thorpej 
    287       1.1   thorpej 	cs_attach(sc, NULL, NULL, 0, 0);
    288       1.1   thorpej }
    289