]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/snc/if_snc_pccard.c
Merge bmake-20150505 improve detection of malformed conditionals.
[FreeBSD/FreeBSD.git] / sys / dev / snc / if_snc_pccard.c
1 /*-
2  * Copyright (c) 1995, David Greenman
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 unmodified, this list of conditions, and the following
10  *    disclaimer.
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.
14  *
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
25  * SUCH DAMAGE.
26  *
27  */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 /*
33  *      National Semiconductor  DP8393X SONIC Driver
34  *
35  *      This is the PC Card attachment on FreeBSD
36  *              written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp> and
37  *                         Hiroshi Yamashita <bluemoon@msj.biglobe.ne.jp>
38  */
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/socket.h>
43 #include <sys/kernel.h>
44 #include <sys/lock.h>
45 #include <sys/mutex.h>
46
47 #include <sys/module.h>
48 #include <sys/bus.h>
49 #include <machine/bus.h>
50
51 #include <net/ethernet.h>
52 #include <net/if.h>
53 #include <net/if_arp.h>
54 #include <net/if_media.h>
55
56 #include <dev/snc/dp83932var.h>
57 #include <dev/snc/if_sncvar.h>
58 #include <dev/snc/if_sncreg.h>
59
60 #include <dev/pccard/pccardvar.h>
61 #include <dev/pccard/pccard_cis.h>
62 #include "pccarddevs.h"
63
64 static const struct pccard_product snc_pccard_products[] = {
65         PCMCIA_CARD(NEC, PC9801N_J02),
66         PCMCIA_CARD(NEC, PC9801N_J02R),
67         { NULL }
68 };
69
70 /*
71  *      PC Card (PCMCIA) specific code.
72  */
73 static int      snc_pccard_probe(device_t);
74 static int      snc_pccard_attach(device_t);
75 static int      snc_pccard_detach(device_t);
76
77
78 static device_method_t snc_pccard_methods[] = {
79         /* Device interface */
80         DEVMETHOD(device_probe,         snc_pccard_probe),
81         DEVMETHOD(device_attach,        snc_pccard_attach),
82         DEVMETHOD(device_detach,        snc_pccard_detach),
83
84         { 0, 0 }
85 };
86
87 static driver_t snc_pccard_driver = {
88         "snc",
89         snc_pccard_methods,
90         sizeof(struct snc_softc)
91 };
92
93 DRIVER_MODULE(snc, pccard, snc_pccard_driver, snc_devclass, 0, 0);
94 MODULE_DEPEND(snc, ether, 1, 1, 1);
95
96 /*
97  *      snc_pccard_detach - detach this instance from the device.
98  */
99 static int
100 snc_pccard_detach(device_t dev)
101 {
102         struct snc_softc *sc = device_get_softc(dev);
103         struct ifnet *ifp = sc->sc_ifp;
104
105         if (sc->gone) {
106                 device_printf(dev, "already unloaded\n");
107                 return (0);
108         }
109         SNC_LOCK(sc);
110         sncshutdown(sc);
111         SNC_UNLOCK(sc);
112         callout_drain(&sc->sc_timer);
113         ether_ifdetach(ifp);
114         sc->gone = 1;
115         bus_teardown_intr(dev, sc->irq, sc->irq_handle);
116         snc_release_resources(dev);
117         mtx_destroy(&sc->sc_lock);
118         return (0);
119 }
120
121 /* 
122  * Probe the pccard.
123  */
124 static int
125 snc_pccard_probe(device_t dev)
126 {
127         const struct pccard_product *pp;
128
129         if ((pp = pccard_product_lookup(dev, snc_pccard_products,
130             sizeof(snc_pccard_products[0]), NULL)) == NULL)
131                 return (EIO);
132         if (pp->pp_name != NULL)
133                 device_set_desc(dev, pp->pp_name);
134         return (0);
135 }
136
137 static int
138 snc_pccard_attach(device_t dev)
139 {
140         struct snc_softc *sc = device_get_softc(dev);
141         int error;
142         
143         /*
144          * Not sure that this belongs here or in snc_pccard_attach
145          */
146         if ((error = snc_alloc_port(dev, 0)) != 0)
147                 goto err;
148         if ((error = snc_alloc_memory(dev, 0)) != 0)
149                 goto err;
150         if ((error = snc_alloc_irq(dev, 0, 0)) != 0)
151                 goto err;
152         if ((error = snc_probe(dev, SNEC_TYPE_PNP)) != 0)
153                 goto err;
154         /* This interface is always enabled. */
155         sc->sc_enabled = 1;
156         /* pccard_get_ether(dev, ether_addr); */
157         if ((error = snc_attach(dev)) != 0)
158                 goto err;
159         return 0;
160 err:;
161         snc_release_resources(dev);
162         return error;
163