From ecf995a8f708078408b704d8bff2f055c6ed9b64 Mon Sep 17 00:00:00 2001 From: rakesh goyal Date: Fri, 28 Feb 2020 15:57:36 +0530 Subject: [PATCH] nvethernet: ethtool: counter for pkt_err stats got cleared MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add counter for how many times pkt_err stats got cleared using osi_clear_tx_pkt_err_statsĀ and osi_clear_rx_pkt_err_stats call. Bug 200548007 Change-Id: I3f98256306f9104ad952ff1829c48ccce41c4d4e Signed-off-by: rakesh goyal Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2304565 Tested-by: mobile promotions Reviewed-by: Srinivas Ramachandran Reviewed-by: Ashutosh Jha Reviewed-by: automaticguardword Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit --- .../net/ethernet/nvidia/nvethernet/ethtool.c | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/nvidia/nvethernet/ethtool.c b/drivers/net/ethernet/nvidia/nvethernet/ethtool.c index 29d2d403..f37742f5 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/ethtool.c +++ b/drivers/net/ethernet/nvidia/nvethernet/ethtool.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -38,6 +38,27 @@ struct ether_stats { size_t stat_offset; }; +/** + * @brief Name of pkt_err statistics, with length of name not more than + * ETH_GSTRING_LEN + */ +#define ETHER_PKT_ERR_STAT(y) \ +{ (#y), FIELD_SIZEOF(struct osi_pkt_err_stats, y), \ + offsetof(struct osi_dma_priv_data, pkt_err_stats.y)} +/** + * @brief ETHER clear pkt_err statistics + */ +static const struct ether_stats ether_cstrings_stats[] = { + /* Counter for pkt_err stats got cleared */ + ETHER_PKT_ERR_STAT(clear_tx_err), + ETHER_PKT_ERR_STAT(clear_rx_err), +}; + +/** + * @brief clear pkt_err statistics array length + */ +#define ETHER_PKT_ERR_STAT_LEN OSI_ARRAY_SIZE(ether_cstrings_stats) + /** * @brief Name of extra DMA stat, with length of name not more than ETH_GSTRING_LEN */ @@ -305,6 +326,14 @@ static void ether_get_ethtool_stats(struct net_device *dev, data[j++] = (ether_dstrings_stats[i].sizeof_stat == sizeof(u64)) ? (*(u64 *)p) : (*(u32 *)p); } + + for (i = 0; i < ETHER_PKT_ERR_STAT_LEN; i++) { + char *p = (char *)osi_dma + + ether_cstrings_stats[i].stat_offset; + + data[j++] = (ether_cstrings_stats[i].sizeof_stat == + sizeof(u64)) ? (*(u64 *)p) : (*(u32 *)p); + } } } @@ -343,6 +372,11 @@ static int ether_get_sset_count(struct net_device *dev, int sset) } else { len += ETHER_EXTRA_DMA_STAT_LEN; } + if (INT_MAX - ETHER_PKT_ERR_STAT_LEN < len) { + /* do nothing */ + } else { + len += ETHER_PKT_ERR_STAT_LEN; + } } else { len = -EOPNOTSUPP; } @@ -396,6 +430,14 @@ static void ether_get_strings(struct net_device *dev, u32 stringset, u8 *data) } p += ETH_GSTRING_LEN; } + for (i = 0; i < ETHER_PKT_ERR_STAT_LEN; i++) { + str = (u8 *)ether_cstrings_stats[i].stat_string; + if (memcpy(p, str, ETH_GSTRING_LEN) == + OSI_NULL) { + return; + } + p += ETH_GSTRING_LEN; + } } } else { dev_err(pdata->dev, "%s() Unsupported stringset\n", __func__);