Wed Jan 29 06:05:31 2020 UTC ()
Adopt <net/if_stats.h>.


(thorpej)
diff -r1.30 -r1.31 src/sys/arch/arm/imx/if_enet.c
diff -r1.11 -r1.12 src/sys/arch/arm/sunxi/sun4i_emac.c
diff -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_can.c
diff -r1.28 -r1.29 src/sys/arch/arm/sunxi/sunxi_emac.c
diff -r1.10 -r1.11 src/sys/arch/arm/ti/if_cpsw.c
diff -r1.44 -r1.45 src/sys/arch/arm/xscale/ixp425_if_npe.c

cvs diff -r1.30 -r1.31 src/sys/arch/arm/imx/if_enet.c (expand / switch to unified diff)

--- src/sys/arch/arm/imx/if_enet.c 2020/01/15 01:09:56 1.30
+++ src/sys/arch/arm/imx/if_enet.c 2020/01/29 06:05:31 1.31
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_enet.c,v 1.30 2020/01/15 01:09:56 jmcneill Exp $ */ 1/* $NetBSD: if_enet.c,v 1.31 2020/01/29 06:05:31 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2014 Ryo Shimizu <ryo@nerv.org> 4 * Copyright (c) 2014 Ryo Shimizu <ryo@nerv.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * i.MX6,7 10/100/1000-Mbps ethernet MAC (ENET) 30 * i.MX6,7 10/100/1000-Mbps ethernet MAC (ENET)
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: if_enet.c,v 1.30 2020/01/15 01:09:56 jmcneill Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: if_enet.c,v 1.31 2020/01/29 06:05:31 thorpej Exp $");
35 35
36#include "vlan.h" 36#include "vlan.h"
37 37
38#include <sys/param.h> 38#include <sys/param.h>
39#include <sys/bus.h> 39#include <sys/bus.h>
40#include <sys/mbuf.h> 40#include <sys/mbuf.h>
41#include <sys/device.h> 41#include <sys/device.h>
42#include <sys/sockio.h> 42#include <sys/sockio.h>
43#include <sys/kernel.h> 43#include <sys/kernel.h>
44#include <sys/rndsource.h> 44#include <sys/rndsource.h>
45 45
46#include <lib/libkern/libkern.h> 46#include <lib/libkern/libkern.h>
47 47
@@ -371,29 +371,30 @@ enet_tick(void *arg) @@ -371,29 +371,30 @@ enet_tick(void *arg)
371 mii = &sc->sc_mii; 371 mii = &sc->sc_mii;
372 ifp = &sc->sc_ethercom.ec_if; 372 ifp = &sc->sc_ethercom.ec_if;
373 373
374 s = splnet(); 374 s = splnet();
375 375
376 if (sc->sc_stopping) 376 if (sc->sc_stopping)
377 goto out; 377 goto out;
378 378
379#ifdef ENET_EVENT_COUNTER 379#ifdef ENET_EVENT_COUNTER
380 enet_update_evcnt(sc); 380 enet_update_evcnt(sc);
381#endif 381#endif
382 382
383 /* update counters */ 383 /* update counters */
384 ifp->if_ierrors += ENET_REG_READ(sc, ENET_RMON_R_UNDERSIZE); 384 if_statadd(ifp, if_ierrors,
385 ifp->if_ierrors += ENET_REG_READ(sc, ENET_RMON_R_FRAG); 385 (uint64_t)ENET_REG_READ(sc, ENET_RMON_R_UNDERSIZE) +
386 ifp->if_ierrors += ENET_REG_READ(sc, ENET_RMON_R_JAB); 386 (uint64_t)ENET_REG_READ(sc, ENET_RMON_R_FRAG) +
 387 (uint64_t)ENET_REG_READ(sc, ENET_RMON_R_JAB));
