mb86960.c revision 1.84 1 /* $NetBSD: mb86960.c,v 1.84 2016/12/15 09:28:05 ozaki-r Exp $ */
2
3 /*
4 * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
5 *
6 * This software may be used, modified, copied, distributed, and sold, in
7 * both source and binary form provided that the above copyright, these
8 * terms and the following disclaimer are retained. The name of the author
9 * and/or the contributor may not be used to endorse or promote products
10 * derived from this software without specific prior written permission.
11 *
12 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND
13 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE
16 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION.
19 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22 * SUCH DAMAGE.
23 */
24
25 /*
26 * Portions copyright (C) 1993, David Greenman. This software may be used,
27 * modified, copied, distributed, and sold, in both source and binary form
28 * provided that the above copyright and these terms are retained. Under no
29 * circumstances is the author responsible for the proper functioning of this
30 * software, nor does the author assume any responsibility for damages
31 * incurred with its use.
32 */
33
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: mb86960.c,v 1.84 2016/12/15 09:28:05 ozaki-r Exp $");
36
37 /*
38 * Device driver for Fujitsu MB86960A/MB86965A based Ethernet cards.
39 * Contributed by M.S. <seki (at) sysrap.cs.fujitsu.co.jp>
40 *
41 * This version is intended to be a generic template for various
42 * MB86960A/MB86965A based Ethernet cards. It currently supports
43 * Fujitsu FMV-180 series (i.e., FMV-181 and FMV-182) and Allied-
44 * Telesis AT1700 series and RE2000 series. There are some
45 * unnecessary hooks embedded, which are primarily intended to support
46 * other types of Ethernet cards, but the author is not sure whether
47 * they are useful.
48 */
49
50 #include "opt_inet.h"
51
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/errno.h>
55 #include <sys/ioctl.h>
56 #include <sys/mbuf.h>
57 #include <sys/socket.h>
58 #include <sys/syslog.h>
59 #include <sys/device.h>
60 #include <sys/rndsource.h>
61
62 #include <net/if.h>
63 #include <net/if_dl.h>
64 #include <net/if_types.h>
65 #include <net/if_media.h>
66 #include <net/if_ether.h>
67
68 #ifdef INET
69 #include <netinet/in.h>
70 #include <netinet/in_systm.h>
71 #include <netinet/in_var.h>
72 #include <netinet/ip.h>
73 #include <netinet/if_inarp.h>
74 #endif
75
76
77 #include <net/bpf.h>
78 #include <net/bpfdesc.h>
79
80 #include <sys/bus.h>
81
82 #include <dev/ic/mb86960reg.h>
83 #include <dev/ic/mb86960var.h>
84
85 #ifndef __BUS_SPACE_HAS_STREAM_METHODS
86 #define bus_space_write_stream_2 bus_space_write_2
87 #define bus_space_write_multi_stream_2 bus_space_write_multi_2
88 #define bus_space_read_multi_stream_2 bus_space_read_multi_2
89 #endif /* __BUS_SPACE_HAS_STREAM_METHODS */
90
91 /* Standard driver entry points. These can be static. */
92 void mb86960_init(struct mb86960_softc *);
93 int mb86960_ioctl(struct ifnet *, u_long, void *);
94 void mb86960_start(struct ifnet *);
95 void mb86960_reset(struct mb86960_softc *);
96 void mb86960_watchdog(struct ifnet *);
97
98 /* Local functions. Order of declaration is confused. FIXME. */
99 int mb86960_get_packet(struct mb86960_softc *, u_int);
100 void mb86960_stop(struct mb86960_softc *);
101 void mb86960_tint(struct mb86960_softc *, uint8_t);
102 void mb86960_rint(struct mb86960_softc *, uint8_t);
103 static inline
104 void mb86960_xmit(struct mb86960_softc *);
105 void mb86960_write_mbufs(struct mb86960_softc *, struct mbuf *);
106 static inline
107 void mb86960_droppacket(struct mb86960_softc *);
108 void mb86960_getmcaf(struct ethercom *, uint8_t *);
109 void mb86960_setmode(struct mb86960_softc *);
110 void mb86960_loadmar(struct mb86960_softc *);
111
112 int mb86960_mediachange(struct ifnet *);
113 void mb86960_mediastatus(struct ifnet *, struct ifmediareq *);
114
115 #if FE_DEBUG >= 1
116 void mb86960_dump(int, struct mb86960_softc *);
117 #endif
118
119 void
120 mb86960_attach(struct mb86960_softc *sc, uint8_t *myea)
121 {
122 bus_space_tag_t bst = sc->sc_bst;
123 bus_space_handle_t bsh = sc->sc_bsh;
124
125 /* Register values which depend on board design. */
126 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
127 sc->proto_dlcr5 = 0;
128 sc->proto_dlcr7 = FE_D7_BYTSWP_LH;
129 if ((sc->sc_flags & FE_FLAGS_MB86960) != 0)
130 sc->proto_dlcr7 |= FE_D7_ED_TEST; /* XXX */
131 sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
132
133 /*
134 * Program the 86960 as following defaults:
135 * SRAM: 32KB, 100ns, byte-wide access.
136 * Transmission buffer: 4KB x 2.
137 * System bus interface: 16 bits.
138 * These values except TXBSIZE should be modified as per
139 * sc_flags which is set in MD attachments, because they
140 * are hard-wired on the board. Modifying TXBSIZE will affect
141 * the driver performance.
142 */
143 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB |
144 FE_D6_BBW_BYTE | FE_D6_SRAM_100ns;
145 if (sc->sc_flags & FE_FLAGS_SBW_BYTE)
146 sc->proto_dlcr6 |= FE_D6_SBW_BYTE;
147 if (sc->sc_flags & FE_FLAGS_SRAM_150ns)
148 sc->proto_dlcr6 &= ~FE_D6_SRAM_100ns;
149
150 /*
151 * Minimum initialization of the hardware.
152 * We write into registers; hope I/O ports have no
153 * overlap with other boards.
154 */
155
156 /* Initialize 86960. */
157 bus_space_write_1(bst, bsh, FE_DLCR6,
158 sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
159 delay(200);
160
161 #ifdef DIAGNOSTIC
162 if (myea == NULL) {
163 aprint_error_dev(sc->sc_dev,
164 "ethernet address shouldn't be NULL\n");
165 panic("NULL ethernet address");
166 }
167 #endif
168 memcpy(sc->sc_enaddr, myea, sizeof(sc->sc_enaddr));
169
170 /* Disable all interrupts. */
171 bus_space_write_1(bst, bsh, FE_DLCR2, 0);
172 bus_space_write_1(bst, bsh, FE_DLCR3, 0);
173 }
174
175 /*
176 * Install interface into kernel networking data structures
177 */
178 void
179 mb86960_config(struct mb86960_softc *sc, int *media, int nmedia, int defmedia)
180 {
181 cfdata_t cf = device_cfdata(sc->sc_dev);
182 struct ifnet *ifp = &sc->sc_ec.ec_if;
183 int i;
184
185 /* Stop the 86960. */
186 mb86960_stop(sc);
187
188 /* Initialize ifnet structure. */
189 strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ);
190 ifp->if_softc = sc;
191 ifp->if_start = mb86960_start;
192 ifp->if_ioctl = mb86960_ioctl;
193 ifp->if_watchdog = mb86960_watchdog;
194 ifp->if_flags =
195 IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
196 IFQ_SET_READY(&ifp->if_snd);
197
198 #if FE_DEBUG >= 3
199 log(LOG_INFO, "%s: mb86960_config()\n", device_xname(sc->sc_dev));
200 mb86960_dump(LOG_INFO, sc);
201 #endif
202
203 #if FE_SINGLE_TRANSMISSION
204 /* Override txb config to allocate minimum. */
205 sc->proto_dlcr6 &= ~FE_D6_TXBSIZ;
206 sc->proto_dlcr6 |= FE_D6_TXBSIZ_2x2KB;
207 #endif
208
209 /* Modify hardware config if it is requested. */
210 if ((cf->cf_flags & FE_FLAGS_OVERRIDE_DLCR6) != 0)
211 sc->proto_dlcr6 = cf->cf_flags & FE_FLAGS_DLCR6_VALUE;
212
213 /* Find TX buffer size, based on the hardware dependent proto. */
214 switch (sc->proto_dlcr6 & FE_D6_TXBSIZ) {
215 case FE_D6_TXBSIZ_2x2KB:
216 sc->txb_size = 2048;
217 break;
218 case FE_D6_TXBSIZ_2x4KB:
219 sc->txb_size = 4096;
220 break;
221 case FE_D6_TXBSIZ_2x8KB:
222 sc->txb_size = 8192;
223 break;
224 default:
225 /* Oops, we can't work with single buffer configuration. */
226 #if FE_DEBUG >= 2
227 log(LOG_WARNING, "%s: strange TXBSIZ config; fixing\n",
228 device_xname(sc->sc_dev));
229 #endif
230 sc->proto_dlcr6 &= ~FE_D6_TXBSIZ;
231 sc->proto_dlcr6 |= FE_D6_TXBSIZ_2x2KB;
232 sc->txb_size = 2048;
233 break;
234 }
235
236 /* Initialize media goo. */
237 ifmedia_init(&sc->sc_media, 0, mb86960_mediachange,
238 mb86960_mediastatus);
239 if (media != NULL) {
240 for (i = 0; i < nmedia; i++)
241 ifmedia_add(&sc->sc_media, media[i], 0, NULL);
242 ifmedia_set(&sc->sc_media, defmedia);
243 } else {
244 ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
245 ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
246 }
247
248 /* Attach the interface. */
249 if_attach(ifp);
250 ether_ifattach(ifp, sc->sc_enaddr);
251
252 rnd_attach_source(&sc->rnd_source, device_xname(sc->sc_dev),
253 RND_TYPE_NET, RND_FLAG_DEFAULT);
254
255 /* Print additional info when attached. */
256 aprint_normal_dev(sc->sc_dev, "Ethernet address %s\n",
257 ether_sprintf(sc->sc_enaddr));
258
259 #if FE_DEBUG >= 3
260 {
261 int buf, txb, bbw, sbw, ram;
262
263 buf = txb = bbw = sbw = ram = -1;
264 switch (sc->proto_dlcr6 & FE_D6_BUFSIZ) {
265 case FE_D6_BUFSIZ_8KB:
266 buf = 8;
267 break;
268 case FE_D6_BUFSIZ_16KB:
269 buf = 16;
270 break;
271 case FE_D6_BUFSIZ_32KB:
272 buf = 32;
273 break;
274 case FE_D6_BUFSIZ_64KB:
275 buf = 64;
276 break;
277 }
278 switch (sc->proto_dlcr6 & FE_D6_TXBSIZ) {
279 case FE_D6_TXBSIZ_2x2KB:
280 txb = 2;
281 break;
282 case FE_D6_TXBSIZ_2x4KB:
283 txb = 4;
284 break;
285 case FE_D6_TXBSIZ_2x8KB:
286 txb = 8;
287 break;
288 }
289 switch (sc->proto_dlcr6 & FE_D6_BBW) {
290 case FE_D6_BBW_BYTE:
291 bbw = 8;
292 break;
293 case FE_D6_BBW_WORD:
294 bbw = 16;
295 break;
296 }
297 switch (sc->proto_dlcr6 & FE_D6_SBW) {
298 case FE_D6_SBW_BYTE:
299 sbw = 8;
300 break;
301 case FE_D6_SBW_WORD:
302 sbw = 16;
303 break;
304 }
305 switch (sc->proto_dlcr6 & FE_D6_SRAM) {
306 case FE_D6_SRAM_100ns:
307 ram = 100;
308 break;
309 case FE_D6_SRAM_150ns:
310 ram = 150;
311 break;
312 }
313 aprint_debug_dev(sc->sc_dev,
314 "SRAM %dKB %dbit %dns, TXB %dKBx2, %dbit I/O\n",
315 buf, bbw, ram, txb, sbw);
316 }
317 #endif
318
319 /* The attach is successful. */
320 sc->sc_stat |= FE_STAT_ATTACHED;
321 }
322
323 /*
324 * Media change callback.
325 */
326 int
327 mb86960_mediachange(struct ifnet *ifp)
328 {
329 struct mb86960_softc *sc = ifp->if_softc;
330
331 if (sc->sc_mediachange)
332 return (*sc->sc_mediachange)(sc);
333 return 0;
334 }
335
336 /*
337 * Media status callback.
338 */
339 void
340 mb86960_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
341 {
342 struct mb86960_softc *sc = ifp->if_softc;
343
344 if ((sc->sc_stat & FE_STAT_ENABLED) == 0) {
345 ifmr->ifm_active = IFM_ETHER | IFM_NONE;
346 ifmr->ifm_status = 0;
347 return;
348 }
349
350 if (sc->sc_mediastatus)
351 (*sc->sc_mediastatus)(sc, ifmr);
352 }
353
354 /*
355 * Reset interface.
356 */
357 void
358 mb86960_reset(struct mb86960_softc *sc)
359 {
360 int s;
361
362 s = splnet();
363 mb86960_stop(sc);
364 mb86960_init(sc);
365 splx(s);
366 }
367
368 /*
369 * Stop everything on the interface.
370 *
371 * All buffered packets, both transmitting and receiving,
372 * if any, will be lost by stopping the interface.
373 */
374 void
375 mb86960_stop(struct mb86960_softc *sc)
376 {
377 bus_space_tag_t bst = sc->sc_bst;
378 bus_space_handle_t bsh = sc->sc_bsh;
379
380 #if FE_DEBUG >= 3
381 log(LOG_INFO, "%s: top of mb86960_stop()\n", device_xname(sc->sc_dev));
382 mb86960_dump(LOG_INFO, sc);
383 #endif
384
385 /* Disable interrupts. */
386 bus_space_write_1(bst, bsh, FE_DLCR2, 0x00);
387 bus_space_write_1(bst, bsh, FE_DLCR3, 0x00);
388
389 /* Stop interface hardware. */
390 delay(200);
391 bus_space_write_1(bst, bsh, FE_DLCR6,
392 sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
393 delay(200);
394
395 /* Clear all interrupt status. */
396 bus_space_write_1(bst, bsh, FE_DLCR0, 0xFF);
397 bus_space_write_1(bst, bsh, FE_DLCR1, 0xFF);
398
399 /* Put the chip in stand-by mode. */
400 delay(200);
401 bus_space_write_1(bst, bsh, FE_DLCR7,
402 sc->proto_dlcr7 | FE_D7_POWER_DOWN);
403 delay(200);
404
405 /* MAR loading can be delayed. */
406 sc->filter_change = 0;
407
408 /* Call a hook. */
409 if (sc->stop_card)
410 (*sc->stop_card)(sc);
411
412 #if FE_DEBUG >= 3
413 log(LOG_INFO, "%s: end of mb86960_stop()\n", device_xname(sc->sc_dev));
414 mb86960_dump(LOG_INFO, sc);
415 #endif
416 }
417
418 /*
419 * Device timeout/watchdog routine. Entered if the device neglects to
420 * generate an interrupt after a transmit has been started on it.
421 */
422 void
423 mb86960_watchdog(struct ifnet *ifp)
424 {
425 struct mb86960_softc *sc = ifp->if_softc;
426
427 log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev));
428 #if FE_DEBUG >= 3
429 mb86960_dump(LOG_INFO, sc);
430 #endif
431
432 /* Record how many packets are lost by this accident. */
433 sc->sc_ec.ec_if.if_oerrors += sc->txb_sched + sc->txb_count;
434
435 mb86960_reset(sc);
436 }
437
438 /*
439 * Drop (skip) a packet from receive buffer in 86960 memory.
440 */
441 static inline void
442 mb86960_droppacket(struct mb86960_softc *sc)
443 {
444 bus_space_tag_t bst = sc->sc_bst;
445 bus_space_handle_t bsh = sc->sc_bsh;
446
447 bus_space_write_1(bst, bsh, FE_BMPR14, FE_B14_FILTER | FE_B14_SKIP);
448 }
449
450 /*
451 * Initialize device.
452 */
453 void
454 mb86960_init(struct mb86960_softc *sc)
455 {
456 bus_space_tag_t bst = sc->sc_bst;
457 bus_space_handle_t bsh = sc->sc_bsh;
458 struct ifnet *ifp = &sc->sc_ec.ec_if;
459 int i;
460
461 #if FE_DEBUG >= 3
462 log(LOG_INFO, "%s: top of mb86960_init()\n", device_xname(sc->sc_dev));
463 mb86960_dump(LOG_INFO, sc);
464 #endif
465
466 /* Reset transmitter flags. */
467 ifp->if_flags &= ~IFF_OACTIVE;
468 ifp->if_timer = 0;
469
470 sc->txb_free = sc->txb_size;
471 sc->txb_count = 0;
472 sc->txb_sched = 0;
473
474 /* Do any card-specific initialization, if applicable. */
475 if (sc->init_card)
476 (*sc->init_card)(sc);
477
478 #if FE_DEBUG >= 3
479 log(LOG_INFO, "%s: after init hook\n", device_xname(sc->sc_dev));
480 mb86960_dump(LOG_INFO, sc);
481 #endif
482
483 /*
484 * Make sure to disable the chip, also.
485 * This may also help re-programming the chip after
486 * hot insertion of PCMCIAs.
487 */
488 bus_space_write_1(bst, bsh, FE_DLCR6,
489 sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
490 delay(200);
491
492 /* Power up the chip and select register bank for DLCRs. */
493 bus_space_write_1(bst, bsh, FE_DLCR7,
494 sc->proto_dlcr7 | FE_D7_RBS_DLCR | FE_D7_POWER_UP);
495 delay(200);
496
497 /* Feed the station address. */
498 bus_space_write_region_1(bst, bsh, FE_DLCR8,
499 sc->sc_enaddr, ETHER_ADDR_LEN);
500
501 /* Select the BMPR bank for runtime register access. */
502 bus_space_write_1(bst, bsh, FE_DLCR7,
503 sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP);
504
505 /* Initialize registers. */
506 bus_space_write_1(bst, bsh, FE_DLCR0, 0xFF); /* Clear all bits. */
507 bus_space_write_1(bst, bsh, FE_DLCR1, 0xFF); /* ditto. */
508 bus_space_write_1(bst, bsh, FE_DLCR2, 0x00);
509 bus_space_write_1(bst, bsh, FE_DLCR3, 0x00);
510 bus_space_write_1(bst, bsh, FE_DLCR4, sc->proto_dlcr4);
511 bus_space_write_1(bst, bsh, FE_DLCR5, sc->proto_dlcr5);
512 bus_space_write_1(bst, bsh, FE_BMPR10, 0x00);
513 bus_space_write_1(bst, bsh, FE_BMPR11, FE_B11_CTRL_SKIP);
514 bus_space_write_1(bst, bsh, FE_BMPR12, 0x00);
515 bus_space_write_1(bst, bsh, FE_BMPR13, sc->proto_bmpr13);
516 bus_space_write_1(bst, bsh, FE_BMPR14, FE_B14_FILTER);
517 bus_space_write_1(bst, bsh, FE_BMPR15, 0x00);
518
519 #if FE_DEBUG >= 3
520 log(LOG_INFO, "%s: just before enabling DLC\n",
521 device_xname(sc->sc_dev));
522 mb86960_dump(LOG_INFO, sc);
523 #endif
524
525 /* Enable interrupts. */
526 bus_space_write_1(bst, bsh, FE_DLCR2, FE_TMASK);
527 bus_space_write_1(bst, bsh, FE_DLCR3, FE_RMASK);
528
529 /* Enable transmitter and receiver. */
530 delay(200);
531 bus_space_write_1(bst, bsh, FE_DLCR6,
532 sc->proto_dlcr6 | FE_D6_DLC_ENABLE);
533 delay(200);
534
535 #if FE_DEBUG >= 3
536 log(LOG_INFO, "%s: just after enabling DLC\n",
537 device_xname(sc->sc_dev));
538 mb86960_dump(LOG_INFO, sc);
539 #endif
540
541 /*
542 * Make sure to empty the receive buffer.
543 *
544 * This may be redundant, but *if* the receive buffer were full
545 * at this point, the driver would hang. I have experienced
546 * some strange hangups just after UP. I hope the following
547 * code solve the problem.
548 *
549 * I have changed the order of hardware initialization.
550 * I think the receive buffer cannot have any packets at this
551 * point in this version. The following code *must* be
552 * redundant now. FIXME.
553 */
554 for (i = 0; i < FE_MAX_RECV_COUNT; i++) {
555 if (bus_space_read_1(bst, bsh, FE_DLCR5) & FE_D5_BUFEMP)
556 break;
557 mb86960_droppacket(sc);
558 }
559 #if FE_DEBUG >= 1
560 if (i >= FE_MAX_RECV_COUNT)
561 log(LOG_ERR, "%s: cannot empty receive buffer\n",
562 device_xname(sc->sc_dev));
563 #endif
564 #if FE_DEBUG >= 3
565 if (i < FE_MAX_RECV_COUNT)
566 log(LOG_INFO, "%s: receive buffer emptied (%d)\n",
567 device_xname(sc->sc_dev), i);
568 #endif
569
570 #if FE_DEBUG >= 3
571 log(LOG_INFO, "%s: after ERB loop\n", device_xname(sc->sc_dev));
572 mb86960_dump(LOG_INFO, sc);
573 #endif
574
575 /* Do we need this here? */
576 bus_space_write_1(bst, bsh, FE_DLCR0, 0xFF); /* Clear all bits. */
577 bus_space_write_1(bst, bsh, FE_DLCR1, 0xFF); /* ditto. */
578
579 #if FE_DEBUG >= 3
580 log(LOG_INFO, "%s: after FIXME\n", device_xname(sc->sc_dev));
581 mb86960_dump(LOG_INFO, sc);
582 #endif
583
584 /* Set 'running' flag. */
585 ifp->if_flags |= IFF_RUNNING;
586
587 /*
588 * At this point, the interface is runnung properly,
589 * except that it receives *no* packets. we then call
590 * mb86960_setmode() to tell the chip what packets to be
591 * received, based on the if_flags and multicast group
592 * list. It completes the initialization process.
593 */
594 mb86960_setmode(sc);
595
596 #if FE_DEBUG >= 3
597 log(LOG_INFO, "%s: after setmode\n", device_xname(sc->sc_dev));
598 mb86960_dump(LOG_INFO, sc);
599 #endif
600
601 /* ...and attempt to start output. */
602 mb86960_start(ifp);
603
604 #if FE_DEBUG >= 3
605 log(LOG_INFO, "%s: end of mb86960_init()\n", device_xname(sc->sc_dev));
606 mb86960_dump(LOG_INFO, sc);
607 #endif
608 }
609
610 /*
611 * This routine actually starts the transmission on the interface
612 */
613 static inline void
614 mb86960_xmit(struct mb86960_softc *sc)
615 {
616 bus_space_tag_t bst = sc->sc_bst;
617 bus_space_handle_t bsh = sc->sc_bsh;
618
619 /*
620 * Set a timer just in case we never hear from the board again.
621 * We use longer timeout for multiple packet transmission.
622 * I'm not sure this timer value is appropriate. FIXME.
623 */
624 sc->sc_ec.ec_if.if_timer = 1 + sc->txb_count;
625
626 /* Update txb variables. */
627 sc->txb_sched = sc->txb_count;
628 sc->txb_count = 0;
629 sc->txb_free = sc->txb_size;
630
631 #if FE_DELAYED_PADDING
632 /* Omit the postponed padding process. */
633 sc->txb_padding = 0;
634 #endif
635
636 /* Start transmitter, passing packets in TX buffer. */
637 bus_space_write_1(bst, bsh, FE_BMPR10, sc->txb_sched | FE_B10_START);
638 }
639
640 /*
641 * Start output on interface.
642 * We make two assumptions here:
643 * 1) that the current priority is set to splnet _before_ this code
644 * is called *and* is returned to the appropriate priority after
645 * return
646 * 2) that the IFF_OACTIVE flag is checked before this code is called
647 * (i.e. that the output part of the interface is idle)
648 */
649 void
650 mb86960_start(struct ifnet *ifp)
651 {
652 struct mb86960_softc *sc = ifp->if_softc;
653 struct mbuf *m;
654
655 #if FE_DEBUG >= 1
656 /* Just a sanity check. */
657 if ((sc->txb_count == 0) != (sc->txb_free == sc->txb_size)) {
658 /*
659 * Txb_count and txb_free co-works to manage the
660 * transmission buffer. Txb_count keeps track of the
661 * used potion of the buffer, while txb_free does unused
662 * potion. So, as long as the driver runs properly,
663 * txb_count is zero if and only if txb_free is same
664 * as txb_size (which represents whole buffer.)
665 */
666 log(LOG_ERR, "%s: inconsistent txb variables (%d, %d)\n",
667 device_xname(sc->sc_dev), sc->txb_count, sc->txb_free);
668 /*
669 * So, what should I do, then?
670 *
671 * We now know txb_count and txb_free contradicts. We
672 * cannot, however, tell which is wrong. More
673 * over, we cannot peek 86960 transmission buffer or
674 * reset the transmission buffer. (In fact, we can
675 * reset the entire interface. I don't want to do it.)
676 *
677 * If txb_count is incorrect, leaving it as is will cause
678 * sending of garbage after the next interrupt. We have to
679 * avoid it. Hence, we reset the txb_count here. If
680 * txb_free was incorrect, resetting txb_count just loose
681 * some packets. We can live with it.
682 */
683 sc->txb_count = 0;
684 }
685 #endif
686
687 #if FE_DEBUG >= 1
688 /*
689 * First, see if there are buffered packets and an idle
690 * transmitter - should never happen at this point.
691 */
692 if ((sc->txb_count > 0) && (sc->txb_sched == 0)) {
693 log(LOG_ERR, "%s: transmitter idle with %d buffered packets\n",
694 device_xname(sc->sc_dev), sc->txb_count);
695 mb86960_xmit(sc);
696 }
697 #endif
698
699 /*
700 * Stop accepting more transmission packets temporarily, when
701 * a filter change request is delayed. Updating the MARs on
702 * 86960 flushes the transmisstion buffer, so it is delayed
703 * until all buffered transmission packets have been sent
704 * out.
705 */
706 if (sc->filter_change) {
707 /*
708 * Filter change request is delayed only when the DLC is
709 * working. DLC soon raise an interrupt after finishing
710 * the work.
711 */
712 goto indicate_active;
713 }
714
715 for (;;) {
716 /*
717 * See if there is room to put another packet in the buffer.
718 * We *could* do better job by peeking the send queue to
719 * know the length of the next packet. Current version just
720 * tests against the worst case (i.e., longest packet). FIXME.
721 *
722 * When adding the packet-peek feature, don't forget adding a
723 * test on txb_count against QUEUEING_MAX.
724 * There is a little chance the packet count exceeds
725 * the limit. Assume transmission buffer is 8KB (2x8KB
726 * configuration) and an application sends a bunch of small
727 * (i.e., minimum packet sized) packets rapidly. An 8KB
728 * buffer can hold 130 blocks of 62 bytes long...
729 */
730 if (sc->txb_free <
731 (ETHER_MAX_LEN - ETHER_CRC_LEN) + FE_TXLEN_SIZE) {
732 /* No room. */
733 goto indicate_active;
734 }
735
736 #if FE_SINGLE_TRANSMISSION
737 if (sc->txb_count > 0) {
738 /* Just one packet per a transmission buffer. */
739 goto indicate_active;
740 }
741 #endif
742
743 /*
744 * Get the next mbuf chain for a packet to send.
745 */
746 IFQ_DEQUEUE(&ifp->if_snd, m);
747 if (m == 0) {
748 /* No more packets to send. */
749 goto indicate_inactive;
750 }
751
752 /* Tap off here if there is a BPF listener. */
753 bpf_mtap(ifp, m);
754
755 /*
756 * Copy the mbuf chain into the transmission buffer.
757 * txb_* variables are updated as necessary.
758 */
759 mb86960_write_mbufs(sc, m);
760
761 m_freem(m);
762
763 /* Start transmitter if it's idle. */
764 if (sc->txb_sched == 0)
765 mb86960_xmit(sc);
766 }
767
768 indicate_inactive:
769 /*
770 * We are using the !OACTIVE flag to indicate to
771 * the outside world that we can accept an
772 * additional packet rather than that the
773 * transmitter is _actually_ active. Indeed, the
774 * transmitter may be active, but if we haven't
775 * filled all the buffers with data then we still
776 * want to accept more.
777 */
778 ifp->if_flags &= ~IFF_OACTIVE;
779 return;
780
781 indicate_active:
782 /*
783 * The transmitter is active, and there are no room for
784 * more outgoing packets in the transmission buffer.
785 */
786 ifp->if_flags |= IFF_OACTIVE;
787 return;
788 }
789
790 /*
791 * Transmission interrupt handler
792 * The control flow of this function looks silly. FIXME.
793 */
794 void
795 mb86960_tint(struct mb86960_softc *sc, uint8_t tstat)
796 {
797 bus_space_tag_t bst = sc->sc_bst;
798 bus_space_handle_t bsh = sc->sc_bsh;
799 struct ifnet *ifp = &sc->sc_ec.ec_if;
800 int left;
801 int col;
802
803 /*
804 * Handle "excessive collision" interrupt.
805 */
806 if (tstat & FE_D0_COLL16) {
807 /*
808 * Find how many packets (including this collided one)
809 * are left unsent in transmission buffer.
810 */
811 left = bus_space_read_1(bst, bsh, FE_BMPR10);
812
813 #if FE_DEBUG >= 2
814 log(LOG_WARNING, "%s: excessive collision (%d/%d)\n",
815 device_xname(sc->sc_dev), left, sc->txb_sched);
816 #endif
817 #if FE_DEBUG >= 3
818 mb86960_dump(LOG_INFO, sc);
819 #endif
820
821 /*
822 * Update statistics.
823 */
824 ifp->if_collisions += 16;
825 ifp->if_oerrors++;
826 ifp->if_opackets += sc->txb_sched - left;
827
828 /*
829 * Collision statistics has been updated.
830 * Clear the collision flag on 86960 now to avoid confusion.
831 */
832 bus_space_write_1(bst, bsh, FE_DLCR0, FE_D0_COLLID);
833
834 /*
835 * Restart transmitter, skipping the
836 * collided packet.
837 *
838 * We *must* skip the packet to keep network running
839 * properly. Excessive collision error is an
840 * indication of the network overload. If we
841 * tried sending the same packet after excessive
842 * collision, the network would be filled with
843 * out-of-time packets. Packets belonging
844 * to reliable transport (such as TCP) are resent
845 * by some upper layer.
846 */
847 bus_space_write_1(bst, bsh, FE_BMPR11,
848 FE_B11_CTRL_SKIP | FE_B11_MODE1);
849 sc->txb_sched = left - 1;
850 }
851
852 /*
853 * Handle "transmission complete" interrupt.
854 */
855 if (tstat & FE_D0_TXDONE) {
856 /*
857 * Add in total number of collisions on last
858 * transmission. We also clear "collision occurred" flag
859 * here.
860 *
861 * 86960 has a design flow on collision count on multiple
862 * packet transmission. When we send two or more packets
863 * with one start command (that's what we do when the
864 * transmission queue is clauded), 86960 informs us number
865 * of collisions occurred on the last packet on the
866 * transmission only. Number of collisions on previous
867 * packets are lost. I have told that the fact is clearly
868 * stated in the Fujitsu document.
869 *
870 * I considered not to mind it seriously. Collision
871 * count is not so important, anyway. Any comments? FIXME.
872 */
873
874 if (bus_space_read_1(bst, bsh, FE_DLCR0) & FE_D0_COLLID) {
875 /* Clear collision flag. */
876 bus_space_write_1(bst, bsh, FE_DLCR0, FE_D0_COLLID);
877
878 /* Extract collision count from 86960. */
879 col = bus_space_read_1(bst, bsh, FE_DLCR4) & FE_D4_COL;
880 if (col == 0) {
881 /*
882 * Status register indicates collisions,
883 * while the collision count is zero.
884 * This can happen after multiple packet
885 * transmission, indicating that one or more
886 * previous packet(s) had been collided.
887 *
888 * Since the accurate number of collisions
889 * has been lost, we just guess it as 1;
890 * Am I too optimistic? FIXME.
891 */
892 col = 1;
893 } else
894 col >>= FE_D4_COL_SHIFT;
895 ifp->if_collisions += col;
896 #if FE_DEBUG >= 4
897 log(LOG_WARNING, "%s: %d collision%s (%d)\n",
898 device_xname(sc->sc_dev), col, col == 1 ? "" : "s",
899 sc->txb_sched);
900 #endif
901 }
902
903 /*
904 * Update total number of successfully
905 * transmitted packets.
906 */
907 ifp->if_opackets += sc->txb_sched;
908 sc->txb_sched = 0;
909 }
910
911 if (sc->txb_sched == 0) {
912 /*
913 * The transmitter is no more active.
914 * Reset output active flag and watchdog timer.
915 */
916 ifp->if_flags &= ~IFF_OACTIVE;
917 ifp->if_timer = 0;
918
919 /*
920 * If more data is ready to transmit in the buffer, start
921 * transmitting them. Otherwise keep transmitter idle,
922 * even if more data is queued. This gives receive
923 * process a slight priority.
924 */
925 if (sc->txb_count > 0)
926 mb86960_xmit(sc);
927 }
928 }
929
930 /*
931 * Ethernet interface receiver interrupt.
932 */
933 void
934 mb86960_rint(struct mb86960_softc *sc, uint8_t rstat)
935 {
936 bus_space_tag_t bst = sc->sc_bst;
937 bus_space_handle_t bsh = sc->sc_bsh;
938 struct ifnet *ifp = &sc->sc_ec.ec_if;
939 u_int status, len;
940 int i;
941
942 /*
943 * Update statistics if this interrupt is caused by an error.
944 */
945 if (rstat & (FE_D1_OVRFLO | FE_D1_CRCERR | FE_D1_ALGERR |
946 FE_D1_SRTPKT)) {
947 #if FE_DEBUG >= 3
948 char sbuf[sizeof(FE_D1_ERRBITS) + 64];
949
950 snprintb(sbuf, sizeof(sbuf), FE_D1_ERRBITS, rstat);
951 log(LOG_WARNING, "%s: receive error: %s\n",
952 device_xname(sc->sc_dev), sbuf);
953 #endif
954 ifp->if_ierrors++;
955 }
956
957 /*
958 * MB86960 has a flag indicating "receive queue empty."
959 * We just loop checking the flag to pull out all received
960 * packets.
961 *
962 * We limit the number of iterrations to avoid infinite loop.
963 * It can be caused by a very slow CPU (some broken
964 * peripheral may insert incredible number of wait cycles)
965 * or, worse, by a broken MB86960 chip.
966 */
967 for (i = 0; i < FE_MAX_RECV_COUNT; i++) {
968 /* Stop the iterration if 86960 indicates no packets. */
969 if (bus_space_read_1(bst, bsh, FE_DLCR5) & FE_D5_BUFEMP)
970 break;
971
972 /*
973 * Extract receive packet status from the receive
974 * packet header.
975 */
976 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) {
977 status = bus_space_read_1(bst, bsh, FE_BMPR8);
978 (void)bus_space_read_1(bst, bsh, FE_BMPR8);
979 } else
980 status = bus_space_read_2(bst, bsh, FE_BMPR8);
981
982 #if FE_DEBUG >= 4
983 log(LOG_INFO, "%s: receive status = %02x\n",
984 device_xname(sc->sc_dev), status);
985 #endif
986
987 /*
988 * If there was an error, update statistics and drop
989 * the packet, unless the interface is in promiscuous
990 * mode.
991 */
992 if ((status & FE_RXSTAT_GOODPKT) == 0) {
993 if ((ifp->if_flags & IFF_PROMISC) == 0) {
994 ifp->if_ierrors++;
995 mb86960_droppacket(sc);
996 continue;
997 }
998 }
999
1000 /*
1001 * Extract the packet length from the receive packet header.
1002 * It is a sum of a header (14 bytes) and a payload.
1003 * CRC has been stripped off by the 86960.
1004 */
1005 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) {
1006 len = bus_space_read_1(bst, bsh, FE_BMPR8);
1007 len |= bus_space_read_1(bst, bsh, FE_BMPR8) << 8;
1008 } else
1009 len = bus_space_read_2(bst, bsh, FE_BMPR8);
1010
1011 /*
1012 * MB86965 checks the packet length and drop big packet
1013 * before passing it to us. There are no chance we can
1014 * get [crufty] packets. Hence, if the length exceeds
1015 * the specified limit, it means some serious failure,
1016 * such as out-of-sync on receive buffer management.
1017 *
1018 * Is this statement true? FIXME.
1019 */
1020 if (len > (ETHER_MAX_LEN - ETHER_CRC_LEN) ||
1021 len < ETHER_HDR_LEN) {
1022 #if FE_DEBUG >= 2
1023 log(LOG_WARNING,
1024 "%s: received a %s packet? (%u bytes)\n",
1025 device_xname(sc->sc_dev),
1026 len < ETHER_HDR_LEN ? "partial" : "big", len);
1027 #endif
1028 ifp->if_ierrors++;
1029 mb86960_droppacket(sc);
1030 continue;
1031 }
1032
1033 /*
1034 * Check for a short (RUNT) packet. We *do* check
1035 * but do nothing other than print a message.
1036 * Short packets are illegal, but does nothing bad
1037 * if it carries data for upper layer.
1038 */
1039 #if FE_DEBUG >= 2
1040 if (len < (ETHER_MIN_LEN - ETHER_CRC_LEN)) {
1041 log(LOG_WARNING,
1042 "%s: received a short packet? (%u bytes)\n",
1043 device_xname(sc->sc_dev), len);
1044 }
1045 #endif
1046
1047 /*
1048 * Go get a packet.
1049 */
1050 if (mb86960_get_packet(sc, len) == 0) {
1051 /* Skip a packet, updating statistics. */
1052 #if FE_DEBUG >= 2
1053 log(LOG_WARNING,
1054 "%s: out of mbufs; dropping packet (%u bytes)\n",
1055 device_xname(sc->sc_dev), len);
1056 #endif
1057 ifp->if_ierrors++;
1058 mb86960_droppacket(sc);
1059
1060 /*
1061 * We stop receiving packets, even if there are
1062 * more in the buffer. We hope we can get more
1063 * mbufs next time.
1064 */
1065 return;
1066 }
1067 }
1068 }
1069
1070 /*
1071 * Ethernet interface interrupt processor
1072 */
1073 int
1074 mb86960_intr(void *arg)
1075 {
1076 struct mb86960_softc *sc = arg;
1077 bus_space_tag_t bst = sc->sc_bst;
1078 bus_space_handle_t bsh = sc->sc_bsh;
1079 struct ifnet *ifp = &sc->sc_ec.ec_if;
1080 uint8_t tstat, rstat;
1081
1082 if ((sc->sc_stat & FE_STAT_ENABLED) == 0 ||
1083 !device_is_active(sc->sc_dev))
1084 return 0;
1085
1086 #if FE_DEBUG >= 4
1087 log(LOG_INFO, "%s: mb86960_intr()\n", device_xname(sc->sc_dev));
1088 mb86960_dump(LOG_INFO, sc);
1089 #endif
1090
1091 /*
1092 * Get interrupt conditions, masking unneeded flags.
1093 */
1094 tstat = bus_space_read_1(bst, bsh, FE_DLCR0) & FE_TMASK;
1095 rstat = bus_space_read_1(bst, bsh, FE_DLCR1) & FE_RMASK;
1096 if (tstat == 0 && rstat == 0)
1097 return 0;
1098
1099 /*
1100 * Loop until there are no more new interrupt conditions.
1101 */
1102 for (;;) {
1103 /*
1104 * Reset the conditions we are acknowledging.
1105 */
1106 bus_space_write_1(bst, bsh, FE_DLCR0, tstat);
1107 bus_space_write_1(bst, bsh, FE_DLCR1, rstat);
1108
1109 /*
1110 * Handle transmitter interrupts. Handle these first because
1111 * the receiver will reset the board under some conditions.
1112 */
1113 if (tstat != 0)
1114 mb86960_tint(sc, tstat);
1115
1116 /*
1117 * Handle receiver interrupts.
1118 */
1119 if (rstat != 0)
1120 mb86960_rint(sc, rstat);
1121
1122 /*
1123 * Update the multicast address filter if it is
1124 * needed and possible. We do it now, because
1125 * we can make sure the transmission buffer is empty,
1126 * and there is a good chance that the receive queue
1127 * is empty. It will minimize the possibility of
1128 * packet lossage.
1129 */
1130 if (sc->filter_change &&
1131 sc->txb_count == 0 && sc->txb_sched == 0) {
1132 mb86960_loadmar(sc);
1133 ifp->if_flags &= ~IFF_OACTIVE;
1134 }
1135
1136 /*
1137 * If it looks like the transmitter can take more data,
1138 * attempt to start output on the interface. This is done
1139 * after handling the receiver interrupt to give the
1140 * receive operation priority.
1141 */
1142 if ((ifp->if_flags & IFF_OACTIVE) == 0)
1143 mb86960_start(ifp);
1144
1145 if (rstat != 0 || tstat != 0)
1146 rnd_add_uint32(&sc->rnd_source, rstat + tstat);
1147
1148 /*
1149 * Get interrupt conditions, masking unneeded flags.
1150 */
1151 tstat = bus_space_read_1(bst, bsh, FE_DLCR0) & FE_TMASK;
1152 rstat = bus_space_read_1(bst, bsh, FE_DLCR1) & FE_RMASK;
1153 if (tstat == 0 && rstat == 0)
1154 return 1;
1155 }
1156 }
1157
1158 /*
1159 * Process an ioctl request. This code needs some work - it looks pretty ugly.
1160 */
1161 int
1162 mb86960_ioctl(struct ifnet *ifp, u_long cmd, void *data)
1163 {
1164 struct mb86960_softc *sc = ifp->if_softc;
1165 struct ifaddr *ifa = (struct ifaddr *)data;
1166 struct ifreq *ifr = (struct ifreq *)data;
1167 int s, error = 0;
1168
1169 #if FE_DEBUG >= 3
1170 log(LOG_INFO, "%s: ioctl(%lx)\n", device_xname(sc->sc_dev), cmd);
1171 #endif
1172
1173 s = splnet();
1174
1175 switch (cmd) {
1176 case SIOCINITIFADDR:
1177 if ((error = mb86960_enable(sc)) != 0)
1178 break;
1179 ifp->if_flags |= IFF_UP;
1180
1181 mb86960_init(sc);
1182 switch (ifa->ifa_addr->sa_family) {
1183 #ifdef INET
1184 case AF_INET:
1185 arp_ifinit(ifp, ifa);
1186 break;
1187 #endif
1188 default:
1189 break;
1190 }
1191 break;
1192
1193 case SIOCSIFFLAGS:
1194 if ((error = ifioctl_common(ifp, cmd, data)) != 0)
1195 break;
1196 /* XXX re-use ether_ioctl() */
1197 switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) {
1198 case IFF_RUNNING:
1199 /*
1200 * If interface is marked down and it is running, then
1201 * stop it.
1202 */
1203 mb86960_stop(sc);
1204 ifp->if_flags &= ~IFF_RUNNING;
1205 mb86960_disable(sc);
1206 break;
1207 case IFF_UP:
1208 /*
1209 * If interface is marked up and it is stopped, then
1210 * start it.
1211 */
1212 if ((error = mb86960_enable(sc)) != 0)
1213 break;
1214 mb86960_init(sc);
1215 break;
1216 case IFF_UP|IFF_RUNNING:
1217 /*
1218 * Reset the interface to pick up changes in any other
1219 * flags that affect hardware registers.
1220 */
1221 mb86960_setmode(sc);
1222 break;
1223 case 0:
1224 break;
1225 }
1226 #if FE_DEBUG >= 1
1227 /* "ifconfig fe0 debug" to print register dump. */
1228 if (ifp->if_flags & IFF_DEBUG) {
1229 log(LOG_INFO, "%s: SIOCSIFFLAGS(DEBUG)\n",
1230 device_xname(sc->sc_dev));
1231 mb86960_dump(LOG_DEBUG, sc);
1232 }
1233 #endif
1234 break;
1235
1236 case SIOCADDMULTI:
1237 case SIOCDELMULTI:
1238 if ((sc->sc_stat & FE_STAT_ENABLED) == 0) {
1239 error = EIO;
1240 break;
1241 }
1242
1243 /* Update our multicast list. */
1244 if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {
1245 /*
1246 * Multicast list has changed; set the hardware filter
1247 * accordingly.
1248 */
1249 if (ifp->if_flags & IFF_RUNNING)
1250 mb86960_setmode(sc);
1251 error = 0;
1252 }
1253 break;
1254
1255 case SIOCGIFMEDIA:
1256 case SIOCSIFMEDIA:
1257 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
1258 break;
1259
1260 default:
1261 error = ether_ioctl(ifp, cmd, data);
1262 break;
1263 }
1264
1265 splx(s);
1266 return error;
1267 }
1268
1269 /*
1270 * Retrieve packet from receive buffer and send to the next level up via
1271 * ether_input(). If there is a BPF listener, give a copy to BPF, too.
1272 * Returns 0 if success, -1 if error (i.e., mbuf allocation failure).
1273 */
1274 int
1275 mb86960_get_packet(struct mb86960_softc *sc, u_int len)
1276 {
1277 bus_space_tag_t bst = sc->sc_bst;
1278 bus_space_handle_t bsh = sc->sc_bsh;
1279 struct ifnet *ifp = &sc->sc_ec.ec_if;
1280 struct mbuf *m;
1281
1282 /* Allocate a header mbuf. */
1283 MGETHDR(m, M_DONTWAIT, MT_DATA);
1284 if (m == 0)
1285 return 0;
1286 m_set_rcvif(m, ifp);
1287 m->m_pkthdr.len = len;
1288
1289 /* The following silliness is to make NFS happy. */
1290 #define EROUND ((sizeof(struct ether_header) + 3) & ~3)
1291 #define EOFF (EROUND - sizeof(struct ether_header))
1292
1293 /*
1294 * Our strategy has one more problem. There is a policy on
1295 * mbuf cluster allocation. It says that we must have at
1296 * least MINCLSIZE (208 bytes) to allocate a cluster. For a
1297 * packet of a size between (MHLEN - 2) to (MINCLSIZE - 2),
1298 * our code violates the rule...
1299 * On the other hand, the current code is short, simple,
1300 * and fast, however. It does no harmful thing, just waists
1301 * some memory. Any comments? FIXME.
1302 */
1303
1304 /* Attach a cluster if this packet doesn't fit in a normal mbuf. */
1305 if (len > MHLEN - EOFF) {
1306 MCLGET(m, M_DONTWAIT);
1307 if ((m->m_flags & M_EXT) == 0) {
1308 m_freem(m);
1309 return 0;
1310 }
1311 }
1312
1313 /*
1314 * The following assumes there is room for the ether header in the
1315 * header mbuf.
1316 */
1317 m->m_data += EOFF;
1318
1319 /* Set the length of this packet. */
1320 m->m_len = len;
1321
1322 /* Get a packet. */
1323 if (sc->sc_flags & FE_FLAGS_SBW_BYTE)
1324 bus_space_read_multi_1(bst, bsh, FE_BMPR8,
1325 mtod(m, uint8_t *), len);
1326 else
1327 bus_space_read_multi_stream_2(bst, bsh, FE_BMPR8,
1328 mtod(m, uint16_t *), (len + 1) >> 1);
1329
1330 if_percpuq_enqueue(ifp->if_percpuq, m);
1331 return 1;
1332 }
1333
1334 /*
1335 * Write an mbuf chain to the transmission buffer memory using 16 bit PIO.
1336 * Returns number of bytes actually written, including length word.
1337 *
1338 * If an mbuf chain is too long for an Ethernet frame, it is not sent.
1339 * Packets shorter than Ethernet minimum are legal, and we pad them
1340 * before sending out. An exception is "partial" packets which are
1341 * shorter than mandatory Ethernet header.
1342 *
1343 * I wrote a code for an experimental "delayed padding" technique.
1344 * When employed, it postpones the padding process for short packets.
1345 * If xmit() occurred at the moment, the padding process is omitted, and
1346 * garbages are sent as pad data. If next packet is stored in the
1347 * transmission buffer before xmit(), write_mbuf() pads the previous
1348 * packet before transmitting new packet. This *may* gain the
1349 * system performance (slightly).
1350 */
1351 void
1352 mb86960_write_mbufs(struct mb86960_softc *sc, struct mbuf *m)
1353 {
1354 bus_space_tag_t bst = sc->sc_bst;
1355 bus_space_handle_t bsh = sc->sc_bsh;
1356 int totlen, len;
1357 #if FE_DEBUG >= 2
1358 struct mbuf *mp;
1359 #endif
1360
1361 #if FE_DELAYED_PADDING
1362 /* Do the "delayed padding." */
1363 if (sc->txb_padding > 0) {
1364 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) {
1365 for (len = sc->txb_padding; len > 0; len--)
1366 bus_space_write_1(bst, bsh, FE_BMPR8, 0);
1367 } else {
1368 for (len = sc->txb_padding >> 1; len > 0; len--)
1369 bus_space_write_2(bst, bsh, FE_BMPR8, 0);
1370 }
1371 sc->txb_padding = 0;
1372 }
1373 #endif
1374
1375 /* We need to use m->m_pkthdr.len, so require the header */
1376 if ((m->m_flags & M_PKTHDR) == 0)
1377 panic("mb86960_write_mbufs: no header mbuf");
1378
1379 #if FE_DEBUG >= 2
1380 /* First, count up the total number of bytes to copy. */
1381 for (totlen = 0, mp = m; mp != 0; mp = mp->m_next)
1382 totlen += mp->m_len;
1383 /* Check if this matches the one in the packet header. */
1384 if (totlen != m->m_pkthdr.len)
1385 log(LOG_WARNING, "%s: packet length mismatch? (%d/%d)\n",
1386 device_xname(sc->sc_dev), totlen, m->m_pkthdr.len);
1387 #else
1388 /* Just use the length value in the packet header. */
1389 totlen = m->m_pkthdr.len;
1390 #endif
1391
1392 #if FE_DEBUG >= 1
1393 /*
1394 * Should never send big packets. If such a packet is passed,
1395 * it should be a bug of upper layer. We just ignore it.
1396 * ... Partial (too short) packets, neither.
1397 */
1398 if (totlen > (ETHER_MAX_LEN - ETHER_CRC_LEN) ||
1399 totlen < ETHER_HDR_LEN) {
1400 log(LOG_ERR, "%s: got a %s packet (%u bytes) to send\n",
1401 device_xname(sc->sc_dev),
1402 totlen < ETHER_HDR_LEN ? "partial" : "big", totlen);
1403 sc->sc_ec.ec_if.if_oerrors++;
1404 return;
1405 }
1406 #endif
1407
1408 /*
1409 * Put the length word for this frame.
1410 * Does 86960 accept odd length? -- Yes.
1411 * Do we need to pad the length to minimum size by ourselves?
1412 * -- Generally yes. But for (or will be) the last
1413 * packet in the transmission buffer, we can skip the
1414 * padding process. It may gain performance slightly. FIXME.
1415 */
1416 len = max(totlen, (ETHER_MIN_LEN - ETHER_CRC_LEN));
1417 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) {
1418 bus_space_write_1(bst, bsh, FE_BMPR8, len);
1419 bus_space_write_1(bst, bsh, FE_BMPR8, len >> 8);
1420 } else {
1421 bus_space_write_2(bst, bsh, FE_BMPR8, len);
1422 /* roundup packet length since we will use word access */
1423 totlen = (totlen + 1) & ~1;
1424 }
1425
1426 /*
1427 * Update buffer status now.
1428 * Truncate the length up to an even number
1429 * if the chip is set in SBW_WORD mode.
1430 */
1431 sc->txb_free -= FE_TXLEN_SIZE +
1432 max(totlen, (ETHER_MIN_LEN - ETHER_CRC_LEN));
1433 sc->txb_count++;
1434
1435 #if FE_DELAYED_PADDING
1436 /* Postpone the packet padding if necessary. */
1437 if (totlen < (ETHER_MIN_LEN - ETHER_CRC_LEN))
1438 sc->txb_padding = (ETHER_MIN_LEN - ETHER_CRC_LEN) - totlen;
1439 #endif
1440
1441 /*
1442 * Transfer the data from mbuf chain to the transmission buffer.
1443 * If the MB86960 is configured in word mode, data needs to be
1444 * transferred as words, and only words.
1445 * So that we require some extra code to patch over odd-length
1446 * or unaligned mbufs.
1447 */
1448 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) {
1449 /* It's simple in byte mode. */
1450 for (; m != NULL; m = m->m_next) {
1451 if (m->m_len) {
1452 bus_space_write_multi_1(bst, bsh, FE_BMPR8,
1453 mtod(m, uint8_t *), m->m_len);
1454 }
1455 }
1456 } else {
1457 /* a bit trickier in word mode. */
1458 uint8_t *data, savebyte[2];
1459 int leftover;
1460
1461 leftover = 0;
1462 savebyte[0] = savebyte[1] = 0;
1463
1464 for (; m != NULL; m = m->m_next) {
1465 len = m->m_len;
1466 if (len == 0)
1467 continue;
1468 data = mtod(m, uint8_t *);
1469 while (len > 0) {
1470 if (leftover) {
1471 /*
1472 * Data left over (from mbuf or
1473 * realignment). Buffer the next
1474 * byte, and write it and the
1475 * leftover data out.
1476 */
1477 savebyte[1] = *data++;
1478 len--;
1479 bus_space_write_stream_2(bst, bsh,
1480 FE_BMPR8, *(uint16_t *)savebyte);
1481 leftover = 0;
1482 } else if (BUS_SPACE_ALIGNED_POINTER(data,
1483 uint16_t) == 0) {
1484 /*
1485 * Unaligned data; buffer the next byte.
1486 */
1487 savebyte[0] = *data++;
1488 len--;
1489 leftover = 1;
1490 } else {
1491 /*
1492 * Aligned data; output contiguous
1493 * words as much as we can, then
1494 * buffer the remaining byte, if any.
1495 */
1496 leftover = len & 1;
1497 len &= ~1;
1498 bus_space_write_multi_stream_2(bst, bsh,
1499 FE_BMPR8, (uint16_t *)data,
1500 len >> 1);
1501 data += len;
1502 if (leftover)
1503 savebyte[0] = *data++;
1504 len = 0;
1505 }
1506 }
1507 if (len < 0)
1508 panic("mb86960_write_mbufs: negative len");
1509 }
1510 if (leftover) {
1511 savebyte[1] = 0;
1512 bus_space_write_stream_2(bst, bsh, FE_BMPR8,
1513 *(uint16_t *)savebyte);
1514 }
1515 }
1516 #if FE_DELAYED_PADDING == 0
1517 /*
1518 * Pad the packet to the minimum length if necessary.
1519 */
1520 len = (ETHER_MIN_LEN - ETHER_CRC_LEN) - totlen;
1521 if (len > 0) {
1522 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) {
1523 while (len-- > 0)
1524 bus_space_write_1(bst, bsh, FE_BMPR8, 0);
1525 } else {
1526 len >>= 1;
1527 while (len-- > 0)
1528 bus_space_write_2(bst, bsh, FE_BMPR8, 0);
1529 }
1530 }
1531 #endif
1532 }
1533
1534 /*
1535 * Compute the multicast address filter from the
1536 * list of multicast addresses we need to listen to.
1537 */
1538 void
1539 mb86960_getmcaf(struct ethercom *ec, uint8_t *af)
1540 {
1541 struct ifnet *ifp = &ec->ec_if;
1542 struct ether_multi *enm;
1543 uint32_t crc;
1544 struct ether_multistep step;
1545
1546 /*
1547 * Set up multicast address filter by passing all multicast addresses
1548 * through a crc generator, and then using the high order 6 bits as an
1549 * index into the 64 bit logical address filter. The high order bit
1550 * selects the word, while the rest of the bits select the bit within
1551 * the word.
1552 */
1553
1554 if ((ifp->if_flags & IFF_PROMISC) != 0)
1555 goto allmulti;
1556
1557 memset(af, 0, FE_FILTER_LEN);
1558 ETHER_FIRST_MULTI(step, ec, enm);
1559 while (enm != NULL) {
1560 if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
1561 sizeof(enm->enm_addrlo)) != 0) {
1562 /*
1563 * We must listen to a range of multicast addresses.
1564 * For now, just accept all multicasts, rather than
1565 * trying to set only those filter bits needed to match
1566 * the range. (At this time, the only use of address
1567 * ranges is for IP multicast routing, for which the
1568 * range is big enough to require all bits set.)
1569 */
1570 goto allmulti;
1571 }
1572
1573 crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN);
1574
1575 /* Just want the 6 most significant bits. */
1576 crc >>= 26;
1577
1578 /* Turn on the corresponding bit in the filter. */
1579 af[crc >> 3] |= 1 << (crc & 7);
1580
1581 ETHER_NEXT_MULTI(step, enm);
1582 }
1583 ifp->if_flags &= ~IFF_ALLMULTI;
1584 return;
1585
1586 allmulti:
1587 ifp->if_flags |= IFF_ALLMULTI;
1588 memset(af, 0xff, FE_FILTER_LEN);
1589 }
1590
1591 /*
1592 * Calculate a new "multicast packet filter" and put the 86960
1593 * receiver in appropriate mode.
1594 */
1595 void
1596 mb86960_setmode(struct mb86960_softc *sc)
1597 {
1598 bus_space_tag_t bst = sc->sc_bst;
1599 bus_space_handle_t bsh = sc->sc_bsh;
1600 int flags = sc->sc_ec.ec_if.if_flags;
1601
1602 /*
1603 * If the interface is not running, we postpone the update
1604 * process for receive modes and multicast address filter
1605 * until the interface is restarted. It reduces some
1606 * complicated job on maintaining chip states. (Earlier versions
1607 * of this driver had a bug on that point...)
1608 *
1609 * To complete the trick, mb86960_init() calls mb86960_setmode() after
1610 * restarting the interface.
1611 */
1612 if ((flags & IFF_RUNNING) == 0)
1613 return;
1614
1615 /*
1616 * Promiscuous mode is handled separately.
1617 */
1618 if ((flags & IFF_PROMISC) != 0) {
1619 /*
1620 * Program 86960 to receive all packets on the segment
1621 * including those directed to other stations.
1622 * Multicast filter stored in MARs are ignored
1623 * under this setting, so we don't need to update it.
1624 *
1625 * Promiscuous mode is used solely by BPF, and BPF only
1626 * listens to valid (no error) packets. So, we ignore
1627 * errornous ones even in this mode.
1628 */
1629 bus_space_write_1(bst, bsh, FE_DLCR5,
1630 sc->proto_dlcr5 | FE_D5_AFM0 | FE_D5_AFM1);
1631 sc->filter_change = 0;
1632
1633 #if FE_DEBUG >= 3
1634 log(LOG_INFO, "%s: promiscuous mode\n",
1635 device_xname(sc->sc_dev));
1636 #endif
1637 return;
1638 }
1639
1640 /*
1641 * Turn the chip to the normal (non-promiscuous) mode.
1642 */
1643 bus_space_write_1(bst, bsh, FE_DLCR5, sc->proto_dlcr5 | FE_D5_AFM1);
1644
1645 /*
1646 * Find the new multicast filter value.
1647 */
1648 mb86960_getmcaf(&sc->sc_ec, sc->filter);
1649 sc->filter_change = 1;
1650
1651 #if FE_DEBUG >= 3
1652 log(LOG_INFO,
1653 "%s: address filter: [%02x %02x %02x %02x %02x %02x %02x %02x]\n",
1654 device_xname(sc->sc_dev),
1655 sc->filter[0], sc->filter[1], sc->filter[2], sc->filter[3],
1656 sc->filter[4], sc->filter[5], sc->filter[6], sc->filter[7]);
1657 #endif
1658
1659 /*
1660 * We have to update the multicast filter in the 86960, A.S.A.P.
1661 *
1662 * Note that the DLC (Data Linc Control unit, i.e. transmitter
1663 * and receiver) must be stopped when feeding the filter, and
1664 * DLC trashes all packets in both transmission and receive
1665 * buffers when stopped.
1666 *
1667 * ... Are the above sentenses correct? I have to check the
1668 * manual of the MB86960A. FIXME.
1669 *
1670 * To reduce the packet lossage, we delay the filter update
1671 * process until buffers are empty.
1672 */
1673 if (sc->txb_sched == 0 && sc->txb_count == 0 &&
1674 (bus_space_read_1(bst, bsh, FE_DLCR1) & FE_D1_PKTRDY) == 0) {
1675 /*
1676 * Buffers are (apparently) empty. Load
1677 * the new filter value into MARs now.
1678 */
1679 mb86960_loadmar(sc);
1680 } else {
1681 /*
1682 * Buffers are not empty. Mark that we have to update
1683 * the MARs. The new filter will be loaded by mb86960_intr()
1684 * later.
1685 */
1686 #if FE_DEBUG >= 4
1687 log(LOG_INFO, "%s: filter change delayed\n",
1688 device_xname(sc->sc_dev));
1689 #endif
1690 }
1691 }
1692
1693 /*
1694 * Load a new multicast address filter into MARs.
1695 *
1696 * The caller must have splnet'ed befor mb86960_loadmar.
1697 * This function starts the DLC upon return. So it can be called only
1698 * when the chip is working, i.e., from the driver's point of view, when
1699 * a device is RUNNING. (I mistook the point in previous versions.)
1700 */
1701 void
1702 mb86960_loadmar(struct mb86960_softc *sc)
1703 {
1704 bus_space_tag_t bst = sc->sc_bst;
1705 bus_space_handle_t bsh = sc->sc_bsh;
1706
1707 /* Stop the DLC (transmitter and receiver). */
1708 bus_space_write_1(bst, bsh, FE_DLCR6,
1709 sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
1710
1711 /* Select register bank 1 for MARs. */
1712 bus_space_write_1(bst, bsh, FE_DLCR7,
1713 sc->proto_dlcr7 | FE_D7_RBS_MAR | FE_D7_POWER_UP);
1714
1715 /* Copy filter value into the registers. */
1716 bus_space_write_region_1(bst, bsh, FE_MAR8, sc->filter, FE_FILTER_LEN);
1717
1718 /* Restore the bank selection for BMPRs (i.e., runtime registers). */
1719 bus_space_write_1(bst, bsh, FE_DLCR7,
1720 sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP);
1721
1722 /* Restart the DLC. */
1723 bus_space_write_1(bst, bsh, FE_DLCR6,
1724 sc->proto_dlcr6 | FE_D6_DLC_ENABLE);
1725
1726 /* We have just updated the filter. */
1727 sc->filter_change = 0;
1728
1729 #if FE_DEBUG >= 3
1730 log(LOG_INFO, "%s: address filter changed\n", device_xname(sc->sc_dev));
1731 #endif
1732 }
1733
1734 /*
1735 * Enable power on the interface.
1736 */
1737 int
1738 mb86960_enable(struct mb86960_softc *sc)
1739 {
1740
1741 #if FE_DEBUG >= 3
1742 log(LOG_INFO, "%s: mb86960_enable()\n", device_xname(sc->sc_dev));
1743 #endif
1744
1745 if ((sc->sc_stat & FE_STAT_ENABLED) == 0 && sc->sc_enable != NULL) {
1746 if ((*sc->sc_enable)(sc) != 0) {
1747 aprint_error_dev(sc->sc_dev, "device enable failed\n");
1748 return EIO;
1749 }
1750 }
1751
1752 sc->sc_stat |= FE_STAT_ENABLED;
1753 return 0;
1754 }
1755
1756 /*
1757 * Disable power on the interface.
1758 */
1759 void
1760 mb86960_disable(struct mb86960_softc *sc)
1761 {
1762
1763 #if FE_DEBUG >= 3
1764 log(LOG_INFO, "%s: mb86960_disable()\n", device_xname(sc->sc_dev));
1765 #endif
1766
1767 if ((sc->sc_stat & FE_STAT_ENABLED) != 0 && sc->sc_disable != NULL) {
1768 (*sc->sc_disable)(sc);
1769 sc->sc_stat &= ~FE_STAT_ENABLED;
1770 }
1771 }
1772
1773 /*
1774 * mbe_activate:
1775 *
1776 * Handle device activation/deactivation requests.
1777 */
1778 int
1779 mb86960_activate(device_t self, enum devact act)
1780 {
1781 struct mb86960_softc *sc = device_private(self);
1782
1783 switch (act) {
1784 case DVACT_DEACTIVATE:
1785 if_deactivate(&sc->sc_ec.ec_if);
1786 return 0;
1787 default:
1788 return EOPNOTSUPP;
1789 }
1790 }
1791
1792 /*
1793 * mb86960_detach:
1794 *
1795 * Detach a MB86960 interface.
1796 */
1797 int
1798 mb86960_detach(struct mb86960_softc *sc)
1799 {
1800 struct ifnet *ifp = &sc->sc_ec.ec_if;
1801
1802 /* Succeed now if there's no work to do. */
1803 if ((sc->sc_stat & FE_STAT_ATTACHED) == 0)
1804 return 0;
1805
1806 /* Delete all media. */
1807 ifmedia_delete_instance(&sc->sc_media, IFM_INST_ANY);
1808
1809 /* Unhook the entropy source. */
1810 rnd_detach_source(&sc->rnd_source);
1811
1812 ether_ifdetach(ifp);
1813 if_detach(ifp);
1814
1815 mb86960_disable(sc);
1816 return 0;
1817 }
1818
1819 /*
1820 * Routines to read all bytes from the config EEPROM (93C06) through MB86965A.
1821 */
1822 void
1823 mb86965_read_eeprom(bus_space_tag_t iot, bus_space_handle_t ioh, uint8_t *data)
1824 {
1825 int addr, op, bit;
1826 uint16_t val;
1827
1828 /* Read bytes from EEPROM; two bytes per an iteration. */
1829 for (addr = 0; addr < FE_EEPROM_SIZE / 2; addr++) {
1830 /* Reset the EEPROM interface. */
1831 bus_space_write_1(iot, ioh, FE_BMPR16, 0x00);
1832 bus_space_write_1(iot, ioh, FE_BMPR17, 0x00);
1833 bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT);
1834
1835 /* Send start bit. */
1836 bus_space_write_1(iot, ioh, FE_BMPR17, FE_B17_DATA);
1837 FE_EEPROM_DELAY();
1838 bus_space_write_1(iot, ioh,
1839 FE_BMPR16, FE_B16_SELECT | FE_B16_CLOCK);
1840 FE_EEPROM_DELAY();
1841 bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT);
1842
1843 /* Send read command and read address. */
1844 op = 0x80 | addr; /* READ instruction */
1845 for (bit = 8; bit > 0; bit--) {
1846 bus_space_write_1(iot, ioh, FE_BMPR17,
1847 (op & (1 << (bit - 1))) ? FE_B17_DATA : 0);
1848 FE_EEPROM_DELAY();
1849 bus_space_write_1(iot, ioh,
1850 FE_BMPR16, FE_B16_SELECT | FE_B16_CLOCK);
1851 FE_EEPROM_DELAY();
1852 bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT);
1853 }
1854 bus_space_write_1(iot, ioh, FE_BMPR17, 0x00);
1855
1856 /* Read two bytes in each address */
1857 val = 0;
1858 for (bit = 16; bit > 0; bit--) {
1859 FE_EEPROM_DELAY();
1860 bus_space_write_1(iot, ioh,
1861 FE_BMPR16, FE_B16_SELECT | FE_B16_CLOCK);
1862 FE_EEPROM_DELAY();
1863 if (bus_space_read_1(iot, ioh, FE_BMPR17) &
1864 FE_B17_DATA)
1865 val |= 1 << (bit - 1);
1866 bus_space_write_1(iot, ioh,
1867 FE_BMPR16, FE_B16_SELECT);
1868 }
1869 data[addr * 2] = val >> 8;
1870 data[addr * 2 + 1] = val & 0xff;
1871 }
1872
1873 /* Make sure the EEPROM is turned off. */
1874 bus_space_write_1(iot, ioh, FE_BMPR16, 0);
1875 bus_space_write_1(iot, ioh, FE_BMPR17, 0);
1876
1877 #if FE_DEBUG >= 3
1878 /* Report what we got. */
1879 log(LOG_INFO, "mb86965_read_eeprom: "
1880 " %02x%02x%02x%02x %02x%02x%02x%02x -"
1881 " %02x%02x%02x%02x %02x%02x%02x%02x -"
1882 " %02x%02x%02x%02x %02x%02x%02x%02x -"
1883 " %02x%02x%02x%02x %02x%02x%02x%02x\n",
1884 data[ 0], data[ 1], data[ 2], data[ 3],
1885 data[ 4], data[ 5], data[ 6], data[ 7],
1886 data[ 8], data[ 9], data[10], data[11],
1887 data[12], data[13], data[14], data[15],
1888 data[16], data[17], data[18], data[19],
1889 data[20], data[21], data[22], data[23],
1890 data[24], data[25], data[26], data[27],
1891 data[28], data[29], data[30], data[31]);
1892 #endif
1893 }
1894
1895 #if FE_DEBUG >= 1
1896 void
1897 mb86960_dump(int level, struct mb86960_softc *sc)
1898 {
1899 bus_space_tag_t bst = sc->sc_bst;
1900 bus_space_handle_t bsh = sc->sc_bsh;
1901 uint8_t save_dlcr7;
1902
1903 save_dlcr7 = bus_space_read_1(bst, bsh, FE_DLCR7);
1904
1905 log(level, "\tDLCR = %02x %02x %02x %02x %02x %02x %02x %02x\n",
1906 bus_space_read_1(bst, bsh, FE_DLCR0),
1907 bus_space_read_1(bst, bsh, FE_DLCR1),
1908 bus_space_read_1(bst, bsh, FE_DLCR2),
1909 bus_space_read_1(bst, bsh, FE_DLCR3),
1910 bus_space_read_1(bst, bsh, FE_DLCR4),
1911 bus_space_read_1(bst, bsh, FE_DLCR5),
1912 bus_space_read_1(bst, bsh, FE_DLCR6),
1913 bus_space_read_1(bst, bsh, FE_DLCR7));
1914
1915 bus_space_write_1(bst, bsh, FE_DLCR7,
1916 (save_dlcr7 & ~FE_D7_RBS) | FE_D7_RBS_DLCR);
1917 log(level, "\t %02x %02x %02x %02x %02x %02x %02x %02x\n",
1918 bus_space_read_1(bst, bsh, FE_DLCR8),
1919 bus_space_read_1(bst, bsh, FE_DLCR9),
1920 bus_space_read_1(bst, bsh, FE_DLCR10),
1921 bus_space_read_1(bst, bsh, FE_DLCR11),
1922 bus_space_read_1(bst, bsh, FE_DLCR12),
1923 bus_space_read_1(bst, bsh, FE_DLCR13),
1924 bus_space_read_1(bst, bsh, FE_DLCR14),
1925 bus_space_read_1(bst, bsh, FE_DLCR15));
1926
1927 bus_space_write_1(bst, bsh, FE_DLCR7,
1928 (save_dlcr7 & ~FE_D7_RBS) | FE_D7_RBS_MAR);
1929 log(level, "\tMAR = %02x %02x %02x %02x %02x %02x %02x %02x\n",
1930 bus_space_read_1(bst, bsh, FE_MAR8),
1931 bus_space_read_1(bst, bsh, FE_MAR9),
1932 bus_space_read_1(bst, bsh, FE_MAR10),
1933 bus_space_read_1(bst, bsh, FE_MAR11),
1934 bus_space_read_1(bst, bsh, FE_MAR12),
1935 bus_space_read_1(bst, bsh, FE_MAR13),
1936 bus_space_read_1(bst, bsh, FE_MAR14),
1937 bus_space_read_1(bst, bsh, FE_MAR15));
1938
1939 bus_space_write_1(bst, bsh, FE_DLCR7,
1940 (save_dlcr7 & ~FE_D7_RBS) | FE_D7_RBS_BMPR);
1941 log(level,
1942 "\tBMPR = xx xx %02x %02x %02x %02x %02x %02x %02x %02x xx %02x\n",
1943 bus_space_read_1(bst, bsh, FE_BMPR10),
1944 bus_space_read_1(bst, bsh, FE_BMPR11),
1945 bus_space_read_1(bst, bsh, FE_BMPR12),
1946 bus_space_read_1(bst, bsh, FE_BMPR13),
1947 bus_space_read_1(bst, bsh, FE_BMPR14),
1948 bus_space_read_1(bst, bsh, FE_BMPR15),
1949 bus_space_read_1(bst, bsh, FE_BMPR16),
1950 bus_space_read_1(bst, bsh, FE_BMPR17),
1951 bus_space_read_1(bst, bsh, FE_BMPR19));
1952
1953 bus_space_write_1(bst, bsh, FE_DLCR7, save_dlcr7);
1954 }
1955 #endif
1956
1957