]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/ed/if_ed_isa.c
MFV r326785: 8880 improve DTrace error checking
[FreeBSD/FreeBSD.git] / sys / dev / ed / if_ed_isa.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 1995, David Greenman
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  */
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33
34 #include "opt_ed.h"
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/socket.h>
39 #include <sys/kernel.h>
40
41 #include <sys/module.h>
42 #include <sys/bus.h>
43 #include <machine/bus.h>
44
45 #include <net/ethernet.h>
46 #include <net/if.h>
47 #include <net/if_arp.h>
48 #include <net/if_media.h>
49 #include <net/if_mib.h>
50
51 #include <isa/isavar.h>
52
53 #include <dev/ed/if_edvar.h>
54 #include <dev/ed/if_edreg.h>
55
56 static int ed_isa_probe(device_t);
57 static int ed_isa_attach(device_t);
58
59 static struct isa_pnp_id ed_ids[] = {
60         { 0x0131d805,   NULL },         /* ANX3101 */
61         { 0x4cf48906,   NULL },         /* ATIf44c */
62         { 0x01200507,   NULL },         /* AXE2001 */
63         { 0x0115180e,   NULL },         /* CPX1501 */
64         { 0x0090252a,   NULL },         /* JQE9000 */
65         { 0x0020832e,   NULL },         /* KTC2000 */
66         { 0xd680d041,   NULL },         /* PNP80d6 */
67         { 0x6081d041,   NULL },         /* PNP8160 */
68         { 0x19808c4a,   NULL },         /* RTL8019 */
69         { 0x1684a34d,   NULL },         /* SMC8416 */
70         { 0x1980635e,   NULL },         /* WSC8019 */
71         { 0,            NULL }
72 };
73
74 static int
75 ed_isa_probe_Novell(device_t dev)
76 {
77         struct ed_softc *sc = device_get_softc(dev);
78         int flags = device_get_flags(dev);
79         int err;
80
81         err = ed_probe_Novell(dev, 0, flags);
82         if (err)
83                 return err;
84         ed_Novell_read_mac(sc);
85         /*
86          * Final sanity check for Gateway Ethernet cards before
87          * believing that they really are Gateway AT.
88          * XXX I think this is stale.
89          */
90         if ((ED_FLAGS_GETTYPE(flags) == ED_FLAGS_GWETHER) &&
91             (sc->enaddr[2] == 0x86)) {
92                 sc->type_str = "Gateway AT";
93         }
94         
95         return (0);
96 }
97
98 static int
99 ed_isa_probe(device_t dev)
100 {
101         struct ed_softc *sc = device_get_softc(dev);
102         int flags = device_get_flags(dev);
103         int error = 0;
104
105         /* Check isapnp ids */
106         error = ISA_PNP_PROBE(device_get_parent(dev), dev, ed_ids);
107
108         /* If the card had a PnP ID that didn't match any we know about */
109         if (error == ENXIO)
110                 goto end;
111
112         /* If we had some other problem. */
113         if (!(error == 0 || error == ENOENT))
114                 goto end;
115
116         /* Heuristic probes */
117
118         error = ed_probe_WD80x3(dev, 0, flags);
119         if (error == 0)
120                 goto end;
121         ed_release_resources(dev);
122
123         error = ed_probe_RTL80x9(dev, 0, flags);
124         if (error == 0) {
125                 ed_Novell_read_mac(sc);
126                 goto end;
127         }
128         ed_release_resources(dev);
129         
130 #ifdef ED_3C503
131         error = ed_probe_3Com(dev, 0, flags);
132         if (error == 0)
133                 goto end;
134         ed_release_resources(dev);
135 #endif
136
137 #ifdef ED_SIC
138         error = ed_probe_SIC(dev, 0, flags);
139         if (error == 0)
140                 goto end;
141         ed_release_resources(dev);
142 #endif
143         error = ed_isa_probe_Novell(dev);
144         if (error == 0)
145                 goto end;
146         ed_release_resources(dev);
147
148 #ifdef ED_HPP
149         error = ed_probe_HP_pclanp(dev, 0, flags);
150         if (error == 0)
151                 goto end;
152         ed_release_resources(dev);
153 #endif
154 end:
155         if (error == 0)
156                 error = ed_alloc_irq(dev, 0, 0);
157
158         ed_release_resources(dev);
159         return (error);
160 }
161
162 static int
163 ed_isa_attach(device_t dev)
164 {
165         struct ed_softc *sc = device_get_softc(dev);
166         int error;
167         
168         if (sc->port_used > 0)
169                 ed_alloc_port(dev, 0, sc->port_used);
170         if (sc->mem_used)
171                 ed_alloc_memory(dev, 0, sc->mem_used);
172         ed_alloc_irq(dev, 0, 0);
173
174         if (sc->sc_media_ioctl == NULL)
175                 ed_gen_ifmedia_init(sc);
176         error = ed_attach(dev);
177         if (error) {
178                 ed_release_resources(dev);
179                 return (error);
180         }
181         error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
182             NULL, edintr, sc, &sc->irq_handle);
183         if (error)
184                 ed_release_resources(dev);
185         return (error);
186 }
187
188 static device_method_t ed_isa_methods[] = {
189         /* Device interface */
190         DEVMETHOD(device_probe,         ed_isa_probe),
191         DEVMETHOD(device_attach,        ed_isa_attach),
192         DEVMETHOD(device_detach,        ed_detach),
193
194         { 0, 0 }
195 };
196
197 static driver_t ed_isa_driver = {
198         "ed",
199         ed_isa_methods,
200         sizeof(struct ed_softc)
201 };
202
203 DRIVER_MODULE(ed, isa, ed_isa_driver, ed_devclass, 0, 0);
204 MODULE_DEPEND(ed, isa, 1, 1, 1);
205 MODULE_DEPEND(ed, ether, 1, 1, 1);
206 MODULE_PNP_INFO("E:pnpid;", isa, ed, ed_ids, sizeof(ed_ids[0]),
207     nitems(ed_ids) - 1);
208