387 388
388 /* clear counters */ 389 /* clear counters */
389 ENET_REG_WRITE(sc, ENET_MIBC, ENET_MIBC_MIB_CLEAR); 390 ENET_REG_WRITE(sc, ENET_MIBC, ENET_MIBC_MIB_CLEAR);
390 ENET_REG_WRITE(sc, ENET_MIBC, 0); 391 ENET_REG_WRITE(sc, ENET_MIBC, 0);
391 392
392 mii_tick(mii); 393 mii_tick(mii);
393 out: 394 out:
394 395
395 if (!sc->sc_stopping) 396 if (!sc->sc_stopping)
396 callout_schedule(&sc->sc_tick_ch, ENET_TICK); 397 callout_schedule(&sc->sc_tick_ch, ENET_TICK);
397 398
398 splx(s); 399 splx(s);
399} 400}
@@ -451,54 +452,54 @@ enet_tx_intr(void *arg) @@ -451,54 +452,54 @@ enet_tx_intr(void *arg)
451 txs = &sc->sc_txsoft[idx]; 452 txs = &sc->sc_txsoft[idx];
452 453
453 TXDESC_READIN(idx); 454 TXDESC_READIN(idx);
454 if (sc->sc_txdesc_ring[idx].tx_flags1_len & TXFLAGS1_R) { 455 if (sc->sc_txdesc_ring[idx].tx_flags1_len & TXFLAGS1_R) {
455 /* This TX Descriptor has not been transmitted yet */ 456 /* This TX Descriptor has not been transmitted yet */
456 break; 457 break;
457 } 458 }
458 459
459 /* txsoft is available on first segment (TXFLAGS1_T1) */ 460 /* txsoft is available on first segment (TXFLAGS1_T1) */
460 if (sc->sc_txdesc_ring[idx].tx_flags1_len & TXFLAGS1_T1) { 461 if (sc->sc_txdesc_ring[idx].tx_flags1_len & TXFLAGS1_T1) {
461 bus_dmamap_unload(sc->sc_dmat, 462 bus_dmamap_unload(sc->sc_dmat,
462 txs->txs_dmamap); 463 txs->txs_dmamap);
463 m_freem(txs->txs_mbuf); 464 m_freem(txs->txs_mbuf);
464 ifp->if_opackets++; 465 if_statinc(ifp, if_opackets);
465 } 466 }
466 467
467 /* checking error */ 468 /* checking error */
468 if (sc->sc_txdesc_ring[idx].tx_flags1_len & TXFLAGS1_L) { 469 if (sc->sc_txdesc_ring[idx].tx_flags1_len & TXFLAGS1_L) {
469 uint32_t flags2; 470 uint32_t flags2;
470 471
471 flags2 = sc->sc_txdesc_ring[idx].tx_flags2; 472 flags2 = sc->sc_txdesc_ring[idx].tx_flags2;
472 473
473 if (flags2 & (TXFLAGS2_TXE | 474 if (flags2 & (TXFLAGS2_TXE |
474 TXFLAGS2_UE | TXFLAGS2_EE | TXFLAGS2_FE | 475 TXFLAGS2_UE | TXFLAGS2_EE | TXFLAGS2_FE |
475 TXFLAGS2_LCE | TXFLAGS2_OE | TXFLAGS2_TSE)) { 476 TXFLAGS2_LCE | TXFLAGS2_OE | TXFLAGS2_TSE)) {
476#ifdef DEBUG_ENET 477#ifdef DEBUG_ENET
477 if (enet_debug) { 478 if (enet_debug) {
478 char flagsbuf[128]; 479 char flagsbuf[128];
479 480
480 snprintb(flagsbuf, sizeof(flagsbuf), 481 snprintb(flagsbuf, sizeof(flagsbuf),
481 "\20" "\20TRANSMIT" "\16UNDERFLOW" 482 "\20" "\20TRANSMIT" "\16UNDERFLOW"
482 "\15COLLISION" "\14FRAME" 483 "\15COLLISION" "\14FRAME"
483 "\13LATECOLLISION" "\12OVERFLOW", 484 "\13LATECOLLISION" "\12OVERFLOW",
484 flags2); 485 flags2);
485 486
486 device_printf(sc->sc_dev, 487 device_printf(sc->sc_dev,
487 "txdesc[%d]: transmit error: " 488 "txdesc[%d]: transmit error: "
488 "flags2=%s\n", idx, flagsbuf); 489 "flags2=%s\n", idx, flagsbuf);
489 } 490 }
490#endif /* DEBUG_ENET */ 491#endif /* DEBUG_ENET */
491 ifp->if_oerrors++; 492 if_statinc(ifp, if_oerrors);
492 } 493 }
493 } 494 }
494 495
495 sc->sc_tx_free++; 496 sc->sc_tx_free++;
496 } 497 }
497 sc->sc_tx_considx = idx; 498 sc->sc_tx_considx = idx;
498 499
499 if (sc->sc_tx_free > 0) 500 if (sc->sc_tx_free > 0)
500 ifp->if_flags &= ~IFF_OACTIVE; 501 ifp->if_flags &= ~IFF_OACTIVE;
501 502
502 /* 503 /*
503 * No more pending TX descriptor, 504 * No more pending TX descriptor,
504 * cancel the watchdog timer. 505 * cancel the watchdog timer.
@@ -579,27 +580,27 @@ enet_rx_intr(void *arg) @@ -579,27 +580,27 @@ enet_rx_intr(void *arg)
579 "\20" "\31MISS" "\26LENGTHVIOLATION" 580 "\20" "\31MISS" "\26LENGTHVIOLATION"
580 "\25NONOCTET" "\23CRC" "\22OVERRUN" 581 "\25NONOCTET" "\23CRC" "\22OVERRUN"
581 "\21TRUNCATED", flags1); 582 "\21TRUNCATED", flags1);
582 snprintb(flags2buf, sizeof(flags2buf), 583 snprintb(flags2buf, sizeof(flags2buf),
583 "\20" "\40MAC" "\33PHY" 584 "\20" "\40MAC" "\33PHY"
584 "\32COLLISION", flags2); 585 "\32COLLISION", flags2);
585 586
586 DEVICE_DPRINTF( 587 DEVICE_DPRINTF(
587 "rxdesc[%d]: receive error: " 588 "rxdesc[%d]: receive error: "
588 "flags1=%s,flags2=%s,len=%d\n", 589 "flags1=%s,flags2=%s,len=%d\n",
589 idx, flags1buf, flags2buf, amount); 590 idx, flags1buf, flags2buf, amount);
590 } 591 }
591#endif /* DEBUG_ENET */ 592#endif /* DEBUG_ENET */
592 ifp->if_ierrors++; 593 if_statinc(ifp, if_ierrors);
593 m_freem(m0); 594 m_freem(m0);
594 595
595 } else { 596 } else {
596 /* packet receive ok */ 597 /* packet receive ok */
597 m_set_rcvif(m0, ifp); 598 m_set_rcvif(m0, ifp);
598 m0->m_pkthdr.len = amount; 599 m0->m_pkthdr.len = amount;
599 600
600 bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0, 601 bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0,
601 rxs->rxs_dmamap->dm_mapsize, 602 rxs->rxs_dmamap->dm_mapsize,
602 BUS_DMASYNC_PREREAD); 603 BUS_DMASYNC_PREREAD);
603 604
604 if (ifp->if_csum_flags_rx & (M_CSUM_IPv4 | 605 if (ifp->if_csum_flags_rx & (M_CSUM_IPv4 |
605 M_CSUM_TCPv4 | M_CSUM_UDPv4 | 606 M_CSUM_TCPv4 | M_CSUM_UDPv4 |
@@ -863,27 +864,27 @@ enet_start(struct ifnet *ifp) @@ -863,27 +864,27 @@ enet_start(struct ifnet *ifp)
863 ifp->if_flags |= IFF_OACTIVE; 864 ifp->if_flags |= IFF_OACTIVE;
864 DEVICE_DPRINTF("TX descriptor is full\n"); 865 DEVICE_DPRINTF("TX descriptor is full\n");
865 break; 866 break;
866 } 867 }
867 868
868 IFQ_DEQUEUE(&ifp->if_snd, m); 869 IFQ_DEQUEUE(&ifp->if_snd, m);
869 870
870 if (enet_encap_txring(sc, &m) != 0) { 871 if (enet_encap_txring(sc, &m) != 0) {
871 /* too many mbuf chains? */ 872 /* too many mbuf chains? */
872 ifp->if_flags |= IFF_OACTIVE; 873 ifp->if_flags |= IFF_OACTIVE;
873 DEVICE_DPRINTF( 874 DEVICE_DPRINTF(
874 "TX descriptor is full. dropping packet\n"); 875 "TX descriptor is full. dropping packet\n");
875 m_freem(m); 876 m_freem(m);
876 ifp->if_oerrors++; 877 if_statinc(ifp, if_oerrors);
877 break; 878 break;
878 } 879 }
879 880
880 /* Pass the packet to any BPF listeners */ 881 /* Pass the packet to any BPF listeners */
881 bpf_mtap(ifp, m, BPF_D_OUT); 882 bpf_mtap(ifp, m, BPF_D_OUT);
882 } 883 }
883 884
884 if (npkt) { 885 if (npkt) {
885 /* enable TX DMA */ 886 /* enable TX DMA */
886 ENET_REG_WRITE(sc, ENET_TDAR, ENET_TDAR_ACTIVE); 887 ENET_REG_WRITE(sc, ENET_TDAR, ENET_TDAR_ACTIVE);
887 888
888 ifp->if_timer = 5; 889 ifp->if_timer = 5;
889 } 890 }
@@ -919,27 +920,27 @@ enet_stop(struct ifnet *ifp, int disable @@ -919,27 +920,27 @@ enet_stop(struct ifnet *ifp, int disable
919 splx(s); 920 splx(s);
920} 921}
921 922
922static void 923static void
923enet_watchdog(struct ifnet *ifp) 924enet_watchdog(struct ifnet *ifp)
924{ 925{
925 struct enet_softc *sc; 926 struct enet_softc *sc;
926 int s; 927 int s;
927 928
928 sc = ifp->if_softc; 929 sc = ifp->if_softc;
929 s = splnet(); 930 s = splnet();
930 931
931 device_printf(sc->sc_dev, "watchdog timeout\n"); 932 device_printf(sc->sc_dev, "watchdog timeout\n");
932 ifp->if_oerrors++; 933 if_statinc(ifp, if_oerrors);
933 934
934 /* salvage packets left in descriptors */ 935 /* salvage packets left in descriptors */
935 enet_tx_intr(sc); 936 enet_tx_intr(sc);
936 enet_rx_intr(sc); 937 enet_rx_intr(sc);
937 938
938 /* reset */ 939 /* reset */
939 enet_stop(ifp, 1); 940 enet_stop(ifp, 1);
940 enet_init(ifp); 941 enet_init(ifp);
941 942
942 splx(s); 943 splx(s);
943} 944}
944 945
945static void 946static void
@@ -1312,27 +1313,27 @@ enet_drain_txbuf(struct enet_softc *sc) @@ -1312,27 +1313,27 @@ enet_drain_txbuf(struct enet_softc *sc)
1312 1313
1313 for (idx = sc->sc_tx_considx; idx != sc->sc_tx_prodidx; 1314 for (idx = sc->sc_tx_considx; idx != sc->sc_tx_prodidx;
1314 idx = ENET_TX_NEXTIDX(idx)) { 1315 idx = ENET_TX_NEXTIDX(idx)) {
1315 1316
1316 /* txsoft[] is used only first segment */ 1317 /* txsoft[] is used only first segment */
1317 txs = &sc->sc_txsoft[idx]; 1318 txs = &sc->sc_txsoft[idx];
1318 TXDESC_READIN(idx); 1319 TXDESC_READIN(idx);
1319 if (sc->sc_txdesc_ring[idx].tx_flags1_len & TXFLAGS1_T1) { 1320 if (sc->sc_txdesc_ring[idx].tx_flags1_len & TXFLAGS1_T1) {
1320 sc->sc_txdesc_ring[idx].tx_flags1_len = 0; 1321 sc->sc_txdesc_ring[idx].tx_flags1_len = 0;
1321 bus_dmamap_unload(sc->sc_dmat, 1322 bus_dmamap_unload(sc->sc_dmat,
1322 txs->txs_dmamap); 1323 txs->txs_dmamap);
1323 m_freem(txs->txs_mbuf); 1324 m_freem(txs->txs_mbuf);
1324 1325
1325 ifp->if_oerrors++; 1326 if_statinc(ifp, if_oerrors);
1326 } 1327 }
1327 sc->sc_tx_free++; 1328 sc->sc_tx_free++;
1328 } 1329 }
1329} 1330}
1330 1331
1331static void 1332static void
1332enet_drain_rxbuf(struct enet_softc *sc) 1333enet_drain_rxbuf(struct enet_softc *sc)
1333{ 1334{
1334 int i; 1335 int i;
1335 1336
1336 for (i = 0; i < ENET_RX_RING_CNT; i++) { 1337 for (i = 0; i < ENET_RX_RING_CNT; i++) {
1337 if (sc->sc_rxsoft[i].rxs_mbuf != NULL) { 1338 if (sc->sc_rxsoft[i].rxs_mbuf != NULL) {
1338 sc->sc_rxdesc_ring[i].rx_flags1_len = 0; 1339 sc->sc_rxdesc_ring[i].rx_flags1_len = 0;

cvs diff -r1.11 -r1.12 src/sys/arch/arm/sunxi/sun4i_emac.c (expand / switch to unified diff)

--- src/sys/arch/arm/sunxi/sun4i_emac.c 2019/05/28 07:41:46 1.11
+++ src/sys/arch/arm/sunxi/sun4i_emac.c 2020/01/29 06:05:31 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sun4i_emac.c,v 1.11 2019/05/28 07:41:46 msaitoh Exp $ */ 1/* $NetBSD: sun4i_emac.c,v 1.12 2020/01/29 06:05:31 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013-2017 The NetBSD Foundation, Inc. 4 * Copyright (c) 2013-2017 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry and Jared McNeill. 8 * by Matt Thomas of 3am Software Foundry and Jared McNeill.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33 33
34__KERNEL_RCSID(1, "$NetBSD: sun4i_emac.c,v 1.11 2019/05/28 07:41:46 msaitoh Exp $"); 34__KERNEL_RCSID(1, "$NetBSD: sun4i_emac.c,v 1.12 2020/01/29 06:05:31 thorpej Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/bus.h> 37#include <sys/bus.h>
38#include <sys/device.h> 38#include <sys/device.h>
39#include <sys/intr.h> 39#include <sys/intr.h>
40#include <sys/ioctl.h> 40#include <sys/ioctl.h>
41#include <sys/mutex.h> 41#include <sys/mutex.h>
42#include <sys/rndsource.h> 42#include <sys/rndsource.h>
43#include <sys/kernel.h> 43#include <sys/kernel.h>
44#include <sys/systm.h> 44#include <sys/systm.h>
45 45
46#include <net/bpf.h> 46#include <net/bpf.h>
47#include <net/if.h> 47#include <net/if.h>
@@ -559,33 +559,33 @@ sun4i_emac_rx_intr(struct sun4i_emac_sof @@ -559,33 +559,33 @@ sun4i_emac_rx_intr(struct sun4i_emac_sof
559 } 559 }
560 560
561 uint32_t v = sun4i_emac_read(sc, EMAC_RX_IO_DATA_REG); 561 uint32_t v = sun4i_emac_read(sc, EMAC_RX_IO_DATA_REG);
562 if (v != EMAC_RX_MAGIC) { 562 if (v != EMAC_RX_MAGIC) {
563 sun4i_emac_rxfifo_flush(sc); 563 sun4i_emac_rxfifo_flush(sc);
564 return; 564 return;
565 } 565 }
566 566
567 uint32_t rxhdr = sun4i_emac_read(sc, EMAC_RX_IO_DATA_REG); 567 uint32_t rxhdr = sun4i_emac_read(sc, EMAC_RX_IO_DATA_REG);
568 uint32_t rxlen = __SHIFTOUT(rxhdr, EMAC_RXHDR_LEN); 568 uint32_t rxlen = __SHIFTOUT(rxhdr, EMAC_RXHDR_LEN);
569 uint32_t rxsts = __SHIFTOUT(rxhdr, EMAC_RXHDR_STS); 569 uint32_t rxsts = __SHIFTOUT(rxhdr, EMAC_RXHDR_STS);
570 570
571 if (rxlen < ETHER_MIN_LEN || (rxsts & EMAC_RX_STA_PKTOK) == 0) { 571 if (rxlen < ETHER_MIN_LEN || (rxsts & EMAC_RX_STA_PKTOK) == 0) {
572 sc->sc_ec.ec_if.if_ierrors++; 572 if_statinc(&sc->sc_ec.ec_if, if_ierrors);
573 continue; 573 continue;
574 } 574 }
575 575
576 m = sun4i_emac_mgethdr(sc, rxlen); 576 m = sun4i_emac_mgethdr(sc, rxlen);
577 if (m == NULL) { 577 if (m == NULL) {
578 sc->sc_ec.ec_if.if_ierrors++; 578 if_statinc(&sc->sc_ec.ec_if, if_ierrors);
579 sun4i_emac_rxfifo_consume(sc, rxlen); 579 sun4i_emac_rxfifo_consume(sc, rxlen);
580 return; 580 return;
581 } 581 }
582 582
583 sun4i_emac_rxfifo_transfer(sc, m); 583 sun4i_emac_rxfifo_transfer(sc, m);
584 sun4i_emac_if_input(sc, m); 584 sun4i_emac_if_input(sc, m);
585 } 585 }
586} 586}
587 587
588static int 588static int
589sun4i_emac_txfifo_transfer(struct sun4i_emac_softc *sc, struct mbuf *m, u_int slot) 589sun4i_emac_txfifo_transfer(struct sun4i_emac_softc *sc, struct mbuf *m, u_int slot)
590{ 590{
591 bus_size_t const io_data_reg = EMAC_TX_IO_DATA_REG(0); 591 bus_size_t const io_data_reg = EMAC_TX_IO_DATA_REG(0);
@@ -821,27 +821,27 @@ sun4i_emac_ifinit(struct ifnet *ifp) @@ -821,27 +821,27 @@ sun4i_emac_ifinit(struct ifnet *ifp)
821 mii_mediachg(mii); 821 mii_mediachg(mii);
822 callout_schedule(&sc->sc_stat_ch, hz); 822 callout_schedule(&sc->sc_stat_ch, hz);
823 823
824 return 0; 824 return 0;
825} 825}
826 826
827static void 827static void
828sun4i_emac_ifwatchdog(struct ifnet *ifp) 828sun4i_emac_ifwatchdog(struct ifnet *ifp)
829{ 829{
830 struct sun4i_emac_softc * const sc = ifp->if_softc; 830 struct sun4i_emac_softc * const sc = ifp->if_softc;
831 831
832 device_printf(sc->sc_dev, "device timeout\n"); 832 device_printf(sc->sc_dev, "device timeout\n");
833 833
834 ifp->if_oerrors++; 834 if_statinc(ifp, if_oerrors);
835 sun4i_emac_ifinit(ifp); 835 sun4i_emac_ifinit(ifp);
836 sun4i_emac_ifstart(ifp); 836 sun4i_emac_ifstart(ifp);
837} 837}
838 838
839static void 839static void
840sun4i_emac_rx_hash(struct sun4i_emac_softc *sc) 840sun4i_emac_rx_hash(struct sun4i_emac_softc *sc)
841{ 841{
842 struct ethercom *ec = &sc->sc_ec; 842 struct ethercom *ec = &sc->sc_ec;
843 struct ifnet * const ifp = &ec->ec_if; 843 struct ifnet * const ifp = &ec->ec_if;
844 struct ether_multistep step; 844 struct ether_multistep step;
845 struct ether_multi *enm; 845 struct ether_multi *enm;
846 uint32_t hash[2]; 846 uint32_t hash[2];
847 uint32_t rxctl; 847 uint32_t rxctl;

cvs diff -r1.2 -r1.3 src/sys/arch/arm/sunxi/sunxi_can.c (expand / switch to unified diff)

--- src/sys/arch/arm/sunxi/sunxi_can.c 2019/10/21 08:00:58 1.2
+++ src/sys/arch/arm/sunxi/sunxi_can.c 2020/01/29 06:05:31 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sunxi_can.c,v 1.2 2019/10/21 08:00:58 msaitoh Exp $ */ 1/* $NetBSD: sunxi_can.c,v 1.3 2020/01/29 06:05:31 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2017,2018 The NetBSD Foundation, Inc. 4 * Copyright (c) 2017,2018 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Manuel Bouyer. 8 * by Manuel Bouyer.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -26,27 +26,27 @@ @@ -26,27 +26,27 @@
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 32
33#include "locators.h" 33#include "locators.h"
34#include "opt_can.h" 34#include "opt_can.h"
35 35
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38 38
39__KERNEL_RCSID(1, "$NetBSD: sunxi_can.c,v 1.2 2019/10/21 08:00:58 msaitoh Exp $"); 39__KERNEL_RCSID(1, "$NetBSD: sunxi_can.c,v 1.3 2020/01/29 06:05:31 thorpej Exp $");
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#include <sys/bus.h> 42#include <sys/bus.h>
43#include <sys/device.h> 43#include <sys/device.h>
44#include <sys/intr.h> 44#include <sys/intr.h>
45#include <sys/ioctl.h> 45#include <sys/ioctl.h>
46#include <sys/mutex.h> 46#include <sys/mutex.h>
47#include <sys/rndsource.h> 47#include <sys/rndsource.h>
48#include <sys/mbuf.h> 48#include <sys/mbuf.h>
49#include <sys/systm.h> 49#include <sys/systm.h>
50 50
51#include <net/if.h> 51#include <net/if.h>
52#include <net/if_types.h> 52#include <net/if_types.h>
@@ -243,34 +243,34 @@ sunxi_can_rx_intr(struct sunxi_can_softc @@ -243,34 +243,34 @@ sunxi_can_rx_intr(struct sunxi_can_softc
243{ 243{
244 uint32_t reg0v; 244 uint32_t reg0v;
245 struct mbuf *m; 245 struct mbuf *m;
246 struct ifnet *ifp = sc->sc_ifp; 246 struct ifnet *ifp = sc->sc_ifp;
247 struct can_frame *cf; 247 struct can_frame *cf;
248 int dlc; 248 int dlc;
249 int regd, i; 249 int regd, i;
250 250
251 KASSERT(mutex_owned(&sc->sc_intr_lock)); 251 KASSERT(mutex_owned(&sc->sc_intr_lock));
252 reg0v = sunxi_can_read(sc, SUNXI_CAN_TXBUF0_REG); 252 reg0v = sunxi_can_read(sc, SUNXI_CAN_TXBUF0_REG);
253 dlc = reg0v & SUNXI_CAN_TXBUF0_DL; 253 dlc = reg0v & SUNXI_CAN_TXBUF0_DL;
254 254
255 if (dlc > CAN_MAX_DLC) { 255 if (dlc > CAN_MAX_DLC) {
256 ifp->if_ierrors++; 256 if_statinc(ifp, if_ierrors);
257 sunxi_can_write(sc, SUNXI_CAN_CMD_REG, SUNXI_CAN_CMD_REL_RX_BUF); 257 sunxi_can_write(sc, SUNXI_CAN_CMD_REG, SUNXI_CAN_CMD_REL_RX_BUF);
258 return; 258 return;
259 } 259 }
260  260
261 m = m_gethdr(M_NOWAIT, MT_HEADER); 261 m = m_gethdr(M_NOWAIT, MT_HEADER);
262 if (m == NULL) { 262 if (m == NULL) {
263 ifp->if_ierrors++; 263 if_statinc(ifp, if_ierrors);
264 sunxi_can_write(sc, SUNXI_CAN_CMD_REG, SUNXI_CAN_CMD_REL_RX_BUF); 264 sunxi_can_write(sc, SUNXI_CAN_CMD_REG, SUNXI_CAN_CMD_REL_RX_BUF);
265 return; 265 return;
266 } 266 }
267 cf = mtod(m, struct can_frame *); 267 cf = mtod(m, struct can_frame *);
268 memset(cf, 0, sizeof(struct can_frame)); 268 memset(cf, 0, sizeof(struct can_frame));
269 269
270 cf->can_dlc = dlc; 270 cf->can_dlc = dlc;
271 271
272 if (reg0v & SUNXI_CAN_TXBUF0_EFF) { 272 if (reg0v & SUNXI_CAN_TXBUF0_EFF) {
273 cf->can_id =  273 cf->can_id =
274 (sunxi_can_read(sc, SUNXI_CAN_TXBUF1_REG) << 21) | 274 (sunxi_can_read(sc, SUNXI_CAN_TXBUF1_REG) << 21) |
275 (sunxi_can_read(sc, SUNXI_CAN_TXBUF2_REG) << 13) | 275 (sunxi_can_read(sc, SUNXI_CAN_TXBUF2_REG) << 13) |
276 (sunxi_can_read(sc, SUNXI_CAN_TXBUF3_REG) << 5) | 276 (sunxi_can_read(sc, SUNXI_CAN_TXBUF3_REG) << 5) |
@@ -282,42 +282,41 @@ sunxi_can_rx_intr(struct sunxi_can_softc @@ -282,42 +282,41 @@ sunxi_can_rx_intr(struct sunxi_can_softc
282 (sunxi_can_read(sc, SUNXI_CAN_TXBUF1_REG) << 3) | 282 (sunxi_can_read(sc, SUNXI_CAN_TXBUF1_REG) << 3) |
283 ((sunxi_can_read(sc, SUNXI_CAN_TXBUF2_REG) << 5) & 0x7); 283 ((sunxi_can_read(sc, SUNXI_CAN_TXBUF2_REG) << 5) & 0x7);
284 regd = SUNXI_CAN_TXBUF3_REG; 284 regd = SUNXI_CAN_TXBUF3_REG;
285 } 285 }
286 if (reg0v & SUNXI_CAN_TXBUF0_RTR) { 286 if (reg0v & SUNXI_CAN_TXBUF0_RTR) {
287 cf->can_id |= CAN_RTR_FLAG;  287 cf->can_id |= CAN_RTR_FLAG;
288 } else { 288 } else {
289 for (i = 0; i < cf->can_dlc; i++) { 289 for (i = 0; i < cf->can_dlc; i++) {
290 cf->data[i] = sunxi_can_read(sc, regd + i * 4); 290 cf->data[i] = sunxi_can_read(sc, regd + i * 4);
291 } 291 }
292 } 292 }
293 sunxi_can_write(sc, SUNXI_CAN_CMD_REG, SUNXI_CAN_CMD_REL_RX_BUF); 293 sunxi_can_write(sc, SUNXI_CAN_CMD_REG, SUNXI_CAN_CMD_REL_RX_BUF);
294 m->m_len = m->m_pkthdr.len = CAN_MTU; 294 m->m_len = m->m_pkthdr.len = CAN_MTU;
295 ifp->if_ibytes += m->m_len; 295 if_statadd(ifp, if_ibytes, m->m_len);
296 m_set_rcvif(m, ifp); 296 m_set_rcvif(m, ifp);
297 can_bpf_mtap(ifp, m, 1); 297 can_bpf_mtap(ifp, m, 1);
298 can_input(ifp, m); 298 can_input(ifp, m);
299} 299}
300 300
301static void 301static void
302sunxi_can_tx_intr(struct sunxi_can_softc *sc) 302sunxi_can_tx_intr(struct sunxi_can_softc *sc)
303{ 303{
304 struct ifnet * const ifp = sc->sc_ifp; 304 struct ifnet * const ifp = sc->sc_ifp;
305 struct mbuf *m; 305 struct mbuf *m;
306 306
307 KASSERT(mutex_owned(&sc->sc_intr_lock)); 307 KASSERT(mutex_owned(&sc->sc_intr_lock));
308 if ((m = sc->sc_m_transmit) != NULL) { 308 if ((m = sc->sc_m_transmit) != NULL) {
309 ifp->if_obytes += m->m_len; 309 if_statadd2(ifp, if_obytes, m->m_len, if_opackets, 1);
310 ifp->if_opackets++; 
311 can_mbuf_tag_clean(m); 310 can_mbuf_tag_clean(m);
312 m_set_rcvif(m, ifp); 311 m_set_rcvif(m, ifp);
313 can_input(ifp, m); /* loopback */ 312 can_input(ifp, m); /* loopback */
314 sc->sc_m_transmit = NULL; 313 sc->sc_m_transmit = NULL;
315 ifp->if_timer = 0; 314 ifp->if_timer = 0;
316 } 315 }
317 ifp->if_flags &= ~IFF_OACTIVE; 316 ifp->if_flags &= ~IFF_OACTIVE;
318 if_schedule_deferred_start(ifp); 317 if_schedule_deferred_start(ifp);
319} 318}
320 319
321static int 320static int
322sunxi_can_tx_abort(struct sunxi_can_softc *sc) 321sunxi_can_tx_abort(struct sunxi_can_softc *sc)
323{ 322{
@@ -336,50 +335,50 @@ sunxi_can_tx_abort(struct sunxi_can_soft @@ -336,50 +335,50 @@ sunxi_can_tx_abort(struct sunxi_can_soft
336 } 335 }
337 return 0; 336 return 0;
338} 337}
339 338
340static void 339static void
341sunxi_can_err_intr(struct sunxi_can_softc *sc, uint32_t irq, uint32_t sts) 340sunxi_can_err_intr(struct sunxi_can_softc *sc, uint32_t irq, uint32_t sts)
342{ 341{
343 struct ifnet * const ifp = sc->sc_ifp; 342 struct ifnet * const ifp = sc->sc_ifp;
344 KASSERT(mutex_owned(&sc->sc_intr_lock)); 343 KASSERT(mutex_owned(&sc->sc_intr_lock));
345 int txerr = 0; 344 int txerr = 0;
346 uint32_t reg; 345 uint32_t reg;
347 346
348 if (irq & SUNXI_CAN_INT_DATA_OR) { 347 if (irq & SUNXI_CAN_INT_DATA_OR) {
349 ifp->if_ierrors++; 348 if_statinc(ifp, if_ierrors);
350 sunxi_can_write(sc, SUNXI_CAN_CMD_REG, SUNXI_CAN_CMD_CLR_OR); 349 sunxi_can_write(sc, SUNXI_CAN_CMD_REG, SUNXI_CAN_CMD_CLR_OR);
351 } 350 }
352 if (irq & SUNXI_CAN_INT_ERR) { 351 if (irq & SUNXI_CAN_INT_ERR) {
353 reg = sunxi_can_read(sc, SUNXI_CAN_REC_REG); 352 reg = sunxi_can_read(sc, SUNXI_CAN_REC_REG);
354 printf("%s: ERR interrupt status 0x%x counters 0x%x\n", 353 printf("%s: ERR interrupt status 0x%x counters 0x%x\n",
355 device_xname(sc->sc_dev), sts, reg); 354 device_xname(sc->sc_dev), sts, reg);
356 355
357 } 356 }
358 if (irq & SUNXI_CAN_INT_BERR) { 357 if (irq & SUNXI_CAN_INT_BERR) {
359 if (sts & SUNXI_CAN_STA_TX) 358 if (sts & SUNXI_CAN_STA_TX)
360 txerr++; 359 txerr++;
361 if (sts & SUNXI_CAN_STA_RX) 360 if (sts & SUNXI_CAN_STA_RX)
362 ifp->if_ierrors++; 361 if_statinc(ifp, if_ierrors);
363 } 362 }
364 if (irq & SUNXI_CAN_INT_ERR_PASSIVE) { 363 if (irq & SUNXI_CAN_INT_ERR_PASSIVE) {
365 printf("%s: PASSV interrupt status 0x%x\n", 364 printf("%s: PASSV interrupt status 0x%x\n",
366 device_xname(sc->sc_dev), sts); 365 device_xname(sc->sc_dev), sts);
367 } 366 }
368 if (irq & SUNXI_CAN_INT_ARB_LOST) { 367 if (irq & SUNXI_CAN_INT_ARB_LOST) {
369 txerr++; 368 txerr++;
370 } 369 }
371 if (txerr) { 370 if (txerr) {
372 ifp->if_oerrors += txerr; 371 if_statadd(ifp, if_oerrors, txerr);
373 (void) sunxi_can_tx_abort(sc); 372 (void) sunxi_can_tx_abort(sc);
374 } 373 }
375} 374}
376 375
377int 376int
378sunxi_can_intr(void *arg) 377sunxi_can_intr(void *arg)
379{ 378{
380 struct sunxi_can_softc * const sc = arg; 379 struct sunxi_can_softc * const sc = arg;
381 int rv = 0; 380 int rv = 0;
382 int irq; 381 int irq;
383 382
384 mutex_enter(&sc->sc_intr_lock); 383 mutex_enter(&sc->sc_intr_lock);
385 384
@@ -593,27 +592,27 @@ sunxi_can_ifwatchdog(struct ifnet *ifp) @@ -593,27 +592,27 @@ sunxi_can_ifwatchdog(struct ifnet *ifp)
593 struct sunxi_can_softc * const sc = ifp->if_softc; 592 struct sunxi_can_softc * const sc = ifp->if_softc;
594 printf("%s: watchdog timeout\n", device_xname(sc->sc_dev)); 593 printf("%s: watchdog timeout\n", device_xname(sc->sc_dev));
595 594
596 mutex_enter(&sc->sc_intr_lock); 595 mutex_enter(&sc->sc_intr_lock);
597 printf("irq 0x%x en 0x%x mode 0x%x status 0x%x timings 0x%x err 0x%x\n", 596 printf("irq 0x%x en 0x%x mode 0x%x status 0x%x timings 0x%x err 0x%x\n",
598 sunxi_can_read(sc, SUNXI_CAN_INT_REG), 597 sunxi_can_read(sc, SUNXI_CAN_INT_REG),
599 sunxi_can_read(sc, SUNXI_CAN_INTE_REG), 598 sunxi_can_read(sc, SUNXI_CAN_INTE_REG),
600 sunxi_can_read(sc, SUNXI_CAN_MODSEL_REG), 599 sunxi_can_read(sc, SUNXI_CAN_MODSEL_REG),
601 sunxi_can_read(sc, SUNXI_CAN_STA_REG), 600 sunxi_can_read(sc, SUNXI_CAN_STA_REG),
602 sunxi_can_read(sc, SUNXI_CAN_BUS_TIME_REG), 601 sunxi_can_read(sc, SUNXI_CAN_BUS_TIME_REG),
603 sunxi_can_read(sc, SUNXI_CAN_REC_REG)); 602 sunxi_can_read(sc, SUNXI_CAN_REC_REG));
604 /* if there is a transmit in progress abort */ 603 /* if there is a transmit in progress abort */
605 if (sunxi_can_tx_abort(sc)) { 604 if (sunxi_can_tx_abort(sc)) {
606 ifp->if_oerrors++; 605 if_statinc(ifp, if_oerrors);
607 } 606 }
608 mutex_exit(&sc->sc_intr_lock); 607 mutex_exit(&sc->sc_intr_lock);
609} 608}
610 609
611static void 610static void
612sunxi_can_enter_reset(struct sunxi_can_softc *sc) 611sunxi_can_enter_reset(struct sunxi_can_softc *sc)
613{ 612{
614 int i; 613 int i;
615 uint32_t val; 614 uint32_t val;
616 615
617 for (i = 0; i < 1000; i++) { 616 for (i = 0; i < 1000; i++) {
618 val = sunxi_can_read(sc, SUNXI_CAN_MODSEL_REG); 617 val = sunxi_can_read(sc, SUNXI_CAN_MODSEL_REG);
619 val |= SUNXI_CAN_MODSEL_RST; 618 val |= SUNXI_CAN_MODSEL_RST;

cvs diff -r1.28 -r1.29 src/sys/arch/arm/sunxi/sunxi_emac.c (expand / switch to unified diff)

--- src/sys/arch/arm/sunxi/sunxi_emac.c 2019/07/13 21:56:23 1.28
+++ src/sys/arch/arm/sunxi/sunxi_emac.c 2020/01/29 06:05:31 1.29
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sunxi_emac.c,v 1.28 2019/07/13 21:56:23 thorpej Exp $ */ 1/* $NetBSD: sunxi_emac.c,v 1.29 2020/01/29 06:05:31 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016-2017 Jared McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2016-2017 Jared McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * Allwinner Gigabit Ethernet MAC (EMAC) controller 30 * Allwinner Gigabit Ethernet MAC (EMAC) controller
31 */ 31 */
32 32
33#include "opt_net_mpsafe.h" 33#include "opt_net_mpsafe.h"
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.28 2019/07/13 21:56:23 thorpej Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.29 2020/01/29 06:05:31 thorpej Exp $");
37 37
38#include <sys/param.h> 38#include <sys/param.h>
39#include <sys/bus.h> 39#include <sys/bus.h>
40#include <sys/device.h> 40#include <sys/device.h>
41#include <sys/intr.h> 41#include <sys/intr.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/kernel.h> 43#include <sys/kernel.h>
44#include <sys/mutex.h> 44#include <sys/mutex.h>
45#include <sys/callout.h> 45#include <sys/callout.h>
46#include <sys/gpio.h> 46#include <sys/gpio.h>
47#include <sys/cprng.h> 47#include <sys/cprng.h>
48 48
49#include <net/if.h> 49#include <net/if.h>
@@ -818,27 +818,27 @@ sunxi_emac_rxintr(struct sunxi_emac_soft @@ -818,27 +818,27 @@ sunxi_emac_rxintr(struct sunxi_emac_soft
818 } 818 }
819 819
820 ++npkt; 820 ++npkt;
821 821
822 if_percpuq_enqueue(ifp->if_percpuq, m); 822 if_percpuq_enqueue(ifp->if_percpuq, m);
823 } 823 }
824 824
825 if ((m0 = sunxi_emac_alloc_mbufcl(sc)) != NULL) { 825 if ((m0 = sunxi_emac_alloc_mbufcl(sc)) != NULL) {
826 error = sunxi_emac_setup_rxbuf(sc, index, m0); 826 error = sunxi_emac_setup_rxbuf(sc, index, m0);
827 if (error != 0) { 827 if (error != 0) {
828 /* XXX hole in RX ring */ 828 /* XXX hole in RX ring */
829 } 829 }
830 } else 830 } else
831 ifp->if_ierrors++; 831 if_statinc(ifp, if_ierrors);
832 832
833 sunxi_emac_dma_sync(sc, sc->rx.desc_tag, sc->rx.desc_map, 833 sunxi_emac_dma_sync(sc, sc->rx.desc_tag, sc->rx.desc_map,
834 index, index + 1, 834 index, index + 1,
835 RX_DESC_COUNT, BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 835 RX_DESC_COUNT, BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
836 } 836 }
837 837
838 sc->rx.cur = index; 838 sc->rx.cur = index;
839 839
840 return npkt; 840 return npkt;
841} 841}
842 842
843static void 843static void
844sunxi_emac_txintr(struct sunxi_emac_softc *sc) 844sunxi_emac_txintr(struct sunxi_emac_softc *sc)
@@ -866,27 +866,27 @@ sunxi_emac_txintr(struct sunxi_emac_soft @@ -866,27 +866,27 @@ sunxi_emac_txintr(struct sunxi_emac_soft
866 0, bmap->map->dm_mapsize, 866 0, bmap->map->dm_mapsize,
867 BUS_DMASYNC_POSTWRITE); 867 BUS_DMASYNC_POSTWRITE);
868 bus_dmamap_unload(sc->tx.buf_tag, bmap->map); 868 bus_dmamap_unload(sc->tx.buf_tag, bmap->map);
869 m_freem(bmap->mbuf); 869 m_freem(bmap->mbuf);
870 bmap->mbuf = NULL; 870 bmap->mbuf = NULL;
871 } 871 }
872 872
873 sunxi_emac_setup_txdesc(sc, i, 0, 0, 0); 873 sunxi_emac_setup_txdesc(sc, i, 0, 0, 0);
874 sunxi_emac_dma_sync(sc, sc->tx.desc_tag, sc->tx.desc_map, 874 sunxi_emac_dma_sync(sc, sc->tx.desc_tag, sc->tx.desc_map,
875 i, i + 1, TX_DESC_COUNT, 875 i, i + 1, TX_DESC_COUNT,
876 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); 876 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
877 877
878 ifp->if_flags &= ~IFF_OACTIVE; 878 ifp->if_flags &= ~IFF_OACTIVE;
879 ifp->if_opackets++; 879 if_statinc(ifp, if_opackets);
880 } 880 }
881 881
882 sc->tx.next = i; 882 sc->tx.next = i;
883} 883}
884 884
885static int 885static int
886sunxi_emac_intr(void *arg) 886sunxi_emac_intr(void *arg)
887{ 887{
888 struct sunxi_emac_softc *sc = arg; 888 struct sunxi_emac_softc *sc = arg;
889 struct ifnet *ifp = &sc->ec.ec_if; 889 struct ifnet *ifp = &sc->ec.ec_if;
890 uint32_t val; 890 uint32_t val;
891 891
892 EMAC_LOCK(sc); 892 EMAC_LOCK(sc);

cvs diff -r1.10 -r1.11 src/sys/arch/arm/ti/if_cpsw.c (expand / switch to unified diff)

--- src/sys/arch/arm/ti/if_cpsw.c 2020/01/06 06:50:00 1.10
+++ src/sys/arch/arm/ti/if_cpsw.c 2020/01/29 06:05:31 1.11
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_cpsw.c,v 1.10 2020/01/06 06:50:00 msaitoh Exp $ */ 1/* $NetBSD: if_cpsw.c,v 1.11 2020/01/29 06:05:31 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2013 Jonathan A. Kollasch 4 * Copyright (c) 2013 Jonathan A. Kollasch
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -43,27 +43,27 @@ @@ -43,27 +43,27 @@
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * SUCH DAMAGE. 52 * SUCH DAMAGE.
53 */ 53 */
54 54
55#include <sys/cdefs.h> 55#include <sys/cdefs.h>
56__KERNEL_RCSID(1, "$NetBSD: if_cpsw.c,v 1.10 2020/01/06 06:50:00 msaitoh Exp $"); 56__KERNEL_RCSID(1, "$NetBSD: if_cpsw.c,v 1.11 2020/01/29 06:05:31 thorpej Exp $");
57 57
58#include <sys/param.h> 58#include <sys/param.h>
59#include <sys/bus.h> 59#include <sys/bus.h>
60#include <sys/device.h> 60#include <sys/device.h>
61#include <sys/ioctl.h> 61#include <sys/ioctl.h>
62#include <sys/intr.h> 62#include <sys/intr.h>
63#include <sys/kmem.h> 63#include <sys/kmem.h>
64#include <sys/mutex.h> 64#include <sys/mutex.h>
65#include <sys/systm.h> 65#include <sys/systm.h>
66#include <sys/kernel.h> 66#include <sys/kernel.h>
67 67
68#include <net/if.h> 68#include <net/if.h>
69#include <net/if_ether.h> 69#include <net/if_ether.h>
@@ -619,27 +619,27 @@ cpsw_start(struct ifnet *ifp) @@ -619,27 +619,27 @@ cpsw_start(struct ifnet *ifp)
619 619
620 while (txfree > 0) { 620 while (txfree > 0) {
621 IFQ_POLL(&ifp->if_snd, m); 621 IFQ_POLL(&ifp->if_snd, m);
622 if (m == NULL) 622 if (m == NULL)
623 break; 623 break;
624 624
625 dm = rdp->tx_dm[sc->sc_txnext]; 625 dm = rdp->tx_dm[sc->sc_txnext];
626 626
627 error = bus_dmamap_load_mbuf(sc->sc_bdt, dm, m, BUS_DMA_NOWAIT); 627 error = bus_dmamap_load_mbuf(sc->sc_bdt, dm, m, BUS_DMA_NOWAIT);
628 if (error == EFBIG) { 628 if (error == EFBIG) {
629 device_printf(sc->sc_dev, "won't fit\n"); 629 device_printf(sc->sc_dev, "won't fit\n");
630 IFQ_DEQUEUE(&ifp->if_snd, m); 630 IFQ_DEQUEUE(&ifp->if_snd, m);
631 m_freem(m); 631 m_freem(m);
632 ifp->if_oerrors++; 632 if_statinc(ifp, if_oerrors);
633 continue; 633 continue;
634 } else if (error != 0) { 634 } else if (error != 0) {
635 device_printf(sc->sc_dev, "error\n"); 635 device_printf(sc->sc_dev, "error\n");
636 break; 636 break;
637 } 637 }
638 638
639 if (dm->dm_nsegs + 1 >= txfree) { 639 if (dm->dm_nsegs + 1 >= txfree) {
640 ifp->if_flags |= IFF_OACTIVE; 640 ifp->if_flags |= IFF_OACTIVE;
641 bus_dmamap_unload(sc->sc_bdt, dm); 641 bus_dmamap_unload(sc->sc_bdt, dm);
642 break; 642 break;
643 } 643 }
644 644
645 mlen = m_length(m); 645 mlen = m_length(m);
@@ -729,27 +729,27 @@ cpsw_ioctl(struct ifnet *ifp, u_long cmd @@ -729,27 +729,27 @@ cpsw_ioctl(struct ifnet *ifp, u_long cmd
729 729
730 splx(s); 730 splx(s);
731 731
732 return error; 732 return error;
733} 733}
734 734
735static void 735static void
736cpsw_watchdog(struct ifnet *ifp) 736cpsw_watchdog(struct ifnet *ifp)
737{ 737{
738 struct cpsw_softc *sc = ifp->if_softc; 738 struct cpsw_softc *sc = ifp->if_softc;
739 739
740 device_printf(sc->sc_dev, "device timeout\n"); 740 device_printf(sc->sc_dev, "device timeout\n");
741 741
742 ifp->if_oerrors++; 742 if_statinc(ifp, if_oerrors);
743 cpsw_init(ifp); 743 cpsw_init(ifp);
744 cpsw_start(ifp); 744 cpsw_start(ifp);
745} 745}
746 746
747static int 747static int
748cpsw_mii_wait(struct cpsw_softc * const sc, int reg) 748cpsw_mii_wait(struct cpsw_softc * const sc, int reg)
749{ 749{
750 u_int tries; 750 u_int tries;
751 751
752 for (tries = 0; tries < 1000; tries++) { 752 for (tries = 0; tries < 1000; tries++) {
753 if ((cpsw_read_4(sc, reg) & __BIT(31)) == 0) 753 if ((cpsw_read_4(sc, reg) & __BIT(31)) == 0)
754 return 0; 754 return 0;
755 delay(1); 755 delay(1);
@@ -1159,27 +1159,27 @@ cpsw_rxintr(void *arg) @@ -1159,27 +1159,27 @@ cpsw_rxintr(void *arg)
1159 return 1; 1159 return 1;
1160 } 1160 }
1161 1161
1162 if ((dw[3] & (CPDMA_BD_SOP | CPDMA_BD_EOP)) != 1162 if ((dw[3] & (CPDMA_BD_SOP | CPDMA_BD_EOP)) !=
1163 (CPDMA_BD_SOP | CPDMA_BD_EOP)) { 1163 (CPDMA_BD_SOP | CPDMA_BD_EOP)) {
1164 //Debugger(); 1164 //Debugger();
1165 } 1165 }
1166 1166
1167 bus_dmamap_sync(sc->sc_bdt, dm, 0, dm->dm_mapsize, 1167 bus_dmamap_sync(sc->sc_bdt, dm, 0, dm->dm_mapsize,
1168 BUS_DMASYNC_POSTREAD); 1168 BUS_DMASYNC_POSTREAD);
1169 1169
1170 if (cpsw_new_rxbuf(sc, i) != 0) { 1170 if (cpsw_new_rxbuf(sc, i) != 0) {
1171 /* drop current packet, reuse buffer for new */ 1171 /* drop current packet, reuse buffer for new */
1172 ifp->if_ierrors++; 1172 if_statinc(ifp, if_ierrors);
1173 goto next; 1173 goto next;
1174 } 1174 }
1175 1175
1176 off = __SHIFTOUT(dw[2], (uint32_t)__BITS(26, 16)); 1176 off = __SHIFTOUT(dw[2], (uint32_t)__BITS(26, 16));
1177 len = __SHIFTOUT(dw[3], (uint32_t)__BITS(10, 0)); 1177 len = __SHIFTOUT(dw[3], (uint32_t)__BITS(10, 0));
1178 1178
1179 if (ISSET(dw[3], CPDMA_BD_PASSCRC)) 1179 if (ISSET(dw[3], CPDMA_BD_PASSCRC))
1180 len -= ETHER_CRC_LEN; 1180 len -= ETHER_CRC_LEN;
1181 1181
1182 m_set_rcvif(m, ifp); 1182 m_set_rcvif(m, ifp);
1183 m->m_pkthdr.len = m->m_len = len; 1183 m->m_pkthdr.len = m->m_len = len;
1184 m->m_data += off; 1184 m->m_data += off;
1185 1185
@@ -1263,27 +1263,27 @@ cpsw_txintr(void *arg) @@ -1263,27 +1263,27 @@ cpsw_txintr(void *arg)
1263 if (ISSET(dw[3], CPDMA_BD_TDOWNCMPLT)) { 1263 if (ISSET(dw[3], CPDMA_BD_TDOWNCMPLT)) {
1264 sc->sc_txrun = false; 1264 sc->sc_txrun = false;
1265 return 1; 1265 return 1;
1266 } 1266 }
1267 1267
1268 bus_dmamap_sync(sc->sc_bdt, rdp->tx_dm[sc->sc_txhead], 1268 bus_dmamap_sync(sc->sc_bdt, rdp->tx_dm[sc->sc_txhead],
1269 0, rdp->tx_dm[sc->sc_txhead]->dm_mapsize, 1269 0, rdp->tx_dm[sc->sc_txhead]->dm_mapsize,
1270 BUS_DMASYNC_POSTWRITE); 1270 BUS_DMASYNC_POSTWRITE);
1271 bus_dmamap_unload(sc->sc_bdt, rdp->tx_dm[sc->sc_txhead]); 1271 bus_dmamap_unload(sc->sc_bdt, rdp->tx_dm[sc->sc_txhead]);
1272 1272
1273 m_freem(rdp->tx_mb[sc->sc_txhead]); 1273 m_freem(rdp->tx_mb[sc->sc_txhead]);
1274 rdp->tx_mb[sc->sc_txhead] = NULL; 1274 rdp->tx_mb[sc->sc_txhead] = NULL;
1275 1275
1276 ifp->if_opackets++; 1276 if_statinc(ifp, if_opackets);
1277 1277
1278 handled = true; 1278 handled = true;
1279 1279
1280 ifp->if_flags &= ~IFF_OACTIVE; 1280 ifp->if_flags &= ~IFF_OACTIVE;
1281 1281
1282next: 1282next:
1283 if (ISSET(dw[3], CPDMA_BD_EOP) && ISSET(dw[3], CPDMA_BD_EOQ)) { 1283 if (ISSET(dw[3], CPDMA_BD_EOP) && ISSET(dw[3], CPDMA_BD_EOQ)) {
1284 sc->sc_txeoq = true; 1284 sc->sc_txeoq = true;
1285 } 1285 }
1286 if (sc->sc_txhead == cpi) { 1286 if (sc->sc_txhead == cpi) {
1287 cpsw_write_4(sc, CPSW_CPDMA_TX_CP(0), 1287 cpsw_write_4(sc, CPSW_CPDMA_TX_CP(0),
1288 cpsw_txdesc_paddr(sc, cpi)); 1288 cpsw_txdesc_paddr(sc, cpi));
1289 sc->sc_txhead = TXDESC_NEXT(sc->sc_txhead); 1289 sc->sc_txhead = TXDESC_NEXT(sc->sc_txhead);

cvs diff -r1.44 -r1.45 src/sys/arch/arm/xscale/ixp425_if_npe.c (expand / switch to unified diff)

--- src/sys/arch/arm/xscale/ixp425_if_npe.c 2019/12/27 08:22:49 1.44
+++ src/sys/arch/arm/xscale/ixp425_if_npe.c 2020/01/29 06:05:31 1.45
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ixp425_if_npe.c,v 1.44 2019/12/27 08:22:49 msaitoh Exp $ */ 1/* $NetBSD: ixp425_if_npe.c,v 1.45 2020/01/29 06:05:31 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2006 Sam Leffler. All rights reserved. 4 * Copyright (c) 2006 Sam Leffler. 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 *
@@ -18,27 +18,27 @@ @@ -18,27 +18,27 @@
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#if 0 28#if 0
29__FBSDID("$FreeBSD: src/sys/arm/xscale/ixp425/if_npe.c,v 1.1 2006/11/19 23:55:23 sam Exp $"); 29__FBSDID("$FreeBSD: src/sys/arm/xscale/ixp425/if_npe.c,v 1.1 2006/11/19 23:55:23 sam Exp $");
30#endif 30#endif
31__KERNEL_RCSID(0, "$NetBSD: ixp425_if_npe.c,v 1.44 2019/12/27 08:22:49 msaitoh Exp $"); 31__KERNEL_RCSID(0, "$NetBSD: ixp425_if_npe.c,v 1.45 2020/01/29 06:05:31 thorpej Exp $");
32 32
33/* 33/*
34 * Intel XScale NPE Ethernet driver. 34 * Intel XScale NPE Ethernet driver.
35 * 35 *
36 * This driver handles the two ports present on the IXP425. 36 * This driver handles the two ports present on the IXP425.
37 * Packet processing is done by the Network Processing Engines 37 * Packet processing is done by the Network Processing Engines
38 * (NPE's) that work together with a MAC and PHY. The MAC 38 * (NPE's) that work together with a MAC and PHY. The MAC
39 * is also mapped to the XScale cpu; the PHY is accessed via 39 * is also mapped to the XScale cpu; the PHY is accessed via
40 * the MAC. NPE-XScale communication happens through h/w 40 * the MAC. NPE-XScale communication happens through h/w
41 * queues managed by the Q Manager block. 41 * queues managed by the Q Manager block.
42 * 42 *
43 * The code here replaces the ethAcc, ethMii, and ethDB classes 43 * The code here replaces the ethAcc, ethMii, and ethDB classes
44 * in the Intel Access Library (IAL) and the OS-specific driver. 44 * in the Intel Access Library (IAL) and the OS-specific driver.
@@ -693,40 +693,43 @@ npe_ifmedia_status(struct ifnet *ifp, st @@ -693,40 +693,43 @@ npe_ifmedia_status(struct ifnet *ifp, st
693 693
694 mii_pollstat(&sc->sc_mii); 694 mii_pollstat(&sc->sc_mii);
695 695
696 ifmr->ifm_active = sc->sc_mii.mii_media_active; 696 ifmr->ifm_active = sc->sc_mii.mii_media_active;
697 ifmr->ifm_status = sc->sc_mii.mii_media_status; 697 ifmr->ifm_status = sc->sc_mii.mii_media_status;
698} 698}
699 699
700static void 700static void
701npe_addstats(struct npe_softc *sc) 701npe_addstats(struct npe_softc *sc)
702{ 702{
703 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 703 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
704 struct npestats *ns = sc->sc_stats; 704 struct npestats *ns = sc->sc_stats;
705 705
706 ifp->if_oerrors += 706 net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
 707 if_statadd_ref(nsr, if_oerrors,
707 be32toh(ns->dot3StatsInternalMacTransmitErrors) 708 be32toh(ns->dot3StatsInternalMacTransmitErrors)
708 + be32toh(ns->dot3StatsCarrierSenseErrors) 709 + be32toh(ns->dot3StatsCarrierSenseErrors)
709 + be32toh(ns->TxVLANIdFilterDiscards) 710 + be32toh(ns->TxVLANIdFilterDiscards)
710 ; 711 );
711 ifp->if_ierrors += be32toh(ns->dot3StatsFCSErrors) 712 if_statadd_ref(nsr, if_ierrors,
 713 be32toh(ns->dot3StatsFCSErrors)
712 + be32toh(ns->dot3StatsInternalMacReceiveErrors) 714 + be32toh(ns->dot3StatsInternalMacReceiveErrors)
713 + be32toh(ns->RxOverrunDiscards) 715 + be32toh(ns->RxOverrunDiscards)
714 + be32toh(ns->RxUnderflowEntryDiscards) 716 + be32toh(ns->RxUnderflowEntryDiscards)
715 ; 717 );
716 ifp->if_collisions += 718 if_statadd_ref(nsr, if_collisions,
717 be32toh(ns->dot3StatsSingleCollisionFrames) 719 be32toh(ns->dot3StatsSingleCollisionFrames)
718 + be32toh(ns->dot3StatsMultipleCollisionFrames) 720 + be32toh(ns->dot3StatsMultipleCollisionFrames)
719 ; 721 );
 722 IF_STAT_PUTREF(ifp);
720} 723}
721 724
722static void 725static void
723npe_tick(void *xsc) 726npe_tick(void *xsc)
724{ 727{
725#define ACK (NPE_RESETSTATS << NPE_MAC_MSGID_SHL) 728#define ACK (NPE_RESETSTATS << NPE_MAC_MSGID_SHL)
726 struct npe_softc *sc = xsc; 729 struct npe_softc *sc = xsc;
727 uint32_t msg[2]; 730 uint32_t msg[2];
728 731
729 /* 732 /*
730 * NB: to avoid sleeping with the softc lock held we 733 * NB: to avoid sleeping with the softc lock held we
731 * split the NPE msg processing into two parts. The 734 * split the NPE msg processing into two parts. The
732 * request for statistics is sent w/o waiting for a 735 * request for statistics is sent w/o waiting for a
@@ -788,27 +791,27 @@ struct txdone { @@ -788,27 +791,27 @@ struct txdone {
788}; 791};
789 792
790static __inline void 793static __inline void
791npe_txdone_finish(struct npe_softc *sc, const struct txdone *td) 794npe_txdone_finish(struct npe_softc *sc, const struct txdone *td)
792{ 795{
793 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 796 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
794 797
795 *td->tail = sc->tx_free; 798 *td->tail = sc->tx_free;
796 sc->tx_free = td->head; 799 sc->tx_free = td->head;
797 /* 800 /*
798 * We're no longer busy, so clear the busy flag and call the 801 * We're no longer busy, so clear the busy flag and call the
799 * start routine to xmit more packets. 802 * start routine to xmit more packets.
800 */ 803 */
801 ifp->if_opackets += td->count; 804 if_statadd(ifp, if_opackets, td->count);
802 ifp->if_flags &= ~IFF_OACTIVE; 805 ifp->if_flags &= ~IFF_OACTIVE;
803 ifp->if_timer = 0; 806 ifp->if_timer = 0;
804 if_schedule_deferred_start(ifp); 807 if_schedule_deferred_start(ifp);
805} 808}
806 809
807/* 810/*
808 * Q manager callback on tx done queue. Reap mbufs 811 * Q manager callback on tx done queue. Reap mbufs
809 * and return tx buffers to the free list. Finally 812 * and return tx buffers to the free list. Finally
810 * restart output. Note the microcode has only one 813 * restart output. Note the microcode has only one
811 * txdone q wired into it so we must use the NPE ID 814 * txdone q wired into it so we must use the NPE ID
812 * returned with each npehwbuf to decide where to 815 * returned with each npehwbuf to decide where to
813 * send buffers. 816 * send buffers.
814 */ 817 */
@@ -943,27 +946,27 @@ npe_rxdone(int qid, void *arg) @@ -943,27 +946,27 @@ npe_rxdone(int qid, void *arg)
943 /* set m_len etc. per rx frame size */ 946 /* set m_len etc. per rx frame size */
944 mrx->m_len = be32toh(hw->ix_ne[0].len) & 0xffff; 947 mrx->m_len = be32toh(hw->ix_ne[0].len) & 0xffff;
945 mrx->m_pkthdr.len = mrx->m_len; 948 mrx->m_pkthdr.len = mrx->m_len;
946 m_set_rcvif(mrx, ifp); 949 m_set_rcvif(mrx, ifp);
947 /* Don't add M_HASFCS. See below */ 950 /* Don't add M_HASFCS. See below */
948 951
949#if 1 952#if 1
950 if (mrx->m_pkthdr.len < sizeof(struct ether_header)) { 953 if (mrx->m_pkthdr.len < sizeof(struct ether_header)) {
951 log(LOG_INFO, "%s: too short frame (len=%d)\n", 954 log(LOG_INFO, "%s: too short frame (len=%d)\n",
952 device_xname(sc->sc_dev), 955 device_xname(sc->sc_dev),
953 mrx->m_pkthdr.len); 956 mrx->m_pkthdr.len);
954 /* Back out "newly allocated" mbuf. */ 957 /* Back out "newly allocated" mbuf. */
955 m_freem(m); 958 m_freem(m);
956 ifp->if_ierrors++; 959 if_statinc(ifp, if_ierrors);
957 goto fail; 960 goto fail;
958 } 961 }
959 if ((ifp->if_flags & IFF_PROMISC) == 0) { 962 if ((ifp->if_flags & IFF_PROMISC) == 0) {
960 struct ether_header *eh; 963 struct ether_header *eh;
961 964
962 /* 965 /*
963 * Workaround for "Non-Intel XScale Technology 966 * Workaround for "Non-Intel XScale Technology
964 * Eratta" No. 29. AA:BB:CC:DD:EE:xF's packet 967 * Eratta" No. 29. AA:BB:CC:DD:EE:xF's packet
965 * matches the filter (both unicast and 968 * matches the filter (both unicast and
966 * multicast). 969 * multicast).
967 */ 970 */
968 eh = mtod(mrx, struct ether_header *); 971 eh = mtod(mrx, struct ether_header *);
969 if (ETHER_IS_MULTICAST(eh->ether_dhost) == 0) { 972 if (ETHER_IS_MULTICAST(eh->ether_dhost) == 0) {
@@ -1022,27 +1025,27 @@ npe_rxdone(int qid, void *arg) @@ -1022,27 +1025,27 @@ npe_rxdone(int qid, void *arg)
1022 * Back out "newly allocated" 1025 * Back out "newly allocated"
1023 * mbuf. 1026 * mbuf.
1024 */ 1027 */
1025 m_freem(m); 1028 m_freem(m);
1026 goto fail; 1029 goto fail;
1027 } 1030 }
1028 } 1031 }
1029 } 1032 }
1030 if (mrx->m_pkthdr.len > NPE_FRAME_SIZE_DEFAULT) { 1033 if (mrx->m_pkthdr.len > NPE_FRAME_SIZE_DEFAULT) {
1031 log(LOG_INFO, "%s: oversized frame (len=%d)\n", 1034 log(LOG_INFO, "%s: oversized frame (len=%d)\n",
1032 device_xname(sc->sc_dev), mrx->m_pkthdr.len); 1035 device_xname(sc->sc_dev), mrx->m_pkthdr.len);
1033 /* Back out "newly allocated" mbuf. */ 1036 /* Back out "newly allocated" mbuf. */
1034 m_freem(m); 1037 m_freem(m);
1035 ifp->if_ierrors++; 1038 if_statinc(ifp, if_ierrors);
1036 goto fail; 1039 goto fail;
1037 } 1040 }
1038#endif 1041#endif
1039 1042
1040 /* 1043 /*
1041 * Trim FCS! 1044 * Trim FCS!
1042 * NPE always adds the FCS by this driver's setting, 1045 * NPE always adds the FCS by this driver's setting,
1043 * so we always trim it here and not add M_HASFCS. 1046 * so we always trim it here and not add M_HASFCS.
1044 */ 1047 */
1045 m_adj(mrx, -ETHER_CRC_LEN); 1048 m_adj(mrx, -ETHER_CRC_LEN);
1046 1049
1047 /* 1050 /*
1048 * Tap off here if there is a bpf listener. 1051 * Tap off here if there is a bpf listener.
@@ -1144,27 +1147,27 @@ npeinit_macreg(struct npe_softc *sc) @@ -1144,27 +1147,27 @@ npeinit_macreg(struct npe_softc *sc)
1144 WR4(sc, NPE_MAC_RX_CNTRL1, 1147 WR4(sc, NPE_MAC_RX_CNTRL1,
1145 NPE_RX_CNTRL1_CRC_EN /* include CRC/FCS */ 1148 NPE_RX_CNTRL1_CRC_EN /* include CRC/FCS */
1146 | NPE_RX_CNTRL1_PAUSE_EN); /* ena pause frame handling */ 1149 | NPE_RX_CNTRL1_PAUSE_EN); /* ena pause frame handling */
1147 WR4(sc, NPE_MAC_RX_CNTRL2, 0); 1150 WR4(sc, NPE_MAC_RX_CNTRL2, 0);
1148} 1151}
1149 1152
1150static void 1153static void
1151npeinit_resetcb(void *xsc) 1154npeinit_resetcb(void *xsc)
1152{ 1155{
1153 struct npe_softc *sc = xsc; 1156 struct npe_softc *sc = xsc;
1154 struct ifnet *ifp = &sc->sc_ethercom.ec_if; 1157 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
1155 uint32_t msg[2]; 1158 uint32_t msg[2];
1156 1159
1157 ifp->if_oerrors++; 1160 if_statinc(ifp, if_oerrors);
1158 npeinit_locked(sc); 1161 npeinit_locked(sc);
1159 1162
1160 msg[0] = NPE_NOTIFYMACRECOVERYDONE << NPE_MAC_MSGID_SHL 1163 msg[0] = NPE_NOTIFYMACRECOVERYDONE << NPE_MAC_MSGID_SHL
1161 | (npeconfig[sc->sc_unit].macport << NPE_MAC_PORTID_SHL); 1164 | (npeconfig[sc->sc_unit].macport << NPE_MAC_PORTID_SHL);
1162 msg[1] = 0; 1165 msg[1] = 0;
1163 ixpnpe_sendandrecvmsg(sc->sc_npe, msg, msg); 1166 ixpnpe_sendandrecvmsg(sc->sc_npe, msg, msg);
1164} 1167}
1165 1168
1166/* 1169/*
1167 * Reset and initialize the chip 1170 * Reset and initialize the chip
1168 */ 1171 */
1169static void 1172static void
1170npeinit_locked(void *xsc) 1173npeinit_locked(void *xsc)
@@ -1392,27 +1395,27 @@ npestop(struct ifnet *ifp, int disable) @@ -1392,27 +1395,27 @@ npestop(struct ifnet *ifp, int disable)
1392 1395
1393 ifp->if_timer = 0; 1396 ifp->if_timer = 0;
1394 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); 1397 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1395} 1398}
1396 1399
1397void 1400void
1398npewatchdog(struct ifnet *ifp) 1401npewatchdog(struct ifnet *ifp)
1399{ 1402{
1400 struct npe_softc *sc = ifp->if_softc; 1403 struct npe_softc *sc = ifp->if_softc;
1401 int s; 1404 int s;
1402 1405
1403 aprint_error_dev(sc->sc_dev, "device timeout\n"); 1406 aprint_error_dev(sc->sc_dev, "device timeout\n");
1404 s = splnet(); 1407 s = splnet();
1405 ifp->if_oerrors++; 1408 if_statinc(ifp, if_oerrors);
1406 npeinit_locked(sc); 1409 npeinit_locked(sc);
1407 splx(s); 1410 splx(s);
1408} 1411}
1409 1412
1410static int 1413static int
1411npeioctl(struct ifnet *ifp, u_long cmd, void *data) 1414npeioctl(struct ifnet *ifp, u_long cmd, void *data)
1412{ 1415{
1413 struct npe_softc *sc = ifp->if_softc; 1416 struct npe_softc *sc = ifp->if_softc;
1414 struct ifreq *ifr = (struct ifreq *) data; 1417 struct ifreq *ifr = (struct ifreq *) data;
1415 int s, error = 0; 1418 int s, error = 0;
1416 1419
1417 s = splnet(); 1420 s = splnet();
1418 1421