[PATCH] uadk: Convert signed to unsigned in uadk drv bitwise operations

Convert signed to unsigned in uadk drv bitwise operations Signed-off-by: ZongYu Wu <wuzongyu1@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

From: Wenkai Lin <linwenkai6@hisilicon.com> Several modifications have been added to the batch address index scheme. The new scheme requires the input of batch_row_size along with the batch addr, it is used to calculate the address of a batch line during the build hash phase. Previously, hash_slot_row_size was used to get the size of a batch line during the gather phase, but now batch_row_size is used instead. The index_batch_type is expanded by 2 bits to support three types of index. In scenarios with more than 2800 batches cannot use the batch number index by hardware tasks but it can still be utilized by software calculations. Therefore, the hashjoin check on the number of batches is removed. Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> --- drv/hisi_dae.h | 11 +++++------ drv/hisi_dae_join_gather.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/drv/hisi_dae.h b/drv/hisi_dae.h index 1264813..050b872 100644 --- a/drv/hisi_dae.h +++ b/drv/hisi_dae.h @@ -108,7 +108,7 @@ struct dae_sqe { __u32 resv3 : 9; __u32 bd_invlid : 1; __u16 table_row_size; - __u16 resv4; + __u16 batch_row_size; __u32 batch_num; __u32 low_tag; __u32 hi_tag; @@ -122,12 +122,11 @@ struct dae_sqe { __u32 sva_prefetch_en : 1; __u32 counta_vld : 1; __u32 index_num : 5; - __u32 resv5 : 8; - __u32 index_batch_type : 1; - __u32 resv6 : 1; + __u32 resv4 : 8; + __u32 index_batch_type : 2; __u8 key_data_type[16]; __u8 agg_data_type[16]; - __u32 resv9[6]; + __u32 resv5[6]; __u64 addr_ext; __u16 key_col_bitmap; __u16 has_empty; @@ -141,7 +140,7 @@ struct dae_sqe { __u32 out_raw_num; __u32 data_row_offset; __u16 sum_overflow_cols; - __u16 resv10; + __u16 resv6; }; struct dae_ext_sqe { diff --git a/drv/hisi_dae_join_gather.c b/drv/hisi_dae_join_gather.c index db965d3..dcbeed4 100644 --- a/drv/hisi_dae_join_gather.c +++ b/drv/hisi_dae_join_gather.c @@ -43,6 +43,17 @@ enum dae_gather_stage { DAE_GATHER_COMPLETE = 0x7, }; +enum dae_join_index_type { + DAE_JOIN_BATCH_ADDR_INDEX = 0x1, + DAE_JOIN_BATCH_NUM_INDEX = 0x2, + DAE_JOIN_BATCH_ALL_INDEX = 0x3, +}; + +enum dae_gather_index_type { + DAE_GATHER_BATCH_NUM_INDEX = 0x0, + DAE_GATHER_BATCH_ADDR_INDEX = 0x1, +}; + enum dae_task_type { DAE_HASH_JOIN = 0x1, DAE_GATHER = 0x2, @@ -106,7 +117,10 @@ static void fill_join_gather_misc_field(struct wd_join_gather_msg *msg, sqe->index_num = cols_data->index_num; sqe->key_out_en = msg->key_out_en; sqe->break_point_en = sqe->init_row_num ? true : false; - sqe->index_batch_type = msg->index_type; + if (msg->index_type == WD_BATCH_ADDR_INDEX) + sqe->index_batch_type = DAE_JOIN_BATCH_ALL_INDEX; + else + sqe->index_batch_type = DAE_JOIN_BATCH_NUM_INDEX; break; case WD_JOIN_REHASH: sqe->task_type = DAE_HASH_JOIN; @@ -123,8 +137,11 @@ static void fill_join_gather_misc_field(struct wd_join_gather_msg *msg, sqe->task_type = DAE_GATHER; sqe->task_type_ext = DAE_GATHER_COMPLETE; sqe->multi_batch_en = msg->multi_batch_en; - sqe->index_batch_type = msg->index_type; sqe->data_row_num = msg->req.output_row_num; + if (msg->index_type == WD_BATCH_ADDR_INDEX) + sqe->index_batch_type = DAE_GATHER_BATCH_ADDR_INDEX; + else + sqe->index_batch_type = DAE_GATHER_BATCH_NUM_INDEX; break; default: break; @@ -199,8 +216,10 @@ static void fill_join_key_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sqe, case WD_JOIN_BUILD_HASH: usr_key = req->key_cols; hw_key = addr_list->input_addr; - if (msg->index_type == WD_BATCH_ADDR_INDEX) + if (msg->index_type == WD_BATCH_ADDR_INDEX) { sqe->addr_ext = (__u64)(uintptr_t)req->build_batch_addr.addr; + sqe->batch_row_size = req->build_batch_addr.row_size; + } break; case WD_JOIN_PROBE: usr_key = req->key_cols; @@ -262,7 +281,7 @@ static void fill_gather_col_data(struct dae_sqe *sqe, struct dae_ext_sqe *ext_sq sqe->key_col_bitmap = GENMASK(cols_num - 1, 0); sqe->has_empty = cols_data->has_empty[table_index]; - sqe->table_row_size = ctx->batch_row_size[table_index]; + sqe->batch_row_size = ctx->batch_row_size[table_index]; usr_data = gather_req->data_cols; batch_addr = gather_req->row_batchs.batch_addr; @@ -362,13 +381,7 @@ static int check_join_gather_param(struct wd_join_gather_msg *msg) msg->req.input_row_num, DAE_JOIN_MAX_ROW_NUN); return -WD_EINVAL; } - if (msg->index_type == WD_BATCH_NUMBER_INDEX) { - if (msg->req.join_req.build_batch_index >= DAE_JOIN_MAX_BATCH_NUM) { - WD_ERR("invalid: input join batch index is more than %d!\n", - DAE_JOIN_MAX_BATCH_NUM - 1); - return -WD_EINVAL; - } - } else { + if (msg->index_type == WD_BATCH_ADDR_INDEX) { if (!msg->req.join_req.build_batch_addr.addr || !msg->req.join_req.build_batch_addr.row_num || !msg->req.join_req.build_batch_addr.row_size) { -- 2.33.0

From: Weili Qian <qianweili@huawei.com> Currently, wd only supports hardware versions up to v3. On newer versions, it will report an error. Therefore, considering future compatibility issues, modify the implementation to use the v3 interface for executing business logic when the version is greater than v3. Signed-off-by: Weili Qian <qianweili@huawei.com> --- v1/drv/hisi_qm_udrv.c | 64 +++++++++++++++++++++++++------------------ v1/wd_adapter.c | 17 ++++++++++-- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/v1/drv/hisi_qm_udrv.c b/v1/drv/hisi_qm_udrv.c index 755d88e..e78ec2f 100644 --- a/v1/drv/hisi_qm_udrv.c +++ b/v1/drv/hisi_qm_udrv.c @@ -14,8 +14,8 @@ * limitations under the License. */ +#include <limits.h> #include <stdlib.h> -#include <unistd.h> #include <stdio.h> #include <sys/mman.h> #include <string.h> @@ -25,6 +25,7 @@ #include <sys/epoll.h> #include <sys/eventfd.h> #include <sys/types.h> +#include <unistd.h> #include "v1/drv/hisi_zip_udrv.h" #include "v1/drv/hisi_hpre_udrv.h" @@ -34,6 +35,13 @@ #define HISI_SGL_SGE_NUM_MAX 255 #define HISI_SGL_ALIGN_SZ 64 #define HISI_SGL_SGE_ALIGN_SZ 32 +#define HISI_VERSION_ID_SHIFT 9 + +enum { + HISI_QM_V1 = 1, + HISI_QM_V2 = 2, + HISI_QM_V3 = 3, +}; /* get hisi hardware sgl information, like sge_size, sgl_size, and its align size. * sgl numbers in a chain : 256 at most; @@ -324,7 +332,7 @@ static bool hpre_alg_info_init(struct wd_queue *q, const char *alg) return is_found; } -static bool sec_alg_info_init(struct q_info *qinfo, const char *alg) +static bool sec_alg_info_init(struct q_info *qinfo, const char *alg, unsigned long ver) { struct qm_queue_info *info = qinfo->priv; bool is_found = true; @@ -332,30 +340,30 @@ static bool sec_alg_info_init(struct q_info *qinfo, const char *alg) if (!strcmp(alg, "cipher")) { qinfo->atype = WCRYPTO_CIPHER; info->sqe_size = QM_SEC_BD_SIZE; - if (strstr(qinfo->hw_type, HISI_QM_API_VER2_BASE)) { + if (ver == HISI_QM_V2) { info->sqe_fill[WCRYPTO_CIPHER] = qm_fill_cipher_sqe; info->sqe_parse[WCRYPTO_CIPHER] = qm_parse_cipher_sqe; - } else if (strstr(qinfo->hw_type, HISI_QM_API_VER3_BASE)) { + } else if (ver >= HISI_QM_V3) { info->sqe_fill[WCRYPTO_CIPHER] = qm_fill_cipher_bd3_sqe; info->sqe_parse[WCRYPTO_CIPHER] = qm_parse_cipher_bd3_sqe; } } else if (!strcmp(alg, "digest")) { qinfo->atype = WCRYPTO_DIGEST; info->sqe_size = QM_SEC_BD_SIZE; - if (strstr(qinfo->hw_type, HISI_QM_API_VER2_BASE)) { + if (ver == HISI_QM_V2) { info->sqe_fill[WCRYPTO_DIGEST] = qm_fill_digest_sqe; info->sqe_parse[WCRYPTO_DIGEST] = qm_parse_digest_sqe; - } else if (strstr(qinfo->hw_type, HISI_QM_API_VER3_BASE)) { + } else if (ver >= HISI_QM_V3) { info->sqe_fill[WCRYPTO_DIGEST] = qm_fill_digest_bd3_sqe; info->sqe_parse[WCRYPTO_DIGEST] = qm_parse_digest_bd3_sqe; } } else if (!strcmp(alg, "aead")) { qinfo->atype = WCRYPTO_AEAD; info->sqe_size = QM_SEC_BD_SIZE; - if (strstr(qinfo->hw_type, HISI_QM_API_VER2_BASE)) { + if (ver == HISI_QM_V2) { info->sqe_fill[WCRYPTO_AEAD] = qm_fill_aead_sqe; info->sqe_parse[WCRYPTO_AEAD] = qm_parse_aead_sqe; - } else if (strstr(qinfo->hw_type, HISI_QM_API_VER3_BASE)) { + } else if (ver >= HISI_QM_V3) { info->sqe_fill[WCRYPTO_AEAD] = qm_fill_aead_bd3_sqe; info->sqe_parse[WCRYPTO_AEAD] = qm_parse_aead_bd3_sqe; } @@ -373,7 +381,7 @@ static bool sec_alg_info_init(struct q_info *qinfo, const char *alg) return is_found; } -static bool zip_alg_info_init(struct q_info *qinfo, const char *alg) +static bool zip_alg_info_init(struct q_info *qinfo, const char *alg, unsigned long ver) { struct qm_queue_info *info = qinfo->priv; bool is_found = false; @@ -384,10 +392,10 @@ static bool zip_alg_info_init(struct q_info *qinfo, const char *alg) !strcmp(alg, "lz77_zstd")) { qinfo->atype = WCRYPTO_COMP; info->sqe_size = QM_ZIP_BD_SIZE; - if (strstr(qinfo->hw_type, HISI_QM_API_VER2_BASE)) { + if (ver == HISI_QM_V2) { info->sqe_fill[WCRYPTO_COMP] = qm_fill_zip_sqe; info->sqe_parse[WCRYPTO_COMP] = qm_parse_zip_sqe; - } else if (strstr(qinfo->hw_type, HISI_QM_API_VER3_BASE)) { + } else if (ver >= HISI_QM_V3) { info->sqe_fill[WCRYPTO_COMP] = qm_fill_zip_sqe_v3; info->sqe_parse[WCRYPTO_COMP] = qm_parse_zip_sqe_v3; } @@ -408,12 +416,24 @@ static int qm_set_queue_alg_info(struct wd_queue *q) struct qm_queue_info *info = qinfo->priv; struct wcrypto_paras *priv = &q->capa.priv; int ret = -WD_EINVAL; + unsigned long ver; + + if (strlen(qinfo->hw_type) <= HISI_VERSION_ID_SHIFT) { + WD_ERR("invalid: hw_type is %s!\n", qinfo->hw_type); + return ret; + } + + ver = strtoul(qinfo->hw_type + HISI_VERSION_ID_SHIFT, NULL, 10); + if (!ver || ver == ULONG_MAX) { + WD_ERR("failed to strtoul, ver = %lu!\n", ver); + return ret; + } if (hpre_alg_info_init(q, alg)) { ret = WD_SUCCESS; - } else if (zip_alg_info_init(qinfo, alg)) { + } else if (zip_alg_info_init(qinfo, alg, ver)) { ret = WD_SUCCESS; - } else if (sec_alg_info_init(qinfo, alg)) { + } else if (sec_alg_info_init(qinfo, alg, ver)) { /* setting the type is 0 for sqc_type */ priv->direction = 0; ret = WD_SUCCESS; @@ -431,23 +451,17 @@ static int qm_set_queue_alg_info(struct wd_queue *q) return ret; } -static int qm_set_db_info(struct q_info *qinfo) +static void qm_set_db_info(struct q_info *qinfo) { struct qm_queue_info *info = qinfo->priv; - if (strstr(qinfo->hw_type, HISI_QM_API_VER2_BASE) || - strstr(qinfo->hw_type, HISI_QM_API_VER3_BASE)) { - info->db = qm_db_v2; - info->doorbell_base = info->mmio_base + QM_V2_DOORBELL_OFFSET; - } else if (strstr(qinfo->hw_type, HISI_QM_API_VER_BASE)) { + if (strstr(qinfo->hw_type, HISI_QM_API_VER_BASE)) { info->db = qm_db_v1; info->doorbell_base = info->mmio_base + QM_DOORBELL_OFFSET; } else { - WD_ERR("hw version mismatch!\n"); - return -WD_EINVAL; + info->db = qm_db_v2; + info->doorbell_base = info->mmio_base + QM_V2_DOORBELL_OFFSET; } - - return 0; } static int qm_init_queue_info(struct wd_queue *q) @@ -525,9 +539,7 @@ static int qm_set_queue_info(struct wd_queue *q) info->ds_tx_base = info->sq_base + qinfo->qfrs_offset[WD_UACCE_QFRT_DUS] - sizeof(uint32_t); info->ds_rx_base = info->ds_tx_base - sizeof(uint32_t); - ret = qm_set_db_info(qinfo); - if (ret) - goto err_with_regions; + qm_set_db_info(qinfo); info->req_cache = calloc(info->sq_depth, sizeof(void *)); if (!info->req_cache) { diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c index 0c9cd33..df5368d 100644 --- a/v1/wd_adapter.c +++ b/v1/wd_adapter.c @@ -24,6 +24,7 @@ #define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) #define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) +#define WD_MAX_NOIOMMU_ID 2 static const struct wd_drv_dio_if hw_dio_tbl[] = { { .hw_type = HISI_QM_API_VER_BASE WD_UACCE_API_VER_NOIOMMU_SUBFIX, @@ -94,6 +95,7 @@ int drv_open(struct wd_queue *q) { struct q_info *qinfo = q->qinfo; __u32 type_size = MAX_HW_TYPE; + char *type; __u32 i; /* try to find another device if the user driver is not available */ @@ -104,9 +106,18 @@ int drv_open(struct wd_queue *q) return hw_dio_tbl[qinfo->hw_type_id].open(q); } } - WD_ERR("No matched driver to use (%s)!\n", qinfo->hw_type); - errno = ENODEV; - return -ENODEV; + + /* + * If the device version is greater than the current version supported by wd, + * use the latest version of wd. + */ + type = strstr(qinfo->hw_type, WD_UACCE_API_VER_NOIOMMU_SUBFIX); + if (!type) + qinfo->hw_type_id = i - 1; + else + qinfo->hw_type_id = WD_MAX_NOIOMMU_ID; + + return hw_dio_tbl[qinfo->hw_type_id].open(q); } void drv_close(struct wd_queue *q) -- 2.33.0
participants (1)
-
ZongYu Wu