1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * CQHCI crypto engine (inline encryption) support 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Copyright 2020 Google LLC 6*4882a593Smuzhiyun */ 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun #ifndef LINUX_MMC_CQHCI_CRYPTO_H 9*4882a593Smuzhiyun #define LINUX_MMC_CQHCI_CRYPTO_H 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun #include <linux/mmc/host.h> 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun #include "cqhci.h" 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun #ifdef CONFIG_MMC_CRYPTO 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun int cqhci_crypto_init(struct cqhci_host *host); 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun /* 20*4882a593Smuzhiyun * Returns the crypto bits that should be set in bits 64-127 of the 21*4882a593Smuzhiyun * task descriptor. 22*4882a593Smuzhiyun */ cqhci_crypto_prep_task_desc(struct mmc_request * mrq)23*4882a593Smuzhiyunstatic inline u64 cqhci_crypto_prep_task_desc(struct mmc_request *mrq) 24*4882a593Smuzhiyun { 25*4882a593Smuzhiyun if (!mrq->crypto_ctx) 26*4882a593Smuzhiyun return 0; 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun /* We set max_dun_bytes_supported=4, so all DUNs should be 32-bit. */ 29*4882a593Smuzhiyun WARN_ON_ONCE(mrq->crypto_ctx->bc_dun[0] > U32_MAX); 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun return CQHCI_CRYPTO_ENABLE_BIT | 32*4882a593Smuzhiyun CQHCI_CRYPTO_KEYSLOT(mrq->crypto_key_slot) | 33*4882a593Smuzhiyun mrq->crypto_ctx->bc_dun[0]; 34*4882a593Smuzhiyun } 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun #else /* CONFIG_MMC_CRYPTO */ 37*4882a593Smuzhiyun cqhci_crypto_init(struct cqhci_host * host)38*4882a593Smuzhiyunstatic inline int cqhci_crypto_init(struct cqhci_host *host) 39*4882a593Smuzhiyun { 40*4882a593Smuzhiyun return 0; 41*4882a593Smuzhiyun } 42*4882a593Smuzhiyun cqhci_crypto_prep_task_desc(struct mmc_request * mrq)43*4882a593Smuzhiyunstatic inline u64 cqhci_crypto_prep_task_desc(struct mmc_request *mrq) 44*4882a593Smuzhiyun { 45*4882a593Smuzhiyun return 0; 46*4882a593Smuzhiyun } 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun #endif /* !CONFIG_MMC_CRYPTO */ 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun #endif /* LINUX_MMC_CQHCI_CRYPTO_H */ 51