Module Name:    src
Committed By:   martin
Date:           Sun Oct  8 15:13:10 UTC 2023

Modified Files:
        src/sys/dev/pci/ixgbe [netbsd-9]: ix_txrx.c ixgbe.c ixgbe.h
            ixgbe_82599.c ixgbe_mbx.h ixgbe_type.h ixgbe_vf.c ixgbe_vf.h ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1745):

        sys/dev/pci/ixgbe/ixgbe_82599.c: revision 1.30
        sys/dev/pci/ixgbe/ixv.c: revision 1.184
        sys/dev/pci/ixgbe/ixv.c: revision 1.185
        sys/dev/pci/ixgbe/ixgbe_vf.c: revision 1.32
        sys/dev/pci/ixgbe/ixgbe_vf.c: revision 1.33
        sys/dev/pci/ixgbe/ixgbe.h: revision 1.87
        sys/dev/pci/ixgbe/ixgbe.h: revision 1.88
        sys/dev/pci/ixgbe/ixgbe.c: revision 1.330
        sys/dev/pci/ixgbe/ixgbe.c: revision 1.331
        sys/dev/pci/ixgbe/ixgbe.c: revision 1.332
        sys/dev/pci/ixgbe/ixgbe_vf.h: revision 1.18
        sys/dev/pci/ixgbe/ix_txrx.c: revision 1.101
        sys/dev/pci/ixgbe/ixgbe_type.h: revision 1.57
        sys/dev/pci/ixgbe/ixgbe_mbx.h: revision 1.20
        sys/dev/pci/ixgbe/ixgbe.c: revision 1.327
        sys/dev/pci/ixgbe/ixgbe.c: revision 1.328
        sys/dev/pci/ixgbe/ixgbe.c: revision 1.329

ixgbe: Reorder some event counters for readability.

ixg(4): Rename some descriptions of event counters.
 - Rename some descriptions from register name to the meaning.
 - For the same meaning's counters, add "(soft)" or "(reg)".
   The former is for a software level counter and the latter is for a
   statistics counter register based.

ixg(4): Count Queue Bytes {Transmit, Receive} counter.

ixg(4): Reorder some flow control related event counters for readability.

ixg(4): Rename some descriptions of flow control related event conters.
Remove obsolete comment.

ixgbe: Fix typo in comment. No functional change.

ixv(4): Improve error check.
 ixgbe_vf.c rev. 1.31 changed the behavior of the ixgbe_check_mac_link_vf()
function. It was from FreeBSD's ixv-1.5.25 to resolve mailbox collision
problem. The change had a problem that error checks have not done at all if
the API version >= 1.5. Fix it. From FreeBSD ixv-1.5.27.

ixv(4): Add new IXGBE_VF_GET_LINK_STATE message support.
 PF can control vf's link state by this change. Note that Linux's PF driver
can't control the link to force up (i.e. ip link set XXX vf Y state enable).
>From FreeBSD ixv-1.5.30.

ixg(4): Update FCTRL after writing multicast filter. Same as other OSes.
 From FreeBSD 395cc55d896654b8f75071e71e856b22aed87da5.


To generate a diff of this commit:
cvs rdiff -u -r1.54.2.11 -r1.54.2.12 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.199.2.26 -r1.199.2.27 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.56.2.9 -r1.56.2.10 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.21.4.4 -r1.21.4.5 src/sys/dev/pci/ixgbe/ixgbe_82599.c
cvs rdiff -u -r1.14.2.2 -r1.14.2.3 src/sys/dev/pci/ixgbe/ixgbe_mbx.h
cvs rdiff -u -r1.41.2.8 -r1.41.2.9 src/sys/dev/pci/ixgbe/ixgbe_type.h
cvs rdiff -u -r1.18.2.6 -r1.18.2.7 src/sys/dev/pci/ixgbe/ixgbe_vf.c
cvs rdiff -u -r1.13.8.3 -r1.13.8.4 src/sys/dev/pci/ixgbe/ixgbe_vf.h
cvs rdiff -u -r1.125.2.21 -r1.125.2.22 src/sys/dev/pci/ixgbe/ixv.c

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/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.54.2.11 src/sys/dev/pci/ixgbe/ix_txrx.c:1.54.2.12
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.54.2.11	Mon Jan 23 14:04:42 2023
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Sun Oct  8 15:13:09 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.54.2.11 2023/01/23 14:04:42 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.54.2.12 2023/10/08 15:13:09 martin Exp $ */
 
 /******************************************************************************
 
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.54.2.11 2023/01/23 14:04:42 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.54.2.12 2023/10/08 15:13:09 martin Exp $");
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -1341,11 +1341,6 @@ ixgbe_setup_hw_rsc(struct rx_ring *rxr)
  *      exhaustion are unnecessary, if an mbuf cannot be obtained
  *      it just returns, keeping its placeholder, thus it can simply
  *      be recalled to try again.
- *
- *   XXX NetBSD TODO:
- *    - The ixgbe_rxeof() function always preallocates mbuf cluster,
- *      so the ixgbe_refresh_mbufs() function can be simplified.
- *
  ************************************************************************/
 static void
 ixgbe_refresh_mbufs(struct rx_ring *rxr, int limit)

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.199.2.26 src/sys/dev/pci/ixgbe/ixgbe.c:1.199.2.27
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.199.2.26	Wed Jun 21 19:20:50 2023
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Sun Oct  8 15:13:09 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.199.2.26 2023/06/21 19:20:50 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.199.2.27 2023/10/08 15:13:09 martin Exp $ */
 
 /******************************************************************************
 
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ixgbe.c,v 1.199.2.26 2023/06/21 19:20:50 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ixgbe.c,v 1.199.2.27 2023/10/08 15:13:09 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1593,8 +1593,19 @@ ixgbe_update_stats_counters(struct adapt
 	for (i = 0; i < queue_counters; i++) {
 		IXGBE_EVC_REGADD(hw, stats, IXGBE_QPRC(i), qprc[i]);
 		IXGBE_EVC_REGADD(hw, stats, IXGBE_QPTC(i), qptc[i]);
-		if (hw->mac.type >= ixgbe_mac_82599EB)
+		if (hw->mac.type >= ixgbe_mac_82599EB) {
+			IXGBE_EVC_ADD(&stats->qbrc[i],
+			    IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)) +
+			    ((u64)IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)) << 32));
+			IXGBE_EVC_ADD(&stats->qbtc[i],
+			    IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)) +
+			    ((u64)IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)) << 32));
 			IXGBE_EVC_REGADD(hw, stats, IXGBE_QPRDC(i), qprdc[i]);
+		} else {
+			/* 82598 */
+			IXGBE_EVC_REGADD(hw, stats, IXGBE_QBRC(i), qbrc[i]);
+			IXGBE_EVC_REGADD(hw, stats, IXGBE_QBTC(i), qbtc[i]);
+		}
 	}
 
 	/* 8 registers exist */
