xref: /linux/drivers/gpu/drm/xe/xe_sriov_types.h (revision 2c1ed907520c50326b8f604907a8478b27881a2e)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2023 Intel Corporation
4  */
5 
6 #ifndef _XE_SRIOV_TYPES_H_
7 #define _XE_SRIOV_TYPES_H_
8 
9 #include <linux/build_bug.h>
10 #include <linux/mutex.h>
11 #include <linux/types.h>
12 #include <linux/workqueue_types.h>
13 
14 /**
15  * VFID - Virtual Function Identifier
16  * @n: VF number
17  *
18  * Helper macro to represent Virtual Function (VF) Identifier.
19  * VFID(0) is used as alias to the PFID that represents Physical Function.
20  *
21  * Note: According to PCI spec, SR-IOV VF's numbers are 1-based (VF1, VF2, ...).
22  */
23 #define VFID(n)		(n)
24 #define PFID		VFID(0)
25 
26 /**
27  * enum xe_sriov_mode - SR-IOV mode
28  * @XE_SRIOV_MODE_NONE: bare-metal mode (non-virtualized)
29  * @XE_SRIOV_MODE_PF: SR-IOV Physical Function (PF) mode
30  * @XE_SRIOV_MODE_VF: SR-IOV Virtual Function (VF) mode
31  */
32 enum xe_sriov_mode {
33 	/*
34 	 * Note: We don't use default enum value 0 to allow catch any too early
35 	 * attempt of checking the SR-IOV mode prior to the actual mode probe.
36 	 */
37 	XE_SRIOV_MODE_NONE = 1,
38 	XE_SRIOV_MODE_PF,
39 	XE_SRIOV_MODE_VF,
40 };
41 static_assert(XE_SRIOV_MODE_NONE);
42 
43 /**
44  * struct xe_device_pf - Xe PF related data
45  *
46  * The data in this structure is valid only if driver is running in the
47  * @XE_SRIOV_MODE_PF mode.
48  */
49 struct xe_device_pf {
50 	/** @device_total_vfs: Maximum number of VFs supported by the device. */
51 	u16 device_total_vfs;
52 
53 	/** @driver_max_vfs: Maximum number of VFs supported by the driver. */
54 	u16 driver_max_vfs;
55 
56 	/** @master_lock: protects all VFs configurations across GTs */
57 	struct mutex master_lock;
58 };
59 
60 /**
61  * struct xe_device_vf - Xe Virtual Function related data
62  *
63  * The data in this structure is valid only if driver is running in the
64  * @XE_SRIOV_MODE_VF mode.
65  */
66 struct xe_device_vf {
67 	/** @migration: VF Migration state data */
68 	struct {
69 		/** @migration.worker: VF migration recovery worker */
70 		struct work_struct worker;
71 		/** @migration.gt_flags: Per-GT request flags for VF migration recovery */
72 		unsigned long gt_flags;
73 	} migration;
74 };
75 
76 #endif
77