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