From patchwork Fri Aug 28 11:50:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Horia_Geant=C4=83?= X-Patchwork-Id: 7091331 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0CA7E9F1C2 for ; Fri, 28 Aug 2015 11:51:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 926E720898 for ; Fri, 28 Aug 2015 11:51:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E62E52088F for ; Fri, 28 Aug 2015 11:51:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752179AbbH1Lum (ORCPT ); Fri, 28 Aug 2015 07:50:42 -0400 Received: from mail-by2on0131.outbound.protection.outlook.com ([207.46.100.131]:12044 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751652AbbH1LuS (ORCPT ); Fri, 28 Aug 2015 07:50:18 -0400 Received: from BN3PR0301MB1298.namprd03.prod.outlook.com (10.161.210.153) by BN3PR0301MB1188.namprd03.prod.outlook.com (10.160.156.15) with Microsoft SMTP Server (TLS) id 15.1.243.23; Fri, 28 Aug 2015 11:50:17 +0000 Received: from BLUPR0301CA0035.namprd03.prod.outlook.com (10.162.113.173) by BN3PR0301MB1298.namprd03.prod.outlook.com (10.161.210.153) with Microsoft SMTP Server (TLS) id 15.1.256.15; Fri, 28 Aug 2015 11:50:15 +0000 Received: from BY2FFO11FD001.protection.gbl (2a01:111:f400:7c0c::138) by BLUPR0301CA0035.outlook.office365.com (2a01:111:e400:5259::45) with Microsoft SMTP Server (TLS) id 15.1.256.15 via Frontend Transport; Fri, 28 Aug 2015 11:50:15 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=freescale.com; 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 BY2FFO11FD001.mail.protection.outlook.com (10.1.14.123) with Microsoft SMTP Server (TLS) id 15.1.256.10 via Frontend Transport; Fri, 28 Aug 2015 11:50:15 +0000 Received: from enigma.ea.freescale.net (enigma.ea.freescale.net [10.171.77.120]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t7SBoAbK014541; Fri, 28 Aug 2015 04:50:11 -0700 From: =?UTF-8?q?Horia=20Geant=C4=83?= To: Herbert Xu , Catalin Marinas , Will Deacon CC: , "David S. Miller" , , , "Scott Wood" , Victoria Milhoan , Steve Cornelius , Fabio Estevam , Alex Porosanu Subject: [RFC][PATCH 2/2] crypto: caam - handle core endianness != caam endianness Date: Fri, 28 Aug 2015 14:50:08 +0300 Message-ID: <1440762608-7866-1-git-send-email-horia.geanta@freescale.com> X-Mailer: git-send-email 2.4.4 In-Reply-To: <1440762306-7764-1-git-send-email-horia.geanta@freescale.com> References: <1440762306-7764-1-git-send-email-horia.geanta@freescale.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD001; 1:81fvIAQD7MHCF0Diybo4xyQ8yHnXqg6CmbZzJHpspJR0kqCi0iXTyU3BMdnYNPgQsl+d422AKUKAdUQVog5xCUDxI6cv0Wq5xHgPCdSTuyNE8Kp+jGmikj6FLPype+eEaU1u6Y+Tm4L8tRDOVPDC2mXx4ifkk1nYZdLY06sakExZ8qRI6Y7m1G30yeQBQSLUPjfDB2sIMpfqEsijL5CcVj0d0EDfH+LtePqzw4mflziXXSzkvTt4xKpeTW3+h37/Wmt65LX1kJ4RPudot36c5wBfnTzIuXtmaR7gTQSKEGzwa8+KY9OEEj1Fa5FpLy0CRKB6UmcWg5jy4vIK5wx1KffVcAPOJeN+VB0LZl3Rueg1DWRiWw5jdAdHmSJp6tUIE+fObLo6vjYQD9VdY1cdVviTLAfmG3eRICbJGiYbDXe3ZZcIK9s0mTlKiAYx5NadWs1SYLNAReBCvq1gfgjVmw== X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(3050300001)(199003)(189002)(105606002)(107886002)(69596002)(19580395003)(46102003)(19580405001)(86362001)(575784001)(5001960100002)(50466002)(189998001)(33646002)(36756003)(229853001)(104016003)(23676002)(85426001)(47776003)(106466001)(64706001)(97736004)(92566002)(68736005)(87936001)(2950100001)(6806004)(77096005)(5820100001)(77156002)(50986999)(62966003)(5007970100001)(5001770100001)(81156007)(5001830100001)(50226001)(4001540100001)(76176999)(5001860100001)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:BN3PR0301MB1298; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB1298; 2:WDzohBOQJpeA3ciSKmKIGof0iz0H3sR2HA3AdZoWdK2gxP0RYIod0tIxdUF5pj44GHPs24KYJRodoQ/Z4cukl4RCQAZxbb4AZeXuOpgis+RN0SL9JEXTucQVAUSTdBBhxouZpZLjN1xLusPQph9+OsWpuGDUlwKMZRltRNhrcGQ=; 3:+soiimjd0kgmfXJVK4bThv8//E7rZfLCwGu+Tsr2rRCTjHgI3laLlI2csozX0Wj7fQ7SH7Xbym0k5L+MMMOva59mvD7hzz74Mj3bS21qZXatqNYFvhj5dgRnDZJ58HqrVvZjUQqQvzvHs9pAQ0mrlcuLmDSfJL7QYNRcw5nFUCfiyrTXqk4A3noA7P+X51lQR4dFANY0LkSanunrLSkmjLj4MEoPHw+t0w3orTGSnJ8=; 25:4UvEFPVJx1y8GFssOqkgW5NT1HnXcD/3bu+rcqL+zGtHVSxJd6ixoXrnTYJPLnQg/oYr5eXdAMiW/cyMw5PMTnpv3jOjulyT6029/E2Hfdh324CKs3JIPQi7mCu0NCtPIpZwAtJqVmMCSBU1BDmLBA/a63d+0isO5nwqMBSzAES/1TZKWBrLOnZmoYCmTmul6eWVtXiv1xO3rjGKNE1aEHtdOigYbNOSoPNPDSHUZDCStA7Jivw9S8JWNe+nSRbr X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0301MB1298; UriScan:; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0301MB1188; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB1298; 20:iuYKUygpSb/bQ6x4srOKt7Lg3miPL1VCebWlaB12ESWsBotL67hibsXXMeTRMxgUNMBW8To0YXlv4i0W8kwG2LpZo9dHV2OozC1UBvkQWM1Jj6XLyYH3UYUUnWRMiVFix1/IuTRhgX9a/7RgnFBvBKkgv+ayRshtJ9zm+k3iLbikIL02KKuSMXNwbUyuis2wdHVePoCXNms5MZClSRM9KIxLH0IhllXsBROQKVgxBWXb39VJXYoXnUuJZ/EQdnCEv7bS/1iR8GrztWCBXiXKjN9mQWF0BXYMU+kinML/RDZRn6M4uxME80IorWlvJBkVHVgy52gAOhgufI9ypmJa+Hwr0N18DR8/AKMViXc1Zy0=; 4:IRNcv2N2TVsQsKYGYkHIVHN/hHizBE3jNtMDNlwcfW5nj+diGtPiYKKEL7u0HBgycQwTIwnslBGgj2lb1UrSRngqiGe7E9As3UGgjmYe9srfHr5JniWEPEaBC4kONFq7ZBxMqcY6RqZHxqBzcIQB/4w7/MyFLdmSYfHmJsjkvAxl83wS1yOG3iDaNzfViiefVpQvRMeujq98W+zJsnkF3nKTA13v1TUuQ9IQKVi3wS4E34s2dF2YUcZHu4cN6kPp/BXwgm+wsUZln5sm8CuZNNXVMmCfWKd1hmvUuPUjI11/+ZWdZPem+1hYOvwGUkfG X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(8121501046)(3002001); SRVR:BN3PR0301MB1298; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0301MB1298; X-Forefront-PRVS: 0682FC00E8 X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTjNQUjAzMDFNQjEyOTg7MjM6UzQ0ekV1bGZwVjFodnRIWWxwWEp0TENP?= =?utf-8?B?SlV3VTZSQVEyN1N5bXBBWGZNYWVJOEdBR1pmRmpBcGFKaTA2eUYvWDROZXg5?= =?utf-8?B?V1VEOGlRRjd4b1BKSVlRbWRFZkZ4R094ZDYwMVVoNGFGaDlNcUp3VGhtd0da?= =?utf-8?B?VkxKVGwwWGNIL1VtZWlHbnVNUUs3MWJhRXVFcEgyMkgvZkxRSDloMy9lS1gv?= =?utf-8?B?b3V5ZGN1ay9VMXlSU1BWOUMvdjZnSlEwSHorVW5xekVEdHhCdU1aNXoyNVNY?= =?utf-8?B?RU9WNnNCWFZyZlIyMndkenkvRmNiOEViSDB4Ym9MblNmY08zcm1IVkZBWTJy?= =?utf-8?B?ZThpbjJjQXBYbWNLZ2tXTURBNzdyQWFWcTU4dGxDQXRTWVgvbDRIRVJKTHl6?= =?utf-8?B?dDlFQlFxRk92Q05vdXlCVEVxRlJhWGlLM0tleTN0a3lrOXlUaFRqcElZZlFP?= =?utf-8?B?K05xeEVBdytCNFloUlhLZHgvK1dPMXZjWmtCVXZOVEdOOG9qUkVseW9HMFNT?= =?utf-8?B?Z0hiS2psTnhSR0dUVm1CSm4yZG13VWRUZUVMaytseTFKajFldkJwTFljdVZB?= =?utf-8?B?WEkxYllpTnZnVWhBaFkyRnRaMHlBcnZOM2MrMXdPeXluK2ZHemk3dU9wQTZP?= =?utf-8?B?ZGY0ZWNsTGp3cml0NlVuVWdoek5ISFBWWHdDWDRqaHU1WkFKUzY4MDlTeEE2?= =?utf-8?B?Q0l5clVZLzByUGRCdy9vWFNvaU9MeWtWNDlRZjluYWU4V0ppRkxEb0RnOVYv?= =?utf-8?B?ZVNPZzZHRjFseFM2bStHcCtSY3d2bE5MSFZyUnJGSmtyZm84RTlVd2V6bkJa?= =?utf-8?B?OSs0Skk4c3pmdFlLaExmNXVXb1VoMk5YU094TEFSVEdzRTQ4c0JqZU5ETHIx?= =?utf-8?B?eTlwV0h4QTRneDdyK2tXbFA5UzFaWXhjdExhbEVJOXRXMStEM1FxYkoyZm9I?= =?utf-8?B?ZDhlcmh0SzlTZ3QzeFRQYkNHckJaSVROK3FiYUdDZDhRekxsMFhzcTlSSDlk?= =?utf-8?B?WU9odElYNzNKWmNBNWpmMlVwSnJPcjV3dlFVSkhmdllrL0VWYUdWOTQweHhN?= =?utf-8?B?U3o0aDB6MEpQWTh0OHNzakdHVTc5ZFAyaEZUUnY2UTVQL3paNDNMN3hWNXlF?= =?utf-8?B?VHF2R011ZTNCelZFNVkvOGZqUlcxeFNMOUtHUVo5S25SdnB2Y3RvMnA4Szh5?= =?utf-8?B?M29LVFhkeVpQektHdzE1R3Z2K1ZNQ3JuY3FWTFhJT0ExbFN2YXgwSmh6YmE5?= =?utf-8?B?SkE4WEFzSnBxR1VaNXZPUmRJclplVkZNeE11M3pFREpCdEx1TG5heUUrci9i?= =?utf-8?B?d0ZzVnNac1BuWURKNjJhWEJWQzlZb0pyUGkzcHJQZXNuZkZaTm9zMjAvT0tM?= =?utf-8?B?OWk2Q1YzM29aRmRZVzZJSlVFSW9tSjRwaUdUQmxMUFo4dVkycjRnREszM0NM?= =?utf-8?B?dFJoQTNzWXZ1VUQyRy9XRlNtOVhOK2JlNmdFWGJOaER6YXNYUVp1OVdFSUV6?= =?utf-8?B?QmgzWC94N0pyaGhIbVI5WDZKZnEyYjVVM3lnd0xwTloxT0tWVlhQTlR6SThK?= =?utf-8?B?M25CSWdhR25WNS9haUk0RlhTK254S24rNFZBek1WakY5WXlrT0QwUitDRjFy?= =?utf-8?B?b1ltZGN6V1VNQmdTUXc0c1MwRXdja3lXTC9XQzlJNjhHcUYyVnR3SUNZODl1?= =?utf-8?Q?ph8Ay4tL/1QhkAPzkIxw=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB1298; 5:bK0zLCQYGyDHPGoUJJ5igoNJTaxisWKZWUS6Pq+nDdotJRREh4hwHvxoven9xm42QdnDEnktDwS6PaPDKyNkPVmNSItcdtBJ3IfQAmNzbEocslqlctOyIK7KySNII+kSw7PN4jz8RcBYWrPZCLsxaw==; 24:ArtSNjl4cp08EyMC8gjPRVEs8y+WtkFhxEQ6spJ0Dv6tWfenkJ6Hx8ncn2CWcfOPrcWOCu5Zy/7YiOYHTaDFRXT1kBDzIwjFwHctiN/EJTs=; 20:Gpei8t3qrWGvL0SwqgUuct3Q0PQVaBYO3Ou5IRCGw/f+u//kITO1P6b/rzahEwojyEbrCw4KxbM4lgTVucaVKA== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Aug 2015 11:50:15.2109 (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: BN3PR0301MB1298 X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB1188; 2:mAqOgp3qFME2B5jiiJY+v82IIPJJ15lROVNBA4t2QHEDAbBAkdx3wX/aTGhfDE2zbtuuriKj1lpqrPC/UoBF47X+8CxZN6iOq04zFh7rprs7zBFbA4s2sfc0XqkJ5M+0qG5GZGdzb+MADaMyk+BebEHpJAgix+VLfhlV5Le0Xfg=; 3:w6exPFvmqv3rlboXnjJnWnJEtvI9FI5H9KMw6lzCeNlFmY2KLEwz+KqV/28y95nPQR2bxUJJeMKOKos6q743oZekJBOXba3RQdvMBPsUqdDcejVn4rMQYE+YZPZXta5dS3+vp6dR4omVvCFEcCwuqHFwcqElzhgFy17YSto2FWufDIsMrsRNHJ73C9BIQX4bhem7mH1YIylkf04at90jjiYD+qHj9SEkY+jo3ZgCenc=; 25:ZhYq74EZhnKYzGtkw9eTN6A+fvr25LN/jAoZWThPsCIWmREF0khvVoe3D6fEnj15QkE/+KKM2JqNNbgIolCxXAjve1KDZNL7sWdL9nQqbpwD/bejPF1F6rdeGHQWaR8b63lSRxNBxbYn4mGN/XnQzcF72fd0QdNsc+P+TLMMwJ2MU/x7mx7nCFPQ5NKtWcYqWdX9PeOrlbwhfhtZQubFR9KiA8gURk3FKfD1im6Eb971z+MMEik5pmKA9lCN4eI4; 23:MoFAAveI7jTEUs5BSjIw+TX3a7RlpkumthFleROjSbFo+hi6Tsr8MypVyzQDsftpsDILodm26HK4jTQYVxCb0hdU5nt8YAA6WdnEqbeG3bCTpircH4ZlqYL/uWcPiPHgIeQ+Ya2Z9OaT01WYORy+bZAx/PEKB8uWhDFHOfZ0rK+yp3b1WkkNZjvd0SE6+EzR 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=-8.3 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 There are SoCs like LS1043A where CAAM endianness (BE) does not match the endianness of the core (LE). Moreover, there are requirements for the driver to handle cases like CPU_BIG_ENDIAN=y on ARM-based SoCs. This requires for a complete rewrite of the I/O accessors. PPC-specific accessors - {in,out}_{le,be}XX - are replaced with generic io{read,write}[be]XX where possible (no 64-bit generic I/O). Signed-off-by: Horia Geant? Signed-off-by: Alex Porosanu --- While patch takes into consideration the S/G format (struct sec4_sg_entry) for i.MX7, I don't have a board so I haven't tested this platform. drivers/crypto/caam/caamhash.c | 5 +-- drivers/crypto/caam/ctrl.c | 2 +- drivers/crypto/caam/desc.h | 9 ++++- drivers/crypto/caam/desc_constr.h | 42 +++++++++++++++-------- drivers/crypto/caam/jr.c | 8 ++--- drivers/crypto/caam/regs.h | 72 ++++++++++++++++++++++++++++----------- drivers/crypto/caam/sg_sw_sec4.h | 10 +++--- 7 files changed, 102 insertions(+), 46 deletions(-) diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index 72acf8e5ac2f..c39332171fa3 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -841,7 +841,7 @@ static int ahash_update_ctx(struct ahash_request *req) *next_buflen, 0); } else { (edesc->sec4_sg + sec4_sg_src_index - 1)->len |= - SEC4_SG_LEN_FIN; + cpu_to_caam32(SEC4_SG_LEN_FIN); } state->current_buf = !state->current_buf; @@ -942,7 +942,8 @@ static int ahash_final_ctx(struct ahash_request *req) state->buf_dma = try_buf_map_to_sec4_sg(jrdev, edesc->sec4_sg + 1, buf, state->buf_dma, buflen, last_buflen); - (edesc->sec4_sg + sec4_sg_bytes - 1)->len |= SEC4_SG_LEN_FIN; + (edesc->sec4_sg + sec4_sg_bytes - 1)->len |= + cpu_to_caam32(SEC4_SG_LEN_FIN); edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg, sec4_sg_bytes, DMA_TO_DEVICE); diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index 8abb4bc548cc..e527d1e0b9ab 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -128,7 +128,7 @@ static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc, } for (i = 0; i < desc_len(desc); i++) - wr_reg32(&deco->descbuf[i], *(desc + i)); + wr_reg32(&deco->descbuf[i], caam32_to_cpu(*(desc + i))); flags = DECO_JQCR_WHL; /* diff --git a/drivers/crypto/caam/desc.h b/drivers/crypto/caam/desc.h index 983d663ef671..fc257b343d3b 100644 --- a/drivers/crypto/caam/desc.h +++ b/drivers/crypto/caam/desc.h @@ -23,16 +23,23 @@ #define SEC4_SG_OFFS_MASK 0x00001fff struct sec4_sg_entry { -#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_IMX +#if !defined(CONFIG_ARCH_DMA_ADDR_T_64BIT) && \ + defined(CONFIG_CRYPTO_DEV_FSL_CAAM_IMX) u32 rsvd1; dma_addr_t ptr; #else u64 ptr; #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_IMX */ u32 len; +#ifndef CONFIG_CRYPTO_DEV_FSL_CAAM_LE u8 rsvd2; u8 buf_pool_id; u16 offset; +#else + u16 offset; + u8 buf_pool_id; + u8 rsvd2; +#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_LE */ }; /* Max size of any CAAM descriptor in 32-bit words, inclusive of header */ diff --git a/drivers/crypto/caam/desc_constr.h b/drivers/crypto/caam/desc_constr.h index 98d07de24fc4..40baf4752fbc 100644 --- a/drivers/crypto/caam/desc_constr.h +++ b/drivers/crypto/caam/desc_constr.h @@ -5,6 +5,7 @@ */ #include "desc.h" +#include "regs.h" #define IMMEDIATE (1 << 23) #define CAAM_CMD_SZ sizeof(u32) @@ -32,7 +33,7 @@ static inline int desc_len(u32 *desc) { - return *desc & HDR_DESCLEN_MASK; + return caam32_to_cpu(*desc) & HDR_DESCLEN_MASK; } static inline int desc_bytes(void *desc) @@ -52,7 +53,7 @@ static inline void *sh_desc_pdb(u32 *desc) static inline void init_desc(u32 *desc, u32 options) { - *desc = (options | HDR_ONE) + 1; + *desc = cpu_to_caam32((options | HDR_ONE) + 1); } static inline void init_sh_desc(u32 *desc, u32 options) @@ -78,9 +79,10 @@ static inline void append_ptr(u32 *desc, dma_addr_t ptr) { dma_addr_t *offset = (dma_addr_t *)desc_end(desc); - *offset = ptr; + *offset = wr_dma(ptr); - (*desc) += CAAM_PTR_SZ / CAAM_CMD_SZ; + (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + + CAAM_PTR_SZ / CAAM_CMD_SZ); } static inline void init_job_desc_shared(u32 *desc, dma_addr_t ptr, int len, @@ -99,16 +101,17 @@ static inline void append_data(u32 *desc, void *data, int len) if (len) /* avoid sparse warning: memcpy with byte count of 0 */ memcpy(offset, data, len); - (*desc) += (len + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ; + (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + + (len + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ); } static inline void append_cmd(u32 *desc, u32 command) { u32 *cmd = desc_end(desc); - *cmd = command; + *cmd = cpu_to_caam32(command); - (*desc)++; + (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + 1); } #define append_u32 append_cmd @@ -117,16 +120,22 @@ static inline void append_u64(u32 *desc, u64 data) { u32 *offset = desc_end(desc); - *offset = upper_32_bits(data); - *(++offset) = lower_32_bits(data); + /* Only 32-bit alignment is guaranteed in descriptor buffer */ + if (IS_ENABLED(CONFIG_CRYPTO_DEV_FSL_CAAM_LE)) { + *offset = cpu_to_caam32(lower_32_bits(data)); + *(++offset) = cpu_to_caam32(upper_32_bits(data)); + } else { + *offset = cpu_to_caam32(upper_32_bits(data)); + *(++offset) = cpu_to_caam32(lower_32_bits(data)); + } - (*desc) += 2; + (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + 2); } /* Write command without affecting header, and return pointer to next word */ static inline u32 *write_cmd(u32 *desc, u32 command) { - *desc = command; + *desc = cpu_to_caam32(command); return desc + 1; } @@ -168,14 +177,17 @@ APPEND_CMD_RET(move, MOVE) static inline void set_jump_tgt_here(u32 *desc, u32 *jump_cmd) { - *jump_cmd = *jump_cmd | (desc_len(desc) - (jump_cmd - desc)); + *jump_cmd = cpu_to_caam32(caam32_to_cpu(*jump_cmd) | + (desc_len(desc) - (jump_cmd - desc))); } static inline void set_move_tgt_here(u32 *desc, u32 *move_cmd) { - *move_cmd &= ~MOVE_OFFSET_MASK; - *move_cmd = *move_cmd | ((desc_len(desc) << (MOVE_OFFSET_SHIFT + 2)) & - MOVE_OFFSET_MASK); + u32 val = caam32_to_cpu(*move_cmd); + + val &= ~MOVE_OFFSET_MASK; + val |= (desc_len(desc) << (MOVE_OFFSET_SHIFT + 2)) & MOVE_OFFSET_MASK; + *move_cmd = cpu_to_caam32(val); } #define APPEND_CMD(cmd, op) \ diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index f7e0d8d4c3da..5add26b2a2ff 100644 --- a/drivers/crypto/caam/jr.c +++ b/drivers/crypto/caam/jr.c @@ -182,7 +182,7 @@ static void caam_jr_dequeue(unsigned long devarg) sw_idx = (tail + i) & (JOBR_DEPTH - 1); if (jrp->outring[hw_idx].desc == - jrp->entinfo[sw_idx].desc_addr_dma) + rd_dma(jrp->entinfo[sw_idx].desc_addr_dma)) break; /* found */ } /* we should never fail to find a matching descriptor */ @@ -200,7 +200,7 @@ static void caam_jr_dequeue(unsigned long devarg) usercall = jrp->entinfo[sw_idx].callbk; userarg = jrp->entinfo[sw_idx].cbkarg; userdesc = jrp->entinfo[sw_idx].desc_addr_virt; - userstatus = jrp->outring[hw_idx].jrstatus; + userstatus = caam32_to_cpu(jrp->outring[hw_idx].jrstatus); /* * Make sure all information from the job has been obtained @@ -330,7 +330,7 @@ int caam_jr_enqueue(struct device *dev, u32 *desc, int head, tail, desc_size; dma_addr_t desc_dma; - desc_size = (*desc & HDR_JD_LENGTH_MASK) * sizeof(u32); + desc_size = (caam32_to_cpu(*desc) & HDR_JD_LENGTH_MASK) * sizeof(u32); desc_dma = dma_map_single(dev, desc, desc_size, DMA_TO_DEVICE); if (dma_mapping_error(dev, desc_dma)) { dev_err(dev, "caam_jr_enqueue(): can't map jobdesc\n"); @@ -356,7 +356,7 @@ int caam_jr_enqueue(struct device *dev, u32 *desc, head_entry->cbkarg = areq; head_entry->desc_addr_dma = desc_dma; - jrp->inpring[jrp->inp_ring_write_index] = desc_dma; + jrp->inpring[jrp->inp_ring_write_index] = wr_dma(desc_dma); /* * Guarantee that the descriptor's DMA address has been written to diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h index a8a79975682f..d3e93e066cd8 100644 --- a/drivers/crypto/caam/regs.h +++ b/drivers/crypto/caam/regs.h @@ -65,7 +65,7 @@ * */ -#ifdef CONFIG_ARM +#if defined(CONFIG_ARM) || defined(CONFIG_ARM64) /* These are common macros for Power, put here for ARM */ #define setbits32(_addr, _v) writel((readl(_addr) | (_v)), (_addr)) #define clrbits32(_addr, _v) writel((readl(_addr) & ~(_v)), (_addr)) @@ -86,26 +86,62 @@ #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set) #endif -#ifdef __BIG_ENDIAN -#define wr_reg32(reg, data) out_be32(reg, data) -#define rd_reg32(reg) in_be32(reg) +#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_LE +#define caam16_to_cpu(value) le16_to_cpu(value) +#define cpu_to_caam16(value) cpu_to_le16(value) +#define caam32_to_cpu(value) le32_to_cpu(value) +#define cpu_to_caam32(value) cpu_to_le32(value) +#define caam64_to_cpu(value) le64_to_cpu(value) +#define cpu_to_caam64(value) cpu_to_le64(value) +#define wr_reg32(reg, data) iowrite32(data, reg) +#define rd_reg32(reg) ioread32(reg) +#define clrsetbits_32(addr, clear, set) clrsetbits_le32(addr, clear, set) +#else +#define caam16_to_cpu(value) be16_to_cpu(value) +#define cpu_to_caam16(value) cpu_to_be16(value) +#define caam32_to_cpu(value) be32_to_cpu(value) +#define cpu_to_caam32(value) cpu_to_be32(value) +#define caam64_to_cpu(value) be64_to_cpu(value) +#define cpu_to_caam64(value) cpu_to_be64(value) +#define wr_reg32(reg, data) iowrite32be(data, reg) +#define rd_reg32(reg) ioread32be(reg) #define clrsetbits_32(addr, clear, set) clrsetbits_be32(addr, clear, set) -#ifdef CONFIG_64BIT -#define wr_reg64(reg, data) out_be64(reg, data) -#define rd_reg64(reg) in_be64(reg) #endif + +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT +#ifdef CONFIG_SOC_IMX7D +#define wr_dma(value) (((u64)cpu_to_caam32(lower_32_bits(value)) << 32) | \ + (u64)cpu_to_caam32(higher_32_bits(value))) +#define rd_dma(value) (((u64)caam32_to_cpu(lower_32_bits(value)) << 32) | \ + (u64)caam32_to_cpu(higher_32_bits(value))) #else -#ifdef __LITTLE_ENDIAN -#define wr_reg32(reg, data) __raw_writel(data, reg) -#define rd_reg32(reg) __raw_readl(reg) -#define clrsetbits_32(addr, clear, set) clrsetbits_le32(addr, clear, set) -#ifdef CONFIG_64BIT -#define wr_reg64(reg, data) __raw_writeq(data, reg) -#define rd_reg64(reg) __raw_readq(reg) -#endif -#endif +#define wr_dma(value) cpu_to_caam64(value) +#define rd_dma(value) caam64_to_cpu(value) +#endif /* CONFIG_SOC_IMX7D */ +#else +#define wr_dma(value) cpu_to_caam32(value) +#define rd_dma(value) caam32_to_cpu(value) #endif +#ifdef CONFIG_64BIT +#ifdef CONFIG_PPC +#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_LE +#define wr_reg64(reg, data) out_le64(reg, data) +#define rd_reg64(reg) in_le64(reg) +#else +#define wr_reg64(reg, data) out_be64(reg, data) +#define rd_reg64(reg) in_be64(reg) +#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_LE */ +#else /* CONFIG_PPC */ +#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_LE +#define wr_reg64(reg, data) writeq(data, reg) +#define rd_reg64(reg) readq(reg) +#else +#define wr_reg64(reg, data) iowrite64be(data, reg) +#define rd_reg64(reg) ioread64be(reg) +#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_LE */ +#endif /* CONFIG_PPC */ +#else /* CONFIG_64BIT */ /* * The only users of these wr/rd_reg64 functions is the Job Ring (JR). * The DMA address registers in the JR are handled differently depending on @@ -123,8 +159,6 @@ * base + 0x0000 : least-significant 32 bits * base + 0x0004 : most-significant 32 bits */ - -#ifndef CONFIG_64BIT #if !defined(CONFIG_CRYPTO_DEV_FSL_CAAM_LE) || \ defined(CONFIG_CRYPTO_DEV_FSL_CAAM_IMX) #define REG64_MS32(reg) ((u32 __iomem *)(reg)) @@ -145,7 +179,7 @@ static inline u64 rd_reg64(u64 __iomem *reg) return ((u64)rd_reg32(REG64_MS32(reg)) << 32 | (u64)rd_reg32(REG64_LS32(reg))); } -#endif +#endif /* CONFIG_64BIT */ /* * jr_outentry diff --git a/drivers/crypto/caam/sg_sw_sec4.h b/drivers/crypto/caam/sg_sw_sec4.h index 18cd6d1f5870..fb8e0084e3e5 100644 --- a/drivers/crypto/caam/sg_sw_sec4.h +++ b/drivers/crypto/caam/sg_sw_sec4.h @@ -5,6 +5,8 @@ * */ +#include "regs.h" + struct sec4_sg_entry; /* @@ -13,10 +15,10 @@ struct sec4_sg_entry; static inline void dma_to_sec4_sg_one(struct sec4_sg_entry *sec4_sg_ptr, dma_addr_t dma, u32 len, u32 offset) { - sec4_sg_ptr->ptr = dma; - sec4_sg_ptr->len = len; + sec4_sg_ptr->ptr = wr_dma(dma); + sec4_sg_ptr->len = cpu_to_caam32(len); sec4_sg_ptr->buf_pool_id = 0; - sec4_sg_ptr->offset = offset; + sec4_sg_ptr->offset = cpu_to_caam16(offset & SEC4_SG_OFFS_MASK); #ifdef DEBUG print_hex_dump(KERN_ERR, "sec4_sg_ptr@: ", DUMP_PREFIX_ADDRESS, 16, 4, sec4_sg_ptr, @@ -51,7 +53,7 @@ static inline void sg_to_sec4_sg_last(struct scatterlist *sg, int sg_count, u32 offset) { sec4_sg_ptr = sg_to_sec4_sg(sg, sg_count, sec4_sg_ptr, offset); - sec4_sg_ptr->len |= SEC4_SG_LEN_FIN; + sec4_sg_ptr->len |= cpu_to_caam32(SEC4_SG_LEN_FIN); } static inline struct sec4_sg_entry *sg_to_sec4_sg_len(