linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V5 1/2] PCI: limit FLR wait time to 100ms maximum
@ 2017-08-02  3:44 Sinan Kaya
  2017-08-02  3:44 ` [PATCH V5 2/2] PCI: handle CRS returned by device after FLR Sinan Kaya
  0 siblings, 1 reply; 4+ messages in thread
From: Sinan Kaya @ 2017-08-02  3:44 UTC (permalink / raw)
  To: linux-pci, timur, alex.williamson
  Cc: linux-arm-msm, linux-arm-kernel, Sinan Kaya, linux-kernel

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.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
---
 drivers/pci/pci.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index af0cc34..2ed604a 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -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);
-- 
1.9.1

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

* [PATCH V5 2/2] PCI: handle CRS returned by device after FLR
  2017-08-02  3:44 [PATCH V5 1/2] PCI: limit FLR wait time to 100ms maximum Sinan Kaya
@ 2017-08-02  3:44 ` Sinan Kaya
  2017-08-02  4:44   ` Alex Williamson
  0 siblings, 1 reply; 4+ messages in thread
From: Sinan Kaya @ 2017-08-02  3:44 UTC (permalink / raw)
  To: linux-pci, timur, alex.williamson
  Cc: linux-arm-msm, linux-arm-kernel, Sinan Kaya, linux-kernel

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 <okaya@codeaurora.org>
---
 drivers/pci/pci.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 2ed604a..25c7a83 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3813,14 +3813,16 @@ 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 1s 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 id;
+	bool ret;
 
 	if (dev->is_virtfn) {
 		msleep(100);
@@ -3828,15 +3830,15 @@ static void pci_flr_wait(struct pci_dev *dev)
 	}
 
 	do {
-		msleep(100);
-		pci_read_config_dword(dev, PCI_COMMAND, &id);
-	} while (i++ < 10 && id == ~0);
+		ret = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &id,
+						 1000);
+	} while (i++ < 60 && !ret);
 
-	if (id == ~0)
+	if (!ret)
 		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);
+		dev_info(&dev->dev, "Required additional %ds to return from FLR\n",
+			 (i - 1));
 }
 
 /**
-- 
1.9.1

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

* Re: [PATCH V5 2/2] PCI: handle CRS returned by device after FLR
  2017-08-02  3:44 ` [PATCH V5 2/2] PCI: handle CRS returned by device after FLR Sinan Kaya
@ 2017-08-02  4:44   ` Alex Williamson
  2017-08-02 15:42     ` Sinan Kaya
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Williamson @ 2017-08-02  4:44 UTC (permalink / raw)
  To: Sinan Kaya
  Cc: linux-pci, timur, linux-arm-msm, linux-arm-kernel, linux-kernel

On Tue,  1 Aug 2017 23:44:13 -0400
Sinan Kaya <okaya@codeaurora.org> 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 <okaya@codeaurora.org>
> ---
>  drivers/pci/pci.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 2ed604a..25c7a83 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -3813,14 +3813,16 @@ 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 1s when an LCD panel is attached.  We use
> + * pci_bus_read_dev_vendor_id() for reading the vendor ID as it handles
> + * CRS gracefully.

nit, stating that IGD requires 1s with an LCD panel is a
misinterpretation of the previous comment.  In fact the original commit
only mentions 300ms.  I think perhaps 1s was simply a nice round
interval.

>   */
>  static void pci_flr_wait(struct pci_dev *dev)
>  {
>  	int i = 0;
>  	u32 id;
> +	bool ret;
>  
>  	if (dev->is_virtfn) {
>  		msleep(100);
> @@ -3828,15 +3830,15 @@ static void pci_flr_wait(struct pci_dev *dev)
>  	}
>  
>  	do {
> -		msleep(100);
> -		pci_read_config_dword(dev, PCI_COMMAND, &id);
> -	} while (i++ < 10 && id == ~0);
> +		ret = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &id,
> +						 1000);

Is it a problem that there's now zero delay between the FLR and first
attempt to read config space?  Seems like there should be a 100ms
delay before we start trying.  This is also going to print a kernel
warning 60 times in the course of getting to a 60s timeout, why not let
pci_bus_read_dev_vendor_id() manage the entire timeout?  Are we only
trying to preserve the dev_info() below?  Thanks,

