]> git.proxmox.com Git - mirror_zfs.git/blob - module/zfs/qat.h
QAT support for AES-GCM
[mirror_zfs.git] / module / zfs / qat.h
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
25 typedef enum qat_compress_dir {
26 QAT_DECOMPRESS = 0,
27 QAT_COMPRESS = 1,
28 } qat_compress_dir_t;
29
30 typedef 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 /*
49 * The minimal and maximal buffer size, which are not restricted
50 * in the QAT hardware, but with the input buffer size between 4KB
51 * and 128KB, the hardware can provide the optimal performance.
52 */
53 #define QAT_MIN_BUF_SIZE (4*1024)
54 #define QAT_MAX_BUF_SIZE (128*1024)
55
56 /*
57 * Used for qat kstat.
58 */
59 typedef struct qat_stats {
60 /*
61 * Number of jobs submitted to qat compression engine.
62 */
63 kstat_named_t comp_requests;
64 /*
65 * Total bytes sent to qat compression engine.
66 */
67 kstat_named_t comp_total_in_bytes;
68 /*
69 * Total bytes output from qat compression engine.
70 */
71 kstat_named_t comp_total_out_bytes;
72 /*
73 * Number of jobs submitted to qat de-compression engine.
74 */
75 kstat_named_t decomp_requests;
76 /*
77 * Total bytes sent to qat de-compression engine.
78 */
79 kstat_named_t decomp_total_in_bytes;
80 /*
81 * Total bytes output from qat de-compression engine.
82 */
83 kstat_named_t decomp_total_out_bytes;
84 /*
85 * Number of fails in the qat compression / decompression engine.
86 * Note: when qat fail happens, it doesn't mean a critical hardware
87 * issue. Sometimes it is because the output buffer is not big enough.
88 * The compression job will be transfered to gzip software
89 * implementation, so the functionality of ZFS is not impacted.
90 */
91 kstat_named_t dc_fails;
92
93 /*
94 * Number of jobs submitted to qat encryption engine.
95 */
96 kstat_named_t encrypt_requests;
97 /*
98 * Total bytes sent to qat encryption engine.
99 */
100 kstat_named_t encrypt_total_in_bytes;
101 /*
102 * Total bytes output from qat encryption engine.
103 */
104 kstat_named_t encrypt_total_out_bytes;
105 /*
106 * Number of jobs submitted to qat decryption engine.
107 */
108 kstat_named_t decrypt_requests;
109 /*
110 * Total bytes sent to qat decryption engine.
111 */
112 kstat_named_t decrypt_total_in_bytes;
113 /*
114 * Total bytes output from qat decryption engine.
115 */
116 kstat_named_t decrypt_total_out_bytes;
117 /*
118 * Number of fails in the qat encryption / decryption engine.
119 * Note: when qat fail happens, it doesn't mean a critical hardware
120 * issue. Sometimes it is because the output buffer is not big enough.
121 * The encryption job will be transfered to the software implementation,
122 * so the functionality of ZFS is not impacted.
123 */
124 kstat_named_t crypt_fails;
125 } qat_stats_t;
126
127 #define QAT_STAT_INCR(stat, val) \
128 atomic_add_64(&qat_stats.stat.value.ui64, (val))
129 #define QAT_STAT_BUMP(stat) \
130 QAT_STAT_INCR(stat, 1)
131
132 extern qat_stats_t qat_stats;
133 extern int zfs_qat_disable;
134
135 /* inlined for performance */
136 static inline struct page *
137 qat_mem_to_page(void *addr)
138 {
139 if (!is_vmalloc_addr(addr))
140 return (virt_to_page(addr));
141
142 return (vmalloc_to_page(addr));
143 }
144
145 CpaStatus qat_mem_alloc_contig(void **pp_mem_addr, Cpa32U size_bytes);
146 void qat_mem_free_contig(void **pp_mem_addr);
147 #define QAT_PHYS_CONTIG_ALLOC(pp_mem_addr, size_bytes) \
148 qat_mem_alloc_contig((void *)(pp_mem_addr), (size_bytes))
149 #define QAT_PHYS_CONTIG_FREE(p_mem_addr) \
150 qat_mem_free_contig((void *)&(p_mem_addr))
151
152 extern int qat_dc_init(void);
153 extern void qat_dc_fini(void);
154 extern int qat_crypt_init(void);
155 extern void qat_crypt_fini(void);
156 extern int qat_init(void);
157 extern void qat_fini(void);
158
159 extern boolean_t qat_dc_use_accel(size_t s_len);
160 extern boolean_t qat_crypt_use_accel(size_t s_len);
161 extern int qat_compress(qat_compress_dir_t dir, char *src, int src_len,
162 char *dst, int dst_len, size_t *c_len);
163 extern int qat_crypt(qat_encrypt_dir_t dir, uint8_t *src_buf, uint8_t *dst_buf,
164 uint8_t *aad_buf, uint32_t aad_len, uint8_t *iv_buf, uint8_t *digest_buf,
165 crypto_key_t *key, uint64_t crypt, uint32_t enc_len);
166 #else
167 #define CPA_STATUS_SUCCESS 0
168 #define qat_init()
169 #define qat_fini()
170 #define qat_dc_use_accel(s_len) 0
171 #define qat_crypt_use_accel(s_len) 0
172 #define qat_compress(dir, s, sl, d, dl, cl) 0
173 #define qat_crypt(dir, s, d, a, al, i, db, k, c, el) 0
174 #endif
175
176 #endif /* _SYS_QAT_H */