Commit 89b34322 authored by Gal Pressman's avatar Gal Pressman Committed by Jakub Kicinski
Browse files

net/mlx5e: Use ethtool_sprintf/puts() to fill stats strings



Use ethtool_sprintf/puts() helper functions which handle the common
pattern of printing a string into the ethtool strings interface and
incrementing the string pointer by ETH_GSTRING_LEN.

Change the fill_strings callback to accept a **data pointer, and remove
the index and return value.

Signed-off-by: default avatarGal Pressman <gal@nvidia.com>
Reviewed-by: default avatarTariq Toukan <tariqt@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
Signed-off-by: default avatarTariq Toukan <tariqt@nvidia.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240402133043.56322-4-tariqt@nvidia.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 9ac9299d
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -78,13 +78,10 @@ static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(ipsec_hw)
	unsigned int i;

	if (!priv->ipsec)
		return idx;
		return;

	for (i = 0; i < NUM_IPSEC_HW_COUNTERS; i++)
		strcpy(data + (idx++) * ETH_GSTRING_LEN,
		       mlx5e_ipsec_hw_stats_desc[i].format);

	return idx;
		ethtool_puts(data, mlx5e_ipsec_hw_stats_desc[i].format);
}

static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(ipsec_hw)
@@ -115,9 +112,7 @@ static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(ipsec_sw)

	if (priv->ipsec)
		for (i = 0; i < NUM_IPSEC_SW_COUNTERS; i++)
			strcpy(data + (idx++) * ETH_GSTRING_LEN,
			       mlx5e_ipsec_sw_stats_desc[i].format);
	return idx;
			ethtool_puts(data, mlx5e_ipsec_sw_stats_desc[i].format);
}

static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(ipsec_sw)
+2 −5
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ int mlx5e_ktls_init(struct mlx5e_priv *priv);
void mlx5e_ktls_cleanup(struct mlx5e_priv *priv);

int mlx5e_ktls_get_count(struct mlx5e_priv *priv);
int mlx5e_ktls_get_strings(struct mlx5e_priv *priv, uint8_t *data);
void mlx5e_ktls_get_strings(struct mlx5e_priv *priv, uint8_t **data);
int mlx5e_ktls_get_stats(struct mlx5e_priv *priv, u64 *data);

#else
@@ -144,10 +144,7 @@ static inline bool mlx5e_is_ktls_rx(struct mlx5_core_dev *mdev)
static inline int mlx5e_ktls_init(struct mlx5e_priv *priv) { return 0; }
static inline void mlx5e_ktls_cleanup(struct mlx5e_priv *priv) { }
static inline int mlx5e_ktls_get_count(struct mlx5e_priv *priv) { return 0; }
static inline int mlx5e_ktls_get_strings(struct mlx5e_priv *priv, uint8_t *data)
{
	return 0;
}
static inline void mlx5e_ktls_get_strings(struct mlx5e_priv *priv, uint8_t **data) { }

static inline int mlx5e_ktls_get_stats(struct mlx5e_priv *priv, u64 *data)
{
+4 −7
Original line number Diff line number Diff line
@@ -58,20 +58,17 @@ int mlx5e_ktls_get_count(struct mlx5e_priv *priv)
	return ARRAY_SIZE(mlx5e_ktls_sw_stats_desc);
}

int mlx5e_ktls_get_strings(struct mlx5e_priv *priv, uint8_t *data)
void mlx5e_ktls_get_strings(struct mlx5e_priv *priv, uint8_t **data)
{
	unsigned int i, n, idx = 0;
	unsigned int i, n;

	if (!priv->tls)
		return 0;
		return;

	n = mlx5e_ktls_get_count(priv);

	for (i = 0; i < n; i++)
		strcpy(data + (idx++) * ETH_GSTRING_LEN,
		       mlx5e_ktls_sw_stats_desc[i].format);

	return n;
		ethtool_puts(data, mlx5e_ktls_sw_stats_desc[i].format);
}

int mlx5e_ktls_get_stats(struct mlx5e_priv *priv, u64 *data)
+3 −6
Original line number Diff line number Diff line
@@ -38,16 +38,13 @@ static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(macsec_hw)
	unsigned int i;

	if (!priv->macsec)
		return idx;
		return;

	if (!mlx5e_is_macsec_device(priv->mdev))
		return idx;
		return;

	for (i = 0; i < NUM_MACSEC_HW_COUNTERS; i++)
		strcpy(data + (idx++) * ETH_GSTRING_LEN,
		       mlx5e_macsec_hw_stats_desc[i].format);

	return idx;
		ethtool_puts(data, mlx5e_macsec_hw_stats_desc[i].format);
}

static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(macsec_hw)
+3 −7
Original line number Diff line number Diff line
@@ -135,9 +135,7 @@ static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(sw_rep)
	int i;

	for (i = 0; i < NUM_VPORT_REP_SW_COUNTERS; i++)
		strcpy(data + (idx++) * ETH_GSTRING_LEN,
		       sw_rep_stats_desc[i].format);
	return idx;
		ethtool_puts(data, sw_rep_stats_desc[i].format);
}

static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(sw_rep)
@@ -176,11 +174,9 @@ static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(vport_rep)
	int i;

	for (i = 0; i < NUM_VPORT_REP_HW_COUNTERS; i++)
		strcpy(data + (idx++) * ETH_GSTRING_LEN, vport_rep_stats_desc[i].format);
		ethtool_puts(data, vport_rep_stats_desc[i].format);
	for (i = 0; i < NUM_VPORT_REP_LOOPBACK_COUNTERS(priv->mdev); i++)
		strcpy(data + (idx++) * ETH_GSTRING_LEN,
		       vport_rep_loopback_stats_desc[i].format);
	return idx;
		ethtool_puts(data, vport_rep_loopback_stats_desc[i].format);
}

static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(vport_rep)
Loading