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