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