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