Home | History | Annotate | Line # | Download | only in isapnp
if_cs_isapnp.c revision 1.17
      1  1.17   tsutsui /* $NetBSD: if_cs_isapnp.c,v 1.17 2009/09/22 16:44:08 tsutsui Exp $ */
      2   1.1      yamt 
      3   1.1      yamt /*-
      4   1.1      yamt  * Copyright (c)2001 YAMAMOTO Takashi,
      5   1.1      yamt  * All rights reserved.
      6   1.1      yamt  *
      7   1.1      yamt  * Redistribution and use in source and binary forms, with or without
      8   1.1      yamt  * modification, are permitted provided that the following conditions
      9   1.1      yamt  * are met:
     10   1.1      yamt  * 1. Redistributions of source code must retain the above copyright
     11   1.1      yamt  *    notice, this list of conditions and the following disclaimer.
     12   1.1      yamt  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1      yamt  *    notice, this list of conditions and the following disclaimer in the
     14   1.1      yamt  *    documentation and/or other materials provided with the distribution.
     15   1.1      yamt  *
     16   1.1      yamt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17   1.1      yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18   1.1      yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19   1.1      yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20   1.1      yamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21   1.1      yamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22   1.1      yamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23   1.1      yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24   1.1      yamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25   1.1      yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26   1.1      yamt  * SUCH DAMAGE.
     27   1.1      yamt  */
     28   1.1      yamt 
     29   1.1      yamt #include <sys/cdefs.h>
     30  1.17   tsutsui __KERNEL_RCSID(0, "$NetBSD: if_cs_isapnp.c,v 1.17 2009/09/22 16:44:08 tsutsui Exp $");
     31   1.1      yamt 
     32   1.1      yamt #include <sys/param.h>
     33   1.1      yamt #include <sys/systm.h>
     34   1.1      yamt #include <sys/device.h>
     35   1.7     perry #include <sys/socket.h>
     36   1.1      yamt 
     37   1.1      yamt #include "rnd.h"
     38   1.1      yamt #if NRND > 0
     39   1.1      yamt #include <sys/rnd.h>
     40   1.1      yamt #endif
     41   1.1      yamt 
     42   1.1      yamt #include <net/if.h>
     43   1.1      yamt #include <net/if_ether.h>
     44   1.1      yamt #include <net/if_media.h>
     45   1.1      yamt 
     46  1.10        ad #include <sys/bus.h>
     47  1.10        ad #include <sys/intr.h>
     48   1.1      yamt 
     49   1.1      yamt #include <dev/isa/isavar.h>
     50   1.1      yamt 
     51   1.1      yamt #include <dev/ic/cs89x0reg.h>
     52   1.1      yamt #include <dev/ic/cs89x0var.h>
     53   1.1      yamt 
     54   1.1      yamt #include <dev/isapnp/isapnpreg.h>
     55   1.1      yamt #include <dev/isapnp/isapnpvar.h>
     56   1.1      yamt #include <dev/isapnp/isapnpdevs.h>
     57   1.1      yamt 
     58  1.16   tsutsui #define DEVNAME(sc) device_xname((sc)->sc_dev)
     59   1.1      yamt 
     60  1.17   tsutsui static int cs_isapnp_match(device_t, cfdata_t, void *);
     61  1.17   tsutsui static void cs_isapnp_attach(device_t, device_t, void *);
     62   1.1      yamt 
     63  1.16   tsutsui #ifdef notyet
     64  1.16   tsutsui CFATTACH_DECL_NEW(cs_isapnp, sizeof(struct cs_softc_isa),
     65  1.16   tsutsui     cs_isapnp_match, cs_isapnp_attach, NULL, NULL);
     66  1.16   tsutsui #else
     67  1.16   tsutsui CFATTACH_DECL_NEW(cs_isapnp, sizeof(struct cs_softc),
     68   1.5   thorpej     cs_isapnp_match, cs_isapnp_attach, NULL, NULL);
     69  1.16   tsutsui #endif
     70   1.1      yamt 
     71   1.1      yamt int
     72  1.15    cegger cs_isapnp_match(device_t parent, cfdata_t match, void *aux)
     73   1.1      yamt {
     74   1.1      yamt 	int pri, variant;
     75   1.1      yamt 
     76   1.1      yamt 	pri = isapnp_devmatch(aux, &isapnp_cs_devinfo, &variant);
     77   1.1      yamt 	if (pri && variant > 0)
     78   1.1      yamt 		pri = 0;
     79   1.1      yamt 	return pri;
     80   1.1      yamt }
     81   1.1      yamt 
     82   1.1      yamt void
     83  1.15    cegger cs_isapnp_attach(device_t parent, device_t self, void *aux)
     84   1.1      yamt {
     85  1.16   tsutsui #ifdef notyet
     86  1.16   tsutsui 	struct cs_softc_isa *isc = device_private(sc);
     87  1.16   tsutsui 	struct cs_softc *sc = &sc->sc_cs;
     88  1.16   tsutsui #else
     89   1.9   thorpej 	struct cs_softc *sc = device_private(self);
     90  1.16   tsutsui #endif
     91   1.1      yamt 	struct isapnp_attach_args *ipa = aux;
     92   1.1      yamt #ifdef notyet
     93   1.1      yamt 	int i;
     94   1.1      yamt #endif
     95   1.1      yamt 
     96  1.16   tsutsui 	sc->sc_dev = self;
     97  1.16   tsutsui 
     98   1.1      yamt 	printf("\n");
     99   1.1      yamt 
    100   1.1      yamt 	if (ipa->ipa_nio != 1 || ipa->ipa_nirq != 1 || ipa->ipa_ndrq) {
    101   1.1      yamt 		printf("%s: unexpected resource requirements\n",
    102   1.1      yamt 			DEVNAME(sc));
    103   1.1      yamt 		return;
    104   1.1      yamt 	}
    105   1.1      yamt 
    106   1.1      yamt 	if (ipa->ipa_io[0].length != CS8900_IOSIZE) {
    107   1.1      yamt 		printf("%s: unexpected io size\n", DEVNAME(sc));
    108   1.1      yamt 		return;
    109   1.1      yamt 	}
    110   1.1      yamt 
    111   1.1      yamt 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    112   1.1      yamt 		printf("%s: unable to allocate resources\n", DEVNAME(sc));
    113   1.1      yamt 		return;
    114   1.1      yamt 	}
    115   1.1      yamt 
    116   1.1      yamt 	printf("%s: %s %s\n", DEVNAME(sc), ipa->ipa_devident,
    117   1.1      yamt 		ipa->ipa_devclass);
    118   1.1      yamt 
    119   1.1      yamt #ifdef notyet
    120   1.1      yamt #ifdef DEBUG
    121   1.7     perry 	printf("%s: nio=%u, nmem=%u, nmem32=%u, ndrq=%u, nirq=%u\n", DEVNAME(sc),
    122   1.1      yamt 		ipa->ipa_nio, ipa->ipa_nmem, ipa->ipa_nmem32, ipa->ipa_ndrq, ipa->ipa_nirq);
    123   1.1      yamt #endif
    124   1.1      yamt 	isc->sc_ic = ipa->ipa_ic;
    125   1.6  drochner 	isc->sc_drq = -1;
    126   1.1      yamt #endif
    127   1.1      yamt 	sc->sc_iot = ipa->ipa_iot;
    128   1.1      yamt 	sc->sc_ioh = ipa->ipa_io[0].h;
    129   1.1      yamt 	sc->sc_irq = ipa->ipa_irq[0].num;
    130   1.1      yamt 
    131   1.1      yamt #ifdef notyet
    132   1.1      yamt 	for (i = 0; i < ipa->ipa_nmem; i++) {
    133   1.1      yamt 		if (ipa->ipa_mem[i].length == CS8900_MEMSIZE) {
    134   1.1      yamt #if 0
    135   1.1      yamt 			u_int16_t id;
    136   1.1      yamt 
    137   1.2  augustss 			id = CS_READ_PACKET_PAGE_MEM(sc, PKTPG_EISA_NUM);
    138   1.1      yamt 			if (id != EISA_NUM_CRYSTAL) {
    139   1.1      yamt 				printf("%s: unexpected id(%u)\n",
    140   1.1      yamt 					 DEVNAME(sc), id);
    141   1.1      yamt 				continue;
    142   1.1      yamt 			}
    143   1.1      yamt 			printf("%s: correct id(%u) from mem=%u\n",
    144   1.1      yamt 				 DEVNAME(sc), id, (u_int)ipa->ipa_mem[i].h);
    145   1.1      yamt #endif
    146   1.7     perry 
    147   1.1      yamt 			sc->sc_memt = ipa->ipa_memt;
    148   1.1      yamt 			sc->sc_memh = ipa->ipa_mem[i].h;
    149   1.1      yamt 			sc->sc_pktpgaddr = ipa->ipa_mem[i].base;
    150   1.1      yamt 			sc->sc_cfgflags |= CFGFLG_MEM_MODE;
    151   1.1      yamt 			printf("%s: memory mode\n", DEVNAME(sc));
    152   1.1      yamt 			break;
    153   1.1      yamt 		}
    154   1.1      yamt 	}
    155   1.1      yamt #endif
    156   1.1      yamt 
    157   1.1      yamt 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    158   1.1      yamt 		ipa->ipa_irq[0].type, IPL_NET, cs_intr, sc);
    159   1.1      yamt 	if (sc->sc_ih == 0) {
    160   1.1      yamt 		printf("%s: unable to establish interrupt\n",
    161   1.1      yamt 			DEVNAME(sc));
    162   1.1      yamt 		goto fail;
    163   1.1      yamt 	}
    164   1.1      yamt 
    165   1.1      yamt 	if (cs_attach(sc, 0, 0, 0, 0)) {
    166   1.1      yamt 		printf("%s: unable to attach\n", DEVNAME(sc));
    167   1.1      yamt 		goto fail;
    168   1.1      yamt 	}
    169   1.1      yamt 
    170   1.1      yamt 	return;
    171   1.1      yamt 
    172   1.1      yamt fail:
    173   1.1      yamt 	if (sc->sc_ih)
    174   1.1      yamt 		isa_intr_disestablish(ipa->ipa_ic, sc->sc_ih);
    175   1.1      yamt 	isapnp_unconfig(ipa->ipa_iot, ipa->ipa_memt, ipa);
    176   1.1      yamt }
    177