Skip to contentSkip to conversation

net/mlx: replace hardcoded value with macro

PATCH In review Thomas Monjalon 3 participants 6 messages Feb 9, 2020 – Feb 11, 2020 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx: replace hardcoded value with macro

Replace checking against 65535 limit,
with a simpler form using RTE_MIN and UINT16_MAX macros.

---
 drivers/net/mlx4/mlx4_ethdev.c | 5 ++---
 drivers/net/mlx5/mlx5_ethdev.c | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)
drivers/net/mlx4/mlx4_ethdev.c +2 -3
index e500ec422c..9ff05c6738 100644
@@ -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);
drivers/net/mlx5/mlx5_ethdev.c +2 -3
index 86923aa7af..d7d3bc73ce 100644
@@ -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;
Signature · 1 line
2.25.0
#1 lore raw

Hi Thomas

From: Thomas Monjalon

Quoted 48 lines

Sent: Sunday, February 9, 2020 11:17 PM
To: Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Slava Ovsiienko <[email protected]>
Cc: [email protected]
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.

---
drivers/net/mlx4/mlx4_ethdev.c | 5 ++--- drivers/net/mlx5/mlx5_ethdev.c
| 5 ++---

 2 files changed, 4 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/drivers/net/mlx4/mlx4_ethdev.c index e500ec422c..9ff05c6738 100644

drivers/net/mlx4/mlx4_ethdev.c +2 -3
@@ -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

drivers/net/mlx5/mlx5_ethdev.c +2 -3
@@ -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;
Quoted 1 line

info->max_mac_addrs = MLX5_MAX_UC_MAC_ADDRESSES;

No more misusing of *_MAX \ RTE_MIN\RTE_MAX in the mlx PMDs?

#2 lore raw

10/02/2020 07:32, Matan Azrad:

Quoted 9 lines

From: Thomas Monjalon

Quoted 5 lines

Replace checking against 65535 limit,
with a simpler form using RTE_MIN and UINT16_MAX macros.

---

No more misusing of *_MAX \ RTE_MIN\RTE_MAX in the mlx PMDs?

Sorry I don't understand your question.

#3 lore raw

10/02/2020 09:52, Thomas Monjalon:

Quoted 6 lines

10/02/2020 07:32, Matan Azrad:

Quoted 5 lines

From: Thomas Monjalon

Quoted 3 lines

Replace checking against 65535 limit,
with a simpler form using RTE_MIN and UINT16_MAX macros.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

---

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.

Acked-by
#4 lore raw

From: Thomas Monjalon

Quoted 10 lines

10/02/2020 09:52, Thomas Monjalon:

Quoted 9 lines

10/02/2020 07:32, Matan Azrad:

Quoted 8 lines

From: Thomas Monjalon

Quoted 5 lines

Replace checking against 65535 limit, with a simpler form using RTE_MIN and UINT16_MAX macros.

---

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

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.

#5 lore raw
In reply to Thomas Monjalon

Hi,

Quoted 52 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Thomas Monjalon
Sent: Sunday, February 9, 2020 11:17 PM
To: Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Slava Ovsiienko <[email protected]>
Cc: [email protected]
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.

---
 drivers/net/mlx4/mlx4_ethdev.c | 5 ++---
 drivers/net/mlx5/mlx5_ethdev.c | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)
drivers/net/mlx4/mlx4_ethdev.c +2 -3
index e500ec422c..9ff05c6738 100644
@@ -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;
drivers/net/mlx4/mlx4_ethdev.c +0 -0
 	info->max_mac_addrs = RTE_DIM(priv->mac);
drivers/net/mlx5/mlx5_ethdev.c +2 -3
index 86923aa7af..d7d3bc73ce 100644
@@ -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;
Quoted 3 lines

info->max_mac_addrs = MLX5_MAX_UC_MAC_ADDRESSES;
--
2.25.0

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh