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/mca/if_ne_mca.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_mca.c,v 1.6 2002/10/02 16:34:12 thorpej Exp $    */
    2 
    3 /*-
    4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Jaromir Dolecek.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *      This product includes software developed by the NetBSD
   21  *      Foundation, Inc. and its contributors.
   22  * 4. Neither the name of The NetBSD Foundation nor the names of its
   23  *    contributors may be used to endorse or promote products derived
   24  *    from this software without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 
   39 /*
   40  * Driver for Novell NE/2 Ethernet Adapter (and clones).
   41  *
   42  * According to Linux ne2 driver, Arco and Compex card should be also
   43  * supported by this driver. However, NetBSD driver was only tested
   44  * with the Novell adapter so far.
   45  */
   46 
   47 #include <sys/cdefs.h>
   48 __KERNEL_RCSID(0, "$NetBSD: if_ne_mca.c,v 1.6 2002/10/02 16:34:12 thorpej Exp $");
   49 
   50 #include <sys/param.h>
   51 #include <sys/systm.h>
   52 #include <sys/mbuf.h>
   53 #include <sys/errno.h>
   54 #include <sys/device.h>
   55 #include <sys/protosw.h>
   56 #include <sys/socket.h>
   57 
   58 #include <net/if.h>
   59 #include <net/if_types.h>
   60 #include <net/if_media.h>
   61 #include <net/if_ether.h>
   62 
   63 #include <machine/bus.h>
   64 
   65 #include <dev/ic/dp8390reg.h>
   66 #include <dev/ic/dp8390var.h>
   67 
   68 #include <dev/ic/ne2000reg.h>
   69 #include <dev/ic/ne2000var.h>
   70 
   71 #include <dev/ic/rtl80x9reg.h>
   72 #include <dev/ic/rtl80x9var.h>
   73 
   74 #include <dev/mca/mcadevs.h>
   75 #include <dev/mca/mcavar.h>
   76 
   77 #define NE2_NPORTS      0x30
   78 
   79 struct ne_mca_softc {
   80         struct ne2000_softc sc_ne2000;          /* real "ne2000" softc */
   81 
   82         /* MCA-specific goo */
   83         void            *sc_ih;         /* interrupt handle */
   84 };
   85 
   86 int     ne_mca_match __P((struct device *, struct cfdata *, void *));
   87 void    ne_mca_attach __P((struct device *, struct device *, void *));
   88 
   89 CFATTACH_DECL(ne_mca, sizeof(struct ne_mca_softc),
   90     ne_mca_match, ne_mca_attach, NULL, NULL);
   91 
   92 static const struct ne_mca_products {
   93         u_int32_t ne_id;
   94         const char *ne_name;
   95 } ne_mca_products[] = {
   96         { MCA_PRODUCT_ARCOAE,   "Arco Electronics AE/2 Ethernet Adapter" },
   97         { MCA_PRODUCT_NE2,      "Novell NE/2 Ethernet Adapter" },
   98         { MCA_PRODUCT_CENET16, "Compex Inc. PS/2 ENET16-MC/P Microchannel Ad."},
   99         { 0, NULL }
  100 };
  101 
  102 static const struct ne_mca_products *ne_mca_lookup __P((int id));
  103 
  104 static const struct ne_mca_products *
  105 ne_mca_lookup(int id)
  106 {
  107         const struct ne_mca_products *np;
  108 
  109         for(np = ne_mca_products; np->ne_name; np++) 
  110                 if (id == np->ne_id)
  111                         return (np);
  112 
  113         return (NULL);
  114 }
  115 
  116 int
  117 ne_mca_match(struct device *parent, struct cfdata *cf, void *aux)
  118 {
  119         struct mca_attach_args *ma = aux;
  120 
  121         if (ne_mca_lookup(ma->ma_id))
  122                 return (1);
  123 
  124         return (0);
  125 }
  126 
  127 /* These values were taken from NE/2 ADF file */
  128 static const int ne_mca_irq[] = {
  129         3, 4, 5, 9
  130 };
  131 static const int ne_mca_iobase[] = {
  132         0, 0x1000, 0x2020, 0x8020, 0xa0a0, 0xb0b0, 0xc0c0, 0xc3d0
  133 };
  134 
  135 void
  136 ne_mca_attach(struct device *parent, struct device *self, void *aux)
  137 {
  138         struct ne_mca_softc *psc = (struct ne_mca_softc *)self;
  139         struct ne2000_softc *nsc = &psc->sc_ne2000;
  140         struct dp8390_softc *dsc = &nsc->sc_dp8390;
  141         struct mca_attach_args *ma = aux;
  142         bus_space_tag_t nict;
  143         bus_space_handle_t nich;
  144         bus_space_tag_t asict;
  145         bus_space_handle_t asich;
  146         int pos2, iobase, irq;
  147         const struct ne_mca_products *np;
  148 
  149         pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
  150 
  151         /*
  152          * POS register 2: (adf pos0)
  153          * 
  154          * 7 6 5 4 3 2 1 0
  155          *   \_/ | \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
  156          *    |  |     \____ I/O, Mem: 001=0x1000-0x102f 010=0x2020-0x204f
  157          *    |  |             011=0x8020-0x804f 100=0xa0a0-0xa0cf
  158          *    |  |             101=0xb0b0-0xb0df 110=0xc0c0-0xc0ef
  159          *     \  \            111=0xc3d0-0xc3ff
  160          *      \  \________ Boot Rom: 1=disabled 0=enabled
  161          *       \__________ Interrupt level: 00=3 01=4 10=5 11=9
  162          */
  163 
  164         np = ne_mca_lookup(ma->ma_id);
  165 
  166         iobase = ne_mca_iobase[(pos2 & 0x0e) >> 1];
  167         irq = ne_mca_irq[(pos2 & 0x60) >> 5];
  168         
  169         printf(" slot %d irq %d: %s\n", ma->ma_slot + 1, irq, np->ne_name);
  170 
  171         nict = ma->ma_iot;
  172 
  173         /* Map the device. */
  174         if (bus_space_map(nict, iobase, NE2_NPORTS, 0, &nich)) {
  175                 printf("%s: can't map i/o space\n", dsc->sc_dev.dv_xname);
  176                 return;
  177         }
  178 
  179         asict = nict;
  180         if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
  181             NE2000_ASIC_NPORTS, &asich)) {
  182                 printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
  183                 return;
  184         }
  185 
  186         dsc->sc_regt = nict;
  187         dsc->sc_regh = nich;
  188 
  189         nsc->sc_asict = asict;
  190         nsc->sc_asich = asich;
  191 
  192         /* This interface is always enabled. */
  193         dsc->sc_enabled = 1;
  194 
  195         dsc->sc_mediachange     = NULL;
  196         dsc->sc_mediastatus     = NULL;
  197         dsc->sc_media_init      = NULL;
  198         dsc->init_card          = NULL;
  199 
  200         /*
  201          * This is necessary for NE/2. Hopefully the other clones also work
  202          * this way.
  203          */
  204         nsc->sc_type = NE2000_TYPE_AX88190;
  205 
  206         /*
  207          * Do generic NE2000 attach.  This will read the station address
  208          * from the EEPROM.
  209          */
  210         if (ne2000_attach(nsc, NULL))
  211                 return;
  212 
  213         /* establish interrupt handler */
  214         psc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET, dp8390_intr,
  215                         dsc);
  216         if (psc->sc_ih == NULL) {
  217                 printf("%s: couldn't establish interrupt handler\n",
  218                        dsc->sc_dev.dv_xname);
  219                 return;
  220         }
  221 }

Cache object: f7d5370019d96eeb39589006e9de5d73


[ 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.