From patchwork Wed Nov 29 16:31:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nam Cao X-Patchwork-Id: 13473196 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F67AC4167B for ; Wed, 29 Nov 2023 16:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kfB3Cazb4mlZhQW4ViPBya93f3GHXVEVfJ+GvAGCwU8=; b=35JJBoVHv0+qv+ mUfQMOK6nZbXtT0XMy4GPggzibxt9hJQxcjf2oiOLiM9h2c8ge/qKgP3dPZKl7X2M3RfKTMvBZHrD lTsA3Wy20feQlQNiglgjwOFOzsckB/w7eLk7CS3qmTWajDPq8iDssRqIzvK7FJehLYZ4vylmHbRTQ dNSCGCS2eOZNFLW0loL7W9Jo1/USpgeBEzXJwXGuAtl4AFOCxMIhoft7cBRwVeieLJ+D1nerA1+e/ clDOY+nTBZYJ8wfVWZST3yNgrT3E5D5YkQeO74DwYzKl4Mu19P1Yvr3+LlNDtkRXSfgiA+TpytytG Vu4+RKJc7z0KKl3Hd64g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r8NUI-008tlP-0G; Wed, 29 Nov 2023 16:32:34 +0000 Received: from galois.linutronix.de ([193.142.43.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r8NUE-008tkT-1q for linux-arm-kernel@lists.infradead.org; Wed, 29 Nov 2023 16:32:32 +0000 From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701275548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gTLB0ThBnn/pS6UUkx2HH5EKbiVm5lM2rnyIrBkr1Jo=; b=H1bQ8XuEF942xI+G9ZqJRqKQ3B2FFQApYvp6F4ALDrqkxG9HVD4bb+/74X3Ww1FrjOjdqS 5tkCduWI8+MYUw8G53XpUJqrI6p0+Zk9wew+pkXZdROi/EiOHjn47vYifynqiXiKPQS1DH tR/kn23pB+uvYzG/TSrfhr/zSnTOOQyuBmXR5euAPDpOvpsT8+qMJK4Ar2UUSCUiRv7m6Y tie5qXYC5LZhZ0xDsc8MsNYeG40v1LCpuC/FaSnXkD5cwxndGFRKbHaVTvRrjyd+wZuA09 4wSpbyYaW5QUATAHyyX/tsoWP4ZAjWAYn4xJ+cssyXMDwH6GTXXpv/bJx+OjDA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701275548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gTLB0ThBnn/pS6UUkx2HH5EKbiVm5lM2rnyIrBkr1Jo=; b=sOCVYsOvhKSU1/uBKMPHkYKPx/vPtJ9O6KFYns8bQZW93oRsaP3z/ZXWLZVOdRpUVr9sCA +pT7cslBTCqhq2Ag== To: linus.walleij@linaro.org, broonie@kernel.org, linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH v2 1/2] spi: introduce SPI_TRANS_FAIL_IO for error reporting Date: Wed, 29 Nov 2023 17:31:55 +0100 Message-Id: <4b420dac528e60f122adde16851da88e4798c1ea.1701274975.git.namcao@linutronix.de> In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231129_083230_790284_C02DE2C5 X-CRM114-Status: GOOD ( 13.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The default message transfer implementation - spi_transfer_one_message - invokes the specific device driver's transfer_one(), then waits for completion. However, there is no mechanism for the device driver to report failure in the middle of the transfer. Introduce SPI_TRANS_FAIL_IO for drivers to report transfer failure. Signed-off-by: Nam Cao Acked-by: Linus Walleij --- v2: add document for this new flag drivers/spi/spi.c | 3 +++ include/linux/spi/spi.h | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 8ead7acb99f3..a4b8c07c5951 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1361,6 +1361,9 @@ static int spi_transfer_wait(struct spi_controller *ctlr, "SPI transfer timed out\n"); return -ETIMEDOUT; } + + if (xfer->error & SPI_TRANS_FAIL_IO) + return -EIO; } return 0; diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 7b4baff63c5c..5d65a6273dcf 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -461,10 +461,13 @@ extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 ch * - return 1 if the transfer is still in progress. When * the driver is finished with this transfer it must * call spi_finalize_current_transfer() so the subsystem - * can issue the next transfer. Note: transfer_one and - * transfer_one_message are mutually exclusive; when both - * are set, the generic subsystem does not call your - * transfer_one callback. + * can issue the next transfer. If the transfer fails, the + * driver must set the flag SPI_TRANS_FAIL_IO to + * spi_transfer->error first, before calling + * spi_finalize_current_transfer(). + * Note: transfer_one and transfer_one_message are mutually + * exclusive; when both are set, the generic subsystem does + * not call your transfer_one callback. * @handle_err: the subsystem calls the driver to handle an error that occurs * in the generic implementation of transfer_one_message(). * @mem_ops: optimized/dedicated operations for interactions with SPI memory. @@ -1040,6 +1043,7 @@ struct spi_transfer { unsigned len; #define SPI_TRANS_FAIL_NO_START BIT(0) +#define SPI_TRANS_FAIL_IO BIT(1) u16 error; dma_addr_t tx_dma;