From patchwork Tue Oct 1 16:02:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13818332 Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11012013.outbound.protection.outlook.com [52.101.66.13]) (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 5FC061CB53F for ; Tue, 1 Oct 2024 16:03:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.13 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727798631; cv=fail; b=mR25/A1YFteeQpLD0aBvUU7S7M1loE2U7qzl6n6NqOKkO2Jz4+CFxPjCL1h8rBxfzOU5k4x73JHK9b+qUVMU+Bpt26qAP2vBF0L98yKfheWEO6vEar66BvD//d4oqbfUiiylZgXtW7wJIw4enniyTXpy5YeEZNz8wXecfRGnBy4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727798631; c=relaxed/simple; bh=bXdIg5zPM9BaWXsC+SgKZ7H7HKQdnYJSf5AlhHtZq7U=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=R62Woyb7BKzr61Yzawz6A7EKcKNnMqWKrji3VJhVQcc9IaNVTM9cm/+N2ACF4zcijN9KCulKJFIQ0AyVvOGCRw58qLtC+tbosMH1h7n4P2qgT14e3vQM0lvV9OZaIE+y9ikcQgs3t79NIHgWDOqq4nlPgXqQ5HYdFQDxQ8Qcnyo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=md4eq4uU; arc=fail smtp.client-ip=52.101.66.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="md4eq4uU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WCzFaRsniwF/UmqiKbka3S5AcXtYCbESh6lO+CBw6yZ898bP3NtUTdggYSBwAAXhdci8IEMG33jplc89WoRvn7AqcUDy0v79xW3Ha0nZuSXrPynMZ4Kd1mFmkfSTDKqgtb1onS1NKDWoOz5roW3bwyt4MidCkQeOqH45jZKsE37OJw5cpNmvtCeZBUvZ7DMya0hkI7KA/JhjfuB1+xdcD42SQ8euR+tgUfcXNStRRPyOfuWdLxXWRSV6ApIK42eUwIBPfFHPrQfKSndgrSjVn9o5UaLyY9lIV5n+wfREOBUBo0DCZsbWq00BTqrSFrvtNrSg27LDxglTN8A7anCxXQ== 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=lUG3B5sw0m9FDBnZS2WFp6KjUgxzk050Wfyb+JjQsVc=; b=nPHBgzNGQ7FHHJ2Y1QM+Th1meQvnmzPtRu2XGbQ0uw9BB728gBg1Q7qhF9o2YCZFGNTY5tjNF/O+WjN7X3NIpO9+71ZMz1VFG1xWU7jsVIh/LvTiyyp0BSECi+oDpMH+tMMvoAQrNMvu0JbQsGamCGyaCzllbX3bsf9JlSw+diTRbqjY1ipd8sDR3sb70fI8yrLluEzhLs+jgyy7uQUwZfVke2xmDNA81ezwtT50m96HwDMaKHIjGmJiEpIA/6LQCOlg4HhhFmP6kZVQGa/F3smOHXvRYAEw/0wFQxtaJcFVaAiMbIiXIvh61sotUo/CpzttIgi6qAAwbNY40K+EdQ== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lUG3B5sw0m9FDBnZS2WFp6KjUgxzk050Wfyb+JjQsVc=; b=md4eq4uU3YIqrhIx10tW90ezYrUtS3P/wemPY/SX1XTB1J6bK5WTKLkXF8OrDYhiWDadcPLncah/X42l8m4y1fqUsehTYTI4X/Dfy49elXJiUGBNYWWv9GgifZXQiqxKzhyJlgm594cXIqpe4JEE/8r21/5sTYK9VYHa9sgf4jRWcU0t3SlRl2dAyZH9Q2YLrqSZrL/2jETWD6LYbKEQyE1r6N4CEXbyOj/XiaoDSfXAko1RJbU7jVa+NPoK5P2ugXhLEAkFx9Z4tZpgc7fX0k6nIv7tRd6Cdk/mx3MvY7rYdALL0sDioKrXvtIl5UfJALb1n1/+WcyjOLi8HjXIKg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS8PR04MB7879.eurprd04.prod.outlook.com (2603:10a6:20b:2a4::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27; Tue, 1 Oct 2024 16:03:44 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8005.024; Tue, 1 Oct 2024 16:03:44 +0000 From: Frank Li Date: Tue, 01 Oct 2024 12:02:53 -0400 Subject: [PATCH v5 4/6] i3c: master: svc: use spin_lock_irqsave at svc_i3c_master_ibi_work() Message-Id: <20241001-svc-i3c-hj-v5-4-480ab8aed849@nxp.com> References: <20241001-svc-i3c-hj-v5-0-480ab8aed849@nxp.com> In-Reply-To: <20241001-svc-i3c-hj-v5-0-480ab8aed849@nxp.com> To: Miquel Raynal , Conor Culhane , Alexandre Belloni Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1727798616; l=2497; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=bXdIg5zPM9BaWXsC+SgKZ7H7HKQdnYJSf5AlhHtZq7U=; b=3dJeBl7aVLwecgJrIlp8kF/ymDU4ZRPIwNY3GrPbPaPg5DF6K3DRd7q8IXlQKUFDcB0pdSDg6 WLMO7iSISDsBqIjxFMOpXjLIx/p8WY2WSaM9GbMwwRbYe3xwfW2RksI X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SA1P222CA0045.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:2d0::22) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB7879:EE_ X-MS-Office365-Filtering-Correlation-Id: 2b594cf1-5c5a-4e69-1aec-08dce2329ff9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?V67RefDIH7fqkalFqeVFkrHeVtSCYK8?= =?utf-8?q?9ApaMwKnmvS82Kr9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X8Ouy8GOqFTyIGa74i0jrqIpQmoCaRuqbi2I7tO+A?= =?utf-8?q?aHJcLU3nwL+CjjJlCtdQTTk8il+F4za1fN68ySqmCoc3xy5bC8bl57PQk6IUYZNEw?= =?utf-8?q?EhHjwvy0We6u/uJzDH08VAtBBF17QUW5+Rf0nVKTc1byExRQo3tUJijeIExL6oJnb?= =?utf-8?q?30Ww+y9qkY+O/NCMmHMmNtP0xtA+lJA9AjP4BgI6e63+/ciO4U9orMOnpE5i7YU9k?= =?utf-8?q?rVX8BjCmvrwJerM1z1pkE9+Wseim9z+HysHLBWylyaxPOx7aX7hLyDXya127hhyAY?= =?utf-8?q?r3rSv/qgrB/kEo0xRDh0oWdeluY736BgkUanrb4LpZiho/JxyIt6xNavo4/u3ZV+E?= =?utf-8?q?c95fGRnpM/xGjZo2pu9Y7Nhu3onE8fKBDQg=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?eXUWsN4R9PDOXVOP/pe7CkFZXtIB?= =?utf-8?q?z7n1agRS1hxRtBrYYq9zcb+lFowv09bzhyod2Yx7RXbV5WdFzksmCbwRpGxT9EFmQ?= =?utf-8?q?7PFhrDig0dDUAlvWYHmsia0R8NwIRWnqGnp3gxkfHOyvuWK7tz2sDTei8Cc+AMSSM?= =?utf-8?q?23Yi/5/QFo8jQkfJ0KE1S+Q6x+92T2cJ2oAhq7mtf7rKKl8s4GV1qyGCCq9BqNT98?= =?utf-8?q?IaaXPCToCDsElN91LSMUc48QHRzpdNawEbK0oGD9Nu5K04lfGqtZFpFsAueIReEB0?= =?utf-8?q?/xkQHZ7CI5Lg1j+Pn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oo2gENhyKg+4Kvk9Lyxo9oBzkHCnUqzrLptb?= =?utf-8?q?z3me+/mISrcvE9O64veU3M3x8/vcbe3L9XHl+4m+RKTUwSGHsEQh2SwO+vP4pxSVF?= =?utf-8?q?i0zpDtKKIDrKAhIK5hBam7wR2nFJzIW2rolVnbLJzqHGubXKX7MDLZc8pR/U4Gw+O?= =?utf-8?q?0k0Ol5v9c3UYGaFGWwEJsyUV4hggXinoIGzyAtP/BIanWL94dd6/XD2NKMoCFOiDb?= =?utf-8?q?zA5p6YFrOpFfPQtX69WsotzOrY3CsjL3hSmvsxr3EH8byO68PsoqZ6UqNCECLGQwI?= =?utf-8?q?Ey2lI4SzA0OwiAu6NNkfCV13q8aGYjbrtC/mz5GX9ICDHl/z3Q9WV7ns=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b594cf1-5c5a-4e69-1aec-08dce2329ff9 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 16:03:44.0625 (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: 8F40fmGiCNXghkeQ8H75uUvFv2KDiFAGFfPVmeAmb6H9AL42g/dfjDSQMOK58w9ddLOC+kfV3Y3voRR4d9DknA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7879 According to I3C spec ver 1.1, 09-Jun-2021, section 5.1.2.5: The I3C Controller shall hold SCL low while the Bus is in ACK/NACK Phase of I3C/I2C transfer. But maximum stall time is 100us. The IRQs have to be disabled to prevent schedule during the whole I3C transaction, otherwise, the I3C bus timeout may happen if any irq or schedule happen during transaction. Replace mutex with spin_lock_irqsave() to avoid stalling SCL more than 100us. Signed-off-by: Frank Li Reviewed-by: Miquel Raynal --- Change from v3-v4 - improve commit message - needn't mutex here, other place already use spin_lock_saveirq to protent i3c transfer. --- drivers/i3c/master/svc-i3c-master.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index 5df0ec02d73ce..1ee6ce186195c 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -436,7 +436,16 @@ static void svc_i3c_master_ibi_work(struct work_struct *work) u32 status, val; int ret; - mutex_lock(&master->lock); + /* + * According to I3C spec ver 1.1, 09-Jun-2021, section 5.1.2.5: + * + * The I3C Controller shall hold SCL low while the Bus is in ACK/NACK Phase of I3C/I2C + * transfer. But maximum stall time is 100us. The IRQs have to be disabled to prevent + * schedule during the whole I3C transaction, otherwise, the I3C bus timeout may happen if + * any irq or schedule happen during transaction. + */ + guard(spinlock_irqsave)(&master->xferqueue.lock); + /* * IBIWON may be set before SVC_I3C_MCTRL_REQUEST_AUTO_IBI, causing * readl_relaxed_poll_timeout() to return immediately. Consequently, @@ -456,7 +465,7 @@ static void svc_i3c_master_ibi_work(struct work_struct *work) master->regs + SVC_I3C_MCTRL); /* Wait for IBIWON, should take approximately 100us */ - ret = readl_relaxed_poll_timeout(master->regs + SVC_I3C_MSTATUS, val, + ret = readl_relaxed_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, val, SVC_I3C_MSTATUS_IBIWON(val), 0, 1000); if (ret) { dev_err(master->dev, "Timeout when polling for IBIWON\n"); @@ -529,7 +538,6 @@ static void svc_i3c_master_ibi_work(struct work_struct *work) reenable_ibis: svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART); - mutex_unlock(&master->lock); } static irqreturn_t svc_i3c_master_irq_handler(int irq, void *dev_id)