1 /* $NetBSD: if_we_mca.c,v 1.4 2001/04/23 06:10:09 jdolecek Exp $ */ 2 3 /*- 4 * Copyright (c) 1997, 1998, 2001 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, and Jaromir Dolecek. 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 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40 /* 41 * Device driver for National Semiconductor DS8390/WD83C690 based ethernet 42 * adapters. 43 * 44 * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. 45 * 46 * Copyright (C) 1993, David Greenman. This software may be used, modified, 47 * copied, distributed, and sold, in both source and binary form provided that 48 * the above copyright and these terms are retained. Under no circumstances is 49 * the author responsible for the proper functioning of this software, nor does 50 * the author assume any responsibility for damages incurred with its use. 51 */ 52 53 /* 54 * Device driver for the Western Digital/SMC 8003 and 8013 series, 55 * and the SMC Elite Ultra (8216). 56 * 57 * Currently only tested with WD8003W/A. Other WD8003-based cards 58 * should work without problems, the SMC Elite based ones hopefully too. 59 */ 60 61 #include <sys/param.h> 62 #include <sys/systm.h> 63 #include <sys/device.h> 64 #include <sys/socket.h> 65 #include <sys/mbuf.h> 66 67 #include <net/if.h> 68 #include <net/if_types.h> 69 #include <net/if_media.h> 70 #include <net/if_ether.h> 71 72 #include <machine/bus.h> 73 74 #include <dev/mca/mcareg.h> 75 #include <dev/mca/mcavar.h> 76 #include <dev/mca/mcadevs.h> 77 78 #include <dev/ic/dp8390reg.h> 79 #include <dev/ic/dp8390var.h> 80 #include <dev/ic/wereg.h> 81 #include <dev/ic/wevar.h> 82 83 #define WD_8003 0x01 84 #define WD_ELITE 0x02 85 #define WD_MEMSIZE 16384 /* all supported cards have 16K Bytes memory */ 86 87 int we_mca_probe __P((struct device *, struct cfdata *, void *)); 88 void we_mca_attach __P((struct device *, struct device *, void *)); 89 void we_mca_init_hook __P((struct we_softc *)); 90 91 struct cfattach we_mca_ca = { 92 sizeof(struct we_softc), we_mca_probe, we_mca_attach 93 }; 94 95 /* 96 * The types for some cards may not be correct; hopefully it's close 97 * enough. 98 */ 99 static const struct we_mca_product { 100 u_int32_t we_id; 101 const char *we_name; 102 int we_flag; 103 int we_type; 104 const char *we_typestr; 105 } we_mca_products[] = { 106 { MCA_PRODUCT_WD_8013EP, "EtherCard PLUS Elite/A (8013EP/A)", 107 WD_ELITE, WE_TYPE_WD8013EP, "WD8013EP/A" }, 108 { MCA_PRODUCT_WD_8013WP, "EtherCard PLUS Elite 10T/A (8013WP/A)", 109 WD_ELITE, WE_TYPE_WD8013EP, "WD8013WP/A" }, /* XXX */ 110 { MCA_PRODUCT_IBM_WD_2,"IBM PS/2 Adapter/A for Ethernet Networks (UTP)", 111 WD_ELITE, WE_TYPE_WD8013EP, "WD8013WP/A"}, /* XXX */ 112 { MCA_PRODUCT_IBM_WD_T,"IBM PS/2 Adapter/A for Ethernet Networks (BNC)", 113 WD_ELITE, WE_TYPE_WD8013EP, "WD8013WP/A"}, /* XXX */ 114 { MCA_PRODUCT_WD_8003E, "WD EtherCard PLUS/A (WD8003E/A or WD8003ET/A)", 115 WD_8003, WE_TYPE_WD8003E, "WD8003E/A or WD8003ET/A" }, 116 { MCA_PRODUCT_WD_8003ST,"WD StarCard PLUS/A (WD8003ST/A)", 117 WD_8003, WE_TYPE_WD8003W, "WD8003ST/A" }, /* XXX */ 118 { MCA_PRODUCT_WD_8003W, "WD EtherCard PLUS 10T/A (WD8003W/A)", 119 WD_8003, WE_TYPE_WD8003W, "WD8003W/A" }, 120 { MCA_PRODUCT_IBM_WD_O, "IBM PS/2 Adapter/A for Ethernet Networks", 121 WD_8003, WE_TYPE_WD8003W, "IBM PS/2 Adapter/A" },/*XXX*/ 122 { 0x0000, NULL }, 123 }; 124 125 /* see POS description in we_mca_attach() */ 126 static const int we_mca_irq[] = { 127 3, 4, 10, 15, 128 }; 129 130 /* memory position and shared RAM sizes for WD8013-type of cards */ 131 static const struct { 132 u_int8_t id; 133 int maddr; 134 int memsize; 135 } we_mca_elite_mem[] = { 136 { 0x10, 0x0C0000, 16384 }, 137 { 0x12, 0x0C4000, 16384 }, 138 { 0x14, 0x0C8000, 16384 }, 139 { 0x16, 0x0CC000, 16384 }, 140 { 0x18, 0x0D0000, 16384 }, 141 { 0x1A, 0x0D4000, 16384 }, 142 { 0x1C, 0x0D8000, 16384 }, 143 { 0x1E, 0x0DC000, 16384 }, 144 { 0x90, 0xFC0000, 16384 }, 145 { 0x94, 0xFC8000, 16384 }, 146 { 0x98, 0xFD0000, 16384 }, 147 { 0x9C, 0x0C0000, 16384 }, 148 { 0x00, 0x0C0000, 8192 }, 149 { 0x01, 0x0C2000, 8192 }, 150 { 0x10, 0x0C4000, 8192 }, 151 { 0x11, 0x0C6000, 8192 }, 152 { 0x00, 0x000000, 0 }, 153 }; 154 155 156 static const struct we_mca_product *we_mca_lookup __P((int)); 157 158 static const struct we_mca_product * 159 we_mca_lookup(id) 160 int id; 161 { 162 const struct we_mca_product *wep; 163 164 for(wep = we_mca_products; wep->we_name; wep++) 165 if (wep->we_id == id) 166 return (wep); 167 168 return (NULL); 169 } 170 171 int 172 we_mca_probe(parent, cf, aux) 173 struct device *parent; 174 struct cfdata *cf; 175 void *aux; 176 { 177 struct mca_attach_args *ma = aux; 178 179 return (we_mca_lookup(ma->ma_id) != NULL); 180 } 181 182 void 183 we_mca_attach(parent, self, aux) 184 struct device *parent, *self; 185 void *aux; 186 { 187 struct we_softc *wsc = (struct we_softc *)self; 188 struct dp8390_softc *sc = &wsc->sc_dp8390; 189 struct mca_attach_args *ma = aux; 190 const struct we_mca_product *wep; 191 bus_space_tag_t nict, asict, memt; 192 bus_space_handle_t nich, asich, memh; 193 const char *typestr; 194 int irq, iobase, maddr; 195 int pos2, pos3, pos5; 196 197 pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2); 198 pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3); 199 pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5); 200 201 /* 202 * POS registers differ much between 8003 and 8013, so they are 203 * divided to two sections. 204 * 205 * 8003: POS register 2: (adf pos0) 206 * 7 6 5 4 3 2 1 0 207 * 0 0 1 \___/ \__ enable: 0=adapter disabled, 1=adapter enabled 208 * \_____ Adapter IO Space: 0x200-0x29F + XX*0x20 209 * 210 * 8003: POS register 3: (adf pos1) 211 * 7 6 5 4 3 2 1 0 212 * 1 1 0 \__/ 1 X 213 * \______ Shared Ram Space (16K Bytes): 214 * 0xC0000-0xC3FFF + XX * 0x4000 215 * 216 * 8003: POS register 5: (adf pos3) 217 * 7 6 5 4 3 2 1 0 218 * \_/ 219 * \__ Interrupt Level: 00=3 01=4 10=10 11=15 220 * 221 * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 222 * 223 * 8013: POS register 2: (adf pos0) 224 * 7 6 5 4 3 2 1 0 225 * \____/ \__ enable: 0=adapter disabled, 1=adapter enabled 226 * \___________ Adapter I/O Space: 0x0800-0x081F + XX * 0x1000 227 * 228 * 8013: POS register 3: (adf pos1) 229 * 7 6 5 4 3 2 1 0 230 * X 0 Shared Ram Base Address - mask 0x9f 231 * see wd_elite_mem[] array for details 232 * 233 * 8013: POS register 5: (adf pos3) 234 * 7 6 5 4 3 2 1 0 235 * \_/ \_/ 236 * \ \__ Media Select: 00=TwPr (no link) 10=BNC 237 * \ 01=AUI|AUI or 10BaseT 238 * \____ Interrupt Level: 00=3 01=4 10=10 11=14 239 */ 240 241 wep = we_mca_lookup(ma->ma_id); 242 #ifdef DIAGNOSTIC 243 if (wep == NULL) { 244 printf("\n%s: where did the card go?\n", sc->sc_dev.dv_xname); 245 return; 246 } 247 #endif 248 249 if (wep->we_flag & WD_8003) { 250 /* WD8003 based */ 251 iobase = 0x200 + (((pos2 & 0x0e) >> 1) * 0x020); 252 maddr = 0xC0000 + (((pos3 & 0x1c) >> 2) * 0x04000); 253 irq = we_mca_irq[(pos5 & 0x03)]; 254 sc->mem_size = WD_MEMSIZE; 255 } else { 256 /* SMC Elite */ 257 int i, id; 258 259 iobase = 0x800 + (((pos2 & 0xf0) >> 4) * 0x1000); 260 irq = we_mca_irq[(pos5 & 0x06) >> 2]; 261 262 /* find location of shared mem and it's size */ 263 id = (pos3 & 0x9f); 264 for(i=0; we_mca_elite_mem[i].maddr; i++) 265 if (we_mca_elite_mem[i].id == id) 266 break; 267 if (we_mca_elite_mem[i].maddr == 0) { 268 printf("\n%s: cannot find Shared Ram Base Address\n", 269 sc->sc_dev.dv_xname); 270 return; 271 } 272 273 maddr = we_mca_elite_mem[i].maddr; 274 sc->mem_size = we_mca_elite_mem[i].memsize; 275 } 276 277 nict = asict = ma->ma_iot; 278 memt = ma->ma_memt; 279 280 printf(" slot %d irq %d: %s\n", ma->ma_slot + 1, irq, wep->we_name); 281 282 /* Map the device. */ 283 if (bus_space_map(asict, iobase, WE_NPORTS, 0, &asich)) { 284 printf("%s: can't map nic i/o space\n", 285 sc->sc_dev.dv_xname); 286 return; 287 } 288 289 if (bus_space_subregion(asict, asich, WE_NIC_OFFSET, WE_NIC_NPORTS, 290 &nich)) { 291 printf("%s: can't subregion i/o space\n", 292 sc->sc_dev.dv_xname); 293 return; 294 } 295 296 wsc->sc_type = wep->we_type; 297 wsc->sc_16bitp = 1; /* all cards we support are 16bit */ 298 sc->is790 = 0; 299 typestr = wep->we_typestr; 300 301 /* 302 * Map memory space. 303 */ 304 if (bus_space_map(memt, maddr, sc->mem_size, 0, &memh)) { 305 printf("%s: can't map shared memory\n", 306 sc->sc_dev.dv_xname); 307 return; 308 } 309 310 wsc->sc_asict = asict; 311 wsc->sc_asich = asich; 312 313 sc->sc_regt = nict; 314 sc->sc_regh = nich; 315 316 sc->sc_buft = memt; 317 sc->sc_bufh = memh; 318 319 wsc->sc_maddr = maddr; 320 321 /* Interface is always enabled. */ 322 sc->sc_enabled = 1; 323 324 wsc->sc_init_hook = we_mca_init_hook; 325 326 if (we_config(self, wsc, typestr)) 327 return; 328 329 /* Map and establish the interrupt. */ 330 wsc->sc_ih = mca_intr_establish(ma->ma_mc, irq, 331 IPL_NET, dp8390_intr, sc); 332 if (wsc->sc_ih == NULL) { 333 printf("%s: can't establish interrupt\n", sc->sc_dev.dv_xname); 334 return; 335 } 336 } 337 338 void 339 we_mca_init_hook(wsc) 340 struct we_softc *wsc; 341 { 342 /* 343 * This quirk really needs to be here, at least for WD8003W/A. Without 344 * this, the card doesn't send any interrupts in 16bit mode. The quirk 345 * was taken from Linux smc-mca.c driver. 346 * I do not know why it's necessary. I don't want to know. It works 347 * and that is enough for me. 348 */ 349 bus_space_write_1(wsc->sc_asict, wsc->sc_asich, WE_LAAR, 0x04); 350 wsc->sc_laar_proto |= 0x04; 351 } 352