linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/8] PCCI: EPC: Add support to wake up host from D3 states
@ 2023-06-30 10:52 Krishna chaitanya chundru
  2023-06-30 10:52 ` [PATCH v2 1/8] PCI: endpoint: Add dstate change notifier support Krishna chaitanya chundru
                   ` (7 more replies)
  0 siblings, 8 replies; 24+ messages in thread
From: Krishna chaitanya chundru @ 2023-06-30 10:52 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: helgaas, linux-pci, linux-arm-msm, linux-kernel, quic_vbadigan,
	quic_nitegupt, quic_skananth, quic_ramkri, krzysztof.kozlowski,
	Krishna chaitanya chundru

Here we propose this patch series to add support in PCI endpoint
driver to wake up host from D3 states.

As endpoint cannot send any data/MSI when the D-state is in
D3cold or D3hot. Endpoint needs to bring the device back to D0
to send any kind of data.

For this endpoint needs to send inband PME the device is in D3 state or
toggle wake when the device is D3 cold and vaux is not supplied.

As EPF doestn't know the D-state of the PCI, added a notify op whenever
device state changes.

Based on the D-state the EPF driver decides to wake host either by
toggling wake or by sending PME.

When the MHI state is in M3 MHI driver will wakeup the host using the
wakeup op.

Changes from v1:
	- Moved from RFC patch to regular patch
	- Inclueded EPF patch and added a new op patch to notify dstate change
Krishna chaitanya chundru (8):
  PCI: endpoint: Add dstate change notifier support
  PCI: qcom-ep: Add support for D-state change notification
  PCI: epf-mhi: Add dtate change op
  PCI: endpoint: Add wakeup host API to EPC core
  pci: dwc: Add wakeup host op to pci_epc_ops
  PCI: qcom: ep: Add wake up host op to dw_pcie_ep_ops
  PCI: epf-mhi: Add wakeup host op
  bus: mhi: ep: wake up host is the MHI state is in M3

 Documentation/PCI/endpoint/pci-endpoint.rst     | 11 +++++
 drivers/bus/mhi/ep/main.c                       | 16 ++++++-
 drivers/pci/controller/dwc/pcie-designware-ep.c | 12 +++++
 drivers/pci/controller/dwc/pcie-designware.h    |  3 ++
 drivers/pci/controller/dwc/pcie-qcom-ep.c       | 37 ++++++++++++++++
 drivers/pci/endpoint/functions/pci-epf-mhi.c    | 32 ++++++++++++++
 drivers/pci/endpoint/pci-epc-core.c             | 58 +++++++++++++++++++++++++
 include/linux/mhi_ep.h                          |  4 ++
 include/linux/pci-epc.h                         | 12 +++++
 include/linux/pci-epf.h                         |  1 +
 10 files changed, 185 insertions(+), 1 deletion(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 1/8] PCI: endpoint: Add dstate change notifier support
  2023-06-30 10:52 [PATCH v2 0/8] PCCI: EPC: Add support to wake up host from D3 states Krishna chaitanya chundru
@ 2023-06-30 10:52 ` Krishna chaitanya chundru
  2023-07-07  5:44   ` Manivannan Sadhasivam
  2023-06-30 10:52 ` [PATCH v2 2/8] PCI: qcom-ep: Add support for D-state change notification Krishna chaitanya chundru
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 24+ messages in thread
From: Krishna chaitanya chundru @ 2023-06-30 10:52 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: helgaas, linux-pci, linux-arm-msm, linux-kernel, quic_vbadigan,
	quic_nitegupt, quic_skananth, quic_ramkri, krzysztof.kozlowski,
	Krishna chaitanya chundru, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Manivannan Sadhasivam,
	Kishon Vijay Abraham I, Bjorn Helgaas, Jonathan Corbet,
	open list:DOCUMENTATION

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

Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
---
 Documentation/PCI/endpoint/pci-endpoint.rst |  5 +++++
 drivers/pci/endpoint/pci-epc-core.c         | 27 +++++++++++++++++++++++++++
 include/linux/pci-epc.h                     |  1 +
 include/linux/pci-epf.h                     |  1 +
 4 files changed, 34 insertions(+)

diff --git a/Documentation/PCI/endpoint/pci-endpoint.rst b/Documentation/PCI/endpoint/pci-endpoint.rst
index 4f5622a..0538cdc 100644
--- a/Documentation/PCI/endpoint/pci-endpoint.rst
+++ b/Documentation/PCI/endpoint/pci-endpoint.rst
@@ -78,6 +78,11 @@ by the PCI controller driver.
    Cleanup the pci_epc_mem structure allocated during pci_epc_mem_init().
 
 
+* pci_epc_dstate_change()
+
+   In order to notify all the function devices that the EPC device has
+   changed its D-state.
+
 EPC APIs for the PCI Endpoint Function Driver
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index 6c54fa5..cad360f 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -785,6 +785,33 @@ void pci_epc_bme_notify(struct pci_epc *epc)
 EXPORT_SYMBOL_GPL(pci_epc_bme_notify);
 
 /**
+ * pci_epc_dstate_change() - Notify the EPF device 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 has D-state has
+ * changed.
+ */
+void pci_epc_dstate_change(struct pci_epc *epc, pci_power_t state)
+{
+	struct pci_epf *epf;
+
+	if (!epc || IS_ERR(epc))
+		return;
+
+	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_change)
+			epf->event_ops->dstate_change(epf, state);
+		mutex_unlock(&epf->lock);
+	}
+	mutex_unlock(&epc->list_lock);
+}
+EXPORT_SYMBOL_GPL(pci_epc_dstate_change);
+
+/**
  * pci_epc_destroy() - destroy the EPC device
  * @epc: the EPC device that has to be destroyed
  *
diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
index 5cb6940..26a1108 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -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_change(struct pci_epc *epc, pci_power_t state);
 #endif /* __LINUX_PCI_EPC_H */
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index 4b52807..1d3c2a2 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -79,6 +79,7 @@ struct pci_epc_event_ops {
 	int (*link_up)(struct pci_epf *epf);
 	int (*link_down)(struct pci_epf *epf);
 	int (*bme)(struct pci_epf *epf);
+	int (*dstate_change)(struct pci_epf *epf, pci_power_t state);
 };
 
 /**
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 2/8] PCI: qcom-ep: Add support for D-state change notification
  2023-06-30 10:52 [PATCH v2 0/8] PCCI: EPC: Add support to wake up host from D3 states Krishna chaitanya chundru
  2023-06-30 10:52 ` [PATCH v2 1/8] PCI: endpoint: Add dstate change notifier support Krishna chaitanya chundru
@ 2023-06-30 10:52 ` Krishna chaitanya chundru
  2023-07-07  5:51   ` Manivannan Sadhasivam
  2023-07-13 20:04   ` kernel test robot
  2023-06-30 10:52 ` [PATCH v2 3/8] PCI: epf-mhi: Add dtate change op Krishna chaitanya chundru
                   ` (5 subsequent siblings)
  7 siblings, 2 replies; 24+ messages in thread
From: Krishna chaitanya chundru @ 2023-06-30 10:52 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: helgaas, linux-pci, linux-arm-msm, linux-kernel, quic_vbadigan,
	quic_nitegupt, quic_skananth, quic_ramkri, krzysztof.kozlowski,
	Krishna chaitanya chundru, Manivannan Sadhasivam,
	Lorenzo Pieralisi, Krzysztof Wilczyński, Rob Herring,
	Bjorn Helgaas

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

Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
---
 drivers/pci/controller/dwc/pcie-qcom-ep.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
index 1435f51..e75aec4 100644
--- a/drivers/pci/controller/dwc/pcie-qcom-ep.c
+++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c
@@ -561,6 +561,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);
@@ -583,11 +584,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);
+		state = dstate;
 		if (dstate == 3) {
 			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);
+			state = PCI_D3hot;
+			if (gpiod_get_value(pcie_ep->reset))
+				state = PCI_D3cold;
 		}
+		pci_epc_dstate_change(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);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 3/8] PCI: epf-mhi: Add dtate change op
  2023-06-30 10:52 [PATCH v2 0/8] PCCI: EPC: Add support to wake up host from D3 states Krishna chaitanya chundru
  2023-06-30 10:52 ` [PATCH v2 1/8] PCI: endpoint: Add dstate change notifier support Krishna chaitanya chundru
  2023-06-30 10:52 ` [PATCH v2 2/8] PCI: qcom-ep: Add support for D-state change notification Krishna chaitanya chundru
@ 2023-06-30 10:52 ` Krishna chaitanya chundru
  2023-07-07  5:59   ` Manivannan Sadhasivam
  2023-06-30 10:52 ` [PATCH v2 4/8] PCI: endpoint: Add wakeup host API to EPC core Krishna chaitanya chundru
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 24+ messages in thread
From: Krishna chaitanya chundru @ 2023-06-30 10:52 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: helgaas, linux-pci, linux-arm-msm, linux-kernel, quic_vbadigan,
	quic_nitegupt, quic_skananth, quic_ramkri, krzysztof.kozlowski,
	Krishna chaitanya chundru, Manivannan Sadhasivam,
	Lorenzo Pieralisi, Krzysztof Wilczyński,
	Kishon Vijay Abraham I, Bjorn Helgaas, Jeffrey Hugo,
	open list:MHI BUS

Add dstate host op for MHI EPF.

Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
---
 drivers/pci/endpoint/functions/pci-epf-mhi.c | 13 +++++++++++++
 include/linux/mhi_ep.h                       |  3 +++
 2 files changed, 16 insertions(+)

diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
index 9c1f5a1..64ff37d 100644
--- a/drivers/pci/endpoint/functions/pci-epf-mhi.c
+++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
@@ -339,6 +339,18 @@ static int pci_epf_mhi_bme(struct pci_epf *epf)
 	return 0;
 }
 
+static int pci_epf_mhi_dstate_change(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;
+	struct device *dev = &epf->dev;
+
+	mhi_cntrl->dstate = state;
+	dev_info(dev, "D-state changeg to %s\n", pci_power_name(state));
+
+	return 0;
+}
+
 static int pci_epf_mhi_bind(struct pci_epf *epf)
 {
 	struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
@@ -394,6 +406,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_change = pci_epf_mhi_dstate_change,
 };
 
 static int pci_epf_mhi_probe(struct pci_epf *epf,
diff --git a/include/linux/mhi_ep.h b/include/linux/mhi_ep.h
index f198a8a..c3a0685 100644
--- a/include/linux/mhi_ep.h
+++ b/include/linux/mhi_ep.h
@@ -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;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 4/8] PCI: endpoint: Add wakeup host API to EPC core
  2023-06-30 10:52 [PATCH v2 0/8] PCCI: EPC: Add support to wake up host from D3 states Krishna chaitanya chundru
                   ` (2 preceding siblings ...)
  2023-06-30 10:52 ` [PATCH v2 3/8] PCI: epf-mhi: Add dtate change op Krishna chaitanya chundru
