Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1440839ybl; Fri, 10 Jan 2020 18:49:18 -0800 (PST) X-Google-Smtp-Source: APXvYqzmRkayJdsZOJDny4teKH29xvZGG1FszpBcQWjePR+Jk6/ZrIKUWL+/DYi7nc+hpoyrVDnL X-Received: by 2002:a9d:7e8c:: with SMTP id m12mr5460875otp.346.1578710958206; Fri, 10 Jan 2020 18:49:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578710958; cv=none; d=google.com; s=arc-20160816; b=xJ5cCFWYq+vSiEEWBYjV8pgryrxUShEpaRNKP8Td4FyLWZwjbi0O6Z5/wiWdj3oeJk v17GPP8Gb5U4vzVix1f0/W/Tr0dWdv+KyFwpx9oPN5zFFHYm+DgN8r4goxypC4X/7oVZ fgWjGLMTR2X8795CAWpVbT40jj34KQmY7tV/++wSEwPJ8cFtqQsFAj3fBtjs7qtfL5Wn 50G/9iLKohKqy+Ukemye2fPL8CzQ3oEY0rh7gCpO2qrxNm7sOdAKeLVj6DDAfVnpTzjt KtJHfr0UqOYWlaXSG6MWu5m6uyFaHZR2FlJkJXfOCXq81JTPLEb1TawcEywR1l7xvDBd e6Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=1aBp91nKQ2bXGy+dD746c7Tpbvjnyhz2SdAhJqt6qcI=; b=W2dBvLZKjsDcxTgfJErf2jTdHyHZKiETdRLh5fxfHN4GblapcP+WGzd5bnp2YhJd/V 11PPEjCexChAdl+fqyt7iQPMy/5r10ZAYaa5i9DkSK8R2IKWVjfr5+7rMau3dDW0T20d UJtXQLXyXNEPdAUKkozN236bAWBR2eUnWs6QMDv4l4PAfORZkFdT30VVMxzkheGLpK10 /RIcISot3hS/VsL6wjDP12LON4gNDxhcxwvcnDx+2dvn6eHOl8MrBx+M5zxLhtiZRpMH p1RozBjSCrrS+n3CubMv67tulYr1RPrxSqawMOaomAD4qZlJUKjPu14Pnjt4kvJPzS0V usyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j19si2226110oij.51.2020.01.10.18.49.07; Fri, 10 Jan 2020 18:49:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728199AbgAKCpy (ORCPT + 99 others); Fri, 10 Jan 2020 21:45:54 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:45452 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728203AbgAKCpx (ORCPT ); Fri, 10 Jan 2020 21:45:53 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 5AD7212F72B471935EEA; Sat, 11 Jan 2020 10:45:49 +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.439.0; Sat, 11 Jan 2020 10:45:43 +0800 From: Zaibo Xu To: , CC: , , , , , , , , , , Subject: [PATCH v2 8/9] crypto: hisilicon - redefine skcipher initiation Date: Sat, 11 Jan 2020 10:41:55 +0800 Message-ID: <1578710516-40535-9-git-send-email-xuzaibo@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1578710516-40535-1-git-send-email-xuzaibo@huawei.com> References: <1578710516-40535-1-git-send-email-xuzaibo@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 1.Define base initiation of QP for context which can be reused. 2.Define cipher initiation for other algorithms. Signed-off-by: Zaibo Xu --- drivers/crypto/hisilicon/sec2/sec_crypto.c | 96 +++++++++++++++++++----------- 1 file changed, 61 insertions(+), 35 deletions(-) diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c index 521bab8..f919dea 100644 --- a/drivers/crypto/hisilicon/sec2/sec_crypto.c +++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c @@ -273,25 +273,17 @@ static void sec_release_qp_ctx(struct sec_ctx *ctx, hisi_qm_release_qp(qp_ctx->qp); } -static int sec_skcipher_init(struct crypto_skcipher *tfm) +static int sec_ctx_base_init(struct sec_ctx *ctx) { - struct sec_ctx *ctx = crypto_skcipher_ctx(tfm); - struct sec_cipher_ctx *c_ctx; struct sec_dev *sec; - struct device *dev; - struct hisi_qm *qm; int i, ret; - crypto_skcipher_set_reqsize(tfm, sizeof(struct sec_req)); - sec = sec_find_device(cpu_to_node(smp_processor_id())); if (!sec) { pr_err("Can not find proper Hisilicon SEC device!\n"); return -ENODEV; } ctx->sec = sec; - qm = &sec->qm; - dev = &qm->pdev->dev; ctx->hlf_q_num = sec->ctx_q_num >> 1; /* Half of queue depth is taken as fake requests limit in the queue. */ @@ -302,27 +294,12 @@ static int sec_skcipher_init(struct crypto_skcipher *tfm) return -ENOMEM; for (i = 0; i < sec->ctx_q_num; i++) { - ret = sec_create_qp_ctx(qm, ctx, i, 0); + ret = sec_create_qp_ctx(&sec->qm, ctx, i, 0); if (ret) goto err_sec_release_qp_ctx; } - c_ctx = &ctx->c_ctx; - c_ctx->ivsize = crypto_skcipher_ivsize(tfm); - if (c_ctx->ivsize > SEC_IV_SIZE) { - dev_err(dev, "get error iv size!\n"); - ret = -EINVAL; - goto err_sec_release_qp_ctx; - } - c_ctx->c_key = dma_alloc_coherent(dev, SEC_MAX_KEY_SIZE, - &c_ctx->c_key_dma, GFP_KERNEL); - if (!c_ctx->c_key) { - ret = -ENOMEM; - goto err_sec_release_qp_ctx; - } - return 0; - err_sec_release_qp_ctx: for (i = i - 1; i >= 0; i--) sec_release_qp_ctx(ctx, &ctx->qp_ctx[i]); @@ -331,17 +308,9 @@ static int sec_skcipher_init(struct crypto_skcipher *tfm) return ret; } -static void sec_skcipher_uninit(struct crypto_skcipher *tfm) +static void sec_ctx_base_uninit(struct sec_ctx *ctx) { - struct sec_ctx *ctx = crypto_skcipher_ctx(tfm); - struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; - int i = 0; - - if (c_ctx->c_key) { - dma_free_coherent(SEC_CTX_DEV(ctx), SEC_MAX_KEY_SIZE, - c_ctx->c_key, c_ctx->c_key_dma); - c_ctx->c_key = NULL; - } + int i; for (i = 0; i < ctx->sec->ctx_q_num; i++) sec_release_qp_ctx(ctx, &ctx->qp_ctx[i]); @@ -349,6 +318,63 @@ static void sec_skcipher_uninit(struct crypto_skcipher *tfm) kfree(ctx->qp_ctx); } +static int sec_cipher_init(struct sec_ctx *ctx) +{ + struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; + + c_ctx->c_key = dma_alloc_coherent(SEC_CTX_DEV(ctx), SEC_MAX_KEY_SIZE, + &c_ctx->c_key_dma, GFP_KERNEL); + if (!c_ctx->c_key) + return -ENOMEM; + + return 0; +} + +static void sec_cipher_uninit(struct sec_ctx *ctx) +{ + struct sec_cipher_ctx *c_ctx = &ctx->c_ctx; + + memzero_explicit(c_ctx->c_key, SEC_MAX_KEY_SIZE); + dma_free_coherent(SEC_CTX_DEV(ctx), SEC_MAX_KEY_SIZE, + c_ctx->c_key, c_ctx->c_key_dma); +} + +static int sec_skcipher_init(struct crypto_skcipher *tfm) +{ + struct sec_ctx *ctx = crypto_skcipher_ctx(tfm); + int ret; + + ctx = crypto_skcipher_ctx(tfm); + crypto_skcipher_set_reqsize(tfm, sizeof(struct sec_req)); + ctx->c_ctx.ivsize = crypto_skcipher_ivsize(tfm); + if (ctx->c_ctx.ivsize > SEC_IV_SIZE) { + dev_err(SEC_CTX_DEV(ctx), "get error skcipher iv size!\n"); + return -EINVAL; + } + + ret = sec_ctx_base_init(ctx); + if (ret) + return ret; + + ret = sec_cipher_init(ctx); + if (ret) + goto err_cipher_init; + + return 0; +err_cipher_init: + sec_ctx_base_uninit(ctx); + + return ret; +} + +static void sec_skcipher_uninit(struct crypto_skcipher *tfm) +{ + struct sec_ctx *ctx = crypto_skcipher_ctx(tfm); + + sec_cipher_uninit(ctx); + sec_ctx_base_uninit(ctx); +} + static int sec_skcipher_3des_setkey(struct sec_cipher_ctx *c_ctx, const u32 keylen, const enum sec_cmode c_mode) -- 2.8.1