// SPDX-License-Identifier: GPL-2.0-only /* * IBM Accelerator Family 'GenWQE' * * (C) Copyright IBM Corp. 2013 * * Author: Frank Haverkamp <haver@linux.vnet.ibm.com> * Author: Joerg-Stephan Vogt <jsvogt@de.ibm.com> * Author: Michael Jung <mijung@gmx.net> * Author: Michael Ruettger <michael@ibmra.de>
*/
/* * Module initialization and PCIe setup. Card health monitoring and * recovery functionality. Character device creation and deletion are * controlled from here.
*/
/** * genwqe_dev_alloc() - Create and prepare a new card descriptor * * Return: Pointer to card descriptor, or ERR_PTR(err) on error
*/ staticstruct genwqe_dev *genwqe_dev_alloc(void)
{ unsignedint i = 0, j; struct genwqe_dev *cd;
for (i = 0; i < GENWQE_CARD_NO_MAX; i++) { if (genwqe_devices[i] == NULL) break;
} if (i >= GENWQE_CARD_NO_MAX) return ERR_PTR(-ENODEV);
cd = kzalloc(sizeof(struct genwqe_dev), GFP_KERNEL); if (!cd) return ERR_PTR(-ENOMEM);
staticvoid genwqe_dev_free(struct genwqe_dev *cd)
{ if (!cd) return;
genwqe_devices[cd->card_idx] = NULL;
kfree(cd);
}
/** * genwqe_bus_reset() - Card recovery * @cd: GenWQE device information * * pci_reset_function() will recover the device and ensure that the * registers are accessible again when it completes with success. If * not, the card will stay dead and registers will be unaccessible * still.
*/ staticint genwqe_bus_reset(struct genwqe_dev *cd)
{ int rc = 0; struct pci_dev *pci_dev = cd->pci_dev; void __iomem *mmio;
if (cd->err_inject & GENWQE_INJECT_BUS_RESET_FAILURE) return -EIO;
/* * Firmware/BIOS might change memory mapping during bus reset. * Settings like enable bus-mastering, ... are backuped and * restored by the pci_reset_function().
*/
dev_dbg(&pci_dev->dev, "[%s] pci_reset function ...\n", __func__);
rc = pci_reset_function(pci_dev); if (rc) {
dev_err(&pci_dev->dev, "[%s] err: failed reset func (rc %d)\n", __func__, rc); return rc;
}
dev_dbg(&pci_dev->dev, "[%s] done with rc=%d\n", __func__, rc);
/* * Here is the right spot to clear the register read * failure. pci_bus_reset() does this job in real systems.
*/
cd->err_inject &= ~(GENWQE_INJECT_HARDWARE_FAILURE |
GENWQE_INJECT_GFIR_FATAL |
GENWQE_INJECT_GFIR_INFO);
/* * Hardware circumvention section. Certain bitstreams in our test-lab * had different kinds of problems. Here is where we adjust those * bitstreams to function will with this version of our device driver. * * Thise circumventions are applied to the physical function only. * The magical numbers below are identifying development/manufacturing * versions of the bitstream used on the card. * * Turn off error reporting for old/manufacturing images.
*/
/** * genwqe_recovery_on_fatal_gfir_required() - Version depended actions * @cd: GenWQE device information * * Bitstreams older than 2013-02-17 have a bug where fatal GFIRs must * be ignored. This is e.g. true for the bitstream we gave to the card * manufacturer, but also for some old bitstreams we released to our * test-lab.
*/ int genwqe_recovery_on_fatal_gfir_required(struct genwqe_dev *cd)
{ return (cd->slu_unitcfg & 0xFFFF0ull) >= 0x32170ull;
}
/** * genwqe_T_psec() - Calculate PF/VF timeout register content * @cd: GenWQE device information * * Note: From a design perspective it turned out to be a bad idea to * use codes here to specifiy the frequency/speed values. An old * driver cannot understand new codes and is therefore always a * problem. Better is to measure out the value or put the * speed/frequency directly into a register which is always a valid * value for old as well as for new software.
*/ /* T = 1/f */ staticint genwqe_T_psec(struct genwqe_dev *cd)
{
u16 speed; /* 1/f -> 250, 200, 166, 175 */ staticconstint T[] = { 4000, 5000, 6000, 5714 };
speed = (u16)((cd->slu_unitcfg >> 28) & 0x0full); if (speed >= ARRAY_SIZE(T)) return -1; /* illegal value */
return T[speed];
}
/** * genwqe_setup_pf_jtimer() - Setup PF hardware timeouts for DDCB execution * @cd: GenWQE device information * * Do this _after_ card_reset() is called. Otherwise the values will * vanish. The settings need to be done when the queues are inactive. * * The max. timeout value is 2^(10+x) * T (6ns for 166MHz) * 15/16. * The min. timeout value is 2^(10+x) * T (6ns for 166MHz) * 14/16.
*/ staticbool genwqe_setup_pf_jtimer(struct genwqe_dev *cd)
{
u32 T = genwqe_T_psec(cd);
u64 x;
if (GENWQE_PF_JOBTIMEOUT_MSEC == 0) returnfalse;
/* PF: large value needed, flash update 2sec per block */
x = ilog2(GENWQE_PF_JOBTIMEOUT_MSEC *
16000000000uL/(T * 15)) - 10;
staticint genwqe_ffdc_buffs_alloc(struct genwqe_dev *cd)
{ unsignedint type, e = 0;
for (type = 0; type < GENWQE_DBG_UNITS; type++) { switch (type) { case GENWQE_DBG_UNIT0:
e = genwqe_ffdc_buff_size(cd, 0); break; case GENWQE_DBG_UNIT1:
e = genwqe_ffdc_buff_size(cd, 1); break; case GENWQE_DBG_UNIT2:
e = genwqe_ffdc_buff_size(cd, 2); break; case GENWQE_DBG_REGS:
e = GENWQE_FFDC_REGS; break;
}
/* currently support only the debug units mentioned here */
cd->ffdc[type].entries = e;
cd->ffdc[type].regs =
kmalloc_array(e, sizeof(struct genwqe_reg),
GFP_KERNEL); /* * regs == NULL is ok, the using code treats this as no regs, * Printing warning is ok in this case.
*/
} return 0;
}
/* * Is access to all registers possible? If we are a VF the * answer is obvious. If we run fully virtualized, we need to * check if we can access all registers. If we do not have * full access we will cause an UR and some informational FIRs * in the PF, but that should not harm.
*/ if (pci_dev->is_virtfn)
cd->is_privileged = 0; else
cd->is_privileged = (__genwqe_readq(cd, IO_SLU_BITSTREAM)
!= IO_ILLEGAL_VALUE);
if (cd->card_state == GENWQE_CARD_FATAL_ERROR) {
dev_warn(&pci_dev->dev, "[%s] chip reload/recovery!\n", __func__);
/* * Stealth Mode: Reload chip on either hot * reset or PERST.
*/
cd->softreset = 0x7Cull;
__genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET,
cd->softreset);
err = genwqe_bus_reset(cd); if (err != 0) {
dev_err(&pci_dev->dev, "[%s] err: bus reset failed!\n",
__func__); goto out;
}
/* * Re-read the IDs because * it could happen that the bitstream load * failed!
*/
err = genwqe_read_ids(cd); if (err) goto out;
}
}
err = genwqe_setup_service_layer(cd); /* does a reset to the card */ if (err != 0) {
dev_err(&pci_dev->dev, "[%s] err: could not setup servicelayer!\n", __func__);
err = -ENODEV; goto out;
}
if (genwqe_is_privileged(cd)) { /* code is running _after_ reset */
genwqe_tweak_hardware(cd);
out_release_service_layer:
genwqe_release_service_layer(cd);
out: if (genwqe_is_privileged(cd))
genwqe_ffdc_buffs_free(cd); return -EIO;
}
/** * genwqe_stop() - Stop card operation * @cd: GenWQE device information * * Recovery notes: * As long as genwqe_thread runs we might access registers during * error data capture. Same is with the genwqe_health_thread. * When genwqe_bus_reset() fails this function might called two times: * first by the genwqe_health_thread() and later by genwqe_remove() to * unbind the device. We must be able to survive that. * * This function must be robust enough to be called twice.
*/ staticint genwqe_stop(struct genwqe_dev *cd)
{
genwqe_finish_queue(cd); /* no register access */
genwqe_device_remove(cd); /* device removed, procs killed */
genwqe_release_service_layer(cd); /* here genwqe_thread is stopped */
if (genwqe_is_privileged(cd)) {
pci_disable_sriov(cd->pci_dev); /* access pci config space */
genwqe_ffdc_buffs_free(cd);
}
return 0;
}
/** * genwqe_recover_card() - Try to recover the card if it is possible * @cd: GenWQE device information * @fatal_err: Indicate whether to attempt soft reset * * If fatal_err is set no register access is possible anymore. It is * likely that genwqe_start fails in that situation. Proper error * handling is required in this case. * * genwqe_bus_reset() will cause the pci code to call genwqe_remove() * and later genwqe_probe() for all virtual functions.
*/ staticint genwqe_recover_card(struct genwqe_dev *cd, int fatal_err)
{ int rc; struct pci_dev *pci_dev = cd->pci_dev;
genwqe_stop(cd);
/* * Make sure chip is not reloaded to maintain FFDC. Write SLU * Reset Register, CPLDReset field to 0.
*/ if (!fatal_err) {
cd->softreset = 0x70ull;
__genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET, cd->softreset);
}
/** * genwqe_fir_checking() - Check the fault isolation registers of the card * @cd: GenWQE device information * * If this code works ok, can be tried out with help of the genwqe_poke tool: * sudo ./tools/genwqe_poke 0x8 0xfefefefefef * * Now the relevant FIRs/sFIRs should be printed out and the driver should * invoke recovery (devices are removed and readded).
*/ static u64 genwqe_fir_checking(struct genwqe_dev *cd)
{ int j, iterations = 0;
u64 mask, fir, fec, uid, gfir, gfir_masked, sfir, sfec;
u32 fir_addr, fir_clr_addr, fec_addr, sfir_addr, sfec_addr; struct pci_dev *pci_dev = cd->pci_dev;
healthMonitor:
iterations++; if (iterations > 16) {
dev_err(&pci_dev->dev, "* exit looping after %d times\n",
iterations); goto fatal_error;
}
gfir = __genwqe_readq(cd, IO_SLC_CFGREG_GFIR); if (gfir != 0x0)
dev_err(&pci_dev->dev, "* 0x%08x 0x%016llx\n",
IO_SLC_CFGREG_GFIR, gfir); if (gfir == IO_ILLEGAL_VALUE) goto fatal_error;
/* * Avoid printing when to GFIR bit is on prevents contignous * printout e.g. for the following bug: * FIR set without a 2ndary FIR/FIR cannot be cleared * Comment out the following if to get the prints:
*/ if (gfir == 0) return 0;
for (uid = 0; uid < GENWQE_MAX_UNITS; uid++) { /* 0..2 in zEDC */
/* read the primary FIR (pfir) */
fir_addr = (uid << 24) + 0x08;
fir = __genwqe_readq(cd, fir_addr); if (fir == 0x0) continue; /* no error in this unit */
gfir = __genwqe_readq(cd, IO_SLC_CFGREG_GFIR); if (gfir == IO_ILLEGAL_VALUE) goto fatal_error;
/* gfir turned on during routine! get out and
start over. */ if ((gfir_masked == 0x0) &&
(gfir & GFIR_ERR_TRIGGER)) { goto healthMonitor;
}
/* do not clear if we entered with a fatal gfir */ if (gfir_masked == 0x0) {
/* NEW clear by mask the logged bits */
sfir_addr = (uid << 24) + 0x100 + 0x08 * j;
__genwqe_writeq(cd, sfir_addr, sfir);
dev_dbg(&pci_dev->dev, "[HM] Clearing 2ndary FIR 0x%08x with 0x%016llx\n",
sfir_addr, sfir);
/* * note, these cannot be error-Firs * since gfir_masked is 0 after sfir * was read. Also, it is safe to do * this write if sfir=0. Still need to * clear the primary. This just means * there is no secondary FIR.
*/
/* clear by mask the logged bit. */
fir_clr_addr = (uid << 24) + 0x10;
__genwqe_writeq(cd, fir_clr_addr, mask);
dev_dbg(&pci_dev->dev, "[HM] Clearing primary FIR 0x%08x with 0x%016llx\n",
fir_clr_addr, mask);
}
}
}
gfir = __genwqe_readq(cd, IO_SLC_CFGREG_GFIR); if (gfir == IO_ILLEGAL_VALUE) goto fatal_error;
if ((gfir_masked == 0x0) && (gfir & GFIR_ERR_TRIGGER)) { /* * Check once more that it didn't go on after all the * FIRS were cleared.
*/
dev_dbg(&pci_dev->dev, "ACK! Another FIR! Recursing %d!\n",
iterations); goto healthMonitor;
} return gfir_masked;
fatal_error: return IO_ILLEGAL_VALUE;
}
/** * genwqe_pci_fundamental_reset() - trigger a PCIe fundamental reset on the slot * @pci_dev: PCI device information struct * * Note: pci_set_pcie_reset_state() is not implemented on all archs, so this * reset method will not work in all cases. * * Return: 0 on success or error code from pci_set_pcie_reset_state()
*/ staticint genwqe_pci_fundamental_reset(struct pci_dev *pci_dev)
{ int rc;
/* * lock pci config space access from userspace, * save state and issue PCIe fundamental reset
*/
pci_cfg_access_lock(pci_dev);
pci_save_state(pci_dev);
rc = pci_set_pcie_reset_state(pci_dev, pcie_warm_reset); if (!rc) { /* keep PCIe reset asserted for 250ms */
msleep(250);
pci_set_pcie_reset_state(pci_dev, pcie_deassert_reset); /* Wait for 2s to reload flash and train the link */
msleep(2000);
}
pci_restore_state(pci_dev);
pci_cfg_access_unlock(pci_dev); return rc;
}
/* Try recoverying the card with fundamental reset */
rc = genwqe_pci_fundamental_reset(pci_dev); if (!rc) {
rc = genwqe_start(cd); if (!rc)
dev_info(&pci_dev->dev, "[%s] card recovered\n", __func__); else
dev_err(&pci_dev->dev, "[%s] err: cannot start card services! (err=%d)\n",
__func__, rc);
} else {
dev_err(&pci_dev->dev, "[%s] card reset failed\n", __func__);
}
return rc;
}
/** * genwqe_reload_bistream() - reload card bitstream * @cd: GenWQE device information * * Set the appropriate register and call fundamental reset to reaload the card * bitstream. * * Return: 0 on success, error code otherwise
*/ staticint genwqe_reload_bistream(struct genwqe_dev *cd)
{ struct pci_dev *pci_dev = cd->pci_dev; int rc;
dev_info(&pci_dev->dev, "[%s] resetting card for bitstream reload\n",
__func__);
genwqe_stop(cd);
/* * Cause a CPLD reprogram with the 'next_bitstream' * partition on PCIe hot or fundamental reset
*/
__genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET,
(cd->softreset & 0xcull) | 0x70ull);
rc = genwqe_pci_fundamental_reset(pci_dev); if (rc) { /* * A fundamental reset failure can be caused * by lack of support on the arch, so we just * log the error and try to start the card * again.
*/
dev_err(&pci_dev->dev, "[%s] err: failed to reset card for bitstream reload\n",
__func__);
}
/** * genwqe_health_thread() - Health checking thread * @data: GenWQE device information * * This thread is only started for the PF of the card. * * This thread monitors the health of the card. A critical situation * is when we read registers which contain -1 (IO_ILLEGAL_VALUE). In * this case we need to be recovered from outside. Writing to * registers will very likely not work either. * * This thread must only exit if kthread_should_stop() becomes true. * * Condition for the health-thread to trigger: * a) when a kthread_stop() request comes in or * b) a critical GFIR occured * * Informational GFIRs are checked and potentially printed in * GENWQE_HEALTH_CHECK_INTERVAL seconds.
*/ staticint genwqe_health_thread(void *data)
{ int rc, should_stop = 0; struct genwqe_dev *cd = data; struct pci_dev *pci_dev = cd->pci_dev;
u64 gfir, gfir_masked, slu_unitcfg, app_unitcfg;
gfir_masked = genwqe_fir_checking(cd); if (gfir_masked == IO_ILLEGAL_VALUE) goto fatal_error;
/* * GFIR ErrorTrigger bits set => reset the card! * Never do this for old/manufacturing images!
*/ if ((gfir_masked) && !cd->skip_recovery &&
genwqe_recovery_on_fatal_gfir_required(cd)) {
cd->card_state = GENWQE_CARD_FATAL_ERROR;
rc = genwqe_recover_card(cd, 0); if (rc < 0) { /* FIXME Card is unusable and needs unbind! */ goto fatal_error;
}
}
if (cd->card_state == GENWQE_CARD_RELOAD_BITSTREAM) { /* Userspace requested card bitstream reload */
rc = genwqe_reload_bistream(cd); if (rc) goto fatal_error;
}
cd->last_gfir = gfir;
cond_resched();
}
return 0;
fatal_error: if (cd->use_platform_recovery) { /* * Since we use raw accessors, EEH errors won't be detected * by the platform until we do a non-raw MMIO or config space * read
*/
readq(cd->mmio + IO_SLC_CFGREG_GFIR);
/* We do nothing if the card is going over PCI recovery */ if (pci_channel_offline(pci_dev)) return -EIO;
/* * If it's supported by the platform, we try a fundamental reset * to recover from a fatal error. Otherwise, we continue to wait * for an external recovery procedure to take care of it.
*/
rc = genwqe_platform_recovery(cd); if (!rc) goto health_thread_begin;
}
/** * genwqe_probe() - Device initialization * @pci_dev: PCI device information struct * @id: PCI device ID * * Callable for multiple cards. This function is called on bind. * * Return: 0 if succeeded, < 0 when failed
*/ staticint genwqe_probe(struct pci_dev *pci_dev, conststruct pci_device_id *id)
{ int err; struct genwqe_dev *cd;
genwqe_init_crc32();
cd = genwqe_dev_alloc(); if (IS_ERR(cd)) {
dev_err(&pci_dev->dev, "err: could not alloc mem (err=%d)!\n",
(int)PTR_ERR(cd)); return PTR_ERR(cd);
}
/** * genwqe_remove() - Called when device is removed (hot-plugable) * @pci_dev: PCI device information struct * * Or when driver is unloaded respecitively when unbind is done.
*/ staticvoid genwqe_remove(struct pci_dev *pci_dev)
{ struct genwqe_dev *cd = dev_get_drvdata(&pci_dev->dev);
genwqe_health_check_stop(cd);
/* * genwqe_stop() must survive if it is called twice * sequentially. This happens when the health thread calls it * and fails on genwqe_bus_reset().
*/
genwqe_stop(cd);
genwqe_pci_remove(cd);
genwqe_dev_free(cd);
}
/** * genwqe_err_error_detected() - Error detection callback * @pci_dev: PCI device information struct * @state: PCI channel state * * This callback is called by the PCI subsystem whenever a PCI bus * error is detected.
*/ static pci_ers_result_t genwqe_err_error_detected(struct pci_dev *pci_dev,
pci_channel_state_t state)
{ struct genwqe_dev *cd;
cd = dev_get_drvdata(&pci_dev->dev); if (cd == NULL) return PCI_ERS_RESULT_DISCONNECT;
/* Stop the card */
genwqe_health_check_stop(cd);
genwqe_stop(cd);
/* * On permanent failure, the PCI code will call device remove * after the return of this function. * genwqe_stop() can be called twice.
*/ if (state == pci_channel_io_perm_failure) { return PCI_ERS_RESULT_DISCONNECT;
} else {
genwqe_pci_remove(cd); return PCI_ERS_RESULT_NEED_RESET;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.