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