Home | History | Annotate | Line # | Download | only in pcmcia
mhzc.c revision 1.53
      1 /*	$NetBSD: mhzc.c,v 1.53 2021/04/24 23:36:58 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.53 2021/04/24 23:36:58 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 	    CFARG_EOL);
    249 	/*XXXUNCONST*/
    250 	sc->sc_ethernet = config_found(self, __UNCONST("sm"), mhzc_print,
    251 	    CFARG_EOL);
    252 
    253 	mhzc_disable(sc, MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED);
    254 	return;
    255 
    256 fail:
    257 	/* I/O spaces will be freed by detach. */
    258 	;
    259 }
    260 
    261 int
    262 mhzc_check_cfe(struct mhzc_softc *sc, struct pcmcia_config_entry *cfe)
    263 {
    264 
    265 	if (cfe->num_memspace != 0)
    266 		return (0);
    267 
    268 	if (cfe->num_iospace != 1)
    269 		return (0);
    270 
    271 	if (pcmcia_io_alloc(sc->sc_pf,
    272 	    cfe->iospace[0].start,
    273 	    cfe->iospace[0].length,
    274 	    cfe->iospace[0].length,
    275 	    &sc->sc_modem_pcioh) == 0) {
    276 		/* Found one for the modem! */
    277 		sc->sc_flags |= MHZC_MODEM_ALLOCED;
    278 		return (1);
    279 	}
    280 
    281 	return (0);
    282 }
    283 
    284 int
    285 mhzc_alloc_ethernet(struct mhzc_softc *sc, struct pcmcia_config_entry *cfe)
    286 {
    287 	bus_addr_t addr, maxaddr;
    288 
    289 	addr = cfe->iospace[0].start + cfe->iospace[0].length;
    290 	maxaddr = 0x1000;
    291 
    292 	/*
    293 	 * Now round it up so that it starts on a 16-byte boundary.
    294 	 */
    295 	addr = roundup(addr, 0x10);
    296 
    297 	for (; (addr + 0x10) < maxaddr; addr += 0x10) {
    298 		if (addr & 0x80)
    299 			continue;
    300 		if (pcmcia_io_alloc(sc->sc_pf, addr, 0x10, 0x10,
    301 		    &sc->sc_ethernet_pcioh) == 0) {
    302 			/* Found one for the ethernet! */
    303 			sc->sc_flags |= MHZC_ETHERNET_ALLOCED;
    304 			return (1);
    305 		}
    306 	}
    307 
    308 	return (0);
    309 }
    310 
    311 int
    312 mhzc_print(void *aux, const char *pnp)
    313 {
    314 	const char *name = aux;
    315 
    316 	if (pnp)
    317 		aprint_normal("%s at %s(*)",  name, pnp);
    318 
    319 	return (UNCONF);
    320 }
    321 
    322 void
    323 mhzc_childdet(device_t self, device_t child)
    324 {
    325 	struct mhzc_softc *sc = device_private(self);
    326 
    327 	if (sc->sc_ethernet == child)
    328 		sc->sc_ethernet = NULL;
    329 	if (sc->sc_modem == child)
    330 		sc->sc_modem = NULL;
    331 }
    332 
    333 int
    334 mhzc_detach(device_t self, int flags)
    335 {
    336 	struct mhzc_softc *sc = device_private(self);
    337 	int rv;
    338 
    339 	if (sc->sc_ethernet != NULL) {
    340 		if ((rv = config_detach(sc->sc_ethernet, flags)) != 0)
    341 			return rv;
    342 	}
    343 
    344 	if (sc->sc_modem != NULL) {
    345 		if ((rv = config_detach(sc->sc_modem, flags)) != 0)
    346 			return rv;
    347 	}
    348 
    349 	/* Unmap our i/o windows. */
    350 	if (sc->sc_flags & MHZC_MODEM_MAPPED)
    351 		pcmcia_io_unmap(sc->sc_pf, sc->sc_modem_io_window);
    352 	if (sc->sc_flags & MHZC_ETHERNET_MAPPED)
    353 		pcmcia_io_unmap(sc->sc_pf, sc->sc_ethernet_io_window);
    354 
    355 	/* Free our i/o spaces. */
    356 	if (sc->sc_flags & MHZC_ETHERNET_ALLOCED)
    357 		pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
    358 	if (sc->sc_flags & MHZC_MODEM_ALLOCED)
    359 		pcmcia_io_free(sc->sc_pf, &sc->sc_ethernet_pcioh);
    360 
    361 	sc->sc_flags = 0;
    362 
    363 	return 0;
    364 }
    365 
    366 int
    367 mhzc_intr(void *arg)
    368 {
    369 	struct mhzc_softc *sc = arg;
    370 	int rval = 0;
    371 
    372 #if NCOM_MHZC > 0
    373 	if (sc->sc_modem != NULL &&
    374 	    (sc->sc_flags & MHZC_MODEM_ENABLED) != 0)
    375 		rval |= comintr(sc->sc_modem);
    376 #endif
    377 
    378 #if NSM_MHZC > 0
    379 	if (sc->sc_ethernet != NULL &&
    380 	    (sc->sc_flags & MHZC_ETHERNET_ENABLED) != 0)
    381 		rval |= smc91cxx_intr(sc->sc_ethernet);
    382 #endif
    383 
    384 	return (rval);
    385 }
    386 
    387 int
    388 mhzc_enable(struct mhzc_softc *sc, int flag)
    389 {
    390 	int error;
    391 
    392 	if ((sc->sc_flags & flag) == flag) {
    393 		printf("%s: already enabled\n", device_xname(sc->sc_dev));
    394 		return (0);
    395 	}
    396 
    397 	if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0) {
    398 		sc->sc_flags |= flag;
    399 		return (0);
    400 	}
    401 
    402 	/*
    403 	 * Establish our interrupt handler.
    404 	 *
    405 	 * XXX Note, we establish this at IPL_NET.  This is suboptimal
    406 	 * XXX the Modem portion, but is necessary to make the Ethernet
    407 	 * XXX portion have the correct interrupt level semantics.
    408 	 *
    409 	 * XXX Eventually we should use the `enabled' bits in the
    410 	 * XXX flags word to determine which level we should be at.
    411 	 */
    412 	sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET,
    413 	    mhzc_intr, sc);
    414 	if (!sc->sc_ih)
    415 		return (EIO);
    416 
    417 	error = pcmcia_function_enable(sc->sc_pf);
    418 	if (error) {
    419 		pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    420 		sc->sc_ih = 0;
    421 		return (error);
    422 	}
    423 
    424 	/*
    425 	 * Perform any special enable magic necessary.
    426 	 */
    427 	if (sc->sc_product->mp_enable != NULL &&
    428 	    (*sc->sc_product->mp_enable)(sc) != 0) {
    429 		pcmcia_function_disable(sc->sc_pf);
    430 		pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    431 		return (1);
    432 	}
    433 
    434 	sc->sc_flags |= flag;
    435 	return (0);
    436 }
    437 
    438 void
    439 mhzc_disable(struct mhzc_softc *sc, int flag)
    440 {
    441 
    442 	if ((sc->sc_flags & flag) == 0) {
    443 		printf("%s: already disabled\n", device_xname(sc->sc_dev));
    444 		return;
    445 	}
    446 
    447 	sc->sc_flags &= ~flag;
    448 	if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0)
    449 		return;
    450 
    451 	pcmcia_function_disable(sc->sc_pf);
    452 	pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    453 	sc->sc_ih = 0;
    454 }
    455 
    456 /*****************************************************************************
    457  * Megahertz EM3336 (and compatibles) support
    458  *****************************************************************************/
    459 
    460 int	mhzc_em3336_lannid_ciscallback(struct pcmcia_tuple *, void *);
    461 int	mhzc_em3336_ascii_enaddr(const char *cisstr, u_int8_t *);
    462 
    463 int
    464 mhzc_em3336_enaddr(struct mhzc_softc *sc, u_int8_t *myla)
    465 {
    466 
    467 	/* Get the station address from CIS tuple 0x81. */
    468 	if (pcmcia_scan_cis(device_parent(sc->sc_dev),
    469 	    mhzc_em3336_lannid_ciscallback, myla) != 1) {
    470 		printf("%s: unable to get Ethernet address from CIS\n",
    471 		    device_xname(sc->sc_dev));
    472 		return (0);
    473 	}
    474 
    475 	return (1);
    476 }
    477 
    478 int
    479 mhzc_em3336_enable(struct mhzc_softc *sc)
    480 {
    481 	struct pcmcia_mem_handle memh;
    482 	bus_size_t memoff;
    483 	int memwin, reg;
    484 
    485 	/*
    486 	 * Bring the chip to live by touching its registers in the correct
    487 	 * way (as per my reference... the Linux smc91c92_cs.c driver by
    488 	 * David A. Hinds).
    489 	 */
    490 
    491 	/* Map the ISRPOWEREG. */
    492 	if (pcmcia_mem_alloc(sc->sc_pf, 0x1000, &memh) != 0) {
    493 		aprint_error_dev(sc->sc_dev, "unable to allocate memory space\n");
    494 		return (1);
    495 	}
    496 
    497 	if (pcmcia_mem_map(sc->sc_pf, PCMCIA_MEM_ATTR, 0, 0x1000,
    498 	    &memh, &memoff, &memwin)) {
    499 		aprint_error_dev(sc->sc_dev, "unable to map memory space\n");
    500 		pcmcia_mem_free(sc->sc_pf, &memh);
    501 		return (1);
    502 	}
    503 
    504 	/*
    505 	 * The magic sequence:
    506 	 *
    507 	 *	- read/write the CCR option register.
    508 	 *	- read the ISRPOWEREG 2 times.
    509 	 *	- read/write the CCR option register again.
    510 	 */
    511 
    512 	reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION);
    513 	pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg);
    514 
    515 	reg = bus_space_read_1(memh.memt, memh.memh, 0x380);
    516 	delay(5);
    517 	reg = bus_space_read_1(memh.memt, memh.memh, 0x380);
    518 
    519 	tsleep(&mhzc_em3336_enable, PWAIT, "mhz3en", hz * 200 / 1000);
    520 
    521 	reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION);
    522 	delay(5);
    523 	pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg);
    524 
    525 	pcmcia_mem_unmap(sc->sc_pf, memwin);
    526 	pcmcia_mem_free(sc->sc_pf, &memh);
    527 
    528 	return (0);
    529 }
    530 
    531 int
    532 mhzc_em3336_lannid_ciscallback(struct pcmcia_tuple *tuple, void *arg)
    533 {
    534 	u_int8_t *myla = arg, addr_str[ETHER_ADDR_LEN * 2];
    535 	int i;
    536 
    537 	if (tuple->code == 0x81) {
    538 		/*
    539 		 * We have a string-encoded address.  Length includes
    540 		 * terminating 0xff.
    541 		 */
    542 		if (tuple->length != (ETHER_ADDR_LEN * 2) + 1)
    543 			return (0);
    544 
    545 		for (i = 0; i < tuple->length - 1; i++)
    546 			addr_str[i] = pcmcia_tuple_read_1(tuple, i);
    547 
    548 		/*
    549 		 * Decode the string into `myla'.
    550 		 */
    551 		return (mhzc_em3336_ascii_enaddr(addr_str, myla));
    552 	}
    553 	return (0);
    554 }
    555 
    556 /* XXX This should be shared w/ if_sm_pcmcia.c */
    557 int
    558 mhzc_em3336_ascii_enaddr(const char *cisstr, u_int8_t *myla)
    559 {
    560 	u_int8_t digit;
    561 	int i;
    562 
    563 	memset(myla, 0, ETHER_ADDR_LEN);
    564 
    565 	for (i = 0, digit = 0; i < (ETHER_ADDR_LEN * 2); i++) {
    566 		if (cisstr[i] >= '0' && cisstr[i] <= '9')
    567 			digit |= cisstr[i] - '0';
    568 		else if (cisstr[i] >= 'a' && cisstr[i] <= 'f')
    569 			digit |= (cisstr[i] - 'a') + 10;
    570 		else if (cisstr[i] >= 'A' && cisstr[i] <= 'F')
    571 			digit |= (cisstr[i] - 'A') + 10;
    572 		else {
    573 			/* Bogus digit!! */
    574 			return (0);
    575 		}
    576 
    577 		/* Compensate for ordering of digits. */
    578 		if (i & 1) {
    579 			myla[i >> 1] = digit;
    580 			digit = 0;
    581 		} else
    582 			digit <<= 4;
    583 	}
    584 
    585 	return (1);
    586 }
    587 
    588 /****** Here begins the com attachment code. ******/
    589 
    590 #if NCOM_MHZC > 0
    591 int	com_mhzc_match(device_t, cfdata_t , void *);
    592 void	com_mhzc_attach(device_t, device_t, void *);
    593 int	com_mhzc_detach(device_t, int);
    594 
    595 /* No mhzc-specific goo in the softc; it's all in the parent. */
    596 CFATTACH_DECL_NEW(com_mhzc, sizeof(struct com_softc),
    597     com_mhzc_match, com_mhzc_attach, com_detach, NULL);
    598 
    599 int	com_mhzc_enable(struct com_softc *);
    600 void	com_mhzc_disable(struct com_softc *);
    601 
    602 int
    603 com_mhzc_match(device_t parent, cfdata_t match, void *aux)
    604 {
    605 	extern struct cfdriver com_cd;
    606 	const char *name = aux;
    607 
    608 	/* Device is always present. */
    609 	if (strcmp(name, com_cd.cd_name) == 0)
    610 		return (1);
    611 
    612 	return (0);
    613 }
    614 
    615 void
    616 com_mhzc_attach(device_t parent, device_t self, void *aux)
    617 {
    618 	struct com_softc *sc = device_private(self);
    619 	struct mhzc_softc *msc = device_private(parent);
    620 
    621 	sc->sc_dev = self;
    622 	aprint_normal("\n");
    623 
    624 	com_init_regs(&sc->sc_regs,
    625 	    msc->sc_modem_pcioh.iot,
    626 	    msc->sc_modem_pcioh.ioh,
    627 	    -1);
    628 
    629 	sc->enabled = 1;
    630 
    631 	sc->sc_frequency = COM_FREQ;
    632 
    633 	sc->enable = com_mhzc_enable;
    634 	sc->disable = com_mhzc_disable;
    635 
    636 	aprint_normal("%s", device_xname(self));
    637 
    638 	com_attach_subr(sc);
    639 
    640 	sc->enabled = 0;
    641 }
    642 
    643 int
    644 com_mhzc_enable(struct com_softc *sc)
    645 {
    646 
    647 	return (mhzc_enable(device_private(device_parent(sc->sc_dev)),
    648 	    MHZC_MODEM_ENABLED));
    649 }
    650 
    651 void
    652 com_mhzc_disable(struct com_softc *sc)
    653 {
    654 
    655 	mhzc_disable(device_private(device_parent(sc->sc_dev)),
    656 	    MHZC_MODEM_ENABLED);
    657 }
    658 
    659 #endif /* NCOM_MHZC > 0 */
    660 
    661 /****** Here begins the sm attachment code. ******/
    662 
    663 #if NSM_MHZC > 0
    664 int	sm_mhzc_match(device_t, cfdata_t, void *);
    665 void	sm_mhzc_attach(device_t, device_t, void *);
    666 
    667 /* No mhzc-specific goo in the softc; it's all in the parent. */
    668 CFATTACH_DECL_NEW(sm_mhzc, sizeof(struct smc91cxx_softc),
    669     sm_mhzc_match, sm_mhzc_attach, smc91cxx_detach, smc91cxx_activate);
    670 
    671 int	sm_mhzc_enable(struct smc91cxx_softc *);
    672 void	sm_mhzc_disable(struct smc91cxx_softc *);
    673 
    674 int
    675 sm_mhzc_match(device_t parent, cfdata_t match, void *aux)
    676 {
    677 	extern struct cfdriver sm_cd;
    678 	const char *name = aux;
    679 
    680 	/* Device is always present. */
    681 	if (strcmp(name, sm_cd.cd_name) == 0)
    682 		return (1);
    683 
    684 	return (0);
    685 }
    686 
    687 void
    688 sm_mhzc_attach(device_t parent, device_t self, void *aux)
    689 {
    690 	struct smc91cxx_softc *sc = device_private(self);
    691 	struct mhzc_softc *msc = device_private(parent);
    692 	u_int8_t myla[ETHER_ADDR_LEN];
    693 
    694 	aprint_normal("\n");
    695 
    696 	sc->sc_dev = self;
    697 	sc->sc_bst = msc->sc_ethernet_pcioh.iot;
    698 	sc->sc_bsh = msc->sc_ethernet_pcioh.ioh;
    699 
    700 	sc->sc_enable = sm_mhzc_enable;
    701 	sc->sc_disable = sm_mhzc_disable;
    702 
    703 	if ((*msc->sc_product->mp_enaddr)(msc, myla) != 1)
    704 		return;
    705 
    706 	/* Perform generic initialization. */
    707 	smc91cxx_attach(sc, myla);
    708 }
    709 
    710 int
    711 sm_mhzc_enable(struct smc91cxx_softc *sc)
    712 {
    713 	struct mhzc_softc *xsc = device_private(device_parent(sc->sc_dev));
    714 
    715 	return mhzc_enable(xsc, MHZC_ETHERNET_ENABLED);
    716 }
    717 
    718 void
    719 sm_mhzc_disable(struct smc91cxx_softc *sc)
    720 {
    721 	struct mhzc_softc *xsc = device_private(device_parent(sc->sc_dev));
    722 
    723 	mhzc_disable(xsc, MHZC_ETHERNET_ENABLED);
    724 }
    725 
    726 #endif /* NSM_MHZC > 0 */
    727