xref: /linux/drivers/crypto/ti/dthev2-common.h (revision 8a7c601e14576a22c2bbf7f67455ccf3f3d2737f)
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 enum dthe_aes_mode {
32 	DTHE_AES_ECB = 0,
33 	DTHE_AES_CBC,
34 };
35 
36 /* Driver specific struct definitions */
37 
38 /**
39  * struct dthe_data - DTHE_V2 driver instance data
40  * @dev: Device pointer
41  * @regs: Base address of the register space
42  * @list: list node for dev
43  * @engine: Crypto engine instance
44  * @dma_aes_rx: AES Rx DMA Channel
45  * @dma_aes_tx: AES Tx DMA Channel
46  * @dma_sha_tx: SHA Tx DMA Channel
47  */
48 struct dthe_data {
49 	struct device *dev;
50 	void __iomem *regs;
51 	struct list_head list;
52 	struct crypto_engine *engine;
53 
54 	struct dma_chan *dma_aes_rx;
55 	struct dma_chan *dma_aes_tx;
56 
57 	struct dma_chan *dma_sha_tx;
58 };
59 
60 /**
61  * struct dthe_list - device data list head
62  * @dev_list: linked list head
63  * @lock: Spinlock protecting accesses to the list
64  */
65 struct dthe_list {
66 	struct list_head dev_list;
67 	spinlock_t lock;
68 };
69 
70 /**
71  * struct dthe_tfm_ctx - Transform ctx struct containing ctx for all sub-components of DTHE V2
72  * @dev_data: Device data struct pointer
73  * @keylen: AES key length
74  * @key: AES key
75  * @aes_mode: AES mode
76  */
77 struct dthe_tfm_ctx {
78 	struct dthe_data *dev_data;
79 	unsigned int keylen;
80 	u32 key[AES_KEYSIZE_256 / sizeof(u32)];
81 	enum dthe_aes_mode aes_mode;
82 };
83 
84 /**
85  * struct dthe_aes_req_ctx - AES engine req ctx struct
86  * @enc: flag indicating encryption or decryption operation
87  * @aes_compl: Completion variable for use in manual completion in case of DMA callback failure
88  */
89 struct dthe_aes_req_ctx {
90 	int enc;
91 	struct completion aes_compl;
92 };
93 
94 /* Struct definitions end */
95 
96 struct dthe_data *dthe_get_dev(struct dthe_tfm_ctx *ctx);
97 
98 int dthe_register_aes_algs(void);
99 void dthe_unregister_aes_algs(void);
100 
101 #endif
102