diff mbox series

[net-next,08/12] sfc_ef100: statistics gathering

Message ID aa432cce-7376-129b-dff3-48def9c52945@solarflare.com
State Changes Requested
Delegated to: David Miller
Headers show
Series sfc: driver for EF100 family NICs, part 2 | expand

Commit Message

Edward Cree July 30, 2020, 2:38 p.m. UTC
MAC stats work much the same as on EF10, with a periodic DMA to a region
 specified via an MCDI.

Signed-off-by: Edward Cree <ecree@solarflare.com>
---
 drivers/net/ethernet/sfc/ef100_netdev.c |   6 +
 drivers/net/ethernet/sfc/ef100_nic.c    | 168 ++++++++++++++++++++++++
 drivers/net/ethernet/sfc/ef100_nic.h    |  41 ++++++
 3 files changed, 215 insertions(+)

Comments

kernel test robot July 30, 2020, 7:25 p.m. UTC | #1
Hi Edward,

I love your patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Edward-Cree/sfc-driver-for-EF100-family-NICs-part-2/20200730-224221
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 41d707b7332f1386642c47eb078110ca368a46f5
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=xtensa 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/net/ethernet/sfc/ef100_nic.c: In function 'ef100_get_stat_mask':
>> drivers/net/ethernet/sfc/ef100_nic.c:456:32: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '274877906943' to '4294967295' [-Woverflow]
     456 | #define EF100_COMMON_STAT_MASK ((1ULL << EF100_STAT_port_tx_bytes) |  \
         |                                ^
   drivers/net/ethernet/sfc/ef100_nic.c:542:10: note: in expansion of macro 'EF100_COMMON_STAT_MASK'
     542 |  *mask = EF100_COMMON_STAT_MASK;
         |          ^~~~~~~~~~~~~~~~~~~~~~
   drivers/net/ethernet/sfc/ef100_nic.c: At top level:
   drivers/net/ethernet/sfc/ef100_nic.c:706:3: error: 'const struct efx_nic_type' has no member named 'filter_rfs_expire_one'
     706 |  .filter_rfs_expire_one = efx_mcdi_filter_rfs_expire_one,
         |   ^~~~~~~~~~~~~~~~~~~~~
   drivers/net/ethernet/sfc/ef100_nic.c:706:27: error: initialization of 'int (*)(struct efx_nic *)' from incompatible pointer type 'bool (*)(struct efx_nic *, u32,  unsigned int)' {aka '_Bool (*)(struct efx_nic *, unsigned int,  unsigned int)'} [-Werror=incompatible-pointer-types]
     706 |  .filter_rfs_expire_one = efx_mcdi_filter_rfs_expire_one,
         |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/net/ethernet/sfc/ef100_nic.c:706:27: note: (near initialization for 'ef100_pf_nic_type.mtd_probe')
   cc1: some warnings being treated as errors

