Acc
Threads by month
- ----- 2026 -----
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- 1 participants
- 411 discussions
From: Weili Qian <qianweili(a)huawei.com>
The internal asynchronous polling interface is not
used in any scenario, remove it.
Upstream: YES
Feature or Bugfix:Bugfix
AR:AR20230706877890
DTS:DTS2026042322013
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
include/wd_aead.h | 3 +-
include/wd_cipher.h | 3 +-
include/wd_comp.h | 3 +-
include/wd_digest.h | 3 +-
include/wd_ecc.h | 3 +-
include/wd_rsa.h | 3 +-
include/wd_util.h | 37 ----
wd_aead.c | 24 +--
wd_cipher.c | 24 +--
wd_comp.c | 28 +--
wd_dh.c | 24 +--
wd_digest.c | 24 +--
wd_ecc.c | 24 +--
wd_rsa.c | 24 +--
wd_util.c | 418 +-------------------------------------------
15 files changed, 70 insertions(+), 575 deletions(-)
diff --git a/include/wd_aead.h b/include/wd_aead.h
index 4b5095f..3585c86 100644
--- a/include/wd_aead.h
+++ b/include/wd_aead.h
@@ -254,7 +254,8 @@ void wd_aead_ctx_num_uninit(void);
* @type: operation type.
* @mode: 0: sync mode, 1: async mode
* @num: return ctx num.
- * @is_enable return enable inner poll flag.
+ * @is_enable: return enable inner poll flag, inner poll is not
+ * supported, and is_enable will always be 0.
*
* If the current algorithm library does not require the type parameter,
* the type parameter is invalid. The function returns 0 to indicate that
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
index a6f8be1..383d315 100644
--- a/include/wd_cipher.h
+++ b/include/wd_cipher.h
@@ -218,7 +218,8 @@ void wd_cipher_ctx_num_uninit(void);
* @type: operation type.
* @mode: 0: sync mode, 1: async mode
* @num: return ctx num.
- * @is_enable return enable inner poll flag.
+ * @is_enable: return enable inner poll flag, inner poll is not
+ * supported, and is_enable will always be 0.
*/
int wd_cipher_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
diff --git a/include/wd_comp.h b/include/wd_comp.h
index 8579f93..890799a 100644
--- a/include/wd_comp.h
+++ b/include/wd_comp.h
@@ -252,7 +252,8 @@ void wd_comp_ctx_num_uninit(void);
* @type: operation type.
* @mode: 0: sync mode, 1: async mode
* @num: return ctx num.
- * @is_enable return enable inner poll flag.
+ * @is_enable: return enable inner poll flag, inner poll is not
+ * supported, and is_enable will always be 0.
*
* If the current algorithm library does not require the type parameter,
* the type parameter is invalid. The function returns 0 to indicate that
diff --git a/include/wd_digest.h b/include/wd_digest.h
index 42a95db..410c7f9 100644
--- a/include/wd_digest.h
+++ b/include/wd_digest.h
@@ -278,7 +278,8 @@ void wd_digest_ctx_num_uninit(void);
* @type: operation type.
* @mode: 0: sync mode, 1: async mode
* @num: return ctx num.
- * @is_enable return enable inner poll flag.
+ * @is_enable: return enable inner poll flag, inner poll is not
+ * supported, and is_enable will always be 0.
*/
int wd_digest_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
diff --git a/include/wd_ecc.h b/include/wd_ecc.h
index 18c1c0d..d868951 100644
--- a/include/wd_ecc.h
+++ b/include/wd_ecc.h
@@ -548,7 +548,8 @@ void wd_ecc_ctx_num_uninit(void);
* @type: operation type.
* @mode: 0: sync mode, 1: async mode
* @num: return ctx num.
- * @is_enable return enable inner poll flag.
+ * @is_enable: return enable inner poll flag, inner poll is not
+ * supported, and is_enable will always be 0.
*/
int wd_ecc_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
diff --git a/include/wd_rsa.h b/include/wd_rsa.h
index 9c91432..b0ead0a 100644
--- a/include/wd_rsa.h
+++ b/include/wd_rsa.h
@@ -239,7 +239,8 @@ void wd_rsa_ctx_num_uninit(void);
* @type: operation type.
* @mode: 0: sync mode, 1: async mode
* @num: return ctx num.
- * @is_enable return enable inner poll flag.
+ * @is_enable: return enable inner poll flag, inner poll is not
+ * supported, and is_enable will always be 0.
*/
int wd_rsa_get_env_param(__u32 node, __u32 type, __u32 mode,
__u32 *num, __u8 *is_enable);
diff --git a/include/wd_util.h b/include/wd_util.h
index 42270d9..c24c554 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -78,16 +78,10 @@ struct wd_env_config_per_numa {
/* Resource begin */
struct uacce_dev *dev;
int dev_num;
- /* This can be made statically currently */
- unsigned long async_poll_num;
- void *async_task_queue_array;
};
struct wd_env_config {
struct wd_env_config_per_numa *config_per_numa;
- /* Let's make it as a gobal config, not per numa */
- bool enable_internal_poll;
-
/* resource config */
struct wd_sched *sched;
bool internal_sched;
@@ -273,28 +267,6 @@ int wd_check_datalist(struct wd_datalist *head, __u64 size);
*/
int wd_parse_ctx_num(struct wd_env_config *config, const char *s);
-/*
- * wd_parse_async_poll_en() - Parse async polling thread related environment
- * variable and store it.
- * @config: Pointer of wd_env_config which is used to store environment
- * variable information.
- * @s: Related environment variable string.
- *
- * More information, please see docs/wd_environment_variable.
- */
-int wd_parse_async_poll_en(struct wd_env_config *config, const char *s);
-
-/*
- * wd_parse_async_poll_num() - Parse async polling thread related environment
- * variable and store it.
- * @config: Pointer of wd_env_config which is used to store environment
- * variable information.
- * @s: Related environment variable string.
- *
- * More information, please see docs/wd_environment_variable.
- */
-int wd_parse_async_poll_num(struct wd_env_config *config, const char *s);
-
/*
* wd_alg_env_init() - Init wd algorithm environment variable configurations.
* This is a help function which can be used by specific
@@ -323,15 +295,6 @@ int wd_alg_env_init(struct wd_env_config *env_config,
void wd_alg_env_uninit(struct wd_env_config *env_config,
const struct wd_alg_ops *ops);
-/*
- * wd_add_task_to_async_queue() - Add an async request to its related async
- * task queue.
- * @config: Pointer of wd_env_config which is used to store environment
- * variable information.
- * @idx: Index of ctx in config.
- */
-int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx);
-
/*
* dump_env_info() - dump wd algorithm ctx info.
* @config: Pointer of wd_env_config which is used to store environment
diff --git a/wd_aead.c b/wd_aead.c
index 748bf95..3e993a1 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -957,9 +957,6 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_aead_env_config, idx);
- if (ret)
- goto fail_with_msg;
return 0;
@@ -1039,15 +1036,10 @@ int wd_aead_poll(__u32 expt, __u32 *count)
return sched->poll_policy(h_ctx, expt, count);
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_AEAD_CTX_NUM",
- .def_val = "sync:2@0,async:2@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_AEAD_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- }
+static const struct wd_config_variable table = {
+ .name = "WD_AEAD_CTX_NUM",
+ .def_val = "sync:2@0,async:2@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_aead_ops = {
@@ -1062,8 +1054,8 @@ int wd_aead_env_init(struct wd_sched *sched)
{
wd_aead_env_config.sched = sched;
- return wd_alg_env_init(&wd_aead_env_config, table,
- &wd_aead_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_aead_env_config, &table,
+ &wd_aead_ops, 1, NULL);
}
void wd_aead_env_uninit(void)
@@ -1080,8 +1072,8 @@ int wd_aead_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_aead_env_config, table,
- &wd_aead_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_aead_env_config, &table,
+ &wd_aead_ops, 1, &ctx_attr);
}
void wd_aead_ctx_num_uninit(void)
diff --git a/wd_cipher.c b/wd_cipher.c
index abedfb3..a4d6c63 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -800,9 +800,6 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_cipher_env_config, idx);
- if (ret)
- goto fail_with_msg;
return 0;
@@ -883,15 +880,10 @@ int wd_cipher_poll(__u32 expt, __u32 *count)
return sched->poll_policy(h_ctx, expt, count);
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_CIPHER_CTX_NUM",
- .def_val = "sync:2@0,async:2@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_CIPHER_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- }
+static const struct wd_config_variable table = {
+ .name = "WD_CIPHER_CTX_NUM",
+ .def_val = "sync:2@0,async:2@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_cipher_ops = {
@@ -906,8 +898,8 @@ int wd_cipher_env_init(struct wd_sched *sched)
{
wd_cipher_env_config.sched = sched;
- return wd_alg_env_init(&wd_cipher_env_config, table,
- &wd_cipher_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_cipher_env_config, &table,
+ &wd_cipher_ops, 1, NULL);
}
void wd_cipher_env_uninit(void)
@@ -924,8 +916,8 @@ int wd_cipher_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_cipher_env_config, table,
- &wd_cipher_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_cipher_env_config, &table,
+ &wd_cipher_ops, 1, &ctx_attr);
}
void wd_cipher_ctx_num_uninit(void)
diff --git a/wd_comp.c b/wd_comp.c
index 247eadd..84fb079 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -880,9 +880,6 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_comp_env_config, idx);
- if (unlikely(ret))
- goto fail_with_msg;
return 0;
@@ -908,19 +905,10 @@ int wd_comp_poll(__u32 expt, __u32 *count)
return sched->poll_policy(h_sched_ctx, expt, count);
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_COMP_CTX_NUM",
- .def_val = "sync-comp:1@0,sync-decomp:1@0,async-comp:1@0,async-decomp:1@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_COMP_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- },
- { .name = "WD_COMP_ASYNC_POLL_NUM",
- .def_val = "1@0",
- .parse_fn = wd_parse_async_poll_num
- }
+static const struct wd_config_variable table = {
+ .name = "WD_COMP_CTX_NUM",
+ .def_val = "sync-comp:1@0,sync-decomp:1@0,async-comp:1@0,async-decomp:1@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_comp_ops = {
@@ -935,8 +923,8 @@ int wd_comp_env_init(struct wd_sched *sched)
{
wd_comp_env_config.sched = sched;
- return wd_alg_env_init(&wd_comp_env_config, table,
- &wd_comp_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_comp_env_config, &table,
+ &wd_comp_ops, 1, NULL);
}
void wd_comp_env_uninit(void)
@@ -958,8 +946,8 @@ int wd_comp_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_comp_env_config, table,
- &wd_comp_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_comp_env_config, &table,
+ &wd_comp_ops, 1, &ctx_attr);
}
void wd_comp_ctx_num_uninit(void)
diff --git a/wd_dh.c b/wd_dh.c
index 3395060..7837114 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -441,9 +441,6 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_dh_env_config, idx);
- if (ret)
- goto fail_with_msg;
return WD_SUCCESS;
@@ -654,15 +651,10 @@ void wd_dh_free_sess(handle_t sess)
free(sess_t);
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_DH_CTX_NUM",
- .def_val = "sync:2@0,async:2@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_DH_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- }
+static const struct wd_config_variable table = {
+ .name = "WD_DH_CTX_NUM",
+ .def_val = "sync:2@0,async:2@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_dh_ops = {
@@ -677,8 +669,8 @@ int wd_dh_env_init(struct wd_sched *sched)
{
wd_dh_env_config.sched = sched;
- return wd_alg_env_init(&wd_dh_env_config, table,
- &wd_dh_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_dh_env_config, &table,
+ &wd_dh_ops, 1, NULL);
}
void wd_dh_env_uninit(void)
@@ -695,8 +687,8 @@ int wd_dh_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_dh_env_config, table,
- &wd_dh_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_dh_env_config, &table,
+ &wd_dh_ops, 1, &ctx_attr);
}
void wd_dh_ctx_num_uninit(void)
diff --git a/wd_digest.c b/wd_digest.c
index 8e5bf94..bd3dd05 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -746,9 +746,6 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_digest_env_config, idx);
- if (ret)
- goto fail_with_msg;
return 0;
@@ -830,15 +827,10 @@ int wd_digest_poll(__u32 expt, __u32 *count)
return sched->poll_policy(h_ctx, expt, count);
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_DIGEST_CTX_NUM",
- .def_val = "sync:2@0,async:2@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_DIGEST_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- }
+static const struct wd_config_variable table = {
+ .name = "WD_DIGEST_CTX_NUM",
+ .def_val = "sync:2@0,async:2@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_digest_ops = {
@@ -853,8 +845,8 @@ int wd_digest_env_init(struct wd_sched *sched)
{
wd_digest_env_config.sched = sched;
- return wd_alg_env_init(&wd_digest_env_config, table,
- &wd_digest_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_digest_env_config, &table,
+ &wd_digest_ops, 1, NULL);
}
void wd_digest_env_uninit(void)
@@ -871,8 +863,8 @@ int wd_digest_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_digest_env_config, table,
- &wd_digest_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_digest_env_config, &table,
+ &wd_digest_ops, 1, &ctx_attr);
}
void wd_digest_ctx_num_uninit(void)
diff --git a/wd_ecc.c b/wd_ecc.c
index c31495f..4c77a04 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -2319,9 +2319,6 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_ecc_env_config, idx);
- if (ret)
- goto fail_with_msg;
return WD_SUCCESS;
@@ -2401,15 +2398,10 @@ int wd_ecc_poll(__u32 expt, __u32 *count)
return wd_ecc_setting.sched.poll_policy(h_sched_sess, expt, count);
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_ECC_CTX_NUM",
- .def_val = "sync:2@0,async:2@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_ECC_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- }
+static const struct wd_config_variable table = {
+ .name = "WD_ECC_CTX_NUM",
+ .def_val = "sync:2@0,async:2@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_ecc_ops = {
@@ -2424,8 +2416,8 @@ int wd_ecc_env_init(struct wd_sched *sched)
{
wd_ecc_env_config.sched = sched;
- return wd_alg_env_init(&wd_ecc_env_config, table,
- &wd_ecc_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_ecc_env_config, &table,
+ &wd_ecc_ops, 1, NULL);
}
void wd_ecc_env_uninit(void)
@@ -2442,8 +2434,8 @@ int wd_ecc_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_ecc_env_config, table,
- &wd_ecc_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_ecc_env_config, &table,
+ &wd_ecc_ops, 1, &ctx_attr);
}
void wd_ecc_ctx_num_uninit(void)
diff --git a/wd_rsa.c b/wd_rsa.c
index c020514..2242fed 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -502,9 +502,6 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req)
}
wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
- ret = wd_add_task_to_async_queue(&wd_rsa_env_config, idx);
- if (ret)
- goto fail_with_msg;
return WD_SUCCESS;
@@ -1266,15 +1263,10 @@ void wd_rsa_get_prikey(handle_t sess, struct wd_rsa_prikey **prikey)
*prikey = ((struct wd_rsa_sess *)sess)->prikey;
}
-static const struct wd_config_variable table[] = {
- { .name = "WD_RSA_CTX_NUM",
- .def_val = "sync:2@0,async:2@0",
- .parse_fn = wd_parse_ctx_num
- },
- { .name = "WD_RSA_ASYNC_POLL_EN",
- .def_val = "0",
- .parse_fn = wd_parse_async_poll_en
- }
+static const struct wd_config_variable table = {
+ .name = "WD_RSA_CTX_NUM",
+ .def_val = "sync:2@0,async:2@0",
+ .parse_fn = wd_parse_ctx_num
};
static const struct wd_alg_ops wd_rsa_ops = {
@@ -1289,8 +1281,8 @@ int wd_rsa_env_init(struct wd_sched *sched)
{
wd_rsa_env_config.sched = sched;
- return wd_alg_env_init(&wd_rsa_env_config, table,
- &wd_rsa_ops, ARRAY_SIZE(table), NULL);
+ return wd_alg_env_init(&wd_rsa_env_config, &table,
+ &wd_rsa_ops, 1, NULL);
}
void wd_rsa_env_uninit(void)
@@ -1307,8 +1299,8 @@ int wd_rsa_ctx_num_init(__u32 node, __u32 type, __u32 num, __u8 mode)
if (ret)
return ret;
- return wd_alg_env_init(&wd_rsa_env_config, table,
- &wd_rsa_ops, ARRAY_SIZE(table), &ctx_attr);
+ return wd_alg_env_init(&wd_rsa_env_config, &table,
+ &wd_rsa_ops, 1, &ctx_attr);
}
void wd_rsa_ctx_num_uninit(void)
diff --git a/wd_util.c b/wd_util.c
index f97b558..c174d7c 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -8,7 +8,6 @@
#include <dirent.h>
#include <dlfcn.h>
#include <pthread.h>
-#include <semaphore.h>
#include <string.h>
#include <ctype.h>
#include "wd_sched.h"
@@ -72,27 +71,6 @@ static const char *wd_env_name[WD_TYPE_MAX] = {
"WD_JOIN_GATHER_CTX_NUM",
};
-struct async_task {
- __u32 idx;
-};
-
-struct async_task_queue {
- struct async_task *head;
- int depth;
- /* the producer offset of task queue */
- int prod;
- /* the consumer offset of task queue */
- int cons;
- int cur_task;
- int left_task;
- int end;
- sem_t empty_sem;
- sem_t full_sem;
- pthread_mutex_t lock;
- pthread_t tid;
- int (*alg_poll_ctx)(__u32, __u32, __u32 *);
-};
-
struct drv_lib_list {
void *dlhandle;
struct drv_lib_list *next;
@@ -784,17 +762,6 @@ static int str_to_bool(const char *s, bool *target)
return 0;
}
-int wd_parse_async_poll_en(struct wd_env_config *config, const char *s)
-{
- int ret;
-
- ret = str_to_bool(s, &config->enable_internal_poll);
- if (ret)
- WD_ERR("failed to parse async poll enable flag(%s)!\n", s);
-
- return ret;
-}
-
static int parse_num_on_numa(const char *s, int *num, int *node)
{
char *sep, *start, *left;
@@ -1036,41 +1003,6 @@ int wd_parse_ctx_num(struct wd_env_config *config, const char *s)
return parse_ctx_num(config, s);
}
-int wd_parse_async_poll_num(struct wd_env_config *config, const char *s)
-{
- struct wd_env_config_per_numa *config_numa;
- char *left, *section, *start;
- int node, poll_num, ret;
-
- if (!config->enable_internal_poll) {
- WD_ERR("internal poll not enabled, skip parse poll number!\n");
- return 0;
- }
-
- start = strdup(s);
- if (!start)
- return -ENOMEM;
-
- left = start;
- while ((section = strsep(&left, ","))) {
- ret = parse_num_on_numa(section, &poll_num, &node);
- if (ret)
- goto out;
- config_numa = wd_get_config_numa(config, node);
- if (!config_numa) {
- ret = -WD_EINVAL;
- goto out;
- }
- config_numa->async_poll_num = poll_num;
- }
-
- free(start);
- return 0;
-out:
- free(start);
- return ret;
-}
-
static int wd_parse_env(struct wd_env_config *config)
{
const struct wd_config_variable *var;
@@ -1119,8 +1051,6 @@ static int wd_parse_ctx_attr(struct wd_env_config *env_config,
/* Use default sched and disable internal poll */
env_config->sched = NULL;
- env_config->enable_internal_poll = 0;
- config_numa->async_poll_num = 0;
return 0;
}
@@ -1348,21 +1278,17 @@ static int wd_init_sched_config(struct wd_env_config *config,
{
struct wd_env_config_per_numa *config_numa;
int i, j, ret, max_node, type_num;
- void *func = NULL;
type_num = config->op_type_num;
max_node = numa_max_node() + 1;
if (max_node <= 0)
return -WD_EINVAL;
- if (!config->enable_internal_poll)
- func = alg_poll_ctx;
-
config->internal_sched = false;
if (!config->sched) {
WD_ERR("no sched is specified, alloc a default sched!\n");
config->sched = wd_sched_rr_alloc(SCHED_POLICY_RR, type_num,
- max_node, func);
+ max_node, alg_poll_ctx);
if (!config->sched)
return -WD_ENOMEM;
@@ -1389,339 +1315,6 @@ err_release_sched:
return ret;
}
-static struct async_task_queue *find_async_queue(struct wd_env_config *config,
- __u32 idx)
-{
- struct wd_env_config_per_numa *config_numa;
- struct wd_ctx_range **ctx_table;
- struct async_task_queue *head;
- unsigned long offset = 0;
- __u32 i, num = 0;
-
- FOREACH_NUMA(i, config, config_numa) {
- num += config_numa->sync_ctx_num + config_numa->async_ctx_num;
- if (idx < num)
- break;
- }
-
- if (i == config->numa_num) {
- WD_ERR("failed to find a proper numa node!\n");
- return NULL;
- }
-
- if (!config_numa->async_poll_num) {
- WD_ERR("invalid: async_poll_num of numa is zero!\n");
- return NULL;
- }
-
- ctx_table = config_numa->ctx_table;
- for (i = 0; i < config_numa->op_type_num; i++) {
- if (idx <= ctx_table[CTX_MODE_ASYNC][i].end &&
- idx >= ctx_table[CTX_MODE_ASYNC][i].begin) {
- offset = (idx - ctx_table[CTX_MODE_ASYNC][i].begin) %
- config_numa->async_poll_num;
- break;
- }
- }
-
- if (i == config_numa->op_type_num) {
- WD_ERR("failed to find async queue for ctx: idx %u!\n", idx);
- return NULL;
- }
-
- head = (struct async_task_queue *)config_numa->async_task_queue_array;
-
- return head + offset;
-}
-
-int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx)
-{
- struct async_task_queue *task_queue;
- struct async_task *task;
- int curr_prod, ret;
-
- if (!config->enable_internal_poll)
- return 0;
-
- task_queue = find_async_queue(config, idx);
- if (!task_queue)
- return -WD_EINVAL;
-
- ret = sem_wait(&task_queue->empty_sem);
- if (ret) {
- WD_ERR("failed to wait empty_sem!\n");
- return ret;
- }
-
- pthread_mutex_lock(&task_queue->lock);
-
- /* get an available async task and fill ctx idx */
- curr_prod = task_queue->prod;
- task = task_queue->head + curr_prod;
- task->idx = idx;
-
- /* update global information of task queue */
- task_queue->prod = (curr_prod + 1) % task_queue->depth;
- task_queue->cur_task++;
- task_queue->left_task--;
-
- pthread_mutex_unlock(&task_queue->lock);
-
- ret = sem_post(&task_queue->full_sem);
- if (ret) {
- WD_ERR("failed to post full_sem!\n");
- goto err_out;
- }
-
- return 0;
-
-err_out:
- pthread_mutex_lock(&task_queue->lock);
- task_queue->left_task++;
- task_queue->cur_task--;
- task_queue->prod = curr_prod;
- pthread_mutex_unlock(&task_queue->lock);
- sem_post(&task_queue->empty_sem);
-
- return ret;
-}
-
-static void *async_poll_process_func(void *args)
-{
- struct async_task_queue *task_queue = args;
- struct async_task *head, *task;
- __u32 count;
- int cons, ret;
-
- while (1) {
- if (sem_wait(&task_queue->full_sem)) {
- if (errno == EINTR) {
- continue;
- }
- }
- if (__atomic_load_n(&task_queue->end, __ATOMIC_ACQUIRE)) {
- __atomic_store_n(&task_queue->end, 0, __ATOMIC_RELEASE);
- goto out;
- }
-
- pthread_mutex_lock(&task_queue->lock);
-
- /* async sending message isn't submitted yet */
- if (task_queue->cons == task_queue->prod) {
- pthread_mutex_unlock(&task_queue->lock);
- sem_post(&task_queue->full_sem);
- continue;
- }
-
- cons = task_queue->cons;
- head = task_queue->head;
- task = head + cons;
-
- task_queue->cons = (cons + 1) % task_queue->depth;
- task_queue->cur_task--;
- task_queue->left_task++;
-
- pthread_mutex_unlock(&task_queue->lock);
-
- ret = task_queue->alg_poll_ctx(task->idx, 1, &count);
- if (ret < 0) {
- pthread_mutex_lock(&task_queue->lock);
- task_queue->cons = cons;
- task_queue->cur_task++;
- task_queue->left_task--;
- pthread_mutex_unlock(&task_queue->lock);
- if (ret == -WD_EAGAIN) {
- sem_post(&task_queue->full_sem);
- continue;
- } else
- goto out;
- }
-
- if (sem_post(&task_queue->empty_sem))
- goto out;
- }
-out:
- return NULL;
-}
-
-static int wd_init_one_task_queue(struct async_task_queue *task_queue,
- void *alg_poll_ctx)
-
-{
- struct async_task *head;
- pthread_t thread_id;
- pthread_attr_t attr;
- int depth, ret;
-
- task_queue->depth = depth = WD_ASYNC_DEF_QUEUE_DEPTH;
-
- head = calloc(task_queue->depth, sizeof(*head));
- if (!head)
- return -WD_ENOMEM;
-
- task_queue->head = head;
- task_queue->left_task = depth;
- task_queue->alg_poll_ctx = alg_poll_ctx;
-
- if (sem_init(&task_queue->empty_sem, 0, depth)) {
- WD_ERR("failed to init empty_sem!\n");
- goto err_free_head;
- }
-
- if (sem_init(&task_queue->full_sem, 0, 0)) {
- WD_ERR("failed to init full_sem!\n");
- goto err_uninit_empty_sem;
- }
-
- if (pthread_mutex_init(&task_queue->lock, NULL)) {
- WD_ERR("failed to init task queue's mutex lock!\n");
- goto err_uninit_full_sem;
- }
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- task_queue->tid = 0;
- if (pthread_create(&thread_id, &attr, async_poll_process_func,
- task_queue)) {
- WD_ERR("failed to create poll thread!\n");
- goto err_destory_mutex;
- }
-
- task_queue->tid = thread_id;
- pthread_attr_destroy(&attr);
-
- return 0;
-
-err_destory_mutex:
- pthread_attr_destroy(&attr);
- pthread_mutex_destroy(&task_queue->lock);
-err_uninit_full_sem:
- sem_destroy(&task_queue->full_sem);
-err_uninit_empty_sem:
- sem_destroy(&task_queue->empty_sem);
-err_free_head:
- free(head);
- ret = -errno;
- return ret;
-}
-
-static void wd_uninit_one_task_queue(struct async_task_queue *task_queue)
-{
- /*
- * If there's no async task, async_poll_process_func() is sleeping
- * on task_queue->full_sem. It'll cause that threads could not
- * be end and memory leak.
- */
- sem_post(&task_queue->full_sem);
- __atomic_store_n(&task_queue->end, 1, __ATOMIC_RELEASE);
- while (__atomic_load_n(&task_queue->end, __ATOMIC_ACQUIRE))
- sched_yield();
-
- pthread_mutex_destroy(&task_queue->lock);
- sem_destroy(&task_queue->full_sem);
- sem_destroy(&task_queue->empty_sem);
- free(task_queue->head);
- task_queue->head = NULL;
-}
-
-static int wd_init_async_polling_thread_per_numa(struct wd_env_config *config,
- struct wd_env_config_per_numa *config_numa,
- void *alg_poll_ctx)
-{
- struct async_task_queue *task_queue, *queue_head;
- int i, j, ret;
- double num;
-
- if (!config_numa->async_ctx_num)
- return 0;
-
- if (!config_numa->async_poll_num) {
- WD_ERR("invalid async poll num (%lu) is set.\n",
- config_numa->async_poll_num);
- WD_ERR("change to default value: %d\n", WD_ASYNC_DEF_POLL_NUM);
- config_numa->async_poll_num = WD_ASYNC_DEF_POLL_NUM;
- }
-
- num = MIN(config_numa->async_poll_num, config_numa->async_ctx_num);
-
- /* make max task queues as the number of async ctxs */
- queue_head = calloc(config_numa->async_ctx_num, sizeof(*queue_head));
- if (!queue_head)
- return -WD_ENOMEM;
-
- task_queue = queue_head;
- for (i = 0; i < num; task_queue++, i++) {
- ret = wd_init_one_task_queue(task_queue, alg_poll_ctx);
- if (ret) {
- for (j = 0; j < i; task_queue++, j++)
- wd_uninit_one_task_queue(task_queue);
- free(queue_head);
- return ret;
- }
- }
-
- config_numa->async_task_queue_array = (void *)queue_head;
-
- return 0;
-}
-
-static void wd_uninit_async_polling_thread_per_numa(struct wd_env_config *cfg,
- struct wd_env_config_per_numa *config_numa)
-{
- struct async_task_queue *task_queue, *head;
- double num;
- int i;
-
- if (!config_numa || !config_numa->async_task_queue_array)
- return;
-
- head = config_numa->async_task_queue_array;
- task_queue = head;
- num = MIN(config_numa->async_poll_num, config_numa->async_ctx_num);
-
- for (i = 0; i < num; task_queue++, i++)
- wd_uninit_one_task_queue(task_queue);
- free(head);
- config_numa->async_task_queue_array = NULL;
-}
-
-static int wd_init_async_polling_thread(struct wd_env_config *config,
- void *alg_poll_ctx)
-{
- struct wd_env_config_per_numa *config_numa;
- int i, ret;
-
- if (!config->enable_internal_poll)
- return 0;
-
- FOREACH_NUMA(i, config, config_numa) {
- ret = wd_init_async_polling_thread_per_numa(config, config_numa,
- alg_poll_ctx);
- if (ret)
- goto out;
- }
-
- return 0;
-
-out:
- FOREACH_NUMA(i, config, config_numa)
- wd_uninit_async_polling_thread_per_numa(config, config_numa);
-
- return ret;
-}
-
-static void wd_uninit_async_polling_thread(struct wd_env_config *config)
-{
- struct wd_env_config_per_numa *config_numa;
- int i;
-
- if (!config->enable_internal_poll)
- return;
-
- FOREACH_NUMA(i, config, config_numa)
- wd_uninit_async_polling_thread_per_numa(config, config_numa);
-}
-
static int wd_init_resource(struct wd_env_config *config,
const struct wd_alg_ops *ops)
{
@@ -1739,14 +1332,8 @@ static int wd_init_resource(struct wd_env_config *config,
if (ret)
goto err_uninit_sched;
- ret = wd_init_async_polling_thread(config, ops->alg_poll_ctx);
- if (ret)
- goto err_uninit_alg;
-
return 0;
-err_uninit_alg:
- ops->alg_uninit();
err_uninit_sched:
wd_uninit_sched_config(config);
err_uninit_ctx:
@@ -1757,7 +1344,6 @@ err_uninit_ctx:
static void wd_uninit_resource(struct wd_env_config *config,
const struct wd_alg_ops *ops)
{
- wd_uninit_async_polling_thread(config);
ops->alg_uninit();
wd_uninit_sched_config(config);
wd_free_ctx(config);
@@ -1811,7 +1397,7 @@ int wd_alg_get_env_param(struct wd_env_config *env_config,
return -WD_EINVAL;
}
- *is_enable = env_config->enable_internal_poll;
+ *is_enable = 0;
config_numa = wd_get_config_numa(env_config, attr.node);
if (!config_numa)
--
2.43.0
1
4
From: Weili Qian <qianweili(a)huawei.com>
The OpenSSL version macro is used to solve the compatibility issues
between the uadk provider and OpenSSL 3.5.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
src/uadk_prov_ec_kmgmt.c | 13 ++++++++++++-
src/uadk_prov_ecdsa.c | 13 +++++++++++--
src/uadk_prov_ecx.c | 4 ++++
src/uadk_prov_pkey.h | 37 ++++++++++++++++++++++++++++++++++---
src/uadk_prov_rsa_enc.c | 5 ++++-
src/uadk_prov_rsa_sign.c | 7 +++++++
src/uadk_prov_sm2_sign.c | 14 +++++++++++---
7 files changed, 83 insertions(+), 10 deletions(-)
diff --git a/src/uadk_prov_ec_kmgmt.c b/src/uadk_prov_ec_kmgmt.c
index bd5cbd9..530929c 100644
--- a/src/uadk_prov_ec_kmgmt.c
+++ b/src/uadk_prov_ec_kmgmt.c
@@ -412,6 +412,7 @@ static void uadk_keymgmt_ec_gen_cleanup(void *genctx)
if (!gctx)
return;
+ OPENSSL_clear_free(gctx->dhkem_ikm, gctx->dhkem_ikmlen);
EC_GROUP_free(gctx->gen_group);
BN_free(gctx->p);
BN_free(gctx->a);
@@ -620,6 +621,13 @@ static int uadk_keymgmt_ec_gen_set_params(void *genctx, const OSSL_PARAM params[
if (!ret)
return ret;
+# if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ ret = ec_set_octet_param(OSSL_PKEY_PARAM_DHKEM_IKM, &gctx->dhkem_ikm,
+ &gctx->dhkem_ikmlen, params);
+ if (!ret)
+ return ret;
+# endif
+
return ec_set_octet_param(OSSL_PKEY_PARAM_EC_GENERATOR,
&gctx->gen, &gctx->gen_len, params);
}
@@ -640,8 +648,11 @@ static const OSSL_PARAM *uadk_keymgmt_ec_gen_settable_params(ossl_unused void *g
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_EC_GENERATOR, NULL, 0),
OSSL_PARAM_BN(OSSL_PKEY_PARAM_EC_ORDER, NULL, 0),
OSSL_PARAM_BN(OSSL_PKEY_PARAM_EC_COFACTOR, NULL, 0),
- OSSL_PARAM_BN(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0),
OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_EC_SEED, NULL, 0),
+# if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_DHKEM_IKM, NULL, 0),
+# endif
+ OSSL_PARAM_BN(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0),
OSSL_PARAM_END
};
diff --git a/src/uadk_prov_ecdsa.c b/src/uadk_prov_ecdsa.c
index 3876488..44f64f6 100644
--- a/src/uadk_prov_ecdsa.c
+++ b/src/uadk_prov_ecdsa.c
@@ -53,7 +53,9 @@ struct ecdsa_ctx {
/* The Algorithm Identifier of the combined signature algorithm */
unsigned char aid_buf[MAX_ALGORITHM_ID_SIZE];
+#if OPENSSL_VERSION_NUMBER < 0x30400000L
unsigned char *aid;
+#endif
size_t aid_len;
size_t mdsize;
int operation;
@@ -174,6 +176,7 @@ err:
static void ecdsa_set_aid(struct ecdsa_ctx *ctx, int md_nid)
{
+ unsigned char *aid = NULL;
WPACKET pkt;
ctx->aid_len = 0;
@@ -181,9 +184,11 @@ static void ecdsa_set_aid(struct ecdsa_ctx *ctx, int md_nid)
ossl_DER_w_algorithmIdentifier_ECDSA_with_MD(&pkt, -1, ctx->ec, md_nid) &&
WPACKET_finish(&pkt)) {
WPACKET_get_total_written(&pkt, &ctx->aid_len);
- ctx->aid = WPACKET_get_curr(&pkt);
+ aid = WPACKET_get_curr(&pkt);
}
WPACKET_cleanup(&pkt);
+ if (aid && ctx->aid_len)
+ memmove(ctx->aid_buf, aid, ctx->aid_len);
}
/*
@@ -969,13 +974,17 @@ static int uadk_signature_ecdsa_digest_verify_final(void *vctx, const unsigned c
static int ecdsa_get_ctx_aid(struct ecdsa_ctx *ctx, OSSL_PARAM *params)
{
+ unsigned char *aid = NULL;
OSSL_PARAM *p;
+ if (ctx->aid_len)
+ aid = ctx->aid_buf;
+
p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
if (!p)
return UADK_P_SUCCESS;
- return OSSL_PARAM_set_octet_string(p, ctx->aid, ctx->aid_len);
+ return OSSL_PARAM_set_octet_string(p, aid, ctx->aid_len);
}
static int ecdsa_get_ctx_digest_size(struct ecdsa_ctx *ctx, OSSL_PARAM *params)
diff --git a/src/uadk_prov_ecx.c b/src/uadk_prov_ecx.c
index 7353836..69494cc 100644
--- a/src/uadk_prov_ecx.c
+++ b/src/uadk_prov_ecx.c
@@ -147,6 +147,10 @@ typedef struct {
char *propq;
ECX_KEY_TYPE type;
int selection;
+# if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ unsigned char *dhkem_ikm;
+ size_t dhkem_ikmlen;
+# endif
size_t keylen;
/* uadk sesssion */
handle_t sess;
diff --git a/src/uadk_prov_pkey.h b/src/uadk_prov_pkey.h
index e82df34..aa7a07b 100644
--- a/src/uadk_prov_pkey.h
+++ b/src/uadk_prov_pkey.h
@@ -121,6 +121,8 @@ struct ec_gen_ctx {
int selection;
int ecdh_mode;
EC_GROUP *gen_group;
+ unsigned char *dhkem_ikm;
+ size_t dhkem_ikmlen;
BIGNUM *priv_key;
};
@@ -129,12 +131,17 @@ typedef struct {
int id;
int name_id;
+#if OPENSSL_VERSION_NUMBER >= 0x30300000L
+ /* NID for the legacy alg if there is one */
+ int legacy_alg;
+# endif
char *type_name;
const char *description;
OSSL_PROVIDER *prov;
int refcnt;
+#if OPENSSL_VERSION_NUMBER < 0x30200000L
void *lock;
-
+# endif
/* Constructor(s), destructor, information */
OSSL_FUNC_keymgmt_new_fn *new_fun;
OSSL_FUNC_keymgmt_free_fn *free;
@@ -146,6 +153,10 @@ typedef struct {
/* Generation, a complex constructor */
OSSL_FUNC_keymgmt_gen_init_fn *gen_init;
OSSL_FUNC_keymgmt_gen_set_template_fn *gen_set_template;
+#if OPENSSL_VERSION_NUMBER >= 0x30400000L
+ OSSL_FUNC_keymgmt_gen_get_params_fn *gen_get_params;
+ OSSL_FUNC_keymgmt_gen_gettable_params_fn *gen_gettable_params;
+# endif
OSSL_FUNC_keymgmt_gen_set_params_fn *gen_set_params;
OSSL_FUNC_keymgmt_gen_settable_params_fn *gen_settable_params;
OSSL_FUNC_keymgmt_gen_fn *gen;
@@ -161,8 +172,14 @@ typedef struct {
/* Import and export routines */
OSSL_FUNC_keymgmt_import_fn *import;
OSSL_FUNC_keymgmt_import_types_fn *import_types;
+#if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ OSSL_FUNC_keymgmt_import_types_ex_fn *import_types_ex;
+# endif
OSSL_FUNC_keymgmt_export_fn *export_fun;
OSSL_FUNC_keymgmt_export_types_fn *export_types;
+#if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ OSSL_FUNC_keymgmt_export_types_ex_fn *export_types_ex;
+# endif
OSSL_FUNC_keymgmt_dup_fn *dup;
} UADK_PKEY_KEYMGMT;
@@ -228,13 +245,24 @@ typedef struct {
const char *description;
OSSL_PROVIDER *prov;
int refcnt;
+#if OPENSSL_VERSION_NUMBER < 0x30200000L
void *lock;
-
+#endif
OSSL_FUNC_signature_newctx_fn *newctx;
OSSL_FUNC_signature_sign_init_fn *sign_init;
OSSL_FUNC_signature_sign_fn *sign;
+#if OPENSSL_VERSION_NUMBER >= 0x30400000L
+ OSSL_FUNC_signature_sign_message_init_fn *sign_message_init;
+ OSSL_FUNC_signature_sign_message_update_fn *sign_message_update;
+ OSSL_FUNC_signature_sign_message_final_fn *sign_message_final;
+#endif
OSSL_FUNC_signature_verify_init_fn *verify_init;
OSSL_FUNC_signature_verify_fn *verify;
+#if OPENSSL_VERSION_NUMBER >= 0x30400000L
+ OSSL_FUNC_signature_verify_message_init_fn *verify_message_init;
+ OSSL_FUNC_signature_verify_message_update_fn *verify_message_update;
+ OSSL_FUNC_signature_verify_message_final_fn *verify_message_final;
+#endif
OSSL_FUNC_signature_verify_recover_init_fn *verify_recover_init;
OSSL_FUNC_signature_verify_recover_fn *verify_recover;
OSSL_FUNC_signature_digest_sign_init_fn *digest_sign_init;
@@ -330,8 +358,9 @@ typedef struct {
const char *description;
OSSL_PROVIDER *prov;
int refcnt;
+#if OPENSSL_VERSION_NUMBER < 0x30200000L
void *lock;
-
+#endif
OSSL_FUNC_asym_cipher_newctx_fn *newctx;
OSSL_FUNC_asym_cipher_encrypt_init_fn *encrypt_init;
OSSL_FUNC_asym_cipher_encrypt_fn *encrypt;
@@ -384,7 +413,9 @@ typedef struct {
const char *description;
OSSL_PROVIDER *prov;
int refcnt;
+#if OPENSSL_VERSION_NUMBER < 0x30200000L
void *lock;
+#endif
OSSL_FUNC_keyexch_newctx_fn *newctx;
OSSL_FUNC_keyexch_init_fn *init;
diff --git a/src/uadk_prov_rsa_enc.c b/src/uadk_prov_rsa_enc.c
index 50005f9..c0da4c9 100644
--- a/src/uadk_prov_rsa_enc.c
+++ b/src/uadk_prov_rsa_enc.c
@@ -44,7 +44,10 @@ struct PROV_RSA_ASYM_CTX {
/* TLS padding */
unsigned int client_version;
unsigned int alt_version;
-
+#if OPENSSL_VERSION_NUMBER >= 0x30200000L
+ /* PKCS#1 v1.5 decryption mode */
+ unsigned int implicit_rejection;
+# endif
unsigned int soft : 1;
};
diff --git a/src/uadk_prov_rsa_sign.c b/src/uadk_prov_rsa_sign.c
index 4db3ab7..8483b2e 100644
--- a/src/uadk_prov_rsa_sign.c
+++ b/src/uadk_prov_rsa_sign.c
@@ -44,6 +44,9 @@ struct PROV_RSA_SIG_CTX {
*/
unsigned int flag_allow_md : 1;
unsigned int mgf1_md_set : 1;
+ unsigned int flag_allow_update : 1;
+ unsigned int flag_allow_final : 1;
+ unsigned int flag_allow_oneshot : 1;
/* main digest */
EVP_MD *md;
@@ -61,6 +64,10 @@ struct PROV_RSA_SIG_CTX {
int saltlen;
/* Minimum salt length or -1 if no PSS parameter restriction */
int min_saltlen;
+#if OPENSSL_VERSION_NUMBER >= 0x30400000L
+ unsigned char *sig;
+ size_t siglen;
+#endif
/* Temp buffer */
unsigned char *tbuf;
diff --git a/src/uadk_prov_sm2_sign.c b/src/uadk_prov_sm2_sign.c
index 27627c1..aa7049e 100644
--- a/src/uadk_prov_sm2_sign.c
+++ b/src/uadk_prov_sm2_sign.c
@@ -61,8 +61,10 @@ typedef struct {
/* The Algorithm Identifier of the combined signature algorithm */
unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
+#if OPENSSL_VERSION_NUMBER < 0x30400000L
unsigned char *aid;
- size_t aid_len;
+#endif
+ size_t aid_len;
/* main digest */
EVP_MD *md;
@@ -755,6 +757,7 @@ static int sm2_digest_signverify_init(void *vpsm2ctx, const char *mdname,
void *ec, const OSSL_PARAM params[])
{
PROV_SM2_SIGN_CTX *psm2ctx = (PROV_SM2_SIGN_CTX *)vpsm2ctx;
+ unsigned char *aid = NULL;
int md_nid;
WPACKET pkt;
@@ -784,9 +787,11 @@ static int sm2_digest_signverify_init(void *vpsm2ctx, const char *mdname,
ossl_DER_w_algorithmIdentifier_SM2_with_MD(&pkt, -1, psm2ctx->key, md_nid) &&
WPACKET_finish(&pkt)) {
WPACKET_get_total_written(&pkt, &psm2ctx->aid_len);
- psm2ctx->aid = WPACKET_get_curr(&pkt);
+ aid = WPACKET_get_curr(&pkt);
}
WPACKET_cleanup(&pkt);
+ if (aid && psm2ctx->aid_len)
+ memmove(psm2ctx->aid_buf, aid, psm2ctx->aid_len);
if (!EVP_DigestInit_ex2(psm2ctx->mdctx, psm2ctx->md, params)) {
UADK_ERR("failed to do digest init\n");
@@ -1240,6 +1245,7 @@ static const OSSL_PARAM *uadk_signature_sm2_gettable_ctx_params(ossl_unused void
static int uadk_signature_sm2_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params)
{
PROV_SM2_SIGN_CTX *psm2ctx = (PROV_SM2_SIGN_CTX *)vpsm2ctx;
+ unsigned char *aid = NULL;
OSSL_PARAM *p;
if (!psm2ctx) {
@@ -1247,8 +1253,10 @@ static int uadk_signature_sm2_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params)
return UADK_P_FAIL;
}
+ if (psm2ctx->aid_len)
+ aid = psm2ctx->aid_buf;
p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
- if (p && !OSSL_PARAM_set_octet_string(p, psm2ctx->aid, psm2ctx->aid_len)) {
+ if (p != NULL && !OSSL_PARAM_set_octet_string(p, aid, psm2ctx->aid_len)) {
UADK_ERR("failed to locate algorithm id\n");
return UADK_P_FAIL;
}
--
2.33.0
1
0
[PATCH 00/11] uadk: Fixing compression-related issues and functional enhancements
by ZongYu Wu 27 Apr '26
by ZongYu Wu 27 Apr '26
27 Apr '26
This patch set primarily fixes multiple issues related to compression in the uadk driver and adds some functional enhancements.
Main fixes include:
- Resolving the compression status issue when the storage buffer is not cleared
- Moving the tail packet append function to the hisi_comp.c file
- Removing redundant print information in v1/hisi_zip_udrv
- Fixing the hashjoin key alignment size issue
- Cleaning up wd_agg code
- Addressing some code parameter issues
- Fixing large number comparison issues
- Correcting the HPRE parameter comparison method
- Supporting empty final blocks in stream mode
- Fixing long timeout issues in synchronous mode when a device failure occurs.
Chenghai Huang (4):
uadk: clear the literal length in the ctx of all LZ77 algorithms
uadk: fix the status of compression when store buffer is not yet
cleared
uadk: move tail packet appending function to hisi_comp.c
uadk: delete redundant print messages for v1/hisi_zip_udrv
Longfang Liu (3):
uadk: bugfix some code parameter issues.
uadk: bugfix big number comparison issues
uadk: bugfix HPRE parameter comparison method
Wenkai Lin (2):
uadk: fix for hashjoin key align size
uadk: clean code for wd_agg
ZongYu Wu (1):
uadk: support empty final block for raw DEFLATE in stream mode
lizhi (1):
uadk/v1: fix long timeout of asymmetric algorithm in sync mode during
device failure
drv/hisi_comp.c | 111 +++++++++++++++++++++++++++++--------
drv/hisi_dae_join_gather.c | 2 +-
drv/hisi_hpre.c | 23 +++++---
drv/hisi_sec.c | 2 +-
include/drv/wd_comp_drv.h | 2 +
include/wd_internal.h | 2 +
libwd.map | 1 +
v1/drv/hisi_zip_udrv.c | 33 ++++-------
v1/wd_dh.c | 12 ++--
v1/wd_ecc.c | 12 ++--
v1/wd_rsa.c | 14 +++--
v1/wd_util.c | 31 +++++++++++
v1/wd_util.h | 2 +
wd.c | 19 +++++++
wd_aead.c | 4 +-
wd_agg.c | 34 ++++++------
wd_cipher.c | 2 +-
wd_comp.c | 72 +-----------------------
wd_join_gather.c | 2 +-
19 files changed, 218 insertions(+), 162 deletions(-)
--
2.33.0
1
11
From: Junchong Pan <panjunchong(a)h-partners.com>
Signed-off-by: Junchong Pan <panjunchong(a)h-partners.com>
---
Makefile.am | 2 +-
test/hisi_hpre_test/Makefile.am | 1 +
uadk_tool/Makefile.am | 14 +-
uadk_tool/benchmark/sec_soft3_benchmark.c | 1431 +++++++++++++++++++++
uadk_tool/benchmark/sec_soft3_benchmark.h | 8 +
uadk_tool/benchmark/uadk_benchmark.c | 18 +-
uadk_tool/test/comp_lib.c | 21 +-
uadk_tool/test/comp_lib.h | 10 +
uadk_tool/test/comp_main.c | 8 +-
uadk_tool/test/uadk_test.c | 4 +-
10 files changed, 1499 insertions(+), 18 deletions(-)
create mode 100644 uadk_tool/benchmark/sec_soft3_benchmark.c
create mode 100644 uadk_tool/benchmark/sec_soft3_benchmark.h
diff --git a/Makefile.am b/Makefile.am
index 84c97e9..fe619f3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,7 +3,7 @@ AUTOMAKE_OPTIONS = foreign subdir-objects
AM_CFLAGS=-std=gnu11 -Wall -Werror -Wextra -Wno-unused-parameter -Wfloat-equal \
-fno-common -fno-strict-aliasing -I$(top_srcdir)/include
AM_CFLAGS+=-fPIC -fPIE -pie -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
- -O2 -ftrapv -Wl,-z,relro,-z,now -Wl,-s
+ -O0 -ftrapv -Wl,-z,relro,-z,now -g
AM_CFLAGS += -Wall -Wuninitialized -Wno-error -Wno-error=format -Wundef \
-Wunused -Wdate-time -Wfloat-equal -Wshadow -Wvla -Wdisabled-optimization \
-Wempty-body -Wignored-qualifiers -Wimplicit-fallthrough=3 -Wtype-limits \
diff --git a/test/hisi_hpre_test/Makefile.am b/test/hisi_hpre_test/Makefile.am
index 6cc8a37..e32ac95 100644
--- a/test/hisi_hpre_test/Makefile.am
+++ b/test/hisi_hpre_test/Makefile.am
@@ -14,5 +14,6 @@ endif
test_hisi_hpre_LDFLAGS=-Wl,-rpath,'/usr/local/lib'
if WITH_OPENSSL_DIR
AM_CFLAGS+= -DWITH_OPENSSL_DIR
+test_hisi_hpre_LDADD+= $(with_openssl_dir)/libcrypto.so.3
test_hisi_hpre_LDADD+= $(with_openssl_dir)/libcrypto_wd.so
endif
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
index 6fd9d95..ee7dea4 100644
--- a/uadk_tool/Makefile.am
+++ b/uadk_tool/Makefile.am
@@ -1,9 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 -I./include
AUTOMAKE_OPTIONS = foreign subdir-objects
-AM_CFLAGS=-Wall -Werror -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/benchmark/include \
+AM_CFLAGS=-Wall -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/benchmark/include \
-pthread
AM_CFLAGS += -fPIC -fPIE -pie -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
--O2 -ftrapv -Wl,-z,now -Wl,-s
+-O0 -ftrapv -Wl,-z,now -g
#AUTOMAKE_OPTIONS = subdir-objects
@@ -50,14 +50,18 @@ endif
if WITH_OPENSSL_DIR
AM_CFLAGS+= -DWITH_OPENSSL_DIR -I$(with_openssl_dir)/include
+AM_CFLAGS+= -DHAVE_OPENSSL3=$(shell echo '#include <openssl/opensslv.h>' | \
+ $(CC) -E -I$(with_openssl_dir)/include - | grep 'OPENSSL_VERSION_MAJOR' | sed 's/#define OPENSSL_VERSION_MAJOR //')
+
+uadk_tool_SOURCES+=test/comp_main.c test/comp_main.h test/comp_lib.c test/comp_lib.h
+# uadk_tool_SOURCES+=benchmark/sec_soft_benchmark.c benchmark/sec_soft_benchmark.h
+uadk_tool_SOURCES+=benchmark/sec_soft3_benchmark.c benchmark/sec_soft3_benchmark.h
-uadk_tool_SOURCES+=benchmark/sec_soft_benchmark.c benchmark/sec_soft_benchmark.h \
- test/comp_main.c test/comp_main.h test/comp_lib.c test/comp_lib.h
if WD_STATIC_DRV
uadk_tool_LDADD+= $(with_openssl_dir)/libcrypto.a
else
-uadk_tool_LDADD+= $(with_openssl_dir)/libcrypto.so.1.1
+uadk_tool_LDADD+= $(with_openssl_dir)/libcrypto.so.3
endif
endif
diff --git a/uadk_tool/benchmark/sec_soft3_benchmark.c b/uadk_tool/benchmark/sec_soft3_benchmark.c
new file mode 100644
index 0000000..8d40074
--- /dev/null
+++ b/uadk_tool/benchmark/sec_soft3_benchmark.c
@@ -0,0 +1,1431 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+
+#define _GNU_SOURCE
+#include "openssl/async.h"
+#include "openssl/bn.h"
+#include "openssl/crypto.h"
+#include "openssl/engine.h"
+#include "openssl/err.h"
+#include "openssl/evp.h"
+#include "openssl/ossl_typ.h"
+#include "openssl/objects.h"
+#include "openssl/ssl.h"
+#include "openssl/provider.h"
+#include "openssl/x509.h"
+#include "openssl/param_build.h"
+
+#include "include/wd_cipher.h"
+#include "include/wd_digest.h"
+#include "sec_soft3_benchmark.h"
+
+#define SSL_TST_PRT printf
+#define ENV_STRING_LEN 256
+
+struct soft_bd {
+ u8 *src;
+ u8 *dst;
+};
+
+struct bd_pool {
+ struct soft_bd *bds;
+};
+
+struct thread_pool {
+ struct bd_pool *pool;
+ u8 *iv;
+ u8 *key;
+} g_soft_pool;
+
+typedef struct soft_thread_res {
+ const EVP_CIPHER *evp_cipher;
+ const EVP_MD *evp_md;
+ OSSL_PROVIDER *engine;
+ u32 subtype;
+ u32 mode;
+ u32 keysize;
+ u32 optype;
+ u32 td_id;
+ u32 engine_flag;
+ u32 sync_mode;
+} soft_thread;
+
+typedef struct soft_jobs_res {
+ const EVP_CIPHER *evp_cipher;
+ const EVP_MD *evp_md;
+ OSSL_PROVIDER *engine;
+ u32 subtype;
+ u32 mode;
+ u32 keysize;
+ u32 optype;
+ u32 td_id;
+ u32 jobid;
+} jobs_data;
+
+typedef struct soft_loop_args {
+ ASYNC_JOB *in_job;
+ ASYNC_WAIT_CTX *wait_ctx;
+ bool job_valid;
+} jobs_args;
+
+#define MAX_IVK_LENTH 64
+#define DEF_IVK_DATA 0xAA
+#define MAX_JOBS_NUM MAX_CTX_NUM
+
+static unsigned int g_thread_num;
+static unsigned int g_jobsnum;
+static unsigned int g_pktlen;
+
+static int init_soft_bd_pool(void)
+{
+ unsigned long step;
+ int fill_size;
+ int i, j;
+
+ // make the block not align to 4K
+ step = sizeof(char) * g_pktlen * 2;
+ if (g_pktlen > MAX_IVK_LENTH)
+ fill_size = MAX_IVK_LENTH;
+ else
+ fill_size = g_pktlen;
+
+ g_soft_pool.iv = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
+ g_soft_pool.key = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char));
+
+ g_soft_pool.pool = malloc(g_thread_num * sizeof(struct bd_pool));
+ if (!g_soft_pool.pool) {
+ SSL_TST_PRT("init openssl pool alloc thread failed!\n");
+ return -ENOMEM;
+ } else {
+ for (i = 0; i < g_thread_num; i++) {
+ g_soft_pool.pool[i].bds = malloc(MAX_POOL_LENTH *
+ sizeof(struct soft_bd));
+ if (!g_soft_pool.pool[i].bds) {
+ SSL_TST_PRT("init openssl bds alloc failed!\n");
+ goto malloc_error1;
+ }
+ for (j = 0; j < MAX_POOL_LENTH; j++) {
+ g_soft_pool.pool[i].bds[j].src = malloc(step);
+ if (!g_soft_pool.pool[i].bds[j].src)
+ goto malloc_error2;
+ g_soft_pool.pool[i].bds[j].dst = malloc(step);
+ if (!g_soft_pool.pool[i].bds[j].dst)
+ goto malloc_error3;
+
+ get_rand_data(g_soft_pool.pool[i].bds[j].src, fill_size);
+ }
+ }
+ }
+
+ return 0;
+
+malloc_error3:
+ free(g_soft_pool.pool[i].bds[j].src);
+malloc_error2:
+ for (j--; j >= 0; j--) {
+ free(g_soft_pool.pool[i].bds[j].src);
+ free(g_soft_pool.pool[i].bds[j].dst);
+ }
+malloc_error1:
+ for (i--; i >= 0; i--) {
+ for (j = 0; j < MAX_POOL_LENTH; j++) {
+ free(g_soft_pool.pool[i].bds[j].src);
+ free(g_soft_pool.pool[i].bds[j].dst);
+ }
+ free(g_soft_pool.pool[i].bds);
+ g_soft_pool.pool[i].bds = NULL;
+ }
+ free(g_soft_pool.pool);
+ g_soft_pool.pool = NULL;
+
+ free(g_soft_pool.iv);
+ free(g_soft_pool.key);
+
+ SSL_TST_PRT("init openssl bd pool alloc failed!\n");
+ return -ENOMEM;
+}
+
+static void free_soft_bd_pool(void)
+{
+ int i, j;
+
+ for (i = 0; i < g_thread_num; i++) {
+ if (g_soft_pool.pool[i].bds) {
+ for (j = 0; j < MAX_POOL_LENTH; j++) {
+ free(g_soft_pool.pool[i].bds[j].src);
+ free(g_soft_pool.pool[i].bds[j].dst);
+ }
+ }
+ free(g_soft_pool.pool[i].bds);
+ g_soft_pool.pool[i].bds = NULL;
+ }
+ free(g_soft_pool.pool);
+ g_soft_pool.pool = NULL;
+
+ free(g_soft_pool.iv);
+ free(g_soft_pool.key);
+}
+
+/*-------------------------------openssl benchmark main code-------------------------------------*/
+static int sec_soft_param_parse(soft_thread *tddata, struct acc_option *options)
+{
+ u32 algtype = options->algtype;
+ u32 optype = options->optype;
+ u8 keysize = 0;
+ u8 mode;
+
+ tddata->evp_cipher = NULL;
+ tddata->evp_md = NULL;
+
+ switch(algtype) {
+ case AES_128_ECB:
+ keysize = 16;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_aes_128_ecb();
+ break;
+ case AES_192_ECB:
+ keysize = 24;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_aes_192_ecb();
+ break;
+ case AES_256_ECB:
+ keysize = 32;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_aes_256_ecb();
+ break;
+ case AES_128_CBC:
+ keysize = 16;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_128_cbc();
+ break;
+ case AES_192_CBC:
+ keysize = 24;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_192_cbc();
+ break;
+ case AES_256_CBC:
+ keysize = 32;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_256_cbc();
+ break;
+ case AES_128_CTR:
+ keysize = 16;
+ mode = WD_CIPHER_CTR;
+ tddata->evp_cipher = EVP_aes_128_ctr();
+ break;
+ case AES_192_CTR:
+ keysize = 24;
+ mode = WD_CIPHER_CTR;
+ tddata->evp_cipher = EVP_aes_192_ctr();
+ break;
+ case AES_256_CTR:
+ keysize = 32;
+ mode = WD_CIPHER_CTR;
+ tddata->evp_cipher = EVP_aes_256_ctr();
+ break;
+ case AES_128_OFB:
+ keysize = 16;
+ mode = WD_CIPHER_OFB;
+ tddata->evp_cipher = EVP_aes_128_ofb();
+ break;
+ case AES_192_OFB:
+ keysize = 24;
+ mode = WD_CIPHER_OFB;
+ tddata->evp_cipher = EVP_aes_192_ofb();
+ break;
+ case AES_256_OFB:
+ keysize = 32;
+ mode = WD_CIPHER_OFB;
+ tddata->evp_cipher = EVP_aes_256_ofb();
+ break;
+ case AES_128_CFB:
+ keysize = 16;
+ mode = WD_CIPHER_CFB;
+ tddata->evp_cipher = EVP_aes_128_cfb();
+ break;
+ case AES_192_CFB:
+ keysize = 24;
+ mode = WD_CIPHER_CFB;
+ tddata->evp_cipher = EVP_aes_192_cfb();
+ break;
+ case AES_256_CFB:
+ keysize = 32;
+ mode = WD_CIPHER_CFB;
+ tddata->evp_cipher = EVP_aes_256_cfb();
+ break;
+ case AES_256_XTS:
+ keysize = 32;
+ mode = WD_CIPHER_XTS;
+ tddata->evp_cipher = EVP_aes_128_xts();
+ break;
+ case AES_512_XTS:
+ keysize = 64;
+ mode = WD_CIPHER_XTS;
+ tddata->evp_cipher = EVP_aes_256_xts();
+ break;
+ case DES3_128_ECB:
+ keysize = 16;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_des_ede_ecb();
+ break;
+ case DES3_192_ECB:
+ keysize = 24;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_des_ede3_ecb();
+ break;
+ case DES3_128_CBC:
+ keysize = 16;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_des_ede_cbc();
+ break;
+ case DES3_192_CBC:
+ keysize = 24;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_des_ede3_cbc();
+ break;
+#ifndef OPENSSL_NO_SM4
+ case SM4_128_ECB:
+ keysize = 16;
+ mode = WD_CIPHER_ECB;
+ tddata->evp_cipher = EVP_sm4_ecb();
+ break;
+ case SM4_128_CBC:
+ keysize = 16;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_sm4_cbc();
+ break;
+ case SM4_128_CTR:
+ keysize = 16;
+ mode = WD_CIPHER_CTR;
+ tddata->evp_cipher = EVP_sm4_ctr();
+ break;
+ case SM4_128_OFB:
+ keysize = 16;
+ mode = WD_CIPHER_OFB;
+ tddata->evp_cipher = EVP_sm4_ofb();
+ break;
+ case SM4_128_CFB:
+ keysize = 16;
+ mode = WD_CIPHER_CFB;
+ tddata->evp_cipher = EVP_sm4_cfb128();
+ break;
+ case SM4_128_XTS:
+ keysize = 16;
+ mode = WD_CIPHER_XTS;
+ break;
+#endif
+ case AES_128_CCM:
+ keysize = 16;
+ mode = WD_CIPHER_CCM;
+ tddata->evp_cipher = EVP_aes_128_ccm();
+ break;
+ case AES_192_CCM:
+ keysize = 24;
+ mode = WD_CIPHER_CCM;
+ tddata->evp_cipher = EVP_aes_192_ccm();
+ break;
+ case AES_256_CCM:
+ keysize = 32;
+ mode = WD_CIPHER_CCM;
+ tddata->evp_cipher = EVP_aes_256_ccm();
+ break;
+ case AES_128_GCM:
+ keysize = 16;
+ mode = WD_CIPHER_GCM;
+ tddata->evp_cipher = EVP_aes_128_gcm();
+ break;
+ case AES_192_GCM:
+ keysize = 24;
+ mode = WD_CIPHER_GCM;
+ tddata->evp_cipher = EVP_aes_192_gcm();
+ break;
+ case AES_256_GCM:
+ keysize = 32;
+ mode = WD_CIPHER_GCM;
+ tddata->evp_cipher = EVP_aes_256_gcm();
+ break;
+ case AES_128_CBC_SHA256_HMAC:
+ keysize = 16;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_128_cbc();
+ break;
+ case AES_192_CBC_SHA256_HMAC:
+ keysize = 24;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_192_cbc();
+ break;
+ case AES_256_CBC_SHA256_HMAC:
+ keysize = 32;
+ mode = WD_CIPHER_CBC;
+ tddata->evp_cipher = EVP_aes_256_cbc();
+ break;
+#ifndef OPENSSL_NO_SM4
+ case SM4_128_CCM:
+ keysize = 16;
+ mode = WD_CIPHER_CCM;
+ break;
+ case SM4_128_GCM:
+ keysize = 16;
+ mode = WD_CIPHER_GCM;
+ break;
+#endif
+ case SM3_ALG: // digest mode is optype
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sm3();
+ break;
+ case MD5_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_md5();
+ break;
+ case SHA1_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha1();
+ break;
+ case SHA256_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha256();
+ break;
+ case SHA224_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha224();
+ break;
+ case SHA384_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha384();
+ break;
+ case SHA512_ALG:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha512();
+ break;
+ case SHA512_224:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha512_224();
+ break;
+ case SHA512_256:
+ keysize = 4;
+ mode = optype;
+ tddata->evp_md = EVP_sha512_256();
+ break;
+ default:
+ SSL_TST_PRT("Fail to set sec alg\n");
+ return -EINVAL;
+ }
+
+ tddata->mode = mode;
+ tddata->keysize = keysize;
+ tddata->optype = options->optype;
+ tddata->subtype = options->subtype;
+
+ return 0;
+}
+
+static int sec_soft_cipher_jobfunc(void *args)
+{
+ jobs_data *jdata = (jobs_data *)args;
+ const EVP_CIPHER *evp_cipher = jdata->evp_cipher;
+ u32 optype = jdata->optype;
+ u32 jid = jdata->jobid;
+ struct bd_pool *soft_pool;
+ u8 *priv_iv, *priv_key;
+ int ret, outl, i;
+ EVP_CIPHER_CTX *ctx = NULL;
+ ASYNC_JOB *currjob;
+ u32 count = 0;
+ u8 *src, *dst;
+
+ currjob = ASYNC_get_current_job();
+ if (!currjob) {
+ SSL_TST_PRT("Error: not executing within a job\n");
+ return 0;
+ }
+
+ if (!evp_cipher) {
+ SSL_TST_PRT("Error: openssl not support!\n");
+ return 0;
+ }
+
+ if (jdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id %d out of range (max %d)\n", jdata->td_id, g_thread_num);
+ return 0;
+ }
+
+ soft_pool = &g_soft_pool.pool[jdata->td_id];
+ priv_iv = &g_soft_pool.iv[jdata->td_id];
+ priv_key = &g_soft_pool.key[jdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ ctx = EVP_CIPHER_CTX_new();
+ if (!ctx) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_new failed\n");
+ return 0;
+ }
+
+ OSSL_PARAM params[4];
+ size_t iv_len = EVP_CIPHER_get_iv_length(evp_cipher);
+
+ params[0] = OSSL_PARAM_construct_octet_string("key", priv_key, MAX_IVK_LENTH);
+ params[1] = OSSL_PARAM_construct_octet_string("iv", priv_iv, iv_len);
+ params[2] = OSSL_PARAM_construct_int("padding", 0);
+ params[3] = OSSL_PARAM_construct_end();
+
+ while (1) {
+ i = jid % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+ dst = soft_pool->bds[i].dst;
+
+ if (optype) {
+ EVP_DecryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, NULL);
+ EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_DecryptFinal_ex(ctx, dst, &outl);
+ } else {
+ EVP_EncryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, NULL);
+ EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_EncryptFinal_ex(ctx, dst, &outl);
+ }
+
+ ret = EVP_CIPHER_CTX_set_params(ctx, params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_set_params failed\n");
+ break;
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_CIPHER_CTX_free(ctx);
+
+ add_recv_data(count, g_pktlen);
+
+ return 0;
+}
+static int sec_soft_aead_jobfunc(void *args)
+{
+ jobs_data *jdata = (jobs_data *)args;
+ const EVP_CIPHER *evp_cipher = jdata->evp_cipher;
+ u32 optype = jdata->optype;
+ u32 jid = jdata->jobid;
+ struct bd_pool *soft_pool;
+ u8 *priv_iv, *priv_key;
+ int ret, outl, i;
+ EVP_CIPHER_CTX *ctx = NULL;
+ ASYNC_JOB *currjob;
+ u8 aad[13] = {0xcc};
+ u8 in_tag[12] = {0};
+ u8 out_tag[EVP_MAX_IV_LENGTH] = {0};
+ u32 count = 0;
+ u8 *src, *dst;
+ size_t taglen = 0;
+
+ currjob = ASYNC_get_current_job();
+ if (!currjob) {
+ SSL_TST_PRT("Error: not executing within a job\n");
+ return 0;
+ }
+
+ if (!evp_cipher) {
+ SSL_TST_PRT("Error: openssl not support!\n");
+ return 0;
+ }
+
+ if (jdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id %d out of range (max %d)\n", jdata->td_id, g_thread_num);
+ return 0;
+ }
+
+ soft_pool = &g_soft_pool.pool[jdata->td_id];
+ priv_iv = &g_soft_pool.iv[jdata->td_id];
+ priv_key = &g_soft_pool.key[jdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ ctx = EVP_CIPHER_CTX_new();
+ if (!ctx) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_new failed\n");
+ return 0;
+ }
+
+ while (1) {
+ i = jid % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+ dst = soft_pool->bds[i].dst;
+
+ OSSL_PARAM core_params[5];
+ int iv_len = EVP_CIPHER_get_iv_length(evp_cipher);
+ size_t key_len = MAX_IVK_LENTH;
+
+
+ memset(core_params, 0, sizeof(core_params));
+
+ core_params[0] = OSSL_PARAM_construct_octet_string("key", priv_key, key_len);
+ core_params[1] = OSSL_PARAM_construct_octet_string("iv", priv_iv, iv_len);
+
+ core_params[2] = OSSL_PARAM_construct_int("padding", 0);
+ core_params[3] = OSSL_PARAM_construct_end();
+
+ if (optype) {
+ EVP_DecryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, core_params);
+ EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_DecryptFinal_ex(ctx, dst + outl, &outl);
+ } else {
+ EVP_EncryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, core_params);
+ EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_EncryptFinal_ex(ctx, dst + outl, &outl);
+ }
+
+ if (jdata->mode == WD_CIPHER_CCM) {
+
+ taglen = 12;
+ OSSL_PARAM ccm_specific_params[3];
+ ccm_specific_params[0] = OSSL_PARAM_construct_size_t("taglen", &taglen);
+
+ int ccm_l = (iv_len - 1) - 1;
+ ccm_specific_params[1] = OSSL_PARAM_construct_int("L", &ccm_l);
+ ccm_specific_params[2] = OSSL_PARAM_construct_end();
+
+ ret = EVP_CIPHER_CTX_set_params(ctx, ccm_specific_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: CCM EVP_CIPHER_CTX_set_params failed\n");
+ break;
+ }
+ } else {
+
+ taglen = 16;
+ OSSL_PARAM gcm_specific_params[3];
+ gcm_specific_params[0] = OSSL_PARAM_construct_size_t("taglen", &taglen);
+
+ if (optype) {
+ gcm_specific_params[1] = OSSL_PARAM_construct_octet_string("tag", in_tag, sizeof(in_tag));
+ } else {
+ gcm_specific_params[1] = OSSL_PARAM_construct_octet_string("tag", out_tag, 0);
+ }
+ gcm_specific_params[2] = OSSL_PARAM_construct_end();
+
+ ret = EVP_CIPHER_CTX_set_params(ctx, gcm_specific_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: GCM EVP_CIPHER_CTX_set_params failed\n");
+ break;
+ }
+
+ OSSL_PARAM aad_params[] = {
+ OSSL_PARAM_construct_octet_string("aad", aad, sizeof(aad)),
+ OSSL_PARAM_construct_end()
+ };
+ ret = EVP_CIPHER_CTX_set_params(ctx, aad_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: GCM EVP_CIPHER_CTX_set_params(aad) failed\n");
+ break;
+ }
+ }
+
+ if (!optype && jdata->mode != WD_CIPHER_CCM) {
+ OSSL_PARAM get_tag_params[] = {
+ OSSL_PARAM_construct_octet_string("tag", out_tag, sizeof(out_tag)),
+ OSSL_PARAM_construct_end()
+ };
+ (void)EVP_CIPHER_CTX_get_params(ctx, get_tag_params);
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_CIPHER_CTX_free(ctx);
+ add_recv_data(count, g_pktlen);
+
+ return 0;
+}
+
+
+static int sec_soft_digest_jobfunc(void *args)
+{
+ jobs_data *jdata = (jobs_data *)args;
+ const EVP_MD *evp_md = jdata->evp_md;
+ u32 optype = jdata->optype;
+ u32 jid = jdata->jobid;
+ struct bd_pool *soft_pool;
+ u8 mac[EVP_MAX_MD_SIZE] = {0x00};
+ EVP_MD_CTX *md_ctx;
+ EVP_MAC *f_mac = NULL;
+ EVP_MAC_CTX *m_ctx = NULL;
+ ASYNC_JOB *currjob;
+ u32 ssl_size = 0;
+ u8 *priv_key, *src;
+ u32 count = 0;
+ size_t required_len = 0;
+ int i;
+
+ currjob = ASYNC_get_current_job();
+ if (!currjob) {
+ SSL_TST_PRT("Error: not executing within a job\n");
+ return 0;
+ }
+
+ if (!evp_md) {
+ SSL_TST_PRT("Error: openssl evp_md not support!\n");
+ return 0;
+ }
+
+ if (jdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id out of range\n");
+ return 0;
+ }
+
+ soft_pool = &g_soft_pool.pool[jdata->td_id];
+ priv_key = &g_soft_pool.key[jdata->td_id];
+
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ if (!optype) {
+ md_ctx = EVP_MD_CTX_new();
+ if (!md_ctx) {
+ SSL_TST_PRT("Error: EVP_MD_CTX_new failed\n");
+ return 0;
+ }
+
+ OSSL_PARAM params[3];
+ params[0] = OSSL_PARAM_construct_utf8_string("digest", (char *)EVP_MD_get0_name(evp_md), 0);
+ params[1] = OSSL_PARAM_construct_octet_string("key", priv_key, jdata->keysize);
+ params[2] = OSSL_PARAM_construct_end();
+
+ while (1) {
+ i = jid % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+
+ EVP_DigestInit_ex2(md_ctx, evp_md, params);
+ EVP_DigestUpdate(md_ctx, src, g_pktlen);
+ EVP_DigestFinal_ex(md_ctx, mac, &ssl_size);
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+ EVP_MD_CTX_free(md_ctx);
+
+ } else {
+ f_mac = EVP_MAC_fetch(NULL, "HMAC", NULL);
+ m_ctx = EVP_MAC_CTX_new(f_mac);
+ if (!m_ctx) {
+ SSL_TST_PRT("Error: EVP_MAC_CTX_new failed\n");
+ EVP_MAC_free(f_mac);
+ return 0;
+ }
+
+ OSSL_PARAM params[3];
+ params[0] = OSSL_PARAM_construct_utf8_string("digest", "SHA256", 0);
+ params[1] = OSSL_PARAM_construct_octet_string("key", priv_key, jdata->keysize);
+ params[2] = OSSL_PARAM_construct_end();
+
+ while (1) {
+ i = jid % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+
+ EVP_MAC_init(m_ctx, priv_key, jdata->keysize, params);
+ EVP_MAC_update(m_ctx, src, g_pktlen);
+ EVP_MAC_final(m_ctx, mac, &required_len, EVP_MAX_MD_SIZE);
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_MAC_CTX_free(m_ctx);
+ EVP_MAC_free(f_mac);
+ }
+
+ add_recv_data(count, g_pktlen);
+
+ return 0;
+}
+
+static void *sec_soft_async_run(void *arg)
+{
+ typedef int (*sec_soft_run)(void *arg);
+ sec_soft_run sec_soft_jobfunc = NULL;
+ soft_thread *pdata = (soft_thread *)arg;
+ jobs_args loop_jobs[MAX_JOBS_NUM];
+ OSSL_ASYNC_FD waitfd = 0;
+ jobs_data jobdata;
+ fd_set waitfdset;
+ size_t numfds = 0;
+ int i, j, k, ret;
+ int jobret = 0;
+ u32 valid_jobs = 0;
+ u32 jobs_num;
+
+ jobdata.evp_cipher = pdata->evp_cipher;
+ jobdata.evp_md = pdata->evp_md;
+ jobdata.keysize = pdata->keysize;
+ jobdata.mode = pdata->mode;
+ jobdata.optype = pdata->optype;
+ jobdata.subtype = pdata->subtype;
+ jobdata.td_id = pdata->td_id;
+ jobdata.engine = pdata->engine;
+
+ jobs_num = g_jobsnum;
+ if (jobs_num > MAX_JOBS_NUM) {
+ SSL_TST_PRT("Error: check async jobs num failed.\n");
+ return NULL;
+ }
+ memset(loop_jobs, 0x0, sizeof(jobs_args) * MAX_JOBS_NUM);
+
+ switch (pdata->subtype) {
+ case CIPHER_TYPE:
+ sec_soft_jobfunc = sec_soft_cipher_jobfunc;
+ break;
+ case AEAD_TYPE:
+ sec_soft_jobfunc = sec_soft_aead_jobfunc;
+ break;
+ case DIGEST_TYPE:
+ sec_soft_jobfunc = sec_soft_digest_jobfunc;
+ break;
+ }
+
+ /* one thread for one job */
+ for (i = 0; i < jobs_num; i++) {
+ loop_jobs[i].wait_ctx = ASYNC_WAIT_CTX_new();
+ if (!loop_jobs[i].wait_ctx) {
+ SSL_TST_PRT("Error: create ASYNC_WAIT_CTX failed\n");
+ goto async_error;
+ }
+
+ jobdata.jobid = i;
+ ret = ASYNC_start_job(&loop_jobs[i].in_job, loop_jobs[i].wait_ctx, &jobret,
+ sec_soft_jobfunc, (void *)&jobdata, sizeof(jobs_data));
+ switch(ret) {
+ case ASYNC_ERR:
+ SSL_TST_PRT("Error: start soft async job err.\n");
+ break;
+ case ASYNC_NO_JOBS:
+ SSL_TST_PRT("Error: can't get soft async job from job pool.\n");
+ break;
+ case ASYNC_PAUSE:
+ loop_jobs[i].job_valid = true;
+ valid_jobs++;
+ break;
+ case ASYNC_FINISH:
+ break;
+ default:
+ SSL_TST_PRT("Error: do soft async job err.\n");
+ }
+ }
+
+ j = valid_jobs;
+ while (j > 0) {
+ for (i = 0; i < jobs_num; i++) {
+ FD_ZERO(&waitfdset);
+ if (!loop_jobs[i].job_valid)
+ continue;
+
+ /* Wait for the job to be woken */
+ if (!ASYNC_WAIT_CTX_get_all_fds(loop_jobs[i].wait_ctx, NULL, &numfds) ||
+ numfds > 1) {
+ SSL_TST_PRT("Error: unexpected number of fds.\n");
+ continue;
+ }
+ ASYNC_WAIT_CTX_get_all_fds(loop_jobs[i].wait_ctx, &waitfd, &numfds);
+
+ FD_SET(waitfd, &waitfdset);
+ ret = select(waitfd + 1, &waitfdset, NULL, NULL, NULL);
+ if (ret == -1) {
+ SSL_TST_PRT("Error: select soft async job error.\n");
+ goto async_finish;
+ } else if (ret == 0 || (ret == -1 && errno == EINTR)) {
+ SSL_TST_PRT("Infor: select soft async job result continue.\n");
+ continue;
+ }
+
+ jobdata.jobid = i;
+ ret = ASYNC_start_job(&loop_jobs[i].in_job, loop_jobs[i].wait_ctx, &jobret,
+ sec_soft_jobfunc, (void *)&jobdata, sizeof(jobs_data));
+ switch(ret) {
+ case ASYNC_ERR:
+ loop_jobs[i].job_valid = false;
+ j--;
+ SSL_TST_PRT("Error: restart soft async job err.\n");
+ break;
+ case ASYNC_NO_JOBS:
+ SSL_TST_PRT("Error: can't get soft async job from job pool.\n");
+ break;
+ case ASYNC_PAUSE:
+ break;
+ case ASYNC_FINISH:
+ loop_jobs[i].job_valid = false;
+ j--;
+ break;
+ default:
+ SSL_TST_PRT("Error: do soft async job err.\n");
+ }
+ }
+ }
+
+async_finish:
+ i = jobs_num;
+async_error:
+ for (k = 0; k < i; k++)
+ ASYNC_WAIT_CTX_free(loop_jobs[k].wait_ctx);
+
+ add_send_complete();
+
+ return NULL;
+}
+
+static void *sec_soft_cipher_sync(void *arg)
+{
+ soft_thread *pdata = (soft_thread *)arg;
+ const EVP_CIPHER *evp_cipher = pdata->evp_cipher;
+ u32 optype = pdata->optype;
+ struct bd_pool *soft_pool;
+ u8 *priv_iv, *priv_key;
+ EVP_CIPHER_CTX *ctx = NULL;
+ u32 count = 0;
+ u8 *src, *dst;
+ int ret;
+ int outl = 0;
+
+ if (!evp_cipher) {
+ SSL_TST_PRT("Error: openssl not support!\n");
+ return NULL;
+ }
+
+ if (pdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id %d out of range (max %d)\n", pdata->td_id, g_thread_num);
+ return NULL;
+ }
+
+ soft_pool = &g_soft_pool.pool[pdata->td_id];
+ priv_iv = &g_soft_pool.iv[pdata->td_id];
+ priv_key = &g_soft_pool.key[pdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ ctx = EVP_CIPHER_CTX_new();
+ if (!ctx) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_new failed\n");
+ return NULL;
+ }
+
+ size_t iv_len = EVP_CIPHER_get_iv_length(evp_cipher);
+ size_t key_len = MAX_IVK_LENTH;
+
+ while (1) {
+ u32 local_count = count % MAX_POOL_LENTH;
+ src = soft_pool->bds[local_count].src;
+ dst = soft_pool->bds[local_count].dst;
+
+ if (optype) {
+ EVP_DecryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, NULL);
+ EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_CIPHER_CTX_set_padding(ctx, EVP_PADDING_ZERO);
+ EVP_DecryptFinal_ex(ctx, dst, &outl);
+ } else {
+ EVP_EncryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, NULL);
+ EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_CIPHER_CTX_set_padding(ctx, EVP_PADDING_ZERO);
+ EVP_EncryptFinal_ex(ctx, dst, &outl);
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_CIPHER_CTX_free(ctx);
+ cal_avg_latency(count);
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void *sec_soft_aead_sync(void *arg)
+{
+ soft_thread *pdata = (soft_thread *)arg;
+ const EVP_CIPHER *evp_cipher = pdata->evp_cipher;
+ u32 optype = pdata->optype;
+ u32 mode = pdata->mode;
+ struct bd_pool *soft_pool;
+ u8 *priv_iv, *priv_key;
+ EVP_CIPHER_CTX *ctx = NULL;
+ u8 aad[13] = {0xcc};
+ u8 tag[12] = {0};
+ u8 out_tag[EVP_MAX_IV_LENGTH] = {0};
+ u32 count = 0;
+ u8 *src, *dst;
+ int ret, i;
+ int outl = 0;
+ size_t taglen = 0;
+ int ccm_l = 0;
+
+ if (!evp_cipher) {
+ SSL_TST_PRT("Error: openssl not support!\n");
+ return NULL;
+ }
+
+ if (pdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id out of range\n");
+ return NULL;
+ }
+
+ soft_pool = &g_soft_pool.pool[pdata->td_id];
+ priv_iv = &g_soft_pool.iv[pdata->td_id];
+ priv_key = &g_soft_pool.key[pdata->td_id];
+
+ memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH);
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ ctx = EVP_CIPHER_CTX_new();
+ if (!ctx) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_new failed\n");
+ return NULL;
+ }
+
+ while (1) {
+ i = count % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+ dst = soft_pool->bds[i].dst;
+
+ OSSL_PARAM params[10];
+ int param_idx = 0;
+
+ params[param_idx++] = OSSL_PARAM_construct_utf8_string("cipher", (char *)EVP_CIPHER_get0_name(evp_cipher), 0);
+ params[param_idx++] = OSSL_PARAM_construct_octet_string("key", priv_key, MAX_IVK_LENTH);
+ params[param_idx++] = OSSL_PARAM_construct_octet_string("iv", priv_iv, EVP_CIPHER_get_iv_length(evp_cipher));
+
+ if (mode == WD_CIPHER_CCM) {
+ taglen = 12;
+ params[param_idx++] = OSSL_PARAM_construct_size_t("taglen", &taglen);
+ ccm_l = (EVP_CIPHER_get_iv_length(evp_cipher) - 1) - 1;
+ params[param_idx++] = OSSL_PARAM_construct_int("ccm_l", &ccm_l);
+ } else {
+ taglen = 16;
+ params[param_idx++] = OSSL_PARAM_construct_size_t("taglen", &taglen);
+ ccm_l = (EVP_CIPHER_get_iv_length(evp_cipher) - 1) - 1;
+ params[param_idx++] = OSSL_PARAM_construct_int("ccm_l", &ccm_l);
+ }
+ params[param_idx++] = OSSL_PARAM_construct_end();
+
+ if (optype) {
+ ret = EVP_DecryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, params);
+ } else {
+ ret = EVP_EncryptInit_ex2(ctx, evp_cipher, priv_key, priv_iv, params);
+ }
+
+ if (optype) {
+ OSSL_PARAM tag_params[] = {
+ OSSL_PARAM_construct_octet_string("tag", tag, sizeof(tag)),
+ OSSL_PARAM_construct_end()
+ };
+ ret = EVP_CIPHER_CTX_set_params(ctx, tag_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_set_params(tag) failed on decrypt\n");
+ break;
+ }
+
+ OSSL_PARAM aad_params[] = {
+ OSSL_PARAM_construct_octet_string("aad", aad, sizeof(aad)),
+ OSSL_PARAM_construct_end()
+ };
+ ret = EVP_CIPHER_CTX_set_params(ctx, aad_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_set_params(aad) failed on decrypt\n");
+ break;
+ }
+
+ EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_DecryptFinal_ex(ctx, dst + outl, &outl);
+
+ } else {
+ OSSL_PARAM aad_params[] = {
+ OSSL_PARAM_construct_octet_string("aad", aad, sizeof(aad)),
+ OSSL_PARAM_construct_end()
+ };
+ ret = EVP_CIPHER_CTX_set_params(ctx, aad_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_CIPHER_CTX_set_params(aad) failed on encrypt\n");
+ break;
+ }
+
+ EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen);
+ EVP_EncryptFinal_ex(ctx, dst + outl, &outl);
+ }
+
+ if (!optype && mode != WD_CIPHER_CCM) {
+ OSSL_PARAM get_tag_params[] = {
+ OSSL_PARAM_construct_octet_string("tag", out_tag, sizeof(out_tag)),
+ OSSL_PARAM_construct_end()
+ };
+ (void)EVP_CIPHER_CTX_get_params(ctx, get_tag_params);
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_CIPHER_CTX_free(ctx);
+
+ cal_avg_latency(count);
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void *sec_soft_digest_sync(void *arg)
+{
+ soft_thread *pdata = (soft_thread *)arg;
+ const EVP_CIPHER *evp_cipher = pdata->evp_cipher;
+ const EVP_MD *evp_md = pdata->evp_md;
+ u32 optype = pdata->optype;
+ u8 mac[EVP_MAX_MD_SIZE] = {0x00};
+ struct bd_pool *soft_pool;
+ EVP_MD_CTX *md_ctx = NULL;
+ EVP_MAC *f_mac = NULL;
+ EVP_MAC_CTX *m_ctx = NULL;
+ u8 *priv_key, *src;
+ size_t mac_size = 0;
+ u32 count = 0;
+ int i;
+ int ret = 0;
+ u32 ssl_size = 0;
+
+ if (!evp_cipher && !evp_md) {
+ SSL_TST_PRT("Error: openssl not support! No cipher or md provided.\n");
+ return NULL;
+ }
+
+ if (pdata->td_id > g_thread_num) {
+ SSL_TST_PRT("Error: thread id %d out of range (max %d)\n", pdata->td_id, g_thread_num);
+ return NULL;
+ }
+
+ soft_pool = &g_soft_pool.pool[pdata->td_id];
+ priv_key = &g_soft_pool.key[pdata->td_id];
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
+
+ if (!optype) {
+ md_ctx = EVP_MD_CTX_new();
+ if (!md_ctx) {
+ SSL_TST_PRT("Error: EVP_MD_CTX_new failed\n");
+ return NULL;
+ }
+
+ OSSL_PARAM digest_params[] = {
+ OSSL_PARAM_construct_utf8_string("digest", (char *)EVP_MD_get0_name(evp_md), 0),
+ OSSL_PARAM_construct_end()
+ };
+
+ while (1) {
+ i = count % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+
+ ret = EVP_DigestInit_ex2(md_ctx, evp_md, digest_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_DigestInit_ex2 failed\n");
+ break;
+ }
+
+ ret = EVP_DigestUpdate(md_ctx, src, g_pktlen);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_DigestUpdate failed\n");
+ break;
+ }
+
+ ret = EVP_DigestFinal_ex(md_ctx, mac, &ssl_size);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_DigestFinal_ex failed\n");
+ break;
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_MD_CTX_free(md_ctx);
+ } else {
+ f_mac = EVP_MAC_fetch(NULL, "HMAC", NULL);
+ if (!f_mac) {
+ SSL_TST_PRT("Error: EVP_MAC_fetch(HMAC) failed\n");
+ return NULL;
+ }
+
+ m_ctx = EVP_MAC_CTX_new(f_mac);
+ if (!m_ctx) {
+ SSL_TST_PRT("Error: EVP_MAC_CTX_new failed\n");
+ EVP_MAC_free(f_mac);
+ return NULL;
+ }
+
+ OSSL_PARAM mac_params[] = {
+ OSSL_PARAM_construct_utf8_string("digest", "SHA256", 0),
+ OSSL_PARAM_construct_octet_string("key", priv_key, pdata->keysize),
+ OSSL_PARAM_construct_end()
+ };
+
+ while (1) {
+ i = count % MAX_POOL_LENTH;
+ src = soft_pool->bds[i].src;
+
+ ret = EVP_MAC_init(m_ctx, priv_key, pdata->keysize, mac_params);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_MAC_init failed\n");
+ break;
+ }
+
+ ret = EVP_MAC_update(m_ctx, src, g_pktlen);
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_MAC_update failed\n");
+ break;
+ }
+
+ ret = EVP_MAC_final(m_ctx, mac, &mac_size, sizeof(mac));
+ if (ret != 1) {
+ SSL_TST_PRT("Error: EVP_MAC_final failed\n");
+ break;
+ }
+
+ count++;
+ if (get_run_state() == 0)
+ break;
+ }
+
+ EVP_MAC_CTX_free(m_ctx);
+ EVP_MAC_free(f_mac);
+ }
+
+ if(optype && !f_mac) {
+ return NULL;
+ }
+ if(!optype && !md_ctx) {
+ return NULL;
+ }
+
+ cal_avg_latency(count);
+ add_recv_data(count, g_pktlen);
+
+ return NULL;
+}
+
+static void uadk_engine_set_env(soft_thread *options)
+{
+ char env_string[ENV_STRING_LEN] = {0};
+ char *var_name = NULL;
+
+ switch(options->subtype) {
+ case CIPHER_TYPE:
+ var_name = "WD_CIPHER_CTX_NUM";
+ break;
+ case AEAD_TYPE:
+ var_name = "WD_CIPHER_CTX_NUM";
+ break;
+ case DIGEST_TYPE:
+ var_name = "WD_DIGEST_CTX_NUM";
+ break;
+ default:
+ return;
+ }
+
+ unsetenv(var_name);
+
+ /* uadk will request ctxs from env param */
+ if (options->sync_mode) // async mode
+ (void)snprintf(env_string, ENV_STRING_LEN, "%s%d%s%d%s",
+ "async:", g_jobsnum,"@0,async:", g_jobsnum, "@2");
+ else
+ (void)snprintf(env_string, ENV_STRING_LEN, "%s%d%s%d%s",
+ "sync:", g_jobsnum,"@0,sync:", g_jobsnum, "@2");
+ (void)setenv(var_name, env_string, 1);
+}
+
+static int uadk_provider_register(soft_thread *options, char *engine_name)
+{
+ if (!options->engine_flag)
+ return 0;
+
+ /* Set env param for uadk engine */
+ uadk_engine_set_env(options);
+ OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
+
+ options->engine = OSSL_PROVIDER_load(NULL, engine_name);
+ if (!options->engine) {
+ SSL_TST_PRT("setup uadk engine failed!\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void uadk_provider_unregister(soft_thread *options)
+{
+ if (!options->engine_flag)
+ return;
+
+ if (options->engine) {
+ OSSL_PROVIDER_unload(options->engine);
+ options->engine = NULL;
+ }
+}
+
+int sec_soft_sync_threads(struct acc_option *options)
+{
+ typedef void *(*sec_sync_run)(void *arg);
+ sec_sync_run soft_sec_sync_run = NULL;
+ soft_thread threads_args[THREADS_NUM];
+ soft_thread threads_option;
+ pthread_t tdid[THREADS_NUM];
+ int i, ret;
+
+ /* Alg param parse and set to thread data */
+ ret = sec_soft_param_parse(&threads_option, options);
+ if (ret)
+ return ret;
+
+ threads_option.engine_flag = options->engine_flag;
+ threads_option.sync_mode = options->syncmode;
+ ret = uadk_provider_register(&threads_option, options->engine);
+ if (ret)
+ return ret;
+
+
+ switch (options->subtype) {
+ case CIPHER_TYPE:
+ SSL_TST_PRT(" --- CIPHER_TYPE\n");
+ soft_sec_sync_run = sec_soft_cipher_sync;
+ break;
+ case AEAD_TYPE:
+ SSL_TST_PRT(" --- AEAD_TYPE\n");
+ soft_sec_sync_run = sec_soft_aead_sync;
+ break;
+ case DIGEST_TYPE:
+ SSL_TST_PRT(" --- DIGEST_TYPE\n");
+ soft_sec_sync_run = sec_soft_digest_sync;
+ break;
+ }
+
+
+
+ for (i = 0; i < g_thread_num; i++) {
+ threads_args[i].evp_cipher = threads_option.evp_cipher;
+ threads_args[i].evp_md = threads_option.evp_md;
+ threads_args[i].subtype = threads_option.subtype;
+ threads_args[i].mode = threads_option.mode;
+ threads_args[i].keysize = threads_option.keysize;
+ threads_args[i].optype = threads_option.optype;
+ threads_args[i].td_id = i;
+ threads_args[i].engine_flag = options->engine_flag;
+ threads_args[i].engine = threads_option.engine;
+ ret = pthread_create(&tdid[i], NULL, soft_sec_sync_run, &threads_args[i]);
+ if (ret) {
+ SSL_TST_PRT("Create sync thread fail!\n");
+ goto sync_error;
+ }
+ }
+
+
+ /* Join thread */
+ for (i = 0; i < g_thread_num; i++) {
+ ret = pthread_join(tdid[i], NULL);
+ if (ret) {
+ SSL_TST_PRT("Join sync thread fail!\n");
+ goto sync_error;
+ }
+ }
+
+sync_error:
+ uadk_provider_unregister(&threads_option);
+ return ret;
+}
+
+int sec_soft_async_threads(struct acc_option *options)
+{
+ soft_thread threads_args[THREADS_NUM];
+ soft_thread threads_option;
+ pthread_t tdid[THREADS_NUM];
+ int i, ret;
+
+ /* Alg param parse and set to thread data */
+ ret = sec_soft_param_parse(&threads_option, options);
+ if (ret)
+ return ret;
+
+ threads_option.engine_flag = options->engine_flag;
+ threads_option.sync_mode = options->syncmode;
+ ret = uadk_provider_register(&threads_option, options->engine);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < g_thread_num; i++) {
+ threads_args[i].evp_cipher = threads_option.evp_cipher;
+ threads_args[i].evp_md = threads_option.evp_md;
+ threads_args[i].subtype = threads_option.subtype;
+ threads_args[i].mode = threads_option.mode;
+ threads_args[i].keysize = threads_option.keysize;
+ threads_args[i].optype = threads_option.optype;
+ threads_args[i].td_id = i;
+ threads_args[i].engine_flag = options->engine_flag;
+ threads_args[i].engine = threads_option.engine;
+ ret = pthread_create(&tdid[i], NULL, sec_soft_async_run, &threads_args[i]);
+ if (ret) {
+ SSL_TST_PRT("Create async thread fail!\n");
+ goto async_error;
+ }
+ }
+
+ /* Join thread */
+ for (i = 0; i < g_thread_num; i++) {
+ ret = pthread_join(tdid[i], NULL);
+ if (ret) {
+ SSL_TST_PRT("Join async thread fail!\n");
+ goto async_error;
+ }
+ }
+
+async_error:
+ uadk_provider_unregister(&threads_option);
+ return ret;
+}
+
+int sec_soft3_benchmark(struct acc_option *options)
+{
+ u32 ptime;
+ int ret;
+
+ signal(SIGSEGV, segmentfault_handler);
+ g_thread_num = options->threads;
+ g_pktlen = options->pktlen;
+ g_jobsnum = options->ctxnums;
+ if (options->optype > WD_CIPHER_DECRYPTION) {
+ SSL_TST_PRT("SEC optype error: %u\n", options->optype);
+ return -EINVAL;
+ }
+
+ ret = init_soft_bd_pool();
+ if (ret)
+ return ret;
+
+ get_pid_cpu_time(&ptime);
+ time_start(options->times);
+ if (options->syncmode)
+ ret = sec_soft_async_threads(options);
+ else
+ ret = sec_soft_sync_threads(options);
+ cal_perfermance_data(options, ptime);
+ if (ret)
+ return ret;
+
+ free_soft_bd_pool();
+
+ return 0;
+}
diff --git a/uadk_tool/benchmark/sec_soft3_benchmark.h b/uadk_tool/benchmark/sec_soft3_benchmark.h
new file mode 100644
index 0000000..f10bcb2
--- /dev/null
+++ b/uadk_tool/benchmark/sec_soft3_benchmark.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+#ifndef SEC_SOFT3_BENCHMARK_H
+#define SEC_SOFT3_BENCHMARK_H
+
+#include "uadk_benchmark.h"
+
+extern int sec_soft3_benchmark(struct acc_option *options);
+#endif /* SEC_SOFT_BENCHMARK_H */
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index d8f066f..756c3ad 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -8,7 +8,11 @@
#include "uadk_benchmark.h"
#include "sec_uadk_benchmark.h"
#include "sec_wd_benchmark.h"
-#include "sec_soft_benchmark.h"
+// # if OPENSSL_VERSION_NUMBER < 0x30000000L
+// #include "sec_soft_benchmark.h"
+// # else
+#include "sec_soft3_benchmark.h"
+// # endif
#include "hpre_uadk_benchmark.h"
#include "hpre_wd_benchmark.h"
@@ -568,11 +572,17 @@ static int benchmark_run(struct acc_option *option)
ret = sec_wd_benchmark(option);
}
usleep(20000);
-#ifdef HAVE_CRYPTO
+// #ifdef HAVE_CRYPTO
+// # if OPENSSL_VERSION_NUMBER < 0x30000000L
+// if (option->modetype == SOFT_MODE) {
+// ret = sec_soft_benchmark(option);
+// }
+// # else
if (option->modetype == SOFT_MODE) {
- ret = sec_soft_benchmark(option);
+ ret = sec_soft3_benchmark(option);
}
-#endif
+// # endif
+// #endif
break;
case HPRE_TYPE:
if (option->modetype == SVA_MODE) {
diff --git a/uadk_tool/test/comp_lib.c b/uadk_tool/test/comp_lib.c
index 014aa98..39bc526 100644
--- a/uadk_tool/test/comp_lib.c
+++ b/uadk_tool/test/comp_lib.c
@@ -10,6 +10,12 @@
#include <math.h>
#include <sys/mman.h>
#include <zlib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+// #include "openssl/md5.h"
+
+
#include "comp_lib.h"
@@ -255,9 +261,18 @@ int calculate_md5(comp_md5_t *md5, const void *buf, size_t len)
{
if (!md5 || !buf || !len)
return -EINVAL;
+
+# if OPENSSL_VERSION_NUMBER < 0x30000000L
MD5_Init(&md5->md5_ctx);
MD5_Update(&md5->md5_ctx, buf, len);
MD5_Final(md5->md, &md5->md5_ctx);
+# else
+ md5->ctx = EVP_MD_CTX_new();
+ EVP_DigestInit_ex2(md5->ctx, EVP_md5(), NULL);
+ EVP_DigestUpdate(md5->ctx, buf, len);
+ EVP_DigestFinal_ex(md5->ctx, md5->md, NULL);
+ EVP_MD_CTX_free(md5->ctx);
+# endif
return 0;
}
@@ -425,7 +440,7 @@ static int chunk_inflate(void *in, size_t in_sz, void *out, size_t *out_sz,
do {
ret = inflate(&strm, Z_NO_FLUSH);
if ((ret < 0) || (ret == Z_NEED_DICT)) {
- COMP_TST_PRT("zlib error %d - %s\n", ret, strm.msg);
+ COMP_TST_PRT("zlib error %d - %s %s\n", ret, strm.msg, __func__);
goto out;
}
if (!strm.avail_out) {
@@ -1319,7 +1334,7 @@ int hizip_check_output(void *buf, size_t size, size_t *checked,
do {
ret = inflate(&stream, Z_NO_FLUSH);
if (ret < 0 || ret == Z_NEED_DICT) {
- COMP_TST_PRT("zlib error %d - %s\n", ret, stream.msg);
+ COMP_TST_PRT("zlib error %d - %s %s\n", ret, stream.msg, __func__);
ret = -ENOSR;
break;
}
@@ -1387,7 +1402,7 @@ int zlib_deflate(void *output, unsigned int out_size,
do {
ret = deflate(&stream, Z_FINISH);
if (ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR) {
- COMP_TST_PRT("zlib error %d - %s\n", ret, stream.msg);
+ COMP_TST_PRT("zlib error %d - %s %s\n", ret, stream.msg, __func__);
ret = -ENOSR;
break;
} else if (!stream.avail_in) {
diff --git a/uadk_tool/test/comp_lib.h b/uadk_tool/test/comp_lib.h
index c37a226..9eb7a31 100644
--- a/uadk_tool/test/comp_lib.h
+++ b/uadk_tool/test/comp_lib.h
@@ -22,6 +22,12 @@
#include "include/wd_comp.h"
#include "include/wd_sched.h"
+# if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#include "openssl/opensslv.h"
+#include "openssl/evp.h"
+#include "openssl/ossl_typ.h"
+# endif
+
#define SYS_ERR_COND(cond, msg, ...) \
do { \
if (cond) { \
@@ -120,7 +126,11 @@ struct test_options {
};
typedef struct _comp_md5_t {
+# if OPENSSL_VERSION_NUMBER < 0x30000000L
MD5_CTX md5_ctx;
+# else
+ EVP_MD_CTX *ctx;
+# endif
unsigned char md[MD5_DIGEST_LENGTH];
} comp_md5_t;
diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c
index 24f52d2..81b213a 100644
--- a/uadk_tool/test/comp_main.c
+++ b/uadk_tool/test/comp_main.c
@@ -86,7 +86,7 @@ static void *sw_dfl_hw_ifl(void *arg)
void *tbuf;
size_t tbuf_sz;
chunk_list_t *tlist;
- comp_md5_t final_md5 = {{0}};
+ comp_md5_t final_md5 = {0};
int i, ret;
__u32 tout_sz;
@@ -230,7 +230,7 @@ static void *hw_dfl_sw_ifl(void *arg)
void *tbuf;
size_t tbuf_sz;
chunk_list_t *tlist;
- comp_md5_t final_md5 = {{0}};
+ comp_md5_t final_md5 = {0};
int i, ret;
__u32 tmp_sz;
@@ -374,7 +374,7 @@ static void *hw_dfl_hw_ifl(void *arg)
void *tbuf;
size_t tbuf_sz;
chunk_list_t *tlist;
- comp_md5_t final_md5 = {{0}};
+ comp_md5_t final_md5 = {0};
int i, ret;
__u32 tmp_sz, tout_sz;
@@ -886,6 +886,7 @@ static int test_hw(struct test_options *opts, char *model)
goto out_src;
opts->total_len = statbuf.st_size;
info.in_size = opts->total_len;
+ COMP_TST_PRT("in_size : %d\n", info.in_size);
if (ifl_flag)
info.out_size = opts->total_len * INFLATION_RATIO;
else
@@ -898,6 +899,7 @@ static int test_hw(struct test_options *opts, char *model)
if (opts->is_file) {
ret = load_file_data(&info);
+ COMP_TST_PRT("file_size : %d\n", ret);
if (ret < 0)
goto out_buf;
} else {
diff --git a/uadk_tool/test/uadk_test.c b/uadk_tool/test/uadk_test.c
index 536861a..aa885d1 100644
--- a/uadk_tool/test/uadk_test.c
+++ b/uadk_tool/test/uadk_test.c
@@ -63,10 +63,10 @@ void acc_test_run(int argc, char *argv[])
(void)test_hpre_entry(argc, argv);
} else if (!strcmp(input_module, "sec")) {
(void)test_sec_entry(argc, argv);
-#ifdef HAVE_CRYPTO
+// #ifdef HAVE_CRYPTO
} else if (!strcmp(input_module, "zip")) {
(void)test_comp_entry(argc, argv);
-#endif
+// #endif
} else {
print_test_help();
printf("failed to parse module parameter!\n");
--
2.33.0
1
0
08 Apr '26
From: Longfang Liu <liulongfang(a)huawei.com>
This reverts commit 3fc344aa4f7c460269cd0d870fe388f01dfa22a2.
---
drv/hash_mb/hash_mb.c | 45 +++++------
drv/hisi_comp.c | 32 +++-----
drv/hisi_dae.c | 13 +---
drv/hisi_dae.h | 4 +-
drv/hisi_dae_common.c | 28 +++----
drv/hisi_dae_join_gather.c | 21 ++----
drv/hisi_hpre.c | 76 +++++++------------
drv/hisi_sec.c | 123 +++++++++++++++----------------
drv/hisi_udma.c | 30 +++-----
drv/isa_ce_sm3.c | 38 ++++------
drv/isa_ce_sm4.c | 41 ++++-------
include/drv/wd_agg_drv.h | 3 +-
include/drv/wd_ecc_drv.h | 5 +-
include/drv/wd_join_gather_drv.h | 12 ++-
include/wd_alg.h | 19 +++--
include/wd_util.h | 14 ++--
wd_aead.c | 37 ++++------
wd_agg.c | 15 ++--
wd_alg.c | 20 -----
wd_cipher.c | 20 ++---
wd_comp.c | 20 ++---
wd_dh.c | 22 +++---
wd_digest.c | 37 ++++------
wd_ecc.c | 26 ++++---
wd_join_gather.c | 28 +++----
wd_rsa.c | 22 +++---
wd_udma.c | 15 ++--
wd_util.c | 38 ++++++++--
28 files changed, 351 insertions(+), 453 deletions(-)
diff --git a/drv/hash_mb/hash_mb.c b/drv/hash_mb/hash_mb.c
index bd412b2..5c0daf2 100644
--- a/drv/hash_mb/hash_mb.c
+++ b/drv/hash_mb/hash_mb.c
@@ -186,46 +186,34 @@ free_mb_queue:
return ret;
}
-static int hash_mb_init(struct wd_alg_driver *drv, void *conf)
+static int hash_mb_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
- struct hash_mb_ctx *priv;
- int ret;
+ struct hash_mb_ctx *mb_ctx = priv;
/* Fallback init is NULL */
- if (!drv || !conf)
+ if (!conf || !priv)
return 0;
- priv = malloc(sizeof(struct hash_mb_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
/* multibuff does not use epoll. */
config->epoll_en = 0;
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
+ memcpy(&mb_ctx->config, config, sizeof(struct wd_ctx_config_internal));
- ret = hash_mb_queue_init(config);
- if (ret) {
- free(priv);
- return ret;
- }
-
- drv->priv = priv;
-
- return WD_SUCCESS;
+ return hash_mb_queue_init(config);
}
-static void hash_mb_exit(struct wd_alg_driver *drv)
+static void hash_mb_exit(void *priv)
{
- struct hash_mb_ctx *priv;
+ struct hash_mb_ctx *mb_ctx = priv;
+ struct wd_ctx_config_internal *config;
- if (!drv || !drv->priv)
+ if (!priv) {
+ WD_ERR("invalid: input parameter is NULL!\n");
return;
+ }
- priv = (struct hash_mb_ctx *)drv->priv;
- hash_mb_queue_uninit(&priv->config, priv->config.ctx_num);
- free(priv);
- drv->priv = NULL;
+ config = &mb_ctx->config;
+ hash_mb_queue_uninit(config, config->ctx_num);
}
static void hash_mb_pad_data(struct hash_pad *hash_pad, __u8 *in, __u32 partial,
@@ -267,7 +255,7 @@ static inline void hash_xor(__u8 *key_out, __u8 *key_in, __u32 key_len, __u8 xor
if (i < key_len)
key_out[i] = key_in[i] ^ xor_value;
else
- key_out[i] = xor_value;
+ key_out[i] = 0x0 ^ xor_value;
}
}
@@ -555,7 +543,7 @@ static int hash_mb_check_param(struct hash_mb_queue *mb_queue, struct wd_digest_
return WD_SUCCESS;
}
-static int hash_mb_send(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg)
+static int hash_mb_send(handle_t ctx, void *drv_msg)
{
struct wd_soft_ctx *s_ctx = (struct wd_soft_ctx *)ctx;
struct hash_mb_queue *mb_queue = s_ctx->priv;
@@ -776,7 +764,7 @@ static int hash_mb_do_jobs(struct hash_mb_queue *mb_queue)
return WD_SUCCESS;
}
-static int hash_mb_recv(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg)
+static int hash_mb_recv(handle_t ctx, void *drv_msg)
{
struct wd_soft_ctx *s_ctx = (struct wd_soft_ctx *)ctx;
struct hash_mb_queue *mb_queue = s_ctx->priv;
@@ -810,6 +798,7 @@ static int hash_mb_get_usage(void *param)
.alg_name = (hash_alg_name),\
.calc_type = UADK_ALG_SVE_INSTR,\
.priority = 100,\
+ .priv_size = sizeof(struct hash_mb_ctx),\
.queue_num = 1,\
.op_type_num = 1,\
.fallback = 0,\
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index a6b2947..be16b83 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -1414,11 +1414,11 @@ static void hisi_zip_sqe_ops_adapt(handle_t h_qp)
}
}
-static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
+static int hisi_zip_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv;
struct hisi_qm_priv qm_priv;
- struct hisi_zip_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -1428,11 +1428,7 @@ static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_zip_ctx));
- if (!priv)
- return -WD_EINVAL;
-
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
+ memcpy(&zip_ctx->config, config, sizeof(struct wd_ctx_config_internal));
/* allocate qp for each context */
for (i = 0; i < config->ctx_num; i++) {
h_ctx = config->ctxs[i].ctx;
@@ -1450,7 +1446,6 @@ static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
}
hisi_zip_sqe_ops_adapt(h_qp);
- drv->priv = priv;
return 0;
out:
@@ -1458,28 +1453,20 @@ out:
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[j].ctx);
hisi_qm_free_qp(h_qp);
}
- free(priv);
return -WD_EINVAL;
}
-static void hisi_zip_exit(struct wd_alg_driver *drv)
+static void hisi_zip_exit(void *priv)
{
- struct wd_ctx_config_internal *config;
- struct hisi_zip_ctx *priv;
+ struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv;
+ struct wd_ctx_config_internal *config = &zip_ctx->config;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
- return;
-
- priv = (struct hisi_zip_ctx *)drv->priv;
- config = &priv->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
hisi_qm_free_qp(h_qp);
}
- free(priv);
- drv->priv = NULL;
}
static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
@@ -1534,7 +1521,7 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
return 0;
}
-static int hisi_zip_comp_send(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg)
+static int hisi_zip_comp_send(handle_t ctx, void *comp_msg)
{
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
struct wd_comp_msg *msg = comp_msg;
@@ -1722,7 +1709,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
return 0;
}
-static int hisi_zip_comp_recv(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg)
+static int hisi_zip_comp_recv(handle_t ctx, void *comp_msg)
{
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
struct wd_comp_msg *recv_msg = comp_msg;
@@ -1775,7 +1762,7 @@ static int hisi_zip_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_zip_ctx *)drv->priv;
+ priv = (struct hisi_zip_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
@@ -1803,6 +1790,7 @@ static int hisi_zip_get_usage(void *param)
.alg_name = (zip_alg_name),\
.calc_type = UADK_ALG_HW,\
.priority = 100,\
+ .priv_size = sizeof(struct hisi_zip_ctx),\
.queue_num = ZIP_CTX_Q_NUM_DEF,\
.op_type_num = 2,\
.fallback = 0,\
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index d86b9f6..4a1ac89 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -426,7 +426,7 @@ static int check_hashagg_param(struct wd_agg_msg *msg)
return WD_SUCCESS;
}
-static int hashagg_send(struct wd_alg_driver *drv, handle_t ctx, void *hashagg_msg)
+static int hashagg_send(handle_t ctx, void *hashagg_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -563,7 +563,7 @@ static void fill_hashagg_msg_task_err(struct dae_sqe *sqe, struct wd_agg_msg *ms
}
}
-static int hashagg_recv(struct wd_alg_driver *drv, handle_t ctx, void *hashagg_msg)
+static int hashagg_recv(handle_t ctx, void *hashagg_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -1214,17 +1214,11 @@ static void hashagg_sess_priv_uninit(struct wd_alg_driver *drv, void *priv)
free(agg_ctx);
}
-static int hashagg_sess_priv_init(struct wd_alg_driver *drv,
- struct wd_agg_sess_setup *setup, void **priv)
+static int hashagg_sess_priv_init(struct wd_agg_sess_setup *setup, void **priv)
{
struct hashagg_ctx *agg_ctx;
int ret;
- if (!drv || !drv->priv) {
- WD_ERR("invalid: dae drv is NULL!\n");
- return -WD_EINVAL;
- }
-
if (!setup || !priv) {
WD_ERR("invalid: dae sess priv is NULL!\n");
return -WD_EINVAL;
@@ -1297,6 +1291,7 @@ static struct wd_alg_driver hashagg_driver = {
.alg_name = "hashagg",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_dae_ctx),
.queue_num = DAE_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
diff --git a/drv/hisi_dae.h b/drv/hisi_dae.h
index f82b13c..f8888b6 100644
--- a/drv/hisi_dae.h
+++ b/drv/hisi_dae.h
@@ -210,8 +210,8 @@ struct hisi_dae_ctx {
struct wd_ctx_config_internal config;
};
-void dae_exit(struct wd_alg_driver *drv);
-int dae_init(struct wd_alg_driver *drv, void *conf);
+void dae_exit(void *priv);
+int dae_init(void *conf, void *priv);
int dae_hash_table_init(struct hash_table_data *hw_table,
struct hash_table_data *rehash_table,
struct wd_dae_hash_table *hash_table,
diff --git a/drv/hisi_dae_common.c b/drv/hisi_dae_common.c
index c077d1d..216e424 100644
--- a/drv/hisi_dae_common.c
+++ b/drv/hisi_dae_common.c
@@ -308,11 +308,11 @@ update_table:
return ret;
}
-int dae_init(struct wd_alg_driver *drv, void *conf)
+int dae_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_dae_ctx *dae_ctx = priv;
struct hisi_qm_priv qm_priv;
- struct hisi_dae_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -323,10 +323,6 @@ int dae_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_dae_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
qm_priv.op_type = DAE_SQC_ALG_TYPE;
qm_priv.sqe_size = sizeof(struct dae_sqe);
/* Allocate qp for each context */
@@ -347,8 +343,7 @@ int dae_init(struct wd_alg_driver *drv, void *conf)
if (ret)
goto free_h_qp;
}
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&dae_ctx->config, config, sizeof(struct wd_ctx_config_internal));
return WD_SUCCESS;
@@ -362,22 +357,22 @@ out:
hisi_qm_free_qp(h_qp);
}
}
- free(priv);
return ret;
}
-void dae_exit(struct wd_alg_driver *drv)
+void dae_exit(void *priv)
{
struct wd_ctx_config_internal *config;
- struct hisi_dae_ctx *priv;
+ struct hisi_dae_ctx *dae_ctx = priv;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
+ if (!priv) {
+ WD_ERR("invalid: input parameter is NULL!\n");
return;
+ }
- priv = (struct hisi_dae_ctx *)drv->priv;
- config = &priv->config;
+ config = &dae_ctx->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
if (h_qp) {
@@ -385,9 +380,6 @@ void dae_exit(struct wd_alg_driver *drv)
hisi_qm_free_qp(h_qp);
}
}
-
- free(priv);
- drv->priv = NULL;
}
int dae_get_usage(void *param)
@@ -406,7 +398,7 @@ int dae_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_dae_ctx *)drv->priv;
+ priv = (struct hisi_dae_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
diff --git a/drv/hisi_dae_join_gather.c b/drv/hisi_dae_join_gather.c
index 8c45f57..43ed539 100644
--- a/drv/hisi_dae_join_gather.c
+++ b/drv/hisi_dae_join_gather.c
@@ -455,7 +455,7 @@ static int check_join_gather_param(struct wd_join_gather_msg *msg)
return WD_SUCCESS;
}
-static int join_gather_send(struct wd_alg_driver *drv, handle_t ctx, void *send_msg)
+static int join_gather_send(handle_t ctx, void *send_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -540,7 +540,7 @@ static void fill_join_gather_task_err(struct dae_sqe *sqe, struct wd_join_gather
}
}
-static int join_gather_recv(struct wd_alg_driver *drv, handle_t hctx, void *recv_msg)
+static int join_gather_recv(handle_t hctx, void *recv_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(hctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -892,7 +892,7 @@ static int join_gather_fill_ctx(struct join_gather_ctx *ctx,
return WD_SUCCESS;
}
-static void join_gather_sess_priv_uninit(struct wd_alg_driver *drv, void *priv)
+static void join_gather_sess_priv_uninit(void *priv)
{
struct join_gather_ctx *ctx = priv;
@@ -904,17 +904,11 @@ static void join_gather_sess_priv_uninit(struct wd_alg_driver *drv, void *priv)
free(ctx);
}
-static int join_gather_sess_priv_init(struct wd_alg_driver *drv,
- struct wd_join_gather_sess_setup *setup, void **priv)
+static int join_gather_sess_priv_init(struct wd_join_gather_sess_setup *setup, void **priv)
{
struct join_gather_ctx *ctx;
int ret;
- if (!drv || !drv->priv) {
- WD_ERR("invalid: dae drv is NULL!\n");
- return -WD_EINVAL;
- }
-
if (!setup || !priv) {
WD_ERR("invalid: dae sess priv is NULL!\n");
return -WD_EINVAL;
@@ -941,7 +935,7 @@ free_ctx:
return ret;
}
-static int join_get_table_row_size(struct wd_alg_driver *drv, void *param)
+static int join_get_table_row_size(void *param)
{
struct join_gather_ctx *ctx = param;
@@ -951,7 +945,7 @@ static int join_get_table_row_size(struct wd_alg_driver *drv, void *param)
return ctx->hash_table_row_size;
}
-static int gather_get_batch_row_size(struct wd_alg_driver *drv, void *param,
+static int gather_get_batch_row_size(void *param,
__u32 *row_size, __u32 size)
{
struct join_gather_ctx *ctx = param;
@@ -967,8 +961,7 @@ static int gather_get_batch_row_size(struct wd_alg_driver *drv, void *param,
return 0;
}
-static int join_hash_table_init(struct wd_alg_driver *drv,
- struct wd_dae_hash_table *table, void *priv)
+static int join_hash_table_init(struct wd_dae_hash_table *table, void *priv)
{
struct join_gather_ctx *ctx = priv;
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 3c41826..7da8407 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -680,11 +680,11 @@ out:
return -WD_EINVAL;
}
-static int hpre_rsa_dh_init(struct wd_alg_driver *drv, void *conf)
+static int hpre_rsa_dh_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
struct hisi_qm_priv qm_priv;
- struct hisi_hpre_ctx *priv;
int ret;
if (!config->ctx_num) {
@@ -692,27 +692,19 @@ static int hpre_rsa_dh_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_hpre_ctx));
- if (!priv)
- return -WD_EINVAL;
-
qm_priv.op_type = HPRE_HW_V2_ALG_TYPE;
- ret = hpre_init_qm_priv(config, priv, &qm_priv);
- if (ret) {
- free(priv);
+ ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
+ if (ret)
return ret;
- }
-
- drv->priv = priv;
return WD_SUCCESS;
}
-static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf)
+static int hpre_ecc_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
struct hisi_qm_priv qm_priv;
- struct hisi_hpre_ctx *priv;
int ret;
if (!config->ctx_num) {
@@ -720,44 +712,28 @@ static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_hpre_ctx));
- if (!priv)
- return -WD_EINVAL;
-
qm_priv.op_type = HPRE_HW_V3_ECC_ALG_TYPE;
- ret = hpre_init_qm_priv(config, priv, &qm_priv);
- if (ret) {
- free(priv);
+ ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
+ if (ret)
return ret;
- }
-
- drv->priv = priv;
return WD_SUCCESS;
}
-static void hpre_exit(struct wd_alg_driver *drv)
+static void hpre_exit(void *priv)
{
- struct wd_ctx_config_internal *config;
- struct hisi_hpre_ctx *priv;
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
+ struct wd_ctx_config_internal *config = &hpre_ctx->config;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
- return;
-
- priv = (struct hisi_hpre_ctx *)drv->priv;
- config = &priv->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
hisi_qm_free_qp(h_qp);
}
-
- free(priv);
- drv->priv = NULL;
}
-static int rsa_send(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
+static int rsa_send(handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_rsa_msg *msg = rsa_msg;
@@ -829,7 +805,7 @@ static void hpre_result_check(struct hisi_hpre_sqe *hw_msg,
}
}
-static int rsa_recv(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
+static int rsa_recv(handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -949,7 +925,7 @@ static int dh_out_transfer(struct wd_dh_msg *msg, struct hisi_hpre_sqe *hw_msg,
return WD_SUCCESS;
}
-static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
+static int dh_send(handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct map_info_cache cache = {0};
@@ -1020,7 +996,7 @@ dh_fail:
return ret;
}
-static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
+static int dh_recv(handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -2147,7 +2123,7 @@ free_dst:
return ret;
}
-static int ecc_send(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
+static int ecc_send(handle_t ctx, void *ecc_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_ecc_msg *msg = ecc_msg;
@@ -2743,7 +2719,7 @@ fail:
return ret;
}
-static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
+static int ecc_recv(handle_t ctx, void *ecc_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_ecc_msg *msg = ecc_msg;
@@ -2786,7 +2762,7 @@ static handle_t hpre_find_dev_qp(struct wd_alg_driver *drv, const char *dev_name
handle_t qp = 0;
__u32 i;
- priv = (struct hisi_hpre_ctx *)drv->priv;
+ priv = (struct hisi_hpre_ctx *)drv->drv_data;
if (!priv)
return 0;
@@ -2874,31 +2850,30 @@ static void ecc_sess_eops_uninit(struct wd_alg_driver *drv, void *params)
free(params);
}
-static bool is_valid_hw_type(struct wd_alg_driver *drv)
+static bool is_valid_hw_type(void *drv_priv)
{
struct hisi_hpre_ctx *hpre_ctx;
struct hisi_qp *qp;
- if (unlikely(!drv || !drv->priv))
+ if (unlikely(!drv_priv))
return false;
- hpre_ctx = (struct hisi_hpre_ctx *)drv->priv;
+ hpre_ctx = (struct hisi_hpre_ctx *)drv_priv;
qp = (struct hisi_qp *)wd_ctx_get_priv(hpre_ctx->config.ctxs[0].ctx);
if (!qp || qp->q_info.hw_type < HISI_QM_API_VER3_BASE)
return false;
return true;
}
-static void ecc_sess_eops_params_cfg(struct wd_alg_driver *drv,
- struct wd_ecc_sess_setup *setup,
- struct wd_ecc_curve *cv, void *params)
+static void ecc_sess_eops_params_cfg(struct wd_ecc_sess_setup *setup,
+ struct wd_ecc_curve *cv, void *drv_priv, void *params)
{
__u8 data[SECP256R1_PARAM_SIZE] = SECG_P256_R1_PARAM;
struct hpre_ecc_ctx *ecc_ctx = params;
__u32 key_size;
int ret;
- if (!is_valid_hw_type(drv))
+ if (!is_valid_hw_type(drv_priv))
return;
if (!ecc_ctx) {
@@ -2938,6 +2913,7 @@ static int hpre_ecc_get_extend_ops(void *ops)
.alg_name = (hpre_alg_name),\
.calc_type = UADK_ALG_HW,\
.priority = 100,\
+ .priv_size = sizeof(struct hisi_hpre_ctx),\
.queue_num = HPRE_CTX_Q_NUM_DEF,\
.op_type_num = 1,\
.fallback = 0,\
@@ -2962,6 +2938,7 @@ static struct wd_alg_driver hpre_rsa_driver = {
.alg_name = "rsa",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_hpre_ctx),
.queue_num = HPRE_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
@@ -2977,6 +2954,7 @@ static struct wd_alg_driver hpre_dh_driver = {
.alg_name = "dh",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_hpre_ctx),
.queue_num = HPRE_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index c8b831c..fb9de2c 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -526,76 +526,76 @@ static __u32 g_sec_hmac_full_len[WD_DIGEST_TYPE_MAX] = {
SEC_HMAC_SHA512_MAC_LEN, SEC_HMAC_SHA512_224_MAC_LEN, SEC_HMAC_SHA512_256_MAC_LEN
};
-static int hisi_sec_init(struct wd_alg_driver *drv, void *conf);
-static void hisi_sec_exit(struct wd_alg_driver *drv);
+static int hisi_sec_init(void *conf, void *priv);
+static void hisi_sec_exit(void *priv);
-static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_send(handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_recv(handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_send_v3(handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_recv_v3(handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_send(handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_recv(handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_send_v3(handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_recv_v3(handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_send(handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_recv(handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_send_v3(handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_recv_v3(handle_t ctx, void *wd_msg);
-static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_send(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_cipher_send(drv, ctx, msg);
- return hisi_sec_cipher_send_v3(drv, ctx, msg);
+ return hisi_sec_cipher_send(ctx, msg);
+ return hisi_sec_cipher_send_v3(ctx, msg);
}
-static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_recv(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_cipher_recv(drv, ctx, msg);
- return hisi_sec_cipher_recv_v3(drv, ctx, msg);
+ return hisi_sec_cipher_recv(ctx, msg);
+ return hisi_sec_cipher_recv_v3(ctx, msg);
}
-static int digest_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int digest_send(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_digest_send(drv, ctx, msg);
- return hisi_sec_digest_send_v3(drv, ctx, msg);
+ return hisi_sec_digest_send(ctx, msg);
+ return hisi_sec_digest_send_v3(ctx, msg);
}
-static int digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int digest_recv(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_digest_recv(drv, ctx, msg);
- return hisi_sec_digest_recv_v3(drv, ctx, msg);
+ return hisi_sec_digest_recv(ctx, msg);
+ return hisi_sec_digest_recv_v3(ctx, msg);
}
-static int aead_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int aead_send(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_aead_send(drv, ctx, msg);
- return hisi_sec_aead_send_v3(drv, ctx, msg);
+ return hisi_sec_aead_send(ctx, msg);
+ return hisi_sec_aead_send_v3(ctx, msg);
}
-static int aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int aead_recv(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_aead_recv(drv, ctx, msg);
- return hisi_sec_aead_recv_v3(drv, ctx, msg);
+ return hisi_sec_aead_recv(ctx, msg);
+ return hisi_sec_aead_recv_v3(ctx, msg);
}
static int hisi_sec_get_usage(void *param)
@@ -614,7 +614,7 @@ static int hisi_sec_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_sec_ctx *)drv->priv;
+ priv = (struct hisi_sec_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
@@ -638,8 +638,8 @@ static int hisi_sec_get_usage(void *param)
static int eops_param_check(struct wd_alg_driver *drv, struct wd_mm_ops *mm_ops)
{
- if (!drv || !drv->priv) {
- WD_ERR("invalid: aead drv or priv is NULL!\n");
+ if (!drv || !drv->drv_data) {
+ WD_ERR("invalid: aead drv or data is NULL!\n");
return -WD_EINVAL;
}
@@ -680,7 +680,7 @@ static int aead_sess_eops_init(struct wd_alg_driver *drv,
return -WD_ENOMEM;
}
- sec_ctx = (struct hisi_sec_ctx *)drv->priv;
+ sec_ctx = (struct hisi_sec_ctx *)drv->drv_data;
qp = (struct hisi_qp *)wd_ctx_get_priv(sec_ctx->config.ctxs[0].ctx);
sq_depth = qp->q_info.sq_depth;
aiv_addr->aiv = mm_ops->alloc(mm_ops->usr, (__u32)sq_depth << AEAD_AIV_OFFSET);
@@ -735,7 +735,7 @@ static void aead_sess_eops_uninit(struct wd_alg_driver *drv,
return;
}
- sec_ctx = (struct hisi_sec_ctx *)drv->priv;
+ sec_ctx = (struct hisi_sec_ctx *)drv->drv_data;
qp = (struct hisi_qp *)wd_ctx_get_priv(sec_ctx->config.ctxs[0].ctx);
sq_depth = qp->q_info.sq_depth;
@@ -793,6 +793,7 @@ static int sec_aead_get_extend_ops(void *ops)
.alg_name = (sec_alg_name),\
.calc_type = UADK_ALG_HW,\
.priority = 100,\
+ .priv_size = sizeof(struct hisi_sec_ctx),\
.queue_num = SEC_CTX_Q_NUM_DEF,\
.op_type_num = 1,\
.fallback = 0,\
@@ -1400,7 +1401,7 @@ static int fill_cipher_bd2(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
return 0;
}
-static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_cipher_send(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_cipher_msg *msg = wd_msg;
@@ -1456,7 +1457,7 @@ static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *w
return 0;
}
-static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_cipher_recv(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_cipher_msg *recv_msg = wd_msg;
@@ -1693,7 +1694,7 @@ static void fill_sec_prefetch(__u8 data_fmt, __u32 len, __u16 hw_type, struct hi
sqe->auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET;
}
-static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_cipher_send_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -1800,7 +1801,7 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "cipher");
}
-static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_cipher_recv_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_cipher_msg *recv_msg = wd_msg;
@@ -2132,7 +2133,7 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
return 0;
}
-static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_digest_send(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_digest_msg *msg = wd_msg;
@@ -2209,7 +2210,7 @@ put_sgl:
return ret;
}
-static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_digest_recv(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_digest_msg *recv_msg = wd_msg;
@@ -2473,7 +2474,7 @@ map_err:
return -WD_ENOMEM;
}
-static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_digest_send_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -2587,7 +2588,7 @@ static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "digest");
}
-static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_digest_recv_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_digest_msg *recv_msg = wd_msg;
@@ -3216,7 +3217,7 @@ static int fill_aead_bd2_addr(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe,
return aead_mem_nosva_map(msg, sqe, idx);
}
-static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_aead_send(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -3347,7 +3348,7 @@ static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe,
dump_sec_msg(temp_msg, "aead");
}
-static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_aead_recv(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_aead_msg *recv_msg = wd_msg;
@@ -3744,7 +3745,7 @@ static int fill_aead_bd3_addr(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe
return aead_mem_nosva_map_v3(msg, sqe, idx);
}
-static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_aead_send_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -3863,7 +3864,7 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "aead");
}
-static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_aead_recv_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_aead_msg *recv_msg = wd_msg;
@@ -3888,11 +3889,11 @@ static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *
return 0;
}
-static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
+static int hisi_sec_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_sec_ctx *sec_ctx = priv;
struct hisi_qm_priv qm_priv;
- struct hisi_sec_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -3902,10 +3903,6 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_sec_ctx));
- if (!priv)
- return -WD_EINVAL;
-
qm_priv.sqe_size = sizeof(struct hisi_sec_sqe);
/* allocate qp for each context */
for (i = 0; i < config->ctx_num; i++) {
@@ -3922,8 +3919,7 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
goto out;
config->ctxs[i].sqn = qm_priv.sqn;
}
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&sec_ctx->config, config, sizeof(struct wd_ctx_config_internal));
return 0;
@@ -3936,25 +3932,24 @@ out:
return -WD_EINVAL;
}
-static void hisi_sec_exit(struct wd_alg_driver *drv)
+static void hisi_sec_exit(void *priv)
{
struct wd_ctx_config_internal *config;
- struct hisi_sec_ctx *priv;
+ struct hisi_sec_ctx *sec_ctx = priv;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
+ if (!priv) {
+ WD_ERR("invalid: input parameter is NULL!\n");
return;
+ }
- priv = (struct hisi_sec_ctx *)drv->priv;
- config = &priv->config;
+ config = &sec_ctx->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
hisi_qm_free_qp(h_qp);
}
- free(priv);
- drv->priv = NULL;
}
#ifdef WD_STATIC_DRV
diff --git a/drv/hisi_udma.c b/drv/hisi_udma.c
index a9f5607..5c8a743 100644
--- a/drv/hisi_udma.c
+++ b/drv/hisi_udma.c
@@ -290,7 +290,7 @@ static void fill_init_value(struct udma_sqe *sqe, struct wd_udma_msg *msg)
memset(&sqe->init_val, msg->value, sizeof(__u64));
}
-static int udma_send(struct wd_alg_driver *drv, handle_t ctx, void *udma_msg)
+static int udma_send(handle_t ctx, void *udma_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -342,7 +342,7 @@ static void dump_udma_msg(struct udma_sqe *sqe, struct wd_udma_msg *msg)
"op_type:%u addr_num:%d.\n", msg->op_type, msg->addr_num);
}
-static int udma_recv(struct wd_alg_driver *drv, handle_t ctx, void *udma_msg)
+static int udma_recv(handle_t ctx, void *udma_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -442,11 +442,11 @@ free_inter_addr:
return ret;
}
-static int udma_init(struct wd_alg_driver *drv, void *conf)
+static int udma_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_udma_ctx *uctx = priv;
struct hisi_qm_priv qm_priv;
- struct hisi_udma_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -457,10 +457,6 @@ static int udma_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_udma_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
qm_priv.op_type = UDMA_ALG_TYPE;
qm_priv.sqe_size = sizeof(struct udma_sqe);
/* Allocate qp for each context */
@@ -481,8 +477,7 @@ static int udma_init(struct wd_alg_driver *drv, void *conf)
if (ret)
goto free_h_qp;
}
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&uctx->config, config, sizeof(struct wd_ctx_config_internal));
return WD_SUCCESS;
free_h_qp:
@@ -493,30 +488,26 @@ out:
udma_uninit_qp_priv(h_qp);
hisi_qm_free_qp(h_qp);
}
- free(priv);
return ret;
}
-static void udma_exit(struct wd_alg_driver *drv)
+static void udma_exit(void *priv)
{
struct wd_ctx_config_internal *config;
- struct hisi_udma_ctx *priv;
+ struct hisi_udma_ctx *uctx = priv;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
+ if (!priv)
return;
- priv = (struct hisi_udma_ctx *)drv->priv;
- config = &priv->config;
+ config = &uctx->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
udma_uninit_qp_priv(h_qp);
hisi_qm_free_qp(h_qp);
}
- free(priv);
- drv->priv = NULL;
}
static int udma_get_usage(void *param)
@@ -535,7 +526,7 @@ static int udma_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_udma_ctx *)drv->priv;
+ priv = (struct hisi_udma_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
@@ -562,6 +553,7 @@ static struct wd_alg_driver udma_driver = {
.alg_name = "udma",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_udma_ctx),
.queue_num = UDMA_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
diff --git a/drv/isa_ce_sm3.c b/drv/isa_ce_sm3.c
index 8d23061..0ebaba5 100644
--- a/drv/isa_ce_sm3.c
+++ b/drv/isa_ce_sm3.c
@@ -24,10 +24,10 @@
typedef void (sm3_ce_block_fn)(__u32 word_reg[SM3_STATE_WORDS],
const unsigned char *src, size_t blocks);
-static int sm3_ce_drv_init(struct wd_alg_driver *drv, void *conf);
-static void sm3_ce_drv_exit(struct wd_alg_driver *drv);
-static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg);
-static int sm3_ce_drv_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg);
+static int sm3_ce_drv_init(void *conf, void *priv);
+static void sm3_ce_drv_exit(void *priv);
+static int sm3_ce_drv_send(handle_t ctx, void *digest_msg);
+static int sm3_ce_drv_recv(handle_t ctx, void *digest_msg);
static int sm3_ce_get_usage(void *param);
static struct wd_alg_driver sm3_ce_alg_driver = {
@@ -35,6 +35,7 @@ static struct wd_alg_driver sm3_ce_alg_driver = {
.alg_name = "sm3",
.calc_type = UADK_ALG_CE_INSTR,
.priority = 200,
+ .priv_size = sizeof(struct sm3_ce_drv_ctx),
.queue_num = 1,
.op_type_num = 1,
.fallback = 0,
@@ -335,7 +336,7 @@ static int do_hmac_sm3_ce(struct wd_digest_msg *msg, __u8 *out_hmac)
return WD_SUCCESS;
}
-static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
+static int sm3_ce_drv_send(handle_t ctx, void *digest_msg)
{
struct wd_digest_msg *msg = (struct wd_digest_msg *)digest_msg;
__u8 digest[SM3_DIGEST_SIZE] = {0};
@@ -370,39 +371,26 @@ static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest
return ret;
}
-static int sm3_ce_drv_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
+static int sm3_ce_drv_recv(handle_t ctx, void *digest_msg)
{
return WD_SUCCESS;
}
-static int sm3_ce_drv_init(struct wd_alg_driver *drv, void *conf)
+static int sm3_ce_drv_init(void *conf, void *priv)
{
- struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
- struct sm3_ce_drv_ctx *priv;
+ struct wd_ctx_config_internal *config = conf;
+ struct sm3_ce_drv_ctx *sctx = priv;
/* Fallback init is NULL */
- if (!drv || !conf)
+ if (!conf || !conf)
return 0;
- priv = malloc(sizeof(struct sm3_ce_drv_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
config->epoll_en = 0;
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&sctx->config, config, sizeof(struct wd_ctx_config_internal));
return WD_SUCCESS;
}
-static void sm3_ce_drv_exit(struct wd_alg_driver *drv)
+static void sm3_ce_drv_exit(void *priv)
{
- struct sm3_ce_drv_ctx *sctx;
-
- if (!drv || !drv->priv)
- return;
-
- sctx = (struct sm3_ce_drv_ctx *)drv->priv;
- free(sctx);
- drv->priv = NULL;
}
diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c
index 52dca1f..504ef73 100644
--- a/drv/isa_ce_sm4.c
+++ b/drv/isa_ce_sm4.c
@@ -11,9 +11,10 @@
* Copyright 2024 Huawei Technologies Co.,Ltd. All rights reserved.
*/
+#include "wd_alg.h"
#include "drv/wd_cipher_drv.h"
-#include "wd_cipher.h"
#include "isa_ce_sm4.h"
+#include "wd_cipher.h"
#define SM4_ENCRYPT 1
#define SM4_DECRYPT 0
@@ -31,36 +32,23 @@
((p)[0] = (__u8)((v) >> 24), (p)[1] = (__u8)((v) >> 16), \
(p)[2] = (__u8)((v) >> 8), (p)[3] = (__u8)(v))
-static int isa_ce_init(struct wd_alg_driver *drv, void *conf)
+static int isa_ce_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
- struct sm4_ce_drv_ctx *priv;
+ struct sm4_ce_drv_ctx *sctx = priv;
/* Fallback init is NULL */
- if (!drv || !conf)
+ if (!conf || !priv)
return 0;
- priv = malloc(sizeof(struct sm4_ce_drv_ctx));
- if (!priv)
- return -WD_EINVAL;
-
config->epoll_en = 0;
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&sctx->config, config, sizeof(struct wd_ctx_config_internal));
- return WD_SUCCESS;
+ return 0;
}
-static void isa_ce_exit(struct wd_alg_driver *drv)
+static void isa_ce_exit(void *priv)
{
- struct sm4_ce_drv_ctx *sctx;
-
- if (!drv || !drv->priv)
- return;
-
- sctx = (struct sm4_ce_drv_ctx *)drv->priv;
- free(sctx);
- drv->priv = NULL;
}
/* increment upper 96 bits of 128-bit counter by 1 */
@@ -334,7 +322,7 @@ static int sm4_xts_decrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey
return 0;
}
-static int isa_ce_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int isa_ce_cipher_send(handle_t ctx, void *wd_msg)
{
struct wd_cipher_msg *msg = wd_msg;
struct SM4_KEY rkey;
@@ -400,19 +388,19 @@ static int isa_ce_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_
return ret;
}
-static int isa_ce_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int isa_ce_cipher_recv(handle_t ctx, void *wd_msg)
{
return 0;
}
-static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_send(handle_t ctx, void *msg)
{
- return isa_ce_cipher_send(drv, ctx, msg);
+ return isa_ce_cipher_send(ctx, msg);
}
-static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_recv(handle_t ctx, void *msg)
{
- return isa_ce_cipher_recv(drv, ctx, msg);
+ return isa_ce_cipher_recv(ctx, msg);
}
#define GEN_CE_ALG_DRIVER(ce_alg_name, alg_type) \
@@ -421,6 +409,7 @@ static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
.alg_name = (ce_alg_name),\
.calc_type = UADK_ALG_CE_INSTR,\
.priority = 200,\
+ .priv_size = sizeof(struct sm4_ce_drv_ctx),\
.op_type_num = 1,\
.fallback = 0,\
.init = isa_ce_init,\
diff --git a/include/drv/wd_agg_drv.h b/include/drv/wd_agg_drv.h
index b26b25d..8952ee9 100644
--- a/include/drv/wd_agg_drv.h
+++ b/include/drv/wd_agg_drv.h
@@ -43,8 +43,7 @@ struct wd_agg_msg {
struct wd_agg_ops {
int (*get_row_size)(struct wd_alg_driver *drv, void *priv);
- int (*sess_init)(struct wd_alg_driver *drv,
- struct wd_agg_sess_setup *setup, void **priv);
+ int (*sess_init)(struct wd_agg_sess_setup *setup, void **priv);
void (*sess_uninit)(struct wd_alg_driver *drv, void *priv);
int (*hash_table_init)(struct wd_alg_driver *drv,
struct wd_dae_hash_table *hash_table, void *priv);
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 48c422f..98ff28c 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -181,9 +181,8 @@ struct wd_ecc_out {
struct wd_ecc_extend_ops {
void *params; /* the params are passed to the following ops */
- void (*eops_params_cfg)(struct wd_alg_driver *drv,
- struct wd_ecc_sess_setup *setup,
- struct wd_ecc_curve *cv, void *params);
+ void (*eops_params_cfg)(struct wd_ecc_sess_setup *setup,
+ struct wd_ecc_curve *cv, void *drv_priv, void *params);
int (*sess_init)(struct wd_alg_driver *drv, void **params);
void (*sess_uninit)(struct wd_alg_driver *drv, void *params);
};
diff --git a/include/drv/wd_join_gather_drv.h b/include/drv/wd_join_gather_drv.h
index dbf4ee7..d7f136d 100644
--- a/include/drv/wd_join_gather_drv.h
+++ b/include/drv/wd_join_gather_drv.h
@@ -33,14 +33,12 @@ struct wd_join_gather_msg {
};
struct wd_join_gather_ops {
- int (*get_table_row_size)(struct wd_alg_driver *drv, void *priv);
- int (*get_batch_row_size)(struct wd_alg_driver *drv, void *priv,
+ int (*get_table_row_size)(void *priv);
+ int (*get_batch_row_size)(void *priv,
__u32 *batch_row_size, __u32 size);
- int (*sess_init)(struct wd_alg_driver *drv,
- struct wd_join_gather_sess_setup *setup, void **priv);
- void (*sess_uninit)(struct wd_alg_driver *drv, void *priv);
- int (*hash_table_init)(struct wd_alg_driver *drv,
- struct wd_dae_hash_table *hash_table, void *priv);
+ int (*sess_init)(struct wd_join_gather_sess_setup *setup, void **priv);
+ void (*sess_uninit)(void *priv);
+ int (*hash_table_init)(struct wd_dae_hash_table *hash_table, void *priv);
};
struct wd_join_gather_msg *wd_join_gather_get_msg(__u32 idx, __u32 tag);
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 18503ca..885a5e3 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -19,6 +19,7 @@ extern "C" {
#define handle_t uintptr_t
#define ALG_NAME_SIZE 128
#define DEV_NAME_LEN 128
+typedef unsigned char __u8;
/*
* Macros related to arm platform:
@@ -85,7 +86,8 @@ enum alg_dev_type {
* execute the algorithm task
* @op_type_num: number of modes in which the device executes the
* algorithm business and requires queues to be executed separately
- * @priv: pointer of priv ctx
+ * @priv_size: parameter memory size passed between the internal
+ * interfaces of the driver
* @fallback: soft calculation driver handle when performing soft
* calculation supplement
* @init: callback interface for initializing device drivers
@@ -105,13 +107,14 @@ struct wd_alg_driver {
int calc_type;
int queue_num;
int op_type_num;
- void *priv;
+ int priv_size;
+ int *drv_data;
handle_t fallback;
- int (*init)(struct wd_alg_driver *drv, void *conf);
- void (*exit)(struct wd_alg_driver *drv);
- int (*send)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
- int (*recv)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
+ int (*init)(void *conf, void *priv);
+ void (*exit)(void *priv);
+ int (*send)(handle_t ctx, void *drv_msg);
+ int (*recv)(handle_t ctx, void *drv_msg);
int (*get_usage)(void *param);
int (*get_extend_ops)(void *ops);
};
@@ -182,10 +185,6 @@ bool wd_drv_alg_support(const char *alg_name,
void wd_enable_drv(struct wd_alg_driver *drv);
void wd_disable_drv(struct wd_alg_driver *drv);
-int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf);
-void wd_alg_driver_exit(struct wd_alg_driver *drv);
-int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg);
-int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg);
int wd_alg_get_dev_usage(const char *dev_name, const char *alg_type, __u8 op_type);
int wd_get_alg_type(const char *alg_name, char *alg_type);
diff --git a/include/wd_util.h b/include/wd_util.h
index 2abceec..14985e2 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -120,8 +120,8 @@ struct wd_ctx_attr {
};
struct wd_msg_handle {
- int (*send)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
- int (*recv)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
+ int (*send)(handle_t sess, void *msg);
+ int (*recv)(handle_t sess, void *msg);
};
struct wd_init_attrs {
@@ -378,7 +378,6 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en);
/**
* wd_handle_msg_sync() - recv msg from hardware
- * @drv: the driver to handle msg.
* @msg_handle: callback of msg handle ops.
* @ctx: the handle of context.
* @msg: the msg of task.
@@ -387,8 +386,8 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en);
*
* Return 0 if successful or less than 0 otherwise.
*/
-int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_handle,
- handle_t ctx, void *msg, __u64 *balance, bool epoll_en);
+int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx,
+ void *msg, __u64 *balance, bool epoll_en);
/**
* wd_init_check() - Check input parameters for wd_<alg>_init.
@@ -486,13 +485,14 @@ void wd_alg_drv_unbind(struct wd_alg_driver *drv);
* to the obtained queue resource and the applied driver.
* @config: device resources requested by the current algorithm.
* @driver: device driver for the current algorithm application.
+ * @drv_priv: the parameter pointer of the current device driver.
*
* Return 0 if succeed and other error number if fail.
*/
int wd_alg_init_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver);
+ struct wd_alg_driver *driver, void **drv_priv);
void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver);
+ struct wd_alg_driver *driver, void **drv_priv);
/**
* wd_dlopen_drv() - Open the dynamic library file of the device driver.
diff --git a/wd_aead.c b/wd_aead.c
index 8467409..43bda73 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -34,6 +34,7 @@ struct wd_aead_setting {
struct wd_sched sched;
struct wd_alg_driver *driver;
struct wd_async_msg_pool pool;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_aead_setting;
@@ -603,7 +604,8 @@ static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_aead_setting.config,
- wd_aead_setting.driver);
+ wd_aead_setting.driver,
+ &wd_aead_setting.priv);
if (ret)
goto out_clear_pool;
@@ -652,30 +654,21 @@ out_clear_init:
return ret;
}
-static int wd_aead_uninit_nolock(void)
+static void wd_aead_uninit_nolock(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_aead_setting.status, &status);
- if (status == WD_UNINIT)
- return -WD_EINVAL;
-
wd_uninit_async_request_pool(&wd_aead_setting.pool);
wd_clear_sched(&wd_aead_setting.sched);
wd_alg_uninit_driver(&wd_aead_setting.config,
- wd_aead_setting.driver);
-
- return 0;
+ wd_aead_setting.driver,
+ &wd_aead_setting.priv);
}
void wd_aead_uninit(void)
{
- int ret;
-
- ret = wd_aead_uninit_nolock();
- if (ret)
+ if (!wd_aead_setting.priv)
return;
+ wd_aead_uninit_nolock();
wd_aead_close_driver(WD_TYPE_V1);
wd_alg_clear_init(&wd_aead_setting.status);
}
@@ -781,12 +774,10 @@ out_uninit:
void wd_aead_uninit2(void)
{
- int ret;
-
- ret = wd_aead_uninit_nolock();
- if (ret)
+ if (!wd_aead_setting.priv)
return;
+ wd_aead_uninit_nolock();
wd_alg_attrs_uninit(&wd_aead_init_attrs);
wd_alg_drv_unbind(wd_aead_setting.driver);
wd_aead_close_driver(WD_TYPE_V2);
@@ -875,8 +866,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
msg_handle.recv = wd_aead_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_aead_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, wd_aead_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
+ wd_aead_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
return ret;
@@ -951,7 +942,7 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req)
fill_request_msg(msg, req, sess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_aead_setting.driver, ctx->ctx, msg);
+ ret = wd_aead_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send BD, hw is err!\n");
@@ -1001,7 +992,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_aead_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_aead_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_agg.c b/wd_agg.c
index 8c54d10..66e9e0f 100644
--- a/wd_agg.c
+++ b/wd_agg.c
@@ -361,7 +361,7 @@ static int wd_agg_init_sess_priv(struct wd_agg_sess *sess, struct wd_agg_sess_se
WD_ERR("failed to get session uninit ops!\n");
return -WD_EINVAL;
}
- ret = sess->ops.sess_init(wd_agg_setting.driver, setup, &sess->priv);
+ ret = sess->ops.sess_init(setup, &sess->priv);
if (ret) {
WD_ERR("failed to init session priv!\n");
return ret;
@@ -595,7 +595,8 @@ static int wd_agg_alg_init(struct wd_ctx_config *config, struct wd_sched *sched)
if (ret < 0)
goto out_clear_sched;
- ret = wd_alg_init_driver(&wd_agg_setting.config, wd_agg_setting.driver);
+ ret = wd_alg_init_driver(&wd_agg_setting.config, wd_agg_setting.driver,
+ &wd_agg_setting.priv);
if (ret)
goto out_clear_pool;
@@ -624,7 +625,8 @@ static int wd_agg_alg_uninit(void)
/* Unset config, sched, driver */
wd_clear_sched(&wd_agg_setting.sched);
- wd_alg_uninit_driver(&wd_agg_setting.config, wd_agg_setting.driver);
+ wd_alg_uninit_driver(&wd_agg_setting.config, wd_agg_setting.driver,
+ &wd_agg_setting.priv);
return WD_SUCCESS;
}
@@ -1101,8 +1103,7 @@ static int wd_agg_sync_job(struct wd_agg_sess *sess, struct wd_agg_req *req,
msg_handle.recv = wd_agg_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_agg_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, config->epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, config->epoll_en);
pthread_spin_unlock(&ctx->lock);
return ret;
@@ -1203,7 +1204,7 @@ static int wd_agg_async_job(struct wd_agg_sess *sess, struct wd_agg_req *req, bo
else
fill_request_msg_output(msg, req, sess, false);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_agg_setting.driver, ctx->ctx, msg);
+ ret = wd_agg_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("wd agg async send err!\n");
@@ -1542,7 +1543,7 @@ static int wd_agg_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_agg_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_agg_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (unlikely(ret < 0)) {
diff --git a/wd_alg.c b/wd_alg.c
index 1e4f14a..a1a0a79 100644
--- a/wd_alg.c
+++ b/wd_alg.c
@@ -465,26 +465,6 @@ void wd_release_drv(struct wd_alg_driver *drv)
pthread_mutex_unlock(&mutex);
}
-int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf)
-{
- return drv->init(drv, conf);
-}
-
-void wd_alg_driver_exit(struct wd_alg_driver *drv)
-{
- drv->exit(drv);
-}
-
-int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
-{
- return drv->send(drv, ctx, msg);
-}
-
-int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
-{
- return drv->recv(drv, ctx, msg);
-}
-
int wd_alg_get_dev_usage(const char *dev_name, const char *alg_type, __u8 alg_op_type)
{
struct wd_alg_list *pnext = alg_list_head.next;
diff --git a/wd_cipher.c b/wd_cipher.c
index 58656dc..53733a4 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -53,6 +53,7 @@ struct wd_cipher_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_cipher_setting;
@@ -379,7 +380,8 @@ static int wd_cipher_common_init(struct wd_ctx_config *config,
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_cipher_setting.config,
- wd_cipher_setting.driver);
+ wd_cipher_setting.driver,
+ &wd_cipher_setting.priv);
if (ret)
goto out_clear_pool;
@@ -396,10 +398,9 @@ out_clear_ctx_config:
static int wd_cipher_common_uninit(void)
{
- enum wd_status status;
+ void *priv = wd_cipher_setting.priv;
- wd_alg_get_init(&wd_cipher_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!priv)
return -WD_EINVAL;
/* uninit async request pool */
@@ -409,7 +410,8 @@ static int wd_cipher_common_uninit(void)
wd_clear_sched(&wd_cipher_setting.sched);
wd_alg_uninit_driver(&wd_cipher_setting.config,
- wd_cipher_setting.driver);
+ wd_cipher_setting.driver,
+ &wd_cipher_setting.priv);
return 0;
}
@@ -720,8 +722,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
msg_handle.recv = wd_cipher_setting.driver->recv;
wd_ctx_spin_lock(ctx, wd_cipher_setting.driver->calc_type);
- ret = wd_handle_msg_sync(wd_cipher_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, wd_cipher_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
+ wd_cipher_setting.config.epoll_en);
wd_ctx_spin_unlock(ctx, wd_cipher_setting.driver->calc_type);
return ret;
@@ -796,7 +798,7 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req)
fill_request_msg(msg, req, sess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_cipher_setting.driver, ctx->ctx, msg);
+ ret = wd_cipher_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("wd cipher async send err!\n");
@@ -846,7 +848,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_cipher_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_cipher_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN)
return ret;
else if (ret < 0) {
diff --git a/wd_comp.c b/wd_comp.c
index c67b7f1..be08ee8 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -51,6 +51,7 @@ struct wd_comp_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_comp_setting;
@@ -172,7 +173,8 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_comp_setting.config,
- wd_comp_setting.driver);
+ wd_comp_setting.driver,
+ &wd_comp_setting.priv);
if (ret)
goto out_clear_pool;
@@ -189,10 +191,9 @@ out_clear_ctx_config:
static int wd_comp_uninit_nolock(void)
{
- enum wd_status status;
+ void *priv = wd_comp_setting.priv;
- wd_alg_get_init(&wd_comp_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!priv)
return -WD_EINVAL;
/* Uninit async request pool */
@@ -202,7 +203,8 @@ static int wd_comp_uninit_nolock(void)
wd_clear_sched(&wd_comp_setting.sched);
wd_alg_uninit_driver(&wd_comp_setting.config,
- wd_comp_setting.driver);
+ wd_comp_setting.driver,
+ &wd_comp_setting.priv);
return 0;
}
@@ -382,7 +384,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_comp_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_comp_setting.driver->recv(ctx->ctx, &resp_msg);
if (unlikely(ret < 0)) {
if (ret == -WD_HW_EACCESS)
WD_ERR("wd comp recv hw error!\n");
@@ -685,8 +687,8 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
msg_handle.recv = wd_comp_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_comp_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, config->epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
+ NULL, config->epoll_en);
pthread_spin_unlock(&ctx->lock);
return ret;
@@ -944,7 +946,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
msg->tag = tag;
msg->stream_mode = WD_COMP_STATELESS;
- ret = wd_alg_driver_send(wd_comp_setting.driver, ctx->ctx, msg);
+ ret = wd_comp_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("wd comp send error, ret = %d!\n", ret);
diff --git a/wd_dh.c b/wd_dh.c
index 0c1372c..42a1805 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -36,6 +36,7 @@ static struct wd_dh_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_dh_setting;
@@ -144,7 +145,8 @@ static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sche
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_dh_setting.config,
- wd_dh_setting.driver);
+ wd_dh_setting.driver,
+ &wd_dh_setting.priv);
if (ret)
goto out_clear_pool;
@@ -161,11 +163,10 @@ out_clear_ctx_config:
static int wd_dh_common_uninit(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_dh_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!wd_dh_setting.priv) {
+ WD_ERR("invalid: repeat uninit dh!\n");
return -WD_EINVAL;
+ }
/* uninit async request pool */
wd_uninit_async_request_pool(&wd_dh_setting.pool);
@@ -173,7 +174,8 @@ static int wd_dh_common_uninit(void)
/* unset config, sched, driver */
wd_clear_sched(&wd_dh_setting.sched);
wd_alg_uninit_driver(&wd_dh_setting.config,
- wd_dh_setting.driver);
+ wd_dh_setting.driver,
+ &wd_dh_setting.priv);
return WD_SUCCESS;
}
@@ -390,8 +392,8 @@ int wd_do_dh_sync(handle_t sess, struct wd_dh_req *req)
msg_handle.recv = wd_dh_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_dh_setting.driver, &msg_handle, ctx->ctx,
- &msg, &balance, wd_dh_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
+ wd_dh_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
return ret;
@@ -437,7 +439,7 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = wd_alg_driver_send(wd_dh_setting.driver, ctx->ctx, msg);
+ ret = wd_dh_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send dh BD, hw is err!\n");
@@ -488,7 +490,7 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_dh_setting.driver, ctx->ctx, &rcv_msg);
+ ret = wd_dh_setting.driver->recv(ctx->ctx, &rcv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (unlikely(ret)) {
diff --git a/wd_digest.c b/wd_digest.c
index 0b37f8b..763eae5 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -42,6 +42,7 @@ struct wd_digest_setting {
struct wd_sched sched;
struct wd_alg_driver *driver;
struct wd_async_msg_pool pool;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_digest_setting;
@@ -312,7 +313,8 @@ static int wd_digest_init_nolock(struct wd_ctx_config *config,
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_digest_setting.config,
- wd_digest_setting.driver);
+ wd_digest_setting.driver,
+ &wd_digest_setting.priv);
if (ret)
goto out_clear_pool;
@@ -361,29 +363,21 @@ out_clear_init:
return ret;
}
-static int wd_digest_uninit_nolock(void)
+static void wd_digest_uninit_nolock(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_digest_setting.status, &status);
- if (status == WD_UNINIT)
- return -WD_EINVAL;
-
wd_uninit_async_request_pool(&wd_digest_setting.pool);
wd_clear_sched(&wd_digest_setting.sched);
wd_alg_uninit_driver(&wd_digest_setting.config,
- wd_digest_setting.driver);
- return 0;
+ wd_digest_setting.driver,
+ &wd_digest_setting.priv);
}
void wd_digest_uninit(void)
{
- int ret;
-
- ret = wd_digest_uninit_nolock();
- if (ret)
+ if (!wd_digest_setting.priv)
return;
+ wd_digest_uninit_nolock();
wd_digest_close_driver(WD_TYPE_V1);
wd_alg_clear_init(&wd_digest_setting.status);
}
@@ -485,12 +479,10 @@ out_uninit:
void wd_digest_uninit2(void)
{
- int ret;
-
- ret = wd_digest_uninit_nolock();
- if (ret)
+ if (!wd_digest_setting.priv)
return;
+ wd_digest_uninit_nolock();
wd_alg_attrs_uninit(&wd_digest_init_attrs);
wd_alg_drv_unbind(wd_digest_setting.driver);
wd_digest_close_driver(WD_TYPE_V2);
@@ -655,8 +647,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds
msg_handle.recv = wd_digest_setting.driver->recv;
wd_ctx_spin_lock(ctx, wd_digest_setting.driver->calc_type);
- ret = wd_handle_msg_sync(wd_digest_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, wd_digest_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
+ NULL, wd_digest_setting.config.epoll_en);
wd_ctx_spin_unlock(ctx, wd_digest_setting.driver->calc_type);
if (unlikely(ret))
return ret;
@@ -750,7 +742,7 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req)
fill_request_msg(msg, req, dsess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_digest_setting.driver, ctx->ctx, msg);
+ ret = wd_digest_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send BD, hw is err!\n");
@@ -800,7 +792,8 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_digest_setting.driver, ctx->ctx, &recv_msg);
+ ret = wd_digest_setting.driver->recv(ctx->ctx,
+ &recv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_ecc.c b/wd_ecc.c
index 2c88d0a..900f36c 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -69,6 +69,7 @@ static struct wd_ecc_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_ecc_setting;
@@ -210,7 +211,8 @@ static int wd_ecc_common_init(struct wd_ctx_config *config, struct wd_sched *sch
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_ecc_setting.config,
- wd_ecc_setting.driver);
+ wd_ecc_setting.driver,
+ &wd_ecc_setting.priv);
if (ret)
goto out_clear_pool;
@@ -227,11 +229,10 @@ out_clear_ctx_config:
static int wd_ecc_common_uninit(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_ecc_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!wd_ecc_setting.priv) {
+ WD_ERR("invalid: repeat uninit ecc!\n");
return -WD_EINVAL;
+ }
/* uninit async request pool */
wd_uninit_async_request_pool(&wd_ecc_setting.pool);
@@ -239,7 +240,8 @@ static int wd_ecc_common_uninit(void)
/* unset config, sched, driver */
wd_clear_sched(&wd_ecc_setting.sched);
wd_alg_uninit_driver(&wd_ecc_setting.config,
- wd_ecc_setting.driver);
+ wd_ecc_setting.driver,
+ &wd_ecc_setting.priv);
return WD_SUCCESS;
}
@@ -1203,8 +1205,8 @@ static void wd_ecc_sess_eops_cfg(struct wd_ecc_sess_setup *setup,
{
if (sess->eops.sess_init && sess->eops.eops_params_cfg) {
/* the config result does not impact task sucesss or failure */
- sess->eops.eops_params_cfg(wd_ecc_setting.driver, setup, sess->key.cv,
- sess->eops.params);
+ sess->eops.eops_params_cfg(setup, sess->key.cv,
+ wd_ecc_setting.priv, sess->eops.params);
}
}
@@ -1652,8 +1654,8 @@ int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req)
msg_handle.recv = wd_ecc_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_ecc_setting.driver, &msg_handle, ctx->ctx, &msg,
- &balance, wd_ecc_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
+ wd_ecc_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
return ret;
@@ -2339,7 +2341,7 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = wd_alg_driver_send(wd_ecc_setting.driver, ctx->ctx, msg);
+ ret = wd_ecc_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send ecc BD, hw is err!\n");
@@ -2389,7 +2391,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_ecc_setting.driver, ctx->ctx, &recv_msg);
+ ret = wd_ecc_setting.driver->recv(ctx->ctx, &recv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_join_gather.c b/wd_join_gather.c
index 915c1b8..86190c4 100644
--- a/wd_join_gather.c
+++ b/wd_join_gather.c
@@ -410,13 +410,12 @@ static void wd_join_gather_uninit_sess(struct wd_join_gather_sess *sess)
free(sess->gather_conf.batch_row_size);
if (sess->ops.sess_uninit)
- sess->ops.sess_uninit(wd_join_gather_setting.driver, sess->priv);
+ sess->ops.sess_uninit(sess->priv);
}
static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
struct wd_join_gather_sess_setup *setup)
{
- struct wd_alg_driver *drv = wd_join_gather_setting.driver;
__u32 array_size;
int ret;
@@ -425,7 +424,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
WD_ERR("failed to get session uninit ops!\n");
return -WD_EINVAL;
}
- ret = sess->ops.sess_init(drv, setup, &sess->priv);
+ ret = sess->ops.sess_init(setup, &sess->priv);
if (ret) {
WD_ERR("failed to init session priv!\n");
return ret;
@@ -433,7 +432,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
}
if (sess->ops.get_table_row_size && setup->alg != WD_GATHER) {
- ret = sess->ops.get_table_row_size(drv, sess->priv);
+ ret = sess->ops.get_table_row_size(sess->priv);
if (ret <= 0) {
WD_ERR("failed to get hash table row size: %d!\n", ret);
goto uninit;
@@ -447,7 +446,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
if (!sess->gather_conf.batch_row_size)
goto uninit;
- ret = sess->ops.get_batch_row_size(drv, sess->priv,
+ ret = sess->ops.get_batch_row_size(sess->priv,
sess->gather_conf.batch_row_size,
array_size);
if (ret) {
@@ -462,7 +461,7 @@ free_batch:
free(sess->gather_conf.batch_row_size);
uninit:
if (sess->ops.sess_uninit)
- sess->ops.sess_uninit(drv, sess->priv);
+ sess->ops.sess_uninit(sess->priv);
return -WD_EINVAL;
}
@@ -656,8 +655,7 @@ int wd_join_set_hash_table(handle_t h_sess, struct wd_dae_hash_table *info)
WD_INFO("info: extern hash table is NULL!\n");
if (sess->ops.hash_table_init) {
- ret = sess->ops.hash_table_init(wd_join_gather_setting.driver,
- info, sess->priv);
+ ret = sess->ops.hash_table_init(info, sess->priv);
if (ret)
goto out;
}
@@ -699,7 +697,9 @@ static int wd_join_gather_alg_init(struct wd_ctx_config *config, struct wd_sched
if (ret < 0)
goto out_clear_sched;
- ret = wd_alg_init_driver(&wd_join_gather_setting.config, wd_join_gather_setting.driver);
+ ret = wd_alg_init_driver(&wd_join_gather_setting.config,
+ wd_join_gather_setting.driver,
+ &wd_join_gather_setting.priv);
if (ret)
goto out_clear_pool;
@@ -728,7 +728,9 @@ static int wd_join_gather_alg_uninit(void)
/* Unset config, sched, driver */
wd_clear_sched(&wd_join_gather_setting.sched);
- wd_alg_uninit_driver(&wd_join_gather_setting.config, wd_join_gather_setting.driver);
+ wd_alg_uninit_driver(&wd_join_gather_setting.config,
+ wd_join_gather_setting.driver,
+ &wd_join_gather_setting.priv);
return WD_SUCCESS;
}
@@ -1215,7 +1217,7 @@ static int wd_join_gather_sync_job(struct wd_join_gather_sess *sess,
msg_handle.recv = setting->driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(setting->driver, &msg_handle, ctx->ctx,
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx,
msg, NULL, config->epoll_en);
pthread_spin_unlock(&ctx->lock);
@@ -1311,7 +1313,7 @@ static int wd_join_gather_async_job(struct wd_join_gather_sess *sess,
fill_join_gather_msg(msg, req, sess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(setting->driver, ctx->ctx, msg);
+ ret = wd_join_gather_setting.driver->send(ctx->ctx, msg);
if (ret < 0) {
if (ret != -WD_EBUSY)
WD_ERR("wd join gather async send err!\n");
@@ -1781,7 +1783,7 @@ static int wd_join_gather_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_join_gather_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_join_gather_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_rsa.c b/wd_rsa.c
index bc78c6a..3e4d70d 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -77,6 +77,7 @@ static struct wd_rsa_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_rsa_setting;
@@ -184,7 +185,8 @@ static int wd_rsa_common_init(struct wd_ctx_config *config, struct wd_sched *sch
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_rsa_setting.config,
- wd_rsa_setting.driver);
+ wd_rsa_setting.driver,
+ &wd_rsa_setting.priv);
if (ret)
goto out_clear_pool;
@@ -201,11 +203,10 @@ out_clear_ctx_config:
static int wd_rsa_common_uninit(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_rsa_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!wd_rsa_setting.priv) {
+ WD_ERR("invalid: repeat uninit rsa!\n");
return -WD_EINVAL;
+ }
/* uninit async request pool */
wd_uninit_async_request_pool(&wd_rsa_setting.pool);
@@ -213,7 +214,8 @@ static int wd_rsa_common_uninit(void)
/* unset config, sched, driver */
wd_clear_sched(&wd_rsa_setting.sched);
wd_alg_uninit_driver(&wd_rsa_setting.config,
- wd_rsa_setting.driver);
+ wd_rsa_setting.driver,
+ &wd_rsa_setting.priv);
return WD_SUCCESS;
}
@@ -451,8 +453,8 @@ int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req)
msg_handle.recv = wd_rsa_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_rsa_setting.driver, &msg_handle, ctx->ctx, &msg,
- &balance, wd_rsa_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
+ wd_rsa_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
return ret;
@@ -498,7 +500,7 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = wd_alg_driver_send(wd_rsa_setting.driver, ctx->ctx, msg);
+ ret = wd_rsa_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send rsa BD, hw is err!\n");
@@ -548,7 +550,7 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_rsa_setting.driver, ctx->ctx, &recv_msg);
+ ret = wd_rsa_setting.driver->recv(ctx->ctx, &recv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_udma.c b/wd_udma.c
index eebe495..341b533 100644
--- a/wd_udma.c
+++ b/wd_udma.c
@@ -22,6 +22,7 @@ static struct wd_udma_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_udma_setting;
@@ -229,7 +230,7 @@ int wd_do_udma_sync(handle_t h_sess, struct wd_udma_req *req)
msg_handle.send = wd_udma_setting.driver->send;
msg_handle.recv = wd_udma_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_udma_setting.driver, &msg_handle, ctx->ctx,
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx,
&msg, NULL, wd_udma_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
@@ -276,7 +277,7 @@ int wd_do_udma_async(handle_t sess, struct wd_udma_req *req)
fill_udma_msg(msg, req);
msg->tag = mid;
- ret = wd_alg_driver_send(wd_udma_setting.driver, ctx->ctx, msg);
+ ret = wd_udma_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send udma BD, hw is err!\n");
@@ -314,7 +315,7 @@ static int wd_udma_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_udma_setting.driver, ctx->ctx, &rcv_msg);
+ ret = wd_udma_setting.driver->recv(ctx->ctx, &rcv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (unlikely(ret)) {
@@ -364,7 +365,9 @@ static void wd_udma_alg_uninit(void)
wd_uninit_async_request_pool(&wd_udma_setting.pool);
/* Unset config, sched, driver */
wd_clear_sched(&wd_udma_setting.sched);
- wd_alg_uninit_driver(&wd_udma_setting.config, wd_udma_setting.driver);
+ wd_alg_uninit_driver(&wd_udma_setting.config,
+ wd_udma_setting.driver,
+ &wd_udma_setting.priv);
}
void wd_udma_uninit(void)
@@ -405,7 +408,9 @@ static int wd_udma_alg_init(struct wd_ctx_config *config, struct wd_sched *sched
if (ret < 0)
goto out_clear_sched;
- ret = wd_alg_init_driver(&wd_udma_setting.config, wd_udma_setting.driver);
+ ret = wd_alg_init_driver(&wd_udma_setting.config,
+ wd_udma_setting.driver,
+ &wd_udma_setting.priv);
if (ret)
goto out_clear_pool;
diff --git a/wd_util.c b/wd_util.c
index bf82fc1..0dc9a67 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1878,8 +1878,8 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en)
return 0;
}
-int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_handle,
- handle_t ctx, void *msg, __u64 *balance, bool epoll_en)
+int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx,
+ void *msg, __u64 *balance, bool epoll_en)
{
__u64 timeout = WD_RECV_MAX_CNT_NOSLEEP;
__u64 rx_cnt = 0;
@@ -1888,7 +1888,7 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand
if (balance)
timeout = WD_RECV_MAX_CNT_SLEEP;
- ret = msg_handle->send(drv, ctx, msg);
+ ret = msg_handle->send(ctx, msg);
if (unlikely(ret < 0)) {
WD_ERR("failed to send msg to hw, ret = %d!\n", ret);
return ret;
@@ -1901,7 +1901,7 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand
WD_ERR("wd ctx wait timeout(%d)!\n", ret);
}
- ret = msg_handle->recv(drv, ctx, msg);
+ ret = msg_handle->recv(ctx, msg);
if (ret != -WD_EAGAIN) {
if (unlikely(ret < 0)) {
WD_ERR("failed to recv msg: error = %d!\n", ret);
@@ -1964,10 +1964,21 @@ static void wd_alg_uninit_fallback(struct wd_alg_driver *fb_driver)
}
int wd_alg_init_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver)
+ struct wd_alg_driver *driver, void **drv_priv)
{
+ void *priv;
int ret;
+ if (!driver->priv_size) {
+ WD_ERR("invalid: driver priv ctx size is zero!\n");
+ return -WD_EINVAL;
+ }
+
+ /* Init ctx related resources in specific driver */
+ priv = calloc(1, driver->priv_size);
+ if (!priv)
+ return -WD_ENOMEM;
+
if (!driver->init) {
driver->fallback = 0;
WD_ERR("driver have no init interface.\n");
@@ -1975,11 +1986,12 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config,
goto err_alloc;
}
- ret = driver->init(driver, config);
+ ret = driver->init(config, priv);
if (ret < 0) {
WD_ERR("driver init failed.\n");
goto err_alloc;
}
+ driver->drv_data = priv;
if (driver->fallback) {
ret = wd_alg_init_fallback((struct wd_alg_driver *)driver->fallback);
@@ -1988,22 +2000,32 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config,
WD_ERR("soft alg driver init failed.\n");
}
}
+ *drv_priv = priv;
return 0;
err_alloc:
+ free(priv);
return ret;
}
void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver)
+ struct wd_alg_driver *driver, void **drv_priv)
{
- driver->exit(driver);
+ void *priv = *drv_priv;
+
+ driver->exit(priv);
/* Ctx config just need clear once */
wd_clear_ctx_config(config);
if (driver->fallback)
wd_alg_uninit_fallback((struct wd_alg_driver *)driver->fallback);
+
+ if (priv) {
+ free(priv);
+ driver->drv_data = NULL;
+ *drv_priv = NULL;
+ }
}
void wd_dlclose_drv(void *dlh_list)
--
2.43.0
1
18
08 Apr '26
From: Longfang Liu <liulongfang(a)huawei.com>
This reverts commit 3fc344aa4f7c460269cd0d870fe388f01dfa22a2.
---
drv/hash_mb/hash_mb.c | 45 +++++------
drv/hisi_comp.c | 32 +++-----
drv/hisi_dae.c | 13 +---
drv/hisi_dae.h | 4 +-
drv/hisi_dae_common.c | 28 +++----
drv/hisi_dae_join_gather.c | 21 ++----
drv/hisi_hpre.c | 76 +++++++------------
drv/hisi_sec.c | 123 +++++++++++++++----------------
drv/hisi_udma.c | 30 +++-----
drv/isa_ce_sm3.c | 38 ++++------
drv/isa_ce_sm4.c | 41 ++++-------
include/drv/wd_agg_drv.h | 3 +-
include/drv/wd_ecc_drv.h | 5 +-
include/drv/wd_join_gather_drv.h | 12 ++-
include/wd_alg.h | 19 +++--
include/wd_util.h | 14 ++--
wd_aead.c | 37 ++++------
wd_agg.c | 15 ++--
wd_alg.c | 20 -----
wd_cipher.c | 20 ++---
wd_comp.c | 20 ++---
wd_dh.c | 22 +++---
wd_digest.c | 37 ++++------
wd_ecc.c | 26 ++++---
wd_join_gather.c | 28 +++----
wd_rsa.c | 22 +++---
wd_udma.c | 15 ++--
wd_util.c | 38 ++++++++--
28 files changed, 351 insertions(+), 453 deletions(-)
diff --git a/drv/hash_mb/hash_mb.c b/drv/hash_mb/hash_mb.c
index bd412b2..5c0daf2 100644
--- a/drv/hash_mb/hash_mb.c
+++ b/drv/hash_mb/hash_mb.c
@@ -186,46 +186,34 @@ free_mb_queue:
return ret;
}
-static int hash_mb_init(struct wd_alg_driver *drv, void *conf)
+static int hash_mb_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
- struct hash_mb_ctx *priv;
- int ret;
+ struct hash_mb_ctx *mb_ctx = priv;
/* Fallback init is NULL */
- if (!drv || !conf)
+ if (!conf || !priv)
return 0;
- priv = malloc(sizeof(struct hash_mb_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
/* multibuff does not use epoll. */
config->epoll_en = 0;
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
+ memcpy(&mb_ctx->config, config, sizeof(struct wd_ctx_config_internal));
- ret = hash_mb_queue_init(config);
- if (ret) {
- free(priv);
- return ret;
- }
-
- drv->priv = priv;
-
- return WD_SUCCESS;
+ return hash_mb_queue_init(config);
}
-static void hash_mb_exit(struct wd_alg_driver *drv)
+static void hash_mb_exit(void *priv)
{
- struct hash_mb_ctx *priv;
+ struct hash_mb_ctx *mb_ctx = priv;
+ struct wd_ctx_config_internal *config;
- if (!drv || !drv->priv)
+ if (!priv) {
+ WD_ERR("invalid: input parameter is NULL!\n");
return;
+ }
- priv = (struct hash_mb_ctx *)drv->priv;
- hash_mb_queue_uninit(&priv->config, priv->config.ctx_num);
- free(priv);
- drv->priv = NULL;
+ config = &mb_ctx->config;
+ hash_mb_queue_uninit(config, config->ctx_num);
}
static void hash_mb_pad_data(struct hash_pad *hash_pad, __u8 *in, __u32 partial,
@@ -267,7 +255,7 @@ static inline void hash_xor(__u8 *key_out, __u8 *key_in, __u32 key_len, __u8 xor
if (i < key_len)
key_out[i] = key_in[i] ^ xor_value;
else
- key_out[i] = xor_value;
+ key_out[i] = 0x0 ^ xor_value;
}
}
@@ -555,7 +543,7 @@ static int hash_mb_check_param(struct hash_mb_queue *mb_queue, struct wd_digest_
return WD_SUCCESS;
}
-static int hash_mb_send(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg)
+static int hash_mb_send(handle_t ctx, void *drv_msg)
{
struct wd_soft_ctx *s_ctx = (struct wd_soft_ctx *)ctx;
struct hash_mb_queue *mb_queue = s_ctx->priv;
@@ -776,7 +764,7 @@ static int hash_mb_do_jobs(struct hash_mb_queue *mb_queue)
return WD_SUCCESS;
}
-static int hash_mb_recv(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg)
+static int hash_mb_recv(handle_t ctx, void *drv_msg)
{
struct wd_soft_ctx *s_ctx = (struct wd_soft_ctx *)ctx;
struct hash_mb_queue *mb_queue = s_ctx->priv;
@@ -810,6 +798,7 @@ static int hash_mb_get_usage(void *param)
.alg_name = (hash_alg_name),\
.calc_type = UADK_ALG_SVE_INSTR,\
.priority = 100,\
+ .priv_size = sizeof(struct hash_mb_ctx),\
.queue_num = 1,\
.op_type_num = 1,\
.fallback = 0,\
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index a6b2947..be16b83 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -1414,11 +1414,11 @@ static void hisi_zip_sqe_ops_adapt(handle_t h_qp)
}
}
-static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
+static int hisi_zip_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv;
struct hisi_qm_priv qm_priv;
- struct hisi_zip_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -1428,11 +1428,7 @@ static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_zip_ctx));
- if (!priv)
- return -WD_EINVAL;
-
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
+ memcpy(&zip_ctx->config, config, sizeof(struct wd_ctx_config_internal));
/* allocate qp for each context */
for (i = 0; i < config->ctx_num; i++) {
h_ctx = config->ctxs[i].ctx;
@@ -1450,7 +1446,6 @@ static int hisi_zip_init(struct wd_alg_driver *drv, void *conf)
}
hisi_zip_sqe_ops_adapt(h_qp);
- drv->priv = priv;
return 0;
out:
@@ -1458,28 +1453,20 @@ out:
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[j].ctx);
hisi_qm_free_qp(h_qp);
}
- free(priv);
return -WD_EINVAL;
}
-static void hisi_zip_exit(struct wd_alg_driver *drv)
+static void hisi_zip_exit(void *priv)
{
- struct wd_ctx_config_internal *config;
- struct hisi_zip_ctx *priv;
+ struct hisi_zip_ctx *zip_ctx = (struct hisi_zip_ctx *)priv;
+ struct wd_ctx_config_internal *config = &zip_ctx->config;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
- return;
-
- priv = (struct hisi_zip_ctx *)drv->priv;
- config = &priv->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
hisi_qm_free_qp(h_qp);
}
- free(priv);
- drv->priv = NULL;
}
static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
@@ -1534,7 +1521,7 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
return 0;
}
-static int hisi_zip_comp_send(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg)
+static int hisi_zip_comp_send(handle_t ctx, void *comp_msg)
{
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
struct wd_comp_msg *msg = comp_msg;
@@ -1722,7 +1709,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe,
return 0;
}
-static int hisi_zip_comp_recv(struct wd_alg_driver *drv, handle_t ctx, void *comp_msg)
+static int hisi_zip_comp_recv(handle_t ctx, void *comp_msg)
{
struct hisi_qp *qp = wd_ctx_get_priv(ctx);
struct wd_comp_msg *recv_msg = comp_msg;
@@ -1775,7 +1762,7 @@ static int hisi_zip_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_zip_ctx *)drv->priv;
+ priv = (struct hisi_zip_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
@@ -1803,6 +1790,7 @@ static int hisi_zip_get_usage(void *param)
.alg_name = (zip_alg_name),\
.calc_type = UADK_ALG_HW,\
.priority = 100,\
+ .priv_size = sizeof(struct hisi_zip_ctx),\
.queue_num = ZIP_CTX_Q_NUM_DEF,\
.op_type_num = 2,\
.fallback = 0,\
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index d86b9f6..4a1ac89 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -426,7 +426,7 @@ static int check_hashagg_param(struct wd_agg_msg *msg)
return WD_SUCCESS;
}
-static int hashagg_send(struct wd_alg_driver *drv, handle_t ctx, void *hashagg_msg)
+static int hashagg_send(handle_t ctx, void *hashagg_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -563,7 +563,7 @@ static void fill_hashagg_msg_task_err(struct dae_sqe *sqe, struct wd_agg_msg *ms
}
}
-static int hashagg_recv(struct wd_alg_driver *drv, handle_t ctx, void *hashagg_msg)
+static int hashagg_recv(handle_t ctx, void *hashagg_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -1214,17 +1214,11 @@ static void hashagg_sess_priv_uninit(struct wd_alg_driver *drv, void *priv)
free(agg_ctx);
}
-static int hashagg_sess_priv_init(struct wd_alg_driver *drv,
- struct wd_agg_sess_setup *setup, void **priv)
+static int hashagg_sess_priv_init(struct wd_agg_sess_setup *setup, void **priv)
{
struct hashagg_ctx *agg_ctx;
int ret;
- if (!drv || !drv->priv) {
- WD_ERR("invalid: dae drv is NULL!\n");
- return -WD_EINVAL;
- }
-
if (!setup || !priv) {
WD_ERR("invalid: dae sess priv is NULL!\n");
return -WD_EINVAL;
@@ -1297,6 +1291,7 @@ static struct wd_alg_driver hashagg_driver = {
.alg_name = "hashagg",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_dae_ctx),
.queue_num = DAE_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
diff --git a/drv/hisi_dae.h b/drv/hisi_dae.h
index f82b13c..f8888b6 100644
--- a/drv/hisi_dae.h
+++ b/drv/hisi_dae.h
@@ -210,8 +210,8 @@ struct hisi_dae_ctx {
struct wd_ctx_config_internal config;
};
-void dae_exit(struct wd_alg_driver *drv);
-int dae_init(struct wd_alg_driver *drv, void *conf);
+void dae_exit(void *priv);
+int dae_init(void *conf, void *priv);
int dae_hash_table_init(struct hash_table_data *hw_table,
struct hash_table_data *rehash_table,
struct wd_dae_hash_table *hash_table,
diff --git a/drv/hisi_dae_common.c b/drv/hisi_dae_common.c
index c077d1d..216e424 100644
--- a/drv/hisi_dae_common.c
+++ b/drv/hisi_dae_common.c
@@ -308,11 +308,11 @@ update_table:
return ret;
}
-int dae_init(struct wd_alg_driver *drv, void *conf)
+int dae_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_dae_ctx *dae_ctx = priv;
struct hisi_qm_priv qm_priv;
- struct hisi_dae_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -323,10 +323,6 @@ int dae_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_dae_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
qm_priv.op_type = DAE_SQC_ALG_TYPE;
qm_priv.sqe_size = sizeof(struct dae_sqe);
/* Allocate qp for each context */
@@ -347,8 +343,7 @@ int dae_init(struct wd_alg_driver *drv, void *conf)
if (ret)
goto free_h_qp;
}
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&dae_ctx->config, config, sizeof(struct wd_ctx_config_internal));
return WD_SUCCESS;
@@ -362,22 +357,22 @@ out:
hisi_qm_free_qp(h_qp);
}
}
- free(priv);
return ret;
}
-void dae_exit(struct wd_alg_driver *drv)
+void dae_exit(void *priv)
{
struct wd_ctx_config_internal *config;
- struct hisi_dae_ctx *priv;
+ struct hisi_dae_ctx *dae_ctx = priv;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
+ if (!priv) {
+ WD_ERR("invalid: input parameter is NULL!\n");
return;
+ }
- priv = (struct hisi_dae_ctx *)drv->priv;
- config = &priv->config;
+ config = &dae_ctx->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
if (h_qp) {
@@ -385,9 +380,6 @@ void dae_exit(struct wd_alg_driver *drv)
hisi_qm_free_qp(h_qp);
}
}
-
- free(priv);
- drv->priv = NULL;
}
int dae_get_usage(void *param)
@@ -406,7 +398,7 @@ int dae_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_dae_ctx *)drv->priv;
+ priv = (struct hisi_dae_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
diff --git a/drv/hisi_dae_join_gather.c b/drv/hisi_dae_join_gather.c
index 8c45f57..43ed539 100644
--- a/drv/hisi_dae_join_gather.c
+++ b/drv/hisi_dae_join_gather.c
@@ -455,7 +455,7 @@ static int check_join_gather_param(struct wd_join_gather_msg *msg)
return WD_SUCCESS;
}
-static int join_gather_send(struct wd_alg_driver *drv, handle_t ctx, void *send_msg)
+static int join_gather_send(handle_t ctx, void *send_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -540,7 +540,7 @@ static void fill_join_gather_task_err(struct dae_sqe *sqe, struct wd_join_gather
}
}
-static int join_gather_recv(struct wd_alg_driver *drv, handle_t hctx, void *recv_msg)
+static int join_gather_recv(handle_t hctx, void *recv_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(hctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -892,7 +892,7 @@ static int join_gather_fill_ctx(struct join_gather_ctx *ctx,
return WD_SUCCESS;
}
-static void join_gather_sess_priv_uninit(struct wd_alg_driver *drv, void *priv)
+static void join_gather_sess_priv_uninit(void *priv)
{
struct join_gather_ctx *ctx = priv;
@@ -904,17 +904,11 @@ static void join_gather_sess_priv_uninit(struct wd_alg_driver *drv, void *priv)
free(ctx);
}
-static int join_gather_sess_priv_init(struct wd_alg_driver *drv,
- struct wd_join_gather_sess_setup *setup, void **priv)
+static int join_gather_sess_priv_init(struct wd_join_gather_sess_setup *setup, void **priv)
{
struct join_gather_ctx *ctx;
int ret;
- if (!drv || !drv->priv) {
- WD_ERR("invalid: dae drv is NULL!\n");
- return -WD_EINVAL;
- }
-
if (!setup || !priv) {
WD_ERR("invalid: dae sess priv is NULL!\n");
return -WD_EINVAL;
@@ -941,7 +935,7 @@ free_ctx:
return ret;
}
-static int join_get_table_row_size(struct wd_alg_driver *drv, void *param)
+static int join_get_table_row_size(void *param)
{
struct join_gather_ctx *ctx = param;
@@ -951,7 +945,7 @@ static int join_get_table_row_size(struct wd_alg_driver *drv, void *param)
return ctx->hash_table_row_size;
}
-static int gather_get_batch_row_size(struct wd_alg_driver *drv, void *param,
+static int gather_get_batch_row_size(void *param,
__u32 *row_size, __u32 size)
{
struct join_gather_ctx *ctx = param;
@@ -967,8 +961,7 @@ static int gather_get_batch_row_size(struct wd_alg_driver *drv, void *param,
return 0;
}
-static int join_hash_table_init(struct wd_alg_driver *drv,
- struct wd_dae_hash_table *table, void *priv)
+static int join_hash_table_init(struct wd_dae_hash_table *table, void *priv)
{
struct join_gather_ctx *ctx = priv;
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 3c41826..7da8407 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -680,11 +680,11 @@ out:
return -WD_EINVAL;
}
-static int hpre_rsa_dh_init(struct wd_alg_driver *drv, void *conf)
+static int hpre_rsa_dh_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
struct hisi_qm_priv qm_priv;
- struct hisi_hpre_ctx *priv;
int ret;
if (!config->ctx_num) {
@@ -692,27 +692,19 @@ static int hpre_rsa_dh_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_hpre_ctx));
- if (!priv)
- return -WD_EINVAL;
-
qm_priv.op_type = HPRE_HW_V2_ALG_TYPE;
- ret = hpre_init_qm_priv(config, priv, &qm_priv);
- if (ret) {
- free(priv);
+ ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
+ if (ret)
return ret;
- }
-
- drv->priv = priv;
return WD_SUCCESS;
}
-static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf)
+static int hpre_ecc_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
struct hisi_qm_priv qm_priv;
- struct hisi_hpre_ctx *priv;
int ret;
if (!config->ctx_num) {
@@ -720,44 +712,28 @@ static int hpre_ecc_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_hpre_ctx));
- if (!priv)
- return -WD_EINVAL;
-
qm_priv.op_type = HPRE_HW_V3_ECC_ALG_TYPE;
- ret = hpre_init_qm_priv(config, priv, &qm_priv);
- if (ret) {
- free(priv);
+ ret = hpre_init_qm_priv(config, hpre_ctx, &qm_priv);
+ if (ret)
return ret;
- }
-
- drv->priv = priv;
return WD_SUCCESS;
}
-static void hpre_exit(struct wd_alg_driver *drv)
+static void hpre_exit(void *priv)
{
- struct wd_ctx_config_internal *config;
- struct hisi_hpre_ctx *priv;
+ struct hisi_hpre_ctx *hpre_ctx = (struct hisi_hpre_ctx *)priv;
+ struct wd_ctx_config_internal *config = &hpre_ctx->config;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
- return;
-
- priv = (struct hisi_hpre_ctx *)drv->priv;
- config = &priv->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
hisi_qm_free_qp(h_qp);
}
-
- free(priv);
- drv->priv = NULL;
}
-static int rsa_send(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
+static int rsa_send(handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_rsa_msg *msg = rsa_msg;
@@ -829,7 +805,7 @@ static void hpre_result_check(struct hisi_hpre_sqe *hw_msg,
}
}
-static int rsa_recv(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
+static int rsa_recv(handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -949,7 +925,7 @@ static int dh_out_transfer(struct wd_dh_msg *msg, struct hisi_hpre_sqe *hw_msg,
return WD_SUCCESS;
}
-static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
+static int dh_send(handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct map_info_cache cache = {0};
@@ -1020,7 +996,7 @@ dh_fail:
return ret;
}
-static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
+static int dh_recv(handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -2147,7 +2123,7 @@ free_dst:
return ret;
}
-static int ecc_send(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
+static int ecc_send(handle_t ctx, void *ecc_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_ecc_msg *msg = ecc_msg;
@@ -2743,7 +2719,7 @@ fail:
return ret;
}
-static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
+static int ecc_recv(handle_t ctx, void *ecc_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_ecc_msg *msg = ecc_msg;
@@ -2786,7 +2762,7 @@ static handle_t hpre_find_dev_qp(struct wd_alg_driver *drv, const char *dev_name
handle_t qp = 0;
__u32 i;
- priv = (struct hisi_hpre_ctx *)drv->priv;
+ priv = (struct hisi_hpre_ctx *)drv->drv_data;
if (!priv)
return 0;
@@ -2874,31 +2850,30 @@ static void ecc_sess_eops_uninit(struct wd_alg_driver *drv, void *params)
free(params);
}
-static bool is_valid_hw_type(struct wd_alg_driver *drv)
+static bool is_valid_hw_type(void *drv_priv)
{
struct hisi_hpre_ctx *hpre_ctx;
struct hisi_qp *qp;
- if (unlikely(!drv || !drv->priv))
+ if (unlikely(!drv_priv))
return false;
- hpre_ctx = (struct hisi_hpre_ctx *)drv->priv;
+ hpre_ctx = (struct hisi_hpre_ctx *)drv_priv;
qp = (struct hisi_qp *)wd_ctx_get_priv(hpre_ctx->config.ctxs[0].ctx);
if (!qp || qp->q_info.hw_type < HISI_QM_API_VER3_BASE)
return false;
return true;
}
-static void ecc_sess_eops_params_cfg(struct wd_alg_driver *drv,
- struct wd_ecc_sess_setup *setup,
- struct wd_ecc_curve *cv, void *params)
+static void ecc_sess_eops_params_cfg(struct wd_ecc_sess_setup *setup,
+ struct wd_ecc_curve *cv, void *drv_priv, void *params)
{
__u8 data[SECP256R1_PARAM_SIZE] = SECG_P256_R1_PARAM;
struct hpre_ecc_ctx *ecc_ctx = params;
__u32 key_size;
int ret;
- if (!is_valid_hw_type(drv))
+ if (!is_valid_hw_type(drv_priv))
return;
if (!ecc_ctx) {
@@ -2938,6 +2913,7 @@ static int hpre_ecc_get_extend_ops(void *ops)
.alg_name = (hpre_alg_name),\
.calc_type = UADK_ALG_HW,\
.priority = 100,\
+ .priv_size = sizeof(struct hisi_hpre_ctx),\
.queue_num = HPRE_CTX_Q_NUM_DEF,\
.op_type_num = 1,\
.fallback = 0,\
@@ -2962,6 +2938,7 @@ static struct wd_alg_driver hpre_rsa_driver = {
.alg_name = "rsa",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_hpre_ctx),
.queue_num = HPRE_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
@@ -2977,6 +2954,7 @@ static struct wd_alg_driver hpre_dh_driver = {
.alg_name = "dh",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_hpre_ctx),
.queue_num = HPRE_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index c8b831c..fb9de2c 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -526,76 +526,76 @@ static __u32 g_sec_hmac_full_len[WD_DIGEST_TYPE_MAX] = {
SEC_HMAC_SHA512_MAC_LEN, SEC_HMAC_SHA512_224_MAC_LEN, SEC_HMAC_SHA512_256_MAC_LEN
};
-static int hisi_sec_init(struct wd_alg_driver *drv, void *conf);
-static void hisi_sec_exit(struct wd_alg_driver *drv);
+static int hisi_sec_init(void *conf, void *priv);
+static void hisi_sec_exit(void *priv);
-static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_send(handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_recv(handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_send_v3(handle_t ctx, void *wd_msg);
+static int hisi_sec_cipher_recv_v3(handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_send(handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_recv(handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_send_v3(handle_t ctx, void *wd_msg);
+static int hisi_sec_digest_recv_v3(handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
-static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_send(handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_recv(handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_send_v3(handle_t ctx, void *wd_msg);
+static int hisi_sec_aead_recv_v3(handle_t ctx, void *wd_msg);
-static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_send(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_cipher_send(drv, ctx, msg);
- return hisi_sec_cipher_send_v3(drv, ctx, msg);
+ return hisi_sec_cipher_send(ctx, msg);
+ return hisi_sec_cipher_send_v3(ctx, msg);
}
-static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_recv(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_cipher_recv(drv, ctx, msg);
- return hisi_sec_cipher_recv_v3(drv, ctx, msg);
+ return hisi_sec_cipher_recv(ctx, msg);
+ return hisi_sec_cipher_recv_v3(ctx, msg);
}
-static int digest_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int digest_send(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_digest_send(drv, ctx, msg);
- return hisi_sec_digest_send_v3(drv, ctx, msg);
+ return hisi_sec_digest_send(ctx, msg);
+ return hisi_sec_digest_send_v3(ctx, msg);
}
-static int digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int digest_recv(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_digest_recv(drv, ctx, msg);
- return hisi_sec_digest_recv_v3(drv, ctx, msg);
+ return hisi_sec_digest_recv(ctx, msg);
+ return hisi_sec_digest_recv_v3(ctx, msg);
}
-static int aead_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int aead_send(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_aead_send(drv, ctx, msg);
- return hisi_sec_aead_send_v3(drv, ctx, msg);
+ return hisi_sec_aead_send(ctx, msg);
+ return hisi_sec_aead_send_v3(ctx, msg);
}
-static int aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int aead_recv(handle_t ctx, void *msg)
{
struct hisi_qp *qp = (struct hisi_qp *)wd_ctx_get_priv(ctx);
if (qp->q_info.hw_type == HISI_QM_API_VER2_BASE)
- return hisi_sec_aead_recv(drv, ctx, msg);
- return hisi_sec_aead_recv_v3(drv, ctx, msg);
+ return hisi_sec_aead_recv(ctx, msg);
+ return hisi_sec_aead_recv_v3(ctx, msg);
}
static int hisi_sec_get_usage(void *param)
@@ -614,7 +614,7 @@ static int hisi_sec_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_sec_ctx *)drv->priv;
+ priv = (struct hisi_sec_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
@@ -638,8 +638,8 @@ static int hisi_sec_get_usage(void *param)
static int eops_param_check(struct wd_alg_driver *drv, struct wd_mm_ops *mm_ops)
{
- if (!drv || !drv->priv) {
- WD_ERR("invalid: aead drv or priv is NULL!\n");
+ if (!drv || !drv->drv_data) {
+ WD_ERR("invalid: aead drv or data is NULL!\n");
return -WD_EINVAL;
}
@@ -680,7 +680,7 @@ static int aead_sess_eops_init(struct wd_alg_driver *drv,
return -WD_ENOMEM;
}
- sec_ctx = (struct hisi_sec_ctx *)drv->priv;
+ sec_ctx = (struct hisi_sec_ctx *)drv->drv_data;
qp = (struct hisi_qp *)wd_ctx_get_priv(sec_ctx->config.ctxs[0].ctx);
sq_depth = qp->q_info.sq_depth;
aiv_addr->aiv = mm_ops->alloc(mm_ops->usr, (__u32)sq_depth << AEAD_AIV_OFFSET);
@@ -735,7 +735,7 @@ static void aead_sess_eops_uninit(struct wd_alg_driver *drv,
return;
}
- sec_ctx = (struct hisi_sec_ctx *)drv->priv;
+ sec_ctx = (struct hisi_sec_ctx *)drv->drv_data;
qp = (struct hisi_qp *)wd_ctx_get_priv(sec_ctx->config.ctxs[0].ctx);
sq_depth = qp->q_info.sq_depth;
@@ -793,6 +793,7 @@ static int sec_aead_get_extend_ops(void *ops)
.alg_name = (sec_alg_name),\
.calc_type = UADK_ALG_HW,\
.priority = 100,\
+ .priv_size = sizeof(struct hisi_sec_ctx),\
.queue_num = SEC_CTX_Q_NUM_DEF,\
.op_type_num = 1,\
.fallback = 0,\
@@ -1400,7 +1401,7 @@ static int fill_cipher_bd2(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe)
return 0;
}
-static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_cipher_send(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_cipher_msg *msg = wd_msg;
@@ -1456,7 +1457,7 @@ static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *w
return 0;
}
-static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_cipher_recv(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_cipher_msg *recv_msg = wd_msg;
@@ -1693,7 +1694,7 @@ static void fill_sec_prefetch(__u8 data_fmt, __u32 len, __u16 hw_type, struct hi
sqe->auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET;
}
-static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_cipher_send_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -1800,7 +1801,7 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "cipher");
}
-static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_cipher_recv_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_cipher_msg *recv_msg = wd_msg;
@@ -2132,7 +2133,7 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type)
return 0;
}
-static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_digest_send(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_digest_msg *msg = wd_msg;
@@ -2209,7 +2210,7 @@ put_sgl:
return ret;
}
-static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_digest_recv(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_digest_msg *recv_msg = wd_msg;
@@ -2473,7 +2474,7 @@ map_err:
return -WD_ENOMEM;
}
-static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_digest_send_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -2587,7 +2588,7 @@ static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "digest");
}
-static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_digest_recv_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_digest_msg *recv_msg = wd_msg;
@@ -3216,7 +3217,7 @@ static int fill_aead_bd2_addr(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe,
return aead_mem_nosva_map(msg, sqe, idx);
}
-static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_aead_send(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -3347,7 +3348,7 @@ static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe,
dump_sec_msg(temp_msg, "aead");
}
-static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_aead_recv(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_aead_msg *recv_msg = wd_msg;
@@ -3744,7 +3745,7 @@ static int fill_aead_bd3_addr(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe
return aead_mem_nosva_map_v3(msg, sqe, idx);
}
-static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int hisi_sec_aead_send_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -3863,7 +3864,7 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe,
dump_sec_msg(temp_msg, "aead");
}
-static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+int hisi_sec_aead_recv_v3(handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_aead_msg *recv_msg = wd_msg;
@@ -3888,11 +3889,11 @@ static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *
return 0;
}
-static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
+static int hisi_sec_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_sec_ctx *sec_ctx = priv;
struct hisi_qm_priv qm_priv;
- struct hisi_sec_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -3902,10 +3903,6 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_sec_ctx));
- if (!priv)
- return -WD_EINVAL;
-
qm_priv.sqe_size = sizeof(struct hisi_sec_sqe);
/* allocate qp for each context */
for (i = 0; i < config->ctx_num; i++) {
@@ -3922,8 +3919,7 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf)
goto out;
config->ctxs[i].sqn = qm_priv.sqn;
}
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&sec_ctx->config, config, sizeof(struct wd_ctx_config_internal));
return 0;
@@ -3936,25 +3932,24 @@ out:
return -WD_EINVAL;
}
-static void hisi_sec_exit(struct wd_alg_driver *drv)
+static void hisi_sec_exit(void *priv)
{
struct wd_ctx_config_internal *config;
- struct hisi_sec_ctx *priv;
+ struct hisi_sec_ctx *sec_ctx = priv;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
+ if (!priv) {
+ WD_ERR("invalid: input parameter is NULL!\n");
return;
+ }
- priv = (struct hisi_sec_ctx *)drv->priv;
- config = &priv->config;
+ config = &sec_ctx->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
hisi_qm_free_qp(h_qp);
}
- free(priv);
- drv->priv = NULL;
}
#ifdef WD_STATIC_DRV
diff --git a/drv/hisi_udma.c b/drv/hisi_udma.c
index a9f5607..5c8a743 100644
--- a/drv/hisi_udma.c
+++ b/drv/hisi_udma.c
@@ -290,7 +290,7 @@ static void fill_init_value(struct udma_sqe *sqe, struct wd_udma_msg *msg)
memset(&sqe->init_val, msg->value, sizeof(__u64));
}
-static int udma_send(struct wd_alg_driver *drv, handle_t ctx, void *udma_msg)
+static int udma_send(handle_t ctx, void *udma_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -342,7 +342,7 @@ static void dump_udma_msg(struct udma_sqe *sqe, struct wd_udma_msg *msg)
"op_type:%u addr_num:%d.\n", msg->op_type, msg->addr_num);
}
-static int udma_recv(struct wd_alg_driver *drv, handle_t ctx, void *udma_msg)
+static int udma_recv(handle_t ctx, void *udma_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
@@ -442,11 +442,11 @@ free_inter_addr:
return ret;
}
-static int udma_init(struct wd_alg_driver *drv, void *conf)
+static int udma_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
+ struct hisi_udma_ctx *uctx = priv;
struct hisi_qm_priv qm_priv;
- struct hisi_udma_ctx *priv;
handle_t h_qp = 0;
handle_t h_ctx;
__u32 i, j;
@@ -457,10 +457,6 @@ static int udma_init(struct wd_alg_driver *drv, void *conf)
return -WD_EINVAL;
}
- priv = malloc(sizeof(struct hisi_udma_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
qm_priv.op_type = UDMA_ALG_TYPE;
qm_priv.sqe_size = sizeof(struct udma_sqe);
/* Allocate qp for each context */
@@ -481,8 +477,7 @@ static int udma_init(struct wd_alg_driver *drv, void *conf)
if (ret)
goto free_h_qp;
}
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&uctx->config, config, sizeof(struct wd_ctx_config_internal));
return WD_SUCCESS;
free_h_qp:
@@ -493,30 +488,26 @@ out:
udma_uninit_qp_priv(h_qp);
hisi_qm_free_qp(h_qp);
}
- free(priv);
return ret;
}
-static void udma_exit(struct wd_alg_driver *drv)
+static void udma_exit(void *priv)
{
struct wd_ctx_config_internal *config;
- struct hisi_udma_ctx *priv;
+ struct hisi_udma_ctx *uctx = priv;
handle_t h_qp;
__u32 i;
- if (!drv || !drv->priv)
+ if (!priv)
return;
- priv = (struct hisi_udma_ctx *)drv->priv;
- config = &priv->config;
+ config = &uctx->config;
for (i = 0; i < config->ctx_num; i++) {
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
udma_uninit_qp_priv(h_qp);
hisi_qm_free_qp(h_qp);
}
- free(priv);
- drv->priv = NULL;
}
static int udma_get_usage(void *param)
@@ -535,7 +526,7 @@ static int udma_get_usage(void *param)
return -WD_EINVAL;
}
- priv = (struct hisi_udma_ctx *)drv->priv;
+ priv = (struct hisi_udma_ctx *)drv->drv_data;
if (!priv)
return -WD_EACCES;
@@ -562,6 +553,7 @@ static struct wd_alg_driver udma_driver = {
.alg_name = "udma",
.calc_type = UADK_ALG_HW,
.priority = 100,
+ .priv_size = sizeof(struct hisi_udma_ctx),
.queue_num = UDMA_CTX_Q_NUM_DEF,
.op_type_num = 1,
.fallback = 0,
diff --git a/drv/isa_ce_sm3.c b/drv/isa_ce_sm3.c
index 8d23061..0ebaba5 100644
--- a/drv/isa_ce_sm3.c
+++ b/drv/isa_ce_sm3.c
@@ -24,10 +24,10 @@
typedef void (sm3_ce_block_fn)(__u32 word_reg[SM3_STATE_WORDS],
const unsigned char *src, size_t blocks);
-static int sm3_ce_drv_init(struct wd_alg_driver *drv, void *conf);
-static void sm3_ce_drv_exit(struct wd_alg_driver *drv);
-static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg);
-static int sm3_ce_drv_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg);
+static int sm3_ce_drv_init(void *conf, void *priv);
+static void sm3_ce_drv_exit(void *priv);
+static int sm3_ce_drv_send(handle_t ctx, void *digest_msg);
+static int sm3_ce_drv_recv(handle_t ctx, void *digest_msg);
static int sm3_ce_get_usage(void *param);
static struct wd_alg_driver sm3_ce_alg_driver = {
@@ -35,6 +35,7 @@ static struct wd_alg_driver sm3_ce_alg_driver = {
.alg_name = "sm3",
.calc_type = UADK_ALG_CE_INSTR,
.priority = 200,
+ .priv_size = sizeof(struct sm3_ce_drv_ctx),
.queue_num = 1,
.op_type_num = 1,
.fallback = 0,
@@ -335,7 +336,7 @@ static int do_hmac_sm3_ce(struct wd_digest_msg *msg, __u8 *out_hmac)
return WD_SUCCESS;
}
-static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
+static int sm3_ce_drv_send(handle_t ctx, void *digest_msg)
{
struct wd_digest_msg *msg = (struct wd_digest_msg *)digest_msg;
__u8 digest[SM3_DIGEST_SIZE] = {0};
@@ -370,39 +371,26 @@ static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest
return ret;
}
-static int sm3_ce_drv_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg)
+static int sm3_ce_drv_recv(handle_t ctx, void *digest_msg)
{
return WD_SUCCESS;
}
-static int sm3_ce_drv_init(struct wd_alg_driver *drv, void *conf)
+static int sm3_ce_drv_init(void *conf, void *priv)
{
- struct wd_ctx_config_internal *config = (struct wd_ctx_config_internal *)conf;
- struct sm3_ce_drv_ctx *priv;
+ struct wd_ctx_config_internal *config = conf;
+ struct sm3_ce_drv_ctx *sctx = priv;
/* Fallback init is NULL */
- if (!drv || !conf)
+ if (!conf || !conf)
return 0;
- priv = malloc(sizeof(struct sm3_ce_drv_ctx));
- if (!priv)
- return -WD_ENOMEM;
-
config->epoll_en = 0;
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&sctx->config, config, sizeof(struct wd_ctx_config_internal));
return WD_SUCCESS;
}
-static void sm3_ce_drv_exit(struct wd_alg_driver *drv)
+static void sm3_ce_drv_exit(void *priv)
{
- struct sm3_ce_drv_ctx *sctx;
-
- if (!drv || !drv->priv)
- return;
-
- sctx = (struct sm3_ce_drv_ctx *)drv->priv;
- free(sctx);
- drv->priv = NULL;
}
diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c
index 52dca1f..504ef73 100644
--- a/drv/isa_ce_sm4.c
+++ b/drv/isa_ce_sm4.c
@@ -11,9 +11,10 @@
* Copyright 2024 Huawei Technologies Co.,Ltd. All rights reserved.
*/
+#include "wd_alg.h"
#include "drv/wd_cipher_drv.h"
-#include "wd_cipher.h"
#include "isa_ce_sm4.h"
+#include "wd_cipher.h"
#define SM4_ENCRYPT 1
#define SM4_DECRYPT 0
@@ -31,36 +32,23 @@
((p)[0] = (__u8)((v) >> 24), (p)[1] = (__u8)((v) >> 16), \
(p)[2] = (__u8)((v) >> 8), (p)[3] = (__u8)(v))
-static int isa_ce_init(struct wd_alg_driver *drv, void *conf)
+static int isa_ce_init(void *conf, void *priv)
{
struct wd_ctx_config_internal *config = conf;
- struct sm4_ce_drv_ctx *priv;
+ struct sm4_ce_drv_ctx *sctx = priv;
/* Fallback init is NULL */
- if (!drv || !conf)
+ if (!conf || !priv)
return 0;
- priv = malloc(sizeof(struct sm4_ce_drv_ctx));
- if (!priv)
- return -WD_EINVAL;
-
config->epoll_en = 0;
- memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
- drv->priv = priv;
+ memcpy(&sctx->config, config, sizeof(struct wd_ctx_config_internal));
- return WD_SUCCESS;
+ return 0;
}
-static void isa_ce_exit(struct wd_alg_driver *drv)
+static void isa_ce_exit(void *priv)
{
- struct sm4_ce_drv_ctx *sctx;
-
- if (!drv || !drv->priv)
- return;
-
- sctx = (struct sm4_ce_drv_ctx *)drv->priv;
- free(sctx);
- drv->priv = NULL;
}
/* increment upper 96 bits of 128-bit counter by 1 */
@@ -334,7 +322,7 @@ static int sm4_xts_decrypt(struct wd_cipher_msg *msg, const struct SM4_KEY *rkey
return 0;
}
-static int isa_ce_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int isa_ce_cipher_send(handle_t ctx, void *wd_msg)
{
struct wd_cipher_msg *msg = wd_msg;
struct SM4_KEY rkey;
@@ -400,19 +388,19 @@ static int isa_ce_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_
return ret;
}
-static int isa_ce_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
+static int isa_ce_cipher_recv(handle_t ctx, void *wd_msg)
{
return 0;
}
-static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_send(handle_t ctx, void *msg)
{
- return isa_ce_cipher_send(drv, ctx, msg);
+ return isa_ce_cipher_send(ctx, msg);
}
-static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
+static int cipher_recv(handle_t ctx, void *msg)
{
- return isa_ce_cipher_recv(drv, ctx, msg);
+ return isa_ce_cipher_recv(ctx, msg);
}
#define GEN_CE_ALG_DRIVER(ce_alg_name, alg_type) \
@@ -421,6 +409,7 @@ static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
.alg_name = (ce_alg_name),\
.calc_type = UADK_ALG_CE_INSTR,\
.priority = 200,\
+ .priv_size = sizeof(struct sm4_ce_drv_ctx),\
.op_type_num = 1,\
.fallback = 0,\
.init = isa_ce_init,\
diff --git a/include/drv/wd_agg_drv.h b/include/drv/wd_agg_drv.h
index b26b25d..8952ee9 100644
--- a/include/drv/wd_agg_drv.h
+++ b/include/drv/wd_agg_drv.h
@@ -43,8 +43,7 @@ struct wd_agg_msg {
struct wd_agg_ops {
int (*get_row_size)(struct wd_alg_driver *drv, void *priv);
- int (*sess_init)(struct wd_alg_driver *drv,
- struct wd_agg_sess_setup *setup, void **priv);
+ int (*sess_init)(struct wd_agg_sess_setup *setup, void **priv);
void (*sess_uninit)(struct wd_alg_driver *drv, void *priv);
int (*hash_table_init)(struct wd_alg_driver *drv,
struct wd_dae_hash_table *hash_table, void *priv);
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 48c422f..98ff28c 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -181,9 +181,8 @@ struct wd_ecc_out {
struct wd_ecc_extend_ops {
void *params; /* the params are passed to the following ops */
- void (*eops_params_cfg)(struct wd_alg_driver *drv,
- struct wd_ecc_sess_setup *setup,
- struct wd_ecc_curve *cv, void *params);
+ void (*eops_params_cfg)(struct wd_ecc_sess_setup *setup,
+ struct wd_ecc_curve *cv, void *drv_priv, void *params);
int (*sess_init)(struct wd_alg_driver *drv, void **params);
void (*sess_uninit)(struct wd_alg_driver *drv, void *params);
};
diff --git a/include/drv/wd_join_gather_drv.h b/include/drv/wd_join_gather_drv.h
index dbf4ee7..d7f136d 100644
--- a/include/drv/wd_join_gather_drv.h
+++ b/include/drv/wd_join_gather_drv.h
@@ -33,14 +33,12 @@ struct wd_join_gather_msg {
};
struct wd_join_gather_ops {
- int (*get_table_row_size)(struct wd_alg_driver *drv, void *priv);
- int (*get_batch_row_size)(struct wd_alg_driver *drv, void *priv,
+ int (*get_table_row_size)(void *priv);
+ int (*get_batch_row_size)(void *priv,
__u32 *batch_row_size, __u32 size);
- int (*sess_init)(struct wd_alg_driver *drv,
- struct wd_join_gather_sess_setup *setup, void **priv);
- void (*sess_uninit)(struct wd_alg_driver *drv, void *priv);
- int (*hash_table_init)(struct wd_alg_driver *drv,
- struct wd_dae_hash_table *hash_table, void *priv);
+ int (*sess_init)(struct wd_join_gather_sess_setup *setup, void **priv);
+ void (*sess_uninit)(void *priv);
+ int (*hash_table_init)(struct wd_dae_hash_table *hash_table, void *priv);
};
struct wd_join_gather_msg *wd_join_gather_get_msg(__u32 idx, __u32 tag);
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 18503ca..885a5e3 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -19,6 +19,7 @@ extern "C" {
#define handle_t uintptr_t
#define ALG_NAME_SIZE 128
#define DEV_NAME_LEN 128
+typedef unsigned char __u8;
/*
* Macros related to arm platform:
@@ -85,7 +86,8 @@ enum alg_dev_type {
* execute the algorithm task
* @op_type_num: number of modes in which the device executes the
* algorithm business and requires queues to be executed separately
- * @priv: pointer of priv ctx
+ * @priv_size: parameter memory size passed between the internal
+ * interfaces of the driver
* @fallback: soft calculation driver handle when performing soft
* calculation supplement
* @init: callback interface for initializing device drivers
@@ -105,13 +107,14 @@ struct wd_alg_driver {
int calc_type;
int queue_num;
int op_type_num;
- void *priv;
+ int priv_size;
+ int *drv_data;
handle_t fallback;
- int (*init)(struct wd_alg_driver *drv, void *conf);
- void (*exit)(struct wd_alg_driver *drv);
- int (*send)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
- int (*recv)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
+ int (*init)(void *conf, void *priv);
+ void (*exit)(void *priv);
+ int (*send)(handle_t ctx, void *drv_msg);
+ int (*recv)(handle_t ctx, void *drv_msg);
int (*get_usage)(void *param);
int (*get_extend_ops)(void *ops);
};
@@ -182,10 +185,6 @@ bool wd_drv_alg_support(const char *alg_name,
void wd_enable_drv(struct wd_alg_driver *drv);
void wd_disable_drv(struct wd_alg_driver *drv);
-int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf);
-void wd_alg_driver_exit(struct wd_alg_driver *drv);
-int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg);
-int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg);
int wd_alg_get_dev_usage(const char *dev_name, const char *alg_type, __u8 op_type);
int wd_get_alg_type(const char *alg_name, char *alg_type);
diff --git a/include/wd_util.h b/include/wd_util.h
index 2abceec..14985e2 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -120,8 +120,8 @@ struct wd_ctx_attr {
};
struct wd_msg_handle {
- int (*send)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
- int (*recv)(struct wd_alg_driver *drv, handle_t ctx, void *drv_msg);
+ int (*send)(handle_t sess, void *msg);
+ int (*recv)(handle_t sess, void *msg);
};
struct wd_init_attrs {
@@ -378,7 +378,6 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en);
/**
* wd_handle_msg_sync() - recv msg from hardware
- * @drv: the driver to handle msg.
* @msg_handle: callback of msg handle ops.
* @ctx: the handle of context.
* @msg: the msg of task.
@@ -387,8 +386,8 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en);
*
* Return 0 if successful or less than 0 otherwise.
*/
-int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_handle,
- handle_t ctx, void *msg, __u64 *balance, bool epoll_en);
+int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx,
+ void *msg, __u64 *balance, bool epoll_en);
/**
* wd_init_check() - Check input parameters for wd_<alg>_init.
@@ -486,13 +485,14 @@ void wd_alg_drv_unbind(struct wd_alg_driver *drv);
* to the obtained queue resource and the applied driver.
* @config: device resources requested by the current algorithm.
* @driver: device driver for the current algorithm application.
+ * @drv_priv: the parameter pointer of the current device driver.
*
* Return 0 if succeed and other error number if fail.
*/
int wd_alg_init_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver);
+ struct wd_alg_driver *driver, void **drv_priv);
void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver);
+ struct wd_alg_driver *driver, void **drv_priv);
/**
* wd_dlopen_drv() - Open the dynamic library file of the device driver.
diff --git a/wd_aead.c b/wd_aead.c
index 8467409..43bda73 100644
--- a/wd_aead.c
+++ b/wd_aead.c
@@ -34,6 +34,7 @@ struct wd_aead_setting {
struct wd_sched sched;
struct wd_alg_driver *driver;
struct wd_async_msg_pool pool;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_aead_setting;
@@ -603,7 +604,8 @@ static int wd_aead_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_aead_setting.config,
- wd_aead_setting.driver);
+ wd_aead_setting.driver,
+ &wd_aead_setting.priv);
if (ret)
goto out_clear_pool;
@@ -652,30 +654,21 @@ out_clear_init:
return ret;
}
-static int wd_aead_uninit_nolock(void)
+static void wd_aead_uninit_nolock(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_aead_setting.status, &status);
- if (status == WD_UNINIT)
- return -WD_EINVAL;
-
wd_uninit_async_request_pool(&wd_aead_setting.pool);
wd_clear_sched(&wd_aead_setting.sched);
wd_alg_uninit_driver(&wd_aead_setting.config,
- wd_aead_setting.driver);
-
- return 0;
+ wd_aead_setting.driver,
+ &wd_aead_setting.priv);
}
void wd_aead_uninit(void)
{
- int ret;
-
- ret = wd_aead_uninit_nolock();
- if (ret)
+ if (!wd_aead_setting.priv)
return;
+ wd_aead_uninit_nolock();
wd_aead_close_driver(WD_TYPE_V1);
wd_alg_clear_init(&wd_aead_setting.status);
}
@@ -781,12 +774,10 @@ out_uninit:
void wd_aead_uninit2(void)
{
- int ret;
-
- ret = wd_aead_uninit_nolock();
- if (ret)
+ if (!wd_aead_setting.priv)
return;
+ wd_aead_uninit_nolock();
wd_alg_attrs_uninit(&wd_aead_init_attrs);
wd_alg_drv_unbind(wd_aead_setting.driver);
wd_aead_close_driver(WD_TYPE_V2);
@@ -875,8 +866,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
msg_handle.recv = wd_aead_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_aead_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, wd_aead_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
+ wd_aead_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
return ret;
@@ -951,7 +942,7 @@ int wd_do_aead_async(handle_t h_sess, struct wd_aead_req *req)
fill_request_msg(msg, req, sess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_aead_setting.driver, ctx->ctx, msg);
+ ret = wd_aead_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send BD, hw is err!\n");
@@ -1001,7 +992,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_aead_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_aead_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_agg.c b/wd_agg.c
index 8c54d10..66e9e0f 100644
--- a/wd_agg.c
+++ b/wd_agg.c
@@ -361,7 +361,7 @@ static int wd_agg_init_sess_priv(struct wd_agg_sess *sess, struct wd_agg_sess_se
WD_ERR("failed to get session uninit ops!\n");
return -WD_EINVAL;
}
- ret = sess->ops.sess_init(wd_agg_setting.driver, setup, &sess->priv);
+ ret = sess->ops.sess_init(setup, &sess->priv);
if (ret) {
WD_ERR("failed to init session priv!\n");
return ret;
@@ -595,7 +595,8 @@ static int wd_agg_alg_init(struct wd_ctx_config *config, struct wd_sched *sched)
if (ret < 0)
goto out_clear_sched;
- ret = wd_alg_init_driver(&wd_agg_setting.config, wd_agg_setting.driver);
+ ret = wd_alg_init_driver(&wd_agg_setting.config, wd_agg_setting.driver,
+ &wd_agg_setting.priv);
if (ret)
goto out_clear_pool;
@@ -624,7 +625,8 @@ static int wd_agg_alg_uninit(void)
/* Unset config, sched, driver */
wd_clear_sched(&wd_agg_setting.sched);
- wd_alg_uninit_driver(&wd_agg_setting.config, wd_agg_setting.driver);
+ wd_alg_uninit_driver(&wd_agg_setting.config, wd_agg_setting.driver,
+ &wd_agg_setting.priv);
return WD_SUCCESS;
}
@@ -1101,8 +1103,7 @@ static int wd_agg_sync_job(struct wd_agg_sess *sess, struct wd_agg_req *req,
msg_handle.recv = wd_agg_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_agg_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, config->epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL, config->epoll_en);
pthread_spin_unlock(&ctx->lock);
return ret;
@@ -1203,7 +1204,7 @@ static int wd_agg_async_job(struct wd_agg_sess *sess, struct wd_agg_req *req, bo
else
fill_request_msg_output(msg, req, sess, false);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_agg_setting.driver, ctx->ctx, msg);
+ ret = wd_agg_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("wd agg async send err!\n");
@@ -1542,7 +1543,7 @@ static int wd_agg_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_agg_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_agg_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (unlikely(ret < 0)) {
diff --git a/wd_alg.c b/wd_alg.c
index 1e4f14a..a1a0a79 100644
--- a/wd_alg.c
+++ b/wd_alg.c
@@ -465,26 +465,6 @@ void wd_release_drv(struct wd_alg_driver *drv)
pthread_mutex_unlock(&mutex);
}
-int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf)
-{
- return drv->init(drv, conf);
-}
-
-void wd_alg_driver_exit(struct wd_alg_driver *drv)
-{
- drv->exit(drv);
-}
-
-int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg)
-{
- return drv->send(drv, ctx, msg);
-}
-
-int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
-{
- return drv->recv(drv, ctx, msg);
-}
-
int wd_alg_get_dev_usage(const char *dev_name, const char *alg_type, __u8 alg_op_type)
{
struct wd_alg_list *pnext = alg_list_head.next;
diff --git a/wd_cipher.c b/wd_cipher.c
index 58656dc..53733a4 100644
--- a/wd_cipher.c
+++ b/wd_cipher.c
@@ -53,6 +53,7 @@ struct wd_cipher_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_cipher_setting;
@@ -379,7 +380,8 @@ static int wd_cipher_common_init(struct wd_ctx_config *config,
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_cipher_setting.config,
- wd_cipher_setting.driver);
+ wd_cipher_setting.driver,
+ &wd_cipher_setting.priv);
if (ret)
goto out_clear_pool;
@@ -396,10 +398,9 @@ out_clear_ctx_config:
static int wd_cipher_common_uninit(void)
{
- enum wd_status status;
+ void *priv = wd_cipher_setting.priv;
- wd_alg_get_init(&wd_cipher_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!priv)
return -WD_EINVAL;
/* uninit async request pool */
@@ -409,7 +410,8 @@ static int wd_cipher_common_uninit(void)
wd_clear_sched(&wd_cipher_setting.sched);
wd_alg_uninit_driver(&wd_cipher_setting.config,
- wd_cipher_setting.driver);
+ wd_cipher_setting.driver,
+ &wd_cipher_setting.priv);
return 0;
}
@@ -720,8 +722,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx,
msg_handle.recv = wd_cipher_setting.driver->recv;
wd_ctx_spin_lock(ctx, wd_cipher_setting.driver->calc_type);
- ret = wd_handle_msg_sync(wd_cipher_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, wd_cipher_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg, NULL,
+ wd_cipher_setting.config.epoll_en);
wd_ctx_spin_unlock(ctx, wd_cipher_setting.driver->calc_type);
return ret;
@@ -796,7 +798,7 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req)
fill_request_msg(msg, req, sess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_cipher_setting.driver, ctx->ctx, msg);
+ ret = wd_cipher_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("wd cipher async send err!\n");
@@ -846,7 +848,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_cipher_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_cipher_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN)
return ret;
else if (ret < 0) {
diff --git a/wd_comp.c b/wd_comp.c
index c67b7f1..be08ee8 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -51,6 +51,7 @@ struct wd_comp_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_comp_setting;
@@ -172,7 +173,8 @@ static int wd_comp_init_nolock(struct wd_ctx_config *config, struct wd_sched *sc
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_comp_setting.config,
- wd_comp_setting.driver);
+ wd_comp_setting.driver,
+ &wd_comp_setting.priv);
if (ret)
goto out_clear_pool;
@@ -189,10 +191,9 @@ out_clear_ctx_config:
static int wd_comp_uninit_nolock(void)
{
- enum wd_status status;
+ void *priv = wd_comp_setting.priv;
- wd_alg_get_init(&wd_comp_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!priv)
return -WD_EINVAL;
/* Uninit async request pool */
@@ -202,7 +203,8 @@ static int wd_comp_uninit_nolock(void)
wd_clear_sched(&wd_comp_setting.sched);
wd_alg_uninit_driver(&wd_comp_setting.config,
- wd_comp_setting.driver);
+ wd_comp_setting.driver,
+ &wd_comp_setting.priv);
return 0;
}
@@ -382,7 +384,7 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_comp_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_comp_setting.driver->recv(ctx->ctx, &resp_msg);
if (unlikely(ret < 0)) {
if (ret == -WD_HW_EACCESS)
WD_ERR("wd comp recv hw error!\n");
@@ -685,8 +687,8 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
msg_handle.recv = wd_comp_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_comp_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, config->epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
+ NULL, config->epoll_en);
pthread_spin_unlock(&ctx->lock);
return ret;
@@ -944,7 +946,7 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
msg->tag = tag;
msg->stream_mode = WD_COMP_STATELESS;
- ret = wd_alg_driver_send(wd_comp_setting.driver, ctx->ctx, msg);
+ ret = wd_comp_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("wd comp send error, ret = %d!\n", ret);
diff --git a/wd_dh.c b/wd_dh.c
index 0c1372c..42a1805 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -36,6 +36,7 @@ static struct wd_dh_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_dh_setting;
@@ -144,7 +145,8 @@ static int wd_dh_common_init(struct wd_ctx_config *config, struct wd_sched *sche
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_dh_setting.config,
- wd_dh_setting.driver);
+ wd_dh_setting.driver,
+ &wd_dh_setting.priv);
if (ret)
goto out_clear_pool;
@@ -161,11 +163,10 @@ out_clear_ctx_config:
static int wd_dh_common_uninit(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_dh_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!wd_dh_setting.priv) {
+ WD_ERR("invalid: repeat uninit dh!\n");
return -WD_EINVAL;
+ }
/* uninit async request pool */
wd_uninit_async_request_pool(&wd_dh_setting.pool);
@@ -173,7 +174,8 @@ static int wd_dh_common_uninit(void)
/* unset config, sched, driver */
wd_clear_sched(&wd_dh_setting.sched);
wd_alg_uninit_driver(&wd_dh_setting.config,
- wd_dh_setting.driver);
+ wd_dh_setting.driver,
+ &wd_dh_setting.priv);
return WD_SUCCESS;
}
@@ -390,8 +392,8 @@ int wd_do_dh_sync(handle_t sess, struct wd_dh_req *req)
msg_handle.recv = wd_dh_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_dh_setting.driver, &msg_handle, ctx->ctx,
- &msg, &balance, wd_dh_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
+ wd_dh_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
return ret;
@@ -437,7 +439,7 @@ int wd_do_dh_async(handle_t sess, struct wd_dh_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = wd_alg_driver_send(wd_dh_setting.driver, ctx->ctx, msg);
+ ret = wd_dh_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send dh BD, hw is err!\n");
@@ -488,7 +490,7 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_dh_setting.driver, ctx->ctx, &rcv_msg);
+ ret = wd_dh_setting.driver->recv(ctx->ctx, &rcv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (unlikely(ret)) {
diff --git a/wd_digest.c b/wd_digest.c
index 0b37f8b..763eae5 100644
--- a/wd_digest.c
+++ b/wd_digest.c
@@ -42,6 +42,7 @@ struct wd_digest_setting {
struct wd_sched sched;
struct wd_alg_driver *driver;
struct wd_async_msg_pool pool;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_digest_setting;
@@ -312,7 +313,8 @@ static int wd_digest_init_nolock(struct wd_ctx_config *config,
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_digest_setting.config,
- wd_digest_setting.driver);
+ wd_digest_setting.driver,
+ &wd_digest_setting.priv);
if (ret)
goto out_clear_pool;
@@ -361,29 +363,21 @@ out_clear_init:
return ret;
}
-static int wd_digest_uninit_nolock(void)
+static void wd_digest_uninit_nolock(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_digest_setting.status, &status);
- if (status == WD_UNINIT)
- return -WD_EINVAL;
-
wd_uninit_async_request_pool(&wd_digest_setting.pool);
wd_clear_sched(&wd_digest_setting.sched);
wd_alg_uninit_driver(&wd_digest_setting.config,
- wd_digest_setting.driver);
- return 0;
+ wd_digest_setting.driver,
+ &wd_digest_setting.priv);
}
void wd_digest_uninit(void)
{
- int ret;
-
- ret = wd_digest_uninit_nolock();
- if (ret)
+ if (!wd_digest_setting.priv)
return;
+ wd_digest_uninit_nolock();
wd_digest_close_driver(WD_TYPE_V1);
wd_alg_clear_init(&wd_digest_setting.status);
}
@@ -485,12 +479,10 @@ out_uninit:
void wd_digest_uninit2(void)
{
- int ret;
-
- ret = wd_digest_uninit_nolock();
- if (ret)
+ if (!wd_digest_setting.priv)
return;
+ wd_digest_uninit_nolock();
wd_alg_attrs_uninit(&wd_digest_init_attrs);
wd_alg_drv_unbind(wd_digest_setting.driver);
wd_digest_close_driver(WD_TYPE_V2);
@@ -655,8 +647,8 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds
msg_handle.recv = wd_digest_setting.driver->recv;
wd_ctx_spin_lock(ctx, wd_digest_setting.driver->calc_type);
- ret = wd_handle_msg_sync(wd_digest_setting.driver, &msg_handle, ctx->ctx,
- msg, NULL, wd_digest_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, msg,
+ NULL, wd_digest_setting.config.epoll_en);
wd_ctx_spin_unlock(ctx, wd_digest_setting.driver->calc_type);
if (unlikely(ret))
return ret;
@@ -750,7 +742,7 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req)
fill_request_msg(msg, req, dsess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(wd_digest_setting.driver, ctx->ctx, msg);
+ ret = wd_digest_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret < 0)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send BD, hw is err!\n");
@@ -800,7 +792,8 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_digest_setting.driver, ctx->ctx, &recv_msg);
+ ret = wd_digest_setting.driver->recv(ctx->ctx,
+ &recv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_ecc.c b/wd_ecc.c
index 2c88d0a..900f36c 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -69,6 +69,7 @@ static struct wd_ecc_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_ecc_setting;
@@ -210,7 +211,8 @@ static int wd_ecc_common_init(struct wd_ctx_config *config, struct wd_sched *sch
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_ecc_setting.config,
- wd_ecc_setting.driver);
+ wd_ecc_setting.driver,
+ &wd_ecc_setting.priv);
if (ret)
goto out_clear_pool;
@@ -227,11 +229,10 @@ out_clear_ctx_config:
static int wd_ecc_common_uninit(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_ecc_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!wd_ecc_setting.priv) {
+ WD_ERR("invalid: repeat uninit ecc!\n");
return -WD_EINVAL;
+ }
/* uninit async request pool */
wd_uninit_async_request_pool(&wd_ecc_setting.pool);
@@ -239,7 +240,8 @@ static int wd_ecc_common_uninit(void)
/* unset config, sched, driver */
wd_clear_sched(&wd_ecc_setting.sched);
wd_alg_uninit_driver(&wd_ecc_setting.config,
- wd_ecc_setting.driver);
+ wd_ecc_setting.driver,
+ &wd_ecc_setting.priv);
return WD_SUCCESS;
}
@@ -1203,8 +1205,8 @@ static void wd_ecc_sess_eops_cfg(struct wd_ecc_sess_setup *setup,
{
if (sess->eops.sess_init && sess->eops.eops_params_cfg) {
/* the config result does not impact task sucesss or failure */
- sess->eops.eops_params_cfg(wd_ecc_setting.driver, setup, sess->key.cv,
- sess->eops.params);
+ sess->eops.eops_params_cfg(setup, sess->key.cv,
+ wd_ecc_setting.priv, sess->eops.params);
}
}
@@ -1652,8 +1654,8 @@ int wd_do_ecc_sync(handle_t h_sess, struct wd_ecc_req *req)
msg_handle.recv = wd_ecc_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_ecc_setting.driver, &msg_handle, ctx->ctx, &msg,
- &balance, wd_ecc_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
+ wd_ecc_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
return ret;
@@ -2339,7 +2341,7 @@ int wd_do_ecc_async(handle_t sess, struct wd_ecc_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = wd_alg_driver_send(wd_ecc_setting.driver, ctx->ctx, msg);
+ ret = wd_ecc_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send ecc BD, hw is err!\n");
@@ -2389,7 +2391,7 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_ecc_setting.driver, ctx->ctx, &recv_msg);
+ ret = wd_ecc_setting.driver->recv(ctx->ctx, &recv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_join_gather.c b/wd_join_gather.c
index 915c1b8..86190c4 100644
--- a/wd_join_gather.c
+++ b/wd_join_gather.c
@@ -410,13 +410,12 @@ static void wd_join_gather_uninit_sess(struct wd_join_gather_sess *sess)
free(sess->gather_conf.batch_row_size);
if (sess->ops.sess_uninit)
- sess->ops.sess_uninit(wd_join_gather_setting.driver, sess->priv);
+ sess->ops.sess_uninit(sess->priv);
}
static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
struct wd_join_gather_sess_setup *setup)
{
- struct wd_alg_driver *drv = wd_join_gather_setting.driver;
__u32 array_size;
int ret;
@@ -425,7 +424,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
WD_ERR("failed to get session uninit ops!\n");
return -WD_EINVAL;
}
- ret = sess->ops.sess_init(drv, setup, &sess->priv);
+ ret = sess->ops.sess_init(setup, &sess->priv);
if (ret) {
WD_ERR("failed to init session priv!\n");
return ret;
@@ -433,7 +432,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
}
if (sess->ops.get_table_row_size && setup->alg != WD_GATHER) {
- ret = sess->ops.get_table_row_size(drv, sess->priv);
+ ret = sess->ops.get_table_row_size(sess->priv);
if (ret <= 0) {
WD_ERR("failed to get hash table row size: %d!\n", ret);
goto uninit;
@@ -447,7 +446,7 @@ static int wd_join_gather_init_sess(struct wd_join_gather_sess *sess,
if (!sess->gather_conf.batch_row_size)
goto uninit;
- ret = sess->ops.get_batch_row_size(drv, sess->priv,
+ ret = sess->ops.get_batch_row_size(sess->priv,
sess->gather_conf.batch_row_size,
array_size);
if (ret) {
@@ -462,7 +461,7 @@ free_batch:
free(sess->gather_conf.batch_row_size);
uninit:
if (sess->ops.sess_uninit)
- sess->ops.sess_uninit(drv, sess->priv);
+ sess->ops.sess_uninit(sess->priv);
return -WD_EINVAL;
}
@@ -656,8 +655,7 @@ int wd_join_set_hash_table(handle_t h_sess, struct wd_dae_hash_table *info)
WD_INFO("info: extern hash table is NULL!\n");
if (sess->ops.hash_table_init) {
- ret = sess->ops.hash_table_init(wd_join_gather_setting.driver,
- info, sess->priv);
+ ret = sess->ops.hash_table_init(info, sess->priv);
if (ret)
goto out;
}
@@ -699,7 +697,9 @@ static int wd_join_gather_alg_init(struct wd_ctx_config *config, struct wd_sched
if (ret < 0)
goto out_clear_sched;
- ret = wd_alg_init_driver(&wd_join_gather_setting.config, wd_join_gather_setting.driver);
+ ret = wd_alg_init_driver(&wd_join_gather_setting.config,
+ wd_join_gather_setting.driver,
+ &wd_join_gather_setting.priv);
if (ret)
goto out_clear_pool;
@@ -728,7 +728,9 @@ static int wd_join_gather_alg_uninit(void)
/* Unset config, sched, driver */
wd_clear_sched(&wd_join_gather_setting.sched);
- wd_alg_uninit_driver(&wd_join_gather_setting.config, wd_join_gather_setting.driver);
+ wd_alg_uninit_driver(&wd_join_gather_setting.config,
+ wd_join_gather_setting.driver,
+ &wd_join_gather_setting.priv);
return WD_SUCCESS;
}
@@ -1215,7 +1217,7 @@ static int wd_join_gather_sync_job(struct wd_join_gather_sess *sess,
msg_handle.recv = setting->driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(setting->driver, &msg_handle, ctx->ctx,
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx,
msg, NULL, config->epoll_en);
pthread_spin_unlock(&ctx->lock);
@@ -1311,7 +1313,7 @@ static int wd_join_gather_async_job(struct wd_join_gather_sess *sess,
fill_join_gather_msg(msg, req, sess);
msg->tag = msg_id;
- ret = wd_alg_driver_send(setting->driver, ctx->ctx, msg);
+ ret = wd_join_gather_setting.driver->send(ctx->ctx, msg);
if (ret < 0) {
if (ret != -WD_EBUSY)
WD_ERR("wd join gather async send err!\n");
@@ -1781,7 +1783,7 @@ static int wd_join_gather_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_join_gather_setting.driver, ctx->ctx, &resp_msg);
+ ret = wd_join_gather_setting.driver->recv(ctx->ctx, &resp_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_rsa.c b/wd_rsa.c
index bc78c6a..3e4d70d 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -77,6 +77,7 @@ static struct wd_rsa_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_rsa_setting;
@@ -184,7 +185,8 @@ static int wd_rsa_common_init(struct wd_ctx_config *config, struct wd_sched *sch
goto out_clear_sched;
ret = wd_alg_init_driver(&wd_rsa_setting.config,
- wd_rsa_setting.driver);
+ wd_rsa_setting.driver,
+ &wd_rsa_setting.priv);
if (ret)
goto out_clear_pool;
@@ -201,11 +203,10 @@ out_clear_ctx_config:
static int wd_rsa_common_uninit(void)
{
- enum wd_status status;
-
- wd_alg_get_init(&wd_rsa_setting.status, &status);
- if (status == WD_UNINIT)
+ if (!wd_rsa_setting.priv) {
+ WD_ERR("invalid: repeat uninit rsa!\n");
return -WD_EINVAL;
+ }
/* uninit async request pool */
wd_uninit_async_request_pool(&wd_rsa_setting.pool);
@@ -213,7 +214,8 @@ static int wd_rsa_common_uninit(void)
/* unset config, sched, driver */
wd_clear_sched(&wd_rsa_setting.sched);
wd_alg_uninit_driver(&wd_rsa_setting.config,
- wd_rsa_setting.driver);
+ wd_rsa_setting.driver,
+ &wd_rsa_setting.priv);
return WD_SUCCESS;
}
@@ -451,8 +453,8 @@ int wd_do_rsa_sync(handle_t h_sess, struct wd_rsa_req *req)
msg_handle.recv = wd_rsa_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_rsa_setting.driver, &msg_handle, ctx->ctx, &msg,
- &balance, wd_rsa_setting.config.epoll_en);
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx, &msg, &balance,
+ wd_rsa_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
return ret;
@@ -498,7 +500,7 @@ int wd_do_rsa_async(handle_t sess, struct wd_rsa_req *req)
goto fail_with_msg;
msg->tag = mid;
- ret = wd_alg_driver_send(wd_rsa_setting.driver, ctx->ctx, msg);
+ ret = wd_rsa_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send rsa BD, hw is err!\n");
@@ -548,7 +550,7 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_rsa_setting.driver, ctx->ctx, &recv_msg);
+ ret = wd_rsa_setting.driver->recv(ctx->ctx, &recv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (ret < 0) {
diff --git a/wd_udma.c b/wd_udma.c
index eebe495..341b533 100644
--- a/wd_udma.c
+++ b/wd_udma.c
@@ -22,6 +22,7 @@ static struct wd_udma_setting {
struct wd_sched sched;
struct wd_async_msg_pool pool;
struct wd_alg_driver *driver;
+ void *priv;
void *dlhandle;
void *dlh_list;
} wd_udma_setting;
@@ -229,7 +230,7 @@ int wd_do_udma_sync(handle_t h_sess, struct wd_udma_req *req)
msg_handle.send = wd_udma_setting.driver->send;
msg_handle.recv = wd_udma_setting.driver->recv;
pthread_spin_lock(&ctx->lock);
- ret = wd_handle_msg_sync(wd_udma_setting.driver, &msg_handle, ctx->ctx,
+ ret = wd_handle_msg_sync(&msg_handle, ctx->ctx,
&msg, NULL, wd_udma_setting.config.epoll_en);
pthread_spin_unlock(&ctx->lock);
if (unlikely(ret))
@@ -276,7 +277,7 @@ int wd_do_udma_async(handle_t sess, struct wd_udma_req *req)
fill_udma_msg(msg, req);
msg->tag = mid;
- ret = wd_alg_driver_send(wd_udma_setting.driver, ctx->ctx, msg);
+ ret = wd_udma_setting.driver->send(ctx->ctx, msg);
if (unlikely(ret)) {
if (ret != -WD_EBUSY)
WD_ERR("failed to send udma BD, hw is err!\n");
@@ -314,7 +315,7 @@ static int wd_udma_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
ctx = config->ctxs + idx;
do {
- ret = wd_alg_driver_recv(wd_udma_setting.driver, ctx->ctx, &rcv_msg);
+ ret = wd_udma_setting.driver->recv(ctx->ctx, &rcv_msg);
if (ret == -WD_EAGAIN) {
return ret;
} else if (unlikely(ret)) {
@@ -364,7 +365,9 @@ static void wd_udma_alg_uninit(void)
wd_uninit_async_request_pool(&wd_udma_setting.pool);
/* Unset config, sched, driver */
wd_clear_sched(&wd_udma_setting.sched);
- wd_alg_uninit_driver(&wd_udma_setting.config, wd_udma_setting.driver);
+ wd_alg_uninit_driver(&wd_udma_setting.config,
+ wd_udma_setting.driver,
+ &wd_udma_setting.priv);
}
void wd_udma_uninit(void)
@@ -405,7 +408,9 @@ static int wd_udma_alg_init(struct wd_ctx_config *config, struct wd_sched *sched
if (ret < 0)
goto out_clear_sched;
- ret = wd_alg_init_driver(&wd_udma_setting.config, wd_udma_setting.driver);
+ ret = wd_alg_init_driver(&wd_udma_setting.config,
+ wd_udma_setting.driver,
+ &wd_udma_setting.priv);
if (ret)
goto out_clear_pool;
diff --git a/wd_util.c b/wd_util.c
index bf82fc1..0dc9a67 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1878,8 +1878,8 @@ int wd_set_epoll_en(const char *var_name, bool *epoll_en)
return 0;
}
-int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_handle,
- handle_t ctx, void *msg, __u64 *balance, bool epoll_en)
+int wd_handle_msg_sync(struct wd_msg_handle *msg_handle, handle_t ctx,
+ void *msg, __u64 *balance, bool epoll_en)
{
__u64 timeout = WD_RECV_MAX_CNT_NOSLEEP;
__u64 rx_cnt = 0;
@@ -1888,7 +1888,7 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand
if (balance)
timeout = WD_RECV_MAX_CNT_SLEEP;
- ret = msg_handle->send(drv, ctx, msg);
+ ret = msg_handle->send(ctx, msg);
if (unlikely(ret < 0)) {
WD_ERR("failed to send msg to hw, ret = %d!\n", ret);
return ret;
@@ -1901,7 +1901,7 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand
WD_ERR("wd ctx wait timeout(%d)!\n", ret);
}
- ret = msg_handle->recv(drv, ctx, msg);
+ ret = msg_handle->recv(ctx, msg);
if (ret != -WD_EAGAIN) {
if (unlikely(ret < 0)) {
WD_ERR("failed to recv msg: error = %d!\n", ret);
@@ -1964,10 +1964,21 @@ static void wd_alg_uninit_fallback(struct wd_alg_driver *fb_driver)
}
int wd_alg_init_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver)
+ struct wd_alg_driver *driver, void **drv_priv)
{
+ void *priv;
int ret;
+ if (!driver->priv_size) {
+ WD_ERR("invalid: driver priv ctx size is zero!\n");
+ return -WD_EINVAL;
+ }
+
+ /* Init ctx related resources in specific driver */
+ priv = calloc(1, driver->priv_size);
+ if (!priv)
+ return -WD_ENOMEM;
+
if (!driver->init) {
driver->fallback = 0;
WD_ERR("driver have no init interface.\n");
@@ -1975,11 +1986,12 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config,
goto err_alloc;
}
- ret = driver->init(driver, config);
+ ret = driver->init(config, priv);
if (ret < 0) {
WD_ERR("driver init failed.\n");
goto err_alloc;
}
+ driver->drv_data = priv;
if (driver->fallback) {
ret = wd_alg_init_fallback((struct wd_alg_driver *)driver->fallback);
@@ -1988,22 +2000,32 @@ int wd_alg_init_driver(struct wd_ctx_config_internal *config,
WD_ERR("soft alg driver init failed.\n");
}
}
+ *drv_priv = priv;
return 0;
err_alloc:
+ free(priv);
return ret;
}
void wd_alg_uninit_driver(struct wd_ctx_config_internal *config,
- struct wd_alg_driver *driver)
+ struct wd_alg_driver *driver, void **drv_priv)
{
- driver->exit(driver);
+ void *priv = *drv_priv;
+
+ driver->exit(priv);
/* Ctx config just need clear once */
wd_clear_ctx_config(config);
if (driver->fallback)
wd_alg_uninit_fallback((struct wd_alg_driver *)driver->fallback);
+
+ if (priv) {
+ free(priv);
+ driver->drv_data = NULL;
+ *drv_priv = NULL;
+ }
}
void wd_dlclose_drv(void *dlh_list)
--
2.43.0
1
18
[PATCH OLK-5.10 0/2] crypto: hisilicon/qm - support querying the hardware fault status
by ZongYu Wu 31 Mar '26
by ZongYu Wu 31 Mar '26
31 Mar '26
From: JiangShui Yang <yangjiangshui(a)h-partners.com>
Zhushuai Yin (1):
crypto: hisilicon/qm - support querying the hardware fault status
through VFs
nieweiqiang (1):
crypto: hisilicon/qm - add concurrency protection for variable
err_threshold
drivers/crypto/hisilicon/qm.c | 129 ++++++++++++++++++++---
drivers/crypto/hisilicon/sec2/sec_main.c | 10 +-
drivers/crypto/hisilicon/zip/zip_main.c | 10 +-
3 files changed, 124 insertions(+), 25 deletions(-)
--
2.33.0
1
2
[PATCH OLK-6.6] crypto: hisilicon/qm - support querying the hardware fault status through VFs
by ZongYu Wu 26 Mar '26
by ZongYu Wu 26 Mar '26
26 Mar '26
From: Zhushuai Yin <yinzhushuai(a)huawei.com>
driver inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/8816
CVE: NA
----------------------------------------------------------------------
The problem that the VF device cannot obtain the isolation
status and isolation threshold of the device is resolved.
Signed-off-by: Zhushuai Yin <yinzhushuai(a)huawei.com>
Signed-off-by: JiangShui Yang <yangjiangshui(a)h-partners.com>
---
drivers/crypto/hisilicon/hpre/hpre_main.c | 10 +-
drivers/crypto/hisilicon/qm.c | 119 +++++++++++++++++++---
2 files changed, 111 insertions(+), 18 deletions(-)
diff --git a/drivers/crypto/hisilicon/hpre/hpre_main.c b/drivers/crypto/hisilicon/hpre/hpre_main.c
index 074b3424becf..bcc5bc02bb30 100644
--- a/drivers/crypto/hisilicon/hpre/hpre_main.c
+++ b/drivers/crypto/hisilicon/hpre/hpre_main.c
@@ -1613,12 +1613,10 @@ static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id)
goto err_qm_del_list;
}
- if (qm->uacce) {
- ret = uacce_register(qm->uacce);
- if (ret) {
- pci_err(pdev, "failed to register uacce (%d)!\n", ret);
- goto err_with_alg_register;
- }
+ ret = qm_register_uacce(qm);
+ if (ret) {
+ pci_err(pdev, "failed to register uacce (%d)!\n", ret);
+ goto err_with_alg_register;
}
if (qm->fun_type == QM_HW_PF && vfs_num) {
diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index ae7132a84e4a..7e7d4d3a79f0 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -252,6 +252,10 @@
#define QM_QOS_MAX_CIR_U 6
#define QM_AUTOSUSPEND_DELAY 3000
+/* qm isolation state mask */
+#define QM_ISOLATED_STATE BIT(31)
+#define QM_ISOLATED_THRESHOLD_MASK GENMASK(15, 0)
+
/* abnormal status value for stopping queue */
#define QM_STOP_QUEUE_FAIL 1
#define QM_DUMP_SQC_FAIL 3
@@ -292,6 +296,21 @@ enum qm_alg_type {
ALG_TYPE_1,
};
+/**
+ * @brief Message format for QM_VF_GET_ISOLATE and QM_PF_SET_ISOLATE commands
+ *
+ * These commands use a 32-bit command field (cmd) and 32-bit data field (data)
+ *
+ * @details
+ * Command behavior:
+ * - QM_VF_GET_ISOLATE: VF requests isolation status and threshold
+ * - QM_PF_SET_ISOLATE: PF sets isolation status and threshold
+ *
+ * Data field bit layout:
+ * - bit31 (MSB): Isolation status flag (1 = isolated, 0 = non-isolated)
+ * - bit15-0 (16 LSB): Isolation threshold value
+ * - bit30-16 (15 bits): Reserved
+ */
enum qm_ifc_cmd {
QM_PF_FLR_PREPARE = 0x01,
QM_PF_SRST_PREPARE,
@@ -302,6 +321,8 @@ enum qm_ifc_cmd {
QM_VF_START_FAIL,
QM_PF_SET_QOS,
QM_VF_GET_QOS,
+ QM_VF_GET_ISOLATE,
+ QM_PF_SET_ISOLATE
};
enum qm_basic_type {
@@ -1780,7 +1801,7 @@ static int qm_ping_single_vf(struct hisi_qm *qm, enum qm_ifc_cmd cmd, u32 data,
return ret;
}
-static int qm_ping_all_vfs(struct hisi_qm *qm, enum qm_ifc_cmd cmd)
+static int qm_ping_all_vfs(struct hisi_qm *qm, enum qm_ifc_cmd cmd, u32 data)
{
struct device *dev = &qm->pdev->dev;
u32 vfs_num = qm->vfs_num;
@@ -1789,7 +1810,7 @@ static int qm_ping_all_vfs(struct hisi_qm *qm, enum qm_ifc_cmd cmd)
int ret;
u32 i;
- ret = qm->ops->set_ifc_begin(qm, cmd, 0, QM_MB_PING_ALL_VFS);
+ ret = qm->ops->set_ifc_begin(qm, cmd, data, QM_MB_PING_ALL_VFS);
if (ret && cmd != QM_PF_FLR_PREPARE && cmd != QM_PF_SRST_PREPARE) {
dev_err(dev, "failed to send command(0x%x) to all vfs!\n", cmd);
qm->ops->set_ifc_end(qm);
@@ -2808,7 +2829,10 @@ static void qm_uacce_base_init(struct hisi_qm *qm)
else
mmio_page_nr = QM_QP_DB_INTERVAL / PAGE_SIZE;
- uacce->is_vf = pdev->is_virtfn;
+ if (qm->fun_type == QM_HW_PF)
+ uacce->is_vf = false;
+ else
+ uacce->is_vf = true;
uacce->priv = qm;
uacce->parent = &pdev->dev;
qm_get_xqc_depth(qm, &sq_depth, &cq_depth, QM_QP_DEPTH_CAP);
@@ -2898,6 +2922,7 @@ static enum uacce_dev_state hisi_qm_get_isolate_state(struct uacce_device *uacce
static int hisi_qm_isolate_threshold_write(struct uacce_device *uacce, u32 num)
{
struct hisi_qm *qm = uacce->priv;
+ int ret;
/* Must be set by PF */
if (uacce->is_vf)
@@ -2911,6 +2936,18 @@ static int hisi_qm_isolate_threshold_write(struct uacce_device *uacce, u32 num)
/* After the policy is updated, need to reset the hardware err list */
qm_hw_err_destroy(qm);
+
+ if (!qm->vfs_num) {
+ mutex_unlock(&qm->isolate_data.isolate_lock);
+ return 0;
+ }
+
+ /* Notifying all VFs to update after the PF sets a threshold. */
+ if (test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps)) {
+ ret = qm_ping_all_vfs(qm, QM_PF_SET_ISOLATE, qm->isolate_data.err_threshold);
+ if (ret)
+ dev_err(&qm->pdev->dev, "failed to send command to all VFs set isolate!\n");
+ }
mutex_unlock(&qm->isolate_data.isolate_lock);
return 0;
@@ -2921,7 +2958,7 @@ static u32 hisi_qm_isolate_threshold_read(struct uacce_device *uacce)
struct hisi_qm *qm = uacce->priv;
struct hisi_qm *pf_qm;
- if (uacce->is_vf) {
+ if (uacce->is_vf && !test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps)) {
pf_qm = pci_get_drvdata(pci_physfn(qm->pdev));
return pf_qm->isolate_data.err_threshold;
}
@@ -3004,10 +3041,19 @@ static int qm_alloc_uacce(struct hisi_qm *qm)
int qm_register_uacce(struct hisi_qm *qm)
{
+ int ret;
+
if (!qm->uacce)
return 0;
dev_info(&qm->pdev->dev, "qm register to uacce\n");
+
+ if (qm->fun_type == QM_HW_VF && test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps)) {
+ ret = qm_ping_pf(qm, QM_VF_GET_ISOLATE);
+ if (ret)
+ dev_err(&qm->pdev->dev, "failed to send cmd to PF to get isolate!\n");
+ }
+
return uacce_register(qm->uacce);
}
EXPORT_SYMBOL_GPL(qm_register_uacce);
@@ -4581,7 +4627,7 @@ static int qm_try_stop_vfs(struct hisi_qm *qm, enum qm_ifc_cmd cmd,
/* Kunpeng930 supports to notify VFs to stop before PF reset */
if (test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps)) {
- ret = qm_ping_all_vfs(qm, cmd);
+ ret = qm_ping_all_vfs(qm, cmd, 0);
if (ret)
pci_err(pdev, "failed to send command to all VFs before PF reset!\n");
} else {
@@ -4766,6 +4812,7 @@ static int qm_vf_reset_done(struct hisi_qm *qm)
static int qm_try_start_vfs(struct hisi_qm *qm, enum qm_ifc_cmd cmd)
{
struct pci_dev *pdev = qm->pdev;
+ u32 data;
int ret;
if (!qm->vfs_num)
@@ -4779,7 +4826,11 @@ static int qm_try_start_vfs(struct hisi_qm *qm, enum qm_ifc_cmd cmd)
/* Kunpeng930 supports to notify VFs to start after PF reset. */
if (test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps)) {
- ret = qm_ping_all_vfs(qm, cmd);
+ data = qm->isolate_data.err_threshold;
+ if (qm->isolate_data.is_isolate)
+ data |= QM_ISOLATED_STATE;
+ /* Broadcasting isolate info via RAS to all VFs. */
+ ret = qm_ping_all_vfs(qm, cmd, data);
if (ret)
pci_warn(pdev, "failed to send cmd to all VFs after PF reset!\n");
} else {
@@ -5247,10 +5298,22 @@ static void qm_pf_reset_vf_done(struct hisi_qm *qm)
qm_reset_bit_clear(qm);
}
-static int qm_wait_pf_reset_finish(struct hisi_qm *qm)
+static void qm_vf_update_isolate_info(struct hisi_qm *qm, u32 data)
+{
+ /* Updating the local isolation status. */
+ mutex_lock(&qm->isolate_data.isolate_lock);
+ if (data & QM_ISOLATED_STATE)
+ qm->isolate_data.is_isolate = true;
+ else
+ qm->isolate_data.is_isolate = false;
+ qm->isolate_data.err_threshold = data & QM_ISOLATED_THRESHOLD_MASK;
+ mutex_unlock(&qm->isolate_data.isolate_lock);
+}
+
+static int qm_wait_pf_reset_finish(struct hisi_qm *qm, enum qm_stop_reason stop_reason)
{
struct device *dev = &qm->pdev->dev;
- u32 val, cmd;
+ u32 val, cmd, data;
int ret;
/* Wait for reset to finish */
@@ -5267,7 +5330,7 @@ static int qm_wait_pf_reset_finish(struct hisi_qm *qm)
* Whether message is got successfully,
* VF needs to ack PF by clearing the interrupt.
*/
- ret = qm->ops->get_ifc(qm, &cmd, NULL, 0);
+ ret = qm->ops->get_ifc(qm, &cmd, &data, 0);
qm_clear_cmd_interrupt(qm, 0);
if (ret) {
dev_err(dev, "failed to get command from PF in reset done!\n");
@@ -5276,10 +5339,14 @@ static int qm_wait_pf_reset_finish(struct hisi_qm *qm)
if (cmd != QM_PF_RESET_DONE) {
dev_err(dev, "the command(0x%x) is not reset done!\n", cmd);
- ret = -EINVAL;
+ return -EINVAL;
}
- return ret;
+ /* The VF processes the device isolation information received from the RAS reset. */
+ if (stop_reason == QM_SOFT_RESET)
+ qm_vf_update_isolate_info(qm, data);
+
+ return 0;
}
static void qm_pf_reset_vf_process(struct hisi_qm *qm,
@@ -5294,7 +5361,7 @@ static void qm_pf_reset_vf_process(struct hisi_qm *qm,
qm_cmd_uninit(qm);
qm_pf_reset_vf_prepare(qm, stop_reason);
- ret = qm_wait_pf_reset_finish(qm);
+ ret = qm_wait_pf_reset_finish(qm, stop_reason);
if (ret)
goto err_get_status;
@@ -5306,11 +5373,32 @@ static void qm_pf_reset_vf_process(struct hisi_qm *qm,
return;
err_get_status:
+ if (stop_reason == QM_SOFT_RESET) {
+ /* Update local isolation status on PF-VF reset failure. */
+ mutex_lock(&qm->isolate_data.isolate_lock);
+ qm->isolate_data.is_isolate = true;
+ mutex_unlock(&qm->isolate_data.isolate_lock);
+ }
clear_bit(QM_DEVICE_DOWN, &qm->misc_ctl);
qm_cmd_init(qm);
qm_reset_bit_clear(qm);
}
+static void qm_vf_get_isolate_data(struct hisi_qm *qm, u32 fun_num)
+{
+ u32 data = qm->isolate_data.err_threshold;
+ struct device *dev = &qm->pdev->dev;
+ int ret;
+
+ if (qm->isolate_data.is_isolate)
+ data |= QM_ISOLATED_STATE;
+
+ ret = qm_ping_single_vf(qm, QM_PF_SET_ISOLATE, data, fun_num);
+ if (ret)
+ dev_err(dev, "failed to send command(0x%x) to VF(%u)!\n",
+ (unsigned int)QM_PF_SET_ISOLATE, fun_num);
+}
+
static void qm_handle_cmd_msg(struct hisi_qm *qm, u32 fun_num)
{
struct device *dev = &qm->pdev->dev;
@@ -5348,6 +5436,13 @@ static void qm_handle_cmd_msg(struct hisi_qm *qm, u32 fun_num)
case QM_PF_SET_QOS:
qm->mb_qos = data;
break;
+ case QM_VF_GET_ISOLATE:
+ /* Read the isolation policy of the PF during VF initialization. */
+ qm_vf_get_isolate_data(qm, fun_num);
+ break;
+ case QM_PF_SET_ISOLATE:
+ qm_vf_update_isolate_info(qm, data);
+ break;
default:
dev_err(dev, "unsupported command(0x%x) sent by function(%u)!\n", cmd, fun_num);
break;
--
2.43.0
1
0
From: Weili Qian <qianweili(a)huawei.com>
The trng module is not required. Therefore, remove the trng module code.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
Makefile.am | 6 +-
configure.ac | 1 -
uadk_tool/Makefile.am | 1 -
uadk_tool/benchmark/trng_wd_benchmark.c | 333 ------------
uadk_tool/benchmark/trng_wd_benchmark.h | 7 -
uadk_tool/benchmark/uadk_benchmark.c | 15 -
uadk_tool/benchmark/uadk_benchmark.h | 1 -
v1/drv/hisi_rng_udrv.c | 167 ------
v1/drv/hisi_rng_udrv.h | 40 --
v1/libwd.map | 5 -
v1/test/Makefile.am | 1 -
v1/test/hisi_trng_test/Makefile.am | 20 -
v1/test/hisi_trng_test/test_hisi_trngk.c | 155 ------
v1/test/hisi_trng_test/test_hisi_trngp.c | 137 -----
v1/test/hisi_trng_test/test_hisi_trngu.c | 624 -----------------------
v1/wd.h | 2 +-
v1/wd_adapter.c | 7 -
v1/wd_rng.c | 296 -----------
v1/wd_rng.h | 76 ---
19 files changed, 3 insertions(+), 1891 deletions(-)
delete mode 100644 uadk_tool/benchmark/trng_wd_benchmark.c
delete mode 100644 uadk_tool/benchmark/trng_wd_benchmark.h
delete mode 100644 v1/drv/hisi_rng_udrv.c
delete mode 100644 v1/drv/hisi_rng_udrv.h
delete mode 100644 v1/test/hisi_trng_test/Makefile.am
delete mode 100755 v1/test/hisi_trng_test/test_hisi_trngk.c
delete mode 100644 v1/test/hisi_trng_test/test_hisi_trngp.c
delete mode 100755 v1/test/hisi_trng_test/test_hisi_trngu.c
delete mode 100644 v1/wd_rng.c
delete mode 100644 v1/wd_rng.h
diff --git a/Makefile.am b/Makefile.am
index d1a5953..7749613 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,9 +49,8 @@ uadk_driversdir=$(libdir)/uadk
uadk_drivers_LTLIBRARIES=libhisi_sec.la libhisi_hpre.la libhisi_zip.la \
libisa_ce.la libisa_sve.la libhisi_dae.la libhisi_udma.la
-libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \
+libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \
v1/wd.c v1/wd.h v1/wd_adapter.c v1/wd_adapter.h \
- v1/wd_rng.c v1/wd_rng.h \
v1/wd_rsa.c v1/wd_rsa.h \
v1/wd_aead.c v1/wd_aead.h \
v1/wd_dh.c v1/wd_dh.h \
@@ -68,8 +67,7 @@ libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \
v1/drv/hisi_zip_udrv.c v1/drv/hisi_zip_udrv.h \
v1/drv/hisi_zip_huf.c v1/drv/hisi_zip_huf.h \
v1/drv/hisi_hpre_udrv.c v1/drv/hisi_hpre_udrv.h \
- v1/drv/hisi_sec_udrv.c v1/drv/hisi_sec_udrv.h \
- v1/drv/hisi_rng_udrv.c v1/drv/hisi_rng_udrv.h
+ v1/drv/hisi_sec_udrv.c v1/drv/hisi_sec_udrv.h
libwd_udma_la_SOURCES=wd_udma.h wd_udma_drv.h wd_udma.c \
wd_util.c wd_util.h wd_sched.c wd_sched.h wd.c wd.h
diff --git a/configure.ac b/configure.ac
index 95c9f67..eb5a211 100644
--- a/configure.ac
+++ b/configure.ac
@@ -109,7 +109,6 @@ AC_CONFIG_FILES([Makefile
v1/test/bmm_test/Makefile
v1/test/test_mm/Makefile
v1/test/hisi_hpre_test/Makefile
- v1/test/hisi_trng_test/Makefile
v1/test/hisi_sec_test/Makefile
v1/test/hisi_sec_test_sgl/Makefile
v1/test/hisi_zip_test/Makefile
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
index 86b3064..9a1703d 100644
--- a/uadk_tool/Makefile.am
+++ b/uadk_tool/Makefile.am
@@ -17,7 +17,6 @@ uadk_tool_SOURCES=uadk_tool.c dfx/uadk_dfx.c dfx/uadk_dfx.h \
benchmark/hpre_wd_benchmark.c hpre_wd_benchmark.h \
benchmark/zip_uadk_benchmark.c benchmark/zip_uadk_benchmark.h \
benchmark/zip_wd_benchmark.c benchmark/zip_wd_benchmark.h \
- benchmark/trng_wd_benchmark.c benchmark/trng_wd_benchmark.h \
test/uadk_test.c test/uadk_test.h \
test/test_sec.c test/test_sec.h test/sec_template_tv.h
diff --git a/uadk_tool/benchmark/trng_wd_benchmark.c b/uadk_tool/benchmark/trng_wd_benchmark.c
deleted file mode 100644
index 2f058d4..0000000
--- a/uadk_tool/benchmark/trng_wd_benchmark.c
+++ /dev/null
@@ -1,333 +0,0 @@
-/* SPDX-License-Identifier: Apache-2.0 */
-
-#include <numa.h>
-#include "uadk_benchmark.h"
-
-#include "trng_wd_benchmark.h"
-#include "v1/wd.h"
-#include "v1/wd_rng.h"
-
-struct thread_bd_res {
- struct wd_queue *queue;
- void *out;
- __u32 in_bytes;
-};
-
-struct thread_queue_res {
- struct thread_bd_res *bd_res;
-};
-
-struct wd_thread_res {
- u32 td_id;
- u32 pollid;
-};
-
-struct trng_async_tag {
- void *ctx;
- int optype;
-};
-
-static unsigned int g_thread_num;
-static struct thread_queue_res g_thread_queue;
-
-static int init_trng_wd_queue(struct acc_option *options)
-{
- int i, ret;
-
- g_thread_queue.bd_res = malloc(g_thread_num * sizeof(struct thread_bd_res));
- if (!g_thread_queue.bd_res) {
- printf("failed to malloc thread res memory!\n");
- return -ENOMEM;
- }
-
- for (i = 0; i < g_thread_num; i++) {
- g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue));
- if (!g_thread_queue.bd_res[i].queue) {
- ret = -ENOMEM;
- goto free_mem;
- }
-
- g_thread_queue.bd_res[i].queue->capa.alg = options->algclass;
- /* nodemask need to be clean */
- g_thread_queue.bd_res[i].queue->node_mask = 0x0;
- memset(g_thread_queue.bd_res[i].queue->dev_path, 0x0, PATH_STR_SIZE);
- if (strlen(options->device) != 0) {
- ret = snprintf(g_thread_queue.bd_res[i].queue->dev_path,
- PATH_STR_SIZE, "%s", options->device);
- if (ret < 0) {
- WD_ERR("failed to copy dev file path!\n");
- return -WD_EINVAL;
- }
- }
-
- g_thread_queue.bd_res[i].in_bytes = options->pktlen;
- g_thread_queue.bd_res[i].out = malloc(options->pktlen);
- if (!g_thread_queue.bd_res[i].queue) {
- free(g_thread_queue.bd_res[i].queue);
- ret = -ENOMEM;
- goto free_mem;
- }
-
- ret = wd_request_queue(g_thread_queue.bd_res[i].queue);
- if (ret) {
- printf("failed to request queue %d, ret = %d!\n", i, ret);
- free(g_thread_queue.bd_res[i].out);
- free(g_thread_queue.bd_res[i].queue);
- goto free_mem;
- }
- }
-
- return 0;
-
-free_mem:
- for (i = i - 1; i >= 0; i--) {
- wd_release_queue(g_thread_queue.bd_res[i].queue);
- free(g_thread_queue.bd_res[i].out);
- free(g_thread_queue.bd_res[i].queue);
- }
-
- free(g_thread_queue.bd_res);
- return ret;
-}
-
-static void uninit_trng_wd_queue(void)
-{
- int j;
-
- for (j = 0; j < g_thread_num; j++) {
- wd_release_queue(g_thread_queue.bd_res[j].queue);
- free(g_thread_queue.bd_res[j].out);
- free(g_thread_queue.bd_res[j].queue);
- }
-
- free(g_thread_queue.bd_res);
-}
-
-static void *trng_wd_sync_run(void *arg)
-{
- struct wd_thread_res *pdata = (struct wd_thread_res *)arg;
- struct wcrypto_rng_ctx_setup trng_setup;
- struct wcrypto_rng_op_data opdata;
- struct wd_queue *queue;
- void *ctx = NULL;
- u32 count = 0;
- int ret;
-
- queue = g_thread_queue.bd_res[pdata->td_id].queue;
- ctx = wcrypto_create_rng_ctx(queue, &trng_setup);
- if (!ctx)
- return NULL;
-
- memset(&opdata, 0, sizeof(opdata));
- opdata.in_bytes = g_thread_queue.bd_res[pdata->td_id].in_bytes;
- opdata.out = g_thread_queue.bd_res[pdata->td_id].out;
- opdata.op_type = WCRYPTO_TRNG_GEN;
-
- do {
- ret = wcrypto_do_rng(ctx, &opdata, NULL);
- if (ret) {
- printf("failed to do rng task, ret: %d\n", ret);
- goto ctx_release;
- }
-
- count++;
- if (get_run_state() == 0)
- break;
- } while (true);
-
-ctx_release:
- wcrypto_del_rng_ctx(ctx);
- add_recv_data(count, opdata.in_bytes);
-
- return NULL;
-}
-
-static void trng_wd_sync_threads(void)
-{
- struct wd_thread_res threads_args[THREADS_NUM];
- pthread_t tdid[THREADS_NUM];
- int i, ret;
-
- for (i = 0; i < g_thread_num; i++) {
- threads_args[i].td_id = i;
- ret = pthread_create(&tdid[i], NULL, trng_wd_sync_run, &threads_args[i]);
- if (ret) {
- printf("failed to create sync thread!\n");
- return;
- }
- }
-
- /* join thread */
- for (i = 0; i < g_thread_num; i++) {
- ret = pthread_join(tdid[i], NULL);
- if (ret) {
- printf("failed to join sync thread!\n");
- return;
- }
- }
-}
-
-void *wd_trng_poll(void *data)
-{
- struct wd_thread_res *pdata = (struct wd_thread_res *)data;
- struct wd_queue *queue;
- u32 last_time = 2; // poll need one more recv time
- u32 count = 0;
- u32 in_bytes;
- int recv;
-
- in_bytes = g_thread_queue.bd_res[pdata->pollid].in_bytes;
- queue = g_thread_queue.bd_res[pdata->pollid].queue;
-
- while (last_time) {
- recv = wcrypto_rng_poll(queue, ACC_QUEUE_SIZE);
- if (recv < 0) {
- printf("failed to recv bd, ret: %d!\n", recv);
- goto recv_error;
- }
- count += recv;
-
- if (get_run_state() == 0)
- last_time--;
- }
-
-recv_error:
- add_recv_data(count, in_bytes);
-
- return NULL;
-}
-
-static void *trng_async_cb(const void *msg, void *tag)
-{
- return NULL;
-}
-
-static void *wd_trng_async_run(void *arg)
-{
- struct wd_thread_res *pdata = (struct wd_thread_res *)arg;
- struct wcrypto_rng_ctx_setup trng_setup;
- struct wcrypto_rng_op_data opdata;
- struct trng_async_tag *tag = NULL;
- struct wd_queue *queue;
- void *ctx = NULL;
- int ret, i;
-
- memset(&opdata, 0, sizeof(opdata));
-
- queue = g_thread_queue.bd_res[pdata->td_id].queue;
- trng_setup.cb = (void *)trng_async_cb;
-
- ctx = wcrypto_create_rng_ctx(queue, &trng_setup);
- if (!ctx)
- return NULL;
-
- opdata.in_bytes = g_thread_queue.bd_res[pdata->td_id].in_bytes;
- opdata.out = g_thread_queue.bd_res[pdata->td_id].out;
- opdata.op_type = WCRYPTO_TRNG_GEN;
-
- tag = malloc(sizeof(*tag) * MAX_POOL_LENTH);
- if (!tag) {
- printf("failed to malloc dh tag!\n");
- goto free_ctx;
- }
- tag->ctx = ctx;
-
- do {
- ret = wcrypto_do_rng(ctx, &opdata, tag);
- if (ret && ret != -WD_EBUSY) {
- printf("failed to send trng task, ret = %d!\n", ret);
- break;
- }
-
- if (get_run_state() == 0)
- break;
- } while (true);
-
- /* Release memory after all tasks are complete. */
- i = 0;
- while (get_recv_time() != g_thread_num) {
- if (i++ >= MAX_TRY_CNT) {
- printf("failed to wait poll thread finish!\n");
- break;
- }
-
- usleep(SEND_USLEEP);
- }
-
- if (tag)
- free(tag);
-free_ctx:
- wcrypto_del_rng_ctx(ctx);
- add_send_complete();
-
- return NULL;
-}
-
-static void trng_wd_async_threads(void)
-{
- struct wd_thread_res threads_args[THREADS_NUM];
- pthread_t tdid[THREADS_NUM];
- pthread_t pollid[THREADS_NUM];
- int i, ret;
-
- for (i = 0; i < g_thread_num; i++) {
- threads_args[i].pollid = i;
- /* poll thread */
- ret = pthread_create(&pollid[i], NULL, wd_trng_poll, &threads_args[i]);
- if (ret) {
- printf("failed to create poll thread!\n");
- return;
- }
- }
-
- for (i = 0; i < g_thread_num; i++) {
- threads_args[i].td_id = i;
- ret = pthread_create(&tdid[i], NULL, wd_trng_async_run, &threads_args[i]);
- if (ret) {
- printf("failed to create async thread!\n");
- return;
- }
- }
-
- /* join thread */
- for (i = 0; i < g_thread_num; i++) {
- ret = pthread_join(tdid[i], NULL);
- if (ret) {
- printf("failed to join async thread!\n");
- return;
- }
- }
-
- for (i = 0; i < g_thread_num; i++) {
- ret = pthread_join(pollid[i], NULL);
- if (ret) {
- printf("failed to join poll thread!\n");
- return;
- }
- }
-}
-
-int trng_wd_benchmark(struct acc_option *options)
-{
- u32 ptime;
- int ret;
-
- signal(SIGSEGV, segmentfault_handler);
- g_thread_num = options->threads;
-
- ret = init_trng_wd_queue(options);
- if (ret)
- return ret;
-
- get_pid_cpu_time(&ptime);
- time_start(options->times);
- if (options->syncmode)
- trng_wd_async_threads();
- else
- trng_wd_sync_threads();
- cal_perfermance_data(options, ptime);
-
- uninit_trng_wd_queue();
-
- return 0;
-}
diff --git a/uadk_tool/benchmark/trng_wd_benchmark.h b/uadk_tool/benchmark/trng_wd_benchmark.h
deleted file mode 100644
index 49453c8..0000000
--- a/uadk_tool/benchmark/trng_wd_benchmark.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: Apache-2.0 */
-
-#ifndef TRNG_WD_BENCHMARK_H
-#define TRNG_WD_BENCHMARK_H
-
-extern int trng_wd_benchmark(struct acc_option *options);
-#endif /* TRNG_WD_BENCHMARK_H */
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index fd64f6c..09e99e2 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -16,8 +16,6 @@
#include "zip_uadk_benchmark.h"
#include "zip_wd_benchmark.h"
-#include "trng_wd_benchmark.h"
-
#define TABLE_SPACE_SIZE 8
/*----------------------------------------head struct--------------------------------------------------------*/
@@ -157,7 +155,6 @@ static struct acc_alg_item alg_options[] = {
{"sha512", "sha512", SHA512_ALG},
{"sha512-224", "sha512-224", SHA512_224},
{"sha512-256", "sha512-256", SHA512_256},
- {"trng", "trng", TRNG},
{"", "", ALG_MAX}
};
@@ -463,11 +460,6 @@ static void parse_alg_param(struct acc_option *option)
option->acctype = HPRE_TYPE;
option->subtype = X448_TYPE;
break;
- case TRNG:
- snprintf(option->algclass, MAX_ALG_NAME, "%s", "trng");
- option->acctype = TRNG_TYPE;
- option->subtype = DEFAULT_TYPE;
- break;
default:
if (option->algtype <= RSA_4096_CRT) {
snprintf(option->algclass, MAX_ALG_NAME, "%s", "rsa");
@@ -596,13 +588,6 @@ static int benchmark_run(struct acc_option *option)
ret = zip_wd_benchmark(option);
}
break;
- case TRNG_TYPE:
- if (option->modetype == SVA_MODE)
- ACC_TST_PRT("TRNG not support sva mode..\n");
- else if (option->modetype == NOSVA_MODE)
- ret = trng_wd_benchmark(option);
-
- break;
}
return ret;
diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h
index 9a0ad5e..83fd7fa 100644
--- a/uadk_tool/benchmark/uadk_benchmark.h
+++ b/uadk_tool/benchmark/uadk_benchmark.h
@@ -96,7 +96,6 @@ enum acc_type {
SEC_TYPE,
HPRE_TYPE,
ZIP_TYPE,
- TRNG_TYPE,
};
enum acc_init_type {
diff --git a/v1/drv/hisi_rng_udrv.c b/v1/drv/hisi_rng_udrv.c
deleted file mode 100644
index 605ef27..0000000
--- a/v1/drv/hisi_rng_udrv.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright 2018-2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <pthread.h>
-#include <sys/mman.h>
-#include <string.h>
-#include <stdint.h>
-#include <sys/epoll.h>
-#include <sys/eventfd.h>
-#include <sys/types.h>
-
-#include "hisi_rng_udrv.h"
-
-#define HISI_RNG_BYTES 4
-#define MAX_RETRY_COUNTS 8
-#define RNG_NUM_OFFSET 0x00F0
-
-int rng_init_queue(struct wd_queue *q)
-{
- struct q_info *qinfo = q->qinfo;
- struct rng_queue_info *info;
- int ret;
-
- info = calloc(1, sizeof(*info));
- if (!info) {
- WD_ERR("no mem!\n");
- return -ENOMEM;
- }
-
- ret = pthread_spin_init(&info->lock, PTHREAD_PROCESS_PRIVATE);
- if (ret) {
- free(info);
- WD_ERR("failed to init rng qinfo lock!\n");
- return ret;
- }
-
- qinfo->priv = info;
- info->mmio_base = wd_drv_mmap_qfr(q, WD_UACCE_QFRT_MMIO, 0);
- if (info->mmio_base == MAP_FAILED) {
- info->mmio_base = NULL;
- qinfo->priv = NULL;
- pthread_spin_destroy(&info->lock);
- free(info);
- WD_ERR("mmap trng mmio fail\n");
- return -ENOMEM;
- }
-
- return 0;
-}
-
-void rng_uninit_queue(struct wd_queue *q)
-{
- struct q_info *qinfo = q->qinfo;
- struct rng_queue_info *info = qinfo->priv;
-
- wd_drv_unmmap_qfr(q, info->mmio_base, WD_UACCE_QFRT_MMIO, 0);
-
- free(qinfo->priv);
- qinfo->priv = NULL;
- pthread_spin_destroy(&info->lock);
-}
-
-int rng_send(struct wd_queue *q, void **req, __u32 num)
-{
- struct q_info *qinfo = q->qinfo;
- struct rng_queue_info *info = qinfo->priv;
-
- pthread_spin_lock(&info->lock);
- if (!info->req_cache[info->send_idx]) {
- info->req_cache[info->send_idx] = req[0];
- info->send_idx++;
- pthread_spin_unlock(&info->lock);
- return 0;
- }
- pthread_spin_unlock(&info->lock);
-
- WD_ERR("queue is full!\n");
- return -WD_EBUSY;
-}
-
-static int rng_read(struct rng_queue_info *info, struct wcrypto_rng_msg *msg)
-{
- __u32 max = msg->in_bytes;
- __u32 currsize = 0;
- int recv_count = 0;
- __u32 val;
-
- do {
- val = wd_reg_read((void *)((uintptr_t)info->mmio_base +
- RNG_NUM_OFFSET));
- if (!val) {
- if (++recv_count > MAX_RETRY_COUNTS) {
- WD_ERR("read random data timeout\n");
- break;
- }
-
- usleep(1);
- continue;
- }
-
- recv_count = 0;
- if (max - currsize >= HISI_RNG_BYTES) {
- memcpy(msg->out + currsize, &val, HISI_RNG_BYTES);
- currsize += HISI_RNG_BYTES;
- if (currsize == max)
- break;
- continue;
- }
-
- memcpy(msg->out + currsize, &val, max - currsize);
- currsize = max;
- } while (currsize < max);
-
- return currsize;
-}
-
-int rng_recv(struct wd_queue *q, void **resp, __u32 num)
-{
- struct q_info *qinfo = q->qinfo;
- struct rng_queue_info *info = qinfo->priv;
- __u16 usr = (__u16)(uintptr_t)*resp;
- struct wcrypto_rng_msg *msg;
- struct wcrypto_cb_tag *tag;
- __u32 currsize = 0;
-
- pthread_spin_lock(&info->lock);
- msg = info->req_cache[info->recv_idx];
- if (!msg) {
- pthread_spin_unlock(&info->lock);
- return 0;
- }
-
- info->req_cache[info->recv_idx] = NULL;
- info->recv_idx++;
- pthread_spin_unlock(&info->lock);
-
- tag = (void *)(uintptr_t)msg->usr_tag;
- if (usr && tag->ctx_id != usr)
- return 0;
-
- currsize = rng_read(info, msg);
- if (!currsize) {
- WD_ERR("random data err!\n");
- return -WD_EINVAL;
- }
-
- msg->out_bytes = currsize;
- *resp = msg;
-
- return 1;
-}
diff --git a/v1/drv/hisi_rng_udrv.h b/v1/drv/hisi_rng_udrv.h
deleted file mode 100644
index 3efa10e..0000000
--- a/v1/drv/hisi_rng_udrv.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2018-2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __HISI_RNG_UDRV_H__
-#define __HISI_RNG_UDRV_H__
-
-#include <linux/types.h>
-#include "v1/wd.h"
-#include "v1/wd_util.h"
-#include "v1/wd_rng.h"
-
-#define TRNG_Q_DEPTH 256
-
-struct rng_queue_info {
- void *mmio_base;
- void *req_cache[TRNG_Q_DEPTH];
- __u8 send_idx;
- __u8 recv_idx;
- pthread_spinlock_t lock;
-};
-
-int rng_init_queue(struct wd_queue *q);
-void rng_uninit_queue(struct wd_queue *q);
-int rng_send(struct wd_queue *q, void **req, __u32 num);
-int rng_recv(struct wd_queue *q, void **resp, __u32 num);
-
-#endif
diff --git a/v1/libwd.map b/v1/libwd.map
index d53201b..6c54479 100644
--- a/v1/libwd.map
+++ b/v1/libwd.map
@@ -133,11 +133,6 @@ global:
wcrypto_rsa_poll;
wcrypto_del_rsa_ctx;
- wcrypto_create_rng_ctx;
- wcrypto_del_rng_ctx;
- wcrypto_do_rng;
- wcrypto_rng_poll;
-
wd_sglpool_create;
wd_sglpool_destroy;
wd_alloc_sgl;
diff --git a/v1/test/Makefile.am b/v1/test/Makefile.am
index bd41cfe..6cbf79f 100644
--- a/v1/test/Makefile.am
+++ b/v1/test/Makefile.am
@@ -7,7 +7,6 @@ SUBDIRS+=hisi_zip_test
endif
SUBDIRS+=hisi_zip_test_sgl
-SUBDIRS+=hisi_trng_test
if HAVE_CRYPTO
SUBDIRS+=hisi_hpre_test
diff --git a/v1/test/hisi_trng_test/Makefile.am b/v1/test/hisi_trng_test/Makefile.am
deleted file mode 100644
index b561585..0000000
--- a/v1/test/hisi_trng_test/Makefile.am
+++ /dev/null
@@ -1,20 +0,0 @@
-AM_CFLAGS=-Wall -Werror -O0 -fno-strict-aliasing -I$(top_srcdir)/include -I$(srcdir) -pthread
-
-if HAVE_CRYPTO
-bin_PROGRAMS=test_hisi_trngu_v1 test_hisi_trngk_v1 test_hisi_trngp_v1
-
-test_hisi_trngu_v1_SOURCES=test_hisi_trngu.c
-test_hisi_trngk_v1_SOURCES=test_hisi_trngk.c
-test_hisi_trngp_v1_SOURCES=test_hisi_trngp.c
-
-if WD_STATIC_DRV
-test_hisi_trngu_v1_LDADD=../../../.libs/libwd.la
-test_hisi_trngk_v1_LDADD=../../../.libs/libwd.la
-test_hisi_trngp_v1_LDADD=../../../.libs/libwd.la
-else
-test_hisi_trngu_v1_LDADD=../../../.libs/libwd.so
-test_hisi_trngk_v1_LDADD=../../../.libs/libwd.so
-test_hisi_trngp_v1_LDADD=../../../.libs/libwd.so
-endif
-
-endif
diff --git a/v1/test/hisi_trng_test/test_hisi_trngk.c b/v1/test/hisi_trng_test/test_hisi_trngk.c
deleted file mode 100755
index ae719e5..0000000
--- a/v1/test/hisi_trng_test/test_hisi_trngk.c
+++ /dev/null
@@ -1,155 +0,0 @@
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#define __USE_GNU
-#include <sched.h>
-#include <pthread.h>
-#include <sys/mman.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <semaphore.h>
-
-
-struct thread_info
-{
- pthread_t thread_id;
- unsigned int size;
- unsigned int num;
- int addr;
-
-};
-
-void *trng_thread(void *args)
-{
-
- int fd = -1;
- int fd_w = -1;
- int ret;
- unsigned int input;
- struct thread_info *tinfo = args;
- input = tinfo->size;
- unsigned int *data = (unsigned int*)malloc(sizeof(unsigned int) * input);
-
- if(!data)
- return NULL;
-
- if (tinfo->addr == 0){
-
-// printf("Now try to get %d bytes random number from /dev/hwrng.\n", input * 4);
- fd = open ("/dev/hwrng", O_RDONLY);
- }
- else if (tinfo->addr == 1){
-// printf("Now try to get %d bytes random number from /dev/random.\n", input * 4);
- fd = open ("/dev/random", O_RDONLY);
- }
-
- if (fd <0 ) {
- printf("can not open\n");
- return NULL;
- }
-
- fd_w = open ("/root/trng_file", O_WRONLY|O_CREAT|O_APPEND,0777);
- if (fd_w <0 ) {
- printf("can not open trng_file\n");
- return NULL;
- }
- memset(data, 0, sizeof(int) * input);
- ret = read(fd, data, input);
- if (ret < 0) {
- printf("read error %d\n", ret);
- return NULL;
- }
- ret =write(fd_w,data,input);
- if (ret < 0) {
- printf("write error %d\n", ret);
- return NULL;
- }
-
- close(fd);
- close(fd_w);
-
- return NULL;
-}
-
-
-void trng_test(int addr,int num,unsigned int si,int thread_num)
-{
-
- int i;
- void *ret = NULL;
- struct thread_info *tinfo;
- tinfo = calloc(thread_num, sizeof(struct thread_info));
-
- if (tinfo == NULL)
- {
- printf("calloc fail...\n");
- return;
- }
-
- for (i = 0; i<thread_num; ++i)
- {
- tinfo[i].thread_id = i;
- tinfo[i].addr = addr;
- tinfo[i].num = num;
- tinfo[i].size = si;
-
- if ((pthread_create(&tinfo[i].thread_id,NULL,trng_thread, (void *)&tinfo[i])) != 0)
- {
- return;
- }
- }
-
- for (i=0; i<thread_num; ++i)
- {
- if (pthread_join(tinfo[i].thread_id, &ret) != 0)
- {
- printf("thread is not exit....\n");
- return;
- }
- //printf("thread exit coid %d\n", (int *)ret);
- free(ret);
- }
- free(tinfo);
-}
-
-
-
-
-int main (int argc, char* argv[]) {
-
- int opt;
- int addr = 0, num = 0, thread_num = 0;
- unsigned int si = 0;
-
- while ((opt = getopt(argc, argv, "hri:p:s:")) != -1) {
- switch (opt) {
- case 'h':
- addr = 0;
- break;
- case 'r':
- addr = 1;
- break;
- case 'i':
- num = atoi(optarg);
- break;
- case 'p':
- thread_num = atoi(optarg);
- break;
- case 's':
- si = (unsigned int)atoi(optarg);
- break;
- default:
- break;
- }
- }
-
- trng_test(addr,num,si,thread_num);
-
- return 0;
-}
diff --git a/v1/test/hisi_trng_test/test_hisi_trngp.c b/v1/test/hisi_trng_test/test_hisi_trngp.c
deleted file mode 100644
index 2330b1e..0000000
--- a/v1/test/hisi_trng_test/test_hisi_trngp.c
+++ /dev/null
@@ -1,137 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <pthread.h>
-#include <unistd.h>
-
-static int input;
-static int thread_num;
-struct thread_info
-{
- pthread_t thread_id;
- unsigned int size;
- int num;
-};
-
-void *trng_thread(void *args)
-{
- int j;
- int fd = -1;
- int data;
- int ret;
- struct thread_info *tinfo = args;
- int si;
- int num;
- int size;
- int fd_w = -1;
- si = tinfo->size;
- num = tinfo->num;
- size=si/num;
- printf("Now try to get bytes random number from /dev/random.\n");
- fd = open("/dev/random", O_RDONLY);
- if (fd <0 ) {
- printf("can not open\n");
- return NULL;
- }
- for (j = 0; j< size; j++) {
- ret = read(fd, &data, 1);
- if (ret < 0) {
- printf("read error %d\n", ret);
- return NULL;
- }
-// else if (ret < 1)
-// goto rd_ag;
-// if (!data) {
-// printf("read data error!\n");
-// return data;
-// }
- printf("the read num:%x\n",data);
- }
- fd_w = open ("/root/trng_file", O_RDWR | O_CREAT |O_APPEND , 0777);
- if (fd_w <0 ) {
- printf("can not open trng_file\n");
- return NULL;
- }
- ret = write(fd_w,&data,size);
- if (ret < 0) {
- printf("write error %d\n", ret);
- return NULL;
- }
- close(fd);
- close(fd_w);
- return NULL;
-}
-
-void trng_test(int input,int thread_num)
-{
- int i;
- void *ret = NULL;
- struct thread_info *tinfo;
- tinfo = calloc(thread_num, sizeof(struct thread_info));
- if(tinfo == NULL)
- {
- printf("calloc fail...\n");
- return;
- }
- for(i = 0; i<thread_num; ++i)
- {
- tinfo[i].thread_id = i;
- tinfo[i].num=thread_num;
-// tinfo[i].addr = addr;
-// tinfo[i].num = num;
- tinfo[i].size = input;
- if((pthread_create(&tinfo[i].thread_id,NULL,trng_thread, (void *)&tinfo[i])) != 0)
- {
- return;
- }
- }
-
- for(i=0; i<thread_num; ++i)
- {
- if(pthread_join(tinfo[i].thread_id, &ret) != 0)
- {
- printf("thread is not exit....\n");
- return;
- }
-// printf("thread exit coid %d\n", (int *)ret);
- free(ret);
- }
- free(tinfo);
-}
-
-int main (int argc, char* argv[])
-{
- struct timeval start_tval, end_tval;
- float time,speed;
- int fd_f=-1;
- fd_f = open ("/root/trng_file", O_RDWR | O_CREAT |O_TRUNC, 0777);
- if (fd_f <0 ) {
- printf("can not open trng_file\n");
- return fd_f;
- }
- input = strtoul(argv[1], NULL, 10);
- if (input <= 0){
- printf("input error!\n");
- return -1;
- }
- thread_num = strtoul((char *)argv[2], NULL, 10);
- if (thread_num <= 0 || thread_num > 128) {
- printf("Invalid threads num:%d!\n",thread_num);
- printf("Now set threads num as 2\n");
- thread_num = 2;
- }
- gettimeofday(&start_tval, NULL);
- trng_test(input,thread_num);
- gettimeofday(&end_tval, NULL);
- time = (float)((end_tval.tv_sec - start_tval.tv_sec) * 1000000 +
- (end_tval.tv_usec - start_tval.tv_usec));
- speed = input/(time / 1000000);
- printf("read random speed: %0.0f time\n", time);
- printf("read random speed: %0.0f bytes/s\n", speed);
- close(fd_f);
- return 0;
-}
diff --git a/v1/test/hisi_trng_test/test_hisi_trngu.c b/v1/test/hisi_trng_test/test_hisi_trngu.c
deleted file mode 100755
index 86aa8a9..0000000
--- a/v1/test/hisi_trng_test/test_hisi_trngu.c
+++ /dev/null
@@ -1,624 +0,0 @@
-/*
- * Copyright 2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#define __USE_GNU
-#include <sched.h>
-#include <pthread.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/syscall.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <semaphore.h>
-
-#include "../../wd.h"
-#include "../../wd_rng.h"
-
-#define RNG_TST_PRT printf
-#define BN_ULONG unsigned long
-#define TEST_MAX_THRD 128
-#define MAX_TRY_TIMES 10000
-#define LOG_INTVL_NUM 8
-#define TEST_CNT 10
-
-static int q_num = 1;
-static int ctx_num_per_q = 1;
-
-enum alg_op_type {
- TRNG_GEN,
- TRNG_AGEN,
-};
-
-struct trng_user_tag_info {
- int pid;
- int thread_id;
-};
-
-struct test_trng_pthread_dt {
- int cpu_id;
- int thread_num;
- void *q;
-};
-
-static struct test_trng_pthread_dt test_thrds_data[TEST_MAX_THRD];
-static pthread_t system_test_thrds[TEST_MAX_THRD];
-static unsigned int g_input;
-
-
-static inline int _get_cpu_id(int thr, __u64 core_mask)
-{
- __u64 i;
- int cnt = 0;
-
- for (i = 1; i < 64; i++) {
- if (core_mask & (0x1ull << i)) {
- if (thr == cnt)
- return i;
- cnt++;
- }
- }
-
- return 0;
-}
-
-static inline int _get_one_bits(__u64 val)
-{
- int count = 0;
-
- while (val) {
- if (val % 2 == 1)
- count++;
- val = val / 2;
- }
-
- return count;
-}
-
-void *_trng_sys_test_thread(void *data)
-{
- int ret, cpuid, i = 0;
- struct test_trng_pthread_dt *pdata = data;
- struct wcrypto_rng_ctx_setup setup;
- struct wcrypto_rng_op_data opdata;
- int pid = getpid();
- int thread_id = (int)syscall(__NR_gettid);
- struct wd_queue *q;
- int *out_data;
- void *ctx = NULL;
- void *tag = NULL;
-
- cpu_set_t mask;
- CPU_ZERO(&mask);
- cpuid = pdata->cpu_id;
- q = pdata->q;
- CPU_SET(cpuid, &mask);
-
- if (cpuid) {
- ret = pthread_setaffinity_np(pthread_self(),
- sizeof(mask), &mask);
- if (ret < 0) {
- RNG_TST_PRT("Proc-%d, thrd-%d:set affinity fail!\n",
- pid, thread_id);
- return NULL;
- }
- RNG_TST_PRT("Proc-%d, thrd-%d bind to cpu-%d!\n",
- pid, thread_id, cpuid);
- }
-
- memset(&setup, 0, sizeof(setup));
- memset(&opdata, 0, sizeof(opdata));
- ctx = wcrypto_create_rng_ctx(q, &setup);
- if (!ctx) {
- RNG_TST_PRT("Proc-%d, %d-TD:create %s ctx fail!\n",
- pid, thread_id, q->capa.alg);
- ret = -EINVAL;
- goto fail_release;
- }
-
- out_data = malloc(g_input);
- if(!out_data) {
- RNG_TST_PRT("malloc out_data memory fail!\n");
- }
- RNG_TST_PRT("request queue fail5!\n");
-
- while (1) {
- opdata.in_bytes = g_input;
- opdata.out = out_data;
- ret = wcrypto_do_rng(ctx, &opdata, tag);
- if (ret < 0) {
- RNG_TST_PRT("Proc-%d, T-%d:trng %d fail!\n", pid, thread_id, i);
- goto fail_release;
- }
- RNG_TST_PRT("the read data size %d!\n", opdata.out_bytes);
- i++;
- }
-fail_release:
- if (opdata.out)
- free(opdata.out);
- if (ctx)
- wcrypto_del_rng_ctx(ctx);
- return NULL;
-}
-
-
-static int trng_sys_test(int thread_num, __u64 lcore_mask,
- __u64 hcore_mask)
-{
- int i, ret, cnt = 0, j;
- struct wd_queue *q;
- int h_cpuid, qidx;
-
- q = malloc(q_num * sizeof(struct wd_queue));
- if (!q) {
- RNG_TST_PRT("malloc q memory fail!\n");
- return -ENOMEM;
- }
- memset(q, 0, q_num * sizeof(struct wd_queue));
-
- for (j = 0; j < q_num; j++) {
- q[j].capa.alg = "trng";
- ret = wd_request_queue(&q[j]);
- if (ret) {
- RNG_TST_PRT("request queue %d fail!\n", j);
- return ret;
- }
- }
- RNG_TST_PRT("request queue fail!\n");
- if (_get_one_bits(lcore_mask) > 0)
- cnt = _get_one_bits(lcore_mask);
- else if (_get_one_bits(lcore_mask) == 0 &&
- _get_one_bits(hcore_mask) == 0)
- cnt = thread_num;
-
- for (i = 0; i < cnt; i++) {
- qidx = i / ctx_num_per_q;
- test_thrds_data[i].q = &q[qidx];
- test_thrds_data[i].thread_num = thread_num;
- test_thrds_data[i].cpu_id = _get_cpu_id(i, lcore_mask);
- ret = pthread_create(&system_test_thrds[i], NULL,
- _trng_sys_test_thread, &test_thrds_data[i]);
- if (ret) {
- RNG_TST_PRT("Create %dth thread fail!\n", i);
- return ret;
- }
- }
- RNG_TST_PRT("request queue fail2!\n");
- for (i = 0; i < thread_num - cnt; i++) {
- h_cpuid = _get_cpu_id(i, hcore_mask);
- if (h_cpuid > 0)
- h_cpuid += 64;
-
- qidx = (i + cnt) / ctx_num_per_q;
- test_thrds_data[i + cnt].q = &q[qidx];
- test_thrds_data[i + cnt].thread_num = thread_num;
- test_thrds_data[i + cnt].cpu_id = h_cpuid;
- ret = pthread_create(&system_test_thrds[i + cnt], NULL,
- _trng_sys_test_thread, &test_thrds_data[i + cnt]);
- if (ret) {
- RNG_TST_PRT("Create %dth thread fail!\n", i);
- return ret;
- }
- }
- RNG_TST_PRT("request queue fail3!\n");
- for (i = 0; i < thread_num; i++) {
- ret = pthread_join(system_test_thrds[i], NULL);
- if (ret) {
- RNG_TST_PRT("Join %dth thread fail!\n", i);
- return ret;
- }
- }
- free(q);
- return 0;
-}
-
-
-static void _trng_cb(const void *message, void *tag)
-{
- const struct wcrypto_rng_msg *msg = message;
- struct trng_user_tag_info* pSwData = (struct trng_user_tag_info*)tag;
- struct wcrypto_rng_op_data opdata;
- int pid, threadId;
-
- if (NULL == pSwData) {
- RNG_TST_PRT("pSwData NULL!\n");
- return;
- }
- memset(&opdata, 0, sizeof(opdata));
-
- opdata.out = (void *)msg->out;
- opdata.out_bytes = msg->out_bytes;
- pid = pSwData->pid;
- threadId = pSwData->thread_id;
- RNG_TST_PRT("Proc-%d, %d-TD trng\n", pid, threadId);
- RNG_TST_PRT("the random number size :%d\n", opdata.out_bytes);
-
- if (opdata.out)
- free(opdata.out);
-
- if (pSwData)
- free(pSwData);
-}
-
-static void *_trng_asys_test_thread(void *data)
-{
- int ret, cpuid;
- struct test_trng_pthread_dt *pdata = data;
- struct wd_queue *q = NULL;
- cpu_set_t mask;
- struct wcrypto_rng_ctx_setup setup;
- struct wcrypto_rng_ctx *ctx = NULL;
- struct trng_user_tag_info *tag = NULL;
- struct wcrypto_rng_op_data opdata;
- int pid = getpid();
- int thread_id = (int)syscall(__NR_gettid);
- int *out_data;
- int i = 0;
-
- CPU_ZERO(&mask);
- cpuid = pdata->cpu_id;
- q = (struct wd_queue *)pdata->q;
- CPU_SET(cpuid, &mask);
-
- if (!q) {
- RNG_TST_PRT("q null!\n");
- return NULL;
- }
- if (cpuid) {
- ret = pthread_setaffinity_np(pthread_self(),
- sizeof(mask), &mask);
- if (ret < 0) {
- RNG_TST_PRT("Proc-%d, thrd-%d:set affinity fail!\n",
- pid, thread_id);
- return NULL;
- }
- RNG_TST_PRT("Proc-%d, thrd-%d bind to cpu-%d!\n",
- pid, thread_id, cpuid);
- }
-
- q->capa.alg = "trng";
- memset(&setup, 0, sizeof(setup));
- memset(&opdata, 0, sizeof(opdata));
- setup.cb = _trng_cb;
- ctx = wcrypto_create_rng_ctx(q, &setup);
- if (!ctx) {
- RNG_TST_PRT("Proc-%d, %d-TD:create %s ctx fail!\n",
- pid, thread_id, q->capa.alg);
- goto fail_release;
- }
-
- while(1) {
- tag = malloc(sizeof(struct trng_user_tag_info));
- if (!tag) {
- RNG_TST_PRT("malloc tag fail!\n");
- goto fail_release;
- }
-
- tag->pid = pid;
- tag->thread_id = thread_id;
-
- out_data = malloc(g_input);
- if(!out_data) {
- RNG_TST_PRT("malloc fail\n");
- return 0;
- }
-
- opdata.in_bytes = g_input;
- opdata.out = out_data;
- try_again:
- ret = wcrypto_do_rng(ctx, &opdata, tag);
- if (ret == -WD_EBUSY) {
- usleep(100);
- goto try_again;
- } else if(ret) {
- RNG_TST_PRT("Proc-%d, T-%d:trng %d fail!\n", pid, thread_id, i);
- goto fail_release;
- }
- i++;
- }
-fail_release:
- wcrypto_del_rng_ctx(ctx);
- return NULL;
-}
-
-static void* _trng_async_poll_test_thread(void *data)
-{
- struct test_trng_pthread_dt *pdata = data;
- struct wd_queue *q = pdata->q;
- int ret, cpuid;
- int pid = getpid();
- cpu_set_t mask;
- int thread_id = (int)syscall(__NR_gettid);
-
- CPU_ZERO(&mask);
- cpuid = pdata->cpu_id;
- CPU_SET(cpuid, &mask);
- if (cpuid) {
- ret = pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask);
- if (ret < 0) {
- RNG_TST_PRT("Proc-%d, thrd-%d:set affinity fail!\n",
- pid, thread_id);
- return NULL;
- }
- RNG_TST_PRT("Proc-%d, poll thrd-%d bind to cpu-%d!\n",
- pid, thread_id, cpuid);
- }
-
- while (1) {
- ret = wcrypto_rng_poll(q, 1);
- if (ret < 0) {
- break;
- }
- }
-
- return NULL;
-}
-
-static int trng_asys_test(int thread_num, __u64 lcore_mask, __u64 hcore_mask)
-{
- int i, ret, cnt = 0;
- struct wd_queue q;
- int h_cpuid;
-
- memset(&q, 0, sizeof(q));
-
- q.capa.alg = "trng";
- ret = wd_request_queue(&q);
- if (ret) {
- RNG_TST_PRT("request queue fail!\n");
- return ret;
- }
-
- if (_get_one_bits(lcore_mask) > 0)
- cnt = _get_one_bits(lcore_mask);
- else if (_get_one_bits(lcore_mask) == 0 &&
- _get_one_bits(hcore_mask) == 0)
- cnt = thread_num;
-
- test_thrds_data[0].q= &q;
- test_thrds_data[0].thread_num = 1;
- test_thrds_data[0].cpu_id = _get_cpu_id(0, lcore_mask);
- ret = pthread_create(&system_test_thrds[0], NULL,
- _trng_async_poll_test_thread, &test_thrds_data[0]);
- if (ret) {
- RNG_TST_PRT("Create poll thread fail!\n");
- return ret;
- }
-
- for (i = 1; i <= cnt; i++) {
- test_thrds_data[i].q = &q;
- test_thrds_data[i].thread_num = thread_num;
- test_thrds_data[i].cpu_id = _get_cpu_id(i, lcore_mask);
- ret = pthread_create(&system_test_thrds[i], NULL,
- _trng_asys_test_thread, &test_thrds_data[i]);
- if (ret) {
- RNG_TST_PRT("Create %dth thread fail!\n", i);
- return ret;
- }
- }
-
- for (i = 1; i <= thread_num - cnt; i++) {
- h_cpuid = _get_cpu_id(i, hcore_mask);
- if (h_cpuid > 0)
- h_cpuid += 64;
- test_thrds_data[i + cnt].q = &q;
- test_thrds_data[i + cnt].thread_num = thread_num;
- test_thrds_data[i + cnt].cpu_id = h_cpuid;
- ret = pthread_create(&system_test_thrds[i + cnt], NULL,
- _trng_asys_test_thread, &test_thrds_data[i + cnt]);
- if (ret) {
- RNG_TST_PRT("Create %dth thread fail!\n", i);
- return ret;
- }
- }
-
- for (i = 0; i < thread_num; i++) {
- ret = pthread_join(system_test_thrds[i], NULL);
- if (ret) {
- RNG_TST_PRT("Join %dth thread fail!\n", i);
- return ret;
- }
- }
-
- wd_release_queue(&q);
- return 0;
-
-}
-int main(int argc, char *argv[])
-{
- struct wcrypto_rng_ctx *ctx;
- struct wcrypto_rng_op_data opdata;
- struct wcrypto_rng_ctx_setup setup;
- enum alg_op_type alg_op_type = TRNG_GEN;
- int thread_num, bits;
- __u64 core_mask[2];
- struct wd_queue q;
- void *tag = NULL;
- int *data;
- int ret;
- int fd = -1;
- int fd_w = -1;
- if (!argv[1]) {
- RNG_TST_PRT("pls printf the size of the random data!\n");
- return -WD_EINVAL;
- }
- g_input = (unsigned int)strtoul(argv[1], NULL, 10);
- printf("g_input:%d\n",g_input);
- //if (g_input <= 0){
- // printf("input error!\n");
- // return -WD_EINVAL;
- //}
- if (argv[2]) {
- if(!strcmp(argv[2], "-system-gen")) {
- alg_op_type = TRNG_GEN;
- RNG_TST_PRT("Now doing system random number gen test!\n");
- } else if(!strcmp(argv[2], "-system-agen")) {
- alg_op_type = TRNG_AGEN;
- RNG_TST_PRT("Now doing system random number agen test!\n");
- }
-
- thread_num = strtoul((char *)argv[3], NULL, 10);
- if (thread_num <= 0 || thread_num > TEST_MAX_THRD) {
- RNG_TST_PRT("Invalid threads num:%d!\n",
- thread_num);
- RNG_TST_PRT("Now set threads num as 2\n");
- thread_num = 2;
- }
-
- if (strcmp(argv[4], "-c")) {
- RNG_TST_PRT("./test_hisi_trng --help get details\n");
- return -EINVAL;
- }
- if (argv[5][0] != '0' || argv[5][1] != 'x') {
- RNG_TST_PRT("Err:coremask should be hex!\n");
- return -EINVAL;
- }
-
- if (strlen(argv[5]) > 34) {
- RNG_TST_PRT("Warning: coremask is cut!\n");
- argv[5][34] = 0;
- }
-
- if (strlen(argv[5]) <= 18) {
- core_mask[0] = strtoull(argv[5], NULL, 16);
- if (core_mask[0] & 0x1) {
- RNG_TST_PRT("Warn:cannot bind to core 0,\n");
- RNG_TST_PRT("now run without binding\n");
- core_mask[0] = 0x0; /* no binding */
- }
- core_mask[1] = 0;
- } else {
- int offset = 0;
- char *temp;
-
- offset = strlen(argv[5]) - 16;
- core_mask[0] = strtoull(&argv[5][offset], NULL, 16);
- if (core_mask[0] & 0x1) {
- RNG_TST_PRT("Warn:cannot bind to core 0,\n");
- RNG_TST_PRT("now run without binding\n");
- core_mask[0] = 0x0; /* no binding */
- }
- temp = malloc(64);
- strcpy(temp, argv[5]);
- temp[offset] = 0;
- core_mask[1] = strtoull(temp, NULL, 16);
- free(temp);
- }
-
- bits = _get_one_bits(core_mask[0]);
- bits += _get_one_bits(core_mask[1]);
- if (thread_num > bits) {
- RNG_TST_PRT("Coremask not covers all thrds,\n");
- RNG_TST_PRT("Bind first %d thrds!\n", bits);
- } else if (thread_num < bits) {
- RNG_TST_PRT("Coremask overflow,\n");
- RNG_TST_PRT("Just try to bind all thrds!\n");
- }
-
- if (argv[6]) {
- ctx_num_per_q = strtoul(argv[6], NULL, 10);
- if (ctx_num_per_q <= 0) {
- RNG_TST_PRT("Invalid ctx num per queue:%s!\n",
- argv[6]);
- RNG_TST_PRT("Now ctx num per queue is set as 1!\n");
- ctx_num_per_q = 1;
- }
- } else {
- RNG_TST_PRT("Now ctx num per queue is set as 1!\n");
- ctx_num_per_q = 1;
- }
-
- q_num = (thread_num - 1) / ctx_num_per_q + 1;
-
- RNG_TST_PRT("Proc-%d: starts %d threads bind to %s\n",
- getpid(), thread_num, argv[5]);
- RNG_TST_PRT(" lcoremask=0x%llx, hcoremask=0x%llx\n",
- core_mask[0], core_mask[1]);
- if(alg_op_type == TRNG_GEN)
- return trng_sys_test(thread_num, core_mask[0],
- core_mask[1]);
-
- return trng_asys_test(thread_num, core_mask[0],
- core_mask[1]);
- }
-
- RNG_TST_PRT("Now try to get %d bytes random number.\n", g_input);
-
- data = malloc(g_input);
- if (!data) {
- RNG_TST_PRT("malloc data failed.\n");
- return -1;
- }
-
- memset((void *)&q, 0, sizeof(q));
- memset(&setup, 0, sizeof(setup));
- memset(&opdata, 0, sizeof(opdata));
-
- q.capa.alg = "trng";
- ret = wd_request_queue(&q);
- if (ret) {
- RNG_TST_PRT("request queue fail!\n");
- return ret;
- }
- ctx = wcrypto_create_rng_ctx(&q, &setup);
- if (!ctx) {
- ret = -ENOMEM;
- RNG_TST_PRT("create trng ctx fail!\n");
- goto release_q;
- }
-
- opdata.in_bytes = g_input;
- opdata.out = data;
- ret = wcrypto_do_rng(ctx, &opdata, tag);
- if (ret != 1) {
- RNG_TST_PRT("a wd_do_trng fail!\n");
- goto del_ctx;
- }
-
- RNG_TST_PRT("random_data size= %d.\n", opdata.out_bytes);
- fd_w = open ("/root/trng_file", O_RDWR|O_CREAT|O_TRUNC,0777);
- if (fd_w <0 ) {
- printf("can not open trng_file\n");
- return fd_w;
- }
- /*fd = open ("/dev/random", O_RDONLY);
- if (fd <0 ) {
- printf("can not open\n");
- return fd;
- }*/
- /*ret = read(fd, data, g_input);
- if (ret < 0) {
- printf("read error %d\n", ret);
- return ret;
- }*/
- ret = write(fd_w,opdata.out,opdata.out_bytes);
- if (ret < 0) {
- printf("write error %d\n", ret);
- return ret;
- }
- close(fd);
- close(fd_w);
-del_ctx:
- wcrypto_del_rng_ctx(ctx);
-
-release_q:
- wd_release_queue(&q);
- free(data);
- return ret;
-}
diff --git a/v1/wd.h b/v1/wd.h
index 0132e25..35dcf31 100644
--- a/v1/wd.h
+++ b/v1/wd.h
@@ -184,7 +184,7 @@ struct wd_capa {
* Other capabilities.
* 0~15 bits: number of cookies that the user wants to allocate.
* Optional, user can set value based on the number of requests and system memory,
- * 1~1024 is valid. If the value is not set or invalid, the default value 64 (rng is 256)
+ * 1~1024 is valid. If the value is not set or invalid, the default value 64
* is used to initialize cookies.
*/
__u32 flags;
diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c
index 1c9f656..df5368d 100644
--- a/v1/wd_adapter.c
+++ b/v1/wd_adapter.c
@@ -20,7 +20,6 @@
#include "v1/wd_util.h"
#include "v1/drv/hisi_qm_udrv.h"
-#include "v1/drv/hisi_rng_udrv.h"
#include "v1/wd_adapter.h"
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
@@ -87,12 +86,6 @@ static const struct wd_drv_dio_if hw_dio_tbl[] = { {
.init_sgl = qm_init_hwsgl_mem,
.uninit_sgl = qm_uninit_hwsgl_mem,
.sgl_merge = qm_merge_hwsgl,
- }, {
- .hw_type = "hisi-trng-v2",
- .open = rng_init_queue,
- .close = rng_uninit_queue,
- .send = rng_send,
- .recv = rng_recv,
},
};
diff --git a/v1/wd_rng.c b/v1/wd_rng.c
deleted file mode 100644
index 7a89cd1..0000000
--- a/v1/wd_rng.c
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright 2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <sys/mman.h>
-
-#include "wd.h"
-#include "wd_util.h"
-#include "wd_rng.h"
-
-#define RNG_RESEND_CNT 8
-#define RNG_RECV_CNT 8
-#define WD_RNG_CTX_COOKIE_NUM 256
-
-struct wcrypto_rng_cookie {
- struct wcrypto_cb_tag tag;
- struct wcrypto_rng_msg msg;
-};
-
-struct wcrypto_rng_ctx {
- struct wd_cookie_pool pool;
- unsigned long ctx_id;
- struct wd_queue *q;
- struct wcrypto_rng_ctx_setup setup;
-};
-
-static int wcrypto_setup_qinfo(struct wcrypto_rng_ctx_setup *setup,
- struct wd_queue *q, __u32 *ctx_id)
-{
- struct q_info *qinfo;
- int ret = -WD_EINVAL;
-
- if (!q || !q->qinfo || !setup) {
- WD_ERR("input parameter err!\n");
- return ret;
- }
-
- if (strcmp(q->capa.alg, "trng")) {
- WD_ERR("algorithm mismatch!\n");
- return ret;
- }
- qinfo = q->qinfo;
- /* lock at ctx creating */
- wd_spinlock(&qinfo->qlock);
- if (qinfo->ctx_num >= WD_MAX_CTX_NUM) {
- WD_ERR("create too many trng ctx!\n");
- goto unlock;
- }
-
- ret = wd_alloc_id(qinfo->ctx_id, WD_MAX_CTX_NUM, ctx_id, 0,
- WD_MAX_CTX_NUM);
- if (ret) {
- WD_ERR("err: alloc ctx id fail!\n");
- goto unlock;
- }
- qinfo->ctx_num++;
- ret = WD_SUCCESS;
-unlock:
- wd_unspinlock(&qinfo->qlock);
- return ret;
-}
-
-void *wcrypto_create_rng_ctx(struct wd_queue *q,
- struct wcrypto_rng_ctx_setup *setup)
-{
- struct wcrypto_rng_cookie *cookie;
- struct wcrypto_rng_ctx *ctx;
- struct q_info *qinfo;
- __u32 cookies_num, i;
- __u32 ctx_id = 0;
- int ret;
-
- if (wcrypto_setup_qinfo(setup, q, &ctx_id))
- return NULL;
-
- ctx = calloc(1, sizeof(struct wcrypto_rng_ctx));
- if (!ctx) {
- WD_ERR("alloc ctx memory fail!\n");
- goto free_ctx_id;
- }
- memcpy(&ctx->setup, setup, sizeof(*setup));
- ctx->q = q;
- ctx->ctx_id = ctx_id + 1;
-
- cookies_num = wd_get_ctx_cookies_num(q->capa.flags, WD_RNG_CTX_COOKIE_NUM);
- ret = wd_init_cookie_pool(&ctx->pool,
- sizeof(struct wcrypto_rng_cookie), cookies_num);
- if (ret) {
- WD_ERR("fail to init cookie pool!\n");
- free(ctx);
- goto free_ctx_id;
- }
- for (i = 0; i < cookies_num; i++) {
- cookie = (void *)((uintptr_t)ctx->pool.cookies +
- i * ctx->pool.cookies_size);
- cookie->msg.alg_type = WCRYPTO_RNG;
- cookie->tag.ctx = ctx;
- cookie->tag.ctx_id = ctx->ctx_id;
- cookie->msg.usr_tag = (uintptr_t)&cookie->tag;
- }
-
- return ctx;
-
-free_ctx_id:
- qinfo = q->qinfo;
- wd_spinlock(&qinfo->qlock);
- qinfo->ctx_num--;
- wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, ctx_id, WD_MAX_CTX_NUM);
- wd_unspinlock(&qinfo->qlock);
-
- return NULL;
-}
-
-void wcrypto_del_rng_ctx(void *ctx)
-{
- struct wcrypto_rng_ctx *cx;
- struct q_info *qinfo;
-
- if (!ctx) {
- WD_ERR("delete trng ctx is NULL!\n");
- return;
- }
-
- cx = ctx;
- qinfo = cx->q->qinfo;
-
- wd_uninit_cookie_pool(&cx->pool);
- wd_spinlock(&qinfo->qlock);
- if (qinfo->ctx_num <= 0) {
- wd_unspinlock(&qinfo->qlock);
- WD_ERR("repeat delete trng ctx!\n");
- return;
- }
- qinfo->ctx_num--;
- wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, cx->ctx_id - 1,
- WD_MAX_CTX_NUM);
- wd_unspinlock(&qinfo->qlock);
-
- free(ctx);
-}
-
-int wcrypto_rng_poll(struct wd_queue *q, unsigned int num)
-{
- struct wcrypto_rng_msg *resp = NULL;
- struct wcrypto_rng_ctx *ctx;
- struct wcrypto_cb_tag *tag;
- unsigned int tmp = num;
- int count = 0;
- int ret;
-
- if (!q) {
- WD_ERR("%s(): input parameter err!\n", __func__);
- return -WD_EINVAL;
- }
-
- do {
- ret = wd_recv(q, (void **)&resp);
- if (!ret)
- break;
-
- if (ret < 0) {
- WD_ERR("recv err at trng poll!\n");
- return ret;
- }
-
- count++;
- tag = (void *)(uintptr_t)resp->usr_tag;
- ctx = tag->ctx;
- ctx->setup.cb(resp, tag->tag);
- wd_put_cookies(&ctx->pool, (void **)&tag, 1);
- resp = NULL;
- } while (--tmp);
-
- return count;
-}
-
-static int wcrypto_do_prepare(struct wcrypto_rng_cookie **cookie_addr,
- struct wcrypto_rng_op_data *opdata,
- struct wcrypto_rng_msg **req_addr,
- struct wcrypto_rng_ctx *ctxt,
- void *tag)
-{
- struct wcrypto_rng_cookie *cookie;
- struct wcrypto_rng_msg *req;
- int ret;
-
- if (unlikely(!ctxt || !opdata)) {
- WD_ERR("invalid: rng input parameter err!\n");
- return -WD_EINVAL;
- }
-
- if (unlikely((opdata->in_bytes && !opdata->out))) {
- WD_ERR("invalid: dst addr is NULL when in_bytes is non-zero!!\n");
- return -WD_EINVAL;
- }
-
- ret = wd_get_cookies(&ctxt->pool, (void **)&cookie, 1);
- if (ret)
- return ret;
-
- if (tag) {
- if (!ctxt->setup.cb) {
- WD_ERR("invalid: ctx call back is null!\n");
- wd_put_cookies(&ctxt->pool, (void **)&cookie, 1);
- return -WD_EINVAL;
- }
- cookie->tag.tag = tag;
- }
-
- req = &cookie->msg;
- req->in_bytes = opdata->in_bytes;
- req->out = opdata->out;
- *cookie_addr = cookie;
- *req_addr = req;
-
- return 0;
-}
-
-int wcrypto_do_rng(void *ctx, struct wcrypto_rng_op_data *opdata, void *tag)
-{
- struct wcrypto_rng_ctx *ctxt = ctx;
- struct wcrypto_rng_cookie *cookie;
- struct wcrypto_rng_msg *req;
- struct wcrypto_rng_msg *resp;
- uint32_t tx_cnt = 0;
- uint32_t rx_cnt = 0;
- int ret = 0;
-
- ret = wcrypto_do_prepare(&cookie, opdata, &req, ctxt, tag);
- if (ret)
- return ret;
-
- do {
- ret = wd_send(ctxt->q, req);
- if (!ret) {
- break;
- } else if (ret == -WD_EBUSY) {
- if (++tx_cnt > RNG_RESEND_CNT) {
- WD_ERR("do trng send cnt %u, exit!\n", tx_cnt);
- goto fail_with_cookie;
- }
-
- usleep(1);
- } else {
- WD_ERR("do rng wd_send err!\n");
- goto fail_with_cookie;
- }
- } while (true);
-
- if (tag)
- return ret;
-
- resp = (void *)(uintptr_t)ctxt->ctx_id;
-
- do {
- ret = wd_recv(ctxt->q, (void **)&resp);
- if (ret > 0) {
- break;
- } else if (!ret) {
- if (++rx_cnt > RNG_RECV_CNT) {
- WD_ERR("do trng recv cnt %u, exit!\n", rx_cnt);
- ret = -WD_ETIMEDOUT;
- goto fail_with_cookie;
- }
-
- usleep(1);
- } else {
- WD_ERR("do trng recv err!\n");
- goto fail_with_cookie;
- }
- } while (true);
-
- opdata->out_bytes = resp->out_bytes;
- ret = WD_SUCCESS;
-fail_with_cookie:
- wd_put_cookies(&ctxt->pool, (void **)&cookie, 1);
- return ret;
-}
diff --git a/v1/wd_rng.h b/v1/wd_rng.h
deleted file mode 100644
index fcde26d..0000000
--- a/v1/wd_rng.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __WD_RNG_H
-#define __WD_RNG_H
-
-#include "wd.h"
-#include "wd_digest.h"
-#include "wd_cipher.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct wcrypto_rng_ctx_setup {
- wcrypto_cb cb;
- __u16 data_fmt; /* Data format, denoted by enum wd_buff_type */
- enum wcrypto_type type; /* Please refer to the definition of enum */
- enum wcrypto_cipher_alg calg; /* DRBG cipher algorithm */
- enum wcrypto_cipher_mode cmode; /* DRBG cipher mode */
- enum wcrypto_digest_alg dalg; /* DRBG digest algorithm */
- enum wcrypto_digest_mode dmode; /* DRBG digest mode */
-};
-
-struct wcrypto_rng_msg {
- __u8 alg_type; /* Denoted by enum wcrypto_type */
- __u8 op_type; /* Denoted by enum wcrypto_rng_op_type */
- __u8 data_fmt; /* Data format, denoted by enum wd_buff_type */
- __u8 result; /* Data format, denoted by WD error code */
- __u8 *out; /* Result address */
- __u8 *in; /* Input address */
- __u32 out_bytes; /* output bytes */
- __u32 in_bytes; /* input bytes */
- __u64 usr_tag; /* user identifier */
-};
-
-enum wcrypto_rng_op_type {
- WCRYPTO_RNG_INVALID, /* Invalid RNG operational type */
- WCRYPTO_DRBG_RESEED, /* seed operation */
- WCRYPTO_DRBG_GEN, /* deterministic random number generation */
- WCRYPTO_TRNG_GEN, /* true random number generation */
-};
-
-struct wcrypto_rng_op_data {
- enum wcrypto_rng_op_type op_type;
- __u32 status; /* Operation result status */
- void *in; /* input */
- void *out; /* output */
- __u32 in_bytes; /* input bytes */
- __u32 out_bytes; /* output bytes */
-};
-
-void *wcrypto_create_rng_ctx(struct wd_queue *q,
- struct wcrypto_rng_ctx_setup *setup);
-void wcrypto_del_rng_ctx(void *ctx);
-int wcrypto_do_rng(void *ctx, struct wcrypto_rng_op_data *opdata, void *tag);
-int wcrypto_rng_poll(struct wd_queue *q, unsigned int num);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
--
2.33.0
1
0
From: Weili Qian <qianweili(a)huawei.com>
The trng module is not required. Therefore, remove the trng module code.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
Makefile.am | 6 +-
configure.ac | 1 -
uadk_tool/Makefile.am | 1 -
uadk_tool/benchmark/trng_wd_benchmark.c | 333 ------------
uadk_tool/benchmark/trng_wd_benchmark.h | 7 -
uadk_tool/benchmark/uadk_benchmark.c | 15 -
uadk_tool/benchmark/uadk_benchmark.h | 1 -
v1/drv/hisi_rng_udrv.c | 167 ------
v1/drv/hisi_rng_udrv.h | 40 --
v1/libwd.map | 5 -
v1/test/Makefile.am | 1 -
v1/test/hisi_trng_test/Makefile.am | 20 -
v1/test/hisi_trng_test/test_hisi_trngk.c | 155 ------
v1/test/hisi_trng_test/test_hisi_trngp.c | 137 -----
v1/test/hisi_trng_test/test_hisi_trngu.c | 624 -----------------------
v1/wd.h | 2 +-
v1/wd_adapter.c | 7 -
v1/wd_rng.c | 296 -----------
v1/wd_rng.h | 76 ---
19 files changed, 3 insertions(+), 1891 deletions(-)
delete mode 100644 uadk_tool/benchmark/trng_wd_benchmark.c
delete mode 100644 uadk_tool/benchmark/trng_wd_benchmark.h
delete mode 100644 v1/drv/hisi_rng_udrv.c
delete mode 100644 v1/drv/hisi_rng_udrv.h
delete mode 100644 v1/test/hisi_trng_test/Makefile.am
delete mode 100755 v1/test/hisi_trng_test/test_hisi_trngk.c
delete mode 100644 v1/test/hisi_trng_test/test_hisi_trngp.c
delete mode 100755 v1/test/hisi_trng_test/test_hisi_trngu.c
delete mode 100644 v1/wd_rng.c
delete mode 100644 v1/wd_rng.h
diff --git a/Makefile.am b/Makefile.am
index d1a5953..7749613 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,9 +49,8 @@ uadk_driversdir=$(libdir)/uadk
uadk_drivers_LTLIBRARIES=libhisi_sec.la libhisi_hpre.la libhisi_zip.la \
libisa_ce.la libisa_sve.la libhisi_dae.la libhisi_udma.la
-libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \
+libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \
v1/wd.c v1/wd.h v1/wd_adapter.c v1/wd_adapter.h \
- v1/wd_rng.c v1/wd_rng.h \
v1/wd_rsa.c v1/wd_rsa.h \
v1/wd_aead.c v1/wd_aead.h \
v1/wd_dh.c v1/wd_dh.h \
@@ -68,8 +67,7 @@ libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \
v1/drv/hisi_zip_udrv.c v1/drv/hisi_zip_udrv.h \
v1/drv/hisi_zip_huf.c v1/drv/hisi_zip_huf.h \
v1/drv/hisi_hpre_udrv.c v1/drv/hisi_hpre_udrv.h \
- v1/drv/hisi_sec_udrv.c v1/drv/hisi_sec_udrv.h \
- v1/drv/hisi_rng_udrv.c v1/drv/hisi_rng_udrv.h
+ v1/drv/hisi_sec_udrv.c v1/drv/hisi_sec_udrv.h
libwd_udma_la_SOURCES=wd_udma.h wd_udma_drv.h wd_udma.c \
wd_util.c wd_util.h wd_sched.c wd_sched.h wd.c wd.h
diff --git a/configure.ac b/configure.ac
index 95c9f67..eb5a211 100644
--- a/configure.ac
+++ b/configure.ac
@@ -109,7 +109,6 @@ AC_CONFIG_FILES([Makefile
v1/test/bmm_test/Makefile
v1/test/test_mm/Makefile
v1/test/hisi_hpre_test/Makefile
- v1/test/hisi_trng_test/Makefile
v1/test/hisi_sec_test/Makefile
v1/test/hisi_sec_test_sgl/Makefile
v1/test/hisi_zip_test/Makefile
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
index 86b3064..9a1703d 100644
--- a/uadk_tool/Makefile.am
+++ b/uadk_tool/Makefile.am
@@ -17,7 +17,6 @@ uadk_tool_SOURCES=uadk_tool.c dfx/uadk_dfx.c dfx/uadk_dfx.h \
benchmark/hpre_wd_benchmark.c hpre_wd_benchmark.h \
benchmark/zip_uadk_benchmark.c benchmark/zip_uadk_benchmark.h \
benchmark/zip_wd_benchmark.c benchmark/zip_wd_benchmark.h \
- benchmark/trng_wd_benchmark.c benchmark/trng_wd_benchmark.h \
test/uadk_test.c test/uadk_test.h \
test/test_sec.c test/test_sec.h test/sec_template_tv.h
diff --git a/uadk_tool/benchmark/trng_wd_benchmark.c b/uadk_tool/benchmark/trng_wd_benchmark.c
deleted file mode 100644
index 2f058d4..0000000
--- a/uadk_tool/benchmark/trng_wd_benchmark.c
+++ /dev/null
@@ -1,333 +0,0 @@
-/* SPDX-License-Identifier: Apache-2.0 */
-
-#include <numa.h>
-#include "uadk_benchmark.h"
-
-#include "trng_wd_benchmark.h"
-#include "v1/wd.h"
-#include "v1/wd_rng.h"
-
-struct thread_bd_res {
- struct wd_queue *queue;
- void *out;
- __u32 in_bytes;
-};
-
-struct thread_queue_res {
- struct thread_bd_res *bd_res;
-};
-
-struct wd_thread_res {
- u32 td_id;
- u32 pollid;
-};
-
-struct trng_async_tag {
- void *ctx;
- int optype;
-};
-
-static unsigned int g_thread_num;
-static struct thread_queue_res g_thread_queue;
-
-static int init_trng_wd_queue(struct acc_option *options)
-{
- int i, ret;
-
- g_thread_queue.bd_res = malloc(g_thread_num * sizeof(struct thread_bd_res));
- if (!g_thread_queue.bd_res) {
- printf("failed to malloc thread res memory!\n");
- return -ENOMEM;
- }
-
- for (i = 0; i < g_thread_num; i++) {
- g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue));
- if (!g_thread_queue.bd_res[i].queue) {
- ret = -ENOMEM;
- goto free_mem;
- }
-
- g_thread_queue.bd_res[i].queue->capa.alg = options->algclass;
- /* nodemask need to be clean */
- g_thread_queue.bd_res[i].queue->node_mask = 0x0;
- memset(g_thread_queue.bd_res[i].queue->dev_path, 0x0, PATH_STR_SIZE);
- if (strlen(options->device) != 0) {
- ret = snprintf(g_thread_queue.bd_res[i].queue->dev_path,
- PATH_STR_SIZE, "%s", options->device);
- if (ret < 0) {
- WD_ERR("failed to copy dev file path!\n");
- return -WD_EINVAL;
- }
- }
-
- g_thread_queue.bd_res[i].in_bytes = options->pktlen;
- g_thread_queue.bd_res[i].out = malloc(options->pktlen);
- if (!g_thread_queue.bd_res[i].queue) {
- free(g_thread_queue.bd_res[i].queue);
- ret = -ENOMEM;
- goto free_mem;
- }
-
- ret = wd_request_queue(g_thread_queue.bd_res[i].queue);
- if (ret) {
- printf("failed to request queue %d, ret = %d!\n", i, ret);
- free(g_thread_queue.bd_res[i].out);
- free(g_thread_queue.bd_res[i].queue);
- goto free_mem;
- }
- }
-
- return 0;
-
-free_mem:
- for (i = i - 1; i >= 0; i--) {
- wd_release_queue(g_thread_queue.bd_res[i].queue);
- free(g_thread_queue.bd_res[i].out);
- free(g_thread_queue.bd_res[i].queue);
- }
-
- free(g_thread_queue.bd_res);
- return ret;
-}
-
-static void uninit_trng_wd_queue(void)
-{
- int j;
-
- for (j = 0; j < g_thread_num; j++) {
- wd_release_queue(g_thread_queue.bd_res[j].queue);
- free(g_thread_queue.bd_res[j].out);
- free(g_thread_queue.bd_res[j].queue);
- }
-
- free(g_thread_queue.bd_res);
-}
-
-static void *trng_wd_sync_run(void *arg)
-{
- struct wd_thread_res *pdata = (struct wd_thread_res *)arg;
- struct wcrypto_rng_ctx_setup trng_setup;
- struct wcrypto_rng_op_data opdata;
- struct wd_queue *queue;
- void *ctx = NULL;
- u32 count = 0;
- int ret;
-
- queue = g_thread_queue.bd_res[pdata->td_id].queue;
- ctx = wcrypto_create_rng_ctx(queue, &trng_setup);
- if (!ctx)
- return NULL;
-
- memset(&opdata, 0, sizeof(opdata));
- opdata.in_bytes = g_thread_queue.bd_res[pdata->td_id].in_bytes;
- opdata.out = g_thread_queue.bd_res[pdata->td_id].out;
- opdata.op_type = WCRYPTO_TRNG_GEN;
-
- do {
- ret = wcrypto_do_rng(ctx, &opdata, NULL);
- if (ret) {
- printf("failed to do rng task, ret: %d\n", ret);
- goto ctx_release;
- }
-
- count++;
- if (get_run_state() == 0)
- break;
- } while (true);
-
-ctx_release:
- wcrypto_del_rng_ctx(ctx);
- add_recv_data(count, opdata.in_bytes);
-
- return NULL;
-}
-
-static void trng_wd_sync_threads(void)
-{
- struct wd_thread_res threads_args[THREADS_NUM];
- pthread_t tdid[THREADS_NUM];
- int i, ret;
-
- for (i = 0; i < g_thread_num; i++) {
- threads_args[i].td_id = i;
- ret = pthread_create(&tdid[i], NULL, trng_wd_sync_run, &threads_args[i]);
- if (ret) {
- printf("failed to create sync thread!\n");
- return;
- }
- }
-
- /* join thread */
- for (i = 0; i < g_thread_num; i++) {
- ret = pthread_join(tdid[i], NULL);
- if (ret) {
- printf("failed to join sync thread!\n");
- return;
- }
- }
-}
-
-void *wd_trng_poll(void *data)
-{
- struct wd_thread_res *pdata = (struct wd_thread_res *)data;
- struct wd_queue *queue;
- u32 last_time = 2; // poll need one more recv time
- u32 count = 0;
- u32 in_bytes;
- int recv;
-
- in_bytes = g_thread_queue.bd_res[pdata->pollid].in_bytes;
- queue = g_thread_queue.bd_res[pdata->pollid].queue;
-
- while (last_time) {
- recv = wcrypto_rng_poll(queue, ACC_QUEUE_SIZE);
- if (recv < 0) {
- printf("failed to recv bd, ret: %d!\n", recv);
- goto recv_error;
- }
- count += recv;
-
- if (get_run_state() == 0)
- last_time--;
- }
-
-recv_error:
- add_recv_data(count, in_bytes);
-
- return NULL;
-}
-
-static void *trng_async_cb(const void *msg, void *tag)
-{
- return NULL;
-}
-
-static void *wd_trng_async_run(void *arg)
-{
- struct wd_thread_res *pdata = (struct wd_thread_res *)arg;
- struct wcrypto_rng_ctx_setup trng_setup;
- struct wcrypto_rng_op_data opdata;
- struct trng_async_tag *tag = NULL;
- struct wd_queue *queue;
- void *ctx = NULL;
- int ret, i;
-
- memset(&opdata, 0, sizeof(opdata));
-
- queue = g_thread_queue.bd_res[pdata->td_id].queue;
- trng_setup.cb = (void *)trng_async_cb;
-
- ctx = wcrypto_create_rng_ctx(queue, &trng_setup);
- if (!ctx)
- return NULL;
-
- opdata.in_bytes = g_thread_queue.bd_res[pdata->td_id].in_bytes;
- opdata.out = g_thread_queue.bd_res[pdata->td_id].out;
- opdata.op_type = WCRYPTO_TRNG_GEN;
-
- tag = malloc(sizeof(*tag) * MAX_POOL_LENTH);
- if (!tag) {
- printf("failed to malloc dh tag!\n");
- goto free_ctx;
- }
- tag->ctx = ctx;
-
- do {
- ret = wcrypto_do_rng(ctx, &opdata, tag);
- if (ret && ret != -WD_EBUSY) {
- printf("failed to send trng task, ret = %d!\n", ret);
- break;
- }
-
- if (get_run_state() == 0)
- break;
- } while (true);
-
- /* Release memory after all tasks are complete. */
- i = 0;
- while (get_recv_time() != g_thread_num) {
- if (i++ >= MAX_TRY_CNT) {
- printf("failed to wait poll thread finish!\n");
- break;
- }
-
- usleep(SEND_USLEEP);
- }
-
- if (tag)
- free(tag);
-free_ctx:
- wcrypto_del_rng_ctx(ctx);
- add_send_complete();
-
- return NULL;
-}
-
-static void trng_wd_async_threads(void)
-{
- struct wd_thread_res threads_args[THREADS_NUM];
- pthread_t tdid[THREADS_NUM];
- pthread_t pollid[THREADS_NUM];
- int i, ret;
-
- for (i = 0; i < g_thread_num; i++) {
- threads_args[i].pollid = i;
- /* poll thread */
- ret = pthread_create(&pollid[i], NULL, wd_trng_poll, &threads_args[i]);
- if (ret) {
- printf("failed to create poll thread!\n");
- return;
- }
- }
-
- for (i = 0; i < g_thread_num; i++) {
- threads_args[i].td_id = i;
- ret = pthread_create(&tdid[i], NULL, wd_trng_async_run, &threads_args[i]);
- if (ret) {
- printf("failed to create async thread!\n");
- return;
- }
- }
-
- /* join thread */
- for (i = 0; i < g_thread_num; i++) {
- ret = pthread_join(tdid[i], NULL);
- if (ret) {
- printf("failed to join async thread!\n");
- return;
- }
- }
-
- for (i = 0; i < g_thread_num; i++) {
- ret = pthread_join(pollid[i], NULL);
- if (ret) {
- printf("failed to join poll thread!\n");
- return;
- }
- }
-}
-
-int trng_wd_benchmark(struct acc_option *options)
-{
- u32 ptime;
- int ret;
-
- signal(SIGSEGV, segmentfault_handler);
- g_thread_num = options->threads;
-
- ret = init_trng_wd_queue(options);
- if (ret)
- return ret;
-
- get_pid_cpu_time(&ptime);
- time_start(options->times);
- if (options->syncmode)
- trng_wd_async_threads();
- else
- trng_wd_sync_threads();
- cal_perfermance_data(options, ptime);
-
- uninit_trng_wd_queue();
-
- return 0;
-}
diff --git a/uadk_tool/benchmark/trng_wd_benchmark.h b/uadk_tool/benchmark/trng_wd_benchmark.h
deleted file mode 100644
index 49453c8..0000000
--- a/uadk_tool/benchmark/trng_wd_benchmark.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: Apache-2.0 */
-
-#ifndef TRNG_WD_BENCHMARK_H
-#define TRNG_WD_BENCHMARK_H
-
-extern int trng_wd_benchmark(struct acc_option *options);
-#endif /* TRNG_WD_BENCHMARK_H */
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index fd64f6c..09e99e2 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -16,8 +16,6 @@
#include "zip_uadk_benchmark.h"
#include "zip_wd_benchmark.h"
-#include "trng_wd_benchmark.h"
-
#define TABLE_SPACE_SIZE 8
/*----------------------------------------head struct--------------------------------------------------------*/
@@ -157,7 +155,6 @@ static struct acc_alg_item alg_options[] = {
{"sha512", "sha512", SHA512_ALG},
{"sha512-224", "sha512-224", SHA512_224},
{"sha512-256", "sha512-256", SHA512_256},
- {"trng", "trng", TRNG},
{"", "", ALG_MAX}
};
@@ -463,11 +460,6 @@ static void parse_alg_param(struct acc_option *option)
option->acctype = HPRE_TYPE;
option->subtype = X448_TYPE;
break;
- case TRNG:
- snprintf(option->algclass, MAX_ALG_NAME, "%s", "trng");
- option->acctype = TRNG_TYPE;
- option->subtype = DEFAULT_TYPE;
- break;
default:
if (option->algtype <= RSA_4096_CRT) {
snprintf(option->algclass, MAX_ALG_NAME, "%s", "rsa");
@@ -596,13 +588,6 @@ static int benchmark_run(struct acc_option *option)
ret = zip_wd_benchmark(option);
}
break;
- case TRNG_TYPE:
- if (option->modetype == SVA_MODE)
- ACC_TST_PRT("TRNG not support sva mode..\n");
- else if (option->modetype == NOSVA_MODE)
- ret = trng_wd_benchmark(option);
-
- break;
}
return ret;
diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h
index 9a0ad5e..83fd7fa 100644
--- a/uadk_tool/benchmark/uadk_benchmark.h
+++ b/uadk_tool/benchmark/uadk_benchmark.h
@@ -96,7 +96,6 @@ enum acc_type {
SEC_TYPE,
HPRE_TYPE,
ZIP_TYPE,
- TRNG_TYPE,
};
enum acc_init_type {
diff --git a/v1/drv/hisi_rng_udrv.c b/v1/drv/hisi_rng_udrv.c
deleted file mode 100644
index 605ef27..0000000
--- a/v1/drv/hisi_rng_udrv.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright 2018-2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <pthread.h>
-#include <sys/mman.h>
-#include <string.h>
-#include <stdint.h>
-#include <sys/epoll.h>
-#include <sys/eventfd.h>
-#include <sys/types.h>
-
-#include "hisi_rng_udrv.h"
-
-#define HISI_RNG_BYTES 4
-#define MAX_RETRY_COUNTS 8
-#define RNG_NUM_OFFSET 0x00F0
-
-int rng_init_queue(struct wd_queue *q)
-{
- struct q_info *qinfo = q->qinfo;
- struct rng_queue_info *info;
- int ret;
-
- info = calloc(1, sizeof(*info));
- if (!info) {
- WD_ERR("no mem!\n");
- return -ENOMEM;
- }
-
- ret = pthread_spin_init(&info->lock, PTHREAD_PROCESS_PRIVATE);
- if (ret) {
- free(info);
- WD_ERR("failed to init rng qinfo lock!\n");
- return ret;
- }
-
- qinfo->priv = info;
- info->mmio_base = wd_drv_mmap_qfr(q, WD_UACCE_QFRT_MMIO, 0);
- if (info->mmio_base == MAP_FAILED) {
- info->mmio_base = NULL;
- qinfo->priv = NULL;
- pthread_spin_destroy(&info->lock);
- free(info);
- WD_ERR("mmap trng mmio fail\n");
- return -ENOMEM;
- }
-
- return 0;
-}
-
-void rng_uninit_queue(struct wd_queue *q)
-{
- struct q_info *qinfo = q->qinfo;
- struct rng_queue_info *info = qinfo->priv;
-
- wd_drv_unmmap_qfr(q, info->mmio_base, WD_UACCE_QFRT_MMIO, 0);
-
- free(qinfo->priv);
- qinfo->priv = NULL;
- pthread_spin_destroy(&info->lock);
-}
-
-int rng_send(struct wd_queue *q, void **req, __u32 num)
-{
- struct q_info *qinfo = q->qinfo;
- struct rng_queue_info *info = qinfo->priv;
-
- pthread_spin_lock(&info->lock);
- if (!info->req_cache[info->send_idx]) {
- info->req_cache[info->send_idx] = req[0];
- info->send_idx++;
- pthread_spin_unlock(&info->lock);
- return 0;
- }
- pthread_spin_unlock(&info->lock);
-
- WD_ERR("queue is full!\n");
- return -WD_EBUSY;
-}
-
-static int rng_read(struct rng_queue_info *info, struct wcrypto_rng_msg *msg)
-{
- __u32 max = msg->in_bytes;
- __u32 currsize = 0;
- int recv_count = 0;
- __u32 val;
-
- do {
- val = wd_reg_read((void *)((uintptr_t)info->mmio_base +
- RNG_NUM_OFFSET));
- if (!val) {
- if (++recv_count > MAX_RETRY_COUNTS) {
- WD_ERR("read random data timeout\n");
- break;
- }
-
- usleep(1);
- continue;
- }
-
- recv_count = 0;
- if (max - currsize >= HISI_RNG_BYTES) {
- memcpy(msg->out + currsize, &val, HISI_RNG_BYTES);
- currsize += HISI_RNG_BYTES;
- if (currsize == max)
- break;
- continue;
- }
-
- memcpy(msg->out + currsize, &val, max - currsize);
- currsize = max;
- } while (currsize < max);
-
- return currsize;
-}
-
-int rng_recv(struct wd_queue *q, void **resp, __u32 num)
-{
- struct q_info *qinfo = q->qinfo;
- struct rng_queue_info *info = qinfo->priv;
- __u16 usr = (__u16)(uintptr_t)*resp;
- struct wcrypto_rng_msg *msg;
- struct wcrypto_cb_tag *tag;
- __u32 currsize = 0;
-
- pthread_spin_lock(&info->lock);
- msg = info->req_cache[info->recv_idx];
- if (!msg) {
- pthread_spin_unlock(&info->lock);
- return 0;
- }
-
- info->req_cache[info->recv_idx] = NULL;
- info->recv_idx++;
- pthread_spin_unlock(&info->lock);
-
- tag = (void *)(uintptr_t)msg->usr_tag;
- if (usr && tag->ctx_id != usr)
- return 0;
-
- currsize = rng_read(info, msg);
- if (!currsize) {
- WD_ERR("random data err!\n");
- return -WD_EINVAL;
- }
-
- msg->out_bytes = currsize;
- *resp = msg;
-
- return 1;
-}
diff --git a/v1/drv/hisi_rng_udrv.h b/v1/drv/hisi_rng_udrv.h
deleted file mode 100644
index 3efa10e..0000000
--- a/v1/drv/hisi_rng_udrv.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2018-2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __HISI_RNG_UDRV_H__
-#define __HISI_RNG_UDRV_H__
-
-#include <linux/types.h>
-#include "v1/wd.h"
-#include "v1/wd_util.h"
-#include "v1/wd_rng.h"
-
-#define TRNG_Q_DEPTH 256
-
-struct rng_queue_info {
- void *mmio_base;
- void *req_cache[TRNG_Q_DEPTH];
- __u8 send_idx;
- __u8 recv_idx;
- pthread_spinlock_t lock;
-};
-
-int rng_init_queue(struct wd_queue *q);
-void rng_uninit_queue(struct wd_queue *q);
-int rng_send(struct wd_queue *q, void **req, __u32 num);
-int rng_recv(struct wd_queue *q, void **resp, __u32 num);
-
-#endif
diff --git a/v1/libwd.map b/v1/libwd.map
index d53201b..6c54479 100644
--- a/v1/libwd.map
+++ b/v1/libwd.map
@@ -133,11 +133,6 @@ global:
wcrypto_rsa_poll;
wcrypto_del_rsa_ctx;
- wcrypto_create_rng_ctx;
- wcrypto_del_rng_ctx;
- wcrypto_do_rng;
- wcrypto_rng_poll;
-
wd_sglpool_create;
wd_sglpool_destroy;
wd_alloc_sgl;
diff --git a/v1/test/Makefile.am b/v1/test/Makefile.am
index bd41cfe..6cbf79f 100644
--- a/v1/test/Makefile.am
+++ b/v1/test/Makefile.am
@@ -7,7 +7,6 @@ SUBDIRS+=hisi_zip_test
endif
SUBDIRS+=hisi_zip_test_sgl
-SUBDIRS+=hisi_trng_test
if HAVE_CRYPTO
SUBDIRS+=hisi_hpre_test
diff --git a/v1/test/hisi_trng_test/Makefile.am b/v1/test/hisi_trng_test/Makefile.am
deleted file mode 100644
index b561585..0000000
--- a/v1/test/hisi_trng_test/Makefile.am
+++ /dev/null
@@ -1,20 +0,0 @@
-AM_CFLAGS=-Wall -Werror -O0 -fno-strict-aliasing -I$(top_srcdir)/include -I$(srcdir) -pthread
-
-if HAVE_CRYPTO
-bin_PROGRAMS=test_hisi_trngu_v1 test_hisi_trngk_v1 test_hisi_trngp_v1
-
-test_hisi_trngu_v1_SOURCES=test_hisi_trngu.c
-test_hisi_trngk_v1_SOURCES=test_hisi_trngk.c
-test_hisi_trngp_v1_SOURCES=test_hisi_trngp.c
-
-if WD_STATIC_DRV
-test_hisi_trngu_v1_LDADD=../../../.libs/libwd.la
-test_hisi_trngk_v1_LDADD=../../../.libs/libwd.la
-test_hisi_trngp_v1_LDADD=../../../.libs/libwd.la
-else
-test_hisi_trngu_v1_LDADD=../../../.libs/libwd.so
-test_hisi_trngk_v1_LDADD=../../../.libs/libwd.so
-test_hisi_trngp_v1_LDADD=../../../.libs/libwd.so
-endif
-
-endif
diff --git a/v1/test/hisi_trng_test/test_hisi_trngk.c b/v1/test/hisi_trng_test/test_hisi_trngk.c
deleted file mode 100755
index ae719e5..0000000
--- a/v1/test/hisi_trng_test/test_hisi_trngk.c
+++ /dev/null
@@ -1,155 +0,0 @@
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#define __USE_GNU
-#include <sched.h>
-#include <pthread.h>
-#include <sys/mman.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <semaphore.h>
-
-
-struct thread_info
-{
- pthread_t thread_id;
- unsigned int size;
- unsigned int num;
- int addr;
-
-};
-
-void *trng_thread(void *args)
-{
-
- int fd = -1;
- int fd_w = -1;
- int ret;
- unsigned int input;
- struct thread_info *tinfo = args;
- input = tinfo->size;
- unsigned int *data = (unsigned int*)malloc(sizeof(unsigned int) * input);
-
- if(!data)
- return NULL;
-
- if (tinfo->addr == 0){
-
-// printf("Now try to get %d bytes random number from /dev/hwrng.\n", input * 4);
- fd = open ("/dev/hwrng", O_RDONLY);
- }
- else if (tinfo->addr == 1){
-// printf("Now try to get %d bytes random number from /dev/random.\n", input * 4);
- fd = open ("/dev/random", O_RDONLY);
- }
-
- if (fd <0 ) {
- printf("can not open\n");
- return NULL;
- }
-
- fd_w = open ("/root/trng_file", O_WRONLY|O_CREAT|O_APPEND,0777);
- if (fd_w <0 ) {
- printf("can not open trng_file\n");
- return NULL;
- }
- memset(data, 0, sizeof(int) * input);
- ret = read(fd, data, input);
- if (ret < 0) {
- printf("read error %d\n", ret);
- return NULL;
- }
- ret =write(fd_w,data,input);
- if (ret < 0) {
- printf("write error %d\n", ret);
- return NULL;
- }
-
- close(fd);
- close(fd_w);
-
- return NULL;
-}
-
-
-void trng_test(int addr,int num,unsigned int si,int thread_num)
-{
-
- int i;
- void *ret = NULL;
- struct thread_info *tinfo;
- tinfo = calloc(thread_num, sizeof(struct thread_info));
-
- if (tinfo == NULL)
- {
- printf("calloc fail...\n");
- return;
- }
-
- for (i = 0; i<thread_num; ++i)
- {
- tinfo[i].thread_id = i;
- tinfo[i].addr = addr;
- tinfo[i].num = num;
- tinfo[i].size = si;
-
- if ((pthread_create(&tinfo[i].thread_id,NULL,trng_thread, (void *)&tinfo[i])) != 0)
- {
- return;
- }
- }
-
- for (i=0; i<thread_num; ++i)
- {
- if (pthread_join(tinfo[i].thread_id, &ret) != 0)
- {
- printf("thread is not exit....\n");
- return;
- }
- //printf("thread exit coid %d\n", (int *)ret);
- free(ret);
- }
- free(tinfo);
-}
-
-
-
-
-int main (int argc, char* argv[]) {
-
- int opt;
- int addr = 0, num = 0, thread_num = 0;
- unsigned int si = 0;
-
- while ((opt = getopt(argc, argv, "hri:p:s:")) != -1) {
- switch (opt) {
- case 'h':
- addr = 0;
- break;
- case 'r':
- addr = 1;
- break;
- case 'i':
- num = atoi(optarg);
- break;
- case 'p':
- thread_num = atoi(optarg);
- break;
- case 's':
- si = (unsigned int)atoi(optarg);
- break;
- default:
- break;
- }
- }
-
- trng_test(addr,num,si,thread_num);
-
- return 0;
-}
diff --git a/v1/test/hisi_trng_test/test_hisi_trngp.c b/v1/test/hisi_trng_test/test_hisi_trngp.c
deleted file mode 100644
index 2330b1e..0000000
--- a/v1/test/hisi_trng_test/test_hisi_trngp.c
+++ /dev/null
@@ -1,137 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <pthread.h>
-#include <unistd.h>
-
-static int input;
-static int thread_num;
-struct thread_info
-{
- pthread_t thread_id;
- unsigned int size;
- int num;
-};
-
-void *trng_thread(void *args)
-{
- int j;
- int fd = -1;
- int data;
- int ret;
- struct thread_info *tinfo = args;
- int si;
- int num;
- int size;
- int fd_w = -1;
- si = tinfo->size;
- num = tinfo->num;
- size=si/num;
- printf("Now try to get bytes random number from /dev/random.\n");
- fd = open("/dev/random", O_RDONLY);
- if (fd <0 ) {
- printf("can not open\n");
- return NULL;
- }
- for (j = 0; j< size; j++) {
- ret = read(fd, &data, 1);
- if (ret < 0) {
- printf("read error %d\n", ret);
- return NULL;
- }
-// else if (ret < 1)
-// goto rd_ag;
-// if (!data) {
-// printf("read data error!\n");
-// return data;
-// }
- printf("the read num:%x\n",data);
- }
- fd_w = open ("/root/trng_file", O_RDWR | O_CREAT |O_APPEND , 0777);
- if (fd_w <0 ) {
- printf("can not open trng_file\n");
- return NULL;
- }
- ret = write(fd_w,&data,size);
- if (ret < 0) {
- printf("write error %d\n", ret);
- return NULL;
- }
- close(fd);
- close(fd_w);
- return NULL;
-}
-
-void trng_test(int input,int thread_num)
-{
- int i;
- void *ret = NULL;
- struct thread_info *tinfo;
- tinfo = calloc(thread_num, sizeof(struct thread_info));
- if(tinfo == NULL)
- {
- printf("calloc fail...\n");
- return;
- }
- for(i = 0; i<thread_num; ++i)
- {
- tinfo[i].thread_id = i;
- tinfo[i].num=thread_num;
-// tinfo[i].addr = addr;
-// tinfo[i].num = num;
- tinfo[i].size = input;
- if((pthread_create(&tinfo[i].thread_id,NULL,trng_thread, (void *)&tinfo[i])) != 0)
- {
- return;
- }
- }
-
- for(i=0; i<thread_num; ++i)
- {
- if(pthread_join(tinfo[i].thread_id, &ret) != 0)
- {
- printf("thread is not exit....\n");
- return;
- }
-// printf("thread exit coid %d\n", (int *)ret);
- free(ret);
- }
- free(tinfo);
-}
-
-int main (int argc, char* argv[])
-{
- struct timeval start_tval, end_tval;
- float time,speed;
- int fd_f=-1;
- fd_f = open ("/root/trng_file", O_RDWR | O_CREAT |O_TRUNC, 0777);
- if (fd_f <0 ) {
- printf("can not open trng_file\n");
- return fd_f;
- }
- input = strtoul(argv[1], NULL, 10);
- if (input <= 0){
- printf("input error!\n");
- return -1;
- }
- thread_num = strtoul((char *)argv[2], NULL, 10);
- if (thread_num <= 0 || thread_num > 128) {
- printf("Invalid threads num:%d!\n",thread_num);
- printf("Now set threads num as 2\n");
- thread_num = 2;
- }
- gettimeofday(&start_tval, NULL);
- trng_test(input,thread_num);
- gettimeofday(&end_tval, NULL);
- time = (float)((end_tval.tv_sec - start_tval.tv_sec) * 1000000 +
- (end_tval.tv_usec - start_tval.tv_usec));
- speed = input/(time / 1000000);
- printf("read random speed: %0.0f time\n", time);
- printf("read random speed: %0.0f bytes/s\n", speed);
- close(fd_f);
- return 0;
-}
diff --git a/v1/test/hisi_trng_test/test_hisi_trngu.c b/v1/test/hisi_trng_test/test_hisi_trngu.c
deleted file mode 100755
index 86aa8a9..0000000
--- a/v1/test/hisi_trng_test/test_hisi_trngu.c
+++ /dev/null
@@ -1,624 +0,0 @@
-/*
- * Copyright 2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#define __USE_GNU
-#include <sched.h>
-#include <pthread.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/syscall.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <semaphore.h>
-
-#include "../../wd.h"
-#include "../../wd_rng.h"
-
-#define RNG_TST_PRT printf
-#define BN_ULONG unsigned long
-#define TEST_MAX_THRD 128
-#define MAX_TRY_TIMES 10000
-#define LOG_INTVL_NUM 8
-#define TEST_CNT 10
-
-static int q_num = 1;
-static int ctx_num_per_q = 1;
-
-enum alg_op_type {
- TRNG_GEN,
- TRNG_AGEN,
-};
-
-struct trng_user_tag_info {
- int pid;
- int thread_id;
-};
-
-struct test_trng_pthread_dt {
- int cpu_id;
- int thread_num;
- void *q;
-};
-
-static struct test_trng_pthread_dt test_thrds_data[TEST_MAX_THRD];
-static pthread_t system_test_thrds[TEST_MAX_THRD];
-static unsigned int g_input;
-
-
-static inline int _get_cpu_id(int thr, __u64 core_mask)
-{
- __u64 i;
- int cnt = 0;
-
- for (i = 1; i < 64; i++) {
- if (core_mask & (0x1ull << i)) {
- if (thr == cnt)
- return i;
- cnt++;
- }
- }
-
- return 0;
-}
-
-static inline int _get_one_bits(__u64 val)
-{
- int count = 0;
-
- while (val) {
- if (val % 2 == 1)
- count++;
- val = val / 2;
- }
-
- return count;
-}
-
-void *_trng_sys_test_thread(void *data)
-{
- int ret, cpuid, i = 0;
- struct test_trng_pthread_dt *pdata = data;
- struct wcrypto_rng_ctx_setup setup;
- struct wcrypto_rng_op_data opdata;
- int pid = getpid();
- int thread_id = (int)syscall(__NR_gettid);
- struct wd_queue *q;
- int *out_data;
- void *ctx = NULL;
- void *tag = NULL;
-
- cpu_set_t mask;
- CPU_ZERO(&mask);
- cpuid = pdata->cpu_id;
- q = pdata->q;
- CPU_SET(cpuid, &mask);
-
- if (cpuid) {
- ret = pthread_setaffinity_np(pthread_self(),
- sizeof(mask), &mask);
- if (ret < 0) {
- RNG_TST_PRT("Proc-%d, thrd-%d:set affinity fail!\n",
- pid, thread_id);
- return NULL;
- }
- RNG_TST_PRT("Proc-%d, thrd-%d bind to cpu-%d!\n",
- pid, thread_id, cpuid);
- }
-
- memset(&setup, 0, sizeof(setup));
- memset(&opdata, 0, sizeof(opdata));
- ctx = wcrypto_create_rng_ctx(q, &setup);
- if (!ctx) {
- RNG_TST_PRT("Proc-%d, %d-TD:create %s ctx fail!\n",
- pid, thread_id, q->capa.alg);
- ret = -EINVAL;
- goto fail_release;
- }
-
- out_data = malloc(g_input);
- if(!out_data) {
- RNG_TST_PRT("malloc out_data memory fail!\n");
- }
- RNG_TST_PRT("request queue fail5!\n");
-
- while (1) {
- opdata.in_bytes = g_input;
- opdata.out = out_data;
- ret = wcrypto_do_rng(ctx, &opdata, tag);
- if (ret < 0) {
- RNG_TST_PRT("Proc-%d, T-%d:trng %d fail!\n", pid, thread_id, i);
- goto fail_release;
- }
- RNG_TST_PRT("the read data size %d!\n", opdata.out_bytes);
- i++;
- }
-fail_release:
- if (opdata.out)
- free(opdata.out);
- if (ctx)
- wcrypto_del_rng_ctx(ctx);
- return NULL;
-}
-
-
-static int trng_sys_test(int thread_num, __u64 lcore_mask,
- __u64 hcore_mask)
-{
- int i, ret, cnt = 0, j;
- struct wd_queue *q;
- int h_cpuid, qidx;
-
- q = malloc(q_num * sizeof(struct wd_queue));
- if (!q) {
- RNG_TST_PRT("malloc q memory fail!\n");
- return -ENOMEM;
- }
- memset(q, 0, q_num * sizeof(struct wd_queue));
-
- for (j = 0; j < q_num; j++) {
- q[j].capa.alg = "trng";
- ret = wd_request_queue(&q[j]);
- if (ret) {
- RNG_TST_PRT("request queue %d fail!\n", j);
- return ret;
- }
- }
- RNG_TST_PRT("request queue fail!\n");
- if (_get_one_bits(lcore_mask) > 0)
- cnt = _get_one_bits(lcore_mask);
- else if (_get_one_bits(lcore_mask) == 0 &&
- _get_one_bits(hcore_mask) == 0)
- cnt = thread_num;
-
- for (i = 0; i < cnt; i++) {
- qidx = i / ctx_num_per_q;
- test_thrds_data[i].q = &q[qidx];
- test_thrds_data[i].thread_num = thread_num;
- test_thrds_data[i].cpu_id = _get_cpu_id(i, lcore_mask);
- ret = pthread_create(&system_test_thrds[i], NULL,
- _trng_sys_test_thread, &test_thrds_data[i]);
- if (ret) {
- RNG_TST_PRT("Create %dth thread fail!\n", i);
- return ret;
- }
- }
- RNG_TST_PRT("request queue fail2!\n");
- for (i = 0; i < thread_num - cnt; i++) {
- h_cpuid = _get_cpu_id(i, hcore_mask);
- if (h_cpuid > 0)
- h_cpuid += 64;
-
- qidx = (i + cnt) / ctx_num_per_q;
- test_thrds_data[i + cnt].q = &q[qidx];
- test_thrds_data[i + cnt].thread_num = thread_num;
- test_thrds_data[i + cnt].cpu_id = h_cpuid;
- ret = pthread_create(&system_test_thrds[i + cnt], NULL,
- _trng_sys_test_thread, &test_thrds_data[i + cnt]);
- if (ret) {
- RNG_TST_PRT("Create %dth thread fail!\n", i);
- return ret;
- }
- }
- RNG_TST_PRT("request queue fail3!\n");
- for (i = 0; i < thread_num; i++) {
- ret = pthread_join(system_test_thrds[i], NULL);
- if (ret) {
- RNG_TST_PRT("Join %dth thread fail!\n", i);
- return ret;
- }
- }
- free(q);
- return 0;
-}
-
-
-static void _trng_cb(const void *message, void *tag)
-{
- const struct wcrypto_rng_msg *msg = message;
- struct trng_user_tag_info* pSwData = (struct trng_user_tag_info*)tag;
- struct wcrypto_rng_op_data opdata;
- int pid, threadId;
-
- if (NULL == pSwData) {
- RNG_TST_PRT("pSwData NULL!\n");
- return;
- }
- memset(&opdata, 0, sizeof(opdata));
-
- opdata.out = (void *)msg->out;
- opdata.out_bytes = msg->out_bytes;
- pid = pSwData->pid;
- threadId = pSwData->thread_id;
- RNG_TST_PRT("Proc-%d, %d-TD trng\n", pid, threadId);
- RNG_TST_PRT("the random number size :%d\n", opdata.out_bytes);
-
- if (opdata.out)
- free(opdata.out);
-
- if (pSwData)
- free(pSwData);
-}
-
-static void *_trng_asys_test_thread(void *data)
-{
- int ret, cpuid;
- struct test_trng_pthread_dt *pdata = data;
- struct wd_queue *q = NULL;
- cpu_set_t mask;
- struct wcrypto_rng_ctx_setup setup;
- struct wcrypto_rng_ctx *ctx = NULL;
- struct trng_user_tag_info *tag = NULL;
- struct wcrypto_rng_op_data opdata;
- int pid = getpid();
- int thread_id = (int)syscall(__NR_gettid);
- int *out_data;
- int i = 0;
-
- CPU_ZERO(&mask);
- cpuid = pdata->cpu_id;
- q = (struct wd_queue *)pdata->q;
- CPU_SET(cpuid, &mask);
-
- if (!q) {
- RNG_TST_PRT("q null!\n");
- return NULL;
- }
- if (cpuid) {
- ret = pthread_setaffinity_np(pthread_self(),
- sizeof(mask), &mask);
- if (ret < 0) {
- RNG_TST_PRT("Proc-%d, thrd-%d:set affinity fail!\n",
- pid, thread_id);
- return NULL;
- }
- RNG_TST_PRT("Proc-%d, thrd-%d bind to cpu-%d!\n",
- pid, thread_id, cpuid);
- }
-
- q->capa.alg = "trng";
- memset(&setup, 0, sizeof(setup));
- memset(&opdata, 0, sizeof(opdata));
- setup.cb = _trng_cb;
- ctx = wcrypto_create_rng_ctx(q, &setup);
- if (!ctx) {
- RNG_TST_PRT("Proc-%d, %d-TD:create %s ctx fail!\n",
- pid, thread_id, q->capa.alg);
- goto fail_release;
- }
-
- while(1) {
- tag = malloc(sizeof(struct trng_user_tag_info));
- if (!tag) {
- RNG_TST_PRT("malloc tag fail!\n");
- goto fail_release;
- }
-
- tag->pid = pid;
- tag->thread_id = thread_id;
-
- out_data = malloc(g_input);
- if(!out_data) {
- RNG_TST_PRT("malloc fail\n");
- return 0;
- }
-
- opdata.in_bytes = g_input;
- opdata.out = out_data;
- try_again:
- ret = wcrypto_do_rng(ctx, &opdata, tag);
- if (ret == -WD_EBUSY) {
- usleep(100);
- goto try_again;
- } else if(ret) {
- RNG_TST_PRT("Proc-%d, T-%d:trng %d fail!\n", pid, thread_id, i);
- goto fail_release;
- }
- i++;
- }
-fail_release:
- wcrypto_del_rng_ctx(ctx);
- return NULL;
-}
-
-static void* _trng_async_poll_test_thread(void *data)
-{
- struct test_trng_pthread_dt *pdata = data;
- struct wd_queue *q = pdata->q;
- int ret, cpuid;
- int pid = getpid();
- cpu_set_t mask;
- int thread_id = (int)syscall(__NR_gettid);
-
- CPU_ZERO(&mask);
- cpuid = pdata->cpu_id;
- CPU_SET(cpuid, &mask);
- if (cpuid) {
- ret = pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask);
- if (ret < 0) {
- RNG_TST_PRT("Proc-%d, thrd-%d:set affinity fail!\n",
- pid, thread_id);
- return NULL;
- }
- RNG_TST_PRT("Proc-%d, poll thrd-%d bind to cpu-%d!\n",
- pid, thread_id, cpuid);
- }
-
- while (1) {
- ret = wcrypto_rng_poll(q, 1);
- if (ret < 0) {
- break;
- }
- }
-
- return NULL;
-}
-
-static int trng_asys_test(int thread_num, __u64 lcore_mask, __u64 hcore_mask)
-{
- int i, ret, cnt = 0;
- struct wd_queue q;
- int h_cpuid;
-
- memset(&q, 0, sizeof(q));
-
- q.capa.alg = "trng";
- ret = wd_request_queue(&q);
- if (ret) {
- RNG_TST_PRT("request queue fail!\n");
- return ret;
- }
-
- if (_get_one_bits(lcore_mask) > 0)
- cnt = _get_one_bits(lcore_mask);
- else if (_get_one_bits(lcore_mask) == 0 &&
- _get_one_bits(hcore_mask) == 0)
- cnt = thread_num;
-
- test_thrds_data[0].q= &q;
- test_thrds_data[0].thread_num = 1;
- test_thrds_data[0].cpu_id = _get_cpu_id(0, lcore_mask);
- ret = pthread_create(&system_test_thrds[0], NULL,
- _trng_async_poll_test_thread, &test_thrds_data[0]);
- if (ret) {
- RNG_TST_PRT("Create poll thread fail!\n");
- return ret;
- }
-
- for (i = 1; i <= cnt; i++) {
- test_thrds_data[i].q = &q;
- test_thrds_data[i].thread_num = thread_num;
- test_thrds_data[i].cpu_id = _get_cpu_id(i, lcore_mask);
- ret = pthread_create(&system_test_thrds[i], NULL,
- _trng_asys_test_thread, &test_thrds_data[i]);
- if (ret) {
- RNG_TST_PRT("Create %dth thread fail!\n", i);
- return ret;
- }
- }
-
- for (i = 1; i <= thread_num - cnt; i++) {
- h_cpuid = _get_cpu_id(i, hcore_mask);
- if (h_cpuid > 0)
- h_cpuid += 64;
- test_thrds_data[i + cnt].q = &q;
- test_thrds_data[i + cnt].thread_num = thread_num;
- test_thrds_data[i + cnt].cpu_id = h_cpuid;
- ret = pthread_create(&system_test_thrds[i + cnt], NULL,
- _trng_asys_test_thread, &test_thrds_data[i + cnt]);
- if (ret) {
- RNG_TST_PRT("Create %dth thread fail!\n", i);
- return ret;
- }
- }
-
- for (i = 0; i < thread_num; i++) {
- ret = pthread_join(system_test_thrds[i], NULL);
- if (ret) {
- RNG_TST_PRT("Join %dth thread fail!\n", i);
- return ret;
- }
- }
-
- wd_release_queue(&q);
- return 0;
-
-}
-int main(int argc, char *argv[])
-{
- struct wcrypto_rng_ctx *ctx;
- struct wcrypto_rng_op_data opdata;
- struct wcrypto_rng_ctx_setup setup;
- enum alg_op_type alg_op_type = TRNG_GEN;
- int thread_num, bits;
- __u64 core_mask[2];
- struct wd_queue q;
- void *tag = NULL;
- int *data;
- int ret;
- int fd = -1;
- int fd_w = -1;
- if (!argv[1]) {
- RNG_TST_PRT("pls printf the size of the random data!\n");
- return -WD_EINVAL;
- }
- g_input = (unsigned int)strtoul(argv[1], NULL, 10);
- printf("g_input:%d\n",g_input);
- //if (g_input <= 0){
- // printf("input error!\n");
- // return -WD_EINVAL;
- //}
- if (argv[2]) {
- if(!strcmp(argv[2], "-system-gen")) {
- alg_op_type = TRNG_GEN;
- RNG_TST_PRT("Now doing system random number gen test!\n");
- } else if(!strcmp(argv[2], "-system-agen")) {
- alg_op_type = TRNG_AGEN;
- RNG_TST_PRT("Now doing system random number agen test!\n");
- }
-
- thread_num = strtoul((char *)argv[3], NULL, 10);
- if (thread_num <= 0 || thread_num > TEST_MAX_THRD) {
- RNG_TST_PRT("Invalid threads num:%d!\n",
- thread_num);
- RNG_TST_PRT("Now set threads num as 2\n");
- thread_num = 2;
- }
-
- if (strcmp(argv[4], "-c")) {
- RNG_TST_PRT("./test_hisi_trng --help get details\n");
- return -EINVAL;
- }
- if (argv[5][0] != '0' || argv[5][1] != 'x') {
- RNG_TST_PRT("Err:coremask should be hex!\n");
- return -EINVAL;
- }
-
- if (strlen(argv[5]) > 34) {
- RNG_TST_PRT("Warning: coremask is cut!\n");
- argv[5][34] = 0;
- }
-
- if (strlen(argv[5]) <= 18) {
- core_mask[0] = strtoull(argv[5], NULL, 16);
- if (core_mask[0] & 0x1) {
- RNG_TST_PRT("Warn:cannot bind to core 0,\n");
- RNG_TST_PRT("now run without binding\n");
- core_mask[0] = 0x0; /* no binding */
- }
- core_mask[1] = 0;
- } else {
- int offset = 0;
- char *temp;
-
- offset = strlen(argv[5]) - 16;
- core_mask[0] = strtoull(&argv[5][offset], NULL, 16);
- if (core_mask[0] & 0x1) {
- RNG_TST_PRT("Warn:cannot bind to core 0,\n");
- RNG_TST_PRT("now run without binding\n");
- core_mask[0] = 0x0; /* no binding */
- }
- temp = malloc(64);
- strcpy(temp, argv[5]);
- temp[offset] = 0;
- core_mask[1] = strtoull(temp, NULL, 16);
- free(temp);
- }
-
- bits = _get_one_bits(core_mask[0]);
- bits += _get_one_bits(core_mask[1]);
- if (thread_num > bits) {
- RNG_TST_PRT("Coremask not covers all thrds,\n");
- RNG_TST_PRT("Bind first %d thrds!\n", bits);
- } else if (thread_num < bits) {
- RNG_TST_PRT("Coremask overflow,\n");
- RNG_TST_PRT("Just try to bind all thrds!\n");
- }
-
- if (argv[6]) {
- ctx_num_per_q = strtoul(argv[6], NULL, 10);
- if (ctx_num_per_q <= 0) {
- RNG_TST_PRT("Invalid ctx num per queue:%s!\n",
- argv[6]);
- RNG_TST_PRT("Now ctx num per queue is set as 1!\n");
- ctx_num_per_q = 1;
- }
- } else {
- RNG_TST_PRT("Now ctx num per queue is set as 1!\n");
- ctx_num_per_q = 1;
- }
-
- q_num = (thread_num - 1) / ctx_num_per_q + 1;
-
- RNG_TST_PRT("Proc-%d: starts %d threads bind to %s\n",
- getpid(), thread_num, argv[5]);
- RNG_TST_PRT(" lcoremask=0x%llx, hcoremask=0x%llx\n",
- core_mask[0], core_mask[1]);
- if(alg_op_type == TRNG_GEN)
- return trng_sys_test(thread_num, core_mask[0],
- core_mask[1]);
-
- return trng_asys_test(thread_num, core_mask[0],
- core_mask[1]);
- }
-
- RNG_TST_PRT("Now try to get %d bytes random number.\n", g_input);
-
- data = malloc(g_input);
- if (!data) {
- RNG_TST_PRT("malloc data failed.\n");
- return -1;
- }
-
- memset((void *)&q, 0, sizeof(q));
- memset(&setup, 0, sizeof(setup));
- memset(&opdata, 0, sizeof(opdata));
-
- q.capa.alg = "trng";
- ret = wd_request_queue(&q);
- if (ret) {
- RNG_TST_PRT("request queue fail!\n");
- return ret;
- }
- ctx = wcrypto_create_rng_ctx(&q, &setup);
- if (!ctx) {
- ret = -ENOMEM;
- RNG_TST_PRT("create trng ctx fail!\n");
- goto release_q;
- }
-
- opdata.in_bytes = g_input;
- opdata.out = data;
- ret = wcrypto_do_rng(ctx, &opdata, tag);
- if (ret != 1) {
- RNG_TST_PRT("a wd_do_trng fail!\n");
- goto del_ctx;
- }
-
- RNG_TST_PRT("random_data size= %d.\n", opdata.out_bytes);
- fd_w = open ("/root/trng_file", O_RDWR|O_CREAT|O_TRUNC,0777);
- if (fd_w <0 ) {
- printf("can not open trng_file\n");
- return fd_w;
- }
- /*fd = open ("/dev/random", O_RDONLY);
- if (fd <0 ) {
- printf("can not open\n");
- return fd;
- }*/
- /*ret = read(fd, data, g_input);
- if (ret < 0) {
- printf("read error %d\n", ret);
- return ret;
- }*/
- ret = write(fd_w,opdata.out,opdata.out_bytes);
- if (ret < 0) {
- printf("write error %d\n", ret);
- return ret;
- }
- close(fd);
- close(fd_w);
-del_ctx:
- wcrypto_del_rng_ctx(ctx);
-
-release_q:
- wd_release_queue(&q);
- free(data);
- return ret;
-}
diff --git a/v1/wd.h b/v1/wd.h
index 0132e25..35dcf31 100644
--- a/v1/wd.h
+++ b/v1/wd.h
@@ -184,7 +184,7 @@ struct wd_capa {
* Other capabilities.
* 0~15 bits: number of cookies that the user wants to allocate.
* Optional, user can set value based on the number of requests and system memory,
- * 1~1024 is valid. If the value is not set or invalid, the default value 64 (rng is 256)
+ * 1~1024 is valid. If the value is not set or invalid, the default value 64
* is used to initialize cookies.
*/
__u32 flags;
diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c
index 1c9f656..df5368d 100644
--- a/v1/wd_adapter.c
+++ b/v1/wd_adapter.c
@@ -20,7 +20,6 @@
#include "v1/wd_util.h"
#include "v1/drv/hisi_qm_udrv.h"
-#include "v1/drv/hisi_rng_udrv.h"
#include "v1/wd_adapter.h"
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
@@ -87,12 +86,6 @@ static const struct wd_drv_dio_if hw_dio_tbl[] = { {
.init_sgl = qm_init_hwsgl_mem,
.uninit_sgl = qm_uninit_hwsgl_mem,
.sgl_merge = qm_merge_hwsgl,
- }, {
- .hw_type = "hisi-trng-v2",
- .open = rng_init_queue,
- .close = rng_uninit_queue,
- .send = rng_send,
- .recv = rng_recv,
},
};
diff --git a/v1/wd_rng.c b/v1/wd_rng.c
deleted file mode 100644
index 7a89cd1..0000000
--- a/v1/wd_rng.c
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright 2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <sys/mman.h>
-
-#include "wd.h"
-#include "wd_util.h"
-#include "wd_rng.h"
-
-#define RNG_RESEND_CNT 8
-#define RNG_RECV_CNT 8
-#define WD_RNG_CTX_COOKIE_NUM 256
-
-struct wcrypto_rng_cookie {
- struct wcrypto_cb_tag tag;
- struct wcrypto_rng_msg msg;
-};
-
-struct wcrypto_rng_ctx {
- struct wd_cookie_pool pool;
- unsigned long ctx_id;
- struct wd_queue *q;
- struct wcrypto_rng_ctx_setup setup;
-};
-
-static int wcrypto_setup_qinfo(struct wcrypto_rng_ctx_setup *setup,
- struct wd_queue *q, __u32 *ctx_id)
-{
- struct q_info *qinfo;
- int ret = -WD_EINVAL;
-
- if (!q || !q->qinfo || !setup) {
- WD_ERR("input parameter err!\n");
- return ret;
- }
-
- if (strcmp(q->capa.alg, "trng")) {
- WD_ERR("algorithm mismatch!\n");
- return ret;
- }
- qinfo = q->qinfo;
- /* lock at ctx creating */
- wd_spinlock(&qinfo->qlock);
- if (qinfo->ctx_num >= WD_MAX_CTX_NUM) {
- WD_ERR("create too many trng ctx!\n");
- goto unlock;
- }
-
- ret = wd_alloc_id(qinfo->ctx_id, WD_MAX_CTX_NUM, ctx_id, 0,
- WD_MAX_CTX_NUM);
- if (ret) {
- WD_ERR("err: alloc ctx id fail!\n");
- goto unlock;
- }
- qinfo->ctx_num++;
- ret = WD_SUCCESS;
-unlock:
- wd_unspinlock(&qinfo->qlock);
- return ret;
-}
-
-void *wcrypto_create_rng_ctx(struct wd_queue *q,
- struct wcrypto_rng_ctx_setup *setup)
-{
- struct wcrypto_rng_cookie *cookie;
- struct wcrypto_rng_ctx *ctx;
- struct q_info *qinfo;
- __u32 cookies_num, i;
- __u32 ctx_id = 0;
- int ret;
-
- if (wcrypto_setup_qinfo(setup, q, &ctx_id))
- return NULL;
-
- ctx = calloc(1, sizeof(struct wcrypto_rng_ctx));
- if (!ctx) {
- WD_ERR("alloc ctx memory fail!\n");
- goto free_ctx_id;
- }
- memcpy(&ctx->setup, setup, sizeof(*setup));
- ctx->q = q;
- ctx->ctx_id = ctx_id + 1;
-
- cookies_num = wd_get_ctx_cookies_num(q->capa.flags, WD_RNG_CTX_COOKIE_NUM);
- ret = wd_init_cookie_pool(&ctx->pool,
- sizeof(struct wcrypto_rng_cookie), cookies_num);
- if (ret) {
- WD_ERR("fail to init cookie pool!\n");
- free(ctx);
- goto free_ctx_id;
- }
- for (i = 0; i < cookies_num; i++) {
- cookie = (void *)((uintptr_t)ctx->pool.cookies +
- i * ctx->pool.cookies_size);
- cookie->msg.alg_type = WCRYPTO_RNG;
- cookie->tag.ctx = ctx;
- cookie->tag.ctx_id = ctx->ctx_id;
- cookie->msg.usr_tag = (uintptr_t)&cookie->tag;
- }
-
- return ctx;
-
-free_ctx_id:
- qinfo = q->qinfo;
- wd_spinlock(&qinfo->qlock);
- qinfo->ctx_num--;
- wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, ctx_id, WD_MAX_CTX_NUM);
- wd_unspinlock(&qinfo->qlock);
-
- return NULL;
-}
-
-void wcrypto_del_rng_ctx(void *ctx)
-{
- struct wcrypto_rng_ctx *cx;
- struct q_info *qinfo;
-
- if (!ctx) {
- WD_ERR("delete trng ctx is NULL!\n");
- return;
- }
-
- cx = ctx;
- qinfo = cx->q->qinfo;
-
- wd_uninit_cookie_pool(&cx->pool);
- wd_spinlock(&qinfo->qlock);
- if (qinfo->ctx_num <= 0) {
- wd_unspinlock(&qinfo->qlock);
- WD_ERR("repeat delete trng ctx!\n");
- return;
- }
- qinfo->ctx_num--;
- wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, cx->ctx_id - 1,
- WD_MAX_CTX_NUM);
- wd_unspinlock(&qinfo->qlock);
-
- free(ctx);
-}
-
-int wcrypto_rng_poll(struct wd_queue *q, unsigned int num)
-{
- struct wcrypto_rng_msg *resp = NULL;
- struct wcrypto_rng_ctx *ctx;
- struct wcrypto_cb_tag *tag;
- unsigned int tmp = num;
- int count = 0;
- int ret;
-
- if (!q) {
- WD_ERR("%s(): input parameter err!\n", __func__);
- return -WD_EINVAL;
- }
-
- do {
- ret = wd_recv(q, (void **)&resp);
- if (!ret)
- break;
-
- if (ret < 0) {
- WD_ERR("recv err at trng poll!\n");
- return ret;
- }
-
- count++;
- tag = (void *)(uintptr_t)resp->usr_tag;
- ctx = tag->ctx;
- ctx->setup.cb(resp, tag->tag);
- wd_put_cookies(&ctx->pool, (void **)&tag, 1);
- resp = NULL;
- } while (--tmp);
-
- return count;
-}
-
-static int wcrypto_do_prepare(struct wcrypto_rng_cookie **cookie_addr,
- struct wcrypto_rng_op_data *opdata,
- struct wcrypto_rng_msg **req_addr,
- struct wcrypto_rng_ctx *ctxt,
- void *tag)
-{
- struct wcrypto_rng_cookie *cookie;
- struct wcrypto_rng_msg *req;
- int ret;
-
- if (unlikely(!ctxt || !opdata)) {
- WD_ERR("invalid: rng input parameter err!\n");
- return -WD_EINVAL;
- }
-
- if (unlikely((opdata->in_bytes && !opdata->out))) {
- WD_ERR("invalid: dst addr is NULL when in_bytes is non-zero!!\n");
- return -WD_EINVAL;
- }
-
- ret = wd_get_cookies(&ctxt->pool, (void **)&cookie, 1);
- if (ret)
- return ret;
-
- if (tag) {
- if (!ctxt->setup.cb) {
- WD_ERR("invalid: ctx call back is null!\n");
- wd_put_cookies(&ctxt->pool, (void **)&cookie, 1);
- return -WD_EINVAL;
- }
- cookie->tag.tag = tag;
- }
-
- req = &cookie->msg;
- req->in_bytes = opdata->in_bytes;
- req->out = opdata->out;
- *cookie_addr = cookie;
- *req_addr = req;
-
- return 0;
-}
-
-int wcrypto_do_rng(void *ctx, struct wcrypto_rng_op_data *opdata, void *tag)
-{
- struct wcrypto_rng_ctx *ctxt = ctx;
- struct wcrypto_rng_cookie *cookie;
- struct wcrypto_rng_msg *req;
- struct wcrypto_rng_msg *resp;
- uint32_t tx_cnt = 0;
- uint32_t rx_cnt = 0;
- int ret = 0;
-
- ret = wcrypto_do_prepare(&cookie, opdata, &req, ctxt, tag);
- if (ret)
- return ret;
-
- do {
- ret = wd_send(ctxt->q, req);
- if (!ret) {
- break;
- } else if (ret == -WD_EBUSY) {
- if (++tx_cnt > RNG_RESEND_CNT) {
- WD_ERR("do trng send cnt %u, exit!\n", tx_cnt);
- goto fail_with_cookie;
- }
-
- usleep(1);
- } else {
- WD_ERR("do rng wd_send err!\n");
- goto fail_with_cookie;
- }
- } while (true);
-
- if (tag)
- return ret;
-
- resp = (void *)(uintptr_t)ctxt->ctx_id;
-
- do {
- ret = wd_recv(ctxt->q, (void **)&resp);
- if (ret > 0) {
- break;
- } else if (!ret) {
- if (++rx_cnt > RNG_RECV_CNT) {
- WD_ERR("do trng recv cnt %u, exit!\n", rx_cnt);
- ret = -WD_ETIMEDOUT;
- goto fail_with_cookie;
- }
-
- usleep(1);
- } else {
- WD_ERR("do trng recv err!\n");
- goto fail_with_cookie;
- }
- } while (true);
-
- opdata->out_bytes = resp->out_bytes;
- ret = WD_SUCCESS;
-fail_with_cookie:
- wd_put_cookies(&ctxt->pool, (void **)&cookie, 1);
- return ret;
-}
diff --git a/v1/wd_rng.h b/v1/wd_rng.h
deleted file mode 100644
index fcde26d..0000000
--- a/v1/wd_rng.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __WD_RNG_H
-#define __WD_RNG_H
-
-#include "wd.h"
-#include "wd_digest.h"
-#include "wd_cipher.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct wcrypto_rng_ctx_setup {
- wcrypto_cb cb;
- __u16 data_fmt; /* Data format, denoted by enum wd_buff_type */
- enum wcrypto_type type; /* Please refer to the definition of enum */
- enum wcrypto_cipher_alg calg; /* DRBG cipher algorithm */
- enum wcrypto_cipher_mode cmode; /* DRBG cipher mode */
- enum wcrypto_digest_alg dalg; /* DRBG digest algorithm */
- enum wcrypto_digest_mode dmode; /* DRBG digest mode */
-};
-
-struct wcrypto_rng_msg {
- __u8 alg_type; /* Denoted by enum wcrypto_type */
- __u8 op_type; /* Denoted by enum wcrypto_rng_op_type */
- __u8 data_fmt; /* Data format, denoted by enum wd_buff_type */
- __u8 result; /* Data format, denoted by WD error code */
- __u8 *out; /* Result address */
- __u8 *in; /* Input address */
- __u32 out_bytes; /* output bytes */
- __u32 in_bytes; /* input bytes */
- __u64 usr_tag; /* user identifier */
-};
-
-enum wcrypto_rng_op_type {
- WCRYPTO_RNG_INVALID, /* Invalid RNG operational type */
- WCRYPTO_DRBG_RESEED, /* seed operation */
- WCRYPTO_DRBG_GEN, /* deterministic random number generation */
- WCRYPTO_TRNG_GEN, /* true random number generation */
-};
-
-struct wcrypto_rng_op_data {
- enum wcrypto_rng_op_type op_type;
- __u32 status; /* Operation result status */
- void *in; /* input */
- void *out; /* output */
- __u32 in_bytes; /* input bytes */
- __u32 out_bytes; /* output bytes */
-};
-
-void *wcrypto_create_rng_ctx(struct wd_queue *q,
- struct wcrypto_rng_ctx_setup *setup);
-void wcrypto_del_rng_ctx(void *ctx);
-int wcrypto_do_rng(void *ctx, struct wcrypto_rng_op_data *opdata, void *tag);
-int wcrypto_rng_poll(struct wd_queue *q, unsigned int num);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
--
2.33.0
1
0
From: Weili Qian <qianweili(a)huawei.com>
The trng module is not required. Therefore, remove the trng module code.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
Makefile.am | 6 +-
configure.ac | 1 -
uadk_tool/Makefile.am | 1 -
uadk_tool/benchmark/trng_wd_benchmark.c | 333 ------------
uadk_tool/benchmark/trng_wd_benchmark.h | 7 -
uadk_tool/benchmark/uadk_benchmark.c | 15 -
uadk_tool/benchmark/uadk_benchmark.h | 1 -
v1/drv/hisi_rng_udrv.c | 167 ------
v1/drv/hisi_rng_udrv.h | 40 --
v1/libwd.map | 5 -
v1/test/Makefile.am | 1 -
v1/test/hisi_trng_test/Makefile.am | 20 -
v1/test/hisi_trng_test/test_hisi_trngk.c | 155 ------
v1/test/hisi_trng_test/test_hisi_trngp.c | 137 -----
v1/test/hisi_trng_test/test_hisi_trngu.c | 624 -----------------------
v1/wd.h | 2 +-
v1/wd_adapter.c | 7 -
v1/wd_rng.c | 296 -----------
v1/wd_rng.h | 76 ---
19 files changed, 3 insertions(+), 1891 deletions(-)
delete mode 100644 uadk_tool/benchmark/trng_wd_benchmark.c
delete mode 100644 uadk_tool/benchmark/trng_wd_benchmark.h
delete mode 100644 v1/drv/hisi_rng_udrv.c
delete mode 100644 v1/drv/hisi_rng_udrv.h
delete mode 100644 v1/test/hisi_trng_test/Makefile.am
delete mode 100755 v1/test/hisi_trng_test/test_hisi_trngk.c
delete mode 100644 v1/test/hisi_trng_test/test_hisi_trngp.c
delete mode 100755 v1/test/hisi_trng_test/test_hisi_trngu.c
delete mode 100644 v1/wd_rng.c
delete mode 100644 v1/wd_rng.h
diff --git a/Makefile.am b/Makefile.am
index d1a5953..7749613 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,9 +49,8 @@ uadk_driversdir=$(libdir)/uadk
uadk_drivers_LTLIBRARIES=libhisi_sec.la libhisi_hpre.la libhisi_zip.la \
libisa_ce.la libisa_sve.la libhisi_dae.la libhisi_udma.la
-libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \
+libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \
v1/wd.c v1/wd.h v1/wd_adapter.c v1/wd_adapter.h \
- v1/wd_rng.c v1/wd_rng.h \
v1/wd_rsa.c v1/wd_rsa.h \
v1/wd_aead.c v1/wd_aead.h \
v1/wd_dh.c v1/wd_dh.h \
@@ -68,8 +67,7 @@ libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \
v1/drv/hisi_zip_udrv.c v1/drv/hisi_zip_udrv.h \
v1/drv/hisi_zip_huf.c v1/drv/hisi_zip_huf.h \
v1/drv/hisi_hpre_udrv.c v1/drv/hisi_hpre_udrv.h \
- v1/drv/hisi_sec_udrv.c v1/drv/hisi_sec_udrv.h \
- v1/drv/hisi_rng_udrv.c v1/drv/hisi_rng_udrv.h
+ v1/drv/hisi_sec_udrv.c v1/drv/hisi_sec_udrv.h
libwd_udma_la_SOURCES=wd_udma.h wd_udma_drv.h wd_udma.c \
wd_util.c wd_util.h wd_sched.c wd_sched.h wd.c wd.h
diff --git a/configure.ac b/configure.ac
index 95c9f67..eb5a211 100644
--- a/configure.ac
+++ b/configure.ac
@@ -109,7 +109,6 @@ AC_CONFIG_FILES([Makefile
v1/test/bmm_test/Makefile
v1/test/test_mm/Makefile
v1/test/hisi_hpre_test/Makefile
- v1/test/hisi_trng_test/Makefile
v1/test/hisi_sec_test/Makefile
v1/test/hisi_sec_test_sgl/Makefile
v1/test/hisi_zip_test/Makefile
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
index 86b3064..9a1703d 100644
--- a/uadk_tool/Makefile.am
+++ b/uadk_tool/Makefile.am
@@ -17,7 +17,6 @@ uadk_tool_SOURCES=uadk_tool.c dfx/uadk_dfx.c dfx/uadk_dfx.h \
benchmark/hpre_wd_benchmark.c hpre_wd_benchmark.h \
benchmark/zip_uadk_benchmark.c benchmark/zip_uadk_benchmark.h \
benchmark/zip_wd_benchmark.c benchmark/zip_wd_benchmark.h \
- benchmark/trng_wd_benchmark.c benchmark/trng_wd_benchmark.h \
test/uadk_test.c test/uadk_test.h \
test/test_sec.c test/test_sec.h test/sec_template_tv.h
diff --git a/uadk_tool/benchmark/trng_wd_benchmark.c b/uadk_tool/benchmark/trng_wd_benchmark.c
deleted file mode 100644
index 2f058d4..0000000
--- a/uadk_tool/benchmark/trng_wd_benchmark.c
+++ /dev/null
@@ -1,333 +0,0 @@
-/* SPDX-License-Identifier: Apache-2.0 */
-
-#include <numa.h>
-#include "uadk_benchmark.h"
-
-#include "trng_wd_benchmark.h"
-#include "v1/wd.h"
-#include "v1/wd_rng.h"
-
-struct thread_bd_res {
- struct wd_queue *queue;
- void *out;
- __u32 in_bytes;
-};
-
-struct thread_queue_res {
- struct thread_bd_res *bd_res;
-};
-
-struct wd_thread_res {
- u32 td_id;
- u32 pollid;
-};
-
-struct trng_async_tag {
- void *ctx;
- int optype;
-};
-
-static unsigned int g_thread_num;
-static struct thread_queue_res g_thread_queue;
-
-static int init_trng_wd_queue(struct acc_option *options)
-{
- int i, ret;
-
- g_thread_queue.bd_res = malloc(g_thread_num * sizeof(struct thread_bd_res));
- if (!g_thread_queue.bd_res) {
- printf("failed to malloc thread res memory!\n");
- return -ENOMEM;
- }
-
- for (i = 0; i < g_thread_num; i++) {
- g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue));
- if (!g_thread_queue.bd_res[i].queue) {
- ret = -ENOMEM;
- goto free_mem;
- }
-
- g_thread_queue.bd_res[i].queue->capa.alg = options->algclass;
- /* nodemask need to be clean */
- g_thread_queue.bd_res[i].queue->node_mask = 0x0;
- memset(g_thread_queue.bd_res[i].queue->dev_path, 0x0, PATH_STR_SIZE);
- if (strlen(options->device) != 0) {
- ret = snprintf(g_thread_queue.bd_res[i].queue->dev_path,
- PATH_STR_SIZE, "%s", options->device);
- if (ret < 0) {
- WD_ERR("failed to copy dev file path!\n");
- return -WD_EINVAL;
- }
- }
-
- g_thread_queue.bd_res[i].in_bytes = options->pktlen;
- g_thread_queue.bd_res[i].out = malloc(options->pktlen);
- if (!g_thread_queue.bd_res[i].queue) {
- free(g_thread_queue.bd_res[i].queue);
- ret = -ENOMEM;
- goto free_mem;
- }
-
- ret = wd_request_queue(g_thread_queue.bd_res[i].queue);
- if (ret) {
- printf("failed to request queue %d, ret = %d!\n", i, ret);
- free(g_thread_queue.bd_res[i].out);
- free(g_thread_queue.bd_res[i].queue);
- goto free_mem;
- }
- }
-
- return 0;
-
-free_mem:
- for (i = i - 1; i >= 0; i--) {
- wd_release_queue(g_thread_queue.bd_res[i].queue);
- free(g_thread_queue.bd_res[i].out);
- free(g_thread_queue.bd_res[i].queue);
- }
-
- free(g_thread_queue.bd_res);
- return ret;
-}
-
-static void uninit_trng_wd_queue(void)
-{
- int j;
-
- for (j = 0; j < g_thread_num; j++) {
- wd_release_queue(g_thread_queue.bd_res[j].queue);
- free(g_thread_queue.bd_res[j].out);
- free(g_thread_queue.bd_res[j].queue);
- }
-
- free(g_thread_queue.bd_res);
-}
-
-static void *trng_wd_sync_run(void *arg)
-{
- struct wd_thread_res *pdata = (struct wd_thread_res *)arg;
- struct wcrypto_rng_ctx_setup trng_setup;
- struct wcrypto_rng_op_data opdata;
- struct wd_queue *queue;
- void *ctx = NULL;
- u32 count = 0;
- int ret;
-
- queue = g_thread_queue.bd_res[pdata->td_id].queue;
- ctx = wcrypto_create_rng_ctx(queue, &trng_setup);
- if (!ctx)
- return NULL;
-
- memset(&opdata, 0, sizeof(opdata));
- opdata.in_bytes = g_thread_queue.bd_res[pdata->td_id].in_bytes;
- opdata.out = g_thread_queue.bd_res[pdata->td_id].out;
- opdata.op_type = WCRYPTO_TRNG_GEN;
-
- do {
- ret = wcrypto_do_rng(ctx, &opdata, NULL);
- if (ret) {
- printf("failed to do rng task, ret: %d\n", ret);
- goto ctx_release;
- }
-
- count++;
- if (get_run_state() == 0)
- break;
- } while (true);
-
-ctx_release:
- wcrypto_del_rng_ctx(ctx);
- add_recv_data(count, opdata.in_bytes);
-
- return NULL;
-}
-
-static void trng_wd_sync_threads(void)
-{
- struct wd_thread_res threads_args[THREADS_NUM];
- pthread_t tdid[THREADS_NUM];
- int i, ret;
-
- for (i = 0; i < g_thread_num; i++) {
- threads_args[i].td_id = i;
- ret = pthread_create(&tdid[i], NULL, trng_wd_sync_run, &threads_args[i]);
- if (ret) {
- printf("failed to create sync thread!\n");
- return;
- }
- }
-
- /* join thread */
- for (i = 0; i < g_thread_num; i++) {
- ret = pthread_join(tdid[i], NULL);
- if (ret) {
- printf("failed to join sync thread!\n");
- return;
- }
- }
-}
-
-void *wd_trng_poll(void *data)
-{
- struct wd_thread_res *pdata = (struct wd_thread_res *)data;
- struct wd_queue *queue;
- u32 last_time = 2; // poll need one more recv time
- u32 count = 0;
- u32 in_bytes;
- int recv;
-
- in_bytes = g_thread_queue.bd_res[pdata->pollid].in_bytes;
- queue = g_thread_queue.bd_res[pdata->pollid].queue;
-
- while (last_time) {
- recv = wcrypto_rng_poll(queue, ACC_QUEUE_SIZE);
- if (recv < 0) {
- printf("failed to recv bd, ret: %d!\n", recv);
- goto recv_error;
- }
- count += recv;
-
- if (get_run_state() == 0)
- last_time--;
- }
-
-recv_error:
- add_recv_data(count, in_bytes);
-
- return NULL;
-}
-
-static void *trng_async_cb(const void *msg, void *tag)
-{
- return NULL;
-}
-
-static void *wd_trng_async_run(void *arg)
-{
- struct wd_thread_res *pdata = (struct wd_thread_res *)arg;
- struct wcrypto_rng_ctx_setup trng_setup;
- struct wcrypto_rng_op_data opdata;
- struct trng_async_tag *tag = NULL;
- struct wd_queue *queue;
- void *ctx = NULL;
- int ret, i;
-
- memset(&opdata, 0, sizeof(opdata));
-
- queue = g_thread_queue.bd_res[pdata->td_id].queue;
- trng_setup.cb = (void *)trng_async_cb;
-
- ctx = wcrypto_create_rng_ctx(queue, &trng_setup);
- if (!ctx)
- return NULL;
-
- opdata.in_bytes = g_thread_queue.bd_res[pdata->td_id].in_bytes;
- opdata.out = g_thread_queue.bd_res[pdata->td_id].out;
- opdata.op_type = WCRYPTO_TRNG_GEN;
-
- tag = malloc(sizeof(*tag) * MAX_POOL_LENTH);
- if (!tag) {
- printf("failed to malloc dh tag!\n");
- goto free_ctx;
- }
- tag->ctx = ctx;
-
- do {
- ret = wcrypto_do_rng(ctx, &opdata, tag);
- if (ret && ret != -WD_EBUSY) {
- printf("failed to send trng task, ret = %d!\n", ret);
- break;
- }
-
- if (get_run_state() == 0)
- break;
- } while (true);
-
- /* Release memory after all tasks are complete. */
- i = 0;
- while (get_recv_time() != g_thread_num) {
- if (i++ >= MAX_TRY_CNT) {
- printf("failed to wait poll thread finish!\n");
- break;
- }
-
- usleep(SEND_USLEEP);
- }
-
- if (tag)
- free(tag);
-free_ctx:
- wcrypto_del_rng_ctx(ctx);
- add_send_complete();
-
- return NULL;
-}
-
-static void trng_wd_async_threads(void)
-{
- struct wd_thread_res threads_args[THREADS_NUM];
- pthread_t tdid[THREADS_NUM];
- pthread_t pollid[THREADS_NUM];
- int i, ret;
-
- for (i = 0; i < g_thread_num; i++) {
- threads_args[i].pollid = i;
- /* poll thread */
- ret = pthread_create(&pollid[i], NULL, wd_trng_poll, &threads_args[i]);
- if (ret) {
- printf("failed to create poll thread!\n");
- return;
- }
- }
-
- for (i = 0; i < g_thread_num; i++) {
- threads_args[i].td_id = i;
- ret = pthread_create(&tdid[i], NULL, wd_trng_async_run, &threads_args[i]);
- if (ret) {
- printf("failed to create async thread!\n");
- return;
- }
- }
-
- /* join thread */
- for (i = 0; i < g_thread_num; i++) {
- ret = pthread_join(tdid[i], NULL);
- if (ret) {
- printf("failed to join async thread!\n");
- return;
- }
- }
-
- for (i = 0; i < g_thread_num; i++) {
- ret = pthread_join(pollid[i], NULL);
- if (ret) {
- printf("failed to join poll thread!\n");
- return;
- }
- }
-}
-
-int trng_wd_benchmark(struct acc_option *options)
-{
- u32 ptime;
- int ret;
-
- signal(SIGSEGV, segmentfault_handler);
- g_thread_num = options->threads;
-
- ret = init_trng_wd_queue(options);
- if (ret)
- return ret;
-
- get_pid_cpu_time(&ptime);
- time_start(options->times);
- if (options->syncmode)
- trng_wd_async_threads();
- else
- trng_wd_sync_threads();
- cal_perfermance_data(options, ptime);
-
- uninit_trng_wd_queue();
-
- return 0;
-}
diff --git a/uadk_tool/benchmark/trng_wd_benchmark.h b/uadk_tool/benchmark/trng_wd_benchmark.h
deleted file mode 100644
index 49453c8..0000000
--- a/uadk_tool/benchmark/trng_wd_benchmark.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* SPDX-License-Identifier: Apache-2.0 */
-
-#ifndef TRNG_WD_BENCHMARK_H
-#define TRNG_WD_BENCHMARK_H
-
-extern int trng_wd_benchmark(struct acc_option *options);
-#endif /* TRNG_WD_BENCHMARK_H */
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c
index fd64f6c..09e99e2 100644
--- a/uadk_tool/benchmark/uadk_benchmark.c
+++ b/uadk_tool/benchmark/uadk_benchmark.c
@@ -16,8 +16,6 @@
#include "zip_uadk_benchmark.h"
#include "zip_wd_benchmark.h"
-#include "trng_wd_benchmark.h"
-
#define TABLE_SPACE_SIZE 8
/*----------------------------------------head struct--------------------------------------------------------*/
@@ -157,7 +155,6 @@ static struct acc_alg_item alg_options[] = {
{"sha512", "sha512", SHA512_ALG},
{"sha512-224", "sha512-224", SHA512_224},
{"sha512-256", "sha512-256", SHA512_256},
- {"trng", "trng", TRNG},
{"", "", ALG_MAX}
};
@@ -463,11 +460,6 @@ static void parse_alg_param(struct acc_option *option)
option->acctype = HPRE_TYPE;
option->subtype = X448_TYPE;
break;
- case TRNG:
- snprintf(option->algclass, MAX_ALG_NAME, "%s", "trng");
- option->acctype = TRNG_TYPE;
- option->subtype = DEFAULT_TYPE;
- break;
default:
if (option->algtype <= RSA_4096_CRT) {
snprintf(option->algclass, MAX_ALG_NAME, "%s", "rsa");
@@ -596,13 +588,6 @@ static int benchmark_run(struct acc_option *option)
ret = zip_wd_benchmark(option);
}
break;
- case TRNG_TYPE:
- if (option->modetype == SVA_MODE)
- ACC_TST_PRT("TRNG not support sva mode..\n");
- else if (option->modetype == NOSVA_MODE)
- ret = trng_wd_benchmark(option);
-
- break;
}
return ret;
diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h
index 9a0ad5e..83fd7fa 100644
--- a/uadk_tool/benchmark/uadk_benchmark.h
+++ b/uadk_tool/benchmark/uadk_benchmark.h
@@ -96,7 +96,6 @@ enum acc_type {
SEC_TYPE,
HPRE_TYPE,
ZIP_TYPE,
- TRNG_TYPE,
};
enum acc_init_type {
diff --git a/v1/drv/hisi_rng_udrv.c b/v1/drv/hisi_rng_udrv.c
deleted file mode 100644
index 605ef27..0000000
--- a/v1/drv/hisi_rng_udrv.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright 2018-2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <pthread.h>
-#include <sys/mman.h>
-#include <string.h>
-#include <stdint.h>
-#include <sys/epoll.h>
-#include <sys/eventfd.h>
-#include <sys/types.h>
-
-#include "hisi_rng_udrv.h"
-
-#define HISI_RNG_BYTES 4
-#define MAX_RETRY_COUNTS 8
-#define RNG_NUM_OFFSET 0x00F0
-
-int rng_init_queue(struct wd_queue *q)
-{
- struct q_info *qinfo = q->qinfo;
- struct rng_queue_info *info;
- int ret;
-
- info = calloc(1, sizeof(*info));
- if (!info) {
- WD_ERR("no mem!\n");
- return -ENOMEM;
- }
-
- ret = pthread_spin_init(&info->lock, PTHREAD_PROCESS_PRIVATE);
- if (ret) {
- free(info);
- WD_ERR("failed to init rng qinfo lock!\n");
- return ret;
- }
-
- qinfo->priv = info;
- info->mmio_base = wd_drv_mmap_qfr(q, WD_UACCE_QFRT_MMIO, 0);
- if (info->mmio_base == MAP_FAILED) {
- info->mmio_base = NULL;
- qinfo->priv = NULL;
- pthread_spin_destroy(&info->lock);
- free(info);
- WD_ERR("mmap trng mmio fail\n");
- return -ENOMEM;
- }
-
- return 0;
-}
-
-void rng_uninit_queue(struct wd_queue *q)
-{
- struct q_info *qinfo = q->qinfo;
- struct rng_queue_info *info = qinfo->priv;
-
- wd_drv_unmmap_qfr(q, info->mmio_base, WD_UACCE_QFRT_MMIO, 0);
-
- free(qinfo->priv);
- qinfo->priv = NULL;
- pthread_spin_destroy(&info->lock);
-}
-
-int rng_send(struct wd_queue *q, void **req, __u32 num)
-{
- struct q_info *qinfo = q->qinfo;
- struct rng_queue_info *info = qinfo->priv;
-
- pthread_spin_lock(&info->lock);
- if (!info->req_cache[info->send_idx]) {
- info->req_cache[info->send_idx] = req[0];
- info->send_idx++;
- pthread_spin_unlock(&info->lock);
- return 0;
- }
- pthread_spin_unlock(&info->lock);
-
- WD_ERR("queue is full!\n");
- return -WD_EBUSY;
-}
-
-static int rng_read(struct rng_queue_info *info, struct wcrypto_rng_msg *msg)
-{
- __u32 max = msg->in_bytes;
- __u32 currsize = 0;
- int recv_count = 0;
- __u32 val;
-
- do {
- val = wd_reg_read((void *)((uintptr_t)info->mmio_base +
- RNG_NUM_OFFSET));
- if (!val) {
- if (++recv_count > MAX_RETRY_COUNTS) {
- WD_ERR("read random data timeout\n");
- break;
- }
-
- usleep(1);
- continue;
- }
-
- recv_count = 0;
- if (max - currsize >= HISI_RNG_BYTES) {
- memcpy(msg->out + currsize, &val, HISI_RNG_BYTES);
- currsize += HISI_RNG_BYTES;
- if (currsize == max)
- break;
- continue;
- }
-
- memcpy(msg->out + currsize, &val, max - currsize);
- currsize = max;
- } while (currsize < max);
-
- return currsize;
-}
-
-int rng_recv(struct wd_queue *q, void **resp, __u32 num)
-{
- struct q_info *qinfo = q->qinfo;
- struct rng_queue_info *info = qinfo->priv;
- __u16 usr = (__u16)(uintptr_t)*resp;
- struct wcrypto_rng_msg *msg;
- struct wcrypto_cb_tag *tag;
- __u32 currsize = 0;
-
- pthread_spin_lock(&info->lock);
- msg = info->req_cache[info->recv_idx];
- if (!msg) {
- pthread_spin_unlock(&info->lock);
- return 0;
- }
-
- info->req_cache[info->recv_idx] = NULL;
- info->recv_idx++;
- pthread_spin_unlock(&info->lock);
-
- tag = (void *)(uintptr_t)msg->usr_tag;
- if (usr && tag->ctx_id != usr)
- return 0;
-
- currsize = rng_read(info, msg);
- if (!currsize) {
- WD_ERR("random data err!\n");
- return -WD_EINVAL;
- }
-
- msg->out_bytes = currsize;
- *resp = msg;
-
- return 1;
-}
diff --git a/v1/drv/hisi_rng_udrv.h b/v1/drv/hisi_rng_udrv.h
deleted file mode 100644
index 3efa10e..0000000
--- a/v1/drv/hisi_rng_udrv.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2018-2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __HISI_RNG_UDRV_H__
-#define __HISI_RNG_UDRV_H__
-
-#include <linux/types.h>
-#include "v1/wd.h"
-#include "v1/wd_util.h"
-#include "v1/wd_rng.h"
-
-#define TRNG_Q_DEPTH 256
-
-struct rng_queue_info {
- void *mmio_base;
- void *req_cache[TRNG_Q_DEPTH];
- __u8 send_idx;
- __u8 recv_idx;
- pthread_spinlock_t lock;
-};
-
-int rng_init_queue(struct wd_queue *q);
-void rng_uninit_queue(struct wd_queue *q);
-int rng_send(struct wd_queue *q, void **req, __u32 num);
-int rng_recv(struct wd_queue *q, void **resp, __u32 num);
-
-#endif
diff --git a/v1/libwd.map b/v1/libwd.map
index d53201b..6c54479 100644
--- a/v1/libwd.map
+++ b/v1/libwd.map
@@ -133,11 +133,6 @@ global:
wcrypto_rsa_poll;
wcrypto_del_rsa_ctx;
- wcrypto_create_rng_ctx;
- wcrypto_del_rng_ctx;
- wcrypto_do_rng;
- wcrypto_rng_poll;
-
wd_sglpool_create;
wd_sglpool_destroy;
wd_alloc_sgl;
diff --git a/v1/test/Makefile.am b/v1/test/Makefile.am
index bd41cfe..6cbf79f 100644
--- a/v1/test/Makefile.am
+++ b/v1/test/Makefile.am
@@ -7,7 +7,6 @@ SUBDIRS+=hisi_zip_test
endif
SUBDIRS+=hisi_zip_test_sgl
-SUBDIRS+=hisi_trng_test
if HAVE_CRYPTO
SUBDIRS+=hisi_hpre_test
diff --git a/v1/test/hisi_trng_test/Makefile.am b/v1/test/hisi_trng_test/Makefile.am
deleted file mode 100644
index b561585..0000000
--- a/v1/test/hisi_trng_test/Makefile.am
+++ /dev/null
@@ -1,20 +0,0 @@
-AM_CFLAGS=-Wall -Werror -O0 -fno-strict-aliasing -I$(top_srcdir)/include -I$(srcdir) -pthread
-
-if HAVE_CRYPTO
-bin_PROGRAMS=test_hisi_trngu_v1 test_hisi_trngk_v1 test_hisi_trngp_v1
-
-test_hisi_trngu_v1_SOURCES=test_hisi_trngu.c
-test_hisi_trngk_v1_SOURCES=test_hisi_trngk.c
-test_hisi_trngp_v1_SOURCES=test_hisi_trngp.c
-
-if WD_STATIC_DRV
-test_hisi_trngu_v1_LDADD=../../../.libs/libwd.la
-test_hisi_trngk_v1_LDADD=../../../.libs/libwd.la
-test_hisi_trngp_v1_LDADD=../../../.libs/libwd.la
-else
-test_hisi_trngu_v1_LDADD=../../../.libs/libwd.so
-test_hisi_trngk_v1_LDADD=../../../.libs/libwd.so
-test_hisi_trngp_v1_LDADD=../../../.libs/libwd.so
-endif
-
-endif
diff --git a/v1/test/hisi_trng_test/test_hisi_trngk.c b/v1/test/hisi_trng_test/test_hisi_trngk.c
deleted file mode 100755
index ae719e5..0000000
--- a/v1/test/hisi_trng_test/test_hisi_trngk.c
+++ /dev/null
@@ -1,155 +0,0 @@
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#define __USE_GNU
-#include <sched.h>
-#include <pthread.h>
-#include <sys/mman.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <semaphore.h>
-
-
-struct thread_info
-{
- pthread_t thread_id;
- unsigned int size;
- unsigned int num;
- int addr;
-
-};
-
-void *trng_thread(void *args)
-{
-
- int fd = -1;
- int fd_w = -1;
- int ret;
- unsigned int input;
- struct thread_info *tinfo = args;
- input = tinfo->size;
- unsigned int *data = (unsigned int*)malloc(sizeof(unsigned int) * input);
-
- if(!data)
- return NULL;
-
- if (tinfo->addr == 0){
-
-// printf("Now try to get %d bytes random number from /dev/hwrng.\n", input * 4);
- fd = open ("/dev/hwrng", O_RDONLY);
- }
- else if (tinfo->addr == 1){
-// printf("Now try to get %d bytes random number from /dev/random.\n", input * 4);
- fd = open ("/dev/random", O_RDONLY);
- }
-
- if (fd <0 ) {
- printf("can not open\n");
- return NULL;
- }
-
- fd_w = open ("/root/trng_file", O_WRONLY|O_CREAT|O_APPEND,0777);
- if (fd_w <0 ) {
- printf("can not open trng_file\n");
- return NULL;
- }
- memset(data, 0, sizeof(int) * input);
- ret = read(fd, data, input);
- if (ret < 0) {
- printf("read error %d\n", ret);
- return NULL;
- }
- ret =write(fd_w,data,input);
- if (ret < 0) {
- printf("write error %d\n", ret);
- return NULL;
- }
-
- close(fd);
- close(fd_w);
-
- return NULL;
-}
-
-
-void trng_test(int addr,int num,unsigned int si,int thread_num)
-{
-
- int i;
- void *ret = NULL;
- struct thread_info *tinfo;
- tinfo = calloc(thread_num, sizeof(struct thread_info));
-
- if (tinfo == NULL)
- {
- printf("calloc fail...\n");
- return;
- }
-
- for (i = 0; i<thread_num; ++i)
- {
- tinfo[i].thread_id = i;
- tinfo[i].addr = addr;
- tinfo[i].num = num;
- tinfo[i].size = si;
-
- if ((pthread_create(&tinfo[i].thread_id,NULL,trng_thread, (void *)&tinfo[i])) != 0)
- {
- return;
- }
- }
-
- for (i=0; i<thread_num; ++i)
- {
- if (pthread_join(tinfo[i].thread_id, &ret) != 0)
- {
- printf("thread is not exit....\n");
- return;
- }
- //printf("thread exit coid %d\n", (int *)ret);
- free(ret);
- }
- free(tinfo);
-}
-
-
-
-
-int main (int argc, char* argv[]) {
-
- int opt;
- int addr = 0, num = 0, thread_num = 0;
- unsigned int si = 0;
-
- while ((opt = getopt(argc, argv, "hri:p:s:")) != -1) {
- switch (opt) {
- case 'h':
- addr = 0;
- break;
- case 'r':
- addr = 1;
- break;
- case 'i':
- num = atoi(optarg);
- break;
- case 'p':
- thread_num = atoi(optarg);
- break;
- case 's':
- si = (unsigned int)atoi(optarg);
- break;
- default:
- break;
- }
- }
-
- trng_test(addr,num,si,thread_num);
-
- return 0;
-}
diff --git a/v1/test/hisi_trng_test/test_hisi_trngp.c b/v1/test/hisi_trng_test/test_hisi_trngp.c
deleted file mode 100644
index 2330b1e..0000000
--- a/v1/test/hisi_trng_test/test_hisi_trngp.c
+++ /dev/null
@@ -1,137 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <pthread.h>
-#include <unistd.h>
-
-static int input;
-static int thread_num;
-struct thread_info
-{
- pthread_t thread_id;
- unsigned int size;
- int num;
-};
-
-void *trng_thread(void *args)
-{
- int j;
- int fd = -1;
- int data;
- int ret;
- struct thread_info *tinfo = args;
- int si;
- int num;
- int size;
- int fd_w = -1;
- si = tinfo->size;
- num = tinfo->num;
- size=si/num;
- printf("Now try to get bytes random number from /dev/random.\n");
- fd = open("/dev/random", O_RDONLY);
- if (fd <0 ) {
- printf("can not open\n");
- return NULL;
- }
- for (j = 0; j< size; j++) {
- ret = read(fd, &data, 1);
- if (ret < 0) {
- printf("read error %d\n", ret);
- return NULL;
- }
-// else if (ret < 1)
-// goto rd_ag;
-// if (!data) {
-// printf("read data error!\n");
-// return data;
-// }
- printf("the read num:%x\n",data);
- }
- fd_w = open ("/root/trng_file", O_RDWR | O_CREAT |O_APPEND , 0777);
- if (fd_w <0 ) {
- printf("can not open trng_file\n");
- return NULL;
- }
- ret = write(fd_w,&data,size);
- if (ret < 0) {
- printf("write error %d\n", ret);
- return NULL;
- }
- close(fd);
- close(fd_w);
- return NULL;
-}
-
-void trng_test(int input,int thread_num)
-{
- int i;
- void *ret = NULL;
- struct thread_info *tinfo;
- tinfo = calloc(thread_num, sizeof(struct thread_info));
- if(tinfo == NULL)
- {
- printf("calloc fail...\n");
- return;
- }
- for(i = 0; i<thread_num; ++i)
- {
- tinfo[i].thread_id = i;
- tinfo[i].num=thread_num;
-// tinfo[i].addr = addr;
-// tinfo[i].num = num;
- tinfo[i].size = input;
- if((pthread_create(&tinfo[i].thread_id,NULL,trng_thread, (void *)&tinfo[i])) != 0)
- {
- return;
- }
- }
-
- for(i=0; i<thread_num; ++i)
- {
- if(pthread_join(tinfo[i].thread_id, &ret) != 0)
- {
- printf("thread is not exit....\n");
- return;
- }
-// printf("thread exit coid %d\n", (int *)ret);
- free(ret);
- }
- free(tinfo);
-}
-
-int main (int argc, char* argv[])
-{
- struct timeval start_tval, end_tval;
- float time,speed;
- int fd_f=-1;
- fd_f = open ("/root/trng_file", O_RDWR | O_CREAT |O_TRUNC, 0777);
- if (fd_f <0 ) {
- printf("can not open trng_file\n");
- return fd_f;
- }
- input = strtoul(argv[1], NULL, 10);
- if (input <= 0){
- printf("input error!\n");
- return -1;
- }
- thread_num = strtoul((char *)argv[2], NULL, 10);
- if (thread_num <= 0 || thread_num > 128) {
- printf("Invalid threads num:%d!\n",thread_num);
- printf("Now set threads num as 2\n");
- thread_num = 2;
- }
- gettimeofday(&start_tval, NULL);
- trng_test(input,thread_num);
- gettimeofday(&end_tval, NULL);
- time = (float)((end_tval.tv_sec - start_tval.tv_sec) * 1000000 +
- (end_tval.tv_usec - start_tval.tv_usec));
- speed = input/(time / 1000000);
- printf("read random speed: %0.0f time\n", time);
- printf("read random speed: %0.0f bytes/s\n", speed);
- close(fd_f);
- return 0;
-}
diff --git a/v1/test/hisi_trng_test/test_hisi_trngu.c b/v1/test/hisi_trng_test/test_hisi_trngu.c
deleted file mode 100755
index 86aa8a9..0000000
--- a/v1/test/hisi_trng_test/test_hisi_trngu.c
+++ /dev/null
@@ -1,624 +0,0 @@
-/*
- * Copyright 2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#define __USE_GNU
-#include <sched.h>
-#include <pthread.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/syscall.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <semaphore.h>
-
-#include "../../wd.h"
-#include "../../wd_rng.h"
-
-#define RNG_TST_PRT printf
-#define BN_ULONG unsigned long
-#define TEST_MAX_THRD 128
-#define MAX_TRY_TIMES 10000
-#define LOG_INTVL_NUM 8
-#define TEST_CNT 10
-
-static int q_num = 1;
-static int ctx_num_per_q = 1;
-
-enum alg_op_type {
- TRNG_GEN,
- TRNG_AGEN,
-};
-
-struct trng_user_tag_info {
- int pid;
- int thread_id;
-};
-
-struct test_trng_pthread_dt {
- int cpu_id;
- int thread_num;
- void *q;
-};
-
-static struct test_trng_pthread_dt test_thrds_data[TEST_MAX_THRD];
-static pthread_t system_test_thrds[TEST_MAX_THRD];
-static unsigned int g_input;
-
-
-static inline int _get_cpu_id(int thr, __u64 core_mask)
-{
- __u64 i;
- int cnt = 0;
-
- for (i = 1; i < 64; i++) {
- if (core_mask & (0x1ull << i)) {
- if (thr == cnt)
- return i;
- cnt++;
- }
- }
-
- return 0;
-}
-
-static inline int _get_one_bits(__u64 val)
-{
- int count = 0;
-
- while (val) {
- if (val % 2 == 1)
- count++;
- val = val / 2;
- }
-
- return count;
-}
-
-void *_trng_sys_test_thread(void *data)
-{
- int ret, cpuid, i = 0;
- struct test_trng_pthread_dt *pdata = data;
- struct wcrypto_rng_ctx_setup setup;
- struct wcrypto_rng_op_data opdata;
- int pid = getpid();
- int thread_id = (int)syscall(__NR_gettid);
- struct wd_queue *q;
- int *out_data;
- void *ctx = NULL;
- void *tag = NULL;
-
- cpu_set_t mask;
- CPU_ZERO(&mask);
- cpuid = pdata->cpu_id;
- q = pdata->q;
- CPU_SET(cpuid, &mask);
-
- if (cpuid) {
- ret = pthread_setaffinity_np(pthread_self(),
- sizeof(mask), &mask);
- if (ret < 0) {
- RNG_TST_PRT("Proc-%d, thrd-%d:set affinity fail!\n",
- pid, thread_id);
- return NULL;
- }
- RNG_TST_PRT("Proc-%d, thrd-%d bind to cpu-%d!\n",
- pid, thread_id, cpuid);
- }
-
- memset(&setup, 0, sizeof(setup));
- memset(&opdata, 0, sizeof(opdata));
- ctx = wcrypto_create_rng_ctx(q, &setup);
- if (!ctx) {
- RNG_TST_PRT("Proc-%d, %d-TD:create %s ctx fail!\n",
- pid, thread_id, q->capa.alg);
- ret = -EINVAL;
- goto fail_release;
- }
-
- out_data = malloc(g_input);
- if(!out_data) {
- RNG_TST_PRT("malloc out_data memory fail!\n");
- }
- RNG_TST_PRT("request queue fail5!\n");
-
- while (1) {
- opdata.in_bytes = g_input;
- opdata.out = out_data;
- ret = wcrypto_do_rng(ctx, &opdata, tag);
- if (ret < 0) {
- RNG_TST_PRT("Proc-%d, T-%d:trng %d fail!\n", pid, thread_id, i);
- goto fail_release;
- }
- RNG_TST_PRT("the read data size %d!\n", opdata.out_bytes);
- i++;
- }
-fail_release:
- if (opdata.out)
- free(opdata.out);
- if (ctx)
- wcrypto_del_rng_ctx(ctx);
- return NULL;
-}
-
-
-static int trng_sys_test(int thread_num, __u64 lcore_mask,
- __u64 hcore_mask)
-{
- int i, ret, cnt = 0, j;
- struct wd_queue *q;
- int h_cpuid, qidx;
-
- q = malloc(q_num * sizeof(struct wd_queue));
- if (!q) {
- RNG_TST_PRT("malloc q memory fail!\n");
- return -ENOMEM;
- }
- memset(q, 0, q_num * sizeof(struct wd_queue));
-
- for (j = 0; j < q_num; j++) {
- q[j].capa.alg = "trng";
- ret = wd_request_queue(&q[j]);
- if (ret) {
- RNG_TST_PRT("request queue %d fail!\n", j);
- return ret;
- }
- }
- RNG_TST_PRT("request queue fail!\n");
- if (_get_one_bits(lcore_mask) > 0)
- cnt = _get_one_bits(lcore_mask);
- else if (_get_one_bits(lcore_mask) == 0 &&
- _get_one_bits(hcore_mask) == 0)
- cnt = thread_num;
-
- for (i = 0; i < cnt; i++) {
- qidx = i / ctx_num_per_q;
- test_thrds_data[i].q = &q[qidx];
- test_thrds_data[i].thread_num = thread_num;
- test_thrds_data[i].cpu_id = _get_cpu_id(i, lcore_mask);
- ret = pthread_create(&system_test_thrds[i], NULL,
- _trng_sys_test_thread, &test_thrds_data[i]);
- if (ret) {
- RNG_TST_PRT("Create %dth thread fail!\n", i);
- return ret;
- }
- }
- RNG_TST_PRT("request queue fail2!\n");
- for (i = 0; i < thread_num - cnt; i++) {
- h_cpuid = _get_cpu_id(i, hcore_mask);
- if (h_cpuid > 0)
- h_cpuid += 64;
-
- qidx = (i + cnt) / ctx_num_per_q;
- test_thrds_data[i + cnt].q = &q[qidx];
- test_thrds_data[i + cnt].thread_num = thread_num;
- test_thrds_data[i + cnt].cpu_id = h_cpuid;
- ret = pthread_create(&system_test_thrds[i + cnt], NULL,
- _trng_sys_test_thread, &test_thrds_data[i + cnt]);
- if (ret) {
- RNG_TST_PRT("Create %dth thread fail!\n", i);
- return ret;
- }
- }
- RNG_TST_PRT("request queue fail3!\n");
- for (i = 0; i < thread_num; i++) {
- ret = pthread_join(system_test_thrds[i], NULL);
- if (ret) {
- RNG_TST_PRT("Join %dth thread fail!\n", i);
- return ret;
- }
- }
- free(q);
- return 0;
-}
-
-
-static void _trng_cb(const void *message, void *tag)
-{
- const struct wcrypto_rng_msg *msg = message;
- struct trng_user_tag_info* pSwData = (struct trng_user_tag_info*)tag;
- struct wcrypto_rng_op_data opdata;
- int pid, threadId;
-
- if (NULL == pSwData) {
- RNG_TST_PRT("pSwData NULL!\n");
- return;
- }
- memset(&opdata, 0, sizeof(opdata));
-
- opdata.out = (void *)msg->out;
- opdata.out_bytes = msg->out_bytes;
- pid = pSwData->pid;
- threadId = pSwData->thread_id;
- RNG_TST_PRT("Proc-%d, %d-TD trng\n", pid, threadId);
- RNG_TST_PRT("the random number size :%d\n", opdata.out_bytes);
-
- if (opdata.out)
- free(opdata.out);
-
- if (pSwData)
- free(pSwData);
-}
-
-static void *_trng_asys_test_thread(void *data)
-{
- int ret, cpuid;
- struct test_trng_pthread_dt *pdata = data;
- struct wd_queue *q = NULL;
- cpu_set_t mask;
- struct wcrypto_rng_ctx_setup setup;
- struct wcrypto_rng_ctx *ctx = NULL;
- struct trng_user_tag_info *tag = NULL;
- struct wcrypto_rng_op_data opdata;
- int pid = getpid();
- int thread_id = (int)syscall(__NR_gettid);
- int *out_data;
- int i = 0;
-
- CPU_ZERO(&mask);
- cpuid = pdata->cpu_id;
- q = (struct wd_queue *)pdata->q;
- CPU_SET(cpuid, &mask);
-
- if (!q) {
- RNG_TST_PRT("q null!\n");
- return NULL;
- }
- if (cpuid) {
- ret = pthread_setaffinity_np(pthread_self(),
- sizeof(mask), &mask);
- if (ret < 0) {
- RNG_TST_PRT("Proc-%d, thrd-%d:set affinity fail!\n",
- pid, thread_id);
- return NULL;
- }
- RNG_TST_PRT("Proc-%d, thrd-%d bind to cpu-%d!\n",
- pid, thread_id, cpuid);
- }
-
- q->capa.alg = "trng";
- memset(&setup, 0, sizeof(setup));
- memset(&opdata, 0, sizeof(opdata));
- setup.cb = _trng_cb;
- ctx = wcrypto_create_rng_ctx(q, &setup);
- if (!ctx) {
- RNG_TST_PRT("Proc-%d, %d-TD:create %s ctx fail!\n",
- pid, thread_id, q->capa.alg);
- goto fail_release;
- }
-
- while(1) {
- tag = malloc(sizeof(struct trng_user_tag_info));
- if (!tag) {
- RNG_TST_PRT("malloc tag fail!\n");
- goto fail_release;
- }
-
- tag->pid = pid;
- tag->thread_id = thread_id;
-
- out_data = malloc(g_input);
- if(!out_data) {
- RNG_TST_PRT("malloc fail\n");
- return 0;
- }
-
- opdata.in_bytes = g_input;
- opdata.out = out_data;
- try_again:
- ret = wcrypto_do_rng(ctx, &opdata, tag);
- if (ret == -WD_EBUSY) {
- usleep(100);
- goto try_again;
- } else if(ret) {
- RNG_TST_PRT("Proc-%d, T-%d:trng %d fail!\n", pid, thread_id, i);
- goto fail_release;
- }
- i++;
- }
-fail_release:
- wcrypto_del_rng_ctx(ctx);
- return NULL;
-}
-
-static void* _trng_async_poll_test_thread(void *data)
-{
- struct test_trng_pthread_dt *pdata = data;
- struct wd_queue *q = pdata->q;
- int ret, cpuid;
- int pid = getpid();
- cpu_set_t mask;
- int thread_id = (int)syscall(__NR_gettid);
-
- CPU_ZERO(&mask);
- cpuid = pdata->cpu_id;
- CPU_SET(cpuid, &mask);
- if (cpuid) {
- ret = pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask);
- if (ret < 0) {
- RNG_TST_PRT("Proc-%d, thrd-%d:set affinity fail!\n",
- pid, thread_id);
- return NULL;
- }
- RNG_TST_PRT("Proc-%d, poll thrd-%d bind to cpu-%d!\n",
- pid, thread_id, cpuid);
- }
-
- while (1) {
- ret = wcrypto_rng_poll(q, 1);
- if (ret < 0) {
- break;
- }
- }
-
- return NULL;
-}
-
-static int trng_asys_test(int thread_num, __u64 lcore_mask, __u64 hcore_mask)
-{
- int i, ret, cnt = 0;
- struct wd_queue q;
- int h_cpuid;
-
- memset(&q, 0, sizeof(q));
-
- q.capa.alg = "trng";
- ret = wd_request_queue(&q);
- if (ret) {
- RNG_TST_PRT("request queue fail!\n");
- return ret;
- }
-
- if (_get_one_bits(lcore_mask) > 0)
- cnt = _get_one_bits(lcore_mask);
- else if (_get_one_bits(lcore_mask) == 0 &&
- _get_one_bits(hcore_mask) == 0)
- cnt = thread_num;
-
- test_thrds_data[0].q= &q;
- test_thrds_data[0].thread_num = 1;
- test_thrds_data[0].cpu_id = _get_cpu_id(0, lcore_mask);
- ret = pthread_create(&system_test_thrds[0], NULL,
- _trng_async_poll_test_thread, &test_thrds_data[0]);
- if (ret) {
- RNG_TST_PRT("Create poll thread fail!\n");
- return ret;
- }
-
- for (i = 1; i <= cnt; i++) {
- test_thrds_data[i].q = &q;
- test_thrds_data[i].thread_num = thread_num;
- test_thrds_data[i].cpu_id = _get_cpu_id(i, lcore_mask);
- ret = pthread_create(&system_test_thrds[i], NULL,
- _trng_asys_test_thread, &test_thrds_data[i]);
- if (ret) {
- RNG_TST_PRT("Create %dth thread fail!\n", i);
- return ret;
- }
- }
-
- for (i = 1; i <= thread_num - cnt; i++) {
- h_cpuid = _get_cpu_id(i, hcore_mask);
- if (h_cpuid > 0)
- h_cpuid += 64;
- test_thrds_data[i + cnt].q = &q;
- test_thrds_data[i + cnt].thread_num = thread_num;
- test_thrds_data[i + cnt].cpu_id = h_cpuid;
- ret = pthread_create(&system_test_thrds[i + cnt], NULL,
- _trng_asys_test_thread, &test_thrds_data[i + cnt]);
- if (ret) {
- RNG_TST_PRT("Create %dth thread fail!\n", i);
- return ret;
- }
- }
-
- for (i = 0; i < thread_num; i++) {
- ret = pthread_join(system_test_thrds[i], NULL);
- if (ret) {
- RNG_TST_PRT("Join %dth thread fail!\n", i);
- return ret;
- }
- }
-
- wd_release_queue(&q);
- return 0;
-
-}
-int main(int argc, char *argv[])
-{
- struct wcrypto_rng_ctx *ctx;
- struct wcrypto_rng_op_data opdata;
- struct wcrypto_rng_ctx_setup setup;
- enum alg_op_type alg_op_type = TRNG_GEN;
- int thread_num, bits;
- __u64 core_mask[2];
- struct wd_queue q;
- void *tag = NULL;
- int *data;
- int ret;
- int fd = -1;
- int fd_w = -1;
- if (!argv[1]) {
- RNG_TST_PRT("pls printf the size of the random data!\n");
- return -WD_EINVAL;
- }
- g_input = (unsigned int)strtoul(argv[1], NULL, 10);
- printf("g_input:%d\n",g_input);
- //if (g_input <= 0){
- // printf("input error!\n");
- // return -WD_EINVAL;
- //}
- if (argv[2]) {
- if(!strcmp(argv[2], "-system-gen")) {
- alg_op_type = TRNG_GEN;
- RNG_TST_PRT("Now doing system random number gen test!\n");
- } else if(!strcmp(argv[2], "-system-agen")) {
- alg_op_type = TRNG_AGEN;
- RNG_TST_PRT("Now doing system random number agen test!\n");
- }
-
- thread_num = strtoul((char *)argv[3], NULL, 10);
- if (thread_num <= 0 || thread_num > TEST_MAX_THRD) {
- RNG_TST_PRT("Invalid threads num:%d!\n",
- thread_num);
- RNG_TST_PRT("Now set threads num as 2\n");
- thread_num = 2;
- }
-
- if (strcmp(argv[4], "-c")) {
- RNG_TST_PRT("./test_hisi_trng --help get details\n");
- return -EINVAL;
- }
- if (argv[5][0] != '0' || argv[5][1] != 'x') {
- RNG_TST_PRT("Err:coremask should be hex!\n");
- return -EINVAL;
- }
-
- if (strlen(argv[5]) > 34) {
- RNG_TST_PRT("Warning: coremask is cut!\n");
- argv[5][34] = 0;
- }
-
- if (strlen(argv[5]) <= 18) {
- core_mask[0] = strtoull(argv[5], NULL, 16);
- if (core_mask[0] & 0x1) {
- RNG_TST_PRT("Warn:cannot bind to core 0,\n");
- RNG_TST_PRT("now run without binding\n");
- core_mask[0] = 0x0; /* no binding */
- }
- core_mask[1] = 0;
- } else {
- int offset = 0;
- char *temp;
-
- offset = strlen(argv[5]) - 16;
- core_mask[0] = strtoull(&argv[5][offset], NULL, 16);
- if (core_mask[0] & 0x1) {
- RNG_TST_PRT("Warn:cannot bind to core 0,\n");
- RNG_TST_PRT("now run without binding\n");
- core_mask[0] = 0x0; /* no binding */
- }
- temp = malloc(64);
- strcpy(temp, argv[5]);
- temp[offset] = 0;
- core_mask[1] = strtoull(temp, NULL, 16);
- free(temp);
- }
-
- bits = _get_one_bits(core_mask[0]);
- bits += _get_one_bits(core_mask[1]);
- if (thread_num > bits) {
- RNG_TST_PRT("Coremask not covers all thrds,\n");
- RNG_TST_PRT("Bind first %d thrds!\n", bits);
- } else if (thread_num < bits) {
- RNG_TST_PRT("Coremask overflow,\n");
- RNG_TST_PRT("Just try to bind all thrds!\n");
- }
-
- if (argv[6]) {
- ctx_num_per_q = strtoul(argv[6], NULL, 10);
- if (ctx_num_per_q <= 0) {
- RNG_TST_PRT("Invalid ctx num per queue:%s!\n",
- argv[6]);
- RNG_TST_PRT("Now ctx num per queue is set as 1!\n");
- ctx_num_per_q = 1;
- }
- } else {
- RNG_TST_PRT("Now ctx num per queue is set as 1!\n");
- ctx_num_per_q = 1;
- }
-
- q_num = (thread_num - 1) / ctx_num_per_q + 1;
-
- RNG_TST_PRT("Proc-%d: starts %d threads bind to %s\n",
- getpid(), thread_num, argv[5]);
- RNG_TST_PRT(" lcoremask=0x%llx, hcoremask=0x%llx\n",
- core_mask[0], core_mask[1]);
- if(alg_op_type == TRNG_GEN)
- return trng_sys_test(thread_num, core_mask[0],
- core_mask[1]);
-
- return trng_asys_test(thread_num, core_mask[0],
- core_mask[1]);
- }
-
- RNG_TST_PRT("Now try to get %d bytes random number.\n", g_input);
-
- data = malloc(g_input);
- if (!data) {
- RNG_TST_PRT("malloc data failed.\n");
- return -1;
- }
-
- memset((void *)&q, 0, sizeof(q));
- memset(&setup, 0, sizeof(setup));
- memset(&opdata, 0, sizeof(opdata));
-
- q.capa.alg = "trng";
- ret = wd_request_queue(&q);
- if (ret) {
- RNG_TST_PRT("request queue fail!\n");
- return ret;
- }
- ctx = wcrypto_create_rng_ctx(&q, &setup);
- if (!ctx) {
- ret = -ENOMEM;
- RNG_TST_PRT("create trng ctx fail!\n");
- goto release_q;
- }
-
- opdata.in_bytes = g_input;
- opdata.out = data;
- ret = wcrypto_do_rng(ctx, &opdata, tag);
- if (ret != 1) {
- RNG_TST_PRT("a wd_do_trng fail!\n");
- goto del_ctx;
- }
-
- RNG_TST_PRT("random_data size= %d.\n", opdata.out_bytes);
- fd_w = open ("/root/trng_file", O_RDWR|O_CREAT|O_TRUNC,0777);
- if (fd_w <0 ) {
- printf("can not open trng_file\n");
- return fd_w;
- }
- /*fd = open ("/dev/random", O_RDONLY);
- if (fd <0 ) {
- printf("can not open\n");
- return fd;
- }*/
- /*ret = read(fd, data, g_input);
- if (ret < 0) {
- printf("read error %d\n", ret);
- return ret;
- }*/
- ret = write(fd_w,opdata.out,opdata.out_bytes);
- if (ret < 0) {
- printf("write error %d\n", ret);
- return ret;
- }
- close(fd);
- close(fd_w);
-del_ctx:
- wcrypto_del_rng_ctx(ctx);
-
-release_q:
- wd_release_queue(&q);
- free(data);
- return ret;
-}
diff --git a/v1/wd.h b/v1/wd.h
index 0132e25..35dcf31 100644
--- a/v1/wd.h
+++ b/v1/wd.h
@@ -184,7 +184,7 @@ struct wd_capa {
* Other capabilities.
* 0~15 bits: number of cookies that the user wants to allocate.
* Optional, user can set value based on the number of requests and system memory,
- * 1~1024 is valid. If the value is not set or invalid, the default value 64 (rng is 256)
+ * 1~1024 is valid. If the value is not set or invalid, the default value 64
* is used to initialize cookies.
*/
__u32 flags;
diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c
index 1c9f656..df5368d 100644
--- a/v1/wd_adapter.c
+++ b/v1/wd_adapter.c
@@ -20,7 +20,6 @@
#include "v1/wd_util.h"
#include "v1/drv/hisi_qm_udrv.h"
-#include "v1/drv/hisi_rng_udrv.h"
#include "v1/wd_adapter.h"
#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
@@ -87,12 +86,6 @@ static const struct wd_drv_dio_if hw_dio_tbl[] = { {
.init_sgl = qm_init_hwsgl_mem,
.uninit_sgl = qm_uninit_hwsgl_mem,
.sgl_merge = qm_merge_hwsgl,
- }, {
- .hw_type = "hisi-trng-v2",
- .open = rng_init_queue,
- .close = rng_uninit_queue,
- .send = rng_send,
- .recv = rng_recv,
},
};
diff --git a/v1/wd_rng.c b/v1/wd_rng.c
deleted file mode 100644
index 7a89cd1..0000000
--- a/v1/wd_rng.c
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright 2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <sys/mman.h>
-
-#include "wd.h"
-#include "wd_util.h"
-#include "wd_rng.h"
-
-#define RNG_RESEND_CNT 8
-#define RNG_RECV_CNT 8
-#define WD_RNG_CTX_COOKIE_NUM 256
-
-struct wcrypto_rng_cookie {
- struct wcrypto_cb_tag tag;
- struct wcrypto_rng_msg msg;
-};
-
-struct wcrypto_rng_ctx {
- struct wd_cookie_pool pool;
- unsigned long ctx_id;
- struct wd_queue *q;
- struct wcrypto_rng_ctx_setup setup;
-};
-
-static int wcrypto_setup_qinfo(struct wcrypto_rng_ctx_setup *setup,
- struct wd_queue *q, __u32 *ctx_id)
-{
- struct q_info *qinfo;
- int ret = -WD_EINVAL;
-
- if (!q || !q->qinfo || !setup) {
- WD_ERR("input parameter err!\n");
- return ret;
- }
-
- if (strcmp(q->capa.alg, "trng")) {
- WD_ERR("algorithm mismatch!\n");
- return ret;
- }
- qinfo = q->qinfo;
- /* lock at ctx creating */
- wd_spinlock(&qinfo->qlock);
- if (qinfo->ctx_num >= WD_MAX_CTX_NUM) {
- WD_ERR("create too many trng ctx!\n");
- goto unlock;
- }
-
- ret = wd_alloc_id(qinfo->ctx_id, WD_MAX_CTX_NUM, ctx_id, 0,
- WD_MAX_CTX_NUM);
- if (ret) {
- WD_ERR("err: alloc ctx id fail!\n");
- goto unlock;
- }
- qinfo->ctx_num++;
- ret = WD_SUCCESS;
-unlock:
- wd_unspinlock(&qinfo->qlock);
- return ret;
-}
-
-void *wcrypto_create_rng_ctx(struct wd_queue *q,
- struct wcrypto_rng_ctx_setup *setup)
-{
- struct wcrypto_rng_cookie *cookie;
- struct wcrypto_rng_ctx *ctx;
- struct q_info *qinfo;
- __u32 cookies_num, i;
- __u32 ctx_id = 0;
- int ret;
-
- if (wcrypto_setup_qinfo(setup, q, &ctx_id))
- return NULL;
-
- ctx = calloc(1, sizeof(struct wcrypto_rng_ctx));
- if (!ctx) {
- WD_ERR("alloc ctx memory fail!\n");
- goto free_ctx_id;
- }
- memcpy(&ctx->setup, setup, sizeof(*setup));
- ctx->q = q;
- ctx->ctx_id = ctx_id + 1;
-
- cookies_num = wd_get_ctx_cookies_num(q->capa.flags, WD_RNG_CTX_COOKIE_NUM);
- ret = wd_init_cookie_pool(&ctx->pool,
- sizeof(struct wcrypto_rng_cookie), cookies_num);
- if (ret) {
- WD_ERR("fail to init cookie pool!\n");
- free(ctx);
- goto free_ctx_id;
- }
- for (i = 0; i < cookies_num; i++) {
- cookie = (void *)((uintptr_t)ctx->pool.cookies +
- i * ctx->pool.cookies_size);
- cookie->msg.alg_type = WCRYPTO_RNG;
- cookie->tag.ctx = ctx;
- cookie->tag.ctx_id = ctx->ctx_id;
- cookie->msg.usr_tag = (uintptr_t)&cookie->tag;
- }
-
- return ctx;
-
-free_ctx_id:
- qinfo = q->qinfo;
- wd_spinlock(&qinfo->qlock);
- qinfo->ctx_num--;
- wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, ctx_id, WD_MAX_CTX_NUM);
- wd_unspinlock(&qinfo->qlock);
-
- return NULL;
-}
-
-void wcrypto_del_rng_ctx(void *ctx)
-{
- struct wcrypto_rng_ctx *cx;
- struct q_info *qinfo;
-
- if (!ctx) {
- WD_ERR("delete trng ctx is NULL!\n");
- return;
- }
-
- cx = ctx;
- qinfo = cx->q->qinfo;
-
- wd_uninit_cookie_pool(&cx->pool);
- wd_spinlock(&qinfo->qlock);
- if (qinfo->ctx_num <= 0) {
- wd_unspinlock(&qinfo->qlock);
- WD_ERR("repeat delete trng ctx!\n");
- return;
- }
- qinfo->ctx_num--;
- wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, cx->ctx_id - 1,
- WD_MAX_CTX_NUM);
- wd_unspinlock(&qinfo->qlock);
-
- free(ctx);
-}
-
-int wcrypto_rng_poll(struct wd_queue *q, unsigned int num)
-{
- struct wcrypto_rng_msg *resp = NULL;
- struct wcrypto_rng_ctx *ctx;
- struct wcrypto_cb_tag *tag;
- unsigned int tmp = num;
- int count = 0;
- int ret;
-
- if (!q) {
- WD_ERR("%s(): input parameter err!\n", __func__);
- return -WD_EINVAL;
- }
-
- do {
- ret = wd_recv(q, (void **)&resp);
- if (!ret)
- break;
-
- if (ret < 0) {
- WD_ERR("recv err at trng poll!\n");
- return ret;
- }
-
- count++;
- tag = (void *)(uintptr_t)resp->usr_tag;
- ctx = tag->ctx;
- ctx->setup.cb(resp, tag->tag);
- wd_put_cookies(&ctx->pool, (void **)&tag, 1);
- resp = NULL;
- } while (--tmp);
-
- return count;
-}
-
-static int wcrypto_do_prepare(struct wcrypto_rng_cookie **cookie_addr,
- struct wcrypto_rng_op_data *opdata,
- struct wcrypto_rng_msg **req_addr,
- struct wcrypto_rng_ctx *ctxt,
- void *tag)
-{
- struct wcrypto_rng_cookie *cookie;
- struct wcrypto_rng_msg *req;
- int ret;
-
- if (unlikely(!ctxt || !opdata)) {
- WD_ERR("invalid: rng input parameter err!\n");
- return -WD_EINVAL;
- }
-
- if (unlikely((opdata->in_bytes && !opdata->out))) {
- WD_ERR("invalid: dst addr is NULL when in_bytes is non-zero!!\n");
- return -WD_EINVAL;
- }
-
- ret = wd_get_cookies(&ctxt->pool, (void **)&cookie, 1);
- if (ret)
- return ret;
-
- if (tag) {
- if (!ctxt->setup.cb) {
- WD_ERR("invalid: ctx call back is null!\n");
- wd_put_cookies(&ctxt->pool, (void **)&cookie, 1);
- return -WD_EINVAL;
- }
- cookie->tag.tag = tag;
- }
-
- req = &cookie->msg;
- req->in_bytes = opdata->in_bytes;
- req->out = opdata->out;
- *cookie_addr = cookie;
- *req_addr = req;
-
- return 0;
-}
-
-int wcrypto_do_rng(void *ctx, struct wcrypto_rng_op_data *opdata, void *tag)
-{
- struct wcrypto_rng_ctx *ctxt = ctx;
- struct wcrypto_rng_cookie *cookie;
- struct wcrypto_rng_msg *req;
- struct wcrypto_rng_msg *resp;
- uint32_t tx_cnt = 0;
- uint32_t rx_cnt = 0;
- int ret = 0;
-
- ret = wcrypto_do_prepare(&cookie, opdata, &req, ctxt, tag);
- if (ret)
- return ret;
-
- do {
- ret = wd_send(ctxt->q, req);
- if (!ret) {
- break;
- } else if (ret == -WD_EBUSY) {
- if (++tx_cnt > RNG_RESEND_CNT) {
- WD_ERR("do trng send cnt %u, exit!\n", tx_cnt);
- goto fail_with_cookie;
- }
-
- usleep(1);
- } else {
- WD_ERR("do rng wd_send err!\n");
- goto fail_with_cookie;
- }
- } while (true);
-
- if (tag)
- return ret;
-
- resp = (void *)(uintptr_t)ctxt->ctx_id;
-
- do {
- ret = wd_recv(ctxt->q, (void **)&resp);
- if (ret > 0) {
- break;
- } else if (!ret) {
- if (++rx_cnt > RNG_RECV_CNT) {
- WD_ERR("do trng recv cnt %u, exit!\n", rx_cnt);
- ret = -WD_ETIMEDOUT;
- goto fail_with_cookie;
- }
-
- usleep(1);
- } else {
- WD_ERR("do trng recv err!\n");
- goto fail_with_cookie;
- }
- } while (true);
-
- opdata->out_bytes = resp->out_bytes;
- ret = WD_SUCCESS;
-fail_with_cookie:
- wd_put_cookies(&ctxt->pool, (void **)&cookie, 1);
- return ret;
-}
diff --git a/v1/wd_rng.h b/v1/wd_rng.h
deleted file mode 100644
index fcde26d..0000000
--- a/v1/wd_rng.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2019 Huawei Technologies Co.,Ltd.All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __WD_RNG_H
-#define __WD_RNG_H
-
-#include "wd.h"
-#include "wd_digest.h"
-#include "wd_cipher.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct wcrypto_rng_ctx_setup {
- wcrypto_cb cb;
- __u16 data_fmt; /* Data format, denoted by enum wd_buff_type */
- enum wcrypto_type type; /* Please refer to the definition of enum */
- enum wcrypto_cipher_alg calg; /* DRBG cipher algorithm */
- enum wcrypto_cipher_mode cmode; /* DRBG cipher mode */
- enum wcrypto_digest_alg dalg; /* DRBG digest algorithm */
- enum wcrypto_digest_mode dmode; /* DRBG digest mode */
-};
-
-struct wcrypto_rng_msg {
- __u8 alg_type; /* Denoted by enum wcrypto_type */
- __u8 op_type; /* Denoted by enum wcrypto_rng_op_type */
- __u8 data_fmt; /* Data format, denoted by enum wd_buff_type */
- __u8 result; /* Data format, denoted by WD error code */
- __u8 *out; /* Result address */
- __u8 *in; /* Input address */
- __u32 out_bytes; /* output bytes */
- __u32 in_bytes; /* input bytes */
- __u64 usr_tag; /* user identifier */
-};
-
-enum wcrypto_rng_op_type {
- WCRYPTO_RNG_INVALID, /* Invalid RNG operational type */
- WCRYPTO_DRBG_RESEED, /* seed operation */
- WCRYPTO_DRBG_GEN, /* deterministic random number generation */
- WCRYPTO_TRNG_GEN, /* true random number generation */
-};
-
-struct wcrypto_rng_op_data {
- enum wcrypto_rng_op_type op_type;
- __u32 status; /* Operation result status */
- void *in; /* input */
- void *out; /* output */
- __u32 in_bytes; /* input bytes */
- __u32 out_bytes; /* output bytes */
-};
-
-void *wcrypto_create_rng_ctx(struct wd_queue *q,
- struct wcrypto_rng_ctx_setup *setup);
-void wcrypto_del_rng_ctx(void *ctx);
-int wcrypto_do_rng(void *ctx, struct wcrypto_rng_op_data *opdata, void *tag);
-int wcrypto_rng_poll(struct wd_queue *q, unsigned int num);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
--
2.33.0
1
0
From: Hao Fang <fanghao11(a)huawei.com>
add testcase for init2 just use cmd --init 2.
default or --init 1 for init interface.
Signed-off-by: Hao Fang <fanghao11(a)huawei.com>
---
uadk_tool/test/test_sec.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/uadk_tool/test/test_sec.c b/uadk_tool/test/test_sec.c
index 5b552fa..0a28db6 100644
--- a/uadk_tool/test/test_sec.c
+++ b/uadk_tool/test/test_sec.c
@@ -1483,6 +1483,14 @@ static int digest_init2(int type, int mode)
cparams.op_type_num = 1;
cparams.ctx_set_num = ctx_set_num;
+ cparams.bmp = numa_allocate_nodemask();
+ if (!cparams.bmp) {
+ WD_ERR("failed to create nodemask!\n");
+ ret = -WD_ENOMEM;
+ goto out_freectx;
+ }
+
+ numa_bitmask_setall(cparams.bmp);
if (mode == CTX_MODE_SYNC)
ctx_set_num->sync_ctx_num = g_ctxnum;
@@ -1494,7 +1502,13 @@ static int digest_init2(int type, int mode)
ret = wd_digest_init2("sm3", SCHED_POLICY_NONE, TASK_INSTR);
else
ret = wd_digest_init2_(digest_names[g_testalg], 0, 0, &cparams);
+ if (ret)
+ goto out_freebmp;
+
+out_freebmp:
+ numa_free_nodemask(cparams.bmp);
+out_freectx:
free(ctx_set_num);
return ret;
--
2.33.0
1
12
12 Feb '26
From: Weili Qian <qianweili(a)huawei.com>
Fix the compilation failure of wd_alg.h, error log likes:
wd_alg.h:121:9: error: unknown type name ‘__u8’.
And improve code portability by including linux/types.h
instead of asm/types.h.
Upstream: YES
Feature or Bugfix:Bugfix
AR: AR20230722287656
DTS: DTS2026012302441
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
drv/hisi_comp.c | 2 +-
drv/hisi_comp_huf.c | 2 +-
drv/hisi_comp_huf.h | 2 +-
include/drv/wd_agg_drv.h | 2 +-
include/drv/wd_cipher_drv.h | 2 +-
include/drv/wd_comp_drv.h | 2 +-
include/drv/wd_dh_drv.h | 2 +-
include/drv/wd_ecc_drv.h | 2 +-
include/drv/wd_join_gather_drv.h | 2 +-
include/drv/wd_rsa_drv.h | 2 +-
include/drv/wd_udma_drv.h | 2 +-
include/wd.h | 6 ++----
include/wd_agg.h | 3 ++-
include/wd_alg.h | 1 +
include/wd_cipher.h | 3 ++-
include/wd_dae.h | 3 ++-
include/wd_join_gather.h | 3 ++-
include/wd_sched.h | 2 +-
include/wd_util.h | 2 +-
include/wd_zlibwrapper.h | 2 +-
20 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 6758c02..7c449e0 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. */
-#include <asm/types.h>
+#include <linux/types.h>
#include "drv/wd_comp_drv.h"
#include "drv/hisi_comp_huf.h"
#include "hisi_qm_udrv.h"
diff --git a/drv/hisi_comp_huf.c b/drv/hisi_comp_huf.c
index 161fee4..c64c418 100644
--- a/drv/hisi_comp_huf.c
+++ b/drv/hisi_comp_huf.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved. */
-#include <asm/types.h>
+#include <linux/types.h>
#include "drv/hisi_comp_huf.h"
#include "wd_util.h"
diff --git a/drv/hisi_comp_huf.h b/drv/hisi_comp_huf.h
index 6585b7a..dde0ff4 100644
--- a/drv/hisi_comp_huf.h
+++ b/drv/hisi_comp_huf.h
@@ -4,7 +4,7 @@
#ifndef __HISI_COMP_HUF_H
#define __HISI_COMP_HUF_H
-#include <asm/types.h>
+#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/drv/wd_agg_drv.h b/include/drv/wd_agg_drv.h
index 978c2d3..b26b25d 100644
--- a/include/drv/wd_agg_drv.h
+++ b/include/drv/wd_agg_drv.h
@@ -6,7 +6,7 @@
#ifndef __WD_AGG_DRV_H
#define __WD_AGG_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_agg.h"
#include "wd_util.h"
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
index c0be0c3..458a8d8 100644
--- a/include/drv/wd_cipher_drv.h
+++ b/include/drv/wd_cipher_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_CIPHER_DRV_H
#define __WD_CIPHER_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_cipher.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
index 95f7fb7..2311d79 100644
--- a/include/drv/wd_comp_drv.h
+++ b/include/drv/wd_comp_drv.h
@@ -5,7 +5,7 @@
#define __WD_COMP_DRV_H
#include <pthread.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_comp.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index d2a6157..a46aa90 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_DH_DRV_H
#define __WD_DH_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_dh.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index b123a9b..48c422f 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -5,7 +5,7 @@
#define __WD_ECC_DRV_H
#include <stdint.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_ecc.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_join_gather_drv.h b/include/drv/wd_join_gather_drv.h
index 80fb932..dbf4ee7 100644
--- a/include/drv/wd_join_gather_drv.h
+++ b/include/drv/wd_join_gather_drv.h
@@ -6,7 +6,7 @@
#ifndef __WD_JOIN_GATHER_DRV_H
#define __WD_JOIN_GATHER_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_join_gather.h"
#include "wd_util.h"
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index c12f3e0..728abdf 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -3,7 +3,7 @@
#ifndef __WD_RSA_DRV_H
#define __WD_RSA_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_rsa.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_udma_drv.h b/include/drv/wd_udma_drv.h
index c8028f7..8c5edea 100644
--- a/include/drv/wd_udma_drv.h
+++ b/include/drv/wd_udma_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_UDMA_DRV_H
#define __WD_UDMA_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_udma.h"
#include "../wd_util.h"
diff --git a/include/wd.h b/include/wd.h
index 7e92e41..a468047 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -15,7 +15,8 @@
#include <string.h>
#include <syslog.h>
#include <unistd.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "uacce.h"
#ifdef __cplusplus
@@ -33,9 +34,6 @@ extern "C" {
#define CRYPTO_MAX_ALG_NAME 128
#define NUMA_NO_NODE (-1)
-typedef unsigned char __u8;
-typedef unsigned int __u32;
-typedef unsigned long long __u64;
/* Required compiler attributes */
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
diff --git a/include/wd_agg.h b/include/wd_agg.h
index fed08c5..b35c8c2 100644
--- a/include/wd_agg.h
+++ b/include/wd_agg.h
@@ -7,7 +7,8 @@
#define __WD_AGG_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_dae.h"
#ifdef __cplusplus
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 7a3ae5f..18503ca 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -10,6 +10,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
+#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
index 1d82eac..a6f8be1 100644
--- a/include/wd_cipher.h
+++ b/include/wd_cipher.h
@@ -8,7 +8,8 @@
#define __WD_CIPHER_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_dae.h b/include/wd_dae.h
index 64f17dc..3d7463e 100644
--- a/include/wd_dae.h
+++ b/include/wd_dae.h
@@ -8,7 +8,8 @@
#include <dlfcn.h>
#include <stdbool.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_alg_common.h"
#include "wd.h"
diff --git a/include/wd_join_gather.h b/include/wd_join_gather.h
index 4962ee3..44588b2 100644
--- a/include/wd_join_gather.h
+++ b/include/wd_join_gather.h
@@ -7,7 +7,8 @@
#define __WD_JOIN_GATHER_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_dae.h"
#ifdef __cplusplus
diff --git a/include/wd_sched.h b/include/wd_sched.h
index 949396e..5baecd3 100644
--- a/include/wd_sched.h
+++ b/include/wd_sched.h
@@ -6,7 +6,7 @@
#ifndef SCHED_SAMPLE_h
#define SCHED_SAMPLE_h
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_util.h b/include/wd_util.h
index a337284..2abceec 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -11,7 +11,7 @@
#include <stdbool.h>
#include <sys/ipc.h>
#include <sys/shm.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd.h"
#include "wd_sched.h"
diff --git a/include/wd_zlibwrapper.h b/include/wd_zlibwrapper.h
index 978d1ed..80ba08f 100644
--- a/include/wd_zlibwrapper.h
+++ b/include/wd_zlibwrapper.h
@@ -6,7 +6,7 @@
#ifndef UADK_ZLIBWRAPPER_H
#define UADK_ZLIBWRAPPER_H
-#include <asm/types.h>
+#include <linux/types.h>
/*
* These APIs are used to replace the ZLIB library. So if you don't use them.
--
2.33.0
1
0
12 Feb '26
From: Weili Qian <qianweili(a)huawei.com>
Fix the compilation failure of wd_alg.h, error log likes:
wd_alg.h:121:9: error: unknown type name ‘__u8’.
And improve code portability by including linux/types.h
instead of asm/types.h.
Upstream: YES
Feature or Bugfix:Bugfix
AR: AR20230722287656
DTS: DTS2026012302441
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
drv/hisi_comp.c | 2 +-
drv/hisi_comp_huf.c | 2 +-
drv/hisi_comp_huf.h | 2 +-
include/drv/wd_agg_drv.h | 2 +-
include/drv/wd_cipher_drv.h | 2 +-
include/drv/wd_comp_drv.h | 2 +-
include/drv/wd_dh_drv.h | 2 +-
include/drv/wd_ecc_drv.h | 2 +-
include/drv/wd_join_gather_drv.h | 2 +-
include/drv/wd_rsa_drv.h | 2 +-
include/drv/wd_udma_drv.h | 2 +-
include/wd.h | 6 ++----
include/wd_agg.h | 3 ++-
include/wd_alg.h | 1 +
include/wd_cipher.h | 3 ++-
include/wd_dae.h | 3 ++-
include/wd_join_gather.h | 3 ++-
include/wd_sched.h | 2 +-
include/wd_util.h | 2 +-
include/wd_zlibwrapper.h | 2 +-
20 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 6758c02..7c449e0 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. */
-#include <asm/types.h>
+#include <linux/types.h>
#include "drv/wd_comp_drv.h"
#include "drv/hisi_comp_huf.h"
#include "hisi_qm_udrv.h"
diff --git a/drv/hisi_comp_huf.c b/drv/hisi_comp_huf.c
index 161fee4..c64c418 100644
--- a/drv/hisi_comp_huf.c
+++ b/drv/hisi_comp_huf.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved. */
-#include <asm/types.h>
+#include <linux/types.h>
#include "drv/hisi_comp_huf.h"
#include "wd_util.h"
diff --git a/drv/hisi_comp_huf.h b/drv/hisi_comp_huf.h
index 6585b7a..dde0ff4 100644
--- a/drv/hisi_comp_huf.h
+++ b/drv/hisi_comp_huf.h
@@ -4,7 +4,7 @@
#ifndef __HISI_COMP_HUF_H
#define __HISI_COMP_HUF_H
-#include <asm/types.h>
+#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/drv/wd_agg_drv.h b/include/drv/wd_agg_drv.h
index 978c2d3..b26b25d 100644
--- a/include/drv/wd_agg_drv.h
+++ b/include/drv/wd_agg_drv.h
@@ -6,7 +6,7 @@
#ifndef __WD_AGG_DRV_H
#define __WD_AGG_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_agg.h"
#include "wd_util.h"
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
index c0be0c3..458a8d8 100644
--- a/include/drv/wd_cipher_drv.h
+++ b/include/drv/wd_cipher_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_CIPHER_DRV_H
#define __WD_CIPHER_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_cipher.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
index 95f7fb7..2311d79 100644
--- a/include/drv/wd_comp_drv.h
+++ b/include/drv/wd_comp_drv.h
@@ -5,7 +5,7 @@
#define __WD_COMP_DRV_H
#include <pthread.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_comp.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index d2a6157..a46aa90 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_DH_DRV_H
#define __WD_DH_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_dh.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index b123a9b..48c422f 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -5,7 +5,7 @@
#define __WD_ECC_DRV_H
#include <stdint.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_ecc.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_join_gather_drv.h b/include/drv/wd_join_gather_drv.h
index 80fb932..dbf4ee7 100644
--- a/include/drv/wd_join_gather_drv.h
+++ b/include/drv/wd_join_gather_drv.h
@@ -6,7 +6,7 @@
#ifndef __WD_JOIN_GATHER_DRV_H
#define __WD_JOIN_GATHER_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_join_gather.h"
#include "wd_util.h"
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index c12f3e0..728abdf 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -3,7 +3,7 @@
#ifndef __WD_RSA_DRV_H
#define __WD_RSA_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_rsa.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_udma_drv.h b/include/drv/wd_udma_drv.h
index c8028f7..8c5edea 100644
--- a/include/drv/wd_udma_drv.h
+++ b/include/drv/wd_udma_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_UDMA_DRV_H
#define __WD_UDMA_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_udma.h"
#include "../wd_util.h"
diff --git a/include/wd.h b/include/wd.h
index 7e92e41..a468047 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -15,7 +15,8 @@
#include <string.h>
#include <syslog.h>
#include <unistd.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "uacce.h"
#ifdef __cplusplus
@@ -33,9 +34,6 @@ extern "C" {
#define CRYPTO_MAX_ALG_NAME 128
#define NUMA_NO_NODE (-1)
-typedef unsigned char __u8;
-typedef unsigned int __u32;
-typedef unsigned long long __u64;
/* Required compiler attributes */
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
diff --git a/include/wd_agg.h b/include/wd_agg.h
index fed08c5..b35c8c2 100644
--- a/include/wd_agg.h
+++ b/include/wd_agg.h
@@ -7,7 +7,8 @@
#define __WD_AGG_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_dae.h"
#ifdef __cplusplus
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 7a3ae5f..18503ca 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -10,6 +10,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
+#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
index 1d82eac..a6f8be1 100644
--- a/include/wd_cipher.h
+++ b/include/wd_cipher.h
@@ -8,7 +8,8 @@
#define __WD_CIPHER_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_dae.h b/include/wd_dae.h
index 64f17dc..3d7463e 100644
--- a/include/wd_dae.h
+++ b/include/wd_dae.h
@@ -8,7 +8,8 @@
#include <dlfcn.h>
#include <stdbool.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_alg_common.h"
#include "wd.h"
diff --git a/include/wd_join_gather.h b/include/wd_join_gather.h
index 4962ee3..44588b2 100644
--- a/include/wd_join_gather.h
+++ b/include/wd_join_gather.h
@@ -7,7 +7,8 @@
#define __WD_JOIN_GATHER_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_dae.h"
#ifdef __cplusplus
diff --git a/include/wd_sched.h b/include/wd_sched.h
index 949396e..5baecd3 100644
--- a/include/wd_sched.h
+++ b/include/wd_sched.h
@@ -6,7 +6,7 @@
#ifndef SCHED_SAMPLE_h
#define SCHED_SAMPLE_h
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_util.h b/include/wd_util.h
index a337284..2abceec 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -11,7 +11,7 @@
#include <stdbool.h>
#include <sys/ipc.h>
#include <sys/shm.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd.h"
#include "wd_sched.h"
diff --git a/include/wd_zlibwrapper.h b/include/wd_zlibwrapper.h
index 978d1ed..80ba08f 100644
--- a/include/wd_zlibwrapper.h
+++ b/include/wd_zlibwrapper.h
@@ -6,7 +6,7 @@
#ifndef UADK_ZLIBWRAPPER_H
#define UADK_ZLIBWRAPPER_H
-#include <asm/types.h>
+#include <linux/types.h>
/*
* These APIs are used to replace the ZLIB library. So if you don't use them.
--
2.33.0
1
0
From: Weili Qian <qianweili(a)huawei.com>
Fix the compilation failure of wd_alg.h, error log likes:
wd_alg.h:121:9: error: unknown type name ‘__u8’.
And improve code portability by including linux/types.h
instead of asm/types.h.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
drv/hisi_comp.c | 2 +-
drv/hisi_comp_huf.c | 2 +-
drv/hisi_comp_huf.h | 2 +-
include/drv/wd_agg_drv.h | 2 +-
include/drv/wd_cipher_drv.h | 2 +-
include/drv/wd_comp_drv.h | 2 +-
include/drv/wd_dh_drv.h | 2 +-
include/drv/wd_ecc_drv.h | 2 +-
include/drv/wd_join_gather_drv.h | 2 +-
include/drv/wd_rsa_drv.h | 2 +-
include/drv/wd_udma_drv.h | 2 +-
include/wd.h | 6 ++----
include/wd_agg.h | 3 ++-
include/wd_alg.h | 1 +
include/wd_cipher.h | 3 ++-
include/wd_dae.h | 3 ++-
include/wd_join_gather.h | 3 ++-
include/wd_sched.h | 2 +-
include/wd_util.h | 2 +-
include/wd_zlibwrapper.h | 2 +-
20 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index cf8d315..a6b2947 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2020-2021 Huawei Technologies Co.,Ltd. All rights reserved. */
-#include <asm/types.h>
+#include <linux/types.h>
#include "drv/wd_comp_drv.h"
#include "drv/hisi_comp_huf.h"
#include "hisi_qm_udrv.h"
diff --git a/drv/hisi_comp_huf.c b/drv/hisi_comp_huf.c
index 161fee4..c64c418 100644
--- a/drv/hisi_comp_huf.c
+++ b/drv/hisi_comp_huf.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved. */
-#include <asm/types.h>
+#include <linux/types.h>
#include "drv/hisi_comp_huf.h"
#include "wd_util.h"
diff --git a/drv/hisi_comp_huf.h b/drv/hisi_comp_huf.h
index 6585b7a..dde0ff4 100644
--- a/drv/hisi_comp_huf.h
+++ b/drv/hisi_comp_huf.h
@@ -4,7 +4,7 @@
#ifndef __HISI_COMP_HUF_H
#define __HISI_COMP_HUF_H
-#include <asm/types.h>
+#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/drv/wd_agg_drv.h b/include/drv/wd_agg_drv.h
index 978c2d3..b26b25d 100644
--- a/include/drv/wd_agg_drv.h
+++ b/include/drv/wd_agg_drv.h
@@ -6,7 +6,7 @@
#ifndef __WD_AGG_DRV_H
#define __WD_AGG_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_agg.h"
#include "wd_util.h"
diff --git a/include/drv/wd_cipher_drv.h b/include/drv/wd_cipher_drv.h
index c0be0c3..458a8d8 100644
--- a/include/drv/wd_cipher_drv.h
+++ b/include/drv/wd_cipher_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_CIPHER_DRV_H
#define __WD_CIPHER_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_cipher.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_comp_drv.h b/include/drv/wd_comp_drv.h
index 95f7fb7..2311d79 100644
--- a/include/drv/wd_comp_drv.h
+++ b/include/drv/wd_comp_drv.h
@@ -5,7 +5,7 @@
#define __WD_COMP_DRV_H
#include <pthread.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_comp.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index d2a6157..a46aa90 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_DH_DRV_H
#define __WD_DH_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_dh.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index b123a9b..48c422f 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -5,7 +5,7 @@
#define __WD_ECC_DRV_H
#include <stdint.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_ecc.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_join_gather_drv.h b/include/drv/wd_join_gather_drv.h
index 80fb932..dbf4ee7 100644
--- a/include/drv/wd_join_gather_drv.h
+++ b/include/drv/wd_join_gather_drv.h
@@ -6,7 +6,7 @@
#ifndef __WD_JOIN_GATHER_DRV_H
#define __WD_JOIN_GATHER_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_join_gather.h"
#include "wd_util.h"
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index c12f3e0..728abdf 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -3,7 +3,7 @@
#ifndef __WD_RSA_DRV_H
#define __WD_RSA_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_rsa.h"
#include "../wd_util.h"
diff --git a/include/drv/wd_udma_drv.h b/include/drv/wd_udma_drv.h
index c8028f7..8c5edea 100644
--- a/include/drv/wd_udma_drv.h
+++ b/include/drv/wd_udma_drv.h
@@ -4,7 +4,7 @@
#ifndef __WD_UDMA_DRV_H
#define __WD_UDMA_DRV_H
-#include <asm/types.h>
+#include <linux/types.h>
#include "../wd_udma.h"
#include "../wd_util.h"
diff --git a/include/wd.h b/include/wd.h
index 7e92e41..a468047 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -15,7 +15,8 @@
#include <string.h>
#include <syslog.h>
#include <unistd.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "uacce.h"
#ifdef __cplusplus
@@ -33,9 +34,6 @@ extern "C" {
#define CRYPTO_MAX_ALG_NAME 128
#define NUMA_NO_NODE (-1)
-typedef unsigned char __u8;
-typedef unsigned int __u32;
-typedef unsigned long long __u64;
/* Required compiler attributes */
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
diff --git a/include/wd_agg.h b/include/wd_agg.h
index fed08c5..b35c8c2 100644
--- a/include/wd_agg.h
+++ b/include/wd_agg.h
@@ -7,7 +7,8 @@
#define __WD_AGG_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_dae.h"
#ifdef __cplusplus
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 7a3ae5f..18503ca 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -10,6 +10,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
+#include <linux/types.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/wd_cipher.h b/include/wd_cipher.h
index 1d82eac..a6f8be1 100644
--- a/include/wd_cipher.h
+++ b/include/wd_cipher.h
@@ -8,7 +8,8 @@
#define __WD_CIPHER_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_dae.h b/include/wd_dae.h
index 64f17dc..3d7463e 100644
--- a/include/wd_dae.h
+++ b/include/wd_dae.h
@@ -8,7 +8,8 @@
#include <dlfcn.h>
#include <stdbool.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_alg_common.h"
#include "wd.h"
diff --git a/include/wd_join_gather.h b/include/wd_join_gather.h
index 4962ee3..44588b2 100644
--- a/include/wd_join_gather.h
+++ b/include/wd_join_gather.h
@@ -7,7 +7,8 @@
#define __WD_JOIN_GATHER_H
#include <dlfcn.h>
-#include <asm/types.h>
+#include <linux/types.h>
+
#include "wd_dae.h"
#ifdef __cplusplus
diff --git a/include/wd_sched.h b/include/wd_sched.h
index 949396e..5baecd3 100644
--- a/include/wd_sched.h
+++ b/include/wd_sched.h
@@ -6,7 +6,7 @@
#ifndef SCHED_SAMPLE_h
#define SCHED_SAMPLE_h
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd_alg_common.h"
#ifdef __cplusplus
diff --git a/include/wd_util.h b/include/wd_util.h
index a337284..2abceec 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -11,7 +11,7 @@
#include <stdbool.h>
#include <sys/ipc.h>
#include <sys/shm.h>
-#include <asm/types.h>
+#include <linux/types.h>
#include "wd.h"
#include "wd_sched.h"
diff --git a/include/wd_zlibwrapper.h b/include/wd_zlibwrapper.h
index 978d1ed..80ba08f 100644
--- a/include/wd_zlibwrapper.h
+++ b/include/wd_zlibwrapper.h
@@ -6,7 +6,7 @@
#ifndef UADK_ZLIBWRAPPER_H
#define UADK_ZLIBWRAPPER_H
-#include <asm/types.h>
+#include <linux/types.h>
/*
* These APIs are used to replace the ZLIB library. So if you don't use them.
--
2.33.0
1
1
From: parm64 <parm64(a)huawei.com>
Weili Qian (9):
uadk_provider: set the default provider when initializing the uadk
provider
uadk_engine: release asynchronous resources before destroying
algorithm resources
uadk_provider: release asynchronous resources before destroying
algorithm resources
uadk_provider/sm2: move sm2 key generation into a separate file
uadk_provider/sm2: modify the return value of keygen
uadk_provider/sm2: remove unnecessary code
uadk_engine/ecc: remove unnecessary code
uadk_engine: fix compilation warnings
uadk_provider/sm2: split uadk_prov_sm2.c into 2 files
Zhushuai Yin (3):
uadk_provider: reduce lock scope during prov init to improve perf
uadk_engine: reduce lock scope during prov init to improve perf
uadk_provider: delete asynchronous redundancy declaration
lizhi (4):
uadk_provider: adapt uadk_provider with tls 1.3
uadk_provider: adapt rsa key management with pss padding mode
uadk_provider: adapt rsa pss key management with algorithm enable
configuration.
uadk_engine/ecc: fix memory leak in the ecx algorithm
src/Makefile.am | 4 +-
src/uadk_aead.c | 1 +
src/uadk_async.h | 1 -
src/uadk_cipher.c | 1 +
src/uadk_cipher_adapter.c | 2 +-
src/uadk_dh.c | 1 +
src/uadk_digest.c | 1 +
src/uadk_ec.c | 34 +-
src/uadk_ecx.c | 1 +
src/uadk_engine_init.c | 8 +-
src/uadk_pkey.c | 1 +
src/uadk_prov.h | 19 +-
src/uadk_prov_aead.c | 18 +-
src/uadk_prov_capabilities.c | 224 +++
src/uadk_prov_cipher.c | 70 +-
src/uadk_prov_dh.c | 66 +-
src/uadk_prov_digest.c | 18 +-
src/uadk_prov_ec_kmgmt.c | 19 +
src/uadk_prov_ecdh_exch.c | 33 +-
src/uadk_prov_ecx.c | 125 +-
src/uadk_prov_hmac.c | 24 +-
src/uadk_prov_init.c | 96 +-
src/uadk_prov_pkey.c | 14 +-
src/uadk_prov_pkey.h | 21 +-
src/uadk_prov_rsa.c | 14 +-
src/uadk_prov_rsa_enc.c | 34 +-
src/uadk_prov_rsa_kmgmt.c | 101 ++
src/uadk_prov_rsa_sign.c | 34 +-
src/uadk_prov_sm2.c | 3320 ----------------------------------
src/uadk_prov_sm2_enc.c | 860 +++++++++
src/uadk_prov_sm2_kmgmt.c | 505 ++++++
src/uadk_prov_sm2_sign.c | 1342 ++++++++++++++
src/uadk_rsa.c | 1 +
33 files changed, 3398 insertions(+), 3615 deletions(-)
create mode 100644 src/uadk_prov_capabilities.c
delete mode 100644 src/uadk_prov_sm2.c
create mode 100644 src/uadk_prov_sm2_enc.c
create mode 100644 src/uadk_prov_sm2_kmgmt.c
create mode 100644 src/uadk_prov_sm2_sign.c
--
2.43.0
1
16
From: Wenkai Lin <linwenkai6(a)hisilicon.com>
Adjusted the rehash descriptors counta_vld, agg_col_bit_map,
Agg_Oid, Agg_Out_Type, Col_Data_Type, and Col_Data_Info.
These descriptors are consistent with those generated by the
hash aggregation task. In addition, an extra 4 bytes are added
when calculating the row size to ensure that each hash table
contains 4 bytes of empty information.
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
Signed-off-by: Zhushuai Yin <yinzhushuai(a)huawei.com>
---
drv/hisi_dae.c | 12 ++++++++----
drv/hisi_dae_join_gather.c | 7 +++++--
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index a6ee368..8fe6092 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -33,7 +33,6 @@
/* hash table */
#define HASH_TABLE_HEAD_TAIL_SIZE 8
-#define HASH_TABLE_EMPTY_SIZE 4
/* hash agg operations col max num */
#define DAE_AGG_COL_ALG_MAX_NUM 2
@@ -160,13 +159,18 @@ static void fill_hashagg_merge_output_order(struct dae_sqe *sqe, struct dae_ext_
{
struct hashagg_ctx *agg_ctx = msg->priv;
struct hashagg_col_data *cols_data = &agg_ctx->cols_data;
+ __u32 out_cols_num = cols_data->output_num;
struct hashagg_output_src *output_src;
__u32 offset = 0;
__u32 i;
- output_src = cols_data->rehash_output;
+ output_src = cols_data->normal_output;
+ if (cols_data->is_count_all) {
+ sqe->counta_vld = DAE_HASH_COUNT_ALL;
+ out_cols_num--;
+ }
- for (i = 0; i < cols_data->output_num; i++) {
+ for (i = 0; i < out_cols_num; i++) {
ext_sqe->out_from_in_idx |= (__u64)output_src[i].out_from_in_idx << offset;
ext_sqe->out_optype |= (__u64)output_src[i].out_optype << offset;
offset += DAE_COL_BIT_NUM;
@@ -370,7 +374,7 @@ static void fill_hashagg_merge_input_data(struct dae_sqe *sqe, struct dae_ext_sq
struct hashagg_ctx *agg_ctx = msg->priv;
struct hashagg_col_data *cols_data = &agg_ctx->cols_data;
- fill_hashagg_data_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->input_data, msg->agg_cols_num);
}
static void fill_hashagg_ext_addr(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
diff --git a/drv/hisi_dae_join_gather.c b/drv/hisi_dae_join_gather.c
index 92fae1a..8c45f57 100644
--- a/drv/hisi_dae_join_gather.c
+++ b/drv/hisi_dae_join_gather.c
@@ -19,7 +19,7 @@
#define PROBE_INDEX_ROW_SIZE 4
/* align size */
-#define DAE_KEY_ALIGN_SIZE 8
+#define DAE_KEY_ALIGN_SIZE 4
#define DAE_BREAKPOINT_SIZE 81920
#define DAE_ADDR_INDEX_SHIFT 1
@@ -28,7 +28,6 @@
#define HASH_TABLE_INDEX_NUM 1
#define HASH_TABLE_MAX_INDEX_NUM 15
#define HASH_TABLE_INDEX_SIZE 12
-#define HASH_TABLE_EMPTY_SIZE 4
#define GATHER_ROW_BATCH_EMPTY_SIZE 4
/* DAE hardware protocol data */
@@ -173,6 +172,9 @@ static void fill_join_table_data(struct dae_sqe *sqe, struct dae_addr_list *addr
}
sqe->table_row_size = ctx->hash_table_row_size;
+ /* Initialize these fields for hardware check*/
+ sqe->src_table_width = ctx->table_data.table_width;
+ sqe->dst_table_width = ctx->table_data.table_width;
if (table_data_src) {
sqe->src_table_width = table_data_src->table_width;
@@ -814,6 +816,7 @@ static int join_get_table_rowsize(struct join_gather_col_data *cols_data,
for (i = 0; i < key_num; i++)
row_count_size += get_data_type_size(key_data[i].hw_type, 0);
+ row_count_size += HASH_TABLE_EMPTY_SIZE;
row_count_size = ALIGN(row_count_size, DAE_KEY_ALIGN_SIZE);
row_count_size += HASH_TABLE_HEAD_TAIL_SIZE +
cols_data->index_num * HASH_TABLE_INDEX_SIZE;
--
2.33.0
1
4
06 Jan '26
From: Zhushuai Yin <yinzhushuai(a)huawei.com>
Due to changes in chip specifications, the hash agg 8B and 16B operations
have been reduced from 9 columns to 8 columns,requiring the driver to be
adapted accordingly.
Signed-off-by: Zhushuai Yin <yinzhushuai(a)huawei.com>
---
drv/hisi_dae.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index d7b34c2..a6ee368 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -673,7 +673,7 @@ static int agg_get_output_num(enum wd_dae_data_type type,
}
static int agg_output_num_check(struct wd_agg_col_info *agg_cols, __u32 cols_num,
- bool is_count_all, __u16 hw_type)
+ bool is_count_all)
{
__u32 size8 = 0, size16 = 0;
__u32 i, j, count_num;
@@ -691,8 +691,7 @@ static int agg_output_num_check(struct wd_agg_col_info *agg_cols, __u32 cols_num
if (is_count_all)
size8++;
- if (hw_type < HISI_QM_API_VER5_BASE &&
- (size8 > DAE_MAX_8B_COLS_NUM || size16 > DAE_MAX_16B_COLS_NUM)) {
+ if (size8 > DAE_MAX_8B_COLS_NUM || size16 > DAE_MAX_16B_COLS_NUM) {
WD_ERR("invalid: output col num 8B-16B %u-%u is more than support %d-%d !\n",
size8, size16, DAE_MAX_8B_COLS_NUM, DAE_MAX_16B_COLS_NUM);
return -WD_EINVAL;
@@ -708,7 +707,7 @@ static int agg_output_num_check(struct wd_agg_col_info *agg_cols, __u32 cols_num
return WD_SUCCESS;
}
-static int hashagg_init_param_check(struct wd_agg_sess_setup *setup, __u16 hw_type)
+static int hashagg_init_param_check(struct wd_agg_sess_setup *setup)
{
int ret;
@@ -735,7 +734,7 @@ static int hashagg_init_param_check(struct wd_agg_sess_setup *setup, __u16 hw_ty
return -WD_EINVAL;
return agg_output_num_check(setup->agg_cols_info, setup->agg_cols_num,
- setup->is_count_all, hw_type);
+ setup->is_count_all);
}
static int transfer_key_col_info(struct wd_key_col_info *key_cols,
@@ -1236,7 +1235,7 @@ static int hashagg_sess_priv_init(struct wd_alg_driver *drv,
h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[0].ctx);
qp = (struct hisi_qp *)h_qp;
- ret = hashagg_init_param_check(setup, qp->q_info.hw_type);
+ ret = hashagg_init_param_check(setup);
if (ret)
return -WD_EINVAL;
--
2.33.0
1
0
06 Jan '26
From: Weili Qian <qianweili(a)huawei.com>
When looking up the corresponding driver by algorithm type,
since the driver does not save the algorithm type, it cannot
be directly obtained. Therefore, the algorithm type should be
saved during algorithm registration.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
include/wd_alg.h | 2 ++
libwd.map | 1 +
wd_alg.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++
wd_util.c | 94 ++++--------------------------------------------
4 files changed, 102 insertions(+), 87 deletions(-)
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 5ff73ca..848bdf1 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -145,6 +145,7 @@ struct wd_alg_list {
struct wd_alg_driver *drv;
struct wd_alg_list *next;
+ char alg_type[ALG_NAME_SIZE];
};
/*
@@ -178,6 +179,7 @@ int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf);
void wd_alg_driver_exit(struct wd_alg_driver *drv);
int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg);
int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg);
+int wd_get_alg_type(const char *alg_name, char *alg_type);
struct wd_alg_list *wd_get_alg_head(void);
diff --git a/libwd.map b/libwd.map
index 90eb5c5..5d732d0 100644
--- a/libwd.map
+++ b/libwd.map
@@ -53,6 +53,7 @@ global:
wd_alg_driver_exit;
wd_alg_driver_send;
wd_alg_driver_recv;
+ wd_get_alg_type;
wd_find_ctx;
wd_get_dev_id;
diff --git a/wd_alg.c b/wd_alg.c
index 9c7c0fd..919483b 100644
--- a/wd_alg.c
+++ b/wd_alg.c
@@ -24,6 +24,97 @@ static struct wd_alg_list *alg_list_tail = &alg_list_head;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+struct acc_alg_item {
+ const char *name;
+ const char *algtype;
+};
+
+static struct acc_alg_item alg_options[] = {
+ {"zlib", "zlib"},
+ {"gzip", "gzip"},
+ {"deflate", "deflate"},
+ {"lz77_zstd", "lz77_zstd"},
+ {"lz4", "lz4"},
+ {"lz77_only", "lz77_only"},
+ {"hashagg", "hashagg"},
+ {"udma", "udma"},
+ {"hashjoin", "hashjoin"},
+ {"gather", "gather"},
+ {"join-gather", "hashjoin"},
+
+ {"rsa", "rsa"},
+ {"dh", "dh"},
+ {"ecdh", "ecdh"},
+ {"x25519", "x25519"},
+ {"x448", "x448"},
+ {"ecdsa", "ecdsa"},
+ {"sm2", "sm2"},
+
+ {"ecb(aes)", "cipher"},
+ {"cbc(aes)", "cipher"},
+ {"xts(aes)", "cipher"},
+ {"ofb(aes)", "cipher"},
+ {"cfb(aes)", "cipher"},
+ {"ctr(aes)", "cipher"},
+ {"cbc-cs1(aes)", "cipher"},
+ {"cbc-cs2(aes)", "cipher"},
+ {"cbc-cs3(aes)", "cipher"},
+ {"ecb(sm4)", "cipher"},
+ {"xts(sm4)", "cipher"},
+ {"cbc(sm4)", "cipher"},
+ {"ofb(sm4)", "cipher"},
+ {"cfb(sm4)", "cipher"},
+ {"ctr(sm4)", "cipher"},
+ {"cbc-cs1(sm4)", "cipher"},
+ {"cbc-cs2(sm4)", "cipher"},
+ {"cbc-cs3(sm4)", "cipher"},
+ {"ecb(des)", "cipher"},
+ {"cbc(des)", "cipher"},
+ {"ecb(des3_ede)", "cipher"},
+ {"cbc(des3_ede)", "cipher"},
+
+ {"ccm(aes)", "aead"},
+ {"gcm(aes)", "aead"},
+ {"ccm(sm4)", "aead"},
+ {"gcm(sm4)", "aead"},
+ {"authenc(generic,cbc(aes))", "aead"},
+ {"authenc(generic,cbc(sm4))", "aead"},
+
+ {"sm3", "digest"},
+ {"md5", "digest"},
+ {"sha1", "digest"},
+ {"sha256", "digest"},
+ {"sha224", "digest"},
+ {"sha384", "digest"},
+ {"sha512", "digest"},
+ {"sha512-224", "digest"},
+ {"sha512-256", "digest"},
+ {"cmac(aes)", "digest"},
+ {"gmac(aes)", "digest"},
+ {"xcbc-mac-96(aes)", "digest"},
+ {"xcbc-prf-128(aes)", "digest"},
+ {"", ""}
+};
+
+int wd_get_alg_type(const char *alg_name, char *alg_type)
+{
+ __u64 i;
+
+ if (!alg_name || !alg_type) {
+ WD_ERR("invalid: alg_name or alg_type is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(alg_options); i++) {
+ if (strcmp(alg_name, alg_options[i].name) == 0) {
+ (void)strcpy(alg_type, alg_options[i].algtype);
+ return 0;
+ }
+ }
+
+ return -WD_EINVAL;
+}
+
static bool wd_check_accel_dev(const char *dev_name)
{
struct dirent *dev_dir;
@@ -182,6 +273,7 @@ int wd_alg_driver_register(struct wd_alg_driver *drv)
return -WD_ENOMEM;
}
+ (void)wd_get_alg_type(drv->alg_name, new_alg->alg_type);
strncpy(new_alg->alg_name, drv->alg_name, ALG_NAME_SIZE - 1);
strncpy(new_alg->drv_name, drv->drv_name, DEV_NAME_LEN - 1);
new_alg->priority = drv->priority;
diff --git a/wd_util.c b/wd_util.c
index 138a078..67a46a6 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -98,78 +98,6 @@ struct drv_lib_list {
struct drv_lib_list *next;
};
-struct acc_alg_item {
- const char *name;
- const char *algtype;
-};
-
-static struct acc_alg_item alg_options[] = {
- {"zlib", "zlib"},
- {"gzip", "gzip"},
- {"deflate", "deflate"},
- {"lz77_zstd", "lz77_zstd"},
- {"lz4", "lz4"},
- {"lz77_only", "lz77_only"},
- {"hashagg", "hashagg"},
- {"udma", "udma"},
- {"hashjoin", "hashjoin"},
- {"gather", "gather"},
- {"join-gather", "hashjoin"},
-
- {"rsa", "rsa"},
- {"dh", "dh"},
- {"ecdh", "ecdh"},
- {"x25519", "x25519"},
- {"x448", "x448"},
- {"ecdsa", "ecdsa"},
- {"sm2", "sm2"},
-
- {"ecb(aes)", "cipher"},
- {"cbc(aes)", "cipher"},
- {"xts(aes)", "cipher"},
- {"ofb(aes)", "cipher"},
- {"cfb(aes)", "cipher"},
- {"ctr(aes)", "cipher"},
- {"cbc-cs1(aes)", "cipher"},
- {"cbc-cs2(aes)", "cipher"},
- {"cbc-cs3(aes)", "cipher"},
- {"ecb(sm4)", "cipher"},
- {"xts(sm4)", "cipher"},
- {"cbc(sm4)", "cipher"},
- {"ofb(sm4)", "cipher"},
- {"cfb(sm4)", "cipher"},
- {"ctr(sm4)", "cipher"},
- {"cbc-cs1(sm4)", "cipher"},
- {"cbc-cs2(sm4)", "cipher"},
- {"cbc-cs3(sm4)", "cipher"},
- {"ecb(des)", "cipher"},
- {"cbc(des)", "cipher"},
- {"ecb(des3_ede)", "cipher"},
- {"cbc(des3_ede)", "cipher"},
-
- {"ccm(aes)", "aead"},
- {"gcm(aes)", "aead"},
- {"ccm(sm4)", "aead"},
- {"gcm(sm4)", "aead"},
- {"authenc(generic,cbc(aes))", "aead"},
- {"authenc(generic,cbc(sm4))", "aead"},
-
- {"sm3", "digest"},
- {"md5", "digest"},
- {"sha1", "digest"},
- {"sha256", "digest"},
- {"sha224", "digest"},
- {"sha384", "digest"},
- {"sha512", "digest"},
- {"sha512-224", "digest"},
- {"sha512-256", "digest"},
- {"cmac(aes)", "digest"},
- {"gmac(aes)", "digest"},
- {"xcbc-mac-96(aes)", "digest"},
- {"xcbc-prf-128(aes)", "digest"},
- {"", ""}
-};
-
static void *wd_internal_alloc(void *usr, size_t size)
{
if (size != 0)
@@ -2013,18 +1941,6 @@ int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched)
return 0;
}
-static void wd_get_alg_type(const char *alg_name, char *alg_type)
-{
- __u64 i;
-
- for (i = 0; i < ARRAY_SIZE(alg_options); i++) {
- if (strcmp(alg_name, alg_options[i].name) == 0) {
- (void)strcpy(alg_type, alg_options[i].algtype);
- break;
- }
- }
-}
-
static int wd_alg_init_fallback(struct wd_alg_driver *fb_driver)
{
if (!fb_driver->init) {
@@ -2175,7 +2091,7 @@ static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const cha
char *left, *section, *start;
struct uacce_dev_list *list;
int is_comp;
- int ret = 0;
+ int ret;
/* COMP environment variable's format is different, mark it */
is_comp = strncmp(name, "WD_COMP_CTX_NUM", strlen(name)) ? 0 : 1;
@@ -2186,7 +2102,10 @@ static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const cha
if (!start)
return -WD_ENOMEM;
- wd_get_alg_type(alg_name, alg_type);
+ ret = wd_get_alg_type(alg_name, alg_type);
+ if (ret)
+ return ret;
+
list = wd_get_accel_list(alg_type);
if (!list) {
WD_ERR("failed to get devices!\n");
@@ -3112,7 +3031,8 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs)
}
break;
case UADK_ALG_HW:
- wd_get_alg_type(alg, alg_type);
+ if (wd_get_alg_type(alg, alg_type))
+ return -WD_EINVAL;
(void)strcpy(attrs->alg, alg_type);
ctx_config = calloc(1, sizeof(*ctx_config));
--
2.33.0
1
4
您好!
sig-AccLib 邀请您参加 2025-12-24 11:00 召开的Zoom会议
会议主题:【2025/12/24 AccLIb SIG 双周例会 11:00 - 12:00】
会议链接:https://us06web.zoom.us/j/82679099901?pwd=rhb41PVIzL4V7ST8egX5bRqqq4Fag6.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-12-24 11:00,
The subject of the conference is 【2025/12/24 AccLIb SIG 双周例会 11:00 - 12:00】
You can join the meeting at https://us06web.zoom.us/j/82679099901?pwd=rhb41PVIzL4V7ST8egX5bRqqq4Fag6.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
18 Dec '25
From: parm64 <parm64(a)huawei.com>
Add support for multiple RSA padding modes with OpenSSL provider mechanism.
1. RSA_X931_PADDING and RSA_PKCS1_PSS_PADDING for signing and verification.
2. RSA_PKCS1_OAEP_PADDING and RSA_PKCS1_WITH_TLS_PADDING for encryption and
decryption.
Weili Qian (1):
uadk_provider/dh: set meth flags when new dh
Zhushuai Yin (2):
uadk_engine: fix the SM2 x25519 x448 err in OpenSSL3.0
uadk_provider: prov added compilation options
lizhi (8):
uadk_provider: split RSA algorithm into four functional components
uadk_provider: add some RSA utils functions to adapt RSA with several
padding modes
uadk_provider: adapt rsa signature operation with X931 and PKCS1_PSS
padding modes
uadk_provider: adapt rsa encryption operation with OAEP and
PKCS1_WITH_TLS padding modes
provider: optimize hardware version and availability queries using
global variables
uadk_provider: move several macro definitions to shared header file
uadk_engine: delete several unused functions
uadk_engine: fixup a bug in rsa X931 padding mode
src/Makefile.am | 9 +-
src/uadk_ecx.c | 152 +-
src/uadk_pkey.c | 2 +
src/uadk_pkey.h | 3 -
src/uadk_prov.h | 11 +-
src/uadk_prov_aead.c | 1 -
src/uadk_prov_cipher.c | 18 +-
src/uadk_prov_dh.c | 107 +-
src/uadk_prov_digest.c | 15 +-
src/uadk_prov_hmac.c | 122 +-
src/uadk_prov_init.c | 10 +-
src/uadk_prov_pkey.c | 13 +-
src/uadk_prov_pkey.h | 12 +-
src/uadk_prov_rsa.c | 2974 ++-----------------------------------
src/uadk_prov_rsa.h | 179 +++
src/uadk_prov_rsa_enc.c | 692 +++++++++
src/uadk_prov_rsa_kmgmt.c | 975 ++++++++++++
src/uadk_prov_rsa_sign.c | 1676 +++++++++++++++++++++
src/uadk_prov_rsa_utils.c | 138 ++
src/uadk_rsa.c | 4 +-
20 files changed, 4156 insertions(+), 2957 deletions(-)
create mode 100644 src/uadk_prov_rsa.h
create mode 100644 src/uadk_prov_rsa_enc.c
create mode 100644 src/uadk_prov_rsa_kmgmt.c
create mode 100644 src/uadk_prov_rsa_sign.c
create mode 100644 src/uadk_prov_rsa_utils.c
--
2.43.0
1
11
16 Dec '25
From: parm64 <parm64(a)huawei.com>
Add support for multiple RSA padding modes with OpenSSL provider mechanism.
1. RSA_X931_PADDING and RSA_PKCS1_PSS_PADDING for signing and verification.
2. RSA_PKCS1_OAEP_PADDING and RSA_PKCS1_WITH_TLS_PADDING for encryption and
decryption.
Weili Qian (1):
uadk_provider/dh: set meth flags when new dh
Zhushuai Yin (2):
uadk_engine: fix the SM2 x25519 x448 err in OpenSSL3.0
uadk_provider: prov added compilation options
lizhi (8):
uadk_provider: split RSA algorithm into four functional components
uadk_provider: add some RSA utils functions to adapt RSA with several
padding modes
uadk_provider: adapt rsa signature operation with X931 and PKCS1_PSS
padding modes
uadk_provider: adapt rsa encryption operation with OAEP and
PKCS1_WITH_TLS padding modes
provider: optimize hardware version and availability queries using
global variables
uadk_provider: move several macro definitions to shared header file
uadk_engine: delete several unused functions
uadk_engine: fixup a bug in rsa X931 padding mode
src/Makefile.am | 9 +-
src/uadk_ecx.c | 152 +-
src/uadk_pkey.c | 2 +
src/uadk_pkey.h | 3 -
src/uadk_prov.h | 11 +-
src/uadk_prov_aead.c | 1 -
src/uadk_prov_cipher.c | 18 +-
src/uadk_prov_dh.c | 107 +-
src/uadk_prov_digest.c | 15 +-
src/uadk_prov_hmac.c | 122 +-
src/uadk_prov_init.c | 10 +-
src/uadk_prov_pkey.c | 13 +-
src/uadk_prov_pkey.h | 12 +-
src/uadk_prov_rsa.c | 2974 ++-----------------------------------
src/uadk_prov_rsa.h | 179 +++
src/uadk_prov_rsa_enc.c | 692 +++++++++
src/uadk_prov_rsa_kmgmt.c | 975 ++++++++++++
src/uadk_prov_rsa_sign.c | 1676 +++++++++++++++++++++
src/uadk_prov_rsa_utils.c | 138 ++
src/uadk_rsa.c | 4 +-
20 files changed, 4156 insertions(+), 2957 deletions(-)
create mode 100644 src/uadk_prov_rsa.h
create mode 100644 src/uadk_prov_rsa_enc.c
create mode 100644 src/uadk_prov_rsa_kmgmt.c
create mode 100644 src/uadk_prov_rsa_sign.c
create mode 100644 src/uadk_prov_rsa_utils.c
--
2.43.0
1
11
From: Zhushuai Yin <yinzhushuai(a)huawei.com>
When the input is 0, the hardware will also access the
src address. In this case, src is NULL, which will cause
the hardware to report an error.
Signed-off-by: Zhushuai Yin <yinzhushuai(a)huawei.com>
---
drv/hisi_sec.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 1e95ce5..d19afe2 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -1751,7 +1751,11 @@ static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *w
sqe.sds_sa_type |= (__u8)(de | scene);
sqe.type2.alen_ivllen |= (__u32)msg->in_bytes;
- sqe.type2.data_src_addr = (__u64)(uintptr_t)msg->in;
+ /* avoid HW accessing address 0 when the pointer is NULL */
+ if (msg->in)
+ sqe.type2.data_src_addr = (__u64)(uintptr_t)msg->in;
+ else
+ sqe.type2.data_src_addr = (__u64)(uintptr_t)msg->out;
sqe.type2.mac_addr = (__u64)(uintptr_t)msg->out;
ret = fill_digest_bd2_alg(msg, &sqe);
@@ -1987,7 +1991,11 @@ static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void
}
sqe.a_len_key = (__u32)msg->in_bytes;
- sqe.data_src_addr = (__u64)(uintptr_t)msg->in;
+ /* avoid HW accessing address 0 when the pointer is NULL */
+ if (msg->in)
+ sqe.data_src_addr = (__u64)(uintptr_t)msg->in;
+ else
+ sqe.data_src_addr = (__u64)(uintptr_t)msg->out;
sqe.mac_addr = (__u64)(uintptr_t)msg->out;
ret = fill_digest_bd3_alg(msg, &sqe);
--
2.43.0
1
0
From: Zongyu Wu <wuzongyu1(a)huawei.com>
Fix compilation warning in the UADK module regarding an unused variable.
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 8 ++---
v1/test/test_mm/test_wd_mem.c | 4 +--
v1/test/wd_sched.c | 1 -
wd_util.c | 42 ++++++++++++++++--------
4 files changed, 33 insertions(+), 22 deletions(-)
diff --git a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
index 7a3be22..21ec30c 100644
--- a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
+++ b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
@@ -27,7 +27,6 @@ static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
{
unsigned int flags = 0;
struct q_info *qinfo;
- void *pool;
int i;
qinfo = sched->qs[0].qinfo;
@@ -54,12 +53,13 @@ static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
{
- int ret, i, j;
unsigned int flags = 0;
struct q_info *qinfo;
struct wd_blkpool_setup mm_setup;
struct wd_sglpool_setup sp;
void *pool;
+ int ret, j;
+ int i = 0;
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
@@ -260,9 +260,7 @@ err_with_msgs:
int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
{
- int ret, j, k;
- unsigned int flags;
- struct q_info *qinfo;
+ int ret;
ret = wd_sched_preinit(sched, data_fmt);
if (ret < 0)
diff --git a/v1/test/test_mm/test_wd_mem.c b/v1/test/test_mm/test_wd_mem.c
index e2eec60..a1f55db 100644
--- a/v1/test/test_mm/test_wd_mem.c
+++ b/v1/test/test_mm/test_wd_mem.c
@@ -208,7 +208,7 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_request_queue(&pdata->qinfo1.q);
+ ret = wd_request_queue(pdata->qinfo1.q);
if (ret) {
wd_release_queue(&rsa_q);
MMT_PRT("Proc-%d, thrd-%d:rsa queue fail!\n",
@@ -226,7 +226,7 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_request_queue(&pdata->qinfo2.q);
+ ret = wd_request_queue(pdata->qinfo2.q);
if (ret) {
MMT_PRT("Proc-%d, thrd-%d:zlib queue fail!\n",
pid, thread_id);
diff --git a/v1/test/wd_sched.c b/v1/test/wd_sched.c
index ce1d260..54f400a 100644
--- a/v1/test/wd_sched.c
+++ b/v1/test/wd_sched.c
@@ -26,7 +26,6 @@ static int wd_sched_pre_uninit(struct wd_scheduler *sched)
{
unsigned int flags = 0;
struct q_info *qinfo;
- void *pool;
int i;
qinfo = sched->qs[0].qinfo;
diff --git a/wd_util.c b/wd_util.c
index daa7309..138a078 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -2459,19 +2459,22 @@ static struct drv_lib_list *load_libraries_from_config(const char *config_path,
FILE *config_file;
int ret;
- path_buf = calloc(WD_PATH_DIR_NUM, PATH_MAX);
- if (!path_buf) {
- WD_ERR("fail to alloc memery for path_buf.\n");
- return NULL;
+ lib_path = calloc(1, PATH_MAX);
+ if (!lib_path) {
+ WD_ERR("Failed to alloc memery for lib_path.\n");
+ return head;
+ }
+
+ line = calloc(1, PATH_MAX);
+ if (!line) {
+ WD_ERR("Failed to alloc memery for lib_line.\n");
+ goto free_path;
}
- lib_path = path_buf;
- line = path_buf + PATH_MAX;
config_file = fopen(config_path, "r");
if (!config_file) {
WD_ERR("Failed to open config file: %s\n", config_path);
- free(path_buf);
- return NULL;
+ goto free_line;
}
/* Read config file line by line */
@@ -2486,8 +2489,12 @@ static struct drv_lib_list *load_libraries_from_config(const char *config_path,
create_lib_to_list(lib_path, &head);
}
- free(path_buf);
fclose(config_file);
+
+free_line:
+ free(line);
+free_path:
+ free(lib_path);
return head;
}
@@ -2533,15 +2540,21 @@ void *wd_dlopen_drv(const char *cust_lib_dir)
int ret, len;
DIR *wd_dir;
- path_buf = calloc(WD_PATH_DIR_NUM + 1, PATH_MAX);
+ path_buf = calloc(WD_PATH_DIR_NUM, PATH_MAX);
if (!path_buf) {
- WD_ERR("fail to alloc memory for path buffers.\n");
- return NULL;
+ WD_ERR("Failed to alloc memory for path_buf buffers.\n");
+ return head;
+ }
+
+ config_path = calloc(1, PATH_MAX);
+ if (!config_path) {
+ WD_ERR("Failed to alloc memory for config_path buffers.\n");
+ free(path_buf);
+ return head;
}
lib_dir_path = path_buf;
- config_path = path_buf + PATH_MAX;
- lib_path = config_path + PATH_MAX;
+ lib_path = path_buf + PATH_MAX;
if (!cust_lib_dir) {
ret = wd_get_lib_file_path(NULL, lib_dir_path, true);
@@ -2582,6 +2595,7 @@ close_dir:
closedir(wd_dir);
free_path:
free(path_buf);
+ free(config_path);
return (void *)head;
}
--
2.33.0
1
0
您好!
sig-AccLib 邀请您参加 2025-12-10 11:00 召开的Zoom会议
会议主题:【2025/12/10 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/89936554365?pwd=rGBVuuAFuM1aWG32BRhNs0fk2bya0a.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-12-10 11:00,
The subject of the conference is 【2025/12/10 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/89936554365?pwd=rGBVuuAFuM1aWG32BRhNs0fk2bya0a.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
From: Weili Qian <qianweili(a)huawei.com>
UADK adds the ability to obtain device usage. When the device
is not bound to a driver, it retrieves the usage through sysfs
files. When the device is bound to a driver, it directly reads the
hardware registers to obtain the usage.
Upstream: Yes
AR: AR20230722287656
Feature or Bugfix: Feature
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
drv/hisi_comp.c | 39 +++++++++
drv/hisi_dae.c | 5 --
drv/hisi_dae.h | 1 +
drv/hisi_dae_common.c | 38 +++++++++
drv/hisi_dae_join_gather.c | 1 +
drv/hisi_hpre.c | 69 ++++++++++++++--
drv/hisi_qm_udrv.c | 36 +++++++++
drv/hisi_qm_udrv.h | 1 +
drv/hisi_sec.c | 35 +++++++-
drv/hisi_udma.c | 35 +++++++-
include/wd.h | 8 ++
include/wd_alg.h | 9 +++
libwd.map | 3 +
wd.c | 162 +++++++++++++++++++++++++++++++++++++
wd_alg.c | 124 ++++++++++++++++++++++++++++
wd_util.c | 93 ++-------------------
16 files changed, 560 insertions(+), 99 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 65dcf8e..cad21fa 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -1755,6 +1755,44 @@ static int hisi_zip_comp_recv(struct wd_alg_driver *drv, handle_t ctx, void *com
return 0;
}
+static int hisi_zip_get_usage(void *param)
+{
+ struct hisi_dev_usage *zip_usage = (struct hisi_dev_usage *)param;
+ struct wd_alg_driver *drv = zip_usage->drv;
+ struct wd_ctx_config_internal *config;
+ struct hisi_zip_ctx *priv;
+ char *ctx_dev_name;
+ handle_t ctx = 0;
+ handle_t qp = 0;
+ __u32 i;
+
+ if (zip_usage->alg_op_type >= drv->op_type_num) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", zip_usage->alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ priv = (struct hisi_zip_ctx *)drv->priv;
+ if (!priv)
+ return -WD_EACCES;
+
+ config = &priv->config;
+ for (i = 0; i < config->ctx_num; i++) {
+ ctx_dev_name = wd_ctx_get_dev_name(config->ctxs[i].ctx);
+ if (!strcmp(zip_usage->dev_name, ctx_dev_name)) {
+ ctx = config->ctxs[i].ctx;
+ break;
+ }
+ }
+
+ if (ctx)
+ qp = (handle_t)wd_ctx_get_priv(ctx);
+
+ if (qp)
+ return hisi_qm_get_usage(qp, zip_usage->alg_op_type);
+
+ return -WD_EACCES;
+}
+
#define GEN_ZIP_ALG_DRIVER(zip_alg_name) \
{\
.drv_name = "hisi_zip",\
@@ -1768,6 +1806,7 @@ static int hisi_zip_comp_recv(struct wd_alg_driver *drv, handle_t ctx, void *com
.exit = hisi_zip_exit,\
.send = hisi_zip_comp_send,\
.recv = hisi_zip_comp_recv,\
+ .get_usage = hisi_zip_get_usage, \
}
static struct wd_alg_driver zip_alg_driver[] = {
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index 49387aa..d7b34c2 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -1283,11 +1283,6 @@ static int agg_hash_table_init(struct wd_alg_driver *drv,
hash_table, agg_ctx->row_size);
}
-static int dae_get_usage(void *param)
-{
- return 0;
-}
-
static int dae_get_extend_ops(void *ops)
{
struct wd_agg_ops *agg_ops = (struct wd_agg_ops *)ops;
diff --git a/drv/hisi_dae.h b/drv/hisi_dae.h
index 050b872..f82b13c 100644
--- a/drv/hisi_dae.h
+++ b/drv/hisi_dae.h
@@ -220,6 +220,7 @@ int get_free_ext_addr(struct dae_extend_addr *ext_addr);
void put_ext_addr(struct dae_extend_addr *ext_addr, int idx);
__u32 get_data_type_size(enum dae_data_type type, __u16 data_info);
int dae_decimal_precision_check(__u16 data_info, bool longdecimal);
+int dae_get_usage(void *param);
#ifdef __cplusplus
}
diff --git a/drv/hisi_dae_common.c b/drv/hisi_dae_common.c
index 5cfc105..c077d1d 100644
--- a/drv/hisi_dae_common.c
+++ b/drv/hisi_dae_common.c
@@ -389,3 +389,41 @@ void dae_exit(struct wd_alg_driver *drv)
free(priv);
drv->priv = NULL;
}
+
+int dae_get_usage(void *param)
+{
+ struct hisi_dev_usage *dae_usage = (struct hisi_dev_usage *)param;
+ struct wd_alg_driver *drv = dae_usage->drv;
+ struct wd_ctx_config_internal *config;
+ struct hisi_dae_ctx *priv;
+ char *ctx_dev_name;
+ handle_t ctx = 0;
+ handle_t qp = 0;
+ __u32 i;
+
+ if (dae_usage->alg_op_type >= drv->op_type_num) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", dae_usage->alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ priv = (struct hisi_dae_ctx *)drv->priv;
+ if (!priv)
+ return -WD_EACCES;
+
+ config = &priv->config;
+ for (i = 0; i < config->ctx_num; i++) {
+ ctx_dev_name = wd_ctx_get_dev_name(config->ctxs[i].ctx);
+ if (!strcmp(dae_usage->dev_name, ctx_dev_name)) {
+ ctx = config->ctxs[i].ctx;
+ break;
+ }
+ }
+
+ if (ctx)
+ qp = (handle_t)wd_ctx_get_priv(ctx);
+
+ if (qp)
+ return hisi_qm_get_usage(qp, DAE_SQC_ALG_TYPE);
+
+ return -WD_EACCES;
+}
diff --git a/drv/hisi_dae_join_gather.c b/drv/hisi_dae_join_gather.c
index 63c7670..92fae1a 100644
--- a/drv/hisi_dae_join_gather.c
+++ b/drv/hisi_dae_join_gather.c
@@ -1007,6 +1007,7 @@ static int join_gather_get_extend_ops(void *ops)
.send = join_gather_send,\
.recv = join_gather_recv,\
.get_extend_ops = join_gather_get_extend_ops,\
+ .get_usage = dae_get_usage,\
}
static struct wd_alg_driver join_gather_driver[] = {
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index f3f2451..3c41826 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -2777,9 +2777,68 @@ static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
return ecc_sqe_parse((struct hisi_qp *)h_qp, msg, &hw_msg);
}
-static int hpre_get_usage(void *param)
+static handle_t hpre_find_dev_qp(struct wd_alg_driver *drv, const char *dev_name)
{
- return WD_SUCCESS;
+ struct wd_ctx_config_internal *config;
+ struct hisi_hpre_ctx *priv;
+ char *ctx_dev_name;
+ handle_t ctx = 0;
+ handle_t qp = 0;
+ __u32 i;
+
+ priv = (struct hisi_hpre_ctx *)drv->priv;
+ if (!priv)
+ return 0;
+
+ config = &priv->config;
+ for (i = 0; i < config->ctx_num; i++) {
+ ctx_dev_name = wd_ctx_get_dev_name(config->ctxs[i].ctx);
+ if (!strcmp(ctx_dev_name, dev_name)) {
+ ctx = config->ctxs[i].ctx;
+ break;
+ }
+ }
+
+ if (ctx)
+ qp = (handle_t)wd_ctx_get_priv(ctx);
+
+ return qp;
+}
+
+static int hpre_ecc_get_usage(void *param)
+{
+ struct hisi_dev_usage *hpre_usage = (struct hisi_dev_usage *)param;
+ struct wd_alg_driver *drv = hpre_usage->drv;
+ handle_t qp;
+
+ if (hpre_usage->alg_op_type >= drv->op_type_num) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", hpre_usage->alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ qp = hpre_find_dev_qp(drv, hpre_usage->dev_name);
+ if (qp)
+ return hisi_qm_get_usage(qp, HPRE_HW_V3_ECC_ALG_TYPE);
+
+ return -WD_EACCES;
+}
+
+static int hpre_rsa_get_usage(void *param)
+{
+ struct hisi_dev_usage *hpre_usage = (struct hisi_dev_usage *)param;
+ struct wd_alg_driver *drv = hpre_usage->drv;
+ handle_t qp;
+
+ if (hpre_usage->alg_op_type >= drv->op_type_num) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", hpre_usage->alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ qp = hpre_find_dev_qp(drv, hpre_usage->dev_name);
+ if (qp)
+ return hisi_qm_get_usage(qp, HPRE_HW_V2_ALG_TYPE);
+
+ return -WD_EACCES;
}
static int ecc_sess_eops_init(struct wd_alg_driver *drv, void **params)
@@ -2886,7 +2945,7 @@ static int hpre_ecc_get_extend_ops(void *ops)
.exit = hpre_exit,\
.send = ecc_send,\
.recv = ecc_recv,\
- .get_usage = hpre_get_usage,\
+ .get_usage = hpre_ecc_get_usage,\
.get_extend_ops = hpre_ecc_get_extend_ops,\
}
@@ -2910,7 +2969,7 @@ static struct wd_alg_driver hpre_rsa_driver = {
.exit = hpre_exit,
.send = rsa_send,
.recv = rsa_recv,
- .get_usage = hpre_get_usage,
+ .get_usage = hpre_rsa_get_usage,
};
static struct wd_alg_driver hpre_dh_driver = {
@@ -2925,7 +2984,7 @@ static struct wd_alg_driver hpre_dh_driver = {
.exit = hpre_exit,
.send = dh_send,
.recv = dh_recv,
- .get_usage = hpre_get_usage,
+ .get_usage = hpre_rsa_get_usage,
};
#ifdef WD_STATIC_DRV
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 216b80a..4ddf8a8 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -42,6 +42,12 @@
#define ADDR_ALIGN_64(addr) ((((uintptr_t)(addr) >> 6) + 1) << 6)
+#define QM_TYPE_USAGE_OFFSET 0x1100
+#define QM_DEV_USAGE_OFFSET 16
+#define QM_CHANNEL_ADDR_INTRVL 0x4
+#define QM_MAX_DEV_USAGE 100
+#define QM_DEV_USAGE_RATE 100
+
struct hisi_qm_type {
__u16 qm_ver;
int qm_db_offs;
@@ -154,6 +160,36 @@ static struct hisi_qm_type qm_type[] = {
}
};
+int hisi_qm_get_usage(handle_t h_qp, __u8 type)
+{
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct hisi_qm_queue_info *q_info;
+ __u16 count, usage;
+ __u32 val;
+
+ if (!qp)
+ return -WD_EINVAL;
+
+ q_info = &qp->q_info;
+ if (q_info->hw_type < HISI_QM_API_VER5_BASE) {
+ WD_ERR("invalid: device not support get usage!\n");
+ return -WD_EINVAL;
+ }
+
+ val = wd_ioread32(q_info->mmio_base + QM_TYPE_USAGE_OFFSET +
+ type * QM_CHANNEL_ADDR_INTRVL);
+ count = val >> QM_DEV_USAGE_OFFSET;
+ if (!count) {
+ WD_ERR("failed to get dev count usage!\n");
+ return -WD_EINVAL;
+ }
+
+ usage = (__u16)val * QM_DEV_USAGE_RATE / count;
+ usage = usage > QM_MAX_DEV_USAGE ? QM_MAX_DEV_USAGE : usage;
+
+ return usage;
+}
+
static void hisi_qm_fill_sqe(const void *sqe, struct hisi_qm_queue_info *info,
__u16 tail, __u16 num)
{
diff --git a/drv/hisi_qm_udrv.h b/drv/hisi_qm_udrv.h
index f066881..a7222ce 100644
--- a/drv/hisi_qm_udrv.h
+++ b/drv/hisi_qm_udrv.h
@@ -210,6 +210,7 @@ int hisi_qm_get_free_sqe_num(handle_t h_qp);
*/
__u32 hisi_qm_get_list_size(struct wd_datalist *start_node,
struct wd_datalist *end_node);
+int hisi_qm_get_usage(handle_t h_qp, __u8 type);
#ifdef __cplusplus
}
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index e64fd5c..53bf334 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -600,7 +600,40 @@ static int aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
static int hisi_sec_get_usage(void *param)
{
- return 0;
+ struct hisi_dev_usage *sec_usage = (struct hisi_dev_usage *)param;
+ struct wd_alg_driver *drv = sec_usage->drv;
+ struct wd_ctx_config_internal *config;
+ struct hisi_sec_ctx *priv;
+ char *ctx_dev_name;
+ handle_t ctx = 0;
+ handle_t qp = 0;
+ __u32 i;
+
+ if (sec_usage->alg_op_type >= drv->op_type_num) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", sec_usage->alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ priv = (struct hisi_sec_ctx *)drv->priv;
+ if (!priv)
+ return -WD_EACCES;
+
+ config = &priv->config;
+ for (i = 0; i < config->ctx_num; i++) {
+ ctx_dev_name = wd_ctx_get_dev_name(config->ctxs[i].ctx);
+ if (!strcmp(sec_usage->dev_name, ctx_dev_name)) {
+ ctx = config->ctxs[i].ctx;
+ break;
+ }
+ }
+
+ if (ctx)
+ qp = (handle_t)wd_ctx_get_priv(ctx);
+
+ if (qp)
+ return hisi_qm_get_usage(qp, 0);
+
+ return -WD_EACCES;
}
static int eops_param_check(struct wd_alg_driver *drv, struct wd_mm_ops *mm_ops)
diff --git a/drv/hisi_udma.c b/drv/hisi_udma.c
index 37f0550..a9f5607 100644
--- a/drv/hisi_udma.c
+++ b/drv/hisi_udma.c
@@ -521,7 +521,40 @@ static void udma_exit(struct wd_alg_driver *drv)
static int udma_get_usage(void *param)
{
- return 0;
+ struct hisi_dev_usage *udma_usage = (struct hisi_dev_usage *)param;
+ struct wd_alg_driver *drv = udma_usage->drv;
+ struct wd_ctx_config_internal *config;
+ struct hisi_udma_ctx *priv;
+ char *ctx_dev_name;
+ handle_t ctx = 0;
+ handle_t qp = 0;
+ __u32 i;
+
+ if (udma_usage->alg_op_type >= drv->op_type_num) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", udma_usage->alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ priv = (struct hisi_udma_ctx *)drv->priv;
+ if (!priv)
+ return -WD_EACCES;
+
+ config = &priv->config;
+ for (i = 0; i < config->ctx_num; i++) {
+ ctx_dev_name = wd_ctx_get_dev_name(config->ctxs[i].ctx);
+ if (!strcmp(udma_usage->dev_name, ctx_dev_name)) {
+ ctx = config->ctxs[i].ctx;
+ break;
+ }
+ }
+
+ if (ctx)
+ qp = (handle_t)wd_ctx_get_priv(ctx);
+
+ if (qp)
+ return hisi_qm_get_usage(qp, UDMA_ALG_TYPE);
+
+ return -WD_EACCES;
}
static struct wd_alg_driver udma_driver = {
diff --git a/include/wd.h b/include/wd.h
index b97e5c7..abc745d 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -627,6 +627,14 @@ struct wd_capability {
struct wd_capability *wd_get_alg_cap(void);
void wd_release_alg_cap(struct wd_capability *head);
+/**
+ * wd_get_dev_usage() - Get the device bandwidth usage.
+ * @dev: Indicate device.
+ * @alg_name: Indicates the intention to query the bandwidth usage of the algorithm on the device.
+ * @alg_op_type: algorithm type.
+ */
+int wd_get_dev_usage(struct uacce_dev *dev, const char *alg_name, __u8 alg_op_type);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/wd_alg.h b/include/wd_alg.h
index 5ff73ca..878c595 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -115,6 +115,12 @@ struct wd_alg_driver {
int (*get_extend_ops)(void *ops);
};
+struct hisi_dev_usage {
+ struct wd_alg_driver *drv;
+ char *dev_name;
+ __u8 alg_op_type;
+};
+
/*
* wd_alg_driver_register() - Register a device driver.
* @wd_alg_driver: a device driver that supports an algorithm.
@@ -145,6 +151,7 @@ struct wd_alg_list {
struct wd_alg_driver *drv;
struct wd_alg_list *next;
+ char alg_type[ALG_NAME_SIZE];
};
/*
@@ -178,6 +185,8 @@ int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf);
void wd_alg_driver_exit(struct wd_alg_driver *drv);
int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg);
int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg);
+int wd_alg_get_dev_usage(const char *dev_name, const char *alg_type, __u8 op_type);
+int wd_get_alg_type(const char *alg_name, char *alg_type);
struct wd_alg_list *wd_get_alg_head(void);
diff --git a/libwd.map b/libwd.map
index 90eb5c5..1267a8d 100644
--- a/libwd.map
+++ b/libwd.map
@@ -22,6 +22,7 @@ global:
wd_ctx_set_io_cmd;
wd_ctx_get_region_size;
wd_ctx_get_dev_name;
+ wd_get_dev_usage;
wd_block_alloc;
wd_block_free;
@@ -53,6 +54,8 @@ global:
wd_alg_driver_exit;
wd_alg_driver_send;
wd_alg_driver_recv;
+ wd_alg_get_dev_usage;
+ wd_get_alg_type;
wd_find_ctx;
wd_get_dev_id;
diff --git a/wd.c b/wd.c
index 657fbae..7f26f84 100644
--- a/wd.c
+++ b/wd.c
@@ -23,6 +23,7 @@
#include "wd_internal.h"
#define SYS_CLASS_DIR "/sys/class/uacce"
#define FILE_MAX_SIZE (8 << 20)
+#define WD_DEV_USAGE_SIZE 256
enum UADK_LOG_LEVEL {
WD_LOG_NONE = 0,
@@ -34,6 +35,27 @@ enum UADK_LOG_LEVEL {
static int uadk_log_level = WD_LOG_INVALID;
+struct dev_usage_info {
+ char *dev_name;
+ __u8 alg_op_type;
+ int (*usage_parse_fn)(char *buf, const char *alg_name, __u8 alg_op_type);
+};
+
+static const char * const hpre_ecc_algs[] = {
+ "sm2",
+ "ecdh",
+ "x448",
+ "x25519",
+ "ecdsa"
+};
+
+static const char * const zip_dae_algs[] = {
+ "udma",
+ "hashagg",
+ "hashjoin",
+ "gather",
+};
+
static int wd_check_ctx_type(handle_t h_ctx)
{
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
@@ -986,3 +1008,143 @@ alloc_err:
return NULL;
}
+static int wd_parse_usage_value(char *buf, const char *type_name)
+{
+ char *str;
+ int ret;
+
+ str = strstr(buf, type_name);
+ if (!str)
+ return -WD_EINVAL;
+
+ str += strlen(type_name);
+ ret = strtol(str, NULL, 10);
+ if (ret < 0)
+ WD_ERR("fail to get device usage value, ret %d!\n", ret);
+
+ return ret;
+}
+
+/*
+ * The format of the string obtained from sysfs is fixed
+ * and does not need to consider other scenarios.
+ */
+static int wd_zip_usage_parse_fn(char *buf, const char *alg_name, __u8 alg_op_type)
+{
+ size_t size = ARRAY_SIZE(zip_dae_algs);
+ size_t i;
+
+ for (i = 0; i < size; i++) {
+ if (!strcmp(alg_name, zip_dae_algs[i])) {
+ if (alg_op_type != 0) {
+ WD_ERR("invalid: alg_name %s alg_op_type error!\n", alg_name);
+ return -WD_EINVAL;
+ }
+ return wd_parse_usage_value(buf, "DAE: ");
+ }
+ }
+
+ if (alg_op_type == 0)
+ return wd_parse_usage_value(buf, "COMPRESS: ");
+
+ return wd_parse_usage_value(buf, "DECOMPRESS: ");
+}
+
+static int wd_sec_usage_parse_fn(char *buf, const char *alg_name, __u8 alg_op_type)
+{
+ return wd_parse_usage_value(buf, "SEC: ");
+}
+
+static int wd_hpre_usage_parse_fn(char *buf, const char *alg_name, __u8 alg_op_type)
+{
+ size_t size = ARRAY_SIZE(hpre_ecc_algs);
+ size_t i;
+
+ for (i = 0; i < size; i++) {
+ if (!strcmp(alg_name, hpre_ecc_algs[i]))
+ return wd_parse_usage_value(buf, "ECC: ");
+ }
+
+ return wd_parse_usage_value(buf, "RSA: ");
+}
+
+static const struct dev_usage_info dev_usage_parse[] = {
+ {
+ .dev_name = "hisi_zip",
+ .alg_op_type = 2,
+ .usage_parse_fn = wd_zip_usage_parse_fn
+ }, {
+ .dev_name = "hisi_sec",
+ .alg_op_type = 1,
+ .usage_parse_fn = wd_sec_usage_parse_fn
+ }, {
+ .dev_name = "hisi_hpre",
+ .alg_op_type = 1,
+ .usage_parse_fn = wd_hpre_usage_parse_fn
+ },
+};
+
+static int wd_parse_dev_usage(struct uacce_dev *dev, char *buf,
+ const char *alg_name, __u8 alg_op_type)
+{
+ size_t size = ARRAY_SIZE(dev_usage_parse);
+ size_t i;
+
+ for (i = 0; i < size; i++) {
+ if (strstr(dev->dev_root, dev_usage_parse[i].dev_name))
+ break;
+ }
+
+ if (i == size) {
+ WD_ERR("failed to find parse function!\n");
+ return -WD_EINVAL;
+ }
+
+ if (alg_op_type >= dev_usage_parse[i].alg_op_type) {
+ WD_ERR("invalid: alg_op_type %u is error!\n", alg_op_type);
+ return -WD_EINVAL;
+ }
+
+ return dev_usage_parse[i].usage_parse_fn(buf, alg_name, alg_op_type);
+}
+
+static int wd_read_dev_usage(struct uacce_dev *dev, const char *alg_name, __u8 alg_op_type)
+{
+ char buf[WD_DEV_USAGE_SIZE];
+ int ret;
+
+ ret = access_attr(dev->dev_root, "dev_usage", F_OK);
+ if (ret) {
+ WD_ERR("failed to access dev_usage!\n");
+ return ret;
+ }
+
+ ret = get_str_attr(dev, "dev_usage", buf, WD_DEV_USAGE_SIZE);
+ if (ret < 0)
+ return ret;
+
+ return wd_parse_dev_usage(dev, buf, alg_name, alg_op_type);
+}
+
+int wd_get_dev_usage(struct uacce_dev *dev, const char *alg_name, __u8 alg_op_type)
+{
+ char *dev_name;
+ int ret;
+
+ if (!dev || !alg_name) {
+ WD_ERR("invalid: dev or alg name is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (!dev_has_alg(dev->algs, alg_name)) {
+ WD_ERR("invalid: dev does not support alg %s!\n", alg_name);
+ return -WD_EINVAL;
+ }
+
+ dev_name = wd_get_accel_name(dev->char_dev_path, 0);
+ ret = wd_alg_get_dev_usage(dev_name, alg_name, alg_op_type);
+ if (ret == -WD_EACCES)
+ return wd_read_dev_usage(dev, alg_name, alg_op_type);
+
+ return ret;
+}
diff --git a/wd_alg.c b/wd_alg.c
index 9c7c0fd..c819d32 100644
--- a/wd_alg.c
+++ b/wd_alg.c
@@ -24,6 +24,97 @@ static struct wd_alg_list *alg_list_tail = &alg_list_head;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+struct acc_alg_item {
+ const char *name;
+ const char *algtype;
+};
+
+static struct acc_alg_item alg_options[] = {
+ {"zlib", "zlib"},
+ {"gzip", "gzip"},
+ {"deflate", "deflate"},
+ {"lz77_zstd", "lz77_zstd"},
+ {"lz4", "lz4"},
+ {"lz77_only", "lz77_only"},
+ {"hashagg", "hashagg"},
+ {"udma", "udma"},
+ {"hashjoin", "hashjoin"},
+ {"gather", "gather"},
+ {"join-gather", "hashjoin"},
+
+ {"rsa", "rsa"},
+ {"dh", "dh"},
+ {"ecdh", "ecdh"},
+ {"x25519", "x25519"},
+ {"x448", "x448"},
+ {"ecdsa", "ecdsa"},
+ {"sm2", "sm2"},
+
+ {"ecb(aes)", "cipher"},
+ {"cbc(aes)", "cipher"},
+ {"xts(aes)", "cipher"},
+ {"ofb(aes)", "cipher"},
+ {"cfb(aes)", "cipher"},
+ {"ctr(aes)", "cipher"},
+ {"cbc-cs1(aes)", "cipher"},
+ {"cbc-cs2(aes)", "cipher"},
+ {"cbc-cs3(aes)", "cipher"},
+ {"ecb(sm4)", "cipher"},
+ {"xts(sm4)", "cipher"},
+ {"cbc(sm4)", "cipher"},
+ {"ofb(sm4)", "cipher"},
+ {"cfb(sm4)", "cipher"},
+ {"ctr(sm4)", "cipher"},
+ {"cbc-cs1(sm4)", "cipher"},
+ {"cbc-cs2(sm4)", "cipher"},
+ {"cbc-cs3(sm4)", "cipher"},
+ {"ecb(des)", "cipher"},
+ {"cbc(des)", "cipher"},
+ {"ecb(des3_ede)", "cipher"},
+ {"cbc(des3_ede)", "cipher"},
+
+ {"ccm(aes)", "aead"},
+ {"gcm(aes)", "aead"},
+ {"ccm(sm4)", "aead"},
+ {"gcm(sm4)", "aead"},
+ {"authenc(generic,cbc(aes))", "aead"},
+ {"authenc(generic,cbc(sm4))", "aead"},
+
+ {"sm3", "digest"},
+ {"md5", "digest"},
+ {"sha1", "digest"},
+ {"sha256", "digest"},
+ {"sha224", "digest"},
+ {"sha384", "digest"},
+ {"sha512", "digest"},
+ {"sha512-224", "digest"},
+ {"sha512-256", "digest"},
+ {"cmac(aes)", "digest"},
+ {"gmac(aes)", "digest"},
+ {"xcbc-mac-96(aes)", "digest"},
+ {"xcbc-prf-128(aes)", "digest"},
+ {"", ""}
+};
+
+int wd_get_alg_type(const char *alg_name, char *alg_type)
+{
+ __u64 i;
+
+ if (!alg_name || !alg_type) {
+ WD_ERR("invalid: alg_name or alg_type is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(alg_options); i++) {
+ if (strcmp(alg_name, alg_options[i].name) == 0) {
+ (void)strcpy(alg_type, alg_options[i].algtype);
+ return 0;
+ }
+ }
+
+ return -WD_EINVAL;
+}
+
static bool wd_check_accel_dev(const char *dev_name)
{
struct dirent *dev_dir;
@@ -182,6 +273,7 @@ int wd_alg_driver_register(struct wd_alg_driver *drv)
return -WD_ENOMEM;
}
+ (void)wd_get_alg_type(drv->alg_name, new_alg->alg_type);
strncpy(new_alg->alg_name, drv->alg_name, ALG_NAME_SIZE - 1);
strncpy(new_alg->drv_name, drv->drv_name, DEV_NAME_LEN - 1);
new_alg->priority = drv->priority;
@@ -393,3 +485,35 @@ int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
return drv->recv(drv, ctx, msg);
}
+int wd_alg_get_dev_usage(const char *dev_name, const char *alg_type, __u8 alg_op_type)
+{
+ struct wd_alg_list *pnext = alg_list_head.next;
+ struct hisi_dev_usage dev_usage;
+ struct wd_alg_driver *drv;
+
+ if (!dev_name || !alg_type) {
+ WD_ERR("dev_name or alg_type is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ while (pnext) {
+ if (strstr(dev_name, pnext->drv_name) &&
+ !strcmp(alg_type, pnext->alg_type))
+ break;
+
+ pnext = pnext->next;
+ }
+
+ if (!pnext)
+ return -WD_EACCES;
+
+ drv = pnext->drv;
+ if (!drv->get_usage)
+ return -WD_EINVAL;
+
+ dev_usage.drv = drv;
+ dev_usage.alg_op_type = alg_op_type;
+ dev_usage.dev_name = dev_name;
+
+ return drv->get_usage(&dev_usage);
+}
diff --git a/wd_util.c b/wd_util.c
index daa7309..bec23f5 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -98,78 +98,6 @@ struct drv_lib_list {
struct drv_lib_list *next;
};
-struct acc_alg_item {
- const char *name;
- const char *algtype;
-};
-
-static struct acc_alg_item alg_options[] = {
- {"zlib", "zlib"},
- {"gzip", "gzip"},
- {"deflate", "deflate"},
- {"lz77_zstd", "lz77_zstd"},
- {"lz4", "lz4"},
- {"lz77_only", "lz77_only"},
- {"hashagg", "hashagg"},
- {"udma", "udma"},
- {"hashjoin", "hashjoin"},
- {"gather", "gather"},
- {"join-gather", "hashjoin"},
-
- {"rsa", "rsa"},
- {"dh", "dh"},
- {"ecdh", "ecdh"},
- {"x25519", "x25519"},
- {"x448", "x448"},
- {"ecdsa", "ecdsa"},
- {"sm2", "sm2"},
-
- {"ecb(aes)", "cipher"},
- {"cbc(aes)", "cipher"},
- {"xts(aes)", "cipher"},
- {"ofb(aes)", "cipher"},
- {"cfb(aes)", "cipher"},
- {"ctr(aes)", "cipher"},
- {"cbc-cs1(aes)", "cipher"},
- {"cbc-cs2(aes)", "cipher"},
- {"cbc-cs3(aes)", "cipher"},
- {"ecb(sm4)", "cipher"},
- {"xts(sm4)", "cipher"},
- {"cbc(sm4)", "cipher"},
- {"ofb(sm4)", "cipher"},
- {"cfb(sm4)", "cipher"},
- {"ctr(sm4)", "cipher"},
- {"cbc-cs1(sm4)", "cipher"},
- {"cbc-cs2(sm4)", "cipher"},
- {"cbc-cs3(sm4)", "cipher"},
- {"ecb(des)", "cipher"},
- {"cbc(des)", "cipher"},
- {"ecb(des3_ede)", "cipher"},
- {"cbc(des3_ede)", "cipher"},
-
- {"ccm(aes)", "aead"},
- {"gcm(aes)", "aead"},
- {"ccm(sm4)", "aead"},
- {"gcm(sm4)", "aead"},
- {"authenc(generic,cbc(aes))", "aead"},
- {"authenc(generic,cbc(sm4))", "aead"},
-
- {"sm3", "digest"},
- {"md5", "digest"},
- {"sha1", "digest"},
- {"sha256", "digest"},
- {"sha224", "digest"},
- {"sha384", "digest"},
- {"sha512", "digest"},
- {"sha512-224", "digest"},
- {"sha512-256", "digest"},
- {"cmac(aes)", "digest"},
- {"gmac(aes)", "digest"},
- {"xcbc-mac-96(aes)", "digest"},
- {"xcbc-prf-128(aes)", "digest"},
- {"", ""}
-};
-
static void *wd_internal_alloc(void *usr, size_t size)
{
if (size != 0)
@@ -2013,18 +1941,6 @@ int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched)
return 0;
}
-static void wd_get_alg_type(const char *alg_name, char *alg_type)
-{
- __u64 i;
-
- for (i = 0; i < ARRAY_SIZE(alg_options); i++) {
- if (strcmp(alg_name, alg_options[i].name) == 0) {
- (void)strcpy(alg_type, alg_options[i].algtype);
- break;
- }
- }
-}
-
static int wd_alg_init_fallback(struct wd_alg_driver *fb_driver)
{
if (!fb_driver->init) {
@@ -2175,7 +2091,7 @@ static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const cha
char *left, *section, *start;
struct uacce_dev_list *list;
int is_comp;
- int ret = 0;
+ int ret;
/* COMP environment variable's format is different, mark it */
is_comp = strncmp(name, "WD_COMP_CTX_NUM", strlen(name)) ? 0 : 1;
@@ -2186,7 +2102,9 @@ static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const cha
if (!start)
return -WD_ENOMEM;
- wd_get_alg_type(alg_name, alg_type);
+ ret = wd_get_alg_type(alg_name, alg_type);
+ if (ret)
+ return ret;
list = wd_get_accel_list(alg_type);
if (!list) {
WD_ERR("failed to get devices!\n");
@@ -3098,7 +3016,8 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs)
}
break;
case UADK_ALG_HW:
- wd_get_alg_type(alg, alg_type);
+ if (wd_get_alg_type(alg, alg_type))
+ return -WD_EINVAL;
(void)strcpy(attrs->alg, alg_type);
ctx_config = calloc(1, sizeof(*ctx_config));
--
2.33.0
1
7
您好!
sig-AccLib 邀请您参加 2025-11-26 11:00 召开的Zoom会议
会议主题:【2025/11/26 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/81738189438?pwd=pBbpGzVXKm85xvTcYVseW7cijBuaQp.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-11-26 11:00,
The subject of the conference is 【2025/11/26 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/81738189438?pwd=pBbpGzVXKm85xvTcYVseW7cijBuaQp.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
18 Nov '25
From: lizhi <lizhi206(a)huawei.com>
The hpre v2 interface needs to support the no-sva business model
within the new evolution framework. This ensures that users
switching to the v2 interface can utilize both the sva mode
and the no-sva mode.
Signed-off-by: lizhi <lizhi206(a)huawei.com>
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
drv/hisi_comp.c | 3 +-
drv/hisi_hpre.c | 650 ++++++++++++++++++++++++++++-----------
drv/hisi_qm_udrv.c | 15 +-
include/drv/wd_dh_drv.h | 3 +
include/drv/wd_ecc_drv.h | 3 +
include/drv/wd_rsa_drv.h | 3 +
include/wd_dh.h | 2 +
include/wd_ecc.h | 2 +
include/wd_rsa.h | 2 +
wd_dh.c | 22 +-
wd_ecc.c | 53 ++--
wd_rsa.c | 56 +++-
12 files changed, 580 insertions(+), 234 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 87d2103..8474e17 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -267,7 +267,8 @@ static __u32 copy_to_out(struct wd_comp_msg *msg, struct hisi_comp_buf *buf, __u
struct wd_comp_req *req = &msg->req;
struct wd_datalist *node = req->list_dst;
__u32 sgl_restlen, copy_len;
- __u32 len = 0, sgl_cplen = 0;
+ __u32 sgl_cplen = 0;
+ __u32 len = 0;
copy_len = total_len > req->dst_len ?
req->dst_len : total_len;
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 7ce842b..f3f2451 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -34,14 +34,17 @@
#define SM2_PONIT_SIZE 64
#define MAX_HASH_LENS BITS_TO_BYTES(521)
#define HW_PLAINTEXT_BYTES_MAX BITS_TO_BYTES(4096)
-#define HPRE_CTX_Q_NUM_DEF 1
+#define HPRE_CTX_Q_NUM_DEF 1
+#define MAP_PAIR_NUM_MAX 6
#define CRT_PARAMS_SZ(key_size) ((5 * (key_size)) >> 1)
#define CRT_GEN_PARAMS_SZ(key_size) ((7 * (key_size)) >> 1)
#define GEN_PARAMS_SZ(key_size) ((key_size) << 1)
#define CRT_PARAM_SZ(key_size) ((key_size) >> 1)
-#define WD_TRANS_FAIL 0
+#define GEN_PARAMS_SZ_UL(key_size) ((unsigned long)(key_size) << 1)
+#define DMA_ADDR(hi, lo) ((__u64)(((__u64)(hi) << 32) | (__u64)(lo)))
+#define WD_TRANS_FAIL 0
#define CURVE_PARAM_NUM 6
#define SECP256R1_KEY_SIZE 32
@@ -78,6 +81,21 @@ enum hpre_alg_name {
WD_ECC
};
+enum hpre_hw_msg_field {
+ HW_MSG_IN,
+ HW_MSG_OUT,
+ HW_MSG_KEY,
+};
+
+struct map_info_cache {
+ struct map_pair {
+ void *addr;
+ uintptr_t pa;
+ size_t size;
+ } pairs[MAP_PAIR_NUM_MAX];
+ size_t cnt;
+};
+
/* put vendor hardware message as a user interface is not suitable here */
struct hisi_hpre_sqe {
__u32 alg : 5;
@@ -113,12 +131,122 @@ struct hisi_hpre_sqe {
struct hisi_hpre_ctx {
struct wd_ctx_config_internal config;
+ struct wd_mm_ops *mm_ops;
+ handle_t rsv_mem_ctx;
};
struct hpre_ecc_ctx {
__u32 enable_hpcore;
};
+static void add_map_info(struct map_info_cache *cache, void *addr, uintptr_t dma, size_t size)
+{
+ /* The cnt is guaranteed not to exceed MAP_PAIR_NUM_MAX within hpre. */
+ cache->pairs[cache->cnt].addr = addr;
+ cache->pairs[cache->cnt].pa = dma;
+ cache->pairs[cache->cnt].size = size;
+ cache->cnt++;
+}
+
+static void unmap_addr_in_cache(struct wd_mm_ops *mm_ops, struct map_info_cache *cache)
+{
+ size_t i;
+
+ if (mm_ops->sva_mode)
+ return;
+
+ /* The cnt is guaranteed not to exceed MAP_PAIR_NUM_MAX within hpre. */
+ for (i = 0; i < cache->cnt; i++)
+ mm_ops->iova_unmap(mm_ops->usr, cache->pairs[i].addr,
+ (void *)cache->pairs[i].pa, cache->pairs[i].size);
+}
+
+static void unsetup_hw_msg_addr(struct wd_mm_ops *mm_ops, enum hpre_hw_msg_field t_type,
+ struct hisi_hpre_sqe *hw_msg, void *va, size_t data_sz)
+{
+ void *addr;
+
+ if (!mm_ops || mm_ops->sva_mode || !va || !data_sz)
+ return;
+
+ switch (t_type) {
+ case HW_MSG_KEY:
+ addr = VA_ADDR(hw_msg->hi_key, hw_msg->low_key);
+ break;
+ case HW_MSG_IN:
+ addr = VA_ADDR(hw_msg->hi_in, hw_msg->low_in);
+ break;
+ case HW_MSG_OUT:
+ addr = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
+ break;
+ default:
+ return;
+ }
+
+ if (!addr)
+ return;
+
+ mm_ops->iova_unmap(mm_ops->usr, va, (void *)addr, data_sz);
+}
+
+static uintptr_t select_addr_by_sva_mode(struct wd_mm_ops *mm_ops, void *data,
+ size_t data_sz, struct map_info_cache *cache)
+{
+ uintptr_t addr;
+
+ if (!mm_ops->sva_mode) {
+ addr = (uintptr_t)mm_ops->iova_map(mm_ops->usr, data, data_sz);
+ if (!addr) {
+ WD_ERR("Failed to get mappped DMA address for hardware.\n");
+ return 0;
+ }
+ add_map_info(cache, data, addr, data_sz);
+ } else {
+ addr = (uintptr_t)data;
+ }
+
+ return addr;
+}
+
+static void fill_hw_msg_addr(enum hpre_hw_msg_field t_type, struct hisi_hpre_sqe *hw_msg,
+ uintptr_t addr)
+{
+ switch (t_type) {
+ case HW_MSG_KEY:
+ hw_msg->low_key = LW_U32(addr);
+ hw_msg->hi_key = HI_U32(addr);
+ break;
+ case HW_MSG_IN:
+ hw_msg->low_in = LW_U32(addr);
+ hw_msg->hi_in = HI_U32(addr);
+ break;
+ case HW_MSG_OUT:
+ hw_msg->low_out = LW_U32(addr);
+ hw_msg->hi_out = HI_U32(addr);
+ break;
+ default:
+ return;
+ }
+}
+
+static int check_hpre_mem_params(struct wd_mm_ops *mm_ops, enum wd_mem_type mm_type)
+{
+ if (!mm_ops) {
+ WD_ERR("Memory operation functions are null.\n");
+ return -WD_EINVAL;
+ }
+
+ if (mm_type == UADK_MEM_AUTO && !mm_ops->sva_mode) {
+ WD_ERR("No-SVA in auto mode is not supported yet.\n");
+ return -WD_EINVAL;
+ } else if (mm_type > UADK_MEM_PROXY) {
+ WD_ERR("failed to check memory type.\n");
+ return -WD_EINVAL;
+ }
+
+ return WD_SUCCESS;
+}
+
static void dump_hpre_msg(void *msg, int alg)
{
struct wd_rsa_msg *rsa_msg;
@@ -269,7 +397,8 @@ static int fill_rsa_crt_prikey2(struct wd_rsa_prikey *prikey,
*data = wd_dq->data;
- return WD_SUCCESS;
+ return (int)(wd_dq->bsize + wd_qinv->bsize + wd_p->bsize +
+ wd_q->bsize + wd_dp->bsize);
}
static int fill_rsa_prikey1(struct wd_rsa_prikey *prikey, void **data)
@@ -292,7 +421,7 @@ static int fill_rsa_prikey1(struct wd_rsa_prikey *prikey, void **data)
*data = wd_d->data;
- return WD_SUCCESS;
+ return (int)(wd_n->bsize + wd_d->bsize);
}
static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data)
@@ -315,7 +444,7 @@ static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data)
*data = wd_e->data;
- return WD_SUCCESS;
+ return (int)(wd_n->bsize + wd_e->bsize);
}
static int fill_rsa_genkey_in(struct wd_rsa_kg_in *genkey)
@@ -378,22 +507,21 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg,
{
struct wd_rsa_req *req = &msg->req;
struct wd_rsa_kg_out *key = req->dst;
+ struct wd_rsa_msg *target_msg;
__u16 kbytes = msg->key_bytes;
struct wd_dtb qinv, dq, dp;
struct wd_dtb d, n;
- void *data;
int ret;
- if (hw_msg->alg == HPRE_ALG_KG_CRT || hw_msg->alg == HPRE_ALG_KG_STD) {
- /* async */
- if (qp_mode == CTX_MODE_ASYNC) {
- data = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- key = container_of(data, struct wd_rsa_kg_out, data);
- } else {
- key = req->dst;
- }
+ target_msg = (struct wd_rsa_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct rsa send msg from hardware!\n");
+ return -WD_ADDR_ERR;
}
+ if (hw_msg->alg == HPRE_ALG_KG_CRT || hw_msg->alg == HPRE_ALG_KG_STD)
+ key = target_msg->req.dst;
+
msg->result = WD_SUCCESS;
if (hw_msg->alg == HPRE_ALG_KG_CRT) {
req->dst_bytes = CRT_GEN_PARAMS_SZ(kbytes);
@@ -424,37 +552,38 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg,
return WD_SUCCESS;
}
-static int rsa_prepare_key(struct wd_rsa_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int rsa_prepare_key(struct wd_rsa_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
struct wd_rsa_req *req = &msg->req;
+ uintptr_t addr;
+ int ret, len;
void *data;
- int ret;
if (req->op_type == WD_RSA_SIGN) {
if (hw_msg->alg == HPRE_ALG_NC_CRT) {
- ret = fill_rsa_crt_prikey2((void *)msg->key, &data);
- if (ret)
- return ret;
+ len = fill_rsa_crt_prikey2((void *)msg->key, &data);
+ if (len <= 0)
+ return -WD_EINVAL;
} else {
- ret = fill_rsa_prikey1((void *)msg->key, &data);
- if (ret)
- return ret;
+ len = fill_rsa_prikey1((void *)msg->key, &data);
+ if (len <= 0)
+ return -WD_EINVAL;
hw_msg->alg = HPRE_ALG_NC_NCRT;
}
} else if (req->op_type == WD_RSA_VERIFY) {
- ret = fill_rsa_pubkey((void *)msg->key, &data);
- if (ret)
- return ret;
+ len = fill_rsa_pubkey((void *)msg->key, &data);
+ if (len <= 0)
+ return -WD_EINVAL;
hw_msg->alg = HPRE_ALG_NC_NCRT;
} else if (req->op_type == WD_RSA_GENKEY) {
ret = fill_rsa_genkey_in((void *)msg->key);
if (ret)
return ret;
- ret = wd_rsa_kg_in_data((void *)msg->key, (char **)&data);
- if (ret < 0) {
+ len = wd_rsa_kg_in_data((void *)msg->key, (char **)&data);
+ if (len < 0) {
WD_ERR("failed to get rsa gen key data!\n");
- return ret;
+ return -WD_EINVAL;
}
if (hw_msg->alg == HPRE_ALG_NC_CRT)
hw_msg->alg = HPRE_ALG_KG_CRT;
@@ -465,36 +594,53 @@ static int rsa_prepare_key(struct wd_rsa_msg *msg,
return -WD_EINVAL;
}
- hw_msg->low_key = LW_U32((uintptr_t)data);
- hw_msg->hi_key = HI_U32((uintptr_t)data);
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, len, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return WD_SUCCESS;
+ return ret;
}
-static int rsa_prepare_iot(struct wd_rsa_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int rsa_prepare_iot(struct wd_rsa_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
struct wd_rsa_req *req = &msg->req;
struct wd_rsa_kg_out *kout = req->dst;
int ret = WD_SUCCESS;
- void *out = NULL;
+ uintptr_t phy, out;
if (req->op_type != WD_RSA_GENKEY) {
- hw_msg->low_in = LW_U32((uintptr_t)req->src);
- hw_msg->hi_in = HI_U32((uintptr_t)req->src);
- out = req->dst;
+ phy = select_addr_by_sva_mode(msg->mm_ops, req->src, req->src_bytes, cache);
+ if (!phy)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_IN, hw_msg, phy);
+ phy = select_addr_by_sva_mode(msg->mm_ops, req->dst, req->dst_bytes, cache);
+ if (!phy)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_OUT, hw_msg, phy);
} else {
hw_msg->low_in = 0;
hw_msg->hi_in = 0;
ret = wd_rsa_kg_out_data(kout, (char **)&out);
if (ret < 0)
return ret;
- }
- hw_msg->low_out = LW_U32((uintptr_t)out);
- hw_msg->hi_out = HI_U32((uintptr_t)out);
+ if (!msg->mm_ops->sva_mode) {
+ phy = (uintptr_t)msg->mm_ops->iova_map(msg->mm_ops->usr, kout, ret);
+ if (!phy) {
+ WD_ERR("Failed to get DMA address for rsa output!\n");
+ return -WD_ENOMEM;
+ }
+ add_map_info(cache, kout, phy, ret);
+ out = phy + out - (uintptr_t)kout;
+ }
+
+ hw_msg->low_out = LW_U32(out);
+ hw_msg->hi_out = HI_U32(out);
+ }
- return ret;
+ return WD_SUCCESS;
}
static int hpre_init_qm_priv(struct wd_ctx_config_internal *config,
@@ -615,10 +761,17 @@ static int rsa_send(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_rsa_msg *msg = rsa_msg;
+ struct map_info_cache cache = {0};
struct hisi_hpre_sqe hw_msg;
__u16 send_cnt = 0;
int ret;
+ ret = check_hpre_mem_params(msg->mm_ops, msg->mm_type);
+ if (ret) {
+ WD_ERR("rsa memory parmas is err, and ret is %d!\n", ret);
+ return ret;
+ }
+
memset(&hw_msg, 0, sizeof(struct hisi_hpre_sqe));
if (msg->key_type == WD_RSA_PRIKEY1 ||
@@ -631,21 +784,30 @@ static int rsa_send(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
hw_msg.task_len1 = msg->key_bytes / BYTE_BITS - 0x1;
- ret = rsa_prepare_key(msg, &hw_msg);
- if (ret < 0)
- return ret;
+ ret = rsa_prepare_key(msg, &hw_msg, &cache);
+ if (ret)
+ goto rsa_fail;
/* prepare in/out put */
- ret = rsa_prepare_iot(msg, &hw_msg);
- if (ret < 0)
- return ret;
+ ret = rsa_prepare_iot(msg, &hw_msg, &cache);
+ if (ret)
+ goto rsa_fail;
hisi_set_msg_id(h_qp, &msg->tag);
hw_msg.done = 0x1;
hw_msg.etype = 0x0;
- hw_msg.low_tag = msg->tag;
+ hw_msg.low_tag = LW_U32((uintptr_t)msg);
+ hw_msg.hi_tag = HI_U32((uintptr_t)msg);
- return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ ret = hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ if (unlikely(ret))
+ goto rsa_fail;
+
+ return ret;
+
+rsa_fail:
+ unmap_addr_in_cache(msg->mm_ops, &cache);
+ return ret;
}
static void hpre_result_check(struct hisi_hpre_sqe *hw_msg,
@@ -671,32 +833,29 @@ static int rsa_recv(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
- struct hisi_hpre_sqe hw_msg = {0};
+ struct wd_rsa_msg *target_msg;
struct wd_rsa_msg *msg = rsa_msg;
- struct wd_rsa_msg *temp_msg;
+ struct hisi_hpre_sqe hw_msg = {0};
+ size_t ilen = 0, olen = 0;
__u16 recv_cnt = 0;
+ __u16 kbytes;
int ret;
ret = hisi_qm_recv(h_qp, &hw_msg, 1, &recv_cnt);
if (ret < 0)
return ret;
- ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ target_msg = (struct wd_rsa_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, target_msg->tag);
if (ret)
return ret;
- msg->tag = LW_U16(hw_msg.low_tag);
- if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
- temp_msg = wd_rsa_get_msg(qp->q_info.idx, msg->tag);
- if (!temp_msg) {
- WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
- qp->q_info.idx, msg->tag);
- return -WD_EINVAL;
- }
- } else {
- temp_msg = msg;
- }
-
+ msg->tag = target_msg->tag;
hpre_result_check(&hw_msg, &msg->result);
if (!msg->result) {
ret = rsa_out_transfer(msg, &hw_msg, qp->q_info.qp_mode);
@@ -707,15 +866,36 @@ static int rsa_recv(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
}
if (unlikely(msg->result != WD_SUCCESS))
- dump_hpre_msg(temp_msg, WD_RSA);
+ dump_hpre_msg(target_msg, WD_RSA);
+
+ if (!target_msg->mm_ops->sva_mode) {
+ kbytes = target_msg->key_bytes;
+ if (hw_msg.alg == HPRE_ALG_KG_CRT) {
+ olen = CRT_GEN_PARAMS_SZ(kbytes);
+ ilen = GEN_PARAMS_SZ_UL(kbytes);
+ } else if (hw_msg.alg == HPRE_ALG_KG_STD) {
+ olen = GEN_PARAMS_SZ_UL(kbytes);
+ ilen = GEN_PARAMS_SZ_UL(kbytes);
+ } else {
+ olen = kbytes;
+ ilen = kbytes;
+ }
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_IN, &hw_msg,
+ target_msg->req.src, ilen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_OUT, &hw_msg,
+ target_msg->req.dst, olen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_KEY, &hw_msg,
+ target_msg->key, target_msg->key_bytes);
+ }
return WD_SUCCESS;
}
-static int fill_dh_xp_params(struct wd_dh_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int fill_dh_xp_params(struct wd_dh_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
struct wd_dh_req *req = &msg->req;
+ uintptr_t addr;
void *x, *p;
int ret;
@@ -735,26 +915,30 @@ static int fill_dh_xp_params(struct wd_dh_msg *msg,
return ret;
}
- hw_msg->low_key = LW_U32((uintptr_t)x);
- hw_msg->hi_key = HI_U32((uintptr_t)x);
+ addr = select_addr_by_sva_mode(msg->mm_ops, x, GEN_PARAMS_SZ_UL(msg->key_bytes), cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return WD_SUCCESS;
+ return ret;
}
-static int dh_out_transfer(struct wd_dh_msg *msg,
- struct hisi_hpre_sqe *hw_msg, __u8 qp_mode)
+static int dh_out_transfer(struct wd_dh_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ __u8 qp_mode)
{
__u16 key_bytes = (hw_msg->task_len1 + 1) * BYTE_BITS;
struct wd_dh_req *req = &msg->req;
+ struct wd_dh_msg *target_msg;
void *out;
int ret;
- /* async */
- if (qp_mode == CTX_MODE_ASYNC)
- out = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- else
- out = req->pri;
+ target_msg = (struct wd_dh_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+ out = target_msg->req.pri;
ret = hpre_bin_to_crypto_bin((char *)out,
(const char *)out, key_bytes, "dh out");
if (!ret)
@@ -768,12 +952,20 @@ static int dh_out_transfer(struct wd_dh_msg *msg,
static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct map_info_cache cache = {0};
struct wd_dh_msg *msg = dh_msg;
struct wd_dh_req *req = &msg->req;
struct hisi_hpre_sqe hw_msg;
__u16 send_cnt = 0;
+ uintptr_t addr;
int ret;
+ ret = check_hpre_mem_params(msg->mm_ops, msg->mm_type);
+ if (ret) {
+ WD_ERR("dh memory parmas is err, and ret is %d!\n", ret);
+ return ret;
+ }
+
memset(&hw_msg, 0, sizeof(struct hisi_hpre_sqe));
if (msg->is_g2 && req->op_type != WD_DH_PHASE2)
@@ -791,32 +983,50 @@ static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
WD_ERR("failed to transfer dh g para format to hpre bin!\n");
return ret;
}
-
- hw_msg.low_in = LW_U32((uintptr_t)msg->g);
- hw_msg.hi_in = HI_U32((uintptr_t)msg->g);
+ addr = select_addr_by_sva_mode(msg->mm_ops, msg->g, msg->key_bytes, &cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_IN, &hw_msg, addr);
}
- ret = fill_dh_xp_params(msg, &hw_msg);
- if (ret)
- return ret;
+ ret = fill_dh_xp_params(msg, &hw_msg, &cache);
+ if (ret) {
+ WD_ERR("failed to fill dh x or p para!\n");
+ goto dh_fail;
+ }
hisi_set_msg_id(h_qp, &msg->tag);
- hw_msg.low_out = LW_U32((uintptr_t)req->pri);
- hw_msg.hi_out = HI_U32((uintptr_t)req->pri);
hw_msg.done = 0x1;
hw_msg.etype = 0x0;
- hw_msg.low_tag = msg->tag;
- return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ hw_msg.low_tag = LW_U32((uintptr_t)msg);
+ hw_msg.hi_tag = HI_U32((uintptr_t)msg);
+
+ addr = select_addr_by_sva_mode(msg->mm_ops, req->pri, req->pri_bytes, &cache);
+ if (!addr) {
+ ret = -WD_ENOMEM;
+ goto dh_fail;
+ }
+ fill_hw_msg_addr(HW_MSG_OUT, &hw_msg, addr);
+
+ ret = hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ if (unlikely(ret))
+ goto dh_fail;
+
+ return ret;
+
+dh_fail:
+ unmap_addr_in_cache(msg->mm_ops, &cache);
+ return ret;
}
static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
- struct wd_dh_msg *msg = dh_msg;
struct hisi_hpre_sqe hw_msg = {0};
- struct wd_dh_msg *temp_msg;
+ struct wd_dh_msg *msg = dh_msg;
+ struct wd_dh_msg *target_msg;
__u16 recv_cnt = 0;
int ret;
@@ -824,22 +1034,17 @@ static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
if (ret < 0)
return ret;
- ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ target_msg = (struct wd_dh_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, target_msg->tag);
if (ret)
return ret;
- msg->tag = LW_U16(hw_msg.low_tag);
- if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
- temp_msg = wd_dh_get_msg(qp->q_info.idx, msg->tag);
- if (!temp_msg) {
- WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
- qp->q_info.idx, msg->tag);
- return -WD_EINVAL;
- }
- } else {
- temp_msg = msg;
- }
-
+ msg->tag = target_msg->tag;
hpre_result_check(&hw_msg, &msg->result);
if (!msg->result) {
ret = dh_out_transfer(msg, &hw_msg, qp->q_info.qp_mode);
@@ -850,7 +1055,16 @@ static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
}
if (unlikely(msg->result != WD_SUCCESS))
- dump_hpre_msg(temp_msg, WD_DH);
+ dump_hpre_msg(target_msg, WD_DH);
+
+ if (!target_msg->mm_ops->sva_mode) {
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_OUT, &hw_msg,
+ target_msg->req.pri, target_msg->req.pri_bytes);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_KEY, &hw_msg,
+ target_msg->req.x_p, GEN_PARAMS_SZ_UL(target_msg->key_bytes));
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_IN, &hw_msg,
+ target_msg->g, target_msg->key_bytes);
+ }
return WD_SUCCESS;
}
@@ -1081,30 +1295,49 @@ static bool is_prikey_used(__u8 op_type)
op_type == HPRE_SM2_DEC;
}
-static int ecc_prepare_key(struct wd_ecc_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static __u32 ecc_get_prikey_size(struct wd_ecc_msg *msg)
+{
+ if (msg->req.op_type == WD_SM2_SIGN ||
+ msg->req.op_type == WD_ECDSA_SIGN ||
+ msg->req.op_type == WD_SM2_DECRYPT)
+ return ECC_PRIKEY_SZ(msg->key_bytes);
+ else if (msg->curve_id == WD_X25519 ||
+ msg->curve_id == WD_X448)
+ return X_DH_HW_KEY_SZ(msg->key_bytes);
+ else
+ return ECDH_HW_KEY_SZ(msg->key_bytes);
+}
+
+static int ecc_prepare_key(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
void *data = NULL;
+ uintptr_t addr;
+ size_t ksz;
int ret;
if (is_prikey_used(msg->req.op_type)) {
+ ksz = ecc_get_prikey_size(msg);
ret = ecc_prepare_prikey((void *)msg->key, &data, msg->curve_id);
if (ret)
return ret;
} else {
+ ksz = ECC_PUBKEY_SZ(msg->key_bytes);
ret = ecc_prepare_pubkey((void *)msg->key, &data);
if (ret)
return ret;
}
- hw_msg->low_key = LW_U32((uintptr_t)data);
- hw_msg->hi_key = HI_U32((uintptr_t)data);
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, ksz, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return WD_SUCCESS;
+ return ret;
}
-static void ecc_get_io_len(__u32 atype, __u32 hsz, size_t *ilen,
- size_t *olen)
+static void ecc_get_io_len(__u32 atype, __u32 hsz,
+ size_t *ilen, size_t *olen)
{
if (atype == HPRE_ALG_ECDH_MULTIPLY) {
*olen = ECDH_OUT_PARAMS_SZ(hsz);
@@ -1467,12 +1700,12 @@ static int ecc_prepare_out(struct wd_ecc_msg *msg, void **data)
}
/* prepare in/out hw message */
-static int ecc_prepare_iot(struct wd_ecc_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int ecc_prepare_iot(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
+ size_t i_sz, o_sz;
void *data = NULL;
- size_t i_sz = 0;
- size_t o_sz = 0;
+ uintptr_t addr;
__u16 kbytes;
int ret;
@@ -1483,8 +1716,11 @@ static int ecc_prepare_iot(struct wd_ecc_msg *msg,
WD_ERR("failed to prepare ecc in!\n");
return ret;
}
- hw_msg->low_in = LW_U32((uintptr_t)data);
- hw_msg->hi_in = HI_U32((uintptr_t)data);
+
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, i_sz, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_IN, hw_msg, addr);
ret = ecc_prepare_out(msg, &data);
if (ret) {
@@ -1496,8 +1732,10 @@ static int ecc_prepare_iot(struct wd_ecc_msg *msg,
if (!data)
return WD_SUCCESS;
- hw_msg->low_out = LW_U32((uintptr_t)data);
- hw_msg->hi_out = HI_U32((uintptr_t)data);
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, o_sz, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_OUT, hw_msg, addr);
return WD_SUCCESS;
}
@@ -1613,7 +1851,7 @@ static struct wd_ecc_out *create_ecdh_out(struct wd_ecc_msg *msg)
return NULL;
}
- out = malloc(len);
+ out = msg->mm_ops->alloc(msg->mm_ops->usr, len);
if (!out) {
WD_ERR("failed to alloc out memory, sz = %u!\n", len);
return NULL;
@@ -1677,7 +1915,7 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
prikey = (struct wd_ecc_prikey *)(ecc_key + 1);
ecc_key->prikey = prikey;
- prikey->data = malloc(ECC_PRIKEY_SZ(src->key_bytes));
+ prikey->data = src->mm_ops->alloc(src->mm_ops->usr, ECC_PRIKEY_SZ(src->key_bytes));
if (unlikely(!prikey->data)) {
WD_ERR("failed to alloc prikey data!\n");
goto fail_alloc_key_data;
@@ -1696,7 +1934,7 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
return dst;
fail_set_prikey:
- free(prikey->data);
+ src->mm_ops->free(src->mm_ops->usr, prikey->data);
fail_alloc_key_data:
free(ecc_key);
fail_alloc_key:
@@ -1709,9 +1947,9 @@ static void free_req(struct wd_ecc_msg *msg)
{
struct wd_ecc_key *key = (void *)msg->key;
- free(key->prikey->data);
+ msg->mm_ops->free(msg->mm_ops->usr, key->prikey->data);
free(key);
- free(msg->req.dst);
+ msg->mm_ops->free(msg->mm_ops->usr, msg->req.dst);
free(msg);
}
@@ -1732,7 +1970,8 @@ static int split_req(struct wd_ecc_msg *src, struct wd_ecc_msg **dst)
return WD_SUCCESS;
}
-static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
+static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
__u32 hw_sz = get_hw_keysz(msg->key_bytes);
__u8 op_type = msg->req.op_type;
@@ -1757,39 +1996,42 @@ static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
return ret;
/* prepare key */
- ret = ecc_prepare_key(msg, hw_msg);
+ ret = ecc_prepare_key(msg, hw_msg, cache);
if (ret)
return ret;
/* prepare in/out put */
- ret = ecc_prepare_iot(msg, hw_msg);
+ ret = ecc_prepare_iot(msg, hw_msg, cache);
if (ret)
return ret;
hw_msg->done = 0x1;
hw_msg->etype = 0x0;
- hw_msg->low_tag = msg->tag;
+
+ hw_msg->low_tag = LW_U32((uintptr_t)msg);
+ hw_msg->hi_tag = HI_U32((uintptr_t)msg);
hw_msg->task_len1 = hw_sz / BYTE_BITS - 0x1;
return ret;
}
-static int ecc_general_send(handle_t ctx, struct wd_ecc_msg *msg)
+static int ecc_general_send(handle_t ctx, struct wd_ecc_msg *msg,
+ struct map_info_cache *cache)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_hpre_sqe hw_msg;
__u16 send_cnt = 0;
int ret;
- ret = ecc_fill(msg, &hw_msg);
+ ret = ecc_fill(msg, &hw_msg, cache);
if (ret)
return ret;
return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
}
-
-static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
+static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg,
+ struct map_info_cache *cache)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_sm2_enc_in *ein = msg->req.src;
@@ -1801,7 +2043,7 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
if (ein->plaintext.dsize <= HW_PLAINTEXT_BYTES_MAX &&
hash->type == WD_HASH_SM3)
- return ecc_general_send(ctx, msg);
+ return ecc_general_send(ctx, msg, cache);
if (unlikely(!ein->k_set)) {
WD_ERR("invalid: k not set!\n");
@@ -1824,13 +2066,13 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
return ret;
}
- ret = ecc_fill(msg_dst[0], &hw_msg[0]);
+ ret = ecc_fill(msg_dst[0], &hw_msg[0], cache);
if (unlikely(ret)) {
WD_ERR("failed to fill 1th sqe, ret = %d!\n", ret);
goto fail_fill_sqe;
}
- ret = ecc_fill(msg_dst[1], &hw_msg[1]);
+ ret = ecc_fill(msg_dst[1], &hw_msg[1], cache);
if (unlikely(ret)) {
WD_ERR("failed to fill 2th sqe, ret = %d!\n", ret);
goto fail_fill_sqe;
@@ -1855,7 +2097,8 @@ fail_fill_sqe:
return ret;
}
-static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
+static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg,
+ struct map_info_cache *cache)
{
struct wd_sm2_dec_in *din = (void *)msg->req.src;
struct wd_hash_mt *hash = &msg->hash;
@@ -1865,7 +2108,7 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
/* c2 data lens <= 4096 bit */
if (din->c2.dsize <= BITS_TO_BYTES(4096) &&
hash->type == WD_HASH_SM3)
- return ecc_general_send(ctx, msg);
+ return ecc_general_send(ctx, msg, cache);
if (unlikely(!hash->cb || hash->type >= WD_HASH_MAX)) {
WD_ERR("invalid: input hash type %u is error!\n", hash->type);
@@ -1891,14 +2134,14 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
goto free_dst;
}
- ret = ecc_general_send(ctx, dst);
+ ret = ecc_general_send(ctx, dst, cache);
if (unlikely(ret))
goto free_req_dst;
return ret;
free_req_dst:
- free(dst->req.dst);
+ msg->mm_ops->free(msg->mm_ops->usr, dst->req.dst);
free_dst:
free(dst);
return ret;
@@ -1908,14 +2151,37 @@ static int ecc_send(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_ecc_msg *msg = ecc_msg;
+ struct map_info_cache cache = {0};
+ int ret;
+
+ ret = check_hpre_mem_params(msg->mm_ops, msg->mm_type);
+ if (ret) {
+ WD_ERR("ecc memory parmas is err, and ret is %d!\n", ret);
+ return ret;
+ }
hisi_set_msg_id(h_qp, &msg->tag);
- if (msg->req.op_type == WD_SM2_ENCRYPT)
- return sm2_enc_send(ctx, msg);
- else if (msg->req.op_type == WD_SM2_DECRYPT)
- return sm2_dec_send(ctx, msg);
+ if (msg->req.op_type == WD_SM2_ENCRYPT) {
+ ret = sm2_enc_send(ctx, msg, &cache);
+ if (ret)
+ goto ecc_fail;
+ return ret;
+ } else if (msg->req.op_type == WD_SM2_DECRYPT) {
+ ret = sm2_dec_send(ctx, msg, &cache);
+ if (ret)
+ goto ecc_fail;
+ return ret;
+ }
- return ecc_general_send(ctx, msg);
+ ret = ecc_general_send(ctx, msg, &cache);
+ if (ret)
+ goto ecc_fail;
+
+ return ret;
+
+ecc_fail:
+ unmap_addr_in_cache(msg->mm_ops, &cache);
+ return ret;
}
static int ecdh_out_transfer(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
@@ -2020,14 +2286,14 @@ static int sm2_enc_out_transfer(struct wd_ecc_msg *msg,
static int ecc_out_transfer(struct wd_ecc_msg *msg,
struct hisi_hpre_sqe *hw_msg, __u8 qp_mode)
{
+ struct wd_ecc_msg *target_msg;
int ret = -WD_EINVAL;
- void *va;
+
+ target_msg = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
/* async */
- if (qp_mode == CTX_MODE_ASYNC) {
- va = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- msg->req.dst = container_of(va, struct wd_ecc_out, data);
- }
+ if (qp_mode == CTX_MODE_ASYNC)
+ msg->req.dst = target_msg->req.dst;
if (hw_msg->alg == HPRE_ALG_SM2_SIGN ||
hw_msg->alg == HPRE_ALG_ECDSA_SIGN)
@@ -2319,19 +2585,16 @@ static int sm2_convert_dec_out(struct wd_ecc_msg *src,
static int ecc_sqe_parse(struct hisi_qp *qp, struct wd_ecc_msg *msg,
struct hisi_hpre_sqe *hw_msg)
{
- struct wd_ecc_msg *temp_msg;
+ struct wd_ecc_msg *target_msg;
+ size_t ilen = 0;
+ size_t olen = 0;
+ __u16 kbytes;
int ret;
- msg->tag = LW_U16(hw_msg->low_tag);
- if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
- temp_msg = wd_ecc_get_msg(qp->q_info.idx, msg->tag);
- if (!temp_msg) {
- WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
- qp->q_info.idx, msg->tag);
- return -WD_EINVAL;
- }
- } else {
- temp_msg = msg;
+ target_msg = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct ecc send msg from hardware!\n");
+ return -WD_ADDR_ERR;
}
hpre_result_check(hw_msg, &msg->result);
@@ -2347,10 +2610,20 @@ static int ecc_sqe_parse(struct hisi_qp *qp, struct wd_ecc_msg *msg,
goto dump_err_msg;
}
- return ret;
+ return WD_SUCCESS;
dump_err_msg:
- dump_hpre_msg(temp_msg, WD_ECC);
+ kbytes = target_msg->key_bytes;
+ if (!target_msg->mm_ops->sva_mode) {
+ ecc_get_io_len(hw_msg->alg, kbytes, &ilen, &olen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_OUT, hw_msg,
+ target_msg->req.dst, olen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_KEY, hw_msg,
+ target_msg->key, kbytes);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_IN, hw_msg,
+ target_msg->req.src, ilen);
+ }
+ dump_hpre_msg(target_msg, WD_ECC);
return ret;
}
@@ -2363,8 +2636,6 @@ static int parse_second_sqe(handle_t h_qp,
struct wd_ecc_msg *dst;
__u16 recv_cnt = 0;
int cnt = 0;
- void *data;
- __u32 hsz;
int ret;
while (1) {
@@ -2380,10 +2651,12 @@ static int parse_second_sqe(handle_t h_qp,
break;
}
- data = VA_ADDR(hw_msg.hi_out, hw_msg.low_out);
- hsz = (hw_msg.task_len1 + 1) * BYTE_BITS;
- dst = *(struct wd_ecc_msg **)((uintptr_t)data +
- hsz * ECDH_OUT_PARAM_NUM);
+ dst = (struct wd_ecc_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!dst) {
+ WD_ERR("failed to get correct sm2 enc second send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
ret = ecc_sqe_parse((struct hisi_qp *)h_qp, dst, &hw_msg);
msg->result = dst->result;
*second = dst;
@@ -2394,19 +2667,17 @@ static int parse_second_sqe(handle_t h_qp,
static int sm2_enc_parse(handle_t h_qp, struct wd_ecc_msg *msg,
struct hisi_hpre_sqe *hw_msg)
{
- __u16 tag = LW_U16(hw_msg->low_tag);
struct wd_ecc_msg *second = NULL;
struct wd_ecc_msg *first;
struct wd_ecc_msg src;
- void *data;
- __u32 hsz;
int ret;
- msg->tag = tag;
- data = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- hsz = (hw_msg->task_len1 + 1) * BYTE_BITS;
- first = *(struct wd_ecc_msg **)((uintptr_t)data +
- hsz * ECDH_OUT_PARAM_NUM);
+ first = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!first) {
+ WD_ERR("failed to get correct sm2 enc msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
memcpy(&src, first + 1, sizeof(src));
/* parse first sqe */
@@ -2440,17 +2711,15 @@ free_first:
static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
struct hisi_hpre_sqe *hw_msg)
{
- __u16 tag = LW_U16(hw_msg->low_tag);
struct wd_ecc_msg *dst;
struct wd_ecc_msg src;
- void *data;
- __u32 hsz;
int ret;
- data = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- hsz = (hw_msg->task_len1 + 1) * BYTE_BITS;
- dst = *(struct wd_ecc_msg **)((uintptr_t)data +
- hsz * ECDH_OUT_PARAM_NUM);
+ dst = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!dst) {
+ WD_ERR("failed to get correct sm2 dec msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
memcpy(&src, dst + 1, sizeof(src));
/* parse first sqe */
@@ -2460,7 +2729,6 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
goto fail;
}
msg->result = dst->result;
- msg->tag = tag;
ret = sm2_convert_dec_out(&src, dst);
if (unlikely(ret)) {
@@ -2469,7 +2737,7 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
}
fail:
- free(dst->req.dst);
+ dst->mm_ops->free(dst->mm_ops->usr, dst->req.dst);
free(dst);
return ret;
@@ -2479,6 +2747,7 @@ static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_ecc_msg *msg = ecc_msg;
+ struct wd_ecc_msg *target_msg;
struct hisi_hpre_sqe hw_msg;
__u16 recv_cnt = 0;
int ret;
@@ -2487,10 +2756,17 @@ static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
if (ret)
return ret;
- ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ target_msg = (struct wd_ecc_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, target_msg->tag);
if (ret)
return ret;
+ msg->tag = target_msg->tag;
if (hw_msg.alg == HPRE_ALG_ECDH_MULTIPLY &&
hw_msg.sm2_mlen == HPRE_SM2_ENC)
return sm2_enc_parse(h_qp, msg, &hw_msg);
@@ -2549,7 +2825,7 @@ static bool is_valid_hw_type(struct wd_alg_driver *drv)
hpre_ctx = (struct hisi_hpre_ctx *)drv->priv;
qp = (struct hisi_qp *)wd_ctx_get_priv(hpre_ctx->config.ctxs[0].ctx);
- if (qp->q_info.hw_type < HISI_QM_API_VER3_BASE)
+ if (!qp || qp->q_info.hw_type < HISI_QM_API_VER3_BASE)
return false;
return true;
}
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 9251b4c..216b80a 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -473,7 +473,7 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
{
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
struct hisi_qm_queue_info *q_info;
- __u16 free_num, send_num;
+ __u16 free_num;
__u16 tail;
if (unlikely(!qp || !req || !count))
@@ -488,11 +488,14 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
return -WD_EBUSY;
}
- send_num = expect > free_num ? free_num : expect;
+ if (expect > free_num) {
+ pthread_spin_unlock(&q_info->sd_lock);
+ return -WD_EBUSY;
+ }
tail = q_info->sq_tail_index;
- hisi_qm_fill_sqe(req, q_info, tail, send_num);
- tail = (tail + send_num) % q_info->sq_depth;
+ hisi_qm_fill_sqe(req, q_info, tail, expect);
+ tail = (tail + expect) % q_info->sq_depth;
/*
* Before sending doorbell, check the queue status,
@@ -510,9 +513,9 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
q_info->sq_tail_index = tail;
/* Make sure used_num is changed before the next thread gets free sqe. */
- __atomic_add_fetch(&q_info->used_num, send_num, __ATOMIC_RELAXED);
+ __atomic_add_fetch(&q_info->used_num, expect, __ATOMIC_RELAXED);
pthread_spin_unlock(&q_info->sd_lock);
- *count = send_num;
+ *count = expect;
return 0;
}
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index d205dc4..d2a6157 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -16,12 +16,15 @@ extern "C" {
/* DH message format */
struct wd_dh_msg {
struct wd_dh_req req;
+ struct wd_mm_ops *mm_ops;
+ enum wd_mem_type mm_type;
__u32 tag; /* User-defined request identifier */
void *g;
__u16 gbytes;
__u16 key_bytes; /* Input key bytes */
__u8 is_g2;
__u8 result; /* Data format, denoted by WD error code */
+ __u8 *rsv_out; /* reserved output data pointer */
};
struct wd_dh_msg *wd_dh_get_msg(__u32 idx, __u32 tag);
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 6193c8b..b123a9b 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -48,6 +48,8 @@ extern "C" {
/* ECC message format */
struct wd_ecc_msg {
struct wd_ecc_req req;
+ struct wd_mm_ops *mm_ops;
+ enum wd_mem_type mm_type;
struct wd_hash_mt hash;
__u32 tag; /* User-defined request identifier */
__u8 *key; /* Input key VA, should be DMA buffer */
@@ -55,6 +57,7 @@ struct wd_ecc_msg {
__u8 curve_id; /* Ec curve denoted by enum wd_ecc_curve_type */
__u8 result; /* alg op error code */
void *drv_cfg; /* internal driver configuration */
+ __u8 *rsv_out; /* reserved output data pointer */
};
struct wd_ecc_pubkey {
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index d231ecf..c12f3e0 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -42,11 +42,14 @@ struct wd_rsa_kg_out {
/* RSA message format */
struct wd_rsa_msg {
struct wd_rsa_req req;
+ struct wd_mm_ops *mm_ops;
+ enum wd_mem_type mm_type;
__u32 tag; /* User-defined request identifier */
__u16 key_bytes; /* Input key bytes */
__u8 key_type; /* Denoted by enum wd_rsa_key_type */
__u8 result; /* Data format, denoted by WD error code */
__u8 *key; /* Input key VA pointer, should be DMA buffer */
+ __u8 *rsv_out; /* reserved output data pointer */
};
struct wd_rsa_msg *wd_rsa_get_msg(__u32 idx, __u32 tag);
diff --git a/include/wd_dh.h b/include/wd_dh.h
index afc2f7c..235c602 100644
--- a/include/wd_dh.h
+++ b/include/wd_dh.h
@@ -27,6 +27,8 @@ struct wd_dh_sess_setup {
__u16 key_bits; /* DH key bites */
bool is_g2; /* is g2 mode or not */
void *sched_param;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
struct wd_dh_req {
diff --git a/include/wd_ecc.h b/include/wd_ecc.h
index 6f670e2..18c1c0d 100644
--- a/include/wd_ecc.h
+++ b/include/wd_ecc.h
@@ -116,6 +116,8 @@ struct wd_ecc_sess_setup {
struct wd_rand_mt rand; /* rand method from user */
struct wd_hash_mt hash; /* hash method from user */
void *sched_param;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
struct wd_ecc_req {
diff --git a/include/wd_rsa.h b/include/wd_rsa.h
index 2f4e589..9c91432 100644
--- a/include/wd_rsa.h
+++ b/include/wd_rsa.h
@@ -60,6 +60,8 @@ struct wd_rsa_sess_setup {
__u16 key_bits; /* RSA key bits */
bool is_crt; /* CRT mode or not */
void *sched_param;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
bool wd_rsa_is_crt(handle_t sess);
diff --git a/wd_dh.c b/wd_dh.c
index 221322f..0c1372c 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -26,6 +26,8 @@ struct wd_dh_sess {
struct wd_dtb g;
struct wd_dh_sess_setup setup;
void *sched_key;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
static struct wd_dh_setting {
@@ -326,6 +328,8 @@ static int fill_dh_msg(struct wd_dh_msg *msg, struct wd_dh_req *req,
memcpy(&msg->req, req, sizeof(*req));
msg->result = WD_EINVAL;
msg->key_bytes = sess->key_size;
+ msg->mm_ops = &sess->mm_ops;
+ msg->mm_type = sess->mm_type;
if (unlikely(req->pri_bytes < sess->key_size)) {
WD_ERR("invalid: req pri bytes %hu is error!\n", req->pri_bytes);
@@ -581,6 +585,7 @@ void wd_dh_get_g(handle_t sess, struct wd_dtb **g)
handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup)
{
struct wd_dh_sess *sess;
+ int ret;
if (!setup) {
WD_ERR("invalid: alloc dh sess setup NULL!\n");
@@ -606,10 +611,19 @@ handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup)
memcpy(&sess->setup, setup, sizeof(*setup));
sess->key_size = setup->key_bits >> BYTE_BITS_SHIFT;
- sess->g.data = malloc(sess->key_size);
- if (!sess->g.data)
+ ret = wd_mem_ops_init(wd_dh_setting.config.ctxs[0].ctx, &setup->mm_ops, setup->mm_type);
+ if (ret) {
+ WD_ERR("failed to init memory ops!\n");
goto sess_err;
+ }
+ memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops));
+ sess->mm_type = setup->mm_type;
+ sess->g.data = sess->mm_ops.alloc(sess->mm_ops.usr, sess->key_size);
+ if (!sess->g.data) {
+ WD_ERR("failed to malloc sess g param memory!\n");
+ goto sess_err;
+ }
sess->g.bsize = sess->key_size;
/* Some simple scheduler don't need scheduling parameters */
sess->sched_key = (void *)wd_dh_setting.sched.sched_init(
@@ -622,7 +636,7 @@ handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup)
return (handle_t)sess;
sched_err:
- free(sess->g.data);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->g.data);
sess_err:
free(sess);
return (handle_t)0;
@@ -638,7 +652,7 @@ void wd_dh_free_sess(handle_t sess)
}
if (sess_t->g.data)
- free(sess_t->g.data);
+ sess_t->mm_ops.free(sess_t->mm_ops.usr, sess_t->g.data);
if (sess_t->sched_key)
free(sess_t->sched_key);
diff --git a/wd_ecc.c b/wd_ecc.c
index b1971b9..2c88d0a 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -52,6 +52,8 @@ struct wd_ecc_sess {
struct wd_ecc_sess_setup setup;
struct wd_ecc_extend_ops eops;
void *sched_key;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
struct wd_ecc_curve_list {
@@ -494,7 +496,7 @@ static void release_ecc_prikey(struct wd_ecc_sess *sess)
struct wd_ecc_prikey *prikey = sess->key.prikey;
wd_memset_zero(prikey->data, prikey->size);
- free(prikey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, prikey->data);
free(prikey);
sess->key.prikey = NULL;
}
@@ -503,7 +505,7 @@ static void release_ecc_pubkey(struct wd_ecc_sess *sess)
{
struct wd_ecc_pubkey *pubkey = sess->key.pubkey;
- free(pubkey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, pubkey->data);
free(pubkey);
sess->key.pubkey = NULL;
}
@@ -522,7 +524,7 @@ static struct wd_ecc_prikey *create_ecc_prikey(struct wd_ecc_sess *sess)
}
dsz = ECC_PRIKEY_SZ(hsz);
- data = malloc(dsz);
+ data = sess->mm_ops.alloc(sess->mm_ops.usr, dsz);
if (!data) {
WD_ERR("failed to malloc prikey data, sz = %u!\n", dsz);
free(prikey);
@@ -551,7 +553,7 @@ static struct wd_ecc_pubkey *create_ecc_pubkey(struct wd_ecc_sess *sess)
}
dsz = ECC_PUBKEY_SZ(hsz);
- data = malloc(dsz);
+ data = sess->mm_ops.alloc(sess->mm_ops.usr, dsz);
if (!data) {
WD_ERR("failed to malloc pubkey data, sz = %u!\n", dsz);
free(pubkey);
@@ -570,7 +572,7 @@ static void release_ecc_in(struct wd_ecc_sess *sess,
struct wd_ecc_in *ecc_in)
{
wd_memset_zero(ecc_in->data, ecc_in->size);
- free(ecc_in);
+ sess->mm_ops.free(sess->mm_ops.usr, ecc_in);
}
static struct wd_ecc_in *create_ecc_in(struct wd_ecc_sess *sess, __u32 num)
@@ -585,7 +587,7 @@ static struct wd_ecc_in *create_ecc_in(struct wd_ecc_sess *sess, __u32 num)
hsz = get_key_bsz(sess->key_size);
len = sizeof(struct wd_ecc_in) + hsz * num;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc ecc in, sz = %u!\n", len);
return NULL;
@@ -613,7 +615,7 @@ static struct wd_ecc_in *create_sm2_sign_in(struct wd_ecc_sess *sess,
len = sizeof(struct wd_ecc_in)
+ ECC_SIGN_IN_PARAM_NUM * ksz + m_len;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc sm2 sign in, sz = %llu!\n", len);
return NULL;
@@ -653,7 +655,7 @@ static struct wd_ecc_in *create_sm2_enc_in(struct wd_ecc_sess *sess,
}
len = sizeof(struct wd_ecc_in) + ksz + m_len;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc sm2 enc in, sz = %llu!\n", len);
return NULL;
@@ -697,7 +699,7 @@ static void *create_sm2_ciphertext(struct wd_ecc_sess *sess, __u32 m_len,
*len = (__u64)st_sz + ECC_POINT_PARAM_NUM * (__u64)sess->key_size +
(__u64)m_len + (__u64)h_byts;
- start = malloc(*len);
+ start = sess->mm_ops.alloc(sess->mm_ops.usr, *len);
if (unlikely(!start)) {
WD_ERR("failed to alloc start, sz = %llu!\n", *len);
return NULL;
@@ -745,7 +747,7 @@ static struct wd_ecc_out *create_ecc_out(struct wd_ecc_sess *sess, __u32 num)
hsz = get_key_bsz(sess->key_size);
len = sizeof(struct wd_ecc_out) + hsz * num;
- out = malloc(len);
+ out = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!out) {
WD_ERR("failed to malloc out, sz = %u!\n", len);
return NULL;
@@ -1149,13 +1151,13 @@ static void del_sess_key(struct wd_ecc_sess *sess)
{
if (sess->key.prikey) {
wd_memset_zero(sess->key.prikey->data, sess->key.prikey->size);
- free(sess->key.prikey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->key.prikey->data);
free(sess->key.prikey);
sess->key.prikey = NULL;
}
if (sess->key.pubkey) {
- free(sess->key.pubkey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->key.pubkey->data);
free(sess->key.pubkey);
sess->key.pubkey = NULL;
}
@@ -1227,6 +1229,15 @@ handle_t wd_ecc_alloc_sess(struct wd_ecc_sess_setup *setup)
memcpy(&sess->setup, setup, sizeof(*setup));
sess->key_size = BITS_TO_BYTES(setup->key_bits);
+ /* Memory type set */
+ ret = wd_mem_ops_init(wd_ecc_setting.config.ctxs[0].ctx, &setup->mm_ops, setup->mm_type);
+ if (ret) {
+ WD_ERR("failed to init memory ops!\n");
+ goto sess_err;
+ }
+ memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops));
+ sess->mm_type = setup->mm_type;
+
if (wd_ecc_setting.driver->get_extend_ops) {
ret = wd_ecc_setting.driver->get_extend_ops(&sess->eops);
if (ret) {
@@ -1508,9 +1519,10 @@ void wd_ecxdh_get_out_params(struct wd_ecc_out *out, struct wd_ecc_point **pbk)
void wd_ecc_del_in(handle_t sess, struct wd_ecc_in *in)
{
+ struct wd_ecc_sess *sess_t = (struct wd_ecc_sess *)sess;
__u32 bsz;
- if (!in) {
+ if (!sess_t || !in) {
WD_ERR("invalid: del ecc in parameter error!\n");
return;
}
@@ -1522,14 +1534,15 @@ void wd_ecc_del_in(handle_t sess, struct wd_ecc_in *in)
}
wd_memset_zero(in->data, bsz);
- free(in);
+ sess_t->mm_ops.free(sess_t->mm_ops.usr, in);
}
-void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out)
+void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out)
{
+ struct wd_ecc_sess *sess_t = (struct wd_ecc_sess *)sess;
__u32 bsz;
- if (!out) {
+ if (!sess_t || !out) {
WD_ERR("invalid: del ecc out parameter error!\n");
return;
}
@@ -1541,7 +1554,7 @@ void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out)
}
wd_memset_zero(out->data, bsz);
- free(out);
+ sess_t->mm_ops.free(sess_t->mm_ops.usr, out);
}
static int fill_ecc_msg(struct wd_ecc_msg *msg, struct wd_ecc_req *req,
@@ -1551,6 +1564,8 @@ static int fill_ecc_msg(struct wd_ecc_msg *msg, struct wd_ecc_req *req,
memcpy(&msg->req, req, sizeof(msg->req));
memcpy(&msg->hash, &sess->setup.hash, sizeof(msg->hash));
+ msg->mm_ops = &sess->mm_ops;
+ msg->mm_type = sess->mm_type;
msg->key_bytes = sess->key_size;
msg->curve_id = sess->setup.cv.cfg.id;
msg->drv_cfg = sess->eops.params;
@@ -1922,7 +1937,7 @@ static struct wd_ecc_in *create_sm2_verf_in(struct wd_ecc_sess *sess,
hsz = get_key_bsz(sess->key_size);
len = sizeof(struct wd_ecc_in) + ECC_VERF_IN_PARAM_NUM * hsz +
m_len;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc sm2 verf in, sz = %llu!\n", len);
return NULL;
@@ -2211,7 +2226,7 @@ struct wd_ecc_out *wd_sm2_new_dec_out(handle_t sess, __u32 plaintext_len)
}
len = sizeof(*ecc_out) + plaintext_len;
- ecc_out = malloc(len);
+ ecc_out = sess_t->mm_ops.alloc(sess_t->mm_ops.usr, len);
if (!ecc_out) {
WD_ERR("failed to malloc ecc_out, sz = %llu!\n", len);
return NULL;
diff --git a/wd_rsa.c b/wd_rsa.c
index cf9239c..bc78c6a 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -67,6 +67,8 @@ struct wd_rsa_sess {
struct wd_rsa_prikey *prikey;
struct wd_rsa_sess_setup setup;
void *sched_key;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
static struct wd_rsa_setting {
@@ -373,6 +375,8 @@ static int fill_rsa_msg(struct wd_rsa_msg *msg, struct wd_rsa_req *req,
memcpy(&msg->req, req, sizeof(*req));
msg->key_bytes = sess->key_size;
msg->result = WD_EINVAL;
+ msg->mm_ops = &sess->mm_ops;
+ msg->mm_type = sess->mm_type;
switch (msg->req.op_type) {
case WD_RSA_SIGN:
@@ -641,7 +645,7 @@ struct wd_rsa_kg_in *wd_rsa_new_kg_in(handle_t sess, struct wd_dtb *e,
}
kg_in_size = (int)GEN_PARAMS_SZ(c->key_size);
- kg_in = malloc(kg_in_size + sizeof(*kg_in));
+ kg_in = c->mm_ops.alloc(c->mm_ops.usr, kg_in_size + sizeof(*kg_in));
if (!kg_in) {
WD_ERR("failed to malloc kg_in memory!\n");
return NULL;
@@ -681,19 +685,16 @@ void wd_rsa_get_kg_in_params(struct wd_rsa_kg_in *kin, struct wd_dtb *e,
p->data = (void *)kin->p;
}
-static void del_kg(void *k)
+void wd_rsa_del_kg_in(handle_t sess, struct wd_rsa_kg_in *ki)
{
- if (!k) {
+ struct wd_rsa_sess *c = (struct wd_rsa_sess *)sess;
+
+ if (!c || !ki) {
WD_ERR("invalid: del key generate params err!\n");
return;
}
- free(k);
-}
-
-void wd_rsa_del_kg_in(handle_t sess, struct wd_rsa_kg_in *ki)
-{
- del_kg(ki);
+ c->mm_ops.free(c->mm_ops.usr, ki);
}
struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
@@ -719,7 +720,7 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
else
kg_out_size = (int)GEN_PARAMS_SZ(c->key_size);
- kg_out = malloc(kg_out_size + sizeof(*kg_out));
+ kg_out = c->mm_ops.alloc(c->mm_ops.usr, kg_out_size + sizeof(*kg_out));
if (!kg_out) {
WD_ERR("failed to malloc kg_out memory!\n");
return NULL;
@@ -741,13 +742,15 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
void wd_rsa_del_kg_out(handle_t sess, struct wd_rsa_kg_out *kout)
{
- if (!kout) {
+ struct wd_rsa_sess *c = (struct wd_rsa_sess *)sess;
+
+ if (!c || !kout) {
WD_ERR("invalid: param null at del kg out!\n");
return;
}
wd_memset_zero(kout->data, kout->size);
- del_kg(kout);
+ c->mm_ops.free(c->mm_ops.usr, kout);
}
void wd_rsa_get_kg_out_params(struct wd_rsa_kg_out *kout, struct wd_dtb *d,
@@ -804,6 +807,11 @@ void wd_rsa_set_kg_out_crt_psz(struct wd_rsa_kg_out *kout,
size_t dq_sz,
size_t dp_sz)
{
+ if (!kout) {
+ WD_ERR("invalid: input null when set kg out crt psz!\n");
+ return;
+ }
+
kout->qinvbytes = qinv_sz;
kout->dqbytes = dq_sz;
kout->dpbytes = dp_sz;
@@ -813,6 +821,11 @@ void wd_rsa_set_kg_out_psz(struct wd_rsa_kg_out *kout,
size_t d_sz,
size_t n_sz)
{
+ if (!kout) {
+ WD_ERR("invalid: input null when set kg out psz!\n");
+ return;
+ }
+
kout->dbytes = d_sz;
kout->nbytes = n_sz;
}
@@ -862,7 +875,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
if (setup->is_crt) {
len = sizeof(struct wd_rsa_prikey) +
(int)CRT_PARAMS_SZ(sess->key_size);
- sess->prikey = malloc(len);
+ sess->prikey = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!sess->prikey) {
WD_ERR("failed to alloc sess prikey2!\n");
return -WD_ENOMEM;
@@ -873,7 +886,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
} else {
len = sizeof(struct wd_rsa_prikey) +
(int)GEN_PARAMS_SZ(sess->key_size);
- sess->prikey = malloc(len);
+ sess->prikey = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!sess->prikey) {
WD_ERR("failed to alloc sess prikey1!\n");
return -WD_ENOMEM;
@@ -885,7 +898,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
len = sizeof(struct wd_rsa_pubkey) +
(int)GEN_PARAMS_SZ(sess->key_size);
- sess->pubkey = malloc(len);
+ sess->pubkey = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!sess->pubkey) {
free(sess->prikey);
WD_ERR("failed to alloc sess pubkey!\n");
@@ -912,8 +925,8 @@ static void del_sess_key(struct wd_rsa_sess *sess)
wd_memset_zero(prk->pkey.pkey2.data, CRT_PARAMS_SZ(sess->key_size));
else
wd_memset_zero(prk->pkey.pkey1.data, GEN_PARAMS_SZ(sess->key_size));
- free(sess->prikey);
- free(sess->pubkey);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->prikey);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->pubkey);
}
static void del_sess(struct wd_rsa_sess *c)
@@ -948,6 +961,15 @@ handle_t wd_rsa_alloc_sess(struct wd_rsa_sess_setup *setup)
memcpy(&sess->setup, setup, sizeof(*setup));
sess->key_size = setup->key_bits >> BYTE_BITS_SHIFT;
+ /* Memory type set */
+ ret = wd_mem_ops_init(wd_rsa_setting.config.ctxs[0].ctx, &setup->mm_ops, setup->mm_type);
+ if (ret) {
+ WD_ERR("failed to init memory ops!\n");
+ goto sess_err;
+ }
+
+ memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops));
+ sess->mm_type = setup->mm_type;
ret = create_sess_key(setup, sess);
if (ret) {
WD_ERR("failed to create rsa sess keys!\n");
--
2.33.0
1
0
From: Wenkai Lin <linwenkai6(a)hisilicon.com>
Extract a common function fill_hashagg_data_info.
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
drv/hisi_dae.c | 56 +++++++++++++++++++-------------------------------
1 file changed, 21 insertions(+), 35 deletions(-)
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index 4f4d13c..49387aa 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -26,7 +26,7 @@
#define DAE_VCHAR_OFFSET_SIZE 2
#define DAE_COL_BIT_NUM 4
#define DAE_AGG_START_COL 16
-#define DAE_HASHAGG_MAX_ROW_NUN 50000
+#define DAE_HASHAGG_MAX_ROW_NUM 50000
/* align size */
#define DAE_CHAR_ALIGN_SIZE 4
@@ -294,23 +294,8 @@ static void fill_hashagg_merge_key_data(struct dae_sqe *sqe, struct dae_ext_sqe
}
}
-static void fill_hashagg_normal_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
- struct hashagg_col_data *cols_data, __u32 agg_cols_num)
-{
- struct hw_agg_data *agg_data = cols_data->input_data;
- __u32 i;
-
- for (i = 0; i < agg_cols_num; i++) {
- sqe->agg_data_type[i] = agg_data[i].hw_type;
- sqe->agg_data_type[i] |= agg_data[i].sum_outtype << DAE_COL_BIT_NUM;
- ext_sqe->agg_data_info[i] = agg_data[i].data_info;
- }
-
- sqe->agg_col_bitmap = GENMASK(agg_cols_num + DAE_AGG_START_COL - 1, DAE_AGG_START_COL);
-}
-
-static void fill_hashagg_rehash_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
- struct hw_agg_data *agg_data, __u32 agg_cols_num)
+static void fill_hashagg_data_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
+ struct hw_agg_data *agg_data, __u32 agg_cols_num)
{
__u32 i;
@@ -344,14 +329,14 @@ static void fill_hashagg_input_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext
hw_agg_addr = &addr_list->input_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.agg_cols;
agg_col_num = msg->agg_cols_num;
- fill_hashagg_normal_info(sqe, ext_sqe, cols_data, agg_col_num);
+ fill_hashagg_data_info(sqe, ext_sqe, agg_data, agg_col_num);
break;
case WD_AGG_REHASH_INPUT:
agg_data = cols_data->output_data;
hw_agg_addr = &addr_list->input_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.agg_cols;
agg_col_num = cols_data->output_num;
- fill_hashagg_rehash_info(sqe, ext_sqe, agg_data, agg_col_num);
+ fill_hashagg_data_info(sqe, ext_sqe, agg_data, agg_col_num);
break;
case WD_AGG_STREAM_OUTPUT:
case WD_AGG_REHASH_OUTPUT:
@@ -359,7 +344,7 @@ static void fill_hashagg_input_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext
hw_agg_addr = &addr_list->output_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.out_agg_cols;
agg_col_num = cols_data->output_num;
- fill_hashagg_normal_info(sqe, ext_sqe, cols_data, cols_data->input_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->input_data, cols_data->input_num);
break;
}
@@ -385,7 +370,7 @@ static void fill_hashagg_merge_input_data(struct dae_sqe *sqe, struct dae_ext_sq
struct hashagg_ctx *agg_ctx = msg->priv;
struct hashagg_col_data *cols_data = &agg_ctx->cols_data;
- fill_hashagg_rehash_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
}
static void fill_hashagg_ext_addr(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
@@ -422,26 +407,15 @@ static void fill_hashagg_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
static int check_hashagg_param(struct wd_agg_msg *msg)
{
- struct hashagg_col_data *cols_data;
- struct hashagg_ctx *agg_ctx;
-
if (!msg) {
WD_ERR("invalid: input hashagg msg is NULL!\n");
return -WD_EINVAL;
}
- agg_ctx = msg->priv;
- cols_data = &agg_ctx->cols_data;
- if (cols_data->output_num > DAE_MAX_OUTPUT_COLS) {
- WD_ERR("invalid: input hashagg output num %u is more than %d!\n",
- cols_data->output_num, DAE_MAX_OUTPUT_COLS);
- return -WD_EINVAL;
- }
-
if ((msg->pos == WD_AGG_STREAM_INPUT || msg->pos == WD_AGG_REHASH_INPUT) &&
- msg->row_count > DAE_HASHAGG_MAX_ROW_NUN) {
+ msg->row_count > DAE_HASHAGG_MAX_ROW_NUM) {
WD_ERR("invalid: input hashagg row count %u is more than %d!\n",
- msg->row_count, DAE_HASHAGG_MAX_ROW_NUN);
+ msg->row_count, DAE_HASHAGG_MAX_ROW_NUM);
return -WD_EINVAL;
}
@@ -1005,6 +979,7 @@ static int transfer_input_col_info(struct wd_agg_col_info *agg_cols,
struct hw_agg_data *user_output_data,
__u32 cols_num, __u32 *output_num)
{
+ __u32 tmp = *output_num;
__u32 i, j, k = 0;
int ret;
@@ -1013,7 +988,15 @@ static int transfer_input_col_info(struct wd_agg_col_info *agg_cols,
WD_ERR("invalid: col alg num(%u) more than 2!\n", agg_cols[i].col_alg_num);
return -WD_EINVAL;
}
+ tmp += agg_cols[i].col_alg_num;
+ }
+ if (tmp > DAE_MAX_OUTPUT_COLS) {
+ WD_ERR("invalid: output col num is more than %d!\n", DAE_MAX_OUTPUT_COLS);
+ return -WD_EINVAL;
+ }
+
+ for (i = 0; i < cols_num; i++) {
for (j = 0; j < agg_cols[i].col_alg_num; j++) {
ret = hashagg_check_input_data(&agg_cols[i], &user_input_data[i],
&user_output_data[k], j);
@@ -1137,6 +1120,9 @@ static int transfer_data_to_hw_type(struct hashagg_col_data *cols_data,
struct wd_agg_col_info *agg_cols = setup->agg_cols_info;
int ret;
+ if (setup->is_count_all)
+ cols_data->output_num++;
+
ret = transfer_input_col_info(agg_cols, user_input_data, user_output_data,
setup->agg_cols_num, &cols_data->output_num);
if (ret)
--
2.33.0
1
0
From: Wenkai Lin <linwenkai6(a)hisilicon.com>
Extract a common function fill_hashagg_data_info.
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
drv/hisi_dae.c | 56 +++++++++++++++++++-------------------------------
1 file changed, 21 insertions(+), 35 deletions(-)
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index 4f4d13c..49387aa 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -26,7 +26,7 @@
#define DAE_VCHAR_OFFSET_SIZE 2
#define DAE_COL_BIT_NUM 4
#define DAE_AGG_START_COL 16
-#define DAE_HASHAGG_MAX_ROW_NUN 50000
+#define DAE_HASHAGG_MAX_ROW_NUM 50000
/* align size */
#define DAE_CHAR_ALIGN_SIZE 4
@@ -294,23 +294,8 @@ static void fill_hashagg_merge_key_data(struct dae_sqe *sqe, struct dae_ext_sqe
}
}
-static void fill_hashagg_normal_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
- struct hashagg_col_data *cols_data, __u32 agg_cols_num)
-{
- struct hw_agg_data *agg_data = cols_data->input_data;
- __u32 i;
-
- for (i = 0; i < agg_cols_num; i++) {
- sqe->agg_data_type[i] = agg_data[i].hw_type;
- sqe->agg_data_type[i] |= agg_data[i].sum_outtype << DAE_COL_BIT_NUM;
- ext_sqe->agg_data_info[i] = agg_data[i].data_info;
- }
-
- sqe->agg_col_bitmap = GENMASK(agg_cols_num + DAE_AGG_START_COL - 1, DAE_AGG_START_COL);
-}
-
-static void fill_hashagg_rehash_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
- struct hw_agg_data *agg_data, __u32 agg_cols_num)
+static void fill_hashagg_data_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
+ struct hw_agg_data *agg_data, __u32 agg_cols_num)
{
__u32 i;
@@ -344,14 +329,14 @@ static void fill_hashagg_input_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext
hw_agg_addr = &addr_list->input_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.agg_cols;
agg_col_num = msg->agg_cols_num;
- fill_hashagg_normal_info(sqe, ext_sqe, cols_data, agg_col_num);
+ fill_hashagg_data_info(sqe, ext_sqe, agg_data, agg_col_num);
break;
case WD_AGG_REHASH_INPUT:
agg_data = cols_data->output_data;
hw_agg_addr = &addr_list->input_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.agg_cols;
agg_col_num = cols_data->output_num;
- fill_hashagg_rehash_info(sqe, ext_sqe, agg_data, agg_col_num);
+ fill_hashagg_data_info(sqe, ext_sqe, agg_data, agg_col_num);
break;
case WD_AGG_STREAM_OUTPUT:
case WD_AGG_REHASH_OUTPUT:
@@ -359,7 +344,7 @@ static void fill_hashagg_input_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext
hw_agg_addr = &addr_list->output_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.out_agg_cols;
agg_col_num = cols_data->output_num;
- fill_hashagg_normal_info(sqe, ext_sqe, cols_data, cols_data->input_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->input_data, cols_data->input_num);
break;
}
@@ -385,7 +370,7 @@ static void fill_hashagg_merge_input_data(struct dae_sqe *sqe, struct dae_ext_sq
struct hashagg_ctx *agg_ctx = msg->priv;
struct hashagg_col_data *cols_data = &agg_ctx->cols_data;
- fill_hashagg_rehash_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
}
static void fill_hashagg_ext_addr(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
@@ -422,26 +407,15 @@ static void fill_hashagg_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
static int check_hashagg_param(struct wd_agg_msg *msg)
{
- struct hashagg_col_data *cols_data;
- struct hashagg_ctx *agg_ctx;
-
if (!msg) {
WD_ERR("invalid: input hashagg msg is NULL!\n");
return -WD_EINVAL;
}
- agg_ctx = msg->priv;
- cols_data = &agg_ctx->cols_data;
- if (cols_data->output_num > DAE_MAX_OUTPUT_COLS) {
- WD_ERR("invalid: input hashagg output num %u is more than %d!\n",
- cols_data->output_num, DAE_MAX_OUTPUT_COLS);
- return -WD_EINVAL;
- }
-
if ((msg->pos == WD_AGG_STREAM_INPUT || msg->pos == WD_AGG_REHASH_INPUT) &&
- msg->row_count > DAE_HASHAGG_MAX_ROW_NUN) {
+ msg->row_count > DAE_HASHAGG_MAX_ROW_NUM) {
WD_ERR("invalid: input hashagg row count %u is more than %d!\n",
- msg->row_count, DAE_HASHAGG_MAX_ROW_NUN);
+ msg->row_count, DAE_HASHAGG_MAX_ROW_NUM);
return -WD_EINVAL;
}
@@ -1005,6 +979,7 @@ static int transfer_input_col_info(struct wd_agg_col_info *agg_cols,
struct hw_agg_data *user_output_data,
__u32 cols_num, __u32 *output_num)
{
+ __u32 tmp = *output_num;
__u32 i, j, k = 0;
int ret;
@@ -1013,7 +988,15 @@ static int transfer_input_col_info(struct wd_agg_col_info *agg_cols,
WD_ERR("invalid: col alg num(%u) more than 2!\n", agg_cols[i].col_alg_num);
return -WD_EINVAL;
}
+ tmp += agg_cols[i].col_alg_num;
+ }
+ if (tmp > DAE_MAX_OUTPUT_COLS) {
+ WD_ERR("invalid: output col num is more than %d!\n", DAE_MAX_OUTPUT_COLS);
+ return -WD_EINVAL;
+ }
+
+ for (i = 0; i < cols_num; i++) {
for (j = 0; j < agg_cols[i].col_alg_num; j++) {
ret = hashagg_check_input_data(&agg_cols[i], &user_input_data[i],
&user_output_data[k], j);
@@ -1137,6 +1120,9 @@ static int transfer_data_to_hw_type(struct hashagg_col_data *cols_data,
struct wd_agg_col_info *agg_cols = setup->agg_cols_info;
int ret;
+ if (setup->is_count_all)
+ cols_data->output_num++;
+
ret = transfer_input_col_info(agg_cols, user_input_data, user_output_data,
setup->agg_cols_num, &cols_data->output_num);
if (ret)
--
2.33.0
1
0
18 Nov '25
From: lizhi <lizhi206(a)huawei.com>
The hpre v2 interface needs to support the no-sva business model
within the new evolution framework. This ensures that users
switching to the v2 interface can utilize both the sva mode
and the no-sva mode.
Signed-off-by: lizhi <lizhi206(a)huawei.com>
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
drv/hisi_comp.c | 3 +-
drv/hisi_hpre.c | 650 ++++++++++++++++++++++++++++-----------
drv/hisi_qm_udrv.c | 15 +-
include/drv/wd_dh_drv.h | 3 +
include/drv/wd_ecc_drv.h | 3 +
include/drv/wd_rsa_drv.h | 3 +
include/wd_dh.h | 2 +
include/wd_ecc.h | 2 +
include/wd_rsa.h | 2 +
wd_dh.c | 22 +-
wd_ecc.c | 53 ++--
wd_rsa.c | 56 +++-
12 files changed, 580 insertions(+), 234 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 87d2103..8474e17 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -267,7 +267,8 @@ static __u32 copy_to_out(struct wd_comp_msg *msg, struct hisi_comp_buf *buf, __u
struct wd_comp_req *req = &msg->req;
struct wd_datalist *node = req->list_dst;
__u32 sgl_restlen, copy_len;
- __u32 len = 0, sgl_cplen = 0;
+ __u32 sgl_cplen = 0;
+ __u32 len = 0;
copy_len = total_len > req->dst_len ?
req->dst_len : total_len;
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index 7ce842b..f3f2451 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -34,14 +34,17 @@
#define SM2_PONIT_SIZE 64
#define MAX_HASH_LENS BITS_TO_BYTES(521)
#define HW_PLAINTEXT_BYTES_MAX BITS_TO_BYTES(4096)
-#define HPRE_CTX_Q_NUM_DEF 1
+#define HPRE_CTX_Q_NUM_DEF 1
+#define MAP_PAIR_NUM_MAX 6
#define CRT_PARAMS_SZ(key_size) ((5 * (key_size)) >> 1)
#define CRT_GEN_PARAMS_SZ(key_size) ((7 * (key_size)) >> 1)
#define GEN_PARAMS_SZ(key_size) ((key_size) << 1)
#define CRT_PARAM_SZ(key_size) ((key_size) >> 1)
-#define WD_TRANS_FAIL 0
+#define GEN_PARAMS_SZ_UL(key_size) ((unsigned long)(key_size) << 1)
+#define DMA_ADDR(hi, lo) ((__u64)(((__u64)(hi) << 32) | (__u64)(lo)))
+#define WD_TRANS_FAIL 0
#define CURVE_PARAM_NUM 6
#define SECP256R1_KEY_SIZE 32
@@ -78,6 +81,21 @@ enum hpre_alg_name {
WD_ECC
};
+enum hpre_hw_msg_field {
+ HW_MSG_IN,
+ HW_MSG_OUT,
+ HW_MSG_KEY,
+};
+
+struct map_info_cache {
+ struct map_pair {
+ void *addr;
+ uintptr_t pa;
+ size_t size;
+ } pairs[MAP_PAIR_NUM_MAX];
+ size_t cnt;
+};
+
/* put vendor hardware message as a user interface is not suitable here */
struct hisi_hpre_sqe {
__u32 alg : 5;
@@ -113,12 +131,122 @@ struct hisi_hpre_sqe {
struct hisi_hpre_ctx {
struct wd_ctx_config_internal config;
+ struct wd_mm_ops *mm_ops;
+ handle_t rsv_mem_ctx;
};
struct hpre_ecc_ctx {
__u32 enable_hpcore;
};
+static void add_map_info(struct map_info_cache *cache, void *addr, uintptr_t dma, size_t size)
+{
+ /* The cnt is guaranteed not to exceed MAP_PAIR_NUM_MAX within hpre. */
+ cache->pairs[cache->cnt].addr = addr;
+ cache->pairs[cache->cnt].pa = dma;
+ cache->pairs[cache->cnt].size = size;
+ cache->cnt++;
+}
+
+static void unmap_addr_in_cache(struct wd_mm_ops *mm_ops, struct map_info_cache *cache)
+{
+ size_t i;
+
+ if (mm_ops->sva_mode)
+ return;
+
+ /* The cnt is guaranteed not to exceed MAP_PAIR_NUM_MAX within hpre. */
+ for (i = 0; i < cache->cnt; i++)
+ mm_ops->iova_unmap(mm_ops->usr, cache->pairs[i].addr,
+ (void *)cache->pairs[i].pa, cache->pairs[i].size);
+}
+
+static void unsetup_hw_msg_addr(struct wd_mm_ops *mm_ops, enum hpre_hw_msg_field t_type,
+ struct hisi_hpre_sqe *hw_msg, void *va, size_t data_sz)
+{
+ void *addr;
+
+ if (!mm_ops || mm_ops->sva_mode || !va || !data_sz)
+ return;
+
+ switch (t_type) {
+ case HW_MSG_KEY:
+ addr = VA_ADDR(hw_msg->hi_key, hw_msg->low_key);
+ break;
+ case HW_MSG_IN:
+ addr = VA_ADDR(hw_msg->hi_in, hw_msg->low_in);
+ break;
+ case HW_MSG_OUT:
+ addr = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
+ break;
+ default:
+ return;
+ }
+
+ if (!addr)
+ return;
+
+ mm_ops->iova_unmap(mm_ops->usr, va, (void *)addr, data_sz);
+}
+
+static uintptr_t select_addr_by_sva_mode(struct wd_mm_ops *mm_ops, void *data,
+ size_t data_sz, struct map_info_cache *cache)
+{
+ uintptr_t addr;
+
+ if (!mm_ops->sva_mode) {
+ addr = (uintptr_t)mm_ops->iova_map(mm_ops->usr, data, data_sz);
+ if (!addr) {
+ WD_ERR("Failed to get mappped DMA address for hardware.\n");
+ return 0;
+ }
+ add_map_info(cache, data, addr, data_sz);
+ } else {
+ addr = (uintptr_t)data;
+ }
+
+ return addr;
+}
+
+static void fill_hw_msg_addr(enum hpre_hw_msg_field t_type, struct hisi_hpre_sqe *hw_msg,
+ uintptr_t addr)
+{
+ switch (t_type) {
+ case HW_MSG_KEY:
+ hw_msg->low_key = LW_U32(addr);
+ hw_msg->hi_key = HI_U32(addr);
+ break;
+ case HW_MSG_IN:
+ hw_msg->low_in = LW_U32(addr);
+ hw_msg->hi_in = HI_U32(addr);
+ break;
+ case HW_MSG_OUT:
+ hw_msg->low_out = LW_U32(addr);
+ hw_msg->hi_out = HI_U32(addr);
+ break;
+ default:
+ return;
+ }
+}
+
+static int check_hpre_mem_params(struct wd_mm_ops *mm_ops, enum wd_mem_type mm_type)
+{
+ if (!mm_ops) {
+ WD_ERR("Memory operation functions are null.\n");
+ return -WD_EINVAL;
+ }
+
+ if (mm_type == UADK_MEM_AUTO && !mm_ops->sva_mode) {
+ WD_ERR("No-SVA in auto mode is not supported yet.\n");
+ return -WD_EINVAL;
+ } else if (mm_type > UADK_MEM_PROXY) {
+ WD_ERR("failed to check memory type.\n");
+ return -WD_EINVAL;
+ }
+
+ return WD_SUCCESS;
+}
+
static void dump_hpre_msg(void *msg, int alg)
{
struct wd_rsa_msg *rsa_msg;
@@ -269,7 +397,8 @@ static int fill_rsa_crt_prikey2(struct wd_rsa_prikey *prikey,
*data = wd_dq->data;
- return WD_SUCCESS;
+ return (int)(wd_dq->bsize + wd_qinv->bsize + wd_p->bsize +
+ wd_q->bsize + wd_dp->bsize);
}
static int fill_rsa_prikey1(struct wd_rsa_prikey *prikey, void **data)
@@ -292,7 +421,7 @@ static int fill_rsa_prikey1(struct wd_rsa_prikey *prikey, void **data)
*data = wd_d->data;
- return WD_SUCCESS;
+ return (int)(wd_n->bsize + wd_d->bsize);
}
static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data)
@@ -315,7 +444,7 @@ static int fill_rsa_pubkey(struct wd_rsa_pubkey *pubkey, void **data)
*data = wd_e->data;
- return WD_SUCCESS;
+ return (int)(wd_n->bsize + wd_e->bsize);
}
static int fill_rsa_genkey_in(struct wd_rsa_kg_in *genkey)
@@ -378,22 +507,21 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg,
{
struct wd_rsa_req *req = &msg->req;
struct wd_rsa_kg_out *key = req->dst;
+ struct wd_rsa_msg *target_msg;
__u16 kbytes = msg->key_bytes;
struct wd_dtb qinv, dq, dp;
struct wd_dtb d, n;
- void *data;
int ret;
- if (hw_msg->alg == HPRE_ALG_KG_CRT || hw_msg->alg == HPRE_ALG_KG_STD) {
- /* async */
- if (qp_mode == CTX_MODE_ASYNC) {
- data = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- key = container_of(data, struct wd_rsa_kg_out, data);
- } else {
- key = req->dst;
- }
+ target_msg = (struct wd_rsa_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct rsa send msg from hardware!\n");
+ return -WD_ADDR_ERR;
}
+ if (hw_msg->alg == HPRE_ALG_KG_CRT || hw_msg->alg == HPRE_ALG_KG_STD)
+ key = target_msg->req.dst;
+
msg->result = WD_SUCCESS;
if (hw_msg->alg == HPRE_ALG_KG_CRT) {
req->dst_bytes = CRT_GEN_PARAMS_SZ(kbytes);
@@ -424,37 +552,38 @@ static int rsa_out_transfer(struct wd_rsa_msg *msg,
return WD_SUCCESS;
}
-static int rsa_prepare_key(struct wd_rsa_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int rsa_prepare_key(struct wd_rsa_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
struct wd_rsa_req *req = &msg->req;
+ uintptr_t addr;
+ int ret, len;
void *data;
- int ret;
if (req->op_type == WD_RSA_SIGN) {
if (hw_msg->alg == HPRE_ALG_NC_CRT) {
- ret = fill_rsa_crt_prikey2((void *)msg->key, &data);
- if (ret)
- return ret;
+ len = fill_rsa_crt_prikey2((void *)msg->key, &data);
+ if (len <= 0)
+ return -WD_EINVAL;
} else {
- ret = fill_rsa_prikey1((void *)msg->key, &data);
- if (ret)
- return ret;
+ len = fill_rsa_prikey1((void *)msg->key, &data);
+ if (len <= 0)
+ return -WD_EINVAL;
hw_msg->alg = HPRE_ALG_NC_NCRT;
}
} else if (req->op_type == WD_RSA_VERIFY) {
- ret = fill_rsa_pubkey((void *)msg->key, &data);
- if (ret)
- return ret;
+ len = fill_rsa_pubkey((void *)msg->key, &data);
+ if (len <= 0)
+ return -WD_EINVAL;
hw_msg->alg = HPRE_ALG_NC_NCRT;
} else if (req->op_type == WD_RSA_GENKEY) {
ret = fill_rsa_genkey_in((void *)msg->key);
if (ret)
return ret;
- ret = wd_rsa_kg_in_data((void *)msg->key, (char **)&data);
- if (ret < 0) {
+ len = wd_rsa_kg_in_data((void *)msg->key, (char **)&data);
+ if (len < 0) {
WD_ERR("failed to get rsa gen key data!\n");
- return ret;
+ return -WD_EINVAL;
}
if (hw_msg->alg == HPRE_ALG_NC_CRT)
hw_msg->alg = HPRE_ALG_KG_CRT;
@@ -465,36 +594,53 @@ static int rsa_prepare_key(struct wd_rsa_msg *msg,
return -WD_EINVAL;
}
- hw_msg->low_key = LW_U32((uintptr_t)data);
- hw_msg->hi_key = HI_U32((uintptr_t)data);
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, len, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return WD_SUCCESS;
+ return ret;
}
-static int rsa_prepare_iot(struct wd_rsa_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int rsa_prepare_iot(struct wd_rsa_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
struct wd_rsa_req *req = &msg->req;
struct wd_rsa_kg_out *kout = req->dst;
int ret = WD_SUCCESS;
- void *out = NULL;
+ uintptr_t phy, out;
if (req->op_type != WD_RSA_GENKEY) {
- hw_msg->low_in = LW_U32((uintptr_t)req->src);
- hw_msg->hi_in = HI_U32((uintptr_t)req->src);
- out = req->dst;
+ phy = select_addr_by_sva_mode(msg->mm_ops, req->src, req->src_bytes, cache);
+ if (!phy)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_IN, hw_msg, phy);
+ phy = select_addr_by_sva_mode(msg->mm_ops, req->dst, req->dst_bytes, cache);
+ if (!phy)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_OUT, hw_msg, phy);
} else {
hw_msg->low_in = 0;
hw_msg->hi_in = 0;
ret = wd_rsa_kg_out_data(kout, (char **)&out);
if (ret < 0)
return ret;
- }
- hw_msg->low_out = LW_U32((uintptr_t)out);
- hw_msg->hi_out = HI_U32((uintptr_t)out);
+ if (!msg->mm_ops->sva_mode) {
+ phy = (uintptr_t)msg->mm_ops->iova_map(msg->mm_ops->usr, kout, ret);
+ if (!phy) {
+ WD_ERR("Failed to get DMA address for rsa output!\n");
+ return -WD_ENOMEM;
+ }
+ add_map_info(cache, kout, phy, ret);
+ out = phy + out - (uintptr_t)kout;
+ }
+
+ hw_msg->low_out = LW_U32(out);
+ hw_msg->hi_out = HI_U32(out);
+ }
- return ret;
+ return WD_SUCCESS;
}
static int hpre_init_qm_priv(struct wd_ctx_config_internal *config,
@@ -615,10 +761,17 @@ static int rsa_send(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_rsa_msg *msg = rsa_msg;
+ struct map_info_cache cache = {0};
struct hisi_hpre_sqe hw_msg;
__u16 send_cnt = 0;
int ret;
+ ret = check_hpre_mem_params(msg->mm_ops, msg->mm_type);
+ if (ret) {
+ WD_ERR("rsa memory parmas is err, and ret is %d!\n", ret);
+ return ret;
+ }
+
memset(&hw_msg, 0, sizeof(struct hisi_hpre_sqe));
if (msg->key_type == WD_RSA_PRIKEY1 ||
@@ -631,21 +784,30 @@ static int rsa_send(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
hw_msg.task_len1 = msg->key_bytes / BYTE_BITS - 0x1;
- ret = rsa_prepare_key(msg, &hw_msg);
- if (ret < 0)
- return ret;
+ ret = rsa_prepare_key(msg, &hw_msg, &cache);
+ if (ret)
+ goto rsa_fail;
/* prepare in/out put */
- ret = rsa_prepare_iot(msg, &hw_msg);
- if (ret < 0)
- return ret;
+ ret = rsa_prepare_iot(msg, &hw_msg, &cache);
+ if (ret)
+ goto rsa_fail;
hisi_set_msg_id(h_qp, &msg->tag);
hw_msg.done = 0x1;
hw_msg.etype = 0x0;
- hw_msg.low_tag = msg->tag;
+ hw_msg.low_tag = LW_U32((uintptr_t)msg);
+ hw_msg.hi_tag = HI_U32((uintptr_t)msg);
- return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ ret = hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ if (unlikely(ret))
+ goto rsa_fail;
+
+ return ret;
+
+rsa_fail:
+ unmap_addr_in_cache(msg->mm_ops, &cache);
+ return ret;
}
static void hpre_result_check(struct hisi_hpre_sqe *hw_msg,
@@ -671,32 +833,29 @@ static int rsa_recv(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
- struct hisi_hpre_sqe hw_msg = {0};
+ struct wd_rsa_msg *target_msg;
struct wd_rsa_msg *msg = rsa_msg;
- struct wd_rsa_msg *temp_msg;
+ struct hisi_hpre_sqe hw_msg = {0};
+ size_t ilen = 0, olen = 0;
__u16 recv_cnt = 0;
+ __u16 kbytes;
int ret;
ret = hisi_qm_recv(h_qp, &hw_msg, 1, &recv_cnt);
if (ret < 0)
return ret;
- ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ target_msg = (struct wd_rsa_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, target_msg->tag);
if (ret)
return ret;
- msg->tag = LW_U16(hw_msg.low_tag);
- if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
- temp_msg = wd_rsa_get_msg(qp->q_info.idx, msg->tag);
- if (!temp_msg) {
- WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
- qp->q_info.idx, msg->tag);
- return -WD_EINVAL;
- }
- } else {
- temp_msg = msg;
- }
-
+ msg->tag = target_msg->tag;
hpre_result_check(&hw_msg, &msg->result);
if (!msg->result) {
ret = rsa_out_transfer(msg, &hw_msg, qp->q_info.qp_mode);
@@ -707,15 +866,36 @@ static int rsa_recv(struct wd_alg_driver *drv, handle_t ctx, void *rsa_msg)
}
if (unlikely(msg->result != WD_SUCCESS))
- dump_hpre_msg(temp_msg, WD_RSA);
+ dump_hpre_msg(target_msg, WD_RSA);
+
+ if (!target_msg->mm_ops->sva_mode) {
+ kbytes = target_msg->key_bytes;
+ if (hw_msg.alg == HPRE_ALG_KG_CRT) {
+ olen = CRT_GEN_PARAMS_SZ(kbytes);
+ ilen = GEN_PARAMS_SZ_UL(kbytes);
+ } else if (hw_msg.alg == HPRE_ALG_KG_STD) {
+ olen = GEN_PARAMS_SZ_UL(kbytes);
+ ilen = GEN_PARAMS_SZ_UL(kbytes);
+ } else {
+ olen = kbytes;
+ ilen = kbytes;
+ }
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_IN, &hw_msg,
+ target_msg->req.src, ilen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_OUT, &hw_msg,
+ target_msg->req.dst, olen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_KEY, &hw_msg,
+ target_msg->key, target_msg->key_bytes);
+ }
return WD_SUCCESS;
}
-static int fill_dh_xp_params(struct wd_dh_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int fill_dh_xp_params(struct wd_dh_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
struct wd_dh_req *req = &msg->req;
+ uintptr_t addr;
void *x, *p;
int ret;
@@ -735,26 +915,30 @@ static int fill_dh_xp_params(struct wd_dh_msg *msg,
return ret;
}
- hw_msg->low_key = LW_U32((uintptr_t)x);
- hw_msg->hi_key = HI_U32((uintptr_t)x);
+ addr = select_addr_by_sva_mode(msg->mm_ops, x, GEN_PARAMS_SZ_UL(msg->key_bytes), cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return WD_SUCCESS;
+ return ret;
}
-static int dh_out_transfer(struct wd_dh_msg *msg,
- struct hisi_hpre_sqe *hw_msg, __u8 qp_mode)
+static int dh_out_transfer(struct wd_dh_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ __u8 qp_mode)
{
__u16 key_bytes = (hw_msg->task_len1 + 1) * BYTE_BITS;
struct wd_dh_req *req = &msg->req;
+ struct wd_dh_msg *target_msg;
void *out;
int ret;
- /* async */
- if (qp_mode == CTX_MODE_ASYNC)
- out = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- else
- out = req->pri;
+ target_msg = (struct wd_dh_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+ out = target_msg->req.pri;
ret = hpre_bin_to_crypto_bin((char *)out,
(const char *)out, key_bytes, "dh out");
if (!ret)
@@ -768,12 +952,20 @@ static int dh_out_transfer(struct wd_dh_msg *msg,
static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct map_info_cache cache = {0};
struct wd_dh_msg *msg = dh_msg;
struct wd_dh_req *req = &msg->req;
struct hisi_hpre_sqe hw_msg;
__u16 send_cnt = 0;
+ uintptr_t addr;
int ret;
+ ret = check_hpre_mem_params(msg->mm_ops, msg->mm_type);
+ if (ret) {
+ WD_ERR("dh memory parmas is err, and ret is %d!\n", ret);
+ return ret;
+ }
+
memset(&hw_msg, 0, sizeof(struct hisi_hpre_sqe));
if (msg->is_g2 && req->op_type != WD_DH_PHASE2)
@@ -791,32 +983,50 @@ static int dh_send(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
WD_ERR("failed to transfer dh g para format to hpre bin!\n");
return ret;
}
-
- hw_msg.low_in = LW_U32((uintptr_t)msg->g);
- hw_msg.hi_in = HI_U32((uintptr_t)msg->g);
+ addr = select_addr_by_sva_mode(msg->mm_ops, msg->g, msg->key_bytes, &cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_IN, &hw_msg, addr);
}
- ret = fill_dh_xp_params(msg, &hw_msg);
- if (ret)
- return ret;
+ ret = fill_dh_xp_params(msg, &hw_msg, &cache);
+ if (ret) {
+ WD_ERR("failed to fill dh x or p para!\n");
+ goto dh_fail;
+ }
hisi_set_msg_id(h_qp, &msg->tag);
- hw_msg.low_out = LW_U32((uintptr_t)req->pri);
- hw_msg.hi_out = HI_U32((uintptr_t)req->pri);
hw_msg.done = 0x1;
hw_msg.etype = 0x0;
- hw_msg.low_tag = msg->tag;
- return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ hw_msg.low_tag = LW_U32((uintptr_t)msg);
+ hw_msg.hi_tag = HI_U32((uintptr_t)msg);
+
+ addr = select_addr_by_sva_mode(msg->mm_ops, req->pri, req->pri_bytes, &cache);
+ if (!addr) {
+ ret = -WD_ENOMEM;
+ goto dh_fail;
+ }
+ fill_hw_msg_addr(HW_MSG_OUT, &hw_msg, addr);
+
+ ret = hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
+ if (unlikely(ret))
+ goto dh_fail;
+
+ return ret;
+
+dh_fail:
+ unmap_addr_in_cache(msg->mm_ops, &cache);
+ return ret;
}
static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
- struct wd_dh_msg *msg = dh_msg;
struct hisi_hpre_sqe hw_msg = {0};
- struct wd_dh_msg *temp_msg;
+ struct wd_dh_msg *msg = dh_msg;
+ struct wd_dh_msg *target_msg;
__u16 recv_cnt = 0;
int ret;
@@ -824,22 +1034,17 @@ static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
if (ret < 0)
return ret;
- ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ target_msg = (struct wd_dh_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, target_msg->tag);
if (ret)
return ret;
- msg->tag = LW_U16(hw_msg.low_tag);
- if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
- temp_msg = wd_dh_get_msg(qp->q_info.idx, msg->tag);
- if (!temp_msg) {
- WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
- qp->q_info.idx, msg->tag);
- return -WD_EINVAL;
- }
- } else {
- temp_msg = msg;
- }
-
+ msg->tag = target_msg->tag;
hpre_result_check(&hw_msg, &msg->result);
if (!msg->result) {
ret = dh_out_transfer(msg, &hw_msg, qp->q_info.qp_mode);
@@ -850,7 +1055,16 @@ static int dh_recv(struct wd_alg_driver *drv, handle_t ctx, void *dh_msg)
}
if (unlikely(msg->result != WD_SUCCESS))
- dump_hpre_msg(temp_msg, WD_DH);
+ dump_hpre_msg(target_msg, WD_DH);
+
+ if (!target_msg->mm_ops->sva_mode) {
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_OUT, &hw_msg,
+ target_msg->req.pri, target_msg->req.pri_bytes);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_KEY, &hw_msg,
+ target_msg->req.x_p, GEN_PARAMS_SZ_UL(target_msg->key_bytes));
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_IN, &hw_msg,
+ target_msg->g, target_msg->key_bytes);
+ }
return WD_SUCCESS;
}
@@ -1081,30 +1295,49 @@ static bool is_prikey_used(__u8 op_type)
op_type == HPRE_SM2_DEC;
}
-static int ecc_prepare_key(struct wd_ecc_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static __u32 ecc_get_prikey_size(struct wd_ecc_msg *msg)
+{
+ if (msg->req.op_type == WD_SM2_SIGN ||
+ msg->req.op_type == WD_ECDSA_SIGN ||
+ msg->req.op_type == WD_SM2_DECRYPT)
+ return ECC_PRIKEY_SZ(msg->key_bytes);
+ else if (msg->curve_id == WD_X25519 ||
+ msg->curve_id == WD_X448)
+ return X_DH_HW_KEY_SZ(msg->key_bytes);
+ else
+ return ECDH_HW_KEY_SZ(msg->key_bytes);
+}
+
+static int ecc_prepare_key(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
void *data = NULL;
+ uintptr_t addr;
+ size_t ksz;
int ret;
if (is_prikey_used(msg->req.op_type)) {
+ ksz = ecc_get_prikey_size(msg);
ret = ecc_prepare_prikey((void *)msg->key, &data, msg->curve_id);
if (ret)
return ret;
} else {
+ ksz = ECC_PUBKEY_SZ(msg->key_bytes);
ret = ecc_prepare_pubkey((void *)msg->key, &data);
if (ret)
return ret;
}
- hw_msg->low_key = LW_U32((uintptr_t)data);
- hw_msg->hi_key = HI_U32((uintptr_t)data);
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, ksz, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_KEY, hw_msg, addr);
- return WD_SUCCESS;
+ return ret;
}
-static void ecc_get_io_len(__u32 atype, __u32 hsz, size_t *ilen,
- size_t *olen)
+static void ecc_get_io_len(__u32 atype, __u32 hsz,
+ size_t *ilen, size_t *olen)
{
if (atype == HPRE_ALG_ECDH_MULTIPLY) {
*olen = ECDH_OUT_PARAMS_SZ(hsz);
@@ -1467,12 +1700,12 @@ static int ecc_prepare_out(struct wd_ecc_msg *msg, void **data)
}
/* prepare in/out hw message */
-static int ecc_prepare_iot(struct wd_ecc_msg *msg,
- struct hisi_hpre_sqe *hw_msg)
+static int ecc_prepare_iot(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
+ size_t i_sz, o_sz;
void *data = NULL;
- size_t i_sz = 0;
- size_t o_sz = 0;
+ uintptr_t addr;
__u16 kbytes;
int ret;
@@ -1483,8 +1716,11 @@ static int ecc_prepare_iot(struct wd_ecc_msg *msg,
WD_ERR("failed to prepare ecc in!\n");
return ret;
}
- hw_msg->low_in = LW_U32((uintptr_t)data);
- hw_msg->hi_in = HI_U32((uintptr_t)data);
+
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, i_sz, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_IN, hw_msg, addr);
ret = ecc_prepare_out(msg, &data);
if (ret) {
@@ -1496,8 +1732,10 @@ static int ecc_prepare_iot(struct wd_ecc_msg *msg,
if (!data)
return WD_SUCCESS;
- hw_msg->low_out = LW_U32((uintptr_t)data);
- hw_msg->hi_out = HI_U32((uintptr_t)data);
+ addr = select_addr_by_sva_mode(msg->mm_ops, data, o_sz, cache);
+ if (!addr)
+ return -WD_ENOMEM;
+ fill_hw_msg_addr(HW_MSG_OUT, hw_msg, addr);
return WD_SUCCESS;
}
@@ -1613,7 +1851,7 @@ static struct wd_ecc_out *create_ecdh_out(struct wd_ecc_msg *msg)
return NULL;
}
- out = malloc(len);
+ out = msg->mm_ops->alloc(msg->mm_ops->usr, len);
if (!out) {
WD_ERR("failed to alloc out memory, sz = %u!\n", len);
return NULL;
@@ -1677,7 +1915,7 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
prikey = (struct wd_ecc_prikey *)(ecc_key + 1);
ecc_key->prikey = prikey;
- prikey->data = malloc(ECC_PRIKEY_SZ(src->key_bytes));
+ prikey->data = src->mm_ops->alloc(src->mm_ops->usr, ECC_PRIKEY_SZ(src->key_bytes));
if (unlikely(!prikey->data)) {
WD_ERR("failed to alloc prikey data!\n");
goto fail_alloc_key_data;
@@ -1696,7 +1934,7 @@ static struct wd_ecc_msg *create_req(struct wd_ecc_msg *src, __u8 req_idx)
return dst;
fail_set_prikey:
- free(prikey->data);
+ src->mm_ops->free(src->mm_ops->usr, prikey->data);
fail_alloc_key_data:
free(ecc_key);
fail_alloc_key:
@@ -1709,9 +1947,9 @@ static void free_req(struct wd_ecc_msg *msg)
{
struct wd_ecc_key *key = (void *)msg->key;
- free(key->prikey->data);
+ msg->mm_ops->free(msg->mm_ops->usr, key->prikey->data);
free(key);
- free(msg->req.dst);
+ msg->mm_ops->free(msg->mm_ops->usr, msg->req.dst);
free(msg);
}
@@ -1732,7 +1970,8 @@ static int split_req(struct wd_ecc_msg *src, struct wd_ecc_msg **dst)
return WD_SUCCESS;
}
-static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
+static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg,
+ struct map_info_cache *cache)
{
__u32 hw_sz = get_hw_keysz(msg->key_bytes);
__u8 op_type = msg->req.op_type;
@@ -1757,39 +1996,42 @@ static int ecc_fill(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
return ret;
/* prepare key */
- ret = ecc_prepare_key(msg, hw_msg);
+ ret = ecc_prepare_key(msg, hw_msg, cache);
if (ret)
return ret;
/* prepare in/out put */
- ret = ecc_prepare_iot(msg, hw_msg);
+ ret = ecc_prepare_iot(msg, hw_msg, cache);
if (ret)
return ret;
hw_msg->done = 0x1;
hw_msg->etype = 0x0;
- hw_msg->low_tag = msg->tag;
+
+ hw_msg->low_tag = LW_U32((uintptr_t)msg);
+ hw_msg->hi_tag = HI_U32((uintptr_t)msg);
hw_msg->task_len1 = hw_sz / BYTE_BITS - 0x1;
return ret;
}
-static int ecc_general_send(handle_t ctx, struct wd_ecc_msg *msg)
+static int ecc_general_send(handle_t ctx, struct wd_ecc_msg *msg,
+ struct map_info_cache *cache)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct hisi_hpre_sqe hw_msg;
__u16 send_cnt = 0;
int ret;
- ret = ecc_fill(msg, &hw_msg);
+ ret = ecc_fill(msg, &hw_msg, cache);
if (ret)
return ret;
return hisi_qm_send(h_qp, &hw_msg, 1, &send_cnt);
}
-
-static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
+static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg,
+ struct map_info_cache *cache)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_sm2_enc_in *ein = msg->req.src;
@@ -1801,7 +2043,7 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
if (ein->plaintext.dsize <= HW_PLAINTEXT_BYTES_MAX &&
hash->type == WD_HASH_SM3)
- return ecc_general_send(ctx, msg);
+ return ecc_general_send(ctx, msg, cache);
if (unlikely(!ein->k_set)) {
WD_ERR("invalid: k not set!\n");
@@ -1824,13 +2066,13 @@ static int sm2_enc_send(handle_t ctx, struct wd_ecc_msg *msg)
return ret;
}
- ret = ecc_fill(msg_dst[0], &hw_msg[0]);
+ ret = ecc_fill(msg_dst[0], &hw_msg[0], cache);
if (unlikely(ret)) {
WD_ERR("failed to fill 1th sqe, ret = %d!\n", ret);
goto fail_fill_sqe;
}
- ret = ecc_fill(msg_dst[1], &hw_msg[1]);
+ ret = ecc_fill(msg_dst[1], &hw_msg[1], cache);
if (unlikely(ret)) {
WD_ERR("failed to fill 2th sqe, ret = %d!\n", ret);
goto fail_fill_sqe;
@@ -1855,7 +2097,8 @@ fail_fill_sqe:
return ret;
}
-static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
+static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg,
+ struct map_info_cache *cache)
{
struct wd_sm2_dec_in *din = (void *)msg->req.src;
struct wd_hash_mt *hash = &msg->hash;
@@ -1865,7 +2108,7 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
/* c2 data lens <= 4096 bit */
if (din->c2.dsize <= BITS_TO_BYTES(4096) &&
hash->type == WD_HASH_SM3)
- return ecc_general_send(ctx, msg);
+ return ecc_general_send(ctx, msg, cache);
if (unlikely(!hash->cb || hash->type >= WD_HASH_MAX)) {
WD_ERR("invalid: input hash type %u is error!\n", hash->type);
@@ -1891,14 +2134,14 @@ static int sm2_dec_send(handle_t ctx, struct wd_ecc_msg *msg)
goto free_dst;
}
- ret = ecc_general_send(ctx, dst);
+ ret = ecc_general_send(ctx, dst, cache);
if (unlikely(ret))
goto free_req_dst;
return ret;
free_req_dst:
- free(dst->req.dst);
+ msg->mm_ops->free(msg->mm_ops->usr, dst->req.dst);
free_dst:
free(dst);
return ret;
@@ -1908,14 +2151,37 @@ static int ecc_send(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_ecc_msg *msg = ecc_msg;
+ struct map_info_cache cache = {0};
+ int ret;
+
+ ret = check_hpre_mem_params(msg->mm_ops, msg->mm_type);
+ if (ret) {
+ WD_ERR("ecc memory parmas is err, and ret is %d!\n", ret);
+ return ret;
+ }
hisi_set_msg_id(h_qp, &msg->tag);
- if (msg->req.op_type == WD_SM2_ENCRYPT)
- return sm2_enc_send(ctx, msg);
- else if (msg->req.op_type == WD_SM2_DECRYPT)
- return sm2_dec_send(ctx, msg);
+ if (msg->req.op_type == WD_SM2_ENCRYPT) {
+ ret = sm2_enc_send(ctx, msg, &cache);
+ if (ret)
+ goto ecc_fail;
+ return ret;
+ } else if (msg->req.op_type == WD_SM2_DECRYPT) {
+ ret = sm2_dec_send(ctx, msg, &cache);
+ if (ret)
+ goto ecc_fail;
+ return ret;
+ }
- return ecc_general_send(ctx, msg);
+ ret = ecc_general_send(ctx, msg, &cache);
+ if (ret)
+ goto ecc_fail;
+
+ return ret;
+
+ecc_fail:
+ unmap_addr_in_cache(msg->mm_ops, &cache);
+ return ret;
}
static int ecdh_out_transfer(struct wd_ecc_msg *msg, struct hisi_hpre_sqe *hw_msg)
@@ -2020,14 +2286,14 @@ static int sm2_enc_out_transfer(struct wd_ecc_msg *msg,
static int ecc_out_transfer(struct wd_ecc_msg *msg,
struct hisi_hpre_sqe *hw_msg, __u8 qp_mode)
{
+ struct wd_ecc_msg *target_msg;
int ret = -WD_EINVAL;
- void *va;
+
+ target_msg = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
/* async */
- if (qp_mode == CTX_MODE_ASYNC) {
- va = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- msg->req.dst = container_of(va, struct wd_ecc_out, data);
- }
+ if (qp_mode == CTX_MODE_ASYNC)
+ msg->req.dst = target_msg->req.dst;
if (hw_msg->alg == HPRE_ALG_SM2_SIGN ||
hw_msg->alg == HPRE_ALG_ECDSA_SIGN)
@@ -2319,19 +2585,16 @@ static int sm2_convert_dec_out(struct wd_ecc_msg *src,
static int ecc_sqe_parse(struct hisi_qp *qp, struct wd_ecc_msg *msg,
struct hisi_hpre_sqe *hw_msg)
{
- struct wd_ecc_msg *temp_msg;
+ struct wd_ecc_msg *target_msg;
+ size_t ilen = 0;
+ size_t olen = 0;
+ __u16 kbytes;
int ret;
- msg->tag = LW_U16(hw_msg->low_tag);
- if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
- temp_msg = wd_ecc_get_msg(qp->q_info.idx, msg->tag);
- if (!temp_msg) {
- WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
- qp->q_info.idx, msg->tag);
- return -WD_EINVAL;
- }
- } else {
- temp_msg = msg;
+ target_msg = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct ecc send msg from hardware!\n");
+ return -WD_ADDR_ERR;
}
hpre_result_check(hw_msg, &msg->result);
@@ -2347,10 +2610,20 @@ static int ecc_sqe_parse(struct hisi_qp *qp, struct wd_ecc_msg *msg,
goto dump_err_msg;
}
- return ret;
+ return WD_SUCCESS;
dump_err_msg:
- dump_hpre_msg(temp_msg, WD_ECC);
+ kbytes = target_msg->key_bytes;
+ if (!target_msg->mm_ops->sva_mode) {
+ ecc_get_io_len(hw_msg->alg, kbytes, &ilen, &olen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_OUT, hw_msg,
+ target_msg->req.dst, olen);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_KEY, hw_msg,
+ target_msg->key, kbytes);
+ unsetup_hw_msg_addr(target_msg->mm_ops, HW_MSG_IN, hw_msg,
+ target_msg->req.src, ilen);
+ }
+ dump_hpre_msg(target_msg, WD_ECC);
return ret;
}
@@ -2363,8 +2636,6 @@ static int parse_second_sqe(handle_t h_qp,
struct wd_ecc_msg *dst;
__u16 recv_cnt = 0;
int cnt = 0;
- void *data;
- __u32 hsz;
int ret;
while (1) {
@@ -2380,10 +2651,12 @@ static int parse_second_sqe(handle_t h_qp,
break;
}
- data = VA_ADDR(hw_msg.hi_out, hw_msg.low_out);
- hsz = (hw_msg.task_len1 + 1) * BYTE_BITS;
- dst = *(struct wd_ecc_msg **)((uintptr_t)data +
- hsz * ECDH_OUT_PARAM_NUM);
+ dst = (struct wd_ecc_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!dst) {
+ WD_ERR("failed to get correct sm2 enc second send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
ret = ecc_sqe_parse((struct hisi_qp *)h_qp, dst, &hw_msg);
msg->result = dst->result;
*second = dst;
@@ -2394,19 +2667,17 @@ static int parse_second_sqe(handle_t h_qp,
static int sm2_enc_parse(handle_t h_qp, struct wd_ecc_msg *msg,
struct hisi_hpre_sqe *hw_msg)
{
- __u16 tag = LW_U16(hw_msg->low_tag);
struct wd_ecc_msg *second = NULL;
struct wd_ecc_msg *first;
struct wd_ecc_msg src;
- void *data;
- __u32 hsz;
int ret;
- msg->tag = tag;
- data = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- hsz = (hw_msg->task_len1 + 1) * BYTE_BITS;
- first = *(struct wd_ecc_msg **)((uintptr_t)data +
- hsz * ECDH_OUT_PARAM_NUM);
+ first = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!first) {
+ WD_ERR("failed to get correct sm2 enc msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
memcpy(&src, first + 1, sizeof(src));
/* parse first sqe */
@@ -2440,17 +2711,15 @@ free_first:
static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
struct hisi_hpre_sqe *hw_msg)
{
- __u16 tag = LW_U16(hw_msg->low_tag);
struct wd_ecc_msg *dst;
struct wd_ecc_msg src;
- void *data;
- __u32 hsz;
int ret;
- data = VA_ADDR(hw_msg->hi_out, hw_msg->low_out);
- hsz = (hw_msg->task_len1 + 1) * BYTE_BITS;
- dst = *(struct wd_ecc_msg **)((uintptr_t)data +
- hsz * ECDH_OUT_PARAM_NUM);
+ dst = (struct wd_ecc_msg *)VA_ADDR(hw_msg->hi_tag, hw_msg->low_tag);
+ if (!dst) {
+ WD_ERR("failed to get correct sm2 dec msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
memcpy(&src, dst + 1, sizeof(src));
/* parse first sqe */
@@ -2460,7 +2729,6 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
goto fail;
}
msg->result = dst->result;
- msg->tag = tag;
ret = sm2_convert_dec_out(&src, dst);
if (unlikely(ret)) {
@@ -2469,7 +2737,7 @@ static int sm2_dec_parse(handle_t ctx, struct wd_ecc_msg *msg,
}
fail:
- free(dst->req.dst);
+ dst->mm_ops->free(dst->mm_ops->usr, dst->req.dst);
free(dst);
return ret;
@@ -2479,6 +2747,7 @@ static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
struct wd_ecc_msg *msg = ecc_msg;
+ struct wd_ecc_msg *target_msg;
struct hisi_hpre_sqe hw_msg;
__u16 recv_cnt = 0;
int ret;
@@ -2487,10 +2756,17 @@ static int ecc_recv(struct wd_alg_driver *drv, handle_t ctx, void *ecc_msg)
if (ret)
return ret;
- ret = hisi_check_bd_id(h_qp, msg->tag, hw_msg.low_tag);
+ target_msg = (struct wd_ecc_msg *)VA_ADDR(hw_msg.hi_tag, hw_msg.low_tag);
+ if (!target_msg) {
+ WD_ERR("failed to get correct send msg from hardware!\n");
+ return -WD_ADDR_ERR;
+ }
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, target_msg->tag);
if (ret)
return ret;
+ msg->tag = target_msg->tag;
if (hw_msg.alg == HPRE_ALG_ECDH_MULTIPLY &&
hw_msg.sm2_mlen == HPRE_SM2_ENC)
return sm2_enc_parse(h_qp, msg, &hw_msg);
@@ -2549,7 +2825,7 @@ static bool is_valid_hw_type(struct wd_alg_driver *drv)
hpre_ctx = (struct hisi_hpre_ctx *)drv->priv;
qp = (struct hisi_qp *)wd_ctx_get_priv(hpre_ctx->config.ctxs[0].ctx);
- if (qp->q_info.hw_type < HISI_QM_API_VER3_BASE)
+ if (!qp || qp->q_info.hw_type < HISI_QM_API_VER3_BASE)
return false;
return true;
}
diff --git a/drv/hisi_qm_udrv.c b/drv/hisi_qm_udrv.c
index 9251b4c..216b80a 100644
--- a/drv/hisi_qm_udrv.c
+++ b/drv/hisi_qm_udrv.c
@@ -473,7 +473,7 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
{
struct hisi_qp *qp = (struct hisi_qp *)h_qp;
struct hisi_qm_queue_info *q_info;
- __u16 free_num, send_num;
+ __u16 free_num;
__u16 tail;
if (unlikely(!qp || !req || !count))
@@ -488,11 +488,14 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
return -WD_EBUSY;
}
- send_num = expect > free_num ? free_num : expect;
+ if (expect > free_num) {
+ pthread_spin_unlock(&q_info->sd_lock);
+ return -WD_EBUSY;
+ }
tail = q_info->sq_tail_index;
- hisi_qm_fill_sqe(req, q_info, tail, send_num);
- tail = (tail + send_num) % q_info->sq_depth;
+ hisi_qm_fill_sqe(req, q_info, tail, expect);
+ tail = (tail + expect) % q_info->sq_depth;
/*
* Before sending doorbell, check the queue status,
@@ -510,9 +513,9 @@ int hisi_qm_send(handle_t h_qp, const void *req, __u16 expect, __u16 *count)
q_info->sq_tail_index = tail;
/* Make sure used_num is changed before the next thread gets free sqe. */
- __atomic_add_fetch(&q_info->used_num, send_num, __ATOMIC_RELAXED);
+ __atomic_add_fetch(&q_info->used_num, expect, __ATOMIC_RELAXED);
pthread_spin_unlock(&q_info->sd_lock);
- *count = send_num;
+ *count = expect;
return 0;
}
diff --git a/include/drv/wd_dh_drv.h b/include/drv/wd_dh_drv.h
index d205dc4..d2a6157 100644
--- a/include/drv/wd_dh_drv.h
+++ b/include/drv/wd_dh_drv.h
@@ -16,12 +16,15 @@ extern "C" {
/* DH message format */
struct wd_dh_msg {
struct wd_dh_req req;
+ struct wd_mm_ops *mm_ops;
+ enum wd_mem_type mm_type;
__u32 tag; /* User-defined request identifier */
void *g;
__u16 gbytes;
__u16 key_bytes; /* Input key bytes */
__u8 is_g2;
__u8 result; /* Data format, denoted by WD error code */
+ __u8 *rsv_out; /* reserved output data pointer */
};
struct wd_dh_msg *wd_dh_get_msg(__u32 idx, __u32 tag);
diff --git a/include/drv/wd_ecc_drv.h b/include/drv/wd_ecc_drv.h
index 6193c8b..b123a9b 100644
--- a/include/drv/wd_ecc_drv.h
+++ b/include/drv/wd_ecc_drv.h
@@ -48,6 +48,8 @@ extern "C" {
/* ECC message format */
struct wd_ecc_msg {
struct wd_ecc_req req;
+ struct wd_mm_ops *mm_ops;
+ enum wd_mem_type mm_type;
struct wd_hash_mt hash;
__u32 tag; /* User-defined request identifier */
__u8 *key; /* Input key VA, should be DMA buffer */
@@ -55,6 +57,7 @@ struct wd_ecc_msg {
__u8 curve_id; /* Ec curve denoted by enum wd_ecc_curve_type */
__u8 result; /* alg op error code */
void *drv_cfg; /* internal driver configuration */
+ __u8 *rsv_out; /* reserved output data pointer */
};
struct wd_ecc_pubkey {
diff --git a/include/drv/wd_rsa_drv.h b/include/drv/wd_rsa_drv.h
index d231ecf..c12f3e0 100644
--- a/include/drv/wd_rsa_drv.h
+++ b/include/drv/wd_rsa_drv.h
@@ -42,11 +42,14 @@ struct wd_rsa_kg_out {
/* RSA message format */
struct wd_rsa_msg {
struct wd_rsa_req req;
+ struct wd_mm_ops *mm_ops;
+ enum wd_mem_type mm_type;
__u32 tag; /* User-defined request identifier */
__u16 key_bytes; /* Input key bytes */
__u8 key_type; /* Denoted by enum wd_rsa_key_type */
__u8 result; /* Data format, denoted by WD error code */
__u8 *key; /* Input key VA pointer, should be DMA buffer */
+ __u8 *rsv_out; /* reserved output data pointer */
};
struct wd_rsa_msg *wd_rsa_get_msg(__u32 idx, __u32 tag);
diff --git a/include/wd_dh.h b/include/wd_dh.h
index afc2f7c..235c602 100644
--- a/include/wd_dh.h
+++ b/include/wd_dh.h
@@ -27,6 +27,8 @@ struct wd_dh_sess_setup {
__u16 key_bits; /* DH key bites */
bool is_g2; /* is g2 mode or not */
void *sched_param;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
struct wd_dh_req {
diff --git a/include/wd_ecc.h b/include/wd_ecc.h
index 6f670e2..18c1c0d 100644
--- a/include/wd_ecc.h
+++ b/include/wd_ecc.h
@@ -116,6 +116,8 @@ struct wd_ecc_sess_setup {
struct wd_rand_mt rand; /* rand method from user */
struct wd_hash_mt hash; /* hash method from user */
void *sched_param;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
struct wd_ecc_req {
diff --git a/include/wd_rsa.h b/include/wd_rsa.h
index 2f4e589..9c91432 100644
--- a/include/wd_rsa.h
+++ b/include/wd_rsa.h
@@ -60,6 +60,8 @@ struct wd_rsa_sess_setup {
__u16 key_bits; /* RSA key bits */
bool is_crt; /* CRT mode or not */
void *sched_param;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
bool wd_rsa_is_crt(handle_t sess);
diff --git a/wd_dh.c b/wd_dh.c
index 221322f..0c1372c 100644
--- a/wd_dh.c
+++ b/wd_dh.c
@@ -26,6 +26,8 @@ struct wd_dh_sess {
struct wd_dtb g;
struct wd_dh_sess_setup setup;
void *sched_key;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
static struct wd_dh_setting {
@@ -326,6 +328,8 @@ static int fill_dh_msg(struct wd_dh_msg *msg, struct wd_dh_req *req,
memcpy(&msg->req, req, sizeof(*req));
msg->result = WD_EINVAL;
msg->key_bytes = sess->key_size;
+ msg->mm_ops = &sess->mm_ops;
+ msg->mm_type = sess->mm_type;
if (unlikely(req->pri_bytes < sess->key_size)) {
WD_ERR("invalid: req pri bytes %hu is error!\n", req->pri_bytes);
@@ -581,6 +585,7 @@ void wd_dh_get_g(handle_t sess, struct wd_dtb **g)
handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup)
{
struct wd_dh_sess *sess;
+ int ret;
if (!setup) {
WD_ERR("invalid: alloc dh sess setup NULL!\n");
@@ -606,10 +611,19 @@ handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup)
memcpy(&sess->setup, setup, sizeof(*setup));
sess->key_size = setup->key_bits >> BYTE_BITS_SHIFT;
- sess->g.data = malloc(sess->key_size);
- if (!sess->g.data)
+ ret = wd_mem_ops_init(wd_dh_setting.config.ctxs[0].ctx, &setup->mm_ops, setup->mm_type);
+ if (ret) {
+ WD_ERR("failed to init memory ops!\n");
goto sess_err;
+ }
+ memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops));
+ sess->mm_type = setup->mm_type;
+ sess->g.data = sess->mm_ops.alloc(sess->mm_ops.usr, sess->key_size);
+ if (!sess->g.data) {
+ WD_ERR("failed to malloc sess g param memory!\n");
+ goto sess_err;
+ }
sess->g.bsize = sess->key_size;
/* Some simple scheduler don't need scheduling parameters */
sess->sched_key = (void *)wd_dh_setting.sched.sched_init(
@@ -622,7 +636,7 @@ handle_t wd_dh_alloc_sess(struct wd_dh_sess_setup *setup)
return (handle_t)sess;
sched_err:
- free(sess->g.data);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->g.data);
sess_err:
free(sess);
return (handle_t)0;
@@ -638,7 +652,7 @@ void wd_dh_free_sess(handle_t sess)
}
if (sess_t->g.data)
- free(sess_t->g.data);
+ sess_t->mm_ops.free(sess_t->mm_ops.usr, sess_t->g.data);
if (sess_t->sched_key)
free(sess_t->sched_key);
diff --git a/wd_ecc.c b/wd_ecc.c
index b1971b9..2c88d0a 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -52,6 +52,8 @@ struct wd_ecc_sess {
struct wd_ecc_sess_setup setup;
struct wd_ecc_extend_ops eops;
void *sched_key;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
struct wd_ecc_curve_list {
@@ -494,7 +496,7 @@ static void release_ecc_prikey(struct wd_ecc_sess *sess)
struct wd_ecc_prikey *prikey = sess->key.prikey;
wd_memset_zero(prikey->data, prikey->size);
- free(prikey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, prikey->data);
free(prikey);
sess->key.prikey = NULL;
}
@@ -503,7 +505,7 @@ static void release_ecc_pubkey(struct wd_ecc_sess *sess)
{
struct wd_ecc_pubkey *pubkey = sess->key.pubkey;
- free(pubkey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, pubkey->data);
free(pubkey);
sess->key.pubkey = NULL;
}
@@ -522,7 +524,7 @@ static struct wd_ecc_prikey *create_ecc_prikey(struct wd_ecc_sess *sess)
}
dsz = ECC_PRIKEY_SZ(hsz);
- data = malloc(dsz);
+ data = sess->mm_ops.alloc(sess->mm_ops.usr, dsz);
if (!data) {
WD_ERR("failed to malloc prikey data, sz = %u!\n", dsz);
free(prikey);
@@ -551,7 +553,7 @@ static struct wd_ecc_pubkey *create_ecc_pubkey(struct wd_ecc_sess *sess)
}
dsz = ECC_PUBKEY_SZ(hsz);
- data = malloc(dsz);
+ data = sess->mm_ops.alloc(sess->mm_ops.usr, dsz);
if (!data) {
WD_ERR("failed to malloc pubkey data, sz = %u!\n", dsz);
free(pubkey);
@@ -570,7 +572,7 @@ static void release_ecc_in(struct wd_ecc_sess *sess,
struct wd_ecc_in *ecc_in)
{
wd_memset_zero(ecc_in->data, ecc_in->size);
- free(ecc_in);
+ sess->mm_ops.free(sess->mm_ops.usr, ecc_in);
}
static struct wd_ecc_in *create_ecc_in(struct wd_ecc_sess *sess, __u32 num)
@@ -585,7 +587,7 @@ static struct wd_ecc_in *create_ecc_in(struct wd_ecc_sess *sess, __u32 num)
hsz = get_key_bsz(sess->key_size);
len = sizeof(struct wd_ecc_in) + hsz * num;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc ecc in, sz = %u!\n", len);
return NULL;
@@ -613,7 +615,7 @@ static struct wd_ecc_in *create_sm2_sign_in(struct wd_ecc_sess *sess,
len = sizeof(struct wd_ecc_in)
+ ECC_SIGN_IN_PARAM_NUM * ksz + m_len;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc sm2 sign in, sz = %llu!\n", len);
return NULL;
@@ -653,7 +655,7 @@ static struct wd_ecc_in *create_sm2_enc_in(struct wd_ecc_sess *sess,
}
len = sizeof(struct wd_ecc_in) + ksz + m_len;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc sm2 enc in, sz = %llu!\n", len);
return NULL;
@@ -697,7 +699,7 @@ static void *create_sm2_ciphertext(struct wd_ecc_sess *sess, __u32 m_len,
*len = (__u64)st_sz + ECC_POINT_PARAM_NUM * (__u64)sess->key_size +
(__u64)m_len + (__u64)h_byts;
- start = malloc(*len);
+ start = sess->mm_ops.alloc(sess->mm_ops.usr, *len);
if (unlikely(!start)) {
WD_ERR("failed to alloc start, sz = %llu!\n", *len);
return NULL;
@@ -745,7 +747,7 @@ static struct wd_ecc_out *create_ecc_out(struct wd_ecc_sess *sess, __u32 num)
hsz = get_key_bsz(sess->key_size);
len = sizeof(struct wd_ecc_out) + hsz * num;
- out = malloc(len);
+ out = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!out) {
WD_ERR("failed to malloc out, sz = %u!\n", len);
return NULL;
@@ -1149,13 +1151,13 @@ static void del_sess_key(struct wd_ecc_sess *sess)
{
if (sess->key.prikey) {
wd_memset_zero(sess->key.prikey->data, sess->key.prikey->size);
- free(sess->key.prikey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->key.prikey->data);
free(sess->key.prikey);
sess->key.prikey = NULL;
}
if (sess->key.pubkey) {
- free(sess->key.pubkey->data);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->key.pubkey->data);
free(sess->key.pubkey);
sess->key.pubkey = NULL;
}
@@ -1227,6 +1229,15 @@ handle_t wd_ecc_alloc_sess(struct wd_ecc_sess_setup *setup)
memcpy(&sess->setup, setup, sizeof(*setup));
sess->key_size = BITS_TO_BYTES(setup->key_bits);
+ /* Memory type set */
+ ret = wd_mem_ops_init(wd_ecc_setting.config.ctxs[0].ctx, &setup->mm_ops, setup->mm_type);
+ if (ret) {
+ WD_ERR("failed to init memory ops!\n");
+ goto sess_err;
+ }
+ memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops));
+ sess->mm_type = setup->mm_type;
+
if (wd_ecc_setting.driver->get_extend_ops) {
ret = wd_ecc_setting.driver->get_extend_ops(&sess->eops);
if (ret) {
@@ -1508,9 +1519,10 @@ void wd_ecxdh_get_out_params(struct wd_ecc_out *out, struct wd_ecc_point **pbk)
void wd_ecc_del_in(handle_t sess, struct wd_ecc_in *in)
{
+ struct wd_ecc_sess *sess_t = (struct wd_ecc_sess *)sess;
__u32 bsz;
- if (!in) {
+ if (!sess_t || !in) {
WD_ERR("invalid: del ecc in parameter error!\n");
return;
}
@@ -1522,14 +1534,15 @@ void wd_ecc_del_in(handle_t sess, struct wd_ecc_in *in)
}
wd_memset_zero(in->data, bsz);
- free(in);
+ sess_t->mm_ops.free(sess_t->mm_ops.usr, in);
}
-void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out)
+void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out)
{
+ struct wd_ecc_sess *sess_t = (struct wd_ecc_sess *)sess;
__u32 bsz;
- if (!out) {
+ if (!sess_t || !out) {
WD_ERR("invalid: del ecc out parameter error!\n");
return;
}
@@ -1541,7 +1554,7 @@ void wd_ecc_del_out(handle_t sess, struct wd_ecc_out *out)
}
wd_memset_zero(out->data, bsz);
- free(out);
+ sess_t->mm_ops.free(sess_t->mm_ops.usr, out);
}
static int fill_ecc_msg(struct wd_ecc_msg *msg, struct wd_ecc_req *req,
@@ -1551,6 +1564,8 @@ static int fill_ecc_msg(struct wd_ecc_msg *msg, struct wd_ecc_req *req,
memcpy(&msg->req, req, sizeof(msg->req));
memcpy(&msg->hash, &sess->setup.hash, sizeof(msg->hash));
+ msg->mm_ops = &sess->mm_ops;
+ msg->mm_type = sess->mm_type;
msg->key_bytes = sess->key_size;
msg->curve_id = sess->setup.cv.cfg.id;
msg->drv_cfg = sess->eops.params;
@@ -1922,7 +1937,7 @@ static struct wd_ecc_in *create_sm2_verf_in(struct wd_ecc_sess *sess,
hsz = get_key_bsz(sess->key_size);
len = sizeof(struct wd_ecc_in) + ECC_VERF_IN_PARAM_NUM * hsz +
m_len;
- in = malloc(len);
+ in = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!in) {
WD_ERR("failed to malloc sm2 verf in, sz = %llu!\n", len);
return NULL;
@@ -2211,7 +2226,7 @@ struct wd_ecc_out *wd_sm2_new_dec_out(handle_t sess, __u32 plaintext_len)
}
len = sizeof(*ecc_out) + plaintext_len;
- ecc_out = malloc(len);
+ ecc_out = sess_t->mm_ops.alloc(sess_t->mm_ops.usr, len);
if (!ecc_out) {
WD_ERR("failed to malloc ecc_out, sz = %llu!\n", len);
return NULL;
diff --git a/wd_rsa.c b/wd_rsa.c
index cf9239c..bc78c6a 100644
--- a/wd_rsa.c
+++ b/wd_rsa.c
@@ -67,6 +67,8 @@ struct wd_rsa_sess {
struct wd_rsa_prikey *prikey;
struct wd_rsa_sess_setup setup;
void *sched_key;
+ struct wd_mm_ops mm_ops;
+ enum wd_mem_type mm_type;
};
static struct wd_rsa_setting {
@@ -373,6 +375,8 @@ static int fill_rsa_msg(struct wd_rsa_msg *msg, struct wd_rsa_req *req,
memcpy(&msg->req, req, sizeof(*req));
msg->key_bytes = sess->key_size;
msg->result = WD_EINVAL;
+ msg->mm_ops = &sess->mm_ops;
+ msg->mm_type = sess->mm_type;
switch (msg->req.op_type) {
case WD_RSA_SIGN:
@@ -641,7 +645,7 @@ struct wd_rsa_kg_in *wd_rsa_new_kg_in(handle_t sess, struct wd_dtb *e,
}
kg_in_size = (int)GEN_PARAMS_SZ(c->key_size);
- kg_in = malloc(kg_in_size + sizeof(*kg_in));
+ kg_in = c->mm_ops.alloc(c->mm_ops.usr, kg_in_size + sizeof(*kg_in));
if (!kg_in) {
WD_ERR("failed to malloc kg_in memory!\n");
return NULL;
@@ -681,19 +685,16 @@ void wd_rsa_get_kg_in_params(struct wd_rsa_kg_in *kin, struct wd_dtb *e,
p->data = (void *)kin->p;
}
-static void del_kg(void *k)
+void wd_rsa_del_kg_in(handle_t sess, struct wd_rsa_kg_in *ki)
{
- if (!k) {
+ struct wd_rsa_sess *c = (struct wd_rsa_sess *)sess;
+
+ if (!c || !ki) {
WD_ERR("invalid: del key generate params err!\n");
return;
}
- free(k);
-}
-
-void wd_rsa_del_kg_in(handle_t sess, struct wd_rsa_kg_in *ki)
-{
- del_kg(ki);
+ c->mm_ops.free(c->mm_ops.usr, ki);
}
struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
@@ -719,7 +720,7 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
else
kg_out_size = (int)GEN_PARAMS_SZ(c->key_size);
- kg_out = malloc(kg_out_size + sizeof(*kg_out));
+ kg_out = c->mm_ops.alloc(c->mm_ops.usr, kg_out_size + sizeof(*kg_out));
if (!kg_out) {
WD_ERR("failed to malloc kg_out memory!\n");
return NULL;
@@ -741,13 +742,15 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess)
void wd_rsa_del_kg_out(handle_t sess, struct wd_rsa_kg_out *kout)
{
- if (!kout) {
+ struct wd_rsa_sess *c = (struct wd_rsa_sess *)sess;
+
+ if (!c || !kout) {
WD_ERR("invalid: param null at del kg out!\n");
return;
}
wd_memset_zero(kout->data, kout->size);
- del_kg(kout);
+ c->mm_ops.free(c->mm_ops.usr, kout);
}
void wd_rsa_get_kg_out_params(struct wd_rsa_kg_out *kout, struct wd_dtb *d,
@@ -804,6 +807,11 @@ void wd_rsa_set_kg_out_crt_psz(struct wd_rsa_kg_out *kout,
size_t dq_sz,
size_t dp_sz)
{
+ if (!kout) {
+ WD_ERR("invalid: input null when set kg out crt psz!\n");
+ return;
+ }
+
kout->qinvbytes = qinv_sz;
kout->dqbytes = dq_sz;
kout->dpbytes = dp_sz;
@@ -813,6 +821,11 @@ void wd_rsa_set_kg_out_psz(struct wd_rsa_kg_out *kout,
size_t d_sz,
size_t n_sz)
{
+ if (!kout) {
+ WD_ERR("invalid: input null when set kg out psz!\n");
+ return;
+ }
+
kout->dbytes = d_sz;
kout->nbytes = n_sz;
}
@@ -862,7 +875,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
if (setup->is_crt) {
len = sizeof(struct wd_rsa_prikey) +
(int)CRT_PARAMS_SZ(sess->key_size);
- sess->prikey = malloc(len);
+ sess->prikey = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!sess->prikey) {
WD_ERR("failed to alloc sess prikey2!\n");
return -WD_ENOMEM;
@@ -873,7 +886,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
} else {
len = sizeof(struct wd_rsa_prikey) +
(int)GEN_PARAMS_SZ(sess->key_size);
- sess->prikey = malloc(len);
+ sess->prikey = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!sess->prikey) {
WD_ERR("failed to alloc sess prikey1!\n");
return -WD_ENOMEM;
@@ -885,7 +898,7 @@ static int create_sess_key(struct wd_rsa_sess_setup *setup,
len = sizeof(struct wd_rsa_pubkey) +
(int)GEN_PARAMS_SZ(sess->key_size);
- sess->pubkey = malloc(len);
+ sess->pubkey = sess->mm_ops.alloc(sess->mm_ops.usr, len);
if (!sess->pubkey) {
free(sess->prikey);
WD_ERR("failed to alloc sess pubkey!\n");
@@ -912,8 +925,8 @@ static void del_sess_key(struct wd_rsa_sess *sess)
wd_memset_zero(prk->pkey.pkey2.data, CRT_PARAMS_SZ(sess->key_size));
else
wd_memset_zero(prk->pkey.pkey1.data, GEN_PARAMS_SZ(sess->key_size));
- free(sess->prikey);
- free(sess->pubkey);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->prikey);
+ sess->mm_ops.free(sess->mm_ops.usr, sess->pubkey);
}
static void del_sess(struct wd_rsa_sess *c)
@@ -948,6 +961,15 @@ handle_t wd_rsa_alloc_sess(struct wd_rsa_sess_setup *setup)
memcpy(&sess->setup, setup, sizeof(*setup));
sess->key_size = setup->key_bits >> BYTE_BITS_SHIFT;
+ /* Memory type set */
+ ret = wd_mem_ops_init(wd_rsa_setting.config.ctxs[0].ctx, &setup->mm_ops, setup->mm_type);
+ if (ret) {
+ WD_ERR("failed to init memory ops!\n");
+ goto sess_err;
+ }
+
+ memcpy(&sess->mm_ops, &setup->mm_ops, sizeof(struct wd_mm_ops));
+ sess->mm_type = setup->mm_type;
ret = create_sess_key(setup, sess);
if (ret) {
WD_ERR("failed to create rsa sess keys!\n");
--
2.33.0
1
2
From: Wenkai Lin <linwenkai6(a)hisilicon.com>
Extract a common function fill_hashagg_data_info.
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
drv/hisi_dae.c | 56 +++++++++++++++++++-------------------------------
1 file changed, 21 insertions(+), 35 deletions(-)
diff --git a/drv/hisi_dae.c b/drv/hisi_dae.c
index 4f4d13c..49387aa 100644
--- a/drv/hisi_dae.c
+++ b/drv/hisi_dae.c
@@ -26,7 +26,7 @@
#define DAE_VCHAR_OFFSET_SIZE 2
#define DAE_COL_BIT_NUM 4
#define DAE_AGG_START_COL 16
-#define DAE_HASHAGG_MAX_ROW_NUN 50000
+#define DAE_HASHAGG_MAX_ROW_NUM 50000
/* align size */
#define DAE_CHAR_ALIGN_SIZE 4
@@ -294,23 +294,8 @@ static void fill_hashagg_merge_key_data(struct dae_sqe *sqe, struct dae_ext_sqe
}
}
-static void fill_hashagg_normal_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
- struct hashagg_col_data *cols_data, __u32 agg_cols_num)
-{
- struct hw_agg_data *agg_data = cols_data->input_data;
- __u32 i;
-
- for (i = 0; i < agg_cols_num; i++) {
- sqe->agg_data_type[i] = agg_data[i].hw_type;
- sqe->agg_data_type[i] |= agg_data[i].sum_outtype << DAE_COL_BIT_NUM;
- ext_sqe->agg_data_info[i] = agg_data[i].data_info;
- }
-
- sqe->agg_col_bitmap = GENMASK(agg_cols_num + DAE_AGG_START_COL - 1, DAE_AGG_START_COL);
-}
-
-static void fill_hashagg_rehash_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
- struct hw_agg_data *agg_data, __u32 agg_cols_num)
+static void fill_hashagg_data_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
+ struct hw_agg_data *agg_data, __u32 agg_cols_num)
{
__u32 i;
@@ -344,14 +329,14 @@ static void fill_hashagg_input_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext
hw_agg_addr = &addr_list->input_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.agg_cols;
agg_col_num = msg->agg_cols_num;
- fill_hashagg_normal_info(sqe, ext_sqe, cols_data, agg_col_num);
+ fill_hashagg_data_info(sqe, ext_sqe, agg_data, agg_col_num);
break;
case WD_AGG_REHASH_INPUT:
agg_data = cols_data->output_data;
hw_agg_addr = &addr_list->input_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.agg_cols;
agg_col_num = cols_data->output_num;
- fill_hashagg_rehash_info(sqe, ext_sqe, agg_data, agg_col_num);
+ fill_hashagg_data_info(sqe, ext_sqe, agg_data, agg_col_num);
break;
case WD_AGG_STREAM_OUTPUT:
case WD_AGG_REHASH_OUTPUT:
@@ -359,7 +344,7 @@ static void fill_hashagg_input_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext
hw_agg_addr = &addr_list->output_addr[DAE_AGG_START_COL];
usr_agg_addr = msg->req.out_agg_cols;
agg_col_num = cols_data->output_num;
- fill_hashagg_normal_info(sqe, ext_sqe, cols_data, cols_data->input_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->input_data, cols_data->input_num);
break;
}
@@ -385,7 +370,7 @@ static void fill_hashagg_merge_input_data(struct dae_sqe *sqe, struct dae_ext_sq
struct hashagg_ctx *agg_ctx = msg->priv;
struct hashagg_col_data *cols_data = &agg_ctx->cols_data;
- fill_hashagg_rehash_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
+ fill_hashagg_data_info(sqe, ext_sqe, cols_data->output_data, msg->agg_cols_num);
}
static void fill_hashagg_ext_addr(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
@@ -422,26 +407,15 @@ static void fill_hashagg_info(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe,
static int check_hashagg_param(struct wd_agg_msg *msg)
{
- struct hashagg_col_data *cols_data;
- struct hashagg_ctx *agg_ctx;
-
if (!msg) {
WD_ERR("invalid: input hashagg msg is NULL!\n");
return -WD_EINVAL;
}
- agg_ctx = msg->priv;
- cols_data = &agg_ctx->cols_data;
- if (cols_data->output_num > DAE_MAX_OUTPUT_COLS) {
- WD_ERR("invalid: input hashagg output num %u is more than %d!\n",
- cols_data->output_num, DAE_MAX_OUTPUT_COLS);
- return -WD_EINVAL;
- }
-
if ((msg->pos == WD_AGG_STREAM_INPUT || msg->pos == WD_AGG_REHASH_INPUT) &&
- msg->row_count > DAE_HASHAGG_MAX_ROW_NUN) {
+ msg->row_count > DAE_HASHAGG_MAX_ROW_NUM) {
WD_ERR("invalid: input hashagg row count %u is more than %d!\n",
- msg->row_count, DAE_HASHAGG_MAX_ROW_NUN);
+ msg->row_count, DAE_HASHAGG_MAX_ROW_NUM);
return -WD_EINVAL;
}
@@ -1005,6 +979,7 @@ static int transfer_input_col_info(struct wd_agg_col_info *agg_cols,
struct hw_agg_data *user_output_data,
__u32 cols_num, __u32 *output_num)
{
+ __u32 tmp = *output_num;
__u32 i, j, k = 0;
int ret;
@@ -1013,7 +988,15 @@ static int transfer_input_col_info(struct wd_agg_col_info *agg_cols,
WD_ERR("invalid: col alg num(%u) more than 2!\n", agg_cols[i].col_alg_num);
return -WD_EINVAL;
}
+ tmp += agg_cols[i].col_alg_num;
+ }
+ if (tmp > DAE_MAX_OUTPUT_COLS) {
+ WD_ERR("invalid: output col num is more than %d!\n", DAE_MAX_OUTPUT_COLS);
+ return -WD_EINVAL;
+ }
+
+ for (i = 0; i < cols_num; i++) {
for (j = 0; j < agg_cols[i].col_alg_num; j++) {
ret = hashagg_check_input_data(&agg_cols[i], &user_input_data[i],
&user_output_data[k], j);
@@ -1137,6 +1120,9 @@ static int transfer_data_to_hw_type(struct hashagg_col_data *cols_data,
struct wd_agg_col_info *agg_cols = setup->agg_cols_info;
int ret;
+ if (setup->is_count_all)
+ cols_data->output_num++;
+
ret = transfer_input_col_info(agg_cols, user_input_data, user_output_data,
setup->agg_cols_num, &cols_data->output_num);
if (ret)
--
2.33.0
1
0
From: parm64 <parm64(a)huawei.com>
Zhushuai Yin (6):
uadk_provider: fix spelling errors and incorrect return value issues
uadk_provider: prov supports dynamic algorithm cropping func
uadk_provider: provide log configuration functionality
uadk_provider:fix the issue of algorithm prohibition failure for DH
uadk_provider: fix issues that may cause encryption to fail
uadk_engine: fix the issue of incorrect engine use the V2 interface
ZongYu Wu (1):
uadk_engine: fix uadk prov module spelling error
lizhi (2):
uadk_provider: fix poll timeout in abnormal scenarios
uadk_engine: clean up unused functions
src/uadk_aead.c | 2 +-
src/uadk_async.c | 9 +-
src/uadk_cipher.c | 3 +-
src/uadk_cipher_adapter.c | 3 +-
src/uadk_dh.c | 3 +-
src/uadk_digest.c | 2 +-
src/uadk_ec.c | 2 +-
src/uadk_ecx.c | 18 --
src/uadk_engine_init.c | 11 +-
src/uadk_pkey.c | 3 +-
src/uadk_prov.h | 23 +-
src/uadk_prov_aead.c | 105 +++----
src/uadk_prov_cipher.c | 120 ++++----
src/uadk_prov_dh.c | 194 ++++++------
src/uadk_prov_digest.c | 78 ++---
src/uadk_prov_ec_kmgmt.c | 60 ++--
src/uadk_prov_ecdh_exch.c | 73 ++---
src/uadk_prov_ecdsa.c | 118 ++++----
src/uadk_prov_ecx.c | 162 +++++-----
src/uadk_prov_ffc.c | 9 +-
src/uadk_prov_hmac.c | 76 ++---
src/uadk_prov_init.c | 607 +++++++++++++++++++++++++++++++++++---
src/uadk_prov_packet.c | 5 +-
src/uadk_prov_pkey.c | 87 +++---
src/uadk_prov_pkey.h | 3 -
src/uadk_prov_rsa.c | 111 ++++---
src/uadk_prov_sm2.c | 474 ++++++++++++++---------------
src/uadk_rsa.c | 3 +-
src/uadk_sm2.c | 9 -
src/uadk_utils.c | 14 +
src/uadk_utils.h | 27 ++
uadk_provider.cnf | 27 ++
32 files changed, 1507 insertions(+), 934 deletions(-)
--
2.43.0
1
9
14 Nov '25
From: Longfang Liu <liulongfang(a)huawei.com>
Add kernel-state reserved memory handling functionality to the
uadk SVA framework to adapt to No-SVA features, including functions
for applying for and initializing reserved memory pools, applying for,
using, and releasing memory within the memory pool.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
Signed-off-by: Zongyu Wu <wuzongyu1(a)huawei.com>
---
Makefile.am | 9 +-
include/uacce.h | 7 +
include/wd.h | 23 +
include/wd_alg_common.h | 36 +-
include/wd_bmm.h | 44 ++
include/wd_internal.h | 70 +++
include/wd_util.h | 2 +
libwd.map | 14 +
wd.c | 38 +-
wd_bmm.c | 1057 +++++++++++++++++++++++++++++++++++++++
wd_util.c | 107 +++-
11 files changed, 1355 insertions(+), 52 deletions(-)
create mode 100644 include/wd_bmm.h
create mode 100644 include/wd_internal.h
create mode 100644 wd_bmm.c
diff --git a/Makefile.am b/Makefile.am
index f897533..0e1203a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -32,12 +32,13 @@ YEAR = 2025
AM_CFLAGS+= -DUADK_VERSION_NUMBER="\"UADK version: ${MAJOR}.${MINOR}.${REVISION}\""
AM_CFLAGS+= -DUADK_RELEASED_TIME="\"Released ${MONTH} ${DAY}, ${YEAR}\""
-pkginclude_HEADERS = include/wd.h include/wd_cipher.h include/wd_aead.h \
+pkginclude_HEADERS = include/wd.h include/wd_internal.h include/wd_cipher.h include/wd_aead.h \
include/wd_comp.h include/wd_dh.h include/wd_digest.h \
include/wd_rsa.h include/uacce.h include/wd_alg_common.h \
include/wd_ecc.h include/wd_sched.h include/wd_alg.h \
include/wd_zlibwrapper.h include/wd_dae.h include/wd_agg.h \
- include/wd_udma.h include/wd_join_gather.h
+ include/wd_udma.h include/wd_join_gather.h \
+ include/wd_bmm.h
nobase_pkginclude_HEADERS = v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/uacce.h v1/wd_dh.h \
v1/wd_digest.h v1/wd_rsa.h v1/wd_bmm.h
@@ -48,7 +49,7 @@ uadk_driversdir=$(libdir)/uadk
uadk_drivers_LTLIBRARIES=libhisi_sec.la libhisi_hpre.la libhisi_zip.la \
libisa_ce.la libisa_sve.la libhisi_dae.la libhisi_udma.la
-libwd_la_SOURCES=wd.c wd_mempool.c wd.h wd_alg.c wd_alg.h \
+libwd_la_SOURCES=wd.c wd_mempool.c wd_bmm.c wd_bmm.h wd.h wd_alg.c wd_alg.h \
v1/wd.c v1/wd.h v1/wd_adapter.c v1/wd_adapter.h \
v1/wd_rsa.c v1/wd_rsa.h \
v1/wd_aead.c v1/wd_aead.h \
@@ -126,7 +127,7 @@ libwd_comp_la_DEPENDENCIES = libwd.la
libhisi_zip_la_LIBADD = -ldl
-libwd_crypto_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma
+libwd_crypto_la_LIBADD = -lwd -ldl -lnuma -lm -lpthread
libwd_crypto_la_DEPENDENCIES = libwd.la
libwd_udma_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -lm -lpthread
diff --git a/include/uacce.h b/include/uacce.h
index f7fae27..c6bb4fb 100644
--- a/include/uacce.h
+++ b/include/uacce.h
@@ -15,6 +15,12 @@ extern "C" {
#define UACCE_CMD_START _IO('W', 0)
#define UACCE_CMD_PUT_Q _IO('W', 1)
+#define UACCE_CMD_GET_SS_DMA _IOR('W', 3, unsigned long)
+
+/* Pass DMA SS region slice size by granularity 64KB */
+#define UACCE_GRAN_SIZE 0x10000ull
+#define UACCE_GRAN_SHIFT 16
+#define UACCE_GRAN_NUM_MASK 0xfffull
/**
* UACCE Device flags:
@@ -33,6 +39,7 @@ enum {
enum uacce_qfrt {
UACCE_QFRT_MMIO = 0, /* device mmio region */
UACCE_QFRT_DUS = 1, /* device user share */
+ UACCE_QFRT_SS, /* static share memory */
UACCE_QFRT_MAX,
};
diff --git a/include/wd.h b/include/wd.h
index b62d355..b97e5c7 100644
--- a/include/wd.h
+++ b/include/wd.h
@@ -38,6 +38,7 @@ typedef unsigned long long __u64;
/* Required compiler attributes */
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define handle_t uintptr_t
typedef struct wd_dev_mask wd_dev_mask_t;
@@ -115,6 +116,28 @@ enum wd_alg_type {
WD_AEAD,
};
+/* Memory APIs for UADK API Layer */
+typedef void *(*wd_alloc)(void *usr, size_t size);
+typedef void (*wd_free)(void *usr, void *va);
+
+ /* Memory VA to DMA address map and unmap */
+typedef void *(*wd_map)(void *usr, void *va, size_t sz);
+typedef void (*wd_unmap)(void *usr, void *va, void *dma, size_t sz);
+typedef __u32 (*wd_bufsize)(void *usr);
+
+/* Memory from user, it is given at ctx creating. */
+struct wd_mm_ops {
+ wd_alloc alloc; /* Memory allocation */
+ wd_free free; /* Memory free */
+ wd_map iova_map; /* Get iova from user space VA */
+
+ /* Destroy the mapping between the PA of VA and iova */
+ wd_unmap iova_unmap;
+ wd_bufsize get_bufsize; /* Optional */
+ void *usr; /* Data for the above operations */
+ bool sva_mode; /* Record whether the OS is SVA or No-SVA mode */
+};
+
/*
* If the actual size of data is inconsistent
* with dsize, undefined behavior occurs.
diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h
index fd77426..a294877 100644
--- a/include/wd_alg_common.h
+++ b/include/wd_alg_common.h
@@ -12,6 +12,7 @@
#include <numa.h>
#include "wd.h"
#include "wd_alg.h"
+#include "wd_internal.h"
#ifdef __cplusplus
extern "C" {
@@ -24,7 +25,6 @@ extern "C" {
#define BITS_TO_BYTES(bits) (((bits) + 7) >> 3)
#define BYTES_TO_BITS(bytes) ((bytes) << 3)
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define MAX_STR_LEN 256
#define CTX_TYPE_INVALID 9999
#define POLL_TIME 1000
@@ -60,6 +60,13 @@ enum wd_init_type {
WD_TYPE_V2,
};
+enum wd_mem_type {
+ UADK_MEM_AUTO,
+ UADK_MEM_USER,
+ UADK_MEM_PROXY,
+ UADK_MEM_MAX,
+};
+
/*
* struct wd_ctx - Define one ctx and related type.
* @ctx: The ctx itself.
@@ -132,27 +139,6 @@ struct wd_ctx_params {
struct wd_cap_config *cap;
};
-struct wd_soft_ctx {
- void *priv;
-};
-
-struct wd_ctx_internal {
- handle_t ctx;
- __u8 op_type;
- __u8 ctx_mode;
- __u16 sqn;
- pthread_spinlock_t lock;
-};
-
-struct wd_ctx_config_internal {
- __u32 ctx_num;
- int shmid;
- struct wd_ctx_internal *ctxs;
- void *priv;
- bool epoll_en;
- unsigned long *msg_cnt;
-};
-
/*
* struct wd_comp_sched - Define a scheduler.
* @name: Name of this scheduler.
@@ -181,12 +167,6 @@ struct wd_sched {
typedef int (*wd_alg_init)(struct wd_ctx_config *config, struct wd_sched *sched);
typedef int (*wd_alg_poll_ctx)(__u32 idx, __u32 expt, __u32 *count);
-struct wd_datalist {
- void *data;
- __u32 len;
- struct wd_datalist *next;
-};
-
#ifdef __cplusplus
}
#endif
diff --git a/include/wd_bmm.h b/include/wd_bmm.h
new file mode 100644
index 0000000..76b56a0
--- /dev/null
+++ b/include/wd_bmm.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved.
+ */
+
+#ifndef _WD_SVA_BMM_H
+#define _WD_SVA_BMM_H
+
+#include <stdint.h>
+#include "wd.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Memory pool creating parameters */
+struct wd_mempool_setup {
+ __u32 block_size; /* Block buffer size */
+ __u32 block_num; /* Block buffer number */
+ __u32 align_size; /* Block buffer starting address align size */
+ struct wd_mm_ops ops; /* memory from user if don't use UADK memory */
+};
+
+void *wd_mempool_alloc(handle_t h_ctx, struct wd_mempool_setup *setup);
+void wd_mempool_free(handle_t h_ctx, void *pool);
+void *wd_mem_alloc(void *pool, size_t size);
+void wd_mem_free(void *pool, void *buf);
+
+void *wd_mem_map(void *pool, void *buf, size_t sz);
+void wd_mem_unmap(void *pool, void *buf_dma, void *buf, size_t sz);
+int wd_get_free_num(void *pool, __u32 *free_num);
+int wd_get_fail_num(void *pool, __u32 *fail_num);
+__u32 wd_get_bufsize(void *pool);
+
+handle_t wd_find_ctx(const char *alg_name);
+void wd_remove_ctx_list(void);
+int wd_insert_ctx_list(handle_t h_ctx, char *alg_name);
+__u32 wd_get_dev_id(void *pool);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _WD_SVA_BMM_H */
diff --git a/include/wd_internal.h b/include/wd_internal.h
new file mode 100644
index 0000000..cd90ebf
--- /dev/null
+++ b/include/wd_internal.h
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved.
+ */
+
+#ifndef WD_INTERNAL_H
+#define WD_INTERNAL_H
+
+#include <pthread.h>
+#include <stdbool.h>
+#include "wd.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DECIMAL_NUMBER 10
+#define MAX_FD_NUM 65535
+
+struct wd_ctx_h {
+ int fd;
+ char dev_path[MAX_DEV_NAME_LEN];
+ char *dev_name;
+ char *drv_name;
+ unsigned long qfrs_offs[UACCE_QFRT_MAX];
+ void *qfrs_base[UACCE_QFRT_MAX];
+ struct uacce_dev *dev;
+ void *priv;
+};
+
+struct wd_soft_ctx {
+ int fd;
+ void *priv;
+};
+
+struct wd_ce_ctx {
+ int fd;
+ char *drv_name;
+ void *priv;
+};
+
+struct wd_ctx_internal {
+ handle_t ctx;
+ __u8 op_type;
+ __u8 ctx_mode;
+ __u16 sqn;
+ pthread_spinlock_t lock;
+};
+
+struct wd_ctx_config_internal {
+ __u32 ctx_num;
+ int shmid;
+ struct wd_ctx_internal *ctxs;
+ void *priv;
+ bool epoll_en;
+ unsigned long *msg_cnt;
+ char *alg_name;
+};
+
+struct wd_datalist {
+ void *data;
+ __u32 len;
+ struct wd_datalist *next;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/wd_util.h b/include/wd_util.h
index 4a5204d..a337284 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -553,6 +553,8 @@ static inline void wd_ctx_spin_unlock(struct wd_ctx_internal *ctx, int type)
pthread_spin_unlock(&ctx->lock);
}
+int wd_mem_ops_init(handle_t h_ctx, struct wd_mm_ops *mm_ops, int mem_type);
+
#ifdef __cplusplus
}
#endif
diff --git a/libwd.map b/libwd.map
index 5522ec0..b1b90b3 100644
--- a/libwd.map
+++ b/libwd.map
@@ -49,5 +49,19 @@ global:
wd_enable_drv;
wd_disable_drv;
wd_get_alg_head;
+
+ wd_find_ctx;
+ wd_get_dev_id;
+ wd_remove_ctx_list;
+ wd_insert_ctx_list;
+ wd_mempool_alloc;
+ wd_mempool_free;
+ wd_mem_alloc;
+ wd_mem_free;
+ wd_mem_map;
+ wd_mem_unmap;
+ wd_get_free_num;
+ wd_get_fail_num;
+ wd_get_bufsize;
local: *;
};
diff --git a/wd.c b/wd.c
index c1cc282..3e867b6 100644
--- a/wd.c
+++ b/wd.c
@@ -20,6 +20,7 @@
#include "wd.h"
#include "wd_alg.h"
+#include "wd_internal.h"
#define SYS_CLASS_DIR "/sys/class/uacce"
#define FILE_MAX_SIZE (8 << 20)
@@ -33,16 +34,18 @@ enum UADK_LOG_LEVEL {
static int uadk_log_level = WD_LOG_INVALID;
-struct wd_ctx_h {
- int fd;
- char dev_path[MAX_DEV_NAME_LEN];
- char *dev_name;
- char *drv_name;
- unsigned long qfrs_offs[UACCE_QFRT_MAX];
- void *qfrs_base[UACCE_QFRT_MAX];
- struct uacce_dev *dev;
- void *priv;
-};
+static int wd_check_ctx_type(handle_t h_ctx)
+{
+ struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+
+ /* A simple and efficient method to check the queue type */
+ if (ctx->fd < 0 || ctx->fd > MAX_FD_NUM) {
+ WD_INFO("Invalid: this ctx not HW ctx.\n");
+ return -WD_HW_EACCESS;
+ }
+
+ return 0;
+}
static void wd_parse_log_level(void)
{
@@ -446,7 +449,7 @@ void wd_release_ctx(handle_t h_ctx)
{
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
- if (!ctx)
+ if (!ctx || wd_check_ctx_type(h_ctx))
return;
close(ctx->fd);
@@ -461,7 +464,7 @@ int wd_ctx_start(handle_t h_ctx)
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
int ret;
- if (!ctx)
+ if (!ctx || wd_check_ctx_type(h_ctx))
return -WD_EINVAL;
ret = wd_ctx_set_io_cmd(h_ctx, UACCE_CMD_START, NULL);
@@ -527,6 +530,7 @@ void wd_ctx_unmap_qfr(handle_t h_ctx, enum uacce_qfrt qfrt)
unsigned long wd_ctx_get_region_size(handle_t h_ctx, enum uacce_qfrt qfrt)
{
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+
if (!ctx || qfrt >= UACCE_QFRT_MAX)
return 0;
return ctx->qfrs_offs[qfrt];
@@ -585,8 +589,16 @@ int wd_ctx_wait(handle_t h_ctx, __u16 ms)
int wd_is_sva(handle_t h_ctx)
{
struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+ int ret;
- if (!ctx || !ctx->dev)
+ if (!ctx)
+ return -WD_EINVAL;
+
+ ret = wd_check_ctx_type(h_ctx);
+ if (ret)
+ return ret;
+
+ if (!ctx->dev)
return -WD_EINVAL;
if ((unsigned int)ctx->dev->flags & UACCE_DEV_SVA)
diff --git a/wd_bmm.c b/wd_bmm.c
new file mode 100644
index 0000000..21c46ca
--- /dev/null
+++ b/wd_bmm.c
@@ -0,0 +1,1057 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved.
+ */
+
+/* Block Memory Management (lib): Adapted for SVA mode */
+#define _GNU_SOURCE
+#include <dirent.h>
+#include <numa.h>
+#include <sched.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include "wd_internal.h"
+#include "wd_bmm.h"
+#include "uacce.h"
+#include "wd.h"
+
+#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
+#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define UACCE_DEV_IOMMU (1<<7)
+
+#define TAG_FREE 0x12345678 /* block is free */
+#define TAG_USED 0x87654321 /* block is busy */
+#define MAX_ALIGN_SIZE 0x1000 /* 4KB */
+#define MAX_BLOCK_SIZE 0x10000000 /* 256MB */
+#define BLK_BALANCE_SZ 0x100000ul
+#define NUM_TIMES(x) (87 * (x) / 100)
+
+#define BYTE_SIZE 8
+#define BIT_SHIFT 3
+
+struct wd_ss_region {
+ unsigned long long pa;
+ void *va;
+ size_t size;
+ TAILQ_ENTRY(wd_ss_region) next;
+};
+TAILQ_HEAD(wd_ss_region_list, wd_ss_region);
+
+struct ctx_info {
+ int fd;
+ int iommu_type;
+ void *ss_va;
+ size_t ss_mm_size;
+ struct wd_ss_region_list ss_list;
+ struct wd_ss_region_list *head;
+ unsigned long qfrs_offset[UACCE_QFRT_MAX];
+};
+
+struct wd_blk_hd {
+ unsigned int blk_tag;
+ unsigned int blk_num;
+ void *blk_dma;
+ void *blk;
+};
+
+struct wd_blkpool {
+ pthread_spinlock_t pool_lock;
+ unsigned int free_blk_num;
+ unsigned int alloc_failures;
+ struct ctx_info *cinfo;
+ struct wd_blk_hd *blk_array; // memory blk array
+ unsigned int total_blocks; // total blk numbers
+ unsigned char *free_bitmap; // free blk bitmap, 0 mean unused
+ unsigned int bitmap_size; // bitmap's memory size
+ void *usr_mem_start;
+ void *act_start;
+ unsigned int act_hd_sz;
+ unsigned int act_blk_sz;
+ unsigned long act_mem_sz;
+ unsigned int dev_id;
+ struct wd_mempool_setup setup;
+};
+
+struct mem_ctx_node {
+ char alg_name[CRYPTO_MAX_ALG_NAME];
+ handle_t h_ctx;
+ int numa_id;
+ bool used;
+ TAILQ_ENTRY(mem_ctx_node) list_node;
+};
+static TAILQ_HEAD(, mem_ctx_node) g_mem_ctx_list = TAILQ_HEAD_INITIALIZER(g_mem_ctx_list);
+static pthread_mutex_t g_mem_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+handle_t wd_find_ctx(const char *alg_name)
+{
+ struct mem_ctx_node *close_node = NULL;
+ struct mem_ctx_node *node;
+ int min_distance = 0xFFFF;
+ int cpu = sched_getcpu();
+ int nid = numa_node_of_cpu(cpu);
+ handle_t h_ctx = 0;
+ int numa_dis;
+
+ if (!alg_name) {
+ WD_ERR("Invalid: alg_name is NULL!\n");
+ return 0;
+ }
+
+ pthread_mutex_lock(&g_mem_ctx_mutex);
+ TAILQ_FOREACH(node, &g_mem_ctx_list, list_node) {
+ if (node->used == false && strstr(node->alg_name, alg_name)) {
+ if (node->numa_id == nid) {
+ h_ctx = node->h_ctx;
+ node->used = true;
+ break;
+ }
+
+ /* Query the queue with the shortest NUMA distance */
+ numa_dis = numa_distance(nid, node->numa_id);
+ if (numa_dis < min_distance) {
+ min_distance = numa_dis;
+ close_node = node;
+ }
+ }
+ }
+
+ /* If no ctx matching the NUMA ID, use the shortest distance instead ctx */
+ if (!h_ctx && close_node) {
+ h_ctx = close_node->h_ctx;
+ close_node->used = true;
+ }
+ pthread_mutex_unlock(&g_mem_ctx_mutex);
+
+ if (!h_ctx)
+ WD_ERR("Failed to find mem ctx for alg: %s\n", alg_name);
+
+ return h_ctx;
+}
+
+void wd_remove_ctx_list(void)
+{
+ struct mem_ctx_node *node;
+
+ pthread_mutex_lock(&g_mem_ctx_mutex);
+ /* Free all list node */
+ while ((node = TAILQ_FIRST(&g_mem_ctx_list)) != NULL) {
+ /* Use TAILQ_REMOVE to remove list node */
+ TAILQ_REMOVE(&g_mem_ctx_list, node, list_node);
+ free(node);
+ }
+
+ pthread_mutex_unlock(&g_mem_ctx_mutex);
+}
+
+int wd_insert_ctx_list(handle_t h_ctx, char *alg_name)
+{
+ struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+ struct mem_ctx_node *new_node;
+ int numa_id;
+
+ if (!alg_name || !h_ctx) {
+ WD_ERR("Invalid: input params is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ /* A simple and efficient method to check the queue type */
+ if (ctx->fd < 0 || ctx->fd > MAX_FD_NUM) {
+ WD_INFO("Invalid ctx: this ctx not HW ctx.\n");
+ return 0;
+ }
+
+ numa_id = ctx->dev->numa_id;
+ new_node = malloc(sizeof(struct mem_ctx_node));
+ if (new_node) {
+ pthread_mutex_lock(&g_mem_ctx_mutex);
+ strncpy(new_node->alg_name, alg_name, CRYPTO_MAX_ALG_NAME - 1);
+ new_node->alg_name[CRYPTO_MAX_ALG_NAME - 1] = '\0';
+ new_node->numa_id = numa_id;
+ new_node->h_ctx = h_ctx;
+ new_node->used = false;
+ TAILQ_INSERT_TAIL(&g_mem_ctx_list, new_node, list_node);
+ pthread_mutex_unlock(&g_mem_ctx_mutex);
+ return 0;
+ }
+
+ return -WD_ENOMEM;
+}
+
+static void wd_free_slice(struct ctx_info *cinfo)
+{
+ struct wd_ss_region *rgn;
+
+ while (true) {
+ rgn = TAILQ_FIRST(&cinfo->ss_list);
+ if (!rgn)
+ break;
+ TAILQ_REMOVE(&cinfo->ss_list, rgn, next);
+ free(rgn);
+ }
+}
+
+static void wd_add_slice(struct ctx_info *cinfo, struct wd_ss_region *rgn)
+{
+ struct wd_ss_region *rg;
+
+ rg = TAILQ_LAST(&cinfo->ss_list, wd_ss_region_list);
+ if (rg) {
+ if (rg->pa + rg->size == rgn->pa) {
+ rg->size += rgn->size;
+ free(rgn);
+ return;
+ }
+ }
+
+ TAILQ_INSERT_TAIL(&cinfo->ss_list, rgn, next);
+}
+
+static void wd_show_ss_slices(struct ctx_info *cinfo)
+{
+ struct wd_ss_region *rgn;
+ int i = 0;
+
+ TAILQ_FOREACH(rgn, cinfo->head, next) {
+ WD_ERR("slice-%d:size = 0x%lx\n", i, rgn->size);
+ i++;
+ }
+}
+
+static void bitmap_set_bit(unsigned char *bitmap, unsigned int bit_index)
+{
+ if (!bitmap)
+ return;
+
+ bitmap[bit_index >> BIT_SHIFT] |= (1 << (bit_index % BYTE_SIZE));
+}
+
+static void bitmap_clear_bit(unsigned char *bitmap, unsigned int bit_index)
+{
+ if (!bitmap)
+ return;
+
+ bitmap[bit_index >> BIT_SHIFT] &= ~(1 << (bit_index % BYTE_SIZE));
+}
+
+static bool bitmap_test_bit(const unsigned char *bitmap, unsigned int bit_index)
+{
+ if (!bitmap)
+ return false;
+
+ /* bit is 1, it indicates that the block has already been used and is not free */
+ if ((bitmap[bit_index >> BIT_SHIFT] >> (bit_index % BYTE_SIZE)) & 0x1)
+ return false;
+
+ return true;
+}
+
+static void *wd_mmap_qfr(struct ctx_info *cinfo, enum uacce_qfrt qfrt, size_t size)
+{
+ off_t off;
+
+ off = qfrt * getpagesize();
+
+ return mmap(0, size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, cinfo->fd, off);
+}
+
+static void wd_unmap_reserve_mem(void *addr, size_t size)
+{
+ int ret;
+
+ if (!addr)
+ return;
+
+ ret = munmap(addr, size);
+ if (ret)
+ WD_ERR("wd qfr unmap failed!\n");
+}
+
+static void *wd_map_reserve_mem(struct wd_blkpool *pool, size_t size)
+{
+ struct ctx_info *cinfo = pool->cinfo;
+ struct wd_ss_region *rgn;
+ unsigned long info;
+ size_t tmp = size;
+ unsigned long i = 0;
+ void *ptr;
+ int ret = 1;
+
+ if (!cinfo) {
+ WD_ERR("ctx queue information is NULL!\n");
+ return NULL;
+ }
+
+ /* Make sure memory map granularity size align */
+ if (!cinfo->iommu_type)
+ tmp = ALIGN(tmp, UACCE_GRAN_SIZE);
+
+ ptr = wd_mmap_qfr(cinfo, UACCE_QFRT_SS, tmp);
+ if (ptr == MAP_FAILED) {
+ WD_ERR("wd drv mmap fail!(err = %d)\n", errno);
+ return NULL;
+ }
+
+ cinfo->ss_va = ptr;
+ cinfo->ss_mm_size = tmp;
+ tmp = 0;
+ while (ret > 0) {
+ info = i;
+ ret = ioctl(cinfo->fd, UACCE_CMD_GET_SS_DMA, &info);
+ if (ret < 0) {
+ wd_show_ss_slices(cinfo);
+ WD_ERR("get DMA fail!\n");
+ goto err_out;
+ }
+
+ rgn = malloc(sizeof(*rgn));
+ if (!rgn) {
+ WD_ERR("alloc ss region fail!\n");
+ goto err_out;
+ }
+ memset(rgn, 0, sizeof(*rgn));
+
+ if (cinfo->iommu_type)
+ rgn->size = cinfo->ss_mm_size;
+ else
+ rgn->size = (info & UACCE_GRAN_NUM_MASK) <<
+ UACCE_GRAN_SHIFT;
+ rgn->pa = info & (~UACCE_GRAN_NUM_MASK);
+ rgn->va = ptr + tmp;
+ tmp += rgn->size;
+ wd_add_slice(cinfo, rgn);
+
+ i++;
+ }
+
+ return ptr;
+
+err_out:
+ wd_free_slice(cinfo);
+ wd_unmap_reserve_mem(cinfo->ss_va, cinfo->ss_mm_size);
+
+ return NULL;
+}
+
+static int wd_pool_params_check(struct wd_mempool_setup *setup)
+{
+ if (!setup->block_num || !setup->block_size ||
+ setup->block_size > MAX_BLOCK_SIZE) {
+ WD_ERR("Invalid: block_size or block_num(%x, %u)!\n",
+ setup->block_size, setup->block_num);
+ return -WD_EINVAL;
+ }
+
+ /* Check parameters, and align_size must be 2^N */
+ if (setup->align_size <= 0x1 || setup->align_size > MAX_ALIGN_SIZE ||
+ (setup->align_size & (setup->align_size - 0x1))) {
+ WD_ERR("Invalid align_size.\n");
+ return -WD_EINVAL;
+ }
+
+ return WD_SUCCESS;
+}
+
+static int wd_ctx_info_init(struct wd_ctx_h *ctx, struct wd_blkpool *p)
+{
+ struct ctx_info *cinfo;
+
+ cinfo = calloc(1, sizeof(struct ctx_info));
+ if (!cinfo) {
+ WD_ERR("failed to alloc ctx info memory.\n");
+ return -WD_ENOMEM;
+ }
+
+ cinfo->fd = ctx->fd;
+ cinfo->iommu_type = (unsigned int)ctx->dev->flags & UACCE_DEV_IOMMU;
+ cinfo->head = &cinfo->ss_list;
+ TAILQ_INIT(&cinfo->ss_list);
+ (void)memcpy(cinfo->qfrs_offset, ctx->qfrs_offs,
+ sizeof(cinfo->qfrs_offset));
+ p->cinfo = (void *)cinfo;
+
+ return 0;
+}
+
+static int wd_pool_pre_layout(handle_t h_ctx,
+ struct wd_blkpool *p,
+ struct wd_mempool_setup *sp)
+{
+ struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+ struct ctx_info *cinfo = NULL;
+ unsigned int asz;
+ int ret;
+
+ if (!ctx && !sp->ops.alloc) {
+ WD_ERR("ctx is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (!sp->ops.alloc) {
+ ret = wd_ctx_info_init(ctx, p);
+ if (ret) {
+ WD_ERR("failed to init ctx info.\n");
+ return ret;
+ }
+ cinfo = p->cinfo;
+ }
+
+ ret = wd_pool_params_check(sp);
+ if (ret) {
+ free(p->cinfo);
+ p->cinfo = NULL;
+ return ret;
+ }
+
+ asz = sp->align_size;
+
+ /* Get actual value by align */
+ p->act_hd_sz = ALIGN(sizeof(struct wd_blk_hd), asz);
+ p->act_blk_sz = ALIGN(sp->block_size, asz);
+ p->act_mem_sz = (p->act_hd_sz + p->act_blk_sz) *
+ (unsigned long)sp->block_num + asz;
+
+ /*
+ * When we use WD reserve memory and the blk_sz is larger than 1M,
+ * in order to ensure the mem_pool to be success,
+ * ensure that the allocated memory is an integer multiple of 1M.
+ */
+ if (!sp->ops.alloc && (cinfo && !cinfo->iommu_type))
+ p->act_mem_sz = ((p->act_mem_sz + BLK_BALANCE_SZ - 1) & ~(BLK_BALANCE_SZ - 1)) << 1;
+
+ return WD_SUCCESS;
+}
+
+/**
+ * wd_iova_map - Map virtual address to physical address
+ * @cinfo: context information
+ * @va: virtual address to map
+ * @sz: size of the mapping (not used in current implementation)
+ *
+ * When IOMMU is enabled, the PA is actually an IOVA; userspace still sees it
+ * as consistent and contiguous with the VA.
+ * When IOMMU is disabled, the PA refers to the kernel's physical address, which
+ * must be physically contiguous to be allocated by the kernel.
+ * Therefore, the PA address can be obtained from the offset of the VA.
+ *
+ */
+static void *wd_iova_map(struct ctx_info *cinfo, void *va, size_t sz)
+{
+ struct wd_ss_region *rgn;
+ unsigned long offset;
+ void *dma_addr;
+
+ if (!cinfo || !va) {
+ WD_ERR("wd iova map: parameter err!\n");
+ return NULL;
+ }
+
+ /* Search through all memory regions to find where va belongs */
+ TAILQ_FOREACH(rgn, cinfo->head, next) {
+ if (rgn->va <= va && va < rgn->va + rgn->size) {
+ /* Calculate offset within the region */
+ offset = (uintptr_t)va - (uintptr_t)rgn->va;
+ /* Add base physical address of the region */
+ dma_addr = (void *)((uintptr_t)rgn->pa + offset);
+ return dma_addr;
+ }
+ }
+
+ WD_ERR("wd iova map: va not found in any region\n");
+ return NULL;
+}
+
+/**
+ * wd_iova_unmap - Unmap physical address (no-op in non-IOMMU mode)
+ * @cinfo: context information
+ * @va: virtual address
+ * @dma: physical address
+ * @sz: size of the mapping (not used in current implementation)
+ *
+ * In non-IOMMU mode, this function does nothing as there's no need to unmap.
+ * In IOMMU mode, this would typically involve unmapping the DMA address.
+ */
+static void wd_iova_unmap(struct ctx_info *cinfo, void *va, void *dma, size_t sz)
+{
+ /* For no-iommu, dma-unmap doing nothing */
+}
+
+static void wd_pool_uninit(struct wd_blkpool *p)
+{
+ struct ctx_info *cinfo = p->cinfo;
+ struct wd_blk_hd *fhd = NULL;
+ unsigned long block_size;
+ unsigned int i;
+
+ block_size = (unsigned long)p->act_hd_sz + p->act_blk_sz;
+ /* Clean up the allocated resources. */
+ for (i = 0; i < p->total_blocks; i++) {
+ /* Release the previously allocated blocks. */
+ fhd = &p->blk_array[i];
+ wd_iova_unmap(cinfo, fhd->blk, fhd->blk_dma, block_size);
+ }
+
+ free(p->free_bitmap);
+ p->free_bitmap = NULL;
+ free(p->blk_array);
+ p->blk_array = NULL;
+}
+
+static int wd_pool_init(struct wd_blkpool *p)
+{
+ struct ctx_info *cinfo = p->cinfo;
+ __u32 blk_size = p->setup.block_size;
+ void *dma_start, *dma_end, *va;
+ struct wd_blk_hd *fhd = NULL;
+ struct wd_blk_hd *hd = NULL;
+ unsigned int i, j, act_num;
+ unsigned long block_size;
+ unsigned int dma_num = 0;
+
+ p->act_start = (void *)ALIGN((uintptr_t)p->usr_mem_start,
+ p->setup.align_size);
+
+ /* Calculate the actual number of allocatable blocks */
+ block_size = (unsigned long)(p->act_hd_sz + p->act_blk_sz);
+ if (block_size == 0) {
+ WD_ERR("Invalid block size with header.\n");
+ return -WD_EINVAL;
+ }
+ act_num = p->act_mem_sz / block_size;
+ if (!act_num) {
+ WD_ERR("Invalid memory size.\n");
+ return -WD_EINVAL;
+ }
+
+ /* Allocate block array */
+ p->blk_array = (struct wd_blk_hd *)malloc(act_num * sizeof(struct wd_blk_hd));
+ if (!p->blk_array) {
+ WD_ERR("Failed to allocate block array.\n");
+ return -WD_ENOMEM;
+ }
+
+ /* Allocate bitmap */
+ p->total_blocks = act_num;
+ p->bitmap_size = (act_num + BYTE_SIZE - 1) >> BIT_SHIFT;
+ p->free_bitmap = (unsigned char *)calloc(1, p->bitmap_size);
+ if (!p->free_bitmap) {
+ WD_ERR("Failed to allocate free bitmap.\n");
+ goto bitmap_error;
+ }
+
+ /* Initialize all blocks. */
+ for (i = 0; i < act_num; i++) {
+ /* Calculate the virtual address of the current block. */
+ va = (void *)((uintptr_t)p->act_start + block_size * i);
+
+ /* Get the physical address. */
+ dma_start = wd_iova_map(cinfo, va, 0);
+ dma_end = wd_iova_map(cinfo, va + blk_size - 1, 0);
+ if (!dma_start || !dma_end) {
+ WD_ERR("wd_iova_map err.\n");
+ /* Clean up the allocated resources. */
+ goto init_blk_error;
+ }
+
+ /* Check whether the physical addresses are contiguous. */
+ if ((uintptr_t)dma_end - (uintptr_t)dma_start != blk_size - 1) {
+ /* If OS kernel is not open SMMU, need to check dma address */
+ WD_INFO("wd dma address not continuous.\n");
+ /* Mark as unavailable, bit value is 1. */
+ bitmap_set_bit(p->free_bitmap, i);
+ continue;
+ }
+
+ /* Initialize the block. */
+ hd = &p->blk_array[i];
+ hd->blk_dma = dma_start;
+ hd->blk = va;
+ hd->blk_tag = TAG_FREE;
+ hd->blk_num = 0;
+
+ dma_num++;
+ }
+
+ /*
+ * if dma_num <= (1 / 1.15) * user's block_num, we think the pool
+ * is created with failure.
+ */
+ if (dma_num <= NUM_TIMES(p->setup.block_num)) {
+ WD_ERR("dma_num = %u, not enough.\n", dma_num);
+ goto init_blk_error;
+ }
+
+ p->free_blk_num = dma_num;
+ p->setup.block_num = dma_num;
+
+ return WD_SUCCESS;
+
+init_blk_error:
+ /* Clean up the allocated resources. */
+ for (j = 0; j < i; j++) {
+ /* Release the previously allocated blocks. */
+ fhd = &p->blk_array[j];
+ wd_iova_unmap(cinfo, fhd->blk, fhd->blk_dma, block_size);
+ }
+ free(p->free_bitmap);
+
+bitmap_error:
+ free(p->blk_array);
+
+ return -WD_ENOMEM;
+}
+
+static int usr_pool_init(struct wd_blkpool *p)
+{
+ struct wd_mempool_setup *sp = &p->setup;
+ __u32 blk_size = sp->block_size;
+ struct wd_blk_hd *hd = NULL;
+ __u32 i;
+
+ p->act_start = (void *)ALIGN((uintptr_t)p->usr_mem_start,
+ sp->align_size);
+ for (i = 0; i < sp->block_num; i++) {
+ hd = (void *)((uintptr_t)p->act_start + (p->act_hd_sz + p->act_blk_sz) * i);
+ hd->blk = (void *)((uintptr_t)hd + p->act_hd_sz);
+ hd->blk_dma = sp->ops.iova_map(sp->ops.usr, hd->blk, blk_size);
+ if (!hd->blk_dma) {
+ WD_ERR("failed to map usr blk.\n");
+ return -WD_ENOMEM;
+ }
+ hd->blk_tag = TAG_FREE;
+ }
+
+ p->free_blk_num = sp->block_num;
+
+ return WD_SUCCESS;
+}
+
+static int wd_parse_dev_id(char *dev_name)
+{
+ char *last_dash = NULL;
+ char *endptr;
+ int dev_id;
+
+ if (!dev_name)
+ return -WD_EINVAL;
+
+ /* Find the last '-' in the string. */
+ last_dash = strrchr(dev_name, '-');
+ if (!last_dash || *(last_dash + 1) == '\0')
+ return -WD_EINVAL;
+
+ /* Parse the following number */
+ dev_id = strtol(last_dash + 1, &endptr, DECIMAL_NUMBER);
+ /* Check whether it is truly all digits */
+ if (*endptr != '\0' || dev_id < 0)
+ return -WD_EINVAL;
+
+ return dev_id;
+}
+
+static int wd_mempool_init(handle_t h_ctx, struct wd_blkpool *pool,
+ struct wd_mempool_setup *setup)
+{
+ struct wd_ctx_h *ctx = (struct wd_ctx_h *)h_ctx;
+ struct ctx_info *cinfo = pool->cinfo;
+ void *addr = NULL;
+ int ret;
+
+ /* Use user's memory, and its ops alloc function */
+ if (setup->ops.alloc && setup->ops.free && setup->ops.iova_map) {
+ addr = setup->ops.alloc(setup->ops.usr, pool->act_mem_sz);
+ if (!addr) {
+ WD_ERR("failed to allocate memory in user pool.\n");
+ return -WD_EINVAL;
+ }
+
+ pool->usr_mem_start = addr;
+ if (usr_pool_init(pool)) {
+ WD_ERR("failed to initialize user pool.\n");
+ setup->ops.free(setup->ops.usr, addr);
+ return -WD_EINVAL;
+ }
+ } else {
+ /* Use wd to reserve memory */
+ addr = wd_map_reserve_mem(pool, pool->act_mem_sz);
+ if (!addr) {
+ WD_ERR("wd pool failed to reserve memory.\n");
+ return -WD_ENOMEM;
+ }
+
+ pool->usr_mem_start = addr;
+ if (wd_pool_init(pool)) {
+ WD_ERR("failed to initialize wd pool.\n");
+ goto err_out;
+ }
+ setup->block_num = pool->setup.block_num;
+ }
+
+ ret = wd_parse_dev_id(ctx->dev_path);
+ if (ret < 0) {
+ wd_pool_uninit(pool);
+ goto err_out;
+ }
+ pool->dev_id = ret;
+
+ return WD_SUCCESS;
+
+err_out:
+ if (pool->cinfo) {
+ wd_free_slice(cinfo);
+ wd_unmap_reserve_mem(cinfo->ss_va, cinfo->ss_mm_size);
+ pool->cinfo = NULL;
+ }
+ return -WD_EINVAL;
+}
+
+void *wd_mempool_alloc(handle_t h_ctx, struct wd_mempool_setup *setup)
+{
+ struct wd_blkpool *pool = NULL;
+ int ret;
+
+ if (!setup || !h_ctx) {
+ WD_ERR("Input param is NULL!\n");
+ return NULL;
+ }
+
+ ret = wd_is_sva(h_ctx);
+ if (ret < 0) {
+ WD_ERR("failed to check device ctx!\n");
+ return NULL;
+ } else if (ret == UACCE_DEV_SVA) {
+ WD_ERR("the device is SVA mode!\n");
+ return NULL;
+ }
+
+ pool = calloc(1, sizeof(*pool));
+ if (!pool) {
+ WD_ERR("failed to malloc pool.\n");
+ return NULL;
+ }
+ ret = pthread_spin_init(&pool->pool_lock, PTHREAD_PROCESS_PRIVATE);
+ if (ret)
+ goto err_pool_alloc;
+
+ memcpy(&pool->setup, setup, sizeof(pool->setup));
+
+ ret = wd_pool_pre_layout(h_ctx, pool, setup);
+ if (ret)
+ goto err_pool_layout;
+
+ ret = wd_mempool_init(h_ctx, pool, setup);
+ if (ret)
+ goto err_pool_init;
+
+ return pool;
+
+err_pool_init:
+ if (pool->cinfo) {
+ free(pool->cinfo);
+ pool->cinfo = NULL;
+ }
+err_pool_layout:
+ pthread_spin_destroy(&pool->pool_lock);
+err_pool_alloc:
+ free(pool);
+
+ return NULL;
+}
+
+void wd_mempool_free(handle_t h_ctx, void *pool)
+{
+ struct wd_mempool_setup *setup;
+ struct wd_blkpool *p = pool;
+
+ if (!p || !h_ctx) {
+ WD_ERR("pool destroy err, pool or ctx is NULL.\n");
+ return;
+ }
+
+ setup = &p->setup;
+ if (p->free_blk_num != setup->block_num) {
+ WD_ERR("Can not destroy blk pool, as it's in use.\n");
+ return;
+ }
+
+ if (setup->ops.free)
+ setup->ops.free(setup->ops.usr, p->usr_mem_start);
+
+ if (p->cinfo) {
+ /* Free block array memory */
+ if (p->blk_array)
+ free(p->blk_array);
+
+ if (p->free_bitmap)
+ free(p->free_bitmap);
+
+ wd_free_slice(p->cinfo);
+ wd_unmap_reserve_mem(p->cinfo->ss_va, p->cinfo->ss_mm_size);
+ free(p->cinfo);
+ p->cinfo = NULL;
+ }
+
+ pthread_spin_destroy(&p->pool_lock);
+ free(p);
+}
+
+void wd_mem_free(void *pool, void *buf)
+{
+ struct wd_blkpool *p = pool;
+ struct wd_blk_hd *current_hd;
+ struct wd_blk_hd *hd;
+ unsigned int current_idx;
+ unsigned int blk_idx;
+ unsigned long offset;
+ unsigned int i, num;
+ unsigned long sz;
+
+ if (unlikely(!p || !buf)) {
+ WD_ERR("free blk parameters err!\n");
+ return;
+ }
+
+ sz = p->act_hd_sz + p->act_blk_sz;
+ if (!sz) {
+ WD_ERR("memory pool blk size is zero!\n");
+ return;
+ }
+
+ if ((uintptr_t)buf < (uintptr_t)p->act_start) {
+ WD_ERR("free block addr is error.\n");
+ return;
+ }
+
+ /* Calculate the block index. */
+ offset = (unsigned long)((uintptr_t)buf - (uintptr_t)p->act_start);
+ blk_idx = offset / sz;
+
+ /* Check if the index is valid. */
+ if (blk_idx >= p->total_blocks) {
+ WD_ERR("Invalid block index<%u>.\n", blk_idx);
+ return;
+ }
+
+ /* Get the block header. */
+ hd = &p->blk_array[blk_idx];
+ num = hd->blk_num;
+
+ pthread_spin_lock(&p->pool_lock);
+ /* Release all related blocks. */
+ for (i = 0; i < num; i++) {
+ // Recalculate the index (since it is contiguous).
+ current_idx = blk_idx + i;
+ current_hd = &p->blk_array[current_idx];
+ current_hd->blk_tag = TAG_FREE;
+ current_hd->blk_num = 0;
+ bitmap_clear_bit(p->free_bitmap, current_idx);
+ }
+ p->free_blk_num += num;
+ pthread_spin_unlock(&p->pool_lock);
+}
+
+static int wd_find_contiguous_blocks(struct wd_blkpool *p,
+ unsigned int required_blocks,
+ unsigned int *start_block)
+{
+#define MAX_SKIP_ATTEMPTS 10
+ unsigned int consecutive_count = 0;
+ unsigned int skip_attempts = 0;
+ struct wd_blk_hd *hd, *tl;
+ unsigned int i;
+
+ if (required_blocks == 0 || required_blocks > p->total_blocks)
+ return -WD_EINVAL;
+
+ for (i = 0; i < p->total_blocks; i++) {
+ if (!bitmap_test_bit(p->free_bitmap, i)) {
+ consecutive_count = 0;
+ continue;
+ }
+
+ if (consecutive_count == 0)
+ *start_block = i;
+ consecutive_count++;
+
+ if (consecutive_count < required_blocks)
+ continue;
+
+ /* Check DMA contiguity only if more than one block is needed */
+ if (required_blocks > 1) {
+ hd = &p->blk_array[*start_block];
+ tl = &p->blk_array[*start_block + required_blocks - 1];
+
+ if (((uintptr_t)tl->blk_dma - (uintptr_t)hd->blk_dma) !=
+ ((uintptr_t)tl->blk - (uintptr_t)hd->blk)) {
+ /* Not contiguous, skip this start and try again */
+ if (++skip_attempts > MAX_SKIP_ATTEMPTS)
+ return -WD_ENOMEM;
+
+ i = *start_block; // will be incremented by loop
+ consecutive_count = 0;
+ continue;
+ }
+ }
+
+ /* Found and DMA is contiguous */
+ return WD_SUCCESS;
+ }
+
+ return -WD_ENOMEM;
+}
+
+void *wd_mem_alloc(void *pool, size_t size)
+{
+ unsigned int required_blocks;
+ unsigned int start_block = 0;
+ struct wd_blk_hd *hd = NULL;
+ struct wd_blkpool *p = pool;
+ unsigned int j;
+ int ret;
+
+ if (unlikely(!p || !size)) {
+ WD_ERR("blk alloc pool is null!\n");
+ return NULL;
+ }
+
+ if (!p->act_blk_sz) {
+ WD_ERR("blk pool is error!\n");
+ return NULL;
+ }
+
+ /* Calculate the number of blocks required. */
+ required_blocks = (size + p->act_blk_sz - 1) / p->act_blk_sz;
+ if (required_blocks > p->free_blk_num) {
+ p->alloc_failures++;
+ WD_ERR("Not enough free blocks.\n");
+ return NULL;
+ }
+
+ pthread_spin_lock(&p->pool_lock);
+ /* Find contiguous free blocks. */
+ ret = wd_find_contiguous_blocks(p, required_blocks, &start_block);
+ if (ret != 0) {
+ p->alloc_failures++;
+ pthread_spin_unlock(&p->pool_lock);
+ WD_ERR("Failed to find contiguous blocks.\n");
+ return NULL;
+ }
+
+ /* Mark all required blocks as used */
+ for (j = start_block; j < start_block + required_blocks; j++) {
+ p->blk_array[j].blk_tag = TAG_USED;
+ bitmap_set_bit(p->free_bitmap, j);
+ }
+
+ p->free_blk_num -= required_blocks;
+ hd = &p->blk_array[start_block];
+ hd->blk_num = required_blocks;
+ pthread_spin_unlock(&p->pool_lock);
+
+ return hd->blk;
+}
+
+void *wd_mem_map(void *pool, void *buf, size_t sz)
+{
+ struct wd_blkpool *p = pool;
+ struct wd_blk_hd *hd;
+ unsigned long offset;
+ unsigned long blk_sz;
+ unsigned long blk_idx;
+
+ if (unlikely(!pool || !buf)) {
+ WD_ERR("blk map err, pool is NULL!\n");
+ return NULL;
+ }
+
+ if (!sz || (uintptr_t)buf < (uintptr_t)p->act_start) {
+ WD_ERR("map buf addr is error.\n");
+ return NULL;
+ }
+ /* Calculate the block index. */
+ offset = (unsigned long)((uintptr_t)buf - (uintptr_t)p->act_start);
+ blk_sz = p->act_hd_sz + p->act_blk_sz;
+ blk_idx = offset / blk_sz;
+
+ /* Check if the index is valid. */
+ if (blk_idx >= p->total_blocks) {
+ WD_ERR("Invalid block index<%lu> in map.\n", blk_idx);
+ return NULL;
+ }
+
+ hd = &p->blk_array[blk_idx];
+ if (unlikely(hd->blk_tag != TAG_USED ||
+ (uintptr_t)buf < (uintptr_t)hd->blk)) {
+ WD_ERR("dma map fail!\n");
+ return NULL;
+ }
+
+ return (void *)((uintptr_t)hd->blk_dma + ((uintptr_t)buf -
+ (uintptr_t)hd->blk));
+}
+
+void wd_mem_unmap(void *pool, void *buf_dma, void *buf, size_t sz)
+{
+ /* do nothing at no-iommu mode */
+}
+
+int wd_get_free_num(void *pool, __u32 *free_num)
+{
+ struct wd_blkpool *p = pool;
+
+ if (!p || !free_num) {
+ WD_ERR("get_free_blk_num err, parameter err!\n");
+ return -WD_EINVAL;
+ }
+
+ *free_num = __atomic_load_n(&p->free_blk_num, __ATOMIC_RELAXED);
+
+ return WD_SUCCESS;
+}
+
+int wd_get_fail_num(void *pool, __u32 *fail_num)
+{
+ struct wd_blkpool *p = pool;
+
+ if (!p || !fail_num) {
+ WD_ERR("get_blk_alloc_failure err, pool is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ *fail_num = __atomic_load_n(&p->alloc_failures, __ATOMIC_RELAXED);
+
+ return WD_SUCCESS;
+}
+
+__u32 wd_get_bufsize(void *pool)
+{
+ struct wd_blkpool *p = pool;
+
+ if (!p) {
+ WD_ERR("get dev id is null!\n");
+ return 0;
+ }
+
+ return p->act_blk_sz;
+}
+
+__u32 wd_get_dev_id(void *pool)
+{
+ struct wd_blkpool *p = pool;
+
+ if (!p) {
+ WD_ERR("failed to get dev id!\n");
+ return 0;
+ }
+
+ return p->dev_id;
+}
+
diff --git a/wd_util.c b/wd_util.c
index e8a2934..d0d83eb 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -13,6 +13,8 @@
#include <ctype.h>
#include "wd_sched.h"
#include "wd_util.h"
+#include "wd_alg.h"
+#include "wd_bmm.h"
#define WD_ASYNC_DEF_POLL_NUM 1
#define WD_ASYNC_DEF_QUEUE_DEPTH 1024
@@ -100,11 +102,6 @@ struct acc_alg_item {
const char *algtype;
};
-struct wd_ce_ctx {
- char *drv_name;
- void *priv;
-};
-
static struct acc_alg_item alg_options[] = {
{"zlib", "zlib"},
{"gzip", "gzip"},
@@ -172,6 +169,93 @@ static struct acc_alg_item alg_options[] = {
{"", ""}
};
+static void *wd_internal_alloc(void *usr, size_t size)
+{
+ if (size != 0)
+ return malloc(size);
+ else
+ return NULL;
+}
+
+static void wd_internal_free(void *usr, void *va)
+{
+ if (va != NULL)
+ free(va);
+}
+
+static __u32 wd_mem_bufsize(void *usr)
+{
+ /* Malloc memory min size is 1 Byte */
+ return 1;
+}
+
+int wd_mem_ops_init(handle_t h_ctx, struct wd_mm_ops *mm_ops, int mem_type)
+{
+ int ret;
+
+ ret = wd_is_sva(h_ctx);
+ if (ret == UACCE_DEV_SVA || ret == -WD_HW_EACCESS) {
+ /*
+ * In software queue scenario, all memory is handled as virtual memory
+ * and processed in the same way as SVA mode
+ */
+ mm_ops->sva_mode = true;
+ } else if (!ret) {
+ mm_ops->sva_mode = false;
+ } else {
+ WD_ERR("failed to check ctx!\n");
+ return ret;
+ }
+
+ /*
+ * Under SVA mode, there is no need to consider the memory type;
+ * directly proceed with virtual memory handling
+ */
+ if (mm_ops->sva_mode) {
+ mm_ops->alloc = (void *)wd_internal_alloc;
+ mm_ops->free = (void *)wd_internal_free;
+ mm_ops->iova_map = NULL;
+ mm_ops->iova_unmap = NULL;
+ mm_ops->get_bufsize = (void *)wd_mem_bufsize;
+ mm_ops->usr = NULL;
+ return 0;
+ }
+
+ switch (mem_type) {
+ case UADK_MEM_AUTO:
+ /*
+ * The memory pool needs to be allocated according to
+ * the block size when it is first executed in the UADK
+ */
+ mm_ops->usr = NULL;
+ WD_ERR("automatic under No-SVA mode is not supported!\n");
+ return -WD_EINVAL;
+ case UADK_MEM_USER:
+ if (!mm_ops->alloc || !mm_ops->free || !mm_ops->iova_map ||
+ !mm_ops->iova_unmap || !mm_ops->usr) { // The user create a memory pool
+ WD_ERR("failed to check memory ops, some ops function is NULL!\n");
+ return -WD_EINVAL;
+ }
+ break;
+ case UADK_MEM_PROXY:
+ if (!mm_ops->usr) {
+ WD_ERR("failed to check memory pool!\n");
+ return -WD_EINVAL;
+ }
+ mm_ops->alloc = (void *)wd_mem_alloc;
+ mm_ops->free = (void *)wd_mem_free;
+ mm_ops->iova_map = (void *)wd_mem_map;
+ mm_ops->iova_unmap = (void *)wd_mem_unmap;
+ mm_ops->get_bufsize = (void *)wd_get_bufsize;
+ break;
+ default:
+ WD_ERR("failed to check memory type!\n");
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
static void clone_ctx_to_internal(struct wd_ctx *ctx,
struct wd_ctx_internal *ctx_in)
{
@@ -257,6 +341,12 @@ int wd_init_ctx_config(struct wd_ctx_config_internal *in,
WD_ERR("failed to init ctxs lock!\n");
goto err_out;
}
+
+ ret = wd_insert_ctx_list(cfg->ctxs[i].ctx, in->alg_name);
+ if (ret) {
+ WD_ERR("failed to add ctx to mem list!\n");
+ goto err_out;
+ }
}
in->ctxs = ctxs;
@@ -318,6 +408,7 @@ void wd_clear_ctx_config(struct wd_ctx_config_internal *in)
in->ctxs = NULL;
}
+ wd_remove_ctx_list();
wd_shm_delete(in);
}
@@ -2485,7 +2576,7 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l
/* If the ctx set number is 0, the initialization is skipped. */
if (!ctx_set_num)
- return 0;
+ return -WD_ENOPROC;
dev = wd_find_dev_by_numa(list, numa_id);
if (WD_IS_ERR(dev))
@@ -2573,7 +2664,9 @@ static int wd_init_ctx_and_sched(struct wd_init_attrs *attrs, struct bitmask *bm
for (j = 0; j < op_type_num; j++) {
ctx_nums = ctx_params->ctx_set_num[j];
ret = wd_init_ctx_set(attrs, list, idx, i, j);
- if (ret)
+ if (ret == -WD_ENOPROC)
+ continue;
+ else if (ret)
goto free_ctxs;
ret = wd_instance_sched_set(attrs->sched, ctx_nums, idx, i, j);
if (ret)
--
2.33.0
1
29
您好!
sig-AccLib 邀请您参加 2025-11-12 11:00 召开的Zoom会议
会议主题:【2025/11/12 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/83926110482?pwd=aEbqlYoZb2CHsaTYMRJs0YzjeUf7TY.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-11-12 11:00,
The subject of the conference is 【2025/11/12 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/83926110482?pwd=aEbqlYoZb2CHsaTYMRJs0YzjeUf7TY.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
您好!
sig-AccLib 邀请您参加 2025-10-29 11:00 召开的Zoom会议
会议主题:2025/10/29 AccLIb SIG 双周例会 11:00 - 12:00
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/81029452568?pwd=gFECql6wHjvNVBSmZO2bUBF7JiKvAX.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-10-29 11:00,
The subject of the conference is 2025/10/29 AccLIb SIG 双周例会 11:00 - 12:00
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/81029452568?pwd=gFECql6wHjvNVBSmZO2bUBF7JiKvAX.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
您好!
sig-AccLib 邀请您参加 2025-10-15 11:00 召开的Zoom会议
会议主题:【2025/10/15 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接: linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/83929445214?pwd=16oKu20KnPBdVaw4nLVb30eX4o93EB.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-10-15 11:00,
The subject of the conference is 【2025/10/15 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接: linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/83929445214?pwd=16oKu20KnPBdVaw4nLVb30eX4o93EB.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
27 Sep '25
Convert signed to unsigned in uadk drv bitwise operations
Signed-off-by: ZongYu Wu <wuzongyu1(a)huawei.com>
---
drv/hisi_comp_huf.c | 11 ++++++-----
v1/drv/hisi_zip_huf.c | 10 ++++++----
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/drv/hisi_comp_huf.c b/drv/hisi_comp_huf.c
index 3684a18..161fee4 100644
--- a/drv/hisi_comp_huf.c
+++ b/drv/hisi_comp_huf.c
@@ -76,7 +76,7 @@ static long read_bits(struct bit_reader *br, __u32 n)
if (br->cur_pos + n > br->total_bits)
return -WD_EINVAL;
- ret = (br->data >> br->cur_pos) & ((1L << n) - 1L);
+ ret = (br->data >> br->cur_pos) & ((1UL << n) - 1UL);
br->cur_pos += n;
return ret;
@@ -85,7 +85,7 @@ static long read_bits(struct bit_reader *br, __u32 n)
static int check_store_huffman_block(struct bit_reader *br)
{
__u32 pad, bit_len;
- long data;
+ unsigned long data;
bit_len = br->total_bits - br->cur_pos;
@@ -111,8 +111,8 @@ static int check_store_huffman_block(struct bit_reader *br)
static int check_fix_huffman_block(struct bit_reader *br)
{
- long bit, len_idx, dist_code, extra;
- long code, bits;
+ long bits, bit, len_idx, dist_code, extra;
+ unsigned long code, ubit;
while (br->cur_pos < br->total_bits) {
/* reads 7~9 bits to determine literal/length */
@@ -123,7 +123,8 @@ static int check_fix_huffman_block(struct bit_reader *br)
if (bit < 0)
return BLOCK_IS_INCOMPLETE;
- code = (code << 1) | bit;
+ ubit = bit;
+ code = (code << 1) | ubit;
bits++;
/*
diff --git a/v1/drv/hisi_zip_huf.c b/v1/drv/hisi_zip_huf.c
index 086fa9f..61f7ab7 100644
--- a/v1/drv/hisi_zip_huf.c
+++ b/v1/drv/hisi_zip_huf.c
@@ -76,7 +76,7 @@ static long read_bits(struct bit_reader *br, __u32 n)
if (br->cur_pos + n > br->total_bits)
return -WD_EINVAL;
- ret = (br->data >> br->cur_pos) & ((1L << n) - 1L);
+ ret = (br->data >> br->cur_pos) & ((1UL << n) - 1UL);
br->cur_pos += n;
return ret;
@@ -85,7 +85,7 @@ static long read_bits(struct bit_reader *br, __u32 n)
static int check_store_huffman_block(struct bit_reader *br)
{
__u32 pad, bits;
- long data;
+ unsigned long data;
bits = br->total_bits - br->cur_pos;
@@ -111,7 +111,8 @@ static int check_store_huffman_block(struct bit_reader *br)
static int check_fix_huffman_block(struct bit_reader *br)
{
- long bit, len_idx, dist_code, extra, code;
+ long bit, len_idx, dist_code, extra;
+ unsigned long code, ubit;
__u32 bits;
while (br->cur_pos < br->total_bits) {
@@ -123,7 +124,8 @@ static int check_fix_huffman_block(struct bit_reader *br)
if (bit < 0)
return HF_BLOCK_IS_INCOMPLETE;
- code = (code << 1) | bit;
+ ubit = bit;
+ code = (code << 1) | ubit;
bits++;
/*
--
2.33.0
1
2
[PATCH] uadk: fix the issue of excessive memory allocation in reserved memory
by ZongYu Wu 19 Sep '25
by ZongYu Wu 19 Sep '25
19 Sep '25
From: Chenghai Huang <huangchenghai2(a)huawei.com>
It just need to align with 1M, but here currently, memory of a size that
is a multiple of 1M has been requested.
Signed-off-by: Chenghai Huang <huangchenghai2(a)huawei.com>
---
v1/wd_bmm.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/v1/wd_bmm.c b/v1/wd_bmm.c
index cdf5f0b..c58484f 100644
--- a/v1/wd_bmm.c
+++ b/v1/wd_bmm.c
@@ -116,12 +116,13 @@ static int wd_pool_pre_layout(struct wd_queue *q,
p->act_mem_sz = (p->act_hd_sz + p->act_blk_sz) *
(unsigned long)sp->block_num + asz;
- /* When we use WD reserve memory and the blk_sz is larger than 1M,
+ /*
+ * When we use WD reserve memory and the blk_sz is larger than 1M,
* in order to ensure the mem_pool to be success,
- * we should to reserve more memory
+ * ensure that the allocated memory is an integer multiple of 1M.
*/
if (!sp->br.alloc && !qinfo->iommu_type)
- p->act_mem_sz *= (1 + p->act_blk_sz / BLK_BALANCE_SZ);
+ p->act_mem_sz = (p->act_mem_sz + BLK_BALANCE_SZ - 1) & ~(BLK_BALANCE_SZ - 1);
return WD_SUCCESS;
}
--
2.33.0
1
2
12 Sep '25
From: Wenkai Lin <linwenkai6(a)hisilicon.com>
There is an issue with the counter in the sec prefetch state machine,
when the length exceeding a certain number of pages may cause chaos,
and errors may carry over to the next operation. Now, when the packet
length exceeds 24KB(the hardware limit value), the prefetch is disabled.
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
---
drv/hisi_sec.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 747d3a8..1e95ce5 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -48,6 +48,7 @@
#define SEC_SM4_XTS_GB_V3 0x1
#define SEC_AUTH_ALG_OFFSET_V3 15
#define SEC_SVA_PREFETCH_OFFSET 27
+#define SEC_SVA_PREFETCH_MAX_LEN 0x6000
#define SEC_ENABLE_SVA_PREFETCH 0x1
#define SEC_CIPHER_AUTH_V3 0xbf
#define SEC_AUTH_CIPHER_V3 0x40
@@ -1357,14 +1358,20 @@ static int fill_cipher_bd3(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe)
return ret;
}
- sqe->auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET;
-
return 0;
}
+static void fill_sec_prefetch(__u8 data_fmt, __u32 len, __u16 hw_type, struct hisi_sec_sqe3 *sqe)
+{
+ if (hw_type >= HISI_QM_API_VER5_BASE ||
+ (data_fmt == WD_FLAT_BUF && len <= SEC_SVA_PREFETCH_MAX_LEN))
+ sqe->auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET;
+}
+
static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
struct wd_cipher_msg *msg = wd_msg;
struct hisi_sec_sqe3 sqe;
__u16 count = 0;
@@ -1380,6 +1387,8 @@ static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void
if (ret)
return ret;
+ fill_sec_prefetch(msg->data_fmt, msg->in_bytes, qp->q_info.hw_type, &sqe);
+
if (msg->data_fmt == WD_SGL_BUF) {
ret = hisi_sec_fill_sgl_v3(h_qp, &msg->in, &msg->out, &sqe,
msg->alg_type);
@@ -1950,6 +1959,7 @@ static void fill_digest_v3_scene(struct hisi_sec_sqe3 *sqe,
static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
struct wd_digest_msg *msg = wd_msg;
struct hisi_sec_sqe3 sqe;
__u16 count = 0;
@@ -1990,7 +2000,8 @@ static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void
hisi_set_msg_id(h_qp, &msg->tag);
sqe.tag = (__u64)(uintptr_t)msg->tag;
- sqe.auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET;
+
+ fill_sec_prefetch(msg->data_fmt, msg->in_bytes, qp->q_info.hw_type, &sqe);
ret = hisi_qm_send(h_qp, &sqe, 1, &count);
if (ret < 0) {
@@ -2912,7 +2923,6 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe)
sqe->c_len_ivin = msg->in_bytes;
sqe->cipher_src_offset = msg->assoc_bytes;
sqe->a_len_key = msg->in_bytes + msg->assoc_bytes;
- sqe->auth_mac_key |= (__u32)SEC_ENABLE_SVA_PREFETCH << SEC_SVA_PREFETCH_OFFSET;
ret = fill_aead_bd3_alg(msg, sqe);
if (ret) {
@@ -2932,6 +2942,7 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe)
static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
struct wd_aead_msg *msg = wd_msg;
struct hisi_sec_sqe3 sqe;
__u16 count = 0;
@@ -2955,6 +2966,9 @@ static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *
if (unlikely(ret))
return ret;
+ fill_sec_prefetch(msg->data_fmt, msg->in_bytes + msg->assoc_bytes,
+ qp->q_info.hw_type, &sqe);
+
if (msg->data_fmt == WD_SGL_BUF) {
ret = hisi_sec_fill_sgl_v3(h_qp, &msg->in, &msg->out, &sqe,
msg->alg_type);
--
2.33.0
1
0
您好!
sig-AccLib 邀请您参加 2025-09-03 11:00 召开的Zoom会议
会议主题:【2025/9/3 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接 linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/86320332510?pwd=naSQBzymGAEm87frSKnpAVAMyPl59N.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-09-03 11:00,
The subject of the conference is 【2025/9/3 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接 linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/86320332510?pwd=naSQBzymGAEm87frSKnpAVAMyPl59N.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
Remove nosva limitation to permit nosva run
Signed-off-by: Zhangfei Gao <zhangfei.gao(a)linaro.org>
---
wd.c | 4 ----
wd_alg.c | 44 +-------------------------------------------
wd_util.c | 4 ----
3 files changed, 1 insertion(+), 51 deletions(-)
diff --git a/wd.c b/wd.c
index 75a9469..5fa8feb 100644
--- a/wd.c
+++ b/wd.c
@@ -235,10 +235,6 @@ static int get_dev_info(struct uacce_dev *dev)
ret = get_int_attr(dev, "flags", &dev->flags);
if (ret < 0)
return ret;
- else if (!((unsigned int)dev->flags & UACCE_DEV_SVA)) {
- WD_ERR("skip none sva uacce device!\n");
- return -WD_ENODEV;
- }
ret = get_int_attr(dev, "region_mmio_size", &value);
if (ret < 0)
diff --git a/wd_alg.c b/wd_alg.c
index 08f0e2e..45619ba 100644
--- a/wd_alg.c
+++ b/wd_alg.c
@@ -23,47 +23,6 @@ static struct wd_alg_list alg_list_head;
static struct wd_alg_list *alg_list_tail = &alg_list_head;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-
-static bool wd_check_dev_sva(const char *dev_name)
-{
- char dev_path[PATH_MAX] = {'\0'};
- char buf[DEV_SVA_SIZE] = {'\0'};
- unsigned int val;
- ssize_t ret;
- int fd;
-
- ret = snprintf(dev_path, PATH_STR_SIZE, "%s/%s/%s", SYS_CLASS_DIR,
- dev_name, SVA_FILE_NAME);
- if (ret < 0) {
- WD_ERR("failed to snprintf, device name: %s!\n", dev_name);
- return false;
- }
-
- /**
- * The opened file is the specified device driver file.
- * no need for realpath processing.
- */
- fd = open(dev_path, O_RDONLY, 0);
- if (fd < 0) {
- WD_ERR("failed to open %s(%d)!\n", dev_path, -errno);
- return false;
- }
-
- ret = read(fd, buf, DEV_SVA_SIZE - 1);
- if (ret <= 0) {
- WD_ERR("failed to read anything at %s!\n", dev_path);
- close(fd);
- return false;
- }
- close(fd);
-
- val = strtol(buf, NULL, STR_DECIMAL);
- if (val & UACCE_DEV_SVA)
- return true;
-
- return false;
-}
-
static bool wd_check_accel_dev(const char *dev_name)
{
struct dirent *dev_dir;
@@ -80,8 +39,7 @@ static bool wd_check_accel_dev(const char *dev_name)
!strncmp(dev_dir->d_name, "..", LINUX_PRTDIR_SIZE))
continue;
- if (!strncmp(dev_dir->d_name, dev_name, strlen(dev_name)) &&
- wd_check_dev_sva(dev_dir->d_name)) {
+ if (!strncmp(dev_dir->d_name, dev_name, strlen(dev_name))) {
closedir(wd_class);
return true;
}
diff --git a/wd_util.c b/wd_util.c
index f1b27bf..9675098 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1883,10 +1883,6 @@ int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched)
return -WD_EINVAL;
}
- if (!wd_is_sva(config->ctxs[0].ctx)) {
- WD_ERR("invalid: the mode is non sva, please check system!\n");
- return -WD_EINVAL;
- }
return 0;
}
--
2.25.1
2
10
21 Aug '25
From: lizhi <lizhi206(a)huawei.com>
On some Ubuntu systems, the gcc compiler disables the DATE and TIME
macros via the -Wdate-time flag during compilation.
To ensure the compilation timestamp feature remains functional,
this issue is addressed through the Makefile.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
---
uadk_tool/Makefile.am | 6 ++++++
uadk_tool/dfx/uadk_dfx.c | 6 +++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am
index 6fd9d95..9ae9fd7 100644
--- a/uadk_tool/Makefile.am
+++ b/uadk_tool/Makefile.am
@@ -1,10 +1,16 @@
ACLOCAL_AMFLAGS = -I m4 -I./include
AUTOMAKE_OPTIONS = foreign subdir-objects
+
+# get UADK build time
+BUILD_DATETIME := $(shell date -u +"%Y-%m-%d_%H:%M:%S")
+
AM_CFLAGS=-Wall -Werror -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/benchmark/include \
-pthread
AM_CFLAGS += -fPIC -fPIE -pie -fstack-protector-strong -D_FORTIFY_SOURCE=2 \
-O2 -ftrapv -Wl,-z,now -Wl,-s
+AM_CFLAGS += -DUADK_BUILD_DATETIME=\"$(BUILD_DATETIME)\"
+
#AUTOMAKE_OPTIONS = subdir-objects
bin_PROGRAMS=uadk_tool
diff --git a/uadk_tool/dfx/uadk_dfx.c b/uadk_tool/dfx/uadk_dfx.c
index 9c54b7b..8afcb15 100644
--- a/uadk_tool/dfx/uadk_dfx.c
+++ b/uadk_tool/dfx/uadk_dfx.c
@@ -14,7 +14,11 @@
#include "include/wd.h"
#include "uadk_dfx.h"
-#define uadk_build_date() printf("built on: %s %s\n", __DATE__, __TIME__)
+#ifndef UADK_BUILD_DATETIME
+#define UADK_BUILD_DATETIME "unknown"
+#endif
+
+#define uadk_build_date() printf("built on: %s\n", UADK_BUILD_DATETIME)
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define PRIVILEGE_FLAG 0666
--
2.33.0
1
0
19 Aug '25
From: Longfang Liu <liulongfang(a)huawei.com>
After removing the shared queue memory allocation interface, the UADK
test tools must also eliminate the shared memory functionality.
For individual memory reservations, the wd_reserve_memory interface
should be used. When allocating memory for multiple queues, each queue
should independently request its own reserved memory allocation.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
---
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 -----------------------
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 +++++++++---------
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +++++++-------
4 files changed, 300 insertions(+), 657 deletions(-)
diff --git a/v1/test/hisi_hpre_test/hpre_test_tools.c b/v1/test/hisi_hpre_test/hpre_test_tools.c
index 7f562f34..10a4ade9 100755
--- a/v1/test/hisi_hpre_test/hpre_test_tools.c
+++ b/v1/test/hisi_hpre_test/hpre_test_tools.c
@@ -644,317 +644,6 @@ int application_release_multiple_queue(char *dev, char *alg_type, unsigned int q
printf("application_release_multiple_queue test end!\n");
return 0;
}
-
-/***
-
-***/
-int hpre_dev_queue_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_node_queue_share(char *dev, unsigned int node, unsigned int share_node, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
- q.node_mask = node;
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- target_q.node_mask = node;
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on target q fail!\n");
- return 1;
- }
-
- ret = wd_share_reserved_memory(&q, &target_q);
-
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on share q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on share target q fail!\n");
- return 1;
- }
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_dev_queue_interact_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return ret;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- addr = wd_reserve_memory(&target_q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- //target_q
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
-/***
-
-***/
-int hpre_dev_queue_cross_proc_share(char *dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- pid_t pid;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size=0;
-
- pid = fork();
- if(pid < 0)
- {
- printf("Creation process failed, pid:%d\n",pid);
- return 1;
- }
- else if(pid == 0)
- {
- printf("child process:%d\n", pid);
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("request queue fail!\n");
- exit(1);
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("queue reserve memory fail!\n");
- exit(2);
- }
- printf("queue reserve memory success!\n");
- memset(addr, 0, memory_size);
- exit(0);
- }
- printf("parent process:%d\n", pid);
- pid_t wpid;
- int status = -1;
- wpid = waitpid(pid, &status, WUNTRACED | WCONTINUED);
- if( wpid < 0)
- {
- printf("exited, status=%d\n", WEXITSTATUS(status));
- return(status);
- }
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&target_q);
- wd_release_queue(&q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
/***
***/
@@ -1696,87 +1385,6 @@ int main(int arc, char *argv[])
return 1;
}
}
- else if(!strcmp(argv[1], "queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "node-queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示设备node
- argv[5] - 表示共享内存设备node
- argv[6] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- unsigned int node=0;
- node = strtoul(argv[4], NULL, 16);
- unsigned int share_node=0;
- share_node = strtoul(argv[5], NULL, 16);
- memory_size = strtoul(argv[6], NULL, 10);
-
- ret = hpre_node_queue_share(dev, node, share_node, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-interact-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //队列预留内存后作为共享的目标队列
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_interact_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-cross-proc-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示申请队列的预留内存大小
- ***/
- //跨进程进行队列共享
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- memory_size = strtoul(argv[4], NULL, 10);
- ret = hpre_dev_queue_cross_proc_share(dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
else if(!strcmp(argv[1], "mult-thread-queue"))
{
/***
diff --git a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
index 31637565..7a3be22c 100644
--- a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
+++ b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
@@ -23,96 +23,33 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
- } else { /* use sgl */
- sched->msgs[i].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
- sched->msgs[i].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i, data_fmt);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- } else { /* use sgl */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_sgl(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_sgl(pool, sched->msgs[i].data_out);
- }
- wd_sglpool_destroy(pool);
- }
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
@@ -124,14 +61,6 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
struct wd_sglpool_setup sp;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -145,12 +74,22 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
+ return 0;
+ }
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
+ goto out_with_queues;
+ }
+
+ qinfo = sched->qs[i].qinfo;
pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -162,15 +101,18 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
qinfo->br.iova_map = (void *)wd_blk_iova_map;
qinfo->br.iova_unmap = (void *)wd_blk_iova_unmap;
qinfo->br.usr = pool;
- } else { /* use sgl*/
- memset(&sp, 0, sizeof(sp));
- sp.buf_size = sched->msg_data_size / 10;
- sp.align_size = 64;
- sp.sge_num_in_sgl = 60;
- sp.buf_num_in_sgl = sp.sge_num_in_sgl;
- sp.sgl_num = 3 * sched->msg_cache_num;
- sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
-
+ }
+ } else { /* use sgl*/
+ memset(&sp, 0, sizeof(sp));
+ sp.buf_size = sched->msg_data_size / 10;
+ sp.align_size = 64;
+ sp.sge_num_in_sgl = 60;
+ sp.buf_num_in_sgl = sp.sge_num_in_sgl;
+ sp.sgl_num = 3 * sched->msg_cache_num;
+ sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
pool = wd_sglpool_create(&sched->qs[0], &sp);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -189,17 +131,132 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
+
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ } else { /* use sgl */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_sgl(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_sgl(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
+
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
+ qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
+ flags = qinfo->dev_flags;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ } else { /* use sgl */
+ sched->msgs[j].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
+ sched->msgs[j].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ }
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j, data_fmt);
+ }
+ }
+
+ return 0;
+
+err_with_stat:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched, data_fmt);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
{
@@ -211,57 +268,22 @@ int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
if (ret < 0)
return -EINVAL;
- qinfo = sched->qs[0].qinfo;
- flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
- }
- }
- }
-
sched->cl = sched->msg_cache_num;
ret = __init_cache(sched, data_fmt);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched, data_fmt);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched, data_fmt);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched, data_fmt);
}
static int __sync_send(struct wd_scheduler *sched)
@@ -350,4 +372,4 @@ int wd_sched_work(struct wd_scheduler *sched, int remained)
}
return sched->cl;
-}
\ No newline at end of file
+}
diff --git a/v1/test/test_mm/test_wd_mem.c b/v1/test/test_mm/test_wd_mem.c
index 09824b99..e2eec60e 100644
--- a/v1/test/test_mm/test_wd_mem.c
+++ b/v1/test/test_mm/test_wd_mem.c
@@ -208,10 +208,10 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo1.q, &rsa_q);
+ ret = wd_request_queue(&pdata->qinfo1.q);
if (ret) {
wd_release_queue(&rsa_q);
- MMT_PRT("Proc-%d, thrd-%d:share mem on rsa queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:rsa queue fail!\n",
pid, thread_id);
return NULL;
}
@@ -226,9 +226,9 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo2.q, &zlib_q);
+ ret = wd_request_queue(&pdata->qinfo2.q);
if (ret) {
- MMT_PRT("Proc-%d, thrd-%d:share mem on zlib queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:zlib queue fail!\n",
pid, thread_id);
goto fail_release;
diff --git a/v1/test/wd_sched.c b/v1/test/wd_sched.c
index f5e46699..ce1d2604 100644
--- a/v1/test/wd_sched.c
+++ b/v1/test/wd_sched.c
@@ -22,94 +22,40 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched)
{
- int ret, i, j;
+ struct wd_blkpool_setup mm_setup;
unsigned int flags = 0;
struct q_info *qinfo;
- struct wd_blkpool_setup mm_setup;
+ int ret, i, j;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -120,18 +66,29 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
sched->ss_region = malloc(sched->ss_region_size);
if (!sched->ss_region) {
WD_ERR("fail to alloc sched ss region mem!\n");
+ return -ENOMEM;
+ }
+ return 0;
+ }
+
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
- pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
+
+ qinfo = sched->qs[i].qinfo;
+ pool = wd_blkpool_create(&sched->qs[i], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
ret = -ENOMEM;
+ wd_release_queue(&sched->qs[i]);
goto out_with_queues;
}
qinfo->br.alloc = (void *)wd_alloc_blk;
@@ -144,79 +101,135 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
-int wd_sched_init(struct wd_scheduler *sched)
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched)
{
- int ret, j, k;
- unsigned int flags;
struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
- ret = wd_sched_preinit(sched);
- if (ret < 0)
- return -EINVAL;
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_alloc;
}
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j);
}
}
- sched->cl = sched->msg_cache_num;
+ return 0;
+
+err_with_alloc:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
+
+int wd_sched_init(struct wd_scheduler *sched)
+{
+ int ret;
+ ret = wd_sched_preinit(sched);
+ if (ret < 0)
+ return -EINVAL;
+
+ sched->cl = sched->msg_cache_num;
ret = __init_cache(sched);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched);
}
static int __sync_send(struct wd_scheduler *sched)
--
2.33.0
1
0
From: Longfang Liu <liulongfang(a)huawei.com>
In the No-SVA mode of UADK, a feature was implemented to reserve
memory allocated for shared queues, which was exposed to external
users through the wd_share_reserved_memory interface.
After this functionality was removed from the kernel-space UACCE,
the corresponding external interface in UADK must also be deleted
to maintain consistency.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
---
v1/uacce.h | 1 -
v1/wd.c | 57 ++----------------------------------------------------
v1/wd.h | 2 --
3 files changed, 2 insertions(+), 58 deletions(-)
diff --git a/v1/uacce.h b/v1/uacce.h
index eef932c7..ffd576c1 100644
--- a/v1/uacce.h
+++ b/v1/uacce.h
@@ -79,7 +79,6 @@ enum uacce_qfrt {
* Optimization method since close fd may delay
*/
#define WD_UACCE_CMD_PUT_Q _IO('W', 1)
-#define WD_UACCE_CMD_SHARE_SVAS _IO('W', 2)
#define WD_UACCE_CMD_GET_SS_DMA _IOR('W', 3, unsigned long)
#endif
diff --git a/v1/wd.c b/v1/wd.c
index 13239b58..bab2712f 100644
--- a/v1/wd.c
+++ b/v1/wd.c
@@ -58,7 +58,6 @@ struct dev_info {
int node_id;
int numa_dis;
int flags;
- int ref;
int available_instances;
int iommu_type;
unsigned int weight;
@@ -531,7 +530,6 @@ static int get_queue_from_dev(struct wd_queue *q, const struct dev_info *dev)
qinfo->iommu_type = dev->iommu_type;
qinfo->dev_info = dev;
qinfo->head = &qinfo->ss_list;
- __atomic_clear(&qinfo->ref, __ATOMIC_RELEASE);
TAILQ_INIT(&qinfo->ss_list);
memcpy(qinfo->qfrs_offset, dev->qfrs_offset,
sizeof(qinfo->qfrs_offset));
@@ -618,23 +616,14 @@ err_with_dev:
void wd_release_queue(struct wd_queue *q)
{
- struct wd_ss_region_list *head;
- struct q_info *qinfo, *sqinfo;
+ struct q_info *qinfo;
if (!q || !q->qinfo) {
WD_ERR("release queue parameter error!\n");
return;
}
- qinfo = q->qinfo;
- if (__atomic_load_n(&qinfo->ref, __ATOMIC_RELAXED)) {
- WD_ERR("q(%s) is busy, release fail!\n", q->capa.alg);
- return;
- }
- head = qinfo->head;
- sqinfo = container_of(head, struct q_info, ss_list);
- if (sqinfo != qinfo) /* q_share */
- __atomic_sub_fetch(&sqinfo->ref, 1, __ATOMIC_RELAXED);
+ qinfo = q->qinfo;
if (ioctl(qinfo->fd, WD_UACCE_CMD_PUT_Q))
WD_ERR("failed to put queue!\n");
@@ -721,48 +710,6 @@ void *wd_reserve_memory(struct wd_queue *q, size_t size)
return drv_reserve_mem(q, size);
}
-int wd_share_reserved_memory(struct wd_queue *q,
- struct wd_queue *target_q)
-{
- const struct dev_info *info, *tgt_info;
- struct q_info *qinfo, *tqinfo;
- int ret;
-
- if (!q || !target_q || !q->qinfo || !target_q->qinfo) {
- WD_ERR("wd share reserved memory: parameter err!\n");
- return -WD_EINVAL;
- }
-
- qinfo = q->qinfo;
- tqinfo = target_q->qinfo;
- tgt_info = tqinfo->dev_info;
- info = qinfo->dev_info;
-
- /* Just share DMA memory from 'q' in NO-IOMMU mode */
- if (qinfo->iommu_type) {
- WD_ERR("IOMMU opened, not support share mem!\n");
- return -WD_EINVAL;
- }
-
- if (qinfo->iommu_type != tqinfo->iommu_type) {
- WD_ERR("IOMMU type mismatching as share mem!\n");
- return -WD_EINVAL;
- }
- if (info->node_id != tgt_info->node_id)
- WD_ERR("Warn: the 2 queues is not at the same node!\n");
-
- ret = ioctl(qinfo->fd, WD_UACCE_CMD_SHARE_SVAS, tqinfo->fd);
- if (ret) {
- WD_ERR("ioctl share dma memory fail!\n");
- return ret;
- }
-
- tqinfo->head = qinfo->head;
- __atomic_add_fetch(&qinfo->ref, 1, __ATOMIC_RELAXED);
-
- return 0;
-}
-
int wd_get_available_dev_num(const char *algorithm)
{
struct wd_queue q;
diff --git a/v1/wd.h b/v1/wd.h
index 79b8a2ad..35dcf31a 100644
--- a/v1/wd.h
+++ b/v1/wd.h
@@ -210,8 +210,6 @@ int wd_recv(struct wd_queue *q, void **resp);
int wd_wait(struct wd_queue *q, __u16 ms);
int wd_recv_sync(struct wd_queue *q, void **resp, __u16 ms);
void *wd_reserve_memory(struct wd_queue *q, size_t size);
-int wd_share_reserved_memory(struct wd_queue *q,
- struct wd_queue *target_q);
int wd_get_available_dev_num(const char *algorithm);
int wd_get_node_id(struct wd_queue *q);
void *wd_iova_map(struct wd_queue *q, void *va, size_t sz);
--
2.33.0
1
0
*** BLURB HERE ***
Chenghai Huang (7):
uadk: fix definition coding standard issues
uadk: add or remove some store buf condition judgments
uadk: add new alg called lz77_only
uadk: remove redundant checks on bit read results
uadk_tool: modify unrecv num in async benchmark test
uadk_tool: add lz77_only alg in zip benchmark test
uadk_tool: add lz4 alg in zip benchmark test
Longfang Liu (3):
uadk: resolve some code issues
uadk: removal of the Shared Memory Interface for Queues
uadk_tools: Removal of the Shared Memory Interface for Queues
Qi Tao (1):
uadk_tool: add aead algorithm
Qinxin Xia (3):
uadk: hisi_comp - abstract get sgl function and general deflate
functions
uadk: hisi_comp - support the new algorithm 'lz4'
uadk: wd_comp - support the new algorithm 'lz4'
Weili Qian (1):
uadk: support data move
Wenkai Lin (2):
uadk: fix for rehash invalid size
uadk: support hashjoin and gather algorithm
Zhushuai Yin (5):
uadk: Add max and min operations at the hash algorithm layer
uadk: hash agg adapter drv parameter
uadk:Add max,min,and rehash implementations
uadk:zip algorithm increases buffer len interception
uadk:fix dh prov segmentation issue
Makefile.am | 31 +-
drv/hisi_comp.c | 580 +++++--
drv/hisi_comp_huf.c | 11 +-
drv/hisi_dae.c | 827 +++-------
drv/hisi_dae.h | 229 +++
drv/hisi_dae_common.c | 387 +++++
drv/hisi_dae_join_gather.c | 1040 ++++++++++++
drv/hisi_qm_udrv.h | 3 +-
drv/hisi_udma.c | 566 +++++++
include/drv/wd_agg_drv.h | 10 +-
include/drv/wd_join_gather_drv.h | 52 +
include/drv/wd_udma_drv.h | 34 +
include/wd_agg.h | 9 +-
include/wd_alg.h | 4 +
include/wd_comp.h | 2 +
include/wd_dae.h | 12 +
include/wd_join_gather.h | 352 +++++
include/wd_udma.h | 124 ++
include/wd_util.h | 2 +
libwd_dae.map | 34 +-
uadk_tool/benchmark/sec_uadk_benchmark.c | 34 +
uadk_tool/benchmark/sec_wd_benchmark.c | 34 +
uadk_tool/benchmark/uadk_benchmark.c | 14 +
uadk_tool/benchmark/uadk_benchmark.h | 4 +
uadk_tool/benchmark/zip_uadk_benchmark.c | 24 +-
v1/drv/hisi_zip_huf.c | 11 +-
v1/drv/hisi_zip_udrv.c | 2 +-
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 -----
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 ++--
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +--
v1/uacce.h | 1 -
v1/wd.c | 57 +-
v1/wd.h | 2 -
wd.c | 2 +-
wd_agg.c | 75 +-
wd_comp.c | 56 +-
wd_join_gather.c | 1823 ++++++++++++++++++++++
wd_sched.c | 3 +-
wd_udma.c | 511 ++++++
wd_util.c | 34 +-
41 files changed, 6435 insertions(+), 1518 deletions(-)
create mode 100644 drv/hisi_dae.h
create mode 100644 drv/hisi_dae_common.c
create mode 100644 drv/hisi_dae_join_gather.c
create mode 100644 drv/hisi_udma.c
create mode 100644 include/drv/wd_join_gather_drv.h
create mode 100644 include/drv/wd_udma_drv.h
create mode 100644 include/wd_join_gather.h
create mode 100644 include/wd_udma.h
create mode 100644 wd_join_gather.c
create mode 100644 wd_udma.c
--
2.33.0
1
22
From: Chenghai Huang <huangchenghai2(a)huawei.com>
Supports LZ77 encoding for LZ4 without additional offset
processing. The output includes literal and sequence (LitLength,
MatchLength, Offset).
Signed-off-by: Chenghai Huang <huangchenghai2(a)huawei.com>
---
drv/hisi_comp.c | 310 +++++++++++++++++++++++++++++++++++++---------
include/wd_comp.h | 1 +
wd_comp.c | 2 +-
wd_util.c | 1 +
4 files changed, 255 insertions(+), 59 deletions(-)
diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c
index 0c36301d..1c9f438f 100644
--- a/drv/hisi_comp.c
+++ b/drv/hisi_comp.c
@@ -84,6 +84,9 @@
#define OVERFLOW_DATA_SIZE 8
#define SEQ_DATA_SIZE_SHIFT 3
#define ZSTD_FREQ_DATA_SIZE 784
+#define ZSTD_MIN_OUT_SIZE 1000
+#define LZ77_MIN_OUT_SIZE 200
+#define PRICE_MIN_OUT_SIZE 4096
#define ZSTD_LIT_RESV_SIZE 16
#define REPCODE_SIZE 12
@@ -108,6 +111,8 @@ enum alg_type {
HW_GZIP,
HW_LZ77_ZSTD_PRICE = 0x42,
HW_LZ77_ZSTD,
+ HW_LZ77_ONLY = 0x40,
+ HW_LZ77_ONLY_PRICE,
};
enum hw_state {
@@ -616,31 +621,30 @@ static void fill_buf_addr_lz77_zstd(struct hisi_zip_sqe *sqe,
sqe->stream_ctx_addr_h = upper_32_bits(ctx_buf);
}
-static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe,
- struct wd_comp_msg *msg)
+static int lz77_zstd_buf_check(struct wd_comp_msg *msg)
{
- struct wd_comp_req *req = &msg->req;
- struct wd_lz77_zstd_data *data = req->priv;
__u32 in_size = msg->req.src_len;
- __u32 lits_size = in_size + ZSTD_LIT_RESV_SIZE;
__u32 out_size = msg->avail_out;
- void *ctx_buf = NULL;
+ __u32 lits_size = in_size + ZSTD_LIT_RESV_SIZE;
+ __u32 seq_avail_out = out_size - lits_size;
- if (unlikely(!data)) {
- WD_ERR("invalid: wd_lz77_zstd_data address is NULL!\n");
- return -WD_EINVAL;
+ if (unlikely(in_size > ZSTD_MAX_SIZE)) {
+ WD_ERR("invalid: in_len(%u) of lz77_zstd is out of range!\n", in_size);
+ return -WD_EINVAL;
}
- if (unlikely(in_size > ZSTD_MAX_SIZE)) {
- WD_ERR("invalid: in_len(%u) of lz77_zstd is out of range!\n",
- in_size);
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv < WD_COMP_L9 &&
+ seq_avail_out <= ZSTD_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum!\n",
+ out_size, ZSTD_MIN_OUT_SIZE + lits_size);
return -WD_EINVAL;
}
- if (unlikely(out_size > HZ_MAX_SIZE)) {
- WD_ERR("warning: avail_out(%u) is out of range , will set 8MB size max!\n",
- out_size);
- out_size = HZ_MAX_SIZE;
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv == WD_COMP_L9 &&
+ seq_avail_out <= PRICE_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum in price mode!\n",
+ out_size, PRICE_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
}
/*
@@ -653,14 +657,92 @@ static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe,
return -WD_EINVAL;
}
+ return 0;
+}
+
+static int lz77_only_buf_check(struct wd_comp_msg *msg)
+{
+ __u32 in_size = msg->req.src_len;
+ __u32 out_size = msg->avail_out;
+ __u32 lits_size = in_size + ZSTD_LIT_RESV_SIZE;
+ __u32 seq_avail_out = out_size - lits_size;
+
+ /* lits_size need to be less than 8M when use pbuffer */
+ if (unlikely(lits_size > HZ_MAX_SIZE)) {
+ WD_ERR("invalid: in_len(%u) of lz77_only is out of range!\n", in_size);
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv < WD_COMP_L9 &&
+ seq_avail_out <= LZ77_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum!\n",
+ out_size, LZ77_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv == WD_COMP_L9 &&
+ seq_avail_out <= PRICE_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum in price mode!\n",
+ out_size, PRICE_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ /* For lz77_only, the hardware needs 32 Bytes buffer to output the dfx information */
+ if (unlikely(out_size < ZSTD_LIT_RESV_SIZE + lits_size)) {
+ WD_ERR("invalid: output is not enough, %u bytes are minimum!\n",
+ ZSTD_LIT_RESV_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
+static int lz77_buf_check(struct wd_comp_msg *msg)
+{
+ enum wd_comp_alg_type alg_type = msg->alg_type;
+
+ if (alg_type == WD_LZ77_ZSTD)
+ return lz77_zstd_buf_check(msg);
+ else if (alg_type == WD_LZ77_ONLY)
+ return lz77_only_buf_check(msg);
+
+ return 0;
+}
+
+static int fill_buf_lz77_zstd(handle_t h_qp, struct hisi_zip_sqe *sqe,
+ struct wd_comp_msg *msg)
+{
+ struct wd_comp_req *req = &msg->req;
+ struct wd_lz77_zstd_data *data = req->priv;
+ __u32 in_size = msg->req.src_len;
+ __u32 lits_size = in_size + ZSTD_LIT_RESV_SIZE;
+ __u32 seq_avail_out = msg->avail_out - lits_size;
+ void *ctx_buf = NULL;
+ int ret;
+
+ if (unlikely(!data)) {
+ WD_ERR("invalid: wd_lz77_zstd_data address is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ ret = lz77_buf_check(msg);
+ if (ret)
+ return ret;
+
+ if (unlikely(seq_avail_out > HZ_MAX_SIZE)) {
+ WD_ERR("warning: sequence avail_out(%u) is out of range , will set 8MB size max!\n",
+ seq_avail_out);
+ seq_avail_out = HZ_MAX_SIZE;
+ }
+
if (msg->ctx_buf) {
ctx_buf = msg->ctx_buf + RSV_OFFSET;
- if (data->blk_type != COMP_BLK)
+ if (msg->alg_type == WD_LZ77_ZSTD && data->blk_type != COMP_BLK)
memcpy(ctx_buf + CTX_HW_REPCODE_OFFSET,
msg->ctx_buf + CTX_REPCODE2_OFFSET, REPCODE_SIZE);
}
- fill_buf_size_lz77_zstd(sqe, in_size, lits_size, out_size - lits_size);
+ fill_buf_size_lz77_zstd(sqe, in_size, lits_size, seq_avail_out);
fill_buf_addr_lz77_zstd(sqe, req->src, req->dst, req->dst + lits_size, ctx_buf);
@@ -685,6 +767,103 @@ static struct wd_datalist *get_seq_start_list(struct wd_comp_req *req)
return cur;
}
+static int lz77_zstd_buf_check_sgl(struct wd_comp_msg *msg, __u32 lits_size)
+{
+ __u32 in_size = msg->req.src_len;
+ __u32 out_size = msg->avail_out;
+ __u32 seq_avail_out;
+
+ if (unlikely(in_size > ZSTD_MAX_SIZE)) {
+ WD_ERR("invalid: in_len(%u) of lz77_zstd is out of range!\n", in_size);
+ return -WD_EINVAL;
+ }
+
+ /*
+ * For lz77_zstd, the hardware needs 784 Bytes buffer to output
+ * the frequency information about input data. The sequences
+ * and frequency data need to be written to an independent sgl
+ * splited from list_dst.
+ */
+ if (unlikely(lits_size < in_size + ZSTD_LIT_RESV_SIZE)) {
+ WD_ERR("invalid: output is not enough for literals, at least %u bytes!\n",
+ ZSTD_FREQ_DATA_SIZE + lits_size);
+ return -WD_EINVAL;
+ } else if (unlikely(out_size < ZSTD_FREQ_DATA_SIZE + lits_size)) {
+ WD_ERR("invalid: output is not enough for sequences, at least %u bytes more!\n",
+ ZSTD_FREQ_DATA_SIZE + lits_size - out_size);
+ return -WD_EINVAL;
+ }
+
+ seq_avail_out = out_size - lits_size;
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv < WD_COMP_L9 &&
+ seq_avail_out <= ZSTD_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum!\n",
+ out_size, ZSTD_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv == WD_COMP_L9 &&
+ seq_avail_out <= PRICE_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum in price mode!\n",
+ out_size, PRICE_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
+static int lz77_only_buf_check_sgl(struct wd_comp_msg *msg, __u32 lits_size)
+{
+ __u32 in_size = msg->req.src_len;
+ __u32 out_size = msg->avail_out;
+ __u32 seq_avail_out;
+
+ /*
+ * For lz77_only, the hardware needs 32 Bytes buffer to output
+ * the dfx information. The literals and sequences data need to be written
+ * to an independent sgl splited from list_dst.
+ */
+ if (unlikely(lits_size < in_size + ZSTD_LIT_RESV_SIZE)) {
+ WD_ERR("invalid: output is not enough for literals, at least %u bytes!\n",
+ ZSTD_LIT_RESV_SIZE + lits_size);
+ return -WD_EINVAL;
+ } else if (unlikely(out_size < ZSTD_LIT_RESV_SIZE + lits_size)) {
+ WD_ERR("invalid: output is not enough for sequences, at least %u bytes more!\n",
+ ZSTD_LIT_RESV_SIZE + lits_size - out_size);
+ return -WD_EINVAL;
+ }
+
+ seq_avail_out = out_size - lits_size;
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv < WD_COMP_L9 &&
+ seq_avail_out <= LZ77_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum!\n",
+ out_size, LZ77_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv == WD_COMP_L9 &&
+ seq_avail_out <= PRICE_MIN_OUT_SIZE)) {
+ WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum in price mode!\n",
+ out_size, PRICE_MIN_OUT_SIZE + lits_size);
+ return -WD_EINVAL;
+ }
+
+ return 0;
+}
+
+
+static int lz77_buf_check_sgl(struct wd_comp_msg *msg, __u32 lits_size)
+{
+ enum wd_comp_alg_type alg_type = msg->alg_type;
+
+ if (alg_type == WD_LZ77_ZSTD)
+ return lz77_zstd_buf_check_sgl(msg, lits_size);
+ else if (alg_type == WD_LZ77_ONLY)
+ return lz77_only_buf_check_sgl(msg, lits_size);
+
+ return 0;
+}
+
static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
struct wd_comp_msg *msg)
{
@@ -698,12 +877,6 @@ static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
__u32 lits_size;
int ret;
- if (unlikely(in_size > ZSTD_MAX_SIZE)) {
- WD_ERR("invalid: in_len(%u) of lz77_zstd is out of range!\n",
- in_size);
- return -WD_EINVAL;
- }
-
if (unlikely(!data)) {
WD_ERR("invalid: wd_lz77_zstd_data address is NULL!\n");
return -WD_EINVAL;
@@ -715,26 +888,15 @@ static int fill_buf_lz77_zstd_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
if (unlikely(!seq_start))
return -WD_EINVAL;
+ lits_size = hisi_qm_get_list_size(req->list_dst, seq_start);
+
+ ret = lz77_buf_check_sgl(msg, lits_size);
+ if (ret)
+ return ret;
+
data->literals_start = req->list_dst;
data->sequences_start = seq_start;
- /*
- * For lz77_zstd, the hardware needs 784 Bytes buffer to output
- * the frequency information about input data. The sequences
- * and frequency data need to be written to an independent sgl
- * splited from list_dst.
- */
- lits_size = hisi_qm_get_list_size(req->list_dst, seq_start);
- if (unlikely(lits_size < in_size + ZSTD_LIT_RESV_SIZE)) {
- WD_ERR("invalid: output is not enough for literals, %u bytes are minimum!\n",
- ZSTD_FREQ_DATA_SIZE + lits_size);
- return -WD_EINVAL;
- } else if (unlikely(out_size < ZSTD_FREQ_DATA_SIZE + lits_size)) {
- WD_ERR("invalid: output is not enough for sequences, at least %u bytes more!\n",
- ZSTD_FREQ_DATA_SIZE + lits_size - out_size);
- return -WD_EINVAL;
- }
-
fill_buf_size_lz77_zstd(sqe, in_size, lits_size, out_size - lits_size);
h_sgl_pool = hisi_qm_get_sglpool(h_qp);
@@ -824,6 +986,15 @@ static void fill_alg_lz77_zstd(struct hisi_zip_sqe *sqe)
sqe->dw9 = val;
}
+static void fill_alg_lz77_only(struct hisi_zip_sqe *sqe)
+{
+ __u32 val;
+
+ val = sqe->dw9 & ~HZ_REQ_TYPE_MASK;
+ val |= HW_LZ77_ONLY;
+ sqe->dw9 = val;
+}
+
static void fill_tag_v1(struct hisi_zip_sqe *sqe, __u32 tag)
{
sqe->dw13 = tag;
@@ -841,7 +1012,7 @@ static int fill_comp_level_deflate(struct hisi_zip_sqe *sqe, enum wd_comp_level
static int fill_comp_level_lz77_zstd(struct hisi_zip_sqe *sqe, enum wd_comp_level comp_lv)
{
- __u32 val;
+ __u32 val, alg;
switch (comp_lv) {
case WD_COMP_L8:
@@ -851,8 +1022,12 @@ static int fill_comp_level_lz77_zstd(struct hisi_zip_sqe *sqe, enum wd_comp_leve
*/
break;
case WD_COMP_L9:
+ alg = sqe->dw9 & HZ_REQ_TYPE_MASK;
val = sqe->dw9 & ~HZ_REQ_TYPE_MASK;
- val |= HW_LZ77_ZSTD_PRICE;
+ if (alg == HW_LZ77_ZSTD)
+ val |= HW_LZ77_ZSTD_PRICE;
+ else if (alg == HW_LZ77_ONLY)
+ val |= HW_LZ77_ONLY_PRICE;
sqe->dw9 = val;
break;
default:
@@ -911,18 +1086,22 @@ static void get_data_size_lz77_zstd(struct hisi_zip_sqe *sqe, enum wd_comp_op_ty
if (unlikely(!data))
return;
+ recv_msg->in_cons = sqe->consumed;
data->lit_num = sqe->comp_data_length;
data->seq_num = sqe->produced;
- data->lit_length_overflow_cnt = sqe->dw31 >> LITLEN_OVERFLOW_CNT_SHIFT;
- data->lit_length_overflow_pos = sqe->dw31 & LITLEN_OVERFLOW_POS_MASK;
- data->freq = data->sequences_start + (data->seq_num << SEQ_DATA_SIZE_SHIFT) +
- OVERFLOW_DATA_SIZE;
-
- if (ctx_buf) {
- memcpy(ctx_buf + CTX_REPCODE2_OFFSET,
- ctx_buf + CTX_REPCODE1_OFFSET, REPCODE_SIZE);
- memcpy(ctx_buf + CTX_REPCODE1_OFFSET,
- ctx_buf + RSV_OFFSET + CTX_HW_REPCODE_OFFSET, REPCODE_SIZE);
+
+ if (recv_msg->alg_type == WD_LZ77_ZSTD) {
+ data->lit_length_overflow_cnt = sqe->dw31 >> LITLEN_OVERFLOW_CNT_SHIFT;
+ data->lit_length_overflow_pos = sqe->dw31 & LITLEN_OVERFLOW_POS_MASK;
+ data->freq = data->sequences_start + (data->seq_num << SEQ_DATA_SIZE_SHIFT) +
+ OVERFLOW_DATA_SIZE;
+
+ if (ctx_buf) {
+ memcpy(ctx_buf + CTX_REPCODE2_OFFSET,
+ ctx_buf + CTX_REPCODE1_OFFSET, REPCODE_SIZE);
+ memcpy(ctx_buf + CTX_REPCODE1_OFFSET,
+ ctx_buf + RSV_OFFSET + CTX_HW_REPCODE_OFFSET, REPCODE_SIZE);
+ }
}
}
@@ -970,6 +1149,16 @@ struct hisi_zip_sqe_ops ops[] = { {
.fill_comp_level = fill_comp_level_lz77_zstd,
.get_data_size = get_data_size_lz77_zstd,
.get_tag = get_tag_v3,
+ }, {
+ .alg_name = "lz77_only",
+ .fill_buf[WD_FLAT_BUF] = fill_buf_lz77_zstd,
+ .fill_buf[WD_SGL_BUF] = fill_buf_lz77_zstd_sgl,
+ .fill_sqe_type = fill_sqe_type_v3,
+ .fill_alg = fill_alg_lz77_only,
+ .fill_tag = fill_tag_v3,
+ .fill_comp_level = fill_comp_level_lz77_zstd,
+ .get_data_size = get_data_size_lz77_zstd,
+ .get_tag = get_tag_v3,
}
};
@@ -1079,10 +1268,6 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
return -WD_EINVAL;
}
- ret = ops[alg_type].fill_comp_level(sqe, msg->comp_lv);
- if (unlikely(ret))
- return ret;
-
ret = ops[alg_type].fill_buf[msg->req.data_fmt]((handle_t)qp, sqe, msg);
if (unlikely(ret))
return ret;
@@ -1091,6 +1276,10 @@ static int fill_zip_comp_sqe(struct hisi_qp *qp, struct wd_comp_msg *msg,
ops[alg_type].fill_alg(sqe);
+ ret = ops[alg_type].fill_comp_level(sqe, msg->comp_lv);
+ if (unlikely(ret))
+ return ret;
+
ops[alg_type].fill_tag(sqe, msg->tag);
state = (msg->stream_mode == WD_COMP_STATEFUL) ? HZ_STATEFUL :
@@ -1132,7 +1321,7 @@ static void free_hw_sgl(handle_t h_qp, struct hisi_zip_sqe *sqe,
hw_sgl_out = VA_ADDR(sqe->dest_addr_h, sqe->dest_addr_l);
hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_out);
- if (alg_type == WD_LZ77_ZSTD) {
+ if (alg_type == WD_LZ77_ZSTD || alg_type == WD_LZ77_ONLY) {
hw_sgl_out = VA_ADDR(sqe->literals_addr_h,
sqe->literals_addr_l);
hisi_qm_put_hw_sgl(h_sgl_pool, hw_sgl_out);
@@ -1190,6 +1379,10 @@ static int get_alg_type(__u32 type)
case HW_LZ77_ZSTD_PRICE:
alg_type = WD_LZ77_ZSTD;
break;
+ case HW_LZ77_ONLY:
+ case HW_LZ77_ONLY_PRICE:
+ alg_type = WD_LZ77_ONLY;
+ break;
default:
break;
}
@@ -1369,6 +1562,7 @@ static struct wd_alg_driver zip_alg_driver[] = {
GEN_ZIP_ALG_DRIVER("deflate"),
GEN_ZIP_ALG_DRIVER("lz77_zstd"),
+ GEN_ZIP_ALG_DRIVER("lz77_only"),
};
#ifdef WD_STATIC_DRV
diff --git a/include/wd_comp.h b/include/wd_comp.h
index 45994ff6..0012ef6b 100644
--- a/include/wd_comp.h
+++ b/include/wd_comp.h
@@ -20,6 +20,7 @@ enum wd_comp_alg_type {
WD_ZLIB,
WD_GZIP,
WD_LZ77_ZSTD,
+ WD_LZ77_ONLY,
WD_COMP_ALG_MAX,
};
diff --git a/wd_comp.c b/wd_comp.c
index 647c320e..8e47a32f 100644
--- a/wd_comp.c
+++ b/wd_comp.c
@@ -27,7 +27,7 @@
#define cpu_to_be32(x) swap_byte(x)
static const char *wd_comp_alg_name[WD_COMP_ALG_MAX] = {
- "zlib", "gzip", "deflate", "lz77_zstd"
+ "zlib", "gzip", "deflate", "lz77_zstd", "lz77_only"
};
struct wd_comp_sess {
diff --git a/wd_util.c b/wd_util.c
index 669743cb..f21b3236 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -107,6 +107,7 @@ static struct acc_alg_item alg_options[] = {
{"gzip", "gzip"},
{"deflate", "deflate"},
{"lz77_zstd", "lz77_zstd"},
+ {"lz77_only", "lz77_only"},
{"hashagg", "hashagg"},
{"udma", "udma"},
--
2.33.0
1
5
From: Longfang Liu <liulongfang(a)huawei.com>
In the No-SVA mode of UADK, a feature was implemented to reserve
memory allocated for shared queues, which was exposed to external
users through the wd_share_reserved_memory interface.
After this functionality was removed from the kernel-space UACCE,
the corresponding external interface in UADK must also be deleted
to maintain consistency.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
---
v1/uacce.h | 1 -
v1/wd.c | 57 ++----------------------------------------------------
v1/wd.h | 2 --
3 files changed, 2 insertions(+), 58 deletions(-)
diff --git a/v1/uacce.h b/v1/uacce.h
index eef932c7..ffd576c1 100644
--- a/v1/uacce.h
+++ b/v1/uacce.h
@@ -79,7 +79,6 @@ enum uacce_qfrt {
* Optimization method since close fd may delay
*/
#define WD_UACCE_CMD_PUT_Q _IO('W', 1)
-#define WD_UACCE_CMD_SHARE_SVAS _IO('W', 2)
#define WD_UACCE_CMD_GET_SS_DMA _IOR('W', 3, unsigned long)
#endif
diff --git a/v1/wd.c b/v1/wd.c
index 13239b58..bab2712f 100644
--- a/v1/wd.c
+++ b/v1/wd.c
@@ -58,7 +58,6 @@ struct dev_info {
int node_id;
int numa_dis;
int flags;
- int ref;
int available_instances;
int iommu_type;
unsigned int weight;
@@ -531,7 +530,6 @@ static int get_queue_from_dev(struct wd_queue *q, const struct dev_info *dev)
qinfo->iommu_type = dev->iommu_type;
qinfo->dev_info = dev;
qinfo->head = &qinfo->ss_list;
- __atomic_clear(&qinfo->ref, __ATOMIC_RELEASE);
TAILQ_INIT(&qinfo->ss_list);
memcpy(qinfo->qfrs_offset, dev->qfrs_offset,
sizeof(qinfo->qfrs_offset));
@@ -618,23 +616,14 @@ err_with_dev:
void wd_release_queue(struct wd_queue *q)
{
- struct wd_ss_region_list *head;
- struct q_info *qinfo, *sqinfo;
+ struct q_info *qinfo;
if (!q || !q->qinfo) {
WD_ERR("release queue parameter error!\n");
return;
}
- qinfo = q->qinfo;
- if (__atomic_load_n(&qinfo->ref, __ATOMIC_RELAXED)) {
- WD_ERR("q(%s) is busy, release fail!\n", q->capa.alg);
- return;
- }
- head = qinfo->head;
- sqinfo = container_of(head, struct q_info, ss_list);
- if (sqinfo != qinfo) /* q_share */
- __atomic_sub_fetch(&sqinfo->ref, 1, __ATOMIC_RELAXED);
+ qinfo = q->qinfo;
if (ioctl(qinfo->fd, WD_UACCE_CMD_PUT_Q))
WD_ERR("failed to put queue!\n");
@@ -721,48 +710,6 @@ void *wd_reserve_memory(struct wd_queue *q, size_t size)
return drv_reserve_mem(q, size);
}
-int wd_share_reserved_memory(struct wd_queue *q,
- struct wd_queue *target_q)
-{
- const struct dev_info *info, *tgt_info;
- struct q_info *qinfo, *tqinfo;
- int ret;
-
- if (!q || !target_q || !q->qinfo || !target_q->qinfo) {
- WD_ERR("wd share reserved memory: parameter err!\n");
- return -WD_EINVAL;
- }
-
- qinfo = q->qinfo;
- tqinfo = target_q->qinfo;
- tgt_info = tqinfo->dev_info;
- info = qinfo->dev_info;
-
- /* Just share DMA memory from 'q' in NO-IOMMU mode */
- if (qinfo->iommu_type) {
- WD_ERR("IOMMU opened, not support share mem!\n");
- return -WD_EINVAL;
- }
-
- if (qinfo->iommu_type != tqinfo->iommu_type) {
- WD_ERR("IOMMU type mismatching as share mem!\n");
- return -WD_EINVAL;
- }
- if (info->node_id != tgt_info->node_id)
- WD_ERR("Warn: the 2 queues is not at the same node!\n");
-
- ret = ioctl(qinfo->fd, WD_UACCE_CMD_SHARE_SVAS, tqinfo->fd);
- if (ret) {
- WD_ERR("ioctl share dma memory fail!\n");
- return ret;
- }
-
- tqinfo->head = qinfo->head;
- __atomic_add_fetch(&qinfo->ref, 1, __ATOMIC_RELAXED);
-
- return 0;
-}
-
int wd_get_available_dev_num(const char *algorithm)
{
struct wd_queue q;
diff --git a/v1/wd.h b/v1/wd.h
index 79b8a2ad..35dcf31a 100644
--- a/v1/wd.h
+++ b/v1/wd.h
@@ -210,8 +210,6 @@ int wd_recv(struct wd_queue *q, void **resp);
int wd_wait(struct wd_queue *q, __u16 ms);
int wd_recv_sync(struct wd_queue *q, void **resp, __u16 ms);
void *wd_reserve_memory(struct wd_queue *q, size_t size);
-int wd_share_reserved_memory(struct wd_queue *q,
- struct wd_queue *target_q);
int wd_get_available_dev_num(const char *algorithm);
int wd_get_node_id(struct wd_queue *q);
void *wd_iova_map(struct wd_queue *q, void *va, size_t sz);
--
2.33.0
1
1
From: Weili Qian <qianweili(a)huawei.com>
UADK supports hardware acceleration for the data move.
Currently, data copying and initialization are supported.
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
Makefile.am | 27 +-
drv/hisi_udma.c | 566 ++++++++++++++++++++++++++++++++++++++
include/drv/wd_udma_drv.h | 34 +++
include/wd_alg.h | 2 +
include/wd_udma.h | 124 +++++++++
include/wd_util.h | 1 +
libwd_dae.map | 15 +-
wd_udma.c | 511 ++++++++++++++++++++++++++++++++++
wd_util.c | 2 +
9 files changed, 1278 insertions(+), 4 deletions(-)
create mode 100644 drv/hisi_udma.c
create mode 100644 include/drv/wd_udma_drv.h
create mode 100644 include/wd_udma.h
create mode 100644 wd_udma.c
diff --git a/Makefile.am b/Makefile.am
index c4b9c526..df756f72 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,16 +36,17 @@ pkginclude_HEADERS = include/wd.h include/wd_cipher.h include/wd_aead.h \
include/wd_comp.h include/wd_dh.h include/wd_digest.h \
include/wd_rsa.h include/uacce.h include/wd_alg_common.h \
include/wd_ecc.h include/wd_sched.h include/wd_alg.h \
- include/wd_zlibwrapper.h include/wd_dae.h include/wd_agg.h
+ include/wd_zlibwrapper.h include/wd_dae.h include/wd_agg.h \
+ include/wd_udma.h
nobase_pkginclude_HEADERS = v1/wd.h v1/wd_cipher.h v1/wd_aead.h v1/uacce.h v1/wd_dh.h \
v1/wd_digest.h v1/wd_rsa.h v1/wd_bmm.h
-lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la libwd_dae.la
+lib_LTLIBRARIES=libwd.la libwd_comp.la libwd_crypto.la libwd_dae.la libwd_udma.la
uadk_driversdir=$(libdir)/uadk
uadk_drivers_LTLIBRARIES=libhisi_sec.la libhisi_hpre.la libhisi_zip.la \
- libisa_ce.la libisa_sve.la libhisi_dae.la
+ libisa_ce.la libisa_sve.la libhisi_dae.la libhisi_udma.la
libwd_la_SOURCES=wd.c wd_mempool.c wd.h wd_alg.c wd_alg.h \
v1/wd.c v1/wd.h v1/wd_adapter.c v1/wd_adapter.h \
@@ -69,6 +70,9 @@ libwd_la_SOURCES=wd.c wd_mempool.c wd.h wd_alg.c wd_alg.h \
v1/drv/hisi_sec_udrv.c v1/drv/hisi_sec_udrv.h \
v1/drv/hisi_rng_udrv.c v1/drv/hisi_rng_udrv.h
+libwd_udma_la_SOURCES=wd_udma.h wd_udma_drv.h wd_udma.c \
+ wd_util.c wd_util.h wd_sched.c wd_sched.h wd.c wd.h
+
libwd_dae_la_SOURCES=wd_dae.h wd_agg.h wd_agg_drv.h wd_agg.c \
wd_util.c wd_util.h wd_sched.c wd_sched.h wd.c wd.h
@@ -110,6 +114,9 @@ endif
libhisi_dae_la_SOURCES=drv/hisi_dae.c drv/hisi_qm_udrv.c \
hisi_qm_udrv.h
+libhisi_udma_la_SOURCES=drv/hisi_udma.c drv/hisi_qm_udrv.c \
+ hisi_qm_udrv.h
+
if WD_STATIC_DRV
AM_CFLAGS += -DWD_STATIC_DRV -fPIC
AM_CFLAGS += -DWD_NO_LOG
@@ -124,6 +131,9 @@ libhisi_zip_la_LIBADD = -ldl
libwd_crypto_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma
libwd_crypto_la_DEPENDENCIES = libwd.la
+libwd_udma_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma -lm -lpthread
+libwd_udma_la_DEPENDENCIES = libwd.la
+
libwd_dae_la_LIBADD = $(libwd_la_OBJECTS) -ldl -lnuma
libwd_dae_la_DEPENDENCIES = libwd.la
@@ -139,6 +149,9 @@ libisa_ce_la_DEPENDENCIES = libwd.la libwd_crypto.la
libisa_sve_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_crypto_la_OBJECTS)
libisa_sve_la_DEPENDENCIES = libwd.la libwd_crypto.la
+libhisi_udma_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_udma_la_OBJECTS)
+libhisi_udma_la_DEPENDENCIES = libwd.la libwd_udma.la
+
libhisi_dae_la_LIBADD = $(libwd_la_OBJECTS) $(libwd_dae_la_OBJECTS)
libhisi_dae_la_DEPENDENCIES = libwd.la libwd_dae.la
@@ -160,6 +173,10 @@ libwd_crypto_la_LIBADD= -lwd -ldl -lnuma
libwd_crypto_la_LDFLAGS=$(UADK_VERSION) $(UADK_CRYPTO_SYMBOL) -lpthread
libwd_crypto_la_DEPENDENCIES= libwd.la
+libwd_udma_la_LIBADD= -lwd -ldl -lnuma -lm -lpthread
+libwd_udma_la_LDFLAGS=$(UADK_VERSION) $(UADK_DAE_SYMBOL)
+libwd_udma_la_DEPENDENCIES= libwd.la
+
libwd_dae_la_LIBADD= -lwd -ldl -lnuma -lm
libwd_dae_la_LDFLAGS=$(UADK_VERSION) $(UADK_DAE_SYMBOL)
libwd_dae_la_DEPENDENCIES= libwd.la
@@ -184,6 +201,10 @@ libisa_sve_la_LIBADD= -lwd -lwd_crypto
libisa_sve_la_LDFLAGS=$(UADK_VERSION)
libisa_sve_la_DEPENDENCIES= libwd.la libwd_crypto.la
+libhisi_udma_la_LIBADD= -lwd -lwd_udma
+libhisi_udma_la_LDFLAGS=$(UADK_VERSION)
+libhisi_udma_la_DEPENDENCIES= libwd.la libwd_udma.la
+
libhisi_dae_la_LIBADD= -lwd -lwd_dae
libhisi_dae_la_LDFLAGS=$(UADK_VERSION)
libhisi_dae_la_DEPENDENCIES= libwd.la libwd_dae.la
diff --git a/drv/hisi_udma.c b/drv/hisi_udma.c
new file mode 100644
index 00000000..57dae8cb
--- /dev/null
+++ b/drv/hisi_udma.c
@@ -0,0 +1,566 @@
+// SPDX-License-Identifier: Apache-2.0
+/* Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved. */
+
+#include <math.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include "hisi_qm_udrv.h"
+#include "../include/drv/wd_udma_drv.h"
+
+#define BIT(nr) (1UL << (nr))
+#define UDMA_CTX_Q_NUM_DEF 1
+#define UDMA_TASK_TYPE 0x3
+#define UDMA_SQE_TYPE 0x1
+#define UDMA_ALG_TYPE 2
+/* Multi max data size is (16M -1) * 64 */
+#define UDMA_M_MAX_ADDR_SIZE 1073741760
+/* Single max data size is (16M - 1) */
+#define UDMA_S_MAX_ADDR_SIZE 16777215
+#define UDMA_MAX_ADDR_NUM 64
+#define UDMA_ADDR_NUM_SHIFT 6
+#define UDMA_MULTI_ADDR_EN BIT(14)
+#define UDMA_ADDR_NUM_SHIFT 6
+#define UDMA_SVA_PREFETCH_EN BIT(15)
+#define UDMA_ADDR_RESV_NUM 16
+#define UDMA_ADDR_ALIGN_SIZE 128
+
+enum {
+ DATA_MEMCPY = 0x0,
+ DATA_MEMSET = 0x7,
+};
+
+enum {
+ UDMA_TASK_DONE = 0x1,
+ UDMA_TASK_ERROR = 0x2,
+};
+
+struct udma_addr {
+ __u64 addr;
+ __u64 data_size;
+};
+
+struct udma_addr_array {
+ __u64 resv_addr[UDMA_ADDR_RESV_NUM];
+ struct udma_addr src_addr[UDMA_MAX_ADDR_NUM];
+ struct udma_addr dst_addr[UDMA_MAX_ADDR_NUM];
+};
+
+struct udma_sqe {
+ __u32 bd_type : 6;
+ __u32 resv1 : 2;
+ __u32 task_type : 6;
+ __u32 resv2 : 2;
+ __u32 task_type_ext : 6;
+ __u32 resv3 : 9;
+ __u32 bd_invlid : 1;
+ __u32 rsv4[2];
+ __u32 low_tag;
+ __u32 hi_tag;
+ /* The number of bytes to be copied or filled for single address. */
+ __u32 data_size;
+ __u32 rsv5;
+ /*
+ * 0 ~ 13 bits: reserved,
+ * 14 bit: single address or multi addresses,
+ * 15 bit: sva prefetch en.
+ */
+ __u16 dw0;
+ /*
+ * 0 ~5 bits: reserved,
+ * 6 ~ 13 bits: address num,
+ * 14 ~15 bits: reserved.
+ */
+ __u16 dw1;
+ __u64 init_val;
+ __u32 rsv6[12];
+ /* dst addr for single address task */
+ __u64 dst_addr;
+ __u32 rsv7[2];
+ /* src addr for single address task, addr array for multi addresses. */
+ __u64 addr_array;
+ __u32 done_flag : 3;
+ __u32 rsv8 : 1;
+ __u32 ext_err_type : 12;
+ __u32 err_type : 8;
+ __u32 wtype : 8;
+ __u32 rsv9[3];
+};
+
+struct udma_internal_addr {
+ struct udma_addr_array *addr_array;
+ __u8 *addr_status;
+ __u16 addr_count;
+ __u16 tail;
+};
+
+struct hisi_udma_ctx {
+ struct wd_ctx_config_internal config;
+};
+
+static int get_free_inter_addr(struct udma_internal_addr *inter_addr)
+{
+ __u16 addr_count = inter_addr->addr_count;
+ __u16 idx = inter_addr->tail;
+ __u16 cnt = 0;
+
+ if (unlikely(!addr_count)) {
+ WD_ERR("invalid: internal addr count is 0!\n");
+ return -WD_EINVAL;
+ }
+
+ while (__atomic_test_and_set(&inter_addr->addr_status[idx], __ATOMIC_ACQUIRE)) {
+ idx = (idx + 1) % addr_count;
+ cnt++;
+ if (cnt == addr_count)
+ return -WD_EBUSY;
+ }
+
+ inter_addr->tail = (idx + 1) % addr_count;
+
+ return idx;
+}
+
+static void put_inter_addr(struct udma_internal_addr *inter_addr, int idx)
+{
+ __atomic_clear(&inter_addr->addr_status[idx], __ATOMIC_RELEASE);
+}
+
+static int check_udma_param(struct wd_udma_msg *msg)
+{
+ int i;
+
+ if (unlikely(!msg)) {
+ WD_ERR("invalid: input udma msg is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(msg->addr_num > UDMA_MAX_ADDR_NUM)) {
+ WD_ERR("invalid: input addr_num is more than %d!\n", UDMA_MAX_ADDR_NUM);
+ return -WD_EINVAL;
+ }
+
+ /*
+ * When the single address length exceeds UDMA_S_MAX_ADDR_SIZE,
+ * the driver will split the address into multiple addresses and
+ * send them to the hardware.
+ */
+ if (msg->addr_num == 1) {
+ if (unlikely(msg->dst->data_size > UDMA_M_MAX_ADDR_SIZE)) {
+ WD_ERR("invalid: input size %lu is more than %d!\n",
+ msg->dst->data_size, UDMA_M_MAX_ADDR_SIZE);
+ return -WD_EINVAL;
+ }
+
+ return WD_SUCCESS;
+ }
+
+ for (i = 0; i < msg->addr_num; i++) {
+ if (unlikely(msg->dst[i].data_size > UDMA_S_MAX_ADDR_SIZE)) {
+ WD_ERR("invalid: addr %d input size %lu is more than %d!\n",
+ i, msg->dst[i].data_size, UDMA_S_MAX_ADDR_SIZE);
+ return -WD_EINVAL;
+ }
+ }
+
+ return WD_SUCCESS;
+}
+
+static void fill_long_size_memcpy_info(struct udma_sqe *sqe, struct wd_udma_msg *msg,
+ struct udma_addr_array *addr_array)
+{
+ __u32 addr_num = 0;
+ __u64 count;
+
+ for (count = 0; count < msg->src->data_size; count += UDMA_S_MAX_ADDR_SIZE) {
+ addr_array->src_addr[addr_num].addr = (__u64)(uintptr_t)msg->src->addr + count;
+ addr_array->dst_addr[addr_num].addr = (__u64)(uintptr_t)msg->dst->addr + count;
+ if (count + UDMA_S_MAX_ADDR_SIZE <= msg->src->data_size) {
+ addr_array->src_addr[addr_num].data_size = UDMA_S_MAX_ADDR_SIZE;
+ addr_array->dst_addr[addr_num].data_size = UDMA_S_MAX_ADDR_SIZE;
+ } else {
+ addr_array->src_addr[addr_num].data_size = msg->src->data_size - count;
+ addr_array->dst_addr[addr_num].data_size = msg->dst->data_size - count;
+ }
+ addr_num++;
+ }
+ sqe->dw1 |= (addr_num - 1) << UDMA_ADDR_NUM_SHIFT;
+}
+
+static void fill_long_size_memset_info(struct udma_sqe *sqe, struct wd_udma_msg *msg,
+ struct udma_addr_array *addr_array)
+{
+ __u32 addr_num = 0;
+ __u64 count;
+
+ for (count = 0; count < msg->dst->data_size; count += UDMA_S_MAX_ADDR_SIZE) {
+ addr_array->dst_addr[addr_num].addr = (__u64)(uintptr_t)msg->dst->addr + count;
+ if (count + UDMA_S_MAX_ADDR_SIZE <= msg->dst->data_size)
+ addr_array->dst_addr[addr_num].data_size = UDMA_S_MAX_ADDR_SIZE;
+ else
+ addr_array->dst_addr[addr_num].data_size = msg->dst->data_size - count;
+ addr_num++;
+ }
+
+ sqe->dw1 |= (addr_num - 1) << UDMA_ADDR_NUM_SHIFT;
+}
+
+static void fill_mulit_memset_addr_info(struct udma_sqe *sqe, struct wd_udma_msg *msg,
+ struct udma_addr_array *addr_array)
+{
+ int i;
+
+ for (i = 0; i < msg->addr_num; i++) {
+ addr_array->dst_addr[i].addr = (__u64)(uintptr_t)msg->dst[i].addr;
+ addr_array->dst_addr[i].data_size = (__u64)(uintptr_t)msg->dst[i].data_size;
+ }
+
+ sqe->dw1 |= ((__u32)msg->addr_num - 1) << UDMA_ADDR_NUM_SHIFT;
+}
+
+static void fill_multi_memcpy_addr_info(struct udma_sqe *sqe, struct wd_udma_msg *msg,
+ struct udma_addr_array *addr_array)
+{
+ int i;
+
+ for (i = 0; i < msg->addr_num; i++) {
+ addr_array->src_addr[i].addr = (__u64)(uintptr_t)msg->src[i].addr;
+ addr_array->src_addr[i].data_size = (__u64)(uintptr_t)msg->src[i].data_size;
+ addr_array->dst_addr[i].addr = (__u64)(uintptr_t)msg->dst[i].addr;
+ addr_array->dst_addr[i].data_size = (__u64)(uintptr_t)msg->dst[i].data_size;
+ }
+
+ sqe->dw1 |= ((__u32)msg->addr_num - 1) << UDMA_ADDR_NUM_SHIFT;
+}
+
+static void fill_multi_addr_info(struct udma_sqe *sqe, struct wd_udma_msg *msg,
+ struct udma_addr_array *addr_array)
+{
+ if (msg->addr_num == 1) {
+ if (msg->op_type == WD_UDMA_MEMCPY)
+ fill_long_size_memcpy_info(sqe, msg, addr_array);
+ else
+ fill_long_size_memset_info(sqe, msg, addr_array);
+ } else {
+ if (msg->op_type == WD_UDMA_MEMCPY)
+ fill_multi_memcpy_addr_info(sqe, msg, addr_array);
+ else
+ fill_mulit_memset_addr_info(sqe, msg, addr_array);
+ }
+
+ sqe->addr_array = (__u64)(uintptr_t)addr_array;
+ sqe->dw0 |= UDMA_MULTI_ADDR_EN;
+}
+
+static void fill_single_addr_info(struct udma_sqe *sqe, struct wd_udma_msg *msg)
+{
+ if (msg->op_type == WD_UDMA_MEMCPY)
+ sqe->addr_array = (__u64)(uintptr_t)msg->src->addr;
+ sqe->dst_addr = (__u64)(uintptr_t)msg->dst->addr;
+ sqe->data_size = msg->dst->data_size;
+}
+
+static void fill_udma_sqe_addr(struct udma_sqe *sqe, struct wd_udma_msg *msg,
+ struct udma_addr_array *addr_array)
+{
+ if (!addr_array)
+ fill_single_addr_info(sqe, msg);
+ else
+ fill_multi_addr_info(sqe, msg, addr_array);
+}
+
+static void fill_sqe_type(struct udma_sqe *sqe, struct wd_udma_msg *msg)
+{
+ sqe->bd_type = UDMA_SQE_TYPE;
+ sqe->task_type = UDMA_TASK_TYPE;
+ if (msg->op_type == WD_UDMA_MEMCPY)
+ sqe->task_type_ext = DATA_MEMCPY;
+ else
+ sqe->task_type_ext = DATA_MEMSET;
+}
+
+static void fill_init_value(struct udma_sqe *sqe, struct wd_udma_msg *msg)
+{
+ if (msg->op_type == WD_UDMA_MEMSET)
+ memset(&sqe->init_val, msg->value, sizeof(__u64));
+}
+
+static int udma_send(struct wd_alg_driver *drv, handle_t ctx, void *udma_msg)
+{
+ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct udma_internal_addr *inter_addr = qp->priv;
+ struct udma_addr_array *addr_array = NULL;
+ struct wd_udma_msg *msg = udma_msg;
+ struct udma_sqe sqe = {0};
+ __u16 send_cnt = 0;
+ int idx = 0;
+ int ret;
+
+ ret = check_udma_param(msg);
+ if (unlikely(ret))
+ return ret;
+
+ if (msg->addr_num > 1 || msg->dst->data_size > UDMA_S_MAX_ADDR_SIZE) {
+ idx = get_free_inter_addr(inter_addr);
+ if (idx < 0)
+ return -WD_EBUSY;
+
+ addr_array = &inter_addr->addr_array[idx];
+ memset(addr_array, 0, sizeof(struct udma_addr_array));
+ }
+
+ fill_sqe_type(&sqe, msg);
+ fill_init_value(&sqe, msg);
+ fill_udma_sqe_addr(&sqe, msg, addr_array);
+
+ hisi_set_msg_id(h_qp, &msg->tag);
+ sqe.low_tag = msg->tag;
+ sqe.hi_tag = (__u32)idx;
+ sqe.dw0 |= UDMA_SVA_PREFETCH_EN;
+
+ ret = hisi_qm_send(h_qp, &sqe, 1, &send_cnt);
+ if (unlikely(ret)) {
+ if (ret != -WD_EBUSY)
+ WD_ERR("failed to send to hardware, ret = %d!\n", ret);
+ if (addr_array)
+ put_inter_addr(inter_addr, idx);
+ return ret;
+ }
+
+ return WD_SUCCESS;
+}
+
+static void dump_udma_msg(struct udma_sqe *sqe, struct wd_udma_msg *msg)
+{
+ WD_ERR("dump UDMA message after a task error occurs.\n"
+ "op_type:%u addr_num:%d.\n", msg->op_type, msg->addr_num);
+}
+
+static int udma_recv(struct wd_alg_driver *drv, handle_t ctx, void *udma_msg)
+{
+ handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct udma_internal_addr *inter_addr = qp->priv;
+ struct wd_udma_msg *msg = udma_msg;
+ struct wd_udma_msg *temp_msg = msg;
+ struct udma_sqe sqe = {0};
+ __u16 recv_cnt = 0;
+ int ret;
+
+ ret = hisi_qm_recv(h_qp, &sqe, 1, &recv_cnt);
+ if (ret)
+ return ret;
+
+ ret = hisi_check_bd_id(h_qp, msg->tag, sqe.low_tag);
+ if (ret)
+ goto out;
+
+ msg->tag = sqe.low_tag;
+ if (qp->q_info.qp_mode == CTX_MODE_ASYNC) {
+ temp_msg = wd_udma_get_msg(qp->q_info.idx, msg->tag);
+ if (!temp_msg) {
+ WD_ERR("failed to get send msg! idx = %u, tag = %u.\n",
+ qp->q_info.idx, msg->tag);
+ ret = -WD_EINVAL;
+ goto out;
+ }
+ }
+
+ msg->result = WD_SUCCESS;
+ if (sqe.done_flag != UDMA_TASK_DONE ||
+ sqe.err_type || sqe.ext_err_type || sqe.wtype) {
+ WD_ERR("failed to do udma task! done=0x%x, err_type=0x%x\n"
+ "ext_err_type=0x%x, wtype=0x%x!\n",
+ (__u32)sqe.done_flag, (__u32)sqe.err_type,
+ (__u32)sqe.ext_err_type, (__u32)sqe.wtype);
+ msg->result = WD_IN_EPARA;
+ }
+
+ if (unlikely(msg->result != WD_SUCCESS))
+ dump_udma_msg(&sqe, temp_msg);
+
+out:
+ if (sqe.dw0 & UDMA_MULTI_ADDR_EN)
+ put_inter_addr(inter_addr, sqe.hi_tag);
+ return ret;
+}
+
+static void udma_uninit_qp_priv(handle_t h_qp)
+{
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ struct udma_internal_addr *inter_addr;
+
+ if (!qp)
+ return;
+
+ inter_addr = (struct udma_internal_addr *)qp->priv;
+ if (!inter_addr)
+ return;
+
+ free(inter_addr->addr_array);
+ free(inter_addr->addr_status);
+ free(inter_addr);
+ qp->priv = NULL;
+}
+
+static int udma_init_qp_priv(handle_t h_qp)
+{
+ struct hisi_qp *qp = (struct hisi_qp *)h_qp;
+ __u16 sq_depth = qp->q_info.sq_depth;
+ struct udma_internal_addr *inter_addr;
+ int ret = -WD_ENOMEM;
+
+ inter_addr = calloc(1, sizeof(struct udma_internal_addr));
+ if (!inter_addr)
+ return ret;
+
+ inter_addr->addr_status = calloc(1, sizeof(__u8) * sq_depth);
+ if (!inter_addr->addr_status)
+ goto free_inter_addr;
+
+ inter_addr->addr_array = aligned_alloc(UDMA_ADDR_ALIGN_SIZE,
+ sizeof(struct udma_addr_array) * sq_depth);
+ if (!inter_addr->addr_array)
+ goto free_addr_status;
+
+ inter_addr->addr_count = sq_depth;
+ qp->priv = inter_addr;
+
+ return WD_SUCCESS;
+
+free_addr_status:
+ free(inter_addr->addr_status);
+free_inter_addr:
+ free(inter_addr);
+
+ return ret;
+}
+
+static int udma_init(struct wd_alg_driver *drv, void *conf)
+{
+ struct wd_ctx_config_internal *config = conf;
+ struct hisi_qm_priv qm_priv;
+ struct hisi_udma_ctx *priv;
+ handle_t h_qp = 0;
+ handle_t h_ctx;
+ __u32 i, j;
+ int ret;
+
+ if (!config || !config->ctx_num) {
+ WD_ERR("invalid: udma init config is null or ctx num is 0!\n");
+ return -WD_EINVAL;
+ }
+
+ priv = malloc(sizeof(struct hisi_udma_ctx));
+ if (!priv)
+ return -WD_ENOMEM;
+
+ qm_priv.op_type = UDMA_ALG_TYPE;
+ qm_priv.sqe_size = sizeof(struct udma_sqe);
+ /* Allocate qp for each context */
+ for (i = 0; i < config->ctx_num; i++) {
+ h_ctx = config->ctxs[i].ctx;
+ qm_priv.qp_mode = config->ctxs[i].ctx_mode;
+ /* Setting the epoll en to 0 for ASYNC ctx */
+ qm_priv.epoll_en = (qm_priv.qp_mode == CTX_MODE_SYNC) ?
+ config->epoll_en : 0;
+ qm_priv.idx = i;
+ h_qp = hisi_qm_alloc_qp(&qm_priv, h_ctx);
+ if (!h_qp) {
+ ret = -WD_ENOMEM;
+ goto out;
+ }
+ config->ctxs[i].sqn = qm_priv.sqn;
+ ret = udma_init_qp_priv(h_qp);
+ if (ret)
+ goto free_h_qp;
+ }
+ memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal));
+ drv->priv = priv;
+
+ return WD_SUCCESS;
+free_h_qp:
+ hisi_qm_free_qp(h_qp);
+out:
+ for (j = 0; j < i; j++) {
+ h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[j].ctx);
+ udma_uninit_qp_priv(h_qp);
+ hisi_qm_free_qp(h_qp);
+ }
+ free(priv);
+ return ret;
+}
+
+static void udma_exit(struct wd_alg_driver *drv)
+{
+ struct wd_ctx_config_internal *config;
+ struct hisi_udma_ctx *priv;
+ handle_t h_qp;
+ __u32 i;
+
+ if (!drv || !drv->priv)
+ return;
+
+ priv = (struct hisi_udma_ctx *)drv->priv;
+ config = &priv->config;
+ for (i = 0; i < config->ctx_num; i++) {
+ h_qp = (handle_t)wd_ctx_get_priv(config->ctxs[i].ctx);
+ udma_uninit_qp_priv(h_qp);
+ hisi_qm_free_qp(h_qp);
+ }
+
+ free(priv);
+ drv->priv = NULL;
+}
+
+static int udma_get_usage(void *param)
+{
+ return 0;
+}
+
+static struct wd_alg_driver udma_driver = {
+ .drv_name = "hisi_zip",
+ .alg_name = "udma",
+ .calc_type = UADK_ALG_HW,
+ .priority = 100,
+ .queue_num = UDMA_CTX_Q_NUM_DEF,
+ .op_type_num = 1,
+ .fallback = 0,
+ .init = udma_init,
+ .exit = udma_exit,
+ .send = udma_send,
+ .recv = udma_recv,
+ .get_usage = udma_get_usage,
+};
+
+#ifdef WD_STATIC_DRV
+void hisi_udma_probe(void)
+#else
+static void __attribute__((constructor)) hisi_udma_probe(void)
+#endif
+{
+ int ret;
+
+ WD_INFO("Info: register UDMA alg drivers!\n");
+
+ ret = wd_alg_driver_register(&udma_driver);
+ if (ret && ret != -WD_ENODEV)
+ WD_ERR("failed to register UDMA driver, ret = %d!\n", ret);
+}
+
+#ifdef WD_STATIC_DRV
+void hisi_udma_remove(void)
+#else
+static void __attribute__((destructor)) hisi_udma_remove(void)
+#endif
+{
+ WD_INFO("Info: unregister UDMA alg drivers!\n");
+
+ wd_alg_driver_unregister(&udma_driver);
+}
diff --git a/include/drv/wd_udma_drv.h b/include/drv/wd_udma_drv.h
new file mode 100644
index 00000000..c8028f79
--- /dev/null
+++ b/include/drv/wd_udma_drv.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/* Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved. */
+
+#ifndef __WD_UDMA_DRV_H
+#define __WD_UDMA_DRV_H
+
+#include <asm/types.h>
+
+#include "../wd_udma.h"
+#include "../wd_util.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* udma message format */
+struct wd_udma_msg {
+ struct wd_udma_req req;
+ struct wd_data_addr *src;
+ struct wd_data_addr *dst;
+ int addr_num;
+ int value;
+ enum wd_udma_op_type op_type;
+ __u32 tag; /* User-defined request identifier */
+ __u8 result; /* alg op error code */
+};
+
+struct wd_udma_msg *wd_udma_get_msg(__u32 idx, __u32 tag);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __WD_UDMA_DRV_H */
diff --git a/include/wd_alg.h b/include/wd_alg.h
index aba855d6..441b3bef 100644
--- a/include/wd_alg.h
+++ b/include/wd_alg.h
@@ -204,11 +204,13 @@ void hisi_sec2_probe(void);
void hisi_hpre_probe(void);
void hisi_zip_probe(void);
void hisi_dae_probe(void);
+void hisi_udma_probe(void);
void hisi_sec2_remove(void);
void hisi_hpre_remove(void);
void hisi_zip_remove(void);
void hisi_dae_remove(void);
+void hisi_udma_remove(void);
#endif
diff --git a/include/wd_udma.h b/include/wd_udma.h
new file mode 100644
index 00000000..d8a7964e
--- /dev/null
+++ b/include/wd_udma.h
@@ -0,0 +1,124 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved.
+ */
+
+#ifndef __WD_UDMA_H
+#define __WD_UDMA_H
+
+#include <stdbool.h>
+
+#include "wd_alg_common.h"
+
+typedef void (*wd_udma_cb_t)(void *cb_param);
+
+/**
+ * wd_udma_op_type - Algorithm type of option.
+ */
+enum wd_udma_op_type {
+ WD_UDMA_MEMCPY,
+ WD_UDMA_MEMSET,
+ WD_UDMA_OP_MAX
+};
+
+/**
+ * wd_udma_sess_setup - udma session setup information.
+ * @sched_param: Parameters of the scheduling policy,
+ * usually allocated according to struct sched_params.
+ */
+struct wd_udma_sess_setup {
+ void *sched_param;
+};
+
+/**
+ * wd_data_addr - addr information of UDMA.
+ * @addr: Indicates the start address of the operation.
+ * @addr_size: Maximum size of the addr, in bytes.
+ * @count: Number of bytes to be set.
+ */
+struct wd_data_addr {
+ void *addr;
+ size_t addr_size;
+ size_t data_size;
+};
+
+/**
+ * wd_udma_req - udma operation request.
+ * @src: pointer to input address.
+ * @dst: pointer to output address, for WD_UDMA_MEMSET, only one of src and dst can be set.
+ * @addr_num: Number of address.
+ * @value: Value to be written for WD_UDMA_MEMSET.
+ * @op_type: udma operation type.
+ * @cb: Callback function.
+ * @cb_param: Parameters of the callback function.
+ * @state: operation result written back by the driver.
+ */
+struct wd_udma_req {
+ struct wd_data_addr *src;
+ struct wd_data_addr *dst;
+ int addr_num;
+ int value;
+ enum wd_udma_op_type op_type;
+ wd_udma_cb_t cb;
+ void *cb_param;
+ int status;
+};
+
+/**
+ * wd_udma_init() - A simplify interface to initializate ecc.
+ * To make the initializate simpler, ctx_params support set NULL.
+ * And then the function will set them as driver's default.
+ *
+ * @alg: The algorithm users want to use.
+ * @sched_type: The scheduling type users want to use.
+ * @task_type: Task types, including soft computing, hardware and hybrid computing.
+ * @ctx_params: The ctxs resources users want to use. Include per operation
+ * type ctx numbers and business process run numa.
+ *
+ * Return 0 if succeed and others if fail.
+ */
+int wd_udma_init(const char *alg, __u32 sched_type,
+ int task_type, struct wd_ctx_params *ctx_params);
+
+/**
+ * wd_udma_uninit() - Uninitialise ctx configuration and scheduler.
+ */
+void wd_udma_uninit(void);
+
+/**
+ * wd_udma_alloc_sess() - Allocate a wd udma session.
+ * @setup: Parameters to setup this session.
+ *
+ * Return 0 if failed.
+ */
+handle_t wd_udma_alloc_sess(struct wd_udma_sess_setup *setup);
+
+/**
+ * wd_udma_free_sess() - Free a wd udma session.
+ * @ sess: The sess to be freed.
+ */
+void wd_udma_free_sess(handle_t sess);
+
+/**
+ * wd_do_udma_sync() - Send a sync udma request.
+ * @h_sess: The session which request will be sent to.
+ * @req: Request.
+ */
+int wd_do_udma_sync(handle_t h_sess, struct wd_udma_req *req);
+
+/**
+ * wd_do_udma_async() - Send an async udma request.
+ * @sess: The session which request will be sent to.
+ * @req: Request.
+ */
+int wd_do_udma_async(handle_t h_sess, struct wd_udma_req *req);
+
+/**
+ * wd_udma_poll() - Poll finished request.
+ *
+ * This function will call poll_policy function which is registered to wd udma
+ * by user.
+ */
+int wd_udma_poll(__u32 expt, __u32 *count);
+
+#endif /* __WD_UDMA_H */
diff --git a/include/wd_util.h b/include/wd_util.h
index 9e9d4e35..bbb18a7c 100644
--- a/include/wd_util.h
+++ b/include/wd_util.h
@@ -42,6 +42,7 @@ enum wd_type {
WD_DH_TYPE,
WD_ECC_TYPE,
WD_AGG_TYPE,
+ WD_UDMA_TYPE,
WD_TYPE_MAX,
};
diff --git a/libwd_dae.map b/libwd_dae.map
index 4c51b856..6597ff98 100644
--- a/libwd_dae.map
+++ b/libwd_dae.map
@@ -1,4 +1,4 @@
-UADK_CRYPTO_2.0 {
+UADK_DAE_2.0 {
global:
wd_agg_alloc_sess;
wd_agg_free_sess;
@@ -17,5 +17,18 @@ global:
wd_sched_rr_instance;
wd_sched_rr_alloc;
wd_sched_rr_release;
+
+ wd_udma_alloc_sess;
+ wd_udma_free_sess;
+ wd_udma_init;
+ wd_udma_uninit;
+ wd_do_udma_sync;
+ wd_do_udma_async;
+ wd_udma_poll;
+ wd_udma_get_msg;
+
+ wd_sched_rr_instance;
+ wd_sched_rr_alloc;
+ wd_sched_rr_release;
local: *;
};
diff --git a/wd_udma.c b/wd_udma.c
new file mode 100644
index 00000000..7675df30
--- /dev/null
+++ b/wd_udma.c
@@ -0,0 +1,511 @@
+// SPDX-License-Identifier: Apache-2.0
+/*
+ * Copyright 2025 Huawei Technologies Co.,Ltd. All rights reserved.
+ */
+
+#include <stdlib.h>
+#include <pthread.h>
+#include <limits.h>
+#include "include/drv/wd_udma_drv.h"
+#include "wd_udma.h"
+
+struct wd_udma_sess {
+ const char *alg_name;
+ wd_dev_mask_t *dev_mask;
+ void *priv;
+ void *sched_key;
+};
+
+static struct wd_udma_setting {
+ enum wd_status status;
+ struct wd_ctx_config_internal config;
+ struct wd_sched sched;
+ struct wd_async_msg_pool pool;
+ struct wd_alg_driver *driver;
+ void *dlhandle;
+ void *dlh_list;
+} wd_udma_setting;
+
+static struct wd_init_attrs wd_udma_init_attrs;
+
+static void wd_udma_close_driver(void)
+{
+#ifndef WD_STATIC_DRV
+ wd_dlclose_drv(wd_udma_setting.dlh_list);
+ wd_udma_setting.dlh_list = NULL;
+#else
+ wd_release_drv(wd_udma_setting.driver);
+ hisi_udma_remove();
+#endif
+}
+
+static int wd_udma_open_driver(void)
+{
+#ifndef WD_STATIC_DRV
+ /*
+ * Driver lib file path could set by env param.
+ * then open tham by wd_dlopen_drv()
+ * use NULL means dynamic query path
+ */
+ wd_udma_setting.dlh_list = wd_dlopen_drv(NULL);
+ if (!wd_udma_setting.dlh_list) {
+ WD_ERR("fail to open driver lib files.\n");
+ return -WD_EINVAL;
+ }
+#else
+ hisi_udma_probe();
+#endif
+ return WD_SUCCESS;
+}
+
+void wd_udma_free_sess(handle_t sess)
+{
+ struct wd_udma_sess *sess_t = (struct wd_udma_sess *)sess;
+
+ if (!sess_t) {
+ WD_ERR("invalid: free udma sess param NULL!\n");
+ return;
+ }
+
+ if (sess_t->sched_key)
+ free(sess_t->sched_key);
+ free(sess_t);
+}
+
+handle_t wd_udma_alloc_sess(struct wd_udma_sess_setup *setup)
+{
+ struct wd_udma_sess *sess;
+
+ if (!setup) {
+ WD_ERR("invalid: alloc udma sess setup NULL!\n");
+ return (handle_t)0;
+ }
+
+ sess = calloc(1, sizeof(struct wd_udma_sess));
+ if (!sess)
+ return (handle_t)0;
+
+ sess->alg_name = "udma";
+ /* Some simple scheduler don't need scheduling parameters */
+ sess->sched_key = (void *)wd_udma_setting.sched.sched_init(
+ wd_udma_setting.sched.h_sched_ctx, setup->sched_param);
+ if (WD_IS_ERR(sess->sched_key)) {
+ WD_ERR("failed to init session schedule key!\n");
+ goto free_sess;
+ }
+
+ return (handle_t)sess;
+
+free_sess:
+ free(sess);
+ return (handle_t)0;
+}
+
+static int wd_udma_addr_check(struct wd_data_addr *data_addr)
+{
+ if (unlikely(!data_addr->addr)) {
+ WD_ERR("invalid: udma addr is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(!data_addr->data_size ||
+ data_addr->data_size > data_addr->addr_size)) {
+ WD_ERR("invalid: udma size is error, data_size %lu, addr_size is %lu!\n",
+ data_addr->data_size, data_addr->addr_size);
+ return -WD_EINVAL;
+ }
+
+ return WD_SUCCESS;
+}
+
+static int wd_udma_param_check(struct wd_udma_sess *sess,
+ struct wd_udma_req *req)
+{
+ struct wd_data_addr *src, *dst;
+ int i, ret;
+
+ if (unlikely(!sess || !req)) {
+ WD_ERR("invalid: input param NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(req->addr_num <= 0)) {
+ WD_ERR("invalid: addr num is error %d!\n", req->addr_num);
+ return -WD_EINVAL;
+ }
+
+ src = req->src;
+ dst = req->dst;
+ if (unlikely(req->op_type >= WD_UDMA_OP_MAX)) {
+ WD_ERR("invalid: op_type is error %u!\n", req->op_type);
+ return -WD_EINVAL;
+ } else if (unlikely(req->op_type == WD_UDMA_MEMCPY && (!src || !dst))) {
+ WD_ERR("invalid: memcpy src or dst is NULL!\n");
+ return -WD_EINVAL;
+ } else if (unlikely(req->op_type == WD_UDMA_MEMSET &&
+ ((!src && !dst) || (src && dst)))) {
+ WD_ERR("invalid: memset src and dst is error!\n");
+ return -WD_EINVAL;
+ }
+
+ if (req->op_type == WD_UDMA_MEMSET)
+ dst = !req->src ? req->dst : req->src;
+
+ for (i = 0; i < req->addr_num; i++) {
+ if (req->op_type == WD_UDMA_MEMCPY) {
+ ret = wd_udma_addr_check(&src[i]);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: udma memcpy src addr is error!\n");
+ return -WD_EINVAL;
+ }
+
+ ret = wd_udma_addr_check(&dst[i]);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: udma memcpy dst addr is error!\n");
+ return -WD_EINVAL;
+ }
+
+ if (unlikely(dst[i].data_size != src[i].data_size)) {
+ WD_ERR("invalid: udma memcpy data_size is error!\n"
+ "src %lu, dst %lu!\n",
+ dst[i].data_size, src[i].data_size);
+ return -WD_EINVAL;
+ }
+ } else {
+ ret = wd_udma_addr_check(&dst[i]);
+ if (unlikely(ret)) {
+ WD_ERR("invalid: udma memset addr is error!\n");
+ return -WD_EINVAL;
+ }
+ }
+ }
+
+ return WD_SUCCESS;
+}
+
+static void fill_udma_msg(struct wd_udma_msg *msg, struct wd_udma_req *req)
+{
+ msg->result = WD_EINVAL;
+
+ memcpy(&msg->req, req, sizeof(*req));
+ msg->op_type = req->op_type;
+ msg->addr_num = req->addr_num;
+ msg->value = req->value;
+ if (req->op_type == WD_UDMA_MEMSET) {
+ msg->dst = !req->src ? req->dst : req->src;
+ } else {
+ msg->src = req->src;
+ msg->dst = req->dst;
+ }
+}
+
+int wd_do_udma_sync(handle_t h_sess, struct wd_udma_req *req)
+{
+ struct wd_ctx_config_internal *config = &wd_udma_setting.config;
+ handle_t h_sched_ctx = wd_udma_setting.sched.h_sched_ctx;
+ struct wd_udma_sess *sess_t = (struct wd_udma_sess *)h_sess;
+ struct wd_msg_handle msg_handle;
+ struct wd_ctx_internal *ctx;
+ struct wd_udma_msg msg = {0};
+ __u32 idx;
+ int ret;
+
+ ret = wd_udma_param_check(sess_t, req);
+ if (unlikely(ret))
+ return ret;
+
+ idx = wd_udma_setting.sched.pick_next_ctx(h_sched_ctx,
+ sess_t->sched_key,
+ CTX_MODE_SYNC);
+ ret = wd_check_ctx(config, CTX_MODE_SYNC, idx);
+ if (unlikely(ret))
+ return ret;
+
+ wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
+ ctx = config->ctxs + idx;
+
+ fill_udma_msg(&msg, req);
+
+ msg_handle.send = wd_udma_setting.driver->send;
+ msg_handle.recv = wd_udma_setting.driver->recv;
+ pthread_spin_lock(&ctx->lock);
+ ret = wd_handle_msg_sync(wd_udma_setting.driver, &msg_handle, ctx->ctx,
+ &msg, NULL, wd_udma_setting.config.epoll_en);
+ pthread_spin_unlock(&ctx->lock);
+ if (unlikely(ret))
+ return ret;
+
+ req->status = msg.result;
+
+ return GET_NEGATIVE(msg.result);
+}
+
+int wd_do_udma_async(handle_t sess, struct wd_udma_req *req)
+{
+ struct wd_ctx_config_internal *config = &wd_udma_setting.config;
+ handle_t h_sched_ctx = wd_udma_setting.sched.h_sched_ctx;
+ struct wd_udma_sess *sess_t = (struct wd_udma_sess *)sess;
+ struct wd_udma_msg *msg = NULL;
+ struct wd_ctx_internal *ctx;
+ int ret, mid;
+ __u32 idx;
+
+ ret = wd_udma_param_check(sess_t, req);
+ if (unlikely(ret))
+ return ret;
+
+ if (unlikely(!req->cb)) {
+ WD_ERR("invalid: udma input req cb is NULL!\n");
+ return -WD_EINVAL;
+ }
+
+ idx = wd_udma_setting.sched.pick_next_ctx(h_sched_ctx,
+ sess_t->sched_key,
+ CTX_MODE_ASYNC);
+ ret = wd_check_ctx(config, CTX_MODE_ASYNC, idx);
+ if (unlikely(ret))
+ return ret;
+ ctx = config->ctxs + idx;
+
+ mid = wd_get_msg_from_pool(&wd_udma_setting.pool, idx, (void **)&msg);
+ if (unlikely(mid < 0)) {
+ WD_ERR("failed to get msg from pool!\n");
+ return mid;
+ }
+
+ fill_udma_msg(msg, req);
+ msg->tag = mid;
+
+ ret = wd_alg_driver_send(wd_udma_setting.driver, ctx->ctx, msg);
+ if (unlikely(ret)) {
+ if (ret != -WD_EBUSY)
+ WD_ERR("failed to send udma BD, hw is err!\n");
+
+ goto fail_with_msg;
+ }
+
+ wd_dfx_msg_cnt(config, WD_CTX_CNT_NUM, idx);
+
+ return WD_SUCCESS;
+
+fail_with_msg:
+ wd_put_msg_to_pool(&wd_udma_setting.pool, idx, mid);
+
+ return ret;
+}
+
+static int wd_udma_poll_ctx(__u32 idx, __u32 expt, __u32 *count)
+{
+ struct wd_ctx_config_internal *config = &wd_udma_setting.config;
+ struct wd_udma_msg rcv_msg = {0};
+ struct wd_ctx_internal *ctx;
+ struct wd_udma_req *req;
+ struct wd_udma_msg *msg;
+ __u32 rcv_cnt = 0;
+ __u32 tmp = expt;
+ int ret;
+
+ *count = 0;
+
+ ret = wd_check_ctx(config, CTX_MODE_ASYNC, idx);
+ if (ret)
+ return ret;
+
+ ctx = config->ctxs + idx;
+
+ do {
+ ret = wd_alg_driver_recv(wd_udma_setting.driver, ctx->ctx, &rcv_msg);
+ if (ret == -WD_EAGAIN) {
+ return ret;
+ } else if (unlikely(ret)) {
+ WD_ERR("failed to async recv, ret = %d!\n", ret);
+ *count = rcv_cnt;
+ wd_put_msg_to_pool(&wd_udma_setting.pool, idx,
+ rcv_msg.tag);
+ return ret;
+ }
+ rcv_cnt++;
+ msg = wd_find_msg_in_pool(&wd_udma_setting.pool, idx, rcv_msg.tag);
+ if (!msg) {
+ WD_ERR("failed to find udma msg!\n");
+ return -WD_EINVAL;
+ }
+
+ msg->req.status = rcv_msg.result;
+ req = &msg->req;
+ req->cb(req);
+ wd_put_msg_to_pool(&wd_udma_setting.pool, idx, rcv_msg.tag);
+ *count = rcv_cnt;
+ } while (--tmp);
+
+ return ret;
+}
+
+int wd_udma_poll(__u32 expt, __u32 *count)
+{
+ handle_t h_sched_ctx = wd_udma_setting.sched.h_sched_ctx;
+
+ if (unlikely(!count || !expt)) {
+ WD_ERR("invalid: udma poll count is NULL or expt is 0!\n");
+ return -WD_EINVAL;
+ }
+
+ return wd_udma_setting.sched.poll_policy(h_sched_ctx, expt, count);
+}
+
+static void wd_udma_clear_status(void)
+{
+ wd_alg_clear_init(&wd_udma_setting.status);
+}
+
+static void wd_udma_alg_uninit(void)
+{
+ /* Uninit async request pool */
+ wd_uninit_async_request_pool(&wd_udma_setting.pool);
+ /* Unset config, sched, driver */
+ wd_clear_sched(&wd_udma_setting.sched);
+ wd_alg_uninit_driver(&wd_udma_setting.config, wd_udma_setting.driver);
+}
+
+void wd_udma_uninit(void)
+{
+ enum wd_status status;
+
+ wd_alg_get_init(&wd_udma_setting.status, &status);
+ if (status == WD_UNINIT)
+ return;
+
+ wd_udma_alg_uninit();
+ wd_alg_attrs_uninit(&wd_udma_init_attrs);
+ wd_alg_drv_unbind(wd_udma_setting.driver);
+ wd_udma_close_driver();
+ wd_alg_clear_init(&wd_udma_setting.status);
+}
+
+static int wd_udma_alg_init(struct wd_ctx_config *config, struct wd_sched *sched)
+{
+ int ret;
+
+ ret = wd_set_epoll_en("WD_UDMA_EPOLL_EN", &wd_udma_setting.config.epoll_en);
+ if (ret < 0)
+ return ret;
+
+ ret = wd_init_ctx_config(&wd_udma_setting.config, config);
+ if (ret < 0)
+ return ret;
+
+ ret = wd_init_sched(&wd_udma_setting.sched, sched);
+ if (ret < 0)
+ goto out_clear_ctx_config;
+
+ /* Allocate async pool for every ctx */
+ ret = wd_init_async_request_pool(&wd_udma_setting.pool, config, WD_POOL_MAX_ENTRIES,
+ sizeof(struct wd_udma_msg));
+ if (ret < 0)
+ goto out_clear_sched;
+
+ ret = wd_alg_init_driver(&wd_udma_setting.config, wd_udma_setting.driver);
+ if (ret)
+ goto out_clear_pool;
+
+ return WD_SUCCESS;
+
+out_clear_pool:
+ wd_uninit_async_request_pool(&wd_udma_setting.pool);
+out_clear_sched:
+ wd_clear_sched(&wd_udma_setting.sched);
+out_clear_ctx_config:
+ wd_clear_ctx_config(&wd_udma_setting.config);
+ return ret;
+}
+
+int wd_udma_init(const char *alg, __u32 sched_type, int task_type,
+ struct wd_ctx_params *ctx_params)
+{
+ struct wd_ctx_nums udma_ctx_num[WD_UDMA_OP_MAX] = {0};
+ struct wd_ctx_params udma_ctx_params = {0};
+ int state, ret = -WD_EINVAL;
+
+ pthread_atfork(NULL, NULL, wd_udma_clear_status);
+
+ state = wd_alg_try_init(&wd_udma_setting.status);
+ if (state)
+ return state;
+
+ if (!alg || sched_type >= SCHED_POLICY_BUTT ||
+ task_type < 0 || task_type >= TASK_MAX_TYPE) {
+ WD_ERR("invalid: input param is wrong!\n");
+ goto out_clear_init;
+ }
+
+ if (strcmp(alg, "udma")) {
+ WD_ERR("invalid: the alg %s not support!\n", alg);
+ goto out_clear_init;
+ }
+
+ state = wd_udma_open_driver();
+ if (state)
+ goto out_clear_init;
+
+ while (ret) {
+ memset(&wd_udma_setting.config, 0, sizeof(struct wd_ctx_config_internal));
+
+ /* Get alg driver and dev name */
+ wd_udma_setting.driver = wd_alg_drv_bind(task_type, alg);
+ if (!wd_udma_setting.driver) {
+ WD_ERR("fail to bind a valid driver.\n");
+ ret = -WD_EINVAL;
+ goto out_dlopen;
+ }
+
+ udma_ctx_params.ctx_set_num = udma_ctx_num;
+ ret = wd_ctx_param_init(&udma_ctx_params, ctx_params,
+ wd_udma_setting.driver, WD_UDMA_TYPE, WD_UDMA_OP_MAX);
+ if (ret) {
+ if (ret == -WD_EAGAIN) {
+ wd_disable_drv(wd_udma_setting.driver);
+ wd_alg_drv_unbind(wd_udma_setting.driver);
+ continue;
+ }
+ goto out_driver;
+ }
+
+ wd_udma_init_attrs.alg = alg;
+ wd_udma_init_attrs.sched_type = sched_type;
+ wd_udma_init_attrs.driver = wd_udma_setting.driver;
+ wd_udma_init_attrs.ctx_params = &udma_ctx_params;
+ wd_udma_init_attrs.alg_init = wd_udma_alg_init;
+ wd_udma_init_attrs.alg_poll_ctx = wd_udma_poll_ctx;
+ ret = wd_alg_attrs_init(&wd_udma_init_attrs);
+ if (ret) {
+ if (ret == -WD_ENODEV) {
+ wd_disable_drv(wd_udma_setting.driver);
+ wd_alg_drv_unbind(wd_udma_setting.driver);
+ wd_ctx_param_uninit(&udma_ctx_params);
+ continue;
+ }
+ WD_ERR("failed to init alg attrs!\n");
+ goto out_params_uninit;
+ }
+ }
+
+ wd_alg_set_init(&wd_udma_setting.status);
+ wd_ctx_param_uninit(&udma_ctx_params);
+
+ return WD_SUCCESS;
+
+out_params_uninit:
+ wd_ctx_param_uninit(&udma_ctx_params);
+out_driver:
+ wd_alg_drv_unbind(wd_udma_setting.driver);
+out_dlopen:
+ wd_udma_close_driver();
+out_clear_init:
+ wd_alg_clear_init(&wd_udma_setting.status);
+ return ret;
+}
+
+struct wd_udma_msg *wd_udma_get_msg(__u32 idx, __u32 tag)
+{
+ return wd_find_msg_in_pool(&wd_udma_setting.pool, idx, tag);
+}
diff --git a/wd_util.c b/wd_util.c
index f1b27bf8..38d2d375 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -63,6 +63,7 @@ static const char *wd_env_name[WD_TYPE_MAX] = {
"WD_DH_CTX_NUM",
"WD_ECC_CTX_NUM",
"WD_AGG_CTX_NUM",
+ "WD_UDMA_CTX_NUM",
};
struct async_task {
@@ -107,6 +108,7 @@ static struct acc_alg_item alg_options[] = {
{"deflate", "deflate"},
{"lz77_zstd", "lz77_zstd"},
{"hashagg", "hashagg"},
+ {"udma", "udma"},
{"rsa", "rsa"},
{"dh", "dh"},
--
2.33.0
1
0
*** BLURB HERE ***
Chenghai Huang (9):
uadk: fix definition coding standard issues
uadk: add or remove some store buf condition judgments
uadk: add new alg called lz77_only
uadk: modify the condition for copying repcode
uadk: remove redundant checks on bit read results
uadk_tool: modify unrecv num in async benchmark test
uadk_tool: add lz77_only alg in zip benchmark test
uadk_tool: add lz4 alg in zip benchmark test
uadk: fix a sgl pool memery issue in lz77_only
Longfang Liu (1):
uadk: resolve some code issues
Qi Tao (1):
uadk_tool: add aead algorithm
Qinxin Xia (5):
uadk: hisi_comp - abstract get sgl function and general deflate
functions
uadk: hisi_comp - support the new algorithm 'lz4'
uadk: wd_comp - support the new algorithm 'lz4'
uadk: hisi_comp: reduce some invalid spaces.
uadk: rectify the incorrect boundary value judgment of LZ4
Weili Qian (1):
uadk: support data move
Wenkai Lin (9):
uadk: support hashjoin and gather algorithm
uadk: fix for build and probe index check
uadk: fix for check_key_cols_info
uadk: reduce repeated dae code
uadk: modify print info for wd_gather_get_batch_rowsize
uadk: fix for rehash invalid size
uadk: optimize for rehash performance
uadk: fix for the segment fault in gather param check
uadk: fix for the hashjoin task runtime error
Zhushuai Yin (6):
uadk: Add max and min operations at the hash algorithm layer
uadk: hash agg adapter drv parameter
uadk:Add max,min,and rehash implementations
uadk:zip algorithm increases buffer len interception
uadk: Fix the problem of failing to intercept the new comp stream
scene
uadk:fix dh prov segmentation issue
Makefile.am | 31 +-
drv/hisi_comp.c | 565 +++++--
drv/hisi_comp_huf.c | 11 +-
drv/hisi_dae.c | 826 +++-------
drv/hisi_dae.h | 229 +++
drv/hisi_dae_common.c | 387 +++++
drv/hisi_dae_join_gather.c | 1040 ++++++++++++
drv/hisi_qm_udrv.h | 3 +-
drv/hisi_udma.c | 566 +++++++
include/drv/wd_agg_drv.h | 10 +-
include/drv/wd_join_gather_drv.h | 52 +
include/drv/wd_udma_drv.h | 34 +
include/wd_agg.h | 9 +-
include/wd_alg.h | 4 +
include/wd_comp.h | 2 +
include/wd_dae.h | 12 +
include/wd_join_gather.h | 352 +++++
include/wd_udma.h | 124 ++
include/wd_util.h | 2 +
libwd_dae.map | 34 +-
uadk_tool/benchmark/sec_uadk_benchmark.c | 34 +
uadk_tool/benchmark/sec_wd_benchmark.c | 34 +
uadk_tool/benchmark/uadk_benchmark.c | 14 +
uadk_tool/benchmark/uadk_benchmark.h | 4 +
uadk_tool/benchmark/zip_uadk_benchmark.c | 24 +-
v1/drv/hisi_zip_huf.c | 11 +-
v1/drv/hisi_zip_udrv.c | 2 +-
wd.c | 2 +-
wd_agg.c | 76 +-
wd_comp.c | 56 +-
wd_join_gather.c | 1823 ++++++++++++++++++++++
wd_sched.c | 3 +-
wd_udma.c | 511 ++++++
wd_util.c | 34 +-
34 files changed, 6125 insertions(+), 796 deletions(-)
create mode 100644 drv/hisi_dae.h
create mode 100644 drv/hisi_dae_common.c
create mode 100644 drv/hisi_dae_join_gather.c
create mode 100644 drv/hisi_udma.c
create mode 100644 include/drv/wd_join_gather_drv.h
create mode 100644 include/drv/wd_udma_drv.h
create mode 100644 include/wd_join_gather.h
create mode 100644 include/wd_udma.h
create mode 100644 wd_join_gather.c
create mode 100644 wd_udma.c
--
2.33.0
1
32
From: JiangShui Yang <yangjiangshui(a)h-partners.com>
Chenghai Huang (1):
uadk_provider: add reset for part of ctx after final
Qi Tao (1):
uadk_provider/rsa: bugfix for rsa digest interface
Weili Qian (3):
uadk_engine/sm2: set the default user id
uadk_provider/sm2: delete duplicate applications sess
uadk_engine/digest: small packet directly uses soft computing
Wenkai Lin (2):
uadk_engine: optimize for sec cipher and digest init
uadk_engine/aead: fix for set key problem
Zhushuai Yin (3):
uadk_provider:Improved SM3 hmac performance
uadk_engine:Fix DH algorithm shared key comparison failure
uadk_provider/sm2:fix the issue of SM2 authentication failure
lizhi (2):
uadk_provider: clean up unused functions
uadk_prov: fix a cleancode issue
src/uadk_aead.c | 65 ++++++++++----------
src/uadk_async.c | 5 ++
src/uadk_async.h | 1 +
src/uadk_cipher.c | 98 +++++++++++++-----------------
src/uadk_dh.c | 8 ++-
src/uadk_digest.c | 120 ++++++++++++++++++-------------------
src/uadk_prov_der_writer.c | 69 ---------------------
src/uadk_prov_der_writer.h | 4 --
src/uadk_prov_digest.c | 29 ++++++---
src/uadk_prov_ffc.c | 3 +-
src/uadk_prov_hmac.c | 18 ++++--
src/uadk_prov_rsa.c | 107 +++++++++++++++++++++------------
src/uadk_prov_sm2.c | 108 +++++++++++++++++----------------
src/uadk_sm2.c | 95 +++++++++++++++--------------
14 files changed, 356 insertions(+), 374 deletions(-)
--
2.43.0
1
12
您好!
sig-AccLib 邀请您参加 2025-08-06 11:00 召开的Zoom会议
会议主题:2025/8/6 AccLIb SIG 双周例会 11:00 - 12:00
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/87414340535?pwd=sXcaBaZEpTqpKISlBDzkMyMwMfZKAh.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-08-06 11:00,
The subject of the conference is 2025/8/6 AccLIb SIG 双周例会 11:00 - 12:00
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/87414340535?pwd=sXcaBaZEpTqpKISlBDzkMyMwMfZKAh.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
doc
https://docs.qq.com/doc/DRVBtbVh6TkdaTFVB
memcpy
++ ./uadk_tool/uadk_tool benchmark --alg zlib --mode sva --opt 0 --sync --pktlen 1024
algname: length: perf: iops: CPU_rate:
zlib 1024Bytes 336851.00KiB/s 336.9Kops 293.67%
user pointer // --user
++ ./uadk_tool/uadk_tool benchmark --alg zlib --mode sva --user --opt 0 --sync --pktlen 1024
algname: length: perf: iops: CPU_rate:
zlib 1024Bytes 522916.00KiB/s 522.9Kops 299.67%
sgl // --sgl
++ ./uadk_tool/uadk_tool benchmark --alg zlib --mode sva --sgl --opt 0 --sync --pktlen 1024
algname: length: perf: iops: CPU_rate:
zlib 1024Bytes 415577.00KiB/s 415.6Kops 299.67%
Zhangfei Gao (7):
uadk: remove nosva limitation
uadk: add wd_reserve_mem & wd_is_noiommu for nosva
uadk: add blkpool
uadk: ctxs call wd_blkpool_new at init and delete blkpool at uninit
wd_comp: add wd_comp_setup_blkpool
wd_comp: support nosva case
uadk_tool: support nosva test
Makefile.am | 1 +
drv/hisi_comp.c | 98 ++-
drv/hisi_qm_udrv.c | 14 +-
drv/hisi_qm_udrv.h | 3 +-
drv/hisi_sec.c | 8 +-
include/drv/wd_comp_drv.h | 7 +
include/uacce.h | 6 +-
include/wd.h | 16 +
include/wd_alg_common.h | 9 +
include/wd_bmm.h | 66 ++
include/wd_comp.h | 2 +
libwd.map | 10 +
libwd_comp.map | 1 +
uadk_tool/benchmark/uadk_benchmark.c | 8 +
uadk_tool/benchmark/uadk_benchmark.h | 2 +
uadk_tool/benchmark/zip_uadk_benchmark.c | 146 ++++-
wd.c | 34 +-
wd_alg.c | 44 +-
wd_bmm.c | 739 +++++++++++++++++++++++
wd_comp.c | 84 +++
wd_util.c | 13 +-
21 files changed, 1213 insertions(+), 98 deletions(-)
create mode 100644 include/wd_bmm.h
create mode 100644 wd_bmm.c
--
2.25.1
1
7
您好!
sig-AccLib 邀请您参加 2025-07-23 11:00 召开的Zoom会议
会议主题:【2025/7/23 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/87687572460?pwd=vbbd91ASP0NR3Taa6E9bawp14QR0Qh.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-07-23 11:00,
The subject of the conference is 【2025/7/23 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/87687572460?pwd=vbbd91ASP0NR3Taa6E9bawp14QR0Qh.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
您好!
sig-AccLib 邀请您参加 2025-07-09 11:00 召开的Zoom会议
会议主题:【2025/7/9 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/87048823607?pwd=j9jXyW5hh2ztCnoasdV2LhPzSJRiiL.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-07-09 11:00,
The subject of the conference is 【2025/7/9 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/87048823607?pwd=j9jXyW5hh2ztCnoasdV2LhPzSJRiiL.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
您好!
sig-AccLib 邀请您参加 2025-06-25 11:00 召开的Zoom会议
会议主题:【2025/6/25 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/89107269981?pwd=fG5l7sJqKZ2oa8MLBvKEM95gjCeYzU.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-06-25 11:00,
The subject of the conference is 【2025/6/25 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/89107269981?pwd=fG5l7sJqKZ2oa8MLBvKEM95gjCeYzU.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
From: Chenghai Huang <huangchenghai2(a)huawei.com>
In the destructor, it need to check whether zlibwrapper has been
initialized, otherwise it will cause double free.
Signed-off-by: Chenghai Huang <huangchenghai2(a)huawei.com>
---
wd_zlibwrapper.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c
index a08db320..ea1667bb 100644
--- a/wd_zlibwrapper.c
+++ b/wd_zlibwrapper.c
@@ -299,5 +299,6 @@ int wd_inflate_end(z_streamp strm)
__attribute__ ((destructor)) static void wd_zlibwrapper_destory(void)
{
- wd_zlib_uadk_uninit();
+ if (zlib_status == WD_ZLIB_INIT)
+ wd_zlib_uadk_uninit();
}
--
2.33.0
1
0
From: Chenghai Huang <huangchenghai2(a)huawei.com>
---
wd_zlibwrapper.c | 47 +++++++++++++++++++++++++----------------------
1 file changed, 25 insertions(+), 22 deletions(-)
diff --git a/wd_zlibwrapper.c b/wd_zlibwrapper.c
index a08db32..7411455 100644
--- a/wd_zlibwrapper.c
+++ b/wd_zlibwrapper.c
@@ -24,6 +24,18 @@ enum uadk_init_status {
WD_ZLIB_INIT,
};
+enum alg_win_bits {
+ DEFLATE_MIN_WBITS = -15,
+ DEFLATE_4K_WBITS = 12,
+ DEFLATE_MAX_WBITS = -8,
+ ZLIB_MIN_WBITS = 8,
+ ZLIB_4K_WBITS = 12,
+ ZLIB_MAX_WBITS = 15,
+ GZIP_MIN_WBITS = 24,
+ GZIP_4K_WBITS = 28,
+ GZIP_MAX_WBITS = 31,
+};
+
static pthread_mutex_t wd_zlib_mutex = PTHREAD_MUTEX_INITIALIZER;
static int zlib_status;
@@ -88,28 +100,19 @@ static void wd_zlib_uadk_uninit(void)
static int wd_zlib_analy_alg(int windowbits, int *alg, int *windowsize)
{
- static const int ZLIB_MAX_WBITS = 15;
- static const int ZLIB_MIN_WBITS = 8;
- static const int GZIP_MAX_WBITS = 31;
- static const int GZIP_MIN_WBITS = 24;
- static const int DEFLATE_MAX_WBITS = -8;
- static const int DEFLATE_MIN_WBITS = -15;
- static const int WBINS_ZLIB_4K = 12;
- static const int WBINS_GZIP_4K = 28;
- static const int WBINS_DEFLATE_4K = 12;
-
- if ((windowbits >= ZLIB_MIN_WBITS) && (windowbits <= ZLIB_MAX_WBITS)) {
- *alg = WD_ZLIB;
- *windowsize = max(windowbits - WBINS_ZLIB_4K, WD_COMP_WS_4K);
- } else if ((windowbits >= GZIP_MIN_WBITS) && (windowbits <= GZIP_MAX_WBITS)) {
- *alg = WD_GZIP;
- *windowsize = max(windowbits - WBINS_GZIP_4K, WD_COMP_WS_4K);
- } else if ((windowbits >= DEFLATE_MIN_WBITS) && (windowbits <= DEFLATE_MAX_WBITS)) {
- *alg = WD_DEFLATE;
- windowbits = -windowbits;
- *windowsize = max(windowbits - WBINS_DEFLATE_4K, WD_COMP_WS_4K);
- } else {
- return Z_STREAM_ERROR;
+ switch (windowbits) {
+ case DEFLATE_MIN_WBITS ... DEFLATE_MAX_WBITS:
+ *alg = WD_DEFLATE;
+ windowbits = -windowbits;
+ *windowsize = max(windowbits - DEFLATE_4K_WBITS, WD_COMP_WS_4K);
+ case GZIP_MIN_WBITS ... GZIP_MAX_WBITS:
+ *alg = WD_GZIP;
+ *windowsize = max(windowbits - GZIP_4K_WBITS, WD_COMP_WS_4K);
+ case ZLIB_MIN_WBITS ... ZLIB_MAX_WBITS:
+ *alg = WD_ZLIB;
+ *windowsize = max(windowbits - ZLIB_4K_WBITS, WD_COMP_WS_4K);
+ default:
+ return Z_STREAM_ERROR;
}
*windowsize = *windowsize == WD_COMP_WS_24K ? WD_COMP_WS_32K : *windowsize;
--
2.33.0
1
0
13 Jun '25
From: Longfang Liu <liulongfang(a)huawei.com>
After removing the shared queue memory allocation interface, the UADK
test tools must also eliminate the shared memory functionality.
For individual memory reservations, the wd_reserve_memory interface
should be used. When allocating memory for multiple queues, each queue
should independently request its own reserved memory allocation.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 -----------------------
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 +++++++++---------
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +++++++-------
4 files changed, 300 insertions(+), 657 deletions(-)
diff --git a/v1/test/hisi_hpre_test/hpre_test_tools.c b/v1/test/hisi_hpre_test/hpre_test_tools.c
index 7f562f34..10a4ade9 100755
--- a/v1/test/hisi_hpre_test/hpre_test_tools.c
+++ b/v1/test/hisi_hpre_test/hpre_test_tools.c
@@ -644,317 +644,6 @@ int application_release_multiple_queue(char *dev, char *alg_type, unsigned int q
printf("application_release_multiple_queue test end!\n");
return 0;
}
-
-/***
-
-***/
-int hpre_dev_queue_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_node_queue_share(char *dev, unsigned int node, unsigned int share_node, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
- q.node_mask = node;
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- target_q.node_mask = node;
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on target q fail!\n");
- return 1;
- }
-
- ret = wd_share_reserved_memory(&q, &target_q);
-
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on share q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on share target q fail!\n");
- return 1;
- }
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_dev_queue_interact_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return ret;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- addr = wd_reserve_memory(&target_q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- //target_q
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
-/***
-
-***/
-int hpre_dev_queue_cross_proc_share(char *dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- pid_t pid;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size=0;
-
- pid = fork();
- if(pid < 0)
- {
- printf("Creation process failed, pid:%d\n",pid);
- return 1;
- }
- else if(pid == 0)
- {
- printf("child process:%d\n", pid);
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("request queue fail!\n");
- exit(1);
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("queue reserve memory fail!\n");
- exit(2);
- }
- printf("queue reserve memory success!\n");
- memset(addr, 0, memory_size);
- exit(0);
- }
- printf("parent process:%d\n", pid);
- pid_t wpid;
- int status = -1;
- wpid = waitpid(pid, &status, WUNTRACED | WCONTINUED);
- if( wpid < 0)
- {
- printf("exited, status=%d\n", WEXITSTATUS(status));
- return(status);
- }
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&target_q);
- wd_release_queue(&q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
/***
***/
@@ -1696,87 +1385,6 @@ int main(int arc, char *argv[])
return 1;
}
}
- else if(!strcmp(argv[1], "queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "node-queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示设备node
- argv[5] - 表示共享内存设备node
- argv[6] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- unsigned int node=0;
- node = strtoul(argv[4], NULL, 16);
- unsigned int share_node=0;
- share_node = strtoul(argv[5], NULL, 16);
- memory_size = strtoul(argv[6], NULL, 10);
-
- ret = hpre_node_queue_share(dev, node, share_node, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-interact-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //队列预留内存后作为共享的目标队列
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_interact_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-cross-proc-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示申请队列的预留内存大小
- ***/
- //跨进程进行队列共享
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- memory_size = strtoul(argv[4], NULL, 10);
- ret = hpre_dev_queue_cross_proc_share(dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
else if(!strcmp(argv[1], "mult-thread-queue"))
{
/***
diff --git a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
index 31637565..7a3be22c 100644
--- a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
+++ b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
@@ -23,96 +23,33 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
- } else { /* use sgl */
- sched->msgs[i].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
- sched->msgs[i].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i, data_fmt);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- } else { /* use sgl */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_sgl(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_sgl(pool, sched->msgs[i].data_out);
- }
- wd_sglpool_destroy(pool);
- }
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
@@ -124,14 +61,6 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
struct wd_sglpool_setup sp;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -145,12 +74,22 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
+ return 0;
+ }
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
+ goto out_with_queues;
+ }
+
+ qinfo = sched->qs[i].qinfo;
pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -162,15 +101,18 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
qinfo->br.iova_map = (void *)wd_blk_iova_map;
qinfo->br.iova_unmap = (void *)wd_blk_iova_unmap;
qinfo->br.usr = pool;
- } else { /* use sgl*/
- memset(&sp, 0, sizeof(sp));
- sp.buf_size = sched->msg_data_size / 10;
- sp.align_size = 64;
- sp.sge_num_in_sgl = 60;
- sp.buf_num_in_sgl = sp.sge_num_in_sgl;
- sp.sgl_num = 3 * sched->msg_cache_num;
- sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
-
+ }
+ } else { /* use sgl*/
+ memset(&sp, 0, sizeof(sp));
+ sp.buf_size = sched->msg_data_size / 10;
+ sp.align_size = 64;
+ sp.sge_num_in_sgl = 60;
+ sp.buf_num_in_sgl = sp.sge_num_in_sgl;
+ sp.sgl_num = 3 * sched->msg_cache_num;
+ sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
pool = wd_sglpool_create(&sched->qs[0], &sp);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -189,17 +131,132 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
+
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ } else { /* use sgl */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_sgl(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_sgl(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
+
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
+ qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
+ flags = qinfo->dev_flags;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ } else { /* use sgl */
+ sched->msgs[j].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
+ sched->msgs[j].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ }
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j, data_fmt);
+ }
+ }
+
+ return 0;
+
+err_with_stat:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched, data_fmt);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
{
@@ -211,57 +268,22 @@ int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
if (ret < 0)
return -EINVAL;
- qinfo = sched->qs[0].qinfo;
- flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
- }
- }
- }
-
sched->cl = sched->msg_cache_num;
ret = __init_cache(sched, data_fmt);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched, data_fmt);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched, data_fmt);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched, data_fmt);
}
static int __sync_send(struct wd_scheduler *sched)
@@ -350,4 +372,4 @@ int wd_sched_work(struct wd_scheduler *sched, int remained)
}
return sched->cl;
-}
\ No newline at end of file
+}
diff --git a/v1/test/test_mm/test_wd_mem.c b/v1/test/test_mm/test_wd_mem.c
index 09824b99..e2eec60e 100644
--- a/v1/test/test_mm/test_wd_mem.c
+++ b/v1/test/test_mm/test_wd_mem.c
@@ -208,10 +208,10 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo1.q, &rsa_q);
+ ret = wd_request_queue(&pdata->qinfo1.q);
if (ret) {
wd_release_queue(&rsa_q);
- MMT_PRT("Proc-%d, thrd-%d:share mem on rsa queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:rsa queue fail!\n",
pid, thread_id);
return NULL;
}
@@ -226,9 +226,9 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo2.q, &zlib_q);
+ ret = wd_request_queue(&pdata->qinfo2.q);
if (ret) {
- MMT_PRT("Proc-%d, thrd-%d:share mem on zlib queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:zlib queue fail!\n",
pid, thread_id);
goto fail_release;
diff --git a/v1/test/wd_sched.c b/v1/test/wd_sched.c
index f5e46699..ce1d2604 100644
--- a/v1/test/wd_sched.c
+++ b/v1/test/wd_sched.c
@@ -22,94 +22,40 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched)
{
- int ret, i, j;
+ struct wd_blkpool_setup mm_setup;
unsigned int flags = 0;
struct q_info *qinfo;
- struct wd_blkpool_setup mm_setup;
+ int ret, i, j;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -120,18 +66,29 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
sched->ss_region = malloc(sched->ss_region_size);
if (!sched->ss_region) {
WD_ERR("fail to alloc sched ss region mem!\n");
+ return -ENOMEM;
+ }
+ return 0;
+ }
+
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
- pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
+
+ qinfo = sched->qs[i].qinfo;
+ pool = wd_blkpool_create(&sched->qs[i], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
ret = -ENOMEM;
+ wd_release_queue(&sched->qs[i]);
goto out_with_queues;
}
qinfo->br.alloc = (void *)wd_alloc_blk;
@@ -144,79 +101,135 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
-int wd_sched_init(struct wd_scheduler *sched)
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched)
{
- int ret, j, k;
- unsigned int flags;
struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
- ret = wd_sched_preinit(sched);
- if (ret < 0)
- return -EINVAL;
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_alloc;
}
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j);
}
}
- sched->cl = sched->msg_cache_num;
+ return 0;
+
+err_with_alloc:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
+
+int wd_sched_init(struct wd_scheduler *sched)
+{
+ int ret;
+ ret = wd_sched_preinit(sched);
+ if (ret < 0)
+ return -EINVAL;
+
+ sched->cl = sched->msg_cache_num;
ret = __init_cache(sched);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched);
}
static int __sync_send(struct wd_scheduler *sched)
--
2.33.0
1
0
13 Jun '25
From: Longfang Liu <liulongfang(a)huawei.com>
After removing the shared queue memory allocation interface, the UADK
test tools must also eliminate the shared memory functionality.
For individual memory reservations, the wd_reserve_memory interface
should be used. When allocating memory for multiple queues, each queue
should independently request its own reserved memory allocation.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 -----------------------
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 +++++++++---------
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +++++++-------
4 files changed, 300 insertions(+), 657 deletions(-)
diff --git a/v1/test/hisi_hpre_test/hpre_test_tools.c b/v1/test/hisi_hpre_test/hpre_test_tools.c
index 7f562f34..10a4ade9 100755
--- a/v1/test/hisi_hpre_test/hpre_test_tools.c
+++ b/v1/test/hisi_hpre_test/hpre_test_tools.c
@@ -644,317 +644,6 @@ int application_release_multiple_queue(char *dev, char *alg_type, unsigned int q
printf("application_release_multiple_queue test end!\n");
return 0;
}
-
-/***
-
-***/
-int hpre_dev_queue_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_node_queue_share(char *dev, unsigned int node, unsigned int share_node, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
- q.node_mask = node;
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- target_q.node_mask = node;
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on target q fail!\n");
- return 1;
- }
-
- ret = wd_share_reserved_memory(&q, &target_q);
-
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on share q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on share target q fail!\n");
- return 1;
- }
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_dev_queue_interact_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return ret;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- addr = wd_reserve_memory(&target_q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- //target_q
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
-/***
-
-***/
-int hpre_dev_queue_cross_proc_share(char *dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- pid_t pid;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size=0;
-
- pid = fork();
- if(pid < 0)
- {
- printf("Creation process failed, pid:%d\n",pid);
- return 1;
- }
- else if(pid == 0)
- {
- printf("child process:%d\n", pid);
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("request queue fail!\n");
- exit(1);
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("queue reserve memory fail!\n");
- exit(2);
- }
- printf("queue reserve memory success!\n");
- memset(addr, 0, memory_size);
- exit(0);
- }
- printf("parent process:%d\n", pid);
- pid_t wpid;
- int status = -1;
- wpid = waitpid(pid, &status, WUNTRACED | WCONTINUED);
- if( wpid < 0)
- {
- printf("exited, status=%d\n", WEXITSTATUS(status));
- return(status);
- }
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&target_q);
- wd_release_queue(&q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
/***
***/
@@ -1696,87 +1385,6 @@ int main(int arc, char *argv[])
return 1;
}
}
- else if(!strcmp(argv[1], "queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "node-queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示设备node
- argv[5] - 表示共享内存设备node
- argv[6] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- unsigned int node=0;
- node = strtoul(argv[4], NULL, 16);
- unsigned int share_node=0;
- share_node = strtoul(argv[5], NULL, 16);
- memory_size = strtoul(argv[6], NULL, 10);
-
- ret = hpre_node_queue_share(dev, node, share_node, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-interact-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //队列预留内存后作为共享的目标队列
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_interact_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-cross-proc-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示申请队列的预留内存大小
- ***/
- //跨进程进行队列共享
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- memory_size = strtoul(argv[4], NULL, 10);
- ret = hpre_dev_queue_cross_proc_share(dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
else if(!strcmp(argv[1], "mult-thread-queue"))
{
/***
diff --git a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
index 31637565..7a3be22c 100644
--- a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
+++ b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
@@ -23,96 +23,33 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
- } else { /* use sgl */
- sched->msgs[i].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
- sched->msgs[i].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i, data_fmt);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- } else { /* use sgl */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_sgl(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_sgl(pool, sched->msgs[i].data_out);
- }
- wd_sglpool_destroy(pool);
- }
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
@@ -124,14 +61,6 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
struct wd_sglpool_setup sp;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -145,12 +74,22 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
+ return 0;
+ }
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
+ goto out_with_queues;
+ }
+
+ qinfo = sched->qs[i].qinfo;
pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -162,15 +101,18 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
qinfo->br.iova_map = (void *)wd_blk_iova_map;
qinfo->br.iova_unmap = (void *)wd_blk_iova_unmap;
qinfo->br.usr = pool;
- } else { /* use sgl*/
- memset(&sp, 0, sizeof(sp));
- sp.buf_size = sched->msg_data_size / 10;
- sp.align_size = 64;
- sp.sge_num_in_sgl = 60;
- sp.buf_num_in_sgl = sp.sge_num_in_sgl;
- sp.sgl_num = 3 * sched->msg_cache_num;
- sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
-
+ }
+ } else { /* use sgl*/
+ memset(&sp, 0, sizeof(sp));
+ sp.buf_size = sched->msg_data_size / 10;
+ sp.align_size = 64;
+ sp.sge_num_in_sgl = 60;
+ sp.buf_num_in_sgl = sp.sge_num_in_sgl;
+ sp.sgl_num = 3 * sched->msg_cache_num;
+ sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
pool = wd_sglpool_create(&sched->qs[0], &sp);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -189,17 +131,132 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
+
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ } else { /* use sgl */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_sgl(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_sgl(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
+
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
+ qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
+ flags = qinfo->dev_flags;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ } else { /* use sgl */
+ sched->msgs[j].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
+ sched->msgs[j].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ }
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j, data_fmt);
+ }
+ }
+
+ return 0;
+
+err_with_stat:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched, data_fmt);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
{
@@ -211,57 +268,22 @@ int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
if (ret < 0)
return -EINVAL;
- qinfo = sched->qs[0].qinfo;
- flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
- }
- }
- }
-
sched->cl = sched->msg_cache_num;
ret = __init_cache(sched, data_fmt);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched, data_fmt);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched, data_fmt);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched, data_fmt);
}
static int __sync_send(struct wd_scheduler *sched)
@@ -350,4 +372,4 @@ int wd_sched_work(struct wd_scheduler *sched, int remained)
}
return sched->cl;
-}
\ No newline at end of file
+}
diff --git a/v1/test/test_mm/test_wd_mem.c b/v1/test/test_mm/test_wd_mem.c
index 09824b99..e2eec60e 100644
--- a/v1/test/test_mm/test_wd_mem.c
+++ b/v1/test/test_mm/test_wd_mem.c
@@ -208,10 +208,10 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo1.q, &rsa_q);
+ ret = wd_request_queue(&pdata->qinfo1.q);
if (ret) {
wd_release_queue(&rsa_q);
- MMT_PRT("Proc-%d, thrd-%d:share mem on rsa queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:rsa queue fail!\n",
pid, thread_id);
return NULL;
}
@@ -226,9 +226,9 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo2.q, &zlib_q);
+ ret = wd_request_queue(&pdata->qinfo2.q);
if (ret) {
- MMT_PRT("Proc-%d, thrd-%d:share mem on zlib queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:zlib queue fail!\n",
pid, thread_id);
goto fail_release;
diff --git a/v1/test/wd_sched.c b/v1/test/wd_sched.c
index f5e46699..ce1d2604 100644
--- a/v1/test/wd_sched.c
+++ b/v1/test/wd_sched.c
@@ -22,94 +22,40 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched)
{
- int ret, i, j;
+ struct wd_blkpool_setup mm_setup;
unsigned int flags = 0;
struct q_info *qinfo;
- struct wd_blkpool_setup mm_setup;
+ int ret, i, j;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -120,18 +66,29 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
sched->ss_region = malloc(sched->ss_region_size);
if (!sched->ss_region) {
WD_ERR("fail to alloc sched ss region mem!\n");
+ return -ENOMEM;
+ }
+ return 0;
+ }
+
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
- pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
+
+ qinfo = sched->qs[i].qinfo;
+ pool = wd_blkpool_create(&sched->qs[i], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
ret = -ENOMEM;
+ wd_release_queue(&sched->qs[i]);
goto out_with_queues;
}
qinfo->br.alloc = (void *)wd_alloc_blk;
@@ -144,79 +101,135 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
-int wd_sched_init(struct wd_scheduler *sched)
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched)
{
- int ret, j, k;
- unsigned int flags;
struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
- ret = wd_sched_preinit(sched);
- if (ret < 0)
- return -EINVAL;
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_alloc;
}
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j);
}
}
- sched->cl = sched->msg_cache_num;
+ return 0;
+
+err_with_alloc:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
+
+int wd_sched_init(struct wd_scheduler *sched)
+{
+ int ret;
+ ret = wd_sched_preinit(sched);
+ if (ret < 0)
+ return -EINVAL;
+
+ sched->cl = sched->msg_cache_num;
ret = __init_cache(sched);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched);
}
static int __sync_send(struct wd_scheduler *sched)
--
2.33.0
1
0
13 Jun '25
From: Longfang Liu <liulongfang(a)huawei.com>
After removing the shared queue memory allocation interface, the UADK
test tools must also eliminate the shared memory functionality.
For individual memory reservations, the wd_reserve_memory interface
should be used. When allocating memory for multiple queues, each queue
should independently request its own reserved memory allocation.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 -----------------------
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 +++++++++---------
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +++++++-------
4 files changed, 300 insertions(+), 657 deletions(-)
diff --git a/v1/test/hisi_hpre_test/hpre_test_tools.c b/v1/test/hisi_hpre_test/hpre_test_tools.c
index 7f562f34..10a4ade9 100755
--- a/v1/test/hisi_hpre_test/hpre_test_tools.c
+++ b/v1/test/hisi_hpre_test/hpre_test_tools.c
@@ -644,317 +644,6 @@ int application_release_multiple_queue(char *dev, char *alg_type, unsigned int q
printf("application_release_multiple_queue test end!\n");
return 0;
}
-
-/***
-
-***/
-int hpre_dev_queue_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_node_queue_share(char *dev, unsigned int node, unsigned int share_node, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
- q.node_mask = node;
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- target_q.node_mask = node;
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on target q fail!\n");
- return 1;
- }
-
- ret = wd_share_reserved_memory(&q, &target_q);
-
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on share q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on share target q fail!\n");
- return 1;
- }
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_dev_queue_interact_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return ret;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- addr = wd_reserve_memory(&target_q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- //target_q
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
-/***
-
-***/
-int hpre_dev_queue_cross_proc_share(char *dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- pid_t pid;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size=0;
-
- pid = fork();
- if(pid < 0)
- {
- printf("Creation process failed, pid:%d\n",pid);
- return 1;
- }
- else if(pid == 0)
- {
- printf("child process:%d\n", pid);
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("request queue fail!\n");
- exit(1);
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("queue reserve memory fail!\n");
- exit(2);
- }
- printf("queue reserve memory success!\n");
- memset(addr, 0, memory_size);
- exit(0);
- }
- printf("parent process:%d\n", pid);
- pid_t wpid;
- int status = -1;
- wpid = waitpid(pid, &status, WUNTRACED | WCONTINUED);
- if( wpid < 0)
- {
- printf("exited, status=%d\n", WEXITSTATUS(status));
- return(status);
- }
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&target_q);
- wd_release_queue(&q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
/***
***/
@@ -1696,87 +1385,6 @@ int main(int arc, char *argv[])
return 1;
}
}
- else if(!strcmp(argv[1], "queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "node-queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示设备node
- argv[5] - 表示共享内存设备node
- argv[6] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- unsigned int node=0;
- node = strtoul(argv[4], NULL, 16);
- unsigned int share_node=0;
- share_node = strtoul(argv[5], NULL, 16);
- memory_size = strtoul(argv[6], NULL, 10);
-
- ret = hpre_node_queue_share(dev, node, share_node, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-interact-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //队列预留内存后作为共享的目标队列
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_interact_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-cross-proc-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示申请队列的预留内存大小
- ***/
- //跨进程进行队列共享
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- memory_size = strtoul(argv[4], NULL, 10);
- ret = hpre_dev_queue_cross_proc_share(dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
else if(!strcmp(argv[1], "mult-thread-queue"))
{
/***
diff --git a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
index 31637565..7a3be22c 100644
--- a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
+++ b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
@@ -23,96 +23,33 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
- } else { /* use sgl */
- sched->msgs[i].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
- sched->msgs[i].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i, data_fmt);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- } else { /* use sgl */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_sgl(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_sgl(pool, sched->msgs[i].data_out);
- }
- wd_sglpool_destroy(pool);
- }
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
@@ -124,14 +61,6 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
struct wd_sglpool_setup sp;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -145,12 +74,22 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
+ return 0;
+ }
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
+ goto out_with_queues;
+ }
+
+ qinfo = sched->qs[i].qinfo;
pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -162,15 +101,18 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
qinfo->br.iova_map = (void *)wd_blk_iova_map;
qinfo->br.iova_unmap = (void *)wd_blk_iova_unmap;
qinfo->br.usr = pool;
- } else { /* use sgl*/
- memset(&sp, 0, sizeof(sp));
- sp.buf_size = sched->msg_data_size / 10;
- sp.align_size = 64;
- sp.sge_num_in_sgl = 60;
- sp.buf_num_in_sgl = sp.sge_num_in_sgl;
- sp.sgl_num = 3 * sched->msg_cache_num;
- sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
-
+ }
+ } else { /* use sgl*/
+ memset(&sp, 0, sizeof(sp));
+ sp.buf_size = sched->msg_data_size / 10;
+ sp.align_size = 64;
+ sp.sge_num_in_sgl = 60;
+ sp.buf_num_in_sgl = sp.sge_num_in_sgl;
+ sp.sgl_num = 3 * sched->msg_cache_num;
+ sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
pool = wd_sglpool_create(&sched->qs[0], &sp);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -189,17 +131,132 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
+
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ } else { /* use sgl */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_sgl(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_sgl(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
+
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
+ qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
+ flags = qinfo->dev_flags;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ } else { /* use sgl */
+ sched->msgs[j].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
+ sched->msgs[j].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ }
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j, data_fmt);
+ }
+ }
+
+ return 0;
+
+err_with_stat:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched, data_fmt);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
{
@@ -211,57 +268,22 @@ int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
if (ret < 0)
return -EINVAL;
- qinfo = sched->qs[0].qinfo;
- flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
- }
- }
- }
-
sched->cl = sched->msg_cache_num;
ret = __init_cache(sched, data_fmt);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched, data_fmt);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched, data_fmt);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched, data_fmt);
}
static int __sync_send(struct wd_scheduler *sched)
@@ -350,4 +372,4 @@ int wd_sched_work(struct wd_scheduler *sched, int remained)
}
return sched->cl;
-}
\ No newline at end of file
+}
diff --git a/v1/test/test_mm/test_wd_mem.c b/v1/test/test_mm/test_wd_mem.c
index 09824b99..e2eec60e 100644
--- a/v1/test/test_mm/test_wd_mem.c
+++ b/v1/test/test_mm/test_wd_mem.c
@@ -208,10 +208,10 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo1.q, &rsa_q);
+ ret = wd_request_queue(&pdata->qinfo1.q);
if (ret) {
wd_release_queue(&rsa_q);
- MMT_PRT("Proc-%d, thrd-%d:share mem on rsa queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:rsa queue fail!\n",
pid, thread_id);
return NULL;
}
@@ -226,9 +226,9 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo2.q, &zlib_q);
+ ret = wd_request_queue(&pdata->qinfo2.q);
if (ret) {
- MMT_PRT("Proc-%d, thrd-%d:share mem on zlib queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:zlib queue fail!\n",
pid, thread_id);
goto fail_release;
diff --git a/v1/test/wd_sched.c b/v1/test/wd_sched.c
index f5e46699..ce1d2604 100644
--- a/v1/test/wd_sched.c
+++ b/v1/test/wd_sched.c
@@ -22,94 +22,40 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched)
{
- int ret, i, j;
+ struct wd_blkpool_setup mm_setup;
unsigned int flags = 0;
struct q_info *qinfo;
- struct wd_blkpool_setup mm_setup;
+ int ret, i, j;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -120,18 +66,29 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
sched->ss_region = malloc(sched->ss_region_size);
if (!sched->ss_region) {
WD_ERR("fail to alloc sched ss region mem!\n");
+ return -ENOMEM;
+ }
+ return 0;
+ }
+
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
- pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
+
+ qinfo = sched->qs[i].qinfo;
+ pool = wd_blkpool_create(&sched->qs[i], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
ret = -ENOMEM;
+ wd_release_queue(&sched->qs[i]);
goto out_with_queues;
}
qinfo->br.alloc = (void *)wd_alloc_blk;
@@ -144,79 +101,135 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
-int wd_sched_init(struct wd_scheduler *sched)
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched)
{
- int ret, j, k;
- unsigned int flags;
struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
- ret = wd_sched_preinit(sched);
- if (ret < 0)
- return -EINVAL;
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_alloc;
}
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j);
}
}
- sched->cl = sched->msg_cache_num;
+ return 0;
+
+err_with_alloc:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
+
+int wd_sched_init(struct wd_scheduler *sched)
+{
+ int ret;
+ ret = wd_sched_preinit(sched);
+ if (ret < 0)
+ return -EINVAL;
+
+ sched->cl = sched->msg_cache_num;
ret = __init_cache(sched);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched);
}
static int __sync_send(struct wd_scheduler *sched)
--
2.33.0
1
0
13 Jun '25
From: Longfang Liu <liulongfang(a)huawei.com>
After removing the shared queue memory allocation interface, the UADK
test tools must also eliminate the shared memory functionality.
For individual memory reservations, the wd_reserve_memory interface
should be used. When allocating memory for multiple queues, each queue
should independently request its own reserved memory allocation.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 -----------------------
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 +++++++++---------
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +++++++-------
4 files changed, 300 insertions(+), 657 deletions(-)
diff --git a/v1/test/hisi_hpre_test/hpre_test_tools.c b/v1/test/hisi_hpre_test/hpre_test_tools.c
index 7f562f34..10a4ade9 100755
--- a/v1/test/hisi_hpre_test/hpre_test_tools.c
+++ b/v1/test/hisi_hpre_test/hpre_test_tools.c
@@ -644,317 +644,6 @@ int application_release_multiple_queue(char *dev, char *alg_type, unsigned int q
printf("application_release_multiple_queue test end!\n");
return 0;
}
-
-/***
-
-***/
-int hpre_dev_queue_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_node_queue_share(char *dev, unsigned int node, unsigned int share_node, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
- q.node_mask = node;
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- target_q.node_mask = node;
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on target q fail!\n");
- return 1;
- }
-
- ret = wd_share_reserved_memory(&q, &target_q);
-
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on share q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on share target q fail!\n");
- return 1;
- }
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_dev_queue_interact_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return ret;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- addr = wd_reserve_memory(&target_q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- //target_q
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
-/***
-
-***/
-int hpre_dev_queue_cross_proc_share(char *dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- pid_t pid;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size=0;
-
- pid = fork();
- if(pid < 0)
- {
- printf("Creation process failed, pid:%d\n",pid);
- return 1;
- }
- else if(pid == 0)
- {
- printf("child process:%d\n", pid);
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("request queue fail!\n");
- exit(1);
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("queue reserve memory fail!\n");
- exit(2);
- }
- printf("queue reserve memory success!\n");
- memset(addr, 0, memory_size);
- exit(0);
- }
- printf("parent process:%d\n", pid);
- pid_t wpid;
- int status = -1;
- wpid = waitpid(pid, &status, WUNTRACED | WCONTINUED);
- if( wpid < 0)
- {
- printf("exited, status=%d\n", WEXITSTATUS(status));
- return(status);
- }
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&target_q);
- wd_release_queue(&q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
/***
***/
@@ -1696,87 +1385,6 @@ int main(int arc, char *argv[])
return 1;
}
}
- else if(!strcmp(argv[1], "queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "node-queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示设备node
- argv[5] - 表示共享内存设备node
- argv[6] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- unsigned int node=0;
- node = strtoul(argv[4], NULL, 16);
- unsigned int share_node=0;
- share_node = strtoul(argv[5], NULL, 16);
- memory_size = strtoul(argv[6], NULL, 10);
-
- ret = hpre_node_queue_share(dev, node, share_node, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-interact-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //队列预留内存后作为共享的目标队列
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_interact_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-cross-proc-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示申请队列的预留内存大小
- ***/
- //跨进程进行队列共享
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- memory_size = strtoul(argv[4], NULL, 10);
- ret = hpre_dev_queue_cross_proc_share(dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
else if(!strcmp(argv[1], "mult-thread-queue"))
{
/***
diff --git a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
index 31637565..7a3be22c 100644
--- a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
+++ b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
@@ -23,96 +23,33 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
- } else { /* use sgl */
- sched->msgs[i].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
- sched->msgs[i].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i, data_fmt);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- } else { /* use sgl */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_sgl(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_sgl(pool, sched->msgs[i].data_out);
- }
- wd_sglpool_destroy(pool);
- }
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
@@ -124,14 +61,6 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
struct wd_sglpool_setup sp;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -145,12 +74,22 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
+ return 0;
+ }
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
+ goto out_with_queues;
+ }
+
+ qinfo = sched->qs[i].qinfo;
pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -162,15 +101,18 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
qinfo->br.iova_map = (void *)wd_blk_iova_map;
qinfo->br.iova_unmap = (void *)wd_blk_iova_unmap;
qinfo->br.usr = pool;
- } else { /* use sgl*/
- memset(&sp, 0, sizeof(sp));
- sp.buf_size = sched->msg_data_size / 10;
- sp.align_size = 64;
- sp.sge_num_in_sgl = 60;
- sp.buf_num_in_sgl = sp.sge_num_in_sgl;
- sp.sgl_num = 3 * sched->msg_cache_num;
- sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
-
+ }
+ } else { /* use sgl*/
+ memset(&sp, 0, sizeof(sp));
+ sp.buf_size = sched->msg_data_size / 10;
+ sp.align_size = 64;
+ sp.sge_num_in_sgl = 60;
+ sp.buf_num_in_sgl = sp.sge_num_in_sgl;
+ sp.sgl_num = 3 * sched->msg_cache_num;
+ sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
pool = wd_sglpool_create(&sched->qs[0], &sp);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -189,17 +131,132 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
+
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ } else { /* use sgl */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_sgl(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_sgl(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
+
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
+ qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
+ flags = qinfo->dev_flags;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ } else { /* use sgl */
+ sched->msgs[j].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
+ sched->msgs[j].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ }
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j, data_fmt);
+ }
+ }
+
+ return 0;
+
+err_with_stat:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched, data_fmt);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
{
@@ -211,57 +268,22 @@ int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
if (ret < 0)
return -EINVAL;
- qinfo = sched->qs[0].qinfo;
- flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
- }
- }
- }
-
sched->cl = sched->msg_cache_num;
ret = __init_cache(sched, data_fmt);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched, data_fmt);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched, data_fmt);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched, data_fmt);
}
static int __sync_send(struct wd_scheduler *sched)
@@ -350,4 +372,4 @@ int wd_sched_work(struct wd_scheduler *sched, int remained)
}
return sched->cl;
-}
\ No newline at end of file
+}
diff --git a/v1/test/test_mm/test_wd_mem.c b/v1/test/test_mm/test_wd_mem.c
index 09824b99..e2eec60e 100644
--- a/v1/test/test_mm/test_wd_mem.c
+++ b/v1/test/test_mm/test_wd_mem.c
@@ -208,10 +208,10 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo1.q, &rsa_q);
+ ret = wd_request_queue(&pdata->qinfo1.q);
if (ret) {
wd_release_queue(&rsa_q);
- MMT_PRT("Proc-%d, thrd-%d:share mem on rsa queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:rsa queue fail!\n",
pid, thread_id);
return NULL;
}
@@ -226,9 +226,9 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo2.q, &zlib_q);
+ ret = wd_request_queue(&pdata->qinfo2.q);
if (ret) {
- MMT_PRT("Proc-%d, thrd-%d:share mem on zlib queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:zlib queue fail!\n",
pid, thread_id);
goto fail_release;
diff --git a/v1/test/wd_sched.c b/v1/test/wd_sched.c
index f5e46699..ce1d2604 100644
--- a/v1/test/wd_sched.c
+++ b/v1/test/wd_sched.c
@@ -22,94 +22,40 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched)
{
- int ret, i, j;
+ struct wd_blkpool_setup mm_setup;
unsigned int flags = 0;
struct q_info *qinfo;
- struct wd_blkpool_setup mm_setup;
+ int ret, i, j;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -120,18 +66,29 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
sched->ss_region = malloc(sched->ss_region_size);
if (!sched->ss_region) {
WD_ERR("fail to alloc sched ss region mem!\n");
+ return -ENOMEM;
+ }
+ return 0;
+ }
+
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
- pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
+
+ qinfo = sched->qs[i].qinfo;
+ pool = wd_blkpool_create(&sched->qs[i], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
ret = -ENOMEM;
+ wd_release_queue(&sched->qs[i]);
goto out_with_queues;
}
qinfo->br.alloc = (void *)wd_alloc_blk;
@@ -144,79 +101,135 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
-int wd_sched_init(struct wd_scheduler *sched)
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched)
{
- int ret, j, k;
- unsigned int flags;
struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
- ret = wd_sched_preinit(sched);
- if (ret < 0)
- return -EINVAL;
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_alloc;
}
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j);
}
}
- sched->cl = sched->msg_cache_num;
+ return 0;
+
+err_with_alloc:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
+
+int wd_sched_init(struct wd_scheduler *sched)
+{
+ int ret;
+ ret = wd_sched_preinit(sched);
+ if (ret < 0)
+ return -EINVAL;
+
+ sched->cl = sched->msg_cache_num;
ret = __init_cache(sched);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched);
}
static int __sync_send(struct wd_scheduler *sched)
--
2.33.0
1
0
13 Jun '25
From: Longfang Liu <liulongfang(a)huawei.com>
After removing the shared queue memory allocation interface, the UADK
test tools must also eliminate the shared memory functionality.
For individual memory reservations, the wd_reserve_memory interface
should be used. When allocating memory for multiple queues, each queue
should independently request its own reserved memory allocation.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 -----------------------
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 +++++++++---------
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +++++++-------
4 files changed, 300 insertions(+), 657 deletions(-)
diff --git a/v1/test/hisi_hpre_test/hpre_test_tools.c b/v1/test/hisi_hpre_test/hpre_test_tools.c
index 7f562f34..10a4ade9 100755
--- a/v1/test/hisi_hpre_test/hpre_test_tools.c
+++ b/v1/test/hisi_hpre_test/hpre_test_tools.c
@@ -644,317 +644,6 @@ int application_release_multiple_queue(char *dev, char *alg_type, unsigned int q
printf("application_release_multiple_queue test end!\n");
return 0;
}
-
-/***
-
-***/
-int hpre_dev_queue_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_node_queue_share(char *dev, unsigned int node, unsigned int share_node, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
- q.node_mask = node;
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- target_q.node_mask = node;
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on target q fail!\n");
- return 1;
- }
-
- ret = wd_share_reserved_memory(&q, &target_q);
-
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on share q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on share target q fail!\n");
- return 1;
- }
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_dev_queue_interact_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return ret;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- addr = wd_reserve_memory(&target_q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- //target_q
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
-/***
-
-***/
-int hpre_dev_queue_cross_proc_share(char *dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- pid_t pid;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size=0;
-
- pid = fork();
- if(pid < 0)
- {
- printf("Creation process failed, pid:%d\n",pid);
- return 1;
- }
- else if(pid == 0)
- {
- printf("child process:%d\n", pid);
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("request queue fail!\n");
- exit(1);
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("queue reserve memory fail!\n");
- exit(2);
- }
- printf("queue reserve memory success!\n");
- memset(addr, 0, memory_size);
- exit(0);
- }
- printf("parent process:%d\n", pid);
- pid_t wpid;
- int status = -1;
- wpid = waitpid(pid, &status, WUNTRACED | WCONTINUED);
- if( wpid < 0)
- {
- printf("exited, status=%d\n", WEXITSTATUS(status));
- return(status);
- }
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&target_q);
- wd_release_queue(&q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
/***
***/
@@ -1696,87 +1385,6 @@ int main(int arc, char *argv[])
return 1;
}
}
- else if(!strcmp(argv[1], "queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "node-queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示设备node
- argv[5] - 表示共享内存设备node
- argv[6] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- unsigned int node=0;
- node = strtoul(argv[4], NULL, 16);
- unsigned int share_node=0;
- share_node = strtoul(argv[5], NULL, 16);
- memory_size = strtoul(argv[6], NULL, 10);
-
- ret = hpre_node_queue_share(dev, node, share_node, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-interact-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //队列预留内存后作为共享的目标队列
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_interact_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-cross-proc-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示申请队列的预留内存大小
- ***/
- //跨进程进行队列共享
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- memory_size = strtoul(argv[4], NULL, 10);
- ret = hpre_dev_queue_cross_proc_share(dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
else if(!strcmp(argv[1], "mult-thread-queue"))
{
/***
diff --git a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
index 31637565..7a3be22c 100644
--- a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
+++ b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
@@ -23,96 +23,33 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
- } else { /* use sgl */
- sched->msgs[i].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
- sched->msgs[i].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i, data_fmt);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- } else { /* use sgl */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_sgl(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_sgl(pool, sched->msgs[i].data_out);
- }
- wd_sglpool_destroy(pool);
- }
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
@@ -124,14 +61,6 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
struct wd_sglpool_setup sp;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -145,12 +74,22 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
+ return 0;
+ }
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
+ goto out_with_queues;
+ }
+
+ qinfo = sched->qs[i].qinfo;
pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -162,15 +101,18 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
qinfo->br.iova_map = (void *)wd_blk_iova_map;
qinfo->br.iova_unmap = (void *)wd_blk_iova_unmap;
qinfo->br.usr = pool;
- } else { /* use sgl*/
- memset(&sp, 0, sizeof(sp));
- sp.buf_size = sched->msg_data_size / 10;
- sp.align_size = 64;
- sp.sge_num_in_sgl = 60;
- sp.buf_num_in_sgl = sp.sge_num_in_sgl;
- sp.sgl_num = 3 * sched->msg_cache_num;
- sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
-
+ }
+ } else { /* use sgl*/
+ memset(&sp, 0, sizeof(sp));
+ sp.buf_size = sched->msg_data_size / 10;
+ sp.align_size = 64;
+ sp.sge_num_in_sgl = 60;
+ sp.buf_num_in_sgl = sp.sge_num_in_sgl;
+ sp.sgl_num = 3 * sched->msg_cache_num;
+ sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
pool = wd_sglpool_create(&sched->qs[0], &sp);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -189,17 +131,132 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
+
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ } else { /* use sgl */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_sgl(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_sgl(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
+
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
+ qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
+ flags = qinfo->dev_flags;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ } else { /* use sgl */
+ sched->msgs[j].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
+ sched->msgs[j].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ }
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j, data_fmt);
+ }
+ }
+
+ return 0;
+
+err_with_stat:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched, data_fmt);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
{
@@ -211,57 +268,22 @@ int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
if (ret < 0)
return -EINVAL;
- qinfo = sched->qs[0].qinfo;
- flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
- }
- }
- }
-
sched->cl = sched->msg_cache_num;
ret = __init_cache(sched, data_fmt);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched, data_fmt);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched, data_fmt);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched, data_fmt);
}
static int __sync_send(struct wd_scheduler *sched)
@@ -350,4 +372,4 @@ int wd_sched_work(struct wd_scheduler *sched, int remained)
}
return sched->cl;
-}
\ No newline at end of file
+}
diff --git a/v1/test/test_mm/test_wd_mem.c b/v1/test/test_mm/test_wd_mem.c
index 09824b99..e2eec60e 100644
--- a/v1/test/test_mm/test_wd_mem.c
+++ b/v1/test/test_mm/test_wd_mem.c
@@ -208,10 +208,10 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo1.q, &rsa_q);
+ ret = wd_request_queue(&pdata->qinfo1.q);
if (ret) {
wd_release_queue(&rsa_q);
- MMT_PRT("Proc-%d, thrd-%d:share mem on rsa queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:rsa queue fail!\n",
pid, thread_id);
return NULL;
}
@@ -226,9 +226,9 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo2.q, &zlib_q);
+ ret = wd_request_queue(&pdata->qinfo2.q);
if (ret) {
- MMT_PRT("Proc-%d, thrd-%d:share mem on zlib queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:zlib queue fail!\n",
pid, thread_id);
goto fail_release;
diff --git a/v1/test/wd_sched.c b/v1/test/wd_sched.c
index f5e46699..ce1d2604 100644
--- a/v1/test/wd_sched.c
+++ b/v1/test/wd_sched.c
@@ -22,94 +22,40 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched)
{
- int ret, i, j;
+ struct wd_blkpool_setup mm_setup;
unsigned int flags = 0;
struct q_info *qinfo;
- struct wd_blkpool_setup mm_setup;
+ int ret, i, j;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -120,18 +66,29 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
sched->ss_region = malloc(sched->ss_region_size);
if (!sched->ss_region) {
WD_ERR("fail to alloc sched ss region mem!\n");
+ return -ENOMEM;
+ }
+ return 0;
+ }
+
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
- pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
+
+ qinfo = sched->qs[i].qinfo;
+ pool = wd_blkpool_create(&sched->qs[i], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
ret = -ENOMEM;
+ wd_release_queue(&sched->qs[i]);
goto out_with_queues;
}
qinfo->br.alloc = (void *)wd_alloc_blk;
@@ -144,79 +101,135 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
-int wd_sched_init(struct wd_scheduler *sched)
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched)
{
- int ret, j, k;
- unsigned int flags;
struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
- ret = wd_sched_preinit(sched);
- if (ret < 0)
- return -EINVAL;
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_alloc;
}
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j);
}
}
- sched->cl = sched->msg_cache_num;
+ return 0;
+
+err_with_alloc:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
+
+int wd_sched_init(struct wd_scheduler *sched)
+{
+ int ret;
+ ret = wd_sched_preinit(sched);
+ if (ret < 0)
+ return -EINVAL;
+
+ sched->cl = sched->msg_cache_num;
ret = __init_cache(sched);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched);
}
static int __sync_send(struct wd_scheduler *sched)
--
2.33.0
1
0
13 Jun '25
From: Longfang Liu <liulongfang(a)huawei.com>
After removing the shared queue memory allocation interface, the UADK
test tools must also eliminate the shared memory functionality.
For individual memory reservations, the wd_reserve_memory interface
should be used. When allocating memory for multiple queues, each queue
should independently request its own reserved memory allocation.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 -----------------------
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 +++++++++---------
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +++++++-------
4 files changed, 300 insertions(+), 657 deletions(-)
diff --git a/v1/test/hisi_hpre_test/hpre_test_tools.c b/v1/test/hisi_hpre_test/hpre_test_tools.c
index 7f562f34..10a4ade9 100755
--- a/v1/test/hisi_hpre_test/hpre_test_tools.c
+++ b/v1/test/hisi_hpre_test/hpre_test_tools.c
@@ -644,317 +644,6 @@ int application_release_multiple_queue(char *dev, char *alg_type, unsigned int q
printf("application_release_multiple_queue test end!\n");
return 0;
}
-
-/***
-
-***/
-int hpre_dev_queue_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_node_queue_share(char *dev, unsigned int node, unsigned int share_node, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
- q.node_mask = node;
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- target_q.node_mask = node;
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on target q fail!\n");
- return 1;
- }
-
- ret = wd_share_reserved_memory(&q, &target_q);
-
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on share q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on share target q fail!\n");
- return 1;
- }
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_dev_queue_interact_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return ret;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- addr = wd_reserve_memory(&target_q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- //target_q
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
-/***
-
-***/
-int hpre_dev_queue_cross_proc_share(char *dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- pid_t pid;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size=0;
-
- pid = fork();
- if(pid < 0)
- {
- printf("Creation process failed, pid:%d\n",pid);
- return 1;
- }
- else if(pid == 0)
- {
- printf("child process:%d\n", pid);
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("request queue fail!\n");
- exit(1);
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("queue reserve memory fail!\n");
- exit(2);
- }
- printf("queue reserve memory success!\n");
- memset(addr, 0, memory_size);
- exit(0);
- }
- printf("parent process:%d\n", pid);
- pid_t wpid;
- int status = -1;
- wpid = waitpid(pid, &status, WUNTRACED | WCONTINUED);
- if( wpid < 0)
- {
- printf("exited, status=%d\n", WEXITSTATUS(status));
- return(status);
- }
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&target_q);
- wd_release_queue(&q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
/***
***/
@@ -1696,87 +1385,6 @@ int main(int arc, char *argv[])
return 1;
}
}
- else if(!strcmp(argv[1], "queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "node-queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示设备node
- argv[5] - 表示共享内存设备node
- argv[6] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- unsigned int node=0;
- node = strtoul(argv[4], NULL, 16);
- unsigned int share_node=0;
- share_node = strtoul(argv[5], NULL, 16);
- memory_size = strtoul(argv[6], NULL, 10);
-
- ret = hpre_node_queue_share(dev, node, share_node, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-interact-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //队列预留内存后作为共享的目标队列
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_interact_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-cross-proc-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示申请队列的预留内存大小
- ***/
- //跨进程进行队列共享
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- memory_size = strtoul(argv[4], NULL, 10);
- ret = hpre_dev_queue_cross_proc_share(dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
else if(!strcmp(argv[1], "mult-thread-queue"))
{
/***
diff --git a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
index 31637565..7a3be22c 100644
--- a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
+++ b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
@@ -23,96 +23,33 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
- } else { /* use sgl */
- sched->msgs[i].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
- sched->msgs[i].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i, data_fmt);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- } else { /* use sgl */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_sgl(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_sgl(pool, sched->msgs[i].data_out);
- }
- wd_sglpool_destroy(pool);
- }
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
@@ -124,14 +61,6 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
struct wd_sglpool_setup sp;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -145,12 +74,22 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
+ return 0;
+ }
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
+ goto out_with_queues;
+ }
+
+ qinfo = sched->qs[i].qinfo;
pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -162,15 +101,18 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
qinfo->br.iova_map = (void *)wd_blk_iova_map;
qinfo->br.iova_unmap = (void *)wd_blk_iova_unmap;
qinfo->br.usr = pool;
- } else { /* use sgl*/
- memset(&sp, 0, sizeof(sp));
- sp.buf_size = sched->msg_data_size / 10;
- sp.align_size = 64;
- sp.sge_num_in_sgl = 60;
- sp.buf_num_in_sgl = sp.sge_num_in_sgl;
- sp.sgl_num = 3 * sched->msg_cache_num;
- sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
-
+ }
+ } else { /* use sgl*/
+ memset(&sp, 0, sizeof(sp));
+ sp.buf_size = sched->msg_data_size / 10;
+ sp.align_size = 64;
+ sp.sge_num_in_sgl = 60;
+ sp.buf_num_in_sgl = sp.sge_num_in_sgl;
+ sp.sgl_num = 3 * sched->msg_cache_num;
+ sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
pool = wd_sglpool_create(&sched->qs[0], &sp);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -189,17 +131,132 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
+
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ } else { /* use sgl */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_sgl(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_sgl(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
+
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
+ qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
+ flags = qinfo->dev_flags;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ } else { /* use sgl */
+ sched->msgs[j].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
+ sched->msgs[j].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ }
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j, data_fmt);
+ }
+ }
+
+ return 0;
+
+err_with_stat:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched, data_fmt);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
{
@@ -211,57 +268,22 @@ int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
if (ret < 0)
return -EINVAL;
- qinfo = sched->qs[0].qinfo;
- flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
- }
- }
- }
-
sched->cl = sched->msg_cache_num;
ret = __init_cache(sched, data_fmt);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched, data_fmt);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched, data_fmt);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched, data_fmt);
}
static int __sync_send(struct wd_scheduler *sched)
@@ -350,4 +372,4 @@ int wd_sched_work(struct wd_scheduler *sched, int remained)
}
return sched->cl;
-}
\ No newline at end of file
+}
diff --git a/v1/test/test_mm/test_wd_mem.c b/v1/test/test_mm/test_wd_mem.c
index 09824b99..e2eec60e 100644
--- a/v1/test/test_mm/test_wd_mem.c
+++ b/v1/test/test_mm/test_wd_mem.c
@@ -208,10 +208,10 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo1.q, &rsa_q);
+ ret = wd_request_queue(&pdata->qinfo1.q);
if (ret) {
wd_release_queue(&rsa_q);
- MMT_PRT("Proc-%d, thrd-%d:share mem on rsa queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:rsa queue fail!\n",
pid, thread_id);
return NULL;
}
@@ -226,9 +226,9 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo2.q, &zlib_q);
+ ret = wd_request_queue(&pdata->qinfo2.q);
if (ret) {
- MMT_PRT("Proc-%d, thrd-%d:share mem on zlib queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:zlib queue fail!\n",
pid, thread_id);
goto fail_release;
diff --git a/v1/test/wd_sched.c b/v1/test/wd_sched.c
index f5e46699..ce1d2604 100644
--- a/v1/test/wd_sched.c
+++ b/v1/test/wd_sched.c
@@ -22,94 +22,40 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched)
{
- int ret, i, j;
+ struct wd_blkpool_setup mm_setup;
unsigned int flags = 0;
struct q_info *qinfo;
- struct wd_blkpool_setup mm_setup;
+ int ret, i, j;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -120,18 +66,29 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
sched->ss_region = malloc(sched->ss_region_size);
if (!sched->ss_region) {
WD_ERR("fail to alloc sched ss region mem!\n");
+ return -ENOMEM;
+ }
+ return 0;
+ }
+
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
- pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
+
+ qinfo = sched->qs[i].qinfo;
+ pool = wd_blkpool_create(&sched->qs[i], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
ret = -ENOMEM;
+ wd_release_queue(&sched->qs[i]);
goto out_with_queues;
}
qinfo->br.alloc = (void *)wd_alloc_blk;
@@ -144,79 +101,135 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
-int wd_sched_init(struct wd_scheduler *sched)
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched)
{
- int ret, j, k;
- unsigned int flags;
struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
- ret = wd_sched_preinit(sched);
- if (ret < 0)
- return -EINVAL;
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_alloc;
}
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j);
}
}
- sched->cl = sched->msg_cache_num;
+ return 0;
+
+err_with_alloc:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
+
+int wd_sched_init(struct wd_scheduler *sched)
+{
+ int ret;
+ ret = wd_sched_preinit(sched);
+ if (ret < 0)
+ return -EINVAL;
+
+ sched->cl = sched->msg_cache_num;
ret = __init_cache(sched);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched);
}
static int __sync_send(struct wd_scheduler *sched)
--
2.33.0
1
0
13 Jun '25
From: Longfang Liu <liulongfang(a)huawei.com>
After removing the shared queue memory allocation interface, the UADK
test tools must also eliminate the shared memory functionality.
For individual memory reservations, the wd_reserve_memory interface
should be used. When allocating memory for multiple queues, each queue
should independently request its own reserved memory allocation.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 -----------------------
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 +++++++++---------
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +++++++-------
4 files changed, 300 insertions(+), 657 deletions(-)
diff --git a/v1/test/hisi_hpre_test/hpre_test_tools.c b/v1/test/hisi_hpre_test/hpre_test_tools.c
index 7f562f34..10a4ade9 100755
--- a/v1/test/hisi_hpre_test/hpre_test_tools.c
+++ b/v1/test/hisi_hpre_test/hpre_test_tools.c
@@ -644,317 +644,6 @@ int application_release_multiple_queue(char *dev, char *alg_type, unsigned int q
printf("application_release_multiple_queue test end!\n");
return 0;
}
-
-/***
-
-***/
-int hpre_dev_queue_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_node_queue_share(char *dev, unsigned int node, unsigned int share_node, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
- q.node_mask = node;
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- target_q.node_mask = node;
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on target q fail!\n");
- return 1;
- }
-
- ret = wd_share_reserved_memory(&q, &target_q);
-
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on share q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on share target q fail!\n");
- return 1;
- }
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_dev_queue_interact_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return ret;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- addr = wd_reserve_memory(&target_q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- //target_q
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
-/***
-
-***/
-int hpre_dev_queue_cross_proc_share(char *dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- pid_t pid;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size=0;
-
- pid = fork();
- if(pid < 0)
- {
- printf("Creation process failed, pid:%d\n",pid);
- return 1;
- }
- else if(pid == 0)
- {
- printf("child process:%d\n", pid);
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("request queue fail!\n");
- exit(1);
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("queue reserve memory fail!\n");
- exit(2);
- }
- printf("queue reserve memory success!\n");
- memset(addr, 0, memory_size);
- exit(0);
- }
- printf("parent process:%d\n", pid);
- pid_t wpid;
- int status = -1;
- wpid = waitpid(pid, &status, WUNTRACED | WCONTINUED);
- if( wpid < 0)
- {
- printf("exited, status=%d\n", WEXITSTATUS(status));
- return(status);
- }
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&target_q);
- wd_release_queue(&q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
/***
***/
@@ -1696,87 +1385,6 @@ int main(int arc, char *argv[])
return 1;
}
}
- else if(!strcmp(argv[1], "queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "node-queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示设备node
- argv[5] - 表示共享内存设备node
- argv[6] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- unsigned int node=0;
- node = strtoul(argv[4], NULL, 16);
- unsigned int share_node=0;
- share_node = strtoul(argv[5], NULL, 16);
- memory_size = strtoul(argv[6], NULL, 10);
-
- ret = hpre_node_queue_share(dev, node, share_node, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-interact-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //队列预留内存后作为共享的目标队列
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_interact_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-cross-proc-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示申请队列的预留内存大小
- ***/
- //跨进程进行队列共享
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- memory_size = strtoul(argv[4], NULL, 10);
- ret = hpre_dev_queue_cross_proc_share(dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
else if(!strcmp(argv[1], "mult-thread-queue"))
{
/***
diff --git a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
index 31637565..7a3be22c 100644
--- a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
+++ b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
@@ -23,96 +23,33 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
- } else { /* use sgl */
- sched->msgs[i].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
- sched->msgs[i].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i, data_fmt);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- } else { /* use sgl */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_sgl(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_sgl(pool, sched->msgs[i].data_out);
- }
- wd_sglpool_destroy(pool);
- }
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
@@ -124,14 +61,6 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
struct wd_sglpool_setup sp;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -145,12 +74,22 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
+ return 0;
+ }
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
+ goto out_with_queues;
+ }
+
+ qinfo = sched->qs[i].qinfo;
pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -162,15 +101,18 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
qinfo->br.iova_map = (void *)wd_blk_iova_map;
qinfo->br.iova_unmap = (void *)wd_blk_iova_unmap;
qinfo->br.usr = pool;
- } else { /* use sgl*/
- memset(&sp, 0, sizeof(sp));
- sp.buf_size = sched->msg_data_size / 10;
- sp.align_size = 64;
- sp.sge_num_in_sgl = 60;
- sp.buf_num_in_sgl = sp.sge_num_in_sgl;
- sp.sgl_num = 3 * sched->msg_cache_num;
- sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
-
+ }
+ } else { /* use sgl*/
+ memset(&sp, 0, sizeof(sp));
+ sp.buf_size = sched->msg_data_size / 10;
+ sp.align_size = 64;
+ sp.sge_num_in_sgl = 60;
+ sp.buf_num_in_sgl = sp.sge_num_in_sgl;
+ sp.sgl_num = 3 * sched->msg_cache_num;
+ sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
pool = wd_sglpool_create(&sched->qs[0], &sp);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -189,17 +131,132 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
+
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ } else { /* use sgl */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_sgl(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_sgl(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
+
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
+ qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
+ flags = qinfo->dev_flags;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ } else { /* use sgl */
+ sched->msgs[j].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
+ sched->msgs[j].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ }
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j, data_fmt);
+ }
+ }
+
+ return 0;
+
+err_with_stat:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched, data_fmt);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
{
@@ -211,57 +268,22 @@ int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
if (ret < 0)
return -EINVAL;
- qinfo = sched->qs[0].qinfo;
- flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
- }
- }
- }
-
sched->cl = sched->msg_cache_num;
ret = __init_cache(sched, data_fmt);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched, data_fmt);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched, data_fmt);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched, data_fmt);
}
static int __sync_send(struct wd_scheduler *sched)
@@ -350,4 +372,4 @@ int wd_sched_work(struct wd_scheduler *sched, int remained)
}
return sched->cl;
-}
\ No newline at end of file
+}
diff --git a/v1/test/test_mm/test_wd_mem.c b/v1/test/test_mm/test_wd_mem.c
index 09824b99..e2eec60e 100644
--- a/v1/test/test_mm/test_wd_mem.c
+++ b/v1/test/test_mm/test_wd_mem.c
@@ -208,10 +208,10 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo1.q, &rsa_q);
+ ret = wd_request_queue(&pdata->qinfo1.q);
if (ret) {
wd_release_queue(&rsa_q);
- MMT_PRT("Proc-%d, thrd-%d:share mem on rsa queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:rsa queue fail!\n",
pid, thread_id);
return NULL;
}
@@ -226,9 +226,9 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo2.q, &zlib_q);
+ ret = wd_request_queue(&pdata->qinfo2.q);
if (ret) {
- MMT_PRT("Proc-%d, thrd-%d:share mem on zlib queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:zlib queue fail!\n",
pid, thread_id);
goto fail_release;
diff --git a/v1/test/wd_sched.c b/v1/test/wd_sched.c
index f5e46699..ce1d2604 100644
--- a/v1/test/wd_sched.c
+++ b/v1/test/wd_sched.c
@@ -22,94 +22,40 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched)
{
- int ret, i, j;
+ struct wd_blkpool_setup mm_setup;
unsigned int flags = 0;
struct q_info *qinfo;
- struct wd_blkpool_setup mm_setup;
+ int ret, i, j;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -120,18 +66,29 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
sched->ss_region = malloc(sched->ss_region_size);
if (!sched->ss_region) {
WD_ERR("fail to alloc sched ss region mem!\n");
+ return -ENOMEM;
+ }
+ return 0;
+ }
+
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
- pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
+
+ qinfo = sched->qs[i].qinfo;
+ pool = wd_blkpool_create(&sched->qs[i], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
ret = -ENOMEM;
+ wd_release_queue(&sched->qs[i]);
goto out_with_queues;
}
qinfo->br.alloc = (void *)wd_alloc_blk;
@@ -144,79 +101,135 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
-int wd_sched_init(struct wd_scheduler *sched)
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched)
{
- int ret, j, k;
- unsigned int flags;
struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
- ret = wd_sched_preinit(sched);
- if (ret < 0)
- return -EINVAL;
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_alloc;
}
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j);
}
}
- sched->cl = sched->msg_cache_num;
+ return 0;
+
+err_with_alloc:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
+
+int wd_sched_init(struct wd_scheduler *sched)
+{
+ int ret;
+ ret = wd_sched_preinit(sched);
+ if (ret < 0)
+ return -EINVAL;
+
+ sched->cl = sched->msg_cache_num;
ret = __init_cache(sched);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched);
}
static int __sync_send(struct wd_scheduler *sched)
--
2.33.0
1
0
13 Jun '25
From: Longfang Liu <liulongfang(a)huawei.com>
After removing the shared queue memory allocation interface, the UADK
test tools must also eliminate the shared memory functionality.
For individual memory reservations, the wd_reserve_memory interface
should be used. When allocating memory for multiple queues, each queue
should independently request its own reserved memory allocation.
Signed-off-by: Longfang Liu <liulongfang(a)huawei.com>
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 -----------------------
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 +++++++++---------
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +++++++-------
4 files changed, 300 insertions(+), 657 deletions(-)
diff --git a/v1/test/hisi_hpre_test/hpre_test_tools.c b/v1/test/hisi_hpre_test/hpre_test_tools.c
index 7f562f34..10a4ade9 100755
--- a/v1/test/hisi_hpre_test/hpre_test_tools.c
+++ b/v1/test/hisi_hpre_test/hpre_test_tools.c
@@ -644,317 +644,6 @@ int application_release_multiple_queue(char *dev, char *alg_type, unsigned int q
printf("application_release_multiple_queue test end!\n");
return 0;
}
-
-/***
-
-***/
-int hpre_dev_queue_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_node_queue_share(char *dev, unsigned int node, unsigned int share_node, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
- q.node_mask = node;
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return 1;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- target_q.node_mask = node;
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- //target_q队列共享q队列预留内存;
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on target q fail!\n");
- return 1;
- }
-
- ret = wd_share_reserved_memory(&q, &target_q);
-
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
- ret = do_dh(&q);
- if(ret)
- {
- printf("do dh on share q fail!\n");
- return 1;
- }
- ret = do_dh(&target_q);
- if(ret)
- {
- printf("do dh on share target q fail!\n");
- return 1;
- }
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-/***
-
-***/
-int hpre_dev_queue_interact_share(char *dev, char * share_dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size;
-
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("wd request queue fail!\n");
- return ret;
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", share_dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- addr = wd_reserve_memory(&target_q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd reserve memory fail!\n");
- return 1;
- }
- printf("wd reserve memory success!\n");
- memset(addr, 0, memory_size);
-
- //target_q
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&q);
- wd_release_queue(&target_q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
-/***
-
-***/
-int hpre_dev_queue_cross_proc_share(char *dev, char *alg_type, unsigned long m_size)
-{
- void *addr=NULL;
- int ret = 0;
- pid_t pid;
- struct wd_queue q;
- struct wd_queue target_q;
- unsigned long memory_size=0;
-
- pid = fork();
- if(pid < 0)
- {
- printf("Creation process failed, pid:%d\n",pid);
- return 1;
- }
- else if(pid == 0)
- {
- printf("child process:%d\n", pid);
- memset((void *)&q, 0, sizeof(q));
- q.capa.alg = alg_type;
- snprintf(q.dev_path, sizeof(q.dev_path), "%s", dev);
- printf("queue path:%s\n", q.dev_path);
-
- ret = wd_request_queue(&q);
- if(ret)
- {
- printf("request queue fail!\n");
- exit(1);
- }
- printf("wd request queue success!\n");
- memory_size = m_size;
- addr = wd_reserve_memory(&q, memory_size);
- if(!addr)
- {
- wd_release_queue(&q);
- printf("queue reserve memory fail!\n");
- exit(2);
- }
- printf("queue reserve memory success!\n");
- memset(addr, 0, memory_size);
- exit(0);
- }
- printf("parent process:%d\n", pid);
- pid_t wpid;
- int status = -1;
- wpid = waitpid(pid, &status, WUNTRACED | WCONTINUED);
- if( wpid < 0)
- {
- printf("exited, status=%d\n", WEXITSTATUS(status));
- return(status);
- }
-
- memset((void *)&target_q, 0, sizeof(target_q));
- target_q.capa.alg = alg_type;
- snprintf(target_q.dev_path, sizeof(target_q.dev_path), "%s", dev);
- printf("target queue path:%s\n", target_q.dev_path);
-
- ret = wd_request_queue(&target_q);
- if(ret)
- {
- wd_release_queue(&q);
- printf("wd request target_q queue fail!\n");
- return 1;
- }
- printf("wd request target_q queue success!\n");
- ret = wd_share_reserved_memory(&q, &target_q);
- if(ret)
- {
- wd_release_queue(&target_q);
- wd_release_queue(&q);
- printf("wd target_q queue share reserved memory fail!\n");
- return 1;
- }
- printf("wd target_q queue share reserved memory success!\n");
-
- wd_release_queue(&target_q);
- wd_release_queue(&q);
-
- return 0;
-}
-
/***
***/
@@ -1696,87 +1385,6 @@ int main(int arc, char *argv[])
return 1;
}
}
- else if(!strcmp(argv[1], "queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "node-queue-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示设备node
- argv[5] - 表示共享内存设备node
- argv[6] - 表示申请队列的预留内存大小
- ***/
- //申请单个队列,预留内存,与其它队列共享预留内存
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- unsigned int node=0;
- node = strtoul(argv[4], NULL, 16);
- unsigned int share_node=0;
- share_node = strtoul(argv[5], NULL, 16);
- memory_size = strtoul(argv[6], NULL, 10);
-
- ret = hpre_node_queue_share(dev, node, share_node, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-interact-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示共享预留内存的设备
- argv[5] - 表示申请队列的预留内存大小
- ***/
- //队列预留内存后作为共享的目标队列
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- snprintf(share_dev, sizeof(share_dev), "%s", argv[4]);
- memory_size = strtoul(argv[5], NULL, 10);
-
- ret = hpre_dev_queue_interact_share(dev, share_dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
- else if(!strcmp(argv[1], "queue-cross-proc-share"))
- {
- /***
- argv[2] - 表示算法类型
- argv[3] - 表示申请队列设备
- argv[4] - 表示申请队列的预留内存大小
- ***/
- //跨进程进行队列共享
- snprintf(algorithm_type, sizeof(algorithm_type), "%s", argv[2]);
- snprintf(dev, sizeof(dev), "%s", argv[3]);
- memory_size = strtoul(argv[4], NULL, 10);
- ret = hpre_dev_queue_cross_proc_share(dev, algorithm_type, memory_size);
- if(0 != ret)
- {
- return 1;
- }
- }
else if(!strcmp(argv[1], "mult-thread-queue"))
{
/***
diff --git a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
index 31637565..7a3be22c 100644
--- a/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
+++ b/v1/test/hisi_zip_test_sgl/wd_sched_sgl.c
@@ -23,96 +23,33 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
- } else { /* use sgl */
- sched->msgs[i].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
- sched->msgs[i].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
- }
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i, data_fmt);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- } else { /* use sgl */
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_sgl(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_sgl(pool, sched->msgs[i].data_out);
- }
- wd_sglpool_destroy(pool);
- }
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
@@ -124,14 +61,6 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
struct wd_sglpool_setup sp;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -145,12 +74,22 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
+ return 0;
+ }
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer*/
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
+ goto out_with_queues;
+ }
+
+ qinfo = sched->qs[i].qinfo;
pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -162,15 +101,18 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
qinfo->br.iova_map = (void *)wd_blk_iova_map;
qinfo->br.iova_unmap = (void *)wd_blk_iova_unmap;
qinfo->br.usr = pool;
- } else { /* use sgl*/
- memset(&sp, 0, sizeof(sp));
- sp.buf_size = sched->msg_data_size / 10;
- sp.align_size = 64;
- sp.sge_num_in_sgl = 60;
- sp.buf_num_in_sgl = sp.sge_num_in_sgl;
- sp.sgl_num = 3 * sched->msg_cache_num;
- sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
-
+ }
+ } else { /* use sgl*/
+ memset(&sp, 0, sizeof(sp));
+ sp.buf_size = sched->msg_data_size / 10;
+ sp.align_size = 64;
+ sp.sge_num_in_sgl = 60;
+ sp.buf_num_in_sgl = sp.sge_num_in_sgl;
+ sp.sgl_num = 3 * sched->msg_cache_num;
+ sp.buf_num = sp.buf_num_in_sgl * sp.sgl_num + sp.sgl_num * 2;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
pool = wd_sglpool_create(&sched->qs[0], &sp);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
@@ -189,17 +131,132 @@ static int wd_sched_preinit(struct wd_scheduler *sched, int data_fmt)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ if (data_fmt == WD_FLAT_BUF)
+ wd_blkpool_destroy(qinfo->br.usr);
+ else
+ wd_sglpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
+
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ } else { /* use sgl */
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_sgl(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_sgl(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched, int data_fmt)
+{
+ struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
+
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
+ qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
+ flags = qinfo->dev_flags;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ if (data_fmt == WD_FLAT_BUF) { /* use pbuffer */
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ } else { /* use sgl */
+ sched->msgs[j].data_in = wd_alloc_sgl(pool, sched->msg_data_size);
+ sched->msgs[j].data_out = wd_alloc_sgl(pool, sched->msg_data_size);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_stat;
+ }
+ }
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j, data_fmt);
+ }
+ }
+
+ return 0;
+
+err_with_stat:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched, data_fmt);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
{
@@ -211,57 +268,22 @@ int wd_sched_init(struct wd_scheduler *sched, int data_fmt)
if (ret < 0)
return -EINVAL;
- qinfo = sched->qs[0].qinfo;
- flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
- }
- }
- }
-
sched->cl = sched->msg_cache_num;
ret = __init_cache(sched, data_fmt);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched, data_fmt);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched, int data_fmt)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched, data_fmt);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched, data_fmt);
}
static int __sync_send(struct wd_scheduler *sched)
@@ -350,4 +372,4 @@ int wd_sched_work(struct wd_scheduler *sched, int remained)
}
return sched->cl;
-}
\ No newline at end of file
+}
diff --git a/v1/test/test_mm/test_wd_mem.c b/v1/test/test_mm/test_wd_mem.c
index 09824b99..e2eec60e 100644
--- a/v1/test/test_mm/test_wd_mem.c
+++ b/v1/test/test_mm/test_wd_mem.c
@@ -208,10 +208,10 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo1.q, &rsa_q);
+ ret = wd_request_queue(&pdata->qinfo1.q);
if (ret) {
wd_release_queue(&rsa_q);
- MMT_PRT("Proc-%d, thrd-%d:share mem on rsa queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:rsa queue fail!\n",
pid, thread_id);
return NULL;
}
@@ -226,9 +226,9 @@ void *mmt_sys_test_thread(void *data)
return NULL;
}
- ret = wd_share_reserved_memory(pdata->qinfo2.q, &zlib_q);
+ ret = wd_request_queue(&pdata->qinfo2.q);
if (ret) {
- MMT_PRT("Proc-%d, thrd-%d:share mem on zlib queue fail!\n",
+ MMT_PRT("Proc-%d, thrd-%d:zlib queue fail!\n",
pid, thread_id);
goto fail_release;
diff --git a/v1/test/wd_sched.c b/v1/test/wd_sched.c
index f5e46699..ce1d2604 100644
--- a/v1/test/wd_sched.c
+++ b/v1/test/wd_sched.c
@@ -22,94 +22,40 @@
#define EXTRA_SIZE 4096
#define WD_WAIT_MS 1000
-static int __init_cache(struct wd_scheduler *sched)
+static int wd_sched_pre_uninit(struct wd_scheduler *sched)
{
- int i;
- int ret = -ENOMEM;
+ unsigned int flags = 0;
struct q_info *qinfo;
void *pool;
+ int i;
- sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
- if (!sched->msgs) {
- WD_ERR("calloc for sched->msgs fail!\n");
- return ret;
- }
- sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
- if (!sched->stat) {
- WD_ERR("calloc for sched->stat fail!\n");
- goto err_with_msgs;
- }
qinfo = sched->qs[0].qinfo;
- pool = qinfo->br.usr;
- for (i = 0; i < sched->msg_cache_num; i++) {
- sched->msgs[i].data_in = wd_alloc_blk(pool);
- sched->msgs[i].data_out = wd_alloc_blk(pool);
- if (!sched->msgs[i].data_in || !sched->msgs[i].data_out) {
- dbg("not enough data ss_region memory "
- "for cache %d (bs=%d)\n", i, sched->msg_data_size);
- goto err_with_stat;
+ flags = qinfo->dev_flags;
+ if (flags & WD_UACCE_DEV_PASID) {
+ if (sched->ss_region) {
+ free(sched->ss_region);
+ sched->ss_region = NULL;
}
+ return 0;
+ }
- if (sched->init_cache)
- sched->init_cache(sched, i);
+ for (i = 0; i < sched->q_num; i++) {
+ wd_release_queue(&sched->qs[i]);
+ qinfo = sched->qs[i].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
}
return 0;
-
-err_with_stat:
- free(sched->stat);
- sched->stat = NULL;
-err_with_msgs:
- free(sched->msgs);
- sched->msgs = NULL;
- return ret;
-}
-
-static void __fini_cache(struct wd_scheduler *sched)
-{
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
- void *pool;
- int i;
-
- if (sched->stat) {
- free(sched->stat);
- sched->stat = NULL;
- }
- if (!(flags & WD_UACCE_DEV_PASID)) {
- pool = qinfo->br.usr;
- if (pool) {
- for (i = 0; i < sched->msg_cache_num; i++) {
- if (sched->msgs[i].data_in)
- wd_free_blk(pool, sched->msgs[i].data_in);
- if (sched->msgs[i].data_out)
- wd_free_blk(pool, sched->msgs[i].data_out);
- }
- wd_blkpool_destroy(pool);
- }
- }
- if (sched->msgs) {
- free(sched->msgs);
- sched->msgs = NULL;
- }
}
static int wd_sched_preinit(struct wd_scheduler *sched)
{
- int ret, i, j;
+ struct wd_blkpool_setup mm_setup;
unsigned int flags = 0;
struct q_info *qinfo;
- struct wd_blkpool_setup mm_setup;
+ int ret, i, j;
void *pool;
- for (i = 0; i < sched->q_num; i++) {
- ret = wd_request_queue(&sched->qs[i]);
- if (ret) {
- WD_ERR("fail to request queue!\n");
- goto out_with_queues;
- }
- }
-
if (!sched->ss_region_size)
sched->ss_region_size = EXTRA_SIZE + /* add 1 page extra */
sched->msg_cache_num * (sched->msg_data_size << 0x1);
@@ -120,18 +66,29 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
sched->ss_region = malloc(sched->ss_region_size);
if (!sched->ss_region) {
WD_ERR("fail to alloc sched ss region mem!\n");
+ return -ENOMEM;
+ }
+ return 0;
+ }
+
+ memset(&mm_setup, 0, sizeof(mm_setup));
+ mm_setup.block_size = sched->msg_data_size;
+ mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
+ mm_setup.align_size = 128;
+ for (i = 0; i < sched->q_num; i++) {
+ ret = wd_request_queue(&sched->qs[i]);
+ if (ret) {
+ WD_ERR("fail to request queue!\n");
ret = -ENOMEM;
goto out_with_queues;
}
- } else {
- memset(&mm_setup, 0, sizeof(mm_setup));
- mm_setup.block_size = sched->msg_data_size;
- mm_setup.block_num = sched->msg_cache_num << 0x1; /* in and out */
- mm_setup.align_size = 128;
- pool = wd_blkpool_create(&sched->qs[0], &mm_setup);
+
+ qinfo = sched->qs[i].qinfo;
+ pool = wd_blkpool_create(&sched->qs[i], &mm_setup);
if (!pool) {
WD_ERR("%s(): create pool fail!\n", __func__);
ret = -ENOMEM;
+ wd_release_queue(&sched->qs[i]);
goto out_with_queues;
}
qinfo->br.alloc = (void *)wd_alloc_blk;
@@ -144,79 +101,135 @@ static int wd_sched_preinit(struct wd_scheduler *sched)
return 0;
out_with_queues:
+ for (j = i-1; j >= 0; j--) {
+ wd_release_queue(&sched->qs[j]);
+ qinfo = sched->qs[j].qinfo;
+ wd_blkpool_destroy(qinfo->br.usr);
+ }
+
if (flags & WD_UACCE_DEV_PASID) {
if (sched->ss_region) {
free(sched->ss_region);
sched->ss_region = NULL;
}
}
- for (j = i-1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
+
return ret;
}
+static void __fini_cache(struct wd_scheduler *sched)
+{
+ struct q_info *qinfo = sched->qs[0].qinfo;
+ unsigned int flags = qinfo->dev_flags;
+ void *pool;
+ int i, j;
-int wd_sched_init(struct wd_scheduler *sched)
+ if (sched->stat) {
+ free(sched->stat);
+ sched->stat = NULL;
+ }
+
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+
+ if (!(flags & WD_UACCE_DEV_PASID)) {
+ for (j = 0; j < sched->q_num; j++) {
+ qinfo = sched->qs[j].qinfo;
+ pool = qinfo->br.usr;
+ if (!pool)
+ continue;
+
+ for (i = 0; i < sched->msg_cache_num; i++) {
+ if (sched->msgs[i].data_in)
+ wd_free_blk(pool, sched->msgs[i].data_in);
+ if (sched->msgs[i].data_out)
+ wd_free_blk(pool, sched->msgs[i].data_out);
+ }
+ }
+ }
+}
+
+static int __init_cache(struct wd_scheduler *sched)
{
- int ret, j, k;
- unsigned int flags;
struct q_info *qinfo;
+ unsigned int flags;
+ int ret = -ENOMEM;
+ int i, j;
+ void *pool;
- ret = wd_sched_preinit(sched);
- if (ret < 0)
- return -EINVAL;
+ sched->msgs = calloc(sched->msg_cache_num, sizeof(*sched->msgs));
+ if (!sched->msgs) {
+ WD_ERR("calloc for sched->msgs fail!\n");
+ return ret;
+ }
+ sched->stat = calloc(sched->q_num, sizeof(*sched->stat));
+ if (!sched->stat) {
+ WD_ERR("calloc for sched->stat fail!\n");
+ goto err_with_msgs;
+ }
qinfo = sched->qs[0].qinfo;
+ pool = qinfo->br.usr;
flags = qinfo->dev_flags;
- if (!(flags & WD_UACCE_DEV_PASID)) {
- for (k = 1; k < sched->q_num; k++) {
- ret = wd_share_reserved_memory(&sched->qs[0],
- &sched->qs[k]);
- if (ret) {
- WD_ERR("fail to share queue reserved mem!\n");
- goto out_with_queues;
+ if ((flags & WD_UACCE_DEV_PASID))
+ return 0;
+
+ for (i = 0; i < sched->q_num; i++) {
+ qinfo = sched->qs[i].qinfo;
+ pool = qinfo->br.usr;
+ for (j = 0; j < sched->msg_cache_num; j++) {
+ sched->msgs[j].data_in = wd_alloc_blk(pool);
+ sched->msgs[j].data_out = wd_alloc_blk(pool);
+ if (!sched->msgs[j].data_in || !sched->msgs[j].data_out) {
+ dbg("not enough data ss_region memory "
+ "for cache %d (bs=%d)\n", j, sched->msg_data_size);
+ goto err_with_alloc;
}
+
+ if (sched->init_cache)
+ sched->init_cache(sched, j);
}
}
- sched->cl = sched->msg_cache_num;
+ return 0;
+
+err_with_alloc:
+ free(sched->stat);
+ sched->stat = NULL;
+ __fini_cache(sched);
+err_with_msgs:
+ if (sched->msgs) {
+ free(sched->msgs);
+ sched->msgs = NULL;
+ }
+ return ret;
+}
+
+int wd_sched_init(struct wd_scheduler *sched)
+{
+ int ret;
+ ret = wd_sched_preinit(sched);
+ if (ret < 0)
+ return -EINVAL;
+
+ sched->cl = sched->msg_cache_num;
ret = __init_cache(sched);
if (ret) {
WD_ERR("fail to init caches!\n");
- goto out_with_queues;
+ wd_sched_pre_uninit(sched);
+ return -EINVAL;
}
return 0;
-
-out_with_queues:
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
- for (j = sched->q_num - 1; j >= 0; j--)
- wd_release_queue(&sched->qs[j]);
- return ret;
}
void wd_sched_fini(struct wd_scheduler *sched)
{
- int i;
- struct q_info *qinfo = sched->qs[0].qinfo;
- unsigned int flags = qinfo->dev_flags;
-
__fini_cache(sched);
- if (flags & WD_UACCE_DEV_PASID) {
- if (sched->ss_region) {
- free(sched->ss_region);
- sched->ss_region = NULL;
- }
- }
-
- for (i = sched->q_num - 1; i >= 0; i--)
- wd_release_queue(&sched->qs[i]);
+ wd_sched_pre_uninit(sched);
}
static int __sync_send(struct wd_scheduler *sched)
--
2.33.0
1
0
*** BLURB HERE ***
Chenghai Huang (6):
uadk:remove the data consumption modifying when copying cache output
uadk: add the function of parsing the cached tail packets
uadk: add the function of parsing the cached tail packets in v1
uadk: fix the windowbits setting issue in zlibwrapper
uadk: fix gzip windowbits and level setting issue in zlibwrapper
uadk: fix repeated initialization issue
Hao Fang (1):
uadk_tool: hpre: fix for x448/x25519 perf test failed
Longfang Liu (2):
uadk: removal of the Shared Memory Interface for Queues
uadk_tools: Removal of the Shared Memory Interface for Queues
Qi Tao (1):
uadk: fix code cleanup issues
Super User (1):
uadk: the uadk_tool is compiled using the private OpenSSL header file.
Zhiqi Song (1):
uadk/hpre: remove redundant null operation
Zhushuai Yin (3):
Uadk: Fix the DAE memory leak issue.
uadk: The MAX MIN and rehash functions are added to the hash agg.
Uadk: fix hash agg review comments
lizhi (8):
uadk: adapt ECDH for high-performance cores
uadk_tool: adapt ecdh benchmark with secp256r1 curve
uadk/hpre: fix up severel parameter type mismatch issues
uadk: check hardware type to config hpcore field
uadk_tool: update ECC curve in uadk_tool benchmark
uadk:fix some cleanup issues
uadk: fix potential null pointer dereference
uadk_tool: Fix x448 bug caused by wrong nid.
Makefile.am | 2 +
drv/hisi_comp.c | 54 +--
drv/hisi_comp_huf.c | 248 ++++++++++++++
drv/hisi_comp_huf.h | 19 ++
drv/hisi_dae.c | 244 ++++++++++++--
drv/hisi_hpre.c | 108 +++++-
drv/hisi_qm_udrv.h | 3 +-
include/drv/wd_agg_drv.h | 10 +-
include/drv/wd_ecc_drv.h | 10 +
include/wd_agg.h | 9 +-
include/wd_ecc_curve.h | 27 ++
include/wd_util.h | 2 +-
include/wd_zlibwrapper.h | 2 +-
uadk_tool/benchmark/hpre_uadk_benchmark.c | 58 ++--
uadk_tool/benchmark/hpre_wd_benchmark.c | 32 +-
uadk_tool/benchmark/sec_soft_benchmark.c | 20 +-
uadk_tool/benchmark/uadk_benchmark.h | 2 +-
uadk_tool/test/comp_lib.h | 2 +-
v1/drv/hisi_zip_huf.c | 248 ++++++++++++++
v1/drv/hisi_zip_huf.h | 19 ++
v1/drv/hisi_zip_udrv.c | 52 ++-
v1/test/hisi_hpre_test/hpre_test_tools.c | 392 ----------------------
v1/test/hisi_zip_test_sgl/wd_sched_sgl.c | 310 +++++++++--------
v1/test/test_mm/test_wd_mem.c | 8 +-
v1/test/wd_sched.c | 247 +++++++-------
v1/uacce.h | 1 -
v1/wd.c | 57 +---
v1/wd.h | 2 -
wd.c | 4 +-
wd_aead.c | 8 +-
wd_agg.c | 47 +--
wd_cipher.c | 16 +-
wd_comp.c | 6 +-
wd_dh.c | 4 +-
wd_digest.c | 7 +-
wd_ecc.c | 70 +++-
wd_rsa.c | 5 +-
wd_util.c | 6 +-
wd_zlibwrapper.c | 48 +--
39 files changed, 1473 insertions(+), 936 deletions(-)
create mode 100644 drv/hisi_comp_huf.c
create mode 100644 drv/hisi_comp_huf.h
create mode 100644 v1/drv/hisi_zip_huf.c
create mode 100644 v1/drv/hisi_zip_huf.h
--
2.33.0
1
23
您好!
sig-AccLib 邀请您参加 2025-06-11 11:00 召开的Zoom会议
会议主题:【2025/6/11 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/86361583097?pwd=PIujIKJR3JaIEl4pg3LAdclauyjQyy.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-06-11 11:00,
The subject of the conference is 【2025/6/11 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/86361583097?pwd=PIujIKJR3JaIEl4pg3LAdclauyjQyy.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
[PATCH 00/10] uadk_engine/provider: fixed static code alarms and code format issues.
by Qi Tao 05 Jun '25
by Qi Tao 05 Jun '25
05 Jun '25
From: JiangShui Yang <yangjiangshui(a)h-partners.com>
Chenghai Huang (4):
uadk_provider: fix some possible issues where empty memory is accessed
uadk_provider: adjust the code style
uadk_provider: fix the static variable problem in the case of multiple
concurrency
uadk_provider: add parameter validation to avoid memory errors
Hao Fang (6):
uadk_engine/provider: tinyfixes for code format alignment
uadk_engine/provider: add blank line before return
uadk_engine/provider: remove the variable redundant initialization
uadk_provider: add const keyword
uadk_provider: remove unused parameters
uadk_engine:sm2: use UADK_E_INVAL replace -1
src/uadk_aead.c | 2 +-
src/uadk_cipher.c | 13 +--
src/uadk_dh.c | 11 +--
src/uadk_digest.c | 24 +++---
src/uadk_ec.c | 6 ++
src/uadk_ecx.c | 4 +-
src/uadk_engine_init.c | 1 +
src/uadk_pkey.c | 9 ++-
src/uadk_pkey.h | 3 +-
src/uadk_prov_aead.c | 3 +-
src/uadk_prov_bio.c | 18 ++---
src/uadk_prov_cipher.c | 46 ++++++-----
src/uadk_prov_der_writer.c | 96 +++++++++++-----------
src/uadk_prov_der_writer.h | 8 +-
src/uadk_prov_dh.c | 89 +++++++++++----------
src/uadk_prov_digest.c | 23 +++---
src/uadk_prov_ec_kmgmt.c | 3 +-
src/uadk_prov_ecdh_exch.c | 21 +++--
src/uadk_prov_ecdsa.c | 8 +-
src/uadk_prov_ecx.c | 53 ++++++------
src/uadk_prov_ffc.c | 160 ++++++++++++++++++++-----------------
src/uadk_prov_ffc.h | 4 +-
src/uadk_prov_hmac.c | 20 ++---
src/uadk_prov_init.c | 10 +--
src/uadk_prov_packet.c | 48 ++++++-----
src/uadk_prov_packet.h | 52 ++++++------
src/uadk_prov_pkey.c | 63 ++++++++-------
src/uadk_prov_rsa.c | 82 +++++++++----------
src/uadk_prov_sm2.c | 135 ++++++++++++++++---------------
src/uadk_rsa.c | 31 +++----
src/uadk_sm2.c | 59 ++++++++------
31 files changed, 594 insertions(+), 511 deletions(-)
--
2.33.0
1
10
From: lizhi <lizhi206(a)huawei.com>
fix memory leak and avoid possible double-free risk in sm2.
Signed-off-by: lizhi <lizhi206(a)huawei.com>
---
src/uadk_sm2.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/uadk_sm2.c b/src/uadk_sm2.c
index 170d320..7737292 100644
--- a/src/uadk_sm2.c
+++ b/src/uadk_sm2.c
@@ -407,9 +407,12 @@ static int sign_bin_to_ber(EC_KEY *ec, struct wd_dtb *r, struct wd_dtb *s,
if (sltmp < 0) {
fprintf(stderr, "failed to i2d_ECDSA_SIG\n");
ret = -EINVAL;
- goto free_s;
+ /* bs and br set to e_sig, use unified interface to prevent double release. */
+ goto free_sig;
}
+
*siglen = (size_t)sltmp;
+ ECDSA_SIG_free(e_sig);
return 0;
free_s:
@@ -417,7 +420,6 @@ free_s:
free_r:
BN_clear_free(br);
free_sig:
- ECDSA_SIG_set0(e_sig, NULL, NULL);
ECDSA_SIG_free(e_sig);
return ret;
--
2.33.0
1
1
Fixed the following issues:
1. Remove redundant function return value check.
2. Modify inappropriate exception printing.
3. There is no need to check the return value of
async_wake_job(). Only need to check req->state to
determine if there is an exception in packet reception.
Therefore, add "(void)" before the function call.
4. Free the allocated memory before returning an error.
5. The callback function's parameter list does not match
the function pointer definition.
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
src/uadk_aead.c | 4 ++--
src/uadk_async.c | 2 +-
src/uadk_cipher.c | 6 +-----
src/uadk_dh.c | 2 +-
src/uadk_digest.c | 2 +-
src/uadk_pkey.c | 2 +-
src/uadk_prov_aead.c | 4 ++--
src/uadk_prov_cipher.c | 4 ++--
src/uadk_prov_dh.c | 2 +-
src/uadk_prov_digest.c | 6 +++---
src/uadk_prov_hmac.c | 6 +++---
src/uadk_prov_init.c | 4 +++-
src/uadk_prov_pkey.c | 2 +-
src/uadk_prov_rsa.c | 2 +-
src/uadk_rsa.c | 2 +-
15 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/src/uadk_aead.c b/src/uadk_aead.c
index 1da7753..69223f1 100644
--- a/src/uadk_aead.c
+++ b/src/uadk_aead.c
@@ -469,7 +469,7 @@ static int do_aead_sync_inner(struct aead_priv_ctx *priv, unsigned char *out,
priv->req.state = 0;
ret = wd_do_aead_sync(priv->sess, &priv->req);
if (unlikely(ret < 0 || priv->req.state)) {
- fprintf(stderr, "do aead task failed, msg state: %d, ret: %d, state: %u!\n",
+ fprintf(stderr, "do aead task failed, msg state: %u, ret: %d, state: %u!\n",
state, ret, priv->req.state);
return RET_FAIL;
}
@@ -547,7 +547,7 @@ static void *uadk_e_aead_cb(struct wd_aead_req *req, void *data)
if (op && op->job && !op->done) {
op->done = 1;
async_free_poll_task(op->idx, 1);
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
}
return NULL;
diff --git a/src/uadk_async.c b/src/uadk_async.c
index 7536bd5..0f92dde 100644
--- a/src/uadk_async.c
+++ b/src/uadk_async.c
@@ -329,7 +329,7 @@ static void *async_poll_process_func(void *args)
if (!poll_queue.is_recv && op->job) {
op->done = 1;
op->ret = ret;
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
async_free_poll_task(idx, 0);
}
}
diff --git a/src/uadk_cipher.c b/src/uadk_cipher.c
index 457e90d..95af193 100644
--- a/src/uadk_cipher.c
+++ b/src/uadk_cipher.c
@@ -242,10 +242,6 @@ static int uadk_e_cipher_soft_work(EVP_CIPHER_CTX *ctx, unsigned char *out,
*/
if (!priv->update_iv) {
iv = EVP_CIPHER_CTX_iv_noconst(ctx);
- if (unlikely(iv == NULL)) {
- fprintf(stderr, "get openssl software iv failed.\n");
- return 0;
- }
memcpy(iv, priv->iv, EVP_CIPHER_CTX_iv_length(ctx));
priv->update_iv = true;
}
@@ -567,7 +563,7 @@ static void *uadk_e_cipher_cb(struct wd_cipher_req *req, void *data)
if (op && op->job && !op->done) {
op->done = 1;
async_free_poll_task(op->idx, 1);
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
}
return NULL;
diff --git a/src/uadk_dh.c b/src/uadk_dh.c
index 2f2c1cf..011bf56 100644
--- a/src/uadk_dh.c
+++ b/src/uadk_dh.c
@@ -259,7 +259,7 @@ static void uadk_e_dh_cb(void *req_t)
if (op && op->job && !op->done) {
op->done = 1;
async_free_poll_task(op->idx, 1);
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
}
}
diff --git a/src/uadk_digest.c b/src/uadk_digest.c
index 6827f98..0b4e8c5 100644
--- a/src/uadk_digest.c
+++ b/src/uadk_digest.c
@@ -802,7 +802,7 @@ static void *uadk_e_digest_cb(void *data)
if (op && op->job && !op->done) {
op->done = 1;
async_free_poll_task(op->idx, 1);
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
}
return NULL;
diff --git a/src/uadk_pkey.c b/src/uadk_pkey.c
index 1f8234b..e05c7d0 100644
--- a/src/uadk_pkey.c
+++ b/src/uadk_pkey.c
@@ -101,7 +101,7 @@ void uadk_e_ecc_cb(void *req_t)
op->done = 1;
op->ret = 0;
async_free_poll_task(op->idx, 1);
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
}
}
diff --git a/src/uadk_prov_aead.c b/src/uadk_prov_aead.c
index 54e0115..dbbd844 100644
--- a/src/uadk_prov_aead.c
+++ b/src/uadk_prov_aead.c
@@ -390,7 +390,7 @@ static void *uadk_prov_aead_cb(struct wd_aead_req *req, void *data)
if (op && op->job && !op->done) {
op->done = 1;
async_free_poll_task(op->idx, 1);
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
}
return NULL;
@@ -800,7 +800,7 @@ static int uadk_get_aead_info(struct aead_priv_ctx *priv)
}
if (unlikely(i == aead_counts)) {
- fprintf(stderr, "failed to setup the private ctx.\n");
+ fprintf(stderr, "failed to get aead info.\n");
return UADK_AEAD_FAIL;
}
diff --git a/src/uadk_prov_cipher.c b/src/uadk_prov_cipher.c
index db4a957..dfe6666 100644
--- a/src/uadk_prov_cipher.c
+++ b/src/uadk_prov_cipher.c
@@ -395,7 +395,7 @@ static int uadk_get_cipher_info(struct cipher_priv_ctx *priv)
}
}
- fprintf(stderr, "failed to setup the private ctx.\n");
+ fprintf(stderr, "failed to get cipher info.\n");
return UADK_P_FAIL;
}
@@ -455,7 +455,7 @@ static void async_cb(struct wd_cipher_req *req, void *data)
if (op && op->job && !op->done) {
op->done = 1;
async_free_poll_task(op->idx, 1);
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
}
}
diff --git a/src/uadk_prov_dh.c b/src/uadk_prov_dh.c
index c75c386..1cb4b45 100644
--- a/src/uadk_prov_dh.c
+++ b/src/uadk_prov_dh.c
@@ -581,7 +581,7 @@ static void uadk_prov_dh_cb(void *req_t)
if (op && op->job && !op->done) {
op->done = 1;
async_free_poll_task(op->idx, 1);
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
}
}
diff --git a/src/uadk_prov_digest.c b/src/uadk_prov_digest.c
index 7a5bfff..a13d075 100644
--- a/src/uadk_prov_digest.c
+++ b/src/uadk_prov_digest.c
@@ -303,7 +303,7 @@ static int uadk_get_digest_info(struct digest_priv_ctx *priv)
}
if (unlikely(i == digest_counts)) {
- fprintf(stderr, "failed to setup the private ctx.\n");
+ fprintf(stderr, "failed to digest info.\n");
return UADK_DIGEST_FAIL;
}
@@ -534,7 +534,7 @@ soft_update:
return uadk_digest_soft_update(priv, data, data_len);
}
-static void uadk_async_cb(struct wd_digest_req *req, void *data)
+static void uadk_async_cb(struct wd_digest_req *req)
{
struct uadk_e_cb_info *digest_cb_param;
struct wd_digest_req *req_origin;
@@ -550,7 +550,7 @@ static void uadk_async_cb(struct wd_digest_req *req, void *data)
if (op && op->job && !op->done) {
op->done = 1;
async_free_poll_task(op->idx, 1);
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
}
}
diff --git a/src/uadk_prov_hmac.c b/src/uadk_prov_hmac.c
index db49612..6bf7947 100644
--- a/src/uadk_prov_hmac.c
+++ b/src/uadk_prov_hmac.c
@@ -361,7 +361,7 @@ static int uadk_get_hmac_info(struct hmac_priv_ctx *priv)
}
}
- fprintf(stderr, "failed to setup the private ctx, algname = %s.\n", priv->alg_name);
+ fprintf(stderr, "failed to get hmac info, algname = %s.\n", priv->alg_name);
return UADK_HMAC_FAIL;
}
@@ -529,7 +529,7 @@ soft_init:
return uadk_hmac_soft_init(priv);
}
-static void uadk_hmac_async_cb(struct wd_digest_req *req, void *data)
+static void uadk_hmac_async_cb(struct wd_digest_req *req)
{
struct uadk_e_cb_info *hmac_cb_param;
struct wd_digest_req *req_origin;
@@ -545,7 +545,7 @@ static void uadk_hmac_async_cb(struct wd_digest_req *req, void *data)
if (op && op->job && !op->done) {
op->done = 1;
async_free_poll_task(op->idx, 1);
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
}
}
diff --git a/src/uadk_prov_init.c b/src/uadk_prov_init.c
index c29500b..20f7068 100644
--- a/src/uadk_prov_init.c
+++ b/src/uadk_prov_init.c
@@ -470,8 +470,10 @@ int OSSL_provider_init(const OSSL_CORE_HANDLE *handle,
ctx->libctx = (OSSL_LIB_CTX *)c_get_libctx(handle);
ret = uadk_prov_ctx_set_core_bio_method(ctx);
- if (!ret)
+ if (!ret) {
+ OPENSSL_free(ctx);
return UADK_P_FAIL;
+ }
ret = async_module_init();
if (!ret)
diff --git a/src/uadk_prov_pkey.c b/src/uadk_prov_pkey.c
index ca853ae..ac4541c 100644
--- a/src/uadk_prov_pkey.c
+++ b/src/uadk_prov_pkey.c
@@ -362,7 +362,7 @@ void uadk_prov_ecc_cb(void *req_t)
ecc_async_op->done = 1;
ecc_async_op->ret = 0;
async_free_poll_task(ecc_async_op->idx, 1);
- async_wake_job(ecc_async_op->job);
+ (void)async_wake_job(ecc_async_op->job);
}
}
diff --git a/src/uadk_prov_rsa.c b/src/uadk_prov_rsa.c
index b9713cc..4351514 100644
--- a/src/uadk_prov_rsa.c
+++ b/src/uadk_prov_rsa.c
@@ -1275,7 +1275,7 @@ static void uadk_e_rsa_cb(void *req_t)
if (op && op->job && !op->done) {
op->done = 1;
async_free_poll_task(op->idx, 1);
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
}
}
diff --git a/src/uadk_rsa.c b/src/uadk_rsa.c
index 76678a4..1755374 100644
--- a/src/uadk_rsa.c
+++ b/src/uadk_rsa.c
@@ -1117,7 +1117,7 @@ static void uadk_e_rsa_cb(void *req_t)
if (op && op->job && !op->done) {
op->done = 1;
async_free_poll_task(op->idx, 1);
- async_wake_job(op->job);
+ (void)async_wake_job(op->job);
}
}
--
2.33.0
1
0
您好!
sig-AccLib 邀请您参加 2025-05-28 11:00 召开的Zoom会议
会议主题:【2025/5/28 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:
linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/82863167501?pwd=tvnic0aWCxFSVFObmeHHXbN3gh2a8m.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-05-28 11:00,
The subject of the conference is 【2025/5/28 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接:
linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/82863167501?pwd=tvnic0aWCxFSVFObmeHHXbN3gh2a8m.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
From: JiangShui Yang <yangjiangshui(a)h-partners.com>
Chenghai Huang (5):
uadk_provider: adjust the threshold for SHA384 to use Digest to
Calculated key
uadk_provider: fix dh memery leak issue in free params
uadk_provider: fix rsa memery leak issue in bn_ctx_new
uadk_provider: rectify the soft switch contidition of RAS
uadk_provider: fix some compilation warning issues
Qi Tao (6):
uadk_prov: fix some cleancode issues
uadk_prov: the query returns the v3 alg array to handle exception
uadk_prov: modify the location of creating soft ctx
uadk_prov: fix memory leak error
uadk_engine: fix cleancode issues
uadk_prov: default to turn on the soft switch
Weili Qian (3):
uadk_engine: fix possible double free issues
uadk_engine/ecdh: remove unnecessary call uadk_ecc_set_public_key
uadk_provider/sm2: free all applied memory when freectx
Zhiqi Song (2):
uadk_engine/cipher: fixup the method of obtaining IV in init
uadk_engine/hpre: fixup some param release problem
Zhushuai Yin (1):
uadk_provider:fix dh insufficient performance
lizhi (5):
uadk_engine/ecdh: Pad the high bits of short shared keys with 0
uadk_provider/ecdh: Pad the high bits of short shared keys with 0
uadk_provider/ecx: fix memory leak of ecx_key
uadk_provider/sm2: Fix the race conditions caused by atomic variables
uadk_provider/sm2: fix a bug of switching soft compute
src/uadk_aead.c | 4 +-
src/uadk_async.c | 2 +-
src/uadk_cipher.c | 8 +-
src/uadk_dh.c | 4 +-
src/uadk_digest.c | 5 +-
src/uadk_ec.c | 52 +++---
src/uadk_pkey.c | 2 +-
src/uadk_prov.h | 4 +-
src/uadk_prov_aead.c | 43 +++--
src/uadk_prov_cipher.c | 38 +++--
src/uadk_prov_dh.c | 123 ++++++++------
src/uadk_prov_digest.c | 38 +++--
src/uadk_prov_ecdh_exch.c | 9 +-
src/uadk_prov_ecx.c | 29 ++--
src/uadk_prov_ffc.c | 170 +++++++++++++++++---
src/uadk_prov_ffc.h | 38 ++++-
src/uadk_prov_hmac.c | 8 +-
src/uadk_prov_init.c | 36 +++--
src/uadk_prov_pkey.c | 2 +-
src/uadk_prov_rsa.c | 138 ++++++++--------
src/uadk_prov_sm2.c | 331 ++++++++++++++++++++------------------
src/uadk_rsa.c | 2 +-
src/uadk_sm2.c | 10 +-
23 files changed, 678 insertions(+), 418 deletions(-)
--
2.33.0
1
22
From: Chenghai Huang <huangchenghai2(a)huawei.com>
The corresponding sending thread can be precisely woken
up only after the poll thread receiving succeeds.
When a hardware error occurs, asynchronous receiving will reture
an abnormal value. In this case, the corresponding sending
thread cannot be sure to woken up. Therefore, the counting
method is used to wake up the corresponding thread whose number
of failures exceeds the threshold.
Signed-off-by: Chenghai Huang <huangchenghai2(a)huawei.com>
---
src/uadk_async.c | 10 ++++++++++
src/uadk_async.h | 2 ++
2 files changed, 12 insertions(+)
diff --git a/src/uadk_async.c b/src/uadk_async.c
index 0f92dde..8adc964 100644
--- a/src/uadk_async.c
+++ b/src/uadk_async.c
@@ -327,6 +327,16 @@ static void *async_poll_process_func(void *args)
idx = op->idx;
ret = async_recv_func[task->type](task->ctx);
if (!poll_queue.is_recv && op->job) {
+ /*
+ * Wake up the op->job whose number of polling
+ * failures exceeds the threshold.
+ */
+ if (ret && ret != -ETIMEDOUT && op->retry++ < ASYNC_MAX_RETRY_CNT) {
+ (void)sem_post(&poll_queue.full_sem);
+ continue;
+ }
+
+ op->retry = 0;
op->done = 1;
op->ret = ret;
(void) async_wake_job(op->job);
diff --git a/src/uadk_async.h b/src/uadk_async.h
index 8de3c3c..23f017e 100644
--- a/src/uadk_async.h
+++ b/src/uadk_async.h
@@ -23,6 +23,7 @@
#include <openssl/async.h>
#define ASYNC_QUEUE_TASK_NUM 1024
+#define ASYNC_MAX_RETRY_CNT 1000
#define UADK_E_SUCCESS 1
#define UADK_E_FAIL 0
#define DO_SYNC 1
@@ -32,6 +33,7 @@ struct async_op {
int done;
int idx;
int ret;
+ int retry;
};
struct uadk_e_cb_info {
--
2.33.0
1
0
From: Hao Fang <fanghao11(a)huawei.com>
Signed-off-by: Hao Fang <fanghao11(a)huawei.com>
---
test/sanity_test.sh | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/test/sanity_test.sh b/test/sanity_test.sh
index 1c4b631..acc44a9 100755
--- a/test/sanity_test.sh
+++ b/test/sanity_test.sh
@@ -87,10 +87,10 @@ hw_blk_deflate()
case $3 in
"gzip")
${RM} -f /tmp/gzip_list.bin
- run_cmd uadk_tool test --m zip --in $1 --out $2 $@
+ run_cmd uadk_tool test --m zip --stream --in $1 --out $2 $@
;;
"zlib")
- run_cmd uadk_tool test --m zip --alg 1 --in $1 --out $2 $@
+ run_cmd uadk_tool test --m zip --stream --alg 1 --in $1 --out $2 $@
;;
*)
echo "Unsupported algorithm type: $3"
@@ -104,10 +104,10 @@ hw_blk_inflate()
{
case $3 in
"gzip")
- run_cmd uadk_tool test --m zip --inf --in $1 --out $2 $@
+ run_cmd uadk_tool test --m zip --stream --inf --in $1 --out $2 $@
;;
"zlib")
- run_cmd uadk_tool test --m zip --alg 1 --inf --in $1 --out $2 $@
+ run_cmd uadk_tool test --m zip --stream --alg 1 --inf --in $1 --out $2 $@
;;
*)
echo "Unsupported algorithm type: $3"
@@ -365,9 +365,9 @@ run_zip_test_v2()
WD_COMP_EPOLL_EN=1 hw_dfl_hw_ifl /tmp/syslog
WD_COMP_EPOLL_EN=0 hw_dfl_hw_ifl /tmp/syslog
# test without environment variables
- #run_cmd uadk_tool test --m zip --blksize 8192 --size 81920 --loop 1000 --self
+ #run_cmd uadk_tool test --m zip --stream --blksize 8192 --size 81920 --loop 1000 --self
# test with environment variables
- #run_cmd uadk_tool test --m zip --blksize 8192 --size 81920 --loop 1000 --self --env
+ #run_cmd uadk_tool test --m zip --stream --blksize 8192 --size 81920 --loop 1000 --self --env
}
# Accept more paraterms
--
2.33.0
1
0
From: Chenghai Huang <huangchenghai2(a)huawei.com>
When a hardware error occurs, asynchronous receiving will reture
an abnormal value. In this case, the corresponding sending
thread cannot be sure to woken up. Therefore, the counting
method is used to wake up the corresponding thread whose number
of failures exceeds the threshold.
Signed-off-by: Chenghai Huang <huangchenghai2(a)huawei.com>
---
src/uadk_async.c | 8 ++++++++
src/uadk_async.h | 2 ++
2 files changed, 10 insertions(+)
diff --git a/src/uadk_async.c b/src/uadk_async.c
index 0f92dde..947b4ee 100644
--- a/src/uadk_async.c
+++ b/src/uadk_async.c
@@ -326,6 +326,14 @@ static void *async_poll_process_func(void *args)
op = task->op;
idx = op->idx;
ret = async_recv_func[task->type](task->ctx);
+ if (ret && !poll_queue.is_recv) {
+ if (op->retry++ < ASYNC_MAX_RETRY_CNT) {
+ (void)sem_post(&poll_queue.full_sem);
+ continue;
+ }
+ op->retry = 0;
+ }
+
if (!poll_queue.is_recv && op->job) {
op->done = 1;
op->ret = ret;
diff --git a/src/uadk_async.h b/src/uadk_async.h
index 8de3c3c..23f017e 100644
--- a/src/uadk_async.h
+++ b/src/uadk_async.h
@@ -23,6 +23,7 @@
#include <openssl/async.h>
#define ASYNC_QUEUE_TASK_NUM 1024
+#define ASYNC_MAX_RETRY_CNT 1000
#define UADK_E_SUCCESS 1
#define UADK_E_FAIL 0
#define DO_SYNC 1
@@ -32,6 +33,7 @@ struct async_op {
int done;
int idx;
int ret;
+ int retry;
};
struct uadk_e_cb_info {
--
2.33.0
1
0
From: Hao Fang <fanghao11(a)huawei.com>
list_loader.py is for software comp test, but hw comp test
had remove the --list commands, the loopback test will be failed,
so list_loader.py also do the same thing.
Signed-off-by: Hao Fang <fanghao11(a)huawei.com>
---
test/list_loader.py | 71 ++++++++++++++-------------------------------
test/sanity_test.sh | 4 +--
2 files changed, 23 insertions(+), 52 deletions(-)
diff --git a/test/list_loader.py b/test/list_loader.py
index d5e1578..7373a88 100755
--- a/test/list_loader.py
+++ b/test/list_loader.py
@@ -13,22 +13,16 @@ class listcontent(object):
self.ofile_nm = ofile
self.ifile = open(ifile, "rb")
self.ofile = open(ofile, "wb")
- # addr: 8 bytes, size: 8 bytes, next: 8 bytes
- #self.entry_sz = 0x18;
- self.entry_addr = 0;
- self.entry_size = 0;
- self.entry_next = 0;
def __del__(self):
self.ifile.close()
self.ofile.close()
- def deflate(self, olist, blk_sz):
+ def deflate(self, blk_sz):
ifile_sz = os.path.getsize(self.ifile_nm)
count = (ifile_sz + int(blk_sz) - 1) / int(blk_sz)
# Create array
data = np.ndarray(count * 3, dtype=np.uint64)
- entries = data.reshape(-1, 3)
i = 0
while i < count:
# Each block of data is stored in temporary file that is used
@@ -44,33 +38,21 @@ class listcontent(object):
os.system("cat %s > %s" % (of.name, self.ofile_nm))
else:
os.system("cat %s >> %s" % (of.name, self.ofile_nm))
- # entries[i][0] should be the address of output buffer.
- # But the output is file now, not buffer. So fill it with
- # any non-zero value.
- entries[i][0] = 1
- entries[i][1] = os.path.getsize(of.name)
- if i == count - 1:
- entries[i][2] = 0
- else:
- entries[i][2] = 1
i += 1
os.remove(f.name)
os.remove(of.name)
- entries.tofile(olist)
- # Read block data from ifile by ilist. And inflate each block data.
- def inflate(self, ilist):
- self.ilist_nm = ilist
- data = np.fromfile(self.ilist_nm, dtype=np.uint64)
- # Each entry contains addr, size and next fields
- # Convert data array into the two dimensional array
- entries = data.reshape(-1, 3)
+ # Read block data from ifile. And inflate each block data.
+ def inflate(self):
+ ifile_sz = os.path.getsize(self.ifile_nm)
i = 0
- while i < entries.shape[0]:
+ while True:
# Each block of data is stored in temporary file that is used
# by gunzip.
f = tempfile.NamedTemporaryFile(delete=False)
- blk = self.ifile.read(entries[i][1])
+ blk = self.ifile.read(ifile_sz)
+ if not blk:
+ break
f.write(blk)
f.close()
if not i:
@@ -78,42 +60,31 @@ class listcontent(object):
else:
os.system("gunzip < %s >> %s" % (f.name, self.ofile_nm))
os.remove(f.name)
- if not entries[i][2]:
- break
i += 1
-def sw_deflate(ifile, ofile, olist, blk_sz):
+def sw_deflate(ifile, ofile, blk_sz):
dfl = listcontent(ifile, ofile)
- dfl.deflate(olist, blk_sz)
+ dfl.deflate(blk_sz)
-def sw_inflate(ifile, ofile, ilist):
+def sw_inflate(ifile, ofile):
ifl = listcontent(ifile, ofile)
- ifl.inflate(ilist)
+ ifl.inflate()
def main(argv):
- ilist = ''
- olist = ''
ifile = ''
ofile = ''
blk_sz = 0
try:
- opts, args = getopt.getopt(argv, "hb:", ["ilist=","olist=","in=","out="])
+ opts, args = getopt.getopt(argv, "hb:", ["in=","out="])
for opt, arg in opts:
if opt in ("-h"):
print('Software deflate command:')
- print(' list_loader -b <block size> --in <file> --out <file> --olist <file>')
+ print(' list_loader -b <block size> --in <file> --out <file>')
print('Software inflate command:')
- print(' list_loader --in <file> --out <file> --ilist <file>')
+ print(' list_loader --in <file> --out <file>')
sys.exit()
elif opt in ("-b"):
blk_sz = arg
- elif opt in ("--ilist"):
- if not os.path.isfile(arg):
- print("File does not exist:", arg)
- sys.exit(1)
- ilist = arg
- elif opt in ("--olist"):
- olist = arg
elif opt in ("--in"):
if not os.path.isfile(arg):
print("File does not exist:", arg)
@@ -122,18 +93,18 @@ def main(argv):
elif opt in ("--out"):
ofile = arg
except getopt.GetoptError:
- # Compress source to destination file and output list file
+ # Compress source to destination file
print('Software deflate command:')
- print(' list_loader -b <block size> --in <file> --out <file> --olist <file>')
- # Decompress source to destination file with input list file
+ print(' list_loader -b <block size> --in <file> --out <file>')
+ # Decompress source to destination file
print('Software inflate command:')
- print(' list_loader --in <file> --out <file> --ilist <file>')
+ print(' list_loader --in <file> --out <file>')
sys.exit(2)
if blk_sz:
- sw_deflate(ifile, ofile, olist, blk_sz)
+ sw_deflate(ifile, ofile, blk_sz)
else:
- sw_inflate(ifile, ofile, ilist)
+ sw_inflate(ifile, ofile)
if __name__ == "__main__":
main(sys.argv[1:])
diff --git a/test/sanity_test.sh b/test/sanity_test.sh
index 9ffb137..1c4b631 100755
--- a/test/sanity_test.sh
+++ b/test/sanity_test.sh
@@ -157,7 +157,7 @@ sw_blk_deflate()
case $3 in
"gzip")
${RM} -f /tmp/gzip_list.bin
- python test/list_loader.py --in $1 --out $2 --olist /tmp/gzip_list.bin -b $4
+ python test/list_loader.py --in $1 --out $2 -b $4
;;
*)
echo "Unsupported algorithm type: $3"
@@ -171,7 +171,7 @@ sw_blk_inflate()
{
case $3 in
"gzip")
- python test/list_loader.py --in $1 --out $2 --ilist /tmp/gzip_list.bin
+ python test/list_loader.py --in $1 --out $2
;;
*)
echo "Unsupported algorithm type: $3"
--
2.33.0
1
0
From: Junchong Pan <panjunchong(a)h-partners.com>
Queue is malloc but not init, is_poll is set
but poll interface is not invoked, may case eq overflow.
Signed-off-by: Junchong Pan <panjunchong(a)h-partners.com>
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
uadk_tool/benchmark/hpre_wd_benchmark.c | 2 +-
uadk_tool/benchmark/sec_wd_benchmark.c | 2 +-
uadk_tool/benchmark/zip_wd_benchmark.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.c b/uadk_tool/benchmark/hpre_wd_benchmark.c
index 40f7f0b..60ed3bd 100644
--- a/uadk_tool/benchmark/hpre_wd_benchmark.c
+++ b/uadk_tool/benchmark/hpre_wd_benchmark.c
@@ -447,7 +447,7 @@ static int init_hpre_wd_queue(struct acc_option *options)
}
for (i = 0; i < g_thread_num; i++) {
- g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue));
+ g_thread_queue.bd_res[i].queue = calloc(1, sizeof(struct wd_queue));
g_thread_queue.bd_res[i].queue->capa.alg = options->algclass;
// 0 is ENC, 1 is DEC
g_thread_queue.bd_res[i].queue->capa.priv.direction = options->optype;
diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c
index e022dcb..f066a5b 100644
--- a/uadk_tool/benchmark/sec_wd_benchmark.c
+++ b/uadk_tool/benchmark/sec_wd_benchmark.c
@@ -610,7 +610,7 @@ static int init_wd_queue(struct acc_option *options)
}
for (i = 0; i < g_thread_num; i++) {
- g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue));
+ g_thread_queue.bd_res[i].queue = calloc(1, sizeof(struct wd_queue));
memset(g_thread_queue.bd_res[i].queue, 0, sizeof(struct wd_queue));
g_thread_queue.bd_res[i].queue->capa.alg = options->algclass;
// 0 is ENC, 1 is DEC
diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c
index 8ad3e96..ab9a894 100644
--- a/uadk_tool/benchmark/zip_wd_benchmark.c
+++ b/uadk_tool/benchmark/zip_wd_benchmark.c
@@ -311,7 +311,7 @@ static int init_zip_wd_queue(struct acc_option *options)
}
for (i = 0; i < g_thread_num; i++) {
- g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue));
+ g_thread_queue.bd_res[i].queue = calloc(1, sizeof(struct wd_queue));
g_thread_queue.bd_res[i].queue->capa.alg = options->algclass;
// 0 is compress, 1 is decompress
g_thread_queue.bd_res[i].queue->capa.priv.direction = op_type;
--
2.33.0
1
1
您好!
sig-AccLib 邀请您参加 2025-04-30 11:00 召开的Zoom会议
会议主题:2025/4/30 AccLIb SIG 双周例会 11:00 - 12:00
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/87831643076?pwd=Xx3vcsnmCOBXKdtaKVecCJjSRboVNl.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-04-30 11:00,
The subject of the conference is 2025/4/30 AccLIb SIG 双周例会 11:00 - 12:00
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/87831643076?pwd=Xx3vcsnmCOBXKdtaKVecCJjSRboVNl.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
From: Hao Fang <fanghao11(a)huawei.com>
uadk_tool test --m zip supports the most of function tests
except for one command --ilist, so the test file size set
to 8MB for block mode.
The --ilist cmd has been removed because a complex user
protocol was constructed only for large file compression
in block mode.
Signed-off-by: Hao Fang <fanghao11(a)huawei.com>
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
test/sanity_test.sh | 62 +++++++++++++++++++-------------------
uadk_tool/test/comp_main.c | 5 ---
2 files changed, 31 insertions(+), 36 deletions(-)
diff --git a/test/sanity_test.sh b/test/sanity_test.sh
index 591f8e2d..a1f2b234 100755
--- a/test/sanity_test.sh
+++ b/test/sanity_test.sh
@@ -88,10 +88,10 @@ hw_blk_deflate()
case $3 in
"gzip")
${RM} -f /tmp/gzip_list.bin
- run_cmd zip_sva_perf --in $1 --out $2 --olist /tmp/gzip_list.bin $@
+ run_cmd uadk_tool test --m zip --in $1 --out $2 $@
;;
"zlib")
- run_cmd zip_sva_perf -z --in $1 --out $2 --olist /tmp/zlib_list.bin $@
+ run_cmd uadk_tool test --m zip --alg 1 --in $1 --out $2 $@
;;
*)
echo "Unsupported algorithm type: $3"
@@ -105,10 +105,10 @@ hw_blk_inflate()
{
case $3 in
"gzip")
- run_cmd zip_sva_perf -d --in $1 --out $2 --ilist /tmp/gzip_list.bin $@
+ run_cmd uadk_tool test --m zip --inf --in $1 --out $2 $@
;;
"zlib")
- run_cmd zip_sva_perf -z -d --in $1 --out $2 --ilist /tmp/zlib_list.bin $@
+ run_cmd uadk_tool test --m zip --alg 1 --inf --in $1 --out $2 $@
;;
*)
echo "Unsupported algorithm type: $3"
@@ -122,10 +122,10 @@ hw_strm_deflate()
{
case $3 in
"gzip")
- run_cmd zip_sva_perf -S --in $1 --out $2 $@
+ run_cmd uadk_tool test --m zip --stream --in $1 --out $2 $@
;;
"zlib")
- run_cmd zip_sva_perf -z -S --in $1 --out $2 $@
+ run_cmd uadk_tool test --m zip --stream --alg 1 --in $1 --out $2 $@
;;
*)
echo "Unsupported algorithm type: $3"
@@ -139,10 +139,10 @@ hw_strm_inflate()
{
case $3 in
"gzip")
- run_cmd zip_sva_perf -S -d --in $1 --out $2 $@
+ run_cmd uadk_tool test --m zip --stream --inf --in $1 --out $2 $@
;;
"zlib")
- run_cmd zip_sva_perf -z -S -d --in $1 --out $2 $@
+ run_cmd uadk_tool test --m zip --stream --inf --in $1 --out $2 $@
;;
*)
echo "Unsupported algorithm type: $3"
@@ -234,12 +234,12 @@ hw_dfl_sw_ifl()
prepare_src_file random 1
md5sum origin > ori.md5
- hw_blk_deflate origin /tmp/ori.gz gzip -b 8192 --env
+ hw_blk_deflate origin /tmp/ori.gz gzip --blksize 8192 --env
sw_blk_inflate /tmp/ori.gz origin gzip
md5sum -c ori.md5
${RM} -f /tmp/ori.gz
- hw_strm_deflate origin /tmp/ori.gz gzip -b 8192 --env
+ hw_strm_deflate origin /tmp/ori.gz gzip --blksize 8192 --env
sw_strm_inflate /tmp/ori.gz origin gzip
md5sum -c ori.md5
@@ -249,7 +249,7 @@ hw_dfl_sw_ifl()
md5sum origin > ori.md5
${RM} -f /tmp/ori.gz
- hw_strm_deflate origin /tmp/ori.gz gzip -b 8192 --env
+ hw_strm_deflate origin /tmp/ori.gz gzip --blksize 8192 --env
sw_strm_inflate /tmp/ori.gz origin gzip
md5sum -c ori.md5
@@ -259,13 +259,13 @@ hw_dfl_sw_ifl()
prepare_src_file $1
md5sum origin > ori.md5
- hw_blk_deflate origin /tmp/ori.gz gzip -b 8192 --env
+ hw_blk_deflate origin /tmp/ori.gz gzip --blksize 8192 --env
sw_blk_inflate /tmp/ori.gz origin gzip
md5sum -c ori.md5
# This case fails.
${RM} -f /tmp/ori.gz
- hw_strm_deflate origin /tmp/ori.gz gzip -b 8192 --env
+ hw_strm_deflate origin /tmp/ori.gz gzip --blksize 8192 --env
sw_strm_inflate /tmp/ori.gz origin gzip
md5sum -c ori.md5
}
@@ -282,13 +282,13 @@ sw_dfl_hw_ifl()
# Only gzip compress and hardware decompress
sw_blk_deflate origin /tmp/ori.gz gzip 8192
- hw_blk_inflate /tmp/ori.gz origin gzip -b 8192
+ hw_blk_inflate /tmp/ori.gz origin gzip --blksize 8192
md5sum -c ori.md5
- hw_blk_inflate /tmp/ori.gz origin gzip -b 8192 --env
+ hw_blk_inflate /tmp/ori.gz origin gzip --blksize 8192 --env
md5sum -c ori.md5
sw_strm_deflate origin /tmp/ori.gz gzip 8192
- hw_strm_inflate /tmp/ori.gz origin gzip -b 8192 --env
+ hw_strm_inflate /tmp/ori.gz origin gzip --blksize 8192 --env
md5sum -c ori.md5
# Generate random data with 500MB size
@@ -298,7 +298,7 @@ sw_dfl_hw_ifl()
${RM} -f /tmp/ori.gz
sw_strm_deflate origin /tmp/ori.gz gzip 8192
- hw_strm_inflate /tmp/ori.gz origin gzip -b 8192 --env
+ hw_strm_inflate /tmp/ori.gz origin gzip --blksize 8192 --env
md5sum -c ori.md5
# Use existed text file. It's not in alignment.
@@ -308,11 +308,11 @@ sw_dfl_hw_ifl()
md5sum origin > ori.md5
#sw_blk_deflate origin /tmp/ori.gz gzip 8192
- #hw_blk_inflate /tmp/ori.gz origin gzip -b 8192 --env
+ #hw_blk_inflate /tmp/ori.gz origin gzip --blksize 8192 --env
#md5sum -c ori.md5
sw_strm_deflate origin /tmp/ori.gz gzip 8192
- hw_strm_inflate /tmp/ori.gz origin gzip -b 8192 --env
+ hw_strm_inflate /tmp/ori.gz origin gzip --blksize 8192 --env
md5sum -c ori.md5
}
@@ -326,13 +326,13 @@ hw_dfl_hw_ifl()
prepare_src_file random 1
md5sum origin > ori.md5
- hw_blk_deflate origin /tmp/ori.gz gzip -b 8192
- hw_blk_inflate /tmp/ori.gz origin gzip -b 8192
+ hw_blk_deflate origin /tmp/ori.gz gzip --blksize 8192
+ hw_blk_inflate /tmp/ori.gz origin gzip --blksize 8192
md5sum -c ori.md5
${RM} -f /tmp/ori.gz
- hw_strm_deflate origin /tmp/ori.gz gzip -b 8192
- hw_strm_inflate /tmp/ori.gz origin gzip -b 8192
+ hw_strm_deflate origin /tmp/ori.gz gzip --blksize 8192
+ hw_strm_inflate /tmp/ori.gz origin gzip --blksize 8192
md5sum -c ori.md5
# Use existed text file. It's not in alignment.
@@ -341,13 +341,13 @@ hw_dfl_hw_ifl()
prepare_src_file $1
md5sum origin > ori.md5
- #hw_blk_deflate origin /tmp/ori.gz gzip -b 8192
- #hw_blk_inflate /tmp/ori.gz origin gzip -b 8192
+ #hw_blk_deflate origin /tmp/ori.gz gzip --blksize 8192
+ #hw_blk_inflate /tmp/ori.gz origin gzip --blksize 8192
#md5sum -c ori.md5
${RM} -f /tmp/ori.gz
- hw_strm_deflate origin /tmp/ori.gz gzip -b 8192
- hw_strm_inflate /tmp/ori.gz origin gzip -b 8192
+ hw_strm_deflate origin /tmp/ori.gz gzip --blksize 8192
+ hw_strm_inflate /tmp/ori.gz origin gzip --blksize 8192
md5sum -c ori.md5
}
@@ -358,17 +358,17 @@ run_zip_test_v2()
export WD_COMP_ASYNC_POLL_EN=1
export WD_COMP_ASYNC_POLL_NUM="4@0"
# test without environment variables
- # limit test file in 64MB
+ # limit test file in 8MB
rm -fr /tmp/syslog
- dd if=/var/log/syslog of=/tmp/syslog bs=1M count=16 >& /dev/null
+ dd if=/var/log/syslog of=/tmp/syslog bs=1M count=8 >& /dev/null
sw_dfl_hw_ifl /tmp/syslog
hw_dfl_sw_ifl /tmp/syslog
WD_COMP_EPOLL_EN=1 hw_dfl_hw_ifl /tmp/syslog
WD_COMP_EPOLL_EN=0 hw_dfl_hw_ifl /tmp/syslog
# test without environment variables
- #run_cmd zip_sva_perf -b 8192 -s 81920 -l 1000 --self
+ #run_cmd uadk_tool test --m zip --blksize 8192 --size 81920 --loop 1000 --self
# test with environment variables
- #run_cmd zip_sva_perf -b 8192 -s 81920 -l 1000 --self --env
+ #run_cmd uadk_tool test --m zip --blksize 8192 --size 81920 --loop 1000 --self --env
}
# Accept more paraterms
diff --git a/uadk_tool/test/comp_main.c b/uadk_tool/test/comp_main.c
index 3bdfea62..77d5decc 100644
--- a/uadk_tool/test/comp_main.c
+++ b/uadk_tool/test/comp_main.c
@@ -674,11 +674,6 @@ int store_file(struct hizip_test_info *info, char *model)
size_t sum = 0;
ssize_t file_sz = 0;
- if (!opts->is_stream) {
- COMP_TST_PRT("Invalid, file need stream mode!\n");
- return -EINVAL;
- }
-
p = tdata->out_list;
file_sz = write(opts->fd_out, p->addr, p->size);
if (file_sz < p->size)
--
2.33.0
1
0
From: Wenkai Lin <linwenkai6(a)hisilicon.com>
When soft computing is required, an invalid BD
is used to ensure the integrity of the sending
and receiving process, it is more efficient.
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
drv/hisi_sec.c | 49 ++++++++++++-------------------------------------
1 file changed, 12 insertions(+), 37 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 7f4ae109..5990565a 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -54,6 +54,8 @@
#define SEC_AI_GEN_OFFSET_V3 2
#define SEC_SEQ_OFFSET_V3 6
#define SEC_AUTH_MASK_V3 0xFFFFFFFC
+#define SEC_BD3_IVLD_OFFSET 0x4
+#define SEC_BD2_IVLD_OFFSET 0x7
#define SEC_SGL_MODE_MASK_V3 0x4800
#define SEC_PBUFF_MODE_MASK_V3 0x800
@@ -2440,7 +2442,7 @@ static int gcm_do_soft_mac(struct wd_aead_msg *msg)
msg->result = WD_SUCCESS;
- return WD_SOFT_COMPUTING;
+ return WD_SUCCESS;
}
static int fill_stream_bd2(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe)
@@ -2460,6 +2462,8 @@ static int fill_stream_bd2(struct wd_aead_msg *msg, struct hisi_sec_sqe *sqe)
if (msg->cmode == WD_CIPHER_GCM) {
gcm_auth_ivin(msg);
ret = gcm_do_soft_mac(msg);
+ /* Make the bd invalid to avoid recalculation of the data. */
+ sqe->iv_tls_ld = 0x1 << SEC_BD2_IVLD_OFFSET;
}
break;
default:
@@ -2577,12 +2581,8 @@ static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_
fill_aead_bd2_addr(msg, &sqe);
ret = fill_stream_bd2(msg, &sqe);
- if (ret == WD_SOFT_COMPUTING) {
- ret = 0;
- goto put_sgl;
- } else if (unlikely(ret)) {
+ if (unlikely(ret))
goto put_sgl;
- }
hisi_set_msg_id(h_qp, &msg->tag);
sqe.type2.tag = (__u16)msg->tag;
@@ -2661,24 +2661,6 @@ static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe,
dump_sec_msg(temp_msg, "aead");
}
-static bool soft_compute_check(struct hisi_qp *qp, struct wd_aead_msg *msg)
-{
- /* Asynchronous mode does not use the sent message, so ignores it */
- if (qp->q_info.qp_mode == CTX_MODE_ASYNC)
- return false;
- /*
- * For aead gcm stream mode, due to some hardware limitations,
- * the final message was not sent to hardware if the qm is
- * not higher than v3 version or the input length of the
- * message is 0, the software calculation has been executed.
- */
- if (msg->msg_state == AEAD_MSG_END && msg->cmode == WD_CIPHER_GCM &&
- (qp->q_info.hw_type <= HISI_QM_API_VER3_BASE || !msg->in_bytes))
- return true;
-
- return false;
-}
-
static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg)
{
handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx);
@@ -2687,9 +2669,6 @@ static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_
__u16 count = 0;
int ret;
- if (soft_compute_check((struct hisi_qp *)h_qp, recv_msg))
- return 0;
-
ret = hisi_qm_recv(h_qp, &sqe, 1, &count);
if (ret < 0)
return ret;
@@ -2886,10 +2865,13 @@ static int fill_stream_bd3(handle_t h_qp, struct wd_aead_msg *msg, struct hisi_s
if (msg->cmode == WD_CIPHER_GCM) {
gcm_auth_ivin(msg);
/* Due to hardware limitations, software compute is required. */
- if (qp->q_info.hw_type <= HISI_QM_API_VER3_BASE || !msg->in_bytes)
+ if (qp->q_info.hw_type <= HISI_QM_API_VER3_BASE || !msg->in_bytes) {
ret = gcm_do_soft_mac(msg);
- else
+ /* Make the bd invalid to avoid recalculation of the data. */
+ sqe->bd_param |= 0x1 << SEC_BD3_IVLD_OFFSET;
+ } else {
fill_gcm_final_bd3(msg, sqe);
+ }
}
break;
default:
@@ -2982,12 +2964,8 @@ static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *
fill_aead_bd3_addr(msg, &sqe);
ret = fill_stream_bd3(h_qp, msg, &sqe);
- if (ret == WD_SOFT_COMPUTING) {
- ret = 0;
- goto put_sgl;
- } else if (unlikely(ret)) {
+ if (unlikely(ret))
goto put_sgl;
- }
hisi_set_msg_id(h_qp, &msg->tag);
sqe.tag = msg->tag;
@@ -3059,9 +3037,6 @@ static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *
__u16 count = 0;
int ret;
- if (soft_compute_check((struct hisi_qp *)h_qp, recv_msg))
- return 0;
-
ret = hisi_qm_recv(h_qp, &sqe, 1, &count);
if (ret < 0)
return ret;
--
2.33.0
1
28
21 Apr '25
From: JiangShui Yang <yangjiangshui(a)h-partners.com>
Chenghai Huang (4):
uadk_provider: fix a memory leak issue in BIO_meth
uadk_provider: add hmac alg for uadk_provider in openssl3.0
uadk_provider: add soft mac switching function for uadk_provider
uadk_engine: fix a digest software switching issue in update
Junchong Pan (1):
uadk_engine - fix print format
Qi Tao (2):
uadk_provider: fix async packet reception timeout error
uadk_prov: sec support switching to soft calculation
Wenkai Lin (2):
digest: fix for digest soft work
digest: fix for digest soft init
Zhiqi Song (1):
uadk_provider: fix atomic compare parameter
lizhi (7):
uadk_provider: support switching to software in init
uadk_provider/dh: add dh switching software computation function
uadk_provider/rsa: add rsa switching software computation function
uadk_provider/sm2: add sm2 switching software computation function
uadk_provider/ecx: add x448 and x25519 switching software computation
function
uadk_provider/ecdsa: add ecdsa switching software computation function
uadk_provider/ecdh: add ecdh switching software computation function
src/Makefile.am | 3 +-
src/uadk_async.h | 1 +
src/uadk_digest.c | 108 ++--
src/uadk_ec.c | 2 +-
src/uadk_prov.h | 11 +
src/uadk_prov_aead.c | 340 ++++++++---
src/uadk_prov_cipher.c | 93 +++-
src/uadk_prov_dh.c | 88 ++-
src/uadk_prov_digest.c | 220 +++++---
src/uadk_prov_ec_kmgmt.c | 27 +-
src/uadk_prov_ecdh_exch.c | 61 +-
src/uadk_prov_ecdsa.c | 69 ++-
src/uadk_prov_ecx.c | 242 +++++---
src/uadk_prov_hmac.c | 1115 +++++++++++++++++++++++++++++++++++++
src/uadk_prov_init.c | 171 ++++--
src/uadk_prov_pkey.c | 30 +-
src/uadk_prov_pkey.h | 6 +
src/uadk_prov_rsa.c | 182 +++---
src/uadk_prov_sm2.c | 241 +++++++-
19 files changed, 2526 insertions(+), 484 deletions(-)
create mode 100644 src/uadk_prov_hmac.c
--
2.33.0
1
17
您好!
sig-AccLib 邀请您参加 2025-04-16 11:00 召开的Zoom会议
会议主题:2025/4/16 AccLIb SIG 双周例会 11:00 - 12:00
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/85069156271?pwd=tWrjUA5saZVqZ4PxRJX7XMjqZv4GNa.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-04-16 11:00,
The subject of the conference is 2025/4/16 AccLIb SIG 双周例会 11:00 - 12:00
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/85069156271?pwd=tWrjUA5saZVqZ4PxRJX7XMjqZv4GNa.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
您好!
sig-AccLib 邀请您参加 2025-04-02 11:00 召开的Zoom会议
会议主题:2025/4/2 AccLIb SIG 双周例会 11:00 - 12:00
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/89619281074?pwd=U8YN8vo04bS9kKqwQntJjtamrbUeYY.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-04-02 11:00,
The subject of the conference is 2025/4/2 AccLIb SIG 双周例会 11:00 - 12:00
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/89619281074?pwd=U8YN8vo04bS9kKqwQntJjtamrbUeYY.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
From: caijian <caijian11(a)h-partners.com>
List all DSDT files and allow them to change.
Signed-of-by: caijian <caijian11(a)h-partners.com>
---
tests/qtest/bios-tables-test-allowed-diff.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios-tables-test-allowed-diff.h
index dfb8523c8b..e4a94bb8bd 100644
--- a/tests/qtest/bios-tables-test-allowed-diff.h
+++ b/tests/qtest/bios-tables-test-allowed-diff.h
@@ -1 +1,7 @@
/* List of comma-separated changed AML files to ignore */
+"tests/data/acpi/microvm/DSDT.pcie",
+"tests/data/acpi/virt/DSDT",
+"tests/data/acpi/virt/DSDT.acpihmatvirt",
+"tests/data/acpi/virt/DSDT.memhp",
+"tests/data/acpi/virt/DSDT.pxb",
+"tests/data/acpi/virt/DSDT.topology",
--
2.43.0
1
5
您好!
sig-AccLib 邀请您参加 2025-03-19 11:00 召开的Zoom会议
会议主题:【2025/3/19 AccLIb SIG 双周例会 11:00 - 12:00】
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/83002354706?pwd=X0OBGbq6auYKYZcvtSXaJqLNODbCfs.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-03-19 11:00,
The subject of the conference is 【2025/3/19 AccLIb SIG 双周例会 11:00 - 12:00】
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/83002354706?pwd=X0OBGbq6auYKYZcvtSXaJqLNODbCfs.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
您好!
sig-AccLib 邀请您参加 2025-03-05 11:00 召开的Zoom会议
会议主题:2025/3/5 AccLIb SIG 双周例会 11:00 - 12:00
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meetings
会议链接:https://us06web.zoom.us/j/86433360382?pwd=sHbExElIDMtdjFUNtt2A4ZfbFqTssp.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-03-05 11:00,
The subject of the conference is 2025/3/5 AccLIb SIG 双周例会 11:00 - 12:00
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meetings
You can join the meeting at https://us06web.zoom.us/j/86433360382?pwd=sHbExElIDMtdjFUNtt2A4ZfbFqTssp.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
您好!
sig-AccLib 邀请您参加 2025-02-19 11:00 召开的Zoom会议
会议主题:2025/2/19 AccLIb SIG 双周例会 11:00 - 12:00
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/84927213524?pwd=QpZ05fkCFtfN0j2vRR0JN5jUsXaR7l.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-02-19 11:00,
The subject of the conference is 2025/2/19 AccLIb SIG 双周例会 11:00 - 12:00
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/84927213524?pwd=QpZ05fkCFtfN0j2vRR0JN5jUsXaR7l.1
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings
More information: https://www.openeuler.org/en/
1
0
From: Wenkai Lin <linwenkai6(a)hisilicon.com>
Ensure that soft_ctx is initialized before
invoking software calculation and reduces
repeated judgments for digest soft init.
Signed-off-by: Wenkai Lin <linwenkai6(a)hisilicon.com>
---
src/uadk_digest.c | 83 ++++++++++++++++++++---------------------------
1 file changed, 36 insertions(+), 47 deletions(-)
diff --git a/src/uadk_digest.c b/src/uadk_digest.c
index ed68ee2..f7882e4 100644
--- a/src/uadk_digest.c
+++ b/src/uadk_digest.c
@@ -189,70 +189,56 @@ static EVP_MD *uadk_sha512;
static int uadk_e_digests_soft_md(struct digest_priv_ctx *priv)
{
- int app_datasize = 0;
+ int app_datasize;
- if (priv->soft_md)
+ if (priv->soft_md && priv->soft_ctx)
return 1;
switch (priv->e_nid) {
- case NID_sm3:
- priv->soft_md = EVP_sm3();
- break;
case NID_md5:
priv->soft_md = EVP_md5();
+ /* OpenSSL 3.0 has no app_datasize, need set manually
+ * check crypto/evp/legacy_md5.c: md5_md as example
+ */
+ app_datasize = EVP_MD_meth_get_app_datasize(priv->soft_md);
+ if (!app_datasize)
+ app_datasize = sizeof(EVP_MD *) + sizeof(MD5_CTX);
+ break;
+ case NID_sm3:
+ priv->soft_md = EVP_sm3();
+ app_datasize = EVP_MD_meth_get_app_datasize(priv->soft_md);
+ if (!app_datasize)
+ app_datasize = sizeof(EVP_MD *) + sizeof(SM3_CTX);
break;
case NID_sha1:
priv->soft_md = EVP_sha1();
+ app_datasize = EVP_MD_meth_get_app_datasize(priv->soft_md);
+ if (!app_datasize)
+ app_datasize = sizeof(EVP_MD *) + sizeof(SHA_CTX);
break;
case NID_sha224:
- priv->soft_md = EVP_sha224();
- break;
case NID_sha256:
- priv->soft_md = EVP_sha256();
+ if (priv->e_nid == NID_sha224)
+ priv->soft_md = EVP_sha224();
+ else
+ priv->soft_md = EVP_sha256();
+ app_datasize = EVP_MD_meth_get_app_datasize(priv->soft_md);
+ if (!app_datasize)
+ app_datasize = sizeof(EVP_MD *) + sizeof(SHA256_CTX);
break;
case NID_sha384:
- priv->soft_md = EVP_sha384();
- break;
case NID_sha512:
- priv->soft_md = EVP_sha512();
+ if (priv->e_nid == NID_sha384)
+ priv->soft_md = EVP_sha384();
+ else
+ priv->soft_md = EVP_sha512();
+ app_datasize = EVP_MD_meth_get_app_datasize(priv->soft_md);
+ if (!app_datasize)
+ app_datasize = sizeof(EVP_MD *) + sizeof(SHA512_CTX);
break;
default:
- break;
- }
-
- if (unlikely(priv->soft_md == NULL))
+ fprintf(stderr, "digest nid %d is invalid.\n", priv->e_nid);
return 0;
-
- app_datasize = EVP_MD_meth_get_app_datasize(priv->soft_md);
- if (app_datasize == 0) {
- /* OpenSSL 3.0 has no app_datasize, need set manually
- * check crypto/evp/legacy_md5.c: md5_md as example
- */
- switch (priv->e_nid) {
- case NID_sm3:
- app_datasize = sizeof(EVP_MD *) + sizeof(SM3_CTX);
- break;
- case NID_md5:
- app_datasize = sizeof(EVP_MD *) + sizeof(MD5_CTX);
- break;
- case NID_sha1:
- app_datasize = sizeof(EVP_MD *) + sizeof(SHA_CTX);
- break;
- case NID_sha224:
- app_datasize = sizeof(EVP_MD *) + sizeof(SHA256_CTX);
- break;
- case NID_sha256:
- app_datasize = sizeof(EVP_MD *) + sizeof(SHA256_CTX);
- break;
- case NID_sha384:
- app_datasize = sizeof(EVP_MD *) + sizeof(SHA512_CTX);
- break;
- case NID_sha512:
- app_datasize = sizeof(EVP_MD *) + sizeof(SHA512_CTX);
- break;
- default:
- break;
- }
}
if (priv->soft_ctx == NULL) {
@@ -262,8 +248,10 @@ static int uadk_e_digests_soft_md(struct digest_priv_ctx *priv)
return 0;
ctx->md_data = OPENSSL_malloc(app_datasize);
- if (ctx->md_data == NULL)
+ if (ctx->md_data == NULL) {
+ EVP_MD_CTX_free(ctx);
return 0;
+ }
priv->soft_ctx = ctx;
priv->app_datasize = app_datasize;
@@ -1015,6 +1003,7 @@ static int uadk_e_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
}
if (t->soft_ctx) {
+ t->soft_md = NULL;
t->soft_ctx = NULL;
ret = digest_soft_init(t);
if (!ret)
--
2.33.0
1
0
1. longfang 问的ctx的问题
adapter 方案 ctx 是在worker 内部的,每个worker有pool, ctx 等资源,完全解耦/不相关的
比如sve 是支持异步的, hw+sve 异步是完全没问题的,
代码
wd_cipher_init2_
for (i = 0; i < adapter->workers_nb; i++) {
// 依次初始化各worker
wd_alg_attrs_init(worker, &wd_cipher_init_attrs);
switch (driver_type) {
case UADK_ALG_SVE_INSTR:
分配sve的ctxs // sve, ce 其实可以合并
case UADK_ALG_HW:
分配hw的ctx
wd_cipher_common_init ->
wd_init_async_request_pool(&worker->pool, // 分配worker自己的pool
}
另外,adapter方案的调度是选择worker, 是以worker为调度单元
比如小包 sw,大包 hw,
我们之前的调度,是期望每次过来能选择不同的ctx,
实际中多线程需要加锁,性能跟不上,所以被废弃掉了。
直接改成了alloc_sess的时候就绑定ctx,即每个线程就指定一个ctx
我理解这个其实就是ctx_allocator
adapter 方案是把ctx 封装到worker内部了,即只管怎么选worker, 如果是硬件,还是按现在这样,绑定ctx的
目前get_worker 选择worker 是放在算法层
2. To longfang
之前想到的问题, 在群里也提过
前提是如果用户初始化的时候init(mix) 指定了选择异构调度,
a, 这个代码不好改,比如已经上传了dpdk/ceph社区
b. 即使能改,init 很费时间,uadk_engine 基本是初始化的时候就init 了,
即 init 一旦选择了异构调度方案 就不会随便动了。
1) 流模式下,不能运行一半发生切换,如何避免
即调度器如何知道 现在是不是流模式,算法层的信息如何传递给调度层。
ps. adapter 方案是在 算法层做的,所以直接就能判断是否是流模式
2. 如何实现threshold, 很多场景就只是小包,无论怎么优化,就是指令集快
调度器如何知道包的大小,需要传给调度层
ps. adapter 方案是在 算法层,直接获取包的大小,这个数据结构各算法还不一样
比如req->src_len vs req->in_bytes
3. 硬件出错怎么处理,fb 异步能否实现,fb方案其实我们没验证过。
代码
cipher.c
wd_do_cipher_async
msg_id = wd_get_msg_from_pool(&wd_cipher_setting.pool, idx, (void
**)&msg); //ctx_id a
drv:
temp_msg = wd_cipher_get_msg(qp->q_info.idx, tag); // ctx_id_a
如果fb-> drv_b
temp_msg = wd_cipher_get_msg(ctx_id_b, tag); // 这里我理解拿不到msg, 可能有坑
ps:adapter方案 的做法是设标记,上层retry进来选worker[1]
4. 多个加速器,如何选, hw/ce/sve
龙芳群里的回答: 指定业务运行方式,配置设备驱动
不懂
目前的做法 删掉ce的库,然后指定sve
ps:adapter方案 可以在uadk.conf 配置,
通过命令行 也可以 即生成个配置文件 /tmp/pid.conf, setenv
5. 不同平台加速器不一样,920 hw, 920b hw/ce/sve, 920c? 一套模式/算法在一个平台上调好,其他平台是否适用
龙芳群里的回答:自动适配,不区分硬件平台
不同算法可能有区别 比如rsa 就是硬件好
cipher/digest 就是小包指令集更好。
6. 未来如果有办法读取带宽,能否/怎么支持。
这个龙芳群里回答过
带宽查询功能具备以后,通过驱动的get_usage()直接读取,然后再新建一个调度器根据设备利用率实施调度
ps:adapter方案 可能做法是get_worker里面加if/else
【腾讯文档】adapter方案
https://docs.qq.com/doc/DRUxFaVJDdHJFUWdM
2
3
您好!
sig-AccLib 邀请您参加 2025-01-22 11:00 召开的Zoom会议
会议主题:2025/1/22 AccLIb SIG 双周例会 11:00 - 12:00
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/89685603297?pwd=oTjA3Nd99NBqEQbPVD7aYubeMganRz.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-01-22 11:00,
The subject of the conference is 2025/1/22 AccLIb SIG 双周例会 11:00 - 12:00,
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/89685603297?pwd=oTjA3Nd99NBqEQbPVD7aYubeMganRz.1.
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings.
More information: https://www.openeuler.org/en/
1
0
*** BLURB HERE ***
Chenghai Huang (4):
uadk_provider/aead: cleanup functions in aead
uadk_provider: fix the fork function of the digest
uadk_provider: fix the ctx copy function of the digest
uadk_provider: code cleanup for digest and aead
Weili Qian (3):
uadk_provider/ecdsa: support ecdsa signature and verify
uadk_async: check type and ctx in task
uadk_provider: use default provider to get random data
Zhiqi Song (4):
uadk_engine/rsa: fix memory leak of pkey meth
uadk_engine: fix memory leak in fork scene
uadk_provider: support X25519
uadk_engine/rsa: add rsa finish method
src/Makefile.am | 2 +-
src/uadk_async.c | 5 +-
src/uadk_engine_init.c | 2 +-
src/uadk_prov.h | 5 +
src/uadk_prov_aead.c | 92 ++-
src/uadk_prov_cipher.c | 3 +
src/uadk_prov_der_writer.c | 112 +++-
src/uadk_prov_der_writer.h | 2 +
src/uadk_prov_digest.c | 235 ++++++--
src/uadk_prov_ecdsa.c | 1151 ++++++++++++++++++++++++++++++++++++
src/uadk_prov_ecx.c | 517 ++++++++++++++--
src/uadk_prov_init.c | 17 +-
src/uadk_prov_pkey.c | 28 +-
src/uadk_prov_pkey.h | 3 +
src/uadk_rsa.c | 11 +
15 files changed, 2003 insertions(+), 182 deletions(-)
create mode 100644 src/uadk_prov_ecdsa.c
--
2.33.0
1
0
20 Jan '25
From: Weili Qian <qianweili(a)huawei.com>
Support ecdsa signature and verify.
openssl speed -provider uadk_provider -seconds 10 ecdsap521
Signed-off-by: Weili Qian <qianweili(a)huawei.com>
---
src/Makefile.am | 2 +-
src/uadk_prov.h | 2 +
src/uadk_prov_der_writer.c | 112 +++-
src/uadk_prov_der_writer.h | 2 +
src/uadk_prov_ecdsa.c | 1151 ++++++++++++++++++++++++++++++++++++
src/uadk_prov_init.c | 2 +
src/uadk_prov_pkey.c | 2 +-
src/uadk_prov_pkey.h | 1 +
8 files changed, 1269 insertions(+), 5 deletions(-)
create mode 100644 src/uadk_prov_ecdsa.c
diff --git a/src/Makefile.am b/src/Makefile.am
index c143edd..66650d2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -75,7 +75,7 @@ uadk_provider_la_SOURCES=uadk_prov_init.c uadk_async.c uadk_utils.c \
uadk_prov_pkey.c uadk_prov_sm2.c \
uadk_prov_ffc.c uadk_prov_aead.c \
uadk_prov_ec_kmgmt.c uadk_prov_ecdh_exch.c \
- uadk_prov_ecx.c
+ uadk_prov_ecx.c uadk_prov_ecdsa.c
uadk_provider_la_LDFLAGS=-module -version-number $(VERSION)
uadk_provider_la_LIBADD=$(WD_LIBS) -lpthread
diff --git a/src/uadk_prov.h b/src/uadk_prov.h
index 84a3f01..2786e79 100644
--- a/src/uadk_prov.h
+++ b/src/uadk_prov.h
@@ -185,6 +185,8 @@ extern const OSSL_DISPATCH uadk_ecdh_keyexch_functions[FUNC_MAX_NUM];
extern const OSSL_DISPATCH uadk_x448_keymgmt_functions[FUNC_MAX_NUM];
extern const OSSL_DISPATCH uadk_x448_keyexch_functions[FUNC_MAX_NUM];
+extern const OSSL_DISPATCH uadk_ecdsa_signature_functions[FUNC_MAX_NUM];
+
void uadk_prov_destroy_digest(void);
void uadk_prov_destroy_cipher(void);
void uadk_prov_destroy_aead(void);
diff --git a/src/uadk_prov_der_writer.c b/src/uadk_prov_der_writer.c
index e7e7e49..7e5ee31 100644
--- a/src/uadk_prov_der_writer.c
+++ b/src/uadk_prov_der_writer.c
@@ -12,10 +12,66 @@
#include <string.h>
#include "uadk_prov_der_writer.h"
-#define DER_OID_SZ_sm2_with_SM3 10
-#define PACKET_LEN_TAG 30
+#define PACKET_LEN_TAG 30
+#define DER_P_OBJECT 6
+#define DER_OID_SZ_sm2_with_SM3 10
+#define DER_OID_SZ_ecdsa_with_SHA1 9
+#define DER_OID_SZ_ecdsa_with_SHA224 10
+#define DER_OID_SZ_ecdsa_with_SHA256 10
+#define DER_OID_SZ_ecdsa_with_SHA384 10
+#define DER_OID_SZ_ecdsa_with_SHA512 10
+#define DER_OID_SZ_id_ecdsa_with_sha3_224 11
+#define DER_OID_SZ_id_ecdsa_with_sha3_256 11
+#define DER_OID_SZ_id_ecdsa_with_sha3_384 11
+#define DER_OID_SZ_id_ecdsa_with_sha3_512 11
+
+static const unsigned char
+ossl_der_oid_id_ecdsa_with_sha1[DER_OID_SZ_ecdsa_with_SHA1] = {
+ DER_P_OBJECT, 7, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x01
+};
+
+static const unsigned char
+ossl_der_oid_id_ecdsa_with_sha224[DER_OID_SZ_ecdsa_with_SHA224] = {
+ DER_P_OBJECT, 8, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x01
+};
+
+static const unsigned char
+ossl_der_oid_id_ecdsa_with_sha256[DER_OID_SZ_ecdsa_with_SHA256] = {
+ DER_P_OBJECT, 8, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02
+};
-unsigned char ossl_der_oid_sm2_with_SM3[DER_OID_SZ_sm2_with_SM3] = {
+static const unsigned char
+ossl_der_oid_id_ecdsa_with_sha384[DER_OID_SZ_ecdsa_with_SHA384] = {
+ DER_P_OBJECT, 8, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x03
+};
+
+static const unsigned char
+ossl_der_oid_id_ecdsa_with_sha512[DER_OID_SZ_ecdsa_with_SHA384] = {
+ DER_P_OBJECT, 8, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x04
+};
+
+static const unsigned char
+ossl_der_oid_id_ecdsa_with_sha3_224[DER_OID_SZ_id_ecdsa_with_sha3_224] = {
+ DER_P_OBJECT, 9, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x09
+};
+
+static const unsigned char
+ossl_der_oid_id_ecdsa_with_sha3_256[DER_OID_SZ_id_ecdsa_with_sha3_256] = {
+ DER_P_OBJECT, 9, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x0A
+};
+
+static const unsigned char
+ossl_der_oid_id_ecdsa_with_sha3_384[DER_OID_SZ_id_ecdsa_with_sha3_384] = {
+ DER_P_OBJECT, 9, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x0B
+};
+
+static const unsigned char
+ossl_der_oid_id_ecdsa_with_sha3_512[DER_OID_SZ_id_ecdsa_with_sha3_512] = {
+ DER_P_OBJECT, 9, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x0C
+};
+
+static const unsigned char
+ossl_der_oid_sm2_with_SM3[DER_OID_SZ_sm2_with_SM3] = {
6, 8, 0x2A, 0x81, 0x1C, 0xCF, 0x55, 0x01, 0x83, 0x75
};
@@ -234,3 +290,53 @@ int ossl_DER_w_algorithmIdentifier_SM2_with_MD(WPACKET *pkt, int cont,
&& ossl_DER_w_precompiled(pkt, -1, precompiled, precompiled_sz)
&& ossl_DER_w_end_sequence(pkt, cont);
}
+
+int ossl_DER_w_algorithmIdentifier_ECDSA_with_MD(WPACKET *pkt, int cont,
+ EC_KEY *ec, int mdnid)
+{
+ const unsigned char *precompiled = NULL;
+ size_t precompiled_sz = 0;
+
+#define MD_CASE(name) \
+do { \
+ precompiled = ossl_der_oid_id_ecdsa_with_##name; \
+ precompiled_sz = sizeof(ossl_der_oid_id_ecdsa_with_##name); \
+} while (0)
+
+ switch (mdnid) {
+ case NID_sha1:
+ MD_CASE(sha1);
+ break;
+ case NID_sha224:
+ MD_CASE(sha224);
+ break;
+ case NID_sha256:
+ MD_CASE(sha256);
+ break;
+ case NID_sha384:
+ MD_CASE(sha384);
+ break;
+ case NID_sha512:
+ MD_CASE(sha512);
+ break;
+ case NID_sha3_224:
+ MD_CASE(sha3_224);
+ break;
+ case NID_sha3_256:
+ MD_CASE(sha3_256);
+ break;
+ case NID_sha3_384:
+ MD_CASE(sha3_384);
+ break;
+ case NID_sha3_512:
+ MD_CASE(sha3_512);
+ break;
+ default:
+ return 0;
+ }
+
+ return ossl_DER_w_begin_sequence(pkt, cont) &&
+ /* No parameters (yet?) */
+ ossl_DER_w_precompiled(pkt, -1, precompiled, precompiled_sz) &&
+ ossl_DER_w_end_sequence(pkt, cont);
+}
diff --git a/src/uadk_prov_der_writer.h b/src/uadk_prov_der_writer.h
index 39308e0..4f0bab5 100644
--- a/src/uadk_prov_der_writer.h
+++ b/src/uadk_prov_der_writer.h
@@ -126,4 +126,6 @@ int ossl_DER_w_end_sequence(WPACKET *pkt, int tag);
int ossl_DER_w_algorithmIdentifier_SM2_with_MD(WPACKET *pkt, int cont,
EC_KEY *ec, int mdnid);
+int ossl_DER_w_algorithmIdentifier_ECDSA_with_MD(WPACKET *pkt, int cont,
+ EC_KEY *ec, int mdnid);
#endif
diff --git a/src/uadk_prov_ecdsa.c b/src/uadk_prov_ecdsa.c
new file mode 100644
index 0000000..774e8ee
--- /dev/null
+++ b/src/uadk_prov_ecdsa.c
@@ -0,0 +1,1151 @@
+// SPDX-License-Identifier: Apache-2.0
+/*
+ * Copyright 2024 Huawei Technologies Co.,Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <openssl/err.h>
+#include <openssl/evp.h>
+#include <openssl/err.h>
+#include <openssl/kdf.h>
+#include "uadk_async.h"
+#include "uadk_prov.h"
+#include "uadk_prov_der_writer.h"
+#include "uadk_prov_pkey.h"
+
+#define DIGEST_MAX_NAME_SIZE 50
+#define MAX_ALGORITHM_ID_SIZE 256
+#define MAX_PROPQUERY_SIZE 256
+#define UADK_SIGN_SIG_NULL 2
+#define DGST_SHIFT_NUM(n) (8 - ((n) & 0x7))
+#define UADK_PROV_ECDSA "ecdsa"
+
+/*
+ * What's passed as an actual key is defined by the KEYMGMT interface.
+ * We happen to know that our KEYMGMT simply passes DSA structures, so
+ * we use that here too.
+ */
+struct ecdsa_ctx {
+ OSSL_LIB_CTX *libctx;
+ char *propq;
+ EC_KEY *ec;
+ char mdname[DIGEST_MAX_NAME_SIZE];
+
+ /*
+ * Flag to determine if the hash function can be changed (true) or not (false)
+ * Because it's dangerous to change during a DigestSign or DigestVerify
+ * operation, this flag is cleared by their Init function, and set again
+ * by their Final function.
+ */
+ bool flag_allow_md;
+
+ /* The Algorithm Identifier of the combined signature algorithm */
+ unsigned char aid_buf[MAX_ALGORITHM_ID_SIZE];
+ unsigned char *aid;
+ size_t aid_len;
+ size_t mdsize;
+ int operation;
+
+ EVP_MD *md;
+ EVP_MD_CTX *mdctx;
+ /*
+ * Internally used to cache the results of calling the EC group
+ * sign_setup() methods which are then passed to the sign operation.
+ * This is used by CAVS failure tests to terminate a loop if the signature
+ * is not valid.
+ * This could of also been done with a simple flag.
+ */
+ BIGNUM *kinv;
+ BIGNUM *r;
+};
+
+struct ecdsa_opdata {
+ const unsigned char *tbs;
+ size_t tbslen;
+ ECDSA_SIG *sig;
+ EC_KEY *ec;
+};
+
+UADK_PKEY_SIGNATURE_DESCR(ecdsa, ECDSA);
+
+static void *uadk_signature_ecdsa_newctx(void *provctx, const char *propq)
+{
+ struct ecdsa_ctx *ctx;
+
+ ctx = OPENSSL_zalloc(sizeof(*ctx));
+ if (!ctx)
+ return NULL;
+
+ ctx->flag_allow_md = true;
+ ctx->libctx = prov_libctx_of(provctx);
+
+ if (propq) {
+ ctx->propq = OPENSSL_strdup(propq);
+ if (!ctx->propq) {
+ fprintf(stderr, "failed to strdup propq!\n");
+ OPENSSL_free(ctx);
+ ctx = NULL;
+ }
+ }
+
+ return ctx;
+}
+
+static void uadk_signature_ecdsa_freectx(void *vctx)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+
+ if (!ctx)
+ return;
+
+ OPENSSL_free(ctx->propq);
+ EVP_MD_CTX_free(ctx->mdctx);
+ EVP_MD_free(ctx->md);
+ EC_KEY_free(ctx->ec);
+ BN_clear_free(ctx->kinv);
+ BN_clear_free(ctx->r);
+ OPENSSL_clear_free(ctx, sizeof(*ctx));
+}
+
+static void *uadk_signature_ecdsa_dupctx(void *vctx)
+{
+ struct ecdsa_ctx *src_ctx = (struct ecdsa_ctx *)vctx;
+ struct ecdsa_ctx *dst_ctx;
+
+ if (!src_ctx) {
+ fprintf(stderr, "invalid: src ctx is NULL to dupctx!\n");
+ return NULL;
+ }
+
+ /* Test KATS should not need to be supported */
+ if (src_ctx->kinv || src_ctx->r) {
+ fprintf(stderr, "invalid: src ctx kinv or r is not NULL!\n");
+ return NULL;
+ }
+
+ dst_ctx = OPENSSL_zalloc(sizeof(*dst_ctx));
+ if (!dst_ctx)
+ return NULL;
+
+ *dst_ctx = *src_ctx;
+ dst_ctx->ec = NULL;
+ dst_ctx->md = NULL;
+ dst_ctx->mdctx = NULL;
+ dst_ctx->propq = NULL;
+
+ if (src_ctx->ec && !EC_KEY_up_ref(src_ctx->ec))
+ goto err;
+ dst_ctx->ec = src_ctx->ec;
+
+ if (src_ctx->md && !EVP_MD_up_ref(src_ctx->md))
+ goto err;
+ dst_ctx->md = src_ctx->md;
+
+ if (src_ctx->mdctx) {
+ dst_ctx->mdctx = EVP_MD_CTX_new();
+ if (!dst_ctx->mdctx || !EVP_MD_CTX_copy_ex(dst_ctx->mdctx, src_ctx->mdctx))
+ goto err;
+ }
+
+ if (src_ctx->propq) {
+ dst_ctx->propq = OPENSSL_strdup(src_ctx->propq);
+ if (!dst_ctx->propq)
+ goto err;
+ }
+
+ return dst_ctx;
+
+err:
+ uadk_signature_ecdsa_freectx(dst_ctx);
+ return NULL;
+}
+
+static void ecdsa_set_aid(struct ecdsa_ctx *ctx, int md_nid)
+{
+ WPACKET pkt;
+
+ ctx->aid_len = 0;
+ if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf)) &&
+ ossl_DER_w_algorithmIdentifier_ECDSA_with_MD(&pkt, -1, ctx->ec, md_nid) &&
+ WPACKET_finish(&pkt)) {
+ WPACKET_get_total_written(&pkt, &ctx->aid_len);
+ ctx->aid = WPACKET_get_curr(&pkt);
+ }
+ WPACKET_cleanup(&pkt);
+}
+
+/*
+ * Internal library code deals with NIDs, so we need to translate from a name.
+ * We do so using EVP_MD_is_a(), and therefore need a name to NID map.
+ */
+static int ecdsa_digest_md_to_nid(const EVP_MD *md, const OSSL_ITEM *it, size_t it_len)
+{
+ size_t i;
+
+ if (!md)
+ return NID_undef;
+
+ for (i = 0; i < it_len; i++)
+ if (EVP_MD_is_a(md, it[i].ptr))
+ return (int)it[i].id;
+
+ return NID_undef;
+}
+
+/*
+ * Retrieve one of the FIPS approved hash algorithms by nid.
+ * See FIPS 180-4 "Secure Hash Standard" and FIPS 202 - SHA-3.
+ */
+static int ecdsa_digest_get_nid(const EVP_MD *md)
+{
+ static const OSSL_ITEM name_to_nid[] = {
+ {NID_sha1, OSSL_DIGEST_NAME_SHA1},
+ {NID_sha224, OSSL_DIGEST_NAME_SHA2_224},
+ {NID_sha256, OSSL_DIGEST_NAME_SHA2_256},
+ {NID_sha384, OSSL_DIGEST_NAME_SHA2_384},
+ {NID_sha512, OSSL_DIGEST_NAME_SHA2_512},
+ {NID_sha512_224, OSSL_DIGEST_NAME_SHA2_512_224},
+ {NID_sha512_256, OSSL_DIGEST_NAME_SHA2_512_256},
+ {NID_sha3_224, OSSL_DIGEST_NAME_SHA3_224},
+ {NID_sha3_256, OSSL_DIGEST_NAME_SHA3_256},
+ {NID_sha3_384, OSSL_DIGEST_NAME_SHA3_384},
+ {NID_sha3_512, OSSL_DIGEST_NAME_SHA3_512},
+ };
+
+ return ecdsa_digest_md_to_nid(md, name_to_nid, OSSL_NELEM(name_to_nid));
+}
+
+static int ecdsa_digest_get_approved_nid(struct ecdsa_ctx *ctx, const EVP_MD *md)
+{
+ int mdnid = ecdsa_digest_get_nid(md);
+
+#ifndef OPENSSL_NO_FIPS_SECURITYCHECKS
+ int sha1_allowed = (ctx->operation != EVP_PKEY_OP_SIGN);
+
+ if (uadk_prov_securitycheck_enabled(ctx->libctx)) {
+ if (mdnid == NID_undef || (mdnid == NID_sha1 && !sha1_allowed))
+ mdnid = -1; /* disallowed by security checks */
+ }
+# endif /* OPENSSL_NO_FIPS_SECURITYCHECKS */
+
+ return mdnid;
+}
+
+static int ecdsa_setup_md(struct ecdsa_ctx *ctx, const char *mdname, const char *mdprops)
+{
+ size_t mdname_len;
+ EVP_MD *md = NULL;
+ int md_nid;
+
+ if (!mdname)
+ return UADK_P_SUCCESS;
+
+ mdname_len = strlen(mdname);
+ if (mdname_len >= DIGEST_MAX_NAME_SIZE) {
+ fprintf(stderr, "invalid: %s size %zu exceeds name buffer length %d!\n",
+ mdname, mdname_len, DIGEST_MAX_NAME_SIZE);
+ return UADK_P_FAIL;
+ }
+
+ if (!mdprops)
+ mdprops = ctx->propq;
+
+ md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
+ if (!md) {
+ fprintf(stderr, "failed to fetch %s!\n", mdname);
+ return UADK_P_FAIL;
+ }
+
+ md_nid = ecdsa_digest_get_approved_nid(ctx, md);
+ if (md_nid < 0) {
+ fprintf(stderr, "digest %s not allowed!\n", mdname);
+ goto err;
+ }
+
+ if (!ctx->flag_allow_md) {
+ if (ctx->mdname[0] != '\0' && !EVP_MD_is_a(md, ctx->mdname)) {
+ fprintf(stderr, "digest %s is not same ctx digest %s!\n",
+ mdname, ctx->mdname);
+ goto err;
+ }
+ EVP_MD_free(md);
+ return UADK_P_SUCCESS;
+ }
+
+ EVP_MD_CTX_free(ctx->mdctx);
+ ctx->mdctx = NULL;
+
+ EVP_MD_free(ctx->md);
+ ctx->md = md;
+ ctx->mdsize = EVP_MD_get_size(ctx->md);
+ OPENSSL_strlcpy(ctx->mdname, mdname, DIGEST_MAX_NAME_SIZE);
+
+ ecdsa_set_aid(ctx, md_nid);
+
+ return UADK_P_SUCCESS;
+
+err:
+ EVP_MD_free(md);
+ return UADK_P_FAIL;
+}
+
+static int ecdsa_signverify_init(void *vctx, void *ec,
+ const OSSL_PARAM params[],
+ int operation)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+ const EC_KEY *eckey = (const EC_KEY *)ec;
+ int ret;
+
+ if (!ctx || (!ec && !ctx->ec)) {
+ fprintf(stderr, "invalid: ctx or ec is NULL to digest init!\n");
+ return UADK_P_FAIL;
+ }
+
+ ret = uadk_signature_ecdsa_set_ctx_params(ctx, params);
+ if (!ret)
+ return ret;
+
+ if (eckey) {
+ if (!uadk_prov_ecc_check_key(ctx->libctx, eckey,
+ operation == EVP_PKEY_OP_SIGN))
+ return UADK_P_FAIL;
+
+ if (!EC_KEY_up_ref(ec))
+ return UADK_P_FAIL;
+ EC_KEY_free(ctx->ec);
+ ctx->ec = ec;
+ }
+
+ ctx->operation = operation;
+
+ return UADK_P_SUCCESS;
+}
+
+static int uadk_signature_ecdsa_sign_init(void *vctx, void *ec, const OSSL_PARAM params[])
+{
+ return ecdsa_signverify_init(vctx, ec, params, EVP_PKEY_OP_SIGN);
+}
+
+static int uadk_signature_ecdsa_verify_init(void *vctx, void *ec, const OSSL_PARAM params[])
+{
+ return ecdsa_signverify_init(vctx, ec, params, EVP_PKEY_OP_VERIFY);
+}
+
+static int ecdsa_common_params_check(struct ecdsa_ctx *ctx,
+ struct ecdsa_opdata *opdata)
+{
+ const EC_GROUP *group;
+ int type;
+
+ if (unlikely(!opdata->tbs || !opdata->tbslen)) {
+ fprintf(stderr, "invalid: tbs is NULL or tbslen %zu error!\n", opdata->tbslen);
+ return UADK_P_FAIL;
+ }
+
+ if (ctx->mdsize && opdata->tbslen != ctx->mdsize) {
+ fprintf(stderr, "invalid: ctx->mdsize %zu not equal tbslen %zu!\n",
+ ctx->mdsize, opdata->tbslen);
+ return UADK_P_FAIL;
+ }
+
+ group = EC_KEY_get0_group(ctx->ec);
+ if (unlikely(!group)) {
+ fprintf(stderr, "invalid: group is NULL!\n");
+ return UADK_P_FAIL;
+ }
+
+ /* Field GF(2m) is not supported by uadk */
+ type = EC_METHOD_get_field_type(EC_GROUP_method_of(group));
+ if (type != NID_X9_62_prime_field) {
+ fprintf(stderr, "invalid: uadk unsupport Field GF(2m)!\n");
+ return UADK_P_FAIL;
+ }
+
+ opdata->ec = ctx->ec;
+
+ return uadk_prov_ecc_bit_check(group);
+}
+
+static handle_t ecdsa_alloc_sess(EC_KEY *ec)
+{
+ int ret;
+
+ ret = uadk_prov_signature_get_support_state(SIGNATURE_ECDSA);
+ if (!ret) {
+ fprintf(stderr, "failed to get hardware ecdsa support!\n");
+ return ret;
+ }
+
+ ret = uadk_prov_ecc_init(UADK_PROV_ECDSA);
+ if (!ret) {
+ fprintf(stderr, "failed to init ecdsa!\n");
+ return ret;
+ }
+
+ return uadk_prov_ecc_alloc_sess(ec, UADK_PROV_ECDSA);
+}
+
+static void ecdsa_free_sess(handle_t sess)
+{
+ wd_ecc_free_sess(sess);
+}
+
+static bool ecdsa_data_is_all_zero(struct wd_dtb *e)
+{
+ __u32 i;
+
+ for (i = 0; i < e->dsize; i++) {
+ if (e->data[i])
+ return false;
+ }
+
+ return true;
+}
+
+static int ecdsa_set_digest(struct ecdsa_opdata *opdata, struct wd_dtb *e)
+{
+ const EC_GROUP *group = EC_KEY_get0_group(opdata->ec);
+ size_t order_bits = EC_GROUP_order_bits(group);
+ size_t data_len = opdata->tbslen;
+ BIGNUM *m;
+
+ if (BYTES_TO_BITS(data_len) > order_bits) {
+ m = BN_new();
+ if (!m) {
+ fprintf(stderr, "failed to BN_new m!\n");
+ return UADK_P_FAIL;
+ }
+
+ /*
+ * Need to truncate digest if it is too long: first truncate
+ * whole bytes
+ */
+ data_len = BITS_TO_BYTES(order_bits);
+ if (!BN_bin2bn(opdata->tbs, data_len, m)) {
+ fprintf(stderr, "failed to BN_bin2bn tbs!\n");
+ BN_free(m);
+ return UADK_P_FAIL;
+ }
+
+ /*
+ * If the length of digest is still longer than the length
+ * of the base point order, truncate remaining bits with a
+ * shift to that length.
+ */
+ if (BYTES_TO_BITS(data_len) > order_bits &&
+ !BN_rshift(m, m, DGST_SHIFT_NUM(order_bits))) {
+ fprintf(stderr, "failed to truncate input tbs!\n");
+ BN_free(m);
+ return UADK_P_FAIL;
+ }
+ e->dsize = BN_bn2bin(m, (void *)e->data);
+ e->bsize = UADK_ECC_MAX_KEY_BYTES;
+ BN_free(m);
+ } else {
+ e->data = (char *)opdata->tbs;
+ e->dsize = data_len;
+ e->bsize = data_len;
+ }
+
+ if (ecdsa_data_is_all_zero(e))
+ return UADK_P_FAIL;
+
+ return UADK_P_SUCCESS;
+}
+
+static int ecdsa_sign_init_iot(handle_t sess, struct wd_ecc_req *req,
+ struct ecdsa_opdata *opdata)
+{
+ char buff[UADK_ECC_MAX_KEY_BYTES] = {0};
+ struct wd_ecc_out *ecc_out;
+ struct wd_ecc_in *ecc_in;
+ struct wd_dtb e = {0};
+ int ret;
+
+ e.data = buff;
+ ret = ecdsa_set_digest(opdata, &e);
+ if (!ret)
+ return ret;
+
+ ecc_in = wd_ecdsa_new_sign_in(sess, &e, NULL);
+ if (unlikely(!ecc_in)) {
+ fprintf(stderr, "failed to new ecdsa sign in!\n");
+ return UADK_P_FAIL;
+ }
+
+ ecc_out = wd_ecdsa_new_sign_out(sess);
+ if (unlikely(!ecc_out)) {
+ fprintf(stderr, "failed to new ecdsa sign out!\n");
+ wd_ecc_del_in(sess, ecc_in);
+ return UADK_P_FAIL;
+ }
+
+ uadk_prov_ecc_fill_req(req, WD_ECDSA_SIGN, ecc_in, ecc_out);
+
+ return UADK_P_SUCCESS;
+}
+
+static void ecdsa_uninit_req_iot(handle_t sess, struct wd_ecc_req *req)
+{
+ if (req->src)
+ wd_ecc_del_in(sess, req->src);
+ if (req->dst)
+ wd_ecc_del_out(sess, req->dst);
+}
+
+static ECDSA_SIG *ecdsa_get_sign_data(struct wd_ecc_req *req)
+{
+ struct wd_dtb *r = NULL;
+ struct wd_dtb *s = NULL;
+ BIGNUM *br, *bs;
+ ECDSA_SIG *sig;
+ int ret;
+
+ br = BN_new();
+ bs = BN_new();
+ if (unlikely(!br || !bs)) {
+ fprintf(stderr, "failed to new br or bs!\n");
+ goto free_bn;
+ }
+
+ wd_ecdsa_get_sign_out_params(req->dst, &r, &s);
+ if (unlikely(!r || !s)) {
+ fprintf(stderr, "failed to get r or s\n");
+ goto free_bn;
+ }
+
+ if (!BN_bin2bn((void *)r->data, r->dsize, br) ||
+ !BN_bin2bn((void *)s->data, s->dsize, bs)) {
+ fprintf(stderr, "failed to BN_bin2bn r or s\n");
+ goto free_bn;
+ }
+
+ sig = ECDSA_SIG_new();
+ if (unlikely(!sig)) {
+ fprintf(stderr, "failed to new sig!\n");
+ goto free_bn;
+ }
+
+ ret = ECDSA_SIG_set0(sig, br, bs);
+ if (unlikely(!ret)) {
+ fprintf(stderr, "failed to set br or bs to sig!\n");
+ goto free_sig;
+ }
+
+ return sig;
+free_sig:
+ ECDSA_SIG_free(sig);
+free_bn:
+ BN_clear_free(br);
+ BN_clear_free(bs);
+ return NULL;
+}
+
+static int ecdsa_hw_sign(struct ecdsa_opdata *opdata)
+{
+ struct wd_ecc_req req = {0};
+ handle_t sess;
+ int ret;
+
+ sess = ecdsa_alloc_sess(opdata->ec);
+ if (unlikely(!sess)) {
+ fprintf(stderr, "failed to alloc ecdsa sess!\n");
+ return UADK_P_FAIL;
+ }
+
+ ret = ecdsa_sign_init_iot(sess, &req, opdata);
+ if (unlikely(!ret)) {
+ fprintf(stderr, "failed to ecdsa_sign_init_iot!\n");
+ goto free_sess;
+ }
+
+ ret = uadk_prov_ecc_set_private_key(sess, opdata->ec);
+ if (unlikely(!ret)) {
+ fprintf(stderr, "failed to set private key!\n");
+ goto free_iot;
+ }
+
+ ret = uadk_prov_ecc_crypto(sess, &req, (void *)sess);
+ if (unlikely(!ret)) {
+ fprintf(stderr, "failed to sign!\n");
+ goto free_iot;
+ }
+
+ opdata->sig = ecdsa_get_sign_data(&req);
+ if (!opdata->sig)
+ ret = UADK_P_FAIL;
+
+free_iot:
+ ecdsa_uninit_req_iot(sess, &req);
+free_sess:
+ ecdsa_free_sess(sess);
+ return ret;
+}
+
+static int ecdsa_sign_params_check(struct ecdsa_ctx *ctx,
+ struct ecdsa_opdata *opdata,
+ unsigned char *sig, size_t *siglen,
+ size_t sigsize)
+{
+ size_t ecsize;
+
+ if (unlikely(!siglen)) {
+ fprintf(stderr, "invalid: siglen is NULL to sign!\n");
+ return UADK_P_FAIL;
+ }
+
+ if (unlikely(!ctx || !ctx->ec)) {
+ fprintf(stderr, "invalid: ctx or ec is NULL to sign!\n");
+ return UADK_P_FAIL;
+ }
+
+ ecsize = ECDSA_size(ctx->ec);
+ if (unlikely(!sig)) {
+ *siglen = ecsize;
+ return UADK_SIGN_SIG_NULL;
+ }
+
+ if (unlikely(sigsize < ecsize)) {
+ fprintf(stderr, "invalid: sigsize %zu is less than ecsize %zu!\n",
+ sigsize, ecsize);
+ return UADK_P_FAIL;
+ }
+
+ return ecdsa_common_params_check(ctx, opdata);
+}
+
+static int uadk_signature_ecdsa_sign(void *vctx, unsigned char *sig, size_t *siglen,
+ size_t sigsize, const unsigned char *tbs, size_t tbslen)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+ struct ecdsa_opdata opdata = {0};
+ int ret;
+
+ opdata.tbs = tbs;
+ opdata.tbslen = tbslen;
+ ret = ecdsa_sign_params_check(ctx, &opdata, sig, siglen, sigsize);
+ if (ret == UADK_SIGN_SIG_NULL) {
+ return UADK_P_SUCCESS;
+ } else if (unlikely(!ret)) {
+ fprintf(stderr, "failed to check params to sign!\n");
+ goto err;
+ }
+
+ ret = ecdsa_hw_sign(&opdata);
+ if (unlikely(!ret))
+ goto err;
+ ret = i2d_ECDSA_SIG(opdata.sig, &sig);
+ /* ECDSA_SIG_free will free br and bs applied for in ecdsa_get_sign_data() */
+ ECDSA_SIG_free(opdata.sig);
+ if (ret < 0)
+ goto err;
+
+ *siglen = (size_t)ret;
+
+ return UADK_P_SUCCESS;
+err:
+ if (siglen)
+ *siglen = 0;
+ return UADK_P_FAIL;
+}
+
+static int ecdsa_verify_init_iot(handle_t sess, struct wd_ecc_req *req,
+ struct ecdsa_opdata *opdata)
+{
+ char buf_r[UADK_ECC_MAX_KEY_BYTES] = {0};
+ char buf_s[UADK_ECC_MAX_KEY_BYTES] = {0};
+ char buf_e[UADK_ECC_MAX_KEY_BYTES] = {0};
+ const BIGNUM *sig_r = NULL;
+ const BIGNUM *sig_s = NULL;
+ struct wd_ecc_in *ecc_in;
+ struct wd_dtb e = {0};
+ struct wd_dtb r = {0};
+ struct wd_dtb s = {0};
+ int ret;
+
+ e.data = buf_e;
+ ret = ecdsa_set_digest(opdata, &e);
+ if (!ret)
+ return ret;
+
+ r.data = buf_r;
+ s.data = buf_s;
+ r.bsize = UADK_ECC_MAX_KEY_BYTES;
+ s.bsize = UADK_ECC_MAX_KEY_BYTES;
+ ECDSA_SIG_get0(opdata->sig, &sig_r, &sig_s);
+ r.dsize = BN_bn2bin(sig_r, (void *)r.data);
+ s.dsize = BN_bn2bin(sig_s, (void *)s.data);
+ ecc_in = wd_ecdsa_new_verf_in(sess, &e, &r, &s);
+ if (unlikely(!ecc_in)) {
+ fprintf(stderr, "failed to new ecdsa verf in\n");
+ return UADK_P_FAIL;
+ }
+
+ uadk_prov_ecc_fill_req(req, WD_ECDSA_VERIFY, ecc_in, NULL);
+
+ return UADK_P_SUCCESS;
+}
+
+static int ecdsa_hw_verify(struct ecdsa_opdata *opdata)
+{
+ struct wd_ecc_req req = {0};
+ handle_t sess;
+ int ret;
+
+ sess = ecdsa_alloc_sess(opdata->ec);
+ if (!sess) {
+ fprintf(stderr, "failed to alloc ecdsa sess!\n");
+ return UADK_P_FAIL;
+ }
+
+ ret = ecdsa_verify_init_iot(sess, &req, opdata);
+ if (!ret)
+ goto free_sess;
+
+ ret = uadk_prov_ecc_set_public_key(sess, opdata->ec);
+ if (!ret)
+ goto free_iot;
+
+ ret = uadk_prov_ecc_crypto(sess, &req, (void *)sess);
+
+free_iot:
+ ecdsa_uninit_req_iot(sess, &req);
+free_sess:
+ ecdsa_free_sess(sess);
+ return ret;
+}
+
+static int ecdsa_verify_params_check(struct ecdsa_ctx *ctx, struct ecdsa_opdata *opdata,
+ const unsigned char *sig, size_t siglen)
+{
+ if (!ctx || !ctx->ec) {
+ fprintf(stderr, "invalid: ctx or ec is NULL to verify!\n");
+ return UADK_P_FAIL;
+ }
+
+ if (!sig || !siglen) {
+ fprintf(stderr, "invalid: sig is NULL or siglen %zu error!\n", siglen);
+ return UADK_P_FAIL;
+ }
+
+ return ecdsa_common_params_check(ctx, opdata);
+}
+
+static ECDSA_SIG *ecdsa_create_sig(const unsigned char *sig, size_t siglen)
+{
+ const unsigned char *p = sig;
+ unsigned char *der = NULL;
+ ECDSA_SIG *s;
+ int derlen;
+
+ s = ECDSA_SIG_new();
+ if (!s) {
+ fprintf(stderr, "failed to new s to verify!\n");
+ return NULL;
+ }
+
+ if (!d2i_ECDSA_SIG(&s, &p, siglen)) {
+ fprintf(stderr, "failed to d2i_ECDSA_SIG: siglen = %zu!\n",
+ siglen);
+ goto err;
+ }
+
+ /* Ensure signature uses DER and doesn't have trailing garbage */
+ derlen = i2d_ECDSA_SIG(s, &der);
+ if (derlen != siglen || memcmp(sig, der, derlen) != 0) {
+ fprintf(stderr, "sig have trailing garbage, derlen %d!\n", derlen);
+ OPENSSL_free(der);
+ goto err;
+ }
+
+ OPENSSL_free(der);
+
+ return s;
+
+err:
+ ECDSA_SIG_free(s);
+ return NULL;
+}
+
+static int uadk_signature_ecdsa_verify(void *vctx, const unsigned char *sig,
+ size_t siglen, const unsigned char *tbs,
+ size_t tbslen)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+ struct ecdsa_opdata opdata = {0};
+ int ret;
+
+ opdata.tbs = tbs;
+ opdata.tbslen = tbslen;
+ ret = ecdsa_verify_params_check(ctx, &opdata, sig, siglen);
+ if (!ret) {
+ fprintf(stderr, "failed to check params to sign!\n");
+ return UADK_P_FAIL;
+ }
+
+ opdata.sig = ecdsa_create_sig(sig, siglen);
+ if (!opdata.sig) {
+ fprintf(stderr, "failed to create s to verify!\n");
+ return UADK_P_FAIL;
+ }
+
+ ret = ecdsa_hw_verify(&opdata);
+
+ ECDSA_SIG_free(opdata.sig);
+ return ret;
+}
+
+static int ecdsa_digest_singverify_init(void *vctx, const char *mdname, void *ec,
+ const OSSL_PARAM params[], int operation)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+ int ret;
+
+ ret = ecdsa_signverify_init(vctx, ec, params, operation);
+ if (!ret)
+ return ret;
+
+ ret = ecdsa_setup_md(ctx, mdname, NULL);
+ if (!ret)
+ return ret;
+
+ ctx->flag_allow_md = false;
+ if (!ctx->mdctx) {
+ ctx->mdctx = EVP_MD_CTX_new();
+ if (!ctx->mdctx)
+ goto err;
+ }
+
+ ret = EVP_DigestInit_ex2(ctx->mdctx, ctx->md, params);
+ if (!ret)
+ goto err;
+
+ return UADK_P_SUCCESS;
+
+err:
+ EVP_MD_CTX_free(ctx->mdctx);
+ ctx->mdctx = NULL;
+ return UADK_P_FAIL;
+}
+
+static int uadk_signature_ecdsa_digest_sign_init(void *vctx, const char *mdname,
+ void *ec, const OSSL_PARAM params[])
+{
+ return ecdsa_digest_singverify_init(vctx, mdname, ec, params, EVP_PKEY_OP_SIGN);
+}
+
+static int ecdsa_digest_signverify_update(void *vctx, const unsigned char *data,
+ size_t datalen)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+
+ if (!ctx || !ctx->mdctx) {
+ fprintf(stderr, "invalid: ctx or mdctx is NULL to digest update!\n");
+ return UADK_P_FAIL;
+ }
+
+ return EVP_DigestUpdate(ctx->mdctx, data, datalen);
+}
+
+static int uadk_signature_ecdsa_digest_sign_update(void *vctx, const unsigned char *data,
+ size_t datalen)
+{
+ return ecdsa_digest_signverify_update(vctx, data, datalen);
+}
+
+static int uadk_signature_ecdsa_digest_sign_final(void *vctx, unsigned char *sig,
+ size_t *siglen, size_t sigsize)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+ unsigned char digest[EVP_MAX_MD_SIZE];
+ unsigned int dlen = 0;
+
+ if (!ctx || !ctx->mdctx) {
+ fprintf(stderr, "invalid: ctx or mdctx is NULL to sign digest final!\n");
+ return UADK_P_FAIL;
+ }
+
+ /*
+ * If sig is NULL then we're just finding out the sig size. Other fields
+ * are ignored. Defer to uadk_signature_ecdsa_sign.
+ */
+ if (sig && !EVP_DigestFinal_ex(ctx->mdctx, digest, &dlen))
+ return UADK_P_FAIL;
+
+ ctx->flag_allow_md = true;
+
+ return uadk_signature_ecdsa_sign(vctx, sig, siglen, sigsize, digest, (size_t)dlen);
+}
+
+static int uadk_signature_ecdsa_digest_verify_init(void *vctx, const char *mdname,
+ void *ec, const OSSL_PARAM params[])
+{
+ return ecdsa_digest_singverify_init(vctx, mdname, ec, params, EVP_PKEY_OP_VERIFY);
+}
+
+static int uadk_signature_ecdsa_digest_verify_update(void *vctx, const unsigned char *data,
+ size_t datalen)
+{
+ return ecdsa_digest_signverify_update(vctx, data, datalen);
+}
+
+static int uadk_signature_ecdsa_digest_verify_final(void *vctx, const unsigned char *sig,
+ size_t siglen)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+ unsigned char digest[EVP_MAX_MD_SIZE];
+ unsigned int dlen = 0;
+
+ if (!ctx || !ctx->mdctx) {
+ fprintf(stderr, "invalid: ctx or mdctx is NULL to verify digest final!\n");
+ return UADK_P_FAIL;
+ }
+
+ if (!EVP_DigestFinal_ex(ctx->mdctx, digest, &dlen))
+ return UADK_P_FAIL;
+
+ ctx->flag_allow_md = true;
+
+ return uadk_signature_ecdsa_verify(vctx, sig, siglen, digest, (size_t)dlen);
+}
+
+static int ecdsa_get_ctx_aid(struct ecdsa_ctx *ctx, OSSL_PARAM *params)
+{
+ OSSL_PARAM *p;
+
+ p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
+ if (!p)
+ return UADK_P_SUCCESS;
+
+ return OSSL_PARAM_set_octet_string(p, ctx->aid, ctx->aid_len);
+}
+
+static int ecdsa_get_ctx_digest_size(struct ecdsa_ctx *ctx, OSSL_PARAM *params)
+{
+ OSSL_PARAM *p;
+
+ p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
+ if (!p)
+ return UADK_P_SUCCESS;
+
+ return OSSL_PARAM_set_size_t(p, ctx->mdsize);
+}
+
+static int ecdsa_get_ctx_digest(struct ecdsa_ctx *ctx, OSSL_PARAM *params)
+{
+ const char *mdname;
+ OSSL_PARAM *p;
+
+ p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST);
+ if (!p)
+ return UADK_P_SUCCESS;
+
+ mdname = ctx->md ? EVP_MD_get0_name(ctx->md) : ctx->mdname;
+
+ return OSSL_PARAM_set_utf8_string(p, mdname);
+}
+
+static int uadk_signature_ecdsa_get_ctx_params(void *vctx, OSSL_PARAM *params)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+ int ret;
+
+ if (!ctx) {
+ fprintf(stderr, "invalid: ctx is NULL to get_ctx_params!\n");
+ return UADK_P_FAIL;
+ }
+
+ if (!params)
+ return UADK_P_SUCCESS;
+
+ ret = ecdsa_get_ctx_digest(ctx, params);
+ if (!ret)
+ return ret;
+
+ ret = ecdsa_get_ctx_digest_size(ctx, params);
+ if (!ret)
+ return ret;
+
+ return ecdsa_get_ctx_aid(ctx, params);
+}
+
+static const OSSL_PARAM known_gettable_ctx_params[] = {
+ OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0),
+ OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
+ OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
+ OSSL_PARAM_END
+};
+
+static const OSSL_PARAM *
+uadk_signature_ecdsa_gettable_ctx_params(ossl_unused void *vctx,
+ ossl_unused void *provctx)
+{
+ return known_gettable_ctx_params;
+}
+
+static int ecdsa_set_ctx_digest(struct ecdsa_ctx *ctx, const OSSL_PARAM params[])
+{
+ char mdname[DIGEST_MAX_NAME_SIZE] = {0};
+ char mdprops[MAX_PROPQUERY_SIZE] = {0};
+ const OSSL_PARAM *p_digest, *propsp;
+ char *pmdprops = mdprops;
+ char *pmdname = mdname;
+ int ret;
+
+ p_digest = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST);
+ if (!p_digest)
+ return UADK_P_SUCCESS;
+
+ ret = OSSL_PARAM_get_utf8_string(p_digest, &pmdname, DIGEST_MAX_NAME_SIZE);
+ if (!ret)
+ return UADK_P_FAIL;
+
+ propsp = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_PROPERTIES);
+ if (propsp) {
+ ret = OSSL_PARAM_get_utf8_string(propsp, &pmdprops, MAX_PROPQUERY_SIZE);
+ if (!ret)
+ return UADK_P_FAIL;
+ }
+
+ return ecdsa_setup_md(ctx, mdname, mdprops);
+}
+
+static int ecdsa_set_ctx_digest_size(struct ecdsa_ctx *ctx, const OSSL_PARAM params[])
+{
+ const OSSL_PARAM *p;
+ size_t mdsize = 0;
+ int ret;
+
+ p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
+ if (!p)
+ return UADK_P_SUCCESS;
+
+ ret = OSSL_PARAM_get_size_t(p, &mdsize);
+ if (!ret)
+ return UADK_P_FAIL;
+
+ if (!ctx->flag_allow_md && mdsize != ctx->mdsize)
+ return UADK_P_FAIL;
+
+ ctx->mdsize = mdsize;
+
+ return UADK_P_SUCCESS;
+}
+
+static int uadk_signature_ecdsa_set_ctx_params(void *vctx, const OSSL_PARAM params[])
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+ int ret;
+
+ if (!ctx) {
+ fprintf(stderr, "invalid: ctx is NULL to set_ctx_params!\n");
+ return UADK_P_FAIL;
+ }
+
+ if (!params)
+ return UADK_P_SUCCESS;
+
+ ret = ecdsa_set_ctx_digest(ctx, params);
+ if (!ret)
+ return ret;
+
+ return ecdsa_set_ctx_digest_size(ctx, params);
+}
+
+static const OSSL_PARAM settable_ctx_params[] = {
+ OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
+ OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
+ OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PROPERTIES, NULL, 0),
+ OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_KAT, NULL),
+ OSSL_PARAM_END
+};
+
+static const OSSL_PARAM settable_ctx_params_no_digest[] = {
+ OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_KAT, NULL),
+ OSSL_PARAM_END
+};
+
+static const OSSL_PARAM *
+uadk_signature_ecdsa_settable_ctx_params(void *vctx, ossl_unused void *provctx)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+
+ if (ctx && !ctx->flag_allow_md)
+ return settable_ctx_params_no_digest;
+
+ return settable_ctx_params;
+}
+
+static int uadk_signature_ecdsa_get_ctx_md_params(void *vctx, OSSL_PARAM *params)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+
+ if (!ctx || !ctx->mdctx) {
+ fprintf(stderr, "invalid: ctx or md ctx is NULL to get_ctx_md_params!\n");
+ return UADK_P_FAIL;
+ }
+
+ return EVP_MD_CTX_get_params(ctx->mdctx, params);
+}
+
+static const OSSL_PARAM *uadk_signature_ecdsa_gettable_ctx_md_params(void *vctx)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+
+ if (!ctx || !ctx->md) {
+ fprintf(stderr, "invalid: ctx or md is NULL to gettable_ctx_md_params!\n");
+ return NULL;
+ }
+
+ return EVP_MD_gettable_ctx_params(ctx->md);
+}
+
+static int uadk_signature_ecdsa_set_ctx_md_params(void *vctx, const OSSL_PARAM params[])
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+
+ if (!ctx || !ctx->mdctx) {
+ fprintf(stderr, "invalid: ctx or md ctx is NULL to set_ctx_md_params!\n");
+ return UADK_P_FAIL;
+ }
+
+ return EVP_MD_CTX_set_params(ctx->mdctx, params);
+}
+
+static const OSSL_PARAM *uadk_signature_ecdsa_settable_ctx_md_params(void *vctx)
+{
+ struct ecdsa_ctx *ctx = (struct ecdsa_ctx *)vctx;
+
+ if (!ctx || !ctx->md) {
+ fprintf(stderr, "invalid: ctx or md is NULL to settable_ctx_md_params!\n");
+ return NULL;
+ }
+
+ return EVP_MD_settable_ctx_params(ctx->md);
+}
+
+static int uadk_signature_ecdsa_verify_recover_init(void *vctx, void *vecdsa,
+ const OSSL_PARAM params[])
+{
+ return UADK_P_SUCCESS;
+}
+
+static int uadk_signature_ecdsa_verify_recover(void *vctx, unsigned char *rout,
+ size_t *routlen, size_t routsize,
+ const unsigned char *sig, size_t siglen)
+{
+ return UADK_P_SUCCESS;
+}
diff --git a/src/uadk_prov_init.c b/src/uadk_prov_init.c
index 9a2baeb..52d0b90 100644
--- a/src/uadk_prov_init.c
+++ b/src/uadk_prov_init.c
@@ -165,6 +165,8 @@ static const OSSL_ALGORITHM uadk_prov_signature[] = {
uadk_rsa_signature_functions, "uadk_provider rsa_signature" },
{ "SM2", UADK_DEFAULT_PROPERTIES,
uadk_sm2_signature_functions, "uadk_provider sm2_signature" },
+ { "ECDSA", UADK_DEFAULT_PROPERTIES,
+ uadk_ecdsa_signature_functions, "uadk_provider ecdsa_signature" },
{ NULL, NULL, NULL }
};
diff --git a/src/uadk_prov_pkey.c b/src/uadk_prov_pkey.c
index f654dd6..ebf90e4 100644
--- a/src/uadk_prov_pkey.c
+++ b/src/uadk_prov_pkey.c
@@ -680,7 +680,7 @@ void uadk_prov_keymgmt_alg(void)
void uadk_prov_signature_alg(void)
{
- static const char * const signature_alg[] = {"sm2"};
+ static const char * const signature_alg[] = {"sm2", "ecdsa"};
__u32 i, size;
bool sp;
diff --git a/src/uadk_prov_pkey.h b/src/uadk_prov_pkey.h
index f40313d..38a67ac 100644
--- a/src/uadk_prov_pkey.h
+++ b/src/uadk_prov_pkey.h
@@ -75,6 +75,7 @@ enum {
enum {
SIGNATURE_SM2 = 0x0,
+ SIGNATURE_ECDSA = 0x1,
SIGNATURE_MAX = 0x3
};
--
2.33.0
1
10
[PATCH 01/46] vfio: Introduce base object for VFIOContainer and targeted interface
by Zhou Wang 11 Jan '25
by Zhou Wang 11 Jan '25
11 Jan '25
From: Zhenzhong Duan <zhenzhong.duan(a)intel.com>
Introduce a dumb VFIOContainerBase object and its targeted interface.
This is willingly not a QOM object because we don't want it to be
visible from the user interface. The VFIOContainerBase will be
smoothly populated in subsequent patches as well as interfaces.
No functional change intended.
Signed-off-by: Eric Auger <eric.auger(a)redhat.com>
Signed-off-by: Yi Liu <yi.l.liu(a)intel.com>
Signed-off-by: Yi Sun <yi.y.sun(a)linux.intel.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan(a)intel.com>
Reviewed-by: Cédric Le Goater <clg(a)redhat.com>
Signed-off-by: Cédric Le Goater <clg(a)redhat.com>
Signed-off-by: Zhou Wang <wangzhou1(a)hisilicon.com>
---
include/hw/vfio/vfio-common.h | 8 ++---
include/hw/vfio/vfio-container-base.h | 50 +++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 6 deletions(-)
create mode 100644 include/hw/vfio/vfio-container-base.h
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index fd9828d50b..c89b5886f2 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -30,6 +30,7 @@
#include <linux/vfio.h>
#endif
#include "sysemu/sysemu.h"
+#include "hw/vfio/vfio-container-base.h"
#define VFIO_MSG_PREFIX "vfio %s: "
@@ -89,6 +90,7 @@ typedef struct VFIODMARange {
} VFIODMARange;
typedef struct VFIOContainer {
+ VFIOContainerBase bcontainer;
VFIOAddressSpace *space;
int fd; /* /dev/vfio/vfio, empowered by the attached groups */
MemoryListener listener;
@@ -211,12 +213,6 @@ typedef struct VFIODisplay {
} dmabuf;
} VFIODisplay;
-typedef struct {
- unsigned long *bitmap;
- hwaddr size;
- hwaddr pages;
-} VFIOBitmap;
-
VFIOAddressSpace *vfio_get_address_space(AddressSpace *as);
void vfio_put_address_space(VFIOAddressSpace *space);
bool vfio_devices_all_running_and_saving(VFIOContainer *container);
diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
new file mode 100644
index 0000000000..1d6daaea5d
--- /dev/null
+++ b/include/hw/vfio/vfio-container-base.h
@@ -0,0 +1,50 @@
+/*
+ * VFIO BASE CONTAINER
+ *
+ * Copyright (C) 2023 Intel Corporation.
+ * Copyright Red Hat, Inc. 2023
+ *
+ * Authors: Yi Liu <yi.l.liu(a)intel.com>
+ * Eric Auger <eric.auger(a)redhat.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_VFIO_VFIO_CONTAINER_BASE_H
+#define HW_VFIO_VFIO_CONTAINER_BASE_H
+
+#include "exec/memory.h"
+
+typedef struct VFIODevice VFIODevice;
+typedef struct VFIOIOMMUOps VFIOIOMMUOps;
+
+typedef struct {
+ unsigned long *bitmap;
+ hwaddr size;
+ hwaddr pages;
+} VFIOBitmap;
+
+/*
+ * This is the base object for vfio container backends
+ */
+typedef struct VFIOContainerBase {
+ const VFIOIOMMUOps *ops;
+} VFIOContainerBase;
+
+struct VFIOIOMMUOps {
+ /* basic feature */
+ int (*dma_map)(VFIOContainerBase *bcontainer,
+ hwaddr iova, ram_addr_t size,
+ void *vaddr, bool readonly);
+ int (*dma_unmap)(VFIOContainerBase *bcontainer,
+ hwaddr iova, ram_addr_t size,
+ IOMMUTLBEntry *iotlb);
+ int (*attach_device)(const char *name, VFIODevice *vbasedev,
+ AddressSpace *as, Error **errp);
+ void (*detach_device)(VFIODevice *vbasedev);
+ /* migration feature */
+ int (*set_dirty_page_tracking)(VFIOContainerBase *bcontainer, bool start);
+ int (*query_dirty_bitmap)(VFIOContainerBase *bcontainer, VFIOBitmap *vbmap,
+ hwaddr iova, hwaddr size);
+};
+#endif /* HW_VFIO_VFIO_CONTAINER_BASE_H */
--
2.33.0
1
45
*** BLURB HERE ***
Junchong Pan (1):
uadk_tool: print help when empty parameters
Qi Tao (1):
uadk: support appending tag for digest stream model
Wenkai Lin (7):
uadk: fix for aead authsize check
uadk: fix for aead auth key length
uadk: fix for digest auth key length
uadk: fix for ce key_len check
uadk: fix for key address check
uadk: fix for v1 aead authsize check
uadk: fix for aead cbc mode authsize
drv/hisi_sec.c | 40 +++++++++++++-------------
drv/isa_ce_sm3.c | 5 ----
uadk_tool/benchmark/uadk_benchmark.c | 6 ++--
uadk_tool/benchmark/uadk_benchmark.h | 1 +
uadk_tool/uadk_tool.c | 10 ++++++-
v1/drv/hisi_sec_udrv.c | 18 ++----------
v1/wd_aead.c | 41 ++++++++++++++++++++-------
v1/wd_cipher.c | 2 +-
v1/wd_digest.c | 42 ++++++++++++++++++++++------
v1/wd_digest.h | 19 +++++++++++--
wd_aead.c | 11 +++-----
wd_digest.c | 12 ++++----
12 files changed, 127 insertions(+), 80 deletions(-)
--
2.33.0
1
2
In common digest stream mode, io_bytes and iv_bytes need to
be set to 0 when the final bd is calculated. Therefore, in the
appending tag scenario, need to restore the values of io_bytes
and iv_bytes to the values before they are set to 0.
Therefore, the hardware can compute the overall hash value of
the appending packet and the previously calculated packet,
and reduce the repeated calculation.
Signed-off-by: Qi Tao <taoqi10(a)huawei.com>
---
v1/wd_digest.c | 29 +++++++++++++++++++++++++++--
v1/wd_digest.h | 19 +++++++++++++++++--
2 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/v1/wd_digest.c b/v1/wd_digest.c
index c02b3b30..1b665a34 100644
--- a/v1/wd_digest.c
+++ b/v1/wd_digest.c
@@ -445,7 +445,7 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx,
return -WD_EINVAL;
}
- if (d_opdata[i]->has_next)
+ if (d_opdata[i]->has_next == WCRYPTO_DIGEST_DOING)
ret = stream_mode_param_check(d_ctx, d_opdata[i], num);
else
ret = block_mode_param_check(d_ctx, d_opdata[i]);
@@ -466,6 +466,24 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx,
return WD_SUCCESS;
}
+static int append_tag_restore_status(struct wcrypto_digest_ctx *ctxt,
+ struct wcrypto_digest_op_data **opdata,
+ struct wcrypto_digest_msg **req, __u32 ind)
+{
+ if (opdata[ind]->has_next == WCRYPTO_DIGEST_STREAM_END)
+ opdata[ind]->has_next = WCRYPTO_DIGEST_END;
+ else if (opdata[ind]->has_next == WCRYPTO_DIGEST_STREAM_DOING)
+ opdata[ind]->has_next = WCRYPTO_DIGEST_DOING;
+ else
+ return -WD_EINVAL;
+
+ ctxt->io_bytes = *(__u64 *)opdata[ind]->priv;
+ req[ind]->iv_bytes = opdata[ind]->out_bytes;
+ opdata[ind]->priv = NULL;
+
+ return WD_SUCCESS;
+}
+
int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **opdata,
void **tag, __u32 num)
{
@@ -483,8 +501,15 @@ int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **opdata,
return ret;
for (i = 0; i < num; i++) {
- cookies[i]->tag.priv = opdata[i]->priv;
req[i] = &cookies[i]->msg;
+
+ if (opdata[i]->has_next > WCRYPTO_DIGEST_DOING) {
+ ret = append_tag_restore_status(ctxt, opdata, req, i);
+ if (unlikely(ret))
+ goto fail_with_cookies;
+ }
+
+ cookies[i]->tag.priv = opdata[i]->priv;
if (tag)
cookies[i]->tag.wcrypto_tag.tag = tag[i];
}
diff --git a/v1/wd_digest.h b/v1/wd_digest.h
index f0bdf4da..07901e3f 100644
--- a/v1/wd_digest.h
+++ b/v1/wd_digest.h
@@ -76,6 +76,21 @@ enum wcrypto_digest_mode {
WCRYPTO_DIGEST_HMAC,
};
+/**
+ * wcrypto_digest_msg_state - Message state of digest
+ * @WCRYPTO_DIGEST_END: Final message or single block message
+ * @WCRYPTO_DIGEST_DOING: First message or middle message
+ * @WCRYPTO_DIGEST_STREAM_END: Final message for appending tag mode
+ * @WCRYPTO_DIGEST_STREAM_DOING: Middle message for appending tag mode
+ */
+enum wcrypto_digest_msg_state {
+ WCRYPTO_DIGEST_END = 0x0,
+ WCRYPTO_DIGEST_DOING,
+ WCRYPTO_DIGEST_STREAM_END,
+ WCRYPTO_DIGEST_STREAM_DOING,
+ WCRYPTO_DIGEST_MSG_STATE_MAX,
+};
+
/**
* different contexts for different users/threads
* @cb: call back functions of user
@@ -100,7 +115,7 @@ struct wcrypto_digest_ctx_setup {
* @out_bytes:output data size
* @priv:reserved data field segment
* @status:I/O operation return status
- * @has_next: is there next data block
+ * @has_next: message state, all types are defined in enum wcrypto_digest_msg_state
* @iv: initialization verctor data address
* @iv_bytes:initialization verctor data size
*/
@@ -111,7 +126,7 @@ struct wcrypto_digest_op_data {
__u32 out_bytes;
void *priv;
int status;
- bool has_next;
+ int has_next;
void *iv;
__u32 iv_bytes;
};
--
2.33.0
1
0
您好!
sig-AccLib 邀请您参加 2025-01-08 11:00 召开的Zoom会议
会议主题:2025/1/8 AccLIb SIG 双周例会 11:00 - 12:00
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/83172200317?pwd=nrqT1amyXEaZrWuXb30bWbaJMV2XNv.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2025-01-08 11:00,
The subject of the conference is 2025/1/8 AccLIb SIG 双周例会 11:00 - 12:00,
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/83172200317?pwd=nrqT1amyXEaZrWuXb30bWbaJMV2XNv.1.
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings.
More information: https://www.openeuler.org/en/
1
0
From: Yang Shen <shenyang39(a)huawei.com>
In Warpdrive sync mode, the driver writes a tag in the SQE to mark
the owner and checks this tag when a request is completed.
To ensure it functions properly, we added a lock to protect the
receiving process. However, pthread_spin_lock is a CAS lock, which
results in a situation where a thread can repeatedly acquire the lock
while the completed request does not belong to it until timeout.
Therefore, we introduce a fair lock to replace pthread_spin_lock.
This way, every thread can acquire the lock in a round-robin manner.
Signed-off-by: Yang Shen <shenyang39(a)huawei.com>
---
v1/drv/hisi_qm_udrv.c | 39 ++++++++++++---------------------------
v1/drv/hisi_qm_udrv.h | 4 ++--
v1/wd_util.c | 31 +++++++++++++++++++++++++++++++
v1/wd_util.h | 8 ++++++++
4 files changed, 53 insertions(+), 29 deletions(-)
diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c
index c711a497..7b0183bc 100644
--- a/v1/drv/hisi_qm_udrv.c
+++ b/v1/drv/hisi_qm_udrv.c
@@ -535,24 +535,11 @@ static int qm_set_queue_info(struct wd_queue *q)
goto err_with_regions;
}
- ret = pthread_spin_init(&info->sd_lock, PTHREAD_PROCESS_PRIVATE);
- if (ret) {
- WD_ERR("failed to init qinfo sd_lock!\n");
- goto free_cache;
- }
-
- ret = pthread_spin_init(&info->rc_lock, PTHREAD_PROCESS_PRIVATE);
- if (ret) {
- WD_ERR("failed to init qinfo rc_lock!\n");
- goto uninit_lock;
- }
+ wd_fair_init(&info->sd_lock);
+ wd_fair_init(&info->rc_lock);
return 0;
-uninit_lock:
- pthread_spin_destroy(&info->sd_lock);
-free_cache:
- free(info->req_cache);
err_with_regions:
qm_unset_queue_regions(q);
return ret;
@@ -593,8 +580,6 @@ void qm_uninit_queue(struct wd_queue *q)
struct q_info *qinfo = q->qinfo;
struct qm_queue_info *info = qinfo->priv;
- pthread_spin_destroy(&info->rc_lock);
- pthread_spin_destroy(&info->sd_lock);
free(info->req_cache);
qm_unset_queue_regions(q);
free(qinfo->priv);
@@ -624,10 +609,10 @@ int qm_send(struct wd_queue *q, void **req, __u32 num)
int ret;
__u32 i;
- pthread_spin_lock(&info->sd_lock);
+ wd_fair_lock(&info->sd_lock);
if (unlikely((__u32)__atomic_load_n(&info->used, __ATOMIC_RELAXED) >
info->sq_depth - num - 1)) {
- pthread_spin_unlock(&info->sd_lock);
+ wd_fair_unlock(&info->sd_lock);
WD_ERR("queue is full!\n");
return -WD_EBUSY;
}
@@ -636,7 +621,7 @@ int qm_send(struct wd_queue *q, void **req, __u32 num)
ret = info->sqe_fill[qinfo->atype](req[i], qinfo->priv,
info->sq_tail_index);
if (unlikely(ret != WD_SUCCESS)) {
- pthread_spin_unlock(&info->sd_lock);
+ wd_fair_unlock(&info->sd_lock);
WD_ERR("sqe fill error, ret %d!\n", ret);
return -WD_EINVAL;
}
@@ -648,7 +633,7 @@ int qm_send(struct wd_queue *q, void **req, __u32 num)
}
ret = qm_tx_update(info, num);
- pthread_spin_unlock(&info->sd_lock);
+ wd_fair_unlock(&info->sd_lock);
return ret;
}
@@ -681,9 +666,9 @@ static int check_ds_rx_base(struct qm_queue_info *info,
return 0;
if (before) {
- pthread_spin_lock(&info->rc_lock);
+ wd_fair_lock(&info->rc_lock);
qm_rx_from_cache(info, resp, num);
- pthread_spin_unlock(&info->rc_lock);
+ wd_fair_unlock(&info->rc_lock);
WD_ERR("wd queue hw error happened before qm receive!\n");
} else {
WD_ERR("wd queue hw error happened after qm receive!\n");
@@ -724,7 +709,7 @@ int qm_recv(struct wd_queue *q, void **resp, __u32 num)
if (unlikely(ret))
return ret;
- pthread_spin_lock(&info->rc_lock);
+ wd_fair_lock(&info->rc_lock);
for (i = 0; i < num; i++) {
cqe = info->cq_base + info->cq_head_index * sizeof(struct cqe);
if (info->cqc_phase != CQE_PHASE(cqe))
@@ -733,7 +718,7 @@ int qm_recv(struct wd_queue *q, void **resp, __u32 num)
mb(); /* make sure the data is all in memory before read */
sq_head = CQE_SQ_HEAD_INDEX(cqe);
if (unlikely(sq_head >= info->sq_depth)) {
- pthread_spin_unlock(&info->rc_lock);
+ wd_fair_unlock(&info->rc_lock);
WD_ERR("CQE_SQ_HEAD_INDEX(%u) error\n", sq_head);
return -WD_EIO;
}
@@ -745,7 +730,7 @@ int qm_recv(struct wd_queue *q, void **resp, __u32 num)
if (!ret) {
break;
} else if (ret < 0) {
- pthread_spin_unlock(&info->rc_lock);
+ wd_fair_unlock(&info->rc_lock);
WD_ERR("recv sqe error %u\n", sq_head);
return ret;
}
@@ -766,7 +751,7 @@ int qm_recv(struct wd_queue *q, void **resp, __u32 num)
ret = i;
}
- pthread_spin_unlock(&info->rc_lock);
+ wd_fair_unlock(&info->rc_lock);
return ret;
}
diff --git a/v1/drv/hisi_qm_udrv.h b/v1/drv/hisi_qm_udrv.h
index 06ac66a0..d71f9de8 100644
--- a/v1/drv/hisi_qm_udrv.h
+++ b/v1/drv/hisi_qm_udrv.h
@@ -166,8 +166,8 @@ struct qm_queue_info {
qm_sqe_parse sqe_parse[WCRYPTO_MAX_ALG];
hisi_qm_sqe_fill_priv sqe_fill_priv;
hisi_qm_sqe_parse_priv sqe_parse_priv;
- pthread_spinlock_t sd_lock;
- pthread_spinlock_t rc_lock;
+ struct wd_fair_lock sd_lock;
+ struct wd_fair_lock rc_lock;
struct wd_queue *q;
int (*sgl_info)(struct hw_sgl_info *info);
int (*sgl_init)(void *pool, struct wd_sgl *sgl);
diff --git a/v1/wd_util.c b/v1/wd_util.c
index 29f65792..3dac2d74 100644
--- a/v1/wd_util.c
+++ b/v1/wd_util.c
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <stdatomic.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
@@ -21,6 +22,7 @@
#include "v1/wd_util.h"
#define BYTE_TO_BIT 8
+#define LOCK_TRY_CNT (0x800000000U)
void wd_spinlock(struct wd_lock *lock)
{
@@ -43,6 +45,35 @@ void wd_unspinlock(struct wd_lock *lock)
__atomic_store_n(&lock->lock, 0, __ATOMIC_RELEASE);
}
+void wd_fair_init(struct wd_fair_lock *lock)
+{
+ atomic_exchange_explicit(&lock->ticket, 0, memory_order_acq_rel);
+ atomic_exchange_explicit(&lock->serving, 0, memory_order_acq_rel);
+}
+
+void wd_fair_lock(struct wd_fair_lock *lock)
+{
+ __u32 my_ticket = atomic_fetch_add_explicit(&lock->ticket, 1,
+ memory_order_acq_rel);
+ __u32 val = atomic_load_explicit(&lock->serving, memory_order_acquire);
+ __u64 cnt = 0;
+
+ if (val == my_ticket)
+ return;
+
+ do {
+ if (++cnt == LOCK_TRY_CNT)
+ WD_ERR("failed to get lock with %lu times\n", LOCK_TRY_CNT);
+
+ val = atomic_load_explicit(&lock->serving, memory_order_acquire);
+ } while (val != my_ticket);
+}
+
+void wd_fair_unlock(struct wd_fair_lock *lock)
+{
+ atomic_fetch_add_explicit(&lock->serving, 1, memory_order_acq_rel);
+}
+
void *drv_iova_map(struct wd_queue *q, void *va, size_t sz)
{
struct q_info *qinfo = q->qinfo;
diff --git a/v1/wd_util.h b/v1/wd_util.h
index 21137d2d..70f9ed92 100644
--- a/v1/wd_util.h
+++ b/v1/wd_util.h
@@ -111,6 +111,11 @@ struct wd_lock {
__u8 lock;
};
+struct wd_fair_lock {
+ volatile __u32 ticket;
+ volatile __u32 serving;
+};
+
struct wd_ss_region {
void *va;
unsigned long long pa;
@@ -392,6 +397,9 @@ static inline uint32_t wd_reg_read(void *reg_addr)
void wd_spinlock(struct wd_lock *lock);
void wd_unspinlock(struct wd_lock *lock);
+void wd_fair_init(struct wd_fair_lock *lock);
+void wd_fair_lock(struct wd_fair_lock *lock);
+void wd_fair_unlock(struct wd_fair_lock *lock);
void *wd_drv_mmap_qfr(struct wd_queue *q, enum uacce_qfrt qfrt, size_t size);
void wd_drv_unmmap_qfr(struct wd_queue *q, void *addr,
enum uacce_qfrt qfrt, size_t size);
--
2.33.0
1
0
您好!
sig-AccLib 邀请您参加 2024-12-25 11:00 召开的Zoom会议
会议主题:2024/12/25 AccLIb SIG 双周例会 11:00 - 12:00
会议内容:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
会议链接:https://us06web.zoom.us/j/87231569205?pwd=h4OaT6BML3ZmPXDiWL8aCUJSx2opeH.1
会议纪要:https://etherpad.openeuler.org/p/sig-AccLib-meetings
更多资讯尽在:https://www.openeuler.org/zh/
Hello!
sig-AccLib invites you to attend the Zoom conference will be held at 2024-12-25 11:00,
The subject of the conference is 2024/12/25 AccLIb SIG 双周例会 11:00 - 12:00,
Summary:
会议链接:linaro-org.zoom.us/j/91879279131
会议纪要:etherpad.openeuler.org/p/sig-AccLib-meet
You can join the meeting at https://us06web.zoom.us/j/87231569205?pwd=h4OaT6BML3ZmPXDiWL8aCUJSx2opeH.1.
Add topics at https://etherpad.openeuler.org/p/sig-AccLib-meetings.
More information: https://www.openeuler.org/en/
1
0
*** BLURB HERE ***
Chenghai Huang (1):
uadk - fix the log frequency limit function
Qi Tao (2):
uadk: add compilation options
uadk_tool: fix error in saving the aead dst data
Wenkai Lin (7):
uadk: fix for set hashagg session state
uadk/v1: support the hmac(sm3)-cbc(sm4) algorithm
uadk: fix for the algorithm name of the aead cbc mode
uadk/v1: Add stream mode for AES-GCM and SM4-GCM
uadk/v1: add assoc bytes check
uadk/v1: set aead msg state for the hardware v2
uadk/v1: fix input length check for aead stream mode.
Zhiqi Song (3):
uadk/hpre: modify privkey transform method of ecc
v1/hpre: modify privkey transform method of ecc
uadk/v1: cleanup key format transform function
Makefile.am | 17 +-
drv/hash_mb/hash_mb.c | 4 +
drv/hisi_comp.c | 6 +-
drv/hisi_dae.c | 34 ++-
drv/hisi_hpre.c | 18 +-
drv/hisi_sec.c | 8 +-
include/crypto/sm4.h | 18 ++
include/wd_rsa.h | 2 -
include/wd_util.h | 10 +-
lib/crypto/sm4.c | 176 ++++++++++++++
uadk_tool/benchmark/sec_uadk_benchmark.c | 6 +
uadk_tool/benchmark/uadk_benchmark.c | 6 +-
uadk_tool/test/test_sec.c | 4 +-
v1/drv/hisi_hpre_udrv.c | 28 +--
v1/drv/hisi_qm_udrv.c | 12 +-
v1/drv/hisi_sec_udrv.c | 296 ++++++++++++++++++++++-
v1/drv/hisi_sec_udrv.h | 9 +-
v1/drv/hisi_zip_udrv.c | 26 +-
v1/test/hisi_sec_test/test_hisi_sec.c | 4 +-
v1/wd_adapter.c | 4 +-
v1/wd_adapter.h | 2 +-
v1/wd_aead.c | 67 ++++-
v1/wd_aead.h | 12 +
v1/wd_cipher.c | 2 +-
v1/wd_digest.c | 6 +-
v1/wd_ecc.c | 10 +-
wd.c | 2 +-
wd_aead.c | 10 +-
wd_agg.c | 43 ++--
wd_alg.c | 2 +
wd_cipher.c | 6 +-
wd_comp.c | 16 +-
wd_digest.c | 14 +-
wd_ecc.c | 13 -
wd_mempool.c | 2 +-
wd_rsa.c | 6 +-
wd_util.c | 16 +-
37 files changed, 739 insertions(+), 178 deletions(-)
create mode 100644 include/crypto/sm4.h
create mode 100644 lib/crypto/sm4.c
--
2.33.0
1
13