0001
0002
0003
0004
0005
0006 #include "mt76.h"
0007 #include <linux/pci.h>
0008
0009 void mt76_pci_disable_aspm(struct pci_dev *pdev)
0010 {
0011 struct pci_dev *parent = pdev->bus->self;
0012 u16 aspm_conf, parent_aspm_conf = 0;
0013
0014 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &aspm_conf);
0015 aspm_conf &= PCI_EXP_LNKCTL_ASPMC;
0016 if (parent) {
0017 pcie_capability_read_word(parent, PCI_EXP_LNKCTL,
0018 &parent_aspm_conf);
0019 parent_aspm_conf &= PCI_EXP_LNKCTL_ASPMC;
0020 }
0021
0022 if (!aspm_conf && (!parent || !parent_aspm_conf)) {
0023
0024 return;
0025 }
0026
0027 dev_info(&pdev->dev, "disabling ASPM %s %s\n",
0028 (aspm_conf & PCI_EXP_LNKCTL_ASPM_L0S) ? "L0s" : "",
0029 (aspm_conf & PCI_EXP_LNKCTL_ASPM_L1) ? "L1" : "");
0030
0031 if (IS_ENABLED(CONFIG_PCIEASPM)) {
0032 int err;
0033
0034 err = pci_disable_link_state(pdev, aspm_conf);
0035 if (!err)
0036 return;
0037 }
0038
0039
0040
0041
0042 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_conf);
0043 if (parent)
0044 pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
0045 aspm_conf);
0046 }
0047 EXPORT_SYMBOL_GPL(mt76_pci_disable_aspm);