Skip to contentSkip to conversation

ethernet: intel: Support Hyper-V hosts

PATCH Superseded K. Y. Srinivasan 6 participants 19 messages Apr 14, 2016 – Apr 16, 2016

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover ethernet: intel: Support Hyper-V hosts

Make adjustments to the Intel 10G VF driver to support running on Hyper-V hosts.

K. Y. Srinivasan (2):
ethernet: intel: Add the device ID's presented while running on
Hyper-V
intel: ixgbevf: Support Windows hosts (Hyper-V)

 drivers/net/ethernet/intel/ixgbevf/defines.h      |    5 +
 drivers/net/ethernet/intel/ixgbevf/ixgbevf.h      |   11 ++
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c |   56 ++++++---
 drivers/net/ethernet/intel/ixgbevf/mbx.c          |   12 ++
 drivers/net/ethernet/intel/ixgbevf/vf.c           |  138 +++++++++++++++++++++
 drivers/net/ethernet/intel/ixgbevf/vf.h           |    2 +
 6 files changed, 206 insertions(+), 18 deletions(-)
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 2/2 intel: ixgbevf: Support Windows hosts (Hyper-V)

In reply to K. Y. Srinivasan

On Hyper-V, the VF/PF communication is a via software mediated path as opposed to the hardware mailbox. Make the necessary adjustments to support Hyper-V.

---
 drivers/net/ethernet/intel/ixgbevf/ixgbevf.h      |   11 ++
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c |   56 ++++++---
 drivers/net/ethernet/intel/ixgbevf/mbx.c          |   12 ++
 drivers/net/ethernet/intel/ixgbevf/vf.c           |  138 +++++++++++++++++++++
 drivers/net/ethernet/intel/ixgbevf/vf.h           |    2 +
 5 files changed, 201 insertions(+), 18 deletions(-)
drivers/net/ethernet/intel/ixgbevf/ixgbevf.h +11 -0
index 5ac60ee..f8d2a0b 100644
@@ -460,9 +460,13 @@ enum ixbgevf_state_t {
 
 enum ixgbevf_boards {
 	board_82599_vf,
+	board_82599_vf_hv,
 	board_X540_vf,
+	board_X540_vf_hv,
 	board_X550_vf,
+	board_X550_vf_hv,
 	board_X550EM_x_vf,
+	board_X550EM_x_vf_hv,
 };
 
 enum ixgbevf_xcast_modes {
@@ -477,6 +481,13 @@ extern const struct ixgbevf_info ixgbevf_X550_vf_info;
 extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_info;
 extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops;
 
+
+extern const struct ixgbevf_info ixgbevf_82599_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X540_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X550_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info;
+extern const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops;
+
 /* needed by ethtool.c */
 extern const char ixgbevf_driver_name[];
 extern const char ixgbevf_driver_version[];
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +38 -18

135 lines not on this page · raw message

drivers/net/ethernet/intel/ixgbevf/mbx.c +12 -0
index dc68fea..298a0da 100644
@@ -346,3 +346,15 @@ const struct ixgbe_mbx_operations ixgbevf_mbx_ops = {
 	.check_for_rst	= ixgbevf_check_for_rst_vf,
 };
 
+/**
+ * Mailbox operations when running on Hyper-V.
+ * On Hyper-V, PF/VF communiction is not through the
+ * hardware mailbox; this communication is through
+ * a software mediated path.
+ * Most mail box operations are noop while running on
+ * Hyper-V.
+ */
+const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops = {
+	.init_params	= ixgbevf_init_mbx_params_vf,
+	.check_for_rst	= ixgbevf_check_for_rst_vf,
+};
drivers/net/ethernet/intel/ixgbevf/vf.c +138 -0

190 lines not on this page · raw message

drivers/net/ethernet/intel/ixgbevf/vf.h +2 -0
index ef9f773..7242a97 100644
@@ -32,7 +32,9 @@
 #include <linux/interrupt.h>
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
+#include <asm/hypervisor.h>
 
+#include <asm/hypervisor.h>
 #include "defines.h"
 #include "regs.h"
 #include "mbx.h"
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/2 ethernet: intel: Add the device ID's presented while running on Hyper-V

In reply to K. Y. Srinivasan

Intel SR-IOV cards present different ID when running on Hyper-V. Add the device IDs presented while running on Hyper-V.

---
 drivers/net/ethernet/intel/ixgbevf/defines.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/net/ethernet/intel/ixgbevf/defines.h +5 -0
index 5843458..1306a0d 100644
@@ -33,6 +33,11 @@
 #define IXGBE_DEV_ID_X550_VF		0x1565
 #define IXGBE_DEV_ID_X550EM_X_VF	0x15A8
 
+#define IXGBE_DEV_ID_82599_VF_HV	0x152E
+#define IXGBE_DEV_ID_X540_VF_HV		0x1530
+#define IXGBE_DEV_ID_X550_VF_HV		0x1564
+#define IXGBE_DEV_ID_X550EM_X_VF_HV	0x15A9
+
 #define IXGBE_VF_IRQ_CLEAR_MASK		7
 #define IXGBE_VF_MAX_TX_QUEUES		8
 #define IXGBE_VF_MAX_RX_QUEUES		8
Signature · 1 line
1.7.4.1
#3 lore raw

Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

In reply to K. Y. Srinivasan
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi Srinivasan,

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/K-Y-Srinivasan/ethernet-intel-Add-the-device-ID-s-presented-while-running-on-Hyper-V/20160415-061821
config: sparc64-allyesconfig (attached as .config)

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=sparc64

All errors (new ones prefixed by >>):

drivers/net/ethernet/intel/ixgbevf/vf.c: In function 'ixgbevf_rlpml_set_vf':

>> drivers/net/ethernet/intel/ixgbevf/vf.c:754:6: error: 'x86_hyper' undeclared (first use in this function)
     if (x86_hyper == &x86_hyper_ms_hyperv) {
         ^
   drivers/net/ethernet/intel/ixgbevf/vf.c:754:6: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/net/ethernet/intel/ixgbevf/vf.c:754:20: error: 'x86_hyper_ms_hyperv' undeclared (first use in this function)
     if (x86_hyper == &x86_hyper_ms_hyperv) {
                       ^
   drivers/net/ethernet/intel/ixgbevf/vf.c: In function 'ixgbevf_negotiate_api_version':
   drivers/net/ethernet/intel/ixgbevf/vf.c:781:6: error: 'x86_hyper' undeclared (first use in this function)
     if (x86_hyper == &x86_hyper_ms_hyperv) {
         ^
   drivers/net/ethernet/intel/ixgbevf/vf.c:781:20: error: 'x86_hyper_ms_hyperv' undeclared (first use in this function)
     if (x86_hyper == &x86_hyper_ms_hyperv) {
                       ^

vim +/x86_hyper +754 drivers/net/ethernet/intel/ixgbevf/vf.c

748 **/
749 void ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
750 {
751 u32 msgbuf[2];
752 u32 reg;
753

 > 754		if (x86_hyper == &x86_hyper_ms_hyperv) {

755 /*
756 * If we are on Hyper-V, we implement
757 * this functionality differently.

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#4 lore raw

Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

In reply to K. Y. Srinivasan

Some comments below:

Quoted 12 lines · K. Y. Srinivasan

On Hyper-V, the VF/PF communication is a via software mediated path as opposed to the hardware mailbox. Make the necessary adjustments to support Hyper-V.

---
 drivers/net/ethernet/intel/ixgbevf/ixgbevf.h      |   11 ++
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c |   56 ++++++---
 drivers/net/ethernet/intel/ixgbevf/mbx.c          |   12 ++
 drivers/net/ethernet/intel/ixgbevf/vf.c           |  138 +++++++++++++++++++++
 drivers/net/ethernet/intel/ixgbevf/vf.h           |    2 +
 5 files changed, 201 insertions(+), 18 deletions(-)

<snip>

Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
index 4d613a4..92397fd 100644

<snip>

drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw) · line 142

Quoted 11 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +7 -0
@@ -126,6 +133,23 @@ static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw)
 }
 
 /**
+ * Hyper-V variant; the VF/PF communication is through the PCI
+ * config space.
+ */
+static s32 ixgbevf_hv_reset_hw_vf(struct ixgbe_hw *hw)
+{
+	int i;
+	struct ixgbevf_adapter *adapter = hw->back;

The two lines above should be swapped so that the longer one is first.

Quoted 17 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10 -0
+
+	for (i = 0; i < 6; i++)
+		pci_read_config_byte(adapter->pdev,
+				     (i + IXGBE_HV_RESET_OFFSET),
+				     &hw->mac.perm_addr[i]);
+
+	return 0;
+}
+
+/**
  *  ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
  *  @hw: pointer to hardware structure
  *
@@ -656,6 +680,68 @@ out:
 }
 
 /**

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 692

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10 -0
+ * Hyper-V variant; there is no mailbox communication.
+ */
+static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,
+					ixgbe_link_speed *speed,
+					bool *link_up,
+					bool autoneg_wait_to_complete)
+{
+	struct ixgbe_mbx_info *mbx = &hw->mbx;
+	struct ixgbe_mac_info *mac = &hw->mac;
+	s32 ret_val = 0;

ret_val here is redundant as this is the only assignment to it. Please delete it and just return 0 at the end.

Quoted 39 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +39 -0
+	u32 links_reg;
+
+	/* If we were hit with a reset drop the link */
+	if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
+		mac->get_link_status = true;
+
+	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;
+
+	/* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
+	 * before the link status is correct
+	 */
+	if (mac->type == ixgbe_mac_82599_vf) {
+		int i;
+
+		for (i = 0; i < 5; i++) {
+			udelay(100);
+			links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
+
+			if (!(links_reg & IXGBE_LINKS_UP))
+				goto out;
+		}
+	}
+
+	switch (links_reg & IXGBE_LINKS_SPEED_82599) {
+	case IXGBE_LINKS_SPEED_10G_82599:
+		*speed = IXGBE_LINK_SPEED_10GB_FULL;
+		break;
+	case IXGBE_LINKS_SPEED_1G_82599:
+		*speed = IXGBE_LINK_SPEED_1GB_FULL;
+		break;
+	case IXGBE_LINKS_SPEED_100_82599:
+		*speed = IXGBE_LINK_SPEED_100_FULL;
+		break;

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 741

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10 -0
+	}
+
+	/* if we passed all the tests above then the link is up and we no
+	 * longer need to check for link
+	 */
+	mac->get_link_status = false;
+
+out:
+	*link_up = !mac->get_link_status;
+	return ret_val;

Just return 0 above.

Quoted 6 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +3 -0
+}
+
+/**
  *  ixgbevf_rlpml_set_vf - Set the maximum receive packet length
  *  @hw: pointer to the HW structure
  *  @max_size: value to assign to max frame size

<snip>

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 756

Quoted 9 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +5 -0
@@ -663,6 +749,19 @@ out:
 void ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
 {
 	u32 msgbuf[2];
+	u32 reg;
+
+	if (x86_hyper == &x86_hyper_ms_hyperv) {
+		/*
+		 * If we are on Hyper-V, we implement

Please format the comment above netdev-style, /* If we are... as you did elsewhere.

Quoted 12 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +8 -0
+		 * this functionality differently.
+		 */
+		reg =  IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(0));
+		/* CRC == 4 */
+		reg |= ((max_size + 4) | IXGBE_RXDCTL_RLPML_EN);
+		IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(0), reg);
+		return;
+	}
 
 	msgbuf[0] = IXGBE_VF_SET_LPE;
 	msgbuf[1] = max_size;

drivers/net/ethernet/intel/ixgbevf/vf.c int ixgbevf_negotiate_api_version(struct ixgbe_hw · line 784

Quoted 7 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +3 -0
@@ -679,6 +778,16 @@ int ixgbevf_negotiate_api_version(struct ixgbe_hw  
 *hw, int api)
 	int err;
 	u32 msg[3];
 
+	if (x86_hyper == &x86_hyper_ms_hyperv) {
+		/*
+		 * Hyper-V only supports api version ixgbe_mbox_api_10

Again, please use netdev-style comment above.

Quoted 14 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +7 -0
+		 */
+		if (api != ixgbe_mbox_api_10)
+			return IXGBE_ERR_INVALID_ARGUMENT;
+
+		return 0;
+	}
+
 	/* Negotiate the mailbox API version */
 	msg[0] = IXGBE_VF_API_NEGOTIATE;
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
 	msg[1] = api;
@@ -776,22 +885,51 @@ static const struct ixgbe_mac_operations  
 ixgbevf_mac_ops = {
 	.set_vfta		= ixgbevf_set_vfta_vf,
 };

drivers/net/ethernet/intel/ixgbevf/vf.c static const struct ixgbe_mac_operations · line 897

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +9 -0
 
+static const struct ixgbe_mac_operations ixgbevf_hv_mac_ops = {
+	.init_hw		= ixgbevf_init_hw_vf,
+	.reset_hw		= ixgbevf_hv_reset_hw_vf,
+	.start_hw		= ixgbevf_start_hw_vf,
+	.get_mac_addr		= ixgbevf_get_mac_addr_vf,
+	.stop_adapter		= ixgbevf_stop_hw_vf,
+	.setup_link		= ixgbevf_setup_mac_link_vf,
+	.check_link		= ixgbevf_hv_check_mac_link_vf,
+};

Please add a blank line between these two structures as you have done elsewhere.

Quoted 44 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +20 -0
 const struct ixgbevf_info ixgbevf_82599_vf_info = {
 	.mac = ixgbe_mac_82599_vf,
 	.mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_82599_vf_hv_info = {
+	.mac = ixgbe_mac_82599_vf,
+	.mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X540_vf_info = {
 	.mac = ixgbe_mac_X540_vf,
 	.mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_X540_vf_hv_info = {
+	.mac = ixgbe_mac_X540_vf,
+	.mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X550_vf_info = {
 	.mac = ixgbe_mac_X550_vf,
 	.mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_X550_vf_hv_info = {
+	.mac = ixgbe_mac_X550_vf,
+	.mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X550EM_x_vf_info = {
 	.mac = ixgbe_mac_X550EM_x_vf,
 	.mac_ops = &ixgbevf_mac_ops,
 };
+
+const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info = {
+	.mac = ixgbe_mac_X550EM_x_vf,
+	.mac_ops = &ixgbevf_hv_mac_ops,
+};
drivers/net/ethernet/intel/ixgbevf/vf.h +0 -0
index ef9f773..7242a97 100644

drivers/net/ethernet/intel/ixgbevf/vf.h line 37

Quoted 6 lines
drivers/net/ethernet/intel/ixgbevf/vf.h +2 -0
@@ -32,7 +32,9 @@
 #include <linux/interrupt.h>
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
+#include <asm/hypervisor.h>
 
+#include <asm/hypervisor.h>

Surely you didn't mean to include the same file twice!

drivers/net/ethernet/intel/ixgbevf/vf.h line 40

Quoted 3 lines
drivers/net/ethernet/intel/ixgbevf/vf.h +0 -0
 #include "defines.h"
 #include "regs.h"
 #include "mbx.h"

--
Mark Rustad, Networking Division, Intel Corporation

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

#5 lore raw

PATCH 2/2 intel: ixgbevf: Support Windows hosts (Hyper-V)

I am resending my comments to intel-wired-lan because the original somehow trashed the address into intel-wired-lan at linuxonhyperv.com, preventing the list from getting them!

Quoted 261 lines

From: "Rustad, Mark D" <[email protected]>
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)
Date: April 14, 2016 at 4:01:16 PM PDT
To: "K. Y. Srinivasan" <[email protected]>
Cc: David Miller <[email protected]>, netdev <[email protected]>, linux-kernel at vger.kernel.org, devel at linuxdriverproject.org,
olaf at aepfle.de, apw at canonical.com, jasowang at redhat.com, eli at mellanox.com, jackm at mellanox.com, yevgenyp at mellanox.com, john.ronciak at intel.com, intel-wired-lan at linuxonhyperv.com

Some comments below:

Quoted 12 lines · K. Y. Srinivasan

On Hyper-V, the VF/PF communication is a via software mediated path as opposed to the hardware mailbox. Make the necessary adjustments to support Hyper-V.

---
 drivers/net/ethernet/intel/ixgbevf/ixgbevf.h      |   11 ++
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c |   56 ++++++---
 drivers/net/ethernet/intel/ixgbevf/mbx.c          |   12 ++
 drivers/net/ethernet/intel/ixgbevf/vf.c           |  138 +++++++++++++++++++++
 drivers/net/ethernet/intel/ixgbevf/vf.h           |    2 +
 5 files changed, 201 insertions(+), 18 deletions(-)

<snip>

Quoted 5 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
index 4d613a4..92397fd 100644

<snip>

drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw) · line 142

Quoted 11 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +7 -0
@@ -126,6 +133,23 @@ static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw)
 }
 
 /**
+ * Hyper-V variant; the VF/PF communication is through the PCI
+ * config space.
+ */
+static s32 ixgbevf_hv_reset_hw_vf(struct ixgbe_hw *hw)
+{
+	int i;
+	struct ixgbevf_adapter *adapter = hw->back;

The two lines above should be swapped so that the longer one is first.

Quoted 17 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10 -0
+
+	for (i = 0; i < 6; i++)
+		pci_read_config_byte(adapter->pdev,
+				     (i + IXGBE_HV_RESET_OFFSET),
+				     &hw->mac.perm_addr[i]);
+
+	return 0;
+}
+
+/**
  *  ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
  *  @hw: pointer to hardware structure
  *
@@ -656,6 +680,68 @@ out:
 }
 
 /**

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 692

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10 -0
+ * Hyper-V variant; there is no mailbox communication.
+ */
+static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,
+					ixgbe_link_speed *speed,
+					bool *link_up,
+					bool autoneg_wait_to_complete)
+{
+	struct ixgbe_mbx_info *mbx = &hw->mbx;
+	struct ixgbe_mac_info *mac = &hw->mac;
+	s32 ret_val = 0;

ret_val here is redundant as this is the only assignment to it. Please delete it and just return 0 at the end.

Quoted 39 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +39 -0
+	u32 links_reg;
+
+	/* If we were hit with a reset drop the link */
+	if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
+		mac->get_link_status = true;
+
+	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;
+
+	/* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
+	 * before the link status is correct
+	 */
+	if (mac->type == ixgbe_mac_82599_vf) {
+		int i;
+
+		for (i = 0; i < 5; i++) {
+			udelay(100);
+			links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
+
+			if (!(links_reg & IXGBE_LINKS_UP))
+				goto out;
+		}
+	}
+
+	switch (links_reg & IXGBE_LINKS_SPEED_82599) {
+	case IXGBE_LINKS_SPEED_10G_82599:
+		*speed = IXGBE_LINK_SPEED_10GB_FULL;
+		break;
+	case IXGBE_LINKS_SPEED_1G_82599:
+		*speed = IXGBE_LINK_SPEED_1GB_FULL;
+		break;
+	case IXGBE_LINKS_SPEED_100_82599:
+		*speed = IXGBE_LINK_SPEED_100_FULL;
+		break;

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 741

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10 -0
+	}
+
+	/* if we passed all the tests above then the link is up and we no
+	 * longer need to check for link
+	 */
+	mac->get_link_status = false;
+
+out:
+	*link_up = !mac->get_link_status;
+	return ret_val;

Just return 0 above.

Quoted 6 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +3 -0
+}
+
+/**
  *  ixgbevf_rlpml_set_vf - Set the maximum receive packet length
  *  @hw: pointer to the HW structure
  *  @max_size: value to assign to max frame size

<snip>

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 756

Quoted 9 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +5 -0
@@ -663,6 +749,19 @@ out:
 void ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
 {
 	u32 msgbuf[2];
+	u32 reg;
+
+	if (x86_hyper == &x86_hyper_ms_hyperv) {
+		/*
+		 * If we are on Hyper-V, we implement

Please format the comment above netdev-style, /* If we are... as you did elsewhere.

Quoted 12 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +8 -0
+		 * this functionality differently.
+		 */
+		reg =  IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(0));
+		/* CRC == 4 */
+		reg |= ((max_size + 4) | IXGBE_RXDCTL_RLPML_EN);
+		IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(0), reg);
+		return;
+	}
 
 	msgbuf[0] = IXGBE_VF_SET_LPE;
 	msgbuf[1] = max_size;

drivers/net/ethernet/intel/ixgbevf/vf.c int ixgbevf_negotiate_api_version(struct ixgbe_hw · line 784

Quoted 7 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +3 -0
@@ -679,6 +778,16 @@ int ixgbevf_negotiate_api_version(struct ixgbe_hw  
 *hw, int api)
 	int err;
 	u32 msg[3];
 
+	if (x86_hyper == &x86_hyper_ms_hyperv) {
+		/*
+		 * Hyper-V only supports api version ixgbe_mbox_api_10

Again, please use netdev-style comment above.

Quoted 14 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +7 -0
+		 */
+		if (api != ixgbe_mbox_api_10)
+			return IXGBE_ERR_INVALID_ARGUMENT;
+
+		return 0;
+	}
+
 	/* Negotiate the mailbox API version */
 	msg[0] = IXGBE_VF_API_NEGOTIATE;
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
 	msg[1] = api;
@@ -776,22 +885,51 @@ static const struct ixgbe_mac_operations  
 ixgbevf_mac_ops = {
 	.set_vfta		= ixgbevf_set_vfta_vf,
 };

drivers/net/ethernet/intel/ixgbevf/vf.c static const struct ixgbe_mac_operations · line 897

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +9 -0
 
+static const struct ixgbe_mac_operations ixgbevf_hv_mac_ops = {
+	.init_hw		= ixgbevf_init_hw_vf,
+	.reset_hw		= ixgbevf_hv_reset_hw_vf,
+	.start_hw		= ixgbevf_start_hw_vf,
+	.get_mac_addr		= ixgbevf_get_mac_addr_vf,
+	.stop_adapter		= ixgbevf_stop_hw_vf,
+	.setup_link		= ixgbevf_setup_mac_link_vf,
+	.check_link		= ixgbevf_hv_check_mac_link_vf,
+};

Please add a blank line between these two structures as you have done elsewhere.

Quoted 45 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +20 -0
 const struct ixgbevf_info ixgbevf_82599_vf_info = {
 	.mac = ixgbe_mac_82599_vf,
 	.mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_82599_vf_hv_info = {
+	.mac = ixgbe_mac_82599_vf,
+	.mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X540_vf_info = {
 	.mac = ixgbe_mac_X540_vf,
 	.mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_X540_vf_hv_info = {
+	.mac = ixgbe_mac_X540_vf,
+	.mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X550_vf_info = {
 	.mac = ixgbe_mac_X550_vf,
 	.mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_X550_vf_hv_info = {
+	.mac = ixgbe_mac_X550_vf,
+	.mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X550EM_x_vf_info = {
 	.mac = ixgbe_mac_X550EM_x_vf,
 	.mac_ops = &ixgbevf_mac_ops,
 };
+
+const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info = {
+	.mac = ixgbe_mac_X550EM_x_vf,
+	.mac_ops = &ixgbevf_hv_mac_ops,
+};
drivers/net/ethernet/intel/ixgbevf/vf.h +0 -0
index ef9f773..7242a97 100644

drivers/net/ethernet/intel/ixgbevf/vf.h line 37

Quoted 6 lines
drivers/net/ethernet/intel/ixgbevf/vf.h +2 -0
@@ -32,7 +32,9 @@
 #include <linux/interrupt.h>
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
+#include <asm/hypervisor.h>
 
+#include <asm/hypervisor.h>

Surely you didn't mean to include the same file twice!

Quoted 6 lines

drivers/net/ethernet/intel/ixgbevf/vf.h line 40

Quoted 3 lines
drivers/net/ethernet/intel/ixgbevf/vf.h +0 -0
 #include "defines.h"
 #include "regs.h"
 #include "mbx.h"

--
Mark Rustad, Networking Division, Intel Corporation

--
Mark Rustad, Networking Division, Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20160414/ead5ee29/attachment.asc>

#12 lore raw

Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

In reply to K. Y. Srinivasan
Quoted 131 lines · K. Y. Srinivasan

On Hyper-V, the VF/PF communication is a via software mediated path as opposed to the hardware mailbox. Make the necessary adjustments to support Hyper-V.

---
 drivers/net/ethernet/intel/ixgbevf/ixgbevf.h      |   11 ++
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c |   56 ++++++---
 drivers/net/ethernet/intel/ixgbevf/mbx.c          |   12 ++
 drivers/net/ethernet/intel/ixgbevf/vf.c           |  138 +++++++++++++++++++++
 drivers/net/ethernet/intel/ixgbevf/vf.h           |    2 +
 5 files changed, 201 insertions(+), 18 deletions(-)
drivers/net/ethernet/intel/ixgbevf/ixgbevf.h +11 -0
index 5ac60ee..f8d2a0b 100644
@@ -460,9 +460,13 @@ enum ixbgevf_state_t {
 
 enum ixgbevf_boards {
        board_82599_vf,
+       board_82599_vf_hv,
        board_X540_vf,
+       board_X540_vf_hv,
        board_X550_vf,
+       board_X550_vf_hv,
        board_X550EM_x_vf,
+       board_X550EM_x_vf_hv,
 };
 
 enum ixgbevf_xcast_modes {
@@ -477,6 +481,13 @@ extern const struct ixgbevf_info ixgbevf_X550_vf_info;
 extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_info;
 extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops;
 
+
+extern const struct ixgbevf_info ixgbevf_82599_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X540_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X550_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info;
+extern const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops;
+
 /* needed by ethtool.c */
 extern const char ixgbevf_driver_name[];
 extern const char ixgbevf_driver_version[];
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +21 -9
index 007cbe0..4a0ffac 100644
@@ -49,6 +49,7 @@
 #include <linux/if.h>
 #include <linux/if_vlan.h>
 #include <linux/prefetch.h>
+#include <asm/mshyperv.h>
 
 #include "ixgbevf.h"
 
@@ -62,10 +63,14 @@ static char ixgbevf_copyright[] =
        "Copyright (c) 2009 - 2015 Intel Corporation.";
 
 static const struct ixgbevf_info *ixgbevf_info_tbl[] = {
-       [board_82599_vf] = &ixgbevf_82599_vf_info,
-       [board_X540_vf]  = &ixgbevf_X540_vf_info,
-       [board_X550_vf]  = &ixgbevf_X550_vf_info,
-       [board_X550EM_x_vf] = &ixgbevf_X550EM_x_vf_info,
+       [board_82599_vf]        = &ixgbevf_82599_vf_info,
+       [board_82599_vf_hv]     = &ixgbevf_82599_vf_hv_info,
+       [board_X540_vf]         = &ixgbevf_X540_vf_info,
+       [board_X540_vf_hv]      = &ixgbevf_X540_vf_hv_info,
+       [board_X550_vf]         = &ixgbevf_X550_vf_info,
+       [board_X550_vf_hv]      = &ixgbevf_X550_vf_hv_info,
+       [board_X550EM_x_vf]     = &ixgbevf_X550EM_x_vf_info,
+       [board_X550EM_x_vf_hv]  = &ixgbevf_X550EM_x_vf_hv_info,
 };
 
 /* ixgbevf_pci_tbl - PCI Device ID Table
@@ -78,9 +83,13 @@ static const struct ixgbevf_info *ixgbevf_info_tbl[] = {
  */
 static const struct pci_device_id ixgbevf_pci_tbl[] = {
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF), board_82599_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF_HV), board_82599_vf_hv },
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF), board_X540_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF_HV), board_X540_vf_hv },
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550_VF), board_X550_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550_VF_HV), board_X550_vf_hv },
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_VF), board_X550EM_x_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_VF_HV), board_X550EM_x_vf_hv},
        /* required last entry */
        {0, }
 };
