[Skiboot] [RFC PATCH 04/23] core/pci: Convert set_power_state

Oliver O'Halloran oohall at gmail.com
Wed Apr 3 20:09:01 AEDT 2019


Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 core/pci.c | 55 ++++++++++++++++--------------------------------------
 1 file changed, 16 insertions(+), 39 deletions(-)

diff --git a/core/pci.c b/core/pci.c
index a20268b18e1e..c1959197d06d 100644
--- a/core/pci.c
+++ b/core/pci.c
@@ -365,7 +365,6 @@ static void pci_slot_set_power_state(struct phb *phb,
 				     uint8_t state)
 {
 	struct pci_slot *slot;
-	uint8_t cur_state;
 	int32_t wait = 100;
 	int64_t rc;
 
@@ -378,58 +377,36 @@ static void pci_slot_set_power_state(struct phb *phb,
 	    !slot->ops.set_power_state)
 		return;
 
-	if (state == PCI_SLOT_POWER_OFF) {
-		/* Bail if there're something connected */
-		if (!list_empty(&pd->children)) {
-			PCIERR(phb, pd->bdfn, "Attempted to power off slot with attached devices!\n");
-			return;
-		}
-
-		pci_slot_add_flags(slot, PCI_SLOT_FLAG_BOOTUP);
-		rc = slot->ops.get_power_state(slot, &cur_state);
-		if (rc != OPAL_SUCCESS) {
-			PCINOTICE(phb, pd->bdfn, "Error %lld getting slot power state\n", rc);
-			cur_state = PCI_SLOT_POWER_OFF;
-		}
-
-		pci_slot_remove_flags(slot, PCI_SLOT_FLAG_BOOTUP);
-		if (cur_state == PCI_SLOT_POWER_OFF)
-			return;
+	if (state == PCI_SLOT_POWER_OFF && !list_empty(&pd->children)) {
+		PCIERR(phb, pd->bdfn, "Attempted to power off slot with attached devices!\n");
+		return;
 	}
 
 	pci_slot_add_flags(slot,
 		(PCI_SLOT_FLAG_BOOTUP | PCI_SLOT_FLAG_ENFORCE));
-	rc = slot->ops.set_power_state(slot, state);
-	if (rc == OPAL_SUCCESS)
-		goto success;
-	if (rc != OPAL_ASYNC_COMPLETION) {
-		PCINOTICE(phb, pd->bdfn, "Error %lld powering %s slot\n",
-			  rc, state == PCI_SLOT_POWER_ON ? "on" : "off");
-		goto error;
-	}
 
 	/* Wait until the operation is completed */
 	do {
-		if (slot->state == PCI_SLOT_STATE_SPOWER_DONE)
+		rc = slot->ops.set_power_state(slot, state);
+		if (rc <= 0)
 			break;
-
+		time_wait(rc > 10 ? 10 : rc);
 		check_timers(false);
-		time_wait_ms(10);
-	} while (--wait >= 0);
+	} while (--wait);
 
-	if (wait < 0) {
-		PCINOTICE(phb, pd->bdfn, "Timeout powering %s slot\n",
-			  state == PCI_SLOT_POWER_ON ? "on" : "off");
-		goto error;
+	if (!wait && rc >= 0)
+		rc = OPAL_TIMEOUT;
+
+	if (rc < 0) {
+		PCIERR(phb, pd->bdfn, "Error %lld powering %s slot\n",
+		       rc, state == PCI_SLOT_POWER_ON ? "on" : "off");
+	} else {
+		PCIDBG(phb, pd->bdfn, "Powered %s hotpluggable slot\n",
+		       state == PCI_SLOT_POWER_ON ? "on" : "off");
 	}
 
-success:
-	PCIDBG(phb, pd->bdfn, "Powering %s hotpluggable slot\n",
-	       state == PCI_SLOT_POWER_ON ? "on" : "off");
-error:
 	pci_slot_remove_flags(slot,
 		(PCI_SLOT_FLAG_BOOTUP | PCI_SLOT_FLAG_ENFORCE));
-	pci_slot_set_state(slot, PCI_SLOT_STATE_NORMAL);
 }
 
 static int64_t pci_slot_get_link_width(struct pci_slot *slot)
-- 
2.20.1



More information about the Skiboot mailing list