Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1256732pxb; Thu, 4 Mar 2021 07:11:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzV2ruoR2suRW1vfhdsUAh1CxllWWI9Ap2N9Z+Zg5EFH3uhH6FxBxMTmsIxwaQ2A4W0h2A+ X-Received: by 2002:a17:906:fcc7:: with SMTP id qx7mr4722535ejb.486.1614870701532; Thu, 04 Mar 2021 07:11:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614870701; cv=none; d=google.com; s=arc-20160816; b=lCGuNZxRDytEiNqnYpGRWakq6APN80KpZCSETCGykHlpY59RAuGDdtlGrwHFBCCK3c 5SlDfp1aT7QSz1MkfdxXKRbKHwnTd1bbwOrFQiVrlED8dyOlJd6Ncz3cZwoOD1tjlvrG 0xvynKHCz1sMIL+kT56+nii6G4iASY600GtPnQXPdBWjswJO3rATNsIpIEn+jLYP2Fzb 7v5XGfYH0xowfPesDuekrJIbEss0GvHkxUfylEgLMtTHEbJkFDCw2LdcirY5WTbkMCWn GX38izcG4n9/8FVPORRthT8RMKPwEj3K+0FqYX0nkBfu/r5cECpz7iNd6ic6r7H+FzVt Ebng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=1u83lAX0CMh7CPv2Qo1pbq8Zc94IB/TVHI8xSlGhIB4=; b=ZUV4R3zfVSMIus3Qgip5932S3dRJ2O7VpIg4gsZ8+hGFDGKhWeN9WQpAqCLL4HaQq6 gf9VPn/Su1jeO+UERghJvA+9VSKVwqoRnBFiYXzkg/I0MTTZHvbDAoTJJMKlxN+mZbz0 wRtTText+L4zsDlT0aQSagdZHsFZce8WcDA7LAeGM7FS+TTQxXRcspW2zrqLlnf8/bFP Ov9By4iw+j3vnqxH6CqajEETdXfksElqXXZ2A0cMsQxtI8O5LwTzKgbMzY1769l7fOOh YsmSyrxSyDYf30FjcqHTO2qkac6uBh9BKHU4+E5Vmxuq4w/bc+Hd5paHRcgZvb19j++e AlIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y22si3098497edc.181.2021.03.04.07.11.16; Thu, 04 Mar 2021 07:11:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235379AbhCDGja (ORCPT + 99 others); Thu, 4 Mar 2021 01:39:30 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:13055 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235356AbhCDGjD (ORCPT ); Thu, 4 Mar 2021 01:39:03 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Drh2y2wXGzMhnw; Thu, 4 Mar 2021 14:36:10 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Thu, 4 Mar 2021 14:38:13 +0800 From: Meng Yu To: , , , , , CC: , , , , Subject: [PATCH v10 2/7] crypto: hisilicon/hpre - add algorithm type Date: Thu, 4 Mar 2021 14:35:45 +0800 Message-ID: <1614839750-29670-3-git-send-email-yumeng18@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1614839750-29670-1-git-send-email-yumeng18@huawei.com> References: <1614839750-29670-1-git-send-email-yumeng18@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Algorithm type is brought in to get hardware HPRE queue to support different algorithms. Signed-off-by: Meng Yu Reviewed-by: Zaibo Xu --- drivers/crypto/hisilicon/hpre/hpre.h | 10 +++++++++- drivers/crypto/hisilicon/hpre/hpre_crypto.c | 12 ++++++------ drivers/crypto/hisilicon/hpre/hpre_main.c | 11 +++++++++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/hisilicon/hpre/hpre.h b/drivers/crypto/hisilicon/hpre/hpre.h index cc50f23..02193e1 100644 --- a/drivers/crypto/hisilicon/hpre/hpre.h +++ b/drivers/crypto/hisilicon/hpre/hpre.h @@ -10,6 +10,14 @@ #define HPRE_PF_DEF_Q_NUM 64 #define HPRE_PF_DEF_Q_BASE 0 +/* + * type used in qm sqc DW6. + * 0 - Algorithm which has been supported in V2, like RSA, DH and so on; + * 1 - ECC algorithm in V3. + */ +#define HPRE_V2_ALG_TYPE 0 +#define HPRE_V3_ECC_ALG_TYPE 1 + enum { HPRE_CLUSTER0, HPRE_CLUSTER1, @@ -92,7 +100,7 @@ struct hpre_sqe { __le32 rsvd1[_HPRE_SQE_ALIGN_EXT]; }; -struct hisi_qp *hpre_create_qp(void); +struct hisi_qp *hpre_create_qp(u8 type); int hpre_algs_register(struct hisi_qm *qm); void hpre_algs_unregister(struct hisi_qm *qm); diff --git a/drivers/crypto/hisilicon/hpre/hpre_crypto.c b/drivers/crypto/hisilicon/hpre/hpre_crypto.c index d89b2f5..712bea9 100644 --- a/drivers/crypto/hisilicon/hpre/hpre_crypto.c +++ b/drivers/crypto/hisilicon/hpre/hpre_crypto.c @@ -152,12 +152,12 @@ static void hpre_rm_req_from_ctx(struct hpre_asym_request *hpre_req) } } -static struct hisi_qp *hpre_get_qp_and_start(void) +static struct hisi_qp *hpre_get_qp_and_start(u8 type) { struct hisi_qp *qp; int ret; - qp = hpre_create_qp(); + qp = hpre_create_qp(type); if (!qp) { pr_err("Can not create hpre qp!\n"); return ERR_PTR(-ENODEV); @@ -422,11 +422,11 @@ static void hpre_alg_cb(struct hisi_qp *qp, void *resp) req->cb(ctx, resp); } -static int hpre_ctx_init(struct hpre_ctx *ctx) +static int hpre_ctx_init(struct hpre_ctx *ctx, u8 type) { struct hisi_qp *qp; - qp = hpre_get_qp_and_start(); + qp = hpre_get_qp_and_start(type); if (IS_ERR(qp)) return PTR_ERR(qp); @@ -674,7 +674,7 @@ static int hpre_dh_init_tfm(struct crypto_kpp *tfm) { struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); - return hpre_ctx_init(ctx); + return hpre_ctx_init(ctx, HPRE_V2_ALG_TYPE); } static void hpre_dh_exit_tfm(struct crypto_kpp *tfm) @@ -1100,7 +1100,7 @@ static int hpre_rsa_init_tfm(struct crypto_akcipher *tfm) return PTR_ERR(ctx->rsa.soft_tfm); } - ret = hpre_ctx_init(ctx); + ret = hpre_ctx_init(ctx, HPRE_V2_ALG_TYPE); if (ret) crypto_free_akcipher(ctx->rsa.soft_tfm); diff --git a/drivers/crypto/hisilicon/hpre/hpre_main.c b/drivers/crypto/hisilicon/hpre/hpre_main.c index e7a2c70..76f0a87 100644 --- a/drivers/crypto/hisilicon/hpre/hpre_main.c +++ b/drivers/crypto/hisilicon/hpre/hpre_main.c @@ -226,13 +226,20 @@ static u32 vfs_num; module_param_cb(vfs_num, &vfs_num_ops, &vfs_num, 0444); MODULE_PARM_DESC(vfs_num, "Number of VFs to enable(1-63), 0(default)"); -struct hisi_qp *hpre_create_qp(void) +struct hisi_qp *hpre_create_qp(u8 type) { int node = cpu_to_node(smp_processor_id()); struct hisi_qp *qp = NULL; int ret; - ret = hisi_qm_alloc_qps_node(&hpre_devices, 1, 0, node, &qp); + if (type != HPRE_V2_ALG_TYPE && type != HPRE_V3_ECC_ALG_TYPE) + return NULL; + + /* + * 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); if (!ret) return qp; -- 2.8.1