aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Scherban2015-02-27 16:32:00 -0600
committerMurali Karicheri2015-03-09 16:42:14 -0500
commit428364b2077d7738c0b8a7897fe519a54b42d692 (patch)
tree23410b30b557921bc0920a1717faa0aceb0ee263
parent2f549b1ea2418bc30bbfd624b2f4fd2255fb3e82 (diff)
downloadlinux-428364b2077d7738c0b8a7897fe519a54b42d692.tar.gz
linux-428364b2077d7738c0b8a7897fe519a54b42d692.tar.xz
linux-428364b2077d7738c0b8a7897fe519a54b42d692.zip
net: keystone: store network statistics in 64 bits
Previously the network statistics were stored in 32 bit u_ints which can cause some stats to roll over after several minutes of high traffic. This implements 64 bit storage so larger numbers can be stored. Signed-off-by: Michael Scherban <m-scherban@ti.com>
-rw-r--r--drivers/net/ethernet/ti/keystone_net.h14
-rw-r--r--drivers/net/ethernet/ti/keystone_net_core.c54
2 files changed, 59 insertions, 9 deletions
diff --git a/drivers/net/ethernet/ti/keystone_net.h b/drivers/net/ethernet/ti/keystone_net.h
index bd9e6e7e326..050b7e81260 100644
--- a/drivers/net/ethernet/ti/keystone_net.h
+++ b/drivers/net/ethernet/ti/keystone_net.h
@@ -20,6 +20,7 @@
20#include <linux/netdevice.h> 20#include <linux/netdevice.h>
21#include <linux/keystone-dma.h> 21#include <linux/keystone-dma.h>
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/u64_stats_sync.h>
23 24
24/* Maximum Ethernet frame size supported by Keystone switch */ 25/* Maximum Ethernet frame size supported by Keystone switch */
25#define NETCP_MAX_FRAME_SIZE 9504 26#define NETCP_MAX_FRAME_SIZE 9504
@@ -96,6 +97,17 @@ struct netcp_addr {
96 struct list_head node; 97 struct list_head node;
97}; 98};
98 99
100struct netcp_stats {
101 u64 rx_packets;
102 u64 rx_bytes;
103 u64 tx_packets;
104 u64 tx_bytes;
105 struct u64_stats_sync syncp;
106 u32 rx_errors;
107 u32 rx_dropped;
108 u32 tx_dropped;
109};
110
99/* Flags for hw_capabilities */ 111/* Flags for hw_capabilities */
100#define CPSW_HAS_P0_TX_CRC_REMOVE BIT(0) 112#define CPSW_HAS_P0_TX_CRC_REMOVE BIT(0)
101 113
@@ -123,6 +135,8 @@ struct netcp_priv {
123 struct list_head module_head; 135 struct list_head module_head;
124 struct list_head interface_list; 136 struct list_head interface_list;
125 struct list_head addr_list; 137 struct list_head addr_list;
138 /* 64-bit netcp stats */
139 struct netcp_stats stats;
126 140
127 /* PktDMA configuration data */ 141 /* PktDMA configuration data */
128 u32 rx_queue_depths[KEYSTONE_QUEUES_PER_CHAN]; 142 u32 rx_queue_depths[KEYSTONE_QUEUES_PER_CHAN];
diff --git a/drivers/net/ethernet/ti/keystone_net_core.c b/drivers/net/ethernet/ti/keystone_net_core.c
index 6bfe350cb65..ae5098aa09c 100644
--- a/drivers/net/ethernet/ti/keystone_net_core.c
+++ b/drivers/net/ethernet/ti/keystone_net_core.c
@@ -664,6 +664,7 @@ static void netcp_rx_complete(void *data)
664{ 664{
665 struct netcp_packet *p_info = data; 665 struct netcp_packet *p_info = data;
666 struct netcp_priv *netcp = p_info->netcp; 666 struct netcp_priv *netcp = p_info->netcp;
667 struct netcp_stats *rx_stats = &netcp->stats;
667 struct sk_buff *skb; 668 struct sk_buff *skb;
668 struct scatterlist *sg; 669 struct scatterlist *sg;
669 enum dma_status status; 670 enum dma_status status;
@@ -729,7 +730,7 @@ static void netcp_rx_complete(void *data)
729 p_info, status, netcp_rx_state_str(netcp)); 730 p_info, status, netcp_rx_state_str(netcp));
730 dev_kfree_skb(skb); 731 dev_kfree_skb(skb);
731 kmem_cache_free(netcp_pinfo_cache, p_info); 732 kmem_cache_free(netcp_pinfo_cache, p_info);
732 netcp->ndev->stats.rx_dropped++; 733 rx_stats->rx_dropped++;
733 return; 734 return;
734 } 735 }
735 736
@@ -739,7 +740,7 @@ static void netcp_rx_complete(void *data)
739 p_info, status, netcp_rx_state_str(netcp)); 740 p_info, status, netcp_rx_state_str(netcp));
740 dev_kfree_skb(skb); 741 dev_kfree_skb(skb);
741 kmem_cache_free(netcp_pinfo_cache, p_info); 742 kmem_cache_free(netcp_pinfo_cache, p_info);
742 netcp->ndev->stats.rx_errors++; 743 rx_stats->rx_errors++;
743 return; 744 return;
744 } 745 }
745 746
@@ -747,7 +748,7 @@ static void netcp_rx_complete(void *data)
747 dev_warn(netcp->dev, "receive: zero length packet\n"); 748 dev_warn(netcp->dev, "receive: zero length packet\n");
748 dev_kfree_skb(skb); 749 dev_kfree_skb(skb);
749 kmem_cache_free(netcp_pinfo_cache, p_info); 750 kmem_cache_free(netcp_pinfo_cache, p_info);
750 netcp->ndev->stats.rx_errors++; 751 rx_stats->rx_errors++;
751 return; 752 return;
752 } 753 }
753 754
@@ -779,8 +780,10 @@ static void netcp_rx_complete(void *data)
779 } 780 }
780 rcu_read_unlock(); 781 rcu_read_unlock();
781 782
782 netcp->ndev->stats.rx_packets++; 783 u64_stats_update_begin(&rx_stats->syncp);
783 netcp->ndev->stats.rx_bytes += skb->len; 784 rx_stats->rx_packets++;
785 rx_stats->rx_bytes += skb->len;
786 u64_stats_update_end(&rx_stats->syncp);
784 787
785 kmem_cache_free(netcp_pinfo_cache, p_info); 788 kmem_cache_free(netcp_pinfo_cache, p_info);
786 789
@@ -1178,6 +1181,7 @@ static void netcp_tx_notify(struct dma_chan *chan, void *arg)
1178static int netcp_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev) 1181static int netcp_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1179{ 1182{
1180 struct netcp_priv *netcp = netdev_priv(ndev); 1183 struct netcp_priv *netcp = netdev_priv(ndev);
1184 struct netcp_stats *tx_stats = &netcp->stats;
1181 struct dma_async_tx_descriptor *desc; 1185 struct dma_async_tx_descriptor *desc;
1182 struct netcp_tx_pipe *tx_pipe; 1186 struct netcp_tx_pipe *tx_pipe;
1183 struct netcp_hook_list *tx_hook; 1187 struct netcp_hook_list *tx_hook;
@@ -1189,8 +1193,10 @@ static int netcp_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1189 int poll_count; 1193 int poll_count;
1190 int ret = 0; 1194 int ret = 0;
1191 1195
1192 ndev->stats.tx_packets++; 1196 u64_stats_update_begin(&tx_stats->syncp);
1193 ndev->stats.tx_bytes += skb->len; 1197 tx_stats->tx_packets++;
1198 tx_stats->tx_bytes += skb->len;
1199 u64_stats_update_end(&tx_stats->syncp);
1194 1200
1195 p_info.netcp = netcp; 1201 p_info.netcp = netcp;
1196 p_info.skb = skb; 1202 p_info.skb = skb;
@@ -1236,7 +1242,7 @@ static int netcp_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1236 /* If we get here, the skb has already been dropped */ 1242 /* If we get here, the skb has already been dropped */
1237 dev_warn(netcp->dev, "padding failed (%d), " 1243 dev_warn(netcp->dev, "padding failed (%d), "
1238 "packet dropped\n", ret); 1244 "packet dropped\n", ret);
1239 ndev->stats.tx_dropped++; 1245 tx_stats->tx_dropped++;
1240 return ret; 1246 return ret;
1241 } 1247 }
1242 skb->len = NETCP_MIN_PACKET_SIZE; 1248 skb->len = NETCP_MIN_PACKET_SIZE;
@@ -1309,7 +1315,7 @@ static int netcp_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1309 1315
1310drop: 1316drop:
1311 atomic_add(real_sg_ents, &tx_pipe->dma_poll_count); 1317 atomic_add(real_sg_ents, &tx_pipe->dma_poll_count);
1312 ndev->stats.tx_dropped++; 1318 tx_stats->tx_dropped++;
1313 dev_kfree_skb(skb); 1319 dev_kfree_skb(skb);
1314 return ret; 1320 return ret;
1315} 1321}
@@ -1722,6 +1728,35 @@ static int netcp_ndo_ioctl(struct net_device *ndev,
1722 return (ret == 0) ? 0 : err; 1728 return (ret == 0) ? 0 : err;
1723} 1729}
1724 1730
1731static struct rtnl_link_stats64 *
1732netcp_get_stats(struct net_device *ndev, struct rtnl_link_stats64 *stats)
1733{
1734 struct netcp_priv *netcp = netdev_priv(ndev);
1735 struct netcp_stats *p = &netcp->stats;
1736
1737 u64 rxpackets, rxbytes, txpackets, txbytes;
1738 unsigned int start;
1739 do {
1740 start = u64_stats_fetch_begin_bh(&p->syncp);
1741 rxpackets = p->rx_packets;
1742 rxbytes = p->rx_bytes;
1743 txpackets = p->tx_packets;
1744 txbytes = p->tx_bytes;
1745 } while (u64_stats_fetch_retry_bh(&p->syncp, start));
1746
1747 stats->rx_packets = rxpackets;
1748 stats->rx_bytes = rxbytes;
1749 stats->tx_packets = txpackets;
1750 stats->tx_bytes = txbytes;
1751
1752 /* The following are stored as 32 bit */
1753 stats->rx_errors = p->rx_errors;
1754 stats->rx_dropped = p->rx_dropped;
1755 stats->tx_dropped = p->tx_dropped;
1756
1757 return stats;
1758}
1759
1725static int netcp_ndo_change_mtu(struct net_device *ndev, int new_mtu) 1760static int netcp_ndo_change_mtu(struct net_device *ndev, int new_mtu)
1726{ 1761{
1727 struct netcp_priv *netcp = netdev_priv(ndev); 1762 struct netcp_priv *netcp = netdev_priv(ndev);
@@ -1911,6 +1946,7 @@ static const struct net_device_ops netcp_netdev_ops = {
1911 .ndo_start_xmit = netcp_ndo_start_xmit, 1946 .ndo_start_xmit = netcp_ndo_start_xmit,
1912 .ndo_set_rx_mode = netcp_set_rx_mode, 1947 .ndo_set_rx_mode = netcp_set_rx_mode,
1913 .ndo_do_ioctl = netcp_ndo_ioctl, 1948 .ndo_do_ioctl = netcp_ndo_ioctl,
1949 .ndo_get_stats64 = netcp_get_stats,
1914 .ndo_change_mtu = netcp_ndo_change_mtu, 1950 .ndo_change_mtu = netcp_ndo_change_mtu,
1915 .ndo_set_mac_address = eth_mac_addr, 1951 .ndo_set_mac_address = eth_mac_addr,
1916 .ndo_validate_addr = eth_validate_addr, 1952 .ndo_validate_addr = eth_validate_addr,