Thu Jan 30 13:59:25 2020 UTC ()
Adopt <net/if_stats.h>.


(thorpej)
diff -r1.65 -r1.66 src/sys/dev/pci/if_age.c
diff -r1.46 -r1.47 src/sys/dev/pci/if_alc.c
diff -r1.37 -r1.38 src/sys/dev/pci/if_ale.c

cvs diff -r1.65 -r1.66 src/sys/dev/pci/if_age.c (expand / switch to unified diff)

--- src/sys/dev/pci/if_age.c 2019/12/01 08:16:49 1.65
+++ src/sys/dev/pci/if_age.c 2020/01/30 13:59:24 1.66
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_age.c,v 1.65 2019/12/01 08:16:49 msaitoh Exp $ */ 1/* $NetBSD: if_age.c,v 1.66 2020/01/30 13:59:24 thorpej Exp $ */
2/* $OpenBSD: if_age.c,v 1.1 2009/01/16 05:00:34 kevlo Exp $ */ 2/* $OpenBSD: if_age.c,v 1.1 2009/01/16 05:00:34 kevlo Exp $ */
3 3
4/*- 4/*-
5 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org> 5 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org>
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following 12 * notice unmodified, this list of conditions, and the following
13 * disclaimer. 13 * disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE. 28 * SUCH DAMAGE.
29 */ 29 */
30 30
31/* Driver for Attansic Technology Corp. L1 Gigabit Ethernet. */ 31/* Driver for Attansic Technology Corp. L1 Gigabit Ethernet. */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: if_age.c,v 1.65 2019/12/01 08:16:49 msaitoh Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: if_age.c,v 1.66 2020/01/30 13:59:24 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/proc.h> 39#include <sys/proc.h>
40#include <sys/endian.h> 40#include <sys/endian.h>
41#include <sys/systm.h> 41#include <sys/systm.h>
42#include <sys/types.h> 42#include <sys/types.h>
43#include <sys/sockio.h> 43#include <sys/sockio.h>
44#include <sys/mbuf.h> 44#include <sys/mbuf.h>
45#include <sys/queue.h> 45#include <sys/queue.h>
46#include <sys/kernel.h> 46#include <sys/kernel.h>
47#include <sys/device.h> 47#include <sys/device.h>
@@ -1069,40 +1069,40 @@ age_start(struct ifnet *ifp) @@ -1069,40 +1069,40 @@ age_start(struct ifnet *ifp)
1069 /* Set a timeout in case the chip goes out to lunch. */ 1069 /* Set a timeout in case the chip goes out to lunch. */
1070 ifp->if_timer = AGE_TX_TIMEOUT; 1070 ifp->if_timer = AGE_TX_TIMEOUT;
1071 } 1071 }
1072} 1072}
1073 1073
1074static void 1074static void
1075age_watchdog(struct ifnet *ifp) 1075age_watchdog(struct ifnet *ifp)
1076{ 1076{
1077 struct age_softc *sc = ifp->if_softc; 1077 struct age_softc *sc = ifp->if_softc;
1078 1078
1079 if ((sc->age_flags & AGE_FLAG_LINK) == 0) { 1079 if ((sc->age_flags & AGE_FLAG_LINK) == 0) {
1080 printf("%s: watchdog timeout (missed link)\n", 1080 printf("%s: watchdog timeout (missed link)\n",
1081 device_xname(sc->sc_dev)); 1081 device_xname(sc->sc_dev));
1082 ifp->if_oerrors++; 1082 if_statinc(ifp, if_oerrors);
1083 age_init(ifp); 1083 age_init(ifp);
1084 return; 1084 return;
1085 } 1085 }
1086 1086
1087 if (sc->age_cdata.age_tx_cnt == 0) { 1087 if (sc->age_cdata.age_tx_cnt == 0) {
1088 printf("%s: watchdog timeout (missed Tx interrupts) " 1088 printf("%s: watchdog timeout (missed Tx interrupts) "
1089 "-- recovering\n", device_xname(sc->sc_dev)); 1089 "-- recovering\n", device_xname(sc->sc_dev));
1090 age_start(ifp); 1090 age_start(ifp);
1091 return; 1091 return;
1092 } 1092 }
1093 1093
1094 printf("%s: watchdog timeout\n", device_xname(sc->sc_dev)); 1094 printf("%s: watchdog timeout\n", device_xname(sc->sc_dev));
1095 ifp->if_oerrors++; 1095 if_statinc(ifp, if_oerrors);
1096 age_init(ifp); 1096 age_init(ifp);
1097 age_start(ifp); 1097 age_start(ifp);
1098} 1098}
1099 1099
1100static bool 1100static bool
1101age_shutdown(device_t self, int howto) 1101age_shutdown(device_t self, int howto)
1102{ 1102{
1103 struct age_softc *sc; 1103 struct age_softc *sc;
1104 struct ifnet *ifp; 1104 struct ifnet *ifp;
1105 1105
1106 sc = device_private(self); 1106 sc = device_private(self);
1107 ifp = &sc->sc_ec.ec_if; 1107 ifp = &sc->sc_ec.ec_if;
1108 age_stop(ifp, 1); 1108 age_stop(ifp, 1);
@@ -1401,27 +1401,27 @@ age_rxeof(struct age_softc *sc, struct r @@ -1401,27 +1401,27 @@ age_rxeof(struct age_softc *sc, struct r
1401 sc->age_cdata.age_rx_cons += nsegs; 1401 sc->age_cdata.age_rx_cons += nsegs;
1402 sc->age_cdata.age_rx_cons %= AGE_RX_RING_CNT; 1402 sc->age_cdata.age_rx_cons %= AGE_RX_RING_CNT;
1403 return; 1403 return;
1404 } 1404 }
1405 1405
1406 pktlen = 0; 1406 pktlen = 0;
1407 for (count = 0; count < nsegs; count++, 1407 for (count = 0; count < nsegs; count++,
1408 AGE_DESC_INC(rx_cons, AGE_RX_RING_CNT)) { 1408 AGE_DESC_INC(rx_cons, AGE_RX_RING_CNT)) {
1409 rxd = &sc->age_cdata.age_rxdesc[rx_cons]; 1409 rxd = &sc->age_cdata.age_rxdesc[rx_cons];
1410 mp = rxd->rx_m; 1410 mp = rxd->rx_m;
1411 desc = rxd->rx_desc; 1411 desc = rxd->rx_desc;
1412 /* Add a new receive buffer to the ring. */ 1412 /* Add a new receive buffer to the ring. */
1413 if (age_newbuf(sc, rxd, 0) != 0) { 1413 if (age_newbuf(sc, rxd, 0) != 0) {
1414 ifp->if_iqdrops++; 1414 if_statinc(ifp, if_iqdrops);
1415 /* Reuse Rx buffers. */ 1415 /* Reuse Rx buffers. */
1416 if (sc->age_cdata.age_rxhead != NULL) { 1416 if (sc->age_cdata.age_rxhead != NULL) {
1417 m_freem(sc->age_cdata.age_rxhead); 1417 m_freem(sc->age_cdata.age_rxhead);
1418 AGE_RXCHAIN_RESET(sc); 1418 AGE_RXCHAIN_RESET(sc);
1419 } 1419 }
1420 break; 1420 break;
1421 } 1421 }
1422 1422
1423 /* The length of the first mbuf is computed last. */ 1423 /* The length of the first mbuf is computed last. */
1424 if (count != 0) { 1424 if (count != 0) {
1425 mp->m_len = AGE_RX_BYTES(le32toh(desc->len)); 1425 mp->m_len = AGE_RX_BYTES(le32toh(desc->len));
1426 pktlen += mp->m_len; 1426 pktlen += mp->m_len;
1427 } 1427 }
@@ -2023,40 +2023,47 @@ age_stats_update(struct age_softc *sc) @@ -2023,40 +2023,47 @@ age_stats_update(struct age_softc *sc)
2023 stat->tx_pkts_1519_max += smb->tx_pkts_1519_max; 2023 stat->tx_pkts_1519_max += smb->tx_pkts_1519_max;
2024 stat->tx_single_colls += smb->tx_single_colls; 2024 stat->tx_single_colls += smb->tx_single_colls;
2025 stat->tx_multi_colls += smb->tx_multi_colls; 2025 stat->tx_multi_colls += smb->tx_multi_colls;
2026 stat->tx_late_colls += smb->tx_late_colls; 2026 stat->tx_late_colls += smb->tx_late_colls;
2027 stat->tx_excess_colls += smb->tx_excess_colls; 2027 stat->tx_excess_colls += smb->tx_excess_colls;
2028 stat->tx_underrun += smb->tx_underrun; 2028 stat->tx_underrun += smb->tx_underrun;
2029 stat->tx_desc_underrun += smb->tx_desc_underrun; 2029 stat->tx_desc_underrun += smb->tx_desc_underrun;
2030 stat->tx_lenerrs += smb->tx_lenerrs; 2030 stat->tx_lenerrs += smb->tx_lenerrs;
2031 stat->tx_pkts_truncated += smb->tx_pkts_truncated; 2031 stat->tx_pkts_truncated += smb->tx_pkts_truncated;
2032 stat->tx_bcast_bytes += smb->tx_bcast_bytes; 2032 stat->tx_bcast_bytes += smb->tx_bcast_bytes;
2033 stat->tx_mcast_bytes += smb->tx_mcast_bytes; 2033 stat->tx_mcast_bytes += smb->tx_mcast_bytes;
2034 2034
2035 /* Update counters in ifnet. */ 2035 /* Update counters in ifnet. */
2036 ifp->if_opackets += smb->tx_frames; 2036 net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
2037 2037
2038 ifp->if_collisions += smb->tx_single_colls + 2038 if_statadd_ref(nsr, if_opackets, smb->tx_frames);
 2039
 2040 if_statadd_ref(nsr, if_collisions,
 2041 smb->tx_single_colls +
2039 smb->tx_multi_colls + smb->tx_late_colls + 2042 smb->tx_multi_colls + smb->tx_late_colls +
2040 smb->tx_excess_colls * HDPX_CFG_RETRY_DEFAULT; 2043 smb->tx_excess_colls * HDPX_CFG_RETRY_DEFAULT);
2041 2044
2042 ifp->if_oerrors += smb->tx_excess_colls + 2045 if_statadd_ref(nsr, if_oerrors,
 2046 smb->tx_excess_colls +
2043 smb->tx_late_colls + smb->tx_underrun + 2047 smb->tx_late_colls + smb->tx_underrun +
2044 smb->tx_pkts_truncated; 2048 smb->tx_pkts_truncated);
2045 2049
2046 ifp->if_ierrors += smb->rx_crcerrs + smb->rx_lenerrs + 2050 if_statadd_ref(nsr, if_ierrors,
 2051 smb->rx_crcerrs + smb->rx_lenerrs +
2047 smb->rx_runts + smb->rx_pkts_truncated + 2052 smb->rx_runts + smb->rx_pkts_truncated +
2048 smb->rx_fifo_oflows + smb->rx_desc_oflows + 2053 smb->rx_fifo_oflows + smb->rx_desc_oflows +
2049 smb->rx_alignerrs; 2054 smb->rx_alignerrs);
 2055
 2056 IF_STAT_PUTREF(ifp);
2050 2057
2051 /* Update done, clear. */ 2058 /* Update done, clear. */
2052 smb->updated = 0; 2059 smb->updated = 0;
2053 2060
2054 bus_dmamap_sync(sc->sc_dmat, sc->age_cdata.age_smb_block_map, 0, 2061 bus_dmamap_sync(sc->sc_dmat, sc->age_cdata.age_smb_block_map, 0,
2055 sc->age_cdata.age_smb_block_map->dm_mapsize, 2062 sc->age_cdata.age_smb_block_map->dm_mapsize,
2056 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); 2063 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
2057} 2064}
2058 2065
2059static void 2066static void
2060age_stop_txmac(struct age_softc *sc) 2067age_stop_txmac(struct age_softc *sc)
2061{ 2068{
2062 uint32_t reg; 2069 uint32_t reg;

cvs diff -r1.46 -r1.47 src/sys/dev/pci/if_alc.c (expand / switch to unified diff)

--- src/sys/dev/pci/if_alc.c 2019/12/18 13:25:00 1.46
+++ src/sys/dev/pci/if_alc.c 2020/01/30 13:59:24 1.47
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_alc.c,v 1.46 2019/12/18 13:25:00 msaitoh Exp $ */ 1/* $NetBSD: if_alc.c,v 1.47 2020/01/30 13:59:24 thorpej Exp $ */
2/* $OpenBSD: if_alc.c,v 1.1 2009/08/08 09:31:13 kevlo Exp $ */ 2/* $OpenBSD: if_alc.c,v 1.1 2009/08/08 09:31:13 kevlo Exp $ */
3/*- 3/*-
4 * Copyright (c) 2009, Pyun YongHyeon <yongari@FreeBSD.org> 4 * Copyright (c) 2009, Pyun YongHyeon <yongari@FreeBSD.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 unmodified, this list of conditions, and the following 11 * notice unmodified, this list of conditions, and the following
12 * disclaimer. 12 * disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -2049,33 +2049,33 @@ alc_start(struct ifnet *ifp) @@ -2049,33 +2049,33 @@ alc_start(struct ifnet *ifp)
2049 /* Set a timeout in case the chip goes out to lunch. */ 2049 /* Set a timeout in case the chip goes out to lunch. */
2050 ifp->if_timer = ALC_TX_TIMEOUT; 2050 ifp->if_timer = ALC_TX_TIMEOUT;
2051 } 2051 }
2052} 2052}
2053 2053
2054static void 2054static void
2055alc_watchdog(struct ifnet *ifp) 2055alc_watchdog(struct ifnet *ifp)
2056{ 2056{
2057 struct alc_softc *sc = ifp->if_softc; 2057 struct alc_softc *sc = ifp->if_softc;
2058 2058
2059 if ((sc->alc_flags & ALC_FLAG_LINK) == 0) { 2059 if ((sc->alc_flags & ALC_FLAG_LINK) == 0) {
2060 printf("%s: watchdog timeout (missed link)\n", 2060 printf("%s: watchdog timeout (missed link)\n",
2061 device_xname(sc->sc_dev)); 2061 device_xname(sc->sc_dev));
2062 ifp->if_oerrors++; 2062 if_statinc(ifp, if_oerrors);
2063 alc_init_backend(ifp, false); 2063 alc_init_backend(ifp, false);
2064 return; 2064 return;
2065 } 2065 }
2066 2066
2067 printf("%s: watchdog timeout\n", device_xname(sc->sc_dev)); 2067 printf("%s: watchdog timeout\n", device_xname(sc->sc_dev));
2068 ifp->if_oerrors++; 2068 if_statinc(ifp, if_oerrors);
2069 alc_init_backend(ifp, false); 2069 alc_init_backend(ifp, false);
2070 alc_start(ifp); 2070 alc_start(ifp);
2071} 2071}
2072 2072
2073static int 2073static int
2074alc_ioctl(struct ifnet *ifp, u_long cmd, void *data) 2074alc_ioctl(struct ifnet *ifp, u_long cmd, void *data)
2075{ 2075{
2076 struct alc_softc *sc = ifp->if_softc; 2076 struct alc_softc *sc = ifp->if_softc;
2077 int s, error = 0; 2077 int s, error = 0;
2078 2078
2079 s = splnet(); 2079 s = splnet();
2080 2080
2081 switch (cmd) { 2081 switch (cmd) {
@@ -2257,39 +2257,46 @@ alc_stats_update(struct alc_softc *sc) @@ -2257,39 +2257,46 @@ alc_stats_update(struct alc_softc *sc)
2257 stat->tx_pkts_1519_max += smb->tx_pkts_1519_max; 2257 stat->tx_pkts_1519_max += smb->tx_pkts_1519_max;
2258 stat->tx_single_colls += smb->tx_single_colls; 2258 stat->tx_single_colls += smb->tx_single_colls;
2259 stat->tx_multi_colls += smb->tx_multi_colls; 2259 stat->tx_multi_colls += smb->tx_multi_colls;
2260 stat->tx_late_colls += smb->tx_late_colls; 2260 stat->tx_late_colls += smb->tx_late_colls;
2261 stat->tx_excess_colls += smb->tx_excess_colls; 2261 stat->tx_excess_colls += smb->tx_excess_colls;
2262 stat->tx_underrun += smb->tx_underrun; 2262 stat->tx_underrun += smb->tx_underrun;
2263 stat->tx_desc_underrun += smb->tx_desc_underrun; 2263 stat->tx_desc_underrun += smb->tx_desc_underrun;
2264 stat->tx_lenerrs += smb->tx_lenerrs; 2264 stat->tx_lenerrs += smb->tx_lenerrs;
2265 stat->tx_pkts_truncated += smb->tx_pkts_truncated; 2265 stat->tx_pkts_truncated += smb->tx_pkts_truncated;
2266 stat->tx_bcast_bytes += smb->tx_bcast_bytes; 2266 stat->tx_bcast_bytes += smb->tx_bcast_bytes;
2267 stat->tx_mcast_bytes += smb->tx_mcast_bytes; 2267 stat->tx_mcast_bytes += smb->tx_mcast_bytes;
2268 2268
2269 /* Update counters in ifnet. */ 2269 /* Update counters in ifnet. */
2270 ifp->if_opackets += smb->tx_frames; 2270 net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
2271 2271
2272 ifp->if_collisions += smb->tx_single_colls + 2272 if_statadd_ref(nsr, if_opackets, smb->tx_frames);
 2273
 2274 if_statadd_ref(nsr, if_collisions,
 2275 smb->tx_single_colls +
2273 smb->tx_multi_colls * 2 + smb->tx_late_colls + 2276 smb->tx_multi_colls * 2 + smb->tx_late_colls +
2274 smb->tx_excess_colls * HDPX_CFG_RETRY_DEFAULT; 2277 smb->tx_excess_colls * HDPX_CFG_RETRY_DEFAULT);
2275 2278
2276 ifp->if_oerrors += smb->tx_late_colls + smb->tx_excess_colls + 2279 if_statadd_ref(nsr, if_oerrors,
2277 smb->tx_underrun + smb->tx_pkts_truncated; 2280 smb->tx_late_colls + smb->tx_excess_colls +
 2281 smb->tx_underrun + smb->tx_pkts_truncated);
2278 2282
2279 ifp->if_ierrors += smb->rx_crcerrs + smb->rx_lenerrs + 2283 if_statadd_ref(nsr, if_ierrors,
 2284 smb->rx_crcerrs + smb->rx_lenerrs +
2280 smb->rx_runts + smb->rx_pkts_truncated + 2285 smb->rx_runts + smb->rx_pkts_truncated +
2281 smb->rx_fifo_oflows + smb->rx_rrs_errs + 2286 smb->rx_fifo_oflows + smb->rx_rrs_errs +
2282 smb->rx_alignerrs; 2287 smb->rx_alignerrs);
 2288
 2289 IF_STAT_PUTREF(ifp);
2283 2290
2284 if ((sc->alc_flags & ALC_FLAG_SMB_BUG) == 0) { 2291 if ((sc->alc_flags & ALC_FLAG_SMB_BUG) == 0) {
2285 /* Update done, clear. */ 2292 /* Update done, clear. */
2286 smb->updated = 0; 2293 smb->updated = 0;
2287 bus_dmamap_sync(sc->sc_dmat, sc->alc_cdata.alc_smb_map, 0, 2294 bus_dmamap_sync(sc->sc_dmat, sc->alc_cdata.alc_smb_map, 0,
2288 sc->alc_cdata.alc_smb_map->dm_mapsize, 2295 sc->alc_cdata.alc_smb_map->dm_mapsize,
2289 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); 2296 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
2290 } 2297 }
2291} 2298}
2292 2299
2293static int 2300static int
2294alc_intr(void *arg) 2301alc_intr(void *arg)
2295{ 2302{
@@ -2541,27 +2548,27 @@ alc_rxeof(struct alc_softc *sc, struct r @@ -2541,27 +2548,27 @@ alc_rxeof(struct alc_softc *sc, struct r
2541 */ 2548 */
2542 status |= RRD_TCP_UDPCSUM_NOK | RRD_IPCSUM_NOK; 2549 status |= RRD_TCP_UDPCSUM_NOK | RRD_IPCSUM_NOK;
2543 if ((status & (RRD_ERR_CRC | RRD_ERR_ALIGN | 2550 if ((status & (RRD_ERR_CRC | RRD_ERR_ALIGN |
2544 RRD_ERR_TRUNC | RRD_ERR_RUNT)) != 0) 2551 RRD_ERR_TRUNC | RRD_ERR_RUNT)) != 0)
2545 return; 2552 return;
2546 } 2553 }
2547 2554
2548 for (count = 0; count < nsegs; count++, 2555 for (count = 0; count < nsegs; count++,
2549 ALC_DESC_INC(rx_cons, ALC_RX_RING_CNT)) { 2556 ALC_DESC_INC(rx_cons, ALC_RX_RING_CNT)) {
2550 rxd = &sc->alc_cdata.alc_rxdesc[rx_cons]; 2557 rxd = &sc->alc_cdata.alc_rxdesc[rx_cons];
2551 mp = rxd->rx_m; 2558 mp = rxd->rx_m;
2552 /* Add a new receive buffer to the ring. */ 2559 /* Add a new receive buffer to the ring. */
2553 if (alc_newbuf(sc, rxd, false) != 0) { 2560 if (alc_newbuf(sc, rxd, false) != 0) {
2554 ifp->if_iqdrops++; 2561 if_statinc(ifp, if_iqdrops);
2555 /* Reuse Rx buffers. */ 2562 /* Reuse Rx buffers. */
2556 if (sc->alc_cdata.alc_rxhead != NULL) 2563 if (sc->alc_cdata.alc_rxhead != NULL)
2557 m_freem(sc->alc_cdata.alc_rxhead); 2564 m_freem(sc->alc_cdata.alc_rxhead);
2558 break; 2565 break;
2559 } 2566 }
2560 2567
2561 /* 2568 /*
2562 * Assume we've received a full sized frame. 2569 * Assume we've received a full sized frame.
2563 * Actual size is fixed when we encounter the end of 2570 * Actual size is fixed when we encounter the end of
2564 * multi-segmented frame. 2571 * multi-segmented frame.
2565 */ 2572 */
2566 mp->m_len = sc->alc_buf_size; 2573 mp->m_len = sc->alc_buf_size;
2567 2574

cvs diff -r1.37 -r1.38 src/sys/dev/pci/if_ale.c (expand / switch to unified diff)

--- src/sys/dev/pci/if_ale.c 2019/12/01 08:16:49 1.37
+++ src/sys/dev/pci/if_ale.c 2020/01/30 13:59:24 1.38
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_ale.c,v 1.37 2019/12/01 08:16:49 msaitoh Exp $ */ 1/* $NetBSD: if_ale.c,v 1.38 2020/01/30 13:59:24 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org> 4 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.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 unmodified, this list of conditions, and the following 11 * notice unmodified, this list of conditions, and the following
12 * disclaimer. 12 * disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE. 27 * SUCH DAMAGE.
28 * 28 *
29 * $FreeBSD: src/sys/dev/ale/if_ale.c,v 1.3 2008/12/03 09:01:12 yongari Exp $ 29 * $FreeBSD: src/sys/dev/ale/if_ale.c,v 1.3 2008/12/03 09:01:12 yongari Exp $
30 */ 30 */
31 31
32/* Driver for Atheros AR8121/AR8113/AR8114 PCIe Ethernet. */ 32/* Driver for Atheros AR8121/AR8113/AR8114 PCIe Ethernet. */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__KERNEL_RCSID(0, "$NetBSD: if_ale.c,v 1.37 2019/12/01 08:16:49 msaitoh Exp $"); 35__KERNEL_RCSID(0, "$NetBSD: if_ale.c,v 1.38 2020/01/30 13:59:24 thorpej Exp $");
36 36
37#include "vlan.h" 37#include "vlan.h"
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/proc.h> 40#include <sys/proc.h>
41#include <sys/endian.h> 41#include <sys/endian.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/sockio.h> 44#include <sys/sockio.h>
45#include <sys/mbuf.h> 45#include <sys/mbuf.h>
46#include <sys/queue.h> 46#include <sys/queue.h>
47#include <sys/kernel.h> 47#include <sys/kernel.h>
48#include <sys/device.h> 48#include <sys/device.h>
@@ -1088,33 +1088,33 @@ ale_start(struct ifnet *ifp) @@ -1088,33 +1088,33 @@ ale_start(struct ifnet *ifp)
1088 /* Set a timeout in case the chip goes out to lunch. */ 1088 /* Set a timeout in case the chip goes out to lunch. */
1089 ifp->if_timer = ALE_TX_TIMEOUT; 1089 ifp->if_timer = ALE_TX_TIMEOUT;
1090 } 1090 }
1091} 1091}
1092 1092
1093static void 1093static void
1094ale_watchdog(struct ifnet *ifp) 1094ale_watchdog(struct ifnet *ifp)
1095{ 1095{
1096 struct ale_softc *sc = ifp->if_softc; 1096 struct ale_softc *sc = ifp->if_softc;
1097 1097
1098 if ((sc->ale_flags & ALE_FLAG_LINK) == 0) { 1098 if ((sc->ale_flags & ALE_FLAG_LINK) == 0) {
1099 printf("%s: watchdog timeout (missed link)\n", 1099 printf("%s: watchdog timeout (missed link)\n",
1100 device_xname(sc->sc_dev)); 1100 device_xname(sc->sc_dev));
1101 ifp->if_oerrors++; 1101 if_statinc(ifp, if_oerrors);
1102 ale_init(ifp); 1102 ale_init(ifp);
1103 return; 1103 return;
1104 } 1104 }
1105 1105
1106 printf("%s: watchdog timeout\n", device_xname(sc->sc_dev)); 1106 printf("%s: watchdog timeout\n", device_xname(sc->sc_dev));
1107 ifp->if_oerrors++; 1107 if_statinc(ifp, if_oerrors);
1108 ale_init(ifp); 1108 ale_init(ifp);
1109 1109
1110 if (!IFQ_IS_EMPTY(&ifp->if_snd)) 1110 if (!IFQ_IS_EMPTY(&ifp->if_snd))
1111 ale_start(ifp); 1111 ale_start(ifp);
1112} 1112}
1113 1113
1114static int 1114static int
1115ale_ioctl(struct ifnet *ifp, u_long cmd, void *data) 1115ale_ioctl(struct ifnet *ifp, u_long cmd, void *data)
1116{ 1116{
1117 struct ale_softc *sc = ifp->if_softc; 1117 struct ale_softc *sc = ifp->if_softc;
1118 int s, error; 1118 int s, error;
1119 1119
1120 s = splnet(); 1120 s = splnet();
@@ -1247,46 +1247,53 @@ ale_stats_update(struct ale_softc *sc) @@ -1247,46 +1247,53 @@ ale_stats_update(struct ale_softc *sc)
1247 stat->tx_single_colls += smb->tx_single_colls; 1247 stat->tx_single_colls += smb->tx_single_colls;
1248 stat->tx_multi_colls += smb->tx_multi_colls; 1248 stat->tx_multi_colls += smb->tx_multi_colls;
1249 stat->tx_late_colls += smb->tx_late_colls; 1249 stat->tx_late_colls += smb->tx_late_colls;
1250 stat->tx_excess_colls += smb->tx_excess_colls; 1250 stat->tx_excess_colls += smb->tx_excess_colls;
1251 stat->tx_abort += smb->tx_abort; 1251 stat->tx_abort += smb->tx_abort;
1252 stat->tx_underrun += smb->tx_underrun; 1252 stat->tx_underrun += smb->tx_underrun;
1253 stat->tx_desc_underrun += smb->tx_desc_underrun; 1253 stat->tx_desc_underrun += smb->tx_desc_underrun;
1254 stat->tx_lenerrs += smb->tx_lenerrs; 1254 stat->tx_lenerrs += smb->tx_lenerrs;
1255 stat->tx_pkts_truncated += smb->tx_pkts_truncated; 1255 stat->tx_pkts_truncated += smb->tx_pkts_truncated;
1256 stat->tx_bcast_bytes += smb->tx_bcast_bytes; 1256 stat->tx_bcast_bytes += smb->tx_bcast_bytes;
1257 stat->tx_mcast_bytes += smb->tx_mcast_bytes; 1257 stat->tx_mcast_bytes += smb->tx_mcast_bytes;
1258 1258
1259 /* Update counters in ifnet. */ 1259 /* Update counters in ifnet. */
1260 ifp->if_opackets += smb->tx_frames; 1260 net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
1261 1261
1262 ifp->if_collisions += smb->tx_single_colls + 1262 if_statadd_ref(nsr, if_opackets, smb->tx_frames);
 1263
 1264 if_statadd_ref(nsr, if_collisions,
 1265 smb->tx_single_colls +
1263 smb->tx_multi_colls * 2 + smb->tx_late_colls + 1266 smb->tx_multi_colls * 2 + smb->tx_late_colls +
1264 smb->tx_abort * HDPX_CFG_RETRY_DEFAULT; 1267 smb->tx_abort * HDPX_CFG_RETRY_DEFAULT);
1265 1268
1266 /* 1269 /*
1267 * XXX 1270 * XXX
1268 * tx_pkts_truncated counter looks suspicious. It constantly 1271 * tx_pkts_truncated counter looks suspicious. It constantly
1269 * increments with no sign of Tx errors. This may indicate 1272 * increments with no sign of Tx errors. This may indicate
1270 * the counter name is not correct one so I've removed the 1273 * the counter name is not correct one so I've removed the
1271 * counter in output errors. 1274 * counter in output errors.
1272 */ 1275 */
1273 ifp->if_oerrors += smb->tx_abort + smb->tx_late_colls + 1276 if_statadd_ref(nsr, if_oerrors,
1274 smb->tx_underrun; 1277 smb->tx_abort + smb->tx_late_colls +
 1278 smb->tx_underrun);
1275 1279
1276 ifp->if_ierrors += smb->rx_crcerrs + smb->rx_lenerrs + 1280 if_statadd_ref(nsr, if_ierrors,
 1281 smb->rx_crcerrs + smb->rx_lenerrs +
1277 smb->rx_runts + smb->rx_pkts_truncated + 1282 smb->rx_runts + smb->rx_pkts_truncated +
1278 smb->rx_fifo_oflows + smb->rx_rrs_errs + 1283 smb->rx_fifo_oflows + smb->rx_rrs_errs +
1279 smb->rx_alignerrs; 1284 smb->rx_alignerrs);
 1285
 1286 IF_STAT_PUTREF(ifp);
1280} 1287}
1281 1288
1282static int 1289static int
1283ale_intr(void *xsc) 1290ale_intr(void *xsc)
1284{ 1291{
1285 struct ale_softc *sc = xsc; 1292 struct ale_softc *sc = xsc;
1286 struct ifnet *ifp = &sc->sc_ec.ec_if; 1293 struct ifnet *ifp = &sc->sc_ec.ec_if;
1287 uint32_t status; 1294 uint32_t status;
1288 1295
1289 status = CSR_READ_4(sc, ALE_INTR_STATUS); 1296 status = CSR_READ_4(sc, ALE_INTR_STATUS);
1290 if ((status & ALE_INTRS) == 0) 1297 if ((status & ALE_INTRS) == 0)
1291 return 0; 1298 return 0;
1292 1299
@@ -1522,27 +1529,27 @@ ale_rxeof(struct ale_softc *sc) @@ -1522,27 +1529,27 @@ ale_rxeof(struct ale_softc *sc)
1522 } 1529 }
1523 /* 1530 /*
1524 * m_devget(9) is major bottle-neck of ale(4)(It comes 1531 * m_devget(9) is major bottle-neck of ale(4)(It comes
1525 * from hardware limitation). For jumbo frames we could 1532 * from hardware limitation). For jumbo frames we could
1526 * get a slightly better performance if driver use 1533 * get a slightly better performance if driver use
1527 * m_getjcl(9) with proper buffer size argument. However 1534 * m_getjcl(9) with proper buffer size argument. However
1528 * that would make code more complicated and I don't 1535 * that would make code more complicated and I don't
1529 * think users would expect good Rx performance numbers 1536 * think users would expect good Rx performance numbers
1530 * on these low-end consumer ethernet controller. 1537 * on these low-end consumer ethernet controller.
1531 */ 1538 */
1532 m = m_devget((char *)(rs + 1), length - ETHER_CRC_LEN, 1539 m = m_devget((char *)(rs + 1), length - ETHER_CRC_LEN,
1533 0, ifp); 1540 0, ifp);
1534 if (m == NULL) { 1541 if (m == NULL) {
1535 ifp->if_iqdrops++; 1542 if_statinc(ifp, if_iqdrops);
1536 ale_rx_update_page(sc, &rx_page, length, &prod); 1543 ale_rx_update_page(sc, &rx_page, length, &prod);
1537 continue; 1544 continue;
1538 } 1545 }
1539 if (status & ALE_RD_IPV4) 1546 if (status & ALE_RD_IPV4)
1540 ale_rxcsum(sc, m, status); 1547 ale_rxcsum(sc, m, status);
1541#if NVLAN > 0 1548#if NVLAN > 0
1542 if (status & ALE_RD_VLAN) { 1549 if (status & ALE_RD_VLAN) {
1543 uint32_t vtags = ALE_RX_VLAN(le32toh(rs->vtags)); 1550 uint32_t vtags = ALE_RX_VLAN(le32toh(rs->vtags));
1544 vlan_set_tag(m, ALE_RX_VLAN_TAG(vtags)); 1551 vlan_set_tag(m, ALE_RX_VLAN_TAG(vtags));
1545 } 1552 }
1546#endif 1553#endif
1547 1554
1548 /* Pass it to upper layer. */ 1555 /* Pass it to upper layer. */