2 * Copyright (c) 1995, David Greenman
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 unmodified, this list of conditions, and the following
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.
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
27 * $FreeBSD: src/sys/dev/snc/if_snc_cbus.c,v 1.1.2.1 2000/10/21 03:30:03 nyan Exp $
28 * $DragonFly: src/sys/dev/netif/snc/Attic/if_snc_cbus.c,v 1.3 2003/08/07 21:17:05 dillon Exp $
32 * National Semiconductor DP8393X SONIC Driver
34 * This is the C-bus specific attachment on FreeBSD
35 * written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp>
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/socket.h>
41 #include <sys/kernel.h>
43 #include <sys/module.h>
45 #include <machine/bus.h>
47 #include <machine/resource.h>
49 #include <net/ethernet.h>
51 #include <net/if_arp.h>
52 #include <net/if_media.h>
53 #include <net/if_mib.h>
55 #include <bus/isa/isavar.h>
56 #include <bus/isa/pnpvar.h>
57 #include <sys/malloc.h> /* as dependency for isa/isa_common.h */
58 #include <bus/isa/isa_common.h> /* for snc_isapnp_reconfig() */
60 #include "dp83932var.h"
61 #include "dp83932subr.h"
62 #include "if_sncreg.h"
63 #include "if_sncvar.h"
65 static void snc_isapnp_reconfig __P((device_t));
66 static int snc_isa_probe __P((device_t));
67 static int snc_isa_attach __P((device_t));
69 static struct isa_pnp_id snc_ids[] = {
70 { 0x6180a3b8, NULL }, /* NEC8061 NEC PC-9801-104 */
75 snc_isapnp_reconfig(dev)
78 struct isa_device *idev = DEVTOISA(dev);
79 struct isa_config config;
83 bzero(&config, sizeof(config));
85 for (rid = 0; rid < ISA_NMEM; rid++) {
86 if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count))
88 config.ic_mem[rid].ir_start = start;
89 config.ic_mem[rid].ir_end = start;
90 config.ic_mem[rid].ir_size = count;
93 for (rid = 0; rid < ISA_NPORT; rid++) {
94 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count))
96 config.ic_port[rid].ir_start = start;
97 config.ic_port[rid].ir_end = start;
98 config.ic_port[rid].ir_size = count;
100 config.ic_nport = rid;
101 for (rid = 0; rid < ISA_NIRQ; rid++) {
102 if (bus_get_resource(dev, SYS_RES_IRQ, rid, &start, &count))
104 config.ic_irqmask[rid] = 1 << start;
106 config.ic_nirq = rid;
107 for (rid = 0; rid < ISA_NDRQ; rid++) {
108 if (bus_get_resource(dev, SYS_RES_DRQ, rid, &start, &count))
110 config.ic_drqmask[rid] = 1 << start;
112 config.ic_ndrq = rid;
114 idev->id_config_cb(idev->id_config_arg, &config, 1);
121 struct snc_softc *sc = device_get_softc(dev);
125 bzero(sc, sizeof(struct snc_softc));
127 /* Check isapnp ids */
128 error = ISA_PNP_PROBE(device_get_parent(dev), dev, snc_ids);
130 /* If the card had a PnP ID that didn't match any we know about */
131 if (error == ENXIO) {
136 case 0: /* Matched PnP */
137 type = SNEC_TYPE_PNP;
140 case ENOENT: /* Legacy ISA */
141 type = SNEC_TYPE_LEGACY;
144 default: /* If we had some other problem. */
148 if (type == SNEC_TYPE_PNP && isa_get_portsize(dev) == 0) {
151 struct resource *res = NULL;
153 for (port = 0x0888; port <= 0x3888; port += 0x1000) {
154 bus_set_resource(dev, SYS_RES_IOPORT, rid,
156 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
162 printf("snc_isa_probe: broken PnP resource, ");
164 printf("use port 0x%x\n", port);
165 bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
166 snc_isapnp_reconfig(dev);
168 printf("and can't find port\n");
172 error = snc_alloc_port(dev, 0);
173 error = max(error, snc_alloc_memory(dev, 0));
174 error = max(error, snc_alloc_irq(dev, 0, 0));
176 if (!error && !snc_probe(dev, type))
179 snc_release_resources(dev);
187 struct snc_softc *sc = device_get_softc(dev);
190 bzero(sc, sizeof(struct snc_softc));
192 snc_alloc_port(dev, 0);
193 snc_alloc_memory(dev, 0);
194 snc_alloc_irq(dev, 0, 0);
196 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
197 sncintr, sc, &sc->irq_handle);
199 printf("snc_isa_attach: bus_setup_intr() failed\n");
200 snc_release_resources(dev);
204 /* This interface is always enabled. */
207 return snc_attach(dev);
210 static device_method_t snc_isa_methods[] = {
211 /* Device interface */
212 DEVMETHOD(device_probe, snc_isa_probe),
213 DEVMETHOD(device_attach, snc_isa_attach),
214 DEVMETHOD(device_shutdown, snc_shutdown),
219 static driver_t snc_isa_driver = {
222 sizeof(struct snc_softc)
225 DRIVER_MODULE(if_snc, isa, snc_isa_driver, snc_devclass, 0, 0);