Skip to content

Commit 4b42d55

Browse files
Can Guomartinkpetersen
authored andcommitted
scsi: ufs: core: Fix wrong Task Tag used in task management request UPIUs
In __ufshcd_issue_tm_cmd(), it is not correct to use hba->nutrs + req->tag as the Task Tag in a TMR UPIU. Directly use req->tag as the Task Tag. Fixes: e293313 ("scsi: ufs: Fix broken task management command implementation") Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Can Guo <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 1235fc5 commit 4b42d55

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

drivers/scsi/ufs/ufshcd.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6386,38 +6386,34 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba,
63866386
DECLARE_COMPLETION_ONSTACK(wait);
63876387
struct request *req;
63886388
unsigned long flags;
6389-
int free_slot, task_tag, err;
6389+
int task_tag, err;
63906390

63916391
/*
6392-
* Get free slot, sleep if slots are unavailable.
6393-
* Even though we use wait_event() which sleeps indefinitely,
6394-
* the maximum wait time is bounded by %TM_CMD_TIMEOUT.
6392+
* blk_get_request() is used here only to get a free tag.
63956393
*/
63966394
req = blk_get_request(q, REQ_OP_DRV_OUT, 0);
63976395
if (IS_ERR(req))
63986396
return PTR_ERR(req);
63996397

64006398
req->end_io_data = &wait;
6401-
free_slot = req->tag;
6402-
WARN_ON_ONCE(free_slot < 0 || free_slot >= hba->nutmrs);
64036399
ufshcd_hold(hba, false);
64046400

64056401
spin_lock_irqsave(host->host_lock, flags);
6406-
task_tag = hba->nutrs + free_slot;
64076402
blk_mq_start_request(req);
64086403

6404+
task_tag = req->tag;
64096405
treq->req_header.dword_0 |= cpu_to_be32(task_tag);
64106406

6411-
memcpy(hba->utmrdl_base_addr + free_slot, treq, sizeof(*treq));
6412-
ufshcd_vops_setup_task_mgmt(hba, free_slot, tm_function);
6407+
memcpy(hba->utmrdl_base_addr + task_tag, treq, sizeof(*treq));
6408+
ufshcd_vops_setup_task_mgmt(hba, task_tag, tm_function);
64136409

64146410
/* send command to the controller */
6415-
__set_bit(free_slot, &hba->outstanding_tasks);
6411+
__set_bit(task_tag, &hba->outstanding_tasks);
64166412

64176413
/* Make sure descriptors are ready before ringing the task doorbell */
64186414
wmb();
64196415

6420-
ufshcd_writel(hba, 1 << free_slot, REG_UTP_TASK_REQ_DOOR_BELL);
6416+
ufshcd_writel(hba, 1 << task_tag, REG_UTP_TASK_REQ_DOOR_BELL);
64216417
/* Make sure that doorbell is committed immediately */
64226418
wmb();
64236419

@@ -6437,24 +6433,24 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba,
64376433
ufshcd_add_tm_upiu_trace(hba, task_tag, UFS_TM_ERR);
64386434
dev_err(hba->dev, "%s: task management cmd 0x%.2x timed-out\n",
64396435
__func__, tm_function);
6440-
if (ufshcd_clear_tm_cmd(hba, free_slot))
6441-
dev_WARN(hba->dev, "%s: unable clear tm cmd (slot %d) after timeout\n",
6442-
__func__, free_slot);
6436+
if (ufshcd_clear_tm_cmd(hba, task_tag))
6437+
dev_WARN(hba->dev, "%s: unable to clear tm cmd (slot %d) after timeout\n",
6438+
__func__, task_tag);
64436439
err = -ETIMEDOUT;
64446440
} else {
64456441
err = 0;
6446-
memcpy(treq, hba->utmrdl_base_addr + free_slot, sizeof(*treq));
6442+
memcpy(treq, hba->utmrdl_base_addr + task_tag, sizeof(*treq));
64476443

64486444
ufshcd_add_tm_upiu_trace(hba, task_tag, UFS_TM_COMP);
64496445
}
64506446

64516447
spin_lock_irqsave(hba->host->host_lock, flags);
6452-
__clear_bit(free_slot, &hba->outstanding_tasks);
6448+
__clear_bit(task_tag, &hba->outstanding_tasks);
64536449
spin_unlock_irqrestore(hba->host->host_lock, flags);
64546450

6451+
ufshcd_release(hba);
64556452
blk_put_request(req);
64566453

6457-
ufshcd_release(hba);
64586454
return err;
64596455
}
64606456

0 commit comments

Comments
 (0)