@ 2023-06-30 10:52 ` Krishna chaitanya chundru
  2023-07-07  6:04   ` Manivannan Sadhasivam
  2023-06-30 10:52 ` [PATCH v2 5/8] pci: dwc: Add wakeup host op to pci_epc_ops Krishna chaitanya chundru
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 24+ messages in thread
From: Krishna chaitanya chundru @ 2023-06-30 10:52 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: helgaas, linux-pci, linux-arm-msm, linux-kernel, quic_vbadigan,
	quic_nitegupt, quic_skananth, quic_ramkri, krzysztof.kozlowski,
	Krishna chaitanya chundru, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Manivannan Sadhasivam,
	Kishon Vijay Abraham I, Bjorn Helgaas, Jonathan Corbet,
	open list:DOCUMENTATION

Endpoint cannot send any data/MSI when the D-state is in
D3cold or D3hot. Endpoint needs to bring the host back to D0
to send any kind of data.

Endpoint can toggle wake signal when the D-state is in D3cold and vaux is
not supplied or can send inband PME.

To support this adding wake up host to epc core.

Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
---
 Documentation/PCI/endpoint/pci-endpoint.rst |  6 ++++++
 drivers/pci/endpoint/pci-epc-core.c         | 31 +++++++++++++++++++++++++++++
 include/linux/pci-epc.h                     | 11 ++++++++++
 3 files changed, 48 insertions(+)

diff --git a/Documentation/PCI/endpoint/pci-endpoint.rst b/Documentation/PCI/endpoint/pci-endpoint.rst
index 0538cdc..186ce3b 100644
--- a/Documentation/PCI/endpoint/pci-endpoint.rst
+++ b/Documentation/PCI/endpoint/pci-endpoint.rst
@@ -53,6 +53,7 @@ by the PCI controller driver.
 	 * raise_irq: ops to raise a legacy, MSI or MSI-X interrupt
 	 * start: ops to start the PCI link
 	 * stop: ops to stop the PCI link
+	 * wakeup_host: ops to wake host
 
    The PCI controller driver can then create a new EPC device by invoking
    devm_pci_epc_create()/pci_epc_create().
@@ -122,6 +123,11 @@ by the PCI endpoint function driver.
    The PCI endpoint function driver should use pci_epc_mem_free_addr() to
    free the memory space allocated using pci_epc_mem_alloc_addr().
 
+* pci_epc_wakeup_host()
+
+   The PCI endpoint function driver should use pci_epc_wakeup_host() to wake
+   host.
+
 Other EPC APIs
 ~~~~~~~~~~~~~~
 
diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index cad360f..23599b8 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -167,6 +167,37 @@ const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
 EXPORT_SYMBOL_GPL(pci_epc_get_features);
 
 /**
+ * pci_epc_wakeup_host() - Wakeup the host
+ * @epc: the EPC device which has to wake the host
+ * @func_no: the physical endpoint function number in the EPC device
+ * @vfunc_no: the virtual endpoint function number in the physical function
+ * @type: specify the type of wakeup: WAKEUP_FROM_D3COLD, WAKEUP_FROM_D3HOT
+ *
+ * Invoke to wakeup host
+ */
+int pci_epc_wakeup_host(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
+			enum pci_epc_wakeup_host_type type)
+{
+	int ret;
+
+	if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
+		return -EINVAL;
+
+	if (vfunc_no > 0 && (!epc->max_vfs || vfunc_no > epc->max_vfs[func_no]))
+		return -EINVAL;
+
+	if (!epc->ops->wakeup_host)
+		return 0;
+
+	mutex_lock(&epc->lock);
+	ret = epc->ops->wakeup_host(epc, func_no, vfunc_no, type);
+	mutex_unlock(&epc->lock);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(pci_epc_wakeup_host);
+
+/**
  * pci_epc_stop() - stop the PCI link
  * @epc: the link of the EPC device that has to be stopped
  *
diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
index 26a1108..2323a10 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -26,6 +26,12 @@ enum pci_epc_irq_type {
 	PCI_EPC_IRQ_MSIX,
 };
 
+enum pci_epc_wakeup_host_type {
+	PCI_WAKEUP_UNKNOWN,
+	PCI_WAKEUP_SEND_PME,
+	PCI_WAKEUP_TOGGLE_WAKE,
+};
+
 static inline const char *
 pci_epc_interface_string(enum pci_epc_interface_type type)
 {
@@ -59,6 +65,7 @@ pci_epc_interface_string(enum pci_epc_interface_type type)
  * @start: ops to start the PCI link
  * @stop: ops to stop the PCI link
  * @get_features: ops to get the features supported by the EPC
+ * @wakeup_host: ops to wakeup the host
  * @owner: the module owner containing the ops
  */
 struct pci_epc_ops {
@@ -88,6 +95,8 @@ struct pci_epc_ops {
 	void	(*stop)(struct pci_epc *epc);
 	const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
 						       u8 func_no, u8 vfunc_no);
+	int	(*wakeup_host)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
+				enum pci_epc_wakeup_host_type type);
 	struct module *owner;
 };
 
@@ -234,6 +243,8 @@ int pci_epc_start(struct pci_epc *epc);
 void pci_epc_stop(struct pci_epc *epc);
 const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
 						    u8 func_no, u8 vfunc_no);
+int pci_epc_wakeup_host(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
+					enum pci_epc_wakeup_host_type type);
 enum pci_barno
 pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features);
 enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 5/8] pci: dwc: Add wakeup host op to pci_epc_ops
  2023-06-30 10:52 [PATCH v2 0/8] PCCI: EPC: Add support to wake up host from D3 states Krishna chaitanya chundru
                   ` (3 preceding siblings ...)
  2023-06-30 10:52 ` [PATCH v2 4/8] PCI: endpoint: Add wakeup host API to EPC core Krishna chaitanya chundru
@ 2023-06-30 10:52 ` Krishna chaitanya chundru
  2023-06-30 10:52 ` [PATCH v2 6/8] PCI: qcom: ep: Add wake up host op to dw_pcie_ep_ops Krishna chaitanya chundru
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 24+ messages in thread
From: Krishna chaitanya chundru @ 2023-06-30 10:52 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: helgaas, linux-pci, linux-arm-msm, linux-kernel, quic_vbadigan,
	quic_nitegupt, quic_skananth, quic_ramkri, krzysztof.kozlowski,
	Krishna chaitanya chundru, Jingoo Han, Gustavo Pimentel,
	Lorenzo Pieralisi, Krzysztof Wilczyński, Rob Herring,
	Bjorn Helgaas

Add wakeup host op to wake up host from D3cold or D3hot.

Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
---
 drivers/pci/controller/dwc/pcie-designware-ep.c | 12 ++++++++++++
 drivers/pci/controller/dwc/pcie-designware.h    |  3 +++
 2 files changed, 15 insertions(+)

diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c
index f9182f8..7474849 100644
--- a/drivers/pci/controller/dwc/pcie-designware-ep.c
+++ b/drivers/pci/controller/dwc/pcie-designware-ep.c
@@ -463,6 +463,17 @@ dw_pcie_ep_get_features(struct pci_epc *epc, u8 func_no, u8 vfunc_no)
 	return ep->ops->get_features(ep);
 }
 
+static int dw_pcie_ep_wakeup_host(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
+				enum pci_epc_wakeup_host_type type)
+{
+	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
+
+	if (!ep->ops->wakeup_host)
+		return -EINVAL;
+
+	return ep->ops->wakeup_host(ep, func_no, type);
+}
+
 static const struct pci_epc_ops epc_ops = {
 	.write_header		= dw_pcie_ep_write_header,
 	.set_bar		= dw_pcie_ep_set_bar,
@@ -477,6 +488,7 @@ static const struct pci_epc_ops epc_ops = {
 	.start			= dw_pcie_ep_start,
 	.stop			= dw_pcie_ep_stop,
 	.get_features		= dw_pcie_ep_get_features,
+	.wakeup_host		= dw_pcie_ep_wakeup_host,
 };
 
 int dw_pcie_ep_raise_legacy_irq(struct dw_pcie_ep *ep, u8 func_no)
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index 6156606..79df866 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -330,6 +330,9 @@ struct dw_pcie_ep_ops {
 	 * driver.
 	 */
 	unsigned int (*func_conf_select)(struct dw_pcie_ep *ep, u8 func_no);
+
+	int	(*wakeup_host)(struct dw_pcie_ep *ep, u8 func_no,
+				enum pci_epc_wakeup_host_type type);
 };
 
 struct dw_pcie_ep_func {
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 6/8] PCI: qcom: ep: Add wake up host op to dw_pcie_ep_ops
  2023-06-30 10:52 [PATCH v2 0/8] PCCI: EPC: Add support to wake up host from D3 states Krishna chaitanya chundru
                   ` (4 preceding siblings ...)
  2023-06-30 10:52 ` [PATCH v2 5/8] pci: dwc: Add wakeup host op to pci_epc_ops Krishna chaitanya chundru
@ 2023-06-30 10:52 ` Krishna chaitanya chundru
  2023-07-07  6:10   ` Manivannan Sadhasivam
  2023-06-30 10:52 ` [PATCH v2 7/8] PCI: epf-mhi: Add wakeup host op Krishna chaitanya chundru
  2023-06-30 10:52 ` [PATCH v2 8/8] bus: mhi: ep: wake up host is the MHI state is in M3 Krishna chaitanya chundru
  7 siblings, 1 reply; 24+ messages in thread
From: Krishna chaitanya chundru @ 2023-06-30 10:52 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: helgaas, linux-pci, linux-arm-msm, linux-kernel, quic_vbadigan,
	quic_nitegupt, quic_skananth, quic_ramkri, krzysztof.kozlowski,
	Krishna chaitanya chundru, Manivannan Sadhasivam,
	Lorenzo Pieralisi, Krzysztof Wilczyński, Rob Herring,
	Bjorn Helgaas

Add wakeup host op to dw_pcie_ep_ops to wake up host.
If the EPF asks to send PME trigger the inband PME by writing
into the parf registers otherwise toggle wake signal.

Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
---
 drivers/pci/controller/dwc/pcie-qcom-ep.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
index e75aec4..e382b4b 100644
--- a/drivers/pci/controller/dwc/pcie-qcom-ep.c
+++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c
@@ -89,6 +89,7 @@
 /* PARF_PM_CTRL register fields */
 #define PARF_PM_CTRL_REQ_EXIT_L1		BIT(1)
 #define PARF_PM_CTRL_READY_ENTR_L23		BIT(2)
+#define PARF_PM_CTRL_XMT_PME			BIT(4)
 #define PARF_PM_CTRL_REQ_NOT_ENTR_L1		BIT(5)
 
 /* PARF_MHI_CLOCK_RESET_CTRL fields */
@@ -729,10 +730,40 @@ static void qcom_pcie_ep_init(struct dw_pcie_ep *ep)
 		dw_pcie_ep_reset_bar(pci, bar);
 }
 
+static int qcom_pcie_ep_wakeup_host(struct dw_pcie_ep *ep, u8 func_no,
+					enum pci_epc_wakeup_host_type type)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct qcom_pcie_ep *pcie_ep = to_pcie_ep(pci);
+	struct device *dev = pci->dev;
+	u32 val;
+
+	if (type == PCI_WAKEUP_TOGGLE_WAKE) {
+		dev_dbg(dev, "Waking up the host by toggling WAKE#\n");
+		gpiod_set_value_cansleep(pcie_ep->wake, 1);
+		usleep_range(WAKE_DELAY_US, WAKE_DELAY_US + 500);
+		gpiod_set_value_cansleep(pcie_ep->wake, 0);
+		return 0;
+
+	} else if (type == PCI_WAKEUP_SEND_PME) {
+		dev_dbg(dev, "Waking up the host using PME\n");
+		val = readl_relaxed(pcie_ep->parf + PARF_PM_CTRL);
+		val |= PARF_PM_CTRL_XMT_PME;
+		writel_relaxed(val, pcie_ep->parf + PARF_PM_CTRL);
+
+	} else {
+		dev_err(dev, "Device is not in D3 state wakeup is not supported\n");
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
 static const struct dw_pcie_ep_ops pci_ep_ops = {
 	.ep_init = qcom_pcie_ep_init,
 	.raise_irq = qcom_pcie_ep_raise_irq,
 	.get_features = qcom_pcie_epc_get_features,
+	.wakeup_host = qcom_pcie_ep_wakeup_host,
 };
 
 static int qcom_pcie_ep_probe(struct platform_device *pdev)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 7/8] PCI: epf-mhi: Add wakeup host op
  2023-06-30 10:52 [PATCH v2 0/8] PCCI: EPC: Add support to wake up host from D3 states Krishna chaitanya chundru
                   ` (5 preceding siblings ...)
  2023-06-30 10:52 ` [PATCH v2 6/8] PCI: qcom: ep: Add wake up host op to dw_pcie_ep_ops Krishna chaitanya chundru
@ 2023-06-30 10:52 ` Krishna chaitanya chundru
  2023-07-07  6:14   ` Manivannan Sadhasivam
  2023-06-30 10:52 ` [PATCH v2 8/8] bus: mhi: ep: wake up host is the MHI state is in M3 Krishna chaitanya chundru
  7 siblings, 1 reply; 24+ messages in thread
