blob: 7023d4dcdfcc9af61a391d02f29d45b976f5cde1 [file] [log] [blame]
#ifndef ASR_AES_H
#define ASR_AES_H
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/crypto.h>
#include <crypto/aes.h>
#include <crypto/scatterwalk.h>
#include <crypto/algapi.h>
#include <crypto/internal/skcipher.h>
/* AES flags */
#define AES_FLAGS_ENCRYPT (1 << 0)
#define AES_FLAGS_ECB (0 << 1)
#define AES_FLAGS_CBC (1 << 1)
#define AES_FLAGS_OPMODE_MASK (3 << 1)
#define AES_FLAGS_BUSY (1 << 3)
#define AES_FLAGS_DMA (1 << 4)
#define AES_FLAGS_MODE_MASK (AES_FLAGS_OPMODE_MASK | \
AES_FLAGS_ENCRYPT)
#define AES_FLAGS_PERSISTENT AES_FLAGS_BUSY
#define BIT_SET (1)
#define BIT_CLR (0)
#define ASR_AES_QUEUE_LENGTH 50
#define ASR_AES_PRIORITY 300
#define ASR_AES_BUFFER_ORDER 2
#define ASR_AES_BUFFER_SIZE (PAGE_SIZE << ASR_AES_BUFFER_ORDER)
#define ASR_AES_DMA_THRESHOLD (256)
#define ASR_AES_HWKEY (1 << 0)
enum {
AES_DECRYPT = 0,
AES_ENCRYPT = 1,
};
struct asr_geu_aes;
typedef int (*asr_aes_fn_t)(struct asr_geu_aes *);
typedef irqreturn_t (*asr_geu_irq_t)(u32, void *);
struct asr_aes_ctx {
struct asr_geu_aes *dd;
asr_aes_fn_t start;
int keylen;
u32 key[AES_KEYSIZE_256 / sizeof(u32)];
u16 block_size;
bool use_rkek;
};
struct asr_aes_reqctx {
unsigned long mode;
bool use_rkek;
u32 lastc[AES_BLOCK_SIZE / sizeof(u32)];
};
struct asr_aes_dma {
struct dma_chan *chan;
struct scatterlist *sg;
int nents;
unsigned int remainder;
unsigned int sg_len;
};
struct asr_geu_aes {
struct device *dev;
#ifndef CONFIG_OPTEE
void __iomem *io_base;
unsigned long phys_base;
#endif
struct crypto_async_request *areq;
struct asr_aes_ctx *ctx;
bool is_async;
bool rkek_burned;
unsigned long flags;
spinlock_t lock;
struct crypto_queue queue;
struct tasklet_struct queue_task;
int int_mode;
asr_aes_fn_t resume;
asr_aes_fn_t cpu_transfer_complete;
asr_geu_irq_t aes_irq;
struct tasklet_struct done_task;
#ifndef CONFIG_OPTEE
size_t total;
size_t datalen;
u32 *data;
struct asr_aes_dma src;
struct asr_aes_dma dst;
size_t buflen;
void *buf;
struct scatterlist aligned_sg;
struct scatterlist *real_dst;
#endif
};
#endif