Add DeInit support in the PCIe Endpoint framework
Subsystems (4)
cover Add DeInit support in the PCIe Endpoint framework
Endpoint function driver should cleanup its resources which accesses the hardware during endpoint controller deinitialization. The patches in this series address this requirement by first adding the callback notification in the endpoint code driver. This notification is invoked by the controller driver which is propagated further to the function driver.
This patch series depends on Manivanna's following series.
https://patchwork.ozlabs.org/project/linux-pci/list/?series=317729
Vidya Sagar (3):
PCI: endpoint: Add CORE_DEINIT callback support
PCIe: dwc: Add a DWC wrapper to pci_epc_deinit_notify()
PCI: endpoint: Delete list entry before freeing
.../pci/controller/dwc/pcie-designware-ep.c | 8 ++++++ drivers/pci/controller/dwc/pcie-designware.h | 5 ++++ drivers/pci/endpoint/pci-epc-core.c | 26 +++++++++++++++++++ drivers/pci/endpoint/pci-epf-core.c | 5 ++-- include/linux/pci-epc.h | 1 + include/linux/pci-epf.h | 2 ++ 6 files changed, 45 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 PCI: endpoint: Add CORE_DEINIT callback support
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.
--- 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(+)
drivers/pci/endpoint/pci-epc-core.c +26 -0
@@ -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
include/linux/pci-epc.h +1 -0
@@ -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,
include/linux/pci-epf.h +2 -0
@@ -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); };
Signature · 1 line
2.17.1
PATCH 2/3 PCIe: dwc: Add a DWC wrapper to pci_epc_deinit_notify()
In reply to Vidya SagarAdd 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.
--- drivers/pci/controller/dwc/pcie-designware-ep.c | 8 ++++++++ drivers/pci/controller/dwc/pcie-designware.h | 5 +++++ 2 files changed, 13 insertions(+)
drivers/pci/controller/dwc/pcie-designware-ep.c +8 -0
@@ -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;
drivers/pci/controller/dwc/pcie-designware.h +5 -0
@@ -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) { }
Signature · 1 line
2.17.1
PATCH 3/3 PCI: endpoint: Delete list entry before freeing
In reply to Vidya SagarCurrently 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.
--- drivers/pci/endpoint/pci-epf-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/endpoint/pci-epf-core.c +3 -2
@@ -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); }
Signature · 1 line
2.17.1