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 v8 2/2] scsi: ufs: spacemit: k3: Add UFS Host Controller driver
Date: Mon, 16 Nov 2026 04:16:38 +0000	[thread overview]
Message-ID: <sashiko-outbox-216168@kernel.org> (raw)
In-Reply-To: <20261116-08-k3-ufs-support-v8-2-e3b256972dd4@kernel.org>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] scsi: ufs: spacemit: clocks not enabled and sys1clk rate always
  0 without OPP/freq-table
- [Medium] scsi: ufs: spacemit: zero ref_clk gating delay in
  ufs_spacemit_post_hibern8() on UFS 2.x
- [Low] scsi: ufs: spacemit: ufs_spacemit_event_notify() logs cleared
  hba->errors on UFS_EVT_ABORT
- [Low] scsi: ufs: spacemit: duplicated ufshcd_init_host_params() and
  unused definitions
- [Low] scsi: ufs: spacemit: positive UIC error codes ignored in DME
  error checks
--

commit 893661ab0d45a5f00a091213a0890aea0386b457
Author: Yixun Lan <dlan@kernel.org>

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

This commit adds a UFS host controller platform driver for the SpacemiT K3
SoC, supporting JEDEC UFS 2.2, MIPI UniPro v1.61, and M-PHY v3.0.

> diff --git a/drivers/ufs/host/ufs-spacemit.c b/drivers/ufs/host/ufs-spacemit.c
> new file mode 100644
> index 0000000000000..eb2ad50826997
> --- /dev/null
> +++ b/drivers/ufs/host/ufs-spacemit.c
[ ... ]
> +static u32 ufs_spacemit_get_sys1clk_1us(struct ufs_hba *hba)
> +{
> +	struct ufs_clk_info *clki, *clka = NULL;
> +	struct list_head *head = &hba->clk_list_head;
> +	unsigned long rate_hz = 0;
> +
> +	if (!list_empty(head)) {
> +		list_for_each_entry(clki, head, list) {
> +			if (clki->name && !strcmp(clki->name, "axi") && clki->clk) {
> +				clka = clki;
> +				break;
> +			}
> +		}
> +	}
> +
> +	if (clka && clka->clk)
> +		rate_hz = clk_get_rate(clka->clk);
> +
> +	if (!rate_hz)
> +		return 0;
> +
> +	return DIV_ROUND_CLOSEST(rate_hz, 1000000);
> +}

[Severity: High]
Does hba->clk_list_head remain empty when the Device Tree node has neither
freq-table-hz nor operating-points-v2?

ufshcd_parse_clock_info() returns early without parsing clock-names when
freq-table-hz is absent, and ufshcd_parse_operating_points() does the same
when operating-points-v2 is absent:

drivers/ufs/host/ufshcd-pltfrm.c:ufshcd_parse_clock_info() {
    ...
	sz = of_property_count_u32_elems(np, "freq-table-hz");
	if (sz <= 0) {
		dev_info(dev, "freq-table-hz property not specified\n");
		goto out;
	}
    ...
}

Since the spacemit,k3-ufshc binding omits both properties and
ufs_spacemit_init() does not populate hba->clk_list_head or acquire the
clocks itself, ufshcd_init_clocks() and ufshcd_setup_clocks() never enable
the axi or ref_clk clocks (leaving them subject to clk_disable_unused or
unclocked MMIO access if not enabled by firmware), hba->dev_ref_clk_freq is
never parsed from ref_clk, and ufs_spacemit_get_sys1clk_1us() always returns
0 so ufs_spacemit_link_startup_pre_change() always falls back to
UFS_AXI_CLK_LOW_FREQ_HZ (409.6 MHz).

[ ... ]

