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 */ 60 static inline void *acomp_request_ctx(struct acomp_req *req) 61 { 62 return req->__ctx; 63 } 64 65 static inline void *acomp_tfm_ctx(struct crypto_acomp *tfm) 66 { 67 return tfm->base.__crt_ctx; 68 } 69 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 101 static inline bool acomp_request_chained(struct acomp_req *req) 102 { 103 return crypto_request_chained(&req->base); 104 } 105 106 static inline bool acomp_request_src_isvirt(struct acomp_req *req) 107 { 108 return req->base.flags & CRYPTO_ACOMP_REQ_SRC_VIRT; 109 } 110 111 static inline bool acomp_request_dst_isvirt(struct acomp_req *req) 112 { 113 return req->base.flags & CRYPTO_ACOMP_REQ_DST_VIRT; 114 } 115 116 static inline bool acomp_request_isvirt(struct acomp_req *req) 117 { 118 return req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT | 119 CRYPTO_ACOMP_REQ_DST_VIRT); 120 } 121 122 static inline bool acomp_request_src_isnondma(struct acomp_req *req) 123 { 124 return req->base.flags & CRYPTO_ACOMP_REQ_SRC_NONDMA; 125 } 126 127 static inline bool acomp_request_dst_isnondma(struct acomp_req *req) 128 { 129 return req->base.flags & CRYPTO_ACOMP_REQ_DST_NONDMA; 130 } 131 132 static inline bool acomp_request_isnondma(struct acomp_req *req) 133 { 134 return req->base.flags & (CRYPTO_ACOMP_REQ_SRC_NONDMA | 135 CRYPTO_ACOMP_REQ_DST_NONDMA); 136 } 137 138 static inline bool crypto_acomp_req_chain(struct crypto_acomp *tfm) 139 { 140 return crypto_tfm_req_chain(&tfm->base); 141 } 142 143 #endif 144