diff mbox series

[4/5] cpufreq: tegra186/tegra194: Handle errors in BPMP response

Message ID 20210915085517.1669675-4-mperttunen@nvidia.com (mailing list archive)
State Not Applicable
Delegated to: Lorenzo Pieralisi
Headers show
Series [1/5] thermal: tegra-bpmp: Handle errors in BPMP response | expand

Commit Message

Mikko Perttunen Sept. 15, 2021, 8:55 a.m. UTC
The return value from tegra_bpmp_transfer indicates the success or
failure of the IPC transaction with BPMP. If the transaction
succeeded, we also need to check the actual command's result code.
Add code to do this.

While at it, explicitly handle missing CPU clusters, which can
occur on floorswept chips. This worked before as well, but
possibly only by accident.

Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
---
 drivers/cpufreq/tegra186-cpufreq.c | 4 ++++
 drivers/cpufreq/tegra194-cpufreq.c | 8 +++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

Comments

Viresh Kumar Oct. 4, 2021, 6:37 a.m. UTC | #1
On 15-09-21, 11:55, Mikko Perttunen wrote:
> The return value from tegra_bpmp_transfer indicates the success or
> failure of the IPC transaction with BPMP. If the transaction
> succeeded, we also need to check the actual command's result code.
> Add code to do this.
> 
> While at it, explicitly handle missing CPU clusters, which can
> occur on floorswept chips. This worked before as well, but
> possibly only by accident.
> 
> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
> ---
>  drivers/cpufreq/tegra186-cpufreq.c | 4 ++++
>  drivers/cpufreq/tegra194-cpufreq.c | 8 +++++++-
>  2 files changed, 11 insertions(+), 1 deletion(-)

Should I apply it alone ?
Mikko Perttunen Oct. 4, 2021, 6:51 a.m. UTC | #2
On 10/4/21 9:37 AM, Viresh Kumar wrote:
> On 15-09-21, 11:55, Mikko Perttunen wrote:
>> The return value from tegra_bpmp_transfer indicates the success or
>> failure of the IPC transaction with BPMP. If the transaction
>> succeeded, we also need to check the actual command's result code.
>> Add code to do this.
>>
>> While at it, explicitly handle missing CPU clusters, which can
>> occur on floorswept chips. This worked before as well, but
>> possibly only by accident.
>>
>> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
>> ---
>>   drivers/cpufreq/tegra186-cpufreq.c | 4 ++++
>>   drivers/cpufreq/tegra194-cpufreq.c | 8 +++++++-
>>   2 files changed, 11 insertions(+), 1 deletion(-)
> 
> Should I apply it alone ?
> 

Yes please, all of these patches are independent of each other.

