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