@@ -1805,28 +1816,28 @@ ixgbe_add_hw_stats(struct adapter *adapt
 		if (i < __arraycount(stats->pxontxc)) {
 			evcnt_attach_dynamic(&stats->pxontxc[i],
 			    EVCNT_TYPE_MISC, NULL, adapter->tcs[i].evnamebuf,
-			    "pxontxc");
-			evcnt_attach_dynamic(&stats->pxonrxc[i],
-			    EVCNT_TYPE_MISC, NULL, adapter->tcs[i].evnamebuf,
-			    "pxonrxc");
+			    "Priority XON Transmitted");
 			evcnt_attach_dynamic(&stats->pxofftxc[i],
 			    EVCNT_TYPE_MISC, NULL, adapter->tcs[i].evnamebuf,
-			    "pxofftxc");
-			evcnt_attach_dynamic(&stats->pxoffrxc[i],
-			    EVCNT_TYPE_MISC, NULL, adapter->tcs[i].evnamebuf,
-			    "pxoffrxc");
+			    "Priority XOFF Transmitted");
 			if (hw->mac.type >= ixgbe_mac_82599EB)
 				evcnt_attach_dynamic(&stats->pxon2offc[i],
 				    EVCNT_TYPE_MISC, NULL,
 				    adapter->tcs[i].evnamebuf,
-				    "pxon2offc");
+				    "Priority XON to XOFF");
+			evcnt_attach_dynamic(&stats->pxonrxc[i],
+			    EVCNT_TYPE_MISC, NULL, adapter->tcs[i].evnamebuf,
+			    "Priority XON Received");
+			evcnt_attach_dynamic(&stats->pxoffrxc[i],
+			    EVCNT_TYPE_MISC, NULL, adapter->tcs[i].evnamebuf,
+			    "Priority XOFF Received");
 		}
 	}
 
 	for (i = 0; i < adapter->num_queues; i++, rxr++, txr++) {
 #ifdef LRO
 		struct lro_ctrl *lro = &rxr->lro;
-#endif /* LRO */
+#endif
 
 		snprintf(adapter->queues[i].evnamebuf,
 		    sizeof(adapter->queues[i].evnamebuf), "%s q%d", xname, i);
@@ -1866,27 +1877,6 @@ ixgbe_add_hw_stats(struct adapter *adapt
 		    0, CTL_CREATE, CTL_EOL) != 0)
 			break;
 
