scsi: ufs: some cleanups and make the delay for host enabling customizable
Subsystems (2)
PATCH 1/4 scsi: ufs: remove init_prefetch_data in struct ufs_hba
In reply to Stanley ChuStruct init_prefetch_data currently is used privately in ufshcd_init_icc_levels(), thus it can be removed from struct ufs_hba.
--- drivers/scsi/ufs/ufshcd.c | 15 ++++++--------- drivers/scsi/ufs/ufshcd.h | 2 -- 2 files changed, 6 insertions(+), 11 deletions(-)
drivers/scsi/ufs/ufshcd.c +6 -9
@@ -6494,6 +6494,7 @@ static void ufshcd_init_icc_levels(struct ufs_hba *hba) {int ret;int buff_len = hba->desc_size.pwr_desc; +u32 icc_level;u8 *desc_buf; desc_buf =kmalloc (buff_len,GFP_KERNEL );
@@ -6509,21 +6510,17 @@ static void ufshcd_init_icc_levels(struct ufs_hba *hba) goto out; } - hba->init_prefetch_data.icc_level = -ufshcd_find_max_sup_active_icc_level (hba, - desc_buf, buff_len); -dev_dbg (hba->dev,"%s: setting icc_level 0x%x" , - __func__, hba->init_prefetch_data.icc_level); + icc_level = +ufshcd_find_max_sup_active_icc_level (hba, desc_buf, buff_len); +dev_dbg (hba->dev,"%s: setting icc_level 0x%x" , __func__, icc_level); ret =ufshcd_query_attr_retry (hba,UPIU_QUERY_OPCODE_WRITE_ATTR , -QUERY_ATTR_IDN_ACTIVE_ICC_LVL ,0 ,0 , - &hba->init_prefetch_data.icc_level); +QUERY_ATTR_IDN_ACTIVE_ICC_LVL ,0 ,0 , &icc_level);if (ret)dev_err (hba->dev,"%s: Failed configuring bActiveICCLevel = %d ret = %d" , - __func__, hba->init_prefetch_data.icc_level , ret); - + __func__, icc_level, ret); out:kfree (desc_buf); }
drivers/scsi/ufs/ufshcd.h +0 -2
@@ -541,7 +541,6 @@ enum ufshcd_quirks {* @intr_mask: Interrupt Mask Bits * @ee_ctrl_mask: Exception event control mask * @is_powered: flag to check if HBA is powered -* @init_prefetch_data: data pre-fetched during initialization * @eh_work: Worker to handle UFS errors that require s/w attention * @eeh_work: Worker to handle exception events * @errors: HBA errors
@@ -627,7 +626,6 @@ struct ufs_hba {u32 intr_mask;u16 ee_ctrl_mask;bool is_powered; -struct ufs_init_prefetch init_prefetch_data;/* Work Queues */ struct work_struct eh_work;
Signature · 1 line
2.18.0
cover scsi: ufs: some cleanups and make the delay for host enabling customizable
Hi,
This patchset do some cleanups in ufs host driver and make the delay for host enabling customizable by different controller or vendors.
Stanley Chu (4):
scsi: ufs: remove init_prefetch_data in struct ufs_hba
scsi: ufs: use an enum for host capabilities
scsi: ufs: allow customized delay for host enabling
scsi: ufs-mediatek: remove delay for host enabling
drivers/scsi/ufs/ufs-mediatek.c | 2 + drivers/scsi/ufs/ufshcd.c | 21 +++++----- drivers/scsi/ufs/ufshcd.h | 68 ++++++++++++++++++--------------- 3 files changed, 51 insertions(+), 40 deletions(-)
Signature · 1 line
2.18.0
PATCH 2/4 scsi: ufs: use an enum for host capabilities
Use an enum to specify the host capabilities instead of #defines inside the structure definition.
--- drivers/scsi/ufs/ufshcd.h | 65 ++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 28 deletions(-)
drivers/scsi/ufs/ufshcd.h +37 -28
@@ -510,6 +510,43 @@ enum ufshcd_quirks { UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION = 1 << 5, }; +enum ufshcd_caps { +/* Allow dynamic clk gating */ +UFSHCD_CAP_CLK_GATING =1 <<0 , + +/* Allow hiberb8 with clk gating */ +UFSHCD_CAP_HIBERN8_WITH_CLK_GATING =1 <<1 , + +/* Allow dynamic clk scaling */ +UFSHCD_CAP_CLK_SCALING =1 <<2 , + +/* Allow auto bkops to enabled during runtime suspend */ +UFSHCD_CAP_AUTO_BKOPS_SUSPEND =1 <<3 , + +/* +* This capability allows host controller driver to use the UFS HCI's +* interrupt aggregation capability. +* CAUTION: Enabling this might reduce overall UFS throughput. +*/ +UFSHCD_CAP_INTR_AGGR =1 <<4 , + +/* +* This capability allows the device auto-bkops to be always enabled +* except during suspend (both runtime and suspend). +* Enabling this capability means that device will always be allowed +* to do background operation when it's active but it might degrade +* the performance of ongoing read/write operations. +*/ +UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND =1 <<5 , + +/* +* This capability allows host controller driver to automatically +* enable runtime power management by itself instead of waiting +* for userspace to control the power management. +*/ +UFSHCD_CAP_RPM_AUTOSUSPEND =1 <<6 , +}; +/** * struct ufs_hba - per adapter private structure * @mmio_base: UFSHCI base register address
@@ -662,34 +699,6 @@ struct ufs_hba {struct ufs_clk_gating clk_gating;/* Control to enable/disable host capabilities */ u32 caps; -/* Allow dynamic clk gating */ -#define UFSHCD_CAP_CLK_GATING (1 << 0) -/* Allow hiberb8 with clk gating */ -#define UFSHCD_CAP_HIBERN8_WITH_CLK_GATING (1 << 1) -/* Allow dynamic clk scaling */ -#define UFSHCD_CAP_CLK_SCALING (1 << 2) -/* Allow auto bkops to enabled during runtime suspend */ -#define UFSHCD_CAP_AUTO_BKOPS_SUSPEND (1 << 3) -/* -* This capability allows host controller driver to use the UFS HCI's -* interrupt aggregation capability. -* CAUTION: Enabling this might reduce overall UFS throughput. -*/ -#define UFSHCD_CAP_INTR_AGGR (1 << 4) -/* -* This capability allows the device auto-bkops to be always enabled -* except during suspend (both runtime and suspend). -* Enabling this capability means that device will always be allowed -* to do background operation when it's active but it might degrade -* the performance of ongoing read/write operations. -*/ -#define UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND (1 << 5) -/* -* This capability allows host controller driver to automatically -* enable runtime power management by itself instead of waiting -* for userspace to control the power management. -*/ -#define UFSHCD_CAP_RPM_AUTOSUSPEND (1 << 6)struct devfreq *devfreq;struct ufs_clk_scaling clk_scaling;
Signature · 1 line
2.18.0
PATCH 4/4 scsi: ufs-mediatek: remove delay for host enabling
In reply to Stanley ChuMediaTek platform and UFS controller do not require the delay for host enabling, thus remove it.
--- drivers/scsi/ufs/ufs-mediatek.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/ufs/ufs-mediatek.c +2 -0
@@ -258,6 +258,8 @@ static int ufs_mtk_init(struct ufs_hba *hba)if (err) goto out_variant_clear; + hba->hba_enable_delay_us =0 ; +/* Enable runtime autosuspend */ hba->caps |=UFSHCD_CAP_RPM_AUTOSUSPEND ;
Signature · 5 lines
2.18.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 3/4 scsi: ufs: allow customized delay for host enabling
In reply to Stanley ChuCurrently a 1 ms delay is applied before polling CONTROLLER_ENABLE bit. This delay may not be required or can be changed in different controllers. Make the delay as a changeable value in struct ufs_hba to allow it customized by vendors.
--- drivers/scsi/ufs/ufshcd.c | 6 +++++- drivers/scsi/ufs/ufshcd.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/scsi/ufs/ufshcd.c +5 -1
@@ -4282,7 +4282,10 @@ int ufshcd_hba_enable(struct ufs_hba *hba)* instruction might be read back. * This delay can be changed based on the controller. */ -usleep_range (1000 ,1100 ); +if (hba->hba_enable_delay_us) { +usleep_range (hba->hba_enable_delay_us, + hba->hba_enable_delay_us +100 ); + }/* wait for the host controller to complete initialization */ retry =10 ;
@@ -8402,6 +8405,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) hba->mmio_base = mmio_base; hba->irq = irq; + hba->hba_enable_delay_us =1000 ; err =ufshcd_hba_init (hba);if (err)
drivers/scsi/ufs/ufshcd.h +1 -0
@@ -662,6 +662,7 @@ struct ufs_hba {u32 eh_flags;u32 intr_mask;u16 ee_ctrl_mask; +u16 hba_enable_delay_us;bool is_powered;/* Work Queues */
Signature · 1 line
2.18.0
Re: [PATCH v1 2/4] scsi: ufs: use an enum for host capabilities
In reply to Stanley ChuHi Stanley,
Quoted 4 lines · Stanley Chu
Use an enum to specify the host capabilities instead of #defines inside the structure definition.
Signed-off-by Stanley Chu <[email protected]>
Quoted 87 lines
--- drivers/scsi/ufs/ufshcd.h | 65 ++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 28 deletions(-)drivers/scsi/ufs/ufshcd.h +37
-28@@ -510,6 +510,43 @@ enum ufshcd_quirks { UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION = 1 << 5, }; +enum ufshcd_caps { +/* Allow dynamic clk gating */ +UFSHCD_CAP_CLK_GATING =1 <<0 , + +/* Allow hiberb8 with clk gating */ +UFSHCD_CAP_HIBERN8_WITH_CLK_GATING =1 <<1 , + +/* Allow dynamic clk scaling */ +UFSHCD_CAP_CLK_SCALING =1 <<2 , + +/* Allow auto bkops to enabled during runtime suspend */ +UFSHCD_CAP_AUTO_BKOPS_SUSPEND =1 <<3 , + +/* +* This capability allows host controller driver to use the UFS HCI's +* interrupt aggregation capability. +* CAUTION: Enabling this might reduce overall UFS throughput. +*/ +UFSHCD_CAP_INTR_AGGR =1 <<4 , + +/* +* This capability allows the device auto-bkops to be always enabled +* except during suspend (both runtime and suspend). +* Enabling this capability means that device will always be allowed +* to do background operation when it's active but it might degrade +* the performance of ongoing read/write operations. +*/ +UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND =1 <<5 , + +/* +* This capability allows host controller driver to automatically +* enable runtime power management by itself instead of waiting +* for userspace to control the power management. +*/ +UFSHCD_CAP_RPM_AUTOSUSPEND =1 <<6 , +}; +/** * struct ufs_hba - per adapter private structure * @mmio_base: UFSHCI base register address @@ -662,34 +699,6 @@ struct ufs_hba {struct ufs_clk_gating clk_gating;/* Control to enable/disable host capabilities */ u32 caps; -/* Allow dynamic clk gating */ -#define UFSHCD_CAP_CLK_GATING (1 << 0) -/* Allow hiberb8 with clk gating */ -#define UFSHCD_CAP_HIBERN8_WITH_CLK_GATING (1 << 1) -/* Allow dynamic clk scaling */ -#define UFSHCD_CAP_CLK_SCALING (1 << 2) -/* Allow auto bkops to enabled during runtime suspend */ -#define UFSHCD_CAP_AUTO_BKOPS_SUSPEND (1 << 3) -/* -* This capability allows host controller driver to use the UFS HCI's -* interrupt aggregation capability. -* CAUTION: Enabling this might reduce overall UFS throughput. -*/ -#define UFSHCD_CAP_INTR_AGGR (1 << 4) -/* -* This capability allows the device auto-bkops to be always enabled -* except during suspend (both runtime and suspend). -* Enabling this capability means that device will always be allowed -* to do background operation when it's active but it might degrade -* the performance of ongoing read/write operations. -*/ -#define UFSHCD_CAP_KEEP_AUTO_BKOPS_ENABLED_EXCEPT_SUSPEND (1 << 5) -/* -* This capability allows host controller driver to automatically -* enable runtime power management by itself instead of waiting -* for userspace to control the power management. -*/ -#define UFSHCD_CAP_RPM_AUTOSUSPEND (1 << 6)struct devfreq *devfreq;struct ufs_clk_scaling clk_scaling;
Re: [PATCH v1 3/4] scsi: ufs: allow customized delay for host enabling
In reply to Stanley ChuHi Stanley,
Quoted 6 lines · Stanley Chu
Currently a 1 ms delay is applied before polling
CONTROLLER_ENABLEbit. This delay may not be required or can be changed in different controllers. Make the delay as a changeable value in structufs_hbato allow it customized by vendors.Signed-off-by Stanley Chu <[email protected]>
Quoted 42 lines
--- drivers/scsi/ufs/ufshcd.c | 6 +++++- drivers/scsi/ufs/ufshcd.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)drivers/scsi/ufs/ufshcd.c +5
-1@@ -4282,7 +4282,10 @@ int ufshcd_hba_enable(struct ufs_hba *hba)* instruction might be read back. * This delay can be changed based on the controller. */ -usleep_range (1000 ,1100 ); +if (hba->hba_enable_delay_us) { +usleep_range (hba->hba_enable_delay_us, + hba->hba_enable_delay_us +100 ); + }/* wait for the host controller to complete initialization */ retry =10 ;@@ -8402,6 +8405,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) hba->mmio_base = mmio_base; hba->irq = irq; + hba->hba_enable_delay_us =1000 ; err =ufshcd_hba_init (hba);drivers/scsi/ufs/ufshcd.c +0
-0if (err)drivers/scsi/ufs/ufshcd.h +1
-0@@ -662,6 +662,7 @@ struct ufs_hba {u32 eh_flags;u32 intr_mask;u16 ee_ctrl_mask; +u16 hba_enable_delay_us;bool is_powered;/* Work Queues */
RE: [PATCH v1 4/4] scsi: ufs-mediatek: remove delay for host enabling
In reply to Stanley ChuHi Stanley,
drivers/scsi/ufs/ufs-mediatek.c static int ufs_mtk_init(struct ufs_hba *hba)
Quoted 15 lines
MediaTek platform and UFS controller do not require the delay for host enabling, thus remove it.
Signed-off-by Stanley Chu <[email protected]>--- drivers/scsi/ufs/ufs-mediatek.c | 2 ++ 1 file changed, 2 insertions(+)drivers/scsi/ufs/ufs-mediatek.c +0
-0@@ -258,6 +258,8 @@ static int ufs_mtk_init(struct ufs_hba *hba)
I would expect to set whatever is needed for your host controller In ufshcd_vops_hce_enable_notify(hba, PRE_CHANGE), and not here.
Thanks,
Avri
Quoted 10 lines
drivers/scsi/ufs/ufs-mediatek.c +2
-1if (err) goto out_variant_clear; + hba->hba_enable_delay_us =0 ; +/* Enable runtime autosuspend */ hba->caps |=UFSHCD_CAP_RPM_AUTOSUSPEND ; --2.18.0
RE: [PATCH v1 4/4] scsi: ufs-mediatek: remove delay for host enabling
Hi Avri,
Quoted 12 lines · Avri Altman
Hi Stanley,
Quoted 10 lines
MediaTek platform and UFS controller do not require the delay for host enabling, thus remove it.
Signed-off-by Stanley Chu <[email protected]>--- drivers/scsi/ufs/ufs-mediatek.c | 2 ++ 1 file changed, 2 insertions(+)
Quoted 8 lines
drivers/scsi/ufs/ufs-mediatek.c static int ufs_mtk_init(struct ufs_hba *hba)
Quoted 5 lines
drivers/scsi/ufs/ufs-mediatek.c +0
-0@@ -258,6 +258,8 @@ static int ufs_mtk_init(struct ufs_hba *hba)I would expect to set whatever is needed for your host controller In
ufshcd_vops_hce_enable_notify(hba, PRE_CHANGE), and not here.
I think this is a good suggestion! And thus we could have more flexibility to customize the value according to different scenarios.
I will consider this approach in next version.
Thanks!
Stanley Chu