From: Krishna chaitanya chundru @ 2023-06-30 10:52 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: helgaas, linux-pci, linux-arm-msm, linux-kernel, quic_vbadigan,
	quic_nitegupt, quic_skananth, quic_ramkri, krzysztof.kozlowski,
	Krishna chaitanya chundru, Manivannan Sadhasivam,
	Lorenzo Pieralisi, Krzysztof Wilczyński,
	Kishon Vijay Abraham I, Bjorn Helgaas, Jeffrey Hugo,
	open list:MHI BUS

Add wakeup host op for MHI EPF.
If the D-state is in D3cold toggle wake signal, otherwise send PME.

Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
---
 drivers/pci/endpoint/functions/pci-epf-mhi.c | 19 +++++++++++++++++++
 include/linux/mhi_ep.h                       |  1 +
 2 files changed, 20 insertions(+)

diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
index 64ff37d..deb742c 100644
--- a/drivers/pci/endpoint/functions/pci-epf-mhi.c
+++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
@@ -237,6 +237,24 @@ static int pci_epf_mhi_write_to_host(struct mhi_ep_cntrl *mhi_cntrl,
 	return 0;
 }
 
+static int pci_epf_mhi_wakeup_host(struct mhi_ep_cntrl *mhi_cntrl)
+{
+	struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
+	struct pci_epf *epf = epf_mhi->epf;
+	struct pci_epc *epc = epf->epc;
+	int ret;
+
+	if (mhi_cntrl->dstate == PCI_D3cold)
+		ret = pci_epc_wakeup_host(epc, epf->func_no,
+					epf->vfunc_no, PCI_WAKEUP_TOGGLE_WAKE);
+	else
+		ret = pci_epc_wakeup_host(epc, epf->func_no,
+					epf->vfunc_no, PCI_WAKEUP_SEND_PME);
+
+	return ret;
+
+}
+
 static int pci_epf_mhi_core_init(struct pci_epf *epf)
 {
 	struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
@@ -293,6 +311,7 @@ static int pci_epf_mhi_link_up(struct pci_epf *epf)
 	mhi_cntrl->unmap_free = pci_epf_mhi_unmap_free;
 	mhi_cntrl->read_from_host = pci_epf_mhi_read_from_host;
 	mhi_cntrl->write_to_host = pci_epf_mhi_write_to_host;
+	mhi_cntrl->wakeup_host = pci_epf_mhi_wakeup_host;
 
 	/* Register the MHI EP controller */
 	ret = mhi_ep_register_controller(mhi_cntrl, info->config);
diff --git a/include/linux/mhi_ep.h b/include/linux/mhi_ep.h
index c3a0685..e353c429 100644
--- a/include/linux/mhi_ep.h
+++ b/include/linux/mhi_ep.h
@@ -137,6 +137,7 @@ struct mhi_ep_cntrl {
 			   void __iomem *virt, size_t size);
 	int (*read_from_host)(struct mhi_ep_cntrl *mhi_cntrl, u64 from, void *to, size_t size);
 	int (*write_to_host)(struct mhi_ep_cntrl *mhi_cntrl, void *from, u64 to, size_t size);
+	int (*wakeup_host)(struct mhi_ep_cntrl *mhi_cntrl);
 
 	enum mhi_state mhi_state;
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 8/8] bus: mhi: ep: wake up host is the MHI state is in M3
  2023-06-30 10:52 [PATCH v2 0/8] PCCI: EPC: Add support to wake up host from D3 states Krishna chaitanya chundru
                   ` (6 preceding siblings ...)
  2023-06-30 10:52 ` [PATCH v2 7/8] PCI: epf-mhi: Add wakeup host op Krishna chaitanya chundru
@ 2023-06-30 10:52 ` Krishna chaitanya chundru
  2023-07-07  6:20   ` Manivannan Sadhasivam
  7 siblings, 1 reply; 24+ messages in thread
From: Krishna chaitanya chundru @ 2023-06-30 10:52 UTC (permalink / raw)
  To: manivannan.sadhasivam
  Cc: helgaas, linux-pci, linux-arm-msm, linux-kernel, quic_vbadigan,
	quic_nitegupt, quic_skananth, quic_ramkri, krzysztof.kozlowski,
	Krishna chaitanya chundru, Manivannan Sadhasivam, Jeffrey Hugo,
	Rafael J. Wysocki, Dan Carpenter, Greg Kroah-Hartman, Bo Liu,
	open list:MHI BUS

If the MHI state is in M3 then the most probably the host kept the
device in D3 hot or D3 cold, due to that endpoint transctions will not
be read by the host, so endpoint needs to bring the host to D0 which
eventually bring back the MHI state to M0.

Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
---
 drivers/bus/mhi/ep/main.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c
index 6008818..42d3791 100644
--- a/drivers/bus/mhi/ep/main.c
+++ b/drivers/bus/mhi/ep/main.c
@@ -451,12 +451,14 @@ int mhi_ep_queue_skb(struct mhi_ep_device *mhi_dev, struct sk_buff *skb)
 	struct mhi_ep_cntrl *mhi_cntrl = mhi_dev->mhi_cntrl;
 	struct mhi_ep_chan *mhi_chan = mhi_dev->dl_chan;
 	struct device *dev = &mhi_chan->mhi_dev->dev;
+	u32 buf_left, read_offset, count = 0;
 	struct mhi_ring_element *el;
-	u32 buf_left, read_offset;
 	struct mhi_ep_ring *ring;
 	enum mhi_ev_ccs code;
+	enum mhi_state state;
 	void *read_addr;
 	u64 write_addr;
+	bool mhi_reset;
 	size_t tr_len;
 	u32 tre_len;
 	int ret;
@@ -464,6 +466,18 @@ int mhi_ep_queue_skb(struct mhi_ep_device *mhi_dev, struct sk_buff *skb)
 	buf_left = skb->len;
 	ring = &mhi_cntrl->mhi_chan[mhi_chan->chan].ring;
 
+	if (mhi_cntrl->mhi_state == MHI_STATE_M3) {
+		dev_dbg(dev, "wake up by ch id %x\n", mhi_chan->chan);
+		mhi_cntrl->wakeup_host(mhi_cntrl);
+	}
+
+	/* Wait for Host to set the M0 state */
+	do {
+		msleep(M0_WAIT_DELAY_MS);
+		mhi_ep_mmio_get_mhi_state(mhi_cntrl, &state, &mhi_reset);
+		count++;
+	} while (state != MHI_STATE_M0 && count < M0_WAIT_COUNT);
+
 	mutex_lock(&mhi_chan->lock);
 
 	do {
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 1/8] PCI: endpoint: Add dstate change notifier support
  2023-06-30 10:52 ` [PATCH v2 1/8] PCI: endpoint: Add dstate change notifier support Krishna chaitanya chundru
@ 2023-07-07  5:44   ` Manivannan Sadhasivam
  2023-07-07 10:52     ` Krishna Chaitanya Chundru
  0 siblings, 1 reply; 24+ messages in thread
From: Manivannan Sadhasivam @ 2023-07-07  5:44 UTC (permalink / raw)
  To: Krishna chaitanya chundru
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Kishon Vijay Abraham I, Bjorn Helgaas,
	Jonathan Corbet, open list:DOCUMENTATION

On Fri, Jun 30, 2023 at 04:22:04PM +0530, Krishna chaitanya chundru wrote:
> Add support to notify the EPF device about the D-state change event
> from the EPC device.
> 
> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
> ---
>  Documentation/PCI/endpoint/pci-endpoint.rst |  5 +++++
>  drivers/pci/endpoint/pci-epc-core.c         | 27 +++++++++++++++++++++++++++
>  include/linux/pci-epc.h                     |  1 +
>  include/linux/pci-epf.h                     |  1 +
>  4 files changed, 34 insertions(+)
> 
> diff --git a/Documentation/PCI/endpoint/pci-endpoint.rst b/Documentation/PCI/endpoint/pci-endpoint.rst
> index 4f5622a..0538cdc 100644
> --- a/Documentation/PCI/endpoint/pci-endpoint.rst
> +++ b/Documentation/PCI/endpoint/pci-endpoint.rst
> @@ -78,6 +78,11 @@ by the PCI controller driver.
>     Cleanup the pci_epc_mem structure allocated during pci_epc_mem_init().
>  
>  
> +* pci_epc_dstate_change()
> +
> +   In order to notify all the function devices that the EPC device has
> +   changed its D-state.
> +
>  EPC APIs for the PCI Endpoint Function Driver
>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  
> diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
> index 6c54fa5..cad360f 100644
> --- a/drivers/pci/endpoint/pci-epc-core.c
> +++ b/drivers/pci/endpoint/pci-epc-core.c
> @@ -785,6 +785,33 @@ void pci_epc_bme_notify(struct pci_epc *epc)
>  EXPORT_SYMBOL_GPL(pci_epc_bme_notify);
>  
>  /**
> + * pci_epc_dstate_change() - Notify the EPF device 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 has D-state has
> + * changed.
> + */
> +void pci_epc_dstate_change(struct pci_epc *epc, pci_power_t state)

How about "pci_epc_dstate_notity()"?

Rest looks good.

- Mani

> +{
> +	struct pci_epf *epf;
> +
> +	if (!epc || IS_ERR(epc))
> +		return;
> +
> +	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_change)
> +			epf->event_ops->dstate_change(epf, state);
> +		mutex_unlock(&epf->lock);
> +	}
> +	mutex_unlock(&epc->list_lock);
> +}
> +EXPORT_SYMBOL_GPL(pci_epc_dstate_change);
> +
> +/**
>   * pci_epc_destroy() - destroy the EPC device
>   * @epc: the EPC device that has to be destroyed
>   *
> diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
> index 5cb6940..26a1108 100644
> --- a/include/linux/pci-epc.h
> +++ b/include/linux/pci-epc.h
> @@ -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_change(struct pci_epc *epc, pci_power_t state);
>  #endif /* __LINUX_PCI_EPC_H */
> diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
> index 4b52807..1d3c2a2 100644
> --- a/include/linux/pci-epf.h
> +++ b/include/linux/pci-epf.h
> @@ -79,6 +79,7 @@ struct pci_epc_event_ops {
>  	int (*link_up)(struct pci_epf *epf);
>  	int (*link_down)(struct pci_epf *epf);
>  	int (*bme)(struct pci_epf *epf);
> +	int (*dstate_change)(struct pci_epf *epf, pci_power_t state);
>  };
>  
>  /**
> -- 
> 2.7.4
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 2/8] PCI: qcom-ep: Add support for D-state change notification
  2023-06-30 10:52 ` [PATCH v2 2/8] PCI: qcom-ep: Add support for D-state change notification Krishna chaitanya chundru
