Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp1071657pxt; Fri, 6 Aug 2021 23:34:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMbY+dzvzLHPhyll+MVLKbet3RcWdHFoBLf55icybb4E8TXacdugsnY+ii4/AzHkwiDGCm X-Received: by 2002:a92:b112:: with SMTP id t18mr127882ilh.36.1628318053866; Fri, 06 Aug 2021 23:34:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628318053; cv=none; d=google.com; s=arc-20160816; b=i81w+bCW7ioAcHe9ViFBfJiHisbkh9NIPSPe4/amVubFgW7Sehk0Tdko9BswjrJZ9p apYU+VvzzaUYqbtZeCj/WXqhYzHaEYAoc1geovaPs1s40dglzUQHJGS2gOtvzF2bLGCD nKSrRo/IKJyncybvMrexQklepHDlzJhigT7Y9Znfox0T0fIgU6J5vZwO27HFYFdK9dkh VG/V/iRxzFGOgn0EnNaQ60/XnoIcUe3oSWOhP1K38ViZBuqSlk9aBh1bc9i9rR6NHLVT bwCbmttetxgImNvXxqXhppxaU0aq5VpwDEruZ9/PA5pd9gbFKKCKVV0ozns8nTzMAxs2 BaTA== 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=IbwmjhJXIW4VhCXT18/+9MsMLwt0uGIRjZdcJVjkYnQ=; b=wpsMl656g2O4cGBc7GWfH40Enh7ucQT30W4TqC5N3yNznODDKLTTQfXwks1VEbvRRo rYPB0en4vtumr1UkDwAeypZHnTKvyOLp2fMxsAlUiF9tNziy78CFG5ZqFPvAXQQEfsMo EJ2COTU60QHb+IvtbHHHE5PVb6LTJ6q5zTOEfAQsRNUzGf0/Agd2erLMuTVZ8tUMKB+9 pU4SXKThMHMWYZAvIc/ZgzvzMQAUWi2bpNOSROWlayAqaLql0zFE358eQszbrvviLHGF a4MyrQfYSUQRcJPy7ktXlt7mGUaY5ZqfniC9gAbsZrV20hjNOBqUVcBcyeWqNc6hASVI V+PQ== 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 a7si1323974ilr.34.2021.08.06.23.34.02; Fri, 06 Aug 2021 23:34:13 -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 S231388AbhHGGdR (ORCPT + 99 others); Sat, 7 Aug 2021 02:33:17 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:7804 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230297AbhHGGdP (ORCPT ); Sat, 7 Aug 2021 02:33:15 -0400 Received: from dggeme768-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GhXb304QZzYlgB; Sat, 7 Aug 2021 14:32:47 +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:56 +0800 From: Weili Qian To: , CC: , , , , Weili Qian Subject: [PATCH 3/3] crypto: hisilicon - enable hpre device clock gating Date: Sat, 7 Aug 2021 14:29:11 +0800 Message-ID: <1628317751-3396-4-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 hpre device supports dynamic clock gating. When doing tasks, the algorithm core is opened, and when idle, the algorithm core is closed. This patch enables hpre dynamic clock gating by writing hardware registers. Signed-off-by: Weili Qian --- drivers/crypto/hisilicon/hpre/hpre_main.c | 63 +++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/drivers/crypto/hisilicon/hpre/hpre_main.c b/drivers/crypto/hisilicon/hpre/hpre_main.c index 8b0640f..6a5de30 100644 --- a/drivers/crypto/hisilicon/hpre/hpre_main.c +++ b/drivers/crypto/hisilicon/hpre/hpre_main.c @@ -81,6 +81,16 @@ #define HPRE_PREFETCH_DISABLE BIT(30) #define HPRE_SVA_DISABLE_READY (BIT(4) | BIT(8)) +/* clock gate */ +#define HPRE_CLKGATE_CTL 0x301a10 +#define HPRE_PEH_CFG_AUTO_GATE 0x301a2c +#define HPRE_CLUSTER_DYN_CTL 0x302010 +#define HPRE_CORE_SHB_CFG 0x302088 +#define HPRE_CLKGATE_CTL_EN BIT(0) +#define HPRE_PEH_CFG_AUTO_GATE_EN BIT(0) +#define HPRE_CLUSTER_DYN_CTL_EN BIT(0) +#define HPRE_CORE_GATE_EN (BIT(30) | BIT(31)) + #define HPRE_AM_OOO_SHUTDOWN_ENB 0x301044 #define HPRE_AM_OOO_SHUTDOWN_ENABLE BIT(0) #define HPRE_WR_MSI_PORT BIT(2) @@ -417,12 +427,63 @@ static void hpre_close_sva_prefetch(struct hisi_qm *qm) pci_err(qm->pdev, "failed to close sva prefetch\n"); } +static void hpre_enable_clock_gate(struct hisi_qm *qm) +{ + u32 val; + + if (qm->ver < QM_HW_V3) + return; + + val = readl(qm->io_base + HPRE_CLKGATE_CTL); + val |= HPRE_CLKGATE_CTL_EN; + writel(val, qm->io_base + HPRE_CLKGATE_CTL); + + val = readl(qm->io_base + HPRE_PEH_CFG_AUTO_GATE); + val |= HPRE_PEH_CFG_AUTO_GATE_EN; + writel(val, qm->io_base + HPRE_PEH_CFG_AUTO_GATE); + + val = readl(qm->io_base + HPRE_CLUSTER_DYN_CTL); + val |= HPRE_CLUSTER_DYN_CTL_EN; + writel(val, qm->io_base + HPRE_CLUSTER_DYN_CTL); + + val = readl_relaxed(qm->io_base + HPRE_CORE_SHB_CFG); + val |= HPRE_CORE_GATE_EN; + writel(val, qm->io_base + HPRE_CORE_SHB_CFG); +} + +static void hpre_disable_clock_gate(struct hisi_qm *qm) +{ + u32 val; + + if (qm->ver < QM_HW_V3) + return; + + val = readl(qm->io_base + HPRE_CLKGATE_CTL); + val &= ~HPRE_CLKGATE_CTL_EN; + writel(val, qm->io_base + HPRE_CLKGATE_CTL); + + val = readl(qm->io_base + HPRE_PEH_CFG_AUTO_GATE); + val &= ~HPRE_PEH_CFG_AUTO_GATE_EN; + writel(val, qm->io_base + HPRE_PEH_CFG_AUTO_GATE); + + val = readl(qm->io_base + HPRE_CLUSTER_DYN_CTL); + val &= ~HPRE_CLUSTER_DYN_CTL_EN; + writel(val, qm->io_base + HPRE_CLUSTER_DYN_CTL); + + val = readl_relaxed(qm->io_base + HPRE_CORE_SHB_CFG); + val &= ~HPRE_CORE_GATE_EN; + writel(val, qm->io_base + HPRE_CORE_SHB_CFG); +} + static int hpre_set_user_domain_and_cache(struct hisi_qm *qm) { struct device *dev = &qm->pdev->dev; u32 val; int ret; + /* disabel dynamic clock gate before sram init */ + hpre_disable_clock_gate(qm); + writel(HPRE_QM_USR_CFG_MASK, qm->io_base + QM_ARUSER_M_CFG_ENABLE); writel(HPRE_QM_USR_CFG_MASK, qm->io_base + QM_AWUSER_M_CFG_ENABLE); writel_relaxed(HPRE_QM_AXI_CFG_MASK, qm->io_base + QM_AXI_M_CFG); @@ -473,6 +534,8 @@ static int hpre_set_user_domain_and_cache(struct hisi_qm *qm) /* Config data buffer pasid needed by Kunpeng 920 */ hpre_config_pasid(qm); + hpre_enable_clock_gate(qm); + return ret; } -- 2.8.1