2 * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
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.
10 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND
11 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
12 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE
14 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
15 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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
26 * Device driver for Fujitsu MB86960A/MB86965A based Ethernet cards.
27 * To be used with FreeBSD 3.x
28 * Contributed by M. Sekiguchi. <seki@sysrap.cs.fujitsu.co.jp>
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
39 * This version also includes some alignments to support RE1000,
40 * C-NET(98)P2 and so on. These cards are not for AT-compatibles,
41 * but for NEC PC-98 bus -- a proprietary bus architecture available
42 * only in Japan. Confusingly, it is different from the Microsoft's
43 * PC98 architecture. :-{
44 * Further work for PC-98 version will be available as a part of
45 * FreeBSD(98) project.
47 * This software is a derivative work of if_ed.c version 1.56 by David
48 * Greenman available as a part of FreeBSD 2.0 RELEASE source distribution.
50 * The following lines are retained from the original if_ed.c:
52 * Copyright (C) 1993, David Greenman. This software may be used, modified,
53 * copied, distributed, and sold, in both source and binary form provided
54 * that the above copyright and these terms are retained. Under no
55 * circumstances is the author responsible for the proper functioning
56 * of this software, nor does the author assume any responsibility
57 * for damages incurred with its use.
62 * o To support ISA PnP auto configuration for FMV-183/184.
63 * o To reconsider mbuf usage.
64 * o To reconsider transmission buffer usage, including
65 * transmission buffer size (currently 4KB x 2) and pros-and-
66 * cons of multiple frame transmission.
67 * o To test IPX codes.
68 * o To test FreeBSD3.0-current.
69 * o To test BRIDGE codes.
77 #include <sys/param.h>
78 #include <sys/systm.h>
79 #include <sys/sockio.h>
81 #include <sys/socket.h>
83 #include <net/ethernet.h>
85 #include <net/if_dl.h>
86 #include <net/if_mib.h>
87 #include <net/if_media.h>
88 #include <net/if_types.h>
90 #include <netinet/in.h>
91 #include <netinet/if_ether.h>
96 #include <net/bridge.h>
99 #include <machine/clock.h>
101 #include <i386/isa/isa_device.h>
102 #include <i386/isa/icu.h>
105 /* XXX FIXME! doesn't work with new pccard code, must be converted! */
110 #include <sys/kernel.h>
111 #include <sys/select.h>
112 #include <sys/module.h>
113 #include <pccard/cardinfo.h>
114 #include <pccard/slot.h>
117 #include <i386/isa/ic/mb86960.h>
118 #include <i386/isa/if_fereg.h>
121 * Default settings for fe driver specific options.
122 * They can be set in config file by "options" statements.
126 * Transmit just one packet per a "send" command to 86960.
127 * This option is intended for performance test. An EXPERIMENTAL option.
129 #ifndef FE_SINGLE_TRANSMISSION
130 #define FE_SINGLE_TRANSMISSION 0
134 * Maximum loops when interrupt.
135 * This option prevents an infinite loop due to hardware failure.
136 * (Some laptops make an infinite loop after PC-Card is ejected.)
139 #define FE_MAX_LOOP 0x800
143 * If you define this option, 8-bit cards are also supported.
145 /*#define FE_8BIT_SUPPORT*/
148 * Device configuration flags.
151 /* DLCR6 settings. */
152 #define FE_FLAGS_DLCR6_VALUE 0x007F
154 /* Force DLCR6 override. */
155 #define FE_FLAGS_OVERRIDE_DLCR6 0x0080
157 /* Shouldn't these be defined somewhere else such as isa_device.h? */
158 #define NO_IOADDR (-1)
162 * Data type for a multicast address filter on 8696x.
164 struct fe_filter { u_char data [ FE_FILTER_LEN ]; };
167 * Special filter values.
169 static struct fe_filter const fe_filter_nothing = { FE_FILTER_NOTHING };
170 static struct fe_filter const fe_filter_all = { FE_FILTER_ALL };
172 /* How many registers does an fe-supported adapter have at maximum? */
173 #define MAXREGISTERS 32
176 * fe_softc: per line info and status
178 static struct fe_softc {
180 /* Used by "common" codes. */
181 struct arpcom arpcom; /* Ethernet common */
183 /* Used by config codes. */
185 /* Set by probe() and not modified in later phases. */
186 char const * typestr; /* printable name of the interface. */
187 u_short iobase; /* base I/O address of the adapter. */
188 u_short ioaddr [ MAXREGISTERS ]; /* I/O addresses of registers. */
189 u_short txb_size; /* size of TX buffer, in bytes */
190 u_char proto_dlcr4; /* DLCR4 prototype. */
191 u_char proto_dlcr5; /* DLCR5 prototype. */
192 u_char proto_dlcr6; /* DLCR6 prototype. */
193 u_char proto_dlcr7; /* DLCR7 prototype. */
194 u_char proto_bmpr13; /* BMPR13 prototype. */
195 u_char stability; /* How stable is this? */
196 u_short priv_info; /* info specific to a vendor/model. */
198 /* Vendor/model specific hooks. */
199 void (*init)(struct fe_softc *); /* Just before fe_init(). */
200 void (*stop)(struct fe_softc *); /* Just after fe_stop(). */
202 /* Transmission buffer management. */
203 u_short txb_free; /* free bytes in TX buffer */
204 u_char txb_count; /* number of packets in TX buffer */
205 u_char txb_sched; /* number of scheduled packets */
207 /* Excessive collision counter (see fe_tint() for details.) */
208 u_char tx_excolls; /* # of excessive collisions. */
210 /* Multicast address filter management. */
211 u_char filter_change; /* MARs must be changed ASAP. */
212 struct fe_filter filter;/* new filter value. */
214 /* Network management. */
215 struct ifmib_iso_8802_3 mibdata;
217 /* Media information. */
218 struct ifmedia media; /* used by if_media. */
219 u_short mbitmap; /* bitmap for supported media; see bit2media */
220 int defmedia; /* default media */
221 void (* msel)(struct fe_softc *); /* media selector. */
225 #define sc_if arpcom.ac_if
226 #define sc_unit arpcom.ac_if.if_unit
227 #define sc_enaddr arpcom.ac_enaddr
229 /* Standard driver entry points. These can be static. */
230 static int fe_probe ( struct isa_device * );
231 static int fe_attach ( struct isa_device * );
232 static void fe_init ( void * );
233 static ointhand2_t feintr;
234 static int fe_ioctl ( struct ifnet *, u_long, caddr_t );
235 static void fe_start ( struct ifnet * );
236 static void fe_watchdog ( struct ifnet * );
237 static int fe_medchange ( struct ifnet * );
238 static void fe_medstat ( struct ifnet *, struct ifmediareq * );
240 /* Local functions. Order of declaration is confused. FIXME. */
241 static int fe_probe_ssi ( struct isa_device *, struct fe_softc * );
242 static int fe_probe_jli ( struct isa_device *, struct fe_softc * );
243 static int fe_probe_fmv ( struct isa_device *, struct fe_softc * );
244 static int fe_probe_lnx ( struct isa_device *, struct fe_softc * );
245 static int fe_probe_gwy ( struct isa_device *, struct fe_softc * );
246 static int fe_probe_ubn ( struct isa_device *, struct fe_softc * );
248 static int fe_probe_re1000 ( struct isa_device *, struct fe_softc * );
249 static int fe_probe_cnet9ne( struct isa_device *, struct fe_softc * );
252 static int fe_probe_mbh ( struct isa_device *, struct fe_softc * );
253 static int fe_probe_tdk ( struct isa_device *, struct fe_softc * );
255 static int fe_get_packet ( struct fe_softc *, u_short );
256 static void fe_stop ( struct fe_softc * );
257 static void fe_tint ( struct fe_softc *, u_char );
258 static void fe_rint ( struct fe_softc *, u_char );
259 static void fe_xmit ( struct fe_softc * );
260 static void fe_write_mbufs ( struct fe_softc *, struct mbuf * );
261 static void fe_setmode ( struct fe_softc * );
262 static void fe_loadmar ( struct fe_softc * );
265 static void fe_emptybuffer ( struct fe_softc * );
268 /* Driver struct used in the config code. This must be public (external.) */
269 struct isa_driver fedriver =
274 1 /* It's safe to mark as "sensitive" */
278 * Fe driver specific constants which relate to 86960/86965.
281 /* Interrupt masks */
282 #define FE_TMASK ( FE_D2_COLL16 | FE_D2_TXDONE )
283 #define FE_RMASK ( FE_D3_OVRFLO | FE_D3_CRCERR \
284 | FE_D3_ALGERR | FE_D3_SRTPKT | FE_D3_PKTRDY )
286 /* Maximum number of iterations for a receive interrupt. */
287 #define FE_MAX_RECV_COUNT ( ( 65536 - 2048 * 2 ) / 64 )
289 * Maximum size of SRAM is 65536,
290 * minimum size of transmission buffer in fe is 2x2KB,
291 * and minimum amount of received packet including headers
292 * added by the chip is 64 bytes.
293 * Hence FE_MAX_RECV_COUNT is the upper limit for number
294 * of packets in the receive buffer.
298 * Miscellaneous definitions not directly related to hardware.
301 /* Flags for stability. */
302 #define UNSTABLE_IRQ 0x01 /* IRQ setting may be incorrect. */
303 #define UNSTABLE_MAC 0x02 /* Probed MAC address may be incorrect. */
304 #define UNSTABLE_TYPE 0x04 /* Probed vendor/model may be incorrect. */
306 /* The following line must be delete when "net/if_media.h" support it. */
308 #define IFM_10_FL /* 13 */ IFM_10_5
312 /* Mapping between media bitmap (in fe_softc.mbitmap) and ifm_media. */
313 static int const bit2media [] = {
315 IFM_HDX | IFM_ETHER | IFM_AUTO,
317 IFM_HDX | IFM_ETHER | IFM_MANUAL,
319 IFM_HDX | IFM_ETHER | IFM_10_T,
321 IFM_HDX | IFM_ETHER | IFM_10_2,
323 IFM_HDX | IFM_ETHER | IFM_10_5,
325 IFM_HDX | IFM_ETHER | IFM_10_FL,
327 IFM_FDX | IFM_ETHER | IFM_10_T,
328 /* More can be come here... */
332 /* Mapping between media bitmap (in fe_softc.mbitmap) and ifm_media. */
333 static int const bit2media [] = {
335 IFM_ETHER | IFM_AUTO,
337 IFM_ETHER | IFM_MANUAL,
339 IFM_ETHER | IFM_10_T,
341 IFM_ETHER | IFM_10_2,
343 IFM_ETHER | IFM_10_5,
345 IFM_ETHER | IFM_10_FL,
347 IFM_ETHER | IFM_10_T,
348 /* More can be come here... */
354 * Routines to access contiguous I/O ports.
358 inblk ( struct fe_softc * sc, int offs, u_char * mem, int len )
360 while ( --len >= 0 ) {
361 *mem++ = inb( sc->ioaddr[ offs++ ] );
366 outblk ( struct fe_softc * sc, int offs, u_char const * mem, int len )
368 while ( --len >= 0 ) {
369 outb( sc->ioaddr[ offs++ ], *mem++ );
376 * PC-Card (PCMCIA) specific code.
378 static int feinit (struct pccard_devinfo *);
379 static void feunload (struct pccard_devinfo *);
380 static int fe_card_intr (struct pccard_devinfo *);
382 PCCARD_MODULE(fe, feinit, feunload, fe_card_intr, 0, net_imask);
385 * Initialize the device - called from Slot manager.
388 feinit(struct pccard_devinfo *devi)
392 /* validate unit number. */
393 if (devi->isahd.id_unit >= NFE) return ENODEV;
395 /* Prepare for the device probe process. */
396 sc = &fe_softc[devi->isahd.id_unit];
397 sc->sc_unit = devi->isahd.id_unit;
398 sc->iobase = devi->isahd.id_iobase;
401 * When the feinit() is called, the devi->misc holds a
402 * six-byte value set by the pccard daemon. If the
403 * corresponding entry in /etc/pccard.conf has an "ether"
404 * keyword, the value is the Ethernet MAC address extracted
405 * from CIS area of the card. If the entry has no "ether"
406 * keyword, the daemon fills the field with binary zero,
407 * instead. We passes the value (either MAC address or zero)
408 * to model-specific sub-probe routines through sc->sc_enaddr
409 * (it actually is sc->sc_arpcom.ar_enaddr, BTW) so that the
410 * sub-probe routies can use that info.
412 bcopy(devi->misc, sc->sc_enaddr, ETHER_ADDR_LEN);
414 /* Probe for supported cards. */
415 if (fe_probe_mbh(&devi->isahd, sc) == 0
416 && fe_probe_tdk(&devi->isahd, sc) == 0) return ENXIO;
418 /* We've got a supported card. Attach it, then. */
419 if (fe_attach(&devi->isahd) == 0) return ENXIO;
425 * feunload - unload the driver and clear the table.
427 * This is usually called when the card is ejected, but
428 * can be caused by a modunload of a controller driver.
429 * The idea is to reset the driver's view of the device
430 * and ensure that any driver entry points such as
431 * read and write do not hang.
434 feunload(struct pccard_devinfo *devi)
436 struct fe_softc *sc = &fe_softc[devi->isahd.id_unit];
437 printf("fe%d: unload\n", sc->sc_unit);
439 if_down(&sc->arpcom.ac_if);
443 * fe_card_intr - Shared interrupt called from
444 * front end of PC-Card handler.
447 fe_card_intr(struct pccard_devinfo *devi)
449 feintr(devi->isahd.id_unit);
452 #endif /* NCARD > 0 */
456 * Hardware probe routines.
458 * In older versions of this driver, we provided an automatic I/O
459 * address detection. The features is, however, removed from this
460 * version, for simplicity. Any comments?
464 * Determine if the device is present at a specified I/O address. The
465 * main entry to the driver.
469 fe_probe (struct isa_device * dev)
471 struct fe_softc * sc;
475 if (dev->id_unit >= NFE) {
476 printf("fe%d: too large unit number for the current config\n",
482 /* Prepare for the softc struct. */
483 sc = &fe_softc[dev->id_unit];
484 sc->sc_unit = dev->id_unit;
485 sc->iobase = dev->id_iobase;
487 /* Probe for supported boards. */
490 if (!nports) nports = fe_probe_re1000(dev, sc);
491 if (!nports) nports = fe_probe_cnet9ne(dev, sc);
493 if (!nports) nports = fe_probe_ssi(dev, sc);
494 if (!nports) nports = fe_probe_jli(dev, sc);
495 if (!nports) nports = fe_probe_fmv(dev, sc);
496 if (!nports) nports = fe_probe_lnx(dev, sc);
497 if (!nports) nports = fe_probe_ubn(dev, sc);
498 if (!nports) nports = fe_probe_gwy(dev, sc);
500 /* We found supported board. */
505 * Check for specific bits in specific registers have specific values.
506 * A common utility function called from various sub-probe routines.
509 struct fe_simple_probe_struct
511 u_char port; /* Offset from the base I/O address. */
512 u_char mask; /* Bits to be checked. */
513 u_char bits; /* Values to be compared against. */
517 fe_simple_probe ( struct fe_softc const * sc,
518 struct fe_simple_probe_struct const * sp )
520 struct fe_simple_probe_struct const * p;
522 for ( p = sp; p->mask != 0; p++ ) {
524 unsigned a = sc->ioaddr[p->port];
525 printf("fe%d: Probing %02x (%04x): %02x (%02x, %02x): %s\n",
526 sc->sc_unit, p->port, a, inb(a), p->mask, p->bits,
527 (inb(a) & p->mask) == p->bits ? "OK" : "NG");
529 if ( ( inb( sc->ioaddr[ p->port ] ) & p->mask ) != p->bits )
537 /* Test if a given 6 byte value is a valid Ethernet station (MAC)
538 address. "Vendor" is an expected vendor code (first three bytes,)
539 or a zero when nothing expected. */
541 valid_Ether_p (u_char const * addr, unsigned vendor)
544 printf("fe?: validating %6D against %06x\n", addr, ":", vendor);
547 /* All zero is not allowed as a vendor code. */
548 if (addr[0] == 0 && addr[1] == 0 && addr[2] == 0) return 0;
552 /* Legal Ethernet address (stored in ROM) must have
553 its Group and Local bits cleared. */
554 if ((addr[0] & 0x03) != 0) return 0;
557 /* Same as above, but a local address is allowed in
559 if ((addr[0] & 0x01) != 0) return 0;
562 /* Make sure the vendor part matches if one is given. */
563 if ( addr[0] != ((vendor >> 16) & 0xFF)
564 || addr[1] != ((vendor >> 8) & 0xFF)
565 || addr[2] != ((vendor ) & 0xFF)) return 0;
569 /* Host part must not be all-zeros nor all-ones. */
570 if (addr[3] == 0xFF && addr[4] == 0xFF && addr[5] == 0xFF) return 0;
571 if (addr[3] == 0x00 && addr[4] == 0x00 && addr[5] == 0x00) return 0;
573 /* Given addr looks like an Ethernet address. */
577 /* Fill our softc struct with default value. */
579 fe_softc_defaults (struct fe_softc *sc)
583 /* Initialize I/O address re-mapping table for the standard
584 (contiguous) register layout. This routine doesn't use
585 ioaddr[], so the caller can safely override it after
586 calling fe_softc_defaults, if needed. */
587 for (i = 0; i < MAXREGISTERS; i++) sc->ioaddr[i] = sc->iobase + i;
589 /* Prepare for typical register prototypes. We assume a
590 "typical" board has <32KB> of <fast> SRAM connected with a
591 <byte-wide> data lines. */
592 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
594 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
595 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
596 sc->proto_dlcr7 = FE_D7_BYTSWP_LH;
597 sc->proto_bmpr13 = 0;
599 /* Assume the probe process (to be done later) is stable. */
602 /* A typical board needs no hooks. */
606 /* Assume the board has no software-controllable media selection. */
608 sc->defmedia = MB_HM;
612 /* Common error reporting routine used in probe routines for
613 "soft configured IRQ"-type boards. */
615 fe_irq_failure (char const *name, int unit, int irq, char const *list)
617 printf("fe%d: %s board is detected, but %s IRQ was given\n",
618 unit, name, (irq == NO_IRQ ? "no" : "invalid"));
620 printf("fe%d: specify an IRQ from %s in kernel config\n",
626 * Hardware (vendor) specific probe routines and hooks.
630 * Machine independent routines.
634 * Generic media selection scheme for MB86965 based boards.
637 fe_msel_965 (struct fe_softc *sc)
641 /* Find the appropriate bits for BMPR13 tranceiver control. */
642 switch (IFM_SUBTYPE(sc->media.ifm_media)) {
643 case IFM_AUTO: b13 = FE_B13_PORT_AUTO | FE_B13_TPTYPE_UTP; break;
644 case IFM_10_T: b13 = FE_B13_PORT_TP | FE_B13_TPTYPE_UTP; break;
645 default: b13 = FE_B13_PORT_AUI; break;
648 /* Write it into the register. It takes effect immediately. */
649 outb(sc->ioaddr[FE_BMPR13], sc->proto_bmpr13 | b13);
653 * Fujitsu MB86965 JLI mode support routines.
656 /* Datasheet for 86965 explicitly states that it only supports serial
657 * EEPROM with 16 words (32 bytes) capacity. (I.e., 93C06.) However,
658 * ones with 64 words (128 bytes) are available in the marked, namely
659 * 93C46, and are also fully compatible with 86965. It is known that
660 * some boards (e.g., ICL) actually have 93C46 on them and use extra
661 * storage to keep various config info. */
662 #define JLI_EEPROM_SIZE 128
665 * Routines to read all bytes from the config EEPROM through MB86965A.
666 * It is a MicroWire (3-wire) serial EEPROM with 6-bit address.
670 fe_strobe_eeprom_jli ( u_short bmpr16 )
673 * We must guarantee 1us (or more) interval to access slow
674 * EEPROMs. The following redundant code provides enough
675 * delay with ISA timing. (Even if the bus clock is "tuned.")
676 * Some modification will be needed on faster busses.
678 outb( bmpr16, FE_B16_SELECT );
679 outb( bmpr16, FE_B16_SELECT | FE_B16_CLOCK );
680 outb( bmpr16, FE_B16_SELECT | FE_B16_CLOCK );
681 outb( bmpr16, FE_B16_SELECT );
685 fe_read_eeprom_jli ( struct fe_softc * sc, u_char * data )
687 u_short bmpr16 = sc->ioaddr[ FE_BMPR16 ];
688 u_short bmpr17 = sc->ioaddr[ FE_BMPR17 ];
690 u_char save16, save17;
692 /* Save the current value of the EEPROM interface registers. */
693 save16 = inb(bmpr16);
694 save17 = inb(bmpr17);
696 /* Read bytes from EEPROM; two bytes per an iteration. */
697 for ( n = 0; n < JLI_EEPROM_SIZE / 2; n++ ) {
699 /* Reset the EEPROM interface. */
700 outb( bmpr16, 0x00 );
701 outb( bmpr17, 0x00 );
703 /* Start EEPROM access. */
704 outb( bmpr16, FE_B16_SELECT );
705 outb( bmpr17, FE_B17_DATA );
706 fe_strobe_eeprom_jli( bmpr16 );
708 /* Pass the iteration count as well as a READ command. */
710 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
711 outb( bmpr17, ( val & bit ) ? FE_B17_DATA : 0 );
712 fe_strobe_eeprom_jli( bmpr16 );
714 outb( bmpr17, 0x00 );
718 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
719 fe_strobe_eeprom_jli( bmpr16 );
720 if ( inb( bmpr17 ) & FE_B17_DATA ) {
726 /* Read one more byte. */
728 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
729 fe_strobe_eeprom_jli( bmpr16 );
730 if ( inb( bmpr17 ) & FE_B17_DATA ) {
738 /* Reset the EEPROM interface, again. */
739 outb( bmpr16, 0x00 );
740 outb( bmpr17, 0x00 );
742 /* Make sure to restore the original value of EEPROM interface
743 registers, since we are not yet sure we have MB86965A on
745 outb(bmpr17, save17);
746 outb(bmpr16, save16);
750 /* Report what we got. */
753 data -= JLI_EEPROM_SIZE;
754 for (i = 0; i < JLI_EEPROM_SIZE; i += 16) {
755 printf("fe%d: EEPROM(JLI):%3x: %16D\n",
756 sc->sc_unit, i, data + i, " ");
763 fe_init_jli (struct fe_softc * sc)
765 /* "Reset" by writing into a magic location. */
767 outb(sc->ioaddr[0x1E], inb(sc->ioaddr[0x1E]));
772 * SSi 78Q8377A support routines.
775 #define SSI_EEPROM_SIZE 512
783 * Routines to read all bytes from the config EEPROM through 78Q8377A.
784 * It is a MicroWire (3-wire) serial EEPROM with 8-bit address. (I.e.,
787 * As I don't have SSi manuals, (hmm, an old song again!) I'm not exactly
788 * sure the following code is correct... It is just stolen from the
789 * C-NET(98)P2 support routine in FreeBSD(98).
793 fe_read_eeprom_ssi (struct fe_softc *sc, u_char *data)
795 u_short bmpr12 = sc->ioaddr[FE_DLCR12];
798 u_char save6, save7, save12;
800 /* Save the current value for the DLCR registers we are about
802 save6 = inb(sc->ioaddr[FE_DLCR6]);
803 save7 = inb(sc->ioaddr[FE_DLCR7]);
805 /* Put the 78Q8377A into a state that we can access the EEPROM. */
806 outb(sc->ioaddr[FE_DLCR6],
807 FE_D6_BBW_WORD | FE_D6_SBW_WORD | FE_D6_DLC_DISABLE);
808 outb(sc->ioaddr[FE_DLCR7],
809 FE_D7_BYTSWP_LH | FE_D7_RBS_BMPR | FE_D7_RDYPNS | FE_D7_POWER_UP);
811 /* Save the current value for the BMPR12 register, too. */
812 save12 = inb(bmpr12);
814 /* Read bytes from EEPROM; two bytes per an iteration. */
815 for ( n = 0; n < SSI_EEPROM_SIZE / 2; n++ ) {
817 /* Start EEPROM access */
818 outb(bmpr12, SSI_EEP);
819 outb(bmpr12, SSI_EEP | SSI_CSL);
821 /* Send the following four bits to the EEPROM in the
822 specified order: a dummy bit, a start bit, and
823 command bits (10) for READ. */
824 outb(bmpr12, SSI_EEP | SSI_CSL );
825 outb(bmpr12, SSI_EEP | SSI_CSL | SSI_CLK ); /* 0 */
826 outb(bmpr12, SSI_EEP | SSI_CSL | SSI_DAT);
827 outb(bmpr12, SSI_EEP | SSI_CSL | SSI_CLK | SSI_DAT); /* 1 */
828 outb(bmpr12, SSI_EEP | SSI_CSL | SSI_DAT);
829 outb(bmpr12, SSI_EEP | SSI_CSL | SSI_CLK | SSI_DAT); /* 1 */
830 outb(bmpr12, SSI_EEP | SSI_CSL );
831 outb(bmpr12, SSI_EEP | SSI_CSL | SSI_CLK ); /* 0 */
833 /* Pass the iteration count to the chip. */
834 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
835 val = ( n & bit ) ? SSI_DAT : 0;
836 outb(bmpr12, SSI_EEP | SSI_CSL | val);
837 outb(bmpr12, SSI_EEP | SSI_CSL | SSI_CLK | val);
842 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
843 outb(bmpr12, SSI_EEP | SSI_CSL);
844 outb(bmpr12, SSI_EEP | SSI_CSL | SSI_CLK);
845 if (inb(bmpr12) & SSI_DIN) val |= bit;
849 /* Read one more byte. */
851 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
852 outb(bmpr12, SSI_EEP | SSI_CSL);
853 outb(bmpr12, SSI_EEP | SSI_CSL | SSI_CLK);
854 if (inb(bmpr12) & SSI_DIN) val |= bit;
858 outb(bmpr12, SSI_EEP);
861 /* Reset the EEPROM interface. (For now.) */
862 outb( bmpr12, 0x00 );
864 /* Restore the saved register values, for the case that we
865 didn't have 78Q8377A at the given address. */
866 outb(bmpr12, save12);
867 outb(sc->ioaddr[FE_DLCR7], save7);
868 outb(sc->ioaddr[FE_DLCR6], save6);
871 /* Report what we got. */
874 data -= SSI_EEPROM_SIZE;
875 for (i = 0; i < SSI_EEPROM_SIZE; i += 16) {
876 printf("fe%d: EEPROM(SSI):%3x: %16D\n",
877 sc->sc_unit, i, data + i, " ");
883 #define FE_SSI_EEP_IRQ 9 /* Irq ??? */
884 #define FE_SSI_EEP_ADDR 16 /* Station(MAC) address */
885 #define FE_SSI_EEP_DUPLEX 25 /* Duplex mode ??? */
888 * TDK/LANX boards support routines.
891 /* AX012/AX013 equips an X24C01 chip, which has 128 bytes of memory cells. */
892 #define LNX_EEPROM_SIZE 128
894 /* Bit assignments and command definitions for the serial EEPROM
895 interface register in LANX ASIC. */
896 #define LNX_SDA_HI 0x08 /* Drive SDA line high (logical 1.) */
897 #define LNX_SDA_LO 0x00 /* Drive SDA line low (logical 0.) */
898 #define LNX_SDA_FL 0x08 /* Float (don't drive) SDA line. */
899 #define LNX_SDA_IN 0x01 /* Mask for reading SDA line. */
900 #define LNX_CLK_HI 0x04 /* Drive clock line high (active.) */
901 #define LNX_CLK_LO 0x00 /* Drive clock line low (inactive.) */
903 /* It is assumed that the CLK line is low and SDA is high (float) upon entry. */
904 #define LNX_PH(D,K,N) \
905 ((LNX_SDA_##D | LNX_CLK_##K) << N)
906 #define LNX_CYCLE(D1,D2,D3,D4,K1,K2,K3,K4) \
907 (LNX_PH(D1,K1,0)|LNX_PH(D2,K2,8)|LNX_PH(D3,K3,16)|LNX_PH(D4,K4,24))
909 #define LNX_CYCLE_START LNX_CYCLE(HI,LO,LO,HI, HI,HI,LO,LO)
910 #define LNX_CYCLE_STOP LNX_CYCLE(LO,LO,HI,HI, LO,HI,HI,LO)
911 #define LNX_CYCLE_HI LNX_CYCLE(HI,HI,HI,HI, LO,HI,LO,LO)
912 #define LNX_CYCLE_LO LNX_CYCLE(LO,LO,LO,HI, LO,HI,LO,LO)
913 #define LNX_CYCLE_INIT LNX_CYCLE(LO,HI,HI,HI, LO,LO,LO,LO)
916 fe_eeprom_cycle_lnx (u_short reg20, u_long cycle)
918 outb(reg20, (cycle ) & 0xFF);
920 outb(reg20, (cycle >> 8) & 0xFF);
922 outb(reg20, (cycle >> 16) & 0xFF);
924 outb(reg20, (cycle >> 24) & 0xFF);
929 fe_eeprom_receive_lnx (u_short reg20)
933 outb(reg20, LNX_CLK_HI | LNX_SDA_FL);
936 outb(reg20, LNX_CLK_LO | LNX_SDA_FL);
938 return (dat & LNX_SDA_IN);
942 fe_read_eeprom_lnx (struct fe_softc *sc, u_char *data)
947 u_short reg20 = sc->ioaddr[0x14];
951 /* NOTE: DELAY() timing constants are approximately three
952 times longer (slower) than the required minimum. This is
953 to guarantee a reliable operation under some tough
954 conditions... Fortunately, this routine is only called
955 during the boot phase, so the speed is less important than
959 /* Reset the X24C01's internal state machine and put it into
960 the IDLE state. We usually don't need this, but *if*
961 someone (e.g., probe routine of other driver) write some
962 garbage into the register at 0x14, synchronization will be
963 lost, and the normal EEPROM access protocol won't work.
964 Moreover, as there are no easy way to reset, we need a
965 _manoeuvre_ here. (It even lacks a reset pin, so pushing
966 the RESET button on the PC doesn't help!) */
967 fe_eeprom_cycle_lnx(reg20, LNX_CYCLE_INIT);
968 for (i = 0; i < 10; i++) {
969 fe_eeprom_cycle_lnx(reg20, LNX_CYCLE_START);
971 fe_eeprom_cycle_lnx(reg20, LNX_CYCLE_STOP);
975 /* Issue a start condition. */
976 fe_eeprom_cycle_lnx(reg20, LNX_CYCLE_START);
978 /* Send seven bits of the starting address (zero, in this
979 case) and a command bit for READ. */
981 for (bit = 0x80; bit != 0x00; bit >>= 1) {
983 fe_eeprom_cycle_lnx(reg20, LNX_CYCLE_HI);
985 fe_eeprom_cycle_lnx(reg20, LNX_CYCLE_LO);
989 /* Receive an ACK bit. */
990 if (fe_eeprom_receive_lnx(reg20)) {
991 /* ACK was not received. EEPROM is not present (i.e.,
992 this board was not a TDK/LANX) or not working
995 printf("fe%d: no ACK received from EEPROM(LNX)\n",
998 /* Clear the given buffer to indicate we could not get
999 any info. and return. */
1000 bzero(data, LNX_EEPROM_SIZE);
1004 /* Read bytes from EEPROM. */
1005 for (n = 0; n < LNX_EEPROM_SIZE; n++) {
1007 /* Read a byte and store it into the buffer. */
1009 for (bit = 0x80; bit != 0x00; bit >>= 1) {
1010 if (fe_eeprom_receive_lnx(reg20)) val |= bit;
1014 /* Acknowledge if we have to read more. */
1015 if (n < LNX_EEPROM_SIZE - 1) {
1016 fe_eeprom_cycle_lnx(reg20, LNX_CYCLE_LO);
1020 /* Issue a STOP condition, de-activating the clock line.
1021 It will be safer to keep the clock line low than to leave
1023 fe_eeprom_cycle_lnx(reg20, LNX_CYCLE_STOP);
1026 outb(reg20, save20);
1029 /* Report what we got. */
1031 data -= LNX_EEPROM_SIZE;
1032 for (i = 0; i < LNX_EEPROM_SIZE; i += 16) {
1033 printf("fe%d: EEPROM(LNX):%3x: %16D\n",
1034 sc->sc_unit, i, data + i, " ");
1041 fe_init_lnx ( struct fe_softc * sc )
1043 /* Reset the 86960. Do we need this? FIXME. */
1044 outb(sc->ioaddr[0x12], 0x06);
1046 outb(sc->ioaddr[0x12], 0x07);
1049 /* Setup IRQ control register on the ASIC. */
1050 outb(sc->ioaddr[0x14], sc->priv_info);
1054 * Ungermann-Bass boards support routine.
1057 fe_init_ubn ( struct fe_softc * sc )
1059 /* Do we need this? FIXME. */
1060 outb(sc->ioaddr[FE_DLCR7],
1061 sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP);
1062 outb(sc->ioaddr[0x18], 0x00);
1065 /* Setup IRQ control register on the ASIC. */
1066 outb(sc->ioaddr[0x14], sc->priv_info);
1070 * Machine dependent probe routines.
1075 fe_probe_fmv ( struct isa_device * dev, struct fe_softc * sc )
1077 /* PC-98 has no board of this architechture. */
1081 /* ioaddr for RE1000/1000Plus - Very dirty! */
1082 static u_short ioaddr_re1000[MAXREGISTERS] = {
1083 0x0000, 0x0001, 0x0200, 0x0201, 0x0400, 0x0401, 0x0600, 0x0601,
1084 0x0800, 0x0801, 0x0a00, 0x0a01, 0x0c00, 0x0c01, 0x0e00, 0x0e01,
1085 0x1000, 0x1200, 0x1400, 0x1600, 0x1800, 0x1a00, 0x1c00, 0x1e00,
1086 0x1001, 0x1201, 0x1401, 0x1601, 0x1801, 0x1a01, 0x1c01, 0x1e01,
1090 * Probe and initialization for Allied-Telesis RE1000 series.
1093 fe_init_re1000 ( struct fe_softc * sc )
1095 /* Setup IRQ control register on the ASIC. */
1096 outb(sc->ioaddr[FE_RE1000_IRQCONF], sc->priv_info);
1100 fe_probe_re1000 ( struct isa_device * dev, struct fe_softc * sc )
1105 static struct fe_simple_probe_struct probe_table [] = {
1106 { FE_DLCR2, 0x58, 0x00 },
1107 { FE_DLCR4, 0x08, 0x00 },
1111 /* See if the specified I/O address is possible for RE1000. */
1112 /* [01]D[02468ACE] are allowed. */
1113 if ((sc->iobase & ~0x10E) != 0xD0) return 0;
1115 /* Setup an I/O address mapping table and some others. */
1116 fe_softc_defaults(sc);
1118 /* Re-map ioaddr for RE1000. */
1119 for (i = 0; i < MAXREGISTERS; i++)
1120 sc->ioaddr[i] = sc->iobase + ioaddr_re1000[i];
1122 /* See if the card is on its address. */
1123 if (!fe_simple_probe(sc, probe_table)) return 0;
1125 /* Get our station address from EEPROM. */
1126 inblk(sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN);
1128 /* Make sure it is Allied-Telesis's. */
1129 if (!valid_Ether_p(sc->sc_enaddr, 0x0000F4)) return 0;
1131 /* Calculate checksum. */
1132 sum = inb(sc->ioaddr[0x1e]);
1133 for (i = 0; i < ETHER_ADDR_LEN; i++) {
1134 sum ^= sc->sc_enaddr[i];
1136 if (sum != 0) return 0;
1138 /* Setup the board type. */
1139 sc->typestr = "RE1000";
1141 /* This looks like an RE1000 board. It requires an
1142 explicit IRQ setting in config. Make sure we have one,
1143 determining an appropriate value for the IRQ control
1145 switch (dev->id_irq) {
1146 case IRQ3: n = 0x10; break;
1147 case IRQ5: n = 0x20; break;
1148 case IRQ6: n = 0x40; break;
1149 case IRQ12: n = 0x80; break;
1151 fe_irq_failure(sc->typestr,
1152 sc->sc_unit, dev->id_irq, "3/5/6/12");
1155 sc->priv_info = inb(sc->ioaddr[FE_RE1000_IRQCONF]) & 0x0f | n;
1157 /* Setup hooks. We need a special initialization procedure. */
1158 sc->init = fe_init_re1000;
1160 /* The I/O address range is fragmented in the RE1000.
1161 It occupies 2*16 I/O addresses, by the way. */
1165 /* JLI sub-probe for Allied-Telesis RE1000Plus/ME1500 series. */
1166 static u_short const *
1167 fe_probe_jli_re1000p (struct fe_softc * sc, u_char const * eeprom)
1170 static u_short const irqmaps_re1000p [4] = { IRQ3, IRQ5, IRQ6, IRQ12 };
1172 /* Make sure the EEPROM contains Allied-Telesis bit pattern. */
1173 if (eeprom[1] != 0xFF) return NULL;
1174 for (i = 2; i < 8; i++) if (eeprom[i] != 0xFF) return NULL;
1175 for (i = 14; i < 24; i++) if (eeprom[i] != 0xFF) return NULL;
1177 /* Get our station address from EEPROM, and make sure the
1178 EEPROM contains Allied-Telesis's address. */
1179 bcopy(eeprom+8, sc->sc_enaddr, ETHER_ADDR_LEN);
1180 if (!valid_Ether_p(sc->sc_enaddr, 0x0000F4)) return NULL;
1182 /* I don't know any sub-model identification. */
1183 sc->typestr = "RE1000Plus/ME1500";
1185 /* Returns the IRQ table for the RE1000Plus. */
1186 return irqmaps_re1000p;
1190 * Probe for Allied-Telesis RE1000Plus/ME1500 series.
1193 fe_probe_jli (struct isa_device * dev, struct fe_softc * sc)
1197 u_char eeprom [JLI_EEPROM_SIZE];
1198 u_short const * irqmap;
1200 static u_short const baseaddr [8] =
1201 { 0x1D6, 0x1D8, 0x1DA, 0x1D4, 0x0D4, 0x0D2, 0x0D8, 0x0D0 };
1202 static struct fe_simple_probe_struct const probe_table [] = {
1203 /* { FE_DLCR1, 0x20, 0x00 }, Doesn't work. */
1204 { FE_DLCR2, 0x50, 0x00 },
1205 { FE_DLCR4, 0x08, 0x00 },
1206 /* { FE_DLCR5, 0x80, 0x00 }, Doesn't work. */
1208 { FE_BMPR16, 0x1B, 0x00 },
1209 { FE_BMPR17, 0x7F, 0x00 },
1215 * See if the specified address is possible for MB86965A JLI mode.
1217 for (i = 0; i < 8; i++) {
1218 if (baseaddr[i] == sc->iobase) break;
1220 if (i == 8) return 0;
1222 /* Fill the softc struct with reasonable default. */
1223 fe_softc_defaults(sc);
1225 /* Re-map ioaddr for RE1000Plus. */
1226 for (i = 0; i < MAXREGISTERS; i++)
1227 sc->ioaddr[i] = sc->iobase + ioaddr_re1000[i];
1230 * We should test if MB86965A is on the base address now.
1231 * Unfortunately, it is very hard to probe it reliably, since
1232 * we have no way to reset the chip under software control.
1233 * On cold boot, we could check the "signature" bit patterns
1234 * described in the Fujitsu document. On warm boot, however,
1235 * we can predict almost nothing about register values.
1237 if (!fe_simple_probe(sc, probe_table)) return 0;
1239 /* Check if our I/O address matches config info on 86965. */
1240 n = (inb(sc->ioaddr[FE_BMPR19]) & FE_B19_ADDR) >> FE_B19_ADDR_SHIFT;
1241 if (baseaddr[n] != sc->iobase) return 0;
1244 * We are now almost sure we have an MB86965 at the given
1245 * address. So, read EEPROM through it. We have to write
1246 * into LSI registers to read from EEPROM. I want to avoid it
1247 * at this stage, but I cannot test the presence of the chip
1248 * any further without reading EEPROM. FIXME.
1250 fe_read_eeprom_jli(sc, eeprom);
1252 /* Make sure that config info in EEPROM and 86965 agree. */
1253 if (eeprom[FE_EEPROM_CONF] != inb(sc->ioaddr[FE_BMPR19])) {
1257 /* Use 86965 media selection scheme, unless othewise
1258 specified. It is "AUTO always" and "select with BMPR13".
1259 This behaviour covers most of the 86965 based board (as
1260 minimum requirements.) It is backward compatible with
1261 previous versions, also. */
1262 sc->mbitmap = MB_HA;
1263 sc->defmedia = MB_HA;
1264 sc->msel = fe_msel_965;
1266 /* Perform board-specific probe. */
1267 if ((irqmap = fe_probe_jli_re1000p(sc, eeprom)) == NULL) return 0;
1269 /* Find the IRQ read from EEPROM. */
1270 n = (inb(sc->ioaddr[FE_BMPR19]) & FE_B19_IRQ) >> FE_B19_IRQ_SHIFT;
1273 /* Try to determine IRQ setting. */
1274 if (dev->id_irq == NO_IRQ && irq == NO_IRQ) {
1275 /* The device must be configured with an explicit IRQ. */
1276 printf("fe%d: IRQ auto-detection does not work\n",
1279 } else if (dev->id_irq == NO_IRQ && irq != NO_IRQ) {
1280 /* Just use the probed IRQ value. */
1282 } else if (dev->id_irq != NO_IRQ && irq == NO_IRQ) {
1283 /* No problem. Go ahead. */
1284 } else if (dev->id_irq == irq) {
1285 /* Good. Go ahead. */
1287 /* User must be warned in this case. */
1288 sc->stability |= UNSTABLE_IRQ;
1291 /* Setup a hook, which resets te 86965 when the driver is being
1292 initialized. This may solve a nasty bug. FIXME. */
1293 sc->init = fe_init_jli;
1295 /* The I/O address range is fragmented in the RE1000Plus.
1296 It occupies 2*16 I/O addresses, by the way. */
1301 * Probe and initialization for Contec C-NET(9N)E series.
1304 /* TODO: Should be in "if_fereg.h" */
1305 #define FE_CNET9NE_INTR 0x10 /* Interrupt Mask? */
1308 fe_init_cnet9ne ( struct fe_softc * sc )
1310 /* Enable interrupt? FIXME. */
1311 outb(sc->ioaddr[FE_CNET9NE_INTR], 0x10);
1315 fe_probe_cnet9ne ( struct isa_device * dev, struct fe_softc * sc )
1319 static struct fe_simple_probe_struct probe_table [] = {
1320 { FE_DLCR2, 0x58, 0x00 },
1321 { FE_DLCR4, 0x08, 0x00 },
1324 static u_short ioaddr[MAXREGISTERS - 16] = {
1325 /* 0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007, */
1326 /* 0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f, */
1327 0x400, 0x402, 0x404, 0x406, 0x408, 0x40a, 0x40c, 0x40e,
1328 0x401, 0x403, 0x405, 0x407, 0x409, 0x40b, 0x40d, 0x40f,
1331 /* See if the specified I/O address is possible for C-NET(9N)E. */
1332 if (sc->iobase != 0x73D0) return 0;
1334 /* Setup an I/O address mapping table and some others. */
1335 fe_softc_defaults(sc);
1337 /* Re-map ioaddr for C-NET(9N)E. */
1338 for (i = 16; i < MAXREGISTERS; i++)
1339 sc->ioaddr[i] = sc->iobase + ioaddr[i - 16];
1341 /* See if the card is on its address. */
1342 if (!fe_simple_probe(sc, probe_table)) return 0;
1344 /* Get our station address from EEPROM. */
1345 inblk(sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN);
1347 /* Make sure it is Contec's. */
1348 if (!valid_Ether_p(sc->sc_enaddr, 0x00804C)) return 0;
1350 /* Determine the card type. */
1351 if (sc->sc_enaddr[3] == 0x06) {
1352 sc->typestr = "C-NET(9N)C";
1354 /* We seems to need our own IDENT bits... FIXME. */
1355 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
1357 /* C-NET(9N)C requires an explicit IRQ to work. */
1358 if (dev->id_irq == NO_IRQ) {
1359 fe_irq_failure(sc->typestr, sc->sc_unit, NO_IRQ, NULL);
1363 sc->typestr = "C-NET(9N)E";
1365 /* C-NET(9N)E works only IRQ5. */
1366 if (dev->id_irq != IRQ5) {
1367 fe_irq_failure(sc->typestr,
1368 sc->sc_unit, dev->id_irq, "5");
1372 /* We need an init hook to initialize ASIC before we start. */
1373 sc->init = fe_init_cnet9ne;
1376 /* C-NET(9N)E has 64KB SRAM. */
1377 sc->proto_dlcr6 = FE_D6_BUFSIZ_64KB | FE_D6_TXBSIZ_2x4KB
1378 | FE_D6_BBW_WORD | FE_D6_SBW_WORD | FE_D6_SRAM;
1380 /* The I/O address range is fragmented in the C-NET(9N)E.
1381 This is the number of regs at iobase. */
1386 * Probe for Contec C-NET(98)P2 series.
1387 * (Logitec LAN-98TP/LAN-98T25P - parhaps)
1390 fe_probe_ssi (struct isa_device *dev, struct fe_softc *sc)
1392 u_char eeprom [SSI_EEPROM_SIZE];
1394 static struct fe_simple_probe_struct probe_table [] = {
1395 { FE_DLCR2, 0x08, 0x00 },
1396 { FE_DLCR4, 0x08, 0x00 },
1399 static u_short const irqmap[] = {
1400 /* INT0 INT1 INT2 */
1401 NO_IRQ, NO_IRQ, NO_IRQ, IRQ3 , NO_IRQ, IRQ5 , IRQ6 , NO_IRQ,
1402 NO_IRQ, IRQ9 , IRQ10 , NO_IRQ, IRQ12 , IRQ13 , NO_IRQ, NO_IRQ,
1403 /* INT3 INT41 INT5 INT6 */
1406 /* See if the specified I/O address is possible for 78Q8377A. */
1407 /* [0-D]3D0 are allowed. */
1408 if ((sc->iobase & 0xFFF) != 0x3D0) return 0; /* XXX */
1410 /* Fill the softc struct with default values. */
1411 fe_softc_defaults(sc);
1413 /* See if the card is on its address. */
1414 if (!fe_simple_probe(sc, probe_table)) return 0;
1416 /* We now have to read the config EEPROM. We should be very
1417 careful, since doing so destroys a register. (Remember, we
1418 are not yet sure we have a C-NET(98)P2 board here.) Don't
1419 remember to select BMPRs bofore reading EEPROM, since other
1420 register bank may be selected before the probe() is called. */
1421 fe_read_eeprom_ssi(sc, eeprom);
1423 /* Make sure the Ethernet (MAC) station address is of Contec's. */
1424 if (!valid_Ether_p(eeprom+FE_SSI_EEP_ADDR, 0x00804C)) return 0;
1425 bcopy(eeprom+FE_SSI_EEP_ADDR, sc->sc_enaddr, ETHER_ADDR_LEN);
1427 /* Setup the board type. */
1428 sc->typestr = "C-NET(98)P2";
1430 /* Get IRQ configuration from EEPROM. */
1431 dev->id_irq = irqmap[eeprom[FE_SSI_EEP_IRQ]];
1432 if (dev->id_irq == NO_IRQ) {
1433 fe_irq_failure(sc->typestr,
1434 sc->sc_unit, dev->id_irq, "3/5/6/9/10/12/13");
1438 /* Get Duplex-mode configuration from EEPROM. */
1439 sc->proto_dlcr4 |= (eeprom[FE_SSI_EEP_DUPLEX] & FE_D4_DSC);
1441 /* Fill softc struct accordingly. */
1442 sc->mbitmap = MB_HT;
1443 sc->defmedia = MB_HT;
1445 /* We have 16 registers. */
1450 * Probe for TDK LAC-98012/013/025/9N011 - parhaps.
1453 fe_probe_lnx (struct isa_device *dev, struct fe_softc *sc)
1455 #ifndef FE_8BIT_SUPPORT
1456 printf("fe%d: skip LAC-98012/013(only 16-bit cards are supported)\n",
1461 u_char eeprom [LNX_EEPROM_SIZE];
1463 static struct fe_simple_probe_struct probe_table [] = {
1464 { FE_DLCR2, 0x58, 0x00 },
1465 { FE_DLCR4, 0x08, 0x00 },
1469 /* See if the specified I/O address is possible for TDK/LANX boards. */
1470 /* 0D0, 4D0, 8D0, and CD0 are allowed. */
1471 if ((sc->iobase & ~0xC00) != 0xD0) return 0;
1473 /* Fill the softc struct with default values. */
1474 fe_softc_defaults(sc);
1476 /* Re-map ioaddr for LAC-98.
1477 * 0x000, 0x002, 0x004, 0x006, 0x008, 0x00a, 0x00c, 0x00e,
1478 * 0x100, 0x102, 0x104, 0x106, 0x108, 0x10a, 0x10c, 0x10e,
1479 * 0x200, 0x202, 0x204, 0x206, 0x208, 0x20a, 0x20c, 0x20e,
1480 * 0x300, 0x302, 0x304, 0x306, 0x308, 0x30a, 0x30c, 0x30e,
1482 for (i = 0; i < MAXREGISTERS; i++)
1483 sc->ioaddr[i] = sc->iobase + ((i & 7) << 1) + ((i & 0x18) << 5);
1485 /* See if the card is on its address. */
1486 if (!fe_simple_probe(sc, probe_table)) return 0;
1488 /* We now have to read the config EEPROM. We should be very
1489 careful, since doing so destroys a register. (Remember, we
1490 are not yet sure we have a LAC-98012/98013 board here.) */
1491 fe_read_eeprom_lnx(sc, eeprom);
1493 /* Make sure the Ethernet (MAC) station address is of TDK/LANX's. */
1494 if (!valid_Ether_p(eeprom, 0x008098)) return 0;
1495 bcopy(eeprom, sc->sc_enaddr, ETHER_ADDR_LEN);
1497 /* Setup the board type. */
1498 sc->typestr = "LAC-98012/98013";
1500 /* This looks like a TDK/LANX board. It requires an
1501 explicit IRQ setting in config. Make sure we have one,
1502 determining an appropriate value for the IRQ control
1504 switch (dev->id_irq) {
1505 case IRQ3 : sc->priv_info = 0x10 | LNX_CLK_LO | LNX_SDA_HI; break;
1506 case IRQ5 : sc->priv_info = 0x20 | LNX_CLK_LO | LNX_SDA_HI; break;
1507 case IRQ6 : sc->priv_info = 0x40 | LNX_CLK_LO | LNX_SDA_HI; break;
1508 case IRQ12: sc->priv_info = 0x80 | LNX_CLK_LO | LNX_SDA_HI; break;
1510 fe_irq_failure(sc->typestr,
1511 sc->sc_unit, dev->id_irq, "3/5/6/12");
1515 /* LAC-98's system bus width is 8-bit. */
1516 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x2KB
1517 | FE_D6_BBW_BYTE | FE_D6_SBW_BYTE | FE_D6_SRAM_150ns;
1519 /* Setup hooks. We need a special initialization procedure. */
1520 sc->init = fe_init_lnx;
1522 /* The I/O address range is fragmented in the LAC-98.
1523 It occupies 16*4 I/O addresses, by the way. */
1525 #endif /* FE_8BIT_SUPPORT */
1529 * Probe for Gateway Communications' old cards.
1530 * (both as Generic MB86960 probe routine)
1533 fe_probe_gwy ( struct isa_device * dev, struct fe_softc * sc )
1535 static struct fe_simple_probe_struct probe_table [] = {
1536 /* { FE_DLCR2, 0x70, 0x00 }, */
1537 { FE_DLCR2, 0x58, 0x00 },
1538 { FE_DLCR4, 0x08, 0x00 },
1542 /* I'm not sure which address is possible, so accepts any. FIXME. */
1544 /* Setup an I/O address mapping table and some others. */
1545 fe_softc_defaults(sc);
1547 /* Does we need to re-map ioaddr? FIXME. */
1549 /* See if the card is on its address. */
1550 if ( !fe_simple_probe( sc, probe_table ) ) return 0;
1552 /* Get our station address from EEPROM. */
1553 inblk( sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN );
1554 if (!valid_Ether_p(sc->sc_enaddr, 0x000000)) return 0;
1556 /* Determine the card type. */
1557 sc->typestr = "Generic MB86960 Ethernet";
1558 if (valid_Ether_p(sc->sc_enaddr, 0x000061))
1559 sc->typestr = "Gateway Ethernet (Fujitsu chipset)";
1561 /* Gateway's board requires an explicit IRQ to work, since it
1562 is not possible to probe the setting of jumpers. */
1563 if (dev->id_irq == NO_IRQ) {
1564 fe_irq_failure(sc->typestr, sc->sc_unit, NO_IRQ, NULL);
1568 /* We should change return value when re-mapping ioaddr. FIXME. */
1573 * Probe for Ungermann-Bass Access/PC N98C+(Model 85152).
1576 fe_probe_ubn (struct isa_device * dev, struct fe_softc * sc)
1580 static struct fe_simple_probe_struct const probe_table [] = {
1581 { FE_DLCR2, 0x58, 0x00 },
1582 { FE_DLCR4, 0x08, 0x00 },
1586 /* See if the specified I/O address is possible for Access/PC. */
1587 /* [01][048C]D0 are allowed. */
1588 if ((sc->iobase & ~0x1C00) != 0xD0) return 0;
1590 /* Setup an I/O address mapping table and some others. */
1591 fe_softc_defaults(sc);
1593 /* Re-map ioaddr for Access/PC N98C+.
1594 * 0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007,
1595 * 0x008, 0x009, 0x00a, 0x00b, 0x00c, 0x00d, 0x00e, 0x00f,
1596 * 0x200, 0x201, 0x202, 0x203, 0x204, 0x205, 0x206, 0x207,
1597 * 0x208, 0x209, 0x20a, 0x20b, 0x20c, 0x20d, 0x20e, 0x20f,
1599 for (i = 16; i < MAXREGISTERS; i++)
1600 sc->ioaddr[i] = sc->iobase + 0x200 - 16 + i;
1603 if (!fe_simple_probe(sc, probe_table)) return 0;
1605 /* NOTE: Access/NOTE N98 sometimes freeze when reading station
1606 address. In case of using it togather with C-NET(9N)C,
1607 this problem usually happens.
1608 Writing DLCR7 prevents freezing, but I don't know why. FIXME. */
1610 /* Save the current value for the DLCR7 register we are about
1612 save7 = inb(sc->ioaddr[FE_DLCR7]);
1613 outb(sc->ioaddr[FE_DLCR7],
1614 sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP);
1616 /* Get our station address form ID ROM and make sure it is UBN's. */
1617 inblk(sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN);
1618 if (!valid_Ether_p(sc->sc_enaddr, 0x00DD01)) goto fail_ubn;
1620 /* Calculate checksum. */
1621 sum = inb(sc->ioaddr[0x1e]);
1622 for (i = 0; i < ETHER_ADDR_LEN; i++) {
1623 sum ^= sc->sc_enaddr[i];
1625 if (sum != 0) goto fail_ubn;
1627 /* Setup the board type. */
1628 sc->typestr = "Access/PC";
1630 /* This looks like an AccessPC/N98C+ board. It requires an
1631 explicit IRQ setting in config. Make sure we have one,
1632 determining an appropriate value for the IRQ control
1634 switch (dev->id_irq) {
1635 case IRQ3: sc->priv_info = 0x01; break;
1636 case IRQ5: sc->priv_info = 0x02; break;
1637 case IRQ6: sc->priv_info = 0x04; break;
1638 case IRQ12: sc->priv_info = 0x08; break;
1640 fe_irq_failure(sc->typestr,
1641 sc->sc_unit, dev->id_irq, "3/5/6/12");
1645 /* Setup hooks. We need a special initialization procedure. */
1646 sc->init = fe_init_ubn;
1648 /* The I/O address range is fragmented in the Access/PC N98C+.
1649 This is the number of regs at iobase. */
1653 outb(sc->ioaddr[FE_DLCR7], save7);
1659 * Probe and initialization for Fujitsu FMV-180 series boards
1663 fe_init_fmv (struct fe_softc *sc)
1665 /* Initialize ASIC. */
1666 outb( sc->ioaddr[ FE_FMV3 ], 0 );
1667 outb( sc->ioaddr[ FE_FMV10 ], 0 );
1670 /* "Refresh" hardware configuration. FIXME. */
1671 outb( sc->ioaddr[ FE_FMV2 ], inb( sc->ioaddr[ FE_FMV2 ] ) );
1674 /* Turn the "master interrupt control" flag of ASIC on. */
1675 outb( sc->ioaddr[ FE_FMV3 ], FE_FMV3_IRQENB );
1679 fe_msel_fmv184 (struct fe_softc *sc)
1683 /* FMV-184 has a special "register" to switch between AUI/BNC.
1684 Determine the value to write into the register, based on the
1685 user-specified media selection. */
1686 port = (IFM_SUBTYPE(sc->media.ifm_media) == IFM_10_2) ? 0x00 : 0x01;
1688 /* The register is #5 on exntesion register bank...
1689 (Details of the register layout is not yet discovered.) */
1690 outb(sc->ioaddr[0x1B], 0x46); /* ??? */
1691 outb(sc->ioaddr[0x1E], 0x04); /* select ex-reg #4. */
1692 outb(sc->ioaddr[0x1F], 0xC8); /* ??? */
1693 outb(sc->ioaddr[0x1E], 0x05); /* select ex-reg #5. */
1694 outb(sc->ioaddr[0x1F], port); /* Switch the media. */
1695 outb(sc->ioaddr[0x1E], 0x04); /* select ex-reg #4. */
1696 outb(sc->ioaddr[0x1F], 0x00); /* ??? */
1697 outb(sc->ioaddr[0x1B], 0x00); /* ??? */
1699 /* Make sure to select "external tranceiver" on MB86964. */
1700 outb(sc->ioaddr[FE_BMPR13], sc->proto_bmpr13 | FE_B13_PORT_AUI);
1704 fe_probe_fmv ( struct isa_device * dev, struct fe_softc * sc )
1708 static u_short const irqmap [ 4 ] =
1709 { IRQ3, IRQ7, IRQ10, IRQ15 };
1711 static struct fe_simple_probe_struct const probe_table [] = {
1712 { FE_DLCR2, 0x71, 0x00 },
1713 { FE_DLCR4, 0x08, 0x00 },
1715 { FE_FMV0, 0x78, 0x50 }, /* ERRDY+PRRDY */
1716 { FE_FMV1, 0xB0, 0x00 }, /* FMV-183/4 has 0x48 bits. */
1717 { FE_FMV3, 0x7F, 0x00 },
1722 /* Board subtypes; it lists known FMV-180 variants. */
1729 static struct subtype const typelist [] = {
1730 { 0x0005, MB_HA|MB_HT|MB_H5, MB_HA, "FMV-181" },
1731 { 0x0105, MB_HA|MB_HT|MB_H5, MB_HA, "FMV-181A" },
1732 { 0x0003, MB_HM, MB_HM, "FMV-182" },
1733 { 0x0103, MB_HM, MB_HM, "FMV-182A" },
1734 { 0x0804, MB_HT, MB_HT, "FMV-183" },
1735 { 0x0C04, MB_HT, MB_HT, "FMV-183 (on-board)" },
1736 { 0x0803, MB_H2|MB_H5, MB_H2, "FMV-184" },
1737 { 0, MB_HA, MB_HA, "unknown FMV-180 (?)" },
1739 struct subtype const * type;
1741 /* Media indicator and "Hardware revision ID" */
1744 /* See if the specified address is possible for FMV-180
1745 series. 220, 240, 260, 280, 2A0, 2C0, 300, and 340 are
1746 allowed for all boards, and 200, 2E0, 320, 360, 380, 3A0,
1747 3C0, and 3E0 for PnP boards. */
1748 if ((sc->iobase & ~0x1E0) != 0x200) return 0;
1750 /* Setup an I/O address mapping table and some others. */
1751 fe_softc_defaults(sc);
1754 if (!fe_simple_probe(sc, probe_table)) return 0;
1756 /* Get our station address from EEPROM, and make sure it is
1758 inblk(sc, FE_FMV4, sc->sc_enaddr, ETHER_ADDR_LEN);
1759 if (!valid_Ether_p(sc->sc_enaddr, 0x00000E)) return 0;
1761 /* Find the supported media and "hardware revision" to know
1762 the model identification. */
1763 mcode = (inb(sc->ioaddr[FE_FMV0]) & FE_FMV0_MEDIA)
1764 | ((inb(sc->ioaddr[FE_FMV1]) & FE_FMV1_REV) << 8);
1766 /* Determine the card type. */
1767 for (type = typelist; type->mcode != 0; type++) {
1768 if (type->mcode == mcode) break;
1770 if (type->mcode == 0) {
1771 /* Unknown card type... Hope the driver works. */
1772 sc->stability |= UNSTABLE_TYPE;
1774 printf("fe%d: unknown config: %x-%x-%x-%x\n",
1776 inb(sc->ioaddr[FE_FMV0]),
1777 inb(sc->ioaddr[FE_FMV1]),
1778 inb(sc->ioaddr[FE_FMV2]),
1779 inb(sc->ioaddr[FE_FMV3]));
1783 /* Setup the board type and media information. */
1784 sc->typestr = type->str;
1785 sc->mbitmap = type->mbitmap;
1786 sc->defmedia = type->defmedia;
1787 sc->msel = fe_msel_965;
1789 if (type->mbitmap == (MB_H2 | MB_H5)) {
1790 /* FMV184 requires a special media selection procedure. */
1791 sc->msel = fe_msel_fmv184;
1795 * An FMV-180 has been probed.
1796 * Determine which IRQ to be used.
1798 * In this version, we give a priority to the kernel config file.
1799 * If the EEPROM and config don't match, say it to the user for
1802 n = ( inb( sc->ioaddr[ FE_FMV2 ] ) & FE_FMV2_IRS )
1803 >> FE_FMV2_IRS_SHIFT;
1804 if ( dev->id_irq == NO_IRQ ) {
1805 /* Just use the probed value. */
1806 dev->id_irq = irqmap[ n ];
1807 } else if ( dev->id_irq != irqmap[ n ] ) {
1809 sc->stability |= UNSTABLE_IRQ;
1812 /* We need an init hook to initialize ASIC before we start. */
1813 sc->init = fe_init_fmv;
1816 * That's all. FMV-180 occupies 32 I/O addresses, by the way.
1822 * Fujitsu MB86965 JLI mode probe routines.
1824 * 86965 has a special operating mode called JLI (mode 0), under which
1825 * the chip interfaces with ISA bus with a software-programmable
1826 * configuration. (The Fujitsu document calls the feature "Plug and
1827 * play," but it is not compatible with the ISA-PnP spec. designed by
1828 * Intel and Microsoft.) Ethernet cards designed to use JLI are
1829 * almost same, but there are two things which require board-specific
1830 * probe routines: EEPROM layout and IRQ pin connection.
1832 * JLI provides a handy way to access EEPROM which should contains the
1833 * chip configuration information (such as I/O port address) as well
1834 * as Ethernet station (MAC) address. The chip configuration info. is
1835 * stored on a fixed location. However, the station address can be
1836 * located anywhere in the EEPROM; it is up to the board designer to
1837 * determine the location. (The manual just says "somewhere in the
1838 * EEPROM.") The fe driver must somehow find out the correct
1841 * Another problem resides in the IRQ pin connection. JLI provides a
1842 * user to choose an IRQ from up to four predefined IRQs. The 86965
1843 * chip has a register to select one out of the four possibilities.
1844 * However, the selection is against the four IRQ pins on the chip.
1845 * (So-called IRQ-A, -B, -C and -D.) It is (again) up to the board
1846 * designer to determine which pin to connect which IRQ line on the
1847 * ISA bus. We need a vendor (or model, for some vendor) specific IRQ
1850 * The routine fe_probe_jli() provides all probe and initialization
1851 * processes which are common to all JLI implementation, and sub-probe
1852 * routines supply board-specific actions.
1854 * JLI sub-probe routine has the following template:
1856 * u_short const * func (struct fe_softc * sc, u_char const * eeprom);
1858 * where eeprom is a pointer to an array of 32 byte data read from the
1859 * config EEPROM on the board. It retuns an IRQ mapping table for the
1860 * board, when the corresponding implementation is detected. It
1861 * returns a NULL otherwise.
1863 * Primary purpose of the functin is to analize the config EEPROM,
1864 * determine if it matches with the pattern of that of supported card,
1865 * and extract necessary information from it. One of the information
1866 * expected to be extracted from EEPROM is the Ethernet station (MAC)
1867 * address, which must be set to the softc table of the interface by
1868 * the board-specific routine.
1871 /* JLI sub-probe for Allied-Telesyn/Allied-Telesis AT1700/RE2000 series. */
1872 static u_short const *
1873 fe_probe_jli_ati (struct fe_softc * sc, u_char const * eeprom)
1876 static u_short const irqmaps_ati [4][4] =
1878 { IRQ3, IRQ4, IRQ5, IRQ9 },
1879 { IRQ10, IRQ11, IRQ12, IRQ15 },
1880 { IRQ3, IRQ11, IRQ5, IRQ15 },
1881 { IRQ10, IRQ11, IRQ14, IRQ15 },
1884 /* Make sure the EEPROM contains Allied-Telesis/Allied-Telesyn
1886 if (eeprom[1] != 0x00) return NULL;
1887 for (i = 2; i < 8; i++) if (eeprom[i] != 0xFF) return NULL;
1888 for (i = 14; i < 24; i++) if (eeprom[i] != 0xFF) return NULL;
1890 /* Get our station address from EEPROM, and make sure the
1891 EEPROM contains ATI's address. */
1892 bcopy(eeprom+8, sc->sc_enaddr, ETHER_ADDR_LEN);
1893 if (!valid_Ether_p(sc->sc_enaddr, 0x0000F4)) return NULL;
1896 * The following model identification codes are stolen
1897 * from the NetBSD port of the fe driver. My reviewers
1898 * suggested minor revision.
1901 /* Determine the card type. */
1902 switch (eeprom[FE_ATI_EEP_MODEL]) {
1903 case FE_ATI_MODEL_AT1700T:
1904 sc->typestr = "AT-1700T/RE2001";
1905 sc->mbitmap = MB_HT;
1906 sc->defmedia = MB_HT;
1908 case FE_ATI_MODEL_AT1700BT:
1909 sc->typestr = "AT-1700BT/RE2003";
1910 sc->mbitmap = MB_HA | MB_HT | MB_H2;
1912 case FE_ATI_MODEL_AT1700FT:
1913 sc->typestr = "AT-1700FT/RE2009";
1914 sc->mbitmap = MB_HA | MB_HT | MB_HF;
1916 case FE_ATI_MODEL_AT1700AT:
1917 sc->typestr = "AT-1700AT/RE2005";
1918 sc->mbitmap = MB_HA | MB_HT | MB_H5;
1921 sc->typestr = "unknown AT-1700/RE2000";
1922 sc->stability |= UNSTABLE_TYPE | UNSTABLE_IRQ;
1927 /* Should we extract default media from eeprom? Linux driver
1928 for AT1700 does it, although previous releases of FreeBSD
1930 /* Determine the default media selection from the config
1931 EEPROM. The byte at offset EEP_MEDIA is believed to
1932 contain BMPR13 value to be set. We just ignore STP bit or
1933 squelch bit, since we don't support those. (It is
1935 switch (eeprom[FE_ATI_EEP_MEDIA] & FE_B13_PORT) {
1937 sc->defmedia = MB_HA;
1940 sc->defmedia = MB_HT;
1943 sc->defmedia = sc->mbitmap & (MB_H2|MB_H5|MB_H5); /*XXX*/
1946 sc->defmedia = MB_HA;
1950 /* Make sure the default media is compatible with the supported
1952 if ((sc->defmedia & sc->mbitmap) == 0) {
1953 if (sc->defmedia == MB_HA) {
1954 sc->defmedia = MB_HT;
1956 sc->defmedia = MB_HA;
1962 * Try to determine IRQ settings.
1963 * Different models use different ranges of IRQs.
1965 switch ((eeprom[FE_ATI_EEP_REVISION] & 0xf0)
1966 |(eeprom[FE_ATI_EEP_MAGIC] & 0x04)) {
1967 case 0x30: case 0x34: return irqmaps_ati[3];
1968 case 0x10: case 0x14:
1969 case 0x50: case 0x54: return irqmaps_ati[2];
1970 case 0x44: case 0x64: return irqmaps_ati[1];
1971 default: return irqmaps_ati[0];
1975 /* JLI sub-probe and msel hook for ICL Ethernet. */
1978 fe_msel_icl (struct fe_softc *sc)
1982 /* Switch between UTP and "external tranceiver" as always. */
1985 /* The board needs one more bit (on DLCR4) be set appropriately. */
1986 if (IFM_SUBTYPE(sc->media.ifm_media) == IFM_10_5) {
1987 d4 = sc->proto_dlcr4 | FE_D4_CNTRL;
1989 d4 = sc->proto_dlcr4 & ~FE_D4_CNTRL;
1991 outb(sc->ioaddr[FE_DLCR4], d4);
1994 static u_short const *
1995 fe_probe_jli_icl (struct fe_softc * sc, u_char const * eeprom)
2000 static u_short const irqmap_icl [4] = { IRQ9, IRQ10, IRQ5, IRQ15 };
2002 /* Make sure the EEPROM contains ICL bit pattern. */
2003 for (i = 24; i < 39; i++) {
2004 if (eeprom[i] != 0x20 && (eeprom[i] & 0xF0) != 0x30) return NULL;
2006 for (i = 112; i < 122; i++) {
2007 if (eeprom[i] != 0x20 && (eeprom[i] & 0xF0) != 0x30) return NULL;
2010 /* Make sure the EEPROM contains ICL's permanent station
2011 address. If it isn't, probably this board is not an
2013 if (!valid_Ether_p(eeprom+122, 0x00004B)) return NULL;
2015 /* Check if the "configured" Ethernet address in the EEPROM is
2016 valid. Use it if it is, or use the "permanent" address instead. */
2017 if (valid_Ether_p(eeprom+4, 0x020000)) {
2018 /* The configured address is valid. Use it. */
2019 bcopy(eeprom+4, sc->sc_enaddr, ETHER_ADDR_LEN);
2021 /* The configured address is invalid. Use permanent. */
2022 bcopy(eeprom+122, sc->sc_enaddr, ETHER_ADDR_LEN);
2025 /* Determine model and supported media. */
2026 switch (eeprom[0x5E]) {
2028 sc->typestr = "EtherTeam16i/COMBO";
2029 sc->mbitmap = MB_HA | MB_HT | MB_H5 | MB_H2;
2032 sc->typestr = "EtherTeam16i/TP";
2033 sc->mbitmap = MB_HT;
2036 sc->typestr = "EtherTeam16i/ErgoPro";
2037 sc->mbitmap = MB_HA | MB_HT | MB_H5;
2040 sc->typestr = "EtherTeam16i/DUO";
2041 sc->mbitmap = MB_HA | MB_HT | MB_H2;
2044 sc->typestr = "EtherTeam16i";
2045 sc->stability |= UNSTABLE_TYPE;
2047 printf("fe%d: unknown model code %02x for EtherTeam16i\n",
2048 sc->sc_unit, eeprom[0x5E]);
2053 /* I'm not sure the following msel hook is required by all
2054 models or COMBO only... FIXME. */
2055 sc->msel = fe_msel_icl;
2057 /* Make the configured media selection the default media. */
2058 switch (eeprom[0x28]) {
2059 case 0: defmedia = MB_HA; break;
2060 case 1: defmedia = MB_H5; break;
2061 case 2: defmedia = MB_HT; break;
2062 case 3: defmedia = MB_H2; break;
2065 printf("fe%d: unknown default media: %02x\n",
2066 sc->sc_unit, eeprom[0x28]);
2072 /* Make sure the default media is compatible with the
2074 if ((defmedia & sc->mbitmap) == 0) {
2076 printf("fe%d: default media adjusted\n", sc->sc_unit);
2078 defmedia = sc->mbitmap;
2081 /* Keep the determined default media. */
2082 sc->defmedia = defmedia;
2084 /* ICL has "fat" models. We have to program 86965 to properly
2085 reflect the hardware. */
2086 d6 = sc->proto_dlcr6 & ~(FE_D6_BUFSIZ | FE_D6_BBW);
2087 switch ((eeprom[0x61] << 8) | eeprom[0x60]) {
2088 case 0x2008: d6 |= FE_D6_BUFSIZ_32KB | FE_D6_BBW_BYTE; break;
2089 case 0x4010: d6 |= FE_D6_BUFSIZ_64KB | FE_D6_BBW_WORD; break;
2091 /* We can't support it, since we don't know which bits
2093 printf("fe%d: unknown SRAM config for ICL\n", sc->sc_unit);
2096 sc->proto_dlcr6 = d6;
2098 /* Returns the IRQ table for the ICL board. */
2102 /* JLI sub-probe for RATOC REX-5586/5587. */
2103 static u_short const *
2104 fe_probe_jli_rex (struct fe_softc * sc, u_char const * eeprom)
2107 static u_short const irqmap_rex [4] = { IRQ3, IRQ4, IRQ5, NO_IRQ };
2109 /* Make sure the EEPROM contains RATOC's config pattern. */
2110 if (eeprom[1] != eeprom[0]) return NULL;
2111 for (i = 8; i < 32; i++) if (eeprom[i] != 0xFF) return NULL;
2113 /* Get our station address from EEPROM. Note that RATOC
2114 stores it "byte-swapped" in each word. (I don't know why.)
2115 So, we just can't use bcopy().*/
2116 sc->sc_enaddr[0] = eeprom[3];
2117 sc->sc_enaddr[1] = eeprom[2];
2118 sc->sc_enaddr[2] = eeprom[5];
2119 sc->sc_enaddr[3] = eeprom[4];
2120 sc->sc_enaddr[4] = eeprom[7];
2121 sc->sc_enaddr[5] = eeprom[6];
2123 /* Make sure the EEPROM contains RATOC's station address. */
2124 if (!valid_Ether_p(sc->sc_enaddr, 0x00C0D0)) return NULL;
2126 /* I don't know any sub-model identification. */
2127 sc->typestr = "REX-5586/5587";
2129 /* Returns the IRQ for the RATOC board. */
2133 /* JLI sub-probe for Unknown board. */
2134 static u_short const *
2135 fe_probe_jli_unk (struct fe_softc * sc, u_char const * eeprom)
2138 static u_short const irqmap [4] = { NO_IRQ, NO_IRQ, NO_IRQ, NO_IRQ };
2140 /* The generic JLI probe considered this board has an 86965
2141 in JLI mode, but any other board-specific routines could
2142 not find the matching implementation. So, we "guess" the
2143 location by looking for a bit pattern which looks like a
2146 /* Determine how large the EEPROM is. */
2147 for (romsize = JLI_EEPROM_SIZE/2; romsize > 16; romsize >>= 1) {
2148 for (i = 0; i < romsize; i++) {
2149 if (eeprom[i] != eeprom[i+romsize]) break;
2151 if (i < romsize) break;
2155 /* Look for a bit pattern which looks like a MAC address. */
2156 for (n = 2; n <= romsize - ETHER_ADDR_LEN; n += 2) {
2157 if (!valid_Ether_p(eeprom + n, 0x000000)) continue;
2160 /* If no reasonable address was found, we can't go further. */
2161 if (n > romsize - ETHER_ADDR_LEN) return NULL;
2163 /* Extract our (guessed) station address. */
2164 bcopy(eeprom+n, sc->sc_enaddr, ETHER_ADDR_LEN);
2166 /* We are not sure what type of board it is... */
2167 sc->typestr = "(unknown JLI)";
2168 sc->stability |= UNSTABLE_TYPE | UNSTABLE_MAC;
2170 /* Returns the totally unknown IRQ mapping table. */
2175 * Probe and initialization for all JLI implementations.
2179 fe_probe_jli (struct isa_device * dev, struct fe_softc * sc)
2183 u_char eeprom [JLI_EEPROM_SIZE];
2184 u_short const * irqmap;
2186 static u_short const baseaddr [8] =
2187 { 0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300 };
2188 static struct fe_simple_probe_struct const probe_table [] = {
2189 { FE_DLCR1, 0x20, 0x00 },
2190 { FE_DLCR2, 0x50, 0x00 },
2191 { FE_DLCR4, 0x08, 0x00 },
2192 { FE_DLCR5, 0x80, 0x00 },
2194 { FE_BMPR16, 0x1B, 0x00 },
2195 { FE_BMPR17, 0x7F, 0x00 },
2201 * See if the specified address is possible for MB86965A JLI mode.
2203 for (i = 0; i < 8; i++) {
2204 if (baseaddr[i] == sc->iobase) break;
2206 if (i == 8) return 0;
2208 /* Fill the softc struct with reasonable default. */
2209 fe_softc_defaults(sc);
2212 * We should test if MB86965A is on the base address now.
2213 * Unfortunately, it is very hard to probe it reliably, since
2214 * we have no way to reset the chip under software control.
2215 * On cold boot, we could check the "signature" bit patterns
2216 * described in the Fujitsu document. On warm boot, however,
2217 * we can predict almost nothing about register values.
2219 if (!fe_simple_probe(sc, probe_table)) return 0;
2221 /* Check if our I/O address matches config info on 86965. */
2222 n = (inb(sc->ioaddr[FE_BMPR19]) & FE_B19_ADDR) >> FE_B19_ADDR_SHIFT;
2223 if (baseaddr[n] != sc->iobase) return 0;
2226 * We are now almost sure we have an MB86965 at the given
2227 * address. So, read EEPROM through it. We have to write
2228 * into LSI registers to read from EEPROM. I want to avoid it
2229 * at this stage, but I cannot test the presence of the chip
2230 * any further without reading EEPROM. FIXME.
2232 fe_read_eeprom_jli(sc, eeprom);
2234 /* Make sure that config info in EEPROM and 86965 agree. */
2235 if (eeprom[FE_EEPROM_CONF] != inb(sc->ioaddr[FE_BMPR19])) {
2239 /* Use 86965 media selection scheme, unless othewise
2240 specified. It is "AUTO always" and "select with BMPR13."
2241 This behaviour covers most of the 86965 based board (as
2242 minimum requirements.) It is backward compatible with
2243 previous versions, also. */
2244 sc->mbitmap = MB_HA;
2245 sc->defmedia = MB_HA;
2246 sc->msel = fe_msel_965;
2248 /* Perform board-specific probe, one by one. Note that the
2249 order of probe is important and should not be changed
2251 if ((irqmap = fe_probe_jli_ati(sc, eeprom)) == NULL
2252 && (irqmap = fe_probe_jli_rex(sc, eeprom)) == NULL
2253 && (irqmap = fe_probe_jli_icl(sc, eeprom)) == NULL
2254 && (irqmap = fe_probe_jli_unk(sc, eeprom)) == NULL) return 0;
2256 /* Find the IRQ read from EEPROM. */
2257 n = (inb(sc->ioaddr[FE_BMPR19]) & FE_B19_IRQ) >> FE_B19_IRQ_SHIFT;
2260 /* Try to determine IRQ setting. */
2261 if (dev->id_irq == NO_IRQ && irq == NO_IRQ) {
2262 /* The device must be configured with an explicit IRQ. */
2263 printf("fe%d: IRQ auto-detection does not work\n",
2266 } else if (dev->id_irq == NO_IRQ && irq != NO_IRQ) {
2267 /* Just use the probed IRQ value. */
2269 } else if (dev->id_irq != NO_IRQ && irq == NO_IRQ) {
2270 /* No problem. Go ahead. */
2271 } else if (dev->id_irq == irq) {
2272 /* Good. Go ahead. */
2274 /* User must be warned in this case. */
2275 sc->stability |= UNSTABLE_IRQ;
2278 /* Setup a hook, which resets te 86965 when the driver is being
2279 initialized. This may solve a nasty bug. FIXME. */
2280 sc->init = fe_init_jli;
2283 * That's all. 86965 JLI occupies 32 I/O addresses, by the way.
2288 /* Probe for TDK LAK-AX031, which is an SSi 78Q8377A based board. */
2291 fe_probe_ssi (struct isa_device *dev, struct fe_softc *sc)
2293 u_char eeprom [SSI_EEPROM_SIZE];
2295 static struct fe_simple_probe_struct probe_table [] = {
2296 { FE_DLCR2, 0x08, 0x00 },
2297 { FE_DLCR4, 0x08, 0x00 },
2301 /* See if the specified I/O address is possible for 78Q8377A. */
2302 if ((sc->iobase & ~0x3F0) != 0x000) return 0;
2304 /* Fill the softc struct with default values. */
2305 fe_softc_defaults(sc);
2307 /* See if the card is on its address. */
2308 if (!fe_simple_probe(sc, probe_table)) return 0;
2310 /* We now have to read the config EEPROM. We should be very
2311 careful, since doing so destroys a register. (Remember, we
2312 are not yet sure we have a LAK-AX031 board here.) Don't
2313 remember to select BMPRs bofore reading EEPROM, since other
2314 register bank may be selected before the probe() is called. */
2315 fe_read_eeprom_ssi(sc, eeprom);
2317 /* Make sure the Ethernet (MAC) station address is of TDK's. */
2318 if (!valid_Ether_p(eeprom+FE_SSI_EEP_ADDR, 0x008098)) return 0;
2319 bcopy(eeprom+FE_SSI_EEP_ADDR, sc->sc_enaddr, ETHER_ADDR_LEN);
2321 /* This looks like a TDK-AX031 board. It requires an explicit
2322 IRQ setting in config, since we currently don't know how we
2323 can find the IRQ value assigned by ISA PnP manager. */
2324 if (dev->id_irq == NO_IRQ) {
2325 fe_irq_failure("LAK-AX031", sc->sc_unit, dev->id_irq, NULL);
2329 /* Fill softc struct accordingly. */
2330 sc->typestr = "LAK-AX031";
2331 sc->mbitmap = MB_HT;
2332 sc->defmedia = MB_HT;
2334 /* We have 16 registers. */
2339 * Probe and initialization for TDK/LANX LAC-AX012/013 boards.
2342 fe_probe_lnx (struct isa_device *dev, struct fe_softc *sc)
2344 u_char eeprom [LNX_EEPROM_SIZE];
2346 static struct fe_simple_probe_struct probe_table [] = {
2347 { FE_DLCR2, 0x58, 0x00 },
2348 { FE_DLCR4, 0x08, 0x00 },
2352 /* See if the specified I/O address is possible for TDK/LANX boards. */
2353 /* 300, 320, 340, and 360 are allowed. */
2354 if ((sc->iobase & ~0x060) != 0x300) return 0;
2356 /* Fill the softc struct with default values. */
2357 fe_softc_defaults(sc);
2359 /* See if the card is on its address. */
2360 if (!fe_simple_probe(sc, probe_table)) return 0;
2362 /* We now have to read the config EEPROM. We should be very
2363 careful, since doing so destroys a register. (Remember, we
2364 are not yet sure we have a LAC-AX012/AX013 board here.) */
2365 fe_read_eeprom_lnx(sc, eeprom);
2367 /* Make sure the Ethernet (MAC) station address is of TDK/LANX's. */
2368 if (!valid_Ether_p(eeprom, 0x008098)) return 0;
2369 bcopy(eeprom, sc->sc_enaddr, ETHER_ADDR_LEN);
2371 /* This looks like a TDK/LANX board. It requires an
2372 explicit IRQ setting in config. Make sure we have one,
2373 determining an appropriate value for the IRQ control
2375 switch (dev->id_irq) {
2376 case IRQ3: sc->priv_info = 0x40 | LNX_CLK_LO | LNX_SDA_HI; break;
2377 case IRQ4: sc->priv_info = 0x20 | LNX_CLK_LO | LNX_SDA_HI; break;
2378 case IRQ5: sc->priv_info = 0x10 | LNX_CLK_LO | LNX_SDA_HI; break;
2379 case IRQ9: sc->priv_info = 0x80 | LNX_CLK_LO | LNX_SDA_HI; break;
2381 fe_irq_failure("LAC-AX012/AX013",
2382 sc->sc_unit, dev->id_irq, "3/4/5/9");
2386 /* Fill softc struct accordingly. */
2387 sc->typestr = "LAC-AX012/AX013";
2388 sc->init = fe_init_lnx;
2390 /* We have 32 registers. */
2395 * Probe and initialization for Gateway Communications' old cards.
2398 fe_probe_gwy ( struct isa_device * dev, struct fe_softc * sc )
2400 static struct fe_simple_probe_struct probe_table [] = {
2401 /* { FE_DLCR2, 0x70, 0x00 }, */
2402 { FE_DLCR2, 0x58, 0x00 },
2403 { FE_DLCR4, 0x08, 0x00 },
2407 /* See if the specified I/O address is possible for Gateway boards. */
2408 if ((sc->iobase & ~0x1E0) != 0x200) return 0;
2410 /* Setup an I/O address mapping table and some others. */
2411 fe_softc_defaults(sc);
2413 /* See if the card is on its address. */
2414 if ( !fe_simple_probe( sc, probe_table ) ) return 0;
2416 /* Get our station address from EEPROM. */
2417 inblk( sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN );
2419 /* Make sure it is Gateway Communication's. */
2420 if (!valid_Ether_p(sc->sc_enaddr, 0x000061)) return 0;
2422 /* Gateway's board requires an explicit IRQ to work, since it
2423 is not possible to probe the setting of jumpers. */
2424 if (dev->id_irq == NO_IRQ) {
2425 fe_irq_failure("Gateway Ethernet", sc->sc_unit, NO_IRQ, NULL);
2429 /* Fill softc struct accordingly. */
2430 sc->typestr = "Gateway Ethernet (Fujitsu chipset)";
2432 /* That's all. The card occupies 32 I/O addresses, as always. */
2436 /* Probe and initialization for Ungermann-Bass Network
2437 K.K. "Access/PC" boards. */
2439 fe_probe_ubn (struct isa_device * dev, struct fe_softc * sc)
2444 static struct fe_simple_probe_struct const probe_table [] = {
2445 { FE_DLCR2, 0x58, 0x00 },
2446 { FE_DLCR4, 0x08, 0x00 },
2450 /* See if the specified I/O address is possible for AccessPC/ISA. */
2451 if ((sc->iobase & ~0x0E0) != 0x300) return 0;
2453 /* Setup an I/O address mapping table and some others. */
2454 fe_softc_defaults(sc);
2457 if (!fe_simple_probe(sc, probe_table)) return 0;
2459 /* Get our station address form ID ROM and make sure it is UBN's. */
2460 inblk(sc, 0x18, sc->sc_enaddr, ETHER_ADDR_LEN);
2461 if (!valid_Ether_p(sc->sc_enaddr, 0x00DD01)) return 0;
2463 /* Calculate checksum. */
2464 sum = inb(sc->ioaddr[0x1e]);
2465 for (i = 0; i < ETHER_ADDR_LEN; i++) {
2466 sum ^= sc->sc_enaddr[i];
2468 if (sum != 0) return 0;
2470 /* This looks like an AccessPC/ISA board. It requires an
2471 explicit IRQ setting in config. Make sure we have one,
2472 determining an appropriate value for the IRQ control
2474 switch (dev->id_irq) {
2475 case IRQ3: sc->priv_info = 0x02; break;
2476 case IRQ4: sc->priv_info = 0x04; break;
2477 case IRQ5: sc->priv_info = 0x08; break;
2478 case IRQ10: sc->priv_info = 0x10; break;
2480 fe_irq_failure("Access/PC",
2481 sc->sc_unit, dev->id_irq, "3/4/5/10");
2485 /* Fill softc struct accordingly. */
2486 sc->typestr = "Access/PC";
2487 sc->init = fe_init_ubn;
2489 /* We have 32 registers. */
2496 * Probe and initialization for Fujitsu MBH10302 PCMCIA Ethernet interface.
2497 * Note that this is for 10302 only; MBH10304 is handled by fe_probe_tdk().
2501 fe_init_mbh ( struct fe_softc * sc )
2503 /* Minimal initialization of 86960. */
2505 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
2508 /* Disable all interrupts. */
2509 outb( sc->ioaddr[ FE_DLCR2 ], 0 );
2510 outb( sc->ioaddr[ FE_DLCR3 ], 0 );
2512 /* Enable master interrupt flag. */
2513 outb( sc->ioaddr[ FE_MBH0 ], FE_MBH0_MAGIC | FE_MBH0_INTR_ENABLE );
2517 fe_probe_mbh ( struct isa_device * dev, struct fe_softc * sc )
2519 static struct fe_simple_probe_struct probe_table [] = {
2520 { FE_DLCR2, 0x58, 0x00 },
2521 { FE_DLCR4, 0x08, 0x00 },
2522 { FE_DLCR6, 0xFF, 0xB6 },
2527 /* We need an explicit IRQ. */
2528 if (dev->id_irq == NO_IRQ) return 0;
2531 /* Ethernet MAC address should *NOT* have been given by pccardd,
2532 if this is a true MBH10302; i.e., Ethernet address must be
2533 "all-zero" upon entry. */
2534 if (sc->sc_enaddr[0] || sc->sc_enaddr[1] || sc->sc_enaddr[2] ||
2535 sc->sc_enaddr[3] || sc->sc_enaddr[4] || sc->sc_enaddr[5]) {
2539 /* Fill the softc struct with default values. */
2540 fe_softc_defaults(sc);
2543 * See if MBH10302 is on its address.
2544 * I'm not sure the following probe code works. FIXME.
2546 if ( !fe_simple_probe( sc, probe_table ) ) return 0;
2548 /* Get our station address from EEPROM. */
2549 inblk( sc, FE_MBH10, sc->sc_enaddr, ETHER_ADDR_LEN );
2551 /* Make sure we got a valid station address. */
2552 if (!valid_Ether_p(sc->sc_enaddr, 0)) return 0;
2554 /* Determine the card type. */
2555 sc->typestr = "MBH10302 (PCMCIA)";
2557 /* We seems to need our own IDENT bits... FIXME. */
2558 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
2560 /* Setup hooks. We need a special initialization procedure. */
2561 sc->init = fe_init_mbh;
2564 * That's all. MBH10302 occupies 32 I/O addresses, by the way.
2570 * Probe and initialization for TDK/CONTEC PCMCIA Ethernet interface.
2571 * by MASUI Kenji <masui@cs.titech.ac.jp>
2573 * (Contec uses TDK Ethenet chip -- hosokawa)
2575 * This version of fe_probe_tdk has been rewrote to handle
2576 * *generic* PC card implementation of Fujitsu MB8696x family. The
2577 * name _tdk is just for a historical reason. :-)
2580 fe_probe_tdk ( struct isa_device * dev, struct fe_softc * sc )
2582 static struct fe_simple_probe_struct probe_table [] = {
2583 { FE_DLCR2, 0x50, 0x00 },
2584 { FE_DLCR4, 0x08, 0x00 },
2585 /* { FE_DLCR5, 0x80, 0x00 }, Does not work well. */
2589 if ( dev->id_irq == NO_IRQ ) {
2593 fe_softc_defaults(sc);
2596 * See if C-NET(PC)C is on its address.
2599 if ( !fe_simple_probe( sc, probe_table ) ) return 0;
2601 /* Determine the card type. */
2602 sc->typestr = "Generic MB8696x/78Q837x Ethernet (PCMCIA)";
2605 * Initialize constants in the per-line structure.
2608 /* Make sure we got a valid station address. */
2609 if (!valid_Ether_p(sc->sc_enaddr, 0)) return 0;
2612 * That's all. C-NET(PC)C occupies 16 I/O addresses.
2613 * XXX: Are there any card with 32 I/O addresses? FIXME.
2617 #endif /* NCARD > 0 */
2620 * Install interface into kernel networking data structures
2623 fe_attach ( struct isa_device * dev )
2626 static int already_ifattach[NFE];
2628 struct fe_softc *sc = &fe_softc[dev->id_unit];
2631 dev->id_ointr = feintr;
2634 * Initialize ifnet structure
2636 sc->sc_if.if_softc = sc;
2637 sc->sc_if.if_unit = sc->sc_unit;
2638 sc->sc_if.if_name = "fe";
2639 sc->sc_if.if_output = ether_output;
2640 sc->sc_if.if_start = fe_start;
2641 sc->sc_if.if_ioctl = fe_ioctl;
2642 sc->sc_if.if_watchdog = fe_watchdog;
2643 sc->sc_if.if_init = fe_init;
2644 sc->sc_if.if_linkmib = &sc->mibdata;
2645 sc->sc_if.if_linkmiblen = sizeof (sc->mibdata);
2647 #if 0 /* I'm not sure... */
2648 sc->mibdata.dot3Compliance = DOT3COMPLIANCE_COLLS;
2652 * Set fixed interface flags.
2654 sc->sc_if.if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
2658 * Set maximum size of output queue, if it has not been set.
2659 * It is done here as this driver may be started after the
2660 * system initialization (i.e., the interface is PCMCIA.)
2662 * I'm not sure this is really necessary, but, even if it is,
2663 * it should be done somewhere else, e.g., in if_attach(),
2664 * since it must be a common workaround for all network drivers.
2667 if ( sc->sc_if.if_snd.ifq_maxlen == 0 ) {
2668 sc->sc_if.if_snd.ifq_maxlen = ifqmaxlen;
2672 #if FE_SINGLE_TRANSMISSION
2673 /* Override txb config to allocate minimum. */
2674 sc->proto_dlcr6 &= ~FE_D6_TXBSIZ
2675 sc->proto_dlcr6 |= FE_D6_TXBSIZ_2x2KB;
2678 /* Modify hardware config if it is requested. */
2679 if ( dev->id_flags & FE_FLAGS_OVERRIDE_DLCR6 ) {
2680 sc->proto_dlcr6 = dev->id_flags & FE_FLAGS_DLCR6_VALUE;
2683 /* Find TX buffer size, based on the hardware dependent proto. */
2684 switch ( sc->proto_dlcr6 & FE_D6_TXBSIZ ) {
2685 case FE_D6_TXBSIZ_2x2KB: sc->txb_size = 2048; break;
2686 case FE_D6_TXBSIZ_2x4KB: sc->txb_size = 4096; break;
2687 case FE_D6_TXBSIZ_2x8KB: sc->txb_size = 8192; break;
2689 /* Oops, we can't work with single buffer configuration. */
2691 printf("fe%d: strange TXBSIZ config; fixing\n",
2694 sc->proto_dlcr6 &= ~FE_D6_TXBSIZ;
2695 sc->proto_dlcr6 |= FE_D6_TXBSIZ_2x2KB;
2696 sc->txb_size = 2048;
2700 /* Initialize the if_media interface. */
2701 ifmedia_init(&sc->media, 0, fe_medchange, fe_medstat );
2702 for (b = 0; bit2media[b] != 0; b++) {
2703 if (sc->mbitmap & (1 << b)) {
2704 ifmedia_add(&sc->media, bit2media[b], 0, NULL);
2707 for (b = 0; bit2media[b] != 0; b++) {
2708 if (sc->defmedia & (1 << b)) {
2709 ifmedia_set(&sc->media, bit2media[b]);
2713 #if 0 /* Turned off; this is called later, when the interface UPs. */
2717 /* Attach and stop the interface. */
2719 if (already_ifattach[dev->id_unit] != 1) {
2720 if_attach(&sc->sc_if);
2721 already_ifattach[dev->id_unit] = 1;
2724 if_attach(&sc->sc_if);
2727 ether_ifattach(&sc->sc_if);
2729 /* Print additional info when attached. */
2730 printf("fe%d: address %6D, type %s%s\n", sc->sc_unit,
2731 sc->sc_enaddr, ":" , sc->typestr,
2732 (sc->proto_dlcr4 & FE_D4_DSC) ? ", full duplex" : "");
2734 int buf, txb, bbw, sbw, ram;
2736 buf = txb = bbw = sbw = ram = -1;
2737 switch ( sc->proto_dlcr6 & FE_D6_BUFSIZ ) {
2738 case FE_D6_BUFSIZ_8KB: buf = 8; break;
2739 case FE_D6_BUFSIZ_16KB: buf = 16; break;
2740 case FE_D6_BUFSIZ_32KB: buf = 32; break;
2741 case FE_D6_BUFSIZ_64KB: buf = 64; break;
2743 switch ( sc->proto_dlcr6 & FE_D6_TXBSIZ ) {
2744 case FE_D6_TXBSIZ_2x2KB: txb = 2; break;
2745 case FE_D6_TXBSIZ_2x4KB: txb = 4; break;
2746 case FE_D6_TXBSIZ_2x8KB: txb = 8; break;
2748 switch ( sc->proto_dlcr6 & FE_D6_BBW ) {
2749 case FE_D6_BBW_BYTE: bbw = 8; break;
2750 case FE_D6_BBW_WORD: bbw = 16; break;
2752 switch ( sc->proto_dlcr6 & FE_D6_SBW ) {
2753 case FE_D6_SBW_BYTE: sbw = 8; break;
2754 case FE_D6_SBW_WORD: sbw = 16; break;
2756 switch ( sc->proto_dlcr6 & FE_D6_SRAM ) {
2757 case FE_D6_SRAM_100ns: ram = 100; break;
2758 case FE_D6_SRAM_150ns: ram = 150; break;
2760 printf("fe%d: SRAM %dKB %dbit %dns, TXB %dKBx2, %dbit I/O\n",
2761 sc->sc_unit, buf, bbw, ram, txb, sbw);
2763 if (sc->stability & UNSTABLE_IRQ) {
2764 printf("fe%d: warning: IRQ number may be incorrect\n",
2767 if (sc->stability & UNSTABLE_MAC) {
2768 printf("fe%d: warning: above MAC address may be incorrect\n",
2771 if (sc->stability & UNSTABLE_TYPE) {
2772 printf("fe%d: warning: hardware type was not validated\n",
2776 /* If BPF is in the kernel, call the attach for it. */
2777 bpfattach(&sc->sc_if, DLT_EN10MB, sizeof(struct ether_header));
2782 * Reset interface, after some (hardware) trouble is deteced.
2785 fe_reset (struct fe_softc *sc)
2787 /* Record how many packets are lost by this accident. */
2788 sc->sc_if.if_oerrors += sc->txb_sched + sc->txb_count;
2789 sc->mibdata.dot3StatsInternalMacTransmitErrors++;
2791 /* Put the interface into known initial state. */
2793 if (sc->sc_if.if_flags & IFF_UP) fe_init(sc);
2797 * Stop everything on the interface.
2799 * All buffered packets, both transmitting and receiving,
2800 * if any, will be lost by stopping the interface.
2803 fe_stop (struct fe_softc *sc)
2809 /* Disable interrupts. */
2810 outb( sc->ioaddr[ FE_DLCR2 ], 0x00 );
2811 outb( sc->ioaddr[ FE_DLCR3 ], 0x00 );
2813 /* Stop interface hardware. */
2815 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
2818 /* Clear all interrupt status. */
2819 outb( sc->ioaddr[ FE_DLCR0 ], 0xFF );
2820 outb( sc->ioaddr[ FE_DLCR1 ], 0xFF );
2822 /* Put the chip in stand-by mode. */
2824 outb( sc->ioaddr[ FE_DLCR7 ], sc->proto_dlcr7 | FE_D7_POWER_DOWN );
2827 /* Reset transmitter variables and interface flags. */
2828 sc->sc_if.if_flags &= ~( IFF_OACTIVE | IFF_RUNNING );
2829 sc->sc_if.if_timer = 0;
2830 sc->txb_free = sc->txb_size;
2834 /* MAR loading can be delayed. */
2835 sc->filter_change = 0;
2837 /* Call a device-specific hook. */
2838 if ( sc->stop ) sc->stop( sc );
2844 * Device timeout/watchdog routine. Entered if the device neglects to
2845 * generate an interrupt after a transmit has been started on it.
2848 fe_watchdog ( struct ifnet *ifp )
2850 struct fe_softc *sc = (struct fe_softc *)ifp;
2852 /* A "debug" message. */
2853 printf("fe%d: transmission timeout (%d+%d)%s\n",
2854 ifp->if_unit, sc->txb_sched, sc->txb_count,
2855 (ifp->if_flags & IFF_UP) ? "" : " when down");
2856 if ( sc->sc_if.if_opackets == 0 && sc->sc_if.if_ipackets == 0 ) {
2857 printf("fe%d: wrong IRQ setting in config?\n", ifp->if_unit);
2863 * Initialize device.
2866 fe_init (void * xsc)
2868 struct fe_softc *sc = xsc;
2871 /* We need an address. */
2872 if (TAILQ_EMPTY(&sc->sc_if.if_addrhead)) { /* XXX unlikely */
2874 printf("fe%d: init() without any address\n", sc->sc_unit);
2879 /* Start initializing 86960. */
2882 /* Call a hook before we start initializing the chip. */
2883 if ( sc->init ) sc->init( sc );
2886 * Make sure to disable the chip, also.
2887 * This may also help re-programming the chip after
2888 * hot insertion of PCMCIAs.
2891 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
2894 /* Power up the chip and select register bank for DLCRs. */
2896 outb( sc->ioaddr[ FE_DLCR7 ],
2897 sc->proto_dlcr7 | FE_D7_RBS_DLCR | FE_D7_POWER_UP );
2900 /* Feed the station address. */
2901 outblk( sc, FE_DLCR8, sc->sc_enaddr, ETHER_ADDR_LEN );
2903 /* Clear multicast address filter to receive nothing. */
2904 outb( sc->ioaddr[ FE_DLCR7 ],
2905 sc->proto_dlcr7 | FE_D7_RBS_MAR | FE_D7_POWER_UP );
2906 outblk( sc, FE_MAR8, fe_filter_nothing.data, FE_FILTER_LEN );
2908 /* Select the BMPR bank for runtime register access. */
2909 outb( sc->ioaddr[ FE_DLCR7 ],
2910 sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP );
2912 /* Initialize registers. */
2913 outb( sc->ioaddr[ FE_DLCR0 ], 0xFF ); /* Clear all bits. */
2914 outb( sc->ioaddr[ FE_DLCR1 ], 0xFF ); /* ditto. */
2915 outb( sc->ioaddr[ FE_DLCR2 ], 0x00 );
2916 outb( sc->ioaddr[ FE_DLCR3 ], 0x00 );
2917 outb( sc->ioaddr[ FE_DLCR4 ], sc->proto_dlcr4 );
2918 outb( sc->ioaddr[ FE_DLCR5 ], sc->proto_dlcr5 );
2919 outb( sc->ioaddr[ FE_BMPR10 ], 0x00 );
2920 outb( sc->ioaddr[ FE_BMPR11 ], FE_B11_CTRL_SKIP | FE_B11_MODE1 );
2921 outb( sc->ioaddr[ FE_BMPR12 ], 0x00 );
2922 outb( sc->ioaddr[ FE_BMPR13 ], sc->proto_bmpr13 );
2923 outb( sc->ioaddr[ FE_BMPR14 ], 0x00 );
2924 outb( sc->ioaddr[ FE_BMPR15 ], 0x00 );
2926 /* Enable interrupts. */
2927 outb( sc->ioaddr[ FE_DLCR2 ], FE_TMASK );
2928 outb( sc->ioaddr[ FE_DLCR3 ], FE_RMASK );
2930 /* Select requested media, just before enabling DLC. */
2931 if (sc->msel) sc->msel(sc);
2933 /* Enable transmitter and receiver. */
2935 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_ENABLE );
2940 * Make sure to empty the receive buffer.
2942 * This may be redundant, but *if* the receive buffer were full
2943 * at this point, then the driver would hang. I have experienced
2944 * some strange hang-up just after UP. I hope the following
2945 * code solve the problem.
2947 * I have changed the order of hardware initialization.
2948 * I think the receive buffer cannot have any packets at this
2949 * point in this version. The following code *must* be
2950 * redundant now. FIXME.
2952 * I've heard a rumore that on some PC card implementation of
2953 * 8696x, the receive buffer can have some data at this point.
2954 * The following message helps discovering the fact. FIXME.
2956 if ( !( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) ) {
2957 printf("fe%d: receive buffer has some data after reset\n",
2959 fe_emptybuffer( sc );
2962 /* Do we need this here? Actually, no. I must be paranoia. */
2963 outb( sc->ioaddr[ FE_DLCR0 ], 0xFF ); /* Clear all bits. */
2964 outb( sc->ioaddr[ FE_DLCR1 ], 0xFF ); /* ditto. */
2967 /* Set 'running' flag, because we are now running. */
2968 sc->sc_if.if_flags |= IFF_RUNNING;
2971 * At this point, the interface is running properly,
2972 * except that it receives *no* packets. we then call
2973 * fe_setmode() to tell the chip what packets to be
2974 * received, based on the if_flags and multicast group
2975 * list. It completes the initialization process.
2980 /* ...and attempt to start output queued packets. */
2981 /* TURNED OFF, because the semi-auto media prober wants to UP
2982 the interface keeping it idle. The upper layer will soon
2983 start the interface anyway, and there are no significant
2985 fe_start( &sc->sc_if );
2992 * This routine actually starts the transmission on the interface
2995 fe_xmit ( struct fe_softc * sc )
2998 * Set a timer just in case we never hear from the board again.
2999 * We use longer timeout for multiple packet transmission.
3000 * I'm not sure this timer value is appropriate. FIXME.
3002 sc->sc_if.if_timer = 1 + sc->txb_count;
3004 /* Update txb variables. */
3005 sc->txb_sched = sc->txb_count;
3007 sc->txb_free = sc->txb_size;
3010 /* Start transmitter, passing packets in TX buffer. */
3011 outb( sc->ioaddr[ FE_BMPR10 ], sc->txb_sched | FE_B10_START );
3015 * Start output on interface.
3016 * We make two assumptions here:
3017 * 1) that the current priority is set to splimp _before_ this code
3018 * is called *and* is returned to the appropriate priority after
3020 * 2) that the IFF_OACTIVE flag is checked before this code is called
3021 * (i.e. that the output part of the interface is idle)
3024 fe_start ( struct ifnet *ifp )
3026 struct fe_softc *sc = ifp->if_softc;
3030 /* Just a sanity check. */
3031 if ( ( sc->txb_count == 0 ) != ( sc->txb_free == sc->txb_size ) ) {
3033 * Txb_count and txb_free co-works to manage the
3034 * transmission buffer. Txb_count keeps track of the
3035 * used potion of the buffer, while txb_free does unused
3036 * potion. So, as long as the driver runs properly,
3037 * txb_count is zero if and only if txb_free is same
3038 * as txb_size (which represents whole buffer.)
3040 printf("fe%d: inconsistent txb variables (%d, %d)\n",
3041 sc->sc_unit, sc->txb_count, sc->txb_free);
3043 * So, what should I do, then?
3045 * We now know txb_count and txb_free contradicts. We
3046 * cannot, however, tell which is wrong. More
3047 * over, we cannot peek 86960 transmission buffer or
3048 * reset the transmission buffer. (In fact, we can
3049 * reset the entire interface. I don't want to do it.)
3051 * If txb_count is incorrect, leaving it as-is will cause
3052 * sending of garbage after next interrupt. We have to
3053 * avoid it. Hence, we reset the txb_count here. If
3054 * txb_free was incorrect, resetting txb_count just loose
3055 * some packets. We can live with it.
3062 * First, see if there are buffered packets and an idle
3063 * transmitter - should never happen at this point.
3065 if ( ( sc->txb_count > 0 ) && ( sc->txb_sched == 0 ) ) {
3066 printf("fe%d: transmitter idle with %d buffered packets\n",
3067 sc->sc_unit, sc->txb_count);
3072 * Stop accepting more transmission packets temporarily, when
3073 * a filter change request is delayed. Updating the MARs on
3074 * 86960 flushes the transmission buffer, so it is delayed
3075 * until all buffered transmission packets have been sent
3078 if ( sc->filter_change ) {
3080 * Filter change request is delayed only when the DLC is
3081 * working. DLC soon raise an interrupt after finishing
3084 goto indicate_active;
3090 * See if there is room to put another packet in the buffer.
3091 * We *could* do better job by peeking the send queue to
3092 * know the length of the next packet. Current version just
3093 * tests against the worst case (i.e., longest packet). FIXME.
3095 * When adding the packet-peek feature, don't forget adding a
3096 * test on txb_count against QUEUEING_MAX.
3097 * There is a little chance the packet count exceeds
3098 * the limit. Assume transmission buffer is 8KB (2x8KB
3099 * configuration) and an application sends a bunch of small
3100 * (i.e., minimum packet sized) packets rapidly. An 8KB
3101 * buffer can hold 130 blocks of 62 bytes long...
3104 < ETHER_MAX_LEN - ETHER_CRC_LEN + FE_DATA_LEN_LEN ) {
3106 goto indicate_active;
3109 #if FE_SINGLE_TRANSMISSION
3110 if ( sc->txb_count > 0 ) {
3111 /* Just one packet per a transmission buffer. */
3112 goto indicate_active;
3117 * Get the next mbuf chain for a packet to send.
3119 IF_DEQUEUE( &sc->sc_if.if_snd, m );
3121 /* No more packets to send. */
3122 goto indicate_inactive;
3126 * Copy the mbuf chain into the transmission buffer.
3127 * txb_* variables are updated as necessary.
3129 fe_write_mbufs( sc, m );
3131 /* Start transmitter if it's idle. */
3132 if ( ( sc->txb_count > 0 ) && ( sc->txb_sched == 0 ) ) {
3137 * Tap off here if there is a bpf listener,
3138 * and the device is *not* in promiscuous mode.
3139 * (86960 receives self-generated packets if
3140 * and only if it is in "receive everything"
3143 if ( sc->sc_if.if_bpf
3144 && !( sc->sc_if.if_flags & IFF_PROMISC ) ) {
3145 bpf_mtap( &sc->sc_if, m );
3153 * We are using the !OACTIVE flag to indicate to
3154 * the outside world that we can accept an
3155 * additional packet rather than that the
3156 * transmitter is _actually_ active. Indeed, the
3157 * transmitter may be active, but if we haven't
3158 * filled all the buffers with data then we still
3159 * want to accept more.
3161 sc->sc_if.if_flags &= ~IFF_OACTIVE;
3166 * The transmitter is active, and there are no room for
3167 * more outgoing packets in the transmission buffer.
3169 sc->sc_if.if_flags |= IFF_OACTIVE;
3174 * Drop (skip) a packet from receive buffer in 86960 memory.
3177 fe_droppacket ( struct fe_softc * sc, int len )
3182 * 86960 manual says that we have to read 8 bytes from the buffer
3183 * before skip the packets and that there must be more than 8 bytes
3184 * remaining in the buffer when issue a skip command.
3185 * Remember, we have already read 4 bytes before come here.
3188 /* Read 4 more bytes, and skip the rest of the packet. */
3189 #ifdef FE_8BIT_SUPPORT
3190 if ((sc->proto_dlcr6 & FE_D6_SBW) == FE_D6_SBW_BYTE)
3192 ( void )inb( sc->ioaddr[ FE_BMPR8 ] );
3193 ( void )inb( sc->ioaddr[ FE_BMPR8 ] );
3194 ( void )inb( sc->ioaddr[ FE_BMPR8 ] );
3195 ( void )inb( sc->ioaddr[ FE_BMPR8 ] );
3200 ( void )inw( sc->ioaddr[ FE_BMPR8 ] );
3201 ( void )inw( sc->ioaddr[ FE_BMPR8 ] );
3203 outb( sc->ioaddr[ FE_BMPR14 ], FE_B14_SKIP );
3205 /* We should not come here unless receiving RUNTs. */
3206 #ifdef FE_8BIT_SUPPORT
3207 if ((sc->proto_dlcr6 & FE_D6_SBW) == FE_D6_SBW_BYTE)
3209 for ( i = 0; i < len; i++ ) {
3210 ( void )inb( sc->ioaddr[ FE_BMPR8 ] );
3216 for ( i = 0; i < len; i += 2 ) {
3217 ( void )inw( sc->ioaddr[ FE_BMPR8 ] );
3225 * Empty receiving buffer.
3228 fe_emptybuffer ( struct fe_softc * sc )
3234 printf("fe%d: emptying receive buffer\n", sc->sc_unit);
3238 * Stop receiving packets, temporarily.
3240 saved_dlcr5 = inb( sc->ioaddr[ FE_DLCR5 ] );
3241 outb( sc->ioaddr[ FE_DLCR5 ], sc->proto_dlcr5 );
3245 * When we come here, the receive buffer management may
3246 * have been broken. So, we cannot use skip operation.
3247 * Just discard everything in the buffer.
3249 #ifdef FE_8BIT_SUPPORT
3250 if ((sc->proto_dlcr6 & FE_D6_SBW) == FE_D6_SBW_BYTE)
3252 for ( i = 0; i < 65536; i++ ) {
3253 if ( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) break;
3254 ( void )inb( sc->ioaddr[ FE_BMPR8 ] );
3260 for ( i = 0; i < 65536; i += 2 ) {
3261 if ( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) break;
3262 ( void )inw( sc->ioaddr[ FE_BMPR8 ] );
3269 if ( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) {
3270 printf("fe%d: could not empty receive buffer\n", sc->sc_unit);
3271 /* Hmm. What should I do if this happens? FIXME. */
3275 * Restart receiving packets.
3277 outb( sc->ioaddr[ FE_DLCR5 ], saved_dlcr5 );
3282 * Transmission interrupt handler
3283 * The control flow of this function looks silly. FIXME.
3286 fe_tint ( struct fe_softc * sc, u_char tstat )
3292 * Handle "excessive collision" interrupt.
3294 if ( tstat & FE_D0_COLL16 ) {
3297 * Find how many packets (including this collided one)
3298 * are left unsent in transmission buffer.
3300 left = inb( sc->ioaddr[ FE_BMPR10 ] );
3301 printf("fe%d: excessive collision (%d/%d)\n",
3302 sc->sc_unit, left, sc->txb_sched);
3305 * Clear the collision flag (in 86960) here
3306 * to avoid confusing statistics.
3308 outb( sc->ioaddr[ FE_DLCR0 ], FE_D0_COLLID );
3311 * Restart transmitter, skipping the
3314 * We *must* skip the packet to keep network running
3315 * properly. Excessive collision error is an
3316 * indication of the network overload. If we
3317 * tried sending the same packet after excessive
3318 * collision, the network would be filled with
3319 * out-of-time packets. Packets belonging
3320 * to reliable transport (such as TCP) are resent
3321 * by some upper layer.
3323 outb( sc->ioaddr[ FE_BMPR11 ],
3324 FE_B11_CTRL_SKIP | FE_B11_MODE1 );
3326 /* Update statistics. */
3331 * Handle "transmission complete" interrupt.
3333 if ( tstat & FE_D0_TXDONE ) {
3336 * Add in total number of collisions on last
3337 * transmission. We also clear "collision occurred" flag
3340 * 86960 has a design flaw on collision count on multiple
3341 * packet transmission. When we send two or more packets
3342 * with one start command (that's what we do when the
3343 * transmission queue is crowded), 86960 informs us number
3344 * of collisions occurred on the last packet on the
3345 * transmission only. Number of collisions on previous
3346 * packets are lost. I have told that the fact is clearly
3347 * stated in the Fujitsu document.
3349 * I considered not to mind it seriously. Collision
3350 * count is not so important, anyway. Any comments? FIXME.
3353 if ( inb( sc->ioaddr[ FE_DLCR0 ] ) & FE_D0_COLLID ) {
3355 /* Clear collision flag. */
3356 outb( sc->ioaddr[ FE_DLCR0 ], FE_D0_COLLID );
3358 /* Extract collision count from 86960. */
3359 col = inb( sc->ioaddr[ FE_DLCR4 ] );
3360 col = ( col & FE_D4_COL ) >> FE_D4_COL_SHIFT;
3363 * Status register indicates collisions,
3364 * while the collision count is zero.
3365 * This can happen after multiple packet
3366 * transmission, indicating that one or more
3367 * previous packet(s) had been collided.
3369 * Since the accurate number of collisions
3370 * has been lost, we just guess it as 1;
3371 * Am I too optimistic? FIXME.
3375 sc->sc_if.if_collisions += col;
3377 sc->mibdata.dot3StatsSingleCollisionFrames++;
3379 sc->mibdata.dot3StatsMultipleCollisionFrames++;
3381 sc->mibdata.dot3StatsCollFrequencies[col-1]++;
3385 * Update transmission statistics.
3386 * Be sure to reflect number of excessive collisions.
3388 col = sc->tx_excolls;
3389 sc->sc_if.if_opackets += sc->txb_sched - col;
3390 sc->sc_if.if_oerrors += col;
3391 sc->sc_if.if_collisions += col * 16;
3392 sc->mibdata.dot3StatsExcessiveCollisions += col;
3393 sc->mibdata.dot3StatsCollFrequencies[15] += col;
3397 * The transmitter is no more active.
3398 * Reset output active flag and watchdog timer.
3400 sc->sc_if.if_flags &= ~IFF_OACTIVE;
3401 sc->sc_if.if_timer = 0;
3404 * If more data is ready to transmit in the buffer, start
3405 * transmitting them. Otherwise keep transmitter idle,
3406 * even if more data is queued. This gives receive
3407 * process a slight priority.
3409 if ( sc->txb_count > 0 ) fe_xmit( sc );
3414 * Ethernet interface receiver interrupt.
3417 fe_rint ( struct fe_softc * sc, u_char rstat )
3424 * Update statistics if this interrupt is caused by an error.
3425 * Note that, when the system was not sufficiently fast, the
3426 * receive interrupt might not be acknowledged immediately. If
3427 * one or more errornous frames were received before this routine
3428 * was scheduled, they are ignored, and the following error stats
3429 * give less than real values.
3431 if ( rstat & ( FE_D1_OVRFLO | FE_D1_CRCERR
3432 | FE_D1_ALGERR | FE_D1_SRTPKT ) ) {
3433 if ( rstat & FE_D1_OVRFLO )
3434 sc->mibdata.dot3StatsInternalMacReceiveErrors++;
3435 if ( rstat & FE_D1_CRCERR )
3436 sc->mibdata.dot3StatsFCSErrors++;
3437 if ( rstat & FE_D1_ALGERR )
3438 sc->mibdata.dot3StatsAlignmentErrors++;
3440 /* The reference MAC receiver defined in 802.3
3441 silently ignores short frames (RUNTs) without
3442 notifying upper layer. RFC 1650 (dot3 MIB) is
3443 based on the 802.3, and it has no stats entry for
3445 if ( rstat & FE_D1_SRTPKT )
3446 sc->mibdata.dot3StatsFrameTooShorts++; /* :-) */
3448 sc->sc_if.if_ierrors++;
3452 * MB86960 has a flag indicating "receive queue empty."
3453 * We just loop, checking the flag, to pull out all received
3456 * We limit the number of iterations to avoid infinite-loop.
3457 * The upper bound is set to unrealistic high value.
3459 for ( i = 0; i < FE_MAX_RECV_COUNT * 2; i++ ) {
3461 /* Stop the iteration if 86960 indicates no packets. */
3462 if ( inb( sc->ioaddr[ FE_DLCR5 ] ) & FE_D5_BUFEMP ) return;
3465 * Extract a receive status byte.
3466 * As our 86960 is in 16 bit bus access mode, we have to
3467 * use inw() to get the status byte. The significant
3468 * value is returned in lower 8 bits.
3470 #ifdef FE_8BIT_SUPPORT
3471 if ((sc->proto_dlcr6 & FE_D6_SBW) == FE_D6_SBW_BYTE)
3473 status = inb( sc->ioaddr[ FE_BMPR8 ] );
3474 ( void ) inb( sc->ioaddr[ FE_BMPR8 ] );
3479 status = ( u_char )inw( sc->ioaddr[ FE_BMPR8 ] );
3483 * Extract the packet length.
3484 * It is a sum of a header (14 bytes) and a payload.
3485 * CRC has been stripped off by the 86960.
3487 #ifdef FE_8BIT_SUPPORT
3488 if ((sc->proto_dlcr6 & FE_D6_SBW) == FE_D6_SBW_BYTE)
3490 len = inb( sc->ioaddr[ FE_BMPR8 ] );
3491 len |= ( inb( sc->ioaddr[ FE_BMPR8 ] ) << 8 );
3496 len = inw( sc->ioaddr[ FE_BMPR8 ] );
3500 * AS our 86960 is programed to ignore errored frame,
3501 * we must not see any error indication in the
3502 * receive buffer. So, any error condition is a
3503 * serious error, e.g., out-of-sync of the receive
3506 if ( ( status & 0xF0 ) != 0x20
3507 || len > ETHER_MAX_LEN - ETHER_CRC_LEN
3508 || len < ETHER_MIN_LEN - ETHER_CRC_LEN ) {
3509 printf("fe%d: RX buffer out-of-sync\n", sc->sc_unit);
3510 sc->sc_if.if_ierrors++;
3511 sc->mibdata.dot3StatsInternalMacReceiveErrors++;
3519 if ( fe_get_packet( sc, len ) < 0 ) {
3521 * Negative return from fe_get_packet()
3522 * indicates no available mbuf. We stop
3523 * receiving packets, even if there are more
3524 * in the buffer. We hope we can get more
3527 sc->sc_if.if_ierrors++;
3528 sc->mibdata.dot3StatsMissedFrames++;
3529 fe_droppacket( sc, len );
3533 /* Successfully received a packet. Update stat. */
3534 sc->sc_if.if_ipackets++;
3537 /* Maximum number of frames has been received. Something
3538 strange is happening here... */
3539 printf("fe%d: unusual receive flood\n", sc->sc_unit);
3540 sc->mibdata.dot3StatsInternalMacReceiveErrors++;
3545 * Ethernet interface interrupt processor
3550 struct fe_softc *sc = &fe_softc[unit];
3551 u_char tstat, rstat;
3552 int loop_count = FE_MAX_LOOP;
3554 /* Loop until there are no more new interrupt conditions. */
3555 while (loop_count-- > 0) {
3557 * Get interrupt conditions, masking unneeded flags.
3559 tstat = inb( sc->ioaddr[ FE_DLCR0 ] ) & FE_TMASK;
3560 rstat = inb( sc->ioaddr[ FE_DLCR1 ] ) & FE_RMASK;
3561 if ( tstat == 0 && rstat == 0 ) return;
3564 * Reset the conditions we are acknowledging.
3566 outb( sc->ioaddr[ FE_DLCR0 ], tstat );
3567 outb( sc->ioaddr[ FE_DLCR1 ], rstat );
3570 * Handle transmitter interrupts.
3573 fe_tint( sc, tstat );
3577 * Handle receiver interrupts
3580 fe_rint( sc, rstat );
3584 * Update the multicast address filter if it is
3585 * needed and possible. We do it now, because
3586 * we can make sure the transmission buffer is empty,
3587 * and there is a good chance that the receive queue
3588 * is empty. It will minimize the possibility of
3591 if ( sc->filter_change
3592 && sc->txb_count == 0 && sc->txb_sched == 0 ) {
3594 sc->sc_if.if_flags &= ~IFF_OACTIVE;
3598 * If it looks like the transmitter can take more data,
3599 * attempt to start output on the interface. This is done
3600 * after handling the receiver interrupt to give the
3601 * receive operation priority.
3603 * BTW, I'm not sure in what case the OACTIVE is on at
3604 * this point. Is the following test redundant?
3606 * No. This routine polls for both transmitter and
3607 * receiver interrupts. 86960 can raise a receiver
3608 * interrupt when the transmission buffer is full.
3610 if ( ( sc->sc_if.if_flags & IFF_OACTIVE ) == 0 ) {
3611 fe_start( &sc->sc_if );
3616 printf("fe%d: too many loops\n", sc->sc_unit);
3621 * Process an ioctl request. This code needs some work - it looks
3625 fe_ioctl ( struct ifnet * ifp, u_long command, caddr_t data )
3627 struct fe_softc *sc = ifp->if_softc;
3628 struct ifreq *ifr = (struct ifreq *)data;
3638 /* Just an ordinary action. */
3639 error = ether_ioctl(ifp, command, data);
3644 * Switch interface state between "running" and
3645 * "stopped", reflecting the UP flag.
3647 if ( sc->sc_if.if_flags & IFF_UP ) {
3648 if ( ( sc->sc_if.if_flags & IFF_RUNNING ) == 0 ) {
3652 if ( ( sc->sc_if.if_flags & IFF_RUNNING ) != 0 ) {
3658 * Promiscuous and/or multicast flags may have changed,
3659 * so reprogram the multicast filter and/or receive mode.
3669 * Multicast list has changed; set the hardware filter
3677 /* Let if_media to handle these commands and to call
3679 error = ifmedia_ioctl(ifp, ifr, &sc->media, command);
3692 * Retrieve packet from receive buffer and send to the next level up via
3693 * ether_input(). If there is a BPF listener, give a copy to BPF, too.
3694 * Returns 0 if success, -1 if error (i.e., mbuf allocation failure).
3697 fe_get_packet ( struct fe_softc * sc, u_short len )
3699 struct ether_header *eh;
3703 * NFS wants the data be aligned to the word (4 byte)
3704 * boundary. Ethernet header has 14 bytes. There is a
3707 #define NFS_MAGIC_OFFSET 2
3710 * This function assumes that an Ethernet packet fits in an
3711 * mbuf (with a cluster attached when necessary.) On FreeBSD
3712 * 2.0 for x86, which is the primary target of this driver, an
3713 * mbuf cluster has 4096 bytes, and we are happy. On ancient
3714 * BSDs, such as vanilla 4.3 for 386, a cluster size was 1024,
3715 * however. If the following #error message were printed upon
3716 * compile, you need to rewrite this function.
3718 #if ( MCLBYTES < ETHER_MAX_LEN - ETHER_CRC_LEN + NFS_MAGIC_OFFSET )
3719 #error "Too small MCLBYTES to use fe driver."
3723 * Our strategy has one more problem. There is a policy on
3724 * mbuf cluster allocation. It says that we must have at
3725 * least MINCLSIZE (208 bytes on FreeBSD 2.0 for x86) to
3726 * allocate a cluster. For a packet of a size between
3727 * (MHLEN - 2) to (MINCLSIZE - 2), our code violates the rule...
3728 * On the other hand, the current code is short, simple,
3729 * and fast, however. It does no harmful thing, just waists
3730 * some memory. Any comments? FIXME.
3733 /* Allocate an mbuf with packet header info. */
3734 MGETHDR(m, M_DONTWAIT, MT_DATA);
3735 if ( m == NULL ) return -1;
3737 /* Attach a cluster if this packet doesn't fit in a normal mbuf. */
3738 if ( len > MHLEN - NFS_MAGIC_OFFSET ) {
3739 MCLGET( m, M_DONTWAIT );
3740 if ( !( m->m_flags & M_EXT ) ) {
3746 /* Initialize packet header info. */
3747 m->m_pkthdr.rcvif = &sc->sc_if;
3748 m->m_pkthdr.len = len;
3750 /* Set the length of this packet. */
3753 /* The following silliness is to make NFS happy */
3754 m->m_data += NFS_MAGIC_OFFSET;
3756 /* Get (actually just point to) the header part. */
3757 eh = mtod(m, struct ether_header *);
3760 #ifdef FE_8BIT_SUPPORT
3761 if ((sc->proto_dlcr6 & FE_D6_SBW) == FE_D6_SBW_BYTE)
3763 insb( sc->ioaddr[ FE_BMPR8 ], eh, len );
3768 insw( sc->ioaddr[ FE_BMPR8 ], eh, ( len + 1 ) >> 1 );
3771 #define ETHER_ADDR_IS_MULTICAST(A) (*(char *)(A) & 1)
3774 * Check if there's a BPF listener on this interface.
3775 * If it is, hand off the raw packet to bpf.
3777 if ( sc->sc_if.if_bpf ) {
3778 bpf_mtap( &sc->sc_if, m );
3786 if (ifp == BDG_DROP) {
3790 if (ifp != BDG_LOCAL)
3791 bdg_forward(&m, ifp); /* not local, need forwarding */
3792 if (ifp == BDG_LOCAL || ifp == BDG_BCAST || ifp == BDG_MCAST)
3794 /* not local and not multicast, just drop it */
3802 * Make sure this packet is (or may be) directed to us.
3803 * That is, the packet is either unicasted to our address,
3804 * or broad/multi-casted. If any other packets are
3805 * received, it is an indication of an error -- probably
3806 * 86960 is in a wrong operation mode.
3807 * Promiscuous mode is an exception. Under the mode, all
3808 * packets on the media must be received. (We must have
3809 * programmed the 86960 so.)
3812 if ( ( sc->sc_if.if_flags & IFF_PROMISC )
3813 && !ETHER_ADDR_IS_MULTICAST( eh->ether_dhost )
3814 && bcmp( eh->ether_dhost, sc->sc_enaddr, ETHER_ADDR_LEN ) != 0 ) {
3816 * The packet was not for us. This is normal since
3817 * we are now in promiscuous mode. Just drop the packet.
3826 /* Strip off the Ethernet header. */
3827 m->m_pkthdr.len -= sizeof ( struct ether_header );
3828 m->m_len -= sizeof ( struct ether_header );
3829 m->m_data += sizeof ( struct ether_header );
3831 /* Feed the packet to upper layer. */
3832 ether_input( &sc->sc_if, eh, m );
3837 * Write an mbuf chain to the transmission buffer memory using 16 bit PIO.
3838 * Returns number of bytes actually written, including length word.
3840 * If an mbuf chain is too long for an Ethernet frame, it is not sent.
3841 * Packets shorter than Ethernet minimum are legal, and we pad them
3842 * before sending out. An exception is "partial" packets which are
3843 * shorter than mandatory Ethernet header.
3846 fe_write_mbufs ( struct fe_softc *sc, struct mbuf *m )
3848 u_short addr_bmpr8 = sc->ioaddr[ FE_BMPR8 ];
3849 u_short length, len;
3852 u_short savebyte; /* WARNING: Architecture dependent! */
3853 #define NO_PENDING_BYTE 0xFFFF
3855 static u_char padding [ ETHER_MIN_LEN - ETHER_CRC_LEN - ETHER_HDR_LEN ];
3858 /* First, count up the total number of bytes to copy */
3860 for ( mp = m; mp != NULL; mp = mp->m_next ) {
3861 length += mp->m_len;
3863 /* Check if this matches the one in the packet header. */
3864 if ( length != m->m_pkthdr.len ) {
3865 printf("fe%d: packet length mismatch? (%d/%d)\n", sc->sc_unit,
3866 length, m->m_pkthdr.len);
3869 /* Just use the length value in the packet header. */
3870 length = m->m_pkthdr.len;
3875 * Should never send big packets. If such a packet is passed,
3876 * it should be a bug of upper layer. We just ignore it.
3877 * ... Partial (too short) packets, neither.
3879 if ( length < ETHER_HDR_LEN
3880 || length > ETHER_MAX_LEN - ETHER_CRC_LEN ) {
3881 printf("fe%d: got an out-of-spec packet (%u bytes) to send\n",
3882 sc->sc_unit, length);
3883 sc->sc_if.if_oerrors++;
3884 sc->mibdata.dot3StatsInternalMacTransmitErrors++;
3890 * Put the length word for this frame.
3891 * Does 86960 accept odd length? -- Yes.
3892 * Do we need to pad the length to minimum size by ourselves?
3893 * -- Generally yes. But for (or will be) the last
3894 * packet in the transmission buffer, we can skip the
3895 * padding process. It may gain performance slightly. FIXME.
3897 #ifdef FE_8BIT_SUPPORT
3898 if ((sc->proto_dlcr6 & FE_D6_SBW) == FE_D6_SBW_BYTE)
3900 len = max( length, ETHER_MIN_LEN - ETHER_CRC_LEN );
3901 outb( addr_bmpr8, len & 0x00ff );
3902 outb( addr_bmpr8, ( len & 0xff00 ) >> 8 );
3907 outw( addr_bmpr8, max( length, ETHER_MIN_LEN - ETHER_CRC_LEN ) );
3911 * Update buffer status now.
3912 * Truncate the length up to an even number, since we use outw().
3914 #ifdef FE_8BIT_SUPPORT
3915 if ((sc->proto_dlcr6 & FE_D6_SBW) != FE_D6_SBW_BYTE)
3918 length = ( length + 1 ) & ~1;
3920 sc->txb_free -= FE_DATA_LEN_LEN + max( length, ETHER_MIN_LEN - ETHER_CRC_LEN);
3924 * Transfer the data from mbuf chain to the transmission buffer.
3925 * MB86960 seems to require that data be transferred as words, and
3926 * only words. So that we require some extra code to patch
3927 * over odd-length mbufs.
3929 #ifdef FE_8BIT_SUPPORT
3930 if ((sc->proto_dlcr6 & FE_D6_SBW) == FE_D6_SBW_BYTE)
3932 /* 8-bit cards are easy. */
3933 for ( mp = m; mp != 0; mp = mp->m_next ) {
3935 outsb( addr_bmpr8, mtod(mp, caddr_t), mp->m_len );
3942 /* 16-bit cards are a pain. */
3943 savebyte = NO_PENDING_BYTE;
3944 for ( mp = m; mp != 0; mp = mp->m_next ) {
3946 /* Ignore empty mbuf. */
3948 if ( len == 0 ) continue;
3950 /* Find the actual data to send. */
3951 data = mtod(mp, caddr_t);
3953 /* Finish the last byte. */
3954 if ( savebyte != NO_PENDING_BYTE ) {
3955 outw( addr_bmpr8, savebyte | ( *data << 8 ) );
3958 savebyte = NO_PENDING_BYTE;
3961 /* output contiguous words */
3963 outsw( addr_bmpr8, data, len >> 1);
3968 /* Save a remaining byte, if there is one. */
3974 /* Spit the last byte, if the length is odd. */
3975 if ( savebyte != NO_PENDING_BYTE ) {
3976 outw( addr_bmpr8, savebyte );
3980 /* Pad to the Ethernet minimum length, if the packet is too short. */
3981 if ( length < ETHER_MIN_LEN - ETHER_CRC_LEN ) {
3982 #ifdef FE_8BIT_SUPPORT
3983 if ((sc->proto_dlcr6 & FE_D6_SBW) == FE_D6_SBW_BYTE)
3985 outsb( addr_bmpr8, padding, ETHER_MIN_LEN - ETHER_CRC_LEN - length );
3990 outsw( addr_bmpr8, padding, ( ETHER_MIN_LEN - ETHER_CRC_LEN - length ) >> 1);
3996 * Compute hash value for an Ethernet address
3999 fe_hash ( u_char * ep )
4001 #define FE_HASH_MAGIC_NUMBER 0xEDB88320L
4003 u_long hash = 0xFFFFFFFFL;
4008 for ( i = ETHER_ADDR_LEN; --i >= 0; ) {
4010 for ( j = 8; --j >= 0; ) {
4013 if ( ( m ^ b ) & 1 ) hash ^= FE_HASH_MAGIC_NUMBER;
4017 return ( ( int )( hash >> 26 ) );
4021 * Compute the multicast address filter from the
4022 * list of multicast addresses we need to listen to.
4024 static struct fe_filter
4025 fe_mcaf ( struct fe_softc *sc )
4028 struct fe_filter filter;
4029 struct ifmultiaddr *ifma;
4031 filter = fe_filter_nothing;
4032 for (ifma = sc->arpcom.ac_if.if_multiaddrs.lh_first; ifma;
4033 ifma = ifma->ifma_link.le_next) {
4034 if (ifma->ifma_addr->sa_family != AF_LINK)
4036 index = fe_hash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
4038 printf("fe%d: hash(%6D) == %d\n",
4039 sc->sc_unit, enm->enm_addrlo , ":", index);
4042 filter.data[index >> 3] |= 1 << (index & 7);
4048 * Calculate a new "multicast packet filter" and put the 86960
4049 * receiver in appropriate mode.
4052 fe_setmode ( struct fe_softc *sc )
4054 int flags = sc->sc_if.if_flags;
4057 * If the interface is not running, we postpone the update
4058 * process for receive modes and multicast address filter
4059 * until the interface is restarted. It reduces some
4060 * complicated job on maintaining chip states. (Earlier versions
4061 * of this driver had a bug on that point...)
4063 * To complete the trick, fe_init() calls fe_setmode() after
4064 * restarting the interface.
4066 if ( !( flags & IFF_RUNNING ) ) return;
4069 * Promiscuous mode is handled separately.
4071 if ( flags & IFF_PROMISC ) {
4073 * Program 86960 to receive all packets on the segment
4074 * including those directed to other stations.
4075 * Multicast filter stored in MARs are ignored
4076 * under this setting, so we don't need to update it.
4078 * Promiscuous mode in FreeBSD 2 is used solely by
4079 * BPF, and BPF only listens to valid (no error) packets.
4080 * So, we ignore erroneous ones even in this mode.
4081 * (Older versions of fe driver mistook the point.)
4083 outb( sc->ioaddr[ FE_DLCR5 ],
4084 sc->proto_dlcr5 | FE_D5_AFM0 | FE_D5_AFM1 );
4085 sc->filter_change = 0;
4090 * Turn the chip to the normal (non-promiscuous) mode.
4092 outb( sc->ioaddr[ FE_DLCR5 ], sc->proto_dlcr5 | FE_D5_AFM1 );
4095 * Find the new multicast filter value.
4097 if ( flags & IFF_ALLMULTI ) {
4098 sc->filter = fe_filter_all;
4100 sc->filter = fe_mcaf( sc );
4102 sc->filter_change = 1;
4105 * We have to update the multicast filter in the 86960, A.S.A.P.
4107 * Note that the DLC (Data Link Control unit, i.e. transmitter
4108 * and receiver) must be stopped when feeding the filter, and
4109 * DLC trashes all packets in both transmission and receive
4110 * buffers when stopped.
4112 * To reduce the packet loss, we delay the filter update
4113 * process until buffers are empty.
4115 if ( sc->txb_sched == 0 && sc->txb_count == 0
4116 && !( inb( sc->ioaddr[ FE_DLCR1 ] ) & FE_D1_PKTRDY ) ) {
4118 * Buffers are (apparently) empty. Load
4119 * the new filter value into MARs now.
4124 * Buffers are not empty. Mark that we have to update
4125 * the MARs. The new filter will be loaded by feintr()
4132 * Load a new multicast address filter into MARs.
4134 * The caller must have splimp'ed before fe_loadmar.
4135 * This function starts the DLC upon return. So it can be called only
4136 * when the chip is working, i.e., from the driver's point of view, when
4137 * a device is RUNNING. (I mistook the point in previous versions.)
4140 fe_loadmar ( struct fe_softc * sc )
4142 /* Stop the DLC (transmitter and receiver). */
4144 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
4147 /* Select register bank 1 for MARs. */
4148 outb( sc->ioaddr[ FE_DLCR7 ],
4149 sc->proto_dlcr7 | FE_D7_RBS_MAR | FE_D7_POWER_UP );
4151 /* Copy filter value into the registers. */
4152 outblk( sc, FE_MAR8, sc->filter.data, FE_FILTER_LEN );
4154 /* Restore the bank selection for BMPRs (i.e., runtime registers). */
4155 outb( sc->ioaddr[ FE_DLCR7 ],
4156 sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP );
4158 /* Restart the DLC. */
4160 outb( sc->ioaddr[ FE_DLCR6 ], sc->proto_dlcr6 | FE_D6_DLC_ENABLE );
4163 /* We have just updated the filter. */
4164 sc->filter_change = 0;
4167 /* Change the media selection. */
4169 fe_medchange (struct ifnet *ifp)
4171 struct fe_softc *sc = (struct fe_softc *)ifp->if_softc;
4174 /* If_media should not pass any request for a media which this
4175 interface doesn't support. */
4178 for (b = 0; bit2media[b] != 0; b++) {
4179 if (bit2media[b] == sc->media.ifm_media) break;
4181 if (((1 << b) & sc->mbitmap) == 0) {
4182 printf("fe%d: got an unsupported media request (0x%x)\n",
4183 sc->sc_unit, sc->media.ifm_media);
4188 /* We don't actually change media when the interface is down.
4189 fe_init() will do the job, instead. Should we also wait
4190 until the transmission buffer being empty? Changing the
4191 media when we are sending a frame will cause two garbages
4192 on wires, one on old media and another on new. FIXME */
4193 if (sc->sc_if.if_flags & IFF_UP) {
4194 if (sc->msel) sc->msel(sc);
4200 /* I don't know how I can support media status callback... FIXME. */
4202 fe_medstat (struct ifnet *ifp, struct ifmediareq *ifmr)