mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-04-03 12:05:13 +02:00
commit03552d8ac0upstream. The workqueue used for the reset worker is marked as WQ_MEM_RECLAIM, while the GSC one isn't (and can't be as we need to do memory allocations in the gsc worker). Therefore, we can't flush the latter from the former. The reason why we had such a flush was to avoid interrupting either the GSC FW load or in progress GSC proxy operations. GSC proxy operations fall into 2 categories: 1) GSC proxy init: this only happens once immediately after GSC FW load and does not support being interrupted. The only way to recover from an interruption of the proxy init is to do an FLR and re-load the GSC. 2) GSC proxy request: this can happen in response to a request that the driver sends to the GSC. If this is interrupted, the GSC FW will timeout and the driver request will be failed, but overall the GSC will keep working fine. Flushing the work allowed us to avoid interruption in both cases (unless the hang came from the GSC engine itself, in which case we're toast anyway). However, a failure on a proxy request is tolerable if we're in a scenario where we're triggering a GT reset (i.e., something is already gone pretty wrong), so what we really need to avoid is interrupting the init flow, which we can do by polling on the register that reports when the proxy init is complete (as that ensure us that all the load and init operations have been completed). Note that during suspend we still want to do a flush of the worker to make sure it completes any operations involving the HW before the power is cut. v2: fix spelling in commit msg, rename waiter function (Julia) Fixes:dd0e89e5ed("drm/xe/gsc: GSC FW load") Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/4830 Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Cc: John Harrison <John.C.Harrison@Intel.com> Cc: Alan Previn <alan.previn.teres.alexis@intel.com> Cc: <stable@vger.kernel.org> # v6.8+ Reviewed-by: Julia Filipchuk <julia.filipchuk@intel.com> Link: https://lore.kernel.org/r/20250502155104.2201469-1-daniele.ceraolospurio@intel.com (cherry picked from commit12370bfcc4) Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
323 lines
5.8 KiB
C
323 lines
5.8 KiB
C
// SPDX-License-Identifier: MIT
|
|
/*
|
|
* Copyright © 2022 Intel Corporation
|
|
*/
|
|
|
|
#include "xe_uc.h"
|
|
|
|
#include "xe_assert.h"
|
|
#include "xe_device.h"
|
|
#include "xe_gsc.h"
|
|
#include "xe_gsc_proxy.h"
|
|
#include "xe_gt.h"
|
|
#include "xe_gt_printk.h"
|
|
#include "xe_gt_sriov_vf.h"
|
|
#include "xe_guc.h"
|
|
#include "xe_guc_pc.h"
|
|
#include "xe_huc.h"
|
|
#include "xe_sriov.h"
|
|
#include "xe_uc_fw.h"
|
|
#include "xe_wopcm.h"
|
|
|
|
static struct xe_gt *
|
|
uc_to_gt(struct xe_uc *uc)
|
|
{
|
|
return container_of(uc, struct xe_gt, uc);
|
|
}
|
|
|
|
static struct xe_device *
|
|
uc_to_xe(struct xe_uc *uc)
|
|
{
|
|
return gt_to_xe(uc_to_gt(uc));
|
|
}
|
|
|
|
/* Should be called once at driver load only */
|
|
int xe_uc_init(struct xe_uc *uc)
|
|
{
|
|
int ret;
|
|
|
|
/*
|
|
* We call the GuC/HuC/GSC init functions even if GuC submission is off
|
|
* to correctly move our tracking of the FW state to "disabled".
|
|
*/
|
|
ret = xe_guc_init(&uc->guc);
|
|
if (ret)
|
|
goto err;
|
|
|
|
ret = xe_huc_init(&uc->huc);
|
|
if (ret)
|
|
goto err;
|
|
|
|
ret = xe_gsc_init(&uc->gsc);
|
|
if (ret)
|
|
goto err;
|
|
|
|
if (!xe_device_uc_enabled(uc_to_xe(uc)))
|
|
return 0;
|
|
|
|
if (IS_SRIOV_VF(uc_to_xe(uc)))
|
|
return 0;
|
|
|
|
ret = xe_wopcm_init(&uc->wopcm);
|
|
if (ret)
|
|
goto err;
|
|
|
|
return 0;
|
|
|
|
err:
|
|
xe_gt_err(uc_to_gt(uc), "Failed to initialize uC (%pe)\n", ERR_PTR(ret));
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* xe_uc_init_post_hwconfig - init Uc post hwconfig load
|
|
* @uc: The UC object
|
|
*
|
|
* Return: 0 on success, negative error code on error.
|
|
*/
|
|
int xe_uc_init_post_hwconfig(struct xe_uc *uc)
|
|
{
|
|
int err;
|
|
|
|
/* GuC submission not enabled, nothing to do */
|
|
if (!xe_device_uc_enabled(uc_to_xe(uc)))
|
|
return 0;
|
|
|
|
err = xe_uc_sanitize_reset(uc);
|
|
if (err)
|
|
return err;
|
|
|
|
err = xe_guc_init_post_hwconfig(&uc->guc);
|
|
if (err)
|
|
return err;
|
|
|
|
err = xe_huc_init_post_hwconfig(&uc->huc);
|
|
if (err)
|
|
return err;
|
|
|
|
return xe_gsc_init_post_hwconfig(&uc->gsc);
|
|
}
|
|
|
|
static int uc_reset(struct xe_uc *uc)
|
|
{
|
|
struct xe_device *xe = uc_to_xe(uc);
|
|
int ret;
|
|
|
|
ret = xe_guc_reset(&uc->guc);
|
|
if (ret) {
|
|
drm_err(&xe->drm, "Failed to reset GuC, ret = %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void xe_uc_sanitize(struct xe_uc *uc)
|
|
{
|
|
xe_huc_sanitize(&uc->huc);
|
|
xe_guc_sanitize(&uc->guc);
|
|
}
|
|
|
|
int xe_uc_sanitize_reset(struct xe_uc *uc)
|
|
{
|
|
xe_uc_sanitize(uc);
|
|
|
|
return uc_reset(uc);
|
|
}
|
|
|
|
/**
|
|
* xe_uc_init_hwconfig - minimally init Uc, read and parse hwconfig
|
|
* @uc: The UC object
|
|
*
|
|
* Return: 0 on success, negative error code on error.
|
|
*/
|
|
int xe_uc_init_hwconfig(struct xe_uc *uc)
|
|
{
|
|
int ret;
|
|
|
|
/* GuC submission not enabled, nothing to do */
|
|
if (!xe_device_uc_enabled(uc_to_xe(uc)))
|
|
return 0;
|
|
|
|
ret = xe_guc_min_load_for_hwconfig(&uc->guc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int vf_uc_init_hw(struct xe_uc *uc)
|
|
{
|
|
int err;
|
|
|
|
err = xe_uc_sanitize_reset(uc);
|
|
if (err)
|
|
return err;
|
|
|
|
err = xe_guc_enable_communication(&uc->guc);
|
|
if (err)
|
|
return err;
|
|
|
|
err = xe_gt_sriov_vf_connect(uc_to_gt(uc));
|
|
if (err)
|
|
return err;
|
|
|
|
uc->guc.submission_state.enabled = true;
|
|
|
|
err = xe_gt_record_default_lrcs(uc_to_gt(uc));
|
|
if (err)
|
|
return err;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Should be called during driver load, after every GT reset, and after every
|
|
* suspend to reload / auth the firmwares.
|
|
*/
|
|
int xe_uc_init_hw(struct xe_uc *uc)
|
|
{
|
|
int ret;
|
|
|
|
/* GuC submission not enabled, nothing to do */
|
|
if (!xe_device_uc_enabled(uc_to_xe(uc)))
|
|
return 0;
|
|
|
|
if (IS_SRIOV_VF(uc_to_xe(uc)))
|
|
return vf_uc_init_hw(uc);
|
|
|
|
ret = xe_huc_upload(&uc->huc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = xe_guc_upload(&uc->guc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = xe_guc_enable_communication(&uc->guc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = xe_gt_record_default_lrcs(uc_to_gt(uc));
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = xe_guc_post_load_init(&uc->guc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = xe_guc_pc_start(&uc->guc.pc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
/* We don't fail the driver load if HuC fails to auth, but let's warn */
|
|
ret = xe_huc_auth(&uc->huc, XE_HUC_AUTH_VIA_GUC);
|
|
xe_gt_assert(uc_to_gt(uc), !ret);
|
|
|
|
/* GSC load is async */
|
|
xe_gsc_load_start(&uc->gsc);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int xe_uc_fini_hw(struct xe_uc *uc)
|
|
{
|
|
return xe_uc_sanitize_reset(uc);
|
|
}
|
|
|
|
int xe_uc_reset_prepare(struct xe_uc *uc)
|
|
{
|
|
/* GuC submission not enabled, nothing to do */
|
|
if (!xe_device_uc_enabled(uc_to_xe(uc)))
|
|
return 0;
|
|
|
|
return xe_guc_reset_prepare(&uc->guc);
|
|
}
|
|
|
|
void xe_uc_gucrc_disable(struct xe_uc *uc)
|
|
{
|
|
XE_WARN_ON(xe_guc_pc_gucrc_disable(&uc->guc.pc));
|
|
}
|
|
|
|
void xe_uc_stop_prepare(struct xe_uc *uc)
|
|
{
|
|
xe_gsc_stop_prepare(&uc->gsc);
|
|
xe_guc_stop_prepare(&uc->guc);
|
|
}
|
|
|
|
void xe_uc_stop(struct xe_uc *uc)
|
|
{
|
|
/* GuC submission not enabled, nothing to do */
|
|
if (!xe_device_uc_enabled(uc_to_xe(uc)))
|
|
return;
|
|
|
|
xe_guc_stop(&uc->guc);
|
|
}
|
|
|
|
int xe_uc_start(struct xe_uc *uc)
|
|
{
|
|
/* GuC submission not enabled, nothing to do */
|
|
if (!xe_device_uc_enabled(uc_to_xe(uc)))
|
|
return 0;
|
|
|
|
return xe_guc_start(&uc->guc);
|
|
}
|
|
|
|
static void uc_reset_wait(struct xe_uc *uc)
|
|
{
|
|
int ret;
|
|
|
|
again:
|
|
xe_guc_reset_wait(&uc->guc);
|
|
|
|
ret = xe_uc_reset_prepare(uc);
|
|
if (ret)
|
|
goto again;
|
|
}
|
|
|
|
void xe_uc_suspend_prepare(struct xe_uc *uc)
|
|
{
|
|
xe_gsc_wait_for_worker_completion(&uc->gsc);
|
|
xe_guc_stop_prepare(&uc->guc);
|
|
}
|
|
|
|
int xe_uc_suspend(struct xe_uc *uc)
|
|
{
|
|
/* GuC submission not enabled, nothing to do */
|
|
if (!xe_device_uc_enabled(uc_to_xe(uc)))
|
|
return 0;
|
|
|
|
uc_reset_wait(uc);
|
|
|
|
xe_uc_stop(uc);
|
|
|
|
return xe_guc_suspend(&uc->guc);
|
|
}
|
|
|
|
/**
|
|
* xe_uc_remove() - Clean up the UC structures before driver removal
|
|
* @uc: the UC object
|
|
*
|
|
* This function should only act on objects/structures that must be cleaned
|
|
* before the driver removal callback is complete and therefore can't be
|
|
* deferred to a drmm action.
|
|
*/
|
|
void xe_uc_remove(struct xe_uc *uc)
|
|
{
|
|
xe_gsc_remove(&uc->gsc);
|
|
}
|
|
|
|
/**
|
|
* xe_uc_declare_wedged() - Declare UC wedged
|
|
* @uc: the UC object
|
|
*
|
|
* Wedge the UC which stops all submission, saves desired debug state, and
|
|
* cleans up anything which could timeout.
|
|
*/
|
|
void xe_uc_declare_wedged(struct xe_uc *uc)
|
|
{
|
|
xe_gt_assert(uc_to_gt(uc), uc_to_xe(uc)->wedged.mode);
|
|
|
|
xe_guc_declare_wedged(&uc->guc);
|
|
}
|