]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/cm/if_cm_isa.c
Mechanically convert to if_inc_counter().
[FreeBSD/FreeBSD.git] / sys / dev / cm / if_cm_isa.c
1 /*      $NetBSD: if_bah_zbus.c,v 1.6 2000/01/23 21:06:12 aymeric Exp $ */
2
3 #include <sys/cdefs.h>
4 __FBSDID("$FreeBSD$");
5
6 /*-
7  * Copyright (c) 1994, 1995, 1998 The NetBSD Foundation, Inc.
8  * All rights reserved.
9  *
10  * This code is derived from software contributed to The NetBSD Foundation
11  * by Ignatios Souvatzis.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/socket.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40
41 #include <sys/module.h>
42 #include <sys/bus.h>
43
44 #include <machine/bus.h>
45 #include <sys/rman.h>
46 #include <machine/resource.h>
47
48 #include <net/if.h>
49 #include <net/if_var.h>
50 #include <net/if_arc.h>
51
52 #include <dev/cm/smc90cx6reg.h>
53 #include <dev/cm/smc90cx6var.h>
54
55 static int cm_isa_probe         (device_t);
56 static int cm_isa_attach        (device_t);
57
58 static int
59 cm_isa_probe(dev)
60         device_t dev;
61 {
62         struct cm_softc *sc = device_get_softc(dev);
63         int rid;
64
65         rid = 0;
66         sc->port_res = bus_alloc_resource(
67             dev, SYS_RES_IOPORT, &rid, 0ul, ~0ul, CM_IO_PORTS, RF_ACTIVE);
68         if (sc->port_res == NULL)
69                 return (ENOENT);
70
71         if (GETREG(CMSTAT) == 0xff) {
72                 cm_release_resources(dev);
73                 return (ENXIO);
74         }
75
76         rid = 0;
77         sc->mem_res = bus_alloc_resource(
78             dev, SYS_RES_MEMORY, &rid, 0ul, ~0ul, CM_MEM_SIZE, RF_ACTIVE);
79         if (sc->mem_res == NULL) {
80                 cm_release_resources(dev);
81                 return (ENOENT);
82         }
83
84         rid = 0;
85         sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
86         if (sc->irq_res == NULL) {
87                 cm_release_resources(dev);
88                 return (ENOENT);
89         }
90
91         return (0);
92 }
93
94 static int
95 cm_isa_attach(dev)
96         device_t dev;
97 {
98         struct cm_softc *sc = device_get_softc(dev);
99         int error;
100
101         /* init mtx and setup interrupt */
102         mtx_init(&sc->sc_mtx, device_get_nameunit(dev),
103             MTX_NETWORK_LOCK, MTX_DEF);
104         error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
105             NULL, cmintr, sc, &sc->irq_handle);
106         if (error)
107                 goto err;
108
109         /* attach */
110         error = cm_attach(dev);
111         if (error)
112                 goto err;
113
114         return 0;
115
116 err:
117         mtx_destroy(&sc->sc_mtx);
118         cm_release_resources(dev);
119         return (error);
120 }
121
122 static int
123 cm_isa_detach(device_t dev)
124 {
125         struct cm_softc *sc = device_get_softc(dev);
126         struct ifnet *ifp = sc->sc_ifp;
127
128         /* stop and detach */
129         CM_LOCK(sc);
130         cm_stop_locked(sc);
131         ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
132         CM_UNLOCK(sc);
133
134         callout_drain(&sc->sc_recon_ch);
135         arc_ifdetach(ifp);
136
137         /* teardown interrupt, destroy mtx and release resources */
138         bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
139         mtx_destroy(&sc->sc_mtx);
140         if_free(ifp);
141         cm_release_resources(dev);
142
143         bus_generic_detach(dev);
144         return (0);
145 }
146
147 static device_method_t cm_isa_methods[] = {
148         /* Device interface */
149         DEVMETHOD(device_probe,         cm_isa_probe),
150         DEVMETHOD(device_attach,        cm_isa_attach),
151         DEVMETHOD(device_detach,        cm_isa_detach),
152
153         { 0, 0 }
154 };
155
156 static driver_t cm_isa_driver = {
157         "cm",
158         cm_isa_methods,
159         sizeof(struct cm_softc)
160 };
161
162 DRIVER_MODULE(cm, isa, cm_isa_driver, cm_devclass, 0, 0);
163 MODULE_DEPEND(cm, isa, 1, 1, 1);