1 /* $NetBSD: depca_eisa.c,v 1.5 2002/10/02 16:33:46 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * EISA bus front-end for the Digital DEPCA Ethernet controller. 41 */ 42 43 #include <sys/cdefs.h> 44 __KERNEL_RCSID(0, "$NetBSD: depca_eisa.c,v 1.5 2002/10/02 16:33:46 thorpej Exp $"); 45 46 #include "opt_inet.h" 47 #include "bpfilter.h" 48 49 #include <sys/param.h> 50 #include <sys/systm.h> 51 #include <sys/mbuf.h> 52 #include <sys/syslog.h> 53 #include <sys/socket.h> 54 #include <sys/device.h> 55 56 #include <net/if.h> 57 #include <net/if_media.h> 58 #include <net/if_ether.h> 59 60 #ifdef INET 61 #include <netinet/in.h> 62 #include <netinet/if_inarp.h> 63 #endif 64 65 #include <machine/bus.h> 66 #include <machine/intr.h> 67 68 #include <dev/eisa/eisareg.h> 69 #include <dev/eisa/eisavar.h> 70 #include <dev/eisa/eisadevs.h> 71 72 #include <dev/ic/lancereg.h> 73 #include <dev/ic/lancevar.h> 74 #include <dev/ic/am7990reg.h> 75 #include <dev/ic/am7990var.h> 76 #include <dev/ic/depcareg.h> 77 #include <dev/ic/depcavar.h> 78 79 int depca_eisa_match(struct device *, struct cfdata *, void *); 80 void depca_eisa_attach(struct device *, struct device *, void *); 81 82 struct depca_eisa_softc { 83 struct depca_softc sc_depca; 84 85 eisa_chipset_tag_t sc_ec; 86 int sc_irq; 87 int sc_ist; 88 }; 89 90 CFATTACH_DECL(depca_eisa, sizeof(struct depca_eisa_softc), 91 depca_eisa_match, depca_eisa_attach, NULL, NULL); 92 93 void *depca_eisa_intr_establish(struct depca_softc *, struct lance_softc *); 94 95 int 96 depca_eisa_match(struct device *parent, struct cfdata *match, void *aux) 97 { 98 struct eisa_attach_args *ea = aux; 99 100 return (strcmp(ea->ea_idstring, "DEC4220") == 0); 101 } 102 103 #define DEPCA_ECU_FUNC_NETINTR 0 104 #define DEPCA_ECU_FUNC_NETBUF 1 105 106 void 107 depca_eisa_attach(struct device *parent, struct device *self, void *aux) 108 { 109 struct depca_softc *sc = (void *) self; 110 struct depca_eisa_softc *esc = (void *) self; 111 struct eisa_attach_args *ea = aux; 112 struct eisa_cfg_mem ecm; 113 struct eisa_cfg_irq eci; 114 115 printf(": DEC DE422 Ethernet\n"); 116 117 sc->sc_iot = ea->ea_iot; 118 sc->sc_memt = ea->ea_memt; 119 120 esc->sc_ec = ea->ea_ec; 121 122 sc->sc_intr_establish = depca_eisa_intr_establish; 123 124 if (eisa_conf_read_mem(ea->ea_ec, ea->ea_slot, 125 DEPCA_ECU_FUNC_NETBUF, 0, &ecm) != 0) { 126 printf("%s: unable to find network buffer\n", 127 sc->sc_dev.dv_xname); 128 return; 129 } 130 131 printf("%s: shared memory at 0x%lx-0x%lx\n", sc->sc_dev.dv_xname, 132 ecm.ecm_addr, ecm.ecm_addr + ecm.ecm_size - 1); 133 134 sc->sc_memsize = ecm.ecm_size; 135 136 if (bus_space_map(sc->sc_iot, EISA_SLOT_ADDR(ea->ea_slot) + 0xc00, 16, 137 0, &sc->sc_ioh) != 0) { 138 printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname); 139 return; 140 } 141 if (bus_space_map(sc->sc_memt, ecm.ecm_addr, sc->sc_memsize, 142 0, &sc->sc_memh) != 0) { 143 printf("%s: unable to map memory space\n", sc->sc_dev.dv_xname); 144 return; 145 } 146 147 if (eisa_conf_read_irq(ea->ea_ec, ea->ea_slot, 148 DEPCA_ECU_FUNC_NETINTR, 0, &eci) != 0) { 149 printf("%s: unable to determine IRQ\n", 150 sc->sc_dev.dv_xname); 151 return; 152 } 153 154 esc->sc_irq = eci.eci_irq; 155 esc->sc_ist = eci.eci_ist; 156 157 depca_attach(sc); 158 } 159 160 void * 161 depca_eisa_intr_establish(struct depca_softc *parent, struct lance_softc *child) 162 { 163 struct depca_eisa_softc *esc = (void *) parent; 164 eisa_intr_handle_t ih; 165 const char *intrstr; 166 void *rv; 167 168 if (eisa_intr_map(esc->sc_ec, esc->sc_irq, &ih)) { 169 printf("%s: unable to map interrupt (%d)\n", 170 parent->sc_dev.dv_xname, esc->sc_irq); 171 return (NULL); 172 } 173 intrstr = eisa_intr_string(esc->sc_ec, ih); 174 rv = eisa_intr_establish(esc->sc_ec, ih, esc->sc_ist, IPL_NET, 175 (esc->sc_ist == IST_LEVEL) ? am7990_intr : depca_intredge, child); 176 if (rv == NULL) { 177 printf("%s: unable to establish interrupt", 178 parent->sc_dev.dv_xname); 179 if (intrstr != NULL) 180 printf(" at %s", intrstr); 181 printf("\n"); 182 return (NULL); 183 } 184 if (intrstr != NULL) 185 printf("%s: interrupting at %s\n", parent->sc_dev.dv_xname, 186 intrstr); 187 188 return (rv); 189 } 190