| @@ -1,41 +1,41 @@ | | | @@ -1,41 +1,41 @@ |
1 | /* $NetBSD: mb8795.c,v 1.65 2019/05/29 10:07:29 msaitoh Exp $ */ | | 1 | /* $NetBSD: mb8795.c,v 1.66 2020/01/29 05:31:10 thorpej Exp $ */ |
2 | /* | | 2 | /* |
3 | * Copyright (c) 1998 Darrin B. Jewell | | 3 | * Copyright (c) 1998 Darrin B. Jewell |
4 | * All rights reserved. | | 4 | * All rights reserved. |
5 | * | | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | | 7 | * modification, are permitted provided that the following conditions |
8 | * are met: | | 8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright | | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright | | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | | 13 | * documentation and/or other materials provided with the distribution. |
14 | * | | 14 | * |
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ | | 25 | */ |
26 | | | 26 | |
27 | #include <sys/cdefs.h> | | 27 | #include <sys/cdefs.h> |
28 | __KERNEL_RCSID(0, "$NetBSD: mb8795.c,v 1.65 2019/05/29 10:07:29 msaitoh Exp $"); | | 28 | __KERNEL_RCSID(0, "$NetBSD: mb8795.c,v 1.66 2020/01/29 05:31:10 thorpej Exp $"); |
29 | | | 29 | |
30 | #include "opt_inet.h" | | 30 | #include "opt_inet.h" |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/systm.h> | | 33 | #include <sys/systm.h> |
34 | #include <sys/mbuf.h> | | 34 | #include <sys/mbuf.h> |
35 | #include <sys/syslog.h> | | 35 | #include <sys/syslog.h> |
36 | #include <sys/socket.h> | | 36 | #include <sys/socket.h> |
37 | #include <sys/device.h> | | 37 | #include <sys/device.h> |
38 | #include <sys/malloc.h> | | 38 | #include <sys/malloc.h> |
39 | #include <sys/ioctl.h> | | 39 | #include <sys/ioctl.h> |
40 | #include <sys/errno.h> | | 40 | #include <sys/errno.h> |
41 | #include <sys/rndsource.h> | | 41 | #include <sys/rndsource.h> |
| @@ -273,27 +273,27 @@ mb8795_rint(struct mb8795_softc *sc) | | | @@ -273,27 +273,27 @@ mb8795_rint(struct mb8795_softc *sc) |
273 | DPRINTF(("%s: rx CRC error\n", device_xname(sc->sc_dev))); | | 273 | DPRINTF(("%s: rx CRC error\n", device_xname(sc->sc_dev))); |
274 | #if 0 | | 274 | #if 0 |
275 | error++; | | 275 | error++; |
276 | #endif | | 276 | #endif |
277 | } | | 277 | } |
278 | if (rxstat & MB8795_RXSTAT_OVERFLOW) { | | 278 | if (rxstat & MB8795_RXSTAT_OVERFLOW) { |
279 | DPRINTF(("%s: rx overflow error\n", device_xname(sc->sc_dev))); | | 279 | DPRINTF(("%s: rx overflow error\n", device_xname(sc->sc_dev))); |
280 | #if 0 | | 280 | #if 0 |
281 | error++; | | 281 | error++; |
282 | #endif | | 282 | #endif |
283 | } | | 283 | } |
284 | | | 284 | |
285 | if (error) { | | 285 | if (error) { |
286 | ifp->if_ierrors++; | | 286 | if_statinc(ifp, if_ierrors); |
287 | /* @@@ handle more gracefully, free memory, etc. */ | | 287 | /* @@@ handle more gracefully, free memory, etc. */ |
288 | } | | 288 | } |
289 | | | 289 | |
290 | if (rxstat & MB8795_RXSTAT_OK) { | | 290 | if (rxstat & MB8795_RXSTAT_OK) { |
291 | struct mbuf *m; | | 291 | struct mbuf *m; |
292 | int s; | | 292 | int s; |
293 | s = spldma(); | | 293 | s = spldma(); |
294 | | | 294 | |
295 | while ((m = MBDMA_RX_MBUF (sc))) { | | 295 | while ((m = MBDMA_RX_MBUF (sc))) { |
296 | /* CRC is included with the packet; trim it. */ | | 296 | /* CRC is included with the packet; trim it. */ |
297 | m->m_pkthdr.len = m->m_len = m->m_len - ETHER_CRC_LEN; | | 297 | m->m_pkthdr.len = m->m_len = m->m_len - ETHER_CRC_LEN; |
298 | m_set_rcvif(m, ifp); | | 298 | m_set_rcvif(m, ifp); |
299 | | | 299 | |
| @@ -375,40 +375,40 @@ mb8795_tint(struct mb8795_softc *sc) | | | @@ -375,40 +375,40 @@ mb8795_tint(struct mb8795_softc *sc) |
375 | /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask & ~MB8795_TXMASK_TXRXIE); */ | | 375 | /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask & ~MB8795_TXMASK_TXRXIE); */ |
376 | MB_WRITE_REG(sc, MB8795_TXMASK, 0); | | 376 | MB_WRITE_REG(sc, MB8795_TXMASK, 0); |
377 | if ((ifp->if_flags & IFF_RUNNING) | | 377 | if ((ifp->if_flags & IFF_RUNNING) |
378 | && !IF_IS_EMPTY(&sc->sc_tx_snd)) { | | 378 | && !IF_IS_EMPTY(&sc->sc_tx_snd)) { |
379 | void mb8795_start_dma(struct mb8795_softc *); /* XXX */ | | 379 | void mb8795_start_dma(struct mb8795_softc *); /* XXX */ |
380 | /* printf ("Z"); */ | | 380 | /* printf ("Z"); */ |
381 | mb8795_start_dma(sc); | | 381 | mb8795_start_dma(sc); |
382 | } | | 382 | } |
383 | return; | | 383 | return; |
384 | } | | 384 | } |
385 | | | 385 | |
386 | if (txstat & MB8795_TXSTAT_SHORTED) { | | 386 | if (txstat & MB8795_TXSTAT_SHORTED) { |
387 | printf("%s: tx cable shorted\n", device_xname(sc->sc_dev)); | | 387 | printf("%s: tx cable shorted\n", device_xname(sc->sc_dev)); |
388 | ifp->if_oerrors++; | | 388 | if_statinc(ifp, if_oerrors); |
389 | } | | 389 | } |
390 | if (txstat & MB8795_TXSTAT_UNDERFLOW) { | | 390 | if (txstat & MB8795_TXSTAT_UNDERFLOW) { |
391 | printf("%s: tx underflow\n", device_xname(sc->sc_dev)); | | 391 | printf("%s: tx underflow\n", device_xname(sc->sc_dev)); |
392 | ifp->if_oerrors++; | | 392 | if_statinc(ifp, if_oerrors); |
393 | } | | 393 | } |
394 | if (txstat & MB8795_TXSTAT_COLLERR) { | | 394 | if (txstat & MB8795_TXSTAT_COLLERR) { |
395 | DPRINTF(("%s: tx collision\n", device_xname(sc->sc_dev))); | | 395 | DPRINTF(("%s: tx collision\n", device_xname(sc->sc_dev))); |
396 | ifp->if_collisions++; | | 396 | if_statinc(ifp, if_collisions); |
397 | } | | 397 | } |
398 | if (txstat & MB8795_TXSTAT_COLLERR16) { | | 398 | if (txstat & MB8795_TXSTAT_COLLERR16) { |
399 | printf("%s: tx 16th collision\n", device_xname(sc->sc_dev)); | | 399 | printf("%s: tx 16th collision\n", device_xname(sc->sc_dev)); |
400 | ifp->if_oerrors++; | | 400 | if_statinc(ifp, if_oerrors); |
401 | ifp->if_collisions += 16; | | 401 | if_statadd(ifp, if_collisions, 16); |
402 | } | | 402 | } |
403 | | | 403 | |
404 | #if 0 | | 404 | #if 0 |
405 | if (txstat & MB8795_TXSTAT_READY) { | | 405 | if (txstat & MB8795_TXSTAT_READY) { |
406 | char sbuf[256]; | | 406 | char sbuf[256]; |
407 | | | 407 | |
408 | snprintb(sbuf, sizeof(sbuf), MB8795_TXSTAT_BITS, txstat); | | 408 | snprintb(sbuf, sizeof(sbuf), MB8795_TXSTAT_BITS, txstat); |
409 | panic("%s: unexpected tx interrupt %s", | | 409 | panic("%s: unexpected tx interrupt %s", |
410 | device_xname(sc->sc_dev), sbuf); | | 410 | device_xname(sc->sc_dev), sbuf); |
411 | | | 411 | |
412 | /* turn interrupt off */ | | 412 | /* turn interrupt off */ |
413 | MB_WRITE_REG(sc, MB8795_TXMASK, | | 413 | MB_WRITE_REG(sc, MB8795_TXMASK, |
414 | txmask & ~MB8795_TXMASK_READYIE); | | 414 | txmask & ~MB8795_TXMASK_READYIE); |
| @@ -473,30 +473,27 @@ mb8795_reset(struct mb8795_softc *sc) | | | @@ -473,30 +473,27 @@ mb8795_reset(struct mb8795_softc *sc) |
473 | sizeof(sc->sc_enaddr))); | | 473 | sizeof(sc->sc_enaddr))); |
474 | | | 474 | |
475 | MB_WRITE_REG(sc, MB8795_RESET, 0); | | 475 | MB_WRITE_REG(sc, MB8795_RESET, 0); |
476 | | | 476 | |
477 | splx(s); | | 477 | splx(s); |
478 | } | | 478 | } |
479 | | | 479 | |
480 | void | | 480 | void |
481 | mb8795_watchdog(struct ifnet *ifp) | | 481 | mb8795_watchdog(struct ifnet *ifp) |
482 | { | | 482 | { |
483 | struct mb8795_softc *sc = ifp->if_softc; | | 483 | struct mb8795_softc *sc = ifp->if_softc; |
484 | | | 484 | |
485 | log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev)); | | 485 | log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev)); |
486 | ++ifp->if_oerrors; | | 486 | if_statinc(ifp, if_oerrors); |
487 | | | | |
488 | DPRINTF(("%s: %lld input errors, %lld input packets\n", | | | |
489 | device_xname(sc->sc_dev), ifp->if_ierrors, ifp->if_ipackets)); | | | |
490 | | | 487 | |
491 | ifp->if_flags &= ~IFF_RUNNING; | | 488 | ifp->if_flags &= ~IFF_RUNNING; |
492 | mb8795_init(sc); | | 489 | mb8795_init(sc); |
493 | } | | 490 | } |
494 | | | 491 | |
495 | /* | | 492 | /* |
496 | * Initialization of interface; set up initialization block | | 493 | * Initialization of interface; set up initialization block |
497 | * and transmit/receive descriptor rings. | | 494 | * and transmit/receive descriptor rings. |
498 | */ | | 495 | */ |
499 | void | | 496 | void |
500 | mb8795_init(struct mb8795_softc *sc) | | 497 | mb8795_init(struct mb8795_softc *sc) |
501 | { | | 498 | { |
502 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 499 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
| @@ -752,17 +749,17 @@ mb8795_start_dma(struct mb8795_softc *sc | | | @@ -752,17 +749,17 @@ mb8795_start_dma(struct mb8795_softc *sc |
752 | /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask | MB8795_TXMASK_READYIE); */ | | 749 | /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask | MB8795_TXMASK_READYIE); */ |
753 | /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask | MB8795_TXMASK_TXRXIE); */ | | 750 | /* MB_WRITE_REG(sc, MB8795_TXMASK, txmask | MB8795_TXMASK_TXRXIE); */ |
754 | | | 751 | |
755 | ifp->if_timer = 5; | | 752 | ifp->if_timer = 5; |
756 | | | 753 | |
757 | if (MBDMA_TX_MBUF(sc, m)) | | 754 | if (MBDMA_TX_MBUF(sc, m)) |
758 | return; | | 755 | return; |
759 | | | 756 | |
760 | MBDMA_TX_GO(sc); | | 757 | MBDMA_TX_GO(sc); |
761 | if (turbo) | | 758 | if (turbo) |
762 | MB_WRITE_REG(sc, MB8795_TXMODE, | | 759 | MB_WRITE_REG(sc, MB8795_TXMODE, |
763 | MB8795_TXMODE_TURBO1 | MB8795_TXMODE_TURBOSTART); | | 760 | MB8795_TXMODE_TURBO1 | MB8795_TXMODE_TURBOSTART); |
764 | | | 761 | |
765 | ifp->if_opackets++; | | 762 | if_statinc(ifp, if_opackets); |
766 | } | | 763 | } |
767 | | | 764 | |
768 | /****************************************************************/ | | 765 | /****************************************************************/ |