* [PATCH 0/2] Implement some missing UFS Functionality
@ 2026-11-30 3:00 Anirudh Srinivasan
2026-11-30 3:00 ` [PATCH 1/2] hw/ufs: Make num rx/tx lanes reported to the guest configurable Anirudh Srinivasan
2026-11-30 3:00 ` [PATCH 2/2] hw/ufs: Add minimal model for M-PHY TX/RX FSM states Anirudh Srinivasan
0 siblings, 2 replies; 4+ messages in thread
From: Anirudh Srinivasan @ 2026-11-30 3:00 UTC (permalink / raw)
To: qemu-devel
Cc: Jeuk Kim, Pierrick Bouvier, Kevin Wolf, Hanna Reitz, qemu-block,
mps, tgamblin, Anirudh Srinivasan
This series contains 2 patches to implement missing functionality in the
UFS implementation.
Patch 1 adds a qdev property to allow configuring num_lanes reported to
the guest. Linux fails to probe the UFS controller if this value doesn't
match a corresponding value in the DT. Patch 2 adds a minimal
implementation of M-PHY FSM states that are to do with entering
hibernation. This is needed to surpress repeated error prints in Linux
while the device is in use.
Both these patches are needed to get UFS working in Linux on the
spacemit-k3 QEMU machine, which is under review [1]. UFS works in linux
on this machine after adding the 2 patches in this series, plus this
small fix to the machine to set num-lanes for the UFS controller to the
correct alue.
diff --git a/hw/ufs/spacemit_k3_ufs.c b/hw/ufs/spacemit_k3_ufs.c
index 03a631e45f..addca022bb 100644
--- a/hw/ufs/spacemit_k3_ufs.c
+++ b/hw/ufs/spacemit_k3_ufs.c
@@ -64,6 +64,7 @@ static void spacemit_k3_ufs_realize(DeviceState *dev, Error **errp)
K3_UFS_VENDOR_BASE + K3_UFS_VENDOR_SIZE);
sysbus_init_mmio(sbd, &s->container);
+ qdev_prop_set_uint8(DEVICE(&s->ufs), "num-lanes", 2);
sysbus_realize(ufs_sbd, errp);
memory_region_add_subregion(&s->container, 0,
sysbus_mmio_get_region(ufs_sbd, 0));
[1] https://lore.kernel.org/qemu-riscv/20261129-spacemit_k3-v2-0-462c078463e9@oss.tenstorrent.com/
Signed-off-by: Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
---
Anirudh Srinivasan (2):
hw/ufs: Make num rx/tx lanes reported to the guest configurable
hw/ufs: Add minimal model for M-PHY TX/RX FSM states
docs/system/devices/ufs.rst | 11 ++++++++---
hw/ufs/ufs-pci.c | 1 +
hw/ufs/ufs-sysbus.c | 1 +
hw/ufs/ufs.c | 27 ++++++++++++++++++++++-----
hw/ufs/ufs.h | 2 ++
include/block/ufs.h | 10 ++++++++++
6 files changed, 44 insertions(+), 8 deletions(-)
---
base-commit: 9cda597a1a3903d090e8e55e23f5b8a859da88ab
change-id: 20261129-ufs_fixes-da2a51db8b93
Best regards,
--
Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 1/2] hw/ufs: Make num rx/tx lanes reported to the guest configurable
2026-11-30 3:00 [PATCH 0/2] Implement some missing UFS Functionality Anirudh Srinivasan
@ 2026-11-30 3:00 ` Anirudh Srinivasan
2026-11-30 3:00 ` [PATCH 2/2] hw/ufs: Add minimal model for M-PHY TX/RX FSM states Anirudh Srinivasan
1 sibling, 0 replies; 4+ messages in thread
From: Anirudh Srinivasan @ 2026-11-30 3:00 UTC (permalink / raw)
To: qemu-devel
Cc: Jeuk Kim, Pierrick Bouvier, Kevin Wolf, Hanna Reitz, qemu-block,
mps, tgamblin, Anirudh Srinivasan
Some SoCs have UFS controllers that support more than 1 Tx/Rx
lane. A property in the DT node for the UFS controller
"lanes-per-direction" specifies the value, and Linux checks value
against what the controller returns. This check errors out in QEMU
because the UFS implementation always returns 1.
[ 1.644609] scsi host0: ufshcd
[ 1.656590] ufshcd-spacemit c0e00000.ufshc: Tx lane mismatch [config,reported] [2,1]
[ 1.657073] ufshcd-spacemit c0e00000.ufshc: link startup failed -67
[ 1.660505] ufshcd-spacemit c0e00000.ufshc: error -ENOLINK: Initialization failed with error -67
[ 1.661176] ufshcd-spacemit c0e00000.ufshc: probe with driver ufshcd-spacemit failed with error -67
Add a "num-lanes" qdev property to the ufs controller to make this value
configurable.
Signed-off-by: Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
---
docs/system/devices/ufs.rst | 3 +++
hw/ufs/ufs-pci.c | 1 +
hw/ufs/ufs-sysbus.c | 1 +
hw/ufs/ufs.c | 17 ++++++++++++-----
hw/ufs/ufs.h | 1 +
5 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/docs/system/devices/ufs.rst b/docs/system/devices/ufs.rst
index 7e1fa671ab..c493806d53 100644
--- a/docs/system/devices/ufs.rst
+++ b/docs/system/devices/ufs.rst
@@ -63,6 +63,9 @@ Host Controller Properties
Maximum and minimum WriteBooster buffer size, in allocation units.
``wb-min-size`` must not exceed ``wb-max-size``.
+``num-lanes`` (default 1, maximum 2)
+ Number of Rx/Tx lanes supported by the controller advertised to the guest.
+
Logical Unit Properties
=======================
diff --git a/hw/ufs/ufs-pci.c b/hw/ufs/ufs-pci.c
index 8a2268f11f..f582b9baf4 100644
--- a/hw/ufs/ufs-pci.c
+++ b/hw/ufs/ufs-pci.c
@@ -79,6 +79,7 @@ static const Property ufs_pci_props[] = {
ufs.params.fault_inject_mode,
UFS_FAULT_INJECT_ABORT_SUCCESS,
ufs_prop_fault_inject_mode, UfsFaultInjectMode),
+ DEFINE_PROP_UINT8("num-lanes", UfsPciState, ufs.params.num_lanes, 1),
};
static const VMStateDescription ufs_pci_vmstate = {
diff --git a/hw/ufs/ufs-sysbus.c b/hw/ufs/ufs-sysbus.c
index 7e85d8fc4c..1554cf1cc6 100644
--- a/hw/ufs/ufs-sysbus.c
+++ b/hw/ufs/ufs-sysbus.c
@@ -52,6 +52,7 @@ static const Property ufs_sysbus_props[] = {
ufs.params.fault_inject_mode,
UFS_FAULT_INJECT_ABORT_SUCCESS,
ufs_prop_fault_inject_mode, UfsFaultInjectMode),
+ DEFINE_PROP_UINT8("num-lanes", SysbusUfsState, ufs.params.num_lanes, 1),
};
static const VMStateDescription ufs_sysbus_vmstate = {
diff --git a/hw/ufs/ufs.c b/hw/ufs/ufs.c
index 3de67831ea..4a5b07b102 100644
--- a/hw/ufs/ufs.c
+++ b/hw/ufs/ufs.c
@@ -28,6 +28,7 @@
#define UFS_MAX_NUTRS 32
#define UFS_MAX_NUTMRS 8
#define UFS_MCQ_QCFGPTR 2
+#define UFS_MAX_NUM_LANES 2
/* Each value represents the temperature in celsius as (value - 80) */
#define UFS_TEMPERATURE 120
@@ -393,17 +394,17 @@ 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: a single lane in HS-Gear 4, FAST_MODE.
+ * 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.
*/
-static uint32_t ufs_uic_dme_get_value(uint16_t attr_id)
+static uint32_t ufs_uic_dme_get_value(UfsHc *u, uint16_t attr_id)
{
switch (attr_id) {
case UFS_ATTR_PA_AVAILTXDATALANES:
case UFS_ATTR_PA_AVAILRXDATALANES:
case UFS_ATTR_PA_CONNECTEDTXDATALANES:
case UFS_ATTR_PA_CONNECTEDRXDATALANES:
- return 1;
+ return u->params.num_lanes;
case UFS_ATTR_PA_MAXRXHSGEAR:
case UFS_ATTR_PA_MAXRXPWMGEAR:
return 4;
@@ -434,7 +435,7 @@ static void ufs_process_uiccmd(UfsHc *u, uint32_t val)
case UFS_UIC_CMD_DME_GET:
case UFS_UIC_CMD_DME_PEER_GET:
attr_id = (u->reg.ucmdarg1 >> 16) & 0xFFFF;
- u->reg.ucmdarg3 = ufs_uic_dme_get_value(attr_id);
+ u->reg.ucmdarg3 = ufs_uic_dme_get_value(u, attr_id);
u->reg.ucmdarg2 = UFS_UIC_CMD_RESULT_SUCCESS;
break;
case UFS_UIC_CMD_DME_SET:
@@ -3042,6 +3043,12 @@ static bool ufs_check_constraints(UfsHc *u, Error **errp)
return false;
}
+ if (u->params.num_lanes > UFS_MAX_NUM_LANES) {
+ error_setg(errp, "num-lanes must be less than or equal to %d",
+ UFS_MAX_NUM_LANES);
+ return false;
+ }
+
return true;
}
diff --git a/hw/ufs/ufs.h b/hw/ufs/ufs.h
index 0014978322..592a428d7f 100644
--- a/hw/ufs/ufs.h
+++ b/hw/ufs/ufs.h
@@ -122,6 +122,7 @@ typedef struct UfsParams {
uint32_t wb_min_size; /* WB Minimum allocation units */
uint32_t fault_inject_tag;
UfsFaultInjectMode fault_inject_mode;
+ uint8_t num_lanes; /* Num Tx/Rx lanes reported to the host */
} UfsParams;
/*
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] hw/ufs: Add minimal model for M-PHY TX/RX FSM states
2026-11-30 3:00 [PATCH 0/2] Implement some missing UFS Functionality Anirudh Srinivasan
2026-11-30 3:00 ` [PATCH 1/2] hw/ufs: Make num rx/tx lanes reported to the guest configurable Anirudh Srinivasan
@ 2026-11-30 3:00 ` Anirudh Srinivasan
2026-12-02 17:24 ` Milan P. Stanić
1 sibling, 1 reply; 4+ messages in thread
From: Anirudh Srinivasan @ 2026-11-30 3:00 UTC (permalink / raw)
To: qemu-devel
Cc: Jeuk Kim, Pierrick Bouvier, Kevin Wolf, Hanna Reitz, qemu-block,
mps, tgamblin, Anirudh Srinivasan
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.
[ 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 <asrinivasan@oss.tenstorrent.com>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] hw/ufs: Add minimal model for M-PHY TX/RX FSM states
2026-11-30 3:00 ` [PATCH 2/2] hw/ufs: Add minimal model for M-PHY TX/RX FSM states Anirudh Srinivasan
@ 2026-12-02 17:24 ` Milan P. Stanić
0 siblings, 0 replies; 4+ messages in thread
From: Milan P. Stanić @ 2026-12-02 17:24 UTC (permalink / raw)
To: Anirudh Srinivasan
Cc: qemu-devel, Jeuk Kim, Pierrick Bouvier, Kevin Wolf, Hanna Reitz,
qemu-block, tgamblin
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ć <mps@arvanta.net>
> [ 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 <asrinivasan@oss.tenstorrent.com>
> ---
> 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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-02 17:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 3:00 [PATCH 0/2] Implement some missing UFS Functionality Anirudh Srinivasan
2026-11-30 3:00 ` [PATCH 1/2] hw/ufs: Make num rx/tx lanes reported to the guest configurable Anirudh Srinivasan
2026-11-30 3:00 ` [PATCH 2/2] hw/ufs: Add minimal model for M-PHY TX/RX FSM states Anirudh Srinivasan
2026-12-02 17:24 ` Milan P. Stanić
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.