Commit 2de36e3f authored by Piotr Piórkowski's avatar Piotr Piórkowski Committed by Michał Winiarski
Browse files

drm/xe/pf: Add FLR_PREPARE state to VF control flow



Our xe-vfio-pci component relies on the confirmation from the PF
that VF FLR processing has finished, but due to the notification
latency on the HW/FW side, PF might be unaware yet of the already
triggered VF FLR.

Update VF state machine with new FLR_PREPARE state that indicate
imminent VF FLR notification and treat that as a begin of the FLR
sequence. Also introduce function that xe-vfio-pci should call to
guarantee correct synchronization.

v2: move PREPARE into WIP, update commit msg (Michal)

Signed-off-by: default avatarPiotr Piórkowski <piotr.piorkowski@intel.com>
Co-developed-by: default avatarMichal Wajdeczko <michal.wajdeczko@intel.com>
Signed-off-by: default avatarMichal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: default avatarMichał Winiarski <michal.winiarski@intel.com>
Link: https://patch.msgid.link/20260309152449.910636-2-piotr.piorkowski@intel.com


Signed-off-by: default avatarMichał Winiarski <michal.winiarski@intel.com>
parent a3156676
Loading
Loading
Loading
Loading
+62 −16
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@ static const char *control_bit_to_string(enum xe_gt_sriov_control_bits bit)
	case XE_GT_SRIOV_STATE_##_X: return #_X
	CASE2STR(WIP);
	CASE2STR(FLR_WIP);
	CASE2STR(FLR_PREPARE);
	CASE2STR(FLR_SEND_START);
	CASE2STR(FLR_WAIT_GUC);
	CASE2STR(FLR_GUC_DONE);
@@ -1486,11 +1487,15 @@ int xe_gt_sriov_pf_control_stop_vf(struct xe_gt *gt, unsigned int vfid)
 * The VF FLR state machine looks like::
 *
 *	 (READY,PAUSED,STOPPED)<------------<--------------o
 *	    |                                               \
 *	   flr                                               \
 *	    |                                                 \
 *	....V..........................FLR_WIP...........      \
 *	:    \                                          :       \
 *	    |             |                                 \
 *	   flr           prepare                             \
 *	    |             |                                   \
 *	....V.............V............FLR_WIP...........      \
 *	:   |             |                             :       \
 *	:   |    FLR_PREPARE                            :        |
 *	:   |    /                                      :        |
 *	:   \   flr                                     :        |
 *	:    \ /                                        :        |
 *	:     \   o----<----busy                        :        |
 *	:      \ /            /                         :        |
 *	:       FLR_SEND_START---failed----->-----------o--->(FLR_FAILED)<---o
@@ -1539,20 +1544,28 @@ static void pf_enter_vf_flr_send_start(struct xe_gt *gt, unsigned int vfid)
	pf_queue_vf(gt, vfid);
}

