From patchwork Wed Oct 2 14:50:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13819883 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2077.outbound.protection.outlook.com [40.107.21.77]) (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 9559C1D1E7F for ; Wed, 2 Oct 2024 14:51:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727880670; cv=fail; b=XrpQbJ0l1RvnCNmlJ1mpUc51jQYE1EowVCfAxMWoG/mWWtuDq7dO9yekGP5u7itJhA8wH56c/RCV/LjO93GNiqL8XoS8LLPj1TFrMMuCjqK8fxPjEBkRIwUpWTLHGdrHIQzQBsjkJVuoOK9RLRs6d/EnOpdk4F3nSQ7hzvSm3Z0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727880670; c=relaxed/simple; bh=AHvZeWDy6/xYEqoA2DrJdTLBov3b0kSpblBok0ICshQ=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=qNkW2MZ8lMatX1MGk59430vrvmEuY2JNDW4V72J7pjK/CYNVEPh/Cv7L1uPPQEhlUsVRTuFDXAEA93pc1oH93Z5JhJxJreA0Pa/5jGtx5aF8SV4s2PVnQDbr9M/CZl19Tn+4yH/iY5rtKTNtZTuww23o796+1R22lxXuA0iohG0= 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=dfdl3C36; arc=fail smtp.client-ip=40.107.21.77 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="dfdl3C36" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EXCgQmjw4FqVXa+2pcHmMRHXwJlwNe/owNrJ7VKWnEIJtDc0/NnmTZUPwdIjSzL9qX+fhpmTOVUbbOJA2KGdKbT6qOQufvBovZYr6EGisFcBk6COx9VyXc3x89rC+fHGYwTN1VvsL7d0dVE8aj/dU2/Yvx/0IQimYrlk4NAOdWlBx6Hd/UNxfLXpfUxATddwIooQJ7UPuB87G5wqPoolLosV67g9/qgGLOhx0qZ8ZxxZJW7yBtesijBiRlVOwCAdhQyGqGJE1BY10xpueRbbF9wcUz/8tiJ0bfOXkVTU/TUmZECHlDva1xB1lg+xwKMWqfRFIrihjF4xsh6GITAUzg== 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=LWw8O34Z1PaA0bIpNMoMDZht14UG39YKCT4LXoVb5rY=; b=lUGvaUtRRtHlk66NlAWYcun9d9Knf7vaFByYIoh4YVOMVDXHs9LxD1+N9vozXYvJQBcx6QJeqFU0xb0q5BtxliBuR97KWbJuX2XBi5rNCetxKuRsSTS0p9FTUmS8wU5P2dLGiaXMS6E+Le/juQE+y1s38SB8voipZKUTLGGFxXubIXbErgj2R68mjGXG9YGEGm+AyMdi9t3A3AFt4TludHEUKYOCxUq7sXINuk0PhLmtBmDg5PUz2MkIhCchH5rDqv+DYyyJNZuFKEuxgjTCA954+peu+42Ijl9yHc+FcxtZ8bm7GOsJLcs1ZH5uubLhEG6ECYhO62/Ocb1qGihhKA== 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=LWw8O34Z1PaA0bIpNMoMDZht14UG39YKCT4LXoVb5rY=; b=dfdl3C36PIFZX14Mk4cVwg7Lm1AqK8VELgG+jXqq3Bg0A1eNPyt3ex03n+SKbJ1boWbKAGMu4EAYuQyOHwa2mdrkMf5uD8DcmkkuyYPS1d48Wes+6H4YbFV7hgB5DluKpQFcQEULNEFK+jSdtDnwjjfLszFhUx1Pg6jsKnUoeeQc672x8pvZjYrSt8nnU4Y7IKEB26oz+Wf6+YrjKdVp1KkRat8+w1WrjtBtcUhKbjnka0FgHYEWdL+TiHLwZGgdoXhPYUfEFyfzfrQOtkV2TKg49DLRDYg2xxAFz04D9o5H30ro2TJbG21qc9X73HEvap09nod9fmdw3pFvKzXRSw== 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 AS1PR04MB9699.eurprd04.prod.outlook.com (2603:10a6:20b:482::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27; Wed, 2 Oct 2024 14:51:01 +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; Wed, 2 Oct 2024 14:51:01 +0000 From: Frank Li Date: Wed, 02 Oct 2024 10:50:36 -0400 Subject: [PATCH v6 4/6] i3c: master: svc: use spin_lock_irqsave at svc_i3c_master_ibi_work() Message-Id: <20241002-svc-i3c-hj-v6-4-7e6e1d3569ae@nxp.com> References: <20241002-svc-i3c-hj-v6-0-7e6e1d3569ae@nxp.com> In-Reply-To: <20241002-svc-i3c-hj-v6-0-7e6e1d3569ae@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=1727880649; l=2752; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=AHvZeWDy6/xYEqoA2DrJdTLBov3b0kSpblBok0ICshQ=; b=E9naYrDh21bcxEeOMa+vTbTy6zWSgauI4eieu801Jp/W05Hufc/Xrb1eTHaMVezNDN0Y1sfVO 2+1cW0Ih0TRAQOvFQxNuVyKgXv+9vzFnxgm8skshKaoPQkELanThnDT X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0177.namprd13.prod.outlook.com (2603:10b6:a03:2c7::32) 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_|AS1PR04MB9699:EE_ X-MS-Office365-Filtering-Correlation-Id: 68d26252-9578-4d03-ed30-08dce2f1a1c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?RQvvLL2U+GkpGRL/rWs6LYOxRvM/OvJ?= =?utf-8?q?z8z5CB6ZrKcGYah7s7i4PjDWV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O+qd7aZi++c8QG0tGSr2gjj8vq?= =?utf-8?q?xj2od40g+FZo0pWo/7csKJqhk1hB0oUzFuCERhl9w5kQCvMMEoOzkzUOR5ItX7MiC?= =?utf-8?q?zNpqxS1e9yq5GWbwM+mZUjKiuGFFY1l+5v9oIPk98OR/D2xZHA+Q98Hv3am0+v5Zy?= =?utf-8?q?c11MG3UEHtnWAyiM4GIX3D0onNplbdX11zPqoOkc7CqvkSECTBnGdiIWNdpLK8n++?= =?utf-8?q?H5VxmvivEkgWUx4qulYiYgXu5vO1zKeceqYD1KJMA2dT8pSx1JBWfcQA/0YPzpYVV?= =?utf-8?q?vL8kQhofazQADX8pEgI7BEXsuCnQ6hbUb4rCdPjr8/aloBcvan83+DIIBOXZB5lWp?= =?utf-8?q?Y79xG4iO0c/NMd9j2D2rWIg0uNwxu7mjfxA=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)(376014)(1800799024)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?4PxHd1VB2F6S97f0m2TIXAju5xPN?= =?utf-8?q?DaK670hlpib4Uu3pZOIQ2mPxQ/cjIxKAZBIzKg/kOudnxcuD5UFbjQPrV9z3JuMNG?= =?utf-8?q?2BduaQ0UEx8tl3fyXiHpHD14n4qqzhCO2c+LyRCVVbIXHxJwNBR9bJGqm0iqcY+nt?= =?utf-8?q?nrx0cWHBJY/0c2KJTc7oMIe0juunn+GGLgjgEvlyY8C4kcMOEyTcWUaz/p5OXksk6?= =?utf-8?q?cOuCP0uoT4OnM0enZLki9Vo4Zj1uOmqt8+512nCU7fw9Py0d6F3nY4OSfwYVAgj70?= =?utf-8?q?tdDzL3z1WuDlGCx7CFGbQxCGKtXH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A+/KaLNcH8PrvMUtdeO9WpX?= =?utf-8?q?IDxmVwoK+SxmVqFuAtOUSPRQ18tWrWG4FyllORMZ67ZXctOYsqElmv9UlxbFpCf5H?= =?utf-8?q?RwycCPvMOtikv3F0COb7DR8B097+f8363lg0ObMq7wuTPkWSruoiTiJEcH+lXU6hg?= =?utf-8?q?DNOhH8MiSPZ6lDeuc2S9wJLRb8HwBbqIoWlrf3IEpqHYoywWn1aqEZ4rY9WxDsiXc?= =?utf-8?q?GD8zxh5053KDQ6sEeQBVkYjRj+LvzBGQQ/zwS41joTcyGeolKT7n+4sTqB6PDRlZ0?= =?utf-8?q?UygKuyBBtcibdXdgJpAAZMhvBdqA7EvsCNvKYjBhBOJ2sOq4obSicfgL0aq+TCwEv?= =?utf-8?q?ud7Pm3lDtgqA?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68d26252-9578-4d03-ed30-08dce2f1a1c4 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2024 14:51:00.9681 (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: nL0mxQ1QKI3wM3AqqmtH9vozwrF+KuB6h+RSW2i3d7fg3rIHHtSNhfaeeMlanGNsedJJG7LhSBh/I4IPjKu8OA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR04MB9699 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. Reviewed-by: Miquel Raynal Signed-off-by: Frank Li --- Change from v5 to v6 - reduce timeout to 100us, normal get IBIWIN at 9th SCL. 100us will timeout by i3c spec. 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 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index 5df0ec02d73ce..ed3f1bfbea37a 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,8 +465,8 @@ 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, - SVC_I3C_MSTATUS_IBIWON(val), 0, 1000); + ret = readl_relaxed_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, val, + SVC_I3C_MSTATUS_IBIWON(val), 0, 100); if (ret) { dev_err(master->dev, "Timeout when polling for IBIWON\n"); svc_i3c_master_emit_stop(master); @@ -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)