xref: /linux/drivers/crypto/ti/dthev2-common.h (revision a619fe35ab41fded440d3762d4fbad84ff86a4d4)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * K3 DTHE V2 crypto accelerator driver
4  *
5  * Copyright (C) Texas Instruments 2025 - https://www.ti.com
6  * Author: T Pratham <t-pratham@ti.com>
7  */
8 
9 #ifndef __TI_DTHEV2_H__
10 #define __TI_DTHEV2_H__
11 
12 #include <crypto/aead.h>
13 #include <crypto/aes.h>
14 #include <crypto/algapi.h>
15 #include <crypto/engine.h>
16 #include <crypto/hash.h>
17 #include <crypto/internal/aead.h>
18 #include <crypto/internal/hash.h>
19 #include <crypto/internal/skcipher.h>
20 
21 #include <linux/delay.h>
22 #include <linux/dmaengine.h>
23 #include <linux/dmapool.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/io.h>
26 #include <linux/scatterlist.h>
27 
28 #define DTHE_REG_SIZE		4
29 #define DTHE_DMA_TIMEOUT_MS	2000
30 /*
31  * Size of largest possible key (of all algorithms) to be stored in dthe_tfm_ctx
32  * This is currently the keysize of XTS-AES-256 which is 512 bits (64 bytes)
33  */
34 #define DTHE_MAX_KEYSIZE	(AES_MAX_KEY_SIZE * 2)
35 
36 enum dthe_aes_mode {
37 	DTHE_AES_ECB = 0,
38 	DTHE_AES_CBC,
39 	DTHE_AES_XTS,
40 };
41 
42 /* Driver specific struct definitions */
43 
44 /**
45  * struct dthe_data - DTHE_V2 driver instance data
46  * @dev: Device pointer
47  * @regs: Base address of the register space
48  * @list: list node for dev
49  * @engine: Crypto engine instance
50  * @dma_aes_rx: AES Rx DMA Channel
51  * @dma_aes_tx: AES Tx DMA Channel
52  * @dma_sha_tx: SHA Tx DMA Channel
53  */
54 struct dthe_data {
55 	struct device *dev;
56 	void __iomem *regs;
57 	struct list_head list;
58 	struct crypto_engine *engine;
59 
60 	struct dma_chan *dma_aes_rx;
61 	struct dma_chan *dma_aes_tx;
62 
63 	struct dma_chan *dma_sha_tx;
64 };
65 
66 /**
67  * struct dthe_list - device data list head
68  * @dev_list: linked list head
69  * @lock: Spinlock protecting accesses to the list
70  */
71 struct dthe_list {
72 	struct list_head dev_list;
73 	spinlock_t lock;
74 };
75 
76 /**
77  * struct dthe_tfm_ctx - Transform ctx struct containing ctx for all sub-components of DTHE V2
78  * @dev_data: Device data struct pointer
79  * @keylen: AES key length
80  * @key: AES key
81  * @aes_mode: AES mode
82  * @skcipher_fb: Fallback crypto skcipher handle for AES-XTS mode
83  */
84 struct dthe_tfm_ctx {
85 	struct dthe_data *dev_data;
86 	unsigned int keylen;
87 	u32 key[DTHE_MAX_KEYSIZE / sizeof(u32)];
88 	enum dthe_aes_mode aes_mode;
89 	struct crypto_sync_skcipher *skcipher_fb;
90 };
91 
92 /**
93  * struct dthe_aes_req_ctx - AES engine req ctx struct
94  * @enc: flag indicating encryption or decryption operation
95  * @aes_compl: Completion variable for use in manual completion in case of DMA callback failure
96  */
97 struct dthe_aes_req_ctx {
98 	int enc;
99 	struct completion aes_compl;
100 };
101 
102 /* Struct definitions end */
103 
104 struct dthe_data *dthe_get_dev(struct dthe_tfm_ctx *ctx);
105 
106 int dthe_register_aes_algs(void);
107 void dthe_unregister_aes_algs(void);
108 
109 #endif
110