1 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
2 /* Copyright(c) 2014 - 2020 Intel Corporation */
3 #include <linux/firmware.h>
6 #include "adf_accel_devices.h"
7 #include "adf_common_drv.h"
8 #include "icp_qat_uclo.h"
10 static int adf_ae_fw_load_images(struct adf_accel_dev
*accel_dev
, void *fw_addr
,
13 struct adf_fw_loader_data
*loader_data
= accel_dev
->fw_loader
;
14 struct adf_hw_device_data
*hw_device
= accel_dev
->hw_device
;
15 struct icp_qat_fw_loader_handle
*loader
;
21 loader
= loader_data
->fw_loader
;
22 num_objs
= hw_device
->uof_get_num_objs();
24 for (i
= 0; i
< num_objs
; i
++) {
25 obj_name
= hw_device
->uof_get_name(i
);
26 ae_mask
= hw_device
->uof_get_ae_mask(i
);
28 if (qat_uclo_set_cfg_ae_mask(loader
, ae_mask
)) {
29 dev_err(&GET_DEV(accel_dev
),
30 "Invalid mask for UOF image\n");
33 if (qat_uclo_map_obj(loader
, fw_addr
, fw_size
, obj_name
)) {
34 dev_err(&GET_DEV(accel_dev
),
35 "Failed to map UOF firmware\n");
38 if (qat_uclo_wr_all_uimage(loader
)) {
39 dev_err(&GET_DEV(accel_dev
),
40 "Failed to load UOF firmware\n");
43 qat_uclo_del_obj(loader
);
49 adf_ae_fw_release(accel_dev
);
53 int adf_ae_fw_load(struct adf_accel_dev
*accel_dev
)
55 struct adf_fw_loader_data
*loader_data
= accel_dev
->fw_loader
;
56 struct adf_hw_device_data
*hw_device
= accel_dev
->hw_device
;
57 void *fw_addr
, *mmp_addr
;
58 u32 fw_size
, mmp_size
;
60 if (!hw_device
->fw_name
)
63 if (request_firmware(&loader_data
->mmp_fw
, hw_device
->fw_mmp_name
,
64 &accel_dev
->accel_pci_dev
.pci_dev
->dev
)) {
65 dev_err(&GET_DEV(accel_dev
), "Failed to load MMP firmware %s\n",
66 hw_device
->fw_mmp_name
);
69 if (request_firmware(&loader_data
->uof_fw
, hw_device
->fw_name
,
70 &accel_dev
->accel_pci_dev
.pci_dev
->dev
)) {
71 dev_err(&GET_DEV(accel_dev
), "Failed to load UOF firmware %s\n",
76 fw_size
= loader_data
->uof_fw
->size
;
77 fw_addr
= (void *)loader_data
->uof_fw
->data
;
78 mmp_size
= loader_data
->mmp_fw
->size
;
79 mmp_addr
= (void *)loader_data
->mmp_fw
->data
;
81 if (qat_uclo_wr_mimage(loader_data
->fw_loader
, mmp_addr
, mmp_size
)) {
82 dev_err(&GET_DEV(accel_dev
), "Failed to load MMP\n");
86 if (hw_device
->uof_get_num_objs
)
87 return adf_ae_fw_load_images(accel_dev
, fw_addr
, fw_size
);
89 if (qat_uclo_map_obj(loader_data
->fw_loader
, fw_addr
, fw_size
, NULL
)) {
90 dev_err(&GET_DEV(accel_dev
), "Failed to map FW\n");
93 if (qat_uclo_wr_all_uimage(loader_data
->fw_loader
)) {
94 dev_err(&GET_DEV(accel_dev
), "Failed to load UOF\n");
100 adf_ae_fw_release(accel_dev
);
104 void adf_ae_fw_release(struct adf_accel_dev
*accel_dev
)
106 struct adf_fw_loader_data
*loader_data
= accel_dev
->fw_loader
;
107 struct adf_hw_device_data
*hw_device
= accel_dev
->hw_device
;
109 if (!hw_device
->fw_name
)
112 qat_uclo_del_obj(loader_data
->fw_loader
);
113 qat_hal_deinit(loader_data
->fw_loader
);
114 release_firmware(loader_data
->uof_fw
);
115 release_firmware(loader_data
->mmp_fw
);
116 loader_data
->uof_fw
= NULL
;
117 loader_data
->mmp_fw
= NULL
;
118 loader_data
->fw_loader
= NULL
;
121 int adf_ae_start(struct adf_accel_dev
*accel_dev
)
123 struct adf_fw_loader_data
*loader_data
= accel_dev
->fw_loader
;
124 struct adf_hw_device_data
*hw_data
= accel_dev
->hw_device
;
127 if (!hw_data
->fw_name
)
130 ae_ctr
= qat_hal_start(loader_data
->fw_loader
);
131 dev_info(&GET_DEV(accel_dev
),
132 "qat_dev%d started %d acceleration engines\n",
133 accel_dev
->accel_id
, ae_ctr
);
137 int adf_ae_stop(struct adf_accel_dev
*accel_dev
)
139 struct adf_fw_loader_data
*loader_data
= accel_dev
->fw_loader
;
140 struct adf_hw_device_data
*hw_data
= accel_dev
->hw_device
;
141 u32 ae_ctr
, ae
, max_aes
= GET_MAX_ACCELENGINES(accel_dev
);
143 if (!hw_data
->fw_name
)
146 for (ae
= 0, ae_ctr
= 0; ae
< max_aes
; ae
++) {
147 if (hw_data
->ae_mask
& (1 << ae
)) {
148 qat_hal_stop(loader_data
->fw_loader
, ae
, 0xFF);
152 dev_info(&GET_DEV(accel_dev
),
153 "qat_dev%d stopped %d acceleration engines\n",
154 accel_dev
->accel_id
, ae_ctr
);
158 static int adf_ae_reset(struct adf_accel_dev
*accel_dev
, int ae
)
160 struct adf_fw_loader_data
*loader_data
= accel_dev
->fw_loader
;
162 qat_hal_reset(loader_data
->fw_loader
);
163 if (qat_hal_clr_reset(loader_data
->fw_loader
))
169 int adf_ae_init(struct adf_accel_dev
*accel_dev
)
171 struct adf_fw_loader_data
*loader_data
;
172 struct adf_hw_device_data
*hw_device
= accel_dev
->hw_device
;
174 if (!hw_device
->fw_name
)
177 loader_data
= kzalloc(sizeof(*loader_data
), GFP_KERNEL
);
181 accel_dev
->fw_loader
= loader_data
;
182 if (qat_hal_init(accel_dev
)) {
183 dev_err(&GET_DEV(accel_dev
), "Failed to init the AEs\n");
187 if (adf_ae_reset(accel_dev
, 0)) {
188 dev_err(&GET_DEV(accel_dev
), "Failed to reset the AEs\n");
189 qat_hal_deinit(loader_data
->fw_loader
);
196 int adf_ae_shutdown(struct adf_accel_dev
*accel_dev
)
198 struct adf_fw_loader_data
*loader_data
= accel_dev
->fw_loader
;
199 struct adf_hw_device_data
*hw_device
= accel_dev
->hw_device
;
201 if (!hw_device
->fw_name
)
204 qat_hal_deinit(loader_data
->fw_loader
);
205 kfree(accel_dev
->fw_loader
);
206 accel_dev
->fw_loader
= NULL
;