mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chenghai Huang <huangchenghai2@huawei.com>
To: <herbert@gondor.apana.org.au>, <davem@davemloft.net>
Cc: <linux-kernel@vger.kernel.org>, <linux-crypto@vger.kernel.org>,
	<liulongfang@huawei.com>, <qianweili@huawei.com>,
	<wangzhou1@hisilicon.com>, <linwenkai6@hisilicon.com>
Subject: [PATCH 2/4] crypto: engine - add acomp support
Date: Mon, 9 Nov 2026 15:35:54 +0800	[thread overview]
Message-ID: <20261109073556.2517351-3-huangchenghai2@huawei.com> (raw)
In-Reply-To: <20261109073556.2517351-1-huangchenghai2@huawei.com>

Add support for asynchronous compression (acomp) algorithms to the
crypto engine framework: transfer/finalize helpers plus an
acomp_engine_alg registration interface, mirroring the existing
akcipher and kpp support.

As engine.h needs to embed struct acomp_alg by value, move it from
include/crypto/internal/acompress.h to include/crypto/acompress.h.
The internal header still provides it through the existing include.

Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
 crypto/crypto_engine.c              | 42 +++++++++++++++++++++++++++++
 include/crypto/acompress.h          | 33 +++++++++++++++++++++++
 include/crypto/engine.h             | 13 +++++++++
 include/crypto/internal/acompress.h | 33 -----------------------
 4 files changed, 88 insertions(+), 33 deletions(-)

diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c
index 5b669038acb4..2a0740d9dd63 100644
--- a/crypto/crypto_engine.c
+++ b/crypto/crypto_engine.c
@@ -7,6 +7,7 @@
  * Author: Baolin Wang <baolin.wang@linaro.org>
  */
 
+#include <crypto/internal/acompress.h>
 #include <crypto/internal/aead.h>
 #include <crypto/internal/akcipher.h>
 #include <crypto/internal/engine.h>
@@ -220,6 +221,19 @@ static int crypto_transfer_request_to_engine(struct crypto_engine *engine,
 	return crypto_transfer_request(engine, req, true);
 }
 
