All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Milan P. Stanić" <mps@arvanta.net>
To: Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
Cc: qemu-devel@nongnu.org, Jeuk Kim <jeuk20.kim@samsung.com>,
	Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>,
	Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
	qemu-block@nongnu.org, tgamblin@baylibre.com
Subject: Re: [PATCH 2/2] hw/ufs: Add minimal model for M-PHY TX/RX FSM states
Date: Wed, 2 Dec 2026 18:24:48 +0100	[thread overview]
Message-ID: <20261202172448.GA15691@air> (raw)
In-Reply-To: <20261129-ufs_fixes-v1-2-cd67a74b1ae3@oss.tenstorrent.com>

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
> 


      reply	other threads:[~2026-12-02 17:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202172448.GA15691@air \
    --to=mps@arvanta.net \
    --cc=asrinivasan@oss.tenstorrent.com \
    --cc=hreitz@redhat.com \
    --cc=jeuk20.kim@samsung.com \
    --cc=kwolf@redhat.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=tgamblin@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.