@ 2023-07-07  5:51   ` Manivannan Sadhasivam
  2023-07-07 10:54     ` Krishna Chaitanya Chundru
  2023-07-13 20:04   ` kernel test robot
  1 sibling, 1 reply; 24+ messages in thread
From: Manivannan Sadhasivam @ 2023-07-07  5:51 UTC (permalink / raw)
  To: Krishna chaitanya chundru
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas

On Fri, Jun 30, 2023 at 04:22:05PM +0530, Krishna chaitanya chundru wrote:
> Add support to pass D-state change notification to Endpoint
> function driver.
> 
> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>

Few comments below.

> ---
>  drivers/pci/controller/dwc/pcie-qcom-ep.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
> index 1435f51..e75aec4 100644
> --- a/drivers/pci/controller/dwc/pcie-qcom-ep.c
> +++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c
> @@ -561,6 +561,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);
> @@ -583,11 +584,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);

We should also change this debug output to make use of pci_power_name() based on
the "state" variable and move it just above pci_epc_dstate_change(). But this
should be a separate patch.

> +		state = dstate;
>  		if (dstate == 3) {
>  			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);
> +			state = PCI_D3hot;
> +			if (gpiod_get_value(pcie_ep->reset))
> +				state = PCI_D3cold;
>  		}
> +		pci_epc_dstate_change(pci->ep.epc, state);

Need to change this API as per my comment on patch 1.

- Mani

>  	} 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);
> -- 
> 2.7.4
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 3/8] PCI: epf-mhi: Add dtate change op
  2023-06-30 10:52 ` [PATCH v2 3/8] PCI: epf-mhi: Add dtate change op Krishna chaitanya chundru
@ 2023-07-07  5:59   ` Manivannan Sadhasivam
  2023-07-07 10:55     ` Krishna Chaitanya Chundru
  0 siblings, 1 reply; 24+ messages in thread
From: Manivannan Sadhasivam @ 2023-07-07  5:59 UTC (permalink / raw)
  To: Krishna chaitanya chundru
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Kishon Vijay Abraham I, Bjorn Helgaas,
	Jeffrey Hugo, open list:MHI BUS

On Fri, Jun 30, 2023 at 04:22:06PM +0530, Krishna chaitanya chundru wrote:
> Add dstate host op for MHI EPF.
> 

Use "D-state" everywhere. Also the subject should be:

"PCI: epf-mhi: Add support for handling D-state notification from EPC"

Fix the commit message accordingly.

> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
> ---
>  drivers/pci/endpoint/functions/pci-epf-mhi.c | 13 +++++++++++++
>  include/linux/mhi_ep.h                       |  3 +++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> index 9c1f5a1..64ff37d 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-mhi.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> @@ -339,6 +339,18 @@ static int pci_epf_mhi_bme(struct pci_epf *epf)
>  	return 0;
>  }
>  
> +static int pci_epf_mhi_dstate_change(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;
> +	struct device *dev = &epf->dev;
> +
> +	mhi_cntrl->dstate = state;
> +	dev_info(dev, "D-state changeg to %s\n", pci_power_name(state));

This can be removed since we already print the state in pci driver.

- Mani

> +
> +	return 0;
> +}
> +
>  static int pci_epf_mhi_bind(struct pci_epf *epf)
>  {
>  	struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
> @@ -394,6 +406,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_change = pci_epf_mhi_dstate_change,
>  };
>  
>  static int pci_epf_mhi_probe(struct pci_epf *epf,
> diff --git a/include/linux/mhi_ep.h b/include/linux/mhi_ep.h
> index f198a8a..c3a0685 100644
> --- a/include/linux/mhi_ep.h
> +++ b/include/linux/mhi_ep.h
> @@ -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;
> -- 
> 2.7.4
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 4/8] PCI: endpoint: Add wakeup host API to EPC core
  2023-06-30 10:52 ` [PATCH v2 4/8] PCI: endpoint: Add wakeup host API to EPC core Krishna chaitanya chundru
@ 2023-07-07  6:04   ` Manivannan Sadhasivam
  2023-07-07 10:57     ` Krishna Chaitanya Chundru
  0 siblings, 1 reply; 24+ messages in thread
From: Manivannan Sadhasivam @ 2023-07-07  6:04 UTC (permalink / raw)
  To: Krishna chaitanya chundru
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Kishon Vijay Abraham I, Bjorn Helgaas,
	Jonathan Corbet, open list:DOCUMENTATION

On Fri, Jun 30, 2023 at 04:22:07PM +0530, Krishna chaitanya chundru wrote:
> Endpoint cannot send any data/MSI when the D-state is in
> D3cold or D3hot. Endpoint needs to bring the host back to D0

Endpoint needs to wake up the host to bring the D-state to D0

> to send any kind of data.
> 
> Endpoint can toggle wake signal when the D-state is in D3cold and vaux is
> not supplied or can send inband PME.
> 
> To support this adding wake up host to epc core.
> 

"add wakeup_host() callback to the EPC core".


> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
> ---
>  Documentation/PCI/endpoint/pci-endpoint.rst |  6 ++++++
>  drivers/pci/endpoint/pci-epc-core.c         | 31 +++++++++++++++++++++++++++++
>  include/linux/pci-epc.h                     | 11 ++++++++++
>  3 files changed, 48 insertions(+)
> 
> diff --git a/Documentation/PCI/endpoint/pci-endpoint.rst b/Documentation/PCI/endpoint/pci-endpoint.rst
> index 0538cdc..186ce3b 100644
> --- a/Documentation/PCI/endpoint/pci-endpoint.rst
> +++ b/Documentation/PCI/endpoint/pci-endpoint.rst
> @@ -53,6 +53,7 @@ by the PCI controller driver.
>  	 * raise_irq: ops to raise a legacy, MSI or MSI-X interrupt
>  	 * start: ops to start the PCI link
>  	 * stop: ops to stop the PCI link
> +	 * wakeup_host: ops to wake host

wakeup

>  
>     The PCI controller driver can then create a new EPC device by invoking
>     devm_pci_epc_create()/pci_epc_create().
> @@ -122,6 +123,11 @@ by the PCI endpoint function driver.
>     The PCI endpoint function driver should use pci_epc_mem_free_addr() to
>     free the memory space allocated using pci_epc_mem_alloc_addr().
>  
> +* pci_epc_wakeup_host()
> +
> +   The PCI endpoint function driver should use pci_epc_wakeup_host() to wake

wakeup

> +   host.
> +
>  Other EPC APIs
>  ~~~~~~~~~~~~~~
>  
> diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
> index cad360f..23599b8 100644
> --- a/drivers/pci/endpoint/pci-epc-core.c
> +++ b/drivers/pci/endpoint/pci-epc-core.c
> @@ -167,6 +167,37 @@ const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
>  EXPORT_SYMBOL_GPL(pci_epc_get_features);
>  
>  /**
> + * pci_epc_wakeup_host() - Wakeup the host
> + * @epc: the EPC device which has to wake the host

wakeup

> + * @func_no: the physical endpoint function number in the EPC device
> + * @vfunc_no: the virtual endpoint function number in the physical function
> + * @type: specify the type of wakeup: WAKEUP_FROM_D3COLD, WAKEUP_FROM_D3HOT
> + *
> + * Invoke to wakeup host
> + */
> +int pci_epc_wakeup_host(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
> +			enum pci_epc_wakeup_host_type type)

Why can't you use a bool?

- Mani

> +{
> +	int ret;
> +
> +	if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
> +		return -EINVAL;
> +
> +	if (vfunc_no > 0 && (!epc->max_vfs || vfunc_no > epc->max_vfs[func_no]))
> +		return -EINVAL;
> +
> +	if (!epc->ops->wakeup_host)
> +		return 0;
> +
> +	mutex_lock(&epc->lock);
> +	ret = epc->ops->wakeup_host(epc, func_no, vfunc_no, type);
> +	mutex_unlock(&epc->lock);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(pci_epc_wakeup_host);
> +
> +/**
>   * pci_epc_stop() - stop the PCI link
>   * @epc: the link of the EPC device that has to be stopped
>   *
> diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
> index 26a1108..2323a10 100644
> --- a/include/linux/pci-epc.h
> +++ b/include/linux/pci-epc.h
> @@ -26,6 +26,12 @@ enum pci_epc_irq_type {
>  	PCI_EPC_IRQ_MSIX,
>  };
>  
> +enum pci_epc_wakeup_host_type {
> +	PCI_WAKEUP_UNKNOWN,
> +	PCI_WAKEUP_SEND_PME,
> +	PCI_WAKEUP_TOGGLE_WAKE,
> +};
> +
>  static inline const char *
>  pci_epc_interface_string(enum pci_epc_interface_type type)
>  {
> @@ -59,6 +65,7 @@ pci_epc_interface_string(enum pci_epc_interface_type type)
>   * @start: ops to start the PCI link
>   * @stop: ops to stop the PCI link
>   * @get_features: ops to get the features supported by the EPC
> + * @wakeup_host: ops to wakeup the host
>   * @owner: the module owner containing the ops
>   */
>  struct pci_epc_ops {
> @@ -88,6 +95,8 @@ struct pci_epc_ops {
>  	void	(*stop)(struct pci_epc *epc);
>  	const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
>  						       u8 func_no, u8 vfunc_no);
> +	int	(*wakeup_host)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
> +				enum pci_epc_wakeup_host_type type);
>  	struct module *owner;
>  };
>  
> @@ -234,6 +243,8 @@ int pci_epc_start(struct pci_epc *epc);
>  void pci_epc_stop(struct pci_epc *epc);
>  const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
>  						    u8 func_no, u8 vfunc_no);
> +int pci_epc_wakeup_host(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
> +					enum pci_epc_wakeup_host_type type);
>  enum pci_barno
>  pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features);
>  enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features
> -- 
> 2.7.4
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 6/8] PCI: qcom: ep: Add wake up host op to dw_pcie_ep_ops
  2023-06-30 10:52 ` [PATCH v2 6/8] PCI: qcom: ep: Add wake up host op to dw_pcie_ep_ops Krishna chaitanya chundru
