Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4971431ybb; Tue, 24 Mar 2020 08:36:14 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtKYae8TPGa+TRECVAv1Tn+8tWLHqVECiJi1BYc7/WdJv2PwtAqcak1MXwHmnDjWLmiqd0D X-Received: by 2002:a05:6830:146:: with SMTP id j6mr22341114otp.117.1585064174757; Tue, 24 Mar 2020 08:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585064174; cv=none; d=google.com; s=arc-20160816; b=NTvpBMe4m8cvUwthEnDifZaL4jzhhzF2UPePCh+DtQYeCBi47zBSfwF7bP+2jxXgen lCzSmenfgRYcYzcf3MQT/wIy7KgygB9naclBzMEEQ6shqrv3rBBQGgJ+SI4ArBWjgNiz AzQHfgQQ3u//yerVy8TJu5evNOvJ3KXNrsWykb8LQiP57DuCtHIIp7YdBiUFo4qygZBw VgVfry8vu+7vRa4pCz6du/OJlwmR/XJzRCib9CNfOKdm7iDUB27Dli6mFS2PipVQtfNW 1eHYq5QYEwLh3BsqQ9ZEpjzKryrZ1qiLDOCaTDBJj01cSJIgxHa+0H91fePWYOIT+y/V EdEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=7SefhooHBeqrax5c775SDC8LBVoWflSlXii4phy7WNw=; b=frB3R/WsvSSNoi2I6hbA74qF8AEID8MFu8XwEkm8Xe/nd2p3I8WYoV1n0FSd+kpBFy OHIDB/iAJ30L2n1i/EvtKKHowb1HazoxO2XDJIfQqiLMS+WfgLQTBAgVK3x1yjqpPkoc U73y8hXZ8hzkxfVpRDnDdi7TXg7BzBqoSQYRyJISj4UlbS2wo3WO7h0dpzVqTeNQtrH4 lWj7+G9CA0Qm7F/iVolQu+d0a0hxqsy9Ni3zxLRq8hj+XxWiPKHqHMJ7sSj0r3GbQXob nObqX2LMA/9G5GxJ5NVn/KGvKd4e04KvBh+sb0l3KkndYuJwMp7JuomCufEZNz7rFzpt UkOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t7si5272575otd.115.2020.03.24.08.36.00; Tue, 24 Mar 2020 08:36:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728001AbgCXPfU (ORCPT + 99 others); Tue, 24 Mar 2020 11:35:20 -0400 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 IronPort-SDR: LgWswiGKgRZcEtQCpX5S3ORFudk+2Zo0lp6rRUAYot75geEy27RdMTAuyYsvdHp0Hn1BWk/mLa x5MxbtF0ZSqQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2020 08:35:20 -0700 IronPort-SDR: DjgDT7YuDwbDWYF1HGq2qCo2JezbGlElTudi5lGD2km4UWW+ArvxX+SXNRQf/xcxzNHEj84W24 iUl24loeegPA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,300,1580803200"; d="scan'208";a="235616865" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga007.jf.intel.com with ESMTP; 24 Mar 2020 08:35:16 -0700 Received: from andy by smile with local (Exim 4.93) (envelope-from ) id 1jGlaI-00CZJi-U8; Tue, 24 Mar 2020 17:35:18 +0200 Date: Tue, 24 Mar 2020 17:35:18 +0200 From: Andy Shevchenko To: Kai-Heng Feng Cc: ajayg@nvidia.com, Wolfram Sang , "open list:I2C CONTROLLER DRIVER FOR NVIDIA GPU" , open list Subject: Re: [PATCH v3] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status() 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 Content-Disposition: inline In-Reply-To: <20200324152812.20231-1-kai.heng.feng@canonical.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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