> +static void ufs_spacemit_set_dev_cap(struct ufs_host_params *host_params, u32 pwr_hs)
> +{
> +	if (!host_params)
> +		return;
> +
> +	memset(host_params, 0, sizeof(struct ufs_host_params));
> +	host_params->tx_lanes = UFS_SPACEMIT_K3_LIMIT_NUM_LANES_TX;
> +	host_params->rx_lanes = UFS_SPACEMIT_K3_LIMIT_NUM_LANES_RX;
> +	host_params->hs_rx_gear = UFS_SPACEMIT_K3_LIMIT_HSGEAR_RX;
> +	host_params->hs_tx_gear = UFS_SPACEMIT_K3_LIMIT_HSGEAR_TX;
> +	host_params->pwm_rx_gear = UFS_SPACEMIT_K3_LIMIT_PWMGEAR_RX;
> +	host_params->pwm_tx_gear = UFS_SPACEMIT_K3_LIMIT_PWMGEAR_TX;
> +	host_params->rx_pwr_pwm = UFS_SPACEMIT_K3_LIMIT_RX_PWR_PWM;
> +	host_params->tx_pwr_pwm = UFS_SPACEMIT_K3_LIMIT_TX_PWR_PWM;
> +	host_params->rx_pwr_hs = pwr_hs;
> +	host_params->tx_pwr_hs = pwr_hs;
> +	host_params->hs_rate = UFS_SPACEMIT_K3_LIMIT_HS_RATE;
> +	host_params->desired_working_mode = UFS_HS_MODE;
> +}

[Severity: Low]
This isn't a bug, but ufs_spacemit_set_dev_cap() and the
UFS_SPACEMIT_K3_LIMIT_* macros set the exact same defaults as the exported
ufshcd_init_host_params() helper in drivers/ufs/host/ufshcd-pltfrm.c.

In addition, ufs_spacemit_init() allocates struct ufs_spacemit_host and
stores it with ufshcd_set_variant(), but the variant pointer is never
retrieved anywhere in the driver.  MPHY_TX_FSM_STATE is also defined in both
ufs-spacemit.h and ufs-spacemit.c, ANA_EQ_CTRL_REG_ATTR and
MPHY_PU_WITH_HB8_RESET are defined in ufs-spacemit.c while raw literals
0x00CD and 0xb7f are still used in ufs_spacemit_uniprov1p6_init() and
ufs_spacemit_mphy_init(), and MPHY_RX_FSM_STATE along with several headers
and macros in ufs-spacemit.h are unused.

> +
> +static int ufs_spacemit_link_startup_pre_change(struct ufs_hba *hba)
> +{
> +	u32 value, sys1clk_1us;
> +	int err;
> +
> +	err = ufs_spacemit_mphy_init(hba);
> +	if (err < 0)
> +		return err;
> +
> +	err = ufs_spacemit_uniprov1p6_init(hba);
> +	if (err < 0)
> +		return err;
[ ... ]
> +static int ufs_spacemit_apply_dev_quirks(struct ufs_hba *hba)
> +{
> +	static const struct ufshcd_dme_attr_val setup_attrs[] = {
> +		/* LCC_DISABLE */
> +		{ UIC_ARG_MIB_SEL(TX_LCC_ENABLE, UIC_ARG_MPHY_TX_GEN_SEL_INDEX(0)), 0 },
> +		{ UIC_ARG_MIB_SEL(TX_LCC_ENABLE, UIC_ARG_MPHY_TX_GEN_SEL_INDEX(1)), 0 },
> +		/* TX_Min_ActivateTime */
> +		{ UIC_ARG_MIB_SEL(TX_MIN_ACTIVATETIME, UIC_ARG_MPHY_TX_GEN_SEL_INDEX(0)), 0x0 },
> +		{ UIC_ARG_MIB_SEL(TX_MIN_ACTIVATETIME, UIC_ARG_MPHY_TX_GEN_SEL_INDEX(1)), 0x0 },
> +		{ UIC_ARG_MIB(ANA_HSGEAR_CTRL_ATTR), 0x25 },
> +	};
> +	int err;
> +
> +	if (hba->dev_quirks & UFS_DEVICE_QUIRK_HOST_PA_SAVECONFIGTIME) {
> +		err = ufs_spacemit_quirk_host_pa_saveconfigtime(hba);
> +		if (err < 0)
> +			return err;
> +	}
> +
> +	if (hba->dev_info.wmanufacturerid == UFS_VENDOR_WDC)
> +		hba->dev_quirks |= UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE;
> +
> +	err = ufs_spacemit_dme_set(hba, setup_attrs, ARRAY_SIZE(setup_attrs));
> +	if (err < 0)
> +		return err;
> +
> +	return ufs_spacemit_wait_mphy_pll_lock(hba);
> +}

[Severity: Low]
As reported by Troy Mitchell on v6 [1], can positive UIC error codes bypass
the "if (err < 0)" checks in ufs_spacemit_link_startup_pre_change() and
ufs_spacemit_apply_dev_quirks()?

ufshcd_dme_get() and ufshcd_dme_set() return positive 8-bit UIC command
result codes (0x01..0xFF) when a DME command fails at the UniPro layer.
Checking "if (err < 0)" misses those positive error codes and allows both
functions to continue past failed DME operations instead of aborting early.

[ ... ]

> +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;
> +	case UFS_EVT_ABORT:
> +		dev_warn(hba->dev, "Abort event, INT errors:0x%x\n", hba->errors);
> +		break;
> +	default:
> +		break;
> +	}
> +}

