Skip to contentSkip to conversation

UFS driver fixes and cleanups

PATCH Applied Bart Van Assche 2 participants 9 messages Oct 22, 2024 – Nov 5, 2024

Subsystems (2)
lore
Share & tools
lore

Bart Van Assche

author reviewer
#0 lore raw

v2 cover UFS driver fixes and cleanups

Hi Martin,

This patch series includes several fixes and cleanup patches for the UFS driver. Please consider this patch series for the next merge window.

Thanks,

Bart.

Changes compared to v1:
- Reworked patch 4. Instead of changing ufshcd_scsi_block_requests() into blk_mq_quiesce_tagset(), remove the calls for blocking and unblocking SCSI requests.
- Made the patch description of patch 6 more detailed.
- Dropped patch 7 from this series and posted it separately.

Bart Van Assche (6):
scsi: ufs: core: Move the ufshcd_mcq_enable_esi() definition
scsi: ufs: core: Remove goto statements from
ufshcd_try_to_abort_task()
scsi: ufs: core: Simplify ufshcd_try_to_abort_task()
scsi: ufs: core: Simplify ufshcd_exception_event_handler()
scsi: ufs: core: Simplify ufshcd_err_handling_prepare()
scsi: ufs: core: Improve ufshcd_mcq_sq_cleanup()

 drivers/ufs/core/ufs-mcq.c | 26 ++++++++------
 drivers/ufs/core/ufshcd.c  | 73 ++++++++++----------------------------
 include/ufs/ufshcd.h       |  4 +--
 3 files changed, 34 insertions(+), 69 deletions(-)
author reviewer
#1 lore raw

PATCH v2 1/6 scsi: ufs: core: Move the ufshcd_mcq_enable_esi() definition

Move the ufshcd_mcq_enable_esi() definition such that it occurs immediately before the ufshcd_mcq_config_esi() definition.

---
 drivers/ufs/core/ufs-mcq.c | 14 +++++++-------
 include/ufs/ufshcd.h       |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/ufs/core/ufs-mcq.c +7 -7
index 5891cdacd0b3..57ced1729b73 100644
@@ -417,13 +417,6 @@ void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba)
 }
 EXPORT_SYMBOL_GPL(ufshcd_mcq_make_queues_operational);
 
-void ufshcd_mcq_enable_esi(struct ufs_hba *hba)
-{
-	ufshcd_writel(hba, ufshcd_readl(hba, REG_UFS_MEM_CFG) | 0x2,
-		      REG_UFS_MEM_CFG);
-}
-EXPORT_SYMBOL_GPL(ufshcd_mcq_enable_esi);
-
 void ufshcd_mcq_enable(struct ufs_hba *hba)
 {
 	ufshcd_rmwl(hba, MCQ_MODE_SELECT, MCQ_MODE_SELECT, REG_UFS_MEM_CFG);
@@ -437,6 +430,13 @@ void ufshcd_mcq_disable(struct ufs_hba *hba)
 	hba->mcq_enabled = false;
 }
 
+void ufshcd_mcq_enable_esi(struct ufs_hba *hba)
+{
+	ufshcd_writel(hba, ufshcd_readl(hba, REG_UFS_MEM_CFG) | 0x2,
+		      REG_UFS_MEM_CFG);
+}
+EXPORT_SYMBOL_GPL(ufshcd_mcq_enable_esi);
+
 void ufshcd_mcq_config_esi(struct ufs_hba *hba, struct msi_msg *msg)
 {
 	ufshcd_writel(hba, msg->address_lo, REG_UFS_ESILBA);
include/ufs/ufshcd.h +1 -1
index a95282b9f743..a0b325a32aca 100644
@@ -1321,8 +1321,8 @@ void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i);
 unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba,
 					 struct ufs_hw_queue *hwq);
 void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba);
-void ufshcd_mcq_enable_esi(struct ufs_hba *hba);
 void ufshcd_mcq_enable(struct ufs_hba *hba);
