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