Lines Matching +full:back +full:- +full:powering
1 // SPDX-License-Identifier: GPL-2.0+
16 #include <asm/pnv-pci.h>
17 #include <asm/ppc-pci.h>
24 ((sl)->pdev ? pci_warn((sl)->pdev, x) : dev_warn(&(sl)->bus->dev, x))
42 struct pci_dev *pdev = php_slot->pdev; in pnv_php_disable_irq()
45 if (php_slot->irq > 0) { in pnv_php_disable_irq()
52 free_irq(php_slot->irq, php_slot); in pnv_php_disable_irq()
53 php_slot->irq = 0; in pnv_php_disable_irq()
56 if (php_slot->wq) { in pnv_php_disable_irq()
57 destroy_workqueue(php_slot->wq); in pnv_php_disable_irq()
58 php_slot->wq = NULL; in pnv_php_disable_irq()
62 if (pdev->msix_enabled) in pnv_php_disable_irq()
64 else if (pdev->msi_enabled) in pnv_php_disable_irq()
76 WARN_ON(!list_empty(&php_slot->children)); in pnv_php_free_slot()
78 kfree(php_slot->name); in pnv_php_free_slot()
88 kref_put(&php_slot->kref, pnv_php_free_slot); in pnv_php_put_slot()
96 if (php_slot->dn == dn) { in pnv_php_match()
97 kref_get(&php_slot->kref); in pnv_php_match()
101 list_for_each_entry(tmp, &php_slot->children, link) { in pnv_php_match()
131 * The function should remove pdn in a depth-first manner.
146 * function should handle device nodes in depth-first manner.
169 pnv_php_rmv_pdns(php_slot->dn); in pnv_php_rmv_devtree()
175 if (php_slot->fdt) in pnv_php_rmv_devtree()
176 of_changeset_destroy(&php_slot->ocs); in pnv_php_rmv_devtree()
177 pnv_php_detach_device_nodes(php_slot->dn); in pnv_php_rmv_devtree()
179 if (php_slot->fdt) { in pnv_php_rmv_devtree()
180 kfree(php_slot->dt); in pnv_php_rmv_devtree()
181 kfree(php_slot->fdt); in pnv_php_rmv_devtree()
182 php_slot->dt = NULL; in pnv_php_rmv_devtree()
183 php_slot->dn->child = NULL; in pnv_php_rmv_devtree()
184 php_slot->fdt = NULL; in pnv_php_rmv_devtree()
197 /* In-depth first */ in pnv_php_reverse_nodes()
202 child = parent->child; in pnv_php_reverse_nodes()
203 parent->child = NULL; in pnv_php_reverse_nodes()
205 next = child->sibling; in pnv_php_reverse_nodes()
207 child->sibling = parent->child; in pnv_php_reverse_nodes()
208 parent->child = child; in pnv_php_reverse_nodes()
243 return ERR_PTR(-ENOMEM); in pnv_php_add_one_pdn()
250 struct pci_controller *hose = pci_bus_to_host(slot->bus); in pnv_php_add_pdns()
252 pci_traverse_device_nodes(slot->dn, pnv_php_add_one_pdn, hose); in pnv_php_add_pdns()
266 ret = -ENOMEM; in pnv_php_add_devtree()
270 ret = pnv_pci_get_device_tree(php_slot->dn->phandle, fdt1, 0x10000); in pnv_php_add_devtree()
278 ret = -ENOMEM; in pnv_php_add_devtree()
283 dt = of_fdt_unflatten_tree(fdt, php_slot->dn, NULL); in pnv_php_add_devtree()
285 ret = -EINVAL; in pnv_php_add_devtree()
291 of_changeset_init(&php_slot->ocs); in pnv_php_add_devtree()
292 pnv_php_reverse_nodes(php_slot->dn); in pnv_php_add_devtree()
293 ret = pnv_php_populate_changeset(&php_slot->ocs, php_slot->dn); in pnv_php_add_devtree()
295 pnv_php_reverse_nodes(php_slot->dn); in pnv_php_add_devtree()
301 php_slot->dn->child = NULL; in pnv_php_add_devtree()
302 ret = of_changeset_apply(&php_slot->ocs); in pnv_php_add_devtree()
310 php_slot->fdt = fdt; in pnv_php_add_devtree()
311 php_slot->dt = dt; in pnv_php_add_devtree()
316 of_changeset_destroy(&php_slot->ocs); in pnv_php_add_devtree()
319 php_slot->dn->child = NULL; in pnv_php_add_devtree()
340 ret = pnv_pci_set_power_state(php_slot->id, state, &msg); in pnv_php_set_slot_power_state()
342 if (be64_to_cpu(msg.params[1]) != php_slot->dn->phandle || in pnv_php_set_slot_power_state()
348 return -ENOMSG; in pnv_php_set_slot_power_state()
351 ret = -ENODEV; in pnv_php_set_slot_power_state()
366 SLOT_WARN(php_slot, "Error %d powering %s\n", in pnv_php_set_slot_power_state()
380 * getting that, the power status fails back to in pnv_php_get_power_state()
383 ret = pnv_pci_get_power_state(php_slot->id, &power_state); in pnv_php_get_power_state()
402 * get that, it will fail back to be empty. in pnv_php_get_adapter_state()
404 ret = pnv_pci_get_presence_state(php_slot->id, &presence); in pnv_php_get_adapter_state()
419 *state = php_slot->attention_state; in pnv_php_get_attention_state()
426 struct pci_dev *bridge = php_slot->pdev; in pnv_php_set_attention_state()
429 php_slot->attention_state = state; in pnv_php_set_attention_state()
447 struct hotplug_slot *slot = &php_slot->slot; in pnv_php_enable()
453 if (php_slot->state != PNV_PHP_STATE_REGISTERED) in pnv_php_enable()
468 if (!php_slot->power_state_check) { in pnv_php_enable()
469 php_slot->power_state_check = true; in pnv_php_enable()
485 * has its power off and non-empty slot has its power on. in pnv_php_enable()
487 if (!php_slot->power_state_check) { in pnv_php_enable()
488 php_slot->power_state_check = true; in pnv_php_enable()
515 pci_hp_add_devices(php_slot->bus); in pnv_php_enable()
520 php_slot->state = PNV_PHP_STATE_POPULATED; in pnv_php_enable()
522 pnv_php_register(php_slot->dn); in pnv_php_enable()
524 php_slot->state = PNV_PHP_STATE_POPULATED; in pnv_php_enable()
533 struct pci_dev *bridge = php_slot->pdev; in pnv_php_reset_slot()
545 if (php_slot->irq > 0) in pnv_php_reset_slot()
546 disable_irq(php_slot->irq); in pnv_php_reset_slot()
551 pcie_capability_read_word(php_slot->pdev, PCI_EXP_SLTSTA, &sts); in pnv_php_reset_slot()
553 pcie_capability_write_word(php_slot->pdev, PCI_EXP_SLTSTA, sts); in pnv_php_reset_slot()
555 if (php_slot->irq > 0) in pnv_php_reset_slot()
556 enable_irq(php_slot->irq); in pnv_php_reset_slot()
578 if (php_slot->state != PNV_PHP_STATE_POPULATED && in pnv_php_disable_slot()
579 php_slot->state != PNV_PHP_STATE_REGISTERED) in pnv_php_disable_slot()
584 pci_hp_remove_devices(php_slot->bus); in pnv_php_disable_slot()
588 pnv_php_unregister(php_slot->dn); in pnv_php_disable_slot()
593 php_slot->state = PNV_PHP_STATE_REGISTERED; in pnv_php_disable_slot()
613 list_del(&php_slot->link); in pnv_php_release()
618 pnv_php_put_slot(php_slot->parent); in pnv_php_release()
629 ret = of_property_read_string(dn, "ibm,slot-label", &label); in pnv_php_alloc_slot()
644 php_slot->name = kstrdup(label, GFP_KERNEL); in pnv_php_alloc_slot()
645 if (!php_slot->name) { in pnv_php_alloc_slot()
650 if (dn->child && PCI_DN(dn->child)) in pnv_php_alloc_slot()
651 php_slot->slot_no = PCI_SLOT(PCI_DN(dn->child)->devfn); in pnv_php_alloc_slot()
653 php_slot->slot_no = -1; /* Placeholder slot */ in pnv_php_alloc_slot()
655 kref_init(&php_slot->kref); in pnv_php_alloc_slot()
656 php_slot->state = PNV_PHP_STATE_INITIALIZED; in pnv_php_alloc_slot()
657 php_slot->dn = dn; in pnv_php_alloc_slot()
658 php_slot->pdev = bus->self; in pnv_php_alloc_slot()
659 php_slot->bus = bus; in pnv_php_alloc_slot()
660 php_slot->id = id; in pnv_php_alloc_slot()
661 php_slot->power_state_check = false; in pnv_php_alloc_slot()
662 php_slot->slot.ops = &php_slot_ops; in pnv_php_alloc_slot()
664 INIT_LIST_HEAD(&php_slot->children); in pnv_php_alloc_slot()
665 INIT_LIST_HEAD(&php_slot->link); in pnv_php_alloc_slot()
673 struct device_node *dn = php_slot->dn; in pnv_php_register_slot()
678 parent = pnv_php_find_slot(php_slot->dn); in pnv_php_register_slot()
681 return -EEXIST; in pnv_php_register_slot()
685 ret = pci_hp_register(&php_slot->slot, php_slot->bus, in pnv_php_register_slot()
686 php_slot->slot_no, php_slot->name); in pnv_php_register_slot()
709 php_slot->parent = parent; in pnv_php_register_slot()
711 list_add_tail(&php_slot->link, &parent->children); in pnv_php_register_slot()
713 list_add_tail(&php_slot->link, &pnv_php_slot_list); in pnv_php_register_slot()
716 php_slot->state = PNV_PHP_STATE_REGISTERED; in pnv_php_register_slot()
722 struct pci_dev *pdev = php_slot->pdev; in pnv_php_enable_msix()
736 return -ERANGE; in pnv_php_enable_msix()
752 struct pnv_php_slot *php_slot = event->php_slot; in pnv_php_event_handler()
754 if (event->added) in pnv_php_event_handler()
755 pnv_php_enable_slot(&php_slot->slot); in pnv_php_event_handler()
757 pnv_php_disable_slot(&php_slot->slot); in pnv_php_event_handler()
765 struct pci_dev *pchild, *pdev = php_slot->pdev; in pnv_php_interrupt()
780 php_slot->name, in pnv_php_interrupt()
787 } else if (!(php_slot->flags & PNV_PHP_FLAG_BROKEN_PDC) && in pnv_php_interrupt()
789 ret = pnv_pci_get_presence_state(php_slot->id, &presence); in pnv_php_interrupt()
793 php_slot->name, ret, sts); in pnv_php_interrupt()
799 pci_dbg(pdev, "PCI slot [%s]: Spurious IRQ?\n", php_slot->name); in pnv_php_interrupt()
805 pchild = list_first_entry_or_null(&php_slot->bus->devices, in pnv_php_interrupt()
808 pe = edev ? edev->pe : NULL; in pnv_php_interrupt()
825 php_slot->name, sts); in pnv_php_interrupt()
830 php_slot->name, added ? "added" : "removed", irq); in pnv_php_interrupt()
831 INIT_WORK(&event->work, pnv_php_event_handler); in pnv_php_interrupt()
832 event->added = added; in pnv_php_interrupt()
833 event->php_slot = php_slot; in pnv_php_interrupt()
834 queue_work(php_slot->wq, &event->work); in pnv_php_interrupt()
841 struct pci_dev *pdev = php_slot->pdev; in pnv_php_init_irq()
847 php_slot->wq = alloc_workqueue("pciehp-%s", 0, 0, php_slot->name); in pnv_php_init_irq()
848 if (!php_slot->wq) { in pnv_php_init_irq()
855 ret = of_property_read_u32(php_slot->dn, "ibm,slot-broken-pdc", in pnv_php_init_irq()
858 php_slot->flags |= PNV_PHP_FLAG_BROKEN_PDC; in pnv_php_init_irq()
862 if (php_slot->flags & PNV_PHP_FLAG_BROKEN_PDC) in pnv_php_init_irq()
870 php_slot->name, php_slot); in pnv_php_init_irq()
879 if (php_slot->flags & PNV_PHP_FLAG_BROKEN_PDC) { in pnv_php_init_irq()
891 php_slot->irq = irq; in pnv_php_init_irq()
896 struct pci_dev *pdev = php_slot->pdev; in pnv_php_enable_irq()
923 * Use MSI if MSIx doesn't work. Fail back to legacy INTx in pnv_php_enable_irq()
927 if (!ret || pdev->irq) { in pnv_php_enable_irq()
928 irq = pdev->irq; in pnv_php_enable_irq()
940 ret = of_property_read_u32(dn, "ibm,slot-pluggable", &prop32); in pnv_php_register_one()
942 return -ENXIO; in pnv_php_register_one()
944 ret = of_property_read_u32(dn, "ibm,reset-by-firmware", &prop32); in pnv_php_register_one()
946 return -ENXIO; in pnv_php_register_one()
950 return -ENODEV; in pnv_php_register_one()
961 ret = of_property_read_u32(dn, "ibm,slot-surprise-pluggable", &prop32); in pnv_php_register_one()
968 pnv_php_unregister_one(php_slot->dn); in pnv_php_register_one()
996 php_slot->state = PNV_PHP_STATE_OFFLINE; in pnv_php_unregister_one()
997 pci_hp_deregister(&php_slot->slot); in pnv_php_unregister_one()
1018 for_each_compatible_node(dn, NULL, "ibm,ioda2-phb") in pnv_php_init()
1021 for_each_compatible_node(dn, NULL, "ibm,ioda3-phb") in pnv_php_init()
1024 for_each_compatible_node(dn, NULL, "ibm,ioda2-npu2-opencapi-phb") in pnv_php_init()
1033 for_each_compatible_node(dn, NULL, "ibm,ioda2-phb") in pnv_php_exit()
1036 for_each_compatible_node(dn, NULL, "ibm,ioda3-phb") in pnv_php_exit()
1039 for_each_compatible_node(dn, NULL, "ibm,ioda2-npu2-opencapi-phb") in pnv_php_exit()