FreeBSD/sys/dev/cxgb/common/cxgb_xgmac.c
/**
 *	t3_mac_update_stats - accumulate MAC statistics
 *	@mac: the MAC handle
 *
 *	This function is called periodically to accumulate the current values
 *	of the RMON counters into the port statistics.  Since the packet
 *	counters are only 32 bits they can overflow in ~286 secs at 10G, so the
 *	function should be called more frequently than that.  The byte counters
 *	are 45-bit wide, they would overflow in ~7.8 hours.
 */
accumulate MAC statistics
@mac: the MAC handle

This function is called periodically to accumulate the current values
of the RMON counters into the port statistics.  Since the packet
counters are only 32 bits they can overflow in ~286 secs at 10G, so the
function should be called more frequently than that.  The byte counters
are 45-bit wide, they would overflow in ~7.8 hours.
accumulate MAC statistics @mac : the MAC handle This function is called periodically to accumulate the current values of the RMON counters into the port statistics . Since the packet counters are only 32 bits they can overflow in ~286 secs at 10G so the function should be called more frequently than that . The byte counters are 45 - bit wide they would overflow in ~7 . 8 hours .
const struct mac_stats *t3_mac_update_stats(struct cmac *mac)
{
#define RMON_READ(mac, addr) t3_read_reg(mac->adapter, addr + mac->offset)
#define RMON_UPDATE(mac, name, reg) \
	(mac)->stats.name += (u64)RMON_READ(mac, A_XGM_STAT_##reg)
#define RMON_UPDATE64(mac, name, reg_lo, reg_hi) \
	(mac)->stats.name += RMON_READ(mac, A_XGM_STAT_##reg_lo) + \
			     ((u64)RMON_READ(mac, A_XGM_STAT_##reg_hi) << 32)
	u32 v, lo;
	if (mac->multiport)
		return t3_vsc7323_update_stats(mac);
	RMON_UPDATE64(mac, rx_octets, RX_BYTES_LOW, RX_BYTES_HIGH);
	RMON_UPDATE64(mac, rx_frames, RX_FRAMES_LOW, RX_FRAMES_HIGH);
	RMON_UPDATE(mac, rx_mcast_frames, RX_MCAST_FRAMES);
	RMON_UPDATE(mac, rx_bcast_frames, RX_BCAST_FRAMES);
	RMON_UPDATE(mac, rx_fcs_errs, RX_CRC_ERR_FRAMES);
	RMON_UPDATE(mac, rx_pause, RX_PAUSE_FRAMES);
	RMON_UPDATE(mac, rx_jabber, RX_JABBER_FRAMES);
	RMON_UPDATE(mac, rx_short, RX_SHORT_FRAMES);
	RMON_UPDATE(mac, rx_symbol_errs, RX_SYM_CODE_ERR_FRAMES);
	RMON_UPDATE(mac, rx_too_long, RX_OVERSIZE_FRAMES);
	v = RMON_READ(mac, A_XGM_RX_MAX_PKT_SIZE_ERR_CNT);
	if (mac->adapter->params.rev == T3_REV_B2)
		v &= 0x7fffffff;
	mac->stats.rx_too_long += v;
	RMON_UPDATE(mac, rx_frames_64,        RX_64B_FRAMES);
	RMON_UPDATE(mac, rx_frames_65_127,    RX_65_127B_FRAMES);
	RMON_UPDATE(mac, rx_frames_128_255,   RX_128_255B_FRAMES);
	RMON_UPDATE(mac, rx_frames_256_511,   RX_256_511B_FRAMES);
	RMON_UPDATE(mac, rx_frames_512_1023,  RX_512_1023B_FRAMES);
	RMON_UPDATE(mac, rx_frames_1024_1518, RX_1024_1518B_FRAMES);
	RMON_UPDATE(mac, rx_frames_1519_max,  RX_1519_MAXB_FRAMES);
	RMON_UPDATE64(mac, tx_octets, TX_BYTE_LOW, TX_BYTE_HIGH);
	RMON_UPDATE64(mac, tx_frames, TX_FRAME_LOW, TX_FRAME_HIGH);
	RMON_UPDATE(mac, tx_mcast_frames, TX_MCAST);
	RMON_UPDATE(mac, tx_bcast_frames, TX_BCAST);
	RMON_UPDATE(mac, tx_pause, TX_PAUSE);
	RMON_UPDATE(mac, tx_underrun, TX_ERR_FRAMES);
	RMON_UPDATE(mac, tx_frames_64,        TX_64B_FRAMES);
	RMON_UPDATE(mac, tx_frames_65_127,    TX_65_127B_FRAMES);
	RMON_UPDATE(mac, tx_frames_128_255,   TX_128_255B_FRAMES);
	RMON_UPDATE(mac, tx_frames_256_511,   TX_256_511B_FRAMES);
	RMON_UPDATE(mac, tx_frames_512_1023,  TX_512_1023B_FRAMES);
	RMON_UPDATE(mac, tx_frames_1024_1518, TX_1024_1518B_FRAMES);
	RMON_UPDATE(mac, tx_frames_1519_max,  TX_1519_MAXB_FRAMES);
	t3_write_reg(mac->adapter, A_TP_MIB_INDEX, mac->offset ? 51 : 50);
	v = t3_read_reg(mac->adapter, A_TP_MIB_RDATA);
	lo = (u32)mac->stats.rx_cong_drops;
	mac->stats.rx_cong_drops += (u64)(v - lo);
	return &mac->stats;
}
const struct mac_stats * t3_mac_update_stats ( struct cmac * mac ) { #define RMON_READ ( mac , addr )  t3_read_reg(mac->adapter, addr + mac->offset) #define RMON_UPDATE ( mac , name , reg )  \
	(mac)->stats.name += (u64)RMON_READ(mac, A_XGM_STAT_##reg) #define RMON_UPDATE64 ( mac , name , reg_lo , reg_hi )  \
	(mac)->stats.name += RMON_READ(mac, A_XGM_STAT_##reg_lo) + \
			     ((u64)RMON_READ(mac, A_XGM_STAT_##reg_hi) << 32) u32 v , lo ; if ( mac -> multiport ) return t3_vsc7323_update_stats ( mac ) ; RMON_UPDATE64 ( mac , rx_octets , RX_BYTES_LOW , RX_BYTES_HIGH ) ; RMON_UPDATE64 ( mac , rx_frames , RX_FRAMES_LOW , RX_FRAMES_HIGH ) ; RMON_UPDATE ( mac , rx_mcast_frames , RX_MCAST_FRAMES ) ; RMON_UPDATE ( mac , rx_bcast_frames , RX_BCAST_FRAMES ) ; RMON_UPDATE ( mac , rx_fcs_errs , RX_CRC_ERR_FRAMES ) ; RMON_UPDATE ( mac , rx_pause , RX_PAUSE_FRAMES ) ; RMON_UPDATE ( mac , rx_jabber , RX_JABBER_FRAMES ) ; RMON_UPDATE ( mac , rx_short , RX_SHORT_FRAMES ) ; RMON_UPDATE ( mac , rx_symbol_errs , RX_SYM_CODE_ERR_FRAMES ) ; RMON_UPDATE ( mac , rx_too_long , RX_OVERSIZE_FRAMES ) ; v = RMON_READ ( mac , A_XGM_RX_MAX_PKT_SIZE_ERR_CNT ) ; if ( mac -> adapter -> params . rev == T3_REV_B2 ) v &= 0x7fffffff ; mac -> stats . rx_too_long += v ; RMON_UPDATE ( mac , rx_frames_64 , RX_64B_FRAMES ) ; RMON_UPDATE ( mac , rx_frames_65_127 , RX_65_127B_FRAMES ) ; RMON_UPDATE ( mac , rx_frames_128_255 , RX_128_255B_FRAMES ) ; RMON_UPDATE ( mac , rx_frames_256_511 , RX_256_511B_FRAMES ) ; RMON_UPDATE ( mac , rx_frames_512_1023 , RX_512_1023B_FRAMES ) ; RMON_UPDATE ( mac , rx_frames_1024_1518 , RX_1024_1518B_FRAMES ) ; RMON_UPDATE ( mac , rx_frames_1519_max , RX_1519_MAXB_FRAMES ) ; RMON_UPDATE64 ( mac , tx_octets , TX_BYTE_LOW , TX_BYTE_HIGH ) ; RMON_UPDATE64 ( mac , tx_frames , TX_FRAME_LOW , TX_FRAME_HIGH ) ; RMON_UPDATE ( mac , tx_mcast_frames , TX_MCAST ) ; RMON_UPDATE ( mac , tx_bcast_frames , TX_BCAST ) ; RMON_UPDATE ( mac , tx_pause , TX_PAUSE ) ; RMON_UPDATE ( mac , tx_underrun , TX_ERR_FRAMES ) ; RMON_UPDATE ( mac , tx_frames_64 , TX_64B_FRAMES ) ; RMON_UPDATE ( mac , tx_frames_65_127 , TX_65_127B_FRAMES ) ; RMON_UPDATE ( mac , tx_frames_128_255 , TX_128_255B_FRAMES ) ; RMON_UPDATE ( mac , tx_frames_256_511 , TX_256_511B_FRAMES ) ; RMON_UPDATE ( mac , tx_frames_512_1023 , TX_512_1023B_FRAMES ) ; RMON_UPDATE ( mac , tx_frames_1024_1518 , TX_1024_1518B_FRAMES ) ; RMON_UPDATE ( mac , tx_frames_1519_max , TX_1519_MAXB_FRAMES ) ; t3_write_reg ( mac -> adapter , A_TP_MIB_INDEX , mac -> offset ? 51 : 50 ) ; v = t3_read_reg ( mac -> adapter , A_TP_MIB_RDATA ) ; lo = ( u32 ) mac -> stats . rx_cong_drops ; mac -> stats . rx_cong_drops += ( u64 ) ( v - lo ) ; return & mac -> stats ; }
t3_mac_update_stats - accumulate MAC statistics
      @mac: the MAC handle
t3_mac_update_stats - accumulate MAC statistics @mac : the MAC handle
/* This counts error frames in general (bad FCS, underrun, etc). */ /* The next stat isn't clear-on-read. */