Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: ISC
0002 /*
0003  * Copyright (C) 2019 Lorenzo Bianconi <lorenzo@kernel.org>
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         /* aspm already disabled */
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     /* both device and parent should have the same ASPM setting.
0040      * disable ASPM in downstream component first and then upstream.
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);