From patchwork Mon Oct 23 16:16:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13433175 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 ABF4FC25B41 for ; Mon, 23 Oct 2023 16:17:28 +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=8YcLXGZ2Te8x9EK1lsciJdQ42Kip8lREFbeqPzxmzlE=; b=4cC02Sr/QoiIV5 N5a5WykOCEbwWks/1nDG1bjDiRQeL/JknmT3akA+jx0f8dw2iKAtic1ymSvN2uYNzqKUZgGroCJ1R dqZtU26tI3pQBiKiTYO6txJEPYvhaB5LdRsoLlF71EaegvmacYxSJSv2dF/rNN/op+zdiB2OymMYt TbgmrYXxBAlFfLfQci6X3gU2n3eiFiCQ0EmBZLWjjAVs+YY5xcv3yDfJilnDPGwhQpfi97AgTZRor AomB+pLegvpletzo12qjXJ8bi9IOiCqQNppgFkAb9vD1jqCItrelu0WP5T+4E1662Bl/xZSbnW1fd 5XgLA8zORekE510E62LA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1quxcO-007o3I-13; Mon, 23 Oct 2023 16:17:28 +0000 Received: from mail-he1eur04on062f.outbound.protection.outlook.com ([2a01:111:f400:fe0d::62f] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1quxcM-007nyM-17 for linux-i3c@lists.infradead.org; Mon, 23 Oct 2023 16:17:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kEnTgr4uz2GhbpBNOlcEoKnkMloS2sDKKkKLTLltEf65KrsPVigmVbFYTlnbEMLv1c8X3QQFxzT3VNssbmNWHpaabWe1cPlLJOs5Z72nwBmDlxFHRaq4XyVFNZpyfVZuLdOhW0bXvY36bfaRqbmrWCoUtAdlVr6ZLtP9r2kCQhw5IH/YXxR0/rHCFFnydPJM0Vy06Hu6FytXa3odODox0Fm4S6qH317mqfYmDBX9iDKx9cMxRHvpF/5XDITmVYZPD1OwDT6+UNFYP+E6Gjail/tq1ht4SU2sSNpIXzU7/zUXyvReeDkgBOt4jBO+ZSfWRsO5KzvsDdN1aJ8aRfm64A== 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=Q1Eg5x0kveUbh+2VLsIws1d1wUUv0QNkE46sI/KeRdQ=; b=eRsX5YV8+u4UqoH611YbcOc6K/dLREz8097MsRG65zNVXCI63tTrU15zxsTh80UqEwwzutq+lxdiBbxxl0lwJL1pVtzI5GI262sf9ywavGD21kVXYp/hQSqL1NzsF2JeBVEA5JeFK5Tv+B5ZkQ4cJHuYFNJKBHW8XT5lfAxwwjeeadVf1Lch/Mze02e2CQEcqNmnXfo5wbhi5OIaiwbpYEOKKT4XifiO5ofm5ZpydqPsLh4/gcAjaAKXCDEcF6qaSvrI7ybt14zkciDa9SD5o8yAgDxatgoin7TSs2E/dVkJ3WYR0Ix2AR+e0l26gbbZvdeuSBKUgp1igrfKqbvFuA== 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=Q1Eg5x0kveUbh+2VLsIws1d1wUUv0QNkE46sI/KeRdQ=; b=M4IVsNvYUbSIaNCQkpM55WwkhvzRFYSjYcn7DVy+SbFHJaP6gANqENhO8mNMBxrq0KUVEEmHn9jwe5UwrI4BqZBO/CgAqHwDARvXXajaEjF8sPuWSOlk/HpkG1LuMjvWCOTIhVMfMihXlrlH4VI2B80Lkn4PiemltwtLSm+IAxw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by PAXPR04MB8655.eurprd04.prod.outlook.com (2603:10a6:102:21e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.16; Mon, 23 Oct 2023 16:17:19 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::97ca:a905:8e64:c098]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::97ca:a905:8e64:c098%6]) with mapi id 15.20.6933.011; Mon, 23 Oct 2023 16:17:19 +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, joe@perches.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/6] i3c: master: svc: fix ibi may not return mandatory data byte Date: Mon, 23 Oct 2023 12:16:55 -0400 Message-Id: <20231023161658.3890811-4-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231023161658.3890811-1-Frank.Li@nxp.com> References: <20231023161658.3890811-1-Frank.Li@nxp.com> X-ClientProxiedBy: BY5PR20CA0002.namprd20.prod.outlook.com (2603:10b6:a03:1f4::15) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|PAXPR04MB8655:EE_ X-MS-Office365-Filtering-Correlation-Id: 1090b22c-74d4-4639-68b4-08dbd3e38793 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EOayPqRAm1d9ObrnFbDFrySO+h1SeZuHIyndiZlVwXqzWp6Nemzxk11touoRt4k9yUnyYdIBNiL0iA0QU4qu4wlPYM4bm6pnITBH1/yU7IVRvaXA6RgqiCv2xiBV2zsuyq0X37riL7KzCYcrsOdQN8CDUu2n8jL+3TjNypGoR2JoDjSDSbmXfG0DrmAlW62JbYb40OzyVx2GBIwkLp/PJz4Gzi7L4HsXfNBgkyfOHVGbYIPtsjbgTpImpxw10lBiZplx4/zknzbvAYcp1JgEDTtnVBx4Xl2eINk8sjRQTHLuEhaffM0Hh/R4QhZeQbuQ6atbTkQ7a2LWTdWiaO2mys18159RLHJIPf2jDrkcKPa00Otgp+8NLbeyH4L3QjuQ6sIHZ9UyRaM+wXhPd5QlC9hgfkH6xQ0B8JROlh9mI5WThsK4q0/67tMD/gsUc19VNbuHsP9IrGPCKEIdlQ/8PaadK0XBf1mXEMZJeTm8WeRikmMyhUV/r56EyoTvgiBtsYpcdUABw8lc2CK/UogKk/zbrxWM7fNHz7iyNfAuXcI6Q/v4msEuWEROdD0nxDwCBtDQSOIDDEmImYwESZ6JD+NZ7NJjjyseFPa3JJzd7jsIjD8VweiPKNeWUEY3dkCd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(136003)(39860400002)(366004)(396003)(376002)(230922051799003)(1800799009)(64100799003)(451199024)(186009)(478600001)(6506007)(6512007)(6666004)(86362001)(316002)(41300700001)(6916009)(2906002)(6486002)(5660300002)(52116002)(36756003)(8676002)(2616005)(1076003)(26005)(38100700002)(8936002)(4326008)(66946007)(38350700005)(83380400001)(66476007)(66556008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /0axMwlIomY2+G1KJdkFqix9Mo4htMPR0YywEiu0RJCLrzMF9VLRYPKZFF+bgtZRtqtKmt4q66NeaCd4/shde5MAoosJL3alQsh9PtATadobez5Vei8ACij4pjf0s8QlUs7jfw7P7Av0AUMqMEFLEPmxIzZuhrQP6tI0/gPgDdVa+rNslDSdXYn0iZoPDoOXEHioHC7DBzEH9WB30TdmHTHt6oO2zYYqqKmpJ5P3BVdNOQ4YURLwFYGtrOwNYkNZbZ2cYbms881ozHw8iFXCbbHLT8Q3ujTkxjSGxdw5zhvckttD9ul/Ag+CBzvppy7SntXX2xhVMFEtfFft7+lNfh0q1cFReggpA2z52UJwjHBVXH2f9gtGx7JfIz9UZw0YLAn49yek1Dx8YSwzHqHExLLvlADoy2dL5eWj2Q53bkldqcGchvmBkS5N6u6dz4QvQobdQaj0zKu64YZSCYIsj92CvdALuV+MpHFuHMxoAtsyUuNkWNh2GpSlT8Bb6gXHFIRm02MQBuceuQeYVTrWVwjUW9smdU+ng9qqSyIOdnJkO4KQZ/zwLoPEbNuVypi98EGSX3z+Pwp+01aka1JreUxnwX4aS369y9ixVcnpK5vTDf4BQlkIDKNelgOjkIWt0nIQtFraCxDqdORpWBIXBQP7bdIuhv5Cu8ZWUBGnVjrVwkXdxSlmPDvGIA7D5TlpwnikShA0VcSVyTZMR1/JD+q0GRsfZDUHijMy7OddhqOdWS0D/Z2ovosivGDI7PSssseSQ3rW5s5zLKVzGNRcWuJlPu5+kPPUaQrxG554+sgP9Q/3irzAp4+OIbmQz36Q4VUlFXvhX6rM1rnf8dEXduNqmExn0nzJSKSL2/TEmsOGRUvkDqh59zfvLbVVLkfqNfNC37D7QjNQKzIMPwlm1WNTBddI4FfYKstlT0ujuM5DyekhRFu8pZO8aYzRo/uRFWuuSm6SbmXWVevRo1lNwPB9TZC1xtjqRGzvwugdYLJB8qpU0fqceypW8jd11pYqTX976gyY4GaEfhXioTqbOknbyKx5CWdb/H75vp5eEzRHD/pt2pJF9s/JnuWWS05kjt9ixzeBTuDY9rH1pD4wjJymnh3RuHvcUzR39buxLW+dKi9oOagAQpKjc8JQwXww+TIe6jAQV7c4ZubXgDTcxDcqDbidSSDv9HCUb0QZPoepXqRWSIekJRMaAYY8OBInYLwuLV5azlcnMxCTgnNOvZFK90Hgvn0muWmpyXuu6DcwxZXCOItnFx0ntilVL4LY0pn1XV0/W5H4V4Yu15zB1Omhqo9H2M/LYyOgKucHcjMAAcaOEDstNhEoXxsGy8AGjSesZmjwe1PQMhkz+FAkDgAqlpCgSlUQdL7Z7bqgUviDdbadNnIJzXCnPpuWCv3OxfEqBuul6EqrAYcoFBJJF05vkqPCo8iVnKxDrbfG4Y+INNf4wFLFThmUSGMxaRR3Oir5uTlUMgWy7e81nUu4ecYBdi9NjwA4Xm7yGLByegqU7jpcafl5U8VpoqQ5Dx2KqnbK9hyH+A9ldlY9UMkH9tB3Y28UwFHmuV9nQpnmDrhSXhH3vEUh2sdU+o0qlsiR X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1090b22c-74d4-4639-68b4-08dbd3e38793 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2023 16:17:19.0411 (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: Z1Heo6JT1FJKSp5sPlkvWlKQNiOIn6xOHdZiLUs+DaLbYp+vVXd74xOEU1UWGCeSHiikmVH49LbfR7YkpbucgQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8655 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231023_091726_386953_D8CDD037 X-CRM114-Status: GOOD ( 11.84 ) 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 MSTATUS[RXPEND] is only updated after the data transfer cycle started. This creates an issue when the I3C clock is slow, and the CPU is running fast enough that MSTATUS[RXPEND] may not be updated when the code reaches checking point. As a result, mandatory data can be missed. Add a wait for MSTATUS[COMPLETE] to ensure that all mandatory data is already in FIFO. It also works without mandatory data. Fixes: dd3c52846d59 ("i3c: master: svc: Add Silvaco I3C master driver") Cc: stable@vger.kernel.org Reviewed-by: Miquel Raynal Signed-off-by: Frank Li --- Notes: Change from v3 to v4 - add review tag Miquel Change from v2 to v3 - update commit message and add no mandatory data in commits message Change from v1 to v2 - update commit message it also works without mandatory bytes Change from v1 to v2 - update commit message it also works without mandatory bytes Change from v2 to v3 - update commit message and add no mandatory data in commits message Change from v1 to v2 - update commit message it also works without mandatory bytes Change from v1 to v2 - update commit message it also works without mandatory bytes drivers/i3c/master/svc-i3c-master.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index abebef666b2bb..dd06b7c9333f1 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -332,6 +332,7 @@ static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master, struct i3c_ibi_slot *slot; unsigned int count; u32 mdatactrl; + int ret, val; u8 *buf; slot = i3c_generic_ibi_get_free_slot(data->ibi_pool); @@ -341,6 +342,13 @@ static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master, slot->len = 0; buf = slot->data; + ret = readl_relaxed_poll_timeout(master->regs + SVC_I3C_MSTATUS, val, + SVC_I3C_MSTATUS_COMPLETE(val), 0, 1000); + if (ret) { + dev_err(master->dev, "Timeout when polling for COMPLETE\n"); + return ret; + } + while (SVC_I3C_MSTATUS_RXPEND(readl(master->regs + SVC_I3C_MSTATUS)) && slot->len < SVC_I3C_FIFO_SIZE) { mdatactrl = readl(master->regs + SVC_I3C_MDATACTRL);