From nobody Fri Dec 19 12:16:35 2025 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013007.outbound.protection.outlook.com [40.93.196.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1718B340D9D; Tue, 28 Oct 2025 15:57:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.7 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761667061; cv=fail; b=lUPjt/BFMoRd/BGHTnpcJzHpJWD+uhSWzzcixwYvOwhhK23EdBk1s1WXEso4c1ddff6dR/x9UmorD7Ji4w1mxiDJyWJ0wFbbNi5pBnULL87pF4iDOyxIGBo6zCD3qyP8F2ABmf1nFkaiKzYvpD699iEDpLTdWzc8kNQp3iK61Ec= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761667061; c=relaxed/simple; bh=IGJwx5jK6OrH2M+NWR/c/WMMpQtLjfOir2T4kGyAkIs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NzPT8oYsgMarvszdfWHCpuTjRcNFjvsILcZZ748jfwByRKuj/msWbIS/VlWWMzlFrywHM4gDTBsXwGSpmgUln7D28YD8eK2c6lcnBazcxNzTk9hdKsrQgdEJPxBqMTkzk7LaNO/1ZJI49Yj7cDFJjhfB9PHoHPDKBFYLRmNHsu0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=W/zQRnbS; arc=fail smtp.client-ip=40.93.196.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="W/zQRnbS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=a1M7jpd2Av9xqG8YfYdlaJ8eIeumVxjMEVKyZGmiFnLV6xBEhPjEpTQyayxtazC65Bczw1NYrLGO//o7Qya9mq1R/0SwrrY0UXJqKfuz61Me3pzupTiKsYxTGHEiG8A1LFxjhI/pEzJ1GYHP3fz/6/5dIJ/JdRAOiPNRg2/pPdbysCT4O1zp4ymfeY5ooLgGx/ja7bP5XSBXt1l24v5kvt+rgeTAhm2qzYlJhh8xTgOsiB1Ou5o3KXmUmn0YPD1FanYo8OfrLZnSD1ucyMx05t9ptFD6aGIlYHPGuSOUpZVOikF7RHZUk/m5w4rzsxRVL+Qu31/xYwDCo4iRThaM/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6PPaXuQeMPiSW2gKTdCzfQGgDy+u0w8AYKgMifcnWNY=; b=cyVMwtDPlnY66q2N0Rdv23flUYHwEfWTHxQu45xu6KY5WPRmONH+8M+Nfsjhc0XbMctshL1bIv0H82Fbf/DKmTYlJHOUVTkB1NZheNOEuztBRF9w1KuSevxZGr7MHE3JlXDQNcCZv93NlHfaH/QoXVEGH1p/WSCVcwcHsiqPFqwuPTVJ/sDtR2J8PtrEfl50ve6TvtJ95yyqDl8tmnwHsHhQ3L7XOSP72q0lWzJrNZ8YRsMuZoSKFYEqf1KY6EeMZKWqHUzmanJef6OSqHHRzucNnQogur9UxFGkxvsq0aNtITeLCS8Yijl3fFhzY2dh80pdnwfcrrc+UVuQ6YOFCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6PPaXuQeMPiSW2gKTdCzfQGgDy+u0w8AYKgMifcnWNY=; b=W/zQRnbSUgoIDVktyIWbwKu0Belkiohr7UAae3A9Di3LElmuXJ7XTR/Mi2TsllwkiXhi1jjgBkWgBSSc5ZlAb8KHTz74rquMQ73xUx4vZvSEqfbTyw8PTdFX6jrz8PVPOgkIUog1i8P2qzE5rlvvf+qeKGdLc6/BRDtWrodUoDl08ZHRZ3PSNwAIgRScTIrASFh+VRKS5cB+OYRBTD11tbEnYf5MMA2iK3R/5qyIz/+trPnCp/e1w7bB3Lkj2xtdVEuXjvrVYcn+PpTyyLFuSpfMmEuF4eTEVp1k+5la9Tx6oXHAGcIgjZqujdLUTaL2/zaltddrl6B0XktedbhIfA== Received: from BY5PR04CA0001.namprd04.prod.outlook.com (2603:10b6:a03:1d0::11) by CH3PR12MB9123.namprd12.prod.outlook.com (2603:10b6:610:1a4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9253.19; Tue, 28 Oct 2025 15:57:37 +0000 Received: from MWH0EPF000989E6.namprd02.prod.outlook.com (2603:10b6:a03:1d0:cafe::44) by BY5PR04CA0001.outlook.office365.com (2603:10b6:a03:1d0::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9253.19 via Frontend Transport; Tue, 28 Oct 2025 15:56:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by MWH0EPF000989E6.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9275.10 via Frontend Transport; Tue, 28 Oct 2025 15:57:37 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Tue, 28 Oct 2025 08:57:17 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Tue, 28 Oct 2025 08:57:16 -0700 Received: from build-va-bionic-20241022.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Tue, 28 Oct 2025 08:57:12 -0700 From: Vishwaroop A To: Mark Brown , Thierry Reding , Jonathan Hunter , "Sowjanya Komatineni" , Laxman Dewangan , , CC: Vishwaroop A , , , , Thierry Reding Subject: [PATCH v5 1/3] spi: tegra210-quad: Fix timeout handling Date: Tue, 28 Oct 2025 15:57:01 +0000 Message-ID: <20251028155703.4151791-2-va@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20251028155703.4151791-1-va@nvidia.com> References: <20251028155703.4151791-1-va@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E6:EE_|CH3PR12MB9123:EE_ X-MS-Office365-Filtering-Correlation-Id: 50cc6795-7539-4ea6-a5e3-08de163ab73c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?ostNnzjHjsJMZAp0vQ1HVIwXLp225BMwb6/YkQ1JxZRkRZ4fYCW+y26DnT2y?= =?us-ascii?Q?TyPig2ZO6NjQ53sHnzFMZJkkAuYkAiPodqLr4+PlfSH7q6Kjju0UuGxFPPsK?= =?us-ascii?Q?LfojlyrdPVcor6eCyfKH+7SotCkFEA2lROiSsQGV0dx/c7DJ0hG7KgsynqTN?= =?us-ascii?Q?VvZsQ6TsGk4Ipy9d9afp6q1ZEBPKOXposOKNZqPXTaYkW0+FrMDchJNaS4gF?= =?us-ascii?Q?9P9FBJ0MB7k1NgHhGfX8ujCvHFxw4hP601sBh8z5mzaOlKnciIEN2LOSCQsf?= =?us-ascii?Q?7OJUocxXYxoLLlxhrQdg/J54OjHyh3PkyZtpNa2x7Kg5r9KEhTpX4keQYx1u?= =?us-ascii?Q?PlfDNEdZEFud1LjRy+2ddV7OgjeycnxOsZKDU1meAgAb53woNK98+JK/uObq?= =?us-ascii?Q?gBU07eWZ+yRj6wqZzSxAc0D2E3qpgHBMnk9W6C4kq/2vPjNLlnDjbIiZNG+b?= =?us-ascii?Q?1jdY6bFRLAEMHjbXlpPvSuBjincF11p3PFubfA8HxYk5j9I5fjkr0tVVGjSU?= =?us-ascii?Q?N+v/BPPdPcudiTxrx8eNE3I5vnLcfg9DuyoElyM0Bm7uqbpE/GIiRMwXnsGD?= =?us-ascii?Q?wiFZi3p2AW8gAKhmTllpWrIMkSDCMPyVJnDd1DEKwVskPzBDCnF59jKiz3hP?= =?us-ascii?Q?DFncXLw582FtCNVcGizDe8TZPpHsEqSeJmU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ZcX4tosyaITiV8o=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2025 15:57:37.0396 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 50cc6795-7539-4ea6-a5e3-08de163ab73c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989E6.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9123 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the CPU that the QSPI interrupt handler runs on (typically CPU 0) is excessively busy, it can lead to rare cases of the IRQ thread not running before the transfer timeout is reached. While handling the timeouts, any pending transfers are cleaned up and the message that they correspond to is marked as failed, which leaves the curr_xfer field pointing at stale memory. To avoid this, clear curr_xfer to NULL upon timeout and check for this condition when the IRQ thread is finally run. While at it, also make sure to clear interrupts on failure so that new interrupts can be run. A better, more involved, fix would move the interrupt clearing into a hard IRQ handler. Ideally we would also want to signal that the IRQ thread no longer needs to be run after the timeout is hit to avoid the extra check for a valid transfer. Fixes: 921fc1838fb0 ("spi: tegra210-quad: Add support for Tegra210 QSPI con= troller") Signed-off-by: Thierry Reding Signed-off-by: Vishwaroop A Reviewed-by: Jon Hunter Tested-by: Jon Hunter --- drivers/spi/spi-tegra210-quad.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-tegra210-quad.c b/drivers/spi/spi-tegra210-qua= d.c index 3be7499db21e..d9ca3d7b082f 100644 --- a/drivers/spi/spi-tegra210-quad.c +++ b/drivers/spi/spi-tegra210-quad.c @@ -1024,8 +1024,10 @@ static void tegra_qspi_handle_error(struct tegra_qsp= i *tqspi) dev_err(tqspi->dev, "error in transfer, fifo status 0x%08x\n", tqspi->sta= tus_reg); tegra_qspi_dump_regs(tqspi); tegra_qspi_flush_fifos(tqspi, true); - if (device_reset(tqspi->dev) < 0) + if (device_reset(tqspi->dev) < 0) { dev_warn_once(tqspi->dev, "device reset failed\n"); + tegra_qspi_mask_clear_irq(tqspi); + } } =20 static void tegra_qspi_transfer_end(struct spi_device *spi) @@ -1176,9 +1178,11 @@ static int tegra_qspi_combined_seq_xfer(struct tegra= _qspi *tqspi, } =20 /* Reset controller if timeout happens */ - if (device_reset(tqspi->dev) < 0) + if (device_reset(tqspi->dev) < 0) { dev_warn_once(tqspi->dev, "device reset failed\n"); + tegra_qspi_mask_clear_irq(tqspi); + } ret =3D -EIO; goto exit; } @@ -1200,11 +1204,13 @@ static int tegra_qspi_combined_seq_xfer(struct tegr= a_qspi *tqspi, tegra_qspi_transfer_end(spi); spi_transfer_delay_exec(xfer); } + tqspi->curr_xfer =3D NULL; transfer_phase++; } ret =3D 0; =20 exit: + tqspi->curr_xfer =3D NULL; msg->status =3D ret; =20 return ret; @@ -1290,6 +1296,8 @@ static int tegra_qspi_non_combined_seq_xfer(struct te= gra_qspi *tqspi, msg->actual_length +=3D xfer->len + dummy_bytes; =20 complete_xfer: + tqspi->curr_xfer =3D NULL; + if (ret < 0) { tegra_qspi_transfer_end(spi); spi_transfer_delay_exec(xfer); @@ -1395,6 +1403,7 @@ static irqreturn_t handle_cpu_based_xfer(struct tegra= _qspi *tqspi) tegra_qspi_calculate_curr_xfer_param(tqspi, t); tegra_qspi_start_cpu_based_transfer(tqspi, t); exit: + tqspi->curr_xfer =3D NULL; spin_unlock_irqrestore(&tqspi->lock, flags); return IRQ_HANDLED; } @@ -1480,6 +1489,15 @@ static irqreturn_t tegra_qspi_isr_thread(int irq, vo= id *context_data) { struct tegra_qspi *tqspi =3D context_data; =20 + /* + * Occasionally the IRQ thread takes a long time to wake up (usually + * when the CPU that it's running on is excessively busy) and we have + * already reached the timeout before and cleaned up the timed out + * transfer. Avoid any processing in that case and bail out early. + */ + if (!tqspi->curr_xfer) + return IRQ_NONE; + tqspi->status_reg =3D tegra_qspi_readl(tqspi, QSPI_FIFO_STATUS); =20 if (tqspi->cur_direction & DATA_DIR_TX) --=20 2.17.1 From nobody Fri Dec 19 12:16:35 2025 Received: from MW6PR02CU001.outbound.protection.outlook.com (mail-westus2azon11012048.outbound.protection.outlook.com [52.101.48.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A909A340DA0; Tue, 28 Oct 2025 15:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.48.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761667073; cv=fail; b=hA2V8jB4WoIOlPOGcy4e0olt4lAPvUGnpzFPa8jrLbCdpM1HDHHOmwWCJU81qWOnAcPZfO+oVsMcA0XxlcOcydLSZERz9/eZalb8lADMQ0Urpx2gP3Y0WmM1r1+UrZcwrj4NfxN5HmSMoqLvbsj3yFKut0FTWesuYfph45lw5Ro= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761667073; c=relaxed/simple; bh=YR1ulCsGwtuzZIZd5ultSpb/k19LfslNMfH9vkzQpYU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BKF6N46CR3Z0Ov4GNho69kJULoInarbf97Wlk7dqHaqzCYxTRlG7ptS0rI4G9vha3f+acEFaKmkWAPeUaFSq9doL3//JIUkuGhpTxX1X56mI916BR1JJlD7KUXFVIwYXyIQkQB+XX4XgKIC6WLJPEqiiNOs/NxEbJtAMIi1IiKI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=urLoiZHv; arc=fail smtp.client-ip=52.101.48.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="urLoiZHv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DfdAPojj5ZLp0fkt0FuWfdXQGtyemiuOxBxeDY3/txCTudHRyEixuK6P/f2fO2Wpypke1CEO2pT5w0/0ATEnKgPpBQRKyfzwgQsNr0CTJx6/aoQ0yOsJxIE7xYBqVE+dzBYW4cOvRV6uPiGkbI4Nx9JVwbo0KrLHSrUdj0BKwx0IbYlciiTTTdroOif6X0LPh8vZzEwSKhi8yaAtqbPv/LG3s+SuN5Vct0XZ7lrj8tx+ZxhNKbHNG+0947U4/Z8wu8lNiYQP4xfmTXX6luzwPq8fyOV5HSlNHdI6a9aylKhb8o99tOtfpb94PG3keAxWOuK6pHw/79HKjFleMut6Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mWGekwxey8n0bGNDDNe3/Lo2+kr93gBpDD65mjMoOSw=; b=MsF5Y3Sg152v2vfX13ewAE9npHlwOVz+vTRViVRWyEE9zgcyrzEAGWPJpGcfvhKLjEELkM3jZ5vDy7ddw6S4LO7Wjs5kVSwaF3wLYYDS66Goyljt3pIvNFbOjJyt+caRttSFJmyY2YSV4rWZKJiGlaQbKa/h0S0DfHxUX+h56gUKs+6O8/R19o6T8V2OJzm6qbipj8aB2rYThAIXheWq9jCTI8gwoxGR2oZVAZksInuH2c39gLVfErZw+1eKJ6yr+HLK4zMrlOvSBQdV0HHIvcKgrSpR5XSECdnt10dkPVpX3scQJI9o16HG8hnsyJQUWT5ca2sOOLjWztxl+mJNjg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mWGekwxey8n0bGNDDNe3/Lo2+kr93gBpDD65mjMoOSw=; b=urLoiZHvEXmIvda/sj4DSMVEFywkpAV1wu/mm8amfRJ23KBUC8e1UV9X6kScj/PV+RzI9YkIFrgrJpBoikHTN0FrqE5AP3cknK+D5XR+MmNO+0XU1qZhT89USluy1QN38ku0067DBhyu452ip9PaLYUT/t3LuCp8IoT3OvHThsDSo+Ov2dbXDNpOxNb8lNoZMoaC6N31tJfEK40JxHxg+X8rdO9pCtyHt2lYCnYCrVDiMhRKG9KOdnHOtI25g7f37G+3MekiMdHW7tfcaTgPjdc6BP98b5LGHL/DKZwIA0cbCHVGXj+D3Kt7LmORsPEsEAvH24rG2Xe0QiHFZ44i0w== Received: from BY3PR10CA0026.namprd10.prod.outlook.com (2603:10b6:a03:255::31) by BL3PR12MB6546.namprd12.prod.outlook.com (2603:10b6:208:38d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9253.18; Tue, 28 Oct 2025 15:57:45 +0000 Received: from CO1PEPF000044FC.namprd21.prod.outlook.com (2603:10b6:a03:255:cafe::82) by BY3PR10CA0026.outlook.office365.com (2603:10b6:a03:255::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9275.12 via Frontend Transport; Tue, 28 Oct 2025 15:57:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CO1PEPF000044FC.mail.protection.outlook.com (10.167.241.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9298.0 via Frontend Transport; Tue, 28 Oct 2025 15:57:45 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.34; Tue, 28 Oct 2025 08:57:22 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Tue, 28 Oct 2025 08:57:22 -0700 Received: from build-va-bionic-20241022.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Tue, 28 Oct 2025 08:57:18 -0700 From: Vishwaroop A To: Mark Brown , Thierry Reding , Jonathan Hunter , "Sowjanya Komatineni" , Laxman Dewangan , , CC: Vishwaroop A , , , Subject: [PATCH v5 2/3] spi: tegra210-quad: Refactor error handling into helper functions Date: Tue, 28 Oct 2025 15:57:02 +0000 Message-ID: <20251028155703.4151791-3-va@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20251028155703.4151791-1-va@nvidia.com> References: <20251028155703.4151791-1-va@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044FC:EE_|BL3PR12MB6546:EE_ X-MS-Office365-Filtering-Correlation-Id: a02ae061-7871-44ee-bf82-08de163abc05 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?MLzIQaOdT/MyK6yPX9dy3msGH1iud4EWN1DKxgjKSDA5Eg64DqCjHpgGCxT4?= =?us-ascii?Q?viV7nGmDtdH7fsJLcf13veqFHJ1Al/N/jZ96M1szxxDOn5PXLssvLW5ksQo5?= =?us-ascii?Q?/1JGGywh9UfqKOgKFcWB9vm2bBCRc5WCVnA/PWAA+JcMpqE2Cz48y4zTEntK?= =?us-ascii?Q?kNnZfIEc8p8zhbN6cafClCzcfsT+wnu34Y2DY+BljgIjFC2xB+IQcovlj+Q4?= =?us-ascii?Q?P3nBqONIRcxIbYg91NF2kMRMMX/JQETtCyxp/7recprjOs1FlKs17sYCi/Q3?= =?us-ascii?Q?hPk5993Z22TfUiz8C9GBsMxcQNgcnHSo4WfTkmlE2Ziha2NrsxZadXOmkXRj?= =?us-ascii?Q?bRQx4yGBRzQ7HFa+7GSZb/6cDSc0CqHC1Cxr8BzzShDGFG3yqUMCa/MLT4Hl?= =?us-ascii?Q?B94uB6e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= =?us-ascii?Q?q2wv4NSQBDtQ4mJBUd088Q8KqXocraVK5/4wDw+7f6FKqm3d6JrK+k9Ge46F?= =?us-ascii?Q?ZrRpipSx/lzSi53OUGCrZNkNTgAyaOSXfgYOx/BHGXIiDOHajeRj1X5IHZlM?= =?us-ascii?Q?2du2SCbmNHeR9Ka6+Ims7/lKuTyr8P2tUHcOduaxPQ5BmDBa1Vg94/sWn9yx?= =?us-ascii?Q?nIWqItn02btFvT+cbpuAe07xa6Aao0nUjbgRQVS05Tai5lZJbtSCGBbbNlMg?= =?us-ascii?Q?dqNV7Jh8JnF6dKC3Rt0=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2025 15:57:45.0831 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a02ae061-7871-44ee-bf82-08de163abc05 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044FC.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6546 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extract common cleanup code into dedicated helper functions to simplify the code and improve readability. This refactoring includes: - tegra_qspi_reset(): Device reset and interrupt cleanup - tegra_qspi_dma_stop(): DMA termination and disable - tegra_qspi_pio_stop(): PIO mode disable No functional changes. This is purely a code reorganization to prepare for improved timeout handling in subsequent patches. Signed-off-by: Vishwaroop A Acked-by: Thierry Reding Reviewed-by: Jon Hunter Tested-by: Jon Hunter --- drivers/spi/spi-tegra210-quad.c | 84 +++++++++++++++++---------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/drivers/spi/spi-tegra210-quad.c b/drivers/spi/spi-tegra210-qua= d.c index d9ca3d7b082f..69defb4ffe49 100644 --- a/drivers/spi/spi-tegra210-quad.c +++ b/drivers/spi/spi-tegra210-quad.c @@ -1019,17 +1019,22 @@ static void tegra_qspi_dump_regs(struct tegra_qspi = *tqspi) tegra_qspi_readl(tqspi, QSPI_FIFO_STATUS)); } =20 -static void tegra_qspi_handle_error(struct tegra_qspi *tqspi) +static void tegra_qspi_reset(struct tegra_qspi *tqspi) { - dev_err(tqspi->dev, "error in transfer, fifo status 0x%08x\n", tqspi->sta= tus_reg); - tegra_qspi_dump_regs(tqspi); - tegra_qspi_flush_fifos(tqspi, true); if (device_reset(tqspi->dev) < 0) { dev_warn_once(tqspi->dev, "device reset failed\n"); tegra_qspi_mask_clear_irq(tqspi); } } =20 +static void tegra_qspi_handle_error(struct tegra_qspi *tqspi) +{ + dev_err(tqspi->dev, "error in transfer, fifo status 0x%08x\n", tqspi->sta= tus_reg); + tegra_qspi_dump_regs(tqspi); + tegra_qspi_flush_fifos(tqspi, true); + tegra_qspi_reset(tqspi); +} + static void tegra_qspi_transfer_end(struct spi_device *spi) { struct tegra_qspi *tqspi =3D spi_controller_get_devdata(spi->controller); @@ -1074,6 +1079,30 @@ static u32 tegra_qspi_addr_config(bool is_ddr, u8 bu= s_width, u8 len) return addr_config; } =20 +static void tegra_qspi_dma_stop(struct tegra_qspi *tqspi) +{ + u32 value; + + if ((tqspi->cur_direction & DATA_DIR_TX) && tqspi->tx_dma_chan) + dmaengine_terminate_all(tqspi->tx_dma_chan); + + if ((tqspi->cur_direction & DATA_DIR_RX) && tqspi->rx_dma_chan) + dmaengine_terminate_all(tqspi->rx_dma_chan); + + value =3D tegra_qspi_readl(tqspi, QSPI_DMA_CTL); + value &=3D ~QSPI_DMA_EN; + tegra_qspi_writel(tqspi, value, QSPI_DMA_CTL); +} + +static void tegra_qspi_pio_stop(struct tegra_qspi *tqspi) +{ + u32 value; + + value =3D tegra_qspi_readl(tqspi, QSPI_COMMAND1); + value &=3D ~QSPI_PIO; + tegra_qspi_writel(tqspi, value, QSPI_COMMAND1); +} + static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi, struct spi_message *msg) { @@ -1081,7 +1110,7 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_= qspi *tqspi, struct spi_transfer *xfer; struct spi_device *spi =3D msg->spi; u8 transfer_phase =3D 0; - u32 cmd1 =3D 0, dma_ctl =3D 0; + u32 cmd1 =3D 0; int ret =3D 0; u32 address_value =3D 0; u32 cmd_config =3D 0, addr_config =3D 0; @@ -1150,39 +1179,16 @@ static int tegra_qspi_combined_seq_xfer(struct tegr= a_qspi *tqspi, if (WARN_ON_ONCE(ret =3D=3D 0)) { dev_err_ratelimited(tqspi->dev, "QSPI Transfer failed with timeout\n"); - if (tqspi->is_curr_dma_xfer) { - if ((tqspi->cur_direction & DATA_DIR_TX) && - tqspi->tx_dma_chan) - dmaengine_terminate_all(tqspi->tx_dma_chan); - if ((tqspi->cur_direction & DATA_DIR_RX) && - tqspi->rx_dma_chan) - dmaengine_terminate_all(tqspi->rx_dma_chan); - } =20 /* Abort transfer by resetting pio/dma bit */ - if (!tqspi->is_curr_dma_xfer) { - cmd1 =3D tegra_qspi_readl - (tqspi, - QSPI_COMMAND1); - cmd1 &=3D ~QSPI_PIO; - tegra_qspi_writel - (tqspi, cmd1, - QSPI_COMMAND1); - } else { - dma_ctl =3D tegra_qspi_readl - (tqspi, - QSPI_DMA_CTL); - dma_ctl &=3D ~QSPI_DMA_EN; - tegra_qspi_writel(tqspi, dma_ctl, - QSPI_DMA_CTL); - } + if (tqspi->is_curr_dma_xfer) + tegra_qspi_dma_stop(tqspi); + else + tegra_qspi_pio_stop(tqspi); =20 /* Reset controller if timeout happens */ - if (device_reset(tqspi->dev) < 0) { - dev_warn_once(tqspi->dev, - "device reset failed\n"); - tegra_qspi_mask_clear_irq(tqspi); - } + tegra_qspi_reset(tqspi); + ret =3D -EIO; goto exit; } @@ -1276,12 +1282,10 @@ static int tegra_qspi_non_combined_seq_xfer(struct = tegra_qspi *tqspi, QSPI_DMA_TIMEOUT); if (WARN_ON(ret =3D=3D 0)) { dev_err(tqspi->dev, "transfer timeout\n"); - if (tqspi->is_curr_dma_xfer) { - if ((tqspi->cur_direction & DATA_DIR_TX) && tqspi->tx_dma_chan) - dmaengine_terminate_all(tqspi->tx_dma_chan); - if ((tqspi->cur_direction & DATA_DIR_RX) && tqspi->rx_dma_chan) - dmaengine_terminate_all(tqspi->rx_dma_chan); - } + + if (tqspi->is_curr_dma_xfer) + tegra_qspi_dma_stop(tqspi); + tegra_qspi_handle_error(tqspi); ret =3D -EIO; goto complete_xfer; --=20 2.17.1 From nobody Fri Dec 19 12:16:35 2025 Received: from MW6PR02CU001.outbound.protection.outlook.com (mail-westus2azon11012005.outbound.protection.outlook.com [52.101.48.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 229443451CD; Tue, 28 Oct 2025 15:57:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.48.5 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761667076; cv=fail; b=VLc+83zBvuGWxTuryuKnJNMykzEFRVx+QF7D612DTzaCxWgp8rsUmXV5pMsJ5+5C6FSCc+S54RlZ9CVMHaF+emrW7SEs4yWe2kIQfnijqSlHbdwiInbltmT78m94IEptbZAc1MkbPRU3sV29RevKoB2ruWILjSZdCIkakhaJkH0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761667076; c=relaxed/simple; bh=whIfqwR3n5bzGGxprJSjfBGxAnkw8946MW3SCf6r6sw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hmdn5IrEy//53L8TYk5LnoeWT30dX5inGnaHYOgvFVS2l4OGTNqkCYRP2N8uaHzuF85lHuFWDmiwhJbDmlOJ7OTX+QzlbWXWZ9z0rXdh6NMUFamyrs0gbXcqihpsOl3xWJ8v12ISGfjFkXOfIZSS7aYS39w31+4oGGK2mwschnM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=kEu5Ksnc; arc=fail smtp.client-ip=52.101.48.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="kEu5Ksnc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=O3CInKhX8lpKOHFb7P8cK0Y5KoEbLkoLlQDT6eAKbYYpDqga3LvEGbEaZWwyrcNjZMdgTThA4UUaNAiBoKkv1PttWGD8lG0wpjuceJxY2RvMByA5IXFXdWJJlsrn3KWEXLf8gMqLGpPmbuuDOIlRJZtZ9pmuCWXCH6V2jPmzJ9YCienmBPgjV4xUnbZYSdlURgNV4+oVmW0hsGu9uUCbwK2uK+N4wRXSrM84XAO2LsdfSjO6K74Ehkiijcg8fyTCCjU+LFwfId9iN8oMLygVOkgfb+F/fXX0VZJ7iBB+/07nr4e/qmWXO/67ZVbOfjBQDIf5ccl9C/MOMNRWF4N1CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/tCjSBuUryYOM8imQmAcR08yeziUoZvmzheD+np5jb8=; b=kQtQDsjr56QnjqiAb0kAe9NTdPWaRjqTfHNNo5Tev1EcVIhEP3Yvd3oi8KGXaVABH8XkLutWRIgjkykJi/710Tsa0jy0s+nNxazHki4o4oIOWKRkVGBndZOEAZzTYaW6Co4xsY61MdbS7qBwCmvfUCcg7ylK16ju3Fxi7VFOONx00XK6J1N7eD7KKAZ9WM3UR0r3wKWZlR/E1dFzgGmv/mrodlBBAdK2XYhpH8xJOCBFgDZdRcIocc8yGo1qENa1EzoyL1pCwTpgF0uZGc4Fyjd4PgFX162Arg5gacbM77J0fApskNblXRTewmuK49GIeuZkmsoDhOfrq12C6ArgJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/tCjSBuUryYOM8imQmAcR08yeziUoZvmzheD+np5jb8=; b=kEu5KsncLk8ulpFnUd61IaQcM27A3vKI31iVvj4uDSBaeUUsE9kGz3YKu5eCb7Zp0erOZBcvdHvrCFH59mfmu4J5MbNHGOzdbByMv12YEGucdrb9JPunwpl4lbeYYUnLV/2A/G3UGIt7Kq9UtKLdHQnZG0KJb0lL9l+CdWp3xsYtyOg+vJzrOFEnxtx7Ipt3ncoXng+D8TWNBmlpRIXZqg/rLJFtv3VxUnRhZ3wofrPnO/ZDMtv4GZVkk8hpmpe/lb6D1pO2t+rP9+sJ2IjtPdsfNbyaUD9Veb5u4ooSS6mpn6TNWSYad1ylPWnVIHbNI3GAVxkwz7zTCPFWzIroqw== Received: from MW4PR04CA0202.namprd04.prod.outlook.com (2603:10b6:303:86::27) by MW4PR12MB7032.namprd12.prod.outlook.com (2603:10b6:303:1e9::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9275.12; Tue, 28 Oct 2025 15:57:49 +0000 Received: from CO1PEPF000044FB.namprd21.prod.outlook.com (2603:10b6:303:86:cafe::c3) by MW4PR04CA0202.outlook.office365.com (2603:10b6:303:86::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9253.18 via Frontend Transport; Tue, 28 Oct 2025 15:57:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CO1PEPF000044FB.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9298.0 via Frontend Transport; Tue, 28 Oct 2025 15:57:49 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.34; Tue, 28 Oct 2025 08:57:29 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Tue, 28 Oct 2025 08:57:28 -0700 Received: from build-va-bionic-20241022.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Tue, 28 Oct 2025 08:57:24 -0700 From: Vishwaroop A To: Mark Brown , Thierry Reding , Jonathan Hunter , "Sowjanya Komatineni" , Laxman Dewangan , , CC: Vishwaroop A , , , Subject: [PATCH v5 3/3] spi: tegra210-quad: Check hardware status on timeout Date: Tue, 28 Oct 2025 15:57:03 +0000 Message-ID: <20251028155703.4151791-4-va@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20251028155703.4151791-1-va@nvidia.com> References: <20251028155703.4151791-1-va@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044FB:EE_|MW4PR12MB7032:EE_ X-MS-Office365-Filtering-Correlation-Id: 39e6e66e-a37a-4653-1ac2-08de163abe9e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?gNcdp7W7FO9CCMK0L7Xidi2pS0jbrawBNyXG5McSbAfzg2xO/mzjwZSHcWsf?= =?us-ascii?Q?tgISxPMfr70bu+zl9IzXbYpV06kQ9HklDWX0lNPjlUlCbcGe6ewiVTykG7Je?= =?us-ascii?Q?HFF7CKInZXATB3N19SW06BBya9UF8HVmt0GV7TprojECLWJbQ2EM+Z067eap?= =?us-ascii?Q?wPTLkWkw6bGND8cqB5kBwxwrWAl/tLQOIcVpi2eRjd/F8hYoNrWS/I18wq/r?= =?us-ascii?Q?3wfpWollpriuB5LPoDKNSvj1jYNvxJt2yUbEkb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OEOeRXwxmUcoUL6JXuIRvRtFmU4WGwpNuif4q1TwzJdILgMQx?= =?us-ascii?Q?TDpTbAVvdPd68BVzImBvKrBNWvp9ARlM5T2PBNGddxp+E0Jv4xrOoYM3og9O?= =?us-ascii?Q?G9Jb2IOpD/zGlQVRbWbkYRRebSTh7JrNnsXKKqgVIf64RuPE8060dNR7HeBT?= =?us-ascii?Q?agQ2IRJ+bHbkX1KwqA2Xw1TcEackRej0sGqqilYALvrRrAu85+x8Oh3AQcM4?= =?us-ascii?Q?0gTt5LpG/AoNv/+SNSK6Mzui3vFwnLyk8r9V1jlMa+UqlY7K+oq4E7qbFO2j?= =?us-ascii?Q?3fJdXWp4ktzILUf+kOuT7w3UyXGv1Cl8mue1FQsfMA7CFkvVqfCMg3Hg2H2K?= =?us-ascii?Q?APHNEnu5nsyRirKyIp7N8VRH4JeBENv2/yiF2AbzssZEQqy9gVtDpFDUKREE?= =?us-ascii?Q?YukokPQuBL18RbsgY/w=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2025 15:57:49.4170 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 39e6e66e-a37a-4653-1ac2-08de163abe9e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044FB.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7032 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Under high system load, QSPI interrupts can be delayed or blocked on the target CPU, causing wait_for_completion_timeout() to report failure even though the hardware successfully completed the transfer. When a timeout occurs, check the QSPI_RDY bit in QSPI_TRANS_STATUS to determine if the hardware actually completed the transfer. If so, manually invoke the completion handler to process the transfer successfully instead of failing it. This distinguishes lost/delayed interrupts from real hardware timeouts, preventing unnecessary failures of transfers that completed successfully. Signed-off-by: Vishwaroop A Acked-by: Thierry Reding Reviewed-by: Jon Hunter Tested-by: Jon Hunter --- drivers/spi/spi-tegra210-quad.c | 100 +++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 20 deletions(-) diff --git a/drivers/spi/spi-tegra210-quad.c b/drivers/spi/spi-tegra210-qua= d.c index 69defb4ffe49..cdc3cb7c01f9 100644 --- a/drivers/spi/spi-tegra210-quad.c +++ b/drivers/spi/spi-tegra210-quad.c @@ -1048,6 +1048,49 @@ static void tegra_qspi_transfer_end(struct spi_devic= e *spi) tegra_qspi_writel(tqspi, tqspi->def_command1_reg, QSPI_COMMAND1); } =20 +static irqreturn_t handle_cpu_based_xfer(struct tegra_qspi *tqspi); +static irqreturn_t handle_dma_based_xfer(struct tegra_qspi *tqspi); + +/** + * tegra_qspi_handle_timeout - Handle transfer timeout with hardware check + * @tqspi: QSPI controller instance + * + * When a timeout occurs but hardware has completed the transfer (interrupt + * was lost or delayed), manually trigger transfer completion processing. + * This avoids failing transfers that actually succeeded. + * + * Returns: 0 if transfer was completed, -ETIMEDOUT if real timeout + */ +static int tegra_qspi_handle_timeout(struct tegra_qspi *tqspi) +{ + irqreturn_t ret; + u32 status; + + /* Check if hardware actually completed the transfer */ + status =3D tegra_qspi_readl(tqspi, QSPI_TRANS_STATUS); + if (!(status & QSPI_RDY)) + return -ETIMEDOUT; + + /* + * Hardware completed but interrupt was lost/delayed. Manually + * process the completion by calling the appropriate handler. + */ + dev_warn_ratelimited(tqspi->dev, + "QSPI interrupt timeout, but transfer complete\n"); + + /* Clear the transfer status */ + status =3D tegra_qspi_readl(tqspi, QSPI_TRANS_STATUS); + tegra_qspi_writel(tqspi, status, QSPI_TRANS_STATUS); + + /* Manually trigger completion handler */ + if (!tqspi->is_curr_dma_xfer) + ret =3D handle_cpu_based_xfer(tqspi); + else + ret =3D handle_dma_based_xfer(tqspi); + + return (ret =3D=3D IRQ_HANDLED) ? 0 : -EIO; +} + static u32 tegra_qspi_cmd_config(bool is_ddr, u8 bus_width, u8 len) { u32 cmd_config =3D 0; @@ -1177,20 +1220,28 @@ static int tegra_qspi_combined_seq_xfer(struct tegr= a_qspi *tqspi, QSPI_DMA_TIMEOUT); =20 if (WARN_ON_ONCE(ret =3D=3D 0)) { - dev_err_ratelimited(tqspi->dev, - "QSPI Transfer failed with timeout\n"); - - /* Abort transfer by resetting pio/dma bit */ - if (tqspi->is_curr_dma_xfer) - tegra_qspi_dma_stop(tqspi); - else - tegra_qspi_pio_stop(tqspi); - - /* Reset controller if timeout happens */ - tegra_qspi_reset(tqspi); - - ret =3D -EIO; - goto exit; + /* + * Check if hardware completed the transfer + * even though interrupt was lost or delayed. + * If so, process the completion and continue. + */ + ret =3D tegra_qspi_handle_timeout(tqspi); + if (ret < 0) { + /* Real timeout - clean up and fail */ + dev_err(tqspi->dev, "transfer timeout\n"); + + /* Abort transfer by resetting pio/dma bit */ + if (tqspi->is_curr_dma_xfer) + tegra_qspi_dma_stop(tqspi); + else + tegra_qspi_pio_stop(tqspi); + + /* Reset controller if timeout happens */ + tegra_qspi_reset(tqspi); + + ret =3D -EIO; + goto exit; + } } =20 if (tqspi->tx_status || tqspi->rx_status) { @@ -1281,14 +1332,23 @@ static int tegra_qspi_non_combined_seq_xfer(struct = tegra_qspi *tqspi, ret =3D wait_for_completion_timeout(&tqspi->xfer_completion, QSPI_DMA_TIMEOUT); if (WARN_ON(ret =3D=3D 0)) { - dev_err(tqspi->dev, "transfer timeout\n"); + /* + * Check if hardware completed the transfer even though + * interrupt was lost or delayed. If so, process the + * completion and continue. + */ + ret =3D tegra_qspi_handle_timeout(tqspi); + if (ret < 0) { + /* Real timeout - clean up and fail */ + dev_err(tqspi->dev, "transfer timeout\n"); =20 - if (tqspi->is_curr_dma_xfer) - tegra_qspi_dma_stop(tqspi); + if (tqspi->is_curr_dma_xfer) + tegra_qspi_dma_stop(tqspi); =20 - tegra_qspi_handle_error(tqspi); - ret =3D -EIO; - goto complete_xfer; + tegra_qspi_handle_error(tqspi); + ret =3D -EIO; + goto complete_xfer; + } } =20 if (tqspi->tx_status || tqspi->rx_status) { --=20 2.17.1