Lines Matching defs:link
3 * Enabling PCIe link L0s/L1 state and Clock Power Management
43 struct pcie_link_state *root; /* pointer to the root port link */
46 struct list_head children; /* list of child link states */
47 struct list_head link; /* node in parent's children list */
87 static int policy_to_aspm_state(struct pcie_link_state *link)
97 return link->aspm_default;
102 static int policy_to_clkpm_state(struct pcie_link_state *link)
112 return link->clkpm_default;
117 static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable)
122 struct pci_bus *linkbus = link->pdev->subordinate;
135 link->clkpm_enabled = !!enable;
138 static void pcie_set_clkpm(struct pcie_link_state *link, int enable)
140 /* Don't enable Clock PM if the link is not Clock PM capable */
141 if (!link->clkpm_capable && enable)
144 if (link->clkpm_enabled == enable)
146 pcie_set_clkpm_nocheck(link, enable);
149 static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
155 struct pci_bus *linkbus = link->pdev->subordinate;
172 link->clkpm_enabled = enabled;
173 link->clkpm_default = enabled;
174 link->clkpm_capable = (blacklist) ? 0 : capable;
178 * pcie_aspm_configure_common_clock: check if the 2 ends of a link
182 static void pcie_aspm_configure_common_clock(struct pcie_link_state *link)
187 struct pci_dev *child, *parent = link->pdev;
229 /* Retrain link */
233 /* Wait for link training end. Break out after waiting for timeout */
316 struct pcie_link_state *link;
323 link = endpoint->bus->self->link_state;
324 acceptable = &link->acceptable[PCI_FUNC(endpoint->devfn)];
326 while (link) {
328 if ((link->aspm_capable & ASPM_STATE_L0S_UP) &&
329 (link->latency_up.l0s > acceptable->l0s))
330 link->aspm_capable &= ~ASPM_STATE_L0S_UP;
333 if ((link->aspm_capable & ASPM_STATE_L0S_DW) &&
334 (link->latency_dw.l0s > acceptable->l0s))
335 link->aspm_capable &= ~ASPM_STATE_L0S_DW;
341 latency = max_t(u32, link->latency_up.l1, link->latency_dw.l1);
342 if ((link->aspm_capable & ASPM_STATE_L1) &&
344 link->aspm_capable &= ~ASPM_STATE_L1;
347 link = link->parent;
351 static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
353 struct pci_dev *child, *parent = link->pdev;
359 link->aspm_enabled = ASPM_STATE_ALL;
360 link->aspm_disable = ASPM_STATE_ALL;
365 pcie_aspm_configure_common_clock(link);
376 * given link unless components on both sides of the link each
380 link->aspm_support |= ASPM_STATE_L0S;
382 link->aspm_enabled |= ASPM_STATE_L0S_UP;
384 link->aspm_enabled |= ASPM_STATE_L0S_DW;
385 link->latency_up.l0s = calc_l0s_latency(upreg.latency_encoding_l0s);
386 link->latency_dw.l0s = calc_l0s_latency(dwreg.latency_encoding_l0s);
390 link->aspm_support |= ASPM_STATE_L1;
392 link->aspm_enabled |= ASPM_STATE_L1;
393 link->latency_up.l1 = calc_l1_latency(upreg.latency_encoding_l1);
394 link->latency_dw.l1 = calc_l1_latency(dwreg.latency_encoding_l1);
397 link->aspm_default = link->aspm_enabled;
400 link->aspm_capable = link->aspm_support;
407 link->aspm_disable = ASPM_STATE_ALL;
417 &link->acceptable[PCI_FUNC(child->devfn)];
447 static void pcie_config_aspm_link(struct pcie_link_state *link, u32 state)
450 struct pci_dev *child, *parent = link->pdev;
453 /* Nothing to do if the link is already in the requested state */
454 state &= (link->aspm_capable & ~link->aspm_disable);
455 if (link->aspm_enabled == state)
479 link->aspm_enabled = state;
482 static void pcie_config_aspm_path(struct pcie_link_state *link)
484 while (link) {
485 pcie_config_aspm_link(link, policy_to_aspm_state(link));
486 link = link->parent;
490 static void free_link_state(struct pcie_link_state *link)
492 link->pdev->link_state = NULL;
493 kfree(link);
526 struct pcie_link_state *link;
528 link = kzalloc(sizeof(*link), GFP_KERNEL);
529 if (!link)
531 INIT_LIST_HEAD(&link->sibling);
532 INIT_LIST_HEAD(&link->children);
533 INIT_LIST_HEAD(&link->link);
534 link->pdev = pdev;
539 kfree(link);
542 link->parent = parent;
543 list_add(&link->link, &parent->children);
545 /* Setup a pointer to the root port link */
546 if (!link->parent)
547 link->root = link;
549 link->root = link->parent->root;
551 list_add(&link->sibling, &link_list);
552 pdev->link_state = link;
553 return link;
557 * pcie_aspm_init_link_state: Initiate PCI express link state.
563 struct pcie_link_state *link;
582 link = alloc_pcie_link_state(pdev);
583 if (!link)
590 pcie_aspm_cap_init(link, blacklist);
593 pcie_clkpm_cap_init(link, blacklist);
597 * link policy setting. Enabling ASPM on broken hardware can cripple
604 pcie_config_aspm_path(link);
605 pcie_set_clkpm(link, policy_to_clkpm_state(link));
617 struct pcie_link_state *link;
619 list_for_each_entry(link, &link_list, sibling) {
620 if (link->root != root)
622 link->aspm_capable = link->aspm_support;
624 list_for_each_entry(link, &link_list, sibling) {
626 struct pci_bus *linkbus = link->pdev->subordinate;
627 if (link->root != root)
642 struct pcie_link_state *link, *root, *parent_link;
660 link = parent->link_state;
661 root = link->root;
662 parent_link = link->parent;
664 /* All functions are removed, so just disable ASPM for the link */
665 pcie_config_aspm_link(link, 0);
666 list_del(&link->sibling);
667 list_del(&link->link);
669 free_link_state(link);
684 struct pcie_link_state *link = pdev->link_state;
686 if (aspm_disabled || !pci_is_pcie(pdev) || !link)
697 pcie_update_aspm_capable(link->root);
698 pcie_config_aspm_path(link);
704 * pci_disable_link_state - disable pci device's link state, so the link will
710 struct pcie_link_state *link;
722 link = parent->link_state;
724 link->aspm_disable |= ASPM_STATE_L0S;
726 link->aspm_disable |= ASPM_STATE_L1;
727 pcie_config_aspm_link(link, policy_to_aspm_state(link));
730 link->clkpm_capable = 0;
731 pcie_set_clkpm(link, 0);
741 struct pcie_link_state *link;
754 list_for_each_entry(link, &link_list, sibling) {
755 pcie_config_aspm_link(link, policy_to_aspm_state(link));
756 pcie_set_clkpm(link, policy_to_clkpm_state(link));
794 struct pcie_link_state *link, *root = pdev->link_state->root;
808 list_for_each_entry(link, &link_list, sibling) {
809 if (link->root != root)
811 pcie_config_aspm_link(link, state);