1515#include "desc_constr.h"
1616#include "error.h"
1717
18+ bool caam_little_end ;
19+ EXPORT_SYMBOL (caam_little_end );
20+
1821/*
1922 * i.MX targets tend to have clock control subsystems that can
2023 * enable/disable clocking to our device.
@@ -106,7 +109,7 @@ static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc,
106109
107110
108111 if (ctrlpriv -> virt_en == 1 ) {
109- setbits32 (& ctrl -> deco_rsr , DECORSR_JR0 );
112+ clrsetbits_32 (& ctrl -> deco_rsr , 0 , DECORSR_JR0 );
110113
111114 while (!(rd_reg32 (& ctrl -> deco_rsr ) & DECORSR_VALID ) &&
112115 -- timeout )
@@ -115,20 +118,20 @@ static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc,
115118 timeout = 100000 ;
116119 }
117120
118- setbits32 (& ctrl -> deco_rq , DECORR_RQD0ENABLE );
121+ clrsetbits_32 (& ctrl -> deco_rq , 0 , DECORR_RQD0ENABLE );
119122
120123 while (!(rd_reg32 (& ctrl -> deco_rq ) & DECORR_DEN0 ) &&
121124 -- timeout )
122125 cpu_relax ();
123126
124127 if (!timeout ) {
125128 dev_err (ctrldev , "failed to acquire DECO 0\n" );
126- clrbits32 (& ctrl -> deco_rq , DECORR_RQD0ENABLE );
129+ clrsetbits_32 (& ctrl -> deco_rq , DECORR_RQD0ENABLE , 0 );
127130 return - ENODEV ;
128131 }
129132
130133 for (i = 0 ; i < desc_len (desc ); i ++ )
131- wr_reg32 (& deco -> descbuf [i ], * (desc + i ));
134+ wr_reg32 (& deco -> descbuf [i ], caam32_to_cpu ( * (desc + i ) ));
132135
133136 flags = DECO_JQCR_WHL ;
134137 /*
@@ -139,7 +142,7 @@ static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc,
139142 flags |= DECO_JQCR_FOUR ;
140143
141144 /* Instruct the DECO to execute it */
142- setbits32 (& deco -> jr_ctl_hi , flags );
145+ clrsetbits_32 (& deco -> jr_ctl_hi , 0 , flags );
143146
144147 timeout = 10000000 ;
145148 do {
@@ -158,10 +161,10 @@ static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc,
158161 DECO_OP_STATUS_HI_ERR_MASK ;
159162
160163 if (ctrlpriv -> virt_en == 1 )
161- clrbits32 (& ctrl -> deco_rsr , DECORSR_JR0 );
164+ clrsetbits_32 (& ctrl -> deco_rsr , DECORSR_JR0 , 0 );
162165
163166 /* Mark the DECO as free */
164- clrbits32 (& ctrl -> deco_rq , DECORR_RQD0ENABLE );
167+ clrsetbits_32 (& ctrl -> deco_rq , DECORR_RQD0ENABLE , 0 );
165168
166169 if (!timeout )
167170 return - EAGAIN ;
@@ -349,7 +352,7 @@ static void kick_trng(struct platform_device *pdev, int ent_delay)
349352 r4tst = & ctrl -> r4tst [0 ];
350353
351354 /* put RNG4 into program mode */
352- setbits32 (& r4tst -> rtmctl , RTMCTL_PRGM );
355+ clrsetbits_32 (& r4tst -> rtmctl , 0 , RTMCTL_PRGM );
353356
354357 /*
355358 * Performance-wise, it does not make sense to
@@ -363,7 +366,7 @@ static void kick_trng(struct platform_device *pdev, int ent_delay)
363366 >> RTSDCTL_ENT_DLY_SHIFT ;
364367 if (ent_delay <= val ) {
365368 /* put RNG4 into run mode */
366- clrbits32 (& r4tst -> rtmctl , RTMCTL_PRGM );
369+ clrsetbits_32 (& r4tst -> rtmctl , RTMCTL_PRGM , 0 );
367370 return ;
368371 }
369372
@@ -381,9 +384,9 @@ static void kick_trng(struct platform_device *pdev, int ent_delay)
381384 * select raw sampling in both entropy shifter
382385 * and statistical checker
383386 */
384- setbits32 (& val , RTMCTL_SAMP_MODE_RAW_ES_SC );
387+ clrsetbits_32 (& val , 0 , RTMCTL_SAMP_MODE_RAW_ES_SC );
385388 /* put RNG4 into run mode */
386- clrbits32 (& val , RTMCTL_PRGM );
389+ clrsetbits_32 (& val , RTMCTL_PRGM , 0 );
387390 /* write back the control register */
388391 wr_reg32 (& r4tst -> rtmctl , val );
389392}
@@ -406,6 +409,23 @@ int caam_get_era(void)
406409}
407410EXPORT_SYMBOL (caam_get_era );
408411
412+ #ifdef CONFIG_DEBUG_FS
413+ static int caam_debugfs_u64_get (void * data , u64 * val )
414+ {
415+ * val = caam64_to_cpu (* (u64 * )data );
416+ return 0 ;
417+ }
418+
419+ static int caam_debugfs_u32_get (void * data , u64 * val )
420+ {
421+ * val = caam32_to_cpu (* (u32 * )data );
422+ return 0 ;
423+ }
424+
425+ DEFINE_SIMPLE_ATTRIBUTE (caam_fops_u32_ro , caam_debugfs_u32_get , NULL , "%llu\n" );
426+ DEFINE_SIMPLE_ATTRIBUTE (caam_fops_u64_ro , caam_debugfs_u64_get , NULL , "%llu\n" );
427+ #endif
428+
409429/* Probe routine for CAAM top (controller) level */
410430static int caam_probe (struct platform_device * pdev )
411431{
@@ -504,6 +524,10 @@ static int caam_probe(struct platform_device *pdev)
504524 ret = - ENOMEM ;
505525 goto disable_caam_emi_slow ;
506526 }
527+
528+ caam_little_end = !(bool )(rd_reg32 (& ctrl -> perfmon .status ) &
529+ (CSTA_PLEND | CSTA_ALT_PLEND ));
530+
507531 /* Finding the page size for using the CTPR_MS register */
508532 comp_params = rd_reg32 (& ctrl -> perfmon .comp_parms_ms );
509533 pg_size = (comp_params & CTPR_MS_PG_SZ_MASK ) >> CTPR_MS_PG_SZ_SHIFT ;
@@ -559,9 +583,9 @@ static int caam_probe(struct platform_device *pdev)
559583 }
560584
561585 if (ctrlpriv -> virt_en == 1 )
562- setbits32 (& ctrl -> jrstart , JRSTART_JR0_START |
563- JRSTART_JR1_START | JRSTART_JR2_START |
564- JRSTART_JR3_START );
586+ clrsetbits_32 (& ctrl -> jrstart , 0 , JRSTART_JR0_START |
587+ JRSTART_JR1_START | JRSTART_JR2_START |
588+ JRSTART_JR3_START );
565589
566590 if (sizeof (dma_addr_t ) == sizeof (u64 ))
567591 if (of_device_is_compatible (nprop , "fsl,sec-v5.0" ))
@@ -693,7 +717,7 @@ static int caam_probe(struct platform_device *pdev)
693717 ctrlpriv -> rng4_sh_init = ~ctrlpriv -> rng4_sh_init & RDSTA_IFMASK ;
694718
695719 /* Enable RDB bit so that RNG works faster */
696- setbits32 (& ctrl -> scfgr , SCFGR_RDBENABLE );
720+ clrsetbits_32 (& ctrl -> scfgr , 0 , SCFGR_RDBENABLE );
697721 }
698722
699723 /* NOTE: RTIC detection ought to go here, around Si time */
@@ -719,48 +743,59 @@ static int caam_probe(struct platform_device *pdev)
719743 ctrlpriv -> ctl = debugfs_create_dir ("ctl" , ctrlpriv -> dfs_root );
720744
721745 /* Controller-level - performance monitor counters */
746+
722747 ctrlpriv -> ctl_rq_dequeued =
723- debugfs_create_u64 ("rq_dequeued" ,
724- S_IRUSR | S_IRGRP | S_IROTH ,
725- ctrlpriv -> ctl , & perfmon -> req_dequeued );
748+ debugfs_create_file ("rq_dequeued" ,
749+ S_IRUSR | S_IRGRP | S_IROTH ,
750+ ctrlpriv -> ctl , & perfmon -> req_dequeued ,
751+ & caam_fops_u64_ro );
726752 ctrlpriv -> ctl_ob_enc_req =
727- debugfs_create_u64 ("ob_rq_encrypted" ,
728- S_IRUSR | S_IRGRP | S_IROTH ,
729- ctrlpriv -> ctl , & perfmon -> ob_enc_req );
753+ debugfs_create_file ("ob_rq_encrypted" ,
754+ S_IRUSR | S_IRGRP | S_IROTH ,
755+ ctrlpriv -> ctl , & perfmon -> ob_enc_req ,
756+ & caam_fops_u64_ro );
730757 ctrlpriv -> ctl_ib_dec_req =
731- debugfs_create_u64 ("ib_rq_decrypted" ,
732- S_IRUSR | S_IRGRP | S_IROTH ,
733- ctrlpriv -> ctl , & perfmon -> ib_dec_req );
758+ debugfs_create_file ("ib_rq_decrypted" ,
759+ S_IRUSR | S_IRGRP | S_IROTH ,
760+ ctrlpriv -> ctl , & perfmon -> ib_dec_req ,
761+ & caam_fops_u64_ro );
734762 ctrlpriv -> ctl_ob_enc_bytes =
735- debugfs_create_u64 ("ob_bytes_encrypted" ,
736- S_IRUSR | S_IRGRP | S_IROTH ,
737- ctrlpriv -> ctl , & perfmon -> ob_enc_bytes );
763+ debugfs_create_file ("ob_bytes_encrypted" ,
764+ S_IRUSR | S_IRGRP | S_IROTH ,
765+ ctrlpriv -> ctl , & perfmon -> ob_enc_bytes ,
766+ & caam_fops_u64_ro );
738767 ctrlpriv -> ctl_ob_prot_bytes =
739- debugfs_create_u64 ("ob_bytes_protected" ,
740- S_IRUSR | S_IRGRP | S_IROTH ,
741- ctrlpriv -> ctl , & perfmon -> ob_prot_bytes );
768+ debugfs_create_file ("ob_bytes_protected" ,
769+ S_IRUSR | S_IRGRP | S_IROTH ,
770+ ctrlpriv -> ctl , & perfmon -> ob_prot_bytes ,
771+ & caam_fops_u64_ro );
742772 ctrlpriv -> ctl_ib_dec_bytes =
743- debugfs_create_u64 ("ib_bytes_decrypted" ,
744- S_IRUSR | S_IRGRP | S_IROTH ,
745- ctrlpriv -> ctl , & perfmon -> ib_dec_bytes );
773+ debugfs_create_file ("ib_bytes_decrypted" ,
774+ S_IRUSR | S_IRGRP | S_IROTH ,
775+ ctrlpriv -> ctl , & perfmon -> ib_dec_bytes ,
776+ & caam_fops_u64_ro );
746777 ctrlpriv -> ctl_ib_valid_bytes =
747- debugfs_create_u64 ("ib_bytes_validated" ,
748- S_IRUSR | S_IRGRP | S_IROTH ,
749- ctrlpriv -> ctl , & perfmon -> ib_valid_bytes );
778+ debugfs_create_file ("ib_bytes_validated" ,
779+ S_IRUSR | S_IRGRP | S_IROTH ,
780+ ctrlpriv -> ctl , & perfmon -> ib_valid_bytes ,
781+ & caam_fops_u64_ro );
750782
751783 /* Controller level - global status values */
752784 ctrlpriv -> ctl_faultaddr =
753- debugfs_create_u64 ("fault_addr" ,
754- S_IRUSR | S_IRGRP | S_IROTH ,
755- ctrlpriv -> ctl , & perfmon -> faultaddr );
785+ debugfs_create_file ("fault_addr" ,
786+ S_IRUSR | S_IRGRP | S_IROTH ,
787+ ctrlpriv -> ctl , & perfmon -> faultaddr ,
788+ & caam_fops_u32_ro );
756789 ctrlpriv -> ctl_faultdetail =
757- debugfs_create_u32 ("fault_detail" ,
758- S_IRUSR | S_IRGRP | S_IROTH ,
759- ctrlpriv -> ctl , & perfmon -> faultdetail );
790+ debugfs_create_file ("fault_detail" ,
791+ S_IRUSR | S_IRGRP | S_IROTH ,
792+ ctrlpriv -> ctl , & perfmon -> faultdetail ,
793+ & caam_fops_u32_ro );
760794 ctrlpriv -> ctl_faultstatus =
761- debugfs_create_u32 ("fault_status" ,
762- S_IRUSR | S_IRGRP | S_IROTH ,
763- ctrlpriv -> ctl , & perfmon -> status );
795+ debugfs_create_file ("fault_status" ,
796+ S_IRUSR | S_IRGRP | S_IROTH ,
797+ ctrlpriv -> ctl , & perfmon -> status ,
798+ & caam_fops_u32_ro );
764799
765800 /* Internal covering keys (useful in non-secure mode only) */
766801 ctrlpriv -> ctl_kek_wrap .data = & ctrlpriv -> ctrl -> kek [0 ];
0 commit comments