Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp629794imm; Wed, 23 May 2018 02:59:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpB6YDpDYPmT5Y4kTrdVcZXQak34gDfqelksGZdFFq4ftRUHphFBKEDKodxeGeVXKUMQCGF X-Received: by 2002:a63:9517:: with SMTP id p23-v6mr1726828pgd.183.1527069545498; Wed, 23 May 2018 02:59:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527069545; cv=none; d=google.com; s=arc-20160816; b=qTtIOVtW4LadjCrPEYW8C/DahKnTzS+nvQ3eYXOIH7E2/Zv64H3C5dVI28t76Fhczj SWFOHi9u/VToUYUWUCXBS0fOL3/QnoQUxUPLbHUIaDmNe0+7lwCo0y1kUxf0JmVl3M5k 5erBM/pO7NAYQzIiw7IBu6bBdijnVBVXGQAHNYev5gtA7BaRFKZ8rkwzq8g1r9a6pQpx LCh224qlYrhAu2Pvc9ynP30pIohMhCIsb5q0Moi/OPVWCg81yFEj4iwpPdn/GW6QGUBK 5VL9JERs0lv1Mhdhqt+g+Vepn0qsc4lx3TcdDzHnwJg5KmCaTN042lVtOijwdydkw5C0 fjVg== 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=m5atjfdioKpL9uRdAJ0UDf7EcIvoU736qRqVqPZ+w/8=; b=KjVluHiKteVeGerUEgrXiEJpQW8/os4pu5VKbq4IWHzNTw/45BtIWx1aEAIO8JVMMz 65+h0sMd0bmXdkaXwJEViUs61Snkdyq+N3ejSytlfEgMhsXnthZ7ja4eGUrCxEnChgqC wuVcuUeDpL51tNMZhBqyfDpo7DUkPwQ4U+yTtNUQdc6uUzFRZyUOtUJQdktaSopELzHp KmQzelRm6jZ/Zgtzu1AyrQzcBEUjktNZj2Y2vIyrKl3+DskmN01b6o7IarwKYVVpZijW c+blLnUcBkx8OcVQA9ABRXrDCHuteiWzIuICoDDrzwivB0LMrvFy4Yu9l9nFXIsT4mQO Maiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=FB3xXFe/; 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 y8-v6si18904642pli.242.2018.05.23.02.58.50; Wed, 23 May 2018 02:59:05 -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=FB3xXFe/; 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 S932454AbeEWJ6F (ORCPT + 99 others); Wed, 23 May 2018 05:58:05 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35007 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932291AbeEWJ4c (ORCPT ); Wed, 23 May 2018 05:56:32 -0400 Received: by mail-wm0-f67.google.com with SMTP id o78-v6so7530355wmg.0; Wed, 23 May 2018 02:56:32 -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=m5atjfdioKpL9uRdAJ0UDf7EcIvoU736qRqVqPZ+w/8=; b=FB3xXFe/SXrvnM49koGqdOSfienhw+gjl0PR6hvvIUT/kxdwhLLXIUTSPFkotsvWQt oZ+ySQdU4PZQyxWSEtkIknWS4MJWIJ81dmZUUhbi8RgvDVSF/YVwMPMep8Swddg1w6So +svn5BIVfSckJWuRT33wOgykZboh8hClCckLw2l2O79YfYknN+A1q1MHRUkvHcazfD8s +M/xlpdZfcP67Zy0IV+DEorAfGcXw6Tz6XHLV97fv8m6A5MN1B21UH9whc5jRNucFTQ1 KwDc2uqmjB6q5jXP775PRTNWPtHpoPQp8A75eMftRplkB5Dvx58e1j39ooWCUIX+myO7 I/pw== 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=m5atjfdioKpL9uRdAJ0UDf7EcIvoU736qRqVqPZ+w/8=; b=WTqoj04IFDkoKcag4mW/VeHSXRE6ucqOoqKihFX0y2d8Xgl4yVAityAWp0XE2m4EmR gAYl/snucFnVxo+4Z4Xj+VeIcLoGX9gBBICnu1Qld0zNkWi5oA30QwAGoWp9vuthzkzN AszDkD6+esAy599gZZfYJk2XUhAdTCMvZ3Oo1ZxPUQNV4EWZ4KRS6m+8tfIipKROInz9 RWNG3fnjDbkfnc+klgjMImsWptypR3xXUQAI4O3bIkPPqW4WPuFu930xVCl6xGiLxWVz e4uB2uYUd/JuorU6DH+Kv4DGahybRaV7bSycsKU06fTBreF+54PBKYobDX3pUwshsm0E 317w== X-Gm-Message-State: ALKqPwf+AVGXg3mueeiUbBEMsFWMyZE/bvEOm6fVLpKQWVCLM2OBYD1I 2oc/jZOBUvo5VMIU9fwaE5VutFHvHdU= X-Received: by 2002:a2e:86d9:: with SMTP id n25-v6mr1346975ljj.18.1527069391082; Wed, 23 May 2018 02:56:31 -0700 (PDT) Received: from localhost ([87.54.42.112]) by smtp.gmail.com with ESMTPSA id e9-v6sm3415417ljg.90.2018.05.23.02.56.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 May 2018 02:56:30 -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 , Linus Walleij , Clemens Gruber , Wei Jinhua , Michail Georgios Etairidis , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] i2c: imx: Fix race condition in dma read Date: Wed, 23 May 2018 11:56:21 +0200 Message-Id: <20180523095623.3347-3-esben.haabendal@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180523095623.3347-1-esben.haabendal@gmail.com> References: <20180523095623.3347-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 6fca5e64cffb..742b548437af 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -677,9 +677,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; @@ -819,6 +816,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.17.0