scsi: ufs-mediatek: Provide features and fixes in MediaTek platforms
cover scsi: ufs-mediatek: Provide features and fixes in MediaTek platforms
Hi Martin,
This series provides some features and fixes in MediaTek UFS platforms. Please consider this patch series for kernel v5.20.
Peter Wang (2):
scsi: ufs: ufs-mediatek: Dump more registers
scsi: ufs: ufs-mediatek: Fix performance scaling
Po-Wen Kao (1):
scsi: ufs: ufs-medaitek: Support clk-scaling to optimize power
consumption
Stanley Chu (2):
scsi: ufs: ufs-mediatek: Remove redundant header files
scsi: ufs: ufs-mediatek: Provide detailed description for UIC errors
drivers/ufs/host/ufs-mediatek-trace.h | 25 +++- drivers/ufs/host/ufs-mediatek.c | 172 ++++++++++++++++++++++++-- drivers/ufs/host/ufs-mediatek.h | 45 +++++++ 3 files changed, 228 insertions(+), 14 deletions(-)
Signature · 1 line
2.18.0
PATCH 1/5 scsi: ufs: ufs-mediatek: Remove redundant header files
Remove redundant header files like
<linux/sched/clock.h>
--- drivers/ufs/host/ufs-mediatek.c | 1 - 1 file changed, 1 deletion(-)
drivers/ufs/host/ufs-mediatek.c +0 -1
@@ -19,7 +19,6 @@#include <linux/pm_qos.h> #include <linux/regulator/consumer.h> #include <linux/reset.h> -#include <linux/sched/clock.h> #include <linux/soc/mediatek/mtk_sip_svc.h> #include <ufs/ufshcd.h>
Signature · 1 line
2.18.0
PATCH 2/5 scsi: ufs: ufs-mediatek: Provide detailed description for UIC errors
In reply to Stanley ChuProvide detailed description in logs for UIC errors for eaiser issue breakdown.
--- drivers/ufs/host/ufs-mediatek.c | 20 +++++++++++++++++ drivers/ufs/host/ufs-mediatek.h | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+)
drivers/ufs/host/ufs-mediatek.c +20 -0
@@ -1309,8 +1309,28 @@ static void ufs_mtk_event_notify(struct ufs_hba *hba, enum ufs_event_type evt, void *data) { unsigned int val = *(u32 *)data; +unsigned long reg; +int bit;trace_ufs_mtk_event (evt, val); + +/* Print details of UIC Errors */ +if (evt <=UFS_EVT_DME_ERR ) { +dev_info (hba->dev, +"Host UIC Error Code (%s): %08x\n" , + ufs_uic_err_str[evt], val); + reg = val; + } + +if (evt ==UFS_EVT_PA_ERR ) { +for_each_set_bit (bit, ®,ARRAY_SIZE (ufs_uic_pa_err_str)) +dev_info (hba->dev,"%s\n" , ufs_uic_pa_err_str[bit]); + } + +if (evt ==UFS_EVT_DL_ERR ) { +for_each_set_bit (bit, ®,ARRAY_SIZE (ufs_uic_dl_err_str)) +dev_info (hba->dev,"%s\n" , ufs_uic_dl_err_str[bit]); + } }/*
drivers/ufs/host/ufs-mediatek.h +38 -0
@@ -26,6 +26,44 @@#define REG_UFS_DEBUG_SEL_B2 0x22D8#define REG_UFS_DEBUG_SEL_B3 0x22DC +/* +* Details of UIC Errors +*/ +static const u8 *ufs_uic_err_str[] = { +"PHY Adapter Layer" , +"Data Link Layer" , +"Network Link Layer" , +"Transport Link Layer" , +"DME" +}; + +static const u8 *ufs_uic_pa_err_str[] = { +"PHY error on Lane 0" , +"PHY error on Lane 1" , +"PHY error on Lane 2" , +"PHY error on Lane 3" , +"Generic PHY Adapter Error. This should be the LINERESET indication" +}; + +static const u8 *ufs_uic_dl_err_str[] = { +"NAC_RECEIVED" , +"TCx_REPLAY_TIMER_EXPIRED" , +"AFCx_REQUEST_TIMER_EXPIRED" , +"FCx_PROTECTION_TIMER_EXPIRED" , +"CRC_ERROR" , +"RX_BUFFER_OVERFLOW" , +"MAX_FRAME_LENGTH_EXCEEDED" , +"WRONG_SEQUENCE_NUMBER" , +"AFC_FRAME_SYNTAX_ERROR" , +"NAC_FRAME_SYNTAX_ERROR" , +"EOF_SYNTAX_ERROR" , +"FRAME_SYNTAX_ERROR" , +"BAD_CTRL_SYMBOL_TYPE" , +"PA_INIT_ERROR" , +"PA_ERROR_IND_RECEIVED" , +"PA_INIT" +}; +/* * Ref-clk control *
Signature · 1 line
2.18.0
PATCH 3/5 scsi: ufs: ufs-mediatek: Dump more registers
In reply to Stanley ChuFrom: Peter Wang <[email protected]>
Dump more proprietary UFSHCI status registers for
easier issue breakdown.
--- drivers/ufs/host/ufs-mediatek.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/ufs/host/ufs-mediatek.c +5 -2
@@ -1246,13 +1246,16 @@ static int ufs_mtk_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)static void ufs_mtk_dbg_register_dump (struct ufs_hba *hba) { -ufshcd_dump_regs (hba,REG_UFS_REFCLK_CTRL ,0x4 ,"Ref-Clk Ctrl " ); +/* Dump ufshci register 0x140 ~ 0x14C */ +ufshcd_dump_regs (hba,REG_UFS_XOUFS_CTRL ,0x10 , +"XOUFS Ctrl (0x140): " );ufshcd_dump_regs (hba,REG_UFS_EXTREG ,0x4 ,"Ext Reg " ); +/* Dump ufshci register 0x2200 ~ 0x22AC */ ufshcd_dump_regs (hba,REG_UFS_MPHYCTRL ,REG_UFS_REJECT_MON -REG_UFS_MPHYCTRL +4 , -"MPHY Ctrl " ); +"MPHY Ctrl (0x2200): " );/* Direct debugging information to REG_MTK_PROBE */ ufs_mtk_dbg_sel (hba);
Signature · 1 line
2.18.0
PATCH 4/5 scsi: ufs: ufs-mediatek: Fix performance scaling
In reply to Stanley ChuFrom: Peter Wang <[email protected]>
If clk-scaling is enabled, performance scaling can be bound to the decision of clk-scaling to avoid unnecessary boosting.
Meanwhile, fix missing initialization of pm-qos request.
--- drivers/ufs/host/ufs-mediatek.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
drivers/ufs/host/ufs-mediatek.c +16 -10
@@ -597,6 +597,12 @@ static void ufs_mtk_boost_pm_qos(struct ufs_hba *hba, bool boost) boost ? 0 : PM_QOS_DEFAULT_VALUE); } +static void ufs_mtk_scale_perf (struct ufs_hba *hba,bool scale_up) +{ +ufs_mtk_boost_crypt (hba, scale_up); +ufs_mtk_boost_pm_qos (hba, scale_up); +} +static void ufs_mtk_pwr_ctrl (struct ufs_hba *hba,bool on) {struct ufs_mtk_host *host =ufshcd_get_variant (hba);
@@ -604,11 +610,11 @@ static void ufs_mtk_pwr_ctrl(struct ufs_hba *hba, bool on)if (on) {phy_power_on (host->mphy);ufs_mtk_setup_ref_clk (hba, on); -ufs_mtk_boost_crypt (hba, on); -ufs_mtk_boost_pm_qos (hba, on); +if (!ufshcd_is_clkscaling_supported (hba)) +ufs_mtk_scale_perf (hba, on); }else { -ufs_mtk_boost_pm_qos (hba, on); -ufs_mtk_boost_crypt (hba, on); +if (!ufshcd_is_clkscaling_supported (hba)) +ufs_mtk_scale_perf (hba, on);ufs_mtk_setup_ref_clk (hba, on);phy_power_off (host->mphy); }
@@ -832,6 +838,10 @@ static int ufs_mtk_init(struct ufs_hba *hba) host->ip_ver =ufshcd_readl (hba,REG_UFS_MTK_IP_VER ); +/* Initialize pm-qos request */ +cpu_latency_qos_add_request (&host->pm_qos_req,PM_QOS_DEFAULT_VALUE ); + host->pm_qos_init = true; + goto out; out_variant_clear:
@@ -1424,7 +1434,6 @@ static int ufs_mtk_remove(struct platform_device *pdev)return 0 ; } -#ifdef CONFIG_PM_SLEEP static int ufs_mtk_system_suspend (struct device *dev) {struct ufs_hba *hba =dev_get_drvdata (dev);
@@ -1447,7 +1456,6 @@ static int ufs_mtk_system_resume(struct device *dev)return ufshcd_system_resume (dev); } -#endif static int ufs_mtk_runtime_suspend (struct device *dev) {
@@ -1473,10 +1481,8 @@ static int ufs_mtk_runtime_resume(struct device *dev) }static const struct dev_pm_ops ufs_mtk_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(ufs_mtk_system_suspend, - ufs_mtk_system_resume) -SET_RUNTIME_PM_OPS (ufs_mtk_runtime_suspend, - ufs_mtk_runtime_resume,NULL ) + SYSTEM_SLEEP_PM_OPS(ufs_mtk_system_suspend, ufs_mtk_system_resume) +RUNTIME_PM_OPS (ufs_mtk_runtime_suspend, ufs_mtk_runtime_resume,NULL ) .prepare = ufshcd_suspend_prepare, .complete = ufshcd_resume_complete, };
Signature · 1 line
2.18.0
PATCH 5/5 scsi: ufs: ufs-medaitek: Support clk-scaling to optimize power consumption
In reply to Stanley ChuFrom: Po-Wen Kao <[email protected]>
Provide clk-scaling feature in MediaTek UFS platforms.
MediaTek platform supports clk-scaling by switching parent clock mux of UFSHCI main clocks: ufs_sel.
The driver needs to prevent changing the rate of ufs_sel because its parent PLL clock may be shared between multiple IPs. In order to achieve this goal, the maximum and minimum clock rates of ufs_sel defined in dts should match the rate of "ufs_sel_max_src" and "ufs_sel_min_src" respectively.
--- drivers/ufs/host/ufs-mediatek-trace.h | 25 +++++- drivers/ufs/host/ufs-mediatek.c | 118 ++++++++++++++++++++++++++ drivers/ufs/host/ufs-mediatek.h | 7 ++ 3 files changed, 149 insertions(+), 1 deletion(-)
drivers/ufs/host/ufs-mediatek-trace.h +24 -1
@@ -26,7 +26,30 @@ TRACE_EVENT(ufs_mtk_event,TP_printk ("ufs:event=%u data=%u" , __entry->type, __entry->data) - ); +); + +TRACE_EVENT (ufs_mtk_clk_scale, + TP_PROTO(const char *name, bool scale_up, uint64_t clk_rate), +TP_ARGS (name, scale_up, clk_rate), + +TP_STRUCT__entry ( + __field(const char*, name) + __field(bool, scale_up) +__field (uint64_t, clk_rate) + ), + +TP_fast_assign ( + __entry->name = name; + __entry->scale_up = scale_up; + __entry->clk_rate = clk_rate; + ), + +TP_printk ("ufs: clk (%s) scaled %s @%d" , + __entry->name, + __entry->scale_up ?"up" :"down" , + __entry->clk_rate) +); +#endif #undef TRACE_INCLUDE_PATH
drivers/ufs/host/ufs-mediatek.c +118 -0
148 lines not on this page · raw message
drivers/ufs/host/ufs-mediatek.h +7 -0
@@ -162,6 +162,12 @@ struct ufs_mtk_crypt_cfg {int vcore_volt; }; +struct ufs_mtk_clk { +struct ufs_clk_info *ufs_sel_clki;/* Mux */ +struct ufs_clk_info *ufs_sel_max_clki;/* Max src */ +struct ufs_clk_info *ufs_sel_min_clki;/* min src */ +}; +struct ufs_mtk_hw_ver {u8 step;u8 minor;
@@ -177,6 +183,7 @@ struct ufs_mtk_host {struct reset_control *crypto_reset;struct ufs_hba *hba;struct ufs_mtk_crypt_cfg *crypt; +struct ufs_mtk_clk mclk;struct ufs_mtk_hw_ver hw_ver;enum ufs_mtk_host_caps caps;bool mphy_powered_on;
Signature · 1 line
2.18.0