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/netif/sbni/if_sbni_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) 1997-2001 Granch, Ltd. All rights reserved.
    3  * Author: Denis I.Timofeev <timofeev@granch.ru>
    4  *
    5  * Redistributon 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 unmodified, this list of conditions, and the following
   10  *    disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   23  * LIABILITY, OR TORT (INCLUDING NEIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  *
   27  * $FreeBSD: src/sys/dev/sbni/if_sbni_pci.c,v 1.6 2002/09/28 20:59:59 phk Exp $
   28  */
   29 
   30  
   31 #include <sys/param.h>
   32 #include <sys/systm.h>
   33 #include <sys/socket.h>
   34 #include <sys/bus.h>
   35 #include <sys/kernel.h>
   36 #include <sys/interrupt.h>
   37 #include <sys/module.h>
   38 #include <sys/rman.h>
   39 #include <sys/malloc.h>
   40 
   41 #include <net/if.h>
   42 #include <net/ethernet.h>
   43 #include <net/if_arp.h>
   44 #include <net/ifq_var.h>
   45 
   46 #include <bus/pci/pcivar.h>
   47 #include <bus/pci/pcireg.h>
   48 
   49 #include "if_sbnireg.h"
   50 #include "if_sbnivar.h"
   51 
   52 static int      sbni_pci_probe(device_t);
   53 static int      sbni_pci_attach(device_t);
   54 
   55 static device_method_t sbni_pci_methods[] = {
   56         /* Device interface */
   57         DEVMETHOD(device_probe, sbni_pci_probe),
   58         DEVMETHOD(device_attach, sbni_pci_attach),
   59         DEVMETHOD_END
   60 };
   61 
   62 static driver_t sbni_pci_driver = {
   63         "sbni",
   64         sbni_pci_methods,
   65         sizeof(struct sbni_softc)
   66 };
   67 
   68 static devclass_t sbni_pci_devclass;
   69 
   70 DRIVER_MODULE(if_sbni, pci, sbni_pci_driver, sbni_pci_devclass, NULL, NULL);
   71 
   72 
   73 static int
   74 sbni_pci_probe(device_t dev)
   75 {
   76         struct sbni_softc  *sc;
   77         u_int32_t  ports;
   78    
   79         ports = SBNI_PORTS;
   80         if (pci_get_vendor(dev) != SBNI_PCI_VENDOR ||
   81             pci_get_device(dev) != SBNI_PCI_DEVICE)
   82                 return (ENXIO);
   83 
   84         sc = device_get_softc(dev);
   85 
   86         if (pci_get_subdevice(dev) == 2) {
   87                 ports <<= 1;
   88                 sc->slave_sc = kmalloc(sizeof(struct sbni_softc),
   89                                       M_DEVBUF, M_INTWAIT | M_ZERO);
   90                 device_set_desc(dev, "Granch SBNI12/PCI Dual adapter");
   91         } else {
   92                 device_set_desc(dev, "Granch SBNI12/PCI adapter");
   93         }
   94 
   95         sc->io_rid = PCIR_MAPS;
   96         sc->io_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->io_rid,
   97                                         0ul, ~0ul, ports, RF_ACTIVE);
   98         if (!sc->io_res) {
   99                 kprintf("sbni: cannot allocate io ports!\n");
  100                 if (sc->slave_sc)
  101                         kfree(sc->slave_sc, M_DEVBUF);
  102                 return (ENOENT);
  103         }
  104 
  105         if (sc->slave_sc) {
  106                 sc->slave_sc->io_res = sc->io_res;
  107                 sc->slave_sc->io_off = 4;
  108         }
  109         if (sbni_probe(sc) != 0) {
  110                 bus_release_resource(dev, SYS_RES_IOPORT,
  111                                      sc->io_rid, sc->io_res);
  112                 if (sc->slave_sc)
  113                         kfree(sc->slave_sc, M_DEVBUF);
  114                 return (ENXIO);
  115         }
  116 
  117         device_quiet(dev);
  118         return (0);
  119 }
  120 
  121 static int
  122 sbni_pci_attach(device_t dev)
  123 {
  124         struct sbni_softc *sc;
  125         struct sbni_flags flags;
  126         int error;
  127 
  128         sc = device_get_softc(dev);
  129 
  130         kprintf("sbni%d: <Granch SBNI12/PCI%sadapter> port 0x%lx",
  131                next_sbni_unit, sc->slave_sc ? " Dual " : " ",
  132                rman_get_start(sc->io_res));
  133         sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
  134             RF_SHAREABLE);
  135 
  136         *(u_int32_t*)&flags = 0;
  137 
  138         sbni_attach(sc, next_sbni_unit++, flags);
  139         if (sc->slave_sc)
  140                 sbni_attach(sc->slave_sc, next_sbni_unit++, flags);
  141 
  142         if (sc->irq_res) {
  143                 struct ifnet *ifp = &sc->arpcom.ac_if;
  144 
  145                 ifq_set_cpuid(&ifp->if_snd, rman_get_cpuid(sc->irq_res));
  146 
  147                 error = bus_setup_intr(dev, sc->irq_res, INTR_MPSAFE,
  148                                        sbni_intr, sc, &sc->irq_handle,
  149                                        ifp->if_serializer);
  150                 if (error)
  151                         kprintf("sbni%d: bus_setup_intr\n", next_sbni_unit);
  152         } else {
  153                 kprintf("\nsbni%d: cannot claim irq!\n", next_sbni_unit);
  154         }
  155 
  156         return (0);
  157 
  158 #if 0
  159         bus_release_resource(dev, SYS_RES_IOPORT, sc->io_rid, sc->io_res);
  160         if (sc->irq_res) {
  161                 bus_release_resource(
  162                     dev, SYS_RES_IRQ, sc->irq_rid, sc->irq_res);
  163         }
  164         if (sc->slave_sc)
  165                 kfree(sc->slave_sc, M_DEVBUF);
  166         return (error);
  167 #endif
  168 }

Cache object: a5dfd14e203e9a247f405e8c2f229f5a


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