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
45 #include <sys/module.h>
46 #include <sys/bus.h>
47 #include <machine/bus.h>
48
49 #include <net/if.h>
50 #include <net/if_arp.h>
51 #include <net/if_media.h>
52
53
54 #include <dev/snc/dp83932var.h>
55 #include <dev/snc/if_sncvar.h>
56 #include <dev/snc/if_sncreg.h>
57
58 /*
59 * PC-Card (PCMCIA) specific code.
60 */
61 static int snc_pccard_probe(device_t);
62 static int snc_pccard_attach(device_t);
63 static int snc_pccard_detach(device_t);
64
65
66 static device_method_t snc_pccard_methods[] = {
67 /* Device interface */
68 DEVMETHOD(device_probe, snc_pccard_probe),
69 DEVMETHOD(device_attach, snc_pccard_attach),
70 DEVMETHOD(device_detach, snc_pccard_detach),
71
72 { 0, 0 }
73 };
74
75 static driver_t snc_pccard_driver = {
76 "snc",
77 snc_pccard_methods,
78 sizeof(struct snc_softc)
79 };
80
81 DRIVER_MODULE(snc, pccard, snc_pccard_driver, snc_devclass, 0, 0);
82 MODULE_DEPEND(snc, ether, 1, 1, 1);
83
84 /*
85 * snc_pccard_detach - unload the driver and clear the table.
86 * XXX TODO:
87 * This is usually called when the card is ejected, but
88 * can be caused by a modunload of a controller driver.
89 * The idea is to reset the driver's view of the device
90 * and ensure that any driver entry points such as
91 * read and write do not hang.
92 */
93 static int
94 snc_pccard_detach(device_t dev)
95 {
96 struct snc_softc *sc = device_get_softc(dev);
97 struct ifnet *ifp = &sc->sc_if;
98
99 if (sc->gone) {
100 device_printf(dev, "already unloaded\n");
101 return (0);
102 }
103 sncshutdown(sc);
104 ifp->if_flags &= ~IFF_RUNNING;
105 if_detach(ifp);
106 sc->gone = 1;
107 bus_teardown_intr(dev, sc->irq, sc->irq_handle);
108 snc_release_resources(dev);
109 return (0);
110 }
111
112 /*
113 * Probe framework for pccards. Replicates the standard framework,
114 * minus the pccard driver registration and ignores the ether address
115 * supplied (from the CIS), relying on the probe to find it instead.
116 */
117 static int
118 snc_pccard_probe(device_t dev)
119 {
120 int error;
121
122 error = snc_alloc_port(dev, 0);
123 error = max(error, snc_alloc_memory(dev, 0));
124 error = max(error, snc_alloc_irq(dev, 0, 0));
125
126 if (!error && !snc_probe(dev, SNEC_TYPE_PNP))
127 error = ENOENT;
128
129 snc_release_resources(dev);
130 return (error);
131 }
132
133 static int
134 snc_pccard_attach(device_t dev)
135 {
136 struct snc_softc *sc = device_get_softc(dev);
137 int error;
138
139 bzero(sc, sizeof(struct snc_softc));
140
141 snc_alloc_port(dev, 0);
142 snc_alloc_memory(dev, 0);
143 snc_alloc_irq(dev, 0, 0);
144
145 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
146 sncintr, sc, &sc->irq_handle);
147 if (error) {
148 printf("snc_isa_attach: bus_setup_intr() failed\n");
149 snc_release_resources(dev);
150 return (error);
151 }
152
153 /* This interface is always enabled. */
154 sc->sc_enabled = 1;
155
156 /* pccard_get_ether(dev, ether_addr); */
157
158 return snc_attach(dev);
159 }
Cache object: ca52f02da7dcf48e5fa77b69f8ae282c
|