Make all network interrupt service routines MPSAFE part 1/3.
[dragonfly.git] / sys / dev / netif / fe / if_fe_pccard.c
CommitLineData
984263bc
MD
1/*
2 * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
3 *
4 * This software may be used, modified, copied, distributed, and sold, in
5 * both source and binary form provided that the above copyright, these
6 * terms and the following disclaimer are retained. The name of the author
7 * and/or the contributor may not be used to endorse or promote products
8 * derived from this software without specific prior written permission.
9 *
10 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND
11 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
12 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE
14 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
15 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
16 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION.
17 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
19 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
20 * SUCH DAMAGE.
21 *
22 * $FreeBSD: src/sys/dev/fe/if_fe_pccard.c,v 1.2.2.1 2000/09/22 10:01:47 nyan Exp $
78195a76 23 * $DragonFly: src/sys/dev/netif/fe/if_fe_pccard.c,v 1.8 2005/11/28 17:13:42 dillon Exp $
984263bc
MD
24 */
25
26#include "opt_fe.h"
27#include "opt_inet.h"
28#include "opt_ipx.h"
29
30#include <sys/param.h>
31#include <sys/kernel.h>
32#include <sys/socket.h>
33#include <sys/module.h>
34#include <machine/clock.h>
35
36#include <sys/bus.h>
37#include <machine/bus.h>
38#include <machine/resource.h>
39
40#include <net/ethernet.h>
41#include <net/if.h>
42#include <net/if_mib.h>
43#include <net/if_media.h>
44
45#include <netinet/in.h>
46#include <netinet/if_ether.h>
47
48#include <i386/isa/ic/mb86960.h>
1f2de5d4
MD
49#include "if_fereg.h"
50#include "if_fevar.h"
984263bc 51
1f2de5d4 52#include <bus/pccard/pccardvar.h>
06d02e3b 53#include <bus/pccard/pccarddevs.h>
1f2de5d4 54#include <bus/pccard/cardinfo.h>
984263bc 55
06d02e3b
JS
56#include "card_if.h"
57
984263bc
MD
58/*
59 * PC-Card (PCMCIA) specific code.
60 */
61static int fe_pccard_probe(device_t);
62static int fe_pccard_attach(device_t);
63static int fe_pccard_detach(device_t);
06d02e3b
JS
64static int fe_pccard_match(device_t);
65
66static const struct fe_pccard_product {
67 struct pccard_product mpp_product;
68 u_int32_t mpp_ioalign; /* required alignment */
69 int mpp_enet_maddr;
70} fe_pccard_products[] = {
71 { PCMCIA_CARD(TDK, LAK_CD021BX, 0), 0, -1 },
72 { PCMCIA_CARD(TDK, LAK_CF010, 0), 0, -1 },
73#if 0 /* XXX 86960-based? */
74 { PCMCIA_CARD(TDK, LAK_DFL9610, 1), 0, -1 },
75#endif
76 { PCMCIA_CARD(CONTEC, CNETPC, 0), 0, -1 },
77 { PCMCIA_CARD(FUJITSU, LA501, 0), 0x20, -1 },
78 { PCMCIA_CARD(FUJITSU, LA10S, 0), 0, -1 },
79 { PCMCIA_CARD(RATOC, REX_R280, 0), 0, 0x1fc },
80 { { NULL } }
81};
82
83static int
84fe_pccard_match(device_t dev)
85{
86 const struct pccard_product *pp;
87
88 if ((pp = pccard_product_lookup(dev,
89 (const struct pccard_product *)fe_pccard_products,
90 sizeof(fe_pccard_products[0]), NULL)) != NULL) {
91 if (pp->pp_name != NULL)
92 device_set_desc(dev, pp->pp_name);
93 return 0;
94 }
95 return ENXIO;
96}
984263bc
MD
97
98static device_method_t fe_pccard_methods[] = {
06d02e3b
JS
99 /* Device interface */
100 DEVMETHOD(device_probe, pccard_compat_probe),
101 DEVMETHOD(device_attach, pccard_compat_attach),
102 DEVMETHOD(device_detach, fe_pccard_detach),
103
104 /* Card interface */
105 DEVMETHOD(card_compat_match, fe_pccard_match),
106 DEVMETHOD(card_compat_probe, fe_pccard_probe),
107 DEVMETHOD(card_compat_attach, fe_pccard_attach),
984263bc
MD
108
109 { 0, 0 }
110};
111
112static driver_t fe_pccard_driver = {
113 "fe",
114 fe_pccard_methods,
115 sizeof (struct fe_softc)
116};
117
32832096 118DRIVER_MODULE(if_fe, pccard, fe_pccard_driver, fe_devclass, 0, 0);
984263bc
MD
119
120
121static int fe_probe_mbh(device_t);
122static int fe_probe_tdk(device_t);
123
124/*
125 * Initialize the device - called from Slot manager.
126 */
127static int
128fe_pccard_probe(device_t dev)
129{
130 struct fe_softc *sc;
6ac1f49d
JS
131 int i, error;
132 uint8_t sum;
133 uint8_t *ether_addr;
984263bc
MD
134
135 /* Prepare for the device probe process. */
136 sc = device_get_softc(dev);
137 sc->sc_unit = device_get_unit(dev);
138
6ac1f49d
JS
139 ether_addr = pccard_get_ether(dev);
140 for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++)
141 sum |= ether_addr[i];
142 if (sum)
143 bcopy(ether_addr, sc->sc_enaddr, ETHER_ADDR_LEN);
984263bc
MD
144
145 /* Probe for supported cards. */
146 if ((error = fe_probe_mbh(dev)) == 0)
147 goto end;
148 fe_release_resource(dev);
149
150 if ((error = fe_probe_tdk(dev)) == 0)
151 goto end;
152 fe_release_resource(dev);
153
154end:
155 if (error == 0)
156 error = fe_alloc_irq(dev, 0);
157
158 fe_release_resource(dev);
159 return (error);
160}
161
162static int
163fe_pccard_attach(device_t dev)
164{
165 struct fe_softc *sc = device_get_softc(dev);
166
167 if (sc->port_used)
168 fe_alloc_port(dev, sc->port_used);
169 fe_alloc_irq(dev, 0);
170
171 return fe_attach(dev);
172}
173
174/*
175 * feunload - unload the driver and clear the table.
176 * XXX TODO:
177 * This is usually called when the card is ejected, but
178 * can be caused by a modunload of a controller driver.
179 * The idea is to reset the driver's view of the device
180 * and ensure that any driver entry points such as
181 * read and write do not hang.
182 */
183static int
184fe_pccard_detach(device_t dev)
185{
186 struct fe_softc *sc = device_get_softc(dev);
187 struct ifnet *ifp = &sc->arpcom.ac_if;
188
78195a76 189 lwkt_serialize_enter(ifp->if_serializer);
984263bc 190 fe_stop(sc);
0a8b5977 191 ether_ifdetach(ifp);
984263bc
MD
192 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
193 fe_release_resource(dev);
78195a76 194 lwkt_serialize_exit(ifp->if_serializer);
984263bc
MD
195
196 return 0;
197}
198
199
200/*
201 * Probe and initialization for Fujitsu MBH10302 PCMCIA Ethernet interface.
202 * Note that this is for 10302 only; MBH10304 is handled by fe_probe_tdk().
203 */
204static void
205fe_init_mbh(struct fe_softc *sc)
206{
207 /* Minimal initialization of 86960. */
208 DELAY(200);
209 fe_outb(sc, FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
210 DELAY(200);
211
212 /* Disable all interrupts. */
213 fe_outb(sc, FE_DLCR2, 0);
214 fe_outb(sc, FE_DLCR3, 0);
215
216 /* Enable master interrupt flag. */
217 fe_outb(sc, FE_MBH0, FE_MBH0_MAGIC | FE_MBH0_INTR_ENABLE);
218}
219
220static int
221fe_probe_mbh(device_t dev)
222{
223 struct fe_softc *sc = device_get_softc(dev);
224
225 static struct fe_simple_probe_struct probe_table [] = {
226 { FE_DLCR2, 0x58, 0x00 },
227 { FE_DLCR4, 0x08, 0x00 },
228 { FE_DLCR6, 0xFF, 0xB6 },
229 { 0 }
230 };
231
232 /* MBH10302 occupies 32 I/O addresses. */
233 if (fe_alloc_port(dev, 32))
234 return ENXIO;
235
236 /* Ethernet MAC address should *NOT* have been given by pccardd,
237 if this is a true MBH10302; i.e., Ethernet address must be
238 "all-zero" upon entry. */
239 if (sc->sc_enaddr[0] || sc->sc_enaddr[1] || sc->sc_enaddr[2] ||
240 sc->sc_enaddr[3] || sc->sc_enaddr[4] || sc->sc_enaddr[5])
241 return ENXIO;
242
243 /* Fill the softc struct with default values. */
244 fe_softc_defaults(sc);
245
246 /*
247 * See if MBH10302 is on its address.
248 * I'm not sure the following probe code works. FIXME.
249 */
250 if (!fe_simple_probe(sc, probe_table))
251 return ENXIO;
252
253 /* Get our station address from EEPROM. */
254 fe_inblk(sc, FE_MBH10, sc->sc_enaddr, ETHER_ADDR_LEN);
255
256 /* Make sure we got a valid station address. */
257 if (!valid_Ether_p(sc->sc_enaddr, 0))
258 return ENXIO;
259
260 /* Determine the card type. */
261 sc->type = FE_TYPE_MBH;
262 sc->typestr = "MBH10302 (PCMCIA)";
263
264 /* We seems to need our own IDENT bits... FIXME. */
265 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
266
267 /* Setup hooks. We need a special initialization procedure. */
268 sc->init = fe_init_mbh;
269
270 return 0;
271}
272
273/*
274 * Probe and initialization for TDK/CONTEC PCMCIA Ethernet interface.
275 * by MASUI Kenji <masui@cs.titech.ac.jp>
276 *
277 * (Contec uses TDK Ethenet chip -- hosokawa)
278 *
279 * This version of fe_probe_tdk has been rewrote to handle
280 * *generic* PC card implementation of Fujitsu MB8696x family. The
281 * name _tdk is just for a historical reason. :-)
282 */
283static int
284fe_probe_tdk (device_t dev)
285{
286 struct fe_softc *sc = device_get_softc(dev);
287
288 static struct fe_simple_probe_struct probe_table [] = {
289 { FE_DLCR2, 0x50, 0x00 },
290 { FE_DLCR4, 0x08, 0x00 },
291 /* { FE_DLCR5, 0x80, 0x00 }, Does not work well. */
292 { 0 }
293 };
294
295 /* C-NET(PC)C occupies 16 I/O addresses. */
296 if (fe_alloc_port(dev, 16))
297 return ENXIO;
298
299 /* Fill the softc struct with default values. */
300 fe_softc_defaults(sc);
301
302 /*
303 * See if C-NET(PC)C is on its address.
304 */
305 if (!fe_simple_probe(sc, probe_table))
306 return ENXIO;
307
308 /* Determine the card type. */
309 sc->type = FE_TYPE_TDK;
310 sc->typestr = "Generic MB8696x/78Q837x Ethernet (PCMCIA)";
311
312 /* Make sure we got a valid station address. */
313 if (!valid_Ether_p(sc->sc_enaddr, 0))
314 return ENXIO;
315
316 return 0;
317}