Home | History | Annotate | Line # | Download | only in pcmcia
if_ne_pcmcia.c revision 1.146
      1 /*	$NetBSD: if_ne_pcmcia.c,v 1.146 2006/09/23 15:39:51 jmcneill 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/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: if_ne_pcmcia.c,v 1.146 2006/09/23 15:39:51 jmcneill Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/select.h>
     38 #include <sys/device.h>
     39 #include <sys/socket.h>
     40 
     41 #include <net/if_types.h>
     42 #include <net/if.h>
     43 #include <net/if_media.h>
     44 #include <net/if_ether.h>
     45 
     46 #include <machine/bus.h>
     47 #include <machine/intr.h>
     48 
     49 #include <dev/pcmcia/pcmciareg.h>
     50 #include <dev/pcmcia/pcmciavar.h>
     51 #include <dev/pcmcia/pcmciadevs.h>
     52 
     53 #include <dev/ic/dp8390reg.h>
     54 #include <dev/ic/dp8390var.h>
     55 
     56 #include <dev/ic/ne2000reg.h>
     57 #include <dev/ic/ne2000var.h>
     58 
     59 #include <dev/ic/rtl80x9reg.h>
     60 #include <dev/ic/rtl80x9var.h>
     61 
     62 #include <dev/ic/dl10019var.h>
     63 
     64 #include <dev/ic/ax88190reg.h>
     65 #include <dev/ic/ax88190var.h>
     66 
     67 int	ne_pcmcia_match(struct device *, struct cfdata *, void *);
     68 int	ne_pcmcia_validate_config(struct pcmcia_config_entry *);
     69 void	ne_pcmcia_attach(struct device *, struct device *, void *);
     70 int	ne_pcmcia_detach(struct device *, int);
     71 
     72 int	ne_pcmcia_enable(struct dp8390_softc *);
     73 void	ne_pcmcia_disable(struct dp8390_softc *);
     74 
     75 struct ne_pcmcia_softc {
     76 	struct ne2000_softc sc_ne2000;		/* real "ne2000" softc */
     77 
     78 	void *sc_ih;				/* interrupt handle */
     79 
     80 	struct pcmcia_function *sc_pf;		/* our PCMCIA function */
     81 	int sc_state;
     82 #define	NE_PCMCIA_ATTACHED	3
     83 	void *sc_powerhook;			/* power management hook */
     84 };
     85 
     86 u_int8_t *ne_pcmcia_get_enaddr(struct ne_pcmcia_softc *, int,
     87 	    u_int8_t [ETHER_ADDR_LEN]);
     88 u_int8_t *ne_pcmcia_dl10019_get_enaddr(struct ne_pcmcia_softc *,
     89 	    u_int8_t [ETHER_ADDR_LEN]);
     90 
     91 CFATTACH_DECL(ne_pcmcia, sizeof(struct ne_pcmcia_softc),
     92     ne_pcmcia_match, ne_pcmcia_attach, ne_pcmcia_detach, dp8390_activate);
     93 
     94 static const struct ne2000dev {
     95     int32_t manufacturer;
     96     int32_t product;
     97     const char *cis_info[4];
     98     int function;
     99     int enet_maddr;
    100     unsigned char enet_vendor[3];
    101     int flags;
    102 #define	NE2000DVF_DL10019	0x0001		/* chip is D-Link DL10019 */
    103 #define	NE2000DVF_AX88190	0x0002		/* chip is ASIX AX88190 */
    104 } ne2000devs[] = {
    105     { PCMCIA_VENDOR_EDIMAX, PCMCIA_PRODUCT_EDIMAX_EP4000A,
    106       PCMCIA_CIS_INVALID,
    107       0, -1, { 0x00, 0xa0, 0x0c }, 0 },
    108 
    109     { PCMCIA_VENDOR_EDIMAX, PCMCIA_PRODUCT_EDIMAX_EP4101,
    110       PCMCIA_CIS_INVALID,
    111       0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_AX88190 },
    112 
    113     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    114       PCMCIA_CIS_SYNERGY21_S21810,
    115       0, -1, { 0x00, 0x48, 0x54 }, 0 },
    116 
    117     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    118       PCMCIA_CIS_AMBICOM_AMB8002T,
    119       0, -1, { 0x00, 0x10, 0x7a }, 0 },
    120 
    121     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    122       PCMCIA_CIS_AMBICOM_AMB8110,
    123       0, -1, { 0x00, 0x10, 0x7a }, NE2000DVF_AX88190 },
    124 
    125     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    126       PCMCIA_CIS_PREMAX_PE200,
    127       0, 0x07f0, { 0x00, 0x20, 0xe0 }, 0 },
    128 
    129     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    130       PCMCIA_CIS_PREMAX_PE200,
    131       0, -1, { 0x00, 0x20, 0xe0 }, 0 },
    132 
    133     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    134       PCMCIA_CIS_PLANET_SMARTCOM2000,
    135       0, 0xff0, { 0x00, 0x00, 0xe8 }, 0 },
    136 
    137     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    138       PCMCIA_CIS_DLINK_DE660,
    139       0, -1, { 0x00, 0x80, 0xc8 }, 0 },
    140 
    141     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    142       PCMCIA_CIS_DLINK_DE660PLUS,
    143       0, -1, { 0x00, 0x80, 0xc8 }, 0 },
    144 
    145     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    146       PCMCIA_CIS_RPTI_EP400,
    147       0, 0x110, { 0x00, 0x40, 0x95 }, 0 },
    148 
    149     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    150       PCMCIA_CIS_RPTI_EP401,
    151       0, -1, { 0x00, 0x40, 0x95 }, 0 },
    152 
    153     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    154       PCMCIA_CIS_ACCTON_EN2212,
    155       0, 0x0ff0, { 0x00, 0x00, 0xe8 }, 0 },
    156 
    157     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    158       PCMCIA_CIS_ACCTON_EN2216,
    159       0, -1, { 0x00, 0x00, 0xe8 }, 0 },
    160 
    161     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    162       PCMCIA_CIS_SVEC_COMBOCARD,
    163       0, -1, { 0x00, 0xe0, 0x98 }, 0 },
    164 
    165     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    166       PCMCIA_CIS_SVEC_LANCARD,
    167       0, 0x7f0, { 0x00, 0xc0, 0x6c }, 0 },
    168 
    169     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_EPSON_EEN10B,
    170       PCMCIA_CIS_EPSON_EEN10B,
    171       0, 0xff0, { 0x00, 0x00, 0x48 }, 0 },
    172 
    173     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    174       PCMCIA_CIS_TAMARACK_ETHERNET,
    175       0, -1, { 0x00, 0x00, 0x00 }, 0 },
    176 
    177     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    178       PCMCIA_CIS_CNET_NE2000,
    179       0, -1, { 0x00, 0x80, 0xad }, 0 },
    180 
    181     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    182       PCMCIA_CIS_GENIUS_ME3000II,
    183       0, -1, { 0x00, 0x40, 0x95 }, 0 },
    184 
    185 
    186     /*
    187      * You have to add new entries which contains
    188      * PCMCIA_VENDOR_INVALID and/or PCMCIA_PRODUCT_INVALID
    189      * in front of this comment.
    190      *
    191      * There are cards which use a generic vendor and product id but needs
    192      * a different handling depending on the cis_info, so ne2000_match
    193      * needs a table where the exceptions comes first and then the normal
    194      * product and vendor entries.
    195      */
    196 
    197     { PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
    198       PCMCIA_CIS_INVALID,
    199       0, 0x0ff0, { 0xff, 0xff, 0xff }, 0 },
    200 
    201     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    202       PCMCIA_CIS_INVALID,
    203       0, -1, { 0x00, 0x80, 0xc8 }, 0 },
    204 
    205     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    206       PCMCIA_CIS_INVALID,
    207       0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_DL10019 },
    208 
    209     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    210       PCMCIA_CIS_INVALID,
    211       0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_AX88190 },
    212 
    213     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    214       PCMCIA_CIS_LANTECH_FASTNETTX,
    215       0, -1, { 0x00, 0x04, 0x1c }, NE2000DVF_AX88190 },
    216 
    217     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
    218       PCMCIA_CIS_INVALID,
    219       0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_DL10019 },
    220 
    221     { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
    222       PCMCIA_CIS_INVALID,
    223       0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_DL10019 },
    224 
    225     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    226       PCMCIA_CIS_DLINK_DFE670TXD,
    227       0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_DL10019 },
    228 
    229     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    230       PCMCIA_CIS_MELCO_LPC2_TX,
    231       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_DL10019 },
    232 
    233     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
    234       PCMCIA_CIS_INVALID,
    235       0, -1, { 0x00, 0x80, 0xc8 }, 0 },
    236 
    237     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_TRUST_COMBO_ECARD,
    238       PCMCIA_CIS_INVALID,
    239       0, 0x0120, { 0x20, 0x04, 0x49 }, 0 },
    240 
    241     /* Although the comments above say to put VENDOR/PRODUCT INVALID IDs
    242        above this list, we need to keep this one below the ECARD_1, or else
    243        both will match the same more-generic entry rather than the more
    244        specific one above with proper vendor and product IDs. */
    245     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    246       PCMCIA_CIS_LINKSYS_ECARD_2,
    247       0, -1, { 0x00, 0x80, 0xc8 }, 0 },
    248 
    249     /*
    250      * D-Link DE-650 has many minor versions:
    251      *
    252      *   CIS information          Manufacturer Product  Note
    253      * 1 "D-Link, DE-650"             INVALID  INVALID  white card
    254      * 2 "D-Link, DE-650, Ver 01.00"  INVALID  INVALID  became bare metal
    255      * 3 "D-Link, DE-650, Ver 01.00"   0x149    0x265   minor change in look
    256      * 4 "D-Link, DE-650, Ver 01.00"   0x149    0x265   collision LED added
    257      *
    258      * While the 1st and the 2nd types should use the "D-Link DE-650" entry,
    259      * the 3rd and the 4th types should use the "Linksys EtherCard" entry.
    260      * Therefore, this enty must be below the LINKSYS_ECARD_1.  --itohy
    261      */
    262     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    263       PCMCIA_CIS_DLINK_DE650,
    264       0, 0x0040, { 0x00, 0x80, 0xc8 }, 0 },
    265 
    266     /*
    267      * IO-DATA PCLA/TE and later version of PCLA/T has valid
    268      * vendor/product ID and it is possible to read MAC address
    269      * using standard I/O ports.  It also read from CIS offset 0x01c0.
    270      * On the other hand, earlier version of PCLA/T doesn't have valid
    271      * vendor/product ID and MAC address must be read from CIS offset
    272      * 0x0ff0 (i.e., usual ne2000 way to read it doesn't work).
    273      * And CIS information of earlier and later version of PCLA/T are
    274      * same except fourth element.  So, for now, we place the entry for
    275      * PCLA/TE (and later version of PCLA/T) followed by entry
    276      * for the earlier version of PCLA/T (or, modify to match all CIS
    277      * information and have three or more individual entries).
    278      */
    279     { PCMCIA_VENDOR_IODATA, PCMCIA_PRODUCT_IODATA_PCLATE,
    280       PCMCIA_CIS_INVALID,
    281       0, -1, { 0xff, 0xff, 0xff }, 0 },
    282 
    283     { PCMCIA_VENDOR_IODATA3, PCMCIA_PRODUCT_IODATA3_PCETTXR,
    284       PCMCIA_CIS_IODATA3_PCETTXR,
    285       0, -1, { 0x00, 0xa0, 0xb0 }, NE2000DVF_DL10019 },
    286 
    287     /*
    288      * This entry should be placed after above PCLA-TE entry.
    289      * See above comments for detail.
    290      */
    291     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    292       PCMCIA_CIS_IODATA_PCLAT,
    293       0, 0x0ff0, { 0x00, 0xa0, 0xb0 }, 0 },
    294 
    295     { PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_1,
    296       PCMCIA_CIS_INVALID,
    297       0, 0x0110, { 0x00, 0x80, 0x19 }, 0 },
    298 
    299     { PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_2,
    300       PCMCIA_CIS_INVALID,
    301       0, -1, { 0x00, 0x80, 0x19 }, 0 },
    302 
    303     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    304       PCMCIA_CIS_COREGA_ETHER_PCC_T,
    305       0, -1, { 0x00, 0x00, 0xf4 }, 0 },
    306 
    307     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    308       PCMCIA_CIS_COREGA_ETHER_PCC_TD,
    309       0, -1, { 0x00, 0x00, 0xf4 }, 0 },
    310 
    311     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    312       PCMCIA_CIS_COREGA_ETHER_PCC_TL,
    313       0, -1, { 0x00, 0x00, 0xf4 }, 0 },
    314 
    315     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    316       PCMCIA_CIS_COREGA_ETHER_II_PCC_T,
    317       0, -1, { 0x00, 0x00, 0xf4 }, 0 },
    318 
    319     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    320       PCMCIA_CIS_COREGA_ETHER_II_PCC_TD,
    321       0, -1, { 0x00, 0x00, 0xf4 }, 0 },
    322 
    323     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    324       PCMCIA_CIS_COREGA_FAST_ETHER_PCC_TX,
    325       0, -1, { 0x00, 0x00, 0xf4 }, NE2000DVF_DL10019 },
    326 
    327     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    328       PCMCIA_CIS_COREGA_FETHER_PCC_TXF,
    329       0, -1, { 0x00, 0x90, 0x99 }, NE2000DVF_DL10019 },
    330 
    331     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    332       PCMCIA_CIS_COREGA_FETHER_PCC_TXD,
    333       0, -1, { 0x00, 0x90, 0x99 }, 0 },
    334 
    335     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    336       PCMCIA_CIS_COREGA_FETHER_II_PCC_TXD,
    337       0, -1, { 0x00, 0x90, 0x99 }, NE2000DVF_AX88190 },
    338 
    339     { PCMCIA_VENDOR_COMPEX, PCMCIA_PRODUCT_COMPEX_LINKPORT_ENET_B,
    340       PCMCIA_CIS_INVALID,
    341       0, 0x01c0, { 0xff, 0xff, 0xff }, 0 },
    342 
    343     { PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_EZCARD,
    344       PCMCIA_CIS_INVALID,
    345       0, 0x01c0, { 0x00, 0xe0, 0x29 }, 0 },
    346 
    347     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    348       PCMCIA_CIS_SMC_8041,
    349       0, -1, { 0x00, 0x04, 0xe2 }, 0 },
    350 
    351     { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_EA_ETHER,
    352       PCMCIA_CIS_INVALID,
    353       0, -1, { 0x00, 0xc0, 0x1b }, 0 },
    354 
    355     { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER_CF,
    356       PCMCIA_CIS_INVALID,
    357       0, -1, { 0x00, 0xc0, 0x1b }, 0 },
    358 
    359     { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETH_10_100_CF,
    360       PCMCIA_CIS_INVALID,
    361       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
    362 
    363     { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER,
    364       PCMCIA_CIS_INVALID,
    365       0, -1, { 0x00, 0xc0, 0x1b }, 0 },
    366 
    367     { PCMCIA_VENDOR_KINGSTON, PCMCIA_PRODUCT_KINGSTON_KNE2,
    368       PCMCIA_CIS_INVALID,
    369       0, -1, { 0x00, 0xc0, 0xf0 }, 0 },
    370 
    371     { PCMCIA_VENDOR_XIRCOM, PCMCIA_PRODUCT_XIRCOM_CFE_10,
    372       PCMCIA_CIS_INVALID,
    373       0, -1, { 0x00, 0x10, 0xa4 }, 0 },
    374 
    375     { PCMCIA_VENDOR_MELCO, PCMCIA_PRODUCT_MELCO_LPC3_TX,
    376       PCMCIA_CIS_INVALID,
    377       0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_AX88190 },
    378 
    379     { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC_CF_CLT,
    380       PCMCIA_CIS_INVALID,
    381       0, -1, { 0x00, 0x07, 0x40 }, 0 },
    382 
    383     { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC3_CLT,
    384       PCMCIA_CIS_INVALID,
    385       0, -1, { 0x00, 0x07, 0x40 }, 0 },
    386 
    387     { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC4_CLX,
    388       PCMCIA_CIS_INVALID,
    389       0, -1, { 0x00, 0x40, 0xfa }, NE2000DVF_AX88190 },
    390 
    391     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    392       PCMCIA_CIS_BILLIONTON_LNT10TN,
    393       0, -1, { 0x00, 0x00, 0x00 }, 0 },
    394 
    395     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    396       PCMCIA_CIS_BILLIONTON_CFLT10N,
    397       0, -1, { 0x00, 0x00, 0x00 }, 0 },
    398 
    399     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    400       PCMCIA_CIS_NDC_ND5100_E,
    401       0, -1, { 0x00, 0x80, 0xc6 }, 0 },
    402 
    403     { PCMCIA_VENDOR_TELECOMDEVICE, PCMCIA_PRODUCT_TELECOMDEVICE_TCD_HPC100,
    404       PCMCIA_CIS_INVALID,
    405       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
    406 
    407     { PCMCIA_VENDOR_MACNICA, PCMCIA_PRODUCT_MACNICA_ME1_JEIDA,
    408       PCMCIA_CIS_INVALID,
    409       0, 0x00b8, { 0x08, 0x00, 0x42 }, 0 },
    410 
    411     { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA411,
    412       PCMCIA_CIS_INVALID,
    413       0, -1, { 0x00, 0x40, 0xf4 }, 0 },
    414 
    415     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    416       PCMCIA_CIS_DYNALINK_L10C,
    417       0, -1, { 0x00, 0x00, 0x00 }, 0 },
    418 
    419     { PCMCIA_VENDOR_ALLIEDTELESIS, PCMCIA_PRODUCT_ALLIEDTELESIS_LA_PCM,
    420       PCMCIA_CIS_INVALID,
    421       0, 0x0ff0, { 0x00, 0x00, 0xf4 }, 0 },
    422 
    423     { PCMCIA_VENDOR_NEXTCOM, PCMCIA_PRODUCT_NEXTCOM_NEXTHAWK,
    424       PCMCIA_CIS_INVALID,
    425       0, -1, { 0x00, 0x40, 0xb4 }, 0 },
    426 
    427     { PCMCIA_VENDOR_BELKIN, PCMCIA_PRODUCT_BELKIN_F5D5020,
    428       PCMCIA_CIS_BELKIN_F5D5020,
    429       0, -1, { 0x00, 0x30, 0xbd } , NE2000DVF_AX88190 },
    430 
    431 #if 0
    432     /* the rest of these are stolen from the linux pcnet pcmcia device
    433        driver.  Since I don't know the manfid or cis info strings for
    434        any of them, they're not compiled in until I do. */
    435     { "APEX MultiCard",
    436       0x0000, 0x0000, NULL, NULL, 0,
    437       0x03f4, { 0x00, 0x20, 0xe5 }, 0 },
    438     { "ASANTE FriendlyNet",
    439       0x0000, 0x0000, NULL, NULL, 0,
    440       0x4910, { 0x00, 0x00, 0x94 }, 0 },
    441     { "Danpex EN-6200P2",
    442       0x0000, 0x0000, NULL, NULL, 0,
    443       0x0110, { 0x00, 0x40, 0xc7 }, 0 },
    444     { "DataTrek NetCard",
    445       0x0000, 0x0000, NULL, NULL, 0,
    446       0x0ff0, { 0x00, 0x20, 0xe8 }, 0 },
    447     { "EP-210 Ethernet",
    448       0x0000, 0x0000, NULL, NULL, 0,
    449       0x0110, { 0x00, 0x40, 0x33 }, 0 },
    450     { "ELECOM Laneed LD-CDWA",
    451       0x0000, 0x0000, NULL, NULL, 0,
    452       0x00b8, { 0x08, 0x00, 0x42 }, 0 },
    453     { "Grey Cell GCS2220",
    454       0x0000, 0x0000, NULL, NULL, 0,
    455       0x0000, { 0x00, 0x47, 0x43 }, 0 },
    456     { "Hypertec Ethernet",
    457       0x0000, 0x0000, NULL, NULL, 0,
    458       0x01c0, { 0x00, 0x40, 0x4c }, 0 },
    459     { "IBM CCAE",
    460       0x0000, 0x0000, NULL, NULL, 0,
    461       0x0ff0, { 0x08, 0x00, 0x5a }, 0 },
    462     { "IBM CCAE",
    463       0x0000, 0x0000, NULL, NULL, 0,
    464       0x0ff0, { 0x00, 0x04, 0xac }, 0 },
    465     { "IBM CCAE",
    466       0x0000, 0x0000, NULL, NULL, 0,
    467       0x0ff0, { 0x00, 0x06, 0x29 }, 0 },
    468     { "IBM FME",
    469       0x0000, 0x0000, NULL, NULL, 0,
    470       0x0374, { 0x00, 0x04, 0xac }, 0 },
    471     { "IBM FME",
    472       0x0000, 0x0000, NULL, NULL, 0,
    473       0x0374, { 0x08, 0x00, 0x5a }, 0 },
    474     { "Katron PE-520",
    475       0x0000, 0x0000, NULL, NULL, 0,
    476       0x0110, { 0x00, 0x40, 0xf6 }, 0 },
    477     { "Kingston KNE-PCM/x",
    478       0x0000, 0x0000, NULL, NULL, 0,
    479       0x0ff0, { 0x00, 0xc0, 0xf0 }, 0 },
    480     { "Kingston KNE-PCM/x",
    481       0x0000, 0x0000, NULL, NULL, 0,
    482       0x0ff0, { 0xe2, 0x0c, 0x0f }, 0 },
    483     { "Longshine LCS-8534",
    484       0x0000, 0x0000, NULL, NULL, 0,
    485       0x0000, { 0x08, 0x00, 0x00 }, 0 },
    486     { "Maxtech PCN2000",
    487       0x0000, 0x0000, NULL, NULL, 0,
    488       0x5000, { 0x00, 0x00, 0xe8 }, 0 },
    489     { "NDC Instant-Link",
    490       0x0000, 0x0000, NULL, NULL, 0,
    491       0x003a, { 0x00, 0x80, 0xc6 }, 0 },
    492     { "NE2000 Compatible",
    493       0x0000, 0x0000, NULL, NULL, 0,
    494       0x0ff0, { 0x00, 0xa0, 0x0c }, 0 },
    495     { "Network General Sniffer",
    496       0x0000, 0x0000, NULL, NULL, 0,
    497       0x0ff0, { 0x00, 0x00, 0x65 }, 0 },
    498     { "Panasonic VEL211",
    499       0x0000, 0x0000, NULL, NULL, 0,
    500       0x0ff0, { 0x00, 0x80, 0x45 }, 0 },
    501     { "SCM Ethernet",
    502       0x0000, 0x0000, NULL, NULL, 0,
    503       0x0ff0, { 0x00, 0x20, 0xcb }, 0 },
    504     { "Volktek NPL-402CT",
    505       0x0000, 0x0000, NULL, NULL, 0,
    506       0x0060, { 0x00, 0x40, 0x05 }, 0 },
    507 #endif
    508 };
    509 
    510 #define	NE2000_NDEVS	(sizeof(ne2000devs) / sizeof(ne2000devs[0]))
    511 
    512 static const struct ne2000dev *
    513 ne2000_match(struct pcmcia_card *card, int fct, int n)
    514 {
    515 	size_t i;
    516 
    517 	/*
    518 	 * See if it matches by manufacturer & product.
    519 	 */
    520 	if (card->manufacturer == ne2000devs[n].manufacturer &&
    521 	    card->manufacturer != PCMCIA_VENDOR_INVALID &&
    522 	    card->product == ne2000devs[n].product &&
    523 	    card->product != PCMCIA_PRODUCT_INVALID)
    524 		goto match;
    525 
    526 	/*
    527 	 * Otherwise, try to match by CIS strings.
    528 	 */
    529 	for (i = 0; i < 2; i++)
    530 		if (card->cis1_info[i] == NULL ||
    531 		    ne2000devs[n].cis_info[i] == NULL ||
    532 		    strcmp(card->cis1_info[i], ne2000devs[n].cis_info[i]) != 0)
    533 			return (NULL);
    534 
    535 match:
    536 	/*
    537 	 * Finally, see if function number matches.
    538 	 */
    539 	return (fct == ne2000devs[n].function ? &ne2000devs[n] : NULL);
    540 }
    541 
    542 
    543 int
    544 ne_pcmcia_match(parent, match, aux)
    545 	struct device *parent;
    546 	struct cfdata *match;
    547 	void *aux;
    548 {
    549 	struct pcmcia_attach_args *pa = aux;
    550 	int i;
    551 
    552 	for (i = 0; i < NE2000_NDEVS; i++) {
    553 		if (ne2000_match(pa->card, pa->pf->number, i))
    554 			return (1);
    555 	}
    556 
    557 	return (0);
    558 }
    559 
    560 int
    561 ne_pcmcia_validate_config(cfe)
    562 	struct pcmcia_config_entry *cfe;
    563 {
    564 	if (cfe->iftype != PCMCIA_IFTYPE_IO ||
    565 	    cfe->num_iospace < 1 || cfe->num_iospace > 2)
    566 		return (EINVAL);
    567 	/* Some cards have a memory space, but we don't use it. */
    568 	cfe->num_memspace = 0;
    569 	return (0);
    570 }
    571 
    572 void
    573 ne_pcmcia_attach(parent, self, aux)
    574 	struct device *parent, *self;
    575 	void *aux;
    576 {
    577 	struct ne_pcmcia_softc *psc = (void *) self;
    578 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    579 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    580 	struct pcmcia_attach_args *pa = aux;
    581 	struct pcmcia_config_entry *cfe;
    582 	const struct ne2000dev *ne_dev;
    583 	int i;
    584 	u_int8_t myea[6], *enaddr;
    585 	const char *typestr = "";
    586 	int error;
    587 
    588 	psc->sc_pf = pa->pf;
    589 
    590 	error = pcmcia_function_configure(pa->pf, ne_pcmcia_validate_config);
    591 	if (error) {
    592 		aprint_error("%s: configure failed, error=%d\n", self->dv_xname,
    593 		    error);
    594 		return;
    595 	}
    596 
    597 	cfe = pa->pf->cfe;
    598 	dsc->sc_regt = cfe->iospace[0].handle.iot;
    599 	dsc->sc_regh = cfe->iospace[0].handle.ioh;
    600 
    601 	if (cfe->num_iospace == 1) {
    602 		nsc->sc_asict = dsc->sc_regt;
    603 		if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
    604 		    NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS, &nsc->sc_asich)) {
    605 			aprint_error("%s: can't get subregion for asic\n",
    606 			    self->dv_xname);
    607 			goto fail;
    608 		}
    609 	} else {
    610 		nsc->sc_asict = cfe->iospace[1].handle.iot;
    611 		nsc->sc_asich = cfe->iospace[1].handle.ioh;
    612 	}
    613 
    614 	error = ne_pcmcia_enable(dsc);
    615 	if (error)
    616 		goto fail;
    617 
    618 	/* Set up power management hooks. */
    619 	dsc->sc_enable = ne_pcmcia_enable;
    620 	dsc->sc_disable = ne_pcmcia_disable;
    621 
    622 	/*
    623 	 * Read the station address from the board.
    624 	 */
    625 	i = 0;
    626 again:
    627 	enaddr = NULL;			/* Ask ASIC by default */
    628 	typestr = "";			/* clear previous card-type */
    629 	for (; i < NE2000_NDEVS; i++) {
    630 		ne_dev = ne2000_match(pa->card, pa->pf->number, i);
    631 		if (ne_dev != NULL) {
    632 			if (ne_dev->enet_maddr >= 0) {
    633 				enaddr = ne_pcmcia_get_enaddr(psc,
    634 				    ne_dev->enet_maddr, myea);
    635 				if (enaddr == NULL)
    636 					continue;
    637 			}
    638 			goto found;
    639 		}
    640 	}
    641 	aprint_error("%s: can't match ethernet vendor code\n", self->dv_xname);
    642 	if (enaddr != NULL)
    643 		aprint_error("%s: ethernet vendor code %02x:%02x:%02x\n",
    644 	            self->dv_xname, enaddr[0], enaddr[1], enaddr[2]);
    645 	goto fail2;
    646 
    647 found:
    648 	if ((ne_dev->flags & NE2000DVF_DL10019) != 0) {
    649 		u_int8_t type;
    650 
    651 		enaddr = ne_pcmcia_dl10019_get_enaddr(psc, myea);
    652 		if (enaddr == NULL) {
    653 			++i;
    654 			goto again;
    655 		}
    656 
    657 		dsc->sc_mediachange = dl10019_mediachange;
    658 		dsc->sc_mediastatus = dl10019_mediastatus;
    659 		dsc->init_card = dl10019_init_card;
    660 		dsc->stop_card = dl10019_stop_card;
    661 		dsc->sc_media_init = dl10019_media_init;
    662 		dsc->sc_media_fini = dl10019_media_fini;
    663 
    664 		/* Determine if this is a DL10019 or a DL10022. */
    665 		type = bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 0x0f);
    666 		if (type == 0x91 || type == 0x99) {
    667 			nsc->sc_type = NE2000_TYPE_DL10022;
    668 			typestr = " (DL10022)";
    669 		} else {
    670 			nsc->sc_type = NE2000_TYPE_DL10019;
    671 			typestr = " (DL10019)";
    672 		}
    673 	}
    674 
    675 	if ((ne_dev->flags & NE2000DVF_AX88190) != 0) {
    676 		u_int8_t test;
    677 
    678 		/* XXX This is highly bogus. */
    679 		if ((pa->pf->ccr_mask & (1 << PCMCIA_CCR_IOBASE0)) == 0) {
    680 			++i;
    681 			goto again;
    682 		}
    683 
    684 		dsc->sc_mediachange = ax88190_mediachange;
    685 		dsc->sc_mediastatus = ax88190_mediastatus;
    686 		dsc->init_card = ax88190_init_card;
    687 		dsc->stop_card = ax88190_stop_card;
    688 		dsc->sc_media_init = ax88190_media_init;
    689 		dsc->sc_media_fini = ax88190_media_fini;
    690 
    691 		test = bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 0x05);
    692 		if (test != 0) {
    693 			nsc->sc_type = NE2000_TYPE_AX88790;
    694 			typestr = " (AX88790)";
    695 		} else {
    696 			nsc->sc_type = NE2000_TYPE_AX88190;
    697 			typestr = " (AX88190)";
    698 		}
    699 	}
    700 
    701 	if (enaddr != NULL &&
    702 	    ne_dev->enet_vendor[0] != 0xff) {
    703 		/*
    704 		 * Make sure this is what we expect.
    705 		 */
    706 		if (enaddr[0] != ne_dev->enet_vendor[0] ||
    707 		    enaddr[1] != ne_dev->enet_vendor[1] ||
    708 		    enaddr[2] != ne_dev->enet_vendor[2]) {
    709 			++i;
    710 			goto again;
    711 		}
    712 	}
    713 
    714 	/*
    715 	 * Check for a Realtek 8019.
    716 	 */
    717 	if (nsc->sc_type == 0) {
    718 		bus_space_write_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CR,
    719 		    ED_CR_PAGE_0 | ED_CR_STP);
    720 		if (bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
    721 		    NERTL_RTL0_8019ID0) == RTL0_8019ID0 &&
    722 		    bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
    723 		    NERTL_RTL0_8019ID1) == RTL0_8019ID1) {
    724 			typestr = " (RTL8019)";
    725 			dsc->sc_mediachange = rtl80x9_mediachange;
    726 			dsc->sc_mediastatus = rtl80x9_mediastatus;
    727 			dsc->init_card = rtl80x9_init_card;
    728 			dsc->sc_media_init = rtl80x9_media_init;
    729 		}
    730 	}
    731 
    732 	if (ne2000_attach(nsc, enaddr))
    733 		goto fail2;
    734 
    735 	psc->sc_powerhook = powerhook_establish(ne2000_power, nsc);
    736 	if (psc->sc_powerhook == NULL)
    737 		printf("%s: WARNING: unable to establish power hook\n",
    738 		    self->dv_xname);
    739 
    740 	psc->sc_state = NE_PCMCIA_ATTACHED;
    741 	ne_pcmcia_disable(dsc);
    742 	return;
    743 
    744 fail2:
    745 	ne_pcmcia_disable(dsc);
    746 fail:
    747 	pcmcia_function_unconfigure(pa->pf);
    748 }
    749 
    750 int
    751 ne_pcmcia_detach(self, flags)
    752 	struct device *self;
    753 	int flags;
    754 {
    755 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)self;
    756 	struct pcmcia_function *pf = psc->sc_pf;
    757 	int error;
    758 
    759 	if (psc->sc_state != NE_PCMCIA_ATTACHED)
    760 		return (0);
    761 
    762 	if (psc->sc_powerhook != NULL)
    763 		powerhook_disestablish(psc->sc_powerhook);
    764 
    765 	error = ne2000_detach(&psc->sc_ne2000, flags);
    766 	if (error)
    767 		return (error);
    768 
    769 	pcmcia_function_unconfigure(pf);
    770 
    771 	return (0);
    772 }
    773 
    774 int
    775 ne_pcmcia_enable(dsc)
    776 	struct dp8390_softc *dsc;
    777 {
    778 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
    779 	int error;
    780 
    781 	/* set up the interrupt */
    782 	psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
    783 	    dsc);
    784 	if (!psc->sc_ih)
    785 		return (EIO);
    786 
    787 	error = pcmcia_function_enable(psc->sc_pf);
    788 	if (error) {
    789 		pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
    790 		psc->sc_ih = 0;
    791 	}
    792 
    793 	return (error);
    794 }
    795 
    796 void
    797 ne_pcmcia_disable(dsc)
    798 	struct dp8390_softc *dsc;
    799 {
    800 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
    801 
    802 	pcmcia_function_disable(psc->sc_pf);
    803 	pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
    804 	psc->sc_ih = 0;
    805 }
    806 
    807 u_int8_t *
    808 ne_pcmcia_get_enaddr(psc, maddr, myea)
    809 	struct ne_pcmcia_softc *psc;
    810 	int maddr;
    811 	u_int8_t myea[ETHER_ADDR_LEN];
    812 {
    813 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    814 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    815 	struct pcmcia_mem_handle pcmh;
    816 	bus_size_t offset;
    817 	u_int8_t *enaddr = NULL;
    818 	int j, mwindow;
    819 
    820 	if (maddr < 0)
    821 		return (NULL);
    822 
    823 	if (pcmcia_mem_alloc(psc->sc_pf, ETHER_ADDR_LEN * 2, &pcmh)) {
    824 		printf("%s: can't alloc mem for enet addr\n",
    825 		    dsc->sc_dev.dv_xname);
    826 		goto fail_1;
    827 	}
    828 	if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, maddr,
    829 	    ETHER_ADDR_LEN * 2, &pcmh, &offset, &mwindow)) {
    830 		printf("%s: can't map mem for enet addr\n",
    831 		    dsc->sc_dev.dv_xname);
    832 		goto fail_2;
    833 	}
    834 	for (j = 0; j < ETHER_ADDR_LEN; j++)
    835 		myea[j] = bus_space_read_1(pcmh.memt, pcmh.memh,
    836 		    offset + (j * 2));
    837 	enaddr = myea;
    838 
    839 	pcmcia_mem_unmap(psc->sc_pf, mwindow);
    840  fail_2:
    841 	pcmcia_mem_free(psc->sc_pf, &pcmh);
    842  fail_1:
    843 	return (enaddr);
    844 }
    845 
    846 u_int8_t *
    847 ne_pcmcia_dl10019_get_enaddr(psc, myea)
    848 	struct ne_pcmcia_softc *psc;
    849 	u_int8_t myea[ETHER_ADDR_LEN];
    850 {
    851 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    852 	u_int8_t sum;
    853 	int j;
    854 
    855 #define PAR0	0x04
    856 	for (j = 0, sum = 0; j < 8; j++)
    857 		sum += bus_space_read_1(nsc->sc_asict, nsc->sc_asich,
    858 		    PAR0 + j);
    859 	if (sum != 0xff)
    860 		return (NULL);
    861 	for (j = 0; j < ETHER_ADDR_LEN; j++)
    862 		myea[j] = bus_space_read_1(nsc->sc_asict,
    863 		    nsc->sc_asich, PAR0 + j);
    864 #undef PAR0
    865 	return (myea);
    866 }
    867