linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status()
@ 2020-03-24 15:28 Kai-Heng Feng
  2020-03-24 15:35 ` Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Kai-Heng Feng @ 2020-03-24 15:28 UTC (permalink / raw)
  To: ajayg
  Cc: Kai-Heng Feng, Wolfram Sang, Andy Shevchenko,
	open list:I2C CONTROLLER DRIVER FOR NVIDIA GPU, open list

Nvidia card may come with a "phantom" UCSI device, and its driver gets
stuck in probe routine, prevents any system PM operations like suspend.

There's an unaccounted case that the target time can equal to jiffies in
gpu_i2c_check_status(), let's solve that by using readl_poll_timeout()
instead of jiffies comparison functions. 

Fixes: c71bcdcb42a7 ("i2c: add i2c bus driver for NVIDIA GPU")
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v3:
- Use readl_poll_timeout to make the retry loop simpler.

v2:
- Use a boolean to make sure the operation is timeout or not.

 drivers/i2c/busses/i2c-nvidia-gpu.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c
index 62e18b4db0ed..f5d25ce00f03 100644
--- a/drivers/i2c/busses/i2c-nvidia-gpu.c
+++ b/drivers/i2c/busses/i2c-nvidia-gpu.c
@@ -8,6 +8,7 @@
 #include <linux/delay.h>
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
+#include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
@@ -75,20 +76,15 @@ static void gpu_enable_i2c_bus(struct gpu_i2c_dev *i2cd)
 
 static int gpu_i2c_check_status(struct gpu_i2c_dev *i2cd)
 {
-	unsigned long target = jiffies + msecs_to_jiffies(1000);
 	u32 val;
+	int ret;
 
-	do {
-		val = readl(i2cd->regs + I2C_MST_CNTL);
-		if (!(val & I2C_MST_CNTL_CYCLE_TRIGGER))
-			break;
-		if ((val & I2C_MST_CNTL_STATUS) !=
-				I2C_MST_CNTL_STATUS_BUS_BUSY)
-			break;
-		usleep_range(500, 600);
-	} while (time_is_after_jiffies(target));
-
-	if (time_is_before_jiffies(target)) {
+	ret = readl_poll_timeout(i2cd->regs + I2C_MST_CNTL, val,
+				 !(val & I2C_MST_CNTL_CYCLE_TRIGGER) ||
+				 (val & I2C_MST_CNTL_STATUS) != I2C_MST_CNTL_STATUS_BUS_BUSY,
+				 500, 1000 * USEC_PER_MSEC);
+
+	if (ret) {
 		dev_err(i2cd->dev, "i2c timeout error %x\n", val);
 		return -ETIMEDOUT;
 	}
-- 
2.17.1


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

* Re: [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status()
  2020-03-24 15:28 [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status() Kai-Heng Feng
@ 2020-03-24 15:35 ` Andy Shevchenko
  2020-03-24 20:57 ` Wolfram Sang
  2020-03-24 21:47 ` Wolfram Sang
  2 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2020-03-24 15:35 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: ajayg, Wolfram Sang,
	open list:I2C CONTROLLER DRIVER FOR NVIDIA GPU, open list

On Tue, Mar 24, 2020 at 11:28:11PM +0800, Kai-Heng Feng wrote:
> Nvidia card may come with a "phantom" UCSI device, and its driver gets
> stuck in probe routine, prevents any system PM operations like suspend.
> 
> There's an unaccounted case that the target time can equal to jiffies in
> gpu_i2c_check_status(), let's solve that by using readl_poll_timeout()
> instead of jiffies comparison functions. 
> 

Thank you!
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


