Re: [PATCH v4 2/2] ufs: mcq: poll OCS after sq cleanup for device management commands

From: Bart Van Assche

Date: Tue Nov 03 2026 - 20:49:50 EST


On 11/1/26 9:52 PM, Kiwoong Kim wrote:
+static enum utp_ocs ufshcd_mcq_read_ocs(struct ufs_hw_queue *hwq,
+ struct ufshcd_lrb *lrbp)
+{
+ guard(spinlock_irqsave)(&hwq->cq_lock);
+ return READ_ONCE(lrbp->utr_descriptor_ptr->header.ocs);
+}

READ_ONCE() is sufficient. I don't think that the spinlock helps here. Additionally, if the spinlock operations are left out, the function
ufshcd_mcq_read_ocs() is no longer necessary and can be inlined in its
only caller.

+ /*
+ * For device management commands, there is no order guaranteed between
+ * OCS update and CUS update, which is why we need to wait here. SCSI
+ * commands are excluded because the OCS in their UTRD is not updated
+ * from the CQE.
+ */
+ if (!err && blk_mq_is_reserved_rq(rq)) {
+ enum utp_ocs ocs;
+
+ err = read_poll_timeout(ufshcd_mcq_read_ocs, ocs,
+ ocs != OCS_INVALID_COMMAND_STATUS, 20,
+ MCQ_POLL_US, false, hwq, lrbp);
+ }

An error message should be reported if the above loop times out.

Thanks,

Bart.