Module Name:    src
Committed By:   msaitoh
Date:           Fri Oct  6 14:34:23 UTC 2023

Modified Files:
        src/sys/dev/pci/ixgbe: ixgbe.h ixgbe_mbx.h ixgbe_type.h ixgbe_vf.c
            ixgbe_vf.h ixv.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/pci/ixgbe/ixgbe_mbx.h
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/pci/ixgbe/ixgbe_type.h
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/pci/ixgbe/ixgbe_vf.c
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/pci/ixgbe/ixgbe_vf.h
cvs rdiff -u -r1.184 -r1.185 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/ixgbe.h
diff -u src/sys/dev/pci/ixgbe/ixgbe.h:1.87 src/sys/dev/pci/ixgbe/ixgbe.h:1.88
--- src/sys/dev/pci/ixgbe/ixgbe.h:1.87	Wed Sep 13 07:28:51 2023
+++ src/sys/dev/pci/ixgbe/ixgbe.h	Fri Oct  6 14:34:23 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.h,v 1.87 2023/09/13 07:28:51 msaitoh Exp $ */
+/* $NetBSD: ixgbe.h,v 1.88 2023/10/06 14:34:23 msaitoh Exp $ */
 
 /******************************************************************************
   SPDX-License-Identifier: BSD-3-Clause
@@ -511,6 +511,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_mbx.h
diff -u src/sys/dev/pci/ixgbe/ixgbe_mbx.h:1.19 src/sys/dev/pci/ixgbe/ixgbe_mbx.h:1.20
--- src/sys/dev/pci/ixgbe/ixgbe_mbx.h:1.19	Fri Dec 24 05:11:04 2021
+++ src/sys/dev/pci/ixgbe/ixgbe_mbx.h	Fri Oct  6 14:34:23 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_mbx.h,v 1.19 2021/12/24 05:11:04 msaitoh Exp $ */
+/* $NetBSD: ixgbe_mbx.h,v 1.20 2023/10/06 14:34:23 msaitoh 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.56 src/sys/dev/pci/ixgbe/ixgbe_type.h:1.57
--- src/sys/dev/pci/ixgbe/ixgbe_type.h:1.56	Mon May 15 08:01:22 2023
+++ src/sys/dev/pci/ixgbe/ixgbe_type.h	Fri Oct  6 14:34:23 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_type.h,v 1.56 2023/05/15 08:01:22 msaitoh Exp $ */
+/* $NetBSD: ixgbe_type.h,v 1.57 2023/10/06 14:34:23 msaitoh 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.32 src/sys/dev/pci/ixgbe/ixgbe_vf.c:1.33
--- src/sys/dev/pci/ixgbe/ixgbe_vf.c:1.32	Fri Oct  6 14:32:05 2023
+++ src/sys/dev/pci/ixgbe/ixgbe_vf.c	Fri Oct  6 14:34:23 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_vf.c,v 1.32 2023/10/06 14:32:05 msaitoh Exp $ */
+/* $NetBSD: ixgbe_vf.c,v 1.33 2023/10/06 14:34:23 msaitoh 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.32 2023/10/06 14:32:05 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ixgbe_vf.c,v 1.33 2023/10/06 14:34:23 msaitoh 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

Index: src/sys/dev/pci/ixgbe/ixgbe_vf.h
diff -u src/sys/dev/pci/ixgbe/ixgbe_vf.h:1.17 src/sys/dev/pci/ixgbe/ixgbe_vf.h:1.18
--- src/sys/dev/pci/ixgbe/ixgbe_vf.h:1.17	Mon Jan 24 01:50:19 2022
+++ src/sys/dev/pci/ixgbe/ixgbe_vf.h	Fri Oct  6 14:34:23 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_vf.h,v 1.17 2022/01/24 01:50:19 msaitoh Exp $ */
+/* $NetBSD: ixgbe_vf.h,v 1.18 2023/10/06 14:34:23 msaitoh 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.184 src/sys/dev/pci/ixgbe/ixv.c:1.185
--- src/sys/dev/pci/ixgbe/ixv.c:1.184	Wed Sep 13 07:28:51 2023
+++ src/sys/dev/pci/ixgbe/ixv.c	Fri Oct  6 14:34:23 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: ixv.c,v 1.184 2023/09/13 07:28:51 msaitoh Exp $ */
+/* $NetBSD: ixv.c,v 1.185 2023/10/06 14:34:23 msaitoh 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.184 2023/09/13 07:28:51 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ixv.c,v 1.185 2023/10/06 14:34:23 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -558,6 +558,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);
@@ -786,6 +793,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);
@@ -1382,7 +1396,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;

Reply via email to