if_ed_pccard.c revision 149696
1/*- 2 * Copyright (c) 1995, David Greenman 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice unmodified, this list of conditions, and the following 10 * 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 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $FreeBSD: head/sys/dev/ed/if_ed_pccard.c 149696 2005-09-01 20:08:24Z imp $ 28 */ 29 30#include "opt_ed.h" 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/socket.h> 35#include <sys/kernel.h> 36#include <sys/conf.h> 37#include <sys/uio.h> 38 39#include <sys/module.h> 40#include <sys/bus.h> 41#include <machine/bus.h> 42#include <sys/rman.h> 43#include <machine/resource.h> 44 45#include <net/ethernet.h> 46#include <net/if.h> 47#include <net/if_arp.h> 48#include <net/if_mib.h> 49#include <net/if_media.h> 50 51#include <dev/ed/if_edreg.h> 52#include <dev/ed/if_edvar.h> 53#include <dev/pccard/pccardvar.h> 54#include <dev/pccard/pccard_cis.h> 55#ifndef ED_NO_MIIBUS 56#include <dev/mii/mii.h> 57#include <dev/mii/miivar.h> 58#endif 59 60#include "card_if.h" 61#ifndef ED_NO_MIIBUS 62/* "device miibus" required. See GENERIC if you get errors here. */ 63#include "miibus_if.h" 64#endif 65#include "pccarddevs.h" 66 67#ifndef ED_NO_MIIBUS 68MODULE_DEPEND(ed, miibus, 1, 1, 1); 69#endif 70MODULE_DEPEND(ed, ether, 1, 1, 1); 71 72/* 73 * PC Cards should be using a network specific FUNCE in the CIS to 74 * communicate their MAC address to the driver. However, there are a 75 * large number of NE-2000ish PC Cards that don't do this. Nearly all 76 * of them store the MAC address at a fixed offset into attribute 77 * memory, without any reference at all appearing in the CIS. And 78 * nearly all of those store it at the same location. 79 */ 80#define ED_DEFAULT_MAC_OFFSET 0xff0 81 82/* 83 * PC Card (PCMCIA) specific code. 84 */ 85static int ed_pccard_probe(device_t); 86static int ed_pccard_attach(device_t); 87 88static int ed_pccard_ax88x90(device_t dev); 89 90static void ax88x90_geteprom(struct ed_softc *); 91static int ed_pccard_memread(device_t dev, off_t offset, u_char *byte); 92static int ed_pccard_memwrite(device_t dev, off_t offset, u_char byte); 93#ifndef ED_NO_MIIBUS 94static void ed_pccard_dlink_mii_reset(struct ed_softc *sc); 95static u_int ed_pccard_dlink_mii_readbits(struct ed_softc *sc, int nbits); 96static void ed_pccard_dlink_mii_writebits(struct ed_softc *sc, u_int val, 97 int nbits); 98#endif 99static int ed_pccard_Linksys(device_t dev); 100 101static const struct ed_product { 102 struct pccard_product prod; 103 int flags; 104#define NE2000DVF_DL100XX 0x0001 /* chip is D-Link DL10019/22 */ 105#define NE2000DVF_AX88X90 0x0002 /* chip is ASIX AX88[17]90 */ 106#define NE2000DVF_ENADDR 0x0004 /* Get MAC from attr mem */ 107#define NE2000DVF_ANYFUNC 0x0008 /* Allow any function type */ 108#define NE2000DVF_MODEM 0x0010 /* Has a modem/serial */ 109 int enoff; 110 int edrid; 111 int siorid; 112} ed_pccard_products[] = { 113 { PCMCIA_CARD(ACCTON, EN2212), 0}, 114 { PCMCIA_CARD(ACCTON, EN2216), 0}, 115 { PCMCIA_CARD(ALLIEDTELESIS, LA_PCM), 0}, 116 { PCMCIA_CARD(AMBICOM, AMB8002T), 0}, 117 { PCMCIA_CARD(BILLIONTON, LNT10TN), 0}, 118 { PCMCIA_CARD(BILLIONTON, CFLT10N), 0}, 119 { PCMCIA_CARD(BROMAX, IPORT), 0}, 120 { PCMCIA_CARD(BROMAX, IPORT2), 0}, 121 { PCMCIA_CARD(BUFFALO, LPC2_CLT), 0}, 122 { PCMCIA_CARD(BUFFALO, LPC3_CLT), 0}, 123 { PCMCIA_CARD(BUFFALO, LPC3_CLX), NE2000DVF_AX88X90}, 124 { PCMCIA_CARD(BUFFALO, LPC4_TX), NE2000DVF_AX88X90}, 125 { PCMCIA_CARD(BUFFALO, LPC_CF_CLT), 0}, 126 { PCMCIA_CARD(CNET, NE2000), 0}, 127 { PCMCIA_CARD(COMPEX, AX88190), NE2000DVF_AX88X90}, 128 { PCMCIA_CARD(COMPEX, LANMODEM), 0}, 129 { PCMCIA_CARD(COMPEX, LINKPORT_ENET_B), 0}, 130 { PCMCIA_CARD(COREGA, ETHER_II_PCC_T), 0}, 131 { PCMCIA_CARD(COREGA, ETHER_II_PCC_TD), 0}, 132 { PCMCIA_CARD(COREGA, ETHER_PCC_T), 0}, 133 { PCMCIA_CARD(COREGA, ETHER_PCC_TD), 0}, 134 { PCMCIA_CARD(COREGA, FAST_ETHER_PCC_TX), NE2000DVF_DL100XX }, 135 { PCMCIA_CARD(COREGA, FETHER_PCC_TXD), NE2000DVF_AX88X90 }, 136 { PCMCIA_CARD(COREGA, FETHER_PCC_TXF), NE2000DVF_DL100XX }, 137 { PCMCIA_CARD(DAYNA, COMMUNICARD_E_1), 0}, 138 { PCMCIA_CARD(DAYNA, COMMUNICARD_E_2), 0}, 139 { PCMCIA_CARD(DLINK, DE650), 0}, 140 { PCMCIA_CARD(DLINK, DE660), 0 }, 141 { PCMCIA_CARD(DLINK, DE660PLUS), 0}, 142 { PCMCIA_CARD(DLINK, DFE670TXD), NE2000DVF_DL100XX }, 143 { PCMCIA_CARD(DYNALINK, L10C), 0}, 144 { PCMCIA_CARD(EDIMAX, EP4000A), 0}, 145 { PCMCIA_CARD(EPSON, EEN10B), 0}, 146 { PCMCIA_CARD(EXP, THINLANCOMBO), 0}, 147 { PCMCIA_CARD(GREY_CELL, TDK3000), 0}, 148 { PCMCIA_CARD(GREY_CELL, DMF650TX), 149 NE2000DVF_ANYFUNC | NE2000DVF_DL100XX | NE2000DVF_MODEM, -1, 1, 0}, 150 { PCMCIA_CARD(IBM, HOME_AND_AWAY), 0}, 151 { PCMCIA_CARD(IBM, INFOMOVER), NE2000DVF_ENADDR, 0xff0}, 152 { PCMCIA_CARD(IODATA3, PCLAT), 0}, 153 { PCMCIA_CARD(KINGSTON, CIO10T), 0}, 154 { PCMCIA_CARD(KINGSTON, KNE2), 0}, 155 { PCMCIA_CARD(LANTECH, FASTNETTX),NE2000DVF_AX88X90 }, 156 { PCMCIA_CARD(LINKSYS, COMBO_ECARD), 157 NE2000DVF_DL100XX | NE2000DVF_AX88X90 }, 158 { PCMCIA_CARD(LINKSYS, ECARD_1), 0}, 159 { PCMCIA_CARD(LINKSYS, ECARD_2), 0}, 160 { PCMCIA_CARD(LINKSYS, ETHERFAST), NE2000DVF_DL100XX }, 161 { PCMCIA_CARD(LINKSYS, TRUST_COMBO_ECARD), 0}, 162 { PCMCIA_CARD(MACNICA, ME1_JEIDA), 0}, 163 { PCMCIA_CARD(MAGICRAM, ETHER), 0}, 164 { PCMCIA_CARD(MELCO, LPC3_CLX), NE2000DVF_AX88X90 }, 165 { PCMCIA_CARD(MELCO, LPC3_TX), NE2000DVF_AX88X90 }, 166 { PCMCIA_CARD(NDC, ND5100_E), 0}, 167 { PCMCIA_CARD(NETGEAR, FA410TXC), NE2000DVF_DL100XX}, 168 { PCMCIA_CARD(NETGEAR, FA411), NE2000DVF_AX88X90}, 169 { PCMCIA_CARD(NEXTCOM, NEXTHAWK), 0}, 170 { PCMCIA_CARD(NEWMEDIA, LANSURFER), 0}, 171 { PCMCIA_CARD(OEM2, ETHERNET), 0}, 172 { PCMCIA_CARD(PLANET, SMARTCOM2000), 0 }, 173 { PCMCIA_CARD(PREMAX, PE200), 0}, 174 { PCMCIA_CARD(PSION, LANGLOBAL), 0}, 175 { PCMCIA_CARD(RACORE, ETHERNET), 0}, 176 { PCMCIA_CARD(RACORE, FASTENET), NE2000DVF_AX88X90}, 177 { PCMCIA_CARD(RACORE, 8041TX), NE2000DVF_AX88X90}, 178 { PCMCIA_CARD(RELIA, COMBO), 0}, 179 { PCMCIA_CARD(RPTI, EP400), 0}, 180 { PCMCIA_CARD(RPTI, EP401), 0}, 181 { PCMCIA_CARD(SMC, EZCARD), 0}, 182 { PCMCIA_CARD(SOCKET, EA_ETHER), 0}, 183 { PCMCIA_CARD(SOCKET, ES_1000), 0}, 184 { PCMCIA_CARD(SOCKET, LP_ETHER), 0}, 185 { PCMCIA_CARD(SOCKET, LP_ETHER_CF), 0}, 186 { PCMCIA_CARD(SOCKET, LP_ETH_10_100_CF), NE2000DVF_DL100XX}, 187 { PCMCIA_CARD(SVEC, COMBOCARD), 0}, 188 { PCMCIA_CARD(SVEC, LANCARD), 0}, 189 { PCMCIA_CARD(TAMARACK, ETHERNET), 0}, 190 { PCMCIA_CARD(TDK, LAK_CD031), 0}, 191 { PCMCIA_CARD(TDK, DFL5610WS), 0}, 192 { PCMCIA_CARD(TELECOMDEVICE, LM5LT), 0 }, 193 { PCMCIA_CARD(TELECOMDEVICE, TCD_HPC100), NE2000DVF_AX88X90 }, 194 { PCMCIA_CARD(XIRCOM, CFE_10), 0}, 195 { PCMCIA_CARD(ZONET, ZEN), 0}, 196 { { NULL } } 197}; 198 199static int 200ed_pccard_probe(device_t dev) 201{ 202 const struct ed_product *pp; 203 int error; 204 uint32_t fcn = PCCARD_FUNCTION_UNSPEC; 205 206 /* Make sure we're a network function */ 207 error = pccard_get_function(dev, &fcn); 208 if (error != 0) 209 return (error); 210 211 if ((pp = (const struct ed_product *) pccard_product_lookup(dev, 212 (const struct pccard_product *) ed_pccard_products, 213 sizeof(ed_pccard_products[0]), NULL)) != NULL) { 214 if (pp->prod.pp_name != NULL) 215 device_set_desc(dev, pp->prod.pp_name); 216 /* 217 * Some devices don't ID themselves as network, but 218 * that's OK if the flags say so. 219 */ 220 if (!(pp->flags & NE2000DVF_ANYFUNC) && 221 fcn != PCCARD_FUNCTION_NETWORK) 222 return (ENXIO); 223 return (0); 224 } 225 return (ENXIO); 226} 227 228static int 229ed_pccard_rom_mac(device_t dev, uint8_t *enaddr) 230{ 231 struct ed_softc *sc = device_get_softc(dev); 232 uint8_t romdata[16]; 233 int i; 234 235 /* 236 * Read in the rom data at location 0. We should see one of 237 * two patterns. Either you'll see odd locations 0xff and 238 * even locations data, or you'll see odd and even locations 239 * mirror each other. In addition, the last two even locations 240 * should be 0. If they aren't 0, then we'll assume that 241 * there's no valid ROM data on this card and try another method 242 * to recover the MAC address. Since there are no NE-1000 243 * based PC Card devices, we'll assume we're 16-bit. 244 */ 245 ed_pio_readmem(sc, 0, romdata, 16); 246 if (romdata[12] != 0 || romdata[14] != 0) 247 return 0; 248 for (i = 0; i < ETHER_ADDR_LEN; i++) 249 enaddr[i] = romdata[i * 2]; 250 return 1; 251} 252 253static int 254ed_pccard_add_modem(device_t dev, int rid) 255{ 256 device_printf(dev, "Need to write this code: modem rid is %d\n", rid); 257 return 0; 258} 259 260static int 261ed_pccard_attach(device_t dev) 262{ 263 u_char sum; 264 u_char enaddr[ETHER_ADDR_LEN]; 265 const struct ed_product *pp; 266 int error, i; 267 struct ed_softc *sc = device_get_softc(dev); 268 269 if ((pp = (const struct ed_product *) pccard_product_lookup(dev, 270 (const struct pccard_product *) ed_pccard_products, 271 sizeof(ed_pccard_products[0]), NULL)) == NULL) 272 return (ENXIO); 273 sc->port_rid = pp->edrid; 274 if (pp->flags & NE2000DVF_DL100XX) { 275 error = ed_probe_Novell(dev, sc->port_rid, 0); 276 if (error == 0) 277 error = ed_pccard_Linksys(dev); 278 ed_release_resources(dev); 279 if (error == 0) 280 goto end2; 281 } 282 if (pp->flags & NE2000DVF_AX88X90) { 283 error = ed_pccard_ax88x90(dev); 284 if (error == 0) 285 goto end2; 286 } 287 error = ed_probe_Novell(dev, sc->port_rid, 0); 288end2: 289 if (error) { 290 ed_release_resources(dev); 291 return (error); 292 } 293 error = ed_alloc_irq(dev, 0, 0); 294 if (error) { 295 ed_release_resources(dev); 296 return (error); 297 } 298 299 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE, 300 edintr, sc, &sc->irq_handle); 301 if (error) { 302 device_printf(dev, "setup intr failed %d \n", error); 303 ed_release_resources(dev); 304 return (error); 305 } 306 307 /* 308 * For the older cards, we have to get the MAC address from 309 * the card in some way. Let's try the standard PCMCIA way 310 * first. If that fails, then check to see if we have valid 311 * data from the standard NE-2000 data roms. If that fails, 312 * check to see if the card has a hint about where to look in 313 * its CIS. If that fails, maybe we should look at some 314 * default value. In all fails, we should fail the attach, 315 * but don't right now. 316 */ 317 if (sc->chip_type == ED_CHIP_TYPE_DP8390) { 318 pccard_get_ether(dev, enaddr); 319 if (bootverbose) 320 device_printf(dev, "CIS MAC %6D\n", enaddr, ":"); 321 for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++) 322 sum |= enaddr[i]; 323 if (sum == 0 && ed_pccard_rom_mac(dev, enaddr)) { 324 if (bootverbose) 325 device_printf(dev, "ROM mac %6D\n", enaddr, 326 ":"); 327 sum++; 328 } 329 if (sum == 0 && pp->flags & NE2000DVF_ENADDR) { 330 for (i = 0; i < ETHER_ADDR_LEN; i++) { 331 ed_pccard_memread(dev, pp->enoff + i * 2, 332 enaddr + i); 333 sum |= enaddr[i]; 334 } 335 if (bootverbose) 336 device_printf(dev, "Hint MAC %6D\n", enaddr, 337 ":"); 338 } 339 if (sum == 0) { 340 for (i = 0; i < ETHER_ADDR_LEN; i++) { 341 ed_pccard_memread(dev, ED_DEFAULT_MAC_OFFSET + 342 i * 2, enaddr + i); 343 sum |= enaddr[i]; 344 } 345 if (bootverbose) 346 device_printf(dev, "Fallback MAC %6D\n", 347 enaddr, ":"); 348 } 349 if (sum == 0) { 350 device_printf(dev, "Cannot extract MAC address.\n"); 351 ed_release_resources(dev); 352 return (ENXIO); 353 } 354 bcopy(enaddr, sc->enaddr, ETHER_ADDR_LEN); 355 } 356 357 error = ed_attach(dev); 358 if (error) { 359 ed_release_resources(dev); 360 return (error); 361 } 362#ifndef ED_NO_MIIBUS 363 if (sc->chip_type == ED_CHIP_TYPE_DL10019 || 364 sc->chip_type == ED_CHIP_TYPE_DL10022) { 365 /* Probe for an MII bus, but ignore errors. */ 366 ed_pccard_dlink_mii_reset(sc); 367 sc->mii_readbits = ed_pccard_dlink_mii_readbits; 368 sc->mii_writebits = ed_pccard_dlink_mii_writebits; 369 mii_phy_probe(dev, &sc->miibus, ed_ifmedia_upd, 370 ed_ifmedia_sts); 371 } 372#endif 373 if (pp->flags & NE2000DVF_MODEM) 374 ed_pccard_add_modem(dev, pp->siorid); 375 return (0); 376} 377 378static void 379ax88x90_geteprom(struct ed_softc *sc) 380{ 381 int prom[16],i; 382 u_char tmp; 383 struct { 384 unsigned char offset, value; 385 } pg_seq[] = { 386 {ED_P0_CR, ED_CR_RD2|ED_CR_STP},/* Select Page0 */ 387 {ED_P0_DCR, 0x01}, 388 {ED_P0_RBCR0, 0x00}, /* Clear the count regs. */ 389 {ED_P0_RBCR1, 0x00}, 390 {ED_P0_IMR, 0x00}, /* Mask completion irq. */ 391 {ED_P0_ISR, 0xff}, 392 {ED_P0_RCR, ED_RCR_MON | ED_RCR_INTT}, /* Set To Monitor */ 393 {ED_P0_TCR, ED_TCR_LB0}, /* loopback mode. */ 394 {ED_P0_RBCR0, 32}, 395 {ED_P0_RBCR1, 0x00}, 396 {ED_P0_RSAR0, 0x00}, 397 {ED_P0_RSAR1, 0x04}, 398 {ED_P0_CR ,ED_CR_RD0 | ED_CR_STA}, 399 }; 400 401 /* Reset Card */ 402 tmp = ed_asic_inb(sc, ED_NOVELL_RESET); 403 ed_asic_outb(sc, ED_NOVELL_RESET, tmp); 404 DELAY(5000); 405 ed_asic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP); 406 DELAY(5000); 407 408 /* Card Settings */ 409 for (i = 0; i < sizeof(pg_seq) / sizeof(pg_seq[0]); i++) 410 ed_nic_outb(sc, pg_seq[i].offset, pg_seq[i].value); 411 412 /* Get Data */ 413 for (i = 0; i < 16; i++) 414 prom[i] = ed_asic_inb(sc, 0); 415 for (i = 0; i < ETHER_ADDR_LEN; i++) 416 sc->enaddr[i] = prom[i]; 417} 418 419static int 420ed_pccard_memwrite(device_t dev, off_t offset, u_char byte) 421{ 422 int cis_rid; 423 struct resource *cis; 424 425 cis_rid = 0; 426 cis = bus_alloc_resource(dev, SYS_RES_MEMORY, &cis_rid, 0, ~0, 427 4 << 10, RF_ACTIVE | RF_SHAREABLE); 428 if (cis == NULL) 429 return (ENXIO); 430 CARD_SET_RES_FLAGS(device_get_parent(dev), dev, SYS_RES_MEMORY, 431 cis_rid, PCCARD_A_MEM_ATTR); 432 433 bus_space_write_1(rman_get_bustag(cis), rman_get_bushandle(cis), 434 offset, byte); 435 436 bus_deactivate_resource(dev, SYS_RES_MEMORY, cis_rid, cis); 437 bus_release_resource(dev, SYS_RES_MEMORY, cis_rid, cis); 438 439 return (0); 440} 441 442static int 443ed_pccard_memread(device_t dev, off_t offset, u_char *byte) 444{ 445 int cis_rid; 446 struct resource *cis; 447 448 cis_rid = 0; 449 cis = bus_alloc_resource(dev, SYS_RES_MEMORY, &cis_rid, 0, ~0, 450 4 << 10, RF_ACTIVE | RF_SHAREABLE); 451 if (cis == NULL) 452 return (ENXIO); 453 CARD_SET_RES_FLAGS(device_get_parent(dev), dev, SYS_RES_MEMORY, 454 cis_rid, PCCARD_A_MEM_ATTR); 455 456 *byte = bus_space_read_1(rman_get_bustag(cis), rman_get_bushandle(cis), 457 offset); 458 459 bus_deactivate_resource(dev, SYS_RES_MEMORY, cis_rid, cis); 460 bus_release_resource(dev, SYS_RES_MEMORY, cis_rid, cis); 461 462 return (0); 463} 464 465/* 466 * Probe the Ethernet MAC addrees for PCMCIA Linksys EtherFast 10/100 467 * and compatible cards (DL10019C Ethernet controller). 468 * 469 * Note: The PAO patches try to use more memory for the card, but that 470 * seems to fail for my card. A future optimization would add this back 471 * conditionally. 472 */ 473static int 474ed_pccard_Linksys(device_t dev) 475{ 476 struct ed_softc *sc = device_get_softc(dev); 477 u_char sum; 478 uint8_t id; 479 int i; 480 481 /* 482 * Linksys registers(offset from ASIC base) 483 * 484 * 0x04-0x09 : Physical Address Register 0-5 (PAR0-PAR5) 485 * 0x0A : Card ID Register (CIR) 486 * 0x0B : Check Sum Register (SR) 487 */ 488 for (sum = 0, i = 0x04; i < 0x0c; i++) 489 sum += ed_asic_inb(sc, i); 490 if (sum != 0xff) 491 return (ENXIO); /* invalid DL10019C */ 492 for (i = 0; i < ETHER_ADDR_LEN; i++) 493 sc->enaddr[i] = ed_asic_inb(sc, 0x04 + i); 494 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS); 495 id = ed_asic_inb(sc, 0xf); 496 sc->isa16bit = 1; 497 sc->vendor = ED_VENDOR_NOVELL; 498 sc->type = ED_TYPE_NE2000; 499 sc->chip_type = (id & 0x90) == 0x90 ? 500 ED_CHIP_TYPE_DL10022 : ED_CHIP_TYPE_DL10019; 501 sc->type_str = ((id & 0x90) == 0x90) ? "DL10022" : "DL10019"; 502 return (0); 503} 504 505/* 506 * Special setup for AX88[17]90 507 */ 508static int 509ed_pccard_ax88x90(device_t dev) 510{ 511 int error; 512 int flags = device_get_flags(dev); 513 int iobase; 514 char *ts; 515 struct ed_softc *sc = device_get_softc(dev); 516 517 /* Allocate the port resource during setup. */ 518 error = ed_alloc_port(dev, sc->port_rid, ED_NOVELL_IO_PORTS); 519 if (error) 520 return (error); 521 522 sc->asic_offset = ED_NOVELL_ASIC_OFFSET; 523 sc->nic_offset = ED_NOVELL_NIC_OFFSET; 524 sc->chip_type = ED_CHIP_TYPE_AX88190; 525 526 /* 527 * Set Attribute Memory IOBASE Register. Is this a deficiency in 528 * the PC Card layer, or an ax88190 specific issue? xxx 529 */ 530 iobase = rman_get_start(sc->port_res); 531 ed_pccard_memwrite(dev, ED_AX88190_IOBASE0, iobase & 0xff); 532 ed_pccard_memwrite(dev, ED_AX88190_IOBASE1, (iobase >> 8) & 0xff); 533 ts = "AX88190"; 534 if (ed_asic_inb(sc, ED_ASIX_TEST) != 0) { 535 ed_pccard_memwrite(dev, ED_AX88790_CSR, ED_AX88790_CSR_PWRDWN); 536 ts = "AX88790"; 537 } 538 ax88x90_geteprom(sc); 539 ed_release_resources(dev); 540 error = ed_probe_Novell(dev, 0, flags); 541 if (error == 0) { 542 sc->vendor = ED_VENDOR_NOVELL; 543 sc->type = ED_TYPE_NE2000; 544 sc->chip_type = ED_CHIP_TYPE_AX88190; 545 sc->type_str = ts; 546 } 547 return (error); 548} 549 550#ifndef ED_NO_MIIBUS 551/* MII bit-twiddling routines for cards using Dlink chipset */ 552#define DLINK_MIISET(sc, x) ed_asic_outb(sc, ED_DLINK_MIIBUS, \ 553 ed_asic_inb(sc, ED_DLINK_MIIBUS) | (x)) 554#define DLINK_MIICLR(sc, x) ed_asic_outb(sc, ED_DLINK_MIIBUS, \ 555 ed_asic_inb(sc, ED_DLINK_MIIBUS) & ~(x)) 556 557static void 558ed_pccard_dlink_mii_reset(sc) 559 struct ed_softc *sc; 560{ 561 if (sc->chip_type != ED_CHIP_TYPE_DL10022) 562 return; 563 564 ed_asic_outb(sc, ED_DLINK_MIIBUS, ED_DLINK_MII_RESET2); 565 DELAY(10); 566 ed_asic_outb(sc, ED_DLINK_MIIBUS, 567 ED_DLINK_MII_RESET2 | ED_DLINK_MII_RESET1); 568 DELAY(10); 569 ed_asic_outb(sc, ED_DLINK_MIIBUS, ED_DLINK_MII_RESET2); 570 DELAY(10); 571 ed_asic_outb(sc, ED_DLINK_MIIBUS, 572 ED_DLINK_MII_RESET2 | ED_DLINK_MII_RESET1); 573 DELAY(10); 574 ed_asic_outb(sc, ED_DLINK_MIIBUS, 0); 575} 576 577static void 578ed_pccard_dlink_mii_writebits(sc, val, nbits) 579 struct ed_softc *sc; 580 u_int val; 581 int nbits; 582{ 583 int i; 584 585 if (sc->chip_type == ED_CHIP_TYPE_DL10022) 586 DLINK_MIISET(sc, ED_DLINK_MII_DIROUT_22); 587 else 588 DLINK_MIISET(sc, ED_DLINK_MII_DIROUT_19); 589 590 for (i = nbits - 1; i >= 0; i--) { 591 if ((val >> i) & 1) 592 DLINK_MIISET(sc, ED_DLINK_MII_DATAOUT); 593 else 594 DLINK_MIICLR(sc, ED_DLINK_MII_DATAOUT); 595 DELAY(10); 596 DLINK_MIISET(sc, ED_DLINK_MII_CLK); 597 DELAY(10); 598 DLINK_MIICLR(sc, ED_DLINK_MII_CLK); 599 DELAY(10); 600 } 601} 602 603static u_int 604ed_pccard_dlink_mii_readbits(sc, nbits) 605 struct ed_softc *sc; 606 int nbits; 607{ 608 int i; 609 u_int val = 0; 610 611 if (sc->chip_type == ED_CHIP_TYPE_DL10022) 612 DLINK_MIICLR(sc, ED_DLINK_MII_DIROUT_22); 613 else 614 DLINK_MIICLR(sc, ED_DLINK_MII_DIROUT_19); 615 616 for (i = nbits - 1; i >= 0; i--) { 617 DLINK_MIISET(sc, ED_DLINK_MII_CLK); 618 DELAY(10); 619 val <<= 1; 620 if (ed_asic_inb(sc, ED_DLINK_MIIBUS) & ED_DLINK_MII_DATATIN) 621 val++; 622 DLINK_MIICLR(sc, ED_DLINK_MII_CLK); 623 DELAY(10); 624 } 625 626 return val; 627} 628#endif 629 630static device_method_t ed_pccard_methods[] = { 631 /* Device interface */ 632 DEVMETHOD(device_probe, ed_pccard_probe), 633 DEVMETHOD(device_attach, ed_pccard_attach), 634 DEVMETHOD(device_detach, ed_detach), 635 636#ifndef ED_NO_MIIBUS 637 /* Bus interface */ 638 DEVMETHOD(bus_child_detached, ed_child_detached), 639 640 /* MII interface */ 641 DEVMETHOD(miibus_readreg, ed_miibus_readreg), 642 DEVMETHOD(miibus_writereg, ed_miibus_writereg), 643#endif 644 645 { 0, 0 } 646}; 647 648static driver_t ed_pccard_driver = { 649 "ed", 650 ed_pccard_methods, 651 sizeof(struct ed_softc) 652}; 653 654DRIVER_MODULE(ed, pccard, ed_pccard_driver, ed_devclass, 0, 0); 655#ifndef ED_NO_MIIBUS 656DRIVER_MODULE(miibus, ed, miibus_driver, miibus_devclass, 0, 0); 657#endif 658