[01/16] core/pci: Refactor common paths on slot hotplug
diff mbox series

Message ID 20190909123151.21944-2-fbarrat@linux.ibm.com
State New
Headers show
Series
  • opencapi: enable card reset and link retraining
Related show

Checks

Context Check Description
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (470ffb5f29d741c3bed600f7bb7bf0cbb270e05a)

Commit Message

Frederic Barrat Sept. 9, 2019, 12:31 p.m. UTC
Refactor code executed to remove or rescan devices when a slot power
state changes, synchronously or asynchronously through a timer
callback. It will be more useful in a future patch.

No functional changes.

Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
---
 core/pci-opal.c | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)

Comments

christophe lombard Sept. 12, 2019, 7:56 a.m. UTC | #1
On 09/09/2019 14:31, Frederic Barrat wrote:
> Refactor code executed to remove or rescan devices when a slot power
> state changes, synchronously or asynchronously through a timer
> callback. It will be more useful in a future patch.
> 
> No functional changes.
> 
> Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
> ---


Reviewed-by: Christophe Lombard <clombard@linux.vnet.ibm.com>

Patch
diff mbox series

diff --git a/core/pci-opal.c b/core/pci-opal.c
index 213a7256..d5209600 100644
--- a/core/pci-opal.c
+++ b/core/pci-opal.c
@@ -647,11 +647,30 @@  static int64_t opal_pci_get_power_state(uint64_t id, uint64_t data)
 }
 opal_call(OPAL_PCI_GET_POWER_STATE, opal_pci_get_power_state, 2);
 
+static void rescan_slot_devices(struct pci_slot *slot)
+{
+	struct phb *phb = slot->phb;
+	struct pci_device *pd = slot->pd;
+
+	slot->ops.prepare_link_change(slot, true);
+	pci_scan_bus(phb, pd->secondary_bus,
+		     pd->subordinate_bus, &pd->children, pd, true);
+	pci_add_device_nodes(phb, &pd->children, pd->dn,
+			     &phb->lstate, 0);
+}
+
+static void remove_slot_devices(struct pci_slot *slot)
+{
+	struct phb *phb = slot->phb;
+	struct pci_device *pd = slot->pd;
+
+	pci_remove_bus(phb, &pd->children);
+}
+
 static void set_power_timer(struct timer *t __unused, void *data,
 			    uint64_t now __unused)
 {
 	struct pci_slot *slot = data;
-	struct phb *phb = slot->phb;
 	struct pci_device *pd = slot->pd;
 	struct dt_node *dn = pd->dn;
 	uint8_t link;
@@ -670,7 +689,7 @@  static void set_power_timer(struct timer *t __unused, void *data,
 		break;
 	case PCI_SLOT_STATE_SPOWER_DONE:
 		if (slot->power_state == OPAL_PCI_SLOT_POWER_OFF) {
-			pci_remove_bus(phb, &pd->children);
+			remove_slot_devices(slot);
 			pci_slot_set_state(slot, PCI_SLOT_STATE_NORMAL);
 			opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
 				       slot->async_token, dn->phandle,
@@ -682,12 +701,7 @@  static void set_power_timer(struct timer *t __unused, void *data,
 		if (slot->ops.get_link_state(slot, &link) != OPAL_SUCCESS)
 			link = 0;
 		if (link) {
-			slot->ops.prepare_link_change(slot, true);
-			pci_scan_bus(phb, pd->secondary_bus,
-				     pd->subordinate_bus,
-				     &pd->children, pd, true);
-			pci_add_device_nodes(phb, &pd->children, dn,
-					     &phb->lstate, 0);
+			rescan_slot_devices(slot);
 			pci_slot_set_state(slot, PCI_SLOT_STATE_NORMAL);
 			opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
 				       slot->async_token, dn->phandle,
@@ -782,15 +796,10 @@  static int64_t opal_pci_set_power_state(uint64_t async_token,
 		init_timer(&slot->timer, set_power_timer, slot);
 		schedule_timer(&slot->timer, msecs_to_tb(10));
 	} else if (rc == OPAL_SUCCESS) {
-		if (*state == OPAL_PCI_SLOT_POWER_OFF) {
-			pci_remove_bus(phb, &pd->children);
-		} else {
-			slot->ops.prepare_link_change(slot, true);
-			pci_scan_bus(phb, pd->secondary_bus,
-				pd->subordinate_bus, &pd->children, pd, true);
-			pci_add_device_nodes(phb, &pd->children, pd->dn,
-				&phb->lstate, 0);
-		}
+		if (*state == OPAL_PCI_SLOT_POWER_OFF)
+			remove_slot_devices(slot);
+		else
+			rescan_slot_devices(slot);
 	}
 
 	phb_unlock(phb);