Skip to content

Commit b4ba221

Browse files
hmynenimpe
authored andcommitted
crypto/nx: Get NX capabilities for GZIP coprocessor type
The hypervisor provides different NX capabilities that it supports. These capabilities such as recommended minimum compression / decompression lengths and the maximum request buffer size in bytes are used to define the user space NX request. NX will reject the request if the buffer size is more than the maximum buffer size. Whereas compression / decompression lengths are recommended values for better performance. Changes to get NX overall capabilities which points to the specific features that the hypervisor supports. Then retrieve the capabilities for the specific feature (available only for NXGZIP). Signed-off-by: Haren Myneni <[email protected]> Acked-by: Herbert Xu <[email protected]> Acked-by: Nicholas Piggin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7da00b0 commit b4ba221

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

drivers/crypto/nx/nx-common-pseries.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010

1111
#include <asm/vio.h>
12+
#include <asm/hvcall.h>
13+
#include <asm/vas.h>
1214

1315
#include "nx-842.h"
1416
#include "nx_csbcpb.h" /* struct nx_csbcpb */
@@ -19,6 +21,29 @@ MODULE_DESCRIPTION("842 H/W Compression driver for IBM Power processors");
1921
MODULE_ALIAS_CRYPTO("842");
2022
MODULE_ALIAS_CRYPTO("842-nx");
2123

24+
/*
25+
* Coprocessor type specific capabilities from the hypervisor.
26+
*/
27+
struct hv_nx_cop_caps {
28+
__be64 descriptor;
29+
__be64 req_max_processed_len; /* Max bytes in one GZIP request */
30+
__be64 min_compress_len; /* Min compression size in bytes */
31+
__be64 min_decompress_len; /* Min decompression size in bytes */
32+
} __packed __aligned(0x1000);
33+
34+
/*
35+
* Coprocessor type specific capabilities.
36+
*/
37+
struct nx_cop_caps {
38+
u64 descriptor;
39+
u64 req_max_processed_len; /* Max bytes in one GZIP request */
40+
u64 min_compress_len; /* Min compression in bytes */
41+
u64 min_decompress_len; /* Min decompression in bytes */
42+
};
43+
44+
static u64 caps_feat;
45+
static struct nx_cop_caps nx_cop_caps;
46+
2247
static struct nx842_constraints nx842_pseries_constraints = {
2348
.alignment = DDE_BUFFER_ALIGN,
2449
.multiple = DDE_BUFFER_LAST_MULT,
@@ -1065,6 +1090,64 @@ static void nx842_remove(struct vio_dev *viodev)
10651090
kfree(old_devdata);
10661091
}
10671092

1093+
/*
1094+
* Get NX capabilities from the hypervisor.
1095+
* Only NXGZIP capabilities are provided by the hypersvisor right
1096+
* now and these values are available to user space with sysfs.
1097+
*/
1098+
static void __init nxcop_get_capabilities(void)
1099+
{
1100+
struct hv_vas_all_caps *hv_caps;
1101+
struct hv_nx_cop_caps *hv_nxc;
1102+
int rc;
1103+
1104+
hv_caps = kmalloc(sizeof(*hv_caps), GFP_KERNEL);
1105+
if (!hv_caps)
1106+
return;
1107+
/*
1108+
* Get NX overall capabilities with feature type=0
1109+
*/
1110+
rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES, 0,
1111+
(u64)virt_to_phys(hv_caps));
1112+
if (rc)
1113+
goto out;
1114+
1115+
caps_feat = be64_to_cpu(hv_caps->feat_type);
1116+
/*
1117+
* NX-GZIP feature available
1118+
*/
1119+
if (caps_feat & VAS_NX_GZIP_FEAT_BIT) {
1120+
hv_nxc = kmalloc(sizeof(*hv_nxc), GFP_KERNEL);
1121+
if (!hv_nxc)
1122+
goto out;
1123+
/*
1124+
* Get capabilities for NX-GZIP feature
1125+
*/
1126+
rc = h_query_vas_capabilities(H_QUERY_NX_CAPABILITIES,
1127+
VAS_NX_GZIP_FEAT,
1128+
(u64)virt_to_phys(hv_nxc));
1129+
} else {
1130+
pr_err("NX-GZIP feature is not available\n");
1131+
rc = -EINVAL;
1132+
}
1133+
1134+
if (!rc) {
1135+
nx_cop_caps.descriptor = be64_to_cpu(hv_nxc->descriptor);
1136+
nx_cop_caps.req_max_processed_len =
1137+
be64_to_cpu(hv_nxc->req_max_processed_len);
1138+
nx_cop_caps.min_compress_len =
1139+
be64_to_cpu(hv_nxc->min_compress_len);
1140+
nx_cop_caps.min_decompress_len =
1141+
be64_to_cpu(hv_nxc->min_decompress_len);
1142+
} else {
1143+
caps_feat = 0;
1144+
}
1145+
1146+
kfree(hv_nxc);
1147+
out:
1148+
kfree(hv_caps);
1149+
}
1150+
10681151
static const struct vio_device_id nx842_vio_driver_ids[] = {
10691152
{"ibm,compression-v1", "ibm,compression"},
10701153
{"", ""},
@@ -1092,6 +1175,10 @@ static int __init nx842_pseries_init(void)
10921175
return -ENOMEM;
10931176

10941177
RCU_INIT_POINTER(devdata, new_devdata);
1178+
/*
1179+
* Get NX capabilities from the hypervisor.
1180+
*/
1181+
nxcop_get_capabilities();
10951182

10961183
ret = vio_register_driver(&nx842_vio_driver);
10971184
if (ret) {

0 commit comments

Comments
 (0)