Commit 80bfdbe3 authored by Kenji Kaneshige's avatar Kenji Kaneshige Committed by Jesse Barnes

PCI ASPM: cleanup aspm state field in struct pcie_link_state

The "support_state", "enabled_state" and "bios_aspm_state" fields in
the struct pcie_link_state take 2-bit value. So those fields don't
need to be defined as unsigned int. This patch makes those fields
2-bit, and cleans up some related code.
Acked-by: default avatarShaohua Li <shaohua.li@intel.com>
Signed-off-by: default avatarKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent dc64cd11
...@@ -41,9 +41,10 @@ struct pcie_link_state { ...@@ -41,9 +41,10 @@ struct pcie_link_state {
struct list_head link; struct list_head link;
/* ASPM state */ /* ASPM state */
unsigned int support_state; u32 aspm_support:2; /* Supported ASPM state */
unsigned int enabled_state; u32 aspm_enabled:2; /* Enabled ASPM state */
unsigned int bios_aspm_state; u32 aspm_default:2; /* Default ASPM state by BIOS */
/* upstream component */ /* upstream component */
unsigned int l0s_upper_latency; unsigned int l0s_upper_latency;
unsigned int l1_upper_latency; unsigned int l1_upper_latency;
...@@ -88,9 +89,9 @@ static int policy_to_aspm_state(struct pci_dev *pdev) ...@@ -88,9 +89,9 @@ static int policy_to_aspm_state(struct pci_dev *pdev)
return 0; return 0;
case POLICY_POWERSAVE: case POLICY_POWERSAVE:
/* Enable ASPM L0s/L1 */ /* Enable ASPM L0s/L1 */
return PCIE_LINK_STATE_L0S|PCIE_LINK_STATE_L1; return PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1;
case POLICY_DEFAULT: case POLICY_DEFAULT:
return link_state->bios_aspm_state; return link_state->aspm_default;
} }
return 0; return 0;
} }
...@@ -311,6 +312,7 @@ static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state, ...@@ -311,6 +312,7 @@ static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state,
u32 reg32; u32 reg32;
unsigned int latency; unsigned int latency;
*l0s = *l1 = *enabled = 0;
pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
pci_read_config_dword(pdev, pos + PCI_EXP_LNKCAP, &reg32); pci_read_config_dword(pdev, pos + PCI_EXP_LNKCAP, &reg32);
*state = (reg32 & PCI_EXP_LNKCAP_ASPMS) >> 10; *state = (reg32 & PCI_EXP_LNKCAP_ASPMS) >> 10;
...@@ -333,26 +335,29 @@ static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state, ...@@ -333,26 +335,29 @@ static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state,
static void pcie_aspm_cap_init(struct pci_dev *pdev) static void pcie_aspm_cap_init(struct pci_dev *pdev)
{ {
struct pci_dev *child_dev; struct pci_dev *child_dev;
u32 state, tmp; u32 support, l0s, l1, enabled;
struct pcie_link_state *link_state = pdev->link_state; struct pcie_link_state *link_state = pdev->link_state;
/* upstream component states */ /* upstream component states */
pcie_aspm_get_cap_device(pdev, &link_state->support_state, pcie_aspm_get_cap_device(pdev, &support, &l0s, &l1, &enabled);
&link_state->l0s_upper_latency, link_state->aspm_support = support;
&link_state->l1_upper_latency, link_state->l0s_upper_latency = l0s;
&link_state->enabled_state); link_state->l1_upper_latency = l1;
link_state->aspm_enabled = enabled;
/* downstream component states, all functions have the same setting */ /* downstream component states, all functions have the same setting */
child_dev = list_entry(pdev->subordinate->devices.next, struct pci_dev, child_dev = list_entry(pdev->subordinate->devices.next, struct pci_dev,
bus_list); bus_list);
pcie_aspm_get_cap_device(child_dev, &state, pcie_aspm_get_cap_device(child_dev, &support, &l0s, &l1, &enabled);
&link_state->l0s_down_latency, link_state->aspm_support &= support;
&link_state->l1_down_latency, link_state->l0s_down_latency = l0s;
&tmp); link_state->l1_down_latency = l1;
link_state->support_state &= state;
if (!link_state->support_state) if (!link_state->aspm_support)
return; return;
link_state->enabled_state &= link_state->support_state;
link_state->bios_aspm_state = link_state->enabled_state; link_state->aspm_enabled &= link_state->aspm_support;
link_state->aspm_default = link_state->aspm_enabled;
/* ENDPOINT states*/ /* ENDPOINT states*/
list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) { list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) {
...@@ -371,7 +376,7 @@ static void pcie_aspm_cap_init(struct pci_dev *pdev) ...@@ -371,7 +376,7 @@ static void pcie_aspm_cap_init(struct pci_dev *pdev)
latency = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6; latency = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6;
latency = calc_L0S_latency(latency, 1); latency = calc_L0S_latency(latency, 1);
ep_state->l0s_acceptable_latency = latency; ep_state->l0s_acceptable_latency = latency;
if (link_state->support_state & PCIE_LINK_STATE_L1) { if (link_state->aspm_support & PCIE_LINK_STATE_L1) {
latency = (reg32 & PCI_EXP_DEVCAP_L1) >> 9; latency = (reg32 & PCI_EXP_DEVCAP_L1) >> 9;
latency = calc_L1_latency(latency, 1); latency = calc_L1_latency(latency, 1);
ep_state->l1_acceptable_latency = latency; ep_state->l1_acceptable_latency = latency;
...@@ -389,7 +394,7 @@ static unsigned int __pcie_aspm_check_state_one(struct pci_dev *pdev, ...@@ -389,7 +394,7 @@ static unsigned int __pcie_aspm_check_state_one(struct pci_dev *pdev,
parent_dev = pdev->bus->self; parent_dev = pdev->bus->self;
link_state = parent_dev->link_state; link_state = parent_dev->link_state;
state &= link_state->support_state; state &= link_state->aspm_support;
if (state == 0) if (state == 0)
return 0; return 0;
ep_state = &link_state->endpoints[PCI_FUNC(pdev->devfn)]; ep_state = &link_state->endpoints[PCI_FUNC(pdev->devfn)];
...@@ -519,7 +524,7 @@ static void __pcie_aspm_config_link(struct pci_dev *pdev, unsigned int state) ...@@ -519,7 +524,7 @@ static void __pcie_aspm_config_link(struct pci_dev *pdev, unsigned int state)
if (!(state & PCIE_LINK_STATE_L1)) if (!(state & PCIE_LINK_STATE_L1))
__pcie_aspm_config_one_dev(pdev, state); __pcie_aspm_config_one_dev(pdev, state);
link_state->enabled_state = state; link_state->aspm_enabled = state;
} }
static struct pcie_link_state *get_root_port_link(struct pcie_link_state *link) static struct pcie_link_state *get_root_port_link(struct pcie_link_state *link)
...@@ -550,7 +555,7 @@ static void __pcie_aspm_configure_link_state(struct pci_dev *pdev, ...@@ -550,7 +555,7 @@ static void __pcie_aspm_configure_link_state(struct pci_dev *pdev,
/* check root port link too in case it hasn't children */ /* check root port link too in case it hasn't children */
state = pcie_aspm_check_state(root_port_link->pdev, state); state = pcie_aspm_check_state(root_port_link->pdev, state);
if (link_state->enabled_state == state) if (link_state->aspm_enabled == state)
return; return;
/* /*
...@@ -675,10 +680,11 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev) ...@@ -675,10 +680,11 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
pcie_aspm_configure_common_clock(pdev); pcie_aspm_configure_common_clock(pdev);
pcie_aspm_cap_init(pdev); pcie_aspm_cap_init(pdev);
} else { } else {
link_state->enabled_state = PCIE_LINK_STATE_L0S|PCIE_LINK_STATE_L1; link_state->aspm_enabled =
link_state->bios_aspm_state = 0; (PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1);
link_state->aspm_default = 0;
/* Set support state to 0, so we will disable ASPM later */ /* Set support state to 0, so we will disable ASPM later */
link_state->support_state = 0; link_state->aspm_support = 0;
} }
link_state->pdev = pdev; link_state->pdev = pdev;
...@@ -690,7 +696,7 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev) ...@@ -690,7 +696,7 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
* initialization will config the whole hierarchy. but we must * initialization will config the whole hierarchy. but we must
* make sure BIOS doesn't set unsupported link state * make sure BIOS doesn't set unsupported link state
**/ **/
state = pcie_aspm_check_state(pdev, link_state->bios_aspm_state); state = pcie_aspm_check_state(pdev, link_state->aspm_default);
__pcie_aspm_config_link(pdev, state); __pcie_aspm_config_link(pdev, state);
} else } else
__pcie_aspm_configure_link_state(pdev, __pcie_aspm_configure_link_state(pdev,
...@@ -753,7 +759,7 @@ void pcie_aspm_pm_state_change(struct pci_dev *pdev) ...@@ -753,7 +759,7 @@ void pcie_aspm_pm_state_change(struct pci_dev *pdev)
* devices changed PM state, we should recheck if latency meets all * devices changed PM state, we should recheck if latency meets all
* functions' requirement * functions' requirement
*/ */
pcie_aspm_configure_link_state(pdev, link_state->enabled_state); pcie_aspm_configure_link_state(pdev, link_state->aspm_enabled);
} }
/* /*
...@@ -776,12 +782,11 @@ void pci_disable_link_state(struct pci_dev *pdev, int state) ...@@ -776,12 +782,11 @@ void pci_disable_link_state(struct pci_dev *pdev, int state)
down_read(&pci_bus_sem); down_read(&pci_bus_sem);
mutex_lock(&aspm_lock); mutex_lock(&aspm_lock);
link_state = parent->link_state; link_state = parent->link_state;
link_state->support_state &= link_state->aspm_support &= ~state;
~(state & (PCIE_LINK_STATE_L0S|PCIE_LINK_STATE_L1));
if (state & PCIE_LINK_STATE_CLKPM) if (state & PCIE_LINK_STATE_CLKPM)
link_state->clk_pm_capable = 0; link_state->clk_pm_capable = 0;
__pcie_aspm_configure_link_state(parent, link_state->enabled_state); __pcie_aspm_configure_link_state(parent, link_state->aspm_enabled);
if (!link_state->clk_pm_capable && link_state->clk_pm_enabled) if (!link_state->clk_pm_capable && link_state->clk_pm_enabled)
pcie_set_clock_pm(parent, 0); pcie_set_clock_pm(parent, 0);
mutex_unlock(&aspm_lock); mutex_unlock(&aspm_lock);
...@@ -842,7 +847,7 @@ static ssize_t link_state_show(struct device *dev, ...@@ -842,7 +847,7 @@ static ssize_t link_state_show(struct device *dev,
struct pci_dev *pci_device = to_pci_dev(dev); struct pci_dev *pci_device = to_pci_dev(dev);
struct pcie_link_state *link_state = pci_device->link_state; struct pcie_link_state *link_state = pci_device->link_state;
return sprintf(buf, "%d\n", link_state->enabled_state); return sprintf(buf, "%d\n", link_state->aspm_enabled);
} }
static ssize_t link_state_store(struct device *dev, static ssize_t link_state_store(struct device *dev,
...@@ -908,7 +913,7 @@ void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev) ...@@ -908,7 +913,7 @@ void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev)
pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) || !link_state) pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) || !link_state)
return; return;
if (link_state->support_state) if (link_state->aspm_support)
sysfs_add_file_to_group(&pdev->dev.kobj, sysfs_add_file_to_group(&pdev->dev.kobj,
&dev_attr_link_state.attr, power_group); &dev_attr_link_state.attr, power_group);
if (link_state->clk_pm_capable) if (link_state->clk_pm_capable)
...@@ -924,7 +929,7 @@ void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev) ...@@ -924,7 +929,7 @@ void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev)
pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) || !link_state) pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) || !link_state)
return; return;
if (link_state->support_state) if (link_state->aspm_support)
sysfs_remove_file_from_group(&pdev->dev.kobj, sysfs_remove_file_from_group(&pdev->dev.kobj,
&dev_attr_link_state.attr, power_group); &dev_attr_link_state.attr, power_group);
if (link_state->clk_pm_capable) if (link_state->clk_pm_capable)
......
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