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