ufs-exynos stability fixes for gs101
Subsystems (4)
Peter Griffin
maintainerv2 cover ufs-exynos stability fixes for gs101
Hi folks,
This series fixes several stability issues with the upstream ufs-exynos driver, specifically for the gs101 SoC found in Pixel 6.
The main fix is regarding the IO cache coherency setting and ensuring that it is correctly applied depending on if the dma-coherent property is specified in device tree. This fixes the UFS stability issues on gs101 and I would imagine will also fix issues on exynosauto platform that seems to have similar iocc shareability bits.
Additionally the phy reference counting is fixed which allows module load/unload to work reliably and keeps the phy state machine in sync with the controller glue driver.
regards,
Peter
Changes since v1:
* Added patch for correct handling of iocc depedent on dma-coherent property
* Rebased onto next-20250319
* Add a gs101 specific suspend hook (Bart)
* Drop asserting GPIO_OUT in .exit() (Peter)
* Remove superfluous blank line (Bart)
* Update PRDT_PREFECT_EN to PRDT_PREFETCH_EN (Bart)
* Update commit description for desctype type 3 (Eric)
* https://lore.kernel.org/lkml/[email protected]/
---
Peter Griffin (7):
scsi: ufs: exynos: ensure pre_link() executes before exynos_ufs_phy_init()
scsi: ufs: exynos: move ufs shareability value to drvdata
scsi: ufs: exynos: disable iocc if dma-coherent property isn't set
scsi: ufs: exynos: ensure consistent phy reference counts
scsi: ufs: exynos: Enable PRDT pre-fetching with UFSHCD_CAP_CRYPTO
scsi: ufs: exynos: Move phy calls to .exit() callback
scsi: ufs: exynos: gs101: put ufs device in reset on .suspend()
drivers/ufs/host/ufs-exynos.c | 85 ++++++++++++++++++++++++++++++++----------- drivers/ufs/host/ufs-exynos.h | 6 ++- 2 files changed, 68 insertions(+), 23 deletions(-)
---
base-commit: 433ccb6f2e879866b8601fcb1de14e316cdb0d39
change-id: 20250319-exynos-ufs-stability-fixes-e8da9862e3dc
Best regards,
Signature · 1 line
Peter Griffin <[email protected]>
Peter Griffin
maintainerPATCH v2 1/7 scsi: ufs: exynos: ensure pre_link() executes before exynos_ufs_phy_init()
Ensure clocks are enabled before configuring unipro. Additionally move the pre_link() hook before the exynos_ufs_phy_init() calls. This means the register write sequence more closely resembles the ordering of the downstream driver.
--- drivers/ufs/host/ufs-exynos.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/ufs/host/ufs-exynos.c +5 -5
@@ -1049,9 +1049,14 @@ static int exynos_ufs_pre_link(struct ufs_hba *hba)exynos_ufs_config_intr (ufs,DFES_DEF_L4_ERRS ,UNIPRO_L4 );exynos_ufs_set_unipro_pclk_div (ufs); +exynos_ufs_setup_clocks (hba, true,PRE_CHANGE ); +/* unipro */ exynos_ufs_config_unipro (ufs); +if (ufs->drv_data->pre_link) + ufs->drv_data->pre_link (ufs); +/* m-phy */ exynos_ufs_phy_init (ufs);if (!(ufs->opts &EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR )) {
@@ -1059,11 +1064,6 @@ static int exynos_ufs_pre_link(struct ufs_hba *hba)exynos_ufs_config_phy_cap_attr (ufs); } -exynos_ufs_setup_clocks (hba, true,PRE_CHANGE ); - -if (ufs->drv_data->pre_link) - ufs->drv_data->pre_link (ufs); -return 0 ; }
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
Peter Griffin
maintainerPATCH v2 2/7 scsi: ufs: exynos: move ufs shareability value to drvdata
In reply to Peter Griffings101 IO coherency shareability bits differ from exynosauto SoC. To support both SoCs move this info the SoC drvdata.
Currently both the value and mask are the same for both gs101 and exynosauto, thus we use the same value.
--- drivers/ufs/host/ufs-exynos.c | 20 ++++++++++++++------ drivers/ufs/host/ufs-exynos.h | 2 ++ 2 files changed, 16 insertions(+), 6 deletions(-)
drivers/ufs/host/ufs-exynos.c +14 -6
@@ -92,11 +92,16 @@ UIC_TRANSPORT_NO_CONNECTION_RX |\ UIC_TRANSPORT_BAD_TC) -/* FSYS UFS Shareability */ -#define UFS_WR_SHARABLE BIT(2) -#define UFS_RD_SHARABLE BIT(1) -#define UFS_SHARABLE (UFS_WR_SHARABLE | UFS_RD_SHARABLE) -#define UFS_SHAREABILITY_OFFSET 0x710 +/* UFS Shareability */ +#define UFS_EXYNOSAUTO_WR_SHARABLE BIT(2) +#define UFS_EXYNOSAUTO_RD_SHARABLE BIT(1) +#define UFS_EXYNOSAUTO_SHARABLE (UFS_EXYNOSAUTO_WR_SHARABLE | \ + UFS_EXYNOSAUTO_RD_SHARABLE) +#define UFS_GS101_WR_SHARABLE BIT(1) +#define UFS_GS101_RD_SHARABLE BIT(0) +#define UFS_GS101_SHARABLE (UFS_GS101_WR_SHARABLE | \ + UFS_GS101_RD_SHARABLE) +#define UFS_SHAREABILITY_OFFSET 0x710/* Multi-host registers */ #define MHCTRL 0xC4
@@ -210,7 +215,7 @@ static int exynos_ufs_shareability(struct exynos_ufs *ufs)if (ufs->sysreg) {return regmap_update_bits (ufs->sysreg, ufs->shareability_reg_offset, -UFS_SHARABLE ,UFS_SHARABLE ); + ufs->iocc_mask, ufs->iocc_mask); }return 0 ;
@@ -1174,6 +1179,7 @@ static int exynos_ufs_parse_dt(struct device *dev, struct exynos_ufs *ufs) } } + ufs->iocc_mask = ufs->drv_data->iocc_mask; ufs->pclk_avail_min =PCLK_AVAIL_MIN ; ufs->pclk_avail_max =PCLK_AVAIL_MAX ;
@@ -2035,6 +2041,7 @@ static const struct exynos_ufs_drv_data exynosauto_ufs_drvs = { .opts = EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL |EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR | EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX, + .iocc_mask = UFS_EXYNOSAUTO_SHARABLE, .drv_init = exynosauto_ufs_drv_init, .post_hce_enable = exynosauto_ufs_post_hce_enable, .pre_link = exynosauto_ufs_pre_link,
@@ -2136,6 +2143,7 @@ static const struct exynos_ufs_drv_data gs101_ufs_drvs = { .opts = EXYNOS_UFS_OPT_SKIP_CONFIG_PHY_ATTR |EXYNOS_UFS_OPT_UFSPR_SECURE | EXYNOS_UFS_OPT_TIMER_TICK_SELECT, + .iocc_mask = UFS_GS101_SHARABLE, .drv_init = gs101_ufs_drv_init, .pre_link = gs101_ufs_pre_link, .post_link = gs101_ufs_post_link,
drivers/ufs/host/ufs-exynos.h +2 -0
@@ -181,6 +181,7 @@ struct exynos_ufs_drv_data {struct exynos_ufs_uic_attr *uic_attr;unsigned int quirks;unsigned int opts; +u32 iocc_mask;/* SoC's specific operations */ int (*drv_init)(struct exynos_ufs *ufs);int (*pre_link)(struct exynos_ufs *ufs);
@@ -231,6 +232,7 @@ struct exynos_ufs {const struct exynos_ufs_drv_data *drv_data;struct regmap *sysreg;u32 shareability_reg_offset; +u32 iocc_mask;u32 opts;#define EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL BIT(0)
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
Peter Griffin
maintainerPATCH v2 3/7 scsi: ufs: exynos: disable iocc if dma-coherent property isn't set
In reply to Peter GriffinIf dma-coherent property isn't set then descriptors are non-cacheable and the iocc shareability bits should be disabled. Without this UFS can end up in an incompatible configuration and suffer from random cache related stability issues.
--- drivers/ufs/host/ufs-exynos.c | 17 +++++++++++++---- drivers/ufs/host/ufs-exynos.h | 3 ++- 2 files changed, 15 insertions(+), 5 deletions(-)
drivers/ufs/host/ufs-exynos.c +13 -4
@@ -214,8 +214,8 @@ static int exynos_ufs_shareability(struct exynos_ufs *ufs)/* IO Coherency setting */ if (ufs->sysreg) {return regmap_update_bits (ufs->sysreg, - ufs->shareability_reg_offset, - ufs->iocc_mask, ufs->iocc_mask); + ufs->iocc_offset, + ufs->iocc_mask, ufs->iocc_val); }return 0 ;
@@ -1173,13 +1173,22 @@ static int exynos_ufs_parse_dt(struct device *dev, struct exynos_ufs *ufs) ufs->sysreg =NULL ; else {if (of_property_read_u32_index (np,"samsung,sysreg" ,1 , - &ufs->shareability_reg_offset)) { + &ufs->iocc_offset)) {dev_warn (dev,"can't get an offset from sysreg. Set to default value\n" ); - ufs->shareability_reg_offset =UFS_SHAREABILITY_OFFSET ; + ufs->iocc_offset =UFS_SHAREABILITY_OFFSET ; } } ufs->iocc_mask = ufs->drv_data->iocc_mask; +/* +* no 'dma-coherent' property means the descriptors are +* non-cacheable so iocc shareability should be disabled. +*/ +if (of_dma_is_coherent (dev->of_node)) + ufs->iocc_val = ufs->iocc_mask; +else + ufs->iocc_val =0 ; + ufs->pclk_avail_min =PCLK_AVAIL_MIN ; ufs->pclk_avail_max =PCLK_AVAIL_MAX ;
drivers/ufs/host/ufs-exynos.h +2 -1
@@ -231,8 +231,9 @@ struct exynos_ufs {ktime_t entry_hibern8_t;const struct exynos_ufs_drv_data *drv_data;struct regmap *sysreg; -u32 shareability_reg_offset; +u32 iocc_offset;u32 iocc_mask; +u32 iocc_val;u32 opts;#define EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL BIT(0)
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
Peter Griffin
maintainerPATCH v2 4/7 scsi: ufs: exynos: ensure consistent phy reference counts
In reply to Peter Griffinufshcd_link_startup() can call ufshcd_vops_link_startup_notify() multiple times when retrying. This causes the phy reference count to keep increasing and the phy to not properly re-initialize.
If the phy has already been previously powered on, first issue a phy_power_off() and phy_exit(), before re-initializing and powering on again.
--- drivers/ufs/host/ufs-exynos.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/ufs/host/ufs-exynos.c +6 -0
@@ -962,6 +962,12 @@ static int exynos_ufs_phy_init(struct exynos_ufs *ufs) }phy_set_bus_width (generic_phy, ufs->avail_ln_rx); + +if (generic_phy->power_count) { +phy_power_off (generic_phy); +phy_exit (generic_phy); + } + ret =phy_init (generic_phy);if (ret) { dev_err(hba->dev, "%s: phy init failed, ret = %d\n",
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
Peter Griffin
maintainerPATCH v2 5/7 scsi: ufs: exynos: Enable PRDT pre-fetching with UFSHCD_CAP_CRYPTO
In reply to Peter GriffinPRDT_PREFETCH_ENABLE[31] bit should be set when desctype field of fmpsecurity0 register is type2 (double file encryption) or type3 (support for file and disk encryption). Setting this bit enables PRDT pre-fetching on both TXPRDT and RXPRDT.
---
Changes since v1:
* Update PRDT_PREFECT_EN to PRDT_PREFETCH_EN (Bart)
* Update commit description for desctype type 3 (Eric)
--- drivers/ufs/host/ufs-exynos.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/ufs/host/ufs-exynos.c +7 -2
@@ -34,7 +34,7 @@* Exynos's Vendor specific registers for UFSHCI */ #define HCI_TXPRDT_ENTRY_SIZE 0x00 -#define PRDT_PREFECT_EN BIT(31) +#define PRDT_PREFETCH_EN BIT(31)#define HCI_RXPRDT_ENTRY_SIZE 0x04#define HCI_1US_TO_CNT_VAL 0x0C#define CNT_VAL_1US_MASK 0x3FF
@@ -1098,12 +1098,17 @@ static int exynos_ufs_post_link(struct ufs_hba *hba)struct exynos_ufs *ufs =ufshcd_get_variant (hba);struct phy *generic_phy = ufs->phy;struct exynos_ufs_uic_attr *attr = ufs->drv_data->uic_attr; +u32 val =ilog2 (DATA_UNIT_SIZE );exynos_ufs_establish_connt (ufs);exynos_ufs_fit_aggr_timeout (ufs);hci_writel (ufs,0xa ,HCI_DATA_REORDER ); -hci_writel (ufs,ilog2 (DATA_UNIT_SIZE ),HCI_TXPRDT_ENTRY_SIZE ); + +if (hba->caps &UFSHCD_CAP_CRYPTO ) + val |=PRDT_PREFETCH_EN ; +hci_writel (ufs, val,HCI_TXPRDT_ENTRY_SIZE ); +hci_writel (ufs,ilog2 (DATA_UNIT_SIZE ),HCI_RXPRDT_ENTRY_SIZE );hci_writel (ufs, (1 << hba->nutrs) -1 ,HCI_UTRL_NEXUS_TYPE );hci_writel (ufs, (1 << hba->nutmrs) -1 ,HCI_UTMRL_NEXUS_TYPE );
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
Peter Griffin
maintainerPATCH v2 6/7 scsi: ufs: exynos: Move phy calls to .exit() callback
In reply to Peter Griffinufshcd_pltfrm_remove() calls ufshcd_remove(hba) which in turn calls ufshcd_hba_exit().
By moving the phy_power_off() and phy_exit() calls to the newly created .exit callback they get called by ufshcd_variant_hba_exit() before ufshcd_hba_exit() turns off the regulators. This is also similar flow to the ufs-qcom driver.
---
Changes since v1:
* Remove superfluous blank line (Bart)
--- drivers/ufs/host/ufs-exynos.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/ufs/host/ufs-exynos.c +9 -6
@@ -1523,6 +1523,14 @@ static int exynos_ufs_init(struct ufs_hba *hba)return ret; } +static void exynos_ufs_exit (struct ufs_hba *hba) +{ +struct exynos_ufs *ufs =ufshcd_get_variant (hba); + +phy_power_off (ufs->phy); +phy_exit (ufs->phy); +} +static int exynos_ufs_host_reset (struct ufs_hba *hba) {struct exynos_ufs *ufs =ufshcd_get_variant (hba);
@@ -1978,6 +1986,7 @@ static int gs101_ufs_pre_pwr_change(struct exynos_ufs *ufs,static const struct ufs_hba_variant_ops ufs_hba_exynos_ops = { .name ="exynos_ufs" , .init = exynos_ufs_init, + .exit = exynos_ufs_exit, .hce_enable_notify = exynos_ufs_hce_enable_notify, .link_startup_notify = exynos_ufs_link_startup_notify, .pwr_change_notify = exynos_ufs_pwr_change_notify,
@@ -2016,13 +2025,7 @@ static int exynos_ufs_probe(struct platform_device *pdev)static void exynos_ufs_remove (struct platform_device *pdev) { -struct ufs_hba *hba =platform_get_drvdata (pdev); -struct exynos_ufs *ufs =ufshcd_get_variant (hba); -ufshcd_pltfrm_remove (pdev); - -phy_power_off (ufs->phy); -phy_exit (ufs->phy); }static struct exynos_ufs_uic_attr exynos7_uic_attr = {
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
Peter Griffin
maintainerPATCH v2 7/7 scsi: ufs: exynos: gs101: put ufs device in reset on .suspend()
In reply to Peter GriffinGPIO_OUT[0] is connected to the reset pin of embedded UFS device. Before powering off the phy assert the reset signal.
This is added as a gs101 specific suspend hook so as not to have any unintended consequences for other SoCs supported by this driver.
---
Changes since v1:
* Add a gs101 specific suspend hook (Bart)
* Drop asserting GPIO_OUT in .exit (Peter)
--- drivers/ufs/host/ufs-exynos.c | 10 ++++++++++ drivers/ufs/host/ufs-exynos.h | 1 + 2 files changed, 11 insertions(+)
drivers/ufs/host/ufs-exynos.c +10 -0
@@ -1701,6 +1701,12 @@ static void exynos_ufs_hibern8_notify(struct ufs_hba *hba, } } +static int gs101_ufs_suspend (struct exynos_ufs *ufs) +{ +hci_writel (ufs,0 <<0 ,HCI_GPIO_OUT ); +return 0 ; +} +static int exynos_ufs_suspend (struct ufs_hba *hba,enum ufs_pm_op pm_op,enum ufs_notify_change_status status) {
@@ -1709,6 +1715,9 @@ static int exynos_ufs_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op,if (status ==PRE_CHANGE )return 0 ; +if (ufs->drv_data->suspend) + ufs->drv_data->suspend (ufs); +if (!ufshcd_is_link_active (hba))phy_power_off (ufs->phy);
@@ -2171,6 +2180,7 @@ static const struct exynos_ufs_drv_data gs101_ufs_drvs = { .pre_link = gs101_ufs_pre_link, .post_link = gs101_ufs_post_link, .pre_pwr_change = gs101_ufs_pre_pwr_change, + .suspend = gs101_ufs_suspend, };static const struct of_device_id exynos_ufs_of_match[] = {
drivers/ufs/host/ufs-exynos.h +1 -0
@@ -192,6 +192,7 @@ struct exynos_ufs_drv_data { const struct ufs_pa_layer_attr *pwr);int (*pre_hce_enable)(struct exynos_ufs *ufs);int (*post_hce_enable)(struct exynos_ufs *ufs); +int (*suspend)(struct exynos_ufs *ufs); };struct ufs_phy_time_cfg {
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
Quoted 9 lines · Peter Griffin
This series fixes several stability issues with the upstream ufs-exynos driver, specifically for the gs101 SoC found in Pixel 6.
The main fix is regarding the IO cache coherency setting and ensuring that it is correctly applied depending on if the dma-coherent property is specified in device tree. This fixes the UFS stability issues on gs101 and I would imagine will also fix issues on exynosauto platform that seems to have similar iocc shareability bits.
Quoted 3 lines
Additionally the phy reference counting is fixed which allows module load/unload to work reliably and keeps the phy state machine in sync with the controller glue driver.
Although these patches are somewhat outside my area of expertise, the patches look good to me, hence:
Martin K. Petersen
AppliedPeter,
Quoted 2 lines
This series fixes several stability issues with the upstream ufs-exynos driver, specifically for the gs101 SoC found in Pixel 6.
Applied to 6.15/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen