1 /*-
2 * Copyright (c) 1997-2001 Granch, Ltd. All rights reserved.
3 * Author: Denis I.Timofeev <[email protected]>
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 */
28
29 #include <sys/cdefs.h>
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/socket.h>
33
34 #include <sys/bus.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <machine/bus.h>
38 #include <machine/resource.h>
39 #include <sys/rman.h>
40
41 #include <net/if.h>
42 #include <net/if_var.h>
43 #include <net/ethernet.h>
44
45 #include <isa/isavar.h>
46
47 #include <dev/sbni/if_sbnireg.h>
48 #include <dev/sbni/if_sbnivar.h>
49
50 static int sbni_probe_isa(device_t);
51 static int sbni_attach_isa(device_t);
52
53 static device_method_t sbni_isa_methods[] = {
54 /* Device interface */
55 DEVMETHOD(device_probe, sbni_probe_isa),
56 DEVMETHOD(device_attach, sbni_attach_isa),
57 { 0, 0 }
58 };
59
60 static driver_t sbni_isa_driver = {
61 "sbni",
62 sbni_isa_methods,
63 sizeof(struct sbni_softc)
64 };
65
66 static struct isa_pnp_id sbni_ids[] = {
67 { 0, NULL } /* we have no pnp sbni cards atm. */
68 };
69
70 static int
sbni_probe_isa(device_t dev)71 sbni_probe_isa(device_t dev)
72 {
73 struct sbni_softc *sc;
74 int error;
75
76 error = ISA_PNP_PROBE(device_get_parent(dev), dev, sbni_ids);
77 if (error && error != ENOENT)
78 return (error);
79
80 sc = device_get_softc(dev);
81
82 sc->io_res = bus_alloc_resource_anywhere(dev, SYS_RES_IOPORT,
83 &sc->io_rid, SBNI_PORTS,
84 RF_ACTIVE);
85 if (!sc->io_res) {
86 printf("sbni: cannot allocate io ports!\n");
87 return (ENOENT);
88 }
89
90 if (sbni_probe(sc) != 0) {
91 sbni_release_resources(sc);
92 return (ENXIO);
93 }
94
95 device_set_desc(dev, "Granch SBNI12/ISA adapter");
96 return (0);
97 }
98
99 static int
sbni_attach_isa(device_t dev)100 sbni_attach_isa(device_t dev)
101 {
102 struct sbni_softc *sc;
103 struct sbni_flags flags;
104 int error;
105
106 sc = device_get_softc(dev);
107 sc->dev = dev;
108
109 sc->irq_res = bus_alloc_resource_any(
110 dev, SYS_RES_IRQ, &sc->irq_rid, RF_ACTIVE);
111
112 #ifndef SBNI_DUAL_COMPOUND
113
114 if (sc->irq_res == NULL) {
115 device_printf(dev, "irq conflict!\n");
116 sbni_release_resources(sc);
117 return (ENOENT);
118 }
119
120 #else /* SBNI_DUAL_COMPOUND */
121
122 if (sc->irq_res) {
123 sbni_add(sc);
124 } else {
125 struct sbni_softc *master;
126
127 if ((master = connect_to_master(sc)) == NULL) {
128 device_printf(dev, "failed to alloc irq\n");
129 sbni_release_resources(sc);
130 return (ENXIO);
131 } else {
132 device_printf(dev, "shared irq with %s\n",
133 if_name(master->ifp));
134 }
135 }
136 #endif /* SBNI_DUAL_COMPOUND */
137
138 *(u_int32_t*)&flags = device_get_flags(dev);
139
140 sbni_attach(sc, device_get_unit(dev) * 2, flags);
141
142 if (sc->irq_res) {
143 error = bus_setup_intr(
144 dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
145 NULL, sbni_intr, sc, &sc->irq_handle);
146 if (error) {
147 device_printf(dev, "bus_setup_intr\n");
148 sbni_detach(sc);
149 sbni_release_resources(sc);
150 return (error);
151 }
152 }
153
154 return (0);
155 }
156
157 DRIVER_MODULE(sbni, isa, sbni_isa_driver, 0, 0);
158 MODULE_DEPEND(sbni, isa, 1, 1, 1);
159 ISA_PNP_INFO(sbni_ids);
160