Skip to content

Commit ee8c88c

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: ufs: core: Fix the polling implementation
Fix the following issues in ufshcd_poll(): - If polling succeeds, return a positive value. - Do not complete polling requests from interrupt context because the block layer expects these requests to be completed from thread context. From block/bio.c: If REQ_ALLOC_CACHE is set, the final put of the bio MUST be done from process context, not hard/soft IRQ. Fixes: eaab9b5 ("scsi: ufs: Implement polling support") Signed-off-by: Bart Van Assche <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Adrian Hunter <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 4d450cf commit ee8c88c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

drivers/ufs/core/ufshcd.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5344,6 +5344,26 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba,
53445344
}
53455345
}
53465346

5347+
/* Any value that is not an existing queue number is fine for this constant. */
5348+
enum {
5349+
UFSHCD_POLL_FROM_INTERRUPT_CONTEXT = -1
5350+
};
5351+
5352+
static void ufshcd_clear_polled(struct ufs_hba *hba,
5353+
unsigned long *completed_reqs)
5354+
{
5355+
int tag;
5356+
5357+
for_each_set_bit(tag, completed_reqs, hba->nutrs) {
5358+
struct scsi_cmnd *cmd = hba->lrb[tag].cmd;
5359+
5360+
if (!cmd)
5361+
continue;
5362+
if (scsi_cmd_to_rq(cmd)->cmd_flags & REQ_POLLED)
5363+
__clear_bit(tag, completed_reqs);
5364+
}
5365+
}
5366+
53475367
/*
53485368
* Returns > 0 if one or more commands have been completed or 0 if no
53495369
* requests have been completed.
@@ -5360,13 +5380,17 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)
53605380
WARN_ONCE(completed_reqs & ~hba->outstanding_reqs,
53615381
"completed: %#lx; outstanding: %#lx\n", completed_reqs,
53625382
hba->outstanding_reqs);
5383+
if (queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT) {
5384+
/* Do not complete polled requests from interrupt context. */
5385+
ufshcd_clear_polled(hba, &completed_reqs);
5386+
}
53635387
hba->outstanding_reqs &= ~completed_reqs;
53645388
spin_unlock_irqrestore(&hba->outstanding_lock, flags);
53655389

53665390
if (completed_reqs)
53675391
__ufshcd_transfer_req_compl(hba, completed_reqs);
53685392

5369-
return completed_reqs;
5393+
return completed_reqs != 0;
53705394
}
53715395

53725396
/**
@@ -5397,7 +5421,7 @@ static irqreturn_t ufshcd_transfer_req_compl(struct ufs_hba *hba)
53975421
* Ignore the ufshcd_poll() return value and return IRQ_HANDLED since we
53985422
* do not want polling to trigger spurious interrupt complaints.
53995423
*/
5400-
ufshcd_poll(hba->host, 0);
5424+
ufshcd_poll(hba->host, UFSHCD_POLL_FROM_INTERRUPT_CONTEXT);
54015425

54025426
return IRQ_HANDLED;
54035427
}

0 commit comments

Comments
 (0)