Deleted Added
sdiff udiff text old ( 72193 ) new ( 73374 )
full compact
1/*
2 * Copyright (c) 1995, David Greenman
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
10 * 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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: head/sys/dev/ed/if_ed.c 73374 2001-03-03 08:31:37Z imp $
28 */
29
30/*
31 * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
32 * adapters. By David Greenman, 29-April-1993
33 *
34 * Currently supports the Western Digital/SMC 8003 and 8013 series,
35 * the SMC Elite Ultra (8216), the 3Com 3c503, the NE1000 and NE2000,
36 * and a variety of similar clones.
37 *
38 */
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/sockio.h>
43#include <sys/mbuf.h>
44#include <sys/kernel.h>
45#include <sys/socket.h>
46#include <sys/syslog.h>
47
48#include <sys/bus.h>
49
50#include <machine/bus.h>
51#include <sys/rman.h>
52#include <machine/resource.h>
53
54#include <net/ethernet.h>
55#include <net/if.h>
56#include <net/if_arp.h>
57#include <net/if_dl.h>
58#include <net/if_mib.h>
59#include <net/if_media.h>
60
61#include <dev/mii/mii.h>
62#include <dev/mii/miivar.h>
63
64#include <net/bpf.h>
65#include "opt_bdg.h"
66#ifdef BRIDGE
67#include <net/bridge.h>
68#endif
69
70#include <machine/md_var.h>
71
72#include <dev/ed/if_edreg.h>
73#include <dev/ed/if_edvar.h>
74
75devclass_t ed_devclass;
76
77static void ed_init __P((void *));
78static int ed_ioctl __P((struct ifnet *, u_long, caddr_t));
79static void ed_start __P((struct ifnet *));
80static void ed_reset __P((struct ifnet *));
81static void ed_watchdog __P((struct ifnet *));
82static void ed_tick __P((void *));
83
84static void ds_getmcaf __P((struct ed_softc *, u_int32_t *));
85
86static void ed_get_packet __P((struct ed_softc *, char *, /* u_short */ int));
87
88static __inline void ed_rint __P((struct ed_softc *));
89static __inline void ed_xmit __P((struct ed_softc *));
90static __inline char * ed_ring_copy __P((struct ed_softc *, char *, char *,
91 /* u_short */ int));
92static void ed_hpp_set_physical_link __P((struct ed_softc *));
93static void ed_hpp_readmem __P((struct ed_softc *, int, unsigned char *,
94 /* u_short */ int));
95static void ed_hpp_writemem __P((struct ed_softc *, unsigned char *,
96 /* u_short */ int, /* u_short */ int));
97static u_short ed_hpp_write_mbufs __P((struct ed_softc *, struct mbuf *,
98 int));
99
100static u_short ed_pio_write_mbufs __P((struct ed_softc *, struct mbuf *,
101 int));
102
103static void ed_setrcr __P((struct ed_softc *));
104
105static u_int32_t ds_crc __P((u_char *ep));
106
107/*
108 * Interrupt conversion table for WD/SMC ASIC/83C584
109 */
110static unsigned short ed_intr_val[] = {
111 9,
112 3,
113 5,
114 7,
115 10,
116 11,
117 15,
118 4
119};
120
121/*
122 * Interrupt conversion table for 83C790
123 */
124static unsigned short ed_790_intr_val[] = {
125 0,
126 9,
127 3,
128 5,
129 7,
130 10,
131 11,
132 15
133};
134
135/*
136 * Interrupt conversion table for the HP PC LAN+
137 */
138
139static unsigned short ed_hpp_intr_val[] = {
140 0, /* 0 */
141 0, /* 1 */
142 0, /* 2 */
143 3, /* 3 */
144 4, /* 4 */
145 5, /* 5 */
146 6, /* 6 */
147 7, /* 7 */
148 0, /* 8 */
149 9, /* 9 */
150 10, /* 10 */
151 11, /* 11 */
152 12, /* 12 */
153 0, /* 13 */
154 0, /* 14 */
155 15 /* 15 */
156};
157
158/*
159 * Generic probe routine for testing for the existance of a DS8390.
160 * Must be called after the NIC has just been reset. This routine
161 * works by looking at certain register values that are guaranteed
162 * to be initialized a certain way after power-up or reset. Seems
163 * not to currently work on the 83C690.
164 *
165 * Specifically:
166 *
167 * Register reset bits set bits
168 * Command Register (CR) TXP, STA RD2, STP
169 * Interrupt Status (ISR) RST
170 * Interrupt Mask (IMR) All bits
171 * Data Control (DCR) LAS
172 * Transmit Config. (TCR) LB1, LB0
173 *
174 * We only look at the CR and ISR registers, however, because looking at
175 * the others would require changing register pages (which would be
176 * intrusive if this isn't an 8390).
177 *
178 * Return 1 if 8390 was found, 0 if not.
179 */
180
181int
182ed_probe_generic8390(sc)
183 struct ed_softc *sc;
184{
185 if ((ed_nic_inb(sc, ED_P0_CR) &
186 (ED_CR_RD2 | ED_CR_TXP | ED_CR_STA | ED_CR_STP)) !=
187 (ED_CR_RD2 | ED_CR_STP))
188 return (0);
189 if ((ed_nic_inb(sc, ED_P0_ISR) & ED_ISR_RST) != ED_ISR_RST)
190 return (0);
191
192 return (1);
193}
194
195/*
196 * Probe and vendor-specific initialization routine for SMC/WD80x3 boards
197 */
198int
199ed_probe_WD80x3_generic(dev, flags, intr_vals)
200 device_t dev;
201 int flags;
202 unsigned short *intr_vals[];
203{
204 struct ed_softc *sc = device_get_softc(dev);
205 int error;
206 int i;
207 u_int memsize, maddr;
208 u_char iptr, isa16bit, sum, totalsum;
209 u_long conf_maddr, conf_msize, irq, junk;
210
211 sc->chip_type = ED_CHIP_TYPE_DP8390;
212
213 if (ED_FLAGS_GETTYPE(flags) == ED_FLAGS_TOSH_ETHER) {
214 totalsum = ED_WD_ROM_CHECKSUM_TOTAL_TOSH_ETHER;
215 ed_asic_outb(sc, ED_WD_MSR, ED_WD_MSR_POW);
216 DELAY(10000);
217 }
218 else
219 totalsum = ED_WD_ROM_CHECKSUM_TOTAL;
220
221 /*
222 * Attempt to do a checksum over the station address PROM. If it
223 * fails, it's probably not a SMC/WD board. There is a problem with
224 * this, though: some clone WD boards don't pass the checksum test.
225 * Danpex boards for one.
226 */
227 for (sum = 0, i = 0; i < 8; ++i)
228 sum += ed_asic_inb(sc, ED_WD_PROM + i);
229
230 if (sum != totalsum) {
231
232 /*
233 * Checksum is invalid. This often happens with cheap WD8003E
234 * clones. In this case, the checksum byte (the eighth byte)
235 * seems to always be zero.
236 */
237 if (ed_asic_inb(sc, ED_WD_CARD_ID) != ED_TYPE_WD8003E ||
238 ed_asic_inb(sc, ED_WD_PROM + 7) != 0)
239 return (ENXIO);
240 }
241 /* reset card to force it into a known state. */
242 if (ED_FLAGS_GETTYPE(flags) == ED_FLAGS_TOSH_ETHER)
243 ed_asic_outb(sc, ED_WD_MSR, ED_WD_MSR_RST | ED_WD_MSR_POW);
244 else
245 ed_asic_outb(sc, ED_WD_MSR, ED_WD_MSR_RST);
246
247 DELAY(100);
248 ed_asic_outb(sc, ED_WD_MSR, ed_asic_inb(sc, ED_WD_MSR) & ~ED_WD_MSR_RST);
249 /* wait in the case this card is reading its EEROM */
250 DELAY(5000);
251
252 sc->vendor = ED_VENDOR_WD_SMC;
253 sc->type = ed_asic_inb(sc, ED_WD_CARD_ID);
254
255 /*
256 * Set initial values for width/size.
257 */
258 memsize = 8192;
259 isa16bit = 0;
260 switch (sc->type) {
261 case ED_TYPE_WD8003S:
262 sc->type_str = "WD8003S";
263 break;
264 case ED_TYPE_WD8003E:
265 sc->type_str = "WD8003E";
266 break;
267 case ED_TYPE_WD8003EB:
268 sc->type_str = "WD8003EB";
269 break;
270 case ED_TYPE_WD8003W:
271 sc->type_str = "WD8003W";
272 break;
273 case ED_TYPE_WD8013EBT:
274 sc->type_str = "WD8013EBT";
275 memsize = 16384;
276 isa16bit = 1;
277 break;
278 case ED_TYPE_WD8013W:
279 sc->type_str = "WD8013W";
280 memsize = 16384;
281 isa16bit = 1;
282 break;
283 case ED_TYPE_WD8013EP: /* also WD8003EP */
284 if (ed_asic_inb(sc, ED_WD_ICR) & ED_WD_ICR_16BIT) {
285 isa16bit = 1;
286 memsize = 16384;
287 sc->type_str = "WD8013EP";
288 } else {
289 sc->type_str = "WD8003EP";
290 }
291 break;
292 case ED_TYPE_WD8013WC:
293 sc->type_str = "WD8013WC";
294 memsize = 16384;
295 isa16bit = 1;
296 break;
297 case ED_TYPE_WD8013EBP:
298 sc->type_str = "WD8013EBP";
299 memsize = 16384;
300 isa16bit = 1;
301 break;
302 case ED_TYPE_WD8013EPC:
303 sc->type_str = "WD8013EPC";
304 memsize = 16384;
305 isa16bit = 1;
306 break;
307 case ED_TYPE_SMC8216C: /* 8216 has 16K shared mem -- 8416 has 8K */
308 case ED_TYPE_SMC8216T:
309 if (sc->type == ED_TYPE_SMC8216C) {
310 sc->type_str = "SMC8216/SMC8216C";
311 } else {
312 sc->type_str = "SMC8216T";
313 }
314
315 ed_asic_outb(sc, ED_WD790_HWR,
316 ed_asic_inb(sc, ED_WD790_HWR) | ED_WD790_HWR_SWH);
317 switch (ed_asic_inb(sc, ED_WD790_RAR) & ED_WD790_RAR_SZ64) {
318 case ED_WD790_RAR_SZ64:
319 memsize = 65536;
320 break;
321 case ED_WD790_RAR_SZ32:
322 memsize = 32768;
323 break;
324 case ED_WD790_RAR_SZ16:
325 memsize = 16384;
326 break;
327 case ED_WD790_RAR_SZ8:
328 /* 8216 has 16K shared mem -- 8416 has 8K */
329 if (sc->type == ED_TYPE_SMC8216C) {
330 sc->type_str = "SMC8416C/SMC8416BT";
331 } else {
332 sc->type_str = "SMC8416T";
333 }
334 memsize = 8192;
335 break;
336 }
337 ed_asic_outb(sc, ED_WD790_HWR,
338 ed_asic_inb(sc, ED_WD790_HWR) & ~ED_WD790_HWR_SWH);
339
340 isa16bit = 1;
341 sc->chip_type = ED_CHIP_TYPE_WD790;
342 break;
343 case ED_TYPE_TOSHIBA1:
344 sc->type_str = "Toshiba1";
345 memsize = 32768;
346 isa16bit = 1;
347 break;
348 case ED_TYPE_TOSHIBA4:
349 sc->type_str = "Toshiba4";
350 memsize = 32768;
351 isa16bit = 1;
352 break;
353 default:
354 sc->type_str = "";
355 break;
356 }
357
358 /*
359 * Make some adjustments to initial values depending on what is found
360 * in the ICR.
361 */
362 if (isa16bit && (sc->type != ED_TYPE_WD8013EBT)
363 && (sc->type != ED_TYPE_TOSHIBA1) && (sc->type != ED_TYPE_TOSHIBA4)
364 && ((ed_asic_inb(sc, ED_WD_ICR) & ED_WD_ICR_16BIT) == 0)) {
365 isa16bit = 0;
366 memsize = 8192;
367 }
368
369 error = bus_get_resource(dev, SYS_RES_MEMORY, 0,
370 &conf_maddr, &conf_msize);
371 if (error)
372 return (error);
373
374#if ED_DEBUG
375 printf("type = %x type_str=%s isa16bit=%d memsize=%d id_msize=%d\n",
376 sc->type, sc->type_str, isa16bit, memsize, conf_msize);
377 for (i = 0; i < 8; i++)
378 printf("%x -> %x\n", i, ed_asic_inb(sc, i));
379#endif
380
381 /*
382 * Allow the user to override the autoconfiguration
383 */
384 if (conf_msize > 1)
385 memsize = conf_msize;
386
387 maddr = conf_maddr;
388 if (maddr < 0xa0000 || maddr + memsize > 0x1000000) {
389 device_printf(dev, "Invalid ISA memory address range configured: 0x%x - 0x%x\n",
390 maddr, maddr + memsize);
391 return (ENXIO);
392 }
393
394 /*
395 * (note that if the user specifies both of the following flags that
396 * '8bit' mode intentionally has precedence)
397 */
398 if (flags & ED_FLAGS_FORCE_16BIT_MODE)
399 isa16bit = 1;
400 if (flags & ED_FLAGS_FORCE_8BIT_MODE)
401 isa16bit = 0;
402
403 /*
404 * If possible, get the assigned interrupt number from the card and
405 * use it.
406 */
407 if ((sc->type & ED_WD_SOFTCONFIG) &&
408 (sc->chip_type != ED_CHIP_TYPE_WD790)) {
409
410 /*
411 * Assemble together the encoded interrupt number.
412 */
413 iptr = (ed_asic_inb(sc, ED_WD_ICR) & ED_WD_ICR_IR2) |
414 ((ed_asic_inb(sc, ED_WD_IRR) &
415 (ED_WD_IRR_IR0 | ED_WD_IRR_IR1)) >> 5);
416
417 /*
418 * If no interrupt specified (or "?"), use what the board tells us.
419 */
420 error = bus_get_resource(dev, SYS_RES_IRQ, 0,
421 &irq, &junk);
422 if (error && intr_vals[0] != NULL) {
423 error = bus_set_resource(dev, SYS_RES_IRQ, 0,
424 intr_vals[0][iptr], 1);
425 }
426 if (error)
427 return (error);
428
429 /*
430 * Enable the interrupt.
431 */
432 ed_asic_outb(sc, ED_WD_IRR,
433 ed_asic_inb(sc, ED_WD_IRR) | ED_WD_IRR_IEN);
434 }
435 if (sc->chip_type == ED_CHIP_TYPE_WD790) {
436 ed_asic_outb(sc, ED_WD790_HWR,
437 ed_asic_inb(sc, ED_WD790_HWR) | ED_WD790_HWR_SWH);
438 iptr = (((ed_asic_inb(sc, ED_WD790_GCR) & ED_WD790_GCR_IR2) >> 4) |
439 (ed_asic_inb(sc, ED_WD790_GCR) &
440 (ED_WD790_GCR_IR1 | ED_WD790_GCR_IR0)) >> 2);
441 ed_asic_outb(sc, ED_WD790_HWR,
442 ed_asic_inb(sc, ED_WD790_HWR) & ~ED_WD790_HWR_SWH);
443
444 /*
445 * If no interrupt specified (or "?"), use what the board tells us.
446 */
447 error = bus_get_resource(dev, SYS_RES_IRQ, 0,
448 &irq, &junk);
449 if (error && intr_vals[1] != NULL) {
450 error = bus_set_resource(dev, SYS_RES_IRQ, 0,
451 intr_vals[1][iptr], 1);
452 }
453 if (error)
454 return (error);
455
456 /*
457 * Enable interrupts.
458 */
459 ed_asic_outb(sc, ED_WD790_ICR,
460 ed_asic_inb(sc, ED_WD790_ICR) | ED_WD790_ICR_EIL);
461 }
462 error = bus_get_resource(dev, SYS_RES_IRQ, 0,
463 &irq, &junk);
464 if (error) {
465 device_printf(dev, "%s cards don't support auto-detected/assigned interrupts.\n",
466 sc->type_str);
467 return (ENXIO);
468 }
469 sc->isa16bit = isa16bit;
470 sc->mem_shared = 1;
471
472 error = ed_alloc_memory(dev, 0, memsize);
473 if (error) {
474 printf("*** ed_alloc_memory() failed! (%d)\n", error);
475 return (error);
476 }
477 sc->mem_start = (caddr_t) rman_get_virtual(sc->mem_res);
478
479 /*
480 * allocate one xmit buffer if < 16k, two buffers otherwise
481 */
482 if ((memsize < 16384) ||
483 (flags & ED_FLAGS_NO_MULTI_BUFFERING)) {
484 sc->txb_cnt = 1;
485 } else {
486 sc->txb_cnt = 2;
487 }
488 sc->tx_page_start = ED_WD_PAGE_OFFSET;
489 sc->rec_page_start = ED_WD_PAGE_OFFSET + ED_TXBUF_SIZE * sc->txb_cnt;
490 sc->rec_page_stop = ED_WD_PAGE_OFFSET + memsize / ED_PAGE_SIZE;
491 sc->mem_ring = sc->mem_start + (ED_PAGE_SIZE * sc->rec_page_start);
492 sc->mem_size = memsize;
493 sc->mem_end = sc->mem_start + memsize;
494
495 /*
496 * Get station address from on-board ROM
497 */
498 for (i = 0; i < ETHER_ADDR_LEN; ++i)
499 sc->arpcom.ac_enaddr[i] = ed_asic_inb(sc, ED_WD_PROM + i);
500
501 /*
502 * Set upper address bits and 8/16 bit access to shared memory.
503 */
504 if (isa16bit) {
505 if (sc->chip_type == ED_CHIP_TYPE_WD790) {
506 sc->wd_laar_proto = ed_asic_inb(sc, ED_WD_LAAR);
507 } else {
508 sc->wd_laar_proto = ED_WD_LAAR_L16EN |
509 ((kvtop(sc->mem_start) >> 19) & ED_WD_LAAR_ADDRHI);
510 }
511 /*
512 * Enable 16bit access
513 */
514 ed_asic_outb(sc, ED_WD_LAAR, sc->wd_laar_proto |
515 ED_WD_LAAR_M16EN);
516 } else {
517 if (((sc->type & ED_WD_SOFTCONFIG) ||
518 (sc->type == ED_TYPE_TOSHIBA1) ||
519 (sc->type == ED_TYPE_TOSHIBA4) ||
520 (sc->type == ED_TYPE_WD8013EBT)) &&
521 (sc->chip_type != ED_CHIP_TYPE_WD790)) {
522 sc->wd_laar_proto = (kvtop(sc->mem_start) >> 19) &
523 ED_WD_LAAR_ADDRHI;
524 ed_asic_outb(sc, ED_WD_LAAR, sc->wd_laar_proto);
525 }
526 }
527
528 /*
529 * Set address and enable interface shared memory.
530 */
531 if (sc->chip_type != ED_CHIP_TYPE_WD790) {
532 if (ED_FLAGS_GETTYPE(flags) == ED_FLAGS_TOSH_ETHER) {
533 ed_asic_outb(sc, ED_WD_MSR + 1,
534 ((kvtop(sc->mem_start) >> 8) & 0xe0) | 4);
535 ed_asic_outb(sc, ED_WD_MSR + 2,
536 ((kvtop(sc->mem_start) >> 16) & 0x0f));
537 ed_asic_outb(sc, ED_WD_MSR,
538 ED_WD_MSR_MENB | ED_WD_MSR_POW);
539 } else {
540 ed_asic_outb(sc, ED_WD_MSR,
541 ((kvtop(sc->mem_start) >> 13) &
542 ED_WD_MSR_ADDR) | ED_WD_MSR_MENB);
543 }
544 sc->cr_proto = ED_CR_RD2;
545 } else {
546 ed_asic_outb(sc, ED_WD_MSR, ED_WD_MSR_MENB);
547 ed_asic_outb(sc, ED_WD790_HWR, (ed_asic_inb(sc, ED_WD790_HWR) | ED_WD790_HWR_SWH));
548 ed_asic_outb(sc, ED_WD790_RAR, ((kvtop(sc->mem_start) >> 13) & 0x0f) |
549 ((kvtop(sc->mem_start) >> 11) & 0x40) |
550 (ed_asic_inb(sc, ED_WD790_RAR) & 0xb0));
551 ed_asic_outb(sc, ED_WD790_HWR, (ed_asic_inb(sc, ED_WD790_HWR) & ~ED_WD790_HWR_SWH));
552 sc->cr_proto = 0;
553 }
554
555#if 0
556 printf("starting memory performance test at 0x%x, size %d...\n",
557 sc->mem_start, memsize*16384);
558 for (i = 0; i < 16384; i++)
559 bzero(sc->mem_start, memsize);
560 printf("***DONE***\n");
561#endif
562
563 /*
564 * Now zero memory and verify that it is clear
565 */
566 bzero(sc->mem_start, memsize);
567
568 for (i = 0; i < memsize; ++i) {
569 if (sc->mem_start[i]) {
570 device_printf(dev, "failed to clear shared memory at %lx - check configuration\n",
571 kvtop(sc->mem_start + i));
572
573 /*
574 * Disable 16 bit access to shared memory
575 */
576 if (isa16bit) {
577 if (sc->chip_type == ED_CHIP_TYPE_WD790) {
578 ed_asic_outb(sc, ED_WD_MSR, 0x00);
579 }
580 ed_asic_outb(sc, ED_WD_LAAR, sc->wd_laar_proto &
581 ~ED_WD_LAAR_M16EN);
582 }
583 return (ENXIO);
584 }
585 }
586
587 /*
588 * Disable 16bit access to shared memory - we leave it
589 * disabled so that 1) machines reboot properly when the board
590 * is set 16 bit mode and there are conflicting 8bit
591 * devices/ROMS in the same 128k address space as this boards
592 * shared memory. and 2) so that other 8 bit devices with
593 * shared memory can be used in this 128k region, too.
594 */
595 if (isa16bit) {
596 if (sc->chip_type == ED_CHIP_TYPE_WD790) {
597 ed_asic_outb(sc, ED_WD_MSR, 0x00);
598 }
599 ed_asic_outb(sc, ED_WD_LAAR, sc->wd_laar_proto &
600 ~ED_WD_LAAR_M16EN);
601 }
602 return (0);
603}
604
605int
606ed_probe_WD80x3(dev, port_rid, flags)
607 device_t dev;
608 int port_rid;
609 int flags;
610{
611 struct ed_softc *sc = device_get_softc(dev);
612 int error;
613 static unsigned short *intr_vals[] = {ed_intr_val, ed_790_intr_val};
614
615 error = ed_alloc_port(dev, port_rid, ED_WD_IO_PORTS);
616 if (error)
617 return (error);
618
619 sc->asic_offset = ED_WD_ASIC_OFFSET;
620 sc->nic_offset = ED_WD_NIC_OFFSET;
621
622 return ed_probe_WD80x3_generic(dev, flags, intr_vals);
623}
624
625/*
626 * Probe and vendor-specific initialization routine for 3Com 3c503 boards
627 */
628int
629ed_probe_3Com(dev, port_rid, flags)
630 device_t dev;
631 int port_rid;
632 int flags;
633{
634 struct ed_softc *sc = device_get_softc(dev);
635 int error;
636 int i;
637 u_int memsize;
638 u_char isa16bit;
639 u_long conf_maddr, conf_msize, irq, junk;
640
641 error = ed_alloc_port(dev, 0, ED_3COM_IO_PORTS);
642 if (error)
643 return (error);
644
645 sc->asic_offset = ED_3COM_ASIC_OFFSET;
646 sc->nic_offset = ED_3COM_NIC_OFFSET;
647
648 /*
649 * Verify that the kernel configured I/O address matches the board
650 * configured address
651 */
652 switch (ed_asic_inb(sc, ED_3COM_BCFR)) {
653 case ED_3COM_BCFR_300:
654 if (rman_get_start(sc->port_res) != 0x300)
655 return (ENXIO);
656 break;
657 case ED_3COM_BCFR_310:
658 if (rman_get_start(sc->port_res) != 0x310)
659 return (ENXIO);
660 break;
661 case ED_3COM_BCFR_330:
662 if (rman_get_start(sc->port_res) != 0x330)
663 return (ENXIO);
664 break;
665 case ED_3COM_BCFR_350:
666 if (rman_get_start(sc->port_res) != 0x350)
667 return (ENXIO);
668 break;
669 case ED_3COM_BCFR_250:
670 if (rman_get_start(sc->port_res) != 0x250)
671 return (ENXIO);
672 break;
673 case ED_3COM_BCFR_280:
674 if (rman_get_start(sc->port_res) != 0x280)
675 return (ENXIO);
676 break;
677 case ED_3COM_BCFR_2A0:
678 if (rman_get_start(sc->port_res) != 0x2a0)
679 return (ENXIO);
680 break;
681 case ED_3COM_BCFR_2E0:
682 if (rman_get_start(sc->port_res) != 0x2e0)
683 return (ENXIO);
684 break;
685 default:
686 return (ENXIO);
687 }
688
689 error = bus_get_resource(dev, SYS_RES_MEMORY, 0,
690 &conf_maddr, &conf_msize);
691 if (error)
692 return (error);
693
694 /*
695 * Verify that the kernel shared memory address matches the board
696 * configured address.
697 */
698 switch (ed_asic_inb(sc, ED_3COM_PCFR)) {
699 case ED_3COM_PCFR_DC000:
700 if (conf_maddr != 0xdc000)
701 return (ENXIO);
702 break;
703 case ED_3COM_PCFR_D8000:
704 if (conf_maddr != 0xd8000)
705 return (ENXIO);
706 break;
707 case ED_3COM_PCFR_CC000:
708 if (conf_maddr != 0xcc000)
709 return (ENXIO);
710 break;
711 case ED_3COM_PCFR_C8000:
712 if (conf_maddr != 0xc8000)
713 return (ENXIO);
714 break;
715 default:
716 return (ENXIO);
717 }
718
719
720 /*
721 * Reset NIC and ASIC. Enable on-board transceiver throughout reset
722 * sequence because it'll lock up if the cable isn't connected if we
723 * don't.
724 */
725 ed_asic_outb(sc, ED_3COM_CR, ED_3COM_CR_RST | ED_3COM_CR_XSEL);
726
727 /*
728 * Wait for a while, then un-reset it
729 */
730 DELAY(50);
731
732 /*
733 * The 3Com ASIC defaults to rather strange settings for the CR after
734 * a reset - it's important to set it again after the following outb
735 * (this is done when we map the PROM below).
736 */
737 ed_asic_outb(sc, ED_3COM_CR, ED_3COM_CR_XSEL);
738
739 /*
740 * Wait a bit for the NIC to recover from the reset
741 */
742 DELAY(5000);
743
744 sc->vendor = ED_VENDOR_3COM;
745 sc->type_str = "3c503";
746 sc->mem_shared = 1;
747 sc->cr_proto = ED_CR_RD2;
748
749 /*
750 * Hmmm...a 16bit 3Com board has 16k of memory, but only an 8k window
751 * to it.
752 */
753 memsize = 8192;
754
755 /*
756 * Get station address from on-board ROM
757 */
758
759 /*
760 * First, map ethernet address PROM over the top of where the NIC
761 * registers normally appear.
762 */
763 ed_asic_outb(sc, ED_3COM_CR, ED_3COM_CR_EALO | ED_3COM_CR_XSEL);
764
765 for (i = 0; i < ETHER_ADDR_LEN; ++i)
766 sc->arpcom.ac_enaddr[i] = ed_nic_inb(sc, i);
767
768 /*
769 * Unmap PROM - select NIC registers. The proper setting of the
770 * tranceiver is set in ed_init so that the attach code is given a
771 * chance to set the default based on a compile-time config option
772 */
773 ed_asic_outb(sc, ED_3COM_CR, ED_3COM_CR_XSEL);
774
775 /*
776 * Determine if this is an 8bit or 16bit board
777 */
778
779 /*
780 * select page 0 registers
781 */
782 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP);
783
784 /*
785 * Attempt to clear WTS bit. If it doesn't clear, then this is a 16bit
786 * board.
787 */
788 ed_nic_outb(sc, ED_P0_DCR, 0);
789
790 /*
791 * select page 2 registers
792 */
793 ed_nic_outb(sc, ED_P0_CR, ED_CR_PAGE_2 | ED_CR_RD2 | ED_CR_STP);
794
795 /*
796 * The 3c503 forces the WTS bit to a one if this is a 16bit board
797 */
798 if (ed_nic_inb(sc, ED_P2_DCR) & ED_DCR_WTS)
799 isa16bit = 1;
800 else
801 isa16bit = 0;
802
803 /*
804 * select page 0 registers
805 */
806 ed_nic_outb(sc, ED_P2_CR, ED_CR_RD2 | ED_CR_STP);
807
808 error = ed_alloc_memory(dev, 0, memsize);
809 if (error)
810 return (error);
811
812 sc->mem_start = (caddr_t) rman_get_virtual(sc->mem_res);
813 sc->mem_size = memsize;
814 sc->mem_end = sc->mem_start + memsize;
815
816 /*
817 * We have an entire 8k window to put the transmit buffers on the
818 * 16bit boards. But since the 16bit 3c503's shared memory is only
819 * fast enough to overlap the loading of one full-size packet, trying
820 * to load more than 2 buffers can actually leave the transmitter idle
821 * during the load. So 2 seems the best value. (Although a mix of
822 * variable-sized packets might change this assumption. Nonetheless,
823 * we optimize for linear transfers of same-size packets.)
824 */
825 if (isa16bit) {
826 if (flags & ED_FLAGS_NO_MULTI_BUFFERING)
827 sc->txb_cnt = 1;
828 else
829 sc->txb_cnt = 2;
830
831 sc->tx_page_start = ED_3COM_TX_PAGE_OFFSET_16BIT;
832 sc->rec_page_start = ED_3COM_RX_PAGE_OFFSET_16BIT;
833 sc->rec_page_stop = memsize / ED_PAGE_SIZE +
834 ED_3COM_RX_PAGE_OFFSET_16BIT;
835 sc->mem_ring = sc->mem_start;
836 } else {
837 sc->txb_cnt = 1;
838 sc->tx_page_start = ED_3COM_TX_PAGE_OFFSET_8BIT;
839 sc->rec_page_start = ED_TXBUF_SIZE + ED_3COM_TX_PAGE_OFFSET_8BIT;
840 sc->rec_page_stop = memsize / ED_PAGE_SIZE +
841 ED_3COM_TX_PAGE_OFFSET_8BIT;
842 sc->mem_ring = sc->mem_start + (ED_PAGE_SIZE * ED_TXBUF_SIZE);
843 }
844
845 sc->isa16bit = isa16bit;
846
847 /*
848 * Initialize GA page start/stop registers. Probably only needed if
849 * doing DMA, but what the hell.
850 */
851 ed_asic_outb(sc, ED_3COM_PSTR, sc->rec_page_start);
852 ed_asic_outb(sc, ED_3COM_PSPR, sc->rec_page_stop);
853
854 /*
855 * Set IRQ. 3c503 only allows a choice of irq 2-5.
856 */
857 error = bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, &junk);
858 if (error)
859 return (error);
860
861 switch (irq) {
862 case 2:
863 case 9:
864 ed_asic_outb(sc, ED_3COM_IDCFR, ED_3COM_IDCFR_IRQ2);
865 break;
866 case 3:
867 ed_asic_outb(sc, ED_3COM_IDCFR, ED_3COM_IDCFR_IRQ3);
868 break;
869 case 4:
870 ed_asic_outb(sc, ED_3COM_IDCFR, ED_3COM_IDCFR_IRQ4);
871 break;
872 case 5:
873 ed_asic_outb(sc, ED_3COM_IDCFR, ED_3COM_IDCFR_IRQ5);
874 break;
875 default:
876 device_printf(dev, "Invalid irq configuration (%ld) must be 3-5,9 for 3c503\n",
877 irq);
878 return (ENXIO);
879 }
880
881 /*
882 * Initialize GA configuration register. Set bank and enable shared
883 * mem.
884 */
885 ed_asic_outb(sc, ED_3COM_GACFR, ED_3COM_GACFR_RSEL |
886 ED_3COM_GACFR_MBS0);
887
888 /*
889 * Initialize "Vector Pointer" registers. These gawd-awful things are
890 * compared to 20 bits of the address on ISA, and if they match, the
891 * shared memory is disabled. We set them to 0xffff0...allegedly the
892 * reset vector.
893 */
894 ed_asic_outb(sc, ED_3COM_VPTR2, 0xff);
895 ed_asic_outb(sc, ED_3COM_VPTR1, 0xff);
896 ed_asic_outb(sc, ED_3COM_VPTR0, 0x00);
897
898 /*
899 * Zero memory and verify that it is clear
900 */
901 bzero(sc->mem_start, memsize);
902
903 for (i = 0; i < memsize; ++i)
904 if (sc->mem_start[i]) {
905 device_printf(dev, "failed to clear shared memory at %lx - check configuration\n",
906 kvtop(sc->mem_start + i));
907 return (ENXIO);
908 }
909 return (0);
910}
911
912/*
913 * Probe and vendor-specific initialization routine for NE1000/2000 boards
914 */
915int
916ed_probe_Novell_generic(dev, flags)
917 device_t dev;
918 int flags;
919{
920 struct ed_softc *sc = device_get_softc(dev);
921 u_int memsize, n;
922 u_char romdata[16], tmp;
923 static char test_pattern[32] = "THIS is A memory TEST pattern";
924 char test_buffer[32];
925
926 /* XXX - do Novell-specific probe here */
927
928 /* Reset the board */
929 if (ED_FLAGS_GETTYPE(flags) == ED_FLAGS_GWETHER) {
930 ed_asic_outb(sc, ED_NOVELL_RESET, 0);
931 DELAY(200);
932 }
933 tmp = ed_asic_inb(sc, ED_NOVELL_RESET);
934
935 /*
936 * I don't know if this is necessary; probably cruft leftover from
937 * Clarkson packet driver code. Doesn't do a thing on the boards I've
938 * tested. -DG [note that a outb(0x84, 0) seems to work here, and is
939 * non-invasive...but some boards don't seem to reset and I don't have
940 * complete documentation on what the 'right' thing to do is...so we
941 * do the invasive thing for now. Yuck.]
942 */
943 ed_asic_outb(sc, ED_NOVELL_RESET, tmp);
944 DELAY(5000);
945
946 /*
947 * This is needed because some NE clones apparently don't reset the
948 * NIC properly (or the NIC chip doesn't reset fully on power-up) XXX
949 * - this makes the probe invasive! ...Done against my better
950 * judgement. -DLG
951 */
952 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP);
953
954 DELAY(5000);
955
956 /* Make sure that we really have an 8390 based board */
957 if (!ed_probe_generic8390(sc))
958 return (ENXIO);
959
960 sc->vendor = ED_VENDOR_NOVELL;
961 sc->mem_shared = 0;
962 sc->cr_proto = ED_CR_RD2;
963
964 /*
965 * Test the ability to read and write to the NIC memory. This has the
966 * side affect of determining if this is an NE1000 or an NE2000.
967 */
968
969 /*
970 * This prevents packets from being stored in the NIC memory when the
971 * readmem routine turns on the start bit in the CR.
972 */
973 ed_nic_outb(sc, ED_P0_RCR, ED_RCR_MON);
974
975 /* Temporarily initialize DCR for byte operations */
976 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
977
978 ed_nic_outb(sc, ED_P0_PSTART, 8192 / ED_PAGE_SIZE);
979 ed_nic_outb(sc, ED_P0_PSTOP, 16384 / ED_PAGE_SIZE);
980
981 sc->isa16bit = 0;
982
983 /*
984 * Write a test pattern in byte mode. If this fails, then there
985 * probably isn't any memory at 8k - which likely means that the board
986 * is an NE2000.
987 */
988 ed_pio_writemem(sc, test_pattern, 8192, sizeof(test_pattern));
989 ed_pio_readmem(sc, 8192, test_buffer, sizeof(test_pattern));
990
991 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern)) == 0) {
992 sc->type = ED_TYPE_NE1000;
993 sc->type_str = "NE1000";
994 } else {
995
996 /* neither an NE1000 nor a Linksys - try NE2000 */
997 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS);
998 ed_nic_outb(sc, ED_P0_PSTART, 16384 / ED_PAGE_SIZE);
999 ed_nic_outb(sc, ED_P0_PSTOP, 32768 / ED_PAGE_SIZE);
1000
1001 sc->isa16bit = 1;
1002
1003 /*
1004 * Write a test pattern in word mode. If this also fails, then
1005 * we don't know what this board is.
1006 */
1007 ed_pio_writemem(sc, test_pattern, 16384, sizeof(test_pattern));
1008 ed_pio_readmem(sc, 16384, test_buffer, sizeof(test_pattern));
1009 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern)) == 0) {
1010 sc->type = ED_TYPE_NE2000;
1011 sc->type_str = "NE2000";
1012 } else {
1013 return (ENXIO);
1014 }
1015 }
1016
1017
1018 /* 8k of memory plus an additional 8k if 16bit */
1019 memsize = 8192 + sc->isa16bit * 8192;
1020
1021#if 0 /* probably not useful - NE boards only come two ways */
1022 /* allow kernel config file overrides */
1023 if (isa_dev->id_msize)
1024 memsize = isa_dev->id_msize;
1025#endif
1026
1027 sc->mem_size = memsize;
1028
1029 /* NIC memory doesn't start at zero on an NE board */
1030 /* The start address is tied to the bus width */
1031 sc->mem_start = (char *) 8192 + sc->isa16bit * 8192;
1032 sc->mem_end = sc->mem_start + memsize;
1033 sc->tx_page_start = memsize / ED_PAGE_SIZE;
1034
1035 if (ED_FLAGS_GETTYPE(flags) == ED_FLAGS_GWETHER) {
1036 int x, i, mstart = 0, msize = 0;
1037 char pbuf0[ED_PAGE_SIZE], pbuf[ED_PAGE_SIZE], tbuf[ED_PAGE_SIZE];
1038
1039 for (i = 0; i < ED_PAGE_SIZE; i++)
1040 pbuf0[i] = 0;
1041
1042 /* Clear all the memory. */
1043 for (x = 1; x < 256; x++)
1044 ed_pio_writemem(sc, pbuf0, x * 256, ED_PAGE_SIZE);
1045
1046 /* Search for the start of RAM. */
1047 for (x = 1; x < 256; x++) {
1048 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE);
1049 if (bcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) {
1050 for (i = 0; i < ED_PAGE_SIZE; i++)
1051 pbuf[i] = 255 - x;
1052 ed_pio_writemem(sc, pbuf, x * 256, ED_PAGE_SIZE);
1053 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE);
1054 if (bcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0) {
1055 mstart = x * ED_PAGE_SIZE;
1056 msize = ED_PAGE_SIZE;
1057 break;
1058 }
1059 }
1060 }
1061
1062 if (mstart == 0) {
1063 device_printf(dev, "Cannot find start of RAM.\n");
1064 return (ENXIO);
1065 }
1066 /* Search for the start of RAM. */
1067 for (x = (mstart / ED_PAGE_SIZE) + 1; x < 256; x++) {
1068 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE);
1069 if (bcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) {
1070 for (i = 0; i < ED_PAGE_SIZE; i++)
1071 pbuf[i] = 255 - x;
1072 ed_pio_writemem(sc, pbuf, x * 256, ED_PAGE_SIZE);
1073 ed_pio_readmem(sc, x * 256, tbuf, ED_PAGE_SIZE);
1074 if (bcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0)
1075 msize += ED_PAGE_SIZE;
1076 else {
1077 break;
1078 }
1079 } else {
1080 break;
1081 }
1082 }
1083
1084 if (msize == 0) {
1085 device_printf(dev, "Cannot find any RAM, start : %d, x = %d.\n", mstart, x);
1086 return (ENXIO);
1087 }
1088 device_printf(dev, "RAM start at %d, size : %d.\n", mstart, msize);
1089
1090 sc->mem_size = msize;
1091 sc->mem_start = (caddr_t) mstart;
1092 sc->mem_end = (caddr_t) (msize + mstart);
1093 sc->tx_page_start = mstart / ED_PAGE_SIZE;
1094 }
1095
1096 /*
1097 * Use one xmit buffer if < 16k, two buffers otherwise (if not told
1098 * otherwise).
1099 */
1100 if ((memsize < 16384) || (flags & ED_FLAGS_NO_MULTI_BUFFERING))
1101 sc->txb_cnt = 1;
1102 else
1103 sc->txb_cnt = 2;
1104
1105 sc->rec_page_start = sc->tx_page_start + sc->txb_cnt * ED_TXBUF_SIZE;
1106 sc->rec_page_stop = sc->tx_page_start + memsize / ED_PAGE_SIZE;
1107
1108 sc->mem_ring = sc->mem_start + sc->txb_cnt * ED_PAGE_SIZE * ED_TXBUF_SIZE;
1109
1110 ed_pio_readmem(sc, 0, romdata, 16);
1111 for (n = 0; n < ETHER_ADDR_LEN; n++)
1112 sc->arpcom.ac_enaddr[n] = romdata[n * (sc->isa16bit + 1)];
1113
1114 if ((ED_FLAGS_GETTYPE(flags) == ED_FLAGS_GWETHER) &&
1115 (sc->arpcom.ac_enaddr[2] == 0x86)) {
1116 sc->type_str = "Gateway AT";
1117 }
1118
1119 /* clear any pending interrupts that might have occurred above */
1120 ed_nic_outb(sc, ED_P0_ISR, 0xff);
1121
1122 return (0);
1123}
1124
1125int
1126ed_probe_Novell(dev, port_rid, flags)
1127 device_t dev;
1128 int port_rid;
1129 int flags;
1130{
1131 struct ed_softc *sc = device_get_softc(dev);
1132 int error;
1133
1134 error = ed_alloc_port(dev, port_rid, ED_NOVELL_IO_PORTS);
1135 if (error)
1136 return (error);
1137
1138 sc->asic_offset = ED_NOVELL_ASIC_OFFSET;
1139 sc->nic_offset = ED_NOVELL_NIC_OFFSET;
1140
1141 return ed_probe_Novell_generic(dev, flags);
1142}
1143
1144#define ED_HPP_TEST_SIZE 16
1145
1146/*
1147 * Probe and vendor specific initialization for the HP PC Lan+ Cards.
1148 * (HP Part nos: 27247B and 27252A).
1149 *
1150 * The card has an asic wrapper around a DS8390 core. The asic handles
1151 * host accesses and offers both standard register IO and memory mapped
1152 * IO. Memory mapped I/O allows better performance at the expense of greater
1153 * chance of an incompatibility with existing ISA cards.
1154 *
1155 * The card has a few caveats: it isn't tolerant of byte wide accesses, only
1156 * short (16 bit) or word (32 bit) accesses are allowed. Some card revisions
1157 * don't allow 32 bit accesses; these are indicated by a bit in the software
1158 * ID register (see if_edreg.h).
1159 *
1160 * Other caveats are: we should read the MAC address only when the card
1161 * is inactive.
1162 *
1163 * For more information; please consult the CRYNWR packet driver.
1164 *
1165 * The AUI port is turned on using the "link2" option on the ifconfig
1166 * command line.
1167 */
1168int
1169ed_probe_HP_pclanp(dev, port_rid, flags)
1170 device_t dev;
1171 int port_rid;
1172 int flags;
1173{
1174 struct ed_softc *sc = device_get_softc(dev);
1175 int error;
1176 int n; /* temp var */
1177 int memsize; /* mem on board */
1178 u_char checksum; /* checksum of board address */
1179 u_char irq; /* board configured IRQ */
1180 char test_pattern[ED_HPP_TEST_SIZE]; /* read/write areas for */
1181 char test_buffer[ED_HPP_TEST_SIZE]; /* probing card */
1182 u_long conf_maddr, conf_msize, conf_irq, junk;
1183
1184 error = ed_alloc_port(dev, 0, ED_HPP_IO_PORTS);
1185 if (error)
1186 return (error);
1187
1188 /* Fill in basic information */
1189 sc->asic_offset = ED_HPP_ASIC_OFFSET;
1190 sc->nic_offset = ED_HPP_NIC_OFFSET;
1191
1192 sc->chip_type = ED_CHIP_TYPE_DP8390;
1193 sc->isa16bit = 0; /* the 8390 core needs to be in byte mode */
1194
1195 /*
1196 * Look for the HP PCLAN+ signature: "0x50,0x48,0x00,0x53"
1197 */
1198
1199 if ((ed_asic_inb(sc, ED_HPP_ID) != 0x50) ||
1200 (ed_asic_inb(sc, ED_HPP_ID + 1) != 0x48) ||
1201 ((ed_asic_inb(sc, ED_HPP_ID + 2) & 0xF0) != 0) ||
1202 (ed_asic_inb(sc, ED_HPP_ID + 3) != 0x53))
1203 return ENXIO;
1204
1205 /*
1206 * Read the MAC address and verify checksum on the address.
1207 */
1208
1209 ed_asic_outw(sc, ED_HPP_PAGING, ED_HPP_PAGE_MAC);
1210 for (n = 0, checksum = 0; n < ETHER_ADDR_LEN; n++)
1211 checksum += (sc->arpcom.ac_enaddr[n] =
1212 ed_asic_inb(sc, ED_HPP_MAC_ADDR + n));
1213
1214 checksum += ed_asic_inb(sc, ED_HPP_MAC_ADDR + ETHER_ADDR_LEN);
1215
1216 if (checksum != 0xFF)
1217 return ENXIO;
1218
1219 /*
1220 * Verify that the software model number is 0.
1221 */
1222
1223 ed_asic_outw(sc, ED_HPP_PAGING, ED_HPP_PAGE_ID);
1224 if (((sc->hpp_id = ed_asic_inw(sc, ED_HPP_PAGE_4)) &
1225 ED_HPP_ID_SOFT_MODEL_MASK) != 0x0000)
1226 return ENXIO;
1227
1228 /*
1229 * Read in and save the current options configured on card.
1230 */
1231
1232 sc->hpp_options = ed_asic_inw(sc, ED_HPP_OPTION);
1233
1234 sc->hpp_options |= (ED_HPP_OPTION_NIC_RESET |
1235 ED_HPP_OPTION_CHIP_RESET |
1236 ED_HPP_OPTION_ENABLE_IRQ);
1237
1238 /*
1239 * Reset the chip. This requires writing to the option register
1240 * so take care to preserve the other bits.
1241 */
1242
1243 ed_asic_outw(sc, ED_HPP_OPTION,
1244 (sc->hpp_options & ~(ED_HPP_OPTION_NIC_RESET |
1245 ED_HPP_OPTION_CHIP_RESET)));
1246
1247 DELAY(5000); /* wait for chip reset to complete */
1248
1249 ed_asic_outw(sc, ED_HPP_OPTION,
1250 (sc->hpp_options | (ED_HPP_OPTION_NIC_RESET |
1251 ED_HPP_OPTION_CHIP_RESET |
1252 ED_HPP_OPTION_ENABLE_IRQ)));
1253
1254 DELAY(5000);
1255
1256 if (!(ed_nic_inb(sc, ED_P0_ISR) & ED_ISR_RST))
1257 return ENXIO; /* reset did not complete */
1258
1259 /*
1260 * Read out configuration information.
1261 */
1262
1263 ed_asic_outw(sc, ED_HPP_PAGING, ED_HPP_PAGE_HW);
1264
1265 irq = ed_asic_inb(sc, ED_HPP_HW_IRQ);
1266
1267 /*
1268 * Check for impossible IRQ.
1269 */
1270
1271 if (irq >= (sizeof(ed_hpp_intr_val) / sizeof(ed_hpp_intr_val[0])))
1272 return ENXIO;
1273
1274 /*
1275 * If the kernel IRQ was specified with a '?' use the cards idea
1276 * of the IRQ. If the kernel IRQ was explicitly specified, it
1277 * should match that of the hardware.
1278 */
1279 error = bus_get_resource(dev, SYS_RES_IRQ, 0,
1280 &conf_irq, &junk);
1281 if (error) {
1282 bus_set_resource(dev, SYS_RES_IRQ, 0,
1283 ed_hpp_intr_val[irq], 1);
1284 } else {
1285 if (conf_irq != ed_hpp_intr_val[irq])
1286 return (ENXIO);
1287 }
1288
1289 /*
1290 * Fill in softconfig info.
1291 */
1292
1293 sc->vendor = ED_VENDOR_HP;
1294 sc->type = ED_TYPE_HP_PCLANPLUS;
1295 sc->type_str = "HP-PCLAN+";
1296
1297 sc->mem_shared = 0; /* we DON'T have dual ported RAM */
1298 sc->mem_start = 0; /* we use offsets inside the card RAM */
1299
1300 sc->hpp_mem_start = NULL;/* no memory mapped I/O by default */
1301
1302 /*
1303 * The board has 32KB of memory. Is there a way to determine
1304 * this programmatically?
1305 */
1306
1307 memsize = 32768;
1308
1309 /*
1310 * Check if memory mapping of the I/O registers possible.
1311 */
1312
1313 if (sc->hpp_options & ED_HPP_OPTION_MEM_ENABLE)
1314 {
1315 u_long mem_addr;
1316
1317 /*
1318 * determine the memory address from the board.
1319 */
1320
1321 ed_asic_outw(sc, ED_HPP_PAGING, ED_HPP_PAGE_HW);
1322 mem_addr = (ed_asic_inw(sc, ED_HPP_HW_MEM_MAP) << 8);
1323
1324 /*
1325 * Check that the kernel specified start of memory and
1326 * hardware's idea of it match.
1327 */
1328 error = bus_get_resource(dev, SYS_RES_MEMORY, 0,
1329 &conf_maddr, &conf_msize);
1330 if (error)
1331 return (error);
1332
1333 if (mem_addr != conf_maddr)
1334 return ENXIO;
1335
1336 error = ed_alloc_memory(dev, 0, memsize);
1337 if (error)
1338 return (error);
1339
1340 sc->hpp_mem_start = rman_get_virtual(sc->mem_res);
1341 }
1342
1343 /*
1344 * Fill in the rest of the soft config structure.
1345 */
1346
1347 /*
1348 * The transmit page index.
1349 */
1350
1351 sc->tx_page_start = ED_HPP_TX_PAGE_OFFSET;
1352
1353 if (device_get_flags(dev) & ED_FLAGS_NO_MULTI_BUFFERING)
1354 sc->txb_cnt = 1;
1355 else
1356 sc->txb_cnt = 2;
1357
1358 /*
1359 * Memory description
1360 */
1361
1362 sc->mem_size = memsize;
1363 sc->mem_ring = sc->mem_start +
1364 (sc->txb_cnt * ED_PAGE_SIZE * ED_TXBUF_SIZE);
1365 sc->mem_end = sc->mem_start + sc->mem_size;
1366
1367 /*
1368 * Receive area starts after the transmit area and
1369 * continues till the end of memory.
1370 */
1371
1372 sc->rec_page_start = sc->tx_page_start +
1373 (sc->txb_cnt * ED_TXBUF_SIZE);
1374 sc->rec_page_stop = (sc->mem_size / ED_PAGE_SIZE);
1375
1376
1377 sc->cr_proto = 0; /* value works */
1378
1379 /*
1380 * Set the wrap registers for string I/O reads.
1381 */
1382
1383 ed_asic_outw(sc, ED_HPP_PAGING, ED_HPP_PAGE_HW);
1384 ed_asic_outw(sc, ED_HPP_HW_WRAP,
1385 ((sc->rec_page_start / ED_PAGE_SIZE) |
1386 (((sc->rec_page_stop / ED_PAGE_SIZE) - 1) << 8)));
1387
1388 /*
1389 * Reset the register page to normal operation.
1390 */
1391
1392 ed_asic_outw(sc, ED_HPP_PAGING, ED_HPP_PAGE_PERF);
1393
1394 /*
1395 * Verify that we can read/write from adapter memory.
1396 * Create test pattern.
1397 */
1398
1399 for (n = 0; n < ED_HPP_TEST_SIZE; n++)
1400 {
1401 test_pattern[n] = (n*n) ^ ~n;
1402 }
1403
1404#undef ED_HPP_TEST_SIZE
1405
1406 /*
1407 * Check that the memory is accessible thru the I/O ports.
1408 * Write out the contents of "test_pattern", read back
1409 * into "test_buffer" and compare the two for any
1410 * mismatch.
1411 */
1412
1413 for (n = 0; n < (32768 / ED_PAGE_SIZE); n ++) {
1414
1415 ed_hpp_writemem(sc, test_pattern, (n * ED_PAGE_SIZE),
1416 sizeof(test_pattern));
1417 ed_hpp_readmem(sc, (n * ED_PAGE_SIZE),
1418 test_buffer, sizeof(test_pattern));
1419
1420 if (bcmp(test_pattern, test_buffer,
1421 sizeof(test_pattern)))
1422 return ENXIO;
1423 }
1424
1425 return (ED_HPP_IO_PORTS);
1426
1427}
1428
1429/*
1430 * HP PC Lan+ : Set the physical link to use AUI or TP/TL.
1431 */
1432
1433void
1434ed_hpp_set_physical_link(struct ed_softc *sc)
1435{
1436 struct ifnet *ifp = &sc->arpcom.ac_if;
1437 int lan_page;
1438
1439 ed_asic_outw(sc, ED_HPP_PAGING, ED_HPP_PAGE_LAN);
1440 lan_page = ed_asic_inw(sc, ED_HPP_PAGE_0);
1441
1442 if (ifp->if_flags & IFF_ALTPHYS) {
1443
1444 /*
1445 * Use the AUI port.
1446 */
1447
1448 lan_page |= ED_HPP_LAN_AUI;
1449
1450 ed_asic_outw(sc, ED_HPP_PAGING, ED_HPP_PAGE_LAN);
1451 ed_asic_outw(sc, ED_HPP_PAGE_0, lan_page);
1452
1453
1454 } else {
1455
1456 /*
1457 * Use the ThinLan interface
1458 */
1459
1460 lan_page &= ~ED_HPP_LAN_AUI;
1461
1462 ed_asic_outw(sc, ED_HPP_PAGING, ED_HPP_PAGE_LAN);
1463 ed_asic_outw(sc, ED_HPP_PAGE_0, lan_page);
1464
1465 }
1466
1467 /*
1468 * Wait for the lan card to re-initialize itself
1469 */
1470
1471 DELAY(150000); /* wait 150 ms */
1472
1473 /*
1474 * Restore normal pages.
1475 */
1476
1477 ed_asic_outw(sc, ED_HPP_PAGING, ED_HPP_PAGE_PERF);
1478
1479}
1480
1481/*
1482 * Allocate a port resource with the given resource id.
1483 */
1484int
1485ed_alloc_port(dev, rid, size)
1486 device_t dev;
1487 int rid;
1488 int size;
1489{
1490 struct ed_softc *sc = device_get_softc(dev);
1491 struct resource *res;
1492
1493 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
1494 0ul, ~0ul, size, RF_ACTIVE);
1495 if (res) {
1496 sc->port_rid = rid;
1497 sc->port_res = res;
1498 sc->port_used = size;
1499 return (0);
1500 } else {
1501 return (ENOENT);
1502 }
1503}
1504
1505/*
1506 * Allocate a memory resource with the given resource id.
1507 */
1508int
1509ed_alloc_memory(dev, rid, size)
1510 device_t dev;
1511 int rid;
1512 int size;
1513{
1514 struct ed_softc *sc = device_get_softc(dev);
1515 struct resource *res;
1516
1517 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
1518 0ul, ~0ul, size, RF_ACTIVE);
1519 if (res) {
1520 sc->mem_rid = rid;
1521 sc->mem_res = res;
1522 sc->mem_used = size;
1523 return (0);
1524 } else {
1525 return (ENOENT);
1526 }
1527}
1528
1529/*
1530 * Allocate an irq resource with the given resource id.
1531 */
1532int
1533ed_alloc_irq(dev, rid, flags)
1534 device_t dev;
1535 int rid;
1536 int flags;
1537{
1538 struct ed_softc *sc = device_get_softc(dev);
1539 struct resource *res;
1540
1541 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
1542 0ul, ~0ul, 1, (RF_ACTIVE | flags));
1543 if (res) {
1544 sc->irq_rid = rid;
1545 sc->irq_res = res;
1546 return (0);
1547 } else {
1548 return (ENOENT);
1549 }
1550}
1551
1552/*
1553 * Release all resources
1554 */
1555void
1556ed_release_resources(dev)
1557 device_t dev;
1558{
1559 struct ed_softc *sc = device_get_softc(dev);
1560
1561 if (sc->port_res) {
1562 bus_deactivate_resource(dev, SYS_RES_IOPORT,
1563 sc->port_rid, sc->port_res);
1564 bus_release_resource(dev, SYS_RES_IOPORT,
1565 sc->port_rid, sc->port_res);
1566 sc->port_res = 0;
1567 }
1568 if (sc->mem_res) {
1569 bus_deactivate_resource(dev, SYS_RES_MEMORY,
1570 sc->mem_rid, sc->mem_res);
1571 bus_release_resource(dev, SYS_RES_MEMORY,
1572 sc->mem_rid, sc->mem_res);
1573 sc->mem_res = 0;
1574 }
1575 if (sc->irq_res) {
1576 bus_deactivate_resource(dev, SYS_RES_IRQ,
1577 sc->irq_rid, sc->irq_res);
1578 bus_release_resource(dev, SYS_RES_IRQ,
1579 sc->irq_rid, sc->irq_res);
1580 sc->irq_res = 0;
1581 }
1582}
1583
1584/*
1585 * Install interface into kernel networking data structures
1586 */
1587int
1588ed_attach(sc, unit, flags)
1589 struct ed_softc *sc;
1590 int unit;
1591 int flags;
1592{
1593 struct ifnet *ifp = &sc->arpcom.ac_if;
1594
1595 callout_handle_init(&sc->tick_ch);
1596 /*
1597 * Set interface to stopped condition (reset)
1598 */
1599 ed_stop(sc);
1600
1601 if (!ifp->if_name) {
1602 /*
1603 * Initialize ifnet structure
1604 */
1605 ifp->if_softc = sc;
1606 ifp->if_unit = unit;
1607 ifp->if_name = "ed";
1608 ifp->if_output = ether_output;
1609 ifp->if_start = ed_start;
1610 ifp->if_ioctl = ed_ioctl;
1611 ifp->if_watchdog = ed_watchdog;
1612 ifp->if_init = ed_init;
1613 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
1614 ifp->if_linkmib = &sc->mibdata;
1615 ifp->if_linkmiblen = sizeof sc->mibdata;
1616 /*
1617 * XXX - should do a better job.
1618 */
1619 if (sc->chip_type == ED_CHIP_TYPE_WD790)
1620 sc->mibdata.dot3StatsEtherChipSet =
1621 DOT3CHIPSET(dot3VendorWesternDigital,
1622 dot3ChipSetWesternDigital83C790);
1623 else
1624 sc->mibdata.dot3StatsEtherChipSet =
1625 DOT3CHIPSET(dot3VendorNational,
1626 dot3ChipSetNational8390);
1627 sc->mibdata.dot3Compliance = DOT3COMPLIANCE_COLLS;
1628
1629 /*
1630 * Set default state for ALTPHYS flag (used to disable the
1631 * tranceiver for AUI operation), based on compile-time
1632 * config option.
1633 */
1634 if (flags & ED_FLAGS_DISABLE_TRANCEIVER)
1635 ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX |
1636 IFF_MULTICAST | IFF_ALTPHYS);
1637 else
1638 ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX |
1639 IFF_MULTICAST);
1640
1641 /*
1642 * Attach the interface
1643 */
1644 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
1645 }
1646 /* device attach does transition from UNCONFIGURED to IDLE state */
1647
1648 /*
1649 * Print additional info when attached
1650 */
1651 printf("%s%d: address %6D, ", ifp->if_name, ifp->if_unit,
1652 sc->arpcom.ac_enaddr, ":");
1653
1654 if (sc->type_str && (*sc->type_str != 0))
1655 printf("type %s ", sc->type_str);
1656 else
1657 printf("type unknown (0x%x) ", sc->type);
1658
1659 if (sc->vendor == ED_VENDOR_HP)
1660 printf("(%s %s IO)", (sc->hpp_id & ED_HPP_ID_16_BIT_ACCESS) ?
1661 "16-bit" : "32-bit",
1662 sc->hpp_mem_start ? "memory mapped" : "regular");
1663 else
1664 printf("%s ", sc->isa16bit ? "(16 bit)" : "(8 bit)");
1665
1666 printf("%s\n", (((sc->vendor == ED_VENDOR_3COM) ||
1667 (sc->vendor == ED_VENDOR_HP)) &&
1668 (ifp->if_flags & IFF_ALTPHYS)) ? " tranceiver disabled" : "");
1669
1670 return (0);
1671}
1672
1673/*
1674 * Reset interface.
1675 */
1676static void
1677ed_reset(ifp)
1678 struct ifnet *ifp;
1679{
1680 struct ed_softc *sc = ifp->if_softc;
1681 int s;
1682
1683 if (sc->gone)
1684 return;
1685 s = splimp();
1686
1687 /*
1688 * Stop interface and re-initialize.
1689 */
1690 ed_stop(sc);
1691 ed_init(sc);
1692
1693 (void) splx(s);
1694}
1695
1696/*
1697 * Take interface offline.
1698 */
1699void
1700ed_stop(sc)
1701 struct ed_softc *sc;
1702{
1703 int n = 5000;
1704
1705 untimeout(ed_tick, sc, sc->tick_ch);
1706 callout_handle_init(&sc->tick_ch);
1707 if (sc->gone)
1708 return;
1709 /*
1710 * Stop everything on the interface, and select page 0 registers.
1711 */
1712 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STP);
1713
1714 /*
1715 * Wait for interface to enter stopped state, but limit # of checks to
1716 * 'n' (about 5ms). It shouldn't even take 5us on modern DS8390's, but
1717 * just in case it's an old one.
1718 */
1719 if (sc->chip_type != ED_CHIP_TYPE_AX88190)
1720 while (((ed_nic_inb(sc, ED_P0_ISR) & ED_ISR_RST) == 0) && --n);
1721}
1722
1723/*
1724 * Device timeout/watchdog routine. Entered if the device neglects to
1725 * generate an interrupt after a transmit has been started on it.
1726 */
1727static void
1728ed_watchdog(ifp)
1729 struct ifnet *ifp;
1730{
1731 struct ed_softc *sc = ifp->if_softc;
1732
1733 if (sc->gone)
1734 return;
1735 log(LOG_ERR, "ed%d: device timeout\n", ifp->if_unit);
1736 ifp->if_oerrors++;
1737
1738 ed_reset(ifp);
1739}
1740
1741static void
1742ed_tick(arg)
1743 void *arg;
1744{
1745 struct ed_softc *sc = arg;
1746 struct mii_data *mii;
1747 int s;
1748
1749 if (sc->gone) {
1750 callout_handle_init(&sc->tick_ch);
1751 return;
1752 }
1753 s = splimp();
1754 if (sc->miibus != NULL) {
1755 mii = device_get_softc(sc->miibus);
1756 mii_tick(mii);
1757 }
1758 sc->tick_ch = timeout(ed_tick, sc, hz);
1759 splx(s);
1760}
1761
1762/*
1763 * Initialize device.
1764 */
1765static void
1766ed_init(xsc)
1767 void *xsc;
1768{
1769 struct ed_softc *sc = xsc;
1770 struct ifnet *ifp = &sc->arpcom.ac_if;
1771 int i, s;
1772
1773 if (sc->gone)
1774 return;
1775
1776 /* address not known */
1777 if (TAILQ_EMPTY(&ifp->if_addrhead)) /* unlikely? XXX */
1778 return;
1779
1780 /*
1781 * Initialize the NIC in the exact order outlined in the NS manual.
1782 * This init procedure is "mandatory"...don't change what or when
1783 * things happen.
1784 */
1785 s = splimp();
1786
1787 /* reset transmitter flags */
1788 sc->xmit_busy = 0;
1789 ifp->if_timer = 0;
1790
1791 sc->txb_inuse = 0;
1792 sc->txb_new = 0;
1793 sc->txb_next_tx = 0;
1794
1795 /* This variable is used below - don't move this assignment */
1796 sc->next_packet = sc->rec_page_start + 1;
1797
1798 /*
1799 * Set interface for page 0, Remote DMA complete, Stopped
1800 */
1801 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STP);
1802
1803 if (sc->isa16bit) {
1804
1805 /*
1806 * Set FIFO threshold to 8, No auto-init Remote DMA, byte
1807 * order=80x86, word-wide DMA xfers,
1808 */
1809 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_WTS | ED_DCR_LS);
1810 } else {
1811
1812 /*
1813 * Same as above, but byte-wide DMA xfers
1814 */
1815 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
1816 }
1817
1818 /*
1819 * Clear Remote Byte Count Registers
1820 */
1821 ed_nic_outb(sc, ED_P0_RBCR0, 0);
1822 ed_nic_outb(sc, ED_P0_RBCR1, 0);
1823
1824 /*
1825 * For the moment, don't store incoming packets in memory.
1826 */
1827 ed_nic_outb(sc, ED_P0_RCR, ED_RCR_MON);
1828
1829 /*
1830 * Place NIC in internal loopback mode
1831 */
1832 ed_nic_outb(sc, ED_P0_TCR, ED_TCR_LB0);
1833
1834 /*
1835 * Initialize transmit/receive (ring-buffer) Page Start
1836 */
1837 ed_nic_outb(sc, ED_P0_TPSR, sc->tx_page_start);
1838 ed_nic_outb(sc, ED_P0_PSTART, sc->rec_page_start);
1839 /* Set lower bits of byte addressable framing to 0 */
1840 if (sc->chip_type == ED_CHIP_TYPE_WD790)
1841 ed_nic_outb(sc, 0x09, 0);
1842
1843 /*
1844 * Initialize Receiver (ring-buffer) Page Stop and Boundry
1845 */
1846 ed_nic_outb(sc, ED_P0_PSTOP, sc->rec_page_stop);
1847 ed_nic_outb(sc, ED_P0_BNRY, sc->rec_page_start);
1848
1849 /*
1850 * Clear all interrupts. A '1' in each bit position clears the
1851 * corresponding flag.
1852 */
1853 ed_nic_outb(sc, ED_P0_ISR, 0xff);
1854
1855 /*
1856 * Enable the following interrupts: receive/transmit complete,
1857 * receive/transmit error, and Receiver OverWrite.
1858 *
1859 * Counter overflow and Remote DMA complete are *not* enabled.
1860 */
1861 ed_nic_outb(sc, ED_P0_IMR,
1862 ED_IMR_PRXE | ED_IMR_PTXE | ED_IMR_RXEE | ED_IMR_TXEE | ED_IMR_OVWE);
1863
1864 /*
1865 * Program Command Register for page 1
1866 */
1867 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_PAGE_1 | ED_CR_STP);
1868
1869 /*
1870 * Copy out our station address
1871 */
1872 for (i = 0; i < ETHER_ADDR_LEN; ++i)
1873 ed_nic_outb(sc, ED_P1_PAR(i), sc->arpcom.ac_enaddr[i]);
1874
1875 /*
1876 * Set Current Page pointer to next_packet (initialized above)
1877 */
1878 ed_nic_outb(sc, ED_P1_CURR, sc->next_packet);
1879
1880 /*
1881 * Program Receiver Configuration Register and multicast filter. CR is
1882 * set to page 0 on return.
1883 */
1884 ed_setrcr(sc);
1885
1886 /*
1887 * Take interface out of loopback
1888 */
1889 ed_nic_outb(sc, ED_P0_TCR, 0);
1890
1891 /*
1892 * If this is a 3Com board, the tranceiver must be software enabled
1893 * (there is no settable hardware default).
1894 */
1895 if (sc->vendor == ED_VENDOR_3COM) {
1896 if (ifp->if_flags & IFF_ALTPHYS) {
1897 ed_asic_outb(sc, ED_3COM_CR, 0);
1898 } else {
1899 ed_asic_outb(sc, ED_3COM_CR, ED_3COM_CR_XSEL);
1900 }
1901 }
1902
1903 if (sc->miibus != NULL) {
1904 struct mii_data *mii;
1905 mii = device_get_softc(sc->miibus);
1906 mii_mediachg(mii);
1907 }
1908 /*
1909 * Set 'running' flag, and clear output active flag.
1910 */
1911 ifp->if_flags |= IFF_RUNNING;
1912 ifp->if_flags &= ~IFF_OACTIVE;
1913
1914 /*
1915 * ...and attempt to start output
1916 */
1917 ed_start(ifp);
1918
1919 untimeout(ed_tick, sc, sc->tick_ch);
1920 sc->tick_ch = timeout(ed_tick, sc, hz);
1921 (void) splx(s);
1922}
1923
1924/*
1925 * This routine actually starts the transmission on the interface
1926 */
1927static __inline void
1928ed_xmit(sc)
1929 struct ed_softc *sc;
1930{
1931 struct ifnet *ifp = (struct ifnet *)sc;
1932 unsigned short len;
1933
1934 if (sc->gone)
1935 return;
1936 len = sc->txb_len[sc->txb_next_tx];
1937
1938 /*
1939 * Set NIC for page 0 register access
1940 */
1941 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STA);
1942
1943 /*
1944 * Set TX buffer start page
1945 */
1946 ed_nic_outb(sc, ED_P0_TPSR, sc->tx_page_start +
1947 sc->txb_next_tx * ED_TXBUF_SIZE);
1948
1949 /*
1950 * Set TX length
1951 */
1952 ed_nic_outb(sc, ED_P0_TBCR0, len);
1953 ed_nic_outb(sc, ED_P0_TBCR1, len >> 8);
1954
1955 /*
1956 * Set page 0, Remote DMA complete, Transmit Packet, and *Start*
1957 */
1958 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_TXP | ED_CR_STA);
1959 sc->xmit_busy = 1;
1960
1961 /*
1962 * Point to next transmit buffer slot and wrap if necessary.
1963 */
1964 sc->txb_next_tx++;
1965 if (sc->txb_next_tx == sc->txb_cnt)
1966 sc->txb_next_tx = 0;
1967
1968 /*
1969 * Set a timer just in case we never hear from the board again
1970 */
1971 ifp->if_timer = 2;
1972}
1973
1974/*
1975 * Start output on interface.
1976 * We make two assumptions here:
1977 * 1) that the current priority is set to splimp _before_ this code
1978 * is called *and* is returned to the appropriate priority after
1979 * return
1980 * 2) that the IFF_OACTIVE flag is checked before this code is called
1981 * (i.e. that the output part of the interface is idle)
1982 */
1983static void
1984ed_start(ifp)
1985 struct ifnet *ifp;
1986{
1987 struct ed_softc *sc = ifp->if_softc;
1988 struct mbuf *m0, *m;
1989 caddr_t buffer;
1990 int len;
1991
1992 if (sc->gone) {
1993 printf("ed_start(%p) GONE\n",ifp);
1994 return;
1995 }
1996outloop:
1997
1998 /*
1999 * First, see if there are buffered packets and an idle transmitter -
2000 * should never happen at this point.
2001 */
2002 if (sc->txb_inuse && (sc->xmit_busy == 0)) {
2003 printf("ed: packets buffered, but transmitter idle\n");
2004 ed_xmit(sc);
2005 }
2006
2007 /*
2008 * See if there is room to put another packet in the buffer.
2009 */
2010 if (sc->txb_inuse == sc->txb_cnt) {
2011
2012 /*
2013 * No room. Indicate this to the outside world and exit.
2014 */
2015 ifp->if_flags |= IFF_OACTIVE;
2016 return;
2017 }
2018 IF_DEQUEUE(&ifp->if_snd, m);
2019 if (m == 0) {
2020
2021 /*
2022 * We are using the !OACTIVE flag to indicate to the outside
2023 * world that we can accept an additional packet rather than
2024 * that the transmitter is _actually_ active. Indeed, the
2025 * transmitter may be active, but if we haven't filled all the
2026 * buffers with data then we still want to accept more.
2027 */
2028 ifp->if_flags &= ~IFF_OACTIVE;
2029 return;
2030 }
2031
2032 /*
2033 * Copy the mbuf chain into the transmit buffer
2034 */
2035
2036 m0 = m;
2037
2038 /* txb_new points to next open buffer slot */
2039 buffer = sc->mem_start + (sc->txb_new * ED_TXBUF_SIZE * ED_PAGE_SIZE);
2040
2041 if (sc->mem_shared) {
2042
2043 /*
2044 * Special case setup for 16 bit boards...
2045 */
2046 if (sc->isa16bit) {
2047 switch (sc->vendor) {
2048
2049 /*
2050 * For 16bit 3Com boards (which have 16k of
2051 * memory), we have the xmit buffers in a
2052 * different page of memory ('page 0') - so
2053 * change pages.
2054 */
2055 case ED_VENDOR_3COM:
2056 ed_asic_outb(sc, ED_3COM_GACFR,
2057 ED_3COM_GACFR_RSEL);
2058 break;
2059
2060 /*
2061 * Enable 16bit access to shared memory on
2062 * WD/SMC boards.
2063 */
2064 case ED_VENDOR_WD_SMC:
2065 ed_asic_outb(sc, ED_WD_LAAR,
2066 sc->wd_laar_proto | ED_WD_LAAR_M16EN);
2067 if (sc->chip_type == ED_CHIP_TYPE_WD790) {
2068 ed_asic_outb(sc, ED_WD_MSR, ED_WD_MSR_MENB);
2069 }
2070 break;
2071 }
2072 }
2073 for (len = 0; m != 0; m = m->m_next) {
2074 bcopy(mtod(m, caddr_t), buffer, m->m_len);
2075 buffer += m->m_len;
2076 len += m->m_len;
2077 }
2078
2079 /*
2080 * Restore previous shared memory access
2081 */
2082 if (sc->isa16bit) {
2083 switch (sc->vendor) {
2084 case ED_VENDOR_3COM:
2085 ed_asic_outb(sc, ED_3COM_GACFR,
2086 ED_3COM_GACFR_RSEL | ED_3COM_GACFR_MBS0);
2087 break;
2088 case ED_VENDOR_WD_SMC:
2089 if (sc->chip_type == ED_CHIP_TYPE_WD790) {
2090 ed_asic_outb(sc, ED_WD_MSR, 0x00);
2091 }
2092 ed_asic_outb(sc, ED_WD_LAAR,
2093 sc->wd_laar_proto & ~ED_WD_LAAR_M16EN);
2094 break;
2095 }
2096 }
2097 } else {
2098 len = ed_pio_write_mbufs(sc, m, (int)buffer);
2099 if (len == 0)
2100 goto outloop;
2101 }
2102
2103 sc->txb_len[sc->txb_new] = max(len, (ETHER_MIN_LEN-ETHER_CRC_LEN));
2104
2105 sc->txb_inuse++;
2106
2107 /*
2108 * Point to next buffer slot and wrap if necessary.
2109 */
2110 sc->txb_new++;
2111 if (sc->txb_new == sc->txb_cnt)
2112 sc->txb_new = 0;
2113
2114 if (sc->xmit_busy == 0)
2115 ed_xmit(sc);
2116
2117 /*
2118 * Tap off here if there is a bpf listener.
2119 */
2120 if (ifp->if_bpf) {
2121 bpf_mtap(ifp, m0);
2122 }
2123
2124 m_freem(m0);
2125
2126 /*
2127 * Loop back to the top to possibly buffer more packets
2128 */
2129 goto outloop;
2130}
2131
2132/*
2133 * Ethernet interface receiver interrupt.
2134 */
2135static __inline void
2136ed_rint(sc)
2137 struct ed_softc *sc;
2138{
2139 struct ifnet *ifp = &sc->arpcom.ac_if;
2140 u_char boundry;
2141 u_short len;
2142 struct ed_ring packet_hdr;
2143 char *packet_ptr;
2144
2145 if (sc->gone)
2146 return;
2147
2148 /*
2149 * Set NIC to page 1 registers to get 'current' pointer
2150 */
2151 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_PAGE_1 | ED_CR_STA);
2152
2153 /*
2154 * 'sc->next_packet' is the logical beginning of the ring-buffer -
2155 * i.e. it points to where new data has been buffered. The 'CURR'
2156 * (current) register points to the logical end of the ring-buffer -
2157 * i.e. it points to where additional new data will be added. We loop
2158 * here until the logical beginning equals the logical end (or in
2159 * other words, until the ring-buffer is empty).
2160 */
2161 while (sc->next_packet != ed_nic_inb(sc, ED_P1_CURR)) {
2162
2163 /* get pointer to this buffer's header structure */
2164 packet_ptr = sc->mem_ring +
2165 (sc->next_packet - sc->rec_page_start) * ED_PAGE_SIZE;
2166
2167 /*
2168 * The byte count includes a 4 byte header that was added by
2169 * the NIC.
2170 */
2171 if (sc->mem_shared)
2172 packet_hdr = *(struct ed_ring *) packet_ptr;
2173 else
2174 ed_pio_readmem(sc, (int)packet_ptr, (char *) &packet_hdr,
2175 sizeof(packet_hdr));
2176 len = packet_hdr.count;
2177 if (len > (ETHER_MAX_LEN - ETHER_CRC_LEN + sizeof(struct ed_ring)) ||
2178 len < (ETHER_MIN_LEN - ETHER_CRC_LEN + sizeof(struct ed_ring))) {
2179 /*
2180 * Length is a wild value. There's a good chance that
2181 * this was caused by the NIC being old and buggy.
2182 * The bug is that the length low byte is duplicated in
2183 * the high byte. Try to recalculate the length based on
2184 * the pointer to the next packet.
2185 */
2186 /*
2187 * NOTE: sc->next_packet is pointing at the current packet.
2188 */
2189 len &= ED_PAGE_SIZE - 1; /* preserve offset into page */
2190 if (packet_hdr.next_packet >= sc->next_packet) {
2191 len += (packet_hdr.next_packet - sc->next_packet) * ED_PAGE_SIZE;
2192 } else {
2193 len += ((packet_hdr.next_packet - sc->rec_page_start) +
2194 (sc->rec_page_stop - sc->next_packet)) * ED_PAGE_SIZE;
2195 }
2196 /*
2197 * because buffers are aligned on 256-byte boundary,
2198 * the length computed above is off by 256 in almost
2199 * all cases. Fix it...
2200 */
2201 if (len & 0xff)
2202 len -= 256 ;
2203 if (len > (ETHER_MAX_LEN - ETHER_CRC_LEN
2204 + sizeof(struct ed_ring)))
2205 sc->mibdata.dot3StatsFrameTooLongs++;
2206 }
2207 /*
2208 * Be fairly liberal about what we allow as a "reasonable" length
2209 * so that a [crufty] packet will make it to BPF (and can thus
2210 * be analyzed). Note that all that is really important is that
2211 * we have a length that will fit into one mbuf cluster or less;
2212 * the upper layer protocols can then figure out the length from
2213 * their own length field(s).
2214 * But make sure that we have at least a full ethernet header
2215 * or we would be unable to call ether_input() later.
2216 */
2217 if ((len >= sizeof(struct ed_ring) + ETHER_HDR_LEN) &&
2218 (len <= MCLBYTES) &&
2219 (packet_hdr.next_packet >= sc->rec_page_start) &&
2220 (packet_hdr.next_packet < sc->rec_page_stop)) {
2221 /*
2222 * Go get packet.
2223 */
2224 ed_get_packet(sc, packet_ptr + sizeof(struct ed_ring),
2225 len - sizeof(struct ed_ring));
2226 ifp->if_ipackets++;
2227 } else {
2228 /*
2229 * Really BAD. The ring pointers are corrupted.
2230 */
2231 log(LOG_ERR,
2232 "ed%d: NIC memory corrupt - invalid packet length %d\n",
2233 ifp->if_unit, len);
2234 ifp->if_ierrors++;
2235 ed_reset(ifp);
2236 return;
2237 }
2238
2239 /*
2240 * Update next packet pointer
2241 */
2242 sc->next_packet = packet_hdr.next_packet;
2243
2244 /*
2245 * Update NIC boundry pointer - being careful to keep it one
2246 * buffer behind. (as recommended by NS databook)
2247 */
2248 boundry = sc->next_packet - 1;
2249 if (boundry < sc->rec_page_start)
2250 boundry = sc->rec_page_stop - 1;
2251
2252 /*
2253 * Set NIC to page 0 registers to update boundry register
2254 */
2255 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STA);
2256
2257 ed_nic_outb(sc, ED_P0_BNRY, boundry);
2258
2259 /*
2260 * Set NIC to page 1 registers before looping to top (prepare
2261 * to get 'CURR' current pointer)
2262 */
2263 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_PAGE_1 | ED_CR_STA);
2264 }
2265}
2266
2267/*
2268 * Ethernet interface interrupt processor
2269 */
2270void
2271edintr(arg)
2272 void *arg;
2273{
2274 struct ed_softc *sc = (struct ed_softc*) arg;
2275 struct ifnet *ifp = (struct ifnet *)sc;
2276 u_char isr;
2277
2278 if (sc->gone)
2279 return;
2280 /*
2281 * Set NIC to page 0 registers
2282 */
2283 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STA);
2284
2285 /*
2286 * loop until there are no more new interrupts
2287 */
2288 while ((isr = ed_nic_inb(sc, ED_P0_ISR)) != 0) {
2289
2290 /*
2291 * reset all the bits that we are 'acknowledging' by writing a
2292 * '1' to each bit position that was set (writing a '1'
2293 * *clears* the bit)
2294 */
2295 ed_nic_outb(sc, ED_P0_ISR, isr);
2296
2297 /* XXX workaround for AX88190 */
2298 if (sc->chip_type == ED_CHIP_TYPE_AX88190) {
2299 while (ed_nic_inb(sc, ED_P0_ISR) & isr) {
2300 ed_nic_outb(sc, ED_P0_ISR,0);
2301 ed_nic_outb(sc, ED_P0_ISR,isr);
2302 }
2303 }
2304
2305 /*
2306 * Handle transmitter interrupts. Handle these first because
2307 * the receiver will reset the board under some conditions.
2308 */
2309 if (isr & (ED_ISR_PTX | ED_ISR_TXE)) {
2310 u_char collisions = ed_nic_inb(sc, ED_P0_NCR) & 0x0f;
2311
2312 /*
2313 * Check for transmit error. If a TX completed with an
2314 * error, we end up throwing the packet away. Really
2315 * the only error that is possible is excessive
2316 * collisions, and in this case it is best to allow
2317 * the automatic mechanisms of TCP to backoff the
2318 * flow. Of course, with UDP we're screwed, but this
2319 * is expected when a network is heavily loaded.
2320 */
2321 (void) ed_nic_inb(sc, ED_P0_TSR);
2322 if (isr & ED_ISR_TXE) {
2323 u_char tsr;
2324
2325 /*
2326 * Excessive collisions (16)
2327 */
2328 tsr = ed_nic_inb(sc, ED_P0_TSR);
2329 if ((tsr & ED_TSR_ABT)
2330 && (collisions == 0)) {
2331
2332 /*
2333 * When collisions total 16, the
2334 * P0_NCR will indicate 0, and the
2335 * TSR_ABT is set.
2336 */
2337 collisions = 16;
2338 sc->mibdata.dot3StatsExcessiveCollisions++;
2339 sc->mibdata.dot3StatsCollFrequencies[15]++;
2340 }
2341 if (tsr & ED_TSR_OWC)
2342 sc->mibdata.dot3StatsLateCollisions++;
2343 if (tsr & ED_TSR_CDH)
2344 sc->mibdata.dot3StatsSQETestErrors++;
2345 if (tsr & ED_TSR_CRS)
2346 sc->mibdata.dot3StatsCarrierSenseErrors++;
2347 if (tsr & ED_TSR_FU)
2348 sc->mibdata.dot3StatsInternalMacTransmitErrors++;
2349
2350 /*
2351 * update output errors counter
2352 */
2353 ifp->if_oerrors++;
2354 } else {
2355
2356 /*
2357 * Update total number of successfully
2358 * transmitted packets.
2359 */
2360 ifp->if_opackets++;
2361 }
2362
2363 /*
2364 * reset tx busy and output active flags
2365 */
2366 sc->xmit_busy = 0;
2367 ifp->if_flags &= ~IFF_OACTIVE;
2368
2369 /*
2370 * clear watchdog timer
2371 */
2372 ifp->if_timer = 0;
2373
2374 /*
2375 * Add in total number of collisions on last
2376 * transmission.
2377 */
2378 ifp->if_collisions += collisions;
2379 switch(collisions) {
2380 case 0:
2381 case 16:
2382 break;
2383 case 1:
2384 sc->mibdata.dot3StatsSingleCollisionFrames++;
2385 sc->mibdata.dot3StatsCollFrequencies[0]++;
2386 break;
2387 default:
2388 sc->mibdata.dot3StatsMultipleCollisionFrames++;
2389 sc->mibdata.
2390 dot3StatsCollFrequencies[collisions-1]
2391 ++;
2392 break;
2393 }
2394
2395 /*
2396 * Decrement buffer in-use count if not zero (can only
2397 * be zero if a transmitter interrupt occured while
2398 * not actually transmitting). If data is ready to
2399 * transmit, start it transmitting, otherwise defer
2400 * until after handling receiver
2401 */
2402 if (sc->txb_inuse && --sc->txb_inuse)
2403 ed_xmit(sc);
2404 }
2405
2406 /*
2407 * Handle receiver interrupts
2408 */
2409 if (isr & (ED_ISR_PRX | ED_ISR_RXE | ED_ISR_OVW)) {
2410
2411 /*
2412 * Overwrite warning. In order to make sure that a
2413 * lockup of the local DMA hasn't occurred, we reset
2414 * and re-init the NIC. The NSC manual suggests only a
2415 * partial reset/re-init is necessary - but some chips
2416 * seem to want more. The DMA lockup has been seen
2417 * only with early rev chips - Methinks this bug was
2418 * fixed in later revs. -DG
2419 */
2420 if (isr & ED_ISR_OVW) {
2421 ifp->if_ierrors++;
2422#ifdef DIAGNOSTIC
2423 log(LOG_WARNING,
2424 "ed%d: warning - receiver ring buffer overrun\n",
2425 ifp->if_unit);
2426#endif
2427
2428 /*
2429 * Stop/reset/re-init NIC
2430 */
2431 ed_reset(ifp);
2432 } else {
2433
2434 /*
2435 * Receiver Error. One or more of: CRC error,
2436 * frame alignment error FIFO overrun, or
2437 * missed packet.
2438 */
2439 if (isr & ED_ISR_RXE) {
2440 u_char rsr;
2441 rsr = ed_nic_inb(sc, ED_P0_RSR);
2442 if (rsr & ED_RSR_CRC)
2443 sc->mibdata.dot3StatsFCSErrors++;
2444 if (rsr & ED_RSR_FAE)
2445 sc->mibdata.dot3StatsAlignmentErrors++;
2446 if (rsr & ED_RSR_FO)
2447 sc->mibdata.dot3StatsInternalMacReceiveErrors++;
2448 ifp->if_ierrors++;
2449#ifdef ED_DEBUG
2450 printf("ed%d: receive error %x\n", ifp->if_unit,
2451 ed_nic_inb(sc, ED_P0_RSR));
2452#endif
2453 }
2454
2455 /*
2456 * Go get the packet(s) XXX - Doing this on an
2457 * error is dubious because there shouldn't be
2458 * any data to get (we've configured the
2459 * interface to not accept packets with
2460 * errors).
2461 */
2462
2463 /*
2464 * Enable 16bit access to shared memory first
2465 * on WD/SMC boards.
2466 */
2467 if (sc->isa16bit &&
2468 (sc->vendor == ED_VENDOR_WD_SMC)) {
2469
2470 ed_asic_outb(sc, ED_WD_LAAR,
2471 sc->wd_laar_proto | ED_WD_LAAR_M16EN);
2472 if (sc->chip_type == ED_CHIP_TYPE_WD790) {
2473 ed_asic_outb(sc, ED_WD_MSR,
2474 ED_WD_MSR_MENB);
2475 }
2476 }
2477 ed_rint(sc);
2478
2479 /* disable 16bit access */
2480 if (sc->isa16bit &&
2481 (sc->vendor == ED_VENDOR_WD_SMC)) {
2482
2483 if (sc->chip_type == ED_CHIP_TYPE_WD790) {
2484 ed_asic_outb(sc, ED_WD_MSR, 0x00);
2485 }
2486 ed_asic_outb(sc, ED_WD_LAAR,
2487 sc->wd_laar_proto & ~ED_WD_LAAR_M16EN);
2488 }
2489 }
2490 }
2491
2492 /*
2493 * If it looks like the transmitter can take more data,
2494 * attempt to start output on the interface. This is done
2495 * after handling the receiver to give the receiver priority.
2496 */
2497 if ((ifp->if_flags & IFF_OACTIVE) == 0)
2498 ed_start(ifp);
2499
2500 /*
2501 * return NIC CR to standard state: page 0, remote DMA
2502 * complete, start (toggling the TXP bit off, even if was just
2503 * set in the transmit routine, is *okay* - it is 'edge'
2504 * triggered from low to high)
2505 */
2506 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STA);
2507
2508 /*
2509 * If the Network Talley Counters overflow, read them to reset
2510 * them. It appears that old 8390's won't clear the ISR flag
2511 * otherwise - resulting in an infinite loop.
2512 */
2513 if (isr & ED_ISR_CNT) {
2514 (void) ed_nic_inb(sc, ED_P0_CNTR0);
2515 (void) ed_nic_inb(sc, ED_P0_CNTR1);
2516 (void) ed_nic_inb(sc, ED_P0_CNTR2);
2517 }
2518 }
2519}
2520
2521/*
2522 * Process an ioctl request. This code needs some work - it looks
2523 * pretty ugly.
2524 */
2525static int
2526ed_ioctl(ifp, command, data)
2527 register struct ifnet *ifp;
2528 u_long command;
2529 caddr_t data;
2530{
2531 struct ed_softc *sc = ifp->if_softc;
2532 struct ifreq *ifr = (struct ifreq *)data;
2533 struct mii_data *mii;
2534 int s, error = 0;
2535
2536 if (sc == NULL || sc->gone) {
2537 ifp->if_flags &= ~IFF_RUNNING;
2538 return ENXIO;
2539 }
2540 s = splimp();
2541
2542 switch (command) {
2543
2544 case SIOCSIFADDR:
2545 case SIOCGIFADDR:
2546 case SIOCSIFMTU:
2547 error = ether_ioctl(ifp, command, data);
2548 break;
2549
2550 case SIOCSIFFLAGS:
2551
2552 /*
2553 * If the interface is marked up and stopped, then start it.
2554 * If it is marked down and running, then stop it.
2555 */
2556 if (ifp->if_flags & IFF_UP) {
2557 if ((ifp->if_flags & IFF_RUNNING) == 0)
2558 ed_init(sc);
2559 } else {
2560 if (ifp->if_flags & IFF_RUNNING) {
2561 ed_stop(sc);
2562 ifp->if_flags &= ~IFF_RUNNING;
2563 }
2564 }
2565
2566 /*
2567 * Promiscuous flag may have changed, so reprogram the RCR.
2568 */
2569 ed_setrcr(sc);
2570
2571 /*
2572 * An unfortunate hack to provide the (required) software
2573 * control of the tranceiver for 3Com boards. The ALTPHYS flag
2574 * disables the tranceiver if set.
2575 */
2576 if (sc->vendor == ED_VENDOR_3COM) {
2577 if (ifp->if_flags & IFF_ALTPHYS) {
2578 ed_asic_outb(sc, ED_3COM_CR, 0);
2579 } else {
2580 ed_asic_outb(sc, ED_3COM_CR, ED_3COM_CR_XSEL);
2581 }
2582 } else if (sc->vendor == ED_VENDOR_HP)
2583 ed_hpp_set_physical_link(sc);
2584 break;
2585
2586 case SIOCADDMULTI:
2587 case SIOCDELMULTI:
2588 /*
2589 * Multicast list has changed; set the hardware filter
2590 * accordingly.
2591 */
2592 ed_setrcr(sc);
2593 error = 0;
2594 break;
2595
2596 case SIOCGIFMEDIA:
2597 case SIOCSIFMEDIA:
2598 if (sc->miibus == NULL) {
2599 error = EINVAL;
2600 break;
2601 }
2602 mii = device_get_softc(sc->miibus);
2603 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
2604 break;
2605
2606 default:
2607 error = EINVAL;
2608 }
2609 (void) splx(s);
2610 return (error);
2611}
2612
2613/*
2614 * Given a source and destination address, copy 'amount' of a packet from
2615 * the ring buffer into a linear destination buffer. Takes into account
2616 * ring-wrap.
2617 */
2618static __inline char *
2619ed_ring_copy(sc, src, dst, amount)
2620 struct ed_softc *sc;
2621 char *src;
2622 char *dst;
2623 u_short amount;
2624{
2625 u_short tmp_amount;
2626
2627 /* does copy wrap to lower addr in ring buffer? */
2628 if (src + amount > sc->mem_end) {
2629 tmp_amount = sc->mem_end - src;
2630
2631 /* copy amount up to end of NIC memory */
2632 if (sc->mem_shared)
2633 bcopy(src, dst, tmp_amount);
2634 else
2635 ed_pio_readmem(sc, (int)src, dst, tmp_amount);
2636
2637 amount -= tmp_amount;
2638 src = sc->mem_ring;
2639 dst += tmp_amount;
2640 }
2641 if (sc->mem_shared)
2642 bcopy(src, dst, amount);
2643 else
2644 ed_pio_readmem(sc, (int)src, dst, amount);
2645
2646 return (src + amount);
2647}
2648
2649/*
2650 * Retreive packet from shared memory and send to the next level up via
2651 * ether_input().
2652 */
2653static void
2654ed_get_packet(sc, buf, len)
2655 struct ed_softc *sc;
2656 char *buf;
2657 u_short len;
2658{
2659 struct ether_header *eh;
2660 struct mbuf *m;
2661
2662 /* Allocate a header mbuf */
2663 MGETHDR(m, M_DONTWAIT, MT_DATA);
2664 if (m == NULL)
2665 return;
2666 m->m_pkthdr.rcvif = &sc->arpcom.ac_if;
2667 m->m_pkthdr.len = m->m_len = len;
2668
2669 /*
2670 * We always put the received packet in a single buffer -
2671 * either with just an mbuf header or in a cluster attached
2672 * to the header. The +2 is to compensate for the alignment
2673 * fixup below.
2674 */
2675 if ((len + 2) > MHLEN) {
2676 /* Attach an mbuf cluster */
2677 MCLGET(m, M_DONTWAIT);
2678
2679 /* Insist on getting a cluster */
2680 if ((m->m_flags & M_EXT) == 0) {
2681 m_freem(m);
2682 return;
2683 }
2684 }
2685
2686 /*
2687 * The +2 is to longword align the start of the real packet.
2688 * This is important for NFS.
2689 */
2690 m->m_data += 2;
2691 eh = mtod(m, struct ether_header *);
2692
2693#ifdef BRIDGE
2694 /*
2695 * Don't read in the entire packet if we know we're going to drop it
2696 * and no bpf is active.
2697 */
2698 if (!sc->arpcom.ac_if.if_bpf &&
2699 do_bridge && BDG_USED( (&sc->arpcom.ac_if) ) ) {
2700 struct ifnet *bif;
2701
2702 ed_ring_copy(sc, buf, (char *)eh, ETHER_HDR_LEN);
2703 bif = bridge_in(&sc->arpcom.ac_if, eh) ;
2704 if (bif == BDG_DROP) {
2705 m_freem(m);
2706 return;
2707 }
2708 if (len > ETHER_HDR_LEN)
2709 ed_ring_copy(sc, buf + ETHER_HDR_LEN,
2710 (char *)(eh + 1), len - ETHER_HDR_LEN);
2711 } else
2712#endif
2713 /*
2714 * Get packet, including link layer address, from interface.
2715 */
2716 ed_ring_copy(sc, buf, (char *)eh, len);
2717
2718 /*
2719 * Remove link layer address.
2720 */
2721 m->m_pkthdr.len = m->m_len = len - sizeof(struct ether_header);
2722 m->m_data += sizeof(struct ether_header);
2723
2724 ether_input(&sc->arpcom.ac_if, eh, m);
2725}
2726
2727/*
2728 * Supporting routines
2729 */
2730
2731/*
2732 * Given a NIC memory source address and a host memory destination
2733 * address, copy 'amount' from NIC to host using Programmed I/O.
2734 * The 'amount' is rounded up to a word - okay as long as mbufs
2735 * are word sized.
2736 * This routine is currently Novell-specific.
2737 */
2738void
2739ed_pio_readmem(sc, src, dst, amount)
2740 struct ed_softc *sc;
2741 int src;
2742 unsigned char *dst;
2743 unsigned short amount;
2744{
2745 /* HP PC Lan+ cards need special handling */
2746 if (sc->vendor == ED_VENDOR_HP && sc->type == ED_TYPE_HP_PCLANPLUS) {
2747 ed_hpp_readmem(sc, src, dst, amount);
2748 return;
2749 }
2750
2751 /* Regular Novell cards */
2752 /* select page 0 registers */
2753 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STA);
2754
2755 /* round up to a word */
2756 if (amount & 1)
2757 ++amount;
2758
2759 /* set up DMA byte count */
2760 ed_nic_outb(sc, ED_P0_RBCR0, amount);
2761 ed_nic_outb(sc, ED_P0_RBCR1, amount >> 8);
2762
2763 /* set up source address in NIC mem */
2764 ed_nic_outb(sc, ED_P0_RSAR0, src);
2765 ed_nic_outb(sc, ED_P0_RSAR1, src >> 8);
2766
2767 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD0 | ED_CR_STA);
2768
2769 if (sc->isa16bit) {
2770 ed_asic_insw(sc, ED_NOVELL_DATA, dst, amount / 2);
2771 } else {
2772 ed_asic_insb(sc, ED_NOVELL_DATA, dst, amount);
2773 }
2774}
2775
2776/*
2777 * Stripped down routine for writing a linear buffer to NIC memory.
2778 * Only used in the probe routine to test the memory. 'len' must
2779 * be even.
2780 */
2781void
2782ed_pio_writemem(sc, src, dst, len)
2783 struct ed_softc *sc;
2784 char *src;
2785 unsigned short dst;
2786 unsigned short len;
2787{
2788 int maxwait = 200; /* about 240us */
2789
2790 /* select page 0 registers */
2791 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STA);
2792
2793 /* reset remote DMA complete flag */
2794 ed_nic_outb(sc, ED_P0_ISR, ED_ISR_RDC);
2795
2796 /* set up DMA byte count */
2797 ed_nic_outb(sc, ED_P0_RBCR0, len);
2798 ed_nic_outb(sc, ED_P0_RBCR1, len >> 8);
2799
2800 /* set up destination address in NIC mem */
2801 ed_nic_outb(sc, ED_P0_RSAR0, dst);
2802 ed_nic_outb(sc, ED_P0_RSAR1, dst >> 8);
2803
2804 /* set remote DMA write */
2805 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD1 | ED_CR_STA);
2806
2807 if (sc->isa16bit) {
2808 ed_asic_outsw(sc, ED_NOVELL_DATA, src, len / 2);
2809 } else {
2810 ed_asic_outsb(sc, ED_NOVELL_DATA, src, len);
2811 }
2812
2813 /*
2814 * Wait for remote DMA complete. This is necessary because on the
2815 * transmit side, data is handled internally by the NIC in bursts and
2816 * we can't start another remote DMA until this one completes. Not
2817 * waiting causes really bad things to happen - like the NIC
2818 * irrecoverably jamming the ISA bus.
2819 */
2820 while (((ed_nic_inb(sc, ED_P0_ISR) & ED_ISR_RDC) != ED_ISR_RDC) && --maxwait);
2821}
2822
2823/*
2824 * Write an mbuf chain to the destination NIC memory address using
2825 * programmed I/O.
2826 */
2827static u_short
2828ed_pio_write_mbufs(sc, m, dst)
2829 struct ed_softc *sc;
2830 struct mbuf *m;
2831 int dst;
2832{
2833 struct ifnet *ifp = (struct ifnet *)sc;
2834 unsigned short total_len, dma_len;
2835 struct mbuf *mp;
2836 int maxwait = 200; /* about 240us */
2837
2838 /* HP PC Lan+ cards need special handling */
2839 if (sc->vendor == ED_VENDOR_HP && sc->type == ED_TYPE_HP_PCLANPLUS) {
2840 return ed_hpp_write_mbufs(sc, m, dst);
2841 }
2842
2843 /* Regular Novell cards */
2844 /* First, count up the total number of bytes to copy */
2845 for (total_len = 0, mp = m; mp; mp = mp->m_next)
2846 total_len += mp->m_len;
2847
2848 dma_len = total_len;
2849 if (sc->isa16bit && (dma_len & 1))
2850 dma_len++;
2851
2852 /* select page 0 registers */
2853 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STA);
2854
2855 /* reset remote DMA complete flag */
2856 ed_nic_outb(sc, ED_P0_ISR, ED_ISR_RDC);
2857
2858 /* set up DMA byte count */
2859 ed_nic_outb(sc, ED_P0_RBCR0, dma_len);
2860 ed_nic_outb(sc, ED_P0_RBCR1, dma_len >> 8);
2861
2862 /* set up destination address in NIC mem */
2863 ed_nic_outb(sc, ED_P0_RSAR0, dst);
2864 ed_nic_outb(sc, ED_P0_RSAR1, dst >> 8);
2865
2866 /* set remote DMA write */
2867 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD1 | ED_CR_STA);
2868
2869 /*
2870 * Transfer the mbuf chain to the NIC memory.
2871 * 16-bit cards require that data be transferred as words, and only words.
2872 * So that case requires some extra code to patch over odd-length mbufs.
2873 */
2874
2875 if (!sc->isa16bit) {
2876 /* NE1000s are easy */
2877 while (m) {
2878 if (m->m_len) {
2879 ed_asic_outsb(sc, ED_NOVELL_DATA,
2880 m->m_data, m->m_len);
2881 }
2882 m = m->m_next;
2883 }
2884 } else {
2885 /* NE2000s are a pain */
2886 unsigned char *data;
2887 int len, wantbyte;
2888 unsigned char savebyte[2];
2889
2890 wantbyte = 0;
2891
2892 while (m) {
2893 len = m->m_len;
2894 if (len) {
2895 data = mtod(m, caddr_t);
2896 /* finish the last word */
2897 if (wantbyte) {
2898 savebyte[1] = *data;
2899 ed_asic_outw(sc, ED_NOVELL_DATA,
2900 *(u_short *)savebyte);
2901 data++;
2902 len--;
2903 wantbyte = 0;
2904 }
2905 /* output contiguous words */
2906 if (len > 1) {
2907 ed_asic_outsw(sc, ED_NOVELL_DATA,
2908 data, len >> 1);
2909 data += len & ~1;
2910 len &= 1;
2911 }
2912 /* save last byte, if necessary */
2913 if (len == 1) {
2914 savebyte[0] = *data;
2915 wantbyte = 1;
2916 }
2917 }
2918 m = m->m_next;
2919 }
2920 /* spit last byte */
2921 if (wantbyte) {
2922 ed_asic_outw(sc, ED_NOVELL_DATA, *(u_short *)savebyte);
2923 }
2924 }
2925
2926 /*
2927 * Wait for remote DMA complete. This is necessary because on the
2928 * transmit side, data is handled internally by the NIC in bursts and
2929 * we can't start another remote DMA until this one completes. Not
2930 * waiting causes really bad things to happen - like the NIC
2931 * irrecoverably jamming the ISA bus.
2932 */
2933 while (((ed_nic_inb(sc, ED_P0_ISR) & ED_ISR_RDC) != ED_ISR_RDC) && --maxwait);
2934
2935 if (!maxwait) {
2936 log(LOG_WARNING, "ed%d: remote transmit DMA failed to complete\n",
2937 ifp->if_unit);
2938 ed_reset(ifp);
2939 return(0);
2940 }
2941 return (total_len);
2942}
2943
2944/*
2945 * Support routines to handle the HP PC Lan+ card.
2946 */
2947
2948/*
2949 * HP PC Lan+: Read from NIC memory, using either PIO or memory mapped
2950 * IO.
2951 */
2952
2953static void
2954ed_hpp_readmem(sc, src, dst, amount)
2955 struct ed_softc *sc;
2956 unsigned short src;
2957 unsigned char *dst;
2958 unsigned short amount;
2959{
2960
2961 int use_32bit_access = !(sc->hpp_id & ED_HPP_ID_16_BIT_ACCESS);
2962
2963
2964 /* Program the source address in RAM */
2965 ed_asic_outw(sc, ED_HPP_PAGE_2, src);
2966
2967 /*
2968 * The HP PC Lan+ card supports word reads as well as
2969 * a memory mapped i/o port that is aliased to every
2970 * even address on the board.
2971 */
2972
2973 if (sc->hpp_mem_start) {
2974
2975 /* Enable memory mapped access. */
2976 ed_asic_outw(sc, ED_HPP_OPTION, sc->hpp_options &
2977 ~(ED_HPP_OPTION_MEM_DISABLE |
2978 ED_HPP_OPTION_BOOT_ROM_ENB));
2979
2980 if (use_32bit_access && (amount > 3)) {
2981 u_int32_t *dl = (u_int32_t *) dst;
2982 volatile u_int32_t *const sl =
2983 (u_int32_t *) sc->hpp_mem_start;
2984 u_int32_t *const fence = dl + (amount >> 2);
2985
2986 /* Copy out NIC data. We could probably write this
2987 as a `movsl'. The currently generated code is lousy.
2988 */
2989
2990 while (dl < fence)
2991 *dl++ = *sl;
2992
2993 dst += (amount & ~3);
2994 amount &= 3;
2995
2996 }
2997
2998 /* Finish off any words left, as a series of short reads */
2999 if (amount > 1) {
3000 u_short *d = (u_short *) dst;
3001 volatile u_short *const s =
3002 (u_short *) sc->hpp_mem_start;
3003 u_short *const fence = d + (amount >> 1);
3004
3005 /* Copy out NIC data. */
3006
3007 while (d < fence)
3008 *d++ = *s;
3009
3010 dst += (amount & ~1);
3011 amount &= 1;
3012 }
3013
3014 /*
3015 * read in a byte; however we need to always read 16 bits
3016 * at a time or the hardware gets into a funny state
3017 */
3018
3019 if (amount == 1) {
3020 /* need to read in a short and copy LSB */
3021 volatile u_short *const s =
3022 (volatile u_short *) sc->hpp_mem_start;
3023
3024 *dst = (*s) & 0xFF;
3025 }
3026
3027 /* Restore Boot ROM access. */
3028
3029 ed_asic_outw(sc, ED_HPP_OPTION, sc->hpp_options);
3030
3031
3032 } else {
3033 /* Read in data using the I/O port */
3034 if (use_32bit_access && (amount > 3)) {
3035 ed_asic_insl(sc, ED_HPP_PAGE_4, dst, amount >> 2);
3036 dst += (amount & ~3);
3037 amount &= 3;
3038 }
3039 if (amount > 1) {
3040 ed_asic_insw(sc, ED_HPP_PAGE_4, dst, amount >> 1);
3041 dst += (amount & ~1);
3042 amount &= 1;
3043 }
3044 if (amount == 1) { /* read in a short and keep the LSB */
3045 *dst = ed_asic_inw(sc, ED_HPP_PAGE_4) & 0xFF;
3046 }
3047 }
3048}
3049
3050/*
3051 * HP PC Lan+: Write to NIC memory, using either PIO or memory mapped
3052 * IO.
3053 * Only used in the probe routine to test the memory. 'len' must
3054 * be even.
3055 */
3056void
3057ed_hpp_writemem(sc, src, dst, len)
3058 struct ed_softc *sc;
3059 unsigned char *src;
3060 unsigned short dst;
3061 unsigned short len;
3062{
3063 /* reset remote DMA complete flag */
3064 ed_nic_outb(sc, ED_P0_ISR, ED_ISR_RDC);
3065
3066 /* program the write address in RAM */
3067 ed_asic_outw(sc, ED_HPP_PAGE_0, dst);
3068
3069 if (sc->hpp_mem_start) {
3070 u_short *s = (u_short *) src;
3071 volatile u_short *d = (u_short *) sc->hpp_mem_start;
3072 u_short *const fence = s + (len >> 1);
3073
3074 /*
3075 * Enable memory mapped access.
3076 */
3077
3078 ed_asic_outw(sc, ED_HPP_OPTION, sc->hpp_options &
3079 ~(ED_HPP_OPTION_MEM_DISABLE |
3080 ED_HPP_OPTION_BOOT_ROM_ENB));
3081
3082 /*
3083 * Copy to NIC memory.
3084 */
3085
3086 while (s < fence)
3087 *d = *s++;
3088
3089 /*
3090 * Restore Boot ROM access.
3091 */
3092
3093 ed_asic_outw(sc, ED_HPP_OPTION, sc->hpp_options);
3094
3095 } else {
3096 /* write data using I/O writes */
3097 ed_asic_outsw(sc, ED_HPP_PAGE_4, src, len / 2);
3098 }
3099}
3100
3101/*
3102 * Write to HP PC Lan+ NIC memory. Access to the NIC can be by using
3103 * outsw() or via the memory mapped interface to the same register.
3104 * Writes have to be in word units; byte accesses won't work and may cause
3105 * the NIC to behave weirdly. Long word accesses are permitted if the ASIC
3106 * allows it.
3107 */
3108
3109static u_short
3110ed_hpp_write_mbufs(struct ed_softc *sc, struct mbuf *m, int dst)
3111{
3112 int len, wantbyte;
3113 unsigned short total_len;
3114 unsigned char savebyte[2];
3115 volatile u_short * const d =
3116 (volatile u_short *) sc->hpp_mem_start;
3117 int use_32bit_accesses = !(sc->hpp_id & ED_HPP_ID_16_BIT_ACCESS);
3118
3119 /* select page 0 registers */
3120 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STA);
3121
3122 /* reset remote DMA complete flag */
3123 ed_nic_outb(sc, ED_P0_ISR, ED_ISR_RDC);
3124
3125 /* program the write address in RAM */
3126 ed_asic_outw(sc, ED_HPP_PAGE_0, dst);
3127
3128 if (sc->hpp_mem_start) /* enable memory mapped I/O */
3129 ed_asic_outw(sc, ED_HPP_OPTION, sc->hpp_options &
3130 ~(ED_HPP_OPTION_MEM_DISABLE |
3131 ED_HPP_OPTION_BOOT_ROM_ENB));
3132
3133 wantbyte = 0;
3134 total_len = 0;
3135
3136 if (sc->hpp_mem_start) { /* Memory mapped I/O port */
3137 while (m) {
3138 total_len += (len = m->m_len);
3139 if (len) {
3140 caddr_t data = mtod(m, caddr_t);
3141 /* finish the last word of the previous mbuf */
3142 if (wantbyte) {
3143 savebyte[1] = *data;
3144 *d = *((ushort *) savebyte);
3145 data++; len--; wantbyte = 0;
3146 }
3147 /* output contiguous words */
3148 if ((len > 3) && (use_32bit_accesses)) {
3149 volatile u_int32_t *const dl =
3150 (volatile u_int32_t *) d;
3151 u_int32_t *sl = (u_int32_t *) data;
3152 u_int32_t *fence = sl + (len >> 2);
3153
3154 while (sl < fence)
3155 *dl = *sl++;
3156
3157 data += (len & ~3);
3158 len &= 3;
3159 }
3160 /* finish off remain 16 bit writes */
3161 if (len > 1) {
3162 u_short *s = (u_short *) data;
3163 u_short *fence = s + (len >> 1);
3164
3165 while (s < fence)
3166 *d = *s++;
3167
3168 data += (len & ~1);
3169 len &= 1;
3170 }
3171 /* save last byte if needed */
3172 if ((wantbyte = (len == 1)) != 0)
3173 savebyte[0] = *data;
3174 }
3175 m = m->m_next; /* to next mbuf */
3176 }
3177 if (wantbyte) /* write last byte */
3178 *d = *((u_short *) savebyte);
3179 } else {
3180 /* use programmed I/O */
3181 while (m) {
3182 total_len += (len = m->m_len);
3183 if (len) {
3184 caddr_t data = mtod(m, caddr_t);
3185 /* finish the last word of the previous mbuf */
3186 if (wantbyte) {
3187 savebyte[1] = *data;
3188 ed_asic_outw(sc, ED_HPP_PAGE_4,
3189 *((u_short *)savebyte));
3190 data++;
3191 len--;
3192 wantbyte = 0;
3193 }
3194 /* output contiguous words */
3195 if ((len > 3) && use_32bit_accesses) {
3196 ed_asic_outsl(sc, ED_HPP_PAGE_4,
3197 data, len >> 2);
3198 data += (len & ~3);
3199 len &= 3;
3200 }
3201 /* finish off remaining 16 bit accesses */
3202 if (len > 1) {
3203 ed_asic_outsw(sc, ED_HPP_PAGE_4,
3204 data, len >> 1);
3205 data += (len & ~1);
3206 len &= 1;
3207 }
3208 if ((wantbyte = (len == 1)) != 0)
3209 savebyte[0] = *data;
3210
3211 } /* if len != 0 */
3212 m = m->m_next;
3213 }
3214 if (wantbyte) /* spit last byte */
3215 ed_asic_outw(sc, ED_HPP_PAGE_4, *(u_short *)savebyte);
3216
3217 }
3218
3219 if (sc->hpp_mem_start) /* turn off memory mapped i/o */
3220 ed_asic_outw(sc, ED_HPP_OPTION, sc->hpp_options);
3221
3222 return (total_len);
3223}
3224
3225/*
3226 * MII bus support routines.
3227 */
3228int
3229ed_miibus_readreg(dev, phy, reg)
3230 device_t dev;
3231 int phy, reg;
3232{
3233 struct ed_softc *sc;
3234 int val;
3235 int failed;
3236
3237 sc = device_get_softc(dev);
3238 if (sc->gone)
3239 return 0;
3240
3241 (*sc->mii_writebits)(sc, 0xffffffff, 32);
3242 (*sc->mii_writebits)(sc, ED_MII_STARTDELIM, ED_MII_STARTDELIM_BITS);
3243 (*sc->mii_writebits)(sc, ED_MII_READOP, ED_MII_OP_BITS);
3244 (*sc->mii_writebits)(sc, phy, ED_MII_PHY_BITS);
3245 (*sc->mii_writebits)(sc, reg, ED_MII_REG_BITS);
3246
3247 failed = (*sc->mii_readbits)(sc, ED_MII_ACK_BITS);
3248 val = (*sc->mii_readbits)(sc, ED_MII_DATA_BITS);
3249 (*sc->mii_writebits)(sc, ED_MII_IDLE, ED_MII_IDLE_BITS);
3250
3251 return (failed ? 0 : val);
3252}
3253
3254void
3255ed_miibus_writereg(dev, phy, reg, data)
3256 device_t dev;
3257 int phy, reg, data;
3258{
3259 struct ed_softc *sc;
3260
3261 sc = device_get_softc(dev);
3262 if (sc->gone)
3263 return;
3264
3265 (*sc->mii_writebits)(sc, 0xffffffff, 32);
3266 (*sc->mii_writebits)(sc, ED_MII_STARTDELIM, ED_MII_STARTDELIM_BITS);
3267 (*sc->mii_writebits)(sc, ED_MII_WRITEOP, ED_MII_OP_BITS);
3268 (*sc->mii_writebits)(sc, phy, ED_MII_PHY_BITS);
3269 (*sc->mii_writebits)(sc, reg, ED_MII_REG_BITS);
3270 (*sc->mii_writebits)(sc, ED_MII_TURNAROUND, ED_MII_TURNAROUND_BITS);
3271 (*sc->mii_writebits)(sc, data, ED_MII_DATA_BITS);
3272 (*sc->mii_writebits)(sc, ED_MII_IDLE, ED_MII_IDLE_BITS);
3273}
3274
3275int
3276ed_ifmedia_upd(ifp)
3277 struct ifnet *ifp;
3278{
3279 struct ed_softc *sc;
3280 struct mii_data *mii;
3281
3282 sc = ifp->if_softc;
3283 if (sc->gone || sc->miibus == NULL)
3284 return (ENXIO);
3285
3286 mii = device_get_softc(sc->miibus);
3287 return mii_mediachg(mii);
3288}
3289
3290void
3291ed_ifmedia_sts(ifp, ifmr)
3292 struct ifnet *ifp;
3293 struct ifmediareq *ifmr;
3294{
3295 struct ed_softc *sc;
3296 struct mii_data *mii;
3297
3298 sc = ifp->if_softc;
3299 if (sc->gone || sc->miibus == NULL)
3300 return;
3301
3302 mii = device_get_softc(sc->miibus);
3303 mii_pollstat(mii);
3304 ifmr->ifm_active = mii->mii_media_active;
3305 ifmr->ifm_status = mii->mii_media_status;
3306}
3307
3308void
3309ed_child_detached(dev, child)
3310 device_t dev;
3311 device_t child;
3312{
3313 struct ed_softc *sc;
3314
3315 sc = device_get_softc(dev);
3316 if (child == sc->miibus)
3317 sc->miibus = NULL;
3318}
3319
3320static void
3321ed_setrcr(sc)
3322 struct ed_softc *sc;
3323{
3324 struct ifnet *ifp = (struct ifnet *)sc;
3325 int i;
3326 u_char reg1;
3327
3328 /* Bit 6 in AX88190 RCR register must be set. */
3329 if (sc->chip_type == ED_CHIP_TYPE_AX88190)
3330 reg1 = ED_RCR_INTT;
3331 else
3332 reg1 = 0x00;
3333
3334 /* set page 1 registers */
3335 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_PAGE_1 | ED_CR_STP);
3336
3337 if (ifp->if_flags & IFF_PROMISC) {
3338
3339 /*
3340 * Reconfigure the multicast filter.
3341 */
3342 for (i = 0; i < 8; i++)
3343 ed_nic_outb(sc, ED_P1_MAR(i), 0xff);
3344
3345 /*
3346 * And turn on promiscuous mode. Also enable reception of
3347 * runts and packets with CRC & alignment errors.
3348 */
3349 /* Set page 0 registers */
3350 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STP);
3351
3352 ed_nic_outb(sc, ED_P0_RCR, ED_RCR_PRO | ED_RCR_AM |
3353 ED_RCR_AB | ED_RCR_AR | ED_RCR_SEP | reg1);
3354 } else {
3355 /* set up multicast addresses and filter modes */
3356 if (ifp->if_flags & IFF_MULTICAST) {
3357 u_int32_t mcaf[2];
3358
3359 if (ifp->if_flags & IFF_ALLMULTI) {
3360 mcaf[0] = 0xffffffff;
3361 mcaf[1] = 0xffffffff;
3362 } else
3363 ds_getmcaf(sc, mcaf);
3364
3365 /*
3366 * Set multicast filter on chip.
3367 */
3368 for (i = 0; i < 8; i++)
3369 ed_nic_outb(sc, ED_P1_MAR(i), ((u_char *) mcaf)[i]);
3370
3371 /* Set page 0 registers */
3372 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STP);
3373
3374 ed_nic_outb(sc, ED_P0_RCR, ED_RCR_AM | ED_RCR_AB | reg1);
3375 } else {
3376
3377 /*
3378 * Initialize multicast address hashing registers to
3379 * not accept multicasts.
3380 */
3381 for (i = 0; i < 8; ++i)
3382 ed_nic_outb(sc, ED_P1_MAR(i), 0x00);
3383
3384 /* Set page 0 registers */
3385 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STP);
3386
3387 ed_nic_outb(sc, ED_P0_RCR, ED_RCR_AB | reg1);
3388 }
3389 }
3390
3391 /*
3392 * Start interface.
3393 */
3394 ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STA);
3395}
3396
3397/*
3398 * Compute crc for ethernet address
3399 */
3400static u_int32_t
3401ds_crc(ep)
3402 u_char *ep;
3403{
3404#define POLYNOMIAL 0x04c11db6
3405 register u_int32_t crc = 0xffffffff;
3406 register int carry, i, j;
3407 register u_char b;
3408
3409 for (i = 6; --i >= 0;) {
3410 b = *ep++;
3411 for (j = 8; --j >= 0;) {
3412 carry = ((crc & 0x80000000) ? 1 : 0) ^ (b & 0x01);
3413 crc <<= 1;
3414 b >>= 1;
3415 if (carry)
3416 crc = (crc ^ POLYNOMIAL) | carry;
3417 }
3418 }
3419 return crc;
3420#undef POLYNOMIAL
3421}
3422
3423/*
3424 * Compute the multicast address filter from the
3425 * list of multicast addresses we need to listen to.
3426 */
3427static void
3428ds_getmcaf(sc, mcaf)
3429 struct ed_softc *sc;
3430 u_int32_t *mcaf;
3431{
3432 register u_int32_t index;
3433 register u_char *af = (u_char *) mcaf;
3434 struct ifmultiaddr *ifma;
3435
3436 mcaf[0] = 0;
3437 mcaf[1] = 0;
3438
3439 TAILQ_FOREACH(ifma, &sc->arpcom.ac_if.if_multiaddrs, ifma_link) {
3440 if (ifma->ifma_addr->sa_family != AF_LINK)
3441 continue;
3442 index = ds_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr))
3443 >> 26;
3444 af[index >> 3] |= 1 << (index & 7);
3445 }
3446}