+void ufshcd_mcq_enable_esi(struct ufs_hba *hba);
 void ufshcd_mcq_config_esi(struct ufs_hba *hba, struct msi_msg *msg);
 
 int ufshcd_opp_config_clks(struct device *dev, struct opp_table *opp_table,
author reviewer
#2 lore raw

PATCH v2 2/6 scsi: ufs: core: Remove goto statements from ufshcd_try_to_abort_task()

In reply to Bart Van Assche

The only statement that follows the 'out:' label in ufshcd_try_to_abort_task() is a return-statement. Simplify this function by changing 'goto out' statements into return statements.

---
 drivers/ufs/core/ufshcd.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/ufs/core/ufshcd.c +7 -12
index 9e6d008f4ea4..57ce1910fda0 100644
@@ -7486,7 +7486,7 @@ static void ufshcd_set_req_abort_skip(struct ufs_hba *hba, unsigned long bitmap)
 int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)
 {
 	struct ufshcd_lrb *lrbp = &hba->lrb[tag];
-	int err = 0;
+	int err;
 	int poll_cnt;
 	u8 resp = 0xF;
 	u32 reg;
@@ -7516,7 +7516,7 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)
 				/* command completed already */
 				dev_err(hba->dev, "%s: cmd at tag=%d is cleared.\n",
 					__func__, tag);
-				goto out;
+				return 0;
 			}
 
 			/* Single Doorbell Mode */
@@ -7529,21 +7529,17 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)
 			/* command completed already */
 			dev_err(hba->dev, "%s: cmd at tag %d successfully cleared from DB.\n",
 				__func__, tag);
-			goto out;
+			return 0;
 		} else {
 			dev_err(hba->dev,
 				"%s: no response from device. tag = %d, err %d\n",
 				__func__, tag, err);
-			if (!err)
-				err = resp; /* service response error */
-			goto out;
+			return err ? : resp;
 		}
 	}
 
-	if (!poll_cnt) {
-		err = -EBUSY;
-		goto out;
-	}
+	if (!poll_cnt)
+		return -EBUSY;
 
 	err = ufshcd_issue_tm_cmd(hba, lrbp->lun, lrbp->task_tag,
 			UFS_ABORT_TASK, &resp);
@@ -7553,7 +7549,7 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)
 			dev_err(hba->dev, "%s: issued. tag = %d, err %d\n",
 				__func__, tag, err);
 		}
-		goto out;
+		return err;
 	}
 
 	err = ufshcd_clear_cmd(hba, tag);
@@ -7561,7 +7557,6 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)
 		dev_err(hba->dev, "%s: Failed clearing cmd at tag %d, err %d\n",
 			__func__, tag, err);
 
-out:
 	return err;
 }
 
author reviewer
#3 lore raw

PATCH v2 3/6 scsi: ufs: core: Simplify ufshcd_try_to_abort_task()

In reply to Bart Van Assche

The MCQ code is also valid for legacy mode. Hence, remove the legacy mode code and retain the MCQ code. Since it is not an error if a command completes while ufshcd_try_to_abort_task() is in progress, use dev_info() instead of dev_err() to report this.

---
 drivers/ufs/core/ufshcd.c | 32 ++++++++------------------------
 1 file changed, 8 insertions(+), 24 deletions(-)
drivers/ufs/core/ufshcd.c +8 -24
index 57ce1910fda0..76884df580c3 100644
@@ -7489,7 +7489,6 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)
 	int err;
 	int poll_cnt;
 	u8 resp = 0xF;
