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