Home | History | Annotate | Line # | Download | only in pcmcia
if_ne_pcmcia.c revision 1.78
      1 /*	$NetBSD: if_ne_pcmcia.c,v 1.78 2001/07/05 08:03:45 kanaoka Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Marc Horowitz.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/select.h>
     35 #include <sys/device.h>
     36 #include <sys/socket.h>
     37 
     38 #include <net/if_types.h>
     39 #include <net/if.h>
     40 #include <net/if_media.h>
     41 #include <net/if_ether.h>
     42 
     43 #include <machine/bus.h>
     44 #include <machine/intr.h>
     45 
     46 #include <dev/pcmcia/pcmciareg.h>
     47 #include <dev/pcmcia/pcmciavar.h>
     48 #include <dev/pcmcia/pcmciadevs.h>
     49 
     50 #include <dev/ic/dp8390reg.h>
     51 #include <dev/ic/dp8390var.h>
     52 
     53 #include <dev/ic/ne2000reg.h>
     54 #include <dev/ic/ne2000var.h>
     55 
     56 #include <dev/ic/rtl80x9reg.h>
     57 #include <dev/ic/rtl80x9var.h>
     58 
     59 #include <dev/ic/dl10019var.h>
     60 
     61 int	ne_pcmcia_match __P((struct device *, struct cfdata *, void *));
     62 void	ne_pcmcia_attach __P((struct device *, struct device *, void *));
     63 int	ne_pcmcia_detach __P((struct device *, int));
     64 
     65 int	ne_pcmcia_enable __P((struct dp8390_softc *));
     66 void	ne_pcmcia_disable __P((struct dp8390_softc *));
     67 
     68 struct ne_pcmcia_softc {
     69 	struct ne2000_softc sc_ne2000;		/* real "ne2000" softc */
     70 
     71 	/* PCMCIA-specific goo */
     72 	struct pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o information */
     73 	int sc_asic_io_window;			/* i/o window for ASIC */
     74 	int sc_nic_io_window;			/* i/o window for NIC */
     75 	struct pcmcia_function *sc_pf;		/* our PCMCIA function */
     76 	void *sc_ih;				/* interrupt handle */
     77 };
     78 
     79 u_int8_t *
     80 	ne_pcmcia_get_enaddr __P((struct ne_pcmcia_softc *, int,
     81 	    u_int8_t [ETHER_ADDR_LEN]));
     82 u_int8_t *
     83 	ne_pcmcia_dl10019_get_enaddr __P((struct ne_pcmcia_softc *,
     84 	    u_int8_t [ETHER_ADDR_LEN]));
     85 int	ne_pcmcia_ax88190_set_iobase __P((struct ne_pcmcia_softc *));
     86 
     87 struct cfattach ne_pcmcia_ca = {
     88 	sizeof(struct ne_pcmcia_softc), ne_pcmcia_match, ne_pcmcia_attach,
     89 	    ne_pcmcia_detach, dp8390_activate
     90 };
     91 
     92 static const struct ne2000dev {
     93     char *name;
     94     int32_t manufacturer;
     95     int32_t product;
     96     char *cis_info[4];
     97     int function;
     98     int enet_maddr;
     99     unsigned char enet_vendor[3];
    100     int flags;
    101 #define	NE2000DVF_DL10019	0x0001		/* chip is D-Link DL10019 */
    102 #define	NE2000DVF_AX88190	0x0002		/* chip is ASIX AX88190 */
    103 } ne2000devs[] = {
    104     { PCMCIA_STR_SYNERGY21_S21810,
    105       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    106       PCMCIA_CIS_SYNERGY21_S21810,
    107       0, -1, { 0x00, 0x48, 0x54 } },
    108 
    109     { PCMCIA_STR_AMBICOM_AMB8002T,
    110       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    111       PCMCIA_CIS_AMBICOM_AMB8002T,
    112       0, -1, { 0x00, 0x10, 0x7a } },
    113 
    114     { PCMCIA_STR_PREMAX_PE200,
    115       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    116       PCMCIA_CIS_PREMAX_PE200,
    117       0, 0x07f0, { 0x00, 0x20, 0xe0 } },
    118 
    119     { PCMCIA_STR_DIGITAL_DEPCMXX,
    120       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    121       PCMCIA_CIS_DIGITAL_DEPCMXX,
    122       0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
    123 
    124     { PCMCIA_STR_PLANET_SMARTCOM2000,
    125       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    126       PCMCIA_CIS_PLANET_SMARTCOM2000,
    127       0, 0xff0, { 0x00, 0x00, 0xe8 } },
    128 
    129     { PCMCIA_STR_DLINK_DE660,
    130       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    131       PCMCIA_CIS_DLINK_DE660,
    132       0, -1, { 0x00, 0x80, 0xc8 } },
    133 
    134     { PCMCIA_STR_RPTI_EP400,
    135       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    136       PCMCIA_CIS_RPTI_EP400,
    137       0, -1, { 0x00, 0x40, 0x95 } },
    138 
    139     { PCMCIA_STR_RPTI_EP401,
    140       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    141       PCMCIA_CIS_RPTI_EP401,
    142       0, -1, { 0x00, 0x40, 0x95 } },
    143 
    144     { PCMCIA_STR_ACCTON_EN2212,
    145       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    146       PCMCIA_CIS_ACCTON_EN2212,
    147       0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
    148 
    149     { PCMCIA_STR_SVEC_COMBOCARD,
    150       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    151       PCMCIA_CIS_SVEC_COMBOCARD,
    152       0, -1, { 0x00, 0xe0, 0x98 } },
    153 
    154     { PCMCIA_STR_SVEC_LANCARD,
    155       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    156       PCMCIA_CIS_SVEC_LANCARD,
    157       0, 0x7f0, { 0x00, 0xc0, 0x6c } },
    158 
    159     { PCMCIA_STR_EPSON_EEN10B,
    160       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_EPSON_EEN10B,
    161       PCMCIA_CIS_EPSON_EEN10B,
    162       0, 0xff0, { 0x00, 0x00, 0x48 } },
    163 
    164     { PCMCIA_STR_CNET_NE2000,
    165       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    166       PCMCIA_CIS_CNET_NE2000,
    167       0, -1, { 0x00, 0x80, 0xad } },
    168 
    169     /*
    170      * You have to add new entries which contains
    171      * PCMCIA_VENDOR_INVALID and/or PCMCIA_PRODUCT_INVALID
    172      * in front of this comment.
    173      *
    174      * There are cards which use a generic vendor and product id but needs
    175      * a different handling depending on the cis_info, so ne2000_match
    176      * needs a table where the exceptions comes first and then the normal
    177      * product and vendor entries.
    178      */
    179 
    180     { PCMCIA_STR_IBM_INFOMOVER,
    181       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    182       PCMCIA_CIS_IBM_INFOMOVER,
    183       0, 0x0ff0, { 0x08, 0x00, 0x5a } },
    184 
    185     { PCMCIA_STR_IBM_INFOMOVER,
    186       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    187       PCMCIA_CIS_IBM_INFOMOVER,
    188       0, 0x0ff0, { 0x00, 0x04, 0xac } },
    189 
    190     { PCMCIA_STR_IBM_INFOMOVER,
    191       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    192       PCMCIA_CIS_IBM_INFOMOVER,
    193       0, 0x0ff0, { 0x00, 0x06, 0x29 } },
    194 
    195     { PCMCIA_STR_LINKSYS_ECARD_1,
    196       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    197       PCMCIA_CIS_LINKSYS_ECARD_1,
    198       0, -1, { 0x00, 0x80, 0xc8 } },
    199 
    200     { PCMCIA_STR_PLANEX_FNW3600T,
    201       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    202       PCMCIA_CIS_PLANEX_FNW3600T,
    203       0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_DL10019 },
    204 
    205     { PCMCIA_STR_SVEC_PN650TX,
    206       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    207       PCMCIA_CIS_SVEC_PN650TX,
    208       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
    209 
    210     /*
    211      * This entry should be here so that above two cards doesn't
    212      * match with this.  FNW-3700T won't match above entries due to
    213      * MAC address check.
    214      */
    215     { PCMCIA_STR_PLANEX_FNW3700T,
    216       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    217       PCMCIA_CIS_PLANEX_FNW3700T,
    218       0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_AX88190 },
    219 
    220     { PCMCIA_STR_LINKSYS_ETHERFAST,
    221       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    222       PCMCIA_CIS_LINKSYS_ETHERFAST,
    223       0, -1, { 0x00, 0x80, 0xc8 }, NE2000DVF_DL10019 },
    224 
    225     { PCMCIA_STR_LINKSYS_ETHERFAST,
    226       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    227       PCMCIA_CIS_LINKSYS_ETHERFAST,
    228       0, -1, { 0x00, 0x90, 0xfe }, NE2000DVF_DL10019 },
    229 
    230     { PCMCIA_STR_DLINK_DE650,
    231       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    232       PCMCIA_CIS_DLINK_DE650,
    233       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
    234 
    235     { PCMCIA_STR_MELCO_LPC2_TX,
    236       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    237       PCMCIA_CIS_MELCO_LPC2_TX,
    238       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_DL10019 },
    239 
    240     { PCMCIA_STR_LINKSYS_COMBO_ECARD,
    241       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    242       PCMCIA_CIS_LINKSYS_COMBO_ECARD,
    243       0, -1, { 0x00, 0x80, 0xc8 } },
    244 
    245     { PCMCIA_STR_LINKSYS_TRUST_COMBO_ECARD,
    246       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_TRUST_COMBO_ECARD,
    247       PCMCIA_CIS_LINKSYS_TRUST_COMBO_ECARD,
    248       0, 0x0120, { 0x20, 0x04, 0x49 } },
    249 
    250     /* Although the comments above say to put VENDOR/PRODUCT INVALID IDs
    251        above this list, we need to keep this one below the ECARD_1, or else
    252        both will match the same more-generic entry rather than the more
    253        specific one above with proper vendor and product IDs. */
    254     { PCMCIA_STR_LINKSYS_ECARD_2,
    255       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    256       PCMCIA_CIS_LINKSYS_ECARD_2,
    257       0, -1, { 0x00, 0x80, 0xc8 } },
    258 
    259     /*
    260      * D-Link DE-650 has many minor versions:
    261      *
    262      *   CIS information          Manufacturer Product  Note
    263      * 1 "D-Link, DE-650"             INVALID  INVALID  white card
    264      * 2 "D-Link, DE-650, Ver 01.00"  INVALID  INVALID  became bare metal
    265      * 3 "D-Link, DE-650, Ver 01.00"   0x149    0x265   minor change in look
    266      * 4 "D-Link, DE-650, Ver 01.00"   0x149    0x265   collision LED added
    267      *
    268      * While the 1st and the 2nd types should use the "D-Link DE-650" entry,
    269      * the 3rd and the 4th types should use the "Linksys EtherCard" entry.
    270      * Therefore, this enty must be below the LINKSYS_ECARD_1.  --itohy
    271      */
    272     { PCMCIA_STR_DLINK_DE650,
    273       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    274       PCMCIA_CIS_DLINK_DE650,
    275       0, 0x0040, { 0x00, 0x80, 0xc8 } },
    276 
    277     /*
    278      * IO-DATA PCLA/TE and later version of PCLA/T has valid
    279      * vendor/product ID and it is possible to read MAC address
    280      * using standard I/O ports.  It also read from CIS offset 0x01c0.
    281      * On the other hand, earlier version of PCLA/T doesn't have valid
    282      * vendor/product ID and MAC address must be read from CIS offset
    283      * 0x0ff0 (i.e., usual ne2000 way to read it doesn't work).
    284      * And CIS information of earlier and later version of PCLA/T are
    285      * same except fourth element.  So, for now, we place the entry for
    286      * PCLA/TE (and later version of PCLA/T) followed by entry
    287      * for the earlier version of PCLA/T (or, modify to match all CIS
    288      * information and have three or more individual entries).
    289      */
    290     { PCMCIA_STR_IODATA_PCLATE,
    291       PCMCIA_VENDOR_IODATA, PCMCIA_PRODUCT_IODATA_PCLATE,
    292       PCMCIA_CIS_IODATA_PCLATE,
    293       0, -1, { 0x00, 0xa0, 0xb0 } },
    294 
    295     /*
    296      * This entry should be placed after above PCLA-TE entry.
    297      * See above comments for detail.
    298      */
    299     { PCMCIA_STR_IODATA_PCLAT,
    300       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    301       PCMCIA_CIS_IODATA_PCLAT,
    302       0, 0x0ff0, { 0x00, 0xa0, 0xb0 } },
    303 
    304     { PCMCIA_STR_DAYNA_COMMUNICARD_E_1,
    305       PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_1,
    306       PCMCIA_CIS_DAYNA_COMMUNICARD_E_1,
    307       0, 0x0110, { 0x00, 0x80, 0x19 } },
    308 
    309     { PCMCIA_STR_DAYNA_COMMUNICARD_E_2,
    310       PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_2,
    311       PCMCIA_CIS_DAYNA_COMMUNICARD_E_2,
    312       0, -1, { 0x00, 0x80, 0x19 } },
    313 
    314     { PCMCIA_STR_COREGA_ETHER_PCC_T,
    315       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_T,
    316       PCMCIA_CIS_COREGA_ETHER_PCC_T,
    317       0, -1, { 0x00, 0x00, 0xf4 } },
    318 
    319     { PCMCIA_STR_COREGA_ETHER_II_PCC_T,
    320       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_T,
    321       PCMCIA_CIS_COREGA_ETHER_II_PCC_T,
    322       0, -1, { 0x00, 0x00, 0xf4 } },
    323 
    324     { PCMCIA_STR_COREGA_FAST_ETHER_PCC_TX,
    325       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FAST_ETHER_PCC_TX,
    326       PCMCIA_CIS_COREGA_FAST_ETHER_PCC_TX,
    327       0, -1, { 0x00, 0x00, 0xf4 }, NE2000DVF_DL10019 },
    328 
    329     { PCMCIA_STR_COREGA_FETHER_PCC_TXF,
    330       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXF,
    331       PCMCIA_CIS_COREGA_FETHER_PCC_TXF,
    332       0, -1, { 0x00, 0x90, 0x99 }, NE2000DVF_DL10019 },
    333 
    334     { PCMCIA_STR_COREGA_FETHER_PCC_TXD,
    335       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXD,
    336       PCMCIA_CIS_COREGA_FETHER_PCC_TXD,
    337       0, -1, { 0x00, 0x90, 0x99 } },
    338 
    339     { PCMCIA_STR_COMPEX_LINKPORT_ENET_B,
    340       PCMCIA_VENDOR_COMPEX, PCMCIA_PRODUCT_COMPEX_LINKPORT_ENET_B,
    341       PCMCIA_CIS_COMPEX_LINKPORT_ENET_B,
    342       0, 0x01c0, { 0x00, 0xa0, 0x0c } },
    343 
    344     { PCMCIA_STR_SMC_EZCARD,
    345       PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_EZCARD,
    346       PCMCIA_CIS_SMC_EZCARD,
    347       0, 0x01c0, { 0x00, 0xe0, 0x29 } },
    348 
    349     { PCMCIA_STR_SOCKET_EA_ETHER,
    350       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_EA_ETHER,
    351       PCMCIA_CIS_SOCKET_EA_ETHER,
    352       0, -1, { 0x00, 0xc0, 0x1b } },
    353 
    354     { PCMCIA_STR_SOCKET_LP_ETHER_CF,
    355       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER_CF,
    356       PCMCIA_CIS_SOCKET_LP_ETHER_CF,
    357       0, -1, { 0x00, 0xc0, 0x1b } },
    358 
    359     { PCMCIA_STR_SOCKET_LP_ETHER,
    360       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER,
    361       PCMCIA_CIS_SOCKET_LP_ETHER,
    362       0, -1, { 0x00, 0xc0, 0x1b } },
    363 
    364     { PCMCIA_STR_KINGSTON_KNE2,
    365       PCMCIA_VENDOR_KINGSTON, PCMCIA_PRODUCT_KINGSTON_KNE2,
    366       PCMCIA_CIS_KINGSTON_KNE2,
    367       0, -1, { 0x00, 0xc0, 0xf0 } },
    368 
    369     { PCMCIA_STR_XIRCOM_CFE_10,
    370       PCMCIA_VENDOR_XIRCOM, PCMCIA_PRODUCT_XIRCOM_CFE_10,
    371       PCMCIA_CIS_XIRCOM_CFE_10,
    372       0, -1, { 0x00, 0x10, 0xa4 } },
    373 
    374     { PCMCIA_STR_MELCO_LPC3_TX,
    375       PCMCIA_VENDOR_MELCO, PCMCIA_PRODUCT_MELCO_LPC3_TX,
    376       PCMCIA_CIS_MELCO_LPC3_TX,
    377       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
    378 
    379     { PCMCIA_STR_BILLIONTON_LNT10TN,
    380       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    381       PCMCIA_CIS_BILLIONTON_LNT10TN,
    382       0, -1, { 0x00, 0x00, 0x00 } },
    383 
    384     { PCMCIA_STR_NDC_ND5100_E,
    385       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    386       PCMCIA_CIS_NDC_ND5100_E,
    387       0, -1, { 0x00, 0x80, 0xc6 } },
    388 
    389     { PCMCIA_STR_TELECOMDEVICE_TCD_HPC100,
    390       PCMCIA_VENDOR_TELECOMDEVICE, PCMCIA_PRODUCT_TELECOMDEVICE_TCD_HPC100,
    391       PCMCIA_CIS_TELECOMDEVICE_TCD_HPC100,
    392       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
    393 
    394     { PCMCIA_STR_MACNICA_ME1_JEIDA,
    395       PCMCIA_VENDOR_MACNICA, PCMCIA_PRODUCT_MACNICA_ME1_JEIDA,
    396       PCMCIA_CIS_MACNICA_ME1_JEIDA,
    397       0, 0x00b8, { 0x08, 0x00, 0x42 } },
    398 
    399 #if 0
    400     /* the rest of these are stolen from the linux pcnet pcmcia device
    401        driver.  Since I don't know the manfid or cis info strings for
    402        any of them, they're not compiled in until I do. */
    403     { "APEX MultiCard",
    404       0x0000, 0x0000, NULL, NULL, 0,
    405       0x03f4, { 0x00, 0x20, 0xe5 } },
    406     { "ASANTE FriendlyNet",
    407       0x0000, 0x0000, NULL, NULL, 0,
    408       0x4910, { 0x00, 0x00, 0x94 } },
    409     { "Danpex EN-6200P2",
    410       0x0000, 0x0000, NULL, NULL, 0,
    411       0x0110, { 0x00, 0x40, 0xc7 } },
    412     { "DataTrek NetCard",
    413       0x0000, 0x0000, NULL, NULL, 0,
    414       0x0ff0, { 0x00, 0x20, 0xe8 } },
    415     { "Dayna CommuniCard E",
    416       0x0000, 0x0000, NULL, NULL, 0,
    417       0x0110, { 0x00, 0x80, 0x19 } },
    418     { "EP-210 Ethernet",
    419       0x0000, 0x0000, NULL, NULL, 0,
    420       0x0110, { 0x00, 0x40, 0x33 } },
    421     { "ELECOM Laneed LD-CDWA",
    422       0x0000, 0x0000, NULL, NULL, 0,
    423       0x00b8, { 0x08, 0x00, 0x42 } },
    424     { "Grey Cell GCS2220",
    425       0x0000, 0x0000, NULL, NULL, 0,
    426       0x0000, { 0x00, 0x47, 0x43 } },
    427     { "Hypertec Ethernet",
    428       0x0000, 0x0000, NULL, NULL, 0,
    429       0x01c0, { 0x00, 0x40, 0x4c } },
    430     { "IBM CCAE",
    431       0x0000, 0x0000, NULL, NULL, 0,
    432       0x0ff0, { 0x08, 0x00, 0x5a } },
    433     { "IBM CCAE",
    434       0x0000, 0x0000, NULL, NULL, 0,
    435       0x0ff0, { 0x00, 0x04, 0xac } },
    436     { "IBM CCAE",
    437       0x0000, 0x0000, NULL, NULL, 0,
    438       0x0ff0, { 0x00, 0x06, 0x29 } },
    439     { "IBM FME",
    440       0x0000, 0x0000, NULL, NULL, 0,
    441       0x0374, { 0x00, 0x04, 0xac } },
    442     { "IBM FME",
    443       0x0000, 0x0000, NULL, NULL, 0,
    444       0x0374, { 0x08, 0x00, 0x5a } },
    445     { "Katron PE-520",
    446       0x0000, 0x0000, NULL, NULL, 0,
    447       0x0110, { 0x00, 0x40, 0xf6 } },
    448     { "Kingston KNE-PCM/x",
    449       0x0000, 0x0000, NULL, NULL, 0,
    450       0x0ff0, { 0x00, 0xc0, 0xf0 } },
    451     { "Kingston KNE-PCM/x",
    452       0x0000, 0x0000, NULL, NULL, 0,
    453       0x0ff0, { 0xe2, 0x0c, 0x0f } },
    454     { "Longshine LCS-8534",
    455       0x0000, 0x0000, NULL, NULL, 0,
    456       0x0000, { 0x08, 0x00, 0x00 } },
    457     { "Maxtech PCN2000",
    458       0x0000, 0x0000, NULL, NULL, 0,
    459       0x5000, { 0x00, 0x00, 0xe8 } },
    460     { "NDC Instant-Link",
    461       0x0000, 0x0000, NULL, NULL, 0,
    462       0x003a, { 0x00, 0x80, 0xc6 } },
    463     { "NE2000 Compatible",
    464       0x0000, 0x0000, NULL, NULL, 0,
    465       0x0ff0, { 0x00, 0xa0, 0x0c } },
    466     { "Network General Sniffer",
    467       0x0000, 0x0000, NULL, NULL, 0,
    468       0x0ff0, { 0x00, 0x00, 0x65 } },
    469     { "Panasonic VEL211",
    470       0x0000, 0x0000, NULL, NULL, 0,
    471       0x0ff0, { 0x00, 0x80, 0x45 } },
    472     { "SCM Ethernet",
    473       0x0000, 0x0000, NULL, NULL, 0,
    474       0x0ff0, { 0x00, 0x20, 0xcb } },
    475     { "Volktek NPL-402CT",
    476       0x0000, 0x0000, NULL, NULL, 0,
    477       0x0060, { 0x00, 0x40, 0x05 } },
    478 #endif
    479 
    480     { PCMCIA_STR_ALLIEDTELESIS_LA_PCM,
    481       PCMCIA_VENDOR_ALLIEDTELESIS, PCMCIA_PRODUCT_ALLIEDTELESIS_LA_PCM,
    482       PCMCIA_CIS_ALLIEDTELESIS_LA_PCM,
    483       0, 0x0ff0, { 0x00, 0x00, 0xf4 } },
    484 };
    485 
    486 #define	NE2000_NDEVS	(sizeof(ne2000devs) / sizeof(ne2000devs[0]))
    487 
    488 #define ne2000_match(card, fct, n) \
    489 ((((((card)->manufacturer != PCMCIA_VENDOR_INVALID) && \
    490     ((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
    491     ((card)->product != PCMCIA_PRODUCT_INVALID) && \
    492     ((card)->product == ne2000devs[(n)].product)) || \
    493    ((ne2000devs[(n)].cis_info[0]) && (ne2000devs[(n)].cis_info[1]) && \
    494     (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis_info[0]) == 0) && \
    495     (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis_info[1]) == 0))) && \
    496   ((fct) == ne2000devs[(n)].function))? \
    497  &ne2000devs[(n)]:NULL)
    498 
    499 int
    500 ne_pcmcia_match(parent, match, aux)
    501 	struct device *parent;
    502 	struct cfdata *match;
    503 	void *aux;
    504 {
    505 	struct pcmcia_attach_args *pa = aux;
    506 	int i;
    507 
    508 	for (i = 0; i < NE2000_NDEVS; i++) {
    509 		if (ne2000_match(pa->card, pa->pf->number, i))
    510 			return (1);
    511 	}
    512 
    513 	return (0);
    514 }
    515 
    516 void
    517 ne_pcmcia_attach(parent, self, aux)
    518 	struct device *parent, *self;
    519 	void *aux;
    520 {
    521 	struct ne_pcmcia_softc *psc = (void *) self;
    522 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    523 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    524 	struct pcmcia_attach_args *pa = aux;
    525 	struct pcmcia_config_entry *cfe;
    526 	const struct ne2000dev *ne_dev;
    527 	int i;
    528 	u_int8_t myea[6], *enaddr;
    529 	const char *typestr = "";
    530 
    531 	psc->sc_pf = pa->pf;
    532 
    533 	for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
    534 	    cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
    535 #if 0
    536 		/*
    537 		 * Some ne2000 driver's claim to have memory; others don't.
    538 		 * Since I don't care, I don't check.
    539 		 */
    540 
    541 		if (cfe->num_memspace != 1) {
    542 			printf(": unexpected number of memory spaces "
    543 			    " %d should be 1\n", cfe->num_memspace);
    544 			continue;
    545 		}
    546 #endif
    547 
    548 		if (cfe->num_iospace == 1) {
    549 			if (cfe->iospace[0].length != NE2000_NPORTS) {
    550 				printf(": unexpected I/O space configuration"
    551 				    " (continued)\n%s", dsc->sc_dev.dv_xname);
    552 				/* XXX really safe for all other cards? */
    553 			}
    554 		} else if (cfe->num_iospace == 2) {
    555 			/*
    556 			 * Some cards report a separate space for NIC and ASIC.
    557 			 * This make some sense, but we must allocate a single
    558 			 * NE2000_NPORTS-sized chunk, due to brain damaged
    559 			 * address decoders on some of these cards.
    560 			 */
    561 			if (cfe->iospace[0].length + cfe->iospace[1].length !=
    562 			    NE2000_NPORTS) {
    563 #ifdef DIAGNOSTIC
    564 				printf(": unexpected I/O "
    565 				    "space configuration; ignored\n%s",
    566 				    dsc->sc_dev.dv_xname);
    567 #endif
    568 				continue;
    569 			}
    570 		} else {
    571 #ifdef DIAGNOSTIC
    572 			printf(": unexpected number of i/o spaces %d"
    573 			    " should be 1 or 2; ignored\n%s",
    574 			    cfe->num_iospace, dsc->sc_dev.dv_xname);
    575 #endif
    576 			continue;
    577 		}
    578 
    579 		if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
    580 		    NE2000_NPORTS, NE2000_NPORTS, &psc->sc_pcioh)) {
    581 #ifdef DIAGNOSTIC
    582 			printf(": can't allocate i/o space %lx; ignored\n%s",
    583 			    cfe->iospace[0].start, dsc->sc_dev.dv_xname);
    584 #endif
    585 			continue;
    586 		}
    587 
    588 		/* Ok, found. */
    589 		break;
    590 	}
    591 
    592 	if (cfe == NULL) {
    593 		printf(": no suitable config entry\n");
    594 		goto fail_1;
    595 	}
    596 
    597 	dsc->sc_regt = psc->sc_pcioh.iot;
    598 	dsc->sc_regh = psc->sc_pcioh.ioh;
    599 
    600 	nsc->sc_asict = psc->sc_pcioh.iot;
    601 	if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
    602 	    NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
    603 	    &nsc->sc_asich)) {
    604 		printf(": can't get subregion for asic\n");
    605 		goto fail_2;
    606 	}
    607 
    608 	/* Set up power management hooks. */
    609 	dsc->sc_enable = ne_pcmcia_enable;
    610 	dsc->sc_disable = ne_pcmcia_disable;
    611 
    612 	/* Enable the card. */
    613 	pcmcia_function_init(pa->pf, cfe);
    614 	if (pcmcia_function_enable(pa->pf)) {
    615 		printf(": function enable failed\n");
    616 		goto fail_2;
    617 	}
    618 
    619 	/* some cards claim to be io16, but they're lying. */
    620 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
    621 	    NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
    622 	    &psc->sc_pcioh, &psc->sc_nic_io_window)) {
    623 		printf(": can't map NIC i/o space\n");
    624 		goto fail_3;
    625 	}
    626 
    627 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
    628 	    NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
    629 	    &psc->sc_pcioh, &psc->sc_asic_io_window)) {
    630 		printf(": can't map ASIC i/o space\n");
    631 		goto fail_4;
    632 	}
    633 
    634 	printf("\n");
    635 
    636 	/*
    637 	 * Read the station address from the board.
    638 	 */
    639 	i = 0;
    640 again:
    641 	enaddr = NULL;			/* Ask ASIC by default */
    642 	for (; i < NE2000_NDEVS; i++) {
    643 		ne_dev = ne2000_match(pa->card, pa->pf->number, i);
    644 		if (ne_dev != NULL) {
    645 			if (ne_dev->enet_maddr >= 0) {
    646 				enaddr = ne_pcmcia_get_enaddr(psc,
    647 				    ne_dev->enet_maddr, myea);
    648 				if (enaddr == NULL)
    649 					continue;
    650 			}
    651 			break;
    652 		}
    653 	}
    654 	if (i == NE2000_NDEVS) {
    655 		printf("%s: can't match ethernet vendor code\n",
    656 		    dsc->sc_dev.dv_xname);
    657 		goto fail_5;
    658 	}
    659 
    660 	if ((ne_dev->flags & NE2000DVF_DL10019) != 0) {
    661 		u_int8_t type;
    662 
    663 		enaddr = ne_pcmcia_dl10019_get_enaddr(psc, myea);
    664 		if (enaddr == NULL) {
    665 			++i;
    666 			goto again;
    667 		}
    668 
    669 		dsc->sc_mediachange = dl10019_mediachange;
    670 		dsc->sc_mediastatus = dl10019_mediastatus;
    671 		dsc->init_card = dl10019_init_card;
    672 		dsc->stop_card = dl10019_stop_card;
    673 		dsc->sc_media_init = dl10019_media_init;
    674 		dsc->sc_media_fini = dl10019_media_fini;
    675 
    676 		/* Determine if this is a DL10019 or a DL10022. */
    677 		type = bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 0x0f);
    678 		if (type == 0x91 || type == 0x99) {
    679 			nsc->sc_type = NE2000_TYPE_DL10022;
    680 			typestr = " (DL10022)";
    681 		} else {
    682 			nsc->sc_type = NE2000_TYPE_DL10019;
    683 			typestr = " (DL10019)";
    684 		}
    685 	}
    686 
    687 	if ((ne_dev->flags & NE2000DVF_AX88190) != 0) {
    688 		if (ne_pcmcia_ax88190_set_iobase(psc)) {
    689 			++i;
    690 			goto again;
    691 		}
    692 		nsc->sc_type = NE2000_TYPE_AX88190;
    693 		typestr = " (AX88190)";
    694 	}
    695 
    696 	if (enaddr != NULL) {
    697 		/*
    698 		 * Make sure this is what we expect.
    699 		 */
    700 		if (enaddr[0] != ne_dev->enet_vendor[0] ||
    701 		    enaddr[1] != ne_dev->enet_vendor[1] ||
    702 		    enaddr[2] != ne_dev->enet_vendor[2]) {
    703 			++i;
    704 			goto again;
    705 		}
    706 	}
    707 
    708 	/*
    709 	 * Check for a RealTek 8019.
    710 	 */
    711 	if (nsc->sc_type == 0) {
    712 		bus_space_write_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CR,
    713 		    ED_CR_PAGE_0 | ED_CR_STP);
    714 		if (bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
    715 		    NERTL_RTL0_8019ID0) == RTL0_8019ID0 &&
    716 		    bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
    717 		    NERTL_RTL0_8019ID1) == RTL0_8019ID1) {
    718 			typestr = " (RTL8019)";
    719 			dsc->sc_mediachange = rtl80x9_mediachange;
    720 			dsc->sc_mediastatus = rtl80x9_mediastatus;
    721 				dsc->init_card = rtl80x9_init_card;
    722 			dsc->sc_media_init = rtl80x9_media_init;
    723 		}
    724 	}
    725 
    726 	printf("%s: %s%s Ethernet\n", dsc->sc_dev.dv_xname, ne_dev->name,
    727 	    typestr);
    728 
    729 	if (ne2000_attach(nsc, enaddr))
    730 		goto fail_5;
    731 
    732 	pcmcia_function_disable(pa->pf);
    733 	return;
    734 
    735  fail_5:
    736 	/* Unmap ASIC i/o windows. */
    737 	pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
    738 
    739  fail_4:
    740 	/* Unmap NIC i/o windows. */
    741 	pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
    742 
    743  fail_3:
    744 	pcmcia_function_disable(pa->pf);
    745 
    746  fail_2:
    747 	/* Free our i/o space. */
    748 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    749 
    750  fail_1:
    751 	psc->sc_nic_io_window = -1;
    752 }
    753 
    754 int
    755 ne_pcmcia_detach(self, flags)
    756 	struct device *self;
    757 	int flags;
    758 {
    759 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)self;
    760 	int error;
    761 
    762 	if (psc->sc_nic_io_window == -1)
    763 		/* Nothing to detach. */
    764 		return (0);
    765 
    766 	error = ne2000_detach(&psc->sc_ne2000, flags);
    767 	if (error != 0)
    768 		return (error);
    769 
    770 	/* Unmap our i/o windows. */
    771 	pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
    772 	pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
    773 
    774 	/* Free our i/o space. */
    775 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    776 
    777 	return (0);
    778 }
    779 
    780 int
    781 ne_pcmcia_enable(dsc)
    782 	struct dp8390_softc *dsc;
    783 {
    784 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
    785 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    786 
    787 	/* set up the interrupt */
    788 	psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
    789 	    dsc);
    790 	if (psc->sc_ih == NULL) {
    791 		printf("%s: couldn't establish interrupt\n",
    792 		    dsc->sc_dev.dv_xname);
    793 		goto fail_1;
    794 	}
    795 
    796 	if (pcmcia_function_enable(psc->sc_pf))
    797 		goto fail_2;
    798 
    799 	if (nsc->sc_type == NE2000_TYPE_AX88190)
    800 		if (ne_pcmcia_ax88190_set_iobase(psc))
    801 			goto fail_3;
    802 
    803 	return (0);
    804 
    805  fail_3:
    806 	pcmcia_function_disable(psc->sc_pf);
    807  fail_2:
    808 	pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
    809  fail_1:
    810 	return (1);
    811 }
    812 
    813 void
    814 ne_pcmcia_disable(dsc)
    815 	struct dp8390_softc *dsc;
    816 {
    817 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
    818 
    819 	pcmcia_function_disable(psc->sc_pf);
    820 	pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
    821 }
    822 
    823 u_int8_t *
    824 ne_pcmcia_get_enaddr(psc, maddr, myea)
    825 	struct ne_pcmcia_softc *psc;
    826 	int maddr;
    827 	u_int8_t myea[ETHER_ADDR_LEN];
    828 {
    829 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    830 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    831 	struct pcmcia_mem_handle pcmh;
    832 	bus_addr_t offset;
    833 	u_int8_t *enaddr = NULL;
    834 	int j, mwindow;
    835 
    836 	if (maddr < 0)
    837 		return (NULL);
    838 
    839 	if (pcmcia_mem_alloc(psc->sc_pf, ETHER_ADDR_LEN * 2, &pcmh)) {
    840 		printf("%s: can't alloc mem for enet addr\n",
    841 		    dsc->sc_dev.dv_xname);
    842 		goto fail_1;
    843 	}
    844 	if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, maddr,
    845 	    ETHER_ADDR_LEN * 2, &pcmh, &offset, &mwindow)) {
    846 		printf("%s: can't map mem for enet addr\n",
    847 		    dsc->sc_dev.dv_xname);
    848 		goto fail_2;
    849 	}
    850 	for (j = 0; j < ETHER_ADDR_LEN; j++)
    851 		myea[j] = bus_space_read_1(pcmh.memt, pcmh.memh,
    852 		    offset + (j * 2));
    853 	enaddr = myea;
    854 
    855 	pcmcia_mem_unmap(psc->sc_pf, mwindow);
    856  fail_2:
    857 	pcmcia_mem_free(psc->sc_pf, &pcmh);
    858  fail_1:
    859 	return (enaddr);
    860 }
    861 
    862 u_int8_t *
    863 ne_pcmcia_dl10019_get_enaddr(psc, myea)
    864 	struct ne_pcmcia_softc *psc;
    865 	u_int8_t myea[ETHER_ADDR_LEN];
    866 {
    867 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    868 	u_int8_t sum;
    869 	int j;
    870 
    871 #define PAR0	0x04
    872 	for (j = 0, sum = 0; j < 8; j++)
    873 		sum += bus_space_read_1(nsc->sc_asict, nsc->sc_asich,
    874 		    PAR0 + j);
    875 	if (sum != 0xff)
    876 		return (NULL);
    877 	for (j = 0; j < ETHER_ADDR_LEN; j++)
    878 		myea[j] = bus_space_read_1(nsc->sc_asict,
    879 		    nsc->sc_asich, PAR0 + j);
    880 #undef PAR0
    881 	return (myea);
    882 }
    883 
    884 int
    885 ne_pcmcia_ax88190_set_iobase(psc)
    886 	struct ne_pcmcia_softc *psc;
    887 {
    888 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    889 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    890 	struct pcmcia_mem_handle pcmh;
    891 	bus_addr_t offset;
    892 	int rv = 1, mwindow;
    893 	u_int last_liobase, new_liobase;
    894 
    895 	if (pcmcia_mem_alloc(psc->sc_pf, NE2000_AX88190_LAN_IOSIZE, &pcmh)) {
    896 #if 0
    897 		printf("%s: can't alloc mem for LAN iobase\n",
    898 		    dsc->sc_dev.dv_xname);
    899 #endif
    900 		goto fail_1;
    901 	}
    902 	if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
    903 	    NE2000_AX88190_LAN_IOBASE, NE2000_AX88190_LAN_IOSIZE,
    904 	    &pcmh, &offset, &mwindow)) {
    905 		printf("%s: can't map mem for LAN iobase\n",
    906 		    dsc->sc_dev.dv_xname);
    907 		goto fail_2;
    908 	}
    909 
    910 	last_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
    911 	    (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
    912 #ifdef DIAGNOSTIC
    913 	printf("%s: LAN iobase 0x%x (0x%x) ->", dsc->sc_dev.dv_xname,
    914 	    last_liobase, (u_int)psc->sc_pcioh.addr);
    915 #endif
    916 	bus_space_write_1(pcmh.memt, pcmh.memh, offset,
    917 	    psc->sc_pcioh.addr & 0xff);
    918 	bus_space_write_1(pcmh.memt, pcmh.memh, offset + 2,
    919 	    psc->sc_pcioh.addr >> 8);
    920 
    921 	new_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
    922 	    (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
    923 #ifdef DIAGNOSTIC
    924 	printf(" 0x%x\n", new_liobase);
    925 #endif
    926 	if ((last_liobase == psc->sc_pcioh.addr)
    927 	    || (last_liobase != new_liobase))
    928 		rv = 0;
    929 
    930 	pcmcia_mem_unmap(psc->sc_pf, mwindow);
    931  fail_2:
    932 	pcmcia_mem_free(psc->sc_pf, &pcmh);
    933  fail_1:
    934 	return (rv);
    935 }
    936