From patchwork Wed Jul 27 00:10:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary R Hook X-Patchwork-Id: 9249135 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A44C2607D8 for ; Wed, 27 Jul 2016 00:25:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9414E26A4D for ; Wed, 27 Jul 2016 00:25:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8783D276AE; Wed, 27 Jul 2016 00:25:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0382026A4D for ; Wed, 27 Jul 2016 00:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757997AbcG0AZG (ORCPT ); Tue, 26 Jul 2016 20:25:06 -0400 Received: from mail-by2nam01on0071.outbound.protection.outlook.com ([104.47.34.71]:38339 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756964AbcG0AY7 (ORCPT ); Tue, 26 Jul 2016 20:24:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=RzWSWVOmusYE7CiCJZwi5WInXMGCmlsHpYLvvyyIaQY=; b=L5eqGBRoPQF0zexPQh3Fec8pAogPVRnjhg3SXKT/uuKxjOCFKS8FEuGqHOGNdyPwF3VRaFfGUBRLJas/3QoLbvzB3oRlZayyg/vzcP/x13ETtPXRVfBgryHMmbnmgS+zM1pTgJM/YifEeiEf9r3g/dXBbDoeubi6C3wvdiQSPr0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Received: from [10.236.19.42] (165.204.77.1) by BY2PR12MB0339.namprd12.prod.outlook.com (10.162.84.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.544.10; Wed, 27 Jul 2016 00:10:06 +0000 Subject: [PATCH 05/10] crypto: ccp - Refactor code supporting the CCP's RNG From: Gary R Hook To: CC: , , Date: Tue, 26 Jul 2016 19:10:02 -0500 Message-ID: <20160727001002.24944.7042.stgit@taos> In-Reply-To: <20160727000652.24944.44919.stgit@taos> References: <20160727000652.24944.44919.stgit@taos> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BY2PR21CA0018.namprd21.prod.outlook.com (10.162.74.156) To BY2PR12MB0339.namprd12.prod.outlook.com (10.162.84.14) X-MS-Office365-Filtering-Correlation-Id: 387a6940-9d5d-4d80-d870-08d3b5b25da0 X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0339; 2:hA2aYdUtIrcuBBz24yxsZ225OiD4AaQwA+4Nr2JDYf2SiqMU829GEDd+qGmW1UBW03k1hmKh9wwLGbDBpSfAp4eELpfjsNaHs6X/tuJeubveatOqWdMM2JwfuLTMSSXYtNPJ/4Z78/B/P7RQBaeWloV2PJ5/x75NBkHd1dgaSqdgrqJzoZVBOE2muI4lOTWY; 3:PGLMy+yMLmZSouD5c0bDVVNV4IhkyzGc1uhFeupokcLu6W5OecuRgZsCNjxDSSXXfekagM2QNk6j+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-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:BY2PR12MB0339; BCL:0; PCL:0; RULEID:; SRVR:BY2PR12MB0339; X-Forefront-PRVS: 0016DEFF96 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(189002)(199003)(76176999)(92566002)(54356999)(2950100001)(50986999)(97736004)(81156014)(77096005)(81166006)(8676002)(105586002)(230700001)(42186005)(50466002)(7736002)(33646002)(9686002)(110136002)(101416001)(83506001)(2906002)(4326007)(1076002)(6116002)(229853001)(19580395003)(23676002)(2351001)(586003)(19580405001)(7846002)(66066001)(103116003)(4001350100001)(97746001)(189998001)(33716001)(47776003)(3846002)(305945005)(86362001)(68736007)(106356001)(71626007); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0339; H:[10.236.19.42]; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCWTJQUjEyTUIwMzM5OzIzOnBkUDN2QzhvZVZ3NEt6Tmszai9zeFNub056?= =?utf-8?B?S3ZIZnRPdTNBSGxXbUJsWDRYdDNDZmZ4QWdkcHA5dy91RG9RT3BSU1Nlc3BS?= =?utf-8?B?NWxIQnVlY0prZDVwVGdob0hqM1lud1VuQVA3ZWxYSy8vOGhrNHREaHJmOWNY?= =?utf-8?B?S0tJd3krcXZVdGM2RTlET0pUUlhva2o3Sm1iOFBlRVVtUHBlV3hINkRldDVG?= =?utf-8?B?UG5MeCtEUGoxdk9QZFBIclozMlV1dnJjQ1NUcGdKaFlUVjg5Y0lGVHVyR0FK?= =?utf-8?B?bGZGcXpKekVJWGNzN3didUg1UWFUSGNRWkkycVRUUm9XUjFrTU1rV3czUnF4?= =?utf-8?B?YmJZ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oue4TJa5++cPlp5GFe660N/Nu7CThYdf476YNwEB9/PLGmLuMoyYEFnNidZe9zY3sSglHbFiBu5XrU+X+Kk8PpuEqN3G2OY=; 7:fo2fHgdq8kc4z1Y4ldDvXf4p9pkELesOYiYNIJUPPUPtpvM27uHblkqwtYV9Z01DP2XQ906T9vAsEwTyzFXcviHNP+3DKKDJElQZ2uAynmp0BNWIvgIZlOLouHY3wb00RSGc0eY1Cg7a6EjCcJ48iIdGy43UC/hrGgHqdjwcMLA0EggVR+I863mn7L7fTqEEh/ZmuWIqBLnFrO5YW4QmZS5cMfwQVsUWI2yH1fR8RU0ztZ6KY8PJmUGhTYG8fDeN SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0339; 20:gqvK03Rw+0cSdtNKD31R/WMr212Jz8n7gWjlZaIiMrukytpTivYazBlldlxEy+eH8IUqXxwXGM7GgED8Lyo9nwy38S+LXTsB8LP4CJO+JWnMogRk9iaPqF6FUnZhEs5rITWpLTN9yh1RXeCPPNfPufH+kKg2t1tpQk7BHRoOZGFsAIKErNHioq3KVhe9lLQWjnYP9QpXrR2VXtALf6pEb6QJefOseGcyp32OGig+C4pWcH3RdYF3emKqxMFKDQE1 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2016 00:10:06.5317 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0339 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make the RNG support code common (where possible) in preparation for adding a v5 device. Signed-off-by: Gary R Hook --- drivers/crypto/ccp/ccp-dev-v3.c | 51 ++++++++------------------------------- drivers/crypto/ccp/ccp-dev.c | 28 +++++++++++++++++++++ drivers/crypto/ccp/ccp-dev.h | 1 + 3 files changed, 40 insertions(+), 40 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/crypto/ccp/ccp-dev-v3.c b/drivers/crypto/ccp/ccp-dev-v3.c index 5b06599..373ac4f 100644 --- a/drivers/crypto/ccp/ccp-dev-v3.c +++ b/drivers/crypto/ccp/ccp-dev-v3.c @@ -307,35 +307,6 @@ static int ccp_perform_ecc(struct ccp_op *op) return ccp_do_cmd(op, cr, ARRAY_SIZE(cr)); } -static int ccp_trng_read(struct hwrng *rng, void *data, size_t max, bool wait) -{ - struct ccp_device *ccp = container_of(rng, struct ccp_device, hwrng); - u32 trng_value; - int len = min_t(int, sizeof(trng_value), max); - - /* - * Locking is provided by the caller so we can update device - * hwrng-related fields safely - */ - trng_value = ioread32(ccp->io_regs + TRNG_OUT_REG); - if (!trng_value) { - /* Zero is returned if not data is available or if a - * bad-entropy error is present. Assume an error if - * we exceed TRNG_RETRIES reads of zero. - */ - if (ccp->hwrng_retries++ > TRNG_RETRIES) - return -EIO; - - return 0; - } - - /* Reset the counter and save the rng value */ - ccp->hwrng_retries = 0; - memcpy(data, &trng_value, len); - - return len; -} - static int ccp_init(struct ccp_device *ccp) { struct device *dev = ccp->dev; @@ -495,17 +466,6 @@ static void ccp_destroy(struct ccp_device *ccp) /* Remove this device from the list of available units first */ ccp_del_device(ccp); - /* Unregister the DMA engine */ - ccp_dmaengine_unregister(ccp); - - /* Unregister the RNG */ - hwrng_unregister(&ccp->hwrng); - - /* Stop the queue kthreads */ - for (i = 0; i < ccp->cmd_q_count; i++) - if (ccp->cmd_q[i].kthread) - kthread_stop(ccp->cmd_q[i].kthread); - /* Build queue interrupt mask (two interrupt masks per queue) */ qim = 0; for (i = 0; i < ccp->cmd_q_count; i++) { @@ -523,6 +483,17 @@ static void ccp_destroy(struct ccp_device *ccp) } iowrite32(qim, ccp->io_regs + IRQ_STATUS_REG); + /* Unregister the DMA engine */ + ccp_dmaengine_unregister(ccp); + + /* Unregister the RNG */ + hwrng_unregister(&ccp->hwrng); + + /* Stop the queue kthreads */ + for (i = 0; i < ccp->cmd_q_count; i++) + if (ccp->cmd_q[i].kthread) + kthread_stop(ccp->cmd_q[i].kthread); + ccp->free_irq(ccp); for (i = 0; i < ccp->cmd_q_count; i++) diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c index 9c8cfbb..6b44730 100644 --- a/drivers/crypto/ccp/ccp-dev.c +++ b/drivers/crypto/ccp/ccp-dev.c @@ -409,6 +409,34 @@ struct ccp_device *ccp_alloc_struct(struct device *dev) return ccp; } +int ccp_trng_read(struct hwrng *rng, void *data, size_t max, bool wait) +{ + struct ccp_device *ccp = container_of(rng, struct ccp_device, hwrng); + u32 trng_value; + int len = min_t(int, sizeof(trng_value), max); + + /* Locking is provided by the caller so we can update device + * hwrng-related fields safely + */ + trng_value = ioread32(ccp->io_regs + TRNG_OUT_REG); + if (!trng_value) { + /* Zero is returned if not data is available or if a + * bad-entropy error is present. Assume an error if + * we exceed TRNG_RETRIES reads of zero. + */ + if (ccp->hwrng_retries++ > TRNG_RETRIES) + return -EIO; + + return 0; + } + + /* Reset the counter and save the rng value */ + ccp->hwrng_retries = 0; + memcpy(data, &trng_value, len); + + return len; +} + #ifdef CONFIG_PM bool ccp_queues_suspended(struct ccp_device *ccp) { diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h index 4e38a61..0c44c5e0 100644 --- a/drivers/crypto/ccp/ccp-dev.h +++ b/drivers/crypto/ccp/ccp-dev.h @@ -440,6 +440,7 @@ void ccp_del_device(struct ccp_device *ccp); struct ccp_device *ccp_alloc_struct(struct device *dev); bool ccp_queues_suspended(struct ccp_device *ccp); int ccp_cmd_queue_thread(void *data); +int ccp_trng_read(struct hwrng *rng, void *data, size_t max, bool wait); int ccp_run_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd);