[PATCH 2/2] mlx5: extract GRXRINGS from .get_rxnfc

Breno Leitao posted 2 patches 2 months, 4 weeks ago
[PATCH 2/2] mlx5: extract GRXRINGS from .get_rxnfc
Posted by Breno Leitao 2 months, 4 weeks ago
Commit 84eaf4359c36 ("net: ethtool: add get_rx_ring_count callback to
optimize RX ring queries") added specific support for GRXRINGS callback,
simplifying .get_rxnfc.

Remove the handling of GRXRINGS in .get_rxnfc() by moving it to the new
.get_rx_ring_count() for both the mlx5 ethernet and IPoIB drivers.

The ETHTOOL_GRXRINGS handling was previously kept in .get_rxnfc() to
support "ethtool -x" when CONFIG_MLX5_EN_RXNFC=n. With the new
dedicated .get_rx_ring_count() callback, this is no longer necessary.

This simplifies the RX ring count retrieval and aligns mlx5 with the new
ethtool API for querying RX ring parameters.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c   | 18 ++++++++----------
 .../net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c    | 18 ++++++++----------
 2 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
index 01b8f05a23db..939e274779b3 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
@@ -2492,21 +2492,18 @@ static int mlx5e_set_rxfh_fields(struct net_device *dev,
 	return mlx5e_ethtool_set_rxfh_fields(priv, cmd, extack);
 }
 
+static u32 mlx5e_get_rx_ring_count(struct net_device *dev)
+{
+	struct mlx5e_priv *priv = netdev_priv(dev);
+
+	return priv->channels.params.num_channels;
+}
+
 static int mlx5e_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
 			   u32 *rule_locs)
 {
 	struct mlx5e_priv *priv = netdev_priv(dev);
 
-	/* ETHTOOL_GRXRINGS is needed by ethtool -x which is not part
-	 * of rxnfc. We keep this logic out of mlx5e_ethtool_get_rxnfc,
-	 * to avoid breaking "ethtool -x" when mlx5e_ethtool_get_rxnfc
-	 * is compiled out via CONFIG_MLX5_EN_RXNFC=n.
-	 */
-	if (info->cmd == ETHTOOL_GRXRINGS) {
-		info->data = priv->channels.params.num_channels;
-		return 0;
-	}
-
 	return mlx5e_ethtool_get_rxnfc(priv, info, rule_locs);
 }
 
@@ -2766,6 +2763,7 @@ const struct ethtool_ops mlx5e_ethtool_ops = {
 	.remove_rxfh_context	= mlx5e_remove_rxfh_context,
 	.get_rxnfc         = mlx5e_get_rxnfc,
 	.set_rxnfc         = mlx5e_set_rxnfc,
+	.get_rx_ring_count = mlx5e_get_rx_ring_count,
 	.get_tunable       = mlx5e_get_tunable,
 	.set_tunable       = mlx5e_set_tunable,
 	.get_pause_stats   = mlx5e_get_pause_stats,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c
index 4b3430ac3905..3b2f54ca30a8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c
@@ -266,21 +266,18 @@ static int mlx5i_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
 	return mlx5e_ethtool_set_rxnfc(priv, cmd);
 }
 
+static u32 mlx5i_get_rx_ring_count(struct net_device *dev)
+{
+	struct mlx5e_priv *priv = mlx5i_epriv(dev);
+
+	return priv->channels.params.num_channels;
+}
+
 static int mlx5i_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
 			   u32 *rule_locs)
 {
 	struct mlx5e_priv *priv = mlx5i_epriv(dev);
 
-	/* ETHTOOL_GRXRINGS is needed by ethtool -x which is not part
-	 * of rxnfc. We keep this logic out of mlx5e_ethtool_get_rxnfc,
-	 * to avoid breaking "ethtool -x" when mlx5e_ethtool_get_rxnfc
-	 * is compiled out via CONFIG_MLX5_EN_RXNFC=n.
-	 */
-	if (info->cmd == ETHTOOL_GRXRINGS) {
-		info->data = priv->channels.params.num_channels;
-		return 0;
-	}
-
 	return mlx5e_ethtool_get_rxnfc(priv, info, rule_locs);
 }
 
@@ -304,6 +301,7 @@ const struct ethtool_ops mlx5i_ethtool_ops = {
 	.set_rxfh_fields    = mlx5i_set_rxfh_fields,
 	.get_rxnfc          = mlx5i_get_rxnfc,
 	.set_rxnfc          = mlx5i_set_rxnfc,
+	.get_rx_ring_count  = mlx5i_get_rx_ring_count,
 	.get_link_ksettings = mlx5i_get_link_ksettings,
 	.get_link           = ethtool_op_get_link,
 };

-- 
2.47.3
Re: [PATCH 2/2] mlx5: extract GRXRINGS from .get_rxnfc
Posted by Tariq Toukan 2 months, 3 weeks ago

