aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/pcie/aspm.c
diff options
context:
space:
mode:
authorKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>2009-05-12 23:21:48 -0400
committerJesse Barnes <jbarnes@virtuousgeek.org>2009-06-18 17:02:21 -0400
commit5e0eaa7d3679c3ef8618803bc9311270e5816641 (patch)
tree895538798c0fd42aa499ac78ed0cb40a8fec27fa /drivers/pci/pcie/aspm.c
parent7ab709910323a8af20722c066267516b3e7680a2 (diff)
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: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'drivers/pci/pcie/aspm.c')
-rw-r--r--drivers/pci/pcie/aspm.c73
1 files changed, 34 insertions, 39 deletions
diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index d85f77ff150c..23fabb303e82 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -257,38 +257,36 @@ static void pcie_aspm_configure_common_clock(struct pcie_link_state *link)
257 pci_write_config_word(parent, ppos + PCI_EXP_LNKCTL, parent_reg); 257 pci_write_config_word(parent, ppos + PCI_EXP_LNKCTL, parent_reg);
258} 258}
259 259
260/* 260/* Convert L0s latency encoding to ns */
261 * calc_L0S_latency: Convert L0s latency encoding to ns 261static u32 calc_l0s_latency(u32 encoding)
262 */
263static unsigned int calc_L0S_latency(unsigned int latency_encoding, int ac)
264{ 262{
265 unsigned int ns = 64; 263 if (encoding == 0x7)
264 return (5 * 1000); /* > 4us */
265 return (64 << encoding);
266}
266 267
267 if (latency_encoding == 0x7) { 268/* Convert L0s acceptable latency encoding to ns */
268 if (ac) 269static u32 calc_l0s_acceptable(u32 encoding)
269 ns = -1U; 270{
270 else 271 if (encoding == 0x7)
271 ns = 5*1000; /* > 4us */ 272 return -1U;
272 } else 273 return (64 << encoding);
273 ns *= (1 << latency_encoding);
274 return ns;
275} 274}
276 275
277/* 276/* Convert L1 latency encoding to ns */
278 * calc_L1_latency: Convert L1 latency encoding to ns 277static u32 calc_l1_latency(u32 encoding)
279 */
280static unsigned int calc_L1_latency(unsigned int latency_encoding, int ac)
281{ 278{
282 unsigned int ns = 1000; 279 if (encoding == 0x7)
280 return (65 * 1000); /* > 64us */
281 return (1000 << encoding);
282}
283 283
284 if (latency_encoding == 0x7) { 284/* Convert L1 acceptable latency encoding to ns */
285 if (ac) 285static u32 calc_l1_acceptable(u32 encoding)
286 ns = -1U; 286{
287 else 287 if (encoding == 0x7)
288 ns = 65*1000; /* > 64us */ 288 return -1U;
289 } else 289 return (1000 << encoding);
290 ns *= (1 << latency_encoding);
291 return ns;
292} 290}
293 291
294static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state, 292static 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{ 294{
297 int pos; 295 int pos;
298 u16 reg16; 296 u16 reg16;
299 u32 reg32, latency; 297 u32 reg32, encoding;
300 298
301 *l0s = *l1 = *enabled = 0; 299 *l0s = *l1 = *enabled = 0;
302 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); 300 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 if (*state == 0) 306 if (*state == 0)
309 return; 307 return;
310 308
311 latency = (reg32 & PCI_EXP_LNKCAP_L0SEL) >> 12; 309 encoding = (reg32 & PCI_EXP_LNKCAP_L0SEL) >> 12;
312 *l0s = calc_L0S_latency(latency, 0); 310 *l0s = calc_l0s_latency(encoding);
313 if (*state & PCIE_LINK_STATE_L1) { 311 if (*state & PCIE_LINK_STATE_L1) {
314 latency = (reg32 & PCI_EXP_LNKCAP_L1EL) >> 15; 312 encoding = (reg32 & PCI_EXP_LNKCAP_L1EL) >> 15;
315 *l1 = calc_L1_latency(latency, 0); 313 *l1 = calc_l1_latency(encoding);
316 } 314 }
317 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16); 315 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
318 *enabled = reg16 & (PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1); 316 *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 /* ENDPOINT states*/ 356 /* ENDPOINT states*/
359 list_for_each_entry(child, &linkbus->devices, bus_list) { 357 list_for_each_entry(child, &linkbus->devices, bus_list) {
360 int pos; 358 int pos;
361 u32 reg32; 359 u32 reg32, encoding;
362 unsigned int latency;
363 struct aspm_latency *acceptable = 360 struct aspm_latency *acceptable =
364 &link->acceptable[PCI_FUNC(child->devfn)]; 361 &link->acceptable[PCI_FUNC(child->devfn)];
365 362
@@ -369,13 +366,11 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
369 366
370 pos = pci_find_capability(child, PCI_CAP_ID_EXP); 367 pos = pci_find_capability(child, PCI_CAP_ID_EXP);
371 pci_read_config_dword(child, pos + PCI_EXP_DEVCAP, &reg32); 368 pci_read_config_dword(child, pos + PCI_EXP_DEVCAP, &reg32);
372 latency = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6; 369 encoding = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6;
373 latency = calc_L0S_latency(latency, 1); 370 acceptable->l0s = calc_l0s_acceptable(encoding);
374 acceptable->l0s = latency;
375 if (link->aspm_support & PCIE_LINK_STATE_L1) { 371 if (link->aspm_support & PCIE_LINK_STATE_L1) {
376 latency = (reg32 & PCI_EXP_DEVCAP_L1) >> 9; 372 encoding = (reg32 & PCI_EXP_DEVCAP_L1) >> 9;
377 latency = calc_L1_latency(latency, 1); 373 acceptable->l1 = calc_l1_acceptable(encoding);
378 acceptable->l1 = latency;
379 } 374 }
380 } 375 }
381} 376}