diff options
Diffstat (limited to 'drivers/pci/hotplug/pnv_php.c')
| -rw-r--r-- | drivers/pci/hotplug/pnv_php.c | 82 | 
1 files changed, 49 insertions, 33 deletions
diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c index d7b2b47bc33e..04565162a449 100644 --- a/drivers/pci/hotplug/pnv_php.c +++ b/drivers/pci/hotplug/pnv_php.c @@ -18,6 +18,9 @@  #define DRIVER_AUTHOR	"Gavin Shan, IBM Corporation"  #define DRIVER_DESC	"PowerPC PowerNV PCI Hotplug Driver" +#define SLOT_WARN(sl, x...) \ +	((sl)->pdev ? pci_warn((sl)->pdev, x) : dev_warn(&(sl)->bus->dev, x)) +  struct pnv_php_event {  	bool			added;  	struct pnv_php_slot	*php_slot; @@ -151,17 +154,11 @@ static void pnv_php_rmv_pdns(struct device_node *dn)  static void pnv_php_detach_device_nodes(struct device_node *parent)  {  	struct device_node *dn; -	int refcount;  	for_each_child_of_node(parent, dn) {  		pnv_php_detach_device_nodes(dn);  		of_node_put(dn); -		refcount = kref_read(&dn->kobj.kref); -		if (refcount != 1) -			pr_warn("Invalid refcount %d on <%pOF>\n", -				refcount, dn); -  		of_detach_node(dn);  	}  } @@ -271,7 +268,7 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot)  	ret = pnv_pci_get_device_tree(php_slot->dn->phandle, fdt1, 0x10000);  	if (ret) { -		pci_warn(php_slot->pdev, "Error %d getting FDT blob\n", ret); +		SLOT_WARN(php_slot, "Error %d getting FDT blob\n", ret);  		goto free_fdt1;  	} @@ -285,7 +282,7 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot)  	dt = of_fdt_unflatten_tree(fdt, php_slot->dn, NULL);  	if (!dt) {  		ret = -EINVAL; -		pci_warn(php_slot->pdev, "Cannot unflatten FDT\n"); +		SLOT_WARN(php_slot, "Cannot unflatten FDT\n");  		goto free_fdt;  	} @@ -295,15 +292,15 @@ static int pnv_php_add_devtree(struct pnv_php_slot *php_slot)  	ret = pnv_php_populate_changeset(&php_slot->ocs, php_slot->dn);  	if (ret) {  		pnv_php_reverse_nodes(php_slot->dn); -		pci_warn(php_slot->pdev, "Error %d populating changeset\n", -			 ret); +		SLOT_WARN(php_slot, "Error %d populating changeset\n", +			  ret);  		goto free_dt;  	}  	php_slot->dn->child = NULL;  	ret = of_changeset_apply(&php_slot->ocs);  	if (ret) { -		pci_warn(php_slot->pdev, "Error %d applying changeset\n", ret); +		SLOT_WARN(php_slot, "Error %d applying changeset\n", ret);  		goto destroy_changeset;  	} @@ -342,18 +339,19 @@ int pnv_php_set_slot_power_state(struct hotplug_slot *slot,  	ret = pnv_pci_set_power_state(php_slot->id, state, &msg);  	if (ret > 0) {  		if (be64_to_cpu(msg.params[1]) != php_slot->dn->phandle	|| -		    be64_to_cpu(msg.params[2]) != state			|| -		    be64_to_cpu(msg.params[3]) != OPAL_SUCCESS) { -			pci_warn(php_slot->pdev, "Wrong msg (%lld, %lld, %lld)\n", -				 be64_to_cpu(msg.params[1]), -				 be64_to_cpu(msg.params[2]), -				 be64_to_cpu(msg.params[3])); +		    be64_to_cpu(msg.params[2]) != state) { +			SLOT_WARN(php_slot, "Wrong msg (%lld, %lld, %lld)\n", +				  be64_to_cpu(msg.params[1]), +				  be64_to_cpu(msg.params[2]), +				  be64_to_cpu(msg.params[3]));  			return -ENOMSG;  		} +		if (be64_to_cpu(msg.params[3]) != OPAL_SUCCESS) { +			ret = -ENODEV; +			goto error; +		}  	} else if (ret < 0) { -		pci_warn(php_slot->pdev, "Error %d powering %s\n", -			 ret, (state == OPAL_PCI_SLOT_POWER_ON) ? "on" : "off"); -		return ret; +		goto error;  	}  	if (state == OPAL_PCI_SLOT_POWER_OFF || state == OPAL_PCI_SLOT_OFFLINE) @@ -362,6 +360,11 @@ int pnv_php_set_slot_power_state(struct hotplug_slot *slot,  		ret = pnv_php_add_devtree(php_slot);  	return ret; + +error: +	SLOT_WARN(php_slot, "Error %d powering %s\n", +		  ret, (state == OPAL_PCI_SLOT_POWER_ON) ? "on" : "off"); +	return ret;  }  EXPORT_SYMBOL_GPL(pnv_php_set_slot_power_state); @@ -378,8 +381,8 @@ static int pnv_php_get_power_state(struct hotplug_slot *slot, u8 *state)  	 */  	ret = pnv_pci_get_power_state(php_slot->id, &power_state);  	if (ret) { -		pci_warn(php_slot->pdev, "Error %d getting power status\n", -			 ret); +		SLOT_WARN(php_slot, "Error %d getting power status\n", +			  ret);  	} else {  		*state = power_state;  	} @@ -402,7 +405,7 @@ static int pnv_php_get_adapter_state(struct hotplug_slot *slot, u8 *state)  		*state = presence;  		ret = 0;  	} else { -		pci_warn(php_slot->pdev, "Error %d getting presence\n", ret); +		SLOT_WARN(php_slot, "Error %d getting presence\n", ret);  	}  	return ret; @@ -566,7 +569,13 @@ static int pnv_php_disable_slot(struct hotplug_slot *slot)  	struct pnv_php_slot *php_slot = to_pnv_php_slot(slot);  	int ret; -	if (php_slot->state != PNV_PHP_STATE_POPULATED) +	/* +	 * Allow to disable a slot already in the registered state to +	 * cover cases where the slot couldn't be enabled and never +	 * reached the populated state +	 */ +	if (php_slot->state != PNV_PHP_STATE_POPULATED && +	    php_slot->state != PNV_PHP_STATE_REGISTERED)  		return 0;  	/* Remove all devices behind the slot */ @@ -675,7 +684,7 @@ static int pnv_php_register_slot(struct pnv_php_slot *php_slot)  	ret = pci_hp_register(&php_slot->slot, php_slot->bus,  			      php_slot->slot_no, php_slot->name);  	if (ret) { -		pci_warn(php_slot->pdev, "Error %d registering slot\n", ret); +		SLOT_WARN(php_slot, "Error %d registering slot\n", ret);  		return ret;  	} @@ -728,7 +737,7 @@ static int pnv_php_enable_msix(struct pnv_php_slot *php_slot)  	/* Enable MSIx */  	ret = pci_enable_msix_exact(pdev, &entry, 1);  	if (ret) { -		pci_warn(pdev, "Error %d enabling MSIx\n", ret); +		SLOT_WARN(php_slot, "Error %d enabling MSIx\n", ret);  		return ret;  	} @@ -778,8 +787,9 @@ static irqreturn_t pnv_php_interrupt(int irq, void *data)  		   (sts & PCI_EXP_SLTSTA_PDC)) {  		ret = pnv_pci_get_presence_state(php_slot->id, &presence);  		if (ret) { -			pci_warn(pdev, "PCI slot [%s] error %d getting presence (0x%04x), to retry the operation.\n", -				 php_slot->name, ret, sts); +			SLOT_WARN(php_slot, +				  "PCI slot [%s] error %d getting presence (0x%04x), to retry the operation.\n", +				  php_slot->name, ret, sts);  			return IRQ_HANDLED;  		} @@ -809,8 +819,9 @@ static irqreturn_t pnv_php_interrupt(int irq, void *data)  	 */  	event = kzalloc(sizeof(*event), GFP_ATOMIC);  	if (!event) { -		pci_warn(pdev, "PCI slot [%s] missed hotplug event 0x%04x\n", -			 php_slot->name, sts); +		SLOT_WARN(php_slot, +			  "PCI slot [%s] missed hotplug event 0x%04x\n", +			  php_slot->name, sts);  		return IRQ_HANDLED;  	} @@ -834,7 +845,7 @@ static void pnv_php_init_irq(struct pnv_php_slot *php_slot, int irq)  	/* Allocate workqueue */  	php_slot->wq = alloc_workqueue("pciehp-%s", 0, 0, php_slot->name);  	if (!php_slot->wq) { -		pci_warn(pdev, "Cannot alloc workqueue\n"); +		SLOT_WARN(php_slot, "Cannot alloc workqueue\n");  		pnv_php_disable_irq(php_slot, true);  		return;  	} @@ -858,7 +869,7 @@ static void pnv_php_init_irq(struct pnv_php_slot *php_slot, int irq)  			  php_slot->name, php_slot);  	if (ret) {  		pnv_php_disable_irq(php_slot, true); -		pci_warn(pdev, "Error %d enabling IRQ %d\n", ret, irq); +		SLOT_WARN(php_slot, "Error %d enabling IRQ %d\n", ret, irq);  		return;  	} @@ -894,7 +905,7 @@ static void pnv_php_enable_irq(struct pnv_php_slot *php_slot)  	ret = pci_enable_device(pdev);  	if (ret) { -		pci_warn(pdev, "Error %d enabling device\n", ret); +		SLOT_WARN(php_slot, "Error %d enabling device\n", ret);  		return;  	} @@ -1009,6 +1020,8 @@ static int __init pnv_php_init(void)  	for_each_compatible_node(dn, NULL, "ibm,ioda3-phb")  		pnv_php_register(dn); +	for_each_compatible_node(dn, NULL, "ibm,ioda2-npu2-opencapi-phb") +		pnv_php_register_one(dn); /* slot directly under the PHB */  	return 0;  } @@ -1021,6 +1034,9 @@ static void __exit pnv_php_exit(void)  	for_each_compatible_node(dn, NULL, "ibm,ioda3-phb")  		pnv_php_unregister(dn); + +	for_each_compatible_node(dn, NULL, "ibm,ioda2-npu2-opencapi-phb") +		pnv_php_unregister_one(dn); /* slot directly under the PHB */  }  module_init(pnv_php_init);  |