PCI: handle CRS response following Hot Reset and D3hot->D0
Subsystems (2)
v3 cover PCI: handle CRS response following Hot Reset and D3hot->D0
Rev 3.1 Sec 2.3.1 Request Handling Rules:
Valid reset conditions after which a device is permitted to return CRS are:
* Cold, Warm, and Hot Resets,
* FLR
* A reset initiated in response to a D3hot to D0 uninitialized
Try to reuse FLR implementation towards other reset types.
Changes from v2:
* Correct Conventional PCI spec reference for AF_FLR
* Commit message update to capitilize the first word following colon
Sinan Kaya (6):
PCI: Protect restore with device lock to be consistent
PCI: Handle FLR failure and allow other reset types
PCI: Make pci_flr_wait() generic and rename to pci_dev_wait()
PCI: Wait device ready after pci_pm_reset()
PCI: Add a return type for pci_reset_bridge_secondary_bus()
PCI: Add device wait after slot and bus reset
drivers/pci/pci.c | 70 ++++++++++++++++++++++++++++++++++------------------- include/linux/pci.h | 4 +-- 2 files changed, 47 insertions(+), 27 deletions(-)
Signature · 1 line
1.9.1
PATCH v3 1/6 PCI: Protect restore with device lock to be consistent
Commit b014e96d1abb ("PCI: Protect pci_error_handlers->reset_notify() usage with device_lock()") added protection around pci_dev_restore() function so that device specific remove callback does not cause a race condition against hotplug.
pci_dev_lock() usage has been forgotten in two different places in the code. Adding locks for pci_slot_restore() and moving pci_dev_restore() inside the locks for pci_try_reset_function().
--- drivers/pci/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/pci.c +3 -1
@@ -4448,9 +4448,9 @@ int pci_try_reset_function(struct pci_dev *dev)pci_dev_save_and_disable (dev); rc =__pci_reset_function_locked (dev); +pci_dev_restore (dev);pci_dev_unlock (dev); -pci_dev_restore (dev);return rc; }EXPORT_SYMBOL_GPL (pci_try_reset_function);
@@ -4658,7 +4658,9 @@ static void pci_slot_restore(struct pci_slot *slot)list_for_each_entry (dev, &slot->bus->devices, bus_list) {if (!dev->slot || dev->slot != slot)continue ; +pci_dev_lock (dev);pci_dev_restore (dev); +pci_dev_unlock (dev);if (dev->subordinate)pci_bus_restore (dev->subordinate); }
Signature · 1 line
1.9.1
PATCH v3 2/6 PCI: Handle FLR failure and allow other reset types
In reply to Sinan Kayapci_flr_wait() and pci_af_flr() functions assume graceful return even though the device is inaccessible under error conditions.
Return -ENOTTY in error cases so that __pci_reset_function_locked() can try other reset types if AF_FLR/FLR reset fails.
--- drivers/pci/pci.c | 18 ++++++++++-------- include/linux/pci.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-)
drivers/pci/pci.c +10 -8
@@ -3945,7 +3945,7 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev) }EXPORT_SYMBOL (pci_wait_for_pending_transaction); -static void pci_flr_wait (struct pci_dev *dev) +static int pci_flr_wait (struct pci_dev *dev) {int delay =1 , timeout =60000 ;u32 id;
@@ -3974,7 +3974,7 @@ static void pci_flr_wait(struct pci_dev *dev)if (delay > timeout) {dev_warn (&dev->dev,"not ready %dms after FLR; giving up\n" ,100 + delay -1 ); -return ; +return -ENOTTY ; }if (delay >1000 )
@@ -3988,6 +3988,8 @@ static void pci_flr_wait(struct pci_dev *dev)if (delay >1000 )dev_info (&dev->dev,"ready %dms after FLR\n" ,100 + delay -1 ); + +return 0 ; }/**
@@ -4016,13 +4018,13 @@ static bool pcie_has_flr(struct pci_dev *dev)* device supports FLR before calling this function, e.g. by using the * pcie_has_flr() helper. */ -void pcie_flr (struct pci_dev *dev) +int pcie_flr (struct pci_dev *dev) {if (!pci_wait_for_pending_transaction (dev))dev_err (&dev->dev,"timed out waiting for pending transaction; performing function level reset anyway\n" );pcie_capability_set_word (dev,PCI_EXP_DEVCTL ,PCI_EXP_DEVCTL_BCR_FLR ); -pci_flr_wait (dev); +return pci_flr_wait (dev); }EXPORT_SYMBOL_GPL (pcie_flr);
@@ -4055,8 +4057,7 @@ static int pci_af_flr(struct pci_dev *dev, int probe)dev_err (&dev->dev,"timed out waiting for pending transaction; performing AF function level reset anyway\n" );pci_write_config_byte (dev, pos +PCI_AF_CTRL ,PCI_AF_CTRL_FLR ); -pci_flr_wait (dev); -return 0 ; +return pci_flr_wait (dev); }/**
@@ -4307,8 +4308,9 @@ int __pci_reset_function_locked(struct pci_dev *dev)if (rc != -ENOTTY )return rc;if (pcie_has_flr (dev)) { -pcie_flr (dev); -return 0 ; + rc =pcie_flr (dev); +if (rc != -ENOTTY ) +return rc; } rc =pci_af_flr (dev,0 );if (rc != -ENOTTY )
include/linux/pci.h +1 -1
@@ -1081,7 +1081,7 @@ static inline int pci_is_managed(struct pci_dev *pdev)int pcie_set_mps (struct pci_dev *dev,int mps);int pcie_get_minimum_link (struct pci_dev *dev,enum pci_bus_speed *speed,enum pcie_link_width *width); -void pcie_flr (struct pci_dev *dev); +int pcie_flr (struct pci_dev *dev);int __pci_reset_function_locked (struct pci_dev *dev);int pci_reset_function (struct pci_dev *dev);int pci_reset_function_locked (struct pci_dev *dev);
Signature · 1 line
1.9.1
PATCH v3 3/6 PCI: Make pci_flr_wait() generic and rename to pci_dev_wait()
In reply to Sinan KayaRev 3.1 Sec 2.3.1 Request Handling Rules:
Valid reset conditions after which a device is permitted to return CRS are:
* Cold, Warm, and Hot Resets,
* FLR
* A reset initiated in response to a D3hot to D0 uninitialized
Try to reuse FLR implementation towards other reset types.
--- drivers/pci/pci.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-)
drivers/pci/pci.c +31 -17
@@ -125,6 +125,9 @@ static int __init pcie_port_pm_setup(char *str) }__setup ("pcie_port_pm=" , pcie_port_pm_setup); +/* time to wait after a reset for device to become responsive */ +#define PCIE_RESET_READY_POLL_MS 60000 +/** * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children * @bus: pointer to PCI bus structure to search
@@ -3945,20 +3948,13 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev) }EXPORT_SYMBOL (pci_wait_for_pending_transaction); -static int pci_flr_wait (struct pci_dev *dev) +static int pci_dev_wait (struct pci_dev *dev,char *reset_type,int timeout) { -int delay =1 , timeout =60000 ; +int delay =1 ;u32 id;/* -* Per PCIe r3.1, sec 6.6.2, a device must complete an FLR within -* 100ms, but may silently discard requests while the FLR is in -* progress. Wait 100ms before trying to access the device. -*/ -msleep (100 ); - -/* -* After 100ms, the device should not silently discard config +* After reset, the device should not silently discard config * requests, but it may still indicate that it needs more time by * responding to them with CRS completions. The Root Port will * generally synthesize ~0 data to complete the read (except when
@@ -3972,14 +3968,14 @@ static int pci_flr_wait(struct pci_dev *dev)pci_read_config_dword (dev,PCI_COMMAND , &id);while (id == ~0 ) {if (delay > timeout) { -dev_warn (&dev->dev,"not ready %dms after FLR; giving up\n" , -100 + delay -1 ); +dev_warn (&dev->dev,"not ready %dms after %s; giving up\n" , + delay -1 , reset_type);return -ENOTTY ; }if (delay >1000 ) -dev_info (&dev->dev,"not ready %dms after FLR; waiting\n" , -100 + delay -1 ); +dev_info (&dev->dev,"not ready %dms after %s; waiting\n" , + delay -1 , reset_type);msleep (delay); delay *=2 ;
@@ -3987,7 +3983,8 @@ static int pci_flr_wait(struct pci_dev *dev) }if (delay >1000 ) -dev_info (&dev->dev,"ready %dms after FLR\n" ,100 + delay -1 ); +dev_info (&dev->dev,"ready %dms after %s\n" , delay -1 , + reset_type);return 0 ; }
@@ -4024,7 +4021,15 @@ int pcie_flr(struct pci_dev *dev)dev_err (&dev->dev,"timed out waiting for pending transaction; performing function level reset anyway\n" );pcie_capability_set_word (dev,PCI_EXP_DEVCTL ,PCI_EXP_DEVCTL_BCR_FLR ); -return pci_flr_wait (dev); + +/* +* Per PCIe r3.1, sec 6.6.2, a device must complete an FLR within +* 100ms, but may silently discard requests while the FLR is in +* progress. Wait 100ms before trying to access the device. +*/ +msleep (100 ); + +return pci_dev_wait (dev,"FLR" ,PCIE_RESET_READY_POLL_MS ); }EXPORT_SYMBOL_GPL (pcie_flr);
@@ -4057,7 +4062,16 @@ static int pci_af_flr(struct pci_dev *dev, int probe)dev_err (&dev->dev,"timed out waiting for pending transaction; performing AF function level reset anyway\n" );pci_write_config_byte (dev, pos +PCI_AF_CTRL ,PCI_AF_CTRL_FLR ); -return pci_flr_wait (dev); + +/* +* Per Advanced Capabilities for Conventional PCI ECN, 13 April 2006, +* updated 27 July 2006; a device must complete an FLR within +* 100ms, but may silently discard requests while the FLR is in +* progress. Wait 100ms before trying to access the device. +*/ +msleep (100 ); + +return pci_dev_wait (dev,"AF_FLR" ,PCIE_RESET_READY_POLL_MS ); }/**
Signature · 1 line
1.9.1
PATCH v3 4/6 PCI: Wait device ready after pci_pm_reset()
In reply to Sinan KayaRev 3.1 Sec 2.3.1 Request Handling Rules says a device can issue CRS following a D3hot->D0 transition. Add pci_dev_wait() call to see if device is available before returning.
--- drivers/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci.c +1 -1
@@ -4116,7 +4116,7 @@ static int pci_pm_reset(struct pci_dev *dev, int probe)pci_write_config_word (dev, dev->pm_cap +PCI_PM_CTRL , csr);pci_dev_d3_sleep (dev); -return 0 ; +return pci_dev_wait (dev,"PM D3->D0" ,PCIE_RESET_READY_POLL_MS ); }void pci_reset_secondary_bus (struct pci_dev *dev)
Signature · 1 line
1.9.1
PATCH v3 5/6 PCI: Add a return type for pci_reset_bridge_secondary_bus()
In reply to Sinan KayaGetting ready to return an error from pci_reset_bridge_secondary_bus() when device is unreachable.
--- drivers/pci/pci.c | 4 +++- include/linux/pci.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/pci/pci.c +3 -1
@@ -4157,9 +4157,11 @@ void __weak pcibios_reset_secondary_bus(struct pci_dev *dev)* Use the bridge control register to assert reset on the secondary bus. * Devices on the secondary bus are left in power-on state. */ -void pci_reset_bridge_secondary_bus (struct pci_dev *dev) +int pci_reset_bridge_secondary_bus (struct pci_dev *dev) {pcibios_reset_secondary_bus (dev); + +return 0 ; }EXPORT_SYMBOL_GPL (pci_reset_bridge_secondary_bus);
include/linux/pci.h +1 -1
@@ -1094,7 +1094,7 @@ int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed,int pci_try_reset_bus (struct pci_bus *bus);void pci_reset_secondary_bus (struct pci_dev *dev);void pcibios_reset_secondary_bus (struct pci_dev *dev); -void pci_reset_bridge_secondary_bus (struct pci_dev *dev); +int pci_reset_bridge_secondary_bus (struct pci_dev *dev);void pci_update_resource (struct pci_dev *dev,int resno);int __must_check pci_assign_resource (struct pci_dev *dev,int i);int __must_check pci_reassign_resource (struct pci_dev *dev,int i,resource_size_t add_size,resource_size_t align);
Signature · 1 line
1.9.1
PATCH v3 6/6 PCI: Add device wait after slot and bus reset
In reply to Sinan KayaRev 3.1 Sec 2.3.1 Request Handling Rules indicates that a device can issue CRS following secondary bus reset. Handle device presence gracefully.
--- drivers/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci.c +1 -1
@@ -4161,7 +4161,7 @@ int pci_reset_bridge_secondary_bus(struct pci_dev *dev) {pcibios_reset_secondary_bus (dev); -return 0 ; +return pci_dev_wait (dev,"bus reset" ,PCIE_RESET_READY_POLL_MS ); }EXPORT_SYMBOL_GPL (pci_reset_bridge_secondary_bus);
Signature · 1 line
1.9.1
v3 cover PCI: handle CRS response following Hot Reset and D3hot->D0
In reply to Sinan KayaHi Bjorn,
Quoted 21 lines · Sinan Kaya
Rev 3.1 Sec 2.3.1 Request Handling Rules:
Valid reset conditions after which a device is permitted to return CRS are:
* Cold, Warm, and Hot Resets,
* FLR
* A reset initiated in response to a D3hot to D0 uninitializedTry to reuse FLR implementation towards other reset types.
Changes from v2:
* Correct Conventional PCI spec reference forAF_FLR
* Commit message update to capitilize the first word following colonSinan Kaya (6):
PCI: Protect restore with device lock to be consistent
PCI: Handle FLR failure and allow other reset types
PCI: Makepci_flr_wait()generic and rename topci_dev_wait()
PCI: Wait device ready afterpci_pm_reset()
PCI: Add a return type forpci_reset_bridge_secondary_bus()
PCI: Add device wait after slot and bus reset
Quoted 4 lines
drivers/pci/pci.c | 70 ++++++++++++++++++++++++++++++++++------------------- include/linux/pci.h | 4 +-- 2 files changed, 47 insertions(+), 27 deletions(-)
Do you think this is ready for merge or do you have more feedback?
Sinan
Signature · 3 lines
Sinan Kaya Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Bjorn Helgaas
Appliedv3 cover PCI: handle CRS response following Hot Reset and D3hot->D0
In reply to Sinan KayaQuoted 21 lines · Sinan Kaya
Rev 3.1 Sec 2.3.1 Request Handling Rules:
Valid reset conditions after which a device is permitted to return CRS are:
* Cold, Warm, and Hot Resets,
* FLR
* A reset initiated in response to a D3hot to D0 uninitializedTry to reuse FLR implementation towards other reset types.
Changes from v2:
* Correct Conventional PCI spec reference forAF_FLR
* Commit message update to capitilize the first word following colonSinan Kaya (6):
PCI: Protect restore with device lock to be consistent
PCI: Handle FLR failure and allow other reset types
PCI: Makepci_flr_wait()generic and rename topci_dev_wait()
PCI: Wait device ready afterpci_pm_reset()
PCI: Add a return type forpci_reset_bridge_secondary_bus()
PCI: Add device wait after slot and bus reset
Quoted 3 lines
drivers/pci/pci.c | 70 ++++++++++++++++++++++++++++++++++------------------- include/linux/pci.h | 4 +-- 2 files changed, 47 insertions(+), 27 deletions(-)
Applied to pci/virtualization for v4.17, thanks!