1/*
2 * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
3 *
4 * This software may be used, modified, copied, distributed, and sold, in
5 * both source and binary form provided that the above copyright, these
6 * terms and the following disclaimer are retained. The name of the author
7 * and/or the contributor may not be used to endorse or promote products
8 * derived from this software without specific prior written permission.
--- 7 unchanged lines hidden (view full) ---
16 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION.
17 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
19 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
20 * SUCH DAMAGE.
21 */
22
23/*
24 * $Id: if_fe.c,v 1.43 1998/10/22 05:58:39 bde Exp $
25 *
26 * Device driver for Fujitsu MB86960A/MB86965A based Ethernet cards.
27 * To be used with FreeBSD 2.x
28 * Contributed by M. Sekiguchi. <seki@sysrap.cs.fujitsu.co.jp>
29 *
30 * This version is intended to be a generic template for various
31 * MB86960A/MB86965A based Ethernet cards. It currently supports
32 * Fujitsu FMV-180 series for ISA and Allied-Telesis AT1700/RE2000
33 * series for ISA, as well as Fujitsu MBH10302 PC card.
34 * There are some currently-
35 * unused hooks embedded, which are primarily intended to support
36 * other types of Ethernet cards, but the author is not sure whether
37 * they are useful.
38 *
39 * This version also includes some alignments for
40 * RE1000/RE1000+/ME1500 support. It is incomplete, however, since the
41 * cards are not for AT-compatibles. (They are for PC98 bus -- a
42 * proprietary bus architecture available only in Japan.) Further
43 * work for PC98 version will be available as a part of FreeBSD(98)
44 * project.
45 *
46 * This software is a derivative work of if_ed.c version 1.56 by David
47 * Greenman available as a part of FreeBSD 2.0 RELEASE source distribution.
48 *
49 * The following lines are retained from the original if_ed.c:
50 *
51 * Copyright (C) 1993, David Greenman. This software may be used, modified,
52 * copied, distributed, and sold, in both source and binary form provided
53 * that the above copyright and these terms are retained. Under no
54 * circumstances is the author responsible for the proper functioning
55 * of this software, nor does the author assume any responsibility
56 * for damages incurred with its use.
57 */
58
59/*
60 * TODO:
61 * o To support MBH10304 PC card. It is another MB8696x based
62 * PCMCIA Ethernet card by Fujitsu, which is not compatible with
63 * MBH10302.
64 * o To merge FreeBSD(98) efforts into a single source file.
65 * o To support ISA PnP auto configuration for FMV-183/184.
66 * o To reconsider mbuf usage.
67 * o To reconsider transmission buffer usage, including
68 * transmission buffer size (currently 4KB x 2) and pros-and-
69 * cons of multiple frame transmission.
70 * o To test IPX codes.
71 */
72
73#include "fe.h"
74#include "bpfilter.h"
75#include "opt_inet.h"
76#include "opt_ipx.h"
77
78#include <sys/param.h>
79#include <sys/systm.h>
80#include <sys/sockio.h>
81#include <sys/mbuf.h>
82#include <sys/socket.h>
83#include <sys/syslog.h>
84
85#include <net/if.h>
86#include <net/if_dl.h>
87
88#ifdef INET
89#include <netinet/in.h>
90#include <netinet/if_ether.h>
91#endif
92
93/* IPX code is not tested. FIXME. */
94#ifdef IPX
--- 12 unchanged lines hidden (view full) ---
107#include <netns/ns.h>
108#include <netns/ns_if.h>
109#endif
110
111#if NBPFILTER > 0
112#include <net/bpf.h>
113#endif
114
115#include <machine/clock.h>
116
117#include <i386/isa/isa_device.h>
118#include <i386/isa/icu.h>
119
120/* PCCARD suport */
121#include "card.h"
122#if NCARD > 0
123#include <sys/kernel.h>
124#include <sys/select.h>
125#include <pccard/cardinfo.h>
126#include <pccard/slot.h>
127#endif
128
129#include <i386/isa/ic/mb86960.h>
130#include <i386/isa/if_fereg.h>
131
132/*
133 * This version of fe is an ISA device driver.
134 * Override the following macro to adapt it to another bus.
135 * (E.g., PC98.)
136 */
137#define DEVICE struct isa_device
138
139/*
140 * Default settings for fe driver specific options.
141 * They can be set in config file by "options" statements.
142 */
143
144/*
145 * Debug control.
146 * 0: No debug at all. All debug specific codes are stripped off.
147 * 1: Silent. No debug messages are logged except emergent ones.
148 * 2: Brief. Lair events and/or important information are logged.
149 * 3: Detailed. Logs all information which *may* be useful for debugging.
150 * 4: Trace. All actions in the driver is logged. Super verbose.
151 */
152#ifndef FE_DEBUG
153#define FE_DEBUG 1
154#endif
155
156/*
157 * Transmit just one packet per a "send" command to 86960.
158 * This option is intended for performance test. An EXPERIMENTAL option.
159 */
160#ifndef FE_SINGLE_TRANSMISSION
161#define FE_SINGLE_TRANSMISSION 0
162#endif
163
164/*
165 * Device configuration flags.
166 */
167
168/* DLCR6 settings. */
169#define FE_FLAGS_DLCR6_VALUE 0x007F
170
171/* Force DLCR6 override. */
172#define FE_FLAGS_OVERRIDE_DLCR6 0x0080
--- 22 unchanged lines hidden (view full) ---
195static struct fe_softc {
196
197 /* Used by "common" codes. */
198 struct arpcom arpcom; /* Ethernet common */
199
200 /* Used by config codes. */
201
202 /* Set by probe() and not modified in later phases. */
203 char * typestr; /* printable name of the interface. */
204 u_short iobase; /* base I/O address of the adapter. */
205 u_short ioaddr [ MAXREGISTERS ]; /* I/O addresses of register. */
206 u_short txb_size; /* size of TX buffer, in bytes */
207 u_char proto_dlcr4; /* DLCR4 prototype. */
208 u_char proto_dlcr5; /* DLCR5 prototype. */
209 u_char proto_dlcr6; /* DLCR6 prototype. */
210 u_char proto_dlcr7; /* DLCR7 prototype. */
211 u_char proto_bmpr13; /* BMPR13 prototype. */
212
213 /* Vendor specific hooks. */
214 void ( * init )( struct fe_softc * ); /* Just before fe_init(). */
215 void ( * stop )( struct fe_softc * ); /* Just after fe_stop(). */
216
217 /* Transmission buffer management. */
218 u_short txb_free; /* free bytes in TX buffer */
219 u_char txb_count; /* number of packets in TX buffer */
220 u_char txb_sched; /* number of scheduled packets */
221
222 /* Excessive collision counter (see fe_tint() for details. */
223 u_char tx_excolls; /* # of excessive collisions. */
224
225 /* Multicast address filter management. */
226 u_char filter_change; /* MARs must be changed ASAP. */
227 struct fe_filter filter;/* new filter value. */
228
229} fe_softc[NFE];
230
231#define sc_if arpcom.ac_if
232#define sc_unit arpcom.ac_if.if_unit
233#define sc_enaddr arpcom.ac_enaddr
234
235/* Standard driver entry points. These can be static. */
236static int fe_probe ( struct isa_device * );
237static int fe_attach ( struct isa_device * );
238static void fe_init ( int );
239static ointhand2_t feintr;
240static int fe_ioctl ( struct ifnet *, u_long, caddr_t );
241static void fe_start ( struct ifnet * );
242static void fe_reset ( int );
243static void fe_watchdog ( struct ifnet * );
244
245/* Local functions. Order of declaration is confused. FIXME. */
246static int fe_probe_fmv ( DEVICE *, struct fe_softc * );
247static int fe_probe_ati ( DEVICE *, struct fe_softc * );
248static void fe_init_ati ( struct fe_softc * );
249static int fe_probe_gwy ( DEVICE *, struct fe_softc * );
250#if NCARD > 0
251static int fe_probe_mbh ( DEVICE *, struct fe_softc * );
252static void fe_init_mbh ( struct fe_softc * );
253static int fe_probe_tdk ( DEVICE *, struct fe_softc * );
254#endif
255static int fe_get_packet ( struct fe_softc *, u_short );
256static void fe_stop ( int );
257static void fe_tint ( struct fe_softc *, u_char );
258static void fe_rint ( struct fe_softc *, u_char );
259static void fe_xmit ( struct fe_softc * );
260static void fe_emptybuffer ( struct fe_softc * );
261static void fe_write_mbufs ( struct fe_softc *, struct mbuf * );
262static struct fe_filter
263 fe_mcaf ( struct fe_softc * );
264static int fe_hash ( u_char * );
265static void fe_setmode ( struct fe_softc * );
266static void fe_loadmar ( struct fe_softc * );
267#if FE_DEBUG >= 1
268static void fe_dump ( int, struct fe_softc *, char * );
269#endif
270
271/* Driver struct used in the config code. This must be public (external.) */
272struct isa_driver fedriver =
273{
274 fe_probe,
275 fe_attach,
276 "fe",
--- 16 unchanged lines hidden (view full) ---
293 * minimum size of transmission buffer in fe is 2x2KB,
294 * and minimum amount of received packet including headers
295 * added by the chip is 64 bytes.
296 * Hence FE_MAX_RECV_COUNT is the upper limit for number
297 * of packets in the receive buffer.
298 */
299
300/*
301 * Routines to access contiguous I/O ports.
302 */
303
304static void
305inblk ( struct fe_softc * sc, int offs, u_char * mem, int len )
306{
307 while ( --len >= 0 ) {
308 *mem++ = inb( sc->ioaddr[ offs++ ] );
--- 8 unchanged lines hidden (view full) ---
317 }
318}
319
320/* PCCARD Support */
321#if NCARD > 0
322/*
323 * PC-Card (PCMCIA) specific code.
324 */
325static int feinit ( struct pccard_devinfo * );
326static void feunload ( struct pccard_devinfo * );
327static int fe_card_intr ( struct pccard_devinfo * );
328
329static struct pccard_device fe_info = {
330 "fe",
331 feinit,
332 feunload,
333 fe_card_intr,
334 0, /* Attributes - presently unused */
335 &net_imask /* XXX - Should this also include tty_imask? */
336};
337
338DATA_SET(pccarddrv_set, fe_info);
339
340/*
341 * Initialize the device - called from Slot manager.
342 */
343static int
344feinit(struct pccard_devinfo *devi)
345{
346 struct fe_softc *sc;
347
348 /* validate unit number. */
349 if (devi->isahd.id_unit >= NFE)
350 return (ENODEV);
351 /*
352 * Probe the device. If a value is returned,
353 * the device was found at the location.
354 */
355#if FE_DEBUG >= 2
356 printf("Start Probe\n");
357#endif
358 /* Initialize "minimum" parts of our softc. */
359 sc = &fe_softc[devi->isahd.id_unit];
360 sc->sc_unit = devi->isahd.id_unit;
361 sc->iobase = devi->isahd.id_iobase;
362
363 /* Use Ethernet address got from CIS, if one is available. */
364 if ((devi->misc[0] & 0x03) == 0x00
365 && (devi->misc[0] | devi->misc[1] | devi->misc[2]) != 0) {
366 /* Yes, it looks like a valid Ether address. */
367 bcopy(devi->misc, sc->sc_enaddr, ETHER_ADDR_LEN);
368 } else {
369 /* Indicate we have no Ether address in CIS. */
370 bzero(sc->sc_enaddr, ETHER_ADDR_LEN);
371 }
372
373 /* Probe supported PC card models. */
374 if (fe_probe_tdk(&devi->isahd, sc) == 0 &&
375 fe_probe_mbh(&devi->isahd, sc) == 0)
376 return (ENXIO);
377#if FE_DEBUG >= 2
378 printf("Start attach\n");
379#endif
380 if (fe_attach(&devi->isahd) == 0)
381 return (ENXIO);
382
383 return (0);
384}
385
386/*
387 * feunload - unload the driver and clear the table.
388 * XXX TODO:
389 * This is usually called when the card is ejected, but
390 * can be caused by a modunload of a controller driver.
391 * The idea is to reset the driver's view of the device
392 * and ensure that any driver entry points such as
393 * read and write do not hang.
394 */
395static void
396feunload(struct pccard_devinfo *devi)
397{
398 printf("fe%d: unload\n", devi->isahd.id_unit);
399 fe_stop(devi->isahd.id_unit);
400}
401
402/*
403 * fe_card_intr - Shared interrupt called from
404 * front end of PC-Card handler.
405 */
406static int
407fe_card_intr(struct pccard_devinfo *devi)
408{
409 feintr(devi->isahd.id_unit);
410 return (1);
411}
412#endif /* NCARD > 0 */
413
414
415/*
416 * Hardware probe routines.
417 */
418
419/* How and where to probe; to support automatic I/O address detection. */
420struct fe_probe_list
421{
422 int ( * probe ) ( DEVICE *, struct fe_softc * );
423 u_short const * addresses;
424};
425
426/* Lists of possible addresses. */
427static u_short const fe_fmv_addr [] =
428 { 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x300, 0x340, 0 };
429static u_short const fe_ati_addr [] =
430 { 0x240, 0x260, 0x280, 0x2A0, 0x300, 0x320, 0x340, 0x380, 0 };
431
432static struct fe_probe_list const fe_probe_list [] =
433{
434 { fe_probe_fmv, fe_fmv_addr },
435 { fe_probe_ati, fe_ati_addr },
436 { fe_probe_gwy, NULL }, /* GWYs cannot be auto detected. */
437 { NULL, NULL }
438};
439
440
441/*
442 * Determine if the device is present
443 *
444 * on entry:
445 * a pointer to an isa_device struct
446 * on exit:
447 * zero if device not found
448 * or number of i/o addresses used (if found)
449 */
450
451static int
452fe_probe ( DEVICE * dev )
453{
454 struct fe_softc * sc;
455 int u;
456 int nports;
457 struct fe_probe_list const * list;
458 u_short const * addr;
459 u_short single [ 2 ];
460
461 /* Initialize "minimum" parts of our softc. */
462 sc = &fe_softc[ dev->id_unit ];
463 sc->sc_unit = dev->id_unit;
464
465 /* Probe each possibility, one at a time. */
466 for ( list = fe_probe_list; list->probe != NULL; list++ ) {
467
468 if ( dev->id_iobase != NO_IOADDR ) {
469 /* Probe one specific address. */
470 single[ 0 ] = dev->id_iobase;
471 single[ 1 ] = 0;
472 addr = single;
473 } else if ( list->addresses != NULL ) {
474 /* Auto detect. */
475 addr = list->addresses;
476 } else {
477 /* We need a list of addresses to do auto detect. */
478 continue;
479 }
480
481 /* Probe all possible addresses for the board. */
482 while ( *addr != 0 ) {
483
484 /* See if the address is already in use. */
485 for ( u = 0; u < NFE; u++ ) {
486 if ( fe_softc[u].iobase == *addr ) break;
487 }
488
489#if FE_DEBUG >= 3
490 if ( u == NFE ) {
491 log( LOG_INFO, "fe%d: probing %d at 0x%x\n",
492 sc->sc_unit, list - fe_probe_list, *addr );
493 } else if ( u == sc->sc_unit ) {
494 log( LOG_INFO, "fe%d: re-probing %d at 0x%x?\n",
495 sc->sc_unit, list - fe_probe_list, *addr );
496 } else {
497 log( LOG_INFO, "fe%d: skipping %d at 0x%x\n",
498 sc->sc_unit, list - fe_probe_list, *addr );
499 }
500#endif
501
502 /* Probe the address if it is free. */
503 if ( u == NFE || u == sc->sc_unit ) {
504
505 /* Probe an address. */
506 sc->iobase = *addr;
507 nports = list->probe( dev, sc );
508 if ( nports > 0 ) {
509 /* Found. */
510 dev->id_iobase = *addr;
511 return ( nports );
512 }
513 sc->iobase = 0;
514 }
515
516 /* Try next. */
517 addr++;
518 }
519 }
520
521 /* Probe failed. */
522 return ( 0 );
523}
524
525/*
526 * Check for specific bits in specific registers have specific values.
527 */
528struct fe_simple_probe_struct
529{
530 u_char port; /* Offset from the base I/O address. */
531 u_char mask; /* Bits to be checked. */
532 u_char bits; /* Values to be compared against. */
533};
534
535static int
536fe_simple_probe ( struct fe_softc const * sc,
537 struct fe_simple_probe_struct const * sp )
538{
539 struct fe_simple_probe_struct const * p;
540
541 for ( p = sp; p->mask != 0; p++ ) {
542#if FE_DEBUG >=2
543 printf("Probe Port:%x,Value:%x,Mask:%x.Bits:%x\n",
544 p->port,inb(sc->ioaddr[ p->port]),p->mask,p->bits);
545#endif
546 if ( ( inb( sc->ioaddr[ p->port ] ) & p->mask ) != p->bits )
547 {
548 return ( 0 );
549 }
550 }
551 return ( 1 );
552}
553
554/*
555 * Routines to read all bytes from the config EEPROM through MB86965A.
556 * I'm not sure what exactly I'm doing here... I was told just to follow
557 * the steps, and it worked. Could someone tell me why the following
558 * code works? (Or, why all similar codes I tried previously doesn't
559 * work.) FIXME.
560 */
561
562static void
563fe_strobe_eeprom ( u_short bmpr16 )
564{
565 /*
566 * We must guarantee 800ns (or more) interval to access slow
567 * EEPROMs. The following redundant code provides enough
568 * delay with ISA timing. (Even if the bus clock is "tuned.")
569 * Some modification will be needed on faster busses.
570 */
571 outb( bmpr16, FE_B16_SELECT );
572 outb( bmpr16, FE_B16_SELECT );
573 outb( bmpr16, FE_B16_SELECT | FE_B16_CLOCK );
574 outb( bmpr16, FE_B16_SELECT | FE_B16_CLOCK );
575 outb( bmpr16, FE_B16_SELECT );
576 outb( bmpr16, FE_B16_SELECT );
577}
578
579static void
580fe_read_eeprom ( struct fe_softc * sc, u_char * data )
581{
582 u_short bmpr16 = sc->ioaddr[ FE_BMPR16 ];
583 u_short bmpr17 = sc->ioaddr[ FE_BMPR17 ];
584 u_char n, val, bit;
585
586 /* Read bytes from EEPROM; two bytes per an iteration. */
587 for ( n = 0; n < FE_EEPROM_SIZE / 2; n++ ) {
588
589 /* Reset the EEPROM interface. */
590 outb( bmpr16, 0x00 );
591 outb( bmpr17, 0x00 );
592
593 /* Start EEPROM access. */
594 outb( bmpr16, FE_B16_SELECT );
595 outb( bmpr17, FE_B17_DATA );
596 fe_strobe_eeprom( bmpr16 );
597
598 /* Pass the iteration count to the chip. */
599 val = 0x80 | n;
600 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
601 outb( bmpr17, ( val & bit ) ? FE_B17_DATA : 0 );
602 fe_strobe_eeprom( bmpr16 );
603 }
604 outb( bmpr17, 0x00 );
605
606 /* Read a byte. */
607 val = 0;
608 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
609 fe_strobe_eeprom( bmpr16 );
610 if ( inb( bmpr17 ) & FE_B17_DATA ) {
611 val |= bit;
612 }
613 }
614 *data++ = val;
615
616 /* Read one more byte. */
617 val = 0;
618 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
619 fe_strobe_eeprom( bmpr16 );
620 if ( inb( bmpr17 ) & FE_B17_DATA ) {
621 val |= bit;
622 }
623 }
624 *data++ = val;
625 }
626
627 /* Reset the EEPROM interface, again. */
628 outb( bmpr16, 0x00 );
629 outb( bmpr17, 0x00 );
630
631#if FE_DEBUG >= 3
632 /* Report what we got. */
633 data -= FE_EEPROM_SIZE;
634 log( LOG_INFO, "fe%d: EEPROM:"
635 " %02x%02x%02x%02x %02x%02x%02x%02x -"
636 " %02x%02x%02x%02x %02x%02x%02x%02x -"
637 " %02x%02x%02x%02x %02x%02x%02x%02x -"
638 " %02x%02x%02x%02x %02x%02x%02x%02x\n",
639 sc->sc_unit,
640 data[ 0], data[ 1], data[ 2], data[ 3],
641 data[ 4], data[ 5], data[ 6], data[ 7],
642 data[ 8], data[ 9], data[10], data[11],
643 data[12], data[13], data[14], data[15],
644 data[16], data[17], data[18], data[19],
645 data[20], data[21], data[22], data[23],
646 data[24], data[25], data[26], data[27],
647 data[28], data[29], data[30], data[31] );
648#endif
649}
650
651/*
652 * Hardware (vendor) specific probe routines.
653 */
654
655/*
656 * Probe and initialization for Fujitsu FMV-180 series boards
657 */
658static int
659fe_probe_fmv ( DEVICE * dev, struct fe_softc * sc )
660{
661 int i, n;
662
663 static u_short const baseaddr [ 8 ] =
664 { 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x300, 0x340 };
665 static u_short const irqmap [ 4 ] =
666 { IRQ3, IRQ7, IRQ10, IRQ15 };
667
668 static struct fe_simple_probe_struct const probe_table [] = {
669 { FE_DLCR2, 0x70, 0x00 },
670 { FE_DLCR4, 0x08, 0x00 },
671 /* { FE_DLCR5, 0x80, 0x00 }, Doesn't work. */
672
673 { FE_FMV0, 0x78, 0x50 }, /* ERRDY+PRRDY */
674 { FE_FMV1, 0xB0, 0x00 }, /* FMV-183/184 has 0x48 bits. */
675 { FE_FMV3, 0x7F, 0x00 },
676#if 1
677 /*
678 * Test *vendor* part of the station address for Fujitsu.
679 * The test will gain reliability of probe process, but
680 * it rejects FMV-180 clone boards manufactured by other vendors.
681 * We have to turn the test off when such cards are made available.
682 */
683 { FE_FMV4, 0xFF, 0x00 },
684 { FE_FMV5, 0xFF, 0x00 },
685 { FE_FMV6, 0xFF, 0x0E },
686#else
687 /*
688 * We can always verify the *first* 2 bits (in Ethernet
689 * bit order) are "no multicast" and "no local" even for
690 * unknown vendors.
691 */
692 { FE_FMV4, 0x03, 0x00 },
693#endif
694 { 0 }
695 };
696
697 /* "Hardware revision ID" */
698 int revision;
699
700 /*
701 * See if the specified address is possible for FMV-180 series.
702 */
703 for ( i = 0; i < 8; i++ ) {
704 if ( baseaddr[ i ] == sc->iobase ) break;
705 }
706 if ( i == 8 ) return 0;
707
708 /* Setup an I/O address mapping table. */
709 for ( i = 0; i < MAXREGISTERS; i++ ) {
710 sc->ioaddr[ i ] = sc->iobase + i;
711 }
712
713 /* Simple probe. */
714 if ( !fe_simple_probe( sc, probe_table ) ) return 0;
715
716 /* Check if our I/O address matches config info. on EEPROM. */
717 n = ( inb( sc->ioaddr[ FE_FMV2 ] ) & FE_FMV2_IOS )
718 >> FE_FMV2_IOS_SHIFT;
719 if ( baseaddr[ n ] != sc->iobase ) {
720#if 0
721 /* May not work on some revisions of the cards... FIXME. */
722 return 0;
723#else
724 /* Just log the fact and see what happens... FIXME. */
725 log( LOG_WARNING, "fe%d: strange I/O config?\n", sc->sc_unit );
726#endif
727 }
728
729 /* Find the "hardware revision." */
730 revision = inb( sc->ioaddr[ FE_FMV1 ] ) & FE_FMV1_REV;
731
732 /* Determine the card type. */
733 sc->typestr = NULL;
734 switch ( inb( sc->ioaddr[ FE_FMV0 ] ) & FE_FMV0_MEDIA ) {
735 case 0:
736 /* No interface? This doesn't seem to be an FMV-180... */
737 return 0;
738 case FE_FMV0_MEDIUM_T:
739 switch ( revision ) {
740 case 8:
741 sc->typestr = "FMV-183";
742 break;
743 case 12:
744 sc->typestr = "FMV-183 (on-board)";
745 break;
746 }
747 break;
748 case FE_FMV0_MEDIUM_T | FE_FMV0_MEDIUM_5:
749 switch ( revision ) {
750 case 0:
751 sc->typestr = "FMV-181";
752 break;
753 case 1:
754 sc->typestr = "FMV-181A";
755 break;
756 }
757 break;
758 case FE_FMV0_MEDIUM_2:
759 switch ( revision ) {
760 case 8:
761 sc->typestr = "FMV-184 (CSR = 2)";
762 break;
763 }
764 break;
765 case FE_FMV0_MEDIUM_5:
766 switch ( revision ) {
767 case 8:
768 sc->typestr = "FMV-184 (CSR = 1)";
769 break;
770 }
771 break;
772 case FE_FMV0_MEDIUM_2 | FE_FMV0_MEDIUM_5:
773 switch ( revision ) {
774 case 0:
775 sc->typestr = "FMV-182";
776 break;
777 case 1:
778 sc->typestr = "FMV-182A";
779 break;
780 case 8:
781 sc->typestr = "FMV-184 (CSR = 3)";
782 break;
783 }
784 break;
785 }
786 if ( sc->typestr == NULL ) {
787 /* Unknown card type... Hope the driver works. */
788 sc->typestr = "unknown FMV-180 version";
789 log( LOG_WARNING, "fe%d: %s: %x-%x-%x-%x\n",
790 sc->sc_unit, sc->typestr,
791 inb( sc->ioaddr[ FE_FMV0 ] ),
792 inb( sc->ioaddr[ FE_FMV1 ] ),
793 inb( sc->ioaddr[ FE_FMV2 ] ),
794 inb( sc->ioaddr[ FE_FMV3 ] ) );
795 }
796
797 /*
798 * An FMV-180 has been proved.
799 * Determine which IRQ to be used.
800 *
801 * In this version, we give a priority to the kernel config file.
802 * If the EEPROM and config don't match, say it to the user for
803 * an attention.
804 */
805 n = ( inb( sc->ioaddr[ FE_FMV2 ] ) & FE_FMV2_IRS )
806 >> FE_FMV2_IRS_SHIFT;
807 if ( dev->id_irq == NO_IRQ ) {
808 /* Just use the probed value. */
809 dev->id_irq = irqmap[ n ];
810 } else if ( dev->id_irq != irqmap[ n ] ) {
811 /* Don't match. */
812 log( LOG_WARNING,
813 "fe%d: check IRQ in config; it may be incorrect\n",
814 sc->sc_unit );
815 }
816
817 /*
818 * Initialize constants in the per-line structure.
819 */
820
821 /* Get our station address from EEPROM. */
822 inblk( sc, FE_FMV4, sc->sc_enaddr, ETHER_ADDR_LEN );
823
824 /* Make sure we got a valid station address. */
825 if ( ( sc->sc_enaddr[ 0 ] & 0x03 ) != 0x00
826 || ( sc->sc_enaddr[ 0 ] == 0x00
827 && sc->sc_enaddr[ 1 ] == 0x00
828 && sc->sc_enaddr[ 2 ] == 0x00 ) ) return 0;
829
830 /*
831 * Register values which (may) depend on board design.
832 *
833 * Program the 86960 as follows:
834 * SRAM: 32KB, 100ns, byte-wide access.
835 * Transmission buffer: 4KB x 2.
836 * System bus interface: 16 bits.
837 */
838 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
839 sc->proto_dlcr5 = 0;
840 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
841 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
842 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_EC;
843 sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
844
845 /*
846 * Minimum initialization of the hardware.
847 * We write into registers; hope I/O ports have no
848 * overlap with other boards.
849 */
850
851 /* Initialize ASIC. */
852 outb( sc->ioaddr[ FE_FMV3 ], 0 );
853 outb( sc->ioaddr[ FE_FMV10 ], 0 );
854
855 /* Initialize 86960. */
856 DELAY( 200 );
857 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
858 DELAY( 200 );
859
860 /* Disable all interrupts. */
861 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
862 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
863
864 /* "Refresh" hardware configuration. FIXME. */
865 outb( sc->ioaddr[ FE_FMV2 ], inb( sc->ioaddr[ FE_FMV2 ] ) );
866
867 /* Turn the "master interrupt control" flag of ASIC on. */
868 outb( sc->ioaddr[ FE_FMV3 ], FE_FMV3_IRQENB );
869
870 /*
871 * That's all. FMV-180 occupies 32 I/O addresses, by the way.
872 */
873 return 32;
874}
875
876/*
877 * Probe and initialization for Allied-Telesis AT1700/RE2000 series.
878 */
879static int
880fe_probe_ati ( DEVICE * dev, struct fe_softc * sc )
881{
882 int i, n;
883 u_char eeprom [ FE_EEPROM_SIZE ];
884 u_char save16, save17;
885
886 static u_short const baseaddr [ 8 ] =
887 { 0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300 };
888 static u_short const irqmaps [ 4 ][ 4 ] =
889 {
890 { IRQ3, IRQ4, IRQ5, IRQ9 },
891 { IRQ10, IRQ11, IRQ12, IRQ15 },
892 { IRQ3, IRQ11, IRQ5, IRQ15 },
893 { IRQ10, IRQ11, IRQ14, IRQ15 },
894 };
895 static struct fe_simple_probe_struct const probe_table [] = {
896 { FE_DLCR2, 0x70, 0x00 },
897 { FE_DLCR4, 0x08, 0x00 },
898 { FE_DLCR5, 0x80, 0x00 },
899#if 0
900 { FE_BMPR16, 0x1B, 0x00 },
901 { FE_BMPR17, 0x7F, 0x00 },
902#endif
903 { 0 }
904 };
905
906 /* Assume we have 86965 and no need to restore these. */
907 save16 = 0;
908 save17 = 0;
909
910#if FE_DEBUG >= 3
911 log( LOG_INFO, "fe%d: probe (0x%x) for ATI\n",
912 sc->sc_unit, sc->iobase );
913 fe_dump( LOG_INFO, sc, NULL );
914#endif
915
916 /*
917 * See if the specified address is possible for MB86965A JLI mode.
918 */
919 for ( i = 0; i < 8; i++ ) {
920 if ( baseaddr[ i ] == sc->iobase ) break;
921 }
922 if ( i == 8 ) goto NOTFOUND;
923
924 /* Setup an I/O address mapping table. */
925 for ( i = 0; i < MAXREGISTERS; i++ ) {
926 sc->ioaddr[ i ] = sc->iobase + i;
927 }
928
929 /*
930 * We should test if MB86965A is on the base address now.
931 * Unfortunately, it is very hard to probe it reliably, since
932 * we have no way to reset the chip under software control.
933 * On cold boot, we could check the "signature" bit patterns
934 * described in the Fujitsu document. On warm boot, however,
935 * we can predict almost nothing about register values.
936 */
937 if ( !fe_simple_probe( sc, probe_table ) ) goto NOTFOUND;
938
939 /* Check if our I/O address matches config info on 86965. */
940 n = ( inb( sc->ioaddr[ FE_BMPR19 ] ) & FE_B19_ADDR )
941 >> FE_B19_ADDR_SHIFT;
942 if ( baseaddr[ n ] != sc->iobase ) goto NOTFOUND;
943
944 /*
945 * We are now almost sure we have an AT1700 at the given
946 * address. So, read EEPROM through 86965. We have to write
947 * into LSI registers to read from EEPROM. I want to avoid it
948 * at this stage, but I cannot test the presence of the chip
949 * any further without reading EEPROM. FIXME.
950 */
951 save16 = inb( sc->ioaddr[ FE_BMPR16 ] );
952 save17 = inb( sc->ioaddr[ FE_BMPR17 ] );
953 fe_read_eeprom( sc, eeprom );
954
955 /* Make sure the EEPROM is turned off. */
956 outb( sc->ioaddr[ FE_BMPR16 ], 0 );
957 outb( sc->ioaddr[ FE_BMPR17 ], 0 );
958
959 /* Make sure that config info in EEPROM and 86965 agree. */
960 if ( eeprom[ FE_EEPROM_CONF ] != inb( sc->ioaddr[ FE_BMPR19 ] ) ) {
961 goto NOTFOUND;
962 }
963
964 /*
965 * The following model identification codes are stolen from
966 * from the NetBSD port of the fe driver. My reviewers
967 * suggested minor revision.
968 */
969
970 /* Determine the card type. */
971 switch (eeprom[FE_ATI_EEP_MODEL]) {
972 case FE_ATI_MODEL_AT1700T:
973 sc->typestr = "AT-1700T/RE2001";
974 break;
975 case FE_ATI_MODEL_AT1700BT:
976 sc->typestr = "AT-1700BT/RE2003";
977 break;
978 case FE_ATI_MODEL_AT1700FT:
979 sc->typestr = "AT-1700FT/RE2009";
980 break;
981 case FE_ATI_MODEL_AT1700AT:
982 sc->typestr = "AT-1700AT/RE2005";
983 break;
984 default:
985 sc->typestr = "unknown AT-1700/RE2000 ?";
986 break;
987 }
988
989 /*
990 * Try to determine IRQ settings.
991 * Different models use different ranges of IRQs.
992 */
993 if ( dev->id_irq == NO_IRQ ) {
994 n = ( inb( sc->ioaddr[ FE_BMPR19 ] ) & FE_B19_IRQ )
995 >> FE_B19_IRQ_SHIFT;
996 switch ( eeprom[ FE_ATI_EEP_REVISION ] & 0xf0 ) {
997 case 0x30:
998 dev->id_irq = irqmaps[ 3 ][ n ];
999 break;
1000 case 0x10:
1001 case 0x50:
1002 dev->id_irq = irqmaps[ 2 ][ n ];
1003 break;
1004 case 0x40:
1005 case 0x60:
1006 if ( eeprom[ FE_ATI_EEP_MAGIC ] & 0x04 ) {
1007 dev->id_irq = irqmaps[ 1 ][ n ];
1008 } else {
1009 dev->id_irq = irqmaps[ 0 ][ n ];
1010 }
1011 break;
1012 default:
1013 dev->id_irq = irqmaps[ 0 ][ n ];
1014 break;
1015 }
1016 }
1017
1018
1019 /*
1020 * Initialize constants in the per-line structure.
1021 */
1022
1023 /* Get our station address from EEPROM. */
1024 bcopy( eeprom + FE_ATI_EEP_ADDR, sc->sc_enaddr, ETHER_ADDR_LEN );
1025
1026#if 1
1027 /*
1028 * This test doesn't work well for AT1700 look-alike by
1029 * other vendors.
1030 */
1031 /* Make sure the vendor part is for Allied-Telesis. */
1032 if ( sc->sc_enaddr[ 0 ] != 0x00
1033 || sc->sc_enaddr[ 1 ] != 0x00
1034 || sc->sc_enaddr[ 2 ] != 0xF4 ) return 0;
1035
1036#else
1037 /* Make sure we got a valid station address. */
1038 if ( ( sc->sc_enaddr[ 0 ] & 0x03 ) != 0x00
1039 || ( sc->sc_enaddr[ 0 ] == 0x00
1040 && sc->sc_enaddr[ 1 ] == 0x00
1041 && sc->sc_enaddr[ 2 ] == 0x00 ) ) return 0;
1042#endif
1043
1044 /*
1045 * Program the 86960 as follows:
1046 * SRAM: 32KB, 100ns, byte-wide access.
1047 * Transmission buffer: 4KB x 2.
1048 * System bus interface: 16 bits.
1049 */
1050 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL; /* FIXME */
1051 sc->proto_dlcr5 = 0;
1052 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
1053 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
1054 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_EC;
1055#if 0 /* XXXX Should we use this? FIXME. */
1056 sc->proto_bmpr13 = eeprom[ FE_ATI_EEP_MEDIA ];
1057#else
1058 sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
1059#endif
1060
1061#if FE_DEBUG >= 3
1062 fe_dump( LOG_INFO, sc, "ATI found" );
1063#endif
1064
1065 /* Setup hooks. This may solves a nasty bug. FIXME. */
1066 sc->init = fe_init_ati;
1067
1068 /* Initialize 86965. */
1069 DELAY( 200 );
1070 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1071 DELAY( 200 );
1072
1073 /* Disable all interrupts. */
1074 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
1075 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
1076
1077#if FE_DEBUG >= 3
1078 fe_dump( LOG_INFO, sc, "end of fe_probe_ati()" );
1079#endif
1080
1081 /*
1082 * That's all. AT1700 occupies 32 I/O addresses, by the way.
1083 */
1084 return 32;
1085
1086 NOTFOUND:
1087 /*
1088 * We have no AT1700 at a given address.
1089 * Restore BMPR16 and BMPR17 if we have destroyed them,
1090 * hoping that the hardware on the address didn't get
1091 * bad side effect.
1092 */
1093 if ( save16 != 0 | save17 != 0 ) {
1094 outb( sc->ioaddr[ FE_BMPR16 ], save16 );
1095 outb( sc->ioaddr[ FE_BMPR17 ], save17 );
1096 }
1097 return ( 0 );
1098}
1099
1100/* ATI specific initialization routine. */
1101static void
1102fe_init_ati ( struct fe_softc * sc )
1103{
1104/*
1105 * I've told that the following operation "Resets" the chip.
1106 * Hope this solve a bug which hangs up the driver under
1107 * heavy load... FIXME.
1108 */
1109
1110 /* Minimal initialization of 86965. */
1111 DELAY( 200 );
1112 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1113 DELAY( 200 );
1114
1115 /* "Reset" by wrting into an undocument register location. */
1116 outb( sc->ioaddr[ 0x1F ], 0 );
1117
1118 /* How long do we have to wait after the reset? FIXME. */
1119 DELAY( 300 );
1120}
1121
1122/*
1123 * Probe and initialization for Gateway Communications' old cards.
1124 */
1125static int
1126fe_probe_gwy ( DEVICE * dev, struct fe_softc * sc )
1127{
1128 int i;
1129
1130 static struct fe_simple_probe_struct probe_table [] = {
1131 { FE_DLCR2, 0x70, 0x00 },
1132 { FE_DLCR4, 0x08, 0x00 },
1133 { FE_DLCR7, 0xC0, 0x00 },
1134 /*
1135 * Test *vendor* part of the address for Gateway.
1136 * This test is essential to identify Gateway's cards.
1137 * We shuld define some symbolic names for the
1138 * following offsets. FIXME.
1139 */
1140 { 0x18, 0xFF, 0x00 },
1141 { 0x19, 0xFF, 0x00 },
1142 { 0x1A, 0xFF, 0x61 },
1143 { 0 }
1144 };
1145
1146 /*
1147 * We need explicit IRQ and supported address.
1148 * I'm not sure which address and IRQ is possible for Gateway
1149 * Ethernet family. The following accepts everything. FIXME.
1150 */
1151 if ( dev->id_irq == NO_IRQ || ( sc->iobase & ~0x3E0 ) != 0 ) {
1152 return ( 0 );
1153 }
1154
1155#if FE_DEBUG >= 3
1156 fe_dump( LOG_INFO, sc, "top of probe" );
1157#endif
1158
1159 /* Setup an I/O address mapping table. */
1160 for ( i = 0; i < MAXREGISTERS; i++ ) {
1161 sc->ioaddr[ i ] = sc->iobase + i;
1162 }
1163
1164 /* See if the card is on its address. */
1165 if ( !fe_simple_probe( sc, probe_table ) ) {
1166 return 0;
1167 }
1168
1169 /* Determine the card type. */
1170 sc->typestr = "Gateway Ethernet w/ Fujitsu chipset";
1171
1172 /* Get our station address from EEPROM. */
1173 inblk( sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN );
1174
1175 /*
1176 * Program the 86960 as follows:
1177 * SRAM: 16KB, 100ns, byte-wide access.
1178 * Transmission buffer: 2KB x 2.
1179 * System bus interface: 16 bits.
1180 * Make sure to clear out ID bits in DLCR7
1181 * (They actually are Encoder/Decoder control in NICE.)
1182 */
1183 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
1184 sc->proto_dlcr5 = 0;
1185 sc->proto_dlcr6 = FE_D6_BUFSIZ_16KB | FE_D6_TXBSIZ_2x2KB
1186 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
1187 sc->proto_dlcr7 = FE_D7_BYTSWP_LH;
1188 sc->proto_bmpr13 = 0;
1189
1190 /* Minimal initialization of 86960. */
1191 DELAY( 200 );
1192 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1193 DELAY( 200 );
1194
1195 /* Disable all interrupts. */
1196 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
1197 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
1198
1199 /* That's all. The card occupies 32 I/O addresses, as always. */
1200 return 32;
1201}
1202
1203#if NCARD > 0
1204/*
1205 * Probe and initialization for Fujitsu MBH10302 PCMCIA Ethernet interface.
1206 * Note that this is for 10302 only; MBH10304 is handled by fe_probe_tdk().
1207 */
1208static int
1209fe_probe_mbh ( DEVICE * dev, struct fe_softc * sc )
1210{
1211 int i;
1212
1213 static struct fe_simple_probe_struct probe_table [] = {
1214 { FE_DLCR0, 0x09, 0x00 },
1215 { FE_DLCR2, 0x79, 0x00 },
1216 { FE_DLCR4, 0x08, 0x00 },
1217 { FE_DLCR6, 0xFF, 0xB6 },
1218 /*
1219 * The following location has the first byte of the card's
1220 * Ethernet (MAC) address.
1221 * We can always verify the *first* 2 bits (in Ethernet
1222 * bit order) are "global" and "unicast" for any vendors'.
1223 */
1224 { FE_MBH10, 0x03, 0x00 },
1225
1226 /* Just a gap? Seems reliable, anyway. */
1227 { 0x12, 0xFF, 0x00 },
1228 { 0x13, 0xFF, 0x00 },
1229 { 0x14, 0xFF, 0x00 },
1230 { 0x15, 0xFF, 0x00 },
1231 { 0x16, 0xFF, 0x00 },
1232 { 0x17, 0xFF, 0x00 },
1233#if 0
1234 { 0x18, 0xFF, 0xFF },
1235 { 0x19, 0xFF, 0xFF },
1236#endif
1237
1238 { 0 }
1239 };
1240
1241 /*
1242 * We need explicit IRQ and supported address.
1243 */
1244 if ( dev->id_irq == NO_IRQ || ( sc->iobase & ~0x3E0 ) != 0 ) {
1245 return ( 0 );
1246 }
1247
1248#if FE_DEBUG >= 3
1249 fe_dump( LOG_INFO, sc, "top of probe" );
1250#endif
1251
1252 /* Setup an I/O address mapping table. */
1253 for ( i = 0; i < MAXREGISTERS; i++ ) {
1254 sc->ioaddr[ i ] = sc->iobase + i;
1255 }
1256
1257 /*
1258 * See if MBH10302 is on its address.
1259 * I'm not sure the following probe code works. FIXME.
1260 */
1261 if ( !fe_simple_probe( sc, probe_table ) ) return 0;
1262
1263 /* Determine the card type. */
1264 sc->typestr = "MBH10302 (PCMCIA)";
1265
1266 /*
1267 * Initialize constants in the per-line structure.
1268 */
1269
1270 /* Get our station address from EEPROM. */
1271 inblk( sc, FE_MBH10, sc->sc_enaddr, ETHER_ADDR_LEN );
1272
1273 /* Make sure we got a valid station address. */
1274 if ( sc->sc_enaddr[ 0 ] == 0x00
1275 && sc->sc_enaddr[ 1 ] == 0x00
1276 && sc->sc_enaddr[ 2 ] == 0x00 ) return 0;
1277
1278 /*
1279 * Program the 86960 as follows:
1280 * SRAM: 32KB, 100ns, byte-wide access.
1281 * Transmission buffer: 4KB x 2.
1282 * System bus interface: 16 bits.
1283 */
1284 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
1285 sc->proto_dlcr5 = 0;
1286 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
1287 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
1288 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
1289 sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
1290
1291 /* Setup hooks. We need a special initialization procedure. */
1292 sc->init = fe_init_mbh;
1293
1294 /*
1295 * Minimum initialization.
1296 */
1297
1298 /* Minimal initialization of 86960. */
1299 DELAY( 200 );
1300 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1301 DELAY( 200 );
1302
1303 /* Disable all interrupts. */
1304 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
1305 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
1306
1307#if 1 /* FIXME. */
1308 /* Initialize system bus interface and encoder/decoder operation. */
1309 outb( sc->ioaddr[ FE_MBH0 ], FE_MBH0_MAGIC | FE_MBH0_INTR_DISABLE );
1310#endif
1311
1312 /*
1313 * That's all. MBH10302 occupies 32 I/O addresses, by the way.
1314 */
1315 return 32;
1316}
1317
1318/* MBH specific initialization routine. */
1319static void
1320fe_init_mbh ( struct fe_softc * sc )
1321{
1322 /* Minimal initialization of 86960. */
1323 DELAY( 200 );
1324 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1325 DELAY( 200 );
1326
1327 /* Disable all interrupts. */
1328 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
1329 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
1330
1331 /* Enable master interrupt flag. */
1332 outb( sc->ioaddr[ FE_MBH0 ], FE_MBH0_MAGIC | FE_MBH0_INTR_ENABLE );
1333}
1334
1335/*
1336 * Probe and initialization for TDK/CONTEC PCMCIA Ethernet interface.
1337 * by MASUI Kenji <masui@cs.titech.ac.jp>
1338 *
1339 * (Contec uses TDK Ethenet chip -- hosokawa)
1340 *
1341 * This version of fe_probe_tdk has been rewrote to handle
1342 * *generic* PC card implementation of Fujitsu MB8696x and compatibles.
1343 * The name _tdk is just for a historical reason. <seki> :-)
1344 */
1345static int
1346fe_probe_tdk ( DEVICE * dev, struct fe_softc * sc )
1347{
1348 int i;
1349
1350 static struct fe_simple_probe_struct probe_table [] = {
1351 { FE_DLCR2, 0x70, 0x00 },
1352 { FE_DLCR4, 0x08, 0x00 },
1353 /* { FE_DLCR5, 0x80, 0x00 }, Does not work well. */
1354 { 0 }
1355 };
1356
1357 /* We need an IRQ. */
1358 if ( dev->id_irq == NO_IRQ ) {
1359 return ( 0 );
1360 }
1361
1362 /* Generic driver needs Ethernet address taken from CIS. */
1363 if (sc->arpcom.ac_enaddr[0] == 0
1364 && sc->arpcom.ac_enaddr[1] == 0
1365 && sc->arpcom.ac_enaddr[2] == 0) {
1366 return 0;
1367 }
1368
1369 /* Setup an I/O address mapping table; we need only 16 ports. */
1370 for (i = 0; i < 16; i++) {
1371 sc->ioaddr[i] = sc->iobase + i;
1372 }
1373 /* Fill unused slots with a safe address. */
1374 for (i = 16; i < MAXREGISTERS; i++) {
1375 sc->ioaddr[i] = sc->iobase;
1376 }
1377
1378 /*
1379 * See if C-NET(PC)C is on its address.
1380 */
1381
1382 if ( !fe_simple_probe( sc, probe_table ) ) return 0;
1383
1384 /* Determine the card type. */
1385 sc->typestr = "Generic MB8696x Ethernet (PCMCIA)";
1386
1387 /*
1388 * Initialize constants in the per-line structure.
1389 */
1390
1391 /* The station address *must*be* already in sc_enaddr;
1392 Make sure we got a valid station address. */
1393 if ( ( sc->sc_enaddr[ 0 ] & 0x03 ) != 0x00
1394 || ( sc->sc_enaddr[ 0 ] == 0x00
1395 && sc->sc_enaddr[ 1 ] == 0x00
1396 && sc->sc_enaddr[ 2 ] == 0x00 ) ) return 0;
1397
1398 /*
1399 * Program the 86965 as follows:
1400 * SRAM: 32KB, 100ns, byte-wide access.
1401 * Transmission buffer: 4KB x 2.
1402 * System bus interface: 16 bits.
1403 * XXX: Should we remove IDENT_NICE from DLCR7? Or,
1404 * even add IDENT_EC instead? FIXME.
1405 */
1406 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
1407 sc->proto_dlcr5 = 0;
1408 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
1409 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
1410 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
1411 sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
1412
1413 /* Minimul initialization of 86960. */
1414 DELAY( 200 );
1415 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1416 DELAY( 200 );
1417
1418 /* Disable all interrupts. */
1419 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
1420 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
1421
1422 /*
1423 * That's all. C-NET(PC)C occupies 16 I/O addresses.
1424 *
1425 * Some PC cards (e.g., TDK and Contec) have 16 I/O addresses,
1426 * while some others (e.g., Fujitsu) have 32. Fortunately,
1427 * this generic driver never accesses latter 16 ports in 32
1428 * ports cards. So, we can assume the *generic* PC cards
1429 * always have 16 ports.
1430 *
1431 * Moreover, PC card probe is isolated from ISA probe, and PC
1432 * card probe routine doesn't use "# of ports" returned by this
1433 * function. 16 v.s. 32 is not important now.
1434 */
1435 return 16;
1436}
1437#endif /* NCARD > 0 */
1438
1439/*
1440 * Install interface into kernel networking data structures
1441 */
1442static int
1443fe_attach ( DEVICE * dev )
1444{
1445#if NCARD > 0
1446 static int already_ifattach[NFE];
1447#endif
1448 struct fe_softc *sc = &fe_softc[dev->id_unit];
1449
1450 dev->id_ointr = feintr;
1451
1452 /*
1453 * Initialize ifnet structure
1454 */
1455 sc->sc_if.if_softc = sc;
1456 sc->sc_if.if_unit = sc->sc_unit;
1457 sc->sc_if.if_name = "fe";
1458 sc->sc_if.if_output = ether_output;
1459 sc->sc_if.if_start = fe_start;
1460 sc->sc_if.if_ioctl = fe_ioctl;
1461 sc->sc_if.if_watchdog = fe_watchdog;
1462
1463 /*
1464 * Set default interface flags.
1465 */
1466 sc->sc_if.if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1467
1468 /*
1469 * Set maximum size of output queue, if it has not been set.
1470 * It is done here as this driver may be started after the
1471 * system initialization (i.e., the interface is PCMCIA.)
1472 *
1473 * I'm not sure this is really necessary, but, even if it is,
1474 * it should be done somewhere else, e.g., in if_attach(),
1475 * since it must be a common workaround for all network drivers.
1476 * FIXME.
1477 */
1478 if ( sc->sc_if.if_snd.ifq_maxlen == 0 ) {
1479 sc->sc_if.if_snd.ifq_maxlen = ifqmaxlen;
1480 }
1481
1482#if FE_DEBUG >= 3
1483 fe_dump( LOG_INFO, sc, "attach()" );
1484#endif
1485
1486#if FE_SINGLE_TRANSMISSION
1487 /* Override txb config to allocate minimum. */
1488 sc->proto_dlcr6 &= ~FE_D6_TXBSIZ
1489 sc->proto_dlcr6 |= FE_D6_TXBSIZ_2x2KB;
1490#endif
1491
--- 4 unchanged lines hidden (view full) ---
1496
1497 /* Find TX buffer size, based on the hardware dependent proto. */
1498 switch ( sc->proto_dlcr6 & FE_D6_TXBSIZ ) {
1499 case FE_D6_TXBSIZ_2x2KB: sc->txb_size = 2048; break;
1500 case FE_D6_TXBSIZ_2x4KB: sc->txb_size = 4096; break;
1501 case FE_D6_TXBSIZ_2x8KB: sc->txb_size = 8192; break;
1502 default:
1503 /* Oops, we can't work with single buffer configuration. */
1504#if FE_DEBUG >= 2
1505 log( LOG_WARNING, "fe%d: strange TXBSIZ config; fixing\n",
1506 sc->sc_unit );
1507#endif
1508 sc->proto_dlcr6 &= ~FE_D6_TXBSIZ;
1509 sc->proto_dlcr6 |= FE_D6_TXBSIZ_2x2KB;
1510 sc->txb_size = 2048;
1511 break;
1512 }
1513
1514 /* Attach and stop the interface. */
1515#if NCARD > 0
1516 if (already_ifattach[dev->id_unit] != 1) {
1517 if_attach(&sc->sc_if);
1518 already_ifattach[dev->id_unit] = 1;
1519 }
1520#else
1521 if_attach(&sc->sc_if);
1522#endif
1523 fe_stop(sc->sc_unit); /* This changes the state to IDLE. */
1524 ether_ifattach(&sc->sc_if);
1525
1526 /* Print additional info when attached. */
1527 printf( "fe%d: address %6D, type %s\n", sc->sc_unit,
1528 sc->sc_enaddr, ":" , sc->typestr );
1529#if FE_DEBUG >= 3
1530 {
1531 int buf, txb, bbw, sbw, ram;
1532
1533 buf = txb = bbw = sbw = ram = -1;
1534 switch ( sc->proto_dlcr6 & FE_D6_BUFSIZ ) {
1535 case FE_D6_BUFSIZ_8KB: buf = 8; break;
1536 case FE_D6_BUFSIZ_16KB: buf = 16; break;
1537 case FE_D6_BUFSIZ_32KB: buf = 32; break;
1538 case FE_D6_BUFSIZ_64KB: buf = 64; break;
--- 10 unchanged lines hidden (view full) ---
1549 switch ( sc->proto_dlcr6 & FE_D6_SBW ) {
1550 case FE_D6_SBW_BYTE: sbw = 8; break;
1551 case FE_D6_SBW_WORD: sbw = 16; break;
1552 }
1553 switch ( sc->proto_dlcr6 & FE_D6_SRAM ) {
1554 case FE_D6_SRAM_100ns: ram = 100; break;
1555 case FE_D6_SRAM_150ns: ram = 150; break;
1556 }
1557 printf( "fe%d: SRAM %dKB %dbit %dns, TXB %dKBx2, %dbit I/O\n",
1558 sc->sc_unit, buf, bbw, ram, txb, sbw );
1559 }
1560#endif
1561
1562#if NBPFILTER > 0
1563 /* If BPF is in the kernel, call the attach for it. */
1564 bpfattach( &sc->sc_if, DLT_EN10MB, sizeof(struct ether_header));
1565#endif
1566 return 1;
1567}
1568
1569/*
1570 * Reset interface.
1571 */
1572static void
1573fe_reset ( int unit )
1574{
1575 /*
1576 * Stop interface and re-initialize.
1577 */
1578 fe_stop(unit);
1579 fe_init(unit);
1580}
1581
1582/*
1583 * Stop everything on the interface.
1584 *
1585 * All buffered packets, both transmitting and receiving,
1586 * if any, will be lost by stopping the interface.
1587 */
1588static void
1589fe_stop ( int unit )
1590{
1591 struct fe_softc *sc = &fe_softc[unit];
1592 int s;
1593
1594 s = splimp();
1595
1596#if FE_DEBUG >= 3
1597 fe_dump( LOG_INFO, sc, "stop()" );
1598#endif
1599
1600 /* Disable interrupts. */
1601 outb( sc->ioaddr[ FE_DLCR2 ], 0x00 );
1602 outb( sc->ioaddr[ FE_DLCR3 ], 0x00 );
1603
1604 /* Stop interface hardware. */
1605 DELAY( 200 );
1606 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1607 DELAY( 200 );
--- 12 unchanged lines hidden (view full) ---
1620 sc->sc_if.if_timer = 0;
1621 sc->txb_free = sc->txb_size;
1622 sc->txb_count = 0;
1623 sc->txb_sched = 0;
1624
1625 /* MAR loading can be delayed. */
1626 sc->filter_change = 0;
1627
1628 /* Update config status also. */
1629
1630 /* Call a hook. */
1631 if ( sc->stop ) sc->stop( sc );
1632
1633#if FE_DEBUG >= 3
1634 fe_dump( LOG_INFO, sc, "end of stop()" );
1635#endif
1636
1637 (void) splx(s);
1638}
1639
1640/*
1641 * Device timeout/watchdog routine. Entered if the device neglects to
1642 * generate an interrupt after a transmit has been started on it.
1643 */
1644static void
1645fe_watchdog ( struct ifnet *ifp )
1646{
1647 struct fe_softc *sc = (struct fe_softc *)ifp;
1648
1649#if FE_DEBUG >= 1
1650 /* A "debug" message. */
1651 log( LOG_ERR, "fe%d: transmission timeout (%d+%d)%s\n",
1652 ifp->if_unit, sc->txb_sched, sc->txb_count,
1653 ( ifp->if_flags & IFF_UP ) ? "" : " when down" );
1654 if ( sc->sc_if.if_opackets == 0 && sc->sc_if.if_ipackets == 0 ) {
1655 log( LOG_WARNING, "fe%d: wrong IRQ setting in config?\n",
1656 ifp->if_unit );
1657 }
1658#endif
1659
1660#if FE_DEBUG >= 3
1661 fe_dump( LOG_INFO, sc, NULL );
1662#endif
1663
1664 /* Record how many packets are lost by this accident. */
1665 ifp->if_oerrors += sc->txb_sched + sc->txb_count;
1666
1667 /* Put the interface into known initial state. */
1668 if ( ifp->if_flags & IFF_UP ) {
1669 fe_reset( ifp->if_unit );
1670 } else {
1671 fe_stop( ifp->if_unit );
1672 }
1673}
1674
1675/*
1676 * Initialize device.
1677 */
1678static void
1679fe_init ( int unit )
1680{
1681 struct fe_softc *sc = &fe_softc[unit];
1682 int s;
1683
1684#if FE_DEBUG >= 3
1685 fe_dump( LOG_INFO, sc, "init()" );
1686#endif
1687
1688 /* We need an address. */
1689 if (TAILQ_EMPTY(&sc->sc_if.if_addrhead)) { /* XXX unlikely */
1690#if FE_DEBUG >= 1
1691 log( LOG_ERR, "fe%d: init() without any address\n",
1692 sc->sc_unit );
1693#endif
1694 return;
1695 }
1696
1697#if FE_DEBUG >= 1
1698 /*
1699 * Make sure we have a valid station address.
1700 * The following test is applicable for any Ethernet interfaces.
1701 * It can be done in somewhere common to all of them. FIXME.
1702 */
1703 if ( ( sc->sc_enaddr[ 0 ] & 0x01 ) != 0
1704 || ( sc->sc_enaddr[ 0 ] == 0x00
1705 && sc->sc_enaddr[ 1 ] == 0x00
1706 && sc->sc_enaddr[ 2 ] == 0x00 ) ) {
1707 log( LOG_ERR, "fe%d: invalid station address (%6D)\n",
1708 sc->sc_unit, sc->sc_enaddr, ":" );
1709 return;
1710 }
1711#endif
1712
1713 /* Start initializing 86960. */
1714 s = splimp();
1715
1716 /* Call a hook. */
1717 if ( sc->init ) sc->init( sc );
1718
1719#if FE_DEBUG >= 3
1720 fe_dump( LOG_INFO, sc, "after init hook" );
1721#endif
1722
1723 /*
1724 * Make sure to disable the chip, also.
1725 * This may also help re-programming the chip after
1726 * hot insertion of PCMCIAs.
1727 */
1728 DELAY( 200 );
1729 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1730 DELAY( 200 );
--- 25 unchanged lines hidden (view full) ---
1756 outb( sc->ioaddr[ FE_DLCR5 ], sc->proto_dlcr5 );
1757 outb( sc->ioaddr[ FE_BMPR10 ], 0x00 );
1758 outb( sc->ioaddr[ FE_BMPR11 ], FE_B11_CTRL_SKIP | FE_B11_MODE1 );
1759 outb( sc->ioaddr[ FE_BMPR12 ], 0x00 );
1760 outb( sc->ioaddr[ FE_BMPR13 ], sc->proto_bmpr13 );
1761 outb( sc->ioaddr[ FE_BMPR14 ], 0x00 );
1762 outb( sc->ioaddr[ FE_BMPR15 ], 0x00 );
1763
1764#if FE_DEBUG >= 3
1765 fe_dump( LOG_INFO, sc, "just before enabling DLC" );
1766#endif
1767
1768 /* Enable interrupts. */
1769 outb( sc->ioaddr[ FE_DLCR2 ], FE_TMASK );
1770 outb( sc->ioaddr[ FE_DLCR3 ], FE_RMASK );
1771
1772 /* Enable transmitter and receiver. */
1773 DELAY( 200 );
1774 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_ENABLE );
1775 DELAY( 200 );
1776
1777#if FE_DEBUG >= 3
1778 fe_dump( LOG_INFO, sc, "just after enabling DLC" );
1779#endif
1780
1781 /*
1782 * Make sure to empty the receive buffer.
1783 *
1784 * This may be redundant, but *if* the receive buffer were full
1785 * at this point, then the driver would hang. I have experienced
1786 * some strange hang-up just after UP. I hope the following
1787 * code solve the problem.
1788 *
1789 * I have changed the order of hardware initialization.
1790 * I think the receive buffer cannot have any packets at this
1791 * point in this version. The following code *must* be
1792 * redundant now. FIXME.
1793 *
1794 * I've heard a rumore that on some PC card implementation of
1795 * 8696x, the receive buffer can have some data at this point.
1796 * The following message helps discovering the fact. FIXME.
1797 */
1798 if ( !( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) ) {
1799 log( LOG_WARNING,
1800 "fe%d: receive buffer has some data after reset\n",
1801 sc->sc_unit );
1802
1803 fe_emptybuffer( sc );
1804 }
1805
1806#if FE_DEBUG >= 3
1807 fe_dump( LOG_INFO, sc, "after ERB loop" );
1808#endif
1809
1810 /* Do we need this here? Actually, no. I must be paranoia. */
1811 outb( sc->ioaddr[ FE_DLCR0 ], 0xFF ); /* Clear all bits. */
1812 outb( sc->ioaddr[ FE_DLCR1 ], 0xFF ); /* ditto. */
1813
1814#if FE_DEBUG >= 3
1815 fe_dump( LOG_INFO, sc, "after FIXME" );
1816#endif
1817 /* Set 'running' flag, because we are now running. */
1818 sc->sc_if.if_flags |= IFF_RUNNING;
1819
1820 /*
1821 * At this point, the interface is running properly,
1822 * except that it receives *no* packets. we then call
1823 * fe_setmode() to tell the chip what packets to be
1824 * received, based on the if_flags and multicast group
1825 * list. It completes the initialization process.
1826 */
1827 fe_setmode( sc );
1828
1829#if FE_DEBUG >= 3
1830 fe_dump( LOG_INFO, sc, "after setmode" );
1831#endif
1832
1833 /* ...and attempt to start output queued packets. */
1834 fe_start( &sc->sc_if );
1835
1836#if FE_DEBUG >= 3
1837 fe_dump( LOG_INFO, sc, "init() done" );
1838#endif
1839
1840 (void) splx(s);
1841}
1842
1843/*
1844 * This routine actually starts the transmission on the interface
1845 */
--- 27 unchanged lines hidden (view full) ---
1873 * (i.e. that the output part of the interface is idle)
1874 */
1875void
1876fe_start ( struct ifnet *ifp )
1877{
1878 struct fe_softc *sc = ifp->if_softc;
1879 struct mbuf *m;
1880
1881#if FE_DEBUG >= 1
1882 /* Just a sanity check. */
1883 if ( ( sc->txb_count == 0 ) != ( sc->txb_free == sc->txb_size ) ) {
1884 /*
1885 * Txb_count and txb_free co-works to manage the
1886 * transmission buffer. Txb_count keeps track of the
1887 * used potion of the buffer, while txb_free does unused
1888 * potion. So, as long as the driver runs properly,
1889 * txb_count is zero if and only if txb_free is same
1890 * as txb_size (which represents whole buffer.)
1891 */
1892 log( LOG_ERR, "fe%d: inconsistent txb variables (%d, %d)\n",
1893 sc->sc_unit, sc->txb_count, sc->txb_free );
1894 /*
1895 * So, what should I do, then?
1896 *
1897 * We now know txb_count and txb_free contradicts. We
1898 * cannot, however, tell which is wrong. More
1899 * over, we cannot peek 86960 transmission buffer or
1900 * reset the transmission buffer. (In fact, we can
1901 * reset the entire interface. I don't want to do it.)
1902 *
1903 * If txb_count is incorrect, leaving it as-is will cause
1904 * sending of garbage after next interrupt. We have to
1905 * avoid it. Hence, we reset the txb_count here. If
1906 * txb_free was incorrect, resetting txb_count just loose
1907 * some packets. We can live with it.
1908 */
1909 sc->txb_count = 0;
1910 }
1911#endif
1912
1913#if FE_DEBUG >= 1
1914 /*
1915 * First, see if there are buffered packets and an idle
1916 * transmitter - should never happen at this point.
1917 */
1918 if ( ( sc->txb_count > 0 ) && ( sc->txb_sched == 0 ) ) {
1919 log( LOG_ERR,
1920 "fe%d: transmitter idle with %d buffered packets\n",
1921 sc->sc_unit, sc->txb_count );
1922 fe_xmit( sc );
1923 }
1924#endif
1925
1926 /*
1927 * Stop accepting more transmission packets temporarily, when
1928 * a filter change request is delayed. Updating the MARs on
1929 * 86960 flushes the transmission buffer, so it is delayed
1930 * until all buffered transmission packets have been sent
1931 * out.
1932 */
--- 105 unchanged lines hidden (view full) ---
2038 /*
2039 * 86960 manual says that we have to read 8 bytes from the buffer
2040 * before skip the packets and that there must be more than 8 bytes
2041 * remaining in the buffer when issue a skip command.
2042 * Remember, we have already read 4 bytes before come here.
2043 */
2044 if ( len > 12 ) {
2045 /* Read 4 more bytes, and skip the rest of the packet. */
2046 ( void )inw( sc->ioaddr[ FE_BMPR8 ] );
2047 ( void )inw( sc->ioaddr[ FE_BMPR8 ] );
2048 outb( sc->ioaddr[ FE_BMPR14 ], FE_B14_SKIP );
2049 } else {
2050 /* We should not come here unless receiving RUNTs. */
2051 for ( i = 0; i < len; i += 2 ) {
2052 ( void )inw( sc->ioaddr[ FE_BMPR8 ] );
2053 }
2054 }
2055}
2056
2057/*
2058 * Empty receiving buffer.
2059 */
2060static void
2061fe_emptybuffer ( struct fe_softc * sc )
2062{
2063 int i;
2064 u_char saved_dlcr5;
2065
2066#if FE_DEBUG >= 2
2067 log( LOG_WARNING, "fe%d: emptying receive buffer\n", sc->sc_unit );
2068#endif
2069 /*
2070 * Stop receiving packets, temporarily.
2071 */
2072 saved_dlcr5 = inb( sc->ioaddr[ FE_DLCR5 ] );
2073 outb( sc->ioaddr[ FE_DLCR5 ], sc->proto_dlcr5 );
2074 DELAY(1300);
2075
2076 /*
2077 * When we come here, the receive buffer management should
2078 * have been broken. So, we cannot use skip operation.
2079 * Just discard everything in the buffer.
2080 */
2081 for (i = 0; i < 32768; i++) {
2082 if ( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) break;
2083 ( void )inw( sc->ioaddr[ FE_BMPR8 ] );
2084 }
2085
2086 /*
2087 * Double check.
2088 */
2089 if ( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) {
2090 log( LOG_ERR, "fe%d: could not empty receive buffer\n",
2091 sc->sc_unit );
2092 /* Hmm. What should I do if this happens? FIXME. */
2093 }
2094
2095 /*
2096 * Restart receiving packets.
2097 */
2098 outb( sc->ioaddr[ FE_DLCR5 ], saved_dlcr5 );
2099}
2100
2101/*
2102 * Transmission interrupt handler
2103 * The control flow of this function looks silly. FIXME.
2104 */
2105static void
2106fe_tint ( struct fe_softc * sc, u_char tstat )
2107{
--- 5 unchanged lines hidden (view full) ---
2113 */
2114 if ( tstat & FE_D0_COLL16 ) {
2115
2116 /*
2117 * Find how many packets (including this collided one)
2118 * are left unsent in transmission buffer.
2119 */
2120 left = inb( sc->ioaddr[ FE_BMPR10 ] );
2121
2122#if FE_DEBUG >= 2
2123 log( LOG_WARNING, "fe%d: excessive collision (%d/%d)\n",
2124 sc->sc_unit, left, sc->txb_sched );
2125#endif
2126#if FE_DEBUG >= 3
2127 fe_dump( LOG_INFO, sc, NULL );
2128#endif
2129
2130 /*
2131 * Clear the collision flag (in 86960) here
2132 * to avoid confusing statistics.
2133 */
2134 outb( sc->ioaddr[ FE_DLCR0 ], FE_D0_COLLID );
2135
2136 /*
2137 * Restart transmitter, skipping the
--- 56 unchanged lines hidden (view full) ---
2194 *
2195 * Since the accurate number of collisions
2196 * has been lost, we just guess it as 1;
2197 * Am I too optimistic? FIXME.
2198 */
2199 col = 1;
2200 }
2201 sc->sc_if.if_collisions += col;
2202#if FE_DEBUG >= 3
2203 log( LOG_WARNING, "fe%d: %d collision(s) (%d)\n",
2204 sc->sc_unit, col, sc->txb_sched );
2205#endif
2206 }
2207
2208 /*
2209 * Update transmission statistics.
2210 * Be sure to reflect number of excessive collisions.
2211 */
2212 sc->sc_if.if_opackets += sc->txb_sched - sc->tx_excolls;
2213 sc->sc_if.if_oerrors += sc->tx_excolls;
2214 sc->sc_if.if_collisions += sc->tx_excolls * 16;
2215 sc->txb_sched = 0;
2216
2217 /*
2218 * The transmitter is no more active.
2219 * Reset output active flag and watchdog timer.
2220 */
2221 sc->sc_if.if_flags &= ~IFF_OACTIVE;
2222 sc->sc_if.if_timer = 0;
--- 15 unchanged lines hidden (view full) ---
2238fe_rint ( struct fe_softc * sc, u_char rstat )
2239{
2240 u_short len;
2241 u_char status;
2242 int i;
2243
2244 /*
2245 * Update statistics if this interrupt is caused by an error.
2246 */
2247 if ( rstat & ( FE_D1_OVRFLO | FE_D1_CRCERR
2248 | FE_D1_ALGERR | FE_D1_SRTPKT ) ) {
2249#if FE_DEBUG >= 2
2250 log( LOG_WARNING,
2251 "fe%d: receive error: %s%s%s%s(%02x)\n",
2252 sc->sc_unit,
2253 rstat & FE_D1_OVRFLO ? "OVR " : "",
2254 rstat & FE_D1_CRCERR ? "CRC " : "",
2255 rstat & FE_D1_ALGERR ? "ALG " : "",
2256 rstat & FE_D1_SRTPKT ? "LEN " : "",
2257 rstat );
2258#endif
2259 sc->sc_if.if_ierrors++;
2260 }
2261
2262 /*
2263 * MB86960 has a flag indicating "receive queue empty."
2264 * We just loop, checking the flag, to pull out all received
2265 * packets.
2266 *
2267 * We limit the number of iterations to avoid infinite-loop.
2268 * The upper bound is set to unrealistic high value.
2269 */
2270 for (i = 0; i < FE_MAX_RECV_COUNT * 2; i++) {
2271
2272 /* Stop the iteration if 86960 indicates no packets. */
2273 if ( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) break;
2274
2275 /*
2276 * Extract A receive status byte.
2277 * As our 86960 is in 16 bit bus access mode, we have to
2278 * use inw() to get the status byte. The significant
2279 * value is returned in lower 8 bits.
2280 */
2281 status = ( u_char )inw( sc->ioaddr[ FE_BMPR8 ] );
2282#if FE_DEBUG >= 4
2283 log( LOG_INFO, "fe%d: receive status = %04x\n",
2284 sc->sc_unit, status );
2285#endif
2286
2287 /*
2288 * Extract the packet length.
2289 * It is a sum of a header (14 bytes) and a payload.
2290 * CRC has been stripped off by the 86960.
2291 */
2292 len = inw( sc->ioaddr[ FE_BMPR8 ] );
2293
2294#if FE_DEBUG >= 1
2295 /*
2296 * If there was an error with the received packet, it
2297 * must be an indication of out-of-sync on receive
2298 * buffer, because we have programmed the 8696x to
2299 * to discard errored packets, even when the interface
2300 * is in promiscuous mode. We have to re-synchronize.
2301 */
2302 if (!(status & FE_RPH_GOOD)) {
2303 log(LOG_ERR,
2304 "fe%d: corrupted receive status byte (%02x)\n",
2305 sc->arpcom.ac_if.if_unit, status);
2306 sc->arpcom.ac_if.if_ierrors++;
2307 fe_emptybuffer( sc );
2308 break;
2309 }
2310#endif
2311
2312#if FE_DEBUG >= 1
2313 /*
2314 * MB86960 checks the packet length and drop big packet
2315 * before passing it to us. There are no chance we can
2316 * get big packets through it, even if they are actually
2317 * sent over a line. Hence, if the length exceeds
2318 * the specified limit, it means some serious failure,
2319 * such as out-of-sync on receive buffer management.
2320 *
2321 * Same for short packets, since we have programmed
2322 * 86960 to drop short packets.
2323 */
2324 if ( len > ETHER_MAX_LEN - ETHER_CRC_LEN
2325 || len < ETHER_MIN_LEN - ETHER_CRC_LEN ) {
2326 log( LOG_WARNING,
2327 "fe%d: received a %s packet? (%u bytes)\n",
2328 sc->sc_unit,
2329 len < ETHER_MIN_LEN - ETHER_CRC_LEN
2330 ? "partial" : "big",
2331 len );
2332 sc->sc_if.if_ierrors++;
2333 fe_emptybuffer( sc );
2334 break;
2335 }
2336#endif
2337
2338 /*
2339 * Go get a packet.
2340 */
2341 if ( fe_get_packet( sc, len ) < 0 ) {
2342
2343#if FE_DEBUG >= 2
2344 log( LOG_WARNING, "%s%d: out of mbuf;"
2345 " dropping a packet (%u bytes)\n",
2346 sc->sc_unit, len );
2347#endif
2348
2349 /* Skip a packet, updating statistics. */
2350 sc->sc_if.if_ierrors++;
2351 fe_droppacket( sc, len );
2352
2353 /*
2354 * Try extracting other packets, although they will
2355 * cause out-of-mbuf error again. This is required
2356 * to keep receiver interrupt comming.
2357 * (Earlier versions had a bug on this point.)
2358 */
2359 continue;
2360 }
2361
2362 /* Successfully received a packet. Update stat. */
2363 sc->sc_if.if_ipackets++;
2364 }
2365}
2366
2367/*
2368 * Ethernet interface interrupt processor
2369 */
2370static void
2371feintr ( int unit )
2372{
2373 struct fe_softc *sc = &fe_softc[unit];
2374 u_char tstat, rstat;
2375
2376 /*
2377 * Loop until there are no more new interrupt conditions.
2378 */
2379 for (;;) {
2380
2381#if FE_DEBUG >= 4
2382 fe_dump( LOG_INFO, sc, "intr()" );
2383#endif
2384
2385 /*
2386 * Get interrupt conditions, masking unneeded flags.
2387 */
2388 tstat = inb( sc->ioaddr[ FE_DLCR0 ] ) & FE_TMASK;
2389 rstat = inb( sc->ioaddr[ FE_DLCR1 ] ) & FE_RMASK;
2390
2391#if FE_DEBUG >= 1
2392 /* Test for a "dead-lock" condition. */
2393 if ((rstat & FE_D1_PKTRDY) == 0
2394 && (inb(sc->ioaddr[FE_DLCR5]) & FE_D5_BUFEMP) == 0
2395 && (inb(sc->ioaddr[FE_DLCR1]) & FE_D1_PKTRDY) == 0) {
2396 /*
2397 * PKTRDY is off, while receive buffer is not empty.
2398 * We did a double check to avoid a race condition...
2399 * So, we should have missed an interrupt.
2400 */
2401 log(LOG_WARNING,
2402 "fe%d: missed a receiver interrupt?\n",
2403 sc->arpcom.ac_if.if_unit);
2404 /* Simulate the missed interrupt condition. */
2405 rstat |= FE_D1_PKTRDY;
2406 }
2407#endif
2408
2409 /* Stop processing if there are no interrupts to handle. */
2410 if ( tstat == 0 && rstat == 0 ) break;
2411
2412 /*
2413 * Reset the conditions we are acknowledging.
2414 */
2415 outb( sc->ioaddr[ FE_DLCR0 ], tstat );
2416 outb( sc->ioaddr[ FE_DLCR1 ], rstat );
2417
2418 /*
2419 * Handle transmitter interrupts. Handle these first because
2420 * the receiver will reset the board under some conditions.
2421 */
2422 if ( tstat ) {
2423 fe_tint( sc, tstat );
2424 }
2425
2426 /*
2427 * Handle receiver interrupts
2428 */
--- 28 unchanged lines hidden (view full) ---
2457 * receiver interrupts. 86960 can raise a receiver
2458 * interrupt when the transmission buffer is full.
2459 */
2460 if ( ( sc->sc_if.if_flags & IFF_OACTIVE ) == 0 ) {
2461 fe_start( &sc->sc_if );
2462 }
2463
2464 }
2465}
2466
2467/*
2468 * Process an ioctl request. This code needs some work - it looks
2469 * pretty ugly.
2470 */
2471static int
2472fe_ioctl ( struct ifnet * ifp, u_long command, caddr_t data )
2473{
2474 struct fe_softc *sc = ifp->if_softc;
2475 int s, error = 0;
2476
2477#if FE_DEBUG >= 3
2478 log( LOG_INFO, "fe%d: ioctl(%x)\n", sc->sc_unit, command );
2479#endif
2480
2481 s = splimp();
2482
2483 switch (command) {
2484
2485 case SIOCSIFADDR:
2486 {
2487 struct ifaddr * ifa = ( struct ifaddr * )data;
2488
2489 sc->sc_if.if_flags |= IFF_UP;
2490
2491 switch (ifa->ifa_addr->sa_family) {
2492#ifdef INET
2493 case AF_INET:
2494 fe_init( sc->sc_unit ); /* before arp_ifinit */
2495 arp_ifinit( &sc->arpcom, ifa );
2496 break;
2497#endif
2498#ifdef IPX
2499 /*
2500 * XXX - This code is probably wrong
2501 */
2502 case AF_IPX:
2503 {
2504 register struct ipx_addr *ina
2505 = &(IA_SIPX(ifa)->sipx_addr);
2506
2507 if (ipx_nullhost(*ina))
2508 ina->x_host =
2509 *(union ipx_host *) (sc->sc_enaddr); else {
2510 bcopy((caddr_t) ina->x_host.c_host,
2511 (caddr_t) sc->sc_enaddr,
2512 sizeof(sc->sc_enaddr));
2513 }
2514
2515 /*
2516 * Set new address
2517 */
2518 fe_init(sc->sc_unit);
2519 break;
2520 }
2521#endif
2522#ifdef INET6
2523 case AF_INET6:
2524 /* IPV6 added by shin 96.2.6 */
2525 fe_init(sc->sc_unit);
2526 ndp6_ifinit(&sc->arpcom, ifa);
2527 break;
2528#endif
2529#ifdef NS
2530
2531 /*
2532 * XXX - This code is probably wrong
2533 */
2534 case AF_NS:
2535 {
2536 register struct ns_addr *ina
2537 = &(IA_SNS(ifa)->sns_addr);
2538
2539 if (ns_nullhost(*ina))
2540 ina->x_host =
2541 *(union ns_host *) (sc->sc_enaddr);
2542 else {
2543 bcopy((caddr_t) ina->x_host.c_host,
2544 (caddr_t) sc->sc_enaddr,
2545 sizeof(sc->sc_enaddr));
2546 }
2547
2548 /*
2549 * Set new address
2550 */
2551 fe_init(sc->sc_unit);
2552 break;
2553 }
2554#endif
2555 default:
2556 fe_init( sc->sc_unit );
2557 break;
2558 }
2559 break;
2560 }
2561
2562#ifdef SIOCGIFADDR
2563 case SIOCGIFADDR:
2564 {
2565 struct ifreq * ifr = ( struct ifreq * )data;
2566 struct sockaddr * sa = ( struct sockaddr * )&ifr->ifr_data;
2567
2568 bcopy((caddr_t)sc->sc_enaddr,
2569 (caddr_t)sa->sa_data, ETHER_ADDR_LEN);
2570 break;
2571 }
2572#endif
2573
2574#ifdef SIOCGIFPHYSADDR
2575 case SIOCGIFPHYSADDR:
2576 {
2577 struct ifreq * ifr = ( struct ifreq * )data;
2578
2579 bcopy((caddr_t)sc->sc_enaddr,
2580 (caddr_t)&ifr->ifr_data, ETHER_ADDR_LEN);
2581 break;
2582 }
2583#endif
2584
2585#ifdef notdef
2586#ifdef SIOCSIFPHYSADDR
2587 case SIOCSIFPHYSADDR:
2588 {
2589 /*
2590 * Set the physical (Ethernet) address of the interface.
2591 * When and by whom is this command used? FIXME.
2592 */
2593 struct ifreq * ifr = ( struct ifreq * )data;
2594
2595 bcopy((caddr_t)&ifr->ifr_data,
2596 (caddr_t)sc->sc_enaddr, ETHER_ADDR_LEN);
2597 fe_setlinkaddr( sc );
2598 break;
2599 }
2600#endif
2601#endif /* notdef */
2602
2603#ifdef SIOCSIFFLAGS
2604 case SIOCSIFFLAGS:
2605 {
2606 /*
2607 * Switch interface state between "running" and
2608 * "stopped", reflecting the UP flag.
2609 */
2610 if ( sc->sc_if.if_flags & IFF_UP ) {
2611 if ( ( sc->sc_if.if_flags & IFF_RUNNING ) == 0 ) {
2612 fe_init( sc->sc_unit );
2613 }
2614 } else {
2615 if ( ( sc->sc_if.if_flags & IFF_RUNNING ) != 0 ) {
2616 fe_stop( sc->sc_unit );
2617 }
2618 }
2619
2620 /*
2621 * Promiscuous and/or multicast flags may have changed,
2622 * so reprogram the multicast filter and/or receive mode.
2623 */
2624 fe_setmode( sc );
2625
2626#if FE_DEBUG >= 1
2627 /* "ifconfig fe0 debug" to print register dump. */
2628 if ( sc->sc_if.if_flags & IFF_DEBUG ) {
2629 fe_dump( LOG_DEBUG, sc, "SIOCSIFFLAGS(DEBUG)" );
2630 }
2631#endif
2632 break;
2633 }
2634#endif
2635
2636#ifdef SIOCADDMULTI
2637 case SIOCADDMULTI:
2638 case SIOCDELMULTI:
2639 /*
2640 * Multicast list has changed; set the hardware filter
2641 * accordingly.
2642 */
2643 fe_setmode( sc );
2644 error = 0;
2645 break;
2646#endif
2647
2648#ifdef SIOCSIFMTU
2649 case SIOCSIFMTU:
2650 {
2651 /*
2652 * Set the interface MTU.
2653 */
2654 struct ifreq * ifr = ( struct ifreq * )data;
2655
2656 if ( ifr->ifr_mtu > ETHERMTU ) {
2657 error = EINVAL;
2658 } else {
2659 sc->sc_if.if_mtu = ifr->ifr_mtu;
2660 }
2661 break;
2662 }
2663#endif
2664
2665 default:
2666 error = EINVAL;
2667 }
2668
2669 (void) splx(s);
2670 return (error);
2671}
2672
2673/*
2674 * Retrieve packet from receive buffer and send to the next level up via
--- 55 unchanged lines hidden (view full) ---
2730 m->m_pkthdr.len = len;
2731
2732 /* Set the length of this packet. */
2733 m->m_len = len;
2734
2735 /* The following silliness is to make NFS happy */
2736 m->m_data += NFS_MAGIC_OFFSET;
2737
2738 /* Get a packet. */
2739 insw( sc->ioaddr[ FE_BMPR8 ], m->m_data, ( len + 1 ) >> 1 );
2740
2741 /* Get (actually just point to) the header part. */
2742 eh = mtod( m, struct ether_header *);
2743
2744#define ETHER_ADDR_IS_MULTICAST(A) (*(char *)(A) & 1)
2745
2746#if NBPFILTER > 0
2747 /*
2748 * Check if there's a BPF listener on this interface.
2749 * If it is, hand off the raw packet to bpf.
2750 */
2751 if ( sc->sc_if.if_bpf ) {
2752 bpf_mtap( &sc->sc_if, m );
2753 }
2754#endif
2755
2756 /*
2757 * Make sure this packet is (or may be) directed to us.
2758 * That is, the packet is either unicasted to our address,
2759 * or broad/multi-casted. If any other packets are
2760 * received, it is an indication of an error -- probably
2761 * 86960 is in a wrong operation mode.
2762 * Promiscuous mode is an exception. Under the mode, all
2763 * packets on the media must be received. (We must have
--- 6 unchanged lines hidden (view full) ---
2770 /*
2771 * The packet was not for us. This is normal since
2772 * we are now in promiscuous mode. Just drop the packet.
2773 */
2774 m_freem( m );
2775 return 0;
2776 }
2777
2778#if FE_DEBUG >= 3
2779 if ( !ETHER_ADDR_IS_MULTICAST( eh->ether_dhost )
2780 && bcmp( eh->ether_dhost, sc->sc_enaddr, ETHER_ADDR_LEN ) != 0 ) {
2781 /*
2782 * This packet was not for us. We can't be in promiscuous
2783 * mode since the case was handled by above test.
2784 * We found an error (of this driver.)
2785 */
2786 log( LOG_WARNING,
2787 "fe%d: got an unwanted packet, dst = %6D\n",
2788 sc->sc_unit, eh->ether_dhost , ":" );
2789 m_freem( m );
2790 return 0;
2791 }
2792#endif
2793
2794 /* Strip off the Ethernet header. */
2795 m->m_pkthdr.len -= sizeof ( struct ether_header );
2796 m->m_len -= sizeof ( struct ether_header );
2797 m->m_data += sizeof ( struct ether_header );
2798
2799 /* Feed the packet to upper layer. */
2800 ether_input( &sc->sc_if, eh, m );
2801 return 0;
--- 15 unchanged lines hidden (view full) ---
2817 u_short length, len;
2818 struct mbuf *mp;
2819 u_char *data;
2820 u_short savebyte; /* WARNING: Architecture dependent! */
2821#define NO_PENDING_BYTE 0xFFFF
2822
2823 static u_char padding [ ETHER_MIN_LEN - ETHER_CRC_LEN - ETHER_HDR_LEN ];
2824
2825#if FE_DEBUG >= 1
2826 /* First, count up the total number of bytes to copy */
2827 length = 0;
2828 for ( mp = m; mp != NULL; mp = mp->m_next ) {
2829 length += mp->m_len;
2830 }
2831#else
2832 /* Just use the length value in the packet header. */
2833 length = m->m_pkthdr.len;
2834#endif
2835
2836#if FE_DEBUG >= 2
2837 /* Check if this matches the one in the packet header. */
2838 if ( length != m->m_pkthdr.len ) {
2839 log( LOG_WARNING, "fe%d: packet length mismatch? (%d/%d)\n",
2840 sc->sc_unit, length, m->m_pkthdr.len );
2841 }
2842#endif
2843
2844#if FE_DEBUG >= 1
2845 /*
2846 * Should never send big packets. If such a packet is passed,
2847 * it should be a bug of upper layer. We just ignore it.
2848 * ... Partial (too short) packets, neither.
2849 */
2850 if ( length < ETHER_HDR_LEN
2851 || length > ETHER_MAX_LEN - ETHER_CRC_LEN ) {
2852 log( LOG_ERR,
2853 "fe%d: got an out-of-spec packet (%u bytes) to send\n",
2854 sc->sc_unit, length );
2855 sc->sc_if.if_oerrors++;
2856 return;
2857 }
2858#endif
2859
2860 /*
2861 * Put the length word for this frame.
2862 * Does 86960 accept odd length? -- Yes.
2863 * Do we need to pad the length to minimum size by ourselves?
2864 * -- Generally yes. But for (or will be) the last
2865 * packet in the transmission buffer, we can skip the
2866 * padding process. It may gain performance slightly. FIXME.
2867 */
2868 outw( addr_bmpr8, max( length, ETHER_MIN_LEN - ETHER_CRC_LEN ) );
2869
2870 /*
2871 * Update buffer status now.
2872 * Truncate the length up to an even number, since we use outw().
2873 */
2874 length = ( length + 1 ) & ~1;
2875 sc->txb_free -= FE_DATA_LEN_LEN + max( length, ETHER_MIN_LEN - ETHER_CRC_LEN);
2876 sc->txb_count++;
2877
2878 /*
2879 * Transfer the data from mbuf chain to the transmission buffer.
2880 * MB86960 seems to require that data be transferred as words, and
2881 * only words. So that we require some extra code to patch
2882 * over odd-length mbufs.
2883 */
2884 savebyte = NO_PENDING_BYTE;
2885 for ( mp = m; mp != 0; mp = mp->m_next ) {
2886
2887 /* Ignore empty mbuf. */
2888 len = mp->m_len;
2889 if ( len == 0 ) continue;
2890
2891 /* Find the actual data to send. */
2892 data = mtod(mp, caddr_t);
2893
2894 /* Finish the last byte. */
2895 if ( savebyte != NO_PENDING_BYTE ) {
2896 outw( addr_bmpr8, savebyte | ( *data << 8 ) );
2897 data++;
2898 len--;
2899 savebyte = NO_PENDING_BYTE;
2900 }
2901
2902 /* output contiguous words */
2903 if (len > 1) {
2904 outsw( addr_bmpr8, data, len >> 1);
2905 data += len & ~1;
2906 len &= 1;
2907 }
2908
2909 /* Save a remaining byte, if there is one. */
2910 if ( len > 0 ) {
2911 savebyte = *data;
2912 }
2913 }
2914
2915 /* Spit the last byte, if the length is odd. */
2916 if ( savebyte != NO_PENDING_BYTE ) {
2917 outw( addr_bmpr8, savebyte );
2918 }
2919
2920 /* Pad to the Ethernet minimum length, if the packet is too short. */
2921 if ( length < ETHER_MIN_LEN - ETHER_CRC_LEN ) {
2922 outsw( addr_bmpr8, padding, ( ETHER_MIN_LEN - ETHER_CRC_LEN - length ) >> 1);
2923 }
2924}
2925
2926/*
2927 * Compute hash value for an Ethernet address
2928 */
2929static int
2930fe_hash ( u_char * ep )
--- 29 unchanged lines hidden (view full) ---
2960 struct ifmultiaddr *ifma;
2961
2962 filter = fe_filter_nothing;
2963 for (ifma = sc->arpcom.ac_if.if_multiaddrs.lh_first; ifma;
2964 ifma = ifma->ifma_link.le_next) {
2965 if (ifma->ifma_addr->sa_family != AF_LINK)
2966 continue;
2967 index = fe_hash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
2968#if FE_DEBUG >= 4
2969 log( LOG_INFO, "fe%d: hash(%6D) == %d\n",
2970 sc->sc_unit, enm->enm_addrlo , ":", index );
2971#endif
2972
2973 filter.data[index >> 3] |= 1 << (index & 7);
2974 }
2975 return ( filter );
2976}
2977
2978/*
--- 30 unchanged lines hidden (view full) ---
3009 * Promiscuous mode in FreeBSD 2 is used solely by
3010 * BPF, and BPF only listens to valid (no error) packets.
3011 * So, we ignore erroneous ones even in this mode.
3012 * (Older versions of fe driver mistook the point.)
3013 */
3014 outb( sc->ioaddr[ FE_DLCR5 ],
3015 sc->proto_dlcr5 | FE_D5_AFM0 | FE_D5_AFM1 );
3016 sc->filter_change = 0;
3017
3018#if FE_DEBUG >= 3
3019 log( LOG_INFO, "fe%d: promiscuous mode\n", sc->sc_unit );
3020#endif
3021 return;
3022 }
3023
3024 /*
3025 * Turn the chip to the normal (non-promiscuous) mode.
3026 */
3027 outb( sc->ioaddr[ FE_DLCR5 ], sc->proto_dlcr5 | FE_D5_AFM1 );
3028
3029 /*
3030 * Find the new multicast filter value.
3031 * I'm not sure we have to handle modes other than MULTICAST.
3032 * Who sets ALLMULTI? Who turns MULTICAST off? FIXME.
3033 */
3034 if ( flags & IFF_ALLMULTI ) {
3035 sc->filter = fe_filter_all;
3036 } else if ( flags & IFF_MULTICAST ) {
3037 sc->filter = fe_mcaf( sc );
3038 } else {
3039 sc->filter = fe_filter_nothing;
3040 }
3041 sc->filter_change = 1;
3042
3043#if FE_DEBUG >= 3
3044 log( LOG_INFO, "fe%d: address filter: [%8D]\n",
3045 sc->sc_unit, sc->filter.data, " " );
3046#endif
3047
3048 /*
3049 * We have to update the multicast filter in the 86960, A.S.A.P.
3050 *
3051 * Note that the DLC (Data Link Control unit, i.e. transmitter
3052 * and receiver) must be stopped when feeding the filter, and
3053 * DLC trashes all packets in both transmission and receive
3054 * buffers when stopped.
3055 *
3056 * ... Are the above sentences correct? I have to check the
3057 * manual of the MB86960A. FIXME.
3058 *
3059 * To reduce the packet loss, we delay the filter update
3060 * process until buffers are empty.
3061 */
3062 if ( sc->txb_sched == 0 && sc->txb_count == 0
3063 && !( inb( sc->ioaddr[ FE_DLCR1 ] ) & FE_D1_PKTRDY ) ) {
3064 /*
3065 * Buffers are (apparently) empty. Load
3066 * the new filter value into MARs now.
3067 */
3068 fe_loadmar(sc);
3069 } else {
3070 /*
3071 * Buffers are not empty. Mark that we have to update
3072 * the MARs. The new filter will be loaded by feintr()
3073 * later.
3074 */
3075#if FE_DEBUG >= 4
3076 log( LOG_INFO, "fe%d: filter change delayed\n", sc->sc_unit );
3077#endif
3078 }
3079}
3080
3081/*
3082 * Load a new multicast address filter into MARs.
3083 *
3084 * The caller must have splimp'ed before fe_loadmar.
3085 * This function starts the DLC upon return. So it can be called only
--- 21 unchanged lines hidden (view full) ---
3107
3108 /* Restart the DLC. */
3109 DELAY( 200 );
3110 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_ENABLE );
3111 DELAY( 200 );
3112
3113 /* We have just updated the filter. */
3114 sc->filter_change = 0;
3115
3116#if FE_DEBUG >= 3
3117 log( LOG_INFO, "fe%d: address filter changed\n", sc->sc_unit );
3118#endif
3119}
3120
3121#if FE_DEBUG >= 1
3122static void
3123fe_dump ( int level, struct fe_softc * sc, char * message )
3124{
3125 log( level, "fe%d: %s,"
3126 " DLCR = %02x %02x %02x %02x %02x %02x %02x %02x,"
3127 " BMPR = xx xx %02x %02x %02x %02x %02x %02x,"
3128 " asic = %02x %02x %02x %02x %02x %02x %02x %02x"
3129 " + %02x %02x %02x %02x %02x %02x %02x %02x\n",
3130 sc->sc_unit, message ? message : "registers",
3131 inb( sc->ioaddr[ FE_DLCR0 ] ), inb( sc->ioaddr[ FE_DLCR1 ] ),
3132 inb( sc->ioaddr[ FE_DLCR2 ] ), inb( sc->ioaddr[ FE_DLCR3 ] ),
3133 inb( sc->ioaddr[ FE_DLCR4 ] ), inb( sc->ioaddr[ FE_DLCR5 ] ),
3134 inb( sc->ioaddr[ FE_DLCR6 ] ), inb( sc->ioaddr[ FE_DLCR7 ] ),
3135 inb( sc->ioaddr[ FE_BMPR10 ] ), inb( sc->ioaddr[ FE_BMPR11 ] ),
3136 inb( sc->ioaddr[ FE_BMPR12 ] ), inb( sc->ioaddr[ FE_BMPR13 ] ),
3137 inb( sc->ioaddr[ FE_BMPR14 ] ), inb( sc->ioaddr[ FE_BMPR15 ] ),
3138 inb( sc->ioaddr[ 0x10 ] ), inb( sc->ioaddr[ 0x11 ] ),
3139 inb( sc->ioaddr[ 0x12 ] ), inb( sc->ioaddr[ 0x13 ] ),
3140 inb( sc->ioaddr[ 0x14 ] ), inb( sc->ioaddr[ 0x15 ] ),
3141 inb( sc->ioaddr[ 0x16 ] ), inb( sc->ioaddr[ 0x17 ] ),
3142 inb( sc->ioaddr[ 0x18 ] ), inb( sc->ioaddr[ 0x19 ] ),
3143 inb( sc->ioaddr[ 0x1A ] ), inb( sc->ioaddr[ 0x1B ] ),
3144 inb( sc->ioaddr[ 0x1C ] ), inb( sc->ioaddr[ 0x1D ] ),
3145 inb( sc->ioaddr[ 0x1E ] ), inb( sc->ioaddr[ 0x1F ] ) );
3146}
3147#endif
2 * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
3 *
4 * This software may be used, modified, copied, distributed, and sold, in
5 * both source and binary form provided that the above copyright, these
6 * terms and the following disclaimer are retained. The name of the author
7 * and/or the contributor may not be used to endorse or promote products
8 * derived from this software without specific prior written permission.
--- 7 unchanged lines hidden (view full) ---
16 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION.
17 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
19 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
20 * SUCH DAMAGE.
21 */
22
23/*
24 * $Id: if_fe.c,v 1.43 1998/10/22 05:58:39 bde Exp $
25 *
26 * Device driver for Fujitsu MB86960A/MB86965A based Ethernet cards.
27 * To be used with FreeBSD 2.x
28 * Contributed by M. Sekiguchi. <seki@sysrap.cs.fujitsu.co.jp>
29 *
30 * This version is intended to be a generic template for various
31 * MB86960A/MB86965A based Ethernet cards. It currently supports
32 * Fujitsu FMV-180 series for ISA and Allied-Telesis AT1700/RE2000
33 * series for ISA, as well as Fujitsu MBH10302 PC card.
34 * There are some currently-
35 * unused hooks embedded, which are primarily intended to support
36 * other types of Ethernet cards, but the author is not sure whether
37 * they are useful.
38 *
39 * This version also includes some alignments for
40 * RE1000/RE1000+/ME1500 support. It is incomplete, however, since the
41 * cards are not for AT-compatibles. (They are for PC98 bus -- a
42 * proprietary bus architecture available only in Japan.) Further
43 * work for PC98 version will be available as a part of FreeBSD(98)
44 * project.
45 *
46 * This software is a derivative work of if_ed.c version 1.56 by David
47 * Greenman available as a part of FreeBSD 2.0 RELEASE source distribution.
48 *
49 * The following lines are retained from the original if_ed.c:
50 *
51 * Copyright (C) 1993, David Greenman. This software may be used, modified,
52 * copied, distributed, and sold, in both source and binary form provided
53 * that the above copyright and these terms are retained. Under no
54 * circumstances is the author responsible for the proper functioning
55 * of this software, nor does the author assume any responsibility
56 * for damages incurred with its use.
57 */
58
59/*
60 * TODO:
61 * o To support MBH10304 PC card. It is another MB8696x based
62 * PCMCIA Ethernet card by Fujitsu, which is not compatible with
63 * MBH10302.
64 * o To merge FreeBSD(98) efforts into a single source file.
65 * o To support ISA PnP auto configuration for FMV-183/184.
66 * o To reconsider mbuf usage.
67 * o To reconsider transmission buffer usage, including
68 * transmission buffer size (currently 4KB x 2) and pros-and-
69 * cons of multiple frame transmission.
70 * o To test IPX codes.
71 */
72
73#include "fe.h"
74#include "bpfilter.h"
75#include "opt_inet.h"
76#include "opt_ipx.h"
77
78#include <sys/param.h>
79#include <sys/systm.h>
80#include <sys/sockio.h>
81#include <sys/mbuf.h>
82#include <sys/socket.h>
83#include <sys/syslog.h>
84
85#include <net/if.h>
86#include <net/if_dl.h>
87
88#ifdef INET
89#include <netinet/in.h>
90#include <netinet/if_ether.h>
91#endif
92
93/* IPX code is not tested. FIXME. */
94#ifdef IPX
--- 12 unchanged lines hidden (view full) ---
107#include <netns/ns.h>
108#include <netns/ns_if.h>
109#endif
110
111#if NBPFILTER > 0
112#include <net/bpf.h>
113#endif
114
115#include <machine/clock.h>
116
117#include <i386/isa/isa_device.h>
118#include <i386/isa/icu.h>
119
120/* PCCARD suport */
121#include "card.h"
122#if NCARD > 0
123#include <sys/kernel.h>
124#include <sys/select.h>
125#include <pccard/cardinfo.h>
126#include <pccard/slot.h>
127#endif
128
129#include <i386/isa/ic/mb86960.h>
130#include <i386/isa/if_fereg.h>
131
132/*
133 * This version of fe is an ISA device driver.
134 * Override the following macro to adapt it to another bus.
135 * (E.g., PC98.)
136 */
137#define DEVICE struct isa_device
138
139/*
140 * Default settings for fe driver specific options.
141 * They can be set in config file by "options" statements.
142 */
143
144/*
145 * Debug control.
146 * 0: No debug at all. All debug specific codes are stripped off.
147 * 1: Silent. No debug messages are logged except emergent ones.
148 * 2: Brief. Lair events and/or important information are logged.
149 * 3: Detailed. Logs all information which *may* be useful for debugging.
150 * 4: Trace. All actions in the driver is logged. Super verbose.
151 */
152#ifndef FE_DEBUG
153#define FE_DEBUG 1
154#endif
155
156/*
157 * Transmit just one packet per a "send" command to 86960.
158 * This option is intended for performance test. An EXPERIMENTAL option.
159 */
160#ifndef FE_SINGLE_TRANSMISSION
161#define FE_SINGLE_TRANSMISSION 0
162#endif
163
164/*
165 * Device configuration flags.
166 */
167
168/* DLCR6 settings. */
169#define FE_FLAGS_DLCR6_VALUE 0x007F
170
171/* Force DLCR6 override. */
172#define FE_FLAGS_OVERRIDE_DLCR6 0x0080
--- 22 unchanged lines hidden (view full) ---
195static struct fe_softc {
196
197 /* Used by "common" codes. */
198 struct arpcom arpcom; /* Ethernet common */
199
200 /* Used by config codes. */
201
202 /* Set by probe() and not modified in later phases. */
203 char * typestr; /* printable name of the interface. */
204 u_short iobase; /* base I/O address of the adapter. */
205 u_short ioaddr [ MAXREGISTERS ]; /* I/O addresses of register. */
206 u_short txb_size; /* size of TX buffer, in bytes */
207 u_char proto_dlcr4; /* DLCR4 prototype. */
208 u_char proto_dlcr5; /* DLCR5 prototype. */
209 u_char proto_dlcr6; /* DLCR6 prototype. */
210 u_char proto_dlcr7; /* DLCR7 prototype. */
211 u_char proto_bmpr13; /* BMPR13 prototype. */
212
213 /* Vendor specific hooks. */
214 void ( * init )( struct fe_softc * ); /* Just before fe_init(). */
215 void ( * stop )( struct fe_softc * ); /* Just after fe_stop(). */
216
217 /* Transmission buffer management. */
218 u_short txb_free; /* free bytes in TX buffer */
219 u_char txb_count; /* number of packets in TX buffer */
220 u_char txb_sched; /* number of scheduled packets */
221
222 /* Excessive collision counter (see fe_tint() for details. */
223 u_char tx_excolls; /* # of excessive collisions. */
224
225 /* Multicast address filter management. */
226 u_char filter_change; /* MARs must be changed ASAP. */
227 struct fe_filter filter;/* new filter value. */
228
229} fe_softc[NFE];
230
231#define sc_if arpcom.ac_if
232#define sc_unit arpcom.ac_if.if_unit
233#define sc_enaddr arpcom.ac_enaddr
234
235/* Standard driver entry points. These can be static. */
236static int fe_probe ( struct isa_device * );
237static int fe_attach ( struct isa_device * );
238static void fe_init ( int );
239static ointhand2_t feintr;
240static int fe_ioctl ( struct ifnet *, u_long, caddr_t );
241static void fe_start ( struct ifnet * );
242static void fe_reset ( int );
243static void fe_watchdog ( struct ifnet * );
244
245/* Local functions. Order of declaration is confused. FIXME. */
246static int fe_probe_fmv ( DEVICE *, struct fe_softc * );
247static int fe_probe_ati ( DEVICE *, struct fe_softc * );
248static void fe_init_ati ( struct fe_softc * );
249static int fe_probe_gwy ( DEVICE *, struct fe_softc * );
250#if NCARD > 0
251static int fe_probe_mbh ( DEVICE *, struct fe_softc * );
252static void fe_init_mbh ( struct fe_softc * );
253static int fe_probe_tdk ( DEVICE *, struct fe_softc * );
254#endif
255static int fe_get_packet ( struct fe_softc *, u_short );
256static void fe_stop ( int );
257static void fe_tint ( struct fe_softc *, u_char );
258static void fe_rint ( struct fe_softc *, u_char );
259static void fe_xmit ( struct fe_softc * );
260static void fe_emptybuffer ( struct fe_softc * );
261static void fe_write_mbufs ( struct fe_softc *, struct mbuf * );
262static struct fe_filter
263 fe_mcaf ( struct fe_softc * );
264static int fe_hash ( u_char * );
265static void fe_setmode ( struct fe_softc * );
266static void fe_loadmar ( struct fe_softc * );
267#if FE_DEBUG >= 1
268static void fe_dump ( int, struct fe_softc *, char * );
269#endif
270
271/* Driver struct used in the config code. This must be public (external.) */
272struct isa_driver fedriver =
273{
274 fe_probe,
275 fe_attach,
276 "fe",
--- 16 unchanged lines hidden (view full) ---
293 * minimum size of transmission buffer in fe is 2x2KB,
294 * and minimum amount of received packet including headers
295 * added by the chip is 64 bytes.
296 * Hence FE_MAX_RECV_COUNT is the upper limit for number
297 * of packets in the receive buffer.
298 */
299
300/*
301 * Routines to access contiguous I/O ports.
302 */
303
304static void
305inblk ( struct fe_softc * sc, int offs, u_char * mem, int len )
306{
307 while ( --len >= 0 ) {
308 *mem++ = inb( sc->ioaddr[ offs++ ] );
--- 8 unchanged lines hidden (view full) ---
317 }
318}
319
320/* PCCARD Support */
321#if NCARD > 0
322/*
323 * PC-Card (PCMCIA) specific code.
324 */
325static int feinit ( struct pccard_devinfo * );
326static void feunload ( struct pccard_devinfo * );
327static int fe_card_intr ( struct pccard_devinfo * );
328
329static struct pccard_device fe_info = {
330 "fe",
331 feinit,
332 feunload,
333 fe_card_intr,
334 0, /* Attributes - presently unused */
335 &net_imask /* XXX - Should this also include tty_imask? */
336};
337
338DATA_SET(pccarddrv_set, fe_info);
339
340/*
341 * Initialize the device - called from Slot manager.
342 */
343static int
344feinit(struct pccard_devinfo *devi)
345{
346 struct fe_softc *sc;
347
348 /* validate unit number. */
349 if (devi->isahd.id_unit >= NFE)
350 return (ENODEV);
351 /*
352 * Probe the device. If a value is returned,
353 * the device was found at the location.
354 */
355#if FE_DEBUG >= 2
356 printf("Start Probe\n");
357#endif
358 /* Initialize "minimum" parts of our softc. */
359 sc = &fe_softc[devi->isahd.id_unit];
360 sc->sc_unit = devi->isahd.id_unit;
361 sc->iobase = devi->isahd.id_iobase;
362
363 /* Use Ethernet address got from CIS, if one is available. */
364 if ((devi->misc[0] & 0x03) == 0x00
365 && (devi->misc[0] | devi->misc[1] | devi->misc[2]) != 0) {
366 /* Yes, it looks like a valid Ether address. */
367 bcopy(devi->misc, sc->sc_enaddr, ETHER_ADDR_LEN);
368 } else {
369 /* Indicate we have no Ether address in CIS. */
370 bzero(sc->sc_enaddr, ETHER_ADDR_LEN);
371 }
372
373 /* Probe supported PC card models. */
374 if (fe_probe_tdk(&devi->isahd, sc) == 0 &&
375 fe_probe_mbh(&devi->isahd, sc) == 0)
376 return (ENXIO);
377#if FE_DEBUG >= 2
378 printf("Start attach\n");
379#endif
380 if (fe_attach(&devi->isahd) == 0)
381 return (ENXIO);
382
383 return (0);
384}
385
386/*
387 * feunload - unload the driver and clear the table.
388 * XXX TODO:
389 * This is usually called when the card is ejected, but
390 * can be caused by a modunload of a controller driver.
391 * The idea is to reset the driver's view of the device
392 * and ensure that any driver entry points such as
393 * read and write do not hang.
394 */
395static void
396feunload(struct pccard_devinfo *devi)
397{
398 printf("fe%d: unload\n", devi->isahd.id_unit);
399 fe_stop(devi->isahd.id_unit);
400}
401
402/*
403 * fe_card_intr - Shared interrupt called from
404 * front end of PC-Card handler.
405 */
406static int
407fe_card_intr(struct pccard_devinfo *devi)
408{
409 feintr(devi->isahd.id_unit);
410 return (1);
411}
412#endif /* NCARD > 0 */
413
414
415/*
416 * Hardware probe routines.
417 */
418
419/* How and where to probe; to support automatic I/O address detection. */
420struct fe_probe_list
421{
422 int ( * probe ) ( DEVICE *, struct fe_softc * );
423 u_short const * addresses;
424};
425
426/* Lists of possible addresses. */
427static u_short const fe_fmv_addr [] =
428 { 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x300, 0x340, 0 };
429static u_short const fe_ati_addr [] =
430 { 0x240, 0x260, 0x280, 0x2A0, 0x300, 0x320, 0x340, 0x380, 0 };
431
432static struct fe_probe_list const fe_probe_list [] =
433{
434 { fe_probe_fmv, fe_fmv_addr },
435 { fe_probe_ati, fe_ati_addr },
436 { fe_probe_gwy, NULL }, /* GWYs cannot be auto detected. */
437 { NULL, NULL }
438};
439
440
441/*
442 * Determine if the device is present
443 *
444 * on entry:
445 * a pointer to an isa_device struct
446 * on exit:
447 * zero if device not found
448 * or number of i/o addresses used (if found)
449 */
450
451static int
452fe_probe ( DEVICE * dev )
453{
454 struct fe_softc * sc;
455 int u;
456 int nports;
457 struct fe_probe_list const * list;
458 u_short const * addr;
459 u_short single [ 2 ];
460
461 /* Initialize "minimum" parts of our softc. */
462 sc = &fe_softc[ dev->id_unit ];
463 sc->sc_unit = dev->id_unit;
464
465 /* Probe each possibility, one at a time. */
466 for ( list = fe_probe_list; list->probe != NULL; list++ ) {
467
468 if ( dev->id_iobase != NO_IOADDR ) {
469 /* Probe one specific address. */
470 single[ 0 ] = dev->id_iobase;
471 single[ 1 ] = 0;
472 addr = single;
473 } else if ( list->addresses != NULL ) {
474 /* Auto detect. */
475 addr = list->addresses;
476 } else {
477 /* We need a list of addresses to do auto detect. */
478 continue;
479 }
480
481 /* Probe all possible addresses for the board. */
482 while ( *addr != 0 ) {
483
484 /* See if the address is already in use. */
485 for ( u = 0; u < NFE; u++ ) {
486 if ( fe_softc[u].iobase == *addr ) break;
487 }
488
489#if FE_DEBUG >= 3
490 if ( u == NFE ) {
491 log( LOG_INFO, "fe%d: probing %d at 0x%x\n",
492 sc->sc_unit, list - fe_probe_list, *addr );
493 } else if ( u == sc->sc_unit ) {
494 log( LOG_INFO, "fe%d: re-probing %d at 0x%x?\n",
495 sc->sc_unit, list - fe_probe_list, *addr );
496 } else {
497 log( LOG_INFO, "fe%d: skipping %d at 0x%x\n",
498 sc->sc_unit, list - fe_probe_list, *addr );
499 }
500#endif
501
502 /* Probe the address if it is free. */
503 if ( u == NFE || u == sc->sc_unit ) {
504
505 /* Probe an address. */
506 sc->iobase = *addr;
507 nports = list->probe( dev, sc );
508 if ( nports > 0 ) {
509 /* Found. */
510 dev->id_iobase = *addr;
511 return ( nports );
512 }
513 sc->iobase = 0;
514 }
515
516 /* Try next. */
517 addr++;
518 }
519 }
520
521 /* Probe failed. */
522 return ( 0 );
523}
524
525/*
526 * Check for specific bits in specific registers have specific values.
527 */
528struct fe_simple_probe_struct
529{
530 u_char port; /* Offset from the base I/O address. */
531 u_char mask; /* Bits to be checked. */
532 u_char bits; /* Values to be compared against. */
533};
534
535static int
536fe_simple_probe ( struct fe_softc const * sc,
537 struct fe_simple_probe_struct const * sp )
538{
539 struct fe_simple_probe_struct const * p;
540
541 for ( p = sp; p->mask != 0; p++ ) {
542#if FE_DEBUG >=2
543 printf("Probe Port:%x,Value:%x,Mask:%x.Bits:%x\n",
544 p->port,inb(sc->ioaddr[ p->port]),p->mask,p->bits);
545#endif
546 if ( ( inb( sc->ioaddr[ p->port ] ) & p->mask ) != p->bits )
547 {
548 return ( 0 );
549 }
550 }
551 return ( 1 );
552}
553
554/*
555 * Routines to read all bytes from the config EEPROM through MB86965A.
556 * I'm not sure what exactly I'm doing here... I was told just to follow
557 * the steps, and it worked. Could someone tell me why the following
558 * code works? (Or, why all similar codes I tried previously doesn't
559 * work.) FIXME.
560 */
561
562static void
563fe_strobe_eeprom ( u_short bmpr16 )
564{
565 /*
566 * We must guarantee 800ns (or more) interval to access slow
567 * EEPROMs. The following redundant code provides enough
568 * delay with ISA timing. (Even if the bus clock is "tuned.")
569 * Some modification will be needed on faster busses.
570 */
571 outb( bmpr16, FE_B16_SELECT );
572 outb( bmpr16, FE_B16_SELECT );
573 outb( bmpr16, FE_B16_SELECT | FE_B16_CLOCK );
574 outb( bmpr16, FE_B16_SELECT | FE_B16_CLOCK );
575 outb( bmpr16, FE_B16_SELECT );
576 outb( bmpr16, FE_B16_SELECT );
577}
578
579static void
580fe_read_eeprom ( struct fe_softc * sc, u_char * data )
581{
582 u_short bmpr16 = sc->ioaddr[ FE_BMPR16 ];
583 u_short bmpr17 = sc->ioaddr[ FE_BMPR17 ];
584 u_char n, val, bit;
585
586 /* Read bytes from EEPROM; two bytes per an iteration. */
587 for ( n = 0; n < FE_EEPROM_SIZE / 2; n++ ) {
588
589 /* Reset the EEPROM interface. */
590 outb( bmpr16, 0x00 );
591 outb( bmpr17, 0x00 );
592
593 /* Start EEPROM access. */
594 outb( bmpr16, FE_B16_SELECT );
595 outb( bmpr17, FE_B17_DATA );
596 fe_strobe_eeprom( bmpr16 );
597
598 /* Pass the iteration count to the chip. */
599 val = 0x80 | n;
600 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
601 outb( bmpr17, ( val & bit ) ? FE_B17_DATA : 0 );
602 fe_strobe_eeprom( bmpr16 );
603 }
604 outb( bmpr17, 0x00 );
605
606 /* Read a byte. */
607 val = 0;
608 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
609 fe_strobe_eeprom( bmpr16 );
610 if ( inb( bmpr17 ) & FE_B17_DATA ) {
611 val |= bit;
612 }
613 }
614 *data++ = val;
615
616 /* Read one more byte. */
617 val = 0;
618 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
619 fe_strobe_eeprom( bmpr16 );
620 if ( inb( bmpr17 ) & FE_B17_DATA ) {
621 val |= bit;
622 }
623 }
624 *data++ = val;
625 }
626
627 /* Reset the EEPROM interface, again. */
628 outb( bmpr16, 0x00 );
629 outb( bmpr17, 0x00 );
630
631#if FE_DEBUG >= 3
632 /* Report what we got. */
633 data -= FE_EEPROM_SIZE;
634 log( LOG_INFO, "fe%d: EEPROM:"
635 " %02x%02x%02x%02x %02x%02x%02x%02x -"
636 " %02x%02x%02x%02x %02x%02x%02x%02x -"
637 " %02x%02x%02x%02x %02x%02x%02x%02x -"
638 " %02x%02x%02x%02x %02x%02x%02x%02x\n",
639 sc->sc_unit,
640 data[ 0], data[ 1], data[ 2], data[ 3],
641 data[ 4], data[ 5], data[ 6], data[ 7],
642 data[ 8], data[ 9], data[10], data[11],
643 data[12], data[13], data[14], data[15],
644 data[16], data[17], data[18], data[19],
645 data[20], data[21], data[22], data[23],
646 data[24], data[25], data[26], data[27],
647 data[28], data[29], data[30], data[31] );
648#endif
649}
650
651/*
652 * Hardware (vendor) specific probe routines.
653 */
654
655/*
656 * Probe and initialization for Fujitsu FMV-180 series boards
657 */
658static int
659fe_probe_fmv ( DEVICE * dev, struct fe_softc * sc )
660{
661 int i, n;
662
663 static u_short const baseaddr [ 8 ] =
664 { 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x300, 0x340 };
665 static u_short const irqmap [ 4 ] =
666 { IRQ3, IRQ7, IRQ10, IRQ15 };
667
668 static struct fe_simple_probe_struct const probe_table [] = {
669 { FE_DLCR2, 0x70, 0x00 },
670 { FE_DLCR4, 0x08, 0x00 },
671 /* { FE_DLCR5, 0x80, 0x00 }, Doesn't work. */
672
673 { FE_FMV0, 0x78, 0x50 }, /* ERRDY+PRRDY */
674 { FE_FMV1, 0xB0, 0x00 }, /* FMV-183/184 has 0x48 bits. */
675 { FE_FMV3, 0x7F, 0x00 },
676#if 1
677 /*
678 * Test *vendor* part of the station address for Fujitsu.
679 * The test will gain reliability of probe process, but
680 * it rejects FMV-180 clone boards manufactured by other vendors.
681 * We have to turn the test off when such cards are made available.
682 */
683 { FE_FMV4, 0xFF, 0x00 },
684 { FE_FMV5, 0xFF, 0x00 },
685 { FE_FMV6, 0xFF, 0x0E },
686#else
687 /*
688 * We can always verify the *first* 2 bits (in Ethernet
689 * bit order) are "no multicast" and "no local" even for
690 * unknown vendors.
691 */
692 { FE_FMV4, 0x03, 0x00 },
693#endif
694 { 0 }
695 };
696
697 /* "Hardware revision ID" */
698 int revision;
699
700 /*
701 * See if the specified address is possible for FMV-180 series.
702 */
703 for ( i = 0; i < 8; i++ ) {
704 if ( baseaddr[ i ] == sc->iobase ) break;
705 }
706 if ( i == 8 ) return 0;
707
708 /* Setup an I/O address mapping table. */
709 for ( i = 0; i < MAXREGISTERS; i++ ) {
710 sc->ioaddr[ i ] = sc->iobase + i;
711 }
712
713 /* Simple probe. */
714 if ( !fe_simple_probe( sc, probe_table ) ) return 0;
715
716 /* Check if our I/O address matches config info. on EEPROM. */
717 n = ( inb( sc->ioaddr[ FE_FMV2 ] ) & FE_FMV2_IOS )
718 >> FE_FMV2_IOS_SHIFT;
719 if ( baseaddr[ n ] != sc->iobase ) {
720#if 0
721 /* May not work on some revisions of the cards... FIXME. */
722 return 0;
723#else
724 /* Just log the fact and see what happens... FIXME. */
725 log( LOG_WARNING, "fe%d: strange I/O config?\n", sc->sc_unit );
726#endif
727 }
728
729 /* Find the "hardware revision." */
730 revision = inb( sc->ioaddr[ FE_FMV1 ] ) & FE_FMV1_REV;
731
732 /* Determine the card type. */
733 sc->typestr = NULL;
734 switch ( inb( sc->ioaddr[ FE_FMV0 ] ) & FE_FMV0_MEDIA ) {
735 case 0:
736 /* No interface? This doesn't seem to be an FMV-180... */
737 return 0;
738 case FE_FMV0_MEDIUM_T:
739 switch ( revision ) {
740 case 8:
741 sc->typestr = "FMV-183";
742 break;
743 case 12:
744 sc->typestr = "FMV-183 (on-board)";
745 break;
746 }
747 break;
748 case FE_FMV0_MEDIUM_T | FE_FMV0_MEDIUM_5:
749 switch ( revision ) {
750 case 0:
751 sc->typestr = "FMV-181";
752 break;
753 case 1:
754 sc->typestr = "FMV-181A";
755 break;
756 }
757 break;
758 case FE_FMV0_MEDIUM_2:
759 switch ( revision ) {
760 case 8:
761 sc->typestr = "FMV-184 (CSR = 2)";
762 break;
763 }
764 break;
765 case FE_FMV0_MEDIUM_5:
766 switch ( revision ) {
767 case 8:
768 sc->typestr = "FMV-184 (CSR = 1)";
769 break;
770 }
771 break;
772 case FE_FMV0_MEDIUM_2 | FE_FMV0_MEDIUM_5:
773 switch ( revision ) {
774 case 0:
775 sc->typestr = "FMV-182";
776 break;
777 case 1:
778 sc->typestr = "FMV-182A";
779 break;
780 case 8:
781 sc->typestr = "FMV-184 (CSR = 3)";
782 break;
783 }
784 break;
785 }
786 if ( sc->typestr == NULL ) {
787 /* Unknown card type... Hope the driver works. */
788 sc->typestr = "unknown FMV-180 version";
789 log( LOG_WARNING, "fe%d: %s: %x-%x-%x-%x\n",
790 sc->sc_unit, sc->typestr,
791 inb( sc->ioaddr[ FE_FMV0 ] ),
792 inb( sc->ioaddr[ FE_FMV1 ] ),
793 inb( sc->ioaddr[ FE_FMV2 ] ),
794 inb( sc->ioaddr[ FE_FMV3 ] ) );
795 }
796
797 /*
798 * An FMV-180 has been proved.
799 * Determine which IRQ to be used.
800 *
801 * In this version, we give a priority to the kernel config file.
802 * If the EEPROM and config don't match, say it to the user for
803 * an attention.
804 */
805 n = ( inb( sc->ioaddr[ FE_FMV2 ] ) & FE_FMV2_IRS )
806 >> FE_FMV2_IRS_SHIFT;
807 if ( dev->id_irq == NO_IRQ ) {
808 /* Just use the probed value. */
809 dev->id_irq = irqmap[ n ];
810 } else if ( dev->id_irq != irqmap[ n ] ) {
811 /* Don't match. */
812 log( LOG_WARNING,
813 "fe%d: check IRQ in config; it may be incorrect\n",
814 sc->sc_unit );
815 }
816
817 /*
818 * Initialize constants in the per-line structure.
819 */
820
821 /* Get our station address from EEPROM. */
822 inblk( sc, FE_FMV4, sc->sc_enaddr, ETHER_ADDR_LEN );
823
824 /* Make sure we got a valid station address. */
825 if ( ( sc->sc_enaddr[ 0 ] & 0x03 ) != 0x00
826 || ( sc->sc_enaddr[ 0 ] == 0x00
827 && sc->sc_enaddr[ 1 ] == 0x00
828 && sc->sc_enaddr[ 2 ] == 0x00 ) ) return 0;
829
830 /*
831 * Register values which (may) depend on board design.
832 *
833 * Program the 86960 as follows:
834 * SRAM: 32KB, 100ns, byte-wide access.
835 * Transmission buffer: 4KB x 2.
836 * System bus interface: 16 bits.
837 */
838 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
839 sc->proto_dlcr5 = 0;
840 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
841 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
842 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_EC;
843 sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
844
845 /*
846 * Minimum initialization of the hardware.
847 * We write into registers; hope I/O ports have no
848 * overlap with other boards.
849 */
850
851 /* Initialize ASIC. */
852 outb( sc->ioaddr[ FE_FMV3 ], 0 );
853 outb( sc->ioaddr[ FE_FMV10 ], 0 );
854
855 /* Initialize 86960. */
856 DELAY( 200 );
857 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
858 DELAY( 200 );
859
860 /* Disable all interrupts. */
861 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
862 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
863
864 /* "Refresh" hardware configuration. FIXME. */
865 outb( sc->ioaddr[ FE_FMV2 ], inb( sc->ioaddr[ FE_FMV2 ] ) );
866
867 /* Turn the "master interrupt control" flag of ASIC on. */
868 outb( sc->ioaddr[ FE_FMV3 ], FE_FMV3_IRQENB );
869
870 /*
871 * That's all. FMV-180 occupies 32 I/O addresses, by the way.
872 */
873 return 32;
874}
875
876/*
877 * Probe and initialization for Allied-Telesis AT1700/RE2000 series.
878 */
879static int
880fe_probe_ati ( DEVICE * dev, struct fe_softc * sc )
881{
882 int i, n;
883 u_char eeprom [ FE_EEPROM_SIZE ];
884 u_char save16, save17;
885
886 static u_short const baseaddr [ 8 ] =
887 { 0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300 };
888 static u_short const irqmaps [ 4 ][ 4 ] =
889 {
890 { IRQ3, IRQ4, IRQ5, IRQ9 },
891 { IRQ10, IRQ11, IRQ12, IRQ15 },
892 { IRQ3, IRQ11, IRQ5, IRQ15 },
893 { IRQ10, IRQ11, IRQ14, IRQ15 },
894 };
895 static struct fe_simple_probe_struct const probe_table [] = {
896 { FE_DLCR2, 0x70, 0x00 },
897 { FE_DLCR4, 0x08, 0x00 },
898 { FE_DLCR5, 0x80, 0x00 },
899#if 0
900 { FE_BMPR16, 0x1B, 0x00 },
901 { FE_BMPR17, 0x7F, 0x00 },
902#endif
903 { 0 }
904 };
905
906 /* Assume we have 86965 and no need to restore these. */
907 save16 = 0;
908 save17 = 0;
909
910#if FE_DEBUG >= 3
911 log( LOG_INFO, "fe%d: probe (0x%x) for ATI\n",
912 sc->sc_unit, sc->iobase );
913 fe_dump( LOG_INFO, sc, NULL );
914#endif
915
916 /*
917 * See if the specified address is possible for MB86965A JLI mode.
918 */
919 for ( i = 0; i < 8; i++ ) {
920 if ( baseaddr[ i ] == sc->iobase ) break;
921 }
922 if ( i == 8 ) goto NOTFOUND;
923
924 /* Setup an I/O address mapping table. */
925 for ( i = 0; i < MAXREGISTERS; i++ ) {
926 sc->ioaddr[ i ] = sc->iobase + i;
927 }
928
929 /*
930 * We should test if MB86965A is on the base address now.
931 * Unfortunately, it is very hard to probe it reliably, since
932 * we have no way to reset the chip under software control.
933 * On cold boot, we could check the "signature" bit patterns
934 * described in the Fujitsu document. On warm boot, however,
935 * we can predict almost nothing about register values.
936 */
937 if ( !fe_simple_probe( sc, probe_table ) ) goto NOTFOUND;
938
939 /* Check if our I/O address matches config info on 86965. */
940 n = ( inb( sc->ioaddr[ FE_BMPR19 ] ) & FE_B19_ADDR )
941 >> FE_B19_ADDR_SHIFT;
942 if ( baseaddr[ n ] != sc->iobase ) goto NOTFOUND;
943
944 /*
945 * We are now almost sure we have an AT1700 at the given
946 * address. So, read EEPROM through 86965. We have to write
947 * into LSI registers to read from EEPROM. I want to avoid it
948 * at this stage, but I cannot test the presence of the chip
949 * any further without reading EEPROM. FIXME.
950 */
951 save16 = inb( sc->ioaddr[ FE_BMPR16 ] );
952 save17 = inb( sc->ioaddr[ FE_BMPR17 ] );
953 fe_read_eeprom( sc, eeprom );
954
955 /* Make sure the EEPROM is turned off. */
956 outb( sc->ioaddr[ FE_BMPR16 ], 0 );
957 outb( sc->ioaddr[ FE_BMPR17 ], 0 );
958
959 /* Make sure that config info in EEPROM and 86965 agree. */
960 if ( eeprom[ FE_EEPROM_CONF ] != inb( sc->ioaddr[ FE_BMPR19 ] ) ) {
961 goto NOTFOUND;
962 }
963
964 /*
965 * The following model identification codes are stolen from
966 * from the NetBSD port of the fe driver. My reviewers
967 * suggested minor revision.
968 */
969
970 /* Determine the card type. */
971 switch (eeprom[FE_ATI_EEP_MODEL]) {
972 case FE_ATI_MODEL_AT1700T:
973 sc->typestr = "AT-1700T/RE2001";
974 break;
975 case FE_ATI_MODEL_AT1700BT:
976 sc->typestr = "AT-1700BT/RE2003";
977 break;
978 case FE_ATI_MODEL_AT1700FT:
979 sc->typestr = "AT-1700FT/RE2009";
980 break;
981 case FE_ATI_MODEL_AT1700AT:
982 sc->typestr = "AT-1700AT/RE2005";
983 break;
984 default:
985 sc->typestr = "unknown AT-1700/RE2000 ?";
986 break;
987 }
988
989 /*
990 * Try to determine IRQ settings.
991 * Different models use different ranges of IRQs.
992 */
993 if ( dev->id_irq == NO_IRQ ) {
994 n = ( inb( sc->ioaddr[ FE_BMPR19 ] ) & FE_B19_IRQ )
995 >> FE_B19_IRQ_SHIFT;
996 switch ( eeprom[ FE_ATI_EEP_REVISION ] & 0xf0 ) {
997 case 0x30:
998 dev->id_irq = irqmaps[ 3 ][ n ];
999 break;
1000 case 0x10:
1001 case 0x50:
1002 dev->id_irq = irqmaps[ 2 ][ n ];
1003 break;
1004 case 0x40:
1005 case 0x60:
1006 if ( eeprom[ FE_ATI_EEP_MAGIC ] & 0x04 ) {
1007 dev->id_irq = irqmaps[ 1 ][ n ];
1008 } else {
1009 dev->id_irq = irqmaps[ 0 ][ n ];
1010 }
1011 break;
1012 default:
1013 dev->id_irq = irqmaps[ 0 ][ n ];
1014 break;
1015 }
1016 }
1017
1018
1019 /*
1020 * Initialize constants in the per-line structure.
1021 */
1022
1023 /* Get our station address from EEPROM. */
1024 bcopy( eeprom + FE_ATI_EEP_ADDR, sc->sc_enaddr, ETHER_ADDR_LEN );
1025
1026#if 1
1027 /*
1028 * This test doesn't work well for AT1700 look-alike by
1029 * other vendors.
1030 */
1031 /* Make sure the vendor part is for Allied-Telesis. */
1032 if ( sc->sc_enaddr[ 0 ] != 0x00
1033 || sc->sc_enaddr[ 1 ] != 0x00
1034 || sc->sc_enaddr[ 2 ] != 0xF4 ) return 0;
1035
1036#else
1037 /* Make sure we got a valid station address. */
1038 if ( ( sc->sc_enaddr[ 0 ] & 0x03 ) != 0x00
1039 || ( sc->sc_enaddr[ 0 ] == 0x00
1040 && sc->sc_enaddr[ 1 ] == 0x00
1041 && sc->sc_enaddr[ 2 ] == 0x00 ) ) return 0;
1042#endif
1043
1044 /*
1045 * Program the 86960 as follows:
1046 * SRAM: 32KB, 100ns, byte-wide access.
1047 * Transmission buffer: 4KB x 2.
1048 * System bus interface: 16 bits.
1049 */
1050 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL; /* FIXME */
1051 sc->proto_dlcr5 = 0;
1052 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
1053 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
1054 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_EC;
1055#if 0 /* XXXX Should we use this? FIXME. */
1056 sc->proto_bmpr13 = eeprom[ FE_ATI_EEP_MEDIA ];
1057#else
1058 sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
1059#endif
1060
1061#if FE_DEBUG >= 3
1062 fe_dump( LOG_INFO, sc, "ATI found" );
1063#endif
1064
1065 /* Setup hooks. This may solves a nasty bug. FIXME. */
1066 sc->init = fe_init_ati;
1067
1068 /* Initialize 86965. */
1069 DELAY( 200 );
1070 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1071 DELAY( 200 );
1072
1073 /* Disable all interrupts. */
1074 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
1075 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
1076
1077#if FE_DEBUG >= 3
1078 fe_dump( LOG_INFO, sc, "end of fe_probe_ati()" );
1079#endif
1080
1081 /*
1082 * That's all. AT1700 occupies 32 I/O addresses, by the way.
1083 */
1084 return 32;
1085
1086 NOTFOUND:
1087 /*
1088 * We have no AT1700 at a given address.
1089 * Restore BMPR16 and BMPR17 if we have destroyed them,
1090 * hoping that the hardware on the address didn't get
1091 * bad side effect.
1092 */
1093 if ( save16 != 0 | save17 != 0 ) {
1094 outb( sc->ioaddr[ FE_BMPR16 ], save16 );
1095 outb( sc->ioaddr[ FE_BMPR17 ], save17 );
1096 }
1097 return ( 0 );
1098}
1099
1100/* ATI specific initialization routine. */
1101static void
1102fe_init_ati ( struct fe_softc * sc )
1103{
1104/*
1105 * I've told that the following operation "Resets" the chip.
1106 * Hope this solve a bug which hangs up the driver under
1107 * heavy load... FIXME.
1108 */
1109
1110 /* Minimal initialization of 86965. */
1111 DELAY( 200 );
1112 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1113 DELAY( 200 );
1114
1115 /* "Reset" by wrting into an undocument register location. */
1116 outb( sc->ioaddr[ 0x1F ], 0 );
1117
1118 /* How long do we have to wait after the reset? FIXME. */
1119 DELAY( 300 );
1120}
1121
1122/*
1123 * Probe and initialization for Gateway Communications' old cards.
1124 */
1125static int
1126fe_probe_gwy ( DEVICE * dev, struct fe_softc * sc )
1127{
1128 int i;
1129
1130 static struct fe_simple_probe_struct probe_table [] = {
1131 { FE_DLCR2, 0x70, 0x00 },
1132 { FE_DLCR4, 0x08, 0x00 },
1133 { FE_DLCR7, 0xC0, 0x00 },
1134 /*
1135 * Test *vendor* part of the address for Gateway.
1136 * This test is essential to identify Gateway's cards.
1137 * We shuld define some symbolic names for the
1138 * following offsets. FIXME.
1139 */
1140 { 0x18, 0xFF, 0x00 },
1141 { 0x19, 0xFF, 0x00 },
1142 { 0x1A, 0xFF, 0x61 },
1143 { 0 }
1144 };
1145
1146 /*
1147 * We need explicit IRQ and supported address.
1148 * I'm not sure which address and IRQ is possible for Gateway
1149 * Ethernet family. The following accepts everything. FIXME.
1150 */
1151 if ( dev->id_irq == NO_IRQ || ( sc->iobase & ~0x3E0 ) != 0 ) {
1152 return ( 0 );
1153 }
1154
1155#if FE_DEBUG >= 3
1156 fe_dump( LOG_INFO, sc, "top of probe" );
1157#endif
1158
1159 /* Setup an I/O address mapping table. */
1160 for ( i = 0; i < MAXREGISTERS; i++ ) {
1161 sc->ioaddr[ i ] = sc->iobase + i;
1162 }
1163
1164 /* See if the card is on its address. */
1165 if ( !fe_simple_probe( sc, probe_table ) ) {
1166 return 0;
1167 }
1168
1169 /* Determine the card type. */
1170 sc->typestr = "Gateway Ethernet w/ Fujitsu chipset";
1171
1172 /* Get our station address from EEPROM. */
1173 inblk( sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN );
1174
1175 /*
1176 * Program the 86960 as follows:
1177 * SRAM: 16KB, 100ns, byte-wide access.
1178 * Transmission buffer: 2KB x 2.
1179 * System bus interface: 16 bits.
1180 * Make sure to clear out ID bits in DLCR7
1181 * (They actually are Encoder/Decoder control in NICE.)
1182 */
1183 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
1184 sc->proto_dlcr5 = 0;
1185 sc->proto_dlcr6 = FE_D6_BUFSIZ_16KB | FE_D6_TXBSIZ_2x2KB
1186 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
1187 sc->proto_dlcr7 = FE_D7_BYTSWP_LH;
1188 sc->proto_bmpr13 = 0;
1189
1190 /* Minimal initialization of 86960. */
1191 DELAY( 200 );
1192 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1193 DELAY( 200 );
1194
1195 /* Disable all interrupts. */
1196 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
1197 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
1198
1199 /* That's all. The card occupies 32 I/O addresses, as always. */
1200 return 32;
1201}
1202
1203#if NCARD > 0
1204/*
1205 * Probe and initialization for Fujitsu MBH10302 PCMCIA Ethernet interface.
1206 * Note that this is for 10302 only; MBH10304 is handled by fe_probe_tdk().
1207 */
1208static int
1209fe_probe_mbh ( DEVICE * dev, struct fe_softc * sc )
1210{
1211 int i;
1212
1213 static struct fe_simple_probe_struct probe_table [] = {
1214 { FE_DLCR0, 0x09, 0x00 },
1215 { FE_DLCR2, 0x79, 0x00 },
1216 { FE_DLCR4, 0x08, 0x00 },
1217 { FE_DLCR6, 0xFF, 0xB6 },
1218 /*
1219 * The following location has the first byte of the card's
1220 * Ethernet (MAC) address.
1221 * We can always verify the *first* 2 bits (in Ethernet
1222 * bit order) are "global" and "unicast" for any vendors'.
1223 */
1224 { FE_MBH10, 0x03, 0x00 },
1225
1226 /* Just a gap? Seems reliable, anyway. */
1227 { 0x12, 0xFF, 0x00 },
1228 { 0x13, 0xFF, 0x00 },
1229 { 0x14, 0xFF, 0x00 },
1230 { 0x15, 0xFF, 0x00 },
1231 { 0x16, 0xFF, 0x00 },
1232 { 0x17, 0xFF, 0x00 },
1233#if 0
1234 { 0x18, 0xFF, 0xFF },
1235 { 0x19, 0xFF, 0xFF },
1236#endif
1237
1238 { 0 }
1239 };
1240
1241 /*
1242 * We need explicit IRQ and supported address.
1243 */
1244 if ( dev->id_irq == NO_IRQ || ( sc->iobase & ~0x3E0 ) != 0 ) {
1245 return ( 0 );
1246 }
1247
1248#if FE_DEBUG >= 3
1249 fe_dump( LOG_INFO, sc, "top of probe" );
1250#endif
1251
1252 /* Setup an I/O address mapping table. */
1253 for ( i = 0; i < MAXREGISTERS; i++ ) {
1254 sc->ioaddr[ i ] = sc->iobase + i;
1255 }
1256
1257 /*
1258 * See if MBH10302 is on its address.
1259 * I'm not sure the following probe code works. FIXME.
1260 */
1261 if ( !fe_simple_probe( sc, probe_table ) ) return 0;
1262
1263 /* Determine the card type. */
1264 sc->typestr = "MBH10302 (PCMCIA)";
1265
1266 /*
1267 * Initialize constants in the per-line structure.
1268 */
1269
1270 /* Get our station address from EEPROM. */
1271 inblk( sc, FE_MBH10, sc->sc_enaddr, ETHER_ADDR_LEN );
1272
1273 /* Make sure we got a valid station address. */
1274 if ( sc->sc_enaddr[ 0 ] == 0x00
1275 && sc->sc_enaddr[ 1 ] == 0x00
1276 && sc->sc_enaddr[ 2 ] == 0x00 ) return 0;
1277
1278 /*
1279 * Program the 86960 as follows:
1280 * SRAM: 32KB, 100ns, byte-wide access.
1281 * Transmission buffer: 4KB x 2.
1282 * System bus interface: 16 bits.
1283 */
1284 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
1285 sc->proto_dlcr5 = 0;
1286 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
1287 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
1288 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
1289 sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
1290
1291 /* Setup hooks. We need a special initialization procedure. */
1292 sc->init = fe_init_mbh;
1293
1294 /*
1295 * Minimum initialization.
1296 */
1297
1298 /* Minimal initialization of 86960. */
1299 DELAY( 200 );
1300 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1301 DELAY( 200 );
1302
1303 /* Disable all interrupts. */
1304 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
1305 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
1306
1307#if 1 /* FIXME. */
1308 /* Initialize system bus interface and encoder/decoder operation. */
1309 outb( sc->ioaddr[ FE_MBH0 ], FE_MBH0_MAGIC | FE_MBH0_INTR_DISABLE );
1310#endif
1311
1312 /*
1313 * That's all. MBH10302 occupies 32 I/O addresses, by the way.
1314 */
1315 return 32;
1316}
1317
1318/* MBH specific initialization routine. */
1319static void
1320fe_init_mbh ( struct fe_softc * sc )
1321{
1322 /* Minimal initialization of 86960. */
1323 DELAY( 200 );
1324 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1325 DELAY( 200 );
1326
1327 /* Disable all interrupts. */
1328 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
1329 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
1330
1331 /* Enable master interrupt flag. */
1332 outb( sc->ioaddr[ FE_MBH0 ], FE_MBH0_MAGIC | FE_MBH0_INTR_ENABLE );
1333}
1334
1335/*
1336 * Probe and initialization for TDK/CONTEC PCMCIA Ethernet interface.
1337 * by MASUI Kenji <masui@cs.titech.ac.jp>
1338 *
1339 * (Contec uses TDK Ethenet chip -- hosokawa)
1340 *
1341 * This version of fe_probe_tdk has been rewrote to handle
1342 * *generic* PC card implementation of Fujitsu MB8696x and compatibles.
1343 * The name _tdk is just for a historical reason. <seki> :-)
1344 */
1345static int
1346fe_probe_tdk ( DEVICE * dev, struct fe_softc * sc )
1347{
1348 int i;
1349
1350 static struct fe_simple_probe_struct probe_table [] = {
1351 { FE_DLCR2, 0x70, 0x00 },
1352 { FE_DLCR4, 0x08, 0x00 },
1353 /* { FE_DLCR5, 0x80, 0x00 }, Does not work well. */
1354 { 0 }
1355 };
1356
1357 /* We need an IRQ. */
1358 if ( dev->id_irq == NO_IRQ ) {
1359 return ( 0 );
1360 }
1361
1362 /* Generic driver needs Ethernet address taken from CIS. */
1363 if (sc->arpcom.ac_enaddr[0] == 0
1364 && sc->arpcom.ac_enaddr[1] == 0
1365 && sc->arpcom.ac_enaddr[2] == 0) {
1366 return 0;
1367 }
1368
1369 /* Setup an I/O address mapping table; we need only 16 ports. */
1370 for (i = 0; i < 16; i++) {
1371 sc->ioaddr[i] = sc->iobase + i;
1372 }
1373 /* Fill unused slots with a safe address. */
1374 for (i = 16; i < MAXREGISTERS; i++) {
1375 sc->ioaddr[i] = sc->iobase;
1376 }
1377
1378 /*
1379 * See if C-NET(PC)C is on its address.
1380 */
1381
1382 if ( !fe_simple_probe( sc, probe_table ) ) return 0;
1383
1384 /* Determine the card type. */
1385 sc->typestr = "Generic MB8696x Ethernet (PCMCIA)";
1386
1387 /*
1388 * Initialize constants in the per-line structure.
1389 */
1390
1391 /* The station address *must*be* already in sc_enaddr;
1392 Make sure we got a valid station address. */
1393 if ( ( sc->sc_enaddr[ 0 ] & 0x03 ) != 0x00
1394 || ( sc->sc_enaddr[ 0 ] == 0x00
1395 && sc->sc_enaddr[ 1 ] == 0x00
1396 && sc->sc_enaddr[ 2 ] == 0x00 ) ) return 0;
1397
1398 /*
1399 * Program the 86965 as follows:
1400 * SRAM: 32KB, 100ns, byte-wide access.
1401 * Transmission buffer: 4KB x 2.
1402 * System bus interface: 16 bits.
1403 * XXX: Should we remove IDENT_NICE from DLCR7? Or,
1404 * even add IDENT_EC instead? FIXME.
1405 */
1406 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
1407 sc->proto_dlcr5 = 0;
1408 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
1409 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
1410 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
1411 sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
1412
1413 /* Minimul initialization of 86960. */
1414 DELAY( 200 );
1415 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1416 DELAY( 200 );
1417
1418 /* Disable all interrupts. */
1419 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
1420 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
1421
1422 /*
1423 * That's all. C-NET(PC)C occupies 16 I/O addresses.
1424 *
1425 * Some PC cards (e.g., TDK and Contec) have 16 I/O addresses,
1426 * while some others (e.g., Fujitsu) have 32. Fortunately,
1427 * this generic driver never accesses latter 16 ports in 32
1428 * ports cards. So, we can assume the *generic* PC cards
1429 * always have 16 ports.
1430 *
1431 * Moreover, PC card probe is isolated from ISA probe, and PC
1432 * card probe routine doesn't use "# of ports" returned by this
1433 * function. 16 v.s. 32 is not important now.
1434 */
1435 return 16;
1436}
1437#endif /* NCARD > 0 */
1438
1439/*
1440 * Install interface into kernel networking data structures
1441 */
1442static int
1443fe_attach ( DEVICE * dev )
1444{
1445#if NCARD > 0
1446 static int already_ifattach[NFE];
1447#endif
1448 struct fe_softc *sc = &fe_softc[dev->id_unit];
1449
1450 dev->id_ointr = feintr;
1451
1452 /*
1453 * Initialize ifnet structure
1454 */
1455 sc->sc_if.if_softc = sc;
1456 sc->sc_if.if_unit = sc->sc_unit;
1457 sc->sc_if.if_name = "fe";
1458 sc->sc_if.if_output = ether_output;
1459 sc->sc_if.if_start = fe_start;
1460 sc->sc_if.if_ioctl = fe_ioctl;
1461 sc->sc_if.if_watchdog = fe_watchdog;
1462
1463 /*
1464 * Set default interface flags.
1465 */
1466 sc->sc_if.if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1467
1468 /*
1469 * Set maximum size of output queue, if it has not been set.
1470 * It is done here as this driver may be started after the
1471 * system initialization (i.e., the interface is PCMCIA.)
1472 *
1473 * I'm not sure this is really necessary, but, even if it is,
1474 * it should be done somewhere else, e.g., in if_attach(),
1475 * since it must be a common workaround for all network drivers.
1476 * FIXME.
1477 */
1478 if ( sc->sc_if.if_snd.ifq_maxlen == 0 ) {
1479 sc->sc_if.if_snd.ifq_maxlen = ifqmaxlen;
1480 }
1481
1482#if FE_DEBUG >= 3
1483 fe_dump( LOG_INFO, sc, "attach()" );
1484#endif
1485
1486#if FE_SINGLE_TRANSMISSION
1487 /* Override txb config to allocate minimum. */
1488 sc->proto_dlcr6 &= ~FE_D6_TXBSIZ
1489 sc->proto_dlcr6 |= FE_D6_TXBSIZ_2x2KB;
1490#endif
1491
--- 4 unchanged lines hidden (view full) ---
1496
1497 /* Find TX buffer size, based on the hardware dependent proto. */
1498 switch ( sc->proto_dlcr6 & FE_D6_TXBSIZ ) {
1499 case FE_D6_TXBSIZ_2x2KB: sc->txb_size = 2048; break;
1500 case FE_D6_TXBSIZ_2x4KB: sc->txb_size = 4096; break;
1501 case FE_D6_TXBSIZ_2x8KB: sc->txb_size = 8192; break;
1502 default:
1503 /* Oops, we can't work with single buffer configuration. */
1504#if FE_DEBUG >= 2
1505 log( LOG_WARNING, "fe%d: strange TXBSIZ config; fixing\n",
1506 sc->sc_unit );
1507#endif
1508 sc->proto_dlcr6 &= ~FE_D6_TXBSIZ;
1509 sc->proto_dlcr6 |= FE_D6_TXBSIZ_2x2KB;
1510 sc->txb_size = 2048;
1511 break;
1512 }
1513
1514 /* Attach and stop the interface. */
1515#if NCARD > 0
1516 if (already_ifattach[dev->id_unit] != 1) {
1517 if_attach(&sc->sc_if);
1518 already_ifattach[dev->id_unit] = 1;
1519 }
1520#else
1521 if_attach(&sc->sc_if);
1522#endif
1523 fe_stop(sc->sc_unit); /* This changes the state to IDLE. */
1524 ether_ifattach(&sc->sc_if);
1525
1526 /* Print additional info when attached. */
1527 printf( "fe%d: address %6D, type %s\n", sc->sc_unit,
1528 sc->sc_enaddr, ":" , sc->typestr );
1529#if FE_DEBUG >= 3
1530 {
1531 int buf, txb, bbw, sbw, ram;
1532
1533 buf = txb = bbw = sbw = ram = -1;
1534 switch ( sc->proto_dlcr6 & FE_D6_BUFSIZ ) {
1535 case FE_D6_BUFSIZ_8KB: buf = 8; break;
1536 case FE_D6_BUFSIZ_16KB: buf = 16; break;
1537 case FE_D6_BUFSIZ_32KB: buf = 32; break;
1538 case FE_D6_BUFSIZ_64KB: buf = 64; break;
--- 10 unchanged lines hidden (view full) ---
1549 switch ( sc->proto_dlcr6 & FE_D6_SBW ) {
1550 case FE_D6_SBW_BYTE: sbw = 8; break;
1551 case FE_D6_SBW_WORD: sbw = 16; break;
1552 }
1553 switch ( sc->proto_dlcr6 & FE_D6_SRAM ) {
1554 case FE_D6_SRAM_100ns: ram = 100; break;
1555 case FE_D6_SRAM_150ns: ram = 150; break;
1556 }
1557 printf( "fe%d: SRAM %dKB %dbit %dns, TXB %dKBx2, %dbit I/O\n",
1558 sc->sc_unit, buf, bbw, ram, txb, sbw );
1559 }
1560#endif
1561
1562#if NBPFILTER > 0
1563 /* If BPF is in the kernel, call the attach for it. */
1564 bpfattach( &sc->sc_if, DLT_EN10MB, sizeof(struct ether_header));
1565#endif
1566 return 1;
1567}
1568
1569/*
1570 * Reset interface.
1571 */
1572static void
1573fe_reset ( int unit )
1574{
1575 /*
1576 * Stop interface and re-initialize.
1577 */
1578 fe_stop(unit);
1579 fe_init(unit);
1580}
1581
1582/*
1583 * Stop everything on the interface.
1584 *
1585 * All buffered packets, both transmitting and receiving,
1586 * if any, will be lost by stopping the interface.
1587 */
1588static void
1589fe_stop ( int unit )
1590{
1591 struct fe_softc *sc = &fe_softc[unit];
1592 int s;
1593
1594 s = splimp();
1595
1596#if FE_DEBUG >= 3
1597 fe_dump( LOG_INFO, sc, "stop()" );
1598#endif
1599
1600 /* Disable interrupts. */
1601 outb( sc->ioaddr[ FE_DLCR2 ], 0x00 );
1602 outb( sc->ioaddr[ FE_DLCR3 ], 0x00 );
1603
1604 /* Stop interface hardware. */
1605 DELAY( 200 );
1606 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1607 DELAY( 200 );
--- 12 unchanged lines hidden (view full) ---
1620 sc->sc_if.if_timer = 0;
1621 sc->txb_free = sc->txb_size;
1622 sc->txb_count = 0;
1623 sc->txb_sched = 0;
1624
1625 /* MAR loading can be delayed. */
1626 sc->filter_change = 0;
1627
1628 /* Update config status also. */
1629
1630 /* Call a hook. */
1631 if ( sc->stop ) sc->stop( sc );
1632
1633#if FE_DEBUG >= 3
1634 fe_dump( LOG_INFO, sc, "end of stop()" );
1635#endif
1636
1637 (void) splx(s);
1638}
1639
1640/*
1641 * Device timeout/watchdog routine. Entered if the device neglects to
1642 * generate an interrupt after a transmit has been started on it.
1643 */
1644static void
1645fe_watchdog ( struct ifnet *ifp )
1646{
1647 struct fe_softc *sc = (struct fe_softc *)ifp;
1648
1649#if FE_DEBUG >= 1
1650 /* A "debug" message. */
1651 log( LOG_ERR, "fe%d: transmission timeout (%d+%d)%s\n",
1652 ifp->if_unit, sc->txb_sched, sc->txb_count,
1653 ( ifp->if_flags & IFF_UP ) ? "" : " when down" );
1654 if ( sc->sc_if.if_opackets == 0 && sc->sc_if.if_ipackets == 0 ) {
1655 log( LOG_WARNING, "fe%d: wrong IRQ setting in config?\n",
1656 ifp->if_unit );
1657 }
1658#endif
1659
1660#if FE_DEBUG >= 3
1661 fe_dump( LOG_INFO, sc, NULL );
1662#endif
1663
1664 /* Record how many packets are lost by this accident. */
1665 ifp->if_oerrors += sc->txb_sched + sc->txb_count;
1666
1667 /* Put the interface into known initial state. */
1668 if ( ifp->if_flags & IFF_UP ) {
1669 fe_reset( ifp->if_unit );
1670 } else {
1671 fe_stop( ifp->if_unit );
1672 }
1673}
1674
1675/*
1676 * Initialize device.
1677 */
1678static void
1679fe_init ( int unit )
1680{
1681 struct fe_softc *sc = &fe_softc[unit];
1682 int s;
1683
1684#if FE_DEBUG >= 3
1685 fe_dump( LOG_INFO, sc, "init()" );
1686#endif
1687
1688 /* We need an address. */
1689 if (TAILQ_EMPTY(&sc->sc_if.if_addrhead)) { /* XXX unlikely */
1690#if FE_DEBUG >= 1
1691 log( LOG_ERR, "fe%d: init() without any address\n",
1692 sc->sc_unit );
1693#endif
1694 return;
1695 }
1696
1697#if FE_DEBUG >= 1
1698 /*
1699 * Make sure we have a valid station address.
1700 * The following test is applicable for any Ethernet interfaces.
1701 * It can be done in somewhere common to all of them. FIXME.
1702 */
1703 if ( ( sc->sc_enaddr[ 0 ] & 0x01 ) != 0
1704 || ( sc->sc_enaddr[ 0 ] == 0x00
1705 && sc->sc_enaddr[ 1 ] == 0x00
1706 && sc->sc_enaddr[ 2 ] == 0x00 ) ) {
1707 log( LOG_ERR, "fe%d: invalid station address (%6D)\n",
1708 sc->sc_unit, sc->sc_enaddr, ":" );
1709 return;
1710 }
1711#endif
1712
1713 /* Start initializing 86960. */
1714 s = splimp();
1715
1716 /* Call a hook. */
1717 if ( sc->init ) sc->init( sc );
1718
1719#if FE_DEBUG >= 3
1720 fe_dump( LOG_INFO, sc, "after init hook" );
1721#endif
1722
1723 /*
1724 * Make sure to disable the chip, also.
1725 * This may also help re-programming the chip after
1726 * hot insertion of PCMCIAs.
1727 */
1728 DELAY( 200 );
1729 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1730 DELAY( 200 );
--- 25 unchanged lines hidden (view full) ---
1756 outb( sc->ioaddr[ FE_DLCR5 ], sc->proto_dlcr5 );
1757 outb( sc->ioaddr[ FE_BMPR10 ], 0x00 );
1758 outb( sc->ioaddr[ FE_BMPR11 ], FE_B11_CTRL_SKIP | FE_B11_MODE1 );
1759 outb( sc->ioaddr[ FE_BMPR12 ], 0x00 );
1760 outb( sc->ioaddr[ FE_BMPR13 ], sc->proto_bmpr13 );
1761 outb( sc->ioaddr[ FE_BMPR14 ], 0x00 );
1762 outb( sc->ioaddr[ FE_BMPR15 ], 0x00 );
1763
1764#if FE_DEBUG >= 3
1765 fe_dump( LOG_INFO, sc, "just before enabling DLC" );
1766#endif
1767
1768 /* Enable interrupts. */
1769 outb( sc->ioaddr[ FE_DLCR2 ], FE_TMASK );
1770 outb( sc->ioaddr[ FE_DLCR3 ], FE_RMASK );
1771
1772 /* Enable transmitter and receiver. */
1773 DELAY( 200 );
1774 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_ENABLE );
1775 DELAY( 200 );
1776
1777#if FE_DEBUG >= 3
1778 fe_dump( LOG_INFO, sc, "just after enabling DLC" );
1779#endif
1780
1781 /*
1782 * Make sure to empty the receive buffer.
1783 *
1784 * This may be redundant, but *if* the receive buffer were full
1785 * at this point, then the driver would hang. I have experienced
1786 * some strange hang-up just after UP. I hope the following
1787 * code solve the problem.
1788 *
1789 * I have changed the order of hardware initialization.
1790 * I think the receive buffer cannot have any packets at this
1791 * point in this version. The following code *must* be
1792 * redundant now. FIXME.
1793 *
1794 * I've heard a rumore that on some PC card implementation of
1795 * 8696x, the receive buffer can have some data at this point.
1796 * The following message helps discovering the fact. FIXME.
1797 */
1798 if ( !( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) ) {
1799 log( LOG_WARNING,
1800 "fe%d: receive buffer has some data after reset\n",
1801 sc->sc_unit );
1802
1803 fe_emptybuffer( sc );
1804 }
1805
1806#if FE_DEBUG >= 3
1807 fe_dump( LOG_INFO, sc, "after ERB loop" );
1808#endif
1809
1810 /* Do we need this here? Actually, no. I must be paranoia. */
1811 outb( sc->ioaddr[ FE_DLCR0 ], 0xFF ); /* Clear all bits. */
1812 outb( sc->ioaddr[ FE_DLCR1 ], 0xFF ); /* ditto. */
1813
1814#if FE_DEBUG >= 3
1815 fe_dump( LOG_INFO, sc, "after FIXME" );
1816#endif
1817 /* Set 'running' flag, because we are now running. */
1818 sc->sc_if.if_flags |= IFF_RUNNING;
1819
1820 /*
1821 * At this point, the interface is running properly,
1822 * except that it receives *no* packets. we then call
1823 * fe_setmode() to tell the chip what packets to be
1824 * received, based on the if_flags and multicast group
1825 * list. It completes the initialization process.
1826 */
1827 fe_setmode( sc );
1828
1829#if FE_DEBUG >= 3
1830 fe_dump( LOG_INFO, sc, "after setmode" );
1831#endif
1832
1833 /* ...and attempt to start output queued packets. */
1834 fe_start( &sc->sc_if );
1835
1836#if FE_DEBUG >= 3
1837 fe_dump( LOG_INFO, sc, "init() done" );
1838#endif
1839
1840 (void) splx(s);
1841}
1842
1843/*
1844 * This routine actually starts the transmission on the interface
1845 */
--- 27 unchanged lines hidden (view full) ---
1873 * (i.e. that the output part of the interface is idle)
1874 */
1875void
1876fe_start ( struct ifnet *ifp )
1877{
1878 struct fe_softc *sc = ifp->if_softc;
1879 struct mbuf *m;
1880
1881#if FE_DEBUG >= 1
1882 /* Just a sanity check. */
1883 if ( ( sc->txb_count == 0 ) != ( sc->txb_free == sc->txb_size ) ) {
1884 /*
1885 * Txb_count and txb_free co-works to manage the
1886 * transmission buffer. Txb_count keeps track of the
1887 * used potion of the buffer, while txb_free does unused
1888 * potion. So, as long as the driver runs properly,
1889 * txb_count is zero if and only if txb_free is same
1890 * as txb_size (which represents whole buffer.)
1891 */
1892 log( LOG_ERR, "fe%d: inconsistent txb variables (%d, %d)\n",
1893 sc->sc_unit, sc->txb_count, sc->txb_free );
1894 /*
1895 * So, what should I do, then?
1896 *
1897 * We now know txb_count and txb_free contradicts. We
1898 * cannot, however, tell which is wrong. More
1899 * over, we cannot peek 86960 transmission buffer or
1900 * reset the transmission buffer. (In fact, we can
1901 * reset the entire interface. I don't want to do it.)
1902 *
1903 * If txb_count is incorrect, leaving it as-is will cause
1904 * sending of garbage after next interrupt. We have to
1905 * avoid it. Hence, we reset the txb_count here. If
1906 * txb_free was incorrect, resetting txb_count just loose
1907 * some packets. We can live with it.
1908 */
1909 sc->txb_count = 0;
1910 }
1911#endif
1912
1913#if FE_DEBUG >= 1
1914 /*
1915 * First, see if there are buffered packets and an idle
1916 * transmitter - should never happen at this point.
1917 */
1918 if ( ( sc->txb_count > 0 ) && ( sc->txb_sched == 0 ) ) {
1919 log( LOG_ERR,
1920 "fe%d: transmitter idle with %d buffered packets\n",
1921 sc->sc_unit, sc->txb_count );
1922 fe_xmit( sc );
1923 }
1924#endif
1925
1926 /*
1927 * Stop accepting more transmission packets temporarily, when
1928 * a filter change request is delayed. Updating the MARs on
1929 * 86960 flushes the transmission buffer, so it is delayed
1930 * until all buffered transmission packets have been sent
1931 * out.
1932 */
--- 105 unchanged lines hidden (view full) ---
2038 /*
2039 * 86960 manual says that we have to read 8 bytes from the buffer
2040 * before skip the packets and that there must be more than 8 bytes
2041 * remaining in the buffer when issue a skip command.
2042 * Remember, we have already read 4 bytes before come here.
2043 */
2044 if ( len > 12 ) {
2045 /* Read 4 more bytes, and skip the rest of the packet. */
2046 ( void )inw( sc->ioaddr[ FE_BMPR8 ] );
2047 ( void )inw( sc->ioaddr[ FE_BMPR8 ] );
2048 outb( sc->ioaddr[ FE_BMPR14 ], FE_B14_SKIP );
2049 } else {
2050 /* We should not come here unless receiving RUNTs. */
2051 for ( i = 0; i < len; i += 2 ) {
2052 ( void )inw( sc->ioaddr[ FE_BMPR8 ] );
2053 }
2054 }
2055}
2056
2057/*
2058 * Empty receiving buffer.
2059 */
2060static void
2061fe_emptybuffer ( struct fe_softc * sc )
2062{
2063 int i;
2064 u_char saved_dlcr5;
2065
2066#if FE_DEBUG >= 2
2067 log( LOG_WARNING, "fe%d: emptying receive buffer\n", sc->sc_unit );
2068#endif
2069 /*
2070 * Stop receiving packets, temporarily.
2071 */
2072 saved_dlcr5 = inb( sc->ioaddr[ FE_DLCR5 ] );
2073 outb( sc->ioaddr[ FE_DLCR5 ], sc->proto_dlcr5 );
2074 DELAY(1300);
2075
2076 /*
2077 * When we come here, the receive buffer management should
2078 * have been broken. So, we cannot use skip operation.
2079 * Just discard everything in the buffer.
2080 */
2081 for (i = 0; i < 32768; i++) {
2082 if ( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) break;
2083 ( void )inw( sc->ioaddr[ FE_BMPR8 ] );
2084 }
2085
2086 /*
2087 * Double check.
2088 */
2089 if ( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) {
2090 log( LOG_ERR, "fe%d: could not empty receive buffer\n",
2091 sc->sc_unit );
2092 /* Hmm. What should I do if this happens? FIXME. */
2093 }
2094
2095 /*
2096 * Restart receiving packets.
2097 */
2098 outb( sc->ioaddr[ FE_DLCR5 ], saved_dlcr5 );
2099}
2100
2101/*
2102 * Transmission interrupt handler
2103 * The control flow of this function looks silly. FIXME.
2104 */
2105static void
2106fe_tint ( struct fe_softc * sc, u_char tstat )
2107{
--- 5 unchanged lines hidden (view full) ---
2113 */
2114 if ( tstat & FE_D0_COLL16 ) {
2115
2116 /*
2117 * Find how many packets (including this collided one)
2118 * are left unsent in transmission buffer.
2119 */
2120 left = inb( sc->ioaddr[ FE_BMPR10 ] );
2121
2122#if FE_DEBUG >= 2
2123 log( LOG_WARNING, "fe%d: excessive collision (%d/%d)\n",
2124 sc->sc_unit, left, sc->txb_sched );
2125#endif
2126#if FE_DEBUG >= 3
2127 fe_dump( LOG_INFO, sc, NULL );
2128#endif
2129
2130 /*
2131 * Clear the collision flag (in 86960) here
2132 * to avoid confusing statistics.
2133 */
2134 outb( sc->ioaddr[ FE_DLCR0 ], FE_D0_COLLID );
2135
2136 /*
2137 * Restart transmitter, skipping the
--- 56 unchanged lines hidden (view full) ---
2194 *
2195 * Since the accurate number of collisions
2196 * has been lost, we just guess it as 1;
2197 * Am I too optimistic? FIXME.
2198 */
2199 col = 1;
2200 }
2201 sc->sc_if.if_collisions += col;
2202#if FE_DEBUG >= 3
2203 log( LOG_WARNING, "fe%d: %d collision(s) (%d)\n",
2204 sc->sc_unit, col, sc->txb_sched );
2205#endif
2206 }
2207
2208 /*
2209 * Update transmission statistics.
2210 * Be sure to reflect number of excessive collisions.
2211 */
2212 sc->sc_if.if_opackets += sc->txb_sched - sc->tx_excolls;
2213 sc->sc_if.if_oerrors += sc->tx_excolls;
2214 sc->sc_if.if_collisions += sc->tx_excolls * 16;
2215 sc->txb_sched = 0;
2216
2217 /*
2218 * The transmitter is no more active.
2219 * Reset output active flag and watchdog timer.
2220 */
2221 sc->sc_if.if_flags &= ~IFF_OACTIVE;
2222 sc->sc_if.if_timer = 0;
--- 15 unchanged lines hidden (view full) ---
2238fe_rint ( struct fe_softc * sc, u_char rstat )
2239{
2240 u_short len;
2241 u_char status;
2242 int i;
2243
2244 /*
2245 * Update statistics if this interrupt is caused by an error.
2246 */
2247 if ( rstat & ( FE_D1_OVRFLO | FE_D1_CRCERR
2248 | FE_D1_ALGERR | FE_D1_SRTPKT ) ) {
2249#if FE_DEBUG >= 2
2250 log( LOG_WARNING,
2251 "fe%d: receive error: %s%s%s%s(%02x)\n",
2252 sc->sc_unit,
2253 rstat & FE_D1_OVRFLO ? "OVR " : "",
2254 rstat & FE_D1_CRCERR ? "CRC " : "",
2255 rstat & FE_D1_ALGERR ? "ALG " : "",
2256 rstat & FE_D1_SRTPKT ? "LEN " : "",
2257 rstat );
2258#endif
2259 sc->sc_if.if_ierrors++;
2260 }
2261
2262 /*
2263 * MB86960 has a flag indicating "receive queue empty."
2264 * We just loop, checking the flag, to pull out all received
2265 * packets.
2266 *
2267 * We limit the number of iterations to avoid infinite-loop.
2268 * The upper bound is set to unrealistic high value.
2269 */
2270 for (i = 0; i < FE_MAX_RECV_COUNT * 2; i++) {
2271
2272 /* Stop the iteration if 86960 indicates no packets. */
2273 if ( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) break;
2274
2275 /*
2276 * Extract A receive status byte.
2277 * As our 86960 is in 16 bit bus access mode, we have to
2278 * use inw() to get the status byte. The significant
2279 * value is returned in lower 8 bits.
2280 */
2281 status = ( u_char )inw( sc->ioaddr[ FE_BMPR8 ] );
2282#if FE_DEBUG >= 4
2283 log( LOG_INFO, "fe%d: receive status = %04x\n",
2284 sc->sc_unit, status );
2285#endif
2286
2287 /*
2288 * Extract the packet length.
2289 * It is a sum of a header (14 bytes) and a payload.
2290 * CRC has been stripped off by the 86960.
2291 */
2292 len = inw( sc->ioaddr[ FE_BMPR8 ] );
2293
2294#if FE_DEBUG >= 1
2295 /*
2296 * If there was an error with the received packet, it
2297 * must be an indication of out-of-sync on receive
2298 * buffer, because we have programmed the 8696x to
2299 * to discard errored packets, even when the interface
2300 * is in promiscuous mode. We have to re-synchronize.
2301 */
2302 if (!(status & FE_RPH_GOOD)) {
2303 log(LOG_ERR,
2304 "fe%d: corrupted receive status byte (%02x)\n",
2305 sc->arpcom.ac_if.if_unit, status);
2306 sc->arpcom.ac_if.if_ierrors++;
2307 fe_emptybuffer( sc );
2308 break;
2309 }
2310#endif
2311
2312#if FE_DEBUG >= 1
2313 /*
2314 * MB86960 checks the packet length and drop big packet
2315 * before passing it to us. There are no chance we can
2316 * get big packets through it, even if they are actually
2317 * sent over a line. Hence, if the length exceeds
2318 * the specified limit, it means some serious failure,
2319 * such as out-of-sync on receive buffer management.
2320 *
2321 * Same for short packets, since we have programmed
2322 * 86960 to drop short packets.
2323 */
2324 if ( len > ETHER_MAX_LEN - ETHER_CRC_LEN
2325 || len < ETHER_MIN_LEN - ETHER_CRC_LEN ) {
2326 log( LOG_WARNING,
2327 "fe%d: received a %s packet? (%u bytes)\n",
2328 sc->sc_unit,
2329 len < ETHER_MIN_LEN - ETHER_CRC_LEN
2330 ? "partial" : "big",
2331 len );
2332 sc->sc_if.if_ierrors++;
2333 fe_emptybuffer( sc );
2334 break;
2335 }
2336#endif
2337
2338 /*
2339 * Go get a packet.
2340 */
2341 if ( fe_get_packet( sc, len ) < 0 ) {
2342
2343#if FE_DEBUG >= 2
2344 log( LOG_WARNING, "%s%d: out of mbuf;"
2345 " dropping a packet (%u bytes)\n",
2346 sc->sc_unit, len );
2347#endif
2348
2349 /* Skip a packet, updating statistics. */
2350 sc->sc_if.if_ierrors++;
2351 fe_droppacket( sc, len );
2352
2353 /*
2354 * Try extracting other packets, although they will
2355 * cause out-of-mbuf error again. This is required
2356 * to keep receiver interrupt comming.
2357 * (Earlier versions had a bug on this point.)
2358 */
2359 continue;
2360 }
2361
2362 /* Successfully received a packet. Update stat. */
2363 sc->sc_if.if_ipackets++;
2364 }
2365}
2366
2367/*
2368 * Ethernet interface interrupt processor
2369 */
2370static void
2371feintr ( int unit )
2372{
2373 struct fe_softc *sc = &fe_softc[unit];
2374 u_char tstat, rstat;
2375
2376 /*
2377 * Loop until there are no more new interrupt conditions.
2378 */
2379 for (;;) {
2380
2381#if FE_DEBUG >= 4
2382 fe_dump( LOG_INFO, sc, "intr()" );
2383#endif
2384
2385 /*
2386 * Get interrupt conditions, masking unneeded flags.
2387 */
2388 tstat = inb( sc->ioaddr[ FE_DLCR0 ] ) & FE_TMASK;
2389 rstat = inb( sc->ioaddr[ FE_DLCR1 ] ) & FE_RMASK;
2390
2391#if FE_DEBUG >= 1
2392 /* Test for a "dead-lock" condition. */
2393 if ((rstat & FE_D1_PKTRDY) == 0
2394 && (inb(sc->ioaddr[FE_DLCR5]) & FE_D5_BUFEMP) == 0
2395 && (inb(sc->ioaddr[FE_DLCR1]) & FE_D1_PKTRDY) == 0) {
2396 /*
2397 * PKTRDY is off, while receive buffer is not empty.
2398 * We did a double check to avoid a race condition...
2399 * So, we should have missed an interrupt.
2400 */
2401 log(LOG_WARNING,
2402 "fe%d: missed a receiver interrupt?\n",
2403 sc->arpcom.ac_if.if_unit);
2404 /* Simulate the missed interrupt condition. */
2405 rstat |= FE_D1_PKTRDY;
2406 }
2407#endif
2408
2409 /* Stop processing if there are no interrupts to handle. */
2410 if ( tstat == 0 && rstat == 0 ) break;
2411
2412 /*
2413 * Reset the conditions we are acknowledging.
2414 */
2415 outb( sc->ioaddr[ FE_DLCR0 ], tstat );
2416 outb( sc->ioaddr[ FE_DLCR1 ], rstat );
2417
2418 /*
2419 * Handle transmitter interrupts. Handle these first because
2420 * the receiver will reset the board under some conditions.
2421 */
2422 if ( tstat ) {
2423 fe_tint( sc, tstat );
2424 }
2425
2426 /*
2427 * Handle receiver interrupts
2428 */
--- 28 unchanged lines hidden (view full) ---
2457 * receiver interrupts. 86960 can raise a receiver
2458 * interrupt when the transmission buffer is full.
2459 */
2460 if ( ( sc->sc_if.if_flags & IFF_OACTIVE ) == 0 ) {
2461 fe_start( &sc->sc_if );
2462 }
2463
2464 }
2465}
2466
2467/*
2468 * Process an ioctl request. This code needs some work - it looks
2469 * pretty ugly.
2470 */
2471static int
2472fe_ioctl ( struct ifnet * ifp, u_long command, caddr_t data )
2473{
2474 struct fe_softc *sc = ifp->if_softc;
2475 int s, error = 0;
2476
2477#if FE_DEBUG >= 3
2478 log( LOG_INFO, "fe%d: ioctl(%x)\n", sc->sc_unit, command );
2479#endif
2480
2481 s = splimp();
2482
2483 switch (command) {
2484
2485 case SIOCSIFADDR:
2486 {
2487 struct ifaddr * ifa = ( struct ifaddr * )data;
2488
2489 sc->sc_if.if_flags |= IFF_UP;
2490
2491 switch (ifa->ifa_addr->sa_family) {
2492#ifdef INET
2493 case AF_INET:
2494 fe_init( sc->sc_unit ); /* before arp_ifinit */
2495 arp_ifinit( &sc->arpcom, ifa );
2496 break;
2497#endif
2498#ifdef IPX
2499 /*
2500 * XXX - This code is probably wrong
2501 */
2502 case AF_IPX:
2503 {
2504 register struct ipx_addr *ina
2505 = &(IA_SIPX(ifa)->sipx_addr);
2506
2507 if (ipx_nullhost(*ina))
2508 ina->x_host =
2509 *(union ipx_host *) (sc->sc_enaddr); else {
2510 bcopy((caddr_t) ina->x_host.c_host,
2511 (caddr_t) sc->sc_enaddr,
2512 sizeof(sc->sc_enaddr));
2513 }
2514
2515 /*
2516 * Set new address
2517 */
2518 fe_init(sc->sc_unit);
2519 break;
2520 }
2521#endif
2522#ifdef INET6
2523 case AF_INET6:
2524 /* IPV6 added by shin 96.2.6 */
2525 fe_init(sc->sc_unit);
2526 ndp6_ifinit(&sc->arpcom, ifa);
2527 break;
2528#endif
2529#ifdef NS
2530
2531 /*
2532 * XXX - This code is probably wrong
2533 */
2534 case AF_NS:
2535 {
2536 register struct ns_addr *ina
2537 = &(IA_SNS(ifa)->sns_addr);
2538
2539 if (ns_nullhost(*ina))
2540 ina->x_host =
2541 *(union ns_host *) (sc->sc_enaddr);
2542 else {
2543 bcopy((caddr_t) ina->x_host.c_host,
2544 (caddr_t) sc->sc_enaddr,
2545 sizeof(sc->sc_enaddr));
2546 }
2547
2548 /*
2549 * Set new address
2550 */
2551 fe_init(sc->sc_unit);
2552 break;
2553 }
2554#endif
2555 default:
2556 fe_init( sc->sc_unit );
2557 break;
2558 }
2559 break;
2560 }
2561
2562#ifdef SIOCGIFADDR
2563 case SIOCGIFADDR:
2564 {
2565 struct ifreq * ifr = ( struct ifreq * )data;
2566 struct sockaddr * sa = ( struct sockaddr * )&ifr->ifr_data;
2567
2568 bcopy((caddr_t)sc->sc_enaddr,
2569 (caddr_t)sa->sa_data, ETHER_ADDR_LEN);
2570 break;
2571 }
2572#endif
2573
2574#ifdef SIOCGIFPHYSADDR
2575 case SIOCGIFPHYSADDR:
2576 {
2577 struct ifreq * ifr = ( struct ifreq * )data;
2578
2579 bcopy((caddr_t)sc->sc_enaddr,
2580 (caddr_t)&ifr->ifr_data, ETHER_ADDR_LEN);
2581 break;
2582 }
2583#endif
2584
2585#ifdef notdef
2586#ifdef SIOCSIFPHYSADDR
2587 case SIOCSIFPHYSADDR:
2588 {
2589 /*
2590 * Set the physical (Ethernet) address of the interface.
2591 * When and by whom is this command used? FIXME.
2592 */
2593 struct ifreq * ifr = ( struct ifreq * )data;
2594
2595 bcopy((caddr_t)&ifr->ifr_data,
2596 (caddr_t)sc->sc_enaddr, ETHER_ADDR_LEN);
2597 fe_setlinkaddr( sc );
2598 break;
2599 }
2600#endif
2601#endif /* notdef */
2602
2603#ifdef SIOCSIFFLAGS
2604 case SIOCSIFFLAGS:
2605 {
2606 /*
2607 * Switch interface state between "running" and
2608 * "stopped", reflecting the UP flag.
2609 */
2610 if ( sc->sc_if.if_flags & IFF_UP ) {
2611 if ( ( sc->sc_if.if_flags & IFF_RUNNING ) == 0 ) {
2612 fe_init( sc->sc_unit );
2613 }
2614 } else {
2615 if ( ( sc->sc_if.if_flags & IFF_RUNNING ) != 0 ) {
2616 fe_stop( sc->sc_unit );
2617 }
2618 }
2619
2620 /*
2621 * Promiscuous and/or multicast flags may have changed,
2622 * so reprogram the multicast filter and/or receive mode.
2623 */
2624 fe_setmode( sc );
2625
2626#if FE_DEBUG >= 1
2627 /* "ifconfig fe0 debug" to print register dump. */
2628 if ( sc->sc_if.if_flags & IFF_DEBUG ) {
2629 fe_dump( LOG_DEBUG, sc, "SIOCSIFFLAGS(DEBUG)" );
2630 }
2631#endif
2632 break;
2633 }
2634#endif
2635
2636#ifdef SIOCADDMULTI
2637 case SIOCADDMULTI:
2638 case SIOCDELMULTI:
2639 /*
2640 * Multicast list has changed; set the hardware filter
2641 * accordingly.
2642 */
2643 fe_setmode( sc );
2644 error = 0;
2645 break;
2646#endif
2647
2648#ifdef SIOCSIFMTU
2649 case SIOCSIFMTU:
2650 {
2651 /*
2652 * Set the interface MTU.
2653 */
2654 struct ifreq * ifr = ( struct ifreq * )data;
2655
2656 if ( ifr->ifr_mtu > ETHERMTU ) {
2657 error = EINVAL;
2658 } else {
2659 sc->sc_if.if_mtu = ifr->ifr_mtu;
2660 }
2661 break;
2662 }
2663#endif
2664
2665 default:
2666 error = EINVAL;
2667 }
2668
2669 (void) splx(s);
2670 return (error);
2671}
2672
2673/*
2674 * Retrieve packet from receive buffer and send to the next level up via
--- 55 unchanged lines hidden (view full) ---
2730 m->m_pkthdr.len = len;
2731
2732 /* Set the length of this packet. */
2733 m->m_len = len;
2734
2735 /* The following silliness is to make NFS happy */
2736 m->m_data += NFS_MAGIC_OFFSET;
2737
2738 /* Get a packet. */
2739 insw( sc->ioaddr[ FE_BMPR8 ], m->m_data, ( len + 1 ) >> 1 );
2740
2741 /* Get (actually just point to) the header part. */
2742 eh = mtod( m, struct ether_header *);
2743
2744#define ETHER_ADDR_IS_MULTICAST(A) (*(char *)(A) & 1)
2745
2746#if NBPFILTER > 0
2747 /*
2748 * Check if there's a BPF listener on this interface.
2749 * If it is, hand off the raw packet to bpf.
2750 */
2751 if ( sc->sc_if.if_bpf ) {
2752 bpf_mtap( &sc->sc_if, m );
2753 }
2754#endif
2755
2756 /*
2757 * Make sure this packet is (or may be) directed to us.
2758 * That is, the packet is either unicasted to our address,
2759 * or broad/multi-casted. If any other packets are
2760 * received, it is an indication of an error -- probably
2761 * 86960 is in a wrong operation mode.
2762 * Promiscuous mode is an exception. Under the mode, all
2763 * packets on the media must be received. (We must have
--- 6 unchanged lines hidden (view full) ---
2770 /*
2771 * The packet was not for us. This is normal since
2772 * we are now in promiscuous mode. Just drop the packet.
2773 */
2774 m_freem( m );
2775 return 0;
2776 }
2777
2778#if FE_DEBUG >= 3
2779 if ( !ETHER_ADDR_IS_MULTICAST( eh->ether_dhost )
2780 && bcmp( eh->ether_dhost, sc->sc_enaddr, ETHER_ADDR_LEN ) != 0 ) {
2781 /*
2782 * This packet was not for us. We can't be in promiscuous
2783 * mode since the case was handled by above test.
2784 * We found an error (of this driver.)
2785 */
2786 log( LOG_WARNING,
2787 "fe%d: got an unwanted packet, dst = %6D\n",
2788 sc->sc_unit, eh->ether_dhost , ":" );
2789 m_freem( m );
2790 return 0;
2791 }
2792#endif
2793
2794 /* Strip off the Ethernet header. */
2795 m->m_pkthdr.len -= sizeof ( struct ether_header );
2796 m->m_len -= sizeof ( struct ether_header );
2797 m->m_data += sizeof ( struct ether_header );
2798
2799 /* Feed the packet to upper layer. */
2800 ether_input( &sc->sc_if, eh, m );
2801 return 0;
--- 15 unchanged lines hidden (view full) ---
2817 u_short length, len;
2818 struct mbuf *mp;
2819 u_char *data;
2820 u_short savebyte; /* WARNING: Architecture dependent! */
2821#define NO_PENDING_BYTE 0xFFFF
2822
2823 static u_char padding [ ETHER_MIN_LEN - ETHER_CRC_LEN - ETHER_HDR_LEN ];
2824
2825#if FE_DEBUG >= 1
2826 /* First, count up the total number of bytes to copy */
2827 length = 0;
2828 for ( mp = m; mp != NULL; mp = mp->m_next ) {
2829 length += mp->m_len;
2830 }
2831#else
2832 /* Just use the length value in the packet header. */
2833 length = m->m_pkthdr.len;
2834#endif
2835
2836#if FE_DEBUG >= 2
2837 /* Check if this matches the one in the packet header. */
2838 if ( length != m->m_pkthdr.len ) {
2839 log( LOG_WARNING, "fe%d: packet length mismatch? (%d/%d)\n",
2840 sc->sc_unit, length, m->m_pkthdr.len );
2841 }
2842#endif
2843
2844#if FE_DEBUG >= 1
2845 /*
2846 * Should never send big packets. If such a packet is passed,
2847 * it should be a bug of upper layer. We just ignore it.
2848 * ... Partial (too short) packets, neither.
2849 */
2850 if ( length < ETHER_HDR_LEN
2851 || length > ETHER_MAX_LEN - ETHER_CRC_LEN ) {
2852 log( LOG_ERR,
2853 "fe%d: got an out-of-spec packet (%u bytes) to send\n",
2854 sc->sc_unit, length );
2855 sc->sc_if.if_oerrors++;
2856 return;
2857 }
2858#endif
2859
2860 /*
2861 * Put the length word for this frame.
2862 * Does 86960 accept odd length? -- Yes.
2863 * Do we need to pad the length to minimum size by ourselves?
2864 * -- Generally yes. But for (or will be) the last
2865 * packet in the transmission buffer, we can skip the
2866 * padding process. It may gain performance slightly. FIXME.
2867 */
2868 outw( addr_bmpr8, max( length, ETHER_MIN_LEN - ETHER_CRC_LEN ) );
2869
2870 /*
2871 * Update buffer status now.
2872 * Truncate the length up to an even number, since we use outw().
2873 */
2874 length = ( length + 1 ) & ~1;
2875 sc->txb_free -= FE_DATA_LEN_LEN + max( length, ETHER_MIN_LEN - ETHER_CRC_LEN);
2876 sc->txb_count++;
2877
2878 /*
2879 * Transfer the data from mbuf chain to the transmission buffer.
2880 * MB86960 seems to require that data be transferred as words, and
2881 * only words. So that we require some extra code to patch
2882 * over odd-length mbufs.
2883 */
2884 savebyte = NO_PENDING_BYTE;
2885 for ( mp = m; mp != 0; mp = mp->m_next ) {
2886
2887 /* Ignore empty mbuf. */
2888 len = mp->m_len;
2889 if ( len == 0 ) continue;
2890
2891 /* Find the actual data to send. */
2892 data = mtod(mp, caddr_t);
2893
2894 /* Finish the last byte. */
2895 if ( savebyte != NO_PENDING_BYTE ) {
2896 outw( addr_bmpr8, savebyte | ( *data << 8 ) );
2897 data++;
2898 len--;
2899 savebyte = NO_PENDING_BYTE;
2900 }
2901
2902 /* output contiguous words */
2903 if (len > 1) {
2904 outsw( addr_bmpr8, data, len >> 1);
2905 data += len & ~1;
2906 len &= 1;
2907 }
2908
2909 /* Save a remaining byte, if there is one. */
2910 if ( len > 0 ) {
2911 savebyte = *data;
2912 }
2913 }
2914
2915 /* Spit the last byte, if the length is odd. */
2916 if ( savebyte != NO_PENDING_BYTE ) {
2917 outw( addr_bmpr8, savebyte );
2918 }
2919
2920 /* Pad to the Ethernet minimum length, if the packet is too short. */
2921 if ( length < ETHER_MIN_LEN - ETHER_CRC_LEN ) {
2922 outsw( addr_bmpr8, padding, ( ETHER_MIN_LEN - ETHER_CRC_LEN - length ) >> 1);
2923 }
2924}
2925
2926/*
2927 * Compute hash value for an Ethernet address
2928 */
2929static int
2930fe_hash ( u_char * ep )
--- 29 unchanged lines hidden (view full) ---
2960 struct ifmultiaddr *ifma;
2961
2962 filter = fe_filter_nothing;
2963 for (ifma = sc->arpcom.ac_if.if_multiaddrs.lh_first; ifma;
2964 ifma = ifma->ifma_link.le_next) {
2965 if (ifma->ifma_addr->sa_family != AF_LINK)
2966 continue;
2967 index = fe_hash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
2968#if FE_DEBUG >= 4
2969 log( LOG_INFO, "fe%d: hash(%6D) == %d\n",
2970 sc->sc_unit, enm->enm_addrlo , ":", index );
2971#endif
2972
2973 filter.data[index >> 3] |= 1 << (index & 7);
2974 }
2975 return ( filter );
2976}
2977
2978/*
--- 30 unchanged lines hidden (view full) ---
3009 * Promiscuous mode in FreeBSD 2 is used solely by
3010 * BPF, and BPF only listens to valid (no error) packets.
3011 * So, we ignore erroneous ones even in this mode.
3012 * (Older versions of fe driver mistook the point.)
3013 */
3014 outb( sc->ioaddr[ FE_DLCR5 ],
3015 sc->proto_dlcr5 | FE_D5_AFM0 | FE_D5_AFM1 );
3016 sc->filter_change = 0;
3017
3018#if FE_DEBUG >= 3
3019 log( LOG_INFO, "fe%d: promiscuous mode\n", sc->sc_unit );
3020#endif
3021 return;
3022 }
3023
3024 /*
3025 * Turn the chip to the normal (non-promiscuous) mode.
3026 */
3027 outb( sc->ioaddr[ FE_DLCR5 ], sc->proto_dlcr5 | FE_D5_AFM1 );
3028
3029 /*
3030 * Find the new multicast filter value.
3031 * I'm not sure we have to handle modes other than MULTICAST.
3032 * Who sets ALLMULTI? Who turns MULTICAST off? FIXME.
3033 */
3034 if ( flags & IFF_ALLMULTI ) {
3035 sc->filter = fe_filter_all;
3036 } else if ( flags & IFF_MULTICAST ) {
3037 sc->filter = fe_mcaf( sc );
3038 } else {
3039 sc->filter = fe_filter_nothing;
3040 }
3041 sc->filter_change = 1;
3042
3043#if FE_DEBUG >= 3
3044 log( LOG_INFO, "fe%d: address filter: [%8D]\n",
3045 sc->sc_unit, sc->filter.data, " " );
3046#endif
3047
3048 /*
3049 * We have to update the multicast filter in the 86960, A.S.A.P.
3050 *
3051 * Note that the DLC (Data Link Control unit, i.e. transmitter
3052 * and receiver) must be stopped when feeding the filter, and
3053 * DLC trashes all packets in both transmission and receive
3054 * buffers when stopped.
3055 *
3056 * ... Are the above sentences correct? I have to check the
3057 * manual of the MB86960A. FIXME.
3058 *
3059 * To reduce the packet loss, we delay the filter update
3060 * process until buffers are empty.
3061 */
3062 if ( sc->txb_sched == 0 && sc->txb_count == 0
3063 && !( inb( sc->ioaddr[ FE_DLCR1 ] ) & FE_D1_PKTRDY ) ) {
3064 /*
3065 * Buffers are (apparently) empty. Load
3066 * the new filter value into MARs now.
3067 */
3068 fe_loadmar(sc);
3069 } else {
3070 /*
3071 * Buffers are not empty. Mark that we have to update
3072 * the MARs. The new filter will be loaded by feintr()
3073 * later.
3074 */
3075#if FE_DEBUG >= 4
3076 log( LOG_INFO, "fe%d: filter change delayed\n", sc->sc_unit );
3077#endif
3078 }
3079}
3080
3081/*
3082 * Load a new multicast address filter into MARs.
3083 *
3084 * The caller must have splimp'ed before fe_loadmar.
3085 * This function starts the DLC upon return. So it can be called only
--- 21 unchanged lines hidden (view full) ---
3107
3108 /* Restart the DLC. */
3109 DELAY( 200 );
3110 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_ENABLE );
3111 DELAY( 200 );
3112
3113 /* We have just updated the filter. */
3114 sc->filter_change = 0;
3115
3116#if FE_DEBUG >= 3
3117 log( LOG_INFO, "fe%d: address filter changed\n", sc->sc_unit );
3118#endif
3119}
3120
3121#if FE_DEBUG >= 1
3122static void
3123fe_dump ( int level, struct fe_softc * sc, char * message )
3124{
3125 log( level, "fe%d: %s,"
3126 " DLCR = %02x %02x %02x %02x %02x %02x %02x %02x,"
3127 " BMPR = xx xx %02x %02x %02x %02x %02x %02x,"
3128 " asic = %02x %02x %02x %02x %02x %02x %02x %02x"
3129 " + %02x %02x %02x %02x %02x %02x %02x %02x\n",
3130 sc->sc_unit, message ? message : "registers",
3131 inb( sc->ioaddr[ FE_DLCR0 ] ), inb( sc->ioaddr[ FE_DLCR1 ] ),
3132 inb( sc->ioaddr[ FE_DLCR2 ] ), inb( sc->ioaddr[ FE_DLCR3 ] ),
3133 inb( sc->ioaddr[ FE_DLCR4 ] ), inb( sc->ioaddr[ FE_DLCR5 ] ),
3134 inb( sc->ioaddr[ FE_DLCR6 ] ), inb( sc->ioaddr[ FE_DLCR7 ] ),
3135 inb( sc->ioaddr[ FE_BMPR10 ] ), inb( sc->ioaddr[ FE_BMPR11 ] ),
3136 inb( sc->ioaddr[ FE_BMPR12 ] ), inb( sc->ioaddr[ FE_BMPR13 ] ),
3137 inb( sc->ioaddr[ FE_BMPR14 ] ), inb( sc->ioaddr[ FE_BMPR15 ] ),
3138 inb( sc->ioaddr[ 0x10 ] ), inb( sc->ioaddr[ 0x11 ] ),
3139 inb( sc->ioaddr[ 0x12 ] ), inb( sc->ioaddr[ 0x13 ] ),
3140 inb( sc->ioaddr[ 0x14 ] ), inb( sc->ioaddr[ 0x15 ] ),
3141 inb( sc->ioaddr[ 0x16 ] ), inb( sc->ioaddr[ 0x17 ] ),
3142 inb( sc->ioaddr[ 0x18 ] ), inb( sc->ioaddr[ 0x19 ] ),
3143 inb( sc->ioaddr[ 0x1A ] ), inb( sc->ioaddr[ 0x1B ] ),
3144 inb( sc->ioaddr[ 0x1C ] ), inb( sc->ioaddr[ 0x1D ] ),
3145 inb( sc->ioaddr[ 0x1E ] ), inb( sc->ioaddr[ 0x1F ] ) );
3146}
3147#endif