From: Wenkai Lin linwenkai6@hisilicon.com
Currently, we use 0 and 1 to fill the has_next filed of digest request, 0 indicates that there is no next packet, 1 indicates there are next packets, we use WD_DIGEST_END and WD_DIGEST_DOING to mark those messages.
In another scenario, when user calculates on data flow A, after partial data is calculated, the result may be copied to data flow B so that flow B can calculate different data. However, flow B uses a new session, there's no information required for continuing calculation. Therefore, messages with this information need to be delivered to uadk, so we use WD_DIGEST_STREAM_END and WD_DIGEST_STREAM_DOING to mark those messages, long_data_len is also added to messages to store the length of the processed data.
After uadk set long data length and msg_state for the session, it will also change the status of has_next, change WD_DIGEST_STREAM_END to WD_DIGEST_END, WD_DIGEST_STREAM_DOING to WD_DIGEST_DOING.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- include/wd_digest.h | 19 ++++++++++++++++++- wd_digest.c | 10 ++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/include/wd_digest.h b/include/wd_digest.h index 9abbe16..7539866 100644 --- a/include/wd_digest.h +++ b/include/wd_digest.h @@ -78,6 +78,20 @@ enum wd_digest_mode { WD_DIGEST_MODE_MAX, };
+/** + * wd_digest_msg_state - Message state of digest + * @WD_DIGEST_END: Final message or single block message + * @WD_DIGEST_DOING: First message or middle message + * @WD_DIGEST_STREAM_END: Final message carrying long data information + * @WD_DIGEST_STREAM_DOING: Middle message carrying long data information + */ +enum wd_digest_msg_state { + WD_DIGEST_END = 0x0, + WD_DIGEST_DOING, + WD_DIGEST_STREAM_END, + WD_DIGEST_STREAM_DOING, +}; + /** * wd_digest_sess_setup - Parameters which is used to allocate a digest session * @alg: digest algorithm type, denoted by enum wd_digest_type @@ -100,9 +114,11 @@ typedef void *wd_digest_cb_t(void *cb_param); * @out_buf_bytes: actual output buffer size * @iv: input iv data addrss for AES_GMAC * @iv_bytes: input iv data size - * @has_next: is there next data block + * @has_next: message state, all types are defined in enum wd_digest_msg_state. * @cb: callback function for async mode * @cb_param: pointer of callback parameter + * @long_data_len: total length of data has been processed, it is only needed by + * the data flow switched to another session for processing. * * Note: If there is a alg selected in session, alg below will be ignore * otherwise, alg here will be used. Same as mode below. @@ -125,6 +141,7 @@ struct wd_digest_req { __u8 data_fmt; wd_digest_cb_t *cb; void *cb_param; + __u64 long_data_len; };
struct wd_cb_tag { diff --git a/wd_digest.c b/wd_digest.c index fd26cc8..69c4b28 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -531,6 +531,16 @@ static void fill_request_msg(struct wd_digest_msg *msg, { memcpy(&msg->req, req, sizeof(struct wd_digest_req));
+ if (unlikely(req->has_next == WD_DIGEST_STREAM_END)) { + sess->long_data_len = req->long_data_len; + sess->msg_state = WD_DIGEST_DOING; + req->has_next = WD_DIGEST_END; + } else if (unlikely(req->has_next == WD_DIGEST_STREAM_DOING)) { + sess->long_data_len = req->long_data_len; + sess->msg_state = WD_DIGEST_DOING; + req->has_next = WD_DIGEST_DOING; + } + msg->alg_type = WD_DIGEST; msg->alg = sess->alg; msg->mode = sess->mode;