Skip to content

Commit

Permalink
ionic: Add driver stats
Browse files Browse the repository at this point in the history
Add in the detailed statistics for ethtool -S that the driver
keeps as it processes packets.  Display of the additional
debug statistics can be enabled through the ethtool priv-flags
feature.

Signed-off-by: Shannon Nelson <snelson@pensando.io>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Shannon Nelson authored and David S. Miller committed Sep 5, 2019
1 parent 1a371ea commit e470355
Show file tree
Hide file tree
Showing 5 changed files with 480 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/pensando/ionic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ obj-$(CONFIG_IONIC) := ionic.o

ionic-y := ionic_main.o ionic_bus_pci.o ionic_devlink.o ionic_dev.o \
ionic_debugfs.o ionic_lif.o ionic_rx_filter.o ionic_ethtool.o \
ionic_txrx.o
ionic_txrx.o ionic_stats.o
101 changes: 101 additions & 0 deletions drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,76 @@
#include "ionic_bus.h"
#include "ionic_lif.h"
#include "ionic_ethtool.h"
#include "ionic_stats.h"

static const char ionic_priv_flags_strings[][ETH_GSTRING_LEN] = {
#define PRIV_F_SW_DBG_STATS BIT(0)
"sw-dbg-stats",
};
#define PRIV_FLAGS_COUNT ARRAY_SIZE(ionic_priv_flags_strings)

static void ionic_get_stats_strings(struct ionic_lif *lif, u8 *buf)
{
u32 i;

for (i = 0; i < ionic_num_stats_grps; i++)
ionic_stats_groups[i].get_strings(lif, &buf);
}

static void ionic_get_stats(struct net_device *netdev,
struct ethtool_stats *stats, u64 *buf)
{
struct ionic_lif *lif;
u32 i;

lif = netdev_priv(netdev);

memset(buf, 0, stats->n_stats * sizeof(*buf));
for (i = 0; i < ionic_num_stats_grps; i++)
ionic_stats_groups[i].get_values(lif, &buf);
}

static int ionic_get_stats_count(struct ionic_lif *lif)
{
int i, num_stats = 0;

for (i = 0; i < ionic_num_stats_grps; i++)
num_stats += ionic_stats_groups[i].get_count(lif);

return num_stats;
}

static int ionic_get_sset_count(struct net_device *netdev, int sset)
{
struct ionic_lif *lif = netdev_priv(netdev);
int count = 0;

switch (sset) {
case ETH_SS_STATS:
count = ionic_get_stats_count(lif);
break;
case ETH_SS_PRIV_FLAGS:
count = PRIV_FLAGS_COUNT;
break;
}
return count;
}

static void ionic_get_strings(struct net_device *netdev,
u32 sset, u8 *buf)
{
struct ionic_lif *lif = netdev_priv(netdev);

switch (sset) {
case ETH_SS_STATS:
ionic_get_stats_strings(lif, buf);
break;
case ETH_SS_PRIV_FLAGS:
memcpy(buf, ionic_priv_flags_strings,
PRIV_FLAGS_COUNT * ETH_GSTRING_LEN);
break;
}
}

static void ionic_get_drvinfo(struct net_device *netdev,
struct ethtool_drvinfo *drvinfo)
Expand Down Expand Up @@ -386,6 +456,32 @@ static int ionic_set_channels(struct net_device *netdev,
return 0;
}

static u32 ionic_get_priv_flags(struct net_device *netdev)
{
struct ionic_lif *lif = netdev_priv(netdev);
u32 priv_flags = 0;

if (test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state))
priv_flags |= PRIV_F_SW_DBG_STATS;

return priv_flags;
}

static int ionic_set_priv_flags(struct net_device *netdev, u32 priv_flags)
{
struct ionic_lif *lif = netdev_priv(netdev);
u32 flags = lif->flags;

clear_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state);
if (priv_flags & PRIV_F_SW_DBG_STATS)
set_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state);

if (flags != lif->flags)
lif->flags = flags;

return 0;
}

static int ionic_get_module_info(struct net_device *netdev,
struct ethtool_modinfo *modinfo)

Expand Down Expand Up @@ -483,6 +579,11 @@ static const struct ethtool_ops ionic_ethtool_ops = {
.set_ringparam = ionic_set_ringparam,
.get_channels = ionic_get_channels,
.set_channels = ionic_set_channels,
.get_strings = ionic_get_strings,
.get_ethtool_stats = ionic_get_stats,
.get_sset_count = ionic_get_sset_count,
.get_priv_flags = ionic_get_priv_flags,
.set_priv_flags = ionic_set_priv_flags,
.get_module_info = ionic_get_module_info,
.get_module_eeprom = ionic_get_module_eeprom,
.get_pauseparam = ionic_get_pauseparam,
Expand Down
16 changes: 15 additions & 1 deletion drivers/net/ethernet/pensando/ionic/ionic_lif.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#define IONIC_MAX_NUM_NAPI_CNTR (NAPI_POLL_WEIGHT + 1)
#define IONIC_MAX_NUM_SG_CNTR (IONIC_TX_MAX_SG_ELEMS + 1)
#define IONIC_RX_COPYBREAK_DEFAULT 256
#define IONIC_RX_COPYBREAK_DEFAULT 256

struct ionic_tx_stats {
u64 dma_map_err;
Expand Down Expand Up @@ -106,8 +106,22 @@ struct ionic_deferred {
struct work_struct work;
};

struct ionic_lif_sw_stats {
u64 tx_packets;
u64 tx_bytes;
u64 rx_packets;
u64 rx_bytes;
u64 tx_tso;
u64 tx_no_csum;
u64 tx_csum;
u64 rx_csum_none;
u64 rx_csum_complete;
u64 rx_csum_error;
};

enum ionic_lif_state_flags {
IONIC_LIF_INITED,
IONIC_LIF_SW_DEBUG_STATS,
IONIC_LIF_UP,
IONIC_LIF_LINK_CHECK_REQUESTED,
IONIC_LIF_QUEUE_RESET,
Expand Down
Loading

0 comments on commit e470355

Please sign in to comment.