Skip to content

Commit

Permalink
gianfar: Fix stats support
Browse files Browse the repository at this point in the history
This patch updates the per rx/tx queue stats.
To update the per rx queue stats a new structure has been
introduced rx_q_stats.
The per tx queue stats are updated via the netdev_queue
structure itself.

Note that we update only the tx_packtes, tx_bytes, rx_packets,
rx_bytes and rx_dropped stats on a per queue basis.

Signed-off-by: Sandeep Gopalpet <Sandeep.Kumar@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Sandeep Gopalpet authored and David S. Miller committed Dec 19, 2009
1 parent 1ccb838 commit a7f3804
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
42 changes: 36 additions & 6 deletions drivers/net/gianfar.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,36 @@ static void gfar_init_mac(struct net_device *ndev)
gfar_write(&regs->fifo_tx_starve_shutoff, priv->fifo_starve_off);
}

static struct net_device_stats *gfar_get_stats(struct net_device *dev)
{
struct gfar_private *priv = netdev_priv(dev);
struct netdev_queue *txq;
unsigned long rx_packets = 0, rx_bytes = 0, rx_dropped = 0;
unsigned long tx_packets = 0, tx_bytes = 0;
int i = 0;

for (i = 0; i < priv->num_rx_queues; i++) {
rx_packets += priv->rx_queue[i]->stats.rx_packets;
rx_bytes += priv->rx_queue[i]->stats.rx_bytes;
rx_dropped += priv->rx_queue[i]->stats.rx_dropped;
}

dev->stats.rx_packets = rx_packets;
dev->stats.rx_bytes = rx_bytes;
dev->stats.rx_dropped = rx_dropped;

for (i = 0; i < priv->num_tx_queues; i++) {
txq = netdev_get_tx_queue(dev, i);
tx_bytes += txq->tx_bytes;
tx_packets += txq->tx_packets;
}

dev->stats.tx_bytes = tx_bytes;
dev->stats.tx_packets = tx_packets;

return &dev->stats;
}

static const struct net_device_ops gfar_netdev_ops = {
.ndo_open = gfar_enet_open,
.ndo_start_xmit = gfar_start_xmit,
Expand All @@ -426,6 +456,7 @@ static const struct net_device_ops gfar_netdev_ops = {
.ndo_tx_timeout = gfar_timeout,
.ndo_do_ioctl = gfar_ioctl,
.ndo_select_queue = gfar_select_queue,
.ndo_get_stats = gfar_get_stats,
.ndo_vlan_rx_register = gfar_vlan_rx_register,
.ndo_set_mac_address = eth_mac_addr,
.ndo_validate_addr = eth_validate_addr,
Expand Down Expand Up @@ -1943,7 +1974,8 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
}

/* Update transmit stats */
dev->stats.tx_bytes += skb->len;
txq->tx_bytes += skb->len;
txq->tx_packets ++;

txbdp = txbdp_start = tx_queue->cur_tx;

Expand Down Expand Up @@ -2301,8 +2333,6 @@ static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)
tx_queue->skb_dirtytx = skb_dirtytx;
tx_queue->dirty_tx = bdp;

dev->stats.tx_packets += howmany;

return howmany;
}

Expand Down Expand Up @@ -2516,22 +2546,22 @@ int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit)
}
} else {
/* Increment the number of packets */
dev->stats.rx_packets++;
rx_queue->stats.rx_packets++;
howmany++;

if (likely(skb)) {
pkt_len = bdp->length - ETH_FCS_LEN;
/* Remove the FCS from the packet length */
skb_put(skb, pkt_len);
dev->stats.rx_bytes += pkt_len;
rx_queue->stats.rx_bytes += pkt_len;

gfar_process_frame(dev, skb, amount_pull);

} else {
if (netif_msg_rx_err(priv))
printk(KERN_WARNING
"%s: Missing skb!\n", dev->name);
dev->stats.rx_dropped++;
rx_queue->stats.rx_dropped++;
priv->extra_stats.rx_skbmissing++;
}

Expand Down
10 changes: 10 additions & 0 deletions drivers/net/gianfar.h
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,15 @@ struct gfar_priv_tx_q {
unsigned short txtime;
};

/*
* Per RX queue stats
*/
struct rx_q_stats {
unsigned long rx_packets;
unsigned long rx_bytes;
unsigned long rx_dropped;
};

/**
* struct gfar_priv_rx_q - per rx queue structure
* @rxlock: per queue rx spin lock
Expand All @@ -962,6 +971,7 @@ struct gfar_priv_rx_q {
struct rxbd8 *cur_rx;
struct net_device *dev;
struct gfar_priv_grp *grp;
struct rx_q_stats stats;
u16 skb_currx;
u16 qindex;
unsigned int rx_ring_size;
Expand Down

0 comments on commit a7f3804

Please sign in to comment.