11e80709bSEric Biggers /* SPDX-License-Identifier: GPL-2.0-only */ 21e80709bSEric Biggers /* 31e80709bSEric Biggers * CQHCI crypto engine (inline encryption) support 41e80709bSEric Biggers * 51e80709bSEric Biggers * Copyright 2020 Google LLC 61e80709bSEric Biggers */ 71e80709bSEric Biggers 81e80709bSEric Biggers #ifndef LINUX_MMC_CQHCI_CRYPTO_H 91e80709bSEric Biggers #define LINUX_MMC_CQHCI_CRYPTO_H 101e80709bSEric Biggers 111e80709bSEric Biggers #include <linux/mmc/host.h> 121e80709bSEric Biggers 131e80709bSEric Biggers #include "cqhci.h" 141e80709bSEric Biggers 151e80709bSEric Biggers #ifdef CONFIG_MMC_CRYPTO 161e80709bSEric Biggers 171e80709bSEric Biggers int cqhci_crypto_init(struct cqhci_host *host); 181e80709bSEric Biggers 191e80709bSEric Biggers /* 201e80709bSEric Biggers * Returns the crypto bits that should be set in bits 64-127 of the 211e80709bSEric Biggers * task descriptor. 221e80709bSEric Biggers */ 231e80709bSEric Biggers static inline u64 cqhci_crypto_prep_task_desc(struct mmc_request *mrq) 241e80709bSEric Biggers { 25*86c639ceSEric Biggers if (!mrq->crypto_ctx) 261e80709bSEric Biggers return 0; 271e80709bSEric Biggers 28*86c639ceSEric Biggers /* We set max_dun_bytes_supported=4, so all DUNs should be 32-bit. */ 29*86c639ceSEric Biggers WARN_ON_ONCE(mrq->crypto_ctx->bc_dun[0] > U32_MAX); 30*86c639ceSEric Biggers 311e80709bSEric Biggers return CQHCI_CRYPTO_ENABLE_BIT | 321e80709bSEric Biggers CQHCI_CRYPTO_KEYSLOT(mrq->crypto_key_slot) | 33*86c639ceSEric Biggers mrq->crypto_ctx->bc_dun[0]; 341e80709bSEric Biggers } 351e80709bSEric Biggers 361e80709bSEric Biggers #else /* CONFIG_MMC_CRYPTO */ 371e80709bSEric Biggers 381e80709bSEric Biggers static inline int cqhci_crypto_init(struct cqhci_host *host) 391e80709bSEric Biggers { 401e80709bSEric Biggers return 0; 411e80709bSEric Biggers } 421e80709bSEric Biggers 431e80709bSEric Biggers static inline u64 cqhci_crypto_prep_task_desc(struct mmc_request *mrq) 441e80709bSEric Biggers { 451e80709bSEric Biggers return 0; 461e80709bSEric Biggers } 471e80709bSEric Biggers 481e80709bSEric Biggers #endif /* !CONFIG_MMC_CRYPTO */ 491e80709bSEric Biggers 501e80709bSEric Biggers #endif /* LINUX_MMC_CQHCI_CRYPTO_H */ 51