From 1c96e546c821aef6e0fb5028d93cc6735a6f3b1c Mon Sep 17 00:00:00 2001 From: Luca Coelho Date: Sun, 18 Feb 2018 15:24:51 +0200 Subject: backport: add pcie_find_root_port() This function was introduced in v4.9 and added to 3.12.69, 4.4.37 and 4.8.13. Signed-off-by: Luca Coelho Signed-off-by: Johannes Berg --- backport/backport-include/linux/pci.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/backport/backport-include/linux/pci.h b/backport/backport-include/linux/pci.h index 81c2d57a..67ac40fc 100644 --- a/backport/backport-include/linux/pci.h +++ b/backport/backport-include/linux/pci.h @@ -184,4 +184,25 @@ static inline int pci_enable_msix_exact(struct pci_dev *dev, #endif #endif /* CONFIG_PCI */ +#if LINUX_VERSION_IS_LESS(4,9,0) && \ + !LINUX_VERSION_IN_RANGE(3,12,69, 3,13,0) && \ + !LINUX_VERSION_IN_RANGE(4,4,37, 4,5,0) && \ + !LINUX_VERSION_IN_RANGE(4,8,13, 4,9,0) + +static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev) +{ + while (1) { + if (!pci_is_pcie(dev)) + break; + if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) + return dev; + if (!dev->bus->self) + break; + dev = dev->bus->self; + } + return NULL; +} + +#endif/* <4.9.0 but not >= 3.12.69, 4.4.37, 4.8.13 */ + #endif /* _BACKPORT_LINUX_PCI_H */ -- cgit v1.2.3