From patchwork Thu Nov 29 15:45:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 10704785 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 562A913AD for ; Thu, 29 Nov 2018 15:48:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F7392D1AF for ; Thu, 29 Nov 2018 15:48:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B3D32BD60; Thu, 29 Nov 2018 15:48:39 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFC742B55C for ; Thu, 29 Nov 2018 15:48:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728363AbeK3CyY (ORCPT ); Thu, 29 Nov 2018 21:54:24 -0500 Received: from mailout2.hostsharing.net ([83.223.90.233]:47793 "EHLO mailout2.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728272AbeK3CyY (ORCPT ); Thu, 29 Nov 2018 21:54:24 -0500 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by mailout2.hostsharing.net (Postfix) with ESMTPS id 7430E10189B34; Thu, 29 Nov 2018 16:48:34 +0100 (CET) Received: from localhost (unknown [89.246.108.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id 1F3C160171E8; Thu, 29 Nov 2018 16:48:34 +0100 (CET) X-Mailbox-Line: From 16337812c5f93fe69456596a010c18f0117440ca Mon Sep 17 00:00:00 2001 Message-Id: <16337812c5f93fe69456596a010c18f0117440ca.1543505321.git.lukas@wunner.de> In-Reply-To: <110014be1385cf8b3ee599d87f97774f3f05ac2f.1543505321.git.lukas@wunner.de> References: <110014be1385cf8b3ee599d87f97774f3f05ac2f.1543505321.git.lukas@wunner.de> From: Lukas Wunner Date: Thu, 29 Nov 2018 16:45:24 +0100 Subject: [PATCH for-4.21 3/3] spi: bcm2835: Synchronize with callback on DMA termination MIME-Version: 1.0 To: Mark Brown Cc: Eric Anholt , Stefan Wahren , Frank Pavlic , Martin Sperl , Noralf Tronnes , linux-spi@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, Vinod Koul Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit b36f09c3c441 ("dmaengine: Add transfer termination synchronization support") deprecated dmaengine_terminate_all() in favor of dmaengine_terminate_sync() and dmaengine_terminate_async() to avoid freeing resources used by the DMA callback before its execution has concluded. Commit de92436ac40f ("dmaengine: bcm2835-dma: Use vchan_terminate_vdesc() instead of desc_free") amended the BCM2835 DMA driver with an implementation of ->device_synchronize(), which is a prerequisite for dmaengine_terminate_sync(). Thus, clients of the DMA driver (such as the BCM2835 SPI driver) may now be converted to the new API. It is generally desirable to use the _sync() variant except in atomic context. There is only a single occurrence where the BCM2835 SPI driver calls dmaengine_terminate_all() in atomic context and that is in bcm2835_spi_dma_done() (the RX DMA channel's callback) to terminate the TX DMA channel. The TX DMA channel doesn't have a callback (yet), hence it is safe to use the _async() variant there. Signed-off-by: Lukas Wunner Cc: Frank Pavlic Cc: Martin Sperl Cc: Noralf Trønnes Cc: Vinod Koul --- drivers/spi/spi-bcm2835.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index 5af4cf74392c..35aebdfd3b4e 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -514,7 +514,7 @@ static void bcm2835_spi_dma_done(void *data) * situation otherwise... */ if (cmpxchg(&bs->dma_pending, true, false)) { - dmaengine_terminate_all(master->dma_tx); + dmaengine_terminate_async(master->dma_tx); bcm2835_spi_undo_prologue(bs); } @@ -605,7 +605,7 @@ static int bcm2835_spi_transfer_one_dma(struct spi_master *master, ret = bcm2835_spi_prepare_sg(master, tfr, false); if (ret) { /* need to reset on errors */ - dmaengine_terminate_all(master->dma_tx); + dmaengine_terminate_sync(master->dma_tx); bs->dma_pending = false; goto err_reset_hw; } @@ -650,12 +650,12 @@ static bool bcm2835_spi_can_dma(struct spi_master *master, static void bcm2835_dma_release(struct spi_master *master) { if (master->dma_tx) { - dmaengine_terminate_all(master->dma_tx); + dmaengine_terminate_sync(master->dma_tx); dma_release_channel(master->dma_tx); master->dma_tx = NULL; } if (master->dma_rx) { - dmaengine_terminate_all(master->dma_rx); + dmaengine_terminate_sync(master->dma_rx); dma_release_channel(master->dma_rx); master->dma_rx = NULL; } @@ -864,8 +864,8 @@ static void bcm2835_spi_handle_err(struct spi_master *master, /* if an error occurred and we have an active dma, then terminate */ if (cmpxchg(&bs->dma_pending, true, false)) { - dmaengine_terminate_all(master->dma_tx); - dmaengine_terminate_all(master->dma_rx); + dmaengine_terminate_sync(master->dma_tx); + dmaengine_terminate_sync(master->dma_rx); bcm2835_spi_undo_prologue(bs); } /* and reset */