occ: Make timeout platform dependent

Keep it 0 for open-power platforms where OCC is going to be preloaded,
also avoids a annoying 1mn delay on early openpower and bml when there
is no OCC firmware to wait for.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
PCI: Add pci_device_init()

The patch adds function pci_device_init(), which is called by
phb->ops->device_init() to apply common initialization on the
specified PCI device during bootup or after PE reset.

Currently, we only put the logic of MPS configuration to the
function, but more will be put there.

Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
PCI: Disable completion timeout

For PCIe devices, there are 2 bits used to control completion
timeout as follows:

   PCIe Cap + 0x24, Device Capabilities 2 Register, bit#4
   PCIe Cap + 0x28, Device Control 2 Register, bit#4

The patch adds function pci_disable_completion_timeout(), which
is called during bootup or after PE reset.

It's responsing to bug#114961

Suggested-by:  Michael A. Perez <perezma@us.ibm.com>
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
core: Setup the OPAL DT node before platform probe

The platform probe code might want to add things to it.

While at it, make add_cpu_idle_state_properties() local to slw.c
and call it from slw_init() instead of from add_opal_node().

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
ipmi: Improve RTC support

Create a device-node which will be used by Linux for matching
and use a saner default time if IPMI doesn't work.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
psi: Workaround for "pulse" external interrupt

The FPGA used on some open power machines generates regular pulses instead
of levels. In that case, reading the status might fail since it's not
latched. In that case, also check the latched event bit in the XIVR.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
dpo: Minor code cleanup

This patch cleans up multiple printf statements and also
introduces couple of defines to reflect the byte position
signatures present on the FSP DPO initiation command.

Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
dpo: Fix missing return statement

This patch adds a positive return statement after handling
DPO message from FSP. Currently it was returning a negetive
value for all the possible cases.

Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Acked-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
dpo: Return error status to FSP when OPAL message queueing fails

Right now if the OPAL message queuing fails, the FSP never gets
the ack back for the original DPO initiation message it had sent
previously. With this patch, if the OPAL message queuing fails to
send the DPO message to the host, it still acks the FSP about the
original message but with error flags.

Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Acked-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
dpo: Return OPAL_WRONG_STATE when not in DPO pending state

This patch changes fsp_opal_get_dpo_status function to return
OPAL_WRONG_STATE when not in DPO pending state. This will help
the host to differentiate whether the system is in DPO pending
state or not and then analyse the returned timeout value correctly.

Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
phb3/capi: Initialize capp regs with field values.

FLUSH_SUE_STATE_MAP change fixes a problem with recovery.  We were using an old
lab value that marked PTE entries in a shared state.  After recovery, PTE
entries were getting flushed out to memory with an SUE, resulting in a machine
check.  The new value means PTE entries are dropped on recovery.

For, APC_MASTER_PB_CTRL spec says to use initfile value and bit 3 should be
set.  Initfile missing bit 3 so do a RMW.  Bit 3 enables CAPP combined
response.

CAPP_EPOCH_TIMER_CTRL enables epoch timers and the recovery timer when recovery
is enabled.  Also relax epoch timer period mask due to a bug.

TRANSPORT_CONTROL reg set bit 37 - rfs_benign_ptr_data in addition to spec
value.  Should be set in initifile in future.

Rename APC_MASTER_CONFIG to APC_MASTER_CAPI_CTRL to match workbook name.

Signed-off-by: Ryan Grimm <grimm@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
phb3/capi: Add two new modes to opal_pci_set_phb_capi_mode

For user initiated capp recovery, provide a mode to turn snoops off.  The perst
alone does not turn snoops off and we need to do this as part of the capp
recovery procedure before reinitializing the phb.

A second mode turns snoops back on after recovery.  The driver needs to do this
after it reinitializes the PSL otherwise tlbies could come in before the psl is
initialized.  Also write 0 to capp error status and control as part of the
recovery procedure.

Put modes as flag defines in opal.h so the driver can pick them up.

Add a dt property "ibm,capi-modes" which tells the driver which modes sapphire
supports.  For backwards compatibility with older opals.  Also, the driver can
disable reset in sysfs if not supported.

Move the mode checking into phb3.c so it's all in one place.

Signed-off-by: Ryan Grimm <grimm@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
phb3/capi: Add capp recovery to phb3

Add a flag indicating the CAPP unit is in recovery.  When a capp recoverable
malfunction HMI comes in, the HMI handler will call into
phb3_set_capp_recovery, which will put set the flag and send the event to
Linux.

EEH will call phb3_next_error which will tell it the phb is fenced.

EEH will then call into sapphire to reinitialize the phb which contains steps
3-5 of capp recovery procedure.  The code increases wait time of PERST to 1s to
ensure fpga download is complete before polling linkup.

EEH will then rebind the cxl driver and it will complete recovery once it
initializes and turns snoops on, steps 7-8, completing capp recovery procedure.

Signed-off-by: Ryan Grimm <grimm@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
hmi: Add locking to hmi handler

Take a lock before handle_hmi_event per Ben's suggestion.  So, when we clear
events, only one thread per core will report it.

Signed-off-by: Ryan Grimm <grimm@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
hmi: Handle capp recoverable malfunctions

Based on email from JT Kellington, Dave Larson, and Joe McGill and feedback
from Ben H.

handle_malfunction reads the bits in the malf alert reg, checks for
is_capp_recoverable, and returns 1 if recoverable.  It also calls into phb3 to
put phb3 in capp error recovery state.  Returns 0 if not capp recoverable and
it's a TODO to add the logic to check the other FIRs.

Don't send message when malf alert empty.  Use return code -1 to tell
opal_handle_hmi to swallow the event.  Also, with locking, only one thread per
core will send the message instead of all threads.

Signed-off-by: Ryan Grimm <grimm@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
phb3/capi: Some tweaks to the new CAPI interfaces

Use real functionality based flags instead of a mode list in the DT
and other cleanups & missing bits (this one actually builds !)

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
attn: Make backtrace buffer global

Code cleanup.

Signed-off-by: Aruna Balakrishnaiah <aruna@linux.vnet.ibm.com>
Acked-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
core: make time_wait call pollers if on boot CPU

Instead of running the pollers flat out, instead call them once every
5ms. This helps in situations where pollers are taking locks that are
also taken by tasks completing on other CPUs.

The 5ms time is arbitrary; it was chosen such that most callers of
time_wait will call the pollers at least twice.

Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
core: pace the loop in cpu_wait_job

When waiting for a job to complete, users call cpu_wait_job. This causes
the pollers to run and take locks eg. dummy_console takes con_lock.
These locks may also be contended by the job that is running, and this
contention between the pollers and the job stops the job making forward
progress.

The 10us delay was picked as a reasonable compromise.

With this change Palmetto with DD2 PCI probe time goes from 8e10 to 4e8
ticks.

Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
PCI: Don't check cap indicator for PLX 8724 (rev ba)

As Murali reported, the upstream port of PLX 8724 (rev ba) switch do
have PCI/PCIE capabilities. However, it doesn't have the capability
indicator (bit#4) in PCI_STATUS config register (offset: 0x6). So
the PCIE capability can't probed successfully from the port and we
don't configure the MPS correctly. Eventually, it caused mismatched
MPS on the PHB and run into EEH error.

The patch fixes it by ignoring the capability indicator on PLX 8724
(rev ba) switch upstream port when looking for its PCIE capability
so that its MPS can be configured properly.

Reported-by: Murali N. Iyer <mniyer@us.ibm.com>
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>