Skip to contentSkip to conversation

Fix PF reset causes VF memory request failure

PATCH Superseded Haiyue Wang 5 participants 46 messages Apr 21, 2021 – Jun 8, 2021 Network drivers

lore
Share & tools
lore
#0 lore raw

cover Fix PF reset causes VF memory request failure

By triggerring the VF reset from PF reset,
echo 1 > /sys/bus/pci/devices/PF-BDF/reset

the PCI bus master bit will cleared on VF, so the VF needs to enable this bit before restart.

This patch set adds the API to enable PCI bus master.

Haiyue Wang (3):
bus/pci: enable PCI master in command register
net/iavf: enable PCI bus master after reset
net/i40e: enable PCI bus master after reset

 drivers/bus/pci/pci_common.c      | 20 ++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h     | 12 ++++++++++++
 drivers/bus/pci/version.map       |  1 +
 drivers/net/i40e/i40e_ethdev_vf.c |  7 ++++++-
 drivers/net/iavf/iavf_ethdev.c    |  3 +++
 lib/librte_pci/rte_pci.h          |  4 ++++
 6 files changed, 46 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/3 bus/pci: enable PCI master in command register

This adds the support to set 'Bus Master Enable' bit in the PCI command register.

---
 drivers/bus/pci/pci_common.c  | 20 ++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h | 12 ++++++++++++
 drivers/bus/pci/version.map   |  1 +
 lib/librte_pci/rte_pci.h      |  4 ++++
 4 files changed, 37 insertions(+)
drivers/bus/pci/pci_common.c +20 -0
index ee7f966358..b631cb9c7e 100644
@@ -746,6 +746,26 @@ rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap)
 	return 0;
 }
 
