From patchwork Wed Mar 22 06:17:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meenakshi Aggarwal X-Patchwork-Id: 13183606 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7469BC6FD1F for ; Wed, 22 Mar 2023 06:17:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229942AbjCVGRv (ORCPT ); Wed, 22 Mar 2023 02:17:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229917AbjCVGRu (ORCPT ); Wed, 22 Mar 2023 02:17:50 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2064.outbound.protection.outlook.com [40.107.21.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E62EE5983E; Tue, 21 Mar 2023 23:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BaPEYDUAwa12pNVUxmAOQjxC3lNqRXs88nycmMu4Ro+/kLnnxRNXZVgfPK/5Y1Ecpa2xl3LUYCoQzXi8EgtoUTvwaU5OPeMbgsZxBMZKrEvLrUvm6QgS40imOI8j2jsJhdWoT2Q7W+kBX+EUjlVW5Pusm9kPSjU8OoRRj3rH6q9MbLT6p99o9RqsqGd9efr4/9YlPDy3tea2htlo/zoUFzXiLF6kpXzZy0T9IbGOq8hlwnrWcrRm14ms6WOIWEbq61E3zojfn+AWVUoLnJgwGXUWd77PFgZvviNfl+3JtRCXNbzQ8Zws7ETDtMXrYQgGGZmnEJkVdK8ZlndvJ//Dlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZHf6i1oVFlO5A2IoRAhx3CloxN4P1lpsHc6NKUct93g=; b=kbaqIGKZFLyFI2QmU2dSSdiYurFL2ZQDCNvs3/pgi9nZP2RlDIW1gbixk9g+w+3vdrN0rzHrgaKX1s0shq2oVPf+ZLofNyqFKdU3NLr5U2HxE5sqoLCA+7c/T2hbKCF1W7qhBB6D201Yle36zJj2POgruoNTZ6HR7C+v9WvlwAScIPzoojYx2L7rz/F1w3Vv/RA5eWcau+Gk1yKFvVxFaByWtUxO50dD/xf0M6lHELeGoKROcsBu6h91p9RMchFFQKIxPmq/DbEj7umrAoGxG+vgfKKL78b0utr14My3URkJuFFrt7GWv+qQeBXHou5h4m3D7oah0CID9WG9jGgFzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZHf6i1oVFlO5A2IoRAhx3CloxN4P1lpsHc6NKUct93g=; b=hI4g6BxGOxau48njpRBuWDJeeFI67Dm6cTrLuY0bS1tSsbz4HZ2tLZB4IfxMja1xMwya38SE9zleR5RGuuEtRvLPMRx6Zr7cfGAdUz1ssdh5OwErlIjtB3m2OgcT0pb9y5wpJPnRUamAXIhwL/wiJ1bpDHl0vNRQXvhdQZiJFUs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU0PR04MB9563.eurprd04.prod.outlook.com (2603:10a6:10:314::7) by DB8PR04MB7020.eurprd04.prod.outlook.com (2603:10a6:10:126::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Wed, 22 Mar 2023 06:17:45 +0000 Received: from DU0PR04MB9563.eurprd04.prod.outlook.com ([fe80::a518:512c:4af1:276e]) by DU0PR04MB9563.eurprd04.prod.outlook.com ([fe80::a518:512c:4af1:276e%6]) with mapi id 15.20.6178.037; Wed, 22 Mar 2023 06:17:45 +0000 From: meenakshi.aggarwal@nxp.com To: horia.geanta@nxp.com, V.sethi@nxp.com, pankaj.gupta@nxp.com, gaurav.jain@nxp.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Meenakshi Aggarwal , Varun Sethi Subject: [PATCH v2 1/2] crypto: caam - reduce page 0 regs access to minimum Date: Wed, 22 Mar 2023 07:17:15 +0100 Message-Id: <20230322061716.3195841-2-meenakshi.aggarwal@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230322061716.3195841-1-meenakshi.aggarwal@nxp.com> References: <20230302062055.1564514-3-meenakshi.aggarwal@nxp.com> <20230322061716.3195841-1-meenakshi.aggarwal@nxp.com> X-ClientProxiedBy: AM6PR04CA0042.eurprd04.prod.outlook.com (2603:10a6:20b:f0::19) To DU0PR04MB9563.eurprd04.prod.outlook.com (2603:10a6:10:314::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9563:EE_|DB8PR04MB7020:EE_ X-MS-Office365-Filtering-Correlation-Id: cae78a5d-f8eb-4dd3-8193-08db2a9d268f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9Egs40QQjbw8phhH++Dv8cs245EwMoP/82qz1UBZtonoShrzeIbl/hBChw12u+Ri/KTy3sWrBVLcNs7xgNs0F9gNuE4UKPyiQD320gC4j00HdJ1xCNd7SFo6jRoLvfnrHaJ91XHOQUMxeC5TqSNtXO1VweGe+P4dNN66Cf13PhXeD80dVd4+9BNL/m3DmVpZW0gt5ZwYSJUi5hosX1ACD2IXzJUdqbsjF1zVApGTNAjEQ1Uq/3/L4jDQXb/ES6avYAw0wvd/F0abZYEKNMlu1Ci4JBNs3f8EMI1Zcl+I7DxitvO+XVn210KETJn7N6SUi90mokvUFLXPw3Wn5jRkgUDB6Y4bDAENsvOmkOm1J0ywM85A35nlyOyltaSJkrCDRp06fsmIBu+NjWdffHSC3rDd3KKF00I+/rG/I3THbi6rBwTd06NbYxqMqGu7gnqW6Qo3lxIj9yycamM/NAEKrOJN2rrFDDfyyfPjIba3tTwGqu8C5U22wn9dtipMMvEyMNnJhkVEZLEWsweecw7YBgXD/92/TFeLMAT3ofjq5wnwutGrqhFKfUYevWiOjX29QsQlAXbEOVvGgsNVnNCPHA7I3R3+2M7VKK469bBGHaRfiGI3Tr0ev5RMwUcuCuYbMVylWEOij0TLkAC+f/E3CTym088fbk4q1z2CTsDMT/pUMZG9hB0f67Y+EqlYH5+SRJ0Xm/U5ffj2vv74Mof+lw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0PR04MB9563.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(376002)(136003)(366004)(39860400002)(396003)(346002)(451199018)(54906003)(6512007)(2616005)(83380400001)(478600001)(6486002)(26005)(186003)(6506007)(9686003)(1076003)(8936002)(6666004)(316002)(66556008)(52116002)(66476007)(86362001)(38350700002)(38100700002)(2906002)(5660300002)(30864003)(4326008)(66946007)(8676002)(36756003)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sWYkqmMA4DR0Wqt/rQ4zXJyPXDVwCykLMC58ViAc5RyLHPNhjl+CE8FfduG7nPYli07+LJ/rQBsMH3ySb4dQKzAv9wkl/tRKqU6yfBrOiVh3O2XfRrgYwH5brrHHYLBAebihZ8J/bdCpbWf72ScvzsDO6N47k3M3YkDz5MOxso/yzYpaLczGGrE5mE3gbvaAmB/uZnUZ3u7ZpMc0glYNM7SotY9jmT43DcDFp/gZJboafR0yP9dIDeGiiqkscDmvn5Az3FSuh3NMOiJiZW6VmVUehTVIpGNefVcDHMzw82qbuiIfXu1uwWFmgDAULR1NH6ds7nqdQ46yp1YRCK2UHstwBeTtlonisDwylmYoUOjsOjTu69oPaecFduvp8pQgq4MyMh7ossobfc2m0g8uIQQQXPXrPvxIAx59DXWf1xHhS7GN92Zg+2B343Xl/P/9yW0dttijhwsDM0yQhcpa97WIZXNTccx+QJ0zefvXJPBYfCSL7w1ov5aUZOaWJNqdl5Gh9WEqYsunVHCpVyz4/dMC6GIERoZZRPIbfLYBeCzc0xj4377x18TL2YRPAMvymADYig88y8gK5+OpjPOzjaGJvFgBg4fSHEWdilI+0h2vEhEcjAfcZS1cHNEgDxLenOQ4+r7WFe6rj4sY5H6x1ixs3R62Y5BMMYKyc7E8vDD/kG6J3wivFETdxruEMM8Hu3Jox1mU44l0Qm1cKSXcmBQSk/yVAS85tQWnZTN1x6UBR67LgxJu/Zc9dFKmcLO9NVs9wH2TeDuESag2LthdPd1R/CNfnSLOixW2CTxRceTeXssmp1i09d/+5uBQw+CP0lHW8c5Oa63D6FH3E9yczNVp0MVfMWsVIK+Mqj4UdsXQsj3edf+Pu44NGmk2pOPvzZOmikRcGh3IL3K/6iBQCPNJy7+Edrx2IbyhVxyU86wiiA3bVEj3X6PVTZjRtLTpd5ZyZ8j87CJ/tw2KKWusGoiDLWzZd7faQfJIxYNYCyxBEzJo1fg+OKdxhcneWVERoDr+nHnj4WbQvW0e/FguZi74rU+7HArI7/xfOZkqoW8iABTBJnpf37QgFNTXfLsAzsUKuvNlXe7rb+4uTl/H9DEP+jLct6IZMM1+QIA4M7UZp9sPyHN8kBoB040u6ZAAKBPu27W2iIsK0E3u9PBOg/rz6LtidnA2Q1M8t8TfPJwLsULbEwD04THXBYe54Qhvhje5nElqtC+ZM5PBPoNAS9sjpBBrjh1MKPUh3DMNQwzEFDA47PgBqsxSAOhdF9fzZVoE77331D9KuFHp/lDxA+kTso5yYiEnEdRX7KVZBNSvf5/S7DKTXeExEHVmPGfxEXs2tajg4XmFo6OmFyHSe7W0lmerQ5t05thPEltKg15F0Zag9+L/cE1unGvxdZkSR1ye0dUPy7HbtaiWB+ORjkouetZxk4eaZhGY4JfDtTN6BZRrLjnNdsBmaS3YqUWB4ZLh/YD7Anzj9oe2HNCyqJMUAYTB706CjfOUKcduQgOV0cKpgirUdU+c938rLOa1Icd2UCFL/XwNrv5PyoCkMHjDalEqZ4Pc2P0mhyU0f5DyzHTyHJ9NsH7HEmWIs2kl0pfJMIDdqT0jDJzaQHR30Q== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: cae78a5d-f8eb-4dd3-8193-08db2a9d268f X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9563.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2023 06:17:44.9477 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: beVHQXh3NHGGaVCUGMr9jyZ/vzzoNQmQJP2pgwvdHM/ZRJ3crayoE4bC5gwOuAQm5VM2yhVrCU+YKzQM4fOORxxKxjIYozb2wVrhf2qlYBo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7020 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Horia GeantA Use job ring register map, in place of controller register map to access page 0 registers, as access to the controller register map is not permitted. Signed-off-by: Horia GeantA Signed-off-by: Gaurav Jain Signed-off-by: Meenakshi Aggarwal Reviewed-by: Varun Sethi Reviewed-by: Gaurav Jain --- drivers/crypto/caam/caamalg.c | 21 ++++----- drivers/crypto/caam/caamhash.c | 10 +++-- drivers/crypto/caam/caampkc.c | 6 +-- drivers/crypto/caam/caamrng.c | 6 +-- drivers/crypto/caam/ctrl.c | 82 +++++++++++++++++++++------------- drivers/crypto/caam/debugfs.c | 9 ++-- drivers/crypto/caam/debugfs.h | 7 ++- 7 files changed, 83 insertions(+), 58 deletions(-) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 12b1c8346243..feb86013dbf6 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -3,7 +3,7 @@ * caam - Freescale FSL CAAM support for crypto API * * Copyright 2008-2011 Freescale Semiconductor, Inc. - * Copyright 2016-2019 NXP + * Copyright 2016-2019, 2023 NXP * * Based on talitos crypto API driver. * @@ -3542,13 +3542,14 @@ int caam_algapi_init(struct device *ctrldev) * First, detect presence and attributes of DES, AES, and MD blocks. */ if (priv->era < 10) { + struct caam_perfmon __iomem *perfmon = &priv->jr[0]->perfmon; u32 cha_vid, cha_inst, aes_rn; - cha_vid = rd_reg32(&priv->ctrl->perfmon.cha_id_ls); + cha_vid = rd_reg32(&perfmon->cha_id_ls); aes_vid = cha_vid & CHA_ID_LS_AES_MASK; md_vid = (cha_vid & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT; - cha_inst = rd_reg32(&priv->ctrl->perfmon.cha_num_ls); + cha_inst = rd_reg32(&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; @@ -3556,23 +3557,23 @@ int caam_algapi_init(struct device *ctrldev) ccha_inst = 0; ptha_inst = 0; - aes_rn = rd_reg32(&priv->ctrl->perfmon.cha_rev_ls) & - CHA_ID_LS_AES_MASK; + aes_rn = rd_reg32(&perfmon->cha_rev_ls) & CHA_ID_LS_AES_MASK; gcm_support = !(aes_vid == CHA_VER_VID_AES_LP && aes_rn < 8); } else { + struct version_regs __iomem *vreg = &priv->jr[0]->vreg; u32 aesa, mdha; - aesa = rd_reg32(&priv->ctrl->vreg.aesa); - mdha = rd_reg32(&priv->ctrl->vreg.mdha); + aesa = rd_reg32(&vreg->aesa); + mdha = rd_reg32(&vreg->mdha); aes_vid = (aesa & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT; md_vid = (mdha & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT; - des_inst = rd_reg32(&priv->ctrl->vreg.desa) & CHA_VER_NUM_MASK; + des_inst = rd_reg32(&vreg->desa) & CHA_VER_NUM_MASK; aes_inst = aesa & CHA_VER_NUM_MASK; md_inst = mdha & CHA_VER_NUM_MASK; - ccha_inst = rd_reg32(&priv->ctrl->vreg.ccha) & CHA_VER_NUM_MASK; - ptha_inst = rd_reg32(&priv->ctrl->vreg.ptha) & CHA_VER_NUM_MASK; + ccha_inst = rd_reg32(&vreg->ccha) & CHA_VER_NUM_MASK; + ptha_inst = rd_reg32(&vreg->ptha) & CHA_VER_NUM_MASK; gcm_support = aesa & CHA_VER_MISC_AES_GCM; } diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index 82d3c730a502..80deb003f0a5 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -3,7 +3,7 @@ * caam - Freescale FSL CAAM support for ahash functions of crypto API * * Copyright 2011 Freescale Semiconductor, Inc. - * Copyright 2018-2019 NXP + * Copyright 2018-2019, 2023 NXP * * Based on caamalg.c crypto API driver. * @@ -1956,12 +1956,14 @@ int caam_algapi_hash_init(struct device *ctrldev) * presence and attributes of MD block. */ if (priv->era < 10) { - md_vid = (rd_reg32(&priv->ctrl->perfmon.cha_id_ls) & + struct caam_perfmon __iomem *perfmon = &priv->jr[0]->perfmon; + + md_vid = (rd_reg32(&perfmon->cha_id_ls) & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT; - md_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) & + md_inst = (rd_reg32(&perfmon->cha_num_ls) & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT; } else { - u32 mdha = rd_reg32(&priv->ctrl->vreg.mdha); + u32 mdha = rd_reg32(&priv->jr[0]->vreg.mdha); md_vid = (mdha & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT; md_inst = mdha & CHA_VER_NUM_MASK; diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c index e40614fef39d..72afc249d42f 100644 --- a/drivers/crypto/caam/caampkc.c +++ b/drivers/crypto/caam/caampkc.c @@ -3,7 +3,7 @@ * caam - Freescale FSL CAAM support for Public Key Cryptography * * Copyright 2016 Freescale Semiconductor, Inc. - * Copyright 2018-2019 NXP + * Copyright 2018-2019, 2023 NXP * * There is no Shared Descriptor for PKC so that the Job Descriptor must carry * all the desired key parameters, input and output pointers. @@ -1168,10 +1168,10 @@ int caam_pkc_init(struct device *ctrldev) /* Determine public key hardware accelerator presence. */ if (priv->era < 10) { - pk_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) & + pk_inst = (rd_reg32(&priv->jr[0]->perfmon.cha_num_ls) & CHA_ID_LS_PK_MASK) >> CHA_ID_LS_PK_SHIFT; } else { - pkha = rd_reg32(&priv->ctrl->vreg.pkha); + pkha = rd_reg32(&priv->jr[0]->vreg.pkha); pk_inst = pkha & CHA_VER_NUM_MASK; /* diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c index 1fd8ff965006..50eb55da45c2 100644 --- a/drivers/crypto/caam/caamrng.c +++ b/drivers/crypto/caam/caamrng.c @@ -3,7 +3,7 @@ * caam - Freescale FSL CAAM support for hw_random * * Copyright 2011 Freescale Semiconductor, Inc. - * Copyright 2018-2019 NXP + * Copyright 2018-2019, 2023 NXP * * Based on caamalg.c crypto API driver. * @@ -227,10 +227,10 @@ int caam_rng_init(struct device *ctrldev) /* Check for an instantiated RNG before registration */ if (priv->era < 10) - rng_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) & + rng_inst = (rd_reg32(&priv->jr[0]->perfmon.cha_num_ls) & CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT; else - rng_inst = rd_reg32(&priv->ctrl->vreg.rng) & CHA_VER_NUM_MASK; + rng_inst = rd_reg32(&priv->jr[0]->vreg.rng) & CHA_VER_NUM_MASK; if (!rng_inst) return 0; diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index 6278afb951c3..ae07c1e5fd38 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -3,7 +3,7 @@ * Controller-level driver, kernel property detection, initialization * * Copyright 2008-2012 Freescale Semiconductor, Inc. - * Copyright 2018-2019 NXP + * Copyright 2018-2019, 2023 NXP */ #include @@ -395,7 +395,7 @@ static void kick_trng(struct platform_device *pdev, int ent_delay) RTMCTL_SAMP_MODE_RAW_ES_SC); } -static int caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl) +static int caam_get_era_from_hw(struct caam_perfmon __iomem *perfmon) { static const struct { u16 ip_id; @@ -421,12 +421,12 @@ static int caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl) u16 ip_id; int i; - ccbvid = rd_reg32(&ctrl->perfmon.ccb_id); + ccbvid = rd_reg32(&perfmon->ccb_id); era = (ccbvid & CCBVID_ERA_MASK) >> CCBVID_ERA_SHIFT; if (era) /* This is '0' prior to CAAM ERA-6 */ return era; - id_ms = rd_reg32(&ctrl->perfmon.caam_id_ms); + id_ms = rd_reg32(&perfmon->caam_id_ms); ip_id = (id_ms & SECVID_MS_IPID_MASK) >> SECVID_MS_IPID_SHIFT; maj_rev = (id_ms & SECVID_MS_MAJ_REV_MASK) >> SECVID_MS_MAJ_REV_SHIFT; @@ -444,9 +444,9 @@ static int caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl) * In case this property is not passed an attempt to retrieve the CAAM * era via register reads will be made. * - * @ctrl: controller region + * @perfmon: Performance Monitor Registers */ -static int caam_get_era(struct caam_ctrl __iomem *ctrl) +static int caam_get_era(struct caam_perfmon __iomem *perfmon) { struct device_node *caam_node; int ret; @@ -459,7 +459,7 @@ static int caam_get_era(struct caam_ctrl __iomem *ctrl) if (!ret) return prop; else - return caam_get_era_from_hw(ctrl); + return caam_get_era_from_hw(perfmon); } /* @@ -626,6 +626,7 @@ static int caam_probe(struct platform_device *pdev) struct device_node *nprop, *np; struct caam_ctrl __iomem *ctrl; struct caam_drv_private *ctrlpriv; + struct caam_perfmon __iomem *perfmon; struct dentry *dfs_root; u32 scfgr, comp_params; u8 rng_vid; @@ -665,9 +666,36 @@ static int caam_probe(struct platform_device *pdev) return ret; } - caam_little_end = !(bool)(rd_reg32(&ctrl->perfmon.status) & + ring = 0; + for_each_available_child_of_node(nprop, np) + if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") || + of_device_is_compatible(np, "fsl,sec4.0-job-ring")) { + u32 reg; + + if (of_property_read_u32_index(np, "reg", 0, ®)) { + dev_err(dev, "%s read reg property error\n", + np->full_name); + continue; + } + + ctrlpriv->jr[ring] = (struct caam_job_ring __iomem __force *) + ((__force uint8_t *)ctrl + reg); + + ctrlpriv->total_jobrs++; + ring++; + } + + /* + * Wherever possible, instead of accessing registers from the global page, + * use the alias registers in the first (cf. DT nodes order) + * job ring's page. + */ + perfmon = ring ? (struct caam_perfmon __iomem *)&ctrlpriv->jr[0]->perfmon : + (struct caam_perfmon __iomem *)&ctrl->perfmon; + + caam_little_end = !(bool)(rd_reg32(&perfmon->status) & (CSTA_PLEND | CSTA_ALT_PLEND)); - comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ms); + comp_params = rd_reg32(&perfmon->comp_parms_ms); if (comp_params & CTPR_MS_PS && rd_reg32(&ctrl->mcr) & MCFGR_LONG_PTR) caam_ptr_sz = sizeof(u64); else @@ -778,7 +806,7 @@ static int caam_probe(struct platform_device *pdev) return ret; } - ctrlpriv->era = caam_get_era(ctrl); + ctrlpriv->era = caam_get_era(perfmon); ctrlpriv->domain = iommu_get_domain_for_dev(dev); dfs_root = debugfs_create_dir(dev_name(dev), NULL); @@ -789,7 +817,7 @@ static int caam_probe(struct platform_device *pdev) return ret; } - caam_debugfs_init(ctrlpriv, dfs_root); + caam_debugfs_init(ctrlpriv, perfmon, dfs_root); /* Check to see if (DPAA 1.x) QI present. If so, enable */ if (ctrlpriv->qi_present && !caam_dpaa2) { @@ -808,26 +836,13 @@ static int caam_probe(struct platform_device *pdev) #endif } - ring = 0; - for_each_available_child_of_node(nprop, np) - if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") || - of_device_is_compatible(np, "fsl,sec4.0-job-ring")) { - ctrlpriv->jr[ring] = (struct caam_job_ring __iomem __force *) - ((__force uint8_t *)ctrl + - (ring + JR_BLOCK_NUMBER) * - BLOCK_OFFSET - ); - ctrlpriv->total_jobrs++; - ring++; - } - /* If no QI and no rings specified, quit and go home */ if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) { dev_err(dev, "no queues configured, terminating\n"); return -ENOMEM; } - comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ls); + comp_params = rd_reg32(&perfmon->comp_parms_ls); ctrlpriv->blob_present = !!(comp_params & CTPR_LS_BLOB); /* @@ -836,15 +851,20 @@ static int caam_probe(struct platform_device *pdev) * check both here. */ if (ctrlpriv->era < 10) { - rng_vid = (rd_reg32(&ctrl->perfmon.cha_id_ls) & + rng_vid = (rd_reg32(&perfmon->cha_id_ls) & CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT; ctrlpriv->blob_present = ctrlpriv->blob_present && - (rd_reg32(&ctrl->perfmon.cha_num_ls) & CHA_ID_LS_AES_MASK); + (rd_reg32(&perfmon->cha_num_ls) & CHA_ID_LS_AES_MASK); } else { - rng_vid = (rd_reg32(&ctrl->vreg.rng) & CHA_VER_VID_MASK) >> + struct version_regs __iomem *vreg; + + vreg = ring ? (struct version_regs __iomem *)&ctrlpriv->jr[0]->vreg : + (struct version_regs __iomem *)&ctrl->vreg; + + rng_vid = (rd_reg32(&vreg->rng) & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT; ctrlpriv->blob_present = ctrlpriv->blob_present && - (rd_reg32(&ctrl->vreg.aesa) & CHA_VER_MISC_AES_NUM_MASK); + (rd_reg32(&vreg->aesa) & CHA_VER_MISC_AES_NUM_MASK); } /* @@ -925,8 +945,8 @@ static int caam_probe(struct platform_device *pdev) /* NOTE: RTIC detection ought to go here, around Si time */ - caam_id = (u64)rd_reg32(&ctrl->perfmon.caam_id_ms) << 32 | - (u64)rd_reg32(&ctrl->perfmon.caam_id_ls); + caam_id = (u64)rd_reg32(&perfmon->caam_id_ms) << 32 | + (u64)rd_reg32(&perfmon->caam_id_ls); /* Report "alive" for developer to see */ dev_info(dev, "device ID = 0x%016llx (Era %d)\n", caam_id, diff --git a/drivers/crypto/caam/debugfs.c b/drivers/crypto/caam/debugfs.c index 806bb20d2aa1..798ba989a8a0 100644 --- a/drivers/crypto/caam/debugfs.c +++ b/drivers/crypto/caam/debugfs.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) -/* Copyright 2019 NXP */ +/* Copyright 2019, 2023 NXP */ #include #include "compat.h" @@ -42,16 +42,15 @@ void caam_debugfs_qi_init(struct caam_drv_private *ctrlpriv) } #endif -void caam_debugfs_init(struct caam_drv_private *ctrlpriv, struct dentry *root) +void caam_debugfs_init(struct caam_drv_private *ctrlpriv, + struct caam_perfmon __iomem *perfmon, + struct dentry *root) { - struct caam_perfmon *perfmon; - /* * FIXME: needs better naming distinction, as some amalgamation of * "caam" and nprop->full_name. The OF name isn't distinctive, * but does separate instances */ - perfmon = (struct caam_perfmon __force *)&ctrlpriv->ctrl->perfmon; ctrlpriv->ctl = debugfs_create_dir("ctl", root); diff --git a/drivers/crypto/caam/debugfs.h b/drivers/crypto/caam/debugfs.h index 661d768acdbf..78e3c6b957c2 100644 --- a/drivers/crypto/caam/debugfs.h +++ b/drivers/crypto/caam/debugfs.h @@ -1,16 +1,19 @@ /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ -/* Copyright 2019 NXP */ +/* Copyright 2019, 2023 NXP */ #ifndef CAAM_DEBUGFS_H #define CAAM_DEBUGFS_H struct dentry; struct caam_drv_private; +struct caam_perfmon; #ifdef CONFIG_DEBUG_FS -void caam_debugfs_init(struct caam_drv_private *ctrlpriv, struct dentry *root); +void caam_debugfs_init(struct caam_drv_private *ctrlpriv, + struct caam_perfmon __iomem *perfmon, struct dentry *root); #else static inline void caam_debugfs_init(struct caam_drv_private *ctrlpriv, + struct caam_perfmon __iomem *perfmon, struct dentry *root) {} #endif From patchwork Wed Mar 22 06:17:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meenakshi Aggarwal X-Patchwork-Id: 13183607 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB002C6FD1F for ; Wed, 22 Mar 2023 06:18:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229819AbjCVGSE (ORCPT ); Wed, 22 Mar 2023 02:18:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229968AbjCVGSD (ORCPT ); Wed, 22 Mar 2023 02:18:03 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2040.outbound.protection.outlook.com [40.107.21.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C64C5B5D5; Tue, 21 Mar 2023 23:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YqnvWurwnBREeVQYuNq1HkvJykgQwpn9GntP131VSBs8c/3Z96yI9b3IsEe9but8EjZ1CD/k2uwx83mO7deYWLlULmJbTPeD0KfchW/0dq0shenY+qiJeGTvWWP7pOEbSubYy/q/m3Y2byKpiPUAjY5JxYHGgFj5HOBV+PljHiZ1UqP9MajGIG8pRM5PCxnpkVufMDtECvcvatTgpJ+BqE8Z2IWjoagvfaO6aY5Mn1e5HCR4HincVe2e6qT9C2/2lx/wgEeU3tMEzXq/HYjbos3Yfcf27W9dpSo3yn1hjKsD+o+EBK1vlfMQ4wP6VBi1cjXcHKDXE+5Z/RJ/FngxNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NF1bKVyeEcuJi/jVR47Sr22EeG9tC4DjwTNu69dU1/E=; b=j5WaOq2g7hgkDjv6fYvLKF31ktOl/nmWx13iFDqA/Qs2e2DIl5DwGOf5FOyS2cMQUo+X2KArN+qKxfvEeb0rfT10YIDkfAbmQP0chbtHUohkTF78WOHp175fYMJsJV+WPaJwFheLuY2eG+7T/8qj8bfOFWlnLpOKPuasrOa+hEDDIK9kA/IKn4OyDp9zrFuazAM5ujMyD6VUiDGFqvV3jxwNuNK9cgntDoWP9wzn+dMICM4YeQyUSVForiyFSEXK8h1JFaf2Wr2Y6vsflRFVLjZid/1DqkAdi05f9LECey1nlhvoHS9dTIHRMsnS8vKQlUiE+mX1+QIwEVTx5zGckA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NF1bKVyeEcuJi/jVR47Sr22EeG9tC4DjwTNu69dU1/E=; b=dw8wlNOB9ngSo7hVWEU3iK4St/IyNX7dzOUY5nXrVBr8hWAEZogRBA0YNYZqlp6mGLg7N2l2YESSGguHq35azNlcD2MrzLYq6B9hm1/8cjDF6N90r7wN6vLJ93lobKC+UwtoUbi/y0wVPmD37icAMXCOn+9HRBaKKDkckG/6iXA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU0PR04MB9563.eurprd04.prod.outlook.com (2603:10a6:10:314::7) by DB8PR04MB7020.eurprd04.prod.outlook.com (2603:10a6:10:126::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Wed, 22 Mar 2023 06:17:52 +0000 Received: from DU0PR04MB9563.eurprd04.prod.outlook.com ([fe80::a518:512c:4af1:276e]) by DU0PR04MB9563.eurprd04.prod.outlook.com ([fe80::a518:512c:4af1:276e%6]) with mapi id 15.20.6178.037; Wed, 22 Mar 2023 06:17:52 +0000 From: meenakshi.aggarwal@nxp.com To: horia.geanta@nxp.com, V.sethi@nxp.com, pankaj.gupta@nxp.com, gaurav.jain@nxp.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Meenakshi Aggarwal Subject: [PATCH v2 2/2] crypto: caam - OP-TEE firmware support Date: Wed, 22 Mar 2023 07:17:16 +0100 Message-Id: <20230322061716.3195841-3-meenakshi.aggarwal@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230322061716.3195841-1-meenakshi.aggarwal@nxp.com> References: <20230302062055.1564514-3-meenakshi.aggarwal@nxp.com> <20230322061716.3195841-1-meenakshi.aggarwal@nxp.com> X-ClientProxiedBy: AM6PR04CA0042.eurprd04.prod.outlook.com (2603:10a6:20b:f0::19) To DU0PR04MB9563.eurprd04.prod.outlook.com (2603:10a6:10:314::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9563:EE_|DB8PR04MB7020:EE_ X-MS-Office365-Filtering-Correlation-Id: 341aa3d6-10b3-4c54-35a9-08db2a9d2abc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8nBtsgSkSd5xgBQxK/nkAoPGHweJKTRC49g7LkBss1B3cJJaqG4RTGJEkKN3jlm8RJagDxD/r8wO9rchB6exJHaKtCN7ptXOPKNdK0U7SVLGGKljbiJyvc91GZ33vIGpe0LCcLW7L6fI7mh8YuKbNgEmIEc5ZyWVks6iflgTi6/AATIFfdk2n+V8Tu06TxQqpGOBxFzMteuDWn/xs/YuNiXt0g7DRn1JM6XkVEzA3Ifj7Le45dfovFmzWH2Lf1O1ONJY3BoauYVmC7kOlYn2YWFZSKNy770Hm7JPAlPdox2W049I1ljYSK+nr0gszuK9NiU0clRFg7FXQdXk7A/TvqIK3Yjj3NamWPl8ZJEBAVT3fWFXxQI/5QC/YSbfA91ggxmrsAz+wsikiBgB0cgxArj4AV34mUa0XyNrtea8NU0ULnvykrqFESYO2WpOd5aQ2OfOHLHiBfeakyLf9jr8zaG5YGdpWzblRJfsuLfxXbTKmchPzgu8neX6c9y/VLDGTrU7n3q8MkWUG3+k1nBL5VTM6jxQHULY7VEkv07T29RdHtcw4Z0LHmc3+f/HGPm5ctVMUzYlrAlbmaruwdzz/7QjkoIwMtTp16A2y6CJ8G8w9Qpo6iYbfPgVCTDO5O1X3or/RL+I8SIZxT1gRfw2HSQPLvFCGroDW3lLa7H6Ch59GqXTDfHFwefi4WDOIuYgSX0Cu4IrV8U42rtjraVv2nqf+NRDFcL/zxp+JPbb+dY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0PR04MB9563.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(376002)(136003)(366004)(39860400002)(396003)(346002)(451199018)(6512007)(2616005)(83380400001)(478600001)(6486002)(26005)(186003)(6506007)(9686003)(1076003)(8936002)(6666004)(316002)(66556008)(52116002)(66476007)(86362001)(38350700002)(38100700002)(2906002)(5660300002)(4326008)(66946007)(8676002)(36756003)(41300700001)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aQxd6U+WUoWqeB1AVwMjYs4H0QijfeOwrBeEYzpfaO2iaALnwgo1j4Ku8vSOg4mXd4gyO71MKlEpny3+INhbYu4t2oIjWkGejyCyS1H43/819JP0o6FfZayryRnyj2m0pusu5e073D/nFPh5yQpM5fTzCexl0OEW7j+0ubwM6dvjNB+FBgy0pJseN8wFnhWZ8vm3ZQFNUH0F1hFfn9944SNpCkzTAwdSTt9/gdo2C3ZdIGOpOrGL/Q3A5pgI+dKS2d+IywmpsUC1HJR1qjq3nBmhI3VTlW2oTDb/3F86qv+TSEW+9nPey0/JgfZTCtPQNTDfZtvXcvRVzdm/SqiEgWSM7OX7e1hfvfQThS13E2JbWIYI0uVLNzk6ZJBAQDGevVofvH2l2EsBFmyjVLDCm/R3kCi+fE2588rQhajJbq4dgOBFix26DYqDL4ElQTwzRsL5lYgWrBIsIyLuPNVQreCmcjZH/6P+GOL87HREaKV1o/DJBpWOHLe8TqM905KLdf8gndHR1prVlLOo5qB+k0O8L50M83sL52+pXnFg+LAAUUxXoSRWlscWuZIgptkmy7kxRuzfty8nImY/EfLHGSqnohVNPeaus6WZ1iIsqFDxOmnfkmd/MLMKtXBxwKlV/W0ezpLXoAqxQi6KiQTTsL8HT2yJOPlUSCoaSXv8TzNRm8leAgWlk+pWUiHFlsnauG6LMV/wl+o9TJCE4TJGMmpffufmRaTmEWUzPZVzHTc9xRE6U3kR1tsIpkCxsGCbgwCy5BTWcmu0m2rBpSehWtO6M7MPaOK/rgnCDbZJlGiPV9f9KaLbyqEhlwpLqADAbUVs9/r+5FiAefs9XGhujxGGGDWdUIgXzVYQqdijM0RC+5mbcHe2YbJIh2y/PVOkzvVNuRTMHXooURMSOOh6vCI5TBAeXRAkbIMkPyc4V7fOYJxT7drorme3jbfPPGMPxa8iHoz2MPwH9pTWb2B+7DJ9fi1KXkduDjtLrw+xJLjCXGXtqvu2wrgsiCzunYiwzRVTep0aNSqgtWQMiqSmXqByKDLUOPq8WXWnG2Mjr44xiqNxvx1F97Fq9s/6YVJ+8az3JV6b1Y82ENRT1ys0W+7FXc+/S9IjE8EICN69g8aLkIMoxqiFUW//++79COApvR7s6gfDFnQxtlUmYJBEhzR3HEsshF7qpjJ4utE0/KPboUZBP2itWH+Z2ZltwZd9BXyJyAMArW8axZgSA7tdJalSUrLBG85y+CPDn8iPUp8oSUsN3hhVR1CIDnUXPD8Axgce5WjplmChfPbCguZoHSAR45HOZZgKNvl5dadQdNnC9Ta7i1sKOIjk1/jBgkf5os/lLoHmR5kkbPbY6mF+xS7xAG3tF8p0uv9lv7jG68OAKf936vucf3QpopXRvViGb2bQiQfxcn5HoZ/4fYXRwMZMoJo1HGApFGhgbkec7/9d9Y9m3WNA0ggSc9fZlSm9wZ2m47RmUXVYrIEqYMpqvZCwiUSKr64VdAEZMlZhD/6rInXmtg+InqbI/uZY//yBlniS/hxpLri4wySTJ71eWyTpkqs6+dk12Pf0DkAGuZ4yzhDWXrSzJJu8SAQ8vrvWuLtqZynBbq2ZkWSEB4X+fQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 341aa3d6-10b3-4c54-35a9-08db2a9d2abc X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9563.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2023 06:17:52.1078 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LT9d2zTkCXtjKBKf+gMFskFepjlPWfXx8AVXyDk/rHNiE81r8d6oyM5mij7LJglxF5F5OP2+I6Z0dwqvuTL2vKnBf7aLC+G9Hwc8P7sWZ+w= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7020 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Horia GeantA caam driver needs to be aware of OP-TEE f/w presence, since some things are done differently: 1. there is no access to controller's register page (note however that some registers are aliased in job rings' register pages) 2 Due to this, MCFGR[PS] cannot be read and driver assumes MCFGR[PS] = b'0 - engine using 32-bit address pointers. This is in sync with the fact that: -all i.MX SoCs currently use MCFGR[PS] = b'0 -only i.MX OP-TEE use cases don't allow access to controller register page Signed-off-by: Horia GeantA Signed-off-by: Meenakshi Aggarwal --- drivers/crypto/caam/ctrl.c | 23 ++++++++++++++++++++++- drivers/crypto/caam/debugfs.c | 3 +++ drivers/crypto/caam/intern.h | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index ae07c1e5fd38..d96c81540957 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -633,6 +633,7 @@ static int caam_probe(struct platform_device *pdev) int pg_size; int BLOCK_OFFSET = 0; bool pr_support = false; + bool reg_access = true; ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL); if (!ctrlpriv) @@ -646,6 +647,17 @@ static int caam_probe(struct platform_device *pdev) caam_imx = (bool)imx_soc_match; if (imx_soc_match) { + /* + * Until Layerscape and i.MX OP-TEE get in sync, + * only i.MX OP-TEE use cases disallow access to + * caam page 0 (controller) registers. + */ + np = of_find_compatible_node(NULL, NULL, "linaro,optee-tz"); + ctrlpriv->optee_en = !!np; + of_node_put(np); + + reg_access = ctrlpriv->optee_en; + if (!imx_soc_match->data) { dev_err(dev, "No clock data provided for i.MX SoC"); return -EINVAL; @@ -696,7 +708,8 @@ static int caam_probe(struct platform_device *pdev) caam_little_end = !(bool)(rd_reg32(&perfmon->status) & (CSTA_PLEND | CSTA_ALT_PLEND)); comp_params = rd_reg32(&perfmon->comp_parms_ms); - if (comp_params & CTPR_MS_PS && rd_reg32(&ctrl->mcr) & MCFGR_LONG_PTR) + if (reg_access && comp_params & CTPR_MS_PS && + rd_reg32(&ctrl->mcr) & MCFGR_LONG_PTR) caam_ptr_sz = sizeof(u64); else caam_ptr_sz = sizeof(u32); @@ -761,6 +774,9 @@ static int caam_probe(struct platform_device *pdev) } #endif + if (!reg_access) + goto set_dma_mask; + /* * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel, * long pointers in master configuration register. @@ -800,6 +816,7 @@ static int caam_probe(struct platform_device *pdev) JRSTART_JR1_START | JRSTART_JR2_START | JRSTART_JR3_START); +set_dma_mask: ret = dma_set_mask_and_coherent(dev, caam_get_dma_mask(dev)); if (ret) { dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", ret); @@ -842,6 +859,9 @@ static int caam_probe(struct platform_device *pdev) return -ENOMEM; } + if (!reg_access) + goto report_live; + comp_params = rd_reg32(&perfmon->comp_parms_ls); ctrlpriv->blob_present = !!(comp_params & CTPR_LS_BLOB); @@ -943,6 +963,7 @@ static int caam_probe(struct platform_device *pdev) clrsetbits_32(&ctrl->scfgr, 0, SCFGR_RDBENABLE); } +report_live: /* NOTE: RTIC detection ought to go here, around Si time */ caam_id = (u64)rd_reg32(&perfmon->caam_id_ms) << 32 | diff --git a/drivers/crypto/caam/debugfs.c b/drivers/crypto/caam/debugfs.c index 798ba989a8a0..cec93498836d 100644 --- a/drivers/crypto/caam/debugfs.c +++ b/drivers/crypto/caam/debugfs.c @@ -77,6 +77,9 @@ void caam_debugfs_init(struct caam_drv_private *ctrlpriv, debugfs_create_file("fault_status", 0444, ctrlpriv->ctl, &perfmon->status, &caam_fops_u32_ro); + if (ctrlpriv->optee_en) + return; + /* Internal covering keys (useful in non-secure mode only) */ ctrlpriv->ctl_kek_wrap.data = (__force void *)&ctrlpriv->ctrl->kek[0]; ctrlpriv->ctl_kek_wrap.size = KEK_KEY_SIZE * sizeof(u32); diff --git a/drivers/crypto/caam/intern.h b/drivers/crypto/caam/intern.h index 572cf66c887a..86ed1b91c22d 100644 --- a/drivers/crypto/caam/intern.h +++ b/drivers/crypto/caam/intern.h @@ -94,6 +94,7 @@ struct caam_drv_private { u8 qi_present; /* Nonzero if QI present in device */ u8 blob_present; /* Nonzero if BLOB support present in device */ u8 mc_en; /* Nonzero if MC f/w is active */ + u8 optee_en; /* Nonzero if OP-TEE f/w is active */ int secvio_irq; /* Security violation interrupt number */ int virt_en; /* Virtualization enabled in CAAM */ int era; /* CAAM Era (internal HW revision) */