Deleted Added
full compact
if_snc_cbus.c (113506) if_snc_cbus.c (119419)
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 *
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: head/sys/dev/snc/if_snc_cbus.c 113506 2003-04-15 06:37:30Z mdodd $
28 */
29
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/dev/snc/if_snc_cbus.c 119419 2003-08-24 18:03:45Z obrien $");
31
30/*
31 * National Semiconductor DP8393X SONIC Driver
32 *
33 * This is the C-bus specific attachment on FreeBSD
34 * written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp>
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/socket.h>
40#include <sys/kernel.h>
41
42#include <sys/module.h>
43#include <sys/bus.h>
44#include <machine/bus.h>
45#include <machine/resource.h>
46
47#include <net/if.h>
48#include <net/if_arp.h>
49#include <net/if_media.h>
50
51#include <isa/isavar.h>
52#include <sys/malloc.h> /* as dependency for isa/isa_common.h */
53#include <isa/isa_common.h> /* for snc_isapnp_reconfig() */
54
55#include <dev/snc/dp83932var.h>
56#include <dev/snc/if_sncreg.h>
57#include <dev/snc/if_sncvar.h>
58
59static void snc_isapnp_reconfig (device_t);
60static int snc_isa_probe (device_t);
61static int snc_isa_attach (device_t);
62
63static struct isa_pnp_id snc_ids[] = {
64 { 0x6180a3b8, NULL }, /* NEC8061 NEC PC-9801-104 */
65 { 0, NULL }
66};
67
68static void
69snc_isapnp_reconfig(dev)
70 device_t dev;
71{
72 struct isa_device *idev = DEVTOISA(dev);
73 struct isa_config config;
74 u_long start, count;
75 int rid;
76
77 bzero(&config, sizeof(config));
78
79 for (rid = 0; rid < ISA_NMEM; rid++) {
80 if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count))
81 break;
82 config.ic_mem[rid].ir_start = start;
83 config.ic_mem[rid].ir_end = start;
84 config.ic_mem[rid].ir_size = count;
85 }
86 config.ic_nmem = rid;
87 for (rid = 0; rid < ISA_NPORT; rid++) {
88 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count))
89 break;
90 config.ic_port[rid].ir_start = start;
91 config.ic_port[rid].ir_end = start;
92 config.ic_port[rid].ir_size = count;
93 }
94 config.ic_nport = rid;
95 for (rid = 0; rid < ISA_NIRQ; rid++) {
96 if (bus_get_resource(dev, SYS_RES_IRQ, rid, &start, &count))
97 break;
98 config.ic_irqmask[rid] = 1 << start;
99 }
100 config.ic_nirq = rid;
101 for (rid = 0; rid < ISA_NDRQ; rid++) {
102 if (bus_get_resource(dev, SYS_RES_DRQ, rid, &start, &count))
103 break;
104 config.ic_drqmask[rid] = 1 << start;
105 }
106 config.ic_ndrq = rid;
107
108 idev->id_config_cb(idev->id_config_arg, &config, 1);
109}
110
111static int
112snc_isa_probe(dev)
113 device_t dev;
114{
115 struct snc_softc *sc = device_get_softc(dev);
116 int type;
117 int error = 0;
118
119 bzero(sc, sizeof(struct snc_softc));
120
121 /* Check isapnp ids */
122 error = ISA_PNP_PROBE(device_get_parent(dev), dev, snc_ids);
123
124 /* If the card had a PnP ID that didn't match any we know about */
125 if (error == ENXIO) {
126 return(error);
127 }
128
129 switch (error) {
130 case 0: /* Matched PnP */
131 type = SNEC_TYPE_PNP;
132 break;
133
134 case ENOENT: /* Legacy ISA */
135 type = SNEC_TYPE_LEGACY;
136 break;
137
138 default: /* If we had some other problem. */
139 return(error);
140 }
141
142 if (type == SNEC_TYPE_PNP && isa_get_portsize(dev) == 0) {
143 int port;
144 int rid = 0;
145 struct resource *res = NULL;
146
147 for (port = 0x0888; port <= 0x3888; port += 0x1000) {
148 bus_set_resource(dev, SYS_RES_IOPORT, rid,
149 port, SNEC_NREGS);
150 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
151 0, ~0, SNEC_NREGS,
152 0 /* !RF_ACTIVE */);
153 if (res) break;
154 }
155
156 printf("snc_isa_probe: broken PnP resource, ");
157 if (res) {
158 printf("use port 0x%x\n", port);
159 bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
160 snc_isapnp_reconfig(dev);
161 } else {
162 printf("and can't find port\n");
163 }
164 }
165
166 error = snc_alloc_port(dev, 0);
167 error = max(error, snc_alloc_memory(dev, 0));
168 error = max(error, snc_alloc_irq(dev, 0, 0));
169
170 if (!error && !snc_probe(dev, type))
171 error = ENOENT;
172
173 snc_release_resources(dev);
174 return (error);
175}
176
177static int
178snc_isa_attach(dev)
179 device_t dev;
180{
181 struct snc_softc *sc = device_get_softc(dev);
182 int error;
183
184 bzero(sc, sizeof(struct snc_softc));
185
186 snc_alloc_port(dev, 0);
187 snc_alloc_memory(dev, 0);
188 snc_alloc_irq(dev, 0, 0);
189
190 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
191 sncintr, sc, &sc->irq_handle);
192 if (error) {
193 printf("snc_isa_attach: bus_setup_intr() failed\n");
194 snc_release_resources(dev);
195 return (error);
196 }
197
198 /* This interface is always enabled. */
199 sc->sc_enabled = 1;
200
201 return snc_attach(dev);
202}
203
204static device_method_t snc_isa_methods[] = {
205 /* Device interface */
206 DEVMETHOD(device_probe, snc_isa_probe),
207 DEVMETHOD(device_attach, snc_isa_attach),
208 DEVMETHOD(device_shutdown, snc_shutdown),
209
210 { 0, 0 }
211};
212
213static driver_t snc_isa_driver = {
214 "snc",
215 snc_isa_methods,
216 sizeof(struct snc_softc)
217};
218
219DRIVER_MODULE(snc, isa, snc_isa_driver, snc_devclass, 0, 0);
220MODULE_DEPEND(snc, isa, 1, 1, 1);
221MODULE_DEPEND(snc, ether, 1, 1, 1);
32/*
33 * National Semiconductor DP8393X SONIC Driver
34 *
35 * This is the C-bus specific attachment on FreeBSD
36 * written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp>
37 */
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/socket.h>
42#include <sys/kernel.h>
43
44#include <sys/module.h>
45#include <sys/bus.h>
46#include <machine/bus.h>
47#include <machine/resource.h>
48
49#include <net/if.h>
50#include <net/if_arp.h>
51#include <net/if_media.h>
52
53#include <isa/isavar.h>
54#include <sys/malloc.h> /* as dependency for isa/isa_common.h */
55#include <isa/isa_common.h> /* for snc_isapnp_reconfig() */
56
57#include <dev/snc/dp83932var.h>
58#include <dev/snc/if_sncreg.h>
59#include <dev/snc/if_sncvar.h>
60
61static void snc_isapnp_reconfig (device_t);
62static int snc_isa_probe (device_t);
63static int snc_isa_attach (device_t);
64
65static struct isa_pnp_id snc_ids[] = {
66 { 0x6180a3b8, NULL }, /* NEC8061 NEC PC-9801-104 */
67 { 0, NULL }
68};
69
70static void
71snc_isapnp_reconfig(dev)
72 device_t dev;
73{
74 struct isa_device *idev = DEVTOISA(dev);
75 struct isa_config config;
76 u_long start, count;
77 int rid;
78
79 bzero(&config, sizeof(config));
80
81 for (rid = 0; rid < ISA_NMEM; rid++) {
82 if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count))
83 break;
84 config.ic_mem[rid].ir_start = start;
85 config.ic_mem[rid].ir_end = start;
86 config.ic_mem[rid].ir_size = count;
87 }
88 config.ic_nmem = rid;
89 for (rid = 0; rid < ISA_NPORT; rid++) {
90 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count))
91 break;
92 config.ic_port[rid].ir_start = start;
93 config.ic_port[rid].ir_end = start;
94 config.ic_port[rid].ir_size = count;
95 }
96 config.ic_nport = rid;
97 for (rid = 0; rid < ISA_NIRQ; rid++) {
98 if (bus_get_resource(dev, SYS_RES_IRQ, rid, &start, &count))
99 break;
100 config.ic_irqmask[rid] = 1 << start;
101 }
102 config.ic_nirq = rid;
103 for (rid = 0; rid < ISA_NDRQ; rid++) {
104 if (bus_get_resource(dev, SYS_RES_DRQ, rid, &start, &count))
105 break;
106 config.ic_drqmask[rid] = 1 << start;
107 }
108 config.ic_ndrq = rid;
109
110 idev->id_config_cb(idev->id_config_arg, &config, 1);
111}
112
113static int
114snc_isa_probe(dev)
115 device_t dev;
116{
117 struct snc_softc *sc = device_get_softc(dev);
118 int type;
119 int error = 0;
120
121 bzero(sc, sizeof(struct snc_softc));
122
123 /* Check isapnp ids */
124 error = ISA_PNP_PROBE(device_get_parent(dev), dev, snc_ids);
125
126 /* If the card had a PnP ID that didn't match any we know about */
127 if (error == ENXIO) {
128 return(error);
129 }
130
131 switch (error) {
132 case 0: /* Matched PnP */
133 type = SNEC_TYPE_PNP;
134 break;
135
136 case ENOENT: /* Legacy ISA */
137 type = SNEC_TYPE_LEGACY;
138 break;
139
140 default: /* If we had some other problem. */
141 return(error);
142 }
143
144 if (type == SNEC_TYPE_PNP && isa_get_portsize(dev) == 0) {
145 int port;
146 int rid = 0;
147 struct resource *res = NULL;
148
149 for (port = 0x0888; port <= 0x3888; port += 0x1000) {
150 bus_set_resource(dev, SYS_RES_IOPORT, rid,
151 port, SNEC_NREGS);
152 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
153 0, ~0, SNEC_NREGS,
154 0 /* !RF_ACTIVE */);
155 if (res) break;
156 }
157
158 printf("snc_isa_probe: broken PnP resource, ");
159 if (res) {
160 printf("use port 0x%x\n", port);
161 bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
162 snc_isapnp_reconfig(dev);
163 } else {
164 printf("and can't find port\n");
165 }
166 }
167
168 error = snc_alloc_port(dev, 0);
169 error = max(error, snc_alloc_memory(dev, 0));
170 error = max(error, snc_alloc_irq(dev, 0, 0));
171
172 if (!error && !snc_probe(dev, type))
173 error = ENOENT;
174
175 snc_release_resources(dev);
176 return (error);
177}
178
179static int
180snc_isa_attach(dev)
181 device_t dev;
182{
183 struct snc_softc *sc = device_get_softc(dev);
184 int error;
185
186 bzero(sc, sizeof(struct snc_softc));
187
188 snc_alloc_port(dev, 0);
189 snc_alloc_memory(dev, 0);
190 snc_alloc_irq(dev, 0, 0);
191
192 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
193 sncintr, sc, &sc->irq_handle);
194 if (error) {
195 printf("snc_isa_attach: bus_setup_intr() failed\n");
196 snc_release_resources(dev);
197 return (error);
198 }
199
200 /* This interface is always enabled. */
201 sc->sc_enabled = 1;
202
203 return snc_attach(dev);
204}
205
206static device_method_t snc_isa_methods[] = {
207 /* Device interface */
208 DEVMETHOD(device_probe, snc_isa_probe),
209 DEVMETHOD(device_attach, snc_isa_attach),
210 DEVMETHOD(device_shutdown, snc_shutdown),
211
212 { 0, 0 }
213};
214
215static driver_t snc_isa_driver = {
216 "snc",
217 snc_isa_methods,
218 sizeof(struct snc_softc)
219};
220
221DRIVER_MODULE(snc, isa, snc_isa_driver, snc_devclass, 0, 0);
222MODULE_DEPEND(snc, isa, 1, 1, 1);
223MODULE_DEPEND(snc, ether, 1, 1, 1);