-		evcnt_attach_dynamic(&adapter->queues[i].irqs, EVCNT_TYPE_INTR,
-		    NULL, adapter->queues[i].evnamebuf, "IRQs on queue");
-		evcnt_attach_dynamic(&adapter->queues[i].handleq,
-		    EVCNT_TYPE_MISC, NULL, adapter->queues[i].evnamebuf,
-		    "Handled queue in softint");
-		evcnt_attach_dynamic(&adapter->queues[i].req, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf, "Requeued in softint");
-		evcnt_attach_dynamic(&txr->tso_tx, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf, "TSO");
-		evcnt_attach_dynamic(&txr->no_desc_avail, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf,
-		    "TX Queue No Descriptor Available");
-		evcnt_attach_dynamic(&txr->total_packets, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf,
-		    "Queue Packets Transmitted");
-#ifndef IXGBE_LEGACY_TX
-		evcnt_attach_dynamic(&txr->pcq_drops, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf,
-		    "Packets dropped in pcq");
-#endif
-
 		if (sysctl_createv(log, 0, &rnode, &cnode,
 		    CTLFLAG_READONLY, CTLTYPE_INT, "rxd_nxck",
 		    SYSCTL_DESCR("Receive Descriptor next to check"),
@@ -1915,33 +1905,62 @@ ixgbe_add_hw_stats(struct adapter *adapt
 		    CTL_CREATE, CTL_EOL) != 0)
 			break;
 
-		if (i < __arraycount(stats->qprc)) {
-			evcnt_attach_dynamic(&stats->qprc[i], EVCNT_TYPE_MISC,
-			    NULL, adapter->queues[i].evnamebuf, "qprc");
+		evcnt_attach_dynamic(&adapter->queues[i].irqs, EVCNT_TYPE_INTR,
+		    NULL, adapter->queues[i].evnamebuf, "IRQs on queue");
+		evcnt_attach_dynamic(&adapter->queues[i].handleq,
+		    EVCNT_TYPE_MISC, NULL, adapter->queues[i].evnamebuf,
+		    "Handled queue in softint");
+		evcnt_attach_dynamic(&adapter->queues[i].req, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf, "Requeued in softint");
+		if (i < __arraycount(stats->qbtc))
+			evcnt_attach_dynamic(&stats->qbtc[i], EVCNT_TYPE_MISC,
+			    NULL, adapter->queues[i].evnamebuf,
+			    "Queue Bytes Transmitted (reg)");
+		evcnt_attach_dynamic(&txr->total_packets, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf,
+		    "Queue Packets Transmitted (soft)");
+		if (i < __arraycount(stats->qptc))
 			evcnt_attach_dynamic(&stats->qptc[i], EVCNT_TYPE_MISC,
-			    NULL, adapter->queues[i].evnamebuf, "qptc");
+			    NULL, adapter->queues[i].evnamebuf,
+			    "Queue Packets Transmitted (reg)");
+#ifndef IXGBE_LEGACY_TX
+		evcnt_attach_dynamic(&txr->pcq_drops, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf,
+		    "Packets dropped in pcq");
+#endif
+		evcnt_attach_dynamic(&txr->no_desc_avail, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf,
+		    "TX Queue No Descriptor Available");
+		evcnt_attach_dynamic(&txr->tso_tx, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf, "TSO");
+
+		evcnt_attach_dynamic(&rxr->rx_bytes, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf,
+		    "Queue Bytes Received (soft)");
+		if (i < __arraycount(stats->qbrc))
 			evcnt_attach_dynamic(&stats->qbrc[i], EVCNT_TYPE_MISC,
-			    NULL, adapter->queues[i].evnamebuf, "qbrc");
-			evcnt_attach_dynamic(&stats->qbtc[i], EVCNT_TYPE_MISC,
-			    NULL, adapter->queues[i].evnamebuf, "qbtc");
-			if (hw->mac.type >= ixgbe_mac_82599EB)
+			    NULL, adapter->queues[i].evnamebuf,
+			    "Queue Bytes Received (reg)");
+		evcnt_attach_dynamic(&rxr->rx_packets, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf,
+		    "Queue Packets Received (soft)");
+		if (i < __arraycount(stats->qprc))
+			evcnt_attach_dynamic(&stats->qprc[i], EVCNT_TYPE_MISC,
+			    NULL, adapter->queues[i].evnamebuf,
+			    "Queue Packets Received (reg)");
+		if ((i < __arraycount(stats->qprdc)) &&
+		    (hw->mac.type >= ixgbe_mac_82599EB))
 				evcnt_attach_dynamic(&stats->qprdc[i],
 				    EVCNT_TYPE_MISC, NULL,
-				    adapter->queues[i].evnamebuf, "qprdc");
-		}
+				    adapter->queues[i].evnamebuf,
+				    "Queue Packets Received Drop");
 
-		evcnt_attach_dynamic(&rxr->rx_packets, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf,
-		    "Queue Packets Received");
-		evcnt_attach_dynamic(&rxr->rx_bytes, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf,
-		    "Queue Bytes Received");
-		evcnt_attach_dynamic(&rxr->rx_copies, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf, "Copied RX Frames");
 		evcnt_attach_dynamic(&rxr->no_mbuf, EVCNT_TYPE_MISC,
 		    NULL, adapter->queues[i].evnamebuf, "Rx no mbuf");
 		evcnt_attach_dynamic(&rxr->rx_discarded, EVCNT_TYPE_MISC,
 		    NULL, adapter->queues[i].evnamebuf, "Rx discarded");