[Severity: Low]
Does the UFS_EVT_ABORT case in ufs_spacemit_event_notify() always log
hba->errors as 0x0?

ufshcd_check_errors() clears hba->errors back to 0 before the interrupt
handler returns (saving sticky bits in hba->saved_err), while UFS_EVT_ABORT
is only emitted later from ufshcd_abort() in SCSI error-handler context with
the aborted tag or LUN passed via data.

[ ... ]

> +static void ufs_spacemit_post_hibern8(struct ufs_hba *hba, enum uic_cmd_dme cmd)
> +{
> +	static const struct ufshcd_dme_attr_val setup_attrs[] = {
> +		{ UIC_ARG_MIB_SEL(0xf1, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(0)), 0x84 },
> +		{ UIC_ARG_MIB_SEL(0xf1, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(1)), 0x84 },
> +		{ UIC_ARG_MIB_SEL(0xf1, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(0)), 0x80 },
> +		{ UIC_ARG_MIB_SEL(0xf1, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(1)), 0x80 },
> +		{ UIC_ARG_MIB(0xdd), 0x57 },
> +		{ UIC_ARG_MIB(0xdd), 0xd7 },
> +		{ UIC_ARG_MIB(0xe8), 0x57 },
> +		{ UIC_ARG_MIB(0xe8), 0xd7 },
> +	};
> +	int err;
> +
> +	if (cmd == UIC_CMD_DME_HIBER_ENTER) {
> +		err = ufs_spacemit_check_hibern8(hba);
> +		if (err)
> +			dev_err(hba->dev, "ufs_spacemit_check_hibern8 error\n");
> +
> +		ufs_spacemit_dme_set(hba, setup_attrs, ARRAY_SIZE(setup_attrs));
> +
> +		/* 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) gate the device reference
clock with zero delay on UFS 2.x devices?

ufshcd_get_ref_clk_gating_wait() only reads bRefClkGatingWaitTime and sets
hba->dev_info.clk_gating_wait_us when hba->dev_info.wspecversion >= 0x300.
On UFS 2.x devices (or if Hibern8 is entered before
ufshcd_device_params_init() runs), clk_gating_wait_us remains 0, so
ufs_spacemit_post_hibern8() calls fsleep(0) and disables
MPHY_DEVICE_REFCLK_OE immediately after powering down the M-PHY without
satisfying the reference clock hold time.

[1] https://lore.kernel.org/r/DLLQJDEA91FU.18Q1TSX09AUR3@linux.spacemit.com

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

  reply	other threads:[~2026-11-16  4:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  3:46 [PATCH v8 0/2] Add UFS Host driver support for SpacemiT K3 SoC Yixun Lan
2026-11-16  3:46 ` Yixun Lan
2026-11-16  3:46 ` [PATCH v8 1/2] scsi: ufs: spacemit: dt-bindings: Add UFS controller for " Yixun Lan
2026-11-16  3:46   ` Yixun Lan
2026-11-16  3:46 ` [PATCH v8 2/2] scsi: ufs: spacemit: k3: Add UFS Host Controller driver Yixun Lan
2026-11-16  3:46   ` Yixun Lan
2026-11-16  4:16   ` sashiko-bot [this message]
2026-11-17 19:44   ` Aurelien Jarno
2026-11-17 19:44     ` Aurelien Jarno
2026-11-17  1:15 ` [PATCH v8 0/2] Add UFS Host driver support for SpacemiT K3 SoC E Shattow
2026-11-17  1:15   ` E Shattow
2026-11-17  3:17   ` Yixun Lan
2026-11-17  3:17     ` Yixun Lan
2026-11-17 19:44   ` Aurelien Jarno
2026-11-17 19:44     ` Aurelien Jarno

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-216168@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.