2 * Copyright (c) 1994-2000
3 * Paul Richards. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
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.
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
30 * $FreeBSD: src/sys/dev/lnc/if_lnc_isa.c,v 1.12 2001/07/04 13:00:19 nyan Exp $
31 * $DragonFly: src/sys/dev/netif/lnc/if_lnc_isa.c,v 1.2 2004/03/14 15:36:50 joerg Exp $
34 #include <sys/param.h>
35 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/malloc.h>
39 #include <sys/socket.h>
41 #include <machine/bus.h>
42 #include <machine/resource.h>
45 #include <net/ethernet.h>
47 #include <net/if_arp.h>
49 #include <bus/isa/isavar.h>
51 #include <dev/netif/lnc/if_lncvar.h>
52 #include <dev/netif/lnc/if_lncreg.h>
54 static struct isa_pnp_id lnc_pnp_ids[] = {
59 lnc_legacy_probe(device_t dev)
61 struct lnc_softc *sc = device_get_softc(dev);
64 sc->portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->portrid,
68 device_printf(dev, "Failed to allocate I/O ports\n");
69 lnc_release_resources(dev);
73 sc->lnc_btag = rman_get_bustag(sc->portres);
74 sc->lnc_bhandle = rman_get_bushandle(sc->portres);
77 * There isn't any way to determine if a NIC is a BICC. Basically, if
78 * the lance probe succeeds using the i/o addresses of the BICC then
79 * we assume it's a BICC.
84 sc->nic.mem_mode = DMA_FIXED;
85 /* XXX Should set BICC_IOSIZE et al somewhere to alloc
86 resources correctly */
88 if ((sc->nic.ic = lance_probe(sc))) {
89 device_set_desc(dev, "BICC Isolan");
91 lnc_release_resources(dev);
94 /* It's not a BICC so try the standard NE2100 ports */
97 if ((sc->nic.ic = lance_probe(sc))) {
98 sc->nic.ident = NE2100;
99 device_set_desc(dev, "NE2100");
100 lnc_release_resources(dev);
103 lnc_release_resources(dev);
110 lnc_isa_probe(device_t dev)
114 pnp = ISA_PNP_PROBE(device_get_parent(dev), dev, lnc_pnp_ids);
116 /* It's not a PNP card, see if we support it by probing it */
117 return (lnc_legacy_probe(dev));
118 } else if (pnp == ENXIO) {
121 /* Found PNP card we support */
127 lnc_alloc_callback(void *arg, bus_dma_segment_t *seg, int nseg, int error)
134 lnc_isa_attach(device_t dev)
136 lnc_softc_t *sc = device_get_softc(dev);
138 bus_size_t lnc_mem_size;
140 device_printf(dev, "Attaching %s\n", device_get_desc(dev));
143 sc->portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->portrid,
144 0, ~0, 1, RF_ACTIVE);
147 device_printf(dev, "Failed to allocate I/O ports\n");
148 lnc_release_resources(dev);
153 sc->drqres = bus_alloc_resource(dev, SYS_RES_DRQ, &sc->drqrid,
154 0, ~0, 1, RF_ACTIVE);
157 device_printf(dev, "Failed to allocate DMA channel\n");
158 lnc_release_resources(dev);
162 if (isa_get_irq(dev) == -1)
163 bus_set_resource(dev, SYS_RES_IRQ, 0, 10, 1);
166 sc->irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irqrid, 0, ~0, 1,
170 device_printf(dev, "Failed to allocate irq\n");
171 lnc_release_resources(dev);
175 err = bus_setup_intr(dev, sc->irqres, INTR_TYPE_NET, lncintr,
179 device_printf(dev, "Failed to setup irq handler\n");
180 lnc_release_resources(dev);
184 /* XXX temp setting for nic */
185 sc->nic.mem_mode = DMA_FIXED;
189 if (sc->nic.ident == NE2100) {
198 /* Create a DMA tag describing the ring memory we need */
200 lnc_mem_size = ((NDESC(sc->nrdre) + NDESC(sc->ntdre)) *
201 sizeof(struct host_ring_entry));
203 lnc_mem_size += (NDESC(sc->nrdre) * RECVBUFSIZE) +
204 (NDESC(sc->ntdre) * TRANSBUFSIZE);
206 err = bus_dma_tag_create(NULL, /* parent */
209 BUS_SPACE_MAXADDR_24BIT, /* lowaddr */
210 BUS_SPACE_MAXADDR, /* highaddr */
211 NULL, NULL, /* filter, filterarg */
212 lnc_mem_size, /* segsize */
214 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
219 device_printf(dev, "Can't create DMA tag\n");
220 lnc_release_resources(dev);
224 err = bus_dmamem_alloc(sc->dmat, (void **)&sc->recv_ring,
225 BUS_DMA_NOWAIT, &sc->dmamap);
228 device_printf(dev, "Couldn't allocate memory\n");
229 lnc_release_resources(dev);
233 err = bus_dmamap_load(sc->dmat, sc->dmamap, sc->recv_ring, lnc_mem_size,
234 lnc_alloc_callback, sc->recv_ring, BUS_DMA_NOWAIT);
237 device_printf(dev, "Couldn't load DMA map\n");
238 lnc_release_resources(dev);
242 isa_dmacascade(rman_get_start(sc->drqres));
244 /* Call generic attach code */
245 if (! lnc_attach_common(dev)) {
246 device_printf(dev, "Generic attach code failed\n");
247 lnc_release_resources(dev);
254 lnc_isa_detach(device_t dev)
256 lnc_softc_t *sc = device_get_softc(dev);
259 ether_ifdetach(&sc->arpcom.ac_if);
263 lnc_release_resources(dev);
268 static device_method_t lnc_isa_methods[] = {
269 /* DEVMETHOD(device_identify, lnc_isa_identify), */
270 DEVMETHOD(device_probe, lnc_isa_probe),
271 DEVMETHOD(device_attach, lnc_isa_attach),
272 DEVMETHOD(device_detach, lnc_isa_detach),
274 DEVMETHOD(device_suspend, lnc_isa_suspend),
275 DEVMETHOD(device_resume, lnc_isa_resume),
276 DEVMETHOD(device_shutdown, lnc_isa_shutdown),
281 static driver_t lnc_isa_driver = {
284 sizeof(struct lnc_softc),
287 DRIVER_MODULE(if_lnc, isa, lnc_isa_driver, lnc_devclass, 0, 0);