From patchwork Mon Jun 3 15:15:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13683925 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 C5367C25B75 for ; Mon, 3 Jun 2024 15:30:23 +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:References:In-Reply-To: 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: List-Owner; bh=IxvitEJKh2mJqcYUeHEDzDDVVTmjwOMCMluZ9MSmPqk=; b=ocnMjnW0Bs43wc RK1EQ/rL5jaQIqzfQ3vfwfOs8pjHgg4YFRM3SbBcmfu1Kog13zCzd35XWjKG4yEq45ZxsJB6BDzxQ BALYQHGCkpQXx4M1ZCXydoTQmNXDWy8IuNaPtwMVy1uAVvTrxIZzZ2QMp/J1wJQF9+EqTf4Ni+DwE fj8wRjr8/IheABcAhNETVQGkoygf0PJeyYDMfvJ5ChhFNW+S32WUmMlwZRUWKDzX1o0WdY4f+1LZg H2m5G/HZjywO11RhldlPMbSEo9I9DKzYsoG9FlYylbXVaPoOIDF9ZsNCymbDXlJ24puJNOg3y8v72 aId4jfeHj9sCFI+dXH6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE9df-0000000HEcW-1czW; Mon, 03 Jun 2024 15:30:23 +0000 Received: from mail-db3eur04on060b.outbound.protection.outlook.com ([2a01:111:f400:fe0c::60b] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE9dd-0000000HEbk-1Yyk for linux-i3c@lists.infradead.org; Mon, 03 Jun 2024 15:30:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LxtNWgPUFynpkHHO3sH58rzAnhU9ynK6hu4LkbB7QA7JjkU3839MhIWrjF35GOsVChLgs+wf5u1sY07GJhfC+1be9DCKd3M5Fk+OJUiMPiZyvVd6iWAq7/Hwcd0sj0Fq/hiydUo8YgNclK7kRr5IxEbyHnftq2Mat3aXyHhhmOx8D2ybHPLuI+v+62WN0QIkWleU33LeXtMf1tF6+nzQL3Zn1r9u95FbsgP/SsfiGb90VCHEOjY9kMJQdQHlP96XXlNgHdJnjkYvxpNycJ+K0MiagL+lhkKo7fedf07jTCvI1ud8sJRw4F2zVyNI8rS5KHj4f3urx8KDZkk3bU0sOQ== 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=zWisBc9PQkOmgHG+ALPjmuDuF3UjhVUe3DAd/6Qs2bc=; b=VcWQm7BVzxeu6ICzUX1QukXJ1RbyJfVfyn63e2qKqQOH30y72fCC6zq+73uUhcUQR+mJb9dVbFowqwBqZ23GrmKjuj5f/IjkRkYHWopIZjO5Xwn5pLSGkKx/aQpO2QwsNYPvHTvG6erHX0Dy/VMCiyGNm0YlvFpmdF6KAQwDPdBo9xqLGJ7+1wQU75Ecqt0Pqd59HQ/WaWQYCGsNJiwbY/TwwlfPV8sOhoPgtSU6AMA+y/IJIw8JVnLtIZ0rpFWj97lgYSk7mz+YyHkd3ByN17Ql8WbohZMW6hja0Plmjk0Y/Auc3GZhHWMGLTyn79xwUJ8Y6WKma4RzaCnYIGrKHw== 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=zWisBc9PQkOmgHG+ALPjmuDuF3UjhVUe3DAd/6Qs2bc=; b=Grv1oISLXfbOFiHWC3uz4u2rnX5Z5rsbbZoqVPvIAJxWaZzEqo4UNWfPcIklFud2EKrESvjhpDjumhbnZuyDznpykwhfeq9I7OJpJB7v4pv1DfCF52f4A+NiKdGPLs3wdLpXAJYpJHArcHLy+fq3+uq64qjN5ROlP/LdoenD1bs= 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 AS4PR04MB9624.eurprd04.prod.outlook.com (2603:10a6:20b:4ce::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.27; Mon, 3 Jun 2024 15:15:45 +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.7633.021; Mon, 3 Jun 2024 15:15:45 +0000 From: Frank Li To: miquel.raynal@bootlin.com Cc: Frank.Li@nxp.com, alexandre.belloni@bootlin.com, conor.culhane@silvaco.com, imx@lists.linux.dev, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] i3c: master: svc: resend target address when get NACK Date: Mon, 3 Jun 2024 11:15:27 -0400 Message-Id: <20240603151527.52235-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603151527.52235-1-Frank.Li@nxp.com> References: <20240603151527.52235-1-Frank.Li@nxp.com> X-ClientProxiedBy: BY3PR04CA0027.namprd04.prod.outlook.com (2603:10b6:a03:217::32) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS4PR04MB9624:EE_ X-MS-Office365-Filtering-Correlation-Id: fad26744-d99b-4e1e-75b7-08dc83e00a51 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|366007|52116005|1800799015|38350700005; X-Microsoft-Antispam-Message-Info: 6vWvH30gjLOGLkU0xpAYQ0hlCzUKJnr+TTPdRInORaPtm4oN8ws8l8mOrp0EuJl8OyrTdRHyd2o5y1tJT1PiXiEq5KfJzgimws4AHqGTwKSzPy5oi/+E73RagO6dsXlJiW4SpOFKI6mG4BmAWjxkYPrVbFQkeJdPudNgq5sfTueD4WIZWTq54qclz35eFmrwqbRyHn8SwRBqGEugXJK7GO01hbYYW6pjHkkKvtHjnQgf8+MhwK2ogJ4PnCd5aJgmMgRnMMVcib/t0oM05oLRN4Hjob307TSEalvWFXoGmf5AzcbBzkd/MBRMHBi4uhh2quTsKkWFDsdqbjrVFq9gIDo9ZRXih403S7V+xvtI1wWj9z26C2bpSl3Z/NcSjybttd/MGi8JCD9/vbfREfVzdP3Y2Wn3etTpFnsoEkVSQJOWqUZtiHDc1Mh1XUtR/cQKdX/oC5ukHae+B2EsFc+QF/bZ1AIB5P1/+UX5CpU0B+GoZJ2citMarbAJOBhTyNUTSsgfatmlDYrVPWyrPZBNHVkH+evQx2r8Ro+HVaBTw+fHDz7vE37VeLGcVXuxllCyAU7bhzj0umC4kJrNSf4C1nH8adXg9EVHoyv+Tzy1+Ifzv/Ty2oPMTreb1JlY9m4hQn0l0SlJxX2zXStconB+DDcjk23zE1HotgGu0oAQfg9AfWVmBtemWlETg8Mc1QQ17ZJdOO2FZmkkeFqZeuVZ+2M/FyiO5OK8KOTnCZhNtlYz+yoQzg8S8rOaHnSoEndrCf0tZj/j0W9021grQTI/Gl/HXItEMmSB7zxKkgedM7bwCl6HIdZpyRE3LlM2Lr2/vu3xQ5ONXyCFF+yTdt0/wm+3RptVj1GqMYQiNR8gvMIB5WhVVpjh57L/lCMW3W2eq2cyVt+4LNhVEMAUtZVSEbMkAY9kIHPAkCZJadFgTx4MBdKdO5flCdwAjbTPFW8NLMG7GX7I0xKkNKhMQZeAxJ4j2XD6r9HJfgoiDg+2daX3Ahx+oOaeT8OJCYr7J9PgFY/5esl3fhy92On1GRikTFauCVM/Z3cL6CkXVBY14TEGc18aS5Rdj4AY+Bfef7BSA7AeYNnh3HtItGM7t6sz8ALrJPRXvn+iWZZKMsmE7Jb/6JFjLSKA4zu0aY/FOFDakTs91wwhrJM7VN3+znZ9CBTZp7V+seZ45qpYB2bI6wLDlcpxjiczPLSRYXJHsMy9MPwVNrdGF1xcDDlGFhAVcQKmDiPacDx6+R+OUCq+Oa/XmGlxNaT4KC+pg9GgXzHX+zZluwtYAofcpmw/YDOrRCHS86mwSrS3GenrNfIeE+9ERtkV7/LeZTsb6zFlno01ss6sdKmMSWLBveYdZM9oMA== 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:(13230031)(376005)(366007)(52116005)(1800799015)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DnXr7E0NtMW9dqXFiz1xhzn6xaHZmqkTQSIMBQTAWPV819j06OSS/clU1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+7V+B1yIdxkzjWaY1ZykSf1jTDtFanu1MoAONqvrRCiSot86DX0w2EhvPzq/iZQTo8x5FgIVpw/DVMI+8EBCZ65uXmXpHZz9uvIOdKcTuOfuOkvjS0z1q5ZVXS/GgTIYWrBS3/QKAUFxPXS1gfX/7OBesXNwK2nMYkg1WpBvkLMgxEmZmfeQuOR2BiA08HKol3cT/H5wAmPh1sDh+auk0GwkzjblwlXMnW9VPZOKLokscqwweMwDxNabXppUrbmZifF4Z765NqT6D26LRMZgOz3zCcgazO3hpJiiaXGYiJ1eoNtnXMZ2dlyAX7TTWOYst7S1ANg7qMD/dpgdF4fprRNzbDRD224RLC55rhdD6J4TnbzJXzu9zvdFSfic++nvo23AcKCzAbPikU+q3YLC8mDysBgB48= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fad26744-d99b-4e1e-75b7-08dc83e00a51 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2024 15:15:45.0170 (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: i/ogYWg9ne/tRpmMR8dYCPdNiVeFWkFDwmmD7xySx62V8QaVc5qHS/XIEAUKztbxvWGlCQDg8NzDnU4F8Pd/Qg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR04MB9624 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_083021_436624_EECEA138 X-CRM114-Status: GOOD ( 15.44 ) 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 1.1.1, 11-Jun-2021, section: 5.1.2.2.3: If the Controller chooses to start an I3C Message with an I3C Dynamic Address, then special provisions shall be made because that same I3C Target may be initiating an IBI or a Controller Role Request. So, one of three things may happen: (skip 1, 2) 3. The Addresses match and the RnW bits also match, and so neither Controller nor Target will ACK since both are expecting the other side to provide ACK. As a result, each side might think it had "won" arbitration, but neither side would continue, as each would subsequently see that the other did not provide ACK. ... For either value of RnW: Due to the NACK, the Controller shall defer the Private Write or Private Read, and should typically transmit the Target ^^^^^^^^^^^^^^^^^^^ Address again after a Repeated START (i.e., the next one or any one prior ^^^^^^^^^^^^^ to a STOP in the Frame). Since the Address Header following a Repeated START is not arbitrated, the Controller will always win (see Section 5.1.2.2.4). Resend target address again if address is not 7E and controller get NACK. Reviewed-by: Miquel Raynal Signed-off-by: Frank Li --- Notes: Change from v1 to v2 Add Reviewed-by: Miquel Raynal drivers/i3c/master/svc-i3c-master.c | 58 ++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index 032fe032ec433..0b588ed5894ea 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -1052,29 +1052,59 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master, u8 *in, const u8 *out, unsigned int xfer_len, unsigned int *actual_len, bool continued) { + int retry = 2; u32 reg; int ret; /* clean SVC_I3C_MINT_IBIWON w1c bits */ writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS); - writel(SVC_I3C_MCTRL_REQUEST_START_ADDR | - xfer_type | - SVC_I3C_MCTRL_IBIRESP_NACK | - SVC_I3C_MCTRL_DIR(rnw) | - SVC_I3C_MCTRL_ADDR(addr) | - SVC_I3C_MCTRL_RDTERM(*actual_len), - master->regs + SVC_I3C_MCTRL); - ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg, + while (retry--) { + writel(SVC_I3C_MCTRL_REQUEST_START_ADDR | + xfer_type | + SVC_I3C_MCTRL_IBIRESP_NACK | + SVC_I3C_MCTRL_DIR(rnw) | + SVC_I3C_MCTRL_ADDR(addr) | + SVC_I3C_MCTRL_RDTERM(*actual_len), + master->regs + SVC_I3C_MCTRL); + + ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg, SVC_I3C_MSTATUS_MCTRLDONE(reg), 0, 1000); - if (ret) - goto emit_stop; + if (ret) + goto emit_stop; - if (readl(master->regs + SVC_I3C_MERRWARN) & SVC_I3C_MERRWARN_NACK) { - ret = -ENXIO; - *actual_len = 0; - goto emit_stop; + if (readl(master->regs + SVC_I3C_MERRWARN) & SVC_I3C_MERRWARN_NACK) { + /* + * According to I3C Spec 1.1.1, 11-Jun-2021, section: 5.1.2.2.3. + * If the Controller chooses to start an I3C Message with an I3C Dynamic + * Address, then special provisions shall be made because that same I3C + * Target may be initiating an IBI or a Controller Role Request. So, one of + * three things may happen: (skip 1, 2) + * + * 3. The Addresses match and the RnW bits also match, and so neither + * Controller nor Target will ACK since both are expecting the other side to + * provide ACK. As a result, each side might think it had "won" arbitration, + * but neither side would continue, as each would subsequently see that the + * other did not provide ACK. + * ... + * For either value of RnW: Due to the NACK, the Controller shall defer the + * Private Write or Private Read, and should typically transmit the Target + * Address again after a Repeated START (i.e., the next one or any one prior + * to a STOP in the Frame). Since the Address Header following a Repeated + * START is not arbitrated, the Controller will always win (see Section + * 5.1.2.2.4). + */ + if (retry && addr != 0x7e) { + writel(SVC_I3C_MERRWARN_NACK, master->regs + SVC_I3C_MERRWARN); + } else { + ret = -ENXIO; + *actual_len = 0; + goto emit_stop; + } + } else { + break; + } } /*