vim +456 drivers/net/ethernet/sfc/ef100_nic.c

   455	
 > 456	#define EF100_COMMON_STAT_MASK ((1ULL << EF100_STAT_port_tx_bytes) |		\
   457					(1ULL << EF100_STAT_port_tx_packets) |		\
   458					(1ULL << EF100_STAT_port_tx_pause) |		\
   459					(1ULL << EF100_STAT_port_tx_unicast) |		\
   460					(1ULL << EF100_STAT_port_tx_multicast) |	\
   461					(1ULL << EF100_STAT_port_tx_broadcast) |	\
   462					(1ULL << EF100_STAT_port_tx_lt64) |		\
   463					(1ULL << EF100_STAT_port_tx_64) |		\
   464					(1ULL << EF100_STAT_port_tx_65_to_127) |	\
   465					(1ULL << EF100_STAT_port_tx_128_to_255) |	\
   466					(1ULL << EF100_STAT_port_tx_256_to_511) |	\
   467					(1ULL << EF100_STAT_port_tx_512_to_1023) |	\
   468					(1ULL << EF100_STAT_port_tx_1024_to_15xx) |	\
   469					(1ULL << EF100_STAT_port_tx_15xx_to_jumbo) |	\
   470					(1ULL << EF100_STAT_port_rx_bytes) |		\
   471					(1ULL << EF100_STAT_port_rx_packets) |		\
   472					(1ULL << EF100_STAT_port_rx_good) |		\
   473					(1ULL << EF100_STAT_port_rx_bad) |		\
   474					(1ULL << EF100_STAT_port_rx_pause) |		\
   475					(1ULL << EF100_STAT_port_rx_unicast) |		\
   476					(1ULL << EF100_STAT_port_rx_multicast) |	\
   477					(1ULL << EF100_STAT_port_rx_broadcast) |	\
   478					(1ULL << EF100_STAT_port_rx_lt64) |		\
   479					(1ULL << EF100_STAT_port_rx_64) |		\
   480					(1ULL << EF100_STAT_port_rx_65_to_127) |	\
   481					(1ULL << EF100_STAT_port_rx_128_to_255) |	\
   482					(1ULL << EF100_STAT_port_rx_256_to_511) |	\
   483					(1ULL << EF100_STAT_port_rx_512_to_1023) |	\
   484					(1ULL << EF100_STAT_port_rx_1024_to_15xx) |	\
   485					(1ULL << EF100_STAT_port_rx_15xx_to_jumbo) |	\
   486					(1ULL << EF100_STAT_port_rx_gtjumbo) |		\
   487					(1ULL << EF100_STAT_port_rx_bad_gtjumbo) |	\
   488					(1ULL << EF100_STAT_port_rx_align_error) |	\
   489					(1ULL << EF100_STAT_port_rx_length_error) |	\
   490					(1ULL << EF100_STAT_port_rx_overflow) |		\
   491					(1ULL << EF100_STAT_port_rx_nodesc_drops) |	\
   492					(1ULL << GENERIC_STAT_rx_nodesc_trunc) |	\
   493					(1ULL << GENERIC_STAT_rx_noskb_drops))
   494	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/net/ethernet/sfc/ef100_netdev.c b/drivers/net/ethernet/sfc/ef100_netdev.c
index 66ffb53e20a8..3ee000944a20 100644
--- a/drivers/net/ethernet/sfc/ef100_netdev.c
+++ b/drivers/net/ethernet/sfc/ef100_netdev.c
@@ -87,6 +87,7 @@  static int ef100_net_stop(struct net_device *net_dev)
 
 	netif_stop_queue(net_dev);
 	efx_stop_all(efx);
+	efx_mcdi_mac_fini_stats(efx);
 	efx_disable_interrupts(efx);
 	efx_clear_interrupt_affinity(efx);
 	efx_nic_fini_interrupt(efx);
@@ -158,6 +159,10 @@  static int ef100_net_open(struct net_device *net_dev)
 	 */
 	(void) efx_mcdi_poll_reboot(efx);
 
+	rc = efx_mcdi_mac_init_stats(efx);
+	if (rc)
+		goto fail;
+
 	efx_start_all(efx);
 
 	/* Link state detection is normally event-driven; we have
@@ -213,6 +218,7 @@  static const struct net_device_ops ef100_netdev_ops = {
 	.ndo_open               = ef100_net_open,
 	.ndo_stop               = ef100_net_stop,
 	.ndo_start_xmit         = ef100_hard_start_xmit,
+	.ndo_get_stats64        = efx_net_stats,
 	.ndo_validate_addr      = eth_validate_addr,
 	.ndo_set_rx_mode        = efx_set_rx_mode, /* Lookout */
 	.ndo_get_phys_port_id   = efx_get_phys_port_id,
diff --git a/drivers/net/ethernet/sfc/ef100_nic.c b/drivers/net/ethernet/sfc/ef100_nic.c
index 73867816196f..424a0a2065e4 100644
--- a/drivers/net/ethernet/sfc/ef100_nic.c
+++ b/drivers/net/ethernet/sfc/ef100_nic.c
@@ -453,6 +453,169 @@  static int ef100_reset(struct efx_nic *efx, enum reset_type reset_type)
 	return rc;
 }
 
