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/vx/if_vx_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) 1996 Naoki Hamada <nao@tom-yam.or.jp>
    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. Neither the name of the author nor the names of any co-contributors
   14  *    may be used to endorse or promote products derived from this software
   15  *    without specific prior written permission.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  */
   29 
   30 #include <sys/cdefs.h>
   31 __FBSDID("$FreeBSD: releng/11.2/sys/dev/vx/if_vx_pci.c 331722 2018-03-29 02:50:57Z eadler $");
   32 
   33 #include <sys/param.h>
   34 #include <sys/systm.h>
   35 #include <sys/kernel.h>
   36 #include <sys/module.h>
   37 #include <sys/socket.h>
   38 
   39 #include <net/ethernet.h>
   40 #include <net/if.h>
   41 #include <net/if_var.h>
   42 #include <net/if_arp.h>
   43 
   44 #include <machine/bus.h>
   45 #include <machine/resource.h>
   46 #include <sys/bus.h>
   47 #include <sys/rman.h>
   48 
   49 #include <dev/pci/pcivar.h>
   50 #include <dev/pci/pcireg.h>
   51 
   52 #include <dev/vx/if_vxreg.h>
   53 #include <dev/vx/if_vxvar.h>
   54 
   55 static int vx_pci_shutdown(device_t);
   56 static int vx_pci_probe(device_t);
   57 static int vx_pci_attach(device_t);
   58 
   59 static device_method_t vx_methods[] = {
   60         /* Device interface */
   61         DEVMETHOD(device_probe, vx_pci_probe),
   62         DEVMETHOD(device_attach, vx_pci_attach),
   63         DEVMETHOD(device_shutdown, vx_pci_shutdown),
   64 
   65         DEVMETHOD_END
   66 };
   67 
   68 static driver_t vx_driver = {
   69         "vx",
   70         vx_methods,
   71         sizeof(struct vx_softc)
   72 };
   73 
   74 static devclass_t vx_devclass;
   75 
   76 DRIVER_MODULE(vx, pci, vx_driver, vx_devclass, 0, 0);
   77 MODULE_DEPEND(vx, pci, 1, 1, 1);
   78 MODULE_DEPEND(vx, ether, 1, 1, 1);
   79 
   80 static int
   81 vx_pci_shutdown(device_t dev)
   82 {
   83         struct vx_softc *sc;
   84 
   85         sc = device_get_softc(dev);
   86         VX_LOCK(sc);
   87         vx_stop(sc);
   88         VX_UNLOCK(sc);
   89 
   90         return (0);
   91 }
   92 
   93 static int
   94 vx_pci_probe(device_t dev)
   95 {
   96         u_int32_t device_id;
   97 
   98         device_id = pci_read_config(dev, PCIR_DEVVENDOR, 4);
   99 
  100         if (device_id == 0x590010b7ul) {
  101                 device_set_desc(dev, "3COM 3C590 Etherlink III PCI");
  102                 return (BUS_PROBE_DEFAULT);
  103         }
  104         if (device_id == 0x595010b7ul || device_id == 0x595110b7ul ||
  105             device_id == 0x595210b7ul) {
  106                 device_set_desc(dev, "3COM 3C595 Etherlink III PCI");
  107                 return (BUS_PROBE_DEFAULT);
  108         }
  109         /*
  110          * The (Fast) Etherlink XL adapters are now supported by
  111          * the xl driver, which uses bus master DMA and is much
  112          * faster. (And which also supports the 3c905B.
  113          */
  114         if (device_id == 0x900010b7ul || device_id == 0x900110b7ul) {
  115                 device_set_desc(dev, "3COM 3C900 Etherlink XL PCI");
  116                 return (BUS_PROBE_LOW_PRIORITY);
  117         }
  118         if (device_id == 0x905010b7ul || device_id == 0x905110b7ul) {
  119                 device_set_desc(dev, "3COM 3C905 Etherlink XL PCI");
  120                 return (BUS_PROBE_LOW_PRIORITY);
  121         }
  122         return (ENXIO);
  123 }
  124 
  125 static int
  126 vx_pci_attach(device_t dev)
  127 {
  128         struct vx_softc *sc;
  129         int rid;
  130 
  131         sc = device_get_softc(dev);
  132 
  133         rid = PCIR_BAR(0);
  134         sc->vx_res =
  135             bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
  136 
  137         if (sc->vx_res == NULL)
  138                 goto bad;
  139 
  140         sc->vx_bst = rman_get_bustag(sc->vx_res);
  141         sc->vx_bsh = rman_get_bushandle(sc->vx_res);
  142 
  143         rid = 0;
  144         sc->vx_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
  145             RF_SHAREABLE | RF_ACTIVE);
  146 
  147         if (sc->vx_irq == NULL)
  148                 goto bad;
  149 
  150         if (vx_attach(dev) == 0)
  151                 goto bad;
  152 
  153         if (bus_setup_intr(dev, sc->vx_irq, INTR_TYPE_NET | INTR_MPSAFE,
  154             NULL, vx_intr, sc, &sc->vx_intrhand))
  155                 goto bad_mtx;
  156 
  157         /* defect check for 3C590 */
  158         if ((pci_read_config(dev, PCIR_DEVVENDOR, 4) >> 16) == 0x5900) {
  159                 GO_WINDOW(0);
  160                 if (vx_busy_eeprom(sc))
  161                         goto bad_mtx;
  162                 CSR_WRITE_2(sc, VX_W0_EEPROM_COMMAND,
  163                     EEPROM_CMD_RD | EEPROM_SOFTINFO2);
  164                 if (vx_busy_eeprom(sc))
  165                         goto bad_mtx;
  166                 if (!(CSR_READ_2(sc, VX_W0_EEPROM_DATA) & NO_RX_OVN_ANOMALY))
  167                         device_printf(dev,
  168                             "Warning! Defective early revision adapter!\n");
  169         }
  170         return (0);
  171 
  172 bad_mtx:
  173         mtx_destroy(&sc->vx_mtx);
  174         ether_ifdetach(sc->vx_ifp);
  175         if_free(sc->vx_ifp);
  176 bad:
  177         if (sc->vx_intrhand != NULL)
  178                 bus_teardown_intr(dev, sc->vx_irq, sc->vx_intrhand);
  179         if (sc->vx_res != NULL)
  180                 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->vx_res);
  181         if (sc->vx_irq != NULL)
  182                 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vx_irq);
  183         return (ENXIO);
  184 }

Cache object: 72865c08265493a8cf635d7882132435


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