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