aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Barrat <fbarrat@linux.ibm.com>2019-10-09 21:38:09 +0200
committerVasant Hegde <hegdevasant@linux.vnet.ibm.com>2020-03-11 11:00:34 +0530
commit651a16973cd2da178f909a255a2f6450c792bd40 (patch)
treef47ea9ac8fd0f6fb727af34d179f6eeb99498af2
parente2b6f8d243e9e3b54170257fbcd973b470c6f676 (diff)
downloadskiboot-651a16973cd2da178f909a255a2f6450c792bd40.zip
skiboot-651a16973cd2da178f909a255a2f6450c792bd40.tar.gz
skiboot-651a16973cd2da178f909a255a2f6450c792bd40.tar.bz2
npu2-opencapi: Activate PCI hotplug on opencapi slot
[ Upstream commit 6299d3e51b16b47a00685da70688df634dedc7df ] Implement the get_power_state() and set_power_state() callbacks for the opencapi slot and add properties in the device tree to mark the opencapi slot as hot-pluggable. We don't really power off/on the opencapi adapter. The slot at play here is the virtual slot associated to the virtual opencapi PHB. The real PCIe slot where the card is drawing its power from is untouched (skiboot is not even aware which PCIe slot the card is seated on). So the 'fake' power off is fencing the card and set it in reset so that the FPGA image can be updated. The 'fake' power on is not doing much, as the unfencing happens on the subsequent link training. Opencapi slots are named 'OPENCAPI-xxxx' where xxxx is the opal ID of the PHB/slot. This is meant to easily identify the slot used by an AFU device, as the AFU device names are also built around that ID. For example, the device /dev/ocxl/AFP3.0006:00:00.1.0 uses the slot OPENCAPI-0006. Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com> Reviewed-by: Christophe Lombard <clombard@linux.vnet.ibm.com> Signed-off-by: Oliver O'Halloran <oohall@gmail.com> Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
-rw-r--r--hw/npu2-opencapi.c69
1 files changed, 65 insertions, 4 deletions
diff --git a/hw/npu2-opencapi.c b/hw/npu2-opencapi.c
index a299b10..6d36c5b 100644
--- a/hw/npu2-opencapi.c
+++ b/hw/npu2-opencapi.c
@@ -1066,9 +1066,10 @@ static int64_t npu2_opencapi_get_presence_state(struct pci_slot __unused *slot,
* As such we will never be asked to get the presence of a slot that's
* empty.
*
- * This may change if we ever support hotplug down the track.
+ * This may change if we ever support surprise hotplug down
+ * the track.
*/
- *val = true;
+ *val = OPAL_PCI_SLOT_PRESENT;
return OPAL_SUCCESS;
}
@@ -1126,6 +1127,38 @@ static int64_t npu2_opencapi_get_link_state(struct pci_slot *slot, uint8_t *val)
return OPAL_SUCCESS;
}
+static int64_t npu2_opencapi_get_power_state(struct pci_slot *slot,
+ uint8_t *val)
+{
+ *val = slot->power_state;
+ return OPAL_SUCCESS;
+}
+
+static int64_t npu2_opencapi_set_power_state(struct pci_slot *slot, uint8_t val)
+{
+ struct npu2_dev *dev = phb_to_npu2_dev_ocapi(slot->phb);
+
+ switch (val) {
+ case PCI_SLOT_POWER_OFF:
+ OCAPIDBG(dev, "Fake power off\n");
+ fence_brick(dev);
+ assert_adapter_reset(dev);
+ slot->power_state = PCI_SLOT_POWER_OFF;
+ return OPAL_SUCCESS;
+
+ case PCI_SLOT_POWER_ON:
+ if (slot->power_state != PCI_SLOT_POWER_OFF)
+ return OPAL_SUCCESS;
+ OCAPIDBG(dev, "Fake power on\n");
+ slot->power_state = PCI_SLOT_POWER_ON;
+ slot->state = OCAPI_SLOT_NORMAL;
+ return OPAL_SUCCESS;
+
+ default:
+ return OPAL_UNSUPPORTED;
+ }
+}
+
static void check_trained_link(struct npu2_dev *dev, uint64_t odl_status)
{
if (get_link_width(odl_status) != OPAL_SHPC_LINK_UP_x8) {
@@ -1166,6 +1199,14 @@ static int64_t npu2_opencapi_retry_state(struct pci_slot *slot,
return pci_slot_set_sm_timeout(slot, msecs_to_tb(1));
}
+static void npu2_opencapi_prepare_link_change(struct pci_slot *slot __unused,
+ bool up __unused)
+{
+ /*
+ * PCI hotplug wants it defined, but we don't need to do anything
+ */
+}
+
static int64_t npu2_opencapi_poll_link(struct pci_slot *slot)
{
struct npu2_dev *dev = phb_to_npu2_dev_ocapi(slot->phb);
@@ -1295,6 +1336,24 @@ static int64_t npu2_opencapi_hreset(struct pci_slot *slot __unused)
return OPAL_UNSUPPORTED;
}
+static void make_slot_hotpluggable(struct pci_slot *slot, struct phb *phb)
+{
+ char label[40];
+
+ /*
+ * Add a few definitions to the DT so that the linux PCI
+ * hotplug framework can find the slot and identify it as
+ * hot-pluggable.
+ *
+ * The "ibm,slot-label" property is used by linux as the slot name
+ */
+ slot->pluggable = 1;
+ pci_slot_add_dt_properties(slot, phb->dt_node);
+ snprintf(label, sizeof(label), "OPENCAPI-%04x",
+ (int)PCI_SLOT_PHB_INDEX(slot->id));
+ dt_add_property_string(phb->dt_node, "ibm,slot-label", label);
+}
+
static struct pci_slot *npu2_opencapi_slot_create(struct phb *phb)
{
struct pci_slot *slot;
@@ -1306,12 +1365,13 @@ static struct pci_slot *npu2_opencapi_slot_create(struct phb *phb)
/* TODO: Figure out other slot functions */
slot->ops.get_presence_state = npu2_opencapi_get_presence_state;
slot->ops.get_link_state = npu2_opencapi_get_link_state;
- slot->ops.get_power_state = NULL;
+ slot->ops.get_power_state = npu2_opencapi_get_power_state;
slot->ops.get_attention_state = NULL;
slot->ops.get_latch_state = NULL;
- slot->ops.set_power_state = NULL;
+ slot->ops.set_power_state = npu2_opencapi_set_power_state;
slot->ops.set_attention_state = NULL;
+ slot->ops.prepare_link_change = npu2_opencapi_prepare_link_change;
slot->ops.poll_link = npu2_opencapi_poll_link;
slot->ops.creset = npu2_opencapi_creset;
slot->ops.freset = npu2_opencapi_freset;
@@ -1750,6 +1810,7 @@ static void setup_device(struct npu2_dev *dev)
*/
prlog(PR_ERR, "OCAPI: Cannot create PHB slot\n");
}
+ make_slot_hotpluggable(slot, &dev->phb_ocapi);
}
return;
}