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