Skip to content

Commit 0fce55e

Browse files
XinIZengherbertx
authored andcommitted
crypto: qat - add interface for live migration
Extend the driver with a new interface to be used for VF live migration. This allows to create and destroy a qat_mig_dev object that contains a set of methods to allow to save and restore the state of QAT VF. This interface will be used by the qat-vfio-pci module. Signed-off-by: Xin Zeng <[email protected]> Reviewed-by: Giovanni Cabiddu <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent bbfdde7 commit 0fce55e

File tree

5 files changed

+189
-1
lines changed

5 files changed

+189
-1
lines changed

drivers/crypto/intel/qat/qat_common/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ intel_qat-$(CONFIG_DEBUG_FS) += adf_transport_debug.o \
5454
intel_qat-$(CONFIG_PCI_IOV) += adf_sriov.o adf_vf_isr.o adf_pfvf_utils.o \
5555
adf_pfvf_pf_msg.o adf_pfvf_pf_proto.o \
5656
adf_pfvf_vf_msg.o adf_pfvf_vf_proto.o \
57-
adf_gen2_pfvf.o adf_gen4_pfvf.o
57+
adf_gen2_pfvf.o adf_gen4_pfvf.o qat_mig_dev.o
5858

5959
intel_qat-$(CONFIG_CRYPTO_DEV_QAT_ERROR_INJECTION) += adf_heartbeat_inject.o

drivers/crypto/intel/qat/qat_common/adf_accel_devices.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/pci.h>
1010
#include <linux/ratelimit.h>
1111
#include <linux/types.h>
12+
#include <linux/qat/qat_mig_dev.h>
1213
#include "adf_cfg_common.h"
1314
#include "adf_rl.h"
1415
#include "adf_telemetry.h"
@@ -258,6 +259,20 @@ struct adf_dc_ops {
258259
void (*build_deflate_ctx)(void *ctx);
259260
};
260261

262+
struct qat_migdev_ops {
263+
int (*init)(struct qat_mig_dev *mdev);
264+
void (*cleanup)(struct qat_mig_dev *mdev);
265+
void (*reset)(struct qat_mig_dev *mdev);
266+
int (*open)(struct qat_mig_dev *mdev);
267+
void (*close)(struct qat_mig_dev *mdev);
268+
int (*suspend)(struct qat_mig_dev *mdev);
269+
int (*resume)(struct qat_mig_dev *mdev);
270+
int (*save_state)(struct qat_mig_dev *mdev);
271+
int (*save_setup)(struct qat_mig_dev *mdev);
272+
int (*load_state)(struct qat_mig_dev *mdev);
273+
int (*load_setup)(struct qat_mig_dev *mdev, int size);
274+
};
275+
261276
struct adf_dev_err_mask {
262277
u32 cppagentcmdpar_mask;
263278
u32 parerr_ath_cph_mask;
@@ -325,6 +340,7 @@ struct adf_hw_device_data {
325340
struct adf_dev_err_mask dev_err_mask;
326341
struct adf_rl_hw_data rl_data;
327342
struct adf_tl_hw_data tl_data;
343+
struct qat_migdev_ops vfmig_ops;
328344
const char *fw_name;
329345
const char *fw_mmp_name;
330346
u32 fuses;
@@ -381,6 +397,7 @@ struct adf_hw_device_data {
381397
#define GET_CSR_OPS(accel_dev) (&(accel_dev)->hw_device->csr_ops)
382398
#define GET_PFVF_OPS(accel_dev) (&(accel_dev)->hw_device->pfvf_ops)
383399
#define GET_DC_OPS(accel_dev) (&(accel_dev)->hw_device->dc_ops)
400+
#define GET_VFMIG_OPS(accel_dev) (&(accel_dev)->hw_device->vfmig_ops)
384401
#define GET_TL_DATA(accel_dev) GET_HW_DATA(accel_dev)->tl_data
385402
#define accel_to_pci_dev(accel_ptr) accel_ptr->accel_pci_dev.pci_dev
386403

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/* Copyright(c) 2024 Intel Corporation */
3+
#ifndef ADF_GEN4_VF_MIG_H_
4+
#define ADF_GEN4_VF_MIG_H_
5+
6+
#include "adf_accel_devices.h"
7+
8+
void adf_gen4_init_vf_mig_ops(struct qat_migdev_ops *vfmig_ops);
9+
10+
#endif
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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);

include/linux/qat/qat_mig_dev.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/* Copyright(c) 2024 Intel Corporation */
3+
#ifndef QAT_MIG_DEV_H_
4+
#define QAT_MIG_DEV_H_
5+
6+
struct pci_dev;
7+
8+
struct qat_mig_dev {
9+
void *parent_accel_dev;
10+
u8 *state;
11+
u32 setup_size;
12+
u32 remote_setup_size;
13+
u32 state_size;
14+
s32 vf_id;
15+
};
16+
17+
struct qat_mig_dev *qat_vfmig_create(struct pci_dev *pdev, int vf_id);
18+
int qat_vfmig_init(struct qat_mig_dev *mdev);
19+
void qat_vfmig_cleanup(struct qat_mig_dev *mdev);
20+
void qat_vfmig_reset(struct qat_mig_dev *mdev);
21+
int qat_vfmig_open(struct qat_mig_dev *mdev);
22+
void qat_vfmig_close(struct qat_mig_dev *mdev);
23+
int qat_vfmig_suspend(struct qat_mig_dev *mdev);
24+
int qat_vfmig_resume(struct qat_mig_dev *mdev);
25+
int qat_vfmig_save_state(struct qat_mig_dev *mdev);
26+
int qat_vfmig_save_setup(struct qat_mig_dev *mdev);
27+
int qat_vfmig_load_state(struct qat_mig_dev *mdev);
28+
int qat_vfmig_load_setup(struct qat_mig_dev *mdev, int size);
29+
void qat_vfmig_destroy(struct qat_mig_dev *mdev);
30+
31+
#endif /*QAT_MIG_DEV_H_*/

0 commit comments

Comments
 (0)