Home | History | Annotate | Line # | Download | only in pcmcia
xirc.c revision 1.5
      1 /*	$NetBSD: xirc.c,v 1.5 2004/08/09 18:11:01 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.5 2004/08/09 18:11:01 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 (xirc_enable(sc, XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED,
    258 	    sc->sc_id & (XIMEDIA_MODEM|XIMEDIA_ETHER))) {
    259 		aprint_error("%s: enable failed\n", self->dv_xname);
    260 		goto fail;
    261 	}
    262 
    263 	sc->sc_mako_intmask = 0xee;
    264 
    265 	if (sc->sc_id & (XIMEDIA_MODEM << 8))
    266 		sc->sc_modem = config_found(self, "com", xirc_print);
    267 	if (sc->sc_id & (XIMEDIA_ETHER << 8))
    268 		sc->sc_ethernet = config_found(self, "xi", xirc_print);
    269 
    270 	xirc_disable(sc, XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED,
    271 	    sc->sc_id & (XIMEDIA_MODEM|XIMEDIA_ETHER));
    272 	return;
    273 
    274 fail:
    275 	/* Free our i/o spaces. */
    276 	if (sc->sc_flags & XIRC_ETHERNET_ALLOCED)
    277 		pcmcia_io_free(sc->sc_pf, &sc->sc_ethernet_pcioh);
    278 	if (sc->sc_flags & XIRC_MODEM_ALLOCED)
    279 		pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
    280 	sc->sc_flags = 0;
    281 }
    282 
    283 int
    284 xirc_manfid_ciscallback(tuple, arg)
    285 	struct pcmcia_tuple *tuple;
    286 	void *arg;
    287 {
    288 	u_int16_t *id = arg;
    289 
    290 	if (tuple->code != PCMCIA_CISTPL_MANFID)
    291 		return (0);
    292 
    293 	if (tuple->length < 5)
    294 		return (0);
    295 
    296 	*id = (pcmcia_tuple_read_1(tuple, 3) << 8) |
    297 	      pcmcia_tuple_read_1(tuple, 4);
    298 	return (1);
    299 }
    300 
    301 struct pcmcia_config_entry *
    302 xirc_mako_alloc(sc)
    303 	struct xirc_softc *sc;
    304 {
    305 	struct pcmcia_config_entry *cfe;
    306 
    307 	SIMPLEQ_FOREACH(cfe, &sc->sc_pf->cfe_head, cfe_list) {
    308 		if (cfe->num_iospace != 1)
    309 			continue;
    310 
    311 		if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[0].start,
    312 		    cfe->iospace[0].length, cfe->iospace[0].length,
    313 		    &sc->sc_modem_pcioh))
    314 			continue;
    315 
    316 		if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[0].start+8,
    317 		    XI_IOSIZE+2, XI_IOSIZE, &sc->sc_ethernet_pcioh) &&
    318 		    pcmcia_io_alloc(sc->sc_pf, cfe->iospace[0].start-24,
    319 		    XI_IOSIZE+2, XI_IOSIZE, &sc->sc_ethernet_pcioh)) {
    320 			pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
    321 			continue;
    322 		}
    323 
    324 		/* Found one! */
    325 		sc->sc_flags |= XIRC_MODEM_ALLOCED;
    326 		sc->sc_flags |= XIRC_ETHERNET_ALLOCED;
    327 		return (cfe);
    328 	}
    329 
    330 	return (0);
    331 }
    332 
    333 struct pcmcia_config_entry *
    334 xirc_dingo_alloc_modem(sc)
    335 	struct xirc_softc *sc;
    336 {
    337 	struct pcmcia_config_entry *cfe;
    338 
    339 	SIMPLEQ_FOREACH(cfe, &sc->sc_pf->cfe_head, cfe_list) {
    340 		if (cfe->num_iospace != 1)
    341 			continue;
    342 
    343 		if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[0].start,
    344 		    cfe->iospace[0].length, cfe->iospace[0].length,
    345 		    &sc->sc_modem_pcioh))
    346 			continue;
    347 
    348 		/* Found one! */
    349 		sc->sc_flags |= XIRC_MODEM_ALLOCED;
    350 		return (cfe);
    351 	}
    352 
    353 	return (0);
    354 }
    355 
    356 struct pcmcia_config_entry *
    357 xirc_dingo_alloc_ethernet(sc)
    358 	struct xirc_softc *sc;
    359 {
    360 	struct pcmcia_config_entry *cfe;
    361 	bus_addr_t port;
    362 
    363 	for (port = 0x300; port < 0x400; port += XI_IOSIZE) {
    364 		if (pcmcia_io_alloc(sc->sc_pf, port,
    365 		    XI_IOSIZE, XI_IOSIZE, &sc->sc_ethernet_pcioh))
    366 			continue;
    367 
    368 		/* Found one for the ethernet! */
    369 		sc->sc_flags |= XIRC_ETHERNET_ALLOCED;
    370 		cfe = SIMPLEQ_FIRST(&sc->sc_pf->cfe_head);
    371 		return (cfe);
    372 	}
    373 
    374 	return (0);
    375 }
    376 
    377 int
    378 xirc_print(aux, pnp)
    379 	void *aux;
    380 	const char *pnp;
    381 {
    382 	const char *name = aux;
    383 
    384 	if (pnp)
    385 		aprint_normal("%s at %s(*)",  name, pnp);
    386 
    387 	return (UNCONF);
    388 }
    389 
    390 int
    391 xirc_detach(self, flags)
    392 	struct device *self;
    393 	int flags;
    394 {
    395 	struct xirc_softc *sc = (void *)self;
    396 	int rv;
    397 
    398 	if (sc->sc_ethernet != NULL) {
    399 		rv = config_detach(sc->sc_ethernet, flags);
    400 		if (rv != 0)
    401 			return (rv);
    402 		sc->sc_ethernet = NULL;
    403 	}
    404 
    405 	if (sc->sc_modem != NULL) {
    406 		rv = config_detach(sc->sc_modem, flags);
    407 		if (rv != 0)
    408 			return (rv);
    409 		sc->sc_modem = NULL;
    410 	}
    411 
    412 	/* Unmap our i/o windows. */
    413 	if (sc->sc_flags & XIRC_ETHERNET_MAPPED)
    414 		pcmcia_io_unmap(sc->sc_pf, sc->sc_ethernet_io_window);
    415 	if (sc->sc_flags & XIRC_MODEM_MAPPED)
    416 		pcmcia_io_unmap(sc->sc_pf, sc->sc_modem_io_window);
    417 
    418 	/* Free our i/o spaces. */
    419 	if (sc->sc_flags & XIRC_ETHERNET_ALLOCED)
    420 		pcmcia_io_free(sc->sc_pf, &sc->sc_ethernet_pcioh);
    421 	if (sc->sc_flags & XIRC_MODEM_ALLOCED)
    422 		pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
    423 	sc->sc_flags = 0;
    424 
    425 	return (0);
    426 }
    427 
    428 int
    429 xirc_activate(self, act)
    430 	struct device *self;
    431 	enum devact act;
    432 {
    433 	struct xirc_softc *sc = (void *)self;
    434 	int s, rv = 0;
    435 
    436 	s = splhigh();
    437 	switch (act) {
    438 	case DVACT_ACTIVATE:
    439 		rv = EOPNOTSUPP;
    440 		break;
    441 
    442 	case DVACT_DEACTIVATE:
    443 		if (sc->sc_ethernet != NULL) {
    444 			rv = config_deactivate(sc->sc_ethernet);
    445 			if (rv != 0)
    446 				goto out;
    447 		}
    448 
    449 		if (sc->sc_modem != NULL) {
    450 			rv = config_deactivate(sc->sc_modem);
    451 			if (rv != 0)
    452 				goto out;
    453 		}
    454 		break;
    455 	}
    456  out:
    457 	splx(s);
    458 	return (rv);
    459 }
    460 
    461 int
    462 xirc_intr(arg)
    463 	void *arg;
    464 {
    465 	struct xirc_softc *sc = arg;
    466 	int rval = 0;
    467 
    468 #if NCOM_XIRC > 0
    469 	if (sc->sc_modem != NULL &&
    470 	    (sc->sc_flags & XIRC_MODEM_ENABLED) != 0)
    471 		rval |= comintr(sc->sc_modem);
    472 #endif
    473 
    474 #if NXI_XIRC > 0
    475 	if (sc->sc_ethernet != NULL &&
    476 	    (sc->sc_flags & XIRC_ETHERNET_ENABLED) != 0)
    477 		rval |= xi_intr(sc->sc_ethernet);
    478 #endif
    479 
    480 	return (rval);
    481 }
    482 
    483 int
    484 xirc_enable(sc, flag, media)
    485 	struct xirc_softc *sc;
    486 	int flag, media;
    487 {
    488 
    489 	if ((sc->sc_flags & flag) == flag) {
    490 		printf("%s: already enabled\n", sc->sc_dev.dv_xname);
    491 		return (0);
    492 	}
    493 
    494 	if ((sc->sc_flags & (XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED)) != 0) {
    495 		sc->sc_flags |= flag;
    496 		return (0);
    497 	}
    498 
    499 	/*
    500 	 * Establish our interrupt handler.
    501 	 *
    502 	 * XXX Note, we establish this at IPL_NET.  This is suboptimal
    503 	 * XXX the Modem portion, but is necessary to make the Ethernet
    504 	 * XXX portion have the correct interrupt level semantics.
    505 	 *
    506 	 * XXX Eventually we should use the `enabled' bits in the
    507 	 * XXX flags word to determine which level we should be at.
    508 	 */
    509 	sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET,
    510 	    xirc_intr, sc);
    511 	if (sc->sc_ih == NULL) {
    512 		printf("%s: unable to establish interrupt\n",
    513 		    sc->sc_dev.dv_xname);
    514 		return (EIO);
    515 	}
    516 
    517 	if (pcmcia_function_enable(sc->sc_pf)) {
    518 		pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    519 		return (EIO);
    520 	}
    521 
    522 	sc->sc_flags |= flag;
    523 
    524 	if (sc->sc_chipset < XI_CHIPSET_DINGO &&
    525 	    sc->sc_id & (XIMEDIA_MODEM << 8)) {
    526 		sc->sc_mako_intmask |= media;
    527 		bus_space_write_1(sc->sc_ethernet_pcioh.iot,
    528 		    sc->sc_ethernet_pcioh.ioh, 0x10, sc->sc_mako_intmask);
    529 	}
    530 
    531 	return (0);
    532 }
    533 
    534 void
    535 xirc_disable(sc, flag, media)
    536 	struct xirc_softc *sc;
    537 	int flag, media;
    538 {
    539 
    540 	if ((sc->sc_flags & flag) == 0) {
    541 		printf("%s: already disabled\n", sc->sc_dev.dv_xname);
    542 		return;
    543 	}
    544 
    545 	if (sc->sc_chipset < XI_CHIPSET_DINGO &&
    546 	    sc->sc_id & (XIMEDIA_MODEM << 8)) {
    547 		sc->sc_mako_intmask &= ~media;
    548 		bus_space_write_1(sc->sc_ethernet_pcioh.iot,
    549 		    sc->sc_ethernet_pcioh.ioh, 0x10, sc->sc_mako_intmask);
    550 	}
    551 
    552 	sc->sc_flags &= ~flag;
    553 	if ((sc->sc_flags & (XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED)) != 0)
    554 		return;
    555 
    556 	pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
    557 	pcmcia_function_disable(sc->sc_pf);
    558 }
    559 
    560 /****** Here begins the com attachment code. ******/
    561 
    562 #if NCOM_XIRC > 0
    563 int	com_xirc_match __P((struct device *, struct cfdata *, void *));
    564 void	com_xirc_attach __P((struct device *, struct device *, void *));
    565 int	com_xirc_detach __P((struct device *, int));
    566 
    567 /* No xirc-specific goo in the softc; it's all in the parent. */
    568 CFATTACH_DECL(com_xirc, sizeof(struct com_softc),
    569     com_xirc_match, com_xirc_attach, com_detach, com_activate);
    570 
    571 int	com_xirc_enable __P((struct com_softc *));
    572 void	com_xirc_disable __P((struct com_softc *));
    573 
    574 int
    575 com_xirc_match(parent, match, aux)
    576 	struct device *parent;
    577 	struct cfdata *match;
    578 	void *aux;
    579 {
    580 	extern struct cfdriver com_cd;
    581 	const char *name = aux;
    582 
    583 	if (strcmp(name, com_cd.cd_name) == 0)
    584 		return (1);
    585 
    586 	return (0);
    587 }
    588 
    589 void
    590 com_xirc_attach(parent, self, aux)
    591 	struct device *parent, *self;
    592 	void *aux;
    593 {
    594 	struct com_softc *sc = (void *)self;
    595 	struct xirc_softc *msc = (void *)parent;
    596 
    597 	aprint_normal("\n");
    598 
    599 	if (pcmcia_io_map(msc->sc_pf, PCMCIA_WIDTH_IO8, &msc->sc_modem_pcioh,
    600 	    &msc->sc_modem_io_window)) {
    601 		aprint_error("%s: unable to map I/O space\n", self->dv_xname);
    602 		return;
    603 	}
    604 	msc->sc_flags |= XIRC_MODEM_MAPPED;
    605 
    606 	sc->sc_iot = msc->sc_modem_pcioh.iot;
    607 	sc->sc_ioh = msc->sc_modem_pcioh.ioh;
    608 
    609 	sc->enabled = 1;
    610 
    611 	sc->sc_iobase = -1;
    612 	sc->sc_frequency = COM_FREQ;
    613 
    614 	sc->enable = com_xirc_enable;
    615 	sc->disable = com_xirc_disable;
    616 
    617 	aprint_normal("%s", self->dv_xname);
    618 
    619 	com_attach_subr(sc);
    620 
    621 	sc->enabled = 0;
    622 }
    623 
    624 int
    625 com_xirc_enable(sc)
    626 	struct com_softc *sc;
    627 {
    628 	struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
    629 
    630 	return (xirc_enable(msc, XIRC_MODEM_ENABLED, XIMEDIA_MODEM));
    631 }
    632 
    633 void
    634 com_xirc_disable(sc)
    635 	struct com_softc *sc;
    636 {
    637 	struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
    638 
    639 	xirc_disable(msc, XIRC_MODEM_ENABLED, XIMEDIA_MODEM);
    640 }
    641 
    642 #endif /* NCOM_XIRC > 0 */
    643 
    644 /****** Here begins the xi attachment code. ******/
    645 
    646 #if NXI_XIRC > 0
    647 int	xi_xirc_match __P((struct device *, struct cfdata *, void *));
    648 void	xi_xirc_attach __P((struct device *, struct device *, void *));
    649 
    650 /* No xirc-specific goo in the softc; it's all in the parent. */
    651 CFATTACH_DECL(xi_xirc, sizeof(struct xi_softc),
    652     xi_xirc_match, xi_xirc_attach, xi_detach, xi_activate);
    653 
    654 int	xi_xirc_enable __P((struct xi_softc *));
    655 void	xi_xirc_disable __P((struct xi_softc *));
    656 int	xi_xirc_lan_nid_ciscallback __P((struct pcmcia_tuple *, void *));
    657 
    658 int
    659 xi_xirc_match(parent, match, aux)
    660 	struct device *parent;
    661 	struct cfdata *match;
    662 	void *aux;
    663 {
    664 	extern struct cfdriver xi_cd;
    665 	const char *name = aux;
    666 
    667 	if (strcmp(name, xi_cd.cd_name) == 0)
    668 		return (1);
    669 
    670 	return (0);
    671 }
    672 
    673 void
    674 xi_xirc_attach(parent, self, aux)
    675 	struct device *parent, *self;
    676 	void *aux;
    677 {
    678 	struct xi_softc *sc = (void *)self;
    679 	struct xirc_softc *msc = (void *)parent;
    680 	u_int8_t myla[ETHER_ADDR_LEN];
    681 
    682 	aprint_normal("\n");
    683 
    684 	if (pcmcia_io_map(msc->sc_pf, PCMCIA_WIDTH_AUTO, &msc->sc_ethernet_pcioh,
    685 	    &msc->sc_ethernet_io_window)) {
    686 		aprint_error("%s: unable to map I/O space\n", self->dv_xname);
    687 		return;
    688 	}
    689 	msc->sc_flags |= XIRC_ETHERNET_MAPPED;
    690 
    691 	sc->sc_bst = msc->sc_ethernet_pcioh.iot;
    692 	sc->sc_bsh = msc->sc_ethernet_pcioh.ioh;
    693 
    694 	sc->sc_chipset = msc->sc_chipset;
    695 
    696 	sc->sc_enable = xi_xirc_enable;
    697 	sc->sc_disable = xi_xirc_disable;
    698 
    699 	if (!pcmcia_scan_cis(msc->sc_dev.dv_parent, xi_xirc_lan_nid_ciscallback,
    700 	    myla)) {
    701 		aprint_error("%s: can't find MAC address\n", self->dv_xname);
    702 		return;
    703 	}
    704 
    705 	/* Perform generic initialization. */
    706 	xi_attach(sc, myla);
    707 }
    708 
    709 int
    710 xi_xirc_enable(sc)
    711 	struct xi_softc *sc;
    712 {
    713 	struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
    714 
    715 	return (xirc_enable(msc, XIRC_ETHERNET_ENABLED, XIMEDIA_ETHER));
    716 }
    717 
    718 void
    719 xi_xirc_disable(sc)
    720 	struct xi_softc *sc;
    721 {
    722 	struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
    723 
    724 	xirc_disable(msc, XIRC_ETHERNET_ENABLED, XIMEDIA_ETHER);
    725 }
    726 
    727 int
    728 xi_xirc_lan_nid_ciscallback(tuple, arg)
    729 	struct pcmcia_tuple *tuple;
    730 	void *arg;
    731 {
    732 	u_int8_t *myla = arg;
    733 	int i;
    734 
    735 	if (tuple->length < 2)
    736 		return (0);
    737 
    738 	switch (tuple->code) {
    739 	case PCMCIA_CISTPL_FUNCE:
    740 		switch (pcmcia_tuple_read_1(tuple, 0)) {
    741 		case PCMCIA_TPLFE_TYPE_LAN_NID:
    742 			if (pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN)
    743 				return (0);
    744 			for (i = 0; i < ETHER_ADDR_LEN; i++)
    745 				myla[i] = pcmcia_tuple_read_1(tuple, i + 2);
    746 			return (1);
    747 
    748 		case 0x02:
    749 			/*
    750 			 * Not sure about this, I don't have a CE2
    751 			 * that puts the ethernet addr here.
    752 			 */
    753 		 	if (pcmcia_tuple_read_1(tuple, 1) != 0x01 ||
    754 			    pcmcia_tuple_read_1(tuple, 2) != ETHER_ADDR_LEN)
    755 				return (0);
    756 			for (i = 0; i < ETHER_ADDR_LEN; i++)
    757 				myla[i] = pcmcia_tuple_read_1(tuple, i + 3);
    758 			return (1);
    759 		}
    760 
    761 	case 0x89:
    762 		if (pcmcia_tuple_read_1(tuple, 0) != 0x04 ||
    763 		    pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN)
    764 			return (0);
    765 		for (i = 0; i < ETHER_ADDR_LEN; i++)
    766 			myla[i] = pcmcia_tuple_read_1(tuple, i + 2);
    767 		return (1);
    768 	}
    769 
    770 	return (0);
    771 }
    772 
    773 #endif /* NXI_XIRC > 0 */
    774