@@ -1809,12 +1818,13 @@ static int ixgbevf_vlan_rx_add_vid(struct net_device *netdev,
 {
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
-       int err;
+       int err = 0;
 
        spin_lock_bh(&adapter->mbx_lock);
 
        /* add VID to filter table */
-       err = hw->mac.ops.set_vfta(hw, vid, 0, true);
+       if (hw->mac.ops.set_vfta)
+               err = hw->mac.ops.set_vfta(hw, vid, 0, true);
 
        spin_unlock_bh(&adapter->mbx_lock);
 
@@ -1835,12 +1845,13 @@ static int ixgbevf_vlan_rx_kill_vid(struct net_device *netdev,
 {
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
-       int err;
+       int err = 0;
 
        spin_lock_bh(&adapter->mbx_lock);
 
        /* remove VID from filter table */
-       err = hw->mac.ops.set_vfta(hw, vid, 0, false);
+       if (hw->mac.ops.set_vfta)
+               err = hw->mac.ops.set_vfta(hw, vid, 0, false);
 
        spin_unlock_bh(&adapter->mbx_lock);
 
@@ -1873,14 +1884,16 @@ static int ixgbevf_write_uc_addr_list(struct net_device *netdev)
                struct netdev_hw_addr *ha;
 
                netdev_for_each_uc_addr(ha, netdev) {
-                       hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
+                       if (hw->mac.ops.set_uc_addr)
+                               hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
                        udelay(200);
                }

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_write_uc_addr_list(struct net_device *netdev) · line 1899

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +2 -1
        } else {
                /* If the list is empty then send message to PF driver to
                 * clear all MAC VLANs on this VF.
                 */
-               hw->mac.ops.set_uc_addr(hw, 0, NULL);
+               if (hw->mac.ops.set_uc_addr)
+                       hw->mac.ops.set_uc_addr(hw, 0, NULL);
        }
 
        return count;

So if I am understanding this correctly it looks like you cannot read or write any addresses for this device. Would I be correct in assuming that you get to have the one unicast address that is provided by the PF and that is it?

If so we may want to look at possibly returning some sort of error on these calls so that we can configure the device to indicate that we cannot support any of these filters.

Quoted 24 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +5 -6
@@ -1908,10 +1921,13 @@ static void ixgbevf_set_rx_mode(struct net_device *netdev)
 
        spin_lock_bh(&adapter->mbx_lock);
 
-       hw->mac.ops.update_xcast_mode(hw, netdev, xcast_mode);
+       if (hw->mac.ops.update_mc_addr_list)
+               if (hw->mac.ops.update_xcast_mode)
+                       hw->mac.ops.update_xcast_mode(hw, netdev, xcast_mode);
 
        /* reprogram multicast list */
-       hw->mac.ops.update_mc_addr_list(hw, netdev);
+       if (hw->mac.ops.update_mc_addr_list)
+               hw->mac.ops.update_mc_addr_list(hw, netdev);
 
        ixgbevf_write_uc_addr_list(netdev);
 
@@ -2074,10 +2090,13 @@ static void ixgbevf_up_complete(struct ixgbevf_adapter *adapter)
 
        spin_lock_bh(&adapter->mbx_lock);
 
-       if (is_valid_ether_addr(hw->mac.addr))
-               hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
-       else
-               hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_up_complete(struct ixgbevf_adapter *adapter) · line 2102

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +7 -0
+       if (is_valid_ether_addr(hw->mac.addr)) {
+               if (hw->mac.ops.set_rar)
+                       hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
+       } else {
+               if (hw->mac.ops.set_rar)
+                       hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);
+       }
 
        spin_unlock_bh(&adapter->mbx_lock);
 

Same here. We shouldn't let the user set a MAC address that we cannot support. We should be returning an error.

Quoted 8 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -1
@@ -3672,14 +3691,15 @@ static int ixgbevf_set_mac(struct net_device *netdev, void *p)
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
        struct sockaddr *addr = p;
-       int err;
+       int err = 0;
 
        if (!is_valid_ether_addr(addr->sa_data))

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_set_mac(struct net_device *netdev, void *p) · line 3705

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +2 -1
                return -EADDRNOTAVAIL;
 
        spin_lock_bh(&adapter->mbx_lock);
 
-       err = hw->mac.ops.set_rar(hw, 0, addr->sa_data, 0);
+       if (hw->mac.ops.set_rar)
+               err = hw->mac.ops.set_rar(hw, 0, addr->sa_data, 0);
 
        spin_unlock_bh(&adapter->mbx_lock);
 

Specifically here. If hw->mac.ops.set_rar is NULL we cannot allow any MAC address change so we should probably return "-EADDRNOTAVAIL".

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/mbx.c +2 -0
index dc68fea..298a0da 100644
@@ -346,3 +346,15 @@ const struct ixgbe_mbx_operations ixgbevf_mbx_ops = {
        .check_for_rst  = ixgbevf_check_for_rst_vf,
 };
 
+/**
+ * Mailbox operations when running on Hyper-V.

drivers/net/ethernet/intel/ixgbevf/mbx.c const struct ixgbe_mbx_operations ixgbevf_mbx_ops = { · line 360

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/mbx.c +10 -0
+ * On Hyper-V, PF/VF communiction is not through the
+ * hardware mailbox; this communication is through
+ * a software mediated path.
+ * Most mail box operations are noop while running on
+ * Hyper-V.
+ */
+const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops = {
+       .init_params    = ixgbevf_init_mbx_params_vf,
+       .check_for_rst  = ixgbevf_check_for_rst_vf,
+};

I'd say if you aren't going to use a mailbox then don't initialize it. The code was based off of the same code that runs the ixgbe driver. It should be able to function without a mailbox provided the necessary calls are updated in the ixgbe_mac_operations that are used by the hyperv VF.

Quoted 28 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +13 -0
index 4d613a4..92397fd 100644
@@ -27,6 +27,13 @@
 #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.
+ */
+#define IXGBE_HV_RESET_OFFSET           0x201
+
 /**
  *  ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx
  *  @hw: pointer to hardware structure
@@ -126,6 +133,23 @@ static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw)
 }
 
 /**
+ * Hyper-V variant; the VF/PF communication is through the PCI
+ * config space.
+ */
+static s32 ixgbevf_hv_reset_hw_vf(struct ixgbe_hw *hw)
+{
+       int i;

drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw) · line 151

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10 -0
+       struct ixgbevf_adapter *adapter = hw->back;
+
+       for (i = 0; i < 6; i++)
+               pci_read_config_byte(adapter->pdev,
+                                    (i + IXGBE_HV_RESET_OFFSET),
+                                    &hw->mac.perm_addr[i]);
+
+       return 0;
+}
+

This bit can be problematic. What about the case where PCI_MMCONFIG is not defined. In such a case it will kill this function without reporting an error other than maybe a MAC address that is all 0s or all FF's.

You might want to add some sort of check here with some message if such a situation occurs just so it can be easier to debug.

Quoted 59 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +52 -0
+/**
  *  ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
  *  @hw: pointer to hardware structure
  *
@@ -656,6 +680,68 @@ out:
 }
 
 /**
+ * Hyper-V variant; there is no mailbox communication.
+ */
+static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,
+                                       ixgbe_link_speed *speed,
+                                       bool *link_up,
+                                       bool autoneg_wait_to_complete)
+{
+       struct ixgbe_mbx_info *mbx = &hw->mbx;
+       struct ixgbe_mac_info *mac = &hw->mac;
+       s32 ret_val = 0;
+       u32 links_reg;
+
+       /* If we were hit with a reset drop the link */
+       if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
+               mac->get_link_status = true;
+
+       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;
+
+       /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
+        * before the link status is correct
+        */
+       if (mac->type == ixgbe_mac_82599_vf) {
+               int i;
+
+               for (i = 0; i < 5; i++) {
+                       udelay(100);
+                       links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
+
+                       if (!(links_reg & IXGBE_LINKS_UP))
+                               goto out;
+               }
+       }
+
+       switch (links_reg & IXGBE_LINKS_SPEED_82599) {
+       case IXGBE_LINKS_SPEED_10G_82599:
+               *speed = IXGBE_LINK_SPEED_10GB_FULL;
+               break;
+       case IXGBE_LINKS_SPEED_1G_82599:
+               *speed = IXGBE_LINK_SPEED_1GB_FULL;
+               break;
+       case IXGBE_LINKS_SPEED_100_82599:
+               *speed = IXGBE_LINK_SPEED_100_FULL;
+               break;
+       }
+

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 743

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10 -0
+       /* if we passed all the tests above then the link is up and we no
+        * longer need to check for link
+        */
+       mac->get_link_status = false;
+
+out:
+       *link_up = !mac->get_link_status;
+       return ret_val;
+}
+

