net/mlx: replace hardcoded value with macro

Message ID 20200209211725.197237-1-thomas@monjalon.net (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx: replace hardcoded value with macro |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/Intel-compilation fail apply issues

Commit Message

Thomas Monjalon Feb. 9, 2020, 9:17 p.m. UTC
  Replace checking against 65535 limit,
with a simpler form using RTE_MIN and UINT16_MAX macros.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 drivers/net/mlx4/mlx4_ethdev.c | 5 ++---
 drivers/net/mlx5/mlx5_ethdev.c | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)
  

Comments

Matan Azrad Feb. 10, 2020, 6:32 a.m. UTC | #1
Hi Thomas

From: Thomas Monjalon
> Sent: Sunday, February 9, 2020 11:17 PM
> To: Matan Azrad <matan@mellanox.com>; Shahaf Shuler
> <shahafs@mellanox.com>; Slava Ovsiienko <viacheslavo@mellanox.com>
> Cc: dev@dpdk.org
> Subject: [PATCH] net/mlx: replace hardcoded value with macro
> 
> Replace checking against 65535 limit,
> with a simpler form using RTE_MIN and UINT16_MAX macros.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
>  drivers/net/mlx4/mlx4_ethdev.c | 5 ++---  drivers/net/mlx5/mlx5_ethdev.c
> | 5 ++---
>  2 files changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/mlx4/mlx4_ethdev.c
> b/drivers/net/mlx4/mlx4_ethdev.c index e500ec422c..9ff05c6738 100644
> --- a/drivers/net/mlx4/mlx4_ethdev.c
> +++ b/drivers/net/mlx4/mlx4_ethdev.c
> @@ -645,9 +645,8 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct
> rte_eth_dev_info *info)
>  	 */
>  	max = ((priv->device_attr.max_cq > priv->device_attr.max_qp) ?
>  	       priv->device_attr.max_qp : priv->device_attr.max_cq);
> -	/* If max >= 65535 then max = 0, max_rx_queues is uint16_t. */
> -	if (max >= 65535)
> -		max = 65535;
> +	/* max_rx_queues is uint16_t. */
> +	max = RTE_MIN(max, (unsigned int)UINT16_MAX);
>  	info->max_rx_queues = max;
>  	info->max_tx_queues = max;
>  	info->max_mac_addrs = RTE_DIM(priv->mac); diff --git
> a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c index
> 86923aa7af..d7d3bc73ce 100644
> --- a/drivers/net/mlx5/mlx5_ethdev.c
> +++ b/drivers/net/mlx5/mlx5_ethdev.c
> @@ -619,9 +619,8 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct
> rte_eth_dev_info *info)
>  	 */
>  	max = RTE_MIN(priv->sh->device_attr.orig_attr.max_cq,
>  		      priv->sh->device_attr.orig_attr.max_qp);
> -	/* If max >= 65535 then max = 0, max_rx_queues is uint16_t. */
> -	if (max >= 65535)
> -		max = 65535;
> +	/* max_rx_queues is uint16_t. */
> +	max = RTE_MIN(max, (unsigned int)UINT16_MAX);
>  	info->max_rx_queues = max;
>  	info->max_tx_queues = max;
>  	info->max_mac_addrs = MLX5_MAX_UC_MAC_ADDRESSES;

No more misusing of *_MAX \ RTE_MIN\RTE_MAX in the mlx PMDs?
  
Thomas Monjalon Feb. 10, 2020, 8:52 a.m. UTC | #2
10/02/2020 07:32, Matan Azrad:
> From: Thomas Monjalon
> 
> > Replace checking against 65535 limit,
> > with a simpler form using RTE_MIN and UINT16_MAX macros.
> > 
> > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > ---
> 
> No more misusing of *_MAX \ RTE_MIN\RTE_MAX in the mlx PMDs?

Sorry I don't understand your question.
  
Thomas Monjalon Feb. 10, 2020, 9:52 a.m. UTC | #3
10/02/2020 09:52, Thomas Monjalon:
> 10/02/2020 07:32, Matan Azrad:
> > From: Thomas Monjalon
> > 
> > > Replace checking against 65535 limit,
> > > with a simpler form using RTE_MIN and UINT16_MAX macros.
> > > 
> > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > > ---
> > 
> > No more misusing of *_MAX \ RTE_MIN\RTE_MAX in the mlx PMDs?
> 
> Sorry I don't understand your question.

If you are asking if there are more hardcoded constants,
the answer is yes but they are masks.
I think the masks can remain hardcoded.
  
Matan Azrad Feb. 10, 2020, 9:57 a.m. UTC | #4
From: Thomas Monjalon
> 10/02/2020 09:52, Thomas Monjalon:
> > 10/02/2020 07:32, Matan Azrad:
> > > From: Thomas Monjalon
> > >
> > > > Replace checking against 65535 limit, with a simpler form using
> > > > RTE_MIN and UINT16_MAX macros.
> > > >
> > > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > > > ---
> > >
> > > No more misusing of *_MAX \ RTE_MIN\RTE_MAX in the mlx PMDs?
> >
> > Sorry I don't understand your question.
> 
> If you are asking if there are more hardcoded constants, the answer is yes
> but they are masks.
> I think the masks can remain hardcoded.

