1 /* $NetBSD: mhzc.c,v 1.34 2005/12/11 12:23:23 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 1999, 2000, 2004 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 by Charles M. Hannum. 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 the Megaherz X-JACK Ethernet/Modem combo cards. 42 * 43 * Many thanks to Chuck Cranor for having the patience to sift through 44 * the Linux smc91c92_cs.c driver to find the magic details to get this 45 * working! 46 */ 47 48 #include <sys/cdefs.h> 49 __KERNEL_RCSID(0, "$NetBSD: mhzc.c,v 1.34 2005/12/11 12:23:23 christos Exp $"); 50 51 #include "opt_inet.h" 52 #include "opt_ns.h" 53 #include "bpfilter.h" 54 55 #include <sys/param.h> 56 #include <sys/systm.h> 57 #include <sys/mbuf.h> 58 #include <sys/socket.h> 59 #include <sys/ioctl.h> 60 #include <sys/errno.h> 61 #include <sys/syslog.h> 62 #include <sys/select.h> 63 #include <sys/tty.h> 64 #include <sys/device.h> 65 #include <sys/kernel.h> 66 #include <sys/proc.h> 67 68 #include <net/if.h> 69 #include <net/if_dl.h> 70 #include <net/if_ether.h> 71 #include <net/if_media.h> 72 73 #ifdef INET 74 #include <netinet/in.h> 75 #include <netinet/in_systm.h> 76 #include <netinet/in_var.h> 77 #include <netinet/ip.h> 78 #include <netinet/if_inarp.h> 79 #endif 80 81 #ifdef NS 82 #include <netns/ns.h> 83 #include <netns/ns_if.h> 84 #endif 85 86 #if NBPFILTER > 0 87 #include <net/bpf.h> 88 #include <net/bpfdesc.h> 89 #endif 90 91 #include <machine/intr.h> 92 #include <machine/bus.h> 93 94 #include <dev/ic/comreg.h> 95 #include <dev/ic/comvar.h> 96 97 #include <dev/mii/mii.h> 98 #include <dev/mii/miivar.h> 99 100 #include <dev/ic/smc91cxxreg.h> 101 #include <dev/ic/smc91cxxvar.h> 102 103 #include <dev/pcmcia/pcmciareg.h> 104 #include <dev/pcmcia/pcmciavar.h> 105 #include <dev/pcmcia/pcmciadevs.h> 106 107 #include "mhzc.h" 108 109 struct mhzc_softc { 110 struct device sc_dev; /* generic device glue */ 111 112 struct pcmcia_function *sc_pf; /* our PCMCIA function */ 113 void *sc_ih; /* interrupt handle */ 114 115 const struct mhzc_product *sc_product; 116 117 /* 118 * Data for the Modem portion. 119 */ 120 struct device *sc_modem; 121 struct pcmcia_io_handle sc_modem_pcioh; 122 int sc_modem_io_window; 123 124 /* 125 * Data for the Ethernet portion. 126 */ 127 struct device *sc_ethernet; 128 struct pcmcia_io_handle sc_ethernet_pcioh; 129 int sc_ethernet_io_window; 130 131 int sc_flags; 132 }; 133 134 /* sc_flags */ 135 #define MHZC_MODEM_MAPPED 0x01 136 #define MHZC_ETHERNET_MAPPED 0x02 137 #define MHZC_MODEM_ENABLED 0x04 138 #define MHZC_ETHERNET_ENABLED 0x08 139 #define MHZC_MODEM_ALLOCED 0x10 140 #define MHZC_ETHERNET_ALLOCED 0x20 141 142 int mhzc_match(struct device *, struct cfdata *, void *); 143 void mhzc_attach(struct device *, struct device *, void *); 144 int mhzc_detach(struct device *, int); 145 int mhzc_activate(struct device *, enum devact); 146 147 CFATTACH_DECL(mhzc, sizeof(struct mhzc_softc), 148 mhzc_match, mhzc_attach, mhzc_detach, mhzc_activate); 149 150 int mhzc_em3336_enaddr(struct mhzc_softc *, u_int8_t *); 151 int mhzc_em3336_enable(struct mhzc_softc *); 152 153 const struct mhzc_product { 154 struct pcmcia_product mp_product; 155 156 /* Get the Ethernet address for this card. */ 157 int (*mp_enaddr)(struct mhzc_softc *, u_int8_t *); 158 159 /* Perform any special `enable' magic. */ 160 int (*mp_enable)(struct mhzc_softc *); 161 } mhzc_products[] = { 162 { { PCMCIA_VENDOR_MEGAHERTZ, PCMCIA_PRODUCT_MEGAHERTZ_EM3336, 163 PCMCIA_CIS_INVALID }, 164 mhzc_em3336_enaddr, mhzc_em3336_enable }, 165 }; 166 static const size_t mhzc_nproducts = 167 sizeof(mhzc_products) / sizeof(mhzc_products[0]); 168 169 int mhzc_print(void *, const char *); 170 171 int mhzc_check_cfe(struct mhzc_softc *, struct pcmcia_config_entry *); 172 int mhzc_alloc_ethernet(struct mhzc_softc *, struct pcmcia_config_entry *); 173 174 int mhzc_enable(struct mhzc_softc *, int); 175 void mhzc_disable(struct mhzc_softc *, int); 176 177 int mhzc_intr(void *); 178 179 int 180 mhzc_match(parent, match, aux) 181 struct device *parent; 182 struct cfdata *match; 183 void *aux; 184 { 185 struct pcmcia_attach_args *pa = aux; 186 187 if (pcmcia_product_lookup(pa, mhzc_products, mhzc_nproducts, 188 sizeof(mhzc_products[0]), NULL)) 189 return (2); /* beat `com' */ 190 return (0); 191 } 192 193 void 194 mhzc_attach(parent, self, aux) 195 struct device *parent, *self; 196 void *aux; 197 { 198 struct mhzc_softc *sc = (void *)self; 199 struct pcmcia_attach_args *pa = aux; 200 struct pcmcia_config_entry *cfe; 201 int error; 202 203 sc->sc_pf = pa->pf; 204 205 sc->sc_product = pcmcia_product_lookup(pa, mhzc_products, 206 mhzc_nproducts, sizeof(mhzc_products[0]), NULL); 207 if (!sc->sc_product) 208 panic("mhzc_attach: impossible"); 209 210 /* 211 * The address decoders on these cards are wacky. The configuration 212 * entries are set up to look like serial ports, and have no 213 * information about the Ethernet portion. In order to talk to 214 * the Modem portion, the I/O address must have bit 0x80 set. 215 * In order to talk to the Ethernet portion, the I/O address must 216 * have the 0x80 bit clear. 217 * 218 * The standard configuration entries conveniently have 0x80 set 219 * in them, and have a length of 8 (a 16550's size, convenient!), 220 * so we use those to set up the Modem portion. 221 * 222 * Once we have the Modem's address established, we search for 223 * an address suitable for the Ethernet portion. We do this by 224 * rounding up to the next 16-byte aligned address where 0x80 225 * isn't set (the SMC Ethernet chip has a 16-byte address size) 226 * and attemping to allocate a 16-byte region until we succeed. 227 * 228 * Sure would have been nice if Megahertz had made the card a 229 * proper multi-function device. 230 */ 231 SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) { 232 if (mhzc_check_cfe(sc, cfe)) { 233 /* Found one! */ 234 break; 235 } 236 } 237 if (cfe == NULL) { 238 aprint_error("%s: unable to find suitable config table entry\n", 239 self->dv_xname); 240 goto fail; 241 } 242 243 if (mhzc_alloc_ethernet(sc, cfe) == 0) { 244 aprint_error("%s: unable to allocate space for Ethernet portion\n", 245 self->dv_xname); 246 goto fail; 247 } 248 249 /* Enable the card. */ 250 pcmcia_function_init(pa->pf, cfe); 251 252 if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_IO8, &sc->sc_modem_pcioh, 253 &sc->sc_modem_io_window)) { 254 aprint_error("%s: unable to map I/O space\n", 255 sc->sc_dev.dv_xname); 256 goto fail; 257 } 258 sc->sc_flags |= MHZC_MODEM_MAPPED; 259 260 if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_AUTO, &sc->sc_ethernet_pcioh, 261 &sc->sc_ethernet_io_window)) { 262 aprint_error("%s: unable to map I/O space\n", 263 sc->sc_dev.dv_xname); 264 goto fail; 265 } 266 sc->sc_flags |= MHZC_ETHERNET_MAPPED; 267 268 error = mhzc_enable(sc, MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED); 269 if (error) 270 goto fail; 271 272 /*XXXUNCONST*/ 273 sc->sc_modem = config_found(self, __UNCONST("com"), mhzc_print); 274 /*XXXUNCONST*/ 275 sc->sc_ethernet = config_found(self, __UNCONST("sm"), mhzc_print); 276 277 mhzc_disable(sc, MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED); 278 return; 279 280 fail: 281 /* I/O spaces will be freed by detach. */ 282 ; 283 } 284 285 int 286 mhzc_check_cfe(sc, cfe) 287 struct mhzc_softc *sc; 288 struct pcmcia_config_entry *cfe; 289 { 290 291 if (cfe->num_memspace != 0) 292 return (0); 293 294 if (cfe->num_iospace != 1) 295 return (0); 296 297 if (pcmcia_io_alloc(sc->sc_pf, 298 cfe->iospace[0].start, 299 cfe->iospace[0].length, 300 cfe->iospace[0].length, 301 &sc->sc_modem_pcioh) == 0) { 302 /* Found one for the modem! */ 303 sc->sc_flags |= MHZC_MODEM_ALLOCED; 304 return (1); 305 } 306 307 return (0); 308 } 309 310 int 311 mhzc_alloc_ethernet(sc, cfe) 312 struct mhzc_softc *sc; 313 struct pcmcia_config_entry *cfe; 314 { 315 bus_addr_t addr, maxaddr; 316 317 addr = cfe->iospace[0].start + cfe->iospace[0].length; 318 maxaddr = 0x1000; 319 320 /* 321 * Now round it up so that it starts on a 16-byte boundary. 322 */ 323 addr = roundup(addr, 0x10); 324 325 for (; (addr + 0x10) < maxaddr; addr += 0x10) { 326 if (addr & 0x80) 327 continue; 328 if (pcmcia_io_alloc(sc->sc_pf, addr, 0x10, 0x10, 329 &sc->sc_ethernet_pcioh) == 0) { 330 /* Found one for the ethernet! */ 331 sc->sc_flags |= MHZC_ETHERNET_ALLOCED; 332 return (1); 333 } 334 } 335 336 return (0); 337 } 338 339 int 340 mhzc_print(aux, pnp) 341 void *aux; 342 const char *pnp; 343 { 344 const char *name = aux; 345 346 if (pnp) 347 aprint_normal("%s at %s(*)", name, pnp); 348 349 return (UNCONF); 350 } 351 352 int 353 mhzc_detach(self, flags) 354 struct device *self; 355 int flags; 356 { 357 struct mhzc_softc *sc = (void *)self; 358 int rv; 359 360 if (sc->sc_ethernet != NULL) { 361 rv = config_detach(sc->sc_ethernet, flags); 362 if (rv != 0) 363 return (rv); 364 sc->sc_ethernet = NULL; 365 } 366 367 if (sc->sc_modem != NULL) { 368 rv = config_detach(sc->sc_modem, flags); 369 if (rv != 0) 370 return (rv); 371 sc->sc_modem = NULL; 372 } 373 374 /* Unmap our i/o windows. */ 375 if (sc->sc_flags & MHZC_MODEM_MAPPED) 376 pcmcia_io_unmap(sc->sc_pf, sc->sc_modem_io_window); 377 if (sc->sc_flags & MHZC_ETHERNET_MAPPED) 378 pcmcia_io_unmap(sc->sc_pf, sc->sc_ethernet_io_window); 379 380 /* Free our i/o spaces. */ 381 if (sc->sc_flags & MHZC_ETHERNET_ALLOCED) 382 pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh); 383 if (sc->sc_flags & MHZC_MODEM_ALLOCED) 384 pcmcia_io_free(sc->sc_pf, &sc->sc_ethernet_pcioh); 385 386 sc->sc_flags = 0; 387 388 return (0); 389 } 390 391 int 392 mhzc_activate(self, act) 393 struct device *self; 394 enum devact act; 395 { 396 struct mhzc_softc *sc = (void *)self; 397 int s, rv = 0; 398 399 s = splhigh(); 400 switch (act) { 401 case DVACT_ACTIVATE: 402 rv = EOPNOTSUPP; 403 break; 404 405 case DVACT_DEACTIVATE: 406 if (sc->sc_ethernet != NULL) { 407 rv = config_deactivate(sc->sc_ethernet); 408 if (rv != 0) 409 goto out; 410 } 411 412 if (sc->sc_modem != NULL) { 413 rv = config_deactivate(sc->sc_modem); 414 if (rv != 0) 415 goto out; 416 } 417 break; 418 } 419 out: 420 splx(s); 421 return (rv); 422 } 423 424 int 425 mhzc_intr(arg) 426 void *arg; 427 { 428 struct mhzc_softc *sc = arg; 429 int rval = 0; 430 431 #if NCOM_MHZC > 0 432 if (sc->sc_modem != NULL && 433 (sc->sc_flags & MHZC_MODEM_ENABLED) != 0) 434 rval |= comintr(sc->sc_modem); 435 #endif 436 437 #if NSM_MHZC > 0 438 if (sc->sc_ethernet != NULL && 439 (sc->sc_flags & MHZC_ETHERNET_ENABLED) != 0) 440 rval |= smc91cxx_intr(sc->sc_ethernet); 441 #endif 442 443 return (rval); 444 } 445 446 int 447 mhzc_enable(sc, flag) 448 struct mhzc_softc *sc; 449 int flag; 450 { 451 int error; 452 453 if ((sc->sc_flags & flag) == flag) { 454 printf("%s: already enabled\n", sc->sc_dev.dv_xname); 455 return (0); 456 } 457 458 if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0) { 459 sc->sc_flags |= flag; 460 return (0); 461 } 462 463 /* 464 * Establish our interrupt handler. 465 * 466 * XXX Note, we establish this at IPL_NET. This is suboptimal 467 * XXX the Modem portion, but is necessary to make the Ethernet 468 * XXX portion have the correct interrupt level semantics. 469 * 470 * XXX Eventually we should use the `enabled' bits in the 471 * XXX flags word to determine which level we should be at. 472 */ 473 sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET, 474 mhzc_intr, sc); 475 if (!sc->sc_ih) 476 return (EIO); 477 478 error = pcmcia_function_enable(sc->sc_pf); 479 if (error) { 480 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih); 481 sc->sc_ih = 0; 482 return (error); 483 } 484 485 /* 486 * Perform any special enable magic necessary. 487 */ 488 if (sc->sc_product->mp_enable != NULL && 489 (*sc->sc_product->mp_enable)(sc) != 0) { 490 pcmcia_function_disable(sc->sc_pf); 491 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih); 492 return (1); 493 } 494 495 sc->sc_flags |= flag; 496 return (0); 497 } 498 499 void 500 mhzc_disable(sc, flag) 501 struct mhzc_softc *sc; 502 int flag; 503 { 504 505 if ((sc->sc_flags & flag) == 0) { 506 printf("%s: already disabled\n", sc->sc_dev.dv_xname); 507 return; 508 } 509 510 sc->sc_flags &= ~flag; 511 if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0) 512 return; 513 514 pcmcia_function_disable(sc->sc_pf); 515 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih); 516 sc->sc_ih = 0; 517 } 518 519 /***************************************************************************** 520 * Megahertz EM3336 (and compatibles) support 521 *****************************************************************************/ 522 523 int mhzc_em3336_lannid_ciscallback(struct pcmcia_tuple *, void *); 524 int mhzc_em3336_ascii_enaddr(const char *cisstr, u_int8_t *); 525 526 int 527 mhzc_em3336_enaddr(sc, myla) 528 struct mhzc_softc *sc; 529 u_int8_t *myla; 530 { 531 532 /* Get the station address from CIS tuple 0x81. */ 533 if (pcmcia_scan_cis(sc->sc_dev.dv_parent, 534 mhzc_em3336_lannid_ciscallback, myla) != 1) { 535 printf("%s: unable to get Ethernet address from CIS\n", 536 sc->sc_dev.dv_xname); 537 return (0); 538 } 539 540 return (1); 541 } 542 543 int 544 mhzc_em3336_enable(sc) 545 struct mhzc_softc *sc; 546 { 547 struct pcmcia_mem_handle memh; 548 bus_size_t memoff; 549 int memwin, reg; 550 551 /* 552 * Bring the chip to live by touching its registers in the correct 553 * way (as per my reference... the Linux smc91c92_cs.c driver by 554 * David A. Hinds). 555 */ 556 557 /* Map the ISRPOWEREG. */ 558 if (pcmcia_mem_alloc(sc->sc_pf, 0x1000, &memh) != 0) { 559 printf("%s: unable to allocate memory space\n", 560 sc->sc_dev.dv_xname); 561 return (1); 562 } 563 564 if (pcmcia_mem_map(sc->sc_pf, PCMCIA_MEM_ATTR, 0, 0x1000, 565 &memh, &memoff, &memwin)) { 566 printf("%s: unable to map memory space\n", 567 sc->sc_dev.dv_xname); 568 pcmcia_mem_free(sc->sc_pf, &memh); 569 return (1); 570 } 571 572 /* 573 * The magic sequence: 574 * 575 * - read/write the CCR option register. 576 * - read the ISRPOWEREG 2 times. 577 * - read/write the CCR option register again. 578 */ 579 580 reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION); 581 pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg); 582 583 reg = bus_space_read_1(memh.memt, memh.memh, 0x380); 584 delay(5); 585 reg = bus_space_read_1(memh.memt, memh.memh, 0x380); 586 587 tsleep(&mhzc_em3336_enable, PWAIT, "mhz3en", hz * 200 / 1000); 588 589 reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION); 590 delay(5); 591 pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg); 592 593 pcmcia_mem_unmap(sc->sc_pf, memwin); 594 pcmcia_mem_free(sc->sc_pf, &memh); 595 596 return (0); 597 } 598 599 int 600 mhzc_em3336_lannid_ciscallback(tuple, arg) 601 struct pcmcia_tuple *tuple; 602 void *arg; 603 { 604 u_int8_t *myla = arg, addr_str[ETHER_ADDR_LEN * 2]; 605 int i; 606 607 if (tuple->code == 0x81) { 608 /* 609 * We have a string-encoded address. Length includes 610 * terminating 0xff. 611 */ 612 if (tuple->length != (ETHER_ADDR_LEN * 2) + 1) 613 return (0); 614 615 for (i = 0; i < tuple->length - 1; i++) 616 addr_str[i] = pcmcia_tuple_read_1(tuple, i); 617 618 /* 619 * Decode the string into `myla'. 620 */ 621 return (mhzc_em3336_ascii_enaddr(addr_str, myla)); 622 } 623 return (0); 624 } 625 626 /* XXX This should be shared w/ if_sm_pcmcia.c */ 627 int 628 mhzc_em3336_ascii_enaddr(cisstr, myla) 629 const char *cisstr; 630 u_int8_t *myla; 631 { 632 u_int8_t digit; 633 int i; 634 635 memset(myla, 0, ETHER_ADDR_LEN); 636 637 for (i = 0, digit = 0; i < (ETHER_ADDR_LEN * 2); i++) { 638 if (cisstr[i] >= '0' && cisstr[i] <= '9') 639 digit |= cisstr[i] - '0'; 640 else if (cisstr[i] >= 'a' && cisstr[i] <= 'f') 641 digit |= (cisstr[i] - 'a') + 10; 642 else if (cisstr[i] >= 'A' && cisstr[i] <= 'F') 643 digit |= (cisstr[i] - 'A') + 10; 644 else { 645 /* Bogus digit!! */ 646 return (0); 647 } 648 649 /* Compensate for ordering of digits. */ 650 if (i & 1) { 651 myla[i >> 1] = digit; 652 digit = 0; 653 } else 654 digit <<= 4; 655 } 656 657 return (1); 658 } 659 660 /****** Here begins the com attachment code. ******/ 661 662 #if NCOM_MHZC > 0 663 int com_mhzc_match(struct device *, struct cfdata *, void *); 664 void com_mhzc_attach(struct device *, struct device *, void *); 665 int com_mhzc_detach(struct device *, int); 666 667 /* No mhzc-specific goo in the softc; it's all in the parent. */ 668 CFATTACH_DECL(com_mhzc, sizeof(struct com_softc), 669 com_mhzc_match, com_mhzc_attach, com_detach, com_activate); 670 671 int com_mhzc_enable(struct com_softc *); 672 void com_mhzc_disable(struct com_softc *); 673 674 int 675 com_mhzc_match(parent, match, aux) 676 struct device *parent; 677 struct cfdata *match; 678 void *aux; 679 { 680 extern struct cfdriver com_cd; 681 const char *name = aux; 682 683 /* Device is always present. */ 684 if (strcmp(name, com_cd.cd_name) == 0) 685 return (1); 686 687 return (0); 688 } 689 690 void 691 com_mhzc_attach(parent, self, aux) 692 struct device *parent, *self; 693 void *aux; 694 { 695 struct com_softc *sc = (void *)self; 696 struct mhzc_softc *msc = (void *)parent; 697 698 aprint_normal("\n"); 699 700 sc->sc_iot = msc->sc_modem_pcioh.iot; 701 sc->sc_ioh = msc->sc_modem_pcioh.ioh; 702 703 sc->enabled = 1; 704 705 sc->sc_iobase = -1; 706 sc->sc_frequency = COM_FREQ; 707 708 sc->enable = com_mhzc_enable; 709 sc->disable = com_mhzc_disable; 710 711 aprint_normal("%s", sc->sc_dev.dv_xname); 712 713 com_attach_subr(sc); 714 715 sc->enabled = 0; 716 } 717 718 int 719 com_mhzc_enable(sc) 720 struct com_softc *sc; 721 { 722 723 return (mhzc_enable((struct mhzc_softc *)sc->sc_dev.dv_parent, 724 MHZC_MODEM_ENABLED)); 725 } 726 727 void 728 com_mhzc_disable(sc) 729 struct com_softc *sc; 730 { 731 732 mhzc_disable((struct mhzc_softc *)sc->sc_dev.dv_parent, 733 MHZC_MODEM_ENABLED); 734 } 735 736 #endif /* NCOM_MHZC > 0 */ 737 738 /****** Here begins the sm attachment code. ******/ 739 740 #if NSM_MHZC > 0 741 int sm_mhzc_match(struct device *, struct cfdata *, void *); 742 void sm_mhzc_attach(struct device *, struct device *, void *); 743 744 /* No mhzc-specific goo in the softc; it's all in the parent. */ 745 CFATTACH_DECL(sm_mhzc, sizeof(struct smc91cxx_softc), 746 sm_mhzc_match, sm_mhzc_attach, smc91cxx_detach, smc91cxx_activate); 747 748 int sm_mhzc_enable(struct smc91cxx_softc *); 749 void sm_mhzc_disable(struct smc91cxx_softc *); 750 751 int 752 sm_mhzc_match(parent, match, aux) 753 struct device *parent; 754 struct cfdata *match; 755 void *aux; 756 { 757 extern struct cfdriver sm_cd; 758 const char *name = aux; 759 760 /* Device is always present. */ 761 if (strcmp(name, sm_cd.cd_name) == 0) 762 return (1); 763 764 return (0); 765 } 766 767 void 768 sm_mhzc_attach(parent, self, aux) 769 struct device *parent, *self; 770 void *aux; 771 { 772 struct smc91cxx_softc *sc = (void *)self; 773 struct mhzc_softc *msc = (void *)parent; 774 u_int8_t myla[ETHER_ADDR_LEN]; 775 776 aprint_normal("\n"); 777 778 sc->sc_bst = msc->sc_ethernet_pcioh.iot; 779 sc->sc_bsh = msc->sc_ethernet_pcioh.ioh; 780 781 sc->sc_enable = sm_mhzc_enable; 782 sc->sc_disable = sm_mhzc_disable; 783 784 if ((*msc->sc_product->mp_enaddr)(msc, myla) != 1) 785 return; 786 787 /* Perform generic initialization. */ 788 smc91cxx_attach(sc, myla); 789 } 790 791 int 792 sm_mhzc_enable(sc) 793 struct smc91cxx_softc *sc; 794 { 795 796 return (mhzc_enable((struct mhzc_softc *)sc->sc_dev.dv_parent, 797 MHZC_ETHERNET_ENABLED)); 798 } 799 800 void 801 sm_mhzc_disable(sc) 802 struct smc91cxx_softc *sc; 803 { 804 805 mhzc_disable((struct mhzc_softc *)sc->sc_dev.dv_parent, 806 MHZC_ETHERNET_ENABLED); 807 } 808 809 #endif /* NSM_MHZC > 0 */ 810