
From: Chenghai Huang <huangchenghai2@huawei.com> Modify the output size to ensure that the output size is 1.125 times of the input size. Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com> Signed-off-by: Qi Tao <taoqi10@huawei.com> --- drv/hisi_comp.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index bfeb8fad..e8c8d1d9 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -66,6 +66,11 @@ #define lower_32_bits(addr) ((__u32)((uintptr_t)(addr))) #define upper_32_bits(addr) ((__u32)((uintptr_t)(addr) >> HZ_HADDR_SHIFT)) +/* the min output buffer size is (input size * 1.125) */ +#define min_out_buf_size(inl) ((((__u64)inl * 9) + 7) >> 3) +/* the max input size is (output buffer size * 8 / 9) and align with 4 byte */ +#define max_in_data_size(outl) ((__u32)(((__u64)outl << 3) / 9) & 0xfffffffc) + #define HZ_MAX_SIZE (8 * 1024 * 1024) #define RSV_OFFSET 64 @@ -417,6 +422,16 @@ static int fill_buf_deflate_generic(struct hisi_zip_sqe *sqe, } } + /* + * When the output buffer is smaller than the 1.125*input len in STATEFUL, + * shrink the input len. + */ + if (msg->stream_mode == WD_COMP_STATEFUL && + (__u64)out_size < min_out_buf_size(in_size)) { + in_size = max_in_data_size(out_size); + msg->req.last = 0; + } + ret = buf_size_check_deflate(&in_size, &out_size); if (unlikely(ret)) return ret; @@ -551,6 +566,16 @@ static int fill_buf_deflate_sgl_generic(handle_t h_qp, struct hisi_zip_sqe *sqe, in_size -= head_size; } + /* + * When the output buffer is smaller than the 1.125*input len in STATEFUL, + * shrink the input len. + */ + if (msg->stream_mode == WD_COMP_STATEFUL && + (__u64)out_size < min_out_buf_size(in_size)) { + in_size = max_in_data_size(out_size); + msg->req.last = 0; + } + fill_buf_sgl_skip(sqe, src_skip, dst_skip); fill_buf_size_deflate(sqe, in_size, out_size); -- 2.33.0