All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yixun Lan" <dlan@kernel.org>
Cc: linux-scsi@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v10 2/2] scsi: ufs: spacemit: k3: Add UFS Host Controller driver
Date: Thu, 03 Dec 2026 12:54:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-247800@kernel.org> (raw)
In-Reply-To: <20261203-08-k3-ufs-support-v10-2-d7120b1be330@kernel.org>

Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [Medium] scsi: ufs: spacemit: missing RESET_CONTROLLER Kconfig
  dependency
- [Medium] scsi: ufs: spacemit: broken ufs_spacemit_pwr_change_notify()
  state handling
- [Medium] scsi: ufs: spacemit: hardcoded 2-lane poll in
  ufs_spacemit_check_hibern8()
- [Medium] scsi: ufs: spacemit: zero clk_gating_wait_us passed to
  fsleep() on UFS 2.x
- [Medium] ufs: spacemit: unratelimited dev_warn() in
  ufs_spacemit_event_notify()
- [Low] scsi: ufs: spacemit: negative err check misses positive UIC DME
  errors
- [Low] scsi: ufs: spacemit: struct ufshcd_dme_attr_val collides with
  ufshcd-dwc.h
- [Low] scsi: ufs: spacemit: unused struct ufs_spacemit_host in
  ufs_spacemit_init()
- [Low] ufs: raw UniPro hex IDs and RX selectors in
  ufs_spacemit_uniprov1p6_init()
--

commit 941ff806ad9ca814afb140eeccebd9435ce81e1c
Author: Yixun Lan <dlan@kernel.org>

scsi: ufs: spacemit: k3: Add UFS Host Controller driver

This commit adds the platform UFS host controller driver for the SpacemiT
K3 SoC, including M-PHY and UniPro initialization, power mode negotiation,
hibern8 handling, and Kconfig/Makefile wiring.

> diff --git a/drivers/ufs/host/Kconfig b/drivers/ufs/host/Kconfig
> index ff170c0b6da0c..6146872fceccb 100644
> --- a/drivers/ufs/host/Kconfig
> +++ b/drivers/ufs/host/Kconfig
> @@ -132,6 +132,18 @@ config SCSI_UFS_VARIABLE_SG_ENTRY_SIZE
>  	bool
>  	default y if SCSI_UFS_EXYNOS && SCSI_UFS_CRYPTO
>  
> +config SCSI_UFS_SPACEMIT
> +	tristate "SpacemiT UFS controller driver"
> +	depends on SCSI_UFSHCD_PLATFORM && (ARCH_SPACEMIT || COMPILE_TEST)

[Severity: Medium]
Should SCSI_UFS_SPACEMIT also depend on RESET_CONTROLLER?

ufs_spacemit_init() requests a non-optional reset control via
devm_reset_control_get_exclusive_deasserted(), which always returns
-ENOTSUPP when CONFIG_RESET_CONTROLLER is disabled.  Neither ARCH_SPACEMIT
nor SCSI_UFSHCD_PLATFORM selects RESET_CONTROLLER, so a SpacemiT-only
config without it compiles cleanly but fails probe on every boot.

> diff --git a/drivers/ufs/host/ufs-spacemit.c b/drivers/ufs/host/ufs-spacemit.c
> new file mode 100644
> index 0000000000000..2d505892de102
> --- /dev/null
> +++ b/drivers/ufs/host/ufs-spacemit.c

[ ... ]