On 13/11/2025 18:46, Breno Leitao wrote:
> Commit 84eaf4359c36 ("net: ethtool: add get_rx_ring_count callback to
> optimize RX ring queries") added specific support for GRXRINGS callback,
> simplifying .get_rxnfc.
> 
> Remove the handling of GRXRINGS in .get_rxnfc() by moving it to the new
> .get_rx_ring_count() for both the mlx5 ethernet and IPoIB drivers.
> 
> The ETHTOOL_GRXRINGS handling was previously kept in .get_rxnfc() to
> support "ethtool -x" when CONFIG_MLX5_EN_RXNFC=n. With the new
> dedicated .get_rx_ring_count() callback, this is no longer necessary.
> 
> This simplifies the RX ring count retrieval and aligns mlx5 with the new
> ethtool API for querying RX ring parameters.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c   | 18 ++++++++----------
>   .../net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c    | 18 ++++++++----------
>   2 files changed, 16 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
> index 01b8f05a23db..939e274779b3 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
> @@ -2492,21 +2492,18 @@ static int mlx5e_set_rxfh_fields(struct net_device *dev,
>   	return mlx5e_ethtool_set_rxfh_fields(priv, cmd, extack);
>   }
>   
> +static u32 mlx5e_get_rx_ring_count(struct net_device *dev)
> +{
> +	struct mlx5e_priv *priv = netdev_priv(dev);
> +
> +	return priv->channels.params.num_channels;
> +}
> +
>   static int mlx5e_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
>   			   u32 *rule_locs)
>   {
>   	struct mlx5e_priv *priv = netdev_priv(dev);
>   
> -	/* ETHTOOL_GRXRINGS is needed by ethtool -x which is not part
> -	 * of rxnfc. We keep this logic out of mlx5e_ethtool_get_rxnfc,
> -	 * to avoid breaking "ethtool -x" when mlx5e_ethtool_get_rxnfc
> -	 * is compiled out via CONFIG_MLX5_EN_RXNFC=n.
> -	 */
> -	if (info->cmd == ETHTOOL_GRXRINGS) {
> -		info->data = priv->channels.params.num_channels;
> -		return 0;
> -	}
> -
>   	return mlx5e_ethtool_get_rxnfc(priv, info, rule_locs);
>   }
>   
> @@ -2766,6 +2763,7 @@ const struct ethtool_ops mlx5e_ethtool_ops = {
>   	.remove_rxfh_context	= mlx5e_remove_rxfh_context,
>   	.get_rxnfc         = mlx5e_get_rxnfc,
>   	.set_rxnfc         = mlx5e_set_rxnfc,
> +	.get_rx_ring_count = mlx5e_get_rx_ring_count,
>   	.get_tunable       = mlx5e_get_tunable,
>   	.set_tunable       = mlx5e_set_tunable,
>   	.get_pause_stats   = mlx5e_get_pause_stats,
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c
> index 4b3430ac3905..3b2f54ca30a8 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c
> @@ -266,21 +266,18 @@ static int mlx5i_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
>   	return mlx5e_ethtool_set_rxnfc(priv, cmd);
>   }
>   
> +static u32 mlx5i_get_rx_ring_count(struct net_device *dev)
> +{
> +	struct mlx5e_priv *priv = mlx5i_epriv(dev);
> +
> +	return priv->channels.params.num_channels;
> +}
> +
>   static int mlx5i_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
>   			   u32 *rule_locs)
>   {
>   	struct mlx5e_priv *priv = mlx5i_epriv(dev);
>   
> -	/* ETHTOOL_GRXRINGS is needed by ethtool -x which is not part
> -	 * of rxnfc. We keep this logic out of mlx5e_ethtool_get_rxnfc,
> -	 * to avoid breaking "ethtool -x" when mlx5e_ethtool_get_rxnfc
> -	 * is compiled out via CONFIG_MLX5_EN_RXNFC=n.
> -	 */
> -	if (info->cmd == ETHTOOL_GRXRINGS) {
> -		info->data = priv->channels.params.num_channels;
> -		return 0;
> -	}
> -
>   	return mlx5e_ethtool_get_rxnfc(priv, info, rule_locs);
>   }
>   
> @@ -304,6 +301,7 @@ const struct ethtool_ops mlx5i_ethtool_ops = {
>   	.set_rxfh_fields    = mlx5i_set_rxfh_fields,
>   	.get_rxnfc          = mlx5i_get_rxnfc,
>   	.set_rxnfc          = mlx5i_set_rxnfc,
> +	.get_rx_ring_count  = mlx5i_get_rx_ring_count,
>   	.get_link_ksettings = mlx5i_get_link_ksettings,
>   	.get_link           = ethtool_op_get_link,
>   };
> 

Reviewed-by: Tariq Toukan <tariqt@nvidia.com>

Thanks.