@ 2023-07-07  6:10   ` Manivannan Sadhasivam
  2023-07-07 10:58     ` Krishna Chaitanya Chundru
  0 siblings, 1 reply; 24+ messages in thread
From: Manivannan Sadhasivam @ 2023-07-07  6:10 UTC (permalink / raw)
  To: Krishna chaitanya chundru
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas

On Fri, Jun 30, 2023 at 04:22:09PM +0530, Krishna chaitanya chundru wrote:

Subject prefix should be "PCI: qcom-ep:"

> Add wakeup host op to dw_pcie_ep_ops to wake up host.
> If the EPF asks to send PME trigger the inband PME by writing
> into the parf registers otherwise toggle wake signal.
> 

If the wakeup type is PME, then trigger inband PME by writing to the PARF
PARF_PM_CTRL register, otherwise toggle #WAKE.

> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
> ---
>  drivers/pci/controller/dwc/pcie-qcom-ep.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
> index e75aec4..e382b4b 100644
> --- a/drivers/pci/controller/dwc/pcie-qcom-ep.c
> +++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c
> @@ -89,6 +89,7 @@
>  /* PARF_PM_CTRL register fields */
>  #define PARF_PM_CTRL_REQ_EXIT_L1		BIT(1)
>  #define PARF_PM_CTRL_READY_ENTR_L23		BIT(2)
> +#define PARF_PM_CTRL_XMT_PME			BIT(4)
>  #define PARF_PM_CTRL_REQ_NOT_ENTR_L1		BIT(5)
>  
>  /* PARF_MHI_CLOCK_RESET_CTRL fields */
> @@ -729,10 +730,40 @@ static void qcom_pcie_ep_init(struct dw_pcie_ep *ep)
>  		dw_pcie_ep_reset_bar(pci, bar);
>  }
>  
> +static int qcom_pcie_ep_wakeup_host(struct dw_pcie_ep *ep, u8 func_no,
> +					enum pci_epc_wakeup_host_type type)
> +{
> +	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
> +	struct qcom_pcie_ep *pcie_ep = to_pcie_ep(pci);
> +	struct device *dev = pci->dev;
> +	u32 val;
> +
> +	if (type == PCI_WAKEUP_TOGGLE_WAKE) {
> +		dev_dbg(dev, "Waking up the host by toggling WAKE#\n");
> +		gpiod_set_value_cansleep(pcie_ep->wake, 1);
> +		usleep_range(WAKE_DELAY_US, WAKE_DELAY_US + 500);
> +		gpiod_set_value_cansleep(pcie_ep->wake, 0);
> +		return 0;
> +
> +	} else if (type == PCI_WAKEUP_SEND_PME) {
> +		dev_dbg(dev, "Waking up the host using PME\n");
> +		val = readl_relaxed(pcie_ep->parf + PARF_PM_CTRL);
> +		val |= PARF_PM_CTRL_XMT_PME;
> +		writel_relaxed(val, pcie_ep->parf + PARF_PM_CTRL);
> +
> +	} else {
> +		dev_err(dev, "Device is not in D3 state wakeup is not supported\n");
> +		return -EOPNOTSUPP;

This is not needed if you use bool. And this debug message is wrong btw since
you are not checking whether the device is in D3 state or not.

- Mani

> +	}
> +
> +	return 0;
> +}
> +
>  static const struct dw_pcie_ep_ops pci_ep_ops = {
>  	.ep_init = qcom_pcie_ep_init,
>  	.raise_irq = qcom_pcie_ep_raise_irq,
>  	.get_features = qcom_pcie_epc_get_features,
> +	.wakeup_host = qcom_pcie_ep_wakeup_host,
>  };
>  
>  static int qcom_pcie_ep_probe(struct platform_device *pdev)
> -- 
> 2.7.4
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 7/8] PCI: epf-mhi: Add wakeup host op
  2023-06-30 10:52 ` [PATCH v2 7/8] PCI: epf-mhi: Add wakeup host op Krishna chaitanya chundru
@ 2023-07-07  6:14   ` Manivannan Sadhasivam
  2023-07-07 11:00     ` Krishna Chaitanya Chundru
  0 siblings, 1 reply; 24+ messages in thread
From: Manivannan Sadhasivam @ 2023-07-07  6:14 UTC (permalink / raw)
  To: Krishna chaitanya chundru
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Kishon Vijay Abraham I, Bjorn Helgaas,
	Jeffrey Hugo, open list:MHI BUS

On Fri, Jun 30, 2023 at 04:22:10PM +0530, Krishna chaitanya chundru wrote:
> Add wakeup host op for MHI EPF.
> If the D-state is in D3cold toggle wake signal, otherwise send PME.
> 
> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
> ---
>  drivers/pci/endpoint/functions/pci-epf-mhi.c | 19 +++++++++++++++++++
>  include/linux/mhi_ep.h                       |  1 +
>  2 files changed, 20 insertions(+)
> 
> diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> index 64ff37d..deb742c 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-mhi.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> @@ -237,6 +237,24 @@ static int pci_epf_mhi_write_to_host(struct mhi_ep_cntrl *mhi_cntrl,
>  	return 0;
>  }
>  
> +static int pci_epf_mhi_wakeup_host(struct mhi_ep_cntrl *mhi_cntrl)
> +{
> +	struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
> +	struct pci_epf *epf = epf_mhi->epf;
> +	struct pci_epc *epc = epf->epc;
> +	int ret;
> +
> +	if (mhi_cntrl->dstate == PCI_D3cold)
> +		ret = pci_epc_wakeup_host(epc, epf->func_no,
> +					epf->vfunc_no, PCI_WAKEUP_TOGGLE_WAKE);
> +	else
> +		ret = pci_epc_wakeup_host(epc, epf->func_no,
> +					epf->vfunc_no, PCI_WAKEUP_SEND_PME);
> +

If the wakeup argument is of type bool (ie. bool use_pme), then

	wakeup = (mhi_cntrl->dstate == PCI_D3cold) ? false : true;

	return pci_epc_wakeup_host(epc, epf->func_no, epf->vfunc_no, state);

- Mani

> +	return ret;
> +
> +}
> +
>  static int pci_epf_mhi_core_init(struct pci_epf *epf)
>  {
>  	struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
> @@ -293,6 +311,7 @@ static int pci_epf_mhi_link_up(struct pci_epf *epf)
>  	mhi_cntrl->unmap_free = pci_epf_mhi_unmap_free;
>  	mhi_cntrl->read_from_host = pci_epf_mhi_read_from_host;
>  	mhi_cntrl->write_to_host = pci_epf_mhi_write_to_host;
> +	mhi_cntrl->wakeup_host = pci_epf_mhi_wakeup_host;
>  
>  	/* Register the MHI EP controller */
>  	ret = mhi_ep_register_controller(mhi_cntrl, info->config);
> diff --git a/include/linux/mhi_ep.h b/include/linux/mhi_ep.h
> index c3a0685..e353c429 100644
> --- a/include/linux/mhi_ep.h
> +++ b/include/linux/mhi_ep.h
> @@ -137,6 +137,7 @@ struct mhi_ep_cntrl {
>  			   void __iomem *virt, size_t size);
>  	int (*read_from_host)(struct mhi_ep_cntrl *mhi_cntrl, u64 from, void *to, size_t size);
>  	int (*write_to_host)(struct mhi_ep_cntrl *mhi_cntrl, void *from, u64 to, size_t size);
> +	int (*wakeup_host)(struct mhi_ep_cntrl *mhi_cntrl);
>  
>  	enum mhi_state mhi_state;
>  
> -- 
> 2.7.4
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 8/8] bus: mhi: ep: wake up host is the MHI state is in M3
  2023-06-30 10:52 ` [PATCH v2 8/8] bus: mhi: ep: wake up host is the MHI state is in M3 Krishna chaitanya chundru
@ 2023-07-07  6:20   ` Manivannan Sadhasivam
  2023-07-07 11:01     ` Krishna Chaitanya Chundru
  0 siblings, 1 reply; 24+ messages in thread
From: Manivannan Sadhasivam @ 2023-07-07  6:20 UTC (permalink / raw)
  To: Krishna chaitanya chundru
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Jeffrey Hugo,
	Rafael J. Wysocki, Dan Carpenter, Greg Kroah-Hartman, Bo Liu,
	open list:MHI BUS

On Fri, Jun 30, 2023 at 04:22:11PM +0530, Krishna chaitanya chundru wrote:
> If the MHI state is in M3 then the most probably the host kept the
> device in D3 hot or D3 cold, due to that endpoint transctions will not
> be read by the host, so endpoint needs to bring the host to D0 which
> eventually bring back the MHI state to M0.
> 

Endpoint cannot bring the host to D0, it can only wake up the host and the host
will bring the device to D0.

> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
> ---
>  drivers/bus/mhi/ep/main.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c
> index 6008818..42d3791 100644
> --- a/drivers/bus/mhi/ep/main.c
> +++ b/drivers/bus/mhi/ep/main.c
> @@ -451,12 +451,14 @@ int mhi_ep_queue_skb(struct mhi_ep_device *mhi_dev, struct sk_buff *skb)
>  	struct mhi_ep_cntrl *mhi_cntrl = mhi_dev->mhi_cntrl;
>  	struct mhi_ep_chan *mhi_chan = mhi_dev->dl_chan;
>  	struct device *dev = &mhi_chan->mhi_dev->dev;
> +	u32 buf_left, read_offset, count = 0;
>  	struct mhi_ring_element *el;
> -	u32 buf_left, read_offset;
>  	struct mhi_ep_ring *ring;
>  	enum mhi_ev_ccs code;
> +	enum mhi_state state;
>  	void *read_addr;
>  	u64 write_addr;
> +	bool mhi_reset;
>  	size_t tr_len;
>  	u32 tre_len;
>  	int ret;
> @@ -464,6 +466,18 @@ int mhi_ep_queue_skb(struct mhi_ep_device *mhi_dev, struct sk_buff *skb)
>  	buf_left = skb->len;
>  	ring = &mhi_cntrl->mhi_chan[mhi_chan->chan].ring;
>  
> +	if (mhi_cntrl->mhi_state == MHI_STATE_M3) {
> +		dev_dbg(dev, "wake up by ch id %x\n", mhi_chan->chan);

This is not needed.

> +		mhi_cntrl->wakeup_host(mhi_cntrl);
> +	}
> +
> +	/* Wait for Host to set the M0 state */
> +	do {
> +		msleep(M0_WAIT_DELAY_MS);
> +		mhi_ep_mmio_get_mhi_state(mhi_cntrl, &state, &mhi_reset);
> +		count++;
> +	} while (state != MHI_STATE_M0 && count < M0_WAIT_COUNT);
> +

Move this change to a function like mhi_ep_wake_host().

- Mani

>  	mutex_lock(&mhi_chan->lock);
>  
>  	do {
> -- 
> 2.7.4
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 1/8] PCI: endpoint: Add dstate change notifier support
  2023-07-07  5:44   ` Manivannan Sadhasivam
@ 2023-07-07 10:52     ` Krishna Chaitanya Chundru
  0 siblings, 0 replies; 24+ messages in thread
