2021-06-16 12:27:52

by Manivannan Sadhasivam

[permalink] [raw]
Subject: [PATCH 0/5] PCI: endpoint: Add support for additional notifiers

Hello,

This series adds support for additional notifiers in the PCI endpoint
framework. The notifiers LINK_DOWN, BME, PME, and D_STATE are generic
for all PCI endpoints but there is also a custom notifier (CUSTOM) added
to pass the device/vendor specific events to EPF from EPC.

The example usage of all notifiers is provided in the commit description.

Thanks,
Mani

Manivannan Sadhasivam (5):
PCI: endpoint: Add linkdown notifier support
PCI: endpoint: Add BME notifier support
PCI: endpoint: Add PME notifier support
PCI: endpoint: Add D_STATE notifier support
PCI: endpoint: Add custom notifier support

drivers/pci/endpoint/pci-epc-core.c | 89 +++++++++++++++++++++++++++++
include/linux/pci-epc.h | 5 ++
include/linux/pci-epf.h | 5 ++
3 files changed, 99 insertions(+)

--
2.25.1


2021-06-16 12:28:01

by Manivannan Sadhasivam

[permalink] [raw]
Subject: [PATCH 2/5] PCI: endpoint: Add BME notifier support

Add support to notify the EPF device about the Bus Master Enable (BME)
event received by the EPC device from the Root complex.

Usage:
======

EPC
---

```
static irqreturn_t pcie_ep_irq(int irq, void *data)
{
...
case PCIE_EP_INT_BME:
pci_epc_bme_notify(epc);
break;
...
}
```

EPF
---

```
static int pci_epf_notifier(struct notifier_block *nb, unsigned long val,
void *data)
{
...
case BME:
/* Handle BME event */
break;
...
}
```

Signed-off-by: Manivannan Sadhasivam <[email protected]>
---
drivers/pci/endpoint/pci-epc-core.c | 17 +++++++++++++++++
include/linux/pci-epc.h | 1 +
include/linux/pci-epf.h | 1 +
3 files changed, 19 insertions(+)

diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index f29d78c18438..7e42a83a4877 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -675,6 +675,23 @@ void pci_epc_init_notify(struct pci_epc *epc)
}
EXPORT_SYMBOL_GPL(pci_epc_init_notify);

