From mboxrd@z Thu Jan 1 00:00:00 1970 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 7BAA7CD13D2 for ; Thu, 30 Apr 2026 11:08:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=njPr2CelAVpsPef3LdMKU8MVjh31mvKYj6jz6cuixK4=; b=qUMenGoITGuIEGcMCCnCRNIBgj +no+IDyp3Xht+BTT17tpOLEKHL1bvuv4a4ygPm6ljUPeUFhy3VKWaqYawvqwsbQ9jcV8LRqu/5NXz TTLcKMGJFwM5gZjCzgsDlivjHtTxlrnjnURKtGwMdoQ/jRDR3z58/QFbw6DNC++7WZbDj1tFlyUc+ 7YLR6GfTfonYuuN5NzLfppZt/Mk6AaZiTA1Vo4ogs5Y94c4v2glyf7W5X0U8ltzhHF9qceYs9Zgdg RSGfl74RxlgObXc+xSnIlMHHY9agpEj/4PezU2/BVx0VpvjaxGqFs4Mi/C5ME/6q7YBtL5Q0UkdD8 792YOoiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wIPFc-00000005GwC-3jFS; Thu, 30 Apr 2026 11:08:12 +0000 Received: from mail-swedencentralazon11013007.outbound.protection.outlook.com ([52.101.83.7] helo=GVXPR05CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wIPEs-00000005Fjo-1wQS; Thu, 30 Apr 2026 11:07:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZQN4d5/t+0dnO/HV8mziqA+SJhNAnze8L8jXXSG8gqCEniMQnyClurH0Em4icf0k38OARw8QyflJHqFAnM5+TZJLRz9HJrEh4VNFq4JWxuvR/IWvPiQ1ISJb/BxXfHugtLBu5g651T5bDGSEVtT8g/2G39gQTTiX4cJ8yHnueVYrDyLNKnQ44oOYL86WrX5sE17+5hv36Zri4KiPfbpBEruxvADxSQ+loEp14i1pxHwazlNrnS6Mxn6aCqtJ+ksc/wxskP29JCxt8dFSOjsZoJg7HbSsBezfD3L7uh+wsXhQPIeIz4P6/M3i85fcbucWXTJLJ6KFq5bxYG4fWmt4VQ== 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=njPr2CelAVpsPef3LdMKU8MVjh31mvKYj6jz6cuixK4=; b=gtQuQGmuMiMdrqKGFIgoQdpM0+imaulFoXqSJlZKbmPFnySjNGrZBqa518PbM27WelJjhHzLX/42InHrGnb8mma+aL+esXzNVFrrCgb3K67DQNNvvGom20vBbn1xiGQRFtAQ+q0Av4pf/H7anNNTdPEvaPWswogM7qvJJAjcUCLPTO7sS71rCqb0jdXrteOFSQPoCb1TSw4Z1wtFWdF7/N9shgjV+LDSUoae/vUY7xt9v/ZkTJaRFA+W8MiwcVIoQLFlvzNJyVZlkMqMbnZcFsk9qMy4/67VZKfNsYszo42/4LdGtDBadobZlRIkWDXpo5FQ7eLzLMbw7IPMBBQs1A== 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=njPr2CelAVpsPef3LdMKU8MVjh31mvKYj6jz6cuixK4=; b=luEFMh08qEVKqbQ67QdPVv49PEP5On8OZm3NZyYGW78SfUjyEqLXaCNnKGW9a5HXHVIIdlscew+XrBErvzpIAtQkpfj+c1/GgKKIUdj7f4wRjx/G7HPqZLwE9BJOgAaS+dQCik31zSCJVoS5U+zxX7W9cbCgSery6hWm9S2+JklS3C6d17KFqdJaN5bBLYxcV+RnbIyShionJWzeh6vbeL8YP49DzDP2zvr9+fr1FiNkpoXni1rmKrWijU+zs1aA+j9i2L1RYsE9qcAO3vYoNbTZstxdslLm0qkfmzDp/IHSDtkBSSUnxKH+RfNKH8vyZoNb0hFrBt2QgdL9F/Xn8A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8585.eurprd04.prod.outlook.com (2603:10a6:20b:438::13) by VI1PR04MB7182.eurprd04.prod.outlook.com (2603:10a6:800:121::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.20; Thu, 30 Apr 2026 11:07:13 +0000 Received: from AM9PR04MB8585.eurprd04.prod.outlook.com ([fe80::f010:fca8:7ef:62f4]) by AM9PR04MB8585.eurprd04.prod.outlook.com ([fe80::f010:fca8:7ef:62f4%4]) with mapi id 15.20.9846.025; Thu, 30 Apr 2026 11:07:13 +0000 From: Vladimir Oltean To: linux-phy@lists.infradead.org Cc: Vinod Koul , Neil Armstrong , dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-can@vger.kernel.org, linux-gpio@vger.kernel.org, linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-scsi@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-usb@vger.kernel.org, netdev@vger.kernel.org, spacemit@lists.linux.dev, UNGLinuxDriver@microchip.com, "James E.J. Bottomley" , Manivannan Sadhasivam , "Martin K. Petersen" , Nitin Rawat Subject: [PATCH v7 phy-next 10/27] scsi: ufs: qcom: keep parallel track of PHY power state Date: Thu, 30 Apr 2026 14:06:35 +0300 Message-Id: <20260430110652.558622-11-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260430110652.558622-1-vladimir.oltean@nxp.com> References: <20260430110652.558622-1-vladimir.oltean@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: AM0PR10CA0024.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:17c::34) To AM9PR04MB8585.eurprd04.prod.outlook.com (2603:10a6:20b:438::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8585:EE_|VI1PR04MB7182:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d4d7bf2-9684-4269-c833-08dea6a8a213 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|7416014|376014|366016|19092799006|1800799024|18002099003|56012099003|22082099003; X-Microsoft-Antispam-Message-Info: QFBNNDxNL2i4/11noJFadnrY7LsLwyMzBqgXzJ9Eq6lnZ0zEbUXVLOc5Vm15Vb6wNUIWLG0VJ5cx935VaV/zf9QVP2RRgPCMj26IyDnNibejbEKlnnva0j7II5AcYyzer2QircnNs7QMNQw2oJM6yKFbFaQbZJHjdblgeA7tSJZlcPz6x4SRfzdDXAPzl5C622iVIbyg6rrv675+LYm7jkazioMBQNCuwEXHoRjGWNnBORNp0Ww0swcooyLD/3GLNO++lgMwSDlmotoKJlIS7/NdS0s/SWbf5u/OfMsuJcNVntvKG9PqCJo+qklQbhHDH3Eiuj4aDmhZCtAmHqPX2XZqczWTxpov9kDKKB6AbTvnupzSdxj8EXjKNYwzSKRIuTLiEDCrAWltZdNHjs7EXEN1nScFpKUjWEAVRNKLf8dzKkbCkdlo1NzTplJMqkSA2jajlJexrwvyuO2jmzCe4Ghqk/OQVZcoaQG272w344KX1qXg/LUV65FV2qejgYg5mx/mmuzQAib7Ltdg6Ek5w0KpXz0Ip0IQiv9R+j6sl9/GjJ+Vp7Vx923YcVWdXuhI2AEg2qUmnjlCTNkzbXAJEKJIqhkxNjwLuuG0tExy3qARQrLgFumb8fHxexNPQP1i0mI2hw1Qv6UiDtYUTKWbET355L8tH7TMr8JsNCCBQ+2xEd2bawHrHaJgjkmgELF1+WqqBoDLYWPwkOEGs6giLVlphaE4VJXFojPjj6ZYPL8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8585.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(7416014)(376014)(366016)(19092799006)(1800799024)(18002099003)(56012099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?mYFzcQ8xMdG4vKppMvv2VosvUysNjrf4g7gkSn06wDGkUOI/Cbb4pC8mstEs?= =?us-ascii?Q?6JDV5MezmBai1MCy4o2Ojve1OIoVcYbWH+QkldiOAfDzQSFib6G0A1q+DIhu?= =?us-ascii?Q?HJo1usBl1uyY1cvkVftuZU6RWZcbQLRqF5T2A3qIXzzXQJz0tWumxiW7d2nS?= =?us-ascii?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TX9l5PcmSI1lTHCZVpIuXA?= =?us-ascii?Q?gVEFnrjLygdt2KTw//NXmUPkzkKQFEupHxqSZTQDKT3gtGQT0qJy2ZCusOYa?= =?us-ascii?Q?4DFcpJJLiWrsFP84xWIxz4RgB26Xqu18gHuXwRIBPh4LoPv7hKKqYwXaS1Fd?= =?us-ascii?Q?s6jxBRXlARDztg7TKl1MmkTeEfh/qmOeoQJzInsdjf+v/Sn4JIQd1QP68TcY?= =?us-ascii?Q?+0doC2b0GHaGFloK/7vSF9yO+6tUuGzJ+iYcMJ5ulxZgHkG9X4OvKb3yM0wy?= =?us-ascii?Q?edX+n+6na75y7Gku2mpll822U9ZJ5yYU5EENZ6CTaOEDd8r0zg0EK4j5aYHQ?= =?us-ascii?Q?BNE5ggHa90ug7Ti1luFMzjh7ozIegUey6E/iD5moI7QJNcJIJ7Dqf+v9gQQg?= =?us-ascii?Q?UA33Miyu1GGc0TyiE83Bx0yc5xcoAVDG6Q8uZ7rr9U4PtModGERUXVAPKfc7?= =?us-ascii?Q?d2MnqqrCJlmtNSWiAaWQGrUxw/Fop/VHT0nF13cFoB6ROqKYggc8iGA6zDps?= =?us-ascii?Q?onTfOmBfsu/SHhYQbTjSINQhRoZMrZry0uPX+nBc7bvXePkjXBxmeMeRD/Zm?= =?us-ascii?Q?DML24+xCzmw5XaQ7WppEfJs5A+TZWrcoUZG3jCnOvhajw4roDkKfIIrJQKXS?= =?us-ascii?Q?K1AegjGOAtZMpzXqOexdgzb4vHhPjWrjXWcQ+h+1JngRSJXGkHZZqiM9rCh9?= =?us-ascii?Q?D5kLcC0g4dtxzfuQaOsEOxWfOb60IlRE0ZdTOIj3mDHMKktatTf+?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d4d7bf2-9684-4269-c833-08dea6a8a213 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8585.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 11:07:13.8663 (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: LOQ0KlGMKhNmbUVKF72A0MPaHLcgZxpJLmelzY8C+vvVypPeI0Bz1/N2wIsOZjF+cOC9GFNDglzlAMukR1xfcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7182 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260430_040727_986170_46322037 X-CRM114-Status: GOOD ( 18.87 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org PHY consumer drivers should not look at the phy->power_count (a PHY internal field), because in the general case there might also be other consumers who have called phy_power_on() too, so the fact that the power_count is non-zero does not mean that we did. Moreover, struct phy will become opaque soon, so the qcom UFS driver will not be able to apply this pattern anymore. By all accounts, the need for ufs_qcom_power_up_sequence() to call phy_power_off() prior to phy_init() denotes a skewed state of affairs. (1) The Generic PHY API warns if phy_power_on() is called prior to phy_init() - which ufs-qcom.c does, from ufs_qcom_setup_clocks(). The UFS controller driver hides its tracks by dropping the power count prior to phy_init(), and that API violation goes undetected. (2) phy_calibrate(), as implemented by the phy-qcom-qmp-ufs.c provider, only works once after power on. Next time it will time out. And since ufs_qcom_hce_enable_notify() -> ufs_qcom_power_up_sequence() is called in a retry loop by the UFS core, the PHY power would normally be on, hence the phy_power_off() call to ensure the consistent state during phy_calibrate(). The above constitute improper Generic PHY API use, *but* fixing that requires delicate surgery and I'm only here to stop this PHY consumer from using fields it's not supposed to. Once this discussion is settled, I will also address the above issues as follow-ups: https://lore.kernel.org/linux-phy/20260327112858.r5lpqygtvsane2vf@skbuf/ Until then, we can reimplement the logic in this driver in a bug-compatible way, by keeping parallel track of just the UFS controller's calls to phy_power_on() and phy_power_off(). Note that phy_power_off() shouldn't return an error in general and doesn't return an error in the particular case of the phy-qcom-qmp-ufs.c provider. So I've removed the one handling of phy_power_off() errors from ufs_qcom_setup_clocks(). Signed-off-by: Vladimir Oltean --- Cc: "James E.J. Bottomley" Cc: Manivannan Sadhasivam Cc: "Martin K. Petersen" Cc: Nitin Rawat v6->v7: none v5->v6: - rewrite commit message - drop phy_power_off() error handling from ufs_qcom_setup_clocks() v4->v5: patch is new --- drivers/ufs/host/ufs-qcom.c | 15 ++++++++------- drivers/ufs/host/ufs-qcom.h | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index bc037db46624..872e4effa60f 100644 --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -508,9 +508,10 @@ static int ufs_qcom_power_up_sequence(struct ufs_hba *hba) if (ret) return ret; - if (phy->power_count) + if (host->phy_powered_on) { phy_power_off(phy); - + host->phy_powered_on = false; + } /* phy initialization - calibrate the phy */ ret = phy_init(phy); @@ -531,6 +532,7 @@ static int ufs_qcom_power_up_sequence(struct ufs_hba *hba) __func__, ret); goto out_disable_phy; } + host->phy_powered_on = true; ret = phy_calibrate(phy); if (ret) { @@ -1447,11 +1449,8 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, ufs_qcom_dev_ref_clk_ctrl(host, false); } - err = phy_power_off(phy); - if (err) { - dev_err(hba->dev, "phy power off failed, ret=%d\n", err); - return err; - } + phy_power_off(phy); + host->phy_powered_on = false; } break; case POST_CHANGE: @@ -1461,6 +1460,7 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, dev_err(hba->dev, "phy power on failed, ret = %d\n", err); return err; } + host->phy_powered_on = true; /* enable the device ref clock for HS mode*/ if (ufshcd_is_hs_mode(&hba->pwr_info)) @@ -1651,6 +1651,7 @@ static void ufs_qcom_exit(struct ufs_hba *hba) ufs_qcom_disable_lane_clks(host); phy_power_off(host->generic_phy); + host->phy_powered_on = false; phy_exit(host->generic_phy); } diff --git a/drivers/ufs/host/ufs-qcom.h b/drivers/ufs/host/ufs-qcom.h index 5d083331a7f4..6eafba3c203b 100644 --- a/drivers/ufs/host/ufs-qcom.h +++ b/drivers/ufs/host/ufs-qcom.h @@ -322,6 +322,7 @@ struct ufs_qcom_host { struct clk_bulk_data *clks; u32 num_clks; bool is_lane_clks_enabled; + bool phy_powered_on; struct icc_path *icc_ddr; struct icc_path *icc_cpu; -- 2.34.1