Commit c979c70e authored by Gavin Shan's avatar Gavin Shan Committed by Benjamin Herrenschmidt

powerpc/powernv: Split ioda_eeh_get_state()

Function ioda_eeh_get_state() is used to fetch EEH state for PHB
or PE. We're going to support compound PE and the function becomes
more complicated with that. The patch splits the function into two
functions for PHB and PE cases separately to improve readability.
Signed-off-by: default avatarGavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
parent 5ca27efb
...@@ -251,122 +251,119 @@ static void ioda_eeh_phb_diag(struct eeh_pe *pe) ...@@ -251,122 +251,119 @@ static void ioda_eeh_phb_diag(struct eeh_pe *pe)
__func__, pe->phb->global_number, rc); __func__, pe->phb->global_number, rc);
} }
/** static int ioda_eeh_get_phb_state(struct eeh_pe *pe)
* ioda_eeh_get_state - Retrieve the state of PE
* @pe: EEH PE
*
* The PE's state should be retrieved from the PEEV, PEST
* IODA tables. Since the OPAL has exported the function
* to do it, it'd better to use that.
*/
static int ioda_eeh_get_state(struct eeh_pe *pe)
{ {
s64 ret = 0; struct pnv_phb *phb = pe->phb->private_data;
u8 fstate; u8 fstate;
__be16 pcierr; __be16 pcierr;
u32 pe_no; s64 rc;
int result; int result = 0;
struct pci_controller *hose = pe->phb;
struct pnv_phb *phb = hose->private_data; rc = opal_pci_eeh_freeze_status(phb->opal_id,
pe->addr,
&fstate,
&pcierr,
NULL);
if (rc != OPAL_SUCCESS) {
pr_warn("%s: Failure %lld getting PHB#%x state\n",
__func__, rc, phb->hose->global_number);
return EEH_STATE_NOT_SUPPORT;
}
/* /*
* Sanity check on PE address. The PHB PE address should * Check PHB state. If the PHB is frozen for the
* be zero. * first time, to dump the PHB diag-data.
*/ */
if (pe->addr < 0 || pe->addr >= phb->ioda.total_pe) { if (be16_to_cpu(pcierr) != OPAL_EEH_PHB_ERROR) {
pr_err("%s: PE address %x out of range [0, %x] " result = (EEH_STATE_MMIO_ACTIVE |
"on PHB#%x\n", EEH_STATE_DMA_ACTIVE |
__func__, pe->addr, phb->ioda.total_pe, EEH_STATE_MMIO_ENABLED |
hose->global_number); EEH_STATE_DMA_ENABLED);
return EEH_STATE_NOT_SUPPORT; } else if (!(pe->state & EEH_PE_ISOLATED)) {
eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
ioda_eeh_phb_diag(pe);
} }
return result;
}
static int ioda_eeh_get_pe_state(struct eeh_pe *pe)
{
struct pnv_phb *phb = pe->phb->private_data;
u8 fstate;
__be16 pcierr;
s64 rc;
int result;
/* /*
* If we're in middle of PE reset, return normal * We don't clobber hardware frozen state until PE
* state to keep EEH core going. For PHB reset, we * reset is completed. In order to keep EEH core
* still expect to have fenced PHB cleared with * moving forward, we have to return operational
* PHB reset. * state during PE reset.
*/ */
if (!(pe->type & EEH_PE_PHB) && if (pe->state & EEH_PE_RESET) {
(pe->state & EEH_PE_RESET)) { result = (EEH_STATE_MMIO_ACTIVE |
result = (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE |
EEH_STATE_DMA_ACTIVE |
EEH_STATE_MMIO_ENABLED | EEH_STATE_MMIO_ENABLED |
EEH_STATE_DMA_ENABLED); EEH_STATE_DMA_ENABLED);
return result; return result;
} }
/* Retrieve PE status through OPAL */ /* Fetch state from hardware */
pe_no = pe->addr; rc = opal_pci_eeh_freeze_status(phb->opal_id,
ret = opal_pci_eeh_freeze_status(phb->opal_id, pe_no, pe->addr,
&fstate, &pcierr, NULL); &fstate,
if (ret) { &pcierr,
pr_err("%s: Failed to get EEH status on " NULL);
"PHB#%x-PE#%x\n, err=%lld\n", if (rc != OPAL_SUCCESS) {
__func__, hose->global_number, pe_no, ret); pr_warn("%s: Failure %lld getting PHB#%x-PE%x state\n",
__func__, rc, phb->hose->global_number, pe->addr);
return EEH_STATE_NOT_SUPPORT; return EEH_STATE_NOT_SUPPORT;
} }
/* Check PHB status */ /* Figure out state */
if (pe->type & EEH_PE_PHB) {
result = 0;
result &= ~EEH_STATE_RESET_ACTIVE;
if (be16_to_cpu(pcierr) != OPAL_EEH_PHB_ERROR) {
result |= EEH_STATE_MMIO_ACTIVE;
result |= EEH_STATE_DMA_ACTIVE;
result |= EEH_STATE_MMIO_ENABLED;
result |= EEH_STATE_DMA_ENABLED;
} else if (!(pe->state & EEH_PE_ISOLATED)) {
eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
ioda_eeh_phb_diag(pe);
}
return result;
}
/* Parse result out */
result = 0;
switch (fstate) { switch (fstate) {
case OPAL_EEH_STOPPED_NOT_FROZEN: case OPAL_EEH_STOPPED_NOT_FROZEN:
result &= ~EEH_STATE_RESET_ACTIVE; result = (EEH_STATE_MMIO_ACTIVE |
result |= EEH_STATE_MMIO_ACTIVE; EEH_STATE_DMA_ACTIVE |
result |= EEH_STATE_DMA_ACTIVE; EEH_STATE_MMIO_ENABLED |
result |= EEH_STATE_MMIO_ENABLED; EEH_STATE_DMA_ENABLED);
result |= EEH_STATE_DMA_ENABLED;
break; break;
case OPAL_EEH_STOPPED_MMIO_FREEZE: case OPAL_EEH_STOPPED_MMIO_FREEZE:
result &= ~EEH_STATE_RESET_ACTIVE; result = (EEH_STATE_DMA_ACTIVE |
result |= EEH_STATE_DMA_ACTIVE; EEH_STATE_DMA_ENABLED);
result |= EEH_STATE_DMA_ENABLED;
break; break;
case OPAL_EEH_STOPPED_DMA_FREEZE: case OPAL_EEH_STOPPED_DMA_FREEZE:
result &= ~EEH_STATE_RESET_ACTIVE; result = (EEH_STATE_MMIO_ACTIVE |
result |= EEH_STATE_MMIO_ACTIVE; EEH_STATE_MMIO_ENABLED);
result |= EEH_STATE_MMIO_ENABLED;
break; break;
case OPAL_EEH_STOPPED_MMIO_DMA_FREEZE: case OPAL_EEH_STOPPED_MMIO_DMA_FREEZE:
result &= ~EEH_STATE_RESET_ACTIVE; result = 0;
break; break;
case OPAL_EEH_STOPPED_RESET: case OPAL_EEH_STOPPED_RESET:
result |= EEH_STATE_RESET_ACTIVE; result = EEH_STATE_RESET_ACTIVE;
break; break;
case OPAL_EEH_STOPPED_TEMP_UNAVAIL: case OPAL_EEH_STOPPED_TEMP_UNAVAIL:
result |= EEH_STATE_UNAVAILABLE; result = EEH_STATE_UNAVAILABLE;
break; break;
case OPAL_EEH_STOPPED_PERM_UNAVAIL: case OPAL_EEH_STOPPED_PERM_UNAVAIL:
result |= EEH_STATE_NOT_SUPPORT; result = EEH_STATE_NOT_SUPPORT;
break; break;
default: default:
pr_warning("%s: Unexpected EEH status 0x%x " result = EEH_STATE_NOT_SUPPORT;
"on PHB#%x-PE#%x\n", pr_warn("%s: Invalid PHB#%x-PE#%x state %x\n",
__func__, fstate, hose->global_number, pe_no); __func__, phb->hose->global_number,
pe->addr, fstate);
} }
/* Dump PHB diag-data for frozen PE */ /*
if (result != EEH_STATE_NOT_SUPPORT && * If the PE is switching to frozen state for the
(result & (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE)) != * first time, to dump the PHB diag-data.
(EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE) && */
if (!(result & EEH_STATE_NOT_SUPPORT) &&
!(result & EEH_STATE_UNAVAILABLE) &&
!(result & EEH_STATE_MMIO_ACTIVE) &&
!(result & EEH_STATE_DMA_ACTIVE) &&
!(pe->state & EEH_PE_ISOLATED)) { !(pe->state & EEH_PE_ISOLATED)) {
eeh_pe_state_mark(pe, EEH_PE_ISOLATED); eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
ioda_eeh_phb_diag(pe); ioda_eeh_phb_diag(pe);
...@@ -375,6 +372,33 @@ static int ioda_eeh_get_state(struct eeh_pe *pe) ...@@ -375,6 +372,33 @@ static int ioda_eeh_get_state(struct eeh_pe *pe)
return result; return result;
} }
/**
* ioda_eeh_get_state - Retrieve the state of PE
* @pe: EEH PE
*
* The PE's state should be retrieved from the PEEV, PEST
* IODA tables. Since the OPAL has exported the function
* to do it, it'd better to use that.
*/
static int ioda_eeh_get_state(struct eeh_pe *pe)
{
struct pnv_phb *phb = pe->phb->private_data;
/* Sanity check on PE number. PHB PE should have 0 */
if (pe->addr < 0 ||
pe->addr >= phb->ioda.total_pe) {
pr_warn("%s: PHB#%x-PE#%x out of range [0, %x]\n",
__func__, phb->hose->global_number,
pe->addr, phb->ioda.total_pe);
return EEH_STATE_NOT_SUPPORT;
}
if (pe->type & EEH_PE_PHB)
return ioda_eeh_get_phb_state(pe);
return ioda_eeh_get_pe_state(pe);
}
static s64 ioda_eeh_phb_poll(struct pnv_phb *phb) static s64 ioda_eeh_phb_poll(struct pnv_phb *phb)
{ {
s64 rc = OPAL_HARDWARE; s64 rc = OPAL_HARDWARE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment