From patchwork Tue Oct 1 17:08:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13818617 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 2FEAFCEACEE for ; Tue, 1 Oct 2024 18:16:34 +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=kSLVaj6IwEJUfw17u4k55MQDQnXmLrBVWaGrFan3b14=; b=t/UWie3ifrtJGqbrpn0NI4Www+ FdY0jl33eZPHIWQWZB7fVAjzjXLTRqleWxvz7HBsUAaFyJjF1M465+ElGvSZM+OrobURecN85dmkc 4suy+/gQ3P0uMDy4o9AzFrRtUs1Cd8dkg/QVK2BdcJetjNJWhlLt4P9mMZVQa7ltOwJkPwnZxTHO2 jWw4az2Pd8CRNP96bPIB0NYlKpJsALOBwyqYb0ZRSrEUSKZ71CTIAqJhZM5L6wNtiRi70eu4SaaaQ lX5ytIdWoxFfL3h4TsDQWujOk/hXRItLDSpPW0zsfZF7l3C/PyzvJz++wl/Svvr+EVxJOMcMFA709 3edslJhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svhQH-00000003kUV-28lx; Tue, 01 Oct 2024 18:16:33 +0000 Received: from mail-db8eur05on20600.outbound.protection.outlook.com ([2a01:111:f403:2614::600] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svgMt-00000003d3R-14GD for linux-i3c@lists.infradead.org; Tue, 01 Oct 2024 17:09:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ptlxuuzBWxGt+VILVWVhlhT6uzjhiNSdLScLzwJV9BKpZsAPqkgZcJQm/ywZ3N5psI0lYgdN5t8klNgaNs3I20tKvAOZeVuWVCJstri2R0TJdz8l9rvuvuxGVI0V3IpgPG3OOiphS4AqvPmePkVErWhfaGzi7+jrKMn6ZgOa/uCoL5GhqEmwZXpG/OO+6bW5YtPdwQrb1yj00Dtowb4PrEh1yLCkwkmi8cb/7K1D+E1GsD4hC9SX5oUe5NrDfAfroMQ8t0c5IcqxqJW65lp1+dtdEMI4d7WbAj0CSN8HIbXdZxfLD3Annf066naub9Xuf1tLlFBlK//DT6xn/MsWrQ== 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=UQfovDJ1ujrnEJUjiym92VRPxtkwgLrPMWqWNVDo7Hg=; b=aH5jnb1IjTqirryEox+IgOOkh+GbB0yzZPXI4k4FoC3Wj8JSn3bKmOboLCrwQ0WcchZEVXr0dAPoQ2rKqQZOFEevfjzcW4vOQvFLESgRYlDPTvDH9fcl5pnPpwS9/VUan2DxIcmplnnTMhRyL8jiHygYioN34pBykRXTH+vypvBI8+Y5bZdbg48Az+uAWQUqrpKlSKJDOdU5/3Z96m3963TJIPp+KS5pHFocZJb7UXrmu1LcuRKkgw/q7G/UqT/BfQOpc+wQsYupPaw5Du4X/mzmPZ7UaZmqJ7FqSAy9e1PdEtyr99Rc6lU+CSsXLHHuHp/lqx9n3EofR864daJeZw== 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=UQfovDJ1ujrnEJUjiym92VRPxtkwgLrPMWqWNVDo7Hg=; b=XNWZt/WC9ZZGaoozUF2XmhKdAlg9nTm3Gzw8t8+9zOmQTUEFuHSeaDwDQOGQdYVW39zsTvAZq9rPJWfMAf9BkqhQTvXMTXNmlU5GaCec51kQaQauEOrlT467pwnjcIV4RjvYeOlnyH2KfsXGSt3AFkWuI2V/gy9666RD1TP/7Fv3yko8rFTWFq0CdGJXB/ZMI0ZYhawsHm/g4VyiBSkuonfRd/RBQ478a33/IMKiUa0OevFd6z5CVqnGY1OgsQCod1W+7ZGrLENL76n1PmUfcXY9/Jh+zeofhpjS3m5SpVjczYwdewnSBqTiRCy8aLXvj6XxuQmh7i4sIpMl7ZffIQ== 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 PA4PR04MB9710.eurprd04.prod.outlook.com (2603:10a6:102:268::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.15; Tue, 1 Oct 2024 17:08:53 +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; Tue, 1 Oct 2024 17:08:53 +0000 From: Frank Li Date: Tue, 01 Oct 2024 13:08:20 -0400 Subject: [PATCH 1/3] i3c: master: Replace hard code 2 with macro I3C_ADDR_SLOT_STATUS_BITS Message-Id: <20241001-i3c_dts_assign-v1-1-6ba83dc15eb8@nxp.com> References: <20241001-i3c_dts_assign-v1-0-6ba83dc15eb8@nxp.com> In-Reply-To: <20241001-i3c_dts_assign-v1-0-6ba83dc15eb8@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=1727802526; l=2002; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=DaFfN+74X5tC67JPy6GOxKmdvDVTxdkWjGpCgAk2ELc=; b=fAX8X1NwHDskH+QD8eHzVE0vVBShlP+PdkBhAhv4loUsBHQu7qbdbmhXAmSX1GTg8x6ap9ki1 tKQJHD9hd3iAeEsr4hXyLODMUYk2K9huSMsXNmne5OxK+5cfhjiCfcy X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0007.namprd03.prod.outlook.com (2603:10b6:a03:33a::12) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA4PR04MB9710:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b7491f2-a605-4af1-a4e6-08dce23bb9d2 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|376014|7416014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?hQNNQXOTZKsydikBjya32PZXwCV+qgT?= =?utf-8?q?atgTzjRYGg9TrHglnU7GHpWUVOt7m3AFTwXVzTKPd3CtlKlYUTOaZfEmvv1gaigPK?= =?utf-8?q?0O5ilpZaDJioSXf+oKjhsnIRqMrxXnGWwfYthGNHfexIA+vuAK8JohWnaKZVXJ1lX?= =?utf-8?q?7IAN1uP5p83hSLNjHcnGdFh/HA+my9AYHNWIWeyMmwkNKnFfClD2Zkw37oHXJIMCh?= =?utf-8?q?nXjj5M+VlQNA6QFnQKYVBkDo84Qo2oamv7aYQZk+NgmUn+sul0PIE4juegypQmfeK?= =?utf-8?q?SHmMaZSKYKSAsGCGsYMDoJDK26mIZyU+WISLDgio9Vfldb2nHvS8ac7Y2o6d76uY8?= =?utf-8?q?gZmmi1/2iccwH0OWEFTfoHilfcn3wdfv39ltxhlnQicApqekIEcSUwDBXTm9muE9J?= =?utf-8?q?BQQTZccWutnvjQWFlRRivDvJiC0eByLiYb/GfSYylmKOGYFT7SNcSOMQNvvHZIwxd?= =?utf-8?q?EbUaQmnPki1KqHkVMK0EMIZGpDP38l4G/xOJkv9t0OSUlfI2g8LmZLPoQYAuMqsbT?= =?utf-8?q?2h6eF4vPllnuJeFk5kTeqnV8XcMBiydFxAVbun2skrkGQG2bfFHH9zLO0wvPFwD79?= =?utf-8?q?LXSDZ+v0t+KxwWsHaNZYtQkF7TCJImcirPyDFIXPfDJ8eQoUksUN/jSrwTQDRZAZu?= =?utf-8?q?hvR5Mumrzlb+ynvLMTA5NCFWYbtOgRjILoi6S49vxhksEbVu7X7LLqtYM+bdPwisI?= =?utf-8?q?8a3qXNwZUAZMurvbbk4GYuZndI5y8Zy1/pry3kTuceJLVpIGKsTJaTyMTYEUmthfL?= =?utf-8?q?uOU8lD8jZ95Gq9xCX11CFyfMczkjKlw2WCvTjiMi8Ck2uPjvo+tXjlpUfw48r9ms5?= =?utf-8?q?Bn1CvaoTU+MwSFzZu0+Gv6Kn7rzWUVznobyUyusTep1R71jAWRxmYyi0c10jOEX5K?= =?utf-8?q?ZeMDTIRNrEt2PoSi6j93KvZONBYo7fYCj1S9R0ppW+7Cv+YGG83fC0Pr9LMZIPnFo?= =?utf-8?q?Hs9seveEa55jMgzN7zvdmpEfKT8fvvGrbDfIb++SdSOsaoKYABwj4p9QiC7nLode5?= =?utf-8?q?g0o8k3A7VcqKKU3/qOiedlwgUndqCuXJWxwneBctQIlCLMwu7uLMizxrk0fY2PmbI?= =?utf-8?q?xfnCc0IoWj8tRxYVHi4P3p7WDOhdWaCExE8MLI3K95wsUC67jR2rgvDuwnIJ9PFjG?= =?utf-8?q?HDdCG5XmlBvXn7K8rC6gTQ0YRcjyhf4ghHeOur4K5z1YN6Ij2fQA6p5o+UNr96slg?= =?utf-8?q?1PmF4nDPMrzbtfdArYOikcW3q6e3bVe3ICmPn244SZGlEzskoPsKoRqpHZFJ8DGOp?= =?utf-8?q?TzXLciv6tOP0A6RWgesqinqqSTdsKAY3nJaH7qCjXmuRgGmgJvIRI/McluOESDg6e?= =?utf-8?q?uPJ5gU9C5/izG198D2TbcLGy4pJa0hyn1A=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)(7416014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?AwIij1OrL4zepSlTN7QQWMw8ovdZ?= =?utf-8?q?KBFOJDw94f0fEi4yU6ZOcOp3h82tu01wKb8hdB+3uPENMQsU4PqD0nOZLHaN8J+NE?= =?utf-8?q?2k/KjTqMSL6i+PRBYfYM0MZ7b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emm9/qhe6yx+bORKVHNFXXAlnXT7Y+TVwCpbGPa8CN/nxYL3?= =?utf-8?q?2dOKs+AIwVHNAbsxiqAJMaeDITqpHOnqMtlrL4YZoM73TjqyyIrYVrUN/MlCZ94J5?= =?utf-8?q?yC8hRHH9Rgs3W8gwGFRX3JFG4pD0m96Hmrh/WQ30a3ALwtuws7xm4arnSQk+WUbfB?= =?utf-8?q?yteZ9ArDmum7Kpp7D9mD/UexzaCmJduDvkwx/qiqvMp6uC+QhFnGSI2rnmwpiLvAZ?= =?utf-8?q?SrX9siP/iPAXJrNbJnMF08POWOBHT3MLOzsz0XW7DJoTr0a3qzKYAttEOYHMBHe92?= =?utf-8?q?sKq20iTjFoJ62n2ES2RdGjUgCYxs659Sa7U7B/lZqYWEm4kHV8YEmWWFyf2sPnScS?= =?utf-8?q?lb3TJK5gE3kq7HqoSoszFJg6KdtDS62GMANzpag58gM4eIxumwhmzAwRsHMQxJ1Zl?= =?utf-8?q?Y0GoEKsaK8p60W0loxmPjgr9ram7bmMMT9W/fU3iAl3NmQoKSu8Fjv/l4amJ0XfiC?= =?utf-8?q?Za+lRSBSue2eco2oIs+3xulIk47fXBlwAINyeFPxddB4H4CVdXhZW5oWEzD4mGJyX?= =?utf-8?q?248vTDiLcM7n?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b7491f2-a605-4af1-a4e6-08dce23bb9d2 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 17:08:52.9280 (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: iqW3sXG2upmX0JquukqmCdaigM50q59DKBwlg5dK3iSlfOKT+f3vUz2uOabbB7t7u0s2Bhh3FN2G/E7D/AbacQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9710 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241001_100859_337584_A79B44ED X-CRM114-Status: GOOD ( 12.41 ) 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. Signed-off-by: Frank Li Reviewed-by: Miquel Raynal --- 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 Tue Oct 1 17:08:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13818618 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 33BE8CEACF3 for ; Tue, 1 Oct 2024 18:16:34 +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=vJH/1OxyoPKCEv+PkL2FJeVhupYYg03JcYKBtB7H5yU=; b=CDA8qbSDcrZIaJ7YBSpOegVG2f sE+WyabClYSIELJ1qTmCGv4+I9SX9pY0HrBtFyumLoHmkRYbix4614uZFMabnStQJcw1cvC9vjmnO FAB5pFfswiWJfq2cy7jg+4gvYqxLM+VPtZmu9AjCg+R9DshjWMjk0iEhzPAQjO15ikcA78+Dy7Vdw kVpMkHs9JEO5rZyVQ2W3zq2m9SuntLgHsCATZw86sGctGZnx9Jt1aLXSn13EpA0AsjYF/CXcs868T d8WrWGltJ0vMGlRasiV9Okx3RqNOYiN4gRnt71vTsSTMczbioLISEYRduD4zrJUqkmYRIhHgOdtgB VoHN0lOw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svhQH-00000003kUb-3N52; Tue, 01 Oct 2024 18:16:33 +0000 Received: from mail-db8eur05on20600.outbound.protection.outlook.com ([2a01:111:f403:2614::600] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svgMu-00000003d3R-3QgY for linux-i3c@lists.infradead.org; Tue, 01 Oct 2024 17:09:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LbyPYjllrQn0tzoZNPdd2YZyJvZhgIc4r2D+hgkKhjDl48CCvVV1RMwG0SGOTbNTthJoNifXgYwkjvvH2XME8tA7T0nAXJVk9b/txNJTy3uAiz7jRXTEf+FbGGAQe32ZxkDYsZliF95xCxfhHuO3Cygzm6j7Hcc4Kqg4Zb2aDiix72pkJ1m4ARMS6gHcWDlainIm1aJ2etWFn9hrJiOAxS5Y8doptneeB9HIC+QL9ZLy4MlfYQ2rRncMDQ3ASkWpkpd680yRJLy7M0HbmW0VP7iWuFcSFOibgwTrGIt7dp3VWiswUenqJSavd1rlKtJyuoKSV6FuttHZGSl3zphqKQ== 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=r63hJtAXg34VgEEJLPki9brRwE37eXOv9n6xTXTxe6Q=; b=zNO8b6vIIYQOOaCVdx7OMt9vmdeEH08GAF7eKbAgXtwbpJbOLowyrwHm9I6MjyIMqmR8ecNe8kIJ2EWi/6HRfSI9av5F4MgZ3ysmDt77M0Y42P8xhx+eFvKsfd8AckAdf8ASBVziolyBckojzqi9JZHxlzHbitEBqh+8VpwYY8n6fIHHrVxuAinDT3kh5Qv8N9b6CMjHSHF4G5U5PvQ1xKSAAS9EmD4OZ4qmKS6EXAryk02UOm2nOmMZMIKk3JRaozbL4Nm6QKIyzF1bNu6i7QoBjiXR/Ctudj0aU6Z5JN4FEsq62m9EjlwojB8o9M8YvtCe1utQwKlBdweOxL3jiw== 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=r63hJtAXg34VgEEJLPki9brRwE37eXOv9n6xTXTxe6Q=; b=U6bBRUJ/h0ZhoIGWUs36JPMAXRkNQXKYU5G4blOmo2mSM0RMHSImtmSRZN2TV6CoX/Af0mgD7e/iksF4c/MON8SMsW7nM4rDK9o9/1j47KDTAFNW8fqMCIxxbl9a00vmxHZPG3J+0Ar45nao6wcHvEy4r8Rjzy/9/3i+ecGjfuOhbQOTaB2VgB+7Vh1SVudapstK+bZ/h/9XCsB0SyTPHuMFkAJd3dEd3r+nRXSPr0duT925QQtEP66U1g5uojkC/ay/kZ8yiFbUwXCSU3ycgg3lMUCsS9LUCYhbq9xyh6T+o5cNnNRNMro9aswuGrCS82wFMj6m68TdqyIqPIw+zw== 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 PA4PR04MB9710.eurprd04.prod.outlook.com (2603:10a6:102:268::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.15; Tue, 1 Oct 2024 17:08:56 +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; Tue, 1 Oct 2024 17:08:56 +0000 From: Frank Li Date: Tue, 01 Oct 2024 13:08:21 -0400 Subject: [PATCH 2/3] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT Message-Id: <20241001-i3c_dts_assign-v1-2-6ba83dc15eb8@nxp.com> References: <20241001-i3c_dts_assign-v1-0-6ba83dc15eb8@nxp.com> In-Reply-To: <20241001-i3c_dts_assign-v1-0-6ba83dc15eb8@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=1727802526; l=9456; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=/mHi0IGhvDETCcr1sx1Tpq46kysDKfA0S20VyM9YTjA=; b=y90JXxQcloUIJ5ejLwIdojh+Jt7Upysp0mxEU+izogT4hkQ3H9XOiSCFxEazT4oFCSs9C0Qt6 e8HHIApOAsLDR5/fCL+B7eo+zH60AuGAqFD4u7R0WfRm6Hs9b4P5YOK X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0007.namprd03.prod.outlook.com (2603:10b6:a03:33a::12) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA4PR04MB9710:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c01a988-db29-4a5f-3f1a-08dce23bbbd4 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|376014|7416014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?5JRBWAoOsplFBsNuc2CDNp8g/1R9xQH?= =?utf-8?q?94DvNcHlhK0vJN6q+tmTbjZWArNgHChWy/s9KGW3I0TBja0oT4EnjhuCNptXSYVoK?= =?utf-8?q?jG3wm82x3KyAX4moNO46f1eaxm47hFgbEYEhjwgUNZjR6PaRCITNJfaxtJvNEKYxD?= =?utf-8?q?ID64fYGICbghB/cXetbsHbqkDMykIwa1Kvcg7s5QBJzcj/kA7UOt3SvLryxlHi8mO?= =?utf-8?q?P4B3L8c5H2TDKhNw9mwU2fbuTgyEiNYrPUDXik+QLK53vCq6mXc+eG3TnBD+Zenrg?= =?utf-8?q?1BXFIPLoiT7jMS033iZ9lmr7p9JkZnC9SVmsc9T1FcFbi7UpaYMuS+/wFP2ZMvxDV?= =?utf-8?q?14WtDRJCWvTuMZV09PJl38Owq05qJRqxhFsI1Ape9QD68srXmn3hfk9bgP1x3mAux?= =?utf-8?q?hPdj/gFJfTiNdgwhIzqlskZaIiIbG+GFEXkrW/M52w+nfucwgvuehmVTVS6eQTtJl?= =?utf-8?q?aRvXeJRty7ejqRYJw8SJSWgwIMiGUoo42adBdfJOUymW7voYGV7J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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)(7416014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?i9Qs0/t/OhNtr56lokhrqVIGi7X4?= =?utf-8?q?1WQSJZTf4LVJKyUPipVj7LyslLKvjBnfNMhWpWc3rqYRXX937RL/mnZnch/QqDcNX?= =?utf-8?q?EfRvffkb2UQg3xFfQUvzL45zHhoc6/6MdLxlV3xyZ6og79cGS5uudDiYvuG9zZ+lV?= =?utf-8?q?qwJdRcM15dNzhmYe8cAx93IWaTEU9fhDhkHZKKGIV1fIpL3hQsVu7DEot9Z6tYLDo?= =?utf-8?q?kT9CholI97Jt1dxydaPVmE9lUq4/tIugWh0AZ33cSJuCONhc/kHy2fjru/Z2FP9BB?= =?utf-8?q?g1f0FQueEEltxGfomA+I0mAPTAITzw9DOpWuczLPqGXiT63YCXhlc92jhHAA+KbPF?= =?utf-8?q?vHuDqwvoZZnxlP33uhh9p2UgbVS9VP1jBlOfZYBsGa1DlI8WMMuLWY6z0vJu0TcUW?= =?utf-8?q?9zD68PY/GpnHCnvHSF7w/gOwfaWQMp3SsJITlNwWXFRagplLTt1kKIc6p/kYc4YvV?= =?utf-8?q?pvS0G/GQ6oYcw8Y8bd4zGqjeeEypyW4fmo7/LF60EHTitrOlpo47mu7lJnQ7krGOH?= =?utf-8?q?p2xY7+QCn5y4borbdqEyiLliZAYgwxRPtx2ktlbfC/475vOD0uhOCwQUnehV/72D8?= =?utf-8?q?WJMkqWlLayRgtPUrsggfr2zDDGyV5e5xkSyRcGGTKpdCZ9PAcR/dm2Dtwl9BgkoL2?= =?utf-8?q?KF9OWa8tQmiFIzH8vQFA0I9R8u8B6Af5a9cRWK2EUSQ68y4Q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id: 6c01a988-db29-4a5f-3f1a-08dce23bbbd4 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 17:08:56.2788 (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: 8LAI+V/8CMcsQSf61t+tPEBvjB5P0ArLon33mQnlruYUV+rGjS88dWKfaWI49OPVRup6g6RPjZdX+gaKj1S4Cg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9710 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241001_100900_896403_AA197812 X-CRM114-Status: GOOD ( 17.12 ) 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_INIT 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 want a specific address (called as "init_dyn_addr"), which is typically specified by the DT's assigned-address property. (Lower addresses have higher IBI priority, and the target can adjust this by using the assigned-address property if using DT). The function i3c_master_add_i3c_dev_locked() will switch to this "init_dyn_addr" if it is not in use. Therefore, i3c_bus_get_free_addr() should return a free address that has not been claimed by any target devices as "init_dyn_addr" (indicated by I3C_ADDR_SLOT_EXT_INIT). 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 all of above address are already used, i3c_bus_get_free_addr() return one from the claimed as init_dyn_addr and free address slot. This ensures support devices as much as possible. Signed-off-by: Frank Li --- change from v3 to v4 - rewrite commit message and comment for i3c_bus_get_free_addr() --- drivers/i3c/master.c | 68 ++++++++++++++++++++++++++++++++++++++++------ include/linux/i3c/master.h | 7 +++-- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index dcf8d23c5941a..a56cb281e6b6d 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_ext(struct i3c_bus *bus, u16 addr) { 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 & I3C_ADDR_SLOT_EXT_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_ext(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, int mask) { int bitpos = addr * I3C_ADDR_SLOT_STATUS_BITS; unsigned long *ptr; @@ -369,11 +375,22 @@ 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 void i3c_bus_set_addr_slot_status_ext(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_EXT_STATUS_MASK); +} + static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr) { enum i3c_addr_slot_status status; @@ -383,11 +400,44 @@ 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 want a specific address (called as "init_dyn_addr"), which is + * typically specified by the DT's assigned-address property. (Lower addresses have higher IBI + * priority, and the target can adjust this by using the assigned-address property if using DT). + * The function i3c_master_add_i3c_dev_locked() will switch to this "init_dyn_addr" if it is not + * in use. + * + * Therefore, i3c_bus_get_free_addr() should return a free address that has not been claimed by any + * target devices 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 all of above address are already used, i3c_bus_get_free_addr() return one from the claimed as + * init_dyn_addr and free address slot. This ensures support devices as much as possible. + */ 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_ext(bus, addr); + 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 +1968,9 @@ 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_ext(&master->bus, + i3cboardinfo->init_dyn_addr, + I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_INIT); /* * 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..57ad6044ac856 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_INIT: the bitmask represents addresses that are preferred by some devices, + * such as the "assigned-address" property in a device tree source (DTS). * 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_INIT = BIT(2), }; -#define I3C_ADDR_SLOT_STATUS_BITS 2 +#define I3C_ADDR_SLOT_STATUS_BITS 4 /** * struct i3c_bus - I3C bus object From patchwork Tue Oct 1 17:08:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13818562 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 68D48CEACEC for ; Tue, 1 Oct 2024 17:09:10 +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=wHQGvqa46IdNb02L4dJCCzIkVnRjOZv9RKBUOY5K18w=; b=e/dSPDaS8f2v0J11ftvnoZZkGV vL3mziJqoPvxTm6P4rL/RottHCbEezIPqdSjqdqX2VCSjz9RLJCFr5TV3PHkNhO6l6yH8BezReohj zSUvPslGg6G8SfzR+vLhE0hht9go+XNI11DQ8/5eCEehSZ3MHStdlogn+UrSk2x46s8wMIHvSDrkg 4SpQUlo92PqkF+RiZdw1vvoO5uSFBNgpu+e4QeSvngXNiy1txqIpod4kHXsWrbinO44tl1KwbAfI9 DcKCqw/wthxYImvQ0xqv6rL4cK4SzV9fCvLSi6mk+nhBFh+NtnZwMS85w7ZnbTQEZgcF3Fl1RKL5U YmwHBcEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svgN4-00000003d8H-0Vyn; Tue, 01 Oct 2024 17:09:10 +0000 Received: from mail-am7eur03on2052.outbound.protection.outlook.com ([40.107.105.52] helo=EUR03-AM7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svgN1-00000003d7R-1FoT for linux-i3c@lists.infradead.org; Tue, 01 Oct 2024 17:09:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iRsOgmo428s8hiWElJ6O+wa2xJ/r4bHfSNt67X/q5gnkwtjeQTaZqyLh15GHeSpivERfHmln1siKn1UNn1YA17RP+ecqp61P1qTGDIplKTmmsRAqXRpxHvySFkedrq1jl2KOtI3jSnqdw75RLUfecupKw0zWtVbD9tEDr6uG135t9O9gqC5DePnqE8zLjomkhK4bPJfsFjhqoiY6XERXLCzhhWaZJPk4NX4+yF56t15yGPj6DtVuSbb4EXdPVqM+Fq2qh1tFJbHrrfAeNRNY9j9YKkxACyRKXSUx1X0iEN9+oRrpxh+kEUBUA09JWwJk3jU0ccEtgxZy5wuu8EJYxg== 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=wq2uhNrumywxyGirPsCsUbtBLGtPk1U0mtxUjUUipPs=; b=XroeNa6uCB0EexIMH3FEzazI4qPxyxcqbJ22UsRaBOLxP8nvgBlT7fYyd1mH4PPTFO6qKdVxqXwvCkgWoaVDqXhQYzRWtL1vfIEUlvbJKwLLaDYudciFIGqjUBwuRPWe9UFKUk4IDEb2hFSzzNwTEqBCFJsbJkg/0jhvIeLxlTOxxpVqz1OK+/A4U10kZzaCqUfsnsPpmipDwZSi75uPqMPF0Ad+2jcxk3gG9O0i6CpjKkBPrCSKPtcq3TNu0pBcx63f2fwFEAWu2UvqB0SklmXkk6STfvQjVGugiq6bRKjIWr0E2qWpIfVs9Bc5YiUP9L1oYahi7q+TM/jl9aCZCA== 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=wq2uhNrumywxyGirPsCsUbtBLGtPk1U0mtxUjUUipPs=; b=b9QXGtMKwcjbzkmdG2m3Imw5Z4J+zvEMToWMkjZeCj9i/+BvEiFyWSBnWU1GGKH/Ym8jVNr1fj5lCcCvlkxhzmQ6DvEJScST6N9899D9bJdcyPtCNRhECMqUJV4+TIg4KnuyaO/he45ran0myVUZ9HoOVUhwvQI0vgtdxzNJUtqAU3FTpjAsEbNJO0wQgSP3Hlyu6oG/z91ZGtNgM47A3jebl4M9ePOh4PVUPS8CGAlUYTiJHKv8gekMeMejpof48B6BxDMWGYdYyhyQj27wX7oNwZU0IyzubYSKNosqpCcOeLqnFQZ4wRxwdaBTpvSt8N2Hzqli4imA42qNWrMi1Q== 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 VI1PR04MB9763.eurprd04.prod.outlook.com (2603:10a6:800:1d3::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26; Tue, 1 Oct 2024 17:09:00 +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; Tue, 1 Oct 2024 17:08:59 +0000 From: Frank Li Date: Tue, 01 Oct 2024 13:08:22 -0400 Subject: [PATCH 3/3] i3c: master: Fix dynamic address leak when 'assigned-address' is present Message-Id: <20241001-i3c_dts_assign-v1-3-6ba83dc15eb8@nxp.com> References: <20241001-i3c_dts_assign-v1-0-6ba83dc15eb8@nxp.com> In-Reply-To: <20241001-i3c_dts_assign-v1-0-6ba83dc15eb8@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=1727802526; l=3667; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=v9ysb37t9UYUAWV/t/laqr7J4MgebHgEF1/XTNH6RrI=; b=vx3zQzJECmDBokBXBNMawCmKn+M4q5bMYJRFCmxNi00KN6/hUifccsdHdL3tD4+LJYp571BjR j2vJl0n0e9RB21JlPD32VePEcKtWFrwGQdpiYs5T3CvwLYEdo82Du84 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0007.namprd03.prod.outlook.com (2603:10b6:a03:33a::12) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|VI1PR04MB9763:EE_ X-MS-Office365-Filtering-Correlation-Id: 64464f56-528c-430b-e134-08dce23bbdf0 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|366016|376014|52116014|7416014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?us2EoMGKSMUiI0aYNBKg/YcFO/utwoi?= =?utf-8?q?LM57388zr3IPWh3otJqEGhqim6ucjPHxIOKRDWSKUKFBVIwEuapzdfrfuo9gjWuu6?= =?utf-8?q?dMJwveatJ+IN3WZ328qWg5n0QsSYuNKs/IBiDC/FX913bl5rfejfcoyybeRtLi0XN?= =?utf-8?q?0deQHuhDrnQRijZEs1fSNNPHULj4KXXTQFfKDVjoWpKlIJ1AuWwixpE89uuq+h1yc?= =?utf-8?q?hPKX7CwHlkodXxu1As7b0dbltfhfRxM7mx5D4ngWqxP3Br0goEvf6ui4nZU2fNTSH?= =?utf-8?q?pwznR4qDSzljWA28l6qvXDEN9BiRUfoQ0/712pO8auRBEmEENvHJ3WhSFwQPaeHU6?= =?utf-8?q?+nbbybyif3MlwXb2wi4vcyQxhVCHoYaO5HPyxzPqP4JEASNlBvd95MHfbu8aMT3cf?= =?utf-8?q?P3dwZEK9vsaey5X5Q0SDZuRAI5nmsUBAfvXMYC+If/y/X27Sdz43rEL6o/kguIrCp?= =?utf-8?q?dD2RG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KkThK/x47pQjiXPieB8MIFDw=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)(366016)(376014)(52116014)(7416014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?PNR6aDbn6ItrhhfVPF2J1+k/9NlT?= =?utf-8?q?Ad/NWiXzTJHhp7AMXX21iRuZC/glt/D8MU3K657M0zSW742DkQPv/dHfOYVx6ud9d?= =?utf-8?q?bZHsIr2EeJyWGVm6v3uumwg2NpRcAHGajUPhbLf+8frsKvCTxUyXD2y2KhbETxkrc?= =?utf-8?q?2e20KeU3e8ccsgoOXJDSSygfE3Mlx0jWbHg9JER1lgi+woqVsK9Cd64pX9LwVlwbX?= =?utf-8?q?lIwpDsXgWVXA9aCg79Jw+/4Lic3KY+uwji6FKyD3GSw7uN+dVCDIPIppra0K81qQf?= =?utf-8?q?Dl41YtJAnEqOft9BmSUSZW6lcELafOYvC5plhNqnVc7Yrt/6WxEXrJriJl1mnYXL3?= =?utf-8?q?TSSm7C1xGJZeV61ZcfPgkr8e/gl3drveHb3Q4p/8t6e4TTCk/0/ugYVnqaW8hPZ/v?= =?utf-8?q?bbA21SP3cM4ekJ2obTKg0q/plu7rd4xAQWN0XEh+/k6UQu/61LAltpJueVl8NM58N?= =?utf-8?q?jWX0v2w1ggmUXxVxQkHX9HmvEsjUJbOy9wno4ElOfIUCibCpPau57jEUqasrMRcRP?= =?utf-8?q?w6RkMm56x+YU0j906kfwqM8uBFsyzoUFL8gM1pDuzsTI90dRR8hAzNrjtuadf2Czn?= =?utf-8?q?e+HLw6QhE+eyJNpKZ/b6YGIk3ra+9/D6C84n/fc9Jm3VArtIkfoP02J4AbYoMJit1?= =?utf-8?q?buN1/aqcpvSyXwuVCDNdLtUrQN47/AWz0eNFemoHyJmuvydAIinc5He2x8nR5Btne?= =?utf-8?q?qjAPI/wUUDWLy6CubYXbFeq1q3l/v14aewdqau5i26ndlEuymtXW/R6UD9EPlphwy?= =?utf-8?q?fAh/8YzVPhMbvciYR5Uww/PX5mKhewl7D5Nu9kIHszUxpEJgD5x8KLRtDOclkUovh?= =?utf-8?q?vWo/3Et6r4JpDHi8fZ/so2wa2zuTmnPEaRbkZGVyPr5bQpESybTkHHUt2e5Km8gFI?= =?utf-8?q?64+FcxP78aZ1eYBx/NINrd/vRpetlpx8MgV4sZaxLDalgB1ptyax1j5w5yNgOBmII?= =?utf-8?q?UzbhUXgaggC3X9TzozY15MdOv8o7AoAD/X0WjFt98Qz2vJN9CA694W07X5F+3ZV7/?= =?utf-8?q?69jOyv64ikV8zhXy3lzjiUCXsoCEti8y6fE2sN0DtGzIWnFRVSn5T6/OskChWiEZO?= =?utf-8?q?ipCfsQlamzpT18iggNcXl7151qq0GCyHFfse+GMCMFKuqWc883JX1mVyQgCdWSGYL?= =?utf-8?q?UxxaD6HBmMRV4T+7yVqbhBz597Q326C9ZdP/BOmQuNfpodYYzoaJE9mQ8XXKnslex?= =?utf-8?q?NsBNpk45M+5GcLy4reK3Reh1yaK4HJLKZYJAwLiXR2fXgB/LBta6ikPSG/XPkHuzQ?= =?utf-8?q?hqlhkcdgYZEK5SgK8UV8oeJE9B+mAHBkW7IGEfzBBSx5Qgo+XHRRdbhByfKINMs+X?= =?utf-8?q?vRwHVAtPw8u+vLOPQO2XO0KchmCyxOD5R+hb62BBamFHxtli5rJZFkocif1hSjprd?= =?utf-8?q?i1HkbPfl+zN6uk1baxZtF+IYqGjcxfpujd74U0j0BTD7C/CWzs4UBuWe37nzUUE6v?= =?utf-8?q?iZvnW/f1tKPHjSYupWHrqA9Y9VuXatadn+7MUoWDsbfLA1QigHUxkY5O/qeN3/itv?= =?utf-8?q?LxAEopHAwNyi?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64464f56-528c-430b-e134-08dce23bbdf0 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 17:08:59.8290 (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: GysygEz74+9CNS6PQsDB14H7DYIqpJH+dECNFJRHW2woNlDBfd4vWro/VDk2pKNla5rO7AOq8AoCcYkfEVCQwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB9763 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241001_100907_387061_68CEB5D6 X-CRM114-Status: GOOD ( 12.68 ) 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 --- 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 a56cb281e6b6d..eae7449f0dacb 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1556,16 +1556,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); @@ -1968,9 +1961,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_ext(&master->bus, i3cboardinfo->init_dyn_addr, - I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_INIT); + I3C_ADDR_SLOT_EXT_INIT); /* * Only try to create/attach devices that have a static @@ -2133,7 +2127,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.