The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/pcmcia/if_ne_pcmcia.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: if_ne_pcmcia.c,v 1.110.2.4 2004/07/05 21:41:47 he 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.110.2.4 2004/07/05 21:41:47 he 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 __P((struct device *, struct cfdata *, void *));
   68 void    ne_pcmcia_attach __P((struct device *, struct device *, void *));
   69 int     ne_pcmcia_detach __P((struct device *, int));
   70 
   71 int     ne_pcmcia_enable __P((struct dp8390_softc *));
   72 void    ne_pcmcia_disable __P((struct dp8390_softc *));
   73 
   74 struct ne_pcmcia_softc {
   75         struct ne2000_softc sc_ne2000;          /* real "ne2000" softc */
   76 
   77         /* PCMCIA-specific goo */
   78         struct pcmcia_io_handle sc_pcioh;       /* PCMCIA i/o information */
   79         int sc_asic_io_window;                  /* i/o window for ASIC */
   80         int sc_nic_io_window;                   /* i/o window for NIC */
   81         struct pcmcia_function *sc_pf;          /* our PCMCIA function */
   82         void *sc_ih;                            /* interrupt handle */
   83 };
   84 
   85 u_int8_t *
   86         ne_pcmcia_get_enaddr __P((struct ne_pcmcia_softc *, int,
   87             u_int8_t [ETHER_ADDR_LEN]));
   88 u_int8_t *
   89         ne_pcmcia_dl10019_get_enaddr __P((struct ne_pcmcia_softc *,
   90             u_int8_t [ETHER_ADDR_LEN]));
   91 int     ne_pcmcia_ax88190_set_iobase __P((struct ne_pcmcia_softc *));
   92 
   93 CFATTACH_DECL(ne_pcmcia, sizeof(struct ne_pcmcia_softc),
   94     ne_pcmcia_match, ne_pcmcia_attach, ne_pcmcia_detach, dp8390_activate);
   95 
   96 static const struct ne2000dev {
   97     char *name;
   98     int32_t manufacturer;
   99     int32_t product;
  100     char *cis_info[4];
  101     int function;
  102     int enet_maddr;
  103     unsigned char enet_vendor[3];
  104     int flags;
  105 #define NE2000DVF_DL10019       0x0001          /* chip is D-Link DL10019 */
  106 #define NE2000DVF_AX88190       0x0002          /* chip is ASIX AX88190 */
  107 #define NE2000DVF_AX88790       0x0004          /* chip is ASIX AX88790 */
  108 } ne2000devs[] = {
  109     { PCMCIA_STR_EDIMAX_EP4000A,
  110       PCMCIA_VENDOR_EDIMAX, PCMCIA_PRODUCT_EDIMAX_EP4000A,
  111       PCMCIA_CIS_EDIMAX_EP4000A,
  112       0, -1, { 0x00, 0xa0, 0x0c } },
  113 
  114     { PCMCIA_STR_SYNERGY21_S21810,
  115       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  116       PCMCIA_CIS_SYNERGY21_S21810,
  117       0, -1, { 0x00, 0x48, 0x54 } },
  118 
  119     { PCMCIA_STR_AMBICOM_AMB8002T,
  120       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  121       PCMCIA_CIS_AMBICOM_AMB8002T,
  122       0, -1, { 0x00, 0x10, 0x7a } },
  123 
  124     { PCMCIA_STR_PREMAX_PE200,
  125       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  126       PCMCIA_CIS_PREMAX_PE200,
  127       0, 0x07f0, { 0x00, 0x20, 0xe0 } },
  128 
  129     { PCMCIA_STR_DIGITAL_DEPCMXX,
  130       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  131       PCMCIA_CIS_DIGITAL_DEPCMXX,
  132       0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
  133 
  134     { PCMCIA_STR_PLANET_SMARTCOM2000,
  135       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  136       PCMCIA_CIS_PLANET_SMARTCOM2000,
  137       0, 0xff0, { 0x00, 0x00, 0xe8 } },
  138 
  139     { PCMCIA_STR_DLINK_DE660,
  140       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  141       PCMCIA_CIS_DLINK_DE660,
  142       0, -1, { 0x00, 0x80, 0xc8 } },
  143 
  144     { PCMCIA_STR_DLINK_DE660PLUS,
  145       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  146       PCMCIA_CIS_DLINK_DE660PLUS,
  147       0, -1, { 0x00, 0x80, 0xc8 } },
  148 
  149     { PCMCIA_STR_RPTI_EP400,
  150       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  151       PCMCIA_CIS_RPTI_EP400,
  152       0, 0x110, { 0x00, 0x40, 0x95 } },
  153 
  154     { PCMCIA_STR_RPTI_EP401,
  155       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  156       PCMCIA_CIS_RPTI_EP401,
  157       0, -1, { 0x00, 0x40, 0x95 } },
  158 
  159     { PCMCIA_STR_ACCTON_EN2212,
  160       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  161       PCMCIA_CIS_ACCTON_EN2212,
  162       0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
  163     { PCMCIA_STR_ACCTON_EN2216,
  164       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  165       PCMCIA_CIS_ACCTON_EN2216,
  166       0, -1, { 0x00, 0x00, 0xe8 } },
  167 
  168     { PCMCIA_STR_SVEC_COMBOCARD,
  169       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  170       PCMCIA_CIS_SVEC_COMBOCARD,
  171       0, -1, { 0x00, 0xe0, 0x98 } },
  172 
  173     { PCMCIA_STR_SVEC_LANCARD,
  174       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  175       PCMCIA_CIS_SVEC_LANCARD,
  176       0, 0x7f0, { 0x00, 0xc0, 0x6c } },
  177 
  178     { PCMCIA_STR_EPSON_EEN10B,
  179       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_EPSON_EEN10B,
  180       PCMCIA_CIS_EPSON_EEN10B,
  181       0, 0xff0, { 0x00, 0x00, 0x48 } },
  182 
  183     { PCMCIA_STR_TAMARACK_ETHERNET,
  184       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  185       PCMCIA_CIS_TAMARACK_ETHERNET,
  186       0, -1, { 0x00, 0x00, 0x00 } },
  187 
  188 
  189     { PCMCIA_STR_CNET_NE2000,
  190       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  191       PCMCIA_CIS_CNET_NE2000,
  192       0, -1, { 0x00, 0x80, 0xad } },
  193 
  194     { PCMCIA_STR_ZONET_ZEN,
  195       PCMCIA_VENDOR_ZONET, PCMCIA_PRODUCT_ZONET_ZEN,
  196       PCMCIA_CIS_ZONET_ZEN,
  197       0, -1, { 0x00, 0x00, 0x00 } },       
  198 
  199     /*
  200      * You have to add new entries which contains
  201      * PCMCIA_VENDOR_INVALID and/or PCMCIA_PRODUCT_INVALID 
  202      * in front of this comment.
  203      *
  204      * There are cards which use a generic vendor and product id but needs
  205      * a different handling depending on the cis_info, so ne2000_match
  206      * needs a table where the exceptions comes first and then the normal
  207      * product and vendor entries.
  208      */
  209 
  210     { PCMCIA_STR_IBM_INFOMOVER,
  211       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
  212       PCMCIA_CIS_IBM_INFOMOVER,
  213       0, 0x0ff0, { 0x08, 0x00, 0x5a } },
  214 
  215     { PCMCIA_STR_IBM_INFOMOVER,
  216       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
  217       PCMCIA_CIS_IBM_INFOMOVER,
  218       0, 0x0ff0, { 0x00, 0x04, 0xac } },
  219 
  220     { PCMCIA_STR_IBM_INFOMOVER,
  221       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
  222       PCMCIA_CIS_IBM_INFOMOVER,
  223       0, 0x0ff0, { 0x00, 0x06, 0x29 } },
  224 
  225     /* NEC 9801N_J12 */
  226     { PCMCIA_STR_IBM_INFOMOVER,
  227       PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
  228       PCMCIA_CIS_IBM_INFOMOVER,
  229       0, 0x0ff0, { 0x00, 0x00, 0x4c } },
  230 
  231     { PCMCIA_STR_LINKSYS_ECARD_1, 
  232       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
  233       PCMCIA_CIS_LINKSYS_ECARD_1, 
  234       0, -1, { 0x00, 0x80, 0xc8 } },
  235 
  236     { PCMCIA_STR_PLANEX_FNW3600T,
  237       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
  238       PCMCIA_CIS_PLANEX_FNW3600T,
  239       0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_DL10019 },
  240 
  241     { PCMCIA_STR_SVEC_PN650TX,
  242       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
  243       PCMCIA_CIS_SVEC_PN650TX,
  244       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
  245 
  246     /*
  247      * This entry should be here so that above two cards doesn't
  248      * match with this.  FNW-3700T won't match above entries due to
  249      * MAC address check.
  250      */
  251     { PCMCIA_STR_LANTECH_FASTNETTX,
  252       PCMCIA_VENDOR_LANTECH, PCMCIA_PRODUCT_LANTECH_FASTNETTX,
  253       PCMCIA_CIS_LANTECH_FASTNETTX,
  254       0, -1, { 0x00, 0x04, 0x1c }, NE2000DVF_AX88190 },
  255 
  256     { PCMCIA_STR_PLANEX_FNW3700T, 
  257       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
  258       PCMCIA_CIS_PLANEX_FNW3700T, 
  259       0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_AX88190 },
  260 
  261     { PCMCIA_STR_LINKSYS_ETHERFAST,
  262       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
  263       PCMCIA_CIS_LINKSYS_ETHERFAST,
  264       0, -1, { 0x00, 0x80, 0xc8 }, NE2000DVF_DL10019 },
  265 
  266     { PCMCIA_STR_LINKSYS_ETHERFAST,
  267       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
  268       PCMCIA_CIS_LINKSYS_ETHERFAST,
  269       0, -1, { 0x00, 0x40, 0x05 }, NE2000DVF_DL10019 },
  270 
  271     { PCMCIA_STR_LINKSYS_ETHERFAST,
  272       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
  273       PCMCIA_CIS_LINKSYS_ETHERFAST,
  274       0, -1, { 0x00, 0x90, 0xfe }, NE2000DVF_DL10019 },
  275 
  276     { PCMCIA_STR_LINKSYS_ETHERFAST,
  277       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
  278       PCMCIA_CIS_LINKSYS_ETHERFAST,
  279       0, -1, { 0x00, 0xa0, 0xb0 }, NE2000DVF_DL10019 },
  280 
  281     { PCMCIA_STR_DLINK_DE650,
  282       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
  283       PCMCIA_CIS_LINKSYS_ETHERFAST,
  284       0, -1, { 0x00, 0x50, 0xba }, NE2000DVF_DL10019 },
  285 
  286     { PCMCIA_STR_DLINK_DE650,
  287       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
  288       PCMCIA_CIS_DLINK_DE650,
  289       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
  290 
  291     /*
  292      * There are two entries for the DFE-670TXD because there are
  293      * several possible Vendor IDs for the MAC address.  Both are
  294      * from D-Link, though.
  295      *
  296      * Oh, wait, there's a third possible vendor code, apparently.
  297      * And it's from "ANI Communications" this time...
  298      */
  299     { PCMCIA_STR_DLINK_DFE670TXD,
  300       PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
  301       PCMCIA_CIS_DLINK_DFE670TXD,
  302       0, -1, { 0x00, 0x50, 0xba }, NE2000DVF_DL10019 },
  303 
  304     { PCMCIA_STR_DLINK_DFE670TXD,
  305       PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
  306       PCMCIA_CIS_DLINK_DFE670TXD,
  307       0, -1, { 0x00, 0x0d, 0x88 }, NE2000DVF_DL10019 },
  308 
  309     { PCMCIA_STR_DLINK_DFE670TXD,
  310       PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
  311       PCMCIA_CIS_DLINK_DFE670TXD,
  312       0, -1, { 0x00, 0x40, 0x05 }, NE2000DVF_DL10019 },
  313 
  314     { PCMCIA_STR_NETGEAR_FA410TXC,
  315       PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
  316       PCMCIA_CIS_NETGEAR_FA410TXC,
  317       0, -1, { 0x00, 0x48, 0x54 }, NE2000DVF_DL10019 },
  318 
  319     { PCMCIA_STR_MELCO_LPC2_TX,
  320       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
  321       PCMCIA_CIS_MELCO_LPC2_TX,
  322       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_DL10019 },
  323 
  324     { PCMCIA_STR_LINKSYS_COMBO_ECARD, 
  325       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
  326       PCMCIA_CIS_LINKSYS_COMBO_ECARD, 
  327       0, -1, { 0x00, 0x80, 0xc8 } },
  328 
  329     { PCMCIA_STR_LINKSYS_TRUST_COMBO_ECARD,
  330       PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_TRUST_COMBO_ECARD,
  331       PCMCIA_CIS_LINKSYS_TRUST_COMBO_ECARD,
  332       0, 0x0120, { 0x20, 0x04, 0x49 } },
  333 
  334     /* Although the comments above say to put VENDOR/PRODUCT INVALID IDs
  335        above this list, we need to keep this one below the ECARD_1, or else
  336        both will match the same more-generic entry rather than the more
  337        specific one above with proper vendor and product IDs. */
  338     { PCMCIA_STR_LINKSYS_ECARD_2, 
  339       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  340       PCMCIA_CIS_LINKSYS_ECARD_2,
  341       0, -1, { 0x00, 0x80, 0xc8 } },
  342 
  343     /*
  344      * D-Link DE-650 has many minor versions:
  345      *
  346      *   CIS information          Manufacturer Product  Note
  347      * 1 "D-Link, DE-650"             INVALID  INVALID  white card
  348      * 2 "D-Link, DE-650, Ver 01.00"  INVALID  INVALID  became bare metal
  349      * 3 "D-Link, DE-650, Ver 01.00"   0x149    0x265   minor change in look
  350      * 4 "D-Link, DE-650, Ver 01.00"   0x149    0x265   collision LED added
  351      *
  352      * While the 1st and the 2nd types should use the "D-Link DE-650" entry,
  353      * the 3rd and the 4th types should use the "Linksys EtherCard" entry.
  354      * Therefore, this enty must be below the LINKSYS_ECARD_1.  --itohy
  355      */
  356     { PCMCIA_STR_DLINK_DE650,
  357       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  358       PCMCIA_CIS_DLINK_DE650,
  359       0, 0x0040, { 0x00, 0x80, 0xc8 } },
  360 
  361     /*
  362      * IO-DATA PCLA/TE and later version of PCLA/T has valid
  363      * vendor/product ID and it is possible to read MAC address
  364      * using standard I/O ports.  It also read from CIS offset 0x01c0.
  365      * On the other hand, earlier version of PCLA/T doesn't have valid
  366      * vendor/product ID and MAC address must be read from CIS offset
  367      * 0x0ff0 (i.e., usual ne2000 way to read it doesn't work).
  368      * And CIS information of earlier and later version of PCLA/T are
  369      * same except fourth element.  So, for now, we place the entry for
  370      * PCLA/TE (and later version of PCLA/T) followed by entry
  371      * for the earlier version of PCLA/T (or, modify to match all CIS
  372      * information and have three or more individual entries).
  373      */
  374     { PCMCIA_STR_IODATA_PCLATE,
  375       PCMCIA_VENDOR_IODATA, PCMCIA_PRODUCT_IODATA_PCLATE,
  376       PCMCIA_CIS_IODATA_PCLATE,
  377       0, -1, { 0x00, 0xa0, 0xb0 } },
  378 
  379     /*
  380      * This entry should be placed after above PCLA-TE entry.
  381      * See above comments for detail.
  382      */
  383     { PCMCIA_STR_IODATA_PCLAT,
  384       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  385       PCMCIA_CIS_IODATA_PCLAT,
  386       0, 0x0ff0, { 0x00, 0xa0, 0xb0 } },
  387 
  388     { PCMCIA_STR_DAYNA_COMMUNICARD_E_1,
  389       PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_1,
  390       PCMCIA_CIS_DAYNA_COMMUNICARD_E_1,
  391       0, 0x0110, { 0x00, 0x80, 0x19 } },
  392 
  393     { PCMCIA_STR_DAYNA_COMMUNICARD_E_2,
  394       PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_2,
  395       PCMCIA_CIS_DAYNA_COMMUNICARD_E_2,
  396       0, -1, { 0x00, 0x80, 0x19 } },
  397 
  398     { PCMCIA_STR_COREGA_ETHER_PCC_T,
  399       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_T,
  400       PCMCIA_CIS_COREGA_ETHER_PCC_T,
  401       0, -1, { 0x00, 0x00, 0xf4 } },
  402 
  403     { PCMCIA_STR_COREGA_ETHER_PCC_TD,
  404       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_TD,
  405       PCMCIA_CIS_COREGA_ETHER_PCC_TD,
  406       0, -1, { 0x00, 0x00, 0xf4 } },
  407 
  408     { PCMCIA_STR_COREGA_ETHER_PCC_TL,
  409       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_TL,
  410       PCMCIA_CIS_COREGA_ETHER_PCC_TL,
  411       0, -1, { 0x00, 0x00, 0xf4 } },
  412 
  413     { PCMCIA_STR_COREGA_ETHER_II_PCC_T,
  414       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_T,
  415       PCMCIA_CIS_COREGA_ETHER_II_PCC_T,
  416       0, -1, { 0x00, 0x00, 0xf4 } },
  417 
  418     { PCMCIA_STR_COREGA_ETHER_II_PCC_TD,
  419       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_TD,
  420       PCMCIA_CIS_COREGA_ETHER_II_PCC_TD,
  421       0, -1, { 0x00, 0x00, 0xf4 } },
  422 
  423     { PCMCIA_STR_COREGA_FAST_ETHER_PCC_TX,
  424       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FAST_ETHER_PCC_TX,
  425       PCMCIA_CIS_COREGA_FAST_ETHER_PCC_TX,
  426       0, -1, { 0x00, 0x00, 0xf4 }, NE2000DVF_DL10019 },
  427 
  428     { PCMCIA_STR_COREGA_FETHER_PCC_TXF,
  429       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXF,
  430       PCMCIA_CIS_COREGA_FETHER_PCC_TXF,
  431       0, -1, { 0x00, 0x90, 0x99 }, NE2000DVF_DL10019 },
  432 
  433     { PCMCIA_STR_COREGA_FETHER_PCC_TXD,
  434       PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXD,
  435       PCMCIA_CIS_COREGA_FETHER_PCC_TXD,
  436       0, -1, { 0x00, 0x90, 0x99 } },
  437 
  438     { PCMCIA_STR_COMPEX_LINKPORT_ENET_B,
  439       PCMCIA_VENDOR_COMPEX, PCMCIA_PRODUCT_COMPEX_LINKPORT_ENET_B,
  440       PCMCIA_CIS_COMPEX_LINKPORT_ENET_B,
  441       0, 0x01c0, { 0x00, 0xa0, 0x0c } },
  442 
  443     { PCMCIA_STR_SMC_EZCARD,
  444       PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_EZCARD,
  445       PCMCIA_CIS_SMC_EZCARD,
  446       0, 0x01c0, { 0x00, 0xe0, 0x29 } },
  447 
  448     { PCMCIA_STR_SMC_8041,
  449       PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_8041,
  450       PCMCIA_CIS_SMC_8041,
  451       0, -1, { 0x00, 0x04, 0xe2 } },
  452 
  453     { PCMCIA_STR_SOCKET_EA_ETHER,
  454       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_EA_ETHER,
  455       PCMCIA_CIS_SOCKET_EA_ETHER,
  456       0, -1, { 0x00, 0xc0, 0x1b } },
  457 
  458     { PCMCIA_STR_SOCKET_LP_ETHER_CF,
  459       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER_CF,
  460       PCMCIA_CIS_SOCKET_LP_ETHER_CF,
  461       0, -1, { 0x00, 0xc0, 0x1b } },
  462 
  463     { PCMCIA_STR_SOCKET_LP_ETH_10_100_CF,
  464       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETH_10_100_CF,
  465       PCMCIA_CIS_SOCKET_LP_ETH_10_100_CF,
  466       0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
  467 
  468     { PCMCIA_STR_SOCKET_LP_ETHER,
  469       PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER,
  470       PCMCIA_CIS_SOCKET_LP_ETHER,
  471       0, -1, { 0x00, 0xc0, 0x1b } },
  472 
  473     { PCMCIA_STR_KINGSTON_KNE2,
  474       PCMCIA_VENDOR_KINGSTON, PCMCIA_PRODUCT_KINGSTON_KNE2,
  475       PCMCIA_CIS_KINGSTON_KNE2,
  476       0, -1, { 0x00, 0xc0, 0xf0 } },
  477 
  478     { PCMCIA_STR_XIRCOM_CFE_10,
  479       PCMCIA_VENDOR_XIRCOM, PCMCIA_PRODUCT_XIRCOM_CFE_10,
  480       PCMCIA_CIS_XIRCOM_CFE_10,
  481       0, -1, { 0x00, 0x10, 0xa4 } },
  482 
  483     { PCMCIA_STR_MELCO_LPC3_TX, 
  484       PCMCIA_VENDOR_MELCO, PCMCIA_PRODUCT_MELCO_LPC3_TX,
  485       PCMCIA_CIS_MELCO_LPC3_TX, 
  486       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
  487 
  488     { PCMCIA_STR_BUFFALO_LPC3_CLT,
  489       PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC3_CLT,
  490       PCMCIA_CIS_BUFFALO_LPC3_CLT,
  491       0, -1, { 0x00, 0x07, 0x40 } },
  492 
  493     { PCMCIA_STR_BUFFALO_LPC4_CLX,
  494       PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC4_CLX,
  495       PCMCIA_CIS_BUFFALO_LPC4_CLX,
  496       0, -1, { 0x00, 0x40, 0xfa }, NE2000DVF_AX88190 | NE2000DVF_AX88790 },
  497 
  498     { PCMCIA_STR_BILLIONTON_LNT10TN,
  499       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  500       PCMCIA_CIS_BILLIONTON_LNT10TN,
  501       0, -1, { 0x00, 0x00, 0x00 } },
  502 
  503     { PCMCIA_STR_BILLIONTON_CFLT10N,
  504       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  505       PCMCIA_CIS_BILLIONTON_CFLT10N,
  506       0, -1, { 0x00, 0x00, 0x00 } },
  507 
  508     { PCMCIA_STR_NDC_ND5100_E,
  509       PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
  510       PCMCIA_CIS_NDC_ND5100_E,
  511       0, -1, { 0x00, 0x80, 0xc6 } },
  512 
  513     { PCMCIA_STR_TELECOMDEVICE_TCD_HPC100,
  514       PCMCIA_VENDOR_TELECOMDEVICE, PCMCIA_PRODUCT_TELECOMDEVICE_TCD_HPC100,
  515       PCMCIA_CIS_TELECOMDEVICE_TCD_HPC100,
  516       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
  517 
  518     { PCMCIA_STR_MACNICA_ME1_JEIDA,
  519       PCMCIA_VENDOR_MACNICA, PCMCIA_PRODUCT_MACNICA_ME1_JEIDA,
  520       PCMCIA_CIS_MACNICA_ME1_JEIDA,
  521       0, 0x00b8, { 0x08, 0x00, 0x42 } },
  522 
  523     { PCMCIA_STR_NETGEAR_FA411,
  524       PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA411,
  525       PCMCIA_CIS_NETGEAR_FA411,
  526       0, -1, { 0x00, 0x40, 0xf4 } },
  527 
  528     { PCMCIA_STR_DYNALINK_L10C,
  529       PCMCIA_VENDOR_DYNALINK, PCMCIA_PRODUCT_DYNALINK_L10C,
  530       PCMCIA_CIS_DYNALINK_L10C,
  531       0, -1, { 0x00, 0x00, 0x00 } },
  532 
  533 #if 0
  534     /* the rest of these are stolen from the linux pcnet pcmcia device
  535        driver.  Since I don't know the manfid or cis info strings for
  536        any of them, they're not compiled in until I do. */
  537     { "APEX MultiCard",
  538       0x0000, 0x0000, NULL, NULL, 0,
  539       0x03f4, { 0x00, 0x20, 0xe5 } },
  540     { "ASANTE FriendlyNet",
  541       0x0000, 0x0000, NULL, NULL, 0,
  542       0x4910, { 0x00, 0x00, 0x94 } },
  543     { "Danpex EN-6200P2",
  544       0x0000, 0x0000, NULL, NULL, 0,
  545       0x0110, { 0x00, 0x40, 0xc7 } },
  546     { "DataTrek NetCard",
  547       0x0000, 0x0000, NULL, NULL, 0,
  548       0x0ff0, { 0x00, 0x20, 0xe8 } },
  549     { "Dayna CommuniCard E",
  550       0x0000, 0x0000, NULL, NULL, 0,
  551       0x0110, { 0x00, 0x80, 0x19 } },
  552     { "EP-210 Ethernet",
  553       0x0000, 0x0000, NULL, NULL, 0,
  554       0x0110, { 0x00, 0x40, 0x33 } },
  555     { "ELECOM Laneed LD-CDWA",
  556       0x0000, 0x0000, NULL, NULL, 0,
  557       0x00b8, { 0x08, 0x00, 0x42 } },
  558     { "Grey Cell GCS2220",
  559       0x0000, 0x0000, NULL, NULL, 0,
  560       0x0000, { 0x00, 0x47, 0x43 } },
  561     { "Hypertec Ethernet",
  562       0x0000, 0x0000, NULL, NULL, 0,
  563       0x01c0, { 0x00, 0x40, 0x4c } },
  564     { "IBM CCAE",
  565       0x0000, 0x0000, NULL, NULL, 0,
  566       0x0ff0, { 0x08, 0x00, 0x5a } },
  567     { "IBM CCAE",
  568       0x0000, 0x0000, NULL, NULL, 0,
  569       0x0ff0, { 0x00, 0x04, 0xac } },
  570     { "IBM CCAE",
  571       0x0000, 0x0000, NULL, NULL, 0,
  572       0x0ff0, { 0x00, 0x06, 0x29 } },
  573     { "IBM FME",
  574       0x0000, 0x0000, NULL, NULL, 0,
  575       0x0374, { 0x00, 0x04, 0xac } },
  576     { "IBM FME",
  577       0x0000, 0x0000, NULL, NULL, 0,
  578       0x0374, { 0x08, 0x00, 0x5a } },
  579     { "Katron PE-520",
  580       0x0000, 0x0000, NULL, NULL, 0,
  581       0x0110, { 0x00, 0x40, 0xf6 } },
  582     { "Kingston KNE-PCM/x",
  583       0x0000, 0x0000, NULL, NULL, 0,
  584       0x0ff0, { 0x00, 0xc0, 0xf0 } },
  585     { "Kingston KNE-PCM/x",
  586       0x0000, 0x0000, NULL, NULL, 0,
  587       0x0ff0, { 0xe2, 0x0c, 0x0f } },
  588     { "Longshine LCS-8534",
  589       0x0000, 0x0000, NULL, NULL, 0,
  590       0x0000, { 0x08, 0x00, 0x00 } },
  591     { "Maxtech PCN2000",
  592       0x0000, 0x0000, NULL, NULL, 0,
  593       0x5000, { 0x00, 0x00, 0xe8 } },
  594     { "NDC Instant-Link",
  595       0x0000, 0x0000, NULL, NULL, 0,
  596       0x003a, { 0x00, 0x80, 0xc6 } },
  597     { "NE2000 Compatible",
  598       0x0000, 0x0000, NULL, NULL, 0,
  599       0x0ff0, { 0x00, 0xa0, 0x0c } },
  600     { "Network General Sniffer",
  601       0x0000, 0x0000, NULL, NULL, 0,
  602       0x0ff0, { 0x00, 0x00, 0x65 } },
  603     { "Panasonic VEL211",
  604       0x0000, 0x0000, NULL, NULL, 0,
  605       0x0ff0, { 0x00, 0x80, 0x45 } },
  606     { "SCM Ethernet",
  607       0x0000, 0x0000, NULL, NULL, 0,
  608       0x0ff0, { 0x00, 0x20, 0xcb } },
  609     { "Volktek NPL-402CT",
  610       0x0000, 0x0000, NULL, NULL, 0,
  611       0x0060, { 0x00, 0x40, 0x05 } },
  612 #endif
  613 
  614     { PCMCIA_STR_ALLIEDTELESIS_LA_PCM,
  615       PCMCIA_VENDOR_ALLIEDTELESIS, PCMCIA_PRODUCT_ALLIEDTELESIS_LA_PCM,
  616       PCMCIA_CIS_ALLIEDTELESIS_LA_PCM,
  617       0, 0x0ff0, { 0x00, 0x00, 0xf4 } },
  618 };
  619 
  620 #define NE2000_NDEVS    (sizeof(ne2000devs) / sizeof(ne2000devs[0]))
  621 
  622 #define ne2000_match(card, fct, n) \
  623 ((((((card)->manufacturer != PCMCIA_VENDOR_INVALID) && \
  624     ((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
  625     ((card)->product != PCMCIA_PRODUCT_INVALID) && \
  626     ((card)->product == ne2000devs[(n)].product)) || \
  627    ((ne2000devs[(n)].cis_info[0]) && (ne2000devs[(n)].cis_info[1]) && \
  628     (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis_info[0]) == 0) && \
  629     (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis_info[1]) == 0))) && \
  630   ((fct) == ne2000devs[(n)].function))? \
  631  &ne2000devs[(n)]:NULL)
  632 
  633 int
  634 ne_pcmcia_match(parent, match, aux)
  635         struct device *parent;
  636         struct cfdata *match;
  637         void *aux;
  638 {
  639         struct pcmcia_attach_args *pa = aux;
  640         int i;
  641 
  642         for (i = 0; i < NE2000_NDEVS; i++) {
  643                 if (ne2000_match(pa->card, pa->pf->number, i))
  644                         return (1);
  645         }
  646 
  647         return (0);
  648 }
  649 
  650 void
  651 ne_pcmcia_attach(parent, self, aux)
  652         struct device *parent, *self;
  653         void *aux;
  654 {
  655         struct ne_pcmcia_softc *psc = (void *) self;
  656         struct ne2000_softc *nsc = &psc->sc_ne2000;
  657         struct dp8390_softc *dsc = &nsc->sc_dp8390;
  658         struct pcmcia_attach_args *pa = aux;
  659         struct pcmcia_config_entry *cfe;
  660         const struct ne2000dev *ne_dev;
  661         int i;
  662         u_int8_t myea[6], *enaddr;
  663         const char *typestr = "";
  664 
  665         psc->sc_pf = pa->pf;
  666 
  667         SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
  668 #if 0
  669                 /*
  670                  * Some ne2000 driver's claim to have memory; others don't.
  671                  * Since I don't care, I don't check.
  672                  */
  673 
  674                 if (cfe->num_memspace != 1) {
  675                         printf(": unexpected number of memory spaces "
  676                             " %d should be 1\n", cfe->num_memspace);
  677                         continue;
  678                 }
  679 #endif
  680 
  681                 if (cfe->num_iospace == 1) {
  682                         if (cfe->iospace[0].length != NE2000_NPORTS) {
  683                                 printf(": unexpected I/O space configuration"
  684                                     " (continued)\n%s", dsc->sc_dev.dv_xname);
  685                                 /* XXX really safe for all other cards? */
  686                         }
  687                 } else if (cfe->num_iospace == 2) {
  688                         /*
  689                          * Some cards report a separate space for NIC and ASIC.
  690                          * This make some sense, but we must allocate a single
  691                          * NE2000_NPORTS-sized chunk, due to brain damaged
  692                          * address decoders on some of these cards.
  693                          */
  694                         if (cfe->iospace[0].length + cfe->iospace[1].length !=
  695                             NE2000_NPORTS) {
  696 #ifdef DIAGNOSTIC
  697                                 printf(": unexpected I/O "
  698                                     "space configuration; ignored\n%s",
  699                                     dsc->sc_dev.dv_xname);
  700 #endif
  701                                 continue;
  702                         }
  703                 } else {
  704 #ifdef DIAGNOSTIC
  705                         printf(": unexpected number of i/o spaces %d"
  706                             " should be 1 or 2; ignored\n%s",
  707                             cfe->num_iospace, dsc->sc_dev.dv_xname);
  708 #endif
  709                         continue;
  710                 }
  711 
  712                 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
  713                     NE2000_NPORTS, NE2000_NPORTS, &psc->sc_pcioh)) {
  714 #ifdef DIAGNOSTIC
  715                         printf(": can't allocate i/o space %lx; ignored\n%s",
  716                             cfe->iospace[0].start, dsc->sc_dev.dv_xname);
  717 #endif
  718                         continue;
  719                 }
  720 
  721                 /* Ok, found. */
  722                 break;
  723         }
  724 
  725         if (cfe == NULL) {
  726                 printf(": no suitable config entry\n");
  727                 goto fail_1;
  728         }
  729 
  730         dsc->sc_regt = psc->sc_pcioh.iot;
  731         dsc->sc_regh = psc->sc_pcioh.ioh;
  732 
  733         nsc->sc_asict = psc->sc_pcioh.iot;
  734         if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
  735             NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
  736             &nsc->sc_asich)) {
  737                 printf(": can't get subregion for asic\n");
  738                 goto fail_2;
  739         }
  740 
  741         /* Set up power management hooks. */
  742         dsc->sc_enable = ne_pcmcia_enable;
  743         dsc->sc_disable = ne_pcmcia_disable;
  744 
  745         /* Enable the card. */
  746         pcmcia_function_init(pa->pf, cfe);
  747         if (pcmcia_function_enable(pa->pf)) {
  748                 printf(": function enable failed\n");
  749                 goto fail_2;
  750         }
  751 
  752         /* some cards claim to be io16, but they're lying. */
  753         if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
  754             NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
  755             &psc->sc_pcioh, &psc->sc_nic_io_window)) {
  756                 printf(": can't map NIC i/o space\n");
  757                 goto fail_3;
  758         }
  759 
  760         if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
  761             NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
  762             &psc->sc_pcioh, &psc->sc_asic_io_window)) {
  763                 printf(": can't map ASIC i/o space\n");
  764                 goto fail_4;
  765         }
  766 
  767         printf("\n");
  768 
  769         /*
  770          * Read the station address from the board.
  771          */
  772         i = 0;
  773 again:
  774         enaddr = NULL;                  /* Ask ASIC by default */
  775         typestr = "";                   /* clear previous card-type */
  776         for (; i < NE2000_NDEVS; i++) {
  777                 ne_dev = ne2000_match(pa->card, pa->pf->number, i);
  778                 if (ne_dev != NULL) {
  779                         if (ne_dev->enet_maddr >= 0) {
  780                                 enaddr = ne_pcmcia_get_enaddr(psc, 
  781                                     ne_dev->enet_maddr, myea);
  782                                 if (enaddr == NULL)
  783                                         continue;
  784                         }
  785                         goto found;
  786                 }
  787         }
  788         printf("%s (manf %08x prod %08x) cis %s %s: "
  789                "can't match ethernet vendor code\n",
  790                dsc->sc_dev.dv_xname,
  791                pa->manufacturer, pa->product,
  792                pa->card->cis1_info[0], pa->card->cis1_info[1]);
  793         if (enaddr != NULL)
  794                 aprint_error("%s: ethernet vendor code %02x:%02x:%02x\n",
  795                     dsc->sc_dev.dv_xname, enaddr[0], enaddr[1], enaddr[2]);
  796         goto fail_5;
  797 
  798 found:
  799         if ((ne_dev->flags & NE2000DVF_DL10019) != 0) {
  800                 u_int8_t type;
  801 
  802                 enaddr = ne_pcmcia_dl10019_get_enaddr(psc, myea);
  803                 if (enaddr == NULL) {
  804                         ++i;
  805                         goto again;
  806                 }
  807 
  808                 dsc->sc_mediachange = dl10019_mediachange;
  809                 dsc->sc_mediastatus = dl10019_mediastatus;
  810                 dsc->init_card = dl10019_init_card;
  811                 dsc->stop_card = dl10019_stop_card;
  812                 dsc->sc_media_init = dl10019_media_init;
  813                 dsc->sc_media_fini = dl10019_media_fini;
  814 
  815                 /* Determine if this is a DL10019 or a DL10022. */
  816                 type = bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 0x0f);
  817                 if (type == 0x91 || type == 0x99) {
  818                         nsc->sc_type = NE2000_TYPE_DL10022;
  819                         typestr = " (DL10022)";
  820                 } else {
  821                         nsc->sc_type = NE2000_TYPE_DL10019;
  822                         typestr = " (DL10019)";
  823                 }
  824         }
  825 
  826         if ((ne_dev->flags & NE2000DVF_AX88190) != 0) {
  827                 if (ne_pcmcia_ax88190_set_iobase(psc)) {
  828                         ++i;
  829                         goto again;
  830                 }
  831 
  832                 dsc->sc_mediachange = ax88190_mediachange;
  833                 dsc->sc_mediastatus = ax88190_mediastatus;
  834                 dsc->init_card = ax88190_init_card;
  835                 dsc->stop_card = ax88190_stop_card;
  836                 dsc->sc_media_init = ax88190_media_init;
  837                 dsc->sc_media_fini = ax88190_media_fini;
  838 
  839                 if ((ne_dev->flags & NE2000DVF_AX88790) != 0) {
  840                         nsc->sc_type = NE2000_TYPE_AX88790;
  841                         typestr = " (AX88790)";
  842                 } else {
  843                         nsc->sc_type = NE2000_TYPE_AX88190;
  844                         typestr = " (AX88190)";
  845                 }
  846         }
  847 
  848         if (enaddr != NULL) {
  849                 /*
  850                  * Make sure this is what we expect.
  851                  */
  852                 if (enaddr[0] != ne_dev->enet_vendor[0] ||
  853                     enaddr[1] != ne_dev->enet_vendor[1] ||
  854                     enaddr[2] != ne_dev->enet_vendor[2]) {
  855                         ++i;
  856                         goto again;
  857                 }
  858         }
  859 
  860         /*
  861          * Check for a Realtek 8019.
  862          */
  863         if (nsc->sc_type == 0) {
  864                 bus_space_write_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CR,
  865                     ED_CR_PAGE_0 | ED_CR_STP);
  866                 if (bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
  867                     NERTL_RTL0_8019ID0) == RTL0_8019ID0 &&
  868                     bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
  869                     NERTL_RTL0_8019ID1) == RTL0_8019ID1) {
  870                         typestr = " (RTL8019)";
  871                         dsc->sc_mediachange = rtl80x9_mediachange;
  872                         dsc->sc_mediastatus = rtl80x9_mediastatus;
  873                         dsc->init_card = rtl80x9_init_card;
  874                         dsc->sc_media_init = rtl80x9_media_init;
  875                 }
  876         }
  877 
  878         printf("%s: %s%s Ethernet\n", dsc->sc_dev.dv_xname, ne_dev->name,
  879             typestr);
  880 
  881         if (ne2000_attach(nsc, enaddr))
  882                 goto fail_5;
  883 
  884         pcmcia_function_disable(pa->pf);
  885         return;
  886 
  887  fail_5:
  888         /* Unmap ASIC i/o windows. */
  889         pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
  890 
  891  fail_4:
  892         /* Unmap NIC i/o windows. */
  893         pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
  894 
  895  fail_3:
  896         pcmcia_function_disable(pa->pf);
  897 
  898  fail_2:
  899         /* Free our i/o space. */
  900         pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
  901 
  902  fail_1:
  903         psc->sc_nic_io_window = -1;
  904 }
  905 
  906 int
  907 ne_pcmcia_detach(self, flags)
  908         struct device *self;
  909         int flags;
  910 {
  911         struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)self;
  912         int error;
  913 
  914         if (psc->sc_nic_io_window == -1)
  915                 /* Nothing to detach. */
  916                 return (0);
  917 
  918         error = ne2000_detach(&psc->sc_ne2000, flags);
  919         if (error != 0)
  920                 return (error);
  921 
  922         /* Unmap our i/o windows. */
  923         pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
  924         pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
  925 
  926         /* Free our i/o space. */
  927         pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
  928 
  929         return (0);
  930 }
  931 
  932 int
  933 ne_pcmcia_enable(dsc)
  934         struct dp8390_softc *dsc;
  935 {
  936         struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
  937         struct ne2000_softc *nsc = &psc->sc_ne2000;
  938         struct pcmcia_mem_handle pcmh;
  939 
  940         /* set up the interrupt */
  941         psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
  942             dsc);
  943         if (psc->sc_ih == NULL) {
  944                 printf("%s: couldn't establish interrupt\n",
  945                     dsc->sc_dev.dv_xname);
  946                 goto fail_1;
  947         }
  948 
  949         if (pcmcia_function_enable(psc->sc_pf))
  950                 goto fail_2;
  951 
  952         if (nsc->sc_type == NE2000_TYPE_AX88190 ||
  953             nsc->sc_type == NE2000_TYPE_AX88790) {
  954                 if (ne_pcmcia_ax88190_set_iobase(psc))
  955                         goto fail_3;
  956                 if (nsc->sc_type == NE2000_TYPE_AX88790) {
  957                         bus_size_t offset;
  958                         int mwindow;
  959 
  960                         if (pcmcia_mem_alloc(psc->sc_pf,
  961                             AX88790_CSR_SIZE, &pcmh)) {
  962                                 printf("%s: can't alloc mem for CSR\n",
  963                                     dsc->sc_dev.dv_xname);
  964                                 goto fail_3;
  965                         }
  966 
  967                         if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
  968                             AX88790_CSR, AX88790_CSR_SIZE,
  969                             &pcmh, &offset, &mwindow)) {
  970                                 printf("%s: can't map mem for CSR\n",
  971                                     dsc->sc_dev.dv_xname);
  972                                 goto fail_4;
  973                         }
  974 
  975                         bus_space_write_1(pcmh.memt, pcmh.memh, offset, 0x4);
  976                         pcmcia_mem_unmap(psc->sc_pf, mwindow);
  977                         pcmcia_mem_free(psc->sc_pf, &pcmh);
  978                 }
  979         }
  980 
  981         return (0);
  982 
  983  fail_4:
  984         pcmcia_mem_free(psc->sc_pf, &pcmh);
  985  fail_3:
  986         pcmcia_function_disable(psc->sc_pf);
  987  fail_2:
  988         pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
  989  fail_1:
  990         return (1);
  991 }
  992 
  993 void
  994 ne_pcmcia_disable(dsc)
  995         struct dp8390_softc *dsc;
  996 {
  997         struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
  998 
  999         pcmcia_function_disable(psc->sc_pf);
 1000         pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
 1001 }
 1002 
 1003 u_int8_t *
 1004 ne_pcmcia_get_enaddr(psc, maddr, myea)
 1005         struct ne_pcmcia_softc *psc;
 1006         int maddr;
 1007         u_int8_t myea[ETHER_ADDR_LEN];
 1008 {
 1009         struct ne2000_softc *nsc = &psc->sc_ne2000;
 1010         struct dp8390_softc *dsc = &nsc->sc_dp8390;
 1011         struct pcmcia_mem_handle pcmh;
 1012         bus_size_t offset;
 1013         u_int8_t *enaddr = NULL;
 1014         int j, mwindow;
 1015 
 1016         if (maddr < 0)
 1017                 return (NULL);
 1018 
 1019         if (pcmcia_mem_alloc(psc->sc_pf, ETHER_ADDR_LEN * 2, &pcmh)) {
 1020                 printf("%s: can't alloc mem for enet addr\n",
 1021                     dsc->sc_dev.dv_xname);
 1022                 goto fail_1;
 1023         }
 1024         if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, maddr,
 1025             ETHER_ADDR_LEN * 2, &pcmh, &offset, &mwindow)) {
 1026                 printf("%s: can't map mem for enet addr\n",
 1027                     dsc->sc_dev.dv_xname);
 1028                 goto fail_2;
 1029         }
 1030         for (j = 0; j < ETHER_ADDR_LEN; j++)
 1031                 myea[j] = bus_space_read_1(pcmh.memt, pcmh.memh,
 1032                     offset + (j * 2));
 1033         enaddr = myea;
 1034 
 1035         pcmcia_mem_unmap(psc->sc_pf, mwindow);
 1036  fail_2:
 1037         pcmcia_mem_free(psc->sc_pf, &pcmh);
 1038  fail_1:
 1039         return (enaddr);
 1040 }
 1041 
 1042 u_int8_t *
 1043 ne_pcmcia_dl10019_get_enaddr(psc, myea)
 1044         struct ne_pcmcia_softc *psc;
 1045         u_int8_t myea[ETHER_ADDR_LEN];
 1046 {
 1047         struct ne2000_softc *nsc = &psc->sc_ne2000;
 1048         u_int8_t sum;
 1049         int j;
 1050 
 1051 #define PAR0    0x04
 1052         for (j = 0, sum = 0; j < 8; j++)
 1053                 sum += bus_space_read_1(nsc->sc_asict, nsc->sc_asich,
 1054                     PAR0 + j);
 1055         if (sum != 0xff)
 1056                 return (NULL);
 1057         for (j = 0; j < ETHER_ADDR_LEN; j++)
 1058                 myea[j] = bus_space_read_1(nsc->sc_asict,
 1059                     nsc->sc_asich, PAR0 + j);
 1060 #undef PAR0
 1061         return (myea);
 1062 }
 1063 
 1064 int
 1065 ne_pcmcia_ax88190_set_iobase(psc)
 1066         struct ne_pcmcia_softc *psc;
 1067 {
 1068         struct ne2000_softc *nsc = &psc->sc_ne2000;
 1069         struct dp8390_softc *dsc = &nsc->sc_dp8390;
 1070         struct pcmcia_mem_handle pcmh;
 1071         bus_size_t offset;
 1072         int rv = 1, mwindow;
 1073         u_int last_liobase, new_liobase;
 1074 
 1075         if (pcmcia_mem_alloc(psc->sc_pf, AX88190_LAN_IOSIZE, &pcmh)) {
 1076 #if 0
 1077                 printf("%s: can't alloc mem for LAN iobase\n",
 1078                     dsc->sc_dev.dv_xname);
 1079 #endif
 1080                 goto fail_1;
 1081         }
 1082         if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
 1083             AX88190_LAN_IOBASE, AX88190_LAN_IOSIZE,
 1084             &pcmh, &offset, &mwindow)) {
 1085                 printf("%s: can't map mem for LAN iobase\n",
 1086                     dsc->sc_dev.dv_xname);
 1087                 goto fail_2;
 1088         }
 1089 
 1090         last_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
 1091             (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
 1092 #ifdef DIAGNOSTIC
 1093         printf("%s: LAN iobase 0x%x (0x%x) ->", dsc->sc_dev.dv_xname,
 1094             last_liobase, (u_int)psc->sc_pcioh.addr);
 1095 #endif
 1096         bus_space_write_1(pcmh.memt, pcmh.memh, offset,
 1097             psc->sc_pcioh.addr & 0xff);
 1098         bus_space_write_1(pcmh.memt, pcmh.memh, offset + 2,
 1099             psc->sc_pcioh.addr >> 8);
 1100 
 1101         new_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
 1102             (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
 1103 #ifdef DIAGNOSTIC
 1104         printf(" 0x%x\n", new_liobase);
 1105 #endif
 1106         if ((last_liobase == psc->sc_pcioh.addr)
 1107             || (last_liobase != new_liobase))
 1108                 rv = 0;
 1109 
 1110         pcmcia_mem_unmap(psc->sc_pf, mwindow);
 1111  fail_2:
 1112         pcmcia_mem_free(psc->sc_pf, &pcmh);
 1113  fail_1:
 1114         return (rv);
 1115 }

Cache object: c7c99b493c67818ee3b9301a15c83b0b


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.