Commit 9dae5921 authored by Rosen Penev's avatar Rosen Penev Committed by Jakub Kicinski
Browse files

net: sfc: use ethtool string helpers



The latter is the preferred way to copy ethtool strings.

Avoids manually incrementing the pointer. Cleans up the code quite well.

Signed-off-by: default avatarRosen Penev <rosenp@gmail.com>
Acked-by: default avatarEdward Cree <ecree.xilinx@gmail.com>
Link: https://patch.msgid.link/20241105231855.235894-1-rosenp@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 7d28f4fc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1751,7 +1751,7 @@ static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
#endif
}

static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 **names)
{
	DECLARE_BITMAP(mask, EF10_STAT_COUNT);

+1 −1
Original line number Diff line number Diff line
@@ -583,7 +583,7 @@ static const struct efx_hw_stat_desc ef100_stat_desc[EF100_STAT_COUNT] = {
	EFX_GENERIC_SW_STAT(rx_noskb_drops),
};

static size_t ef100_describe_stats(struct efx_nic *efx, u8 *names)
static size_t ef100_describe_stats(struct efx_nic *efx, u8 **names)
{
	DECLARE_BITMAP(mask, EF100_STAT_COUNT) = {};

+20 −26
Original line number Diff line number Diff line
@@ -395,7 +395,7 @@ int efx_ethtool_fill_self_tests(struct efx_nic *efx,
	return n;
}

static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 **strings)
{
	size_t n_stats = 0;
	struct efx_channel *channel;
@@ -403,24 +403,22 @@ static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
	efx_for_each_channel(channel, efx) {
		if (efx_channel_has_tx_queues(channel)) {
			n_stats++;
			if (strings != NULL) {
				snprintf(strings, ETH_GSTRING_LEN,
					 "tx-%u.tx_packets",
			if (!strings)
				continue;

			ethtool_sprintf(strings, "tx-%u.tx_packets",
					channel->tx_queue[0].queue /
						EFX_MAX_TXQ_PER_CHANNEL);

				strings += ETH_GSTRING_LEN;
			}
		}
	}
	efx_for_each_channel(channel, efx) {
		if (efx_channel_has_rx_queue(channel)) {
			n_stats++;
			if (strings != NULL) {
				snprintf(strings, ETH_GSTRING_LEN,
					 "rx-%d.rx_packets", channel->channel);
				strings += ETH_GSTRING_LEN;
			}
			if (!strings)
				continue;

			ethtool_sprintf(strings, "rx-%d.rx_packets",
					channel->channel);
		}
	}
	if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) {
@@ -428,11 +426,11 @@ static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)

		for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) {
			n_stats++;
			if (strings) {
				snprintf(strings, ETH_GSTRING_LEN,
					 "tx-xdp-cpu-%hu.tx_packets", xdp);
				strings += ETH_GSTRING_LEN;
			}
			if (!strings)
				continue;

			ethtool_sprintf(strings, "tx-xdp-cpu-%hu.tx_packets",
					xdp);
		}
	}

@@ -464,15 +462,11 @@ void efx_ethtool_get_strings(struct net_device *net_dev,

	switch (string_set) {
	case ETH_SS_STATS:
		strings += (efx->type->describe_stats(efx, strings) *
			    ETH_GSTRING_LEN);
		efx->type->describe_stats(efx, &strings);
		for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
			strscpy(strings + i * ETH_GSTRING_LEN,
				efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
		strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
		strings += (efx_describe_per_queue_stats(efx, strings) *
			    ETH_GSTRING_LEN);
		efx_ptp_describe_stats(efx, strings);
			ethtool_puts(&strings, efx_sw_stat_desc[i].name);
		efx_describe_per_queue_stats(efx, &strings);
		efx_ptp_describe_stats(efx, &strings);
		break;
	case ETH_SS_TEST:
		efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
+14 −20
Original line number Diff line number Diff line
@@ -353,7 +353,7 @@ static int ef4_ethtool_fill_self_tests(struct ef4_nic *efx,
	return n;
}

static size_t ef4_describe_per_queue_stats(struct ef4_nic *efx, u8 *strings)
static size_t ef4_describe_per_queue_stats(struct ef4_nic *efx, u8 **strings)
{
	size_t n_stats = 0;
	struct ef4_channel *channel;
@@ -361,24 +361,22 @@ static size_t ef4_describe_per_queue_stats(struct ef4_nic *efx, u8 *strings)
	ef4_for_each_channel(channel, efx) {
		if (ef4_channel_has_tx_queues(channel)) {
			n_stats++;
			if (strings != NULL) {
				snprintf(strings, ETH_GSTRING_LEN,
					 "tx-%u.tx_packets",
			if (!strings)
				continue;

			ethtool_sprintf(strings, "tx-%u.tx_packets",
					channel->tx_queue[0].queue /
						EF4_TXQ_TYPES);

				strings += ETH_GSTRING_LEN;
			}
		}
	}
	ef4_for_each_channel(channel, efx) {
		if (ef4_channel_has_rx_queue(channel)) {
			n_stats++;
			if (strings != NULL) {
				snprintf(strings, ETH_GSTRING_LEN,
					 "rx-%d.rx_packets", channel->channel);
				strings += ETH_GSTRING_LEN;
			}
			if (!strings)
				continue;

			ethtool_sprintf(strings, "rx-%d.rx_packets",
					channel->channel);
		}
	}
	return n_stats;
@@ -409,14 +407,10 @@ static void ef4_ethtool_get_strings(struct net_device *net_dev,

	switch (string_set) {
	case ETH_SS_STATS:
		strings += (efx->type->describe_stats(efx, strings) *
			    ETH_GSTRING_LEN);
		efx->type->describe_stats(efx, &strings);
		for (i = 0; i < EF4_ETHTOOL_SW_STAT_COUNT; i++)
			strscpy(strings + i * ETH_GSTRING_LEN,
				ef4_sw_stat_desc[i].name, ETH_GSTRING_LEN);
		strings += EF4_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
		strings += (ef4_describe_per_queue_stats(efx, strings) *
			    ETH_GSTRING_LEN);
			ethtool_puts(&strings, ef4_sw_stat_desc[i].name);
		ef4_describe_per_queue_stats(efx, &strings);
		break;
	case ETH_SS_TEST:
		ef4_ethtool_fill_self_tests(efx, NULL, strings, NULL);
+1 −1
Original line number Diff line number Diff line
@@ -2564,7 +2564,7 @@ static void falcon_remove_nic(struct ef4_nic *efx)
	efx->nic_data = NULL;
}

static size_t falcon_describe_nic_stats(struct ef4_nic *efx, u8 *names)
static size_t falcon_describe_nic_stats(struct ef4_nic *efx, u8 **names)
{
	return ef4_nic_describe_stats(falcon_stat_desc, FALCON_STAT_COUNT,
				      falcon_stat_mask, names);
Loading