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