Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6686315imm; Tue, 24 Jul 2018 00:58:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeDUj2jZUiBgtkpYr9+yFL4bbk1jL09LtoDNfI/FqsABMSyMjLGhMwtd1RZQGYbMtgeFXjc X-Received: by 2002:a63:314f:: with SMTP id x76-v6mr14992133pgx.373.1532419115194; Tue, 24 Jul 2018 00:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532419115; cv=none; d=google.com; s=arc-20160816; b=Hi6o+tmdUCFmvHFVLQXeYkHlV8N+NT24qPc36gij/ViZv7jxC7NAR9vbOvizJJ68Ai XfIh991UubRjUKN0y9evsN9BCx0EnG/8DUFM03SByokM1YhMAkIgS6Ckv2J8dVpv3Bpw RZUcjBMfz0G2PC8c33S8IZADC9U1puQ1bozUlmhqDB6/MXgQpFJkEbmoGUSTGvsz1N5z QkybG3sHbrJUwVzwlqpUrP7/EpnFGpbvMabKbLl/5XpB4KtJX9wTC2HTVmQTcDt/4K75 iErck4z3ToTqS4uCkRgSqyGD+M+pqisQYlL485nRKbqQ6acXWjIvKeElvdQ4HwPDovE/ 3VIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=NtzoBGZ/DN3b0ADsITImH58pQB0m26D8+JH6knMeEYA=; b=0DmnrZkM7V2uoFR5sTghnmCJoi8Fp+AMSdmwYQ1DrOA7Zk0mCJE24lLb35H/fbVS0L vwHEPzBU4J0C9jU2UreGX9angy32YWErMzNoV19NTBgb9EkQMyUXsvJvIGeJrOrL5721 ewQV3sIpOUG1Ws6Qev9KFkUkTCek2PyEdyNrVYpQMQd87IQgdB1e7UiwGdYW8qWNXwEK SJjw9fEtqfejadagCWddsxNUj0+gHM6WlTqofjl1QT0kw9/ajb8mUZnzTBUpJOok4oW6 djPDFTF1TL1TRXEqhswHZ90DxL5BoNvnxfhpbVoM1OK8p82Eh7FHvgj8lxAF3uY8YDni xjCg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z18-v6si10840826pfl.209.2018.07.24.00.58.20; Tue, 24 Jul 2018 00:58:35 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388532AbeGXJCh (ORCPT + 99 others); Tue, 24 Jul 2018 05:02:37 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:46371 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388401AbeGXJCh (ORCPT ); Tue, 24 Jul 2018 05:02:37 -0400 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fhsBz-00085Z-S2; Tue, 24 Jul 2018 09:57:11 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1fhsBv-0003bb-4j; Tue, 24 Jul 2018 09:57:07 +0200 Date: Tue, 24 Jul 2018 09:57:07 +0200 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Esben Haabendal Cc: linux-i2c@vger.kernel.org, Wolfram Sang , Rob Herring , Mark Rutland , Yuan Yao , Esben Haabendal , Fabio Estevam , Lucas Stach , Phil Reid , Clemens Gruber , Peter Rosin , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/4] i2c: imx: Fix race condition in dma read Message-ID: <20180724075707.7wrqltjj54gjrl4y@pengutronix.de> References: <20180709094304.8814-1-esben.haabendal@gmail.com> <20180709094304.8814-3-esben.haabendal@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180709094304.8814-3-esben.haabendal@gmail.com> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 09, 2018 at 11:43:02AM +0200, Esben Haabendal wrote: > From: Esben Haabendal > > This fixes a race condition, where the DMAEN bit ends up being set after > I2C slave has transmitted a byte following the dummy read. When that > happens, an interrupt is generated instead, and no DMA request is generated > to kickstart the DMA read, and a timeout happens after DMA_TIMEOUT (1 sec). > > Fixed by setting the DMAEN bit before the dummy read. > > Signed-off-by: Esben Haabendal > --- > drivers/i2c/busses/i2c-imx.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c > index 39cfd98c7b23..d86f152176a4 100644 > --- a/drivers/i2c/busses/i2c-imx.c > +++ b/drivers/i2c/busses/i2c-imx.c > @@ -668,9 +668,6 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx, > struct imx_i2c_dma *dma = i2c_imx->dma; > struct device *dev = &i2c_imx->adapter.dev; > > - temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); > - temp |= I2CR_DMAEN; > - imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); > > dma->chan_using = dma->chan_rx; > dma->dma_transfer_dir = DMA_DEV_TO_MEM; > @@ -810,6 +807,11 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bo > if ((msgs->len - 1) || block_data) > temp &= ~I2CR_TXAK; > imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); > + if (i2c_imx->dma && msgs->len >= DMA_THRESHOLD && !block_data) { > + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); > + temp |= I2CR_DMAEN; > + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); > + } Does this need to be a separate write to the I2CR register? Just before the if there is temp written to this register, so probably this can be changed to just: if (i2c_imx->dma && msgs->len >= DMA_THRESHOLD && !block_data) temp |= I2CR_DMAEN; when moved before up one line. I don't find documentation for the LS processors where this register is described though (and the imx family doesn't seem to support DMA for i2c). Other than that this looks reasonable and warrants a Fixes: ce1a78840ff7 ("i2c: imx: add DMA support for freescale i2c driver") . Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |