Add support for UFS Event Specific Interrupt
Subsystems (4)
v2 cover Add support for UFS Event Specific Interrupt
UFS Multi-Circular Queue (MCQ) driver is on the way. This patch series is to enable Event Specific Interrupt (ESI), which can used in MCQ mode.
Please note that this series is developed and tested based on the latest MCQ driver (v11) pushed by Asutosh Das.
v1 -> v2:
- Improved QCOM specific ESI configuration flow
Can Guo (3):
ufs: core: Add Event Specific Interrupt configuration vendor specific
ops
ufs: core: mcq: Add Event Specific Interrupt enable and config APIs
ufs-host: qcom: Add MCQ ESI config vendor specific ops
drivers/ufs/core/ufs-mcq.c | 16 +++++++ drivers/ufs/core/ufshcd-priv.h | 8 ++++ drivers/ufs/core/ufshcd.c | 5 +++ drivers/ufs/host/ufs-qcom.c | 97 ++++++++++++++++++++++++++++++++++++++++++ drivers/ufs/host/ufs-qcom.h | 5 +++ include/ufs/ufshcd.h | 8 ++++ include/ufs/ufshci.h | 2 + 7 files changed, 141 insertions(+)
Signature · 1 line
2.7.4
PATCH v2 1/3 ufs: core: Add Event Specific Interrupt configuration vendor specific ops
As Event Specific Interrupt message format is not defined in UFSHCI JEDEC specs, and the ESI handling highly depends on how the format is designed, hence add a vendor specific ops such that SoC vendors can configure their own ESI handlers. If ESI vops is not provided or returning error, go with the legacy (central) interrupt way.
--- drivers/ufs/core/ufshcd-priv.h | 8 ++++++++ drivers/ufs/core/ufshcd.c | 5 +++++ include/ufs/ufshcd.h | 2 ++ 3 files changed, 15 insertions(+)
drivers/ufs/core/ufshcd-priv.h +8 -0
@@ -276,6 +276,14 @@ static inline int ufshcd_vops_get_outstanding_cqs(struct ufs_hba *hba,return -EOPNOTSUPP ; } +static inline int ufshcd_mcq_vops_config_esi (struct ufs_hba *hba) +{ +if (hba->vops && hba->vops->config_esi) +return hba->vops->config_esi (hba); + +return -EOPNOTSUPP ; +} +extern const struct ufs_pm_lvl_states ufs_pm_lvl_states[];/**
drivers/ufs/core/ufshcd.c +5 -0
@@ -8375,6 +8375,11 @@ static int ufshcd_alloc_mcq(struct ufs_hba *hba)static void ufshcd_config_mcq (struct ufs_hba *hba) { +int ret; + + ret =ufshcd_mcq_vops_config_esi (hba); +dev_info (hba->dev,"ESI %sconfigured\n" , ret ?"is not " :"" ); +ufshcd_enable_intr (hba,UFSHCD_ENABLE_MCQ_INTRS );ufshcd_mcq_make_queues_operational (hba);ufshcd_mcq_config_mac (hba, hba->nutrs);
include/ufs/ufshcd.h +2 -0
@@ -302,6 +302,7 @@ struct ufs_pwr_mode_info {* @get_hba_mac: called to get vendor specific mac value, mandatory for mcq mode * @op_runtime_config: called to config Operation and runtime regs Pointers * @get_outstanding_cqs: called to get outstanding completion queues +* @config_esi: called to config Event Specific Interrupt */ struct ufs_hba_variant_ops {const char *name;
@@ -345,6 +346,7 @@ struct ufs_hba_variant_ops {int (*op_runtime_config)(struct ufs_hba *hba);int (*get_outstanding_cqs)(struct ufs_hba *hba,unsigned long *ocqs); +int (*config_esi)(struct ufs_hba *hba); };/* clock gating state */
Signature · 1 line
2.7.4
PATCH v2 2/3 ufs: core: mcq: Add Event Specific Interrupt enable and config APIs
In reply to Can GuoAdd two APIs to enable ESI and config ESI base addresses.
--- drivers/ufs/core/ufs-mcq.c | 16 ++++++++++++++++ include/ufs/ufshcd.h | 6 ++++++ include/ufs/ufshci.h | 2 ++ 3 files changed, 24 insertions(+)
drivers/ufs/core/ufs-mcq.c +16 -0
@@ -246,6 +246,7 @@ void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i) {writel (val,mcq_opr_base (hba,OPR_CQIS , i) +REG_CQIS ); } +EXPORT_SYMBOL_GPL (ufshcd_mcq_write_cqis);/* * Current MCQ specification doesn't provide a Task Tag or its equivalent in
@@ -293,6 +294,7 @@ unsigned long ufshcd_mcq_poll_cqe_nolock(struct ufs_hba *hba,return completed_reqs; } +EXPORT_SYMBOL_GPL (ufshcd_mcq_poll_cqe_nolock);unsigned long ufshcd_mcq_poll_cqe_lock (struct ufs_hba *hba,struct ufs_hw_queue *hwq)
@@ -370,6 +372,20 @@ void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba) } } +void ufshcd_mcq_enable_esi (struct ufs_hba *hba) +{ +ufshcd_writel (hba,ufshcd_readl (hba,REG_UFS_MEM_CFG ) |0x2 , +REG_UFS_MEM_CFG ); +} +EXPORT_SYMBOL_GPL (ufshcd_mcq_enable_esi); + +void ufshcd_mcq_config_esi (struct ufs_hba *hba,struct msi_msg *msg) +{ +ufshcd_writel (hba, msg->address_lo,REG_UFS_ESILBA ); +ufshcd_writel (hba, msg->address_hi,REG_UFS_ESIUBA ); +} +EXPORT_SYMBOL_GPL (ufshcd_mcq_config_esi); +int ufshcd_mcq_init (struct ufs_hba *hba) {struct Scsi_Host *host = hba->host;
include/ufs/ufshcd.h +6 -0
@@ -16,6 +16,7 @@#include <linux/blk-crypto-profile.h> #include <linux/blk-mq.h> #include <linux/devfreq.h> +#include <linux/msi.h> #include <linux/pm_runtime.h> #include <scsi/scsi_device.h> #include <ufs/unipro.h>
@@ -1201,6 +1202,11 @@ void ufshcd_parse_dev_ref_clk_freq(struct ufs_hba *hba, struct clk *refclk);void ufshcd_update_evt_hist (struct ufs_hba *hba,u32 id,u32 val);void ufshcd_hba_stop (struct ufs_hba *hba);void ufshcd_schedule_eh_work (struct ufs_hba *hba); +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); +void ufshcd_mcq_enable_esi (struct ufs_hba *hba); +void ufshcd_mcq_config_esi (struct ufs_hba *hba,struct msi_msg *msg);/** * ufshcd_set_variant - set variant specific data to the hba
include/ufs/ufshci.h +2 -0
@@ -59,6 +59,8 @@ enum {REG_UFS_MEM_CFG =0x300 ,REG_UFS_MCQ_CFG =0x380 , +REG_UFS_ESILBA =0x384 , +REG_UFS_ESIUBA =0x388 , UFSHCI_CRYPTO_REG_SPACE_SIZE = 0x400, };
Signature · 1 line
2.7.4
Bart Van Assche
reviewerRe: [PATCH v2 2/3] ufs: core: mcq: Add Event Specific Interrupt enable and config APIs
Quoted 1 line · Can Guo
Add two APIs to enable ESI and config ESI base addresses.
If this patch is reposted, please change "APIs" into "functions" and add a sentence to explain that calls to the exported functions will be added by the next patch in this series.
Thanks,
Bart.
Re: [PATCH v2 2/3] ufs: core: mcq: Add Event Specific Interrupt enable and config APIs
Hi Bart,
Quoted 8 lines · Bart Van Assche
Quoted 1 line · Can Guo
Add two APIs to enable ESI and config ESI base addresses.
If this patch is reposted, please change "APIs" into "functions" and add a sentence to explain that calls to the exported functions will be added by the next patch in this series.
Thanks,
Bart.
Thank you Bart for your review. I will upload a new version to adopt your comments.
Best Regard,
Can Guo.
PATCH v2 3/3 ufs-host: qcom: Add MCQ ESI config vendor specific ops
In reply to Can GuoAdd MCQ ESI config vendor specific ops.
--- drivers/ufs/host/ufs-qcom.c | 97 +++++++++++++++++++++++++++++++++++++++++++++ drivers/ufs/host/ufs-qcom.h | 5 +++ 2 files changed, 102 insertions(+)
drivers/ufs/host/ufs-qcom.c +97 -0
@@ -1568,6 +1568,101 @@ static int ufs_qcom_get_outstanding_cqs(struct ufs_hba *hba,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 id = irq - host->esi_base; +struct ufs_hw_queue *hwq = &hba->uhq[id]; + +ufshcd_mcq_write_cqis (hba,0x1 , id); +ufshcd_mcq_poll_cqe_nolock (hba, hwq); + +return IRQ_HANDLED ; +} + +static int ufs_qcom_config_esi (struct ufs_hba *hba) +{ +struct ufs_qcom_host *host =ufshcd_get_variant (hba); +struct msi_desc *desc; +struct msi_desc *failed_desc =NULL ; +int nr_irqs, ret; + +if (host->esi_enabled) +return 0 ; +else if (host->esi_base <0 ) +return -EINVAL ; + +/* +* 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, +IRQF_SHARED ,"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); + } +platform_msi_domain_free_irqs (hba->dev); + }else { +if (host->hw_ver.major ==6 && host->hw_ver.minor ==0 && + host->hw_ver.step ==0 ) { +ufshcd_writel (hba, +ufshcd_readl (hba,REG_UFS_CFG3 ) |0x1F000 , +REG_UFS_CFG3 ); + } +ufshcd_mcq_enable_esi (hba); + } + +out: +if (ret) { + host->esi_base =-1 ; +dev_warn (hba->dev,"Failed to request Platform MSI %d\n" , ret); + }else { + host->esi_enabled = true; + } + +return ret; +} + +#else +static int ufs_qcom_config_esi (struct ufs_hba *hba) +{ +return -EOPNOTSUPP ; +} +#endif +/* * struct ufs_hba_qcom_vops - UFS QCOM specific variant operations *
@@ -1595,6 +1690,7 @@ static const struct ufs_hba_variant_ops ufs_hba_qcom_vops = { .get_hba_mac = ufs_qcom_get_hba_mac, .op_runtime_config = ufs_qcom_op_runtime_config, .get_outstanding_cqs = ufs_qcom_get_outstanding_cqs, + .config_esi = ufs_qcom_config_esi, };/**
@@ -1628,6 +1724,7 @@ static int ufs_qcom_remove(struct platform_device *pdev)pm_runtime_get_sync (&(pdev)->dev);ufshcd_remove (hba); +platform_msi_domain_free_irqs (hba->dev);return 0 ; }
drivers/ufs/host/ufs-qcom.h +5 -0
@@ -54,6 +54,8 @@ enum {* added in HW Version 3.0.0 */ UFS_AH8_CFG =0xFC , + + REG_UFS_CFG3 = 0x271C, };/* QCOM UFS host controller vendor specific debug registers */
@@ -226,6 +228,9 @@ struct ufs_qcom_host {struct reset_controller_dev rcdev;struct gpio_desc *device_reset; + +int esi_base; +bool esi_enabled; }; static inline u32
Signature · 1 line
2.7.4
Quoted 5 lines · Can Guo
UFS Multi-Circular Queue (MCQ) driver is on the way. This patch series is to enable Event Specific Interrupt (ESI), which can used in MCQ mode.
Please note that this series is developed and tested based on the latest MCQ driver (v11) pushed by Asutosh Das.
Please add the following to the three patches in this series: