Home | History | Annotate | Line # | Download | only in pcmcia
xirc.c revision 1.7
      1 /*	$NetBSD: xirc.c,v 1.7 2004/08/09 19:34:00 mycroft 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  * 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 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: xirc.c,v 1.7 2004/08/09 19:34:00 mycroft Exp $");
     42 
     43 #include "opt_inet.h"
     44 #include "opt_ns.h"
     45 #include "bpfilter.h"
     46 
     47 #include <sys/param.h>
     48 #include <sys/systm.h>
     49 #include <sys/mbuf.h>
     50 #include <sys/socket.h>
     51 #include <sys/ioctl.h>
     52 #include <sys/errno.h>
     53 #include <sys/syslog.h>
     54 #include <sys/select.h>
     55 #include <sys/tty.h>
     56 #include <sys/device.h>
     57 
     58 #include <net/if.h>
     59 #include <net/if_dl.h>
     60 #include <net/if_ether.h>
     61 #include <net/if_media.h>
     62 
     63 #ifdef INET
     64 #include <netinet/in.h>
     65 #include <netinet/in_systm.h>
     66 #include <netinet/in_var.h>
     67 #include <netinet/ip.h>
     68 #include <netinet/if_inarp.h>
     69 #endif
     70 
     71 #ifdef NS
     72 #include <netns/ns.h>
     73 #include <netns/ns_if.h>
     74 #endif
     75 
     76 #if NBPFILTER > 0
     77 #include <net/bpf.h>
     78 #include <net/bpfdesc.h>
     79 #endif
     80 
     81 #include <machine/intr.h>
     82 #include <machine/bus.h>
     83 
     84 #include <dev/pcmcia/pcmciareg.h>
     85 #include <dev/pcmcia/pcmciavar.h>
     86 #include <dev/pcmcia/pcmciadevs.h>
     87 
     88 #include "xirc.h"
     89 
     90 #if NCOM_XIRC > 0
     91 #include <dev/ic/comreg.h>
     92 #include <dev/ic/comvar.h>
     93 #endif
     94 
     95 #if NXI_XIRC > 0
     96 #include <dev/mii/mii.h>
     97 #include <dev/mii/miivar.h>
     98 
     99 #include <dev/pcmcia/if_xivar.h>
    100 #endif
    101 #include <dev/pcmcia/if_xireg.h>
    102 
    103 struct xirc_softc {
    104 	struct device sc_dev;		/* generic device glue */
    105 
    106 	struct pcmcia_function *sc_pf;	/* our PCMCIA function */
    107 	void *sc_ih;			/* interrupt handle */
    108 
    109 	u_int16_t sc_id;
    110 	u_int8_t sc_mako_intmask;
    111 	int sc_chipset;
    112 
    113 	/*
    114 	 * Data for the Modem portion.
    115 	 */
    116 	struct device *sc_modem;
    117 	struct pcmcia_io_handle sc_modem_pcioh;
    118 	int sc_modem_io_window;
    119 
    120 	/*
    121 	 * Data for the Ethernet portion.
    122 	 */
    123 	struct device *sc_ethernet;
    124 	struct pcmcia_io_handle sc_ethernet_pcioh;
    125 	int sc_ethernet_io_window;
    126 
    127 	int sc_flags;
    128 #define	XIRC_MODEM_MAPPED	0x01
    129 #define	XIRC_ETHERNET_MAPPED	0x02
    130 #define	XIRC_MODEM_ENABLED	0x04
    131 #define	XIRC_ETHERNET_ENABLED	0x08
    132 #define	XIRC_MODEM_ALLOCED	0x10
    133 #define	XIRC_ETHERNET_ALLOCED	0x20
    134 };
    135 
    136 int	xirc_match __P((struct device *, struct cfdata *, void *));
    137 void	xirc_attach __P((struct device *, struct device *, void *));
    138 int	xirc_detach __P((struct device *, int));
    139 int	xirc_activate __P((struct device *, enum devact));
    140 
    141 CFATTACH_DECL(xirc, sizeof(struct xirc_softc),
    142     xirc_match, xirc_attach, xirc_detach, xirc_activate);
    143 
    144 int	xirc_print __P((void *, const char *));
    145 
    146 int	xirc_manfid_ciscallback __P((struct pcmcia_tuple *, void *));
    147 struct pcmcia_config_entry *
    148 	xirc_mako_alloc __P((struct xirc_softc *));
    149 struct pcmcia_config_entry *
    150 	xirc_dingo_alloc_modem __P((struct xirc_softc *));
    151 struct pcmcia_config_entry *
    152 	xirc_dingo_alloc_ethernet __P((struct xirc_softc *));
    153 
    154 int	xirc_enable __P((struct xirc_softc *, int, int));
    155 void	xirc_disable __P((struct xirc_softc *, int, int));
    156 
    157 int	xirc_intr __P((void *));
    158 
    159 int
    160 xirc_match(parent, match, aux)
    161 	struct device *parent;
    162 	struct cfdata *match;
    163 	void *aux;
    164 {
    165 	struct pcmcia_attach_args *pa = aux;
    166 
    167 	/* XXX Toshiba, Accton */
    168 
    169 	if (pa->manufacturer == PCMCIA_VENDOR_COMPAQ2 &&
    170 	    pa->product == PCMCIA_PRODUCT_COMPAQ2_CPQ_10_100)
    171 		return (1);
    172 
    173 	if (pa->manufacturer == PCMCIA_VENDOR_INTEL &&
    174 	    pa->product == PCMCIA_PRODUCT_INTEL_EEPRO100)
    175 		return (1);
    176 
    177 	if (pa->manufacturer == PCMCIA_VENDOR_XIRCOM &&
    178 	    (pa->product & (XIMEDIA_ETHER << 8)) != 0)
    179 		return (2);
    180 
    181 	return (0);
    182 }
    183 
    184 void
    185 xirc_attach(parent, self, aux)
    186 	struct device *parent, *self;
    187 	void *aux;
    188 {
    189 	struct xirc_softc *sc = (void *)self;
    190 	struct pcmcia_attach_args *pa = aux;
    191 	struct pcmcia_config_entry *cfe;
    192 	int rv;
    193 
    194 	aprint_normal("\n");
    195 	sc->sc_pf = pa->pf;
    196 
    197 	pcmcia_socket_enable(parent);
    198 	rv = pcmcia_scan_cis(parent, xirc_manfid_ciscallback, &sc->sc_id);
    199 	pcmcia_socket_disable(parent);
    200 	if (!rv) {
    201 		aprint_error("%s: failed to find ID\n", self->dv_xname);
    202 		return;
    203 	}
    204 
    205 	switch (sc->sc_id & 0x100f) {
    206 	case 0x0001:	/* CE */
    207 	case 0x0002:	/* CE2 */
    208 		sc->sc_chipset = XI_CHIPSET_SCIPPER;
    209 		break;
    210 	case 0x0003:	/* CE3 */
    211 		sc->sc_chipset = XI_CHIPSET_MOHAWK;
    212 		break;
    213 	case 0x1001:
    214 	case 0x1002:
    215 	case 0x1003:
    216 	case 0x1004:
    217 		sc->sc_chipset = XI_CHIPSET_SCIPPER;
    218 		break;
    219 	case 0x1005:
    220 		sc->sc_chipset = XI_CHIPSET_MOHAWK;
    221 		break;
    222 	case 0x1006:
    223 	case 0x1007:
    224 		sc->sc_chipset = XI_CHIPSET_DINGO;
    225 		break;
    226 	default:
    227 		aprint_error("%s: unknown ID %04x\n", self->dv_xname,
    228 		    sc->sc_id);
    229 		return;
    230 	}
    231 
    232 	aprint_normal("%s: id=%04x\n", self->dv_xname, sc->sc_id);
    233 
    234 	if (sc->sc_id & (XIMEDIA_MODEM << 8)) {
    235 		if (sc->sc_chipset >= XI_CHIPSET_DINGO) {
    236 			cfe = xirc_dingo_alloc_modem(sc);
    237 			if (cfe && sc->sc_id & (XIMEDIA_ETHER << 8)) {
    238 				if (!xirc_dingo_alloc_ethernet(sc)) {
    239 					pcmcia_io_free(pa->pf,
    240 					    &sc->sc_modem_pcioh);
    241 					cfe = 0;
    242 				}
    243 			}
    244 		} else
    245 			cfe = xirc_mako_alloc(sc);
    246 	} else
    247 		cfe = xirc_dingo_alloc_ethernet(sc);
    248 	if (!cfe) {
    249 		aprint_error("%s: failed to allocate I/O space\n",
    250 		    self->dv_xname);
    251 		goto fail;
    252 	}
    253 
    254 	/* Enable the card. */
    255 	pcmcia_function_init(pa->pf, cfe);
    256 
    257 	if (sc->sc_id & (XIMEDIA_MODEM << 8)) {
    258 		if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_IO8,
    259 		    &sc->sc_modem_pcioh, &sc->sc_modem_io_window)) {
    260 			aprint_error("%s: unable to map I/O space\n",
    261 			    self->dv_xname);
    262 			goto fail;
    263 		}
    264 		sc->sc_flags |= XIRC_MODEM_MAPPED;
    265 	}
    266 
    267 	if (sc->sc_id & (XIMEDIA_ETHER << 8)) {
    268 		if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_AUTO,
    269 		    &sc->sc_ethernet_pcioh, &sc->sc_ethernet_io_window)) {
    270 			aprint_error("%s: unable to map I/O space\n",
    271 			    self->dv_xname);
    272 			goto fail;
    273 		}
    274 		sc->sc_flags |= XIRC_ETHERNET_MAPPED;
    275 	}
    276 
    277 	if (xirc_enable(sc, XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED,
    278 	    sc->sc_id & (XIMEDIA_MODEM|XIMEDIA_ETHER))) {
    279 		aprint_error("%s: enable failed\n", self->dv_xname);
    280 		goto fail;
    281 	}
    282 
    283 	sc->sc_mako_intmask = 0xee;
    284 
    285 	if (sc->sc_id & (XIMEDIA_MODEM << 8))
    286 		sc->sc_modem = config_found(self, "com", xirc_print);
    287 	if (sc->sc_id & (XIMEDIA_ETHER << 8))
    288 		sc->sc_ethernet = config_found(self, "xi", xirc_print);
    289 
    290 	xirc_disable(sc, XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED,
    291 	    sc->sc_id & (XIMEDIA_MODEM|XIMEDIA_ETHER));
    292 	return;
    293 
    294 fail:
    295 	/* I/O spaces will be freed by detach. */
    296 	;
    297 }
    298 
    299 int
    300 xirc_manfid_ciscallback(tuple, arg)
    301 	struct pcmcia_tuple *tuple;
    302 	void *arg;
    303 {
    304 	u_int16_t *id = arg;
    305 
    306 	if (tuple->code != PCMCIA_CISTPL_MANFID)
    307 		return (0);
    308 
    309 	if (tuple->length < 5)
    310 		return (0);
    311 
    312 	*id = (pcmcia_tuple_read_1(tuple, 3) << 8) |
    313 	      pcmcia_tuple_read_1(tuple, 4);
    314 	return (1);
    315 }
    316 
    317 struct pcmcia_config_entry *
    318 xirc_mako_alloc(sc)
    319 	struct xirc_softc *sc;
    320 {
    321 	struct pcmcia_config_entry *cfe;
    322 
    323 	SIMPLEQ_FOREACH(cfe, &sc->sc_pf->cfe_head, cfe_list) {
    324 		if (cfe->num_iospace != 1)
    325 			continue;
    326 
    327 		if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[0].start,
    328 		    cfe->iospace[0].length, cfe->iospace[0].length,
    329 		    &sc->sc_modem_pcioh))
    330 			continue;
    331 
    332 		if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[0].start+8,
    333 		    XI_IOSIZE+2, XI_IOSIZE, &sc->sc_ethernet_pcioh) &&
    334 		    pcmcia_io_alloc(sc->sc_pf, cfe->iospace[0].start-24,
    335 		    XI_IOSIZE+2, XI_IOSIZE, &sc->sc_ethernet_pcioh)) {
    336 			pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
    337 			continue;
    338 		}
    339 
    340 		/* Found one! */
    341 		sc->sc_flags |= XIRC_MODEM_ALLOCED;
    342 		sc->sc_flags |= XIRC_ETHERNET_ALLOCED;
    343 		return (cfe);
    344 	}
    345 
    346 	return (0);
    347 }
    348 
    349 struct pcmcia_config_entry *
    350 xirc_dingo_alloc_modem(sc)
    351 	struct xirc_softc *sc;
    352 {
    353 	struct pcmcia_config_entry *cfe;
    354 
    355 	SIMPLEQ_FOREACH(cfe, &sc->sc_pf->cfe_head, cfe_list) {
    356 		if (cfe->num_iospace != 1)
    357 			continue;
    358 
    359 		if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[0].start,
    360 		    cfe->iospace[0].length, cfe->iospace[0].length,
    361 		    &sc->sc_modem_pcioh))
    362 			continue;
    363 
    364 		/* Found one! */
    365 		sc->sc_flags |= XIRC_MODEM_ALLOCED;
    366 		return (cfe);
    367 	}
    368 
    369 	return (0);
    370 }
    371 
    372 struct pcmcia_config_entry *
    373 xirc_dingo_alloc_ethernet(sc)
    374 	struct xirc_softc *sc;
    375 {
    376 	struct pcmcia_config_entry *cfe;
    377 	bus_addr_t port;
    378 
    379 	for (port = 0x300; port < 0x400; port += XI_IOSIZE) {
    380 		if (pcmcia_io_alloc(sc->sc_pf, port,
    381 		    XI_IOSIZE, XI_IOSIZE, &sc->sc_ethernet_pcioh))
    382 			continue;
    383 
    384 		/* Found one for the ethernet! */
    385 		sc->sc_flags |= XIRC_ETHERNET_ALLOCED;
    386 		cfe = SIMPLEQ_FIRST(&sc->sc_pf->cfe_head);
    387 		return (cfe);
    388 	}
    389 
    390 	return (0);
    391 }
    392 
    393 int
    394 xirc_print(aux, pnp)
    395 	void *aux;
    396 	const char *pnp;
    397 {
    398 	const char *name = aux;
    399 
    400 	if (pnp)
    401 		aprint_normal("%s at %s(*)",  name, pnp);
    402 
    403 	return (UNCONF);
    404 }
    405 
    406 int
    407 xirc_detach(self, flags)
    408 	struct device *self;
    409 	int flags;
    410 {
    411 	struct xirc_softc *sc = (void *)self;
    412 	int rv;
    413 
    414 	if (sc->sc_ethernet != NULL) {
    415 		rv = config_detach(sc->sc_ethernet, flags);
    416 		if (rv != 0)
    417 			return (rv);
    418 		sc->sc_ethernet = NULL;
    419 	}
    420 
    421 	if (sc->sc_modem != NULL) {
    422 		rv = config_detach(sc->sc_modem, flags);
    423 		if (rv != 0)
    424 			return (rv);
    425 		sc->sc_modem = NULL;
    426 	}
    427 
    428 	/* Unmap our i/o windows. */
    429 	if (sc->sc_flags & XIRC_ETHERNET_MAPPED)
    430 		pcmcia_io_unmap(sc->sc_pf, sc->sc_ethernet_io_window);
    431 	if (sc->sc_flags & XIRC_MODEM_MAPPED)
    432 		pcmcia_io_unmap(sc->sc_pf, sc->sc_modem_io_window);
    433 
    434 	/* Free our i/o spaces. */
    435 	if (sc->sc_flags & XIRC_ETHERNET_ALLOCED)
    436 		pcmcia_io_free(sc->sc_pf, &sc->sc_ethernet_pcioh);
    437 	if (sc->sc_flags & XIRC_MODEM_ALLOCED)
    438 		pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
    439 	sc->sc_flags = 0;
    440 
    441 	return (0);
    442 }
    443 
    444 int
    445 xirc_activate(self, act)
    446 	struct device *self;
    447 	enum devact act;
    448 {
    449 	struct xirc_softc *sc = (void *)self;
    450 	int s, rv = 0;
    451 
    452 	s = splhigh();
    453 	switch (act) {
    454 	case DVACT_ACTIVATE:
    455 		rv = EOPNOTSUPP;
    456 		break;
    457 
    458 	case DVACT_DEACTIVATE:
    459 		if (sc->sc_ethernet != NULL) {
    460 			rv = config_deactivate(sc->sc_ethernet);
    461 			if (rv != 0)
    462 				goto out;
    463 		}
    464 
    465 		if (sc->sc_modem != NULL) {
    466 			rv = config_deactivate(sc->sc_modem);
    467 			if (rv != 0)
    468 				goto out;
    469 		}
    470 		break;
    471 	}
    472  out:
    473 	splx(s);
    474 	return (rv);
    475 }
    476 
    477 int
    478 xirc_intr(arg)
    479 	void *arg;
    480 {
    481 	struct xirc_softc *sc = arg;
    482 	int rval = 0;
    483 
    484 #if NCOM_XIRC > 0
    485 	if (sc->sc_modem != NULL &&
    486 	    (sc->sc_flags & XIRC_MODEM_ENABLED) != 0)
    487 		rval |= comintr(sc->sc_modem);
    488 #endif
    489 
    490 #if NXI_XIRC > 0
    491 	if (sc->sc_ethernet != NULL &&
    492 	    (sc->sc_flags & XIRC_ETHERNET_ENABLED) != 0)
    493 		rval |= xi_intr(sc->sc_ethernet);
    494 #endif
    495 
    496 	return (rval);
    497 }
    498 
    499 int
    500 xirc_enable(sc, flag, media)
    501 	struct xirc_softc *sc;
    502 	int flag, media;
    503 {
    504 
    505 	if ((sc->sc_flags & flag) == flag) {
    506 		printf("%s: already enabled\n", sc->sc_dev.dv_xname);
    507 		return (0);
    508 	}
    509 
    510 	if ((sc->sc_flags & (XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED)) != 0) {
    511 		sc->sc_flags |= flag;
    512 		return (0);
    513 	}
    514 
    515 	/*
    516 	 * Establish our interrupt handler.
    517 	 *
    518 	 * XXX Note, we establish this at IPL_NET.  This is suboptimal
    519 	 * XXX the Modem portion, but is necessary to make the Ethernet
    520 	 * XXX portion have the correct interrupt level semantics.
    521 	 *
    522 	 * XXX Eventually we should use the `enabled' bits in the
    523 	 * XXX flags word to determine which level we should be at.
    524 	 */
    525 	sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET,
    526 	    xirc_intr, sc);
    527 	if (sc->sc_ih == NULL) {
    528 		printf("%s: unable to establish interrupt\n",
    529 		    sc->sc_dev.dv_xname);
    530 		return (EIO);
    531 	}
    532 
    533 	if (pcmcia_function_enable(sc->sc_pf)) {
    534 		pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    535 		return (EIO);
    536 	}
    537 
    538 	sc->sc_flags |= flag;
    539 
    540 	if (sc->sc_chipset < XI_CHIPSET_DINGO &&
    541 	    sc->sc_id & (XIMEDIA_MODEM << 8)) {
    542 		sc->sc_mako_intmask |= media;
    543 		bus_space_write_1(sc->sc_ethernet_pcioh.iot,
    544 		    sc->sc_ethernet_pcioh.ioh, 0x10, sc->sc_mako_intmask);
    545 	}
    546 
    547 	return (0);
    548 }
    549 
    550 void
    551 xirc_disable(sc, flag, media)
    552 	struct xirc_softc *sc;
    553 	int flag, media;
    554 {
    555 
    556 	if ((sc->sc_flags & flag) == 0) {
    557 		printf("%s: already disabled\n", sc->sc_dev.dv_xname);
    558 		return;
    559 	}
    560 
    561 	if (sc->sc_chipset < XI_CHIPSET_DINGO &&
    562 	    sc->sc_id & (XIMEDIA_MODEM << 8)) {
    563 		sc->sc_mako_intmask &= ~media;
    564 		bus_space_write_1(sc->sc_ethernet_pcioh.iot,
    565 		    sc->sc_ethernet_pcioh.ioh, 0x10, sc->sc_mako_intmask);
    566 	}
    567 
    568 	sc->sc_flags &= ~flag;
    569 	if ((sc->sc_flags & (XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED)) != 0)
    570 		return;
    571 
    572 	pcmcia_function_disable(sc->sc_pf);
    573 	pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    574 }
    575 
    576 /****** Here begins the com attachment code. ******/
    577 
    578 #if NCOM_XIRC > 0
    579 int	com_xirc_match __P((struct device *, struct cfdata *, void *));
    580 void	com_xirc_attach __P((struct device *, struct device *, void *));
    581 int	com_xirc_detach __P((struct device *, int));
    582 
    583 /* No xirc-specific goo in the softc; it's all in the parent. */
    584 CFATTACH_DECL(com_xirc, sizeof(struct com_softc),
    585     com_xirc_match, com_xirc_attach, com_detach, com_activate);
    586 
    587 int	com_xirc_enable __P((struct com_softc *));
    588 void	com_xirc_disable __P((struct com_softc *));
    589 
    590 int
    591 com_xirc_match(parent, match, aux)
    592 	struct device *parent;
    593 	struct cfdata *match;
    594 	void *aux;
    595 {
    596 	extern struct cfdriver com_cd;
    597 	const char *name = aux;
    598 
    599 	if (strcmp(name, com_cd.cd_name) == 0)
    600 		return (1);
    601 
    602 	return (0);
    603 }
    604 
    605 void
    606 com_xirc_attach(parent, self, aux)
    607 	struct device *parent, *self;
    608 	void *aux;
    609 {
    610 	struct com_softc *sc = (void *)self;
    611 	struct xirc_softc *msc = (void *)parent;
    612 
    613 	aprint_normal("\n");
    614 
    615 	sc->sc_iot = msc->sc_modem_pcioh.iot;
    616 	sc->sc_ioh = msc->sc_modem_pcioh.ioh;
    617 
    618 	sc->enabled = 1;
    619 
    620 	sc->sc_iobase = -1;
    621 	sc->sc_frequency = COM_FREQ;
    622 
    623 	sc->enable = com_xirc_enable;
    624 	sc->disable = com_xirc_disable;
    625 
    626 	aprint_normal("%s", self->dv_xname);
    627 
    628 	com_attach_subr(sc);
    629 
    630 	sc->enabled = 0;
    631 }
    632 
    633 int
    634 com_xirc_enable(sc)
    635 	struct com_softc *sc;
    636 {
    637 	struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
    638 
    639 	return (xirc_enable(msc, XIRC_MODEM_ENABLED, XIMEDIA_MODEM));
    640 }
    641 
    642 void
    643 com_xirc_disable(sc)
    644 	struct com_softc *sc;
    645 {
    646 	struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
    647 
    648 	xirc_disable(msc, XIRC_MODEM_ENABLED, XIMEDIA_MODEM);
    649 }
    650 
    651 #endif /* NCOM_XIRC > 0 */
    652 
    653 /****** Here begins the xi attachment code. ******/
    654 
    655 #if NXI_XIRC > 0
    656 int	xi_xirc_match __P((struct device *, struct cfdata *, void *));
    657 void	xi_xirc_attach __P((struct device *, struct device *, void *));
    658 
    659 /* No xirc-specific goo in the softc; it's all in the parent. */
    660 CFATTACH_DECL(xi_xirc, sizeof(struct xi_softc),
    661     xi_xirc_match, xi_xirc_attach, xi_detach, xi_activate);
    662 
    663 int	xi_xirc_enable __P((struct xi_softc *));
    664 void	xi_xirc_disable __P((struct xi_softc *));
    665 int	xi_xirc_lan_nid_ciscallback __P((struct pcmcia_tuple *, void *));
    666 
    667 int
    668 xi_xirc_match(parent, match, aux)
    669 	struct device *parent;
    670 	struct cfdata *match;
    671 	void *aux;
    672 {
    673 	extern struct cfdriver xi_cd;
    674 	const char *name = aux;
    675 
    676 	if (strcmp(name, xi_cd.cd_name) == 0)
    677 		return (1);
    678 
    679 	return (0);
    680 }
    681 
    682 void
    683 xi_xirc_attach(parent, self, aux)
    684 	struct device *parent, *self;
    685 	void *aux;
    686 {
    687 	struct xi_softc *sc = (void *)self;
    688 	struct xirc_softc *msc = (void *)parent;
    689 	u_int8_t myla[ETHER_ADDR_LEN];
    690 
    691 	aprint_normal("\n");
    692 
    693 	sc->sc_bst = msc->sc_ethernet_pcioh.iot;
    694 	sc->sc_bsh = msc->sc_ethernet_pcioh.ioh;
    695 
    696 	sc->sc_chipset = msc->sc_chipset;
    697 
    698 	sc->sc_enable = xi_xirc_enable;
    699 	sc->sc_disable = xi_xirc_disable;
    700 
    701 	if (!pcmcia_scan_cis(msc->sc_dev.dv_parent, xi_xirc_lan_nid_ciscallback,
    702 	    myla)) {
    703 		aprint_error("%s: can't find MAC address\n", self->dv_xname);
    704 		return;
    705 	}
    706 
    707 	/* Perform generic initialization. */
    708 	xi_attach(sc, myla);
    709 }
    710 
    711 int
    712 xi_xirc_enable(sc)
    713 	struct xi_softc *sc;
    714 {
    715 	struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
    716 
    717 	return (xirc_enable(msc, XIRC_ETHERNET_ENABLED, XIMEDIA_ETHER));
    718 }
    719 
    720 void
    721 xi_xirc_disable(sc)
    722 	struct xi_softc *sc;
    723 {
    724 	struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
    725 
    726 	xirc_disable(msc, XIRC_ETHERNET_ENABLED, XIMEDIA_ETHER);
    727 }
    728 
    729 int
    730 xi_xirc_lan_nid_ciscallback(tuple, arg)
    731 	struct pcmcia_tuple *tuple;
    732 	void *arg;
    733 {
    734 	u_int8_t *myla = arg;
    735 	int i;
    736 
    737 	if (tuple->length < 2)
    738 		return (0);
    739 
    740 	switch (tuple->code) {
    741 	case PCMCIA_CISTPL_FUNCE:
    742 		switch (pcmcia_tuple_read_1(tuple, 0)) {
    743 		case PCMCIA_TPLFE_TYPE_LAN_NID:
    744 			if (pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN)
    745 				return (0);
    746 			for (i = 0; i < ETHER_ADDR_LEN; i++)
    747 				myla[i] = pcmcia_tuple_read_1(tuple, i + 2);
    748 			return (1);
    749 
    750 		case 0x02:
    751 			/*
    752 			 * Not sure about this, I don't have a CE2
    753 			 * that puts the ethernet addr here.
    754 			 */
    755 		 	if (pcmcia_tuple_read_1(tuple, 1) != 0x01 ||
    756 			    pcmcia_tuple_read_1(tuple, 2) != ETHER_ADDR_LEN)
    757 				return (0);
    758 			for (i = 0; i < ETHER_ADDR_LEN; i++)
    759 				myla[i] = pcmcia_tuple_read_1(tuple, i + 3);
    760 			return (1);
    761 		}
    762 
    763 	case 0x89:
    764 		if (pcmcia_tuple_read_1(tuple, 0) != 0x04 ||
    765 		    pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN)
    766 			return (0);
    767 		for (i = 0; i < ETHER_ADDR_LEN; i++)
    768 			myla[i] = pcmcia_tuple_read_1(tuple, i + 2);
    769 		return (1);
    770 	}
    771 
    772 	return (0);
    773 }
    774 
    775 #endif /* NXI_XIRC > 0 */
    776