How does this handle the PF resetting? Seems like you are going to be generating Tx hangs in such a case.

Quoted 14 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +7 -0
+/**
  *  ixgbevf_rlpml_set_vf - Set the maximum receive packet length
  *  @hw: pointer to the HW structure
  *  @max_size: value to assign to max frame size
@@ -663,6 +749,19 @@ out:
 void ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
 {
        u32 msgbuf[2];
+       u32 reg;
+
+       if (x86_hyper == &x86_hyper_ms_hyperv) {
+               /*
+                * If we are on Hyper-V, we implement
+                * this functionality differently.

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 767

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +7 -0
+                */
+               reg =  IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(0));
+               /* CRC == 4 */
+               reg |= ((max_size + 4) | IXGBE_RXDCTL_RLPML_EN);
+               IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(0), reg);
+               return;
+       }
 
        msgbuf[0] = IXGBE_VF_SET_LPE;
        msgbuf[1] = max_size;

You would be better off just implementing a hyperv version of this function and avoiding the mailbox call entirely.

Quoted 7 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +3 -0
@@ -679,6 +778,16 @@ int ixgbevf_negotiate_api_version(struct ixgbe_hw *hw, int api)
        int err;
        u32 msg[3];
 
+       if (x86_hyper == &x86_hyper_ms_hyperv) {
+               /*
+                * Hyper-V only supports api version ixgbe_mbox_api_10

drivers/net/ethernet/intel/ixgbevf/vf.c int ixgbevf_negotiate_api_version(struct ixgbe_hw *hw, int api) · line 793

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +7 -0
+                */
+               if (api != ixgbe_mbox_api_10)
+                       return IXGBE_ERR_INVALID_ARGUMENT;
+
+               return 0;
+       }
+
        /* Negotiate the mailbox API version */
        msg[0] = IXGBE_VF_API_NEGOTIATE;
        msg[1] = api;

Same here. Just implement a hyperv version of this function instead of splicing into the existing call. Also you will need to wrap this code up so that we can build on all architectures, not just x86.

drivers/net/ethernet/intel/ixgbevf/vf.c static const struct ixgbe_mac_operations ixgbevf_mac_ops = { · line 896

Quoted 13 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +9 -0
@@ -776,22 +885,51 @@ static const struct ixgbe_mac_operations ixgbevf_mac_ops = {
        .set_vfta               = ixgbevf_set_vfta_vf,
 };
 
+static const struct ixgbe_mac_operations ixgbevf_hv_mac_ops = {
+       .init_hw                = ixgbevf_init_hw_vf,
+       .reset_hw               = ixgbevf_hv_reset_hw_vf,
+       .start_hw               = ixgbevf_start_hw_vf,
+       .get_mac_addr           = ixgbevf_get_mac_addr_vf,
+       .stop_adapter           = ixgbevf_stop_hw_vf,
+       .setup_link             = ixgbevf_setup_mac_link_vf,
+       .check_link             = ixgbevf_hv_check_mac_link_vf,
+};

You might want to consider implementing a set_rar call that will return an error if you try to change the address to anything that is not the permanent addr.

Quoted 44 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +20 -0
 const struct ixgbevf_info ixgbevf_82599_vf_info = {
        .mac = ixgbe_mac_82599_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_82599_vf_hv_info = {
+       .mac = ixgbe_mac_82599_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X540_vf_info = {
        .mac = ixgbe_mac_X540_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_X540_vf_hv_info = {
+       .mac = ixgbe_mac_X540_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X550_vf_info = {
        .mac = ixgbe_mac_X550_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_X550_vf_hv_info = {
+       .mac = ixgbe_mac_X550_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X550EM_x_vf_info = {
        .mac = ixgbe_mac_X550EM_x_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
+
+const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info = {
+       .mac = ixgbe_mac_X550EM_x_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
drivers/net/ethernet/intel/ixgbevf/vf.h +0 -0
index ef9f773..7242a97 100644

drivers/net/ethernet/intel/ixgbevf/vf.h line 37

Quoted 6 lines
drivers/net/ethernet/intel/ixgbevf/vf.h +2 -0
@@ -32,7 +32,9 @@
 #include <linux/interrupt.h>
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
+#include <asm/hypervisor.h>
 
+#include <asm/hypervisor.h>

I don't think you need to include this twice. Also this is a arch specific header file. You might want to move this to vf.c since that is where you are using the code it provides. Then you can probably wrap it in an X86 build check so that you don't break the build on other architectures.

Quoted 6 lines
drivers/net/ethernet/intel/ixgbevf/vf.h +0 -1
 #include "defines.h"
 #include "regs.h"
 #include "mbx.h"
--

1.7.4.1

#6 lore raw

RE: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

In reply to Rustad, Mark D
Quoted 15 lines

-----Original Message-----
From: Rustad, Mark D [mailto:[email protected]]
Sent: Thursday, April 14, 2016 4:01 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; netdev <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ronciak, John <[email protected]>; intel- [email protected]
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 1 line

Some comments below:

Mark,

Thank you for the comments. I will address them and repost the patches.

Regards,

K. Y

#7 lore raw

Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 17 lines · KY Srinivasan
Quoted 15 lines

-----Original Message-----
From: Rustad, Mark D [mailto:[email protected]]
Sent: Thursday, April 14, 2016 4:01 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; netdev <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ronciak, John <[email protected]>; intel- [email protected]
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 1 line

Some comments below:

Quoted 7 lines

Mark,

Thank you for the comments. I will address them and repost the patches.

Regards,

K. Y

Please look closely at Alex's comments. I think they are much more important.

--
Mark Rustad, Networking Division, Intel Corporation

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

#8 lore raw

RE: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 37 lines

-----Original Message-----
From: Rustad, Mark D [mailto:[email protected]]
Sent: Thursday, April 14, 2016 5:07 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; netdev <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ronciak, John <[email protected]>; intel- [email protected]
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 11 lines · KY Srinivasan
Quoted 11 lines

-----Original Message-----
From: Rustad, Mark D [mailto:[email protected]]
Sent: Thursday, April 14, 2016 4:01 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; netdev <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ronciak, John <[email protected]>;

intel-

Quoted 8 lines
Quoted 5 lines

[email protected]
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Some comments below:

Mark,

Quoted 8 lines
Quoted 5 lines

Thank you for the comments. I will address them and repost the patches.

Regards,

K. Y

Please look closely at Alex's comments. I think they are much more important.

I am looking at Alex's comments as I am writing this.

K. Y

Quoted 3 lines

--
Mark Rustad, Networking Division, Intel Corporation

#9 lore raw

Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 39 lines · KY Srinivasan
Quoted 39 lines

-----Original Message-----
From: Rustad, Mark D [mailto:mark.d.rustad at intel.com]
Sent: Thursday, April 14, 2016 5:07 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; netdev <[email protected]>; linux-kernel at vger.kernel.org; devel at linuxdriverproject.org; olaf at aepfle.de; apw at canonical.com; jasowang at redhat.com; eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com; Ronciak, John <[email protected]>; intel- wired-lan at linuxonhyperv.com
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 9 lines · KY Srinivasan
Quoted 9 lines

-----Original Message-----
From: Rustad, Mark D [mailto:mark.d.rustad at intel.com]
Sent: Thursday, April 14, 2016 4:01 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; netdev <[email protected]>; linux-kernel at vger.kernel.org; devel at linuxdriverproject.org; olaf at aepfle.de; apw at canonical.com; jasowang at redhat.com; eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com; Ronciak, John <[email protected]>;

intel-

Quoted 12 lines
Quoted 5 lines

wired-lan at linuxonhyperv.com
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Some comments below:

Mark,

Thank you for the comments. I will address them and repost the patches.

Regards,

Quoted 10 lines
Quoted 4 lines
Quoted 1 line

K. Y

Please look closely at Alex's comments. I think they are much more important.

I am looking at Alex's comments as I am writing this.

K. Y

Quoted 2 lines

--
Mark Rustad, Networking Division, Intel Corporation

Can you please stop putting that crazy intel-wired-lan at linuxonhyperv.com in your messages? It doesn't exist.

--
Mark Rustad, Networking Division, Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20160415/1af23b43/attachment.asc>

#10 lore raw

Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

In reply to KY Srinivasan
Quoted 39 lines · KY Srinivasan
Quoted 39 lines

-----Original Message-----
From: Rustad, Mark D [mailto:[email protected]]
Sent: Thursday, April 14, 2016 5:07 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; netdev <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ronciak, John <[email protected]>; intel- [email protected]
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 11 lines · KY Srinivasan
Quoted 11 lines

-----Original Message-----
From: Rustad, Mark D [mailto:[email protected]]
Sent: Thursday, April 14, 2016 4:01 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; netdev <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ronciak, John <[email protected]>;

intel-

Quoted 10 lines
Quoted 5 lines

[email protected]
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Some comments below:

Mark,

Thank you for the comments. I will address them and repost the patches.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Regards,

K. Y

Please look closely at Alex's comments. I think they are much more important.

I am looking at Alex's comments as I am writing this.

On additional thought that just occurred to me after looking over the other patches you submitted for the hv_netvsc is that you might just stub out the multicast, unicast, and vfta configuration calls for the hyperV interface since all that stuff should be handled by the other link in the bond anyway. Then you should be able to mostly contain all the changes other than the device IDs to the vf.c file which is really how this kind of change should work anyway.

Also I was wondering. Since HyperV is using a proprietary device ID anyway do you really need the calls like the one below?:
+ if (x86_hyper == &x86_hyper_ms_hyperv) {

If we can just identify HyperV via the device Id then we could drop the x86 arch specific bits and instead just build for all cases.

- Alex

#11 lore raw

RE: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 68 lines

-----Original Message-----
From: Alexander Duyck [mailto:alexander.duyck at gmail.com]
Sent: Thursday, April 14, 2016 5:19 PM
To: KY Srinivasan <[email protected]>
Cc: Rustad, Mark D <[email protected]>; David Miller <[email protected]>; netdev <[email protected]>; linux- kernel at vger.kernel.org; devel at linuxdriverproject.org; olaf at aepfle.de; apw at canonical.com; jasowang at redhat.com; eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com; Ronciak, John <[email protected]>; intel-wired-lan at linuxonhyperv.com
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 11 lines · KY Srinivasan
Quoted 11 lines

-----Original Message-----
From: Rustad, Mark D [mailto:mark.d.rustad at intel.com]
Sent: Thursday, April 14, 2016 5:07 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; netdev <[email protected]>; linux-kernel at vger.kernel.org; devel at linuxdriverproject.org; olaf at aepfle.de; apw at canonical.com; jasowang at redhat.com; eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com; Ronciak, John <[email protected]>;

intel-

Quoted 17 lines
Quoted 17 lines

wired-lan at linuxonhyperv.com
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 11 lines · KY Srinivasan
Quoted 11 lines

-----Original Message-----
From: Rustad, Mark D [mailto:mark.d.rustad at intel.com]
Sent: Thursday, April 14, 2016 4:01 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; netdev <[email protected]>; linux-kernel at vger.kernel.org; devel at linuxdriverproject.org; olaf at aepfle.de; apw at canonical.com; jasowang at redhat.com; eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com; Ronciak, John <[email protected]>;

Quoted 3 lines
Quoted 3 lines

intel-

Quoted 2 lines
Quoted 2 lines

wired-lan at linuxonhyperv.com
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows

hosts

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

(Hyper-V)

Some comments below:

Mark,

Thank you for the comments. I will address them and repost the

patches.

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

Regards,

K. Y

Please look closely at Alex's comments. I think they are much more important.

I am looking at Alex's comments as I am writing this.

Quoted 7 lines

On additional thought that just occurred to me after looking over the other patches you submitted for the hv_netvsc is that you might just stub out the multicast, unicast, and vfta configuration calls for the hyperV interface since all that stuff should be handled by the other link in the bond anyway. Then you should be able to mostly contain all the changes other than the device IDs to the vf.c file which is really how this kind of change should work anyway.

I will do that.

Quoted 7 lines

Also I was wondering. Since HyperV is using a proprietary device ID anyway do you really need the calls like the one below?:
+ if (x86_hyper == &x86_hyper_ms_hyperv) {

If we can just identify HyperV via the device Id then we could drop the x86 arch specific bits and instead just build for all cases.

Yes; I was planning to get rid of the x86 dependency. I will fix this.

K. Y

Quoted 2 lines

- Alex

#17 lore raw
In reply to K. Y. Srinivasan
Quoted 8 lines · K. Y. Srinivasan

Make adjustments to the Intel 10G VF driver to support running on Hyper-V hosts.

K. Y. Srinivasan (2):
ethernet: intel: Add the device ID's presented while running on
Hyper-V
intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 7 lines
 drivers/net/ethernet/intel/ixgbevf/defines.h      |    5 +
 drivers/net/ethernet/intel/ixgbevf/ixgbevf.h      |   11 ++
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c |   56 ++++++---
 drivers/net/ethernet/intel/ixgbevf/mbx.c          |   12 ++
 drivers/net/ethernet/intel/ixgbevf/vf.c           |  138 +++++++++++++++++++++
 drivers/net/ethernet/intel/ixgbevf/vf.h           |    2 +
 6 files changed, 206 insertions(+), 18 deletions(-)

Don't know how you butchered the mailing list address, but you did not send this series to [email protected] mailing list. Please address the requested changes that Mark suggested and resubmit to the correct mailing list please.

#13 lore raw

RE: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

In reply to Alexander Duyck
Quoted 171 lines

-----Original Message-----
From: Alexander Duyck [mailto:alexander.duyck at gmail.com]
Sent: Thursday, April 14, 2016 4:18 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; Netdev <[email protected]>; linux-kernel at vger.kernel.org; devel at linuxdriverproject.org; olaf at aepfle.de; Robo Bot <[email protected]>; Jason Wang <[email protected]>;
eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com; John Ronciak <[email protected]>; intel-wired-lan <intel-wired- lan at lists.osuosl.org>
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 10 lines · K. Y. Srinivasan

On Hyper-V, the VF/PF communication is a via software mediated path as opposed to the hardware mailbox. Make the necessary adjustments to support Hyper-V.

---
 drivers/net/ethernet/intel/ixgbevf/ixgbevf.h      |   11 ++
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c |   56 ++++++---
 drivers/net/ethernet/intel/ixgbevf/mbx.c          |   12 ++
 drivers/net/ethernet/intel/ixgbevf/vf.c           |  138

+++++++++++++++++++++

Review

Quoted 4 lines
 drivers/net/ethernet/intel/ixgbevf/vf.h           |    2 +
 5 files changed, 201 insertions(+), 18 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/ixgbevf.h

drivers/net/ethernet/intel/ixgbevf/ixgbevf.h extern const struct ixgbevf_info

Quoted 18 lines

index 5ac60ee..f8d2a0b 100644

drivers/net/ethernet/intel/ixgbevf/ixgbevf.h +4 -0
@@ -460,9 +460,13 @@ enum ixbgevf_state_t {
 
 enum ixgbevf_boards {
        board_82599_vf,
+       board_82599_vf_hv,
        board_X540_vf,
+       board_X540_vf_hv,
        board_X550_vf,
+       board_X550_vf_hv,
        board_X550EM_x_vf,
+       board_X550EM_x_vf_hv,
 };
 
 enum ixgbevf_xcast_modes {
@@ -477,6 +481,13 @@ extern const struct ixgbevf_info

ixgbevf_X550_vf_info;

Review

Quoted 14 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf.h +7 -0
 extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_info;
 extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops;
 
+
+extern const struct ixgbevf_info ixgbevf_82599_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X540_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X550_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info;
+extern const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops;
+
 /* needed by ethtool.c */
 extern const char ixgbevf_driver_name[];
 extern const char ixgbevf_driver_version[];
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] =

Quoted 31 lines

index 007cbe0..4a0ffac 100644

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +9 -4
@@ -49,6 +49,7 @@
 #include <linux/if.h>
 #include <linux/if_vlan.h>
 #include <linux/prefetch.h>
+#include <asm/mshyperv.h>
 
 #include "ixgbevf.h"
 
@@ -62,10 +63,14 @@ static char ixgbevf_copyright[] =
        "Copyright (c) 2009 - 2015 Intel Corporation.";
 
 static const struct ixgbevf_info *ixgbevf_info_tbl[] = {
-       [board_82599_vf] = &ixgbevf_82599_vf_info,
-       [board_X540_vf]  = &ixgbevf_X540_vf_info,
-       [board_X550_vf]  = &ixgbevf_X550_vf_info,
-       [board_X550EM_x_vf] = &ixgbevf_X550EM_x_vf_info,
+       [board_82599_vf]        = &ixgbevf_82599_vf_info,
+       [board_82599_vf_hv]     = &ixgbevf_82599_vf_hv_info,
+       [board_X540_vf]         = &ixgbevf_X540_vf_info,
+       [board_X540_vf_hv]      = &ixgbevf_X540_vf_hv_info,
+       [board_X550_vf]         = &ixgbevf_X550_vf_info,
+       [board_X550_vf_hv]      = &ixgbevf_X550_vf_hv_info,
+       [board_X550EM_x_vf]     = &ixgbevf_X550EM_x_vf_info,
+       [board_X550EM_x_vf_hv]  = &ixgbevf_X550EM_x_vf_hv_info,
 };
 
 /* ixgbevf_pci_tbl - PCI Device ID Table
@@ -78,9 +83,13 @@ static const struct ixgbevf_info *ixgbevf_info_tbl[] =

{

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] = {

Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
  */
 static const struct pci_device_id ixgbevf_pci_tbl[] = {
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF), board_82599_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF_HV),

board_82599_vf_hv },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] = · line 88

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF), board_X540_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF_HV),

board_X540_vf_hv },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] = · line 90

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550_VF), board_X550_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550_VF_HV),

board_X550_vf_hv },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] = · line 91

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_VF),

