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