^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Asynchronous Compression operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2016, Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Authors: Weigang Li <weigang.li@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Giovanni Cabiddu <giovanni.cabiddu@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef _CRYPTO_ACOMP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define _CRYPTO_ACOMP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define CRYPTO_ACOMP_ALLOC_OUTPUT 0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * struct acomp_req - asynchronous (de)compression request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * @base: Common attributes for asynchronous crypto requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * @src: Source Data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * @dst: Destination data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * @slen: Size of the input buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * @dlen: Size of the output buffer and number of bytes produced
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * @flags: Internal flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * @__ctx: Start of private context data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct acomp_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct crypto_async_request base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct scatterlist *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct scatterlist *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) unsigned int slen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) unsigned int dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) void *__ctx[] CRYPTO_MINALIGN_ATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * struct crypto_acomp - user-instantiated objects which encapsulate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * algorithms and core processing logic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * @compress: Function performs a compress operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * @decompress: Function performs a de-compress operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * @dst_free: Frees destination buffer if allocated inside the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * @reqsize: Context size for (de)compression requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @base: Common crypto API algorithm data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct crypto_acomp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) int (*compress)(struct acomp_req *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int (*decompress)(struct acomp_req *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) void (*dst_free)(struct scatterlist *dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned int reqsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct crypto_tfm base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * struct acomp_alg - asynchronous compression algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @compress: Function performs a compress operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @decompress: Function performs a de-compress operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * @dst_free: Frees destination buffer if allocated inside the algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @init: Initialize the cryptographic transformation object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * This function is used to initialize the cryptographic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * transformation object. This function is called only once at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * the instantiation time, right after the transformation context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * was allocated. In case the cryptographic hardware has some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * special requirements which need to be handled by software, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * function shall check for the precise requirement of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * transformation and put any software fallbacks in place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * @exit: Deinitialize the cryptographic transformation object. This is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * counterpart to @init, used to remove various changes set in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * @init.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * @reqsize: Context size for (de)compression requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * @base: Common crypto API algorithm data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct acomp_alg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int (*compress)(struct acomp_req *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int (*decompress)(struct acomp_req *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) void (*dst_free)(struct scatterlist *dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int (*init)(struct crypto_acomp *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) void (*exit)(struct crypto_acomp *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) unsigned int reqsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct crypto_alg base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * DOC: Asynchronous Compression API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * The Asynchronous Compression API is used with the algorithms of type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * CRYPTO_ALG_TYPE_ACOMPRESS (listed as type "acomp" in /proc/crypto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * crypto_alloc_acomp() -- allocate ACOMPRESS tfm handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * compression algorithm e.g. "deflate"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * @type: specifies the type of the algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * @mask: specifies the mask for the algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * Allocate a handle for a compression algorithm. The returned struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * crypto_acomp is the handle that is required for any subsequent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * API invocation for the compression operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * Return: allocated handle in case of success; IS_ERR() is true in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * of an error, PTR_ERR() returns the error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct crypto_acomp *crypto_alloc_acomp(const char *alg_name, u32 type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) u32 mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * crypto_alloc_acomp_node() -- allocate ACOMPRESS tfm handle with desired NUMA node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * compression algorithm e.g. "deflate"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * @type: specifies the type of the algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * @mask: specifies the mask for the algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * @node: specifies the NUMA node the ZIP hardware belongs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * Allocate a handle for a compression algorithm. Drivers should try to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * (de)compressors on the specified NUMA node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * The returned struct crypto_acomp is the handle that is required for any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * subsequent API invocation for the compression operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * Return: allocated handle in case of success; IS_ERR() is true in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * of an error, PTR_ERR() returns the error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct crypto_acomp *crypto_alloc_acomp_node(const char *alg_name, u32 type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u32 mask, int node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static inline struct crypto_tfm *crypto_acomp_tfm(struct crypto_acomp *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return &tfm->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static inline struct acomp_alg *__crypto_acomp_alg(struct crypto_alg *alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return container_of(alg, struct acomp_alg, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static inline struct crypto_acomp *__crypto_acomp_tfm(struct crypto_tfm *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return container_of(tfm, struct crypto_acomp, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static inline struct acomp_alg *crypto_acomp_alg(struct crypto_acomp *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return __crypto_acomp_alg(crypto_acomp_tfm(tfm)->__crt_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static inline unsigned int crypto_acomp_reqsize(struct crypto_acomp *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return tfm->reqsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static inline void acomp_request_set_tfm(struct acomp_req *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct crypto_acomp *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) req->base.tfm = crypto_acomp_tfm(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static inline struct crypto_acomp *crypto_acomp_reqtfm(struct acomp_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return __crypto_acomp_tfm(req->base.tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * crypto_free_acomp() -- free ACOMPRESS tfm handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acomp()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * If @tfm is a NULL or error pointer, this function does nothing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static inline void crypto_free_acomp(struct crypto_acomp *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) crypto_destroy_tfm(tfm, crypto_acomp_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static inline int crypto_has_acomp(const char *alg_name, u32 type, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) type &= ~CRYPTO_ALG_TYPE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) type |= CRYPTO_ALG_TYPE_ACOMPRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) mask |= CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return crypto_has_alg(alg_name, type, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * acomp_request_alloc() -- allocates asynchronous (de)compression request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acomp()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * Return: allocated handle in case of success or NULL in case of an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct acomp_req *acomp_request_alloc(struct crypto_acomp *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * acomp_request_free() -- zeroize and free asynchronous (de)compression
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * request as well as the output buffer if allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * inside the algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * @req: request to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) void acomp_request_free(struct acomp_req *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * acomp_request_set_callback() -- Sets an asynchronous callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * Callback will be called when an asynchronous operation on a given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * request is finished.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * @req: request that the callback will be set for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * @flgs: specify for instance if the operation may backlog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * @cmlp: callback which will be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * @data: private data used by the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static inline void acomp_request_set_callback(struct acomp_req *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) u32 flgs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) crypto_completion_t cmpl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) req->base.complete = cmpl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) req->base.data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) req->base.flags = flgs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * acomp_request_set_params() -- Sets request parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * Sets parameters required by an acomp operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * @req: asynchronous compress request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * @src: pointer to input buffer scatterlist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * @dst: pointer to output buffer scatterlist. If this is NULL, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * acomp layer will allocate the output memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * @slen: size of the input buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * @dlen: size of the output buffer. If dst is NULL, this can be used by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * the user to specify the maximum amount of memory to allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static inline void acomp_request_set_params(struct acomp_req *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct scatterlist *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct scatterlist *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) unsigned int slen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) unsigned int dlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) req->src = src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) req->dst = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) req->slen = slen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) req->dlen = dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (!req->dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) req->flags |= CRYPTO_ACOMP_ALLOC_OUTPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * crypto_acomp_compress() -- Invoke asynchronous compress operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * Function invokes the asynchronous compress operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * @req: asynchronous compress request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * Return: zero on success; error code in case of error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static inline int crypto_acomp_compress(struct acomp_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct crypto_alg *alg = tfm->base.__crt_alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) unsigned int slen = req->slen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) crypto_stats_get(alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ret = tfm->compress(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) crypto_stats_compress(slen, ret, alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * crypto_acomp_decompress() -- Invoke asynchronous decompress operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * Function invokes the asynchronous decompress operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * @req: asynchronous compress request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * Return: zero on success; error code in case of error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static inline int crypto_acomp_decompress(struct acomp_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct crypto_alg *alg = tfm->base.__crt_alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) unsigned int slen = req->slen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) crypto_stats_get(alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) ret = tfm->decompress(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) crypto_stats_decompress(slen, ret, alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) #endif