+#define EF100_COMMON_STAT_MASK ((1ULL << EF100_STAT_port_tx_bytes) |		\
+				(1ULL << EF100_STAT_port_tx_packets) |		\
+				(1ULL << EF100_STAT_port_tx_pause) |		\
+				(1ULL << EF100_STAT_port_tx_unicast) |		\
+				(1ULL << EF100_STAT_port_tx_multicast) |	\
+				(1ULL << EF100_STAT_port_tx_broadcast) |	\
+				(1ULL << EF100_STAT_port_tx_lt64) |		\
+				(1ULL << EF100_STAT_port_tx_64) |		\
+				(1ULL << EF100_STAT_port_tx_65_to_127) |	\
+				(1ULL << EF100_STAT_port_tx_128_to_255) |	\
+				(1ULL << EF100_STAT_port_tx_256_to_511) |	\
+				(1ULL << EF100_STAT_port_tx_512_to_1023) |	\
+				(1ULL << EF100_STAT_port_tx_1024_to_15xx) |	\
+				(1ULL << EF100_STAT_port_tx_15xx_to_jumbo) |	\
+				(1ULL << EF100_STAT_port_rx_bytes) |		\
+				(1ULL << EF100_STAT_port_rx_packets) |		\
+				(1ULL << EF100_STAT_port_rx_good) |		\
+				(1ULL << EF100_STAT_port_rx_bad) |		\
+				(1ULL << EF100_STAT_port_rx_pause) |		\
+				(1ULL << EF100_STAT_port_rx_unicast) |		\
+				(1ULL << EF100_STAT_port_rx_multicast) |	\
+				(1ULL << EF100_STAT_port_rx_broadcast) |	\
+				(1ULL << EF100_STAT_port_rx_lt64) |		\
+				(1ULL << EF100_STAT_port_rx_64) |		\
+				(1ULL << EF100_STAT_port_rx_65_to_127) |	\
+				(1ULL << EF100_STAT_port_rx_128_to_255) |	\
+				(1ULL << EF100_STAT_port_rx_256_to_511) |	\
+				(1ULL << EF100_STAT_port_rx_512_to_1023) |	\
+				(1ULL << EF100_STAT_port_rx_1024_to_15xx) |	\
+				(1ULL << EF100_STAT_port_rx_15xx_to_jumbo) |	\
+				(1ULL << EF100_STAT_port_rx_gtjumbo) |		\
+				(1ULL << EF100_STAT_port_rx_bad_gtjumbo) |	\
+				(1ULL << EF100_STAT_port_rx_align_error) |	\
+				(1ULL << EF100_STAT_port_rx_length_error) |	\
+				(1ULL << EF100_STAT_port_rx_overflow) |		\
+				(1ULL << EF100_STAT_port_rx_nodesc_drops) |	\
+				(1ULL << GENERIC_STAT_rx_nodesc_trunc) |	\
+				(1ULL << GENERIC_STAT_rx_noskb_drops))
+
+#define EF100_DMA_STAT(ext_name, mcdi_name)			\
+	[EF100_STAT_ ## ext_name] =				\
+	{ #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
+
+static const struct efx_hw_stat_desc ef100_stat_desc[EF100_STAT_COUNT] = {
+	EF100_DMA_STAT(port_tx_bytes, TX_BYTES),
+	EF100_DMA_STAT(port_tx_packets, TX_PKTS),
+	EF100_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
+	EF100_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
+	EF100_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
+	EF100_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
+	EF100_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
+	EF100_DMA_STAT(port_tx_64, TX_64_PKTS),
+	EF100_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
+	EF100_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
+	EF100_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
+	EF100_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
+	EF100_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
+	EF100_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
+	EF100_DMA_STAT(port_rx_bytes, RX_BYTES),
+	EF100_DMA_STAT(port_rx_packets, RX_PKTS),
+	EF100_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
+	EF100_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
+	EF100_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
+	EF100_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
+	EF100_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
+	EF100_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
+	EF100_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
+	EF100_DMA_STAT(port_rx_64, RX_64_PKTS),
+	EF100_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
+	EF100_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
+	EF100_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
+	EF100_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
+	EF100_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
+	EF100_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
+	EF100_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
+	EF100_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
+	EF100_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
+	EF100_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
+	EF100_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
+	EF100_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
+	EFX_GENERIC_SW_STAT(rx_nodesc_trunc),
+	EFX_GENERIC_SW_STAT(rx_noskb_drops),
+};
+
+static void ef100_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
+{
+	*mask = EF100_COMMON_STAT_MASK;
+}
+
+static size_t ef100_describe_stats(struct efx_nic *efx, u8 *names)
+{
+	DECLARE_BITMAP(mask, EF100_STAT_COUNT);
+
+	ef100_get_stat_mask(efx, mask);
+	return efx_nic_describe_stats(ef100_stat_desc, EF100_STAT_COUNT,
+				      mask, names);
+}
+
+static size_t ef100_update_stats_common(struct efx_nic *efx, u64 *full_stats,
+					struct rtnl_link_stats64 *core_stats)
+{
+	struct ef100_nic_data *nic_data = efx->nic_data;
+	DECLARE_BITMAP(mask, EF100_STAT_COUNT);
+	size_t stats_count = 0, index;
+	u64 *stats = nic_data->stats;
+
+	ef100_get_stat_mask(efx, mask);
+
+	if (full_stats) {
+		for_each_set_bit(index, mask, EF100_STAT_COUNT) {
+			if (ef100_stat_desc[index].name) {
+				*full_stats++ = stats[index];
+				++stats_count;
+			}
+		}
+	}
+
+	if (!core_stats)
+		return stats_count;
+
+	core_stats->rx_packets = stats[EF100_STAT_port_rx_packets];
+	core_stats->tx_packets = stats[EF100_STAT_port_tx_packets];
+	core_stats->rx_bytes = stats[EF100_STAT_port_rx_bytes];
+	core_stats->tx_bytes = stats[EF100_STAT_port_tx_bytes];
+	core_stats->rx_dropped = stats[EF100_STAT_port_rx_nodesc_drops] +
+				 stats[GENERIC_STAT_rx_nodesc_trunc] +
+				 stats[GENERIC_STAT_rx_noskb_drops];
+	core_stats->multicast = stats[EF100_STAT_port_rx_multicast];
+	core_stats->rx_length_errors =
+			stats[EF100_STAT_port_rx_gtjumbo] +
+			stats[EF100_STAT_port_rx_length_error];
+	core_stats->rx_crc_errors = stats[EF100_STAT_port_rx_bad];
+	core_stats->rx_frame_errors =
+			stats[EF100_STAT_port_rx_align_error];
+	core_stats->rx_fifo_errors = stats[EF100_STAT_port_rx_overflow];
+	core_stats->rx_errors = (core_stats->rx_length_errors +
+				 core_stats->rx_crc_errors +
+				 core_stats->rx_frame_errors);
+
+	return stats_count;
+}
+
+static size_t ef100_update_stats(struct efx_nic *efx,
+				 u64 *full_stats,
+				 struct rtnl_link_stats64 *core_stats)
+{
+	struct ef100_nic_data *nic_data = efx->nic_data;
+	DECLARE_BITMAP(mask, EF100_STAT_COUNT);
+	__le64 *mc_stats = kmalloc(efx->num_mac_stats * sizeof(__le64),
+				   GFP_ATOMIC);
+	u64 *stats = nic_data->stats;
+
+	ef100_get_stat_mask(efx, mask);
+
+	efx_nic_copy_stats(efx, mc_stats);
+	efx_nic_update_stats(ef100_stat_desc, EF100_STAT_COUNT, mask,
+			     stats, mc_stats, false);
+
+	kfree(mc_stats);
+
+	return ef100_update_stats_common(efx, full_stats, core_stats);
+}
+
 static int efx_ef100_get_phys_port_id(struct efx_nic *efx,
 				      struct netdev_phys_item_id *ppid)
 {
@@ -555,6 +718,11 @@  const struct efx_nic_type ef100_pf_nic_type = {
 	.rx_restore_rss_contexts = efx_mcdi_rx_restore_rss_contexts,
 
 	.reconfigure_mac = ef100_reconfigure_mac,
+	.describe_stats = ef100_describe_stats,
+	.start_stats = efx_mcdi_mac_start_stats,
+	.update_stats = ef100_update_stats,
+	.pull_stats = efx_mcdi_mac_pull_stats,
+	.stop_stats = efx_mcdi_mac_stop_stats,
 
 	/* Per-type bar/size configuration not used on ef100. Location of
 	 * registers is defined by extended capabilities.
diff --git a/drivers/net/ethernet/sfc/ef100_nic.h b/drivers/net/ethernet/sfc/ef100_nic.h
index c8816bc6ae78..7c2d37490074 100644
--- a/drivers/net/ethernet/sfc/ef100_nic.h
+++ b/drivers/net/ethernet/sfc/ef100_nic.h
@@ -17,6 +17,46 @@  extern const struct efx_nic_type ef100_pf_nic_type;
 int ef100_probe_pf(struct efx_nic *efx);
 void ef100_remove(struct efx_nic *efx);
 
+enum {
+	EF100_STAT_port_tx_bytes = GENERIC_STAT_COUNT,
+	EF100_STAT_port_tx_packets,
+	EF100_STAT_port_tx_pause,
+	EF100_STAT_port_tx_unicast,
+	EF100_STAT_port_tx_multicast,
+	EF100_STAT_port_tx_broadcast,
+	EF100_STAT_port_tx_lt64,
+	EF100_STAT_port_tx_64,
+	EF100_STAT_port_tx_65_to_127,
+	EF100_STAT_port_tx_128_to_255,
+	EF100_STAT_port_tx_256_to_511,
+	EF100_STAT_port_tx_512_to_1023,
+	EF100_STAT_port_tx_1024_to_15xx,
+	EF100_STAT_port_tx_15xx_to_jumbo,
+	EF100_STAT_port_rx_bytes,
+	EF100_STAT_port_rx_packets,
+	EF100_STAT_port_rx_good,
+	EF100_STAT_port_rx_bad,
+	EF100_STAT_port_rx_pause,
+	EF100_STAT_port_rx_unicast,
+	EF100_STAT_port_rx_multicast,
+	EF100_STAT_port_rx_broadcast,
+	EF100_STAT_port_rx_lt64,
+	EF100_STAT_port_rx_64,
+	EF100_STAT_port_rx_65_to_127,
+	EF100_STAT_port_rx_128_to_255,
+	EF100_STAT_port_rx_256_to_511,
+	EF100_STAT_port_rx_512_to_1023,
+	EF100_STAT_port_rx_1024_to_15xx,
+	EF100_STAT_port_rx_15xx_to_jumbo,
+	EF100_STAT_port_rx_gtjumbo,
+	EF100_STAT_port_rx_bad_gtjumbo,
+	EF100_STAT_port_rx_align_error,
+	EF100_STAT_port_rx_length_error,
+	EF100_STAT_port_rx_overflow,
+	EF100_STAT_port_rx_nodesc_drops,
+	EF100_STAT_COUNT
+};
+
 struct ef100_nic_data {
 	struct efx_nic *efx;
 	struct efx_buffer mcdi_buf;
@@ -26,6 +66,7 @@  struct ef100_nic_data {
 	u16 warm_boot_count;
 	u8 port_id[ETH_ALEN];
 	DECLARE_BITMAP(evq_phases, EFX_MAX_CHANNELS);
+	u64 stats[EF100_STAT_COUNT];
 	u16 tso_max_hdr_len;
 	u16 tso_max_payload_num_segs;
 	u16 tso_max_frames;