kernel: Use NULL for DRIVER_MODULE()'s evh & arg (which are pointers).
[dragonfly.git] / sys / dev / netif / ed / if_ed_isa.c
1 /*
2  * Copyright (c) 1995, David Greenman
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 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 NEGLIGENCE 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/ed/if_ed_isa.c,v 1.15 2003/10/31 18:31:58 brooks Exp $
28  */
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/socket.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/bus.h>
36 #include <sys/interrupt.h>
37 #include <sys/rman.h>
38
39 #include <net/ethernet.h>
40 #include <net/if.h>
41 #include <net/if_arp.h>
42 #include <net/if_mib.h>
43
44 #include <bus/isa/isavar.h>
45
46 #include "if_edvar.h"
47
48 static int ed_isa_probe         (device_t);
49 static int ed_isa_attach        (device_t);
50 static int ed_isa_detach        (device_t);
51
52 static struct isa_pnp_id ed_ids[] = {
53         { 0x1684a34d,   NULL },         /* SMC8416 */
54         { 0xd680d041,   NULL },         /* PNP80d6 */
55         { 0x1980635e,   NULL },         /* WSC8019 */
56         { 0x0131d805,   NULL },         /* ANX3101 */
57         { 0x01200507,   NULL },         /* AXE2001 */
58         { 0x19808c4a,   NULL },         /* RTL8019 */
59         { 0x0090252a,   NULL },         /* JQE9000 */
60         { 0x0020832e,   NULL },         /* KTC2000 */
61         { 0x4cf48906,   NULL },         /* ATIf44c */
62         { 0,            NULL }
63 };
64
65 static int
66 ed_isa_probe(device_t dev)
67 {
68         int flags = device_get_flags(dev);
69         int error = 0;
70
71         /* Check isapnp ids */
72         error = ISA_PNP_PROBE(device_get_parent(dev), dev, ed_ids);
73
74         /* If the card had a PnP ID that didn't match any we know about */
75         if (error == ENXIO) {
76                 goto end;
77         }
78
79         /* If we had some other problem. */
80         if (!(error == 0 || error == ENOENT)) {
81                 goto end;
82         }
83
84         /* Heuristic probes */
85
86         error = ed_probe_WD80x3(dev, 0, flags);
87         if (error == 0)
88                 goto end;
89         ed_release_resources(dev);
90
91         error = ed_probe_3Com(dev, 0, flags);
92         if (error == 0)
93                 goto end;
94         ed_release_resources(dev);
95
96         error = ed_probe_SIC(dev, 0, flags);
97         if (error == 0)
98                 goto end;
99         ed_release_resources(dev);
100
101         error = ed_probe_Novell(dev, 0, flags);
102         if (error == 0)
103                 goto end;
104         ed_release_resources(dev);
105
106         error = ed_probe_HP_pclanp(dev, 0, flags);
107         if (error == 0)
108                 goto end;
109         ed_release_resources(dev);
110
111 end:
112         if (error == 0)
113                 error = ed_alloc_irq(dev, 0, 0);
114
115         ed_release_resources(dev);
116         return (error);
117 }
118
119 static int
120 ed_isa_attach(device_t dev)
121 {
122         struct ed_softc *sc = device_get_softc(dev);
123         int error;
124         
125         if (sc->port_used > 0)
126                 ed_alloc_port(dev, sc->port_rid, sc->port_used);
127         if (sc->mem_used)
128                 ed_alloc_memory(dev, sc->mem_rid, sc->mem_used);
129
130         ed_alloc_irq(dev, sc->irq_rid, 0);
131
132         error = ed_attach(dev);
133         if (error == 0) {
134                 struct ifnet *ifp = &sc->arpcom.ac_if;
135
136                 error = bus_setup_intr(dev, sc->irq_res, INTR_MPSAFE,
137                                        edintr, sc, &sc->irq_handle,
138                                        ifp->if_serializer);
139                 if (error) {
140                         ed_isa_detach(dev);
141                 } else {
142                         ifp->if_cpuid =
143                                 ithread_cpuid(rman_get_start(sc->irq_res));
144                         KKASSERT(ifp->if_cpuid >= 0 && ifp->if_cpuid < ncpus);
145                 }
146         } else {
147                 ed_release_resources(dev);
148         }
149         return (error);
150 }
151
152 static int
153 ed_isa_detach(device_t dev)
154 {
155         struct ed_softc *sc = device_get_softc(dev);
156         struct ifnet *ifp = &sc->arpcom.ac_if;
157
158         lwkt_serialize_enter(ifp->if_serializer);
159
160         if (sc->gone) {
161                 device_printf(dev, "already unloaded\n");
162                 lwkt_serialize_exit(ifp->if_serializer);
163                 return (0);
164         }
165         ed_stop(sc);
166         ifp->if_flags &= ~IFF_RUNNING;
167         sc->gone = 1;
168         bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
169
170         lwkt_serialize_exit(ifp->if_serializer);
171
172         ether_ifdetach(ifp);
173         ed_release_resources(dev);
174         return (0);
175 }
176
177 static device_method_t ed_isa_methods[] = {
178         /* Device interface */
179         DEVMETHOD(device_probe,         ed_isa_probe),
180         DEVMETHOD(device_attach,        ed_isa_attach),
181         DEVMETHOD(device_attach,        ed_isa_detach),
182
183         { 0, 0 }
184 };
185
186 static driver_t ed_isa_driver = {
187         "ed",
188         ed_isa_methods,
189         sizeof(struct ed_softc)
190 };
191
192 DRIVER_MODULE(if_ed, isa, ed_isa_driver, ed_devclass, NULL, NULL);
193 MODULE_DEPEND(if_ed, isa, 1, 1, 1);