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