Commit 987a4c78 authored by Andrew Patterson's avatar Andrew Patterson Committed by Jesse Barnes

PCI: Use msleep instead of cpu_relax during ASPM link retraining

The cpu_relax() function can be a noop on certain architectures like
IA-64 when CPU threads are disabled, so use msleep instead during link
retraining busy/wait loop.

Introduce define LINK_RETRAIN_TIMEOUT instead of hard-coding timeout in
pcie_aspm_configure_common_clock.

Use time_after() to avoid jiffy wraparound when checking for expired
timeout.

After timeout expires, recheck link status register link training bit
instead of checking for expired timeout to avoid possible false
positive.

Note that Matthew Wilcox came up with the first rough version of this
patch.
Reviewed-by: default avatarMatthew Wilcox <willy@linux.intel.com>
Signed-off-by: default avatarAndrew Patterson <andrew.patterson@hp.com>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent d9347371
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/delay.h>
#include <linux/pci-aspm.h> #include <linux/pci-aspm.h>
#include "../pci.h" #include "../pci.h"
...@@ -75,6 +76,8 @@ static const char *policy_str[] = { ...@@ -75,6 +76,8 @@ static const char *policy_str[] = {
[POLICY_POWERSAVE] = "powersave" [POLICY_POWERSAVE] = "powersave"
}; };
#define LINK_RETRAIN_TIMEOUT HZ
static int policy_to_aspm_state(struct pci_dev *pdev) static int policy_to_aspm_state(struct pci_dev *pdev)
{ {
struct pcie_link_state *link_state = pdev->link_state; struct pcie_link_state *link_state = pdev->link_state;
...@@ -238,16 +241,18 @@ static void pcie_aspm_configure_common_clock(struct pci_dev *pdev) ...@@ -238,16 +241,18 @@ static void pcie_aspm_configure_common_clock(struct pci_dev *pdev)
pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16); pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
/* Wait for link training end */ /* Wait for link training end */
/* break out after waiting for 1 second */ /* break out after waiting for timeout */
start_jiffies = jiffies; start_jiffies = jiffies;
while ((jiffies - start_jiffies) < HZ) { for (;;) {
pci_read_config_word(pdev, pos + PCI_EXP_LNKSTA, &reg16); pci_read_config_word(pdev, pos + PCI_EXP_LNKSTA, &reg16);
if (!(reg16 & PCI_EXP_LNKSTA_LT)) if (!(reg16 & PCI_EXP_LNKSTA_LT))
break; break;
cpu_relax(); if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT))
break;
msleep(1);
} }
/* training failed -> recover */ /* training failed -> recover */
if ((jiffies - start_jiffies) >= HZ) { if (reg16 & PCI_EXP_LNKSTA_LT) {
dev_printk (KERN_ERR, &pdev->dev, "ASPM: Could not configure" dev_printk (KERN_ERR, &pdev->dev, "ASPM: Could not configure"
" common clock\n"); " common clock\n");
i = 0; i = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment