Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2349161imm; Mon, 28 May 2018 06:31:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo4juKyrjYvKxtLxD/38gvlMLCueijiOYlcYdzy03+WpTJKHVcMiWQ6ENrffA45TuPUPrHC X-Received: by 2002:a17:902:600a:: with SMTP id r10-v6mr13442132plj.70.1527514260649; Mon, 28 May 2018 06:31:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527514260; cv=none; d=google.com; s=arc-20160816; b=Myn3sE4DA1xm6IAQfH1nObT73Zm4Z0LSlCgu9IjTIgTFk6QSQ3jVX4vT1oHLMvHIts 0w4ANQ7oqzbSbJ1Rx8ZgPZ8tmKt7UK2YfesETF5FSETbPzluoZ/vyHrKM8UICoTphaAq +Pov/5jVvV/j8loAHAzkyhROXPxQ2uDm786H1ei//GZiOb7CGsmB2RbHoFv6f+5HNPuw YXTXQEsT4tP+29MF1e8NzA4X/Afd977FKZaaq3EPNZfJOs7QKDAUv3v4vBwl+7Flc/Sc ++RlDwLLbSX4VU4wr/guYo+ut3VvRVes0BKa2etnkroBtJs/PbwjLwqJRk+gV3ayt+ny nwlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:from:cc :subject:to:dkim-signature:arc-authentication-results; bh=BoY9XFcaLxLVabEMF1dM6SceQavrNn7BfAu8PUTg3xo=; b=f6x/S7fFPl5Jz5Pag7icOFCSfrxxZ8GbddjJKRSEhFQwpvi6xL5f3UloC09Z0m5kbn I7TeabbgGSztD1f0bLmIC9IUdnofeYeYU1ccBvlm3o1BssF7fAWLiQSUnXgE6SRtPggi LJSN/8ktHTKwxH5Sdh/K8055tQRdPu6/1H/9Fx1htKenySpdgenu4zZBZ5rZp+nVH8Ll Cjq/8aSY9/edYjjI7CBeMQt6Rsk1yYz6N0TUevdawW3XLrI8bAdk6oStrSuM/GwFAsjE lMLcp8bBt3HXgYmdUmsPLfiQR5ZaB3IHUuwTH8b1QxPi7mrGt10Si5iMHGaVaKFrO90v GXIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=TV6BEuqE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2-v6si30253796plb.77.2018.05.28.06.30.45; Mon, 28 May 2018 06:31:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=TV6BEuqE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S939072AbeE1N2y (ORCPT + 99 others); Mon, 28 May 2018 09:28:54 -0400 Received: from smtprelay.synopsys.com ([198.182.37.59]:50880 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939123AbeE1N0y (ORCPT ); Mon, 28 May 2018 09:26:54 -0400 Received: from mailhost.synopsys.com (mailhost1.synopsys.com [10.12.238.239]) by smtprelay.synopsys.com (Postfix) with ESMTP id 1FFE21E04A3 for ; Mon, 28 May 2018 15:26:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1527514013; bh=JxlgRR00hilUfqdY9PGo5ZDf2IqQT7q8fw0APvyV7PA=; h=To:Subject:CC:From:Date:From; b=TV6BEuqEMpmvJNDaW79biLlOl971IkeNEH0hku/0gMaZhe0Y6zOlye3tL+TuXiZW/ sXZINQGwTYPyth4n0qgasvFLP+07xOZMmc40zwm6Jn8YW36CpdMwckEVtgodBBfpyU 2fgSzw8wJMZwIBKA8rsH9sgNl2gvSz2Lgb7zquRsP711ErgH2Orv4QL8ReAngH6WE/ ipNAh7iYsMEq2yCNIIQUuB2Fg6gJnNY93T/1XiSdYLwi2GBTvbQpTBqyWOn5iaeTHQ FnpBNRzvfUSmp8IUsq52EI2AHcmyIJv1WuIBw7/783ymc638aLT/xYgGrvEvm6s05B /bdP0pm5WJ4XA== Received: from US01WEHTC2.internal.synopsys.com (us01wehtc2.internal.synopsys.com [10.12.239.237]) by mailhost.synopsys.com (Postfix) with ESMTP id 77A255626; Mon, 28 May 2018 06:26:52 -0700 (PDT) Received: from US01WEHTC1.internal.synopsys.com (10.12.239.236) by US01WEHTC2.internal.synopsys.com (10.12.239.237) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 28 May 2018 06:26:52 -0700 Received: from [10.0.2.15] (10.144.133.104) by us01wehtc1.internal.synopsys.com (10.12.239.231) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 28 May 2018 06:26:51 -0700 To: "Vinayak Holikatti ; \"James E.J. Bottomley\" ; \"Martin K. Petersen\"" Subject: [PATCH 2/5] scsi: ufs: Add crypto header file for UFS HC driver CC: , "linux-scsi@vger.kernel.org; Manjunath M Bettegowda ; Prabu Thangamuthu ; Tejas Joglekar ; Joao Pinto" From: Ladvine D Almeida Message-ID: <24ee982e-1495-31da-a74f-43a23cd54c96@synopsys.com> Date: Mon, 28 May 2018 14:26:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.144.133.104] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds the required structures, enum definitions, function prototypes for UFS Host Controller Crypto support. Signed-off-by: Ladvine D Almeida --- drivers/scsi/ufs/ufshcd-crypto.h | 156 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 drivers/scsi/ufs/ufshcd-crypto.h diff --git a/drivers/scsi/ufs/ufshcd-crypto.h b/drivers/scsi/ufs/ufshcd-crypto.h new file mode 100644 index 0000000..f5d5148 --- /dev/null +++ b/drivers/scsi/ufs/ufshcd-crypto.h @@ -0,0 +1,156 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Universal Flash Storage Host controller driver crypto + * + * Copyright (C) 2018 Synopsys, Inc. (www.synopsys.com) + * + * Authors: + * Manjunath M Bettegowda , + * Ladvine D Almeida + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#ifndef _UFSHCD_CRYPTO_H +#define _UFSHCD_CRYPTO_H + +#include +#include +#include +#include +#include +#include + +#define REQ_INLINE_ENCRYPTION REQ_DRV + +/* CCAP Register Masks */ +#define UFSHCD_CFGPTR_MASK (0xff000000) +#define UFSHCD_CFGPTR_SHIFT (24) +#define UFSHCD_CFGC_MASK (0x0000ff00) +#define UFSHCD_CFGC_SHIFT (8) +#define UFSHCD_CC_MASK (0x000000ff) + +/* x-CRYPTOCAP Register Masks */ +#define UFSHCD_KS_MASK (0x00ff0000) +#define UFSHCD_KS_SHIFT (16) +#define UFSHCD_SDUSB_MASK (0x0000ff00) +#define UFSHCD_SDUSB_SHIFT (8) +#define UFSHCD_ALGID_MASK (0x000000ff) + +#define SHA1_LENGTH (20) + +struct ufshcd_lrb; +struct ufs_hba; + +/* supported crypto algorithms */ +enum ufshcd_crypto_algorithms { + UFSHCD_AES_XTS = 0x00, + UFSHCD_BITLOCKER_AES_CBC = 0x01, + UFSHCD_AES_ECB = 0x02, + UFSHCD_ESSIV_AES_CBC = 0x03, +}; + +/* supported key sizes */ +enum ufshcd_crypto_key_sizes { + UFSHCD_KS_128 = 0x01, + UFSHCD_KS_192 = 0x02, + UFSHCD_KS_256 = 0x03, + UFSHCD_KS_512 = 0x04, + UFSHCD_KS_MAX = 0x05, +}; + +/* supported data unit sizes */ +enum ufshcd_crypto_data_unit_sizes { + UFSHCD_DUSIZE_512 = 0x01, + UFSHCD_DUSIZE_1K = 0x01<<1, + UFSHCD_DUSIZE_2K = 0x01<<2, + UFSHCD_DUSIZE_4K = 0x01<<3, + UFSHCD_DUSIZE_8K = 0x01<<4, + UFSHCD_DUSIZE_16K = 0x01<<5, + UFSHCD_DUSIZE_32K = 0x01<<6, + UFSHCD_DUSIZE_64K = 0x01<<7, +}; + +/* crypto configuration register fields */ +enum ufshcd_xcryptocfg_offsets { + XCRYPTOCFG_ENABLE = 0x01<<31, + XCRYPTOCFG_SIZE = 0x80, + XCRYPTOCFG_PTR_OFFSET = 0x100, + XCRYPTOCFG_KEYS_OFFSET = 0x00, + XCRYPTOCFG_DW16_OFFSET = 0x40, + XCRYPTOCFG_DW17_OFFSET = 0x44, +}; + +/* ufshcd_x_crypto_cap - Crypto Capability X */ +struct ufshcd_x_crypto_cap { + u32 cap_x; /* KS[23:16] SDUSB[15:08] ALGID[07:00] */ +}; + +/** + * ufshcd_x_cryptocfg - Crypto Configuration X + * @ckey_hash: 511:0 (64 bytes) CRYPTOKEY + * @dus_mask: 519:512 (1 byte) DUSIZE + * @ccap_idx: 527:520 (1 byte) CAPIDX + * @reserved_1: 535:528 (1 byte) Reserved + * @ccfg_en: 543:536 (1 byte) CFGE + * @multi_slot: 551:544 (1 byte) Reserved for Multi-Host Functions + * @reserved_2: 559:558 (1 byte) Reserved + * @vsb: 575:560 (2 bytes) VSB(Vendor Specific Bits) + * @reserved_3: 1023:576 (56 bytes) Reserved + */ +struct ufshcd_x_cryptocfg { + u8 ckey_hash[64]; + u8 dus_mask; + u8 ccap_idx; + u8 reserved_1; + u8 ccfg_en; + u8 multi_slot; + u8 reserved_2; + u8 vsb[2]; + u8 reserved_3[56]; +}; + +/** + * ufshcd_ccap - Crypto Capability structure + * @ccap_en: enable capability of hardware + * @ccfg: CFGPTR Configuration array pointer + * @ccfg_count: CFGC Configuration count + * @ccap_count: CC Number of Crypto capabilities + * @activecfg_count: Total Active configurations + */ +struct ufshcd_ccap { + u8 ccap_en; + struct ufshcd_x_cryptocfg *ccfg; + u8 ccfg_count; + u8 ccap_count; + u8 activecfg_count; +}; + +/** + * ufshcd_xts_ctx - UFSHCD XTS algorithm context + * @fallback: fallback algorithm + * @keylen: key length + * @cipher_key: encryption key + * @cipher_keyhash: hash value of encryption key + * @key_cap_idx: key capability index + * @active_ccfg_idx: key configuration index + */ +struct ufshcd_xts_ctx { + struct crypto_skcipher *fallback; + u32 keylen; + u8 cipher_key[2*AES_KEYSIZE_256]; + u8 cipher_keyhash[64]; + int *key_cap_idx; + int active_ccfg_idx; +}; + +int ufshcd_crypto_memory_alloc(struct ufs_hba *hba); +void ufshcd_remove_crypto_memory(struct ufs_hba *hba); +void ufshcd_read_crypto_capabilities(struct ufs_hba *hba); +void ufshcd_prepare_for_crypto(struct ufs_hba *hba, + struct ufshcd_lrb *lrbp); +int ufshcd_enable_crypt_alg(struct ufs_hba *hba); +void ufshcd_disable_crypt_alg(struct ufs_hba *hba); + +#endif /* End of Header */ -- 2.7.4