1 /* $NetBSD: if_ne_pcmcia.c,v 1.87 2002/01/31 08:45:14 haya Exp $ */ 2 3 /* 4 * Copyright (c) 1997 Marc Horowitz. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Marc Horowitz. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: if_ne_pcmcia.c,v 1.87 2002/01/31 08:45:14 haya Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/select.h> 38 #include <sys/device.h> 39 #include <sys/socket.h> 40 41 #include <net/if_types.h> 42 #include <net/if.h> 43 #include <net/if_media.h> 44 #include <net/if_ether.h> 45 46 #include <machine/bus.h> 47 #include <machine/intr.h> 48 49 #include <dev/pcmcia/pcmciareg.h> 50 #include <dev/pcmcia/pcmciavar.h> 51 #include <dev/pcmcia/pcmciadevs.h> 52 53 #include <dev/ic/dp8390reg.h> 54 #include <dev/ic/dp8390var.h> 55 56 #include <dev/ic/ne2000reg.h> 57 #include <dev/ic/ne2000var.h> 58 59 #include <dev/ic/rtl80x9reg.h> 60 #include <dev/ic/rtl80x9var.h> 61 62 #include <dev/ic/dl10019var.h> 63 64 #include <dev/ic/ax88190reg.h> 65 #include <dev/ic/ax88190var.h> 66 67 int ne_pcmcia_match __P((struct device *, struct cfdata *, void *)); 68 void ne_pcmcia_attach __P((struct device *, struct device *, void *)); 69 int ne_pcmcia_detach __P((struct device *, int)); 70 71 int ne_pcmcia_enable __P((struct dp8390_softc *)); 72 void ne_pcmcia_disable __P((struct dp8390_softc *)); 73 74 struct ne_pcmcia_softc { 75 struct ne2000_softc sc_ne2000; /* real "ne2000" softc */ 76 77 /* PCMCIA-specific goo */ 78 struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o information */ 79 int sc_asic_io_window; /* i/o window for ASIC */ 80 int sc_nic_io_window; /* i/o window for NIC */ 81 struct pcmcia_function *sc_pf; /* our PCMCIA function */ 82 void *sc_ih; /* interrupt handle */ 83 }; 84 85 u_int8_t * 86 ne_pcmcia_get_enaddr __P((struct ne_pcmcia_softc *, int, 87 u_int8_t [ETHER_ADDR_LEN])); 88 u_int8_t * 89 ne_pcmcia_dl10019_get_enaddr __P((struct ne_pcmcia_softc *, 90 u_int8_t [ETHER_ADDR_LEN])); 91 int ne_pcmcia_ax88190_set_iobase __P((struct ne_pcmcia_softc *)); 92 93 struct cfattach ne_pcmcia_ca = { 94 sizeof(struct ne_pcmcia_softc), ne_pcmcia_match, ne_pcmcia_attach, 95 ne_pcmcia_detach, dp8390_activate 96 }; 97 98 static const struct ne2000dev { 99 char *name; 100 int32_t manufacturer; 101 int32_t product; 102 char *cis_info[4]; 103 int function; 104 int enet_maddr; 105 unsigned char enet_vendor[3]; 106 int flags; 107 #define NE2000DVF_DL10019 0x0001 /* chip is D-Link DL10019 */ 108 #define NE2000DVF_AX88190 0x0002 /* chip is ASIX AX88190 */ 109 } ne2000devs[] = { 110 { PCMCIA_STR_EDIMAX_EP4000A, 111 PCMCIA_VENDOR_EDIMAX, PCMCIA_PRODUCT_EDIMAX_EP4000A, 112 PCMCIA_CIS_EDIMAX_EP4000A, 113 0, -1, { 0x00, 0xa0, 0x0c } }, 114 115 { PCMCIA_STR_SYNERGY21_S21810, 116 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 117 PCMCIA_CIS_SYNERGY21_S21810, 118 0, -1, { 0x00, 0x48, 0x54 } }, 119 120 { PCMCIA_STR_AMBICOM_AMB8002T, 121 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 122 PCMCIA_CIS_AMBICOM_AMB8002T, 123 0, -1, { 0x00, 0x10, 0x7a } }, 124 125 { PCMCIA_STR_PREMAX_PE200, 126 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 127 PCMCIA_CIS_PREMAX_PE200, 128 0, 0x07f0, { 0x00, 0x20, 0xe0 } }, 129 130 { PCMCIA_STR_DIGITAL_DEPCMXX, 131 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 132 PCMCIA_CIS_DIGITAL_DEPCMXX, 133 0, 0x0ff0, { 0x00, 0x00, 0xe8 } }, 134 135 { PCMCIA_STR_PLANET_SMARTCOM2000, 136 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 137 PCMCIA_CIS_PLANET_SMARTCOM2000, 138 0, 0xff0, { 0x00, 0x00, 0xe8 } }, 139 140 { PCMCIA_STR_DLINK_DE660, 141 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 142 PCMCIA_CIS_DLINK_DE660, 143 0, -1, { 0x00, 0x80, 0xc8 } }, 144 145 { PCMCIA_STR_DLINK_DE660PLUS, 146 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 147 PCMCIA_CIS_DLINK_DE660PLUS, 148 0, -1, { 0x00, 0x80, 0xc8 } }, 149 150 { PCMCIA_STR_RPTI_EP400, 151 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 152 PCMCIA_CIS_RPTI_EP400, 153 0, -1, { 0x00, 0x40, 0x95 } }, 154 155 { PCMCIA_STR_RPTI_EP401, 156 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 157 PCMCIA_CIS_RPTI_EP401, 158 0, -1, { 0x00, 0x40, 0x95 } }, 159 160 { PCMCIA_STR_ACCTON_EN2212, 161 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 162 PCMCIA_CIS_ACCTON_EN2212, 163 0, 0x0ff0, { 0x00, 0x00, 0xe8 } }, 164 165 { PCMCIA_STR_SVEC_COMBOCARD, 166 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 167 PCMCIA_CIS_SVEC_COMBOCARD, 168 0, -1, { 0x00, 0xe0, 0x98 } }, 169 170 { PCMCIA_STR_SVEC_LANCARD, 171 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 172 PCMCIA_CIS_SVEC_LANCARD, 173 0, 0x7f0, { 0x00, 0xc0, 0x6c } }, 174 175 { PCMCIA_STR_EPSON_EEN10B, 176 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_EPSON_EEN10B, 177 PCMCIA_CIS_EPSON_EEN10B, 178 0, 0xff0, { 0x00, 0x00, 0x48 } }, 179 180 { PCMCIA_STR_CNET_NE2000, 181 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 182 PCMCIA_CIS_CNET_NE2000, 183 0, -1, { 0x00, 0x80, 0xad } }, 184 185 { PCMCIA_STR_ZONET_ZEN, 186 PCMCIA_VENDOR_ZONET, PCMCIA_PRODUCT_ZONET_ZEN, 187 PCMCIA_CIS_ZONET_ZEN, 188 0, -1, { 0x00, 0x00, 0x00 } }, 189 190 /* 191 * You have to add new entries which contains 192 * PCMCIA_VENDOR_INVALID and/or PCMCIA_PRODUCT_INVALID 193 * in front of this comment. 194 * 195 * There are cards which use a generic vendor and product id but needs 196 * a different handling depending on the cis_info, so ne2000_match 197 * needs a table where the exceptions comes first and then the normal 198 * product and vendor entries. 199 */ 200 201 { PCMCIA_STR_IBM_INFOMOVER, 202 PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER, 203 PCMCIA_CIS_IBM_INFOMOVER, 204 0, 0x0ff0, { 0x08, 0x00, 0x5a } }, 205 206 { PCMCIA_STR_IBM_INFOMOVER, 207 PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER, 208 PCMCIA_CIS_IBM_INFOMOVER, 209 0, 0x0ff0, { 0x00, 0x04, 0xac } }, 210 211 { PCMCIA_STR_IBM_INFOMOVER, 212 PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER, 213 PCMCIA_CIS_IBM_INFOMOVER, 214 0, 0x0ff0, { 0x00, 0x06, 0x29 } }, 215 216 /* NEC 9801N_J12 */ 217 { PCMCIA_STR_IBM_INFOMOVER, 218 PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER, 219 PCMCIA_CIS_IBM_INFOMOVER, 220 0, 0x0ff0, { 0x00, 0x00, 0x4c } }, 221 222 { PCMCIA_STR_LINKSYS_ECARD_1, 223 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1, 224 PCMCIA_CIS_LINKSYS_ECARD_1, 225 0, -1, { 0x00, 0x80, 0xc8 } }, 226 227 { PCMCIA_STR_PLANEX_FNW3600T, 228 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD, 229 PCMCIA_CIS_PLANEX_FNW3600T, 230 0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_DL10019 }, 231 232 { PCMCIA_STR_SVEC_PN650TX, 233 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD, 234 PCMCIA_CIS_SVEC_PN650TX, 235 0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 }, 236 237 /* 238 * This entry should be here so that above two cards doesn't 239 * match with this. FNW-3700T won't match above entries due to 240 * MAC address check. 241 */ 242 { PCMCIA_STR_LANTECH_FASTNETTX, 243 PCMCIA_VENDOR_LANTECH, PCMCIA_PRODUCT_LANTECH_FASTNETTX, 244 PCMCIA_CIS_LANTECH_FASTNETTX, 245 0, -1, { 0x00, 0x04, 0x1c }, NE2000DVF_AX88190 }, 246 247 { PCMCIA_STR_PLANEX_FNW3700T, 248 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD, 249 PCMCIA_CIS_PLANEX_FNW3700T, 250 0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_AX88190 }, 251 252 { PCMCIA_STR_LINKSYS_ETHERFAST, 253 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST, 254 PCMCIA_CIS_LINKSYS_ETHERFAST, 255 0, -1, { 0x00, 0x80, 0xc8 }, NE2000DVF_DL10019 }, 256 257 { PCMCIA_STR_LINKSYS_ETHERFAST, 258 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST, 259 PCMCIA_CIS_LINKSYS_ETHERFAST, 260 0, -1, { 0x00, 0x40, 0x05 }, NE2000DVF_DL10019 }, 261 262 { PCMCIA_STR_LINKSYS_ETHERFAST, 263 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST, 264 PCMCIA_CIS_LINKSYS_ETHERFAST, 265 0, -1, { 0x00, 0x90, 0xfe }, NE2000DVF_DL10019 }, 266 267 { PCMCIA_STR_DLINK_DE650, 268 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST, 269 PCMCIA_CIS_DLINK_DE650, 270 0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 }, 271 272 { PCMCIA_STR_MELCO_LPC2_TX, 273 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST, 274 PCMCIA_CIS_MELCO_LPC2_TX, 275 0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_DL10019 }, 276 277 { PCMCIA_STR_LINKSYS_COMBO_ECARD, 278 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD, 279 PCMCIA_CIS_LINKSYS_COMBO_ECARD, 280 0, -1, { 0x00, 0x80, 0xc8 } }, 281 282 { PCMCIA_STR_LINKSYS_TRUST_COMBO_ECARD, 283 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_TRUST_COMBO_ECARD, 284 PCMCIA_CIS_LINKSYS_TRUST_COMBO_ECARD, 285 0, 0x0120, { 0x20, 0x04, 0x49 } }, 286 287 /* Although the comments above say to put VENDOR/PRODUCT INVALID IDs 288 above this list, we need to keep this one below the ECARD_1, or else 289 both will match the same more-generic entry rather than the more 290 specific one above with proper vendor and product IDs. */ 291 { PCMCIA_STR_LINKSYS_ECARD_2, 292 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 293 PCMCIA_CIS_LINKSYS_ECARD_2, 294 0, -1, { 0x00, 0x80, 0xc8 } }, 295 296 /* 297 * D-Link DE-650 has many minor versions: 298 * 299 * CIS information Manufacturer Product Note 300 * 1 "D-Link, DE-650" INVALID INVALID white card 301 * 2 "D-Link, DE-650, Ver 01.00" INVALID INVALID became bare metal 302 * 3 "D-Link, DE-650, Ver 01.00" 0x149 0x265 minor change in look 303 * 4 "D-Link, DE-650, Ver 01.00" 0x149 0x265 collision LED added 304 * 305 * While the 1st and the 2nd types should use the "D-Link DE-650" entry, 306 * the 3rd and the 4th types should use the "Linksys EtherCard" entry. 307 * Therefore, this enty must be below the LINKSYS_ECARD_1. --itohy 308 */ 309 { PCMCIA_STR_DLINK_DE650, 310 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 311 PCMCIA_CIS_DLINK_DE650, 312 0, 0x0040, { 0x00, 0x80, 0xc8 } }, 313 314 /* 315 * IO-DATA PCLA/TE and later version of PCLA/T has valid 316 * vendor/product ID and it is possible to read MAC address 317 * using standard I/O ports. It also read from CIS offset 0x01c0. 318 * On the other hand, earlier version of PCLA/T doesn't have valid 319 * vendor/product ID and MAC address must be read from CIS offset 320 * 0x0ff0 (i.e., usual ne2000 way to read it doesn't work). 321 * And CIS information of earlier and later version of PCLA/T are 322 * same except fourth element. So, for now, we place the entry for 323 * PCLA/TE (and later version of PCLA/T) followed by entry 324 * for the earlier version of PCLA/T (or, modify to match all CIS 325 * information and have three or more individual entries). 326 */ 327 { PCMCIA_STR_IODATA_PCLATE, 328 PCMCIA_VENDOR_IODATA, PCMCIA_PRODUCT_IODATA_PCLATE, 329 PCMCIA_CIS_IODATA_PCLATE, 330 0, -1, { 0x00, 0xa0, 0xb0 } }, 331 332 /* 333 * This entry should be placed after above PCLA-TE entry. 334 * See above comments for detail. 335 */ 336 { PCMCIA_STR_IODATA_PCLAT, 337 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 338 PCMCIA_CIS_IODATA_PCLAT, 339 0, 0x0ff0, { 0x00, 0xa0, 0xb0 } }, 340 341 { PCMCIA_STR_DAYNA_COMMUNICARD_E_1, 342 PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_1, 343 PCMCIA_CIS_DAYNA_COMMUNICARD_E_1, 344 0, 0x0110, { 0x00, 0x80, 0x19 } }, 345 346 { PCMCIA_STR_DAYNA_COMMUNICARD_E_2, 347 PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_2, 348 PCMCIA_CIS_DAYNA_COMMUNICARD_E_2, 349 0, -1, { 0x00, 0x80, 0x19 } }, 350 351 { PCMCIA_STR_COREGA_ETHER_PCC_T, 352 PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_T, 353 PCMCIA_CIS_COREGA_ETHER_PCC_T, 354 0, -1, { 0x00, 0x00, 0xf4 } }, 355 356 { PCMCIA_STR_COREGA_ETHER_PCC_TD, 357 PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_TD, 358 PCMCIA_CIS_COREGA_ETHER_PCC_TD, 359 0, -1, { 0x00, 0x00, 0xf4 } }, 360 361 { PCMCIA_STR_COREGA_ETHER_II_PCC_T, 362 PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_T, 363 PCMCIA_CIS_COREGA_ETHER_II_PCC_T, 364 0, -1, { 0x00, 0x00, 0xf4 } }, 365 366 { PCMCIA_STR_COREGA_FAST_ETHER_PCC_TX, 367 PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FAST_ETHER_PCC_TX, 368 PCMCIA_CIS_COREGA_FAST_ETHER_PCC_TX, 369 0, -1, { 0x00, 0x00, 0xf4 }, NE2000DVF_DL10019 }, 370 371 { PCMCIA_STR_COREGA_FETHER_PCC_TXF, 372 PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXF, 373 PCMCIA_CIS_COREGA_FETHER_PCC_TXF, 374 0, -1, { 0x00, 0x90, 0x99 }, NE2000DVF_DL10019 }, 375 376 { PCMCIA_STR_COREGA_FETHER_PCC_TXD, 377 PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXD, 378 PCMCIA_CIS_COREGA_FETHER_PCC_TXD, 379 0, -1, { 0x00, 0x90, 0x99 } }, 380 381 { PCMCIA_STR_COMPEX_LINKPORT_ENET_B, 382 PCMCIA_VENDOR_COMPEX, PCMCIA_PRODUCT_COMPEX_LINKPORT_ENET_B, 383 PCMCIA_CIS_COMPEX_LINKPORT_ENET_B, 384 0, 0x01c0, { 0x00, 0xa0, 0x0c } }, 385 386 { PCMCIA_STR_SMC_EZCARD, 387 PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_EZCARD, 388 PCMCIA_CIS_SMC_EZCARD, 389 0, 0x01c0, { 0x00, 0xe0, 0x29 } }, 390 391 { PCMCIA_STR_SOCKET_EA_ETHER, 392 PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_EA_ETHER, 393 PCMCIA_CIS_SOCKET_EA_ETHER, 394 0, -1, { 0x00, 0xc0, 0x1b } }, 395 396 { PCMCIA_STR_SOCKET_LP_ETHER_CF, 397 PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER_CF, 398 PCMCIA_CIS_SOCKET_LP_ETHER_CF, 399 0, -1, { 0x00, 0xc0, 0x1b } }, 400 401 { PCMCIA_STR_SOCKET_LP_ETHER, 402 PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER, 403 PCMCIA_CIS_SOCKET_LP_ETHER, 404 0, -1, { 0x00, 0xc0, 0x1b } }, 405 406 { PCMCIA_STR_KINGSTON_KNE2, 407 PCMCIA_VENDOR_KINGSTON, PCMCIA_PRODUCT_KINGSTON_KNE2, 408 PCMCIA_CIS_KINGSTON_KNE2, 409 0, -1, { 0x00, 0xc0, 0xf0 } }, 410 411 { PCMCIA_STR_XIRCOM_CFE_10, 412 PCMCIA_VENDOR_XIRCOM, PCMCIA_PRODUCT_XIRCOM_CFE_10, 413 PCMCIA_CIS_XIRCOM_CFE_10, 414 0, -1, { 0x00, 0x10, 0xa4 } }, 415 416 { PCMCIA_STR_MELCO_LPC3_TX, 417 PCMCIA_VENDOR_MELCO, PCMCIA_PRODUCT_MELCO_LPC3_TX, 418 PCMCIA_CIS_MELCO_LPC3_TX, 419 0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 }, 420 421 { PCMCIA_STR_BILLIONTON_LNT10TN, 422 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 423 PCMCIA_CIS_BILLIONTON_LNT10TN, 424 0, -1, { 0x00, 0x00, 0x00 } }, 425 426 { PCMCIA_STR_NDC_ND5100_E, 427 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 428 PCMCIA_CIS_NDC_ND5100_E, 429 0, -1, { 0x00, 0x80, 0xc6 } }, 430 431 { PCMCIA_STR_TELECOMDEVICE_TCD_HPC100, 432 PCMCIA_VENDOR_TELECOMDEVICE, PCMCIA_PRODUCT_TELECOMDEVICE_TCD_HPC100, 433 PCMCIA_CIS_TELECOMDEVICE_TCD_HPC100, 434 0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 }, 435 436 { PCMCIA_STR_MACNICA_ME1_JEIDA, 437 PCMCIA_VENDOR_MACNICA, PCMCIA_PRODUCT_MACNICA_ME1_JEIDA, 438 PCMCIA_CIS_MACNICA_ME1_JEIDA, 439 0, 0x00b8, { 0x08, 0x00, 0x42 } }, 440 441 #if 0 442 /* the rest of these are stolen from the linux pcnet pcmcia device 443 driver. Since I don't know the manfid or cis info strings for 444 any of them, they're not compiled in until I do. */ 445 { "APEX MultiCard", 446 0x0000, 0x0000, NULL, NULL, 0, 447 0x03f4, { 0x00, 0x20, 0xe5 } }, 448 { "ASANTE FriendlyNet", 449 0x0000, 0x0000, NULL, NULL, 0, 450 0x4910, { 0x00, 0x00, 0x94 } }, 451 { "Danpex EN-6200P2", 452 0x0000, 0x0000, NULL, NULL, 0, 453 0x0110, { 0x00, 0x40, 0xc7 } }, 454 { "DataTrek NetCard", 455 0x0000, 0x0000, NULL, NULL, 0, 456 0x0ff0, { 0x00, 0x20, 0xe8 } }, 457 { "Dayna CommuniCard E", 458 0x0000, 0x0000, NULL, NULL, 0, 459 0x0110, { 0x00, 0x80, 0x19 } }, 460 { "EP-210 Ethernet", 461 0x0000, 0x0000, NULL, NULL, 0, 462 0x0110, { 0x00, 0x40, 0x33 } }, 463 { "ELECOM Laneed LD-CDWA", 464 0x0000, 0x0000, NULL, NULL, 0, 465 0x00b8, { 0x08, 0x00, 0x42 } }, 466 { "Grey Cell GCS2220", 467 0x0000, 0x0000, NULL, NULL, 0, 468 0x0000, { 0x00, 0x47, 0x43 } }, 469 { "Hypertec Ethernet", 470 0x0000, 0x0000, NULL, NULL, 0, 471 0x01c0, { 0x00, 0x40, 0x4c } }, 472 { "IBM CCAE", 473 0x0000, 0x0000, NULL, NULL, 0, 474 0x0ff0, { 0x08, 0x00, 0x5a } }, 475 { "IBM CCAE", 476 0x0000, 0x0000, NULL, NULL, 0, 477 0x0ff0, { 0x00, 0x04, 0xac } }, 478 { "IBM CCAE", 479 0x0000, 0x0000, NULL, NULL, 0, 480 0x0ff0, { 0x00, 0x06, 0x29 } }, 481 { "IBM FME", 482 0x0000, 0x0000, NULL, NULL, 0, 483 0x0374, { 0x00, 0x04, 0xac } }, 484 { "IBM FME", 485 0x0000, 0x0000, NULL, NULL, 0, 486 0x0374, { 0x08, 0x00, 0x5a } }, 487 { "Katron PE-520", 488 0x0000, 0x0000, NULL, NULL, 0, 489 0x0110, { 0x00, 0x40, 0xf6 } }, 490 { "Kingston KNE-PCM/x", 491 0x0000, 0x0000, NULL, NULL, 0, 492 0x0ff0, { 0x00, 0xc0, 0xf0 } }, 493 { "Kingston KNE-PCM/x", 494 0x0000, 0x0000, NULL, NULL, 0, 495 0x0ff0, { 0xe2, 0x0c, 0x0f } }, 496 { "Longshine LCS-8534", 497 0x0000, 0x0000, NULL, NULL, 0, 498 0x0000, { 0x08, 0x00, 0x00 } }, 499 { "Maxtech PCN2000", 500 0x0000, 0x0000, NULL, NULL, 0, 501 0x5000, { 0x00, 0x00, 0xe8 } }, 502 { "NDC Instant-Link", 503 0x0000, 0x0000, NULL, NULL, 0, 504 0x003a, { 0x00, 0x80, 0xc6 } }, 505 { "NE2000 Compatible", 506 0x0000, 0x0000, NULL, NULL, 0, 507 0x0ff0, { 0x00, 0xa0, 0x0c } }, 508 { "Network General Sniffer", 509 0x0000, 0x0000, NULL, NULL, 0, 510 0x0ff0, { 0x00, 0x00, 0x65 } }, 511 { "Panasonic VEL211", 512 0x0000, 0x0000, NULL, NULL, 0, 513 0x0ff0, { 0x00, 0x80, 0x45 } }, 514 { "SCM Ethernet", 515 0x0000, 0x0000, NULL, NULL, 0, 516 0x0ff0, { 0x00, 0x20, 0xcb } }, 517 { "Volktek NPL-402CT", 518 0x0000, 0x0000, NULL, NULL, 0, 519 0x0060, { 0x00, 0x40, 0x05 } }, 520 #endif 521 522 { PCMCIA_STR_ALLIEDTELESIS_LA_PCM, 523 PCMCIA_VENDOR_ALLIEDTELESIS, PCMCIA_PRODUCT_ALLIEDTELESIS_LA_PCM, 524 PCMCIA_CIS_ALLIEDTELESIS_LA_PCM, 525 0, 0x0ff0, { 0x00, 0x00, 0xf4 } }, 526 }; 527 528 #define NE2000_NDEVS (sizeof(ne2000devs) / sizeof(ne2000devs[0])) 529 530 #define ne2000_match(card, fct, n) \ 531 ((((((card)->manufacturer != PCMCIA_VENDOR_INVALID) && \ 532 ((card)->manufacturer == ne2000devs[(n)].manufacturer) && \ 533 ((card)->product != PCMCIA_PRODUCT_INVALID) && \ 534 ((card)->product == ne2000devs[(n)].product)) || \ 535 ((ne2000devs[(n)].cis_info[0]) && (ne2000devs[(n)].cis_info[1]) && \ 536 (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis_info[0]) == 0) && \ 537 (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis_info[1]) == 0))) && \ 538 ((fct) == ne2000devs[(n)].function))? \ 539 &ne2000devs[(n)]:NULL) 540 541 int 542 ne_pcmcia_match(parent, match, aux) 543 struct device *parent; 544 struct cfdata *match; 545 void *aux; 546 { 547 struct pcmcia_attach_args *pa = aux; 548 int i; 549 550 for (i = 0; i < NE2000_NDEVS; i++) { 551 if (ne2000_match(pa->card, pa->pf->number, i)) 552 return (1); 553 } 554 555 return (0); 556 } 557 558 void 559 ne_pcmcia_attach(parent, self, aux) 560 struct device *parent, *self; 561 void *aux; 562 { 563 struct ne_pcmcia_softc *psc = (void *) self; 564 struct ne2000_softc *nsc = &psc->sc_ne2000; 565 struct dp8390_softc *dsc = &nsc->sc_dp8390; 566 struct pcmcia_attach_args *pa = aux; 567 struct pcmcia_config_entry *cfe; 568 const struct ne2000dev *ne_dev; 569 int i; 570 u_int8_t myea[6], *enaddr; 571 const char *typestr = ""; 572 573 psc->sc_pf = pa->pf; 574 575 for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL; 576 cfe = SIMPLEQ_NEXT(cfe, cfe_list)) { 577 #if 0 578 /* 579 * Some ne2000 driver's claim to have memory; others don't. 580 * Since I don't care, I don't check. 581 */ 582 583 if (cfe->num_memspace != 1) { 584 printf(": unexpected number of memory spaces " 585 " %d should be 1\n", cfe->num_memspace); 586 continue; 587 } 588 #endif 589 590 if (cfe->num_iospace == 1) { 591 if (cfe->iospace[0].length != NE2000_NPORTS) { 592 printf(": unexpected I/O space configuration" 593 " (continued)\n%s", dsc->sc_dev.dv_xname); 594 /* XXX really safe for all other cards? */ 595 } 596 } else if (cfe->num_iospace == 2) { 597 /* 598 * Some cards report a separate space for NIC and ASIC. 599 * This make some sense, but we must allocate a single 600 * NE2000_NPORTS-sized chunk, due to brain damaged 601 * address decoders on some of these cards. 602 */ 603 if (cfe->iospace[0].length + cfe->iospace[1].length != 604 NE2000_NPORTS) { 605 #ifdef DIAGNOSTIC 606 printf(": unexpected I/O " 607 "space configuration; ignored\n%s", 608 dsc->sc_dev.dv_xname); 609 #endif 610 continue; 611 } 612 } else { 613 #ifdef DIAGNOSTIC 614 printf(": unexpected number of i/o spaces %d" 615 " should be 1 or 2; ignored\n%s", 616 cfe->num_iospace, dsc->sc_dev.dv_xname); 617 #endif 618 continue; 619 } 620 621 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start, 622 NE2000_NPORTS, NE2000_NPORTS, &psc->sc_pcioh)) { 623 #ifdef DIAGNOSTIC 624 printf(": can't allocate i/o space %lx; ignored\n%s", 625 cfe->iospace[0].start, dsc->sc_dev.dv_xname); 626 #endif 627 continue; 628 } 629 630 /* Ok, found. */ 631 break; 632 } 633 634 if (cfe == NULL) { 635 printf(": no suitable config entry\n"); 636 goto fail_1; 637 } 638 639 dsc->sc_regt = psc->sc_pcioh.iot; 640 dsc->sc_regh = psc->sc_pcioh.ioh; 641 642 nsc->sc_asict = psc->sc_pcioh.iot; 643 if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh, 644 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS, 645 &nsc->sc_asich)) { 646 printf(": can't get subregion for asic\n"); 647 goto fail_2; 648 } 649 650 /* Set up power management hooks. */ 651 dsc->sc_enable = ne_pcmcia_enable; 652 dsc->sc_disable = ne_pcmcia_disable; 653 654 /* Enable the card. */ 655 pcmcia_function_init(pa->pf, cfe); 656 if (pcmcia_function_enable(pa->pf)) { 657 printf(": function enable failed\n"); 658 goto fail_2; 659 } 660 661 /* some cards claim to be io16, but they're lying. */ 662 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8, 663 NE2000_NIC_OFFSET, NE2000_NIC_NPORTS, 664 &psc->sc_pcioh, &psc->sc_nic_io_window)) { 665 printf(": can't map NIC i/o space\n"); 666 goto fail_3; 667 } 668 669 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16, 670 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS, 671 &psc->sc_pcioh, &psc->sc_asic_io_window)) { 672 printf(": can't map ASIC i/o space\n"); 673 goto fail_4; 674 } 675 676 printf("\n"); 677 678 /* 679 * Read the station address from the board. 680 */ 681 i = 0; 682 again: 683 enaddr = NULL; /* Ask ASIC by default */ 684 for (; i < NE2000_NDEVS; i++) { 685 ne_dev = ne2000_match(pa->card, pa->pf->number, i); 686 if (ne_dev != NULL) { 687 if (ne_dev->enet_maddr >= 0) { 688 enaddr = ne_pcmcia_get_enaddr(psc, 689 ne_dev->enet_maddr, myea); 690 if (enaddr == NULL) 691 continue; 692 } 693 break; 694 } 695 } 696 if (i == NE2000_NDEVS) { 697 printf("%s: can't match ethernet vendor code\n", 698 dsc->sc_dev.dv_xname); 699 goto fail_5; 700 } 701 702 if ((ne_dev->flags & NE2000DVF_DL10019) != 0) { 703 u_int8_t type; 704 705 enaddr = ne_pcmcia_dl10019_get_enaddr(psc, myea); 706 if (enaddr == NULL) { 707 ++i; 708 goto again; 709 } 710 711 dsc->sc_mediachange = dl10019_mediachange; 712 dsc->sc_mediastatus = dl10019_mediastatus; 713 dsc->init_card = dl10019_init_card; 714 dsc->stop_card = dl10019_stop_card; 715 dsc->sc_media_init = dl10019_media_init; 716 dsc->sc_media_fini = dl10019_media_fini; 717 718 /* Determine if this is a DL10019 or a DL10022. */ 719 type = bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 0x0f); 720 if (type == 0x91 || type == 0x99) { 721 nsc->sc_type = NE2000_TYPE_DL10022; 722 typestr = " (DL10022)"; 723 } else { 724 nsc->sc_type = NE2000_TYPE_DL10019; 725 typestr = " (DL10019)"; 726 } 727 } 728 729 if ((ne_dev->flags & NE2000DVF_AX88190) != 0) { 730 if (ne_pcmcia_ax88190_set_iobase(psc)) { 731 ++i; 732 goto again; 733 } 734 735 dsc->sc_mediachange = ax88190_mediachange; 736 dsc->sc_mediastatus = ax88190_mediastatus; 737 dsc->init_card = ax88190_init_card; 738 dsc->stop_card = ax88190_stop_card; 739 dsc->sc_media_init = ax88190_media_init; 740 dsc->sc_media_fini = ax88190_media_fini; 741 742 nsc->sc_type = NE2000_TYPE_AX88190; 743 typestr = " (AX88190)"; 744 } 745 746 if (enaddr != NULL) { 747 /* 748 * Make sure this is what we expect. 749 */ 750 if (enaddr[0] != ne_dev->enet_vendor[0] || 751 enaddr[1] != ne_dev->enet_vendor[1] || 752 enaddr[2] != ne_dev->enet_vendor[2]) { 753 ++i; 754 goto again; 755 } 756 } 757 758 /* 759 * Check for a RealTek 8019. 760 */ 761 if (nsc->sc_type == 0) { 762 bus_space_write_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CR, 763 ED_CR_PAGE_0 | ED_CR_STP); 764 if (bus_space_read_1(dsc->sc_regt, dsc->sc_regh, 765 NERTL_RTL0_8019ID0) == RTL0_8019ID0 && 766 bus_space_read_1(dsc->sc_regt, dsc->sc_regh, 767 NERTL_RTL0_8019ID1) == RTL0_8019ID1) { 768 typestr = " (RTL8019)"; 769 dsc->sc_mediachange = rtl80x9_mediachange; 770 dsc->sc_mediastatus = rtl80x9_mediastatus; 771 dsc->init_card = rtl80x9_init_card; 772 dsc->sc_media_init = rtl80x9_media_init; 773 } 774 } 775 776 printf("%s: %s%s Ethernet\n", dsc->sc_dev.dv_xname, ne_dev->name, 777 typestr); 778 779 if (ne2000_attach(nsc, enaddr)) 780 goto fail_5; 781 782 pcmcia_function_disable(pa->pf); 783 return; 784 785 fail_5: 786 /* Unmap ASIC i/o windows. */ 787 pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window); 788 789 fail_4: 790 /* Unmap NIC i/o windows. */ 791 pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window); 792 793 fail_3: 794 pcmcia_function_disable(pa->pf); 795 796 fail_2: 797 /* Free our i/o space. */ 798 pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh); 799 800 fail_1: 801 psc->sc_nic_io_window = -1; 802 } 803 804 int 805 ne_pcmcia_detach(self, flags) 806 struct device *self; 807 int flags; 808 { 809 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)self; 810 int error; 811 812 if (psc->sc_nic_io_window == -1) 813 /* Nothing to detach. */ 814 return (0); 815 816 error = ne2000_detach(&psc->sc_ne2000, flags); 817 if (error != 0) 818 return (error); 819 820 /* Unmap our i/o windows. */ 821 pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window); 822 pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window); 823 824 /* Free our i/o space. */ 825 pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh); 826 827 return (0); 828 } 829 830 int 831 ne_pcmcia_enable(dsc) 832 struct dp8390_softc *dsc; 833 { 834 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc; 835 struct ne2000_softc *nsc = &psc->sc_ne2000; 836 837 /* set up the interrupt */ 838 psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr, 839 dsc); 840 if (psc->sc_ih == NULL) { 841 printf("%s: couldn't establish interrupt\n", 842 dsc->sc_dev.dv_xname); 843 goto fail_1; 844 } 845 846 if (pcmcia_function_enable(psc->sc_pf)) 847 goto fail_2; 848 849 if (nsc->sc_type == NE2000_TYPE_AX88190) 850 if (ne_pcmcia_ax88190_set_iobase(psc)) 851 goto fail_3; 852 853 return (0); 854 855 fail_3: 856 pcmcia_function_disable(psc->sc_pf); 857 fail_2: 858 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih); 859 fail_1: 860 return (1); 861 } 862 863 void 864 ne_pcmcia_disable(dsc) 865 struct dp8390_softc *dsc; 866 { 867 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc; 868 869 pcmcia_function_disable(psc->sc_pf); 870 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih); 871 } 872 873 u_int8_t * 874 ne_pcmcia_get_enaddr(psc, maddr, myea) 875 struct ne_pcmcia_softc *psc; 876 int maddr; 877 u_int8_t myea[ETHER_ADDR_LEN]; 878 { 879 struct ne2000_softc *nsc = &psc->sc_ne2000; 880 struct dp8390_softc *dsc = &nsc->sc_dp8390; 881 struct pcmcia_mem_handle pcmh; 882 bus_size_t offset; 883 u_int8_t *enaddr = NULL; 884 int j, mwindow; 885 886 if (maddr < 0) 887 return (NULL); 888 889 if (pcmcia_mem_alloc(psc->sc_pf, ETHER_ADDR_LEN * 2, &pcmh)) { 890 printf("%s: can't alloc mem for enet addr\n", 891 dsc->sc_dev.dv_xname); 892 goto fail_1; 893 } 894 if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, maddr, 895 ETHER_ADDR_LEN * 2, &pcmh, &offset, &mwindow)) { 896 printf("%s: can't map mem for enet addr\n", 897 dsc->sc_dev.dv_xname); 898 goto fail_2; 899 } 900 for (j = 0; j < ETHER_ADDR_LEN; j++) 901 myea[j] = bus_space_read_1(pcmh.memt, pcmh.memh, 902 offset + (j * 2)); 903 enaddr = myea; 904 905 pcmcia_mem_unmap(psc->sc_pf, mwindow); 906 fail_2: 907 pcmcia_mem_free(psc->sc_pf, &pcmh); 908 fail_1: 909 return (enaddr); 910 } 911 912 u_int8_t * 913 ne_pcmcia_dl10019_get_enaddr(psc, myea) 914 struct ne_pcmcia_softc *psc; 915 u_int8_t myea[ETHER_ADDR_LEN]; 916 { 917 struct ne2000_softc *nsc = &psc->sc_ne2000; 918 u_int8_t sum; 919 int j; 920 921 #define PAR0 0x04 922 for (j = 0, sum = 0; j < 8; j++) 923 sum += bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 924 PAR0 + j); 925 if (sum != 0xff) 926 return (NULL); 927 for (j = 0; j < ETHER_ADDR_LEN; j++) 928 myea[j] = bus_space_read_1(nsc->sc_asict, 929 nsc->sc_asich, PAR0 + j); 930 #undef PAR0 931 return (myea); 932 } 933 934 int 935 ne_pcmcia_ax88190_set_iobase(psc) 936 struct ne_pcmcia_softc *psc; 937 { 938 struct ne2000_softc *nsc = &psc->sc_ne2000; 939 struct dp8390_softc *dsc = &nsc->sc_dp8390; 940 struct pcmcia_mem_handle pcmh; 941 bus_size_t offset; 942 int rv = 1, mwindow; 943 u_int last_liobase, new_liobase; 944 945 if (pcmcia_mem_alloc(psc->sc_pf, AX88190_LAN_IOSIZE, &pcmh)) { 946 #if 0 947 printf("%s: can't alloc mem for LAN iobase\n", 948 dsc->sc_dev.dv_xname); 949 #endif 950 goto fail_1; 951 } 952 if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, 953 AX88190_LAN_IOBASE, AX88190_LAN_IOSIZE, 954 &pcmh, &offset, &mwindow)) { 955 printf("%s: can't map mem for LAN iobase\n", 956 dsc->sc_dev.dv_xname); 957 goto fail_2; 958 } 959 960 last_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) | 961 (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8); 962 #ifdef DIAGNOSTIC 963 printf("%s: LAN iobase 0x%x (0x%x) ->", dsc->sc_dev.dv_xname, 964 last_liobase, (u_int)psc->sc_pcioh.addr); 965 #endif 966 bus_space_write_1(pcmh.memt, pcmh.memh, offset, 967 psc->sc_pcioh.addr & 0xff); 968 bus_space_write_1(pcmh.memt, pcmh.memh, offset + 2, 969 psc->sc_pcioh.addr >> 8); 970 971 new_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) | 972 (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8); 973 #ifdef DIAGNOSTIC 974 printf(" 0x%x\n", new_liobase); 975 #endif 976 if ((last_liobase == psc->sc_pcioh.addr) 977 || (last_liobase != new_liobase)) 978 rv = 0; 979 980 pcmcia_mem_unmap(psc->sc_pf, mwindow); 981 fail_2: 982 pcmcia_mem_free(psc->sc_pf, &pcmh); 983 fail_1: 984 return (rv); 985 } 986