* [PATCH net-next] net: mellanox: use ethtool string helpers
@ 2024-10-29 23:54 Rosen Penev
2024-10-30 13:28 ` Ido Schimmel
0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2024-10-29 23:54 UTC (permalink / raw)
To: netdev
Cc: Ido Schimmel, Petr Machata, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
open list
These are the preferred way to copy ethtool strings.
Avoids incrementing pointers all over the place.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
.../mellanox/mlxsw/spectrum_ethtool.c | 83 +++++++------------
.../ethernet/mellanox/mlxsw/spectrum_ptp.c | 7 +-
2 files changed, 30 insertions(+), 60 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c
index 87a51e7d4390..5189af0da1f4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c
@@ -607,84 +607,57 @@ static void mlxsw_sp_port_get_prio_strings(u8 **p, int prio)
{
int i;
- for (i = 0; i < MLXSW_SP_PORT_HW_PRIO_STATS_LEN; i++) {
- snprintf(*p, ETH_GSTRING_LEN, "%.29s_%.1d",
- mlxsw_sp_port_hw_prio_stats[i].str, prio);
- *p += ETH_GSTRING_LEN;
- }
+ for (i = 0; i < MLXSW_SP_PORT_HW_PRIO_STATS_LEN; i++)
+ ethtool_sprintf(p, "%.29s_%.1d",
+ mlxsw_sp_port_hw_prio_stats[i].str, prio);
}
static void mlxsw_sp_port_get_tc_strings(u8 **p, int tc)
{
int i;
- for (i = 0; i < MLXSW_SP_PORT_HW_TC_STATS_LEN; i++) {
- snprintf(*p, ETH_GSTRING_LEN, "%.28s_%d",
- mlxsw_sp_port_hw_tc_stats[i].str, tc);
- *p += ETH_GSTRING_LEN;
- }
+ for (i = 0; i < MLXSW_SP_PORT_HW_TC_STATS_LEN; i++)
+ ethtool_sprintf(p, "%.28s_%d", mlxsw_sp_port_hw_tc_stats[i].str,
+ tc);
}
static void mlxsw_sp_port_get_strings(struct net_device *dev,
u32 stringset, u8 *data)
{
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
- u8 *p = data;
int i;
- switch (stringset) {
- case ETH_SS_STATS:
- for (i = 0; i < MLXSW_SP_PORT_HW_STATS_LEN; i++) {
- memcpy(p, mlxsw_sp_port_hw_stats[i].str,
- ETH_GSTRING_LEN);
- p += ETH_GSTRING_LEN;
- }
+ if (stringset != ETH_SS_STATS)
+ return;
- for (i = 0; i < MLXSW_SP_PORT_HW_RFC_2863_STATS_LEN; i++) {
- memcpy(p, mlxsw_sp_port_hw_rfc_2863_stats[i].str,
- ETH_GSTRING_LEN);
- p += ETH_GSTRING_LEN;
- }
+ for (i = 0; i < MLXSW_SP_PORT_HW_STATS_LEN; i++)
+ ethtool_puts(&data, mlxsw_sp_port_hw_stats[i].str);
- for (i = 0; i < MLXSW_SP_PORT_HW_RFC_2819_STATS_LEN; i++) {
- memcpy(p, mlxsw_sp_port_hw_rfc_2819_stats[i].str,
- ETH_GSTRING_LEN);
- p += ETH_GSTRING_LEN;
- }
+ for (i = 0; i < MLXSW_SP_PORT_HW_RFC_2863_STATS_LEN; i++)
+ ethtool_puts(&data, mlxsw_sp_port_hw_rfc_2863_stats[i].str);
- for (i = 0; i < MLXSW_SP_PORT_HW_RFC_3635_STATS_LEN; i++) {
- memcpy(p, mlxsw_sp_port_hw_rfc_3635_stats[i].str,
- ETH_GSTRING_LEN);
- p += ETH_GSTRING_LEN;
- }
+ for (i = 0; i < MLXSW_SP_PORT_HW_RFC_2819_STATS_LEN; i++)
+ ethtool_puts(&data, mlxsw_sp_port_hw_rfc_2819_stats[i].str);
- for (i = 0; i < MLXSW_SP_PORT_HW_EXT_STATS_LEN; i++) {
- memcpy(p, mlxsw_sp_port_hw_ext_stats[i].str,
- ETH_GSTRING_LEN);
- p += ETH_GSTRING_LEN;
- }
+ for (i = 0; i < MLXSW_SP_PORT_HW_RFC_3635_STATS_LEN; i++)
+ ethtool_puts(&data, mlxsw_sp_port_hw_rfc_3635_stats[i].str);
- for (i = 0; i < MLXSW_SP_PORT_HW_DISCARD_STATS_LEN; i++) {
- memcpy(p, mlxsw_sp_port_hw_discard_stats[i].str,
- ETH_GSTRING_LEN);
- p += ETH_GSTRING_LEN;
- }
+ for (i = 0; i < MLXSW_SP_PORT_HW_EXT_STATS_LEN; i++)
+ ethtool_puts(&data, mlxsw_sp_port_hw_ext_stats[i].str);
- for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
- mlxsw_sp_port_get_prio_strings(&data, i);
+ for (i = 0; i < MLXSW_SP_PORT_HW_DISCARD_STATS_LEN; i++)
+ ethtool_puts(&data, mlxsw_sp_port_hw_discard_stats[i].str);
- for (i = 0; i < TC_MAX_QUEUE; i++)
- mlxsw_sp_port_get_tc_strings(&data, i);
+ for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
+ mlxsw_sp_port_get_prio_strings(&data, i);
- mlxsw_sp_port->mlxsw_sp->ptp_ops->get_stats_strings(&data);
+ for (i = 0; i < TC_MAX_QUEUE; i++)
+ mlxsw_sp_port_get_tc_strings(&data, i);
- for (i = 0; i < MLXSW_SP_PORT_HW_TRANSCEIVER_STATS_LEN; i++) {
- memcpy(p, mlxsw_sp_port_transceiver_stats[i].str,
- ETH_GSTRING_LEN);
- p += ETH_GSTRING_LEN;
- }
- break;
- }
+ mlxsw_sp_port->mlxsw_sp->ptp_ops->get_stats_strings(&data);
+
+ for (i = 0; i < MLXSW_SP_PORT_HW_TRANSCEIVER_STATS_LEN; i++)
+ ethtool_puts(&data, mlxsw_sp_port_transceiver_stats[i].str);
}
static int mlxsw_sp_port_set_phys_id(struct net_device *dev,
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c
index 5b174cb95eb8..72e925558061 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c
@@ -1326,11 +1326,8 @@ void mlxsw_sp1_get_stats_strings(u8 **p)
{
int i;
- for (i = 0; i < MLXSW_SP_PTP_PORT_STATS_LEN; i++) {
- memcpy(*p, mlxsw_sp_ptp_port_stats[i].str,
- ETH_GSTRING_LEN);
- *p += ETH_GSTRING_LEN;
- }
+ for (i = 0; i < MLXSW_SP_PTP_PORT_STATS_LEN; i++)
+ ethtool_puts(p, mlxsw_sp_ptp_port_stats[i].str);
}
void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
--
2.47.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net-next] net: mellanox: use ethtool string helpers
2024-10-29 23:54 [PATCH net-next] net: mellanox: use ethtool string helpers Rosen Penev
@ 2024-10-30 13:28 ` Ido Schimmel
0 siblings, 0 replies; 2+ messages in thread
From: Ido Schimmel @ 2024-10-30 13:28 UTC (permalink / raw)
To: Rosen Penev
Cc: netdev, Petr Machata, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Richard Cochran, open list
Wasn't able to apply the patch. Seems to be corrupted. See below.
On Tue, Oct 29, 2024 at 04:54:22PM -0700, Rosen Penev wrote:
[...]
> static void mlxsw_sp_port_get_strings(struct net_device *dev,
> u32 stringset, u8 *data)
> {
> struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
> - u8 *p = data;
> int i;
>
> - switch (stringset) {
> - case ETH_SS_STATS:
> - for (i = 0; i < MLXSW_SP_PORT_HW_STATS_LEN; i++) {
> - memcpy(p, mlxsw_sp_port_hw_stats[i].str,
> - ETH_GSTRING_LEN);
> - p += ETH_GSTRING_LEN;
> - }
> + if (stringset != ETH_SS_STATS)
> + return;
>
> - for (i = 0; i < MLXSW_SP_PORT_HW_RFC_2863_STATS_LEN; i++) {
> - memcpy(p, mlxsw_sp_port_hw_rfc_2863_stats[i].str,
> - ETH_GSTRING_LEN);
> - p += ETH_GSTRING_LEN;
> - }
> + for (i = 0; i < MLXSW_SP_PORT_HW_STATS_LEN; i++)
> + ethtool_puts(&data, mlxsw_sp_port_hw_stats[i].str);
>
> - for (i = 0; i < MLXSW_SP_PORT_HW_RFC_2819_STATS_LEN; i++) {
> - memcpy(p, mlxsw_sp_port_hw_rfc_2819_stats[i].str,
> - ETH_GSTRING_LEN);
> - p += ETH_GSTRING_LEN;
> - }
> + for (i = 0; i < MLXSW_SP_PORT_HW_RFC_2863_STATS_LEN; i++)
> + ethtool_puts(&data, mlxsw_sp_port_hw_rfc_2863_stats[i].str);
>
> - for (i = 0; i < MLXSW_SP_PORT_HW_RFC_3635_STATS_LEN; i++) {
> - memcpy(p, mlxsw_sp_port_hw_rfc_3635_stats[i].str,
> - ETH_GSTRING_LEN);
> - p += ETH_GSTRING_LEN;
> - }
> + for (i = 0; i < MLXSW_SP_PORT_HW_RFC_2819_STATS_LEN; i++)
> + ethtool_puts(&data, mlxsw_sp_port_hw_rfc_2819_stats[i].str);
>
> - for (i = 0; i < MLXSW_SP_PORT_HW_EXT_STATS_LEN; i++) {
> - memcpy(p, mlxsw_sp_port_hw_ext_stats[i].str,
> - ETH_GSTRING_LEN);
> - p += ETH_GSTRING_LEN;
> - }
> + for (i = 0; i < MLXSW_SP_PORT_HW_RFC_3635_STATS_LEN; i++)
> + ethtool_puts(&data, mlxsw_sp_port_hw_rfc_3635_stats[i].str);
>
> - for (i = 0; i < MLXSW_SP_PORT_HW_DISCARD_STATS_LEN; i++) {
> - memcpy(p, mlxsw_sp_port_hw_discard_stats[i].str,
> - ETH_GSTRING_LEN);
> - p += ETH_GSTRING_LEN;
> - }
> + for (i = 0; i < MLXSW_SP_PORT_HW_EXT_STATS_LEN; i++)
> + ethtool_puts(&data, mlxsw_sp_port_hw_ext_stats[i].str);
>
> - for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
> - mlxsw_sp_port_get_prio_strings(&data, i);
s/data/p/ in current code
> + for (i = 0; i < MLXSW_SP_PORT_HW_DISCARD_STATS_LEN; i++)
> + ethtool_puts(&data, mlxsw_sp_port_hw_discard_stats[i].str);
>
> - for (i = 0; i < TC_MAX_QUEUE; i++)
> - mlxsw_sp_port_get_tc_strings(&data, i);
Likewise
> + for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
> + mlxsw_sp_port_get_prio_strings(&data, i);
>
> - mlxsw_sp_port->mlxsw_sp->ptp_ops->get_stats_strings(&data);
Likewise
> + for (i = 0; i < TC_MAX_QUEUE; i++)
> + mlxsw_sp_port_get_tc_strings(&data, i);
>
> - for (i = 0; i < MLXSW_SP_PORT_HW_TRANSCEIVER_STATS_LEN; i++) {
> - memcpy(p, mlxsw_sp_port_transceiver_stats[i].str,
> - ETH_GSTRING_LEN);
> - p += ETH_GSTRING_LEN;
> - }
> - break;
> - }
> + mlxsw_sp_port->mlxsw_sp->ptp_ops->get_stats_strings(&data);
> +
> + for (i = 0; i < MLXSW_SP_PORT_HW_TRANSCEIVER_STATS_LEN; i++)
> + ethtool_puts(&data, mlxsw_sp_port_transceiver_stats[i].str);
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-30 13:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-29 23:54 [PATCH net-next] net: mellanox: use ethtool string helpers Rosen Penev
2024-10-30 13:28 ` Ido Schimmel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.