mirror of
https://github.com/hardkernel/linux.git
synced 2026-03-25 03:50:24 +09:00
BACKPORT: FROMLIST: scsi: ufs: Make the polling code report which command has been completed
Prepare for introducing a new __ufshcd_poll() caller that will need to know whether or not a specific command has been completed. Bug: 312786487 Bug: 326329246 Bug: 333069246 Bug: 333317508 Link: https://lore.kernel.org/linux-scsi/20240416171357.1062583-1-bvanassche@acm.org/T/#m68901e4f4e2437e7d0cb747049006ab19f57e038 Change-Id: I1b25b095b4bf9fbf175aa963ec85fcbbcb2be0ed Signed-off-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Bart Van Assche <bvanassche@google.com>
This commit is contained in:
committed by
Bart Van Assche
parent
0fcd7a1c7c
commit
8563ce5895
@@ -268,23 +268,29 @@ static int ufshcd_mcq_get_tag(struct ufs_hba *hba,
|
||||
return div_u64(addr, sizeof(struct utp_transfer_cmd_desc));
|
||||
}
|
||||
|
||||
static void ufshcd_mcq_process_cqe(struct ufs_hba *hba,
|
||||
struct ufs_hw_queue *hwq)
|
||||
/* Returns true if and only if @compl_cmd has been completed. */
|
||||
static bool ufshcd_mcq_process_cqe(struct ufs_hba *hba,
|
||||
struct ufs_hw_queue *hwq,
|
||||
struct scsi_cmnd *compl_cmd)
|
||||
{
|
||||
struct cq_entry *cqe = ufshcd_mcq_cur_cqe(hwq);
|
||||
int tag = ufshcd_mcq_get_tag(hba, hwq, cqe);
|
||||
|
||||
ufshcd_compl_one_cqe(hba, tag, cqe);
|
||||
return ufshcd_compl_one_cqe(hba, tag, cqe, compl_cmd);
|
||||
}
|
||||
|
||||
/* Clears *@compl_cmd if and only if *@compl_cmd has been completed. */
|
||||
unsigned long ufshcd_mcq_poll_cqe_nolock(struct ufs_hba *hba,
|
||||
struct ufs_hw_queue *hwq)
|
||||
struct ufs_hw_queue *hwq,
|
||||
struct scsi_cmnd **compl_cmd)
|
||||
{
|
||||
unsigned long completed_reqs = 0;
|
||||
|
||||
ufshcd_mcq_update_cq_tail_slot(hwq);
|
||||
while (!ufshcd_mcq_is_cq_empty(hwq)) {
|
||||
ufshcd_mcq_process_cqe(hba, hwq);
|
||||
if (ufshcd_mcq_process_cqe(hba, hwq,
|
||||
compl_cmd ? *compl_cmd : NULL))
|
||||
*compl_cmd = NULL;
|
||||
ufshcd_mcq_inc_cq_head_slot(hwq);
|
||||
completed_reqs++;
|
||||
}
|
||||
@@ -295,13 +301,15 @@ unsigned long ufshcd_mcq_poll_cqe_nolock(struct ufs_hba *hba,
|
||||
return completed_reqs;
|
||||
}
|
||||
|
||||
/* Clears *@compl_cmd if and only if *@compl_cmd has been completed. */
|
||||
unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba,
|
||||
struct ufs_hw_queue *hwq)
|
||||
struct ufs_hw_queue *hwq,
|
||||
struct scsi_cmnd **compl_cmd)
|
||||
{
|
||||
unsigned long completed_reqs, flags;
|
||||
|
||||
spin_lock_irqsave(&hwq->cq_lock, flags);
|
||||
completed_reqs = ufshcd_mcq_poll_cqe_nolock(hba, hwq);
|
||||
completed_reqs = ufshcd_mcq_poll_cqe_nolock(hba, hwq, compl_cmd);
|
||||
spin_unlock_irqrestore(&hwq->cq_lock, flags);
|
||||
|
||||
return completed_reqs;
|
||||
|
||||
@@ -56,8 +56,8 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
|
||||
int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
|
||||
enum flag_idn idn, u8 index, bool *flag_res);
|
||||
void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);
|
||||
void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,
|
||||
struct cq_entry *cqe);
|
||||
bool ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,
|
||||
struct cq_entry *cqe, struct scsi_cmnd *compl_cmd);
|
||||
int ufshcd_mcq_init(struct ufs_hba *hba);
|
||||
int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba);
|
||||
int ufshcd_mcq_memory_alloc(struct ufs_hba *hba);
|
||||
@@ -67,11 +67,13 @@ void ufshcd_mcq_select_mcq_mode(struct ufs_hba *hba);
|
||||
u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i);
|
||||
void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i);
|
||||
unsigned long ufshcd_mcq_poll_cqe_nolock(struct ufs_hba *hba,
|
||||
struct ufs_hw_queue *hwq);
|
||||
struct ufs_hw_queue *hwq,
|
||||
struct scsi_cmnd **compl_cmd);
|
||||
struct ufs_hw_queue *ufshcd_mcq_req_to_hwq(struct ufs_hba *hba,
|
||||
struct request *req);
|
||||
unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba,
|
||||
struct ufs_hw_queue *hwq);
|
||||
struct ufs_hw_queue *hwq,
|
||||
struct scsi_cmnd **compl_cmd);
|
||||
|
||||
#define UFSHCD_MCQ_IO_QUEUE_OFFSET 1
|
||||
#define SD_ASCII_STD true
|
||||
|
||||
@@ -5463,9 +5463,12 @@ static void ufshcd_release_scsi_cmd(struct ufs_hba *hba,
|
||||
* @hba: per adapter instance
|
||||
* @task_tag: the task tag of the request to be completed
|
||||
* @cqe: pointer to the completion queue entry
|
||||
* @compl_cmd: if not NULL, check whether this command has been completed
|
||||
*
|
||||
* Returns: true if and only if @compl_cmd has been completed.
|
||||
*/
|
||||
void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,
|
||||
struct cq_entry *cqe)
|
||||
bool ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,
|
||||
struct cq_entry *cqe, struct scsi_cmnd *compl_cmd)
|
||||
{
|
||||
struct ufshcd_lrb *lrbp;
|
||||
struct scsi_cmnd *cmd;
|
||||
@@ -5482,6 +5485,7 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,
|
||||
ufshcd_release_scsi_cmd(hba, lrbp);
|
||||
/* Do not touch lrbp after scsi done */
|
||||
cmd->scsi_done(cmd);
|
||||
return cmd == compl_cmd;
|
||||
} else if (lrbp->command_type == UTP_CMD_TYPE_DEV_MANAGE ||
|
||||
lrbp->command_type == UTP_CMD_TYPE_UFS_STORAGE) {
|
||||
if (hba->dev_cmd.complete) {
|
||||
@@ -5492,20 +5496,26 @@ void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,
|
||||
ufshcd_clk_scaling_update_busy(hba);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* __ufshcd_transfer_req_compl - handle SCSI and query command completion
|
||||
* @hba: per adapter instance
|
||||
* @completed_reqs: bitmask that indicates which requests to complete
|
||||
* @compl_cmd: if not NULL, check whether *@compl_cmd has been completed.
|
||||
* Clear *@compl_cmd if it has been completed.
|
||||
*/
|
||||
static void __ufshcd_transfer_req_compl(struct ufs_hba *hba,
|
||||
unsigned long completed_reqs)
|
||||
unsigned long completed_reqs,
|
||||
struct scsi_cmnd **compl_cmd)
|
||||
{
|
||||
int tag;
|
||||
|
||||
for_each_set_bit(tag, &completed_reqs, hba->nutrs)
|
||||
ufshcd_compl_one_cqe(hba, tag, NULL);
|
||||
if (ufshcd_compl_one_cqe(hba, tag, NULL,
|
||||
compl_cmd ? *compl_cmd : NULL))
|
||||
*compl_cmd = NULL;
|
||||
}
|
||||
|
||||
/* Any value that is not an existing queue number is fine for this constant. */
|
||||
@@ -5532,7 +5542,8 @@ static void ufshcd_clear_polled(struct ufs_hba *hba,
|
||||
* Returns > 0 if one or more commands have been completed or 0 if no
|
||||
* requests have been completed.
|
||||
*/
|
||||
static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)
|
||||
static int __ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num,
|
||||
struct scsi_cmnd **compl_cmd)
|
||||
{
|
||||
struct ufs_hba *hba = shost_priv(shost);
|
||||
unsigned long completed_reqs, flags;
|
||||
@@ -5543,7 +5554,7 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)
|
||||
WARN_ON_ONCE(queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT);
|
||||
hwq = &hba->uhq[queue_num + UFSHCD_MCQ_IO_QUEUE_OFFSET];
|
||||
|
||||
return ufshcd_mcq_poll_cqe_lock(hba, hwq);
|
||||
return ufshcd_mcq_poll_cqe_lock(hba, hwq, compl_cmd);
|
||||
}
|
||||
|
||||
spin_lock_irqsave(&hba->outstanding_lock, flags);
|
||||
@@ -5560,11 +5571,16 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)
|
||||
spin_unlock_irqrestore(&hba->outstanding_lock, flags);
|
||||
|
||||
if (completed_reqs)
|
||||
__ufshcd_transfer_req_compl(hba, completed_reqs);
|
||||
__ufshcd_transfer_req_compl(hba, completed_reqs, compl_cmd);
|
||||
|
||||
return completed_reqs != 0;
|
||||
}
|
||||
|
||||
static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)
|
||||
{
|
||||
return __ufshcd_poll(shost, queue_num, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* ufshcd_transfer_req_compl - handle SCSI and query command completion
|
||||
* @hba: per adapter instance
|
||||
@@ -6820,7 +6836,7 @@ static irqreturn_t ufshcd_handle_mcq_cq_events(struct ufs_hba *hba)
|
||||
ufshcd_mcq_write_cqis(hba, events, i);
|
||||
|
||||
if (events & UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS)
|
||||
ufshcd_mcq_poll_cqe_nolock(hba, hwq);
|
||||
ufshcd_mcq_poll_cqe_nolock(hba, hwq, NULL);
|
||||
}
|
||||
|
||||
return IRQ_HANDLED;
|
||||
@@ -7361,7 +7377,7 @@ static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd)
|
||||
dev_err(hba->dev, "%s: failed to clear requests %#lx\n",
|
||||
__func__, not_cleared);
|
||||
}
|
||||
__ufshcd_transfer_req_compl(hba, pending_reqs & ~not_cleared);
|
||||
__ufshcd_transfer_req_compl(hba, pending_reqs & ~not_cleared, NULL);
|
||||
|
||||
out:
|
||||
hba->req_abort_count = 0;
|
||||
@@ -7522,7 +7538,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)
|
||||
dev_err(hba->dev,
|
||||
"%s: cmd was completed, but without a notifying intr, tag = %d",
|
||||
__func__, tag);
|
||||
__ufshcd_transfer_req_compl(hba, 1UL << tag);
|
||||
__ufshcd_transfer_req_compl(hba, 1UL << tag, NULL);
|
||||
goto release;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user