From patchwork Wed Aug 5 18:28:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Milhoan X-Patchwork-Id: 6952421 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7D340C05AC for ; Wed, 5 Aug 2015 18:29:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 40EF3205C2 for ; Wed, 5 Aug 2015 18:29:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF9D2205D1 for ; Wed, 5 Aug 2015 18:29:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752803AbbHES3D (ORCPT ); Wed, 5 Aug 2015 14:29:03 -0400 Received: from mail-bl2on0127.outbound.protection.outlook.com ([65.55.169.127]:7824 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753532AbbHES24 (ORCPT ); Wed, 5 Aug 2015 14:28:56 -0400 Received: from CY1PR0301MB1579.namprd03.prod.outlook.com (10.162.166.17) by CY1PR0301MB1289.namprd03.prod.outlook.com (10.161.213.151) with Microsoft SMTP Server (TLS) id 15.1.225.19; Wed, 5 Aug 2015 18:28:54 +0000 Received: from CH1PR03CA002.namprd03.prod.outlook.com (10.255.156.147) by CY1PR0301MB1579.namprd03.prod.outlook.com (10.162.166.17) with Microsoft SMTP Server (TLS) id 15.1.225.19; Wed, 5 Aug 2015 18:28:52 +0000 Received: from BL2FFO11FD019.protection.gbl (10.255.156.132) by CH1PR03CA002.outlook.office365.com (10.255.156.147) with Microsoft SMTP Server (TLS) id 15.1.225.19 via Frontend Transport; Wed, 5 Aug 2015 18:28:52 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; kernel.org; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BL2FFO11FD019.mail.protection.outlook.com (10.173.161.37) with Microsoft SMTP Server (TLS) id 15.1.243.9 via Frontend Transport; Wed, 5 Aug 2015 18:28:51 +0000 Received: from stc-hedley.am.freescale.net (stc-hedley.am.freescale.net [10.67.70.12]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t75ISmAI019320; Wed, 5 Aug 2015 11:28:51 -0700 From: Victoria Milhoan To: CC: , , , , , , Subject: [PATCH v2 14/14] crypto: caam - Detect hardware features during algorithm registration Date: Wed, 5 Aug 2015 11:28:48 -0700 Message-ID: <1438799328-10757-15-git-send-email-vicki.milhoan@freescale.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438799328-10757-1-git-send-email-vicki.milhoan@freescale.com> References: <1438228709-27650-1-git-send-email-vicki.milhoan@freescale.com> <1438799328-10757-1-git-send-email-vicki.milhoan@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD019; 1:aAGPtCJ0LhPjRwmGUL/TfhzZqJKFxNI8cmuvUuIzhMVUPH+3/8lS4x2CH2d69agFd2blvIQM+9SbfgwF4IrrEMKcacGMStDF3MXigbfkcMstFsdOZOSrKEA1AhccCPmM7AOuxniiYjFfqUIsnaWvZoPW3sWAKpf0a0t4XAXEJrEObKakV9Wy8+CAEV7Y/S9rNfykGvWmRy6pHXl2ElOKhjTIX0Y4osbqSw073zsGPiR4KfQqLy6xKI+4kjXq3A4nj3qqZl/3S9SRzmZ16B4pG1z2hWsHa6Vnddysf+sq7qskp5vASgts5UGI0MLGuK8vHDMs2BPxsS+yXlz25Z0ZDw== X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(199003)(189002)(50226001)(92566002)(68736005)(19580395003)(62966003)(77156002)(50986999)(189998001)(46102003)(81156007)(106466001)(48376002)(229853001)(86362001)(19580405001)(36756003)(4001540100001)(6806004)(5001960100002)(105606002)(50466002)(5001830100001)(47776003)(76176999)(5003940100001)(2950100001)(97736004)(64706001)(87936001)(69596002)(33646002)(575784001)(110136002)(85426001)(104016003)(5001860100001)(2351001)(77096005); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR0301MB1579; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1579; 2:7u1frnS/KBSqjTX8WLxXtdlMng7h/fGhMXazMsu5Vx/FNDoZgm4xStR7CF2KyxK3xG8TlNQWTCAooQKvm7kyr5Dc0ue0+QAe5FM8i4O/zjrIH35iHPuY0KTn5G2p9PyLBu6OYq8pHHlCmxHYzzRl5qejrZWY+InrSdw+nGXfsPQ=; 3:/+OunS2YBiCvwxoqX3cJfmEXNYSHeRcjchNvYcBMt8fMHwBU+v0CkSEvR25cqgGBFyPXcR/3FaLavnKrvOFZwIKmJ6jksO5pHiQVYi3L6/dzQG+GZeOYp5BIqYOrDUCY+/ogqoHsi/rs6111AfyonBGQOlrKImgSu/HmtItnQYK3gSsMgi1Pu7e5tmuqnGM/hbFIEeF9Rtu8d6YSP4Gh29okN+zMAxi59WJRMEluU5g=; 25:3EZejyRR63aj/3tvsfZAq0YdS82KQG3GbiJGlu907DVm9ImiPSExyorUe5EUkvCckhiuvNlIsl85sJSB+P0lhjABfW2xwOuM2srWeeM5g1l1xfsoWHTJjgqSJm6I9Hj8Fv0zxtRbiCMCM3imBwH11p3+YBDDUhOUd6k04i3vgjxwZw16G1siQ8HNIaXpWR2O/Ghz2ujxRtuTF04vyfu1cTuudC3pw6FqAam77SyqGF7RMCUFb7U/X3Ohq4Np6U4PzbwopDwUAPwwcLkk8LVDgw== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0301MB1579; UriScan:; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0301MB1289; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1579; 20:/mPFf934sUcFBLT7gsUV4NsCU2sHIcu8D1/pDMpOUffCuk3HMBnyOYUiI29PQ0k8xz/OvRPQu20A1/JV+VjeJ0zJ4KhRtcyINlmgdXt64aMr/j7cwp1nYbW9RGs4/x5sdoFrryi6h75NaWGGXPx1duZWxwjOaMKXf83pETlOxxqG/fVwFWXwxPjcAsOW7T+iXQOPB5E60/2iRromXaxCWjdgt9pU7vqUA6u+r//x3qUTG1q9FGFlNnOH3kVHb5P8ZorY30bEEBBPc5DBw+FwN8z3m92/mJyc1jBygngxvz+0decjh1W4taqt0pEMDG2iZYRUu/VXhSm4IG6/iLgt2qMTiHbhsnsDxSsxEMFFo5M=; 4:7KG8oaO/R+r85O8oWm1WWjmvCAWWyH/+c1WmP3j+AYuvk8Io3fiZiXjsef3hO9vD2TVFqBDDzqJRinsTazVYNbDVuRPhZA/PUj46QDCBbOoRP3Yaq/H957PofmvXODY/ofrev5ff3S1cU91vqdJhaxWwt3lzkX1rS2RfDitCt4rVySS4f+uq1F8abSOpiPKKq/VF1ahTUcBkQB3Qm4s0xwu1yQ7GRW7wHZL+YExX6anSxYRFXUmDWMy4Iif+ZWZfUZ0bzhVsAWbNt4TDlOkbDFKqV6YpMPDylAZhRCRUe3w= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:CY1PR0301MB1579; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0301MB1579; X-Forefront-PRVS: 06592CCE58 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR0301MB1579; 23:JNlMJ9uXKnhEkh3P5OcaDFYjYIp2oSXNLpTlABS?= =?us-ascii?Q?4kqJArWLarpZUAZjbTmQPT2BjjJOnvAUNWUmL6eOgiPM6tppFAd3BC0SluNh?= =?us-ascii?Q?6FniG5l7iwrphZyTjM/m1qeIzD3SFATFj7lbfF5MLhB24aaKzeEBJPSGqYtp?= =?us-ascii?Q?5WzpB9y9t4PMJa1mlQH8DpAs/i1WbO9u+t+HyGaOyuDY5q1/lA7ESLfQiy9c?= =?us-ascii?Q?Hw/GIoLg1/3b6APKuvYqo2sZJyc3aKxlF6bfpzXkx6T4lJH+Rrr3b9kpH3YM?= =?us-ascii?Q?XdWWa1S8Q6csa1lZC6T5ZoDLcXIO0A88CrGD7kjQS9fBpC/Zir1+A1ewvm+T?= =?us-ascii?Q?djvdYoTg7jJm7/Awy0uTMaPc/lIYVEnJwQtRixJ8KKqJ5OfBbIUGPKws0gew?= =?us-ascii?Q?g35dOIqa3SyG4H6bcTyA+iQ96efcepIJhtr5MgJonLI1dF/88XY2kNeu4Uur?= =?us-ascii?Q?ktxv9OUBi8dwhN4qpehiLnrqsRMSEQNBfe9gMTMaB7fVyorYGsXs5AZO3ZQF?= =?us-ascii?Q?y/3lf/EX+uJRYLbwZi4BBllLkMJViFhBL71u04QjQMXnwHR4e/DbUTDLE2/S?= =?us-ascii?Q?9glUNbOzDQALpRh/JwlXgtJn8TGvifF4JA9PK62yiZlTRd10qChQfQSEbX3e?= =?us-ascii?Q?/4MsPLTzvTAvsVobLivzYTruHsZkLME1TCQ5oZvwi6OGGNAlexENZ9V7YKU0?= =?us-ascii?Q?WwLOopLq/BoGFiaVli1xxGClRb6zLrn3Ci2U6k3lDKqOlVTNQjuCMnA4olLN?= =?us-ascii?Q?r6xhbctDaC78nAoWY452Cj8kp7EwAU47HqdO1xx6DMM3Ap+UWJuEOYwXjPWW?= =?us-ascii?Q?+0UJJwM6S7Eg/iFcMaSuPrgD2eMhtNEFOqzdIa2nYuZPTZxCUsyRTAoB+RZo?= =?us-ascii?Q?ZGSdq8bRWGyLGqcsXyTPB2/NExJJcPxSZphaTrv3TjiKXHHnjAtwI2MaMdTE?= =?us-ascii?Q?FM+G83bNKbuJRb8mPfDZ2MH64ctdsmBAPXUv0ufLQOiZ5oeklI0XVPFk7bIH?= =?us-ascii?Q?U1HKsA8BhiDZq0CJH9eh+KbKjRWPJnzqQDJhN4o1dDBAH6wWOnOE73fUHG3M?= =?us-ascii?Q?MeLHLjut+WQxUOwK4Vmcz5ZqD9/zFY9S8od0wZxbJv0lc5/rFglbuvknYixt?= =?us-ascii?Q?5esxXHl2R1Rafp5uU5mV+ZEbZgTsfabAL?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1579; 5:LbKdEHufrhoYvakab9LE2dKVmzxUrWSW9GtxKxpSsiW5NLc1rwzfTgj99q8jOi3EnLo3NWRQQlpk+sIXeaLiyUb9AHf7607dsM4c67hNmzbYzTF6ihvwPaGDnKIAjjuGoje0BZroJXmZs1eZngmuhw==; 24:KoT6I/9cmdyVR0WrjK6Q/ubj5BVtLgVqp5LzI5AIhCkXkePXTYnS3dwkYXdQ1saJJ3IHT3hoDY7q0sHmr+TQDdzg+s5uB3zJv17d+qXsQjM=; 20:Ni5VRnsfLH59+W+VV5oPZlJsHmelfXT14WRUo3XVcHMjSxdSPzLeyrMARzBM7n12/61fTV64APNgtQRnoHY0WQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2015 18:28:51.8780 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB1579 X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1289; 2:8rKa+wOFKSUt6J8NoSZv0GMye5MpS+/iHw+x6H5+ZCRRsI1o4stCTiqhy2TFVvFIlziQGwj656t6mHDSmvlJWl3V+6p3gLsBqj/AYlW2B0Zs9NIT46CEYH0aJuGDyDgBshii5GwQILc+94jQJgkvu4uXxsJFs3s2QHmgctoS/ts=; 3:fV2AjE3VORcgZvR4C4mgezXFXx0X9xhBizjqJku5B4eLxHmPkBXHE2YzL+B6puUppoFxxc6mN8X9YUH/+Nk1yYXBzmDuPGEIgUI/VKbCb6T+n0Ie/qSiAcVGQr6enbVmON8KB2O0S/k4fXtC8LBOCJEt4SXgV2M6Nrw2IvjUvrOArkM5lf/jDoLPMiF2qd9qgY/8GM33HJ5R3NhfieOd8kVyA5Hs1zR6+O2R8AFoOiE=; 25:IjwqpFIG6PC8mI5GinC5DvDO9a9GAbv844+reRL68oyIm8izD/39MbrOot4esdbciRZwb9fI4Tp1Qvf6RnO8nlcXbQIAgybUkqYsuniKqPHi5D1HlauxTYXBW8FGGBD/4Gqs2vznCzQ9KitfnTds06ufVXPnFLpsnmzV7LqAc3HOalL0kKZo6ETpn+2rF6uU/dNONpQ+HwFyuNhBRL/F9PiDXY9YZupTSHt+ICoQ6jNpOH/dK+J1Hmu5axjl/C1/18cY5b9VI8wjy+weAnfvGg==; 23:4vKGTWt3nWOnGziaZBKSa9oHLG74ApwFHNESawC5x8o4sGlkyxzAPY5Fz+vOc/MOh4/Ce2enO0BJXPQt4e81fhCAv9gtMCaPV07vwQOuAiMACdOB+lHPG05YLT/xQchr4aZPS7qZLAXTGdWGV9WuUrYIL95P4PFgi98FPtla+zh1Op/CmWuN+VzFoE8tyOKoUQANGq5NZ4w9Dd4GWbKJgIscZwLAxiqp8Eaw4iu4feo8i ho/osivzhcfRKSfzjPV X-OriginatorOrg: freescale.com Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Register only algorithms supported by CAAM hardware, using the CHA version and instantiation registers to identify hardware capabilities. Signed-off-by: Victoria Milhoan --- drivers/crypto/caam/caamalg.c | 68 ++++++++++++++++++++++++++++++++++++++---- drivers/crypto/caam/caamhash.c | 38 ++++++++++++++++++----- drivers/crypto/caam/caamrng.c | 6 +++- drivers/crypto/caam/regs.h | 16 ++++++++-- 4 files changed, 110 insertions(+), 18 deletions(-) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 3d1ca08..3361259 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -4371,8 +4371,10 @@ static int __init caam_algapi_init(void) struct device_node *dev_node; struct platform_device *pdev; struct device *ctrldev; - void *priv; + struct caam_drv_private *priv; int i = 0, err = 0; + u32 cha_vid, cha_inst, des_inst, aes_inst, md_inst; + unsigned int md_limit = SHA512_DIGEST_SIZE; bool registered = false; dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); @@ -4402,16 +4404,39 @@ static int __init caam_algapi_init(void) INIT_LIST_HEAD(&alg_list); - /* register crypto algorithms the device supports */ + /* + * Register crypto algorithms the device supports. + * First, detect presence and attributes of DES, AES, and MD blocks. + */ + cha_vid = rd_reg32(&priv->ctrl->perfmon.cha_id_ls); + cha_inst = rd_reg32(&priv->ctrl->perfmon.cha_num_ls); + des_inst = (cha_inst & CHA_ID_LS_DES_MASK) >> CHA_ID_LS_DES_SHIFT; + aes_inst = (cha_inst & CHA_ID_LS_AES_MASK) >> CHA_ID_LS_AES_SHIFT; + md_inst = (cha_inst & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT; + + /* If MD is present, limit digest size based on LP256 */ + if (md_inst && ((cha_vid & CHA_ID_LS_MD_MASK) == CHA_ID_LS_MD_LP256)) + md_limit = SHA256_DIGEST_SIZE; + for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { - /* TODO: check if h/w supports alg */ struct caam_crypto_alg *t_alg; + struct caam_alg_template *alg = driver_algs + i; + u32 alg_sel = alg->class1_alg_type & OP_ALG_ALGSEL_MASK; + + /* Skip DES algorithms if not supported by device */ + if (!des_inst && + ((alg_sel == OP_ALG_ALGSEL_3DES) || + (alg_sel == OP_ALG_ALGSEL_DES))) + continue; + + /* Skip AES algorithms if not supported by device */ + if (!aes_inst && (alg_sel == OP_ALG_ALGSEL_AES)) + continue; - t_alg = caam_alg_alloc(&driver_algs[i]); + t_alg = caam_alg_alloc(alg); if (IS_ERR(t_alg)) { err = PTR_ERR(t_alg); - pr_warn("%s alg allocation failed\n", - driver_algs[i].driver_name); + pr_warn("%s alg allocation failed\n", alg->driver_name); continue; } @@ -4429,6 +4454,37 @@ static int __init caam_algapi_init(void) for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) { struct caam_aead_alg *t_alg = driver_aeads + i; + u32 c1_alg_sel = t_alg->caam.class1_alg_type & + OP_ALG_ALGSEL_MASK; + u32 c2_alg_sel = t_alg->caam.class2_alg_type & + OP_ALG_ALGSEL_MASK; + u32 alg_aai = t_alg->caam.class1_alg_type & OP_ALG_AAI_MASK; + + /* Skip DES algorithms if not supported by device */ + if (!des_inst && + ((c1_alg_sel == OP_ALG_ALGSEL_3DES) || + (c1_alg_sel == OP_ALG_ALGSEL_DES))) + continue; + + /* Skip AES algorithms if not supported by device */ + if (!aes_inst && (c1_alg_sel == OP_ALG_ALGSEL_AES)) + continue; + + /* + * Check support for AES algorithms not available + * on LP devices. + */ + if ((cha_vid & CHA_ID_LS_AES_MASK) == CHA_ID_LS_AES_LP) + if (alg_aai == OP_ALG_AAI_GCM) + continue; + + /* + * Skip algorithms requiring message digests + * if MD or MD size is not supported by device. + */ + if (c2_alg_sel && + (!md_inst || (t_alg->aead.maxauthsize > md_limit))) + continue; caam_aead_alg_init(t_alg); diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index 16c03f8..bb0935a 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -1883,8 +1883,10 @@ static int __init caam_algapi_hash_init(void) struct device_node *dev_node; struct platform_device *pdev; struct device *ctrldev; - void *priv; int i = 0, err = 0; + struct caam_drv_private *priv; + unsigned int md_limit = SHA512_DIGEST_SIZE; + u32 cha_inst, cha_vid; dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); if (!dev_node) { @@ -1910,19 +1912,40 @@ static int __init caam_algapi_hash_init(void) if (!priv) return -ENODEV; + /* + * Register crypto algorithms the device supports. First, identify + * presence and attributes of MD block. + */ + cha_vid = rd_reg32(&priv->ctrl->perfmon.cha_id_ls); + cha_inst = rd_reg32(&priv->ctrl->perfmon.cha_num_ls); + + /* + * Skip registration of any hashing algorithms if MD block + * is not present. + */ + if (!((cha_inst & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT)) + return -ENODEV; + + /* Limit digest size based on LP256 */ + if ((cha_vid & CHA_ID_LS_MD_MASK) == CHA_ID_LS_MD_LP256) + md_limit = SHA256_DIGEST_SIZE; + INIT_LIST_HEAD(&hash_list); /* register crypto algorithms the device supports */ for (i = 0; i < ARRAY_SIZE(driver_hash); i++) { - /* TODO: check if h/w supports alg */ struct caam_hash_alg *t_alg; + struct caam_hash_template *alg = driver_hash + i; + + /* If MD size is not supported by device, skip registration */ + if (alg->template_ahash.halg.digestsize > md_limit) + continue; /* register hmac version */ - t_alg = caam_hash_alloc(&driver_hash[i], true); + t_alg = caam_hash_alloc(alg, true); if (IS_ERR(t_alg)) { err = PTR_ERR(t_alg); - pr_warn("%s alg allocation failed\n", - driver_hash[i].driver_name); + pr_warn("%s alg allocation failed\n", alg->driver_name); continue; } @@ -1935,11 +1958,10 @@ static int __init caam_algapi_hash_init(void) list_add_tail(&t_alg->entry, &hash_list); /* register unkeyed version */ - t_alg = caam_hash_alloc(&driver_hash[i], false); + t_alg = caam_hash_alloc(alg, false); if (IS_ERR(t_alg)) { err = PTR_ERR(t_alg); - pr_warn("%s alg allocation failed\n", - driver_hash[i].driver_name); + pr_warn("%s alg allocation failed\n", alg->driver_name); continue; } diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c index a1d21d5..345024c 100644 --- a/drivers/crypto/caam/caamrng.c +++ b/drivers/crypto/caam/caamrng.c @@ -315,7 +315,7 @@ static int __init caam_rng_init(void) struct device_node *dev_node; struct platform_device *pdev; struct device *ctrldev; - void *priv; + struct caam_drv_private *priv; int err; dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); @@ -342,6 +342,10 @@ static int __init caam_rng_init(void) if (!priv) return -ENODEV; + /* Check for an instantiated RNG before registration */ + if (!(rd_reg32(&priv->ctrl->perfmon.cha_num_ls) & CHA_ID_LS_RNG_MASK)) + return -ENODEV; + dev = caam_jr_alloc(); if (IS_ERR(dev)) { pr_err("Job Ring Device allocation for transform failed\n"); diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h index 3a2a788..d7c3579 100644 --- a/drivers/crypto/caam/regs.h +++ b/drivers/crypto/caam/regs.h @@ -156,18 +156,28 @@ struct jr_outentry { #define CHA_NUM_MS_DECONUM_SHIFT 24 #define CHA_NUM_MS_DECONUM_MASK (0xfull << CHA_NUM_MS_DECONUM_SHIFT) -/* CHA Version IDs */ +/* + * CHA version IDs / instantiation bitfields + * Defined for use with the cha_id fields in perfmon, but the same shift/mask + * selectors can be used to pull out the number of instantiated blocks within + * cha_num fields in perfmon because the locations are the same. + */ #define CHA_ID_LS_AES_SHIFT 0 -#define CHA_ID_LS_AES_MASK (0xfull << CHA_ID_LS_AES_SHIFT) +#define CHA_ID_LS_AES_MASK (0xfull << CHA_ID_LS_AES_SHIFT) +#define CHA_ID_LS_AES_LP (0x3ull << CHA_ID_LS_AES_SHIFT) +#define CHA_ID_LS_AES_HP (0x4ull << CHA_ID_LS_AES_SHIFT) #define CHA_ID_LS_DES_SHIFT 4 -#define CHA_ID_LS_DES_MASK (0xfull << CHA_ID_LS_DES_SHIFT) +#define CHA_ID_LS_DES_MASK (0xfull << CHA_ID_LS_DES_SHIFT) #define CHA_ID_LS_ARC4_SHIFT 8 #define CHA_ID_LS_ARC4_MASK (0xfull << CHA_ID_LS_ARC4_SHIFT) #define CHA_ID_LS_MD_SHIFT 12 #define CHA_ID_LS_MD_MASK (0xfull << CHA_ID_LS_MD_SHIFT) +#define CHA_ID_LS_MD_LP256 (0x0ull << CHA_ID_LS_MD_SHIFT) +#define CHA_ID_LS_MD_LP512 (0x1ull << CHA_ID_LS_MD_SHIFT) +#define CHA_ID_LS_MD_HP (0x2ull << CHA_ID_LS_MD_SHIFT) #define CHA_ID_LS_RNG_SHIFT 16 #define CHA_ID_LS_RNG_MASK (0xfull << CHA_ID_LS_RNG_SHIFT)