From patchwork Thu Nov 30 22:44:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 748955 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="HF4JB5zM" Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2049.outbound.protection.outlook.com [40.107.20.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CED9E133; Thu, 30 Nov 2023 14:44:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O1Tnr6CtkKJdDOMyZKLrx5RUMBKlZTUAkkqQ9R7PX7YdNopTkrdeuOD8iZfPUhk0G69ALWfKs0+vEZELGNs1LSg++Dp+EJfCoAbo6W6rFebFXYTCqJx/t8bp9kUvniDtTVsomZ4IputrlCIsY4K+m+nMPvcvesl0TbHirofLVKA/3qjRP5FwGJmdTaqDMKpZU9BNXggsdsuzxdePjGI7HBD3QvlANF46sjqymgn7hdvqP8Rnh1Qnp+xDblojuW8MXkgQGoc0gp/N6/DPB+qtRJZjL1tNNSpnRcGGuqZPcNf40f7E8ZTbTehoiLcSs4aaWjJ1xVOwZFfluGkDBn/vpw== 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=piRRPE5LWefhXJGz8Zoeuo2aGktvTAfCXdTndUIkNMo=; b=HkVL368v8mxpgYDy/hf/xqExb9kVmohc0O1wieG5sdEl6EYiki5kINipEGZOiuE8IHv5qyukyqnxDaphMPZXvoZGTSfnVX8Az+7caneYbragLrAgUZlg1JxK4UdtNHvbwUKceL0xxqxkHqv5xsxk3tj7rndfhvRNmDwmCVwVN+LR/JtNRceAGAeAHIaz1T0sM6+Cfd0Vi7QC8YfW5ndP9CUXMzKYyUi4SZKFfkQXhOpPnT2Xdm/0rjM6lfwjRK5lDIm5Uz7Luo189LlwpfiVN1yQV+30FK5JAt4S9lkf6S13EDMeckfmbDmF9pPRrElNT7f79JYvLvwdacb3d4G8+Q== 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=piRRPE5LWefhXJGz8Zoeuo2aGktvTAfCXdTndUIkNMo=; b=HF4JB5zMU6MA03UyJTGBvokbvKrQNZ2twzXw7EUdq7f9y0vCi/r/gwrCZu7F8XCw0Cvl8fOOs4kmaLIJW+lEuqCrdnDbzTmIYQkuFzgstBvnWs/lz74HDZnqQXEYsx7kGHbb2Nm8JAxPwKtKF+Bq/MbzQbS+W3T/8FkJKW9It74= 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 AS8PR04MB8851.eurprd04.prod.outlook.com (2603:10a6:20b:42e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.13; Thu, 30 Nov 2023 22:44:31 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40%6]) with mapi id 15.20.7046.015; Thu, 30 Nov 2023 22:44:31 +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, zbigniew.lukwinski@linux.intel.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v5 1/7] i3c: master: add enable(disable) hot join in sys entry Date: Thu, 30 Nov 2023 17:44:02 -0500 Message-Id: <20231130224408.3591288-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130224408.3591288-1-Frank.Li@nxp.com> References: <20231130224408.3591288-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|AS8PR04MB8851:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c0f1593-a1aa-4e26-54d7-08dbf1f5eaff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H/IsMfOfLZG5xMjJGMeKRFFahLm+7Y9CbQ+CvSySgNCnVe6Vym7OpS4MfYaNgRFPQN9Gfna0w2fysNg2DrURvcKFst5LEmEbuA8H2kACtTK8H/9JpRh5o+iOUNbeXaC0JzoMiXoqvrPSmDLCiImw4NR3KqNXVlsIB+ZhKx8cpL7GEARfpdE7L2H0bodEBR5X8wp26rkz7Bd+B7Lc2B4/tuEMDCXBKjS90KXOMC7MlTqDZdMgcFHY8r+GNK0q8Vyc+uRO3E4Y6xCfcaETuZIoX0IFLfHsl1LQKt/YsFdK89dJRPiE6hpxSinOx7feJxKIwoeip91/QQ3rrfDHdUnG6sV0S9S4ILUgwhW76XDqklacE3hVoBQNEZqi17J/Gc+Z0X6zH+T0xFUcmqvjDvjYqsvSeOKm6Pu0mFUN0xnsMTFVn8+tsdNes9Ukqm4UI/0DK7WQ/U3D5xhg0lTPICZ9jmZS/izlMNI7EC6bBZAXY+r2y3OfDFDb0XeiLGUaF56bm+/ql16PBUSUkb3Ph3JHvtjZi7yM7A4qCWPenQbio63tuvktAUdyoJpF5dy0IXnu1mPAnVw62eyYNeJ2CY6hLzwSM1O1FHDMztEOdnal3sshX+LT3XK9nWtDbUgie0kFMnQVjctYKSn1maSj2oR1qPRamxGwPw0s+dQ38NHPHNE= 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)(39860400002)(396003)(136003)(366004)(376002)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(86362001)(6512007)(5660300002)(36756003)(41300700001)(6506007)(38350700005)(8676002)(52116002)(478600001)(2906002)(6486002)(6666004)(26005)(83380400001)(7416002)(2616005)(1076003)(4326008)(8936002)(66946007)(6916009)(66476007)(66556008)(38100700002)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Fyz3Wr0E6CxghMhdQtxaErEpN4Xq9xRk9ASI7wEE72sVXSOGANvD23vH4KREOjSvuqW2Pb9XLET95CtfNXSzya5z7bGmRRGhecDGeFI9jkU0tdzUbQoWqgnVJga67E0SVE8Nj1RdNYzWWWNLGIcS5lORxDhFcfTNdlaMHfg8F2oF0Je1A/G3yBjxjQdzfF77FWFNUDuGu1Ue6J8GtzXTlm0x9sZezUb2jyphD5kDx1CoFNw+/QTLtMJzqzZ0ulmLZCsscP3CV0en7i04A+Pg28DiB2xdWaQLmHYKY1huwzZXYKSfRknU4c1nBhZ3YnP+KbRvsdfb4Xew7GrMygqiBRpBvY45kL+NPbCcXaIDiygvjAsqZar8VLQLU0UpeKQE4Vx0HojdzvJihdN1EOA/GD3rakGTGcRrDjCznoj7AXV5Hmjs9e+6Nm8yNMFYM9ZW3PXHmOANAllGeCEAQlB0fRLT3v8/lVqe2+ecmJxZU3z0o7owxOT8o9YewQAIr4BqkQgwfJaAr/keBZIK61bTliwMbsKgoLskc4bL1pqxSo7nzEKcoty0dajeSdHRavRCC7zvEoEnA+TZy9WHiK7Ch2dw1e6J5KYCL//MC7hars9XHaWmj3M8IsdqnzFs8ZSizX+5Q53r4KKJFKb3VXgDza3Vcs0NUpoWoIKEOsGFoZmeFZaTQnCUjZn+w5u5qy+V1xf462qUcXsi61LMtb+CJLdIRqlxq78Pw7r7VGL2a3M0vkQHYGLsvek9hwO+DVW+AV/pciOMGSsUsO4ej7uaJ5g1ILbWM2WV0iVc8dEN0/9eMp7AFC2iXS9jL9ttT03GxpbYHTGVl3BWHpMMyIgNLdD8tP8fWs9oct14pJB74TLpV8YB1TRpIdXqCX+rlJ3YfxUiT+uJ2MzmyxnGCekofyf3MKciconD1BkmQmMYIncRrF2Ns49WUlJkvAxEmyjLqH6NHhwiND4HyEw/+IVC1IMc2MeHh0txqxJMA2/FuaCRJAz3mnskqUg9yA0Q7L4oye2uFuyP9lK3CvjY4y1B4xrlbn9VCXe0iX765VqpmvZbtDbzxoIO8iiTqFCdQU683i61zPvAz/HheODBAjxPRGp9Fgn9sGnbHfjypQnSkTIah+Aks/mnwJpyr9LXPBIPanRjU1vrOICjzcx/w5I6lfSs4VbcVdSnQyk6xsX4gUz62lrAMgSWf8OD7qXwWtg6ZrZPK+ymIyyi7Z6W6qOPEIIhZiSxhv9bS8T5rQ/2Wx4IGJegSLNImjrePvkAiHXZJBTgyQBrvD9Vqf4B70pcJWrxKVSxPRbG6G5/4kqvDwhbWDJF1WEEjlIxLKijGGuypBpdm2JD2WX6Ac5bD7yEcmNJWXTO0meVHN583onVrmu2PjjRkO5ivDS8IEaff+AygfUEz4bMjZHWO1rsB1VgDssG05HeCeDZOi1f5gUZYjvZQMAxuCIzYSNk9/PB919ixqVj79UAdQQ5fuENc8jcFtrY5CEFdd3wPVDjypm/yOxVFr9sN7u2rhMvnWolQPyWYA7swxOp/Ls6yvVEJJd+lI6KZ+2J9mq7SCeLVOyHK1nYj6vvi7Kd9xv6wA3BKt34 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c0f1593-a1aa-4e26-54d7-08dbf1f5eaff X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 22:44:31.6465 (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: Fusjs34tGb2zGU9D/kHIBWBsU7uEp+GlIVIdxks3DOuXRazXygNhmz/GDu3xuTnGMfZRJiopjJhZIyyCC/2Dcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8851 Add hotjoin entry in sys file system allow user enable/disable hotjoin feature. Add (*enable(disable)_hotjoin)() to i3c_master_controller_ops. Add api i3c_master_enable(disable)_hotjoin(); Signed-off-by: Frank Li --- Notes: Change from v4 to v5 - using kstrtobool() > + if (!master || > + !master->ops || > + !master->ops->enable_hotjoin || > + !master->ops->disable_hotjoin > + ) break into two if, which will be more clear. and one line is 101 chars. Change from v3 to v4 -none Change from v1 to v2. - Hotjoin control by sys entry, default enable hotjoin, which standard i3c feature, user can disable by echo 0 > /sys/bus/i3c/i3c-0/hotjoin drivers/i3c/master.c | 83 ++++++++++++++++++++++++++++++++++++++ include/linux/i3c/master.h | 5 +++ 2 files changed, 88 insertions(+) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 08aeb69a78003..d3b56c9f601e2 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -526,6 +526,88 @@ static ssize_t i2c_scl_frequency_show(struct device *dev, } static DEVICE_ATTR_RO(i2c_scl_frequency); +static int i3c_set_hotjoin(struct i3c_master_controller *master, bool enable) +{ + int ret; + + if (!master || !master->ops) + return -EINVAL; + + if (!master->ops->enable_hotjoin || !master->ops->disable_hotjoin) + return -EINVAL; + + i3c_bus_normaluse_lock(&master->bus); + + if (enable) + ret = master->ops->enable_hotjoin(master); + else + ret = master->ops->disable_hotjoin(master); + + master->hotjoin = enable; + + i3c_bus_normaluse_unlock(&master->bus); + + return ret; +} + +static ssize_t hotjoin_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i3c_bus *i3cbus = dev_to_i3cbus(dev); + int ret; + bool res; + + if (!i3cbus->cur_master) + return -EINVAL; + + if (kstrtobool(buf, &res)) + return -EINVAL; + + ret = i3c_set_hotjoin(i3cbus->cur_master->common.master, res); + if (ret) + return ret; + + return count; +} + +/* + * i3c_master_enable_hotjoin - Enable hotjoin + * @master: I3C master object + * + * Return: a 0 in case of success, an negative error code otherwise. + */ +int i3c_master_enable_hotjoin(struct i3c_master_controller *master) +{ + return i3c_set_hotjoin(master, true); +} +EXPORT_SYMBOL_GPL(i3c_master_enable_hotjoin); + +/* + * i3c_master_disable_hotjoin - Disable hotjoin + * @master: I3C master object + * + * Return: a 0 in case of success, an negative error code otherwise. + */ +int i3c_master_disable_hotjoin(struct i3c_master_controller *master) +{ + return i3c_set_hotjoin(master, false); +} +EXPORT_SYMBOL_GPL(i3c_master_disable_hotjoin); + +static ssize_t hotjoin_show(struct device *dev, struct device_attribute *da, char *buf) +{ + struct i3c_bus *i3cbus = dev_to_i3cbus(dev); + ssize_t ret; + + i3c_bus_normaluse_lock(i3cbus); + ret = sysfs_emit(buf, "%d\n", i3cbus->cur_master->common.master->hotjoin); + i3c_bus_normaluse_unlock(i3cbus); + + return ret; +} + +static DEVICE_ATTR_RW(hotjoin); + static struct attribute *i3c_masterdev_attrs[] = { &dev_attr_mode.attr, &dev_attr_current_master.attr, @@ -536,6 +618,7 @@ static struct attribute *i3c_masterdev_attrs[] = { &dev_attr_pid.attr, &dev_attr_dynamic_address.attr, &dev_attr_hdrcap.attr, + &dev_attr_hotjoin.attr, NULL, }; ATTRIBUTE_GROUPS(i3c_masterdev); diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index 0b52da4f23467..65b8965968af2 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -452,6 +452,8 @@ struct i3c_master_controller_ops { int (*disable_ibi)(struct i3c_dev_desc *dev); void (*recycle_ibi_slot)(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot); + int (*enable_hotjoin)(struct i3c_master_controller *master); + int (*disable_hotjoin)(struct i3c_master_controller *master); }; /** @@ -487,6 +489,7 @@ struct i3c_master_controller { const struct i3c_master_controller_ops *ops; unsigned int secondary : 1; unsigned int init_done : 1; + unsigned int hotjoin: 1; struct { struct list_head i3c; struct list_head i2c; @@ -543,6 +546,8 @@ int i3c_master_register(struct i3c_master_controller *master, const struct i3c_master_controller_ops *ops, bool secondary); void i3c_master_unregister(struct i3c_master_controller *master); +int i3c_master_enable_hotjoin(struct i3c_master_controller *master); +int i3c_master_disable_hotjoin(struct i3c_master_controller *master); /** * i3c_dev_get_master_data() - get master private data attached to an I3C From patchwork Thu Nov 30 22:44:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 749772 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="pVBR0gUs" Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2071.outbound.protection.outlook.com [40.107.20.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8EE810F0; Thu, 30 Nov 2023 14:44:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HhbQEnY95RL9A5JaOZpnXj03+FwMtvJ4OtbQegzxpzyBUvqoGKKlWZb8ZYP3S1/i+haSN6sMqXF+qgUvbeOQiCOmfJI15eE4nA7tq811SHDXeFsLaJrl5RZmP+mXNoeM7A0KTYz4jPiJ9h1Q6G9U7i9vTPF2+2YioSSfGoJRtgHcPhMzRfAqTeAA/eKDopojVAX8JMMUvg/ca1VeOj7JO7wnYe2d8bOCkFlNsdWFDQF3LsLryYw9+wQiX+XzRkE3+dcpHu7ilHtuNm/ScWebIXlaWf3m696ozGdIczedfXw34HhEKu/VegLIGApVY4vZVyWEQvqqhdn8cHto/1jZQw== 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=CSwk4mrsbP/IlP95SQCItlUNiOZrW7VhvxjtbF83/ek=; b=G3AWjEjvc37L8P97k/quGISbUz4O7nlNMs+mvSnMiU8Fg6LQFSAgiOmdE5jbJu/Jc2DcMie4KhEMQmgmbTsVbHh5wqbCej6+20ubqAzRa6sT5URFPQ+kOSJ6n7G93DsBM/WzjQXaBvlg7P3t6BL9tpHMSSYywdcNnJeI0f59TEFCE4wmwf1fcRrjpKCRH0iLvlCrv+8IeGlJU4TdO0VIR+uklW6EAAfm561PAiYNfH6aPN/SSjkQlYq2c2ym86ACV/HtDcTaNdMGEnGOd/4hCgq3lltdE6VaSWoy/2W2TaWghQJ6W/Si+nOTPWCP1ZS1TQ1Jj8T6cUPE9YyWcHWzGg== 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=CSwk4mrsbP/IlP95SQCItlUNiOZrW7VhvxjtbF83/ek=; b=pVBR0gUsTPnCxtE1rooJAk/b68qH+ODV2EQv8g3ZFTlLuJ8mQN3t2yy/wzFox6c8EGEEf8sHbdypr8/z3XrucCgoMj3gbZbfzKRJw6kpEIYV25bjdpiGOL6LYIKtDJuKKiqIhfn0OAyCfOrkGmsO7ruUMeTv4ZPf2RVH9znoqcg= 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 AS8PR04MB8851.eurprd04.prod.outlook.com (2603:10a6:20b:42e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.13; Thu, 30 Nov 2023 22:44:34 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40%6]) with mapi id 15.20.7046.015; Thu, 30 Nov 2023 22:44:34 +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, zbigniew.lukwinski@linux.intel.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v5 2/7] i3c: master: svc: add hot join support Date: Thu, 30 Nov 2023 17:44:03 -0500 Message-Id: <20231130224408.3591288-3-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130224408.3591288-1-Frank.Li@nxp.com> References: <20231130224408.3591288-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|AS8PR04MB8851:EE_ X-MS-Office365-Filtering-Correlation-Id: 2bf35edd-8306-4614-65ee-08dbf1f5ecd7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2BRNZD6ddfb+QnFAkBnBEqhby2xIH20ggDuC8TtWD44obeFlUG5JocUfTTwikAjMCQgZUH1ZrMQoCNGuSEjvBh5NSqdbzzWHYf39SFyjpv2uzOpQ3E4+cmgu4EaKGpEpv1SzxF4zyyxpLRTKrF+yJMDlFaPrB9NrWnVokITpzGzGlIEf6Koahaj9gbffNI87gPy3/LGN6tAmu1bCZnFZhzZGA/RqoBkuy8vjmkXOpRrljoFNpPfxISBYMVTz/7M4+PUSpzGND+CD5htOWzsMY/9g3dqv5uegUuabiAjux6hlCJmGI3DMgSmAR+kRmSsywlJobvA+95RC7ucfl21z5FXVVoUEmowYmFzD4IcbFIajq2Z/z59yrjQW3im7ap6r42XuUDqbjnjex+LVM1do0o4AevHJuUwUmasyYOwcHsWAyHA5vfB5H3x1ivJNsSa9YCJmEvKJkEAuI3VlMGw58rCJMraohrcscV8zeMtgWjeLS/YTXG6tq8bLk0Sn2H5ab/PNs4qL3c7YSy2Aupcd5AzQA4YzyZB7oG0aiKkq7zhYwsJc0QvPqI5tranCoa0VSyLVSkAD27YxM0kEFVl09ZGqfIdyW60zppkrUPk0g0UPQa+YIDxSPtMnWpxCElZN1l3al3PlixSNJOHuKw1RlAZKn2QfeX/qUchGGveF6MyKnCC1sNuanciXBa6eDp9SgvhX0bKQmXMXilh65u0eNg== 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)(39860400002)(396003)(136003)(366004)(376002)(230922051799003)(230273577357003)(230173577357003)(451199024)(1800799012)(186009)(64100799003)(86362001)(6512007)(5660300002)(36756003)(41300700001)(6506007)(38350700005)(8676002)(52116002)(478600001)(2906002)(6486002)(6666004)(26005)(83380400001)(7416002)(2616005)(1076003)(4326008)(8936002)(66946007)(6916009)(66476007)(66556008)(38100700002)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0Q+b64IT+BSCQNmAss79NJWQj0xfwYDNbLY3irzsLebdS/7nTpoPLLEhrmgyfc/tLq3rUtqaIPwj6O4v7WCiUEho7ioETwP6Bu5Xp0s7x2rrLhN20nhy7V01NHVIVCw1/2k+wNIG4+uEswhQFKnNnrJBufgkpjoXw+I4piGXMA5FFgN4gEewWc7rAnTSA/UVafXLjv3JpZM86p4tt3KyD8B0gh+Vl+kKsSLUwAvZpGzCBtwu27Cza4RSo+54/tqUkyoIKmxILC9dxwZupfncMvq+oAdxocgTnKhvIQPuN48c4fPlejaChswyYn+zIUDi3uylVfGglzOsE8cEO+v7YpTniv/5U+WcsnVI7qMXhy72/31ElmwscZ9i7PbfCGjiTsnTy4A+vVTbGYIbhfsjrzimaWXZ9jylVTjLJgimjNbnVUHttgtPGk0luK+Q52cckyQ86qgUfXZ84AM4/CMeLOQWTe0+eOAvzzpqNou/kZYgD0C87Ck0rlf/0AR4TTgYeVTNOEMxlSjPEH00nQzjyMBl4SDiRaP0tdEfBQbBxc4A4TM8C+NnoS4DlR8cv+SvSbve1fgvbvqhoJbVgRzJElPpbTBaG5m33KEYjj9KsBXCCIG8Idt8ZKk4CLIim7NE0R13SMPiCn1A/DPYbw/QdJz/1vCAR3sHfUw5NhYwS5uZMA0BzOJMI/Vi0I0ufs6kyG7fls+aQSUx8+Yb6by1mOFkN0dFRzMBRw98xQWEL8HhusgG/4Z91R1M4v+3Y6xktLltLCYJpjE6S50om0m4qt6s2aAUvK6d2C8CiCi9pteRK9AelSxqjGRJGSZj7AGpUBmHhyZeOBQSiMprOVVqEMDs7kr6tRVvPWg07Y/Xf8Bk22Ksv/REWtBRda4q9EtSU81pMj5Xjm+E36LzxPHRCRWyOOJIPKE3O0UcdFoGNBYbfx+s01RtMVLV0DrxZKdkEexwj9OnNFgoZOkomUi962hrIh7XSBh4eWNSw+LieOMHAmpn6zAZm3xjquqrTlMmy4hUGpkatZcUHIaEIGv3Cj1zWkERnlEYqqmHx1CzZ+x66vyfO9Lfo8IVkUkd9NWGzJr4L4fHHuEVhUPPcExH9u9uc6TYY9oYrpKQlSXUNsWM9A1nY0dPozc24afNKKHGY6dyNck8DYM4Bn2532PQgzoQ1Sti+IPFZ1ocX4SsN3bJpvalnkiawQB6YIQWjDoopnFJrfWToB8VYtVrx0wAoDzFzmzyaLKJXjDl+uXTv5okkU40f4/W1Kh3nAVI5No/UnXYc2dDxPCgIIRVDEjo79qwIl80ChZoFMTgCHZ2mJevQr+sROOrDazB3nj6YVAEeYeSuL8vuualbH9nXp3610pTIfX6DQIMXn424hw50NPmEcijqm3a0jsY7YHckiWPvulfCy04yie3kR73R2QdWnO3B0/GQVeaHwtBMZpFdJ901xKiOIQJLMc3VVBxy8NVOqaM4PzvmoJCJZ8vasu4a5xVXICMp1QC0vAKTfVl+Sz1FJdv1hP1R7FlBx8t4bkb+3IeaiGCkzvKo3OjtFps0qCr3dWrw61+7+OIgNl9b6ZzwVYS8PzPzunzBCfjUUOT X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2bf35edd-8306-4614-65ee-08dbf1f5ecd7 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 22:44:34.7354 (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: ZWzyxPGqFp1L7tEoKBsqN3OMhiU+uKqSpu63wLFpPsmmGlMz8NpCA2QFP3AxFW4hDzUMbnqQR3BDXsIydQwLIw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8851 Add hot join support for svc master controller. Disable hot join defaultly. User can use sys entry to enable hot join. Signed-off-by: Frank Li --- Notes: Change from v4 to v5 - default disable hotjoin - add help func is_events_enabled() Change from v3 to v4 -fix build warning All warnings (new ones prefixed by >>): drivers/i3c/master/svc-i3c-master.c:212: warning: Function parameter or member 'lock' not described in 'svc_i3c_master' >> drivers/i3c/master/svc-i3c-master.c:212: warning: Function parameter or member 'enabled_events' not described in 'svc_i3c_master' 2 warnings as Errors drivers/i3c/master/svc-i3c-master.c | 61 +++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index 6b6bdd163af4f..f2058a36f869b 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -128,6 +128,9 @@ /* This parameter depends on the implementation and may be tuned */ #define SVC_I3C_FIFO_SIZE 16 +#define SVC_I3C_EVENT_IBI BIT(0) +#define SVC_I3C_EVENT_HOTJOIN BIT(1) + struct svc_i3c_cmd { u8 addr; bool rnw; @@ -176,6 +179,7 @@ struct svc_i3c_regs_save { * @ibi.tbq_slot: To be queued IBI slot * @ibi.lock: IBI lock * @lock: Transfer lock, protect between IBI work thread and callbacks from master + * @enabled_events: Bit masks for enable events (IBI, HotJoin). */ struct svc_i3c_master { struct i3c_master_controller base; @@ -205,6 +209,7 @@ struct svc_i3c_master { spinlock_t lock; } ibi; struct mutex lock; + int enabled_events; }; /** @@ -219,6 +224,11 @@ struct svc_i3c_i2c_dev_data { struct i3c_generic_ibi_pool *ibi_pool; }; +static inline bool is_events_enabled(struct svc_i3c_master *master, u32 mask) +{ + return !!(master->enabled_events & mask); +} + static bool svc_i3c_master_error(struct svc_i3c_master *master) { u32 mstatus, merrwarn; @@ -428,13 +438,16 @@ static void svc_i3c_master_ibi_work(struct work_struct *work) switch (ibitype) { case SVC_I3C_MSTATUS_IBITYPE_IBI: dev = svc_i3c_master_dev_from_addr(master, ibiaddr); - if (!dev) + if (!dev || !is_events_enabled(master, SVC_I3C_EVENT_IBI)) svc_i3c_master_nack_ibi(master); else svc_i3c_master_handle_ibi(master, dev); break; case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN: - svc_i3c_master_ack_ibi(master, false); + if (is_events_enabled(master, SVC_I3C_EVENT_HOTJOIN)) + svc_i3c_master_ack_ibi(master, false); + else + svc_i3c_master_nack_ibi(master); break; case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST: svc_i3c_master_nack_ibi(master); @@ -471,7 +484,9 @@ static void svc_i3c_master_ibi_work(struct work_struct *work) svc_i3c_master_emit_stop(master); break; case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN: - queue_work(master->base.wq, &master->hj_work); + svc_i3c_master_emit_stop(master); + if (is_events_enabled(master, SVC_I3C_EVENT_HOTJOIN)) + queue_work(master->base.wq, &master->hj_work); break; case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST: default: @@ -1471,6 +1486,7 @@ static int svc_i3c_master_enable_ibi(struct i3c_dev_desc *dev) return ret; } + master->enabled_events |= SVC_I3C_EVENT_IBI; svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART); return i3c_master_enec_locked(m, dev->info.dyn_addr, I3C_CCC_EVENT_SIR); @@ -1482,7 +1498,9 @@ static int svc_i3c_master_disable_ibi(struct i3c_dev_desc *dev) struct svc_i3c_master *master = to_svc_i3c_master(m); int ret; - svc_i3c_master_disable_interrupts(master); + master->enabled_events &= ~SVC_I3C_EVENT_IBI; + if (!master->enabled_events) + svc_i3c_master_disable_interrupts(master); ret = i3c_master_disec_locked(m, dev->info.dyn_addr, I3C_CCC_EVENT_SIR); @@ -1492,6 +1510,39 @@ static int svc_i3c_master_disable_ibi(struct i3c_dev_desc *dev) return ret; } +static int svc_i3c_master_enable_hotjoin(struct i3c_master_controller *m) +{ + struct svc_i3c_master *master = to_svc_i3c_master(m); + int ret; + + ret = pm_runtime_resume_and_get(master->dev); + if (ret < 0) { + dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__); + return ret; + } + + master->enabled_events |= SVC_I3C_EVENT_HOTJOIN; + + svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART); + + return 0; +} + +static int svc_i3c_master_disable_hotjoin(struct i3c_master_controller *m) +{ + struct svc_i3c_master *master = to_svc_i3c_master(m); + + master->enabled_events &= ~SVC_I3C_EVENT_HOTJOIN; + + if (!master->enabled_events) + svc_i3c_master_disable_interrupts(master); + + pm_runtime_mark_last_busy(master->dev); + pm_runtime_put_autosuspend(master->dev); + + return 0; +} + static void svc_i3c_master_recycle_ibi_slot(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot) { @@ -1518,6 +1569,8 @@ static const struct i3c_master_controller_ops svc_i3c_master_ops = { .recycle_ibi_slot = svc_i3c_master_recycle_ibi_slot, .enable_ibi = svc_i3c_master_enable_ibi, .disable_ibi = svc_i3c_master_disable_ibi, + .enable_hotjoin = svc_i3c_master_enable_hotjoin, + .disable_hotjoin = svc_i3c_master_disable_hotjoin, }; static int svc_i3c_master_prepare_clks(struct svc_i3c_master *master) From patchwork Thu Nov 30 22:44:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 748954 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="a5rZPENe" Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2086.outbound.protection.outlook.com [40.107.104.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBCE010E5; Thu, 30 Nov 2023 14:44:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b31855fq2DvhCsl7NpVg12bHH30hpTixRmJBUT4mO7dmdCJTHM8iW6D3K8Kr+PnJRct2qYg9e5A/y36dFpa1ro768zfYD0PgPoBPL5It2TLgc77IrCVuUEHi8+c9Nke/ug/Zak1eggcLvIkxQlVkqzGDHccvgDvGMH92fHPo0QfpIVsZ5js4aLUFWX/KwDWaE0PLe6juiX4iI1NVuoUaAz28vxK4mUgK9sNHMstgrBskIINdIea8YSD4nlNzNzJAlyGXXsEDOq2oZAirev1xUJGrw25NCtV78FfUMdKQ/m7uJNUGY4hoUlLo1bduxtllCiMEZl71MLbXF8GorIr+OA== 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=ytSmslj5oOfXj/kvlZ0mw3AYP7VbssW1sje4uneG+bA=; b=T4ft1KON8E+FmzSaq36MA5X64Ewq96fOrmSTR6+M1JTORTTR23j20GCCaV7AhR61BrTu5YMlzCW5kWTp91ELSIhZC//0wl6JDl4ix4CZLtwtFucK9qwfHIl90d/j1v4M9BiCuCcFQl/1XapuTlboX8fcM1vALsI5xjlBOTRSQ9dqDXpl+2DUB3kuWBzCEkVqJ62kiy2L5VuuIoY3KB6viBQgM6tnp/y2cNEa2jqbRvvcdXBwmc61g9XnfkxgdA8FVuzKewAFWQ1zTyTv9Ftj5+WhOgTTexjj2hKBfjsYTmCl9Ph0+A9gAizCUQHF7I0A5FtOY5VXXYM1ex0XDafQEw== 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=ytSmslj5oOfXj/kvlZ0mw3AYP7VbssW1sje4uneG+bA=; b=a5rZPENe55RfhynvToaK9m3o/vTHvm4SU2zUyvcXjY4aOy4iqKGMdm1Ww6VlKeXlZen8kKO/33+7OwvjNsz+7grmMHY37EoTQHoRsspTUtMxe1Zcya07o9UjXASAkcIqNkR+yN49dK7AbRAKhF+gNV5pTBqlF4cAHh830FxRBzU= 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 AS8PR04MB8851.eurprd04.prod.outlook.com (2603:10a6:20b:42e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.13; Thu, 30 Nov 2023 22:44:37 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40%6]) with mapi id 15.20.7046.015; Thu, 30 Nov 2023 22:44:37 +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, zbigniew.lukwinski@linux.intel.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v5 3/7] i3c: add actual_len in i3c_priv_xfer Date: Thu, 30 Nov 2023 17:44:04 -0500 Message-Id: <20231130224408.3591288-4-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130224408.3591288-1-Frank.Li@nxp.com> References: <20231130224408.3591288-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|AS8PR04MB8851:EE_ X-MS-Office365-Filtering-Correlation-Id: a6686b44-0440-4b23-d94d-08dbf1f5eeb1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qiv9MqFZ9gLTCRgG9b74Ttz5boNTt2Nd043CFehMppwf3xNAqPiUl1dG65gwQ+N614AH8kzBk8ZCaCdvohu1tix/0rsJgH4ojVUtXcSbCRkfR5AyaIIrSRJJhz5l+tzIu05enlELfut5dh6yP59/JKyf6MgXMtQmn57TGefpTjbfy16/9zQktXJlPAVZ8ITWVwQN1OryH6aaLyruD9eTaEBEt4nJNHf+M0Pnqk82f0N3yFb54LY1BTV+Z0BD4Q0xRd0Q2Gel36hUBFyP3SaFGaDeVrzw9b1C/ZT7X+WeIPAdF7WBGRZ15DomIgmtzaTljsf/kNwEdhNB0W7KFhJpi/BHLM88MS+46lFR7tRxwwQZeWcC+iAh7Km7BypnHXvO0qVg45IXG3a8tcKAc7B1gMgLRuaGOyX3MHuZnFTGGBjZByGvrxVsXs/f9w+uSP21krzabn0qGOiQQPW+Q/xbgezjqbtEz9tlArw8UcgwkGlUuYmWs60mwhtaRy3/GGqBKX2uClOZqd99+3Yh/FpEwrsLXFllwkDWi5cWWqU0ZfZR0fwumun9jLaZI3KsVq0mL5Q97T4n/m5bsyHxhgToGAUGra4WekZoCmMx1QE7dtpgS9TxrX+G4R2jVhqXTpFUsY1eWunirYTFeRmdY2BAwWaaTSZg9TyhQUx1bXgzET8= 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)(39860400002)(396003)(136003)(366004)(376002)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(86362001)(6512007)(5660300002)(36756003)(41300700001)(6506007)(38350700005)(8676002)(52116002)(478600001)(2906002)(6486002)(6666004)(26005)(7416002)(2616005)(1076003)(4326008)(8936002)(66946007)(6916009)(66476007)(66556008)(38100700002)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?QCE2BPLZF5JgK8OS2f1biehj2YY1?= =?utf-8?q?m1i3rKlhUlhKxh9zFGf1xqEeoRTKCFDtZDeYu5MDXqpsieKCeuVNt0S6nDZKVaRIr?= =?utf-8?q?982yikrwlpl5rdddIuhyk7vQ97HREuwykJOc2FP4ek4C3qdbSxUPye/qqzZgBTWih?= =?utf-8?q?3HhgJM8MCaExf8u2Fp3IqpHdnEYRLGx0xNK+Ga16WMFGZ/TUcJs2OnEljeasMYae0?= =?utf-8?q?TErIDA4rvHXC0Y9OdKSUMOj5bzhELgH0Q+e4Xg9Qn5yxFILQK0C/hptNQkD8kWH4J?= =?utf-8?q?JjxylWfFVmXxrsYQI6mhp3/oXsxcROuZzPNVUYjXLvMd5zxqvHbKtpn7EgXmHqzJ7?= =?utf-8?q?NUF4fvlxoWfG5LcMjfsrwGwOBucXBHI77FmSgdEYBZdcaqVrK/rZQWpeL7djPo5m3?= =?utf-8?q?g3NbOqeGEAmkLZGEJ8tMx0k2qhAiSf6eInjR3QliF6aAxq/VT/fZDgsuq2N7l/xS8?= =?utf-8?q?erwx6dwl+ijPfgJf1YcOzuKqAO3RsnpmK9/mYfVrlrRookAUzyp8dE3Lx0bcCcE3W?= =?utf-8?q?BPctKY6jWDZ4OVmIQKSaOrnLltszbS5+X80GFkT3Ru0Ws9kXJRAGXoI1n3HWjQjVP?= =?utf-8?q?yG8gvWHvhVr3gGof/kCoF7ly3wwEDVKTGAos7rft1s6EIqb1zpQslMJeYGziJdSYL?= =?utf-8?q?vVbbSSDu9thU6yuuq0/AGco5igdKwaVepM+e+adJYvSw23PBIRvvJNr8Vx6BgwY3B?= =?utf-8?q?z+KtsflrF7vYHoSAfOTw63lAs/PWIpJEN8cOcnX38YOY4fonxRyMA7RUipDncHcZ1?= =?utf-8?q?nmqk5OxeQPJr0IX0sOiaejaFnRNS6dVBaOSmb/u5Qvj086b1SX8F3iABizrO3y9ny?= =?utf-8?q?f6L5rHQJOZTAK86TDLnvJQAcPwyASqXTnxpjAOlZyIfXc+2XbpMn+sYVOFXIsiGKG?= =?utf-8?q?aqg5KRNqgIEKagttW9b9G6GiNK7czg017i/JPtbXV9ErKqU/6uBtul9N/LK2q0lZf?= =?utf-8?q?6YoQ2j2CsjmHdxUm11sySfCx6rYVY34mjADSVWsGZiT3kS3iqxv8RalqRVtVZHGI+?= =?utf-8?q?ztXpD2FBRUohaxCYK0y7Yj132x8RDLuyepGG4JESCasmxSf4Vm6uZSRDnS+WtBiti?= =?utf-8?q?PNIB0TjfeIiNulbRRFi4EwmyAA2QQcHzBMxxh/ESuXbf+Z7Kk/xZ2jdJBS72LUU9z?= =?utf-8?q?LMn3MWsVSBsqoXQ2icHC6TrXBCtYGR/mBM1AxIggjBvAXEV2olMabVQpP8KIxoRlc?= =?utf-8?q?juw+99+v+fVD6DJNEsyriKctsGxNxSb+d/RZ87ETjFQHyK+aglsjs/RejvmOxZgpy?= =?utf-8?q?W6+hyuM1EVUl7yZD9Rdfd9299IS5VsjLc5d7bvtGWQg/GhEs/0s+uUj/dcLXfr0GH?= =?utf-8?q?PkyTUZO0wTVUKtTHB8B96nSUcEdsbATs76EPNHu9RKyrVFNM6gY/4HLpWdS7uwJuD?= =?utf-8?q?d+i9QA6Is2AFpup3K5h9NfSZoiIq603ownYgE8gyuvIY/PJAV4vJzWfXy6GDO+Xgg?= =?utf-8?q?3N+a8PXK6mEwbRVw+vnYVsAz+6YJHNyg5ZpSKUxmt3a+zRMUJBOnjbcecTDIHotFZ?= =?utf-8?q?8Rqk0plJ40DW?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6686b44-0440-4b23-d94d-08dbf1f5eeb1 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 22:44:37.8398 (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: 02zHrarsbY50WRY9tGSu6K1IcsU/y9tsdreY89HtyGwwLAlzO5UFOpJGOwg5pXTGuskEcSi7Wrnv0tQR4nc8eQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8851 In MIPI I3C Specification: "Ninth Bit of SDR Target Returned (Read) Data as End-of-Data: In I2C, the ninth Data bit from Target to Controller is an ACK by the Controller. By contrast, in I3C this bit allows the Target to end a Read, and allows the Controller to Abort a Read. In SDR terms, the ninth bit of Read data is referred to as the T-Bit (for ‘Transition’)" I3C allow devices early terminate data transfer. So need "actual_len" field to indicate how much get by i3c_priv_xfer. Reviewed-by: Miquel Raynal Signed-off-by: Frank Li --- Notes: change from v4 to v5 - Add Miquel review tag include/linux/i3c/device.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/i3c/device.h b/include/linux/i3c/device.h index 90fa83464f003..ef6217da8253b 100644 --- a/include/linux/i3c/device.h +++ b/include/linux/i3c/device.h @@ -54,6 +54,7 @@ enum i3c_hdr_mode { * struct i3c_priv_xfer - I3C SDR private transfer * @rnw: encodes the transfer direction. true for a read, false for a write * @len: transfer length in bytes of the transfer + * @actual_len: actual length in bytes are transferred by the controller * @data: input/output buffer * @data.in: input buffer. Must point to a DMA-able buffer * @data.out: output buffer. Must point to a DMA-able buffer @@ -62,6 +63,7 @@ enum i3c_hdr_mode { struct i3c_priv_xfer { u8 rnw; u16 len; + u16 actual_len; union { void *in; const void *out; From patchwork Thu Nov 30 22:44:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 749771 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="bamEUMo3" Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2080.outbound.protection.outlook.com [40.107.20.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 267921704; Thu, 30 Nov 2023 14:44:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dBSjOU8IfeGqRnRRPIfVLeYe/pBTWm7ip6qpB1g72F+DWELNjgc1dx+mbtcPL12fJ2A4YSb3CZ+zmF6l9XoFlCSAQyDS/b6KIm5pu7nIZY67c5Y8t+uwYcwqX95OWWNnfh+iAalpzHJ9QW7lhjhA4ULnYr5G6+KWidwxJgKVegrr1j7xlUjq1q15vV403nxAD1BLn7Ij6IqPaUaYOD57oaToHYFB2Am0HSwmODDTVghgsztm5zu5dhu4MKtyOHIJ/Xu32IgKbt4eWsYyIp6auWPzDqi2YrSizrOZN99BvETc+5LuzbmsQwEbMBFYrevIP6Z+U6K56u3XbNuiUknOTA== 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=XXDAhNm+DCe1srAC+lBUWMnfd6Ayz3DSi20A50myyuQ=; b=n0x/ldLT+sd2GLxdN3cXpb1pFEd3A3OePkdrupFtBBkbpxsQn8SjX/9QiGhe7y/yD6RzjnWKgG6biY5pfrqdHdiEddHKyly3NSFZjy/drZGPI7fwPSCHS4pw1Ks1iIzv6SgxVSsmBeOqwRk6cTTHi4P5tvj8o08VoLP8QUhH1K1+vBMV4NpI/jhR98IG7l22Gx5kkC7FzXRZ4NHyh9ZgfkFfsJZjL45NnpIvSl/+8pbFGmqXtJre3VkEUi+1MOpHhX2Gr2rxE3fWMU/17eu0M39PiB6Kd0GbtxsIdbU4M6P07UvSukCMsrxKImGsurBWhZuXpd4ugXX5Yp3oOE7aZw== 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=XXDAhNm+DCe1srAC+lBUWMnfd6Ayz3DSi20A50myyuQ=; b=bamEUMo3WldkGBMya2I61xEn5kJ9sFOKNq5lIz8EqHKg3pLAw8jkOUzi704YRPyzOlXzRxWSlXq/QgdYPGFMhoLXiw5SfTr4iz+ws9NUUH4+D0k2AtC3WE9McfaB6XdJgD0uiITtM841aelb6aYvWzSVgcWEp7cHVgVGcqLxxbQ= 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 AS8PR04MB8851.eurprd04.prod.outlook.com (2603:10a6:20b:42e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.13; Thu, 30 Nov 2023 22:44:41 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40%6]) with mapi id 15.20.7046.015; Thu, 30 Nov 2023 22:44:40 +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, zbigniew.lukwinski@linux.intel.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v5 4/7] i3c: master: svc: rename read_len as actual_len Date: Thu, 30 Nov 2023 17:44:05 -0500 Message-Id: <20231130224408.3591288-5-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130224408.3591288-1-Frank.Li@nxp.com> References: <20231130224408.3591288-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|AS8PR04MB8851:EE_ X-MS-Office365-Filtering-Correlation-Id: 0641e87c-b724-49aa-8836-08dbf1f5f087 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o3IrbjDB+WX3leaGPijqF313mH1qiw6ooFkMauAGED+19dCqodMxCCyOcJ3Nuq7YWdymAFSL4LVyAhZlgKVgiK6AsJ6BHOjlqd7cpHgKhrnHl13emGp8EEU4rATT6DFAyOeUliUQK38LQoAkH6aTtGaG4dk33TSaBGxlwIdhOjk32cOp1NyeR3cFRjoy+MNo1n9GF6Owv+CgUYVLv5zAqGFFxHTTR+5Yi94BC5C4CTuIG/kFheNTmwdi74gOHkpUigxWRjFpc5lYq9F5+1obTqkUQJq+dhPRtda00OPEcdnZXnI9U38uYZewgiLY7mgPwMvNfONcDSFcirEb4IXlBcWAmNOG1tOaR/ZMd7TvtwG2/R5OkSMLQm4VvUHyrS4f5dObxOW4cThTjWkvcvl5KRjn22HG1zVNefXHEnSGdyHcQ99lBOTw1Pp2Skv9g0cXpM3wxB3457zl3Mg3ODzRUgMskyg6X+T/MXzYN+z9uI4bB5Iy09yajke81DidOFdhQPRxCjJqe37Mx2ajadJ7x/qb6YKb9ISXjXMyCpXwxh6EULIdvZCwM7k47NrF2Cre3c0NnmsF61x+HBUlzNM+y+I+SNdF0GUBqcCvDlKiHRbNYGX4Fshr0+Scgi/pMM4ZoB/exxO1UZJFCsgcoQUyx8oHbbZgX7wOOXdslUDxDb4= 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)(39860400002)(396003)(136003)(366004)(376002)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(86362001)(6512007)(5660300002)(36756003)(41300700001)(6506007)(38350700005)(8676002)(52116002)(478600001)(2906002)(6486002)(6666004)(26005)(83380400001)(7416002)(2616005)(1076003)(4326008)(8936002)(66946007)(6916009)(66476007)(66556008)(38100700002)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Mm2wkNJDtQP26COCpJb84QjErefWJUGPiYA20nFtkF64tyIarsoj074RwMknBM/OoMxhtth52ZHN6c9Xw0UHOgenRgsl+Jog/WoYVyjZC/GcwK3gc54ABE6YVf39g57p/spxlJz7P+zD6UZCvvOo3x1JyB5GxTM70Mi0QzQNChuPyjn84j2wvqL8u5B6S2+rnAcD9ja+ahrlDlK3asIEh6pE7IMYbaZejF7GMX4aJLXz8PCqJx+O4od/Ai0BuHcprNgBIGQIC/zqKgil8ytyIy1n/do+V8LLtowdZqM0MgSY2euWb+nQQ5a1YazKQwIwzcatxVmEyvHM4JizKtEzKluezT7RvAAceKU1MD6F9jghKNy4+IFfeXHZRiRDi9g5xIWjA4lzWuITdpuDEc911XU0kR8y9hrYohg0XPaTZ0KaVKWeOe7KiUIxVFOVxmpHuuQJPyqx6joRiXJbB3qhTiwQBVzFvT/xvYYqAYNBg9pKseO2MeCA9ApBxFA60QJSqGEgd5RTS3HNxn7swS/aBada4SEEuAQaetnlZ9ZwLpHEo3FRZHFnRiIk/AbdHSLo2wx9M0NrOcNWtB0EppYllCYbC2KS1hSc/JT7Jsk1H4yqRz9MjggKRP1iM8kVfykxu4Evai4thE8RWVxDoGwYSMPGzDPTtpiss0ouylGbykiSK1DhI/jJy6qCVlK6aLwIO57dNJaGtkoXXqu+zN5MzvraemJHIDlhp8KQ0jXv1Zghg2A21FXGaLRwSUV35UBPHz0pTkdsKbopKEGn/6SNqS6WTr3o0Ay3a9UYYHpOLYo9PtlS8edWFhYjkyNpk0Js5r6QtxIGpPrWvpv38qokEqAqN8PnRPKxR3LejQvFFgPNTh+9YLlEfBLDQDjwDsUCMydKyYGjWfOSSkMnd9KhOJSBLsKFuu1PBWw6lRW9BU3MQG3OE3KbRTxPjFnGAJwKnZBwyaR2Z5IrMyz2DNNJ5zJqTPJCgtJl4HXig0/A70FkaEf90b4DRti5Z34vgajJkn7N5fopviHrclMJPyWdULavPN+iv3/nfPbKQw1Uj7thsQBoq7czDnaGh+owOARhiI+bgRYzXXPNOTef7TZVZDBKF7KIVJUHjpxTnDBMj+k+uevEjCLSLyHDg34no1lzbND4/4mNSd2wnw1BAOtrDNCZhwVlLJbKHxqr5FhqJT7K+nNCj2WN5T8jY8ZzKaA2kwo12hD3H1NAZ/W9D/M8HkG6Ds6t08x5lA2F4ulc/bm3PAeHwy4oBNJO9gkD3Vev1TXySDj3xyh6g++yq7I9fq2ZKgjIOuYnUqTl3LpoEh/cpIMfcUf/93mpGPlydzFa1jxHJFXb6CVNMktI9z/xUv4q9rAhiyjz+IEc3TISWYcSW0AEH8HyZF0g5O3y2H1PR47wT8YUXFH1yJDGE9inYK1JruqT/6kWFac7ebADQbryY8GtWsRIUxH5ay53FwlhNdtHjyshEvyvre2NATr3cljZ0ZzytO1R7u69asO7ORDmXMEXW3y0dkcoXnHnW1jV70/cZBfHjqnZPtiJAkdbZQ5mQxx/VxZtT/L1PzNm6Jt2LPnSW7MKzVnDZ3Ex5C59 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0641e87c-b724-49aa-8836-08dbf1f5f087 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 22:44:40.9229 (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: j2YtxpGgr2B4jjDO0JeOwgbqOPlzdYKoku3sD6Z2cb0zdT36Eskzq+yjmKwZxLnJoB3uzwX/Cr4zWLFAihNcwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8851 I3C transfer (SDR), target can early terminate read transfer. I3C transfer (HDR), target can end write transfer. I2C transfer, target can NACK write transfer. 'actual_len' is better name than 'read_len'. Reviewed-by: Miquel Raynal Signed-off-by: Frank Li --- Notes: change from v4 to v5: use i3c: master: svc: prefix drivers/i3c/master/svc-i3c-master.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index f2058a36f869b..13a8b3c2aa541 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -137,7 +137,7 @@ struct svc_i3c_cmd { u8 *in; const void *out; unsigned int len; - unsigned int read_len; + unsigned int actual_len; bool continued; }; @@ -1038,7 +1038,7 @@ static int svc_i3c_master_write(struct svc_i3c_master *master, static int svc_i3c_master_xfer(struct svc_i3c_master *master, bool rnw, unsigned int xfer_type, u8 addr, u8 *in, const u8 *out, unsigned int xfer_len, - unsigned int *read_len, bool continued) + unsigned int *actual_len, bool continued) { u32 reg; int ret; @@ -1051,7 +1051,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master, SVC_I3C_MCTRL_IBIRESP_NACK | SVC_I3C_MCTRL_DIR(rnw) | SVC_I3C_MCTRL_ADDR(addr) | - SVC_I3C_MCTRL_RDTERM(*read_len), + SVC_I3C_MCTRL_RDTERM(*actual_len), master->regs + SVC_I3C_MCTRL); ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg, @@ -1089,7 +1089,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master, goto emit_stop; if (rnw) - *read_len = ret; + *actual_len = ret; ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg, SVC_I3C_MSTATUS_COMPLETE(reg), 0, 1000); @@ -1171,7 +1171,7 @@ static void svc_i3c_master_start_xfer_locked(struct svc_i3c_master *master) ret = svc_i3c_master_xfer(master, cmd->rnw, xfer->type, cmd->addr, cmd->in, cmd->out, - cmd->len, &cmd->read_len, + cmd->len, &cmd->actual_len, cmd->continued); if (ret) break; @@ -1257,7 +1257,7 @@ static int svc_i3c_master_send_bdcast_ccc_cmd(struct svc_i3c_master *master, cmd->in = NULL; cmd->out = buf; cmd->len = xfer_len; - cmd->read_len = 0; + cmd->actual_len = 0; cmd->continued = false; mutex_lock(&master->lock); @@ -1277,7 +1277,7 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master, struct i3c_ccc_cmd *ccc) { unsigned int xfer_len = ccc->dests[0].payload.len; - unsigned int read_len = ccc->rnw ? xfer_len : 0; + unsigned int actual_len = ccc->rnw ? xfer_len : 0; struct svc_i3c_xfer *xfer; struct svc_i3c_cmd *cmd; int ret; @@ -1295,7 +1295,7 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master, cmd->in = NULL; cmd->out = &ccc->id; cmd->len = 1; - cmd->read_len = 0; + cmd->actual_len = 0; cmd->continued = true; /* Directed message */ @@ -1305,7 +1305,7 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master, cmd->in = ccc->rnw ? ccc->dests[0].payload.data : NULL; cmd->out = ccc->rnw ? NULL : ccc->dests[0].payload.data, cmd->len = xfer_len; - cmd->read_len = read_len; + cmd->actual_len = actual_len; cmd->continued = false; mutex_lock(&master->lock); @@ -1314,8 +1314,8 @@ static int svc_i3c_master_send_direct_ccc_cmd(struct svc_i3c_master *master, svc_i3c_master_dequeue_xfer(master, xfer); mutex_unlock(&master->lock); - if (cmd->read_len != xfer_len) - ccc->dests[0].payload.len = cmd->read_len; + if (cmd->actual_len != xfer_len) + ccc->dests[0].payload.len = cmd->actual_len; ret = xfer->ret; svc_i3c_master_free_xfer(xfer); @@ -1365,7 +1365,7 @@ static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev, cmd->in = xfers[i].rnw ? xfers[i].data.in : NULL; cmd->out = xfers[i].rnw ? NULL : xfers[i].data.out; cmd->len = xfers[i].len; - cmd->read_len = xfers[i].rnw ? xfers[i].len : 0; + cmd->actual_len = xfers[i].rnw ? xfers[i].len : 0; cmd->continued = (i + 1) < nxfers; } @@ -1405,7 +1405,7 @@ static int svc_i3c_master_i2c_xfers(struct i2c_dev_desc *dev, cmd->in = cmd->rnw ? xfers[i].buf : NULL; cmd->out = cmd->rnw ? NULL : xfers[i].buf; cmd->len = xfers[i].len; - cmd->read_len = cmd->rnw ? xfers[i].len : 0; + cmd->actual_len = cmd->rnw ? xfers[i].len : 0; cmd->continued = (i + 1 < nxfers); } From patchwork Thu Nov 30 22:44:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 748953 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="WRW9meVa" Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2085.outbound.protection.outlook.com [40.107.104.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C15C170D; Thu, 30 Nov 2023 14:44:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ocB+xAJcxM4hzsfwx9o5xcy0MAIh1rtir9Qqttt5uBJqlF0m6BiLrmsl119VbZpsmJdzZqu6F5kJf4BW4645MI9BSTUtIPGoT759dtJZ82WQfiPNPtWhLn2n8N+YwoLzMgfX1fDTE0Ht3qWTWdcGO34u5f33v5AzQfgWP0bwFQ1H36c8gUKbhuI185UD1Ky41ROda8+i9pChA8aILHcpdsTYQ3ybncZVhChIezDhcfEoJmYlp2fqS9pFx+crO8F0s3w6p7KhySJOiW22xvtis2re9jW5eowdkErtme+B62Hc4EHVtuF3CvPFFc/RqDO4bKKDgCvqydSRhIk3Kc5WEQ== 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=QZK3nbhXsExbv0Znn3D5HF/BW5CgmYGvGvpxgFhIT0s=; b=MLKtNdPvZsQ8qcMJ/lEU03gmkOiCvytyZaYZJTVXX5k1grYZ0+VeuEX8keoT/HDx30yk4AuAsDoTf/3Cj1FkY5trdkROS4pwtKWER1YkqXbQRQIzavY3B5g2ZmKnDgA0f/Yl+q6nWHGVLFuC+PXDbJz27q8/2qcsrVK/kBIxzw/rPgpR+Ai6lQb3V8zb5q0ErWbCTiaacsfigwSwTIYlK4FA80n8EYc4/Dc91zUGpRXMjvQ8sCYyMr7wHx7HExKDTlsnBXoSy1kGPdkMDN4KbWDDDVbMuSRycioOKs7SqMAJOvOsiPCgOjBn26AslwEmtmUbwmKKWwdCI2pAbaqXsg== 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=QZK3nbhXsExbv0Znn3D5HF/BW5CgmYGvGvpxgFhIT0s=; b=WRW9meVa5S90wj538VwkGRKL5J4ne4SbYDyEIONAm7j2LcaUdZWDnKRIGkpjf/okXIQCZo4iVZjTkUgc5dUUODF2GlAxC5YiyAxB90BB5+GvSe9RBi0FkdOKUmTn9TORlaN+ZNOh4bA1+DfGHqNUe4WuRHe9rActI6LZZOy2yq0= 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 AS8PR04MB8851.eurprd04.prod.outlook.com (2603:10a6:20b:42e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.13; Thu, 30 Nov 2023 22:44:44 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40%6]) with mapi id 15.20.7046.015; Thu, 30 Nov 2023 22:44:44 +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, zbigniew.lukwinski@linux.intel.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v5 5/7] i3c: master: svc: return actual transfer data len Date: Thu, 30 Nov 2023 17:44:06 -0500 Message-Id: <20231130224408.3591288-6-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130224408.3591288-1-Frank.Li@nxp.com> References: <20231130224408.3591288-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|AS8PR04MB8851:EE_ X-MS-Office365-Filtering-Correlation-Id: b3114018-fa4c-405f-5e02-08dbf1f5f264 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Rqcs962DLN/vmt9CWY3Op7uNistBs8i8kBTmsEfAva1b+LqIJG9wff/6s0ZT8rK01XPKBaysGz8pKwfWZjraE0BAfIA9m/QylBWLgYRovMZRv0+iyOGuhWm2Y1wqY6SJ5TpaULeRR51W67E2RkJMLys7fQPOi3WBcEpIMO476uckWriIgHm1uHjvMDqDF0R6Uhs2b8hUP7KhRLMzhbA0FF1UOVwFriXoSUAAo89P3mNv/Gf3tgXObWZdNpPy29pz8dCkAnH07qyWUT71REPO8Mtjx/29DxTo5PzkExIcAAxzCfrCWBiHYNfga3HiYQVTr+DFx6Mpy5r3ASeerADc57hmI+1qV8X8lV7SWJUbVuyXf4bi6w17tSVaNx6VCmoAZ3MDKn8F1dOWB7B1nmldSA1DXPEhvRuuhUocQhxshISHNKYqxe2gI49WF2drOjjAqK2hFRAoalkhSmCna9ZL4A5RbziXumw1BT7KC2Tk3T0CikK5ZnEPFXsZnLSmKRa3gD0r8aRmR9gGZwQbk/+sw5l91ekT5o70A6tcbWmazj9ujynDl/4QqCpcQ1aXY2NwqyctmLNdY19E2qjQOUixdNCRmpgPH1fccOPBUec4xz58MC1vxAou379klt7q3m6F4tLxg1XVn99a0JPDXZ5jamQpQulWEegeUTYKQ8jaToI= 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)(39860400002)(396003)(136003)(366004)(376002)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(86362001)(6512007)(5660300002)(36756003)(41300700001)(6506007)(38350700005)(8676002)(52116002)(478600001)(2906002)(6486002)(6666004)(26005)(83380400001)(7416002)(2616005)(1076003)(4326008)(8936002)(66946007)(6916009)(66476007)(66556008)(38100700002)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DmPJ1u2oMHj9G3BfoED7TQuetp34mhMogwkt4z8NL9rlXL28uPW+M9gIkuXPVe2pEybKHcL2Al3Vf+O74pUdkZpLN4i7Xeihx5ytGg4UDD21wNkudVQhBYX/ogs32DxYodCEzpjznNj9+8yo/bEd7JAU750TZaEJb6Laz6b/jr5ovszsAqUEXI4Lk/lm/Fz3O6yXXD3GbrmwrU7ocC2Ty/J/2xReq3yATcnb4VfJQnFZcFZNAU35Tw6S87DvVOuRnirlwDhhJCE9Vpo3A947dHJQgrTQy6Jp+nYvdfluAYByCRCEyyoqIo6su+xntkQOEhWl6cXuU6o/x3yuM+SRd/3JC7cu9ld0f4B1RyXJqvLwfP3f+7ZtmMprAMIrIKSgjCwBAUn/wbO1uRhLQnb+tIuzSERAgUikqoPb2XSQp+q2dxZUYXnaGkxby1kMSEN1007I63TvfRNZ2EvAyqOdzk58nwTxx95Lzi/RXwE20UDr37uxwuHs7zXKYBqAR0Vq7CD/Ff1ZNBrgnPypuJTIrFd/jC8y1GjU1DSPrEOjQgWmQUcmJVUtvPAL41+Y4c3zeh78jwC4qQvedI5wC3pQeb/UBO0/YP5LeSL6PSVZEIC0MC9s2WdWJg0FHQCYKu9cgtFN8euV5tv5goCZShJCg9BZuSb0LoB2wVL/OHiToCtwhCYK0W2F9tin2CJUmp/fcDu2KWqhunGh/GS3593BNR0+yvpaIr4pXmONqU7D6+41XVWFVnyFWCXp5XjDMSrqOYtDp5gdK4sjYSvHS5oWDTfN344F9YttnTC+UwN8Y6ZndcPzlBlq32FS6P1JnDBOgnN6053knDHakoas7JHPVRpKjKVz0CfjjVtVsixlyd55Yu/1THXLi6VSHV33OM62qOQLJ9MHEIomPmL+w+rOGtZYqYBWUj/DVXhb/t3SY3njId1G2h9IFOjWHwGtMmH1fbcv9YvF7jtS3fGH4yo3Y+QTEHZKcAXX42JbN4v9Ilrv/PnuxMCWOIIzoR7ie+Hk/LazW1hHwKVAhOfvCfpWGdZBpK7XocLX8yvWbKNzB3Q905GSxGVDjo4ZE49/bhuVYcL/3KQO2c3FvE2/6s0SW+MUz6s/GDO2sH184XzwLddOPMR9q03hTr3SpPaF3Dw3NZXoB9mIGm5Rcd485SiN+ZQCvSxyJhFmeLHlwN4GjI/YWU/azVh2j+TDsz7EWmZ6RIGH4AiKaRMUh5Tgv/saBVmXcLhmaq2YnvzFQ/hOtnJ9T2RO4ZYLb98Y4RQ1iZCT4YCyqvHDH1UdraMVyZyBeActV8SbZulNPzjUYySPW8RRvOeCk8VOy9OfLibvEORU8kqMWpUyukqtHSF9qKD9i8fKDJiHMzX+F/zUjDJ25DY/Crr/oRA2ybEIxQayfj7MiI6b73rGbXcfNqvLuy7YbdS5VGPOHpqVdA39z6UlkQLI4ay2W8JGsc8EFd37Ygr0kLcFMZcoLgvFwkVHrjJlDU/u5ivuVi6U+L4h30VM18U6aw2n2BIcp7SnxOoC1s5dPJPpGiDczGdJRZxW3zBNMyWU407/d1gdGFmqIlmk5zKJxywQeboq02PYy56ygjy4 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b3114018-fa4c-405f-5e02-08dbf1f5f264 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 22:44:44.0665 (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: 4aScZNCBXzj0Y7ndss1hDHQ1we0uG98m2Mw79yHDPjUH42WE1oOQYbkj3KvlUcajRPLti21yCKCphz188pDI/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8851 I3C allow devices early terminate data transfer. So set "actual_len" to indicate how much data get by i3c_priv_xfer. Reviewed-by: Miquel Raynal Signed-off-by: Frank Li --- Notes: change from v4 to v5 update prefix add Miquel's review tag 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 13a8b3c2aa541..bd10bb698da0f 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -138,6 +138,7 @@ struct svc_i3c_cmd { const void *out; unsigned int len; unsigned int actual_len; + struct i3c_priv_xfer *xfer; bool continued; }; @@ -1061,6 +1062,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master, if (readl(master->regs + SVC_I3C_MERRWARN) & SVC_I3C_MERRWARN_NACK) { ret = -ENXIO; + *actual_len = 0; goto emit_stop; } @@ -1078,6 +1080,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master, */ if (SVC_I3C_MSTATUS_IBIWON(reg)) { ret = -ENXIO; + *actual_len = 0; goto emit_stop; } @@ -1173,6 +1176,10 @@ static void svc_i3c_master_start_xfer_locked(struct svc_i3c_master *master) cmd->addr, cmd->in, cmd->out, cmd->len, &cmd->actual_len, cmd->continued); + /* cmd->xfer is NULL if I2C or CCC transfer */ + if (cmd->xfer) + cmd->xfer->actual_len = cmd->actual_len; + if (ret) break; } @@ -1360,6 +1367,7 @@ static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev, for (i = 0; i < nxfers; i++) { struct svc_i3c_cmd *cmd = &xfer->cmds[i]; + cmd->xfer = &xfers[i]; cmd->addr = master->addrs[data->index]; cmd->rnw = xfers[i].rnw; cmd->in = xfers[i].rnw ? xfers[i].data.in : NULL; From patchwork Thu Nov 30 22:44:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 749770 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="Zyoc8FVc" Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2063.outbound.protection.outlook.com [40.107.104.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E8161731; Thu, 30 Nov 2023 14:44:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZMb7Px7DzGm9QuNHUBEX9n5hDyt7AyC9pO8rqyo2k/VHKkkrXS8dwUK/i1hY0x9/+quHRbAaBpkGra/EEAXC5N3s/spB7+oTrCbx+KXAZESlcDgbFCQqOTvOQ3EAmsjs/7+SUcGbBQxieWQ2DnP3LYoGlmW0/avoXtj1vTnERLY5C3vk2fkSxAKLWM4vq2ZqBFlNzv+JBbofT1ylJ8d0pmOTB0CHUN49mKolEG91prDUB23cdgs8JfT3argSRET8USlWFU3ivl1V+yMx9LS6HdCR8Wc6xgrUV0ewQ2ZHMu8cMXr8eGrKLkrMD9P5pbyI3mg9S20o+hewTWJN9yyuOQ== 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=b176R2RF531nL60YMogkuUjnlG8fVTLufS2yB0DChwk=; b=Uphf+0W7V52tqyJ0jV0X8M/q4FGFXshKfnLW/cNi8nqbT0xwFpshgMinKVN+Cm7k87+XXO01M1fWMfte/0kANzTkoTr16iqTlmwICj5DgYzzB/X+hlzZF+uIcnOhYyJfMvSXytFr+3I347KoR3xwu9OuhEUIgZ/hjr16uIYWMIz/6RM0O7ly+FNRiG0p/visk+5m5NOW8kl4LUoXspL/exkKdD3LoYPZN3/4G4FKmMvu2Evet09sGa6vP8oEo8M9mKxtLF87UtJqzD0dp3fFawGdQrGBWp8SDhaH4pQjHXUJcq9hB+utTTVsB95xtMVChqiGnRDgDZGmjpMVzOEcwA== 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=b176R2RF531nL60YMogkuUjnlG8fVTLufS2yB0DChwk=; b=Zyoc8FVc8k4zF+Ke7WIqdZdcAZp68aLNeBh715zw15uvobKRzeaV+6rrT5n/Gf4NLWZ4GhcaZZjKtp9a9j9FxrW0CNXGWT2nPddZg5iH/OxRJuKiumOpPHO+ovb5BRRvg+qCp4B35P6b2Jiaa9oHWo3KmnxV+21Fj3ASMgLNlsU= 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 AS8PR04MB8851.eurprd04.prod.outlook.com (2603:10a6:20b:42e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.13; Thu, 30 Nov 2023 22:44:47 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40%6]) with mapi id 15.20.7046.015; Thu, 30 Nov 2023 22:44:47 +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, zbigniew.lukwinski@linux.intel.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v5 6/7] i3c: add API i3c_dev_gettstatus_format1() to get target device status Date: Thu, 30 Nov 2023 17:44:07 -0500 Message-Id: <20231130224408.3591288-7-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130224408.3591288-1-Frank.Li@nxp.com> References: <20231130224408.3591288-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|AS8PR04MB8851:EE_ X-MS-Office365-Filtering-Correlation-Id: 665ac62f-6107-44b7-33e8-08dbf1f5f441 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EipFGbCe+nmVQaqLJq7GJQF1vUugZxSxnMKsAsCein/8HxgN6GuT9DYyoiuvrCRuBHp6Ls0WHdgKNYbx8XR4aCCT8rWRt1k3Q/oxfzq/3aLtbms8uFmTk508gBLQTdT0ehWWHmfD2iXKCuBiyqAW1t3ekfOMDnzJYQEwrshs1rNZmYf/JqdSQDQx0Rcq2gY4tUcjBo3p5i52DAcrXuUYqulRJ3e9pVwtKmpJglMmSApeCQzeH6XR6VTJA+4bxBCdv4Qbcato0qhh506WE37OJQN4jIbcgrPiT2x3rLRRggsDiHA8/KJFFGcpRkx2n8lA2BThqEPRaiq6XG8zrHaRen8FwuNA8rgZQIaKLHHQkGF/RX/K3gtgIpS6qZJcJptYaEclrmBXgiWe4S3iUsaS0zn6Uigjn81qP8mCnknmA5qFX/vNaFFUjCY4V/02ZUraDuYKAZSBo/f5kiJTHy2+KxfjvKMolNfdeEfw7g/TdUCQ8PMslKrRKH14pwf4KUJJhHri7RFGj7Oak1Zj7BTgZgXHSoM7CIi3IK86ZuyDMCmWyVl0+G1uNKcGBq31qt+qtYjeSN0WSos4fOB0ogC4Lht4XzjIMwhW0u8jnxugZDUtf77azBJMXRvyAzPYC46JSitGHNTu4HnTh7ERtjVne6bqkPmMld3tN/Q2bsNEpb8= 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)(39860400002)(396003)(136003)(366004)(376002)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(86362001)(6512007)(5660300002)(36756003)(41300700001)(6506007)(38350700005)(8676002)(52116002)(478600001)(2906002)(6486002)(6666004)(26005)(83380400001)(7416002)(2616005)(1076003)(4326008)(8936002)(66946007)(6916009)(66476007)(66556008)(38100700002)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xsIVPO4ryE1EDW+4eDeYpj+Rgy6oxzxfNz5a+kI7N+peOTR5xKZHQmhcc/axrL1oReMFwc4sl3oecU3tuJW4DNN0sBlVbPl5RplCiJY3zKuoKoN4y8tpzUF2yQcNi1Q0TZcOzsAD7fqi+NoeOxevljjb1VaaSsz8xUiZw5tauVgCS9s8LXGVlwD8pmxO0F+Am/W/7kc2EyLHd6FltMZESmHcVx085JHwE/0fPs6NJKBUcXbC2QJP4DwhBZONcJO81lWsRpuJUCE4x0B2FrCWQSY/C4PJ5fNUAEckGSYr78oU3ezkgiJ/tbmTokfZGxgLTQbE0Ih07h03QocrdmAFdAkvkmyFRbIIKO9jyqomXWOXFRiCD83/mcVo//CtDdznqckHVp6zMr0bgMPxrsWDqlBNixI36QLJt9bLBn1Lui1BGvur8ZgvTMR2uTHzadVizcvZnxbEeiHExJHCZHrWLOP294zy+j/X379N6xuo5p9R/U39mEVZT/MoRbbHN7BFWuY/wZClX3Wx4Jz/o1eWPT9HyiN9FqIAv/OLMMwy5bjvyT9mV4p5pjjeO+WrpPOZV+/B5PlETx0o9ASqcTZg5kgNURRUj5+sGgipS8Blen+47d5+jRy4ZMdxwTvs2Nz67o98nZJKO/Jt8sfGePOP8khai2xNcG1gK+ibock7oUEPKUG6Z78GTH56PmCBq1jd5Qrd/OflyllpzQclSGAn10/ZPYfnO/MRpzidHuG70k4zEOIOjnYIODO+7pKyR7FnJPK/WEds6LMofqmRtAYI7TVXg6o0gs4YeGn9ovv12xRTL8ctTX05LsRe5SWfXgOUXYShp6cQLbmCHCXSnRoLwPQSQQiigSjb3XaxF/Q8Vfs6zWC143GMnwI5L/CzjHkqMKW+SYOsmxKX+NHgkt65BgxVFCtPVcCPhCiIS+/+YP5OCR7eebij0c8P/B6uJGWmlsA2w+GKxiBjQvvg26RN6MQQc9XHw/maBwx/EZuAjdI+Uqz9O1aew/cFvuebcQWPFL0y3bDjgX4uFHfbxwPDdlxR/bsxNzOiq0hKcyk9h8/wpAUGwm5MRR/2LDaC5VxMKxX8jMeWV2wvgqE6cFpGNDOAm7AlTB+taxEBt8aGds0BCh1+NJnKBlW5tKQZ/bgiZuCT6Do8d51g/5FJGlJQD7SU7+e2b0fjLztzgtYLsW7mXnR6YL/SvdqiUNsYNPFeJ97InDXMNTtBu0/5NtEtqK1qUfxRCAtgzssE+zAziOhrxSPdklo845QxWVMwlQ9vENiROPBcc8EZ8t4C317rRrBawq3WYD9z7aMJj5tM6o7b0SVDZZBZTU88ngXOLgOekjj2gxxzNSf6zaO/kToCaDcy3cICRpREN54MGYWdQjkTREme91Fmc4e/jfmBx719ijnproyS1MhO4h8rKM7bg/sU9fh9hhBHc/+D+vnr5lUNjuErDQv2ZMhNE2BKmsupcbdQfKGxkJkdJNE7EJVpSPuc1yXMEsZB273ZKXRwDDZPOQgq8y0qnaDYOOPl6eXcba8UN0kNcwL34woTAmg47neKKHYbMQ0uQfr8VU7oO5kLIB3wyev65VQiebBRAuNB X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 665ac62f-6107-44b7-33e8-08dbf1f5f441 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 22:44:47.1601 (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: kolQr8cS0D6vUzch39fsfxOl4FR2bFMRJnMpwtoWgbEAqcOM6Gi5wXDz6AZmVDToo5F5FNitSX0XegRUpfBkpQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8851 I3C standard 5.1.9.3.15 Get Device Status (GETSTATUS): Get request for one I3C Target Device to return its current status. Add API to fetch it with format1. Signed-off-by: Frank Li --- Notes: Change from v4 to v5 - none drivers/i3c/device.c | 24 ++++++++++++++++++++++++ drivers/i3c/internals.h | 1 + drivers/i3c/master.c | 26 ++++++++++++++++++++++++++ include/linux/i3c/device.h | 1 + 4 files changed, 52 insertions(+) diff --git a/drivers/i3c/device.c b/drivers/i3c/device.c index 1a6a8703dbc3a..aa26cf50ab9c6 100644 --- a/drivers/i3c/device.c +++ b/drivers/i3c/device.c @@ -196,6 +196,30 @@ void i3c_device_free_ibi(struct i3c_device *dev) } EXPORT_SYMBOL_GPL(i3c_device_free_ibi); +/** + * i3c_device_getstatus_format1() - Get device status with format 1. + * @dev: device for which you want to get status. + * @status: I3C status format 1 + * + * Return: 0 in case of success, a negative error core otherwise. + */ +int i3c_device_getstatus_format1(struct i3c_device *dev, u16 *status) +{ + int ret = -EINVAL; + + if (!status) + return -EINVAL; + + i3c_bus_normaluse_lock(dev->bus); + if (dev->desc) + ret = i3c_dev_getstatus_format1_locked(dev->desc, status); + + i3c_bus_normaluse_unlock(dev->bus); + + return ret; +} +EXPORT_SYMBOL_GPL(i3c_device_getstatus_format1); + /** * i3cdev_to_dev() - Returns the device embedded in @i3cdev * @i3cdev: I3C device diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h index 908a807badaf9..976ad26ca79c2 100644 --- a/drivers/i3c/internals.h +++ b/drivers/i3c/internals.h @@ -24,4 +24,5 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev); int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev, const struct i3c_ibi_setup *req); void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev); +int i3c_dev_getstatus_format1_locked(struct i3c_dev_desc *dev, u16 *status); #endif /* I3C_INTERNAL_H */ diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index d3b56c9f601e2..81611a3e3585a 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2923,6 +2923,32 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev) dev->ibi = NULL; } +int i3c_dev_getstatus_format1_locked(struct i3c_dev_desc *dev, u16 *status) +{ + struct i3c_master_controller *master = i3c_dev_get_master(dev); + struct i3c_ccc_getstatus *format1; + struct i3c_ccc_cmd_dest dest; + struct i3c_ccc_cmd cmd; + int ret; + + format1 = i3c_ccc_cmd_dest_init(&dest, dev->info.dyn_addr, sizeof(*format1)); + if (!format1) + return -ENOMEM; + + i3c_ccc_cmd_init(&cmd, true, I3C_CCC_GETSTATUS, &dest, 1); + + ret = i3c_master_send_ccc_cmd_locked(master, &cmd); + if (ret) + goto out; + + *status = be16_to_cpu(format1->status); + +out: + i3c_ccc_cmd_dest_cleanup(&dest); + + return ret; +} + static int __init i3c_init(void) { int res; diff --git a/include/linux/i3c/device.h b/include/linux/i3c/device.h index ef6217da8253b..5f511bd400f11 100644 --- a/include/linux/i3c/device.h +++ b/include/linux/i3c/device.h @@ -345,4 +345,5 @@ void i3c_device_free_ibi(struct i3c_device *dev); int i3c_device_enable_ibi(struct i3c_device *dev); int i3c_device_disable_ibi(struct i3c_device *dev); +int i3c_device_getstatus_format1(struct i3c_device *dev, u16 *status); #endif /* I3C_DEV_H */ From patchwork Thu Nov 30 22:44:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 748952 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="I6eILvFj" Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2046.outbound.protection.outlook.com [40.107.104.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D03CF170D; Thu, 30 Nov 2023 14:44:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ahWYx3686Sb84A4KwBFL9gW10GwWIg0xTm/RaDMFusCjNdUNKOQay7RELnMbWNIpuu7W/E9q2rLTtrnjY3dYmRmPSx863NKOxCdM9v668JybhVtg10CeLdtQHow/Fy3c3Ku14uGsn9VzZPhaxLEQG4Ghx7BJrBWbM4rKT8aF6ij8oUBkZvNQ+pCIhLa/9mbksJX4mFtAuuA+0TcNnfHV3B7AA8LIHI0D32c9EOtx59gAzX9oj1Edesf7D7DbrrYKSvcKDIQDGDvBR0gvTit4MBeRqREJdPlaHfHyTtaz5X2FuSAkdPll6nwk4OBOSko+zRR584t/m5gpkSQMA5QOFg== 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=JVwdPYrdC9yolJaLwxvjAv/rL0dBVumdMjDodYqNwX0=; b=oXst0re/eFkosVVqyD6UCjYaEI9gcOZe8/h+sbitLPNtO6XOE5mfPm1doJiamJgKR6Y1KA2oOqnfSMad5Cxo+YXz88bYJdWMKslL2YXj9XBAZZsWB/3vw0p+ZNwcCjqp8zj8xljr5SE2fKZKPjm0e9UQye4l+76s2r0V0FLZ+yp1ypj/fJOEatr+qFFfXsBa+cuknPZTpqLR4er4bIJ4WevwrE9ZxAlK5X90Y2gr7lIbPX3fMTUdbTbqSU+KIs8IQLeSFUPaXU1u3Ct1hYdB+W42U/vwpTAc4Q76+OdfNe8+ceb263yRlu9hwYgk94GFNfhUZrstN7Xo3BUYaIKt5Q== 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=JVwdPYrdC9yolJaLwxvjAv/rL0dBVumdMjDodYqNwX0=; b=I6eILvFj1tnR7rnSsZPg0Xc9GT+HxZAJZmXsv7b+izeZTnA9rvoGXGnvb/ygKC1Co7xV/xTv1N679IUdxXPEIs4MfzYiAlOh8dWoP4HFPYmleim6e/tfvh72a2Fprz5/WJvgNEDkezvN8PBUqfgvisy9+8qUTbWs9DF1UewuSOc= 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 AS8PR04MB8851.eurprd04.prod.outlook.com (2603:10a6:20b:42e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.13; Thu, 30 Nov 2023 22:44:50 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40%6]) with mapi id 15.20.7046.015; Thu, 30 Nov 2023 22:44:50 +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, zbigniew.lukwinski@linux.intel.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v5 7/7] tty: i3c: add TTY over I3C master support Date: Thu, 30 Nov 2023 17:44:08 -0500 Message-Id: <20231130224408.3591288-8-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130224408.3591288-1-Frank.Li@nxp.com> References: <20231130224408.3591288-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|AS8PR04MB8851:EE_ X-MS-Office365-Filtering-Correlation-Id: 03f5fbdc-4f32-41d4-44d8-08dbf1f5f619 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C9P7xxkFG9o00fIQw2uewAq3mhKWAbwEQNHMC7++2dJpIgyXFPBGPgUU1cA4uvs5FaETpeFixGpGV8aEmPY01IQ14l9Z9Uh165VuHzE6091F0Mq1GI/TOmjdSXaY6z2qIzsh9iDuYWZYdgX1Zwoem30uRl5uieJqlnYOmU+M+6T+hgpGIrBhSz1EpMUq9PTp/R5jrrUrIlD9nRAxDS8hBCHBwZgcCmnr44X+mna+y45qYzgaHv6tlgPvEdCWoSR2VbVc4hdxtlJclKV2ZoHtfk9YUMbw3ANOLkpDZ0Foi/P0izes9KCUeSS3FvN/GLLyaOK93wNvE0+B78A+AZYusXJ2jsrTC7Z90RQvpL54OAZgo19k+kJXmr0b9/7qdwiO1OZcELrRhfGSoVXhF1rsZI5FY7VxxgGjyqyXKAJYw/lgDk5NWGrZ9Hp5VWG2slG79A2RxPc+3E43h5FQ4dyUzHA/yjWmp/UfButjrqE5ccURRDAEbqoDd+8ZOhtRd58N6mUc2B6/wv6bhBLwkuPzHMxy804YPTPyr6bnhDFutNQCKhc4VMyo2wleB+YLXJlmPsnbgGtxVY5+rxnK7E+84YS7LhvhYzY1VyVhIrwKkqZHvB6HzKJ5Gj05Ps2xusW/K9p7vvevT6gElq0V5uCzRfGtBjokQnlTIDAa/5SNIdE= 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)(39860400002)(396003)(136003)(366004)(376002)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(86362001)(30864003)(6512007)(5660300002)(36756003)(41300700001)(6506007)(38350700005)(8676002)(52116002)(478600001)(2906002)(6486002)(6666004)(26005)(83380400001)(7416002)(2616005)(1076003)(4326008)(8936002)(66946007)(6916009)(66476007)(66556008)(38100700002)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BJGaz2WghYT23b++ymyVbKY8a6o3tGhcSt0JBsE6nreD8exZnnrf3l0n1pTBdKWgVyjKG4YTScotIRolXK1BxLvB46seNpxmgWbDErj+WGNaS0wSN6yIIiv0GjmY3vox0YJb1mJqpUJKX+QPd4cu8S1nH8Hk4Wkq+pz+GGf8l71CqV2RjXhbWEKtD3wZ99M7Kw1x8Ay9YDnv9rFo2p4fBa5YF6EEw2cK3kQlvCIbulAbzJOprCayZB78/xyXXqyz3lL2K4vdTZ1KZkjuCYZAdMB/VY7S2Es0Y8dVfja1Zc6WR1u0R+mY3C8A4sCDPmHZm2op37LVori0sp3XQmDDv3L6fCQW7tEMA296k9/ipe1kdOU+NgSgPqxHpCVnP2Y3gcMpdwgjFCLBJ+0nzBqVse7MmCZ3kCqwLPrm/s8nb5Q4oYOGUmimv5PeamP4mKIRd8In51xU7PxnWyMx4N513rjfoRNQO6M5i0UIKC9camouiqoMFcx/zfjz57V8Ohdsv7Ohcuu3oQ51D70o7lrYqzYtm5+D0FZZtkeRLvc3RQ599hAeIav268p7HgvG5oaMviWKtEgDwvWjcN1U7oYT1sZJt0sdKKdALhgnHzE3tby445huREm+LUygQnh4HuOxUus+WUHvlc/niL5+Hk/dK5cMi2RttRvoYCyhfPvwqFnqe68yYz6dvWJvTmtujQQug4WkiSWXbE3shQZazqiGBtP6g4G/07V+2lMF5Hd9KjiDGqpGhcjMMo2I/kloBj+DqbeCOJZ7iFrGyojjv/Rps7WF0H0xPXUHaCOKc+OfGoK3cLlRaRIDDqO8GG1nsp07iQZgE1hNcSMcABHbQN5zcSxYzQI4yE97UPPK52qqE1INbK28Mgz5yWsVWb6dY6q1XwpjMtdqHkJn6Bn9DxuRaqUYEyfhtdus0EdvDRdLu8s3fVRRuRg2cpK2ua1TrT59hwZr8auow0bGan+sdy6xPeq6wq4TSQLbTNuleSWbsMtnmEtBlLqDEp7sS4npF3KoItP9kEgRdBESU8R1ySCX6w4usr4vBrCldQfQG29m93WdGsPeUpFTL36UqdmdssNfO3tyCLRyRNDQ50/PM9it+oafhgiumbsZTdyR63OCtugs/WVQnLHiW3CTXJ8iJAjo+vXmStouatf6vFa0vEg9IfQwMqaFXmtUO2LDHqLmp6v4bKU8zvgL5oc9U//Rbfv7+1Ixg5Lf+WtNozybVoZSBmQ8T5TwNIqPSbwX+xY4nl2oCb6LvmP5yGD1rWHdhGC/juv6IMH5aQisklStrJZDutaVX2Y1yr1l/+k5rBMGsojz0ZEBLHxTLU//zGxJWlKf8gXQQS+fnOZyeWesIVRRf9U5Qu6gRhRvsUjjiBGupZWy44c6KI1l5chNeUMc7MR47OKaI7/gVtplg8ZhUNfdAkUlnnzn292UsMaFgPcT2s6b7J0uQzlnC+q4atIJ5vM4H2T/uunu5LQeCSx7F8F7QVX8AgpZWhjFrXQ+6kgr7YlQDV2TYMYdVvYU57UgPH1sflOr5/7xD6FmhO+l1v2UXTpLOEBCOo4x0HxkNt5JeAn9qLe+i9ki1hCXyF+26bS7 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03f5fbdc-4f32-41d4-44d8-08dbf1f5f619 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 22:44:50.3745 (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: yv5tjaCEsfKI1jO+uv6dxGI3/YQP7nOLTC7Fp/E3KW+egOuI8bmO8ohYSMmrR9KA2OLKIr1nHMFjRSc5NochEQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8851 In typical embedded Linux systems, UART consoles require at least two pins, TX and RX. In scenarios where I2C/I3C devices like sensors or PMICs are present, we can save these two pins by using this driver. Pins is crucial resources, especially in small chip packages. This introduces support for using the I3C bus to transfer console tty data, effectively replacing the need for dedicated UART pins. This not only conserves valuable pin resources but also facilitates testing of I3C's advanced features, including early termination, in-band interrupt (IBI) support, and the creation of more complex data patterns. Additionally, it aids in identifying and addressing issues within the I3C controller driver. Signed-off-by: Frank Li --- Notes: Change from v4 to v5 - send in i3c improvememtn patches. Change from v2 to v4 - none Change from v1 to v2 - update commit message. - using goto for err handle - using one working queue for all tty-i3c device - fixed typo found by js - update kconfig help - using kfifo Still below items not be fixed (according to Jiri Slaby's comments) - rxwork thread: need trigger from two position. - common thread queue: need some suggestion Some idea about i3c tty in future 1. early console support - early console is useful to debug boot problem. It requires as simple as possible. i3c SDR mode, 9th bit is parity. I3C target can't block master send out data. so never block kernel boot even without any expected target connected. i3c master may send out a boardcast message as early console to every target devices. Only a "i3c-usb-acm" can show it to host's minicom. And this "i3c-usb-acm" can plug in at any time. Write a boardcast message is quite simple at I3C controller. After kernel system boot to certain phase, switch to this driver. 2. multi port supports. create multi virtual uart ports, so firmware, such as arm trust firmware can dump message to difference virtual ports. 3. compatible with UART network adaptor, which defined at MIPI DEBUG for I3C spec. This driver is just first step. drivers/tty/Kconfig | 13 ++ drivers/tty/Makefile | 1 + drivers/tty/i3c_tty.c | 443 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 457 insertions(+) create mode 100644 drivers/tty/i3c_tty.c diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig index 5646dc6242cd9..b13645f2d72bc 100644 --- a/drivers/tty/Kconfig +++ b/drivers/tty/Kconfig @@ -412,6 +412,19 @@ config RPMSG_TTY To compile this driver as a module, choose M here: the module will be called rpmsg_tty. +config I3C_TTY + tristate "TTY over I3C" + depends on I3C + help + Select this options if you'd like use TTY over I3C master controller + + This makes it possible for user-space programs to send and receive + data as a standard tty protocol. I3C provide relatively higher data + transfer rate and less pin numbers, SDA/SCL are shared with other + devices. + + If unsure, say N + endif # TTY source "drivers/tty/serdev/Kconfig" diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile index 07aca5184a55d..f329f9c7d308a 100644 --- a/drivers/tty/Makefile +++ b/drivers/tty/Makefile @@ -27,5 +27,6 @@ obj-$(CONFIG_GOLDFISH_TTY) += goldfish.o obj-$(CONFIG_MIPS_EJTAG_FDC_TTY) += mips_ejtag_fdc.o obj-$(CONFIG_VCC) += vcc.o obj-$(CONFIG_RPMSG_TTY) += rpmsg_tty.o +obj-$(CONFIG_I3C_TTY) += i3c_tty.o obj-y += ipwireless/ diff --git a/drivers/tty/i3c_tty.c b/drivers/tty/i3c_tty.c new file mode 100644 index 0000000000000..1497759cddb76 --- /dev/null +++ b/drivers/tty/i3c_tty.c @@ -0,0 +1,443 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2023 NXP. + * + * Author: Frank Li + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static DEFINE_IDR(i3c_tty_minors); +static DEFINE_MUTEX(i3c_tty_minors_lock); + +static struct tty_driver *i3c_tty_driver; + +#define I3C_TTY_MINORS 256 +#define I3C_TTY_TRANS_SIZE 16 +#define I3C_TTY_RX_STOP 0 +#define I3C_TTY_RETRY 20 +#define I3C_TTY_YIELD_US 100 + +struct ttyi3c_port { + struct tty_port port; + int minor; + spinlock_t xlock; /* protect xmit */ + char tx_buff[I3C_TTY_TRANS_SIZE]; + char rx_buff[I3C_TTY_TRANS_SIZE]; + struct i3c_device *i3cdev; + struct work_struct txwork; + struct work_struct rxwork; + struct completion txcomplete; + unsigned long status; + int buf_overrun; +}; + +struct workqueue_struct *workqueue; + +static const struct i3c_device_id i3c_ids[] = { + I3C_DEVICE(0x011B, 0x1000, NULL), + { /* sentinel */ }, +}; + +static int i3c_port_activate(struct tty_port *port, struct tty_struct *tty) +{ + struct ttyi3c_port *sport = container_of(port, struct ttyi3c_port, port); + int ret; + + ret = tty_port_alloc_xmit_buf(port); + if (ret < 0) + return ret; + + sport->status = 0; + + ret = i3c_device_enable_ibi(sport->i3cdev); + if (ret) { + tty_port_free_xmit_buf(port); + return ret; + } + + return 0; +} + +static void i3c_port_shutdown(struct tty_port *port) +{ + struct ttyi3c_port *sport = + container_of(port, struct ttyi3c_port, port); + + i3c_device_disable_ibi(sport->i3cdev); + tty_port_free_xmit_buf(port); + kfree(sport->tx_buff); + kfree(sport->rx_buff); +} + +static void i3c_port_destruct(struct tty_port *port) +{ + struct ttyi3c_port *sport = + container_of(port, struct ttyi3c_port, port); + + mutex_lock(&i3c_tty_minors_lock); + idr_remove(&i3c_tty_minors, sport->minor); + mutex_unlock(&i3c_tty_minors_lock); +} + +static const struct tty_port_operations i3c_port_ops = { + .shutdown = i3c_port_shutdown, + .activate = i3c_port_activate, + .destruct = i3c_port_destruct, +}; + +static ssize_t i3c_write(struct tty_struct *tty, const unsigned char *buf, size_t count) +{ + struct ttyi3c_port *sport = tty->driver_data; + unsigned long flags; + bool is_empty; + int ret; + + spin_lock_irqsave(&sport->xlock, flags); + ret = kfifo_in(&sport->port.xmit_fifo, buf, count); + is_empty = kfifo_is_empty(&sport->port.xmit_fifo); + spin_unlock_irqrestore(&sport->xlock, flags); + + if (!is_empty) + queue_work(workqueue, &sport->txwork); + + return ret; +} + +static int i3c_put_char(struct tty_struct *tty, unsigned char ch) +{ + struct ttyi3c_port *sport = tty->driver_data; + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(&sport->xlock, flags); + ret = kfifo_put(&sport->port.xmit_fifo, ch); + spin_unlock_irqrestore(&sport->xlock, flags); + + return ret; +} + +static void i3c_flush_chars(struct tty_struct *tty) +{ + struct ttyi3c_port *sport = tty->driver_data; + + queue_work(workqueue, &sport->txwork); +} + +static unsigned int i3c_write_room(struct tty_struct *tty) +{ + struct ttyi3c_port *sport = tty->driver_data; + + return kfifo_avail(&sport->port.xmit_fifo); +} + +static void i3c_throttle(struct tty_struct *tty) +{ + struct ttyi3c_port *sport = tty->driver_data; + + clear_bit(I3C_TTY_RX_STOP, &sport->status); +} + +static void i3c_unthrottle(struct tty_struct *tty) +{ + struct ttyi3c_port *sport = tty->driver_data; + + set_bit(I3C_TTY_RX_STOP, &sport->status); + + queue_work(workqueue, &sport->rxwork); +} + +static int i3c_open(struct tty_struct *tty, struct file *filp) +{ + struct ttyi3c_port *sport = container_of(tty->port, struct ttyi3c_port, port); + + tty->driver_data = sport; + + return tty_port_open(&sport->port, tty, filp); +} + +static void i3c_close(struct tty_struct *tty, struct file *filp) +{ + tty_port_close(tty->port, tty, filp); +} + +static void i3c_wait_until_sent(struct tty_struct *tty, int timeout) +{ + struct ttyi3c_port *sport = tty->driver_data; + + wait_for_completion_timeout(&sport->txcomplete, timeout); + reinit_completion(&sport->txcomplete); +} + +static const struct tty_operations i3c_tty_ops = { + .open = i3c_open, + .close = i3c_close, + .write = i3c_write, + .put_char = i3c_put_char, + .flush_chars = i3c_flush_chars, + .write_room = i3c_write_room, + .throttle = i3c_throttle, + .unthrottle = i3c_unthrottle, + .wait_until_sent = i3c_wait_until_sent, +}; + +static void i3c_controller_irq_handler(struct i3c_device *dev, + const struct i3c_ibi_payload *payload) +{ + struct ttyi3c_port *sport = dev_get_drvdata(&dev->dev); + + /* i3c_unthrottle also queue the work to fetch pending data in target side */ + queue_work(workqueue, &sport->rxwork); +} + +static void tty_i3c_rxwork(struct work_struct *work) +{ + struct ttyi3c_port *sport = container_of(work, struct ttyi3c_port, rxwork); + struct i3c_priv_xfer xfers; + int retry = I3C_TTY_RETRY; + u16 status = BIT(0); + int ret; + + memset(&xfers, 0, sizeof(xfers)); + xfers.data.in = sport->rx_buff; + xfers.len = I3C_TTY_TRANS_SIZE; + xfers.rnw = 1; + + do { + if (test_bit(I3C_TTY_RX_STOP, &sport->status)) + break; + + i3c_device_do_priv_xfers(sport->i3cdev, &xfers, 1); + + if (xfers.actual_len) { + ret = tty_insert_flip_string(&sport->port, sport->rx_buff, + xfers.actual_len); + if (ret < xfers.actual_len) + sport->buf_overrun++; + + retry = I3C_TTY_RETRY; + continue; + } + + status = BIT(0); + i3c_device_getstatus_format1(sport->i3cdev, &status); + /* + * Target side needs some time to fill data into fifo. Target side may not + * have hardware update status in real time. Software update status always + * needs some delays. + * + * Generally, target side have circular buffer in memory, it will be moved + * into FIFO by CPU or DMA. 'status' just show if circular buffer empty. But + * there are gap, especially CPU have not response irq to fill FIFO in time. + * So xfers.actual will be zero, wait for little time to avoid flood + * transfer in i3c bus. + */ + usleep_range(I3C_TTY_YIELD_US, 10 * I3C_TTY_YIELD_US); + retry--; + + } while (retry && (status & BIT(0))); + + tty_flip_buffer_push(&sport->port); +} + +static void tty_i3c_txwork(struct work_struct *work) +{ + struct ttyi3c_port *sport = container_of(work, struct ttyi3c_port, txwork); + struct i3c_priv_xfer xfers; + int retry = I3C_TTY_RETRY; + unsigned long flags; + int ret; + + xfers.rnw = 0; + xfers.data.out = sport->tx_buff; + + while (!kfifo_is_empty(&sport->port.xmit_fifo) && retry) { + xfers.len = kfifo_len(&sport->port.xmit_fifo); + xfers.len = min_t(u16, I3C_TTY_TRANS_SIZE, xfers.len); + + xfers.len = kfifo_out_peek(&sport->port.xmit_fifo, sport->tx_buff, xfers.len); + + ret = i3c_device_do_priv_xfers(sport->i3cdev, &xfers, 1); + if (ret) { + /* + * Target side may not move data out of FIFO. delay can't resolve problem, + * just reduce some possiblity. Target can't end I3C SDR mode write + * transfer, discard data is reasonable when FIFO overrun. + */ + usleep_range(I3C_TTY_YIELD_US, 10 * I3C_TTY_YIELD_US); + retry--; + } else { + retry = I3C_TTY_RETRY; + ret = kfifo_out(&sport->port.xmit_fifo, sport->tx_buff, xfers.len); + } + } + + spin_lock_irqsave(&sport->xlock, flags); + if (kfifo_is_empty(&sport->port.xmit_fifo)) + complete(&sport->txcomplete); + spin_unlock_irqrestore(&sport->xlock, flags); +} + +static int i3c_probe(struct i3c_device *i3cdev) +{ + struct ttyi3c_port *sport; + struct device *tty_dev; + struct i3c_ibi_setup req; + int minor; + int ret; + + sport = devm_kzalloc(&i3cdev->dev, sizeof(*sport), GFP_KERNEL); + if (!sport) + return -ENOMEM; + + sport->i3cdev = i3cdev; + + dev_set_drvdata(&i3cdev->dev, sport); + + req.max_payload_len = 8; + req.num_slots = 4; + req.handler = &i3c_controller_irq_handler; + + ret = i3c_device_request_ibi(i3cdev, &req); + if (ret) + return -EINVAL; + + mutex_lock(&i3c_tty_minors_lock); + minor = idr_alloc(&i3c_tty_minors, sport, 0, I3C_TTY_MINORS, GFP_KERNEL); + mutex_unlock(&i3c_tty_minors_lock); + + if (minor < 0) { + ret = -EINVAL; + goto err_idr_alloc; + } + + spin_lock_init(&sport->xlock); + INIT_WORK(&sport->txwork, tty_i3c_txwork); + INIT_WORK(&sport->rxwork, tty_i3c_rxwork); + init_completion(&sport->txcomplete); + + tty_port_init(&sport->port); + sport->port.ops = &i3c_port_ops; + + tty_dev = tty_port_register_device(&sport->port, i3c_tty_driver, minor, + &i3cdev->dev); + if (IS_ERR(tty_dev)) { + ret = PTR_ERR(tty_dev); + goto err_tty_port_register; + } + + sport->minor = minor; + + return 0; + +err_tty_port_register: + tty_port_put(&sport->port); + + mutex_lock(&i3c_tty_minors_lock); + idr_remove(&i3c_tty_minors, minor); + mutex_unlock(&i3c_tty_minors_lock); + +err_idr_alloc: + i3c_device_free_ibi(i3cdev); + + return ret; +} + +void i3c_remove(struct i3c_device *dev) +{ + struct ttyi3c_port *sport = dev_get_drvdata(&dev->dev); + + tty_port_unregister_device(&sport->port, i3c_tty_driver, sport->minor); + cancel_work_sync(&sport->txwork); + + tty_port_put(&sport->port); + + mutex_lock(&i3c_tty_minors_lock); + idr_remove(&i3c_tty_minors, sport->minor); + mutex_unlock(&i3c_tty_minors_lock); + + i3c_device_free_ibi(sport->i3cdev); +} + +static struct i3c_driver i3c_driver = { + .driver = { + .name = "ttyi3c", + }, + .probe = i3c_probe, + .remove = i3c_remove, + .id_table = i3c_ids, +}; + +static int __init i3c_tty_init(void) +{ + int ret; + + i3c_tty_driver = tty_alloc_driver(I3C_TTY_MINORS, + TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV); + + if (IS_ERR(i3c_tty_driver)) + return PTR_ERR(i3c_tty_driver); + + i3c_tty_driver->driver_name = "ttyI3C"; + i3c_tty_driver->name = "ttyI3C"; + i3c_tty_driver->minor_start = 0, + i3c_tty_driver->type = TTY_DRIVER_TYPE_SERIAL, + i3c_tty_driver->subtype = SERIAL_TYPE_NORMAL, + i3c_tty_driver->init_termios = tty_std_termios; + i3c_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | + CLOCAL; + i3c_tty_driver->init_termios.c_lflag = 0; + + tty_set_operations(i3c_tty_driver, &i3c_tty_ops); + + ret = tty_register_driver(i3c_tty_driver); + if (ret) + goto err_tty_register_driver; + + ret = i3c_driver_register(&i3c_driver); + if (ret) + goto err_i3c_driver_register; + + workqueue = alloc_workqueue("ttyI3C", 0, 0); + if (!workqueue) { + ret = PTR_ERR(workqueue); + goto err_alloc_workqueue; + } + + return 0; + +err_alloc_workqueue: + i3c_driver_unregister(&i3c_driver); + +err_i3c_driver_register: + tty_unregister_driver(i3c_tty_driver); + +err_tty_register_driver: + tty_driver_kref_put(i3c_tty_driver); + + return ret; +} + +static void __exit i3c_tty_exit(void) +{ + i3c_driver_unregister(&i3c_driver); + tty_unregister_driver(i3c_tty_driver); + tty_driver_kref_put(i3c_tty_driver); + idr_destroy(&i3c_tty_minors); +} + +module_init(i3c_tty_init); +module_exit(i3c_tty_exit); + +MODULE_LICENSE("GPL");