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