Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp1072066pxt; Fri, 6 Aug 2021 23:35:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpbmh3grzf/bSB9e3+1sAwXXpL2KYj4cOHkggqC1ypBw8veDKsaC96qwFHpTJWpjNGLfEP X-Received: by 2002:a92:6e12:: with SMTP id j18mr341918ilc.243.1628318109026; Fri, 06 Aug 2021 23:35:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628318109; cv=none; d=google.com; s=arc-20160816; b=Daj/Nzww/yJqZ1DFb0bwew0CwjO0bDNW75xBivzmJwjgOX4CgZoTarRkXxQdqgyHej WewZPG5+Br/0snT9SauvMUrD2qqV20SHMj+u/eRDpfxp31lm63oq478D8b0jG0Ivbw/4 o9+OHIzpMC8I9MrVsRpFkOZCqaA/wo0BV7Bk/Mmw5zJ8M3r8BzQHpfU1OlIxrwn8JHaO cwg1i25v+WqRl8RBk3qkFc3TJ7Cnazb8r4CH8PT3rPLdY0CYFA9Xo++ZDv8kAncGqSy7 CtnM4RR1idTuGHXCDnH8GNBhms+NgA6N7wHX8hVPDRi28/++3qRSDzljdoK4qfxXAd4i rkvA== 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=2h1YNM6MpoP7ndfXG9XjjWZ8Jq9PuGD5jRFLYAo97KQ=; b=wyPeLSlHj52dngZCvcP6582nAgI2BPIm7YBEf9WzKgH3AoWtA9JEYboWN0UXeOYm0y zx3+jKU4x+LazhOo1/vo482G+M0QbMlAaCdko9K9nkeKXW7oW09sO5gq09LD8dOBGstU u4kSzq52SpSh0lEvBuDsDcXPK9JX/FDvKc3YK0IIEPu8PuLyrxDpjh+6RyiRUb+oqNrQ iDyAlxoHxC2GA6k8QIr/78rIGiao4ucUffb3GMU0L5+0b/wsfMeendnZWA3dBhPTiyZw OJAeZAcExBEGpr6QPBq/TEA+3Ll46uDPplY+cx5Yv2m9i9hGPdfXmnnqCUch2UE3uzpP oXaA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m43si587193jav.124.2021.08.06.23.34.57; Fri, 06 Aug 2021 23:35:09 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231384AbhHGGdP (ORCPT + 99 others); Sat, 7 Aug 2021 02:33:15 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:13399 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231335AbhHGGdO (ORCPT ); Sat, 7 Aug 2021 02:33:14 -0400 Received: from dggeme768-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GhXW35Ys5zclFR; Sat, 7 Aug 2021 14:29:19 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggeme768-chm.china.huawei.com (10.3.19.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sat, 7 Aug 2021 14:32:55 +0800 From: Weili Qian To: , CC: , , , , Weili Qian Subject: [PATCH 2/3] crypto: hisilicon - enable sec device clock gating Date: Sat, 7 Aug 2021 14:29:10 +0800 Message-ID: <1628317751-3396-3-git-send-email-qianweili@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1628317751-3396-1-git-send-email-qianweili@huawei.com> References: <1628317751-3396-1-git-send-email-qianweili@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggeme768-chm.china.huawei.com (10.3.19.114) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Kunpeng930 sec device supports dynamic clock gating. When doing tasks, the algorithm core is opened, and when idle, the algorithm core is closed. This patch enables sec dynamic clock gating by writing hardware registers. Signed-off-by: Weili Qian --- drivers/crypto/hisilicon/sec2/sec_main.c | 46 ++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/hisilicon/sec2/sec_main.c b/drivers/crypto/hisilicon/sec2/sec_main.c index 490db7b..db4dbcf 100644 --- a/drivers/crypto/hisilicon/sec2/sec_main.c +++ b/drivers/crypto/hisilicon/sec2/sec_main.c @@ -57,10 +57,16 @@ #define SEC_MEM_START_INIT_REG 0x301100 #define SEC_MEM_INIT_DONE_REG 0x301104 +/* clock gating */ #define SEC_CONTROL_REG 0x301200 -#define SEC_TRNG_EN_SHIFT 8 +#define SEC_DYNAMIC_GATE_REG 0x30121c +#define SEC_CORE_AUTO_GATE 0x30212c +#define SEC_DYNAMIC_GATE_EN 0x7bff +#define SEC_CORE_AUTO_GATE_EN GENMASK(3, 0) #define SEC_CLK_GATE_ENABLE BIT(3) #define SEC_CLK_GATE_DISABLE (~BIT(3)) + +#define SEC_TRNG_EN_SHIFT 8 #define SEC_AXI_SHUTDOWN_ENABLE BIT(12) #define SEC_AXI_SHUTDOWN_DISABLE 0xFFFFEFFF @@ -378,15 +384,43 @@ static void sec_close_sva_prefetch(struct hisi_qm *qm) pci_err(qm->pdev, "failed to close sva prefetch\n"); } +static void sec_enable_clock_gate(struct hisi_qm *qm) +{ + u32 val; + + if (qm->ver < QM_HW_V3) + return; + + val = readl_relaxed(qm->io_base + SEC_CONTROL_REG); + val |= SEC_CLK_GATE_ENABLE; + writel_relaxed(val, qm->io_base + SEC_CONTROL_REG); + + val = readl(qm->io_base + SEC_DYNAMIC_GATE_REG); + val |= SEC_DYNAMIC_GATE_EN; + writel(val, qm->io_base + SEC_DYNAMIC_GATE_REG); + + val = readl(qm->io_base + SEC_CORE_AUTO_GATE); + val |= SEC_CORE_AUTO_GATE_EN; + writel(val, qm->io_base + SEC_CORE_AUTO_GATE); +} + +static void sec_disable_clock_gate(struct hisi_qm *qm) +{ + u32 val; + + /* Kunpeng920 needs to close clock gating */ + val = readl_relaxed(qm->io_base + SEC_CONTROL_REG); + val &= SEC_CLK_GATE_DISABLE; + writel_relaxed(val, qm->io_base + SEC_CONTROL_REG); +} + static int sec_engine_init(struct hisi_qm *qm) { int ret; u32 reg; - /* disable clock gate control */ - reg = readl_relaxed(qm->io_base + SEC_CONTROL_REG); - reg &= SEC_CLK_GATE_DISABLE; - writel_relaxed(reg, qm->io_base + SEC_CONTROL_REG); + /* disable clock gate control before mem init */ + sec_disable_clock_gate(qm); writel_relaxed(0x1, qm->io_base + SEC_MEM_START_INIT_REG); @@ -433,6 +467,8 @@ static int sec_engine_init(struct hisi_qm *qm) reg |= sec_get_endian(qm); writel_relaxed(reg, qm->io_base + SEC_CONTROL_REG); + sec_enable_clock_gate(qm); + return 0; } -- 2.8.1