2 * Copyright (c) 1994-2000
3 * Paul Richards. All rights reserved.
5 * PC-98 port by Chiharu Shibata & FreeBSD(98) porting team.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * verbatim and that no modifications are made prior to this
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name Paul Richards may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY PAUL RICHARDS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL PAUL RICHARDS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/socket.h>
42 #include <machine/clock.h> /* DELAY() */
43 #include <machine/bus.h>
44 #include <machine/resource.h>
47 #include <net/ethernet.h>
49 #include <net/if_arp.h>
51 #include <isa/isavar.h>
53 #include <dev/lnc/if_lncvar.h>
54 #include <dev/lnc/if_lncreg.h>
56 static struct isa_pnp_id lnc_pnp_ids[] = {
60 static bus_addr_t lnc_ioaddr_cnet98s[CNET98S_IOSIZE] = {
61 0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007,
62 0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f,
63 0x400, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407,
64 0x408, 0x409, 0x40a, 0x40b, 0x40c, 0x40d, 0x40e, 0x40f,
68 lnc_legacy_probe(device_t dev)
70 struct lnc_softc *sc = device_get_softc(dev);
74 sc->portres = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &sc->portrid,
75 lnc_ioaddr_cnet98s, CNET98S_IOSIZE,
79 device_printf(dev, "Failed to allocate I/O ports\n");
80 lnc_release_resources(dev);
84 isa_load_resourcev(sc->portres, lnc_ioaddr_cnet98s, CNET98S_IOSIZE);
86 sc->lnc_btag = rman_get_bustag(sc->portres);
87 sc->lnc_bhandle = rman_get_bushandle(sc->portres);
90 tmp = lnc_inw(CNET98S_RESET);
91 lnc_outw(CNET98S_RESET, tmp);
94 sc->rap = CNET98S_RAP;
95 sc->rdp = CNET98S_RDP;
96 sc->nic.mem_mode = DMA_FIXED;
98 if ((sc->nic.ic = lance_probe(sc))) {
99 sc->nic.ident = CNET98S;
100 device_set_desc(dev, "C-NET(98)S");
101 lnc_release_resources(dev);
104 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 = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &sc->portrid,
144 lnc_ioaddr_cnet98s, CNET98S_IOSIZE,
148 device_printf(dev, "Failed to allocate I/O ports\n");
149 lnc_release_resources(dev);
153 isa_load_resourcev(sc->portres, lnc_ioaddr_cnet98s, CNET98S_IOSIZE);
155 sc->lnc_btag = rman_get_bustag(sc->portres);
156 sc->lnc_bhandle = rman_get_bushandle(sc->portres);
161 if (isa_get_irq(dev) == -1)
162 bus_set_resource(dev, SYS_RES_IRQ, 0, 6, 1);
165 sc->irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irqrid, 0, ~0, 1,
169 device_printf(dev, "Failed to allocate irq\n");
170 lnc_release_resources(dev);
174 err = bus_setup_intr(dev, sc->irqres, INTR_TYPE_NET, lncintr,
178 device_printf(dev, "Failed to setup irq handler\n");
179 lnc_release_resources(dev);
183 /* XXX temp setting for nic */
184 sc->nic.mem_mode = DMA_FIXED;
188 if (sc->nic.ident == CNET98S) {
189 sc->rap = CNET98S_RAP;
190 sc->rdp = CNET98S_RDP;
191 } else if (sc->nic.ident == NE2100) {
200 /* Create a DMA tag describing the ring memory we need */
202 lnc_mem_size = ((NDESC(sc->nrdre) + NDESC(sc->ntdre)) *
203 sizeof(struct host_ring_entry));
205 lnc_mem_size += (NDESC(sc->nrdre) * RECVBUFSIZE) +
206 (NDESC(sc->ntdre) * TRANSBUFSIZE);
208 err = bus_dma_tag_create(NULL, /* parent */
211 BUS_SPACE_MAXADDR_24BIT, /* lowaddr */
212 BUS_SPACE_MAXADDR, /* highaddr */
213 NULL, NULL, /* filter, filterarg */
214 lnc_mem_size, /* segsize */
216 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
221 device_printf(dev, "Can't create DMA tag\n");
222 lnc_release_resources(dev);
226 err = bus_dmamem_alloc(sc->dmat, (void **)&sc->recv_ring,
227 BUS_DMA_NOWAIT, &sc->dmamap);
230 device_printf(dev, "Couldn't allocate memory\n");
231 lnc_release_resources(dev);
235 err = bus_dmamap_load(sc->dmat, sc->dmamap, sc->recv_ring, lnc_mem_size,
236 lnc_alloc_callback, sc->recv_ring, BUS_DMA_NOWAIT);
239 device_printf(dev, "Couldn't load DMA map\n");
240 lnc_release_resources(dev);
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 * XXX - Following parameters are Contec C-NET(98)S only.
255 * So, check the Ethernet address here.
257 * Contec uses 00 80 4c ?? ?? ??
259 if (sc->arpcom.ac_enaddr[0] == (u_char)0x00 &&
260 sc->arpcom.ac_enaddr[1] == (u_char)0x80 &&
261 sc->arpcom.ac_enaddr[2] == (u_char)0x4c) {
262 lnc_outw(sc->rap, MSRDA);
263 lnc_outw(CNET98S_IDP, 0x0006);
264 lnc_outw(sc->rap, MSWRA);
265 lnc_outw(CNET98S_IDP, 0x0006);
267 lnc_outw(sc->rap, MC);
268 printf("ISACSR2 = %x\n", lnc_inw(CNET98S_IDP));
270 lnc_outw(sc->rap, LED1);
271 lnc_outw(CNET98S_IDP, LED_PSE | LED_XMTE);
272 lnc_outw(sc->rap, LED2);
273 lnc_outw(CNET98S_IDP, LED_PSE | LED_RCVE);
274 lnc_outw(sc->rap, LED3);
275 lnc_outw(CNET98S_IDP, LED_PSE | LED_COLE);
282 lnc_isa_detach(device_t dev)
284 lnc_softc_t *sc = device_get_softc(dev);
287 ether_ifdetach(&sc->arpcom.ac_if, ETHER_BPF_SUPPORTED);
291 lnc_release_resources(dev);
296 static device_method_t lnc_isa_methods[] = {
297 /* DEVMETHOD(device_identify, lnc_isa_identify), */
298 DEVMETHOD(device_probe, lnc_isa_probe),
299 DEVMETHOD(device_attach, lnc_isa_attach),
300 DEVMETHOD(device_detach, lnc_isa_detach),
302 DEVMETHOD(device_suspend, lnc_isa_suspend),
303 DEVMETHOD(device_resume, lnc_isa_resume),
304 DEVMETHOD(device_shutdown, lnc_isa_shutdown),
309 static driver_t lnc_isa_driver = {
312 sizeof(struct lnc_softc),
315 DRIVER_MODULE(if_lnc, isa, lnc_isa_driver, lnc_devclass, 0, 0);