From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from 003.mia.mailroute.net (003.mia.mailroute.net [199.89.3.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EC012A1BF for ; Wed, 24 Sep 2025 20:33:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.6 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758746015; cv=none; b=bQMI5Rl5F1fTp4+URrDFzqnENSdBi6cRu8od5rsVU8jvQT1OQA0haa6U/mLtGsqzNtEkpQIfsPqrrLKgHKC2G3TNPte/mGuf8iHcXz1FEpfKfEtXKl0ZsfNp+4QDJAK7FALivWe0HfQ6ocbmtUqWuqtpI+o0Uq34Np6+M4gAVyQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758746015; c=relaxed/simple; bh=k0E2CXafVpwyQvBqRUVTrODVN1SQrkApDllCj98VSo4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZON3tCovhKOJvdqCgU6IWm+paZVrDJsGHk5olSk9smbiAn/a9Y12s0GTnKoHBK91Y3BukNNEB4h9fEYLpt75gnlh4yw/r+yH+9jSD0DfBjKdBMimwMdxvgzPwJq2SaMmsQOgmbv/y4SS+a4gb3U0H+VuM4VjgQb25VvcuR7z9G8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=UbP3Gavq; arc=none smtp.client-ip=199.89.3.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="UbP3Gavq" Received: from localhost (localhost [127.0.0.1]) by 003.mia.mailroute.net (Postfix) with ESMTP id 4cX7pj3sxjzlgqxf; Wed, 24 Sep 2025 20:33:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1758746011; x=1761338012; bh=JpDts 1eGr91dTvWwe43Tc++U8r6Ded/p2TBzOjU//NI=; b=UbP3GavqpRr7chQcrXh5u wEuc2i23u1a04htQtZOZDAHuvtBBs0vF7CK8Rza8uJDNv3Dsq5RgZpMloEWH1qpJ PgOizBQu4Z9hgOTI/epIFExU2BjjxEqxNrRUsf7lwkoLc6dWcxa+dLvEH9ztLkHD CFjc91MW+IiEXqlJ6IatHS1KmqvjN+6UkwyDLoeeYyc7rup9oYeiIVD8cJBSGvhl xk73+BjfjvRS0q5N9Enri95RZw6iBbcuhjoNnBxx4BAeh1eCYctdjzTZkRmq7yMI zEsUJJUOJUIZ8ksHp5zgBRbwO7bnH+iH26+oO3c7VGAjBRl+bNgelbTlY1+u+gia w== X-Virus-Scanned: by MailRoute Received: from 003.mia.mailroute.net ([127.0.0.1]) by localhost (003.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id AiogEIKpV4lC; Wed, 24 Sep 2025 20:33:31 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.180.219]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 003.mia.mailroute.net (Postfix) with ESMTPSA id 4cX7pb5GXVzlgqxk; Wed, 24 Sep 2025 20:33:26 +0000 (UTC) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Peter Wang , Avri Altman , Bean Huo Subject: [PATCH v5 15/28] ufs: core: Rework ufshcd_mcq_compl_pending_transfer() Date: Wed, 24 Sep 2025 13:30:34 -0700 Message-ID: <20250924203142.4073403-16-bvanassche@acm.org> X-Mailer: git-send-email 2.51.0.536.g15c5d4f767-goog In-Reply-To: <20250924203142.4073403-1-bvanassche@acm.org> References: <20250924203142.4073403-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Replace a tag loop with blk_mq_tagset_busy_iter(). This patch prepares for removing the hba->lrb[] array. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 80 ++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index ec1c8bdf07e6..eea9e707ab4b 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5717,6 +5717,48 @@ static int ufshcd_poll(struct Scsi_Host *shost, un= signed int queue_num) return completed_reqs !=3D 0; } =20 +static bool ufshcd_mcq_force_compl_one(struct request *rq, void *priv) +{ + struct scsi_cmnd *cmd =3D blk_mq_rq_to_pdu(rq); + struct scsi_device *sdev =3D rq->q->queuedata; + struct Scsi_Host *shost =3D sdev->host; + struct ufs_hba *hba =3D shost_priv(shost); + struct ufshcd_lrb *lrbp =3D &hba->lrb[rq->tag]; + struct ufs_hw_queue *hwq =3D ufshcd_mcq_req_to_hwq(hba, rq); + + if (!hwq) + return true; + + ufshcd_mcq_compl_all_cqes_lock(hba, hwq); + + /* + * For those cmds of which the cqes are not present in the cq, complete + * them explicitly. + */ + scoped_guard(spinlock_irqsave, &hwq->cq_lock) { + if (!test_bit(SCMD_STATE_COMPLETE, &cmd->state)) { + set_host_byte(cmd, DID_REQUEUE); + ufshcd_release_scsi_cmd(hba, lrbp); + scsi_done(cmd); + } + } + + return true; +} + +static bool ufshcd_mcq_compl_one(struct request *rq, void *priv) +{ + struct scsi_device *sdev =3D rq->q->queuedata; + struct Scsi_Host *shost =3D sdev->host; + struct ufs_hba *hba =3D shost_priv(shost); + struct ufs_hw_queue *hwq =3D ufshcd_mcq_req_to_hwq(hba, rq); + + if (hwq) + ufshcd_mcq_poll_cqe_lock(hba, hwq); + + return true; +} + /** * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is * invoked from the error handler context or ufshcd_host_reset_and_resto= re() @@ -5731,40 +5773,10 @@ static int ufshcd_poll(struct Scsi_Host *shost, u= nsigned int queue_num) static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba, bool force_compl) { - struct ufs_hw_queue *hwq; - struct ufshcd_lrb *lrbp; - struct scsi_cmnd *cmd; - unsigned long flags; - int tag; - - for (tag =3D 0; tag < hba->nutrs; tag++) { - lrbp =3D &hba->lrb[tag]; - cmd =3D lrbp->cmd; - if (!ufshcd_cmd_inflight(cmd) || - test_bit(SCMD_STATE_COMPLETE, &cmd->state)) - continue; - - hwq =3D ufshcd_mcq_req_to_hwq(hba, scsi_cmd_to_rq(cmd)); - if (!hwq) - continue; - - if (force_compl) { - ufshcd_mcq_compl_all_cqes_lock(hba, hwq); - /* - * For those cmds of which the cqes are not present - * in the cq, complete them explicitly. - */ - spin_lock_irqsave(&hwq->cq_lock, flags); - if (cmd && !test_bit(SCMD_STATE_COMPLETE, &cmd->state)) { - set_host_byte(cmd, DID_REQUEUE); - ufshcd_release_scsi_cmd(hba, lrbp); - scsi_done(cmd); - } - spin_unlock_irqrestore(&hwq->cq_lock, flags); - } else { - ufshcd_mcq_poll_cqe_lock(hba, hwq); - } - } + blk_mq_tagset_busy_iter(&hba->host->tag_set, + force_compl ? ufshcd_mcq_force_compl_one : + ufshcd_mcq_compl_one, + NULL); } =20 /**