Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Intel Keem Bay OCS AES Crypto Driver.
0004  *
0005  * Copyright (C) 2018-2020 Intel Corporation
0006  */
0007 
0008 #ifndef _CRYPTO_OCS_AES_H
0009 #define _CRYPTO_OCS_AES_H
0010 
0011 #include <linux/dma-mapping.h>
0012 
0013 enum ocs_cipher {
0014     OCS_AES = 0,
0015     OCS_SM4 = 1,
0016 };
0017 
0018 enum ocs_mode {
0019     OCS_MODE_ECB = 0,
0020     OCS_MODE_CBC = 1,
0021     OCS_MODE_CTR = 2,
0022     OCS_MODE_CCM = 6,
0023     OCS_MODE_GCM = 7,
0024     OCS_MODE_CTS = 9,
0025 };
0026 
0027 enum ocs_instruction {
0028     OCS_ENCRYPT = 0,
0029     OCS_DECRYPT = 1,
0030     OCS_EXPAND  = 2,
0031     OCS_BYPASS  = 3,
0032 };
0033 
0034 /**
0035  * struct ocs_aes_dev - AES device context.
0036  * @list:           List head for insertion into device list hold
0037  *              by driver.
0038  * @dev:            OCS AES device.
0039  * @irq:            IRQ number.
0040  * @base_reg:           IO base address of OCS AES.
0041  * @irq_copy_completion:    Completion to indicate IRQ has been triggered.
0042  * @dma_err_mask:       Error reported by OCS DMA interrupts.
0043  * @engine:         Crypto engine for the device.
0044  */
0045 struct ocs_aes_dev {
0046     struct list_head list;
0047     struct device *dev;
0048     int irq;
0049     void __iomem *base_reg;
0050     struct completion irq_completion;
0051     u32 dma_err_mask;
0052     struct crypto_engine *engine;
0053 };
0054 
0055 /**
0056  * struct ocs_dll_desc - Descriptor of an OCS DMA Linked List.
0057  * @vaddr:  Virtual address of the linked list head.
0058  * @dma_addr:   DMA address of the linked list head.
0059  * @size:   Size (in bytes) of the linked list.
0060  */
0061 struct ocs_dll_desc {
0062     void        *vaddr;
0063     dma_addr_t  dma_addr;
0064     size_t      size;
0065 };
0066 
0067 int ocs_aes_set_key(struct ocs_aes_dev *aes_dev, const u32 key_size,
0068             const u8 *key, const enum ocs_cipher cipher);
0069 
0070 int ocs_aes_op(struct ocs_aes_dev *aes_dev,
0071            enum ocs_mode mode,
0072            enum ocs_cipher cipher,
0073            enum ocs_instruction instruction,
0074            dma_addr_t dst_dma_list,
0075            dma_addr_t src_dma_list,
0076            u32 src_size,
0077            u8 *iv,
0078            u32 iv_size);
0079 
0080 /**
0081  * ocs_aes_bypass_op() - Use OCS DMA to copy data.
0082  * @aes_dev:            The OCS AES device to use.
0083  * @dst_dma_list:   The OCS DMA list mapping the memory where input data
0084  *          will be copied to.
0085  * @src_dma_list:   The OCS DMA list mapping input data.
0086  * @src_size:       The amount of data to copy.
0087  */
0088 static inline int ocs_aes_bypass_op(struct ocs_aes_dev *aes_dev,
0089                     dma_addr_t dst_dma_list,
0090                     dma_addr_t src_dma_list, u32 src_size)
0091 {
0092     return ocs_aes_op(aes_dev, OCS_MODE_ECB, OCS_AES, OCS_BYPASS,
0093               dst_dma_list, src_dma_list, src_size, NULL, 0);
0094 }
0095 
0096 int ocs_aes_gcm_op(struct ocs_aes_dev *aes_dev,
0097            enum ocs_cipher cipher,
0098            enum ocs_instruction instruction,
0099            dma_addr_t dst_dma_list,
0100            dma_addr_t src_dma_list,
0101            u32 src_size,
0102            const u8 *iv,
0103            dma_addr_t aad_dma_list,
0104            u32 aad_size,
0105            u8 *out_tag,
0106            u32 tag_size);
0107 
0108 int ocs_aes_ccm_op(struct ocs_aes_dev *aes_dev,
0109            enum ocs_cipher cipher,
0110            enum ocs_instruction instruction,
0111            dma_addr_t dst_dma_list,
0112            dma_addr_t src_dma_list,
0113            u32 src_size,
0114            u8 *iv,
0115            dma_addr_t adata_dma_list,
0116            u32 adata_size,
0117            u8 *in_tag,
0118            u32 tag_size);
0119 
0120 int ocs_create_linked_list_from_sg(const struct ocs_aes_dev *aes_dev,
0121                    struct scatterlist *sg,
0122                    int sg_dma_count,
0123                    struct ocs_dll_desc *dll_desc,
0124                    size_t data_size,
0125                    size_t data_offset);
0126 
0127 irqreturn_t ocs_aes_irq_handler(int irq, void *dev_id);
0128 
0129 #endif