1 // SPDX-License-Identifier: GPL-2.0+
3 * PCI Hotplug Driver for PowerPC PowerNV platform.
5 * Copyright Gavin Shan, IBM Corporation 2016.
8 #include <linux/libfdt.h>
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/pci_hotplug.h>
14 #include <asm/pnv-pci.h>
15 #include <asm/ppc-pci.h>
17 #define DRIVER_VERSION "0.1"
18 #define DRIVER_AUTHOR "Gavin Shan, IBM Corporation"
19 #define DRIVER_DESC "PowerPC PowerNV PCI Hotplug Driver"
21 struct pnv_php_event {
23 struct pnv_php_slot *php_slot;
24 struct work_struct work;
27 static LIST_HEAD(pnv_php_slot_list);
28 static DEFINE_SPINLOCK(pnv_php_lock);
30 static void pnv_php_register(struct device_node *dn);
31 static void pnv_php_unregister_one(struct device_node *dn);
32 static void pnv_php_unregister(struct device_node *dn);
34 static void pnv_php_disable_irq(struct pnv_php_slot *php_slot,
37 struct pci_dev *pdev = php_slot->pdev;
38 int irq = php_slot->irq;
41 if (php_slot->irq > 0) {
42 pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &ctrl);
43 ctrl &= ~(PCI_EXP_SLTCTL_HPIE |
45 PCI_EXP_SLTCTL_DLLSCE);
46 pcie_capability_write_word(pdev, PCI_EXP_SLTCTL, ctrl);
48 free_irq(php_slot->irq, php_slot);
53 destroy_workqueue(php_slot->wq);
57 if (disable_device || irq > 0) {
58 if (pdev->msix_enabled)
59 pci_disable_msix(pdev);
60 else if (pdev->msi_enabled)
61 pci_disable_msi(pdev);
63 pci_disable_device(pdev);
67 static void pnv_php_free_slot(struct kref *kref)
69 struct pnv_php_slot *php_slot = container_of(kref,
70 struct pnv_php_slot, kref);
72 WARN_ON(!list_empty(&php_slot->children));
73 pnv_php_disable_irq(php_slot, false);
74 kfree(php_slot->name);
78 static inline void pnv_php_put_slot(struct pnv_php_slot *php_slot)
84 kref_put(&php_slot->kref, pnv_php_free_slot);
87 static struct pnv_php_slot *pnv_php_match(struct device_node *dn,
88 struct pnv_php_slot *php_slot)
90 struct pnv_php_slot *target, *tmp;
92 if (php_slot->dn == dn) {
93 kref_get(&php_slot->kref);
97 list_for_each_entry(tmp, &php_slot->children, link) {
98 target = pnv_php_match(dn, tmp);
106 struct pnv_php_slot *pnv_php_find_slot(struct device_node *dn)
108 struct pnv_php_slot *php_slot, *tmp;
111 spin_lock_irqsave(&pnv_php_lock, flags);
112 list_for_each_entry(tmp, &pnv_php_slot_list, link) {
113 php_slot = pnv_php_match(dn, tmp);
115 spin_unlock_irqrestore(&pnv_php_lock, flags);
119 spin_unlock_irqrestore(&pnv_php_lock, flags);
123 EXPORT_SYMBOL_GPL(pnv_php_find_slot);
126 * Remove pdn for all children of the indicated device node.
127 * The function should remove pdn in a depth-first manner.
129 static void pnv_php_rmv_pdns(struct device_node *dn)
131 struct device_node *child;
133 for_each_child_of_node(dn, child) {
134 pnv_php_rmv_pdns(child);
136 pci_remove_device_node_info(child);
141 * Detach all child nodes of the indicated device nodes. The
142 * function should handle device nodes in depth-first manner.
144 * We should not invoke of_node_release() as the memory for
145 * individual device node is part of large memory block. The
146 * large block is allocated from memblock (system bootup) or
147 * kmalloc() when unflattening the device tree by OF changeset.
148 * We can not free the large block allocated from memblock. For
149 * later case, it should be released at once.
151 static void pnv_php_detach_device_nodes(struct device_node *parent)
153 struct device_node *dn;
156 for_each_child_of_node(parent, dn) {
157 pnv_php_detach_device_nodes(dn);
160 refcount = kref_read(&dn->kobj.kref);
162 pr_warn("Invalid refcount %d on <%pOF>\n",
169 static void pnv_php_rmv_devtree(struct pnv_php_slot *php_slot)
171 pnv_php_rmv_pdns(php_slot->dn);
174 * Decrease the refcount if the device nodes were created
175 * through OF changeset before detaching them.
178 of_changeset_destroy(&php_slot->ocs);
179 pnv_php_detach_device_nodes(php_slot->dn);
183 kfree(php_slot->fdt);
185 php_slot->dn->child = NULL;
186 php_slot->fdt = NULL;
191 * As the nodes in OF changeset are applied in reverse order, we
192 * need revert the nodes in advance so that we have correct node
193 * order after the changeset is applied.
195 static void pnv_php_reverse_nodes(struct device_node *parent)
197 struct device_node *child, *next;
200 for_each_child_of_node(parent, child)
201 pnv_php_reverse_nodes(child);
203 /* Reverse the nodes in the child list */
204 child = parent->child;
205 parent->child = NULL;
207 next = child->sibling;
209 child->sibling = parent->child;
210 parent->child = child;
215 static int pnv_php_populate_changeset(struct of_changeset *ocs,
216 struct device_node *dn)
218 struct device_node *child;
221 for_each_child_of_node(dn, child) {
222 ret = of_changeset_attach_node(ocs, child);
228 ret = pnv_php_populate_changeset(ocs, child);
238 static void *pnv_php_add_one_pdn(struct device_node *dn, void *data)
240 struct pci_controller *hose = (struct pci_controller *)data;
243 pdn = pci_add_device_node_info(hose, dn);
245 return ERR_PTR(-ENOMEM);
250 static void pnv_php_add_pdns(struct pnv_php_slot *slot)
252 struct pci_controller *hose = pci_bus_to_host(slot->bus);
254 pci_traverse_device_nodes(slot->dn, pnv_php_add_one_pdn, hose);
257 static int pnv_php_add_devtree(struct pnv_php_slot *php_slot)
259 void *fdt, *fdt1, *dt;
262 /* We don't know the FDT blob size. We try to get it through
263 * maximal memory chunk and then copy it to another chunk that
264 * fits the real size.
266 fdt1 = kzalloc(0x10000, GFP_KERNEL);
272 ret = pnv_pci_get_device_tree(php_slot->dn->phandle, fdt1, 0x10000);
274 pci_warn(php_slot->pdev, "Error %d getting FDT blob\n", ret);
278 fdt = kmemdup(fdt1, fdt_totalsize(fdt1), GFP_KERNEL);
284 /* Unflatten device tree blob */
285 dt = of_fdt_unflatten_tree(fdt, php_slot->dn, NULL);
288 pci_warn(php_slot->pdev, "Cannot unflatten FDT\n");
292 /* Initialize and apply the changeset */
293 of_changeset_init(&php_slot->ocs);
294 pnv_php_reverse_nodes(php_slot->dn);
295 ret = pnv_php_populate_changeset(&php_slot->ocs, php_slot->dn);
297 pnv_php_reverse_nodes(php_slot->dn);
298 pci_warn(php_slot->pdev, "Error %d populating changeset\n",
303 php_slot->dn->child = NULL;
304 ret = of_changeset_apply(&php_slot->ocs);
306 pci_warn(php_slot->pdev, "Error %d applying changeset\n", ret);
307 goto destroy_changeset;
310 /* Add device node firmware data */
311 pnv_php_add_pdns(php_slot);
318 of_changeset_destroy(&php_slot->ocs);
321 php_slot->dn->child = NULL;
330 static inline struct pnv_php_slot *to_pnv_php_slot(struct hotplug_slot *slot)
332 return container_of(slot, struct pnv_php_slot, slot);
335 int pnv_php_set_slot_power_state(struct hotplug_slot *slot,
338 struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);
342 ret = pnv_pci_set_power_state(php_slot->id, state, &msg);
344 if (be64_to_cpu(msg.params[1]) != php_slot->dn->phandle ||
345 be64_to_cpu(msg.params[2]) != state ||
346 be64_to_cpu(msg.params[3]) != OPAL_SUCCESS) {
347 pci_warn(php_slot->pdev, "Wrong msg (%lld, %lld, %lld)\n",
348 be64_to_cpu(msg.params[1]),
349 be64_to_cpu(msg.params[2]),
350 be64_to_cpu(msg.params[3]));
353 } else if (ret < 0) {
354 pci_warn(php_slot->pdev, "Error %d powering %s\n",
355 ret, (state == OPAL_PCI_SLOT_POWER_ON) ? "on" : "off");
359 if (state == OPAL_PCI_SLOT_POWER_OFF || state == OPAL_PCI_SLOT_OFFLINE)
360 pnv_php_rmv_devtree(php_slot);
362 ret = pnv_php_add_devtree(php_slot);
366 EXPORT_SYMBOL_GPL(pnv_php_set_slot_power_state);
368 static int pnv_php_get_power_state(struct hotplug_slot *slot, u8 *state)
370 struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);
371 uint8_t power_state = OPAL_PCI_SLOT_POWER_ON;
375 * Retrieve power status from firmware. If we fail
376 * getting that, the power status fails back to
379 ret = pnv_pci_get_power_state(php_slot->id, &power_state);
381 pci_warn(php_slot->pdev, "Error %d getting power status\n",
384 *state = power_state;
390 static int pnv_php_get_adapter_state(struct hotplug_slot *slot, u8 *state)
392 struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);
393 uint8_t presence = OPAL_PCI_SLOT_EMPTY;
397 * Retrieve presence status from firmware. If we can't
398 * get that, it will fail back to be empty.
400 ret = pnv_pci_get_presence_state(php_slot->id, &presence);
405 pci_warn(php_slot->pdev, "Error %d getting presence\n", ret);
411 static int pnv_php_get_attention_state(struct hotplug_slot *slot, u8 *state)
413 struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);
415 *state = php_slot->attention_state;
419 static int pnv_php_set_attention_state(struct hotplug_slot *slot, u8 state)
421 struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);
422 struct pci_dev *bridge = php_slot->pdev;
425 php_slot->attention_state = state;
429 mask = PCI_EXP_SLTCTL_AIC;
432 new = PCI_EXP_SLTCTL_ATTN_IND_ON;
434 new = PCI_EXP_SLTCTL_ATTN_IND_OFF;
436 pcie_capability_clear_and_set_word(bridge, PCI_EXP_SLTCTL, mask, new);
441 static int pnv_php_enable(struct pnv_php_slot *php_slot, bool rescan)
443 struct hotplug_slot *slot = &php_slot->slot;
444 uint8_t presence = OPAL_PCI_SLOT_EMPTY;
445 uint8_t power_status = OPAL_PCI_SLOT_POWER_ON;
448 /* Check if the slot has been configured */
449 if (php_slot->state != PNV_PHP_STATE_REGISTERED)
452 /* Retrieve slot presence status */
453 ret = pnv_php_get_adapter_state(slot, &presence);
458 * Proceed if there have nothing behind the slot. However,
459 * we should leave the slot in registered state at the
460 * beginning. Otherwise, the PCI devices inserted afterwards
461 * won't be probed and populated.
463 if (presence == OPAL_PCI_SLOT_EMPTY) {
464 if (!php_slot->power_state_check) {
465 php_slot->power_state_check = true;
474 * If the power supply to the slot is off, we can't detect
475 * adapter presence state. That means we have to turn the
476 * slot on before going to probe slot's presence state.
478 * On the first time, we don't change the power status to
479 * boost system boot with assumption that the firmware
480 * supplies consistent slot power status: empty slot always
481 * has its power off and non-empty slot has its power on.
483 if (!php_slot->power_state_check) {
484 php_slot->power_state_check = true;
486 ret = pnv_php_get_power_state(slot, &power_status);
490 if (power_status != OPAL_PCI_SLOT_POWER_ON)
494 /* Check the power status. Scan the slot if it is already on */
495 ret = pnv_php_get_power_state(slot, &power_status);
499 if (power_status == OPAL_PCI_SLOT_POWER_ON)
502 /* Power is off, turn it on and then scan the slot */
503 ret = pnv_php_set_slot_power_state(slot, OPAL_PCI_SLOT_POWER_ON);
508 if (presence == OPAL_PCI_SLOT_PRESENT) {
510 pci_lock_rescan_remove();
511 pci_hp_add_devices(php_slot->bus);
512 pci_unlock_rescan_remove();
515 /* Rescan for child hotpluggable slots */
516 php_slot->state = PNV_PHP_STATE_POPULATED;
518 pnv_php_register(php_slot->dn);
520 php_slot->state = PNV_PHP_STATE_POPULATED;
526 static int pnv_php_reset_slot(struct hotplug_slot *slot, int probe)
528 struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);
529 struct pci_dev *bridge = php_slot->pdev;
533 * The CAPI folks want pnv_php to drive OpenCAPI slots
534 * which don't have a bridge. Only claim to support
535 * reset_slot() if we have a bridge device (for now...)
540 /* mask our interrupt while resetting the bridge */
541 if (php_slot->irq > 0)
542 disable_irq(php_slot->irq);
544 pci_bridge_secondary_bus_reset(bridge);
546 /* clear any state changes that happened due to the reset */
547 pcie_capability_read_word(php_slot->pdev, PCI_EXP_SLTSTA, &sts);
548 sts &= (PCI_EXP_SLTSTA_PDC | PCI_EXP_SLTSTA_DLLSC);
549 pcie_capability_write_word(php_slot->pdev, PCI_EXP_SLTSTA, sts);
551 if (php_slot->irq > 0)
552 enable_irq(php_slot->irq);
557 static int pnv_php_enable_slot(struct hotplug_slot *slot)
559 struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);
561 return pnv_php_enable(php_slot, true);
564 static int pnv_php_disable_slot(struct hotplug_slot *slot)
566 struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);
569 if (php_slot->state != PNV_PHP_STATE_POPULATED)
572 /* Remove all devices behind the slot */
573 pci_lock_rescan_remove();
574 pci_hp_remove_devices(php_slot->bus);
575 pci_unlock_rescan_remove();
577 /* Detach the child hotpluggable slots */
578 pnv_php_unregister(php_slot->dn);
580 /* Notify firmware and remove device nodes */
581 ret = pnv_php_set_slot_power_state(slot, OPAL_PCI_SLOT_POWER_OFF);
583 php_slot->state = PNV_PHP_STATE_REGISTERED;
587 static const struct hotplug_slot_ops php_slot_ops = {
588 .get_power_status = pnv_php_get_power_state,
589 .get_adapter_status = pnv_php_get_adapter_state,
590 .get_attention_status = pnv_php_get_attention_state,
591 .set_attention_status = pnv_php_set_attention_state,
592 .enable_slot = pnv_php_enable_slot,
593 .disable_slot = pnv_php_disable_slot,
594 .reset_slot = pnv_php_reset_slot,
597 static void pnv_php_release(struct pnv_php_slot *php_slot)
601 /* Remove from global or child list */
602 spin_lock_irqsave(&pnv_php_lock, flags);
603 list_del(&php_slot->link);
604 spin_unlock_irqrestore(&pnv_php_lock, flags);
606 /* Detach from parent */
607 pnv_php_put_slot(php_slot);
608 pnv_php_put_slot(php_slot->parent);
611 static struct pnv_php_slot *pnv_php_alloc_slot(struct device_node *dn)
613 struct pnv_php_slot *php_slot;
619 ret = of_property_read_string(dn, "ibm,slot-label", &label);
623 if (pnv_pci_get_slot_id(dn, &id))
626 bus = pci_find_bus_by_node(dn);
630 php_slot = kzalloc(sizeof(*php_slot), GFP_KERNEL);
634 php_slot->name = kstrdup(label, GFP_KERNEL);
635 if (!php_slot->name) {
640 if (dn->child && PCI_DN(dn->child))
641 php_slot->slot_no = PCI_SLOT(PCI_DN(dn->child)->devfn);
643 php_slot->slot_no = -1; /* Placeholder slot */
645 kref_init(&php_slot->kref);
646 php_slot->state = PNV_PHP_STATE_INITIALIZED;
648 php_slot->pdev = bus->self;
651 php_slot->power_state_check = false;
652 php_slot->slot.ops = &php_slot_ops;
654 INIT_LIST_HEAD(&php_slot->children);
655 INIT_LIST_HEAD(&php_slot->link);
660 static int pnv_php_register_slot(struct pnv_php_slot *php_slot)
662 struct pnv_php_slot *parent;
663 struct device_node *dn = php_slot->dn;
667 /* Check if the slot is registered or not */
668 parent = pnv_php_find_slot(php_slot->dn);
670 pnv_php_put_slot(parent);
674 /* Register PCI slot */
675 ret = pci_hp_register(&php_slot->slot, php_slot->bus,
676 php_slot->slot_no, php_slot->name);
678 pci_warn(php_slot->pdev, "Error %d registering slot\n", ret);
682 /* Attach to the parent's child list or global list */
683 while ((dn = of_get_parent(dn))) {
689 parent = pnv_php_find_slot(dn);
698 spin_lock_irqsave(&pnv_php_lock, flags);
699 php_slot->parent = parent;
701 list_add_tail(&php_slot->link, &parent->children);
703 list_add_tail(&php_slot->link, &pnv_php_slot_list);
704 spin_unlock_irqrestore(&pnv_php_lock, flags);
706 php_slot->state = PNV_PHP_STATE_REGISTERED;
710 static int pnv_php_enable_msix(struct pnv_php_slot *php_slot)
712 struct pci_dev *pdev = php_slot->pdev;
713 struct msix_entry entry;
717 /* Get total number of MSIx entries */
718 nr_entries = pci_msix_vec_count(pdev);
722 /* Check hotplug MSIx entry is in range */
723 pcie_capability_read_word(pdev, PCI_EXP_FLAGS, &pcie_flag);
724 entry.entry = (pcie_flag & PCI_EXP_FLAGS_IRQ) >> 9;
725 if (entry.entry >= nr_entries)
729 ret = pci_enable_msix_exact(pdev, &entry, 1);
731 pci_warn(pdev, "Error %d enabling MSIx\n", ret);
738 static void pnv_php_event_handler(struct work_struct *work)
740 struct pnv_php_event *event =
741 container_of(work, struct pnv_php_event, work);
742 struct pnv_php_slot *php_slot = event->php_slot;
745 pnv_php_enable_slot(&php_slot->slot);
747 pnv_php_disable_slot(&php_slot->slot);
752 static irqreturn_t pnv_php_interrupt(int irq, void *data)
754 struct pnv_php_slot *php_slot = data;
755 struct pci_dev *pchild, *pdev = php_slot->pdev;
756 struct eeh_dev *edev;
758 struct pnv_php_event *event;
765 pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &sts);
766 sts &= (PCI_EXP_SLTSTA_PDC | PCI_EXP_SLTSTA_DLLSC);
767 pcie_capability_write_word(pdev, PCI_EXP_SLTSTA, sts);
769 pci_dbg(pdev, "PCI slot [%s]: HP int! DLAct: %d, PresDet: %d\n",
771 !!(sts & PCI_EXP_SLTSTA_DLLSC),
772 !!(sts & PCI_EXP_SLTSTA_PDC));
774 if (sts & PCI_EXP_SLTSTA_DLLSC) {
775 pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lsts);
776 added = !!(lsts & PCI_EXP_LNKSTA_DLLLA);
777 } else if (!(php_slot->flags & PNV_PHP_FLAG_BROKEN_PDC) &&
778 (sts & PCI_EXP_SLTSTA_PDC)) {
779 ret = pnv_pci_get_presence_state(php_slot->id, &presence);
781 pci_warn(pdev, "PCI slot [%s] error %d getting presence (0x%04x), to retry the operation.\n",
782 php_slot->name, ret, sts);
786 added = !!(presence == OPAL_PCI_SLOT_PRESENT);
788 pci_dbg(pdev, "PCI slot [%s]: Spurious IRQ?\n", php_slot->name);
792 /* Freeze the removed PE to avoid unexpected error reporting */
794 pchild = list_first_entry_or_null(&php_slot->bus->devices,
795 struct pci_dev, bus_list);
796 edev = pchild ? pci_dev_to_eeh_dev(pchild) : NULL;
797 pe = edev ? edev->pe : NULL;
799 eeh_serialize_lock(&flags);
800 eeh_pe_mark_isolated(pe);
801 eeh_serialize_unlock(flags);
802 eeh_pe_set_option(pe, EEH_OPT_FREEZE_PE);
807 * The PE is left in frozen state if the event is missed. It's
808 * fine as the PCI devices (PE) aren't functional any more.
810 event = kzalloc(sizeof(*event), GFP_ATOMIC);
812 pci_warn(pdev, "PCI slot [%s] missed hotplug event 0x%04x\n",
813 php_slot->name, sts);
817 pci_info(pdev, "PCI slot [%s] %s (IRQ: %d)\n",
818 php_slot->name, added ? "added" : "removed", irq);
819 INIT_WORK(&event->work, pnv_php_event_handler);
820 event->added = added;
821 event->php_slot = php_slot;
822 queue_work(php_slot->wq, &event->work);
827 static void pnv_php_init_irq(struct pnv_php_slot *php_slot, int irq)
829 struct pci_dev *pdev = php_slot->pdev;
834 /* Allocate workqueue */
835 php_slot->wq = alloc_workqueue("pciehp-%s", 0, 0, php_slot->name);
837 pci_warn(pdev, "Cannot alloc workqueue\n");
838 pnv_php_disable_irq(php_slot, true);
842 /* Check PDC (Presence Detection Change) is broken or not */
843 ret = of_property_read_u32(php_slot->dn, "ibm,slot-broken-pdc",
845 if (!ret && broken_pdc)
846 php_slot->flags |= PNV_PHP_FLAG_BROKEN_PDC;
848 /* Clear pending interrupts */
849 pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &sts);
850 if (php_slot->flags & PNV_PHP_FLAG_BROKEN_PDC)
851 sts |= PCI_EXP_SLTSTA_DLLSC;
853 sts |= (PCI_EXP_SLTSTA_PDC | PCI_EXP_SLTSTA_DLLSC);
854 pcie_capability_write_word(pdev, PCI_EXP_SLTSTA, sts);
856 /* Request the interrupt */
857 ret = request_irq(irq, pnv_php_interrupt, IRQF_SHARED,
858 php_slot->name, php_slot);
860 pnv_php_disable_irq(php_slot, true);
861 pci_warn(pdev, "Error %d enabling IRQ %d\n", ret, irq);
865 /* Enable the interrupts */
866 pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &ctrl);
867 if (php_slot->flags & PNV_PHP_FLAG_BROKEN_PDC) {
868 ctrl &= ~PCI_EXP_SLTCTL_PDCE;
869 ctrl |= (PCI_EXP_SLTCTL_HPIE |
870 PCI_EXP_SLTCTL_DLLSCE);
872 ctrl |= (PCI_EXP_SLTCTL_HPIE |
873 PCI_EXP_SLTCTL_PDCE |
874 PCI_EXP_SLTCTL_DLLSCE);
876 pcie_capability_write_word(pdev, PCI_EXP_SLTCTL, ctrl);
878 /* The interrupt is initialized successfully when @irq is valid */
882 static void pnv_php_enable_irq(struct pnv_php_slot *php_slot)
884 struct pci_dev *pdev = php_slot->pdev;
888 * The MSI/MSIx interrupt might have been occupied by other
889 * drivers. Don't populate the surprise hotplug capability
892 if (pci_dev_msi_enabled(pdev))
895 ret = pci_enable_device(pdev);
897 pci_warn(pdev, "Error %d enabling device\n", ret);
901 pci_set_master(pdev);
903 /* Enable MSIx interrupt */
904 irq = pnv_php_enable_msix(php_slot);
906 pnv_php_init_irq(php_slot, irq);
911 * Use MSI if MSIx doesn't work. Fail back to legacy INTx
912 * if MSI doesn't work either
914 ret = pci_enable_msi(pdev);
915 if (!ret || pdev->irq) {
917 pnv_php_init_irq(php_slot, irq);
921 static int pnv_php_register_one(struct device_node *dn)
923 struct pnv_php_slot *php_slot;
927 /* Check if it's hotpluggable slot */
928 ret = of_property_read_u32(dn, "ibm,slot-pluggable", &prop32);
932 ret = of_property_read_u32(dn, "ibm,reset-by-firmware", &prop32);
936 php_slot = pnv_php_alloc_slot(dn);
940 ret = pnv_php_register_slot(php_slot);
944 ret = pnv_php_enable(php_slot, false);
946 goto unregister_slot;
948 /* Enable interrupt if the slot supports surprise hotplug */
949 ret = of_property_read_u32(dn, "ibm,slot-surprise-pluggable", &prop32);
951 pnv_php_enable_irq(php_slot);
956 pnv_php_unregister_one(php_slot->dn);
958 pnv_php_put_slot(php_slot);
962 static void pnv_php_register(struct device_node *dn)
964 struct device_node *child;
967 * The parent slots should be registered before their
970 for_each_child_of_node(dn, child) {
971 pnv_php_register_one(child);
972 pnv_php_register(child);
976 static void pnv_php_unregister_one(struct device_node *dn)
978 struct pnv_php_slot *php_slot;
980 php_slot = pnv_php_find_slot(dn);
984 php_slot->state = PNV_PHP_STATE_OFFLINE;
985 pci_hp_deregister(&php_slot->slot);
986 pnv_php_release(php_slot);
987 pnv_php_put_slot(php_slot);
990 static void pnv_php_unregister(struct device_node *dn)
992 struct device_node *child;
994 /* The child slots should go before their parent slots */
995 for_each_child_of_node(dn, child) {
996 pnv_php_unregister(child);
997 pnv_php_unregister_one(child);
1001 static int __init pnv_php_init(void)
1003 struct device_node *dn;
1005 pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
1006 for_each_compatible_node(dn, NULL, "ibm,ioda2-phb")
1007 pnv_php_register(dn);
1009 for_each_compatible_node(dn, NULL, "ibm,ioda3-phb")
1010 pnv_php_register(dn);
1015 static void __exit pnv_php_exit(void)
1017 struct device_node *dn;
1019 for_each_compatible_node(dn, NULL, "ibm,ioda2-phb")
1020 pnv_php_unregister(dn);
1022 for_each_compatible_node(dn, NULL, "ibm,ioda3-phb")
1023 pnv_php_unregister(dn);
1026 module_init(pnv_php_init);
1027 module_exit(pnv_php_exit);
1029 MODULE_VERSION(DRIVER_VERSION);
1030 MODULE_LICENSE("GPL v2");
1031 MODULE_AUTHOR(DRIVER_AUTHOR);
1032 MODULE_DESCRIPTION(DRIVER_DESC);