From patchwork Tue Jun 16 22:42:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Gong X-Patchwork-Id: 11607933 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F2AE6A2 for ; Tue, 16 Jun 2020 14:43:18 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6AD8220A8B for ; Tue, 16 Jun 2020 14:43:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="im9d9rOo"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="J6XPEGEo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6AD8220A8B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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=J3JJJ+YWiTOjs928kUM97U2rWUC/Bv9GnKfB+/j4jTQ=; b=im9d9rOo5XojgN qIZX0fX1zjE2GkmRccMguVd3jnPUenRwmcz3a68XHmL/0uq0DXkpUPjFDElpe44zwoCRjGvRIcwF9 YKxLwGZY3B28N+uFKGKDCz/bQjymYsGYqe1jMAHPtsK10lbBSKuRUwBiis0ZUzwT/CUizpOA4gZs4 xcFHw1Q1mkcN5ViQ0NdyCDI71+ajhOmjuwLkSeNaK6D+ojUNx+eTj3XNjotno462pfB+9Htq2KGcD bnq3ypBq+BMKOz2S9iHCKT263+dS4mgEIjUvAsrYf4MiyF4DQ8aPd/ON2+5M8dONH5IA1YmBta6rM 3MORGraDvieXRtRc2mIA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jlCnt-0002I4-IG; Tue, 16 Jun 2020 14:43:09 +0000 Received: from mail-eopbgr80055.outbound.protection.outlook.com ([40.107.8.55] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jlCnU-0001zN-A8 for linux-arm-kernel@lists.infradead.org; Tue, 16 Jun 2020 14:42:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VO9AfAEVLOuy5nVOWwPX5Pi9yPOavQclDznTljSoUMbKDigh+/UhjUDpKoeRznaIkm90YI+DlLRhqr0ewwB5E6oOpmxapjAOJmERRkIXgOxwEVxrOlTPSTt8gN8PfT+qROXWlKfCBM4eXhwQNiKlkepqK5VDmFMO8PK4DfFURdtbLnBgzBgxdre17wqYrhwr5KEVJBSgKbE9RaHPmpXO/SRO9yku5ZC3tFJ147ykcxVqH+lLGlXxImAaElAUmQZy+BsJSLdWpZfusDuIik386Jr+0sP8YVOzF1ahTyjabcZPixhoZefZPtMzOw7gbKMlK13bJZoQgaIcM/4ixPvDBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oLRyrQ5y3g95W+DVI2Tw8ZLxJDEixDdn2uDjAiK/u+E=; b=amL6XL/VaXS6ayn28d5cwInxQ6eH6re/9e2ikOi1NgrWSXnAG0iVAAinsj0jE6gLn/wzlQGAmu3L8b56EVKkjVTNgwD0k9ENr01IYi4ZoU8GWJuQpUYy7dXY1affNqIFy0Vflg5zK9My3XsN+Zaz48ZWzUoOKXhTTCHZp16A7KR/AFPO95R7E3gNuAVCMPkFHB0rMgeFDX3Ui+Yk8e+AdgxZvar+k6Zt1VGLPsKAw6PBA/c2zIsXPTyzYyzS4vBO2PX8peag2QNsIQcDxc/MMVaDblSuumZCHsxbaF7ssZMVhcK+d/1WeclCkmaD4sCIlUOtKZnrZTFYj2afpHKm8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oLRyrQ5y3g95W+DVI2Tw8ZLxJDEixDdn2uDjAiK/u+E=; b=J6XPEGEoIjlHUmVr2IQ3LGmmJlPvGXstqfp3HWSrMihMA1i31C7+sl8dlLRsTi4aK+65qVCZHhW+oPmG8o+vfBO203fDXA+MrSk1MaSlYSkbAZ6D3Eh689r6T+xr7MYeCyVTZ0yjxDu35bfaLuO1PtcmL6q8l+WDNCikNCTDCZs= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VE1PR04MB6638.eurprd04.prod.outlook.com (2603:10a6:803:119::15) by VE1PR04MB6623.eurprd04.prod.outlook.com (2603:10a6:803:125::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.24; Tue, 16 Jun 2020 14:42:40 +0000 Received: from VE1PR04MB6638.eurprd04.prod.outlook.com ([fe80::5cc4:23a5:ca17:da7d]) by VE1PR04MB6638.eurprd04.prod.outlook.com ([fe80::5cc4:23a5:ca17:da7d%6]) with mapi id 15.20.3088.028; Tue, 16 Jun 2020 14:42:40 +0000 From: Robin Gong To: broonie@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, robin.murphy@arm.com, matthias.schiffer@ew.tq-group.com Subject: [PATCH v2 1/2] spi: introduce fallback to pio Date: Wed, 17 Jun 2020 06:42:08 +0800 Message-Id: <1592347329-28363-2-git-send-email-yibin.gong@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1592347329-28363-1-git-send-email-yibin.gong@nxp.com> References: <1592347329-28363-1-git-send-email-yibin.gong@nxp.com> X-ClientProxiedBy: SG2PR06CA0163.apcprd06.prod.outlook.com (2603:1096:1:1e::17) To VE1PR04MB6638.eurprd04.prod.outlook.com (2603:10a6:803:119::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from robin-OptiPlex-790.ap.freescale.net (119.31.174.66) by SG2PR06CA0163.apcprd06.prod.outlook.com (2603:1096:1:1e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3109.21 via Frontend Transport; Tue, 16 Jun 2020 14:42:37 +0000 X-Mailer: git-send-email 2.7.4 X-Originating-IP: [119.31.174.66] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8d1c0c6d-7af3-43e0-716a-08d812038564 X-MS-TrafficTypeDiagnostic: VE1PR04MB6623: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-Forefront-PRVS: 04362AC73B X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9tyLrxoD6X4Uki2YDB/S9E7XkCtrsJFonUsPgIP9DkZA3S9bUXSNRcNSn2czdQEmVUaaW/Gizcp6zsHQvAsFjhdqPSSxfh4Hru29d5t2Oo5MbwOcIV0lbVMX0gVdrb50LOb4UqNR9am2qdkGcExicTlTw1dmIceIvRenf0ZOvcaSPTlvUZAanCCsYCfoKZqFufFGRzas+m6wpLWr41GZPqztpgY0FtVgtjDzbdxJ2BTDSxIEx3TO0Wt0WDaQ40KjLGocHkx3xv/KzWp+Kv8ydE3SoHWbklPqZj8+m82SYqqCWoq0Y2nmzotMn0nL54BkHSa2F9jAyxPzWGDqdkBd1w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6638.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(366004)(8936002)(6512007)(6506007)(66946007)(66556008)(8676002)(4326008)(66476007)(498600001)(186003)(16526019)(86362001)(2906002)(83380400001)(6486002)(26005)(52116002)(36756003)(5660300002)(7416002)(2616005)(6666004)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: QFkYbXSzftPozic39eAceOOx3vLBtRUbARB77WCM0nAVOJA64Ci5vPtYX9Njo5L+5Vu7jJMSrSABNdaEEF5ZHgIO5V7i67yMsS32jQ7KTlhuOjJ8j7bVve6OpC/9uPswJUD/Vrg4i1e2sKFPDRx8C3bSvMyaJ98cCEGcBCdi1N19JcJGximBjCO/s3l5m+B2feIf9t5yC6w+YgUjm3z62cWoHgF+KS8t8iTXyCxP69igXoHy5qzOE9tEZtFWqpjRYtM0EL++1fOVA6PkZmPuUJPeTL5tzvLUmDQHDGbGZdyxcKb/9SYNl0zVdu+O2kjOZ1FDN3GHMe8Ao6Vd+0w7OgGBqF+R8j7np5uSGS7bdEN5Oopot3yignM7Dd6Tabo1Zdv3GGRXax0mU+xkfI5HvgyKLbvD31CqQfmz4wcOkdg+xzEIGz0AAJCVwc+UkJ+KxgRVWSJa5Di8HpjAPWvk2dQzhrZR9kwB2V4s2YdJHrs= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8d1c0c6d-7af3-43e0-716a-08d812038564 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2020 14:42:40.8547 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: M/7tG3bokG7qyP3RGzTbBm6VLEqB5hXrVNb8ckXGUgGJCb95iX9N4zWSAjwJILTEBQxARnExiHKGtoIs3tYuDw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6623 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200616_074244_371777_4BA43593 X-CRM114-Status: GOOD ( 15.15 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [40.107.8.55 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [40.107.8.55 listed in wl.mailspike.net] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.0 DATE_IN_FUTURE_06_12 Date: is 6 to 12 hours after Received: date -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com, kernel@pengutronix.de, linux-spi@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add fallback to pio mode in case dma transfer failed with error status SPI_TRANS_FAIL_NO_START. If spi client driver want to enable this feature please set xfer->error in the proper place such as dmaengine_prep_slave_sg() failure detect(but no any data put into spi bus yet). Besides, add master->fallback checking in its can_dma() so that spi core could switch to pio next time. Please refer to spi-imx.c. Signed-off-by: Robin Gong --- drivers/spi/spi.c | 12 ++++++++++++ include/linux/spi/spi.h | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 8158e28..6fa5659 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -982,6 +982,8 @@ static int __spi_unmap_msg(struct spi_controller *ctlr, struct spi_message *msg) spi_unmap_buf(ctlr, tx_dev, &xfer->tx_sg, DMA_TO_DEVICE); } + ctlr->cur_msg_mapped = false; + return 0; } #else /* !CONFIG_HAS_DMA */ @@ -1234,8 +1236,17 @@ static int spi_transfer_one_message(struct spi_controller *ctlr, if (xfer->tx_buf || xfer->rx_buf) { reinit_completion(&ctlr->xfer_completion); +fallback_pio: ret = ctlr->transfer_one(ctlr, msg->spi, xfer); if (ret < 0) { + if (ctlr->cur_msg_mapped && + (xfer->error & SPI_TRANS_FAIL_NO_START)) { + __spi_unmap_msg(ctlr, msg); + ctlr->fallback = true; + xfer->error &= ~SPI_TRANS_FAIL_NO_START; + goto fallback_pio; + } + SPI_STATISTICS_INCREMENT_FIELD(statm, errors); SPI_STATISTICS_INCREMENT_FIELD(stats, @@ -1693,6 +1704,7 @@ void spi_finalize_current_message(struct spi_controller *ctlr) spin_lock_irqsave(&ctlr->queue_lock, flags); ctlr->cur_msg = NULL; ctlr->cur_msg_prepared = false; + ctlr->fallback = false; kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages); spin_unlock_irqrestore(&ctlr->queue_lock, flags); diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index aac57b5..b4917df 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -447,6 +447,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) * If the driver does not set this, the SPI core takes the snapshot as * close to the driver hand-over as possible. * @irq_flags: Interrupt enable state during PTP system timestamping + * @fallback: fallback to pio if dma transfer return failure with + * SPI_TRANS_FAIL_NO_START. * * Each SPI controller can communicate with one or more @spi_device * children. These make a small bus, sharing MOSI, MISO and SCK signals @@ -602,6 +604,7 @@ struct spi_controller { bool auto_runtime_pm; bool cur_msg_prepared; bool cur_msg_mapped; + bool fallback; struct completion xfer_completion; size_t max_dma_len; @@ -847,6 +850,7 @@ extern void spi_res_release(struct spi_controller *ctlr, * back unset and they need the better resolution. * @timestamped_post: See above. The reason why both exist is that these * booleans are also used to keep state in the core SPI logic. + * @error: Error status logged by spi controller driver. * * SPI transfers always write the same number of bytes as they read. * Protocol drivers should always provide @rx_buf and/or @tx_buf. @@ -940,6 +944,9 @@ struct spi_transfer { bool timestamped; struct list_head transfer_list; + +#define SPI_TRANS_FAIL_NO_START BIT(0) + u16 error; }; /** From patchwork Tue Jun 16 22:42:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Gong X-Patchwork-Id: 11607935 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 987A96A2 for ; Tue, 16 Jun 2020 14:43:38 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7603D20882 for ; Tue, 16 Jun 2020 14:43:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AJaADk4/"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="cubxPXIC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7603D20882 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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=+msMbEJ5IGCZAukrnvM0RehyRc64bMSXn3lYep4x0+0=; b=AJaADk4/4iV+EO GuCLLgLPQEu8ciOtcoIK7lLUa2vTxNUbK6LZoxG9ZaCjx4IYXtd6VaTd/iJI9RtNZv8+zWdeopzkR 7YVOgmQcuy7ilZGY9RD7JQvMdSUH+004BbrrDJuBAl7CVH7RKe2lsv2WWGY86ye8bWzemXjAx54kb hYyWLdjXNTG+x4WhrZ6d5WKS//NztsgJphKS+0oRewROXnGR0y+HpPg/ofesp6JmyBsOmlB0vkDKe EgSC4Iat3Lvbs34JVz7bDgNJ7pZvlFOnPqabwCQdQlzcjXGYJMdShNn9a3tsvJqbg68Zj0ZEkf+nX NEgmXg9uPN3ZlzLGFP8w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jlCoE-0002XC-4p; Tue, 16 Jun 2020 14:43:30 +0000 Received: from mail-eopbgr80059.outbound.protection.outlook.com ([40.107.8.59] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jlCnb-000259-UT for linux-arm-kernel@lists.infradead.org; Tue, 16 Jun 2020 14:43:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BPFjd78Wktwm6XioOjxlAnCLDXcwck/s0R8gmKU0GCU9pRaZ+uI9xca/1Z5obxBUibfqo3YCsIXDjwGufCZOF6YFSSPVGoltOGF0+eAzBa5WfBNARGcL/fBVl44AlQaRo8Sm80pUwPdN5dwXJjdLtzL57OxJ8+GuRkFgMapfORMfuh9SZvDmdnBQxwKMYWcg0ExAGYMTfIDwwkOQR5txNJtfB/m0NeQGZw5uZmOzUvpC2Xf3YxEHQG24V7/RXLLxBj1qOwwQsSTPMU59rIYb+f/sAaDrI9DHtAESX+Rfv6eqh1DoPz+wkowiiQlBFIMtV4a8xc35JPceTUIBTuxgZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BWD0C4nag/n17IHZIAleGqEk3ypshR7pobGoU1GZAI0=; b=M5VMpNva1ZeTUI63HX3xqBXKxu6sOVfiEEd1mTB8tWa3HNPC7IOsOPGVNIcc3d0/XTDl374N4eEtuSHDRSiXHmusVWCYn3qJhj+JKHoJqiUkjPaw2ekcT2beZtcdX3oJ03CBxbNC6ee6PTTYHWQ6IXnYpd12KU7MWIYA+ALhoODSx99S0xfF1G0Nh2wEzV2ll7auB2TXgAArIrKwVL4nW38XNNmFWZ8ttnJPPuI9WmAq9FJlgpFvbGvS01nhg+yA+uFjvD4AcGoNLFBU9q69CLgWV81K6Mgv32vLr+L/PorTz0JtTawLA/oScPVcQsqUKV68D6zRVV1jngOBlcW9Uw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BWD0C4nag/n17IHZIAleGqEk3ypshR7pobGoU1GZAI0=; b=cubxPXICtEw1lFbOzy/qZ6Z9qr+enCZzXZ/u0/rzROd7b1ZM304OBtL63rmazo+/7O7ONxMDofAxl+zlRa2sywQ//ex5k3NjxJvseT65fng8DGonyLQs9fJ9f4abnq75hN5yLEMQYD729vbquKTFWt0zbwB7E1Pjf3NyqjSy91M= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VE1PR04MB6638.eurprd04.prod.outlook.com (2603:10a6:803:119::15) by VE1PR04MB6623.eurprd04.prod.outlook.com (2603:10a6:803:125::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.24; Tue, 16 Jun 2020 14:42:48 +0000 Received: from VE1PR04MB6638.eurprd04.prod.outlook.com ([fe80::5cc4:23a5:ca17:da7d]) by VE1PR04MB6638.eurprd04.prod.outlook.com ([fe80::5cc4:23a5:ca17:da7d%6]) with mapi id 15.20.3088.028; Tue, 16 Jun 2020 14:42:48 +0000 From: Robin Gong To: broonie@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, robin.murphy@arm.com, matthias.schiffer@ew.tq-group.com Subject: [PATCH v2 2/2] spi: imx: add fallback feature Date: Wed, 17 Jun 2020 06:42:09 +0800 Message-Id: <1592347329-28363-3-git-send-email-yibin.gong@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1592347329-28363-1-git-send-email-yibin.gong@nxp.com> References: <1592347329-28363-1-git-send-email-yibin.gong@nxp.com> X-ClientProxiedBy: SG2PR06CA0163.apcprd06.prod.outlook.com (2603:1096:1:1e::17) To VE1PR04MB6638.eurprd04.prod.outlook.com (2603:10a6:803:119::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from robin-OptiPlex-790.ap.freescale.net (119.31.174.66) by SG2PR06CA0163.apcprd06.prod.outlook.com (2603:1096:1:1e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3109.21 via Frontend Transport; Tue, 16 Jun 2020 14:42:45 +0000 X-Mailer: git-send-email 2.7.4 X-Originating-IP: [119.31.174.66] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: bf07b327-f169-4980-e1e8-08d812038a0f X-MS-TrafficTypeDiagnostic: VE1PR04MB6623: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:597; X-Forefront-PRVS: 04362AC73B X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DIj/4MADuq49/noAjeuFxqjRxTbcKC7nqBbXp9iEy2463fcZTzQIXm7y4cB3N85Rwwsgyyk/JZbmB5BTR5D5pzHuk60D2zxhshCv4GFDFlayp5Ad30BgbKmlnqVZBDyq4IFA7pdOc4oi7oFldWIK/bsNCBXuiYgcdJi4WTl4eWWoGHXU2fLiTgNMIYXab9XhTHSO/kMDVo90C1XIJwd7qHd3/lmFNA47uWBjGIlBGTxFozJ87BARnO+oGaBlYmd/MC9VRze5U7JCaqrvcL67Jtd42xj6mcVQGrAIAqxCJHB9smCY1pGeUa/xZGxzeqAFTwGehJOH33FDDrdpVMrOhw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6638.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(366004)(8936002)(6512007)(6506007)(66946007)(66556008)(8676002)(4326008)(66476007)(498600001)(186003)(16526019)(86362001)(2906002)(83380400001)(6486002)(26005)(52116002)(36756003)(5660300002)(7416002)(2616005)(6666004)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: UNYLPLHVhD+Gc689JFfECxKaTFTd4dp0Img25I0JOYNkAFpHxjw22teliZ3Ik6Uhi15WlpSQuSMjwx8llNDBPzxXLZUvBHi73aE1CoinWC1HEo7uw2npCN8NBYmP9NwXKbCw6pCCRFJNJl+8OUAdxb9y5dWTy4jg91sgMwI6wFT2zxq69eFwFiKdF+aicq3rqbdYGINLLubJwb2RqcgdA/h0kPZ2SGicyNJlC7N1Zn2Eq0JqnKBncvKBUMQIDkNWF/3MpjHRFIkcz8Ok+sd7rYvSWpfGVbZSXadCTiJ9IlwYRNY4HGwQWak02KBMCILR/vORHTXBUIyeQLH1CASZeXd5k8BazJR6toN1uZUYiKny5VfwBwMtxPSQUwZAiSbwCBEvi3PjkefR7Hh+YWNaL5YLn0uuU6Yze+eyr7pbXWKvyw7hHESL3yX858KGwnSbX4knsPbtFYLnLKalPPJX9YJplwRbe3YyNkGMAFyewvePwn3732Nlbzqzi5XZbYPi X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: bf07b327-f169-4980-e1e8-08d812038a0f X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2020 14:42:48.5802 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: V+pzcmYib8kkVR9Is9sLUQWLAx6L9UOb2jMaM3a81xKbyvsd+MqvDlNfYRxQCZhLw7lRyo+qED5YCTEcJ/GFFA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6623 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200616_074252_025190_7C366376 X-CRM114-Status: GOOD ( 13.03 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [40.107.8.59 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [40.107.8.59 listed in wl.mailspike.net] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.0 DATE_IN_FUTURE_06_12 Date: is 6 to 12 hours after Received: date -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com, kernel@pengutronix.de, linux-spi@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add fallback pio feature in case dma transfer failed before start. Besides, another whole pio transfer including setup_transfer will be issued by spi core, no need to restore jobs like commit bcd8e7761ec9 ("spi: imx: fallback to PIO if dma setup failure"). Signed-off-by: Robin Gong --- drivers/spi/spi-imx.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index b7a85e3..2b8d339 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -224,7 +224,7 @@ static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi, { struct spi_imx_data *spi_imx = spi_master_get_devdata(master); - if (!use_dma) + if (!use_dma || master->fallback) return false; if (!master->dma_rx) @@ -1364,11 +1364,12 @@ static int spi_imx_dma_transfer(struct spi_imx_data *spi_imx, ret = spi_imx_dma_configure(master); if (ret) - return ret; + goto dma_failure_no_start; if (!spi_imx->devtype_data->setup_wml) { dev_err(spi_imx->dev, "No setup_wml()?\n"); - return -EINVAL; + ret = -EINVAL; + goto dma_failure_no_start; } spi_imx->devtype_data->setup_wml(spi_imx); @@ -1379,8 +1380,10 @@ static int spi_imx_dma_transfer(struct spi_imx_data *spi_imx, desc_rx = dmaengine_prep_slave_sg(master->dma_rx, rx->sgl, rx->nents, DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); - if (!desc_rx) - return -EINVAL; + if (!desc_rx) { + ret = -EINVAL; + goto dma_failure_no_start; + } desc_rx->callback = spi_imx_dma_rx_callback; desc_rx->callback_param = (void *)spi_imx; @@ -1425,6 +1428,10 @@ static int spi_imx_dma_transfer(struct spi_imx_data *spi_imx, } return transfer->len; +/* fallback to pio */ +dma_failure_no_start: + transfer->error |= SPI_TRANS_FAIL_NO_START; + return ret; } static int spi_imx_pio_transfer(struct spi_device *spi, @@ -1507,7 +1514,6 @@ static int spi_imx_transfer(struct spi_device *spi, struct spi_transfer *transfer) { struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); - int ret; /* flush rxfifo before transfer */ while (spi_imx->devtype_data->rx_available(spi_imx)) @@ -1516,21 +1522,8 @@ static int spi_imx_transfer(struct spi_device *spi, if (spi_imx->slave_mode) return spi_imx_pio_transfer_slave(spi, transfer); - /* - * fallback PIO mode if dma setup error happen, for example sdma - * firmware may not be updated as ERR009165 required. - */ - if (spi_imx->usedma) { - ret = spi_imx_dma_transfer(spi_imx, transfer); - if (ret != -EINVAL) - return ret; - - spi_imx->devtype_data->disable_dma(spi_imx); - - spi_imx->usedma = false; - spi_imx->dynamic_burst = spi_imx->devtype_data->dynamic_burst; - dev_dbg(&spi->dev, "Fallback to PIO mode\n"); - } + if (spi_imx->usedma) + return spi_imx_dma_transfer(spi_imx, transfer); return spi_imx_pio_transfer(spi, transfer); }