@@ -2494,16 +2494,16 @@ static int ars_get_status(struct acpi_nfit_desc *acpi_desc)
2494
2494
int rc , cmd_rc ;
2495
2495
2496
2496
rc = nd_desc -> ndctl (nd_desc , NULL , ND_CMD_ARS_STATUS , ars_status ,
2497
- acpi_desc -> ars_status_size , & cmd_rc );
2497
+ acpi_desc -> max_ars , & cmd_rc );
2498
2498
if (rc < 0 )
2499
2499
return rc ;
2500
2500
return cmd_rc ;
2501
2501
}
2502
2502
2503
- static int ars_status_process_records (struct acpi_nfit_desc * acpi_desc ,
2504
- struct nd_cmd_ars_status * ars_status )
2503
+ static int ars_status_process_records (struct acpi_nfit_desc * acpi_desc )
2505
2504
{
2506
2505
struct nvdimm_bus * nvdimm_bus = acpi_desc -> nvdimm_bus ;
2506
+ struct nd_cmd_ars_status * ars_status = acpi_desc -> ars_status ;
2507
2507
int rc ;
2508
2508
u32 i ;
2509
2509
@@ -2739,60 +2739,35 @@ static int acpi_nfit_register_region(struct acpi_nfit_desc *acpi_desc,
2739
2739
return rc ;
2740
2740
}
2741
2741
2742
- static int ars_status_alloc (struct acpi_nfit_desc * acpi_desc ,
2743
- u32 max_ars )
2742
+ static int ars_status_alloc (struct acpi_nfit_desc * acpi_desc )
2744
2743
{
2745
2744
struct device * dev = acpi_desc -> dev ;
2746
2745
struct nd_cmd_ars_status * ars_status ;
2747
2746
2748
- if (acpi_desc -> ars_status && acpi_desc -> ars_status_size >= max_ars ) {
2749
- memset (acpi_desc -> ars_status , 0 , acpi_desc -> ars_status_size );
2747
+ if (acpi_desc -> ars_status ) {
2748
+ memset (acpi_desc -> ars_status , 0 , acpi_desc -> max_ars );
2750
2749
return 0 ;
2751
2750
}
2752
2751
2753
- if (acpi_desc -> ars_status )
2754
- devm_kfree (dev , acpi_desc -> ars_status );
2755
- acpi_desc -> ars_status = NULL ;
2756
- ars_status = devm_kzalloc (dev , max_ars , GFP_KERNEL );
2752
+ ars_status = devm_kzalloc (dev , acpi_desc -> max_ars , GFP_KERNEL );
2757
2753
if (!ars_status )
2758
2754
return - ENOMEM ;
2759
2755
acpi_desc -> ars_status = ars_status ;
2760
- acpi_desc -> ars_status_size = max_ars ;
2761
2756
return 0 ;
2762
2757
}
2763
2758
2764
- static int acpi_nfit_query_poison (struct acpi_nfit_desc * acpi_desc ,
2765
- struct nfit_spa * nfit_spa )
2759
+ static int acpi_nfit_query_poison (struct acpi_nfit_desc * acpi_desc )
2766
2760
{
2767
- struct acpi_nfit_system_address * spa = nfit_spa -> spa ;
2768
2761
int rc ;
2769
2762
2770
- if (!nfit_spa -> max_ars ) {
2771
- struct nd_cmd_ars_cap ars_cap ;
2772
-
2773
- memset (& ars_cap , 0 , sizeof (ars_cap ));
2774
- rc = ars_get_cap (acpi_desc , & ars_cap , nfit_spa );
2775
- if (rc < 0 )
2776
- return rc ;
2777
- nfit_spa -> max_ars = ars_cap .max_ars_out ;
2778
- nfit_spa -> clear_err_unit = ars_cap .clear_err_unit ;
2779
- /* check that the supported scrub types match the spa type */
2780
- if (nfit_spa_type (spa ) == NFIT_SPA_VOLATILE &&
2781
- ((ars_cap .status >> 16 ) & ND_ARS_VOLATILE ) == 0 )
2782
- return - ENOTTY ;
2783
- else if (nfit_spa_type (spa ) == NFIT_SPA_PM &&
2784
- ((ars_cap .status >> 16 ) & ND_ARS_PERSISTENT ) == 0 )
2785
- return - ENOTTY ;
2786
- }
2787
-
2788
- if (ars_status_alloc (acpi_desc , nfit_spa -> max_ars ))
2763
+ if (ars_status_alloc (acpi_desc ))
2789
2764
return - ENOMEM ;
2790
2765
2791
2766
rc = ars_get_status (acpi_desc );
2792
2767
if (rc < 0 && rc != - ENOSPC )
2793
2768
return rc ;
2794
2769
2795
- if (ars_status_process_records (acpi_desc , acpi_desc -> ars_status ))
2770
+ if (ars_status_process_records (acpi_desc ))
2796
2771
return - ENOMEM ;
2797
2772
2798
2773
return 0 ;
@@ -2824,7 +2799,7 @@ static void acpi_nfit_async_scrub(struct acpi_nfit_desc *acpi_desc,
2824
2799
2825
2800
if (acpi_desc -> cancel )
2826
2801
break ;
2827
- rc = acpi_nfit_query_poison (acpi_desc , nfit_spa );
2802
+ rc = acpi_nfit_query_poison (acpi_desc );
2828
2803
if (rc == - ENOTTY )
2829
2804
break ;
2830
2805
if (rc == - EBUSY && !tmo ) {
@@ -2925,7 +2900,7 @@ static void acpi_nfit_scrub(struct work_struct *work)
2925
2900
*/
2926
2901
rc = 0 ;
2927
2902
} else
2928
- rc = acpi_nfit_query_poison (acpi_desc , nfit_spa );
2903
+ rc = acpi_nfit_query_poison (acpi_desc );
2929
2904
2930
2905
if (rc == - ENOTTY ) {
2931
2906
/* no ars capability, just register spa and move on */
@@ -3018,6 +2993,31 @@ static void acpi_nfit_scrub(struct work_struct *work)
3018
2993
mutex_unlock (& acpi_desc -> init_mutex );
3019
2994
}
3020
2995
2996
+ static void acpi_nfit_init_ars (struct acpi_nfit_desc * acpi_desc ,
2997
+ struct nfit_spa * nfit_spa )
2998
+ {
2999
+ int type = nfit_spa_type (nfit_spa -> spa );
3000
+ struct nd_cmd_ars_cap ars_cap ;
3001
+ int rc ;
3002
+
3003
+ memset (& ars_cap , 0 , sizeof (ars_cap ));
3004
+ rc = ars_get_cap (acpi_desc , & ars_cap , nfit_spa );
3005
+ if (rc < 0 )
3006
+ return ;
3007
+ /* check that the supported scrub types match the spa type */
3008
+ if (type == NFIT_SPA_VOLATILE && ((ars_cap .status >> 16 )
3009
+ & ND_ARS_VOLATILE ) == 0 )
3010
+ return ;
3011
+ if (type == NFIT_SPA_PM && ((ars_cap .status >> 16 )
3012
+ & ND_ARS_PERSISTENT ) == 0 )
3013
+ return ;
3014
+
3015
+ nfit_spa -> max_ars = ars_cap .max_ars_out ;
3016
+ nfit_spa -> clear_err_unit = ars_cap .clear_err_unit ;
3017
+ acpi_desc -> max_ars = max (nfit_spa -> max_ars , acpi_desc -> max_ars );
3018
+ }
3019
+
3020
+
3021
3021
static int acpi_nfit_register_regions (struct acpi_nfit_desc * acpi_desc )
3022
3022
{
3023
3023
struct nfit_spa * nfit_spa ;
@@ -3026,8 +3026,10 @@ static int acpi_nfit_register_regions(struct acpi_nfit_desc *acpi_desc)
3026
3026
int rc , type = nfit_spa_type (nfit_spa -> spa );
3027
3027
3028
3028
/* PMEM and VMEM will be registered by the ARS workqueue */
3029
- if (type == NFIT_SPA_PM || type == NFIT_SPA_VOLATILE )
3029
+ if (type == NFIT_SPA_PM || type == NFIT_SPA_VOLATILE ) {
3030
+ acpi_nfit_init_ars (acpi_desc , nfit_spa );
3030
3031
continue ;
3032
+ }
3031
3033
/* BLK apertures belong to BLK region registration below */
3032
3034
if (type == NFIT_SPA_BDW )
3033
3035
continue ;
0 commit comments