ixgbevf: fix link speed reporting for Hyper-V E610 VFs
Subsystems (2)
PATCH v3 1/1 ixgbevf: fix link speed reporting for Hyper-V E610 VFs
When an E610 VF is running under Hyper-V, the VFLINKS register does not carry valid link speed. The existing code reads speed from VFLINKS, which does not reflect the actual negotiated speed. This results in ethtool reporting a stale or incorrect link speed.
The Hyper-V synthetic NIC exposes the actual link status through emulated PCI config space at offset 0x209 in VFLINKS register format. Read and decode link status from there when checking link on E610 VFs.
--- drivers/net/ethernet/intel/ixgbevf/vf.c | 77 +++++++++++++++++++++---- 1 file changed, 65 insertions(+), 12 deletions(-)
drivers/net/ethernet/intel/ixgbevf/vf.c +65 -12
@@ -1,14 +1,17 @@// SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 1999 - 2024 Intel Corporation. */ +#include <linux/unaligned.h> +#include "vf.h" #include "ixgbevf.h" -/* On Hyper-V, to reset, we need to read from this offset -* from the PCI config space. This is the mechanism used on -* Hyper-V to support PF/VF communication. +/* On Hyper-V the PF/VF communication is through emulated PCI config +* space. The reset and link status are exposed at the offsets below. */ -#define IXGBE_HV_RESET_OFFSET 0x201 +#define IXGBE_HV_RESET_OFFSET 0x201 +#define IXGBE_HV_LINK_STATUS_OFFSET 0x209 +#define IXGBE_HV_LINK_STATUS_SIZE 4static inline s32 ixgbevf_write_msg_read_ack (struct ixgbe_hw *hw,u32 *msg,u32 *retmsg,u16 size)
@@ -901,6 +904,34 @@ static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw,return ret_val; } +/** +* ixgbevf_hv_read_links_e610 - read link status from PCI config space +* @hw: pointer to hardware structure +* @links_reg: pointer to store read value +* +* On Hyper-V E610 VFs the VFLINKS register does not carry valid link speed. +* Instead, link status is exposed through emulated PCI config space at offset +* 0x209 in VFLINKS register format. +* +* Return: 0 on success, negative error code on failure. +*/ +static s32 ixgbevf_hv_read_links_e610 (struct ixgbe_hw *hw,u32 *links_reg) +{ +struct ixgbevf_adapter *adapter = hw->back; +u8 data[IXGBE_HV_LINK_STATUS_SIZE ]; + +for (int i =0 ; i <IXGBE_HV_LINK_STATUS_SIZE ; i++) { +int ret =pci_read_config_byte (adapter->pdev, +IXGBE_HV_LINK_STATUS_OFFSET + i, + &data[i]); +if (ret) +return pcibios_err_to_errno (ret); + } + + *links_reg =get_unaligned_le32 (data); +return 0 ; +} +/** * ixgbevf_hv_check_mac_link_vf - check link * @hw: pointer to private hardware struct
@@ -909,6 +940,7 @@ static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw,* @autoneg_wait_to_complete: unused * * Hyper-V variant; there is no mailbox communication. +* For E610 VFs, link status is read from emulated PCI config space. */ static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
@@ -923,13 +955,28 @@ static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,if (!mbx->ops.check_for_rst (hw) || !mbx->timeout) mac->get_link_status = true; -if (!mac->get_link_status) - goto out; +/* E610 VFs always read link status from emulated PCI config space +* because VFLINKS does not carry valid speed for these devices. +* Skip get_link_status caching since PCI config reads are cheap. +*/ +if (mac->type == ixgbe_mac_e610_vf) { +if (ixgbevf_hv_read_links_e610 (hw, &links_reg)) { + *link_up = false; + *speed =IXGBE_LINK_SPEED_UNKNOWN ; +return 0 ; + } + }else { +if (!mac->get_link_status) + goto out; -/* if link status is down no point in checking to see if pf is up */ - links_reg =IXGBE_READ_REG (hw,IXGBE_VFLINKS ); -if (!(links_reg &IXGBE_LINKS_UP )) - goto out; + links_reg =IXGBE_READ_REG (hw,IXGBE_VFLINKS ); + } + +if (!(links_reg &IXGBE_LINKS_UP )) { + *link_up = false; + *speed =IXGBE_LINK_SPEED_UNKNOWN ; +return 0 ; + }/* for SFP+ modules and DA cables on 82599 it can take up to 500usecs * before the link status is correct
@@ -941,8 +988,11 @@ static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,udelay (100 ); links_reg =IXGBE_READ_REG (hw,IXGBE_VFLINKS ); -if (!(links_reg &IXGBE_LINKS_UP )) - goto out; +if (!(links_reg &IXGBE_LINKS_UP )) { + *link_up = false; + *speed =IXGBE_LINK_SPEED_UNKNOWN ; +return 0 ; + } } }
@@ -956,6 +1006,9 @@ static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,case IXGBE_LINKS_SPEED_100_82599 : *speed =IXGBE_LINK_SPEED_100_FULL ;break ; +default : + *speed =IXGBE_LINK_SPEED_UNKNOWN ; +break ; }/* if we passed all the tests above then the link is up and we no
Signature · 1 line
2.54.0
Przemek Kitszel
maintainerQuoted 5 lines · Tomasz Lichwala
When an E610 VF is running under Hyper-V, the VFLINKS register does not carry valid link speed. The existing code reads speed from VFLINKS, which does not reflect the actual negotiated speed. This results in ethtool reporting a stale or incorrect link speed.
Quoted 8 lines
The Hyper-V synthetic NIC exposes the actual link status through emulated PCI config space at offset
0x209in VFLINKS register format. Read and decode link status from there when checking link on E610 VFs.Fixes 4c44b450c69b ("ixgbevf: Add support for Intel(R) E610 device")Reviewed-by Marcin Szycik <[email protected]>Signed-off-by Tomasz Lichwala <[email protected]>---
next time please provide changelog section here
Quoted 16 lines
drivers/net/ethernet/intel/ixgbevf/vf.c | 77 +++++++++++++++++++++---- 1 file changed, 65 insertions(+), 12 deletions(-)drivers/net/ethernet/intel/ixgbevf/vf.c +2
-0@@ -1,14 +1,17 @@// SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 1999 - 2024 Intel Corporation. */ +#include <linux/unaligned.h> +#include "vf.h" #include "ixgbevf.h"
[..]
drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw, · line 921
Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +4
-0+static s32 ixgbevf_hv_read_links_e610 (struct ixgbe_hw *hw,u32 *links_reg) +{ +struct ixgbevf_adapter *adapter = hw->back; +u8 data[IXGBE_HV_LINK_STATUS_SIZE ];
following Paul's suggestion, you could add:
if (IS_ENABLED(CONFIG_PCI_MMCONFIG)) {
dev_err_once(&adapter->pdev->dev, "cannot read link status,
PCI_MMCONFIG is required for Hyper-V\n");
return -EOPNOTSUPP;
}and this will give user more information
IS_ENABLED() is really nice macro :)
Quoted 13 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +13
-0+ +for (int i =0 ; i <IXGBE_HV_LINK_STATUS_SIZE ; i++) { +int ret =pci_read_config_byte (adapter->pdev, +IXGBE_HV_LINK_STATUS_OFFSET + i, + &data[i]); +if (ret) +return pcibios_err_to_errno (ret); + } + + *links_reg =get_unaligned_le32 (data); +return 0 ; +} +
Quoted 10 lines · Przemek Kitszel
Quoted 9 lines · Tomasz Lichwala
When an E610 VF is running under Hyper-V, the VFLINKS register does not carry valid link speed. The existing code reads speed from VFLINKS, which does not reflect the actual negotiated speed. This results in ethtool reporting a stale or incorrect link speed.
The Hyper-V synthetic NIC exposes the actual link status through emulated PCI config space at offset
0x209in VFLINKS register format. Read and decode link status from there when checking link on E610 VFs.
Quoted 7 lines
Quoted 4 lines
Fixes 4c44b450c69b ("ixgbevf: Add support for Intel(R) E610 device")Reviewed-by Marcin Szycik <[email protected]>Signed-off-by Tomasz Lichwala <[email protected]>---
next time please provide changelog section here
Noted, will include changelog in subsequent versions.
Quoted 29 lines
Quoted 15 lines
drivers/net/ethernet/intel/ixgbevf/vf.c| 77 +++++++++++++++++++++----1 file changed, 65 insertions(+), 12 deletions(-)drivers/net/ethernet/intel/ixgbevf/vf.c +0
-0@@ -1,14 +1,17 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 1999 - 2024 Intel Corporation. */+#include <
linux/unaligned.h>
+
#include "vf.h"
#include "ixgbevf.h"[..]
drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw, · line 921
Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +4
-0+static s32 ixgbevf_hv_read_links_e610 (struct ixgbe_hw *hw,u32 *links_reg) +{ + struct ixgbevf_adapter *adapter = hw->back; + u8 data[IXGBE_HV_LINK_STATUS_SIZE];following Paul's suggestion, you could add:
if (IS_ENABLED(CONFIG_PCI_MMCONFIG)) {
dev_err_once(&adapter->pdev->dev, "cannot read link status, PCI_MMCONFIG is required for Hyper-V\n"); return-EOPNOTSUPP;
}
Quoted 4 lines
and this will give user more information
IS_ENABLED()is really nice macro :)
I think you meant !IS_ENABLED() here. Without MMCONFIG, pci_read_config_byte() at offset 0x209 (extended config space) will return a PCIBIOS error anyway, and the caller handles that gracefully by reporting link down. I could add the explicit IS_ENABLED check for a friendlier diagnostic message, but the behavior is correct either way. Let me know if you'd prefer I add it in a v4.
Quoted 5 lines
Quoted 5 lines
+
+ for (int i = 0; i <IXGBE_HV_LINK_STATUS_SIZE; i++) { + int ret = pci_read_config_byte(adapter->pdev, +IXGBE_HV_LINK_STATUS_OFFSET+ i, + &data[i]);
Quoted 8 lines
drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw, · line 934
Quoted 8 lines
+ if (ret)
+ returnpcibios_err_to_errno(ret);
+ }drivers/net/ethernet/intel/ixgbevf/vf.c +5
-0+ + *links_reg = get_unaligned_le32(data); + return 0; +} +
Thanks,
Tomasz
Przemek Kitszel
maintainerQuoted 52 lines · Tomasz Lichwala
Quoted 10 lines · Przemek Kitszel
Quoted 9 lines · Tomasz Lichwala
When an E610 VF is running under Hyper-V, the VFLINKS register does not carry valid link speed. The existing code reads speed from VFLINKS, which does not reflect the actual negotiated speed. This results in ethtool reporting a stale or incorrect link speed.
The Hyper-V synthetic NIC exposes the actual link status through emulated PCI config space at offset
0x209in VFLINKS register format. Read and decode link status from there when checking link on E610 VFs.Quoted 7 lines
Quoted 4 lines
Fixes 4c44b450c69b ("ixgbevf: Add support for Intel(R) E610 device")Reviewed-by Marcin Szycik <[email protected]>Signed-off-by Tomasz Lichwala <[email protected]>---
next time please provide changelog section here
Noted, will include changelog in subsequent versions.
Quoted 29 lines
Quoted 15 lines
drivers/net/ethernet/intel/ixgbevf/vf.c | 77 +++++++++++++++++++++---- 1 file changed, 65 insertions(+), 12 deletions(-)drivers/net/ethernet/intel/ixgbevf/vf.c +1
-0@@ -1,14 +1,17 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 1999 - 2024 Intel Corporation. */ +#include <linux/unaligned.h> + #include "vf.h" #include "ixgbevf.h"[..]
drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw, · line 921
Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +4
-0+static s32 ixgbevf_hv_read_links_e610 (struct ixgbe_hw *hw,u32 *links_reg) +{ + struct ixgbevf_adapter *adapter = hw->back; + u8 data[IXGBE_HV_LINK_STATUS_SIZE];following Paul's suggestion, you could add:
if (IS_ENABLED(CONFIG_PCI_MMCONFIG)) {
dev_err_once(&adapter->pdev->dev, "cannot read link status, PCI_MMCONFIG is required for Hyper-V\n"); return-EOPNOTSUPP;
}
Quoted 6 lines
Quoted 4 lines
and this will give user more information
IS_ENABLED()is really nice macro :)I think you meant !IS_ENABLED() here.
oh yea
Without MMCONFIG, pci_read_config_byte() at offset 0x209 (extended config space) will return a PCIBIOS error anyway, and the caller handles that gracefully by reporting link down. I could add the explicit IS_ENABLED check for a friendlier diagnostic message, but the behavior is correct either way. Let me know if you'd prefer I add it in a v4.
yes, please do v4
Quoted 18 lines
Quoted 14 lines
Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +3
-0+ + for (int i = 0; i < IXGBE_HV_LINK_STATUS_SIZE; i++) { + int ret = pci_read_config_byte(adapter->pdev,drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw, · line 934
Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10
-0+ IXGBE_HV_LINK_STATUS_OFFSET + i, + &data[i]); + if (ret) + return pcibios_err_to_errno(ret); + } + + *links_reg = get_unaligned_le32(data); + return 0; +} +Thanks,
Tomasz