1 /*-
2 * Copyright (c) 1994-2000
3 * Paul Richards. 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, this list of conditions and the following disclaimer,
10 * verbatim and that no modifications are made prior to this
11 * point in the file.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name Paul Richards may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY PAUL RICHARDS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL PAUL RICHARDS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 */
31
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/bus.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/module.h>
41 #include <sys/socket.h>
42
43 #include <machine/bus.h>
44 #include <machine/resource.h>
45 #include <sys/rman.h>
46
47 #include <net/ethernet.h>
48 #include <net/if.h>
49 #include <net/if_arp.h>
50
51 #include <isa/isavar.h>
52
53 #include <dev/lnc/if_lncvar.h>
54 #include <dev/lnc/if_lncreg.h>
55
56 static struct isa_pnp_id lnc_pnp_ids[] = {
57 {0, NULL}
58 };
59
60 static int
61 lnc_legacy_probe(device_t dev)
62 {
63 struct lnc_softc *sc = device_get_softc(dev);
64
65 sc->portrid = 0;
66 sc->portres = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->portrid,
67 RF_ACTIVE);
68
69 if (! sc->portres) {
70 device_printf(dev, "Failed to allocate I/O ports\n");
71 lnc_release_resources(dev);
72 return (ENXIO);
73 }
74
75 sc->lnc_btag = rman_get_bustag(sc->portres);
76 sc->lnc_bhandle = rman_get_bushandle(sc->portres);
77
78 /*
79 * There isn't any way to determine if a NIC is a BICC. Basically, if
80 * the lance probe succeeds using the i/o addresses of the BICC then
81 * we assume it's a BICC.
82 *
83 */
84 sc->rap = BICC_RAP;
85 sc->rdp = BICC_RDP;
86 sc->nic.mem_mode = DMA_FIXED;
87 /* XXX Should set BICC_IOSIZE et al somewhere to alloc
88 resources correctly */
89
90 if ((sc->nic.ic = lance_probe(sc))) {
91 device_set_desc(dev, "BICC Isolan");
92 sc->nic.ident = BICC;
93 lnc_release_resources(dev);
94 return (0);
95 } else {
96 /* It's not a BICC so try the standard NE2100 ports */
97 sc->rap = PCNET_RAP;
98 sc->rdp = PCNET_RDP;
99 if ((sc->nic.ic = lance_probe(sc))) {
100 sc->nic.ident = NE2100;
101 device_set_desc(dev, "NE2100");
102 lnc_release_resources(dev);
103 return (0);
104 } else {
105 lnc_release_resources(dev);
106 return (ENXIO);
107 }
108 }
109 }
110
111 static int
112 lnc_isa_probe(device_t dev)
113 {
114 int pnp;
115
116 pnp = ISA_PNP_PROBE(device_get_parent(dev), dev, lnc_pnp_ids);
117 if (pnp == ENOENT) {
118 /* It's not a PNP card, see if we support it by probing it */
119 return (lnc_legacy_probe(dev));
120 } else if (pnp == ENXIO) {
121 return (ENXIO);
122 } else {
123 /* Found PNP card we support */
124 return (0);
125 }
126 }
127
128 static void
129 lnc_alloc_callback(void *arg, bus_dma_segment_t *seg, int nseg, int error)
130 {
131 /* Do nothing */
132 return;
133 }
134
135 static int
136 lnc_isa_attach(device_t dev)
137 {
138 lnc_softc_t *sc = device_get_softc(dev);
139 int err = 0;
140 bus_size_t lnc_mem_size;
141
142 device_printf(dev, "Attaching %s\n", device_get_desc(dev));
143
144 sc->portrid = 0;
145 sc->portres = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->portrid,
146 RF_ACTIVE);
147
148 if (! sc->portres) {
149 device_printf(dev, "Failed to allocate I/O ports\n");
150 lnc_release_resources(dev);
151 return (ENXIO);
152 }
153
154 sc->drqrid = 0;
155 sc->drqres = bus_alloc_resource_any(dev, SYS_RES_DRQ, &sc->drqrid,
156 RF_ACTIVE);
157
158 if (! sc->drqres) {
159 device_printf(dev, "Failed to allocate DMA channel\n");
160 lnc_release_resources(dev);
161 return (ENXIO);
162 }
163
164 if (isa_get_irq(dev) == -1)
165 bus_set_resource(dev, SYS_RES_IRQ, 0, 10, 1);
166
167 sc->irqrid = 0;
168 sc->irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irqrid,
169 RF_ACTIVE);
170
171 if (! sc->irqres) {
172 device_printf(dev, "Failed to allocate irq\n");
173 lnc_release_resources(dev);
174 return (ENXIO);
175 }
176
177 err = bus_setup_intr(dev, sc->irqres, INTR_TYPE_NET, lncintr,
178 sc, &sc->intrhand);
179
180 if (err) {
181 device_printf(dev, "Failed to setup irq handler\n");
182 lnc_release_resources(dev);
183 return (err);
184 }
185
186 /* XXX temp setting for nic */
187 sc->nic.mem_mode = DMA_FIXED;
188 sc->nrdre = NRDRE;
189 sc->ntdre = NTDRE;
190
191 if (sc->nic.ident == NE2100) {
192 sc->rap = PCNET_RAP;
193 sc->rdp = PCNET_RDP;
194 sc->bdp = PCNET_BDP;
195 } else {
196 sc->rap = BICC_RAP;
197 sc->rdp = BICC_RDP;
198 }
199
200 /* Create a DMA tag describing the ring memory we need */
201
202 lnc_mem_size = ((NDESC(sc->nrdre) + NDESC(sc->ntdre)) *
203 sizeof(struct host_ring_entry));
204
205 lnc_mem_size += (NDESC(sc->nrdre) * RECVBUFSIZE) +
206 (NDESC(sc->ntdre) * TRANSBUFSIZE);
207
208 err = bus_dma_tag_create(NULL, /* parent */
209 4, /* alignement */
210 0, /* boundary */
211 BUS_SPACE_MAXADDR_24BIT, /* lowaddr */
212 BUS_SPACE_MAXADDR, /* highaddr */
213 NULL, NULL, /* filter, filterarg */
214 lnc_mem_size, /* segsize */
215 1, /* nsegments */
216 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
217 0, /* flags */
218 busdma_lock_mutex, /* lockfunc */
219 &Giant, /* lockarg */
220 &sc->dmat);
221
222 if (err) {
223 device_printf(dev, "Can't create DMA tag\n");
224 lnc_release_resources(dev);
225 return (ENOMEM);
226 }
227
228 err = bus_dmamem_alloc(sc->dmat, (void **)&sc->recv_ring,
229 BUS_DMA_NOWAIT, &sc->dmamap);
230
231 if (err) {
232 device_printf(dev, "Couldn't allocate memory\n");
233 lnc_release_resources(dev);
234 return (ENOMEM);
235 }
236
237 err = bus_dmamap_load(sc->dmat, sc->dmamap, sc->recv_ring, lnc_mem_size,
238 lnc_alloc_callback, sc->recv_ring, BUS_DMA_NOWAIT);
239
240 if (err) {
241 device_printf(dev, "Couldn't load DMA map\n");
242 lnc_release_resources(dev);
243 return (ENOMEM);
244 }
245
246 isa_dmacascade(rman_get_start(sc->drqres));
247
248 /* Call generic attach code */
249 if (! lnc_attach_common(dev)) {
250 device_printf(dev, "Generic attach code failed\n");
251 lnc_release_resources(dev);
252 return (ENXIO);
253 }
254 return (0);
255 }
256
257 static int
258 lnc_isa_detach(device_t dev)
259 {
260 lnc_softc_t *sc = device_get_softc(dev);
261 int s = splimp();
262
263 ether_ifdetach(&sc->arpcom.ac_if);
264 splx(s);
265
266 lnc_stop(sc);
267 lnc_release_resources(dev);
268
269 return (0);
270 }
271
272 static device_method_t lnc_isa_methods[] = {
273 /* DEVMETHOD(device_identify, lnc_isa_identify), */
274 DEVMETHOD(device_probe, lnc_isa_probe),
275 DEVMETHOD(device_attach, lnc_isa_attach),
276 DEVMETHOD(device_detach, lnc_isa_detach),
277 #ifdef notyet
278 DEVMETHOD(device_suspend, lnc_isa_suspend),
279 DEVMETHOD(device_resume, lnc_isa_resume),
280 DEVMETHOD(device_shutdown, lnc_isa_shutdown),
281 #endif
282 { 0, 0 }
283 };
284
285 static driver_t lnc_isa_driver = {
286 "lnc",
287 lnc_isa_methods,
288 sizeof(struct lnc_softc),
289 };
290
291 DRIVER_MODULE(lnc, isa, lnc_isa_driver, lnc_devclass, 0, 0);
292 MODULE_DEPEND(lnc, isa, 1, 1, 1);
293 MODULE_DEPEND(lnc, ether, 1, 1, 1);
Cache object: c4df5cff81153cd1dfd6508593ae3be8
|