mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Can Guo <quic_cang@quicinc.com>
To: bvanassche@acm.org, stanley.chu@mediatek.com,
	adrian.hunter@intel.com, alim.akhtar@samsung.com,
	avri.altman@wdc.com, beanhuo@micron.com,
	quic_asutoshd@quicinc.com, quic_nguyenb@quicinc.com,
	quic_ziqichen@quicinc.com, linux-scsi@vger.kernel.org,
	kernel-team@android.com, quic_cang@quicinc.com
Cc: Andy Gross <agross@kernel.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-arm-msm@vger.kernel.org (open list:ARM/QUALCOMM SUPPORT),
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH 2/2] scsi: ufs-qcom: Implement three CMQ related vops
Date: Tue, 19 Jul 2022 00:01:59 -0700	[thread overview]
Message-ID: <1658214120-22772-3-git-send-email-quic_cang@quicinc.com> (raw)
In-Reply-To: <1658214120-22772-1-git-send-email-quic_cang@quicinc.com>

Read MCQ_CQIS_VS to figure out the outstanding CQs for legacy ISR.
Configure the MCQ Runtime Operation Pointers.
Implement the MCQ ESI handler.

Co-developed-by: Asutosh Das <quic_asutoshd@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
---
 drivers/ufs/host/ufs-qcom.c | 116 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/ufs/host/ufs-qcom.h |   2 +
 2 files changed, 118 insertions(+)

diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index 473fad8..7a9e023 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -1424,6 +1424,119 @@ static void ufs_qcom_config_scaling_param(struct ufs_hba *hba,
 }
 #endif
 
+static int ufs_qcom_get_outstanding_cqs(struct ufs_hba *hba,
+					unsigned long *ocqs)
+{
+	return -EINVAL;
+}
+
+static int ufs_qcom_config_mcq_rop(struct ufs_hba *hba)
+{
+	struct ufshcd_mcq_rop_info_t *rop;
+	struct ufshcd_res_info_t *mem_res, *sqdao_res;
+	int i;
+
+	mem_res = &hba->res[RES_MEM];
+	sqdao_res = &hba->res[RES_MCQ_SQD];
+
+	if (!mem_res->base || !sqdao_res->base)
+		return -EINVAL;
+
+	for(i = 0; i < ROP_MAX; i++) {
+		rop = &hba->mcq_rop[i];
+		rop->offset = sqdao_res->resource->start -
+			      mem_res->resource->start + 0x40 * i;
+		rop->stride = 0x100;
+		rop->base = sqdao_res->base + 0x40 * i;
+	}
+
+	return 0;
+}
+
+#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
+static void ufs_qcom_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg)
+{
+	struct device *dev = msi_desc_to_dev(desc);
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	ufshcd_mcq_config_esi(hba, msg);
+}
+
+static irqreturn_t ufs_qcom_mcq_esi_handler(int irq, void *__hba)
+{
+	struct ufs_hba *hba = __hba;
+	struct ufs_qcom_host *host = ufshcd_get_variant(hba);
+	u32 event_id = irq - host->esi_base;
+	struct ufs_hw_queue *hwq = &hba->uhq[event_id];
+
+	ufshcd_mcq_poll_cqe_nolock(hba, hwq);
+
+	return IRQ_HANDLED;
+}
+
+static int ufs_qcom_config_mcq_esi(struct ufs_hba *hba)
+{
+	struct ufs_qcom_host *host = ufshcd_get_variant(hba);
+	struct msi_desc *desc;
+	struct msi_desc *failed_desc = NULL;
+	u32 reg;
+	int nr_irqs, ret;
+
+	/*
+	 * 1. We only handle CQs as of now.
+	 * 2. Poll queues do not need ESI.
+	 */
+	nr_irqs = hba->nr_hw_queues - hba->nr_queues[HCTX_TYPE_POLL];
+	ret = platform_msi_domain_alloc_irqs(hba->dev, nr_irqs,
+					     ufs_qcom_write_msi_msg);
+	if (ret)
+		goto out;
+
+	msi_for_each_desc(desc, hba->dev, MSI_DESC_ALL) {
+		if (!desc->msi_index)
+			host->esi_base = desc->irq;
+
+		ret = devm_request_irq(hba->dev, desc->irq,
+				       ufs_qcom_mcq_esi_handler,
+				       0, "qcom-mcq-esi", hba);
+		if (ret) {
+			dev_err(hba->dev, "%s: Fail to request IRQ for %d, err = %d\n",
+				__func__, desc->irq, ret);
+			failed_desc = desc;
+			break;
+		}
+	}
+
+	if (ret) {
+		/* Rewind */
+		msi_for_each_desc(desc, hba->dev, MSI_DESC_ALL) {
+			if (desc == failed_desc)
+				break;
+			devm_free_irq(hba->dev, desc->irq, hba);
+		}
+	} else {
+		if (host->hw_ver.major == 6 && host->hw_ver.minor == 0 &&
+		    host->hw_ver.step == 0) {
+			reg = ufshcd_readl(hba, REG_UFS_CFG3);
+			reg |= 0x1F000;
+			ufshcd_writel(hba, reg, REG_UFS_CFG3);
+		}
+		ufshcd_mcq_enable_esi(hba);
+	}
+
+out:
+	if (ret)
+		dev_warn(hba->dev, "Failed to request Platform MSI %d\n", ret);
+	return ret;
+}
+
+#else
+static int ufs_qcom_config_mcq_esi(struct ufs_hba *hba)
+{
+	return -EINVAL;
+}
+#endif
+
 /*
  * struct ufs_hba_qcom_vops - UFS QCOM specific variant operations
  *
@@ -1447,6 +1560,9 @@ static const struct ufs_hba_variant_ops ufs_hba_qcom_vops = {
 	.device_reset		= ufs_qcom_device_reset,
 	.config_scaling_param = ufs_qcom_config_scaling_param,
 	.program_key		= ufs_qcom_ice_program_key,
+	.get_outstanding_cqs	= ufs_qcom_get_outstanding_cqs,
+	.config_mcq_rop		= ufs_qcom_config_mcq_rop,
+	.config_mcq_esi		= ufs_qcom_config_mcq_esi,
 };
 
 /**
diff --git a/drivers/ufs/host/ufs-qcom.h b/drivers/ufs/host/ufs-qcom.h
index 44466a3..f6f06b2 100644
--- a/drivers/ufs/host/ufs-qcom.h
+++ b/drivers/ufs/host/ufs-qcom.h
@@ -53,6 +53,7 @@ enum {
 	 * added in HW Version 3.0.0
 	 */
 	UFS_AH8_CFG				= 0xFC,
