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
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
33 * National Semiconductor DP8393X SONIC Driver
35 * This is the bus independent attachment on FreeBSD 4.x
36 * written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp>
39 #include <sys/param.h>
40 #include <sys/socket.h>
43 #include <machine/bus.h>
45 #include <machine/resource.h>
47 #include <net/ethernet.h>
49 #include <net/if_arp.h>
50 #include <net/if_media.h>
51 #include <net/if_var.h>
53 #include <dev/snc/dp83932reg.h>
54 #include <dev/snc/dp83932var.h>
55 #include <dev/snc/dp83932subr.h>
56 #include <dev/snc/if_sncreg.h>
57 #include <dev/snc/if_sncvar.h>
59 /* devclass for "snc" */
60 devclass_t snc_devclass;
62 /****************************************************************
63 Resource management functions
64 ****************************************************************/
67 * Allocate a port resource with the given resource id.
70 snc_alloc_port(device_t dev, int rid)
72 struct snc_softc *sc = device_get_softc(dev);
75 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
76 0ul, ~0ul, SNEC_NREGS, RF_ACTIVE);
80 sc->sc_iot = rman_get_bustag(res);
81 sc->sc_ioh = rman_get_bushandle(res);
84 device_printf(dev, "can't assign port\n");
90 * Allocate a memory resource with the given resource id.
93 snc_alloc_memory(device_t dev, int rid)
95 struct snc_softc *sc = device_get_softc(dev);
98 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
99 0ul, ~0ul, SNEC_NMEMS, RF_ACTIVE);
103 sc->sc_memt = rman_get_bustag(res);
104 sc->sc_memh = rman_get_bushandle(res);
107 device_printf(dev, "can't assign memory\n");
113 * Allocate an irq resource with the given resource id.
116 snc_alloc_irq(device_t dev, int rid, int flags)
118 struct snc_softc *sc = device_get_softc(dev);
119 struct resource *res;
121 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE | flags);
127 device_printf(dev, "can't assign irq\n");
133 * Release all resources
136 snc_release_resources(device_t dev)
138 struct snc_softc *sc = device_get_softc(dev);
141 bus_release_resource(dev, SYS_RES_IOPORT,
142 sc->ioport_rid, sc->ioport);
146 bus_release_resource(dev, SYS_RES_MEMORY,
147 sc->iomem_rid, sc->iomem);
151 bus_release_resource(dev, SYS_RES_IRQ,
152 sc->irq_rid, sc->irq);
161 /****************************************************************
163 ****************************************************************/
166 snc_probe(device_t dev, int type)
168 struct snc_softc *sc = device_get_softc(dev);
170 return snc_nec16_detectsubr(sc->sc_iot, sc->sc_ioh,
171 sc->sc_memt, sc->sc_memh,
172 rman_get_start(sc->irq),
173 rman_get_start(sc->iomem),
177 /****************************************************************
179 ****************************************************************/
182 snc_attach(device_t dev)
184 struct snc_softc *sc = device_get_softc(dev);
185 u_int8_t myea[ETHER_ADDR_LEN];
188 if (snc_nec16_register_irq(sc, rman_get_start(sc->irq)) == 0 ||
189 snc_nec16_register_mem(sc, rman_get_start(sc->iomem)) == 0) {
190 snc_release_resources(dev);
194 snc_nec16_get_enaddr(sc->sc_iot, sc->sc_ioh, myea);
195 device_printf(dev, "%s Ethernet\n", snc_nec16_detect_type(myea));
199 sc->sncr_dcr = DCR_SYNC | DCR_WAIT0 |
200 DCR_DMABLOCK | DCR_RFT16 | DCR_TFT28;
201 sc->sncr_dcr2 = 0; /* XXX */
202 sc->bitmode = 0; /* 16 bit card */
204 sc->sc_nic_put = snc_nec16_nic_put;
205 sc->sc_nic_get = snc_nec16_nic_get;
206 sc->sc_writetodesc = snc_nec16_writetodesc;
207 sc->sc_readfromdesc = snc_nec16_readfromdesc;
208 sc->sc_copytobuf = snc_nec16_copytobuf;
209 sc->sc_copyfrombuf = snc_nec16_copyfrombuf;
210 sc->sc_zerobuf = snc_nec16_zerobuf;
212 /* sncsetup returns 1 if something fails */
213 if (sncsetup(sc, myea)) {
214 snc_release_resources(dev);
218 mtx_init(&sc->sc_lock, device_get_nameunit(dev), MTX_NETWORK_LOCK,
220 callout_init_mtx(&sc->sc_timer, &sc->sc_lock, 0);
221 error = sncconfig(sc, NULL, 0, 0, myea);
223 snc_release_resources(dev);
224 mtx_destroy(&sc->sc_lock);
228 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE,
229 NULL, sncintr, sc, &sc->irq_handle);
231 printf("snc_isa_attach: bus_setup_intr() failed\n");
232 ether_ifdetach(sc->sc_ifp);
233 snc_release_resources(dev);
234 mtx_destroy(&sc->sc_lock);
241 /****************************************************************
243 ****************************************************************/
246 snc_shutdown(device_t dev)
248 struct snc_softc *sc = device_get_softc(dev);