From ed0e7b699d9bd6d531225bc7e6907e7191bc94d8 Mon Sep 17 00:00:00 2001 From: yuzh <1109426275@qq.com> Date: Sun, 28 Sep 2025 16:14:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=BC=82=E6=AD=A5=E6=96=B9?= =?UTF-8?q?=E6=A1=88=E6=94=AF=E6=8C=81zlib=E6=A0=BC=E5=BC=8F=E8=A7=A3?= =?UTF-8?q?=E5=8E=8B=E7=BC=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KAEZlib/include/kaezip.h | 17 ++++- KAEZlib/src/kaezip_async_adapter.c | 107 ++++++++++++++++++++++++----- KAEZlib/src/kaezip_async_adapter.h | 12 ++-- KAEZlib/src/v1/kaezip_async_comp.c | 66 +++++++++++++----- KAEZlib/src/v1/kaezip_async_comp.h | 1 + KAEZlib/src/v1/kaezip_common.h | 3 +- KAEZlib/src/v1/kaezip_ctx.h | 3 +- KAEZlib/src/v1/kaezip_init.c | 6 +- KAEZlib/src/v1/kaezip_init.h | 2 +- 9 files changed, 168 insertions(+), 49 deletions(-) diff --git a/KAEZlib/include/kaezip.h b/KAEZlib/include/kaezip.h index b273a56..aae3f1a 100644 --- a/KAEZlib/include/kaezip.h +++ b/KAEZlib/include/kaezip.h @@ -160,5 +160,20 @@ int KAEZIP_decompress_async_in_session(void *sess, const struct kaezip_buffer_li * @param: sess : session */ void KAEZIP_reset_session(void *sess); -#endif +/** + * @brief: Initialize Task Queues and Threads on the KAE Side with zlib format. +* @param: usr_map : function to translate src/dst buf's VA to PA/IOVA +* @param: level : an integer from 0 to 9 or -1 controlling the level of compression +* @param: windowBits : an integer from 8 to 15 to control the size of sliding window +* @return: session, NULL if fail +*/ +void *KAEZIP_create_async_compress_session_zlib(iova_map_fn usr_map, int level, int windowBits); + +/** + * @brief: Initialize Task Queues and Threads on the KAE Side for decompress with zlib format. + * @param: usr_map : function to translate src/dst buf's VA to PA/IOVA + * @return: session, NULL if fail + */ +void *KAEZIP_create_async_decompress_session_zlib(iova_map_fn usr_map); +#endif diff --git a/KAEZlib/src/kaezip_async_adapter.c b/KAEZlib/src/kaezip_async_adapter.c index 8457376..7580be9 100644 --- a/KAEZlib/src/kaezip_async_adapter.c +++ b/KAEZlib/src/kaezip_async_adapter.c @@ -18,7 +18,8 @@ #include "uadk/wd.h" -static void kaezip_dequeue_process(struct kaezip_async_ctrl *ctrl, kaezip_task_queue *task_queue, int budget, int comp_optype, compress_async_fn compress_fn) +static void kaezip_dequeue_process(struct kaezip_async_ctrl *ctrl, kaezip_task_queue *task_queue, int budget, + int comp_optype, int comp_algtype, compress_async_fn compress_fn) { int cnt = 0; // 等待任务 @@ -44,7 +45,7 @@ static void kaezip_dequeue_process(struct kaezip_async_ctrl *ctrl, kaezip_task_q // 更新 ci,复用空闲位置 task_queue->ci++; // 执行压缩操作 - compress_fn(ctrl, task.src, task.dst, task.callback, task.result, task.data_format, comp_optype); + compress_fn(ctrl, task.src, task.dst, task.callback, task.result, task.data_format, comp_optype, comp_algtype); cnt++; } return; @@ -121,15 +122,29 @@ static int kaezip_check_param_valid(const struct kaezip_buffer_list *src, struct return KAE_ZLIB_INVAL_PARA; } result->src_size = 0; - for (unsigned int i = 0; i < src->buf_num; i++) { - if (unlikely(src->buf[i].data == NULL || src->buf[i].buf_len == 0 || src->buf[i].buf_len > REQ_BUFFER_SIZE)) { + + // 对于 zlib 格式,第一个SGE缓冲区大小不得小于2字节,用于容纳zlib-header + if (unlikely(src->buf[0].data == NULL || src->buf[0].buf_len == 0 || + src->buf[0].buf_len > REQ_BUFFER_MAX_SIZE || src->buf[0].buf_len < REQ_BUFFER_MIN_SIZE)) { + return KAE_ZLIB_INVAL_PARA; + } + + for (unsigned int i = 1; i < src->buf_num; i++) { + if (unlikely(src->buf[i].data == NULL || src->buf[i].buf_len == 0 || + src->buf[i].buf_len > REQ_BUFFER_MAX_SIZE)) { return KAE_ZLIB_INVAL_PARA; } result->src_size += src->buf[i].buf_len; } - for (unsigned int i = 0; i < dst->buf_num; i++) { - if (unlikely(dst->buf[i].data == NULL || dst->buf[i].buf_len == 0 || dst->buf[i].buf_len > REQ_BUFFER_SIZE)) { + if (unlikely(dst->buf[0].data == NULL || dst->buf[0].buf_len == 0 || + dst->buf[0].buf_len > REQ_BUFFER_MAX_SIZE || dst->buf[0].buf_len < REQ_BUFFER_MIN_SIZE)) { + return KAE_ZLIB_INVAL_PARA; + } + + for (unsigned int i = 1; i < dst->buf_num; i++) { + if (unlikely(dst->buf[i].data == NULL || dst->buf[i].buf_len == 0 || + dst->buf[i].buf_len > REQ_BUFFER_MAX_SIZE || dst->buf[i].buf_len < REQ_BUFFER_MIN_SIZE)) { return KAE_ZLIB_INVAL_PARA; } result->dst_len += dst->buf[i].buf_len; @@ -155,7 +170,7 @@ static int kaezip_check_session_valid(kaezip_session *sess, int comp_optype) static int kaezip_async_do_comp_in_session(kaezip_session *sess, const struct kaezip_buffer_list *src, struct kaezip_buffer_list *dst, kaezip_async_callback callback, struct kaezip_result *result, - enum kaezip_async_data_format data_format, int comp_optype) + enum kaezip_async_data_format data_format, int comp_optype, int comp_algtype) { kaezip_task_queue *task_queue = &sess->task_queue; kaezip_async_task_t task = {0}; @@ -166,14 +181,14 @@ static int kaezip_async_do_comp_in_session(kaezip_session *sess, const struct ka task.data_format = data_format; if (task_queue->pi != task_queue->ci && !kaezip_async_is_thread_do_comp_full(sess->ctrl)) { - kaezip_dequeue_process(sess->ctrl, task_queue, ASYNC_DEQUEUE_PROCESS_DEFAULT_BUDGET, comp_optype, kaezip_compress_async); + kaezip_dequeue_process(sess->ctrl, task_queue, ASYNC_DEQUEUE_PROCESS_DEFAULT_BUDGET, comp_optype, comp_algtype, kaezip_compress_async); } if (task_queue->pi != task_queue->ci || kaezip_async_is_thread_do_comp_full(sess->ctrl)) { return kaezip_enqueue(task_queue, &task); } else { return kaezip_compress_async(sess->ctrl, task.src, task.dst, task.callback, task.result, - task.data_format, comp_optype); + task.data_format, comp_optype, comp_algtype); } } @@ -185,7 +200,7 @@ int KAEZIP_compress_async_in_session(void *sess, const struct kaezip_buffer_list return KAE_ZLIB_INVAL_PARA; } - return kaezip_async_do_comp_in_session(sess, src, dst, callback, result, KAEZIP_ASYNC_BLOCK, WCRYPTO_DEFLATE); + return kaezip_async_do_comp_in_session(sess, src, dst, callback, result, KAEZIP_ASYNC_BLOCK, WCRYPTO_DEFLATE, ((kaezip_session *)sess)->comp_algtype); } void KAEZIP_async_polling_in_session(void *sess, int budget) @@ -205,7 +220,8 @@ void KAEZIP_async_polling_in_session(void *sess, int budget) while (ret > 0 && cnt < budget) { ret = kaezip_async_compress_polling(ctrl, ASYNC_POLLING_DEFAULT_BUDGET); if (!kaezip_async_is_thread_do_comp_full(ctrl)) { - kaezip_dequeue_process(ctrl, task_queue, ASYNC_DEQUEUE_PROCESS_DEFAULT_BUDGET, ((kaezip_session *)sess)->comp_optype, kaezip_compress_async); + kaezip_dequeue_process(ctrl, task_queue, ASYNC_DEQUEUE_PROCESS_DEFAULT_BUDGET, ((kaezip_session *)sess)->comp_optype, + ((kaezip_session *)sess)->comp_algtype, kaezip_compress_async); } cnt += ret; } @@ -221,12 +237,13 @@ void *KAEZIP_create_async_compress_session(iova_map_fn usr_map) sess->usr_map = usr_map; sess->comp_optype = WCRYPTO_DEFLATE; + sess->comp_algtype = WCRYPTO_RAW_DEFLATE; ret = kaezip_task_queue_init(&sess->task_queue, 0, NULL); if (ret != 0) { free(sess); return NULL; } - ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype); + ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype, sess->comp_algtype); if (ret != 0) { kaezip_task_queue_free(&sess->task_queue); free(sess); @@ -247,7 +264,7 @@ void KAEZIP_destroy_async_compress_session(void *sess) static int kaezip_task_flush_callback(struct kaezip_async_ctrl *ctrl, const struct kaezip_buffer_list *src, struct kaezip_buffer_list *dst, kaezip_async_callback callback, struct kaezip_result *result, - enum kaezip_async_data_format data_format, int comp_optype) + enum kaezip_async_data_format data_format, int comp_optype, int comp_algtype) { result->status = KAE_ZLIB_HW_TIMEOUT_FAIL; result->dst_len = 0; @@ -257,13 +274,13 @@ static int kaezip_task_flush_callback(struct kaezip_async_ctrl *ctrl, const stru static void kaezip_flush_task_queue(kaezip_session *sess) { - kaezip_dequeue_process(sess->ctrl, &sess->task_queue, 0, sess->comp_optype, kaezip_task_flush_callback); + kaezip_dequeue_process(sess->ctrl, &sess->task_queue, 0, sess->comp_optype, sess->comp_algtype, kaezip_task_flush_callback); } void KAEZIP_reset_session(void *sess) { if (sess) { - kaezip_hw_timeout_handle(((kaezip_session *)sess)->ctrl, ((kaezip_session *)sess)->comp_optype); + kaezip_hw_timeout_handle(((kaezip_session *)sess)->ctrl, ((kaezip_session *)sess)->comp_optype, ((kaezip_session *)sess)->comp_algtype); kaezip_flush_task_queue(sess); } } @@ -278,12 +295,13 @@ void *KAEZIP_create_async_decompress_session(iova_map_fn usr_map) sess->usr_map = usr_map; sess->comp_optype = WCRYPTO_INFLATE; + sess->comp_algtype = WCRYPTO_RAW_DEFLATE; ret = kaezip_task_queue_init(&sess->task_queue, 0, NULL); if (ret != 0) { free(sess); return NULL; } - ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype); + ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype, sess->comp_algtype); if (ret != 0) { kaezip_task_queue_free(&sess->task_queue); free(sess); @@ -305,5 +323,60 @@ int KAEZIP_decompress_async_in_session(void *sess, const struct kaezip_buffer_li return KAE_ZLIB_INVAL_PARA; } - return kaezip_async_do_comp_in_session(sess, src, dst, callback, result, KAEZIP_ASYNC_BLOCK, WCRYPTO_INFLATE); + return kaezip_async_do_comp_in_session(sess, src, dst, callback, result, KAEZIP_ASYNC_BLOCK, WCRYPTO_INFLATE, ((kaezip_session *)sess)->comp_algtype); } + +void *KAEZIP_create_async_compress_session_zlib(iova_map_fn usr_map, int level, int windowBits) +{ + kaezip_session *sess = (kaezip_session *)kae_malloc(sizeof(kaezip_session)); + int ret = 0; + + if (!sess) + return NULL; + + sess->usr_map = usr_map; + sess->comp_optype = WCRYPTO_DEFLATE; + sess->comp_algtype = WCRYPTO_ZLIB; + ret = kaezip_task_queue_init(&sess->task_queue, 0, NULL); + if (ret != 0) { + free(sess); + return NULL; + } + ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype, sess->comp_algtype); + // generate zlib header + kaezip_set_zlib_header(sess->ctrl, level, windowBits); + + if (ret != 0) { + kaezip_task_queue_free(&sess->task_queue); + free(sess); + return NULL; + } + + return sess; +} + +void *KAEZIP_create_async_decompress_session_zlib(iova_map_fn usr_map) +{ + kaezip_session *sess = (kaezip_session *)kae_malloc(sizeof(kaezip_session)); + int ret = 0; + + if (!sess) + return NULL; + + sess->usr_map = usr_map; + sess->comp_optype = WCRYPTO_INFLATE; + sess->comp_algtype = WCRYPTO_ZLIB; + ret = kaezip_task_queue_init(&sess->task_queue, 0, NULL); + if (ret != 0) { + free(sess); + return NULL; + } + ret = kaezip_async_instances_init(&sess->ctrl, usr_map, sess->comp_optype, sess->comp_algtype); + if (ret != 0) { + kaezip_task_queue_free(&sess->task_queue); + free(sess); + return NULL; + } + + return sess; +} \ No newline at end of file diff --git a/KAEZlib/src/kaezip_async_adapter.h b/KAEZlib/src/kaezip_async_adapter.h index 67cd8cf..3db150f 100644 --- a/KAEZlib/src/kaezip_async_adapter.h +++ b/KAEZlib/src/kaezip_async_adapter.h @@ -64,25 +64,27 @@ typedef struct { iova_map_fn usr_map; struct kaezip_async_ctrl *ctrl; int comp_optype; + int comp_algtype; } kaezip_session; typedef void *(*task_queue_process_fn)(void *); typedef int (*compress_async_fn)(struct kaezip_async_ctrl *ctrl, const struct kaezip_buffer_list *src, struct kaezip_buffer_list *dst, kaezip_async_callback callback, struct kaezip_result *result, - enum kaezip_async_data_format data_format, int comp_optype); + enum kaezip_async_data_format data_format, int comp_optype, int comp_algtype); -void *kaezip_init_v1(int win_size, int is_sgl, int comp_optype); +void *kaezip_init_v1(int win_size, int is_sgl, int comp_optype, int comp_algtype); int kaezip_get_win_size(void); int kaezip_compress_async(struct kaezip_async_ctrl *ctrl, const struct kaezip_buffer_list *src, struct kaezip_buffer_list *dst, kaezip_async_callback callback, struct kaezip_result *result, - enum kaezip_async_data_format data_format, int comp_optype); + enum kaezip_async_data_format data_format, int comp_optype, int comp_algtype); int kaezip_async_compress_polling(struct kaezip_async_ctrl *ctrl, int budget); int kaezip_async_is_thread_do_comp_full(struct kaezip_async_ctrl *ctrl); -int kaezip_async_instances_init(struct kaezip_async_ctrl **ctrl, iova_map_fn usr_map, int comp_optype); +int kaezip_async_instances_init(struct kaezip_async_ctrl **ctrl, iova_map_fn usr_map, int comp_optype, int comp_algtype); void kaezip_async_instances_deinit(struct kaezip_async_ctrl *ctrl); -void kaezip_hw_timeout_handle(struct kaezip_async_ctrl *ctrl, int comp_optype); +void kaezip_hw_timeout_handle(struct kaezip_async_ctrl *ctrl, int comp_optype, int comp_algtype); +void kaezip_set_zlib_header(struct kaezip_async_ctrl *ctrl, int level, int windowBits); #endif \ No newline at end of file diff --git a/KAEZlib/src/v1/kaezip_async_comp.c b/KAEZlib/src/v1/kaezip_async_comp.c index 75199ef..28024f9 100644 --- a/KAEZlib/src/v1/kaezip_async_comp.c +++ b/KAEZlib/src/v1/kaezip_async_comp.c @@ -9,6 +9,7 @@ #include "kaezip_async_comp.h" #include "kaezip_log.h" #include "kaezip_init.h" +#include "kaezip_common.h" #define PREFL1_64B(ptr) __builtin_prefetch((ptr), 0, 0) @@ -445,7 +446,7 @@ void kaezip_ctx_clear(struct kaezip_async_ctrl *ctrl) } } -int kaezip_async_instances_init(struct kaezip_async_ctrl **ctrl, iova_map_fn usr_map, int comp_optype) +int kaezip_async_instances_init(struct kaezip_async_ctrl **ctrl, iova_map_fn usr_map, int comp_optype, int comp_algtype) { struct kaezip_async_ctrl *new_ctrl = (struct kaezip_async_ctrl *)kae_malloc(sizeof(struct kaezip_async_ctrl)); if (!new_ctrl) @@ -458,7 +459,7 @@ int kaezip_async_instances_init(struct kaezip_async_ctrl **ctrl, iova_map_fn usr new_ctrl->usr_map = usr_map; new_ctrl->is_polling = TRUE; for (int i = 0; i < MAX_NUM_IN_COMP; i++) { - new_ctrl->kz_ctx[i] = kaezip_init_v1(kaezip_get_win_size(), is_sgl, comp_optype); + new_ctrl->kz_ctx[i] = kaezip_init_v1(kaezip_get_win_size(), is_sgl, comp_optype, comp_algtype); if (new_ctrl->kz_ctx[i] == NULL) { goto free_kz_ctx; } @@ -537,7 +538,7 @@ int kaezip_async_compress_polling(struct kaezip_async_ctrl *ctrl, int budget) return cnt; } -void kaezip_hw_timeout_handle(struct kaezip_async_ctrl *ctrl, int comp_optype) +void kaezip_hw_timeout_handle(struct kaezip_async_ctrl *ctrl, int comp_optype, int comp_algtype) { struct kaezip_compress_ctx *compress_ctx = ctrl->ctx_head; struct kaezip_async_req *req = NULL; @@ -572,7 +573,7 @@ void kaezip_hw_timeout_handle(struct kaezip_async_ctrl *ctrl, int comp_optype) if (ctrl->kz_ctx[i] != NULL) { continue; } - kaezip_ctx_t *kz_ctx = kaezip_init_v1(win_size, is_sgl, comp_optype); + kaezip_ctx_t *kz_ctx = kaezip_init_v1(win_size, is_sgl, comp_optype, comp_algtype); if (kz_ctx == NULL) { return; } @@ -583,14 +584,14 @@ void kaezip_hw_timeout_handle(struct kaezip_async_ctrl *ctrl, int comp_optype) static struct timespec polling_timeout_10us = { 0, 10000 }; // 10us超时 -static kaezip_ctx_t *kaezip_async_init_ctx(struct kaezip_async_ctrl *ctrl, int comp_optype) +static kaezip_ctx_t *kaezip_async_init_ctx(struct kaezip_async_ctrl *ctrl, int comp_optype, int comp_algtype) { int enter_polling = 0; kaezip_ctx_t *kz_ctx = NULL; if (unlikely(ctrl->kz_ctx[ctrl->ctx_index] == NULL)) { int is_sgl = (ctrl->usr_map != NULL) ? 1 : 0; - kz_ctx = kaezip_init_v1(kaezip_get_win_size(), is_sgl, comp_optype); + kz_ctx = kaezip_init_v1(kaezip_get_win_size(), is_sgl, comp_optype, comp_algtype); while (kz_ctx == NULL) { // 本质来说,这个初始化函数就初始化了其中的kaeConfig,其他是没有的,所以在外面要赋值 struct timespec timeout; if (enter_polling == 0) { @@ -604,7 +605,7 @@ static kaezip_ctx_t *kaezip_async_init_ctx(struct kaezip_async_ctrl *ctrl, int c } (void)kaezip_async_compress_polling(ctrl, 1); - kz_ctx = kaezip_init_v1(kaezip_get_win_size(), is_sgl, comp_optype); + kz_ctx = kaezip_init_v1(kaezip_get_win_size(), is_sgl, comp_optype, comp_algtype); } ctrl->kz_ctx[ctrl->ctx_index] = kz_ctx; ctrl->kz_ctx[ctrl->ctx_index]->usr_map = ctrl->usr_map; @@ -628,10 +629,10 @@ static kaezip_ctx_t *kaezip_async_init_ctx(struct kaezip_async_ctrl *ctrl, int c return kz_ctx; } -static int kaezip_send_async_compress(struct kaezip_async_ctrl *ctrl, struct kaezip_async_req *req, int comp_optype) +static int kaezip_send_async_compress(struct kaezip_async_ctrl *ctrl, struct kaezip_async_req *req, int comp_optype, int comp_algtype) { // 1.kae上下文初始化函数调用 - req->kz_ctx = kaezip_async_init_ctx(ctrl, comp_optype); + req->kz_ctx = kaezip_async_init_ctx(ctrl, comp_optype, comp_algtype); if (unlikely(req->kz_ctx == NULL)) { US_ERR("Get kae hw ctx failed!\n"); return KAE_ZLIB_INIT_FAIL; @@ -648,7 +649,8 @@ static int kaezip_send_async_compress(struct kaezip_async_ctrl *ctrl, struct kae return ret; } -static void kaezip_fill_hw_req_dst_buf_list(struct kaezip_async_req *req, const struct kaezip_buffer_list *dst) +static void kaezip_fill_hw_req_dst_buf_list(struct kaezip_async_ctrl *ctrl, struct kaezip_async_req *req, + const struct kaezip_buffer_list *dst) { unsigned int index = 0; @@ -665,9 +667,20 @@ static void kaezip_fill_hw_req_dst_buf_list(struct kaezip_async_req *req, const req->dst.buf_num++; } + + if (ctrl->kz_ctx[0]->comp_type == WCRYPTO_DEFLATE && ctrl->kz_ctx[0]->comp_alg_type == WCRYPTO_ZLIB) { + // 添加2字节的 zlib header + ((char*)req->dst.buf[0].data)[0] = ctrl->header[0]; + ((char*)req->dst.buf[0].data)[1] = ctrl->header[1]; + void* original_ptr = req->dst.buf[0].data; + req->dst.buf[0].data = (char*)original_ptr + 2; + req->dst.buf[0].buf_len -= 2; + req->dst_len -= 2; + } } -static void kaezip_fill_hw_req_src_buf_list(struct kaezip_async_req *req, const struct kaezip_buffer_list *src) +static void kaezip_fill_hw_req_src_buf_list(struct kaezip_async_ctrl *ctrl, struct kaezip_async_req *req, + const struct kaezip_buffer_list *src) { unsigned int index = 0; @@ -684,9 +697,17 @@ static void kaezip_fill_hw_req_src_buf_list(struct kaezip_async_req *req, const req->src.buf_num++; } + + if (ctrl->kz_ctx[0]->comp_alg_type == WCRYPTO_ZLIB && ctrl->kz_ctx[0]->comp_type == WCRYPTO_INFLATE) { + // 跳过 zlib 格式压缩文件的头部字段 + void* original_ptr = req->src.buf[0].data; + req->src.buf[0].data = (char*)original_ptr + 2; + req->src.buf[0].buf_len -= 2; + req->src_size -= 2; + } } -static void kaezip_async_compress_process(struct kaezip_async_ctrl *ctrl, void *arg, int comp_optype) +static void kaezip_async_compress_process(struct kaezip_async_ctrl *ctrl, void *arg, int comp_optype, int comp_algtype) { struct kaezip_compress_ctx *compress_ctx = arg; @@ -708,12 +729,11 @@ static void kaezip_async_compress_process(struct kaezip_async_ctrl *ctrl, void * return; } - // 针对zlib的matchlength转换定义的数据结构 - kaezip_fill_hw_req_src_buf_list(req, compress_ctx->src); - kaezip_fill_hw_req_dst_buf_list(req, compress_ctx->dst); + kaezip_fill_hw_req_src_buf_list(ctrl, req, compress_ctx->src); + kaezip_fill_hw_req_dst_buf_list(ctrl, req, compress_ctx->dst); int ret = KAE_ZLIB_SUCC; - ret = kaezip_send_async_compress(ctrl, req, comp_optype); + ret = kaezip_send_async_compress(ctrl, req, comp_optype, comp_algtype); if (ret != KAE_ZLIB_SUCC) { req->compress_ctx->status = KAE_ZLIB_COMP_FAIL; req->done = 1; @@ -771,7 +791,7 @@ static int kaezip_async_block_padding(struct kaezip_async_req *req, const struct struct wcrypto_comp_op_data *op_data = &kz_ctx->op_data; unsigned int output_len = op_data->produced; - if (req->kz_ctx[0].comp_type == WCRYPTO_DEFLATE) { + if (req->kz_ctx[0].comp_type == WCRYPTO_DEFLATE && req->kz_ctx[0].comp_alg_type == WCRYPTO_GZIP) { // extract checksum from dst buffer #ifdef KAE_USE_CRC32 if (req->compress_ctx->result->ibuf_crc != NULL) { @@ -781,6 +801,9 @@ static int kaezip_async_block_padding(struct kaezip_async_req *req, const struct #endif // remove checksum (4 Bytes) and isize (4 Bytes) in dst buffer output_len -= 8; + } else if (req->kz_ctx[0].comp_type == WCRYPTO_DEFLATE && req->kz_ctx[0].comp_alg_type == WCRYPTO_ZLIB) { + // 2 bytes header + output_len += 2; } return output_len; } @@ -791,7 +814,7 @@ const kaezip_post_process_handle_t g_post_process_handle[KAEZIP_ASYNC_BUTT] = { int kaezip_compress_async(struct kaezip_async_ctrl *ctrl, const struct kaezip_buffer_list *src, struct kaezip_buffer_list *dst, kaezip_async_callback callback, struct kaezip_result *result, - enum kaezip_async_data_format data_format, int comp_optype) + enum kaezip_async_data_format data_format, int comp_optype, int comp_algtype) { struct kaezip_compress_ctx *compress_ctx = &ctrl->ctx[ctrl->ctx_index]; @@ -819,9 +842,14 @@ int kaezip_compress_async(struct kaezip_async_ctrl *ctrl, const struct kaezip_bu } ctrl->tail = compress_ctx; - kaezip_async_compress_process(ctrl, compress_ctx, comp_optype); + kaezip_async_compress_process(ctrl, compress_ctx, comp_optype, comp_algtype); ctrl->ctx_index = (ctrl->ctx_index + 1) % MAX_NUM_IN_COMP; ctrl->cur_num_in_comp++; return KAE_ZLIB_SUCC; } + +void kaezip_set_zlib_header(struct kaezip_async_ctrl *ctrl, int level, int windowBits) +{ + ctrl->header = kaezip_get_fmt_header_zlib(level, windowBits); +} \ No newline at end of file diff --git a/KAEZlib/src/v1/kaezip_async_comp.h b/KAEZlib/src/v1/kaezip_async_comp.h index f40959b..631fe34 100644 --- a/KAEZlib/src/v1/kaezip_async_comp.h +++ b/KAEZlib/src/v1/kaezip_async_comp.h @@ -94,6 +94,7 @@ struct kaezip_async_ctrl { volatile int *stop_flag; iova_map_fn usr_map; int is_polling; + const char *header; }; #define KZL_MEMCPY_16(dst, src, size) vst1q_u8((dst), vld1q_u8(src)) diff --git a/KAEZlib/src/v1/kaezip_common.h b/KAEZlib/src/v1/kaezip_common.h index 3c4adf7..8fb7451 100644 --- a/KAEZlib/src/v1/kaezip_common.h +++ b/KAEZlib/src/v1/kaezip_common.h @@ -35,8 +35,7 @@ int kaezip_winbits2algtype(int windowBits); const uint32_t kaezip_fmt_header_sz(int comp_alg_type, int comp_optype, const void* src); const char* kaezip_get_fmt_header(int comp_alg_type, int level, int windowBits); +char* kaezip_get_fmt_header_zlib(int level, int windowBits); void kaezip_set_fmt_tail(kaezip_ctx_t *kz_ctx); void kaezip_deflate_addcrc(kaezip_ctx_t *kz_ctx); #endif - - diff --git a/KAEZlib/src/v1/kaezip_ctx.h b/KAEZlib/src/v1/kaezip_ctx.h index fb1eeac..1530edf 100644 --- a/KAEZlib/src/v1/kaezip_ctx.h +++ b/KAEZlib/src/v1/kaezip_ctx.h @@ -57,7 +57,8 @@ struct wcrypto_end_block { #define MAX_KAE_CTX_DEPTH 64 #define REQ_BUFFER_MAX 255 // uadk支持最大的sgl buf数量 -#define REQ_BUFFER_SIZE (8*1024*1024) // uadk支持最大sge的大小 +#define REQ_BUFFER_MAX_SIZE (8*1024*1024) // uadk支持最大sge的大小 +#define REQ_BUFFER_MIN_SIZE 2 // zlib-format 存在2字节头部 #define KAE_ASYNC_MAX_RECV_TIMES (2000000) #define FLAG_NUM (10) struct kaezip_async_sleep_info { diff --git a/KAEZlib/src/v1/kaezip_init.c b/KAEZlib/src/v1/kaezip_init.c index 6d848db..bc909b3 100644 --- a/KAEZlib/src/v1/kaezip_init.c +++ b/KAEZlib/src/v1/kaezip_init.c @@ -10,13 +10,13 @@ #include "kaezip_init.h" #include "kaezip_log.h" -void *kaezip_init_v1(int win_size, int is_sgl, int comp_type) +void *kaezip_init_v1(int win_size, int is_sgl, int comp_type, int comp_algtype) { kaezip_ctx_t *kaezip_ctx = NULL; - if (comp_type == WCRYPTO_DEFLATE) { + if (comp_type == WCRYPTO_DEFLATE && comp_algtype == WCRYPTO_RAW_DEFLATE) { kaezip_ctx = kaezip_get_ctx(WCRYPTO_GZIP, comp_type, win_size, is_sgl); } else { - kaezip_ctx = kaezip_get_ctx(WCRYPTO_RAW_DEFLATE, comp_type, win_size, is_sgl); + kaezip_ctx = kaezip_get_ctx(comp_algtype, comp_type, win_size, is_sgl); } if (!kaezip_ctx) { US_ERR("kaezlib failed to get kaezip ctx!"); diff --git a/KAEZlib/src/v1/kaezip_init.h b/KAEZlib/src/v1/kaezip_init.h index 95fbc6f..57c110b 100644 --- a/KAEZlib/src/v1/kaezip_init.h +++ b/KAEZlib/src/v1/kaezip_init.h @@ -11,6 +11,6 @@ #include "kaezip_common.h" -void *kaezip_init_v1(int win_size, int is_sgl, int comp_type); +void *kaezip_init_v1(int win_size, int is_sgl, int comp_type, int comp_algtype); #endif \ No newline at end of file -- Gitee From 2a7886f6705163b818acbbcedef1c8e88a5ff63e Mon Sep 17 00:00:00 2001 From: yuzh <1109426275@qq.com> Date: Sun, 28 Sep 2025 16:41:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0KAEZlib=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KAEZlib/README.md | 8 ++++---- KAEZlib/src/kaezip_async_adapter.c | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/KAEZlib/README.md b/KAEZlib/README.md index 5edd734..b52e300 100644 --- a/KAEZlib/README.md +++ b/KAEZlib/README.md @@ -45,8 +45,8 @@ void *KAEZIP_create_async_compress_session(iova_map_fn usr_map); /** * @brief: compress async api * @param: sess : session - * @param: src [IN] : input data - * @param: dst [OUT] : output data, only support buf_num == 1 now. + * @param: src [IN] : input data, up to 255 SGES, each physically contiguous and ≤8 MB in size. + * @param: dst [OUT] : output data, up to 255 SGES, each physically contiguous and ≤8 MB in size. * @param: callback [IN] : async callback function,it can not be NULL, must be typedef void (*kaezip_async_callback)(struct kaezip_result *result); * @param: result [IN OUT] : async callback result,it can not be NULL. must be pointer of struct kaezip_result. * @return: 0 success, other fail @@ -78,8 +78,8 @@ void *KAEZIP_create_async_decompress_session(iova_map_fn usr_map); /** * @brief: decompress async api * @param: sess : session - * @param: src [IN] : input data - * @param: dst [OUT] : output data, only support buf_num == 1 now. + * @param: src [IN] : input data, up to 255 SGES, each physically contiguous and ≤8 MB in size. + * @param: dst [OUT] : output data, up to 255 SGES, each physically contiguous and ≤8 MB in size. * @param: callback [IN] : async callback function,it can not be NULL, must be typedef void (*kaezip_async_callback)(struct kaezip_result *result); * @param: result [IN OUT] : async callback result,it can not be NULL. must be pointer of struct kaezip_result. * @return: 0 success, other fail diff --git a/KAEZlib/src/kaezip_async_adapter.c b/KAEZlib/src/kaezip_async_adapter.c index 7580be9..67f9ec4 100644 --- a/KAEZlib/src/kaezip_async_adapter.c +++ b/KAEZlib/src/kaezip_async_adapter.c @@ -128,6 +128,7 @@ static int kaezip_check_param_valid(const struct kaezip_buffer_list *src, struct src->buf[0].buf_len > REQ_BUFFER_MAX_SIZE || src->buf[0].buf_len < REQ_BUFFER_MIN_SIZE)) { return KAE_ZLIB_INVAL_PARA; } + result->src_size += src->buf[0].buf_len; for (unsigned int i = 1; i < src->buf_num; i++) { if (unlikely(src->buf[i].data == NULL || src->buf[i].buf_len == 0 || @@ -141,6 +142,7 @@ static int kaezip_check_param_valid(const struct kaezip_buffer_list *src, struct dst->buf[0].buf_len > REQ_BUFFER_MAX_SIZE || dst->buf[0].buf_len < REQ_BUFFER_MIN_SIZE)) { return KAE_ZLIB_INVAL_PARA; } + result->dst_len += dst->buf[0].buf_len; for (unsigned int i = 1; i < dst->buf_num; i++) { if (unlikely(dst->buf[i].data == NULL || dst->buf[i].buf_len == 0 || -- Gitee