static void pf_enter_vf_flr_wip(struct xe_gt *gt, unsigned int vfid)
static bool pf_exit_vf_flr_prepare(struct xe_gt *gt, unsigned int vfid)
{
	if (!pf_enter_vf_state(gt, vfid, XE_GT_SRIOV_STATE_FLR_WIP)) {
		xe_gt_sriov_dbg(gt, "VF%u FLR is already in progress\n", vfid);
		return;
	if (!pf_exit_vf_state(gt, vfid, XE_GT_SRIOV_STATE_FLR_PREPARE))
		return false;

	pf_enter_vf_flr_send_start(gt, vfid);
	return true;
}

static bool pf_enter_vf_flr_wip(struct xe_gt *gt, unsigned int vfid)
{
	if (!pf_enter_vf_state(gt, vfid, XE_GT_SRIOV_STATE_FLR_WIP))
		return false;

	pf_enter_vf_wip(gt, vfid);
	pf_enter_vf_flr_send_start(gt, vfid);
	return true;
}

static void pf_exit_vf_flr_wip(struct xe_gt *gt, unsigned int vfid)
{
	if (pf_exit_vf_state(gt, vfid, XE_GT_SRIOV_STATE_FLR_WIP)) {
		pf_escape_vf_state(gt, vfid, XE_GT_SRIOV_STATE_FLR_PREPARE);
		pf_escape_vf_state(gt, vfid, XE_GT_SRIOV_STATE_FLR_SEND_FINISH);
		pf_escape_vf_state(gt, vfid, XE_GT_SRIOV_STATE_FLR_RESET_MMIO);
		pf_escape_vf_state(gt, vfid, XE_GT_SRIOV_STATE_FLR_RESET_DATA);
@@ -1760,21 +1773,54 @@ static void pf_enter_vf_flr_guc_done(struct xe_gt *gt, unsigned int vfid)
}

/**
 * xe_gt_sriov_pf_control_trigger_flr - Start a VF FLR sequence.
 * xe_gt_sriov_pf_control_prepare_flr() - Notify PF that VF FLR request was issued.
 * @gt: the &xe_gt
 * @vfid: the VF identifier
 *
 * This is an optional early notification path used to mark pending FLR before
 * the GuC notifies the PF with a FLR event.
 *
 * This function is for PF only.
 *
 * Return: 0 on success or a negative error code on failure.
 */
int xe_gt_sriov_pf_control_trigger_flr(struct xe_gt *gt, unsigned int vfid)
int xe_gt_sriov_pf_control_prepare_flr(struct xe_gt *gt, unsigned int vfid)
{
	pf_enter_vf_flr_wip(gt, vfid);
	if (!pf_enter_vf_flr_wip(gt, vfid))
		return -EALREADY;

	pf_enter_vf_state(gt, vfid, XE_GT_SRIOV_STATE_FLR_PREPARE);
	return 0;
}

static int pf_begin_vf_flr(struct xe_gt *gt, unsigned int vfid)
{
	if (pf_enter_vf_flr_wip(gt, vfid)) {
		pf_enter_vf_flr_send_start(gt, vfid);
		return 0;
	}

	if (pf_exit_vf_flr_prepare(gt, vfid))
		return 0;

	xe_gt_sriov_dbg(gt, "VF%u FLR is already in progress\n", vfid);
	return -EALREADY;
}

/**
 * xe_gt_sriov_pf_control_trigger_flr - Start a VF FLR sequence.
 * @gt: the &xe_gt
 * @vfid: the VF identifier
 *
 * This function is for PF only.
 *
 * Return: 0 on success or a negative error code on failure.
 */
int xe_gt_sriov_pf_control_trigger_flr(struct xe_gt *gt, unsigned int vfid)
{
	return pf_begin_vf_flr(gt, vfid);
}

/**
 * xe_gt_sriov_pf_control_sync_flr() - Synchronize on the VF FLR checkpoint.
 * @gt: the &xe_gt
@@ -1879,9 +1925,9 @@ static void pf_handle_vf_flr(struct xe_gt *gt, u32 vfid)

	if (needs_dispatch_flr(xe)) {
		for_each_gt(gtit, xe, gtid)
			pf_enter_vf_flr_wip(gtit, vfid);
			pf_begin_vf_flr(gtit, vfid);
	} else {
		pf_enter_vf_flr_wip(gt, vfid);
		pf_begin_vf_flr(gt, vfid);
	}
}

+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ int xe_gt_sriov_pf_control_process_restore_data(struct xe_gt *gt, unsigned int v
int xe_gt_sriov_pf_control_trigger_restore_vf(struct xe_gt *gt, unsigned int vfid);
int xe_gt_sriov_pf_control_finish_restore_vf(struct xe_gt *gt, unsigned int vfid);
int xe_gt_sriov_pf_control_stop_vf(struct xe_gt *gt, unsigned int vfid);
int xe_gt_sriov_pf_control_prepare_flr(struct xe_gt *gt, unsigned int vfid);
int xe_gt_sriov_pf_control_trigger_flr(struct xe_gt *gt, unsigned int vfid);
int xe_gt_sriov_pf_control_sync_flr(struct xe_gt *gt, unsigned int vfid, bool sync);
int xe_gt_sriov_pf_control_wait_flr(struct xe_gt *gt, unsigned int vfid);
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 *
 * @XE_GT_SRIOV_STATE_WIP: indicates that some operations are in progress.
 * @XE_GT_SRIOV_STATE_FLR_WIP: indicates that a VF FLR is in progress.
 * @XE_GT_SRIOV_STATE_FLR_PREPARE: indicates that the PF received early VF FLR prepare notification.
 * @XE_GT_SRIOV_STATE_FLR_SEND_START: indicates that the PF wants to send a FLR START command.
 * @XE_GT_SRIOV_STATE_FLR_WAIT_GUC: indicates that the PF awaits for a response from the GuC.
 * @XE_GT_SRIOV_STATE_FLR_GUC_DONE: indicates that the PF has received a response from the GuC.
@@ -56,6 +57,7 @@ enum xe_gt_sriov_control_bits {
	XE_GT_SRIOV_STATE_WIP = 1,

	XE_GT_SRIOV_STATE_FLR_WIP,
	XE_GT_SRIOV_STATE_FLR_PREPARE,
	XE_GT_SRIOV_STATE_FLR_SEND_START,
	XE_GT_SRIOV_STATE_FLR_WAIT_GUC,
	XE_GT_SRIOV_STATE_FLR_GUC_DONE,
+24 −0
Original line number Diff line number Diff line
@@ -123,6 +123,30 @@ int xe_sriov_pf_control_reset_vf(struct xe_device *xe, unsigned int vfid)
	return result;
}

/**
 * xe_sriov_pf_control_prepare_flr() - Notify PF that VF FLR prepare has started.
 * @xe: the &xe_device
 * @vfid: the VF identifier
 *
 * This function is for PF only.
 *
 * Return: 0 on success or a negative error code on failure.
 */
int xe_sriov_pf_control_prepare_flr(struct xe_device *xe, unsigned int vfid)
{
	struct xe_gt *gt;
	unsigned int id;
	int result = 0;
	int err;

	for_each_gt(gt, xe, id) {
		err = xe_gt_sriov_pf_control_prepare_flr(gt, vfid);
		result = result ? -EUCLEAN : err;
	}

	return result;
}

/**
 * xe_sriov_pf_control_wait_flr() - Wait for a VF reset (FLR) to complete.
 * @xe: the &xe_device
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ int xe_sriov_pf_control_pause_vf(struct xe_device *xe, unsigned int vfid);
int xe_sriov_pf_control_resume_vf(struct xe_device *xe, unsigned int vfid);
int xe_sriov_pf_control_stop_vf(struct xe_device *xe, unsigned int vfid);
int xe_sriov_pf_control_reset_vf(struct xe_device *xe, unsigned int vfid);
int xe_sriov_pf_control_prepare_flr(struct xe_device *xe, unsigned int vfid);
int xe_sriov_pf_control_wait_flr(struct xe_device *xe, unsigned int vfid);
int xe_sriov_pf_control_sync_flr(struct xe_device *xe, unsigned int vfid);
int xe_sriov_pf_control_trigger_save_vf(struct xe_device *xe, unsigned int vfid);
Loading