xref: /OK3568_Linux_fs/kernel/drivers/crypto/ux500/hash/hash_alg.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (C) ST-Ericsson SA 2010
4*4882a593Smuzhiyun  * Author: Shujuan Chen (shujuan.chen@stericsson.com)
5*4882a593Smuzhiyun  * Author: Joakim Bech (joakim.xx.bech@stericsson.com)
6*4882a593Smuzhiyun  * Author: Berne Hebark (berne.hebark@stericsson.com))
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun #ifndef _HASH_ALG_H
9*4882a593Smuzhiyun #define _HASH_ALG_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <linux/bitops.h>
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #define HASH_BLOCK_SIZE			64
14*4882a593Smuzhiyun #define HASH_DMA_FIFO			4
15*4882a593Smuzhiyun #define HASH_DMA_ALIGN_SIZE		4
16*4882a593Smuzhiyun #define HASH_DMA_PERFORMANCE_MIN_SIZE	1024
17*4882a593Smuzhiyun #define HASH_BYTES_PER_WORD		4
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun /* Maximum value of the length's high word */
20*4882a593Smuzhiyun #define HASH_HIGH_WORD_MAX_VAL		0xFFFFFFFFUL
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /* Power on Reset values HASH registers */
23*4882a593Smuzhiyun #define HASH_RESET_CR_VALUE		0x0
24*4882a593Smuzhiyun #define HASH_RESET_STR_VALUE		0x0
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun /* Number of context swap registers */
27*4882a593Smuzhiyun #define HASH_CSR_COUNT			52
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #define HASH_RESET_CSRX_REG_VALUE	0x0
30*4882a593Smuzhiyun #define HASH_RESET_CSFULL_REG_VALUE	0x0
31*4882a593Smuzhiyun #define HASH_RESET_CSDATAIN_REG_VALUE	0x0
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #define HASH_RESET_INDEX_VAL		0x0
34*4882a593Smuzhiyun #define HASH_RESET_BIT_INDEX_VAL	0x0
35*4882a593Smuzhiyun #define HASH_RESET_BUFFER_VAL		0x0
36*4882a593Smuzhiyun #define HASH_RESET_LEN_HIGH_VAL		0x0
37*4882a593Smuzhiyun #define HASH_RESET_LEN_LOW_VAL		0x0
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /* Control register bitfields */
40*4882a593Smuzhiyun #define HASH_CR_RESUME_MASK	0x11FCF
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun #define HASH_CR_SWITCHON_POS	31
43*4882a593Smuzhiyun #define HASH_CR_SWITCHON_MASK	BIT(31)
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun #define HASH_CR_EMPTYMSG_POS	20
46*4882a593Smuzhiyun #define HASH_CR_EMPTYMSG_MASK	BIT(20)
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun #define HASH_CR_DINF_POS	12
49*4882a593Smuzhiyun #define HASH_CR_DINF_MASK	BIT(12)
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun #define HASH_CR_NBW_POS		8
52*4882a593Smuzhiyun #define HASH_CR_NBW_MASK	0x00000F00UL
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun #define HASH_CR_LKEY_POS	16
55*4882a593Smuzhiyun #define HASH_CR_LKEY_MASK	BIT(16)
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun #define HASH_CR_ALGO_POS	7
58*4882a593Smuzhiyun #define HASH_CR_ALGO_MASK	BIT(7)
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun #define HASH_CR_MODE_POS	6
61*4882a593Smuzhiyun #define HASH_CR_MODE_MASK	BIT(6)
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun #define HASH_CR_DATAFORM_POS	4
64*4882a593Smuzhiyun #define HASH_CR_DATAFORM_MASK	(BIT(4) | BIT(5))
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun #define HASH_CR_DMAE_POS	3
67*4882a593Smuzhiyun #define HASH_CR_DMAE_MASK	BIT(3)
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun #define HASH_CR_INIT_POS	2
70*4882a593Smuzhiyun #define HASH_CR_INIT_MASK	BIT(2)
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun #define HASH_CR_PRIVN_POS	1
73*4882a593Smuzhiyun #define HASH_CR_PRIVN_MASK	BIT(1)
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun #define HASH_CR_SECN_POS	0
76*4882a593Smuzhiyun #define HASH_CR_SECN_MASK	BIT(0)
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun /* Start register bitfields */
79*4882a593Smuzhiyun #define HASH_STR_DCAL_POS	8
80*4882a593Smuzhiyun #define HASH_STR_DCAL_MASK	BIT(8)
81*4882a593Smuzhiyun #define HASH_STR_DEFAULT	0x0
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun #define HASH_STR_NBLW_POS	0
84*4882a593Smuzhiyun #define HASH_STR_NBLW_MASK	0x0000001FUL
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun #define HASH_NBLW_MAX_VAL	0x1F
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun /* PrimeCell IDs */
89*4882a593Smuzhiyun #define HASH_P_ID0		0xE0
90*4882a593Smuzhiyun #define HASH_P_ID1		0x05
91*4882a593Smuzhiyun #define HASH_P_ID2		0x38
92*4882a593Smuzhiyun #define HASH_P_ID3		0x00
93*4882a593Smuzhiyun #define HASH_CELL_ID0		0x0D
94*4882a593Smuzhiyun #define HASH_CELL_ID1		0xF0
95*4882a593Smuzhiyun #define HASH_CELL_ID2		0x05
96*4882a593Smuzhiyun #define HASH_CELL_ID3		0xB1
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun #define HASH_SET_BITS(reg_name, mask)	\
99*4882a593Smuzhiyun 	writel_relaxed((readl_relaxed(reg_name) | mask), reg_name)
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun #define HASH_CLEAR_BITS(reg_name, mask)	\
102*4882a593Smuzhiyun 	writel_relaxed((readl_relaxed(reg_name) & ~mask), reg_name)
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun #define HASH_PUT_BITS(reg, val, shift, mask)	\
105*4882a593Smuzhiyun 	writel_relaxed(((readl(reg) & ~(mask)) |	\
106*4882a593Smuzhiyun 		(((u32)val << shift) & (mask))), reg)
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun #define HASH_SET_DIN(val, len)	writesl(&device_data->base->din, (val), (len))
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun #define HASH_INITIALIZE			\
111*4882a593Smuzhiyun 	HASH_PUT_BITS(			\
112*4882a593Smuzhiyun 		&device_data->base->cr,	\
113*4882a593Smuzhiyun 		0x01, HASH_CR_INIT_POS,	\
114*4882a593Smuzhiyun 		HASH_CR_INIT_MASK)
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun #define HASH_SET_DATA_FORMAT(data_format)				\
117*4882a593Smuzhiyun 		HASH_PUT_BITS(						\
118*4882a593Smuzhiyun 			&device_data->base->cr,				\
119*4882a593Smuzhiyun 			(u32) (data_format), HASH_CR_DATAFORM_POS,	\
120*4882a593Smuzhiyun 			HASH_CR_DATAFORM_MASK)
121*4882a593Smuzhiyun #define HASH_SET_NBLW(val)					\
122*4882a593Smuzhiyun 		HASH_PUT_BITS(					\
123*4882a593Smuzhiyun 			&device_data->base->str,		\
124*4882a593Smuzhiyun 			(u32) (val), HASH_STR_NBLW_POS,		\
125*4882a593Smuzhiyun 			HASH_STR_NBLW_MASK)
126*4882a593Smuzhiyun #define HASH_SET_DCAL					\
127*4882a593Smuzhiyun 		HASH_PUT_BITS(				\
128*4882a593Smuzhiyun 			&device_data->base->str,	\
129*4882a593Smuzhiyun 			0x01, HASH_STR_DCAL_POS,	\
130*4882a593Smuzhiyun 			HASH_STR_DCAL_MASK)
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun /* Hardware access method */
133*4882a593Smuzhiyun enum hash_mode {
134*4882a593Smuzhiyun 	HASH_MODE_CPU,
135*4882a593Smuzhiyun 	HASH_MODE_DMA
136*4882a593Smuzhiyun };
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun /**
139*4882a593Smuzhiyun  * struct uint64 - Structure to handle 64 bits integers.
140*4882a593Smuzhiyun  * @high_word:	Most significant bits.
141*4882a593Smuzhiyun  * @low_word:	Least significant bits.
142*4882a593Smuzhiyun  *
143*4882a593Smuzhiyun  * Used to handle 64 bits integers.
144*4882a593Smuzhiyun  */
145*4882a593Smuzhiyun struct uint64 {
146*4882a593Smuzhiyun 	u32 high_word;
147*4882a593Smuzhiyun 	u32 low_word;
148*4882a593Smuzhiyun };
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun /**
151*4882a593Smuzhiyun  * struct hash_register - Contains all registers in ux500 hash hardware.
152*4882a593Smuzhiyun  * @cr:		HASH control register (0x000).
153*4882a593Smuzhiyun  * @din:	HASH data input register (0x004).
154*4882a593Smuzhiyun  * @str:	HASH start register (0x008).
155*4882a593Smuzhiyun  * @hx:		HASH digest register 0..7 (0x00c-0x01C).
156*4882a593Smuzhiyun  * @padding0:	Reserved (0x02C).
157*4882a593Smuzhiyun  * @itcr:	Integration test control register (0x080).
158*4882a593Smuzhiyun  * @itip:	Integration test input register (0x084).
159*4882a593Smuzhiyun  * @itop:	Integration test output register (0x088).
160*4882a593Smuzhiyun  * @padding1:	Reserved (0x08C).
161*4882a593Smuzhiyun  * @csfull:	HASH context full register (0x0F8).
162*4882a593Smuzhiyun  * @csdatain:	HASH context swap data input register (0x0FC).
163*4882a593Smuzhiyun  * @csrx:	HASH context swap register 0..51 (0x100-0x1CC).
164*4882a593Smuzhiyun  * @padding2:	Reserved (0x1D0).
165*4882a593Smuzhiyun  * @periphid0:	HASH peripheral identification register 0 (0xFE0).
166*4882a593Smuzhiyun  * @periphid1:	HASH peripheral identification register 1 (0xFE4).
167*4882a593Smuzhiyun  * @periphid2:	HASH peripheral identification register 2 (0xFE8).
168*4882a593Smuzhiyun  * @periphid3:	HASH peripheral identification register 3 (0xFEC).
169*4882a593Smuzhiyun  * @cellid0:	HASH PCell identification register 0 (0xFF0).
170*4882a593Smuzhiyun  * @cellid1:	HASH PCell identification register 1 (0xFF4).
171*4882a593Smuzhiyun  * @cellid2:	HASH PCell identification register 2 (0xFF8).
172*4882a593Smuzhiyun  * @cellid3:	HASH PCell identification register 3 (0xFFC).
173*4882a593Smuzhiyun  *
174*4882a593Smuzhiyun  * The device communicates to the HASH via 32-bit-wide control registers
175*4882a593Smuzhiyun  * accessible via the 32-bit width AMBA rev. 2.0 AHB Bus. Below is a structure
176*4882a593Smuzhiyun  * with the registers used.
177*4882a593Smuzhiyun  */
178*4882a593Smuzhiyun struct hash_register {
179*4882a593Smuzhiyun 	u32 cr;
180*4882a593Smuzhiyun 	u32 din;
181*4882a593Smuzhiyun 	u32 str;
182*4882a593Smuzhiyun 	u32 hx[8];
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun 	u32 padding0[(0x080 - 0x02C) / sizeof(u32)];
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun 	u32 itcr;
187*4882a593Smuzhiyun 	u32 itip;
188*4882a593Smuzhiyun 	u32 itop;
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun 	u32 padding1[(0x0F8 - 0x08C) / sizeof(u32)];
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun 	u32 csfull;
193*4882a593Smuzhiyun 	u32 csdatain;
194*4882a593Smuzhiyun 	u32 csrx[HASH_CSR_COUNT];
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun 	u32 padding2[(0xFE0 - 0x1D0) / sizeof(u32)];
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun 	u32 periphid0;
199*4882a593Smuzhiyun 	u32 periphid1;
200*4882a593Smuzhiyun 	u32 periphid2;
201*4882a593Smuzhiyun 	u32 periphid3;
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 	u32 cellid0;
204*4882a593Smuzhiyun 	u32 cellid1;
205*4882a593Smuzhiyun 	u32 cellid2;
206*4882a593Smuzhiyun 	u32 cellid3;
207*4882a593Smuzhiyun };
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun /**
210*4882a593Smuzhiyun  * struct hash_state - Hash context state.
211*4882a593Smuzhiyun  * @temp_cr:	Temporary HASH Control Register.
212*4882a593Smuzhiyun  * @str_reg:	HASH Start Register.
213*4882a593Smuzhiyun  * @din_reg:	HASH Data Input Register.
214*4882a593Smuzhiyun  * @csr[52]:	HASH Context Swap Registers 0-39.
215*4882a593Smuzhiyun  * @csfull:	HASH Context Swap Registers 40 ie Status flags.
216*4882a593Smuzhiyun  * @csdatain:	HASH Context Swap Registers 41 ie Input data.
217*4882a593Smuzhiyun  * @buffer:	Working buffer for messages going to the hardware.
218*4882a593Smuzhiyun  * @length:	Length of the part of message hashed so far (floor(N/64) * 64).
219*4882a593Smuzhiyun  * @index:	Valid number of bytes in buffer (N % 64).
220*4882a593Smuzhiyun  * @bit_index:	Valid number of bits in buffer (N % 8).
221*4882a593Smuzhiyun  *
222*4882a593Smuzhiyun  * This structure is used between context switches, i.e. when ongoing jobs are
223*4882a593Smuzhiyun  * interupted with new jobs. When this happens we need to store intermediate
224*4882a593Smuzhiyun  * results in software.
225*4882a593Smuzhiyun  *
226*4882a593Smuzhiyun  * WARNING: "index" is the  member of the structure, to be sure  that "buffer"
227*4882a593Smuzhiyun  * is aligned on a 4-bytes boundary. This is highly implementation dependent
228*4882a593Smuzhiyun  * and MUST be checked whenever this code is ported on new platforms.
229*4882a593Smuzhiyun  */
230*4882a593Smuzhiyun struct hash_state {
231*4882a593Smuzhiyun 	u32		temp_cr;
232*4882a593Smuzhiyun 	u32		str_reg;
233*4882a593Smuzhiyun 	u32		din_reg;
234*4882a593Smuzhiyun 	u32		csr[52];
235*4882a593Smuzhiyun 	u32		csfull;
236*4882a593Smuzhiyun 	u32		csdatain;
237*4882a593Smuzhiyun 	u32		buffer[HASH_BLOCK_SIZE / sizeof(u32)];
238*4882a593Smuzhiyun 	struct uint64	length;
239*4882a593Smuzhiyun 	u8		index;
240*4882a593Smuzhiyun 	u8		bit_index;
241*4882a593Smuzhiyun };
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun /**
244*4882a593Smuzhiyun  * enum hash_device_id - HASH device ID.
245*4882a593Smuzhiyun  * @HASH_DEVICE_ID_0: Hash hardware with ID 0
246*4882a593Smuzhiyun  * @HASH_DEVICE_ID_1: Hash hardware with ID 1
247*4882a593Smuzhiyun  */
248*4882a593Smuzhiyun enum hash_device_id {
249*4882a593Smuzhiyun 	HASH_DEVICE_ID_0 = 0,
250*4882a593Smuzhiyun 	HASH_DEVICE_ID_1 = 1
251*4882a593Smuzhiyun };
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun /**
254*4882a593Smuzhiyun  * enum hash_data_format - HASH data format.
255*4882a593Smuzhiyun  * @HASH_DATA_32_BITS:	32 bits data format
256*4882a593Smuzhiyun  * @HASH_DATA_16_BITS:	16 bits data format
257*4882a593Smuzhiyun  * @HASH_DATA_8_BITS:	8 bits data format.
258*4882a593Smuzhiyun  * @HASH_DATA_1_BITS:	1 bit data format.
259*4882a593Smuzhiyun  */
260*4882a593Smuzhiyun enum hash_data_format {
261*4882a593Smuzhiyun 	HASH_DATA_32_BITS	= 0x0,
262*4882a593Smuzhiyun 	HASH_DATA_16_BITS	= 0x1,
263*4882a593Smuzhiyun 	HASH_DATA_8_BITS	= 0x2,
264*4882a593Smuzhiyun 	HASH_DATA_1_BIT		= 0x3
265*4882a593Smuzhiyun };
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun /**
268*4882a593Smuzhiyun  * enum hash_algo - Enumeration for selecting between SHA1 or SHA2 algorithm.
269*4882a593Smuzhiyun  * @HASH_ALGO_SHA1: Indicates that SHA1 is used.
270*4882a593Smuzhiyun  * @HASH_ALGO_SHA2: Indicates that SHA2 (SHA256) is used.
271*4882a593Smuzhiyun  */
272*4882a593Smuzhiyun enum hash_algo {
273*4882a593Smuzhiyun 	HASH_ALGO_SHA1		= 0x0,
274*4882a593Smuzhiyun 	HASH_ALGO_SHA256	= 0x1
275*4882a593Smuzhiyun };
276*4882a593Smuzhiyun 
277*4882a593Smuzhiyun /**
278*4882a593Smuzhiyun  * enum hash_op - Enumeration for selecting between HASH or HMAC mode.
279*4882a593Smuzhiyun  * @HASH_OPER_MODE_HASH: Indicates usage of normal HASH mode.
280*4882a593Smuzhiyun  * @HASH_OPER_MODE_HMAC: Indicates usage of HMAC.
281*4882a593Smuzhiyun  */
282*4882a593Smuzhiyun enum hash_op {
283*4882a593Smuzhiyun 	HASH_OPER_MODE_HASH = 0x0,
284*4882a593Smuzhiyun 	HASH_OPER_MODE_HMAC = 0x1
285*4882a593Smuzhiyun };
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun /**
288*4882a593Smuzhiyun  * struct hash_config - Configuration data for the hardware.
289*4882a593Smuzhiyun  * @data_format:	Format of data entered into the hash data in register.
290*4882a593Smuzhiyun  * @algorithm:		Algorithm selection bit.
291*4882a593Smuzhiyun  * @oper_mode:		Operating mode selection bit.
292*4882a593Smuzhiyun  */
293*4882a593Smuzhiyun struct hash_config {
294*4882a593Smuzhiyun 	int data_format;
295*4882a593Smuzhiyun 	int algorithm;
296*4882a593Smuzhiyun 	int oper_mode;
297*4882a593Smuzhiyun };
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun /**
300*4882a593Smuzhiyun  * struct hash_dma - Structure used for dma.
301*4882a593Smuzhiyun  * @mask:		DMA capabilities bitmap mask.
302*4882a593Smuzhiyun  * @complete:		Used to maintain state for a "completion".
303*4882a593Smuzhiyun  * @chan_mem2hash:	DMA channel.
304*4882a593Smuzhiyun  * @cfg_mem2hash:	DMA channel configuration.
305*4882a593Smuzhiyun  * @sg_len:		Scatterlist length.
306*4882a593Smuzhiyun  * @sg:			Scatterlist.
307*4882a593Smuzhiyun  * @nents:		Number of sg entries.
308*4882a593Smuzhiyun  */
309*4882a593Smuzhiyun struct hash_dma {
310*4882a593Smuzhiyun 	dma_cap_mask_t		mask;
311*4882a593Smuzhiyun 	struct completion	complete;
312*4882a593Smuzhiyun 	struct dma_chan		*chan_mem2hash;
313*4882a593Smuzhiyun 	void			*cfg_mem2hash;
314*4882a593Smuzhiyun 	int			sg_len;
315*4882a593Smuzhiyun 	struct scatterlist	*sg;
316*4882a593Smuzhiyun 	int			nents;
317*4882a593Smuzhiyun };
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun /**
320*4882a593Smuzhiyun  * struct hash_ctx - The context used for hash calculations.
321*4882a593Smuzhiyun  * @key:	The key used in the operation.
322*4882a593Smuzhiyun  * @keylen:	The length of the key.
323*4882a593Smuzhiyun  * @state:	The state of the current calculations.
324*4882a593Smuzhiyun  * @config:	The current configuration.
325*4882a593Smuzhiyun  * @digestsize:	The size of current digest.
326*4882a593Smuzhiyun  * @device:	Pointer to the device structure.
327*4882a593Smuzhiyun  */
328*4882a593Smuzhiyun struct hash_ctx {
329*4882a593Smuzhiyun 	u8			*key;
330*4882a593Smuzhiyun 	u32			keylen;
331*4882a593Smuzhiyun 	struct hash_config	config;
332*4882a593Smuzhiyun 	int			digestsize;
333*4882a593Smuzhiyun 	struct hash_device_data	*device;
334*4882a593Smuzhiyun };
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun /**
337*4882a593Smuzhiyun  * struct hash_ctx - The request context used for hash calculations.
338*4882a593Smuzhiyun  * @state:	The state of the current calculations.
339*4882a593Smuzhiyun  * @dma_mode:	Used in special cases (workaround), e.g. need to change to
340*4882a593Smuzhiyun  *		cpu mode, if not supported/working in dma mode.
341*4882a593Smuzhiyun  * @updated:	Indicates if hardware is initialized for new operations.
342*4882a593Smuzhiyun  */
343*4882a593Smuzhiyun struct hash_req_ctx {
344*4882a593Smuzhiyun 	struct hash_state	state;
345*4882a593Smuzhiyun 	bool			dma_mode;
346*4882a593Smuzhiyun 	u8			updated;
347*4882a593Smuzhiyun };
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun /**
350*4882a593Smuzhiyun  * struct hash_device_data - structure for a hash device.
351*4882a593Smuzhiyun  * @base:		Pointer to virtual base address of the hash device.
352*4882a593Smuzhiyun  * @phybase:		Pointer to physical memory location of the hash device.
353*4882a593Smuzhiyun  * @list_node:		For inclusion in klist.
354*4882a593Smuzhiyun  * @dev:		Pointer to the device dev structure.
355*4882a593Smuzhiyun  * @ctx_lock:		Spinlock for current_ctx.
356*4882a593Smuzhiyun  * @current_ctx:	Pointer to the currently allocated context.
357*4882a593Smuzhiyun  * @power_state:	TRUE = power state on, FALSE = power state off.
358*4882a593Smuzhiyun  * @power_state_lock:	Spinlock for power_state.
359*4882a593Smuzhiyun  * @regulator:		Pointer to the device's power control.
360*4882a593Smuzhiyun  * @clk:		Pointer to the device's clock control.
361*4882a593Smuzhiyun  * @restore_dev_state:	TRUE = saved state, FALSE = no saved state.
362*4882a593Smuzhiyun  * @dma:		Structure used for dma.
363*4882a593Smuzhiyun  */
364*4882a593Smuzhiyun struct hash_device_data {
365*4882a593Smuzhiyun 	struct hash_register __iomem	*base;
366*4882a593Smuzhiyun 	phys_addr_t             phybase;
367*4882a593Smuzhiyun 	struct klist_node	list_node;
368*4882a593Smuzhiyun 	struct device		*dev;
369*4882a593Smuzhiyun 	spinlock_t		ctx_lock;
370*4882a593Smuzhiyun 	struct hash_ctx		*current_ctx;
371*4882a593Smuzhiyun 	bool			power_state;
372*4882a593Smuzhiyun 	spinlock_t		power_state_lock;
373*4882a593Smuzhiyun 	struct regulator	*regulator;
374*4882a593Smuzhiyun 	struct clk		*clk;
375*4882a593Smuzhiyun 	bool			restore_dev_state;
376*4882a593Smuzhiyun 	struct hash_state	state; /* Used for saving and resuming state */
377*4882a593Smuzhiyun 	struct hash_dma		dma;
378*4882a593Smuzhiyun };
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun int hash_check_hw(struct hash_device_data *device_data);
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun int hash_setconfiguration(struct hash_device_data *device_data,
383*4882a593Smuzhiyun 		struct hash_config *config);
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun void hash_begin(struct hash_device_data *device_data, struct hash_ctx *ctx);
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun void hash_get_digest(struct hash_device_data *device_data,
388*4882a593Smuzhiyun 		u8 *digest, int algorithm);
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun int hash_hw_update(struct ahash_request *req);
391*4882a593Smuzhiyun 
392*4882a593Smuzhiyun int hash_save_state(struct hash_device_data *device_data,
393*4882a593Smuzhiyun 		struct hash_state *state);
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun int hash_resume_state(struct hash_device_data *device_data,
396*4882a593Smuzhiyun 		const struct hash_state *state);
397*4882a593Smuzhiyun 
398*4882a593Smuzhiyun #endif
399