Alex

> +	} while (i++ < 60 && !ret);
>  
> -	if (id == ~0)
> +	if (!ret)
>  		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);
> +		dev_info(&dev->dev, "Required additional %ds to
> return from FLR\n",
> +			 (i - 1));
>  }
>  
>  /**

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

* Re: [PATCH V5 2/2] PCI: handle CRS returned by device after FLR
  2017-08-02  4:44   ` Alex Williamson
@ 2017-08-02 15:42     ` Sinan Kaya
  0 siblings, 0 replies; 4+ messages in thread
From: Sinan Kaya @ 2017-08-02 15:42 UTC (permalink / raw)
  To: Alex Williamson
  Cc: linux-pci, timur, linux-arm-msm, linux-arm-kernel, linux-kernel

Hi Alex,

On 8/2/2017 12:44 AM, Alex Williamson wrote:
> On Tue,  1 Aug 2017 23:44:13 -0400
> Sinan Kaya <okaya@codeaurora.org> wrote:
> 
>> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
>> index 2ed604a..25c7a83 100644
>> --- a/drivers/pci/pci.c
>> +++ b/drivers/pci/pci.c
>> @@ -3813,14 +3813,16 @@ 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 1s when an LCD panel is attached.  We use
>> + * pci_bus_read_dev_vendor_id() for reading the vendor ID as it handles
>> + * CRS gracefully.
> 
> nit, stating that IGD requires 1s with an LCD panel is a
> misinterpretation of the previous comment.  In fact the original commit
> only mentions 300ms.  I think perhaps 1s was simply a nice round
> interval.

I can fix the comment as 300ms to be correct. 

> 
>>   */
>>  static void pci_flr_wait(struct pci_dev *dev)
>>  {
>>  	int i = 0;
>>  	u32 id;
>> +	bool ret;
>>  
>>  	if (dev->is_virtfn) {
>>  		msleep(100);
>> @@ -3828,15 +3830,15 @@ static void pci_flr_wait(struct pci_dev *dev)
>>  	}
>>  
>>  	do {
>> -		msleep(100);
>> -		pci_read_config_dword(dev, PCI_COMMAND, &id);
>> -	} while (i++ < 10 && id == ~0);
>> +		ret = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &id,
>> +						 1000);
> 
> Is it a problem that there's now zero delay between the FLR and first
> attempt to read config space?  

I agree, we should wait 100ms before attempting to do anything.

> Seems like there should be a 100ms
> delay before we start trying.  This is also going to print a kernel
> warning 60 times in the course of getting to a 60s timeout, why not let
> pci_bus_read_dev_vendor_id() manage the entire timeout?  

Bjorn was concerned that if a device is taking too long to come out of reset, 
there won't be any visible output on the screen and somebody might be under the
impression that system is frozen even though we are just busy waiting. 

That's why, I tried to introduce some verbosity.

What I can do is instead of polling 60 times, I can follow a similar pattern
in vendor_id() function and sleep 1 second first, followed by 2 seconds, followed
by 4 seconds etc. to be less verbose. 

User will still see a warning on each read loop that failed. At least, we won't 
fill the screen with warning messages.

> Are we only
> trying to preserve the dev_info() below?  Thanks,

Yes and no, we want to see the progress of polling and a final result. 60 seconds
is a very long time.

> 
> Alex
> 
>> +	} while (i++ < 60 && !ret);
>>  
>> -	if (id == ~0)
>> +	if (!ret)
>>  		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);
>> +		dev_info(&dev->dev, "Required additional %ds to
>> return from FLR\n",
>> +			 (i - 1));
>>  }
>>  
>>  /**
> 
> 


-- 
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.

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

end of thread, other threads:[~2017-08-02 15:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-02  3:44 [PATCH V5 1/2] PCI: limit FLR wait time to 100ms maximum Sinan Kaya
2017-08-02  3:44 ` [PATCH V5 2/2] PCI: handle CRS returned by device after FLR Sinan Kaya
2017-08-02  4:44   ` Alex Williamson
2017-08-02 15:42     ` 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).