From: David Ahern Date: Fri, 16 Jan 2015 21:22:29 +0000 (-0700) Subject: net: rocker: Add basic netdev counters - v2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f2bbca513c80081245ce2cb39f314ec37703afb3;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git net: rocker: Add basic netdev counters - v2 Add packet and byte counters for RX and TX paths. $ ifconfig eth1 eth1: flags=4163 mtu 1500 inet6 fe80::5054:ff:fe12:3501 prefixlen 64 scopeid 0x20 ether 52:54:00:12:35:01 txqueuelen 1000 (Ethernet) RX packets 63 bytes 15813 (15.4 KiB) RX errors 1 dropped 0 overruns 0 frame 0 TX packets 79 bytes 17991 (17.5 KiB) TX errors 7 dropped 0 overruns 0 carrier 0 collisions 0 Rx / Tx errors tested by injecting faults in qemu's hardware model for Rocker. v2: - moved counter locations to avoid potential use after free per Florian's comment Signed-off-by: David Ahern Cc: Scott Feldman Cc: Jiri Pirko Signed-off-by: Scott Feldman Acked-by: Jiri Pirko Signed-off-by: David S. Miller --- diff --git a/drivers/net/ethernet/rocker/rocker.c b/drivers/net/ethernet/rocker/rocker.c index d54781e71cd4..11f4ffcc113d 100644 --- a/drivers/net/ethernet/rocker/rocker.c +++ b/drivers/net/ethernet/rocker/rocker.c @@ -3571,6 +3571,8 @@ nest_cancel: rocker_tlv_nest_cancel(desc_info, frags); out: dev_kfree_skb(skb); + dev->stats.tx_dropped++; + return NETDEV_TX_OK; } @@ -3857,12 +3859,22 @@ static int rocker_port_poll_tx(struct napi_struct *napi, int budget) /* Cleanup tx descriptors */ while ((desc_info = rocker_desc_tail_get(&rocker_port->tx_ring))) { + struct sk_buff *skb; + err = rocker_desc_err(desc_info); if (err && net_ratelimit()) netdev_err(rocker_port->dev, "tx desc received with err %d\n", err); rocker_tx_desc_frags_unmap(rocker_port, desc_info); - dev_kfree_skb_any(rocker_desc_cookie_ptr_get(desc_info)); + + skb = rocker_desc_cookie_ptr_get(desc_info); + if (err == 0) { + rocker_port->dev->stats.tx_packets++; + rocker_port->dev->stats.tx_bytes += skb->len; + } else + rocker_port->dev->stats.tx_errors++; + + dev_kfree_skb_any(skb); credits++; } @@ -3895,6 +3907,10 @@ static int rocker_port_rx_proc(struct rocker *rocker, rx_len = rocker_tlv_get_u16(attrs[ROCKER_TLV_RX_FRAG_LEN]); skb_put(skb, rx_len); skb->protocol = eth_type_trans(skb, rocker_port->dev); + + rocker_port->dev->stats.rx_packets++; + rocker_port->dev->stats.rx_bytes += skb->len; + netif_receive_skb(skb); return rocker_dma_rx_ring_skb_alloc(rocker, rocker_port, desc_info); @@ -3928,6 +3944,9 @@ static int rocker_port_poll_rx(struct napi_struct *napi, int budget) netdev_err(rocker_port->dev, "rx processing failed with err %d\n", err); } + if (err) + rocker_port->dev->stats.rx_errors++; + rocker_desc_gen_clear(desc_info); rocker_desc_head_set(rocker, &rocker_port->rx_ring, desc_info); credits++;