* [PATCH V1 1/3] PCI: endpoint: Add CORE_DEINIT callback support
2022-10-10 11:19 [PATCH V1 0/3] Add DeInit support in the PCIe Endpoint framework Vidya Sagar
@ 2022-10-10 11:19 ` Vidya Sagar
2022-10-10 11:19 ` [PATCH V1 2/3] PCIe: dwc: Add a DWC wrapper to pci_epc_deinit_notify() Vidya Sagar
2022-10-10 11:19 ` [PATCH V1 3/3] PCI: endpoint: Delete list entry before freeing Vidya Sagar
2 siblings, 0 replies; 4+ messages in thread
From: Vidya Sagar @ 2022-10-10 11:19 UTC (permalink / raw)
To: jingoohan1, gustavo.pimentel, lpieralisi, robh, kw, bhelgaas,
mani, kishon
Cc: thierry.reding, jonathanh, linux-pci, linux-kernel, kthota,
mmaddireddy, vidyas, sagar.tv
Function driver needs to clean up the hardware resources and stop all the
running processes accessing the hardware during the endpoint controller
deinitialization. Add core_deinit() callback support for the endpoint
function driver to do the same.
Signed-off-by: Vidya Sagar <vidyas@nvidia.com>
---
drivers/pci/endpoint/pci-epc-core.c | 26 ++++++++++++++++++++++++++
include/linux/pci-epc.h | 1 +
include/linux/pci-epf.h | 2 ++
3 files changed, 29 insertions(+)
diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index 5dac1496cf16..689450f01f75 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -732,6 +732,32 @@ void pci_epc_init_notify(struct pci_epc *epc)
}
EXPORT_SYMBOL_GPL(pci_epc_init_notify);
+/**
+ * pci_epc_deinit_notify() - Notify the EPF device that EPC device's core
+ * deinitialization is scheduled.
+ * @epc: the EPC device whose core deinitialization is scheduled
+ *
+ * Invoke to Notify the EPF device that the EPC device's deinitialization
+ * is scheduled.
+ */
+void pci_epc_deinit_notify(struct pci_epc *epc)
+{
+ 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->core_deinit)
+ epf->event_ops->core_deinit(epf);
+ mutex_unlock(&epf->lock);
+ }
+ mutex_unlock(&epc->list_lock);
+}
+EXPORT_SYMBOL_GPL(pci_epc_deinit_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 301bb0e53707..b95dc4b3e302 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,
enum pci_epc_interface_type type);
void pci_epc_linkup(struct pci_epc *epc);
void pci_epc_init_notify(struct pci_epc *epc);
+void pci_epc_deinit_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, u8 vfunc_no,
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index a215dc8ce693..fa51579951db 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -70,10 +70,12 @@ struct pci_epf_ops {
/**
* struct pci_epf_event_ops - Callbacks for capturing the EPC events
* @core_init: Callback for the EPC initialization complete event
+ * @core_deinit: Callback for the EPC deinitialization schedule event
* @link_up: Callback for the EPC link up event
*/
struct pci_epc_event_ops {
int (*core_init)(struct pci_epf *epf);
+ int (*core_deinit)(struct pci_epf *epf);
int (*link_up)(struct pci_epf *epf);
};
--
2.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH V1 2/3] PCIe: dwc: Add a DWC wrapper to pci_epc_deinit_notify()
2022-10-10 11:19 [PATCH V1 0/3] Add DeInit support in the PCIe Endpoint framework Vidya Sagar
2022-10-10 11:19 ` [PATCH V1 1/3] PCI: endpoint: Add CORE_DEINIT callback support Vidya Sagar
@ 2022-10-10 11:19 ` Vidya Sagar
2022-10-10 11:19 ` [PATCH V1 3/3] PCI: endpoint: Delete list entry before freeing Vidya Sagar
2 siblings, 0 replies; 4+ messages in thread
From: Vidya Sagar @ 2022-10-10 11:19 UTC (permalink / raw)
To: jingoohan1, gustavo.pimentel, lpieralisi, robh, kw, bhelgaas,
mani, kishon
Cc: thierry.reding, jonathanh, linux-pci, linux-kernel, kthota,
mmaddireddy, vidyas, sagar.tv
Add a wrapper for the pci_epc_deinit_notify() at the DWC layer for all DWC
host controller drivers to invoke during the endpoint controller
deinitilization.
Signed-off-by: Vidya Sagar <vidyas@nvidia.com>
---
drivers/pci/controller/dwc/pcie-designware-ep.c | 8 ++++++++
drivers/pci/controller/dwc/pcie-designware.h | 5 +++++
2 files changed, 13 insertions(+)
diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c
index 297d8b306ab8..d39ccb9ca7d0 100644
--- a/drivers/pci/controller/dwc/pcie-designware-ep.c
+++ b/drivers/pci/controller/dwc/pcie-designware-ep.c
@@ -742,6 +742,14 @@ int dw_pcie_ep_init_notify(struct dw_pcie_ep *ep)
}
EXPORT_SYMBOL_GPL(dw_pcie_ep_init_notify);
+void dw_pcie_ep_deinit_notify(struct dw_pcie_ep *ep)
+{
+ struct pci_epc *epc = ep->epc;
+
+ pci_epc_deinit_notify(epc);
+}
+EXPORT_SYMBOL_GPL(dw_pcie_ep_deinit_notify);
+
int dw_pcie_ep_init(struct dw_pcie_ep *ep)
{
int ret;
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index b00bee4b782c..f948b73e8c6f 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -469,6 +469,7 @@ static inline void __iomem *dw_pcie_own_conf_map_bus(struct pci_bus *bus,
void dw_pcie_ep_linkup(struct dw_pcie_ep *ep);
int dw_pcie_ep_init(struct dw_pcie_ep *ep);
int dw_pcie_ep_init_notify(struct dw_pcie_ep *ep);
+void dw_pcie_ep_deinit_notify(struct dw_pcie_ep *ep);
void dw_pcie_ep_deinit(struct dw_pcie_ep *ep);
void dw_pcie_ep_exit(struct dw_pcie_ep *ep);
int dw_pcie_ep_raise_legacy_irq(struct dw_pcie_ep *ep, u8 func_no);
@@ -496,6 +497,10 @@ static inline int dw_pcie_ep_init_notify(struct dw_pcie_ep *ep)
return 0;
}
+static inline void dw_pcie_ep_deinit_notify(struct dw_pcie_ep *ep)
+{
+}
+
static inline void dw_pcie_ep_deinit(struct dw_pcie_ep *ep)
{
}
--
2.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH V1 3/3] PCI: endpoint: Delete list entry before freeing
2022-10-10 11:19 [PATCH V1 0/3] Add DeInit support in the PCIe Endpoint framework Vidya Sagar
2022-10-10 11:19 ` [PATCH V1 1/3] PCI: endpoint: Add CORE_DEINIT callback support Vidya Sagar
2022-10-10 11:19 ` [PATCH V1 2/3] PCIe: dwc: Add a DWC wrapper to pci_epc_deinit_notify() Vidya Sagar
@ 2022-10-10 11:19 ` Vidya Sagar
2 siblings, 0 replies; 4+ messages in thread
From: Vidya Sagar @ 2022-10-10 11:19 UTC (permalink / raw)
To: jingoohan1, gustavo.pimentel, lpieralisi, robh, kw, bhelgaas,
mani, kishon
Cc: thierry.reding, jonathanh, linux-pci, linux-kernel, kthota,
mmaddireddy, vidyas, sagar.tv
Currently epf_group list head is deleted without first deleting entries
pointed by the list head. This patch fixes that by first deleting each
entry from the list.
Signed-off-by: Vidya Sagar <vidyas@nvidia.com>
---
drivers/pci/endpoint/pci-epf-core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
index 9ed556936f48..a7f4ae33905d 100644
--- a/drivers/pci/endpoint/pci-epf-core.c
+++ b/drivers/pci/endpoint/pci-epf-core.c
@@ -340,9 +340,10 @@ static void pci_epf_remove_cfs(struct pci_epf_driver *driver)
return;
mutex_lock(&pci_epf_mutex);
- list_for_each_entry_safe(group, tmp, &driver->epf_group, group_entry)
+ list_for_each_entry_safe(group, tmp, &driver->epf_group, group_entry) {
+ list_del(&group->group_entry);
pci_ep_cfs_remove_epf_group(group);
- list_del(&driver->epf_group);
+ }
mutex_unlock(&pci_epf_mutex);
}
--
2.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread