From patchwork Tue Oct 9 05:47:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10631947 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B67A933 for ; Tue, 9 Oct 2018 05:50:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A0BD28A41 for ; Tue, 9 Oct 2018 05:50:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1851B28A46; Tue, 9 Oct 2018 05:50:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E899428A41 for ; Tue, 9 Oct 2018 05:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FUmQ3OONFHt0A+gZOVkuybqXzYVJfCgAPjL3qLfZWho=; b=bc2Czt3U8WKWys HxA37isI87cFibss9dFIN86QIDqJZAcX+jl09Uo6o5jzNFk99yGPt13vVuP5wuF0WWf27baM/9GvU wAlWCx6bF3UiSWtOsUGbXouvbhDaQ9jO44S9J8PWrt1OswJyJfVAu794PS3UkJt5dofKsxXA7RUDQ MhkX0RgQ+ziAXdbJkVen/B8/mK3m37ivPc0JDB7xwHeyVYqm++veSk797j6ZrxcNREc5L/dYEsr2Q CMIQ1Un7fqjotH+5f+aW6/Iaf5kaAYx4ZoZ4IlB8SeubuqEgmtFQjkh9W1FYKsvF+7Gms/cSRriY6 ZFu7vAaDaakUG4vXxciA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9ku3-0006QJ-Oe; Tue, 09 Oct 2018 05:49:55 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9ksT-0005jQ-HP for linux-arm-kernel@lists.infradead.org; Tue, 09 Oct 2018 05:48:20 +0000 Received: by mail-pf1-x443.google.com with SMTP id l81-v6so262702pfg.3 for ; Mon, 08 Oct 2018 22:48:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eW4Ce55VjYsIH9MyeML3hQXQKFMbk+C12X1qFn1Si2o=; b=J1OJ/NVro04YDIAp7uO6GxnlBPMf1qK+Ic3H2mdbGT/Kv7P8/1DO7uFd/YM3Xr+TH+ U3UoZYhjaONyVNE0CehGK5Cab0SyxQdG6Ncr1jt5ebuxk+t3nydeOnqrYnQIntIKf8P8 EvqWWmTLjxjo6Zeb070B2LlGwhrrmu5njWm4E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eW4Ce55VjYsIH9MyeML3hQXQKFMbk+C12X1qFn1Si2o=; b=r7klBsGad/p6YBDIchmv7tH4gaFh0ZVug8cmFjK4ImeOgbDJO+Uv5pslCnu8oGh3Sc vTosuGK5pYA9Z9+AfADc77g7OIZuLOv2uOa7RTqepGgFXu0eiZ19ttTFc/BFqv7iof3r S9xTD5n6iHCJ/2msm1RwPyKfTQgi8WAW2JBswJHR94Ctmt96xXjcsb0oR1GnpZ7rOtxq 1k41omvQ82PCRZ9pwVgRzc9Ln1w6S7d9fPHn5atdllYMtAQvTGW1+cfKMlWy/N3XzA4u Qw97A4Jy/4FN2+64kPXPpW8MAdm1bgeci1l5IxSltjDCTbhdwJpEmHNaBD3jjbOGNXhe gcWQ== X-Gm-Message-State: ABuFfohsaoHfZwJBrukuRZVp42Fupwe57wXlBCnh2bSIyCNgiascB+3I JpzEgCt61EbxvuHKVvUsyjjxiQ== X-Google-Smtp-Source: ACcGV63EUVAsXYPZ5xjm8SPgh4vzszjNQFzT/4eUBdu1yH33jc3pRXBDGQ88mZGVAc8WaDgUkHJwlQ== X-Received: by 2002:a63:c5a:: with SMTP id 26-v6mr24278770pgm.372.1539064086528; Mon, 08 Oct 2018 22:48:06 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id a15-v6sm16886234pff.8.2018.10.08.22.48.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 22:48:05 -0700 (PDT) From: "Joel Fernandes (Google)" To: stable@vger.kernel.org Subject: [PATCH 1/7] dmaengine: stm32-dma: threshold manages with bitfield feature Date: Mon, 8 Oct 2018 22:47:46 -0700 Message-Id: <20181009054752.145978-2-joel@joelfernandes.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20181009054752.145978-1-joel@joelfernandes.org> References: <20181009054752.145978-1-joel@joelfernandes.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181008_224817_623639_C3125161 X-CRM114-Status: GOOD ( 13.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Torgue , Vinod Koul , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Pierre Yves MORDRET , "Joel Fernandes \(Google\)" , Maxime Coquelin , dmaengine@vger.kernel.org, Dan Williams , "moderated list:ARM/STM32 ARCHITECTURE" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pierre Yves MORDRET >From now on, DMA bitfield is to manage DMA FIFO Threshold. Signed-off-by: Pierre-Yves MORDRET Signed-off-by: Vinod Koul --- drivers/dma/stm32-dma.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index 786fc8fcc38e..4099948b6914 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -116,6 +116,10 @@ #define STM32_DMA_MAX_DATA_PARAM 0x03 #define STM32_DMA_MAX_BURST 16 +/* DMA Features */ +#define STM32_DMA_THRESHOLD_FTR_MASK GENMASK(1, 0) +#define STM32_DMA_THRESHOLD_FTR_GET(n) ((n) & STM32_DMA_THRESHOLD_FTR_MASK) + enum stm32_dma_width { STM32_DMA_BYTE, STM32_DMA_HALF_WORD, @@ -129,11 +133,18 @@ enum stm32_dma_burst_size { STM32_DMA_BURST_INCR16, }; +/** + * struct stm32_dma_cfg - STM32 DMA custom configuration + * @channel_id: channel ID + * @request_line: DMA request + * @stream_config: 32bit mask specifying the DMA channel configuration + * @features: 32bit mask specifying the DMA Feature list + */ struct stm32_dma_cfg { u32 channel_id; u32 request_line; u32 stream_config; - u32 threshold; + u32 features; }; struct stm32_dma_chan_reg { @@ -171,6 +182,7 @@ struct stm32_dma_chan { u32 next_sg; struct dma_slave_config dma_sconfig; struct stm32_dma_chan_reg chan_reg; + u32 threshold; }; struct stm32_dma_device { @@ -976,7 +988,8 @@ static void stm32_dma_set_config(struct stm32_dma_chan *chan, /* Enable Interrupts */ chan->chan_reg.dma_scr |= STM32_DMA_SCR_TEIE | STM32_DMA_SCR_TCIE; - chan->chan_reg.dma_sfcr = cfg->threshold & STM32_DMA_SFCR_FTH_MASK; + chan->threshold = STM32_DMA_THRESHOLD_FTR_GET(cfg->features); + chan->chan_reg.dma_sfcr = STM32_DMA_SFCR_FTH(chan->threshold); } static struct dma_chan *stm32_dma_of_xlate(struct of_phandle_args *dma_spec, @@ -996,7 +1009,7 @@ static struct dma_chan *stm32_dma_of_xlate(struct of_phandle_args *dma_spec, cfg.channel_id = dma_spec->args[0]; cfg.request_line = dma_spec->args[1]; cfg.stream_config = dma_spec->args[2]; - cfg.threshold = dma_spec->args[3]; + cfg.features = dma_spec->args[3]; if ((cfg.channel_id >= STM32_DMA_MAX_CHANNELS) || (cfg.request_line >= STM32_DMA_MAX_REQUEST_ID)) { From patchwork Tue Oct 9 05:47:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10631945 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06368933 for ; Tue, 9 Oct 2018 05:49:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC1A328A41 for ; Tue, 9 Oct 2018 05:49:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFE1728A46; Tue, 9 Oct 2018 05:49:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 832A228A41 for ; Tue, 9 Oct 2018 05:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ykYdiQaAlXE0QFMmFS4bR7BQYENglY1UE5PZYJqQ8Hs=; b=rSytrwMQ51TFg7 GJHCuPZwZeE7/l6Pr+A5eFuVPfAh50Iqybvg/4g4D3+WMxFGYR1UcH0F3tJ0fQZXQx98NdLj3HyJV mZMqZZNDn9OrReznLSOYZoJTDsrfpusF4GeFGS66D6VrSdS9n63G7KPRelppiD9dYlBeLU27cwJI4 3eAR9AKoiMsF2/3ay9yanJbfUEfvt9ctodE/hISeOyoBN2MCfe7Fp9BZYHyjwL7R/S2pWkDH+sRnm tkZtNMhdjGhkgZNXw6VDHqXkpD81ojkUH0/PVwi7hQOvuvQEurjz62s2TgaDZxUDtslk4uFJPvGt9 H1mqpOlKnfRwnQ4zUnJg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9ktD-00065p-Ul; Tue, 09 Oct 2018 05:49:04 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9ksT-0005jr-HN for linux-arm-kernel@lists.infradead.org; Tue, 09 Oct 2018 05:48:20 +0000 Received: by mail-pf1-x443.google.com with SMTP id l81-v6so262758pfg.3 for ; Mon, 08 Oct 2018 22:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+MWYNVKtdWKD6Kujvr2Aj0Wsqz2uAcNP6f8Ca6gsyhQ=; b=UEGr97XWdDuhrAyW352emJpf61BrkxEUIlSDz9vF42Ii3CFMf5SrrrSmUdi5BlcYxz 4bpFquIee4piojPX22Gzdq61W9axvkWAz3d7U4p7SD2l3qTvyC6TX9/P+gqtNzeeO8io vb4JPkTXqL6Z6MO/fpQ25OS4zUU4tEofF2o7Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+MWYNVKtdWKD6Kujvr2Aj0Wsqz2uAcNP6f8Ca6gsyhQ=; b=Z3yZzJNofwmvK61aoQO5DfDzrUphdhRqp992kryR0Gx8KupdwZC1N/B7jNRsCHFHSP p/2LLyzZnUTMvcyFid0a04/QZM3hynchE0oYa9DHCJL/EujqQOHrWdv3FEUV+lzfqvhR RPl6MZRu8sCn3PvF8fnFNCwIq2Coj100JyBEbHEdv+s9mSU5zvwtyn1GzeBFFS50+VqM YX+FBpvSxy5mYypeI/4Fmz6gMwYdb46f8SBbFlRTLchny6mLgNqDkFXYnS+4meG5nTsf KTSLCof+bFc5FmNZun4FJWK7h6tVmtom869mypoCBtbLUlxg3Toc5/BqZGq+0RzsZUjn JC0w== X-Gm-Message-State: ABuFfogRdCjVdHsewojLc4u+pFTfVJOjwIH1nkJjO2uuthBZOKHNdXRo 9466qBIGU9w1F/DMlrmLNwi7j3k0x9Y= X-Google-Smtp-Source: ACcGV62btTrzmG5Nc+IiadGRrGg+nq0I79KJncpZNOsftccNv1XHh1w4r0UpuBz85dlIkAzpLPthrQ== X-Received: by 2002:a63:9409:: with SMTP id m9-v6mr23420475pge.93.1539064088830; Mon, 08 Oct 2018 22:48:08 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id a15-v6sm16886234pff.8.2018.10.08.22.48.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 22:48:07 -0700 (PDT) From: "Joel Fernandes (Google)" To: stable@vger.kernel.org Subject: [PATCH 2/7] dmaengine: stm32-dma: fix incomplete configuration in cyclic mode Date: Mon, 8 Oct 2018 22:47:47 -0700 Message-Id: <20181009054752.145978-3-joel@joelfernandes.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20181009054752.145978-1-joel@joelfernandes.org> References: <20181009054752.145978-1-joel@joelfernandes.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181008_224817_618411_1D58E2BF X-CRM114-Status: GOOD ( 13.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Torgue , Vinod Koul , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Pierre Yves MORDRET , "Joel Fernandes \(Google\)" , Maxime Coquelin , dmaengine@vger.kernel.org, Hugues Fruchet , Dan Williams , "moderated list:ARM/STM32 ARCHITECTURE" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pierre Yves MORDRET When in cyclic mode, the configuration is updated after having started the DMA hardware (STM32_DMA_SCR_EN) leading to incomplete configuration of SMxAR registers. Signed-off-by: Pierre-Yves MORDRET Signed-off-by: Hugues Fruchet Signed-off-by: Vinod Koul --- drivers/dma/stm32-dma.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index 4099948b6914..fae7de54f00a 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -441,6 +441,8 @@ static void stm32_dma_dump_reg(struct stm32_dma_chan *chan) dev_dbg(chan2dev(chan), "SFCR: 0x%08x\n", sfcr); } +static void stm32_dma_configure_next_sg(struct stm32_dma_chan *chan); + static void stm32_dma_start_transfer(struct stm32_dma_chan *chan) { struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan); @@ -483,6 +485,9 @@ static void stm32_dma_start_transfer(struct stm32_dma_chan *chan) if (status) stm32_dma_irq_clear(chan, status); + if (chan->desc->cyclic) + stm32_dma_configure_next_sg(chan); + stm32_dma_dump_reg(chan); /* Start DMA */ @@ -576,8 +581,7 @@ static void stm32_dma_issue_pending(struct dma_chan *c) if (vchan_issue_pending(&chan->vchan) && !chan->desc && !chan->busy) { dev_dbg(chan2dev(chan), "vchan %p: issued\n", &chan->vchan); stm32_dma_start_transfer(chan); - if (chan->desc->cyclic) - stm32_dma_configure_next_sg(chan); + } spin_unlock_irqrestore(&chan->vchan.lock, flags); } From patchwork Tue Oct 9 05:47:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10631949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6D86933 for ; Tue, 9 Oct 2018 05:50:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D81562875C for ; Tue, 9 Oct 2018 05:50:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBDD228A46; Tue, 9 Oct 2018 05:50:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5018C2875C for ; Tue, 9 Oct 2018 05:50:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FYsTjQCvp3W7uxBhDfmYQUk1ZwyvWgvDr+9wXJASknY=; b=bhsBUihHuzXFdv XCPU5c6zA3cIZ74A5oXPW6SC4GsKwte+1ke3syIHYjXRF9oSnqV22o3g8xVua+sTiYMJPAn0PMaLf BZiGVrWn2gUelc/hfazBUmjSn+xgIWEz9Nb2Hr+3C7uJfszD89pkI6Itehc7MtSAEXY9AtFoV12q5 11ScADnL0EW/uqQPS6fT/KJMAGha1A6drt4oom3J5tSo9/fTj4J/RXgTdDAAKktK7CRQvHs4io2uY jbYRAaDvLXuo21SwiNUg+0VlWYjZ0CHzAib+KRVh7yhRPLomk1vpYtdJoAkKD2LORm1NyGmqr90ED e2yt9kUwsBpuVzMwTyjw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9kun-0007yo-BH; Tue, 09 Oct 2018 05:50:41 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9ksX-0005k2-D6 for linux-arm-kernel@lists.infradead.org; Tue, 09 Oct 2018 05:48:32 +0000 Received: by mail-pl1-x643.google.com with SMTP id f8-v6so251940plb.2 for ; Mon, 08 Oct 2018 22:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3RJ/t1zGSm3UfjNE8WI2rEcf5JWxo9DPt72JtaWe1nc=; b=OAnb0LOLsek/oBjbd/RvEDOLwPnxFi8khlKDc7dtNbTDodJRo3hJcQ3+RGL0hlVXUS MeT3As4Err6QRj2bqtj2/AxIeyoiykDcUoyFJnxD0IPlsY0Zn3JArlnbHZKIUqgkjwcO DRNZhYjaAiDXac4oXb/whaGEkY6Vlt1BFkxbQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3RJ/t1zGSm3UfjNE8WI2rEcf5JWxo9DPt72JtaWe1nc=; b=hG9255Y0aYylyEFqaXwTXDM9iTxSiOhsPMLaX7gFq5PUQ2rikgZyBxVdUfAQrxyHSe 5Zp2E4ZtqBR2wiVzLTkfvyf3aXtwg+bXaoZRZTu77pinXrq1SfnuGGD5eAgujHdOuvr3 cRZAycpCZKi9kDoViW7QMcXKgStw00M97q/nlh4Wv8+mzAC/tt7wzImQfw/oAVPnmM+y Q5uqjhPKPCk8L1XJ/ObsRfkPDzIef935RJ7XcgpOS/c5VonTpPb0ZIkJHomcAAaBZiVE BjIelnC2rajg8wd6ndzpQUnjOuSVYIHtHZL6eDZGs6ZDpgMobYR9m1ccyOElMY9nnLiV g+Xw== X-Gm-Message-State: ABuFfogsZGqwFW4FVt0Bjni10Elmpzi6L2I7RKn/sUXlRbLU/wi9vZEJ PKnuW5Hlf7eb0htGB4GvaSNShA== X-Google-Smtp-Source: ACcGV61hNIYMAw/1MXI+AVlnFVRjyLQUhIq8EqHXyT+gawh5a79FLEuK6O6RcAeZ/xrFtwE5xRCgKw== X-Received: by 2002:a17:902:d715:: with SMTP id w21-v6mr26370555ply.143.1539064090437; Mon, 08 Oct 2018 22:48:10 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id a15-v6sm16886234pff.8.2018.10.08.22.48.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 22:48:09 -0700 (PDT) From: "Joel Fernandes (Google)" To: stable@vger.kernel.org Subject: [PATCH 3/7] dmaengine: stm32-dma: fix typo and reported checkpatch warnings Date: Mon, 8 Oct 2018 22:47:48 -0700 Message-Id: <20181009054752.145978-4-joel@joelfernandes.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20181009054752.145978-1-joel@joelfernandes.org> References: <20181009054752.145978-1-joel@joelfernandes.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181008_224821_510746_820FFCA7 X-CRM114-Status: GOOD ( 13.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Torgue , Vinod Koul , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Pierre Yves MORDRET , "Joel Fernandes \(Google\)" , Maxime Coquelin , dmaengine@vger.kernel.org, Dan Williams , "moderated list:ARM/STM32 ARCHITECTURE" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pierre Yves MORDRET Fix typo in a comment and solved reported checkpatch warnings. Signed-off-by: Pierre-Yves MORDRET Signed-off-by: Vinod Koul --- drivers/dma/stm32-dma.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index fae7de54f00a..b64e14a83dec 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -60,7 +60,8 @@ #define STM32_DMA_SCR_PINC BIT(9) /* Peripheral increment mode */ #define STM32_DMA_SCR_CIRC BIT(8) /* Circular mode */ #define STM32_DMA_SCR_PFCTRL BIT(5) /* Peripheral Flow Controller */ -#define STM32_DMA_SCR_TCIE BIT(4) /* Transfer Cplete Int Enable*/ +#define STM32_DMA_SCR_TCIE BIT(4) /* Transfer Complete Int Enable + */ #define STM32_DMA_SCR_TEIE BIT(2) /* Transfer Error Int Enable */ #define STM32_DMA_SCR_DMEIE BIT(1) /* Direct Mode Err Int Enable */ #define STM32_DMA_SCR_EN BIT(0) /* Stream Enable */ @@ -918,7 +919,7 @@ static enum dma_status stm32_dma_tx_status(struct dma_chan *c, u32 residue = 0; status = dma_cookie_status(c, cookie, state); - if ((status == DMA_COMPLETE) || (!state)) + if (status == DMA_COMPLETE || !state) return status; spin_lock_irqsave(&chan->vchan.lock, flags); @@ -982,7 +983,7 @@ static void stm32_dma_desc_free(struct virt_dma_desc *vdesc) } static void stm32_dma_set_config(struct stm32_dma_chan *chan, - struct stm32_dma_cfg *cfg) + struct stm32_dma_cfg *cfg) { stm32_dma_clear_reg(&chan->chan_reg); @@ -1015,8 +1016,8 @@ static struct dma_chan *stm32_dma_of_xlate(struct of_phandle_args *dma_spec, cfg.stream_config = dma_spec->args[2]; cfg.features = dma_spec->args[3]; - if ((cfg.channel_id >= STM32_DMA_MAX_CHANNELS) || - (cfg.request_line >= STM32_DMA_MAX_REQUEST_ID)) { + if (cfg.channel_id >= STM32_DMA_MAX_CHANNELS || + cfg.request_line >= STM32_DMA_MAX_REQUEST_ID) { dev_err(dev, "Bad channel and/or request id\n"); return NULL; } From patchwork Tue Oct 9 05:47:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10631955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1A48E933 for ; Tue, 9 Oct 2018 05:52:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 092102875C for ; Tue, 9 Oct 2018 05:52:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECB5128A4A; Tue, 9 Oct 2018 05:52:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B43A2875C for ; Tue, 9 Oct 2018 05:52:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OCiAbH/Vj12hbhKfyZSrOIED32In/wp1glkg5Rr/q2A=; b=sNLPpsDl1k13iX I1GIxKt0qN6i+iEO6W/eEM+mXcO/n2w5Sk351gKkFPz8s+n8s3zbFtOElTB5qrEGyE0BOw0FFLmg7 cX9filpEnT/dSR1GoJQH2TosHVgvZED/PJmRGFNZLIUDg0vLNF3YTnWYAqxKAXoTtCbl4NTSc0onX urvIfqxCL6TW9nNVKTkZ5sqZzPo6MD6u6TVepJbaqj49r5/FqXX7RK3Oj2MySkjEcR8+SSUpqc+d3 wGRsaDRnNIjbuzkI96PgMYVhfavYyliER9J+ue+Rzez1me20mTowUvmd9N1A8Nh7/LRrZHun4FVfl WfCY0SQPOqR5QdbOTwPA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9kwi-0000JB-79; Tue, 09 Oct 2018 05:52:40 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9ksX-0005kE-Dd for linux-arm-kernel@lists.infradead.org; Tue, 09 Oct 2018 05:48:51 +0000 Received: by mail-pl1-x643.google.com with SMTP id f18-v6so254504plr.1 for ; Mon, 08 Oct 2018 22:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8YRLGC5WX34ZAL7uoXFtEm26pviT5cexDP0CB4kHN9I=; b=SVN1cean+b7VV27fcOshw1t9RIhBy19m57131o7cTR62vI5iukTIp1mydBQN462VqG pAUbkeLYl7glYIyYxSBIaK1rDUVRY8noFTzm99kDmarZfBEBDOIGmsjZBp5amKfzyNY3 oIaoZBeYI/Gm56Ai46FeuHC8xd2Th8MVJupig= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8YRLGC5WX34ZAL7uoXFtEm26pviT5cexDP0CB4kHN9I=; b=V6nTuf49j22tt9+Xo7TA8Y5DNJy4bJKesrd/Lp/t6FCTfPdYuw3E2hfTcurbOY0Xfl oJSXMZ2eJyPRU+/bvknCKPvGxXt374sp8I8GHMmqCpc0AGBlCYqlahBwIiEbD3lyPeC+ GPNWg6TbUGJkT5MSLGcduXmxEJz4xMGNYj4BVX4PKRBko3Y+AbvGro4SOOkScqwN20Cx rwxJQYtEYkru0PhM4KocedFmwOk7ozvP/56JzB1FDZbKfoyRp7s5fcKaKGQp9zmxe15T nd5VbUalpOZbFpfCYZdJz/tWXxZCjDEJsUNWkV59ONIk3yjvMdU0yT/UfhQsCG0L4r3o XGDw== X-Gm-Message-State: ABuFfohrqBJnVAyUILaW99UO2f+MfAUfiGQUMzS1P13bWL0iUcXrsJqq KytFLBA6PNav0jK8dQWQiXm9Yg== X-Google-Smtp-Source: ACcGV63o2k+9w1N7OQPdi5e4CmovOWjCVxsCUt1lAfAAe42bP8DOmdAoN7g/LXdvhj66z5VWQhnfRw== X-Received: by 2002:a17:902:5602:: with SMTP id h2-v6mr27041305pli.220.1539064092125; Mon, 08 Oct 2018 22:48:12 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id a15-v6sm16886234pff.8.2018.10.08.22.48.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 22:48:11 -0700 (PDT) From: "Joel Fernandes (Google)" To: stable@vger.kernel.org Subject: [PATCH 4/7] dmaengine: stm32-dma: Improve memory burst management Date: Mon, 8 Oct 2018 22:47:49 -0700 Message-Id: <20181009054752.145978-5-joel@joelfernandes.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20181009054752.145978-1-joel@joelfernandes.org> References: <20181009054752.145978-1-joel@joelfernandes.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181008_224821_527970_2FFE1C2C X-CRM114-Status: GOOD ( 21.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Joel Fernandes \(Google\)" , Alexandre Torgue , Vinod Koul , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Pierre Yves MORDRET , dmaengine@vger.kernel.org, Maxime Coquelin , M'boumba Cedric Madianga , Dan Williams , "moderated list:ARM/STM32 ARCHITECTURE" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pierre Yves MORDRET This patch improves memory burst capability using best burst size according to transferred buffer size from/to memory. >From now on, memory burst is not necessarily same as with peripheral burst one and fifo threshold is directly managed by this driver in order to fit with computed memory burst. Signed-off-by: M'boumba Cedric Madianga Signed-off-by: Pierre-Yves MORDRET Signed-off-by: Vinod Koul --- drivers/dma/stm32-dma.c | 204 ++++++++++++++++++++++++++++++++++------ 1 file changed, 175 insertions(+), 29 deletions(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index b64e14a83dec..21ad359a5a59 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -5,6 +5,7 @@ * * Copyright (C) M'boumba Cedric Madianga 2015 * Author: M'boumba Cedric Madianga + * Pierre-Yves Mordret * * License terms: GNU General Public License (GPL), version 2 */ @@ -115,6 +116,8 @@ #define STM32_DMA_MAX_CHANNELS 0x08 #define STM32_DMA_MAX_REQUEST_ID 0x08 #define STM32_DMA_MAX_DATA_PARAM 0x03 +#define STM32_DMA_FIFO_SIZE 16 /* FIFO is 16 bytes */ +#define STM32_DMA_MIN_BURST 4 #define STM32_DMA_MAX_BURST 16 /* DMA Features */ @@ -184,6 +187,8 @@ struct stm32_dma_chan { struct dma_slave_config dma_sconfig; struct stm32_dma_chan_reg chan_reg; u32 threshold; + u32 mem_burst; + u32 mem_width; }; struct stm32_dma_device { @@ -248,6 +253,85 @@ static int stm32_dma_get_width(struct stm32_dma_chan *chan, } } +static enum dma_slave_buswidth stm32_dma_get_max_width(u32 buf_len, + u32 threshold) +{ + enum dma_slave_buswidth max_width; + + if (threshold == STM32_DMA_FIFO_THRESHOLD_FULL) + max_width = DMA_SLAVE_BUSWIDTH_4_BYTES; + else + max_width = DMA_SLAVE_BUSWIDTH_2_BYTES; + + while ((buf_len < max_width || buf_len % max_width) && + max_width > DMA_SLAVE_BUSWIDTH_1_BYTE) + max_width = max_width >> 1; + + return max_width; +} + +static bool stm32_dma_fifo_threshold_is_allowed(u32 burst, u32 threshold, + enum dma_slave_buswidth width) +{ + u32 remaining; + + if (width != DMA_SLAVE_BUSWIDTH_UNDEFINED) { + if (burst != 0) { + /* + * If number of beats fit in several whole bursts + * this configuration is allowed. + */ + remaining = ((STM32_DMA_FIFO_SIZE / width) * + (threshold + 1) / 4) % burst; + + if (remaining == 0) + return true; + } else { + return true; + } + } + + return false; +} + +static bool stm32_dma_is_burst_possible(u32 buf_len, u32 threshold) +{ + switch (threshold) { + case STM32_DMA_FIFO_THRESHOLD_FULL: + if (buf_len >= STM32_DMA_MAX_BURST) + return true; + else + return false; + case STM32_DMA_FIFO_THRESHOLD_HALFFULL: + if (buf_len >= STM32_DMA_MAX_BURST / 2) + return true; + else + return false; + default: + return false; + } +} + +static u32 stm32_dma_get_best_burst(u32 buf_len, u32 max_burst, u32 threshold, + enum dma_slave_buswidth width) +{ + u32 best_burst = max_burst; + + if (best_burst == 1 || !stm32_dma_is_burst_possible(buf_len, threshold)) + return 0; + + while ((buf_len < best_burst * width && best_burst > 1) || + !stm32_dma_fifo_threshold_is_allowed(best_burst, threshold, + width)) { + if (best_burst > STM32_DMA_MIN_BURST) + best_burst = best_burst >> 1; + else + best_burst = 0; + } + + return best_burst; +} + static int stm32_dma_get_burst(struct stm32_dma_chan *chan, u32 maxburst) { switch (maxburst) { @@ -267,12 +351,12 @@ static int stm32_dma_get_burst(struct stm32_dma_chan *chan, u32 maxburst) } static void stm32_dma_set_fifo_config(struct stm32_dma_chan *chan, - u32 src_maxburst, u32 dst_maxburst) + u32 src_burst, u32 dst_burst) { chan->chan_reg.dma_sfcr &= ~STM32_DMA_SFCR_MASK; chan->chan_reg.dma_scr &= ~STM32_DMA_SCR_DMEIE; - if ((!src_maxburst) && (!dst_maxburst)) { + if (!src_burst && !dst_burst) { /* Using direct mode */ chan->chan_reg.dma_scr |= STM32_DMA_SCR_DMEIE; } else { @@ -589,37 +673,52 @@ static void stm32_dma_issue_pending(struct dma_chan *c) static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan, enum dma_transfer_direction direction, - enum dma_slave_buswidth *buswidth) + enum dma_slave_buswidth *buswidth, + u32 buf_len) { enum dma_slave_buswidth src_addr_width, dst_addr_width; int src_bus_width, dst_bus_width; int src_burst_size, dst_burst_size; - u32 src_maxburst, dst_maxburst; - u32 dma_scr = 0; + u32 src_maxburst, dst_maxburst, src_best_burst, dst_best_burst; + u32 dma_scr, threshold; src_addr_width = chan->dma_sconfig.src_addr_width; dst_addr_width = chan->dma_sconfig.dst_addr_width; src_maxburst = chan->dma_sconfig.src_maxburst; dst_maxburst = chan->dma_sconfig.dst_maxburst; + threshold = chan->threshold; switch (direction) { case DMA_MEM_TO_DEV: + /* Set device data size */ dst_bus_width = stm32_dma_get_width(chan, dst_addr_width); if (dst_bus_width < 0) return dst_bus_width; - dst_burst_size = stm32_dma_get_burst(chan, dst_maxburst); + /* Set device burst size */ + dst_best_burst = stm32_dma_get_best_burst(buf_len, + dst_maxburst, + threshold, + dst_addr_width); + + dst_burst_size = stm32_dma_get_burst(chan, dst_best_burst); if (dst_burst_size < 0) return dst_burst_size; - if (!src_addr_width) - src_addr_width = dst_addr_width; - + /* Set memory data size */ + src_addr_width = stm32_dma_get_max_width(buf_len, threshold); + chan->mem_width = src_addr_width; src_bus_width = stm32_dma_get_width(chan, src_addr_width); if (src_bus_width < 0) return src_bus_width; - src_burst_size = stm32_dma_get_burst(chan, src_maxburst); + /* Set memory burst size */ + src_maxburst = STM32_DMA_MAX_BURST; + src_best_burst = stm32_dma_get_best_burst(buf_len, + src_maxburst, + threshold, + src_addr_width); + src_burst_size = stm32_dma_get_burst(chan, src_best_burst); if (src_burst_size < 0) return src_burst_size; @@ -629,27 +728,46 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan, STM32_DMA_SCR_PBURST(dst_burst_size) | STM32_DMA_SCR_MBURST(src_burst_size); + /* Set FIFO threshold */ + chan->chan_reg.dma_sfcr &= ~STM32_DMA_SFCR_FTH_MASK; + chan->chan_reg.dma_sfcr |= STM32_DMA_SFCR_FTH(threshold); + + /* Set peripheral address */ chan->chan_reg.dma_spar = chan->dma_sconfig.dst_addr; *buswidth = dst_addr_width; break; case DMA_DEV_TO_MEM: + /* Set device data size */ src_bus_width = stm32_dma_get_width(chan, src_addr_width); if (src_bus_width < 0) return src_bus_width; - src_burst_size = stm32_dma_get_burst(chan, src_maxburst); + /* Set device burst size */ + src_best_burst = stm32_dma_get_best_burst(buf_len, + src_maxburst, + threshold, + src_addr_width); + chan->mem_burst = src_best_burst; + src_burst_size = stm32_dma_get_burst(chan, src_best_burst); if (src_burst_size < 0) return src_burst_size; - if (!dst_addr_width) - dst_addr_width = src_addr_width; - + /* Set memory data size */ + dst_addr_width = stm32_dma_get_max_width(buf_len, threshold); + chan->mem_width = dst_addr_width; dst_bus_width = stm32_dma_get_width(chan, dst_addr_width); if (dst_bus_width < 0) return dst_bus_width; - dst_burst_size = stm32_dma_get_burst(chan, dst_maxburst); + /* Set memory burst size */ + dst_maxburst = STM32_DMA_MAX_BURST; + dst_best_burst = stm32_dma_get_best_burst(buf_len, + dst_maxburst, + threshold, + dst_addr_width); + chan->mem_burst = dst_best_burst; + dst_burst_size = stm32_dma_get_burst(chan, dst_best_burst); if (dst_burst_size < 0) return dst_burst_size; @@ -659,6 +777,11 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan, STM32_DMA_SCR_PBURST(src_burst_size) | STM32_DMA_SCR_MBURST(dst_burst_size); + /* Set FIFO threshold */ + chan->chan_reg.dma_sfcr &= ~STM32_DMA_SFCR_FTH_MASK; + chan->chan_reg.dma_sfcr |= STM32_DMA_SFCR_FTH(threshold); + + /* Set peripheral address */ chan->chan_reg.dma_spar = chan->dma_sconfig.src_addr; *buswidth = chan->dma_sconfig.src_addr_width; break; @@ -668,8 +791,9 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan, return -EINVAL; } - stm32_dma_set_fifo_config(chan, src_maxburst, dst_maxburst); + stm32_dma_set_fifo_config(chan, src_best_burst, dst_best_burst); + /* Set DMA control register */ chan->chan_reg.dma_scr &= ~(STM32_DMA_SCR_DIR_MASK | STM32_DMA_SCR_PSIZE_MASK | STM32_DMA_SCR_MSIZE_MASK | STM32_DMA_SCR_PBURST_MASK | STM32_DMA_SCR_MBURST_MASK); @@ -709,10 +833,6 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_slave_sg( if (!desc) return NULL; - ret = stm32_dma_set_xfer_param(chan, direction, &buswidth); - if (ret < 0) - goto err; - /* Set peripheral flow controller */ if (chan->dma_sconfig.device_fc) chan->chan_reg.dma_scr |= STM32_DMA_SCR_PFCTRL; @@ -720,6 +840,11 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_slave_sg( chan->chan_reg.dma_scr &= ~STM32_DMA_SCR_PFCTRL; for_each_sg(sgl, sg, sg_len, i) { + ret = stm32_dma_set_xfer_param(chan, direction, &buswidth, + sg_dma_len(sg)); + if (ret < 0) + goto err; + desc->sg_req[i].len = sg_dma_len(sg); nb_data_items = desc->sg_req[i].len / buswidth; @@ -784,7 +909,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_cyclic( return NULL; } - ret = stm32_dma_set_xfer_param(chan, direction, &buswidth); + ret = stm32_dma_set_xfer_param(chan, direction, &buswidth, period_len); if (ret < 0) return NULL; @@ -833,9 +958,10 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy( dma_addr_t src, size_t len, unsigned long flags) { struct stm32_dma_chan *chan = to_stm32_dma_chan(c); - u32 num_sgs; + enum dma_slave_buswidth max_width; struct stm32_dma_desc *desc; size_t xfer_count, offset; + u32 num_sgs, best_burst, dma_burst, threshold; int i; num_sgs = DIV_ROUND_UP(len, STM32_DMA_MAX_DATA_ITEMS); @@ -843,25 +969,34 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy( if (!desc) return NULL; + threshold = chan->threshold; + for (offset = 0, i = 0; offset < len; offset += xfer_count, i++) { xfer_count = min_t(size_t, len - offset, STM32_DMA_MAX_DATA_ITEMS); - desc->sg_req[i].len = xfer_count; + /* Compute best burst size */ + max_width = DMA_SLAVE_BUSWIDTH_1_BYTE; + best_burst = stm32_dma_get_best_burst(len, STM32_DMA_MAX_BURST, + threshold, max_width); + dma_burst = stm32_dma_get_burst(chan, best_burst); stm32_dma_clear_reg(&desc->sg_req[i].chan_reg); desc->sg_req[i].chan_reg.dma_scr = STM32_DMA_SCR_DIR(STM32_DMA_MEM_TO_MEM) | + STM32_DMA_SCR_PBURST(dma_burst) | + STM32_DMA_SCR_MBURST(dma_burst) | STM32_DMA_SCR_MINC | STM32_DMA_SCR_PINC | STM32_DMA_SCR_TCIE | STM32_DMA_SCR_TEIE; - desc->sg_req[i].chan_reg.dma_sfcr = STM32_DMA_SFCR_DMDIS | - STM32_DMA_SFCR_FTH(STM32_DMA_FIFO_THRESHOLD_FULL) | - STM32_DMA_SFCR_FEIE; + desc->sg_req[i].chan_reg.dma_sfcr |= STM32_DMA_SFCR_MASK; + desc->sg_req[i].chan_reg.dma_sfcr |= + STM32_DMA_SFCR_FTH(threshold); desc->sg_req[i].chan_reg.dma_spar = src + offset; desc->sg_req[i].chan_reg.dma_sm0ar = dest + offset; desc->sg_req[i].chan_reg.dma_sndtr = xfer_count; + desc->sg_req[i].len = xfer_count; } desc->num_sgs = num_sgs; @@ -886,6 +1021,7 @@ static size_t stm32_dma_desc_residue(struct stm32_dma_chan *chan, struct stm32_dma_desc *desc, u32 next_sg) { + u32 modulo, burst_size; u32 residue = 0; int i; @@ -893,8 +1029,10 @@ static size_t stm32_dma_desc_residue(struct stm32_dma_chan *chan, * In cyclic mode, for the last period, residue = remaining bytes from * NDTR */ - if (chan->desc->cyclic && next_sg == 0) - return stm32_dma_get_remaining_bytes(chan); + if (chan->desc->cyclic && next_sg == 0) { + residue = stm32_dma_get_remaining_bytes(chan); + goto end; + } /* * For all other periods in cyclic mode, and in sg mode, @@ -905,6 +1043,15 @@ static size_t stm32_dma_desc_residue(struct stm32_dma_chan *chan, residue += desc->sg_req[i].len; residue += stm32_dma_get_remaining_bytes(chan); +end: + if (!chan->mem_burst) + return residue; + + burst_size = chan->mem_burst * chan->mem_width; + modulo = residue % burst_size; + if (modulo) + residue = residue - modulo + burst_size; + return residue; } @@ -994,7 +1141,6 @@ static void stm32_dma_set_config(struct stm32_dma_chan *chan, chan->chan_reg.dma_scr |= STM32_DMA_SCR_TEIE | STM32_DMA_SCR_TCIE; chan->threshold = STM32_DMA_THRESHOLD_FTR_GET(cfg->features); - chan->chan_reg.dma_sfcr = STM32_DMA_SFCR_FTH(chan->threshold); } static struct dma_chan *stm32_dma_of_xlate(struct of_phandle_args *dma_spec, From patchwork Tue Oct 9 05:47:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10631951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A31715E2 for ; Tue, 9 Oct 2018 05:51:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED64628A41 for ; Tue, 9 Oct 2018 05:51:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD4F828A47; Tue, 9 Oct 2018 05:51:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 67EA328A41 for ; Tue, 9 Oct 2018 05:51:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8BC5g6NoUrrHoRJ2Znb6rjKwxA0PflHuukGcCrriyVQ=; b=cAOdM61KrIXBgl 3j2EMAmpUFAvJ4FgKCFZqO01GUI/SFYeFYzpK7wg3Mi5wKvHbxsr7RbJRT30F/ZkIc6nP8dX8M9Rm bU+IixwkHoHXvseqKRm7WNzFMqE2e88hvUKFbisVhF8EV0gWE6PUa0poDqUKU3oop+Y70eGvjRUSy jwJKuS97d7kvvedFr/brHNAJZuGMvWO5NKxx1mc2yNWvqvJhbAGOx397eSFAwSvtEBNEJNIbU18Om bK0eWZbplU3xbAd9+tCkdAyYHCZBwFxM0pTrD2NhdNkqjAvy+EyPBye4H8Ln3uUxtKbo0OYHrF69Z HDeQlbKKhnLSwxQYMP9A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9kvR-0008Em-Nz; Tue, 09 Oct 2018 05:51:21 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9ksa-0005lJ-KH for linux-arm-kernel@lists.infradead.org; Tue, 09 Oct 2018 05:48:41 +0000 Received: by mail-pl1-x642.google.com with SMTP id s4-v6so256060plp.0 for ; Mon, 08 Oct 2018 22:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HUriwkHyLvnR6PfOR/IGT3CTgX/2scA9IP2awmjlhNg=; b=uWYR81tWObB0a4RNo9BrUcBqCzZcJgRPoeZCBXo/pWQZrEineujy7zUB3WTRaoN0Pj EOrEy1E/xrZvrfSnUtMVONVfcxl4TXW2LD4TWlUlV3aVzx7B0lyzmHBP03SeAo7SIBYb KDMqTVMPFocag8zgmVOUKZVQQmWu52QdUxb7c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HUriwkHyLvnR6PfOR/IGT3CTgX/2scA9IP2awmjlhNg=; b=QfI1AMAHbCVTvtByU9IFSAGAfyUuN6ly2NxKdumiOZ317lu74aqNrmYqsBytUfkXKa 2UmaA+VyaIoUiaIlnPfPAPZSeGqIttqYQ0T23TrwUUseMxJ4fW/lpgLyfwJz85OPoa6h sA9M/A+vkTTvsf3M8BtaohhAWG9ZNvwQ4UB+rfr6E5jo9oA0bP3xgr7fEe/YaG0eNQmQ rRZlbAFCuWSxTEkbaK64aj/JeNG2xWWSAhyqvPsBepsNnu051feIBt1uJy3zxbizDXyo TIBZFrWhJ+PJtEJYYSQGNPF9eDI3iBNhS8R/qYXFKgHYbTqj5unAuCb14ycmphIKTO2M QQjA== X-Gm-Message-State: ABuFfojkRpyB/go+i4QGZIJAIGoXc1rlpOKl+hD5+CzzUbydMCN0m5DR puTs9f2+BdJf2fVk4ju35jqGvA== X-Google-Smtp-Source: ACcGV61n0c+VbTj7yWqStK2eKWDmJ1dD6rYcg2o4jH6PZOroiMKqXdoK8Hi7z6fVU+zvRIfy+65I7w== X-Received: by 2002:a17:902:7109:: with SMTP id a9-v6mr26985609pll.310.1539064093897; Mon, 08 Oct 2018 22:48:13 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id a15-v6sm16886234pff.8.2018.10.08.22.48.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 22:48:12 -0700 (PDT) From: "Joel Fernandes (Google)" To: stable@vger.kernel.org Subject: [PATCH 5/7] dmaengine: stm32-dma: fix DMA IRQ status handling Date: Mon, 8 Oct 2018 22:47:50 -0700 Message-Id: <20181009054752.145978-6-joel@joelfernandes.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20181009054752.145978-1-joel@joelfernandes.org> References: <20181009054752.145978-1-joel@joelfernandes.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181008_224824_774167_5A2FD97F X-CRM114-Status: GOOD ( 12.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Torgue , Vinod Koul , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Pierre Yves MORDRET , "Joel Fernandes \(Google\)" , Maxime Coquelin , dmaengine@vger.kernel.org, Dan Williams , "moderated list:ARM/STM32 ARCHITECTURE" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pierre Yves MORDRET Update the way Transfer Complete and Half Transfer Complete status are acknowledge. Even if HTI is not enabled its status is shown when reading registers, driver has to clear it gently and not raise an error. Signed-off-by: Pierre-Yves MORDRET Signed-off-by: Vinod Koul --- drivers/dma/stm32-dma.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index 21ad359a5a59..b40486454a2c 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -34,9 +34,14 @@ #define STM32_DMA_LIFCR 0x0008 /* DMA Low Int Flag Clear Reg */ #define STM32_DMA_HIFCR 0x000c /* DMA High Int Flag Clear Reg */ #define STM32_DMA_TCI BIT(5) /* Transfer Complete Interrupt */ +#define STM32_DMA_HTI BIT(4) /* Half Transfer Interrupt */ #define STM32_DMA_TEI BIT(3) /* Transfer Error Interrupt */ #define STM32_DMA_DMEI BIT(2) /* Direct Mode Error Interrupt */ #define STM32_DMA_FEI BIT(0) /* FIFO Error Interrupt */ +#define STM32_DMA_MASKI (STM32_DMA_TCI \ + | STM32_DMA_TEI \ + | STM32_DMA_DMEI \ + | STM32_DMA_FEI) /* DMA Stream x Configuration Register */ #define STM32_DMA_SCR(x) (0x0010 + 0x18 * (x)) /* x = 0..7 */ @@ -643,13 +648,29 @@ static irqreturn_t stm32_dma_chan_irq(int irq, void *devid) status = stm32_dma_irq_status(chan); scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id)); - if ((status & STM32_DMA_TCI) && (scr & STM32_DMA_SCR_TCIE)) { + if (status & STM32_DMA_TCI) { stm32_dma_irq_clear(chan, STM32_DMA_TCI); - stm32_dma_handle_chan_done(chan); - - } else { + if (scr & STM32_DMA_SCR_TCIE) + stm32_dma_handle_chan_done(chan); + status &= ~STM32_DMA_TCI; + } + if (status & STM32_DMA_HTI) { + stm32_dma_irq_clear(chan, STM32_DMA_HTI); + status &= ~STM32_DMA_HTI; + } + if (status & STM32_DMA_FEI) { + stm32_dma_irq_clear(chan, STM32_DMA_FEI); + status &= ~STM32_DMA_FEI; + if (!(scr & STM32_DMA_SCR_EN)) + dev_err(chan2dev(chan), "FIFO Error\n"); + else + dev_dbg(chan2dev(chan), "FIFO over/underrun\n"); + } + if (status) { stm32_dma_irq_clear(chan, status); dev_err(chan2dev(chan), "DMA error: status=0x%08x\n", status); + if (!(scr & STM32_DMA_SCR_EN)) + dev_err(chan2dev(chan), "chan disabled by HW\n"); } spin_unlock(&chan->vchan.lock); From patchwork Tue Oct 9 05:47:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10631957 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC605933 for ; Tue, 9 Oct 2018 05:53:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA11F28A5B for ; Tue, 9 Oct 2018 05:53:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA67D28A5F; Tue, 9 Oct 2018 05:53:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 43F3F28A5B for ; Tue, 9 Oct 2018 05:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Zu8lhjrRCPwVwBk7Au2RnAkaT0Jh4SOVrZGbR/pAOuo=; b=cmcno9BPZljm4V f7r4gm0CUM/xNNa5kAc3aBWon3NNz+LpkWtymOeg4879rZoPppMFAsOlauoJbqB+vuNo1rF3qyB5/ WwLtrGjfQzmuh+4HsqNuHbP3LpdsIxP7QwD+kl4V6sABT9RUmNmjFyJjC7CrXrEF2uHPKG4Mze1y0 bysYvHqHO4lxpzQh98YDL72gQx1dHerb0rFzJTR3YcBJ1kizro8YiC2CTc419G2CaBRSBRTqwHkNK Zv2BcedH2ixcvQNmmox8eSy8FQlBSN+ZORkaxgCImPby9VhHNcPvUqTe700NuuSlHd8ckTVjdDII7 8gHvLlpxa7+ETtozxkTw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9kxX-0000de-8T; Tue, 09 Oct 2018 05:53:31 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9ksc-0005lZ-SU for linux-arm-kernel@lists.infradead.org; Tue, 09 Oct 2018 05:48:55 +0000 Received: by mail-pl1-x641.google.com with SMTP id w14-v6so245357plp.6 for ; Mon, 08 Oct 2018 22:48:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X9Pi7kVseJCqn/XAAguX5FsfI2og3DoGIlIZ/tzzQ3U=; b=LS3IMq7Js5UbwUJ/6XVmpfNBh8RhR80Di9PEgmDQg/k0wz9eZhmCky8McL5u5N9+IX 9PzaaFLsu40ymIvYu2pdjowlF4DgQi3lr1rddt6JZ+WH3rtkSLZ+RdyyJBJQiTnTRNv7 MIhzWjTQ6pwa9suwuF2+Bg0xPFuQecllgZjF8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X9Pi7kVseJCqn/XAAguX5FsfI2og3DoGIlIZ/tzzQ3U=; b=aJIBhi9GskiwQalGS3CLLnBLckoCJCffRtZh4LvyQt6XlAdHd00tJ7UrpEes9JqOTL iK0Ry3xjI2v8+ZphRssjvipS1Z5yzex4uJo4GXeNpmRVEM42AYgaySZ0jciSX9RVpMYl Tnkko7eqCAyOX1B5DvzuhE/M7GNiJCl5YlUapNza75WdNwHWr/+ojRsej+NPIq9Fzyoq WdW51C6WVVFPZ9E0dnL2+X0XsjvIRuKAOcTLSOYVzkOMB1Hu4p2Qv8OQ77PsXDZSI9IT am3mDqZ87yp0e7C9s6DJ9ZpXUINohH8wQc5U0nm748y6aXdqfPk/PZ0OJxAtbRrIOrdW BduA== X-Gm-Message-State: ABuFfoiTumX5OdQ7Ig/KtzSE5Gb9CQ7nvgl5pWzW+eqIdvGzJWq/0fU0 ZimHLvYw9wQkxpaNreUYvyOQMw== X-Google-Smtp-Source: ACcGV60cXp1emE3xFoWYJ8jVXiCRV+8TyYtWQzEho2WnBUiE8RJPqtQsGUFrfg+bytt4NkKjcHXKbA== X-Received: by 2002:a17:902:2f41:: with SMTP id s59-v6mr26811116plb.240.1539064095841; Mon, 08 Oct 2018 22:48:15 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id a15-v6sm16886234pff.8.2018.10.08.22.48.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 22:48:14 -0700 (PDT) From: "Joel Fernandes (Google)" To: stable@vger.kernel.org Subject: [PATCH 6/7] dmaengine: stm32-dma: fix max items per transfer Date: Mon, 8 Oct 2018 22:47:51 -0700 Message-Id: <20181009054752.145978-7-joel@joelfernandes.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20181009054752.145978-1-joel@joelfernandes.org> References: <20181009054752.145978-1-joel@joelfernandes.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181008_224827_019199_AE05F367 X-CRM114-Status: GOOD ( 14.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Torgue , Vinod Koul , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Pierre Yves MORDRET , "Joel Fernandes \(Google\)" , Maxime Coquelin , dmaengine@vger.kernel.org, Dan Williams , "moderated list:ARM/STM32 ARCHITECTURE" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pierre Yves MORDRET Having 0 in item counter register is valid and stands for a "No or Ended transfer". Therefore valid transfer starts from @+0 to @+0xFFFE leading to unaligned scatter gather at boundary. Thus it's safer to round down this value on its FIFO size (16 Bytes). Signed-off-by: Pierre-Yves MORDRET Signed-off-by: Vinod Koul --- drivers/dma/stm32-dma.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index b40486454a2c..05a2974cd2c0 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -38,10 +38,6 @@ #define STM32_DMA_TEI BIT(3) /* Transfer Error Interrupt */ #define STM32_DMA_DMEI BIT(2) /* Direct Mode Error Interrupt */ #define STM32_DMA_FEI BIT(0) /* FIFO Error Interrupt */ -#define STM32_DMA_MASKI (STM32_DMA_TCI \ - | STM32_DMA_TEI \ - | STM32_DMA_DMEI \ - | STM32_DMA_FEI) /* DMA Stream x Configuration Register */ #define STM32_DMA_SCR(x) (0x0010 + 0x18 * (x)) /* x = 0..7 */ @@ -118,6 +114,13 @@ #define STM32_DMA_FIFO_THRESHOLD_FULL 0x03 #define STM32_DMA_MAX_DATA_ITEMS 0xffff +/* + * Valid transfer starts from @0 to @0xFFFE leading to unaligned scatter + * gather at boundary. Thus it's safer to round down this value on FIFO + * size (16 Bytes) + */ +#define STM32_DMA_ALIGNED_MAX_DATA_ITEMS \ + ALIGN_DOWN(STM32_DMA_MAX_DATA_ITEMS, 16) #define STM32_DMA_MAX_CHANNELS 0x08 #define STM32_DMA_MAX_REQUEST_ID 0x08 #define STM32_DMA_MAX_DATA_PARAM 0x03 @@ -869,7 +872,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_slave_sg( desc->sg_req[i].len = sg_dma_len(sg); nb_data_items = desc->sg_req[i].len / buswidth; - if (nb_data_items > STM32_DMA_MAX_DATA_ITEMS) { + if (nb_data_items > STM32_DMA_ALIGNED_MAX_DATA_ITEMS) { dev_err(chan2dev(chan), "nb items not supported\n"); goto err; } @@ -935,7 +938,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_cyclic( return NULL; nb_data_items = period_len / buswidth; - if (nb_data_items > STM32_DMA_MAX_DATA_ITEMS) { + if (nb_data_items > STM32_DMA_ALIGNED_MAX_DATA_ITEMS) { dev_err(chan2dev(chan), "number of items not supported\n"); return NULL; } @@ -985,7 +988,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy( u32 num_sgs, best_burst, dma_burst, threshold; int i; - num_sgs = DIV_ROUND_UP(len, STM32_DMA_MAX_DATA_ITEMS); + num_sgs = DIV_ROUND_UP(len, STM32_DMA_ALIGNED_MAX_DATA_ITEMS); desc = stm32_dma_alloc_desc(num_sgs); if (!desc) return NULL; @@ -994,7 +997,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy( for (offset = 0, i = 0; offset < len; offset += xfer_count, i++) { xfer_count = min_t(size_t, len - offset, - STM32_DMA_MAX_DATA_ITEMS); + STM32_DMA_ALIGNED_MAX_DATA_ITEMS); /* Compute best burst size */ max_width = DMA_SLAVE_BUSWIDTH_1_BYTE; From patchwork Tue Oct 9 05:47:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10631953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5254933 for ; Tue, 9 Oct 2018 05:52:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B51D12875C for ; Tue, 9 Oct 2018 05:52:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A346C28A4A; Tue, 9 Oct 2018 05:52:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 15D742875C for ; Tue, 9 Oct 2018 05:52:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eOZqQQ4PCLzHeY1LC+cw12egxUmpgXQ7UcNuqFJIy+4=; b=nFDlWxuEpAOS9B Tw2QCBugmsEOxO5S+vZQv+vu1+U2K8dcScDtgP1RElpT8qZ52Gma9UVtaSKD+0OHvpUti9uL9eAVv uSW+mM6hM4VHGU1iBag1L03sHpCJlCvDeEwmHZ8GSohRmEjhlpcy9X9n3kSTWyrrKsy5pdm9gwGOm RJiF7TN0Dv6K88YoX+u3AkxYEDPWj7r7kG39U8hzAHEQ9e2gg6UuaFESb87BUUwIJKT5BrpHBmIbY cH4DmQim6jZ10u2JIZ+CdKpKHjHjMnKdhfXKyaDgtTNoUBv+AbBe6i3X4IuJFodEJJhgas7c8FNmA liGcPeyiUzxQvpBpxAug==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9kw4-0008V2-Ez; Tue, 09 Oct 2018 05:52:00 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9ksa-0005mq-KF for linux-arm-kernel@lists.infradead.org; Tue, 09 Oct 2018 05:48:47 +0000 Received: by mail-pl1-x642.google.com with SMTP id v5-v6so229515plz.13 for ; Mon, 08 Oct 2018 22:48:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z23Tjh1yqMbwhE8WbL7Mv5Y/M073KHw3jtyb5qocoBQ=; b=PbZ1lIJyVyyh3yI53kRy/FLEntyL9v3ClQWBuhzRBKXg78LnoAVfyWFgPJzoIA6L/w w3MOu5KXNdANYv8/7appfJ6EQUa/pkPyPQM50A8cZ1HiwJB6zKHRuhdXLtIkkQmOqYDh LLrEUvZiKGrnGhEON+CkLddhpseaIKTjZOK9Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z23Tjh1yqMbwhE8WbL7Mv5Y/M073KHw3jtyb5qocoBQ=; b=gfPYkaSO9HeY8rbJ7EIDf6L/XdstrNpW32KkRGK4okR7K55IeJZLkPTKboPTLYBL/V RKpDa7r/gYW32UlBYwSRuwBVOGeN3sSVfjQMK54s2lUS3BD7jQayy5dwEC6l7syf/jfF xRfUVyBWYO+UxhzeLO+RzdV2nlYqXZszqrxNqai95e197ppnCLUGDRxcza6dMCOsFOex CL9k6o94ES0SqXvV8omGsSOHmixYd0Tp9wtDrXayjgmdNF2BV5yAOVKic3tVyBOFMVfJ GKRrX+wppNL5qgs5Jfr2jaRcaGI/GUxXf+eGjRw8G99AGArVtGmlkQzckBexeeoHlkIl Olkw== X-Gm-Message-State: ABuFfoj56m3gVZel0q9DombJCsyIjYsGHXbrFOMsi8WMIBvqzBvMpmnI QM6xkx1bUecPiM2DKeCZ7H/LFg== X-Google-Smtp-Source: ACcGV615++WW5p6TKsjmAHxp8EVY43qGKMs9RmF8EHqlvjVJXxxB2ee08QLTfYReCUz3k/aBRJ0SOw== X-Received: by 2002:a17:902:50e3:: with SMTP id c32-v6mr26734108plj.194.1539064097457; Mon, 08 Oct 2018 22:48:17 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id a15-v6sm16886234pff.8.2018.10.08.22.48.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 22:48:16 -0700 (PDT) From: "Joel Fernandes (Google)" To: stable@vger.kernel.org Subject: [PATCH 7/7] dmaengine: stm32-dma: properly mask irq bits Date: Mon, 8 Oct 2018 22:47:52 -0700 Message-Id: <20181009054752.145978-8-joel@joelfernandes.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20181009054752.145978-1-joel@joelfernandes.org> References: <20181009054752.145978-1-joel@joelfernandes.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181008_224824_778631_82286A64 X-CRM114-Status: GOOD ( 13.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Torgue , Vinod Koul , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Pierre Yves MORDRET , Antonio Borneo , "Joel Fernandes \(Google\)" , Maxime Coquelin , dmaengine@vger.kernel.org, Dan Williams , "moderated list:ARM/STM32 ARCHITECTURE" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Pierre Yves MORDRET A single register of the controller holds the information for four dma channels. The functions stm32_dma_irq_status() don't mask the relevant bits after the shift, thus adjacent channel's status is also reported in the returned value. Fixed by masking the value before returning it. Similarly, the function stm32_dma_irq_clear() don't mask the input value before shifting it, thus an incorrect input value could disable the interrupts of adjacent channels. Fixed by masking the input value before using it. Signed-off-by: Pierre-Yves MORDRET Signed-off-by: Antonio Borneo Signed-off-by: Vinod Koul --- drivers/dma/stm32-dma.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index 05a2974cd2c0..8c5807362a25 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -38,6 +38,10 @@ #define STM32_DMA_TEI BIT(3) /* Transfer Error Interrupt */ #define STM32_DMA_DMEI BIT(2) /* Direct Mode Error Interrupt */ #define STM32_DMA_FEI BIT(0) /* FIFO Error Interrupt */ +#define STM32_DMA_MASKI (STM32_DMA_TCI \ + | STM32_DMA_TEI \ + | STM32_DMA_DMEI \ + | STM32_DMA_FEI) /* DMA Stream x Configuration Register */ #define STM32_DMA_SCR(x) (0x0010 + 0x18 * (x)) /* x = 0..7 */ @@ -405,7 +409,7 @@ static u32 stm32_dma_irq_status(struct stm32_dma_chan *chan) flags = dma_isr >> (((chan->id & 2) << 3) | ((chan->id & 1) * 6)); - return flags; + return flags & STM32_DMA_MASKI; } static void stm32_dma_irq_clear(struct stm32_dma_chan *chan, u32 flags) @@ -420,6 +424,7 @@ static void stm32_dma_irq_clear(struct stm32_dma_chan *chan, u32 flags) * If (ch % 4) is 2 or 3, left shift the mask by 16 bits. * If (ch % 4) is 1 or 3, additionally left shift the mask by 6 bits. */ + flags &= STM32_DMA_MASKI; dma_ifcr = flags << (((chan->id & 2) << 3) | ((chan->id & 1) * 6)); if (chan->id & 4)