[v3] app/testpmd: increase array for fetching supported FEC caps

Message ID 1608808729-3768-1-git-send-email-rahul.lakkireddy@chelsio.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v3] app/testpmd: increase array for fetching supported FEC caps |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS

Commit Message

Rahul Lakkireddy Dec. 24, 2020, 11:18 a.m. UTC
  From: Karra Satwik <kaara.satwik@chelsio.com>

Request the driver for number of entries in the FEC caps
array and then dynamically allocate the array.

Signed-off-by: Karra Satwik <kaara.satwik@chelsio.com>
Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
Acked-by: Xiaoyun Li <xiaoyun.li@intel.com>
---
v3:
- Use unsigned int num, instead of int num

v2:
- Replace if (!speed_fec_capa) with if (speed_fec_capa == NULL)

 app/test-pmd/cmdline.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
  

Comments

humin (Q) Dec. 25, 2020, 1:06 a.m. UTC | #1
Acked-by: Min Hu (Connor) <humin29@huawei.com>

在 2020/12/24 19:18, Rahul Lakkireddy 写道:
> From: Karra Satwik <kaara.satwik@chelsio.com>
> 
> Request the driver for number of entries in the FEC caps
> array and then dynamically allocate the array.
> 
> Signed-off-by: Karra Satwik <kaara.satwik@chelsio.com>
> Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
> Acked-by: Xiaoyun Li <xiaoyun.li@intel.com>
> ---
> v3:
> - Use unsigned int num, instead of int num
> 
> v2:
> - Replace if (!speed_fec_capa) with if (speed_fec_capa == NULL)
> 
>   app/test-pmd/cmdline.c | 28 ++++++++++++++++++++--------
>   1 file changed, 20 insertions(+), 8 deletions(-)
> 
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> index 2ccbaa039..1dfad5df4 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -16263,11 +16263,9 @@ cmd_show_fec_capability_parsed(void *parsed_result,
>   		__rte_unused struct cmdline *cl,
>   		__rte_unused void *data)
>   {
> -#define FEC_CAP_NUM 2
>   	struct cmd_show_fec_capability_result *res = parsed_result;
> -	struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
> -	unsigned int num = FEC_CAP_NUM;
> -	unsigned int ret_num;
> +	struct rte_eth_fec_capa *speed_fec_capa;
> +	unsigned int num;
>   	int ret;
>   
>   	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
> @@ -16275,17 +16273,31 @@ cmd_show_fec_capability_parsed(void *parsed_result,
>   		return;
>   	}
>   
> -	ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
> +	ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
>   	if (ret == -ENOTSUP) {
>   		printf("Function not implemented\n");
>   		return;
>   	} else if (ret < 0) {
> -		printf("Get FEC capability failed\n");
> +		printf("Get FEC capability failed: %d\n", ret);
> +		return;
> +	}
> +
> +	num = (unsigned int)ret;
> +	speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
> +	if (speed_fec_capa == NULL) {
> +		printf("Failed to alloc FEC capability buffer\n");
>   		return;
>   	}
>   
> -	ret_num = (unsigned int)ret;
> -	show_fec_capability(ret_num, speed_fec_capa);
> +	ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
> +	if (ret < 0) {
> +		printf("Error getting FEC capability: %d\n", ret);
> +		goto out;
> +	}
> +
> +	show_fec_capability(num, speed_fec_capa);
> +out:
> +	free(speed_fec_capa);
>   }
>   
>   cmdline_parse_token_string_t cmd_show_fec_capability_show =
>
  
Ferruh Yigit Jan. 15, 2021, 3:27 p.m. UTC | #2
On 12/25/2020 1:06 AM, Min Hu (Connor) wrote:

> 在 2020/12/24 19:18, Rahul Lakkireddy 写道:
>> From: Karra Satwik <kaara.satwik@chelsio.com>
>>
>> Request the driver for number of entries in the FEC caps
>> array and then dynamically allocate the array.
>>
>> Signed-off-by: Karra Satwik <kaara.satwik@chelsio.com>
>> Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
>> Acked-by: Xiaoyun Li <xiaoyun.li@intel.com>
 > Acked-by: Min Hu (Connor) <humin29@huawei.com>
 >

Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 2ccbaa039..1dfad5df4 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -16263,11 +16263,9 @@  cmd_show_fec_capability_parsed(void *parsed_result,
 		__rte_unused struct cmdline *cl,
 		__rte_unused void *data)
 {
-#define FEC_CAP_NUM 2
 	struct cmd_show_fec_capability_result *res = parsed_result;
-	struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
-	unsigned int num = FEC_CAP_NUM;
-	unsigned int ret_num;
+	struct rte_eth_fec_capa *speed_fec_capa;
+	unsigned int num;
 	int ret;
 
 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
@@ -16275,17 +16273,31 @@  cmd_show_fec_capability_parsed(void *parsed_result,
 		return;
 	}
 
-	ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
+	ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
 	if (ret == -ENOTSUP) {
 		printf("Function not implemented\n");
 		return;
 	} else if (ret < 0) {
-		printf("Get FEC capability failed\n");
+		printf("Get FEC capability failed: %d\n", ret);
+		return;
+	}
+
+	num = (unsigned int)ret;
+	speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
+	if (speed_fec_capa == NULL) {
+		printf("Failed to alloc FEC capability buffer\n");
 		return;
 	}
 
-	ret_num = (unsigned int)ret;
-	show_fec_capability(ret_num, speed_fec_capa);
+	ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
+	if (ret < 0) {
+		printf("Error getting FEC capability: %d\n", ret);
+		goto out;
+	}
+
+	show_fec_capability(num, speed_fec_capa);
+out:
+	free(speed_fec_capa);
 }
 
 cmdline_parse_token_string_t cmd_show_fec_capability_show =