1
2
3
4
5
6
7 #ifndef __ATMEL_I2C_H__
8 #define __ATMEL_I2C_H__
9
10 #include <linux/hw_random.h>
11 #include <linux/types.h>
12
13 #define ATMEL_ECC_PRIORITY 300
14
15 #define COMMAND 0x03
16 #define SLEEP_TOKEN 0x01
17 #define WAKE_TOKEN_MAX_SIZE 8
18
19
20 #define WORD_ADDR_SIZE 1
21 #define COUNT_SIZE 1
22 #define CRC_SIZE 2
23 #define CMD_OVERHEAD_SIZE (COUNT_SIZE + CRC_SIZE)
24
25
26 #define ATMEL_ECC_NIST_P256_N_SIZE 32
27 #define ATMEL_ECC_PUBKEY_SIZE (2 * ATMEL_ECC_NIST_P256_N_SIZE)
28
29 #define STATUS_RSP_SIZE 4
30 #define ECDH_RSP_SIZE (32 + CMD_OVERHEAD_SIZE)
31 #define GENKEY_RSP_SIZE (ATMEL_ECC_PUBKEY_SIZE + \
32 CMD_OVERHEAD_SIZE)
33 #define READ_RSP_SIZE (4 + CMD_OVERHEAD_SIZE)
34 #define RANDOM_RSP_SIZE (32 + CMD_OVERHEAD_SIZE)
35 #define MAX_RSP_SIZE GENKEY_RSP_SIZE
36
37
38
39
40
41
42
43
44
45
46
47
48
49 struct atmel_i2c_cmd {
50 u8 word_addr;
51 u8 count;
52 u8 opcode;
53 u8 param1;
54 __le16 param2;
55 u8 data[MAX_RSP_SIZE];
56 u8 msecs;
57 u16 rxsize;
58 } __packed;
59
60
61 #define STATUS_SIZE 0x04
62 #define STATUS_NOERR 0x00
63 #define STATUS_WAKE_SUCCESSFUL 0x11
64
65
66 #define CONFIG_ZONE 0
67
68
69 #define RSP_DATA_IDX 1
70 #define DATA_SLOT_2 2
71
72
73 #define DEVICE_LOCK_ADDR 0x15
74 #define LOCK_VALUE_IDX (RSP_DATA_IDX + 2)
75 #define LOCK_CONFIG_IDX (RSP_DATA_IDX + 3)
76
77
78
79
80
81 #define TWHI_MIN 1500
82 #define TWHI_MAX 1550
83
84
85 #define TWLO_USEC 60
86
87
88 #define MAX_EXEC_TIME_ECDH 58
89 #define MAX_EXEC_TIME_GENKEY 115
90 #define MAX_EXEC_TIME_READ 1
91 #define MAX_EXEC_TIME_RANDOM 50
92
93
94 #define OPCODE_ECDH 0x43
95 #define OPCODE_GENKEY 0x40
96 #define OPCODE_READ 0x02
97 #define OPCODE_RANDOM 0x1b
98
99
100 #define READ_COUNT 7
101
102
103 #define RANDOM_COUNT 7
104
105
106 #define GENKEY_COUNT 7
107 #define GENKEY_MODE_PRIVATE 0x04
108
109
110 #define ECDH_COUNT 71
111 #define ECDH_PREFIX_MODE 0x00
112
113
114 struct atmel_ecc_driver_data {
115 struct list_head i2c_client_list;
116 spinlock_t i2c_list_lock;
117 } ____cacheline_aligned;
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135 struct atmel_i2c_client_priv {
136 struct i2c_client *client;
137 struct list_head i2c_client_list_node;
138 struct mutex lock;
139 u8 wake_token[WAKE_TOKEN_MAX_SIZE];
140 size_t wake_token_sz;
141 atomic_t tfm_count ____cacheline_aligned;
142 struct hwrng hwrng;
143 };
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 struct atmel_i2c_work_data {
161 void *ctx;
162 struct i2c_client *client;
163 void (*cbk)(struct atmel_i2c_work_data *work_data, void *areq,
164 int status);
165 void *areq;
166 struct work_struct work;
167 struct atmel_i2c_cmd cmd;
168 };
169
170 int atmel_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id);
171
172 void atmel_i2c_enqueue(struct atmel_i2c_work_data *work_data,
173 void (*cbk)(struct atmel_i2c_work_data *work_data,
174 void *areq, int status),
175 void *areq);
176
177 int atmel_i2c_send_receive(struct i2c_client *client, struct atmel_i2c_cmd *cmd);
178
179 void atmel_i2c_init_read_cmd(struct atmel_i2c_cmd *cmd);
180 void atmel_i2c_init_random_cmd(struct atmel_i2c_cmd *cmd);
181 void atmel_i2c_init_genkey_cmd(struct atmel_i2c_cmd *cmd, u16 keyid);
182 int atmel_i2c_init_ecdh_cmd(struct atmel_i2c_cmd *cmd,
183 struct scatterlist *pubkey);
184
185 #endif