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