1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2025 Intel Corporation 4 */ 5 6 #include "xe_device.h" 7 #include "xe_gt_sriov_pf_control.h" 8 #include "xe_sriov_pf_control.h" 9 #include "xe_sriov_printk.h" 10 11 /** 12 * xe_sriov_pf_control_pause_vf() - Pause a VF on all GTs. 13 * @xe: the &xe_device 14 * @vfid: the VF identifier (can't be 0 == PFID) 15 * 16 * This function is for PF only. 17 * 18 * Return: 0 on success or a negative error code on failure. 19 */ 20 int xe_sriov_pf_control_pause_vf(struct xe_device *xe, unsigned int vfid) 21 { 22 struct xe_gt *gt; 23 unsigned int id; 24 int result = 0; 25 int err; 26 27 for_each_gt(gt, xe, id) { 28 err = xe_gt_sriov_pf_control_pause_vf(gt, vfid); 29 result = result ? -EUCLEAN : err; 30 } 31 32 if (result) 33 return result; 34 35 xe_sriov_info(xe, "VF%u paused!\n", vfid); 36 return 0; 37 } 38 39 /** 40 * xe_sriov_pf_control_resume_vf() - Resume a VF on all GTs. 41 * @xe: the &xe_device 42 * @vfid: the VF identifier 43 * 44 * This function is for PF only. 45 * 46 * Return: 0 on success or a negative error code on failure. 47 */ 48 int xe_sriov_pf_control_resume_vf(struct xe_device *xe, unsigned int vfid) 49 { 50 struct xe_gt *gt; 51 unsigned int id; 52 int result = 0; 53 int err; 54 55 for_each_gt(gt, xe, id) { 56 err = xe_gt_sriov_pf_control_resume_vf(gt, vfid); 57 result = result ? -EUCLEAN : err; 58 } 59 60 if (result) 61 return result; 62 63 xe_sriov_info(xe, "VF%u resumed!\n", vfid); 64 return 0; 65 } 66 67 /** 68 * xe_sriov_pf_control_stop_vf - Stop a VF on all GTs. 69 * @xe: the &xe_device 70 * @vfid: the VF identifier 71 * 72 * This function is for PF only. 73 * 74 * Return: 0 on success or a negative error code on failure. 75 */ 76 int xe_sriov_pf_control_stop_vf(struct xe_device *xe, unsigned int vfid) 77 { 78 struct xe_gt *gt; 79 unsigned int id; 80 int result = 0; 81 int err; 82 83 for_each_gt(gt, xe, id) { 84 err = xe_gt_sriov_pf_control_stop_vf(gt, vfid); 85 result = result ? -EUCLEAN : err; 86 } 87 88 if (result) 89 return result; 90 91 xe_sriov_info(xe, "VF%u stopped!\n", vfid); 92 return 0; 93 } 94 95 /** 96 * xe_sriov_pf_control_reset_vf() - Perform a VF reset (FLR). 97 * @xe: the &xe_device 98 * @vfid: the VF identifier 99 * 100 * This function is for PF only. 101 * 102 * Return: 0 on success or a negative error code on failure. 103 */ 104 int xe_sriov_pf_control_reset_vf(struct xe_device *xe, unsigned int vfid) 105 { 106 struct xe_gt *gt; 107 unsigned int id; 108 int result = 0; 109 int err; 110 111 for_each_gt(gt, xe, id) { 112 err = xe_gt_sriov_pf_control_trigger_flr(gt, vfid); 113 result = result ? -EUCLEAN : err; 114 } 115 116 for_each_gt(gt, xe, id) { 117 err = xe_gt_sriov_pf_control_wait_flr(gt, vfid); 118 result = result ? -EUCLEAN : err; 119 } 120 121 return result; 122 } 123 124 /** 125 * xe_sriov_pf_control_sync_flr() - Synchronize a VF FLR between all GTs. 126 * @xe: the &xe_device 127 * @vfid: the VF identifier 128 * 129 * This function is for PF only. 130 * 131 * Return: 0 on success or a negative error code on failure. 132 */ 133 int xe_sriov_pf_control_sync_flr(struct xe_device *xe, unsigned int vfid) 134 { 135 struct xe_gt *gt; 136 unsigned int id; 137 int ret; 138 139 for_each_gt(gt, xe, id) { 140 ret = xe_gt_sriov_pf_control_sync_flr(gt, vfid, false); 141 if (ret < 0) 142 return ret; 143 } 144 for_each_gt(gt, xe, id) { 145 ret = xe_gt_sriov_pf_control_sync_flr(gt, vfid, true); 146 if (ret < 0) 147 return ret; 148 } 149 150 return 0; 151 } 152