From patchwork Mon Jun 17 08:46:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 166975 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2582235ilk; Mon, 17 Jun 2019 01:46:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOdO9zOc/qhyLbcADUGnBgKsPqlHrA3LjjfxJlVEnGesTx7Zx/rikHWyDpDvX+4U9DVd0B X-Received: by 2002:a17:902:aa47:: with SMTP id c7mr20109741plr.171.1560761202659; Mon, 17 Jun 2019 01:46:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560761202; cv=none; d=google.com; s=arc-20160816; b=QZBsmmA0REjBj2AwcTUjje9+b4LHGo9FOcqPMq9uemqs4bgfu2jC83+feT9VhnQgNA bP8+hm+qxNYQ7WR1HeGXQbrqwhIjw023C5y5u8IXpxUHQeqSo1bPu/n5MrcvBaJTvrj1 klrfpvrL5htUvb//5GrZqtIouf4X4KZeQX3bu1+iVu2elZppjqWs+Eyqn0HqvH6rl+Ik vCTkiUqtXgcWeNW+/eHCbODu3yG3PsE8EytMqLs1pNZkmt8ycD5AmSwkQCkKQhSZdtMq zSHjhDpNynUdzxa3dk4ZnPaUQFlzimtzjdsV3kD6IXxT3R0tGJ/bmMjCSmXVxXro4A+T 3ANA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=6v6X4s2I3lsRHPLCypQctANZnwyiAiJz51yWsajOhqk=; b=g9o9eWfb4HUepv4rXnpLQEs4MTEKcxUgJ0De4dA/ed2IGUHGC4HuPRAlNgYHRzuO0W e61BObjI2ZCh2zo37CecdIyxxuDZdUr7S48wM1P/VtG/9P1vTHj7EHfqIwJ3bVbVo04Q nFXhXNj+xzZ/mDNISZgtDSTW1sXxeNPCD645Gmxl+5sCaQSfmAc53jEQSBQSKW5dczmW kITXN/1AEs3ydhr1gnMvmRzdPfBaEjxHjxqiedEgbIf36abN9fEj6/sadGhLesykN53k Vcc2M21tlgGduQTami4dLLaWW84vY88xwoCX5aEWfDSEA1L+ObqBpbg6ptn/KCVwlbBn CLZA== 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 k15si614817pga.99.2019.06.17.01.46.42; Mon, 17 Jun 2019 01:46:42 -0700 (PDT) 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 S1727742AbfFQIql (ORCPT + 3 others); Mon, 17 Jun 2019 04:46:41 -0400 Received: from foss.arm.com ([217.140.110.172]:41806 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725971AbfFQIqk (ORCPT ); Mon, 17 Jun 2019 04:46:40 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D4BC5360; Mon, 17 Jun 2019 01:46:39 -0700 (PDT) Received: from e110176-lin.kfn.arm.com (unknown [10.50.4.178]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9F96C3F246; Mon, 17 Jun 2019 01:46:38 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" Cc: Ofir Drang , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] crypto: ccree: Relocate driver irq registration after clk init Date: Mon, 17 Jun 2019 11:46:27 +0300 Message-Id: <20190617084631.23551-2-gilad@benyossef.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190617084631.23551-1-gilad@benyossef.com> References: <20190617084631.23551-1-gilad@benyossef.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Ofir Drang Relocate driver interrupt registration after clk gate enabling. Signed-off-by: Ofir Drang --- drivers/crypto/ccree/cc_driver.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) -- 2.21.0 diff --git a/drivers/crypto/ccree/cc_driver.c b/drivers/crypto/ccree/cc_driver.c index 86ac7b443355..0f80cb4f79fb 100644 --- a/drivers/crypto/ccree/cc_driver.c +++ b/drivers/crypto/ccree/cc_driver.c @@ -315,15 +315,6 @@ static int init_cc_resources(struct platform_device *plat_dev) return new_drvdata->irq; } - rc = devm_request_irq(dev, new_drvdata->irq, cc_isr, - IRQF_SHARED, "ccree", new_drvdata); - if (rc) { - dev_err(dev, "Could not register to interrupt %d\n", - new_drvdata->irq); - return rc; - } - dev_dbg(dev, "Registered to IRQ: %d\n", new_drvdata->irq); - init_completion(&new_drvdata->hw_queue_avail); if (!plat_dev->dev.dma_mask) @@ -401,6 +392,15 @@ static int init_cc_resources(struct platform_device *plat_dev) /* Display HW versions */ dev_info(dev, "ARM CryptoCell %s Driver: HW version 0x%08X/0x%8X, Driver version %s\n", hw_rev->name, hw_rev_pidr, sig_cidr, DRV_MODULE_VERSION); + /* register the driver isr function */ + rc = devm_request_irq(dev, new_drvdata->irq, cc_isr, + IRQF_SHARED, "ccree", new_drvdata); + if (rc) { + dev_err(dev, "Could not register to interrupt %d\n", + new_drvdata->irq); + return rc; + } + dev_dbg(dev, "Registered to IRQ: %d\n", new_drvdata->irq); rc = init_cc_regs(new_drvdata, true); if (rc) { From patchwork Mon Jun 17 08:46:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 166976 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2582267ilk; Mon, 17 Jun 2019 01:46:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJUwaAxK9ZK9Msf0V2mdgVbHsnfqwqWst9Wb9DwbxpReLWsXGRil3s3ZP0lRcWAQeU1Za3 X-Received: by 2002:a65:668e:: with SMTP id b14mr321185pgw.407.1560761204643; Mon, 17 Jun 2019 01:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560761204; cv=none; d=google.com; s=arc-20160816; b=hfS/n7OxuQekvIDrTfrHciDCxbOU+HvcHQ0ifY2s73G2gjw7s2LldZEz4eP3WdinXU ULCNDL3D9BIXtwvG4SWHZnIV3eHKxMbfq/tiTB0JUOtwfjOmt972fJo8+Sq/juvXwoxr AmHup5shjB/sIjALkq1vVWW+3RHkp95hy1/Smczzjw0opEhY6WoA79ZX2CKbL1VDvsM0 VLSNBQJIF4Q5JyS3eseSi4v6hOF/YyPPOIEUMGUEz2kANavJQlE1PPGTpUi/Sbdzk6Na /f1f0aP8lOKCzXX76VbSRhfiiDNZ4tmkZwvFFxMFRtVDtakV8VBbJd3R8s/0mHlPxfZT pmBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+ZjB/tAb4yo6qIjy6t5PSYIKzPIIZWTqP7VQ3CmWPtQ=; b=LxEMygME2aHysJPntV+zqFrnotRT0VLLtBValRDt8BLINVxg0UTP+tPsNecVHaPyqX jx+QuDiI5Xcw/RMolNCfKkPKhOZmm4WBjj00t1ZJCtn4poqfBB+V8vhKsEfsAQ1VgmwE IA2o6OAvQou1hhHE8RVhkBich68kJtIUW1YpHgZWcx81pCoLZ4sMihHcv1hxt1rkBVJ8 6BgnqS1sUUywUwEJvdecav097v3wjcDOGMcK1+PANOWlLEL81CJY1U0XB1828wtzqkxE 26hZX3Ymp1OO5G/a3Y4yia6CMQ/XvnhDKVqEF4dKxhY+e9IOKdOeyocft6AKu+du6CLq MDsA== 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 k15si614817pga.99.2019.06.17.01.46.44; Mon, 17 Jun 2019 01:46:44 -0700 (PDT) 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 S1725971AbfFQIqn (ORCPT + 3 others); Mon, 17 Jun 2019 04:46:43 -0400 Received: from foss.arm.com ([217.140.110.172]:41816 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727805AbfFQIqn (ORCPT ); Mon, 17 Jun 2019 04:46:43 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 162FC28; Mon, 17 Jun 2019 01:46:42 -0700 (PDT) Received: from e110176-lin.kfn.arm.com (unknown [10.50.4.178]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D42863F246; Mon, 17 Jun 2019 01:46:40 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" Cc: Ofir Drang , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] crypto: ccree: check that cryptocell reset completed Date: Mon, 17 Jun 2019 11:46:28 +0300 Message-Id: <20190617084631.23551-3-gilad@benyossef.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190617084631.23551-1-gilad@benyossef.com> References: <20190617084631.23551-1-gilad@benyossef.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Ofir Drang In case of driver probe and pm resume we need to check that the cryptocell hardware reset cycle is completed. during the reset cycle that Cryptocell provide read only access to the APB interface which allows to verify through the CC registers that the reset is completed. Until reset completion we assume that any write/crypto operation is blocked. Signed-off-by: Ofir Drang --- drivers/crypto/ccree/cc_driver.c | 33 ++++++++++++++++++++++++++++- drivers/crypto/ccree/cc_driver.h | 3 +++ drivers/crypto/ccree/cc_host_regs.h | 3 +++ drivers/crypto/ccree/cc_pm.c | 5 +++++ 4 files changed, 43 insertions(+), 1 deletion(-) -- 2.21.0 diff --git a/drivers/crypto/ccree/cc_driver.c b/drivers/crypto/ccree/cc_driver.c index 0f80cb4f79fb..1e73d32148dd 100644 --- a/drivers/crypto/ccree/cc_driver.c +++ b/drivers/crypto/ccree/cc_driver.c @@ -48,6 +48,7 @@ struct cc_hw_data { }; #define CC_NUM_IDRS 4 +#define CC_HW_RESET_LOOP_COUNT 10 /* Note: PIDR3 holds CMOD/Rev so ignored for HW identification purposes */ static const u32 pidr_0124_offsets[CC_NUM_IDRS] = { @@ -188,6 +189,31 @@ static irqreturn_t cc_isr(int irq, void *dev_id) return IRQ_HANDLED; } +bool cc_wait_for_reset_completion(struct cc_drvdata *drvdata) +{ + unsigned int val; + unsigned int i; + + /* 712/710/63 has no reset completion indication, always return true */ + if (drvdata->hw_rev <= CC_HW_REV_712) + return true; + + for (i = 0; i < CC_HW_RESET_LOOP_COUNT; i++) { + /* in cc7x3 NVM_IS_IDLE indicates that CC reset is + * completed and device is fully functional + */ + val = cc_ioread(drvdata, CC_REG(NVM_IS_IDLE)); + if (val & CC_NVM_IS_IDLE_MASK) { + /* hw indicate reset completed */ + return true; + } + /* allow scheduling other process on the processor */ + schedule(); + } + /* reset not completed */ + return false; +} + int init_cc_regs(struct cc_drvdata *drvdata, bool is_probe) { unsigned int val, cache_params; @@ -343,6 +369,11 @@ static int init_cc_resources(struct platform_device *plat_dev) new_drvdata->sec_disabled = cc_sec_disable; + /* wait for Crytpcell reset completion */ + if (!cc_wait_for_reset_completion(new_drvdata)) { + dev_err(dev, "Cryptocell reset not completed"); + } + if (hw_rev->rev <= CC_HW_REV_712) { /* Verify correct mapping */ val = cc_ioread(new_drvdata, new_drvdata->sig_offset); @@ -398,7 +429,7 @@ static int init_cc_resources(struct platform_device *plat_dev) if (rc) { dev_err(dev, "Could not register to interrupt %d\n", new_drvdata->irq); - return rc; + goto post_clk_err; } dev_dbg(dev, "Registered to IRQ: %d\n", new_drvdata->irq); diff --git a/drivers/crypto/ccree/cc_driver.h b/drivers/crypto/ccree/cc_driver.h index cc403d705c9d..556b3322667e 100644 --- a/drivers/crypto/ccree/cc_driver.h +++ b/drivers/crypto/ccree/cc_driver.h @@ -72,6 +72,8 @@ enum cc_std_body { #define CC_SECURITY_DISABLED_MASK BIT(CC_SECURITY_DISABLED_VALUE_BIT_SHIFT) +#define CC_NVM_IS_IDLE_MASK BIT(CC_NVM_IS_IDLE_VALUE_BIT_SHIFT) + #define AXIM_MON_COMP_VALUE GENMASK(CC_AXIM_MON_COMP_VALUE_BIT_SIZE + \ CC_AXIM_MON_COMP_VALUE_BIT_SHIFT, \ CC_AXIM_MON_COMP_VALUE_BIT_SHIFT) @@ -221,6 +223,7 @@ static inline void dump_byte_array(const char *name, const u8 *the_array, __dump_byte_array(name, the_array, size); } +bool cc_wait_for_reset_completion(struct cc_drvdata *drvdata); int init_cc_regs(struct cc_drvdata *drvdata, bool is_probe); void fini_cc_regs(struct cc_drvdata *drvdata); int cc_clk_on(struct cc_drvdata *drvdata); diff --git a/drivers/crypto/ccree/cc_host_regs.h b/drivers/crypto/ccree/cc_host_regs.h index d0764147573f..ad1acb105f2d 100644 --- a/drivers/crypto/ccree/cc_host_regs.h +++ b/drivers/crypto/ccree/cc_host_regs.h @@ -114,6 +114,9 @@ #define CC_HOST_ICR_DSCRPTR_WATERMARK_QUEUE0_CLEAR_BIT_SIZE 0x1UL #define CC_HOST_ICR_AXIM_COMP_INT_CLEAR_BIT_SHIFT 0x17UL #define CC_HOST_ICR_AXIM_COMP_INT_CLEAR_BIT_SIZE 0x1UL +#define CC_NVM_IS_IDLE_REG_OFFSET 0x0A10UL +#define CC_NVM_IS_IDLE_VALUE_BIT_SHIFT 0x0UL +#define CC_NVM_IS_IDLE_VALUE_BIT_SIZE 0x1UL #define CC_SECURITY_DISABLED_REG_OFFSET 0x0A1CUL #define CC_SECURITY_DISABLED_VALUE_BIT_SHIFT 0x0UL #define CC_SECURITY_DISABLED_VALUE_BIT_SIZE 0x1UL diff --git a/drivers/crypto/ccree/cc_pm.c b/drivers/crypto/ccree/cc_pm.c index 2dad9c9543c6..20f7f3d34e27 100644 --- a/drivers/crypto/ccree/cc_pm.c +++ b/drivers/crypto/ccree/cc_pm.c @@ -49,6 +49,11 @@ int cc_pm_resume(struct device *dev) dev_err(dev, "failed getting clock back on. We're toast.\n"); return rc; } + /* wait for Crytpcell reset completion */ + if (!cc_wait_for_reset_completion(drvdata)) { + dev_err(dev, "Cryptocell reset not completed"); + return -EBUSY; + } cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE); rc = init_cc_regs(drvdata, false); From patchwork Mon Jun 17 08:46:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 166977 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2582292ilk; Mon, 17 Jun 2019 01:46:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPkR5tzcq8+i7Y3jGPz24+a3yK2/E1x2gzO/k0Y7TlMY8K5UNx/liXdDjVt+yV23m4P9/i X-Received: by 2002:a17:90a:2561:: with SMTP id j88mr25208673pje.121.1560761206842; Mon, 17 Jun 2019 01:46:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560761206; cv=none; d=google.com; s=arc-20160816; b=sXQkkNWmIDj31AyctADhT4eCEEV4Fc9z6hrUxWiQTZ/SBXxMzz5LLjYt6Tc+1ikIIz avCLaHbH/ZceRxIooiKFjO82+v/EHm8FdcJNApVlCEs6urhsQsb2h9t4q6i7p1UByCW+ QWPUPI+CD6a0w5t+f7vP+CopGRTyJY89kKhxW+NTyLeb8QNALVdAALzzSq+c//1hQ7T1 J2n+63qRXIC2gtZOwPUP3E8Yp6/6Qdxe8/qMAKaAYNCJLjs0OVCLjRWjH/YXcArW9A5v aG9pkEzqAFKnMkRrvbjW2KR9SXo7Cu9Lt5Lt9m8lfv0t+fRLgOQvsuluaZg1vyGz2C6a P+sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=2GpmxiGAi9MZ2uYPnVRB7goDwTuEZNfhT40Csp3ZMW0=; b=U0VHU/KU5QA5s3P2F/jQ8cIreh6LzX9GuwleUlHBqFeujEGlOmyKre4f63CwFVJum5 tHd7bDQQsZNMl9KDCKFvgyIw1P5pDQrWJ3/agFbbU6Adp6eSLff/HewmE9p/1YK/FETP GtTmp2CKdZstI+orchJn6ZztK7KJOfcpApJU8nDezALZ3+XWifZiTHPSHw0HtvV8aoh5 /UgPyBaX3AyfgyuOC2EwOH5bedVAp0jJJh37Z11csCt4ZHt+YUjJjWIaNkIbmptJYCXM xIf2UmorSfOA9MctraajfdMeiH2XzEi17zBCDH4IOxXz05Fjv0lei8wJYUYJNLjHx5+G 7jug== 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 k15si614817pga.99.2019.06.17.01.46.46; Mon, 17 Jun 2019 01:46:46 -0700 (PDT) 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 S1727858AbfFQIqp (ORCPT + 3 others); Mon, 17 Jun 2019 04:46:45 -0400 Received: from foss.arm.com ([217.140.110.172]:41826 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727838AbfFQIqp (ORCPT ); Mon, 17 Jun 2019 04:46:45 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 44C6F28; Mon, 17 Jun 2019 01:46:44 -0700 (PDT) Received: from e110176-lin.kfn.arm.com (unknown [10.50.4.178]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 108B53F246; Mon, 17 Jun 2019 01:46:42 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" Cc: Ofir Drang , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] crypto: ccree: prevent isr handling in case driver is suspended Date: Mon, 17 Jun 2019 11:46:29 +0300 Message-Id: <20190617084631.23551-4-gilad@benyossef.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190617084631.23551-1-gilad@benyossef.com> References: <20190617084631.23551-1-gilad@benyossef.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Ofir Drang ccree irq may be shared with other devices, in order to prevent ccree isr handling while device maybe suspended we added a check to verify that the device is not suspended. Signed-off-by: Ofir Drang --- drivers/crypto/ccree/cc_driver.c | 3 +++ drivers/crypto/ccree/cc_pm.c | 6 ++++++ drivers/crypto/ccree/cc_pm.h | 7 +++++++ 3 files changed, 16 insertions(+) -- 2.21.0 diff --git a/drivers/crypto/ccree/cc_driver.c b/drivers/crypto/ccree/cc_driver.c index 1e73d32148dd..667bc73d7a00 100644 --- a/drivers/crypto/ccree/cc_driver.c +++ b/drivers/crypto/ccree/cc_driver.c @@ -134,6 +134,9 @@ static irqreturn_t cc_isr(int irq, void *dev_id) u32 imr; /* STAT_OP_TYPE_GENERIC STAT_PHASE_0: Interrupt */ + /* if driver suspended return, probebly shared interrupt */ + if (cc_pm_is_dev_suspended(dev)) + return IRQ_NONE; /* read the interrupt status */ irr = cc_ioread(drvdata, CC_REG(HOST_IRR)); diff --git a/drivers/crypto/ccree/cc_pm.c b/drivers/crypto/ccree/cc_pm.c index 20f7f3d34e27..899a52f05b7a 100644 --- a/drivers/crypto/ccree/cc_pm.c +++ b/drivers/crypto/ccree/cc_pm.c @@ -106,6 +106,12 @@ int cc_pm_put_suspend(struct device *dev) return rc; } +bool cc_pm_is_dev_suspended(struct device *dev) +{ + /* check device state using runtime api */ + return pm_runtime_suspended(dev); +} + int cc_pm_init(struct cc_drvdata *drvdata) { struct device *dev = drvdata_to_dev(drvdata); diff --git a/drivers/crypto/ccree/cc_pm.h b/drivers/crypto/ccree/cc_pm.h index 6190cdba5dad..a7d98a5da2e1 100644 --- a/drivers/crypto/ccree/cc_pm.h +++ b/drivers/crypto/ccree/cc_pm.h @@ -22,6 +22,7 @@ int cc_pm_suspend(struct device *dev); int cc_pm_resume(struct device *dev); int cc_pm_get(struct device *dev); int cc_pm_put_suspend(struct device *dev); +bool cc_pm_is_dev_suspended(struct device *dev); #else @@ -54,6 +55,12 @@ static inline int cc_pm_put_suspend(struct device *dev) return 0; } +static inline bool cc_pm_is_dev_suspended(struct device *dev) +{ + /* if PM not supported device is never suspend */ + return false; +} + #endif #endif /*__POWER_MGR_H__*/ From patchwork Mon Jun 17 08:46:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 166978 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2582307ilk; Mon, 17 Jun 2019 01:46:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqzAPgPgrv+y4hlZozQ/4yy5PLas79O7Tl4B0wM8tgypXiBzugwMj7bmD/4uF3hZdN/o9qud X-Received: by 2002:aa7:9ab5:: with SMTP id x21mr15793946pfi.139.1560761208171; Mon, 17 Jun 2019 01:46:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560761208; cv=none; d=google.com; s=arc-20160816; b=R53YUYa5RQa2Rg+e3ROfJCPsNt6EMvhKQGXUCUoqx8K97DUWtuUipya8G5uRx5PcQi ZH8eyMi9JpH2aAYzFKAN72ctJ5W0jrnc2BoePt6rsyWW8+g9K+TAXXXVNa0ItaIzlJlG MvKb6YEqQb73LL3qZZTxU+Jmd+dcfn1Kq5+gNoZgWiqybKo20okoctkAA4IND3v4lbOy SH+L81ZBPOQqsGYRt7dYZAMS5rSyu0w6dZlhgSIOaAm/GhgmlH0Yp3m2G4JQta4aKcfQ ECg6fQJw5gN9q4jUjpBhTnYdMtsbPVFh0Va9+9Ua90Gve7IC+OlDKSHdKAhjUvx/VsPL 8YeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=yE4HGq+cZW845uFS7HkvoTN/C30rxMwoBCNS8SlL2As=; b=CmQOqQBfiucyBkz2R1HsbM/MfrLn42fomDs0EpQ3r4u3QMCzi5lsl29mxXpoRmBZVA ZRcy01E+xnQCCqCoQnTC+I+lR6teymJQq57tuMg9uEVICaYrQtyMNqmrcdqUO+lx8ZCV HSkjYBMYDF16RBojw2nK5fMp+IaSwlbDkGUyUbHEsyyPACQ5gS/WIKggaIo1htkNDDfY zG11uvUgArjwdUBA9tTRTm5+DjeQkEpR/VNwKJdSnxrVOAhmhdgfTRMI5FNqW6UMxtwt r8Vl6arX0XLqLlFA0w6eEd/c+XWkuFUu69585GXOLnuwqC/noBEXatfg0ao5IY25HaXL 6pZQ== 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 k15si614817pga.99.2019.06.17.01.46.47; Mon, 17 Jun 2019 01:46:48 -0700 (PDT) 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 S1727892AbfFQIqr (ORCPT + 3 others); Mon, 17 Jun 2019 04:46:47 -0400 Received: from foss.arm.com ([217.140.110.172]:41836 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727873AbfFQIqq (ORCPT ); Mon, 17 Jun 2019 04:46:46 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4FA8E28; Mon, 17 Jun 2019 01:46:46 -0700 (PDT) Received: from e110176-lin.kfn.arm.com (unknown [10.50.4.178]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 41CC63F246; Mon, 17 Jun 2019 01:46:45 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] crypto: ccree: add HW engine config check Date: Mon, 17 Jun 2019 11:46:30 +0300 Message-Id: <20190617084631.23551-5-gilad@benyossef.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190617084631.23551-1-gilad@benyossef.com> References: <20190617084631.23551-1-gilad@benyossef.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add check to verify the stated device tree HW configuration matches the HW. Signed-off-by: Gilad Ben-Yossef --- drivers/crypto/ccree/cc_driver.c | 18 ++++++++++++++++++ drivers/crypto/ccree/cc_driver.h | 3 +++ drivers/crypto/ccree/cc_host_regs.h | 17 +++++++++++++++++ 3 files changed, 38 insertions(+) -- 2.21.0 diff --git a/drivers/crypto/ccree/cc_driver.c b/drivers/crypto/ccree/cc_driver.c index 667bc73d7a00..980aa04b655b 100644 --- a/drivers/crypto/ccree/cc_driver.c +++ b/drivers/crypto/ccree/cc_driver.c @@ -408,6 +408,24 @@ static int init_cc_resources(struct platform_device *plat_dev) } sig_cidr = val; + /* Check HW engine configuration */ + val = cc_ioread(new_drvdata, CC_REG(HOST_REMOVE_INPUT_PINS)); + switch (val) { + case CC_PINS_FULL: + /* This is fine */ + break; + case CC_PINS_SLIM: + if (new_drvdata->std_bodies & CC_STD_NIST) { + dev_warn(dev, "703 mode forced due to HW configuration.\n"); + new_drvdata->std_bodies = CC_STD_OSCCA; + } + break; + default: + dev_err(dev, "Unsupported engines configration.\n"); + rc = -EINVAL; + goto post_clk_err; + } + /* Check security disable state */ val = cc_ioread(new_drvdata, CC_REG(SECURITY_DISABLED)); val &= CC_SECURITY_DISABLED_MASK; diff --git a/drivers/crypto/ccree/cc_driver.h b/drivers/crypto/ccree/cc_driver.h index 556b3322667e..6448b2b9794b 100644 --- a/drivers/crypto/ccree/cc_driver.h +++ b/drivers/crypto/ccree/cc_driver.h @@ -58,6 +58,9 @@ enum cc_std_body { #define CC_COHERENT_CACHE_PARAMS 0xEEE +#define CC_PINS_FULL 0x0 +#define CC_PINS_SLIM 0x9F + /* Maximum DMA mask supported by IP */ #define DMA_BIT_MASK_LEN 48 diff --git a/drivers/crypto/ccree/cc_host_regs.h b/drivers/crypto/ccree/cc_host_regs.h index ad1acb105f2d..efe3e1d8b87b 100644 --- a/drivers/crypto/ccree/cc_host_regs.h +++ b/drivers/crypto/ccree/cc_host_regs.h @@ -206,6 +206,23 @@ #define CC_HOST_POWER_DOWN_EN_REG_OFFSET 0xA78UL #define CC_HOST_POWER_DOWN_EN_VALUE_BIT_SHIFT 0x0UL #define CC_HOST_POWER_DOWN_EN_VALUE_BIT_SIZE 0x1UL +#define CC_HOST_REMOVE_INPUT_PINS_REG_OFFSET 0x0A7CUL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_AES_ENGINE_BIT_SHIFT 0x0UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_AES_ENGINE_BIT_SIZE 0x1UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_AES_MAC_ENGINE_BIT_SHIFT 0x1UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_AES_MAC_ENGINE_BIT_SIZE 0x1UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_GHASH_ENGINE_BIT_SHIFT 0x2UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_GHASH_ENGINE_BIT_SIZE 0x1UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_DES_ENGINE_BIT_SHIFT 0x3UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_DES_ENGINE_BIT_SIZE 0x1UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_HASH_ENGINE_BIT_SHIFT 0x4UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_HASH_ENGINE_BIT_SIZE 0x1UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_SM3_ENGINE_BIT_SHIFT 0x5UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_SM3_ENGINE_BIT_SIZE 0x1UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_SM4_ENGINE_BIT_SHIFT 0x6UL +#define CC_HOST_REMOVE_INPUT_PINS_REMOVE_SM4_ENGINE_BIT_SIZE 0x1UL +#define CC_HOST_REMOVE_INPUT_PINS_OTP_DISCONNECTED_BIT_SHIFT 0x7UL +#define CC_HOST_REMOVE_INPUT_PINS_OTP_DISCONNECTED_BIT_SIZE 0x1UL // -------------------------------------- // BLOCK: ID_REGISTERS // --------------------------------------