+	REG_UFS_CFG3				= 0x271C,
 };
 
 /* QCOM UFS host controller vendor specific debug registers */
@@ -221,6 +222,7 @@ struct ufs_qcom_host {
 	struct reset_controller_dev rcdev;
 
 	struct gpio_desc *device_reset;
+	int esi_base;
 };
 
 static inline u32
-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.


      parent reply	other threads:[~2022-07-19  7:02 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1658214120-22772-1-git-send-email-quic_cang@quicinc.com>
2022-07-19  7:01 ` [PATCH 1/2] scsi: ufs: Add Multi-Circular Queue support Can Guo
2022-07-19 23:01   ` Bart Van Assche
2022-07-19 23:07   ` Bart Van Assche
2022-07-20 17:34     ` Asutosh Das (asd)
2022-07-20  7:57   ` kernel test robot
2022-07-20 11:41   ` kernel test robot
2022-07-20 16:36   ` kernel test robot
2022-07-22  7:31   ` Avri Altman
2022-07-22 17:35     ` Asutosh Das (asd)
2022-07-22 19:37       ` Avri Altman
2022-07-22 20:14         ` Asutosh Das (asd)
2022-07-22 20:22           ` Avri Altman
2022-07-22 21:05             ` Asutosh Das (asd)
2022-07-22 17:58     ` Bart Van Assche
2022-07-26  6:48       ` Can Guo
2022-07-22 14:42   ` Avri Altman
2022-07-23 14:59   ` Avri Altman
2022-07-26  2:55     ` Can Guo
2022-07-23 15:26   ` Avri Altman
2022-07-24  3:14     ` Bart Van Assche
2022-07-25 16:24     ` Asutosh Das (asd)
2022-07-23 20:22   ` Avri Altman
2022-07-25 16:26     ` Asutosh Das (asd)
2022-07-25 19:50       ` Avri Altman
2022-07-25 20:24         ` Asutosh Das (asd)
2022-07-23 21:23   ` Avri Altman
2022-07-24  3:15     ` Bart Van Assche
2022-07-25 16:35     ` Asutosh Das (asd)
2022-07-26 22:47       ` Bart Van Assche
2022-07-24  4:07   ` Avri Altman
2022-07-25 16:38     ` Asutosh Das (asd)
2022-07-26  6:35     ` Can Guo
2022-07-26  9:46       ` Avri Altman
2022-07-24  4:32   ` Avri Altman
2022-07-26  6:21     ` Can Guo
2022-07-24  7:21   ` Avri Altman
2022-07-24 21:54   ` Bean Huo
2022-07-25 17:35     ` Asutosh Das (asd)
2022-07-25  9:16   ` Dan Carpenter
2022-07-28 19:10   ` John Garry
2022-07-28 19:15     ` Asutosh Das (asd)
2022-07-28 20:29       ` Bart Van Assche
2022-07-28 21:07         ` Asutosh Das (asd)
2022-07-29 16:43           ` Asutosh Das (asd)
2022-07-29 18:59             ` Bart Van Assche
2022-07-28 19:38   ` Bart Van Assche
2022-07-28 20:00     ` Asutosh Das (asd)
2022-07-19  7:01 ` Can Guo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1658214120-22772-3-git-send-email-quic_cang@quicinc.com \
    --to=quic_cang@quicinc.com \
    --cc=adrian.hunter@intel.com \
    --cc=agross@kernel.org \
    --cc=alim.akhtar@samsung.com \
    --cc=avri.altman@wdc.com \
    --cc=beanhuo@micron.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=bvanassche@acm.org \
    --cc=jejb@linux.ibm.com \
    --cc=kernel-team@android.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=quic_asutoshd@quicinc.com \
    --cc=quic_nguyenb@quicinc.com \
    --cc=quic_ziqichen@quicinc.com \
    --cc=stanley.chu@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®