Skip to content

Commit a573313

Browse files
tstrukherbertx
authored andcommitted
crypto: qat - Move adf admin and adf hw arbitrer to common code
Adf admin and HW arbiter function can be used by dh895xcc specific code well as the new dh895xccvf and future devices so moving them to qat_common so that they can be shared. Signed-off-by: Tadeusz Struk <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 104880a commit a573313

File tree

14 files changed

+97
-241
lines changed

14 files changed

+97
-241
lines changed

drivers/crypto/qat/qat_common/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ intel_qat-objs := adf_cfg.o \
99
adf_accel_engine.o \
1010
adf_aer.o \
1111
adf_transport.o \
12+
adf_admin.o \
13+
adf_hw_arbiter.o \
1214
qat_crypto.o \
1315
qat_algs.o \
1416
qat_rsakey-asn1.o \

drivers/crypto/qat/qat_common/adf_accel_devices.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,16 @@ struct adf_hw_device_data {
141141
uint32_t (*get_num_aes)(struct adf_hw_device_data *self);
142142
uint32_t (*get_num_accels)(struct adf_hw_device_data *self);
143143
enum dev_sku_info (*get_sku)(struct adf_hw_device_data *self);
144-
void (*hw_arb_ring_enable)(struct adf_etr_ring_data *ring);
145-
void (*hw_arb_ring_disable)(struct adf_etr_ring_data *ring);
146144
int (*alloc_irq)(struct adf_accel_dev *accel_dev);
147145
void (*free_irq)(struct adf_accel_dev *accel_dev);
148146
void (*enable_error_correction)(struct adf_accel_dev *accel_dev);
149147
int (*init_admin_comms)(struct adf_accel_dev *accel_dev);
150148
void (*exit_admin_comms)(struct adf_accel_dev *accel_dev);
149+
int (*send_admin_init)(struct adf_accel_dev *accel_dev);
151150
int (*init_arb)(struct adf_accel_dev *accel_dev);
152151
void (*exit_arb)(struct adf_accel_dev *accel_dev);
152+
void (*get_arb_mapping)(struct adf_accel_dev *accel_dev,
153+
const uint32_t **cfg);
153154
void (*enable_ints)(struct adf_accel_dev *accel_dev);
154155
const char *fw_name;
155156
const char *fw_mmp_name;

drivers/crypto/qat/qat_dh895xcc/adf_admin.c renamed to drivers/crypto/qat/qat_common/adf_admin.c

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@
5050
#include <linux/delay.h>
5151
#include <linux/pci.h>
5252
#include <linux/dma-mapping.h>
53-
#include <adf_accel_devices.h>
54-
#include "adf_drv.h"
55-
#include "adf_dh895xcc_hw_data.h"
56-
53+
#include "adf_accel_devices.h"
54+
#include "icp_qat_fw_init_admin.h"
55+
56+
/* Admin Messages Registers */
57+
#define ADF_DH895XCC_ADMINMSGUR_OFFSET (0x3A000 + 0x574)
58+
#define ADF_DH895XCC_ADMINMSGLR_OFFSET (0x3A000 + 0x578)
59+
#define ADF_DH895XCC_MAILBOX_BASE_OFFSET 0x20970
60+
#define ADF_DH895XCC_MAILBOX_STRIDE 0x1000
5761
#define ADF_ADMINMSG_LEN 32
5862

5963
struct adf_admin_comms {
@@ -63,8 +67,8 @@ struct adf_admin_comms {
6367
struct mutex lock; /* protects adf_admin_comms struct */
6468
};
6569

66-
int adf_put_admin_msg_sync(struct adf_accel_dev *accel_dev,
67-
uint32_t ae, void *in, void *out)
70+
static int adf_put_admin_msg_sync(struct adf_accel_dev *accel_dev, u32 ae,
71+
void *in, void *out)
6872
{
6973
struct adf_admin_comms *admin = accel_dev->admin;
7074
int offset = ae * ADF_ADMINMSG_LEN * 2;
@@ -100,13 +104,47 @@ int adf_put_admin_msg_sync(struct adf_accel_dev *accel_dev,
100104
return received ? 0 : -EFAULT;
101105
}
102106

107+
static int adf_send_admin_cmd(struct adf_accel_dev *accel_dev, int cmd)
108+
{
109+
struct adf_hw_device_data *hw_device = accel_dev->hw_device;
110+
struct icp_qat_fw_init_admin_req req;
111+
struct icp_qat_fw_init_admin_resp resp;
112+
int i;
113+
114+
memset(&req, 0, sizeof(struct icp_qat_fw_init_admin_req));
115+
req.init_admin_cmd_id = cmd;
116+
for (i = 0; i < hw_device->get_num_aes(hw_device); i++) {
117+
memset(&resp, 0, sizeof(struct icp_qat_fw_init_admin_resp));
118+
if (adf_put_admin_msg_sync(accel_dev, i, &req, &resp) ||
119+
resp.init_resp_hdr.status)
120+
return -EFAULT;
121+
}
122+
return 0;
123+
}
124+
125+
/**
126+
* adf_send_admin_init() - Function sends init message to FW
127+
* @accel_dev: Pointer to acceleration device.
128+
*
129+
* Function sends admin init message to the FW
130+
*
131+
* Return: 0 on success, error code otherwise.
132+
*/
133+
int adf_send_admin_init(struct adf_accel_dev *accel_dev)
134+
{
135+
return adf_send_admin_cmd(accel_dev, ICP_QAT_FW_INIT_ME);
136+
}
137+
EXPORT_SYMBOL_GPL(adf_send_admin_init);
138+
103139
int adf_init_admin_comms(struct adf_accel_dev *accel_dev)
104140
{
105141
struct adf_admin_comms *admin;
106-
struct adf_bar *pmisc = &GET_BARS(accel_dev)[ADF_DH895XCC_PMISC_BAR];
142+
struct adf_hw_device_data *hw_data = accel_dev->hw_device;
143+
struct adf_bar *pmisc =
144+
&GET_BARS(accel_dev)[hw_data->get_misc_bar_id(hw_data)];
107145
void __iomem *csr = pmisc->virt_addr;
108146
void __iomem *mailbox = csr + ADF_DH895XCC_MAILBOX_BASE_OFFSET;
109-
uint64_t reg_val;
147+
u64 reg_val;
110148

111149
admin = kzalloc_node(sizeof(*accel_dev->admin), GFP_KERNEL,
112150
dev_to_node(&GET_DEV(accel_dev)));
@@ -119,14 +157,15 @@ int adf_init_admin_comms(struct adf_accel_dev *accel_dev)
119157
kfree(admin);
120158
return -ENOMEM;
121159
}
122-
reg_val = (uint64_t)admin->phy_addr;
160+
reg_val = (u64)admin->phy_addr;
123161
ADF_CSR_WR(csr, ADF_DH895XCC_ADMINMSGUR_OFFSET, reg_val >> 32);
124162
ADF_CSR_WR(csr, ADF_DH895XCC_ADMINMSGLR_OFFSET, reg_val);
125163
mutex_init(&admin->lock);
126164
admin->mailbox_addr = mailbox;
127165
accel_dev->admin = admin;
128166
return 0;
129167
}
168+
EXPORT_SYMBOL_GPL(adf_init_admin_comms);
130169

131170
void adf_exit_admin_comms(struct adf_accel_dev *accel_dev)
132171
{
@@ -143,3 +182,4 @@ void adf_exit_admin_comms(struct adf_accel_dev *accel_dev)
143182
kfree(admin);
144183
accel_dev->admin = NULL;
145184
}
185+
EXPORT_SYMBOL_GPL(adf_exit_admin_comms);

drivers/crypto/qat/qat_common/adf_common_drv.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ struct service_hndl {
9191
unsigned long start_status;
9292
char *name;
9393
struct list_head list;
94-
int admin;
9594
};
9695

9796
static inline int get_current_node(void)
@@ -135,6 +134,12 @@ int adf_enable_aer(struct adf_accel_dev *accel_dev, struct pci_driver *adf);
135134
void adf_disable_aer(struct adf_accel_dev *accel_dev);
136135
int adf_init_aer(void);
137136
void adf_exit_aer(void);
137+
int adf_init_admin_comms(struct adf_accel_dev *accel_dev);
138+
void adf_exit_admin_comms(struct adf_accel_dev *accel_dev);
139+
int adf_send_admin_init(struct adf_accel_dev *accel_dev);
140+
int adf_init_arb(struct adf_accel_dev *accel_dev);
141+
void adf_exit_arb(struct adf_accel_dev *accel_dev);
142+
void adf_update_ring_arb(struct adf_etr_ring_data *ring);
138143

139144
int adf_dev_get(struct adf_accel_dev *accel_dev);
140145
void adf_dev_put(struct adf_accel_dev *accel_dev);

drivers/crypto/qat/qat_dh895xcc/adf_hw_arbiter.c renamed to drivers/crypto/qat/qat_common/adf_hw_arbiter.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@
4444
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4545
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4646
*/
47-
#include <adf_accel_devices.h>
48-
#include <adf_transport_internal.h>
49-
#include "adf_drv.h"
47+
#include "adf_accel_devices.h"
48+
#include "adf_transport_internal.h"
5049

5150
#define ADF_ARB_NUM 4
5251
#define ADF_ARB_REQ_RING_NUM 8
@@ -58,7 +57,6 @@
5857
#define ADF_ARB_RO_EN_OFFSET 0x090
5958
#define ADF_ARB_WQCFG_OFFSET 0x100
6059
#define ADF_ARB_WRK_2_SER_MAP_OFFSET 0x180
61-
#define ADF_ARB_WRK_2_SER_MAP 10
6260
#define ADF_ARB_RINGSRVARBEN_OFFSET 0x19C
6361

6462
#define WRITE_CSR_ARB_RINGSRVARBEN(csr_addr, index, value) \
@@ -89,10 +87,11 @@
8987

9088
int adf_init_arb(struct adf_accel_dev *accel_dev)
9189
{
90+
struct adf_hw_device_data *hw_data = accel_dev->hw_device;
9291
void __iomem *csr = accel_dev->transport->banks[0].csr_addr;
93-
uint32_t arb_cfg = 0x1 << 31 | 0x4 << 4 | 0x1;
94-
uint32_t arb, i;
95-
const uint32_t *thd_2_arb_cfg;
92+
u32 arb_cfg = 0x1 << 31 | 0x4 << 4 | 0x1;
93+
u32 arb, i;
94+
const u32 *thd_2_arb_cfg;
9695

9796
/* Service arb configured for 32 bytes responses and
9897
* ring flow control check enabled. */
@@ -109,30 +108,39 @@ int adf_init_arb(struct adf_accel_dev *accel_dev)
109108
WRITE_CSR_ARB_RESPORDERING(csr, i, 0xFFFFFFFF);
110109

111110
/* Setup worker queue registers */
112-
for (i = 0; i < ADF_ARB_WRK_2_SER_MAP; i++)
111+
for (i = 0; i < hw_data->num_engines; i++)
113112
WRITE_CSR_ARB_WQCFG(csr, i, i);
114113

115114
/* Map worker threads to service arbiters */
116-
adf_get_arbiter_mapping(accel_dev, &thd_2_arb_cfg);
115+
hw_data->get_arb_mapping(accel_dev, &thd_2_arb_cfg);
117116

118117
if (!thd_2_arb_cfg)
119118
return -EFAULT;
120119

121-
for (i = 0; i < ADF_ARB_WRK_2_SER_MAP; i++)
120+
for (i = 0; i < hw_data->num_engines; i++)
122121
WRITE_CSR_ARB_WRK_2_SER_MAP(csr, i, *(thd_2_arb_cfg + i));
123122

124123
return 0;
125124
}
126-
127-
void adf_update_ring_arb_enable(struct adf_etr_ring_data *ring)
125+
EXPORT_SYMBOL_GPL(adf_init_arb);
126+
127+
/**
128+
* adf_update_ring_arb() - update ring arbitration rgister
129+
* @accel_dev: Pointer to ring data.
130+
*
131+
* Function enables or disables rings for/from arbitration.
132+
*/
133+
void adf_update_ring_arb(struct adf_etr_ring_data *ring)
128134
{
129135
WRITE_CSR_ARB_RINGSRVARBEN(ring->bank->csr_addr,
130136
ring->bank->bank_number,
131137
ring->bank->ring_mask & 0xFF);
132138
}
139+
EXPORT_SYMBOL_GPL(adf_update_ring_arb);
133140

134141
void adf_exit_arb(struct adf_accel_dev *accel_dev)
135142
{
143+
struct adf_hw_device_data *hw_data = accel_dev->hw_device;
136144
void __iomem *csr;
137145
unsigned int i;
138146

@@ -146,14 +154,15 @@ void adf_exit_arb(struct adf_accel_dev *accel_dev)
146154
WRITE_CSR_ARB_SARCONFIG(csr, i, 0);
147155

148156
/* Shutdown work queue */
149-
for (i = 0; i < ADF_ARB_WRK_2_SER_MAP; i++)
157+
for (i = 0; i < hw_data->num_engines; i++)
150158
WRITE_CSR_ARB_WQCFG(csr, i, 0);
151159

152160
/* Unmap worker threads to service arbiters */
153-
for (i = 0; i < ADF_ARB_WRK_2_SER_MAP; i++)
161+
for (i = 0; i < hw_data->num_engines; i++)
154162
WRITE_CSR_ARB_WRK_2_SER_MAP(csr, i, 0);
155163

156164
/* Disable arbitration on all rings */
157165
for (i = 0; i < GET_MAX_BANKS(accel_dev); i++)
158166
WRITE_CSR_ARB_RINGSRVARBEN(csr, i, 0);
159167
}
168+
EXPORT_SYMBOL_GPL(adf_exit_arb);

drivers/crypto/qat/qat_common/adf_init.c

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,6 @@ int adf_dev_init(struct adf_accel_dev *accel_dev)
177177
*/
178178
list_for_each(list_itr, &service_table) {
179179
service = list_entry(list_itr, struct service_hndl, list);
180-
if (!service->admin)
181-
continue;
182-
if (service->event_hld(accel_dev, ADF_EVENT_INIT)) {
183-
dev_err(&GET_DEV(accel_dev),
184-
"Failed to initialise service %s\n",
185-
service->name);
186-
return -EFAULT;
187-
}
188-
set_bit(accel_dev->accel_id, &service->init_status);
189-
}
190-
list_for_each(list_itr, &service_table) {
191-
service = list_entry(list_itr, struct service_hndl, list);
192-
if (service->admin)
193-
continue;
194180
if (service->event_hld(accel_dev, ADF_EVENT_INIT)) {
195181
dev_err(&GET_DEV(accel_dev),
196182
"Failed to initialise service %s\n",
@@ -218,6 +204,7 @@ EXPORT_SYMBOL_GPL(adf_dev_init);
218204
*/
219205
int adf_dev_start(struct adf_accel_dev *accel_dev)
220206
{
207+
struct adf_hw_device_data *hw_data = accel_dev->hw_device;
221208
struct service_hndl *service;
222209
struct list_head *list_itr;
223210

@@ -229,22 +216,13 @@ int adf_dev_start(struct adf_accel_dev *accel_dev)
229216
}
230217
set_bit(ADF_STATUS_AE_STARTED, &accel_dev->status);
231218

232-
list_for_each(list_itr, &service_table) {
233-
service = list_entry(list_itr, struct service_hndl, list);
234-
if (!service->admin)
235-
continue;
236-
if (service->event_hld(accel_dev, ADF_EVENT_START)) {
237-
dev_err(&GET_DEV(accel_dev),
238-
"Failed to start service %s\n",
239-
service->name);
240-
return -EFAULT;
241-
}
242-
set_bit(accel_dev->accel_id, &service->start_status);
219+
if (hw_data->send_admin_init(accel_dev)) {
220+
dev_err(&GET_DEV(accel_dev), "Failed to send init message\n");
221+
return -EFAULT;
243222
}
223+
244224
list_for_each(list_itr, &service_table) {
245225
service = list_entry(list_itr, struct service_hndl, list);
246-
if (service->admin)
247-
continue;
248226
if (service->event_hld(accel_dev, ADF_EVENT_START)) {
249227
dev_err(&GET_DEV(accel_dev),
250228
"Failed to start service %s\n",
@@ -300,8 +278,6 @@ int adf_dev_stop(struct adf_accel_dev *accel_dev)
300278

301279
list_for_each(list_itr, &service_table) {
302280
service = list_entry(list_itr, struct service_hndl, list);
303-
if (service->admin)
304-
continue;
305281
if (!test_bit(accel_dev->accel_id, &service->start_status))
306282
continue;
307283
ret = service->event_hld(accel_dev, ADF_EVENT_STOP);
@@ -312,19 +288,6 @@ int adf_dev_stop(struct adf_accel_dev *accel_dev)
312288
clear_bit(accel_dev->accel_id, &service->start_status);
313289
}
314290
}
315-
list_for_each(list_itr, &service_table) {
316-
service = list_entry(list_itr, struct service_hndl, list);
317-
if (!service->admin)
318-
continue;
319-
if (!test_bit(accel_dev->accel_id, &service->start_status))
320-
continue;
321-
if (service->event_hld(accel_dev, ADF_EVENT_STOP))
322-
dev_err(&GET_DEV(accel_dev),
323-
"Failed to shutdown service %s\n",
324-
service->name);
325-
else
326-
clear_bit(accel_dev->accel_id, &service->start_status);
327-
}
328291

329292
if (wait)
330293
msleep(100);
@@ -375,21 +338,6 @@ void adf_dev_shutdown(struct adf_accel_dev *accel_dev)
375338

376339
list_for_each(list_itr, &service_table) {
377340
service = list_entry(list_itr, struct service_hndl, list);
378-
if (service->admin)
379-
continue;
380-
if (!test_bit(accel_dev->accel_id, &service->init_status))
381-
continue;
382-
if (service->event_hld(accel_dev, ADF_EVENT_SHUTDOWN))
383-
dev_err(&GET_DEV(accel_dev),
384-
"Failed to shutdown service %s\n",
385-
service->name);
386-
else
387-
clear_bit(accel_dev->accel_id, &service->init_status);
388-
}
389-
list_for_each(list_itr, &service_table) {
390-
service = list_entry(list_itr, struct service_hndl, list);
391-
if (!service->admin)
392-
continue;
393341
if (!test_bit(accel_dev->accel_id, &service->init_status))
394342
continue;
395343
if (service->event_hld(accel_dev, ADF_EVENT_SHUTDOWN))
@@ -426,17 +374,6 @@ int adf_dev_restarting_notify(struct adf_accel_dev *accel_dev)
426374

427375
list_for_each(list_itr, &service_table) {
428376
service = list_entry(list_itr, struct service_hndl, list);
429-
if (service->admin)
430-
continue;
431-
if (service->event_hld(accel_dev, ADF_EVENT_RESTARTING))
432-
dev_err(&GET_DEV(accel_dev),
433-
"Failed to restart service %s.\n",
434-
service->name);
435-
}
436-
list_for_each(list_itr, &service_table) {
437-
service = list_entry(list_itr, struct service_hndl, list);
438-
if (!service->admin)
439-
continue;
440377
if (service->event_hld(accel_dev, ADF_EVENT_RESTARTING))
441378
dev_err(&GET_DEV(accel_dev),
442379
"Failed to restart service %s.\n",
@@ -452,17 +389,6 @@ int adf_dev_restarted_notify(struct adf_accel_dev *accel_dev)
452389

453390
list_for_each(list_itr, &service_table) {
454391
service = list_entry(list_itr, struct service_hndl, list);
455-
if (service->admin)
456-
continue;
457-
if (service->event_hld(accel_dev, ADF_EVENT_RESTARTED))
458-
dev_err(&GET_DEV(accel_dev),
459-
"Failed to restart service %s.\n",
460-
service->name);
461-
}
462-
list_for_each(list_itr, &service_table) {
463-
service = list_entry(list_itr, struct service_hndl, list);
464-
if (!service->admin)
465-
continue;
466392
if (service->event_hld(accel_dev, ADF_EVENT_RESTARTED))
467393
dev_err(&GET_DEV(accel_dev),
468394
"Failed to restart service %s.\n",

0 commit comments

Comments
 (0)