From: Krishna Chaitanya Chundru @ 2023-07-07 10:52 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Kishon Vijay Abraham I, Bjorn Helgaas,
	Jonathan Corbet, open list:DOCUMENTATION


On 7/7/2023 11:14 AM, Manivannan Sadhasivam wrote:
> On Fri, Jun 30, 2023 at 04:22:04PM +0530, Krishna chaitanya chundru wrote:
>> Add support to notify the EPF device about the D-state change event
>> from the EPC device.
>>
>> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
>> ---
>>   Documentation/PCI/endpoint/pci-endpoint.rst |  5 +++++
>>   drivers/pci/endpoint/pci-epc-core.c         | 27 +++++++++++++++++++++++++++
>>   include/linux/pci-epc.h                     |  1 +
>>   include/linux/pci-epf.h                     |  1 +
>>   4 files changed, 34 insertions(+)
>>
>> diff --git a/Documentation/PCI/endpoint/pci-endpoint.rst b/Documentation/PCI/endpoint/pci-endpoint.rst
>> index 4f5622a..0538cdc 100644
>> --- a/Documentation/PCI/endpoint/pci-endpoint.rst
>> +++ b/Documentation/PCI/endpoint/pci-endpoint.rst
>> @@ -78,6 +78,11 @@ by the PCI controller driver.
>>      Cleanup the pci_epc_mem structure allocated during pci_epc_mem_init().
>>   
>>   
>> +* pci_epc_dstate_change()
>> +
>> +   In order to notify all the function devices that the EPC device has
>> +   changed its D-state.
>> +
>>   EPC APIs for the PCI Endpoint Function Driver
>>   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>   
>> diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
>> index 6c54fa5..cad360f 100644
>> --- a/drivers/pci/endpoint/pci-epc-core.c
>> +++ b/drivers/pci/endpoint/pci-epc-core.c
>> @@ -785,6 +785,33 @@ void pci_epc_bme_notify(struct pci_epc *epc)
>>   EXPORT_SYMBOL_GPL(pci_epc_bme_notify);
>>   
>>   /**
>> + * pci_epc_dstate_change() - Notify the EPF device 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 has D-state has
>> + * changed.
>> + */
>> +void pci_epc_dstate_change(struct pci_epc *epc, pci_power_t state)
> How about "pci_epc_dstate_notity()"?
>
> Rest looks good.
>
> - Mani

sure I will change to pci_epc_dstate_notity

-KC

>
>> +{
>> +	struct pci_epf *epf;
>> +
>> +	if (!epc || IS_ERR(epc))
>> +		return;
>> +
>> +	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_change)
>> +			epf->event_ops->dstate_change(epf, state);
>> +		mutex_unlock(&epf->lock);
>> +	}
>> +	mutex_unlock(&epc->list_lock);
>> +}
>> +EXPORT_SYMBOL_GPL(pci_epc_dstate_change);
>> +
>> +/**
>>    * pci_epc_destroy() - destroy the EPC device
>>    * @epc: the EPC device that has to be destroyed
>>    *
>> diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
>> index 5cb6940..26a1108 100644
>> --- a/include/linux/pci-epc.h
>> +++ b/include/linux/pci-epc.h
>> @@ -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_change(struct pci_epc *epc, pci_power_t state);
>>   #endif /* __LINUX_PCI_EPC_H */
>> diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
>> index 4b52807..1d3c2a2 100644
>> --- a/include/linux/pci-epf.h
>> +++ b/include/linux/pci-epf.h
>> @@ -79,6 +79,7 @@ struct pci_epc_event_ops {
>>   	int (*link_up)(struct pci_epf *epf);
>>   	int (*link_down)(struct pci_epf *epf);
>>   	int (*bme)(struct pci_epf *epf);
>> +	int (*dstate_change)(struct pci_epf *epf, pci_power_t state);
>>   };
>>   
>>   /**
>> -- 
>> 2.7.4
>>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 2/8] PCI: qcom-ep: Add support for D-state change notification
  2023-07-07  5:51   ` Manivannan Sadhasivam
@ 2023-07-07 10:54     ` Krishna Chaitanya Chundru
  0 siblings, 0 replies; 24+ messages in thread
From: Krishna Chaitanya Chundru @ 2023-07-07 10:54 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas


On 7/7/2023 11:21 AM, Manivannan Sadhasivam wrote:
> On Fri, Jun 30, 2023 at 04:22:05PM +0530, Krishna chaitanya chundru wrote:
>> Add support to pass D-state change notification to Endpoint
>> function driver.
>>
>> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
> Few comments below.
>
>> ---
>>   drivers/pci/controller/dwc/pcie-qcom-ep.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
>> index 1435f51..e75aec4 100644
>> --- a/drivers/pci/controller/dwc/pcie-qcom-ep.c
>> +++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c
>> @@ -561,6 +561,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);
>> @@ -583,11 +584,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);
> We should also change this debug output to make use of pci_power_name() based on
> the "state" variable and move it just above pci_epc_dstate_change(). But this
> should be a separate patch.
I will add a seperate patch in the same series
>
>> +		state = dstate;
>>   		if (dstate == 3) {
>>   			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);
>> +			state = PCI_D3hot;
>> +			if (gpiod_get_value(pcie_ep->reset))
>> +				state = PCI_D3cold;
>>   		}
>> +		pci_epc_dstate_change(pci->ep.epc, state);
> Need to change this API as per my comment on patch 1.
>
> - Mani

sure will change it as you suggested.

- KC

>
>>   	} 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);
>> -- 
>> 2.7.4
>>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 3/8] PCI: epf-mhi: Add dtate change op
  2023-07-07  5:59   ` Manivannan Sadhasivam
@ 2023-07-07 10:55     ` Krishna Chaitanya Chundru
  0 siblings, 0 replies; 24+ messages in thread
From: Krishna Chaitanya Chundru @ 2023-07-07 10:55 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Kishon Vijay Abraham I, Bjorn Helgaas,
	Jeffrey Hugo, open list:MHI BUS


On 7/7/2023 11:29 AM, Manivannan Sadhasivam wrote:
> On Fri, Jun 30, 2023 at 04:22:06PM +0530, Krishna chaitanya chundru wrote:
>> Add dstate host op for MHI EPF.
>>
> Use "D-state" everywhere. Also the subject should be:
>
> "PCI: epf-mhi: Add support for handling D-state notification from EPC"
>
> Fix the commit message accordingly.
I will change it as you suggested.
>
>> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
>> ---
>>   drivers/pci/endpoint/functions/pci-epf-mhi.c | 13 +++++++++++++
>>   include/linux/mhi_ep.h                       |  3 +++
>>   2 files changed, 16 insertions(+)
>>
>> diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
>> index 9c1f5a1..64ff37d 100644
>> --- a/drivers/pci/endpoint/functions/pci-epf-mhi.c
>> +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
>> @@ -339,6 +339,18 @@ static int pci_epf_mhi_bme(struct pci_epf *epf)
>>   	return 0;
>>   }
>>   
>> +static int pci_epf_mhi_dstate_change(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;
>> +	struct device *dev = &epf->dev;
>> +
>> +	mhi_cntrl->dstate = state;
>> +	dev_info(dev, "D-state changeg to %s\n", pci_power_name(state));
> This can be removed since we already print the state in pci driver.
>
> - Mani

ok

- KC

>
>> +
>> +	return 0;
>> +}
>> +
>>   static int pci_epf_mhi_bind(struct pci_epf *epf)
>>   {
>>   	struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
>> @@ -394,6 +406,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_change = pci_epf_mhi_dstate_change,
>>   };
>>   
>>   static int pci_epf_mhi_probe(struct pci_epf *epf,
>> diff --git a/include/linux/mhi_ep.h b/include/linux/mhi_ep.h
>> index f198a8a..c3a0685 100644
>> --- a/include/linux/mhi_ep.h
>> +++ b/include/linux/mhi_ep.h
>> @@ -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;
>> -- 
>> 2.7.4
>>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 4/8] PCI: endpoint: Add wakeup host API to EPC core
  2023-07-07  6:04   ` Manivannan Sadhasivam
@ 2023-07-07 10:57     ` Krishna Chaitanya Chundru
  0 siblings, 0 replies; 24+ messages in thread
From: Krishna Chaitanya Chundru @ 2023-07-07 10:57 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Kishon Vijay Abraham I, Bjorn Helgaas,
	Jonathan Corbet, open list:DOCUMENTATION


On 7/7/2023 11:34 AM, Manivannan Sadhasivam wrote:
> On Fri, Jun 30, 2023 at 04:22:07PM +0530, Krishna chaitanya chundru wrote:
>> Endpoint cannot send any data/MSI when the D-state is in
>> D3cold or D3hot. Endpoint needs to bring the host back to D0
> Endpoint needs to wake up the host to bring the D-state to D0
>
>> to send any kind of data.
>>
>> Endpoint can toggle wake signal when the D-state is in D3cold and vaux is
>> not supplied or can send inband PME.
>>
>> To support this adding wake up host to epc core.
>>
> "add wakeup_host() callback to the EPC core".
>
>
>> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
>> ---
>>   Documentation/PCI/endpoint/pci-endpoint.rst |  6 ++++++
>>   drivers/pci/endpoint/pci-epc-core.c         | 31 +++++++++++++++++++++++++++++
>>   include/linux/pci-epc.h                     | 11 ++++++++++
>>   3 files changed, 48 insertions(+)
>>
>> diff --git a/Documentation/PCI/endpoint/pci-endpoint.rst b/Documentation/PCI/endpoint/pci-endpoint.rst
>> index 0538cdc..186ce3b 100644
>> --- a/Documentation/PCI/endpoint/pci-endpoint.rst
>> +++ b/Documentation/PCI/endpoint/pci-endpoint.rst
>> @@ -53,6 +53,7 @@ by the PCI controller driver.
>>   	 * raise_irq: ops to raise a legacy, MSI or MSI-X interrupt
>>   	 * start: ops to start the PCI link
>>   	 * stop: ops to stop the PCI link
>> +	 * wakeup_host: ops to wake host
> wakeup
>
>>   
>>      The PCI controller driver can then create a new EPC device by invoking
>>      devm_pci_epc_create()/pci_epc_create().
>> @@ -122,6 +123,11 @@ by the PCI endpoint function driver.
>>      The PCI endpoint function driver should use pci_epc_mem_free_addr() to
>>      free the memory space allocated using pci_epc_mem_alloc_addr().
>>   
>> +* pci_epc_wakeup_host()
>> +
>> +   The PCI endpoint function driver should use pci_epc_wakeup_host() to wake
> wakeup
>
>> +   host.
>> +
>>   Other EPC APIs
>>   ~~~~~~~~~~~~~~
>>   
>> diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
>> index cad360f..23599b8 100644
>> --- a/drivers/pci/endpoint/pci-epc-core.c
>> +++ b/drivers/pci/endpoint/pci-epc-core.c
>> @@ -167,6 +167,37 @@ const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
>>   EXPORT_SYMBOL_GPL(pci_epc_get_features);
>>   
>>   /**
>> + * pci_epc_wakeup_host() - Wakeup the host
>> + * @epc: the EPC device which has to wake the host
> wakeup
>
>> + * @func_no: the physical endpoint function number in the EPC device
>> + * @vfunc_no: the virtual endpoint function number in the physical function
>> + * @type: specify the type of wakeup: WAKEUP_FROM_D3COLD, WAKEUP_FROM_D3HOT
>> + *
>> + * Invoke to wakeup host
>> + */
>> +int pci_epc_wakeup_host(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
>> +			enum pci_epc_wakeup_host_type type)
> Why can't you use a bool?
>
> - Mani

