Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2429199imm; Thu, 16 Aug 2018 09:28:19 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxPFjhPp0bHYNrWJwTe+Aw26PegiYvZWmwamAOxkLcDALsO+S1XndjCGJ7C3GwdF7PnUjDR X-Received: by 2002:a63:67c3:: with SMTP id b186-v6mr29994737pgc.5.1534436899924; Thu, 16 Aug 2018 09:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534436899; cv=none; d=google.com; s=arc-20160816; b=cW4+fRGfp0kIYIaidsHNcMRDOXE1t+YqBhWSfdzMp5jjUl+2U9uPoVzksnoz4yhX2C 68uqIPqmgGJh5xcfXX6jAtljloZ5J/uYemmylcgFt74pWcyCSw7waKSHPi87VxL82F8e ImrV9RX0R7tMQKRGS+sGnSl9LLfb+XmpILR30BlGJ61YAPzQpd0G2zuXKRt/agfK+wIA wvmG9G3SRkQe2eHdlGFwyJYXKsIvdiG7lVdbLnjK6rGXyINt7rHguSqDt9/eGug0K4v7 FFVfDi+lF9S2vaYhKwbKto7L3jP6KIUtQk/6oo1UGsfC+WiTagda4AjZAzJgr8R31ewO eQow== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=eULjIfRmfvgXeIC3+Ipz8mXH88k4V94uDRkFqE1MVvw=; b=kWJJRTHdLHgLIn1fKua3Gshg2+qdcvxujDuKD807dtO1pBrklg2ZFwwWgeBO3I1ygH Pr7uP7qD9indbEgGVE9flvnd3Z+GuVBDSm04jYNVGfDB1gJCQs4ESIpp1awS2G9bT8O5 0IiDOAUfimRzydu1dUc8CtfpqTioeP0Npgah6KE1TTGjRRCNIz5cNkNqyPYoDGddJI8P kOc6PFL+N1wvjvTd73Om8IWTWQlJV4xzVIevNmsy40pYzhQHEilhJf7n7vb3+c4d+urf uw8NnAS/vtMzH7LqXmO5CwSq10l/P6cH8fbOFdoVitBjOqgAebhjNMDwmNXdoihHp1+v HXew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=rJEcDQMi; 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 x81-v6si2690665pgx.156.2018.08.16.09.27.55; Thu, 16 Aug 2018 09:28:19 -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=rJEcDQMi; 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 S2390102AbeHPLkY (ORCPT + 99 others); Thu, 16 Aug 2018 07:40:24 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:34814 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731216AbeHPLkY (ORCPT ); Thu, 16 Aug 2018 07:40:24 -0400 Received: by mail-lj1-f194.google.com with SMTP id f8-v6so3038422ljk.1; Thu, 16 Aug 2018 01:43:24 -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 :mime-version:content-transfer-encoding; bh=eULjIfRmfvgXeIC3+Ipz8mXH88k4V94uDRkFqE1MVvw=; b=rJEcDQMi3nbawq53SJ2NlW4hcqJiYYIZAFFALlPF19q0DLZRORDUtTJiPKjEg6QJuR 70Lq6tiqxeC26Ovmqo2HCdR8dPW3ZXbWxpNv4KJS7dJm/BU1DQSQincbjWdwMDrWX+BH IDXo3xRH8JmhYohU8d9yIJDJIIoTSs/SrtV5um+ZsNLeQJ611mTV1wpj4WXPpZUqE9le tVOIlQ08xbWOI0J3VfUGKvb0moNlqXqHFu0/Yg3l4e629CT+yrTYApQDk4OMU7RF+ffb apwKn99ZwdixJxjQtEcroy47pRO7EyRTEe+pR/V7vYjXvCqogb5EOtrzdnsvEkKC5cDJ n8vw== 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:mime-version:content-transfer-encoding; bh=eULjIfRmfvgXeIC3+Ipz8mXH88k4V94uDRkFqE1MVvw=; b=kh4clPyppo70gsBS2f0GRnUlXhcoFHDB2lSa/Q2Pm9Be6FdfTQ7W+qDDzJjlcQ2Pd9 +G7kbEB3mO053qJHMX73MhHLr9thjmlgw24apBpbMWKbNz9B1SEVffnHIt9KuE4yZ+h3 yIOKOL7zRiKqMkw2jfb+vuadw6BCRMlvDNjWuPnuoXPUBSBwXGjAoqdnFORa7hYAcn1R gy+GACgZfy0O5Mv0CFjYfG/ST/R/fpt4H+iSFFszQgLX6wPgv5fMkn0PX4kBR/xZonA6 Azz6icQ59VoQTzCjG2XX79oKShsVmKsQdU+XT6hQZHyxM+QUwtptg7zk0uj3OZ8G3Ks0 JnYw== X-Gm-Message-State: AOUpUlGmx7u0vjygsih/zoHzP/HYfvXUKyo6kdfKdq1XmSkJAwZ/sKFf gj4jLUobmxYf5XDpJUaYEk8LFoky X-Received: by 2002:a2e:8185:: with SMTP id e5-v6mr21625135ljg.93.1534409003936; Thu, 16 Aug 2018 01:43:23 -0700 (PDT) Received: from localhost ([87.54.42.112]) by smtp.gmail.com with ESMTPSA id j64-v6sm4946269lfe.56.2018.08.16.01.43.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 Aug 2018 01:43:23 -0700 (PDT) From: Esben Haabendal To: linux-i2c@vger.kernel.org Cc: Esben Haabendal , Wolfram Sang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Lucas Stach , Phil Reid , Fabio Estevam , Peter Rosin , linux-kernel@vger.kernel.org Subject: [PATCH v4 1/3] i2c: imx: Fix race condition in dma read Date: Thu, 16 Aug 2018 10:43:12 +0200 Message-Id: <20180816084315.7857-2-esben.haabendal@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180816084315.7857-1-esben.haabendal@gmail.com> References: <20180816084315.7857-1-esben.haabendal@gmail.com> 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: 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 Acked-by: Uwe Kleine-König --- drivers/i2c/busses/i2c-imx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 498c5e891649..ad6adefb64da 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; @@ -783,6 +780,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bo int i, result; unsigned int temp; int block_data = msgs->flags & I2C_M_RECV_LEN; + int use_dma = i2c_imx->dma && msgs->len >= DMA_THRESHOLD && !block_data; dev_dbg(&i2c_imx->adapter.dev, "<%s> write slave address: addr=0x%x\n", @@ -809,12 +807,14 @@ 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; + if (use_dma) + 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__); - if (i2c_imx->dma && msgs->len >= DMA_THRESHOLD && !block_data) + if (use_dma) return i2c_imx_dma_read(i2c_imx, msgs, is_lastmsg); /* read data */ -- 2.18.0