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