Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3287560ybb; Tue, 31 Mar 2020 02:08:56 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvM8s/Tfol+pXFygnYH+RQL93m7OOXTqBdk42c5Zbtvxxfn015YcjI7PH/sM64M1wzfWWqs X-Received: by 2002:aca:b382:: with SMTP id c124mr1323476oif.64.1585645735742; Tue, 31 Mar 2020 02:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585645735; cv=none; d=google.com; s=arc-20160816; b=dkK3rMqleyt28tlhtUuHFIxgQA+LXz+gN/+/PG4CYOGuZ7JIgfD7Uuhqdcu5z+fLfQ mPwkwDHVdVeugQph4DRYBuXAtxtk/fqcKK7loNFBcI0umikz39ddTuj6rmMlKIsIPgXh VB/UwSxUUDZU9hNutwwTCWZ8ZtdDKfpNZH/6I0pC794mq5eXNxzAIUTX1zse+b1L31aa D4ggGG2WqD3uy49Dy8igx6UGSZr9ziu30SMkeP5i9VR5HEHI1ITsfKD2jdOx+KX1wqJs Sd3woZKhVqGYFsQko1EZszSYN31xA9lQkg5elST5aUpuwoGpWJArIFHffhidH0H1QbxB HZTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mpEQsJJAofWA7g98N3YeiZJTxqr2JsYBt4VBcV95S4U=; b=YzKYA/fpQc9Qkpa5lP3byM0MHyTXzEFStkTPc3yIDiC/Lm4K8Rbn2IOFVR5gRLC9zf UtqiD/oPJYR8W517DCkVYJEC445fDL/DyKh+3EbZIULaGUztuCKSO9a91cU+o++R/MOC s14f0RCx5dc/etxcGu7viOMCW9UVdCGigkubHey76HX5Ywmapx0STaz1DZoknwZiCb+u 7uphi2LsAXGlSKshX3C7ohWqIK3+B/dbtO7OKMcfxMvMDb9lSiRbLyCk0XCeK6rgqbkG O9sLhLJHZwzDz/bTYQ0XsXU97ijWbmlbTe2ZGYf2xJ0cm7e8Sq/NciT+RJAGZ+/m126b 18ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JHNUeYyr; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t2si6624575oih.136.2020.03.31.02.08.43; Tue, 31 Mar 2020 02:08:55 -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; dkim=pass header.i=@kernel.org header.s=default header.b=JHNUeYyr; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731354AbgCaJI3 (ORCPT + 99 others); Tue, 31 Mar 2020 05:08:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:50930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730679AbgCaJI2 (ORCPT ); Tue, 31 Mar 2020 05:08:28 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1B3212072E; Tue, 31 Mar 2020 09:08:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585645707; bh=bZoCsEb7wD0uIXnpD9U+XVKOmILOUBspGxL7skoOLsU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JHNUeYyry4anYjjtyfOclsYFn14yBgEY1IQ3I6YKYpGuG6vEdf2yFaLAdOZfaxbDj LMNo/nK6E5aiZzVTYyJjt/6sqWfVcK4k0ozELmPvV+INBDooBHfj3aFvSNvsq9mJPj U1uwNQlZGB3L98me39Wfp2dd8b5Ih3tjtLcNAeb8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Shevchenko , Kai-Heng Feng , Ajay Gupta , Wolfram Sang Subject: [PATCH 5.5 139/170] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status() Date: Tue, 31 Mar 2020 10:59:13 +0200 Message-Id: <20200331085438.227950831@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200331085423.990189598@linuxfoundation.org> References: <20200331085423.990189598@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kai-Heng Feng commit d944b27df121e2ee854a6c2fad13d6c6300792d4 upstream. 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 Signed-off-by: Kai-Heng Feng Reviewed-by: Andy Shevchenko Reviewed-by: Ajay Gupta Tested-by: Ajay Gupta Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/busses/i2c-nvidia-gpu.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) --- 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 gp 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)); + 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 (time_is_before_jiffies(target)) { + if (ret) { dev_err(i2cd->dev, "i2c timeout error %x\n", val); return -ETIMEDOUT; }