Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9076297pxu; Mon, 28 Dec 2020 06:05:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwtj7SUPXfWCiKYXjTrWmlphUXX99k0UQBWayCKJYdk2UzWbQgsHTYMEnyDb4w0EvkFxH6l X-Received: by 2002:a17:906:4bc5:: with SMTP id x5mr41801822ejv.55.1609164342330; Mon, 28 Dec 2020 06:05:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609164342; cv=none; d=google.com; s=arc-20160816; b=lcPbCwnnEJ5ePErKQxs0Tf5bawSPsLhcoPZ7cL+onxEk/W/lAE4Qz9HJTJK+DDC3nM ZzpeO1SeUPemnBGWk4AcmCSw1Qf2NxgGEcNVQGRb8UiG4jL0Ena8VQr7X85UMPgS5b85 Dvfx3/ilS1pY1He/dtbMclXoQxOQNvNHcydVlv0NBsaFCQ7/gpBa5Nqb7r+Bkg5CrVD3 H0ZdbS4KpH2VI2M25W+aeiIm1mDyLQMmN2rI8ACSeZ0OxXQG3rKL5TpXQGx/11Lxbnd6 PSAUCCVtLrbtynMycsPAVj0/ha+K9abQdUf3ZXAEdOlevTU+YDOxk1b8Pbtx+6EJAmX+ N+vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sUGd/gggMGEjuSbKqo4ZpGWruKT8/fWr0JSFVM3oeZ4=; b=gLsk7lRH5uTXWFiCxY7qqhpEVk0N3BqFmWllkqvqvQTxUpNzYIvWexHSEpz/7ga0Tl 7fn1vaZVkj7uOECUEhhwYA6xf9RAyyWEfo2+NvFEIY8VV3k1fecMc5+GewzhObyYF7sy TQYYG/8eNhtqLRGkHC4GjisCQ+kr7OMsATYHRikXS/zq0RLQbp4GvkdqMaFANla2D5pq LoH9aoHnL8ns1nryqH8/2g0Lval9iPHPcin96oeufEvExM7Tj6GzUSIVRl6+bbqIa8DZ E55aeaRIMsNkjS3GQhCvarwUPV3AuKX3e8Hc3MEzMw6hgHG3DCr+e8hpWl61l962+2/f bTjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g7tXic2T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si6647433edl.517.2020.12.28.06.05.18; Mon, 28 Dec 2020 06:05:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g7tXic2T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436685AbgL1OBw (ORCPT + 99 others); Mon, 28 Dec 2020 09:01:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:34768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408313AbgL1OBP (ORCPT ); Mon, 28 Dec 2020 09:01:15 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0410D206E5; Mon, 28 Dec 2020 14:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609164059; bh=k+9nWgCHcHoRAZlN+GsVuaB9HhTJXD9OzDc54IToCxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g7tXic2T/STegVv+heDvdgMlOvN1cWHiJbQwaV+8my5hK/A4N9t+Bv5Kq7QHIV8q/ NmjYhVQ5yK8jfieOzxECA+nDkcwyzFLtvXCE//LBR9oFVjQQgBNlT67B1nxfFptmUr AyKCobpl4XLkFYco/D7hyN8OIofCRSTBLXIsw1aM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Douglas Anderson , Stephen Boyd , Akash Asthana , Dmitry Baryshkov , Bjorn Andersson , Sasha Levin Subject: [PATCH 5.10 014/717] soc: qcom: geni: More properly switch to DMA mode Date: Mon, 28 Dec 2020 13:40:12 +0100 Message-Id: <20201228125021.672250930@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Douglas Anderson [ Upstream commit 4b6ea87be44ef34732846fc71e44c41125f0c4fa ] On geni-i2c transfers using DMA, it was seen that if you program the command (I2C_READ) before calling geni_se_rx_dma_prep() that it could cause interrupts to fire. If we get unlucky, these interrupts can just keep firing (and not be handled) blocking further progress and hanging the system. In commit 02b9aec59243 ("i2c: i2c-qcom-geni: Fix DMA transfer race") we avoided that by making sure we didn't program the command until after geni_se_rx_dma_prep() was called. While that avoided the problems, it also turns out to be invalid. At least in the TX case we started seeing sporadic corrupted transfers. This is easily seen by adding an msleep() between the DMA prep and the writing of the command, which makes the problem worse. That means we need to revert that commit and find another way to fix the bogus IRQs. Specifically, after reverting commit 02b9aec59243 ("i2c: i2c-qcom-geni: Fix DMA transfer race"), I put some traces in. I found that the when the interrupts were firing like crazy: - "m_stat" had bits for M_RX_IRQ_EN, M_RX_FIFO_WATERMARK_EN set. - "dma" was set. Further debugging showed that I could make the problem happen more reliably by adding an "msleep(1)" any time after geni_se_setup_m_cmd() ran up until geni_se_rx_dma_prep() programmed the length. A rather simple fix is to change geni_se_select_dma_mode() so it's a true inverse of geni_se_select_fifo_mode() and disables all the FIFO related interrupts. Now the problematic interrupts can't fire and we can program things in the correct order without worrying. As part of this, let's also change the writel_relaxed() in the prepare function to a writel() so that our DMA is guaranteed to be prepared now that we can't rely on geni_se_setup_m_cmd()'s writel(). NOTE: the only current user of GENI_SE_DMA in mainline is i2c. Fixes: 37692de5d523 ("i2c: i2c-qcom-geni: Add bus driver for the Qualcomm GENI I2C controller") Fixes: 02b9aec59243 ("i2c: i2c-qcom-geni: Fix DMA transfer race") Signed-off-by: Douglas Anderson Reviewed-by: Stephen Boyd Reviewed-by: Akash Asthana Tested-by: Dmitry Baryshkov Link: https://lore.kernel.org/r/20201013142448.v2.1.Ifdb1b69fa3367b81118e16e9e4e63299980ca798@changeid Signed-off-by: Bjorn Andersson Signed-off-by: Sasha Levin --- drivers/soc/qcom/qcom-geni-se.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c index d0e4f520cff8c..751a49f6534f4 100644 --- a/drivers/soc/qcom/qcom-geni-se.c +++ b/drivers/soc/qcom/qcom-geni-se.c @@ -289,10 +289,23 @@ static void geni_se_select_fifo_mode(struct geni_se *se) static void geni_se_select_dma_mode(struct geni_se *se) { + u32 proto = geni_se_read_proto(se); u32 val; geni_se_irq_clear(se); + val = readl_relaxed(se->base + SE_GENI_M_IRQ_EN); + if (proto != GENI_SE_UART) { + val &= ~(M_CMD_DONE_EN | M_TX_FIFO_WATERMARK_EN); + val &= ~(M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN); + } + writel_relaxed(val, se->base + SE_GENI_M_IRQ_EN); + + val = readl_relaxed(se->base + SE_GENI_S_IRQ_EN); + if (proto != GENI_SE_UART) + val &= ~S_CMD_DONE_EN; + writel_relaxed(val, se->base + SE_GENI_S_IRQ_EN); + val = readl_relaxed(se->base + SE_GENI_DMA_MODE_EN); val |= GENI_DMA_MODE_EN; writel_relaxed(val, se->base + SE_GENI_DMA_MODE_EN); @@ -651,7 +664,7 @@ int geni_se_tx_dma_prep(struct geni_se *se, void *buf, size_t len, writel_relaxed(lower_32_bits(*iova), se->base + SE_DMA_TX_PTR_L); writel_relaxed(upper_32_bits(*iova), se->base + SE_DMA_TX_PTR_H); writel_relaxed(GENI_SE_DMA_EOT_BUF, se->base + SE_DMA_TX_ATTR); - writel_relaxed(len, se->base + SE_DMA_TX_LEN); + writel(len, se->base + SE_DMA_TX_LEN); return 0; } EXPORT_SYMBOL(geni_se_tx_dma_prep); @@ -688,7 +701,7 @@ int geni_se_rx_dma_prep(struct geni_se *se, void *buf, size_t len, writel_relaxed(upper_32_bits(*iova), se->base + SE_DMA_RX_PTR_H); /* RX does not have EOT buffer type bit. So just reset RX_ATTR */ writel_relaxed(0, se->base + SE_DMA_RX_ATTR); - writel_relaxed(len, se->base + SE_DMA_RX_LEN); + writel(len, se->base + SE_DMA_RX_LEN); return 0; } EXPORT_SYMBOL(geni_se_rx_dma_prep); -- 2.27.0