+		evcnt_attach_dynamic(&rxr->rx_copies, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf, "Copied RX Frames");
 #ifdef LRO
 		SYSCTL_ADD_INT(ctx, queue_list, OID_AUTO, "lro_queued",
 				CTLFLAG_RD, &lro->lro_queued, 0,
@@ -1994,10 +2013,10 @@ ixgbe_add_hw_stats(struct adapter *adapt
 	    stats->namebuf, "Receive Length Errors");
 	evcnt_attach_dynamic(&stats->lxontxc, EVCNT_TYPE_MISC, NULL,
 	    stats->namebuf, "Link XON Transmitted");
-	evcnt_attach_dynamic(&stats->lxonrxc, EVCNT_TYPE_MISC, NULL,
-	    stats->namebuf, "Link XON Received");
 	evcnt_attach_dynamic(&stats->lxofftxc, EVCNT_TYPE_MISC, NULL,
 	    stats->namebuf, "Link XOFF Transmitted");
+	evcnt_attach_dynamic(&stats->lxonrxc, EVCNT_TYPE_MISC, NULL,
+	    stats->namebuf, "Link XON Received");
 	evcnt_attach_dynamic(&stats->lxoffrxc, EVCNT_TYPE_MISC, NULL,
 	    stats->namebuf, "Link XOFF Received");
 
@@ -2113,12 +2132,12 @@ ixgbe_clear_evcnt(struct adapter *adapte
 		IXGBE_EVC_STORE(&adapter->queues[i].irqs, 0);
 		IXGBE_EVC_STORE(&adapter->queues[i].handleq, 0);
 		IXGBE_EVC_STORE(&adapter->queues[i].req, 0);
-		IXGBE_EVC_STORE(&txr->no_desc_avail, 0);
 		IXGBE_EVC_STORE(&txr->total_packets, 0);
-		IXGBE_EVC_STORE(&txr->tso_tx, 0);
 #ifndef IXGBE_LEGACY_TX
 		IXGBE_EVC_STORE(&txr->pcq_drops, 0);
 #endif
+		IXGBE_EVC_STORE(&txr->no_desc_avail, 0);
+		IXGBE_EVC_STORE(&txr->tso_tx, 0);
 		txr->q_efbig_tx_dma_setup = 0;
 		txr->q_mbuf_defrag_failed = 0;
 		txr->q_efbig2_tx_dma_setup = 0;
@@ -3738,12 +3757,12 @@ ixgbe_detach(device_t dev, int flags)
 		evcnt_detach(&adapter->queues[i].irqs);
 		evcnt_detach(&adapter->queues[i].handleq);
 		evcnt_detach(&adapter->queues[i].req);
-		evcnt_detach(&txr->no_desc_avail);
 		evcnt_detach(&txr->total_packets);
-		evcnt_detach(&txr->tso_tx);
 #ifndef IXGBE_LEGACY_TX
 		evcnt_detach(&txr->pcq_drops);
 #endif
+		evcnt_detach(&txr->no_desc_avail);
+		evcnt_detach(&txr->tso_tx);
 
 		if (i < __arraycount(stats->qprc)) {
 			evcnt_detach(&stats->qprc[i]);
@@ -4488,8 +4507,6 @@ ixgbe_set_rxfilter(struct adapter *adapt
 	} else
 		fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
 
-	IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
-
 	/* Update multicast filter entries only when it's not ALLMULTI */
 	if ((ec->ec_flags & ETHER_F_ALLMULTI) == 0) {
 		ETHER_UNLOCK(ec);
@@ -4498,6 +4515,8 @@ ixgbe_set_rxfilter(struct adapter *adapt
 		    ixgbe_mc_array_itr, TRUE);
 	} else
 		ETHER_UNLOCK(ec);
+
+	IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
 } /* ixgbe_set_rxfilter */
 
 /************************************************************************

Index: src/sys/dev/pci/ixgbe/ixgbe.h
diff -u src/sys/dev/pci/ixgbe/ixgbe.h:1.56.2.9 src/sys/dev/pci/ixgbe/ixgbe.h:1.56.2.10
--- src/sys/dev/pci/ixgbe/ixgbe.h:1.56.2.9	Thu Jun  2 10:45:12 2022
+++ src/sys/dev/pci/ixgbe/ixgbe.h	Sun Oct  8 15:13:09 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.h,v 1.56.2.9 2022/06/02 10:45:12 martin Exp $ */
+/* $NetBSD: ixgbe.h,v 1.56.2.10 2023/10/08 15:13:09 martin Exp $ */
 
 /******************************************************************************
   SPDX-License-Identifier: BSD-3-Clause
@@ -390,10 +390,10 @@ struct tx_ring {
 	u64			bytes;  /* Used for AIM */
 	u64			packets;
 	/* Soft Stats */
-	struct evcnt		tso_tx;
-	struct evcnt		no_desc_avail;
 	struct evcnt		total_packets;
 	struct evcnt		pcq_drops;
+	struct evcnt		no_desc_avail;
+	struct evcnt		tso_tx;
 	/* Per queue conters.  The adapter total is in struct adapter */
 	u64              q_efbig_tx_dma_setup;
 	u64              q_mbuf_defrag_failed;
@@ -507,6 +507,7 @@ struct adapter {
 	u16			num_segs;
 	u32			link_speed;
 	bool			link_up;
+	bool                    link_enabled;
 	u32			vector;
 	u16			dmac;
 	u32			phy_layer;

Index: src/sys/dev/pci/ixgbe/ixgbe_82599.c
diff -u src/sys/dev/pci/ixgbe/ixgbe_82599.c:1.21.4.4 src/sys/dev/pci/ixgbe/ixgbe_82599.c:1.21.4.5
--- src/sys/dev/pci/ixgbe/ixgbe_82599.c:1.21.4.4	Mon Jan 31 17:36:25 2022
+++ src/sys/dev/pci/ixgbe/ixgbe_82599.c	Sun Oct  8 15:13:09 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_82599.c,v 1.21.4.4 2022/01/31 17:36:25 martin Exp $ */
+/* $NetBSD: ixgbe_82599.c,v 1.21.4.5 2023/10/08 15:13:09 martin Exp $ */
 
 /******************************************************************************
   SPDX-License-Identifier: BSD-3-Clause
@@ -36,7 +36,7 @@
 /*$FreeBSD: head/sys/dev/ixgbe/ixgbe_82599.c 331224 2018-03-19 20:55:05Z erj $*/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ixgbe_82599.c,v 1.21.4.4 2022/01/31 17:36:25 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ixgbe_82599.c,v 1.21.4.5 2023/10/08 15:13:09 martin Exp $");
 
 #include "ixgbe_type.h"
 #include "ixgbe_82599.h"
@@ -1829,7 +1829,7 @@ s32 ixgbe_fdir_set_input_mask_82599(stru
 
 		switch (input_mask->formatted.tunnel_type & 0xFFFF) {
 		case 0x0:
-			/* Mask turnnel type, fall through */
+			/* Mask tunnel type, fall through */
 			fdirip6m |= IXGBE_FDIRIP6M_TUNNEL_TYPE;
 		case 0xFFFF:
 			break;

Index: src/sys/dev/pci/ixgbe/ixgbe_mbx.h
diff -u src/sys/dev/pci/ixgbe/ixgbe_mbx.h:1.14.2.2 src/sys/dev/pci/ixgbe/ixgbe_mbx.h:1.14.2.3
--- src/sys/dev/pci/ixgbe/ixgbe_mbx.h:1.14.2.2	Mon Jan 31 17:36:25 2022
+++ src/sys/dev/pci/ixgbe/ixgbe_mbx.h	Sun Oct  8 15:13:10 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_mbx.h,v 1.14.2.2 2022/01/31 17:36:25 martin Exp $ */
+/* $NetBSD: ixgbe_mbx.h,v 1.14.2.3 2023/10/08 15:13:10 martin Exp $ */
 
 /******************************************************************************
   SPDX-License-Identifier: BSD-3-Clause
@@ -156,6 +156,7 @@ enum ixgbe_pfvf_api_rev {
 #define IXGBE_VF_GET_RETA      0x0a    /* VF request for RETA */
 #define IXGBE_VF_GET_RSS_KEY	0x0b    /* get RSS key */
 #define IXGBE_VF_UPDATE_XCAST_MODE	0x0c
+#define IXGBE_VF_GET_LINK_STATE 0x10 /* get vf link state */
 
 /* mode choices for IXGBE_VF_UPDATE_XCAST_MODE */
 enum ixgbevf_xcast_modes {

Index: src/sys/dev/pci/ixgbe/ixgbe_type.h
diff -u src/sys/dev/pci/ixgbe/ixgbe_type.h:1.41.2.8 src/sys/dev/pci/ixgbe/ixgbe_type.h:1.41.2.9
--- src/sys/dev/pci/ixgbe/ixgbe_type.h:1.41.2.8	Wed Jun 21 19:20:51 2023
+++ src/sys/dev/pci/ixgbe/ixgbe_type.h	Sun Oct  8 15:13:09 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_type.h,v 1.41.2.8 2023/06/21 19:20:51 martin Exp $ */
+/* $NetBSD: ixgbe_type.h,v 1.41.2.9 2023/10/08 15:13:09 martin Exp $ */
 
 /******************************************************************************
   SPDX-License-Identifier: BSD-3-Clause
@@ -4076,6 +4076,7 @@ struct ixgbe_mac_operations {
 	s32 (*update_mc_addr_list)(struct ixgbe_hw *, u8 *, u32,
 				   ixgbe_mc_addr_itr, bool clear);
 	s32 (*update_xcast_mode)(struct ixgbe_hw *, int);
+	s32 (*get_link_state)(struct ixgbe_hw *hw, bool *link_state);
 	s32 (*enable_mc)(struct ixgbe_hw *);
 	s32 (*disable_mc)(struct ixgbe_hw *);
 	s32 (*clear_vfta)(struct ixgbe_hw *);

Index: src/sys/dev/pci/ixgbe/ixgbe_vf.c
diff -u src/sys/dev/pci/ixgbe/ixgbe_vf.c:1.18.2.6 src/sys/dev/pci/ixgbe/ixgbe_vf.c:1.18.2.7
--- src/sys/dev/pci/ixgbe/ixgbe_vf.c:1.18.2.6	Mon Jan 31 17:36:25 2022
+++ src/sys/dev/pci/ixgbe/ixgbe_vf.c	Sun Oct  8 15:13:09 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_vf.c,v 1.18.2.6 2022/01/31 17:36:25 martin Exp $ */
+/* $NetBSD: ixgbe_vf.c,v 1.18.2.7 2023/10/08 15:13:09 martin Exp $ */
 
 /******************************************************************************
   SPDX-License-Identifier: BSD-3-Clause
@@ -36,7 +36,7 @@
 /*$FreeBSD: head/sys/dev/ixgbe/ixgbe_vf.c 331224 2018-03-19 20:55:05Z erj $*/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ixgbe_vf.c,v 1.18.2.6 2022/01/31 17:36:25 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ixgbe_vf.c,v 1.18.2.7 2023/10/08 15:13:09 martin Exp $");
 
 #include "ixgbe_api.h"
 #include "ixgbe_type.h"
@@ -85,6 +85,7 @@ s32 ixgbe_init_ops_vf(struct ixgbe_hw *h
 	hw->mac.ops.init_rx_addrs = NULL;
 	hw->mac.ops.update_mc_addr_list = ixgbe_update_mc_addr_list_vf;
 	hw->mac.ops.update_xcast_mode = ixgbevf_update_xcast_mode;
+	hw->mac.ops.get_link_state = ixgbe_get_link_state_vf;
 	hw->mac.ops.enable_mc = NULL;
 	hw->mac.ops.disable_mc = NULL;
 	hw->mac.ops.clear_vfta = NULL;
@@ -497,6 +498,34 @@ s32 ixgbevf_update_xcast_mode(struct ixg
 }
 
 /**
+ * ixgbe_get_link_state_vf - Get VF link state from PF
+ * @hw: pointer to the HW structure
+ * @link_state: link state storage
+ *
+ * Returns state of the operation error or success.
+ **/
+s32 ixgbe_get_link_state_vf(struct ixgbe_hw *hw, bool *link_state)
+{
+	u32 msgbuf[2];
+	s32 err;
+	s32 ret_val;
+
+	msgbuf[0] = IXGBE_VF_GET_LINK_STATE;
+	msgbuf[1] = 0x0;
+
+	err = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
+
+	if (err || (msgbuf[0] & IXGBE_VT_MSGTYPE_FAILURE)) {
+		ret_val = IXGBE_ERR_MBX;
+	} else {
+		ret_val = IXGBE_SUCCESS;
+		*link_state = msgbuf[1];
+	}
+
+	return ret_val;
+}
+
+/**
  * ixgbe_set_vfta_vf - Set/Unset vlan filter table address
  * @hw: pointer to the HW structure
  * @vlan: 12 bit VLAN ID
@@ -624,7 +653,9 @@ s32 ixgbe_check_mac_link_vf(struct ixgbe
 	struct ixgbe_mbx_info *mbx = &hw->mbx;
 	struct ixgbe_mac_info *mac = &hw->mac;
 	s32 ret_val = IXGBE_SUCCESS;
+	u32 in_msg = 0;
 	u32 links_reg;
+
 	UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
 
 	/* If we were hit with a reset drop the link */
@@ -682,27 +713,26 @@ s32 ixgbe_check_mac_link_vf(struct ixgbe
 		*speed = IXGBE_LINK_SPEED_UNKNOWN;
 	}
 
-	if (hw->api_version < ixgbe_mbox_api_15) {
-		u32 in_msg = 0;
-
-		/* if the read failed it could just be a mailbox collision, best wait
-		 * until we are called again and don't report an error
-		 */
-		if (ixgbe_read_mbx(hw, &in_msg, 1, 0))
-			goto out;
+	/* if the read failed it could just be a mailbox collision, best wait
+	 * until we are called again and don't report an error
+	 */
+	if (ixgbe_read_mbx(hw, &in_msg, 1, 0)) {
+		if (hw->api_version >= ixgbe_mbox_api_15)
+			mac->get_link_status = FALSE;
+		goto out;
+	}
 
-		if (!(in_msg & IXGBE_VT_MSGTYPE_CTS)) {
-			/* msg is not CTS and is NACK we must have lost CTS status */
-			if (in_msg & IXGBE_VT_MSGTYPE_FAILURE)
-				ret_val = IXGBE_ERR_MBX;
-			goto out;
-		}
+	if (!(in_msg & IXGBE_VT_MSGTYPE_CTS)) {
+		/* msg is not CTS and is NACK we must have lost CTS status */
+		if (in_msg & IXGBE_VT_MSGTYPE_FAILURE)
+			ret_val = IXGBE_ERR_MBX;
+		goto out;
+	}
 
-		/* the pf is talking, if we timed out in the past we reinit */
-		if (!mbx->timeout) {
-			ret_val = IXGBE_ERR_TIMEOUT;
-			goto out;
-		}
+	/* the pf is talking, if we timed out in the past we reinit */
+	if (!mbx->timeout) {
+		ret_val = IXGBE_ERR_TIMEOUT;
+		goto out;
 	}
 
 	/* if we passed all the tests above then the link is up and we no

Index: src/sys/dev/pci/ixgbe/ixgbe_vf.h
diff -u src/sys/dev/pci/ixgbe/ixgbe_vf.h:1.13.8.3 src/sys/dev/pci/ixgbe/ixgbe_vf.h:1.13.8.4
--- src/sys/dev/pci/ixgbe/ixgbe_vf.h:1.13.8.3	Sun Jan 30 15:58:29 2022
+++ src/sys/dev/pci/ixgbe/ixgbe_vf.h	Sun Oct  8 15:13:09 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_vf.h,v 1.13.8.3 2022/01/30 15:58:29 martin Exp $ */
+/* $NetBSD: ixgbe_vf.h,v 1.13.8.4 2023/10/08 15:13:09 martin Exp $ */
 
 /******************************************************************************
   SPDX-License-Identifier: BSD-3-Clause
@@ -133,6 +133,7 @@ s32 ixgbe_update_mc_addr_list_vf(struct 
 				 u32 mc_addr_count, ixgbe_mc_addr_itr,
 				 bool clear);
 s32 ixgbevf_update_xcast_mode(struct ixgbe_hw *hw, int xcast_mode);
+s32 ixgbe_get_link_state_vf(struct ixgbe_hw *hw, bool *link_state);
 s32 ixgbe_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
 		      bool vlan_on, bool vlvf_bypass);
 s32 ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size);

Index: src/sys/dev/pci/ixgbe/ixv.c
diff -u src/sys/dev/pci/ixgbe/ixv.c:1.125.2.21 src/sys/dev/pci/ixgbe/ixv.c:1.125.2.22
--- src/sys/dev/pci/ixgbe/ixv.c:1.125.2.21	Mon Jan 23 14:04:42 2023
+++ src/sys/dev/pci/ixgbe/ixv.c	Sun Oct  8 15:13:09 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixv.c,v 1.125.2.21 2023/01/23 14:04:42 martin Exp $ */
+/* $NetBSD: ixv.c,v 1.125.2.22 2023/10/08 15:13:09 martin Exp $ */
 
 /******************************************************************************
 
@@ -35,7 +35,7 @@
 /*$FreeBSD: head/sys/dev/ixgbe/if_ixv.c 331224 2018-03-19 20:55:05Z erj $*/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ixv.c,v 1.125.2.21 2023/01/23 14:04:42 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ixv.c,v 1.125.2.22 2023/10/08 15:13:09 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -545,6 +545,13 @@ ixv_attach(device_t parent, device_t dev
 	adapter->mta = malloc(sizeof(*adapter->mta) *
 	    IXGBE_MAX_VF_MC, M_DEVBUF, M_WAITOK);
 
+	/* Check if VF was disabled by PF */
+	error = hw->mac.ops.get_link_state(hw, &adapter->link_enabled);
+	if (error) {		
+		/* PF is not capable of controlling VF state. Enable the link. */
+		adapter->link_enabled = TRUE;
+	}
+
 	/* Do the stats setup */
 	ixv_init_stats(adapter);
 	ixv_add_stats_sysctls(adapter);
@@ -654,12 +661,12 @@ ixv_detach(device_t dev, int flags)
 		evcnt_detach(&adapter->queues[i].irqs);
 		evcnt_detach(&adapter->queues[i].handleq);
 		evcnt_detach(&adapter->queues[i].req);
-		evcnt_detach(&txr->no_desc_avail);
 		evcnt_detach(&txr->total_packets);
-		evcnt_detach(&txr->tso_tx);
 #ifndef IXGBE_LEGACY_TX
 		evcnt_detach(&txr->pcq_drops);
 #endif
+		evcnt_detach(&txr->no_desc_avail);
+		evcnt_detach(&txr->tso_tx);
 
 		evcnt_detach(&rxr->rx_packets);
 		evcnt_detach(&rxr->rx_bytes);
@@ -789,6 +796,13 @@ ixv_init_locked(struct adapter *adapter)
 	ixv_init_stats(adapter);
 
 	/* Config/Enable Link */
+	error = hw->mac.ops.get_link_state(hw, &adapter->link_enabled);
+	if (error) {		
+		/* PF is not capable of controlling VF state. Enable the link. */
+		adapter->link_enabled = TRUE;
+	} else if (adapter->link_enabled == FALSE)
+		device_printf(dev, "VF is disabled by PF\n");
+
 	hw->mac.get_link_status = TRUE;
 	hw->mac.ops.check_link(hw, &adapter->link_speed, &adapter->link_up,
 	    FALSE);
@@ -1370,7 +1384,7 @@ ixv_update_link_status(struct adapter *a
 
 	KASSERT(mutex_owned(&adapter->core_mtx));
 
-	if (adapter->link_up) {
+	if (adapter->link_up && adapter->link_enabled) {
 		if (adapter->link_active != LINK_STATE_UP) {
 			if (bootverbose) {
 				const char *bpsmsg;
@@ -2594,6 +2608,10 @@ ixv_add_stats_sysctls(struct adapter *ad
 	    NULL, xname, "Admin MSI-X IRQ Handled");
 
 	for (int i = 0; i < adapter->num_queues; i++, rxr++, txr++) {
+#ifdef LRO
+		struct lro_ctrl *lro = &rxr->lro;
+#endif
+
 		snprintf(adapter->queues[i].evnamebuf,
 		    sizeof(adapter->queues[i].evnamebuf), "%s q%d", xname, i);
 		snprintf(adapter->queues[i].namebuf,
@@ -2632,31 +2650,6 @@ ixv_add_stats_sysctls(struct adapter *ad
 		    0, CTL_CREATE, CTL_EOL) != 0)
 			break;
 
-		evcnt_attach_dynamic(&adapter->queues[i].irqs, EVCNT_TYPE_INTR,
-		    NULL, adapter->queues[i].evnamebuf, "IRQs on queue");
-		evcnt_attach_dynamic(&adapter->queues[i].handleq,
-		    EVCNT_TYPE_MISC, NULL, adapter->queues[i].evnamebuf,
-		    "Handled queue in softint");
-		evcnt_attach_dynamic(&adapter->queues[i].req, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf, "Requeued in softint");
-		evcnt_attach_dynamic(&txr->tso_tx, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf, "TSO");
-		evcnt_attach_dynamic(&txr->no_desc_avail, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf,
-		    "TX Queue No Descriptor Available");
-		evcnt_attach_dynamic(&txr->total_packets, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf,
-		    "Queue Packets Transmitted");
-#ifndef IXGBE_LEGACY_TX
-		evcnt_attach_dynamic(&txr->pcq_drops, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf,
-		    "Packets dropped in pcq");
-#endif
-
-#ifdef LRO
-		struct lro_ctrl *lro = &rxr->lro;
-#endif /* LRO */
-
 		if (sysctl_createv(log, 0, &rnode, &cnode,
 		    CTLFLAG_READONLY, CTLTYPE_INT, "rxd_nxck",
 		    SYSCTL_DESCR("Receive Descriptor next to check"),
@@ -2685,18 +2678,39 @@ ixv_add_stats_sysctls(struct adapter *ad
 		    CTL_CREATE, CTL_EOL) != 0)
 			break;
 
-		evcnt_attach_dynamic(&rxr->rx_packets, EVCNT_TYPE_MISC,
+		evcnt_attach_dynamic(&adapter->queues[i].irqs, EVCNT_TYPE_INTR,
+		    NULL, adapter->queues[i].evnamebuf, "IRQs on queue");
+		evcnt_attach_dynamic(&adapter->queues[i].handleq,
+		    EVCNT_TYPE_MISC, NULL, adapter->queues[i].evnamebuf,
+		    "Handled queue in softint");
+		evcnt_attach_dynamic(&adapter->queues[i].req, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf, "Requeued in softint");
+		evcnt_attach_dynamic(&txr->total_packets, EVCNT_TYPE_MISC,
 		    NULL, adapter->queues[i].evnamebuf,
-		    "Queue Packets Received");
+		    "Queue Packets Transmitted");
+#ifndef IXGBE_LEGACY_TX
+		evcnt_attach_dynamic(&txr->pcq_drops, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf,
+		    "Packets dropped in pcq");
+#endif
+		evcnt_attach_dynamic(&txr->no_desc_avail, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf,
+		    "TX Queue No Descriptor Available");
+		evcnt_attach_dynamic(&txr->tso_tx, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf, "TSO");
+
 		evcnt_attach_dynamic(&rxr->rx_bytes, EVCNT_TYPE_MISC,
 		    NULL, adapter->queues[i].evnamebuf,
 		    "Queue Bytes Received");
-		evcnt_attach_dynamic(&rxr->rx_copies, EVCNT_TYPE_MISC,
-		    NULL, adapter->queues[i].evnamebuf, "Copied RX Frames");
+		evcnt_attach_dynamic(&rxr->rx_packets, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf,
+		    "Queue Packets Received");
 		evcnt_attach_dynamic(&rxr->no_mbuf, EVCNT_TYPE_MISC,
 		    NULL, adapter->queues[i].evnamebuf, "Rx no mbuf");
 		evcnt_attach_dynamic(&rxr->rx_discarded, EVCNT_TYPE_MISC,
 		    NULL, adapter->queues[i].evnamebuf, "Rx discarded");
+		evcnt_attach_dynamic(&rxr->rx_copies, EVCNT_TYPE_MISC,
+		    NULL, adapter->queues[i].evnamebuf, "Copied RX Frames");
 #ifdef LRO
 		SYSCTL_ADD_INT(ctx, queue_list, OID_AUTO, "lro_queued",
 				CTLFLAG_RD, &lro->lro_queued, 0,
@@ -2772,12 +2786,12 @@ ixv_clear_evcnt(struct adapter *adapter)
 		IXGBE_EVC_STORE(&adapter->queues[i].irqs, 0);
 		IXGBE_EVC_STORE(&adapter->queues[i].handleq, 0);
 		IXGBE_EVC_STORE(&adapter->queues[i].req, 0);
-		IXGBE_EVC_STORE(&txr->tso_tx, 0);
-		IXGBE_EVC_STORE(&txr->no_desc_avail, 0);
 		IXGBE_EVC_STORE(&txr->total_packets, 0);
 #ifndef IXGBE_LEGACY_TX
 		IXGBE_EVC_STORE(&txr->pcq_drops, 0);
 #endif
+		IXGBE_EVC_STORE(&txr->no_desc_avail, 0);
+		IXGBE_EVC_STORE(&txr->tso_tx, 0);
 		txr->q_efbig_tx_dma_setup = 0;
 		txr->q_mbuf_defrag_failed = 0;
 		txr->q_efbig2_tx_dma_setup = 0;

Reply via email to