Skip to contentSkip to conversation

PCI: endpoint: add D-state change notifier support

PATCH Superseded Krishna chaitanya chundru 1 participant 5 messages Sep 8, 2023

Subsystems (7)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover PCI: endpoint: add D-state change notifier support

In this series we added support to nofity the EPF driver whenever there is change in the D-state if the EPF driver registered for it.

This series needed by the following series for epf driver to know whether link is in D3Cold or D3hot to wake the host ('PCI: EPC: Add support to wake up host from D3 states')
https://lore.kernel.org/linux-pci/[email protected]/T/

Changes from v5:
- Fixed compilation errors & removed checks in the dstate_notify() function as suggested by bjorn.

---
Krishna chaitanya chundru (4):
PCI: endpoint: Add D-state change notifier support
PCI: qcom-ep: Add support for D-state change notification
PCI: qcom-ep: Print D-state name to distinguish D3hot/D3cold
PCI: epf-mhi: Add support for handling D-state notify from EPC

 Documentation/PCI/endpoint/pci-endpoint.rst  |  4 ++++
 drivers/pci/controller/dwc/pcie-qcom-ep.c    | 10 ++++++++--
 drivers/pci/endpoint/functions/pci-epf-mhi.c | 11 +++++++++++
 drivers/pci/endpoint/pci-epc-core.c          | 24 ++++++++++++++++++++++++
 include/linux/mhi_ep.h                       |  3 +++
 include/linux/pci-epc.h                      |  1 +
 include/linux/pci-epf.h                      |  2 ++
 7 files changed, 53 insertions(+), 2 deletions(-)

---
base-commit: cd76a0897a67d2e70effd0f5d411792e2d6896c6
change-id: 20230907-dstate_change-b2eba8bea718

Best regards,

Signature · 1 line
Krishna chaitanya chundru <[email protected]>
#1 lore raw

PATCH v6 1/4 PCI: endpoint: Add D-state change notifier support

Add support to notify the EPF device about the D-state change event from the EPC device.

---
 Documentation/PCI/endpoint/pci-endpoint.rst |  4 ++++
 drivers/pci/endpoint/pci-epc-core.c         | 24 ++++++++++++++++++++++++
 include/linux/pci-epc.h                     |  1 +
 include/linux/pci-epf.h                     |  2 ++
 4 files changed, 31 insertions(+)
Documentation/PCI/endpoint/pci-endpoint.rst +4 -0
index 4f5622a65555..a1d610f612b4 100644
@@ -78,6 +78,10 @@ by the PCI controller driver.
    Cleanup the pci_epc_mem structure allocated during pci_epc_mem_init().
 
 
+* pci_epc_dstate_notify()
+
+   Notify all the function drivers that the EPC device has changed its D-state.
+
 EPC APIs for the PCI Endpoint Function Driver
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
drivers/pci/endpoint/pci-epc-core.c +24 -0
index 5a4a8b0be626..4d589a5c96f0 100644
@@ -783,6 +783,30 @@ void pci_epc_bme_notify(struct pci_epc *epc)
 }
 EXPORT_SYMBOL_GPL(pci_epc_bme_notify);
 
+/**
+ * pci_epc_dstate_notify() - Notify the EPF driver that EPC device D-state
+ *			has changed
+ * @epc: the EPC device which has change in D-state
+ * @state: the changed D-state
+ *
+ * Invoke to Notify the EPF device that the EPC device D-state has
+ * changed.
+ */
+void pci_epc_dstate_notify(struct pci_epc *epc, pci_power_t state)
+{
+	struct pci_epf *epf;
+
+	mutex_lock(&epc->list_lock);
+	list_for_each_entry(epf, &epc->pci_epf, list) {
+		mutex_lock(&epf->lock);
+		if (epf->event_ops && epf->event_ops->dstate_notify)
+			epf->event_ops->dstate_notify(epf, state);
+		mutex_unlock(&epf->lock);
+	}
+	mutex_unlock(&epc->list_lock);
+}
+EXPORT_SYMBOL_GPL(pci_epc_dstate_notify);
+
 /**
  * pci_epc_destroy() - destroy the EPC device
  * @epc: the EPC device that has to be destroyed
include/linux/pci-epc.h +1 -0
index 5cb694031072..225a5a88627f 100644
@@ -251,4 +251,5 @@ void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc,
 				     phys_addr_t *phys_addr, size_t size);
 void pci_epc_mem_free_addr(struct pci_epc *epc, phys_addr_t phys_addr,
 			   void __iomem *virt_addr, size_t size);
+void pci_epc_dstate_notify(struct pci_epc *epc, pci_power_t state);
 #endif /* __LINUX_PCI_EPC_H */
