1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Asynchronous Compression operations
4 *
5 * Copyright (c) 2016, Intel Corporation
6 * Authors: Weigang Li <weigang.li@intel.com>
7 * Giovanni Cabiddu <giovanni.cabiddu@intel.com>
8 */
9 #ifndef _CRYPTO_ACOMP_INT_H
10 #define _CRYPTO_ACOMP_INT_H
11
12 #include <crypto/acompress.h>
13 #include <crypto/algapi.h>
14
15 #define ACOMP_REQUEST_ON_STACK(name, tfm) \
16 char __##name##_req[sizeof(struct acomp_req) + \
17 MAX_SYNC_COMP_REQSIZE] CRYPTO_MINALIGN_ATTR; \
18 struct acomp_req *name = acomp_request_on_stack_init( \
19 __##name##_req, (tfm), 0, true)
20
21 /**
22 * struct acomp_alg - asynchronous compression algorithm
23 *
24 * @compress: Function performs a compress operation
25 * @decompress: Function performs a de-compress operation
26 * @init: Initialize the cryptographic transformation object.
27 * This function is used to initialize the cryptographic
28 * transformation object. This function is called only once at
29 * the instantiation time, right after the transformation context
30 * was allocated. In case the cryptographic hardware has some
31 * special requirements which need to be handled by software, this
32 * function shall check for the precise requirement of the
33 * transformation and put any software fallbacks in place.
34 * @exit: Deinitialize the cryptographic transformation object. This is a
35 * counterpart to @init, used to remove various changes set in
36 * @init.
37 *
38 * @reqsize: Context size for (de)compression requests
39 * @base: Common crypto API algorithm data structure
40 * @stream: Per-cpu memory for algorithm
41 * @calg: Cmonn algorithm data structure shared with scomp
42 */
43 struct acomp_alg {
44 int (*compress)(struct acomp_req *req);
45 int (*decompress)(struct acomp_req *req);
46 int (*init)(struct crypto_acomp *tfm);
47 void (*exit)(struct crypto_acomp *tfm);
48
49 unsigned int reqsize;
50
51 union {
52 struct COMP_ALG_COMMON;
53 struct comp_alg_common calg;
54 };
55 };
56
57 /*
58 * Transform internal helpers.
59 */
acomp_request_ctx(struct acomp_req * req)60 static inline void *acomp_request_ctx(struct acomp_req *req)
61 {
62 return req->__ctx;
63 }
64
acomp_tfm_ctx(struct crypto_acomp * tfm)65 static inline void *acomp_tfm_ctx(struct crypto_acomp *tfm)
66 {
67 return tfm->base.__crt_ctx;
68 }
69
acomp_request_complete(struct acomp_req * req,int err)70 static inline void acomp_request_complete(struct acomp_req *req,
71 int err)
72 {
73 crypto_request_complete(&req->base, err);
74 }
75
76 /**
77 * crypto_register_acomp() -- Register asynchronous compression algorithm
78 *
79 * Function registers an implementation of an asynchronous
80 * compression algorithm
81 *
82 * @alg: algorithm definition
83 *
84 * Return: zero on success; error code in case of error
85 */
86 int crypto_register_acomp(struct acomp_alg *alg);
87
88 /**
89 * crypto_unregister_acomp() -- Unregister asynchronous compression algorithm
90 *
91 * Function unregisters an implementation of an asynchronous
92 * compression algorithm
93 *
94 * @alg: algorithm definition
95 */
96 void crypto_unregister_acomp(struct acomp_alg *alg);
97
98 int crypto_register_acomps(struct acomp_alg *algs, int count);
99 void crypto_unregister_acomps(struct acomp_alg *algs, int count);
100
acomp_request_chained(struct acomp_req * req)101 static inline bool acomp_request_chained(struct acomp_req *req)
102 {
103 return crypto_request_chained(&req->base);
104 }
105
acomp_request_issg(struct acomp_req * req)106 static inline bool acomp_request_issg(struct acomp_req *req)
107 {
108 return !(req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT |
109 CRYPTO_ACOMP_REQ_DST_VIRT |
110 CRYPTO_ACOMP_REQ_SRC_FOLIO |
111 CRYPTO_ACOMP_REQ_DST_FOLIO));
112 }
113
acomp_request_src_isvirt(struct acomp_req * req)114 static inline bool acomp_request_src_isvirt(struct acomp_req *req)
115 {
116 return req->base.flags & CRYPTO_ACOMP_REQ_SRC_VIRT;
117 }
118
acomp_request_dst_isvirt(struct acomp_req * req)119 static inline bool acomp_request_dst_isvirt(struct acomp_req *req)
120 {
121 return req->base.flags & CRYPTO_ACOMP_REQ_DST_VIRT;
122 }
123
acomp_request_isvirt(struct acomp_req * req)124 static inline bool acomp_request_isvirt(struct acomp_req *req)
125 {
126 return req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT |
127 CRYPTO_ACOMP_REQ_DST_VIRT);
128 }
129
acomp_request_src_isnondma(struct acomp_req * req)130 static inline bool acomp_request_src_isnondma(struct acomp_req *req)
131 {
132 return req->base.flags & CRYPTO_ACOMP_REQ_SRC_NONDMA;
133 }
134
acomp_request_dst_isnondma(struct acomp_req * req)135 static inline bool acomp_request_dst_isnondma(struct acomp_req *req)
136 {
137 return req->base.flags & CRYPTO_ACOMP_REQ_DST_NONDMA;
138 }
139
acomp_request_isnondma(struct acomp_req * req)140 static inline bool acomp_request_isnondma(struct acomp_req *req)
141 {
142 return req->base.flags & (CRYPTO_ACOMP_REQ_SRC_NONDMA |
143 CRYPTO_ACOMP_REQ_DST_NONDMA);
144 }
145
acomp_request_src_isfolio(struct acomp_req * req)146 static inline bool acomp_request_src_isfolio(struct acomp_req *req)
147 {
148 return req->base.flags & CRYPTO_ACOMP_REQ_SRC_FOLIO;
149 }
150
acomp_request_dst_isfolio(struct acomp_req * req)151 static inline bool acomp_request_dst_isfolio(struct acomp_req *req)
152 {
153 return req->base.flags & CRYPTO_ACOMP_REQ_DST_FOLIO;
154 }
155
crypto_acomp_req_chain(struct crypto_acomp * tfm)156 static inline bool crypto_acomp_req_chain(struct crypto_acomp *tfm)
157 {
158 return crypto_tfm_req_chain(&tfm->base);
159 }
160
161 #endif
162