Commit 5e0eaa7d authored by Kenji Kaneshige's avatar Kenji Kaneshige Committed by Jesse Barnes

PCI ASPM: cleanup calc_Lx_latency

Cleanup for calc_L0S_latency() and calc_L1_latency().

  - Separate exit latency and acceptable latency calculation.
  - Some minor cleanups.
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 7ab70991
...@@ -257,38 +257,36 @@ static void pcie_aspm_configure_common_clock(struct pcie_link_state *link) ...@@ -257,38 +257,36 @@ static void pcie_aspm_configure_common_clock(struct pcie_link_state *link)
pci_write_config_word(parent, ppos + PCI_EXP_LNKCTL, parent_reg); pci_write_config_word(parent, ppos + PCI_EXP_LNKCTL, parent_reg);
} }
/* /* Convert L0s latency encoding to ns */
* calc_L0S_latency: Convert L0s latency encoding to ns static u32 calc_l0s_latency(u32 encoding)
*/
static unsigned int calc_L0S_latency(unsigned int latency_encoding, int ac)
{ {
unsigned int ns = 64; if (encoding == 0x7)
return (5 * 1000); /* > 4us */
return (64 << encoding);
}
if (latency_encoding == 0x7) { /* Convert L0s acceptable latency encoding to ns */
if (ac) static u32 calc_l0s_acceptable(u32 encoding)
ns = -1U; {
else if (encoding == 0x7)
ns = 5*1000; /* > 4us */ return -1U;
} else return (64 << encoding);
ns *= (1 << latency_encoding);
return ns;
} }
/* /* Convert L1 latency encoding to ns */
* calc_L1_latency: Convert L1 latency encoding to ns static u32 calc_l1_latency(u32 encoding)
*/
static unsigned int calc_L1_latency(unsigned int latency_encoding, int ac)
{ {
unsigned int ns = 1000; if (encoding == 0x7)
return (65 * 1000); /* > 64us */
return (1000 << encoding);
}
if (latency_encoding == 0x7) { /* Convert L1 acceptable latency encoding to ns */
if (ac) static u32 calc_l1_acceptable(u32 encoding)
ns = -1U; {
else if (encoding == 0x7)
ns = 65*1000; /* > 64us */ return -1U;
} else return (1000 << encoding);
ns *= (1 << latency_encoding);
return ns;
} }
static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state, static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state,
...@@ -296,7 +294,7 @@ static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state, ...@@ -296,7 +294,7 @@ static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state,
{ {
int pos; int pos;
u16 reg16; u16 reg16;
u32 reg32, latency; u32 reg32, encoding;
*l0s = *l1 = *enabled = 0; *l0s = *l1 = *enabled = 0;
pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
...@@ -308,11 +306,11 @@ static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state, ...@@ -308,11 +306,11 @@ static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state,
if (*state == 0) if (*state == 0)
return; return;
latency = (reg32 & PCI_EXP_LNKCAP_L0SEL) >> 12; encoding = (reg32 & PCI_EXP_LNKCAP_L0SEL) >> 12;
*l0s = calc_L0S_latency(latency, 0); *l0s = calc_l0s_latency(encoding);
if (*state & PCIE_LINK_STATE_L1) { if (*state & PCIE_LINK_STATE_L1) {
latency = (reg32 & PCI_EXP_LNKCAP_L1EL) >> 15; encoding = (reg32 & PCI_EXP_LNKCAP_L1EL) >> 15;
*l1 = calc_L1_latency(latency, 0); *l1 = calc_l1_latency(encoding);
} }
pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16); pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
*enabled = reg16 & (PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1); *enabled = reg16 & (PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1);
...@@ -358,8 +356,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) ...@@ -358,8 +356,7 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
/* ENDPOINT states*/ /* ENDPOINT states*/
list_for_each_entry(child, &linkbus->devices, bus_list) { list_for_each_entry(child, &linkbus->devices, bus_list) {
int pos; int pos;
u32 reg32; u32 reg32, encoding;
unsigned int latency;
struct aspm_latency *acceptable = struct aspm_latency *acceptable =
&link->acceptable[PCI_FUNC(child->devfn)]; &link->acceptable[PCI_FUNC(child->devfn)];
...@@ -369,13 +366,11 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) ...@@ -369,13 +366,11 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
pos = pci_find_capability(child, PCI_CAP_ID_EXP); pos = pci_find_capability(child, PCI_CAP_ID_EXP);
pci_read_config_dword(child, pos + PCI_EXP_DEVCAP, &reg32); pci_read_config_dword(child, pos + PCI_EXP_DEVCAP, &reg32);
latency = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6; encoding = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6;
latency = calc_L0S_latency(latency, 1); acceptable->l0s = calc_l0s_acceptable(encoding);
acceptable->l0s = latency;
if (link->aspm_support & PCIE_LINK_STATE_L1) { if (link->aspm_support & PCIE_LINK_STATE_L1) {
latency = (reg32 & PCI_EXP_DEVCAP_L1) >> 9; encoding = (reg32 & PCI_EXP_DEVCAP_L1) >> 9;
latency = calc_L1_latency(latency, 1); acceptable->l1 = calc_l1_acceptable(encoding);
acceptable->l1 = latency;
} }
} }
} }
......
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