depca_eisa.c revision 1.11
1/* $NetBSD: depca_eisa.c,v 1.11 2008/04/04 12:25:07 tsutsui 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.11 2008/04/04 12:25:07 tsutsui 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 <sys/bus.h> 66#include <sys/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 79static int depca_eisa_match(device_t, cfdata_t, void *); 80static void depca_eisa_attach(device_t, device_t, void *); 81 82struct 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 90CFATTACH_DECL_NEW(depca_eisa, sizeof(struct depca_eisa_softc), 91 depca_eisa_match, depca_eisa_attach, NULL, NULL); 92 93static void *depca_eisa_intr_establish(struct depca_softc *, 94 struct lance_softc *); 95 96static int 97depca_eisa_match(device_t parent, cfdata_t cf, void *aux) 98{ 99 struct eisa_attach_args *ea = aux; 100 101 return (strcmp(ea->ea_idstring, "DEC4220") == 0); 102} 103 104#define DEPCA_ECU_FUNC_NETINTR 0 105#define DEPCA_ECU_FUNC_NETBUF 1 106 107static void 108depca_eisa_attach(device_t parent, device_t self, void *aux) 109{ 110 struct depca_eisa_softc *esc = device_private(self); 111 struct depca_softc *sc = &esc->sc_depca; 112 struct eisa_attach_args *ea = aux; 113 struct eisa_cfg_mem ecm; 114 struct eisa_cfg_irq eci; 115 116 sc->sc_dev = self; 117 aprint_error(": DEC DE422 Ethernet\n"); 118 119 sc->sc_iot = ea->ea_iot; 120 sc->sc_memt = ea->ea_memt; 121 122 esc->sc_ec = ea->ea_ec; 123 124 sc->sc_intr_establish = depca_eisa_intr_establish; 125 126 if (eisa_conf_read_mem(ea->ea_ec, ea->ea_slot, 127 DEPCA_ECU_FUNC_NETBUF, 0, &ecm) != 0) { 128 aprint_error_dev(self, "unable to find network buffer\n"); 129 return; 130 } 131 132 aprint_normal_dev(self, "shared memory at 0x%lx-0x%lx\n", 133 ecm.ecm_addr, ecm.ecm_addr + ecm.ecm_size - 1); 134 135 sc->sc_memsize = ecm.ecm_size; 136 137 if (bus_space_map(sc->sc_iot, EISA_SLOT_ADDR(ea->ea_slot) + 0xc00, 16, 138 0, &sc->sc_ioh) != 0) { 139 aprint_error_dev(self, "unable to map i/o space\n"); 140 return; 141 } 142 if (bus_space_map(sc->sc_memt, ecm.ecm_addr, sc->sc_memsize, 143 0, &sc->sc_memh) != 0) { 144 aprint_error_dev(self, "unable to map memory space\n"); 145 return; 146 } 147 148 if (eisa_conf_read_irq(ea->ea_ec, ea->ea_slot, 149 DEPCA_ECU_FUNC_NETINTR, 0, &eci) != 0) { 150 aprint_error_dev(self, "unable to determine IRQ\n"); 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 160static void * 161depca_eisa_intr_establish(struct depca_softc *parent, struct lance_softc *child) 162{ 163 struct depca_eisa_softc *esc = (struct depca_eisa_softc *)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 aprint_error_dev(parent->sc_dev, 170 "unable to map interrupt (%d)\n", 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 aprint_error_dev(parent->sc_dev, 178 "unable to establish interrupt"); 179 if (intrstr != NULL) 180 aprint_error(" at %s", intrstr); 181 aprint_error("\n"); 182 return (NULL); 183 } 184 if (intrstr != NULL) 185 aprint_normal_dev(parent->sc_dev, "interrupting at %s\n", 186 intrstr); 187 188 return (rv); 189} 190