+/**
+ * pci_epc_bme_notify() - Notify the EPF device that the EPC device has received
+ * the BME event from the Root complex
+ * @epc: the EPC device that received the BME event
+ *
+ * Invoke to Notify the EPF device that the EPC device has received the Bus
+ * Master Enable (BME) event from the Root complex
+ */
+void pci_epc_bme_notify(struct pci_epc *epc)
+{
+ if (!epc || IS_ERR(epc))
+ return;
+
+ atomic_notifier_call_chain(&epc->notifier, BME, NULL);
+}
+EXPORT_SYMBOL_GPL(pci_epc_bme_notify);
+
/**
* 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 23590efc13e7..6c2cff33f670 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -204,6 +204,7 @@ int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf,
void pci_epc_linkup(struct pci_epc *epc);
void pci_epc_linkdown(struct pci_epc *epc);
void pci_epc_init_notify(struct pci_epc *epc);
+void pci_epc_bme_notify(struct pci_epc *epc);
void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
enum pci_epc_interface_type type);
int pci_epc_write_header(struct pci_epc *epc, u8 func_no,
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index e9ad634b1575..063a59a58e3c 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -21,6 +21,7 @@ enum pci_notify_event {
CORE_INIT,
LINK_UP,
LINK_DOWN,
+ BME,
};

enum pci_barno {
--
2.25.1

2021-06-16 13:23:00

by Manivannan Sadhasivam

[permalink] [raw]
Subject: [PATCH 3/5] PCI: endpoint: Add PME notifier support

Add support to notify the EPF device about the Power Management Event
(PME) received by the EPC device from the Root complex.

Usage:
======

EPC
---

```
static irqreturn_t pcie_ep_irq(int irq, void *data)
{
...
case PCIE_EP_INT_PM_TURNOFF:
pci_epc_pme_notify(epc, PCIE_EP_PM_TURNOFF);
break;
...
}
```

EPF
---

```
static int pci_epf_notifier(struct notifier_block *nb, unsigned long val,
void *data)
{
...
case PME:
pm_state = data;
if (pm_state == PCIE_EP_PM_TURNOFF)
/* Handle PM Turnoff event */
break;
...
}
```

Signed-off-by: Manivannan Sadhasivam <[email protected]>
---
drivers/pci/endpoint/pci-epc-core.c | 18 ++++++++++++++++++
include/linux/pci-epc.h | 1 +
include/linux/pci-epf.h | 1 +
3 files changed, 20 insertions(+)

diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index 7e42a83a4877..63fe90dbbba2 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -692,6 +692,24 @@ void pci_epc_bme_notify(struct pci_epc *epc)
}
EXPORT_SYMBOL_GPL(pci_epc_bme_notify);

+/**
+ * pci_epc_pme_notify() - Notify the EPF device that the EPC device has received
+ * the PME from the Root complex
+ * @epc: the EPC device that received the PME
+ * @data: Data for the PME notifier
+ *
+ * Invoke to Notify the EPF device that the EPC device has received the Power
+ * Management Event (PME) from the Root complex
+ */
+void pci_epc_pme_notify(struct pci_epc *epc, void *data)
+{
+ if (!epc || IS_ERR(epc))
+ return;
+
+ atomic_notifier_call_chain(&epc->notifier, PME, data);
+}
+EXPORT_SYMBOL_GPL(pci_epc_pme_notify);
+
/**
* 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 6c2cff33f670..37dbcade1780 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -205,6 +205,7 @@ void pci_epc_linkup(struct pci_epc *epc);
void pci_epc_linkdown(struct pci_epc *epc);
void pci_epc_init_notify(struct pci_epc *epc);
void pci_epc_bme_notify(struct pci_epc *epc);
+void pci_epc_pme_notify(struct pci_epc *epc, void *data);
void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
enum pci_epc_interface_type type);
int pci_epc_write_header(struct pci_epc *epc, u8 func_no,
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index 063a59a58e3c..c162a73eb836 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -22,6 +22,7 @@ enum pci_notify_event {
LINK_UP,
LINK_DOWN,
BME,
+ PME,
};

enum pci_barno {
--
2.25.1

2021-06-16 13:23:00

by Manivannan Sadhasivam

[permalink] [raw]
Subject: [PATCH 1/5] PCI: endpoint: Add linkdown notifier support

Add support to notify the EPF device about the linkdown event from the
EPC device.

Usage:
======

EPC
---

```
static irqreturn_t pcie_ep_irq(int irq, void *data)
{
...
case PCIE_EP_INT_LINK_DOWN:
pci_epc_linkdown(epc);
break;
...
}
```

EPF
---

```
static int pci_epf_notifier(struct notifier_block *nb, unsigned long val,
void *data)
{
...
case LINK_DOWN:
/* Handle link down event */
break;
...
}
```

Signed-off-by: Manivannan Sadhasivam <[email protected]>
---
drivers/pci/endpoint/pci-epc-core.c | 17 +++++++++++++++++
include/linux/pci-epc.h | 1 +
include/linux/pci-epf.h | 1 +
3 files changed, 19 insertions(+)

diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index adec9bee72cf..f29d78c18438 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -641,6 +641,23 @@ void pci_epc_linkup(struct pci_epc *epc)
}
EXPORT_SYMBOL_GPL(pci_epc_linkup);

+/**
+ * pci_epc_linkdown() - Notify the EPF device that EPC device has dropped the
+ * connection with the Root Complex.
+ * @epc: the EPC device which has dropped the link with the host
+ *
+ * Invoke to Notify the EPF device that the EPC device has dropped the
+ * connection with the Root Complex.
+ */
+void pci_epc_linkdown(struct pci_epc *epc)
+{
+ if (!epc || IS_ERR(epc))
+ return;
+
+ atomic_notifier_call_chain(&epc->notifier, LINK_DOWN, NULL);
+}
+EXPORT_SYMBOL_GPL(pci_epc_linkdown);
+
/**
* pci_epc_init_notify() - Notify the EPF device that EPC device's core
* initialization is completed.
diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
index b82c9b100e97..23590efc13e7 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -202,6 +202,7 @@ void pci_epc_destroy(struct pci_epc *epc);
int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf,
enum pci_epc_interface_type type);
void pci_epc_linkup(struct pci_epc *epc);
+void pci_epc_linkdown(struct pci_epc *epc);
void pci_epc_init_notify(struct pci_epc *epc);
void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
enum pci_epc_interface_type type);
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index 6833e2160ef1..e9ad634b1575 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -20,6 +20,7 @@ enum pci_epc_interface_type;
enum pci_notify_event {
CORE_INIT,
LINK_UP,
+ LINK_DOWN,
};

enum pci_barno {
--
2.25.1

2021-06-16 13:23:13

by Manivannan Sadhasivam

[permalink] [raw]
Subject: [PATCH 4/5] PCI: endpoint: Add D_STATE notifier support

Add support to notify the EPF device about the Device State (D_STATE)
event received by the EPC device from the Root complex.

Usage:
======

EPC
---

```
static irqreturn_t pcie_ep_irq(int irq, void *data)
{
...
case PCIE_EP_INT_D_STATE:
dstate = dw_pcie_readl_dbi(pci, DBI_CON_STATUS) & 0x3;
pci_epc_d_state_notify(epc, dstate);
break;
...
}
```

EPF
---

```
static int pci_epf_notifier(struct notifier_block *nb, unsigned long val,
void *data)
{
...
case D_STATE:
dstate = data;
if (dstate == PCIE_EP_D0)
/* Handle D0 event */
else if (dstate == PCIE_EP_D3)
/* Handle D3 event */
break;
...
}
```

Signed-off-by: Manivannan Sadhasivam <[email protected]>
---
drivers/pci/endpoint/pci-epc-core.c | 18 ++++++++++++++++++
include/linux/pci-epc.h | 1 +
include/linux/pci-epf.h | 1 +
3 files changed, 20 insertions(+)

diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index 63fe90dbbba2..b4a7bb3caa97 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -710,6 +710,24 @@ void pci_epc_pme_notify(struct pci_epc *epc, void *data)
}
EXPORT_SYMBOL_GPL(pci_epc_pme_notify);

+/**
+ * pci_epc_d_state_notify() - Notify the EPF device that the EPC device has
+ * received the Device State event from Root complex
+ * @epc: the EPC device that received the Device State event
+ * @data: Data for the D_STATE notifier
+ *
+ * Invoke to notify the EPF device that the EPC device has received the Device
+ * State (D_STATE) event from the Root complex
+ */
+void pci_epc_d_state_notify(struct pci_epc *epc, void *data)
+{
+ if (!epc || IS_ERR(epc))
+ return;
+
+ atomic_notifier_call_chain(&epc->notifier, D_STATE, data);
+}
+EXPORT_SYMBOL_GPL(pci_epc_d_state_notify);
+
/**
* 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 37dbcade1780..94c66fae8a88 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -206,6 +206,7 @@ void pci_epc_linkdown(struct pci_epc *epc);
void pci_epc_init_notify(struct pci_epc *epc);
void pci_epc_bme_notify(struct pci_epc *epc);
void pci_epc_pme_notify(struct pci_epc *epc, void *data);
+void pci_epc_d_state_notify(struct pci_epc *epc, void *data);
void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
enum pci_epc_interface_type type);
int pci_epc_write_header(struct pci_epc *epc, u8 func_no,
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index c162a73eb836..ca020c080431 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -23,6 +23,7 @@ enum pci_notify_event {
LINK_DOWN,
BME,
PME,
+ D_STATE,
};

enum pci_barno {
--
2.25.1

2021-06-16 13:23:13

by Manivannan Sadhasivam

[permalink] [raw]
Subject: [PATCH 5/5] PCI: endpoint: Add custom notifier support

Add support for notifying the EPF device about the custom notifications
received by the EPC device from the Root complex. These notifications
are EPC/vendor specific and are shared with the specific EPF devices.

For instance, the Qcom EPC device generates events such as MHI_A7,
MHI_Q6, DEBUG, MMIO_WRITE, CFG_WRITE etc... These events can be passed
to the EPF device using this notifier.

EPC
---

```
static irqreturn_t pcie_ep_irq(int irq, void *data)
{
...
case PCIE_EP_INT_MHI_A7:
pci_epc_custom_notify(epc, PCIE_EP_INT_MHI_A7);
break;
case PCIE_EP_INT_MHI_Q6:
pci_epc_custom_notify(epc, PCIE_EP_INT_MHI_Q6);
break;
case PCIE_EP_INT_MMIO_WRITE:
pci_epc_custom_notify(epc, PCIE_EP_INT_MMIO_WRITE);
break;
...
}
```

EPF
---

```
static int pci_epf_notifier(struct notifier_block *nb, unsigned long val,
void *data)
{
...
case CUSTOM:
cus_event = data;
if (cus_event == PCIE_EP_INT_MHI_A7)
/* Handle MHI A7 event */
else if (cus_event == PCIE_EP_INT_MHI_Q6)
/* Handle MHI Q6 event */
else if (cus_event == PCIE_EP_INT_MMIO_WRITE)
/* Handle MMIO WRITE event */
break;
...
}
```

Signed-off-by: Manivannan Sadhasivam <[email protected]>
---
drivers/pci/endpoint/pci-epc-core.c | 19 +++++++++++++++++++
include/linux/pci-epc.h | 1 +
include/linux/pci-epf.h | 1 +
3 files changed, 21 insertions(+)

diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index b4a7bb3caa97..b963a4aa0af4 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -728,6 +728,25 @@ void pci_epc_d_state_notify(struct pci_epc *epc, void *data)
}
EXPORT_SYMBOL_GPL(pci_epc_d_state_notify);

+/**
+ * pci_epc_custom_notify() - Notify the EPF device that the EPC device has
+ * received the custom events from the Root complex
+ * @epc: EPC device that received the custom event
+ * @data: Data for the CUSTOM notifier
+ *
+ * Invoke to notify the EPF device that the EPC device has received the Custom
+ * event from the Root complex. The custom event is EPC/vendor specific and is
+ * shared with the EPF device.
+ */
+void pci_epc_custom_notify(struct pci_epc *epc, void *data)
+{
+ if (!epc || IS_ERR(epc))
+ return;
+
+ atomic_notifier_call_chain(&epc->notifier, CUSTOM, data);
+}
+EXPORT_SYMBOL_GPL(pci_epc_custom_notify);
+
/**
* 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 94c66fae8a88..943d31a83f6e 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -207,6 +207,7 @@ void pci_epc_init_notify(struct pci_epc *epc);
void pci_epc_bme_notify(struct pci_epc *epc);
void pci_epc_pme_notify(struct pci_epc *epc, void *data);
void pci_epc_d_state_notify(struct pci_epc *epc, void *data);
+void pci_epc_custom_notify(struct pci_epc *epc, void *data);
void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
enum pci_epc_interface_type type);
int pci_epc_write_header(struct pci_epc *epc, u8 func_no,
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index ca020c080431..2fa3b90399b9 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -24,6 +24,7 @@ enum pci_notify_event {
BME,
PME,
D_STATE,
+ CUSTOM,
};

enum pci_barno {
--
2.25.1

2021-06-17 01:35:25

by Om Prakash Singh

[permalink] [raw]
Subject: Re: [PATCH 0/5] PCI: endpoint: Add support for additional notifiers

Hi Mani,
Adding more notifier types will surely help but I believe the list is
not exhaustive. What you are trying here is to pass various
vendor-specific epc interrupts to EPF driver. That can be taken care by
a single notifier interface as well, "pci_epc_custom_notify" from your
implementation. This also requires to have pre-defined values of "data"
argument to standardize the interface.

your thoughts?

Thanks,
Om

On 6/16/2021 5:29 PM, Manivannan Sadhasivam wrote:
> External email: Use caution opening links or attachments
>
>
> Hello,
>
> This series adds support for additional notifiers in the PCI endpoint
> framework. The notifiers LINK_DOWN, BME, PME, and D_STATE are generic
> for all PCI endpoints but there is also a custom notifier (CUSTOM) added
> to pass the device/vendor specific events to EPF from EPC.
>
> The example usage of all notifiers is provided in the commit description.
>
> Thanks,
> Mani
>
> Manivannan Sadhasivam (5):
> PCI: endpoint: Add linkdown notifier support
> PCI: endpoint: Add BME notifier support
> PCI: endpoint: Add PME notifier support
> PCI: endpoint: Add D_STATE notifier support
> PCI: endpoint: Add custom notifier support
>
> drivers/pci/endpoint/pci-epc-core.c | 89 +++++++++++++++++++++++++++++
> include/linux/pci-epc.h | 5 ++
> include/linux/pci-epf.h | 5 ++
> 3 files changed, 99 insertions(+)
>
> --
> 2.25.1
>

2021-06-17 03:11:10

by Om Prakash Singh

[permalink] [raw]
Subject: Re: [PATCH 1/5] PCI: endpoint: Add linkdown notifier support



On 6/16/2021 5:29 PM, Manivannan Sadhasivam wrote:
> External email: Use caution opening links or attachments
>
>
> Add support to notify the EPF device about the linkdown event from the
> EPC device.
>
> Usage:
> ======
>
> EPC
> ---
>
> ```
> static irqreturn_t pcie_ep_irq(int irq, void *data)
> {
> ...
> case PCIE_EP_INT_LINK_DOWN:
> pci_epc_linkdown(epc);
> break;
Can you provide use case/scenario when epc will get LINK_DOWN interrupt?

> ...
> }
> ```
>
> EPF
> ---
>
> ```
> static int pci_epf_notifier(struct notifier_block *nb, unsigned long val,
> void *data)
> {
> ...
> case LINK_DOWN:
> /* Handle link down event */
> break;
> ...
> }
> ```
>
> Signed-off-by: Manivannan Sadhasivam <[email protected]>
> ---
> drivers/pci/endpoint/pci-epc-core.c | 17 +++++++++++++++++
> include/linux/pci-epc.h | 1 +
> include/linux/pci-epf.h | 1 +
> 3 files changed, 19 insertions(+)
>
> diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
> index adec9bee72cf..f29d78c18438 100644
> --- a/drivers/pci/endpoint/pci-epc-core.c
> +++ b/drivers/pci/endpoint/pci-epc-core.c
> @@ -641,6 +641,23 @@ void pci_epc_linkup(struct pci_epc *epc)
> }
> EXPORT_SYMBOL_GPL(pci_epc_linkup);
>
> +/**
> + * pci_epc_linkdown() - Notify the EPF device that EPC device has dropped the
> + * connection with the Root Complex.
> + * @epc: the EPC device which has dropped the link with the host
> + *
> + * Invoke to Notify the EPF device that the EPC device has dropped the
> + * connection with the Root Complex.
> + */
> +void pci_epc_linkdown(struct pci_epc *epc)
> +{
> + if (!epc || IS_ERR(epc))
> + return;
> +
> + atomic_notifier_call_chain(&epc->notifier, LINK_DOWN, NULL);
> +}
> +EXPORT_SYMBOL_GPL(pci_epc_linkdown);
> +
> /**
> * pci_epc_init_notify() - Notify the EPF device that EPC device's core
> * initialization is completed.
> diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
> index b82c9b100e97..23590efc13e7 100644
> --- a/include/linux/pci-epc.h
> +++ b/include/linux/pci-epc.h
> @@ -202,6 +202,7 @@ void pci_epc_destroy(struct pci_epc *epc);
> int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf,
> enum pci_epc_interface_type type);
> void pci_epc_linkup(struct pci_epc *epc);
> +void pci_epc_linkdown(struct pci_epc *epc);
> void pci_epc_init_notify(struct pci_epc *epc);
> void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
> enum pci_epc_interface_type type);
> diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
> index 6833e2160ef1..e9ad634b1575 100644
> --- a/include/linux/pci-epf.h
> +++ b/include/linux/pci-epf.h
> @@ -20,6 +20,7 @@ enum pci_epc_interface_type;
> enum pci_notify_event {
> CORE_INIT,
> LINK_UP,
> + LINK_DOWN,
> };
>
> enum pci_barno {
> --
> 2.25.1
>

2021-06-17 03:11:35

by Manivannan Sadhasivam

[permalink] [raw]
Subject: Re: [PATCH 1/5] PCI: endpoint: Add linkdown notifier support

On Wed, Jun 16, 2021 at 11:52:28PM +0530, Om Prakash Singh wrote:
>
>
> On 6/16/2021 5:29 PM, Manivannan Sadhasivam wrote:
> > External email: Use caution opening links or attachments
> >
> >
> > Add support to notify the EPF device about the linkdown event from the
> > EPC device.
> >
> > Usage:
> > ======
> >
> > EPC
> > ---
> >
> > ```
> > static irqreturn_t pcie_ep_irq(int irq, void *data)
> > {
> > ...
> > case PCIE_EP_INT_LINK_DOWN:
> > pci_epc_linkdown(epc);
> > break;
> Can you provide use case/scenario when epc will get LINK_DOWN interrupt?
>

During host shutdown/reboot epc will get LINK_DOWN interrupt. And in our MHI
function we need to catch that for handling the SYSERR state as per the spec.

Thanks,
Mani

> > ...
> > }
> > ```
> >
> > EPF
> > ---
> >
> > ```
> > static int pci_epf_notifier(struct notifier_block *nb, unsigned long val,
> > void *data)
> > {
> > ...
> > case LINK_DOWN:
> > /* Handle link down event */
> > break;
> > ...
> > }
> > ```
> >
> > Signed-off-by: Manivannan Sadhasivam <[email protected]>
> > ---
> > drivers/pci/endpoint/pci-epc-core.c | 17 +++++++++++++++++
> > include/linux/pci-epc.h | 1 +
> > include/linux/pci-epf.h | 1 +
> > 3 files changed, 19 insertions(+)
> >
> > diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
> > index adec9bee72cf..f29d78c18438 100644
> > --- a/drivers/pci/endpoint/pci-epc-core.c
> > +++ b/drivers/pci/endpoint/pci-epc-core.c
> > @@ -641,6 +641,23 @@ void pci_epc_linkup(struct pci_epc *epc)
> > }
> > EXPORT_SYMBOL_GPL(pci_epc_linkup);
> >
> > +/**
> > + * pci_epc_linkdown() - Notify the EPF device that EPC device has dropped the
> > + * connection with the Root Complex.
> > + * @epc: the EPC device which has dropped the link with the host
> > + *
> > + * Invoke to Notify the EPF device that the EPC device has dropped the
> > + * connection with the Root Complex.
> > + */
> > +void pci_epc_linkdown(struct pci_epc *epc)
> > +{
> > + if (!epc || IS_ERR(epc))
> > + return;
> > +
> > + atomic_notifier_call_chain(&epc->notifier, LINK_DOWN, NULL);
> > +}
> > +EXPORT_SYMBOL_GPL(pci_epc_linkdown);
> > +
> > /**
> > * pci_epc_init_notify() - Notify the EPF device that EPC device's core
> > * initialization is completed.
> > diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
> > index b82c9b100e97..23590efc13e7 100644
> > --- a/include/linux/pci-epc.h
> > +++ b/include/linux/pci-epc.h
> > @@ -202,6 +202,7 @@ void pci_epc_destroy(struct pci_epc *epc);
> > int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf,
> > enum pci_epc_interface_type type);
> > void pci_epc_linkup(struct pci_epc *epc);
> > +void pci_epc_linkdown(struct pci_epc *epc);
> > void pci_epc_init_notify(struct pci_epc *epc);
> > void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
> > enum pci_epc_interface_type type);
> > diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
> > index 6833e2160ef1..e9ad634b1575 100644
> > --- a/include/linux/pci-epf.h
> > +++ b/include/linux/pci-epf.h
> > @@ -20,6 +20,7 @@ enum pci_epc_interface_type;
> > enum pci_notify_event {
> > CORE_INIT,
> > LINK_UP,
> > + LINK_DOWN,
> > };
> >
> > enum pci_barno {
> > --
> > 2.25.1
> >

2021-06-17 19:25:55

by Manivannan Sadhasivam

[permalink] [raw]
Subject: Re: [PATCH 0/5] PCI: endpoint: Add support for additional notifiers

Hi,

On Thu, Jun 17, 2021 at 12:42:07AM +0530, Om Prakash Singh wrote:
> Hi Mani,
> Adding more notifier types will surely help but I believe the list is not
> exhaustive. What you are trying here is to pass various vendor-specific epc
> interrupts to EPF driver. That can be taken care by a single notifier
> interface as well, "pci_epc_custom_notify" from your implementation.

That's what I initially thought eventhough not all the notifiers are
vendor specific. But Kishon suggested to add notifiers for generic ones
such as BME, PME etc... and that sounded reasonable to me.

> This
> also requires to have pre-defined values of "data" argument to standardize
> the interface.
>

No, I don't think we can standardize the arguments to "custom" notifier.
The custom notifier is supposed to deal with vendor specific events and
I don't see any benefit on standardizing it. I see it more like an
opaque driver_data field where we pass driver specific arguments.

Thanks,
Mani

> your thoughts?
>
> Thanks,
> Om
>
> On 6/16/2021 5:29 PM, Manivannan Sadhasivam wrote:
> > External email: Use caution opening links or attachments
> >
> >
> > Hello,
> >
> > This series adds support for additional notifiers in the PCI endpoint
> > framework. The notifiers LINK_DOWN, BME, PME, and D_STATE are generic
> > for all PCI endpoints but there is also a custom notifier (CUSTOM) added
> > to pass the device/vendor specific events to EPF from EPC.
> >
> > The example usage of all notifiers is provided in the commit description.
> >
> > Thanks,
> > Mani
> >
> > Manivannan Sadhasivam (5):
> > PCI: endpoint: Add linkdown notifier support
> > PCI: endpoint: Add BME notifier support
> > PCI: endpoint: Add PME notifier support
> > PCI: endpoint: Add D_STATE notifier support
> > PCI: endpoint: Add custom notifier support
> >
> > drivers/pci/endpoint/pci-epc-core.c | 89 +++++++++++++++++++++++++++++
> > include/linux/pci-epc.h | 5 ++
> > include/linux/pci-epf.h | 5 ++
> > 3 files changed, 99 insertions(+)
> >
> > --
> > 2.25.1
> >

2021-08-19 13:09:57

by Manivannan Sadhasivam

[permalink] [raw]
Subject: Re: [PATCH 0/5] PCI: endpoint: Add support for additional notifiers

On Wed, Jun 16, 2021 at 05:29:08PM +0530, Manivannan Sadhasivam wrote:
> Hello,
>
> This series adds support for additional notifiers in the PCI endpoint
> framework. The notifiers LINK_DOWN, BME, PME, and D_STATE are generic
> for all PCI endpoints but there is also a custom notifier (CUSTOM) added
> to pass the device/vendor specific events to EPF from EPC.
>
> The example usage of all notifiers is provided in the commit description.
>

Ping on this series!

Thanks,
Mani

> Thanks,
> Mani
>
> Manivannan Sadhasivam (5):
> PCI: endpoint: Add linkdown notifier support
> PCI: endpoint: Add BME notifier support
> PCI: endpoint: Add PME notifier support
> PCI: endpoint: Add D_STATE notifier support
> PCI: endpoint: Add custom notifier support
>
> drivers/pci/endpoint/pci-epc-core.c | 89 +++++++++++++++++++++++++++++
> include/linux/pci-epc.h | 5 ++
> include/linux/pci-epf.h | 5 ++
> 3 files changed, 99 insertions(+)
>
> --
> 2.25.1
>

2021-08-19 14:20:20

by Kishon Vijay Abraham I

[permalink] [raw]
Subject: Re: [PATCH 0/5] PCI: endpoint: Add support for additional notifiers

Hi Manivannan,

On 16/06/21 5:29 pm, Manivannan Sadhasivam wrote:
> Hello,
>
> This series adds support for additional notifiers in the PCI endpoint
> framework. The notifiers LINK_DOWN, BME, PME, and D_STATE are generic
> for all PCI endpoints but there is also a custom notifier (CUSTOM) added
> to pass the device/vendor specific events to EPF from EPC.
>
> The example usage of all notifiers is provided in the commit description.

In my earlier comment I didn't mean you to provide example usage in
commit description. Rather to be used in a existing endpoint controller
driver and handled in endpoint function drivers. Otherwise no point in
adding them to the upstream kernel.

Thanks
Kishon

>
> Thanks,
> Mani
>
> Manivannan Sadhasivam (5):
> PCI: endpoint: Add linkdown notifier support
> PCI: endpoint: Add BME notifier support
> PCI: endpoint: Add PME notifier support
> PCI: endpoint: Add D_STATE notifier support
> PCI: endpoint: Add custom notifier support
>
> drivers/pci/endpoint/pci-epc-core.c | 89 +++++++++++++++++++++++++++++
> include/linux/pci-epc.h | 5 ++
> include/linux/pci-epf.h | 5 ++
> 3 files changed, 99 insertions(+)
>

2021-08-19 14:27:54

by Manivannan Sadhasivam

[permalink] [raw]
Subject: Re: [PATCH 0/5] PCI: endpoint: Add support for additional notifiers

On Thu, Aug 19, 2021 at 07:45:06PM +0530, Kishon Vijay Abraham I wrote:
> Hi Manivannan,
>
> On 16/06/21 5:29 pm, Manivannan Sadhasivam wrote:
> > Hello,
> >
> > This series adds support for additional notifiers in the PCI endpoint
> > framework. The notifiers LINK_DOWN, BME, PME, and D_STATE are generic
> > for all PCI endpoints but there is also a custom notifier (CUSTOM) added
> > to pass the device/vendor specific events to EPF from EPC.
> >
> > The example usage of all notifiers is provided in the commit description.
>
> In my earlier comment I didn't mean you to provide example usage in
> commit description. Rather to be used in a existing endpoint controller
> driver and handled in endpoint function drivers. Otherwise no point in
> adding them to the upstream kernel.
>

Oh, sorry then I must have misinterpreted your comments. I'll submit this series
along with the MHI stack that makes use of these notifiers.

Thanks,
Mani

> Thanks
> Kishon
>
> >
> > Thanks,
> > Mani
> >
> > Manivannan Sadhasivam (5):
> > PCI: endpoint: Add linkdown notifier support
> > PCI: endpoint: Add BME notifier support
> > PCI: endpoint: Add PME notifier support
> > PCI: endpoint: Add D_STATE notifier support
> > PCI: endpoint: Add custom notifier support
> >
> > drivers/pci/endpoint/pci-epc-core.c | 89 +++++++++++++++++++++++++++++
> > include/linux/pci-epc.h | 5 ++
> > include/linux/pci-epf.h | 5 ++
> > 3 files changed, 99 insertions(+)
> >