Agree.
Acked-by: Matan Azrad <matan@mellanox.com>
  
Raslan Darawsheh Feb. 11, 2020, 8:29 a.m. UTC | #5
Hi,

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Thomas Monjalon
> Sent: Sunday, February 9, 2020 11:17 PM
> To: Matan Azrad <matan@mellanox.com>; Shahaf Shuler
> <shahafs@mellanox.com>; Slava Ovsiienko <viacheslavo@mellanox.com>
> Cc: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH] net/mlx: replace hardcoded value with macro
> 
> Replace checking against 65535 limit,
> with a simpler form using RTE_MIN and UINT16_MAX macros.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
>  drivers/net/mlx4/mlx4_ethdev.c | 5 ++---
>  drivers/net/mlx5/mlx5_ethdev.c | 5 ++---
>  2 files changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/mlx4/mlx4_ethdev.c
> b/drivers/net/mlx4/mlx4_ethdev.c
> index e500ec422c..9ff05c6738 100644
> --- a/drivers/net/mlx4/mlx4_ethdev.c
> +++ b/drivers/net/mlx4/mlx4_ethdev.c
> @@ -645,9 +645,8 @@ mlx4_dev_infos_get(struct rte_eth_dev *dev, struct
> rte_eth_dev_info *info)
>  	 */
>  	max = ((priv->device_attr.max_cq > priv->device_attr.max_qp) ?
>  	       priv->device_attr.max_qp : priv->device_attr.max_cq);
> -	/* If max >= 65535 then max = 0, max_rx_queues is uint16_t. */
> -	if (max >= 65535)
> -		max = 65535;
> +	/* max_rx_queues is uint16_t. */
> +	max = RTE_MIN(max, (unsigned int)UINT16_MAX);
>  	info->max_rx_queues = max;
>  	info->max_tx_queues = max;
>  	info->max_mac_addrs = RTE_DIM(priv->mac);
> diff --git a/drivers/net/mlx5/mlx5_ethdev.c
> b/drivers/net/mlx5/mlx5_ethdev.c
> index 86923aa7af..d7d3bc73ce 100644
> --- a/drivers/net/mlx5/mlx5_ethdev.c
> +++ b/drivers/net/mlx5/mlx5_ethdev.c
> @@ -619,9 +619,8 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct
> rte_eth_dev_info *info)
>  	 */
>  	max = RTE_MIN(priv->sh->device_attr.orig_attr.max_cq,
>  		      priv->sh->device_attr.orig_attr.max_qp);
> -	/* If max >= 65535 then max = 0, max_rx_queues is uint16_t. */
> -	if (max >= 65535)
> -		max = 65535;
> +	/* max_rx_queues is uint16_t. */
> +	max = RTE_MIN(max, (unsigned int)UINT16_MAX);
>  	info->max_rx_queues = max;
>  	info->max_tx_queues = max;
>  	info->max_mac_addrs = MLX5_MAX_UC_MAC_ADDRESSES;
> --
> 2.25.0

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh
  

Patch

diff --git a/drivers/net/mlx4/mlx4_ethdev.c b/drivers/net/mlx4/mlx4_ethdev.c
index e500ec422c..9ff05c6738 100644
--- a/drivers/net/mlx4/mlx4_ethdev.c
+++ b/drivers/net/mlx4/mlx4_ethdev.c
@@ -645,9 +645,8 @@  mlx4_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 	 */
 	max = ((priv->device_attr.max_cq > priv->device_attr.max_qp) ?
 	       priv->device_attr.max_qp : priv->device_attr.max_cq);
-	/* If max >= 65535 then max = 0, max_rx_queues is uint16_t. */
-	if (max >= 65535)
-		max = 65535;
+	/* max_rx_queues is uint16_t. */
+	max = RTE_MIN(max, (unsigned int)UINT16_MAX);
 	info->max_rx_queues = max;
 	info->max_tx_queues = max;
 	info->max_mac_addrs = RTE_DIM(priv->mac);
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 86923aa7af..d7d3bc73ce 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -619,9 +619,8 @@  mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 	 */
 	max = RTE_MIN(priv->sh->device_attr.orig_attr.max_cq,
 		      priv->sh->device_attr.orig_attr.max_qp);
-	/* If max >= 65535 then max = 0, max_rx_queues is uint16_t. */
-	if (max >= 65535)
-		max = 65535;
+	/* max_rx_queues is uint16_t. */
+	max = RTE_MIN(max, (unsigned int)UINT16_MAX);
 	info->max_rx_queues = max;
 	info->max_tx_queues = max;
 	info->max_mac_addrs = MLX5_MAX_UC_MAC_ADDRESSES;