1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy * CDDL HEADER START
3eda14cbcSMatt Macy *
4eda14cbcSMatt Macy * The contents of this file are subject to the terms of the
5eda14cbcSMatt Macy * Common Development and Distribution License (the "License").
6eda14cbcSMatt Macy * You may not use this file except in compliance with the License.
7eda14cbcSMatt Macy *
8eda14cbcSMatt Macy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*271171e0SMartin Matuska * or https://opensource.org/licenses/CDDL-1.0.
10eda14cbcSMatt Macy * See the License for the specific language governing permissions
11eda14cbcSMatt Macy * and limitations under the License.
12eda14cbcSMatt Macy *
13eda14cbcSMatt Macy * When distributing Covered Code, include this CDDL HEADER in each
14eda14cbcSMatt Macy * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15eda14cbcSMatt Macy * If applicable, add the following below this CDDL HEADER, with the
16eda14cbcSMatt Macy * fields enclosed by brackets "[]" replaced with your own identifying
17eda14cbcSMatt Macy * information: Portions Copyright [yyyy] [name of copyright owner]
18eda14cbcSMatt Macy *
19eda14cbcSMatt Macy * CDDL HEADER END
20eda14cbcSMatt Macy */
21eda14cbcSMatt Macy
22eda14cbcSMatt Macy #if defined(_KERNEL) && defined(HAVE_QAT)
23eda14cbcSMatt Macy #include <sys/zfs_context.h>
24eda14cbcSMatt Macy #include <sys/qat.h>
25eda14cbcSMatt Macy
26eda14cbcSMatt Macy qat_stats_t qat_stats = {
27eda14cbcSMatt Macy { "comp_requests", KSTAT_DATA_UINT64 },
28eda14cbcSMatt Macy { "comp_total_in_bytes", KSTAT_DATA_UINT64 },
29eda14cbcSMatt Macy { "comp_total_out_bytes", KSTAT_DATA_UINT64 },
30eda14cbcSMatt Macy { "decomp_requests", KSTAT_DATA_UINT64 },
31eda14cbcSMatt Macy { "decomp_total_in_bytes", KSTAT_DATA_UINT64 },
32eda14cbcSMatt Macy { "decomp_total_out_bytes", KSTAT_DATA_UINT64 },
33eda14cbcSMatt Macy { "dc_fails", KSTAT_DATA_UINT64 },
34eda14cbcSMatt Macy { "encrypt_requests", KSTAT_DATA_UINT64 },
35eda14cbcSMatt Macy { "encrypt_total_in_bytes", KSTAT_DATA_UINT64 },
36eda14cbcSMatt Macy { "encrypt_total_out_bytes", KSTAT_DATA_UINT64 },
37eda14cbcSMatt Macy { "decrypt_requests", KSTAT_DATA_UINT64 },
38eda14cbcSMatt Macy { "decrypt_total_in_bytes", KSTAT_DATA_UINT64 },
39eda14cbcSMatt Macy { "decrypt_total_out_bytes", KSTAT_DATA_UINT64 },
40eda14cbcSMatt Macy { "crypt_fails", KSTAT_DATA_UINT64 },
41eda14cbcSMatt Macy { "cksum_requests", KSTAT_DATA_UINT64 },
42eda14cbcSMatt Macy { "cksum_total_in_bytes", KSTAT_DATA_UINT64 },
43eda14cbcSMatt Macy { "cksum_fails", KSTAT_DATA_UINT64 },
44eda14cbcSMatt Macy };
45eda14cbcSMatt Macy
46eda14cbcSMatt Macy static kstat_t *qat_ksp = NULL;
47eda14cbcSMatt Macy
48eda14cbcSMatt Macy CpaStatus
qat_mem_alloc_contig(void ** pp_mem_addr,Cpa32U size_bytes)49eda14cbcSMatt Macy qat_mem_alloc_contig(void **pp_mem_addr, Cpa32U size_bytes)
50eda14cbcSMatt Macy {
51eda14cbcSMatt Macy *pp_mem_addr = kmalloc(size_bytes, GFP_KERNEL);
52eda14cbcSMatt Macy if (*pp_mem_addr == NULL)
53eda14cbcSMatt Macy return (CPA_STATUS_RESOURCE);
54eda14cbcSMatt Macy return (CPA_STATUS_SUCCESS);
55eda14cbcSMatt Macy }
56eda14cbcSMatt Macy
57eda14cbcSMatt Macy void
qat_mem_free_contig(void ** pp_mem_addr)58eda14cbcSMatt Macy qat_mem_free_contig(void **pp_mem_addr)
59eda14cbcSMatt Macy {
60eda14cbcSMatt Macy if (*pp_mem_addr != NULL) {
61eda14cbcSMatt Macy kfree(*pp_mem_addr);
62eda14cbcSMatt Macy *pp_mem_addr = NULL;
63eda14cbcSMatt Macy }
64eda14cbcSMatt Macy }
65eda14cbcSMatt Macy
66eda14cbcSMatt Macy int
qat_init(void)67eda14cbcSMatt Macy qat_init(void)
68eda14cbcSMatt Macy {
69eda14cbcSMatt Macy qat_ksp = kstat_create("zfs", 0, "qat", "misc",
70eda14cbcSMatt Macy KSTAT_TYPE_NAMED, sizeof (qat_stats) / sizeof (kstat_named_t),
71eda14cbcSMatt Macy KSTAT_FLAG_VIRTUAL);
72eda14cbcSMatt Macy if (qat_ksp != NULL) {
73eda14cbcSMatt Macy qat_ksp->ks_data = &qat_stats;
74eda14cbcSMatt Macy kstat_install(qat_ksp);
75eda14cbcSMatt Macy }
76eda14cbcSMatt Macy
77eda14cbcSMatt Macy /*
78eda14cbcSMatt Macy * Just set the disable flag when qat init failed, qat can be
79eda14cbcSMatt Macy * turned on again in post-process after zfs module is loaded, e.g.:
80eda14cbcSMatt Macy * echo 0 > /sys/module/zfs/parameters/zfs_qat_compress_disable
81eda14cbcSMatt Macy */
82eda14cbcSMatt Macy if (qat_dc_init() != 0)
83eda14cbcSMatt Macy zfs_qat_compress_disable = 1;
84eda14cbcSMatt Macy
85eda14cbcSMatt Macy if (qat_cy_init() != 0) {
86eda14cbcSMatt Macy zfs_qat_checksum_disable = 1;
87eda14cbcSMatt Macy zfs_qat_encrypt_disable = 1;
88eda14cbcSMatt Macy }
89eda14cbcSMatt Macy
90eda14cbcSMatt Macy return (0);
91eda14cbcSMatt Macy }
92eda14cbcSMatt Macy
93eda14cbcSMatt Macy void
qat_fini(void)94eda14cbcSMatt Macy qat_fini(void)
95eda14cbcSMatt Macy {
96eda14cbcSMatt Macy if (qat_ksp != NULL) {
97eda14cbcSMatt Macy kstat_delete(qat_ksp);
98eda14cbcSMatt Macy qat_ksp = NULL;
99eda14cbcSMatt Macy }
100eda14cbcSMatt Macy
101eda14cbcSMatt Macy qat_cy_fini();
102eda14cbcSMatt Macy qat_dc_fini();
103eda14cbcSMatt Macy }
104eda14cbcSMatt Macy
105eda14cbcSMatt Macy #endif
106