if_ne_pcmcia.c revision 1.1.2.2 1 /* $NetBSD: if_ne_pcmcia.c,v 1.1.2.2 1997/10/14 01:59:17 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/select.h>
43 #include <sys/device.h>
44 #include <sys/socket.h>
45
46 #include <net/if_types.h>
47 #include <net/if.h>
48 #include <net/if_ether.h>
49
50 #include <machine/bus.h>
51 #include <machine/intr.h>
52
53 #include <dev/pcmcia/pcmciareg.h>
54 #include <dev/pcmcia/pcmciavar.h>
55
56 #include <dev/ic/dp8390reg.h>
57 #include <dev/ic/dp8390var.h>
58
59 #include <dev/ic/ne2000reg.h>
60 #include <dev/ic/ne2000var.h>
61
62 #ifdef __BROKEN_INDIRECT_CONFIG
63 int ne_pcmcia_match __P((struct device *, void *, void *));
64 #else
65 int ne_pcmcia_match __P((struct device *, struct cfdata *, void *));
66 #endif
67 void ne_pcmcia_attach __P((struct device *, struct device *, void *));
68
69 int ne_pcmcia_enable __P((struct dp8390_softc *));
70 void ne_pcmcia_disable __P((struct dp8390_softc *));
71
72 struct ne_pcmcia_softc {
73 struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
74
75 /* PCMCIA-specific goo */
76 struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o information */
77 int sc_asic_io_window; /* i/o window for ASIC */
78 int sc_nic_io_window; /* i/o window for NIC */
79 struct pcmcia_function *sc_pf; /* our PCMCIA function */
80 void *sc_ih; /* interrupt handle */
81 };
82
83 struct cfattach ne_pcmcia_ca = {
84 sizeof(struct ne_pcmcia_softc), ne_pcmcia_match, ne_pcmcia_attach
85 };
86
87 struct ne2000dev {
88 char *name;
89 int manufacturer;
90 int product;
91 char *cis1_info0;
92 char *cis1_info1;
93 int function;
94 int enet_maddr;
95 unsigned char enet_vendor[3];
96 } ne2000devs[] = {
97 { "PreMax PE-200",
98 0xffff, 0xffff, "PMX ", "PE-200", 0,
99 0x07f0, { 0x00, 0x20, 0xe0 } },
100 { "National Semiconductor InfoMover",
101 0x00a4, 0x0002, NULL, NULL, 0,
102 0x0ff0, { 0x08, 0x00, 0x5a } },
103 { "DEC DEPCM-BA",
104 0x0000, 0x0000, "DIGITAL", "DEPCM-XX", 0,
105 0x0ff0, { 0x00, 0x00, 0xe8 } },
106 /* this card might need pcic_alloc_iobase < 0x400, and/or
107 CIRRUS_PD672X on TI TravelMate 5000 needs it: */
108 { "Linksys EthernetCard",
109 0x0149, 0x0265, "LINKSYS", "E-CARD",
110 0, -1, { 0x00, 0x80, 0xc8 } },
111 { "Planet SmartCOM 2000",
112 0xffffffff, 0xffff, "PCMCIA", "UE2212", 0,
113 0xff0, { 0x00, 0x00, 0xe8 } },
114 #if 0
115 /* the rest of these are stolen from the linux pcnet pcmcia device
116 driver. Since I don't know the manfid or cis info strings for
117 any of them, they're not compiled in until I do. */
118
119 { "Accton EN2212",
120 0x0000, 0x0000, NULL, NULL, 0,
121 0x0ff0, { 0x00, 0x00, 0xe8 } },
122 { "Allied Telesis LA-PCM",
123 0x0000, 0x0000, NULL, NULL, 0,
124 0x0ff0, { 0x00, 0x00, 0xf4 } },
125 { "APEX MultiCard",
126 0x0000, 0x0000, NULL, NULL, 0,
127 0x03f4, { 0x00, 0x20, 0xe5 } },
128 { "ASANTE FriendlyNet",
129 0x0000, 0x0000, NULL, NULL, 0,
130 0x4910, { 0x00, 0x00, 0x94 } },
131 { "Danpex EN-6200P2",
132 0x0000, 0x0000, NULL, NULL, 0,
133 0x0110, { 0x00, 0x40, 0xc7 } },
134 { "DataTrek NetCard",
135 0x0000, 0x0000, NULL, NULL, 0,
136 0x0ff0, { 0x00, 0x20, 0xe8 } },
137 { "Dayna CommuniCard E",
138 0x0000, 0x0000, NULL, NULL, 0,
139 0x0110, { 0x00, 0x80, 0x19 } },
140 { "D-Link DE-650",
141 0x0000, 0x0000, NULL, NULL, 0,
142 0x0040, { 0x00, 0x80, 0xc8 } },
143 { "EP-210 Ethernet",
144 0x0000, 0x0000, NULL, NULL, 0,
145 0x0110, { 0x00, 0x40, 0x33 } },
146 { "Epson EEN10B",
147 0x0000, 0x0000, NULL, NULL, 0,
148 0x0ff0, { 0x00, 0x00, 0x48 } },
149 { "ELECOM Laneed LD-CDWA",
150 0x0000, 0x0000, NULL, NULL, 0,
151 0x00b8, { 0x08, 0x00, 0x42 } },
152 { "Grey Cell GCS2220",
153 0x0000, 0x0000, NULL, NULL, 0,
154 0x0000, { 0x00, 0x47, 0x43 } },
155 { "Hypertec Ethernet",
156 0x0000, 0x0000, NULL, NULL, 0,
157 0x01c0, { 0x00, 0x40, 0x4c } },
158 { "IBM CCAE",
159 0x0000, 0x0000, NULL, NULL, 0,
160 0x0ff0, { 0x08, 0x00, 0x5a } },
161 { "IBM CCAE",
162 0x0000, 0x0000, NULL, NULL, 0,
163 0x0ff0, { 0x00, 0x04, 0xac } },
164 { "IBM CCAE",
165 0x0000, 0x0000, NULL, NULL, 0,
166 0x0ff0, { 0x00, 0x06, 0x29 } },
167 { "IBM FME",
168 0x0000, 0x0000, NULL, NULL, 0,
169 0x0374, { 0x00, 0x04, 0xac } },
170 { "IBM FME",
171 0x0000, 0x0000, NULL, NULL, 0,
172 0x0374, { 0x08, 0x00, 0x5a } },
173 { "I-O DATA PCLA/T",
174 0x0000, 0x0000, NULL, NULL, 0,
175 0x0ff0, { 0x00, 0xa0, 0xb0 } },
176 { "Katron PE-520",
177 0x0000, 0x0000, NULL, NULL, 0,
178 0x0110, { 0x00, 0x40, 0xf6 } },
179 { "Kingston KNE-PCM/x",
180 0x0000, 0x0000, NULL, NULL, 0,
181 0x0ff0, { 0x00, 0xc0, 0xf0 } },
182 { "Kingston KNE-PCM/x",
183 0x0000, 0x0000, NULL, NULL, 0,
184 0x0ff0, { 0xe2, 0x0c, 0x0f } },
185 { "Kingston KNE-PC2",
186 0x0000, 0x0000, NULL, NULL, 0,
187 0x0180, { 0x00, 0xc0, 0xf0 } },
188 { "Longshine LCS-8534",
189 0x0000, 0x0000, NULL, NULL, 0,
190 0x0000, { 0x08, 0x00, 0x00 } },
191 { "Maxtech PCN2000",
192 0x0000, 0x0000, NULL, NULL, 0,
193 0x5000, { 0x00, 0x00, 0xe8 } },
194 { "NDC Instant-Link",
195 0x0000, 0x0000, NULL, NULL, 0,
196 0x003a, { 0x00, 0x80, 0xc6 } },
197 { "NE2000 Compatible",
198 0x0000, 0x0000, NULL, NULL, 0,
199 0x0ff0, { 0x00, 0xa0, 0x0c } },
200 { "Network General Sniffer",
201 0x0000, 0x0000, NULL, NULL, 0,
202 0x0ff0, { 0x00, 0x00, 0x65 } },
203 { "Panasonic VEL211",
204 0x0000, 0x0000, NULL, NULL, 0,
205 0x0ff0, { 0x00, 0x80, 0x45 } },
206 { "RPTI EP400",
207 0x0000, 0x0000, NULL, NULL, 0,
208 0x0110, { 0x00, 0x40, 0x95 } },
209 { "SCM Ethernet",
210 0x0000, 0x0000, NULL, NULL, 0,
211 0x0ff0, { 0x00, 0x20, 0xcb } },
212 { "Socket EA",
213 0x0000, 0x0000, NULL, NULL, 0,
214 0x4000, { 0x00, 0xc0, 0x1b } },
215 { "Volktek NPL-402CT",
216 0x0000, 0x0000, NULL, NULL, 0,
217 0x0060, { 0x00, 0x40, 0x05 } },
218 #endif
219 };
220
221 #define NE2000_NDEVS (sizeof(ne2000devs) / sizeof(ne2000devs[0]))
222
223 #define ne2000_match(card, fct, n) \
224 ((((((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
225 ((card)->product == ne2000devs[(n)].product)) || \
226 ((ne2000devs[(n)].cis1_info0) && (ne2000devs[(n)].cis1_info1) && \
227 (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis1_info0) == 0) && \
228 (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis1_info1) == 0))) && \
229 (pa->pf->number == ne2000devs[(n)].function))? \
230 &ne2000devs[(n)]:NULL)
231
232 int
233 ne_pcmcia_match(parent, match, aux)
234 struct device *parent;
235 #ifdef __BROKEN_INDIRECT_CONFIG
236 void *match;
237 #else
238 struct cfdata *cf;
239 #endif
240 void *aux;
241 {
242 struct pcmcia_attach_args *pa = (struct pcmcia_attach_args *) aux;
243 int i;
244
245 for (i = 0; i < NE2000_NDEVS; i++) {
246 if (ne2000_match(pa->card, pa->pf->number, i))
247 return (1);
248 }
249
250 return (0);
251 }
252
253 void
254 ne_pcmcia_attach(parent, self, aux)
255 struct device *parent, *self;
256 void *aux;
257 {
258 struct ne_pcmcia_softc *psc = (void *) self;
259 struct ne2000_softc *nsc = &psc->sc_ne2000;
260 struct dp8390_softc *dsc = &nsc->sc_dp8390;
261 struct pcmcia_attach_args *pa = aux;
262 struct pcmcia_config_entry *cfe;
263 struct ne2000dev *ne_dev;
264 struct pcmcia_mem_handle pcmh;
265 bus_addr_t offset;
266 int i, j, mwindow;
267 u_int8_t myea[6], *enaddr = NULL;
268
269 psc->sc_pf = pa->pf;
270 cfe = pa->pf->cfe_head.sqh_first;
271
272 #if 0
273 /*
274 * Some ne2000 driver's claim to have memory; others don't.
275 * Since I don't care, I don't check.
276 */
277
278 if (cfe->num_memspace != 1) {
279 printf(": unexpected number of memory spaces "
280 " %d should be 1\n", cfe->num_memspace);
281 return;
282 }
283 #endif
284
285 if (cfe->num_iospace == 1) {
286 if (cfe->iospace[0].length != NE2000_NPORTS) {
287 printf(": unexpected I/O space configuration\n");
288 return;
289 }
290 } else if (cfe->num_iospace == 2) {
291 /*
292 * Some cards report a separate space for NIC and ASIC.
293 * This make some sense, but we must allocate a single
294 * NE2000_NPORTS-sized chunk, due to brain damaged
295 * address decoders on some of these cards.
296 */
297 if ((cfe->iospace[0].length + cfe->iospace[1].length) !=
298 NE2000_NPORTS) {
299 printf(": unexpected I/O space configuration\n");
300 return;
301 }
302 } else {
303 printf(": unexpected number of i/o spaces %d"
304 " should be 1 or 2\n", cfe->num_iospace);
305 }
306
307 if (pcmcia_io_alloc(pa->pf, 0, NE2000_NPORTS, NE2000_NPORTS,
308 &psc->sc_pcioh)) {
309 printf(": can't alloc i/o space\n");
310 return;
311 }
312
313 dsc->sc_regt = psc->sc_pcioh.iot;
314 dsc->sc_regh = psc->sc_pcioh.ioh;
315
316 nsc->sc_asict = psc->sc_pcioh.iot;
317 if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
318 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
319 &nsc->sc_asich)) {
320 printf(": can't get subregion for asic\n");
321 return;
322 }
323
324 /* Set up power management hooks. */
325 dsc->sc_enable = ne_pcmcia_enable;
326 dsc->sc_disable = ne_pcmcia_disable;
327
328 /* Enable the card. */
329 pcmcia_function_init(pa->pf, cfe);
330 if (pcmcia_function_enable(pa->pf)) {
331 printf(": function enable failed\n");
332 return;
333 }
334
335 /* some cards claim to be io16, but they're lying. */
336 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
337 NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
338 &psc->sc_pcioh, &psc->sc_nic_io_window)) {
339 printf(": can't map NIC i/o space\n");
340 return;
341 }
342
343 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
344 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
345 &psc->sc_pcioh, &psc->sc_asic_io_window)) {
346 printf(": can't map ASIC i/o space\n");
347 return;
348 }
349
350 printf("\n");
351
352 /*
353 * Read the station address from the board.
354 */
355 for (i = 0; i < NE2000_NDEVS; i++) {
356 if ((ne_dev = ne2000_match(pa->card, pa->pf->number, i))
357 != NULL) {
358 if (ne_dev->enet_maddr >= 0) {
359 if (pcmcia_mem_alloc(pa->pf,
360 ETHER_ADDR_LEN * 2, &pcmh)) {
361 printf("%s: can't alloc mem for"
362 " enet addr\n",
363 dsc->sc_dev.dv_xname);
364 return;
365 }
366 if (pcmcia_mem_map(pa->pf, PCMCIA_MEM_ATTR,
367 ne_dev->enet_maddr, ETHER_ADDR_LEN * 2,
368 &pcmh, &offset, &mwindow)) {
369 printf("%s: can't map mem for"
370 " enet addr\n",
371 dsc->sc_dev.dv_xname);
372 return;
373 }
374 for (j = 0; j < ETHER_ADDR_LEN; j++)
375 myea[j] = bus_space_read_1(pcmh.memt,
376 pcmh.memh, offset + (j * 2));
377 pcmcia_mem_unmap(pa->pf, mwindow);
378 pcmcia_mem_free(pa->pf, &pcmh);
379 enaddr = myea;
380 }
381 break;
382 }
383 }
384
385 if (enaddr != NULL) {
386 /*
387 * Make sure this is what we expect.
388 */
389 if (enaddr[0] != ne_dev->enet_vendor[0] ||
390 enaddr[1] != ne_dev->enet_vendor[1] ||
391 enaddr[2] != ne_dev->enet_vendor[2]) {
392 printf("\n%s: enet addr has incorrect vendor code\n",
393 dsc->sc_dev.dv_xname);
394 printf("%s: (%02x:%02x:%02x should be "
395 "%02x:%02x:%02x)\n", dsc->sc_dev.dv_xname,
396 enaddr[0], enaddr[1], enaddr[2],
397 ne_dev->enet_vendor[0],
398 ne_dev->enet_vendor[1],
399 ne_dev->enet_vendor[2]);
400 return;
401 }
402 }
403
404 printf("%s: %s Ethernet\n", dsc->sc_dev.dv_xname, ne_dev->name);
405
406 ne2000_attach(nsc, enaddr);
407
408 /* set up the interrupt */
409 psc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_NET, dp8390_intr, dsc);
410 if (psc->sc_ih == NULL)
411 printf("%s: couldn't establish interrupt\n",
412 dsc->sc_dev.dv_xname);
413
414 pcmcia_function_disable(pa->pf);
415 }
416
417 int
418 ne_pcmcia_enable(dsc)
419 struct dp8390_softc *dsc;
420 {
421 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
422
423 return (pcmcia_function_enable(psc->sc_pf));
424 }
425
426 void
427 ne_pcmcia_disable(dsc)
428 struct dp8390_softc *dsc;
429 {
430 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
431
432 pcmcia_function_disable(psc->sc_pf);
433 }
434