if_ne_pcmcia.c revision 1.70.2.5 1 /* $NetBSD: if_ne_pcmcia.c,v 1.70.2.5 2002/01/08 00:31:24 nathanw 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.70.2.5 2002/01/08 00:31:24 nathanw 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 struct cfattach ne_pcmcia_ca = {
94 sizeof(struct ne_pcmcia_softc), ne_pcmcia_match, ne_pcmcia_attach,
95 ne_pcmcia_detach, dp8390_activate
96 };
97
98 static const struct ne2000dev {
99 char *name;
100 int32_t manufacturer;
101 int32_t product;
102 char *cis_info[4];
103 int function;
104 int enet_maddr;
105 unsigned char enet_vendor[3];
106 int flags;
107 #define NE2000DVF_DL10019 0x0001 /* chip is D-Link DL10019 */
108 #define NE2000DVF_AX88190 0x0002 /* chip is ASIX AX88190 */
109 } ne2000devs[] = {
110 { PCMCIA_STR_SYNERGY21_S21810,
111 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
112 PCMCIA_CIS_SYNERGY21_S21810,
113 0, -1, { 0x00, 0x48, 0x54 } },
114
115 { PCMCIA_STR_AMBICOM_AMB8002T,
116 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
117 PCMCIA_CIS_AMBICOM_AMB8002T,
118 0, -1, { 0x00, 0x10, 0x7a } },
119
120 { PCMCIA_STR_PREMAX_PE200,
121 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
122 PCMCIA_CIS_PREMAX_PE200,
123 0, 0x07f0, { 0x00, 0x20, 0xe0 } },
124
125 { PCMCIA_STR_DIGITAL_DEPCMXX,
126 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
127 PCMCIA_CIS_DIGITAL_DEPCMXX,
128 0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
129
130 { PCMCIA_STR_PLANET_SMARTCOM2000,
131 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
132 PCMCIA_CIS_PLANET_SMARTCOM2000,
133 0, 0xff0, { 0x00, 0x00, 0xe8 } },
134
135 { PCMCIA_STR_DLINK_DE660,
136 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
137 PCMCIA_CIS_DLINK_DE660,
138 0, -1, { 0x00, 0x80, 0xc8 } },
139
140 { PCMCIA_STR_DLINK_DE660PLUS,
141 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
142 PCMCIA_CIS_DLINK_DE660PLUS,
143 0, -1, { 0x00, 0x80, 0xc8 } },
144
145 { PCMCIA_STR_RPTI_EP400,
146 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
147 PCMCIA_CIS_RPTI_EP400,
148 0, -1, { 0x00, 0x40, 0x95 } },
149
150 { PCMCIA_STR_RPTI_EP401,
151 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
152 PCMCIA_CIS_RPTI_EP401,
153 0, -1, { 0x00, 0x40, 0x95 } },
154
155 { PCMCIA_STR_ACCTON_EN2212,
156 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
157 PCMCIA_CIS_ACCTON_EN2212,
158 0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
159
160 { PCMCIA_STR_SVEC_COMBOCARD,
161 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
162 PCMCIA_CIS_SVEC_COMBOCARD,
163 0, -1, { 0x00, 0xe0, 0x98 } },
164
165 { PCMCIA_STR_SVEC_LANCARD,
166 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
167 PCMCIA_CIS_SVEC_LANCARD,
168 0, 0x7f0, { 0x00, 0xc0, 0x6c } },
169
170 { PCMCIA_STR_EPSON_EEN10B,
171 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_EPSON_EEN10B,
172 PCMCIA_CIS_EPSON_EEN10B,
173 0, 0xff0, { 0x00, 0x00, 0x48 } },
174
175 { PCMCIA_STR_CNET_NE2000,
176 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
177 PCMCIA_CIS_CNET_NE2000,
178 0, -1, { 0x00, 0x80, 0xad } },
179
180 { PCMCIA_STR_ZONET_ZEN,
181 PCMCIA_VENDOR_ZONET, PCMCIA_PRODUCT_ZONET_ZEN,
182 PCMCIA_CIS_ZONET_ZEN,
183 0, -1, { 0x00, 0x00, 0x00 } },
184
185 /*
186 * You have to add new entries which contains
187 * PCMCIA_VENDOR_INVALID and/or PCMCIA_PRODUCT_INVALID
188 * in front of this comment.
189 *
190 * There are cards which use a generic vendor and product id but needs
191 * a different handling depending on the cis_info, so ne2000_match
192 * needs a table where the exceptions comes first and then the normal
193 * product and vendor entries.
194 */
195
196 { PCMCIA_STR_IBM_INFOMOVER,
197 PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
198 PCMCIA_CIS_IBM_INFOMOVER,
199 0, 0x0ff0, { 0x08, 0x00, 0x5a } },
200
201 { PCMCIA_STR_IBM_INFOMOVER,
202 PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
203 PCMCIA_CIS_IBM_INFOMOVER,
204 0, 0x0ff0, { 0x00, 0x04, 0xac } },
205
206 { PCMCIA_STR_IBM_INFOMOVER,
207 PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
208 PCMCIA_CIS_IBM_INFOMOVER,
209 0, 0x0ff0, { 0x00, 0x06, 0x29 } },
210
211 { PCMCIA_STR_LINKSYS_ECARD_1,
212 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
213 PCMCIA_CIS_LINKSYS_ECARD_1,
214 0, -1, { 0x00, 0x80, 0xc8 } },
215
216 { PCMCIA_STR_PLANEX_FNW3600T,
217 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
218 PCMCIA_CIS_PLANEX_FNW3600T,
219 0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_DL10019 },
220
221 { PCMCIA_STR_SVEC_PN650TX,
222 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
223 PCMCIA_CIS_SVEC_PN650TX,
224 0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
225
226 /*
227 * This entry should be here so that above two cards doesn't
228 * match with this. FNW-3700T won't match above entries due to
229 * MAC address check.
230 */
231 { PCMCIA_STR_PLANEX_FNW3700T,
232 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
233 PCMCIA_CIS_PLANEX_FNW3700T,
234 0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_AX88190 },
235
236 { PCMCIA_STR_LINKSYS_ETHERFAST,
237 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
238 PCMCIA_CIS_LINKSYS_ETHERFAST,
239 0, -1, { 0x00, 0x80, 0xc8 }, NE2000DVF_DL10019 },
240
241 { PCMCIA_STR_LINKSYS_ETHERFAST,
242 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
243 PCMCIA_CIS_LINKSYS_ETHERFAST,
244 0, -1, { 0x00, 0x90, 0xfe }, NE2000DVF_DL10019 },
245
246 { PCMCIA_STR_DLINK_DE650,
247 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
248 PCMCIA_CIS_DLINK_DE650,
249 0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
250
251 { PCMCIA_STR_MELCO_LPC2_TX,
252 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
253 PCMCIA_CIS_MELCO_LPC2_TX,
254 0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_DL10019 },
255
256 { PCMCIA_STR_LINKSYS_COMBO_ECARD,
257 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
258 PCMCIA_CIS_LINKSYS_COMBO_ECARD,
259 0, -1, { 0x00, 0x80, 0xc8 } },
260
261 { PCMCIA_STR_LINKSYS_TRUST_COMBO_ECARD,
262 PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_TRUST_COMBO_ECARD,
263 PCMCIA_CIS_LINKSYS_TRUST_COMBO_ECARD,
264 0, 0x0120, { 0x20, 0x04, 0x49 } },
265
266 /* Although the comments above say to put VENDOR/PRODUCT INVALID IDs
267 above this list, we need to keep this one below the ECARD_1, or else
268 both will match the same more-generic entry rather than the more
269 specific one above with proper vendor and product IDs. */
270 { PCMCIA_STR_LINKSYS_ECARD_2,
271 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
272 PCMCIA_CIS_LINKSYS_ECARD_2,
273 0, -1, { 0x00, 0x80, 0xc8 } },
274
275 /*
276 * D-Link DE-650 has many minor versions:
277 *
278 * CIS information Manufacturer Product Note
279 * 1 "D-Link, DE-650" INVALID INVALID white card
280 * 2 "D-Link, DE-650, Ver 01.00" INVALID INVALID became bare metal
281 * 3 "D-Link, DE-650, Ver 01.00" 0x149 0x265 minor change in look
282 * 4 "D-Link, DE-650, Ver 01.00" 0x149 0x265 collision LED added
283 *
284 * While the 1st and the 2nd types should use the "D-Link DE-650" entry,
285 * the 3rd and the 4th types should use the "Linksys EtherCard" entry.
286 * Therefore, this enty must be below the LINKSYS_ECARD_1. --itohy
287 */
288 { PCMCIA_STR_DLINK_DE650,
289 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
290 PCMCIA_CIS_DLINK_DE650,
291 0, 0x0040, { 0x00, 0x80, 0xc8 } },
292
293 /*
294 * IO-DATA PCLA/TE and later version of PCLA/T has valid
295 * vendor/product ID and it is possible to read MAC address
296 * using standard I/O ports. It also read from CIS offset 0x01c0.
297 * On the other hand, earlier version of PCLA/T doesn't have valid
298 * vendor/product ID and MAC address must be read from CIS offset
299 * 0x0ff0 (i.e., usual ne2000 way to read it doesn't work).
300 * And CIS information of earlier and later version of PCLA/T are
301 * same except fourth element. So, for now, we place the entry for
302 * PCLA/TE (and later version of PCLA/T) followed by entry
303 * for the earlier version of PCLA/T (or, modify to match all CIS
304 * information and have three or more individual entries).
305 */
306 { PCMCIA_STR_IODATA_PCLATE,
307 PCMCIA_VENDOR_IODATA, PCMCIA_PRODUCT_IODATA_PCLATE,
308 PCMCIA_CIS_IODATA_PCLATE,
309 0, -1, { 0x00, 0xa0, 0xb0 } },
310
311 /*
312 * This entry should be placed after above PCLA-TE entry.
313 * See above comments for detail.
314 */
315 { PCMCIA_STR_IODATA_PCLAT,
316 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
317 PCMCIA_CIS_IODATA_PCLAT,
318 0, 0x0ff0, { 0x00, 0xa0, 0xb0 } },
319
320 { PCMCIA_STR_DAYNA_COMMUNICARD_E_1,
321 PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_1,
322 PCMCIA_CIS_DAYNA_COMMUNICARD_E_1,
323 0, 0x0110, { 0x00, 0x80, 0x19 } },
324
325 { PCMCIA_STR_DAYNA_COMMUNICARD_E_2,
326 PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_2,
327 PCMCIA_CIS_DAYNA_COMMUNICARD_E_2,
328 0, -1, { 0x00, 0x80, 0x19 } },
329
330 { PCMCIA_STR_COREGA_ETHER_PCC_T,
331 PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_T,
332 PCMCIA_CIS_COREGA_ETHER_PCC_T,
333 0, -1, { 0x00, 0x00, 0xf4 } },
334
335 { PCMCIA_STR_COREGA_ETHER_PCC_TD,
336 PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_TD,
337 PCMCIA_CIS_COREGA_ETHER_PCC_TD,
338 0, -1, { 0x00, 0x00, 0xf4 } },
339
340 { PCMCIA_STR_COREGA_ETHER_II_PCC_T,
341 PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_T,
342 PCMCIA_CIS_COREGA_ETHER_II_PCC_T,
343 0, -1, { 0x00, 0x00, 0xf4 } },
344
345 { PCMCIA_STR_COREGA_FAST_ETHER_PCC_TX,
346 PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FAST_ETHER_PCC_TX,
347 PCMCIA_CIS_COREGA_FAST_ETHER_PCC_TX,
348 0, -1, { 0x00, 0x00, 0xf4 }, NE2000DVF_DL10019 },
349
350 { PCMCIA_STR_COREGA_FETHER_PCC_TXF,
351 PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXF,
352 PCMCIA_CIS_COREGA_FETHER_PCC_TXF,
353 0, -1, { 0x00, 0x90, 0x99 }, NE2000DVF_DL10019 },
354
355 { PCMCIA_STR_COREGA_FETHER_PCC_TXD,
356 PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXD,
357 PCMCIA_CIS_COREGA_FETHER_PCC_TXD,
358 0, -1, { 0x00, 0x90, 0x99 } },
359
360 { PCMCIA_STR_COMPEX_LINKPORT_ENET_B,
361 PCMCIA_VENDOR_COMPEX, PCMCIA_PRODUCT_COMPEX_LINKPORT_ENET_B,
362 PCMCIA_CIS_COMPEX_LINKPORT_ENET_B,
363 0, 0x01c0, { 0x00, 0xa0, 0x0c } },
364
365 { PCMCIA_STR_SMC_EZCARD,
366 PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_EZCARD,
367 PCMCIA_CIS_SMC_EZCARD,
368 0, 0x01c0, { 0x00, 0xe0, 0x29 } },
369
370 { PCMCIA_STR_SOCKET_EA_ETHER,
371 PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_EA_ETHER,
372 PCMCIA_CIS_SOCKET_EA_ETHER,
373 0, -1, { 0x00, 0xc0, 0x1b } },
374
375 { PCMCIA_STR_SOCKET_LP_ETHER_CF,
376 PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER_CF,
377 PCMCIA_CIS_SOCKET_LP_ETHER_CF,
378 0, -1, { 0x00, 0xc0, 0x1b } },
379
380 { PCMCIA_STR_SOCKET_LP_ETHER,
381 PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER,
382 PCMCIA_CIS_SOCKET_LP_ETHER,
383 0, -1, { 0x00, 0xc0, 0x1b } },
384
385 { PCMCIA_STR_KINGSTON_KNE2,
386 PCMCIA_VENDOR_KINGSTON, PCMCIA_PRODUCT_KINGSTON_KNE2,
387 PCMCIA_CIS_KINGSTON_KNE2,
388 0, -1, { 0x00, 0xc0, 0xf0 } },
389
390 { PCMCIA_STR_XIRCOM_CFE_10,
391 PCMCIA_VENDOR_XIRCOM, PCMCIA_PRODUCT_XIRCOM_CFE_10,
392 PCMCIA_CIS_XIRCOM_CFE_10,
393 0, -1, { 0x00, 0x10, 0xa4 } },
394
395 { PCMCIA_STR_MELCO_LPC3_TX,
396 PCMCIA_VENDOR_MELCO, PCMCIA_PRODUCT_MELCO_LPC3_TX,
397 PCMCIA_CIS_MELCO_LPC3_TX,
398 0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
399
400 { PCMCIA_STR_BILLIONTON_LNT10TN,
401 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
402 PCMCIA_CIS_BILLIONTON_LNT10TN,
403 0, -1, { 0x00, 0x00, 0x00 } },
404
405 { PCMCIA_STR_NDC_ND5100_E,
406 PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
407 PCMCIA_CIS_NDC_ND5100_E,
408 0, -1, { 0x00, 0x80, 0xc6 } },
409
410 { PCMCIA_STR_TELECOMDEVICE_TCD_HPC100,
411 PCMCIA_VENDOR_TELECOMDEVICE, PCMCIA_PRODUCT_TELECOMDEVICE_TCD_HPC100,
412 PCMCIA_CIS_TELECOMDEVICE_TCD_HPC100,
413 0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
414
415 { PCMCIA_STR_MACNICA_ME1_JEIDA,
416 PCMCIA_VENDOR_MACNICA, PCMCIA_PRODUCT_MACNICA_ME1_JEIDA,
417 PCMCIA_CIS_MACNICA_ME1_JEIDA,
418 0, 0x00b8, { 0x08, 0x00, 0x42 } },
419
420 #if 0
421 /* the rest of these are stolen from the linux pcnet pcmcia device
422 driver. Since I don't know the manfid or cis info strings for
423 any of them, they're not compiled in until I do. */
424 { "APEX MultiCard",
425 0x0000, 0x0000, NULL, NULL, 0,
426 0x03f4, { 0x00, 0x20, 0xe5 } },
427 { "ASANTE FriendlyNet",
428 0x0000, 0x0000, NULL, NULL, 0,
429 0x4910, { 0x00, 0x00, 0x94 } },
430 { "Danpex EN-6200P2",
431 0x0000, 0x0000, NULL, NULL, 0,
432 0x0110, { 0x00, 0x40, 0xc7 } },
433 { "DataTrek NetCard",
434 0x0000, 0x0000, NULL, NULL, 0,
435 0x0ff0, { 0x00, 0x20, 0xe8 } },
436 { "Dayna CommuniCard E",
437 0x0000, 0x0000, NULL, NULL, 0,
438 0x0110, { 0x00, 0x80, 0x19 } },
439 { "EP-210 Ethernet",
440 0x0000, 0x0000, NULL, NULL, 0,
441 0x0110, { 0x00, 0x40, 0x33 } },
442 { "ELECOM Laneed LD-CDWA",
443 0x0000, 0x0000, NULL, NULL, 0,
444 0x00b8, { 0x08, 0x00, 0x42 } },
445 { "Grey Cell GCS2220",
446 0x0000, 0x0000, NULL, NULL, 0,
447 0x0000, { 0x00, 0x47, 0x43 } },
448 { "Hypertec Ethernet",
449 0x0000, 0x0000, NULL, NULL, 0,
450 0x01c0, { 0x00, 0x40, 0x4c } },
451 { "IBM CCAE",
452 0x0000, 0x0000, NULL, NULL, 0,
453 0x0ff0, { 0x08, 0x00, 0x5a } },
454 { "IBM CCAE",
455 0x0000, 0x0000, NULL, NULL, 0,
456 0x0ff0, { 0x00, 0x04, 0xac } },
457 { "IBM CCAE",
458 0x0000, 0x0000, NULL, NULL, 0,
459 0x0ff0, { 0x00, 0x06, 0x29 } },
460 { "IBM FME",
461 0x0000, 0x0000, NULL, NULL, 0,
462 0x0374, { 0x00, 0x04, 0xac } },
463 { "IBM FME",
464 0x0000, 0x0000, NULL, NULL, 0,
465 0x0374, { 0x08, 0x00, 0x5a } },
466 { "Katron PE-520",
467 0x0000, 0x0000, NULL, NULL, 0,
468 0x0110, { 0x00, 0x40, 0xf6 } },
469 { "Kingston KNE-PCM/x",
470 0x0000, 0x0000, NULL, NULL, 0,
471 0x0ff0, { 0x00, 0xc0, 0xf0 } },
472 { "Kingston KNE-PCM/x",
473 0x0000, 0x0000, NULL, NULL, 0,
474 0x0ff0, { 0xe2, 0x0c, 0x0f } },
475 { "Longshine LCS-8534",
476 0x0000, 0x0000, NULL, NULL, 0,
477 0x0000, { 0x08, 0x00, 0x00 } },
478 { "Maxtech PCN2000",
479 0x0000, 0x0000, NULL, NULL, 0,
480 0x5000, { 0x00, 0x00, 0xe8 } },
481 { "NDC Instant-Link",
482 0x0000, 0x0000, NULL, NULL, 0,
483 0x003a, { 0x00, 0x80, 0xc6 } },
484 { "NE2000 Compatible",
485 0x0000, 0x0000, NULL, NULL, 0,
486 0x0ff0, { 0x00, 0xa0, 0x0c } },
487 { "Network General Sniffer",
488 0x0000, 0x0000, NULL, NULL, 0,
489 0x0ff0, { 0x00, 0x00, 0x65 } },
490 { "Panasonic VEL211",
491 0x0000, 0x0000, NULL, NULL, 0,
492 0x0ff0, { 0x00, 0x80, 0x45 } },
493 { "SCM Ethernet",
494 0x0000, 0x0000, NULL, NULL, 0,
495 0x0ff0, { 0x00, 0x20, 0xcb } },
496 { "Volktek NPL-402CT",
497 0x0000, 0x0000, NULL, NULL, 0,
498 0x0060, { 0x00, 0x40, 0x05 } },
499 #endif
500
501 { PCMCIA_STR_ALLIEDTELESIS_LA_PCM,
502 PCMCIA_VENDOR_ALLIEDTELESIS, PCMCIA_PRODUCT_ALLIEDTELESIS_LA_PCM,
503 PCMCIA_CIS_ALLIEDTELESIS_LA_PCM,
504 0, 0x0ff0, { 0x00, 0x00, 0xf4 } },
505 };
506
507 #define NE2000_NDEVS (sizeof(ne2000devs) / sizeof(ne2000devs[0]))
508
509 #define ne2000_match(card, fct, n) \
510 ((((((card)->manufacturer != PCMCIA_VENDOR_INVALID) && \
511 ((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
512 ((card)->product != PCMCIA_PRODUCT_INVALID) && \
513 ((card)->product == ne2000devs[(n)].product)) || \
514 ((ne2000devs[(n)].cis_info[0]) && (ne2000devs[(n)].cis_info[1]) && \
515 (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis_info[0]) == 0) && \
516 (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis_info[1]) == 0))) && \
517 ((fct) == ne2000devs[(n)].function))? \
518 &ne2000devs[(n)]:NULL)
519
520 int
521 ne_pcmcia_match(parent, match, aux)
522 struct device *parent;
523 struct cfdata *match;
524 void *aux;
525 {
526 struct pcmcia_attach_args *pa = aux;
527 int i;
528
529 for (i = 0; i < NE2000_NDEVS; i++) {
530 if (ne2000_match(pa->card, pa->pf->number, i))
531 return (1);
532 }
533
534 return (0);
535 }
536
537 void
538 ne_pcmcia_attach(parent, self, aux)
539 struct device *parent, *self;
540 void *aux;
541 {
542 struct ne_pcmcia_softc *psc = (void *) self;
543 struct ne2000_softc *nsc = &psc->sc_ne2000;
544 struct dp8390_softc *dsc = &nsc->sc_dp8390;
545 struct pcmcia_attach_args *pa = aux;
546 struct pcmcia_config_entry *cfe;
547 const struct ne2000dev *ne_dev;
548 int i;
549 u_int8_t myea[6], *enaddr;
550 const char *typestr = "";
551
552 psc->sc_pf = pa->pf;
553
554 for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
555 cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
556 #if 0
557 /*
558 * Some ne2000 driver's claim to have memory; others don't.
559 * Since I don't care, I don't check.
560 */
561
562 if (cfe->num_memspace != 1) {
563 printf(": unexpected number of memory spaces "
564 " %d should be 1\n", cfe->num_memspace);
565 continue;
566 }
567 #endif
568
569 if (cfe->num_iospace == 1) {
570 if (cfe->iospace[0].length != NE2000_NPORTS) {
571 printf(": unexpected I/O space configuration"
572 " (continued)\n%s", dsc->sc_dev.dv_xname);
573 /* XXX really safe for all other cards? */
574 }
575 } else if (cfe->num_iospace == 2) {
576 /*
577 * Some cards report a separate space for NIC and ASIC.
578 * This make some sense, but we must allocate a single
579 * NE2000_NPORTS-sized chunk, due to brain damaged
580 * address decoders on some of these cards.
581 */
582 if (cfe->iospace[0].length + cfe->iospace[1].length !=
583 NE2000_NPORTS) {
584 #ifdef DIAGNOSTIC
585 printf(": unexpected I/O "
586 "space configuration; ignored\n%s",
587 dsc->sc_dev.dv_xname);
588 #endif
589 continue;
590 }
591 } else {
592 #ifdef DIAGNOSTIC
593 printf(": unexpected number of i/o spaces %d"
594 " should be 1 or 2; ignored\n%s",
595 cfe->num_iospace, dsc->sc_dev.dv_xname);
596 #endif
597 continue;
598 }
599
600 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
601 NE2000_NPORTS, NE2000_NPORTS, &psc->sc_pcioh)) {
602 #ifdef DIAGNOSTIC
603 printf(": can't allocate i/o space %lx; ignored\n%s",
604 cfe->iospace[0].start, dsc->sc_dev.dv_xname);
605 #endif
606 continue;
607 }
608
609 /* Ok, found. */
610 break;
611 }
612
613 if (cfe == NULL) {
614 printf(": no suitable config entry\n");
615 goto fail_1;
616 }
617
618 dsc->sc_regt = psc->sc_pcioh.iot;
619 dsc->sc_regh = psc->sc_pcioh.ioh;
620
621 nsc->sc_asict = psc->sc_pcioh.iot;
622 if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
623 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
624 &nsc->sc_asich)) {
625 printf(": can't get subregion for asic\n");
626 goto fail_2;
627 }
628
629 /* Set up power management hooks. */
630 dsc->sc_enable = ne_pcmcia_enable;
631 dsc->sc_disable = ne_pcmcia_disable;
632
633 /* Enable the card. */
634 pcmcia_function_init(pa->pf, cfe);
635 if (pcmcia_function_enable(pa->pf)) {
636 printf(": function enable failed\n");
637 goto fail_2;
638 }
639
640 /* some cards claim to be io16, but they're lying. */
641 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
642 NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
643 &psc->sc_pcioh, &psc->sc_nic_io_window)) {
644 printf(": can't map NIC i/o space\n");
645 goto fail_3;
646 }
647
648 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
649 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
650 &psc->sc_pcioh, &psc->sc_asic_io_window)) {
651 printf(": can't map ASIC i/o space\n");
652 goto fail_4;
653 }
654
655 printf("\n");
656
657 /*
658 * Read the station address from the board.
659 */
660 i = 0;
661 again:
662 enaddr = NULL; /* Ask ASIC by default */
663 for (; i < NE2000_NDEVS; i++) {
664 ne_dev = ne2000_match(pa->card, pa->pf->number, i);
665 if (ne_dev != NULL) {
666 if (ne_dev->enet_maddr >= 0) {
667 enaddr = ne_pcmcia_get_enaddr(psc,
668 ne_dev->enet_maddr, myea);
669 if (enaddr == NULL)
670 continue;
671 }
672 break;
673 }
674 }
675 if (i == NE2000_NDEVS) {
676 printf("%s: can't match ethernet vendor code\n",
677 dsc->sc_dev.dv_xname);
678 goto fail_5;
679 }
680
681 if ((ne_dev->flags & NE2000DVF_DL10019) != 0) {
682 u_int8_t type;
683
684 enaddr = ne_pcmcia_dl10019_get_enaddr(psc, myea);
685 if (enaddr == NULL) {
686 ++i;
687 goto again;
688 }
689
690 dsc->sc_mediachange = dl10019_mediachange;
691 dsc->sc_mediastatus = dl10019_mediastatus;
692 dsc->init_card = dl10019_init_card;
693 dsc->stop_card = dl10019_stop_card;
694 dsc->sc_media_init = dl10019_media_init;
695 dsc->sc_media_fini = dl10019_media_fini;
696
697 /* Determine if this is a DL10019 or a DL10022. */
698 type = bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 0x0f);
699 if (type == 0x91 || type == 0x99) {
700 nsc->sc_type = NE2000_TYPE_DL10022;
701 typestr = " (DL10022)";
702 } else {
703 nsc->sc_type = NE2000_TYPE_DL10019;
704 typestr = " (DL10019)";
705 }
706 }
707
708 if ((ne_dev->flags & NE2000DVF_AX88190) != 0) {
709 if (ne_pcmcia_ax88190_set_iobase(psc)) {
710 ++i;
711 goto again;
712 }
713
714 dsc->sc_mediachange = ax88190_mediachange;
715 dsc->sc_mediastatus = ax88190_mediastatus;
716 dsc->init_card = ax88190_init_card;
717 dsc->stop_card = ax88190_stop_card;
718 dsc->sc_media_init = ax88190_media_init;
719 dsc->sc_media_fini = ax88190_media_fini;
720
721 nsc->sc_type = NE2000_TYPE_AX88190;
722 typestr = " (AX88190)";
723 }
724
725 if (enaddr != NULL) {
726 /*
727 * Make sure this is what we expect.
728 */
729 if (enaddr[0] != ne_dev->enet_vendor[0] ||
730 enaddr[1] != ne_dev->enet_vendor[1] ||
731 enaddr[2] != ne_dev->enet_vendor[2]) {
732 ++i;
733 goto again;
734 }
735 }
736
737 /*
738 * Check for a RealTek 8019.
739 */
740 if (nsc->sc_type == 0) {
741 bus_space_write_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CR,
742 ED_CR_PAGE_0 | ED_CR_STP);
743 if (bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
744 NERTL_RTL0_8019ID0) == RTL0_8019ID0 &&
745 bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
746 NERTL_RTL0_8019ID1) == RTL0_8019ID1) {
747 typestr = " (RTL8019)";
748 dsc->sc_mediachange = rtl80x9_mediachange;
749 dsc->sc_mediastatus = rtl80x9_mediastatus;
750 dsc->init_card = rtl80x9_init_card;
751 dsc->sc_media_init = rtl80x9_media_init;
752 }
753 }
754
755 printf("%s: %s%s Ethernet\n", dsc->sc_dev.dv_xname, ne_dev->name,
756 typestr);
757
758 if (ne2000_attach(nsc, enaddr))
759 goto fail_5;
760
761 pcmcia_function_disable(pa->pf);
762 return;
763
764 fail_5:
765 /* Unmap ASIC i/o windows. */
766 pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
767
768 fail_4:
769 /* Unmap NIC i/o windows. */
770 pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
771
772 fail_3:
773 pcmcia_function_disable(pa->pf);
774
775 fail_2:
776 /* Free our i/o space. */
777 pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
778
779 fail_1:
780 psc->sc_nic_io_window = -1;
781 }
782
783 int
784 ne_pcmcia_detach(self, flags)
785 struct device *self;
786 int flags;
787 {
788 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)self;
789 int error;
790
791 if (psc->sc_nic_io_window == -1)
792 /* Nothing to detach. */
793 return (0);
794
795 error = ne2000_detach(&psc->sc_ne2000, flags);
796 if (error != 0)
797 return (error);
798
799 /* Unmap our i/o windows. */
800 pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
801 pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
802
803 /* Free our i/o space. */
804 pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
805
806 return (0);
807 }
808
809 int
810 ne_pcmcia_enable(dsc)
811 struct dp8390_softc *dsc;
812 {
813 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
814 struct ne2000_softc *nsc = &psc->sc_ne2000;
815
816 /* set up the interrupt */
817 psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
818 dsc);
819 if (psc->sc_ih == NULL) {
820 printf("%s: couldn't establish interrupt\n",
821 dsc->sc_dev.dv_xname);
822 goto fail_1;
823 }
824
825 if (pcmcia_function_enable(psc->sc_pf))
826 goto fail_2;
827
828 if (nsc->sc_type == NE2000_TYPE_AX88190)
829 if (ne_pcmcia_ax88190_set_iobase(psc))
830 goto fail_3;
831
832 return (0);
833
834 fail_3:
835 pcmcia_function_disable(psc->sc_pf);
836 fail_2:
837 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
838 fail_1:
839 return (1);
840 }
841
842 void
843 ne_pcmcia_disable(dsc)
844 struct dp8390_softc *dsc;
845 {
846 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
847
848 pcmcia_function_disable(psc->sc_pf);
849 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
850 }
851
852 u_int8_t *
853 ne_pcmcia_get_enaddr(psc, maddr, myea)
854 struct ne_pcmcia_softc *psc;
855 int maddr;
856 u_int8_t myea[ETHER_ADDR_LEN];
857 {
858 struct ne2000_softc *nsc = &psc->sc_ne2000;
859 struct dp8390_softc *dsc = &nsc->sc_dp8390;
860 struct pcmcia_mem_handle pcmh;
861 bus_size_t offset;
862 u_int8_t *enaddr = NULL;
863 int j, mwindow;
864
865 if (maddr < 0)
866 return (NULL);
867
868 if (pcmcia_mem_alloc(psc->sc_pf, ETHER_ADDR_LEN * 2, &pcmh)) {
869 printf("%s: can't alloc mem for enet addr\n",
870 dsc->sc_dev.dv_xname);
871 goto fail_1;
872 }
873 if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, maddr,
874 ETHER_ADDR_LEN * 2, &pcmh, &offset, &mwindow)) {
875 printf("%s: can't map mem for enet addr\n",
876 dsc->sc_dev.dv_xname);
877 goto fail_2;
878 }
879 for (j = 0; j < ETHER_ADDR_LEN; j++)
880 myea[j] = bus_space_read_1(pcmh.memt, pcmh.memh,
881 offset + (j * 2));
882 enaddr = myea;
883
884 pcmcia_mem_unmap(psc->sc_pf, mwindow);
885 fail_2:
886 pcmcia_mem_free(psc->sc_pf, &pcmh);
887 fail_1:
888 return (enaddr);
889 }
890
891 u_int8_t *
892 ne_pcmcia_dl10019_get_enaddr(psc, myea)
893 struct ne_pcmcia_softc *psc;
894 u_int8_t myea[ETHER_ADDR_LEN];
895 {
896 struct ne2000_softc *nsc = &psc->sc_ne2000;
897 u_int8_t sum;
898 int j;
899
900 #define PAR0 0x04
901 for (j = 0, sum = 0; j < 8; j++)
902 sum += bus_space_read_1(nsc->sc_asict, nsc->sc_asich,
903 PAR0 + j);
904 if (sum != 0xff)
905 return (NULL);
906 for (j = 0; j < ETHER_ADDR_LEN; j++)
907 myea[j] = bus_space_read_1(nsc->sc_asict,
908 nsc->sc_asich, PAR0 + j);
909 #undef PAR0
910 return (myea);
911 }
912
913 int
914 ne_pcmcia_ax88190_set_iobase(psc)
915 struct ne_pcmcia_softc *psc;
916 {
917 struct ne2000_softc *nsc = &psc->sc_ne2000;
918 struct dp8390_softc *dsc = &nsc->sc_dp8390;
919 struct pcmcia_mem_handle pcmh;
920 bus_size_t offset;
921 int rv = 1, mwindow;
922 u_int last_liobase, new_liobase;
923
924 if (pcmcia_mem_alloc(psc->sc_pf, AX88190_LAN_IOSIZE, &pcmh)) {
925 #if 0
926 printf("%s: can't alloc mem for LAN iobase\n",
927 dsc->sc_dev.dv_xname);
928 #endif
929 goto fail_1;
930 }
931 if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
932 AX88190_LAN_IOBASE, AX88190_LAN_IOSIZE,
933 &pcmh, &offset, &mwindow)) {
934 printf("%s: can't map mem for LAN iobase\n",
935 dsc->sc_dev.dv_xname);
936 goto fail_2;
937 }
938
939 last_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
940 (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
941 #ifdef DIAGNOSTIC
942 printf("%s: LAN iobase 0x%x (0x%x) ->", dsc->sc_dev.dv_xname,
943 last_liobase, (u_int)psc->sc_pcioh.addr);
944 #endif
945 bus_space_write_1(pcmh.memt, pcmh.memh, offset,
946 psc->sc_pcioh.addr & 0xff);
947 bus_space_write_1(pcmh.memt, pcmh.memh, offset + 2,
948 psc->sc_pcioh.addr >> 8);
949
950 new_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
951 (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
952 #ifdef DIAGNOSTIC
953 printf(" 0x%x\n", new_liobase);
954 #endif
955 if ((last_liobase == psc->sc_pcioh.addr)
956 || (last_liobase != new_liobase))
957 rv = 0;
958
959 pcmcia_mem_unmap(psc->sc_pf, mwindow);
960 fail_2:
961 pcmcia_mem_free(psc->sc_pf, &pcmh);
962 fail_1:
963 return (rv);
964 }
965