if_ne_pcmcia.c revision 1.117 1 /* $NetBSD: if_ne_pcmcia.c,v 1.117 2004/07/07 04:01:30 mycroft Exp $ */
2
3 /*
4 * Copyright (c) 1997 Marc Horowitz. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following 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 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Marc Horowitz.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: if_ne_pcmcia.c,v 1.117 2004/07/07 04:01:30 mycroft Exp $");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/select.h>
38 #include <sys/device.h>
39 #include <sys/socket.h>
40
41 #include <net/if_types.h>
42 #include <net/if.h>
43 #include <net/if_media.h>
44 #include <net/if_ether.h>
45
46 #include <machine/bus.h>
47 #include <machine/intr.h>
48
49 #include <dev/pcmcia/pcmciareg.h>
50 #include <dev/pcmcia/pcmciavar.h>
51 #include <dev/pcmcia/pcmciadevs.h>
52
53 #include <dev/ic/dp8390reg.h>
54 #include <dev/ic/dp8390var.h>
55
56 #include <dev/ic/ne2000reg.h>
57 #include <dev/ic/ne2000var.h>
58
59 #include <dev/ic/rtl80x9reg.h>
60 #include <dev/ic/rtl80x9var.h>
61
62 #include <dev/ic/dl10019var.h>
63
64 #include <dev/ic/ax88190reg.h>
65 #include <dev/ic/ax88190var.h>
66
67 int ne_pcmcia_match __P((struct device *, struct cfdata *, void *));
68 void ne_pcmcia_attach __P((struct device *, struct device *, void *));
69 int ne_pcmcia_detach __P((struct device *, int));
70
71 int ne_pcmcia_enable __P((struct dp8390_softc *));
72 void ne_pcmcia_disable __P((struct dp8390_softc *));
73
74 struct ne_pcmcia_softc {
75 struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
76
77 /* PCMCIA-specific goo */
78 struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o information */
79 int sc_asic_io_window; /* i/o window for ASIC */
80 int sc_nic_io_window; /* i/o window for NIC */
81 struct pcmcia_function *sc_pf; /* our PCMCIA function */
82 void *sc_ih; /* interrupt handle */
83 };
84
85 u_int8_t *
86 ne_pcmcia_get_enaddr __P((struct ne_pcmcia_softc *, int,
87 u_int8_t [ETHER_ADDR_LEN]));
88 u_int8_t *
89 ne_pcmcia_dl10019_get_enaddr __P((struct ne_pcmcia_softc *,
90 u_int8_t [ETHER_ADDR_LEN]));
91 int ne_pcmcia_ax88190_set_iobase __P((struct ne_pcmcia_softc *));
92
93 CFATTACH_DECL(ne_pcmcia, sizeof(struct ne_pcmcia_softc),
94 ne_pcmcia_match, ne_pcmcia_attach, ne_pcmcia_detach, dp8390_activate);
95
96 static const struct ne2000dev {
97 int32_t manufacturer;
98 int32_t product;
99 char *cis_info[4];
100 int function;
101 int enet_maddr;
102 unsigned char enet_vendor[3];
103 int flags;
104 #define NE2000DVF_DL10019 0x0001 /* chip is D-Link DL10019 */
105 #define NE2000DVF_AX88190 0x0002 /* chip is ASIX AX88190 */
106 #define NE2000DVF_AX88790 0x0004 /* chip is ASIX AX88790 */
107 } ne2000devs[] = {
108 { PCMCIA_VENDOR_EDIMAX, PCMCIA_PRODUCT_EDIMAX_EP4000A,
109 PCMCIA_CIS_EDIMAX_EP4000A,
110 0, -1, { 0x00, 0xa0, 0x0c } },
111
112 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
113 PCMCIA_CIS_SYNERGY21_S21810,
114 0, -1, { 0x00, 0x48, 0x54 } },
115
116 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
117 PCMCIA_CIS_AMBICOM_AMB8002T,
118 0, -1, { 0x00, 0x10, 0x7a } },
119
120 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
121 PCMCIA_CIS_PREMAX_PE200,
122 0, 0x07f0, { 0x00, 0x20, 0xe0 } },
123
124 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
125 PCMCIA_CIS_DIGITAL_DEPCMXX,
126 0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
127
128 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
129 PCMCIA_CIS_PLANET_SMARTCOM2000,
130 0, 0xff0, { 0x00, 0x00, 0xe8 } },
131
132 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
133 PCMCIA_CIS_DLINK_DE660,
134 0, -1, { 0x00, 0x80, 0xc8 } },
135
136 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
137 PCMCIA_CIS_DLINK_DE660PLUS,
138 0, -1, { 0x00, 0x80, 0xc8 } },
139
140 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
141 PCMCIA_CIS_RPTI_EP400,
142 0, 0x110, { 0x00, 0x40, 0x95 } },
143
144 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
145 PCMCIA_CIS_RPTI_EP401,
146 0, -1, { 0x00, 0x40, 0x95 } },
147
148 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
149 PCMCIA_CIS_ACCTON_EN2212,
150 0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
151
152 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
153 PCMCIA_CIS_ACCTON_EN2216,
154 0, -1, { 0x00, 0x00, 0xe8 } },
155
156 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
157 PCMCIA_CIS_SVEC_COMBOCARD,
158 0, -1, { 0x00, 0xe0, 0x98 } },
159
160 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
161 PCMCIA_CIS_SVEC_LANCARD,
162 0, 0x7f0, { 0x00, 0xc0, 0x6c } },
163
164 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_EPSON_EEN10B,
165 PCMCIA_CIS_EPSON_EEN10B,
166 0, 0xff0, { 0x00, 0x00, 0x48 } },
167
168 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
169 PCMCIA_CIS_TAMARACK_ETHERNET,
170 0, -1, { 0x00, 0x00, 0x00 } },
171
172
173 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
174 PCMCIA_CIS_CNET_NE2000,
175 0, -1, { 0x00, 0x80, 0xad } },
176
177 { PCMCIA_VENDOR_ZONET, PCMCIA_PRODUCT_ZONET_ZEN,
178 PCMCIA_CIS_ZONET_ZEN,
179 0, -1, { 0x00, 0x00, 0x00 } },
180
181 /*
182 * You have to add new entries which contains
183 * PCMCIA_VENDOR_INVALID and/or PCMCIA_PRODUCT_INVALID
184 * in front of this comment.
185 *
186 * There are cards which use a generic vendor and product id but needs
187 * a different handling depending on the cis_info, so ne2000_match
188 * needs a table where the exceptions comes first and then the normal
189 * product and vendor entries.
190 */
191
192 { PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
193 PCMCIA_CIS_IBM_INFOMOVER,
194 0, 0x0ff0, { 0xff, 0xff, 0xff } },
195
196 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
197 PCMCIA_CIS_LINKSYS_ECARD_1,
198 0, -1, { 0x00, 0x80, 0xc8 } },
199
200 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
201 PCMCIA_CIS_PLANEX_FNW3600T,
202 0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_DL10019 },
203
204 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
205 PCMCIA_CIS_SVEC_PN650TX,
206 0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
207
208 /*
209 * This entry should be here so that above two cards doesn't
210 * match with this. FNW-3700T won't match above entries due to
211 * MAC address check.
212 */
213 { PCMCIA_VENDOR_LANTECH, PCMCIA_PRODUCT_LANTECH_FASTNETTX,
214 PCMCIA_CIS_LANTECH_FASTNETTX,
215 0, -1, { 0x00, 0x04, 0x1c }, NE2000DVF_AX88190 },
216
217 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
218 PCMCIA_CIS_PLANEX_FNW3700T,
219 0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_AX88190 },
220
221 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
222 PCMCIA_CIS_LINKSYS_ETHERFAST,
223 0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_DL10019 },
224
225 /*
226 * There are two entries for the DFE-670TXD because there are
227 * several possible Vendor IDs for the MAC address. Both are
228 * from D-Link, though.
229 *
230 * Oh, wait, there's a third possible vendor code, apparently.
231 * And it's from "ANI Communications" this time...
232 */
233 { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
234 PCMCIA_CIS_DLINK_DFE670TXD,
235 0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_DL10019 },
236
237 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
238 PCMCIA_CIS_MELCO_LPC2_TX,
239 0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_DL10019 },
240
241 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
242 PCMCIA_CIS_LINKSYS_COMBO_ECARD,
243 0, -1, { 0x00, 0x80, 0xc8 } },
244
245 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_TRUST_COMBO_ECARD,
246 PCMCIA_CIS_LINKSYS_TRUST_COMBO_ECARD,
247 0, 0x0120, { 0x20, 0x04, 0x49 } },
248
249 /* Although the comments above say to put VENDOR/PRODUCT INVALID IDs
250 above this list, we need to keep this one below the ECARD_1, or else
251 both will match the same more-generic entry rather than the more
252 specific one above with proper vendor and product IDs. */
253 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
254 PCMCIA_CIS_LINKSYS_ECARD_2,
255 0, -1, { 0x00, 0x80, 0xc8 } },
256
257 /*
258 * D-Link DE-650 has many minor versions:
259 *
260 * CIS information Manufacturer Product Note
261 * 1 "D-Link, DE-650" INVALID INVALID white card
262 * 2 "D-Link, DE-650, Ver 01.00" INVALID INVALID became bare metal
263 * 3 "D-Link, DE-650, Ver 01.00" 0x149 0x265 minor change in look
264 * 4 "D-Link, DE-650, Ver 01.00" 0x149 0x265 collision LED added
265 *
266 * While the 1st and the 2nd types should use the "D-Link DE-650" entry,
267 * the 3rd and the 4th types should use the "Linksys EtherCard" entry.
268 * Therefore, this enty must be below the LINKSYS_ECARD_1. --itohy
269 */
270 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
271 PCMCIA_CIS_DLINK_DE650,
272 0, 0x0040, { 0x00, 0x80, 0xc8 } },
273
274 /*
275 * IO-DATA PCLA/TE and later version of PCLA/T has valid
276 * vendor/product ID and it is possible to read MAC address
277 * using standard I/O ports. It also read from CIS offset 0x01c0.
278 * On the other hand, earlier version of PCLA/T doesn't have valid
279 * vendor/product ID and MAC address must be read from CIS offset
280 * 0x0ff0 (i.e., usual ne2000 way to read it doesn't work).
281 * And CIS information of earlier and later version of PCLA/T are
282 * same except fourth element. So, for now, we place the entry for
283 * PCLA/TE (and later version of PCLA/T) followed by entry
284 * for the earlier version of PCLA/T (or, modify to match all CIS
285 * information and have three or more individual entries).
286 */
287 { PCMCIA_VENDOR_IODATA, PCMCIA_PRODUCT_IODATA_PCLATE,
288 PCMCIA_CIS_IODATA_PCLATE,
289 0, -1, { 0x00, 0xa0, 0xb0 } },
290
291 /*
292 * This entry should be placed after above PCLA-TE entry.
293 * See above comments for detail.
294 */
295 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
296 PCMCIA_CIS_IODATA_PCLAT,
297 0, 0x0ff0, { 0x00, 0xa0, 0xb0 } },
298
299 { PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_1,
300 PCMCIA_CIS_DAYNA_COMMUNICARD_E_1,
301 0, 0x0110, { 0x00, 0x80, 0x19 } },
302
303 { PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_2,
304 PCMCIA_CIS_DAYNA_COMMUNICARD_E_2,
305 0, -1, { 0x00, 0x80, 0x19 } },
306
307 { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_T,
308 PCMCIA_CIS_COREGA_ETHER_PCC_T,
309 0, -1, { 0x00, 0x00, 0xf4 } },
310
311 { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_TD,
312 PCMCIA_CIS_COREGA_ETHER_PCC_TD,
313 0, -1, { 0x00, 0x00, 0xf4 } },
314
315 { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_TL,
316 PCMCIA_CIS_COREGA_ETHER_PCC_TL,
317 0, -1, { 0x00, 0x00, 0xf4 } },
318
319 { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_T,
320 PCMCIA_CIS_COREGA_ETHER_II_PCC_T,
321 0, -1, { 0x00, 0x00, 0xf4 } },
322
323 { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_TD,
324 PCMCIA_CIS_COREGA_ETHER_II_PCC_TD,
325 0, -1, { 0x00, 0x00, 0xf4 } },
326
327 { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FAST_ETHER_PCC_TX,
328 PCMCIA_CIS_COREGA_FAST_ETHER_PCC_TX,
329 0, -1, { 0x00, 0x00, 0xf4 }, NE2000DVF_DL10019 },
330
331 { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXF,
332 PCMCIA_CIS_COREGA_FETHER_PCC_TXF,
333 0, -1, { 0x00, 0x90, 0x99 }, NE2000DVF_DL10019 },
334
335 { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXD,
336 PCMCIA_CIS_COREGA_FETHER_PCC_TXD,
337 0, -1, { 0x00, 0x90, 0x99 } },
338
339 { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_II_PCC_TXD,
340 PCMCIA_CIS_COREGA_FETHER_II_PCC_TXD,
341 0, -1, { 0x00, 0x90, 0x99 }, NE2000DVF_AX88190 | NE2000DVF_AX88790 },
342
343 { PCMCIA_VENDOR_COMPEX, PCMCIA_PRODUCT_COMPEX_LINKPORT_ENET_B,
344 PCMCIA_CIS_COMPEX_LINKPORT_ENET_B,
345 0, 0x01c0, { 0x00, 0xa0, 0x0c } },
346
347 { PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_EZCARD,
348 PCMCIA_CIS_SMC_EZCARD,
349 0, 0x01c0, { 0x00, 0xe0, 0x29 } },
350
351 { PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_8041,
352 PCMCIA_CIS_SMC_8041,
353 0, -1, { 0x00, 0x04, 0xe2 } },
354
355 { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_EA_ETHER,
356 PCMCIA_CIS_SOCKET_EA_ETHER,
357 0, -1, { 0x00, 0xc0, 0x1b } },
358
359 { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER_CF,
360 PCMCIA_CIS_SOCKET_LP_ETHER_CF,
361 0, -1, { 0x00, 0xc0, 0x1b } },
362
363 { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETH_10_100_CF,
364 PCMCIA_CIS_SOCKET_LP_ETH_10_100_CF,
365 0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
366
367 { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER,
368 PCMCIA_CIS_SOCKET_LP_ETHER,
369 0, -1, { 0x00, 0xc0, 0x1b } },
370
371 { PCMCIA_VENDOR_KINGSTON, PCMCIA_PRODUCT_KINGSTON_KNE2,
372 PCMCIA_CIS_KINGSTON_KNE2,
373 0, -1, { 0x00, 0xc0, 0xf0 } },
374
375 { PCMCIA_VENDOR_XIRCOM, PCMCIA_PRODUCT_XIRCOM_CFE_10,
376 PCMCIA_CIS_XIRCOM_CFE_10,
377 0, -1, { 0x00, 0x10, 0xa4 } },
378
379 { PCMCIA_VENDOR_MELCO, PCMCIA_PRODUCT_MELCO_LPC3_TX,
380 PCMCIA_CIS_MELCO_LPC3_TX,
381 0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_AX88190 },
382
383 { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC3_CLT,
384 PCMCIA_CIS_BUFFALO_LPC3_CLT,
385 0, -1, { 0x00, 0x07, 0x40 } },
386
387 { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC4_CLX,
388 PCMCIA_CIS_BUFFALO_LPC4_CLX,
389 0, -1, { 0x00, 0x40, 0xfa }, NE2000DVF_AX88190 | NE2000DVF_AX88790 },
390
391 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
392 PCMCIA_CIS_BILLIONTON_LNT10TN,
393 0, -1, { 0x00, 0x00, 0x00 } },
394
395 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
396 PCMCIA_CIS_BILLIONTON_CFLT10N,
397 0, -1, { 0x00, 0x00, 0x00 } },
398
399 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
400 PCMCIA_CIS_NDC_ND5100_E,
401 0, -1, { 0x00, 0x80, 0xc6 } },
402
403 { PCMCIA_VENDOR_TELECOMDEVICE, PCMCIA_PRODUCT_TELECOMDEVICE_TCD_HPC100,
404 PCMCIA_CIS_TELECOMDEVICE_TCD_HPC100,
405 0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
406
407 { PCMCIA_VENDOR_MACNICA, PCMCIA_PRODUCT_MACNICA_ME1_JEIDA,
408 PCMCIA_CIS_MACNICA_ME1_JEIDA,
409 0, 0x00b8, { 0x08, 0x00, 0x42 } },
410
411 { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA411,
412 PCMCIA_CIS_NETGEAR_FA411,
413 0, -1, { 0x00, 0x40, 0xf4 } },
414
415 { PCMCIA_VENDOR_DYNALINK, PCMCIA_PRODUCT_DYNALINK_L10C,
416 PCMCIA_CIS_DYNALINK_L10C,
417 0, -1, { 0x00, 0x00, 0x00 } },
418
419 #if 0
420 /* the rest of these are stolen from the linux pcnet pcmcia device
421 driver. Since I don't know the manfid or cis info strings for
422 any of them, they're not compiled in until I do. */
423 { "APEX MultiCard",
424 0x0000, 0x0000, NULL, NULL, 0,
425 0x03f4, { 0x00, 0x20, 0xe5 } },
426 { "ASANTE FriendlyNet",
427 0x0000, 0x0000, NULL, NULL, 0,
428 0x4910, { 0x00, 0x00, 0x94 } },
429 { "Danpex EN-6200P2",
430 0x0000, 0x0000, NULL, NULL, 0,
431 0x0110, { 0x00, 0x40, 0xc7 } },
432 { "DataTrek NetCard",
433 0x0000, 0x0000, NULL, NULL, 0,
434 0x0ff0, { 0x00, 0x20, 0xe8 } },
435 { "Dayna CommuniCard E",
436 0x0000, 0x0000, NULL, NULL, 0,
437 0x0110, { 0x00, 0x80, 0x19 } },
438 { "EP-210 Ethernet",
439 0x0000, 0x0000, NULL, NULL, 0,
440 0x0110, { 0x00, 0x40, 0x33 } },
441 { "ELECOM Laneed LD-CDWA",
442 0x0000, 0x0000, NULL, NULL, 0,
443 0x00b8, { 0x08, 0x00, 0x42 } },
444 { "Grey Cell GCS2220",
445 0x0000, 0x0000, NULL, NULL, 0,
446 0x0000, { 0x00, 0x47, 0x43 } },
447 { "Hypertec Ethernet",
448 0x0000, 0x0000, NULL, NULL, 0,
449 0x01c0, { 0x00, 0x40, 0x4c } },
450 { "IBM CCAE",
451 0x0000, 0x0000, NULL, NULL, 0,
452 0x0ff0, { 0x08, 0x00, 0x5a } },
453 { "IBM CCAE",
454 0x0000, 0x0000, NULL, NULL, 0,
455 0x0ff0, { 0x00, 0x04, 0xac } },
456 { "IBM CCAE",
457 0x0000, 0x0000, NULL, NULL, 0,
458 0x0ff0, { 0x00, 0x06, 0x29 } },
459 { "IBM FME",
460 0x0000, 0x0000, NULL, NULL, 0,
461 0x0374, { 0x00, 0x04, 0xac } },
462 { "IBM FME",
463 0x0000, 0x0000, NULL, NULL, 0,
464 0x0374, { 0x08, 0x00, 0x5a } },
465 { "Katron PE-520",
466 0x0000, 0x0000, NULL, NULL, 0,
467 0x0110, { 0x00, 0x40, 0xf6 } },
468 { "Kingston KNE-PCM/x",
469 0x0000, 0x0000, NULL, NULL, 0,
470 0x0ff0, { 0x00, 0xc0, 0xf0 } },
471 { "Kingston KNE-PCM/x",
472 0x0000, 0x0000, NULL, NULL, 0,
473 0x0ff0, { 0xe2, 0x0c, 0x0f } },
474 { "Longshine LCS-8534",
475 0x0000, 0x0000, NULL, NULL, 0,
476 0x0000, { 0x08, 0x00, 0x00 } },
477 { "Maxtech PCN2000",
478 0x0000, 0x0000, NULL, NULL, 0,
479 0x5000, { 0x00, 0x00, 0xe8 } },
480 { "NDC Instant-Link",
481 0x0000, 0x0000, NULL, NULL, 0,
482 0x003a, { 0x00, 0x80, 0xc6 } },
483 { "NE2000 Compatible",
484 0x0000, 0x0000, NULL, NULL, 0,
485 0x0ff0, { 0x00, 0xa0, 0x0c } },
486 { "Network General Sniffer",
487 0x0000, 0x0000, NULL, NULL, 0,
488 0x0ff0, { 0x00, 0x00, 0x65 } },
489 { "Panasonic VEL211",
490 0x0000, 0x0000, NULL, NULL, 0,
491 0x0ff0, { 0x00, 0x80, 0x45 } },
492 { "SCM Ethernet",
493 0x0000, 0x0000, NULL, NULL, 0,
494 0x0ff0, { 0x00, 0x20, 0xcb } },
495 { "Volktek NPL-402CT",
496 0x0000, 0x0000, NULL, NULL, 0,
497 0x0060, { 0x00, 0x40, 0x05 } },
498 #endif
499
500 { PCMCIA_VENDOR_ALLIEDTELESIS, PCMCIA_PRODUCT_ALLIEDTELESIS_LA_PCM,
501 PCMCIA_CIS_ALLIEDTELESIS_LA_PCM,
502 0, 0x0ff0, { 0x00, 0x00, 0xf4 } },
503 };
504
505 #define NE2000_NDEVS (sizeof(ne2000devs) / sizeof(ne2000devs[0]))
506
507 #define ne2000_match(card, fct, n) \
508 ((((((card)->manufacturer != PCMCIA_VENDOR_INVALID) && \
509 ((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
510 ((card)->product != PCMCIA_PRODUCT_INVALID) && \
511 ((card)->product == ne2000devs[(n)].product)) || \
512 ((ne2000devs[(n)].cis_info[0]) && (ne2000devs[(n)].cis_info[1]) && \
513 (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis_info[0]) == 0) && \
514 (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis_info[1]) == 0))) && \
515 ((fct) == ne2000devs[(n)].function))? \
516 &ne2000devs[(n)]:NULL)
517
518 int
519 ne_pcmcia_match(parent, match, aux)
520 struct device *parent;
521 struct cfdata *match;
522 void *aux;
523 {
524 struct pcmcia_attach_args *pa = aux;
525 int i;
526
527 for (i = 0; i < NE2000_NDEVS; i++) {
528 if (ne2000_match(pa->card, pa->pf->number, i))
529 return (1);
530 }
531
532 return (0);
533 }
534
535 void
536 ne_pcmcia_attach(parent, self, aux)
537 struct device *parent, *self;
538 void *aux;
539 {
540 struct ne_pcmcia_softc *psc = (void *) self;
541 struct ne2000_softc *nsc = &psc->sc_ne2000;
542 struct dp8390_softc *dsc = &nsc->sc_dp8390;
543 struct pcmcia_attach_args *pa = aux;
544 struct pcmcia_config_entry *cfe;
545 const struct ne2000dev *ne_dev;
546 int i;
547 u_int8_t myea[6], *enaddr;
548 const char *typestr = "";
549
550 psc->sc_pf = pa->pf;
551
552 SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
553 #if 0
554 /*
555 * Some ne2000 driver's claim to have memory; others don't.
556 * Since I don't care, I don't check.
557 */
558
559 if (cfe->num_memspace != 1) {
560 printf(": unexpected number of memory spaces "
561 " %d should be 1\n", cfe->num_memspace);
562 continue;
563 }
564 #endif
565
566 if (cfe->num_iospace == 1) {
567 if (cfe->iospace[0].length != NE2000_NPORTS) {
568 printf(": unexpected I/O space configuration"
569 " (continued)\n%s", dsc->sc_dev.dv_xname);
570 /* XXX really safe for all other cards? */
571 }
572 } else if (cfe->num_iospace == 2) {
573 /*
574 * Some cards report a separate space for NIC and ASIC.
575 * This make some sense, but we must allocate a single
576 * NE2000_NPORTS-sized chunk, due to brain damaged
577 * address decoders on some of these cards.
578 */
579 if (cfe->iospace[0].length + cfe->iospace[1].length !=
580 NE2000_NPORTS) {
581 #ifdef DIAGNOSTIC
582 printf(": unexpected I/O "
583 "space configuration; ignored\n%s",
584 dsc->sc_dev.dv_xname);
585 #endif
586 continue;
587 }
588 } else {
589 #ifdef DIAGNOSTIC
590 printf(": unexpected number of i/o spaces %d"
591 " should be 1 or 2; ignored\n%s",
592 cfe->num_iospace, dsc->sc_dev.dv_xname);
593 #endif
594 continue;
595 }
596
597 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
598 NE2000_NPORTS, NE2000_NPORTS, &psc->sc_pcioh)) {
599 #ifdef DIAGNOSTIC
600 printf(": can't allocate i/o space %lx; ignored\n%s",
601 cfe->iospace[0].start, dsc->sc_dev.dv_xname);
602 #endif
603 continue;
604 }
605
606 /* Ok, found. */
607 break;
608 }
609
610 if (cfe == NULL) {
611 printf(": no suitable config entry\n");
612 goto fail_1;
613 }
614
615 dsc->sc_regt = psc->sc_pcioh.iot;
616 dsc->sc_regh = psc->sc_pcioh.ioh;
617
618 nsc->sc_asict = psc->sc_pcioh.iot;
619 if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
620 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
621 &nsc->sc_asich)) {
622 printf(": can't get subregion for asic\n");
623 goto fail_2;
624 }
625
626 /* Set up power management hooks. */
627 dsc->sc_enable = ne_pcmcia_enable;
628 dsc->sc_disable = ne_pcmcia_disable;
629
630 /* Enable the card. */
631 pcmcia_function_init(pa->pf, cfe);
632 if (pcmcia_function_enable(pa->pf)) {
633 printf(": function enable failed\n");
634 goto fail_2;
635 }
636
637 /* some cards claim to be io16, but they're lying. */
638 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
639 NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
640 &psc->sc_pcioh, &psc->sc_nic_io_window)) {
641 printf(": can't map NIC i/o space\n");
642 goto fail_3;
643 }
644
645 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
646 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
647 &psc->sc_pcioh, &psc->sc_asic_io_window)) {
648 printf(": can't map ASIC i/o space\n");
649 goto fail_4;
650 }
651
652 printf("\n");
653
654 /*
655 * Read the station address from the board.
656 */
657 i = 0;
658 again:
659 enaddr = NULL; /* Ask ASIC by default */
660 typestr = ""; /* clear previous card-type */
661 for (; i < NE2000_NDEVS; i++) {
662 ne_dev = ne2000_match(pa->card, pa->pf->number, i);
663 if (ne_dev != NULL) {
664 if (ne_dev->enet_maddr >= 0) {
665 enaddr = ne_pcmcia_get_enaddr(psc,
666 ne_dev->enet_maddr, myea);
667 if (enaddr == NULL)
668 continue;
669 }
670 goto found;
671 }
672 }
673 printf("%s (manf %08x prod %08x) cis %s %s: "
674 "can't match ethernet vendor code\n",
675 dsc->sc_dev.dv_xname,
676 pa->manufacturer, pa->product,
677 pa->card->cis1_info[0], pa->card->cis1_info[1]);
678 if (enaddr != NULL)
679 aprint_error("%s: ethernet vendor code %02x:%02x:%02x\n",
680 dsc->sc_dev.dv_xname, enaddr[0], enaddr[1], enaddr[2]);
681 goto fail_5;
682
683 found:
684 if ((ne_dev->flags & NE2000DVF_DL10019) != 0) {
685 u_int8_t type;
686
687 enaddr = ne_pcmcia_dl10019_get_enaddr(psc, myea);
688 if (enaddr == NULL) {
689 ++i;
690 goto again;
691 }
692
693 dsc->sc_mediachange = dl10019_mediachange;
694 dsc->sc_mediastatus = dl10019_mediastatus;
695 dsc->init_card = dl10019_init_card;
696 dsc->stop_card = dl10019_stop_card;
697 dsc->sc_media_init = dl10019_media_init;
698 dsc->sc_media_fini = dl10019_media_fini;
699
700 /* Determine if this is a DL10019 or a DL10022. */
701 type = bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 0x0f);
702 if (type == 0x91 || type == 0x99) {
703 nsc->sc_type = NE2000_TYPE_DL10022;
704 typestr = " (DL10022)";
705 } else {
706 nsc->sc_type = NE2000_TYPE_DL10019;
707 typestr = " (DL10019)";
708 }
709 }
710
711 if ((ne_dev->flags & NE2000DVF_AX88190) != 0) {
712 if (ne_pcmcia_ax88190_set_iobase(psc)) {
713 ++i;
714 goto again;
715 }
716
717 dsc->sc_mediachange = ax88190_mediachange;
718 dsc->sc_mediastatus = ax88190_mediastatus;
719 dsc->init_card = ax88190_init_card;
720 dsc->stop_card = ax88190_stop_card;
721 dsc->sc_media_init = ax88190_media_init;
722 dsc->sc_media_fini = ax88190_media_fini;
723
724 if ((ne_dev->flags & NE2000DVF_AX88790) != 0) {
725 nsc->sc_type = NE2000_TYPE_AX88790;
726 typestr = " (AX88790)";
727 } else {
728 nsc->sc_type = NE2000_TYPE_AX88190;
729 typestr = " (AX88190)";
730 }
731 }
732
733 if (enaddr != NULL &&
734 ne_dev->enet_vendor[0] != 0xff) {
735 /*
736 * Make sure this is what we expect.
737 */
738 if (enaddr[0] != ne_dev->enet_vendor[0] ||
739 enaddr[1] != ne_dev->enet_vendor[1] ||
740 enaddr[2] != ne_dev->enet_vendor[2]) {
741 ++i;
742 goto again;
743 }
744 }
745
746 /*
747 * Check for a Realtek 8019.
748 */
749 if (nsc->sc_type == 0) {
750 bus_space_write_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CR,
751 ED_CR_PAGE_0 | ED_CR_STP);
752 if (bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
753 NERTL_RTL0_8019ID0) == RTL0_8019ID0 &&
754 bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
755 NERTL_RTL0_8019ID1) == RTL0_8019ID1) {
756 typestr = " (RTL8019)";
757 dsc->sc_mediachange = rtl80x9_mediachange;
758 dsc->sc_mediastatus = rtl80x9_mediastatus;
759 dsc->init_card = rtl80x9_init_card;
760 dsc->sc_media_init = rtl80x9_media_init;
761 }
762 }
763
764 aprint_normal("%s: <%s, %s> <%04x, %04x>%s\n",
765 dsc->sc_dev.dv_xname,
766 pa->card->cis1_info[0] ?: "",
767 pa->card->cis1_info[1] ?: "",
768 pa->manufacturer, pa->product, typestr);
769
770 if (ne2000_attach(nsc, enaddr))
771 goto fail_5;
772
773 pcmcia_function_disable(pa->pf);
774 return;
775
776 fail_5:
777 /* Unmap ASIC i/o windows. */
778 pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
779
780 fail_4:
781 /* Unmap NIC i/o windows. */
782 pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
783
784 fail_3:
785 pcmcia_function_disable(pa->pf);
786
787 fail_2:
788 /* Free our i/o space. */
789 pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
790
791 fail_1:
792 psc->sc_nic_io_window = -1;
793 }
794
795 int
796 ne_pcmcia_detach(self, flags)
797 struct device *self;
798 int flags;
799 {
800 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)self;
801 int error;
802
803 if (psc->sc_nic_io_window == -1)
804 /* Nothing to detach. */
805 return (0);
806
807 error = ne2000_detach(&psc->sc_ne2000, flags);
808 if (error != 0)
809 return (error);
810
811 /* Unmap our i/o windows. */
812 pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
813 pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
814
815 /* Free our i/o space. */
816 pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
817
818 return (0);
819 }
820
821 int
822 ne_pcmcia_enable(dsc)
823 struct dp8390_softc *dsc;
824 {
825 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
826 struct ne2000_softc *nsc = &psc->sc_ne2000;
827 struct pcmcia_mem_handle pcmh;
828
829 /* set up the interrupt */
830 psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
831 dsc);
832 if (psc->sc_ih == NULL) {
833 printf("%s: couldn't establish interrupt\n",
834 dsc->sc_dev.dv_xname);
835 goto fail_1;
836 }
837
838 if (pcmcia_function_enable(psc->sc_pf))
839 goto fail_2;
840
841 if (nsc->sc_type == NE2000_TYPE_AX88190 ||
842 nsc->sc_type == NE2000_TYPE_AX88790) {
843 if (ne_pcmcia_ax88190_set_iobase(psc))
844 goto fail_3;
845 if (nsc->sc_type == NE2000_TYPE_AX88790) {
846 bus_size_t offset;
847 int mwindow;
848
849 if (pcmcia_mem_alloc(psc->sc_pf,
850 AX88790_CSR_SIZE, &pcmh)) {
851 printf("%s: can't alloc mem for CSR\n",
852 dsc->sc_dev.dv_xname);
853 goto fail_3;
854 }
855
856 if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
857 AX88790_CSR, AX88790_CSR_SIZE,
858 &pcmh, &offset, &mwindow)) {
859 printf("%s: can't map mem for CSR\n",
860 dsc->sc_dev.dv_xname);
861 goto fail_4;
862 }
863
864 bus_space_write_1(pcmh.memt, pcmh.memh, offset, 0x4);
865 pcmcia_mem_unmap(psc->sc_pf, mwindow);
866 pcmcia_mem_free(psc->sc_pf, &pcmh);
867 }
868 }
869
870 return (0);
871
872 fail_4:
873 pcmcia_mem_free(psc->sc_pf, &pcmh);
874 fail_3:
875 pcmcia_function_disable(psc->sc_pf);
876 fail_2:
877 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
878 fail_1:
879 return (1);
880 }
881
882 void
883 ne_pcmcia_disable(dsc)
884 struct dp8390_softc *dsc;
885 {
886 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
887
888 pcmcia_function_disable(psc->sc_pf);
889 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
890 }
891
892 u_int8_t *
893 ne_pcmcia_get_enaddr(psc, maddr, myea)
894 struct ne_pcmcia_softc *psc;
895 int maddr;
896 u_int8_t myea[ETHER_ADDR_LEN];
897 {
898 struct ne2000_softc *nsc = &psc->sc_ne2000;
899 struct dp8390_softc *dsc = &nsc->sc_dp8390;
900 struct pcmcia_mem_handle pcmh;
901 bus_size_t offset;
902 u_int8_t *enaddr = NULL;
903 int j, mwindow;
904
905 if (maddr < 0)
906 return (NULL);
907
908 if (pcmcia_mem_alloc(psc->sc_pf, ETHER_ADDR_LEN * 2, &pcmh)) {
909 printf("%s: can't alloc mem for enet addr\n",
910 dsc->sc_dev.dv_xname);
911 goto fail_1;
912 }
913 if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, maddr,
914 ETHER_ADDR_LEN * 2, &pcmh, &offset, &mwindow)) {
915 printf("%s: can't map mem for enet addr\n",
916 dsc->sc_dev.dv_xname);
917 goto fail_2;
918 }
919 for (j = 0; j < ETHER_ADDR_LEN; j++)
920 myea[j] = bus_space_read_1(pcmh.memt, pcmh.memh,
921 offset + (j * 2));
922 enaddr = myea;
923
924 pcmcia_mem_unmap(psc->sc_pf, mwindow);
925 fail_2:
926 pcmcia_mem_free(psc->sc_pf, &pcmh);
927 fail_1:
928 return (enaddr);
929 }
930
931 u_int8_t *
932 ne_pcmcia_dl10019_get_enaddr(psc, myea)
933 struct ne_pcmcia_softc *psc;
934 u_int8_t myea[ETHER_ADDR_LEN];
935 {
936 struct ne2000_softc *nsc = &psc->sc_ne2000;
937 u_int8_t sum;
938 int j;
939
940 #define PAR0 0x04
941 for (j = 0, sum = 0; j < 8; j++)
942 sum += bus_space_read_1(nsc->sc_asict, nsc->sc_asich,
943 PAR0 + j);
944 if (sum != 0xff)
945 return (NULL);
946 for (j = 0; j < ETHER_ADDR_LEN; j++)
947 myea[j] = bus_space_read_1(nsc->sc_asict,
948 nsc->sc_asich, PAR0 + j);
949 #undef PAR0
950 return (myea);
951 }
952
953 int
954 ne_pcmcia_ax88190_set_iobase(psc)
955 struct ne_pcmcia_softc *psc;
956 {
957 struct ne2000_softc *nsc = &psc->sc_ne2000;
958 struct dp8390_softc *dsc = &nsc->sc_dp8390;
959 struct pcmcia_mem_handle pcmh;
960 bus_size_t offset;
961 int rv = 1, mwindow;
962 u_int last_liobase, new_liobase;
963
964 if (pcmcia_mem_alloc(psc->sc_pf, AX88190_LAN_IOSIZE, &pcmh)) {
965 #if 0
966 printf("%s: can't alloc mem for LAN iobase\n",
967 dsc->sc_dev.dv_xname);
968 #endif
969 goto fail_1;
970 }
971 if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
972 AX88190_LAN_IOBASE, AX88190_LAN_IOSIZE,
973 &pcmh, &offset, &mwindow)) {
974 printf("%s: can't map mem for LAN iobase\n",
975 dsc->sc_dev.dv_xname);
976 goto fail_2;
977 }
978
979 last_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
980 (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
981 #ifdef DIAGNOSTIC
982 printf("%s: LAN iobase 0x%x (0x%x) ->", dsc->sc_dev.dv_xname,
983 last_liobase, (u_int)psc->sc_pcioh.addr);
984 #endif
985 bus_space_write_1(pcmh.memt, pcmh.memh, offset,
986 psc->sc_pcioh.addr & 0xff);
987 bus_space_write_1(pcmh.memt, pcmh.memh, offset + 2,
988 psc->sc_pcioh.addr >> 8);
989
990 new_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
991 (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
992 #ifdef DIAGNOSTIC
993 printf(" 0x%x\n", new_liobase);
994 #endif
995 if ((last_liobase == psc->sc_pcioh.addr)
996 || (last_liobase != new_liobase))
997 rv = 0;
998
999 pcmcia_mem_unmap(psc->sc_pf, mwindow);
1000 fail_2:
1001 pcmcia_mem_free(psc->sc_pf, &pcmh);
1002 fail_1:
1003 return (rv);
1004 }
1005