1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 #define ISES_DMA_READ_COUNT 0x0100
38 #define ISES_DMA_RCOUNT(x) ((x) << 16)
39 #define ISES_DMA_WRITE_COUNT 0x0100
40 #define ISES_DMA_WCOUNT(x) ((x) & 0x00FF)
41
42 #define ISES_DMA_WRITE_START 0x0104
43 #define ISES_DMA_READ_START 0x0108
44 #define ISES_DMA_CTRL 0x010C
45 #define ISES_DMA_STATUS ISES_DMA_CTRL
46 #define ISES_DMA_RESET 0x0110
47
48 #define ISES_DMA_CTRL_ILT 0x40000000
49 #define ISES_DMA_CTRL_RMULT 0x0D000000
50 #define ISES_DMA_CTRL_RLINE 0x09000000
51 #define ISES_DMA_CTRL_READ 0x01000000
52 #define ISES_DMA_CTRL_WRITE 0x00000100
53
54 #define ISES_DMA_STATUS_R_RUN 0x01000000
55 #define ISES_DMA_STATUS_R_ERR 0x02000000
56 #define ISES_DMA_STATUS_W_RUN 0x00000100
57 #define ISES_DMA_STATUS_W_ERR 0x00000200
58
59
60
61
62
63 #define ISES_A_OFFSET 0x0200
64 #define ISES_A(x) (ISES_A_OFFSET + (x))
65
66 #define ISES_A_STAT ISES_A(0x00)
67 #define ISES_A_INTS ISES_A(0x04)
68 #define ISES_A_INTE ISES_A(0x08)
69 #define ISES_A_SREQ ISES_A(0x0C)
70 #define ISES_A_CTRL ISES_A_SREQ
71 #define ISES_A_OQD ISES_A(0x10)
72 #define ISES_A_IQD ISES_A_OQD
73 #define ISES_A_OQS ISES_A(0x14)
74 #define ISES_A_IQS ISES_A(0x18)
75 #define ISES_A_OQF ISES_A(0x1C)
76 #define ISES_A_IQF ISES_A(0x20)
77
78
79
80
81
82 #define ISES_B_OFFSET 0x0300
83 #define ISES_B(x) (ISES_B_OFFSET + (x))
84
85 #define ISES_B_BDATAIN ISES_B(0x0)
86 #define ISES_B_BDATAOUT ISES_B(0x4)
87 #define ISES_B_STAT ISES_B(0x8)
88
89
90
91
92
93 #define ISES_I_OFFSET 0x0400
94
95
96
97
98
99 #define ISES_BO_OFFSET 0x0500
100 #define ISES_BO(x) (ISES_BO_OFFSET + (x))
101
102 #define ISES_BO_STAT ISES_BO(0x0)
103 #define ISES_BO_LOOPCOUNTER ISES_BO(0x4)
104 #define ISES_BO_TESTREG ISES_BO(0x8)
105
106 #define ISES_BO_STAT_LOOP 0x00000001
107 #define ISES_BO_STAT_TAMPER 0x00000002
108 #define ISES_BO_STAT_POWERDOWN 0x00000004
109 #define ISES_BO_STAT_ACONF 0x00000008
110 #define ISES_BO_STAT_HWRESET 0x00000010
111 #define ISES_BO_STAT_AIRQ 0x00000020
112
113
114
115
116
117 #define ISES_STAT_LNAU_MASKED 0x00000001
118
119
120
121 #define ISES_STAT_LNAU_BUSY_1 0x00000002
122 #define ISES_STAT_LNAU_ERR_1 0x00000004
123 #define ISES_STAT_LNAU_BUSY_2 0x00000008
124 #define ISES_STAT_LNAU_ERR_2 0x00000010
125 #define ISES_STAT_BCHU_MASKED 0x00000020
126 #define ISES_STAT_BCHU_BUSY 0x00000040
127 #define ISES_STAT_BCHU_ERR 0x00000080
128 #define ISES_STAT_BCHU_SCIF 0x00000100
129 #define ISES_STAT_BCHU_HIF 0x00000200
130 #define ISES_STAT_BCHU_DDB 0x00000400
131 #define ISES_STAT_BCHU_IRF 0x00000800
132 #define ISES_STAT_BCHU_OAF 0x00001000
133 #define ISES_STAT_BCHU_DIE 0x00002000
134 #define ISES_STAT_BCHU_UE 0x00004000
135 #define ISES_STAT_BCHU_IFE 0x00008000
136 #define ISES_STAT_BCHU_IFHE 0x00010000
137 #define ISES_STAT_BCHU_IFF 0x00020000
138 #define ISES_STAT_BCHU_OFE 0x00040000
139 #define ISES_STAT_BCHU_OFHF 0x00080000
140 #define ISES_STAT_BCHU_OFF 0x00100000
141 #define ISES_STAT_HW_DA 0x00200000
142 #define ISES_STAT_HW_ACONF 0x00400000
143 #define ISES_STAT_SW_WFOQ 0x00800000
144 #define ISES_STAT_SW_OQSINC 0x08000000
145
146 #define ISES_STAT_IDP_MASK 0x0f000000
147 #define ISES_STAT_IDP_STATE(x) (((x) & ISES_STAT_IDP_MASK) >> 24)
148 #define ISES_IDP_WFPL 0x4
149
150 static const char *ises_idp_state[] =
151 {
152 "reset state",
153 "testing NSRAM",
154 "checking for firmware",
155 "clearing NSRAM",
156 "waiting for program length",
157 "waiting for program data",
158 "waiting for program CRC",
159 "functional test program",
160 0, 0, 0, 0, 0, 0, 0,
161 "Error: NSRAM or firmware failed"
162 };
163
164 #define ISES_STAT_SW_MASK 0x03000000
165 #define ISES_STAT_SW_MODE(x) (((x) & ISES_STAT_SW_MASK) >> 24)
166
167 #define ISES_A_CTRL_RESET 0x0000
168 #define ISES_A_CTRL_CONTINUE 0x0001
169
170 #ifdef ISESDEBUG
171 static const char *ises_sw_mode[] =
172 {
173 "ST (SelfTest)",
174 "CMD",
175 "WFC (Wait for continue)",
176 "CMD (Wait for reset)"
177 };
178 #endif
179
180
181 #define ISES_BERR_DPAR 0x00000001
182 #define ISES_BERR_IDESBCP 0x00000002
183 #define ISES_BERR_ISFRBCP 0x00000004
184 #define ISES_BERR_INCMBCP 0x00000008
185 #define ISES_BERR_IBCF 0x00000010
186 #define ISES_BERR_reserved 0x00000020
187 #define ISES_BERR_SRB 0x00000040
188 #define ISES_BERR_HRB 0x00000080
189 #define ISES_BERR_IHFR 0x00000100
190 #define ISES_BERR_PADERR 0x00000200
191 #define ISES_BERR_BIDM 0x00000400
192
193
194 #define ISES_BCHCR_BCHU_DIE 0x00000001
195 #define ISES_BCHCR_BCHU_UE 0x00000002
196 #define ISES_BCHCR_BCHU_RST 0x00000004
197
198
199
200
201
202 #define ISES_SELR_BCHU_EH 0x80000000
203 #define ISES_SELR_BCHU_HISOF 0x01000000
204 #define ISES_SELR_BCHU_DIS 0x02000000
205
206
207 #define ISES_HOMR_HMTR 0x00800000
208 #define ISES_HOMR_ER 0x00300000
209
210 #define ISES_HOMR_HFR 0x00070000
211 #define ISES_HOMR_HFR_NOP 0x00000000
212 #define ISES_HOMR_HFR_MD5 0x00010000
213 #define ISES_HOMR_HFR_RMD160 0x00020000
214 #define ISES_HOMR_HFR_RMD128 0x00030000
215 #define ISES_HOMR_HFR_SHA1 0x00040000
216
217
218 #define ISES_SOMR_BCFR 0x0000f000
219 #define ISES_SOMR_BCPR 0x00000ff0
220 #define ISES_SOMR_BOMR (ISES_SOMR_BCFR | ISES_SOMR_BCPR)
221 #define ISES_SOMR_BOMR_NOP 0x00000000
222 #define ISES_SOMR_BOMR_TRANSPARENT 0x00000010
223 #define ISES_SOMR_BOMR_DES 0x00001000
224 #define ISES_SOMR_BOMR_3DES2 0x00001010
225 #define ISES_SOMR_BOMR_3DES 0x00001020
226 #define ISES_SOMR_BOMR_SAFER 0x00002000
227 #define ISES_SOMR_EDR 0x00000008
228 #define ISES_SOMR_FMR 0x00000003
229 #define ISES_SOMR_FMR_ECB 0x00000000
230 #define ISES_SOMR_FMR_CBC 0x00000001
231 #define ISES_SOMR_FMR_CFB64 0x00000002
232 #define ISES_SOMR_FMR_OFB64 0x00000003
233
234
235
236
237 #define ISES_OFFSET_HRNG_CTRL 0x00
238 #define ISES_OFFSET_HRNG_LFSR 0x04
239 #define ISES_HRNG_CTRL_HE 0x00000001
240
241
242
243
244 #define ISES_MKCMD(cmd,len) (cmd | cmd << 16 | len << 8 | len << 24)
245 #define ISES_CMD_NONE -1
246
247
248 #define ISES_CMD_CHIP_ID 0x00
249
250 #define ISES_CMD_LRESET_1 0x01
251 #define ISES_CMD_LRSFLG_1 0x02
252 #define ISES_CMD_LUPLOAD_1 0x03
253 #define ISES_CMD_LW_A_1 0x04
254 #define ISES_CMD_LW_B_1 0x05
255 #define ISES_CMD_LW_N_1 0x06
256 #define ISES_CMD_LW_Bq_1 0x07
257 #define ISES_CMD_LW_Nq_1 0x08
258 #define ISES_CMD_LW_Bp_1 0x09
259 #define ISES_CMD_LW_Np_1 0x0a
260 #define ISES_CMD_LW_U_1 0x0b
261 #define ISES_CMD_LMOD_1 0x0c
262 #define ISES_CMD_LMULMOD_1 0x0d
263 #define ISES_CMD_LEXPMOD_1 0x0e
264 #define ISES_CMD_LEXPCRTMOD_1 0x0f
265
266 #define ISES_CMD_LRESET_2 0x10
267 #define ISES_CMD_LRSFLG_2 0x11
268 #define ISES_CMD_LUPLOAD_2 0x12
269 #define ISES_CMD_LW_A_2 0x13
270 #define ISES_CMD_LW_B_2 0x14
271 #define ISES_CMD_LW_N_2 0x15
272 #define ISES_CMD_LW_Bq_2 0x16
273 #define ISES_CMD_LW_Nq_2 0x17
274 #define ISES_CMD_LW_Bp_2 0x18
275 #define ISES_CMD_LW_Np_2 0x19
276 #define ISES_CMD_LW_U_2 0x1a
277 #define ISES_CMD_LMOD_2 0x1b
278 #define ISES_CMD_LMULMOD_2 0x1c
279 #define ISES_CMD_LEXPMOD_2 0x1d
280 #define ISES_CMD_LEXPCRTMOD_2 0x1e
281
282 #define ISES_CMD_RST_BERR 0x1f
283 #define ISES_CMD_BR_BERR 0x20
284 #define ISES_CMD_BW_DATA 0x21
285 #define ISES_CMD_BR_DATA 0x22
286 #define ISES_CMD_BW_BCHCR 0x23
287 #define ISES_CMD_BR_BCHCR 0x24
288 #define ISES_CMD_BW_OMR 0x25
289 #define ISES_CMD_BR_OMR 0x26
290 #define ISES_CMD_BW_KR0 0x27
291 #define ISES_CMD_BR_KR0 0x28
292 #define ISES_CMD_BW_KR1 0x29
293 #define ISES_CMD_BR_KR1 0x2a
294 #define ISES_CMD_BW_KR2 0x2b
295 #define ISES_CMD_BR_KR2 0x2c
296 #define ISES_CMD_BW_SCCR 0x2d
297 #define ISES_CMD_BR_SCCR 0x2e
298 #define ISES_CMD_BW_DBCR 0x2f
299 #define ISES_CMD_BR_DBCR 0x30
300 #define ISES_CMD_BW_HMLR 0x31
301 #define ISES_CMD_BR_HMLR 0x32
302 #define ISES_CMD_BW_CVR 0x33
303 #define ISES_CMD_BR_CVR 0x34
304 #define ISES_CMD_BPROC 0x35
305 #define ISES_CMD_BTERM 0x36
306 #define ISES_CMD_BSWITCH 0x37
307
308 #define ISES_CMD_HSTART 0x38
309 #define ISES_CMD_HSTOP 0x39
310 #define ISES_CMD_HSEED 0x3a
311 #define ISES_CMD_HBITS 0x3b
312
313
314 #define ISES_RC_MASK 0x0000ffff
315 #define ISES_RC_SUCCESS 0x0000
316 #define ISES_RC_CMDERR 0x0001
317 #define ISES_RC_QERR 0x0002
318 #define ISES_RC_LNAU_ERR 0x0003
319 #define ISES_RC_BCHU_ERR 0x0004
320 #define ISES_RC_BCHU_BIFCSEL 0x0005
321 #define ISES_RC_BCHU_ODD 0x0006
322 #define ISES_RC_HRNG_ILLEN 0x0007
323
324
325 #define ISES_IRQ_TIMER_1 0x00000001
326 #define ISES_IRQ_TIMER_2 0x00000002
327 #define ISES_IRQ_I_IIN0 0x00000004
328 #define ISES_IRQ_I_IIN1 0x00000008
329 #define ISES_IRQ_I_IIN2 0x00000010
330 #define ISES_IRQ_I_IIN3 0x00000020
331 #define ISES_IRQ_LNAU_1_ERROR 0x00000040
332 #define ISES_IRQ_LNAU_1_DONE 0x00000080
333 #define ISES_IRQ_LNAU_2_ERROR 0x00000100
334 #define ISES_IRQ_LNAU_2_DONE 0x00000200
335 #define ISES_IRQ_BCHU_DONE 0x00000400
336 #define ISES_IRQ_BCHU_ERROR 0x00000800
337 #define ISES_IRQ_BCHU_IRF 0x00001000
338 #define ISES_IRQ_BCHU_OAF 0x00002000
339 #define ISES_IRQ_BCHU_IEF 0x00004000
340 #define ISES_IRQ_A_WCTRL 0x00008000
341 #define ISES_IRQ_A_RSREQ 0x00010000
342 #define ISES_IRQ_A_DIQ 0x00020000
343 #define ISES_IRQ_A_CIQ 0x00040000
344 #define ISES_IRQ_A_OQF 0x00080000
345
346 #define ISES_SESSION(sid) ( (sid) & 0x0fffffff)
347 #define ISES_CARD(sid) (((sid) & 0xf0000000) >> 28)
348 #define ISES_SID(crd,ses) (((crd) << 28) | ((ses) & 0x0fffffff))
349
350
351
352 struct ises_session {
353 u_int32_t kr[6];
354 u_int32_t omr;
355
356
357 u_int32_t sccr[2];
358 u_int32_t cvr[5];
359 u_int32_t dbcr[2];
360 u_int32_t hmlr[2];
361 } __attribute__((packed));
362
363 #define ISES_B_DATASIZE 4096