From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A6AD606A31A for ; Wed, 2 Dec 2026 17:25:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xYo4e-0008Gj-Bg; Wed, 02 Dec 2026 12:24:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xYo4c-0008GI-Li; Wed, 02 Dec 2026 12:24:54 -0500 Received: from 93-87-244-166.static.isp.telekom.rs ([93.87.244.166] helo=fx.arvanta.net) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xYo4a-0005gK-F0; Wed, 02 Dec 2026 12:24:54 -0500 Received: from air (m1pro.arvanta.net [10.5.1.11]) by fx.arvanta.net (Postfix) with ESMTP id 9B10C421; Wed, 02 Dec 2026 18:24:48 +0100 (CET) Date: Wed, 2 Dec 2026 18:24:48 +0100 From: Milan =?utf-8?Q?P=2E_Stani=C4=87?= To: Anirudh Srinivasan Cc: qemu-devel@nongnu.org, Jeuk Kim , Pierrick Bouvier , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, tgamblin@baylibre.com Subject: Re: [PATCH 2/2] hw/ufs: Add minimal model for M-PHY TX/RX FSM states Message-ID: <20261202172448.GA15691@air> References: <20261129-ufs_fixes-v1-0-cd67a74b1ae3@oss.tenstorrent.com> <20261129-ufs_fixes-v1-2-cd67a74b1ae3@oss.tenstorrent.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261129-ufs_fixes-v1-2-cd67a74b1ae3@oss.tenstorrent.com> Received-SPF: pass client-ip=93.87.244.166; envelope-from=mps@arvanta.net; helo=fx.arvanta.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TVD_RCVD_IP=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Sun, 2026-11-29 at 21:00, Anirudh Srinivasan wrote: > Add a minimal model to track the M-PHY TX/RX_FSM_State so DME reads of > it return a value other than 0 (DISABLED). The following 3 states (along > with transitions between then) are modelled: DISABLED, HIBERN8 and SLEEP. > > Some Linux drivers poll TX_FSM_STATE regularly (before/after > hibernation) and expect to see something other than DISABLED. This > spams the dmesg logs with prints like this. This patch gets rid of these > prints. > Applied patches on top of qemu 11.2.0 rc2 and previously applied '[PATCH v2 0/9] Add Spacemit K3 Machine' series, and build vendor opensbi-spacemit-k3-1.0.10 and u-boot-spacemit-k3-1.0.10 (patched to have extlinux.conf). Build riscv64 UFS image (with script) and tested on Alpine Linux aarch64 edge (development branch) host. Boots fine to the shell and can run all commands fine. These two kernel message below doesn't appears with this series. ufshcd-spacemit c0e00000.ufshc: ufs_spacemit_check_hibern8: invalid TX_FSM_STATE, lane0 = 0, lane1 = 0 ufshcd-spacemit c0e00000.ufshc: ufs_spacemit_check_hibern8 error Tested-by: Milan P. Stanić > [ 25.827278] ufshcd-spacemit c0e00000.ufshc: ufs_spacemit_check_hibern8: invalid TX_FSM_STATE, lane0 = 0, lane1 = 0 > [ 25.827327] ufshcd-spacemit c0e00000.ufshc: ufs_spacemit_check_hibern8 error > > Signed-off-by: Anirudh Srinivasan > --- > docs/system/devices/ufs.rst | 8 +++++--- > hw/ufs/ufs.c | 14 ++++++++++++-- > hw/ufs/ufs.h | 1 + > include/block/ufs.h | 10 ++++++++++ > 4 files changed, 28 insertions(+), 5 deletions(-) > > diff --git a/docs/system/devices/ufs.rst b/docs/system/devices/ufs.rst > index c493806d53..7f3dc0e5ff 100644 > --- a/docs/system/devices/ufs.rst > +++ b/docs/system/devices/ufs.rst > @@ -80,9 +80,11 @@ Limitations > =========== > > * UniPro and M-PHY are not modelled. Only the UIC commands needed for > - link startup, DME attribute access and hibernation are handled; DME > - reads return fixed values, and DME writes, power mode changes and > - hibernation do not change any link state. > + link startup, DME attribute access and hibernation are handled. Most > + DME reads return fixed values; and DME writes, power mode changes do > + not change any link state. M-PHY FSM state is modelled with 3 simple > + states (DISABLED, HIBERN8 or SLEEP) and DME reads for this return > + the current state. > * Only the ``QUERY TASK`` and ``ABORT TASK`` UTP task management > requests are supported; other task management functions such as > ``LOGICAL UNIT RESET`` return ``TASK MANAGEMENT FUNCTION NOT > diff --git a/hw/ufs/ufs.c b/hw/ufs/ufs.c > index 4a5b07b102..cfb449cf7a 100644 > --- a/hw/ufs/ufs.c > +++ b/hw/ufs/ufs.c > @@ -394,12 +394,16 @@ static void ufs_process_db(UfsHc *u, uint32_t val) > } > > /* > - * Return canned PA layer attribute values. The emulated link has no PHY, so > - * these are purely declarative: u->params.num_lanes in HS-Gear 4, FAST_MODE. > + * Return canned PA layer attribute values, except for M-PHY FSM state > + * which is tracked by u->mphy_fsm_state. The emulated link has no PHY, > + * so these are purely declarative: u->params.num_lanes in HS-Gear 4, FAST_MODE. > */ > static uint32_t ufs_uic_dme_get_value(UfsHc *u, uint16_t attr_id) > { > switch (attr_id) { > + case UFS_ATTR_MPHY_TX_FSM_STATE: > + case UFS_ATTR_MPHY_RX_FSM_STATE: > + return u->mphy_fsm_state; > case UFS_ATTR_PA_AVAILTXDATALANES: > case UFS_ATTR_PA_AVAILRXDATALANES: > case UFS_ATTR_PA_CONNECTEDTXDATALANES: > @@ -430,6 +434,7 @@ static void ufs_process_uiccmd(UfsHc *u, uint32_t val) > u->reg.hcs = FIELD_DP32(u->reg.hcs, HCS, DP, 1); > u->reg.hcs = FIELD_DP32(u->reg.hcs, HCS, UTRLRDY, 1); > u->reg.hcs = FIELD_DP32(u->reg.hcs, HCS, UTMRLRDY, 1); > + u->mphy_fsm_state = UFS_MPHY_FSM_SLEEP; > u->reg.ucmdarg2 = UFS_UIC_CMD_RESULT_SUCCESS; > break; > case UFS_UIC_CMD_DME_GET: > @@ -457,11 +462,13 @@ static void ufs_process_uiccmd(UfsHc *u, uint32_t val) > case UFS_UIC_CMD_DME_HIBER_ENTER: > u->reg.is = FIELD_DP32(u->reg.is, IS, UHES, 1); > u->reg.hcs = FIELD_DP32(u->reg.hcs, HCS, UPMCRS, UFS_PWR_LOCAL); > + u->mphy_fsm_state = UFS_MPHY_FSM_HIBERN8; > u->reg.ucmdarg2 = UFS_UIC_CMD_RESULT_SUCCESS; > break; > case UFS_UIC_CMD_DME_HIBER_EXIT: > u->reg.is = FIELD_DP32(u->reg.is, IS, UHXS, 1); > u->reg.hcs = FIELD_DP32(u->reg.hcs, HCS, UPMCRS, UFS_PWR_LOCAL); > + u->mphy_fsm_state = UFS_MPHY_FSM_SLEEP; > u->reg.ucmdarg2 = UFS_UIC_CMD_RESULT_SUCCESS; > break; > default: > @@ -1154,11 +1161,13 @@ static void ufs_write_reg(UfsHc *u, hwaddr offset, uint32_t data, unsigned size) > if (!FIELD_EX32(u->reg.hce, HCE, HCE) && FIELD_EX32(data, HCE, HCE)) { > u->reg.hcs = FIELD_DP32(u->reg.hcs, HCS, UCRDY, 1); > u->reg.hce = FIELD_DP32(u->reg.hce, HCE, HCE, 1); > + u->mphy_fsm_state = UFS_MPHY_FSM_HIBERN8; > } else if (FIELD_EX32(u->reg.hce, HCE, HCE) && > !FIELD_EX32(data, HCE, HCE)) { > ufs_hce_reset(u); > u->reg.hcs = 0; > u->reg.hce = FIELD_DP32(u->reg.hce, HCE, HCE, 0); > + u->mphy_fsm_state = UFS_MPHY_FSM_DISABLED; > } > break; > case A_UTRLBA: > @@ -3128,6 +3137,7 @@ static void ufs_init_hc(UfsHc *u) > memset(&u->reg, 0, sizeof(u->reg)); > memset(&u->mcq_reg, 0, sizeof(u->mcq_reg)); > memset(&u->mcq_op_reg, 0, sizeof(u->mcq_op_reg)); > + u->mphy_fsm_state = UFS_MPHY_FSM_DISABLED; > cap = FIELD_DP32(cap, CAP, NUTRS, (u->params.nutrs - 1)); > cap = FIELD_DP32(cap, CAP, RTT, 2); > cap = FIELD_DP32(cap, CAP, NUTMRS, (u->params.nutmrs - 1)); > diff --git a/hw/ufs/ufs.h b/hw/ufs/ufs.h > index 592a428d7f..0dcd9b00f0 100644 > --- a/hw/ufs/ufs.h > +++ b/hw/ufs/ufs.h > @@ -181,6 +181,7 @@ typedef struct UfsHc { > UfsParams params; > uint32_t reg_size; > UfsRequest *req_list; > + uint8_t mphy_fsm_state; /* Tracks M-PHY FSM State */ > > UfsLu *lus[UFS_MAX_LUS]; > UfsLu report_wlu; > diff --git a/include/block/ufs.h b/include/block/ufs.h > index f4a3371bce..bf20898a17 100644 > --- a/include/block/ufs.h > +++ b/include/block/ufs.h > @@ -656,6 +656,16 @@ enum { > #define UFS_ATTR_PA_MAXRXPWMGEAR 0x1586 > #define UFS_ATTR_PA_MAXRXHSGEAR 0x1587 > > +/* > + * MIPI M-PHY status attribute IDs accessed via DME_GET > + */ > +#define UFS_ATTR_MPHY_TX_FSM_STATE 0x41 > +#define UFS_ATTR_MPHY_RX_FSM_STATE 0xC1 > + > +#define UFS_MPHY_FSM_DISABLED 0 > +#define UFS_MPHY_FSM_HIBERN8 1 > +#define UFS_MPHY_FSM_SLEEP 2 > + > /* > * Request Descriptor Definitions > */ > > -- > 2.43.0 >