From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Shevchenko Subject: Re: [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status() Date: Tue, 24 Mar 2020 17:35:18 +0200 Message-ID: <20200324153518.GP1922688@smile.fi.intel.com> References: <20200324152812.20231-1-kai.heng.feng@canonical.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mga04.intel.com ([192.55.52.120]:20383 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727216AbgCXPfU (ORCPT ); Tue, 24 Mar 2020 11:35:20 -0400 Content-Disposition: inline In-Reply-To: <20200324152812.20231-1-kai.heng.feng@canonical.com> Sender: linux-i2c-owner@vger.kernel.org List-Id: linux-i2c@vger.kernel.org To: Kai-Heng Feng Cc: ajayg@nvidia.com, 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 > Fixes: c71bcdcb42a7 ("i2c: add i2c bus driver for NVIDIA GPU") > Suggested-by: Andy Shevchenko > Signed-off-by: Kai-Heng Feng > --- > 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 > #include > #include > +#include > #include > #include > #include > @@ -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