@@ -3576,6 +3576,11 @@ debugfs_to_reg_name_v3_hw(int off, int base_off,
35763576 return NULL ;
35773577}
35783578
3579+ static bool debugfs_dump_is_generated_v3_hw (void * p )
3580+ {
3581+ return p ? true : false;
3582+ }
3583+
35793584static void debugfs_print_reg_v3_hw (u32 * regs_val , struct seq_file * s ,
35803585 const struct hisi_sas_debugfs_reg * reg )
35813586{
@@ -3601,6 +3606,9 @@ static int debugfs_global_v3_hw_show(struct seq_file *s, void *p)
36013606{
36023607 struct hisi_sas_debugfs_regs * global = s -> private ;
36033608
3609+ if (!debugfs_dump_is_generated_v3_hw (global -> data ))
3610+ return - EPERM ;
3611+
36043612 debugfs_print_reg_v3_hw (global -> data , s ,
36053613 & debugfs_global_reg );
36063614
@@ -3612,6 +3620,9 @@ static int debugfs_axi_v3_hw_show(struct seq_file *s, void *p)
36123620{
36133621 struct hisi_sas_debugfs_regs * axi = s -> private ;
36143622
3623+ if (!debugfs_dump_is_generated_v3_hw (axi -> data ))
3624+ return - EPERM ;
3625+
36153626 debugfs_print_reg_v3_hw (axi -> data , s ,
36163627 & debugfs_axi_reg );
36173628
@@ -3623,6 +3634,9 @@ static int debugfs_ras_v3_hw_show(struct seq_file *s, void *p)
36233634{
36243635 struct hisi_sas_debugfs_regs * ras = s -> private ;
36253636
3637+ if (!debugfs_dump_is_generated_v3_hw (ras -> data ))
3638+ return - EPERM ;
3639+
36263640 debugfs_print_reg_v3_hw (ras -> data , s ,
36273641 & debugfs_ras_reg );
36283642
@@ -3635,6 +3649,9 @@ static int debugfs_port_v3_hw_show(struct seq_file *s, void *p)
36353649 struct hisi_sas_debugfs_port * port = s -> private ;
36363650 const struct hisi_sas_debugfs_reg * reg_port = & debugfs_port_reg ;
36373651
3652+ if (!debugfs_dump_is_generated_v3_hw (port -> data ))
3653+ return - EPERM ;
3654+
36383655 debugfs_print_reg_v3_hw (port -> data , s , reg_port );
36393656
36403657 return 0 ;
@@ -3690,6 +3707,9 @@ static int debugfs_cq_v3_hw_show(struct seq_file *s, void *p)
36903707 struct hisi_sas_debugfs_cq * debugfs_cq = s -> private ;
36913708 int slot ;
36923709
3710+ if (!debugfs_dump_is_generated_v3_hw (debugfs_cq -> complete_hdr ))
3711+ return - EPERM ;
3712+
36933713 for (slot = 0 ; slot < HISI_SAS_QUEUE_SLOTS ; slot ++ )
36943714 debugfs_cq_show_slot_v3_hw (s , slot , debugfs_cq );
36953715
@@ -3711,8 +3731,12 @@ static void debugfs_dq_show_slot_v3_hw(struct seq_file *s, int slot,
37113731
37123732static int debugfs_dq_v3_hw_show (struct seq_file * s , void * p )
37133733{
3734+ struct hisi_sas_debugfs_dq * debugfs_dq = s -> private ;
37143735 int slot ;
37153736
3737+ if (!debugfs_dump_is_generated_v3_hw (debugfs_dq -> hdr ))
3738+ return - EPERM ;
3739+
37163740 for (slot = 0 ; slot < HISI_SAS_QUEUE_SLOTS ; slot ++ )
37173741 debugfs_dq_show_slot_v3_hw (s , slot , s -> private );
37183742
@@ -3726,6 +3750,9 @@ static int debugfs_iost_v3_hw_show(struct seq_file *s, void *p)
37263750 struct hisi_sas_iost * iost = debugfs_iost -> iost ;
37273751 int i , max_command_entries = HISI_SAS_MAX_COMMANDS ;
37283752
3753+ if (!debugfs_dump_is_generated_v3_hw (iost ))
3754+ return - EPERM ;
3755+
37293756 for (i = 0 ; i < max_command_entries ; i ++ , iost ++ ) {
37303757 __le64 * data = & iost -> qw0 ;
37313758
@@ -3745,6 +3772,9 @@ static int debugfs_iost_cache_v3_hw_show(struct seq_file *s, void *p)
37453772 int i , tab_idx ;
37463773 __le64 * iost ;
37473774
3775+ if (!debugfs_dump_is_generated_v3_hw (iost_cache ))
3776+ return - EPERM ;
3777+
37483778 for (i = 0 ; i < HISI_SAS_IOST_ITCT_CACHE_NUM ; i ++ , iost_cache ++ ) {
37493779 /*
37503780 * Data struct of IOST cache:
@@ -3768,6 +3798,9 @@ static int debugfs_itct_v3_hw_show(struct seq_file *s, void *p)
37683798 struct hisi_sas_debugfs_itct * debugfs_itct = s -> private ;
37693799 struct hisi_sas_itct * itct = debugfs_itct -> itct ;
37703800
3801+ if (!debugfs_dump_is_generated_v3_hw (itct ))
3802+ return - EPERM ;
3803+
37713804 for (i = 0 ; i < HISI_SAS_MAX_ITCT_ENTRIES ; i ++ , itct ++ ) {
37723805 __le64 * data = & itct -> qw0 ;
37733806
@@ -3787,6 +3820,9 @@ static int debugfs_itct_cache_v3_hw_show(struct seq_file *s, void *p)
37873820 int i , tab_idx ;
37883821 __le64 * itct ;
37893822
3823+ if (!debugfs_dump_is_generated_v3_hw (itct_cache ))
3824+ return - EPERM ;
3825+
37903826 for (i = 0 ; i < HISI_SAS_IOST_ITCT_CACHE_NUM ; i ++ , itct_cache ++ ) {
37913827 /*
37923828 * Data struct of ITCT cache:
@@ -3804,28 +3840,27 @@ static int debugfs_itct_cache_v3_hw_show(struct seq_file *s, void *p)
38043840}
38053841DEFINE_SHOW_ATTRIBUTE (debugfs_itct_cache_v3_hw );
38063842
3807- static void debugfs_create_files_v3_hw (struct hisi_hba * hisi_hba )
3843+ static void debugfs_create_files_v3_hw (struct hisi_hba * hisi_hba , int index )
38083844{
38093845 u64 * debugfs_timestamp ;
3810- int dump_index = hisi_hba -> debugfs_dump_index ;
38113846 struct dentry * dump_dentry ;
38123847 struct dentry * dentry ;
38133848 char name [256 ];
38143849 int p ;
38153850 int c ;
38163851 int d ;
38173852
3818- snprintf (name , 256 , "%d" , dump_index );
3853+ snprintf (name , 256 , "%d" , index );
38193854
38203855 dump_dentry = debugfs_create_dir (name , hisi_hba -> debugfs_dump_dentry );
38213856
3822- debugfs_timestamp = & hisi_hba -> debugfs_timestamp [dump_index ];
3857+ debugfs_timestamp = & hisi_hba -> debugfs_timestamp [index ];
38233858
38243859 debugfs_create_u64 ("timestamp" , 0400 , dump_dentry ,
38253860 debugfs_timestamp );
38263861
38273862 debugfs_create_file ("global" , 0400 , dump_dentry ,
3828- & hisi_hba -> debugfs_regs [dump_index ][DEBUGFS_GLOBAL ],
3863+ & hisi_hba -> debugfs_regs [index ][DEBUGFS_GLOBAL ],
38293864 & debugfs_global_v3_hw_fops );
38303865
38313866 /* Create port dir and files */
@@ -3834,7 +3869,7 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38343869 snprintf (name , 256 , "%d" , p );
38353870
38363871 debugfs_create_file (name , 0400 , dentry ,
3837- & hisi_hba -> debugfs_port_reg [dump_index ][p ],
3872+ & hisi_hba -> debugfs_port_reg [index ][p ],
38383873 & debugfs_port_v3_hw_fops );
38393874 }
38403875
@@ -3844,7 +3879,7 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38443879 snprintf (name , 256 , "%d" , c );
38453880
38463881 debugfs_create_file (name , 0400 , dentry ,
3847- & hisi_hba -> debugfs_cq [dump_index ][c ],
3882+ & hisi_hba -> debugfs_cq [index ][c ],
38483883 & debugfs_cq_v3_hw_fops );
38493884 }
38503885
@@ -3854,32 +3889,32 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38543889 snprintf (name , 256 , "%d" , d );
38553890
38563891 debugfs_create_file (name , 0400 , dentry ,
3857- & hisi_hba -> debugfs_dq [dump_index ][d ],
3892+ & hisi_hba -> debugfs_dq [index ][d ],
38583893 & debugfs_dq_v3_hw_fops );
38593894 }
38603895
38613896 debugfs_create_file ("iost" , 0400 , dump_dentry ,
3862- & hisi_hba -> debugfs_iost [dump_index ],
3897+ & hisi_hba -> debugfs_iost [index ],
38633898 & debugfs_iost_v3_hw_fops );
38643899
38653900 debugfs_create_file ("iost_cache" , 0400 , dump_dentry ,
3866- & hisi_hba -> debugfs_iost_cache [dump_index ],
3901+ & hisi_hba -> debugfs_iost_cache [index ],
38673902 & debugfs_iost_cache_v3_hw_fops );
38683903
38693904 debugfs_create_file ("itct" , 0400 , dump_dentry ,
3870- & hisi_hba -> debugfs_itct [dump_index ],
3905+ & hisi_hba -> debugfs_itct [index ],
38713906 & debugfs_itct_v3_hw_fops );
38723907
38733908 debugfs_create_file ("itct_cache" , 0400 , dump_dentry ,
3874- & hisi_hba -> debugfs_itct_cache [dump_index ],
3909+ & hisi_hba -> debugfs_itct_cache [index ],
38753910 & debugfs_itct_cache_v3_hw_fops );
38763911
38773912 debugfs_create_file ("axi" , 0400 , dump_dentry ,
3878- & hisi_hba -> debugfs_regs [dump_index ][DEBUGFS_AXI ],
3913+ & hisi_hba -> debugfs_regs [index ][DEBUGFS_AXI ],
38793914 & debugfs_axi_v3_hw_fops );
38803915
38813916 debugfs_create_file ("ras" , 0400 , dump_dentry ,
3882- & hisi_hba -> debugfs_regs [dump_index ][DEBUGFS_RAS ],
3917+ & hisi_hba -> debugfs_regs [index ][DEBUGFS_RAS ],
38833918 & debugfs_ras_v3_hw_fops );
38843919}
38853920
@@ -4542,22 +4577,34 @@ static void debugfs_release_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
45424577 int i ;
45434578
45444579 devm_kfree (dev , hisi_hba -> debugfs_iost_cache [dump_index ].cache );
4580+ hisi_hba -> debugfs_iost_cache [dump_index ].cache = NULL ;
45454581 devm_kfree (dev , hisi_hba -> debugfs_itct_cache [dump_index ].cache );
4582+ hisi_hba -> debugfs_itct_cache [dump_index ].cache = NULL ;
45464583 devm_kfree (dev , hisi_hba -> debugfs_iost [dump_index ].iost );
4584+ hisi_hba -> debugfs_iost [dump_index ].iost = NULL ;
45474585 devm_kfree (dev , hisi_hba -> debugfs_itct [dump_index ].itct );
4586+ hisi_hba -> debugfs_itct [dump_index ].itct = NULL ;
45484587
4549- for (i = 0 ; i < hisi_hba -> queue_count ; i ++ )
4588+ for (i = 0 ; i < hisi_hba -> queue_count ; i ++ ) {
45504589 devm_kfree (dev , hisi_hba -> debugfs_dq [dump_index ][i ].hdr );
4590+ hisi_hba -> debugfs_dq [dump_index ][i ].hdr = NULL ;
4591+ }
45514592
4552- for (i = 0 ; i < hisi_hba -> queue_count ; i ++ )
4593+ for (i = 0 ; i < hisi_hba -> queue_count ; i ++ ) {
45534594 devm_kfree (dev ,
45544595 hisi_hba -> debugfs_cq [dump_index ][i ].complete_hdr );
4596+ hisi_hba -> debugfs_cq [dump_index ][i ].complete_hdr = NULL ;
4597+ }
45554598
4556- for (i = 0 ; i < DEBUGFS_REGS_NUM ; i ++ )
4599+ for (i = 0 ; i < DEBUGFS_REGS_NUM ; i ++ ) {
45574600 devm_kfree (dev , hisi_hba -> debugfs_regs [dump_index ][i ].data );
4601+ hisi_hba -> debugfs_regs [dump_index ][i ].data = NULL ;
4602+ }
45584603
4559- for (i = 0 ; i < hisi_hba -> n_phy ; i ++ )
4604+ for (i = 0 ; i < hisi_hba -> n_phy ; i ++ ) {
45604605 devm_kfree (dev , hisi_hba -> debugfs_port_reg [dump_index ][i ].data );
4606+ hisi_hba -> debugfs_port_reg [dump_index ][i ].data = NULL ;
4607+ }
45614608}
45624609
45634610static const struct hisi_sas_debugfs_reg * debugfs_reg_array_v3_hw [DEBUGFS_REGS_NUM ] = {
@@ -4684,8 +4731,6 @@ static int debugfs_snapshot_regs_v3_hw(struct hisi_hba *hisi_hba)
46844731 debugfs_snapshot_itct_reg_v3_hw (hisi_hba );
46854732 debugfs_snapshot_iost_reg_v3_hw (hisi_hba );
46864733
4687- debugfs_create_files_v3_hw (hisi_hba );
4688-
46894734 debugfs_snapshot_restore_v3_hw (hisi_hba );
46904735 hisi_hba -> debugfs_dump_index ++ ;
46914736
@@ -4769,6 +4814,17 @@ static void debugfs_bist_init_v3_hw(struct hisi_hba *hisi_hba)
47694814 hisi_hba -> debugfs_bist_linkrate = SAS_LINK_RATE_1_5_GBPS ;
47704815}
47714816
4817+ static void debugfs_dump_init_v3_hw (struct hisi_hba * hisi_hba )
4818+ {
4819+ int i ;
4820+
4821+ hisi_hba -> debugfs_dump_dentry =
4822+ debugfs_create_dir ("dump" , hisi_hba -> debugfs_dir );
4823+
4824+ for (i = 0 ; i < hisi_sas_debugfs_dump_count ; i ++ )
4825+ debugfs_create_files_v3_hw (hisi_hba , i );
4826+ }
4827+
47724828static void debugfs_exit_v3_hw (struct hisi_hba * hisi_hba )
47734829{
47744830 debugfs_remove_recursive (hisi_hba -> debugfs_dir );
@@ -4784,8 +4840,7 @@ static void debugfs_init_v3_hw(struct hisi_hba *hisi_hba)
47844840 /* create bist structures */
47854841 debugfs_bist_init_v3_hw (hisi_hba );
47864842
4787- hisi_hba -> debugfs_dump_dentry =
4788- debugfs_create_dir ("dump" , hisi_hba -> debugfs_dir );
4843+ debugfs_dump_init_v3_hw (hisi_hba );
47894844
47904845 debugfs_phy_down_cnt_init_v3_hw (hisi_hba );
47914846 debugfs_fifo_init_v3_hw (hisi_hba );
0 commit comments