]> git.proxmox.com Git - mirror_zfs.git/blame - module/zfs/qat.h
Code improvement and bug fixes for QAT support
[mirror_zfs.git] / module / zfs / qat.h
CommitLineData
cf637391
TC
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * 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.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22#ifndef _SYS_QAT_H
23#define _SYS_QAT_H
24
25typedef enum qat_compress_dir {
26 QAT_DECOMPRESS = 0,
27 QAT_COMPRESS = 1,
28} qat_compress_dir_t;
29
30typedef enum qat_encrypt_dir {
31 QAT_DECRYPT = 0,
32 QAT_ENCRYPT = 1,
33} qat_encrypt_dir_t;
34
35
36#if defined(_KERNEL) && defined(HAVE_QAT)
37#include <sys/zio.h>
38#include <sys/crypto/api.h>
39#include "cpa.h"
40#include "dc/cpa_dc.h"
41#include "lac/cpa_cy_sym.h"
42
43/*
44 * Timeout - no response from hardware after 0.5 seconds
45 */
46#define QAT_TIMEOUT_MS 500
47
48/*
8d9e7c8f 49 * The minimal and maximal buffer size which are not restricted
cf637391 50 * in the QAT hardware, but with the input buffer size between 4KB
8d9e7c8f 51 * and 128KB the hardware can provide the optimal performance.
cf637391
TC
52 */
53#define QAT_MIN_BUF_SIZE (4*1024)
54#define QAT_MAX_BUF_SIZE (128*1024)
55
56/*
8d9e7c8f 57 * Used for QAT kstat.
cf637391
TC
58 */
59typedef struct qat_stats {
60 /*
8d9e7c8f 61 * Number of jobs submitted to QAT compression engine.
cf637391
TC
62 */
63 kstat_named_t comp_requests;
64 /*
8d9e7c8f 65 * Total bytes sent to QAT compression engine.
cf637391
TC
66 */
67 kstat_named_t comp_total_in_bytes;
68 /*
8d9e7c8f 69 * Total bytes output from QAT compression engine.
cf637391
TC
70 */
71 kstat_named_t comp_total_out_bytes;
72 /*
8d9e7c8f 73 * Number of jobs submitted to QAT de-compression engine.
cf637391
TC
74 */
75 kstat_named_t decomp_requests;
76 /*
8d9e7c8f 77 * Total bytes sent to QAT de-compression engine.
cf637391
TC
78 */
79 kstat_named_t decomp_total_in_bytes;
80 /*
8d9e7c8f 81 * Total bytes output from QAT de-compression engine.
cf637391
TC
82 */
83 kstat_named_t decomp_total_out_bytes;
84 /*
8d9e7c8f
TC
85 * Number of fails in the QAT compression / decompression engine.
86 * Note: when a QAT error happens, it doesn't necessarily indicate a
87 * critical hardware issue. Sometimes it is because the output buffer
88 * is not big enough. The compression job will be transfered to the
89 * gzip software implementation so the functionality of ZFS is not
90 * impacted.
cf637391
TC
91 */
92 kstat_named_t dc_fails;
93
94 /*
8d9e7c8f 95 * Number of jobs submitted to QAT encryption engine.
cf637391
TC
96 */
97 kstat_named_t encrypt_requests;
98 /*
8d9e7c8f 99 * Total bytes sent to QAT encryption engine.
cf637391
TC
100 */
101 kstat_named_t encrypt_total_in_bytes;
102 /*
8d9e7c8f 103 * Total bytes output from QAT encryption engine.
cf637391
TC
104 */
105 kstat_named_t encrypt_total_out_bytes;
106 /*
8d9e7c8f 107 * Number of jobs submitted to QAT decryption engine.
cf637391
TC
108 */
109 kstat_named_t decrypt_requests;
110 /*
8d9e7c8f 111 * Total bytes sent to QAT decryption engine.
cf637391
TC
112 */
113 kstat_named_t decrypt_total_in_bytes;
114 /*
8d9e7c8f 115 * Total bytes output from QAT decryption engine.
cf637391
TC
116 */
117 kstat_named_t decrypt_total_out_bytes;
118 /*
8d9e7c8f
TC
119 * Number of fails in the QAT encryption / decryption engine.
120 * Note: when a QAT error happens, it doesn't necessarily indicate a
121 * critical hardware issue. The encryption job will be transfered
122 * to the software implementation so the functionality of ZFS is
123 * not impacted.
cf637391
TC
124 */
125 kstat_named_t crypt_fails;
38742209
TC
126
127 /*
8d9e7c8f 128 * Number of jobs submitted to QAT checksum engine.
38742209
TC
129 */
130 kstat_named_t cksum_requests;
131 /*
8d9e7c8f 132 * Total bytes sent to QAT checksum engine.
38742209
TC
133 */
134 kstat_named_t cksum_total_in_bytes;
135 /*
8d9e7c8f
TC
136 * Number of fails in the QAT checksum engine.
137 * Note: when a QAT error happens, it doesn't necessarily indicate a
138 * critical hardware issue. The checksum job will be transfered to the
139 * software implementation so the functionality of ZFS is not impacted.
38742209
TC
140 */
141 kstat_named_t cksum_fails;
cf637391
TC
142} qat_stats_t;
143
144#define QAT_STAT_INCR(stat, val) \
145 atomic_add_64(&qat_stats.stat.value.ui64, (val))
146#define QAT_STAT_BUMP(stat) \
147 QAT_STAT_INCR(stat, 1)
148
149extern qat_stats_t qat_stats;
5090f727
CZ
150extern int zfs_qat_compress_disable;
151extern int zfs_qat_checksum_disable;
152extern int zfs_qat_encrypt_disable;
cf637391
TC
153
154/* inlined for performance */
155static inline struct page *
156qat_mem_to_page(void *addr)
157{
158 if (!is_vmalloc_addr(addr))
159 return (virt_to_page(addr));
160
161 return (vmalloc_to_page(addr));
162}
163
164CpaStatus qat_mem_alloc_contig(void **pp_mem_addr, Cpa32U size_bytes);
165void qat_mem_free_contig(void **pp_mem_addr);
166#define QAT_PHYS_CONTIG_ALLOC(pp_mem_addr, size_bytes) \
167 qat_mem_alloc_contig((void *)(pp_mem_addr), (size_bytes))
168#define QAT_PHYS_CONTIG_FREE(p_mem_addr) \
169 qat_mem_free_contig((void *)&(p_mem_addr))
170
171extern int qat_dc_init(void);
172extern void qat_dc_fini(void);
5090f727
CZ
173extern int qat_cy_init(void);
174extern void qat_cy_fini(void);
cf637391
TC
175extern int qat_init(void);
176extern void qat_fini(void);
177
32dce2da
TC
178/* fake CpaStatus used to indicate data was not compressible */
179#define CPA_STATUS_INCOMPRESSIBLE (-127)
180
cf637391
TC
181extern boolean_t qat_dc_use_accel(size_t s_len);
182extern boolean_t qat_crypt_use_accel(size_t s_len);
38742209 183extern boolean_t qat_checksum_use_accel(size_t s_len);
cf637391
TC
184extern int qat_compress(qat_compress_dir_t dir, char *src, int src_len,
185 char *dst, int dst_len, size_t *c_len);
186extern int qat_crypt(qat_encrypt_dir_t dir, uint8_t *src_buf, uint8_t *dst_buf,
187 uint8_t *aad_buf, uint32_t aad_len, uint8_t *iv_buf, uint8_t *digest_buf,
188 crypto_key_t *key, uint64_t crypt, uint32_t enc_len);
38742209
TC
189extern int qat_checksum(uint64_t cksum, uint8_t *buf, uint64_t size,
190 zio_cksum_t *zcp);
cf637391
TC
191#else
192#define CPA_STATUS_SUCCESS 0
32dce2da 193#define CPA_STATUS_INCOMPRESSIBLE (-127)
cf637391
TC
194#define qat_init()
195#define qat_fini()
196#define qat_dc_use_accel(s_len) 0
197#define qat_crypt_use_accel(s_len) 0
38742209 198#define qat_checksum_use_accel(s_len) 0
cf637391
TC
199#define qat_compress(dir, s, sl, d, dl, cl) 0
200#define qat_crypt(dir, s, d, a, al, i, db, k, c, el) 0
38742209 201#define qat_checksum(c, buf, s, z) 0
cf637391
TC
202#endif
203
204#endif /* _SYS_QAT_H */