162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Intel Keem Bay OCS HCU Crypto Driver. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2018-2020 Intel Corporation 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include <linux/dma-mapping.h> 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef _CRYPTO_OCS_HCU_H 1162306a36Sopenharmony_ci#define _CRYPTO_OCS_HCU_H 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#define OCS_HCU_DMA_BIT_MASK DMA_BIT_MASK(32) 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#define OCS_HCU_HW_KEY_LEN 64 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_cistruct ocs_hcu_dma_list; 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_cienum ocs_hcu_algo { 2062306a36Sopenharmony_ci OCS_HCU_ALGO_SHA256 = 2, 2162306a36Sopenharmony_ci OCS_HCU_ALGO_SHA224 = 3, 2262306a36Sopenharmony_ci OCS_HCU_ALGO_SHA384 = 4, 2362306a36Sopenharmony_ci OCS_HCU_ALGO_SHA512 = 5, 2462306a36Sopenharmony_ci OCS_HCU_ALGO_SM3 = 6, 2562306a36Sopenharmony_ci}; 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/** 2862306a36Sopenharmony_ci * struct ocs_hcu_dev - OCS HCU device context. 2962306a36Sopenharmony_ci * @list: List of device contexts. 3062306a36Sopenharmony_ci * @dev: OCS HCU device. 3162306a36Sopenharmony_ci * @io_base: Base address of OCS HCU registers. 3262306a36Sopenharmony_ci * @engine: Crypto engine for the device. 3362306a36Sopenharmony_ci * @irq: IRQ number. 3462306a36Sopenharmony_ci * @irq_done: Completion for IRQ. 3562306a36Sopenharmony_ci * @irq_err: Flag indicating an IRQ error has happened. 3662306a36Sopenharmony_ci */ 3762306a36Sopenharmony_cistruct ocs_hcu_dev { 3862306a36Sopenharmony_ci struct list_head list; 3962306a36Sopenharmony_ci struct device *dev; 4062306a36Sopenharmony_ci void __iomem *io_base; 4162306a36Sopenharmony_ci struct crypto_engine *engine; 4262306a36Sopenharmony_ci int irq; 4362306a36Sopenharmony_ci struct completion irq_done; 4462306a36Sopenharmony_ci bool irq_err; 4562306a36Sopenharmony_ci}; 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/** 4862306a36Sopenharmony_ci * struct ocs_hcu_idata - Intermediate data generated by the HCU. 4962306a36Sopenharmony_ci * @msg_len_lo: Length of data the HCU has operated on in bits, low 32b. 5062306a36Sopenharmony_ci * @msg_len_hi: Length of data the HCU has operated on in bits, high 32b. 5162306a36Sopenharmony_ci * @digest: The digest read from the HCU. If the HCU is terminated, it will 5262306a36Sopenharmony_ci * contain the actual hash digest. Otherwise it is the intermediate 5362306a36Sopenharmony_ci * state. 5462306a36Sopenharmony_ci */ 5562306a36Sopenharmony_cistruct ocs_hcu_idata { 5662306a36Sopenharmony_ci u32 msg_len_lo; 5762306a36Sopenharmony_ci u32 msg_len_hi; 5862306a36Sopenharmony_ci u8 digest[SHA512_DIGEST_SIZE]; 5962306a36Sopenharmony_ci}; 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci/** 6262306a36Sopenharmony_ci * struct ocs_hcu_hash_ctx - Context for OCS HCU hashing operation. 6362306a36Sopenharmony_ci * @algo: The hashing algorithm being used. 6462306a36Sopenharmony_ci * @idata: The current intermediate data. 6562306a36Sopenharmony_ci */ 6662306a36Sopenharmony_cistruct ocs_hcu_hash_ctx { 6762306a36Sopenharmony_ci enum ocs_hcu_algo algo; 6862306a36Sopenharmony_ci struct ocs_hcu_idata idata; 6962306a36Sopenharmony_ci}; 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ciirqreturn_t ocs_hcu_irq_handler(int irq, void *dev_id); 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_cistruct ocs_hcu_dma_list *ocs_hcu_dma_list_alloc(struct ocs_hcu_dev *hcu_dev, 7462306a36Sopenharmony_ci int max_nents); 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_civoid ocs_hcu_dma_list_free(struct ocs_hcu_dev *hcu_dev, 7762306a36Sopenharmony_ci struct ocs_hcu_dma_list *dma_list); 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ciint ocs_hcu_dma_list_add_tail(struct ocs_hcu_dev *hcu_dev, 8062306a36Sopenharmony_ci struct ocs_hcu_dma_list *dma_list, 8162306a36Sopenharmony_ci dma_addr_t addr, u32 len); 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ciint ocs_hcu_hash_init(struct ocs_hcu_hash_ctx *ctx, enum ocs_hcu_algo algo); 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ciint ocs_hcu_hash_update(struct ocs_hcu_dev *hcu_dev, 8662306a36Sopenharmony_ci struct ocs_hcu_hash_ctx *ctx, 8762306a36Sopenharmony_ci const struct ocs_hcu_dma_list *dma_list); 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciint ocs_hcu_hash_finup(struct ocs_hcu_dev *hcu_dev, 9062306a36Sopenharmony_ci const struct ocs_hcu_hash_ctx *ctx, 9162306a36Sopenharmony_ci const struct ocs_hcu_dma_list *dma_list, 9262306a36Sopenharmony_ci u8 *dgst, size_t dgst_len); 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ciint ocs_hcu_hash_final(struct ocs_hcu_dev *hcu_dev, 9562306a36Sopenharmony_ci const struct ocs_hcu_hash_ctx *ctx, u8 *dgst, 9662306a36Sopenharmony_ci size_t dgst_len); 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ciint ocs_hcu_digest(struct ocs_hcu_dev *hcu_dev, enum ocs_hcu_algo algo, 9962306a36Sopenharmony_ci void *data, size_t data_len, u8 *dgst, size_t dgst_len); 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ciint ocs_hcu_hmac(struct ocs_hcu_dev *hcu_dev, enum ocs_hcu_algo algo, 10262306a36Sopenharmony_ci const u8 *key, size_t key_len, 10362306a36Sopenharmony_ci const struct ocs_hcu_dma_list *dma_list, 10462306a36Sopenharmony_ci u8 *dgst, size_t dgst_len); 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci#endif /* _CRYPTO_OCS_HCU_H */ 107