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