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