[PATCH 03/11] PCI: epf-mhi: Add MSI-X support
Krishna Chaitanya Chundru
krishna.chundru at oss.qualcomm.com
Sat Nov 21 18:56:16 PST 2026
From: Anvita T <anvita.t at oss.qualcomm.com>
Allow the MHI endpoint function to signal interrupts using MSI-X when the
endpoint controller supports it. On controllers whose epc_features
advertise msix_capable, set up a dedicated MSI-X BAR (BAR_0) from a
"msix" memory region supplied by the platform and program the MSI-X
configuration.
The "msix" resource is optional and only looked up during bind; it is
required only when the controller reports MSI-X capability. At interrupt
time, select PCI_IRQ_MSIX over PCI_IRQ_MSI based on whether MSI-X has
been enabled by the host.
Fetch epc_features earlier in epc_init() so the MSI-X capability can be
checked before setting up the BARs.
Signed-off-by: Anvita T <anvita.t at oss.qualcomm.com>
Signed-off-by: Krishna Chaitanya Chundru <krishna.chundru at oss.qualcomm.com>
---
drivers/pci/endpoint/functions/pci-epf-mhi.c | 54 +++++++++++++++++++++++++---
1 file changed, 49 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
index 52cfffcfd5ca..a8765beffe06 100644
--- a/drivers/pci/endpoint/functions/pci-epf-mhi.c
+++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
@@ -148,6 +148,7 @@ struct pci_epf_mhi {
struct mutex lock;
void __iomem *mmio;
resource_size_t mmio_phys;
+ resource_size_t msix_phys;
struct dma_chan *dma_chan_tx;
struct dma_chan *dma_chan_rx;
struct workqueue_struct *dma_wq;
@@ -155,6 +156,7 @@ struct pci_epf_mhi {
struct list_head dma_list;
spinlock_t list_lock;
u32 mmio_size;
+ u32 msix_size;
int irq;
};
@@ -230,12 +232,16 @@ static void pci_epf_mhi_raise_irq(struct mhi_ep_cntrl *mhi_cntrl, u32 vector)
struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
struct pci_epf *epf = epf_mhi->epf;
struct pci_epc *epc = epf->epc;
+ unsigned int type = PCI_IRQ_MSI;
+
+ if (pci_epc_get_msix(epc, epf->func_no, epf->vfunc_no) > 0)
+ type = PCI_IRQ_MSIX;
/*
* MHI supplies 0 based MSI vectors but the API expects the vector
* number to start from 1, so we need to increment the vector by 1.
*/
- pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, PCI_IRQ_MSI,
+ pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no, type,
vector + 1);
}
@@ -714,11 +720,40 @@ static int pci_epf_mhi_epc_init(struct pci_epf *epf)
{
struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
const struct pci_epf_mhi_ep_info *info = epf_mhi->info;
+ struct pci_epf_bar *msix_bar = &epf->bar[BAR_0];
struct pci_epf_bar *epf_bar = &epf->bar[info->bar_num];
struct pci_epc *epc = epf->epc;
struct device *dev = &epf->dev;
int ret;
+ epf_mhi->epc_features = pci_epc_get_features(epc, epf->func_no, epf->vfunc_no);
+ if (!epf_mhi->epc_features)
+ return -ENODATA;
+
+ if (epf_mhi->epc_features->msix_capable) {
+ if (!epf_mhi->msix_phys) {
+ dev_err(dev, "MSI-X BAR address not configured in DT\n");
+ return -EINVAL;
+ }
+
+ msix_bar->phys_addr = epf_mhi->msix_phys;
+ msix_bar->size = epf_mhi->msix_size;
+ msix_bar->barno = BAR_0;
+ msix_bar->flags = info->epf_flags;
+ ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, msix_bar);
+ if (ret) {
+ dev_err(dev, "Failed to set MSI-X BAR: %d\n", ret);
+ return ret;
+ }
+
+ ret = pci_epc_set_msix(epc, epf->func_no, epf->vfunc_no,
+ info->msi_count, BAR_0, 0);
+ if (ret) {
+ dev_err(dev, "Failed to set MSI-X configuration: %d\n", ret);
+ return ret;
+ }
+ }
+
epf_bar->phys_addr = epf_mhi->mmio_phys;
epf_bar->size = epf_mhi->mmio_size;
epf_bar->barno = info->bar_num;
@@ -743,10 +778,6 @@ static int pci_epf_mhi_epc_init(struct pci_epf *epf)
return ret;
}
- epf_mhi->epc_features = pci_epc_get_features(epc, epf->func_no, epf->vfunc_no);
- if (!epf_mhi->epc_features)
- return -ENODATA;
-
if (info->flags & MHI_EPF_USE_DMA) {
ret = pci_epf_mhi_dma_init(epf_mhi);
if (ret) {
@@ -763,6 +794,7 @@ static void pci_epf_mhi_epc_deinit(struct pci_epf *epf)
struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
const struct pci_epf_mhi_ep_info *info = epf_mhi->info;
struct pci_epf_bar *epf_bar = &epf->bar[info->bar_num];
+ struct pci_epf_bar *msix_bar = &epf->bar[BAR_0];
struct mhi_ep_cntrl *mhi_cntrl = &epf_mhi->mhi_cntrl;
struct pci_epc *epc = epf->epc;
@@ -773,6 +805,8 @@ static void pci_epf_mhi_epc_deinit(struct pci_epf *epf)
mhi_ep_unregister_controller(mhi_cntrl);
}
+ if (epf_mhi->epc_features && epf_mhi->epc_features->msix_capable)
+ pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, msix_bar);
pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, epf_bar);
}
@@ -880,6 +914,13 @@ static int pci_epf_mhi_bind(struct pci_epf *epf)
if (!epf_mhi->mmio)
return -ENOMEM;
+ /* MSI-X BAR address is optional; only present on EPCs that support MSI-X */
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "msix");
+ if (res) {
+ epf_mhi->msix_phys = res->start;
+ epf_mhi->msix_size = resource_size(res);
+ }
+
ret = platform_get_irq_byname(pdev, "doorbell");
if (ret < 0) {
iounmap(epf_mhi->mmio);
@@ -896,6 +937,7 @@ static void pci_epf_mhi_unbind(struct pci_epf *epf)
struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
const struct pci_epf_mhi_ep_info *info = epf_mhi->info;
struct pci_epf_bar *epf_bar = &epf->bar[info->bar_num];
+ struct pci_epf_bar *msix_bar = &epf->bar[BAR_0];
struct mhi_ep_cntrl *mhi_cntrl = &epf_mhi->mhi_cntrl;
struct pci_epc *epc = epf->epc;
@@ -912,6 +954,8 @@ static void pci_epf_mhi_unbind(struct pci_epf *epf)
}
iounmap(epf_mhi->mmio);
+ if (epf_mhi->epc_features && epf_mhi->epc_features->msix_capable)
+ pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, msix_bar);
pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, epf_bar);
}
--
2.34.1
More information about the linux-phy
mailing list