Skip to content

Commit

Permalink
net: xilinx: Ethtool statistics support
Browse files Browse the repository at this point in the history
Add total tx and rx packets, bytes and errors ethtool statistics
support for axiethernet dma and mcdma.

Signed-off-by: Shravya Kumbham <shravya.kumbham@xilinx.com>
Signed-off-by: Srinivas Neeli <srinivas.neeli@amd.com>
Reviewed-by: Harini Katakam <harini.katakam@xilinx.com>
Acked-by: Harini Katakam <harini.katakam@amd.com>
Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
State: pending
  • Loading branch information
Shravya Kumbham authored and michalsimek committed Jan 5, 2023
1 parent 873d9e6 commit 32dd990
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 14 deletions.
1 change: 1 addition & 0 deletions drivers/net/ethernet/xilinx/xilinx_axienet.h
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ struct axienet_dma_q {
unsigned long rx_bytes;
};

#define AXIENET_ETHTOOLS_SSTATS_LEN 6
#define AXIENET_TX_SSTATS_LEN(lp) ((lp)->num_tx_queues * 2)
#define AXIENET_RX_SSTATS_LEN(lp) ((lp)->num_rx_queues * 2)

Expand Down
96 changes: 91 additions & 5 deletions drivers/net/ethernet/xilinx/xilinx_axienet_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,19 @@ static struct xxvenet_option mrmacenet_options[] = {
{}
};

struct axienet_ethtools_stat {
const char *name;
};

static struct axienet_ethtools_stat axienet_get_ethtools_strings_stats[] = {
{ "tx_packets" },
{ "rx_packets" },
{ "tx_bytes" },
{ "rx_bytes" },
{ "tx_errors" },
{ "rx_errors" },
};

/**
* axienet_dma_bd_release - Release buffer descriptor rings
* @ndev: Pointer to the net_device structure
Expand Down Expand Up @@ -1260,6 +1273,7 @@ static int axienet_queue_xmit(struct sk_buff *skb,
*/
if (eth_skb_pad(skb)) {
ndev->stats.tx_dropped++;
ndev->stats.tx_errors++;
return NETDEV_TX_OK;
}
}
Expand Down Expand Up @@ -2566,6 +2580,80 @@ static int axienet_ethtools_get_ts_info(struct net_device *ndev,
}
#endif

/**
* axienet_ethtools_sset_count - Get number of strings that
* get_strings will write.
* @ndev: Pointer to net_device structure
* @sset: Get the set strings
*
* Return: number of strings, on success, Non-zero error value on
* failure.
*/
int axienet_ethtools_sset_count(struct net_device *ndev, int sset)
{
switch (sset) {
case ETH_SS_STATS:
#ifdef CONFIG_AXIENET_HAS_MCDMA
return axienet_sset_count(ndev, sset);
#else
return AXIENET_ETHTOOLS_SSTATS_LEN;
#endif
default:
return -EOPNOTSUPP;
}
}

/**
* axienet_ethtools_get_stats - Get the extended statistics
* about the device.
* @ndev: Pointer to net_device structure
* @stats: Pointer to ethtool_stats structure
* @data: To store the statistics values
*
* Return: None.
*/
void axienet_ethtools_get_stats(struct net_device *ndev,
struct ethtool_stats *stats,
u64 *data)
{
unsigned int i = 0;

data[i++] = ndev->stats.tx_packets;
data[i++] = ndev->stats.rx_packets;
data[i++] = ndev->stats.tx_bytes;
data[i++] = ndev->stats.rx_bytes;
data[i++] = ndev->stats.tx_errors;
data[i++] = ndev->stats.rx_missed_errors + ndev->stats.rx_frame_errors;

#ifdef CONFIG_AXIENET_HAS_MCDMA
axienet_get_stats(ndev, stats, data);
#endif
}

/**
* axienet_ethtools_strings - Set of strings that describe
* the requested objects.
* @ndev: Pointer to net_device structure
* @sset: Get the set strings
* @data: Data of Transmit and Receive statistics
*
* Return: None.
*/
void axienet_ethtools_strings(struct net_device *ndev, u32 sset, u8 *data)
{
int i;

for (i = 0; i < AXIENET_ETHTOOLS_SSTATS_LEN; i++) {
if (sset == ETH_SS_STATS)
memcpy(data + i * ETH_GSTRING_LEN,
axienet_get_ethtools_strings_stats[i].name,
ETH_GSTRING_LEN);
}
#ifdef CONFIG_AXIENET_HAS_MCDMA
axienet_strings(ndev, sset, data);
#endif
}

