From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796302449; b=DdXimOYXYoyGq9bxt2JrFwEqr05azEOJw1rjmr6uJ0WZDKA77u4pANsydo88wi8LIGtH ynV70ynMavlTdn1+m9rMT0q8Ahe5bOLegC8xTpB+ldODAp6/ZUe5bBwzIHifgahxgCRkY apV1L/piE/A9EwXYq3lEvWqdEiIKeRQ3xeG2zSEHqa2IgYH/5DNpWsA+RCNe3UL/ufcfS oAikIyT9R9SCOxblHUpF+FwulM0zLBEhw4EnjKI+W3wCjuaWWBzTBf7i+NYwGm4+FN9fF M/IacyhB3Pg73xcMj3AFxMFQreEOC4CGgyklKKVUL7DkaDM7090OOjo6m0eSKhUQwvw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796302449; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=p9t9Wj5/S9X/q0KLdS1djRp0xlSDi3KZcfdLd4WM0EY=; b=KBlHK/LzOGAcDKVu1y8YvTCN5HBq7tBsgSmjNUTadGXW7PeMigWjTxoNIES3eFUFglYw VYWGZ9ioXg65fyqKddr/Sbj7Qx7ZWiApCPpEunsfFzDadYQFglVj2NzYVptXvmdVVrOuF Fz+WhA+wMxudpMIOTuy+DTah6h7yjUcbDKRQep+1/vRoY7LzjOx1frO64bP/YHSKB0pWt WrHSyPr/mhszjaaxWfOQeit16Hyj+Z7EKXhpdYvqIy1QS2UpvorZEQtwNO6bhUt/z/EYS zYs4xv4Q8XOYnzXBVi9IP+6NvEKsBFAvFXC8RwVDwm4+RH2jJ+CwAAS7S2ywfPTNrzA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=X0UBbNou; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60284606A322; Thu, 3 Dec 2026 12:54:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=X0UBbNou Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D4701F000C1; Thu, 3 Dec 2026 12:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796302449; bh=p9t9Wj5/S9X/q0KLdS1djRp0xlSDi3KZcfdLd4WM0EY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=X0UBbNouDKQf6y2Mah9FKxwIy3MzCH5PQCQqr65xPp4aZYXZx/na3uBUsvZsy/zHH ktjP3FL133j5PgYHXgulLQPh7zecwXEPbltETbYNzQofNcMTELnjVjUsxnT214DpLB +xuo+gD+zmbJ54IFqZeXf+/Qd1hC3qVfaYcvxIf19zT+NsCu6ci+oGbcTlYTT0E+0S vtpMu57QyNXP/NwWGhcCggg6SclEJ6t4VTa/cfAxTo+da+Of4OPsuYD5rvuxiLmkYN gPAGvFMF29LsnnSIs8lT41xlPALk4aY+OrKgMsTPn5puurQWizAIXt359uAX1K2T1U BMJWk8q73lCgQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v10 2/2] scsi: ufs: spacemit: k3: Add UFS Host Controller driver Reply-To: sashiko-reviews@lists.linux.dev To: "Yixun Lan" Cc: linux-scsi@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261203-08-k3-ufs-support-v10-2-d7120b1be330@kernel.org> References: <20261203-08-k3-ufs-support-v10-0-d7120b1be330@kernel.org> <20261203-08-k3-ufs-support-v10-2-d7120b1be330@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 12:54:08 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 > =20 > +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-space= mit.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 =3D 0; > + u32 tx_fsm_val_1 =3D 0; > + int retries =3D DIV_ROUND_UP(HBRN8_POLL_TOUT_MS * 1000, 100); > + int err =3D 0; > + > + do { > + err =3D 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 =3D 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 =3D=3D TX_FSM_HIBERN8 && > + tx_fsm_val_1 =3D=3D 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 =3D 0; > + > + if (!dev_req_params) { > + dev_err(hba->dev, "Invalid Parameters\n"); > + return -EINVAL; > + } > + > + switch (status) { > + case PRE_CHANGE: > + break; > + case POST_CHANGE: > + ret =3D 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 =3D 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 =3D 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 =3D hba->dev; > + struct ufs_spacemit_host *host; > + struct reset_control *rst; > + > + host =3D devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); > + if (!host) > + return -ENOMEM; > + > + rst =3D 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 =3D 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_even= t_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 >=3D 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-space= mit.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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-08-k3-ufs-= support-v10-0-d7120b1be330@kernel.org?part=3D2