Path: blob/main/sys/contrib/openzfs/module/os/linux/zfs/qat.c
48774 views
// SPDX-License-Identifier: CDDL-1.01/*2* CDDL HEADER START3*4* The contents of this file are subject to the terms of the5* Common Development and Distribution License (the "License").6* You may not use this file except in compliance with the License.7*8* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9* or https://opensource.org/licenses/CDDL-1.0.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/2122#if defined(_KERNEL) && defined(HAVE_QAT)23#include <sys/zfs_context.h>24#include <sys/qat.h>2526qat_stats_t qat_stats = {27{ "comp_requests", KSTAT_DATA_UINT64 },28{ "comp_total_in_bytes", KSTAT_DATA_UINT64 },29{ "comp_total_out_bytes", KSTAT_DATA_UINT64 },30{ "decomp_requests", KSTAT_DATA_UINT64 },31{ "decomp_total_in_bytes", KSTAT_DATA_UINT64 },32{ "decomp_total_out_bytes", KSTAT_DATA_UINT64 },33{ "dc_fails", KSTAT_DATA_UINT64 },34{ "encrypt_requests", KSTAT_DATA_UINT64 },35{ "encrypt_total_in_bytes", KSTAT_DATA_UINT64 },36{ "encrypt_total_out_bytes", KSTAT_DATA_UINT64 },37{ "decrypt_requests", KSTAT_DATA_UINT64 },38{ "decrypt_total_in_bytes", KSTAT_DATA_UINT64 },39{ "decrypt_total_out_bytes", KSTAT_DATA_UINT64 },40{ "crypt_fails", KSTAT_DATA_UINT64 },41{ "cksum_requests", KSTAT_DATA_UINT64 },42{ "cksum_total_in_bytes", KSTAT_DATA_UINT64 },43{ "cksum_fails", KSTAT_DATA_UINT64 },44};4546static kstat_t *qat_ksp = NULL;4748CpaStatus49qat_mem_alloc_contig(void **pp_mem_addr, Cpa32U size_bytes)50{51*pp_mem_addr = kmalloc(size_bytes, GFP_KERNEL);52if (*pp_mem_addr == NULL)53return (CPA_STATUS_RESOURCE);54return (CPA_STATUS_SUCCESS);55}5657void58qat_mem_free_contig(void **pp_mem_addr)59{60if (*pp_mem_addr != NULL) {61kfree(*pp_mem_addr);62*pp_mem_addr = NULL;63}64}6566int67qat_init(void)68{69qat_ksp = kstat_create("zfs", 0, "qat", "misc",70KSTAT_TYPE_NAMED, sizeof (qat_stats) / sizeof (kstat_named_t),71KSTAT_FLAG_VIRTUAL);72if (qat_ksp != NULL) {73qat_ksp->ks_data = &qat_stats;74kstat_install(qat_ksp);75}7677/*78* Just set the disable flag when qat init failed, qat can be79* turned on again in post-process after zfs module is loaded, e.g.:80* echo 0 > /sys/module/zfs/parameters/zfs_qat_compress_disable81*/82if (qat_dc_init() != 0)83zfs_qat_compress_disable = 1;8485if (qat_cy_init() != 0) {86zfs_qat_checksum_disable = 1;87zfs_qat_encrypt_disable = 1;88}8990return (0);91}9293void94qat_fini(void)95{96if (qat_ksp != NULL) {97kstat_delete(qat_ksp);98qat_ksp = NULL;99}100101qat_cy_fini();102qat_dc_fini();103}104105#endif106107108