> +static int ufs_spacemit_check_hibern8(struct ufs_hba *hba)
> +{
> +	u32 tx_fsm_val_0 = 0;
> +	u32 tx_fsm_val_1 = 0;
> +	int retries = DIV_ROUND_UP(HBRN8_POLL_TOUT_MS * 1000, 100);
> +	int err = 0;
> +
> +	do {
> +		err = ufshcd_dme_get(hba,
> +				     UIC_ARG_MIB_SEL(MPHY_TX_FSM_STATE,
> +						     UIC_ARG_MPHY_TX_GEN_SEL_INDEX(0)),
> +				     &tx_fsm_val_0);
> +		if (err)
> +			break;
> +
> +		err = ufshcd_dme_get(hba,
> +				     UIC_ARG_MIB_SEL(MPHY_TX_FSM_STATE,
> +						     UIC_ARG_MPHY_TX_GEN_SEL_INDEX(1)),
> +				     &tx_fsm_val_1);
> +		if (err || (tx_fsm_val_0 == TX_FSM_HIBERN8 &&
> +			    tx_fsm_val_1 == TX_FSM_HIBERN8))
> +			break;
> +
> +		usleep_range(100, 200);
> +	} while (--retries > 0);

[Severity: Medium]
Does ufs_spacemit_check_hibern8() time out on every Hibern8 entry for a
1-lane UFS device?

Both the DT binding (via ufs-common.yaml) and ufshcd_negotiate_pwr_params()
allow 1-lane links, where unconnected TX lane 1 stays disabled instead of
entering TX_FSM_HIBERN8.  Because this loop unconditionally requires lane 1
to report TX_FSM_HIBERN8, every runtime autosuspend and system suspend
stalls for the full poll loop and logs -ETIMEDOUT errors.

Separately, counting retries with usleep_range(100, 200) and two
synchronous ufshcd_dme_get() calls per iteration stretches the nominal
100 ms HBRN8_POLL_TOUT_MS bound past 200 ms; polling against a jiffies or
ktime deadline avoids that overshoot.

[ ... ]

> +		{ UIC_ARG_MIB(0x15A8), 0x64 }, /* PA_TACTIVATE */
> +		{ UIC_ARG_MIB(0x1564), 0x64 },	/* PA_TXTRAILINGCLOCKS */
> +		{ UIC_ARG_MIB_SEL(0x008D, 4), 0x0B }, /* RX_LS_PREPARELEN_TIME RX0 */
> +		{ UIC_ARG_MIB_SEL(0x008D, 5), 0x0B }, /* RX_LS_PREPARELEN_TIME RX1 */
> +
> +		/* RX_HIBERNATE_BKEN RX0 */
> +		{ UIC_ARG_MIB_SEL(0x00F4, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(0)), 0x9F },
> +		/* RX_HIBERNATE_BKEN RX1 */
> +		{ UIC_ARG_MIB_SEL(0x00F4, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(1)), 0x9F },
> +		/* PWM_BURST_closure_length */
> +		{ UIC_ARG_MIB_SEL(0x008E, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(0)),   15 },
> +		{ UIC_ARG_MIB_SEL(0x008E, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(1)),   15 },
> +		/* min_stall_not_config_time */
> +		{ UIC_ARG_MIB_SEL(0x0088, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(0)), 0xFF },
> +		{ UIC_ARG_MIB_SEL(0x0088, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(1)), 0xFF },
> +		/* TX HB8_TIME CAP */
> +		{ UIC_ARG_MIB_SEL(0x000F, UIC_ARG_MPHY_TX_GEN_SEL_INDEX(0)), 0x64 },
> +		{ UIC_ARG_MIB_SEL(0x000F, UIC_ARG_MPHY_TX_GEN_SEL_INDEX(1)), 0x64 },
> +		/* RX HB8_TIME CAP */
> +		{ UIC_ARG_MIB_SEL(0x0092, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(0)), 0x64 },
> +		{ UIC_ARG_MIB_SEL(0x0092, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(1)), 0x64 },

[Severity: Low]
Can ufs_spacemit_uniprov1p6_init() use the existing UniPro macros from
include/ufs/unipro.h instead of raw hex literals?  PA_TACTIVATE (0x15A8),
PA_TXTRAILINGCLOCKS (0x1564), TX_HIBERN8TIME_CAPABILITY (0x000F), and
RX_HIBERN8TIME_CAPABILITY (0x0092) are already defined there, and the
hardcoded selectors 4 and 5 on 0x008D can use
UIC_ARG_MPHY_RX_GEN_SEL_INDEX(0) and UIC_ARG_MPHY_RX_GEN_SEL_INDEX(1) like
the entries below them.

[ ... ]

> +static int ufs_spacemit_pwr_change_notify(struct ufs_hba *hba,
> +					  enum ufs_notify_change_status status,
> +					  struct ufs_pa_layer_attr *dev_req_params)
> +{
> +	int ret = 0;
> +
> +	if (!dev_req_params) {
> +		dev_err(hba->dev, "Invalid Parameters\n");
> +		return -EINVAL;
> +	}
> +
> +	switch (status) {
> +	case PRE_CHANGE:
> +		break;
> +	case POST_CHANGE:
> +		ret = ufs_spacemit_wait_mphy_pll_lock(hba);
> +		if (ret < 0)
> +			return ret;
> +
> +		dev_dbg(hba->dev, "M-PHY PLL locked after power mode change\n");
> +		/* Set ANA_HSGEAR_CTRL_ATTR back to default value */
> +		ufshcd_dme_set(hba, UIC_ARG_MIB(ANA_HSGEAR_CTRL_ATTR), 0x00);
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return ret;
> +}

[Severity: Medium]
Can rejecting a NULL dev_req_params here leave ANA_HSGEAR_CTRL_ATTR stuck
at 0x25 when a power mode change fails?

ufshcd_change_power_mode() always invokes POST_CHANGE to pair with
PRE_CHANGE and passes dev_req_params = NULL when
ufshcd_dme_change_power_mode() fails.  Because this callback never uses
dev_req_params, returning -EINVAL on NULL logs a spurious error and skips
resetting ANA_HSGEAR_CTRL_ATTR back to 0x00.

Also, ANA_HSGEAR_CTRL_ATTR is only set to 0x25 in
ufs_spacemit_apply_dev_quirks(), while PRE_CHANGE is a no-op.  When
ufshcd_err_handler() restores HS mode via ufshcd_config_pwr_mode() after a
LINERESET without re-running apply_dev_quirks(), the power mode change runs
with ANA_HSGEAR_CTRL_ATTR still at 0x00.  Programming ANA_HSGEAR_CTRL_ATTR
in PRE_CHANGE would keep both transitions paired.

[ ... ]

> +	if (hba->dev_quirks & UFS_DEVICE_QUIRK_HOST_PA_SAVECONFIGTIME) {
> +		err = ufs_spacemit_quirk_host_pa_saveconfigtime(hba);
> +		if (err < 0)
> +			return err;
> +	}

[Severity: Low]
Does checking err < 0 here miss UniPro DME errors from
ufs_spacemit_quirk_host_pa_saveconfigtime()?

When a DME_GET or DME_SET command fails at the UniPro layer,
ufshcd_wait_for_uic_cmd() returns a positive 8-bit ConfigResultCode
(uic_cmd->argument2 & MASK_UIC_COMMAND_RESULT).  Checking if (err) instead
of if (err < 0) matches the rest of the driver; similarly,
ufs_spacemit_pwr_change_notify() discards the return value of
ufshcd_dme_set() for ANA_HSGEAR_CTRL_ATTR instead of assigning it to ret.

[ ... ]

> +static int ufs_spacemit_init(struct ufs_hba *hba)
> +{
> +	struct device *dev = hba->dev;
> +	struct ufs_spacemit_host *host;
> +	struct reset_control *rst;
> +
> +	host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
> +	if (!host)
> +		return -ENOMEM;
> +
> +	rst = devm_reset_control_get_exclusive_deasserted(dev, NULL);
> +	if (IS_ERR(rst))
> +		return dev_err_probe(dev, PTR_ERR(rst), "Failed to get reset control\n");
> +
> +	host->hba = hba;
> +	ufshcd_set_variant(hba, host);

[Severity: Low]
Is struct ufs_spacemit_host needed yet?  Nothing in this driver or the UFS
core reads hba->priv or calls ufshcd_get_variant(), so the struct
definition and devm_kzalloc() allocation in ufs_spacemit_init() are dead
code until a feature actually requires per-instance private state.

[ ... ]

> +static void ufs_spacemit_event_notify(struct ufs_hba *hba, enum ufs_event_type evt, void *data)
> +{
> +	switch (evt) {
> +	case UFS_EVT_PA_ERR:
> +		if (data)
> +			dev_warn(hba->dev, "PA error event, INT errors:0x%x, PA_ERR_CODE:0x%x\n",
> +				 hba->errors, *(u32 *)data);
> +
> +		break;
> +	case UFS_EVT_DL_ERR:
> +		if (data)
> +			dev_warn(hba->dev, "DL error event, INT errors:0x%x, DL_ERR:0x%x\n",
> +				 hba->errors, *(u32 *)data);
> +
> +		break;

[Severity: Medium]
Can these unratelimited dev_warn() calls cause printk storms and host_lock
stalls on a noisy link?

ufshcd_intr() -> ufshcd_check_errors() -> ufshcd_update_uic_error() ->
ufshcd_update_evt_hist() invokes event_notify synchronously in hardirq
context while holding hba->host->host_lock with local IRQs disabled.  For
non-fatal PA or DL errors, the core does not mask UIC_ERROR or schedule
error recovery, so repeated link errors can flood serial consoles, stall
SCSI command handling, and risk soft lockups.  Switching to
dev_warn_ratelimited() or dev_dbg() avoids this.

[ ... ]

> +		/* Power down M-PHY */
> +		ufshcd_writel(hba, 0x0, UFS_PHY_MNG_BASE + UFS_MPHY_PU_CTRL);
> +
> +		fsleep(hba->dev_info.clk_gating_wait_us);
> +
> +		/* Disable reference clock, keep device reset deasserted */
> +		ufshcd_writel(hba, MPHY_DEVICE_HW_RESET,
> +			      UFS_PHY_MNG_BASE + UFS_DEVICE_IO_CTRL);

[Severity: Medium]
Does fsleep(hba->dev_info.clk_gating_wait_us) turn into a zero-delay no-op
on UFS 2.x devices?

ufshcd_get_ref_clk_gating_wait() only populates clk_gating_wait_us when
wspecversion >= 0x300, leaving it at 0 for all UFS 2.0/2.1/2.2 devices.
On devices that require 30-100 us of REF_CLK hold time after Hibern8 entry
(or when an early UIC error skips the preceding DME commands), clearing
MPHY_DEVICE_REFCLK_OE without a non-zero fallback delay can cause Hibern8
exit failures or link errors during runtime autosuspend.  Other host
drivers such as ufs-qcom and ufs-mediatek guard against a zero value with
an explicit fallback delay.

> diff --git a/drivers/ufs/host/ufs-spacemit.h b/drivers/ufs/host/ufs-spacemit.h
> new file mode 100644
> index 0000000000000..f9b7b8a93752e
> --- /dev/null
> +++ b/drivers/ufs/host/ufs-spacemit.h

[ ... ]

> +struct ufshcd_dme_attr_val {
> +	u32 attr_sel;
> +	u32 mib_val;
> +};

[Severity: Low]
Does struct ufshcd_dme_attr_val collide with the existing three-field
struct ufshcd_dme_attr_val in drivers/ufs/host/ufshcd-dwc.h?  Renaming this
to a driver-private tag such as struct ufs_spacemit_dme_attr_val avoids
type-identity confusion in BTF/DWARF tooling and potential header inclusion
conflicts.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-08-k3-ufs-support-v10-0-d7120b1be330@kernel.org?part=2

      reply	other threads:[~2026-12-03 12:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 12:23 [PATCH v10 0/2] Add UFS Host driver support for SpacemiT K3 SoC Yixun Lan
2026-12-03 12:23 ` Yixun Lan
2026-12-03 12:23 ` [PATCH v10 1/2] scsi: ufs: spacemit: dt-bindings: Add UFS controller for " Yixun Lan
2026-12-03 12:23   ` Yixun Lan
2026-12-03 12:23 ` [PATCH v10 2/2] scsi: ufs: spacemit: k3: Add UFS Host Controller driver Yixun Lan
2026-12-03 12:23   ` Yixun Lan
2026-12-03 12:54   ` sashiko-bot [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=sashiko-outbox-247800@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlan@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.