From patchwork Tue Jul 2 22:31: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: 13720453 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 9055BC30658 for ; Tue, 2 Jul 2024 22:31:33 +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:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=0bUEvAO1z64CRlx7RmDygOPnAlpSipmKA07sofDAgZM=; b=ftngntYH7WaagQ y5qx/eQtu7ZC0YQjHp3yrDoF18GZ6v22qgGvmV6Oi+TCcpuYk9lLnF+6V339GiBMhYFjUPkmOO5MK 48GB0trO8WIiJVFXe9erF+4J6ygXqieK5BUifQnb0iC6rc4be2Dh8hr3UiL4cAA3jUxYxU3jnVN/j O0p5+sPqbFoqTQu/tLT9Z4FIt6A4IN9zHbxfm4nFtuIhoUM7i2PfT3EDo3wiz1+BSHGsnLon72IgF lSEkVdXOeKlrC4ieb6sOFA5p03BzBo+LFl2qT1G8WCZA4xjDy/QV2RbX0wOv6TqalqjF2mykITw+a S/k3acy1OLjKIJ22/fkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOm28-00000008CsQ-2PVG; Tue, 02 Jul 2024 22:31:32 +0000 Received: from mail-am6eur05on2062d.outbound.protection.outlook.com ([2a01:111:f403:2612::62d] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOm26-00000008Crs-0IN2 for linux-i3c@lists.infradead.org; Tue, 02 Jul 2024 22:31:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ByM2DvtA/7tIVxZve1AfSa1UlF0Heh5iEAHP0j2y+C/lLPUGtRC8EQLHv53FPBezqB54FZGZO1j+OovXzoCxzf9PnlZvmoxqydAGSr9czJBlqob6Rcp2zN/SefxjoFDXdLLsw1jqDMRa5d0K33dWNanYFMpx/qSbpEhV2+eUri4xr5N72AePRmfCdqJpTxE9+11kQV8xo5KAICTP/8eaLS90GTTYZ1lzNJZkIbYyep2OdfChyM0CFP2zrbfr5odCXNWNj6sQU4ZqneD5sgf2txaaiwnOZt2RFqJU4wTVJMqvQFciFB6On4BxUbLwcXOaLLP+gouBy/IaBPzrKbZkcw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wzAL42YO20r7weK4io8vj2inehx28JjVrNU+qQ6Tiss=; b=bkl1446SIB4cwbPwlpKxn20Ejsx/v1bTZObiFx+fVnpCAfCFefJ/aYTC1t5cG8mZONSB9I1RHSdtgqilNSbRqmlSRpTNN6lu6zf+zJkH93pCvJaDBPJnANFJ0cQPLpCG9sHzY/O3SUPcp9ezONo38FCIWUB6mRHcyzhshIXqRY23nXHO4IQvAy8NwzyNVwyJ/mi0Bupl31RShQKVzI+YcnIq9UhB4vPGKLqCPyfYUKOGOAcQdAsvJcRMMt+7X2z/titnLsUEzdi8AePFwvDi0vNofIagfaZJ0Oj9zOgbdw2IT1rlDAHSRzP8eYiMzqtK88oXqgt+JrrEuoUh05Tg3Q== 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=wzAL42YO20r7weK4io8vj2inehx28JjVrNU+qQ6Tiss=; b=VAqcyx9MnNA79cb+unV0WX0ND7IMNjx3vsZiAhcewjrUo3D5dsRb8gBvOtovyz5eZJ7sB6VB0C4C91RzzPKlsOPY/+BSc4dR2zGZLMaYk5zRCKYAeIbUpCWPPQSMzoYzF4i4KhdccYlInW2NnQ3PwxxfXjeyWwsRHfvJqHhXzvw= 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 PA1PR04MB10961.eurprd04.prod.outlook.com (2603:10a6:102:492::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7719.32; Tue, 2 Jul 2024 22:31:23 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%2]) with mapi id 15.20.7719.029; Tue, 2 Jul 2024 22:31:23 +0000 From: Frank Li To: Miquel Raynal , Conor Culhane , Alexandre Belloni , linux-i3c@lists.infradead.org (moderated list:SILVACO I3C DUAL-ROLE MASTER), linux-kernel@vger.kernel.org (open list) Cc: imx@lists.linux.dev Subject: [PATCH 1/1] i3c: master: svc: Improve DAA STOP handle code logic Date: Tue, 2 Jul 2024 18:31:07 -0400 Message-Id: <20240702223107.403057-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: BY3PR05CA0018.namprd05.prod.outlook.com (2603:10b6:a03:254::23) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA1PR04MB10961:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b514486-ddc9-4896-1003-08dc9ae6b3d0 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: QtEm0DMHjFUMtfFOwuh9EbiYxXLDj/84iJORaDQTK1KH+Jm/OH+tDAr5GPFV2qKkTxEcl36eJcoMZSLrTmnuFx0ngISjiGh0W2BIj16PJlbOwJ0vjQt32czVD50bMEwaNmSo3z/bWo/abPmADhugeF8Y2D8QXFPf34P9CYVOz5Aps55shaOtzqr5WiQF604aY2RATwXsoKWjlTNJ2jKSV1RyiLjKicOx+CJ6JNP4ad+UOeMLZMzNQ0QYOmonAANurSRhgRNfGWdeSH8b0csLC3VWhUWBt9MafDbWhbofKr52tig53LxU5yryOi9s3E4pDhCcyN2UevljTshxPKi3N9ed+CpLwlbuxYt+lzvgOZbOUdZ54/BZqY/2ue9E3NThtnGTJcSXMC0aPubUxgqSE21dqeroYOZBPibGIu1PHRazHGwwAkQK1eCp+ubjiEyaQG4mNfvdclYLBPqcuTv9bbAPrGjVhUZOUjzJAm3Q6bxCUMhcgdkm2Y6wRUixNWt//stAMQ2wAB+HVnboLHyEkk+jzMeZ0dTKVp3kt1bMOHCX6O2tlpojXGYOOk7qho5f062Y/KZTHHYGVnMJ+J9sPPtFKFZiksfV9BM2uyuFwYaZ+b9KudXRqP7BGkxEnR9ZHHLLOTL/tDryVdpwRRbqhaT4ICMAxtULDBDjSET1NbXGWMLldUMMKk8QRO7a/JBV+bYydhyN6EXnoZzLlIvCPbsxRNGiD8p7DUokd0sDpJcvoBYUjsdTlaTcY0R985zRUCNsSoscmkMBiq2aIuT4ZFCSA+W0V7obsMeeUonoxUXEgKnFLdf66p5xyUqJWQJFUCUuwKz2ydyq95EM+EJxoiMsymAKt9LsKnqLHgU59M2vtXYBgPkaeyW+VbFKfHNNRx6vm6oUIhGGGWp8MZY5m5risMAAp694Q/NydrmTN7hBLnbbUdHy9B9B/zpIs4JxEq2MVDrKGSfsLmHnVzS/URE8vMRkhVPEGyVE54ajLcxVejVtwuIUza42HHq/iv7qFnae7yQuJLsdStFaLYwaeyCWSwLMH/KmKvCdrqSaQp7UdeKzrmG9TvxBjK2wlizo6I2VZjjmgg2Mwj2jsIAeKg+Ewc0iNKhXdPUE6UwDHSYWiqP4zFSzemg6MozUJTGifkFZCnlH+Gfqcx7eAsOiBAS1ZWgsY/Rk8bJhg+AOOWR0tnrtbknD+BWxT2X4FdWWkPd4ii0hAlqG7u9hUq8cM0r1JohGCjrQwFXr6ilXk1d79AKsaOk3PlsRpjcWVmvp9jmAWixGzw2Puc4Y4PS4t6B+28WCV2x14Sj5siXgmi/tmzOC9fttYB4mJzLhq4nWk+SsSnotuIRt0wfpfsqoe5IohUgI0o82VsJVnP8F4fj/epYegX/2DzmRjgkARE884P3KtHS4vUZX0wF7Ac1NEA== 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: 0PkNxK5F5obSg6HNqZ9YLjfMP3psbg4UK/wbCJVyptEOfIn7t2YOiKFoNsl0jeRJIvVjUhuilkxVVzcDAaRSdPMR0o9ffQEv8oWuSx5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NppzGzGp2MPbO9RxQ1zgj8Aq22DU6xuXlQ+I9TU0ApywIxIwjnbLKEKSOmKyaGLWBciRCtbqjzGMghuQIHIXBDZPT4cGhm8Nq5eaJucy49At1v40pVH9uxCp6amV215t+MSuctrVmd4c5QjtzWD7wcH2wD7LtJiOLqpeKqysGGUl0CS+yejXy7isJq7PrlcpIxhD6svnCkzi+d8Nx3N7pax+axiTa22HV7lotisg4n840TReI0k3OriEHVX0dJDcoDlp89xc686hVCtom9nan09Gk7PXQwYit55LZreQJZMegjviL+zrnlxSAqM2c2uxdHL9TlCpMNaZY3Pel9pmlY6j1iFUXiSM87aiBjUrC7+11hG4/ysQIPiOVEqgMKeJsyyuAcCscjurHR9Owj6lg2BeH X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b514486-ddc9-4896-1003-08dc9ae6b3d0 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2024 22:31:23.1052 (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: ZxvSJarpg0uDj/FJYvgqGMQRt9ARX5CSk/HgFWJF2ESzGPuEvLDtqGuMdiGcboKW2mIcaZUwjoAEpJMRzSZy9w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB10961 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240702_153130_149162_995B8371 X-CRM114-Status: GOOD ( 22.28 ) 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 The REQUEST_PROC_DAA command behaves differently from other commands. Sometimes the hardware can auto emit STOP, but in other conditions, it cannot. Improves the code logic to better handle these situations. Hardware can auto emit STOP only when the following conditions are met: - The previous I3C device correctly returns a PID and ACKs an I3C address. - A NACK is received when emitting 7E to try to get the next I3C device's PID. In all other cases, a manual STOP emission is needed. The code is changed to emit STOP when break the while loop and 'return 0' only when the hardware can auto emit STOP. Signed-off-by: Frank Li Reviewed-by: Miquel Raynal --- drivers/i3c/master/svc-i3c-master.c | 61 ++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index f0362509319e0..15fa56383bdc9 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -790,7 +790,20 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master, int ret, i; while (true) { - /* Enter/proceed with DAA */ + /* SVC_I3C_MCTRL_REQUEST_PROC_DAA have two mode, ENTER DAA or PROCESS DAA. + * + * ENTER DAA: + * 1 will issue START, 7E, ENTDAA, and then emits 7E/R to process first target. + * 2 Stops just before the new Dynamic Address (DA) is to be emitted. + * + * PROCESS DAA: + * 1 The DA is written using MWDATAB or ADDR bits 6:0. + * 2 ProcessDAA is requested again to write the new address, and then starts the + * next (START, 7E, ENTDAA) unless marked to STOP; an MSTATUS indicating NACK + * means DA was not accepted (e.g. parity error). If PROCESSDAA is NACKed on the + * 7E/R, which means no more Slaves need a DA, then a COMPLETE will be signaled + * (along with DONE), and a STOP issued automatically. + */ writel(SVC_I3C_MCTRL_REQUEST_PROC_DAA | SVC_I3C_MCTRL_TYPE_I3C | SVC_I3C_MCTRL_IBIRESP_NACK | @@ -807,7 +820,7 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master, SVC_I3C_MSTATUS_MCTRLDONE(reg), 1, 1000); if (ret) - return ret; + break; if (SVC_I3C_MSTATUS_RXPEND(reg)) { u8 data[6]; @@ -819,7 +832,7 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master, */ ret = svc_i3c_master_readb(master, data, 6); if (ret) - return ret; + break; for (i = 0; i < 6; i++) prov_id[dev_nb] |= (u64)(data[i]) << (8 * (5 - i)); @@ -827,7 +840,7 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master, /* We do not care about the BCR and DCR yet */ ret = svc_i3c_master_readb(master, data, 2); if (ret) - return ret; + break; } else if (SVC_I3C_MSTATUS_MCTRLDONE(reg)) { if (SVC_I3C_MSTATUS_STATE_IDLE(reg) && SVC_I3C_MSTATUS_COMPLETE(reg)) { @@ -835,12 +848,23 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master, * All devices received and acked they dynamic * address, this is the natural end of the DAA * procedure. + * + * Hardware will auto emit STOP at this case. */ - break; + *count = dev_nb; + return 0; + } else if (SVC_I3C_MSTATUS_NACKED(reg)) { /* No I3C devices attached */ - if (dev_nb == 0) + if (dev_nb == 0) { + /* + * Hardware can't treat first NACK for ENTAA as normal + * COMPLETE. So need manual emit STOP. + */ + ret = 0; + *count = 0; break; + } /* * A slave device nacked the address, this is @@ -849,8 +873,10 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master, * answer again immediately and shall ack the * address this time. */ - if (prov_id[dev_nb] == nacking_prov_id) - return -EIO; + if (prov_id[dev_nb] == nacking_prov_id) { + ret = EIO; + break; + } dev_nb--; nacking_prov_id = prov_id[dev_nb]; @@ -858,7 +884,7 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master, continue; } else { - return -EIO; + break; } } @@ -870,12 +896,12 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master, SVC_I3C_MSTATUS_BETWEEN(reg), 0, 1000); if (ret) - return ret; + break; /* Give the slave device a suitable dynamic address */ ret = i3c_master_get_free_addr(&master->base, last_addr + 1); if (ret < 0) - return ret; + break; addrs[dev_nb] = ret; dev_dbg(master->dev, "DAA: device %d assigned to 0x%02x\n", @@ -885,9 +911,9 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master, last_addr = addrs[dev_nb++]; } - *count = dev_nb; - - return 0; + /* Need manual issue STOP except for Complete condition */ + svc_i3c_master_emit_stop(master); + return ret; } static int svc_i3c_update_ibirules(struct svc_i3c_master *master) @@ -961,11 +987,10 @@ static int svc_i3c_master_do_daa(struct i3c_master_controller *m) spin_lock_irqsave(&master->xferqueue.lock, flags); ret = svc_i3c_master_do_daa_locked(master, addrs, &dev_nb); spin_unlock_irqrestore(&master->xferqueue.lock, flags); - if (ret) { - svc_i3c_master_emit_stop(master); - svc_i3c_master_clear_merrwarn(master); + + svc_i3c_master_clear_merrwarn(master); + if (ret) goto rpm_out; - } /* Register all devices who participated to the core */ for (i = 0; i < dev_nb; i++) {