static const struct ethtool_ops axienet_ethtool_ops = {
.supported_coalesce_params = ETHTOOL_COALESCE_MAX_FRAMES |
ETHTOOL_COALESCE_USECS,
Expand All @@ -2582,14 +2670,12 @@ static const struct ethtool_ops axienet_ethtool_ops = {
#ifdef CONFIG_XILINX_AXI_EMAC_HWTSTAMP
.get_ts_info = axienet_ethtools_get_ts_info,
#endif
.get_sset_count = axienet_ethtools_sset_count,
.get_ethtool_stats = axienet_ethtools_get_stats,
.get_strings = axienet_ethtools_strings,
.get_link_ksettings = axienet_ethtools_get_link_ksettings,
.set_link_ksettings = axienet_ethtools_set_link_ksettings,
.nway_reset = axienet_ethtools_nway_reset,
#ifdef CONFIG_AXIENET_HAS_MCDMA
.get_sset_count = axienet_sset_count,
.get_ethtool_stats = axienet_get_stats,
.get_strings = axienet_strings,
#endif
};

#ifdef CONFIG_AXIENET_HAS_MCDMA
Expand Down
19 changes: 10 additions & 9 deletions drivers/net/ethernet/xilinx/xilinx_axienet_mcdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ void axienet_strings(struct net_device *ndev, u32 sset, u8 *data)
{
struct axienet_local *lp = netdev_priv(ndev);
struct axienet_dma_q *q;
int i, j, k = 0;
int i = AXIENET_ETHTOOLS_SSTATS_LEN, j, k = 0;

for (i = 0, j = 0; i < AXIENET_TX_SSTATS_LEN(lp);) {
for (j = 0; i < AXIENET_TX_SSTATS_LEN(lp) + AXIENET_ETHTOOLS_SSTATS_LEN;) {
if (j >= lp->num_tx_queues)
break;
q = lp->dq[j];
Expand All @@ -529,8 +529,8 @@ void axienet_strings(struct net_device *ndev, u32 sset, u8 *data)
++j;
}
k = 0;
for (j = 0; i < AXIENET_TX_SSTATS_LEN(lp) +
AXIENET_RX_SSTATS_LEN(lp);) {
for (j = 0; i < AXIENET_TX_SSTATS_LEN(lp) + AXIENET_RX_SSTATS_LEN(lp) +
AXIENET_ETHTOOLS_SSTATS_LEN;) {
if (j >= lp->num_rx_queues)
break;
q = lp->dq[j];
Expand All @@ -553,7 +553,8 @@ int axienet_sset_count(struct net_device *ndev, int sset)

switch (sset) {
case ETH_SS_STATS:
return (AXIENET_TX_SSTATS_LEN(lp) + AXIENET_RX_SSTATS_LEN(lp));
return (AXIENET_TX_SSTATS_LEN(lp) + AXIENET_RX_SSTATS_LEN(lp) +
AXIENET_ETHTOOLS_SSTATS_LEN);
default:
return -EOPNOTSUPP;
}
Expand All @@ -565,9 +566,9 @@ void axienet_get_stats(struct net_device *ndev,
{
struct axienet_local *lp = netdev_priv(ndev);
struct axienet_dma_q *q;
unsigned int i = 0, j;
unsigned int i = AXIENET_ETHTOOLS_SSTATS_LEN, j;

for (i = 0, j = 0; i < AXIENET_TX_SSTATS_LEN(lp);) {
for (j = 0; i < AXIENET_TX_SSTATS_LEN(lp) + AXIENET_ETHTOOLS_SSTATS_LEN;) {
if (j >= lp->num_tx_queues)
break;

Expand All @@ -576,8 +577,8 @@ void axienet_get_stats(struct net_device *ndev,
data[i++] = q->tx_bytes;
++j;
}
for (j = 0; i < AXIENET_TX_SSTATS_LEN(lp) +
AXIENET_RX_SSTATS_LEN(lp);) {
for (j = 0; i < AXIENET_TX_SSTATS_LEN(lp) + AXIENET_RX_SSTATS_LEN(lp) +
AXIENET_ETHTOOLS_SSTATS_LEN;) {
if (j >= lp->num_rx_queues)
break;

Expand Down

0 comments on commit 32dd990

Please sign in to comment.