Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hash_alg.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) ST-Ericsson SA 2010
3  * Author: Shujuan Chen ([email protected])
4  * Author: Joakim Bech ([email protected])
5  * Author: Berne Hebark ([email protected]))
6  * License terms: GNU General Public License (GPL) version 2
7  */
8 #ifndef _HASH_ALG_H
9 #define _HASH_ALG_H
10 
11 #include <linux/bitops.h>
12 
13 #define HASH_BLOCK_SIZE 64
14 #define HASH_DMA_ALIGN_SIZE 4
15 #define HASH_DMA_PERFORMANCE_MIN_SIZE 1024
16 #define HASH_BYTES_PER_WORD 4
17 
18 /* Maximum value of the length's high word */
19 #define HASH_HIGH_WORD_MAX_VAL 0xFFFFFFFFUL
20 
21 /* Power on Reset values HASH registers */
22 #define HASH_RESET_CR_VALUE 0x0
23 #define HASH_RESET_STR_VALUE 0x0
24 
25 /* Number of context swap registers */
26 #define HASH_CSR_COUNT 52
27 
28 #define HASH_RESET_CSRX_REG_VALUE 0x0
29 #define HASH_RESET_CSFULL_REG_VALUE 0x0
30 #define HASH_RESET_CSDATAIN_REG_VALUE 0x0
31 
32 #define HASH_RESET_INDEX_VAL 0x0
33 #define HASH_RESET_BIT_INDEX_VAL 0x0
34 #define HASH_RESET_BUFFER_VAL 0x0
35 #define HASH_RESET_LEN_HIGH_VAL 0x0
36 #define HASH_RESET_LEN_LOW_VAL 0x0
37 
38 /* Control register bitfields */
39 #define HASH_CR_RESUME_MASK 0x11FCF
40 
41 #define HASH_CR_SWITCHON_POS 31
42 #define HASH_CR_SWITCHON_MASK BIT(31)
43 
44 #define HASH_CR_EMPTYMSG_POS 20
45 #define HASH_CR_EMPTYMSG_MASK BIT(20)
46 
47 #define HASH_CR_DINF_POS 12
48 #define HASH_CR_DINF_MASK BIT(12)
49 
50 #define HASH_CR_NBW_POS 8
51 #define HASH_CR_NBW_MASK 0x00000F00UL
52 
53 #define HASH_CR_LKEY_POS 16
54 #define HASH_CR_LKEY_MASK BIT(16)
55 
56 #define HASH_CR_ALGO_POS 7
57 #define HASH_CR_ALGO_MASK BIT(7)
58 
59 #define HASH_CR_MODE_POS 6
60 #define HASH_CR_MODE_MASK BIT(6)
61 
62 #define HASH_CR_DATAFORM_POS 4
63 #define HASH_CR_DATAFORM_MASK (BIT(4) | BIT(5))
64 
65 #define HASH_CR_DMAE_POS 3
66 #define HASH_CR_DMAE_MASK BIT(3)
67 
68 #define HASH_CR_INIT_POS 2
69 #define HASH_CR_INIT_MASK BIT(2)
70 
71 #define HASH_CR_PRIVN_POS 1
72 #define HASH_CR_PRIVN_MASK BIT(1)
73 
74 #define HASH_CR_SECN_POS 0
75 #define HASH_CR_SECN_MASK BIT(0)
76 
77 /* Start register bitfields */
78 #define HASH_STR_DCAL_POS 8
79 #define HASH_STR_DCAL_MASK BIT(8)
80 #define HASH_STR_DEFAULT 0x0
81 
82 #define HASH_STR_NBLW_POS 0
83 #define HASH_STR_NBLW_MASK 0x0000001FUL
84 
85 #define HASH_NBLW_MAX_VAL 0x1F
86 
87 /* PrimeCell IDs */
88 #define HASH_P_ID0 0xE0
89 #define HASH_P_ID1 0x05
90 #define HASH_P_ID2 0x38
91 #define HASH_P_ID3 0x00
92 #define HASH_CELL_ID0 0x0D
93 #define HASH_CELL_ID1 0xF0
94 #define HASH_CELL_ID2 0x05
95 #define HASH_CELL_ID3 0xB1
96 
97 #define HASH_SET_BITS(reg_name, mask) \
98  writel_relaxed((readl_relaxed(reg_name) | mask), reg_name)
99 
100 #define HASH_CLEAR_BITS(reg_name, mask) \
101  writel_relaxed((readl_relaxed(reg_name) & ~mask), reg_name)
102 
103 #define HASH_PUT_BITS(reg, val, shift, mask) \
104  writel_relaxed(((readl(reg) & ~(mask)) | \
105  (((u32)val << shift) & (mask))), reg)
106 
107 #define HASH_SET_DIN(val, len) writesl(&device_data->base->din, (val), (len))
108 
109 #define HASH_INITIALIZE \
110  HASH_PUT_BITS( \
111  &device_data->base->cr, \
112  0x01, HASH_CR_INIT_POS, \
113  HASH_CR_INIT_MASK)
114 
115 #define HASH_SET_DATA_FORMAT(data_format) \
116  HASH_PUT_BITS( \
117  &device_data->base->cr, \
118  (u32) (data_format), HASH_CR_DATAFORM_POS, \
119  HASH_CR_DATAFORM_MASK)
120 #define HASH_SET_NBLW(val) \
121  HASH_PUT_BITS( \
122  &device_data->base->str, \
123  (u32) (val), HASH_STR_NBLW_POS, \
124  HASH_STR_NBLW_MASK)
125 #define HASH_SET_DCAL \
126  HASH_PUT_BITS( \
127  &device_data->base->str, \
128  0x01, HASH_STR_DCAL_POS, \
129  HASH_STR_DCAL_MASK)
130 
131 /* Hardware access method */
132 enum hash_mode {
135 };
136 
144 struct uint64 {
147 };
148 
181  u32 hx[8];
182 
183  u32 padding0[(0x080 - 0x02C) / sizeof(u32)];
184 
188 
189  u32 padding1[(0x0F8 - 0x08C) / sizeof(u32)];
190 
194 
195  u32 padding2[(0xFE0 - 0x1D0) / sizeof(u32)];
196 
201 
206 };
207 
229 struct hash_state {
233  u32 csr[52];
237  struct uint64 length;
240 };
241 
250 };
251 
264 };
265 
271 enum hash_algo {
274 };
275 
281 enum hash_op {
284 };
285 
292 struct hash_config {
296 };
297 
308 struct hash_dma {
313  int sg_len;
314  struct scatterlist *sg;
315  int nents;
316 };
317 
327 struct hash_ctx {
328  u8 *key;
333 };
334 
342 struct hash_req_ctx {
344  bool dma_mode;
346 };
347 
365  struct device *dev;
371  struct clk *clk;
373  struct hash_state state; /* Used for saving and resuming state */
374  struct hash_dma dma;
375 };
376 
377 int hash_check_hw(struct hash_device_data *device_data);
378 
379 int hash_setconfiguration(struct hash_device_data *device_data,
380  struct hash_config *config);
381 
382 void hash_begin(struct hash_device_data *device_data, struct hash_ctx *ctx);
383 
384 void hash_get_digest(struct hash_device_data *device_data,
385  u8 *digest, int algorithm);
386 
387 int hash_hw_update(struct ahash_request *req);
388 
389 int hash_save_state(struct hash_device_data *device_data,
390  struct hash_state *state);
391 
392 int hash_resume_state(struct hash_device_data *device_data,
393  const struct hash_state *state);
394 
395 #endif