1 /* $NetBSD: if_ne_isa.c,v 1.27 2010/03/03 13:39:57 tsutsui Exp $ */ 2 3 /*- 4 * Copyright (c) 1997, 1998 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 of the Numerical Aerospace Simulation Facility, 9 * NASA Ames Research Center. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <sys/cdefs.h> 34 __KERNEL_RCSID(0, "$NetBSD: if_ne_isa.c,v 1.27 2010/03/03 13:39:57 tsutsui Exp $"); 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/mbuf.h> 39 #include <sys/socket.h> 40 #include <sys/ioctl.h> 41 #include <sys/errno.h> 42 #include <sys/syslog.h> 43 #include <sys/select.h> 44 #include <sys/device.h> 45 46 #include <net/if.h> 47 #include <net/if_dl.h> 48 #include <net/if_ether.h> 49 #include <net/if_media.h> 50 51 #include <sys/intr.h> 52 #include <sys/bus.h> 53 54 #include <dev/ic/dp8390reg.h> 55 #include <dev/ic/dp8390var.h> 56 57 #include <dev/ic/ne2000reg.h> 58 #include <dev/ic/ne2000var.h> 59 60 #include <dev/isa/isavar.h> 61 62 int ne_isa_match(device_t, cfdata_t, void *); 63 void ne_isa_attach(device_t, device_t, void *); 64 65 struct ne_isa_softc { 66 struct ne2000_softc sc_ne2000; /* real "ne2000" softc */ 67 68 /* ISA-specific goo. */ 69 void *sc_ih; /* interrupt cookie */ 70 }; 71 72 CFATTACH_DECL_NEW(ne_isa, sizeof(struct ne_isa_softc), 73 ne_isa_match, ne_isa_attach, NULL, NULL); 74 75 int 76 ne_isa_match(device_t parent, cfdata_t match, void *aux) 77 { 78 struct isa_attach_args *ia = aux; 79 bus_space_tag_t nict = ia->ia_iot; 80 bus_space_handle_t nich; 81 bus_space_tag_t asict; 82 bus_space_handle_t asich; 83 int rv = 0; 84 85 if (ia->ia_nio < 1) 86 return (0); 87 if (ia->ia_nirq < 1) 88 return (0); 89 90 if (ISA_DIRECT_CONFIG(ia)) 91 return (0); 92 93 /* Disallow wildcarded values. */ 94 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT) 95 return (0); 96 if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) 97 return (0); 98 99 /* Make sure this is a valid NE[12]000 i/o address. */ 100 if ((ia->ia_io[0].ir_addr & 0x1f) != 0) 101 return (0); 102 103 /* Map i/o space. */ 104 if (bus_space_map(nict, ia->ia_io[0].ir_addr, NE2000_NPORTS, 0, &nich)) 105 return (0); 106 107 asict = nict; 108 if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET, 109 NE2000_ASIC_NPORTS, &asich)) 110 goto out; 111 112 /* Look for an NE2000-compatible card. */ 113 rv = ne2000_detect(nict, nich, asict, asich); 114 115 if (rv) { 116 ia->ia_nio = 1; 117 ia->ia_io[0].ir_size = NE2000_NPORTS; 118 119 ia->ia_nirq = 1; 120 121 ia->ia_niomem = 0; 122 ia->ia_ndrq = 0; 123 } 124 125 out: 126 bus_space_unmap(nict, nich, NE2000_NPORTS); 127 return (rv); 128 } 129 130 void 131 ne_isa_attach(device_t parent, device_t self, void *aux) 132 { 133 struct ne_isa_softc *isc = device_private(self); 134 struct ne2000_softc *nsc = &isc->sc_ne2000; 135 struct dp8390_softc *dsc = &nsc->sc_dp8390; 136 struct isa_attach_args *ia = aux; 137 bus_space_tag_t nict = ia->ia_iot; 138 bus_space_handle_t nich; 139 bus_space_tag_t asict = nict; 140 bus_space_handle_t asich; 141 const char *typestr; 142 int netype; 143 144 dsc->sc_dev = self; 145 aprint_normal("\n"); 146 147 /* Map i/o space. */ 148 if (bus_space_map(nict, ia->ia_io[0].ir_addr, NE2000_NPORTS, 149 0, &nich)) { 150 aprint_error_dev(self, "can't map i/o space\n"); 151 return; 152 } 153 154 if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET, 155 NE2000_ASIC_NPORTS, &asich)) { 156 aprint_error_dev(self, "can't subregion i/o space\n"); 157 return; 158 } 159 160 dsc->sc_regt = nict; 161 dsc->sc_regh = nich; 162 163 nsc->sc_asict = asict; 164 nsc->sc_asich = asich; 165 166 /* 167 * Detect it again, so we can print some information about the 168 * interface. 169 */ 170 netype = ne2000_detect(nict, nich, asict, asich); 171 switch (netype) { 172 case NE2000_TYPE_NE1000: 173 typestr = "NE1000"; 174 break; 175 176 case NE2000_TYPE_NE2000: 177 typestr = "NE2000"; 178 break; 179 180 case NE2000_TYPE_RTL8019: 181 typestr = "NE2000 (RTL8019)"; 182 break; 183 184 default: 185 aprint_error_dev(self, "where did the card go?!\n"); 186 return; 187 } 188 189 aprint_normal_dev(self, "%s Ethernet\n", typestr); 190 191 /* This interface is always enabled. */ 192 dsc->sc_enabled = 1; 193 194 /* 195 * Do generic NE2000 attach. This will read the station address 196 * from the EEPROM. 197 */ 198 ne2000_attach(nsc, NULL); 199 200 /* Establish the interrupt handler. */ 201 isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, 202 IST_EDGE, IPL_NET, dp8390_intr, dsc); 203 if (isc->sc_ih == NULL) 204 aprint_error_dev(self, 205 "couldn't establish interrupt handler\n"); 206 } 207