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/isa/if_ne_isa.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 /*      $OpenBSD: if_ne_isa.c,v 1.18 2022/04/06 18:59:28 naddy 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  *
   21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   31  * POSSIBILITY OF SUCH DAMAGE.
   32  */
   33 
   34 #include "bpfilter.h"
   35 
   36 #include <sys/param.h>
   37 #include <sys/systm.h>
   38 #include <sys/mbuf.h>
   39 #include <sys/socket.h>
   40 #include <sys/ioctl.h>
   41 #include <sys/errno.h>
   42 #include <sys/syslog.h>
   43 #include <sys/selinfo.h>
   44 #include <sys/device.h>
   45 
   46 #include <net/if.h>
   47 #include <net/if_media.h>
   48 
   49 #include <netinet/in.h>
   50 #include <netinet/if_ether.h>
   51 
   52 #if NBPFILTER > 0
   53 #include <net/bpf.h>
   54 #endif
   55 
   56 #include <machine/intr.h>
   57 #include <machine/bus.h>
   58 
   59 #include <dev/ic/dp8390reg.h>
   60 #include <dev/ic/dp8390var.h>
   61 
   62 #include <dev/ic/ne2000reg.h>
   63 #include <dev/ic/ne2000var.h>
   64 
   65 #include <dev/ic/rtl80x9reg.h>
   66 #include <dev/ic/rtl80x9var.h>          
   67 
   68 #include <dev/isa/isavar.h>
   69 
   70 int     ne_isa_match(struct device *, void *, void *);
   71 void    ne_isa_attach(struct device *, struct device *, void *);
   72 
   73 struct ne_isa_softc {
   74         struct  ne2000_softc sc_ne2000;         /* real "ne2000" softc */
   75 
   76         /* ISA-specific goo. */
   77         void    *sc_ih;                         /* interrupt cookie */
   78 };
   79 
   80 const struct cfattach ne_isa_ca = {
   81         sizeof(struct ne_isa_softc), ne_isa_match, ne_isa_attach
   82 };
   83 
   84 int
   85 ne_isa_match(struct device *parent, void *match, void *aux)
   86 {
   87         struct ne_isa_softc *isc = match;
   88         struct ne2000_softc *nsc = &isc->sc_ne2000;
   89         struct dp8390_softc *dsc = &nsc->sc_dp8390;
   90         struct isa_attach_args *ia = aux;
   91         bus_space_tag_t nict = ia->ia_iot;
   92         bus_space_handle_t nich;
   93         bus_space_tag_t asict;
   94         bus_space_handle_t asich;
   95 
   96         /* Disallow wildcarded values. */
   97         if (ia->ia_irq ==  -1 /* ISACF_IRQ_DEFAULT */)
   98                 return (0);
   99         if (ia->ia_iobase == -1 /* ISACF_PORT_DEFAULT */)
  100                 return (0);
  101 
  102         /* Make sure this is a valid NE[12]000 i/o address. */
  103         if ((ia->ia_iobase & 0x1f) != 0)
  104                 return (0);
  105 
  106         /* Map i/o space. */
  107         if (bus_space_map(nict, ia->ia_iobase, NE2000_NPORTS, 0, &nich))
  108                 return (0);
  109 
  110         asict = nict;
  111         if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
  112             NE2000_ASIC_NPORTS, &asich))
  113                 goto out;
  114 
  115         dsc->sc_regt = nict;
  116         dsc->sc_regh = nich;
  117 
  118         nsc->sc_asict = asict;
  119         nsc->sc_asich = asich;
  120 
  121         /* Look for an NE2000-compatible card. */
  122         nsc->sc_type = ne2000_detect(nsc);
  123 
  124         if (nsc->sc_type)
  125                 ia->ia_iosize = NE2000_NPORTS;
  126 
  127  out:
  128         bus_space_unmap(nict, nich, NE2000_NPORTS);
  129         return (nsc->sc_type);
  130 }
  131 
  132 void
  133 ne_isa_attach(struct device *parent, struct device *self, void *aux)
  134 {
  135         struct ne_isa_softc *isc = (struct ne_isa_softc *)self;
  136         struct ne2000_softc *nsc = &isc->sc_ne2000;
  137         struct dp8390_softc *dsc = &nsc->sc_dp8390;
  138         struct isa_attach_args *ia = aux;
  139         bus_space_tag_t nict = ia->ia_iot;
  140         bus_space_handle_t nich;
  141         bus_space_tag_t asict = nict;
  142         bus_space_handle_t asich;
  143         const char *typestr;
  144 
  145         /* Map i/o space. */
  146         if (bus_space_map(nict, ia->ia_iobase, NE2000_NPORTS, 0, &nich)) {
  147                 printf("%s: can't map i/o space\n", dsc->sc_dev.dv_xname);
  148                 return;
  149         }
  150 
  151         if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
  152             NE2000_ASIC_NPORTS, &asich)) {
  153                 printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
  154                 return;
  155         }
  156 
  157         dsc->sc_regt = nict;
  158         dsc->sc_regh = nich;
  159 
  160         nsc->sc_asict = asict;
  161         nsc->sc_asich = asich;
  162 
  163         switch (nsc->sc_type) {
  164         case NE2000_TYPE_NE1000:
  165                 typestr = "NE1000";
  166                 break;
  167 
  168         case NE2000_TYPE_NE2000:
  169                 typestr = "NE2000";
  170                 /*
  171                  * Check for a Realtek 8019.
  172                  */
  173                 bus_space_write_1(nict, nich, ED_P0_CR,
  174                     ED_CR_PAGE_0 | ED_CR_STP);
  175                 if (bus_space_read_1(nict, nich, NERTL_RTL0_8019ID0) ==
  176                                                                 RTL0_8019ID0 &&
  177                     bus_space_read_1(nict, nich, NERTL_RTL0_8019ID1) ==
  178                                                                 RTL0_8019ID1) {
  179                         typestr = "NE2000 (RTL8019)";
  180                         dsc->sc_mediachange = rtl80x9_mediachange;
  181                         dsc->sc_mediastatus = rtl80x9_mediastatus;
  182                         dsc->init_card = rtl80x9_init_card;
  183                         dsc->sc_media_init = rtl80x9_media_init;
  184                 }
  185                 break;
  186 
  187         default:
  188                 printf(": where did the card go?!\n");
  189                 return;
  190         }
  191 
  192         printf(", %s", typestr);
  193 
  194         /* This interface is always enabled. */
  195         dsc->sc_enabled = 1;
  196 
  197         /*
  198          * Do generic NE2000 attach.  This will read the station address
  199          * from the EEPROM.
  200          */
  201         ne2000_attach(nsc, NULL);
  202 
  203         /* Establish the interrupt handler. */
  204         isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
  205             IPL_NET, dp8390_intr, dsc, dsc->sc_dev.dv_xname);
  206         if (isc->sc_ih == NULL)
  207                 printf(": couldn't establish interrupt handler\n");
  208 }

Cache object: adac8dffcc27724b1d1861852f2553be


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