1
2
3
4
5
6
7#ifndef REGS_H
8#define REGS_H
9
10#include <linux/types.h>
11#include <linux/io.h>
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68#ifdef __BIG_ENDIAN
69#define wr_reg32(reg, data) out_be32(reg, data)
70#define rd_reg32(reg) in_be32(reg)
71#ifdef CONFIG_64BIT
72#define wr_reg64(reg, data) out_be64(reg, data)
73#define rd_reg64(reg) in_be64(reg)
74#endif
75#else
76#ifdef __LITTLE_ENDIAN
77#define wr_reg32(reg, data) __raw_writel(data, reg)
78#define rd_reg32(reg) __raw_readl(reg)
79#ifdef CONFIG_64BIT
80#define wr_reg64(reg, data) __raw_writeq(data, reg)
81#define rd_reg64(reg) __raw_readq(reg)
82#endif
83#endif
84#endif
85
86#ifndef CONFIG_64BIT
87static inline void wr_reg64(u64 __iomem *reg, u64 data)
88{
89 wr_reg32((u32 __iomem *)reg, (data & 0xffffffff00000000ull) >> 32);
90 wr_reg32((u32 __iomem *)reg + 1, data & 0x00000000ffffffffull);
91}
92
93static inline u64 rd_reg64(u64 __iomem *reg)
94{
95 return (((u64)rd_reg32((u32 __iomem *)reg)) << 32) |
96 ((u64)rd_reg32((u32 __iomem *)reg + 1));
97}
98#endif
99
100
101
102
103
104struct jr_outentry {
105 dma_addr_t desc;
106 u32 jrstatus;
107} __packed;
108
109
110
111
112
113
114
115
116
117#define CHA_NUM_DECONUM_SHIFT 56
118#define CHA_NUM_DECONUM_MASK (0xfull << CHA_NUM_DECONUM_SHIFT)
119
120
121#define CHA_ID_AES_SHIFT 0
122#define CHA_ID_AES_MASK (0xfull << CHA_ID_AES_SHIFT)
123
124#define CHA_ID_DES_SHIFT 4
125#define CHA_ID_DES_MASK (0xfull << CHA_ID_DES_SHIFT)
126
127#define CHA_ID_ARC4_SHIFT 8
128#define CHA_ID_ARC4_MASK (0xfull << CHA_ID_ARC4_SHIFT)
129
130#define CHA_ID_MD_SHIFT 12
131#define CHA_ID_MD_MASK (0xfull << CHA_ID_MD_SHIFT)
132
133#define CHA_ID_RNG_SHIFT 16
134#define CHA_ID_RNG_MASK (0xfull << CHA_ID_RNG_SHIFT)
135
136#define CHA_ID_SNW8_SHIFT 20
137#define CHA_ID_SNW8_MASK (0xfull << CHA_ID_SNW8_SHIFT)
138
139#define CHA_ID_KAS_SHIFT 24
140#define CHA_ID_KAS_MASK (0xfull << CHA_ID_KAS_SHIFT)
141
142#define CHA_ID_PK_SHIFT 28
143#define CHA_ID_PK_MASK (0xfull << CHA_ID_PK_SHIFT)
144
145#define CHA_ID_CRC_SHIFT 32
146#define CHA_ID_CRC_MASK (0xfull << CHA_ID_CRC_SHIFT)
147
148#define CHA_ID_SNW9_SHIFT 36
149#define CHA_ID_SNW9_MASK (0xfull << CHA_ID_SNW9_SHIFT)
150
151#define CHA_ID_DECO_SHIFT 56
152#define CHA_ID_DECO_MASK (0xfull << CHA_ID_DECO_SHIFT)
153
154#define CHA_ID_JR_SHIFT 60
155#define CHA_ID_JR_MASK (0xfull << CHA_ID_JR_SHIFT)
156
157struct sec_vid {
158 u16 ip_id;
159 u8 maj_rev;
160 u8 min_rev;
161};
162
163struct caam_perfmon {
164
165 u64 req_dequeued;
166 u64 ob_enc_req;
167 u64 ib_dec_req;
168 u64 ob_enc_bytes;
169 u64 ob_prot_bytes;
170 u64 ib_dec_bytes;
171 u64 ib_valid_bytes;
172 u64 rsvd[13];
173
174
175 u64 cha_rev;
176#define CTPR_QI_SHIFT 57
177#define CTPR_QI_MASK (0x1ull << CTPR_QI_SHIFT)
178 u64 comp_parms;
179 u64 rsvd1[2];
180
181
182 u64 faultaddr;
183 u32 faultliodn;
184 u32 faultdetail;
185 u32 rsvd2;
186 u32 status;
187 u64 rsvd3;
188
189
190 u32 rtic_id;
191 u32 ccb_id;
192 u64 cha_id;
193 u64 cha_num;
194 u64 caam_id;
195};
196
197
198#define MSTRID_LOCK_LIODN 0x80000000
199#define MSTRID_LOCK_MAKETRUSTED 0x00010000
200
201#define MSTRID_LIODN_MASK 0x0fff
202struct masterid {
203 u32 liodn_ms;
204 u32 liodn_ls;
205};
206
207
208struct partid {
209 u32 rsvd1;
210 u32 pidr;
211};
212
213
214
215struct rngtst {
216 u32 mode;
217 u32 rsvd1[3];
218 u32 reset;
219 u32 rsvd2[3];
220 u32 status;
221 u32 rsvd3;
222 u32 errstat;
223 u32 rsvd4;
224 u32 errctl;
225 u32 rsvd5;
226 u32 entropy;
227 u32 rsvd6[15];
228 u32 verifctl;
229 u32 rsvd7;
230 u32 verifstat;
231 u32 rsvd8;
232 u32 verifdata;
233 u32 rsvd9;
234 u32 xkey;
235 u32 rsvd10;
236 u32 oscctctl;
237 u32 rsvd11;
238 u32 oscct;
239 u32 rsvd12;
240 u32 oscctstat;
241 u32 rsvd13[2];
242 u32 ofifo[4];
243 u32 rsvd14[15];
244};
245
246
247struct rng4tst {
248#define RTMCTL_PRGM 0x00010000
249 u32 rtmctl;
250 u32 rtscmisc;
251 u32 rtpkrrng;
252 union {
253 u32 rtpkrmax;
254 u32 rtpkrsq;
255 };
256#define RTSDCTL_ENT_DLY_SHIFT 16
257#define RTSDCTL_ENT_DLY_MASK (0xffff << RTSDCTL_ENT_DLY_SHIFT)
258#define RTSDCTL_ENT_DLY_MIN 1200
259#define RTSDCTL_ENT_DLY_MAX 12800
260 u32 rtsdctl;
261 union {
262 u32 rtsblim;
263 u32 rttotsam;
264 };
265 u32 rtfrqmin;
266 union {
267 u32 rtfrqmax;
268 u32 rtfrqcnt;
269 };
270 u32 rsvd1[40];
271#define RDSTA_SKVT 0x80000000
272#define RDSTA_SKVN 0x40000000
273#define RDSTA_IF0 0x00000001
274#define RDSTA_IF1 0x00000002
275#define RDSTA_IFMASK (RDSTA_IF1 | RDSTA_IF0)
276 u32 rdsta;
277 u32 rsvd2[15];
278};
279
280
281
282
283
284
285#define KEK_KEY_SIZE 8
286#define TKEK_KEY_SIZE 8
287#define TDSK_KEY_SIZE 8
288
289#define DECO_RESET 1
290#define DECO_RESET_0 (DECO_RESET << 0)
291#define DECO_RESET_1 (DECO_RESET << 1)
292#define DECO_RESET_2 (DECO_RESET << 2)
293#define DECO_RESET_3 (DECO_RESET << 3)
294#define DECO_RESET_4 (DECO_RESET << 4)
295
296struct caam_ctrl {
297
298
299 u32 rsvd1;
300 u32 mcr;
301 u32 rsvd2;
302 u32 scfgr;
303
304
305
306 struct masterid jr_mid[4];
307 u32 rsvd3[12];
308 struct masterid rtic_mid[4];
309 u32 rsvd4[7];
310 u32 deco_rq;
311 struct partid deco_mid[5];
312 u32 rsvd5[22];
313
314
315 u32 deco_avail;
316 u32 deco_reset;
317 u32 rsvd6[182];
318
319
320
321 u32 kek[KEK_KEY_SIZE];
322 u32 tkek[TKEK_KEY_SIZE];
323 u32 tdsk[TDSK_KEY_SIZE];
324 u32 rsvd7[32];
325 u64 sknonce;
326 u32 rsvd8[70];
327
328
329
330 union {
331 struct rngtst rtst[2];
332 struct rng4tst r4tst[2];
333 };
334
335 u32 rsvd9[448];
336
337
338 struct caam_perfmon perfmon;
339};
340
341
342
343
344#define MCFGR_SWRESET 0x80000000
345#define MCFGR_WDENABLE 0x40000000
346#define MCFGR_WDFAIL 0x20000000
347#define MCFGR_DMA_RESET 0x10000000
348#define MCFGR_LONG_PTR 0x00010000
349#define SCFGR_RDBENABLE 0x00000400
350#define DECORR_RQD0ENABLE 0x00000001
351#define DECORR_DEN0 0x00010000
352
353
354#define MCFGR_ARCACHE_SHIFT 12
355#define MCFGR_ARCACHE_MASK (0xf << MCFGR_ARCACHE_SHIFT)
356
357
358#define MCFGR_AWCACHE_SHIFT 8
359#define MCFGR_AWCACHE_MASK (0xf << MCFGR_AWCACHE_SHIFT)
360
361
362#define MCFGR_AXIPIPE_SHIFT 4
363#define MCFGR_AXIPIPE_MASK (0xf << MCFGR_AXIPIPE_SHIFT)
364
365#define MCFGR_AXIPRI 0x00000008
366#define MCFGR_BURST_64 0x00000001
367
368
369
370
371
372
373struct caam_job_ring {
374
375 u64 inpring_base;
376 u32 rsvd1;
377 u32 inpring_size;
378 u32 rsvd2;
379 u32 inpring_avail;
380 u32 rsvd3;
381 u32 inpring_jobadd;
382
383
384 u64 outring_base;
385 u32 rsvd4;
386 u32 outring_size;
387 u32 rsvd5;
388 u32 outring_rmvd;
389 u32 rsvd6;
390 u32 outring_used;
391
392
393 u32 rsvd7;
394 u32 jroutstatus;
395 u32 rsvd8;
396 u32 jrintstatus;
397 u32 rconfig_hi;
398 u32 rconfig_lo;
399
400
401 u32 rsvd9;
402 u32 inp_rdidx;
403 u32 rsvd10;
404 u32 out_wtidx;
405
406
407 u32 rsvd11;
408 u32 jrcommand;
409
410 u32 rsvd12[932];
411
412
413 struct caam_perfmon perfmon;
414};
415
416#define JR_RINGSIZE_MASK 0x03ff
417
418
419
420
421
422
423#define JRSTA_SSRC_SHIFT 28
424#define JRSTA_SSRC_MASK 0xf0000000
425
426#define JRSTA_SSRC_NONE 0x00000000
427#define JRSTA_SSRC_CCB_ERROR 0x20000000
428#define JRSTA_SSRC_JUMP_HALT_USER 0x30000000
429#define JRSTA_SSRC_DECO 0x40000000
430#define JRSTA_SSRC_JRERROR 0x60000000
431#define JRSTA_SSRC_JUMP_HALT_CC 0x70000000
432
433#define JRSTA_DECOERR_JUMP 0x08000000
434#define JRSTA_DECOERR_INDEX_SHIFT 8
435#define JRSTA_DECOERR_INDEX_MASK 0xff00
436#define JRSTA_DECOERR_ERROR_MASK 0x00ff
437
438#define JRSTA_DECOERR_NONE 0x00
439#define JRSTA_DECOERR_LINKLEN 0x01
440#define JRSTA_DECOERR_LINKPTR 0x02
441#define JRSTA_DECOERR_JRCTRL 0x03
442#define JRSTA_DECOERR_DESCCMD 0x04
443#define JRSTA_DECOERR_ORDER 0x05
444#define JRSTA_DECOERR_KEYCMD 0x06
445#define JRSTA_DECOERR_LOADCMD 0x07
446#define JRSTA_DECOERR_STORECMD 0x08
447#define JRSTA_DECOERR_OPCMD 0x09
448#define JRSTA_DECOERR_FIFOLDCMD 0x0a
449#define JRSTA_DECOERR_FIFOSTCMD 0x0b
450#define JRSTA_DECOERR_MOVECMD 0x0c
451#define JRSTA_DECOERR_JUMPCMD 0x0d
452#define JRSTA_DECOERR_MATHCMD 0x0e
453#define JRSTA_DECOERR_SHASHCMD 0x0f
454#define JRSTA_DECOERR_SEQCMD 0x10
455#define JRSTA_DECOERR_DECOINTERNAL 0x11
456#define JRSTA_DECOERR_SHDESCHDR 0x12
457#define JRSTA_DECOERR_HDRLEN 0x13
458#define JRSTA_DECOERR_BURSTER 0x14
459#define JRSTA_DECOERR_DESCSIGNATURE 0x15
460#define JRSTA_DECOERR_DMA 0x16
461#define JRSTA_DECOERR_BURSTFIFO 0x17
462#define JRSTA_DECOERR_JRRESET 0x1a
463#define JRSTA_DECOERR_JOBFAIL 0x1b
464#define JRSTA_DECOERR_DNRERR 0x80
465#define JRSTA_DECOERR_UNDEFPCL 0x81
466#define JRSTA_DECOERR_PDBERR 0x82
467#define JRSTA_DECOERR_ANRPLY_LATE 0x83
468#define JRSTA_DECOERR_ANRPLY_REPLAY 0x84
469#define JRSTA_DECOERR_SEQOVF 0x85
470#define JRSTA_DECOERR_INVSIGN 0x86
471#define JRSTA_DECOERR_DSASIGN 0x87
472
473#define JRSTA_CCBERR_JUMP 0x08000000
474#define JRSTA_CCBERR_INDEX_MASK 0xff00
475#define JRSTA_CCBERR_INDEX_SHIFT 8
476#define JRSTA_CCBERR_CHAID_MASK 0x00f0
477#define JRSTA_CCBERR_CHAID_SHIFT 4
478#define JRSTA_CCBERR_ERRID_MASK 0x000f
479
480#define JRSTA_CCBERR_CHAID_AES (0x01 << JRSTA_CCBERR_CHAID_SHIFT)
481#define JRSTA_CCBERR_CHAID_DES (0x02 << JRSTA_CCBERR_CHAID_SHIFT)
482#define JRSTA_CCBERR_CHAID_ARC4 (0x03 << JRSTA_CCBERR_CHAID_SHIFT)
483#define JRSTA_CCBERR_CHAID_MD (0x04 << JRSTA_CCBERR_CHAID_SHIFT)
484#define JRSTA_CCBERR_CHAID_RNG (0x05 << JRSTA_CCBERR_CHAID_SHIFT)
485#define JRSTA_CCBERR_CHAID_SNOW (0x06 << JRSTA_CCBERR_CHAID_SHIFT)
486#define JRSTA_CCBERR_CHAID_KASUMI (0x07 << JRSTA_CCBERR_CHAID_SHIFT)
487#define JRSTA_CCBERR_CHAID_PK (0x08 << JRSTA_CCBERR_CHAID_SHIFT)
488#define JRSTA_CCBERR_CHAID_CRC (0x09 << JRSTA_CCBERR_CHAID_SHIFT)
489
490#define JRSTA_CCBERR_ERRID_NONE 0x00
491#define JRSTA_CCBERR_ERRID_MODE 0x01
492#define JRSTA_CCBERR_ERRID_DATASIZ 0x02
493#define JRSTA_CCBERR_ERRID_KEYSIZ 0x03
494#define JRSTA_CCBERR_ERRID_PKAMEMSZ 0x04
495#define JRSTA_CCBERR_ERRID_PKBMEMSZ 0x05
496#define JRSTA_CCBERR_ERRID_SEQUENCE 0x06
497#define JRSTA_CCBERR_ERRID_PKDIVZRO 0x07
498#define JRSTA_CCBERR_ERRID_PKMODEVN 0x08
499#define JRSTA_CCBERR_ERRID_KEYPARIT 0x09
500#define JRSTA_CCBERR_ERRID_ICVCHK 0x0a
501#define JRSTA_CCBERR_ERRID_HARDWARE 0x0b
502#define JRSTA_CCBERR_ERRID_CCMAAD 0x0c
503#define JRSTA_CCBERR_ERRID_INVCHA 0x0f
504
505#define JRINT_ERR_INDEX_MASK 0x3fff0000
506#define JRINT_ERR_INDEX_SHIFT 16
507#define JRINT_ERR_TYPE_MASK 0xf00
508#define JRINT_ERR_TYPE_SHIFT 8
509#define JRINT_ERR_HALT_MASK 0xc
510#define JRINT_ERR_HALT_SHIFT 2
511#define JRINT_ERR_HALT_INPROGRESS 0x4
512#define JRINT_ERR_HALT_COMPLETE 0x8
513#define JRINT_JR_ERROR 0x02
514#define JRINT_JR_INT 0x01
515
516#define JRINT_ERR_TYPE_WRITE 1
517#define JRINT_ERR_TYPE_BAD_INPADDR 3
518#define JRINT_ERR_TYPE_BAD_OUTADDR 4
519#define JRINT_ERR_TYPE_INV_INPWRT 5
520#define JRINT_ERR_TYPE_INV_OUTWRT 6
521#define JRINT_ERR_TYPE_RESET 7
522#define JRINT_ERR_TYPE_REMOVE_OFL 8
523#define JRINT_ERR_TYPE_ADD_OFL 9
524
525#define JRCFG_SOE 0x04
526#define JRCFG_ICEN 0x02
527#define JRCFG_IMSK 0x01
528#define JRCFG_ICDCT_SHIFT 8
529#define JRCFG_ICTT_SHIFT 16
530
531#define JRCR_RESET 0x01
532
533
534
535
536
537
538struct rtic_element {
539 u64 address;
540 u32 rsvd;
541 u32 length;
542};
543
544struct rtic_block {
545 struct rtic_element element[2];
546};
547
548struct rtic_memhash {
549 u32 memhash_be[32];
550 u32 memhash_le[32];
551};
552
553struct caam_assurance {
554
555 u32 rsvd1;
556 u32 status;
557 u32 rsvd2;
558 u32 cmd;
559 u32 rsvd3;
560 u32 ctrl;
561 u32 rsvd4;
562 u32 throttle;
563 u32 rsvd5[2];
564 u64 watchdog;
565 u32 rsvd6;
566 u32 rend;
567 u32 rsvd7[50];
568
569
570 struct rtic_block memblk[4];
571 u32 rsvd8[32];
572
573
574 struct rtic_memhash hash[4];
575 u32 rsvd_3[640];
576};
577
578
579
580
581
582
583struct caam_queue_if {
584 u32 qi_control_hi;
585 u32 qi_control_lo;
586 u32 rsvd1;
587 u32 qi_status;
588 u32 qi_deq_cfg_hi;
589 u32 qi_deq_cfg_lo;
590 u32 qi_enq_cfg_hi;
591 u32 qi_enq_cfg_lo;
592 u32 rsvd2[1016];
593};
594
595
596#define QICTL_DQEN 0x01
597#define QICTL_STOP 0x02
598#define QICTL_SOE 0x04
599
600
601#define QICTL_MBSI 0x01
602#define QICTL_MHWSI 0x02
603#define QICTL_MWSI 0x04
604#define QICTL_MDWSI 0x08
605#define QICTL_CBSI 0x10
606#define QICTL_CHWSI 0x20
607#define QICTL_CWSI 0x40
608#define QICTL_CDWSI 0x80
609#define QICTL_MBSO 0x0100
610#define QICTL_MHWSO 0x0200
611#define QICTL_MWSO 0x0400
612#define QICTL_MDWSO 0x0800
613#define QICTL_CBSO 0x1000
614#define QICTL_CHWSO 0x2000
615#define QICTL_CWSO 0x4000
616#define QICTL_CDWSO 0x8000
617#define QICTL_DMBS 0x010000
618#define QICTL_EPO 0x020000
619
620
621#define QISTA_PHRDERR 0x01
622#define QISTA_CFRDERR 0x02
623#define QISTA_OFWRERR 0x04
624#define QISTA_BPDERR 0x08
625#define QISTA_BTSERR 0x10
626#define QISTA_CFWRERR 0x20
627#define QISTA_STOPD 0x80000000
628
629
630struct deco_sg_table {
631 u64 addr;
632 u32 elen;
633 u32 bpid_offset;
634};
635
636
637
638
639
640
641
642
643
644
645struct caam_deco {
646 u32 rsvd1;
647 u32 cls1_mode;
648 u32 rsvd2;
649 u32 cls1_keysize;
650 u32 cls1_datasize_hi;
651 u32 cls1_datasize_lo;
652 u32 rsvd3;
653 u32 cls1_icvsize;
654 u32 rsvd4[5];
655 u32 cha_ctrl;
656 u32 rsvd5;
657 u32 irq_crtl;
658 u32 rsvd6;
659 u32 clr_written;
660 u32 ccb_status_hi;
661 u32 ccb_status_lo;
662 u32 rsvd7[3];
663 u32 aad_size;
664 u32 rsvd8;
665 u32 cls1_iv_size;
666 u32 rsvd9[7];
667 u32 pkha_a_size;
668 u32 rsvd10;
669 u32 pkha_b_size;
670 u32 rsvd11;
671 u32 pkha_n_size;
672 u32 rsvd12;
673 u32 pkha_e_size;
674 u32 rsvd13[24];
675 u32 cls1_ctx[16];
676 u32 rsvd14[48];
677 u32 cls1_key[8];
678 u32 rsvd15[121];
679 u32 cls2_mode;
680 u32 rsvd16;
681 u32 cls2_keysize;
682 u32 cls2_datasize_hi;
683 u32 cls2_datasize_lo;
684 u32 rsvd17;
685 u32 cls2_icvsize;
686 u32 rsvd18[56];
687 u32 cls2_ctx[18];
688 u32 rsvd19[46];
689 u32 cls2_key[32];
690 u32 rsvd20[84];
691 u32 inp_infofifo_hi;
692 u32 inp_infofifo_lo;
693 u32 rsvd21[2];
694 u64 inp_datafifo;
695 u32 rsvd22[2];
696 u64 out_datafifo;
697 u32 rsvd23[2];
698 u32 jr_ctl_hi;
699 u32 jr_ctl_lo;
700 u64 jr_descaddr;
701#define DECO_OP_STATUS_HI_ERR_MASK 0xF00000FF
702 u32 op_status_hi;
703 u32 op_status_lo;
704 u32 rsvd24[2];
705 u32 liodn;
706 u32 td_liodn;
707 u32 rsvd26[6];
708 u64 math[4];
709 u32 rsvd27[8];
710 struct deco_sg_table gthr_tbl[4];
711 u32 rsvd28[16];
712 struct deco_sg_table sctr_tbl[4];
713 u32 rsvd29[48];
714 u32 descbuf[64];
715 u32 rscvd30[193];
716#define DESC_DBG_DECO_STAT_HOST_ERR 0x00D00000
717#define DESC_DBG_DECO_STAT_VALID 0x80000000
718#define DESC_DBG_DECO_STAT_MASK 0x00F00000
719 u32 desc_dbg;
720 u32 rsvd31[126];
721};
722
723#define DECO_JQCR_WHL 0x20000000
724#define DECO_JQCR_FOUR 0x10000000
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747struct caam_full {
748 struct caam_ctrl __iomem ctrl;
749 struct caam_job_ring jr[4];
750 u64 rsvd[512];
751 struct caam_assurance assure;
752 struct caam_queue_if qi;
753 struct caam_deco deco;
754};
755
756#endif
757