From: Wenkai Lin linwenkai6@hisilicon.com
The session should be updated after job is done successfully.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- include/wd_digest.h | 2 +- wd_digest.c | 44 +++++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/include/wd_digest.h b/include/wd_digest.h index 874e9c1..9abbe16 100644 --- a/include/wd_digest.h +++ b/include/wd_digest.h @@ -180,7 +180,7 @@ void wd_digest_uninit2(void); handle_t wd_digest_alloc_sess(struct wd_digest_sess_setup *setup);
/** - * wd_alg_digest_free_sess() - Free digest session. + * wd_digest_free_sess() - Free digest session. * @h_sess: session handler which will be free */ void wd_digest_free_sess(handle_t h_sess); diff --git a/wd_digest.c b/wd_digest.c index 0847fe3..fd26cc8 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -63,12 +63,13 @@ struct wd_digest_sess { __u32 key_bytes; void *sched_key; /* - * Notify the BD state, zero is frist BD, non-zero - * is middle or final BD. + * Notify the stream message state, zero is frist message, + * non-zero is middle or final message. */ - int bd_state; - /* Total of data for stream mode */ - __u64 long_data_len; + int msg_state; + + /* Total data length for stream mode */ + __u64 long_data_len; };
struct wd_env_config wd_digest_env_config; @@ -542,15 +543,10 @@ static void fill_request_msg(struct wd_digest_msg *msg, msg->out_bytes = req->out_bytes; msg->data_fmt = req->data_fmt; msg->has_next = req->has_next; - sess->long_data_len += req->in_bytes; - msg->long_data_len = sess->long_data_len; + msg->long_data_len = sess->long_data_len + req->in_bytes;
- /* To store the stream BD state, iv_bytes also means BD state */ - msg->iv_bytes = sess->bd_state; - if (req->has_next == 0) { - sess->long_data_len = 0; - sess->bd_state = 0; - } + /* Use iv_bytes to store the stream message state */ + msg->iv_bytes = sess->msg_state; }
static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *dsess, @@ -565,17 +561,23 @@ static int send_recv_sync(struct wd_ctx_internal *ctx, struct wd_digest_sess *ds pthread_spin_lock(&ctx->lock); ret = wd_handle_msg_sync(wd_digest_setting.driver, &msg_handle, ctx->ctx, msg, NULL, wd_digest_setting.config.epoll_en); + pthread_spin_unlock(&ctx->lock); if (unlikely(ret)) - goto out; + return ret;
- /* - * non-zero is final BD or middle BD as stream mode. - */ - dsess->bd_state = msg->has_next; + /* After a stream mode job was done, update session long_data_len */ + if (msg->has_next) { + /* Long hash(first and middle message) */ + dsess->long_data_len += msg->in_bytes; + } else if (msg->iv_bytes) { + /* Long hash(final message) */ + dsess->long_data_len = 0; + }
-out: - pthread_spin_unlock(&ctx->lock); - return ret; + /* Update session message state */ + dsess->msg_state = msg->has_next; + + return 0; }
int wd_do_digest_sync(handle_t h_sess, struct wd_digest_req *req)