lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1389035317.9947.94.camel@bwh-desktop.uk.level5networks.com>
Date:	Mon, 6 Jan 2014 19:08:37 +0000
From:	Ben Hutchings <bhutchings@...arflare.com>
To:	Sabrina Dubroca <sd@...asysnail.net>
CC:	<davem@...emloft.net>, <johannes@...solutions.net>,
	<stephen@...workplumber.org>, <netdev@...r.kernel.org>
Subject: Re: [PATCH v3 5/5] alx: add stats to ethtool

On Mon, 2014-01-06 at 17:33 +0100, Sabrina Dubroca wrote:
> Signed-off-by: Sabrina Dubroca <sd@...asysnail.net>

Reviewed-by: Ben Hutchings <bhutchings@...arflare.com>

> ---
>  drivers/net/ethernet/atheros/alx/ethtool.c | 101 +++++++++++++++++++++++++++++
>  drivers/net/ethernet/atheros/alx/hw.h      |   7 +-
>  2 files changed, 107 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/atheros/alx/ethtool.c b/drivers/net/ethernet/atheros/alx/ethtool.c
> index 45b3650..08e22df 100644
> --- a/drivers/net/ethernet/atheros/alx/ethtool.c
> +++ b/drivers/net/ethernet/atheros/alx/ethtool.c
> @@ -46,6 +46,66 @@
>  #include "reg.h"
>  #include "hw.h"
>  
> +/* The order of these strings must match the order of the fields in
> + * struct alx_hw_stats
> + * See hw.h
> + */
> +static const char alx_gstrings_stats[][ETH_GSTRING_LEN] = {
> +	"rx_packets",
> +	"rx_bcast_packets",
> +	"rx_mcast_packets",
> +	"rx_pause_packets",
> +	"rx_ctrl_packets",
> +	"rx_fcs_errors",
> +	"rx_length_errors",
> +	"rx_bytes",
> +	"rx_runt_packets",
> +	"rx_fragments",
> +	"rx_64B_or_less_packets",
> +	"rx_65B_to_127B_packets",
> +	"rx_128B_to_255B_packets",
> +	"rx_256B_to_511B_packets",
> +	"rx_512B_to_1023B_packets",
> +	"rx_1024B_to_1518B_packets",
> +	"rx_1519B_to_mtu_packets",
> +	"rx_oversize_packets",
> +	"rx_rxf_ov_drop_packets",
> +	"rx_rrd_ov_drop_packets",
> +	"rx_align_errors",
> +	"rx_bcast_bytes",
> +	"rx_mcast_bytes",
> +	"rx_address_errors",
> +	"tx_packets",
> +	"tx_bcast_packets",
> +	"tx_mcast_packets",
> +	"tx_pause_packets",
> +	"tx_exc_defer_packets",
> +	"tx_ctrl_packets",
> +	"tx_defer_packets",
> +	"tx_bytes",
> +	"tx_64B_or_less_packets",
> +	"tx_65B_to_127B_packets",
> +	"tx_128B_to_255B_packets",
> +	"tx_256B_to_511B_packets",
> +	"tx_512B_to_1023B_packets",
> +	"tx_1024B_to_1518B_packets",
> +	"tx_1519B_to_mtu_packets",
> +	"tx_single_collision",
> +	"tx_multiple_collisions",
> +	"tx_late_collision",
> +	"tx_abort_collision",
> +	"tx_underrun",
> +	"tx_trd_eop",
> +	"tx_length_errors",
> +	"tx_trunc_packets",
> +	"tx_bcast_bytes",
> +	"tx_mcast_bytes",
> +	"tx_update",
> +};
> +
> +#define ALX_NUM_STATS ARRAY_SIZE(alx_gstrings_stats)
> +
> +
>  static u32 alx_get_supported_speeds(struct alx_hw *hw)
>  {
>  	u32 supported = SUPPORTED_10baseT_Half |
> @@ -201,6 +261,44 @@ static void alx_set_msglevel(struct net_device *netdev, u32 data)
>  	alx->msg_enable = data;
>  }
>  
> +static void alx_get_ethtool_stats(struct net_device *netdev,
> +				  struct ethtool_stats *estats, u64 *data)
> +{
> +	struct alx_priv *alx = netdev_priv(netdev);
> +	struct alx_hw *hw = &alx->hw;
> +
> +	spin_lock(&alx->stats_lock);
> +
> +	alx_update_hw_stats(hw);
> +	BUILD_BUG_ON(sizeof(hw->stats) - offsetof(struct alx_hw_stats, rx_ok) <
> +		     ALX_NUM_STATS * sizeof(u64));
> +	memcpy(data, &hw->stats.rx_ok, ALX_NUM_STATS * sizeof(u64));
> +
> +	spin_unlock(&alx->stats_lock);
> +}
> +
> +static void alx_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
> +{
> +	switch (stringset) {
> +	case ETH_SS_STATS:
> +		memcpy(buf, &alx_gstrings_stats, sizeof(alx_gstrings_stats));
> +		break;
> +	default:
> +		WARN_ON(1);
> +		break;
> +	}
> +}
> +
> +static int alx_get_sset_count(struct net_device *netdev, int sset)
> +{
> +	switch (sset) {
> +	case ETH_SS_STATS:
> +		return ALX_NUM_STATS;
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
>  const struct ethtool_ops alx_ethtool_ops = {
>  	.get_settings	= alx_get_settings,
>  	.set_settings	= alx_set_settings,
> @@ -209,4 +307,7 @@ const struct ethtool_ops alx_ethtool_ops = {
>  	.get_msglevel	= alx_get_msglevel,
>  	.set_msglevel	= alx_set_msglevel,
>  	.get_link	= ethtool_op_get_link,
> +	.get_strings	= alx_get_strings,
> +	.get_sset_count	= alx_get_sset_count,
> +	.get_ethtool_stats	= alx_get_ethtool_stats,
>  };
> diff --git a/drivers/net/ethernet/atheros/alx/hw.h b/drivers/net/ethernet/atheros/alx/hw.h
> index a97edfb..5978253 100644
> --- a/drivers/net/ethernet/atheros/alx/hw.h
> +++ b/drivers/net/ethernet/atheros/alx/hw.h
> @@ -381,7 +381,12 @@ struct alx_rrd {
>  				 ALX_ISR_RX_Q6 | \
>  				 ALX_ISR_RX_Q7)
>  
> -/* Statistics counters collected by the MAC */
> +/* Statistics counters collected by the MAC
> + *
> + * The order of the fields must match the strings in alx_gstrings_stats
> + * All stats fields should be u64
> + * See ethtool.c
> + */
>  struct alx_hw_stats {
>  	/* rx */
>  	u64 rx_ok;

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