Merge from vendor branch GCC:
[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.10 2005/08/29 10:19:51 sephe Exp $
29  */
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/socket.h>
34 #include <sys/kernel.h>
35
36 #include <sys/module.h>
37 #include <sys/bus.h>
38 #include <machine/bus.h>
39
40 #include <net/ethernet.h>
41 #include <net/if.h>
42 #include <net/if_arp.h>
43 #include <net/if_mib.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
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(dev)
67         device_t dev;
68 {
69         struct ed_softc *sc = device_get_softc(dev);
70         int flags = device_get_flags(dev);
71         int error = 0;
72
73         /* Check isapnp ids */
74         error = ISA_PNP_PROBE(device_get_parent(dev), dev, ed_ids);
75
76         /* If the card had a PnP ID that didn't match any we know about */
77         if (error == ENXIO) {
78                 goto end;
79         }
80
81         /* If we had some other problem. */
82         if (!(error == 0 || error == ENOENT)) {
83                 goto end;
84         }
85
86         /* Heuristic probes */
87
88         error = ed_probe_WD80x3(dev, 0, flags);
89         if (error == 0)
90                 goto end;
91         ed_release_resources(dev);
92
93         error = ed_probe_3Com(dev, 0, flags);
94         if (error == 0)
95                 goto end;
96         ed_release_resources(dev);
97
98         error = ed_probe_SIC(dev, 0, flags);
99         if (error == 0)
100                 goto end;
101         ed_release_resources(dev);
102
103         error = ed_probe_Novell(dev, 0, flags);
104         if (error == 0)
105                 goto end;
106         ed_release_resources(dev);
107
108         error = ed_probe_HP_pclanp(dev, 0, flags);
109         if (error == 0)
110                 goto end;
111         ed_release_resources(dev);
112
113 end:
114         if (error == 0)
115                 error = ed_alloc_irq(dev, 0, 0);
116
117         ed_release_resources(dev);
118         return (error);
119 }
120
121 static int
122 ed_isa_attach(dev)
123         device_t dev;
124 {
125         struct ed_softc *sc = device_get_softc(dev);
126         int error;
127         
128         if (sc->port_used > 0)
129                 ed_alloc_port(dev, sc->port_rid, sc->port_used);
130         if (sc->mem_used)
131                 ed_alloc_memory(dev, sc->mem_rid, sc->mem_used);
132
133         ed_alloc_irq(dev, sc->irq_rid, 0);
134
135         error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
136                                edintr, sc, &sc->irq_handle, NULL);
137         if (error) {
138                 ed_release_resources(dev);
139                 return (error);
140         }
141
142         return ed_attach(dev);
143 }
144
145 static device_method_t ed_isa_methods[] = {
146         /* Device interface */
147         DEVMETHOD(device_probe,         ed_isa_probe),
148         DEVMETHOD(device_attach,        ed_isa_attach),
149
150         { 0, 0 }
151 };
152
153 static driver_t ed_isa_driver = {
154         "ed",
155         ed_isa_methods,
156         sizeof(struct ed_softc)
157 };
158
159 DRIVER_MODULE(if_ed, isa, ed_isa_driver, ed_devclass, 0, 0);
160 MODULE_DEPEND(if_ed, isa, 1, 1, 1);