+int
+rte_pci_enable_bus_master(struct rte_pci_device *dev)
+{
+	uint16_t cmd;
+
+	if (rte_pci_read_config(dev, &cmd, sizeof(cmd), RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in reading PCI command register\n");
+		return -1;
+	}
+
+	cmd |= RTE_PCI_COMMAND_MASTER;
+
+	if (rte_pci_write_config(dev, &cmd, sizeof(cmd), RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in writing PCI command register\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
drivers/bus/pci/rte_bus_pci.h +12 -0
index 64886b4731..83caf477ba 100644
@@ -249,6 +249,18 @@ void rte_pci_dump(FILE *f);
 __rte_experimental
 off_t rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap);
 
+/**
+ * Enables Bus Master for device's PCI command register.
+ *
+ *  @param dev
+ *    A pointer to rte_pci_device structure.
+ *
+ *  @return
+ *  0 on success, -1 on error in PCI config space read/write.
+ */
+__rte_experimental
+int rte_pci_enable_bus_master(struct rte_pci_device *dev);
+
 /**
  * Register a PCI driver.
  *
drivers/bus/pci/version.map +1 -0
index f33ed0abd1..b271e48a8f 100644
@@ -20,5 +20,6 @@ DPDK_21 {
 EXPERIMENTAL {
 	global:
 
+	rte_pci_enable_bus_master;
 	rte_pci_find_ext_capability;
 };
lib/librte_pci/rte_pci.h +4 -0
index a8f8e404a9..1f33d687f4 100644
@@ -32,6 +32,10 @@ extern "C" {
 
 #define RTE_PCI_VENDOR_ID	0x00	/* 16 bits */
 #define RTE_PCI_DEVICE_ID	0x02	/* 16 bits */
+#define RTE_PCI_COMMAND		0x04	/* 16 bits */
+
+/* PCI Command Register */
+#define RTE_PCI_COMMAND_MASTER	0x4	/* Bus Master Enable */
 
 /* PCI Express capability registers */
 #define RTE_PCI_EXP_DEVCTL	8	/* Device Control */
Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/3 net/iavf: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

---
 drivers/net/iavf/iavf_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/iavf/iavf_ethdev.c +3 -0
index d523a0618c..8c924d21b2 100644
@@ -2255,6 +2255,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	rte_free(vf->aq_resp);
 	vf->aq_resp = NULL;
 
+	if (vf->vf_reset)
+		rte_pci_enable_bus_master(pci_dev);
+
 	vf->vf_reset = false;
 
 	return ret;
Signature · 1 line
2.31.1
#3 lore raw

PATCH 3/3 net/i40e: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

And align the VF reset event handling in device close module as the AVF driver does.

---
 drivers/net/i40e/i40e_ethdev_vf.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_ethdev_vf.c +6 -1
index 3c258ba7cf..4f1d04eb2b 100644
@@ -1212,7 +1212,6 @@ i40evf_check_vf_reset_done(struct rte_eth_dev *dev)
 	if (i >= MAX_RESET_WAIT_CNT)
 		return -1;
 
-	vf->vf_reset = false;
 	vf->pend_msg &= ~PFMSG_RESET_IMPENDING;
 
 	return 0;
@@ -1391,6 +1390,7 @@ i40evf_handle_pf_event(struct rte_eth_dev *dev, uint8_t *msg,
 	switch (pf_msg->event) {
 	case VIRTCHNL_EVENT_RESET_IMPENDING:
 		PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
+		vf->vf_reset = true;
 		rte_eth_dev_callback_process(dev,
 				RTE_ETH_EVENT_INTR_RESET, NULL);
 		break;
@@ -2487,6 +2487,11 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 	i40e_shutdown_adminq(hw);
 	i40evf_disable_irq0(hw);
 
+	if (vf->vf_reset)
+		rte_pci_enable_bus_master(RTE_ETH_DEV_TO_PCI(dev));
+
+	vf->vf_reset = false;
+
 	rte_free(vf->vf_res);
 	vf->vf_res = NULL;
 	rte_free(vf->aq_resp);
Signature · 1 line
2.31.1
Tested-by on the v1 series
#4 lore raw
In reply to Haiyue Wang
Quoted 31 lines

-----Original Message-----
From: Wang, Haiyue <[email protected]>
Sent: Wednesday, April 21, 2021 1:03 PM
To: [email protected]
Cc: Zhang, Qi Z <[email protected]>; Wang, Liang-min <[email protected]>; Wang, Haiyue <[email protected]>
Subject: [PATCH v1 0/3] Fix PF reset causes VF memory request failure

By triggerring the VF reset from PF reset,
echo 1 > /sys/bus/pci/devices/PF-BDF/reset

the PCI bus master bit will cleared on VF, so the VF needs to enable this bit before restart.

This patch set adds the API to enable PCI bus master.

Haiyue Wang (3):
bus/pci: enable PCI master in command register
net/iavf: enable PCI bus master after reset
net/i40e: enable PCI bus master after reset

 drivers/bus/pci/pci_common.c      | 20 ++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h     | 12 ++++++++++++
 drivers/bus/pci/version.map       |  1 +
 drivers/net/i40e/i40e_ethdev_vf.c |  7 ++++++-
 drivers/net/iavf/iavf_ethdev.c    |  3 +++
 lib/librte_pci/rte_pci.h          |  4 ++++
 6 files changed, 46 insertions(+), 1 deletion(-)
Quoted 2 lines

--
2.31.1

Thanks
Qi

#5 lore raw

v2 cover fix PF reset causes VF memory request failure

In reply to Haiyue Wang

By triggerring the VF reset from PF reset,

echo 1 > /sys/bus/pci/devices/PF-BDF/reset

the PCI bus master bit will cleared on VF, so the VF needs to enable this bit before restart.

This patch set adds the API to enable PCI bus master.

v2: rebase to new librte directory path.

Haiyue Wang (3):
bus/pci: enable PCI master in command register
net/iavf: enable PCI bus master after reset
net/i40e: enable PCI bus master after reset

 drivers/bus/pci/pci_common.c      | 20 ++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h     | 12 ++++++++++++
 drivers/bus/pci/version.map       |  1 +
 drivers/net/i40e/i40e_ethdev_vf.c |  7 ++++++-
 drivers/net/iavf/iavf_ethdev.c    |  3 +++
 lib/pci/rte_pci.h                 |  4 ++++
 6 files changed, 46 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.1
#6 lore raw

PATCH v2 1/3 bus/pci: enable PCI master in command register

This adds the support to set 'Bus Master Enable' bit in the PCI command register.

---
 drivers/bus/pci/pci_common.c  | 20 ++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h | 12 ++++++++++++
 drivers/bus/pci/version.map   |  1 +
 lib/pci/rte_pci.h             |  4 ++++
 4 files changed, 37 insertions(+)
drivers/bus/pci/pci_common.c +20 -0
index ee7f96635..b631cb9c7 100644
@@ -746,6 +746,26 @@ rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap)
 	return 0;
 }
 
+int
+rte_pci_enable_bus_master(struct rte_pci_device *dev)
+{
+	uint16_t cmd;
+
+	if (rte_pci_read_config(dev, &cmd, sizeof(cmd), RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in reading PCI command register\n");
+		return -1;
+	}
+
+	cmd |= RTE_PCI_COMMAND_MASTER;
+
+	if (rte_pci_write_config(dev, &cmd, sizeof(cmd), RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in writing PCI command register\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
drivers/bus/pci/rte_bus_pci.h +12 -0
index 64886b473..83caf477b 100644
@@ -249,6 +249,18 @@ void rte_pci_dump(FILE *f);
 __rte_experimental
 off_t rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap);
 
+/**
+ * Enables Bus Master for device's PCI command register.
+ *
+ *  @param dev
+ *    A pointer to rte_pci_device structure.
+ *
+ *  @return
+ *  0 on success, -1 on error in PCI config space read/write.
+ */
+__rte_experimental
+int rte_pci_enable_bus_master(struct rte_pci_device *dev);
+
 /**
  * Register a PCI driver.
  *
drivers/bus/pci/version.map +1 -0
index f33ed0abd..b271e48a8 100644
@@ -20,5 +20,6 @@ DPDK_21 {
 EXPERIMENTAL {
 	global:
 
+	rte_pci_enable_bus_master;
 	rte_pci_find_ext_capability;
 };
lib/pci/rte_pci.h +4 -0
index a8f8e404a..1f33d687f 100644
@@ -32,6 +32,10 @@ extern "C" {
 
 #define RTE_PCI_VENDOR_ID	0x00	/* 16 bits */
 #define RTE_PCI_DEVICE_ID	0x02	/* 16 bits */
+#define RTE_PCI_COMMAND		0x04	/* 16 bits */
+
+/* PCI Command Register */
+#define RTE_PCI_COMMAND_MASTER	0x4	/* Bus Master Enable */
 
 /* PCI Express capability registers */
 #define RTE_PCI_EXP_DEVCTL	8	/* Device Control */
Signature · 1 line
2.31.1
#7 lore raw

Re: [dpdk-dev] [PATCH v2 1/3] bus/pci: enable PCI master in command register

Quoted 71 lines · Haiyue Wang

This adds the support to set 'Bus Master Enable' bit in the PCI command register.

---
 drivers/bus/pci/pci_common.c  | 20 ++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h | 12 ++++++++++++
 drivers/bus/pci/version.map   |  1 +
 lib/pci/rte_pci.h             |  4 ++++
 4 files changed, 37 insertions(+)
drivers/bus/pci/pci_common.c +20 -0
index ee7f96635..b631cb9c7 100644
@@ -746,6 +746,26 @@ rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap)
 	return 0;
 }
 
+int
+rte_pci_enable_bus_master(struct rte_pci_device *dev)
+{
+	uint16_t cmd;
+
+	if (rte_pci_read_config(dev, &cmd, sizeof(cmd), RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in reading PCI command register\n");
+		return -1;
+	}
+
+	cmd |= RTE_PCI_COMMAND_MASTER;
+
+	if (rte_pci_write_config(dev, &cmd, sizeof(cmd), RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in writing PCI command register\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
drivers/bus/pci/rte_bus_pci.h +12 -0
index 64886b473..83caf477b 100644
@@ -249,6 +249,18 @@ void rte_pci_dump(FILE *f);
 __rte_experimental
 off_t rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap);
 
+/**
+ * Enables Bus Master for device's PCI command register.
+ *
+ *  @param dev
+ *    A pointer to rte_pci_device structure.
+ *
+ *  @return
+ *  0 on success, -1 on error in PCI config space read/write.
+ */
+__rte_experimental
+int rte_pci_enable_bus_master(struct rte_pci_device *dev);
+
 /**
  * Register a PCI driver.
  *
drivers/bus/pci/version.map +0 -0
index f33ed0abd..b271e48a8 100644

drivers/bus/pci/version.map DPDK_21 { · line 22

Quoted 3 lines
drivers/bus/pci/version.map +0 -0
@@ -20,5 +20,6 @@ DPDK_21 {
 EXPERIMENTAL {
 	global:
 

Please annotate when the symbol was added.

Quoted 19 lines
drivers/bus/pci/version.map +1 -0
+	rte_pci_enable_bus_master;
 	rte_pci_find_ext_capability;
 };
lib/pci/rte_pci.h +4 -0
index a8f8e404a..1f33d687f 100644
@@ -32,6 +32,10 @@ extern "C" {
 
 #define RTE_PCI_VENDOR_ID	0x00	/* 16 bits */
 #define RTE_PCI_DEVICE_ID	0x02	/* 16 bits */
+#define RTE_PCI_COMMAND		0x04	/* 16 bits */
+
+/* PCI Command Register */
+#define RTE_PCI_COMMAND_MASTER	0x4	/* Bus Master Enable */
 
 /* PCI Express capability registers */
 #define RTE_PCI_EXP_DEVCTL	8	/* Device Control */
#8 lore raw

Re: [dpdk-dev] [PATCH v2 1/3] bus/pci: enable PCI master in command register

Quoted 25 lines

-----Original Message-----
From: Kinsella, Ray <[email protected]>
Sent: Friday, April 23, 2021 18:44
To: Wang, Haiyue <[email protected]>; [email protected]
Cc: Zhang, Qi Z <[email protected]>; Wang, Liang-min <[email protected]>; Neil Horman <[email protected]>; Gaetan Rivet <[email protected]>
Subject: Re: [PATCH v2 1/3] bus/pci: enable PCI master in command register

Quoted 12 lines · Haiyue Wang

This adds the support to set 'Bus Master Enable' bit in the PCI command register.

---
 drivers/bus/pci/pci_common.c  | 20 ++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h | 12 ++++++++++++
 drivers/bus/pci/version.map   |  1 +
 lib/pci/rte_pci.h             |  4 ++++
 4 files changed, 37 insertions(+)
Quoted 12 lines

drivers/bus/pci/version.map DPDK_21 { · line 22

Quoted 9 lines

*

drivers/bus/pci/version.map +0 -0
index f33ed0abd..b271e48a8 100644
@@ -20,5 +20,6 @@ DPDK_21 {
 EXPERIMENTAL {
 	global:
 

Please annotate when the symbol was added.

Fixed in v3.

Quoted 1 line
Quoted 1 line
#9 lore raw

PATCH v2 2/3 net/iavf: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

---
 drivers/net/iavf/iavf_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/iavf/iavf_ethdev.c +3 -0
index d523a0618..8c924d21b 100644
@@ -2255,6 +2255,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	rte_free(vf->aq_resp);
 	vf->aq_resp = NULL;
 
+	if (vf->vf_reset)
+		rte_pci_enable_bus_master(pci_dev);
+
 	vf->vf_reset = false;
 
 	return ret;
Signature · 1 line
2.31.1
#10 lore raw

PATCH v2 3/3 net/i40e: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

And align the VF reset event handling in device close module as the AVF driver does.

---
 drivers/net/i40e/i40e_ethdev_vf.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_ethdev_vf.c +6 -1
index 3c258ba7c..4f1d04eb2 100644
@@ -1212,7 +1212,6 @@ i40evf_check_vf_reset_done(struct rte_eth_dev *dev)
 	if (i >= MAX_RESET_WAIT_CNT)
 		return -1;
 
-	vf->vf_reset = false;
 	vf->pend_msg &= ~PFMSG_RESET_IMPENDING;
 
 	return 0;
@@ -1391,6 +1390,7 @@ i40evf_handle_pf_event(struct rte_eth_dev *dev, uint8_t *msg,
 	switch (pf_msg->event) {
 	case VIRTCHNL_EVENT_RESET_IMPENDING:
 		PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
+		vf->vf_reset = true;
 		rte_eth_dev_callback_process(dev,
 				RTE_ETH_EVENT_INTR_RESET, NULL);
 		break;
@@ -2487,6 +2487,11 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 	i40e_shutdown_adminq(hw);
 	i40evf_disable_irq0(hw);
 
+	if (vf->vf_reset)
+		rte_pci_enable_bus_master(RTE_ETH_DEV_TO_PCI(dev));
+
+	vf->vf_reset = false;
+
 	rte_free(vf->vf_res);
 	vf->vf_res = NULL;
 	rte_free(vf->aq_resp);
Signature · 1 line
2.31.1
#11 lore raw

v3 cover fix PF reset causes VF memory request failure

In reply to Haiyue Wang

By triggerring the VF reset from PF reset,

echo 1 > /sys/bus/pci/devices/PF-BDF/reset

the PCI bus master bit will cleared on VF, so the VF needs to enable this bit before restart.

This patch set adds the API to enable PCI bus master.

v3: added the missed annotate symbol add time
v2: rebase to new librte directory path.

Haiyue Wang (3):
bus/pci: enable PCI master in command register
net/iavf: enable PCI bus master after reset
net/i40e: enable PCI bus master after reset

 drivers/bus/pci/pci_common.c      | 20 ++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h     | 12 ++++++++++++
 drivers/bus/pci/version.map       |  3 +++
 drivers/net/i40e/i40e_ethdev_vf.c |  7 ++++++-
 drivers/net/iavf/iavf_ethdev.c    |  3 +++
 lib/pci/rte_pci.h                 |  4 ++++
 6 files changed, 48 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.1
#12 lore raw

PATCH v3 1/3 bus/pci: enable PCI master in command register

This adds the support to set 'Bus Master Enable' bit in the PCI command register.

---
 drivers/bus/pci/pci_common.c  | 20 ++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h | 12 ++++++++++++
 drivers/bus/pci/version.map   |  3 +++
 lib/pci/rte_pci.h             |  4 ++++
 4 files changed, 39 insertions(+)
drivers/bus/pci/pci_common.c +20 -0
index ee7f96635..b631cb9c7 100644
@@ -746,6 +746,26 @@ rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap)
 	return 0;
 }
 
+int
+rte_pci_enable_bus_master(struct rte_pci_device *dev)
+{
+	uint16_t cmd;
+
+	if (rte_pci_read_config(dev, &cmd, sizeof(cmd), RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in reading PCI command register\n");
+		return -1;
+	}
+
+	cmd |= RTE_PCI_COMMAND_MASTER;
+
+	if (rte_pci_write_config(dev, &cmd, sizeof(cmd), RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in writing PCI command register\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
drivers/bus/pci/rte_bus_pci.h +12 -0
index 64886b473..83caf477b 100644
@@ -249,6 +249,18 @@ void rte_pci_dump(FILE *f);
 __rte_experimental
 off_t rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap);
 
+/**
+ * Enables Bus Master for device's PCI command register.
+ *
+ *  @param dev
+ *    A pointer to rte_pci_device structure.
+ *
+ *  @return
+ *  0 on success, -1 on error in PCI config space read/write.
+ */
+__rte_experimental
+int rte_pci_enable_bus_master(struct rte_pci_device *dev);
+
 /**
  * Register a PCI driver.
  *
drivers/bus/pci/version.map +3 -0
index f33ed0abd..9dbec12a0 100644
@@ -21,4 +21,7 @@ EXPERIMENTAL {
 	global:
 
 	rte_pci_find_ext_capability;
+
+	# added in 21.05
+	rte_pci_enable_bus_master;
 };
lib/pci/rte_pci.h +4 -0
index a8f8e404a..1f33d687f 100644
@@ -32,6 +32,10 @@ extern "C" {
 
 #define RTE_PCI_VENDOR_ID	0x00	/* 16 bits */
 #define RTE_PCI_DEVICE_ID	0x02	/* 16 bits */
+#define RTE_PCI_COMMAND		0x04	/* 16 bits */
+
+/* PCI Command Register */
+#define RTE_PCI_COMMAND_MASTER	0x4	/* Bus Master Enable */
 
 /* PCI Express capability registers */
 #define RTE_PCI_EXP_DEVCTL	8	/* Device Control */
Signature · 1 line
2.31.1
Acked-by on v3 1/3
#13 lore raw

Re: [dpdk-dev] [PATCH v3 1/3] bus/pci: enable PCI master in command register

Quoted 84 lines · Haiyue Wang

This adds the support to set 'Bus Master Enable' bit in the PCI command register.

---
 drivers/bus/pci/pci_common.c  | 20 ++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h | 12 ++++++++++++
 drivers/bus/pci/version.map   |  3 +++
 lib/pci/rte_pci.h             |  4 ++++
 4 files changed, 39 insertions(+)
drivers/bus/pci/pci_common.c +20 -0
index ee7f96635..b631cb9c7 100644
@@ -746,6 +746,26 @@ rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap)
 	return 0;
 }
 
+int
+rte_pci_enable_bus_master(struct rte_pci_device *dev)
+{
+	uint16_t cmd;
+
+	if (rte_pci_read_config(dev, &cmd, sizeof(cmd), RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in reading PCI command register\n");
+		return -1;
+	}
+
+	cmd |= RTE_PCI_COMMAND_MASTER;
+
+	if (rte_pci_write_config(dev, &cmd, sizeof(cmd), RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in writing PCI command register\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
drivers/bus/pci/rte_bus_pci.h +12 -0
index 64886b473..83caf477b 100644
@@ -249,6 +249,18 @@ void rte_pci_dump(FILE *f);
 __rte_experimental
 off_t rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap);
 
+/**
+ * Enables Bus Master for device's PCI command register.
+ *
+ *  @param dev
+ *    A pointer to rte_pci_device structure.
+ *
+ *  @return
+ *  0 on success, -1 on error in PCI config space read/write.
+ */
+__rte_experimental
+int rte_pci_enable_bus_master(struct rte_pci_device *dev);
+
 /**
  * Register a PCI driver.
  *
drivers/bus/pci/version.map +3 -0
index f33ed0abd..9dbec12a0 100644
@@ -21,4 +21,7 @@ EXPERIMENTAL {
 	global:
 
 	rte_pci_find_ext_capability;
+
+	# added in 21.05
+	rte_pci_enable_bus_master;
 };
lib/pci/rte_pci.h +0 -0
index a8f8e404a..1f33d687f 100644

lib/pci/rte_pci.h extern "C" { · line 41

Quoted 10 lines
lib/pci/rte_pci.h +4 -0
@@ -32,6 +32,10 @@ extern "C" {
 
 #define RTE_PCI_VENDOR_ID	0x00	/* 16 bits */
 #define RTE_PCI_DEVICE_ID	0x02	/* 16 bits */
+#define RTE_PCI_COMMAND		0x04	/* 16 bits */
+
+/* PCI Command Register */
+#define RTE_PCI_COMMAND_MASTER	0x4	/* Bus Master Enable */
 
 /* PCI Express capability registers */
 #define RTE_PCI_EXP_DEVCTL	8	/* Device Control */
#14 lore raw

Re: [dpdk-dev] [PATCH v3 1/3] bus/pci: enable PCI master in command register

In reply to Haiyue Wang
Quoted 9 lines · Haiyue Wang
drivers/bus/pci/rte_bus_pci.h +1 -0
index 64886b473..83caf477b 100644
@@ -249,6 +249,18 @@ void rte_pci_dump(FILE *f);
 __rte_experimental
 off_t rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap);
 
+/**

drivers/bus/pci/rte_bus_pci.h void rte_pci_dump(FILE *f); · line 262

Quoted 10 lines
drivers/bus/pci/rte_bus_pci.h +10 -0
+ * Enables Bus Master for device's PCI command register.
+ *
+ *  @param dev
+ *    A pointer to rte_pci_device structure.
+ *
+ *  @return
+ *  0 on success, -1 on error in PCI config space read/write.
+ */
+__rte_experimental
+int rte_pci_enable_bus_master(struct rte_pci_device *dev);

I can see pci/vfio and net/hns3 has a similar helper to enable *and* disable bus master.

I'd rather go with a "set" helper, and then we can clean existing drivers who had their own helper:
drivers/bus/pci/linux/pci_uio.c drivers/bus/pci/linux/pci_vfio.c drivers/net/hns3/hns3_ethdev_vf.c

Quoted 21 lines
drivers/bus/pci/rte_bus_pci.h +1 -0
+
 /**
  * Register a PCI driver.
  *
drivers/bus/pci/version.map +3 -0
index f33ed0abd..9dbec12a0 100644
@@ -21,4 +21,7 @@ EXPERIMENTAL {
        global:
 
        rte_pci_find_ext_capability;
+
+       # added in 21.05
+       rte_pci_enable_bus_master;
 };
lib/pci/rte_pci.h +0 -0
index a8f8e404a..1f33d687f 100644

lib/pci/rte_pci.h extern "C" { · line 35

Quoted 4 lines
lib/pci/rte_pci.h +1 -0
@@ -32,6 +32,10 @@ extern "C" {
 
 #define RTE_PCI_VENDOR_ID      0x00    /* 16 bits */
 #define RTE_PCI_DEVICE_ID      0x02    /* 16 bits */
+#define RTE_PCI_COMMAND                0x04    /* 16 bits */

This file uses tab for indent.

Quoted 9 lines
lib/pci/rte_pci.h +3 -1
+
+/* PCI Command Register */
+#define RTE_PCI_COMMAND_MASTER 0x4     /* Bus Master Enable */
 
 /* PCI Express capability registers */
 #define RTE_PCI_EXP_DEVCTL     8       /* Device Control */
--

2.31.1

Signature · 1 line
David Marchand
#15 lore raw

Re: [dpdk-dev] [PATCH v3 1/3] bus/pci: enable PCI master in command register

Quoted 32 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Tuesday, April 27, 2021 17:29
To: Wang, Haiyue <[email protected]>; Gaetan Rivet <[email protected]>
Cc: dev <[email protected]>; Zhang, Qi Z <[email protected]>; Wang, Liang-min <[email protected]>; Ray Kinsella <[email protected]>; Neil Horman <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v3 1/3] bus/pci: enable PCI master in command register

Quoted 9 lines · Haiyue Wang
drivers/bus/pci/rte_bus_pci.h +1 -0
index 64886b473..83caf477b 100644
@@ -249,6 +249,18 @@ void rte_pci_dump(FILE *f);
 __rte_experimental
 off_t rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap);
 
+/**

drivers/bus/pci/rte_bus_pci.h void rte_pci_dump(FILE *f); · line 262

Quoted 10 lines
drivers/bus/pci/rte_bus_pci.h +10 -0
+ * Enables Bus Master for device's PCI command register.
+ *
+ *  @param dev
+ *    A pointer to rte_pci_device structure.
+ *
+ *  @return
+ *  0 on success, -1 on error in PCI config space read/write.
+ */
+__rte_experimental
+int rte_pci_enable_bus_master(struct rte_pci_device *dev);

I can see pci/vfio and net/hns3 has a similar helper to enable *and* disable bus master.

Quoted 7 lines

I'd rather go with a "set" helper, and then we can clean existing drivers who had their own helper:
drivers/bus/pci/linux/pci_uio.c drivers/bus/pci/linux/pci_vfio.c drivers/net/hns3/hns3_ethdev_vf.c

Got it, will change it to 'set'.

Quoted 22 lines
Quoted 22 lines
drivers/bus/pci/rte_bus_pci.h +1 -0
+
 /**
  * Register a PCI driver.
  *
drivers/bus/pci/version.map +3 -0
index f33ed0abd..9dbec12a0 100644
@@ -21,4 +21,7 @@ EXPERIMENTAL {
        global:
 
        rte_pci_find_ext_capability;
+
+       # added in 21.05
+       rte_pci_enable_bus_master;
 };
lib/pci/rte_pci.h +0 -0
index a8f8e404a..1f33d687f 100644
@@ -32,6 +32,10 @@ extern "C" {
 
Quoted 6 lines

lib/pci/rte_pci.h extern "C" { · line 35

Quoted 3 lines
lib/pci/rte_pci.h +1 -0
 #define RTE_PCI_VENDOR_ID      0x00    /* 16 bits */
 #define RTE_PCI_DEVICE_ID      0x02    /* 16 bits */
+#define RTE_PCI_COMMAND                0x04    /* 16 bits */

This file uses tab for indent.

Yes, I use two tabs, then the vi editor shows that they are aligned. but the patch doesn't show well.

So use one tab ?

Quoted 14 lines
Quoted 10 lines
lib/pci/rte_pci.h +3 -1
+
+/* PCI Command Register */
+#define RTE_PCI_COMMAND_MASTER 0x4     /* Bus Master Enable */
 
 /* PCI Express capability registers */
 #define RTE_PCI_EXP_DEVCTL     8       /* Device Control */
--

2.31.1

--
David Marchand

#16 lore raw

Re: [dpdk-dev] [PATCH v3 1/3] bus/pci: enable PCI master in command register

Quoted 13 lines · Haiyue
Quoted 6 lines
Quoted 6 lines
lib/pci/rte_pci.h +0 -0
index a8f8e404a..1f33d687f 100644
@@ -32,6 +32,10 @@ extern "C" {
 
Quoted 6 lines

lib/pci/rte_pci.h extern "C" { · line 35

Quoted 3 lines
lib/pci/rte_pci.h +1 -0
 #define RTE_PCI_VENDOR_ID      0x00    /* 16 bits */
 #define RTE_PCI_DEVICE_ID      0x02    /* 16 bits */
+#define RTE_PCI_COMMAND                0x04    /* 16 bits */

This file uses tab for indent.

Quoted 4 lines

Yes, I use two tabs, then the vi editor shows that they are aligned. but the patch doesn't show well.

So use one tab ?

Sorry, your patch was good.
You can discard this comment.

Signature · 1 line
David Marchand
#17 lore raw

PATCH v3 2/3 net/iavf: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

---
 drivers/net/iavf/iavf_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/iavf/iavf_ethdev.c +3 -0
index d523a0618..8c924d21b 100644
@@ -2255,6 +2255,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	rte_free(vf->aq_resp);
 	vf->aq_resp = NULL;
 
+	if (vf->vf_reset)
+		rte_pci_enable_bus_master(pci_dev);
+
 	vf->vf_reset = false;
 
 	return ret;
Signature · 1 line
2.31.1
#18 lore raw

PATCH v3 3/3 net/i40e: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

And align the VF reset event handling in device close module as the AVF driver does.

---
 drivers/net/i40e/i40e_ethdev_vf.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_ethdev_vf.c +6 -1
index 3c258ba7c..4f1d04eb2 100644
@@ -1212,7 +1212,6 @@ i40evf_check_vf_reset_done(struct rte_eth_dev *dev)
 	if (i >= MAX_RESET_WAIT_CNT)
 		return -1;
 
-	vf->vf_reset = false;
 	vf->pend_msg &= ~PFMSG_RESET_IMPENDING;
 
 	return 0;
@@ -1391,6 +1390,7 @@ i40evf_handle_pf_event(struct rte_eth_dev *dev, uint8_t *msg,
 	switch (pf_msg->event) {
 	case VIRTCHNL_EVENT_RESET_IMPENDING:
 		PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
+		vf->vf_reset = true;
 		rte_eth_dev_callback_process(dev,
 				RTE_ETH_EVENT_INTR_RESET, NULL);
 		break;
@@ -2487,6 +2487,11 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 	i40e_shutdown_adminq(hw);
 	i40evf_disable_irq0(hw);
 
+	if (vf->vf_reset)
+		rte_pci_enable_bus_master(RTE_ETH_DEV_TO_PCI(dev));
+
+	vf->vf_reset = false;
+
 	rte_free(vf->vf_res);
 	vf->vf_res = NULL;
 	rte_free(vf->aq_resp);
Signature · 1 line
2.31.1
#19 lore raw

v4 cover fix PF reset causes VF memory request failure

In reply to Haiyue Wang

By triggerring the VF reset from PF reset,

echo 1 > /sys/bus/pci/devices/PF-BDF/reset

the PCI bus master bit will cleared on VF, so the VF needs to enable this bit before restart.

This patch set adds the API to enable PCI bus master.

v4: change the API to set type, so can enable or disable
v3: added the missed annotate symbol add time
v2: rebase to new librte directory path.

Haiyue Wang (3):
bus/pci: set PCI master in command register
net/iavf: enable PCI bus master after reset
net/i40e: enable PCI bus master after reset

 drivers/bus/pci/pci_common.c      | 28 ++++++++++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h     | 14 ++++++++++++++
 drivers/bus/pci/version.map       |  3 +++
 drivers/net/i40e/i40e_ethdev_vf.c |  7 ++++++-
 drivers/net/iavf/iavf_ethdev.c    |  3 +++
 lib/pci/rte_pci.h                 |  4 ++++
 6 files changed, 58 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.1
#20 lore raw

PATCH v4 1/3 bus/pci: set PCI master in command register

Add the API to set 'Bus Master Enable' bit to be enabled or disabled in the PCI command register.

---
 drivers/bus/pci/pci_common.c  | 28 ++++++++++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h | 14 ++++++++++++++
 drivers/bus/pci/version.map   |  3 +++
 lib/pci/rte_pci.h             |  4 ++++
 4 files changed, 49 insertions(+)
drivers/bus/pci/pci_common.c +28 -0
index ee7f96635..35d7d092d 100644
@@ -746,6 +746,34 @@ rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap)
 	return 0;
 }
 
+int
+rte_pci_set_bus_master(struct rte_pci_device *dev, bool enable)
+{
+	uint16_t old_cmd, cmd;
+
+	if (rte_pci_read_config(dev, &old_cmd, sizeof(old_cmd),
+				RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in reading PCI command register\n");
+		return -1;
+	}
+
+	if (enable)
+		cmd = old_cmd | RTE_PCI_COMMAND_MASTER;
+	else
+		cmd = old_cmd & ~RTE_PCI_COMMAND_MASTER;
+
+	if (cmd == old_cmd)
+		return 0;
+
+	if (rte_pci_write_config(dev, &cmd, sizeof(cmd),
+				 RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in writing PCI command register\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
drivers/bus/pci/rte_bus_pci.h +14 -0
index 64886b473..976c33c92 100644
@@ -249,6 +249,20 @@ void rte_pci_dump(FILE *f);
 __rte_experimental
 off_t rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap);
 
+/**
+ * Enables/Disables Bus Master for device's PCI command register.
+ *
+ *  @param dev
+ *    A pointer to rte_pci_device structure.
+ *  @param enable
+ *    Enable or disable Bus Master.
+ *
+ *  @return
+ *  0 on success, -1 on error in PCI config space read/write.
+ */
+__rte_experimental
+int rte_pci_set_bus_master(struct rte_pci_device *dev, bool enable);
+
 /**
  * Register a PCI driver.
  *
drivers/bus/pci/version.map +3 -0
index f33ed0abd..c6e5f797c 100644
@@ -21,4 +21,7 @@ EXPERIMENTAL {
 	global:
 
 	rte_pci_find_ext_capability;
+
+	# added in 21.05
+	rte_pci_set_bus_master;
 };
lib/pci/rte_pci.h +4 -0
index a8f8e404a..1f33d687f 100644
@@ -32,6 +32,10 @@ extern "C" {
 
 #define RTE_PCI_VENDOR_ID	0x00	/* 16 bits */
 #define RTE_PCI_DEVICE_ID	0x02	/* 16 bits */
+#define RTE_PCI_COMMAND		0x04	/* 16 bits */
+
+/* PCI Command Register */
+#define RTE_PCI_COMMAND_MASTER	0x4	/* Bus Master Enable */
 
 /* PCI Express capability registers */
 #define RTE_PCI_EXP_DEVCTL	8	/* Device Control */
Signature · 1 line
2.31.1
Acked-by on v4 1/3
#21 lore raw

Re: [dpdk-dev] [PATCH v4 1/3] bus/pci: set PCI master in command register

Quoted 11 lines · Haiyue Wang

Add the API to set 'Bus Master Enable' bit to be enabled or disabled in the PCI command register.

---
 drivers/bus/pci/pci_common.c  | 28 ++++++++++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h | 14 ++++++++++++++
 drivers/bus/pci/version.map   |  3 +++
 lib/pci/rte_pci.h             |  4 ++++
 4 files changed, 49 insertions(+)
#22 lore raw

PATCH v4 2/3 net/iavf: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

---
 drivers/net/iavf/iavf_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/iavf/iavf_ethdev.c +3 -0
index d523a0618..9a0a20a29 100644
@@ -2255,6 +2255,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	rte_free(vf->aq_resp);
 	vf->aq_resp = NULL;
 
+	if (vf->vf_reset)
+		rte_pci_set_bus_master(pci_dev, true);
+
 	vf->vf_reset = false;
 
 	return ret;
Signature · 1 line
2.31.1
Acked-by on v4 2/3
#23 lore raw

Re: [dpdk-dev] [PATCH v4 2/3] net/iavf: enable PCI bus master after reset

Quoted 38 lines

-----Original Message-----
From: Wang, Haiyue <[email protected]>
Sent: Tuesday, April 27, 2021 9:39 PM
To: [email protected]
Cc: Zhang, Qi Z <[email protected]>; Wang, Liang-min <[email protected]>; [email protected]; Wang, Haiyue <[email protected]>; Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Subject: [PATCH v4 2/3] net/iavf: enable PCI bus master after reset

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

---
 drivers/net/iavf/iavf_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/iavf/iavf_ethdev.c +3 -1
index d523a0618..9a0a20a29 100644
@@ -2255,6 +2255,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	rte_free(vf->aq_resp);
 	vf->aq_resp = NULL;
 
+	if (vf->vf_reset)
+		rte_pci_set_bus_master(pci_dev, true);
+
 	vf->vf_reset = false;
 
 	return ret;
--
Quoted 1 line

2.31.1

#24 lore raw

Re: [dpdk-dev] [PATCH v4 2/3] net/iavf: enable PCI bus master after reset

In reply to Haiyue Wang
Quoted 17 lines · Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

---
 drivers/net/iavf/iavf_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/iavf/iavf_ethdev.c +0 -0
index d523a0618..9a0a20a29 100644

drivers/net/iavf/iavf_ethdev.c iavf_dev_close(struct rte_eth_dev *dev) · line 2261

Quoted 7 lines
drivers/net/iavf/iavf_ethdev.c +3 -0
@@ -2255,6 +2255,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
        rte_free(vf->aq_resp);
        vf->aq_resp = NULL;
 
+       if (vf->vf_reset)
+               rte_pci_set_bus_master(pci_dev, true);
+
        vf->vf_reset = false;

Not checking for the return code can leave the device in an invalid state. Then after this, calling the init code will fail.

I'd rather move rte_pci_set_bus_master() (it is a noop if bus master is already enabled) in the init path and check for the return code there?
WDYT?

Signature · 1 line
David Marchand
#25 lore raw

Re: [dpdk-dev] [PATCH v4 2/3] net/iavf: enable PCI bus master after reset

Quoted 37 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Tuesday, May 4, 2021 19:32
To: Wang, Haiyue <[email protected]>
Cc: dev <[email protected]>; Zhang, Qi Z <[email protected]>; Wang, Liang-min <[email protected]>; Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Subject: Re: [PATCH v4 2/3] net/iavf: enable PCI bus master after reset

Quoted 17 lines · Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

---
 drivers/net/iavf/iavf_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/iavf/iavf_ethdev.c +0 -0
index d523a0618..9a0a20a29 100644

drivers/net/iavf/iavf_ethdev.c iavf_dev_close(struct rte_eth_dev *dev) · line 2261

Quoted 7 lines
drivers/net/iavf/iavf_ethdev.c +3 -0
@@ -2255,6 +2255,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
        rte_free(vf->aq_resp);
        vf->aq_resp = NULL;
 
+       if (vf->vf_reset)
+               rte_pci_set_bus_master(pci_dev, true);
+
        vf->vf_reset = false;

Not checking for the return code can leave the device in an invalid state. Then after this, calling the init code will fail.

Quoted 2 lines

I'd rather move rte_pci_set_bus_master() (it is a noop if bus master is already enabled) in the init path and check for the return code

Currently, just called when vf_reset happened. And I noticed that the kernel doesn't handle pci_read/write_config_word return code in most cases. I'm wondering if the PCI ops really failed, the system can return back ?

Quoted 6 lines

there?
WDYT?

--
David Marchand

#26 lore raw

Re: [dpdk-dev] [PATCH v4 2/3] net/iavf: enable PCI bus master after reset

In reply to David Marchand
Quoted 29 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Tuesday, May 4, 2021 19:32
To: Wang, Haiyue <[email protected]>
Cc: dev <[email protected]>; Zhang, Qi Z <[email protected]>; Wang, Liang-min <[email protected]>; Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Subject: Re: [PATCH v4 2/3] net/iavf: enable PCI bus master after reset

Quoted 20 lines · Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

---
 drivers/net/iavf/iavf_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/iavf/iavf_ethdev.c +0 -0
index d523a0618..9a0a20a29 100644
@@ -2255,6 +2255,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
        rte_free(vf->aq_resp);
        vf->aq_resp = NULL;
 
Quoted 7 lines

drivers/net/iavf/iavf_ethdev.c iavf_dev_close(struct rte_eth_dev *dev) · line 2261

Quoted 4 lines
drivers/net/iavf/iavf_ethdev.c +3 -0
+       if (vf->vf_reset)
+               rte_pci_set_bus_master(pci_dev, true);
+
        vf->vf_reset = false;

Not checking for the return code can leave the device in an invalid state. Then after this, calling the init code will fail.

From the upper application's view, if this bus master fix can't recover the device into valid state, then the device hotplug API should be used to make the device fully recover. So I'd prefer to call bus master "try best" to fix. If still have error, the system may be in bad state.

The init code is mostly called from PCI VFIO/UIO device management which has enabled bus master. If we put the bus master here, people may confuse. Bind setting the bus master with 'vf->vf_reset' together looks better.

Quoted 3 lines

I'd rather move rte_pci_set_bus_master() (it is a noop if bus master is already enabled) in the init path and check for the return code

In fact, not real noop, since the reading PCI ops may fail. ;-)

Quoted 6 lines

there?
WDYT?

--
David Marchand

#27 lore raw

Re: [dpdk-dev] [PATCH v4 2/3] net/iavf: enable PCI bus master after reset

Quoted 38 lines · Haiyue
Quoted 30 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Tuesday, May 4, 2021 19:32
To: Wang, Haiyue <[email protected]>
Cc: dev <[email protected]>; Zhang, Qi Z <[email protected]>; Wang, Liang-min <[email protected]>; Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Subject: Re: [PATCH v4 2/3] net/iavf: enable PCI bus master after reset

Quoted 20 lines · Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

---
 drivers/net/iavf/iavf_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/iavf/iavf_ethdev.c +0 -0
index d523a0618..9a0a20a29 100644
@@ -2255,6 +2255,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
        rte_free(vf->aq_resp);
        vf->aq_resp = NULL;
 
Quoted 7 lines

drivers/net/iavf/iavf_ethdev.c iavf_dev_close(struct rte_eth_dev *dev) · line 2261

Quoted 4 lines
drivers/net/iavf/iavf_ethdev.c +3 -0
+       if (vf->vf_reset)
+               rte_pci_set_bus_master(pci_dev, true);
+
        vf->vf_reset = false;

Not checking for the return code can leave the device in an invalid state. Then after this, calling the init code will fail.

Quoted 4 lines

From the upper application's view, if this bus master fix can't recover the device into valid state, then the device hotplug API should be used to make the device fully recover. So I'd prefer to call bus master "try best" to fix. If still have error, the system may be in bad state.

I find it odd to put something required for (re)initialising in a .dev_close ops.
Maybe the place is more into .dev_reset if you find it confusing in .dev_init. But this is your driver, I'll let it to your judgement.

On the other hand, what is the point of not failing early/propagating the rte_pci_set_bus_master error?
The driver can't work without bus master enabled, correct?

Signature · 1 line
David Marchand
#28 lore raw

Re: [dpdk-dev] [PATCH v4 2/3] net/iavf: enable PCI bus master after reset

Quoted 53 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Wednesday, May 5, 2021 16:39
To: Wang, Haiyue <[email protected]>
Cc: dev <[email protected]>; Zhang, Qi Z <[email protected]>; Wang, Liang-min <[email protected]>; Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Subject: Re: [PATCH v4 2/3] net/iavf: enable PCI bus master after reset

Quoted 6 lines · Haiyue
Quoted 6 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Tuesday, May 4, 2021 19:32
To: Wang, Haiyue <[email protected]>
Cc: dev <[email protected]>; Zhang, Qi Z <[email protected]>; Wang, Liang-min <liang-

[email protected]>;

Quoted 32 lines
Quoted 24 lines

Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Subject: Re: [PATCH v4 2/3] net/iavf: enable PCI bus master after reset

Quoted 20 lines · Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

---
 drivers/net/iavf/iavf_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/iavf/iavf_ethdev.c +0 -0
index d523a0618..9a0a20a29 100644
@@ -2255,6 +2255,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
        rte_free(vf->aq_resp);
        vf->aq_resp = NULL;
 
Quoted 7 lines

drivers/net/iavf/iavf_ethdev.c iavf_dev_close(struct rte_eth_dev *dev) · line 2261

Quoted 4 lines
drivers/net/iavf/iavf_ethdev.c +3 -0
+       if (vf->vf_reset)
+               rte_pci_set_bus_master(pci_dev, true);
+
        vf->vf_reset = false;

Not checking for the return code can leave the device in an invalid state. Then after this, calling the init code will fail.

Quoted 4 lines

From the upper application's view, if this bus master fix can't recover the device into valid state, then the device hotplug API should be used to make the device fully recover. So I'd prefer to call bus master "try best" to fix. If still have error, the system may be in bad state.

Quoted 5 lines

I find it odd to put something required for (re)initialising in a .dev_close ops.
Maybe the place is more into .dev_reset if you find it confusing in .dev_init. But this is your driver, I'll let it to your judgement.

In fact, the .dev_close is close to .dev_reset.

static int
iavf_dev_reset(struct rte_eth_dev *dev)

{
	int ret;

	ret = iavf_dev_uninit(dev); --> iavf_dev_close
	if (ret)
		return ret;

	return iavf_dev_init(dev);
}
Quoted 4 lines

On the other hand, what is the point of not failing early/propagating the rte_pci_set_bus_master error?
The driver can't work without bus master enabled, correct?

From this point of view, correct. ;-)

Now I changed the vf_reset handling as bellow, if bus master failed, the device will still be in VF reset state, so that other modules will return immediately (the PMD has considered the VF reset state already).

if (vf->vf_reset &&

    !rte_pci_set_bus_master(pci_dev, true))
	vf->vf_reset = false;
Quoted 4 lines

--
David Marchand

#29 lore raw

PATCH v4 3/3 net/i40e: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

And align the VF reset event handling in device close module as the AVF driver does.

---
 drivers/net/i40e/i40e_ethdev_vf.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_ethdev_vf.c +6 -1
index 3c258ba7c..8b041e94c 100644
@@ -1212,7 +1212,6 @@ i40evf_check_vf_reset_done(struct rte_eth_dev *dev)
 	if (i >= MAX_RESET_WAIT_CNT)
 		return -1;
 
-	vf->vf_reset = false;
 	vf->pend_msg &= ~PFMSG_RESET_IMPENDING;
 
 	return 0;
@@ -1391,6 +1390,7 @@ i40evf_handle_pf_event(struct rte_eth_dev *dev, uint8_t *msg,
 	switch (pf_msg->event) {
 	case VIRTCHNL_EVENT_RESET_IMPENDING:
 		PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
+		vf->vf_reset = true;
 		rte_eth_dev_callback_process(dev,
 				RTE_ETH_EVENT_INTR_RESET, NULL);
 		break;
@@ -2487,6 +2487,11 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 	i40e_shutdown_adminq(hw);
 	i40evf_disable_irq0(hw);
 
+	if (vf->vf_reset)
+		rte_pci_set_bus_master(RTE_ETH_DEV_TO_PCI(dev), true);
+
+	vf->vf_reset = false;
+
 	rte_free(vf->vf_res);
 	vf->vf_res = NULL;
 	rte_free(vf->aq_resp);
Signature · 1 line
2.31.1
Acked-by on v4 3/3
#30 lore raw

Re: [dpdk-dev] [PATCH v4 3/3] net/i40e: enable PCI bus master after reset

Quoted 63 lines

-----Original Message-----
From: Wang, Haiyue <[email protected]>
Sent: Tuesday, April 27, 2021 9:39 PM
To: [email protected]
Cc: Zhang, Qi Z <[email protected]>; Wang, Liang-min <[email protected]>; [email protected]; Wang, Haiyue <[email protected]>; Xing, Beilei <[email protected]>; Guo, Jia <[email protected]>
Subject: [PATCH v4 3/3] net/i40e: enable PCI bus master after reset

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master.

And align the VF reset event handling in device close module as the AVF driver does.

---
 drivers/net/i40e/i40e_ethdev_vf.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_ethdev_vf.c +0 -1
index 3c258ba7c..8b041e94c 100644
@@ -1212,7 +1212,6 @@ i40evf_check_vf_reset_done(struct rte_eth_dev
 *dev)
 	if (i >= MAX_RESET_WAIT_CNT)
 		return -1;
 
-	vf->vf_reset = false;
 	vf->pend_msg &= ~PFMSG_RESET_IMPENDING;
 
drivers/net/i40e/i40e_ethdev_vf.c +1 -0
 	return 0;
@@ -1391,6 +1390,7 @@ i40evf_handle_pf_event(struct rte_eth_dev *dev,
 uint8_t *msg,
 	switch (pf_msg->event) {
 	case VIRTCHNL_EVENT_RESET_IMPENDING:
 		PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING
 event");
+		vf->vf_reset = true;
 		rte_eth_dev_callback_process(dev,
drivers/net/i40e/i40e_ethdev_vf.c +5 -1
 				RTE_ETH_EVENT_INTR_RESET, NULL);
 		break;
@@ -2487,6 +2487,11 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 	i40e_shutdown_adminq(hw);
 	i40evf_disable_irq0(hw);
 
+	if (vf->vf_reset)
+		rte_pci_set_bus_master(RTE_ETH_DEV_TO_PCI(dev), true);
+
+	vf->vf_reset = false;
+
 	rte_free(vf->vf_res);
 	vf->vf_res = NULL;
 	rte_free(vf->aq_resp);
--
Quoted 1 line

2.31.1

#31 lore raw

v5 cover fix PF reset causes VF memory request failure

In reply to Haiyue Wang

By triggerring the VF reset from PF reset,

echo 1 > /sys/bus/pci/devices/PF-BDF/reset

the PCI bus master bit will cleared on VF, so the VF needs to enable this bit before restart.

This patch set adds the API to enable PCI bus master.

v5: error handling if bus master enable failed
v4: change the API to set type, so can enable or disable
v3: added the missed annotate symbol add time
v2: rebase to new librte directory path

Haiyue Wang (3):
bus/pci: set PCI master in command register
net/iavf: enable PCI bus master after reset
net/i40e: enable PCI bus master after reset

 drivers/bus/pci/pci_common.c      | 28 ++++++++++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h     | 14 ++++++++++++++
 drivers/bus/pci/version.map       |  3 +++
 drivers/net/i40e/i40e_ethdev_vf.c |  6 +++++-
 drivers/net/iavf/iavf_ethdev.c    |  3 ++-
 lib/pci/rte_pci.h                 |  4 ++++
 6 files changed, 56 insertions(+), 2 deletions(-)
Signature · 1 line
2.31.1
#32 lore raw

PATCH v5 1/3 bus/pci: set PCI master in command register

Add the API to set 'Bus Master Enable' bit to be enabled or disabled in the PCI command register.

---
 drivers/bus/pci/pci_common.c  | 28 ++++++++++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h | 14 ++++++++++++++
 drivers/bus/pci/version.map   |  3 +++
 lib/pci/rte_pci.h             |  4 ++++
 4 files changed, 49 insertions(+)
drivers/bus/pci/pci_common.c +28 -0
index ee7f96635..35d7d092d 100644
@@ -746,6 +746,34 @@ rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap)
 	return 0;
 }
 
+int
+rte_pci_set_bus_master(struct rte_pci_device *dev, bool enable)
+{
+	uint16_t old_cmd, cmd;
+
+	if (rte_pci_read_config(dev, &old_cmd, sizeof(old_cmd),
+				RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in reading PCI command register\n");
+		return -1;
+	}
+
+	if (enable)
+		cmd = old_cmd | RTE_PCI_COMMAND_MASTER;
+	else
+		cmd = old_cmd & ~RTE_PCI_COMMAND_MASTER;
+
+	if (cmd == old_cmd)
+		return 0;
+
+	if (rte_pci_write_config(dev, &cmd, sizeof(cmd),
+				 RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in writing PCI command register\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
drivers/bus/pci/rte_bus_pci.h +14 -0
index 64886b473..976c33c92 100644
@@ -249,6 +249,20 @@ void rte_pci_dump(FILE *f);
 __rte_experimental
 off_t rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap);
 
+/**
+ * Enables/Disables Bus Master for device's PCI command register.
+ *
+ *  @param dev
+ *    A pointer to rte_pci_device structure.
+ *  @param enable
+ *    Enable or disable Bus Master.
+ *
+ *  @return
+ *  0 on success, -1 on error in PCI config space read/write.
+ */
+__rte_experimental
+int rte_pci_set_bus_master(struct rte_pci_device *dev, bool enable);
+
 /**
  * Register a PCI driver.
  *
drivers/bus/pci/version.map +3 -0
index f33ed0abd..c6e5f797c 100644
@@ -21,4 +21,7 @@ EXPERIMENTAL {
 	global:
 
 	rte_pci_find_ext_capability;
+
+	# added in 21.05
+	rte_pci_set_bus_master;
 };
lib/pci/rte_pci.h +4 -0
index a8f8e404a..1f33d687f 100644
@@ -32,6 +32,10 @@ extern "C" {
 
 #define RTE_PCI_VENDOR_ID	0x00	/* 16 bits */
 #define RTE_PCI_DEVICE_ID	0x02	/* 16 bits */
+#define RTE_PCI_COMMAND		0x04	/* 16 bits */
+
+/* PCI Command Register */
+#define RTE_PCI_COMMAND_MASTER	0x4	/* Bus Master Enable */
 
 /* PCI Express capability registers */
 #define RTE_PCI_EXP_DEVCTL	8	/* Device Control */
Signature · 1 line
2.31.1
#33 lore raw

PATCH v5 2/3 net/iavf: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master. And if failed, the device or system may be in an invalid state, so keep the VF reset state to mark it as I/O error.

---
 drivers/net/iavf/iavf_ethdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/iavf/iavf_ethdev.c +2 -1
index c06873d26..0084a083b 100644
@@ -2356,7 +2356,8 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	rte_free(vf->aq_resp);
 	vf->aq_resp = NULL;
 
-	vf->vf_reset = false;
+	if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true))
+		vf->vf_reset = false;
 
 	return ret;
 }
Signature · 1 line
2.31.1
#34 lore raw

PATCH v5 3/3 net/i40e: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master. And if failed, the device or system may be in an invalid state, so keep the VF reset state to mark it as I/O error.

---
 drivers/net/i40e/i40e_ethdev_vf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_ethdev_vf.c +5 -1
index cb898bdb6..bded64842 100644
@@ -1213,7 +1213,6 @@ i40evf_check_vf_reset_done(struct rte_eth_dev *dev)
 	if (i >= MAX_RESET_WAIT_CNT)
 		return -1;
 
-	vf->vf_reset = false;
 	vf->pend_msg &= ~PFMSG_RESET_IMPENDING;
 
 	return 0;
@@ -1392,6 +1391,7 @@ i40evf_handle_pf_event(struct rte_eth_dev *dev, uint8_t *msg,
 	switch (pf_msg->event) {
 	case VIRTCHNL_EVENT_RESET_IMPENDING:
 		PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
+		vf->vf_reset = true;
 		rte_eth_dev_callback_process(dev,
 				RTE_ETH_EVENT_INTR_RESET, NULL);
 		break;
@@ -2490,6 +2490,10 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 	i40e_shutdown_adminq(hw);
 	i40evf_disable_irq0(hw);
 
+	if (vf->vf_reset &&
+	    !rte_pci_set_bus_master(RTE_ETH_DEV_TO_PCI(dev), true))
+		vf->vf_reset = false;
+
 	rte_free(vf->vf_res);
 	vf->vf_res = NULL;
 	rte_free(vf->aq_resp);
Signature · 1 line
2.31.1
#35 lore raw

v6 cover fix PF reset causes VF memory request failure

In reply to Haiyue Wang

By triggerring the VF reset from PF reset,

echo 1 > /sys/bus/pci/devices/PF-BDF/reset

the PCI bus master bit will cleared on VF, so the VF needs to enable this bit before restart.

This patch set adds the API to enable PCI bus master.

v6: update the annotate symbol version, and add some comments in source code
v5: error handling if bus master enable failed
v4: change the API to set type, so can enable or disable
v3: added the missed annotate symbol add time
v2: rebase to new librte directory path

Haiyue Wang (3):
bus/pci: set PCI master in command register
net/iavf: enable PCI bus master after reset
net/i40e: enable PCI bus master after reset

 drivers/bus/pci/pci_common.c      | 28 ++++++++++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h     | 14 ++++++++++++++
 drivers/bus/pci/version.map       |  3 +++
 drivers/net/i40e/i40e_ethdev_vf.c | 13 ++++++++++++-
 drivers/net/iavf/iavf_ethdev.c    | 10 +++++++++-
 lib/pci/rte_pci.h                 |  4 ++++
 6 files changed, 70 insertions(+), 2 deletions(-)
Signature · 1 line
2.31.1
#36 lore raw

PATCH v6 1/3 bus/pci: set PCI master in command register

Add the API to set 'Bus Master Enable' bit to be enabled or disabled in the PCI command register.

---
 drivers/bus/pci/pci_common.c  | 28 ++++++++++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h | 14 ++++++++++++++
 drivers/bus/pci/version.map   |  3 +++
 lib/pci/rte_pci.h             |  4 ++++
 4 files changed, 49 insertions(+)
drivers/bus/pci/pci_common.c +28 -0
index ee7f966358..35d7d092d1 100644
@@ -746,6 +746,34 @@ rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap)
 	return 0;
 }
 
+int
+rte_pci_set_bus_master(struct rte_pci_device *dev, bool enable)
+{
+	uint16_t old_cmd, cmd;
+
+	if (rte_pci_read_config(dev, &old_cmd, sizeof(old_cmd),
+				RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in reading PCI command register\n");
+		return -1;
+	}
+
+	if (enable)
+		cmd = old_cmd | RTE_PCI_COMMAND_MASTER;
+	else
+		cmd = old_cmd & ~RTE_PCI_COMMAND_MASTER;
+
+	if (cmd == old_cmd)
+		return 0;
+
+	if (rte_pci_write_config(dev, &cmd, sizeof(cmd),
+				 RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in writing PCI command register\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
drivers/bus/pci/rte_bus_pci.h +14 -0
index 64886b4731..976c33c921 100644
@@ -249,6 +249,20 @@ void rte_pci_dump(FILE *f);
 __rte_experimental
 off_t rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap);
 
+/**
+ * Enables/Disables Bus Master for device's PCI command register.
+ *
+ *  @param dev
+ *    A pointer to rte_pci_device structure.
+ *  @param enable
+ *    Enable or disable Bus Master.
+ *
+ *  @return
+ *  0 on success, -1 on error in PCI config space read/write.
+ */
+__rte_experimental
+int rte_pci_set_bus_master(struct rte_pci_device *dev, bool enable);
+
 /**
  * Register a PCI driver.
  *
drivers/bus/pci/version.map +3 -0
index f33ed0abd1..00fac8864c 100644
@@ -21,4 +21,7 @@ EXPERIMENTAL {
 	global:
 
 	rte_pci_find_ext_capability;
+
+	# added in 21.08
+	rte_pci_set_bus_master;
 };
lib/pci/rte_pci.h +4 -0
index a8f8e404a9..1f33d687f4 100644
@@ -32,6 +32,10 @@ extern "C" {
 
 #define RTE_PCI_VENDOR_ID	0x00	/* 16 bits */
 #define RTE_PCI_DEVICE_ID	0x02	/* 16 bits */
+#define RTE_PCI_COMMAND		0x04	/* 16 bits */
+
+/* PCI Command Register */
+#define RTE_PCI_COMMAND_MASTER	0x4	/* Bus Master Enable */
 
 /* PCI Express capability registers */
 #define RTE_PCI_EXP_DEVCTL	8	/* Device Control */
Signature · 1 line
2.31.1
#37 lore raw

PATCH v6 2/3 net/iavf: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master. And if failed, the device or system may be in an invalid state, so keep the VF reset state to mark it as I/O error.

---
 drivers/net/iavf/iavf_ethdev.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/iavf/iavf_ethdev.c +9 -1
index d688c31cfb..a7ef7a6d4d 100644
@@ -2356,7 +2356,15 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	rte_free(vf->aq_resp);
 	vf->aq_resp = NULL;
 
-	vf->vf_reset = false;
+	/*
+	 * If the VF is reset via VFLR, the device will be knocked out of bus
+	 * master mode, and the driver will fail to recover from the reset. Fix
+	 * this by enabling bus mastering after every reset. In a non-VFLR case,
+	 * the bus master bit will not be disabled, and this call will have no
+	 * effect.
+	 */
+	if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true))
+		vf->vf_reset = false;
 
 	return ret;
 }
Signature · 1 line
2.31.1
#38 lore raw

PATCH v6 3/3 net/i40e: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggerred by the PF reset event, in this case, the PCI bus master will be cleared, then the VF is not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master. And if failed, the device or system may be in an invalid state, so keep the VF reset state to mark it as I/O error.

---
 drivers/net/i40e/i40e_ethdev_vf.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_ethdev_vf.c +12 -1
index cb898bdb68..385ebedcd3 100644
@@ -1213,7 +1213,6 @@ i40evf_check_vf_reset_done(struct rte_eth_dev *dev)
 	if (i >= MAX_RESET_WAIT_CNT)
 		return -1;
 
-	vf->vf_reset = false;
 	vf->pend_msg &= ~PFMSG_RESET_IMPENDING;
 
 	return 0;
@@ -1392,6 +1391,7 @@ i40evf_handle_pf_event(struct rte_eth_dev *dev, uint8_t *msg,
 	switch (pf_msg->event) {
 	case VIRTCHNL_EVENT_RESET_IMPENDING:
 		PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
+		vf->vf_reset = true;
 		rte_eth_dev_callback_process(dev,
 				RTE_ETH_EVENT_INTR_RESET, NULL);
 		break;
@@ -2468,6 +2468,7 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 {
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 	int ret;
 
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
@@ -2490,6 +2491,16 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 	i40e_shutdown_adminq(hw);
 	i40evf_disable_irq0(hw);
 
+	/*
+	 * If the VF is reset via VFLR, the device will be knocked out of bus
+	 * master mode, and the driver will fail to recover from the reset. Fix
+	 * this by enabling bus mastering after every reset. In a non-VFLR case,
+	 * the bus master bit will not be disabled, and this call will have no
+	 * effect.
+	 */
+	if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true))
+		vf->vf_reset = false;
+
 	rte_free(vf->vf_res);
 	vf->vf_res = NULL;
 	rte_free(vf->aq_resp);
Signature · 1 line
2.31.1
#39 lore raw

v7 cover fix PF reset causes VF memory request failure

In reply to Haiyue Wang

Trigger the VF reset from PF reset,

echo 1 > /sys/bus/pci/devices/PF-BDF/reset

the PCI bus master bit will cleared on VF, so the VF needs to enable this bit before restart.

This patch set adds the API to enable PCI bus master.

v7: fix the commit message typo, and update some description.
v6: update the annotate symbol version, and add some comments in source code
v5: error handling if bus master enable failed
v4: change the API to set type, so can enable or disable
v3: added the missed annotate symbol add time
v2: rebase to new librte directory path

Haiyue Wang (3):
bus/pci: set PCI master in command register
net/iavf: enable PCI bus master after reset
net/i40e: enable PCI bus master after reset

 drivers/bus/pci/pci_common.c      | 28 ++++++++++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h     | 14 ++++++++++++++
 drivers/bus/pci/version.map       |  3 +++
 drivers/net/i40e/i40e_ethdev_vf.c | 13 ++++++++++++-
 drivers/net/iavf/iavf_ethdev.c    | 10 +++++++++-
 lib/pci/rte_pci.h                 |  4 ++++
 6 files changed, 70 insertions(+), 2 deletions(-)
Signature · 1 line
2.31.1
#40 lore raw

PATCH v7 1/3 bus/pci: set PCI master in command register

Add the API to set 'Bus Master Enable' bit to be enabled or disabled in the PCI command register.

---
 drivers/bus/pci/pci_common.c  | 28 ++++++++++++++++++++++++++++
 drivers/bus/pci/rte_bus_pci.h | 14 ++++++++++++++
 drivers/bus/pci/version.map   |  3 +++
 lib/pci/rte_pci.h             |  4 ++++
 4 files changed, 49 insertions(+)
drivers/bus/pci/pci_common.c +28 -0
index ee7f966358..35d7d092d1 100644
@@ -746,6 +746,34 @@ rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap)
 	return 0;
 }
 
+int
+rte_pci_set_bus_master(struct rte_pci_device *dev, bool enable)
+{
+	uint16_t old_cmd, cmd;
+
+	if (rte_pci_read_config(dev, &old_cmd, sizeof(old_cmd),
+				RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in reading PCI command register\n");
+		return -1;
+	}
+
+	if (enable)
+		cmd = old_cmd | RTE_PCI_COMMAND_MASTER;
+	else
+		cmd = old_cmd & ~RTE_PCI_COMMAND_MASTER;
+
+	if (cmd == old_cmd)
+		return 0;
+
+	if (rte_pci_write_config(dev, &cmd, sizeof(cmd),
+				 RTE_PCI_COMMAND) < 0) {
+		RTE_LOG(ERR, EAL, "error in writing PCI command register\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
drivers/bus/pci/rte_bus_pci.h +14 -0
index 64886b4731..976c33c921 100644
@@ -249,6 +249,20 @@ void rte_pci_dump(FILE *f);
 __rte_experimental
 off_t rte_pci_find_ext_capability(struct rte_pci_device *dev, uint32_t cap);
 
+/**
+ * Enables/Disables Bus Master for device's PCI command register.
+ *
+ *  @param dev
+ *    A pointer to rte_pci_device structure.
+ *  @param enable
+ *    Enable or disable Bus Master.
+ *
+ *  @return
+ *  0 on success, -1 on error in PCI config space read/write.
+ */
+__rte_experimental
+int rte_pci_set_bus_master(struct rte_pci_device *dev, bool enable);
+
 /**
  * Register a PCI driver.
  *
drivers/bus/pci/version.map +3 -0
index f33ed0abd1..00fac8864c 100644
@@ -21,4 +21,7 @@ EXPERIMENTAL {
 	global:
 
 	rte_pci_find_ext_capability;
+
+	# added in 21.08
+	rte_pci_set_bus_master;
 };
lib/pci/rte_pci.h +4 -0
index a8f8e404a9..1f33d687f4 100644
@@ -32,6 +32,10 @@ extern "C" {
 
 #define RTE_PCI_VENDOR_ID	0x00	/* 16 bits */
 #define RTE_PCI_DEVICE_ID	0x02	/* 16 bits */
+#define RTE_PCI_COMMAND		0x04	/* 16 bits */
+
+/* PCI Command Register */
+#define RTE_PCI_COMMAND_MASTER	0x4	/* Bus Master Enable */
 
 /* PCI Express capability registers */
 #define RTE_PCI_EXP_DEVCTL	8	/* Device Control */
Signature · 1 line
2.31.1
#41 lore raw

PATCH v7 2/3 net/iavf: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggered by the PF reset event, then the PCI bus master will be cleared, the VF will be not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master. And if failed, the device or system may be in an invalid state, so keep the VF reset state to mark it as I/O error.

---
 drivers/net/iavf/iavf_ethdev.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/iavf/iavf_ethdev.c +9 -1
index d688c31cfb..a7ef7a6d4d 100644
@@ -2356,7 +2356,15 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	rte_free(vf->aq_resp);
 	vf->aq_resp = NULL;
 
-	vf->vf_reset = false;
+	/*
+	 * If the VF is reset via VFLR, the device will be knocked out of bus
+	 * master mode, and the driver will fail to recover from the reset. Fix
+	 * this by enabling bus mastering after every reset. In a non-VFLR case,
+	 * the bus master bit will not be disabled, and this call will have no
+	 * effect.
+	 */
+	if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true))
+		vf->vf_reset = false;
 
 	return ret;
 }
Signature · 1 line
2.31.1
Acked-by on v7 2/3
#42 lore raw

Re: [dpdk-dev] [PATCH v7 2/3] net/iavf: enable PCI bus master after reset

Quoted 46 lines

-----Original Message-----
From: Wang, Haiyue <[email protected]>
Sent: Monday, May 24, 2021 9:24 AM
To: [email protected]
Cc: Zhang, Qi Z <[email protected]>; Wang, Liang-min <liang- [email protected]>; [email protected]; Wang, Haiyue <[email protected]>; Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Subject: [PATCH v7 2/3] net/iavf: enable PCI bus master after reset

The VF reset can be triggered by the PF reset event, then the PCI bus master will be cleared, the VF will be not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master. And if failed, the device or system may be in an invalid state, so keep the VF reset state to mark it as I/O error.

---
 drivers/net/iavf/iavf_ethdev.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/iavf/iavf_ethdev.c +9 -1
index d688c31cfb..a7ef7a6d4d 100644
@@ -2356,7 +2356,15 @@ iavf_dev_close(struct rte_eth_dev *dev)
 	rte_free(vf->aq_resp);
 	vf->aq_resp = NULL;
 
-	vf->vf_reset = false;
+	/*
+	 * If the VF is reset via VFLR, the device will be knocked out of bus
+	 * master mode, and the driver will fail to recover from the reset. Fix
+	 * this by enabling bus mastering after every reset. In a non-VFLR
 case,
+	 * the bus master bit will not be disabled, and this call will have no
+	 * effect.
+	 */
+	if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true))
+		vf->vf_reset = false;
 
 	return ret;
Quoted 3 lines

}
--
2.31.1

#43 lore raw

PATCH v7 3/3 net/i40e: enable PCI bus master after reset

In reply to Haiyue Wang

The VF reset can be triggered by the PF reset event, then the PCI bus master will be cleared, the VF will be not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master. And if failed, the device or system may be in an invalid state, so keep the VF reset state to mark it as I/O error.

---
 drivers/net/i40e/i40e_ethdev_vf.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_ethdev_vf.c +12 -1
index cb898bdb68..385ebedcd3 100644
@@ -1213,7 +1213,6 @@ i40evf_check_vf_reset_done(struct rte_eth_dev *dev)
 	if (i >= MAX_RESET_WAIT_CNT)
 		return -1;
 
-	vf->vf_reset = false;
 	vf->pend_msg &= ~PFMSG_RESET_IMPENDING;
 
 	return 0;
@@ -1392,6 +1391,7 @@ i40evf_handle_pf_event(struct rte_eth_dev *dev, uint8_t *msg,
 	switch (pf_msg->event) {
 	case VIRTCHNL_EVENT_RESET_IMPENDING:
 		PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
+		vf->vf_reset = true;
 		rte_eth_dev_callback_process(dev,
 				RTE_ETH_EVENT_INTR_RESET, NULL);
 		break;
@@ -2468,6 +2468,7 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 {
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 	int ret;
 
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
@@ -2490,6 +2491,16 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 	i40e_shutdown_adminq(hw);
 	i40evf_disable_irq0(hw);
 
+	/*
+	 * If the VF is reset via VFLR, the device will be knocked out of bus
+	 * master mode, and the driver will fail to recover from the reset. Fix
+	 * this by enabling bus mastering after every reset. In a non-VFLR case,
+	 * the bus master bit will not be disabled, and this call will have no
+	 * effect.
+	 */
+	if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true))
+		vf->vf_reset = false;
+
 	rte_free(vf->vf_res);
 	vf->vf_res = NULL;
 	rte_free(vf->aq_resp);
Signature · 1 line
2.31.1
Acked-by on v7 3/3
#44 lore raw

Re: [dpdk-dev] [PATCH v7 3/3] net/i40e: enable PCI bus master after reset

Quoted 76 lines

-----Original Message-----
From: Wang, Haiyue <[email protected]>
Sent: Monday, May 24, 2021 9:24 AM
To: [email protected]
Cc: Zhang, Qi Z <[email protected]>; Wang, Liang-min <liang- [email protected]>; [email protected]; Wang, Haiyue <[email protected]>; Xing, Beilei <[email protected]>
Subject: [PATCH v7 3/3] net/i40e: enable PCI bus master after reset

The VF reset can be triggered by the PF reset event, then the PCI bus master will be cleared, the VF will be not allowed to issue any Memory or I/O Requests.

So after the reset event is detected, always enable the PCI bus master. And if failed, the device or system may be in an invalid state, so keep the VF reset state to mark it as I/O error.

---
 drivers/net/i40e/i40e_ethdev_vf.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/i40e/i40e_ethdev_vf.c +0 -1
index cb898bdb68..385ebedcd3 100644
@@ -1213,7 +1213,6 @@ i40evf_check_vf_reset_done(struct rte_eth_dev
 *dev)
 	if (i >= MAX_RESET_WAIT_CNT)
 		return -1;
 
-	vf->vf_reset = false;
 	vf->pend_msg &= ~PFMSG_RESET_IMPENDING;
 
drivers/net/i40e/i40e_ethdev_vf.c +1 -0
 	return 0;
@@ -1392,6 +1391,7 @@ i40evf_handle_pf_event(struct rte_eth_dev *dev,
 uint8_t *msg,
 	switch (pf_msg->event) {
 	case VIRTCHNL_EVENT_RESET_IMPENDING:
 		PMD_DRV_LOG(DEBUG,
 "VIRTCHNL_EVENT_RESET_IMPENDING event");
+		vf->vf_reset = true;
 		rte_eth_dev_callback_process(dev,
drivers/net/i40e/i40e_ethdev_vf.c +1 -0
 				RTE_ETH_EVENT_INTR_RESET, NULL);
 		break;
@@ -2468,6 +2468,7 @@ i40evf_dev_close(struct rte_eth_dev *dev)  {
 	struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data-
 >dev_private);
 	struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data-
 >dev_private);
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 	int ret;
 
drivers/net/i40e/i40e_ethdev_vf.c +5 -0
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) @@ -2490,6
+2491,16 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 	i40e_shutdown_adminq(hw);
 	i40evf_disable_irq0(hw);
 
+	/*
+	 * If the VF is reset via VFLR, the device will be knocked out of bus
+	 * master mode, and the driver will fail to recover from the reset. Fix
+	 * this by enabling bus mastering after every reset. In a non-VFLR

case,

drivers/net/i40e/i40e_ethdev_vf.c +6 -1
+	 * the bus master bit will not be disabled, and this call will have no
+	 * effect.
+	 */
+	if (vf->vf_reset && !rte_pci_set_bus_master(pci_dev, true))
+		vf->vf_reset = false;
+
 	rte_free(vf->vf_res);
 	vf->vf_res = NULL;
 	rte_free(vf->aq_resp);
--
Quoted 1 line

2.31.1

#45 lore raw

Re: [dpdk-dev] [PATCH v7 0/3] fix PF reset causes VF memory request failure

In reply to Haiyue Wang
Quoted 17 lines · Haiyue Wang

Trigger the VF reset from PF reset,

echo 1 > /sys/bus/pci/devices/PF-BDF/reset

the PCI bus master bit will cleared on VF, so the VF needs to enable this bit before restart.

This patch set adds the API to enable PCI bus master.

v7: fix the commit message typo, and update some description.
v6: update the annotate symbol version, and add some comments in source code
v5: error handling if bus master enable failed
v4: change the API to set type, so can enable or disable
v3: added the missed annotate symbol add time
v2: rebase to new librte directory path

Quoted 4 lines

Haiyue Wang (3):
bus/pci: set PCI master in command register
net/iavf: enable PCI bus master after reset
net/i40e: enable PCI bus master after reset

Series applied, thanks Haiyue.
I'll post a followup patch on using this API in other parts of dpdk.

Signature · 1 line
David Marchand