Sure I will change it to bool as suggested.

- KC

>
>> +{
>> +	int ret;
>> +
>> +	if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
>> +		return -EINVAL;
>> +
>> +	if (vfunc_no > 0 && (!epc->max_vfs || vfunc_no > epc->max_vfs[func_no]))
>> +		return -EINVAL;
>> +
>> +	if (!epc->ops->wakeup_host)
>> +		return 0;
>> +
>> +	mutex_lock(&epc->lock);
>> +	ret = epc->ops->wakeup_host(epc, func_no, vfunc_no, type);
>> +	mutex_unlock(&epc->lock);
>> +
>> +	return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(pci_epc_wakeup_host);
>> +
>> +/**
>>    * pci_epc_stop() - stop the PCI link
>>    * @epc: the link of the EPC device that has to be stopped
>>    *
>> diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
>> index 26a1108..2323a10 100644
>> --- a/include/linux/pci-epc.h
>> +++ b/include/linux/pci-epc.h
>> @@ -26,6 +26,12 @@ enum pci_epc_irq_type {
>>   	PCI_EPC_IRQ_MSIX,
>>   };
>>   
>> +enum pci_epc_wakeup_host_type {
>> +	PCI_WAKEUP_UNKNOWN,
>> +	PCI_WAKEUP_SEND_PME,
>> +	PCI_WAKEUP_TOGGLE_WAKE,
>> +};
>> +
>>   static inline const char *
>>   pci_epc_interface_string(enum pci_epc_interface_type type)
>>   {
>> @@ -59,6 +65,7 @@ pci_epc_interface_string(enum pci_epc_interface_type type)
>>    * @start: ops to start the PCI link
>>    * @stop: ops to stop the PCI link
>>    * @get_features: ops to get the features supported by the EPC
>> + * @wakeup_host: ops to wakeup the host
>>    * @owner: the module owner containing the ops
>>    */
>>   struct pci_epc_ops {
>> @@ -88,6 +95,8 @@ struct pci_epc_ops {
>>   	void	(*stop)(struct pci_epc *epc);
>>   	const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
>>   						       u8 func_no, u8 vfunc_no);
>> +	int	(*wakeup_host)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
>> +				enum pci_epc_wakeup_host_type type);
>>   	struct module *owner;
>>   };
>>   
>> @@ -234,6 +243,8 @@ int pci_epc_start(struct pci_epc *epc);
>>   void pci_epc_stop(struct pci_epc *epc);
>>   const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
>>   						    u8 func_no, u8 vfunc_no);
>> +int pci_epc_wakeup_host(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
>> +					enum pci_epc_wakeup_host_type type);
>>   enum pci_barno
>>   pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features);
>>   enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features
>> -- 
>> 2.7.4
>>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 6/8] PCI: qcom: ep: Add wake up host op to dw_pcie_ep_ops
  2023-07-07  6:10   ` Manivannan Sadhasivam
@ 2023-07-07 10:58     ` Krishna Chaitanya Chundru
  0 siblings, 0 replies; 24+ messages in thread
From: Krishna Chaitanya Chundru @ 2023-07-07 10:58 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas


On 7/7/2023 11:40 AM, Manivannan Sadhasivam wrote:
> On Fri, Jun 30, 2023 at 04:22:09PM +0530, Krishna chaitanya chundru wrote:
>
> Subject prefix should be "PCI: qcom-ep:"
>
>> Add wakeup host op to dw_pcie_ep_ops to wake up host.
>> If the EPF asks to send PME trigger the inband PME by writing
>> into the parf registers otherwise toggle wake signal.
>>
> If the wakeup type is PME, then trigger inband PME by writing to the PARF
> PARF_PM_CTRL register, otherwise toggle #WAKE.
>
>> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
>> ---
>>   drivers/pci/controller/dwc/pcie-qcom-ep.c | 31 +++++++++++++++++++++++++++++++
>>   1 file changed, 31 insertions(+)
>>
>> diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
>> index e75aec4..e382b4b 100644
>> --- a/drivers/pci/controller/dwc/pcie-qcom-ep.c
>> +++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c
>> @@ -89,6 +89,7 @@
>>   /* PARF_PM_CTRL register fields */
>>   #define PARF_PM_CTRL_REQ_EXIT_L1		BIT(1)
>>   #define PARF_PM_CTRL_READY_ENTR_L23		BIT(2)
>> +#define PARF_PM_CTRL_XMT_PME			BIT(4)
>>   #define PARF_PM_CTRL_REQ_NOT_ENTR_L1		BIT(5)
>>   
>>   /* PARF_MHI_CLOCK_RESET_CTRL fields */
>> @@ -729,10 +730,40 @@ static void qcom_pcie_ep_init(struct dw_pcie_ep *ep)
>>   		dw_pcie_ep_reset_bar(pci, bar);
>>   }
>>   
>> +static int qcom_pcie_ep_wakeup_host(struct dw_pcie_ep *ep, u8 func_no,
>> +					enum pci_epc_wakeup_host_type type)
>> +{
>> +	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
>> +	struct qcom_pcie_ep *pcie_ep = to_pcie_ep(pci);
>> +	struct device *dev = pci->dev;
>> +	u32 val;
>> +
>> +	if (type == PCI_WAKEUP_TOGGLE_WAKE) {
>> +		dev_dbg(dev, "Waking up the host by toggling WAKE#\n");
>> +		gpiod_set_value_cansleep(pcie_ep->wake, 1);
>> +		usleep_range(WAKE_DELAY_US, WAKE_DELAY_US + 500);
>> +		gpiod_set_value_cansleep(pcie_ep->wake, 0);
>> +		return 0;
>> +
>> +	} else if (type == PCI_WAKEUP_SEND_PME) {
>> +		dev_dbg(dev, "Waking up the host using PME\n");
>> +		val = readl_relaxed(pcie_ep->parf + PARF_PM_CTRL);
>> +		val |= PARF_PM_CTRL_XMT_PME;
>> +		writel_relaxed(val, pcie_ep->parf + PARF_PM_CTRL);
>> +
>> +	} else {
>> +		dev_err(dev, "Device is not in D3 state wakeup is not supported\n");
>> +		return -EOPNOTSUPP;
> This is not needed if you use bool. And this debug message is wrong btw since
> you are not checking whether the device is in D3 state or not.
>
> - Mani

I will change it bool and will remove these.

- KC

>
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>>   static const struct dw_pcie_ep_ops pci_ep_ops = {
>>   	.ep_init = qcom_pcie_ep_init,
>>   	.raise_irq = qcom_pcie_ep_raise_irq,
>>   	.get_features = qcom_pcie_epc_get_features,
>> +	.wakeup_host = qcom_pcie_ep_wakeup_host,
>>   };
>>   
>>   static int qcom_pcie_ep_probe(struct platform_device *pdev)
>> -- 
>> 2.7.4
>>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 7/8] PCI: epf-mhi: Add wakeup host op
  2023-07-07  6:14   ` Manivannan Sadhasivam
@ 2023-07-07 11:00     ` Krishna Chaitanya Chundru
  0 siblings, 0 replies; 24+ messages in thread
From: Krishna Chaitanya Chundru @ 2023-07-07 11:00 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Kishon Vijay Abraham I, Bjorn Helgaas,
	Jeffrey Hugo, open list:MHI BUS


On 7/7/2023 11:44 AM, Manivannan Sadhasivam wrote:
> On Fri, Jun 30, 2023 at 04:22:10PM +0530, Krishna chaitanya chundru wrote:
>> Add wakeup host op for MHI EPF.
>> If the D-state is in D3cold toggle wake signal, otherwise send PME.
>>
>> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
>> ---
>>   drivers/pci/endpoint/functions/pci-epf-mhi.c | 19 +++++++++++++++++++
>>   include/linux/mhi_ep.h                       |  1 +
>>   2 files changed, 20 insertions(+)
>>
>> diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
>> index 64ff37d..deb742c 100644
>> --- a/drivers/pci/endpoint/functions/pci-epf-mhi.c
>> +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
>> @@ -237,6 +237,24 @@ static int pci_epf_mhi_write_to_host(struct mhi_ep_cntrl *mhi_cntrl,
>>   	return 0;
>>   }
>>   
>> +static int pci_epf_mhi_wakeup_host(struct mhi_ep_cntrl *mhi_cntrl)
>> +{
>> +	struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
>> +	struct pci_epf *epf = epf_mhi->epf;
>> +	struct pci_epc *epc = epf->epc;
>> +	int ret;
>> +
>> +	if (mhi_cntrl->dstate == PCI_D3cold)
>> +		ret = pci_epc_wakeup_host(epc, epf->func_no,
>> +					epf->vfunc_no, PCI_WAKEUP_TOGGLE_WAKE);
>> +	else
>> +		ret = pci_epc_wakeup_host(epc, epf->func_no,
>> +					epf->vfunc_no, PCI_WAKEUP_SEND_PME);
>> +
> If the wakeup argument is of type bool (ie. bool use_pme), then
>
> 	wakeup = (mhi_cntrl->dstate == PCI_D3cold) ? false : true;
>
> 	return pci_epc_wakeup_host(epc, epf->func_no, epf->vfunc_no, state);
>
> - Mani

better to use type as it as it has more readability

but I have taken your inputs here and will change the code as suggetsed.

- KC

>> +	return ret;
>> +
>> +}
>> +
>>   static int pci_epf_mhi_core_init(struct pci_epf *epf)
>>   {
>>   	struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
>> @@ -293,6 +311,7 @@ static int pci_epf_mhi_link_up(struct pci_epf *epf)
>>   	mhi_cntrl->unmap_free = pci_epf_mhi_unmap_free;
>>   	mhi_cntrl->read_from_host = pci_epf_mhi_read_from_host;
>>   	mhi_cntrl->write_to_host = pci_epf_mhi_write_to_host;
>> +	mhi_cntrl->wakeup_host = pci_epf_mhi_wakeup_host;
>>   
>>   	/* Register the MHI EP controller */
>>   	ret = mhi_ep_register_controller(mhi_cntrl, info->config);
>> diff --git a/include/linux/mhi_ep.h b/include/linux/mhi_ep.h
>> index c3a0685..e353c429 100644
>> --- a/include/linux/mhi_ep.h
>> +++ b/include/linux/mhi_ep.h
>> @@ -137,6 +137,7 @@ struct mhi_ep_cntrl {
>>   			   void __iomem *virt, size_t size);
>>   	int (*read_from_host)(struct mhi_ep_cntrl *mhi_cntrl, u64 from, void *to, size_t size);
>>   	int (*write_to_host)(struct mhi_ep_cntrl *mhi_cntrl, void *from, u64 to, size_t size);
>> +	int (*wakeup_host)(struct mhi_ep_cntrl *mhi_cntrl);
>>   
>>   	enum mhi_state mhi_state;
>>   
>> -- 
>> 2.7.4
>>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 8/8] bus: mhi: ep: wake up host is the MHI state is in M3
  2023-07-07  6:20   ` Manivannan Sadhasivam
@ 2023-07-07 11:01     ` Krishna Chaitanya Chundru
  0 siblings, 0 replies; 24+ messages in thread
From: Krishna Chaitanya Chundru @ 2023-07-07 11:01 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: manivannan.sadhasivam, helgaas, linux-pci, linux-arm-msm,
	linux-kernel, quic_vbadigan, quic_nitegupt, quic_skananth,
	quic_ramkri, krzysztof.kozlowski, Jeffrey Hugo,
	Rafael J. Wysocki, Dan Carpenter, Greg Kroah-Hartman, Bo Liu,
	open list:MHI BUS


On 7/7/2023 11:50 AM, Manivannan Sadhasivam wrote:
> On Fri, Jun 30, 2023 at 04:22:11PM +0530, Krishna chaitanya chundru wrote:
>> If the MHI state is in M3 then the most probably the host kept the
>> device in D3 hot or D3 cold, due to that endpoint transctions will not
>> be read by the host, so endpoint needs to bring the host to D0 which
>> eventually bring back the MHI state to M0.
>>
> Endpoint cannot bring the host to D0, it can only wake up the host and the host
> will bring the device to D0.
>
>> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
>> ---
>>   drivers/bus/mhi/ep/main.c | 16 +++++++++++++++-
>>   1 file changed, 15 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c
>> index 6008818..42d3791 100644
>> --- a/drivers/bus/mhi/ep/main.c
>> +++ b/drivers/bus/mhi/ep/main.c
>> @@ -451,12 +451,14 @@ int mhi_ep_queue_skb(struct mhi_ep_device *mhi_dev, struct sk_buff *skb)
>>   	struct mhi_ep_cntrl *mhi_cntrl = mhi_dev->mhi_cntrl;
>>   	struct mhi_ep_chan *mhi_chan = mhi_dev->dl_chan;
>>   	struct device *dev = &mhi_chan->mhi_dev->dev;
>> +	u32 buf_left, read_offset, count = 0;
>>   	struct mhi_ring_element *el;
>> -	u32 buf_left, read_offset;
>>   	struct mhi_ep_ring *ring;
>>   	enum mhi_ev_ccs code;
>> +	enum mhi_state state;
>>   	void *read_addr;
>>   	u64 write_addr;
>> +	bool mhi_reset;
>>   	size_t tr_len;
>>   	u32 tre_len;
>>   	int ret;
>> @@ -464,6 +466,18 @@ int mhi_ep_queue_skb(struct mhi_ep_device *mhi_dev, struct sk_buff *skb)
>>   	buf_left = skb->len;
>>   	ring = &mhi_cntrl->mhi_chan[mhi_chan->chan].ring;
>>   
>> +	if (mhi_cntrl->mhi_state == MHI_STATE_M3) {
>> +		dev_dbg(dev, "wake up by ch id %x\n", mhi_chan->chan);
> This is not needed.
>
>> +		mhi_cntrl->wakeup_host(mhi_cntrl);
>> +	}
>> +
>> +	/* Wait for Host to set the M0 state */
>> +	do {
>> +		msleep(M0_WAIT_DELAY_MS);
>> +		mhi_ep_mmio_get_mhi_state(mhi_cntrl, &state, &mhi_reset);
>> +		count++;
>> +	} while (state != MHI_STATE_M0 && count < M0_WAIT_COUNT);
>> +
> Move this change to a function like mhi_ep_wake_host().
>
> - Mani

Sure I will change it in next patch.

- KC

>
>>   	mutex_lock(&mhi_chan->lock);
>>   
>>   	do {
>> -- 
>> 2.7.4
>>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 2/8] PCI: qcom-ep: Add support for D-state change notification
  2023-06-30 10:52 ` [PATCH v2 2/8] PCI: qcom-ep: Add support for D-state change notification Krishna chaitanya chundru
  2023-07-07  5:51   ` Manivannan Sadhasivam
@ 2023-07-13 20:04   ` kernel test robot
  1 sibling, 0 replies; 24+ messages in thread
From: kernel test robot @ 2023-07-13 20:04 UTC (permalink / raw)
  To: Krishna chaitanya chundru, manivannan.sadhasivam
  Cc: oe-kbuild-all, helgaas, linux-pci, linux-arm-msm, linux-kernel,
	quic_vbadigan, quic_nitegupt, quic_skananth, quic_ramkri,
	krzysztof.kozlowski, Krishna chaitanya chundru,
	Manivannan Sadhasivam, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring

Hi Krishna,

kernel test robot noticed the following build warnings:

[auto build test WARNING on pci/next]
[also build test WARNING on pci/for-linus linus/master v6.5-rc1 next-20230713]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Krishna-chaitanya-chundru/PCI-endpoint-Add-dstate-change-notifier-support/20230630-190228
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next
patch link:    https://lore.kernel.org/r/1688122331-25478-3-git-send-email-quic_krichai%40quicinc.com
patch subject: [PATCH v2 2/8] PCI: qcom-ep: Add support for D-state change notification
config: arm-randconfig-r081-20230713 (https://download.01.org/0day-ci/archive/20230714/202307140321.wjx00mop-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230714/202307140321.wjx00mop-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307140321.wjx00mop-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/pci/controller/dwc/pcie-qcom-ep.c:587:23: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted pci_power_t [usertype] state @@     got unsigned int [assigned] [usertype] dstate @@
   drivers/pci/controller/dwc/pcie-qcom-ep.c:587:23: sparse:     expected restricted pci_power_t [usertype] state
   drivers/pci/controller/dwc/pcie-qcom-ep.c:587:23: sparse:     got unsigned int [assigned] [usertype] dstate

vim +587 drivers/pci/controller/dwc/pcie-qcom-ep.c

   555	
   556	/* TODO: Notify clients about PCIe state change */
   557	static irqreturn_t qcom_pcie_ep_global_irq_thread(int irq, void *data)
   558	{
   559		struct qcom_pcie_ep *pcie_ep = data;
   560		struct dw_pcie *pci = &pcie_ep->pci;
   561		struct device *dev = pci->dev;
   562		u32 status = readl_relaxed(pcie_ep->parf + PARF_INT_ALL_STATUS);
   563		u32 mask = readl_relaxed(pcie_ep->parf + PARF_INT_ALL_MASK);
   564		pci_power_t state;
   565		u32 dstate, val;
   566	
   567		writel_relaxed(status, pcie_ep->parf + PARF_INT_ALL_CLEAR);
   568		status &= mask;
   569	
   570		if (FIELD_GET(PARF_INT_ALL_LINK_DOWN, status)) {
   571			dev_dbg(dev, "Received Linkdown event\n");
   572			pcie_ep->link_status = QCOM_PCIE_EP_LINK_DOWN;
   573			pci_epc_linkdown(pci->ep.epc);
   574		} else if (FIELD_GET(PARF_INT_ALL_BME, status)) {
   575			dev_dbg(dev, "Received BME event. Link is enabled!\n");
   576			pcie_ep->link_status = QCOM_PCIE_EP_LINK_ENABLED;
   577			pci_epc_bme_notify(pci->ep.epc);
   578		} else if (FIELD_GET(PARF_INT_ALL_PM_TURNOFF, status)) {
   579			dev_dbg(dev, "Received PM Turn-off event! Entering L23\n");
   580			val = readl_relaxed(pcie_ep->parf + PARF_PM_CTRL);
   581			val |= PARF_PM_CTRL_READY_ENTR_L23;
   582			writel_relaxed(val, pcie_ep->parf + PARF_PM_CTRL);
   583		} else if (FIELD_GET(PARF_INT_ALL_DSTATE_CHANGE, status)) {
   584			dstate = dw_pcie_readl_dbi(pci, DBI_CON_STATUS) &
   585						   DBI_CON_STATUS_POWER_STATE_MASK;
   586			dev_dbg(dev, "Received D%d state event\n", dstate);
 > 587			state = dstate;
   588			if (dstate == 3) {
   589				val = readl_relaxed(pcie_ep->parf + PARF_PM_CTRL);
   590				val |= PARF_PM_CTRL_REQ_EXIT_L1;
   591				writel_relaxed(val, pcie_ep->parf + PARF_PM_CTRL);
   592				state = PCI_D3hot;
   593				if (gpiod_get_value(pcie_ep->reset))
   594					state = PCI_D3cold;
   595			}
   596			pci_epc_dstate_change(pci->ep.epc, state);
   597		} else if (FIELD_GET(PARF_INT_ALL_LINK_UP, status)) {
   598			dev_dbg(dev, "Received Linkup event. Enumeration complete!\n");
   599			dw_pcie_ep_linkup(&pci->ep);
   600			pcie_ep->link_status = QCOM_PCIE_EP_LINK_UP;
   601		} else {
   602			dev_dbg(dev, "Received unknown event: %d\n", status);
   603		}
   604	
   605		return IRQ_HANDLED;
   606	}
   607	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2023-07-13 20:05 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-30 10:52 [PATCH v2 0/8] PCCI: EPC: Add support to wake up host from D3 states Krishna chaitanya chundru
2023-06-30 10:52 ` [PATCH v2 1/8] PCI: endpoint: Add dstate change notifier support Krishna chaitanya chundru
2023-07-07  5:44   ` Manivannan Sadhasivam
2023-07-07 10:52     ` Krishna Chaitanya Chundru
2023-06-30 10:52 ` [PATCH v2 2/8] PCI: qcom-ep: Add support for D-state change notification Krishna chaitanya chundru
2023-07-07  5:51   ` Manivannan Sadhasivam
2023-07-07 10:54     ` Krishna Chaitanya Chundru
2023-07-13 20:04   ` kernel test robot
2023-06-30 10:52 ` [PATCH v2 3/8] PCI: epf-mhi: Add dtate change op Krishna chaitanya chundru
2023-07-07  5:59   ` Manivannan Sadhasivam
2023-07-07 10:55     ` Krishna Chaitanya Chundru
2023-06-30 10:52 ` [PATCH v2 4/8] PCI: endpoint: Add wakeup host API to EPC core Krishna chaitanya chundru
2023-07-07  6:04   ` Manivannan Sadhasivam
2023-07-07 10:57     ` Krishna Chaitanya Chundru
2023-06-30 10:52 ` [PATCH v2 5/8] pci: dwc: Add wakeup host op to pci_epc_ops Krishna chaitanya chundru
2023-06-30 10:52 ` [PATCH v2 6/8] PCI: qcom: ep: Add wake up host op to dw_pcie_ep_ops Krishna chaitanya chundru
2023-07-07  6:10   ` Manivannan Sadhasivam
2023-07-07 10:58     ` Krishna Chaitanya Chundru
2023-06-30 10:52 ` [PATCH v2 7/8] PCI: epf-mhi: Add wakeup host op Krishna chaitanya chundru
2023-07-07  6:14   ` Manivannan Sadhasivam
2023-07-07 11:00     ` Krishna Chaitanya Chundru
2023-06-30 10:52 ` [PATCH v2 8/8] bus: mhi: ep: wake up host is the MHI state is in M3 Krishna chaitanya chundru
2023-07-07  6:20   ` Manivannan Sadhasivam
2023-07-07 11:01     ` Krishna Chaitanya Chundru

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).