Path: blob/master/drivers/crypto/intel/keembay/ocs-aes.h
29281 views
/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Intel Keem Bay OCS AES Crypto Driver.3*4* Copyright (C) 2018-2020 Intel Corporation5*/67#ifndef _CRYPTO_OCS_AES_H8#define _CRYPTO_OCS_AES_H910#include <linux/dma-mapping.h>1112enum ocs_cipher {13OCS_AES = 0,14OCS_SM4 = 1,15};1617enum ocs_mode {18OCS_MODE_ECB = 0,19OCS_MODE_CBC = 1,20OCS_MODE_CTR = 2,21OCS_MODE_CCM = 6,22OCS_MODE_GCM = 7,23OCS_MODE_CTS = 9,24};2526enum ocs_instruction {27OCS_ENCRYPT = 0,28OCS_DECRYPT = 1,29OCS_EXPAND = 2,30OCS_BYPASS = 3,31};3233/**34* struct ocs_aes_dev - AES device context.35* @list: List head for insertion into device list hold36* by driver.37* @dev: OCS AES device.38* @irq: IRQ number.39* @base_reg: IO base address of OCS AES.40* @irq_copy_completion: Completion to indicate IRQ has been triggered.41* @dma_err_mask: Error reported by OCS DMA interrupts.42* @engine: Crypto engine for the device.43*/44struct ocs_aes_dev {45struct list_head list;46struct device *dev;47int irq;48void __iomem *base_reg;49struct completion irq_completion;50u32 dma_err_mask;51struct crypto_engine *engine;52};5354/**55* struct ocs_dll_desc - Descriptor of an OCS DMA Linked List.56* @vaddr: Virtual address of the linked list head.57* @dma_addr: DMA address of the linked list head.58* @size: Size (in bytes) of the linked list.59*/60struct ocs_dll_desc {61void *vaddr;62dma_addr_t dma_addr;63size_t size;64};6566int ocs_aes_set_key(struct ocs_aes_dev *aes_dev, const u32 key_size,67const u8 *key, const enum ocs_cipher cipher);6869int ocs_aes_op(struct ocs_aes_dev *aes_dev,70enum ocs_mode mode,71enum ocs_cipher cipher,72enum ocs_instruction instruction,73dma_addr_t dst_dma_list,74dma_addr_t src_dma_list,75u32 src_size,76u8 *iv,77u32 iv_size);7879/**80* ocs_aes_bypass_op() - Use OCS DMA to copy data.81* @aes_dev: The OCS AES device to use.82* @dst_dma_list: The OCS DMA list mapping the memory where input data83* will be copied to.84* @src_dma_list: The OCS DMA list mapping input data.85* @src_size: The amount of data to copy.86*/87static inline int ocs_aes_bypass_op(struct ocs_aes_dev *aes_dev,88dma_addr_t dst_dma_list,89dma_addr_t src_dma_list, u32 src_size)90{91return ocs_aes_op(aes_dev, OCS_MODE_ECB, OCS_AES, OCS_BYPASS,92dst_dma_list, src_dma_list, src_size, NULL, 0);93}9495int ocs_aes_gcm_op(struct ocs_aes_dev *aes_dev,96enum ocs_cipher cipher,97enum ocs_instruction instruction,98dma_addr_t dst_dma_list,99dma_addr_t src_dma_list,100u32 src_size,101const u8 *iv,102dma_addr_t aad_dma_list,103u32 aad_size,104u8 *out_tag,105u32 tag_size);106107int ocs_aes_ccm_op(struct ocs_aes_dev *aes_dev,108enum ocs_cipher cipher,109enum ocs_instruction instruction,110dma_addr_t dst_dma_list,111dma_addr_t src_dma_list,112u32 src_size,113u8 *iv,114dma_addr_t adata_dma_list,115u32 adata_size,116u8 *in_tag,117u32 tag_size);118119int ocs_create_linked_list_from_sg(const struct ocs_aes_dev *aes_dev,120struct scatterlist *sg,121int sg_dma_count,122struct ocs_dll_desc *dll_desc,123size_t data_size,124size_t data_offset);125126irqreturn_t ocs_aes_irq_handler(int irq, void *dev_id);127128#endif129130131