PCI: limit FLR wait time to 100ms maximum
Subsystems (2)
PATCH v6 1/2 PCI: limit FLR wait time to 100ms maximum
Code is currently allowing PCIe devices to extend polling time up to 1 second. Reducing the wait time for virtual functions to 100ms maximum to satisfy spec requirement mentioned in PCIe r3.1, sec 6.6.2. Function-Level Reset (FLR).
SR-IOV r1.1, sec 2.2.2 also mentions that the virtual function's presence from configuration space is not affected from FLR. There is no point in polling the command register since it should always return success.
--- drivers/pci/pci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/pci/pci.c +6 -1
@@ -3812,7 +3812,7 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev)EXPORT_SYMBOL (pci_wait_for_pending_transaction);/* -* We should only need to wait 100ms after FLR, but some devices take longer. +* We should only need to wait 100ms after FLR for virtual functions. * Wait for up to 1000ms for config space to return something other than -1. * Intel IGD requires this when an LCD panel is attached. We read the 2nd * dword because VFs don't implement the 1st dword.
@@ -3822,6 +3822,11 @@ static void pci_flr_wait(struct pci_dev *dev)int i =0 ;u32 id; +if (dev->is_virtfn) { +msleep (100 ); +return ; + } + do { msleep(100); pci_read_config_dword(dev, PCI_COMMAND, &id);
Signature · 1 line
1.9.1
PATCH v6 2/2 PCI: handle CRS returned by device after FLR
An endpoint is allowed to issue Configuration Request Retry Status (CRS) following a Function Level Reset (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.1, sec 6.6.2. Function-Level Reset.
Adding a vendor ID read if this is a physical function before attempting to read any other registers on the endpoint. 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 values.
If pci_bus_read_dev_vendor_id() fails, it prints a user visible warning after provided 1 second timeout is reached. pci_flr_wait() will keep calling this function 60 times to allow up to 60 seconds to be consistent with the rest of the kernel CRS timeout handling.
--- drivers/pci/pci.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)
drivers/pci/pci.c +23 -13
@@ -3813,30 +3813,40 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev)/* * We should only need to wait 100ms after FLR for virtual functions. -* Wait for up to 1000ms for config space to return something other than -1. -* Intel IGD requires this when an LCD panel is attached. We read the 2nd -* dword because VFs don't implement the 1st dword. +* Wait for up to 60s for config space to return something other than -1. +* Intel IGD requires 300ms when an LCD panel is attached. We use +* pci_bus_read_dev_vendor_id() for reading the vendor ID as it handles +* CRS gracefully. */ static void pci_flr_wait (struct pci_dev *dev) { -int i =0 ; +u32 sleep =1000 , total =0 ;u32 id; +bool ret;if (dev->is_virtfn) {msleep (100 );return ; } +/* don't touch the HW before waiting 100ms */ +msleep (100 ); +do { -msleep (100 ); -pci_read_config_dword (dev,PCI_COMMAND , &id); - }while (i++ <10 && 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 ); + ret =pci_bus_read_dev_vendor_id (dev->bus, dev->devfn, &id, + sleep); +if (ret) +break ; + total += sleep; + sleep *=2 ; + }while (total <60000 && !ret); + +if (!ret) +dev_warn (&dev->dev,"Failed to return from FLR after %ds\n" , + total); +else if (total) +dev_info (&dev->dev,"Required additional %ds to return from FLR\n" , + total); }/**
Signature · 1 line
1.9.1
Re: [PATCH V6 2/2] PCI: handle CRS returned by device after FLR
Quoted 3 lines · Sinan Kaya
pci_flr_wait()will keep
calling this function 60 times to allow up to 60 seconds to be consistent with the rest of the kernel CRS timeout handling.
I forgot to update the commit message. I'll wait until Bjorn/Alex reviews this version.
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.
Re: [PATCH V6 2/2] PCI: handle CRS returned by device after FLR
In reply to Sinan KayaQuoted 42 lines · On Wed, 2 Aug 2017 13:18:24 -0400 Sinan Kaya <[email protected]> wrote:
An endpoint is allowed to issue Configuration Request Retry Status (CRS) following a Function Level Reset (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.1, sec 6.6.2. Function-Level Reset.
Adding a vendor ID read if this is a physical function before attempting to read any other registers on the endpoint. 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 values.If
pci_bus_read_dev_vendor_id()fails, it prints a user visible warning after provided 1 second timeout is reached.pci_flr_wait()will keep calling this function 60 times to allow up to 60 seconds to be consistent with the rest of the kernel CRS timeout handling.Signed-off-by Sinan Kaya <[email protected]>--- drivers/pci/pci.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)drivers/pci/pci.c +5
-4@@ -3813,30 +3813,40 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev)/* * We should only need to wait 100ms after FLR for virtual functions. -* Wait for up to 1000ms for config space to return something other than -1. -* Intel IGD requires this when an LCD panel is attached. We read the 2nd -* dword because VFs don't implement the 1st dword. +* Wait for up to 60s for config space to return something other than -1. +* Intel IGD requires 300ms when an LCD panel is attached. We use +* pci_bus_read_dev_vendor_id() for reading the vendor ID as it handles +* CRS gracefully. */ static void pci_flr_wait (struct pci_dev *dev) { -int i =0 ; +u32 sleep =1000 , total =0 ;u32 id;
drivers/pci/pci.c int pci_wait_for_pending_transaction(struct pci_dev *dev) · line 3834
Quoted 10 lines
drivers/pci/pci.c +4
-0+bool ret;if (dev->is_virtfn) {msleep (100 );return ; } +/* don't touch the HW before waiting 100ms */ +msleep (100 ); +
Wouldn't it be better as:
msleep(100); if (dev->is_virtfn) return;
Perhaps with a spec reference in a comment why we don't care about checking config space for the vf.
Quoted 15 lines
drivers/pci/pci.c +5
-9do { -msleep (100 ); -pci_read_config_dword (dev,PCI_COMMAND , &id); - }while (i++ <10 && 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 ); + ret = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &id, + sleep); + if (ret) + break; + total += sleep;
drivers/pci/pci.c int pci_wait_for_pending_transaction(struct pci_dev *dev) · line 3850
Quoted 10 lines
drivers/pci/pci.c +9
-0+ sleep *=2 ; + }while (total <60000 && !ret); + +if (!ret) +dev_warn (&dev->dev,"Failed to return from FLR after %ds\n" , + total); +else if (total) +dev_info (&dev->dev,"Required additional %ds to return from FLR\n" , + total); }
I'm not a big fan. Nested exponential backoff is pretty nasty. Are there users of pci_bus_read_dev_vendor_id() that don't want a "still trying" message? It seems better to add that to the function than try to wrap this bandage around it. Thanks,
Alex
Re: [PATCH V6 2/2] PCI: handle CRS returned by device after FLR
Quoted 1 line · Alex Williamson
On Wed, 2 Aug 2017 13:18:24 -0400
[snip]
Quoted 12 lines
Quoted 12 lines
static void
pci_flr_wait(struct pci_dev *dev)
{drivers/pci/pci.c +2
-1-int i =0 ; +u32 sleep =1000 , total =0 ;u32 id; +bool ret;if (dev->is_virtfn) {msleep (100 );return ; }
Quoted 7 lines
drivers/pci/pci.c int pci_wait_for_pending_transaction(struct pci_dev *dev) · line 3834
Quoted 3 lines
drivers/pci/pci.c +3
-0+/* don't touch the HW before waiting 100ms */ +msleep (100 ); +Wouldn't it be better as:
Sure, that looks reasonable.
Quoted 7 lines
msleep(100); if (dev->is_virtfn) return;Perhaps with a spec reference in a comment why we don't care about checking config space for the vf.
The spec reference is in the commit message of
"PCI: limit FLR wait time to 100ms maximum"
where I introduce this check. Do you prefer a reference in the code? I was under the impression that commit messages are used for these kind of documentation.
Quoted 23 lines
Quoted 23 lines
drivers/pci/pci.c +12
-9do { -msleep (100 ); -pci_read_config_dword (dev,PCI_COMMAND , &id); - }while (i++ <10 && 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 ); + ret =pci_bus_read_dev_vendor_id (dev->bus, dev->devfn, &id, + sleep); +if (ret) +break ; + total += sleep; + sleep *=2 ; + }while (total <60000 && !ret); + +if (!ret) +dev_warn (&dev->dev,"Failed to return from FLR after %ds\n" , + total); +else if (total)
Quoted 8 lines
drivers/pci/pci.c int pci_wait_for_pending_transaction(struct pci_dev *dev) · line 3850
Quoted 3 lines
drivers/pci/pci.c +2
-0+dev_info (&dev->dev,"Required additional %ds to return from FLR\n" , + total); }I'm not a big fan. Nested exponential backoff is pretty nasty. Are there users of
pci_bus_read_dev_vendor_id()that don't want a "still trying" message? It seems better to add that to the function than try to wrap this bandage around it. Thanks,
I can work towards that if Bjorn doesn't have any objections.
Quoted 3 lines
Alex
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.