Skip to contentSkip to conversation

scsi: ufs: fix error history and complete device reset history

PATCH Applied Stanley Chu 4 participants 13 messages Jan 4, 2020 – Jan 16, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover scsi: ufs: fix error history and complete device reset history

Hi,

This series targets on UFS error history fixes and feature add-on,

1. Fix empty check logic while outputing error history.
2. Add device reset history events for vendor's implementations.
3. Remove dummy word in output format.

Stanley Chu (3):
scsi: ufs: fix empty check of error history
scsi: ufs: add device reset history for vendor implementations
scsi: ufs: remove "errors" word in ufshcd_print_err_hist()

 drivers/scsi/ufs/ufshcd.c | 9 +++++----
 drivers/scsi/ufs/ufshcd.h | 6 +++++-
 2 files changed, 10 insertions(+), 5 deletions(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/3 scsi: ufs: fix empty check of error history

Currently checking if an error history element is empty or not is by its "value". In most cases, value is error code.

However this checking is not correct because some errors or events do not specify any values in error history so values remain as 0, and this will lead to incorrect empty checking.

Fix it by checking "timestamp" instead of "value" because timestamp will be always assigned for all history elements

Cc Alim Akhtar <[email protected]>
Cc Asutosh Das <[email protected]>
Cc Avri Altman <[email protected]>
Cc Bart Van Assche <[email protected]>
Cc Bean Huo <[email protected]>
Cc Can Guo <[email protected]>
Cc Matthias Brugger <[email protected]>
---
 drivers/scsi/ufs/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/ufs/ufshcd.c +1 -1
index 1b97f2dc0b63..bae43da00bb6 100644
@@ -385,7 +385,7 @@ static void ufshcd_print_err_hist(struct ufs_hba *hba,
 	for (i = 0; i < UFS_ERR_REG_HIST_LENGTH; i++) {
 		int p = (i + err_hist->pos) % UFS_ERR_REG_HIST_LENGTH;
 
-		if (err_hist->reg[p] == 0)
+		if (err_hist->tstamp[p] == 0)
 			continue;
 		dev_err(hba->dev, "%s[%d] = 0x%x at %lld us\n", err_name, p,
 			err_hist->reg[p], ktime_to_us(err_hist->tstamp[p]));
Signature · 1 line
2.18.0
#2 lore raw

Re: [PATCH v1 1/3] scsi: ufs: fix empty check of error history

Quoted 35 lines · Stanley Chu

Currently checking if an error history element is empty or not is by its "value". In most cases, value is error code.

However this checking is not correct because some errors or events do not specify any values in error history so values remain as 0, and this will lead to incorrect empty checking.

Fix it by checking "timestamp" instead of "value" because timestamp will be always assigned for all history elements

Cc Alim Akhtar <[email protected]>
Cc Asutosh Das <[email protected]>
Cc Avri Altman <[email protected]>
Cc Bart Van Assche <[email protected]>
Cc Bean Huo <[email protected]>
Cc Can Guo <[email protected]>
Cc Matthias Brugger <[email protected]>
---
 drivers/scsi/ufs/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/ufs/ufshcd.c +1 -1
index 1b97f2dc0b63..bae43da00bb6 100644
@@ -385,7 +385,7 @@ static void ufshcd_print_err_hist(struct ufs_hba 
 *hba,
 	for (i = 0; i < UFS_ERR_REG_HIST_LENGTH; i++) {
 		int p = (i + err_hist->pos) % UFS_ERR_REG_HIST_LENGTH;
 
-		if (err_hist->reg[p] == 0)
+		if (err_hist->tstamp[p] == 0)
 			continue;
 		dev_err(hba->dev, "%s[%d] = 0x%x at %lld us\n", err_name, p,
Quoted 1 line

err_hist->reg[p], ktime_to_us(err_hist->tstamp[p]));

Looks good to me.

Reviewed by:- Asutosh Das <[email protected]>

#3 lore raw

RE: [EXT] [PATCH v1 1/3] scsi: ufs: fix empty check of error history

In reply to Stanley Chu

Hi, Stanley

Quoted 8 lines

Currently checking if an error history element is empty or not is by its "value". In most cases, value is error code.

However this checking is not correct because some errors or events do not specify any values in error history so values remain as 0, and this will lead to incorrect empty checking.

Do you think this is a bug of UFS host controller? According to the UFS host Spec, If there had error detected in each layer, at least bit31 in its error code register Should be set to 1.

Why there was an error happening, but host didn't set this bit31?

Thanks.
//Bean

#4 lore raw

RE: [EXT] [PATCH v1 1/3] scsi: ufs: fix empty check of error history

Hi Bean,

Quoted 10 lines · Bean Huo (beanhuo)

Hi, Stanley

Quoted 8 lines

Currently checking if an error history element is empty or not is by its "value". In most cases, value is error code.

However this checking is not correct because some errors or events do not specify any values in error history so values remain as 0, and this will lead to incorrect empty checking.

Quoted 6 lines

Do you think this is a bug of UFS host controller? According to the UFS host Spec, If there had error detected in each layer, at least bit31 in its error code register Should be set to 1.

Why there was an error happening, but host didn't set this bit31?

Thanks so much for review.

Yes, the case bit[31] set is true for UIC errors.

However the users of UFS error history, i.e., users of ufshcd_update_reg_hlist(), are not only UIC errors. Some other essential events will update history too, for example, device reset events and abort events.

Take "device reset events" as example: parameter "val" may be 0 while invoking ufshcd_update_reg_hlist(). If this happens, the device reset event will not be printed out because its err_hist->reg[p] is 0 according to the original logic in ufshcd_print_err_hist().

Feel free to correct above description if it is wrong.

Thanks,
Stanley

Reviewed-by
#5 lore raw

RE: [EXT] [PATCH v1 1/3] scsi: ufs: fix empty check of error history

Quoted 35 lines

Subject: RE: [EXT] [PATCH v1 1/3] scsi: ufs: fix empty check of error history

Hi Bean,

Quoted 10 lines · Bean Huo (beanhuo)

Hi, Stanley

Quoted 8 lines

Currently checking if an error history element is empty or not is by its "value". In most cases, value is error code.

However this checking is not correct because some errors or events do not specify any values in error history so values remain as 0, and this will lead to incorrect empty checking.

Quoted 6 lines

Do you think this is a bug of UFS host controller? According to the UFS host Spec, If there had error detected in each layer, at least bit31 in its error code register Should be set to 1.

Why there was an error happening, but host didn't set this bit31?

Thanks so much for review.

Yes, the case bit[31] set is true for UIC errors.

However the users of UFS error history, i.e., users of ufshcd_update_reg_hlist(), are not only UIC errors. Some other essential events will update history too, for example, device reset events and abort events.

Take "device reset events" as example: parameter "val" may be 0 while invoking ufshcd_update_reg_hlist(). If this happens, the device reset event will not be printed out because its err_hist->reg[p] is 0 according to the original logic in ufshcd_print_err_hist().

Quoted 4 lines

Feel free to correct above description if it is wrong.

Thanks,
Stanley

Hi, Stanley
Thanks, now clear, it is not controller negative act issue.

#6 lore raw

PATCH 2/3 scsi: ufs: add device reset history for vendor implementations

In reply to Stanley Chu

Device reset history shall be also added for vendor's device reset variant operation implementation.

Cc Alim Akhtar <[email protected]>
Cc Asutosh Das <[email protected]>
Cc Avri Altman <[email protected]>
Cc Bart Van Assche <[email protected]>
Cc Bean Huo <[email protected]>
Cc Can Guo <[email protected]>
Cc Matthias Brugger <[email protected]>
---
 drivers/scsi/ufs/ufshcd.c | 5 +++--
 drivers/scsi/ufs/ufshcd.h | 6 +++++-
 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/scsi/ufs/ufshcd.c +3 -2
index bae43da00bb6..29e3d50aabfb 100644
@@ -4346,13 +4346,14 @@ static inline int ufshcd_disable_device_tx_lcc(struct ufs_hba *hba)
 	return ufshcd_disable_tx_lcc(hba, true);
 }
 
-static void ufshcd_update_reg_hist(struct ufs_err_reg_hist *reg_hist,
-				   u32 reg)
+void ufshcd_update_reg_hist(struct ufs_err_reg_hist *reg_hist,
+			    u32 reg)
 {
 	reg_hist->reg[reg_hist->pos] = reg;
 	reg_hist->tstamp[reg_hist->pos] = ktime_get();
 	reg_hist->pos = (reg_hist->pos + 1) % UFS_ERR_REG_HIST_LENGTH;
 }
+EXPORT_SYMBOL_GPL(ufshcd_update_reg_hist);
 
 /**
  * ufshcd_link_startup - Initialize unipro link startup
drivers/scsi/ufs/ufshcd.h +5 -1
index e05cafddc87b..de1be6a862b0 100644
@@ -805,6 +805,8 @@ int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask,
 				u32 val, unsigned long interval_us,
 				unsigned long timeout_ms, bool can_sleep);
 void ufshcd_parse_dev_ref_clk_freq(struct ufs_hba *hba, struct clk *refclk);
+void ufshcd_update_reg_hist(struct ufs_err_reg_hist *reg_hist,
+			    u32 reg);
 
 static inline void check_upiu_size(void)
 {
@@ -1083,8 +1085,10 @@ static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
 
 static inline void ufshcd_vops_device_reset(struct ufs_hba *hba)
 {
-	if (hba->vops && hba->vops->device_reset)
+	if (hba->vops && hba->vops->device_reset) {
 		hba->vops->device_reset(hba);
+		ufshcd_update_reg_hist(&hba->ufs_stats.dev_reset, 0);
+	}
 }
 
 extern struct ufs_pm_lvl_states ufs_pm_lvl_states[];
Signature · 1 line
2.18.0
Reviewed-by on v1 2/3
#8 lore raw

Re: [PATCH v1 2/3] scsi: ufs: add device reset history for vendor implementations

In reply to Stanley Chu
Quoted 65 lines · Stanley Chu

Device reset history shall be also added for vendor's device reset variant operation implementation.

Cc Alim Akhtar <[email protected]>
Cc Asutosh Das <[email protected]>
Cc Avri Altman <[email protected]>
Cc Bart Van Assche <[email protected]>
Cc Bean Huo <[email protected]>
Cc Can Guo <[email protected]>
Cc Matthias Brugger <[email protected]>
---
 drivers/scsi/ufs/ufshcd.c | 5 +++--
 drivers/scsi/ufs/ufshcd.h | 6 +++++-
 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/scsi/ufs/ufshcd.c +3 -2
index bae43da00bb6..29e3d50aabfb 100644
@@ -4346,13 +4346,14 @@ static inline int
 ufshcd_disable_device_tx_lcc(struct ufs_hba *hba)
 	return ufshcd_disable_tx_lcc(hba, true);
 }
 
-static void ufshcd_update_reg_hist(struct ufs_err_reg_hist *reg_hist,
-				   u32 reg)
+void ufshcd_update_reg_hist(struct ufs_err_reg_hist *reg_hist,
+			    u32 reg)
 {
 	reg_hist->reg[reg_hist->pos] = reg;
 	reg_hist->tstamp[reg_hist->pos] = ktime_get();
 	reg_hist->pos = (reg_hist->pos + 1) % UFS_ERR_REG_HIST_LENGTH;
 }
+EXPORT_SYMBOL_GPL(ufshcd_update_reg_hist);
 
 /**

* ufshcd_link_startup - Initialize unipro link startup

drivers/scsi/ufs/ufshcd.h +2 -0
index e05cafddc87b..de1be6a862b0 100644
@@ -805,6 +805,8 @@ int ufshcd_wait_for_register(struct ufs_hba *hba,
 u32 reg, u32 mask,
 				u32 val, unsigned long interval_us,
 				unsigned long timeout_ms, bool can_sleep);
 void ufshcd_parse_dev_ref_clk_freq(struct ufs_hba *hba, struct clk 
 *refclk);
+void ufshcd_update_reg_hist(struct ufs_err_reg_hist *reg_hist,
+			    u32 reg);
 

static inline void check_upiu_size(void)
{

drivers/scsi/ufs/ufshcd.h +3 -1
@@ -1083,8 +1085,10 @@ static inline void
 ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
 
 static inline void ufshcd_vops_device_reset(struct ufs_hba *hba)
 {
-	if (hba->vops && hba->vops->device_reset)
+	if (hba->vops && hba->vops->device_reset) {
 		hba->vops->device_reset(hba);
+		ufshcd_update_reg_hist(&hba->ufs_stats.dev_reset, 0);
+	}
 }
 
Quoted 1 line

extern struct ufs_pm_lvl_states ufs_pm_lvl_states[];

#9 lore raw

PATCH 3/3 scsi: ufs: remove "errors" word in ufshcd_print_err_hist()

In reply to Stanley Chu

Remove "errors" word in output string by ufshcd_print_err_hist() since not all printed targets are "errors". Sometimes they are just "events".

In addition, all events which can be treated as "errors" already have "err" or "fail" words in their names.

Cc Alim Akhtar <[email protected]>
Cc Asutosh Das <[email protected]>
Cc Avri Altman <[email protected]>
Cc Bart Van Assche <[email protected]>
Cc Bean Huo <[email protected]>
Cc Can Guo <[email protected]>
Cc Matthias Brugger <[email protected]>
---
 drivers/scsi/ufs/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/ufs/ufshcd.c +1 -1
index 29e3d50aabfb..d847426507e7 100644
@@ -393,7 +393,7 @@ static void ufshcd_print_err_hist(struct ufs_hba *hba,
 	}
 
 	if (!found)
-		dev_err(hba->dev, "No record of %s errors\n", err_name);
+		dev_err(hba->dev, "No record of %s\n", err_name);
 }
 
 static void ufshcd_print_host_regs(struct ufs_hba *hba)
Signature · 1 line
2.18.0
#11 lore raw
In reply to Stanley Chu

Hi,

Gentle ping for this set.

Quoted 17 lines · Stanley Chu

Hi,

This series targets on UFS error history fixes and feature add-on,

1. Fix empty check logic while outputing error history.
2. Add device reset history events for vendor's implementations.
3. Remove dummy word in output format.

Stanley Chu (3):
scsi: ufs: fix empty check of error history
scsi: ufs: add device reset history for vendor implementations
scsi: ufs: remove "errors" word in ufshcd_print_err_hist()

 drivers/scsi/ufs/ufshcd.c | 9 +++++----
 drivers/scsi/ufs/ufshcd.h | 6 +++++-
 2 files changed, 10 insertions(+), 5 deletions(-)
#12 lore raw
In reply to Stanley Chu

Stanley,

Quoted 5 lines

This series targets on UFS error history fixes and feature add-on,

1. Fix empty check logic while outputing error history.
2. Add device reset history events for vendor's implementations.
3. Remove dummy word in output format.

Applied to 5.6/scsi-queue, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering