@@ -3560,6 +3560,11 @@ debugfs_to_reg_name_v3_hw(int off, int base_off,
35603560 return NULL ;
35613561}
35623562
3563+ static bool debugfs_dump_is_generated_v3_hw (void * p )
3564+ {
3565+ return p ? true : false;
3566+ }
3567+
35633568static void debugfs_print_reg_v3_hw (u32 * regs_val , struct seq_file * s ,
35643569 const struct hisi_sas_debugfs_reg * reg )
35653570{
@@ -3585,6 +3590,9 @@ static int debugfs_global_v3_hw_show(struct seq_file *s, void *p)
35853590{
35863591 struct hisi_sas_debugfs_regs * global = s -> private ;
35873592
3593+ if (!debugfs_dump_is_generated_v3_hw (global -> data ))
3594+ return - EPERM ;
3595+
35883596 debugfs_print_reg_v3_hw (global -> data , s ,
35893597 & debugfs_global_reg );
35903598
@@ -3596,6 +3604,9 @@ static int debugfs_axi_v3_hw_show(struct seq_file *s, void *p)
35963604{
35973605 struct hisi_sas_debugfs_regs * axi = s -> private ;
35983606
3607+ if (!debugfs_dump_is_generated_v3_hw (axi -> data ))
3608+ return - EPERM ;
3609+
35993610 debugfs_print_reg_v3_hw (axi -> data , s ,
36003611 & debugfs_axi_reg );
36013612
@@ -3607,6 +3618,9 @@ static int debugfs_ras_v3_hw_show(struct seq_file *s, void *p)
36073618{
36083619 struct hisi_sas_debugfs_regs * ras = s -> private ;
36093620
3621+ if (!debugfs_dump_is_generated_v3_hw (ras -> data ))
3622+ return - EPERM ;
3623+
36103624 debugfs_print_reg_v3_hw (ras -> data , s ,
36113625 & debugfs_ras_reg );
36123626
@@ -3619,6 +3633,9 @@ static int debugfs_port_v3_hw_show(struct seq_file *s, void *p)
36193633 struct hisi_sas_debugfs_port * port = s -> private ;
36203634 const struct hisi_sas_debugfs_reg * reg_port = & debugfs_port_reg ;
36213635
3636+ if (!debugfs_dump_is_generated_v3_hw (port -> data ))
3637+ return - EPERM ;
3638+
36223639 debugfs_print_reg_v3_hw (port -> data , s , reg_port );
36233640
36243641 return 0 ;
@@ -3674,6 +3691,9 @@ static int debugfs_cq_v3_hw_show(struct seq_file *s, void *p)
36743691 struct hisi_sas_debugfs_cq * debugfs_cq = s -> private ;
36753692 int slot ;
36763693
3694+ if (!debugfs_dump_is_generated_v3_hw (debugfs_cq -> complete_hdr ))
3695+ return - EPERM ;
3696+
36773697 for (slot = 0 ; slot < HISI_SAS_QUEUE_SLOTS ; slot ++ )
36783698 debugfs_cq_show_slot_v3_hw (s , slot , debugfs_cq );
36793699
@@ -3695,8 +3715,12 @@ static void debugfs_dq_show_slot_v3_hw(struct seq_file *s, int slot,
36953715
36963716static int debugfs_dq_v3_hw_show (struct seq_file * s , void * p )
36973717{
3718+ struct hisi_sas_debugfs_dq * debugfs_dq = s -> private ;
36983719 int slot ;
36993720
3721+ if (!debugfs_dump_is_generated_v3_hw (debugfs_dq -> hdr ))
3722+ return - EPERM ;
3723+
37003724 for (slot = 0 ; slot < HISI_SAS_QUEUE_SLOTS ; slot ++ )
37013725 debugfs_dq_show_slot_v3_hw (s , slot , s -> private );
37023726
@@ -3710,6 +3734,9 @@ static int debugfs_iost_v3_hw_show(struct seq_file *s, void *p)
37103734 struct hisi_sas_iost * iost = debugfs_iost -> iost ;
37113735 int i , max_command_entries = HISI_SAS_MAX_COMMANDS ;
37123736
3737+ if (!debugfs_dump_is_generated_v3_hw (iost ))
3738+ return - EPERM ;
3739+
37133740 for (i = 0 ; i < max_command_entries ; i ++ , iost ++ ) {
37143741 __le64 * data = & iost -> qw0 ;
37153742
@@ -3729,6 +3756,9 @@ static int debugfs_iost_cache_v3_hw_show(struct seq_file *s, void *p)
37293756 int i , tab_idx ;
37303757 __le64 * iost ;
37313758
3759+ if (!debugfs_dump_is_generated_v3_hw (iost_cache ))
3760+ return - EPERM ;
3761+
37323762 for (i = 0 ; i < HISI_SAS_IOST_ITCT_CACHE_NUM ; i ++ , iost_cache ++ ) {
37333763 /*
37343764 * Data struct of IOST cache:
@@ -3752,6 +3782,9 @@ static int debugfs_itct_v3_hw_show(struct seq_file *s, void *p)
37523782 struct hisi_sas_debugfs_itct * debugfs_itct = s -> private ;
37533783 struct hisi_sas_itct * itct = debugfs_itct -> itct ;
37543784
3785+ if (!debugfs_dump_is_generated_v3_hw (itct ))
3786+ return - EPERM ;
3787+
37553788 for (i = 0 ; i < HISI_SAS_MAX_ITCT_ENTRIES ; i ++ , itct ++ ) {
37563789 __le64 * data = & itct -> qw0 ;
37573790
@@ -3771,6 +3804,9 @@ static int debugfs_itct_cache_v3_hw_show(struct seq_file *s, void *p)
37713804 int i , tab_idx ;
37723805 __le64 * itct ;
37733806
3807+ if (!debugfs_dump_is_generated_v3_hw (itct_cache ))
3808+ return - EPERM ;
3809+
37743810 for (i = 0 ; i < HISI_SAS_IOST_ITCT_CACHE_NUM ; i ++ , itct_cache ++ ) {
37753811 /*
37763812 * Data struct of ITCT cache:
@@ -3788,28 +3824,27 @@ static int debugfs_itct_cache_v3_hw_show(struct seq_file *s, void *p)
37883824}
37893825DEFINE_SHOW_ATTRIBUTE (debugfs_itct_cache_v3_hw );
37903826
3791- static void debugfs_create_files_v3_hw (struct hisi_hba * hisi_hba )
3827+ static void debugfs_create_files_v3_hw (struct hisi_hba * hisi_hba , int index )
37923828{
37933829 u64 * debugfs_timestamp ;
3794- int dump_index = hisi_hba -> debugfs_dump_index ;
37953830 struct dentry * dump_dentry ;
37963831 struct dentry * dentry ;
37973832 char name [256 ];
37983833 int p ;
37993834 int c ;
38003835 int d ;
38013836
3802- snprintf (name , 256 , "%d" , dump_index );
3837+ snprintf (name , 256 , "%d" , index );
38033838
38043839 dump_dentry = debugfs_create_dir (name , hisi_hba -> debugfs_dump_dentry );
38053840
3806- debugfs_timestamp = & hisi_hba -> debugfs_timestamp [dump_index ];
3841+ debugfs_timestamp = & hisi_hba -> debugfs_timestamp [index ];
38073842
38083843 debugfs_create_u64 ("timestamp" , 0400 , dump_dentry ,
38093844 debugfs_timestamp );
38103845
38113846 debugfs_create_file ("global" , 0400 , dump_dentry ,
3812- & hisi_hba -> debugfs_regs [dump_index ][DEBUGFS_GLOBAL ],
3847+ & hisi_hba -> debugfs_regs [index ][DEBUGFS_GLOBAL ],
38133848 & debugfs_global_v3_hw_fops );
38143849
38153850 /* Create port dir and files */
@@ -3818,7 +3853,7 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38183853 snprintf (name , 256 , "%d" , p );
38193854
38203855 debugfs_create_file (name , 0400 , dentry ,
3821- & hisi_hba -> debugfs_port_reg [dump_index ][p ],
3856+ & hisi_hba -> debugfs_port_reg [index ][p ],
38223857 & debugfs_port_v3_hw_fops );
38233858 }
38243859
@@ -3828,7 +3863,7 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38283863 snprintf (name , 256 , "%d" , c );
38293864
38303865 debugfs_create_file (name , 0400 , dentry ,
3831- & hisi_hba -> debugfs_cq [dump_index ][c ],
3866+ & hisi_hba -> debugfs_cq [index ][c ],
38323867 & debugfs_cq_v3_hw_fops );
38333868 }
38343869
@@ -3838,32 +3873,32 @@ static void debugfs_create_files_v3_hw(struct hisi_hba *hisi_hba)
38383873 snprintf (name , 256 , "%d" , d );
38393874
38403875 debugfs_create_file (name , 0400 , dentry ,
3841- & hisi_hba -> debugfs_dq [dump_index ][d ],
3876+ & hisi_hba -> debugfs_dq [index ][d ],
38423877 & debugfs_dq_v3_hw_fops );
38433878 }
38443879
38453880 debugfs_create_file ("iost" , 0400 , dump_dentry ,
3846- & hisi_hba -> debugfs_iost [dump_index ],
3881+ & hisi_hba -> debugfs_iost [index ],
38473882 & debugfs_iost_v3_hw_fops );
38483883
38493884 debugfs_create_file ("iost_cache" , 0400 , dump_dentry ,
3850- & hisi_hba -> debugfs_iost_cache [dump_index ],
3885+ & hisi_hba -> debugfs_iost_cache [index ],
38513886 & debugfs_iost_cache_v3_hw_fops );
38523887
38533888 debugfs_create_file ("itct" , 0400 , dump_dentry ,
3854- & hisi_hba -> debugfs_itct [dump_index ],
3889+ & hisi_hba -> debugfs_itct [index ],
38553890 & debugfs_itct_v3_hw_fops );
38563891
38573892 debugfs_create_file ("itct_cache" , 0400 , dump_dentry ,
3858- & hisi_hba -> debugfs_itct_cache [dump_index ],
3893+ & hisi_hba -> debugfs_itct_cache [index ],
38593894 & debugfs_itct_cache_v3_hw_fops );
38603895
38613896 debugfs_create_file ("axi" , 0400 , dump_dentry ,
3862- & hisi_hba -> debugfs_regs [dump_index ][DEBUGFS_AXI ],
3897+ & hisi_hba -> debugfs_regs [index ][DEBUGFS_AXI ],
38633898 & debugfs_axi_v3_hw_fops );
38643899
38653900 debugfs_create_file ("ras" , 0400 , dump_dentry ,
3866- & hisi_hba -> debugfs_regs [dump_index ][DEBUGFS_RAS ],
3901+ & hisi_hba -> debugfs_regs [index ][DEBUGFS_RAS ],
38673902 & debugfs_ras_v3_hw_fops );
38683903}
38693904
@@ -4645,22 +4680,34 @@ static void debugfs_release_v3_hw(struct hisi_hba *hisi_hba, int dump_index)
46454680 int i ;
46464681
46474682 devm_kfree (dev , hisi_hba -> debugfs_iost_cache [dump_index ].cache );
4683+ hisi_hba -> debugfs_iost_cache [dump_index ].cache = NULL ;
46484684 devm_kfree (dev , hisi_hba -> debugfs_itct_cache [dump_index ].cache );
4685+ hisi_hba -> debugfs_itct_cache [dump_index ].cache = NULL ;
46494686 devm_kfree (dev , hisi_hba -> debugfs_iost [dump_index ].iost );
4687+ hisi_hba -> debugfs_iost [dump_index ].iost = NULL ;
46504688 devm_kfree (dev , hisi_hba -> debugfs_itct [dump_index ].itct );
4689+ hisi_hba -> debugfs_itct [dump_index ].itct = NULL ;
46514690
4652- for (i = 0 ; i < hisi_hba -> queue_count ; i ++ )
4691+ for (i = 0 ; i < hisi_hba -> queue_count ; i ++ ) {
46534692 devm_kfree (dev , hisi_hba -> debugfs_dq [dump_index ][i ].hdr );
4693+ hisi_hba -> debugfs_dq [dump_index ][i ].hdr = NULL ;
4694+ }
46544695
4655- for (i = 0 ; i < hisi_hba -> queue_count ; i ++ )
4696+ for (i = 0 ; i < hisi_hba -> queue_count ; i ++ ) {
46564697 devm_kfree (dev ,
46574698 hisi_hba -> debugfs_cq [dump_index ][i ].complete_hdr );
4699+ hisi_hba -> debugfs_cq [dump_index ][i ].complete_hdr = NULL ;
4700+ }
46584701
4659- for (i = 0 ; i < DEBUGFS_REGS_NUM ; i ++ )
4702+ for (i = 0 ; i < DEBUGFS_REGS_NUM ; i ++ ) {
46604703 devm_kfree (dev , hisi_hba -> debugfs_regs [dump_index ][i ].data );
4704+ hisi_hba -> debugfs_regs [dump_index ][i ].data = NULL ;
4705+ }
46614706
4662- for (i = 0 ; i < hisi_hba -> n_phy ; i ++ )
4707+ for (i = 0 ; i < hisi_hba -> n_phy ; i ++ ) {
46634708 devm_kfree (dev , hisi_hba -> debugfs_port_reg [dump_index ][i ].data );
4709+ hisi_hba -> debugfs_port_reg [dump_index ][i ].data = NULL ;
4710+ }
46644711}
46654712
46664713static const struct hisi_sas_debugfs_reg * debugfs_reg_array_v3_hw [DEBUGFS_REGS_NUM ] = {
@@ -4787,8 +4834,6 @@ static int debugfs_snapshot_regs_v3_hw(struct hisi_hba *hisi_hba)
47874834 debugfs_snapshot_itct_reg_v3_hw (hisi_hba );
47884835 debugfs_snapshot_iost_reg_v3_hw (hisi_hba );
47894836
4790- debugfs_create_files_v3_hw (hisi_hba );
4791-
47924837 debugfs_snapshot_restore_v3_hw (hisi_hba );
47934838 hisi_hba -> debugfs_dump_index ++ ;
47944839
@@ -4872,6 +4917,17 @@ static void debugfs_bist_init_v3_hw(struct hisi_hba *hisi_hba)
48724917 hisi_hba -> debugfs_bist_linkrate = SAS_LINK_RATE_1_5_GBPS ;
48734918}
48744919
4920+ static void debugfs_dump_init_v3_hw (struct hisi_hba * hisi_hba )
4921+ {
4922+ int i ;
4923+
4924+ hisi_hba -> debugfs_dump_dentry =
4925+ debugfs_create_dir ("dump" , hisi_hba -> debugfs_dir );
4926+
4927+ for (i = 0 ; i < hisi_sas_debugfs_dump_count ; i ++ )
4928+ debugfs_create_files_v3_hw (hisi_hba , i );
4929+ }
4930+
48754931static void debugfs_exit_v3_hw (struct hisi_hba * hisi_hba )
48764932{
48774933 debugfs_remove_recursive (hisi_hba -> debugfs_dir );
@@ -4892,8 +4948,7 @@ static void debugfs_init_v3_hw(struct hisi_hba *hisi_hba)
48924948 /* create bist structures */
48934949 debugfs_bist_init_v3_hw (hisi_hba );
48944950
4895- hisi_hba -> debugfs_dump_dentry =
4896- debugfs_create_dir ("dump" , hisi_hba -> debugfs_dir );
4951+ debugfs_dump_init_v3_hw (hisi_hba );
48974952
48984953 debugfs_phy_down_cnt_init_v3_hw (hisi_hba );
48994954 debugfs_fifo_init_v3_hw (hisi_hba );
0 commit comments