1 /* $NetBSD: if_ep_eisa.c,v 1.39 2008/08/27 05:33:47 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 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 /* 34 * Copyright (c) 1997 Jonathan Stone <jonathan@NetBSD.org> 35 * Copyright (c) 1994 Herb Peyerl <hpeyerl@beer.org> 36 * All rights reserved. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 1. Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * 2. Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in the 45 * documentation and/or other materials provided with the distribution. 46 * 3. All advertising materials mentioning features or use of this software 47 * must display the following acknowledgement: 48 * This product includes software developed by Herb Peyerl. 49 * This product includes software developed by Jonathan Stone. 50 * 4. The name of Herb Peyerl or Jonathan Stone may not be used to endorse 51 * or promote products derived from this software without specific 52 * prior written permission. 53 * 54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 56 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 57 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 58 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 59 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 63 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 64 */ 65 66 #include <sys/cdefs.h> 67 __KERNEL_RCSID(0, "$NetBSD: if_ep_eisa.c,v 1.39 2008/08/27 05:33:47 christos Exp $"); 68 69 #include "opt_inet.h" 70 #include "bpfilter.h" 71 72 #include <sys/param.h> 73 #include <sys/systm.h> 74 #include <sys/mbuf.h> 75 #include <sys/socket.h> 76 #include <sys/ioctl.h> 77 #include <sys/errno.h> 78 #include <sys/syslog.h> 79 #include <sys/select.h> 80 #include <sys/device.h> 81 82 #include <net/if.h> 83 #include <net/if_dl.h> 84 #include <net/if_ether.h> 85 #include <net/if_media.h> 86 87 #ifdef INET 88 #include <netinet/in.h> 89 #include <netinet/in_systm.h> 90 #include <netinet/in_var.h> 91 #include <netinet/ip.h> 92 #include <netinet/if_inarp.h> 93 #endif 94 95 96 #if NBPFILTER > 0 97 #include <net/bpf.h> 98 #include <net/bpfdesc.h> 99 #endif 100 101 #include <sys/cpu.h> 102 #include <sys/bus.h> 103 #include <sys/intr.h> 104 105 #include <dev/mii/miivar.h> 106 107 #include <dev/ic/elink3var.h> 108 #include <dev/ic/elink3reg.h> 109 110 #include <dev/eisa/eisareg.h> 111 #include <dev/eisa/eisavar.h> 112 #include <dev/eisa/eisadevs.h> 113 114 static int ep_eisa_match(device_t , cfdata_t , void *); 115 static void ep_eisa_attach(device_t , device_t , void *); 116 117 CFATTACH_DECL_NEW(ep_eisa, sizeof(struct ep_softc), 118 ep_eisa_match, ep_eisa_attach, NULL, NULL); 119 120 /* XXX move these somewhere else */ 121 /* While attaching we need a few special EISA registers of the card, 122 these are mapped at slotbase+EP_EISA_CFG_BASE with len EP_EISA_CFG_SIZE */ 123 #define EP_EISA_CFG_BASE 0x0c80 124 #define EP_EISA_CFG_CONTROL 0x0004 /* 1 byte */ 125 #define EP_EISA_CFG_RESOURCE 0x0008 /* 2 byte */ 126 #define EP_EISA_CFG_SIZE 0x000a 127 128 /* The generic driver backend only needs access to the standard ports, 129 mapped at the beginning of the eisa slot space */ 130 #define EP_IOPORT_OFFSET 0x0000 131 #define EP_IOPORT_SIZE 0x0020 132 133 /* Bits for the eisa control register */ 134 #define EISA_RESET 0x04 135 #define EISA_ERROR 0x02 136 #define EISA_ENABLE 0x01 137 138 static const struct ep_eisa_product { 139 const char *eep_eisaid; /* EISA ID */ 140 u_short eep_chipset; /* 3Com chipset used */ 141 int eep_flags; /* initial softc flags */ 142 const char *eep_name; /* device name */ 143 } ep_eisa_products[] = { 144 { "TCM5091", ELINK_CHIPSET_3C509, 145 0, EISA_PRODUCT_TCM5091 }, 146 147 { "TCM5092", ELINK_CHIPSET_3C509, 148 0, EISA_PRODUCT_TCM5092 }, 149 { "TCM5093", ELINK_CHIPSET_3C509, 150 0, EISA_PRODUCT_TCM5093 }, 151 { "TCM5094", ELINK_CHIPSET_3C509, 152 0, EISA_PRODUCT_TCM5094 }, 153 { "TCM5095", ELINK_CHIPSET_3C509, 154 0, EISA_PRODUCT_TCM5095 }, 155 { "TCM5098", ELINK_CHIPSET_3C509, 156 0, EISA_PRODUCT_TCM5098 }, 157 158 /* 159 * Note: The 3c597 Fast Etherlink MII (TCM5972) is an 160 * MII connector for an external PHY. We treat it as 161 * `manual' in the core driver. 162 */ 163 { "TCM5920", ELINK_CHIPSET_VORTEX, 164 0, EISA_PRODUCT_TCM5920 }, 165 { "TCM5970", ELINK_CHIPSET_VORTEX, 166 0, EISA_PRODUCT_TCM5970 }, 167 { "TCM5971", ELINK_CHIPSET_VORTEX, 168 0, EISA_PRODUCT_TCM5971 }, 169 { "TCM5972", ELINK_CHIPSET_VORTEX, 170 0, EISA_PRODUCT_TCM5972 }, 171 172 { NULL, 0, 173 0, NULL }, 174 }; 175 176 static const struct ep_eisa_product * 177 ep_eisa_lookup(const struct eisa_attach_args *ea) 178 { 179 const struct ep_eisa_product *eep; 180 181 for (eep = ep_eisa_products; eep->eep_name != NULL; eep++) 182 if (strcmp(ea->ea_idstring, eep->eep_eisaid) == 0) 183 return (eep); 184 185 return (NULL); 186 } 187 188 static int 189 ep_eisa_match(device_t parent, cfdata_t match, void *aux) 190 { 191 struct eisa_attach_args *ea = aux; 192 193 /* must match one of our known ID strings */ 194 if (ep_eisa_lookup(ea) != NULL) 195 return (1); 196 197 return (0); 198 } 199 200 static void 201 ep_eisa_attach(device_t parent, device_t self, void *aux) 202 { 203 struct ep_softc *sc = device_private(self); 204 struct eisa_attach_args *ea = aux; 205 bus_space_tag_t iot = ea->ea_iot; 206 bus_space_handle_t ioh, ioh_cfg; 207 eisa_chipset_tag_t ec = ea->ea_ec; 208 eisa_intr_handle_t ih; 209 const char *intrstr; 210 const struct ep_eisa_product *eep; 211 u_int irq; 212 213 /* Map i/o space. */ 214 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + EP_EISA_CFG_BASE, 215 EP_EISA_CFG_SIZE, 0, &ioh_cfg)) { 216 printf("\n"); 217 panic("ep_eisa_attach: can't map eisa cfg i/o space"); 218 } 219 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + EP_IOPORT_OFFSET, 220 EP_IOPORT_SIZE, 0, &ioh)) { 221 printf("\n"); 222 panic("ep_eisa_attach: can't map i/o space"); 223 } 224 225 sc->sc_dev = self; 226 sc->sc_ioh = ioh; 227 sc->sc_iot = iot; 228 229 bus_space_write_1(iot, ioh_cfg, EP_EISA_CFG_CONTROL, EISA_ENABLE); 230 delay(4000); 231 232 /* Read the IRQ from the card. */ 233 irq = bus_space_read_2(iot, ioh_cfg, EP_EISA_CFG_RESOURCE) >> 12; 234 235 eep = ep_eisa_lookup(ea); 236 if (eep == NULL) { 237 printf("\n"); 238 panic("ep_eisa_attach: impossible"); 239 } 240 241 /* we don't need access to the config registers any more, but 242 noone else should be able to map this space, so keep it 243 reserved? */ 244 #if 0 245 bus_space_unmap(iot, ioh_cfg, EP_EISA_CFG_SIZE); 246 #endif 247 248 printf(": %s\n", eep->eep_name); 249 250 sc->enable = NULL; 251 sc->disable = NULL; 252 sc->enabled = 1; 253 254 sc->bustype = ELINK_BUS_EISA; 255 sc->ep_flags = eep->eep_flags; 256 257 if (eisa_intr_map(ec, irq, &ih)) { 258 aprint_error_dev(sc->sc_dev, "couldn't map interrupt (%u)\n", 259 irq); 260 return; 261 } 262 intrstr = eisa_intr_string(ec, ih); 263 sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET, 264 epintr, sc); 265 if (sc->sc_ih == NULL) { 266 aprint_error_dev(sc->sc_dev, "couldn't establish interrupt"); 267 if (intrstr != NULL) 268 printf(" at %s", intrstr); 269 printf("\n"); 270 return; 271 } 272 if (intrstr != NULL) 273 printf("%s: interrupting at %s\n", device_xname(sc->sc_dev), 274 intrstr); 275 276 epconfig(sc, eep->eep_chipset, NULL); 277 } 278