board_X550EM_x_vf },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] = · line 92

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_VF_HV),

board_X550EM_x_vf_hv},

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_vlan_rx_add_vid(struct

Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        /* required last entry */
        {0, }
 };
@@ -1809,12 +1818,13 @@ static int ixgbevf_vlan_rx_add_vid(struct

net_device *netdev,

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_vlan_rx_kill_vid(struct

Quoted 16 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -2
 {
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
-       int err;
+       int err = 0;
 
        spin_lock_bh(&adapter->mbx_lock);
 
        /* add VID to filter table */
-       err = hw->mac.ops.set_vfta(hw, vid, 0, true);
+       if (hw->mac.ops.set_vfta)
+               err = hw->mac.ops.set_vfta(hw, vid, 0, true);
 
        spin_unlock_bh(&adapter->mbx_lock);
 
@@ -1835,12 +1845,13 @@ static int ixgbevf_vlan_rx_kill_vid(struct

net_device *netdev,

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_write_uc_addr_list(struct

Quoted 16 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -2
 {
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
-       int err;
+       int err = 0;
 
        spin_lock_bh(&adapter->mbx_lock);
 
        /* remove VID from filter table */
-       err = hw->mac.ops.set_vfta(hw, vid, 0, false);
+       if (hw->mac.ops.set_vfta)
+               err = hw->mac.ops.set_vfta(hw, vid, 0, false);
 
        spin_unlock_bh(&adapter->mbx_lock);
 
@@ -1873,14 +1884,16 @@ static int ixgbevf_write_uc_addr_list(struct

net_device *netdev)

Quoted 17 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +4 -2
                struct netdev_hw_addr *ha;
 
                netdev_for_each_uc_addr(ha, netdev) {
-                       hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
+                       if (hw->mac.ops.set_uc_addr)
+                               hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
                        udelay(200);
                }
        } else {
                /* If the list is empty then send message to PF driver to
                 * clear all MAC VLANs on this VF.
                 */
-               hw->mac.ops.set_uc_addr(hw, 0, NULL);
+               if (hw->mac.ops.set_uc_addr)
+                       hw->mac.ops.set_uc_addr(hw, 0, NULL);
        }
 
Quoted 6 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_write_uc_addr_list(struct net_device *netdev) · line 1899

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        return count;

So if I am understanding this correctly it looks like you cannot read or write any addresses for this device. Would I be correct in assuming that you get to have the one unicast address that is provided by the PF and that is it?

That is what I have been told by the Windows folks at Intel.

Quoted 4 lines

If so we may want to look at possibly returning some sort of error on these calls so that we can configure the device to indicate that we cannot support any of these filters.

I will do that. So, I am going to check the device ID and return an error. Would IXGBE_NOT_IMPLEMENTED be appropriate?

Quoted 35 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_set_rx_mode(struct

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
@@ -1908,10 +1921,13 @@ static void ixgbevf_set_rx_mode(struct

net_device *netdev)

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_up_complete(struct

Quoted 16 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +5 -2
        spin_lock_bh(&adapter->mbx_lock);
 
-       hw->mac.ops.update_xcast_mode(hw, netdev, xcast_mode);
+       if (hw->mac.ops.update_mc_addr_list)
+               if (hw->mac.ops.update_xcast_mode)
+                       hw->mac.ops.update_xcast_mode(hw, netdev, xcast_mode);
 
        /* reprogram multicast list */
-       hw->mac.ops.update_mc_addr_list(hw, netdev);
+       if (hw->mac.ops.update_mc_addr_list)
+               hw->mac.ops.update_mc_addr_list(hw, netdev);
 
        ixgbevf_write_uc_addr_list(netdev);
 
@@ -2074,10 +2090,13 @@ static void ixgbevf_up_complete(struct

ixgbevf_adapter *adapter)

Quoted 15 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +7 -4
        spin_lock_bh(&adapter->mbx_lock);
 
-       if (is_valid_ether_addr(hw->mac.addr))
-               hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
-       else
-               hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);
+       if (is_valid_ether_addr(hw->mac.addr)) {
+               if (hw->mac.ops.set_rar)
+                       hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
+       } else {
+               if (hw->mac.ops.set_rar)
+                       hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);
+       }
 
Quoted 5 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_up_complete(struct · line 2101

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        spin_unlock_bh(&adapter->mbx_lock);
 

Same here. We shouldn't let the user set a MAC address that we cannot support. We should be returning an error.

Yes; I will return an error.

Quoted 18 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_set_mac(struct net_device

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
@@ -3672,14 +3691,15 @@ static int ixgbevf_set_mac(struct net_device

*netdev, void *p)

Quoted 15 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -2
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
        struct sockaddr *addr = p;
-       int err;
+       int err = 0;
 
        if (!is_valid_ether_addr(addr->sa_data))
                return -EADDRNOTAVAIL;
 
        spin_lock_bh(&adapter->mbx_lock);
 
-       err = hw->mac.ops.set_rar(hw, 0, addr->sa_data, 0);
+       if (hw->mac.ops.set_rar)
+               err = hw->mac.ops.set_rar(hw, 0, addr->sa_data, 0);
 
Quoted 5 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_set_mac(struct net_device · line 3705

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        spin_unlock_bh(&adapter->mbx_lock);
 

Specifically here. If hw->mac.ops.set_rar is NULL we cannot allow any MAC address change so we should probably return "-EADDRNOTAVAIL".

Will do.

Quoted 21 lines

Review

Quoted 2 lines
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/mbx.c

drivers/net/ethernet/intel/ixgbevf/mbx.c const struct ixgbe_mbx_operations

Quoted 4 lines

index dc68fea..298a0da 100644

drivers/net/ethernet/intel/ixgbevf/mbx.c +0 -0
@@ -346,3 +346,15 @@ const struct ixgbe_mbx_operations

ixgbevf_mbx_ops = {

Quoted 13 lines
drivers/net/ethernet/intel/ixgbevf/mbx.c +10 -0
        .check_for_rst  = ixgbevf_check_for_rst_vf,
 };
 
+/**
+ * Mailbox operations when running on Hyper-V.
+ * On Hyper-V, PF/VF communiction is not through the
+ * hardware mailbox; this communication is through
+ * a software mediated path.
+ * Most mail box operations are noop while running on
+ * Hyper-V.
+ */
+const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops = {
+       .init_params    = ixgbevf_init_mbx_params_vf,
Quoted 9 lines

drivers/net/ethernet/intel/ixgbevf/mbx.c const struct ixgbe_mbx_operations ixgbevf_mbx_ops = { · line 360

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/mbx.c +2 -0
+       .check_for_rst  = ixgbevf_check_for_rst_vf,
+};

I'd say if you aren't going to use a mailbox then don't initialize it. The code was based off of the same code that runs the ixgbe driver. It should be able to function without a mailbox provided the necessary calls are updated in the ixgbe_mac_operations that are used by the hyperv VF.

Ok; I will change the code.

Quoted 46 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/vf.c

drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw

Quoted 18 lines

index 4d613a4..92397fd 100644

drivers/net/ethernet/intel/ixgbevf/vf.c +7 -0
@@ -27,6 +27,13 @@
 #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.
+ */
+#define IXGBE_HV_RESET_OFFSET           0x201
+
 /**
  *  ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx
  *  @hw: pointer to hardware structure
@@ -126,6 +133,23 @@ static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw

*hw)

Quoted 9 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +6 -0
 }
 
 /**
+ * Hyper-V variant; the VF/PF communication is through the PCI
+ * config space.
+ */
+static s32 ixgbevf_hv_reset_hw_vf(struct ixgbe_hw *hw)
+{
+       int i;

drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw) · line 151

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10 -0
+       struct ixgbevf_adapter *adapter = hw->back;
+
+       for (i = 0; i < 6; i++)
+               pci_read_config_byte(adapter->pdev,
+                                    (i + IXGBE_HV_RESET_OFFSET),
+                                    &hw->mac.perm_addr[i]);
+
+       return 0;
+}
+

This bit can be problematic. What about the case where PCI_MMCONFIG is not defined. In such a case it will kill this function without reporting an error other than maybe a MAC address that is all 0s or all FF's.

Quoted 2 lines

You might want to add some sort of check here with some message if such a situation occurs just so it can be easier to debug.

I am a little confused here. This function will only execute when we are handling Hyper-V device IDs (while running on Hyper-V). Hyper-V PCI pass-through driver will support the config space access.

Quoted 65 lines
Quoted 65 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +57 -0
+/**
  *  ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
  *  @hw: pointer to hardware structure
  *
@@ -656,6 +680,68 @@ out:
 }
 
 /**
+ * Hyper-V variant; there is no mailbox communication.
+ */
+static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,
+                                       ixgbe_link_speed *speed,
+                                       bool *link_up,
+                                       bool autoneg_wait_to_complete)
+{
+       struct ixgbe_mbx_info *mbx = &hw->mbx;
+       struct ixgbe_mac_info *mac = &hw->mac;
+       s32 ret_val = 0;
+       u32 links_reg;
+
+       /* If we were hit with a reset drop the link */
+       if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
+               mac->get_link_status = true;
+
+       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;
+
+       /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
+        * before the link status is correct
+        */
+       if (mac->type == ixgbe_mac_82599_vf) {
+               int i;
+
+               for (i = 0; i < 5; i++) {
+                       udelay(100);
+                       links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
+
+                       if (!(links_reg & IXGBE_LINKS_UP))
+                               goto out;
+               }
+       }
+
+       switch (links_reg & IXGBE_LINKS_SPEED_82599) {
+       case IXGBE_LINKS_SPEED_10G_82599:
+               *speed = IXGBE_LINK_SPEED_10GB_FULL;
+               break;
+       case IXGBE_LINKS_SPEED_1G_82599:
+               *speed = IXGBE_LINK_SPEED_1GB_FULL;
+               break;
+       case IXGBE_LINKS_SPEED_100_82599:
+               *speed = IXGBE_LINK_SPEED_100_FULL;
+               break;
+       }
+
+       /* if we passed all the tests above then the link is up and we no
+        * longer need to check for link
+        */
+       mac->get_link_status = false;
+
Quoted 8 lines

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 743

Quoted 5 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +5 -0
+out:
+       *link_up = !mac->get_link_status;
+       return ret_val;
+}
+

How does this handle the PF resetting? Seems like you are going to be generating Tx hangs in such a case.

I am not sure how the Windows PF driver communicates this information. Do you have any suggestions for this.

Quoted 23 lines
Quoted 23 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +14 -0
+/**
  *  ixgbevf_rlpml_set_vf - Set the maximum receive packet length
  *  @hw: pointer to the HW structure
  *  @max_size: value to assign to max frame size
@@ -663,6 +749,19 @@ out:
 void ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
 {
        u32 msgbuf[2];
+       u32 reg;
+
+       if (x86_hyper == &x86_hyper_ms_hyperv) {
+               /*
+                * If we are on Hyper-V, we implement
+                * this functionality differently.
+                */
+               reg =  IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(0));
+               /* CRC == 4 */
+               reg |= ((max_size + 4) | IXGBE_RXDCTL_RLPML_EN);
+               IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(0), reg);
+               return;
+       }
 
Quoted 5 lines

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 767

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
        msgbuf[0] = IXGBE_VF_SET_LPE;
        msgbuf[1] = max_size;

You would be better off just implementing a hyperv version of this function and avoiding the mailbox call entirely.

Ok; will do.

Quoted 15 lines

drivers/net/ethernet/intel/ixgbevf/vf.c int ixgbevf_negotiate_api_version(struct

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
@@ -679,6 +778,16 @@ int ixgbevf_negotiate_api_version(struct

ixgbe_hw *hw, int api)

Quoted 12 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +9 -0
        int err;
        u32 msg[3];
 
+       if (x86_hyper == &x86_hyper_ms_hyperv) {
+               /*
+                * Hyper-V only supports api version ixgbe_mbox_api_10
+                */
+               if (api != ixgbe_mbox_api_10)
+                       return IXGBE_ERR_INVALID_ARGUMENT;
+
+               return 0;
+       }
Quoted 8 lines

drivers/net/ethernet/intel/ixgbevf/vf.c int ixgbevf_negotiate_api_version(struct ixgbe_hw *hw, int api) · line 793

Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +1 -0
+
        /* Negotiate the mailbox API version */
        msg[0] = IXGBE_VF_API_NEGOTIATE;
        msg[1] = api;

Same here. Just implement a hyperv version of this function instead of splicing into the existing call. Also you will need to wrap this code up so that we can build on all architectures, not just x86.

Ok; will do.

Quoted 6 lines

drivers/net/ethernet/intel/ixgbevf/vf.c static const struct ixgbe_mac_operations

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
@@ -776,22 +885,51 @@ static const struct ixgbe_mac_operations

ixgbevf_mac_ops = {

Quoted 3 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
        .set_vfta               = ixgbevf_set_vfta_vf,
 };
 
Quoted 13 lines

drivers/net/ethernet/intel/ixgbevf/vf.c static const struct ixgbe_mac_operations ixgbevf_mac_ops = { · line 896

Quoted 9 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +9 -0
+static const struct ixgbe_mac_operations ixgbevf_hv_mac_ops = {
+       .init_hw                = ixgbevf_init_hw_vf,
+       .reset_hw               = ixgbevf_hv_reset_hw_vf,
+       .start_hw               = ixgbevf_start_hw_vf,
+       .get_mac_addr           = ixgbevf_get_mac_addr_vf,
+       .stop_adapter           = ixgbevf_stop_hw_vf,
+       .setup_link             = ixgbevf_setup_mac_link_vf,
+       .check_link             = ixgbevf_hv_check_mac_link_vf,
+};

You might want to consider implementing a set_rar call that will return an error if you try to change the address to anything that is not the permanent addr.

Ok; will do.

Quoted 51 lines

Review

Quoted 41 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +20 -0
 const struct ixgbevf_info ixgbevf_82599_vf_info = {
        .mac = ixgbe_mac_82599_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_82599_vf_hv_info = {
+       .mac = ixgbe_mac_82599_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X540_vf_info = {
        .mac = ixgbe_mac_X540_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_X540_vf_hv_info = {
+       .mac = ixgbe_mac_X540_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X550_vf_info = {
        .mac = ixgbe_mac_X550_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_X550_vf_hv_info = {
+       .mac = ixgbe_mac_X550_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X550EM_x_vf_info = {
        .mac = ixgbe_mac_X550EM_x_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
+
+const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info = {
+       .mac = ixgbe_mac_X550EM_x_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/vf.h

Quoted 9 lines

index ef9f773..7242a97 100644

drivers/net/ethernet/intel/ixgbevf/vf.h +1 -0
@@ -32,7 +32,9 @@
 #include <linux/interrupt.h>
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
+#include <asm/hypervisor.h>
 
Quoted 7 lines

drivers/net/ethernet/intel/ixgbevf/vf.h line 37

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/vf.h +1 -0
+#include <asm/hypervisor.h>

I don't think you need to include this twice. Also this is a arch specific header file. You might want to move this to vf.c since that is where you are using the code it provides. Then you can probably wrap it in an X86 build check so that you don't break the build on other architectures.

I will fix this. Thank you for your detailed comments.

Regards,

K. Y

#18 lore raw
In reply to Jeff Kirsher
Quoted 29 lines

-----Original Message-----
From: tarbal at gmail.com [mailto:tarbal at gmail.com] On Behalf Of Jeff Kirsher
Sent: Thursday, April 14, 2016 7:21 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; netdev <[email protected]>; LKML <[email protected]>; devel at linuxdriverproject.org; olaf at aepfle.de; apw at canonical.com; jasowang at redhat.com; eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com; Ronciak, John <[email protected]>; intel- wired-lan at linuxonhyperv.com
Subject: Re: [PATCH net-next 0/2] ethernet: intel: Support Hyper-V hosts

Quoted 8 lines · K. Y. Srinivasan

Make adjustments to the Intel 10G VF driver to support running on Hyper-V hosts.

K. Y. Srinivasan (2):
ethernet: intel: Add the device ID's presented while running on
Hyper-V
intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 5 lines
 drivers/net/ethernet/intel/ixgbevf/defines.h      |    5 +
 drivers/net/ethernet/intel/ixgbevf/ixgbevf.h      |   11 ++
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c |   56 ++++++---
 drivers/net/ethernet/intel/ixgbevf/mbx.c          |   12 ++
 drivers/net/ethernet/intel/ixgbevf/vf.c           |  138
Quoted 8 lines

+++++++++++++++++++++

Quoted 2 lines
 drivers/net/ethernet/intel/ixgbevf/vf.h           |    2 +
 6 files changed, 206 insertions(+), 18 deletions(-)

Don't know how you butchered the mailing list address, but you did not send this series to intel-wired-lan at lists.osuosl.org mailing list. Please address the requested changes that Mark suggested and resubmit to the correct mailing list please.

Will do.

Thanks,

K. Y

#14 lore raw

Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

In reply to KY Srinivasan
Quoted 171 lines · KY Srinivasan
Quoted 171 lines

-----Original Message-----
From: Alexander Duyck [mailto:alexander.duyck at gmail.com]
Sent: Thursday, April 14, 2016 4:18 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; Netdev <[email protected]>; linux-kernel at vger.kernel.org; devel at linuxdriverproject.org; olaf at aepfle.de; Robo Bot <[email protected]>; Jason Wang <[email protected]>;
eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com; John Ronciak <[email protected]>; intel-wired-lan <intel-wired- lan at lists.osuosl.org>
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 10 lines · K. Y. Srinivasan

On Hyper-V, the VF/PF communication is a via software mediated path as opposed to the hardware mailbox. Make the necessary adjustments to support Hyper-V.

---
 drivers/net/ethernet/intel/ixgbevf/ixgbevf.h      |   11 ++
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c |   56 ++++++---
 drivers/net/ethernet/intel/ixgbevf/mbx.c          |   12 ++
 drivers/net/ethernet/intel/ixgbevf/vf.c           |  138

+++++++++++++++++++++

Review

Quoted 4 lines
 drivers/net/ethernet/intel/ixgbevf/vf.h           |    2 +
 5 files changed, 201 insertions(+), 18 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/ixgbevf.h

drivers/net/ethernet/intel/ixgbevf/ixgbevf.h extern const struct ixgbevf_info

Quoted 18 lines

index 5ac60ee..f8d2a0b 100644

drivers/net/ethernet/intel/ixgbevf/ixgbevf.h +4 -0
@@ -460,9 +460,13 @@ enum ixbgevf_state_t {
 
 enum ixgbevf_boards {
        board_82599_vf,
+       board_82599_vf_hv,
        board_X540_vf,
+       board_X540_vf_hv,
        board_X550_vf,
+       board_X550_vf_hv,
        board_X550EM_x_vf,
+       board_X550EM_x_vf_hv,
 };
 
 enum ixgbevf_xcast_modes {
@@ -477,6 +481,13 @@ extern const struct ixgbevf_info

ixgbevf_X550_vf_info;

Review

Quoted 14 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf.h +7 -0
 extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_info;
 extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops;
 
+
+extern const struct ixgbevf_info ixgbevf_82599_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X540_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X550_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info;
+extern const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops;
+
 /* needed by ethtool.c */
 extern const char ixgbevf_driver_name[];
 extern const char ixgbevf_driver_version[];
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] =

Quoted 31 lines

index 007cbe0..4a0ffac 100644

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +9 -4
@@ -49,6 +49,7 @@
 #include <linux/if.h>
 #include <linux/if_vlan.h>
 #include <linux/prefetch.h>
+#include <asm/mshyperv.h>
 
 #include "ixgbevf.h"
 
@@ -62,10 +63,14 @@ static char ixgbevf_copyright[] =
        "Copyright (c) 2009 - 2015 Intel Corporation.";
 
 static const struct ixgbevf_info *ixgbevf_info_tbl[] = {
-       [board_82599_vf] = &ixgbevf_82599_vf_info,
-       [board_X540_vf]  = &ixgbevf_X540_vf_info,
-       [board_X550_vf]  = &ixgbevf_X550_vf_info,
-       [board_X550EM_x_vf] = &ixgbevf_X550EM_x_vf_info,
+       [board_82599_vf]        = &ixgbevf_82599_vf_info,
+       [board_82599_vf_hv]     = &ixgbevf_82599_vf_hv_info,
+       [board_X540_vf]         = &ixgbevf_X540_vf_info,
+       [board_X540_vf_hv]      = &ixgbevf_X540_vf_hv_info,
+       [board_X550_vf]         = &ixgbevf_X550_vf_info,
+       [board_X550_vf_hv]      = &ixgbevf_X550_vf_hv_info,
+       [board_X550EM_x_vf]     = &ixgbevf_X550EM_x_vf_info,
+       [board_X550EM_x_vf_hv]  = &ixgbevf_X550EM_x_vf_hv_info,
 };
 
 /* ixgbevf_pci_tbl - PCI Device ID Table
@@ -78,9 +83,13 @@ static const struct ixgbevf_info *ixgbevf_info_tbl[] =

{

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] = {

Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
  */
 static const struct pci_device_id ixgbevf_pci_tbl[] = {
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF), board_82599_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF_HV),

board_82599_vf_hv },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] = · line 88

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF), board_X540_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF_HV),

board_X540_vf_hv },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] = · line 90

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550_VF), board_X550_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550_VF_HV),

board_X550_vf_hv },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] = · line 91

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_VF),

board_X550EM_x_vf },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] = · line 92

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_VF_HV),

