summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2019-11-16 13:14:21 +0100
committerHauke Mehrtens <hauke@hauke-m.de>2019-11-21 23:03:22 +0100
commit5f9aea36b5ebf36e8391a0df03cc6f2d8d923a5d (patch)
tree1a932ea214585c1127fbb8b18112d3fccf49b7e8
parent5ab7098a8abed0a0e677892bc51f0bba684a4ba4 (diff)
backports: Add return value to backport_pci_disable_link_state()
Since Linux upstream commit 4cfd21885592 ("PCI: let pci_disable_link_state propagate errors") The pci_disable_link_state() function can return an error. This return code is now used by the mt76 driver. In case it is not possible to disable ASPM, for example on some ACPI systems, we should return an error and mt76 handles this. Do this by checking the PCI registers if the operation was successfully. The checking of the PCI register was added by Felix Fietkau. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
-rw-r--r--backport/backport-include/linux/pci.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/backport/backport-include/linux/pci.h b/backport/backport-include/linux/pci.h
index 84c4e8f6..1cc5f281 100644
--- a/backport/backport-include/linux/pci.h
+++ b/backport/backport-include/linux/pci.h
@@ -236,4 +236,29 @@ static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
(PCI_IRQ_LEGACY | PCI_IRQ_MSI | PCI_IRQ_MSIX)
#endif
+#if defined(CONFIG_PCI)
+#if LINUX_VERSION_IS_LESS(5,3,0)
+static inline int
+backport_pci_disable_link_state(struct pci_dev *pdev, int state)
+{
+ u16 aspmc;
+
+ pci_disable_link_state(pdev, state);
+
+ pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &aspmc);
+ if ((state & PCIE_LINK_STATE_L0S) &&
+ (aspmc & PCI_EXP_LNKCTL_ASPM_L0S))
+ return -EPERM;
+
+ if ((state & PCIE_LINK_STATE_L1) &&
+ (aspmc & PCI_EXP_LNKCTL_ASPM_L1))
+ return -EPERM;
+
+ return 0;
+}
+#define pci_disable_link_state LINUX_BACKPORT(pci_disable_link_state)
+
+#endif /* < 5.3 */
+#endif /* defined(CONFIG_PCI) */
+
#endif /* _BACKPORT_LINUX_PCI_H */