Deleted Added
full compact
1/*
2 * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
3 *
4 * This software may be used, modified, copied, distributed, and sold, in
5 * both source and binary form provided that the above copyright, these
6 * terms and the following disclaimer are retained. The name of the author
7 * and/or the contributor may not be used to endorse or promote products
8 * derived from this software without specific prior written permission.
9 *
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
20 * SUCH DAMAGE.
21 */
22
23#define FE_VERSION "if_fe.c ver. 0.8a"
24
25/*
26 * Device driver for Fujitsu MB86960A/MB86965A based Ethernet cards.
27 * To be used with FreeBSD 2.0 RELEASE.
28 * Contributed by M.S. <seki@sysrap.cs.fujitsu.co.jp>
29 *
30 * This version is intended to be a generic template for various
31 * MB86960A/MB86965A based Ethernet cards. It currently supports
32 * Fujitsu FMV-180 series (i.e., FMV-181 and FMV-182) and Allied-
33 * Telesis AT1700 series and RE2000 series. There are some
34 * unnecessary hooks embedded, which are primarily intended to support
35 * other types of Ethernet cards, but the author is not sure whether
36 * they are useful.
37 *
38 * This software is a derivative work of if_ed.c version 1.56 by David
39 * Greenman available as a part of FreeBSD 2.0 RELEASE source distribution.
40 *
41 * The following lines are retained from the original if_ed.c:
42 *
43 * Copyright (C) 1993, David Greenman. This software may be used, modified,
44 * copied, distributed, and sold, in both source and binary form provided
45 * that the above copyright and these terms are retained. Under no
46 * circumstances is the author responsible for the proper functioning
47 * of this software, nor does the author assume any responsibility
48 * for damages incurred with its use.
49 */
50
51#include "fe.h"
52#include "bpfilter.h"
53
54#include <sys/param.h>
55#include <sys/systm.h>
56#include <sys/conf.h>
57#include <sys/errno.h>
58#include <sys/ioctl.h>
59#include <sys/mbuf.h>
60#include <sys/socket.h>
61#include <sys/syslog.h>
62#include <sys/devconf.h>
63
64#include <net/if.h>
65#include <net/if_dl.h>
66#include <net/if_types.h>
67
68#ifdef INET
69#include <netinet/in.h>
70#include <netinet/in_systm.h>
71#include <netinet/in_var.h>
72#include <netinet/ip.h>
73#include <netinet/if_ether.h>
74#endif
75
76#ifdef IPX
77#include <netipx/ipx.h>
78#include <netipx/ipx_if.h>
79#endif
80
81#ifdef NS
82#include <netns/ns.h>
83#include <netns/ns_if.h>
84#endif
85
86#if NBPFILTER > 0
87#include <net/bpf.h>
88#include <net/bpfdesc.h>
89#endif
90
91#include <machine/clock.h>
92
93#include <i386/isa/isa.h>
94#include <i386/isa/isa_device.h>
95#include <i386/isa/icu.h>
96
97#include <i386/isa/ic/mb86960.h>
98#include <i386/isa/if_fereg.h>
99
100#ifdef __GNUC__
101#define INLINE inline
102#else
103#define INLINE
104#endif
105
106/*
107 * Default settings for fe driver specific options.
108 * They can be set in config file by "options" statements.
109 */
110
111/*
112 * Debug control.
113 * 0: No debug at all. All debug specific codes are stripped off.
114 * 1: Silent. No debug messages are logged except emergent ones.
115 * 2: Brief. Lair events and/or important information are logged.
116 * 3: Detailed. Logs all information which *may* be useful for debugging.
117 * 4: Trace. All actions in the driver is logged. Super verbose.
118 */
119#ifndef FE_DEBUG
120#define FE_DEBUG 1
121#endif
122
123/*
124 * Delay padding of short transmission packets to minimum Ethernet size.
125 * This may or may not gain performance. An EXPERIMENTAL option.
126 */
127#ifndef FE_DELAYED_PADDING
128#define FE_DELAYED_PADDING 0
129#endif
130
131/*
132 * Transmit just one packet per a "send"command to 86960.
133 * This option is intended for performance test. An EXPERIMENTAL option.
134 */
135#ifndef FE_SINGLE_TRANSMISSION
136#define FE_SINGLE_TRANSMISSION 0
137#endif
138
139/*
140 * Device configuration flags.
141 */
142
143/* DLCR6 settings. */
144#define FE_FLAGS_DLCR6_VALUE 0x007F
145
146/* Force DLCR6 override. */
147#define FE_FLAGS_OVERRIDE_DLCR6 0x0080
148
149/* A cludge for PCMCIA support. */
150#define FE_FLAGS_PCMCIA 0x8000
151
152/* Shouldn't this be defined somewhere else such as isa_device.h? */
153#define NO_IOADDR 0xFFFFFFFF
154
155/* Identification of the driver version. */
156static char const fe_version [] = FE_VERSION " / " FE_REG_VERSION;
157
158/*
159 * Supported hardware (Ethernet card) types
160 * This information is currently used only for debugging
161 */
162enum fe_type
163{
164 /* For cards which are successfully probed but not identified. */
165 FE_TYPE_UNKNOWN,
166
167 /* Fujitsu FMV-180 series. */
168 FE_TYPE_FMV181,
169 FE_TYPE_FMV182,
170
171 /* Allied-Telesis AT1700 series and RE2000 series. */
172 FE_TYPE_AT1700,
173
174 /* PCMCIA by Fujitsu. */
175 FE_TYPE_MBH10302,
176 FE_TYPE_MBH10304,
177
178 /* More can be here. */
179};
180
181/*
182 * Data type for a multicast address filter on 86960.
183 */
184struct fe_filter { u_char data [ FE_FILTER_LEN ]; };
185
186/*
187 * Special filter values.
188 */
189static struct fe_filter const fe_filter_nothing = { FE_FILTER_NOTHING };
190static struct fe_filter const fe_filter_all = { FE_FILTER_ALL };
191
192/*
193 * fe_softc: per line info and status
194 */
195static struct fe_softc {
196
197 /* Used by "common" codes. */
198 struct arpcom arpcom; /* ethernet common */
199
200 /* Used by config codes. */
201 struct kern_devconf kdc;/* Kernel configuration database info. */
202
203 /* Set by probe() and not modified in later phases. */
204 enum fe_type type; /* interface type code */
205 char * typestr; /* printable name of the interface. */
206 u_short addr; /* MB86960A I/O base address */
207 u_short txb_size; /* size of TX buffer, in bytes */
208 u_char proto_dlcr4; /* DLCR4 prototype. */
209 u_char proto_dlcr5; /* DLCR5 prototype. */
210 u_char proto_dlcr6; /* DLCR6 prototype. */
211 u_char proto_dlcr7; /* DLCR7 prototype. */
212
213 /* Vendor specific hooks. */
214 void ( * init )( struct fe_softc * ); /* Just before fe_init(). */
215 void ( * stop )( struct fe_softc * ); /* Just after fe_stop(). */
216
217 /* For BPF. */
218 caddr_t bpf; /* BPF "magic cookie" */
219
217 /* Transmission buffer management. */
218 u_short txb_free; /* free bytes in TX buffer */
219 u_char txb_count; /* number of packets in TX buffer */
220 u_char txb_sched; /* number of scheduled packets */
221 u_char txb_padding; /* number of delayed padding bytes */
222
223 /* Multicast address filter management. */
224 u_char filter_change; /* MARs must be changed ASAP. */
225 struct fe_filter filter;/* new filter value. */
226
227} fe_softc[NFE];
228
229/* Frequently accessed members in arpcom and kdc. */
230#define sc_if arpcom.ac_if
231#define sc_unit arpcom.ac_if.if_unit
232#define sc_enaddr arpcom.ac_enaddr
233#define sc_dcstate kdc.kdc_state
234#define sc_description kdc.kdc_description
235
239/*
240 * Some entry functions receive a "struct ifnet *" typed pointer as an
241 * argument. It points to arpcom.ac_if of our softc. Remember arpcom.ac_if
242 * is located at very first of the fe_softc struct. So, there is no
243 * difference between "struct fe_softc *" and "struct ifnet *" at the machine
244 * language level. We just cast to turn a "struct ifnet *" value into "struct
245 * fe_softc * value". If this were C++, we would need no such cast at all.
246 */
247#define IFNET2SOFTC(P) ( ( struct fe_softc * )(P) )
236#define IFNET2SOFTC(P) (P)->if_softc
237
238/* Standard driver entry points. These can be static. */
239static int fe_probe ( struct isa_device * );
240static int fe_attach ( struct isa_device * );
241static void fe_init ( int );
242static int fe_ioctl ( struct ifnet *, int, caddr_t );
243static void fe_start ( struct ifnet * );
244static void fe_reset ( int );
245static void fe_watchdog ( struct ifnet * );
246
247/* Local functions. Order of declaration is confused. FIXME. */
248static int fe_probe_fmv ( struct isa_device *, struct fe_softc * );
249static int fe_probe_ati ( struct isa_device *, struct fe_softc * );
250static int fe_probe_mbh ( struct isa_device *, struct fe_softc * );
251static void fe_init_mbh ( struct fe_softc * );
252static int fe_get_packet ( struct fe_softc *, u_short );
253static void fe_stop ( int );
254static void fe_tint ( struct fe_softc *, u_char );
255static void fe_rint ( struct fe_softc *, u_char );
256static void fe_xmit ( struct fe_softc * );
257static void fe_write_mbufs ( struct fe_softc *, struct mbuf * );
258static struct fe_filter
259 fe_mcaf ( struct fe_softc * );
260static int fe_hash ( u_char * );
261static void fe_setmode ( struct fe_softc * );
262static void fe_loadmar ( struct fe_softc * );
274static void fe_setlinkaddr ( struct fe_softc * );
263#if FE_DEBUG >= 1
264static void fe_dump ( int, struct fe_softc *, char * );
265#endif
266
267/* Ethernet constants. To be defined in if_ehter.h? FIXME. */
268#define ETHER_MIN_LEN 60 /* with header, without CRC. */
269#define ETHER_MAX_LEN 1514 /* with header, without CRC. */
270#define ETHER_ADDR_LEN 6 /* number of bytes in an address. */
271#define ETHER_TYPE_LEN 2 /* number of bytes in a data type field. */
272#define ETHER_HDR_SIZE 14 /* src addr, dst addr, and data type. */
273#define ETHER_CRC_LEN 4 /* number of bytes in CRC field. */
274
275/* Driver struct used in the config code. This must be public (external.) */
276struct isa_driver fedriver =
277{
278 fe_probe,
279 fe_attach,
280 "fe",
281 0 /* Assume we are insensitive. FIXME. */
282};
283
284/* Initial value for a kdc struct. */
285static struct kern_devconf const fe_kdc_template =
286{
287 0, 0, 0,
288 "fe", 0, { MDDT_ISA, 0, "net" },
289 isa_generic_externalize, 0, 0, ISA_EXTERNALLEN,
290 &kdc_isa0, /* We are an ISA device. */
291 0,
292 DC_UNCONFIGURED, /* Not yet configured. */
293 "Ethernet (fe)", /* Tentative description (filled in later.) */
294 DC_CLS_NETIF /* We are a network interface. */
295};
296
297/*
298 * Fe driver specific constants which relate to 86960/86965.
299 * They are here (not in if_fereg.h), since selection of those
300 * values depend on driver design. I want to keep definitions in
301 * if_fereg.h "clean", so that if someone wrote another driver
302 * for 86960/86965, if_fereg.h were usable unchanged.
303 *
304 * The above statement sounds somothing like it's better to name
305 * it "ic/mb86960.h" but "if_fereg.h"... Should I do so? FIXME.
306 */
307
308/* Interrupt masks */
309#define FE_TMASK ( FE_D2_COLL16 | FE_D2_TXDONE )
310#define FE_RMASK ( FE_D3_OVRFLO | FE_D3_CRCERR \
311 | FE_D3_ALGERR | FE_D3_SRTPKT | FE_D3_PKTRDY )
312
313/* Maximum number of iterrations for a receive interrupt. */
314#define FE_MAX_RECV_COUNT ( ( 65536 - 2048 * 2 ) / 64 )
315 /* Maximum size of SRAM is 65536,
316 * minimum size of transmission buffer in fe is 2x2KB,
317 * and minimum amount of received packet including headers
318 * added by the chip is 64 bytes.
319 * Hence FE_MAX_RECV_COUNT is the upper limit for number
320 * of packets in the receive buffer. */
321
322/*
323 * Convenient routines to access contiguous I/O ports.
324 */
325
326static INLINE void
327inblk ( u_short addr, u_char * mem, int len )
328{
329 while ( --len >= 0 ) {
330 *mem++ = inb( addr++ );
331 }
332}
333
334static INLINE void
335outblk ( u_short addr, u_char const * mem, int len )
336{
337 while ( --len >= 0 ) {
338 outb( addr++, *mem++ );
339 }
340}
341
342/*
343 * Hardware probe routines.
344 */
345
346/* How and where to probe; to support automatic I/O address detection. */
347struct fe_probe_list
348{
349 int ( * probe ) ( struct isa_device *, struct fe_softc * );
350 u_short const * addresses;
351};
352
353/* Lists of possible addresses. */
354static u_short const fe_fmv_addr [] =
355 { 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x300, 0x340, 0 };
356static u_short const fe_ati_addr [] =
357 { 0x240, 0x260, 0x280, 0x2A0, 0x300, 0x320, 0x340, 0x380, 0 };
358
359static struct fe_probe_list const fe_probe_list [] =
360{
361 { fe_probe_fmv, fe_fmv_addr },
362 { fe_probe_ati, fe_ati_addr },
363 { fe_probe_mbh, NULL }, /* PCMCIAs cannot be auto-detected. */
364 { NULL, NULL }
365};
366
367/*
368 * Determine if the device is present
369 *
370 * on entry:
371 * a pointer to an isa_device struct
372 * on exit:
373 * zero if device not found
374 * or number of i/o addresses used (if found)
375 */
376
377static int
378fe_probe ( struct isa_device * isa_dev )
379{
380 struct fe_softc * sc, * u;
381 int nports;
382 struct fe_probe_list const * list;
383 u_short const * addr;
384 u_short single [ 2 ];
385
386 /* Initialize "minimum" parts of our softc. */
387 sc = &fe_softc[ isa_dev->id_unit ];
388 sc->sc_unit = isa_dev->id_unit;
389
390#if FE_DEBUG >= 2
391 log( LOG_INFO, "fe%d: %s\n", sc->sc_unit, fe_version );
392#endif
393
394#ifndef DEV_LKM
395 /* Fill the device config data and register it. */
396 sc->kdc = fe_kdc_template;
397 sc->kdc.kdc_unit = sc->sc_unit;
398 sc->kdc.kdc_parentdata = isa_dev;
399 dev_attach( &sc->kdc );
400#endif
401
402 /* Probe each possibility, one at a time. */
403 for ( list = fe_probe_list; list->probe != NULL; list++ ) {
404
405 if ( isa_dev->id_iobase != NO_IOADDR ) {
406 /* Probe one specific address. */
407 single[ 0 ] = isa_dev->id_iobase;
408 single[ 1 ] = 0;
409 addr = single;
410 } else if ( list->addresses != NULL ) {
411 /* Auto detect. */
412 addr = list->addresses;
413 } else {
414 /* We need a list of addresses to do auto detect. */
415 continue;
416 }
417
418 /* Probe all possible addresses for the board. */
419 while ( *addr != 0 ) {
420
421 /* Don't probe already used address. */
422 for ( u = &fe_softc[0]; u < &fe_softc[NFE]; u++ ) {
423 if ( u->addr == *addr ) break;
424 }
425 if ( u < &fe_softc[NFE] ) continue;
426
427 /* Probe an address. */
428 sc->addr = *addr;
429 nports = list->probe( isa_dev, sc );
430 if ( nports > 0 ) {
431 /* Found. */
432 isa_dev->id_iobase = *addr;
433 return ( nports );
434 }
435
436 /* Try next. */
437 sc->addr = 0;
438 addr++;
439 }
440 }
441
442 /* Probe failed. */
443 return ( 0 );
444}
445
446/*
447 * Check for specific bits in specific registers have specific values.
448 */
449struct fe_simple_probe_struct
450{
451 u_char port; /* Offset from the base I/O address. */
452 u_char mask; /* Bits to be checked. */
453 u_char bits; /* Values to be compared against. */
454};
455
456static INLINE int
457fe_simple_probe ( u_short addr, struct fe_simple_probe_struct const * sp )
458{
459 struct fe_simple_probe_struct const * p;
460
461 for ( p = sp; p->mask != 0; p++ ) {
462 if ( ( inb( addr + p->port ) & p->mask ) != p->bits ) {
463 return ( 0 );
464 }
465 }
466 return ( 1 );
467}
468
469/*
470 * Routines to read all bytes from the config EEPROM through MB86965A.
471 * I'm not sure what exactly I'm doing here... I was told just to follow
472 * the steps, and it worked. Could someone tell me why the following
473 * code works? (Or, why all similar codes I tried previously doesn't
474 * work.) FIXME.
475 */
476
477static INLINE void
478strobe ( u_short bmpr16 )
479{
480 /*
481 * Output same value twice. To speed-down execution?
482 */
483 outb( bmpr16, FE_B16_SELECT );
484 outb( bmpr16, FE_B16_SELECT );
485 outb( bmpr16, FE_B16_SELECT | FE_B16_CLOCK );
486 outb( bmpr16, FE_B16_SELECT | FE_B16_CLOCK );
487 outb( bmpr16, FE_B16_SELECT );
488 outb( bmpr16, FE_B16_SELECT );
489}
490
491static void
492fe_read_eeprom ( struct fe_softc * sc, u_char * data )
493{
494 u_short bmpr16 = sc->addr + FE_BMPR16;
495 u_short bmpr17 = sc->addr + FE_BMPR17;
496 u_char n, val, bit;
497 u_char save16, save17;
498
499 /* Save old values of the registers. */
500 save16 = inb( bmpr16 );
501 save17 = inb( bmpr17 );
502
503 /* Read bytes from EEPROM; two bytes per an iterration. */
504 for ( n = 0; n < FE_EEPROM_SIZE / 2; n++ ) {
505
506 /* Reset the EEPROM interface. */
507 outb( bmpr16, 0x00 );
508 outb( bmpr17, 0x00 );
509 outb( bmpr16, FE_B16_SELECT );
510
511 /* Start EEPROM access. */
512 outb( bmpr17, FE_B17_DATA );
513 strobe( bmpr16 );
514
515 /* Pass the iterration count to the chip. */
516 val = 0x80 | n;
517 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
518 outb( bmpr17, ( val & bit ) ? FE_B17_DATA : 0 );
519 strobe( bmpr16 );
520 }
521 outb( bmpr17, 0x00 );
522
523 /* Read a byte. */
524 val = 0;
525 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
526 strobe( bmpr16 );
527 if ( inb( bmpr17 ) & FE_B17_DATA ) {
528 val |= bit;
529 }
530 }
531 *data++ = val;
532
533 /* Read one more byte. */
534 val = 0;
535 for ( bit = 0x80; bit != 0x00; bit >>= 1 ) {
536 strobe( bmpr16 );
537 if ( inb( bmpr17 ) & FE_B17_DATA ) {
538 val |= bit;
539 }
540 }
541 *data++ = val;
542 }
543
544 /* Restore register values, in the case we had no 86965. */
545 outb( bmpr16, save16 );
546 outb( bmpr17, save17 );
547
548#if FE_DEBUG >= 3
549 /* Report what we got. */
550 data -= FE_EEPROM_SIZE;
551 log( LOG_INFO, "fe%d: EEPROM:"
552 " %02x%02x%02x%02x %02x%02x%02x%02x -"
553 " %02x%02x%02x%02x %02x%02x%02x%02x -"
554 " %02x%02x%02x%02x %02x%02x%02x%02x -"
555 " %02x%02x%02x%02x %02x%02x%02x%02x\n",
556 sc->sc_unit,
557 data[ 0], data[ 1], data[ 2], data[ 3],
558 data[ 4], data[ 5], data[ 6], data[ 7],
559 data[ 8], data[ 9], data[10], data[11],
560 data[12], data[13], data[14], data[15],
561 data[16], data[17], data[18], data[19],
562 data[20], data[21], data[22], data[23],
563 data[24], data[25], data[26], data[27],
564 data[28], data[29], data[30], data[31] );
565#endif
566}
567
568/*
569 * Hardware (vendor) specific probe routines.
570 */
571
572/*
573 * Probe and initialization for Fujitsu FMV-180 series boards
574 */
575static int
576fe_probe_fmv ( struct isa_device *isa_dev, struct fe_softc * sc )
577{
578 int i, n;
579
580 static u_short const ioaddr [ 8 ] =
581 { 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x300, 0x340 };
582 static u_short const irqmap [ 4 ] =
583 { IRQ3, IRQ7, IRQ10, IRQ15 };
584
585 static struct fe_simple_probe_struct const probe_table [] = {
586 { FE_DLCR2, 0x70, 0x00 },
587 { FE_DLCR4, 0x08, 0x00 },
588 /* { FE_DLCR5, 0x80, 0x00 }, Doesn't work. */
589
590 { FE_FMV0, FE_FMV0_MAGIC_MASK, FE_FMV0_MAGIC_VALUE },
591 { FE_FMV1, FE_FMV1_CARDID_MASK, FE_FMV1_CARDID_ID },
592 { FE_FMV3, FE_FMV3_EXTRA_MASK, FE_FMV3_EXTRA_VALUE },
593#if 1
594 /*
595 * Test *vendor* part of the station address for Fujitsu.
596 * The test will gain reliability of probe process, but
597 * it rejects FMV-180 clone boards manufactured by other vendors.
598 * We have to turn the test off when such cards are made available.
599 */
600 { FE_FMV4, 0xFF, 0x00 },
601 { FE_FMV5, 0xFF, 0x00 },
602 { FE_FMV6, 0xFF, 0x0E },
603#else
604 /*
605 * We can always verify the *first* 2 bits (in Ehternet
606 * bit order) are "no multicast" and "no local" even for
607 * unknown vendors.
608 */
609 { FE_FMV4, 0x03, 0x00 },
610#endif
611 { 0 }
612 };
613
614#if 0
615 /*
616 * Dont probe at all if the config says we are PCMCIA...
617 */
618 if ( isa_dev->id_flags & FE_FLAGS_PCMCIA ) return ( 0 );
619#endif
620
621 /*
622 * See if the sepcified address is possible for FMV-180 series.
623 */
624 for ( i = 0; i < 8; i++ ) {
625 if ( ioaddr[ i ] == sc->addr ) break;
626 }
627 if ( i == 8 ) return 0;
628
629 /* Simple probe. */
630 if ( !fe_simple_probe( sc->addr, probe_table ) ) return 0;
631
632 /* Check if our I/O address matches config info on EEPROM. */
633 n = ( inb( sc->addr + FE_FMV2 ) & FE_FMV2_ADDR ) >> FE_FMV2_ADDR_SHIFT;
634 if ( ioaddr[ n ] != sc->addr ) return 0;
635
636 /* Determine the card type. */
637 switch ( inb( sc->addr + FE_FMV0 ) & FE_FMV0_MODEL ) {
638 case FE_FMV0_MODEL_FMV181:
639 sc->type = FE_TYPE_FMV181;
640 sc->typestr = "FMV-181";
641 sc->sc_description = "Ethernet adapter: FMV-181";
642 break;
643 case FE_FMV0_MODEL_FMV182:
644 sc->type = FE_TYPE_FMV182;
645 sc->typestr = "FMV-182";
646 sc->sc_description = "Ethernet adapter: FMV-182";
647 break;
648 default:
649 /* Unknown card type: maybe a new model, but... */
650 return 0;
651 }
652
653 /*
654 * An FMV-180 has successfully been proved.
655 * Determine which IRQ to be used.
656 *
657 * In this version, we always get an IRQ assignment from the
658 * FMV-180's configuration EEPROM, ignoring that specified in
659 * config file.
660 */
661 n = ( inb( sc->addr + FE_FMV2 ) & FE_FMV2_IRQ ) >> FE_FMV2_IRQ_SHIFT;
662 isa_dev->id_irq = irqmap[ n ];
663
664 /*
665 * Initialize constants in the per-line structure.
666 */
667
668 /* Get our station address from EEPROM. */
669 inblk( sc->addr + FE_FMV4, sc->sc_enaddr, ETHER_ADDR_LEN );
670
671 /* Make sure we got a valid station address. */
672 if ( ( sc->sc_enaddr[ 0 ] & 0x03 ) != 0x00
673 || ( sc->sc_enaddr[ 0 ] == 0x00
674 && sc->sc_enaddr[ 1 ] == 0x00
675 && sc->sc_enaddr[ 2 ] == 0x00 ) ) return 0;
676
677 /* Register values which depend on board design. */
678 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
679 sc->proto_dlcr5 = 0;
680 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_EC;
681
682 /*
683 * Program the 86960 as follows:
684 * SRAM: 32KB, 100ns, byte-wide access.
685 * Transmission buffer: 4KB x 2.
686 * System bus interface: 16 bits.
687 * We cannot change these values but TXBSIZE, because they
688 * are hard-wired on the board. Modifying TXBSIZE will affect
689 * the driver performance.
690 */
691 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
692 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
693
694 /*
695 * Minimum initialization of the hardware.
696 * We write into registers; hope I/O ports have no
697 * overlap with other boards.
698 */
699
700 /* Initialize ASIC. */
701 outb( sc->addr + FE_FMV3, 0 );
702 outb( sc->addr + FE_FMV10, 0 );
703
704 /* Wait for a while. I'm not sure this is necessary. FIXME. */
705 DELAY(200);
706
707 /* Initialize 86960. */
708 outb( sc->addr + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
709 DELAY(200);
710
711 /* Disable all interrupts. */
712 outb( sc->addr + FE_DLCR2, 0 );
713 outb( sc->addr + FE_DLCR3, 0 );
714
715 /* Turn the "master interrupt control" flag of ASIC on. */
716 outb( sc->addr + FE_FMV3, FE_FMV3_ENABLE_FLAG );
717
718 /*
719 * That's all. FMV-180 occupies 32 I/O addresses, by the way.
720 */
721 return 32;
722}
723
724/*
725 * Probe and initialization for Allied-Telesis AT1700/RE2000 series.
726 */
727static int
728fe_probe_ati ( struct isa_device * isa_dev, struct fe_softc * sc )
729{
730 int i, n;
731 u_char eeprom [ FE_EEPROM_SIZE ];
732
733 static u_short const ioaddr [ 8 ] =
734 { 0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300 };
735 static u_short const irqmap_lo [ 4 ] =
736 { IRQ3, IRQ4, IRQ5, IRQ9 };
737 static u_short const irqmap_hi [ 4 ] =
738 { IRQ10, IRQ11, IRQ12, IRQ15 };
739 static struct fe_simple_probe_struct const probe_table [] = {
740 { FE_DLCR2, 0x70, 0x00 },
741 { FE_DLCR4, 0x08, 0x00 },
742 { FE_DLCR5, 0x80, 0x00 },
743#if 0
744 { FE_BMPR16, 0x1B, 0x00 },
745 { FE_BMPR17, 0x7F, 0x00 },
746#endif
747 { 0 }
748 };
749
750#if 0
751 /*
752 * Don't probe at all if the config says we are PCMCIA...
753 */
754 if ( isa_dev->id_flags & FE_FLAGS_PCMCIA ) return ( 0 );
755#endif
756
757#if FE_DEBUG >= 3
758 log( LOG_INFO, "fe%d: probe (0x%x) for ATI\n", sc->sc_unit, sc->addr );
759 fe_dump( LOG_INFO, sc, NULL );
760#endif
761
762 /*
763 * See if the sepcified address is possible for MB86965A JLI mode.
764 */
765 for ( i = 0; i < 8; i++ ) {
766 if ( ioaddr[ i ] == sc->addr ) break;
767 }
768 if ( i == 8 ) return 0;
769
770 /*
771 * We should test if MB86965A is on the base address now.
772 * Unfortunately, it is very hard to probe it reliably, since
773 * we have no way to reset the chip under software control.
774 * On cold boot, we could check the "signature" bit patterns
775 * described in the Fujitsu document. On warm boot, however,
776 * we can predict almost nothing about register values.
777 */
778 if ( !fe_simple_probe( sc->addr, probe_table ) ) return 0;
779
780 /* Check if our I/O address matches config info on 86965. */
781 n = ( inb( sc->addr + FE_BMPR19 ) & FE_B19_ADDR ) >> FE_B19_ADDR_SHIFT;
782 if ( ioaddr[ n ] != sc->addr ) return 0;
783
784 /*
785 * We are now almost sure we have an AT1700 at the given
786 * address. So, read EEPROM through 86965. We have to write
787 * into LSI registers to read from EEPROM. I want to avoid it
788 * at this stage, but I cannot test the presense of the chip
789 * any further without reading EEPROM. FIXME.
790 */
791 fe_read_eeprom( sc, eeprom );
792
793 /* Make sure that config info in EEPROM and 86965 agree. */
794 if ( eeprom[ FE_EEPROM_CONF ] != inb( sc->addr + FE_BMPR19 ) ) {
795 return 0;
796 }
797
798 /*
799 * Determine the card type.
800 * There may be a way to identify various models. FIXME.
801 */
802 sc->type = FE_TYPE_AT1700;
803 sc->typestr = "AT1700/RE2000";
804 sc->sc_description = "Ethernet adapter: AT1700 or RE2000";
805
806 /*
807 * I was told that RE2000 series has two variants on IRQ
808 * selection. They are 3/4/5/9 and 10/11/12/15. I don't know
809 * how we can distinguish which model is which. For now, we
810 * just trust irq setting in config. FIXME.
811 *
812 * I've heard that ATI puts an identification between these
813 * two models in the EEPROM. Sounds reasonable. I've also
814 * heard that Linux driver for AT1700 tests it. O.K. Let's
815 * try using it and see what happens. Anyway, we will use an
816 * IRQ value passed by config (i.e., user), if one is
817 * available. FIXME.
818 */
819 n = ( inb( sc->addr + FE_BMPR19 ) & FE_B19_IRQ ) >> FE_B19_IRQ_SHIFT;
820 if ( isa_dev->id_irq == 0 ) {
821 /* Try to determine IRQ settings. */
822 if ( eeprom[ FE_EEP_ATI_TYPE ] & FE_EEP_ATI_TYPE_HIGHIRQ ) {
823 isa_dev->id_irq = irqmap_hi[ n ];
824 } else {
825 isa_dev->id_irq = irqmap_lo[ n ];
826 }
827 }
828
829 /*
830 * Initialize constants in the per-line structure.
831 */
832
833 /* Get our station address from EEPROM. */
834 bcopy( eeprom + FE_EEP_ATI_ADDR, sc->sc_enaddr, ETHER_ADDR_LEN );
835
836#if 1
837 /*
838 * This test doesn't work well for AT1700 look-alike by
839 * other vendors.
840 */
841 /* Make sure the vendor part is for Allied-Telesis. */
842 if ( sc->sc_enaddr[ 0 ] != 0x00
843 || sc->sc_enaddr[ 1 ] != 0x00
844 || sc->sc_enaddr[ 2 ] != 0xF4 ) return 0;
845
846#else
847 /* Make sure we got a valid station address. */
848 if ( ( sc->sc_enaddr[ 0 ] & 0x03 ) != 0x00
849 || ( sc->sc_enaddr[ 0 ] == 0x00
850 && sc->sc_enaddr[ 1 ] == 0x00
851 && sc->sc_enaddr[ 2 ] == 0x00 ) ) return 0;
852#endif
853
854 /* Should find all register prototypes here. FIXME. */
855 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL; /* FIXME */
856 sc->proto_dlcr5 = 0;
857 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_EC;
858
859 /*
860 * Program the 86960 as follows:
861 * SRAM: 32KB, 100ns, byte-wide access.
862 * Transmission buffer: 4KB x 2.
863 * System bus interface: 16 bits.
864 * We cannot change these values but TXBSIZE, because they
865 * are hard-wired on the board. Modifying TXBSIZE will affect
866 * the driver performance.
867 */
868 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
869 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
870
871#if FE_DEBUG >= 3
872 fe_dump( LOG_INFO, sc, "ATI found" );
873#endif
874
875 /* Initialize 86965. */
876 outb( sc->addr + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
877 DELAY(200);
878
879 /* Disable all interrupts. */
880 outb( sc->addr + FE_DLCR2, 0 );
881 outb( sc->addr + FE_DLCR3, 0 );
882
883#if FE_DEBUG >= 3
884 fe_dump( LOG_INFO, sc, "end of fe_probe_ati()" );
885#endif
886
887 /*
888 * That's all. AT1700 occupies 32 I/O addresses, by the way.
889 */
890 return 32;
891}
892
893/*
894 * Probe and initialization for Fujitsu MBH10302 PCMCIA Ethernet interface.
895 */
896static int
897fe_probe_mbh ( struct isa_device * isa_dev, struct fe_softc * sc )
898{
899 static struct fe_simple_probe_struct probe_table [] = {
900 { FE_DLCR2, 0x70, 0x00 },
901 { FE_DLCR4, 0x08, 0x00 },
902 /* { FE_DLCR5, 0x80, 0x00 }, Does not work well. */
903#if 0
904 /*
905 * Test *vendor* part of the address for Fujitsu.
906 * The test will gain reliability of probe process, but
907 * it rejects clones by other vendors, or OEM product
908 * supplied by resalers other than Fujitsu.
909 */
910 { FE_MBH10, 0xFF, 0x00 },
911 { FE_MBH11, 0xFF, 0x00 },
912 { FE_MBH12, 0xFF, 0x0E },
913#else
914 /*
915 * We can always verify the *first* 2 bits (in Ehternet
916 * bit order) are "global" and "unicast" even for
917 * unknown vendors.
918 */
919 { FE_MBH10, 0x03, 0x00 },
920#endif
921 /* Just a gap? Seems reliable, anyway. */
922 { 0x12, 0xFF, 0x00 },
923 { 0x13, 0xFF, 0x00 },
924 { 0x14, 0xFF, 0x00 },
925 { 0x15, 0xFF, 0x00 },
926 { 0x16, 0xFF, 0x00 },
927 { 0x17, 0xFF, 0x00 },
928 { 0x18, 0xFF, 0xFF },
929 { 0x19, 0xFF, 0xFF },
930
931 { 0 }
932 };
933
934#if 0
935 /*
936 * We need a PCMCIA flag.
937 */
938 if ( ( isa_dev->id_flags & FE_FLAGS_PCMCIA ) == 0 ) return ( 0 );
939#endif
940
941 /*
942 * We need explicit IRQ and supported address.
943 */
944 if ( isa_dev->id_irq == 0 || ( sc->addr & ~0x3E0 ) != 0 ) return ( 0 );
945
946#if FE_DEBUG >= 3
947 fe_dump( LOG_INFO, sc, "top of probe" );
948#endif
949
950 /*
951 * See if MBH10302 is on its address.
952 * I'm not sure the following probe code works. FIXME.
953 */
954 if ( !fe_simple_probe( sc->addr, probe_table ) ) return 0;
955
956 /* Determine the card type. */
957 sc->type = FE_TYPE_MBH10302;
958 sc->typestr = "MBH10302 (PCMCIA)";
959 sc->sc_description = "Ethernet adapter: MBH10302 (PCMCIA)";
960
961 /*
962 * Initialize constants in the per-line structure.
963 */
964
965 /* Get our station address from EEPROM. */
966 inblk( sc->addr + FE_MBH10, sc->sc_enaddr, ETHER_ADDR_LEN );
967
968 /* Make sure we got a valid station address. */
969 if ( ( sc->sc_enaddr[ 0 ] & 0x03 ) != 0x00
970 || ( sc->sc_enaddr[ 0 ] == 0x00
971 && sc->sc_enaddr[ 1 ] == 0x00
972 && sc->sc_enaddr[ 2 ] == 0x00 ) ) return 0;
973
974 /* Should find all register prototypes here. FIXME. */
975 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
976 sc->proto_dlcr5 = 0;
977 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
978
979 /*
980 * Program the 86960 as follows:
981 * SRAM: 32KB, 100ns, byte-wide access.
982 * Transmission buffer: 4KB x 2.
983 * System bus interface: 16 bits.
984 * We cannot change these values but TXBSIZE, because they
985 * are hard-wired on the board. Modifying TXBSIZE will affect
986 * the driver performance.
987 */
988 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB
989 | FE_D6_BBW_BYTE | FE_D6_SBW_WORD | FE_D6_SRAM_100ns;
990
991 /* Setup hooks. We need a special initialization procedure. */
992 sc->init = fe_init_mbh;
993
994 /*
995 * Minimum initialization.
996 */
997
998 /* Wait for a while. I'm not sure this is necessary. FIXME. */
999 DELAY(200);
1000
1001 /* Minimul initialization of 86960. */
1002 outb( sc->addr + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1003 DELAY( 200 );
1004
1005 /* Disable all interrupts. */
1006 outb( sc->addr + FE_DLCR2, 0 );
1007 outb( sc->addr + FE_DLCR3, 0 );
1008
1009#if 1 /* FIXME. */
1010 /* Initialize system bus interface and encoder/decoder operation. */
1011 outb( sc->addr + FE_MBH0, FE_MBH0_MAGIC | FE_MBH0_INTR_DISABLE );
1012#endif
1013
1014 /*
1015 * That's all. MBH10302 occupies 32 I/O addresses, by the way.
1016 */
1017 return 32;
1018}
1019
1020/* MBH specific initialization routine. */
1021static void
1022fe_init_mbh ( struct fe_softc * sc )
1023{
1024 /* Probably required after hot-insertion... */
1025
1026 /* Wait for a while. I'm not sure this is necessary. FIXME. */
1027 DELAY(200);
1028
1029 /* Minimul initialization of 86960. */
1030 outb( sc->addr + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1031 DELAY( 200 );
1032
1033 /* Disable all interrupts. */
1034 outb( sc->addr + FE_DLCR2, 0 );
1035 outb( sc->addr + FE_DLCR3, 0 );
1036
1037 /* Enable master interrupt flag. */
1038 outb( sc->addr + FE_MBH0, FE_MBH0_MAGIC | FE_MBH0_INTR_ENABLE );
1039}
1040
1041/*
1042 * Install interface into kernel networking data structures
1043 */
1044static int
1045fe_attach ( struct isa_device *isa_dev )
1046{
1047 struct fe_softc *sc = &fe_softc[isa_dev->id_unit];
1048
1049 /*
1050 * Initialize ifnet structure
1051 */
1052 sc->sc_if.if_softc = sc;
1053 sc->sc_if.if_unit = sc->sc_unit;
1054 sc->sc_if.if_name = "fe";
1055 sc->sc_if.if_output = ether_output;
1056 sc->sc_if.if_start = fe_start;
1057 sc->sc_if.if_ioctl = fe_ioctl;
1058 sc->sc_if.if_watchdog = fe_watchdog;
1059
1060 /*
1061 * Set default interface flags.
1062 */
1063 sc->sc_if.if_flags = IFF_BROADCAST | IFF_MULTICAST;
1064
1065 /*
1066 * Set maximum size of output queue, if it has not been set.
1067 * It is done here as this driver may be started after the
1068 * system intialization (i.e., the interface is PCMCIA.)
1069 *
1070 * I'm not sure this is really necessary, but, even if it is,
1071 * it should be done somewhere else, e.g., in if_attach(),
1072 * since it must be a common workaround for all network drivers.
1073 * FIXME.
1074 */
1075 if ( sc->sc_if.if_snd.ifq_maxlen == 0 ) {
1076 sc->sc_if.if_snd.ifq_maxlen = ifqmaxlen;
1077 }
1078
1079#if FE_DEBUG >= 3
1080 fe_dump( LOG_INFO, sc, "attach()" );
1081#endif
1082
1083#if FE_SINGLE_TRANSMISSION
1084 /* Override txb config to allocate minimum. */
1085 sc->proto_dlcr6 &= ~FE_D6_TXBSIZ
1086 sc->proto_dlcr6 |= FE_D6_TXBSIZ_2x2KB;
1087#endif
1088
1089 /* Modify hardware config if it is requested. */
1090 if ( isa_dev->id_flags & FE_FLAGS_OVERRIDE_DLCR6 ) {
1091 sc->proto_dlcr6 = isa_dev->id_flags & FE_FLAGS_DLCR6_VALUE;
1092 }
1093
1094 /* Find TX buffer size, based on the hardware dependent proto. */
1095 switch ( sc->proto_dlcr6 & FE_D6_TXBSIZ ) {
1096 case FE_D6_TXBSIZ_2x2KB: sc->txb_size = 2048; break;
1097 case FE_D6_TXBSIZ_2x4KB: sc->txb_size = 4096; break;
1098 case FE_D6_TXBSIZ_2x8KB: sc->txb_size = 8192; break;
1099 default:
1100 /* Oops, we can't work with single buffer configuration. */
1101#if FE_DEBUG >= 2
1102 log( LOG_WARNING, "fe%d: strange TXBSIZ config; fixing\n",
1103 sc->sc_unit );
1104#endif
1105 sc->proto_dlcr6 &= ~FE_D6_TXBSIZ;
1106 sc->proto_dlcr6 |= FE_D6_TXBSIZ_2x2KB;
1107 sc->txb_size = 2048;
1108 break;
1109 }
1110
1111 /* Attach and stop the interface. */
1112 if_attach( &sc->sc_if );
1113 fe_stop( sc->sc_unit ); /* This changes the state to IDLE. */
1125 fe_setlinkaddr( sc );
1114 ether_ifattach(&sc->sc_if);
1115
1116 /* Print additional info when attached. */
1117 printf( "fe%d: address %6D, type %s\n", sc->sc_unit,
1118 sc->sc_enaddr, ":" , sc->typestr );
1119#if FE_DEBUG >= 3
1120 {
1121 int buf, txb, bbw, sbw, ram;
1122
1123 buf = txb = bbw = sbw = ram = -1;
1124 switch ( sc->proto_dlcr6 & FE_D6_BUFSIZ ) {
1125 case FE_D6_BUFSIZ_8KB: buf = 8; break;
1126 case FE_D6_BUFSIZ_16KB: buf = 16; break;
1127 case FE_D6_BUFSIZ_32KB: buf = 32; break;
1128 case FE_D6_BUFSIZ_64KB: buf = 64; break;
1129 }
1130 switch ( sc->proto_dlcr6 & FE_D6_TXBSIZ ) {
1131 case FE_D6_TXBSIZ_2x2KB: txb = 2; break;
1132 case FE_D6_TXBSIZ_2x4KB: txb = 4; break;
1133 case FE_D6_TXBSIZ_2x8KB: txb = 8; break;
1134 }
1135 switch ( sc->proto_dlcr6 & FE_D6_BBW ) {
1136 case FE_D6_BBW_BYTE: bbw = 8; break;
1137 case FE_D6_BBW_WORD: bbw = 16; break;
1138 }
1139 switch ( sc->proto_dlcr6 & FE_D6_SBW ) {
1140 case FE_D6_SBW_BYTE: sbw = 8; break;
1141 case FE_D6_SBW_WORD: sbw = 16; break;
1142 }
1143 switch ( sc->proto_dlcr6 & FE_D6_SRAM ) {
1144 case FE_D6_SRAM_100ns: ram = 100; break;
1145 case FE_D6_SRAM_150ns: ram = 150; break;
1146 }
1147 printf( "fe%d: SRAM %dKB %dbit %dns, TXB %dKBx2, %dbit I/O\n",
1148 sc->sc_unit, buf, bbw, ram, txb, sbw );
1149 }
1150#endif
1151
1152#if NBPFILTER > 0
1153 /* If BPF is in the kernel, call the attach for it. */
1165 bpfattach(&sc->bpf, &sc->sc_if, DLT_EN10MB,
1166 sizeof(struct ether_header));
1154 bpfattach(&sc->sc_if, DLT_EN10MB, sizeof(struct ether_header));
1155#endif
1156 return 1;
1157}
1158
1159/*
1160 * Reset interface.
1161 */
1162static void
1163fe_reset ( int unit )
1164{
1165 /*
1166 * Stop interface and re-initialize.
1167 */
1168 fe_stop(unit);
1169 fe_init(unit);
1170}
1171
1172/*
1173 * Stop everything on the interface.
1174 *
1175 * All buffered packets, both transmitting and receiving,
1176 * if any, will be lost by stopping the interface.
1177 */
1178static void
1179fe_stop ( int unit )
1180{
1181 struct fe_softc *sc = &fe_softc[unit];
1182 int s;
1183
1184 s = splimp();
1185
1186#if FE_DEBUG >= 3
1187 fe_dump( LOG_INFO, sc, "stop()" );
1188#endif
1189
1190 /* Disable interrupts. */
1191 outb( sc->addr + FE_DLCR2, 0x00 );
1192 outb( sc->addr + FE_DLCR3, 0x00 );
1193
1194 /* Stop interface hardware. */
1195 DELAY( 200 );
1196 outb( sc->addr + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1197 DELAY( 200 );
1198
1199 /* Clear all interrupt status. */
1200 outb( sc->addr + FE_DLCR0, 0xFF );
1201 outb( sc->addr + FE_DLCR1, 0xFF );
1202
1203 /* Put the chip in stand-by mode. */
1204 DELAY( 200 );
1205 outb( sc->addr + FE_DLCR7, sc->proto_dlcr7 | FE_D7_POWER_DOWN );
1206 DELAY( 200 );
1207
1208 /* Reset transmitter variables and interface flags. */
1209 sc->sc_if.if_flags &= ~( IFF_OACTIVE | IFF_RUNNING );
1210 sc->sc_if.if_timer = 0;
1211 sc->txb_free = sc->txb_size;
1212 sc->txb_count = 0;
1213 sc->txb_sched = 0;
1214
1215 /* MAR loading can be delayed. */
1216 sc->filter_change = 0;
1217
1218 /* Update config status also. */
1219 sc->sc_dcstate = DC_IDLE;
1220
1221 /* Call a hook. */
1222 if ( sc->stop ) sc->stop( sc );
1223
1224#if FE_DEBUG >= 3
1225 fe_dump( LOG_INFO, sc, "end of stop()" );
1226#endif
1227
1228 (void) splx(s);
1229}
1230
1231/*
1232 * Device timeout/watchdog routine. Entered if the device neglects to
1233 * generate an interrupt after a transmit has been started on it.
1234 */
1235static void
1236fe_watchdog ( struct ifnet *ifp )
1237{
1238 struct fe_softc *sc = (struct fe_softc *)ifp;
1239
1240#if FE_DEBUG >= 1
1241 log( LOG_ERR, "fe%d: transmission timeout (%d+%d)%s\n",
1242 ifp->if_unit, sc->txb_sched, sc->txb_count,
1243 ( ifp->if_flags & IFF_UP ) ? "" : " when down" );
1244#endif
1245#if FE_DEBUG >= 3
1246 fe_dump( LOG_INFO, sc, NULL );
1247#endif
1248
1249 /* Record how many packets are lost by this accident. */
1250 ifp->if_oerrors += sc->txb_sched + sc->txb_count;
1251
1252 /* Put the interface into known initial state. */
1253 if ( ifp->if_flags & IFF_UP ) {
1254 fe_reset( ifp->if_unit );
1255 } else {
1256 fe_stop( ifp->if_unit );
1257 }
1258}
1259
1260/*
1261 * Initialize device.
1262 */
1263static void
1264fe_init ( int unit )
1265{
1266 struct fe_softc *sc = &fe_softc[unit];
1267 int i, s;
1268
1269#if FE_DEBUG >= 3
1270 fe_dump( LOG_INFO, sc, "init()" );
1271#endif
1272
1273 /* We need an address. */
1274 if (sc->sc_if.if_addrlist == 0) {
1275#if FE_DEBUG >= 1
1276 log( LOG_ERR, "fe%d: init() without any address\n",
1277 sc->sc_unit );
1278#endif
1279 return;
1280 }
1281
1282#if FE_DEBUG >= 1
1283 /*
1284 * Make sure we have a valid station address.
1285 * The following test is applicable for any Ethernet interfaces.
1286 * It can be done in somewhere common to all of them. FIXME.
1287 */
1288 if ( ( sc->sc_enaddr[ 0 ] & 0x01 ) != 0
1289 || ( sc->sc_enaddr[ 0 ] == 0x00
1290 && sc->sc_enaddr[ 1 ] == 0x00
1291 && sc->sc_enaddr[ 2 ] == 0x00 ) ) {
1292 log( LOG_ERR, "fe%d: invalid station address (%6D)\n",
1293 sc->sc_unit, sc->sc_enaddr, ":" );
1294 return;
1295 }
1296#endif
1297
1298 /* Start initializing 86960. */
1299 s = splimp();
1300
1301 /* Call a hook. */
1302 if ( sc->init ) sc->init( sc );
1303
1304#if FE_DEBUG >= 3
1305 fe_dump( LOG_INFO, sc, "after init hook" );
1306#endif
1307
1308 /*
1309 * Make sure to disable the chip, also.
1310 * This may also help re-programming the chip after
1311 * hot insertion of PCMCIAs.
1312 */
1313 outb( sc->addr + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
1314
1315 /* Power up the chip and select register bank for DLCRs. */
1316 DELAY(200);
1317 outb( sc->addr + FE_DLCR7,
1318 sc->proto_dlcr7 | FE_D7_RBS_DLCR | FE_D7_POWER_UP );
1319 DELAY(200);
1320
1321 /* Feed the station address. */
1322 outblk( sc->addr + FE_DLCR8, sc->sc_enaddr, ETHER_ADDR_LEN );
1323
1324 /* Clear multicast address filter to receive nothing. */
1325 outb( sc->addr + FE_DLCR7,
1326 sc->proto_dlcr7 | FE_D7_RBS_MAR | FE_D7_POWER_UP );
1327 outblk( sc->addr + FE_MAR8, fe_filter_nothing.data, FE_FILTER_LEN );
1328
1329 /* Select the BMPR bank for runtime register access. */
1330 outb( sc->addr + FE_DLCR7,
1331 sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP );
1332
1333 /* Initialize registers. */
1334 outb( sc->addr + FE_DLCR0, 0xFF ); /* Clear all bits. */
1335 outb( sc->addr + FE_DLCR1, 0xFF ); /* ditto. */
1336 outb( sc->addr + FE_DLCR2, 0x00 );
1337 outb( sc->addr + FE_DLCR3, 0x00 );
1338 outb( sc->addr + FE_DLCR4, sc->proto_dlcr4 );
1339 outb( sc->addr + FE_DLCR5, sc->proto_dlcr5 );
1340 outb( sc->addr + FE_BMPR10, 0x00 );
1341 outb( sc->addr + FE_BMPR11, FE_B11_CTRL_SKIP );
1342 outb( sc->addr + FE_BMPR12, 0x00 );
1343 outb( sc->addr + FE_BMPR13, FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO );
1344 outb( sc->addr + FE_BMPR14, 0x00 );
1345 outb( sc->addr + FE_BMPR15, 0x00 );
1346
1347#if FE_DEBUG >= 3
1348 fe_dump( LOG_INFO, sc, "just before enabling DLC" );
1349#endif
1350
1351 /* Enable interrupts. */
1352 outb( sc->addr + FE_DLCR2, FE_TMASK );
1353 outb( sc->addr + FE_DLCR3, FE_RMASK );
1354
1355 /* Enable transmitter and receiver. */
1356 DELAY(200);
1357 outb( sc->addr + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_ENABLE );
1358 DELAY(200);
1359
1360#if FE_DEBUG >= 3
1361 fe_dump( LOG_INFO, sc, "just after enabling DLC" );
1362#endif
1363 /*
1364 * Make sure to empty the receive buffer.
1365 *
1366 * This may be redundant, but *if* the receive buffer were full
1367 * at this point, the driver would hang. I have experienced
1368 * some strange hangups just after UP. I hope the following
1369 * code solve the problem.
1370 *
1371 * I have changed the order of hardware initialization.
1372 * I think the receive buffer cannot have any packets at this
1373 * point in this version. The following code *must* be
1374 * redundant now. FIXME.
1375 */
1376 for ( i = 0; i < FE_MAX_RECV_COUNT; i++ ) {
1377 if ( inb( sc->addr + FE_DLCR5 ) & FE_D5_BUFEMP ) break;
1378 outb( sc->addr + FE_BMPR14, FE_B14_SKIP );
1379 }
1380#if FE_DEBUG >= 1
1381 if ( i >= FE_MAX_RECV_COUNT ) {
1382 log( LOG_ERR, "fe%d: cannot empty receive buffer\n",
1383 sc->sc_unit );
1384 }
1385#endif
1386#if FE_DEBUG >= 3
1387 if ( i < FE_MAX_RECV_COUNT ) {
1388 log( LOG_INFO, "fe%d: receive buffer emptied (%d)\n",
1389 sc->sc_unit, i );
1390 }
1391#endif
1392
1393#if FE_DEBUG >= 3
1394 fe_dump( LOG_INFO, sc, "after ERB loop" );
1395#endif
1396
1397 /* Do we need this here? */
1398 outb( sc->addr + FE_DLCR0, 0xFF ); /* Clear all bits. */
1399 outb( sc->addr + FE_DLCR1, 0xFF ); /* ditto. */
1400
1401#if FE_DEBUG >= 3
1402 fe_dump( LOG_INFO, sc, "after FIXME" );
1403#endif
1404 /* Set 'running' flag, because we are now running. */
1405 sc->sc_if.if_flags |= IFF_RUNNING;
1406
1407 /* Update device config status. */
1408 sc->sc_dcstate = DC_BUSY;
1409
1410 /*
1411 * At this point, the interface is runnung properly,
1412 * except that it receives *no* packets. we then call
1413 * fe_setmode() to tell the chip what packets to be
1414 * received, based on the if_flags and multicast group
1415 * list. It completes the initialization process.
1416 */
1417 fe_setmode( sc );
1418
1419#if FE_DEBUG >= 3
1420 fe_dump( LOG_INFO, sc, "after setmode" );
1421#endif
1422
1423 /* ...and attempt to start output queued packets. */
1424 fe_start( &sc->sc_if );
1425
1426#if FE_DEBUG >= 3
1427 fe_dump( LOG_INFO, sc, "init() done" );
1428#endif
1429
1430 (void) splx(s);
1431}
1432
1433/*
1434 * This routine actually starts the transmission on the interface
1435 */
1436static INLINE void
1437fe_xmit ( struct fe_softc * sc )
1438{
1439 /*
1440 * Set a timer just in case we never hear from the board again.
1441 * We use longer timeout for multiple packet transmission.
1442 * I'm not sure this timer value is appropriate. FIXME.
1443 */
1444 sc->sc_if.if_timer = 1 + sc->txb_count;
1445
1446 /* Update txb variables. */
1447 sc->txb_sched = sc->txb_count;
1448 sc->txb_count = 0;
1449 sc->txb_free = sc->txb_size;
1450
1451#if FE_DELAYED_PADDING
1452 /* Omit the postponed padding process. */
1453 sc->txb_padding = 0;
1454#endif
1455
1456 /* Start transmitter, passing packets in TX buffer. */
1457 outb( sc->addr + FE_BMPR10, sc->txb_sched | FE_B10_START );
1458}
1459
1460/*
1461 * Start output on interface.
1462 * We make two assumptions here:
1463 * 1) that the current priority is set to splimp _before_ this code
1464 * is called *and* is returned to the appropriate priority after
1465 * return
1466 * 2) that the IFF_OACTIVE flag is checked before this code is called
1467 * (i.e. that the output part of the interface is idle)
1468 */
1469void
1470fe_start ( struct ifnet *ifp )
1471{
1472 struct fe_softc *sc = IFNET2SOFTC( ifp );
1473 struct mbuf *m;
1474
1475#if FE_DEBUG >= 1
1476 /* Just a sanity check. */
1477 if ( ( sc->txb_count == 0 ) != ( sc->txb_free == sc->txb_size ) ) {
1478 /*
1479 * Txb_count and txb_free co-works to manage the
1480 * transmission buffer. Txb_count keeps track of the
1481 * used potion of the buffer, while txb_free does unused
1482 * potion. So, as long as the driver runs properly,
1483 * txb_count is zero if and only if txb_free is same
1484 * as txb_size (which represents whole buffer.)
1485 */
1486 log( LOG_ERR, "fe%d: inconsistent txb variables (%d, %d)\n",
1487 sc->sc_unit, sc->txb_count, sc->txb_free );
1488 /*
1489 * So, what should I do, then?
1490 *
1491 * We now know txb_count and txb_free contradicts. We
1492 * cannot, however, tell which is wrong. More
1493 * over, we cannot peek 86960 transmission buffer or
1494 * reset the transmission buffer. (In fact, we can
1495 * reset the entire interface. I don't want to do it.)
1496 *
1497 * If txb_count is incorrect, leaving it as is will cause
1498 * sending of gabages after next interrupt. We have to
1499 * avoid it. Hence, we reset the txb_count here. If
1500 * txb_free was incorrect, resetting txb_count just loose
1501 * some packets. We can live with it.
1502 */
1503 sc->txb_count = 0;
1504 }
1505#endif
1506
1507#if FE_DEBUG >= 1
1508 /*
1509 * First, see if there are buffered packets and an idle
1510 * transmitter - should never happen at this point.
1511 */
1512 if ( ( sc->txb_count > 0 ) && ( sc->txb_sched == 0 ) ) {
1513 log( LOG_ERR,
1514 "fe%d: transmitter idle with %d buffered packets\n",
1515 sc->sc_unit, sc->txb_count );
1516 fe_xmit( sc );
1517 }
1518#endif
1519
1520 /*
1521 * Stop accepting more transmission packets temporarily, when
1522 * a filter change request is delayed. Updating the MARs on
1523 * 86960 flushes the transmisstion buffer, so it is delayed
1524 * until all buffered transmission packets have been sent
1525 * out.
1526 */
1527 if ( sc->filter_change ) {
1528 /*
1529 * Filter change requst is delayed only when the DLC is
1530 * working. DLC soon raise an interrupt after finishing
1531 * the work.
1532 */
1533 goto indicate_active;
1534 }
1535
1536 for (;;) {
1537
1538 /*
1539 * See if there is room to put another packet in the buffer.
1540 * We *could* do better job by peeking the send queue to
1541 * know the length of the next packet. Current version just
1542 * tests against the worst case (i.e., longest packet). FIXME.
1543 *
1544 * When adding the packet-peek feature, don't forget adding a
1545 * test on txb_count against QUEUEING_MAX.
1546 * There is a little chance the packet count exceeds
1547 * the limit. Assume transmission buffer is 8KB (2x8KB
1548 * configuration) and an application sends a bunch of small
1549 * (i.e., minimum packet sized) packets rapidly. An 8KB
1550 * buffer can hold 130 blocks of 62 bytes long...
1551 */
1552 if ( sc->txb_free < ETHER_MAX_LEN + FE_DATA_LEN_LEN ) {
1553 /* No room. */
1554 goto indicate_active;
1555 }
1556
1557#if FE_SINGLE_TRANSMISSION
1558 if ( sc->txb_count > 0 ) {
1559 /* Just one packet per a transmission buffer. */
1560 goto indicate_active;
1561 }
1562#endif
1563
1564 /*
1565 * Get the next mbuf chain for a packet to send.
1566 */
1567 IF_DEQUEUE( &sc->sc_if.if_snd, m );
1568 if ( m == NULL ) {
1569 /* No more packets to send. */
1570 goto indicate_inactive;
1571 }
1572
1573 /*
1574 * Copy the mbuf chain into the transmission buffer.
1575 * txb_* variables are updated as necessary.
1576 */
1577 fe_write_mbufs( sc, m );
1578
1579 /* Start transmitter if it's idle. */
1580 if ( sc->txb_sched == 0 ) fe_xmit( sc );
1581
1582#if 0 /* Turned of, since our interface is now duplex. */
1583 /*
1584 * Tap off here if there is a bpf listener.
1585 */
1586#if NBPFILTER > 0
1587 if ( sc->bpf ) bpf_mtap( sc->bpf, m );
1588#endif
1589#endif
1590
1591 m_freem( m );
1592 }
1593
1594 indicate_inactive:
1595 /*
1596 * We are using the !OACTIVE flag to indicate to
1597 * the outside world that we can accept an
1598 * additional packet rather than that the
1599 * transmitter is _actually_ active. Indeed, the
1600 * transmitter may be active, but if we haven't
1601 * filled all the buffers with data then we still
1602 * want to accept more.
1603 */
1604 sc->sc_if.if_flags &= ~IFF_OACTIVE;
1605 return;
1606
1607 indicate_active:
1608 /*
1609 * The transmitter is active, and there are no room for
1610 * more outgoing packets in the transmission buffer.
1611 */
1612 sc->sc_if.if_flags |= IFF_OACTIVE;
1613 return;
1614}
1615
1616/*
1617 * Drop (skip) a packet from receive buffer in 86960 memory.
1618 */
1619static INLINE void
1620fe_droppacket ( struct fe_softc * sc )
1621{
1622 outb( sc->addr + FE_BMPR14, FE_B14_SKIP );
1623}
1624
1625/*
1626 * Transmission interrupt handler
1627 * The control flow of this function looks silly. FIXME.
1628 */
1629static void
1630fe_tint ( struct fe_softc * sc, u_char tstat )
1631{
1632 int left;
1633 int col;
1634
1635 /*
1636 * Handle "excessive collision" interrupt.
1637 */
1638 if ( tstat & FE_D0_COLL16 ) {
1639
1640 /*
1641 * Find how many packets (including this collided one)
1642 * are left unsent in transmission buffer.
1643 */
1644 left = inb( sc->addr + FE_BMPR10 );
1645
1646#if FE_DEBUG >= 2
1647 log( LOG_WARNING, "fe%d: excessive collision (%d/%d)\n",
1648 sc->sc_unit, left, sc->txb_sched );
1649#endif
1650#if FE_DEBUG >= 3
1651 fe_dump( LOG_INFO, sc, NULL );
1652#endif
1653
1654 /*
1655 * Update statistics.
1656 */
1657 sc->sc_if.if_collisions += 16;
1658 sc->sc_if.if_oerrors++;
1659 sc->sc_if.if_opackets += sc->txb_sched - left;
1660
1661 /*
1662 * Collision statistics has been updated.
1663 * Clear the collision flag on 86960 now to avoid confusion.
1664 */
1665 outb( sc->addr + FE_DLCR0, FE_D0_COLLID );
1666
1667 /*
1668 * Restart transmitter, skipping the
1669 * collided packet.
1670 *
1671 * We *must* skip the packet to keep network running
1672 * properly. Excessive collision error is an
1673 * indication of the network overload. If we
1674 * tried sending the same packet after excessive
1675 * collision, the network would be filled with
1676 * out-of-time packets. Packets belonging
1677 * to reliable transport (such as TCP) are resent
1678 * by some upper layer.
1679 */
1680 outb( sc->addr + FE_BMPR11,
1681 FE_B11_CTRL_SKIP | FE_B11_MODE1 );
1682 sc->txb_sched = left - 1;
1683 }
1684
1685 /*
1686 * Handle "transmission complete" interrupt.
1687 */
1688 if ( tstat & FE_D0_TXDONE ) {
1689
1690 /*
1691 * Add in total number of collisions on last
1692 * transmission. We also clear "collision occurred" flag
1693 * here.
1694 *
1695 * 86960 has a design flaw on collision count on multiple
1696 * packet transmission. When we send two or more packets
1697 * with one start command (that's what we do when the
1698 * transmission queue is clauded), 86960 informs us number
1699 * of collisions occured on the last packet on the
1700 * transmission only. Number of collisions on previous
1701 * packets are lost. I have told that the fact is clearly
1702 * stated in the Fujitsu document.
1703 *
1704 * I considered not to mind it seriously. Collision
1705 * count is not so important, anyway. Any comments? FIXME.
1706 */
1707
1708 if ( inb( sc->addr + FE_DLCR0 ) & FE_D0_COLLID ) {
1709
1710 /* Clear collision flag. */
1711 outb( sc->addr + FE_DLCR0, FE_D0_COLLID );
1712
1713 /* Extract collision count from 86960. */
1714 col = inb( sc->addr + FE_DLCR4 );
1715 col = ( col & FE_D4_COL ) >> FE_D4_COL_SHIFT;
1716 if ( col == 0 ) {
1717 /*
1718 * Status register indicates collisions,
1719 * while the collision count is zero.
1720 * This can happen after multiple packet
1721 * transmission, indicating that one or more
1722 * previous packet(s) had been collided.
1723 *
1724 * Since the accurate number of collisions
1725 * has been lost, we just guess it as 1;
1726 * Am I too optimistic? FIXME.
1727 */
1728 col = 1;
1729 }
1730 sc->sc_if.if_collisions += col;
1731#if FE_DEBUG >= 3
1732 log( LOG_WARNING, "fe%d: %d collision(s) (%d)\n",
1733 sc->sc_unit, col, sc->txb_sched );
1734#endif
1735 }
1736
1737 /*
1738 * Update total number of successfully
1739 * transmitted packets.
1740 */
1741 sc->sc_if.if_opackets += sc->txb_sched;
1742 sc->txb_sched = 0;
1743
1744 /*
1745 * The transmitter is no more active.
1746 * Reset output active flag and watchdog timer.
1747 */
1748 sc->sc_if.if_flags &= ~IFF_OACTIVE;
1749 sc->sc_if.if_timer = 0;
1750
1751 /*
1752 * If more data is ready to transmit in the buffer, start
1753 * transmitting them. Otherwise keep transmitter idle,
1754 * even if more data is queued. This gives receive
1755 * process a slight priority.
1756 */
1757 if ( sc->txb_count > 0 ) fe_xmit( sc );
1758 }
1759}
1760
1761/*
1762 * Ethernet interface receiver interrupt.
1763 */
1764static void
1765fe_rint ( struct fe_softc * sc, u_char rstat )
1766{
1767 u_short len;
1768 u_char status;
1769 int i;
1770
1771 /*
1772 * Update statistics if this interrupt is caused by an error.
1773 */
1774 if ( rstat & ( FE_D1_OVRFLO | FE_D1_CRCERR
1775 | FE_D1_ALGERR | FE_D1_SRTPKT ) ) {
1776#if FE_DEBUG >= 3
1777 log( LOG_WARNING,
1778 "fe%d: receive error: %s%s%s%s(%02x)\n",
1779 sc->sc_unit,
1780 rstat & FE_D1_OVRFLO ? "OVR " : "",
1781 rstat & FE_D1_CRCERR ? "CRC " : "",
1782 rstat & FE_D1_ALGERR ? "ALG " : "",
1783 rstat & FE_D1_SRTPKT ? "LEN " : "",
1784 rstat );
1785#endif
1786 sc->sc_if.if_ierrors++;
1787 }
1788
1789 /*
1790 * MB86960 has a flag indicating "receive queue empty."
1791 * We just loop cheking the flag to pull out all received
1792 * packets.
1793 *
1794 * We limit the number of iterrations to avoid inifnit-loop.
1795 * It can be caused by a very slow CPU (some broken
1796 * peripheral may insert incredible number of wait cycles)
1797 * or, worse, by a broken MB86960 chip.
1798 */
1799 for ( i = 0; i < FE_MAX_RECV_COUNT; i++ ) {
1800
1801 /* Stop the iterration if 86960 indicates no packets. */
1802 if ( inb( sc->addr + FE_DLCR5 ) & FE_D5_BUFEMP ) break;
1803
1804 /*
1805 * Extract A receive status byte.
1806 * As our 86960 is in 16 bit bus access mode, we have to
1807 * use inw() to get the status byte. The significant
1808 * value is returned in lower 8 bits.
1809 */
1810 status = ( u_char )inw( sc->addr + FE_BMPR8 );
1811#if FE_DEBUG >= 4
1812 log( LOG_INFO, "fe%d: receive status = %04x\n",
1813 sc->sc_unit, status );
1814#endif
1815
1816 /*
1817 * If there was an error, update statistics and drop
1818 * the packet, unless the interface is in promiscuous
1819 * mode.
1820 */
1821 if ( ( status & 0xF0 ) != 0x20 ) {
1822 if ( !( sc->sc_if.if_flags & IFF_PROMISC ) ) {
1823 sc->sc_if.if_ierrors++;
1824 fe_droppacket(sc);
1825 continue;
1826 }
1827 }
1828
1829 /*
1830 * Extract the packet length.
1831 * It is a sum of a header (14 bytes) and a payload.
1832 * CRC has been stripped off by the 86960.
1833 */
1834 len = inw( sc->addr + FE_BMPR8 );
1835
1836 /*
1837 * MB86965 checks the packet length and drop big packet
1838 * before passing it to us. There are no chance we can
1839 * get [crufty] packets. Hence, if the length exceeds
1840 * the specified limit, it means some serious failure,
1841 * such as out-of-sync on receive buffer management.
1842 *
1843 * Is this statement true? FIXME.
1844 */
1845 if ( len > ETHER_MAX_LEN || len < ETHER_HDR_SIZE ) {
1846#if FE_DEBUG >= 2
1847 log( LOG_WARNING,
1848 "fe%d: received a %s packet? (%u bytes)\n",
1849 sc->sc_unit,
1850 len < ETHER_HDR_SIZE ? "partial" : "big",
1851 len );
1852#endif
1853 sc->sc_if.if_ierrors++;
1854 fe_droppacket( sc );
1855 continue;
1856 }
1857
1858 /*
1859 * Check for a short (RUNT) packet. We *do* check
1860 * but do nothing other than print a message.
1861 * Short packets are illegal, but does nothing bad
1862 * if it carries data for upper layer.
1863 */
1864#if FE_DEBUG >= 2
1865 if ( len < ETHER_MIN_LEN ) {
1866 log( LOG_WARNING,
1867 "fe%d: received a short packet? (%u bytes)\n",
1868 sc->sc_unit, len );
1869 }
1870#endif
1871
1872 /*
1873 * Go get a packet.
1874 */
1875 if ( fe_get_packet( sc, len ) < 0 ) {
1876 /* Skip a packet, updating statistics. */
1877#if FE_DEBUG >= 2
1878 log( LOG_WARNING, "%s%d: no enough mbuf;"
1879 " a packet (%u bytes) dropped\n",
1880 sc->sc_unit, len );
1881#endif
1882 sc->sc_if.if_ierrors++;
1883 fe_droppacket( sc );
1884
1885 /*
1886 * We stop receiving packets, even if there are
1887 * more in the buffer. We hope we can get more
1888 * mbuf next time.
1889 */
1890 return;
1891 }
1892
1893 /* Successfully received a packet. Update stat. */
1894 sc->sc_if.if_ipackets++;
1895 }
1896}
1897
1898/*
1899 * Ethernet interface interrupt processor
1900 */
1901void
1902feintr ( int unit )
1903{
1904 struct fe_softc *sc = &fe_softc[unit];
1905 u_char tstat, rstat;
1906
1907 /*
1908 * Loop until there are no more new interrupt conditions.
1909 */
1910 for (;;) {
1911
1912#if FE_DEBUG >= 4
1913 fe_dump( LOG_INFO, sc, "intr()" );
1914#endif
1915
1916 /*
1917 * Get interrupt conditions, masking unneeded flags.
1918 */
1919 tstat = inb( sc->addr + FE_DLCR0 ) & FE_TMASK;
1920 rstat = inb( sc->addr + FE_DLCR1 ) & FE_RMASK;
1921 if ( tstat == 0 && rstat == 0 ) break;
1922
1923 /*
1924 * Reset the conditions we are acknowledging.
1925 */
1926 outb( sc->addr + FE_DLCR0, tstat );
1927 outb( sc->addr + FE_DLCR1, rstat );
1928
1929 /*
1930 * Handle transmitter interrupts. Handle these first because
1931 * the receiver will reset the board under some conditions.
1932 */
1933 if ( tstat ) {
1934 fe_tint( sc, tstat );
1935 }
1936
1937 /*
1938 * Handle receiver interrupts
1939 */
1940 if ( rstat ) {
1941 fe_rint( sc, rstat );
1942 }
1943
1944 /*
1945 * Update the multicast address filter if it is
1946 * needed and possible. We do it now, because
1947 * we can make sure the transmission buffer is empty,
1948 * and there is a good chance that the receive queue
1949 * is empty. It will minimize the possibility of
1950 * packet lossage.
1951 */
1952 if ( sc->filter_change
1953 && sc->txb_count == 0 && sc->txb_sched == 0 ) {
1954 fe_loadmar(sc);
1955 sc->sc_if.if_flags &= ~IFF_OACTIVE;
1956 }
1957
1958 /*
1959 * If it looks like the transmitter can take more data,
1960 * attempt to start output on the interface. This is done
1961 * after handling the receiver interrupt to give the
1962 * receive operation priority.
1963 *
1964 * BTW, I'm not sure in what case the OACTIVE is on at
1965 * this point. Is the following test redundant?
1966 *
1967 * No. This routine polls for both transmitter and
1968 * receiver interrupts. 86960 can raise a receiver
1969 * interrupt when the transmission buffer is full.
1970 */
1971 if ( ( sc->sc_if.if_flags & IFF_OACTIVE ) == 0 ) {
1972 fe_start( &sc->sc_if );
1973 }
1974
1975 }
1976}
1977
1978/*
1979 * Process an ioctl request. This code needs some work - it looks
1980 * pretty ugly.
1981 */
1982int
1983fe_ioctl ( struct ifnet *ifp, int command, caddr_t data )
1984{
1985 struct fe_softc *sc = IFNET2SOFTC( ifp );
1986 int s, error = 0;
1987
1988#if FE_DEBUG >= 3
1989 log( LOG_INFO, "fe%d: ioctl(%x)\n", sc->sc_unit, command );
1990#endif
1991
1992 s = splimp();
1993
1994 switch (command) {
1995
1996 case SIOCSIFADDR:
1997 {
1998 struct ifaddr * ifa = ( struct ifaddr * )data;
1999
2000 sc->sc_if.if_flags |= IFF_UP;
2001
2002 switch (ifa->ifa_addr->sa_family) {
2003#ifdef INET
2004 case AF_INET:
2005 fe_init( sc->sc_unit ); /* before arpwhohas */
2006 arp_ifinit( &sc->arpcom, ifa );
2007 break;
2008#endif
2009#ifdef IPX
2010
2011 /*
2012 * XXX - This code is probably wrong
2013 */
2014 case AF_IPX:
2015 {
2016 register struct ipx_addr *ina
2017 = &(IA_SIPX(ifa)->sipx_addr);
2018
2019 if (ipx_nullhost(*ina))
2020 ina->x_host =
2021 *(union ipx_host *) (sc->sc_enaddr);
2022 else {
2023 bcopy((caddr_t) ina->x_host.c_host,
2024 (caddr_t) sc->sc_enaddr,
2025 sizeof(sc->sc_enaddr));
2026 }
2027
2028 /*
2029 * Set new address
2030 */
2031 fe_init(sc->sc_unit);
2032 break;
2033 }
2034#endif
2035#ifdef NS
2036
2037 /*
2038 * XXX - This code is probably wrong
2039 */
2040 case AF_NS:
2041 {
2042 register struct ns_addr *ina
2043 = &(IA_SNS(ifa)->sns_addr);
2044
2045 if (ns_nullhost(*ina))
2046 ina->x_host =
2047 *(union ns_host *) (sc->sc_enaddr);
2048 else {
2049 bcopy((caddr_t) ina->x_host.c_host,
2050 (caddr_t) sc->sc_enaddr,
2051 sizeof(sc->sc_enaddr));
2052 }
2053
2054 /*
2055 * Set new address
2056 */
2057 fe_init(sc->sc_unit);
2058 break;
2059 }
2060#endif
2061 default:
2062 fe_init( sc->sc_unit );
2063 break;
2064 }
2065 break;
2066 }
2067
2068#ifdef SIOCGIFADDR
2069 case SIOCGIFADDR:
2070 {
2071 struct ifreq * ifr = ( struct ifreq * )data;
2072 struct sockaddr * sa = ( struct sockaddr * )&ifr->ifr_data;
2073
2074 bcopy((caddr_t)sc->sc_enaddr,
2075 (caddr_t)sa->sa_data, ETHER_ADDR_LEN);
2076 break;
2077 }
2078#endif
2079
2080#ifdef SIOCGIFPHYSADDR
2081 case SIOCGIFPHYSADDR:
2082 {
2083 struct ifreq * ifr = ( struct ifreq * )data;
2084
2085 bcopy((caddr_t)sc->sc_enaddr,
2086 (caddr_t)&ifr->ifr_data, ETHER_ADDR_LEN);
2087 break;
2088 }
2089#endif
2090
2091#ifdef notdef
2092#ifdef SIOCSIFPHYSADDR
2093 case SIOCSIFPHYSADDR:
2094 {
2095 /*
2096 * Set the physical (Ehternet) address of the interface.
2097 * When and by whom is this command used? FIXME.
2098 */
2099 struct ifreq * ifr = ( struct ifreq * )data;
2100
2101 bcopy((caddr_t)&ifr->ifr_data,
2102 (caddr_t)sc->sc_enaddr, ETHER_ADDR_LEN);
2103 fe_setlinkaddr( sc );
2104 break;
2105 }
2106#endif
2107#endif /* notdef */
2108
2109#ifdef SIOCSIFFLAGS
2110 case SIOCSIFFLAGS:
2111 {
2112 /*
2113 * Switch interface state between "running" and
2114 * "stopped", reflecting the UP flag.
2115 */
2116 if ( sc->sc_if.if_flags & IFF_UP ) {
2117 if ( ( sc->sc_if.if_flags & IFF_RUNNING ) == 0 ) {
2118 fe_init( sc->sc_unit );
2119 }
2120 } else {
2121 if ( ( sc->sc_if.if_flags & IFF_RUNNING ) != 0 ) {
2122 fe_stop( sc->sc_unit );
2123 }
2124 }
2125
2126 /*
2127 * Promiscuous and/or multicast flags may have changed,
2128 * so reprogram the multicast filter and/or receive mode.
2129 */
2130 fe_setmode( sc );
2131
2132#if FE_DEBUG >= 1
2133 /* "ifconfig fe0 debug" to print register dump. */
2134 if ( sc->sc_if.if_flags & IFF_DEBUG ) {
2135 fe_dump( LOG_DEBUG, sc, "SIOCSIFFLAGS(DEBUG)" );
2136 }
2137#endif
2138 break;
2139 }
2140#endif
2141
2142#ifdef SIOCADDMULTI
2143 case SIOCADDMULTI:
2144 case SIOCDELMULTI:
2145 {
2146 /*
2147 * Update out multicast list.
2148 */
2149 struct ifreq * ifr = ( struct ifreq * )data;
2150
2151 error = ( command == SIOCADDMULTI )
2152 ? ether_addmulti( ifr, &sc->arpcom )
2153 : ether_delmulti( ifr, &sc->arpcom );
2154
2155 if ( error == ENETRESET ) {
2156 /*
2157 * Multicast list has changed; set the hardware filter
2158 * accordingly.
2159 */
2160 fe_setmode( sc );
2161 error = 0;
2162 }
2163
2164 break;
2165 }
2166#endif
2167
2168#ifdef SIOCSIFMTU
2169 case SIOCSIFMTU:
2170 {
2171 /*
2172 * Set the interface MTU.
2173 */
2174 struct ifreq * ifr = ( struct ifreq * )data;
2175
2176 if ( ifr->ifr_mtu > ETHERMTU ) {
2177 error = EINVAL;
2178 } else {
2179 sc->sc_if.if_mtu = ifr->ifr_mtu;
2180 }
2181 break;
2182 }
2183#endif
2184
2185 default:
2186 error = EINVAL;
2187 }
2188
2189 (void) splx(s);
2190 return (error);
2191}
2192
2193/*
2194 * Retreive packet from receive buffer and send to the next level up via
2195 * ether_input(). If there is a BPF listener, give a copy to BPF, too.
2196 * Returns 0 if success, -1 if error (i.e., mbuf allocation failure).
2197 */
2198static int
2199fe_get_packet ( struct fe_softc * sc, u_short len )
2200{
2201 struct ether_header *eh;
2202 struct mbuf *m;
2203
2204 /*
2205 * NFS wants the data be aligned to the word (4 byte)
2206 * boundary. Ethernet header has 14 bytes. There is a
2207 * 2-byte gap.
2208 */
2209#define NFS_MAGIC_OFFSET 2
2210
2211 /*
2212 * This function assumes that an Ethernet packet fits in an
2213 * mbuf (with a cluster attached when necessary.) On FreeBSD
2214 * 2.0 for x86, which is the primary target of this driver, an
2215 * mbuf cluster has 4096 bytes, and we are happy. On ancient
2216 * BSDs, such as vanilla 4.3 for 386, a cluster size was 1024,
2217 * however. If the following #error message were printed upon
2218 * compile, you need to rewrite this function.
2219 */
2220#if ( MCLBYTES < ETHER_MAX_LEN + NFS_MAGIC_OFFSET )
2221#error "Too small MCLBYTES to use fe driver."
2222#endif
2223
2224 /*
2225 * Our strategy has one more problem. There is a policy on
2226 * mbuf cluster allocation. It says that we must have at
2227 * least MINCLSIZE (208 bytes on FreeBSD 2.0 for x86) to
2228 * allocate a cluster. For a packet of a size between
2229 * (MHLEN - 2) to (MINCLSIZE - 2), our code violates the rule...
2230 * On the other hand, the current code is short, simle,
2231 * and fast, however. It does no harmful thing, just waists
2232 * some memory. Any comments? FIXME.
2233 */
2234
2235 /* Allocate an mbuf with packet header info. */
2236 MGETHDR(m, M_DONTWAIT, MT_DATA);
2237 if ( m == NULL ) return -1;
2238
2239 /* Attach a cluster if this packet doesn't fit in a normal mbuf. */
2240 if ( len > MHLEN - NFS_MAGIC_OFFSET ) {
2241 MCLGET( m, M_DONTWAIT );
2242 if ( !( m->m_flags & M_EXT ) ) {
2243 m_freem( m );
2244 return -1;
2245 }
2246 }
2247
2248 /* Initialize packet header info. */
2249 m->m_pkthdr.rcvif = &sc->sc_if;
2250 m->m_pkthdr.len = len;
2251
2252 /* Set the length of this packet. */
2253 m->m_len = len;
2254
2255 /* The following sillines is to make NFS happy */
2256 m->m_data += NFS_MAGIC_OFFSET;
2257
2258 /* Get a packet. */
2259 insw( sc->addr + FE_BMPR8, m->m_data, ( len + 1 ) >> 1 );
2260
2261 /* Get (actually just point to) the header part. */
2262 eh = mtod( m, struct ether_header *);
2263
2264#define ETHER_ADDR_IS_MULTICAST(A) (*(char *)(A) & 1)
2265
2266#if NBPFILTER > 0
2267 /*
2268 * Check if there's a BPF listener on this interface.
2269 * If it is, hand off the raw packet to bpf.
2270 */
2281 if ( sc->bpf ) {
2282 bpf_mtap( sc->bpf, m );
2271 if ( sc->sc_if.if_bpf ) {
2272 bpf_mtap( &sc->sc_if, m );
2273 }
2274#endif
2275
2276 /*
2277 * Make sure this packet is (or may be) directed to us.
2278 * That is, the packet is either unicasted to our address,
2279 * or broad/multi-casted. If any other packets are
2280 * received, it is an indication of an error -- probably
2281 * 86960 is in a wrong operation mode.
2282 * Promiscuous mode is an exception. Under the mode, all
2283 * packets on the media must be received. (We must have
2284 * programmed the 86960 so.)
2285 */
2286
2287 if ( ( sc->sc_if.if_flags & IFF_PROMISC )
2288 && !ETHER_ADDR_IS_MULTICAST( eh->ether_dhost )
2289 && bcmp( eh->ether_dhost, sc->sc_enaddr, ETHER_ADDR_LEN ) != 0 ) {
2290 /*
2291 * The packet was not for us. This is normal since
2292 * we are now in promiscuous mode. Just drop the packet.
2293 */
2294 m_freem( m );
2295 return 0;
2296 }
2297
2298#if FE_DEBUG >= 3
2299 if ( !ETHER_ADDR_IS_MULTICAST( eh->ether_dhost )
2300 && bcmp( eh->ether_dhost, sc->sc_enaddr, ETHER_ADDR_LEN ) != 0 ) {
2301 /*
2302 * This packet was not for us. We can't be in promiscuous
2303 * mode since the case was handled by above test.
2304 * We found an error (of this driver.)
2305 */
2306 log( LOG_WARNING,
2307 "fe%d: got an unwanted packet, dst = %6D\n",
2308 sc->sc_unit,
2309 eh->ether_dhost , ":" );
2310 m_freem( m );
2311 return 0;
2312 }
2313#endif
2314
2315 /* Strip off the Ethernet header. */
2316 m->m_pkthdr.len -= sizeof ( struct ether_header );
2317 m->m_len -= sizeof ( struct ether_header );
2318 m->m_data += sizeof ( struct ether_header );
2319
2320 /* Feed the packet to upper layer. */
2321 ether_input( &sc->sc_if, eh, m );
2322 return 0;
2323}
2324
2325/*
2326 * Write an mbuf chain to the transmission buffer memory using 16 bit PIO.
2327 * Returns number of bytes actually written, including length word.
2328 *
2329 * If an mbuf chain is too long for an Ethernet frame, it is not sent.
2330 * Packets shorter than Ethernet minimum are legal, and we pad them
2331 * before sending out. An exception is "partial" packets which are
2332 * shorter than mandatory Ethernet header.
2333 *
2334 * I wrote a code for an experimental "delayed padding" technique.
2335 * When employed, it postpones the padding process for short packets.
2336 * If xmit() occured at the moment, the padding process is omitted, and
2337 * garbages are sent as pad data. If next packet is stored in the
2338 * transmission buffer before xmit(), write_mbuf() pads the previous
2339 * packet before transmitting new packet. This *may* gain the
2340 * system performance (slightly).
2341 */
2342static void
2343fe_write_mbufs ( struct fe_softc *sc, struct mbuf *m )
2344{
2345 u_short addr_bmpr8 = sc->addr + FE_BMPR8;
2346 u_short length, len;
2347 short pad;
2348 struct mbuf *mp;
2349 u_char *data;
2350 u_short savebyte; /* WARNING: Architecture dependent! */
2351#define NO_PENDING_BYTE 0xFFFF
2352
2353#if FE_DELAYED_PADDING
2354 /* Do the "delayed padding." */
2355 pad = sc->txb_padding >> 1;
2356 if ( pad > 0 ) {
2357 while ( --pad >= 0 ) {
2358 outw( addr_bmpr8, 0 );
2359 }
2360 sc->txb_padding = 0;
2361 }
2362#endif
2363
2364#if FE_DEBUG >= 2
2365 /* First, count up the total number of bytes to copy */
2366 length = 0;
2367 for ( mp = m; mp != NULL; mp = mp->m_next ) {
2368 length += mp->m_len;
2369 }
2370 /* Check if this matches the one in the packet header. */
2371 if ( length != m->m_pkthdr.len ) {
2372 log( LOG_WARNING, "fe%d: packet length mismatch? (%d/%d)\n",
2373 sc->sc_unit, length, m->m_pkthdr.len );
2374 }
2375#else
2376 /* Just use the length value in the packet header. */
2377 length = m->m_pkthdr.len;
2378#endif
2379
2380#if FE_DEBUG >= 1
2381 /*
2382 * Should never send big packets. If such a packet is passed,
2383 * it should be a bug of upper layer. We just ignore it.
2384 * ... Partial (too short) packets, neither.
2385 */
2386 if ( length > ETHER_MAX_LEN || length < ETHER_HDR_SIZE ) {
2387 log( LOG_ERR,
2388 "fe%d: got a %s packet (%u bytes) to send\n",
2389 sc->sc_unit,
2390 length < ETHER_HDR_SIZE ? "partial" : "big", length );
2391 sc->sc_if.if_oerrors++;
2392 return;
2393 }
2394#endif
2395
2396 /*
2397 * Put the length word for this frame.
2398 * Does 86960 accept odd length? -- Yes.
2399 * Do we need to pad the length to minimum size by ourselves?
2400 * -- Generally yes. But for (or will be) the last
2401 * packet in the transmission buffer, we can skip the
2402 * padding process. It may gain performance slightly. FIXME.
2403 */
2404 outw( addr_bmpr8, max( length, ETHER_MIN_LEN ) );
2405
2406 /*
2407 * Update buffer status now.
2408 * Truncate the length up to an even number, since we use outw().
2409 */
2410 length = ( length + 1 ) & ~1;
2411 sc->txb_free -= FE_DATA_LEN_LEN + max( length, ETHER_MIN_LEN );
2412 sc->txb_count++;
2413
2414#if FE_DELAYED_PADDING
2415 /* Postpone the packet padding if necessary. */
2416 if ( length < ETHER_MIN_LEN ) {
2417 sc->txb_padding = ETHER_MIN_LEN - length;
2418 }
2419#endif
2420
2421 /*
2422 * Transfer the data from mbuf chain to the transmission buffer.
2423 * MB86960 seems to require that data be transferred as words, and
2424 * only words. So that we require some extra code to patch
2425 * over odd-length mbufs.
2426 */
2427 savebyte = NO_PENDING_BYTE;
2428 for ( mp = m; mp != 0; mp = mp->m_next ) {
2429
2430 /* Ignore empty mbuf. */
2431 len = mp->m_len;
2432 if ( len == 0 ) continue;
2433
2434 /* Find the actual data to send. */
2435 data = mtod(mp, caddr_t);
2436
2437 /* Finish the last byte. */
2438 if ( savebyte != NO_PENDING_BYTE ) {
2439 outw( addr_bmpr8, savebyte | ( *data << 8 ) );
2440 data++;
2441 len--;
2442 savebyte = NO_PENDING_BYTE;
2443 }
2444
2445 /* output contiguous words */
2446 if (len > 1) {
2447 outsw( addr_bmpr8, data, len >> 1);
2448 data += len & ~1;
2449 len &= 1;
2450 }
2451
2452 /* Save a remaining byte, if there is one. */
2453 if ( len > 0 ) {
2454 savebyte = *data;
2455 }
2456 }
2457
2458 /* Spit the last byte, if the length is odd. */
2459 if ( savebyte != NO_PENDING_BYTE ) {
2460 outw( addr_bmpr8, savebyte );
2461 }
2462
2463#if ! FE_DELAYED_PADDING
2464 /*
2465 * Pad the packet to the minimum length if necessary.
2466 */
2467 pad = ( ETHER_MIN_LEN >> 1 ) - ( length >> 1 );
2468 while ( --pad >= 0 ) {
2469 outw( addr_bmpr8, 0 );
2470 }
2471#endif
2472}
2473
2474/*
2475 * Compute hash value for an Ethernet address
2476 */
2477static int
2478fe_hash ( u_char * ep )
2479{
2480#define FE_HASH_MAGIC_NUMBER 0xEDB88320L
2481
2482 u_long hash = 0xFFFFFFFFL;
2483 int i, j;
2484 u_char b;
2485 u_long m;
2486
2487 for ( i = ETHER_ADDR_LEN; --i >= 0; ) {
2488 b = *ep++;
2489 for ( j = 8; --j >= 0; ) {
2490 m = hash;
2491 hash >>= 1;
2492 if ( ( m ^ b ) & 1 ) hash ^= FE_HASH_MAGIC_NUMBER;
2493 b >>= 1;
2494 }
2495 }
2496 return ( ( int )( hash >> 26 ) );
2497}
2498
2499/*
2500 * Compute the multicast address filter from the
2501 * list of multicast addresses we need to listen to.
2502 */
2503static struct fe_filter
2504fe_mcaf ( struct fe_softc *sc )
2505{
2506 int index;
2507 struct fe_filter filter;
2508 struct ether_multi *enm;
2509 struct ether_multistep step;
2510
2511 filter = fe_filter_nothing;
2512 ETHER_FIRST_MULTI(step, &sc->arpcom, enm);
2513 while ( enm != NULL) {
2514 if ( bcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN) ) {
2515 return ( fe_filter_all );
2516 }
2517 index = fe_hash( enm->enm_addrlo );
2518#if FE_DEBUG >= 4
2519 log( LOG_INFO, "fe%d: hash(%6D) == %d\n",
2520 sc->sc_unit, enm->enm_addrlo , ":", index );
2521#endif
2522
2523 filter.data[index >> 3] |= 1 << (index & 7);
2524 ETHER_NEXT_MULTI(step, enm);
2525 }
2526 return ( filter );
2527}
2528
2529/*
2530 * Calculate a new "multicast packet filter" and put the 86960
2531 * receiver in appropriate mode.
2532 */
2533static void
2534fe_setmode ( struct fe_softc *sc )
2535{
2536 int flags = sc->sc_if.if_flags;
2537
2538 /*
2539 * If the interface is not running, we postpone the update
2540 * process for receive modes and multicast address filter
2541 * until the interface is restarted. It reduces some
2542 * complicated job on maintaining chip states. (Earlier versions
2543 * of this driver had a bug on that point...)
2544 *
2545 * To complete the trick, fe_init() calls fe_setmode() after
2546 * restarting the interface.
2547 */
2548 if ( !( flags & IFF_RUNNING ) ) return;
2549
2550 /*
2551 * Promiscuous mode is handled separately.
2552 */
2553 if ( flags & IFF_PROMISC ) {
2554 /*
2555 * Program 86960 to receive all packets on the segment
2556 * including those directed to other stations.
2557 * Multicast filter stored in MARs are ignored
2558 * under this setting, so we don't need to update it.
2559 *
2560 * Promiscuous mode in FreeBSD 2 is used solely by
2561 * BPF, and BPF only listens to valid (no error) packets.
2562 * So, we ignore errornous ones even in this mode.
2563 * (Older versions of fe driver mistook the point.)
2564 */
2565 outb( sc->addr + FE_DLCR5,
2566 sc->proto_dlcr5 | FE_D5_AFM0 | FE_D5_AFM1 );
2567 sc->filter_change = 0;
2568
2569#if FE_DEBUG >= 3
2570 log( LOG_INFO, "fe%d: promiscuous mode\n", sc->sc_unit );
2571#endif
2572 return;
2573 }
2574
2575 /*
2576 * Turn the chip to the normal (non-promiscuous) mode.
2577 */
2578 outb( sc->addr + FE_DLCR5, sc->proto_dlcr5 | FE_D5_AFM1 );
2579
2580 /*
2581 * Find the new multicast filter value.
2582 * I'm not sure we have to handle modes other than MULTICAST.
2583 * Who sets ALLMULTI? Who turns MULTICAST off? FIXME.
2584 */
2585 if ( flags & IFF_ALLMULTI ) {
2586 sc->filter = fe_filter_all;
2587 } else if ( flags & IFF_MULTICAST ) {
2588 sc->filter = fe_mcaf( sc );
2589 } else {
2590 sc->filter = fe_filter_nothing;
2591 }
2592 sc->filter_change = 1;
2593
2594#if FE_DEBUG >= 3
2595 log( LOG_INFO, "fe%d: address filter:"
2596 " [%02x %02x %02x %02x %02x %02x %02x %02x]\n",
2597 sc->sc_unit,
2598 sc->filter.data[0], sc->filter.data[1],
2599 sc->filter.data[2], sc->filter.data[3],
2600 sc->filter.data[4], sc->filter.data[5],
2601 sc->filter.data[6], sc->filter.data[7] );
2602#endif
2603
2604 /*
2605 * We have to update the multicast filter in the 86960, A.S.A.P.
2606 *
2607 * Note that the DLC (Data Linc Control unit, i.e. transmitter
2608 * and receiver) must be stopped when feeding the filter, and
2609 * DLC trushes all packets in both transmission and receive
2610 * buffers when stopped.
2611 *
2612 * ... Are the above sentenses correct? I have to check the
2613 * manual of the MB86960A. FIXME.
2614 *
2615 * To reduce the packet lossage, we delay the filter update
2616 * process until buffers are empty.
2617 */
2618 if ( sc->txb_sched == 0 && sc->txb_count == 0
2619 && !( inb( sc->addr + FE_DLCR1 ) & FE_D1_PKTRDY ) ) {
2620 /*
2621 * Buffers are (apparently) empty. Load
2622 * the new filter value into MARs now.
2623 */
2624 fe_loadmar(sc);
2625 } else {
2626 /*
2627 * Buffers are not empty. Mark that we have to update
2628 * the MARs. The new filter will be loaded by feintr()
2629 * later.
2630 */
2631#if FE_DEBUG >= 4
2632 log( LOG_INFO, "fe%d: filter change delayed\n", sc->sc_unit );
2633#endif
2634 }
2635}
2636
2637/*
2638 * Load a new multicast address filter into MARs.
2639 *
2640 * The caller must have splimp'ed befor fe_loadmar.
2641 * This function starts the DLC upon return. So it can be called only
2642 * when the chip is working, i.e., from the driver's point of view, when
2643 * a device is RUNNING. (I mistook the point in previous versions.)
2644 */
2645static void
2646fe_loadmar ( struct fe_softc * sc )
2647{
2648 /* Stop the DLC (transmitter and receiver). */
2649 outb( sc->addr + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE );
2650
2651 /* Select register bank 1 for MARs. */
2652 outb( sc->addr + FE_DLCR7,
2653 sc->proto_dlcr7 | FE_D7_RBS_MAR | FE_D7_POWER_UP );
2654
2655 /* Copy filter value into the registers. */
2656 outblk( sc->addr + FE_MAR8, sc->filter.data, FE_FILTER_LEN );
2657
2658 /* Restore the bank selection for BMPRs (i.e., runtime registers). */
2659 outb( sc->addr + FE_DLCR7,
2660 sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP );
2661
2662 /* Restart the DLC. */
2663 outb( sc->addr + FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_ENABLE );
2664
2665 /* We have just updated the filter. */
2666 sc->filter_change = 0;
2667
2668#if FE_DEBUG >= 3
2669 log( LOG_INFO, "fe%d: address filter changed\n", sc->sc_unit );
2670#endif
2671}
2672
2683/*
2684 * Copy the physical (Ethernet) address into the "data link" address
2685 * entry of the address list for an interface.
2686 * This is (said to be) useful for netstat(1) to keep track of which
2687 * interface is which.
2688 *
2689 * What I'm not sure on this function is, why this is a driver's function.
2690 * Probably this should be moved to somewhere independent to a specific
2691 * hardware, such as if_ehtersubr.c. FIXME.
2692 */
2693static void
2694fe_setlinkaddr ( struct fe_softc * sc )
2695{
2696 struct ifaddr *ifa;
2697 struct sockaddr_dl * sdl;
2698
2699 /*
2700 * Search down the ifa address list looking for the AF_LINK type entry.
2701 */
2702 for ( ifa = sc->sc_if.if_addrlist; ifa != NULL; ifa = ifa->ifa_next ) {
2703 if ( ifa->ifa_addr != NULL
2704 && ifa->ifa_addr->sa_family == AF_LINK ) {
2705
2706 /*
2707 * We have found an AF_LINK type entry.
2708 * Fill in the link-level address for this interface
2709 */
2710 sdl = (struct sockaddr_dl *) ifa->ifa_addr;
2711 sdl->sdl_type = IFT_ETHER;
2712 sdl->sdl_alen = ETHER_ADDR_LEN;
2713 sdl->sdl_slen = 0;
2714 bcopy(sc->sc_enaddr, LLADDR(sdl), ETHER_ADDR_LEN);
2715#if FE_DEBUG >= 3
2716 log( LOG_INFO, "fe%d: link address set\n",
2717 sc->sc_unit );
2718#endif
2719 return;
2720 }
2721 }
2722}
2723
2673#if FE_DEBUG >= 1
2674static void
2675fe_dump ( int level, struct fe_softc * sc, char * message )
2676{
2677 log( level, "fe%d: %s,"
2678 " DLCR = %02x %02x %02x %02x %02x %02x %02x %02x,"
2679 " BMPR = xx xx %02x %02x %02x %02x %02x %02x,"
2680 " asic = %02x %02x %02x %02x %02x %02x %02x %02x"
2681 " + %02x %02x %02x %02x %02x %02x %02x %02x\n",
2682 sc->sc_unit, message ? message : "registers",
2683 inb( sc->addr + FE_DLCR0 ), inb( sc->addr + FE_DLCR1 ),
2684 inb( sc->addr + FE_DLCR2 ), inb( sc->addr + FE_DLCR3 ),
2685 inb( sc->addr + FE_DLCR4 ), inb( sc->addr + FE_DLCR5 ),
2686 inb( sc->addr + FE_DLCR6 ), inb( sc->addr + FE_DLCR7 ),
2687 inb( sc->addr + FE_BMPR10 ), inb( sc->addr + FE_BMPR11 ),
2688 inb( sc->addr + FE_BMPR12 ), inb( sc->addr + FE_BMPR13 ),
2689 inb( sc->addr + FE_BMPR14 ), inb( sc->addr + FE_BMPR15 ),
2690 inb( sc->addr + 0x10 ), inb( sc->addr + 0x11 ),
2691 inb( sc->addr + 0x12 ), inb( sc->addr + 0x13 ),
2692 inb( sc->addr + 0x14 ), inb( sc->addr + 0x15 ),
2693 inb( sc->addr + 0x16 ), inb( sc->addr + 0x17 ),
2694 inb( sc->addr + 0x18 ), inb( sc->addr + 0x19 ),
2695 inb( sc->addr + 0x1A ), inb( sc->addr + 0x1B ),
2696 inb( sc->addr + 0x1C ), inb( sc->addr + 0x1D ),
2697 inb( sc->addr + 0x1E ), inb( sc->addr + 0x1F ) );
2698}
2699#endif