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/hme/if_hme_pci.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 /*
    2  * Copyright (c) 2000 Matthew R. Green
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. The name of the author may not be used to endorse or promote products
   14  *    derived from this software without specific prior written permission.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
   23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26  * SUCH DAMAGE.
   27  *
   28  *      from: NetBSD: if_hme_pci.c,v 1.4 2001/08/27 22:18:49 augustss Exp
   29  *
   30  * $FreeBSD: releng/5.0/sys/dev/hme/if_hme_pci.c 93043 2002-03-23 19:37:11Z tmm $
   31  */
   32 
   33 /*
   34  * PCI front-end device driver for the HME ethernet device.
   35  */
   36 
   37 #include <sys/param.h>
   38 #include <sys/systm.h>
   39 #include <sys/bus.h>
   40 #include <sys/kernel.h>
   41 #include <sys/resource.h>
   42 #include <sys/socket.h>
   43 
   44 #include <machine/bus.h>
   45 #include <machine/ofw_machdep.h>
   46 #include <machine/resource.h>
   47 
   48 #include <sys/rman.h>
   49 
   50 #include <net/ethernet.h>
   51 #include <net/if.h>
   52 #include <net/if_arp.h>
   53 #include <net/if_dl.h>
   54 #include <net/if_media.h>
   55 
   56 #include <mii/mii.h>
   57 #include <mii/miivar.h>
   58 
   59 #include <pci/pcivar.h>
   60 #include <pci/pcireg.h>
   61 
   62 #include <hme/if_hmereg.h>
   63 #include <hme/if_hmevar.h>
   64 
   65 #include "miibus_if.h"
   66 
   67 struct hme_pci_softc {
   68         struct  hme_softc       hsc_hme;        /* HME device */
   69         struct  resource        *hsc_sres;
   70         int                     hsc_srid;
   71         struct  resource        *hsc_ires;
   72         int                     hsc_irid;
   73         bus_space_tag_t         hsc_memt;
   74         bus_space_handle_t      hsc_memh;
   75         void                    *hsc_ih;
   76 };
   77 
   78 static int hme_pci_probe(device_t);
   79 static int hme_pci_attach(device_t);
   80 
   81 static device_method_t hme_pci_methods[] = {
   82         /* Device interface */
   83         DEVMETHOD(device_probe,         hme_pci_probe),
   84         DEVMETHOD(device_attach,        hme_pci_attach),
   85 
   86         /* bus interface */
   87         DEVMETHOD(bus_print_child,      bus_generic_print_child),
   88         DEVMETHOD(bus_driver_added,     bus_generic_driver_added),
   89 
   90         /* MII interface */
   91         DEVMETHOD(miibus_readreg,       hme_mii_readreg),
   92         DEVMETHOD(miibus_writereg,      hme_mii_writereg),
   93         DEVMETHOD(miibus_statchg,       hme_mii_statchg),
   94 
   95         { 0, 0 }
   96 };
   97 
   98 static driver_t hme_pci_driver = {
   99         "hme",
  100         hme_pci_methods,
  101         sizeof(struct hme_pci_softc)
  102 };
  103 
  104 DRIVER_MODULE(if_hme, pci, hme_pci_driver, hme_devclass, 0, 0);
  105 
  106 int
  107 hme_pci_probe(device_t dev)
  108 {
  109 
  110         if (pci_get_vendor(dev) == 0x108e &&
  111             pci_get_device(dev) ==  0x1001) {
  112                 device_set_desc(dev, "Sun HME 10/100 Ethernet");
  113                 return (0);
  114         }
  115         return (ENXIO);
  116 }
  117 
  118 int
  119 hme_pci_attach(device_t dev)
  120 {
  121         struct hme_pci_softc *hsc = device_get_softc(dev);
  122         struct hme_softc *sc = &hsc->hsc_hme;
  123         int error;
  124 
  125         /*
  126          * Enable memory-space and bus master accesses.  This is kinda of
  127          * gross; but the hme comes up with neither enabled.
  128          */
  129         pci_enable_busmaster(dev);
  130         pci_enable_io(dev, SYS_RES_MEMORY);
  131 
  132         sc->sc_pci = 1; /* XXXXX should all be done in bus_dma. */
  133         sc->sc_dev = dev;
  134 
  135         /*
  136          * Map five register banks:
  137          *
  138          *      bank 0: HME SEB registers:      +0x0000
  139          *      bank 1: HME ETX registers:      +0x2000
  140          *      bank 2: HME ERX registers:      +0x4000
  141          *      bank 3: HME MAC registers:      +0x6000
  142          *      bank 4: HME MIF registers:      +0x7000
  143          *
  144          */
  145         hsc->hsc_srid = PCI_HME_BASEADDR;
  146         hsc->hsc_sres = bus_alloc_resource(dev, SYS_RES_MEMORY, &hsc->hsc_srid,
  147             0, ~0, 1, RF_ACTIVE);
  148         if (hsc->hsc_sres == NULL) {
  149                 device_printf(dev, "could not map device registers\n");
  150                 return (ENXIO);
  151         }
  152         hsc->hsc_irid = 0;
  153         hsc->hsc_ires = bus_alloc_resource(dev, SYS_RES_IRQ, &hsc->hsc_irid, 0,
  154             ~0, 1, RF_SHAREABLE | RF_ACTIVE);
  155         if (hsc->hsc_ires == NULL) {
  156                 device_printf(dev, "could not allocate interrupt\n");
  157                 error = ENXIO;
  158                 goto fail_sres;
  159         }
  160         sc->sc_sebt = sc->sc_etxt = sc->sc_erxt = sc->sc_mact = sc->sc_mift =
  161             rman_get_bustag(hsc->hsc_sres);
  162         sc->sc_sebh = sc->sc_etxh = sc->sc_erxh = sc->sc_mach = sc->sc_mifh =
  163             rman_get_bushandle(hsc->hsc_sres);
  164         sc->sc_sebo = 0;
  165         sc->sc_etxo = 0x2000;
  166         sc->sc_erxo = 0x4000;
  167         sc->sc_maco = 0x6000;
  168         sc->sc_mifo = 0x7000;
  169 
  170         OF_getetheraddr(dev, sc->sc_arpcom.ac_enaddr);
  171 
  172         sc->sc_burst = 64;      /* XXX */
  173 
  174         /*
  175          * call the main configure
  176          */
  177         if ((error = hme_config(sc)) != 0) {
  178                 device_printf(dev, "could not be configured\n");
  179                 goto fail_ires;
  180         }
  181 
  182         if ((error = bus_setup_intr(dev, hsc->hsc_ires, INTR_TYPE_NET, hme_intr,
  183              sc, &hsc->hsc_ih)) != 0) {
  184                 device_printf(dev, "couldn't establish interrupt\n");
  185                 goto fail_ires;
  186         }
  187         return (0);
  188 
  189 fail_ires:
  190         bus_release_resource(dev, SYS_RES_IRQ, hsc->hsc_irid, hsc->hsc_ires);
  191 fail_sres:
  192         bus_release_resource(dev, SYS_RES_MEMORY, hsc->hsc_srid, hsc->hsc_sres);
  193         return (ENXIO);
  194 }

Cache object: 5006db50bc87139cd4ef71d0672320b2


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