1 // SPDX-License-Identifier: GPL-2.0-only 2 /* Copyright(c) 2024 Intel Corporation */ 3 #include <linux/dev_printk.h> 4 #include <linux/export.h> 5 #include <linux/pci.h> 6 #include <linux/types.h> 7 #include <linux/qat/qat_mig_dev.h> 8 #include "adf_accel_devices.h" 9 #include "adf_common_drv.h" 10 11 struct qat_mig_dev *qat_vfmig_create(struct pci_dev *pdev, int vf_id) 12 { 13 struct adf_accel_dev *accel_dev; 14 struct qat_migdev_ops *ops; 15 struct qat_mig_dev *mdev; 16 17 accel_dev = adf_devmgr_pci_to_accel_dev(pdev); 18 if (!accel_dev) 19 return ERR_PTR(-ENODEV); 20 21 ops = GET_VFMIG_OPS(accel_dev); 22 if (!ops || !ops->init || !ops->cleanup || !ops->reset || !ops->open || 23 !ops->close || !ops->suspend || !ops->resume || !ops->save_state || 24 !ops->load_state || !ops->save_setup || !ops->load_setup) 25 return ERR_PTR(-EINVAL); 26 27 mdev = kmalloc(sizeof(*mdev), GFP_KERNEL); 28 if (!mdev) 29 return ERR_PTR(-ENOMEM); 30 31 mdev->vf_id = vf_id; 32 mdev->parent_accel_dev = accel_dev; 33 34 return mdev; 35 } 36 EXPORT_SYMBOL_GPL(qat_vfmig_create); 37 38 int qat_vfmig_init(struct qat_mig_dev *mdev) 39 { 40 struct adf_accel_dev *accel_dev = mdev->parent_accel_dev; 41 42 return GET_VFMIG_OPS(accel_dev)->init(mdev); 43 } 44 EXPORT_SYMBOL_GPL(qat_vfmig_init); 45 46 void qat_vfmig_cleanup(struct qat_mig_dev *mdev) 47 { 48 struct adf_accel_dev *accel_dev = mdev->parent_accel_dev; 49 50 return GET_VFMIG_OPS(accel_dev)->cleanup(mdev); 51 } 52 EXPORT_SYMBOL_GPL(qat_vfmig_cleanup); 53 54 void qat_vfmig_reset(struct qat_mig_dev *mdev) 55 { 56 struct adf_accel_dev *accel_dev = mdev->parent_accel_dev; 57 58 return GET_VFMIG_OPS(accel_dev)->reset(mdev); 59 } 60 EXPORT_SYMBOL_GPL(qat_vfmig_reset); 61 62 int qat_vfmig_open(struct qat_mig_dev *mdev) 63 { 64 struct adf_accel_dev *accel_dev = mdev->parent_accel_dev; 65 66 return GET_VFMIG_OPS(accel_dev)->open(mdev); 67 } 68 EXPORT_SYMBOL_GPL(qat_vfmig_open); 69 70 void qat_vfmig_close(struct qat_mig_dev *mdev) 71 { 72 struct adf_accel_dev *accel_dev = mdev->parent_accel_dev; 73 74 GET_VFMIG_OPS(accel_dev)->close(mdev); 75 } 76 EXPORT_SYMBOL_GPL(qat_vfmig_close); 77 78 int qat_vfmig_suspend(struct qat_mig_dev *mdev) 79 { 80 struct adf_accel_dev *accel_dev = mdev->parent_accel_dev; 81 82 return GET_VFMIG_OPS(accel_dev)->suspend(mdev); 83 } 84 EXPORT_SYMBOL_GPL(qat_vfmig_suspend); 85 86 int qat_vfmig_resume(struct qat_mig_dev *mdev) 87 { 88 struct adf_accel_dev *accel_dev = mdev->parent_accel_dev; 89 90 return GET_VFMIG_OPS(accel_dev)->resume(mdev); 91 } 92 EXPORT_SYMBOL_GPL(qat_vfmig_resume); 93 94 int qat_vfmig_save_state(struct qat_mig_dev *mdev) 95 { 96 struct adf_accel_dev *accel_dev = mdev->parent_accel_dev; 97 98 return GET_VFMIG_OPS(accel_dev)->save_state(mdev); 99 } 100 EXPORT_SYMBOL_GPL(qat_vfmig_save_state); 101 102 int qat_vfmig_save_setup(struct qat_mig_dev *mdev) 103 { 104 struct adf_accel_dev *accel_dev = mdev->parent_accel_dev; 105 106 return GET_VFMIG_OPS(accel_dev)->save_setup(mdev); 107 } 108 EXPORT_SYMBOL_GPL(qat_vfmig_save_setup); 109 110 int qat_vfmig_load_state(struct qat_mig_dev *mdev) 111 { 112 struct adf_accel_dev *accel_dev = mdev->parent_accel_dev; 113 114 return GET_VFMIG_OPS(accel_dev)->load_state(mdev); 115 } 116 EXPORT_SYMBOL_GPL(qat_vfmig_load_state); 117 118 int qat_vfmig_load_setup(struct qat_mig_dev *mdev, int size) 119 { 120 struct adf_accel_dev *accel_dev = mdev->parent_accel_dev; 121 122 return GET_VFMIG_OPS(accel_dev)->load_setup(mdev, size); 123 } 124 EXPORT_SYMBOL_GPL(qat_vfmig_load_setup); 125 126 void qat_vfmig_destroy(struct qat_mig_dev *mdev) 127 { 128 kfree(mdev); 129 } 130 EXPORT_SYMBOL_GPL(qat_vfmig_destroy); 131