Mikko
Viresh Kumar Oct. 4, 2021, 7:01 a.m. UTC | #3
On 15-09-21, 11:55, Mikko Perttunen wrote:
> The return value from tegra_bpmp_transfer indicates the success or
> failure of the IPC transaction with BPMP. If the transaction
> succeeded, we also need to check the actual command's result code.
> Add code to do this.
> 
> While at it, explicitly handle missing CPU clusters, which can
> occur on floorswept chips. This worked before as well, but
> possibly only by accident.
> 
> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
> ---
>  drivers/cpufreq/tegra186-cpufreq.c | 4 ++++
>  drivers/cpufreq/tegra194-cpufreq.c | 8 +++++++-
>  2 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/tegra186-cpufreq.c b/drivers/cpufreq/tegra186-cpufreq.c
> index 5d1943e787b0..6c88827f4e62 100644
> --- a/drivers/cpufreq/tegra186-cpufreq.c
> +++ b/drivers/cpufreq/tegra186-cpufreq.c
> @@ -159,6 +159,10 @@ static struct cpufreq_frequency_table *init_vhint_table(
>  		table = ERR_PTR(err);
>  		goto free;
>  	}
> +	if (msg.rx.ret) {
> +		table = ERR_PTR(-EINVAL);
> +		goto free;
> +	}
>  
>  	for (i = data->vfloor; i <= data->vceil; i++) {
>  		u16 ndiv = data->ndiv[i];
> diff --git a/drivers/cpufreq/tegra194-cpufreq.c b/drivers/cpufreq/tegra194-cpufreq.c
> index a9620e4489ae..ac381db25dbe 100644
> --- a/drivers/cpufreq/tegra194-cpufreq.c
> +++ b/drivers/cpufreq/tegra194-cpufreq.c
> @@ -242,7 +242,7 @@ static int tegra194_cpufreq_init(struct cpufreq_policy *policy)
>  
>  	smp_call_function_single(policy->cpu, get_cpu_cluster, &cl, true);
>  
> -	if (cl >= data->num_clusters)
> +	if (cl >= data->num_clusters || !data->tables[cl])
>  		return -EINVAL;
>  
>  	/* set same policy for all cpus in a cluster */
> @@ -310,6 +310,12 @@ init_freq_table(struct platform_device *pdev, struct tegra_bpmp *bpmp,
>  	err = tegra_bpmp_transfer(bpmp, &msg);
>  	if (err)
>  		return ERR_PTR(err);
> +	if (msg.rx.ret == -BPMP_EINVAL) {
> +		/* Cluster not available */
> +		return NULL;
> +	}
> +	if (msg.rx.ret)
> +		return ERR_PTR(-EINVAL);
>  
>  	/*
>  	 * Make sure frequency table step is a multiple of mdiv to match

Applied. Thanks.
Mikko Perttunen Oct. 4, 2021, 7:02 a.m. UTC | #4
On 10/4/21 10:01 AM, Viresh Kumar wrote:
> On 15-09-21, 11:55, Mikko Perttunen wrote:
>> The return value from tegra_bpmp_transfer indicates the success or
>> failure of the IPC transaction with BPMP. If the transaction
>> succeeded, we also need to check the actual command's result code.
>> Add code to do this.
>>
>> While at it, explicitly handle missing CPU clusters, which can
>> occur on floorswept chips. This worked before as well, but
>> possibly only by accident.
>>
>> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
>> ---
>>   drivers/cpufreq/tegra186-cpufreq.c | 4 ++++
>>   drivers/cpufreq/tegra194-cpufreq.c | 8 +++++++-
>>   2 files changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/tegra186-cpufreq.c b/drivers/cpufreq/tegra186-cpufreq.c
>> index 5d1943e787b0..6c88827f4e62 100644
>> --- a/drivers/cpufreq/tegra186-cpufreq.c
>> +++ b/drivers/cpufreq/tegra186-cpufreq.c
>> @@ -159,6 +159,10 @@ static struct cpufreq_frequency_table *init_vhint_table(
>>   		table = ERR_PTR(err);
>>   		goto free;
>>   	}
>> +	if (msg.rx.ret) {
>> +		table = ERR_PTR(-EINVAL);
>> +		goto free;
>> +	}
>>   
>>   	for (i = data->vfloor; i <= data->vceil; i++) {
>>   		u16 ndiv = data->ndiv[i];
>> diff --git a/drivers/cpufreq/tegra194-cpufreq.c b/drivers/cpufreq/tegra194-cpufreq.c
>> index a9620e4489ae..ac381db25dbe 100644
>> --- a/drivers/cpufreq/tegra194-cpufreq.c
>> +++ b/drivers/cpufreq/tegra194-cpufreq.c
>> @@ -242,7 +242,7 @@ static int tegra194_cpufreq_init(struct cpufreq_policy *policy)
>>   
>>   	smp_call_function_single(policy->cpu, get_cpu_cluster, &cl, true);
>>   
>> -	if (cl >= data->num_clusters)
>> +	if (cl >= data->num_clusters || !data->tables[cl])
>>   		return -EINVAL;
>>   
>>   	/* set same policy for all cpus in a cluster */
>> @@ -310,6 +310,12 @@ init_freq_table(struct platform_device *pdev, struct tegra_bpmp *bpmp,
>>   	err = tegra_bpmp_transfer(bpmp, &msg);
>>   	if (err)
>>   		return ERR_PTR(err);
>> +	if (msg.rx.ret == -BPMP_EINVAL) {
>> +		/* Cluster not available */
>> +		return NULL;
>> +	}
>> +	if (msg.rx.ret)
>> +		return ERR_PTR(-EINVAL);
>>   
>>   	/*
>>   	 * Make sure frequency table step is a multiple of mdiv to match
> 
> Applied. Thanks.
> 

Thanks!

Mikko
diff mbox series

Patch

diff --git a/drivers/cpufreq/tegra186-cpufreq.c b/drivers/cpufreq/tegra186-cpufreq.c
index 5d1943e787b0..6c88827f4e62 100644
--- a/drivers/cpufreq/tegra186-cpufreq.c
+++ b/drivers/cpufreq/tegra186-cpufreq.c
@@ -159,6 +159,10 @@  static struct cpufreq_frequency_table *init_vhint_table(
 		table = ERR_PTR(err);
 		goto free;
 	}
+	if (msg.rx.ret) {
+		table = ERR_PTR(-EINVAL);
+		goto free;
+	}
 
 	for (i = data->vfloor; i <= data->vceil; i++) {
 		u16 ndiv = data->ndiv[i];
diff --git a/drivers/cpufreq/tegra194-cpufreq.c b/drivers/cpufreq/tegra194-cpufreq.c
index a9620e4489ae..ac381db25dbe 100644
--- a/drivers/cpufreq/tegra194-cpufreq.c
+++ b/drivers/cpufreq/tegra194-cpufreq.c
@@ -242,7 +242,7 @@  static int tegra194_cpufreq_init(struct cpufreq_policy *policy)
 
 	smp_call_function_single(policy->cpu, get_cpu_cluster, &cl, true);
 
-	if (cl >= data->num_clusters)
+	if (cl >= data->num_clusters || !data->tables[cl])
 		return -EINVAL;
 
 	/* set same policy for all cpus in a cluster */
@@ -310,6 +310,12 @@  init_freq_table(struct platform_device *pdev, struct tegra_bpmp *bpmp,
 	err = tegra_bpmp_transfer(bpmp, &msg);
 	if (err)
 		return ERR_PTR(err);
+	if (msg.rx.ret == -BPMP_EINVAL) {
+		/* Cluster not available */
+		return NULL;
+	}
+	if (msg.rx.ret)
+		return ERR_PTR(-EINVAL);
 
 	/*
 	 * Make sure frequency table step is a multiple of mdiv to match