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