Module Name:    src
Committed By:   msaitoh
Date:           Thu May 11 07:19:02 UTC 2023

Modified Files:
        src/sys/dev/pci: if_wm.c if_wmreg.h

Log Message:
Add some new event counters.

Add the following counters for 82575 and newer except 80003, ICHs and PCHs:
    - Only 82576 document describes about the circuit breaker,
      so the following two might be only for 82575:
        - Circuit Breaker TX Manageability Packet
        - Circuit Breaker RX Dropped Packet
    - 82575's document doesn't describe the following two, but we can see
      the same value as GO{T,R}C have:
        - Host Good Octets RX
        - Host Good Octets TX
    - 82575's document doesn't describe the LENERRS (Length Errors) counter.
      I don't know if it has.
    - Perhaps Non-SerDes/SGMII devices don't have SCVPC
      (SerDes/SGMII Code Violation Packet) register. We don't care if
      it's SerDes/SGMII or not for now.
    - HRMPC (Header Redirection Missed Packet) appears only once
      in 8257[56]'s datasheet. FreeBSD's igb counts it, so we do, too.
    - Count the following two for I350 and newer. I don't know if PCHs have:
        - EEE TX LPI
        - EEE RX LPI


To generate a diff of this commit:
cvs rdiff -u -r1.775 -r1.776 src/sys/dev/pci/if_wm.c
cvs rdiff -u -r1.129 -r1.130 src/sys/dev/pci/if_wmreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.775 src/sys/dev/pci/if_wm.c:1.776
--- src/sys/dev/pci/if_wm.c:1.775	Thu May 11 07:14:46 2023
+++ src/sys/dev/pci/if_wm.c	Thu May 11 07:19:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.775 2023/05/11 07:14:46 msaitoh Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.776 2023/05/11 07:19:02 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.775 2023/05/11 07:14:46 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.776 2023/05/11 07:19:02 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_if_wm.h"
@@ -601,6 +601,7 @@ struct wm_softc {
 	struct evcnt sc_ev_mcc;		/* Multiple Collision */
 	struct evcnt sc_ev_latecol;	/* Late Collision */
 	struct evcnt sc_ev_colc;	/* Collision */
+	struct evcnt sc_ev_cbtmpc;	/* Circuit Breaker Tx Mng. Packet */
 	struct evcnt sc_ev_dc;		/* Defer */
 	struct evcnt sc_ev_tncrs;	/* Tx-No CRS */
 	struct evcnt sc_ev_sec;		/* Sequence Error */
@@ -611,6 +612,7 @@ struct wm_softc {
 	struct evcnt sc_ev_htdpmc;	/* Host Tx Discarded Pkts by MAC */
 
 	struct evcnt sc_ev_rlec;	/* Receive Length Error */
+	struct evcnt sc_ev_cbrdpc;	/* Circuit Breaker Rx Dropped Packet */
 	struct evcnt sc_ev_prc64;	/* Packets Rx (64 bytes) */
 	struct evcnt sc_ev_prc127;	/* Packets Rx (65-127 bytes) */
 	struct evcnt sc_ev_prc255;	/* Packets Rx (128-255 bytes) */
@@ -673,12 +675,17 @@ struct wm_softc {
 	struct evcnt sc_ev_hgptc;	/* Host Good Packets TX */
 	struct evcnt sc_ev_debug4;	/* Debug Counter 4 */
 	struct evcnt sc_ev_htcbdpc;	/* Host Tx Circuit Breaker Drp. Pkts */
-
+	struct evcnt sc_ev_hgorc;	/* Host Good Octets Rx */
+	struct evcnt sc_ev_hgotc;	/* Host Good Octets Tx */
+	struct evcnt sc_ev_lenerrs;	/* Length Error */
+	struct evcnt sc_ev_tlpic;	/* EEE Tx LPI */
+	struct evcnt sc_ev_rlpic;	/* EEE Rx LPI */
 	struct evcnt sc_ev_b2ogprc;	/* BMC2OS pkts received by host */
 	struct evcnt sc_ev_o2bspc;	/* OS2BMC pkts transmitted by host */
 	struct evcnt sc_ev_b2ospc;	/* BMC2OS pkts sent by BMC */
 	struct evcnt sc_ev_o2bgptc;	/* OS2BMC pkts received by BMC */
-
+	struct evcnt sc_ev_scvpc;	/* SerDes/SGMII Code Violation Pkt. */
+	struct evcnt sc_ev_hrmpc;	/* Header Redirection Missed Packet */
 #endif /* WM_EVENT_COUNTERS */
 
 	struct sysctllog *sc_sysctllog;
@@ -3262,6 +3269,9 @@ alloc_retry:
 			    "TCP Segmentation Context Tx Fail");
 		else {
 			/* XXX Is the circuit breaker only for 82576? */
+			evcnt_attach_dynamic(&sc->sc_ev_cbrdpc,
+			    EVCNT_TYPE_MISC, NULL, xname,
+			    "Circuit Breaker Rx Dropped Packet");
 			evcnt_attach_dynamic(&sc->sc_ev_cbrmpc,
 			    EVCNT_TYPE_MISC, NULL, xname,
 			    "Circuit Breaker Rx Manageability Packet");
@@ -3289,6 +3299,11 @@ alloc_retry:
 	    NULL, xname, "Multiple Collision");
 	evcnt_attach_dynamic(&sc->sc_ev_latecol, EVCNT_TYPE_MISC,
 	    NULL, xname, "Late Collisions");
+
+	if ((sc->sc_type >= WM_T_I350) && !WM_IS_ICHPCH(sc))
+		evcnt_attach_dynamic(&sc->sc_ev_cbtmpc, EVCNT_TYPE_MISC,
+		    NULL, xname, "Circuit Breaker Tx Manageability Packet");
+
 	evcnt_attach_dynamic(&sc->sc_ev_dc, EVCNT_TYPE_MISC,
 	    NULL, xname, "Defer");
 	evcnt_attach_dynamic(&sc->sc_ev_prc64, EVCNT_TYPE_MISC,
@@ -3411,8 +3426,19 @@ alloc_retry:
 		/* XXX Is the circuit breaker only for 82576? */
 		evcnt_attach_dynamic(&sc->sc_ev_htcbdpc, EVCNT_TYPE_MISC,
 		    NULL, xname, "Host Tx Circuit Breaker Dropped Packets");
-	}
-	if ((sc->sc_type >= WM_T_I350) && (sc->sc_type < WM_T_80003)) {
+
+		evcnt_attach_dynamic(&sc->sc_ev_hgorc, EVCNT_TYPE_MISC,
+		    NULL, xname, "Host Good Octets Rx");
+		evcnt_attach_dynamic(&sc->sc_ev_hgotc, EVCNT_TYPE_MISC,
+		    NULL, xname, "Host Good Octets Tx");
+		evcnt_attach_dynamic(&sc->sc_ev_lenerrs, EVCNT_TYPE_MISC,
+		    NULL, xname, "Length Errors");
+	}
+	if ((sc->sc_type >= WM_T_I350) && !WM_IS_ICHPCH(sc)) {
+		evcnt_attach_dynamic(&sc->sc_ev_tlpic, EVCNT_TYPE_MISC,
+		    NULL, xname, "EEE Tx LPI");
+		evcnt_attach_dynamic(&sc->sc_ev_rlpic, EVCNT_TYPE_MISC,
+		    NULL, xname, "EEE Rx LPI");
 		evcnt_attach_dynamic(&sc->sc_ev_b2ogprc, EVCNT_TYPE_MISC,
 		    NULL, xname, "BMC2OS Packets received by host");
 		evcnt_attach_dynamic(&sc->sc_ev_o2bspc, EVCNT_TYPE_MISC,
@@ -3421,6 +3447,10 @@ alloc_retry:
 		    NULL, xname, "BMC2OS Packets sent by BMC");
 		evcnt_attach_dynamic(&sc->sc_ev_o2bgptc, EVCNT_TYPE_MISC,
 		    NULL, xname, "OS2BMC Packets received by BMC");
+		evcnt_attach_dynamic(&sc->sc_ev_scvpc, EVCNT_TYPE_MISC,
+		    NULL, xname, "SerDes/SGMII Code Violation Packet");
+		evcnt_attach_dynamic(&sc->sc_ev_hrmpc, EVCNT_TYPE_MISC,
+		    NULL, xname, "Header Redirection Missed Packet");
 	}
 #endif /* WM_EVENT_COUNTERS */
 
@@ -3488,8 +3518,10 @@ wm_detach(device_t self, int flags __unu
 		evcnt_detach(&sc->sc_ev_tsctc);
 		if ((sc->sc_type < WM_T_82575) || WM_IS_ICHPCH(sc))
 			evcnt_detach(&sc->sc_ev_tsctfc);
-		else
+		else {
+			evcnt_detach(&sc->sc_ev_cbrdpc);
 			evcnt_detach(&sc->sc_ev_cbrmpc);
+		}
 	}
 
 	if (sc->sc_type >= WM_T_82542_2_1) {
@@ -3504,6 +3536,10 @@ wm_detach(device_t self, int flags __unu
 	evcnt_detach(&sc->sc_ev_ecol);
 	evcnt_detach(&sc->sc_ev_mcc);
 	evcnt_detach(&sc->sc_ev_latecol);
+
+	if ((sc->sc_type >= WM_T_I350) && !WM_IS_ICHPCH(sc))
+		evcnt_detach(&sc->sc_ev_cbtmpc);
+
 	evcnt_detach(&sc->sc_ev_dc);
 	evcnt_detach(&sc->sc_ev_prc64);
 	evcnt_detach(&sc->sc_ev_prc127);
@@ -3558,12 +3594,20 @@ wm_detach(device_t self, int flags __unu
 		evcnt_detach(&sc->sc_ev_debug4);
 		evcnt_detach(&sc->sc_ev_rxdmtc);
 		evcnt_detach(&sc->sc_ev_htcbdpc);
-	}
-	if ((sc->sc_type >= WM_T_I350) && (sc->sc_type < WM_T_80003)) {
+
+		evcnt_detach(&sc->sc_ev_hgorc);
+		evcnt_detach(&sc->sc_ev_hgotc);
+		evcnt_detach(&sc->sc_ev_lenerrs);
+	}
+	if ((sc->sc_type >= WM_T_I350) && !WM_IS_ICHPCH(sc)) {
+		evcnt_detach(&sc->sc_ev_tlpic);
+		evcnt_detach(&sc->sc_ev_rlpic);
 		evcnt_detach(&sc->sc_ev_b2ogprc);
 		evcnt_detach(&sc->sc_ev_o2bspc);
 		evcnt_detach(&sc->sc_ev_b2ospc);
 		evcnt_detach(&sc->sc_ev_o2bgptc);
+		evcnt_detach(&sc->sc_ev_scvpc);
+		evcnt_detach(&sc->sc_ev_hrmpc);
 	}
 #endif /* WM_EVENT_COUNTERS */
 
@@ -3895,10 +3939,16 @@ wm_tick(void *arg)
 		WM_EVCNT_ADD(&sc->sc_ev_tx_xoff, CSR_READ(sc, WMREG_XOFFTXC));
 		WM_EVCNT_ADD(&sc->sc_ev_rx_macctl, CSR_READ(sc, WMREG_FCRUC));
 	}
+
 	WM_EVCNT_ADD(&sc->sc_ev_scc, CSR_READ(sc, WMREG_SCC));
 	WM_EVCNT_ADD(&sc->sc_ev_ecol, CSR_READ(sc, WMREG_ECOL));
 	WM_EVCNT_ADD(&sc->sc_ev_mcc, CSR_READ(sc, WMREG_MCC));
 	WM_EVCNT_ADD(&sc->sc_ev_latecol, CSR_READ(sc, WMREG_LATECOL));
+
+	if ((sc->sc_type >= WM_T_I350) && !WM_IS_ICHPCH(sc)) {
+		WM_EVCNT_ADD(&sc->sc_ev_cbtmpc, CSR_READ(sc, WMREG_CBTMPC));
+	}
+
 	WM_EVCNT_ADD(&sc->sc_ev_dc, CSR_READ(sc, WMREG_DC));
 	WM_EVCNT_ADD(&sc->sc_ev_prc64, CSR_READ(sc, WMREG_PRC64));
 	WM_EVCNT_ADD(&sc->sc_ev_prc127, CSR_READ(sc, WMREG_PRC127));
@@ -3975,14 +4025,30 @@ wm_tick(void *arg)
 		WM_EVCNT_ADD(&sc->sc_ev_debug4, CSR_READ(sc, WMREG_DEBUG4));
 		WM_EVCNT_ADD(&sc->sc_ev_rxdmtc, CSR_READ(sc, WMREG_RXDMTC));
 		WM_EVCNT_ADD(&sc->sc_ev_htcbdpc, CSR_READ(sc, WMREG_HTCBDPC));
-	}
 
-	if (((sc->sc_type >= WM_T_I350) && (sc->sc_type < WM_T_80003))
-	    && ((CSR_READ(sc, WMREG_MANC) & MANC_EN_BMC2OS) != 0)) {
-		WM_EVCNT_ADD(&sc->sc_ev_b2ogprc, CSR_READ(sc, WMREG_B2OGPRC));
-		WM_EVCNT_ADD(&sc->sc_ev_o2bspc, CSR_READ(sc, WMREG_O2BSPC));
-		WM_EVCNT_ADD(&sc->sc_ev_b2ospc, CSR_READ(sc, WMREG_B2OSPC));
-		WM_EVCNT_ADD(&sc->sc_ev_o2bgptc, CSR_READ(sc, WMREG_O2BGPTC));
+		WM_EVCNT_ADD(&sc->sc_ev_hgorc,
+		    CSR_READ(sc, WMREG_HGORCL) +
+		    ((uint64_t)CSR_READ(sc, WMREG_HGORCH) << 32));
+		WM_EVCNT_ADD(&sc->sc_ev_hgotc,
+		    CSR_READ(sc, WMREG_HGOTCL) +
+		    ((uint64_t)CSR_READ(sc, WMREG_HGOTCH) << 32));
+		WM_EVCNT_ADD(&sc->sc_ev_lenerrs, CSR_READ(sc, WMREG_LENERRS));
+	}
+	if ((sc->sc_type >= WM_T_I350) && (sc->sc_type < WM_T_80003)) {
+		WM_EVCNT_ADD(&sc->sc_ev_tlpic, CSR_READ(sc, WMREG_TLPIC));
+		WM_EVCNT_ADD(&sc->sc_ev_rlpic, CSR_READ(sc, WMREG_RLPIC));
+		if ((CSR_READ(sc, WMREG_MANC) & MANC_EN_BMC2OS) != 0) {
+			WM_EVCNT_ADD(&sc->sc_ev_b2ogprc,
+			    CSR_READ(sc, WMREG_B2OGPRC));
+			WM_EVCNT_ADD(&sc->sc_ev_o2bspc,
+			    CSR_READ(sc, WMREG_O2BSPC));
+			WM_EVCNT_ADD(&sc->sc_ev_b2ospc,
+			    CSR_READ(sc, WMREG_B2OSPC));
+			WM_EVCNT_ADD(&sc->sc_ev_o2bgptc,
+			    CSR_READ(sc, WMREG_O2BGPTC));
+		}
+		WM_EVCNT_ADD(&sc->sc_ev_scvpc, CSR_READ(sc, WMREG_SCVPC));
+		WM_EVCNT_ADD(&sc->sc_ev_hrmpc, CSR_READ(sc, WMREG_HRMPC));
 	}
 	net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
 	if_statadd_ref(nsr, if_collisions, colc);

Index: src/sys/dev/pci/if_wmreg.h
diff -u src/sys/dev/pci/if_wmreg.h:1.129 src/sys/dev/pci/if_wmreg.h:1.130
--- src/sys/dev/pci/if_wmreg.h:1.129	Thu May 11 07:14:46 2023
+++ src/sys/dev/pci/if_wmreg.h	Thu May 11 07:19:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wmreg.h,v 1.129 2023/05/11 07:14:46 msaitoh Exp $	*/
+/*	$NetBSD: if_wmreg.h,v 1.130 2023/05/11 07:19:02 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -1152,6 +1152,7 @@ struct livengood_tcpip_ctxdesc {
 #define	WMREG_MCC	0x401c	/* Multiple Collision Count - R/clr */
 #define	WMREG_LATECOL	0x4020	/* Late Collisions Count - R/clr */
 #define	WMREG_COLC	0x4028	/* Collision Count - R/clr */
+#define	WMREG_CBTMPC	0x402c	/* Circuit Breaker Tx Manageability Packet */
 #define	WMREG_DC	0x4030	/* Defer Count - R/clr */
 #define	WMREG_TNCRS	0x4034	/* Tx with No CRS - R/clr */
 #define	WMREG_SEC	0x4038	/* Sequence Error Count */
@@ -1162,6 +1163,7 @@ struct livengood_tcpip_ctxdesc {
 #define	WMREG_HTDPMC	0x403c	/* Host Tx Discarded Packets by MAC Count */
 
 #define	WMREG_RLEC	0x4040	/* Receive Length Error Count */
+#define	WMREG_CBRDPC	0x4044	/* Circuit Breaker Rx Dropped Packet Count */
 #define	WMREG_XONRXC	0x4048	/* XON Rx Count - R/clr */
 #define	WMREG_XONTXC	0x404c	/* XON Tx Count - R/clr */
 #define	WMREG_XOFFRXC	0x4050	/* XOFF Rx Count - R/clr */
@@ -1230,6 +1232,11 @@ struct livengood_tcpip_ctxdesc {
 #define	WMREG_DEBUG4	0x411c	/* Debug Counter 4 */
 #define	WMREG_RXDMTC	0x4120	/* Rx Desc Min Thresh Count */
 #define	WMREG_HTCBDPC	0x4124	/* Host Tx Circuit Breaker Dropped Pkt. Cnt. */
+#define	WMREG_HGORCL	0x4128	/* Host Good Octets Rx Count Low (>=82576?) */
+#define	WMREG_HGORCH	0x412c	/* Host Good Octets Rx Count High (>=82576?) */
+#define	WMREG_HGOTCL	0x4130	/* Host Good Octets Tx Count Low (>=82576?) */
+#define	WMREG_HGOTCH	0x4134	/* Host Good Octets Tx Count High (>=82576?) */
+#define	WMREG_LENERRS	0x4138	/* Length Errors Count (>=82576?) */
 
 #define	WMREG_TLPIC	0x4148	/* EEE Tx LPI Count */
 #define	WMREG_RLPIC	0x414c	/* EEE Rx LPI Count */
@@ -1270,6 +1277,7 @@ struct livengood_tcpip_ctxdesc {
 #define	WMREG_PCS_ANADV	0x4218	/* AN Advertsement */
 #define	WMREG_PCS_LPAB	0x421c	/* Link Partnet Ability */
 #define	WMREG_PCS_NPTX	0x4220	/* Next Page Transmit */
+#define	WMREG_SCVPC	0x4228	/* SerDes/SGMII Code Violation Packet Count */
 
 #define	WMREG_RXCSUM	0x5000	/* Receive Checksum register */
 #define	RXCSUM_PCSS	0x000000ff	/* Packet Checksum Start */
@@ -1467,6 +1475,8 @@ struct livengood_tcpip_ctxdesc {
 #define	WMREG_B2OSPC	0x8fe0	/* BMC2OS packets sent by BMC */
 #define	WMREG_O2BGPTC	0x8fe4	/* OS2BMC packets received by BMC */
 
+#define	WMREG_HRMPC	0xa018	/* Header Redirection Missed Packet Count */
+
 #define	WMREG_EEC	0x12010
 #define	EEC_FLASH_DETECTED __BIT(19)	/* FLASH */
 #define	EEC_FLUPD	__BIT(23)	/* Update FLASH */

Reply via email to