@@ -451,6 +451,228 @@ static void zip_unregister_compression_device(void)
451451 crypto_unregister_scomp (& zip_scomp_lzs );
452452}
453453
454+ /*
455+ * debugfs functions
456+ */
457+ #ifdef CONFIG_DEBUG_FS
458+ #include <linux/debugfs.h>
459+
460+ /* Displays ZIP device statistics */
461+ static int zip_show_stats (struct seq_file * s , void * unused )
462+ {
463+ u64 val = 0ull ;
464+ u64 avg_chunk = 0ull , avg_cr = 0ull ;
465+ u32 q = 0 ;
466+
467+ int index = 0 ;
468+ struct zip_device * zip ;
469+ struct zip_stats * st ;
470+
471+ for (index = 0 ; index < MAX_ZIP_DEVICES ; index ++ ) {
472+ if (zip_dev [index ]) {
473+ zip = zip_dev [index ];
474+ st = & zip -> stats ;
475+
476+ /* Get all the pending requests */
477+ for (q = 0 ; q < ZIP_NUM_QUEUES ; q ++ ) {
478+ val = zip_reg_read ((zip -> reg_base +
479+ ZIP_DBG_COREX_STA (q )));
480+ val = (val >> 32 );
481+ val = val & 0xffffff ;
482+ atomic64_add (val , & st -> pending_req );
483+ }
484+
485+ avg_chunk = (atomic64_read (& st -> comp_in_bytes ) /
486+ atomic64_read (& st -> comp_req_complete ));
487+ avg_cr = (atomic64_read (& st -> comp_in_bytes ) /
488+ atomic64_read (& st -> comp_out_bytes ));
489+ seq_printf (s , " ZIP Device %d Stats\n"
490+ "-----------------------------------\n"
491+ "Comp Req Submitted : \t%ld\n"
492+ "Comp Req Completed : \t%ld\n"
493+ "Compress In Bytes : \t%ld\n"
494+ "Compressed Out Bytes : \t%ld\n"
495+ "Average Chunk size : \t%llu\n"
496+ "Average Compression ratio : \t%llu\n"
497+ "Decomp Req Submitted : \t%ld\n"
498+ "Decomp Req Completed : \t%ld\n"
499+ "Decompress In Bytes : \t%ld\n"
500+ "Decompressed Out Bytes : \t%ld\n"
501+ "Decompress Bad requests : \t%ld\n"
502+ "Pending Req : \t%ld\n"
503+ "---------------------------------\n" ,
504+ index ,
505+ atomic64_read (& st -> comp_req_submit ),
506+ atomic64_read (& st -> comp_req_complete ),
507+ atomic64_read (& st -> comp_in_bytes ),
508+ atomic64_read (& st -> comp_out_bytes ),
509+ avg_chunk ,
510+ avg_cr ,
511+ atomic64_read (& st -> decomp_req_submit ),
512+ atomic64_read (& st -> decomp_req_complete ),
513+ atomic64_read (& st -> decomp_in_bytes ),
514+ atomic64_read (& st -> decomp_out_bytes ),
515+ atomic64_read (& st -> decomp_bad_reqs ),
516+ atomic64_read (& st -> pending_req ));
517+
518+ /* Reset pending requests count */
519+ atomic64_set (& st -> pending_req , 0 );
520+ }
521+ }
522+ return 0 ;
523+ }
524+
525+ /* Clears stats data */
526+ static int zip_clear_stats (struct seq_file * s , void * unused )
527+ {
528+ int index = 0 ;
529+
530+ for (index = 0 ; index < MAX_ZIP_DEVICES ; index ++ ) {
531+ if (zip_dev [index ]) {
532+ memset (& zip_dev [index ]-> stats , 0 ,
533+ sizeof (struct zip_state ));
534+ seq_printf (s , "Cleared stats for zip %d\n" , index );
535+ }
536+ }
537+
538+ return 0 ;
539+ }
540+
541+ static struct zip_registers zipregs [64 ] = {
542+ {"ZIP_CMD_CTL " , 0x0000ull },
543+ {"ZIP_THROTTLE " , 0x0010ull },
544+ {"ZIP_CONSTANTS " , 0x00A0ull },
545+ {"ZIP_QUE0_MAP " , 0x1400ull },
546+ {"ZIP_QUE1_MAP " , 0x1408ull },
547+ {"ZIP_QUE_ENA " , 0x0500ull },
548+ {"ZIP_QUE_PRI " , 0x0508ull },
549+ {"ZIP_QUE0_DONE " , 0x2000ull },
550+ {"ZIP_QUE1_DONE " , 0x2008ull },
551+ {"ZIP_QUE0_DOORBELL " , 0x4000ull },
552+ {"ZIP_QUE1_DOORBELL " , 0x4008ull },
553+ {"ZIP_QUE0_SBUF_ADDR " , 0x1000ull },
554+ {"ZIP_QUE1_SBUF_ADDR " , 0x1008ull },
555+ {"ZIP_QUE0_SBUF_CTL " , 0x1200ull },
556+ {"ZIP_QUE1_SBUF_CTL " , 0x1208ull },
557+ { NULL , 0 }
558+ };
559+
560+ /* Prints registers' contents */
561+ static int zip_print_regs (struct seq_file * s , void * unused )
562+ {
563+ u64 val = 0 ;
564+ int i = 0 , index = 0 ;
565+
566+ for (index = 0 ; index < MAX_ZIP_DEVICES ; index ++ ) {
567+ if (zip_dev [index ]) {
568+ seq_printf (s , "--------------------------------\n"
569+ " ZIP Device %d Registers\n"
570+ "--------------------------------\n" ,
571+ index );
572+
573+ i = 0 ;
574+
575+ while (zipregs [i ].reg_name ) {
576+ val = zip_reg_read ((zip_dev [index ]-> reg_base +
577+ zipregs [i ].reg_offset ));
578+ seq_printf (s , "%s: 0x%016llx\n" ,
579+ zipregs [i ].reg_name , val );
580+ i ++ ;
581+ }
582+ }
583+ }
584+ return 0 ;
585+ }
586+
587+ static int zip_stats_open (struct inode * inode , struct file * file )
588+ {
589+ return single_open (file , zip_show_stats , NULL );
590+ }
591+
592+ static const struct file_operations zip_stats_fops = {
593+ .owner = THIS_MODULE ,
594+ .open = zip_stats_open ,
595+ .read = seq_read ,
596+ };
597+
598+ static int zip_clear_open (struct inode * inode , struct file * file )
599+ {
600+ return single_open (file , zip_clear_stats , NULL );
601+ }
602+
603+ static const struct file_operations zip_clear_fops = {
604+ .owner = THIS_MODULE ,
605+ .open = zip_clear_open ,
606+ .read = seq_read ,
607+ };
608+
609+ static int zip_regs_open (struct inode * inode , struct file * file )
610+ {
611+ return single_open (file , zip_print_regs , NULL );
612+ }
613+
614+ static const struct file_operations zip_regs_fops = {
615+ .owner = THIS_MODULE ,
616+ .open = zip_regs_open ,
617+ .read = seq_read ,
618+ };
619+
620+ /* Root directory for thunderx_zip debugfs entry */
621+ static struct dentry * zip_debugfs_root ;
622+
623+ static int __init zip_debugfs_init (void )
624+ {
625+ struct dentry * zip_stats , * zip_clear , * zip_regs ;
626+
627+ if (!debugfs_initialized ())
628+ return - ENODEV ;
629+
630+ zip_debugfs_root = debugfs_create_dir ("thunderx_zip" , NULL );
631+ if (!zip_debugfs_root )
632+ return - ENOMEM ;
633+
634+ /* Creating files for entries inside thunderx_zip directory */
635+ zip_stats = debugfs_create_file ("zip_stats" , 0444 ,
636+ zip_debugfs_root ,
637+ NULL , & zip_stats_fops );
638+ if (!zip_stats )
639+ goto failed_to_create ;
640+
641+ zip_clear = debugfs_create_file ("zip_clear" , 0444 ,
642+ zip_debugfs_root ,
643+ NULL , & zip_clear_fops );
644+ if (!zip_clear )
645+ goto failed_to_create ;
646+
647+ zip_regs = debugfs_create_file ("zip_regs" , 0444 ,
648+ zip_debugfs_root ,
649+ NULL , & zip_regs_fops );
650+ if (!zip_regs )
651+ goto failed_to_create ;
652+
653+ return 0 ;
654+
655+ failed_to_create :
656+ debugfs_remove_recursive (zip_debugfs_root );
657+ return - ENOENT ;
658+ }
659+
660+ static void __exit zip_debugfs_exit (void )
661+ {
662+ debugfs_remove_recursive (zip_debugfs_root );
663+ }
664+
665+ #else
666+ static int __init zip_debugfs_init (void )
667+ {
668+ return 0 ;
669+ }
670+
671+ static void __exit zip_debugfs_exit (void ) { }
672+
673+ #endif
674+ /* debugfs - end */
675+
454676static int __init zip_init_module (void )
455677{
456678 int ret ;
@@ -470,15 +692,27 @@ static int __init zip_init_module(void)
470692 goto err_pci_unregister ;
471693 }
472694
695+ /* comp-decomp statistics are handled with debugfs interface */
696+ ret = zip_debugfs_init ();
697+ if (ret < 0 ) {
698+ zip_err ("ZIP: debugfs initialization failed\n" );
699+ goto err_crypto_unregister ;
700+ }
701+
473702 return ret ;
474703
704+ err_crypto_unregister :
705+ zip_unregister_compression_device ();
706+
475707err_pci_unregister :
476708 pci_unregister_driver (& zip_driver );
477709 return ret ;
478710}
479711
480712static void __exit zip_cleanup_module (void )
481713{
714+ zip_debugfs_exit ();
715+
482716 /* Unregister from the kernel crypto interface */
483717 zip_unregister_compression_device ();
484718
0 commit comments