From patchwork Thu Jul 30 03:58:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Milhoan X-Patchwork-Id: 6898051 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 53CD2C05AC for ; Thu, 30 Jul 2015 03:58:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 67D32204D8 for ; Thu, 30 Jul 2015 03:58:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 62769205B4 for ; Thu, 30 Jul 2015 03:58:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752505AbbG3D6i (ORCPT ); Wed, 29 Jul 2015 23:58:38 -0400 Received: from mail-bl2on0130.outbound.protection.outlook.com ([65.55.169.130]:47648 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752703AbbG3D6g (ORCPT ); Wed, 29 Jul 2015 23:58:36 -0400 Received: from BN3PR0301CA0039.namprd03.prod.outlook.com (10.160.180.177) by SN1PR0301MB1581.namprd03.prod.outlook.com (10.162.130.15) with Microsoft SMTP Server (TLS) id 15.1.225.19; Thu, 30 Jul 2015 03:58:34 +0000 Received: from BY2FFO11FD022.protection.gbl (2a01:111:f400:7c0c::124) by BN3PR0301CA0039.outlook.office365.com (2a01:111:e400:4000::49) with Microsoft SMTP Server (TLS) id 15.1.225.19 via Frontend Transport; Thu, 30 Jul 2015 03:58:33 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; arm.linux.org.uk; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD022.mail.protection.outlook.com (10.1.15.211) with Microsoft SMTP Server (TLS) id 15.1.231.11 via Frontend Transport; Thu, 30 Jul 2015 03:58:33 +0000 Received: from stc-hedley.am.freescale.net (stc-hedley.am.freescale.net [10.67.70.12]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t6U3wUba025418; Wed, 29 Jul 2015 20:58:32 -0700 From: Victoria Milhoan To: CC: , , , , , Subject: [PATCH 01/12] crypto: caam - Add cache coherency support Date: Wed, 29 Jul 2015 20:58:18 -0700 Message-ID: <1438228709-27650-2-git-send-email-vicki.milhoan@freescale.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438228709-27650-1-git-send-email-vicki.milhoan@freescale.com> References: <1438228709-27650-1-git-send-email-vicki.milhoan@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD022; 1:ScFXQDD6n6ooPg1NGJO1cboytmZatyS6OuttykvkpF5wEztHgXJfd+BVgRZXkOJhGaNk2h/IA6s4M4rC2Llm34AUepOJSmGb1hKY4+gl82aaZeehkGhsszAVeXcvUVpS/eIj46wqIVzXfzMZU5NkMpY3CSVaUKj/+ZEZA9spG8YoJWCUm22mFeMUL+ouu8hmOFaNlYF6gGkBcSiEVqcx5xLhiymy5ZOaMvtUyIqGlDM5BIs6Adgv4wCS4EwJUi147bebqD0Pa4J5y/fyu9qC4yYLVfLS6YQILfdr3rdzipaFi+2k50JceoEarQgA2Dfz/sjsaHLulcFT4DvALKGA5w== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(199003)(189002)(33646002)(48376002)(6806004)(2351001)(229853001)(106466001)(36756003)(5001960100002)(19580405001)(46102003)(110136002)(189998001)(92566002)(50226001)(105606002)(104016003)(50466002)(76176999)(77156002)(85426001)(77096005)(62966003)(86362001)(19580395003)(50986999)(47776003)(2950100001)(87936001); DIR:OUT; SFP:1102; SCL:1; SRVR:SN1PR0301MB1581; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB1581; 2:p0NHqyWseRViAmNu2Q9cYgaNgsdHPEIjm3yBDfN4tVbDfTSgtkl2AQPInc8ap5eIZxxD9rzf8rKXJ7n/w6BDb9Bl7R/GrJqiYy3K7QbwIVUnmCMesds7kHOTavv+56PUyjtNCEZm5frUhq6FmsnotqmFiIHvfpRUEBNNEWQvz5I=; 3:/J8Y1x4cvub71iF6oJb/T/AHENdRRJk8Z5Z2f4bRNrdwEAUtzBpeHEL7++ejbnTQh9eSPcGx2JSe9JeA7NxrfryzxFBZ/ADdsOGDp70to3GccDVM69IT5ejZKD1fle1R8UZWP4/TXyRp+e47r2xtveuAg5f4hGkNvC3CP9xghydmKla4vh2BSJNNA2fouIvGlfj6nCwVfqdiMvjr974bMKM/atLm94fPQaG0bydXSHU=; 25:PRvCPOQPj3TPzUZkPUOA+cehR1OI/Tb2kbCVnU4spJ39VRsL4cj3dnBQzmLE/8eR4dwrmlOOfU+GCkMpzYjTdPFViAsyGT2McXpTvPFV2XE9ldL8i35U53YWlz9rwgg9KLYPdBHL6Re6xkrsS4L3efESn/jEgpoRiTDx+VbV7UQRhDw3U+PdqNsv7f8rPsbPwDqju6qIGcRvLTbo3nUBQ5aTN7Z8dCOEajSyLYj2iLGp1XmdLG0tp1+aAsxYJSpYRiA3VvIquEqxaMbAsxZj+Q== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0301MB1581; X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB1581; 20:3wS3sCMaAJLAVWS3QmAfiN/nOP0LviAN3prBo8oumFzWkTOCiZvgLa07gBj7jkKylGUSgstozAGmvNQZlzmC7iCXOZ66x9695b8VqjoJPvy4DOtnGfwz6uWNclvjzc+8zjYjwzD7Higmz6g6kxwxfRxG7WprRqd+qurpi6kkJ+13YWqqlbAoq7plaGvGp6T/T2B29hoCaztA5Hs0M1kHT148HT4EiKC7up6AQKGAoj6dB3NMYJfVA+Mi0ro1IbTWcwgGrgOw4RCqdQ8O6xSvWYg3fT4oveM6sAl9m3vhPIhhQIjproQCDg5WZPKwca4nD0Urvz2XpsHpoj7glKJYUTlJq7tB4m8K0hqmF7cp8jc=; 4:iLW2uMlnryc3r2cPIddDTNate3juxjx6mnFlMlHRhKYL7Erih0QN3Xz+iuywV9K1Qx7GTqmzaZnEOV5gyabqdtZCWijXdb76aXpgtXcKzw04/1vyJHLrGyurNhpFhng4npATIvDM/kDLZ6772BqA7ofZIBW6rjZNbPB/J8okC3ALR1DWCy90EMyfEmI4qQ/SNhQtoXa1OFQSN7JOR/4cN3d6OqAz+UuY4jHD4FBxKfY070FaDcn4Hmk/sWE2Fr9PqNYe7VXEceaKFWum04r730revuHnnu/OciPGTleIF3U= SN1PR0301MB1581: X-MS-Exchange-Organization-RulesExecuted 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:SN1PR0301MB1581; BCL:0; PCL:0; RULEID:; SRVR:SN1PR0301MB1581; X-Forefront-PRVS: 06530126A4 X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB1581; 23:6LEi4eIMqCxyHmgjrNbElH5QOxbiTdS6YshLtch6601XbOHSaqrIRMXCUKvWL+REGb0DXqZDziPDWXzTkDoLxKw/xJJwXHtGDgkB305vpT6UxBGD0lovXVV1m3r04BSlaucEtKE7GfSoDeZrcSjbp1x1qY2pLxj+tXUBslRSrITm6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in97ua0iiiph2goRs1/LJXY2U9yahetn7j0wXQ== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2015 03:58:33.3893 (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.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0301MB1581 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Freescale i.MX6 ARM platforms do not support hardware cache coherency. This patch adds cache coherency support to the CAAM driver. Signed-off-by: Victoria Milhoan --- drivers/crypto/caam/caamhash.c | 2 +- drivers/crypto/caam/caamrng.c | 4 ++++ drivers/crypto/caam/jr.c | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index dae1e80..9622a81 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -127,7 +127,7 @@ struct caam_hash_state { int buflen_0; u8 buf_1[CAAM_MAX_HASH_BLOCK_SIZE] ____cacheline_aligned; int buflen_1; - u8 caam_ctx[MAX_CTX_LEN]; + u8 caam_ctx[MAX_CTX_LEN] ____cacheline_aligned; int (*update)(struct ahash_request *req); int (*final)(struct ahash_request *req); int (*finup)(struct ahash_request *req); diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c index 5095337..a1d21d5 100644 --- a/drivers/crypto/caam/caamrng.c +++ b/drivers/crypto/caam/caamrng.c @@ -108,6 +108,10 @@ static void rng_done(struct device *jrdev, u32 *desc, u32 err, void *context) atomic_set(&bd->empty, BUF_NOT_EMPTY); complete(&bd->filled); + + /* Buffer refilled, invalidate cache */ + dma_sync_single_for_cpu(jrdev, bd->addr, RN_BUF_SIZE, DMA_FROM_DEVICE); + #ifdef DEBUG print_hex_dump(KERN_ERR, "rng refreshed buf@: ", DUMP_PREFIX_ADDRESS, 16, 4, bd->buf, RN_BUF_SIZE, 1); diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index b8b5d47..b7ec1ad 100644 --- a/drivers/crypto/caam/jr.c +++ b/drivers/crypto/caam/jr.c @@ -202,6 +202,13 @@ static void caam_jr_dequeue(unsigned long devarg) userdesc = jrp->entinfo[sw_idx].desc_addr_virt; userstatus = jrp->outring[hw_idx].jrstatus; + /* + * Make sure all information from the job has been obtained + * before telling CAAM that the job has been removed from the + * output ring. + */ + mb(); + /* set done */ wr_reg32(&jrp->rregs->outring_rmvd, 1); @@ -351,12 +358,23 @@ int caam_jr_enqueue(struct device *dev, u32 *desc, jrp->inpring[jrp->inp_ring_write_index] = desc_dma; + /* + * Guarantee that the descriptor's DMA address has been written to + * the next slot in the ring before the write index is updated, since + * other cores may update this index independently. + */ smp_wmb(); jrp->inp_ring_write_index = (jrp->inp_ring_write_index + 1) & (JOBR_DEPTH - 1); jrp->head = (head + 1) & (JOBR_DEPTH - 1); + /* + * Ensure that all job information has been written before + * notifying CAAM that a new job was added to the input ring. + */ + wmb(); + wr_reg32(&jrp->rregs->inpring_jobadd, 1); spin_unlock_bh(&jrp->inplock);