> Fixes: c71bcdcb42a7 ("i2c: add i2c bus driver for NVIDIA GPU")
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
> v3:
> - Use readl_poll_timeout to make the retry loop simpler.
> 
> v2:
> - Use a boolean to make sure the operation is timeout or not.
> 
>  drivers/i2c/busses/i2c-nvidia-gpu.c | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c
> index 62e18b4db0ed..f5d25ce00f03 100644
> --- a/drivers/i2c/busses/i2c-nvidia-gpu.c
> +++ b/drivers/i2c/busses/i2c-nvidia-gpu.c
> @@ -8,6 +8,7 @@
>  #include <linux/delay.h>
>  #include <linux/i2c.h>
>  #include <linux/interrupt.h>
> +#include <linux/iopoll.h>
>  #include <linux/module.h>
>  #include <linux/pci.h>
>  #include <linux/platform_device.h>
> @@ -75,20 +76,15 @@ static void gpu_enable_i2c_bus(struct gpu_i2c_dev *i2cd)
>  
>  static int gpu_i2c_check_status(struct gpu_i2c_dev *i2cd)
>  {
> -	unsigned long target = jiffies + msecs_to_jiffies(1000);
>  	u32 val;
> +	int ret;
>  
> -	do {
> -		val = readl(i2cd->regs + I2C_MST_CNTL);
> -		if (!(val & I2C_MST_CNTL_CYCLE_TRIGGER))
> -			break;
> -		if ((val & I2C_MST_CNTL_STATUS) !=
> -				I2C_MST_CNTL_STATUS_BUS_BUSY)
> -			break;
> -		usleep_range(500, 600);
> -	} while (time_is_after_jiffies(target));
> -
> -	if (time_is_before_jiffies(target)) {
> +	ret = readl_poll_timeout(i2cd->regs + I2C_MST_CNTL, val,
> +				 !(val & I2C_MST_CNTL_CYCLE_TRIGGER) ||
> +				 (val & I2C_MST_CNTL_STATUS) != I2C_MST_CNTL_STATUS_BUS_BUSY,
> +				 500, 1000 * USEC_PER_MSEC);
> +
> +	if (ret) {
>  		dev_err(i2cd->dev, "i2c timeout error %x\n", val);
>  		return -ETIMEDOUT;
>  	}
> -- 
> 2.17.1
> 

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status()
  2020-03-24 15:28 [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status() Kai-Heng Feng
  2020-03-24 15:35 ` Andy Shevchenko
@ 2020-03-24 20:57 ` Wolfram Sang
  2020-03-24 21:16   ` Ajay Gupta
  2020-03-24 21:47 ` Wolfram Sang
  2 siblings, 1 reply; 5+ messages in thread
From: Wolfram Sang @ 2020-03-24 20:57 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: ajayg, Andy Shevchenko,
	open list:I2C CONTROLLER DRIVER FOR NVIDIA GPU, open list

[-- Attachment #1: Type: text/plain, Size: 725 bytes --]

On Tue, Mar 24, 2020 at 11:28:11PM +0800, Kai-Heng Feng wrote:
> Nvidia card may come with a "phantom" UCSI device, and its driver gets
> stuck in probe routine, prevents any system PM operations like suspend.
> 
> There's an unaccounted case that the target time can equal to jiffies in
> gpu_i2c_check_status(), let's solve that by using readl_poll_timeout()
> instead of jiffies comparison functions. 
> 
> Fixes: c71bcdcb42a7 ("i2c: add i2c bus driver for NVIDIA GPU")
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

Looks good to me, thanks Andy for the suggestion!

Waiting for the Rev-by from Ajay (driver maintainer).


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* RE: [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status()
  2020-03-24 20:57 ` Wolfram Sang
@ 2020-03-24 21:16   ` Ajay Gupta
  0 siblings, 0 replies; 5+ messages in thread
From: Ajay Gupta @ 2020-03-24 21:16 UTC (permalink / raw)
  To: Wolfram Sang, Kai-Heng Feng
  Cc: Andy Shevchenko, open list:I2C CONTROLLER DRIVER FOR NVIDIA GPU,
	open list

Hi Wolfram,

> -----Original Message-----
> From: Wolfram Sang <wsa@the-dreams.de>
> Sent: Tuesday, March 24, 2020 1:58 PM
> To: Kai-Heng Feng <kai.heng.feng@canonical.com>
> Cc: Ajay Gupta <ajayg@nvidia.com>; Andy Shevchenko
> <andriy.shevchenko@linux.intel.com>; open list:I2C CONTROLLER DRIVER
> FOR NVIDIA GPU <linux-i2c@vger.kernel.org>; open list <linux-
> kernel@vger.kernel.org>
> Subject: Re: [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in
> gpu_i2c_check_status()
> 
> On Tue, Mar 24, 2020 at 11:28:11PM +0800, Kai-Heng Feng wrote:
> > Nvidia card may come with a "phantom" UCSI device, and its driver gets
> > stuck in probe routine, prevents any system PM operations like suspend.
> >
> > There's an unaccounted case that the target time can equal to jiffies
> > in gpu_i2c_check_status(), let's solve that by using
> > readl_poll_timeout() instead of jiffies comparison functions.
> >
> > Fixes: c71bcdcb42a7 ("i2c: add i2c bus driver for NVIDIA GPU")
> > Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> 
> Looks good to me, thanks Andy for the suggestion!
> 
> Waiting for the Rev-by from Ajay (driver maintainer).
Reviewed-by: Ajay Gupta <ajayg@nvidia.com>
Tested-by: Ajay Gupta <ajayg@nvidia.com> 

Thanks
Ajay
> nvpublic


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

* Re: [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status()
  2020-03-24 15:28 [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status() Kai-Heng Feng
  2020-03-24 15:35 ` Andy Shevchenko
  2020-03-24 20:57 ` Wolfram Sang
@ 2020-03-24 21:47 ` Wolfram Sang
  2 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2020-03-24 21:47 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: ajayg, Andy Shevchenko,
	open list:I2C CONTROLLER DRIVER FOR NVIDIA GPU, open list

[-- Attachment #1: Type: text/plain, Size: 650 bytes --]

On Tue, Mar 24, 2020 at 11:28:11PM +0800, Kai-Heng Feng wrote:
> Nvidia card may come with a "phantom" UCSI device, and its driver gets
> stuck in probe routine, prevents any system PM operations like suspend.
> 
> There's an unaccounted case that the target time can equal to jiffies in
> gpu_i2c_check_status(), let's solve that by using readl_poll_timeout()
> instead of jiffies comparison functions. 
> 
> Fixes: c71bcdcb42a7 ("i2c: add i2c bus driver for NVIDIA GPU")
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

Applied to for-current, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2020-03-24 21:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-24 15:28 [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status() Kai-Heng Feng
2020-03-24 15:35 ` Andy Shevchenko
2020-03-24 20:57 ` Wolfram Sang
2020-03-24 21:16   ` Ajay Gupta
2020-03-24 21:47 ` Wolfram Sang

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