linux/drivers/net/ethernet/ti/davinci_emac.c
/**
 * emac_dev_getnetstats - EMAC get statistics function
 * @ndev: The DaVinci EMAC network adapter
 *
 * Called when system wants to get statistics from the device.
 *
 * We return the statistics in net_device_stats structure pulled from emac
 */
EMAC get statistics function
@ndev: The DaVinci EMAC network adapter

Called when system wants to get statistics from the device.

We return the statistics in net_device_stats structure pulled from emac
EMAC get statistics function @ndev : The DaVinci EMAC network adapter Called when system wants to get statistics from the device . We return the statistics in net_device_stats structure pulled from emac
static struct net_device_stats *emac_dev_getnetstats(struct net_device *ndev)
{
	struct emac_priv *priv = netdev_priv(ndev);
	u32 mac_control;
	u32 stats_clear_mask;
	int err;
	err = pm_runtime_get_sync(&priv->pdev->dev);
	if (err < 0) {
		pm_runtime_put_noidle(&priv->pdev->dev);
		dev_err(&priv->pdev->dev, "%s: failed to get_sync(%d)\n",
			__func__, err);
		return &ndev->stats;
	}
	mac_control = emac_read(EMAC_MACCONTROL);
	if (mac_control & EMAC_MACCONTROL_GMIIEN)
		stats_clear_mask = EMAC_STATS_CLR_MASK;
	else
		stats_clear_mask = 0;
	ndev->stats.multicast += emac_read(EMAC_RXMCASTFRAMES);
	emac_write(EMAC_RXMCASTFRAMES, stats_clear_mask);
	ndev->stats.collisions += (emac_read(EMAC_TXCOLLISION) +
					   emac_read(EMAC_TXSINGLECOLL) +
					   emac_read(EMAC_TXMULTICOLL));
	emac_write(EMAC_TXCOLLISION, stats_clear_mask);
	emac_write(EMAC_TXSINGLECOLL, stats_clear_mask);
	emac_write(EMAC_TXMULTICOLL, stats_clear_mask);
	ndev->stats.rx_length_errors += (emac_read(EMAC_RXOVERSIZED) +
						emac_read(EMAC_RXJABBER) +
						emac_read(EMAC_RXUNDERSIZED));
	emac_write(EMAC_RXOVERSIZED, stats_clear_mask);
	emac_write(EMAC_RXJABBER, stats_clear_mask);
	emac_write(EMAC_RXUNDERSIZED, stats_clear_mask);
	ndev->stats.rx_over_errors += (emac_read(EMAC_RXSOFOVERRUNS) +
					       emac_read(EMAC_RXMOFOVERRUNS));
	emac_write(EMAC_RXSOFOVERRUNS, stats_clear_mask);
	emac_write(EMAC_RXMOFOVERRUNS, stats_clear_mask);
	ndev->stats.rx_fifo_errors += emac_read(EMAC_RXDMAOVERRUNS);
	emac_write(EMAC_RXDMAOVERRUNS, stats_clear_mask);
	ndev->stats.tx_carrier_errors +=
		emac_read(EMAC_TXCARRIERSENSE);
	emac_write(EMAC_TXCARRIERSENSE, stats_clear_mask);
	ndev->stats.tx_fifo_errors += emac_read(EMAC_TXUNDERRUN);
	emac_write(EMAC_TXUNDERRUN, stats_clear_mask);
	pm_runtime_put(&priv->pdev->dev);
	return &ndev->stats;
}
static struct net_device_stats * emac_dev_getnetstats ( struct net_device * ndev ) { struct emac_priv * priv = netdev_priv ( ndev ) ; u32 mac_control ; u32 stats_clear_mask ; int err ; err = pm_runtime_get_sync ( & priv -> pdev -> dev ) ; if ( err < 0 ) { pm_runtime_put_noidle ( & priv -> pdev -> dev ) ; dev_err ( & priv -> pdev -> dev , " \n " , __func__ , err ) ; return & ndev -> stats ; } mac_control = emac_read ( EMAC_MACCONTROL ) ; if ( mac_control & EMAC_MACCONTROL_GMIIEN ) stats_clear_mask = EMAC_STATS_CLR_MASK ; else stats_clear_mask = 0 ; ndev -> stats . multicast += emac_read ( EMAC_RXMCASTFRAMES ) ; emac_write ( EMAC_RXMCASTFRAMES , stats_clear_mask ) ; ndev -> stats . collisions += ( emac_read ( EMAC_TXCOLLISION ) + emac_read ( EMAC_TXSINGLECOLL ) + emac_read ( EMAC_TXMULTICOLL ) ) ; emac_write ( EMAC_TXCOLLISION , stats_clear_mask ) ; emac_write ( EMAC_TXSINGLECOLL , stats_clear_mask ) ; emac_write ( EMAC_TXMULTICOLL , stats_clear_mask ) ; ndev -> stats . rx_length_errors += ( emac_read ( EMAC_RXOVERSIZED ) + emac_read ( EMAC_RXJABBER ) + emac_read ( EMAC_RXUNDERSIZED ) ) ; emac_write ( EMAC_RXOVERSIZED , stats_clear_mask ) ; emac_write ( EMAC_RXJABBER , stats_clear_mask ) ; emac_write ( EMAC_RXUNDERSIZED , stats_clear_mask ) ; ndev -> stats . rx_over_errors += ( emac_read ( EMAC_RXSOFOVERRUNS ) + emac_read ( EMAC_RXMOFOVERRUNS ) ) ; emac_write ( EMAC_RXSOFOVERRUNS , stats_clear_mask ) ; emac_write ( EMAC_RXMOFOVERRUNS , stats_clear_mask ) ; ndev -> stats . rx_fifo_errors += emac_read ( EMAC_RXDMAOVERRUNS ) ; emac_write ( EMAC_RXDMAOVERRUNS , stats_clear_mask ) ; ndev -> stats . tx_carrier_errors += emac_read ( EMAC_TXCARRIERSENSE ) ; emac_write ( EMAC_TXCARRIERSENSE , stats_clear_mask ) ; ndev -> stats . tx_fifo_errors += emac_read ( EMAC_TXUNDERRUN ) ; emac_write ( EMAC_TXUNDERRUN , stats_clear_mask ) ; pm_runtime_put ( & priv -> pdev -> dev ) ; return & ndev -> stats ; }
emac_dev_getnetstats - EMAC get statistics function
 @ndev: The DaVinci EMAC network adapter
emac_dev_getnetstats - EMAC get statistics function @ndev : The DaVinci EMAC network adapter
/* update emac hardware stats and reset the registers*/