xref: /linux/drivers/crypto/intel/qat/qat_common/adf_kpt.c (revision b2128290c29902315e632ea59e0504d6bc9e9b42)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright(c) 2026 Intel Corporation */
3 #include <linux/dma-mapping.h>
4 
5 #include "adf_admin.h"
6 #include "adf_cfg_services.h"
7 #include "adf_common_drv.h"
8 #include "adf_kpt.h"
9 
10 static bool adf_kpt_supported(struct adf_accel_dev *accel_dev)
11 {
12 	struct adf_hw_device_data *hw_data = GET_HW_DATA(accel_dev);
13 
14 	return hw_data->accel_capabilities_mask & ICP_ACCEL_CAPABILITIES_KPT;
15 }
16 
17 int adf_enable_kpt(struct adf_accel_dev *accel_dev)
18 {
19 	struct adf_kpt_interface_data *user_data = GET_KPT_USER_DATA(accel_dev);
20 	struct adf_hw_device_data *hw_data = GET_HW_DATA(accel_dev);
21 	dma_addr_t paddr;
22 	void *vaddr;
23 	int ret;
24 	int svc;
25 
26 	/* Return 0 if KPT is not supported by the hardware */
27 	if (!adf_kpt_supported(accel_dev))
28 		return 0;
29 
30 	if (!user_data->enable) {
31 		/* Disable KPT capability if user has not enabled it */
32 		hw_data->accel_capabilities_mask &= ~ICP_ACCEL_CAPABILITIES_KPT;
33 		return 0;
34 	}
35 
36 	svc = adf_get_service_enabled(accel_dev);
37 	if (svc < 0)
38 		return svc;
39 
40 	if (svc != SVC_ASYM) {
41 		dev_err(&GET_DEV(accel_dev),
42 			"KPT can only be enabled when service is configured as 'asym'\n");
43 		return -EINVAL;
44 	}
45 
46 	vaddr = dma_alloc_coherent(&GET_DEV(accel_dev), PAGE_SIZE, &paddr,
47 				   GFP_KERNEL);
48 	if (!vaddr)
49 		return -ENOMEM;
50 
51 	ret = adf_send_admin_kpt_init(accel_dev, vaddr, PAGE_SIZE, paddr);
52 
53 	dma_free_coherent(&GET_DEV(accel_dev), PAGE_SIZE, vaddr, paddr);
54 
55 	return ret;
56 }
57