include/linux/pci-epf.h +2 -0
index 3f44b6aec477..b2178bb0e976 100644
@@ -73,12 +73,14 @@ struct pci_epf_ops {
  * @link_up: Callback for the EPC link up event
  * @link_down: Callback for the EPC link down event
  * @bme: Callback for the EPC BME (Bus Master Enable) event
+ * @dstate_notify: Callback for the EPC D-state change event
  */
 struct pci_epc_event_ops {
 	int (*core_init)(struct pci_epf *epf);
 	int (*link_up)(struct pci_epf *epf);
 	int (*link_down)(struct pci_epf *epf);
 	int (*bme)(struct pci_epf *epf);
+	int (*dstate_notify)(struct pci_epf *epf, pci_power_t state);
 };
 
 /**
Signature · 1 line
2.42.0
#2 lore raw

PATCH v6 2/4 PCI: qcom-ep: Add support for D-state change notification

In reply to Krishna chaitanya chundru

Add support to pass D-state change notification to Endpoint function driver.

---
 drivers/pci/controller/dwc/pcie-qcom-ep.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-qcom-ep.c +7 -1
index 8bd8107690a6..402ace57309d 100644
@@ -633,6 +633,7 @@ static irqreturn_t qcom_pcie_ep_global_irq_thread(int irq, void *data)
 	struct device *dev = pci->dev;
 	u32 status = readl_relaxed(pcie_ep->parf + PARF_INT_ALL_STATUS);
 	u32 mask = readl_relaxed(pcie_ep->parf + PARF_INT_ALL_MASK);
+	pci_power_t state;
 	u32 dstate, val;
 
 	writel_relaxed(status, pcie_ep->parf + PARF_INT_ALL_CLEAR);
@@ -656,11 +657,16 @@ static irqreturn_t qcom_pcie_ep_global_irq_thread(int irq, void *data)
 		dstate = dw_pcie_readl_dbi(pci, DBI_CON_STATUS) &
 					   DBI_CON_STATUS_POWER_STATE_MASK;
 		dev_dbg(dev, "Received D%d state event\n", dstate);
-		if (dstate == 3) {
+		state = dstate;
+		if (dstate == PCI_D3hot) {
 			val = readl_relaxed(pcie_ep->parf + PARF_PM_CTRL);
 			val |= PARF_PM_CTRL_REQ_EXIT_L1;
 			writel_relaxed(val, pcie_ep->parf + PARF_PM_CTRL);
+
+			if (gpiod_get_value(pcie_ep->reset))
+				state = PCI_D3cold;
 		}
+		pci_epc_dstate_notify(pci->ep.epc, state);
 	} else if (FIELD_GET(PARF_INT_ALL_LINK_UP, status)) {
 		dev_dbg(dev, "Received Linkup event. Enumeration complete!\n");
 		dw_pcie_ep_linkup(&pci->ep);
Signature · 1 line
2.42.0
#3 lore raw

PATCH v6 3/4 PCI: qcom-ep: Print D-state name to distinguish D3hot/D3cold

In reply to Krishna chaitanya chundru

Now that the state event is stored as pci_power_t, use the PCI helper pci_power_name() to print the state event.

---
 drivers/pci/controller/dwc/pcie-qcom-ep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-qcom-ep.c +1 -1
index 402ace57309d..2337602ebc7f 100644
@@ -656,7 +656,6 @@ static irqreturn_t qcom_pcie_ep_global_irq_thread(int irq, void *data)
 	} else if (FIELD_GET(PARF_INT_ALL_DSTATE_CHANGE, status)) {
 		dstate = dw_pcie_readl_dbi(pci, DBI_CON_STATUS) &
 					   DBI_CON_STATUS_POWER_STATE_MASK;
-		dev_dbg(dev, "Received D%d state event\n", dstate);
 		state = dstate;
 		if (dstate == PCI_D3hot) {
 			val = readl_relaxed(pcie_ep->parf + PARF_PM_CTRL);
@@ -666,6 +665,7 @@ static irqreturn_t qcom_pcie_ep_global_irq_thread(int irq, void *data)
 			if (gpiod_get_value(pcie_ep->reset))
 				state = PCI_D3cold;
 		}
+		dev_dbg(dev, "Received %s event\n", pci_power_name(state));
 		pci_epc_dstate_notify(pci->ep.epc, state);
 	} else if (FIELD_GET(PARF_INT_ALL_LINK_UP, status)) {
 		dev_dbg(dev, "Received Linkup event. Enumeration complete!\n");
Signature · 1 line
2.42.0
#4 lore raw

PATCH v6 4/4 PCI: epf-mhi: Add support for handling D-state notify from EPC

In reply to Krishna chaitanya chundru

Add support for handling D-state notify for MHI EPF.

---
 drivers/pci/endpoint/functions/pci-epf-mhi.c | 11 +++++++++++
 include/linux/mhi_ep.h                       |  3 +++
 2 files changed, 14 insertions(+)
drivers/pci/endpoint/functions/pci-epf-mhi.c +11 -0
index b7b9d3e21f97..7bd15cca686c 100644
@@ -592,6 +592,16 @@ static int pci_epf_mhi_bme(struct pci_epf *epf)
 	return 0;
 }
 
+static int pci_epf_mhi_dstate_notify(struct pci_epf *epf, pci_power_t state)
+{
+	struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
+	struct mhi_ep_cntrl *mhi_cntrl = &epf_mhi->mhi_cntrl;
+
+	mhi_cntrl->dstate = state;
+
+	return 0;
+}
+
 static int pci_epf_mhi_bind(struct pci_epf *epf)
 {
 	struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
@@ -649,6 +659,7 @@ static struct pci_epc_event_ops pci_epf_mhi_event_ops = {
 	.link_up = pci_epf_mhi_link_up,
 	.link_down = pci_epf_mhi_link_down,
 	.bme = pci_epf_mhi_bme,
+	.dstate_notify = pci_epf_mhi_dstate_notify,
 };
 
 static int pci_epf_mhi_probe(struct pci_epf *epf,
include/linux/mhi_ep.h +3 -0
index f198a8ac7ee7..c3a068592d21 100644
@@ -8,6 +8,7 @@
 
 #include <linux/dma-direction.h>
 #include <linux/mhi.h>
+#include <linux/pci.h>
 
 #define MHI_EP_DEFAULT_MTU 0x8000
 
@@ -139,6 +140,8 @@ struct mhi_ep_cntrl {
 
 	enum mhi_state mhi_state;
 
+	pci_power_t dstate;
+
 	u32 max_chan;
 	u32 mru;
 	u32 event_rings;
Signature · 1 line
2.42.0