From patchwork Tue Aug 13 15:15:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13762213 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 18343C52D7B for ; Tue, 13 Aug 2024 15:15:55 +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:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=1k4yxfb2w/Oo8ZGiwBqOByWgv6MLTE2xAD1uQfgJF6s=; b=fLWk9thcQGyhx9n896uYbFZhG1 L7kCYypAH7yz9JPKO+CQ1gz09wdQJalcieFtHGVJFlsAVZyOpCH/+vG3ruzpid23yNzB7sRrmzesa 5G/Ljbit6zYspEH9ZHpcidSaXDPo99s7ChAYaYG/GwNR/Q+2zh7+3ST+HEwOSDzGeVey2qbZBj698 EynHmqVxi9CBDHWYj6uimbNxZe+BjSiFiCiyA5I66g4bG5KwA0hoRijBtBe8t/f35+rvc0XMVmFXM xsgJjIZ9gX1PwqsWmhpxsDgXmW2JVirXvc7SN++LrCigJjvgcVgE5s3AcQTstKu1qYAnYk8ZvqV4H Dvb/uXMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdtFa-00000004AtM-302h; Tue, 13 Aug 2024 15:15:54 +0000 Received: from mail-westeuropeazlp170110003.outbound.protection.outlook.com ([2a01:111:f403:c201::3] helo=AS8PR04CU009.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdtFX-00000004AqM-3d4q for linux-i3c@lists.infradead.org; Tue, 13 Aug 2024 15:15:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GFQtB3Dz2KiNzwqWcdQ3Rk9CyIR0FXVeuQs6WWTMN/U1XvIMTZqPhwYxdSHLDWwc9bV955snJr0aGvySn7bYerCONxDe31LuKEawdQW5jX6auKaajBiW1byH5bHJo14/XuGF6cwRZYtzqDbbSIs3Z4jgwfotBijp2udtsDQb3tmp2MTaPgj5hf/rxITlMOZEPMcjna7qVIRUFwEJeR/QnW0m3hyt3y95yCrU+9iMibfoZBhXI5OI0cs8AHiBSPUdinh6We1v0udcLI7BXN36Zy6QoYTtw7iK5C1xcGC0bxnIyYlLjoDzWOtOExbmXJVMz9ospV2NDcr5ybPo41c+YQ== 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=X2ZAcKNPuQ4Cy7AYm+SAGciuweTjZACn9ZhCaMcypok=; b=m7UgVRutpj9uCbFcNL4HBiWCV4zxAvmbMQ5NJuL0okHar7BkEcKUIC6P1OLdd/HcR17Jf4xL8kKfxYsvuiIx6qJDfS2JUjBam4cW+yf0sbJ4N3sD1L2DleHQO4mkjUyVv4B6MkqehxD+I36R9Rk9KoLxbr7LshFUKGisSlGFOzH6G1W1cT+rnXqnbqZkITK8cnO34G/ZyG/jN+d/fb2zbI+sWyVatkly1Nvu6SItK1WsrGJ/2facJSKDfeWLWsir5h1ngSXZSZGawi12KRVZCaPJDECZ+xF8oMG3+k54y41UTe18bRoNqqqKmgY4L/Fkzg3ve7gLlplhysGQOQ55YA== 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=X2ZAcKNPuQ4Cy7AYm+SAGciuweTjZACn9ZhCaMcypok=; b=LwTvsyxQF96aHqNLG/xGKqyDbskce7/tKB8/zGBjbhMLxIiJAbuLyDix0xoO8SWURabRyF02SXKCMjgGfZbKaaoAojVytRq18d/RvoByY+pmFWp/kht3vvmFCT/KAglVkuT8yV/VtdXhD9w8CeKXItkbsG+tiKlrPVvJm/jXGeCRbfLQhw/IPOfPeV7vNqpSA7sFw5ohf7ENwAoKCafhbTp1jlcR7eW3aVfIYg5uFmsuf2SLnoNtXdoIJR3IMi6WSJeEq7f5VfkF7p+Y4rf/N7Cf0/H3h5IHeUxUtJ6+gVzqm0wdBYormlHctoXsSxwG2wqE8+MJEzPoGO8lAS4Rrg== 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 AS8PR04MB8404.eurprd04.prod.outlook.com (2603:10a6:20b:3f8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Tue, 13 Aug 2024 15:15:49 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%3]) with mapi id 15.20.7849.019; Tue, 13 Aug 2024 15:15:49 +0000 From: Frank Li Date: Tue, 13 Aug 2024 11:15:07 -0400 Subject: [PATCH v2 09/11] i3c: master: svc: use spinlock_saveirq at svc_i3c_master_ibi_work() Message-Id: <20240813-i3c_fix-v2-9-68fe4a050188@nxp.com> References: <20240813-i3c_fix-v2-0-68fe4a050188@nxp.com> In-Reply-To: <20240813-i3c_fix-v2-0-68fe4a050188@nxp.com> To: Alexandre Belloni , Boris Brezillon , Parshuram Thombare , Greg Kroah-Hartman , Boris Brezillon , Arnd Bergmann , Miquel Raynal , Conor Culhane 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=1723562115; l=2350; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=eh2E0Be8sY7V85u59um2EkSafUz25sxM0/X2fX2jZpI=; b=KVffYwONNtB61AwYdgCAIBUQG1jaeTJPQMAjzDh+ru/mTbBsHvs3e4+U4uKHDbeXf7nmCEPTy PrFWUKWmKjvAYr+aBMxsiAnghPVV1kBpdFri7AfsAvWaIElrrx137nI X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR05CA0125.namprd05.prod.outlook.com (2603:10b6:a03:33d::10) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS8PR04MB8404:EE_ X-MS-Office365-Filtering-Correlation-Id: 44c5e51f-8aa2-4ed9-8168-08dcbbaad05c X-LD-Processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-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9doFwUrQdlh/GxXI6Htd1F6N4mWm5njrWt33J3JPGZ8WPxqJn?= =?utf-8?q?PoOajCFuRoQCMQ/Gi9H+cxUvlXzYo5/O+AnV5soW3F8cTl/6HjvFjlCn8BsGbfvQc?= =?utf-8?q?dX82qj1arMA2blIs1MeMyWcW6f08KjhUL/AATRq8JcH3Hx3n77e0OxhBspdSOezp+?= =?utf-8?q?kOcnzdojcUOl+0RCNi31lp4F5bGnGhUIIqtu7bBCheplB/ySjy2xLa03Aod5D9ST+?= =?utf-8?q?GhkQ/ar9SmPiOkoF82VgJfuQdhmc7HrmNjRny7dJC9Hul5QC/1dyJ1LRIii1p+XAV?= =?utf-8?q?+IPyUUIG39ICrrUv1Ee13SZU6Qo825X5LQc8qXK1ECFRp9VIXSd5G870IsjQ9dMbk?= =?utf-8?q?3oqH2E+saoxfiZ7ciAj+Hv/QbG+pFGZ1rWPrKpJvZKnO8L21yToqEx0l5mdZDiv73?= =?utf-8?q?G3zoiiloHVu1bs53K+UuA33KKKmOCTqvv+zi3ePXp6QohEaUW2mPlljywRSxthJv6?= =?utf-8?q?J7oQmZbWTNIJ5ENuKa5C/y1shxnnV+0yeA=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)(7416014)(376014)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?WlTJPv10uoGKBGyQTL8DLjHXFYz9?= =?utf-8?q?HYfehGS5fXuIxEeukSCYTGBpUdBdyYmTdr4/0/1hzYOH3BIxLGEG1WgfOU9Yhg8rH?= =?utf-8?q?DSrSptFMHJR8Dis/kMYZLug4XSKWfFsU8ShCDdJWvIPv9Gzb9oDUHiQQi2dHNTn0p?= =?utf-8?q?i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CSGuK4tIO36Z/wAYPff2JQgYwPfP/yO2CtAtFFmn/wR0J7nMgU06hkL2tje59?= =?utf-8?q?uSdpP9o0OxW55ekB8e3PaACsFAe3jW2xU3GTe/EiSKhWvpImBhDjm+mASkId22El0?= =?utf-8?q?UxA1z738K78+C+fghaILmWDF/4lDvtEXBshPj9Kqqg0tury2HGqrIfzFqmGiPtQtf?= =?utf-8?q?10mQmBxLp9p0KibOFy9tg1coiHke+YiE/zn7i4ChbKvBAqjrQ2KxVX4I0kz3/NPCv?= =?utf-8?q?4txvbvBuEG+PZceoTmB6XuipBcDhNnVP7NxYxpDebL086NCqERzLF/U56lD63AIxl?= =?utf-8?q?m/2YTWTvthHZCsvS348oQK1q08/VIvKbs/1dwdyP0yi0Gc6Y/FSms8LC6RQuI6Zyo?= =?utf-8?q?yoJuvHZ9NNW/F1p70cxtvCQqjawt0CS7BUo39Bv/xKmE3BmdlaSLUC9ESfa0Z+gYg?= =?utf-8?q?N6vBHgtUL0LiQd/YH6aIjuB/vCoOkPL60ecghH2wOdutZC68tWXA5Xsw=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44c5e51f-8aa2-4ed9-8168-08dcbbaad05c X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2024 15:15:49.5226 (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: 0Tq/qbQdZboThQLEV6Xiw70pkISKpE4TsFpyQHL2F0olXVwBpEAV15uIJf7yc9aMYz9vaaLxrgq5y9+iAdN09w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8404 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240813_081551_955501_313EBE79 X-CRM114-Status: GOOD ( 11.55 ) X-BeenThere: linux-i3c@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-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org 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 I3C/I2C Transfer, ACK/NACK Phase. But maximum stall time is 100us. We have to disable irq and schedule during whole I3C transaction, otherwise, I3C bus timeout will happen if any irq or schedule happen during transaction. Replace mutex with spinlock_saveirq() to make sure finish whole i3c transaction without stall SCL more than 100us. Signed-off-by: Frank Li --- 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 161ccd824443b..fbb6cef405577 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -432,7 +432,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 I3C/I2C Transfer, ACK/NACK + * Phase. But maximum stall time is 100us. We have to disable irq and schedule during whole + * I3C transaction, otherwise, I3C bus timeout will happen if any irq or schedule happen + * between 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, @@ -452,7 +461,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"); @@ -525,7 +534,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)