1 /* $OpenBSD: if_ep_eisa.c,v 1.14 2001/03/09 09:36:31 mickey Exp $ */ 2 /* $NetBSD: if_ep_eisa.c,v 1.13 1997/04/18 00:50:33 cgd Exp $ */ 3 4 /* 5 * Copyright (c) 1997 Jonathan Stone <jonathan@NetBSD.org> 6 * Copyright (c) 1994 Herb Peyerl <hpeyerl@beer.org> 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by Herb Peyerl. 20 * 4. The name of Herb Peyerl may not be used to endorse or promote products 21 * derived from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #include "bpfilter.h" 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/mbuf.h> 40 #include <sys/socket.h> 41 #include <sys/ioctl.h> 42 #include <sys/errno.h> 43 #include <sys/syslog.h> 44 #include <sys/select.h> 45 #include <sys/device.h> 46 47 #include <net/if.h> 48 #include <net/if_dl.h> 49 #include <net/if_types.h> 50 #include <net/netisr.h> 51 #include <net/if_media.h> 52 53 #ifdef INET 54 #include <netinet/in.h> 55 #include <netinet/in_systm.h> 56 #include <netinet/in_var.h> 57 #include <netinet/ip.h> 58 #include <netinet/if_ether.h> 59 #endif 60 61 #if NBPFILTER > 0 62 #include <net/bpf.h> 63 #include <net/bpfdesc.h> 64 #endif 65 66 #include <machine/cpu.h> 67 #include <machine/bus.h> 68 #include <machine/intr.h> 69 70 #include <dev/mii/mii.h> 71 #include <dev/mii/miivar.h> 72 73 #include <dev/ic/elink3var.h> 74 #include <dev/ic/elink3reg.h> 75 76 #include <dev/eisa/eisareg.h> 77 #include <dev/eisa/eisavar.h> 78 #include <dev/eisa/eisadevs.h> 79 80 int ep_eisa_match __P((struct device *, void *, void *)); 81 void ep_eisa_attach __P((struct device *, struct device *, void *)); 82 83 struct cfattach ep_eisa_ca = { 84 sizeof(struct ep_softc), ep_eisa_match, ep_eisa_attach 85 }; 86 87 /* XXX move these somewhere else */ 88 #define EISA_CONTROL 0x0c84 89 #define EISA_RESET 0x04 90 #define EISA_ERROR 0x02 91 #define EISA_ENABLE 0x01 92 93 int 94 ep_eisa_match(parent, match, aux) 95 struct device *parent; 96 void *match, *aux; 97 { 98 struct eisa_attach_args *ea = aux; 99 100 /* must match one of our known ID strings */ 101 if (strcmp(ea->ea_idstring, "TCM5090") && 102 strcmp(ea->ea_idstring, "TCM5091") && 103 strcmp(ea->ea_idstring, "TCM5092") && 104 strcmp(ea->ea_idstring, "TCM5093") && 105 strcmp(ea->ea_idstring, "TCM5094") && 106 strcmp(ea->ea_idstring, "TCM5095") && 107 strcmp(ea->ea_idstring, "TCM5920") && 108 strcmp(ea->ea_idstring, "TCM5970") && 109 strcmp(ea->ea_idstring, "TCM5971") && 110 strcmp(ea->ea_idstring, "TCM5972")) 111 return (0); 112 113 return (1); 114 } 115 116 void 117 ep_eisa_attach(parent, self, aux) 118 struct device *parent, *self; 119 void *aux; 120 { 121 struct ep_softc *sc = (void *)self; 122 struct eisa_attach_args *ea = aux; 123 bus_space_tag_t iot = ea->ea_iot; 124 bus_space_handle_t ioh; 125 u_int16_t k; 126 eisa_chipset_tag_t ec = ea->ea_ec; 127 eisa_intr_handle_t ih; 128 const char *model, *intrstr; 129 int chipset; 130 u_int irq; 131 132 /* Map i/o space. */ 133 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot), 134 EISA_SLOT_SIZE, 0, &ioh)) 135 panic("ep_eisa_attach: can't map i/o space"); 136 137 sc->bustype = EP_BUS_EISA; 138 sc->sc_ioh = ioh; 139 sc->sc_iot = iot; 140 141 /* Reset card. */ 142 bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE | EISA_RESET); 143 delay(10); 144 bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE); 145 /* Wait for reset? */ 146 delay(1000); 147 148 /* XXX What is this doing?! Reading the i/o address? */ 149 k = bus_space_read_2(iot, ioh, EP_W0_ADDRESS_CFG); 150 k = (k & 0x1f) * 0x10 + 0x200; 151 152 /* Read the IRQ from the card. */ 153 irq = bus_space_read_2(iot, ioh, EP_W0_RESOURCE_CFG) >> 12; 154 155 chipset = EP_CHIPSET_3C509; /* assume dumb chipset */ 156 if (strcmp(ea->ea_idstring, "TCM5090") == 0) 157 model = EISA_PRODUCT_TCM5090; 158 else if (strcmp(ea->ea_idstring, "TCM5091") == 0) 159 model = EISA_PRODUCT_TCM5091; 160 else if (strcmp(ea->ea_idstring, "TCM5092") == 0) 161 model = EISA_PRODUCT_TCM5092; 162 else if (strcmp(ea->ea_idstring, "TCM5093") == 0) 163 model = EISA_PRODUCT_TCM5093; 164 else if (strcmp(ea->ea_idstring, "TCM5094") == 0) 165 model = EISA_PRODUCT_TCM5094; 166 else if (strcmp(ea->ea_idstring, "TCM5095") == 0) 167 model = EISA_PRODUCT_TCM5095; 168 else if (strcmp(ea->ea_idstring, "TCM5920") == 0) { 169 model = EISA_PRODUCT_TCM5920; 170 chipset = EP_CHIPSET_VORTEX; 171 } 172 else if (strcmp(ea->ea_idstring, "TCM5970") == 0) { 173 model = EISA_PRODUCT_TCM5970; 174 chipset = EP_CHIPSET_VORTEX; 175 } 176 else if (strcmp(ea->ea_idstring, "TCM5971") == 0) { 177 model = EISA_PRODUCT_TCM5971; 178 chipset = EP_CHIPSET_VORTEX; 179 } 180 else if (strcmp(ea->ea_idstring, "TCM5972") == 0) { 181 model = EISA_PRODUCT_TCM5972; 182 chipset = EP_CHIPSET_VORTEX; 183 } 184 else 185 model = "unknown model!"; 186 printf(": %s", model); 187 188 if (eisa_intr_map(ec, irq, &ih)) { 189 printf("couldn't map interrupt (%u)\n", irq); 190 return; 191 } 192 intrstr = eisa_intr_string(ec, ih); 193 sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET, 194 epintr, sc, sc->sc_dev.dv_xname); 195 if (sc->sc_ih == NULL) { 196 printf("couldn't establish interrupt"); 197 if (intrstr != NULL) 198 printf(" at %s", intrstr); 199 printf("\n"); 200 return; 201 } 202 203 epconfig(sc, chipset, NULL); 204 205 if (intrstr != NULL) 206 printf(" %s\n", intrstr); 207 } 208