Module Name:    src
Committed By:   martin
Date:           Sun Oct  8 15:19:32 UTC 2023

Modified Files:
        src/sys/dev/pci/ixgbe [netbsd-8]: 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.c               1.327-1.332 via patch
        sys/dev/pci/ixgbe/ixgbe.h               1.87-1.88
        sys/dev/pci/ixgbe/ixv.c                 1.184-1.185
        sys/dev/pci/ixgbe/ix_txrx.c             1.101
        sys/dev/pci/ixgbe/ixgbe_82599.c         1.30
        sys/dev/pci/ixgbe/ixgbe_vf.c            1.32-1.33
        sys/dev/pci/ixgbe/ixgbe_vf.h            1.18
        sys/dev/pci/ixgbe/ixgbe_mbx.h           1.20
        sys/dev/pci/ixgbe/ixgbe_type.h          1.57

- Reorder some event counters for readability.
- Rename some descriptions of event counters.
- Count Queue Bytes {Transmit, Receive} counter.
- Improve error check in ixgbe_check_mac_link_vf().
- Add new IXGBE_VF_GET_LINK_STATE message support.
  The VF's link state can be forced to down by PF.
- Update FCTRL after writing multicast filter.
- Update comments.


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.27 -r1.24.2.28 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.55 -r1.88.2.56 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.26 -r1.24.6.27 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.14.8.9 -r1.14.8.10 src/sys/dev/pci/ixgbe/ixgbe_82599.c
cvs rdiff -u -r1.10.8.5 -r1.10.8.6 src/sys/dev/pci/ixgbe/ixgbe_mbx.h
cvs rdiff -u -r1.22.2.18 -r1.22.2.19 src/sys/dev/pci/ixgbe/ixgbe_type.h
cvs rdiff -u -r1.12.8.9 -r1.12.8.10 src/sys/dev/pci/ixgbe/ixgbe_vf.c
cvs rdiff -u -r1.8.6.6 -r1.8.6.7 src/sys/dev/pci/ixgbe/ixgbe_vf.h
cvs rdiff -u -r1.56.2.40 -r1.56.2.41 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.24.2.27 src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.28
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.27	Mon Jan 23 14:07:24 2023
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Sun Oct  8 15:19:31 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.24.2.27 2023/01/23 14:07:24 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.24.2.28 2023/10/08 15:19:31 martin Exp $ */
 
 /******************************************************************************
 
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.24.2.27 2023/01/23 14:07:24 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.24.2.28 2023/10/08 15:19:31 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.88.2.55 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.56
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.55	Wed Jun 21 19:28:12 2023
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Sun Oct  8 15:19:31 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.55 2023/06/21 19:28:12 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.56 2023/10/08 15:19:31 martin Exp $ */
 
 /******************************************************************************
 
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ixgbe.c,v 1.88.2.55 2023/06/21 19:28:12 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ixgbe.c,v 1.88.2.56 2023/10/08 15:19:31 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1601,8 +1601,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 */
@@ -1813,28 +1824,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);
@@ -1874,27 +1885,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"),
@@ -1923,33 +1913,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,
@@ -2002,10 +2021,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");
 
@@ -2121,12 +2140,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;
@@ -3700,12 +3719,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]);
@@ -4450,13 +4469,13 @@ ixgbe_set_rxfilter(struct adapter *adapt
 	} else
 		fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
 
-	IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
-
 	if (mcnt <= MAX_NUM_MULTICAST_ADDRESSES) {
 		update_ptr = (u8 *)mta;
 		ixgbe_update_mc_addr_list(&adapter->hw, update_ptr, mcnt,
 		    ixgbe_mc_array_itr, TRUE);
 	}
