Home | History | Annotate | Line # | Download | only in pcmcia
mhzc.c revision 1.2.2.1
      1 /*	$NetBSD: mhzc.c,v 1.2.2.1 1999/10/20 22:38:06 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999 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/ic/smc91cxxreg.h>
     93 #include <dev/ic/smc91cxxvar.h>
     94 
     95 #include <dev/pcmcia/pcmciareg.h>
     96 #include <dev/pcmcia/pcmciavar.h>
     97 #include <dev/pcmcia/pcmciadevs.h>
     98 
     99 #include "mhzc.h"
    100 
    101 struct mhzc_softc {
    102 	struct device sc_dev;		/* generic device glue */
    103 
    104 	struct pcmcia_function *sc_pf;	/* our PCMCIA function */
    105 	void *sc_ih;			/* interrupt handle */
    106 
    107 	const struct mhzc_product *sc_product;
    108 
    109 	/*
    110 	 * Data for the Modem portion.
    111 	 */
    112 	struct device *sc_modem;
    113 	struct pcmcia_io_handle sc_modem_pcioh;
    114 	int sc_modem_io_window;
    115 
    116 	/*
    117 	 * Data for the Ethernet portion.
    118 	 */
    119 	struct device *sc_ethernet;
    120 	struct pcmcia_io_handle sc_ethernet_pcioh;
    121 	int sc_ethernet_io_window;
    122 
    123 	int sc_flags;
    124 };
    125 
    126 /* sc_flags */
    127 #define	MHZC_MODEM_MAPPED	0x01
    128 #define	MHZC_ETHERNET_MAPPED	0x02
    129 #define	MHZC_MODEM_ENABLED	0x04
    130 #define	MHZC_ETHERNET_ENABLED	0x08
    131 
    132 int	mhzc_match __P((struct device *, struct cfdata *, void *));
    133 void	mhzc_attach __P((struct device *, struct device *, void *));
    134 int	mhzc_detach __P((struct device *, int));
    135 int	mhzc_activate __P((struct device *, enum devact));
    136 
    137 struct cfattach mhzc_ca = {
    138 	sizeof(struct mhzc_softc), mhzc_match, mhzc_attach,
    139 	    mhzc_detach, mhzc_activate
    140 };
    141 
    142 int	mhzc_em3336_enaddr __P((struct mhzc_softc *, u_int8_t *));
    143 int	mhzc_em3336_enable __P((struct mhzc_softc *));
    144 
    145 struct mhzc_product {
    146 	u_int32_t	mp_vendor;	/* PCMCIA vendor ID */
    147 	u_int32_t	mp_product;	/* PCMCIA product ID */
    148 	int		mp_expfunc;	/* expected function number */
    149 	const char	*mp_name;	/* device name */
    150 
    151 	/* Get the Ethernet address for this card. */
    152 	int		(*mp_enaddr) __P((struct mhzc_softc *, u_int8_t *));
    153 
    154 	/* Perform any special `enable' magic. */
    155 	int		(*mp_enable) __P((struct mhzc_softc *));
    156 } mhzc_products[] = {
    157 	{ PCMCIA_VENDOR_MEGAHERTZ,	PCMCIA_PRODUCT_MEGAHERTZ_XJEM3336,
    158 	  0,				PCMCIA_STR_MEGAHERTZ_XJEM3336,
    159 	  mhzc_em3336_enaddr,		mhzc_em3336_enable },
    160 
    161 	/*
    162 	 * Eventually we could add support for other Ethernet/Modem
    163 	 * combo cards, even if they're aren't Megahertz, because
    164 	 * most of them work more or less the same way.
    165 	 */
    166 
    167 	{ 0,				0,
    168 	  0,				NULL,
    169 	  NULL,				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 *));
    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 const struct mhzc_product *mhzc_lookup __P((const struct pcmcia_attach_args *));
    183 
    184 const struct mhzc_product *
    185 mhzc_lookup(pa)
    186 	const struct pcmcia_attach_args *pa;
    187 {
    188 	const struct mhzc_product *mp;
    189 
    190 	for (mp = mhzc_products; mp->mp_name != NULL; mp++) {
    191 		if (pa->manufacturer == mp->mp_vendor &&
    192 		    pa->product == mp->mp_product &&
    193 		    pa->pf->number == mp->mp_expfunc)
    194 			return (mp);
    195 	}
    196 	return (NULL);
    197 }
    198 
    199 int
    200 mhzc_match(parent, match, aux)
    201 	struct device *parent;
    202 	struct cfdata *match;
    203 	void *aux;
    204 {
    205 	struct pcmcia_attach_args *pa = aux;
    206 
    207 	if (mhzc_lookup(pa) != NULL)
    208 		return (10);		/* beat `com' */
    209 
    210 	return (0);
    211 }
    212 
    213 void
    214 mhzc_attach(parent, self, aux)
    215 	struct device *parent, *self;
    216 	void *aux;
    217 {
    218 	struct mhzc_softc *sc = (void *)self;
    219 	struct pcmcia_attach_args *pa = aux;
    220 	struct pcmcia_config_entry *cfe;
    221 
    222 	sc->sc_pf = pa->pf;
    223 
    224 	sc->sc_product = mhzc_lookup(pa);
    225 	if (sc->sc_product == NULL) {
    226 		printf("\n");
    227 		panic("mhzc_attach: impossible");
    228 	}
    229 
    230 	printf(": %s\n", sc->sc_product->mp_name);
    231 
    232 	/*
    233 	 * The address decoders on these cards are wacky.  The configuration
    234 	 * entries are set up to look like serial ports, and have no
    235 	 * information about the Ethernet portion.  In order to talk to
    236 	 * the Modem portion, the I/O address must have bit 0x80 set.
    237 	 * In order to talk to the Ethernet portion, the I/O address must
    238 	 * have the 0x80 bit clear.
    239 	 *
    240 	 * The standard configuration entries conveniently have 0x80 set
    241 	 * in them, and have a length of 8 (a 16550's size, convenient!),
    242 	 * so we use those to set up the Modem portion.
    243 	 *
    244 	 * Once we have the Modem's address established, we search for
    245 	 * an address suitable for the Ethernet portion.  We do this by
    246 	 * rounding up to the next 16-byte aligned address where 0x80
    247 	 * isn't set (the SMC Ethernet chip has a 16-byte address size)
    248 	 * and attemping to allocate a 16-byte region until we succeed.
    249 	 *
    250 	 * Sure would have been nice if Megahertz had made the card a
    251 	 * proper multi-function device.
    252 	 */
    253 	for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
    254 	     cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
    255 		if (mhzc_check_cfe(sc, cfe)) {
    256 			/* Found one! */
    257 			break;
    258 		}
    259 	}
    260 	if (cfe == NULL) {
    261 		printf("%s: unable to find suitable config table entry\n",
    262 		    sc->sc_dev.dv_xname);
    263 		return;
    264 	}
    265 
    266 	if (mhzc_alloc_ethernet(sc) == 0) {
    267 		printf("%s: unable to allocate space for Ethernet portion\n",
    268 		    sc->sc_dev.dv_xname);
    269 		return;
    270 	}
    271 
    272 	/* Enable the card. */
    273 	pcmcia_function_init(pa->pf, cfe);
    274 	if (pcmcia_function_enable(pa->pf)) {
    275 		printf(": function enable failed\n");
    276 		return;
    277 	}
    278 
    279 	if (sc->sc_product->mp_enable != NULL)
    280 		(*sc->sc_product->mp_enable)(sc);
    281 
    282 	sc->sc_modem = config_found(&sc->sc_dev, "com", mhzc_print);
    283 	sc->sc_ethernet = config_found(&sc->sc_dev, "sm", mhzc_print);
    284 
    285 	pcmcia_function_disable(pa->pf);
    286 }
    287 
    288 int
    289 mhzc_check_cfe(sc, cfe)
    290 	struct mhzc_softc *sc;
    291 	struct pcmcia_config_entry *cfe;
    292 {
    293 
    294 	if (cfe->num_memspace != 0)
    295 		return (0);
    296 
    297 	if (cfe->num_iospace != 1)
    298 		return (0);
    299 
    300 	if (pcmcia_io_alloc(sc->sc_pf,
    301 	    cfe->iospace[0].start,
    302 	    cfe->iospace[0].length,
    303 	    cfe->iospace[0].length,
    304 	    &sc->sc_modem_pcioh) == 0) {
    305 		/* Found one for the modem! */
    306 		return (1);
    307 	}
    308 
    309 	return (0);
    310 }
    311 
    312 int
    313 mhzc_alloc_ethernet(sc)
    314 	struct mhzc_softc *sc;
    315 {
    316 	bus_addr_t addr, maxaddr;
    317 
    318 	maxaddr = sc->sc_pf->sc->iobase + sc->sc_pf->sc->iosize;
    319 	addr = sc->sc_pf->sc->iobase;
    320 
    321 	/*
    322 	 * Now round it up so that it starts on a 16-byte boundary.
    323 	 */
    324 	addr = roundup(addr, 0x10);
    325 
    326 	for (; (addr + 0x10) < maxaddr; addr += 0x10) {
    327 		if (addr & 0x80)
    328 			continue;
    329 		if (pcmcia_io_alloc(sc->sc_pf, addr, 0x10, 0x10,
    330 		    &sc->sc_ethernet_pcioh) == 0) {
    331 			/* Found one for the ethernet! */
    332 			return (1);
    333 		}
    334 	}
    335 
    336 	/*
    337 	 * Weren't able to allocate space for the Ethernet, so we
    338 	 * free the Modem's I/O space.
    339 	 */
    340 	pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
    341 	return (0);
    342 }
    343 
    344 int
    345 mhzc_print(aux, pnp)
    346 	void *aux;
    347 	const char *pnp;
    348 {
    349 	const char *name = aux;
    350 
    351 	if (pnp)
    352 		printf("%s at %s", name, pnp);
    353 
    354 	return (UNCONF);
    355 }
    356 
    357 int
    358 mhzc_detach(self, flags)
    359 	struct device *self;
    360 	int flags;
    361 {
    362 	struct mhzc_softc *sc = (void *)self;
    363 	int rv;
    364 
    365 	if (sc->sc_ethernet != NULL) {
    366 		rv = config_detach(sc->sc_ethernet, flags);
    367 		if (rv != 0)
    368 			return (rv);
    369 	}
    370 
    371 	if (sc->sc_modem != NULL) {
    372 		rv = config_detach(sc->sc_modem, flags);
    373 		if (rv != 0)
    374 			return (rv);
    375 	}
    376 
    377 	/* Unmap our i/o windows. */
    378 	if (sc->sc_flags & MHZC_MODEM_MAPPED)
    379 		pcmcia_io_unmap(sc->sc_pf, sc->sc_modem_io_window);
    380 	if (sc->sc_flags & MHZC_ETHERNET_MAPPED)
    381 		pcmcia_io_unmap(sc->sc_pf, sc->sc_ethernet_io_window);
    382 
    383 	/* Free our i/o spaces. */
    384 	pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
    385 	pcmcia_io_free(sc->sc_pf, &sc->sc_ethernet_pcioh);
    386 
    387 	return (0);
    388 }
    389 
    390 int
    391 mhzc_activate(self, act)
    392 	struct device *self;
    393 	enum devact act;
    394 {
    395 	struct mhzc_softc *sc = (void *)self;
    396 	int s, rv = 0;
    397 
    398 	s = splhigh();
    399 	switch (act) {
    400 	case DVACT_ACTIVATE:
    401 		rv = EOPNOTSUPP;
    402 		break;
    403 
    404 	case DVACT_DEACTIVATE:
    405 		if (sc->sc_ethernet != NULL) {
    406 			rv = config_deactivate(sc->sc_ethernet);
    407 			if (rv != 0)
    408 				goto out;
    409 		}
    410 
    411 		if (sc->sc_modem != NULL) {
    412 			rv = config_deactivate(sc->sc_modem);
    413 			if (rv != 0)
    414 				goto out;
    415 		}
    416 		break;
    417 	}
    418  out:
    419 	splx(s);
    420 	return (rv);
    421 }
    422 
    423 int
    424 mhzc_intr(arg)
    425 	void *arg;
    426 {
    427 	struct mhzc_softc *sc = arg;
    428 	int rval = 0;
    429 
    430 #if NCOM_MHZC > 0
    431 	if (sc->sc_modem != NULL &&
    432 	    (sc->sc_flags & MHZC_MODEM_ENABLED) != 0)
    433 		rval |= comintr(sc->sc_modem);
    434 #endif
    435 
    436 #if NSM_MHZC > 0
    437 	if (sc->sc_ethernet != NULL &&
    438 	    (sc->sc_flags & MHZC_ETHERNET_ENABLED) != 0)
    439 		rval |= smc91cxx_intr(sc->sc_ethernet);
    440 #endif
    441 
    442 	return (rval);
    443 }
    444 
    445 int
    446 mhzc_enable(sc, flag)
    447 	struct mhzc_softc *sc;
    448 	int flag;
    449 {
    450 
    451 	if (sc->sc_flags & flag) {
    452 		printf("%s: %s already enabled\n", sc->sc_dev.dv_xname,
    453 		    (flag & MHZC_MODEM_ENABLED) ? "modem" : "ethernet");
    454 		panic("mhzc_enable");
    455 	}
    456 
    457 	if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0) {
    458 		sc->sc_flags |= flag;
    459 		return (0);
    460 	}
    461 
    462 	/*
    463 	 * Establish our interrupt handler.
    464 	 *
    465 	 * XXX Note, we establish this at IPL_NET.  This is suboptimal
    466 	 * XXX the Modem portion, but is necessary to make the Ethernet
    467 	 * XXX portion have the correct interrupt level semantics.
    468 	 *
    469 	 * XXX Eventually we should use the `enabled' bits in the
    470 	 * XXX flags word to determine which level we should be at.
    471 	 */
    472 	sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET,
    473 	    mhzc_intr, sc);
    474 	if (sc->sc_ih == NULL) {
    475 		printf("%s: unable to establish interrupt\n",
    476 		    sc->sc_dev.dv_xname);
    477 		return (1);
    478 	}
    479 
    480 	if (pcmcia_function_enable(sc->sc_pf)) {
    481 		pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    482 		return (1);
    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: %s already disabled\n", sc->sc_dev.dv_xname,
    507 		    (flag & MHZC_MODEM_ENABLED) ? "modem" : "ethernet");
    508 		panic("mhzc_disable");
    509 	}
    510 
    511 	sc->sc_flags &= ~flag;
    512 	if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0)
    513 		return;
    514 
    515 	pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    516 	pcmcia_function_disable(sc->sc_pf);
    517 }
    518 
    519 /*****************************************************************************
    520  * Megahertz EM3336 (and compatibles) support
    521  *****************************************************************************/
    522 
    523 int	mhzc_em3336_lannid_ciscallback __P((struct pcmcia_tuple *, void *));
    524 int	mhzc_em3336_ascii_enaddr __P((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_addr_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 	delay(200000);
    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 __P((struct device *, struct cfdata *, void *));
    664 void	com_mhzc_attach __P((struct device *, struct device *, void *));
    665 
    666 /* No mhzc-specific goo in the softc; it's all in the parent. */
    667 struct cfattach com_mhzc_ca = {
    668 	sizeof(struct com_softc), com_mhzc_match, com_mhzc_attach,
    669 	    com_detach, com_activate
    670 };
    671 
    672 int	com_mhzc_enable __P((struct com_softc *));
    673 void	com_mhzc_disable __P((struct com_softc *));
    674 
    675 int
    676 com_mhzc_match(parent, match, aux)
    677 	struct device *parent;
    678 	struct cfdata *match;
    679 	void *aux;
    680 {
    681 	extern struct cfdriver com_cd;
    682 	const char *name = aux;
    683 
    684 	/* Device is always present. */
    685 	if (strcmp(name, com_cd.cd_name) == 0)
    686 		return (1);
    687 
    688 	return (0);
    689 }
    690 
    691 void
    692 com_mhzc_attach(parent, self, aux)
    693 	struct device *parent, *self;
    694 	void *aux;
    695 {
    696 	struct com_softc *sc = (void *)self;
    697 	struct mhzc_softc *msc = (void *)parent;
    698 
    699 	printf(":");
    700 	if (pcmcia_io_map(msc->sc_pf, PCMCIA_WIDTH_IO8, 0,
    701 	    msc->sc_modem_pcioh.size, &msc->sc_modem_pcioh,
    702 	    &msc->sc_modem_io_window)) {
    703 		printf("unable to map I/O space\n");
    704 		return;
    705 	}
    706 
    707 	msc->sc_flags |= MHZC_MODEM_MAPPED;
    708 
    709 	sc->sc_iot = msc->sc_modem_pcioh.iot;
    710 	sc->sc_ioh = msc->sc_modem_pcioh.ioh;
    711 
    712 	sc->enabled = 1;
    713 
    714 	sc->sc_iobase = -1;
    715 	sc->sc_frequency = COM_FREQ;
    716 
    717 	sc->enable = com_mhzc_enable;
    718 	sc->disable = com_mhzc_disable;
    719 
    720 	com_attach_subr(sc);
    721 
    722 	sc->enabled = 0;
    723 }
    724 
    725 int
    726 com_mhzc_enable(sc)
    727 	struct com_softc *sc;
    728 {
    729 
    730 	return (mhzc_enable((struct mhzc_softc *)sc->sc_dev.dv_parent,
    731 	    MHZC_MODEM_ENABLED));
    732 }
    733 
    734 void
    735 com_mhzc_disable(sc)
    736 	struct com_softc *sc;
    737 {
    738 
    739 	mhzc_disable((struct mhzc_softc *)sc->sc_dev.dv_parent,
    740 	    MHZC_MODEM_ENABLED);
    741 }
    742 
    743 #endif /* NCOM_MHZC > 0 */
    744 
    745 /****** Here begins the sm attachment code. ******/
    746 
    747 #if NSM_MHZC > 0
    748 int	sm_mhzc_match __P((struct device *, struct cfdata *, void *));
    749 void	sm_mhzc_attach __P((struct device *, struct device *, void *));
    750 int	sm_mhzc_detach __P((struct device *, int));
    751 
    752 /* No mhzc-specific goo in the softc; it's all in the parent. */
    753 struct cfattach sm_mhzc_ca = {
    754 	sizeof(struct smc91cxx_softc), sm_mhzc_match, sm_mhzc_attach,
    755 	    sm_mhzc_detach, smc91cxx_activate
    756 };
    757 
    758 int	sm_mhzc_enable __P((struct smc91cxx_softc *));
    759 void	sm_mhzc_disable __P((struct smc91cxx_softc *));
    760 
    761 int
    762 sm_mhzc_match(parent, match, aux)
    763 	struct device *parent;
    764 	struct cfdata *match;
    765 	void *aux;
    766 {
    767 	extern struct cfdriver sm_cd;
    768 	const char *name = aux;
    769 
    770 	/* Device is always present. */
    771 	if (strcmp(name, sm_cd.cd_name) == 0)
    772 		return (1);
    773 
    774 	return (0);
    775 }
    776 
    777 void
    778 sm_mhzc_attach(parent, self, aux)
    779 	struct device *parent, *self;
    780 	void *aux;
    781 {
    782 	struct smc91cxx_softc *sc = (void *)self;
    783 	struct mhzc_softc *msc = (void *)parent;
    784 	u_int8_t myla[ETHER_ADDR_LEN];
    785 
    786 	printf(":");
    787 	if (pcmcia_io_map(msc->sc_pf, PCMCIA_WIDTH_IO16, 0,
    788 	    msc->sc_ethernet_pcioh.size, &msc->sc_ethernet_pcioh,
    789 	    &msc->sc_ethernet_io_window)) {
    790 		printf("unable to map I/O space\n");
    791 		return;
    792 	}
    793 	printf("\n");
    794 
    795 	msc->sc_flags |= MHZC_ETHERNET_MAPPED;
    796 
    797 	sc->sc_bst = msc->sc_ethernet_pcioh.iot;
    798 	sc->sc_bsh = msc->sc_ethernet_pcioh.ioh;
    799 
    800 	sc->sc_enable = sm_mhzc_enable;
    801 	sc->sc_disable = sm_mhzc_disable;
    802 
    803 	if ((*msc->sc_product->mp_enaddr)(msc, myla) != 1)
    804 		return;
    805 
    806 	/* Perform generic initialization. */
    807 	smc91cxx_attach(sc, myla);
    808 }
    809 
    810 int
    811 sm_mhzc_detach(self, flags)
    812 	struct device *self;
    813 	int flags;
    814 {
    815 #ifdef notyet
    816 	struct smc91cxx_softc *sc = (void *)self;
    817 
    818 	/*
    819 	 * Our softc is about to go away, so drop our reference
    820 	 * to the ifnet.
    821 	 */
    822 	if_delref(sc->sc_ec.ec_if);
    823 	return (0);
    824 #else
    825 	return (EBUSY);
    826 #endif
    827 }
    828 
    829 int
    830 sm_mhzc_enable(sc)
    831 	struct smc91cxx_softc *sc;
    832 {
    833 
    834 	return (mhzc_enable((struct mhzc_softc *)sc->sc_dev.dv_parent,
    835 	    MHZC_ETHERNET_ENABLED));
    836 }
    837 
    838 void
    839 sm_mhzc_disable(sc)
    840 	struct smc91cxx_softc *sc;
    841 {
    842 
    843 	mhzc_disable((struct mhzc_softc *)sc->sc_dev.dv_parent,
    844 	    MHZC_ETHERNET_ENABLED);
    845 }
    846 
    847 #endif /* NSM_MHZC > 0 */
    848