aboutsummaryrefslogtreecommitdiffstats
path: root/package/kernel/mac80211/patches/build/101-backport-add-pci_disable_link_state-wrapper-with-ret.patch
blob: cae20f5dc39d8a4211bdfa27f3369a333a714763 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
From: Felix Fietkau <nbd@nbd.name>
Date: Mon, 28 Oct 2019 15:20:40 +0100
Subject: [PATCH] backport: add pci_disable_link_state wrapper with return code

The signature of pci_disable_link_state was changed to indicate if the state
was successfully disabled. Since the old version did not have this, add a
wrapper which checks the pcie register to determine the return code

Signed-off-by: Felix Fietkau <nbd@nbd.name>
---

--- a/backport-include/linux/pci.h
+++ b/backport-include/linux/pci.h
@@ -236,4 +236,29 @@ static inline struct pci_dev *pcie_find_
 	(PCI_IRQ_LEGACY | PCI_IRQ_MSI | PCI_IRQ_MSIX)
 #endif
 
+#if LINUX_VERSION_IS_LESS(5,3,0)
+
+static inline int
+LINUX_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
+
 #endif /* _BACKPORT_LINUX_PCI_H */