Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 601C4C433F5 for ; Mon, 6 Dec 2021 15:24:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386726AbhLFP1N (ORCPT ); Mon, 6 Dec 2021 10:27:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357132AbhLFPRy (ORCPT ); Mon, 6 Dec 2021 10:17:54 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 065C7C0354AB; Mon, 6 Dec 2021 07:11:11 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C1AA1B810AC; Mon, 6 Dec 2021 15:11:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E904DC341C6; Mon, 6 Dec 2021 15:11:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1638803468; bh=zk1nJ+JAJgqvgtbCyFpi89oSLlS8ZID7/oPsUErH5RQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hIhhM8YBWHppZJcHrzUfrf7ScX9P2kuJ/f2nA+cEuj38bnVAV/+00kTi6VaNZCK0E mgcW+cFIGnQjc+4GlP7ealI9ZZcoe8dNFTnfJyCP3YxnhJpn1Vs+JIlcpOzCA2vIGF SfKPHcQ9Qfnm1AJjFr+Am74tkLA/2inY53UZx0n4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alain Volmat , Pierre-Yves MORDRET , Wolfram Sang Subject: [PATCH 4.19 25/48] i2c: stm32f7: stop dma transfer in case of NACK Date: Mon, 6 Dec 2021 15:56:42 +0100 Message-Id: <20211206145549.711110268@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211206145548.859182340@linuxfoundation.org> References: <20211206145548.859182340@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: Alain Volmat commit 31b90a95ccbbb4b628578ac17e3b3cc8eeacfe31 upstream. In case of receiving a NACK, the dma transfer should be stopped to avoid feeding data into the FIFO. Also ensure to properly return the proper error code and avoid waiting for the end of the dma completion in case of error happening during the transmission. Fixes: 7ecc8cfde553 ("i2c: i2c-stm32f7: Add DMA support") Signed-off-by: Alain Volmat Reviewed-by: Pierre-Yves MORDRET Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/busses/i2c-stm32f7.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/drivers/i2c/busses/i2c-stm32f7.c +++ b/drivers/i2c/busses/i2c-stm32f7.c @@ -1379,6 +1379,7 @@ static irqreturn_t stm32f7_i2c_isr_event { struct stm32f7_i2c_dev *i2c_dev = data; struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; + struct stm32_i2c_dma *dma = i2c_dev->dma; void __iomem *base = i2c_dev->base; u32 status, mask; int ret = IRQ_HANDLED; @@ -1403,6 +1404,10 @@ static irqreturn_t stm32f7_i2c_isr_event if (status & STM32F7_I2C_ISR_NACKF) { dev_dbg(i2c_dev->dev, "<%s>: Receive NACK\n", __func__); writel_relaxed(STM32F7_I2C_ICR_NACKCF, base + STM32F7_I2C_ICR); + if (i2c_dev->use_dma) { + stm32f7_i2c_disable_dma_req(i2c_dev); + dmaengine_terminate_all(dma->chan_using); + } f7_msg->result = -ENXIO; } @@ -1418,7 +1423,7 @@ static irqreturn_t stm32f7_i2c_isr_event /* Clear STOP flag */ writel_relaxed(STM32F7_I2C_ICR_STOPCF, base + STM32F7_I2C_ICR); - if (i2c_dev->use_dma) { + if (i2c_dev->use_dma && !f7_msg->result) { ret = IRQ_WAKE_THREAD; } else { i2c_dev->master_mode = false; @@ -1431,7 +1436,7 @@ static irqreturn_t stm32f7_i2c_isr_event if (f7_msg->stop) { mask = STM32F7_I2C_CR2_STOP; stm32f7_i2c_set_bits(base + STM32F7_I2C_CR2, mask); - } else if (i2c_dev->use_dma) { + } else if (i2c_dev->use_dma && !f7_msg->result) { ret = IRQ_WAKE_THREAD; } else if (f7_msg->smbus) { stm32f7_i2c_smbus_rep_start(i2c_dev);