+/**
+ * crypto_transfer_acomp_request_to_engine - transfer one acomp_request
+ * to list into the engine queue
+ * @engine: the hardware engine
+ * @req: the request need to be listed into the engine queue
+ */
+int crypto_transfer_acomp_request_to_engine(struct crypto_engine *engine,
+					    struct acomp_req *req)
+{
+	return crypto_transfer_request_to_engine(engine, &req->base);
+}
+EXPORT_SYMBOL_GPL(crypto_transfer_acomp_request_to_engine);
+
 /**
  * crypto_transfer_aead_request_to_engine - transfer one aead_request
  * to list into the engine queue
@@ -285,6 +299,20 @@ int crypto_transfer_skcipher_request_to_engine(struct crypto_engine *engine,
 }
 EXPORT_SYMBOL_GPL(crypto_transfer_skcipher_request_to_engine);
 
+/**
+ * crypto_finalize_acomp_request - finalize one acomp_request if
+ * the request is done
+ * @engine: the hardware engine
+ * @req: the request need to be finalized
+ * @err: error number
+ */
+void crypto_finalize_acomp_request(struct crypto_engine *engine,
+				   struct acomp_req *req, int err)
+{
+	return crypto_finalize_request(engine, &req->base, err);
+}
+EXPORT_SYMBOL_GPL(crypto_finalize_acomp_request);
+
 /**
  * crypto_finalize_aead_request - finalize one aead_request if
  * the request is done
@@ -504,6 +532,20 @@ void crypto_engine_exit(struct crypto_engine *engine)
 }
 EXPORT_SYMBOL_GPL(crypto_engine_exit);
 
+int crypto_engine_register_acomp(struct acomp_engine_alg *alg)
+{
+	if (!alg->op.do_one_request)
+		return -EINVAL;
+	return crypto_register_acomp(&alg->base);
+}
+EXPORT_SYMBOL_GPL(crypto_engine_register_acomp);
+
+void crypto_engine_unregister_acomp(struct acomp_engine_alg *alg)
+{
+	crypto_unregister_acomp(&alg->base);
+}
+EXPORT_SYMBOL_GPL(crypto_engine_unregister_acomp);
+
 int crypto_engine_register_aead(struct aead_engine_alg *alg)
 {
 	if (!alg->op.do_one_request)
diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h
index 5d5358dfab73..0809fa35490a 100644
--- a/include/crypto/acompress.h
+++ b/include/crypto/acompress.h
@@ -122,6 +122,39 @@ struct crypto_acomp {
 }
 struct comp_alg_common COMP_ALG_COMMON;
 
+/**
+ * struct acomp_alg - asynchronous compression algorithm
+ *
+ * @compress:	Function performs a compress operation
+ * @decompress:	Function performs a de-compress operation
+ * @init:	Initialize the cryptographic transformation object.
+ *		This function is used to initialize the cryptographic
+ *		transformation object. This function is called only once at
+ *		the instantiation time, right after the transformation context
+ *		was allocated. In case the cryptographic hardware has some
+ *		special requirements which need to be handled by software, this
+ *		function shall check for the precise requirement of the
+ *		transformation and put any software fallbacks in place.
+ * @exit:	Deinitialize the cryptographic transformation object. This is a
+ *		counterpart to @init, used to remove various changes set in
+ *		@init.
+ *
+ * @base:	Common crypto API algorithm data structure
+ * @calg:	Common algorithm data structure shared with scomp
+ * @COMP_ALG_COMMON: see struct comp_alg_common
+ */
+struct acomp_alg {
+	int (*compress)(struct acomp_req *req);
+	int (*decompress)(struct acomp_req *req);
+	int (*init)(struct crypto_acomp *tfm);
+	void (*exit)(struct crypto_acomp *tfm);
+
+	union {
+		struct COMP_ALG_COMMON;
+		struct comp_alg_common calg;
+	};
+};
+
 /**
  * DOC: Asynchronous Compression API
  *
diff --git a/include/crypto/engine.h b/include/crypto/engine.h
index 2e60344437da..2b4e3d0e43ed 100644
--- a/include/crypto/engine.h
+++ b/include/crypto/engine.h
@@ -7,6 +7,7 @@
 #ifndef _CRYPTO_ENGINE_H
 #define _CRYPTO_ENGINE_H
 
+#include <crypto/acompress.h>
 #include <crypto/aead.h>
 #include <crypto/akcipher.h>
 #include <crypto/hash.h>
@@ -26,6 +27,11 @@ struct crypto_engine_op {
 			      void *areq);
 };
 
+struct acomp_engine_alg {
+	struct acomp_alg base;
+	struct crypto_engine_op op;
+};
+
 struct aead_engine_alg {
 	struct aead_alg base;
 	struct crypto_engine_op op;
@@ -51,6 +57,8 @@ struct skcipher_engine_alg {
 	struct crypto_engine_op op;
 };
 
+int crypto_transfer_acomp_request_to_engine(struct crypto_engine *engine,
+					    struct acomp_req *req);
 int crypto_transfer_aead_request_to_engine(struct crypto_engine *engine,
 					   struct aead_request *req);
 int crypto_transfer_akcipher_request_to_engine(struct crypto_engine *engine,
@@ -61,6 +69,8 @@ int crypto_transfer_kpp_request_to_engine(struct crypto_engine *engine,
 					  struct kpp_request *req);
 int crypto_transfer_skcipher_request_to_engine(struct crypto_engine *engine,
 					       struct skcipher_request *req);
+void crypto_finalize_acomp_request(struct crypto_engine *engine,
+				   struct acomp_req *req, int err);
 void crypto_finalize_aead_request(struct crypto_engine *engine,
 				  struct aead_request *req, int err);
 void crypto_finalize_akcipher_request(struct crypto_engine *engine,
@@ -79,6 +89,9 @@ struct crypto_engine *crypto_engine_alloc_init_and_set(struct device *dev,
 						       bool rt, int qlen);
 void crypto_engine_exit(struct crypto_engine *engine);
 
+int crypto_engine_register_acomp(struct acomp_engine_alg *alg);
+void crypto_engine_unregister_acomp(struct acomp_engine_alg *alg);
+
 int crypto_engine_register_aead(struct aead_engine_alg *alg);
 void crypto_engine_unregister_aead(struct aead_engine_alg *alg);
 int crypto_engine_register_aeads(struct aead_engine_alg *algs, int count);
diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h
index 9cd37df32dc4..75580e007c0c 100644
--- a/include/crypto/internal/acompress.h
+++ b/include/crypto/internal/acompress.h
@@ -23,39 +23,6 @@
         struct acomp_req *name = acomp_fbreq_on_stack_init( \
                 __##name##_req, (req))
 
-/**
- * struct acomp_alg - asynchronous compression algorithm
- *
- * @compress:	Function performs a compress operation
- * @decompress:	Function performs a de-compress operation
- * @init:	Initialize the cryptographic transformation object.
- *		This function is used to initialize the cryptographic
- *		transformation object. This function is called only once at
- *		the instantiation time, right after the transformation context
- *		was allocated. In case the cryptographic hardware has some
- *		special requirements which need to be handled by software, this
- *		function shall check for the precise requirement of the
- *		transformation and put any software fallbacks in place.
- * @exit:	Deinitialize the cryptographic transformation object. This is a
- *		counterpart to @init, used to remove various changes set in
- *		@init.
- *
- * @base:	Common crypto API algorithm data structure
- * @calg:	Cmonn algorithm data structure shared with scomp
- * @COMP_ALG_COMMON: see struct comp_alg_common
- */
-struct acomp_alg {
-	int (*compress)(struct acomp_req *req);
-	int (*decompress)(struct acomp_req *req);
-	int (*init)(struct crypto_acomp *tfm);
-	void (*exit)(struct crypto_acomp *tfm);
-
-	union {
-		struct COMP_ALG_COMMON;
-		struct comp_alg_common calg;
-	};
-};
-
 struct crypto_acomp_stream {
 	spinlock_t lock;
 	void *ctx;
-- 
2.43.0


  parent reply	other threads:[~2026-11-09  7:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09  7:35 [PATCH 0/4] crypto: engine - add acomp support and adapt Hisilicon HPRE and ZIP drivers Chenghai Huang
2026-11-09  7:35 ` [PATCH 1/4] crypto: engine - clear busy and recheck running in the retry pump loop Chenghai Huang
2026-11-09  7:35 ` Chenghai Huang [this message]
2026-11-09  7:35 ` [PATCH 3/4] crypto: hisilicon/hpre - use crypto engine framework Chenghai Huang
2026-11-09  7:35 ` [PATCH 4/4] crypto: hisilicon/zip - adapt to use crypto engine Chenghai Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261109073556.2517351-3-huangchenghai2@huawei.com \
    --to=huangchenghai2@huawei.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linwenkai6@hisilicon.com \
    --cc=liulongfang@huawei.com \
    --cc=qianweili@huawei.com \
    --cc=wangzhou1@hisilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®