Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / dev / netif / awi / if_awi_pccard.c
1 /*
2  * Copyright (c) 2000 Atsushi Onoe <onoe@sm.sony.co.jp>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * $FreeBSD: src/sys/dev/awi/if_awi_pccard.c,v 1.5.2.1 2000/12/07 04:09:39 imp Exp $
26  * $DragonFly: src/sys/dev/netif/awi/Attic/if_awi_pccard.c,v 1.2 2003/06/17 04:28:22 dillon Exp $
27  */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/socket.h>
33
34 #include <sys/module.h>
35 #include <sys/bus.h>
36
37 #include <machine/bus.h>
38 #include <machine/resource.h>
39 #include <sys/rman.h>
40  
41 #include <net/if.h> 
42 #include <net/if_arp.h>
43 #include <net/if_media.h>
44 #include <net/ethernet.h>
45 #include <net/if_ieee80211.h>
46
47 #include <machine/clock.h>
48
49 #include <dev/awi/am79c930reg.h>
50 #include <dev/awi/am79c930var.h>
51 #include <dev/awi/awireg.h>
52 #include <dev/awi/awivar.h>
53
54 struct awi_pccard_softc {
55         struct awi_softc        sc_awi;
56
57         u_int8_t        sc_version[AWI_BANNER_LEN];
58         int             sc_intr_mask;
59         void            *sc_intrhand;
60         struct resource *sc_irq_res;
61         int             sc_irq_rid;
62         struct resource *sc_port_res;
63         int             sc_port_rid;
64         struct resource *sc_mem_res;
65         int             sc_mem_rid;
66 };
67
68 /*
69  * Initialize the device - called from Slot manager.
70  */
71 static int
72 awi_pccard_probe(device_t dev)
73 {
74         struct awi_pccard_softc *psc = device_get_softc(dev);
75         struct awi_softc *sc = &psc->sc_awi;
76         int error = 0;
77
78         psc->sc_port_rid = 0;
79         psc->sc_port_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
80             &psc->sc_port_rid, 0, ~0, 16, RF_ACTIVE);
81         if (!psc->sc_port_res)
82                 return ENOMEM;
83
84         sc->sc_chip.sc_iot = rman_get_bustag(psc->sc_port_res);
85         sc->sc_chip.sc_ioh = rman_get_bushandle(psc->sc_port_res);
86         am79c930_chip_init(&sc->sc_chip, 0);
87         DELAY(1000); 
88
89         awi_read_bytes(sc, AWI_BANNER, psc->sc_version, AWI_BANNER_LEN);
90         if (memcmp(psc->sc_version, "PCnetMobile:", 12) != 0)  {
91                 device_printf(dev, "awi_pccard_probe: bad banner: %12D\n",
92                     psc->sc_version, " ");
93                 error = ENXIO;
94         } else
95                 device_set_desc(dev, psc->sc_version);
96         bus_release_resource(dev, SYS_RES_IOPORT, psc->sc_port_rid,
97             psc->sc_port_res);
98
99         return error;
100 }
101
102 static int
103 awi_pccard_attach(device_t dev)
104 {
105         struct awi_pccard_softc *psc = device_get_softc(dev);
106         struct awi_softc *sc = &psc->sc_awi;
107         struct ifnet *ifp = &sc->sc_ec.ac_if;
108         int error = 0;
109
110         psc->sc_port_res = 0;
111         psc->sc_irq_res = 0;
112         psc->sc_mem_res = 0;
113         psc->sc_intrhand = 0;
114
115         ifp->if_name = device_get_name(dev);
116         ifp->if_unit = device_get_unit(dev);
117         if (ifp->if_name == NULL) {
118                 printf("awi%d: awi_pccard_attach: cannot get device name\n",
119                     device_get_unit(dev));
120                 goto fail;
121         }
122         snprintf(sc->sc_dev.dv_xname, sizeof(sc->sc_dev.dv_xname),
123             "%s%d", ifp->if_name, ifp->if_unit);
124
125         psc->sc_port_rid = 0;
126         psc->sc_port_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
127             &psc->sc_port_rid, 0, ~0, 16, RF_ACTIVE);
128         if (!psc->sc_port_res) {
129                 device_printf(dev, "awi_pccard_attach: port alloc failed\n");
130                 goto fail;
131         }
132         sc->sc_chip.sc_iot = rman_get_bustag(psc->sc_port_res);
133         sc->sc_chip.sc_ioh = rman_get_bushandle(psc->sc_port_res);
134
135         psc->sc_irq_rid = 0;
136         psc->sc_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ,
137             &psc->sc_irq_rid, 0, ~0, 1, RF_ACTIVE);
138         if (!psc->sc_irq_res) {
139                 device_printf(dev, "awi_pccard_attach: irq alloc failed\n");
140                 goto fail;
141         }
142
143         psc->sc_mem_rid = 0;
144 #if 1
145         /*
146          * XXX: awi needs to access memory with 8bit,
147          * but pccardd apparently maps memory with MDF_16BITS flag.
148          * So memory mapped access is disabled and use IO port instead.
149          */
150         psc->sc_mem_res = 0;
151 #else
152         psc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
153             &psc->sc_mem_rid, 0, ~0, 0x8000, RF_ACTIVE);
154 #endif
155         if (psc->sc_mem_res) {
156                 sc->sc_chip.sc_memt = rman_get_bustag(psc->sc_mem_res);
157                 sc->sc_chip.sc_memh = rman_get_bushandle(psc->sc_mem_res);
158                 am79c930_chip_init(&sc->sc_chip, 1);
159         } else
160                 am79c930_chip_init(&sc->sc_chip, 0);
161
162         error = bus_setup_intr(dev, psc->sc_irq_res, INTR_TYPE_NET,
163             (void (*)(void *))awi_intr, sc, &psc->sc_intrhand);
164         if (error) {
165                 device_printf(dev, "awi_pccard_attach: intr setup failed\n");
166                 goto fail;
167         }
168
169         sc->sc_cansleep = 1;
170         sc->sc_enabled = 1;
171         sc->sc_ifp = &sc->sc_ec.ac_if;
172
173         error = awi_attach(sc);
174         sc->sc_enabled = 0;     /*XXX*/
175         if (error == 0)
176                 return 0;
177         device_printf(dev, "awi_pccard_attach: awi_attach failed\n");
178
179   fail:
180         if (psc->sc_intrhand) {
181                 bus_teardown_intr(dev, psc->sc_irq_res, psc->sc_intrhand);
182                 psc->sc_intrhand = 0;
183         }
184         if (psc->sc_port_res) {
185                 bus_release_resource(dev, SYS_RES_IOPORT, psc->sc_port_rid,
186                     psc->sc_port_res);
187                 psc->sc_port_res = 0;
188         }
189         if (psc->sc_irq_res) {
190                 bus_release_resource(dev, SYS_RES_IRQ, psc->sc_irq_rid,
191                     psc->sc_irq_res);
192                 psc->sc_irq_res = 0;
193         }
194         if (psc->sc_mem_res) {
195                 bus_release_resource(dev, SYS_RES_MEMORY, psc->sc_mem_rid,
196                     psc->sc_mem_res);
197                 psc->sc_mem_res = 0;
198         }
199         if (error == 0)
200                 error = ENXIO;
201         return error;
202 }
203
204 static int
205 awi_pccard_detach(device_t dev)
206 {
207         struct awi_pccard_softc *psc = device_get_softc(dev);
208         struct awi_softc *sc = &psc->sc_awi;
209         struct ifnet *ifp = &sc->sc_ec.ac_if;
210
211         ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
212         ifp->if_flags &= ~IFF_RUNNING; 
213         if (psc->sc_intrhand) {
214                 bus_teardown_intr(dev, psc->sc_irq_res, psc->sc_intrhand);
215                 psc->sc_intrhand = 0;
216         }
217         if (psc->sc_port_res) {
218                 bus_release_resource(dev, SYS_RES_IOPORT, psc->sc_port_rid,
219                     psc->sc_port_res);
220                 psc->sc_port_res = 0;
221         }
222         if (psc->sc_irq_res) {
223                 bus_release_resource(dev, SYS_RES_IRQ, psc->sc_irq_rid,
224                     psc->sc_irq_res);
225                 psc->sc_irq_res = 0;
226         }
227         if (psc->sc_mem_res) {
228                 bus_release_resource(dev, SYS_RES_MEMORY, psc->sc_mem_rid,
229                     psc->sc_mem_res);
230                 psc->sc_mem_res = 0;
231         }
232         return 0;
233 }
234
235 static device_method_t awi_pccard_methods[] = {
236         /* Device interface */
237         DEVMETHOD(device_probe,         awi_pccard_probe),
238         DEVMETHOD(device_attach,        awi_pccard_attach),
239         DEVMETHOD(device_detach,        awi_pccard_detach),
240
241         { 0, 0 }
242 };
243
244 static driver_t awi_pccard_driver = {
245         "awi",
246         awi_pccard_methods,
247         sizeof(struct awi_pccard_softc),
248 };
249
250 extern devclass_t awi_devclass;
251
252 DRIVER_MODULE(awi, pccard, awi_pccard_driver, awi_devclass, 0, 0);