2 * Copyright (c) 1997-2001 Granch, Ltd. All rights reserved.
3 * Author: Denis I.Timofeev <timofeev@granch.ru>
5 * Redistributon and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
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.
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
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/socket.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <machine/bus.h>
38 #include <machine/resource.h>
40 #include <sys/malloc.h>
43 #include <net/ethernet.h>
44 #include <net/if_arp.h>
46 #include <dev/pci/pcivar.h>
47 #include <dev/pci/pcireg.h>
49 #include <dev/sbni/if_sbnireg.h>
50 #include <dev/sbni/if_sbnivar.h>
52 static int sbni_pci_probe(device_t);
53 static int sbni_pci_attach(device_t);
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),
62 static driver_t sbni_pci_driver = {
65 sizeof(struct sbni_softc)
68 static devclass_t sbni_pci_devclass;
70 DRIVER_MODULE(sbni, pci, sbni_pci_driver, sbni_pci_devclass, 0, 0);
71 MODULE_DEPEND(sbni, pci, 1, 1, 1);
74 sbni_pci_probe(device_t dev)
76 struct sbni_softc *sc;
80 if (pci_get_vendor(dev) != SBNI_PCI_VENDOR ||
81 pci_get_device(dev) != SBNI_PCI_DEVICE)
84 sc = device_get_softc(dev);
85 bzero(sc, sizeof(struct sbni_softc));
86 if (pci_get_subdevice(dev) == 2) {
88 sc->slave_sc = malloc(sizeof(struct sbni_softc),
89 M_DEVBUF, M_NOWAIT | M_ZERO);
92 device_set_desc(dev, "Granch SBNI12/PCI Dual adapter");
94 device_set_desc(dev, "Granch SBNI12/PCI adapter");
96 sc->io_rid = PCIR_BAR(0);
97 sc->io_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->io_rid,
98 0ul, ~0ul, ports, RF_ACTIVE);
100 printf("sbni: cannot allocate io ports!\n");
102 free(sc->slave_sc, M_DEVBUF);
107 sc->slave_sc->io_res = sc->io_res;
108 sc->slave_sc->io_off = 4;
110 if (sbni_probe(sc) != 0) {
111 bus_release_resource(dev, SYS_RES_IOPORT,
112 sc->io_rid, sc->io_res);
114 free(sc->slave_sc, M_DEVBUF);
123 sbni_pci_attach(device_t dev)
125 struct sbni_softc *sc;
126 struct sbni_flags flags;
129 sc = device_get_softc(dev);
131 printf("sbni%d: <Granch SBNI12/PCI%sadapter> port 0x%lx",
132 next_sbni_unit, sc->slave_sc ? " Dual " : " ",
133 rman_get_start(sc->io_res));
134 sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
138 printf(" irq %ld\n", rman_get_start(sc->irq_res));
139 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
140 sbni_intr, sc, &sc->irq_handle);
142 printf("sbni%d: bus_setup_intr\n", next_sbni_unit);
146 printf("\nsbni%d: cannot claim irq!\n", next_sbni_unit);
151 *(u_int32_t*)&flags = 0;
153 sbni_attach(sc, next_sbni_unit++, flags);
155 sbni_attach(sc->slave_sc, next_sbni_unit++, flags);
159 bus_release_resource(dev, SYS_RES_IOPORT, sc->io_rid, sc->io_res);
161 bus_release_resource(
162 dev, SYS_RES_IRQ, sc->irq_rid, sc->irq_res);
165 free(sc->slave_sc, M_DEVBUF);