+
+	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.24.6.26 src/sys/dev/pci/ixgbe/ixgbe.h:1.24.6.27
--- src/sys/dev/pci/ixgbe/ixgbe.h:1.24.6.26	Fri Jun  3 12:31:10 2022
+++ src/sys/dev/pci/ixgbe/ixgbe.h	Sun Oct  8 15:19:31 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.h,v 1.24.6.26 2022/06/03 12:31:10 martin Exp $ */
+/* $NetBSD: ixgbe.h,v 1.24.6.27 2023/10/08 15:19:31 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;
@@ -506,6 +506,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.14.8.9 src/sys/dev/pci/ixgbe/ixgbe_82599.c:1.14.8.10
--- src/sys/dev/pci/ixgbe/ixgbe_82599.c:1.14.8.9	Mon Jan 31 17:38:36 2022
+++ src/sys/dev/pci/ixgbe/ixgbe_82599.c	Sun Oct  8 15:19:31 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_82599.c,v 1.14.8.9 2022/01/31 17:38:36 martin Exp $ */
+/* $NetBSD: ixgbe_82599.c,v 1.14.8.10 2023/10/08 15:19:31 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.14.8.9 2022/01/31 17:38:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ixgbe_82599.c,v 1.14.8.10 2023/10/08 15:19:31 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.10.8.5 src/sys/dev/pci/ixgbe/ixgbe_mbx.h:1.10.8.6
--- src/sys/dev/pci/ixgbe/ixgbe_mbx.h:1.10.8.5	Mon Jan 31 17:38:36 2022
+++ src/sys/dev/pci/ixgbe/ixgbe_mbx.h	Sun Oct  8 15:19:31 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_mbx.h,v 1.10.8.5 2022/01/31 17:38:36 martin Exp $ */
+/* $NetBSD: ixgbe_mbx.h,v 1.10.8.6 2023/10/08 15:19:31 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.22.2.18 src/sys/dev/pci/ixgbe/ixgbe_type.h:1.22.2.19
--- src/sys/dev/pci/ixgbe/ixgbe_type.h:1.22.2.18	Wed Jun 21 19:28:12 2023
+++ src/sys/dev/pci/ixgbe/ixgbe_type.h	Sun Oct  8 15:19:31 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_type.h,v 1.22.2.18 2023/06/21 19:28:12 martin Exp $ */
+/* $NetBSD: ixgbe_type.h,v 1.22.2.19 2023/10/08 15:19:31 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.12.8.9 src/sys/dev/pci/ixgbe/ixgbe_vf.c:1.12.8.10
--- src/sys/dev/pci/ixgbe/ixgbe_vf.c:1.12.8.9	Mon Jan 31 17:38:36 2022
+++ src/sys/dev/pci/ixgbe/ixgbe_vf.c	Sun Oct  8 15:19:32 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_vf.c,v 1.12.8.9 2022/01/31 17:38:36 martin Exp $ */
+/* $NetBSD: ixgbe_vf.c,v 1.12.8.10 2023/10/08 15:19:32 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.12.8.9 2022/01/31 17:38:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ixgbe_vf.c,v 1.12.8.10 2023/10/08 15:19:32 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.8.6.6 src/sys/dev/pci/ixgbe/ixgbe_vf.h:1.8.6.7
--- src/sys/dev/pci/ixgbe/ixgbe_vf.h:1.8.6.6	Sun Jan 30 16:06:35 2022
+++ src/sys/dev/pci/ixgbe/ixgbe_vf.h	Sun Oct  8 15:19:32 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_vf.h,v 1.8.6.6 2022/01/30 16:06:35 martin Exp $ */
+/* $NetBSD: ixgbe_vf.h,v 1.8.6.7 2023/10/08 15:19:32 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.56.2.40 src/sys/dev/pci/ixgbe/ixv.c:1.56.2.41
--- src/sys/dev/pci/ixgbe/ixv.c:1.56.2.40	Mon Jan 23 14:07:25 2023
+++ src/sys/dev/pci/ixgbe/ixv.c	Sun Oct  8 15:19:32 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixv.c,v 1.56.2.40 2023/01/23 14:07:25 martin Exp $ */
+/* $NetBSD: ixv.c,v 1.56.2.41 2023/10/08 15:19:32 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.56.2.40 2023/01/23 14:07:25 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ixv.c,v 1.56.2.41 2023/10/08 15:19:32 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -557,6 +557,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);
@@ -674,12 +681,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);
@@ -809,6 +816,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);
@@ -1383,7 +1397,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;
@@ -2525,6 +2539,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,
@@ -2563,31 +2581,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"),
@@ -2616,18 +2609,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,
@@ -2703,12 +2717,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