Skip to content

Commit

Permalink
hw/phb4: Rework phb4_get_presence_state()
Browse files Browse the repository at this point in the history
There are two issues in current implementation: It should return errcode
visibile to Linux, which has prefix OPAL_*. The code isn't very obvious.

This returns OPAL_HARDWARE when the PHB is broken. Otherwise, OPAL_SUCCESS
is always returned. In the mean while, It refactors the code to make it
obvious: OPAL_PCI_SLOT_PRESENT is returned when the presence signal (low active)
or PCIe link is active. Otherwise, OPAL_PCI_SLOT_EMPTY is returned.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
Gavin Shan authored and stewartsmith committed Jun 19, 2017
1 parent 92d7ccf commit d065caf
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions hw/phb4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1845,36 +1845,26 @@ static int64_t phb4_get_presence_state(struct pci_slot *slot, uint8_t *val)
if (p->state == PHB4_STATE_BROKEN)
return OPAL_HARDWARE;

/* Read hotplug status */
/* Check hotplug status */
hps = in_be64(p->regs + PHB_PCIE_HOTPLUG_STATUS);

/* Read link status */
dtctl = in_be64(p->regs + PHB_PCIE_DLP_TRAIN_CTL);

PHBDBG(p, "hp_status=0x%016llx, dlp_train_ctl=0x%016llx\n",
hps, dtctl);

*val = OPAL_PCI_SLOT_PRESENT;
/* Check presence detect */
if (hps & PHB_PCIE_HPSTAT_PRESENCE) {
/* If it says not present but link is up, then we assume
if (!(hps & PHB_PCIE_HPSTAT_PRESENCE)) {
*val = OPAL_PCI_SLOT_PRESENT;
} else {
/*
* If it says not present but link is up, then we assume
* we are on a broken simulation environment and still
* return a valid presence. Otherwise, not present.
*/
dtctl = in_be64(p->regs + PHB_PCIE_DLP_TRAIN_CTL);
if (dtctl & PHB_PCIE_DLP_TL_LINKACT) {
PHBERR(p, "Presence detect 0 but link set !\n");
return OPAL_SHPC_DEV_PRESENT;
*val = OPAL_PCI_SLOT_PRESENT;
} else {
*val = OPAL_PCI_SLOT_EMPTY;
}
*val = OPAL_PCI_SLOT_EMPTY;
return OPAL_SHPC_DEV_NOT_PRESENT;
}

/*
* Anything else, we assume device present, the link state
* machine will perform an early bail out if no electrical
* signaling is established after a second.
*/
return OPAL_SHPC_DEV_PRESENT;
return OPAL_SUCCESS;
}

static int64_t phb4_get_link_state(struct pci_slot *slot, uint8_t *val)
Expand Down

0 comments on commit d065caf

Please sign in to comment.