-	u32 reg;
 
 	for (poll_cnt = 100; poll_cnt; poll_cnt--) {
 		err = ufshcd_issue_tm_cmd(hba, lrbp->lun, lrbp->task_tag,
@@ -7504,32 +7503,17 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag)
 			 * cmd not pending in the device, check if it is
 			 * in transition.
 			 */
-			dev_err(hba->dev, "%s: cmd at tag %d not pending in the device.\n",
+			dev_info(
+				hba->dev,
+				"%s: cmd with tag %d not pending in the device.\n",
 				__func__, tag);
-			if (hba->mcq_enabled) {
-				/* MCQ mode */
-				if (ufshcd_cmd_inflight(lrbp->cmd)) {
-					/* sleep for max. 200us same delay as in SDB mode */
-					usleep_range(100, 200);
-					continue;
-				}
-				/* command completed already */
-				dev_err(hba->dev, "%s: cmd at tag=%d is cleared.\n",
-					__func__, tag);
+			if (!ufshcd_cmd_inflight(lrbp->cmd)) {
+				dev_info(hba->dev,
+					 "%s: cmd with tag=%d completed.\n",
+					 __func__, tag);
 				return 0;
 			}
-
-			/* Single Doorbell Mode */
-			reg = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);
-			if (reg & (1 << tag)) {
-				/* sleep for max. 200us to stabilize */
-				usleep_range(100, 200);
-				continue;
-			}
-			/* command completed already */
-			dev_err(hba->dev, "%s: cmd at tag %d successfully cleared from DB.\n",
-				__func__, tag);
-			return 0;
+			usleep_range(100, 200);
 		} else {
 			dev_err(hba->dev,
 				"%s: no response from device. tag = %d, err %d\n",
author reviewer
#4 lore raw

PATCH v2 4/6 scsi: ufs: core: Simplify ufshcd_exception_event_handler()

In reply to Bart Van Assche

The ufshcd_scsi_block_requests() and ufshcd_scsi_unblock_requests() calls were introduced in ufshcd_exception_event_handler() to prevent that querying the exception event information would time out. Commit 10fe5888a40e ("scsi: ufs: increase the scsi query response timeout") increased the timeout for querying exception information from 30 ms to 1.5 s and thereby eliminated the risk that a timeout would happen. Hence, the calls to block and unblock SCSI requests are superfluous. Remove these calls.

---
 drivers/ufs/core/ufshcd.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/ufs/core/ufshcd.c +1 -4
index 76884df580c3..2fde1b0a6086 100644
@@ -6195,12 +6195,11 @@ static void ufshcd_exception_event_handler(struct work_struct *work)
 	u32 status = 0;
 	hba = container_of(work, struct ufs_hba, eeh_work);
 
-	ufshcd_scsi_block_requests(hba);
 	err = ufshcd_get_ee_status(hba, &status);
 	if (err) {
 		dev_err(hba->dev, "%s: failed to get exception status %d\n",
 				__func__, err);
-		goto out;
+		return;
 	}
 
 	trace_ufshcd_exception_event(dev_name(hba->dev), status);
@@ -6212,8 +6211,6 @@ static void ufshcd_exception_event_handler(struct work_struct *work)
 		ufshcd_temp_exception_event_handler(hba, status);
 
 	ufs_debugfs_exception_event(hba, status);
-out:
-	ufshcd_scsi_unblock_requests(hba);
 }
 
 /* Complete requests that have door-bell cleared */
author reviewer
#5 lore raw

PATCH v2 5/6 scsi: ufs: core: Simplify ufshcd_err_handling_prepare()

In reply to Bart Van Assche

Use blk_mq_quiesce_tagset() instead of ufshcd_scsi_block_requests() and blk_mq_wait_quiesce_done(). Since this patch removes the last callers of ufshcd_scsi_block_requests() and ufshcd_scsi_unblock_requests(), remove these functions.

---
 drivers/ufs/core/ufshcd.c | 19 +++----------------
 include/ufs/ufshcd.h      |  2 --
 2 files changed, 3 insertions(+), 18 deletions(-)
drivers/ufs/core/ufshcd.c +3 -16
index 2fde1b0a6086..e0dba0e3d5b5 100644
@@ -349,18 +349,6 @@ static void ufshcd_configure_wb(struct ufs_hba *hba)
 		ufshcd_wb_toggle_buf_flush(hba, true);
 }
 
-static void ufshcd_scsi_unblock_requests(struct ufs_hba *hba)
-{
-	if (atomic_dec_and_test(&hba->scsi_block_reqs_cnt))
-		scsi_unblock_requests(hba->host);
-}
-
-static void ufshcd_scsi_block_requests(struct ufs_hba *hba)
-{
-	if (atomic_inc_return(&hba->scsi_block_reqs_cnt) == 1)
-		scsi_block_requests(hba->host);
-}
-
 static void ufshcd_add_cmd_upiu_trace(struct ufs_hba *hba, unsigned int tag,
 				      enum ufs_trace_str_t str_t)
 {
@@ -6376,15 +6364,14 @@ static void ufshcd_err_handling_prepare(struct ufs_hba *hba)
 			ufshcd_suspend_clkscaling(hba);
 		ufshcd_clk_scaling_allow(hba, false);
 	}
-	ufshcd_scsi_block_requests(hba);
 	/* Wait for ongoing ufshcd_queuecommand() calls to finish. */
-	blk_mq_wait_quiesce_done(&hba->host->tag_set);
+	blk_mq_quiesce_tagset(&hba->host->tag_set);
 	cancel_work_sync(&hba->eeh_work);
 }
 
 static void ufshcd_err_handling_unprepare(struct ufs_hba *hba)
 {
-	ufshcd_scsi_unblock_requests(hba);
+	blk_mq_unquiesce_tagset(&hba->host->tag_set);
 	ufshcd_release(hba);
 	if (ufshcd_is_clkscaling_supported(hba))
 		ufshcd_clk_scaling_suspend(hba, false);
@@ -10557,7 +10544,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
 
 	/* Hold auto suspend until async scan completes */
 	pm_runtime_get_sync(dev);
-	atomic_set(&hba->scsi_block_reqs_cnt, 0);
+
 	/*
 	 * We are assuming that device wasn't put in sleep/power-down
 	 * state exclusively during the boot stage before kernel.
include/ufs/ufshcd.h +0 -2
index a0b325a32aca..36bd91ff3593 100644
@@ -928,7 +928,6 @@ enum ufshcd_mcq_opr {
  * @wb_mutex: used to serialize devfreq and sysfs write booster toggling
  * @clk_scaling_lock: used to serialize device commands and clock scaling
  * @desc_size: descriptor sizes reported by device
- * @scsi_block_reqs_cnt: reference counting for scsi block requests
  * @bsg_dev: struct device associated with the BSG queue
  * @bsg_queue: BSG queue associated with the UFS controller
  * @rpm_dev_flush_recheck_work: used to suspend from RPM (runtime power
@@ -1089,7 +1088,6 @@ struct ufs_hba {
 
 	struct mutex wb_mutex;
 	struct rw_semaphore clk_scaling_lock;
-	atomic_t scsi_block_reqs_cnt;
 
 	struct device		bsg_dev;
 	struct request_queue	*bsg_queue;
author reviewer
#6 lore raw

PATCH v2 6/6 scsi: ufs: core: Improve ufshcd_mcq_sq_cleanup()

In reply to Bart Van Assche

From the UFSHCI specification: "CleanUp Command Return Code (RTC): host controller sets this return code to provide more details of the cleanup process. It is valid only when CUS is 1." Hence, do not read RTC if the CUS bitfield is zero.

Cc Bao D. Nguyen <[email protected]>
Fixes 8d7290348992 ("scsi: ufs: mcq: Add supporting functions for MCQ abort")
---
 drivers/ufs/core/ufs-mcq.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/ufs/core/ufs-mcq.c +8 -4
index 57ced1729b73..988400500560 100644
@@ -572,14 +572,18 @@ int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag)
 	/* SQRTCy.ICU = 1 */
 	writel(SQ_ICU, opr_sqd_base + REG_SQRTC);
 
-	/* Poll SQRTSy.CUS = 1. Return result from SQRTSy.RTC */
+	/* Wait until SQRTSy.CUS = 1. Report SQRTSy.RTC. */
 	reg = opr_sqd_base + REG_SQRTS;
 	err = read_poll_timeout(readl, val, val & SQ_CUS, 20,
 				MCQ_POLL_US, false, reg);
 	if (err)
-		dev_err(hba->dev, "%s: failed. hwq=%d, tag=%d err=%ld\n",
-			__func__, id, task_tag,
-			FIELD_GET(SQ_ICU_ERR_CODE_MASK, readl(reg)));
+		dev_err(hba->dev, "%s: failed. hwq=%d, tag=%d err=%d\n",
+			__func__, id, task_tag, err);
+	else
+		dev_info(hba->dev,
+			 "%s, hwq %d: cleanup return code (RTC) %ld\n",
+			 __func__, id,
+			 FIELD_GET(SQ_ICU_ERR_CODE_MASK, readl(reg)));
 
 	if (ufshcd_mcq_sq_start(hba, hwq))
 		err = -ETIMEDOUT;
#7 lore raw
In reply to Bart Van Assche

Bart,

Quoted 3 lines

This patch series includes several fixes and cleanup patches for the UFS driver. Please consider this patch series for the next merge window.

Applied to 6.13/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#8 lore raw
In reply to Bart Van Assche
Quoted 8 lines · Bart Van Assche

This patch series includes several fixes and cleanup patches for the UFS driver. Please consider this patch series for the next merge window.

Thanks,

Bart.

[...]

Applied to 6.13/scsi-queue, thanks!

[1/6] scsi: ufs: core: Move the ufshcd_mcq_enable_esi() definition

      https://git.kernel.org/mkp/scsi/c/a085e03758b8
[2/6] scsi: ufs: core: Remove goto statements from ufshcd_try_to_abort_task()
      https://git.kernel.org/mkp/scsi/c/7df89440d0ec
[3/6] scsi: ufs: core: Simplify ufshcd_try_to_abort_task()
      https://git.kernel.org/mkp/scsi/c/9a5f6c09d0fa
[4/6] scsi: ufs: core: Simplify ufshcd_exception_event_handler()
      https://git.kernel.org/mkp/scsi/c/b5d9da58a051
[5/6] scsi: ufs: core: Simplify ufshcd_err_handling_prepare()
      https://git.kernel.org/mkp/scsi/c/2a36646012fc
[6/6] scsi: ufs: core: Improve ufshcd_mcq_sq_cleanup()
      https://git.kernel.org/mkp/scsi/c/2c73fb138da5
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering