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 /** 16 * struct acomp_alg - asynchronous compression algorithm 17 * 18 * @compress: Function performs a compress operation 19 * @decompress: Function performs a de-compress operation 20 * @dst_free: Frees destination buffer if allocated inside the algorithm 21 * @init: Initialize the cryptographic transformation object. 22 * This function is used to initialize the cryptographic 23 * transformation object. This function is called only once at 24 * the instantiation time, right after the transformation context 25 * was allocated. In case the cryptographic hardware has some 26 * special requirements which need to be handled by software, this 27 * function shall check for the precise requirement of the 28 * transformation and put any software fallbacks in place. 29 * @exit: Deinitialize the cryptographic transformation object. This is a 30 * counterpart to @init, used to remove various changes set in 31 * @init. 32 * 33 * @reqsize: Context size for (de)compression requests 34 * @base: Common crypto API algorithm data structure 35 * @stream: Per-cpu memory for algorithm 36 * @calg: Cmonn algorithm data structure shared with scomp 37 */ 38 struct acomp_alg { 39 int (*compress)(struct acomp_req *req); 40 int (*decompress)(struct acomp_req *req); 41 void (*dst_free)(struct scatterlist *dst); 42 int (*init)(struct crypto_acomp *tfm); 43 void (*exit)(struct crypto_acomp *tfm); 44 45 unsigned int reqsize; 46 47 union { 48 struct COMP_ALG_COMMON; 49 struct comp_alg_common calg; 50 }; 51 }; 52 53 /* 54 * Transform internal helpers. 55 */ 56 static inline void *acomp_request_ctx(struct acomp_req *req) 57 { 58 return req->__ctx; 59 } 60 61 static inline void *acomp_tfm_ctx(struct crypto_acomp *tfm) 62 { 63 return tfm->base.__crt_ctx; 64 } 65 66 static inline void acomp_request_complete(struct acomp_req *req, 67 int err) 68 { 69 crypto_request_complete(&req->base, err); 70 } 71 72 /** 73 * crypto_register_acomp() -- Register asynchronous compression algorithm 74 * 75 * Function registers an implementation of an asynchronous 76 * compression algorithm 77 * 78 * @alg: algorithm definition 79 * 80 * Return: zero on success; error code in case of error 81 */ 82 int crypto_register_acomp(struct acomp_alg *alg); 83 84 /** 85 * crypto_unregister_acomp() -- Unregister asynchronous compression algorithm 86 * 87 * Function unregisters an implementation of an asynchronous 88 * compression algorithm 89 * 90 * @alg: algorithm definition 91 */ 92 void crypto_unregister_acomp(struct acomp_alg *alg); 93 94 int crypto_register_acomps(struct acomp_alg *algs, int count); 95 void crypto_unregister_acomps(struct acomp_alg *algs, int count); 96 97 static inline bool acomp_request_chained(struct acomp_req *req) 98 { 99 return crypto_request_chained(&req->base); 100 } 101 102 static inline bool acomp_request_src_isvirt(struct acomp_req *req) 103 { 104 return req->base.flags & CRYPTO_ACOMP_REQ_SRC_VIRT; 105 } 106 107 static inline bool acomp_request_dst_isvirt(struct acomp_req *req) 108 { 109 return req->base.flags & CRYPTO_ACOMP_REQ_DST_VIRT; 110 } 111 112 static inline bool acomp_request_isvirt(struct acomp_req *req) 113 { 114 return req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT | 115 CRYPTO_ACOMP_REQ_DST_VIRT); 116 } 117 118 static inline bool acomp_request_src_isnondma(struct acomp_req *req) 119 { 120 return req->base.flags & CRYPTO_ACOMP_REQ_SRC_NONDMA; 121 } 122 123 static inline bool acomp_request_dst_isnondma(struct acomp_req *req) 124 { 125 return req->base.flags & CRYPTO_ACOMP_REQ_DST_NONDMA; 126 } 127 128 static inline bool acomp_request_isnondma(struct acomp_req *req) 129 { 130 return req->base.flags & (CRYPTO_ACOMP_REQ_SRC_NONDMA | 131 CRYPTO_ACOMP_REQ_DST_NONDMA); 132 } 133 134 static inline bool crypto_acomp_req_chain(struct crypto_acomp *tfm) 135 { 136 return crypto_tfm_req_chain(&tfm->base); 137 } 138 139 #endif 140