root/dev/isa/if_ne_isa.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ne_isa_match
  2. ne_isa_attach

    1 /*      $OpenBSD: if_ne_isa.c,v 1.12 2006/10/20 17:02:24 brad Exp $     */
    2 /*      $NetBSD: if_ne_isa.c,v 1.6 1998/07/05 06:49:13 jonathan Exp $   */
    3 
    4 /*-
    5  * Copyright (c) 1997 The NetBSD Foundation, Inc.
    6  * All rights reserved.
    7  *
    8  * This code is derived from software contributed to The NetBSD Foundation
    9  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
   10  * NASA Ames Research Center.
   11  *
   12  * Redistribution and use in source and binary forms, with or without
   13  * modification, are permitted provided that the following conditions
   14  * are met:
   15  * 1. Redistributions of source code must retain the above copyright
   16  *    notice, this list of conditions and the following disclaimer.
   17  * 2. Redistributions in binary form must reproduce the above copyright
   18  *    notice, this list of conditions and the following disclaimer in the
   19  *    documentation and/or other materials provided with the distribution.
   20  * 3. All advertising materials mentioning features or use of this software
   21  *    must display the following acknowledgement:
   22  *      This product includes software developed by the NetBSD
   23  *      Foundation, Inc. and its contributors.
   24  * 4. Neither the name of The NetBSD Foundation nor the names of its
   25  *    contributors may be used to endorse or promote products derived
   26  *    from this software without specific prior written permission.
   27  *
   28  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   29  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   31  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   38  * POSSIBILITY OF SUCH DAMAGE.
   39  */
   40 
   41 #include "bpfilter.h"
   42 
   43 #include <sys/param.h>
   44 #include <sys/systm.h>
   45 #include <sys/mbuf.h>
   46 #include <sys/socket.h>
   47 #include <sys/ioctl.h>
   48 #include <sys/errno.h>
   49 #include <sys/syslog.h>
   50 #include <sys/selinfo.h>
   51 #include <sys/device.h>
   52 
   53 #include <net/if.h>
   54 #include <net/if_dl.h>
   55 #include <net/if_media.h>
   56 
   57 #ifdef INET
   58 #include <netinet/in.h>
   59 #include <netinet/in_systm.h>
   60 #include <netinet/in_var.h>
   61 #include <netinet/ip.h>
   62 #include <netinet/if_ether.h>
   63 #endif
   64 
   65 #if NBPFILTER > 0
   66 #include <net/bpf.h>
   67 #endif
   68 
   69 #include <machine/intr.h>
   70 #include <machine/bus.h>
   71 
   72 #include <dev/ic/dp8390reg.h>
   73 #include <dev/ic/dp8390var.h>
   74 
   75 #include <dev/ic/ne2000reg.h>
   76 #include <dev/ic/ne2000var.h>
   77 
   78 #include <dev/ic/rtl80x9reg.h>
   79 #include <dev/ic/rtl80x9var.h>          
   80 
   81 #include <dev/isa/isavar.h>
   82 
   83 int     ne_isa_match(struct device *, void *, void *);
   84 void    ne_isa_attach(struct device *, struct device *, void *);
   85 
   86 struct ne_isa_softc {
   87         struct  ne2000_softc sc_ne2000;         /* real "ne2000" softc */
   88 
   89         /* ISA-specific goo. */
   90         void    *sc_ih;                         /* interrupt cookie */
   91 };
   92 
   93 struct cfattach ne_isa_ca = {
   94         sizeof(struct ne_isa_softc), ne_isa_match, ne_isa_attach
   95 };
   96 
   97 int
   98 ne_isa_match(struct device *parent, void *match, void *aux)
   99 {
  100         struct ne_isa_softc *isc = match;
  101         struct ne2000_softc *nsc = &isc->sc_ne2000;
  102         struct dp8390_softc *dsc = &nsc->sc_dp8390;
  103         struct isa_attach_args *ia = aux;
  104         bus_space_tag_t nict = ia->ia_iot;
  105         bus_space_handle_t nich;
  106         bus_space_tag_t asict;
  107         bus_space_handle_t asich;
  108 
  109         /* Disallow wildcarded values. */
  110         if (ia->ia_irq ==  -1 /* ISACF_IRQ_DEFAULT */)
  111                 return (0);
  112         if (ia->ia_iobase == -1 /* ISACF_PORT_DEFAULT */)
  113                 return (0);
  114 
  115         /* Make sure this is a valid NE[12]000 i/o address. */
  116         if ((ia->ia_iobase & 0x1f) != 0)
  117                 return (0);
  118 
  119         /* Map i/o space. */
  120         if (bus_space_map(nict, ia->ia_iobase, NE2000_NPORTS, 0, &nich))
  121                 return (0);
  122 
  123         asict = nict;
  124         if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
  125             NE2000_ASIC_NPORTS, &asich))
  126                 goto out;
  127 
  128         dsc->sc_regt = nict;
  129         dsc->sc_regh = nich;
  130 
  131         nsc->sc_asict = asict;
  132         nsc->sc_asich = asich;
  133 
  134         /* Look for an NE2000-compatible card. */
  135         nsc->sc_type = ne2000_detect(nsc);
  136 
  137         if (nsc->sc_type)
  138                 ia->ia_iosize = NE2000_NPORTS;
  139 
  140  out:
  141         bus_space_unmap(nict, nich, NE2000_NPORTS);
  142         return (nsc->sc_type);
  143 }
  144 
  145 void
  146 ne_isa_attach(struct device *parent, struct device *self, void *aux)
  147 {
  148         struct ne_isa_softc *isc = (struct ne_isa_softc *)self;
  149         struct ne2000_softc *nsc = &isc->sc_ne2000;
  150         struct dp8390_softc *dsc = &nsc->sc_dp8390;
  151         struct isa_attach_args *ia = aux;
  152         bus_space_tag_t nict = ia->ia_iot;
  153         bus_space_handle_t nich;
  154         bus_space_tag_t asict = nict;
  155         bus_space_handle_t asich;
  156         const char *typestr;
  157 
  158         /* Map i/o space. */
  159         if (bus_space_map(nict, ia->ia_iobase, NE2000_NPORTS, 0, &nich)) {
  160                 printf("%s: can't map i/o space\n", dsc->sc_dev.dv_xname);
  161                 return;
  162         }
  163 
  164         if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
  165             NE2000_ASIC_NPORTS, &asich)) {
  166                 printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
  167                 return;
  168         }
  169 
  170         dsc->sc_regt = nict;
  171         dsc->sc_regh = nich;
  172 
  173         nsc->sc_asict = asict;
  174         nsc->sc_asich = asich;
  175 
  176         switch (nsc->sc_type) {
  177         case NE2000_TYPE_NE1000:
  178                 typestr = "NE1000";
  179                 break;
  180 
  181         case NE2000_TYPE_NE2000:
  182                 typestr = "NE2000";
  183                 /*
  184                  * Check for a RealTek 8019.
  185                  */
  186                 bus_space_write_1(nict, nich, ED_P0_CR,
  187                     ED_CR_PAGE_0 | ED_CR_STP);
  188                 if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) ==
  189                                                                 RTL0_8019ID0 &&
  190                     bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) ==
  191                                                                 RTL0_8019ID1) {
  192                         typestr = "NE2000 (RTL8019)";
  193                         dsc->sc_mediachange = rtl80x9_mediachange;
  194                         dsc->sc_mediastatus = rtl80x9_mediastatus;
  195                         dsc->init_card = rtl80x9_init_card;
  196                         dsc->sc_media_init = rtl80x9_media_init;
  197                 }
  198                 break;
  199 
  200         default:
  201                 printf(": where did the card go?!\n");
  202                 return;
  203         }
  204 
  205         printf(", %s", typestr);
  206 
  207         /* This interface is always enabled. */
  208         dsc->sc_enabled = 1;
  209 
  210         /*
  211          * Do generic NE2000 attach.  This will read the station address
  212          * from the EEPROM.
  213          */
  214         ne2000_attach(nsc, NULL);
  215 
  216         /* Establish the interrupt handler. */
  217         isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
  218             IPL_NET, dp8390_intr, dsc, dsc->sc_dev.dv_xname);
  219         if (isc->sc_ih == NULL)
  220                 printf(": couldn't establish interrupt handler\n");
  221 }

/* [<][>][^][v][top][bottom][index][help] */