Deleted Added
sdiff udiff text old ( 140503 ) new ( 140528 )
full compact
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 */
23
24#include <sys/cdefs.h>
25__FBSDID("$FreeBSD: head/sys/dev/fe/if_fe_pccard.c 140503 2005-01-20 07:05:59Z imp $");
26
27#include <sys/param.h>
28#include <sys/kernel.h>
29#include <sys/socket.h>
30#include <sys/systm.h>
31#include <sys/module.h>
32
33#include <sys/bus.h>
34#include <machine/bus.h>
35#include <machine/resource.h>
36
37#include <net/ethernet.h>
38#include <net/if.h>
39#include <net/if_mib.h>
40#include <net/if_media.h>
41
42#include <netinet/in.h>
43#include <netinet/if_ether.h>
44
45#include <i386/isa/ic/mb86960.h>
46#include <dev/fe/if_fereg.h>
47#include <dev/fe/if_fevar.h>
48
49#include <dev/pccard/pccardvar.h>
50
51#include "card_if.h"
52#include "pccarddevs.h"
53
54/*
55 * PC-Card (PCMCIA) specific code.
56 */
57static int fe_pccard_probe(device_t);
58static int fe_pccard_attach(device_t);
59static int fe_pccard_detach(device_t);
60static int fe_pccard_match(device_t);
61
62static const struct fe_pccard_product {
63 struct pccard_product mpp_product;
64 uint32_t mpp_ioalign; /* required alignment */
65 int mpp_enet_maddr;
66 int mpp_flags;
67#define MBH10302 0x1 /* Fujitsu MBH10302 */
68} fe_pccard_products[] = {
69 /* These need to be first */
70 { PCMCIA_CARD(FUJITSU2, FMV_J181, 0), 0, -1, MBH10302},
71 { PCMCIA_CARD(FUJITSU2, FMV_J182, 0), 0, 0xf2c},
72 { PCMCIA_CARD(FUJITSU2, FMV_J182A, 0), 0, 0x1cc},
73 { PCMCIA_CARD(FUJITSU2, ITCFJ182A, 0), 0, 0x1cc},
74 /* These need to be second */
75 { PCMCIA_CARD(TDK, LAK_CD021BX, 0), 0, -1 },
76 { PCMCIA_CARD(TDK, LAK_CF010, 0), 0, -1 },
77#if 0 /* XXX 86960-based? */
78 { PCMCIA_CARD(TDK, LAK_DFL9610, 1), 0, -1 },
79#endif
80 { PCMCIA_CARD(CONTEC, CNETPC, 0), 0, -1 },
81 { PCMCIA_CARD(FUJITSU, LA501, 0), 0x20, -1 },
82 { PCMCIA_CARD(FUJITSU, LA10S, 0), 0, -1 },
83 { PCMCIA_CARD(FUJITSU, NE200T, 0), 0, -1, MBH10302},/* Sold by Eagle */
84 { PCMCIA_CARD(RATOC, REX_R280, 0), 0, 0x1fc },
85 { { NULL } }
86};
87
88static int
89fe_pccard_match(device_t dev)
90{
91 const struct pccard_product *pp;
92
93 if ((pp = pccard_product_lookup(dev,
94 (const struct pccard_product *)fe_pccard_products,
95 sizeof(fe_pccard_products[0]), NULL)) != NULL) {
96 if (pp->pp_name != NULL)
97 device_set_desc(dev, pp->pp_name);
98 return 0;
99 }
100 return EIO;
101}
102
103static device_method_t fe_pccard_methods[] = {
104 /* Device interface */
105 DEVMETHOD(device_probe, pccard_compat_probe),
106 DEVMETHOD(device_attach, pccard_compat_attach),
107 DEVMETHOD(device_detach, fe_pccard_detach),
108
109 /* Card interface */
110 DEVMETHOD(card_compat_match, fe_pccard_match),
111 DEVMETHOD(card_compat_probe, fe_pccard_probe),
112 DEVMETHOD(card_compat_attach, fe_pccard_attach),
113
114 { 0, 0 }
115};
116
117static driver_t fe_pccard_driver = {
118 "fe",
119 fe_pccard_methods,
120 sizeof (struct fe_softc)
121};
122
123DRIVER_MODULE(fe, pccard, fe_pccard_driver, fe_devclass, 0, 0);
124
125static int fe_probe_mbh(device_t);
126static int fe_probe_tdk(device_t);
127
128/*
129 * Initialize the device - called from Slot manager.
130 */
131static int
132fe_pccard_probe(device_t dev)
133{
134 struct fe_softc *sc;
135 int error;
136
137 /* Prepare for the device probe process. */
138 sc = device_get_softc(dev);
139 sc->sc_unit = device_get_unit(dev);
140
141 pccard_get_ether(dev, sc->sc_enaddr);
142
143 /* Probe for supported cards. */
144 if ((error = fe_probe_mbh(dev)) == 0)
145 goto end;
146 fe_release_resource(dev);
147
148 if ((error = fe_probe_tdk(dev)) == 0)
149 goto end;
150 fe_release_resource(dev);
151
152end:
153 if (error == 0)
154 error = fe_alloc_irq(dev, 0);
155
156 fe_release_resource(dev);
157 return (error);
158}
159
160static int
161fe_pccard_attach(device_t dev)
162{
163 struct fe_softc *sc = device_get_softc(dev);
164
165 if (sc->port_used)
166 fe_alloc_port(dev, sc->port_used);
167 fe_alloc_irq(dev, 0);
168
169 return fe_attach(dev);
170}
171
172/*
173 * feunload - unload the driver and clear the table.
174 */
175static int
176fe_pccard_detach(device_t dev)
177{
178 struct fe_softc *sc = device_get_softc(dev);
179 struct ifnet *ifp = &sc->arpcom.ac_if;
180
181 fe_stop(sc);
182 ether_ifdetach(ifp);
183 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
184 fe_release_resource(dev);
185
186 return 0;
187}
188
189
190/*
191 * Probe and initialization for Fujitsu MBH10302 PCMCIA Ethernet interface.
192 * Note that this is for 10302 only; MBH10304 is handled by fe_probe_tdk().
193 */
194static void
195fe_init_mbh(struct fe_softc *sc)
196{
197 /* Minimal initialization of 86960. */
198 DELAY(200);
199 fe_outb(sc, FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
200 DELAY(200);
201
202 /* Disable all interrupts. */
203 fe_outb(sc, FE_DLCR2, 0);
204 fe_outb(sc, FE_DLCR3, 0);
205
206 /* Enable master interrupt flag. */
207 fe_outb(sc, FE_MBH0, FE_MBH0_MAGIC | FE_MBH0_INTR_ENABLE);
208}
209
210static int
211fe_probe_mbh(device_t dev)
212{
213 struct fe_softc *sc = device_get_softc(dev);
214
215 static struct fe_simple_probe_struct probe_table [] = {
216 { FE_DLCR2, 0x58, 0x00 },
217 { FE_DLCR4, 0x08, 0x00 },
218 { FE_DLCR6, 0xFF, 0xB6 },
219 { 0 }
220 };
221
222 /* MBH10302 occupies 32 I/O addresses. */
223 if (fe_alloc_port(dev, 32))
224 return ENXIO;
225
226 /* Ethernet MAC address should *NOT* have been given by pccardd,
227 if this is a true MBH10302; i.e., Ethernet address must be
228 "all-zero" upon entry. */
229 if (sc->sc_enaddr[0] || sc->sc_enaddr[1] || sc->sc_enaddr[2] ||
230 sc->sc_enaddr[3] || sc->sc_enaddr[4] || sc->sc_enaddr[5])
231 return ENXIO;
232
233 /* Fill the softc struct with default values. */
234 fe_softc_defaults(sc);
235
236 /*
237 * See if MBH10302 is on its address.
238 * I'm not sure the following probe code works. FIXME.
239 */
240 if (!fe_simple_probe(sc, probe_table))
241 return ENXIO;
242
243 /* Get our station address from EEPROM. */
244 fe_inblk(sc, FE_MBH10, sc->sc_enaddr, ETHER_ADDR_LEN);
245
246 /* Make sure we got a valid station address. */
247 if (!fe_valid_Ether_p(sc->sc_enaddr, 0))
248 return ENXIO;
249
250 /* Determine the card type. */
251 sc->type = FE_TYPE_MBH;
252 sc->typestr = "MBH10302 (PCMCIA)";
253
254 /* We seems to need our own IDENT bits... FIXME. */
255 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
256
257 /* Setup hooks. We need a special initialization procedure. */
258 sc->init = fe_init_mbh;
259
260 return 0;
261}
262
263/*
264 * Probe and initialization for TDK/CONTEC PCMCIA Ethernet interface.
265 * by MASUI Kenji <masui@cs.titech.ac.jp>
266 *
267 * (Contec uses TDK Ethenet chip -- hosokawa)
268 *
269 * This version of fe_probe_tdk has been rewrote to handle
270 * *generic* PC card implementation of Fujitsu MB8696x family. The
271 * name _tdk is just for a historical reason. :-)
272 */
273static int
274fe_probe_tdk (device_t dev)
275{
276 struct fe_softc *sc = device_get_softc(dev);
277
278 static struct fe_simple_probe_struct probe_table [] = {
279 { FE_DLCR2, 0x50, 0x00 },
280 { FE_DLCR4, 0x08, 0x00 },
281 /* { FE_DLCR5, 0x80, 0x00 }, Does not work well. */
282 { 0 }
283 };
284
285 /* C-NET(PC)C occupies 16 I/O addresses. */
286 if (fe_alloc_port(dev, 16))
287 return ENXIO;
288
289 /* Fill the softc struct with default values. */
290 fe_softc_defaults(sc);
291
292 /*
293 * See if C-NET(PC)C is on its address.
294 */
295 if (!fe_simple_probe(sc, probe_table))
296 return ENXIO;
297
298 /* Determine the card type. */
299 sc->type = FE_TYPE_TDK;
300 sc->typestr = "Generic MB8696x/78Q837x Ethernet (PCMCIA)";
301
302 /* Make sure we got a valid station address. */
303 if (!fe_valid_Ether_p(sc->sc_enaddr, 0))
304 return ENXIO;
305
306 return 0;
307}