]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: hisilicon/qm - enhance the configuration of req_type in queue attributes
authorChenghai Huang <huangchenghai2@huawei.com>
Thu, 18 Dec 2025 13:44:45 +0000 (21:44 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 16 Jan 2026 06:02:06 +0000 (14:02 +0800)
Originally, when a queue was requested, it could only be configured
with the default algorithm type of 0. Now, when multiple tfms use
the same queue, the queue must be selected based on its attributes
to meet the requirements of tfm tasks. So the algorithm type
attribute of queue need to be distinguished. Just like a queue used
for compression in ZIP cannot be used for decompression tasks.

Fixes: 3f1ec97aacf1 ("crypto: hisilicon/qm - Put device finding logic into QM")
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: Weili Qian <qianweili@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/hisilicon/hpre/hpre_main.c
drivers/crypto/hisilicon/qm.c
drivers/crypto/hisilicon/sec2/sec_crypto.c
drivers/crypto/hisilicon/sec2/sec_main.c
drivers/crypto/hisilicon/zip/zip.h
drivers/crypto/hisilicon/zip/zip_crypto.c
drivers/crypto/hisilicon/zip/zip_main.c
include/linux/hisi_acc_qm.h

index b94fecd765eebdfabfd1d2c3363c7c9ac613ef5b..884d5d0afaf41f326e8fcd2868efffda49d164cb 100644 (file)
@@ -465,7 +465,7 @@ struct hisi_qp *hpre_create_qp(u8 type)
         * type: 0 - RSA/DH. algorithm supported in V2,
         *       1 - ECC algorithm in V3.
         */
-       ret = hisi_qm_alloc_qps_node(&hpre_devices, 1, type, node, &qp);
+       ret = hisi_qm_alloc_qps_node(&hpre_devices, 1, &type, node, &qp);
        if (!ret)
                return qp;
 
index 71071ac559d4bbf0d00f304550efc2dfdb7d15f2..5c80ca04a8d42dd6d50132bbfb7c3be77c462a47 100644 (file)
@@ -3620,7 +3620,7 @@ static int hisi_qm_sort_devices(int node, struct list_head *head,
  * not meet the requirements will return error.
  */
 int hisi_qm_alloc_qps_node(struct hisi_qm_list *qm_list, int qp_num,
-                          u8 alg_type, int node, struct hisi_qp **qps)
+                          u8 *alg_type, int node, struct hisi_qp **qps)
 {
        struct hisi_qm_resource *tmp;
        int ret = -ENODEV;
@@ -3638,7 +3638,7 @@ int hisi_qm_alloc_qps_node(struct hisi_qm_list *qm_list, int qp_num,
 
        list_for_each_entry(tmp, &head, list) {
                for (i = 0; i < qp_num; i++) {
-                       qps[i] = hisi_qm_create_qp(tmp->qm, alg_type);
+                       qps[i] = hisi_qm_create_qp(tmp->qm, alg_type[i]);
                        if (IS_ERR(qps[i])) {
                                hisi_qm_free_qps(qps, i);
                                break;
@@ -3653,8 +3653,8 @@ int hisi_qm_alloc_qps_node(struct hisi_qm_list *qm_list, int qp_num,
 
        mutex_unlock(&qm_list->lock);
        if (ret)
-               pr_info("Failed to create qps, node[%d], alg[%u], qp[%d]!\n",
-                       node, alg_type, qp_num);
+               pr_info("Failed to create qps, node[%d], qp[%d]!\n",
+                       node, qp_num);
 
 err:
        free_list(&head);
index 4e41235116e15dc7b0ff6b5c46609c2181857501..364bd69c6088334ce6bd74272b2fd88108159387 100644 (file)
@@ -626,7 +626,6 @@ static int sec_create_qp_ctx(struct sec_ctx *ctx, int qp_ctx_id)
 
        qp_ctx = &ctx->qp_ctx[qp_ctx_id];
        qp = ctx->qps[qp_ctx_id];
-       qp->req_type = 0;
        qp->qp_ctx = qp_ctx;
        qp_ctx->qp = qp;
        qp_ctx->ctx = ctx;
index 5eb2d68207426e42552dc658b112b7e005d02e39..7dd125f5f511fa8f930506fdedc9860456a19ea1 100644 (file)
@@ -417,18 +417,29 @@ struct hisi_qp **sec_create_qps(void)
        int node = cpu_to_node(raw_smp_processor_id());
        u32 ctx_num = ctx_q_num;
        struct hisi_qp **qps;
+       u8 *type;
        int ret;
 
        qps = kcalloc(ctx_num, sizeof(struct hisi_qp *), GFP_KERNEL);
        if (!qps)
                return NULL;
 
-       ret = hisi_qm_alloc_qps_node(&sec_devices, ctx_num, 0, node, qps);
-       if (!ret)
-               return qps;
+       /* The type of SEC is all 0, so just allocated by kcalloc */
+       type = kcalloc(ctx_num, sizeof(u8), GFP_KERNEL);
+       if (!type) {
+               kfree(qps);
+               return NULL;
+       }
 
-       kfree(qps);
-       return NULL;
+       ret = hisi_qm_alloc_qps_node(&sec_devices, ctx_num, type, node, qps);
+       if (ret) {
+               kfree(type);
+               kfree(qps);
+               return NULL;
+       }
+
+       kfree(type);
+       return qps;
 }
 
 u64 sec_get_alg_bitmap(struct hisi_qm *qm, u32 high, u32 low)
index 9fb2a9c01132b48a1fa7cea14b99c80454e69491..b83f228281ab1eb8bdd5c6c9281db1bce28536f7 100644 (file)
@@ -99,7 +99,7 @@ enum zip_cap_table_type {
        ZIP_CORE5_BITMAP,
 };
 
-int zip_create_qps(struct hisi_qp **qps, int qp_num, int node);
+int zip_create_qps(struct hisi_qp **qps, int qp_num, int node, u8 *alg_type);
 int hisi_zip_register_to_crypto(struct hisi_qm *qm);
 void hisi_zip_unregister_from_crypto(struct hisi_qm *qm);
 bool hisi_zip_alg_support(struct hisi_qm *qm, u32 alg);
index b4a656e0177d2dc7857cf5d1259581a6651b6571..8250a33ba58622ad6ca5205adbf28a0bc64fbc70 100644 (file)
@@ -66,6 +66,7 @@ struct hisi_zip_qp_ctx {
        struct hisi_acc_sgl_pool *sgl_pool;
        struct hisi_zip *zip_dev;
        struct hisi_zip_ctx *ctx;
+       u8 req_type;
 };
 
 struct hisi_zip_sqe_ops {
@@ -245,7 +246,7 @@ static int hisi_zip_do_work(struct hisi_zip_qp_ctx *qp_ctx,
                goto err_unmap_input;
        }
 
-       hisi_zip_fill_sqe(qp_ctx->ctx, &zip_sqe, qp->req_type, req);
+       hisi_zip_fill_sqe(qp_ctx->ctx, &zip_sqe, qp_ctx->req_type, req);
 
        /* send command to start a task */
        atomic64_inc(&dfx->send_cnt);
@@ -360,7 +361,6 @@ static int hisi_zip_start_qp(struct hisi_qp *qp, struct hisi_zip_qp_ctx *qp_ctx,
        struct device *dev = &qp->qm->pdev->dev;
        int ret;
 
-       qp->req_type = req_type;
        qp->alg_type = alg_type;
        qp->qp_ctx = qp_ctx;
 
@@ -397,10 +397,15 @@ static int hisi_zip_ctx_init(struct hisi_zip_ctx *hisi_zip_ctx, u8 req_type, int
 {
        struct hisi_qp *qps[HZIP_CTX_Q_NUM] = { NULL };
        struct hisi_zip_qp_ctx *qp_ctx;
+       u8 alg_type[HZIP_CTX_Q_NUM];
        struct hisi_zip *hisi_zip;
        int ret, i, j;
 
-       ret = zip_create_qps(qps, HZIP_CTX_Q_NUM, node);
+       /* alg_type = 0 for compress, 1 for decompress in hw sqe */
+       for (i = 0; i < HZIP_CTX_Q_NUM; i++)
+               alg_type[i] = i;
+
+       ret = zip_create_qps(qps, HZIP_CTX_Q_NUM, node, alg_type);
        if (ret) {
                pr_err("failed to create zip qps (%d)!\n", ret);
                return -ENODEV;
@@ -409,7 +414,6 @@ static int hisi_zip_ctx_init(struct hisi_zip_ctx *hisi_zip_ctx, u8 req_type, int
        hisi_zip = container_of(qps[0]->qm, struct hisi_zip, qm);
 
        for (i = 0; i < HZIP_CTX_Q_NUM; i++) {
-               /* alg_type = 0 for compress, 1 for decompress in hw sqe */
                qp_ctx = &hisi_zip_ctx->qp_ctx[i];
                qp_ctx->ctx = hisi_zip_ctx;
                ret = hisi_zip_start_qp(qps[i], qp_ctx, i, req_type);
@@ -422,6 +426,7 @@ static int hisi_zip_ctx_init(struct hisi_zip_ctx *hisi_zip_ctx, u8 req_type, int
                }
 
                qp_ctx->zip_dev = hisi_zip;
+               qp_ctx->req_type = req_type;
        }
 
        hisi_zip_ctx->ops = &hisi_zip_ops;
index 4fcbe6bada0663cdb1594933de85dfd85000b04d..85b26ef1754855c2f5f3561d7b54c8f552e90d90 100644 (file)
@@ -446,12 +446,12 @@ static const struct pci_device_id hisi_zip_dev_ids[] = {
 };
 MODULE_DEVICE_TABLE(pci, hisi_zip_dev_ids);
 
-int zip_create_qps(struct hisi_qp **qps, int qp_num, int node)
+int zip_create_qps(struct hisi_qp **qps, int qp_num, int node, u8 *alg_type)
 {
        if (node == NUMA_NO_NODE)
                node = cpu_to_node(raw_smp_processor_id());
 
-       return hisi_qm_alloc_qps_node(&zip_devices, qp_num, 0, node, qps);
+       return hisi_qm_alloc_qps_node(&zip_devices, qp_num, alg_type, node, qps);
 }
 
 bool hisi_zip_alg_support(struct hisi_qm *qm, u32 alg)
index 9485896d5dc08d3b567b766d2d60ab60847be942..dd4323633d81e30ad528f0577871364b985ee86f 100644 (file)
@@ -457,7 +457,6 @@ struct hisi_qp {
        u16 sq_depth;
        u16 cq_depth;
        u8 alg_type;
-       u8 req_type;
 
        struct qm_dma qdma;
        void *sqe;
@@ -583,7 +582,7 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
 void hisi_acc_free_sgl_pool(struct device *dev,
                            struct hisi_acc_sgl_pool *pool);
 int hisi_qm_alloc_qps_node(struct hisi_qm_list *qm_list, int qp_num,
-                          u8 alg_type, int node, struct hisi_qp **qps);
+                          u8 *alg_type, int node, struct hisi_qp **qps);
 void hisi_qm_free_qps(struct hisi_qp **qps, int qp_num);
 void hisi_qm_dev_shutdown(struct pci_dev *pdev);
 void hisi_qm_wait_task_finish(struct hisi_qm *qm, struct hisi_qm_list *qm_list);