board_X550EM_x_vf_hv},

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_vlan_rx_add_vid(struct

Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        /* required last entry */
        {0, }
 };
@@ -1809,12 +1818,13 @@ static int ixgbevf_vlan_rx_add_vid(struct

net_device *netdev,

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_vlan_rx_kill_vid(struct

Quoted 16 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -2
 {
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
-       int err;
+       int err = 0;
 
        spin_lock_bh(&adapter->mbx_lock);
 
        /* add VID to filter table */
-       err = hw->mac.ops.set_vfta(hw, vid, 0, true);
+       if (hw->mac.ops.set_vfta)
+               err = hw->mac.ops.set_vfta(hw, vid, 0, true);
 
        spin_unlock_bh(&adapter->mbx_lock);
 
@@ -1835,12 +1845,13 @@ static int ixgbevf_vlan_rx_kill_vid(struct

net_device *netdev,

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_write_uc_addr_list(struct

Quoted 16 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -2
 {
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
-       int err;
+       int err = 0;
 
        spin_lock_bh(&adapter->mbx_lock);
 
        /* remove VID from filter table */
-       err = hw->mac.ops.set_vfta(hw, vid, 0, false);
+       if (hw->mac.ops.set_vfta)
+               err = hw->mac.ops.set_vfta(hw, vid, 0, false);
 
        spin_unlock_bh(&adapter->mbx_lock);
 
@@ -1873,14 +1884,16 @@ static int ixgbevf_write_uc_addr_list(struct

net_device *netdev)

Quoted 17 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +4 -2
                struct netdev_hw_addr *ha;
 
                netdev_for_each_uc_addr(ha, netdev) {
-                       hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
+                       if (hw->mac.ops.set_uc_addr)
+                               hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
                        udelay(200);
                }
        } else {
                /* If the list is empty then send message to PF driver to
                 * clear all MAC VLANs on this VF.
                 */
-               hw->mac.ops.set_uc_addr(hw, 0, NULL);
+               if (hw->mac.ops.set_uc_addr)
+                       hw->mac.ops.set_uc_addr(hw, 0, NULL);
        }
 
Quoted 8 lines
Quoted 6 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_write_uc_addr_list(struct net_device *netdev) · line 1899

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        return count;

So if I am understanding this correctly it looks like you cannot read or write any addresses for this device. Would I be correct in assuming that you get to have the one unicast address that is provided by the PF and that is it?

That is what I have been told by the Windows folks at Intel.

Yeah, so I didn't see the other half of this patchset that has you using a software interface for the multicast and broadcast traffic. What I would recommend doing is just writing up a stub function you can put in vf.c that will allow you to avoid having to add all these if checks to the code.

Quoted 6 lines
Quoted 3 lines

If so we may want to look at possibly returning some sort of error on these calls so that we can configure the device to indicate that we cannot support any of these filters.

I will do that. So, I am going to check the device ID and return an error. Would IXGBE_NOT_IMPLEMENTED be appropriate?

I'd say don't bother returning an error. You can probably just stub out the function since if I recall correctly it is a void function anyway and doesn't provide a return value.

Quoted 11 lines
Quoted 11 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_set_rx_mode(struct

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
@@ -1908,10 +1921,13 @@ static void ixgbevf_set_rx_mode(struct

net_device *netdev)

Quoted 8 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -1
        spin_lock_bh(&adapter->mbx_lock);
 
-       hw->mac.ops.update_xcast_mode(hw, netdev, xcast_mode);
+       if (hw->mac.ops.update_mc_addr_list)
+               if (hw->mac.ops.update_xcast_mode)
+                       hw->mac.ops.update_xcast_mode(hw, netdev, xcast_mode);
 
Quoted 7 lines
Quoted 7 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_set_rx_mode(struct net_device *netdev) · line 1933

Quoted 7 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +2 -1
        /* reprogram multicast list */
-       hw->mac.ops.update_mc_addr_list(hw, netdev);
+       if (hw->mac.ops.update_mc_addr_list)
+               hw->mac.ops.update_mc_addr_list(hw, netdev);
 
        ixgbevf_write_uc_addr_list(netdev);
 

Same thing for the multicast list as well.

Quoted 17 lines
Quoted 17 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_up_complete(struct

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
@@ -2074,10 +2090,13 @@ static void ixgbevf_up_complete(struct

ixgbevf_adapter *adapter)

Quoted 15 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +7 -4
        spin_lock_bh(&adapter->mbx_lock);
 
-       if (is_valid_ether_addr(hw->mac.addr))
-               hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
-       else
-               hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);
+       if (is_valid_ether_addr(hw->mac.addr)) {
+               if (hw->mac.ops.set_rar)
+                       hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
+       } else {
+               if (hw->mac.ops.set_rar)
+                       hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);
+       }
 
Quoted 7 lines
Quoted 5 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_up_complete(struct · line 2101

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        spin_unlock_bh(&adapter->mbx_lock);
 

Same here. We shouldn't let the user set a MAC address that we cannot support. We should be returning an error.

Yes; I will return an error.

This is the one that needs to return an error. That way we should be able to prevent MAC address changes.

Quoted 103 lines
Quoted 18 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_set_mac(struct net_device

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
@@ -3672,14 +3691,15 @@ static int ixgbevf_set_mac(struct net_device

*netdev, void *p)

Quoted 15 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -2
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
        struct sockaddr *addr = p;
-       int err;
+       int err = 0;
 
        if (!is_valid_ether_addr(addr->sa_data))
                return -EADDRNOTAVAIL;
 
        spin_lock_bh(&adapter->mbx_lock);
 
-       err = hw->mac.ops.set_rar(hw, 0, addr->sa_data, 0);
+       if (hw->mac.ops.set_rar)
+               err = hw->mac.ops.set_rar(hw, 0, addr->sa_data, 0);
 
Quoted 5 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_set_mac(struct net_device · line 3705

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        spin_unlock_bh(&adapter->mbx_lock);
 

Specifically here. If hw->mac.ops.set_rar is NULL we cannot allow any MAC address change so we should probably return "-EADDRNOTAVAIL".

Will do.

Quoted 21 lines

Review

Quoted 2 lines
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/mbx.c

drivers/net/ethernet/intel/ixgbevf/mbx.c const struct ixgbe_mbx_operations

Quoted 4 lines

index dc68fea..298a0da 100644

drivers/net/ethernet/intel/ixgbevf/mbx.c +0 -0
@@ -346,3 +346,15 @@ const struct ixgbe_mbx_operations

ixgbevf_mbx_ops = {

Quoted 13 lines
drivers/net/ethernet/intel/ixgbevf/mbx.c +10 -0
        .check_for_rst  = ixgbevf_check_for_rst_vf,
 };
 
+/**
+ * Mailbox operations when running on Hyper-V.
+ * On Hyper-V, PF/VF communiction is not through the
+ * hardware mailbox; this communication is through
+ * a software mediated path.
+ * Most mail box operations are noop while running on
+ * Hyper-V.
+ */
+const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops = {
+       .init_params    = ixgbevf_init_mbx_params_vf,
Quoted 9 lines

drivers/net/ethernet/intel/ixgbevf/mbx.c const struct ixgbe_mbx_operations ixgbevf_mbx_ops = { · line 360

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/mbx.c +2 -0
+       .check_for_rst  = ixgbevf_check_for_rst_vf,
+};

I'd say if you aren't going to use a mailbox then don't initialize it. The code was based off of the same code that runs the ixgbe driver. It should be able to function without a mailbox provided the necessary calls are updated in the ixgbe_mac_operations that are used by the hyperv VF.

Ok; I will change the code.

Quoted 46 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/vf.c

drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw

Quoted 18 lines

index 4d613a4..92397fd 100644

drivers/net/ethernet/intel/ixgbevf/vf.c +7 -0
@@ -27,6 +27,13 @@
 #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.
+ */
+#define IXGBE_HV_RESET_OFFSET           0x201
+
 /**
  *  ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx
  *  @hw: pointer to hardware structure
@@ -126,6 +133,23 @@ static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw

*hw)

Quoted 9 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +6 -0
 }
 
 /**
+ * Hyper-V variant; the VF/PF communication is through the PCI
+ * config space.
+ */
+static s32 ixgbevf_hv_reset_hw_vf(struct ixgbe_hw *hw)
+{
+       int i;

drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw) · line 151

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10 -0
+       struct ixgbevf_adapter *adapter = hw->back;
+
+       for (i = 0; i < 6; i++)
+               pci_read_config_byte(adapter->pdev,
+                                    (i + IXGBE_HV_RESET_OFFSET),
+                                    &hw->mac.perm_addr[i]);
+
+       return 0;
+}
+

This bit can be problematic. What about the case where PCI_MMCONFIG is not defined. In such a case it will kill this function without reporting an error other than maybe a MAC address that is all 0s or all FF's.

Quoted 6 lines
Quoted 2 lines

You might want to add some sort of check here with some message if such a situation occurs just so it can be easier to debug.

I am a little confused here. This function will only execute when we are handling Hyper-V device IDs (while running on Hyper-V). Hyper-V PCI pass-through driver will support the config space access.

The kernel has a configuration option called CONFIG_PCI_MMCONFIG. On x86 it is usually enabled by default, but it can be disabled.

Right now this bit of code is dependent on it being enabled in order to function correctly. Otherwise you will only have access to the first 256 bytes of the PCI configuration space. You might want to explore the possibility of a Kconfig option that would allow you to only support the HyperV VFs if CONFIG_PCI_MMCONFIG is enabled.

Quoted 74 lines
Quoted 65 lines
Quoted 65 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +57 -0
+/**
  *  ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
  *  @hw: pointer to hardware structure
  *
@@ -656,6 +680,68 @@ out:
 }
 
 /**
+ * Hyper-V variant; there is no mailbox communication.
+ */
+static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,
+                                       ixgbe_link_speed *speed,
+                                       bool *link_up,
+                                       bool autoneg_wait_to_complete)
+{
+       struct ixgbe_mbx_info *mbx = &hw->mbx;
+       struct ixgbe_mac_info *mac = &hw->mac;
+       s32 ret_val = 0;
+       u32 links_reg;
+
+       /* If we were hit with a reset drop the link */
+       if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
+               mac->get_link_status = true;
+
+       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;
+
+       /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
+        * before the link status is correct
+        */
+       if (mac->type == ixgbe_mac_82599_vf) {
+               int i;
+
+               for (i = 0; i < 5; i++) {
+                       udelay(100);
+                       links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
+
+                       if (!(links_reg & IXGBE_LINKS_UP))
+                               goto out;
+               }
+       }
+
+       switch (links_reg & IXGBE_LINKS_SPEED_82599) {
+       case IXGBE_LINKS_SPEED_10G_82599:
+               *speed = IXGBE_LINK_SPEED_10GB_FULL;
+               break;
+       case IXGBE_LINKS_SPEED_1G_82599:
+               *speed = IXGBE_LINK_SPEED_1GB_FULL;
+               break;
+       case IXGBE_LINKS_SPEED_100_82599:
+               *speed = IXGBE_LINK_SPEED_100_FULL;
+               break;
+       }
+
+       /* if we passed all the tests above then the link is up and we no
+        * longer need to check for link
+        */
+       mac->get_link_status = false;
+
Quoted 8 lines

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 743

Quoted 5 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +5 -0
+out:
+       *link_up = !mac->get_link_status;
+       return ret_val;
+}
+

How does this handle the PF resetting? Seems like you are going to be generating Tx hangs in such a case.

Quoted 2 lines

I am not sure how the Windows PF driver communicates this information. Do you have any suggestions for this.

You might want to take a look at the fm10k_get_host_state_generic function. You could probably do something like the trick we did there with the TXDCTL in order to detect cases where the PF has reset the VF so that you could then reset your guest once the PF has come back up. That way at least you would report link down instead of Tx hang if the host has reset you.

Quoted 135 lines
Quoted 23 lines
Quoted 23 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +14 -0
+/**
  *  ixgbevf_rlpml_set_vf - Set the maximum receive packet length
  *  @hw: pointer to the HW structure
  *  @max_size: value to assign to max frame size
@@ -663,6 +749,19 @@ out:
 void ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
 {
        u32 msgbuf[2];
+       u32 reg;
+
+       if (x86_hyper == &x86_hyper_ms_hyperv) {
+               /*
+                * If we are on Hyper-V, we implement
+                * this functionality differently.
+                */
+               reg =  IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(0));
+               /* CRC == 4 */
+               reg |= ((max_size + 4) | IXGBE_RXDCTL_RLPML_EN);
+               IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(0), reg);
+               return;
+       }
 
Quoted 5 lines

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 767

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
        msgbuf[0] = IXGBE_VF_SET_LPE;
        msgbuf[1] = max_size;

You would be better off just implementing a hyperv version of this function and avoiding the mailbox call entirely.

Ok; will do.

Quoted 15 lines

drivers/net/ethernet/intel/ixgbevf/vf.c int ixgbevf_negotiate_api_version(struct

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
@@ -679,6 +778,16 @@ int ixgbevf_negotiate_api_version(struct

ixgbe_hw *hw, int api)

Quoted 12 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +9 -0
        int err;
        u32 msg[3];
 
+       if (x86_hyper == &x86_hyper_ms_hyperv) {
+               /*
+                * Hyper-V only supports api version ixgbe_mbox_api_10
+                */
+               if (api != ixgbe_mbox_api_10)
+                       return IXGBE_ERR_INVALID_ARGUMENT;
+
+               return 0;
+       }
Quoted 8 lines

drivers/net/ethernet/intel/ixgbevf/vf.c int ixgbevf_negotiate_api_version(struct ixgbe_hw *hw, int api) · line 793

Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +1 -0
+
        /* Negotiate the mailbox API version */
        msg[0] = IXGBE_VF_API_NEGOTIATE;
        msg[1] = api;

Same here. Just implement a hyperv version of this function instead of splicing into the existing call. Also you will need to wrap this code up so that we can build on all architectures, not just x86.

Ok; will do.

Quoted 6 lines

drivers/net/ethernet/intel/ixgbevf/vf.c static const struct ixgbe_mac_operations

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
@@ -776,22 +885,51 @@ static const struct ixgbe_mac_operations

ixgbevf_mac_ops = {

Quoted 3 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
        .set_vfta               = ixgbevf_set_vfta_vf,
 };
 
Quoted 13 lines

drivers/net/ethernet/intel/ixgbevf/vf.c static const struct ixgbe_mac_operations ixgbevf_mac_ops = { · line 896

Quoted 9 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +9 -0
+static const struct ixgbe_mac_operations ixgbevf_hv_mac_ops = {
+       .init_hw                = ixgbevf_init_hw_vf,
+       .reset_hw               = ixgbevf_hv_reset_hw_vf,
+       .start_hw               = ixgbevf_start_hw_vf,
+       .get_mac_addr           = ixgbevf_get_mac_addr_vf,
+       .stop_adapter           = ixgbevf_stop_hw_vf,
+       .setup_link             = ixgbevf_setup_mac_link_vf,
+       .check_link             = ixgbevf_hv_check_mac_link_vf,
+};

You might want to consider implementing a set_rar call that will return an error if you try to change the address to anything that is not the permanent addr.

Ok; will do.

Quoted 51 lines

Review

Quoted 41 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +20 -0
 const struct ixgbevf_info ixgbevf_82599_vf_info = {
        .mac = ixgbe_mac_82599_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_82599_vf_hv_info = {
+       .mac = ixgbe_mac_82599_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X540_vf_info = {
        .mac = ixgbe_mac_X540_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_X540_vf_hv_info = {
+       .mac = ixgbe_mac_X540_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X550_vf_info = {
        .mac = ixgbe_mac_X550_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_X550_vf_hv_info = {
+       .mac = ixgbe_mac_X550_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X550EM_x_vf_info = {
        .mac = ixgbe_mac_X550EM_x_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
+
+const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info = {
+       .mac = ixgbe_mac_X550EM_x_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/vf.h

Quoted 9 lines

index ef9f773..7242a97 100644

drivers/net/ethernet/intel/ixgbevf/vf.h +1 -0
@@ -32,7 +32,9 @@
 #include <linux/interrupt.h>
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
+#include <asm/hypervisor.h>
 
Quoted 7 lines

drivers/net/ethernet/intel/ixgbevf/vf.h line 37

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/vf.h +1 -0
+#include <asm/hypervisor.h>

I don't think you need to include this twice. Also this is a arch specific header file. You might want to move this to vf.c since that is where you are using the code it provides. Then you can probably wrap it in an X86 build check so that you don't break the build on other architectures.

Quoted 1 line

I will fix this. Thank you for your detailed comments.

Yeah, if we can get away from including this entirely it would be preferred. Odds are we probably don't need it since the device ID is unique to HyperV hosts anyway.

I'll keep an eye out for the next patch set.

- Alex

#15 lore raw

RE: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 379 lines

-----Original Message-----
From: Alexander Duyck [mailto:alexander.duyck at gmail.com]
Sent: Friday, April 15, 2016 8:40 AM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; Netdev <[email protected]>; linux-kernel at vger.kernel.org; devel at linuxdriverproject.org; olaf at aepfle.de; Robo Bot <[email protected]>; Jason Wang <[email protected]>;
eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com; John Ronciak <[email protected]>; intel-wired-lan <intel-wired- lan at lists.osuosl.org>
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 11 lines · KY Srinivasan
Quoted 11 lines

-----Original Message-----
From: Alexander Duyck [mailto:alexander.duyck at gmail.com]
Sent: Thursday, April 14, 2016 4:18 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; Netdev <[email protected]>; linux-kernel at vger.kernel.org; devel at linuxdriverproject.org; olaf at aepfle.de; Robo Bot <[email protected]>; Jason Wang <[email protected]>;
eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com;

John

Quoted 86 lines
Quoted 86 lines

Ronciak <[email protected]>; intel-wired-lan <intel-wired- lan at lists.osuosl.org>
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 10 lines · K. Y. Srinivasan

On Hyper-V, the VF/PF communication is a via software mediated path as opposed to the hardware mailbox. Make the necessary adjustments to support Hyper-V.

---
 drivers/net/ethernet/intel/ixgbevf/ixgbevf.h      |   11 ++
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c |   56 ++++++---
 drivers/net/ethernet/intel/ixgbevf/mbx.c          |   12 ++
 drivers/net/ethernet/intel/ixgbevf/vf.c           |  138

+++++++++++++++++++++

Review

Quoted 4 lines
 drivers/net/ethernet/intel/ixgbevf/vf.h           |    2 +
 5 files changed, 201 insertions(+), 18 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/ixgbevf.h

drivers/net/ethernet/intel/ixgbevf/ixgbevf.h extern const struct ixgbevf_info

Quoted 18 lines

index 5ac60ee..f8d2a0b 100644

drivers/net/ethernet/intel/ixgbevf/ixgbevf.h +4 -0
@@ -460,9 +460,13 @@ enum ixbgevf_state_t {
 
 enum ixgbevf_boards {
        board_82599_vf,
+       board_82599_vf_hv,
        board_X540_vf,
+       board_X540_vf_hv,
        board_X550_vf,
+       board_X550_vf_hv,
        board_X550EM_x_vf,
+       board_X550EM_x_vf_hv,
 };
 
 enum ixgbevf_xcast_modes {
@@ -477,6 +481,13 @@ extern const struct ixgbevf_info

ixgbevf_X550_vf_info;

Review

Quoted 14 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf.h +7 -0
 extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_info;
 extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops;
 
+
+extern const struct ixgbevf_info ixgbevf_82599_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X540_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X550_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info;
+extern const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops;
+
 /* needed by ethtool.c */
 extern const char ixgbevf_driver_name[];
 extern const char ixgbevf_driver_version[];
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c

Quoted 29 lines

index 007cbe0..4a0ffac 100644

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +9 -4
@@ -49,6 +49,7 @@
 #include <linux/if.h>
 #include <linux/if_vlan.h>
 #include <linux/prefetch.h>
+#include <asm/mshyperv.h>
 
 #include "ixgbevf.h"
 
@@ -62,10 +63,14 @@ static char ixgbevf_copyright[] =
        "Copyright (c) 2009 - 2015 Intel Corporation.";
 
 static const struct ixgbevf_info *ixgbevf_info_tbl[] = {
-       [board_82599_vf] = &ixgbevf_82599_vf_info,
-       [board_X540_vf]  = &ixgbevf_X540_vf_info,
-       [board_X550_vf]  = &ixgbevf_X550_vf_info,
-       [board_X550EM_x_vf] = &ixgbevf_X550EM_x_vf_info,
+       [board_82599_vf]        = &ixgbevf_82599_vf_info,
+       [board_82599_vf_hv]     = &ixgbevf_82599_vf_hv_info,
+       [board_X540_vf]         = &ixgbevf_X540_vf_info,
+       [board_X540_vf_hv]      = &ixgbevf_X540_vf_hv_info,
+       [board_X550_vf]         = &ixgbevf_X550_vf_info,
+       [board_X550_vf_hv]      = &ixgbevf_X550_vf_hv_info,
+       [board_X550EM_x_vf]     = &ixgbevf_X550EM_x_vf_info,
+       [board_X550EM_x_vf_hv]  = &ixgbevf_X550EM_x_vf_hv_info,
 };
 
Quoted 2 lines
Quoted 2 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
 /* ixgbevf_pci_tbl - PCI Device ID Table
@@ -78,9 +83,13 @@ static const struct ixgbevf_info

*ixgbevf_info_tbl[] =

Quoted 72 lines
Quoted 72 lines

{

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info *ixgbevf_info_tbl[] = {

Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
  */
 static const struct pci_device_id ixgbevf_pci_tbl[] = {
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF), board_82599_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF_HV),

board_82599_vf_hv },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info · line 88

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF), board_X540_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF_HV),

board_X540_vf_hv },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info · line 90

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550_VF), board_X550_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550_VF_HV),

board_X550_vf_hv },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info · line 91

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_VF),

board_X550EM_x_vf },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info · line 92

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_VF_HV),

board_X550EM_x_vf_hv},

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_vlan_rx_add_vid(struct

Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        /* required last entry */
        {0, }
 };
@@ -1809,12 +1818,13 @@ static int ixgbevf_vlan_rx_add_vid(struct

net_device *netdev,

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_vlan_rx_kill_vid(struct

Quoted 16 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -2
 {
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
-       int err;
+       int err = 0;
 
        spin_lock_bh(&adapter->mbx_lock);
 
        /* add VID to filter table */
-       err = hw->mac.ops.set_vfta(hw, vid, 0, true);
+       if (hw->mac.ops.set_vfta)
+               err = hw->mac.ops.set_vfta(hw, vid, 0, true);
 
        spin_unlock_bh(&adapter->mbx_lock);
 
@@ -1835,12 +1845,13 @@ static int ixgbevf_vlan_rx_kill_vid(struct

net_device *netdev,

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_write_uc_addr_list(struct

Quoted 16 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -2
 {
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
-       int err;
+       int err = 0;
 
        spin_lock_bh(&adapter->mbx_lock);
 
        /* remove VID from filter table */
-       err = hw->mac.ops.set_vfta(hw, vid, 0, false);
+       if (hw->mac.ops.set_vfta)
+               err = hw->mac.ops.set_vfta(hw, vid, 0, false);
 
        spin_unlock_bh(&adapter->mbx_lock);
 
@@ -1873,14 +1884,16 @@ static int ixgbevf_write_uc_addr_list(struct

net_device *netdev)

Quoted 17 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +4 -2
                struct netdev_hw_addr *ha;
 
                netdev_for_each_uc_addr(ha, netdev) {
-                       hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
+                       if (hw->mac.ops.set_uc_addr)
+                               hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
                        udelay(200);
                }
        } else {
                /* If the list is empty then send message to PF driver to
                 * clear all MAC VLANs on this VF.
                 */
-               hw->mac.ops.set_uc_addr(hw, 0, NULL);
+               if (hw->mac.ops.set_uc_addr)
+                       hw->mac.ops.set_uc_addr(hw, 0, NULL);
        }
 
Quoted 8 lines
Quoted 6 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_write_uc_addr_list(struct net_device *netdev) · line 1899

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        return count;

So if I am understanding this correctly it looks like you cannot read or write any addresses for this device. Would I be correct in assuming that you get to have the one unicast address that is provided by the PF and that is it?

That is what I have been told by the Windows folks at Intel.

Yeah, so I didn't see the other half of this patchset that has you using a software interface for the multicast and broadcast traffic. What I would recommend doing is just writing up a stub function you can put in vf.c that will allow you to avoid having to add all these if checks to the code.

Quoted 6 lines
Quoted 3 lines

If so we may want to look at possibly returning some sort of error on these calls so that we can configure the device to indicate that we cannot support any of these filters.

I will do that. So, I am going to check the device ID and return an error. Would IXGBE_NOT_IMPLEMENTED be appropriate?

I'd say don't bother returning an error. You can probably just stub out the function since if I recall correctly it is a void function anyway and doesn't provide a return value.

Quoted 10 lines
Quoted 10 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_set_rx_mode(struct

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
@@ -1908,10 +1921,13 @@ static void ixgbevf_set_rx_mode(struct

net_device *netdev)

Quoted 7 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -1
        spin_lock_bh(&adapter->mbx_lock);
 
-       hw->mac.ops.update_xcast_mode(hw, netdev, xcast_mode);
+       if (hw->mac.ops.update_mc_addr_list)
+               if (hw->mac.ops.update_xcast_mode)
+                       hw->mac.ops.update_xcast_mode(hw, netdev,

xcast_mode);

Quoted 8 lines
Quoted 8 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_set_rx_mode(struct net_device *netdev) · line 1933

Quoted 8 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +2 -1
        /* reprogram multicast list */
-       hw->mac.ops.update_mc_addr_list(hw, netdev);
+       if (hw->mac.ops.update_mc_addr_list)
+               hw->mac.ops.update_mc_addr_list(hw, netdev);
 
        ixgbevf_write_uc_addr_list(netdev);
 

Same thing for the multicast list as well.

Quoted 17 lines
Quoted 17 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_up_complete(struct

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
@@ -2074,10 +2090,13 @@ static void ixgbevf_up_complete(struct

ixgbevf_adapter *adapter)

Quoted 15 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +7 -4
        spin_lock_bh(&adapter->mbx_lock);
 
-       if (is_valid_ether_addr(hw->mac.addr))
-               hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
-       else
-               hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);
+       if (is_valid_ether_addr(hw->mac.addr)) {
+               if (hw->mac.ops.set_rar)
+                       hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
+       } else {
+               if (hw->mac.ops.set_rar)
+                       hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);
+       }
 
Quoted 7 lines
Quoted 5 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_up_complete(struct · line 2101

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        spin_unlock_bh(&adapter->mbx_lock);
 

Same here. We shouldn't let the user set a MAC address that we cannot support. We should be returning an error.

Yes; I will return an error.

This is the one that needs to return an error. That way we should be able to prevent MAC address changes.

Quoted 66 lines
Quoted 18 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_set_mac(struct net_device

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
@@ -3672,14 +3691,15 @@ static int ixgbevf_set_mac(struct net_device

*netdev, void *p)

Quoted 15 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -2
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
        struct sockaddr *addr = p;
-       int err;
+       int err = 0;
 
        if (!is_valid_ether_addr(addr->sa_data))
                return -EADDRNOTAVAIL;
 
        spin_lock_bh(&adapter->mbx_lock);
 
-       err = hw->mac.ops.set_rar(hw, 0, addr->sa_data, 0);
+       if (hw->mac.ops.set_rar)
+               err = hw->mac.ops.set_rar(hw, 0, addr->sa_data, 0);
 
Quoted 5 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_set_mac(struct net_device · line 3705

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        spin_unlock_bh(&adapter->mbx_lock);
 

Specifically here. If hw->mac.ops.set_rar is NULL we cannot allow any MAC address change so we should probably return "-EADDRNOTAVAIL".

Will do.

Quoted 21 lines

Review

Quoted 2 lines
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/mbx.c

drivers/net/ethernet/intel/ixgbevf/mbx.c const struct ixgbe_mbx_operations

Quoted 4 lines

index dc68fea..298a0da 100644

drivers/net/ethernet/intel/ixgbevf/mbx.c +0 -0
@@ -346,3 +346,15 @@ const struct ixgbe_mbx_operations

ixgbevf_mbx_ops = {

Quoted 13 lines
drivers/net/ethernet/intel/ixgbevf/mbx.c +10 -0
        .check_for_rst  = ixgbevf_check_for_rst_vf,
 };
 
+/**
+ * Mailbox operations when running on Hyper-V.
+ * On Hyper-V, PF/VF communiction is not through the
+ * hardware mailbox; this communication is through
+ * a software mediated path.
+ * Most mail box operations are noop while running on
+ * Hyper-V.
+ */
+const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops = {
+       .init_params    = ixgbevf_init_mbx_params_vf,
Quoted 9 lines

drivers/net/ethernet/intel/ixgbevf/mbx.c const struct ixgbe_mbx_operations ixgbevf_mbx_ops = { · line 360

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/mbx.c +2 -0
+       .check_for_rst  = ixgbevf_check_for_rst_vf,
+};

I'd say if you aren't going to use a mailbox then don't initialize it. The code was based off of the same code that runs the ixgbe driver. It should be able to function without a mailbox provided the necessary calls are updated in the ixgbe_mac_operations that are used by the hyperv VF.

Ok; I will change the code.

Quoted 9 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/vf.c

Quoted 7 lines

index 4d613a4..92397fd 100644

drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
@@ -27,6 +27,13 @@
 #include "vf.h"
 #include "ixgbevf.h"
 
Quoted 11 lines
Quoted 11 lines

drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_reset_hw_vf(struct

Quoted 11 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +7 -0
+/*
+ * 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.
+ */
+#define IXGBE_HV_RESET_OFFSET           0x201
+
 /**
  *  ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx
  *  @hw: pointer to hardware structure
@@ -126,6 +133,23 @@ static s32 ixgbevf_reset_hw_vf(struct

ixgbe_hw

Quoted 26 lines
Quoted 26 lines

*hw)

Quoted 9 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +6 -0
 }
 
 /**
+ * Hyper-V variant; the VF/PF communication is through the PCI
+ * config space.
+ */
+static s32 ixgbevf_hv_reset_hw_vf(struct ixgbe_hw *hw)
+{
+       int i;

drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw) · line 151

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10 -0
+       struct ixgbevf_adapter *adapter = hw->back;
+
+       for (i = 0; i < 6; i++)
+               pci_read_config_byte(adapter->pdev,
+                                    (i + IXGBE_HV_RESET_OFFSET),
+                                    &hw->mac.perm_addr[i]);
+
+       return 0;
+}
+

This bit can be problematic. What about the case where PCI_MMCONFIG is not defined. In such a case it will kill this function without reporting an error other than maybe a MAC address that is all 0s or all FF's.

Quoted 4 lines
Quoted 2 lines

You might want to add some sort of check here with some message if such a situation occurs just so it can be easier to debug.

I am a little confused here. This function will only execute when we are

handling Hyper-V

Quoted 1 line

device IDs (while running on Hyper-V). Hyper-V PCI pass-through driver will

support the

Quoted 1 line

config space access.

Quoted 8 lines

The kernel has a configuration option called CONFIG_PCI_MMCONFIG. On x86 it is usually enabled by default, but it can be disabled.

Right now this bit of code is dependent on it being enabled in order to function correctly. Otherwise you will only have access to the first 256 bytes of the PCI configuration space. You might want to explore the possibility of a Kconfig option that would allow you to only support the HyperV VFs if CONFIG_PCI_MMCONFIG is enabled.

Our PCI pss-through driver depends on this functionality. I will make sure we Make that dependency more explicit.

Quoted 79 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +18 -0
+/**
  *  ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
  *  @hw: pointer to hardware structure
  *
@@ -656,6 +680,68 @@ out:
 }
 
 /**
+ * Hyper-V variant; there is no mailbox communication.
+ */
+static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,
+                                       ixgbe_link_speed *speed,
+                                       bool *link_up,
+                                       bool autoneg_wait_to_complete)
+{
+       struct ixgbe_mbx_info *mbx = &hw->mbx;
+       struct ixgbe_mac_info *mac = &hw->mac;
+       s32 ret_val = 0;
+       u32 links_reg;
+
+       /* If we were hit with a reset drop the link */
+       if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
+               mac->get_link_status = true;
+
+       if (!mac->get_link_status)
Quoted 8 lines
Quoted 8 lines

drivers/net/ethernet/intel/ixgbevf/vf.c out:

Quoted 8 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +8 -0
+               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;
+
+       /* for SFP+ modules and DA cables on 82599 it can take up to

500usecs

Quoted 40 lines
Quoted 31 lines
Quoted 31 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +31 -0
+        * before the link status is correct
+        */
+       if (mac->type == ixgbe_mac_82599_vf) {
+               int i;
+
+               for (i = 0; i < 5; i++) {
+                       udelay(100);
+                       links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
+
+                       if (!(links_reg & IXGBE_LINKS_UP))
+                               goto out;
+               }
+       }
+
+       switch (links_reg & IXGBE_LINKS_SPEED_82599) {
+       case IXGBE_LINKS_SPEED_10G_82599:
+               *speed = IXGBE_LINK_SPEED_10GB_FULL;
+               break;
+       case IXGBE_LINKS_SPEED_1G_82599:
+               *speed = IXGBE_LINK_SPEED_1GB_FULL;
+               break;
+       case IXGBE_LINKS_SPEED_100_82599:
+               *speed = IXGBE_LINK_SPEED_100_FULL;
+               break;
+       }
+
+       /* if we passed all the tests above then the link is up and we no
+        * longer need to check for link
+        */
+       mac->get_link_status = false;
+
Quoted 8 lines

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 743

Quoted 5 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +5 -0
+out:
+       *link_up = !mac->get_link_status;
+       return ret_val;
+}
+

How does this handle the PF resetting? Seems like you are going to be generating Tx hangs in such a case.

Quoted 2 lines

I am not sure how the Windows PF driver communicates this information. Do you have any suggestions for this.

Quoted 6 lines

You might want to take a look at the fm10k_get_host_state_generic function. You could probably do something like the trick we did there with the TXDCTL in order to detect cases where the PF has reset the VF so that you could then reset your guest once the PF has come back up. That way at least you would report link down instead of Tx hang if the host has reset you.

I will take a look at your example; thank you.

Quoted 136 lines
Quoted 136 lines
Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +14 -0
+/**
  *  ixgbevf_rlpml_set_vf - Set the maximum receive packet length
  *  @hw: pointer to the HW structure
  *  @max_size: value to assign to max frame size
@@ -663,6 +749,19 @@ out:
 void ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
 {
        u32 msgbuf[2];
+       u32 reg;
+
+       if (x86_hyper == &x86_hyper_ms_hyperv) {
+               /*
+                * If we are on Hyper-V, we implement
+                * this functionality differently.
+                */
+               reg =  IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(0));
+               /* CRC == 4 */
+               reg |= ((max_size + 4) | IXGBE_RXDCTL_RLPML_EN);
+               IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(0), reg);
+               return;
+       }
 
Quoted 5 lines

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 767

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
        msgbuf[0] = IXGBE_VF_SET_LPE;
        msgbuf[1] = max_size;

You would be better off just implementing a hyperv version of this function and avoiding the mailbox call entirely.

Ok; will do.

Quoted 15 lines

drivers/net/ethernet/intel/ixgbevf/vf.c int ixgbevf_negotiate_api_version(struct

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
@@ -679,6 +778,16 @@ int ixgbevf_negotiate_api_version(struct

ixgbe_hw *hw, int api)

Quoted 12 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +9 -0
        int err;
        u32 msg[3];
 
+       if (x86_hyper == &x86_hyper_ms_hyperv) {
+               /*
+                * Hyper-V only supports api version ixgbe_mbox_api_10
+                */
+               if (api != ixgbe_mbox_api_10)
+                       return IXGBE_ERR_INVALID_ARGUMENT;
+
+               return 0;
+       }
Quoted 8 lines

drivers/net/ethernet/intel/ixgbevf/vf.c int ixgbevf_negotiate_api_version(struct ixgbe_hw *hw, int api) · line 793

Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +1 -0
+
        /* Negotiate the mailbox API version */
        msg[0] = IXGBE_VF_API_NEGOTIATE;
        msg[1] = api;

Same here. Just implement a hyperv version of this function instead of splicing into the existing call. Also you will need to wrap this code up so that we can build on all architectures, not just x86.

Ok; will do.

Quoted 6 lines

drivers/net/ethernet/intel/ixgbevf/vf.c static const struct ixgbe_mac_operations

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
@@ -776,22 +885,51 @@ static const struct ixgbe_mac_operations

ixgbevf_mac_ops = {

Quoted 3 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
        .set_vfta               = ixgbevf_set_vfta_vf,
 };
 
Quoted 13 lines

drivers/net/ethernet/intel/ixgbevf/vf.c static const struct ixgbe_mac_operations ixgbevf_mac_ops = { · line 896

Quoted 9 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +9 -0
+static const struct ixgbe_mac_operations ixgbevf_hv_mac_ops = {
+       .init_hw                = ixgbevf_init_hw_vf,
+       .reset_hw               = ixgbevf_hv_reset_hw_vf,
+       .start_hw               = ixgbevf_start_hw_vf,
+       .get_mac_addr           = ixgbevf_get_mac_addr_vf,
+       .stop_adapter           = ixgbevf_stop_hw_vf,
+       .setup_link             = ixgbevf_setup_mac_link_vf,
+       .check_link             = ixgbevf_hv_check_mac_link_vf,
+};

You might want to consider implementing a set_rar call that will return an error if you try to change the address to anything that is not the permanent addr.

Ok; will do.

Quoted 58 lines

Review

Quoted 41 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +20 -0
 const struct ixgbevf_info ixgbevf_82599_vf_info = {
        .mac = ixgbe_mac_82599_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_82599_vf_hv_info = {
+       .mac = ixgbe_mac_82599_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X540_vf_info = {
        .mac = ixgbe_mac_X540_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_X540_vf_hv_info = {
+       .mac = ixgbe_mac_X540_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X550_vf_info = {
        .mac = ixgbe_mac_X550_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
 
+const struct ixgbevf_info ixgbevf_X550_vf_hv_info = {
+       .mac = ixgbe_mac_X550_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
+
 const struct ixgbevf_info ixgbevf_X550EM_x_vf_info = {
        .mac = ixgbe_mac_X550EM_x_vf,
        .mac_ops = &ixgbevf_mac_ops,
 };
+
+const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info = {
+       .mac = ixgbe_mac_X550EM_x_vf,
+       .mac_ops = &ixgbevf_hv_mac_ops,
+};
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/vf.h

drivers/net/ethernet/intel/ixgbevf/vf.h line 37

Quoted 10 lines

index ef9f773..7242a97 100644

drivers/net/ethernet/intel/ixgbevf/vf.h +2 -0
@@ -32,7 +32,9 @@
 #include <linux/interrupt.h>
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
+#include <asm/hypervisor.h>
 
+#include <asm/hypervisor.h>

I don't think you need to include this twice. Also this is a arch specific header file. You might want to move this to vf.c since that is where you are using the code it provides. Then you can probably wrap it in an X86 build check so that you don't break the build on other architectures.

Quoted 7 lines
Quoted 1 line

I will fix this. Thank you for your detailed comments.

Yeah, if we can get away from including this entirely it would be preferred. Odds are we probably don't need it since the device ID is unique to HyperV hosts anyway.

I'll keep an eye out for the next patch set.

Thank you; really appreciate all your help.

Regards,

K. Y

Quoted 2 lines

- Alex

#16 lore raw

RE: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 283 lines

-----Original Message-----
From: KY Srinivasan
Sent: Friday, April 15, 2016 9:01 AM
To: 'Alexander Duyck' <[email protected]>
Cc: David Miller <[email protected]>; Netdev <[email protected]>; linux-kernel at vger.kernel.org; devel at linuxdriverproject.org; olaf at aepfle.de; Robo Bot <[email protected]>; Jason Wang <[email protected]>;
eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com; John Ronciak <[email protected]>; intel-wired-lan <intel-wired- lan at lists.osuosl.org>
Subject: RE: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

Quoted 15 lines

-----Original Message-----
From: Alexander Duyck [mailto:alexander.duyck at gmail.com]
Sent: Friday, April 15, 2016 8:40 AM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; Netdev <[email protected]>; linux-kernel at vger.kernel.org; devel at linuxdriverproject.org; olaf at aepfle.de; Robo Bot <[email protected]>; Jason Wang <[email protected]>;
eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com; John Ronciak <[email protected]>; intel-wired-lan <intel-wired- lan at lists.osuosl.org>
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows hosts (Hyper-V)

On Thu, Apr 14, 2016 at 7:49 PM, KY Srinivasan <[email protected]>

Quoted 11 lines · wrote:
Quoted 11 lines
Quoted 11 lines

-----Original Message-----
From: Alexander Duyck [mailto:alexander.duyck at gmail.com]
Sent: Thursday, April 14, 2016 4:18 PM
To: KY Srinivasan <[email protected]>
Cc: David Miller <[email protected]>; Netdev <[email protected]>; linux-kernel at vger.kernel.org; devel at linuxdriverproject.org; olaf at aepfle.de; Robo Bot <[email protected]>; Jason Wang <[email protected]>;
eli at mellanox.com; jackm at mellanox.com; yevgenyp at mellanox.com;

Quoted 4 lines

John

Quoted 3 lines
Quoted 3 lines

Ronciak <[email protected]>; intel-wired-lan <intel-wired- lan at lists.osuosl.org>
Subject: Re: [PATCH net-next 2/2] intel: ixgbevf: Support Windows

hosts

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

(Hyper-V)

Quoted 1 line · K. Y. Srinivasan

On Hyper-V, the VF/PF communication is a via software mediated

path

Quoted 78 lines
Quoted 78 lines
Quoted 78 lines
Quoted 9 lines

as opposed to the hardware mailbox. Make the necessary adjustments to support Hyper-V.

---
 drivers/net/ethernet/intel/ixgbevf/ixgbevf.h      |   11 ++
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c |   56 ++++++---
 drivers/net/ethernet/intel/ixgbevf/mbx.c          |   12 ++
 drivers/net/ethernet/intel/ixgbevf/vf.c           |  138

+++++++++++++++++++++

Review

Quoted 4 lines
 drivers/net/ethernet/intel/ixgbevf/vf.h           |    2 +
 5 files changed, 201 insertions(+), 18 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/ixgbevf.h

drivers/net/ethernet/intel/ixgbevf/ixgbevf.h extern const struct ixgbevf_info

Quoted 18 lines

index 5ac60ee..f8d2a0b 100644

drivers/net/ethernet/intel/ixgbevf/ixgbevf.h +4 -0
@@ -460,9 +460,13 @@ enum ixbgevf_state_t {
 
 enum ixgbevf_boards {
        board_82599_vf,
+       board_82599_vf_hv,
        board_X540_vf,
+       board_X540_vf_hv,
        board_X550_vf,
+       board_X550_vf_hv,
        board_X550EM_x_vf,
+       board_X550EM_x_vf_hv,
 };
 
 enum ixgbevf_xcast_modes {
@@ -477,6 +481,13 @@ extern const struct ixgbevf_info

ixgbevf_X550_vf_info;

Review

Quoted 14 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf.h +7 -0
 extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_info;
 extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops;
 
+
+extern const struct ixgbevf_info ixgbevf_82599_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X540_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X550_vf_hv_info;
+extern const struct ixgbevf_info ixgbevf_X550EM_x_vf_hv_info;
+extern const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops;
+
 /* needed by ethtool.c */
 extern const char ixgbevf_driver_name[];
 extern const char ixgbevf_driver_version[];
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c

Quoted 29 lines

index 007cbe0..4a0ffac 100644

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +9 -4
@@ -49,6 +49,7 @@
 #include <linux/if.h>
 #include <linux/if_vlan.h>
 #include <linux/prefetch.h>
+#include <asm/mshyperv.h>
 
 #include "ixgbevf.h"
 
@@ -62,10 +63,14 @@ static char ixgbevf_copyright[] =
        "Copyright (c) 2009 - 2015 Intel Corporation.";
 
 static const struct ixgbevf_info *ixgbevf_info_tbl[] = {
-       [board_82599_vf] = &ixgbevf_82599_vf_info,
-       [board_X540_vf]  = &ixgbevf_X540_vf_info,
-       [board_X550_vf]  = &ixgbevf_X550_vf_info,
-       [board_X550EM_x_vf] = &ixgbevf_X550EM_x_vf_info,
+       [board_82599_vf]        = &ixgbevf_82599_vf_info,
+       [board_82599_vf_hv]     = &ixgbevf_82599_vf_hv_info,
+       [board_X540_vf]         = &ixgbevf_X540_vf_info,
+       [board_X540_vf_hv]      = &ixgbevf_X540_vf_hv_info,
+       [board_X550_vf]         = &ixgbevf_X550_vf_info,
+       [board_X550_vf_hv]      = &ixgbevf_X550_vf_hv_info,
+       [board_X550EM_x_vf]     = &ixgbevf_X550EM_x_vf_info,
+       [board_X550EM_x_vf_hv]  = &ixgbevf_X550EM_x_vf_hv_info,
 };
 
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
 /* ixgbevf_pci_tbl - PCI Device ID Table
@@ -78,9 +83,13 @@ static const struct ixgbevf_info

*ixgbevf_info_tbl[] =

Quoted 4 lines
Quoted 4 lines

{

Quoted 3 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
  */
 static const struct pci_device_id ixgbevf_pci_tbl[] = {
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF), board_82599_vf

},

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info · line 86

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF_HV),

board_82599_vf_hv },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info · line 88

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF), board_X540_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF_HV),

board_X540_vf_hv },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info · line 90

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550_VF), board_X550_vf },
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550_VF_HV),

board_X550_vf_hv },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info · line 91

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_VF),

board_X550EM_x_vf },

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static const struct ixgbevf_info · line 92

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
+       {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_VF_HV),

board_X550EM_x_vf_hv},

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_vlan_rx_add_vid(struct

Quoted 4 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        /* required last entry */
        {0, }
 };
@@ -1809,12 +1818,13 @@ static int ixgbevf_vlan_rx_add_vid(struct

net_device *netdev,

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_vlan_rx_kill_vid(struct

Quoted 16 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -2
 {
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
-       int err;
+       int err = 0;
 
        spin_lock_bh(&adapter->mbx_lock);
 
        /* add VID to filter table */
-       err = hw->mac.ops.set_vfta(hw, vid, 0, true);
+       if (hw->mac.ops.set_vfta)
+               err = hw->mac.ops.set_vfta(hw, vid, 0, true);
 
        spin_unlock_bh(&adapter->mbx_lock);
 
@@ -1835,12 +1845,13 @@ static int ixgbevf_vlan_rx_kill_vid(struct

net_device *netdev,

Quoted 8 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -1
 {
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
-       int err;
+       int err = 0;
 
        spin_lock_bh(&adapter->mbx_lock);
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int

Quoted 8 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +2 -1
        /* remove VID from filter table */
-       err = hw->mac.ops.set_vfta(hw, vid, 0, false);
+       if (hw->mac.ops.set_vfta)
+               err = hw->mac.ops.set_vfta(hw, vid, 0, false);
 
        spin_unlock_bh(&adapter->mbx_lock);
 
@@ -1873,14 +1884,16 @@ static int

ixgbevf_write_uc_addr_list(struct

Quoted 61 lines
Quoted 18 lines
Quoted 18 lines

net_device *netdev)

Quoted 17 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +4 -2
                struct netdev_hw_addr *ha;
 
                netdev_for_each_uc_addr(ha, netdev) {
-                       hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
+                       if (hw->mac.ops.set_uc_addr)
+                               hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
                        udelay(200);
                }
        } else {
                /* If the list is empty then send message to PF driver to
                 * clear all MAC VLANs on this VF.
                 */
-               hw->mac.ops.set_uc_addr(hw, 0, NULL);
+               if (hw->mac.ops.set_uc_addr)
+                       hw->mac.ops.set_uc_addr(hw, 0, NULL);
        }
 
Quoted 8 lines
Quoted 6 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_write_uc_addr_list(struct net_device *netdev) · line 1899

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        return count;

So if I am understanding this correctly it looks like you cannot read or write any addresses for this device. Would I be correct in assuming that you get to have the one unicast address that is provided by the PF and that is it?

That is what I have been told by the Windows folks at Intel.

Yeah, so I didn't see the other half of this patchset that has you using a software interface for the multicast and broadcast traffic. What I would recommend doing is just writing up a stub function you can put in vf.c that will allow you to avoid having to add all these if checks to the code.

Quoted 6 lines
Quoted 3 lines

If so we may want to look at possibly returning some sort of error on these calls so that we can configure the device to indicate that we cannot support any of these filters.

I will do that. So, I am going to check the device ID and return an error. Would IXGBE_NOT_IMPLEMENTED be appropriate?

I'd say don't bother returning an error. You can probably just stub out the function since if I recall correctly it is a void function anyway and doesn't provide a return value.

Quoted 10 lines
Quoted 10 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_set_rx_mode(struct

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
@@ -1908,10 +1921,13 @@ static void ixgbevf_set_rx_mode(struct

net_device *netdev)

Quoted 7 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -1
        spin_lock_bh(&adapter->mbx_lock);
 
-       hw->mac.ops.update_xcast_mode(hw, netdev, xcast_mode);
+       if (hw->mac.ops.update_mc_addr_list)
+               if (hw->mac.ops.update_xcast_mode)
+                       hw->mac.ops.update_xcast_mode(hw, netdev,

xcast_mode);

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +2 -1
        /* reprogram multicast list */
-       hw->mac.ops.update_mc_addr_list(hw, netdev);
+       if (hw->mac.ops.update_mc_addr_list)
+               hw->mac.ops.update_mc_addr_list(hw, netdev);
 
Quoted 26 lines
Quoted 2 lines
Quoted 2 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_set_rx_mode(struct net_device *netdev) · line 1933

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        ixgbevf_write_uc_addr_list(netdev);
 

Same thing for the multicast list as well.

Quoted 21 lines
Quoted 21 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_up_complete(struct

Quoted 1 line
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
@@ -2074,10 +2090,13 @@ static void ixgbevf_up_complete(struct

ixgbevf_adapter *adapter)

Quoted 7 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -4
        spin_lock_bh(&adapter->mbx_lock);
 
-       if (is_valid_ether_addr(hw->mac.addr))
-               hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
-       else
-               hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static void ixgbevf_up_complete(struct ixgbevf_adapter *adapter) · line 2102

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +7 -0
+       if (is_valid_ether_addr(hw->mac.addr)) {
+               if (hw->mac.ops.set_rar)
+                       hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
+       } else {
+               if (hw->mac.ops.set_rar)
+                       hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);
+       }
 
        spin_unlock_bh(&adapter->mbx_lock);
 

Same here. We shouldn't let the user set a MAC address that we

cannot

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

support. We should be returning an error.

Quoted 62 lines
Quoted 7 lines
Quoted 1 line

Yes; I will return an error.

This is the one that needs to return an error. That way we should be able to prevent MAC address changes.

Quoted 2 lines
Quoted 2 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_set_mac(struct

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
@@ -3672,14 +3691,15 @@ static int ixgbevf_set_mac(struct

net_device

Quoted 54 lines
Quoted 54 lines
Quoted 16 lines

*netdev, void *p)

Quoted 15 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +3 -2
        struct ixgbevf_adapter *adapter = netdev_priv(netdev);
        struct ixgbe_hw *hw = &adapter->hw;
        struct sockaddr *addr = p;
-       int err;
+       int err = 0;
 
        if (!is_valid_ether_addr(addr->sa_data))
                return -EADDRNOTAVAIL;
 
        spin_lock_bh(&adapter->mbx_lock);
 
-       err = hw->mac.ops.set_rar(hw, 0, addr->sa_data, 0);
+       if (hw->mac.ops.set_rar)
+               err = hw->mac.ops.set_rar(hw, 0, addr->sa_data, 0);
 
Quoted 5 lines

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c static int ixgbevf_set_mac(struct · line 3705

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -0
        spin_unlock_bh(&adapter->mbx_lock);
 

Specifically here. If hw->mac.ops.set_rar is NULL we cannot allow any MAC address change so we should probably return "-EADDRNOTAVAIL".

Will do.

Quoted 21 lines

Review

Quoted 2 lines
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/mbx.c

drivers/net/ethernet/intel/ixgbevf/mbx.c const struct ixgbe_mbx_operations

Quoted 4 lines

index dc68fea..298a0da 100644

drivers/net/ethernet/intel/ixgbevf/mbx.c +0 -0
@@ -346,3 +346,15 @@ const struct ixgbe_mbx_operations

ixgbevf_mbx_ops = {

Quoted 13 lines
drivers/net/ethernet/intel/ixgbevf/mbx.c +10 -0
        .check_for_rst  = ixgbevf_check_for_rst_vf,
 };
 
+/**
+ * Mailbox operations when running on Hyper-V.
+ * On Hyper-V, PF/VF communiction is not through the
+ * hardware mailbox; this communication is through
+ * a software mediated path.
+ * Most mail box operations are noop while running on
+ * Hyper-V.
+ */
+const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops = {
+       .init_params    = ixgbevf_init_mbx_params_vf,
Quoted 9 lines

drivers/net/ethernet/intel/ixgbevf/mbx.c const struct ixgbe_mbx_operations ixgbevf_mbx_ops = { · line 360

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/mbx.c +2 -0
+       .check_for_rst  = ixgbevf_check_for_rst_vf,
+};

I'd say if you aren't going to use a mailbox then don't initialize it. The code was based off of the same code that runs the ixgbe driver. It should be able to function without a mailbox provided the necessary calls are updated in the ixgbe_mac_operations that are used by the hyperv VF.

Ok; I will change the code.

As I am working on addressing your comments, while most mailbox operations are not used, the mechanism for checking for reset (check_for_rst) is identical even on Hyper-V. So keeping Hyper-V specific mailbox operations may actually result in fewer changes. I will shortly send you the updated patch for your review.

Quoted 149 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/ixgbevf/vf.c

Quoted 7 lines

index 4d613a4..92397fd 100644

drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
@@ -27,6 +27,13 @@
 #include "vf.h"
 #include "ixgbevf.h"
 
Quoted 34 lines
Quoted 11 lines
Quoted 11 lines

drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_reset_hw_vf(struct

Quoted 11 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +7 -0
+/*
+ * 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.
+ */
+#define IXGBE_HV_RESET_OFFSET           0x201
+
 /**
  *  ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx
  *  @hw: pointer to hardware structure
@@ -126,6 +133,23 @@ static s32 ixgbevf_reset_hw_vf(struct

ixgbe_hw

Quoted 22 lines
Quoted 22 lines

*hw)

Quoted 9 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +6 -0
 }
 
 /**
+ * Hyper-V variant; the VF/PF communication is through the PCI
+ * config space.
+ */
+static s32 ixgbevf_hv_reset_hw_vf(struct ixgbe_hw *hw)
+{
+       int i;

drivers/net/ethernet/intel/ixgbevf/vf.c static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw) · line 151

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +10 -0
+       struct ixgbevf_adapter *adapter = hw->back;
+
+       for (i = 0; i < 6; i++)
+               pci_read_config_byte(adapter->pdev,
+                                    (i + IXGBE_HV_RESET_OFFSET),
+                                    &hw->mac.perm_addr[i]);
+
+       return 0;
+}
+

This bit can be problematic. What about the case where

PCI_MMCONFIG

Quoted 10 lines
Quoted 8 lines
Quoted 6 lines

is not defined. In such a case it will kill this function without reporting an error other than maybe a MAC address that is all 0s or all FF's.

You might want to add some sort of check here with some message if such a situation occurs just so it can be easier to debug.

I am a little confused here. This function will only execute when we are

handling Hyper-V

Quoted 1 line

device IDs (while running on Hyper-V). Hyper-V PCI pass-through driver

will

Quoted 11 lines

support the

Quoted 1 line

config space access.

The kernel has a configuration option called CONFIG_PCI_MMCONFIG. On x86 it is usually enabled by default, but it can be disabled.

Right now this bit of code is dependent on it being enabled in order to function correctly. Otherwise you will only have access to the first 256 bytes of the PCI configuration space. You might want to explore the possibility of a Kconfig option that would allow you to only support the HyperV VFs if CONFIG_PCI_MMCONFIG is enabled.

Our PCI pss-through driver depends on this functionality. I will make sure we Make that dependency more explicit.

Quoted 79 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +18 -0
+/**
  *  ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
  *  @hw: pointer to hardware structure
  *
@@ -656,6 +680,68 @@ out:
 }
 
 /**
+ * Hyper-V variant; there is no mailbox communication.
+ */
+static s32 ixgbevf_hv_check_mac_link_vf(struct ixgbe_hw *hw,
+                                       ixgbe_link_speed *speed,
+                                       bool *link_up,
+                                       bool autoneg_wait_to_complete)
+{
+       struct ixgbe_mbx_info *mbx = &hw->mbx;
+       struct ixgbe_mac_info *mac = &hw->mac;
+       s32 ret_val = 0;
+       u32 links_reg;
+
+       /* If we were hit with a reset drop the link */
+       if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
+               mac->get_link_status = true;
+
+       if (!mac->get_link_status)
Quoted 8 lines
Quoted 8 lines

drivers/net/ethernet/intel/ixgbevf/vf.c out:

Quoted 8 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +8 -0
+               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;
+
+       /* for SFP+ modules and DA cables on 82599 it can take up to

500usecs

Quoted 42 lines
Quoted 31 lines
Quoted 31 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +31 -0
+        * before the link status is correct
+        */
+       if (mac->type == ixgbe_mac_82599_vf) {
+               int i;
+
+               for (i = 0; i < 5; i++) {
+                       udelay(100);
+                       links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
+
+                       if (!(links_reg & IXGBE_LINKS_UP))
+                               goto out;
+               }
+       }
+
+       switch (links_reg & IXGBE_LINKS_SPEED_82599) {
+       case IXGBE_LINKS_SPEED_10G_82599:
+               *speed = IXGBE_LINK_SPEED_10GB_FULL;
+               break;
+       case IXGBE_LINKS_SPEED_1G_82599:
+               *speed = IXGBE_LINK_SPEED_1GB_FULL;
+               break;
+       case IXGBE_LINKS_SPEED_100_82599:
+               *speed = IXGBE_LINK_SPEED_100_FULL;
+               break;
+       }
+
+       /* if we passed all the tests above then the link is up and we no
+        * longer need to check for link
+        */
+       mac->get_link_status = false;
+
Quoted 8 lines

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 743

Quoted 5 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +5 -0
+out:
+       *link_up = !mac->get_link_status;
+       return ret_val;
+}
+

How does this handle the PF resetting? Seems like you are going to be generating Tx hangs in such a case.

I am not sure how the Windows PF driver communicates this information. Do you have any suggestions for this.

Quoted 8 lines
Quoted 6 lines

You might want to take a look at the fm10k_get_host_state_generic function. You could probably do something like the trick we did there with the TXDCTL in order to detect cases where the PF has reset the VF so that you could then reset your guest once the PF has come back up. That way at least you would report link down instead of Tx hang if the host has reset you.

I will take a look at your example; thank you.

The code you have in fm10k_get_host_state_generic function is somewhat similar to what I have in the function ixgbevf_hv_check_mac_link_vf(). We drop the link if the PF has reset us. I will look at this code some more.

Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +14 -0
+/**
  *  ixgbevf_rlpml_set_vf - Set the maximum receive packet length
  *  @hw: pointer to the HW structure
  *  @max_size: value to assign to max frame size
@@ -663,6 +749,19 @@ out:
 void ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
 {
        u32 msgbuf[2];
+       u32 reg;
+
+       if (x86_hyper == &x86_hyper_ms_hyperv) {
+               /*
+                * If we are on Hyper-V, we implement
+                * this functionality differently.
+                */
+               reg =  IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(0));
+               /* CRC == 4 */
+               reg |= ((max_size + 4) | IXGBE_RXDCTL_RLPML_EN);
+               IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(0), reg);
+               return;
+       }
 
Quoted 5 lines

drivers/net/ethernet/intel/ixgbevf/vf.c out: · line 767

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
        msgbuf[0] = IXGBE_VF_SET_LPE;
        msgbuf[1] = max_size;

You would be better off just implementing a hyperv version of this function and avoiding the mailbox call entirely.

Ok; will do.

Quoted 23 lines

drivers/net/ethernet/intel/ixgbevf/vf.c int ixgbevf_negotiate_api_version(struct

Quoted 2 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +0 -0
@@ -679,6 +778,16 @@ int ixgbevf_negotiate_api_version(struct

ixgbe_hw *hw, int api)

Quoted 6 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +3 -0
        int err;
        u32 msg[3];
 
+       if (x86_hyper == &x86_hyper_ms_hyperv) {
+               /*
+                * Hyper-V only supports api version ixgbe_mbox_api_10

drivers/net/ethernet/intel/ixgbevf/vf.c int ixgbevf_negotiate_api_version(struct ixgbe_hw *hw, int api) · line 793

Quoted 10 lines
drivers/net/ethernet/intel/ixgbevf/vf.c +7 -0
+                */
+               if (api != ixgbe_mbox_api_10)
+                       return IXGBE_ERR_INVALID_ARGUMENT;
+
+               return 0;
+       }
+
        /* Negotiate the mailbox API version */
        msg[0] = IXGBE_VF_API_NEGOTIATE;
        msg[1] = api;

Same here. Just implement a hyperv version of this function instead of splicing into the existing call. Also you will need to wrap this code up so that we can build on all architectures, not just x86.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Ok; will do.

I now have a check for Hyper-V that is based on the mailbox operations
and that should address compilation issues on non x86 platforms. I will post the new set shortly.

Regards,

K. Y