1616#include "xe_gt_sriov_pf_migration.h"
1717#include "xe_gt_sriov_pf_service.h"
1818#include "xe_gt_sriov_printk.h"
19+ #include "xe_guc_submit.h"
1920#include "xe_mmio.h"
2021#include "xe_pm.h"
2122
@@ -47,9 +48,16 @@ static int pf_alloc_metadata(struct xe_gt *gt)
4748
4849static void pf_init_workers (struct xe_gt * gt )
4950{
51+ xe_gt_assert (gt , IS_SRIOV_PF (gt_to_xe (gt )));
5052 INIT_WORK (& gt -> sriov .pf .workers .restart , pf_worker_restart_func );
5153}
5254
55+ static void pf_fini_workers (struct xe_gt * gt )
56+ {
57+ xe_gt_assert (gt , IS_SRIOV_PF (gt_to_xe (gt )));
58+ disable_work_sync (& gt -> sriov .pf .workers .restart );
59+ }
60+
5361/**
5462 * xe_gt_sriov_pf_init_early - Prepare SR-IOV PF data structures on PF.
5563 * @gt: the &xe_gt to initialize
@@ -79,6 +87,21 @@ int xe_gt_sriov_pf_init_early(struct xe_gt *gt)
7987 return 0 ;
8088}
8189
90+ static void pf_fini_action (void * arg )
91+ {
92+ struct xe_gt * gt = arg ;
93+
94+ pf_fini_workers (gt );
95+ }
96+
97+ static int pf_init_late (struct xe_gt * gt )
98+ {
99+ struct xe_device * xe = gt_to_xe (gt );
100+
101+ xe_gt_assert (gt , IS_SRIOV_PF (xe ));
102+ return devm_add_action_or_reset (xe -> drm .dev , pf_fini_action , gt );
103+ }
104+
82105/**
83106 * xe_gt_sriov_pf_init - Prepare SR-IOV PF data structures on PF.
84107 * @gt: the &xe_gt to initialize
@@ -95,7 +118,15 @@ int xe_gt_sriov_pf_init(struct xe_gt *gt)
95118 if (err )
96119 return err ;
97120
98- return xe_gt_sriov_pf_migration_init (gt );
121+ err = xe_gt_sriov_pf_migration_init (gt );
122+ if (err )
123+ return err ;
124+
125+ err = pf_init_late (gt );
126+ if (err )
127+ return err ;
128+
129+ return 0 ;
99130}
100131
101132static bool pf_needs_enable_ggtt_guest_update (struct xe_device * xe )
@@ -230,3 +261,27 @@ void xe_gt_sriov_pf_restart(struct xe_gt *gt)
230261{
231262 pf_queue_restart (gt );
232263}
264+
265+ static void pf_flush_restart (struct xe_gt * gt )
266+ {
267+ xe_gt_assert (gt , IS_SRIOV_PF (gt_to_xe (gt )));
268+ flush_work (& gt -> sriov .pf .workers .restart );
269+ }
270+
271+ /**
272+ * xe_gt_sriov_pf_wait_ready() - Wait until per-GT PF SR-IOV support is ready.
273+ * @gt: the &xe_gt
274+ *
275+ * This function can only be called on PF.
276+ *
277+ * Return: 0 on success or a negative error code on failure.
278+ */
279+ int xe_gt_sriov_pf_wait_ready (struct xe_gt * gt )
280+ {
281+ /* don't wait if there is another ongoing reset */
282+ if (xe_guc_read_stopped (& gt -> uc .guc ))
283+ return - EBUSY ;
284+
285+ pf_flush_restart (gt );
286+ return 0 ;
287+ }
0 commit comments