Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp338411imm; Mon, 9 Jul 2018 02:44:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeKqTmocsilAeUYcCsndQ2N64ZY/DEn3QIlQu/xoU4okFosSrqQHvYzcSzLcE2bkX+gjC89 X-Received: by 2002:a62:d10b:: with SMTP id z11-v6mr20614161pfg.255.1531129465997; Mon, 09 Jul 2018 02:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531129465; cv=none; d=google.com; s=arc-20160816; b=JygvGpv/AtjTCGktKBMa95CILPnW2E9CPeP7f601sD6joV6wW1cQ7jhM4D5i9E/B/9 qGstwYQlawHAYZXB6vkWSJde2pFpBhTx8cqtoyHy4uQDYhHlvWVUZZK6b9uttHuXk86v AcFAP9OMT6UZIxyGMDc9FYrd3j3+fV2lrjFSfTklzdDTboSrsf7uxakH3HixIsifwpjF L2jw0PTKEa03nDyO/yIjH8FxgSeXSwm4zpJHN0clMGXTVRQX9EAS/+9iarWb+VYNcXpM JffNB52KT04Od29V0FqVAf0WtXKPzdFJQM5lsBpTfAZ7m3BQN327IPfhMN0RCORNytLJ NE3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=KoC99XQjYMvYaeFlk1wVGqBun0Bm6WwvjfwbDmoYkF8=; b=fhd0mz13hK73aZ0mOpmPK3C1bW+Nktv7iaL7mGJyaNmlQUAXZMGz9rzXYHARt4eKAx fQqneo1yObPr3qotUTbh5Y4UYj3tTPBU7LzIialFubE2SQ5Zq37v3QMGQrjj2d/nYPWH nuQ8nuEAkgHfKto8SZXJdsW/kT2Ep5ji71rPw0GI2+dyIYFyORpCeX7zirVOx/rt6+Tl +335WnbftcnUTzumtWd7pJ/mynQydF+ZztP+qvZKZAvQIY75sLiV8uYbfpUPiCLSLgcD l9cllY9DjoyRobn46rsunG8bR7TWIAoeZPdRL63eabvhUhW30yHWaE094e//QiOGVDGW q79g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=abi80z4z; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l3-v6si13631564pld.223.2018.07.09.02.44.11; Mon, 09 Jul 2018 02:44:25 -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=fail header.i=@gmail.com header.s=20161025 header.b=abi80z4z; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932805AbeGIJnW (ORCPT + 99 others); Mon, 9 Jul 2018 05:43:22 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:43943 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754405AbeGIJnP (ORCPT ); Mon, 9 Jul 2018 05:43:15 -0400 Received: by mail-lj1-f195.google.com with SMTP id r13-v6so13587398ljg.10; Mon, 09 Jul 2018 02:43:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=KoC99XQjYMvYaeFlk1wVGqBun0Bm6WwvjfwbDmoYkF8=; b=abi80z4zuLEZR1FqD25bFzz3m29Z5cWuqrq12SSooGE/+l7sGFR6wuDV4q/l+2/uiI EIOwcu/Su7eOUVSDgpaN9KMJwccelmvx5Os43KG69viR4Fq+V3olFOnV/gwOk3cMfE9B Rc4B2JQYHZvALYRE9wn6wjOvJjWKV3/4DGe02TvSyWygHUggKTfaaQ30NZV7RfSp0EDq WAlXOzYjcCQgv3woJj18s4nSRdjfrV+37n/s/U3q7n1eu7AqexmoyZJ+VGitrehPb6Vb ruuvessCfXpJKjCt3tpyb4hWO3AnqWzKErtLOlHzfHajBjQPXFGtQhA7j2fcRY8J/gq4 4mfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=KoC99XQjYMvYaeFlk1wVGqBun0Bm6WwvjfwbDmoYkF8=; b=AxXEYKyC2KPXlzrtwfTU1MZVB+wDufCgS+3eAQGpXWVzLfCv9Lw98+N8Q3HaBONaap g5UsEdIFSrEp3fjD5b+a5FqUNL/tw6oAGrN+m6Lxzg0XpaE5giPQLRC09m+CBrhbXieF btsRiTNLPO2IurUpwetyaLinkLB4DG19wDdCQ8IWKrtVszxVZagCNnh8tVf9peOav3f6 abvhwMC7PBiOgK/X4/yVmhi45gbfverNE1asszYlSLPGFTFoD5G+vUUsdW0RRBclyRpq 6n6sUAcN8JN99N4B22vCsjDbAqyReIiAb3iLyV2jqJvPtL0olfPxsil+4zvJZebzHQZD CqHw== X-Gm-Message-State: APt69E1dQzBH34fFePqx0GageaHvlKVvNV54s3s9Hwj8I2WJbuKky3jV JuZFjIxDG79ZJcAW2xVooGcqwoSfYJk= X-Received: by 2002:a2e:40c6:: with SMTP id r67-v6mr12632960lje.41.1531129393815; Mon, 09 Jul 2018 02:43:13 -0700 (PDT) Received: from localhost (87-57-30-174-static.dk.customer.tdc.net. [87.57.30.174]) by smtp.gmail.com with ESMTPSA id v20-v6sm1496115ljc.94.2018.07.09.02.43.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Jul 2018 02:43:13 -0700 (PDT) From: Esben Haabendal To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Rob Herring , Mark Rutland , Yuan Yao , Esben Haabendal , Fabio Estevam , Lucas Stach , Phil Reid , Clemens Gruber , Peter Rosin , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] i2c: imx: Fix race condition in dma read Date: Mon, 9 Jul 2018 11:43:02 +0200 Message-Id: <20180709094304.8814-3-esben.haabendal@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180709094304.8814-1-esben.haabendal@gmail.com> References: <20180709094304.8814-1-esben.haabendal@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); + } imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); /* dummy read */ dev_dbg(&i2c_imx->adapter.dev, "<%s> read data\n", __func__); -- 2.18.0