From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AAC1C43461 for ; Thu, 17 Sep 2020 19:55:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0DFD235F8 for ; Thu, 17 Sep 2020 19:55:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="irr5qCIj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726694AbgIQTz2 (ORCPT ); Thu, 17 Sep 2020 15:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727777AbgIQO5q (ORCPT ); Thu, 17 Sep 2020 10:57:46 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63799C06174A; Thu, 17 Sep 2020 07:57:19 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id c2so2286388ljj.12; Thu, 17 Sep 2020 07:57:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=n0joxHTLl3BqxQ6ij0VXBgOyNi8Eer/XXbvWMRdVNFY=; b=irr5qCIjdOYv20J8iTCaTRA5UJ8jnzNtuQ9wBAKUkBkUwYZvSpC/yLVt7ThRgwXQ3B sAUAzvzQiKgn6uepWWSuEPmVz6AgknRFD868eBfrgomBpnC125FhY/EeTGUpTSm4EjC9 y90PFg52OzZ5LKvpAMAB/vVIvpPXfMTxkIIDssejlrp/YCzJN5iEAdDOK9wprJcz/blX XYdmup+XrgixfQUOA4hklmzYVqN/FszMsZ8QEph+f65iaugTJXhxnuorpw7OqYYL9Vk7 t8goGMla2PD6wfNBb1hJInCz+6Al0znr5ED4bTqS3Fq69eQDa2TN4Ys8SrknAT+w41tV 7nvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=n0joxHTLl3BqxQ6ij0VXBgOyNi8Eer/XXbvWMRdVNFY=; b=PSo1alyDuynrGPcrAxt+CcAStZ+K+d5aQcjbOrPtmTymCzHfcwmOJa2dm6w1ORnXEa 17O15R/GlKK749BNEwak3wA0a40kng2HuLEhWy6/Skr0k4GTjq9zQ7nqipNXv4h9voaA mJYIbisHQPOGhTn+IpMCpbqslUEC2aP4lqpJf7SKg1s0l80WvsFVcSuBlngIurb5O9XF zyeBHik9dxugun6M2xqF4RIMxW/lpEM5WlPSbgwW7dJGt3T4CSaDwAA5XDEIwpJPwat0 8k9p/i7/KGX5qLnvhVbH1qrm20Rr4WeBPloqk234oFpEGKqzL+F3/C2Q/j/RBrT3dXS3 taNQ== X-Gm-Message-State: AOAM533eQ4e9Sw2gtNdrRpU+vVmlcnCSgJeG0fTzbbywEF0TQv3qCWa3 QK+8QEPuqOlZB0InRG0MSUZYQoc7r3g= X-Google-Smtp-Source: ABdhPJxDy3ZIF2c4BkIXP4LkxiCyIhhPar673IiuvvC9LBQ6MF45yrzV0/L+xC0E2Z0ABrAbjVzUPQ== X-Received: by 2002:a2e:810a:: with SMTP id d10mr10798579ljg.302.1600354637605; Thu, 17 Sep 2020 07:57:17 -0700 (PDT) Received: from [192.168.2.145] (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.googlemail.com with ESMTPSA id 140sm5274211lfj.146.2020.09.17.07.57.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Sep 2020 07:57:16 -0700 (PDT) Subject: Re: [PATCH v7 01/34] i2c: tegra: Make tegra_i2c_flush_fifos() usable in atomic transfer To: Thierry Reding Cc: Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko , linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200908224006.25636-1-digetx@gmail.com> <20200908224006.25636-2-digetx@gmail.com> <20200917111057.GM3515672@ulmo> From: Dmitry Osipenko Message-ID: <9beab533-8734-f18b-887d-d0e8cc09bb72@gmail.com> Date: Thu, 17 Sep 2020 17:57:15 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200917111057.GM3515672@ulmo> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 17.09.2020 14:10, Thierry Reding пишет: > On Wed, Sep 09, 2020 at 01:39:33AM +0300, Dmitry Osipenko wrote: >> The tegra_i2c_flush_fifos() shouldn't sleep in atomic transfer and jiffies >> are not updating if interrupts are disabled. Let's switch to use iopoll >> API helpers for register-polling. The iopoll API provides helpers for both >> atomic and non-atomic cases. >> >> Note that this patch doesn't fix any known problem because normally FIFO >> is flushed at the time of starting a new transfer. >> >> Reviewed-by: Michał Mirosław >> Signed-off-by: Dmitry Osipenko >> --- >> drivers/i2c/busses/i2c-tegra.c | 25 ++++++++++++++++--------- >> 1 file changed, 16 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c >> index 00d3e4d7a01e..ab88cdd70376 100644 >> --- a/drivers/i2c/busses/i2c-tegra.c >> +++ b/drivers/i2c/busses/i2c-tegra.c >> @@ -470,9 +470,9 @@ static int tegra_i2c_init_dma(struct tegra_i2c_dev *i2c_dev) >> >> static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) >> { >> - unsigned long timeout = jiffies + HZ; >> - unsigned int offset; >> - u32 mask, val; >> + u32 mask, val, offset, reg_offset; > > Is there are reason why we need reg_offset? Seems to me like we could > simplify this, see below. The reason is that this patch addresses potential problem, hence it's not a cleanup change and it should be kept minimal. >> + void __iomem *addr; >> + int err; >> >> if (i2c_dev->hw->has_mst_fifo) { >> mask = I2C_MST_FIFO_CONTROL_TX_FLUSH | >> @@ -488,12 +488,19 @@ static int tegra_i2c_flush_fifos(struct tegra_i2c_dev *i2c_dev) >> val |= mask; >> i2c_writel(i2c_dev, val, offset); >> >> - while (i2c_readl(i2c_dev, offset) & mask) { >> - if (time_after(jiffies, timeout)) { >> - dev_warn(i2c_dev->dev, "timeout waiting for fifo flush\n"); >> - return -ETIMEDOUT; >> - } >> - usleep_range(1000, 2000); >> + reg_offset = tegra_i2c_reg_addr(i2c_dev, offset); >> + addr = i2c_dev->base + reg_offset; > > Why not just: > > offset = tegra_i2c_reg_offset(i2c_dev, offset); > addr = i2c_dev->base + offset; > > or even just: > > addr = i2c_dev->base + tegra_i2c_reg_offset(i2c_dev, offset); > > ? That makes the patch much smaller because you don't have to rewrite > the whole variable declaration block and just add the "addr" and "err" > variables while removing "timeout". There is a further "cleanup" patch named "Factor out register polling into separate function" that already implements yours suggestion.