linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V9 1/2] PCI: handle CRS returned by device after FLR
@ 2017-08-09  0:57 Sinan Kaya
  2017-08-09  0:57 ` [PATCH V9 2/2] PCI: display not responding message while device is unreachable Sinan Kaya
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Sinan Kaya @ 2017-08-09  0:57 UTC (permalink / raw)
  To: linux-arm-kernel

Sporadic reset issues have been observed with Intel 750 NVMe drive by
writing to the reset file in sysfs in a loop. The sequence of events
observed is as follows:

- perform a Function Level Reset (FLR)
- sleep up to 1000ms total
- read ~0 from PCI_COMMAND
- warn that the device didn't return from FLR
- touch the device before it's ready

An endpoint is allowed to issue Configuration Request Retry Status (CRS)
following a FLR request to indicate that it is not ready to accept new
requests. CRS is defined in PCIe r3.1, sec 2.3.1. Request Handling Rules
and CRS usage in FLR context is mentioned in PCIe r3.1a, sec 6.6.2.
Function-Level Reset.

A CRS indication will only be given if the address to be read is vendor ID
register. pci_bus_read_dev_vendor_id() knows how to deal with CRS returned
0xFFFF0001 value and will continue polling until a value other than
0xFFFF0001 is returned within a given timeout.

Try to discover device presence via CRS first. If device is not found, fall
through to old behavior.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
---
 drivers/pci/pci.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index af0cc34..4366299 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3821,17 +3821,39 @@ static void pci_flr_wait(struct pci_dev *dev)
 {
 	int i = 0;
 	u32 id;
+	bool ret;
+
+	/*
+	 * Don't touch the HW before waiting 100ms. HW has to finish
+	 * within 100ms according to PCI Express Base Specification
+	 * Revision 3.1 Section 6.6.2: Function-Level Reset (FLR).
+	 */
+	msleep(100);
+
+	/*
+	 * See if we can find a device via CRS first. Physical functions
+	 * return from here if found, Virtual functions fall through as
+	 * they return ~0 on vendor id read once CRS is completed.
+	 */
+	ret = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &id,
+					 60000);
+	if (ret)
+		return;
+
+	pci_read_config_dword(dev, PCI_COMMAND, &id);
+	if (id != ~0)
+		return;
 
 	do {
 		msleep(100);
 		pci_read_config_dword(dev, PCI_COMMAND, &id);
-	} while (i++ < 10 && id == ~0);
+	} while (i++ < 9 && id == ~0);
 
 	if (id == ~0)
 		dev_warn(&dev->dev, "Failed to return from FLR\n");
 	else if (i > 1)
 		dev_info(&dev->dev, "Required additional %dms to return from FLR\n",
-			 (i - 1) * 100);
+			 i * 100);
 }
 
 /**
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-08-11 16:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-09  0:57 [PATCH V9 1/2] PCI: handle CRS returned by device after FLR Sinan Kaya
2017-08-09  0:57 ` [PATCH V9 2/2] PCI: display not responding message while device is unreachable Sinan Kaya
2017-08-10 21:52 ` [PATCH V9 1/2] PCI: handle CRS returned by device after FLR Bjorn Helgaas
2017-08-10 22:32   ` Sinan Kaya
2017-08-11 16:54     ` Sinan Kaya
2017-08-10 21:59 ` Bjorn Helgaas
2017-08-11  3:06   ` Sinan Kaya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).