From patchwork Thu Oct 3 20:14:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13821540 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 5D2ABCF34C4 for ; Thu, 3 Oct 2024 20:14:52 +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=C+kwc15+UXM5V9q0TW3G612KpxVg97gNNdKgxInbcZ8=; b=iCw5/j+kLJPUaT0qJY2glAwxmB bfmaPqoxDUMxBb9xHQw8Z1doP6wo4s0D7DPez8MogIp6V/SCgQpgHjgF1rp8bXRhKjtTTQ5dd48fb jYHU0eiwRIqxPMgNcYVXnmG/RVumwpSChHdpXzBtoK71xN7Se/lwoWRD9mw9Vs3T63CmfHpGX5Hcm QiZgKL1OfXM3IaO1ZAYu5HxEQEpXiPPtOynPRgdpAd/229Ko8JydBJUPhTdvqcx/9B4rUnTAnHlkD 4I/fnlbrYaQvuxD7vM0U+65VQdmaSgaA1QKEZDV5t+9l6+roWF/yD6BiGoB4+VYbHXmPjev7X95bL tFvffcWA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1swSDs-0000000AHMo-0OcD; Thu, 03 Oct 2024 20:14:52 +0000 Received: from mail-northeuropeazlp170120003.outbound.protection.outlook.com ([2a01:111:f403:c200::3] helo=DU2PR03CU002.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1swSDo-0000000AHLf-3uul for linux-i3c@lists.infradead.org; Thu, 03 Oct 2024 20:14:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TjyKE2ucAaBhMvkKuz6mxnLCf7JhROHITIZnvDiY/ezHTTqkH8Di4269II6zEsWs2/ckzI+GiKqV1G2YFKomdTiPBMrgil+fu5O5fZzV9YiKbzF/1e82kGKZZM/E6PM/D3FpVkX0K+LsAR9HhcpTTioBsYXrZFpWmNP9U93sbNAu91Xza/dJ1dyHrejI5IXTC5NpTyFkqiL1tcLO6bC9AaUTu8531HdRAVzxabFUkfvuYMyMFaVbZOiDFe5h4/9IxiYuCGtVZEZIbGui8iXY1bbOS3n5oW4Y9+gjf5JmIvZQT0xrZqfS7/jKuAXVpabO9xCBloouYBf/n+Vm7mspTQ== 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=D/u6Y9ZMfX/Q1R8ZZt0lGNOvoJ+yV3wXF+hGur9mRoI=; b=hycc2sexGHQIbq27etK4eqcjO/a/VF34NE+osJpu7TBkAcubTnh1hZ2ff9sJZ7MoSsVfGqhHi3pG/hiaOy/hSohQI8n6c/B+tBTbx0HZxh5/OnFKhU4cjblHGUBMfcTHEzhjl/t/0K1tKAM3W6o402un4R6YsRJwpgch8BeJ8eQBAZb1Qx1+ay7wyvpiLWDJW2R349xjheaWnqe5S3lkSY38gvPZdolXp/+/snZ8LRJw1HqQq3Fcp1N6HDDtPE9/TGBmjyXadV4TFyrH5h5RWkUxgZEPnIY8lMjG3J+qktVj76tdO/EZXRKckVgvdXfqlPqAi3+ABPv9mePUn37ZuA== 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=D/u6Y9ZMfX/Q1R8ZZt0lGNOvoJ+yV3wXF+hGur9mRoI=; b=X0FUVkdod8Kcvk3MgvIphLPjeAeTzIUi4PwGoQFmhkDujQVzcAHrLIUSZPX3ItiB6e4fAS/dM70Aayu5VNzYLD14QSTLt17pbEwsBZvY7dPY2wmSpiHUKK/7ccKUzAvKgcEexp3psI/WXKk7iKpIrCnh7JZnYhrjoFdyLBELLGbGot/QAO4X0zDePUGHT7PK7WCDlKZ2KLERbcg4e0Wjd1rlH1ZEXYzptT6iomT1UbVCQx4QKUzlLxCZIih0EAl3RdxyGFAR4jetqRSasz9EiKmSIiYvbntnXEkHgpHNVgk1I4DbsmRq6pn1sHDpgGUPyv60gvKRhuiNuLJj2IFwLQ== 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 AS4PR04MB9291.eurprd04.prod.outlook.com (2603:10a6:20b:4e6::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.16; Thu, 3 Oct 2024 20:14: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%4]) with mapi id 15.20.8026.016; Thu, 3 Oct 2024 20:14:45 +0000 From: Frank Li Date: Thu, 03 Oct 2024 16:14:19 -0400 Subject: [PATCH v6 1/3] i3c: master: Replace hard code 2 with macro I3C_ADDR_SLOT_STATUS_BITS Message-Id: <20241003-i3c_dts_assign-v6-1-eae2569c92ca@nxp.com> References: <20241003-i3c_dts_assign-v6-0-eae2569c92ca@nxp.com> In-Reply-To: <20241003-i3c_dts_assign-v6-0-eae2569c92ca@nxp.com> To: Alexandre Belloni Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, arnd@arndb.de, bbrezillon@kernel.org, boris.brezillon@collabora.com, conor.culhane@silvaco.com, gregkh@linuxfoundation.org, imx@lists.linux.dev, miquel.raynal@bootlin.com, pthombar@cadence.com, ravindra.yashvant.shinde@nxp.com, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1727986479; l=2146; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=1vXOLZgsQFMbuKD3plBcCWtNrrRzSd/JO0oImYMerAQ=; b=YI/N+PJitl8UKnhClq8Ufr2kkVTjpnW1S7QpbfEUQsQlC0/gAnDnquQVjzIxnif+qFlZiNOUO MJuNXkbBgXMCmeqUCRVs+dMFNdZGB2qelW3O0lZVVD4ySVoxFlToHTN X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY1P220CA0008.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:59d::16) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS4PR04MB9291:EE_ X-MS-Office365-Filtering-Correlation-Id: 965ea561-7185-4716-dd25-08dce3e8063f 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|1800799024|376014|52116014|7416014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Jf7ZXr4GvRpF/6Mbu+zR18IpXz3EGZe?= =?utf-8?q?ZWwrm/cXW/OcztMHv+cCcPza3y2zR6FaLHVmb5fyAMAzbz+VqWWs6+bNAtMMjCFM/?= =?utf-8?q?y9cRLtPJHIwfdDTtOJwgY0VC7PeO/pf7lTQc+vUcpuO8hCGzeMVP5EhbkQZ3EIek8?= =?utf-8?q?N+liwfEY+FmJfWznX5qm//q3mWxBgDL5bb10/s1QTBadw+2Qv/9/IkVEc09pBTVH7?= =?utf-8?q?njlJQzfifNcu9NV+Ieu+U4ixDoHljIUwIuOPxKwDbg/EIKPdy5mlReAEeqt8p1LHR?= =?utf-8?q?5OCgrIyjI+zezBO+/M+lxgXU3I7YzMw/alwK8Qq8ld+RnmwCiJPOAZbC1lbfHC+Mt?= =?utf-8?q?BAFiPu4U1oMVl+Ec/NbxZCUvp05JBXO3CYoojGQ9IUrjxkjC62K+5202wMlKJ0n7P?= =?utf-8?q?2KG+s11XrcbWUNlosq8pzTkB7mad8hHuW740NB0x2HVx1vP8lFWwDMVL1zxRffQmH?= =?utf-8?q?KBnKxt4n0QrNAUYszTW26fWCRhRTKIXNFctzrAU3BZTuMILFiEZv2uAp/Di8K42Fs?= =?utf-8?q?GTtEMoZY9Y8D1mXqGRv8m8nzPQ8hvbfUUlZacV4lFIZ2egJy6wvOvzHA9IJxcoVyg?= =?utf-8?q?LX5e8BigRBhrhEmn5F0vKgpBuNpNgC1P1aKMXqfCO8CD2+Z7SFfrxUqpCcdkVgIb7?= =?utf-8?q?dRwZwuKDaS6GkNF8UwA4EJDk3KpDqAWHJPRzRSlSsL0Rh2793tor3ytQZajExvYZf?= =?utf-8?q?gvDw9epYCrVMlmywTjGFdQqtZxdroPjHr5UwWfwZulVWUlt+QI8OPNCrQndOWNUt0?= =?utf-8?q?u3/YfK7S6Yo1ttdE0r88p2q3lUkqa9nDJZfB1TLFqakJFbpWiqgcMnPHBnsC6dzkE?= =?utf-8?q?0O968rlQdQ7LviMGnV9Gx3+BJ9DEQNF22QoFTLuz1GioEenXqNgwjhQ0OZBhYrHF0?= =?utf-8?q?z9cvX2uWhzMKSGldgzZXI8xx1HxaQolor6xeqU9P0LHT1WigUFMWH5xMGa18o/FPP?= =?utf-8?q?uzmTXYysXa/rBePM8q4uoge7/HvXcfAV/Ypyn2YZGXKRGrQpil22wQNXnYsWbYnNj?= =?utf-8?q?1sHicYxOqD/6UaPyYhG11MxHxSgVT6sIa55//iAEVkofUaXCC1yvd6e3JNINcLE1i?= =?utf-8?q?nN71u5jJxsbC6Cq9us7AYQ/7W45w0tvpCt7PjMdpaeW7VjLx9gIroZO6EcVa4FtEU?= =?utf-8?q?sYX5BWpQIq8haPW5rrbqq+NgBdJjR7RtjmieDqBtZ4GeJq9UZvBW/V4JckZh6GVEn?= =?utf-8?q?HUwCtp9sYF8wKhS5CcgBWmv03LPOyN9qdOAuW+QBexmVs4hilZyfYVOT8fc2Vvbl4?= =?utf-8?q?/pHm7zznOeDokNi4A/QSjCX7+EVbiWwc92w=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)(1800799024)(376014)(52116014)(7416014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?SaOmJ7GxOMLhPSJR/2lFVX1+eZlB?= =?utf-8?q?zLQL4EPvLdxozSww8vH+TG/GmAfJYLF4C9aiupnV8sMDXbnsJFcWVeK1A3nqh3GL4?= =?utf-8?q?6elA22egoRR25rCyBiw+5a92k3BrMDSduUOnsrqOOM8conQ1bsS7GNyv7ITA8xl4T?= =?utf-8?q?2pDLUtPzFY0rYaRvx9sdqMf32ed6IlrPu64QmvE1Ltu0ZyKfq4ZtUSC0BjOMzSXTx?= =?utf-8?q?fkhSipwYUuYz/LPKq+9VryPjaRp+oQTFmMCGRxJ2ehzpa6EQtDQ6xtoBEtH+dRyVj?= =?utf-8?q?YH9zU5hKkn6QgnIywM94il0L/5D5qLB4c3EiWU7kE9/NMuJUGJJK+WTcg80kbt7DD?= =?utf-8?q?Nn6xJYukr57AZZQK5JdKXXIU5/v5xVBz6SCqwYnJdktTKV3knXtJtfnLhm2EXf70Y?= =?utf-8?q?isj0SQ36j1YTykX3VKpIeDvTyCCJrKbnWwmaHuq72xBrD3ADe2Xwe2wmIfzSnTRgH?= =?utf-8?q?Z9D7Wj0SQd34yQGMlA/8k1pEiUyAGVpqEtxaUnNNbxlRvPFBjn06xu6TIZKKZrTDg?= =?utf-8?q?kYKA/IPLB411RLjwm8AkbCX87MbyhRfw8bNqxaNw1gkPoUSw5KZa/X0RS0yZhwHMj?= =?utf-8?q?r/XHjOaqcTlU/pY5R71oLEYrN3wxLYORiAhsDpWr8gFeV31SfDTm8A9tI78C5EMmW?= =?utf-8?q?QF6EWYgZpp6U8PlZ0zFhZJ03xTL2Gz0mAC1JyymOVsEO11G30BxheA1X5VZ+MOjXv?= =?utf-8?q?dn0Lq0owjltPhY6CUp5ZKcIKiLAukIbF83X4MpuJ47U+QRy+0SRzMqqZcb/hx4/Sb?= =?utf-8?q?uTbf1WCx8j9oZ2d8H5CUcxZEZJMDswfIS6gFwYVBFca68mqQsx4TjpsQ5n1IqDm3v?= =?utf-8?q?NuXFamdo0HFxFkgBHF3A7FG4Tot0id6bCZ4h4OY+ZW9R4jz8PmbV688mWLKDTsNtg?= =?utf-8?q?E9wNozIZBAzkwlIynQy1+qMWuwMBSxCNuz8agTahVqvXnF/xtaKYuQ/WR7lat93bJ?= =?utf-8?q?nUVEtH0fjQGDguY0GE9Oy+OtgRJqWfpP+N5PQsKEILRr4WD5tXSIcBEahG507aZPL?= =?utf-8?q?/vI9tLCyaJOS7vxzWN48QNn90T+ce8EZyI635Lhw2ecnTMYzQydLC0I1HaxoonLYL?= =?utf-8?q?KNqrWMxrNlk1GG10CTWmkW/r1FG/DX7ykGehFosWLkYAPdIXj5T/A+Aoe/keVmsCu?= =?utf-8?q?lzRFhOuAFxHEOVlZnAuj65gob6yQjpnqu3MUhN/FoktPewUEOVoLvXojHH/AqawYR?= =?utf-8?q?gMXzrKcQbA9d3HXnT4CHMxpiOkvx9kBfaACm1C0Q/a2RgKcdy+jJuHjDjwMCn+xyH?= =?utf-8?q?KEVvSs8ZxK48wmdQ3+sQSBOeq4VhFbOj+vAPlWt9H5PAlO6MNT8aPPVRi6BfBqowq?= =?utf-8?q?kwCOG/77+tP65V8PLpuwwM3bepsNS9DD8edCjtMJLjfJchC/9gvmAxd1JisPanV1S?= =?utf-8?q?AFkRGPxTBkZpmtY/cRxmoCVLPPboSbVT7GyV+HxfuV4krhiG2PiPoJfhkupZzr+b2?= =?utf-8?q?JnF5tdjP8VDBoXguSpYu7sK5ghreB39yBRcpQn6ZmrZ+8vDoIe97MZqg=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 965ea561-7185-4716-dd25-08dce3e8063f X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2024 20:14:45.7309 (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: cNI/bvNpyY7bgdA9XRMEpw6wfGOCUHVGEP2O9wue/srrDssCgmRSgvo6A2qtZ/QSeKtpl1PI7n9MG7sSn8EW7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR04MB9291 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241003_131449_012959_C549E179 X-CRM114-Status: GOOD ( 12.51 ) 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 Replace the hardcoded value 2, which indicates 2 bits for I3C address status, with the predefined macro I3C_ADDR_SLOT_STATUS_BITS. Improve maintainability and extensibility of the code. Reviewed-by: Miquel Raynal Signed-off-by: Frank Li --- Change from v5 to v6 - fix version, should start from v5 - add Miquel's review tag Change from v3 to v4 - rename to I3C_ADDR_SLOT_STATUS_BITS --- drivers/i3c/master.c | 4 ++-- include/linux/i3c/master.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 6f3eb710a75d6..dcf8d23c5941a 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -348,7 +348,7 @@ static enum i3c_addr_slot_status i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr) { unsigned long status; - int bitpos = addr * 2; + int bitpos = addr * I3C_ADDR_SLOT_STATUS_BITS; if (addr > I2C_MAX_ADDR) return I3C_ADDR_SLOT_RSVD; @@ -362,7 +362,7 @@ i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr) static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr, enum i3c_addr_slot_status status) { - int bitpos = addr * 2; + int bitpos = addr * I3C_ADDR_SLOT_STATUS_BITS; unsigned long *ptr; if (addr > I2C_MAX_ADDR) diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index 2a1ed05d5782a..2100547b2d8d2 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -313,6 +313,8 @@ enum i3c_addr_slot_status { I3C_ADDR_SLOT_STATUS_MASK = 3, }; +#define I3C_ADDR_SLOT_STATUS_BITS 2 + /** * struct i3c_bus - I3C bus object * @cur_master: I3C master currently driving the bus. Since I3C is multi-master @@ -354,7 +356,7 @@ enum i3c_addr_slot_status { struct i3c_bus { struct i3c_dev_desc *cur_master; int id; - unsigned long addrslots[((I2C_MAX_ADDR + 1) * 2) / BITS_PER_LONG]; + unsigned long addrslots[((I2C_MAX_ADDR + 1) * I3C_ADDR_SLOT_STATUS_BITS) / BITS_PER_LONG]; enum i3c_bus_mode mode; struct { unsigned long i3c; From patchwork Thu Oct 3 20:14:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13821541 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 0F1B0CF34C3 for ; Thu, 3 Oct 2024 20:14:56 +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=SoiJuKnSqk3G2D7usLW9Qzgk7QM8rucwBLke6ekNUPg=; b=VEebxFFuXJbszWhbJmMldafT/C 63ZlyAiVqLJzApD6cRaSgZzVNCFUXqo7lXeXXOwo/yvjvzKtt3SYBTBAFiNSQ02iJM/PsFhRfbSIt z5whJ+K6EYXCKqGPcUsGdAM7G6P2ej3K5bKZl+loB/noP1nVhtf7yoQjWu4sCovpTaV2IrAQ3onZ+ txGouLU9DEc7jZC/YYqpNebyvJNC4MHbGCwNXWlUAg8uzLpR/1ZMmnhhaGfhDJW5AnismFaN/LwP7 qX91/rYWq5qNHv2A7eS9BgLRHM0GcINmoVEg6346MCoC+2AqNNEj4IKx9no0c/S6hKPI7b1japHJk 8OsausDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1swSDv-0000000AHOW-3Bif; Thu, 03 Oct 2024 20:14:55 +0000 Received: from mail-northeuropeazlp170110001.outbound.protection.outlook.com ([2a01:111:f403:c200::1] helo=DB3PR0202CU003.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1swSDt-0000000AHMn-1Epj for linux-i3c@lists.infradead.org; Thu, 03 Oct 2024 20:14:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JyG6C6e8hB2ThZcvJmAGMuWutIhrgbAPATVEClEVqvt0Qb17yDW30gOmpIbEvYX8CnrmErusvTYIm1DbprDFfoyaOe9uHtqYKAcigvnCTvk6ojp8Nylu9ih1r0P7prqytmho/r1sRWzJ8rU12fQLjn2SVqwsBrerEOT4TswO1Ba7NuSA0Ogsr4rnlB40gf/dqB8Nt5CCKtj+xbYW92keMxFGv+jogjaS/yct64oOh82OrYPT36YOABNUc3/x0WYY5Tkz8UpctDfpeWzCTWojHuYYePEr4Me+S0bFp66p71RSsSYJzD5eU35C83FJd1t5auHLuJMVliOqdbRCt5x8gQ== 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=1AutemPq5Uze2cW43m6UfBAV9GC9qmzLYuHVO74gWdc=; b=l0EmjAAnjeSa5C3oMseK8RDPStjjnIwvWZBxrzIM/hkviPNGFOIHQqdBUfKrlHWMeIjfB+5SPgGCTqhyNVDwZRmS7NhoukecWegDfPDx2o0aPDKMOQyJu1MPsxQKN3Bqkdyg+ZNejvS7Z/7FUUiwIhkgaDWpArM2GcWSFCeYjfeommLT1b4KAnbsTItR+7TvNp2MhrI6Lvut/rp6wtg49Ru8xrkecrIbw9zbX3BweGHjRFlpi+tTB69ijwEyIjF5g1qpLXJeKUkhSP7m43+Kt8DUfrbreE3/U8YCgqzA1VvmkJnvQzz7OSPKwGKeD65ifMNX5dpaBRtCXjkK2J+fQw== 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=1AutemPq5Uze2cW43m6UfBAV9GC9qmzLYuHVO74gWdc=; b=J4t2iVd4j0ryeV4QUaoq721b5hjDBrQcgGdZ4xu0vYwUH+VDV/pEk+imtnkQJBh+SMXNag3I4Twho4cVPDnd/TJvzZgTytzPO1MZ/+Dm1eHFe93bOL1WQ2rtwT4syzSs0r7K/HpnaOLS9mX6wABOrfnJpEqlLZPLPyWsJzWGFWCz+yZUw9E7N6Kx5IkGNgNp146GYoaNHuzz+SMR1tS6gyX2058kMCQiwRiFc/SDDX8HQw9bskFEhQejAAM4sB1mfia0H57e4fyGqbqhJ0uDMRjX6P1owmCYCABM+LyDp8NG06NuJaqDD3/eXAPSPe6DU78Hrr0Y9YFxnSEUeheZ7g== 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 PR3PR04MB7481.eurprd04.prod.outlook.com (2603:10a6:102:87::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Thu, 3 Oct 2024 20:14: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%4]) with mapi id 15.20.8026.016; Thu, 3 Oct 2024 20:14:49 +0000 From: Frank Li Date: Thu, 03 Oct 2024 16:14:20 -0400 Subject: [PATCH v6 2/3] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_DESIRED Message-Id: <20241003-i3c_dts_assign-v6-2-eae2569c92ca@nxp.com> References: <20241003-i3c_dts_assign-v6-0-eae2569c92ca@nxp.com> In-Reply-To: <20241003-i3c_dts_assign-v6-0-eae2569c92ca@nxp.com> To: Alexandre Belloni Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, arnd@arndb.de, bbrezillon@kernel.org, boris.brezillon@collabora.com, conor.culhane@silvaco.com, gregkh@linuxfoundation.org, imx@lists.linux.dev, miquel.raynal@bootlin.com, pthombar@cadence.com, ravindra.yashvant.shinde@nxp.com, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1727986479; l=9085; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=rzbrQPx0d2MOqsRyyCB0fUBaULbidlCEWYXgPMvvdlY=; b=eGcMTUdulnGr5kNKzZqZ4nRcY751Gpu3hXzHQNFg0+cppo9aKjmdGlkvaDYncqU1reU/pfGhq kxLbu9QdsW3DdkbHKSMkYMivPh4al2XXjzi5LRLzQ113N8ex6P9KYdl X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY1P220CA0008.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:59d::16) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PR3PR04MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: f214ace0-38a9-4e08-f870-08dce3e80835 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|7416014|1800799024|52116014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Adx3WVFBoBtKprWJV2yYkGrXK8IUPh6?= =?utf-8?q?wCR2YNdb352D7z7cvu6ltJDxCrQfgFEKZMfKrYyN3rVp7HgM4S6HMxCpm0nqL7ZOi?= =?utf-8?q?L+sF2ij8YQVVQiXijReWjuGaQzfobx78N7SgeHMwQ9CHLaid/koTxAcHjtwTOruqI?= =?utf-8?q?yR9Gpe8ElHn3pGkDeqBBdledfPJyCOXzofn5G1t+RZsXUzvE9YMjkepfaWoPcvhvr?= =?utf-8?q?lwX0HFt4v2RtjQhg8nlGtN+eL39MapH2V2e2YS3iB38HMtFXB9YEFMUBWYTRuq1YX?= =?utf-8?q?iwPpN3khidYvDnBtho6lMlhuLvPx5TDI2ZFbr1dSA6CAGeFuM0kb88/SNFUtQM4SC?= =?utf-8?q?rf1taVOQCOkO9PkBAxEWqaKlnTNNTD/zfzwR8gW6+TQR9YiTwXQ0NWO08lblCOCAs?= =?utf-8?q?FOjD92OzgE7u3VNRRCGS3OWehCH+z9JtKYCvrdkFfqYfUiWYh45+aloltst9nTFfL?= =?utf-8?q?vcJ11sWpGoHKf7AWOT/9xwNzNgLlSbyg9vaMWvR9142tob9KdOTUDZfTjuXyzYs10?= =?utf-8?q?nUTFANVMItrJ1A7jcks7QgSrN7VfybQZkikAaydcWvOgYblm0688Uvd2bvycpGyrk?= =?utf-8?q?MFIejQYr+I/7BWkMw5c/KQnDf8XcsJtWEdl9OAM0L3Z/XWoygy4xeXgxeAaKXDGZg?= =?utf-8?q?cao5ZjSz/zTZ4ZxBYs1C9ePM2647JE9dpq8JkKCigYNAUa53TU5gOBZGkCLv0i0OY?= =?utf-8?q?AEoJA1hOBklMJ3kRpICBCOu7rEazyne4zF4yzXHyze05IOnRwKcKWrtQOGiwhjyhN?= =?utf-8?q?jicNTKNkUGnEPTzqr8YUJ87iiCnDJS4csCRp9ySdaSRpy44v1OZyIHBLzvmf4w3h3?= =?utf-8?q?H9BKIsblK5srIqVdaUtPCzjLC/o9ER/nvR3Wpmna+WWtkfHuTmTJdDy2Nf0+a+Lpk?= =?utf-8?q?0k6ljHOnQws/vBbUgR+aXMCz3UztOMYMUen9nO3JyOnVq52QDWisEx2U36c30sZQ4?= =?utf-8?q?6aWwqztmfoIpT6m2UrcWrTvUOliKRqRHX+q19n/UgBQocMI6yH6/jb+lTgOlxkc9e?= =?utf-8?q?scOEFzrW3Qev+oqmfbbjygymCwxpm8pTWk69Km90mj36RbLOdpWrnpPOnHfWAdJOw?= =?utf-8?q?YXGwPbHh8W3K+2eZWmuI2FSQXxV/stqEWzCLS0o0Mo9rdBszBm1xrt2R+WQYoZ0eN?= =?utf-8?q?pBdmFnHTZZt9BxK7+prSts+3NkUcB1pLRXnUGhMfwEcH/hoPARUy83reL/dIsvAkE?= =?utf-8?q?9lIyZckfiFg9aRXdYjGQpyuzzDPwLNOXDFIhH9XOMiQWwicVjFsH5fmV91Xvj3gLX?= =?utf-8?q?bgBFcDQvtTNwFN3CyBDdFQgoOBBCH928mFA=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)(7416014)(1800799024)(52116014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?AzAkmb75BFGnn0IJO1IIrTXkwjHW?= =?utf-8?q?gsdDpcQC+7kos9z/litVAkUIzxPZex6t5yc3ehTUaj/0w2/yK0XwTDHCjnnubbUzN?= =?utf-8?q?Wp7m/OkoPHv6aRDsZeqm7kq12hvjyIloozUQhJyZ5NYf8cUC+6JNA4KB1a+VebBmJ?= =?utf-8?q?m0gRNjGRtL056Z/p5NZa60nIT3YWMX91r8J9pxH97hO44N+XETESe+XPtXqkGgEbk?= =?utf-8?q?fVpyE7smIH9j36p8KQhKGF0vUlcz0LZCZRiToYkj/qh59Ccg6lWMrR1aU9z3Qdpxe?= =?utf-8?q?5JYbTKBQTzLRK/zUM0s/jOVRpo+69xGhE24YrQQVQW5TqW3EdmDGkanvNBUy8B0cS?= =?utf-8?q?NL5dBPMmBd5FLSLiaOoVQSxzfNjXWSRYdlq2KsqQiZJQpUY4tv/NSgx7F1gRENicx?= =?utf-8?q?4IjPinNzTKfG5J1B3DwQclK5DX13E8SJLzZ//riBzbipj7zPQJfK1pp/AMQDPDelQ?= =?utf-8?q?pGW5I8J9HFW3BU9lzk97FjVi0ttM9SkG73/6EXR1aiewlKfS8V9ovsQc/WPn16P0f?= =?utf-8?q?4pdwi8CEmKdZfkAsgFojdwyyH4qEnI1iVHXI2+sefMlZqo0keWVlQbYb+TXSu81U/?= =?utf-8?q?6kM2+qdp0sBMv5Ywdc+13tkYTF8saDIFEe4tz/3zs8nuZmJk13MhDjN2Bx+HJNIPD?= =?utf-8?q?CCtH99manHAWE8RarpXpTnLWQbGrGrULJY73JHWlXtXtaoy0hRHhTA2X4HVbP8+Oa?= =?utf-8?q?6s4QWaEgGI3LwZkaKs2n9pIN22sEpyqnWKffhc6E/fMwoqk7jE8uEgszRjBF5KC1G?= =?utf-8?q?HHxBEsxvO0uXnysgFLRvsYsRrWPp9Hr7N6eRktb/86VWR+M86WlVFfM7q3PgpiVrz?= =?utf-8?q?xSJQwj0Ipv67GWtbSnZH93pU7juywHhaTjm64/Vordmh9aIfx7g3zs/lzXbHqJ3wp?= =?utf-8?q?kIjjKAKibZ8pvqIwSkNyDJWAuuoeFdszVhbHVqS5V6zQmjPB+axkECeoPsv0ieoQG?= =?utf-8?q?F1CQGJl3FLBDbAqMOHnXu7T4J3NRowDYAegc5zSTD+HA5R1BDmCExaMYSZPbnGbaB?= =?utf-8?q?li11XNN0E8Ow4OH823gx4Gw1r9mjuNQAmLy6W61nSSzOuDlgtm7CGVSXF2mieQWQj?= =?utf-8?q?zNpemptssH2QDmp6rMXlylc6HWxk9tiCNpmd/5TmU/gl4X7brqx6zxrvHKEPPVNKY?= =?utf-8?q?Y00TPy075Okr8wFC0//opSbIhkDWYUk444q893aoeuJIgXPY7DF6sFkX7xel0KxYL?= =?utf-8?q?LsKFCz6Hw0FtqGrj8UT8mMKPC9VvsqzK16u9HfSpSBqiERmb30/e6yd/I6jvZzVsv?= =?utf-8?q?qQVPzdMhvuA4QWMGxa7IEY8f1vLJmce0X6wHJ+3h7wbPggjG6cf4AyjKg1inm2Ad3?= =?utf-8?q?7Yy+4jRJWGdURjt0HA2lJ2ucxLFJmagqu+vuypPnoQMcjqakWUtf/nKKZrwGvcS2V?= =?utf-8?q?LiDtnbGf2ybjpkmBAIPCP3fmQQTxPUTGBpF+nJnuqBtU/18SMnGVL1mEPzgmbcMb8?= =?utf-8?q?F92rc8EyCaqFVhIS0Ft4vqIJawfKLE0BiLWXcQRFo/qaQA5bhjxGlJoQ=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f214ace0-38a9-4e08-f870-08dce3e80835 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2024 20:14:49.0905 (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: RtealSHcvvDFkwYhNRVyuJU/y/8UzMhh7sfZvIrpUH0adq270tb1pd9qFREEaNeKuvGlCQKT4Apn7/5H61Tiyw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7481 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241003_131453_517611_DFFEDF31 X-CRM114-Status: GOOD ( 15.77 ) 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 Extend the address status bit to 4 and introduce the I3C_ADDR_SLOT_EXT_DESIRED macro to indicate that a device prefers a specific address. This is generally set by the 'assigned-address' in the device tree source (dts) file. ┌────┬─────────────┬───┬─────────┬───┐ │S/Sr│ 7'h7E RnW=0 │ACK│ ENTDAA │ T ├────┐ └────┴─────────────┴───┴─────────┴───┘ │ ┌─────────────────────────────────────────┘ │ ┌──┬─────────────┬───┬─────────────────┬────────────────┬───┬─────────┐ └─►│Sr│7'h7E RnW=1 │ACK│48bit UID BCR DCR│Assign 7bit Addr│PAR│ ACK/NACK│ └──┴─────────────┴───┴─────────────────┴────────────────┴───┴─────────┘ Some master controllers (such as HCI) need to prepare the entire above transaction before sending it out to the I3C bus. This means that a 7-bit dynamic address needs to be allocated before knowing the target device's UID information. However, some I3C targets may request specific addresses (called as "init_dyn_addr"), which is typically specified by the DT-'s assigned-address property. Lower addresses having higher IBI priority. If it is available, i3c_bus_get_free_addr() preferably return a free address that is not in the list of desired addresses (called as "init_dyn_addr"). This allows the device with the "init_dyn_addr" to switch to its "init_dyn_addr" when it hot-joins the I3C bus. Otherwise, if the "init_dyn_addr" is already in use by another I3C device, the target device will not be able to switch to its desired address. If the previous step fails, fallback returning one of the remaining unassigned address, regardless of its state in the desired list. Signed-off-by: Frank Li --- Change from v5 to v6 - fix version number, should start v5 - change to I3C_ADDR_SLOT_EXT_DESIRED - remove _ext function and direct use _mask function - rework commit message and comments according to Miquèl's feedback. - change mask type to u32 change from v3 to v4 - rewrite commit message and comment for i3c_bus_get_free_addr() --- drivers/i3c/master.c | 60 +++++++++++++++++++++++++++++++++++++++------- include/linux/i3c/master.h | 7 ++++-- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index dcf8d23c5941a..68411f1cf80d6 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -345,7 +345,7 @@ const struct bus_type i3c_bus_type = { EXPORT_SYMBOL_GPL(i3c_bus_type); static enum i3c_addr_slot_status -i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr) +i3c_bus_get_addr_slot_status_mask(struct i3c_bus *bus, u16 addr, u32 mask) { unsigned long status; int bitpos = addr * I3C_ADDR_SLOT_STATUS_BITS; @@ -356,11 +356,17 @@ i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr) status = bus->addrslots[bitpos / BITS_PER_LONG]; status >>= bitpos % BITS_PER_LONG; - return status & I3C_ADDR_SLOT_STATUS_MASK; + return status & mask; } -static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr, - enum i3c_addr_slot_status status) +static enum i3c_addr_slot_status +i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr) +{ + return i3c_bus_get_addr_slot_status_mask(bus, addr, I3C_ADDR_SLOT_STATUS_MASK); +} + +static void i3c_bus_set_addr_slot_status_mask(struct i3c_bus *bus, u16 addr, + enum i3c_addr_slot_status status, u32 mask) { int bitpos = addr * I3C_ADDR_SLOT_STATUS_BITS; unsigned long *ptr; @@ -369,11 +375,16 @@ static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr, return; ptr = bus->addrslots + (bitpos / BITS_PER_LONG); - *ptr &= ~((unsigned long)I3C_ADDR_SLOT_STATUS_MASK << - (bitpos % BITS_PER_LONG)); + *ptr &= ~((unsigned long)mask << (bitpos % BITS_PER_LONG)); *ptr |= (unsigned long)status << (bitpos % BITS_PER_LONG); } +static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr, + enum i3c_addr_slot_status status) +{ + i3c_bus_set_addr_slot_status_mask(bus, addr, status, I3C_ADDR_SLOT_STATUS_MASK); +} + static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr) { enum i3c_addr_slot_status status; @@ -383,11 +394,41 @@ static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr) return status == I3C_ADDR_SLOT_FREE; } +/* + * ┌────┬─────────────┬───┬─────────┬───┐ + * │S/Sr│ 7'h7E RnW=0 │ACK│ ENTDAA │ T ├────┐ + * └────┴─────────────┴───┴─────────┴───┘ │ + * ┌─────────────────────────────────────────┘ + * │ ┌──┬─────────────┬───┬─────────────────┬────────────────┬───┬─────────┐ + * └─►│Sr│7'h7E RnW=1 │ACK│48bit UID BCR DCR│Assign 7bit Addr│PAR│ ACK/NACK│ + * └──┴─────────────┴───┴─────────────────┴────────────────┴───┴─────────┘ + * Some master controllers (such as HCI) need to prepare the entire above transaction before + * sending it out to the I3C bus. This means that a 7-bit dynamic address needs to be allocated + * before knowing the target device's UID information. + * + * However, some I3C targets may request specific addresses (called as "init_dyn_addr"), which is + * typically specified by the DT-'s assigned-address property. Lower addresses having higher IBI + * priority. If it is available, i3c_bus_get_free_addr() preferably return a free address that is + * not in the list of desired addresses (called as "init_dyn_addr"). This allows the device with + * the "init_dyn_addr" to switch to its "init_dyn_addr" when it hot-joins the I3C bus. Otherwise, + * if the "init_dyn_addr" is already in use by another I3C device, the target device will not be + * able to switch to its desired address. + * + * If the previous step fails, fallback returning one of the remaining unassigned address, + * regardless of its state in the desired list. + */ static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) { enum i3c_addr_slot_status status; u8 addr; + for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) { + status = i3c_bus_get_addr_slot_status_mask(bus, addr, + I3C_ADDR_SLOT_EXT_STATUS_MASK); + if (status == I3C_ADDR_SLOT_FREE) + return addr; + } + for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) { status = i3c_bus_get_addr_slot_status(bus, addr); if (status == I3C_ADDR_SLOT_FREE) @@ -1918,9 +1959,10 @@ static int i3c_master_bus_init(struct i3c_master_controller *master) goto err_rstdaa; } - i3c_bus_set_addr_slot_status(&master->bus, - i3cboardinfo->init_dyn_addr, - I3C_ADDR_SLOT_I3C_DEV); + i3c_bus_set_addr_slot_status_mask(&master->bus, + i3cboardinfo->init_dyn_addr, + I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_DESIRED, + I3C_ADDR_SLOT_EXT_STATUS_MASK); /* * Only try to create/attach devices that have a static diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index 2100547b2d8d2..6e5328c6c6afd 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -298,7 +298,8 @@ enum i3c_open_drain_speed { * @I3C_ADDR_SLOT_I2C_DEV: address is assigned to an I2C device * @I3C_ADDR_SLOT_I3C_DEV: address is assigned to an I3C device * @I3C_ADDR_SLOT_STATUS_MASK: address slot mask - * + * @I3C_ADDR_SLOT_EXT_DESIRED: the bitmask represents addresses that are preferred by some devices, + * such as the "assigned-address" property in a device tree source. * On an I3C bus, addresses are assigned dynamically, and we need to know which * addresses are free to use and which ones are already assigned. * @@ -311,9 +312,11 @@ enum i3c_addr_slot_status { I3C_ADDR_SLOT_I2C_DEV, I3C_ADDR_SLOT_I3C_DEV, I3C_ADDR_SLOT_STATUS_MASK = 3, + I3C_ADDR_SLOT_EXT_STATUS_MASK = 7, + I3C_ADDR_SLOT_EXT_DESIRED = BIT(2), }; -#define I3C_ADDR_SLOT_STATUS_BITS 2 +#define I3C_ADDR_SLOT_STATUS_BITS 4 /** * struct i3c_bus - I3C bus object From patchwork Thu Oct 3 20:14:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13821542 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 A8949CF34C1 for ; Thu, 3 Oct 2024 20:14:58 +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=Aebm9lJQfQrlw8lcQga9iySUyTsMgO5IpVqktYlnTpM=; b=MnBwec5EtX7yRa6DJeiR/0wJ27 TnGcYhdy8l4xSWQwWQOaONaPIeeaA3mh0pwiUSxEZP5oN8sK2SqtTFfgNmwj9BOcAZWjTECIB7Y5A zIDvHSAvfFNzXVcK0htX80fMogucs6CSznQQWndqUba9yKRpQTfQmCPGnWUfZe1xFbETbK7zthKgL XJLOajbYcXzLudHfEAcwemJ+8KerjST2R0rIZvJulY2nSYfawhCwqWpRJh+TKGsuO5zAMP/ZC6Q7m vJ3yqX7s+xbfTcNUrLbjaN+Jbf3Qmebeb2y78Uj4QfxspYdN/DEdOkAxCBVgAkRZb0U5Ir6JyHPZw NWdDl7VQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1swSDy-0000000AHPW-1hH8; Thu, 03 Oct 2024 20:14:58 +0000 Received: from mail-northeuropeazlp170110001.outbound.protection.outlook.com ([2a01:111:f403:c200::1] helo=DB3PR0202CU003.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1swSDv-0000000AHMn-02qg for linux-i3c@lists.infradead.org; Thu, 03 Oct 2024 20:14:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=c1c83FSXWtwL3gNL37mEDlLKSfcLcKNEZtJVsbeUp0o+6awlU0HpCQDx1giXiNu5NS9yAKNHtOZqDoGCxB91pyu4Y72eopb9alrniZJxVc0AkRf0L/uC86IJBFJ0tuXVGqOk0TNUbzyS7uOBKt6q4qj6gLEKIJchdbA+RxKZ4HwiS0Vh9IBSCAe6BMDgTObst06BT8L63M7CpNpS364Vr5Zy8Ik8Mv3OWlU+jTM4vS0QdML8UMG33249vbjqDLNWfwKkbmqAhBDz1+VzVx19Ly7B0+zZd+9ZMdvc4qFfEHNdasGjN65GDcsthMpLv0Xq9XTqGF1BPIt/d48z3rSefA== 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=0if/ydm24wIbbYdZueK9zG2st0g0wGo5taHXKt9KGfI=; b=hW9fUyC/r09Mnt6GG2L9Lo467qc/b6H3A5VUnPym5ay01s7qIqiHrWUke5sTogeUays2mMckLnOrev0NSESynlZc5DnAjB1eAYYoR0KMrSREgOCmpp+jk94YQMdwv5MCSZYTnbFwtAGmt1aNsN3SWjVRilACArmh1gDGyyzrB2z9/C8Xzj67zcVjjY9F24AS13Z6oy9V7JLoWUZxe4i5K3N+P6RD2yK8WGUBafvQsdqhvdlpJTQylTsHpACjvyMcP9kRJboU1TPVR5J3DZvgVGznU8SlRqhPMafd2PUYBO3ZgE+S/aHJHtffTQcoSe1OmmcvSdvQdPPl6fzCm48vdg== 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=0if/ydm24wIbbYdZueK9zG2st0g0wGo5taHXKt9KGfI=; b=ZtBOLyJecUzODAFwknZE2zr+1ZJPkFt2U1DAuqVrIwi+fX2qdPkTGfTEzVygwaBbL+K5HL7jDCVj5bOzwy1wprqCk3wbnvbA95Ol3/tS/VfMdMngl5bIOzvzs67ZylnDulENJWo9YAMgC5RAOEHyfaYp6mVXNgPamGDzzW2Zpd/hDgtDmIst9E/gsy372fyf9MIrANVpg3rZHhVLsdVRz5OOJ7WjYk70MY7R29RY5TGb5QvdZRubwcnAqJdXo4aAcpIsC2QDmrbqxVvy2vwwrziywxK4ufYN4devC9Pp+dzrm8X+SvYyoQ7L9Wyi/dUgBpr8txJmd6Hq8xmSmUDvFw== 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 PR3PR04MB7481.eurprd04.prod.outlook.com (2603:10a6:102:87::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Thu, 3 Oct 2024 20:14:52 +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.8026.016; Thu, 3 Oct 2024 20:14:52 +0000 From: Frank Li Date: Thu, 03 Oct 2024 16:14:21 -0400 Subject: [PATCH v6 3/3] i3c: master: Fix dynamic address leak when 'assigned-address' is present Message-Id: <20241003-i3c_dts_assign-v6-3-eae2569c92ca@nxp.com> References: <20241003-i3c_dts_assign-v6-0-eae2569c92ca@nxp.com> In-Reply-To: <20241003-i3c_dts_assign-v6-0-eae2569c92ca@nxp.com> To: Alexandre Belloni Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, arnd@arndb.de, bbrezillon@kernel.org, boris.brezillon@collabora.com, conor.culhane@silvaco.com, gregkh@linuxfoundation.org, imx@lists.linux.dev, miquel.raynal@bootlin.com, pthombar@cadence.com, ravindra.yashvant.shinde@nxp.com, Frank Li , stable@kernel.org X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1727986479; l=3769; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=Yb5+glUNRPlFHl6jLjq7YLk0v1GoaUIekn5edA0U3j4=; b=EiWoxD2VbobWJQpPxlrQ2U8mFYbrEU/I/ns6W1eQl9ac8bLf/0xgx6EY/pFbtZyPzJ2JDjEZw fWWUSlb+1tUCS60vhhhFSP9mUGdAqXsEKMzZFeiqDgylkopLXu9pjde X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY1P220CA0008.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:59d::16) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PR3PR04MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b006c73-d064-42c0-cc31-08dce3e80a4f 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|7416014|1800799024|52116014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?jkuYgvHtZw8xsoA4+4UQWN4b4uyjmyk?= =?utf-8?q?ocHigbZffHGtaJvP/zLBb/lMKCZfiWovXH9omQ3svMokiWf6Itthg2r/tNMWWB+/l?= =?utf-8?q?X10mLcHRst51bymZOvdotahndhV17rWUottldDxdaNzq5hbk8ItQ3oGIG3VFMCyn4?= =?utf-8?q?5J6H/mWG+vFbe/fj/JxT6V0Y0+VOnMafOQVvE69MSx3WQ+cIycMHJt9OdPaNNkpdY?= =?utf-8?q?RVvA0SrW/ujDqNkco3mHvLoSsOpiX6SX26vVncmaDHwH9Msssjqtqg4zyAPGJNikp?= =?utf-8?q?vh3595r4Oo1Si9/aaPQZLd2ywfzWP6gGV9nJ1LRYOozKikv/UEEYayX9+1OjuyKLO?= =?utf-8?q?BG8/EGO350R2svfnjoo1jb5IY6o8HxJ3xdVniL/q6sEwyPy6ZN3J1VyukefKou9jB?= =?utf-8?q?lIhS55vTadjl0D0i0bZGITJiLKrrcSEZ8nMzESP7iIofNDCXuMS+W1Hrf3lKajcc4?= =?utf-8?q?JiN/5/xP7Q5a/q5+2FLnZEJK0eghtsc5gw2IdocClFhXP4NBbFNNgY4B1A/naCD7e?= =?utf-8?q?EPi7l2AOAZrgrDxINu3n6bUd/oL2pfByvo/mCPS2GZJd4x6HPqTEC487SwVfFdLqs?= =?utf-8?q?h1AFoZB9Os0qMzwlxcVcpRnN7vtwIuvyMpsTzXssM3xXABG21tmlxWTkT0Cf6yw51?= =?utf-8?q?Fm+rAvy3r4qMRLNYwr0lQr5zOGl08s7ShMQAc91hVBvrwUv+u0Amnith0d0qO9x4G?= =?utf-8?q?4Hsi4oxQVEGIrSzYpo/WdYsnfaNp3t+kPeL4JRy71pgg7fnoveKNXk2uzl9tmjlNu?= =?utf-8?q?2Onxaq7AL/4WnjAhqm9DUx59u9QfRbrs5Fbd2+4SzVsjR3hkSIKnJw7tN+bHcoxWQ?= =?utf-8?q?W9uzesEsFVpy36jDvynybF/bHzWYaGUFb0BMYruH5F+Ak8xPxEasvRz7yaqc3D7DX?= =?utf-8?q?wZOp3SSbVC3vjHcmA+OvjjAfvgCdxokypBp3VicJd9FImkvx28wRS1XtMqcqRzJ6K?= =?utf-8?q?cidJC8OA7p3GVhUXz+HIJommWDDo5EnCZPCh5fhvW1D1JPex/ja6ZMT3BTGCTIQfg?= =?utf-8?q?WFCQJcHuaN7MtsLDuInKzYfSdM8Nzce/WFoq7X2Cx9riQty3W1W3m60YLNxX9b3sU?= =?utf-8?q?7sGCOoVdrZukW4zgCFzkIT9o9eyHVU5B6fazOrYMVY2joYbeSULM9NcKdUolIleaG?= =?utf-8?q?PKdEKZy7OMQiqtR5YByEr5N3Xs6s6kOT/Lo3QZ3yM4I1LFBlCYwISZJTXWmntToHt?= =?utf-8?q?uNviAjUR1Pzs5q0jVrzH33oYG9v5IHdjebA2yftaVqx/2529tBsJUbPfoTbkaH4Bj?= =?utf-8?q?Txu8ZMEGtwOVetjpU8kk6ksO+/L4TGnUvmg=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)(7416014)(1800799024)(52116014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Y1u1l84OTGxaWyh4RvOPdiqszNEr?= =?utf-8?q?E6kTiPtNYkaPu+KOIMI2zWdwDvh+ekhP2/AbDbD4Yh1XmBaNm66lEwIkugg27rJTv?= =?utf-8?q?bLATHLtIup40w0NCV/RDMqOU2dwLFKbNc1YktgI/Hc/9H7Szv9668EETKOSv8XRVN?= =?utf-8?q?YRV1rd1yjz4LCNV/B/qWmGzx3z4TzKMwZ+MgwnqjjoY6QF3xRPTODO/0iuOaobrNs?= =?utf-8?q?5C5H1YxTYISCyjrwj6oaIVX4glNDqUi3HLDDZfSU+/dlMTuvnJ3vePDDjY8GuFzx0?= =?utf-8?q?uVfxnK6pXdSjJNSlMqnKI4n2n7fOQh24mFzZdQg7KAEVVC4ZETeEtO0a69axJupa1?= =?utf-8?q?cUjXsK/shxutDxku3X5597vcwG5fI41Gf61IoQhVIu79kU6fzjZg7bxK7xM9uY7J3?= =?utf-8?q?KC/pmkMUI4lXgKzsp2Mg7SRZcKaOt4ll/LE4EqP8YNLJhDQdP8R4BLkckv3JQgTzI?= =?utf-8?q?72hJS4RqLDVr4IjMnCoylJgjbCE7gRcEhTx+DkUo/7xr1Dv8e5leniF0JgqPMBufz?= =?utf-8?q?OmtOwfBuOP1ff+Mz1CR8IU05qNdq1aECLVVUSUV8xnwUy0qe630rR80Cxc8EX+1Hf?= =?utf-8?q?jTP2uIgQzjjJFZtbLxBGUHwGKE5M45AA8Y3j02A0y494CPxyIMHXxpI/9cYRzSSCx?= =?utf-8?q?6Pr1RzILba46hYcFrhWC9NXzOOLaGbKBtepo/N7DYxcJlhTbXV3jKE2pl8rZhyRQ3?= =?utf-8?q?hxDL+EslA74yUH+Q0AADSafQqHZskYZ/3qJ5L4Cx02PCzPLUGbIG4afjHpmxiKzU2?= =?utf-8?q?HPWJIVVI3E74n51LVoevNKTAdxiPHGfVsxI4vdaVVZCuNf/GrysfO4WJtyeynclP1?= =?utf-8?q?RiKSolK01GRXlyRAPzXmLL/zV75WGQO1BcSIv7OGg2ujSEImQ3at6tPtusRc6m6G/?= =?utf-8?q?6tLIsO6i4W4eRMfdw94zDKki/gmqgV4sXOb8sEdmuC16qpzt0AKAy2fGQ97VOk6ww?= =?utf-8?q?d0mjbARneytu8yA/laYSYDJ9SL9p77MFQ4xnJccCi9j8yM6z6L55OsYvrB946A9yW?= =?utf-8?q?dl5+/AN+S0GTJWELbkZTvfIfsmgl3kYHFUumdiKroOOWN2iMuqnSlD/vdj+9ec/N7?= =?utf-8?q?HPKiqd//ezsQ2+JqdnBTbKRSaFC9oCWN6+MMIe/2F3/8i8WuCs5r9z1qwS9/QWdTE?= =?utf-8?q?FWUERi9VcajgtlCLWj45V3SzeNNZ9PKbuyDTBFzzi7AoKhxT7DuDZyrZWRQYwejyu?= =?utf-8?q?tSTuZlB6M+u5x6TOfg3s7GFlKKTJ8vMLKeXYX9n1T5m2xRY8ad5SHqkCnx2047CvR?= =?utf-8?q?vQ91SAIUDqgOEA2aoGyUe7nN7rT6aNmu3dDNbXVPrudH8xUlO6yGlgr3Bu9zpl5vM?= =?utf-8?q?/gumH5fT/LFfvIvkkXUyQpcTvwg2nuqqmKMYMmx4ky+B+PFe1P+qOdbfvb9DZZ9A5?= =?utf-8?q?Hii1VnvntayMXSNXunGTYvUFP8WYvVo/cVUCaRkIFH2jkJLO/2/QcQSl+o+EdGfzJ?= =?utf-8?q?TD+s9RJUezA6XV8OWaQZhzOiJbIcMhnuO4P5lhNfXl8AC0hPrg7RnI5o=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b006c73-d064-42c0-cc31-08dce3e80a4f X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2024 20:14:52.5704 (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: xdFY5mw48Em1/shn/mHPwrLpXSHPvbGPtKKWdsePYy9CpS/RazgKtTXu30g+KDbGZv0J1xHsh8A1pqBBJwhCIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7481 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241003_131455_097745_9433501D X-CRM114-Status: GOOD ( 13.04 ) 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 If the DTS contains 'assigned-address', a dynamic address leak occurs during hotjoin events. Assume a device have assigned-address 0xb. - Device issue Hotjoin - Call i3c_master_do_daa() - Call driver xxx_do_daa() - Call i3c_master_get_free_addr() to get dynamic address 0x9 - i3c_master_add_i3c_dev_locked(0x9) - expected_dyn_addr = newdev->boardinfo->init_dyn_addr (0xb); - i3c_master_reattach_i3c_dev(newdev(0xb), old_dyn_addr(0x9)); - if (dev->info.dyn_addr != old_dyn_addr && ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0xb != 0x9 -> TRUE (!dev->boardinfo || ^^^^^^^^^^^^^^^ -> FALSE dev->info.dyn_addr != dev->boardinfo->init_dyn_addr)) { ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0xb != 0xb -> FALSE ... i3c_bus_set_addr_slot_status(&master->bus, old_dyn_addr, I3C_ADDR_SLOT_FREE); ^^^ This will be skipped. So old_dyn_addr never free } - i3c_master_get_free_addr() will return increased sequence number. Remove dev->info.dyn_addr != dev->boardinfo->init_dyn_addr condition check. dev->info.dyn_addr should be checked before calling this function because i3c_master_setnewda_locked() has already been called and the target device has already accepted dyn_addr. It is too late to check if dyn_addr is free in i3c_master_reattach_i3c_dev(). Add check to ensure expected_dyn_addr is free before i3c_master_setnewda_locked(). Fixes: cc3a392d69b6 ("i3c: master: fix for SETDASA and DAA process") Cc: stable@kernel.org Signed-off-by: Frank Li --- Chagne v5 to v6 - fixed version number to v5 - fix merge conflict because change function name and macro name. Change v3 to v4 - none --- drivers/i3c/master.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 68411f1cf80d6..42f610636fb7c 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1547,16 +1547,9 @@ static int i3c_master_reattach_i3c_dev(struct i3c_dev_desc *dev, u8 old_dyn_addr) { struct i3c_master_controller *master = i3c_dev_get_master(dev); - enum i3c_addr_slot_status status; int ret; - if (dev->info.dyn_addr != old_dyn_addr && - (!dev->boardinfo || - dev->info.dyn_addr != dev->boardinfo->init_dyn_addr)) { - status = i3c_bus_get_addr_slot_status(&master->bus, - dev->info.dyn_addr); - if (status != I3C_ADDR_SLOT_FREE) - return -EBUSY; + if (dev->info.dyn_addr != old_dyn_addr) { i3c_bus_set_addr_slot_status(&master->bus, dev->info.dyn_addr, I3C_ADDR_SLOT_I3C_DEV); @@ -1959,9 +1952,10 @@ static int i3c_master_bus_init(struct i3c_master_controller *master) goto err_rstdaa; } + /* Not mark as occupied until real device exist in bus */ i3c_bus_set_addr_slot_status_mask(&master->bus, i3cboardinfo->init_dyn_addr, - I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_DESIRED, + I3C_ADDR_SLOT_EXT_DESIRED, I3C_ADDR_SLOT_EXT_STATUS_MASK); /* @@ -2125,7 +2119,8 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, else expected_dyn_addr = newdev->info.dyn_addr; - if (newdev->info.dyn_addr != expected_dyn_addr) { + if (newdev->info.dyn_addr != expected_dyn_addr && + i3c_bus_get_addr_slot_status(&master->bus, expected_dyn_addr) == I3C_ADDR_SLOT_FREE) { /* * Try to apply the expected dynamic address. If it fails, keep * the address assigned by the master.