src/dpdk/drivers/net/cxgbe/base/t4_hw.c
void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p)
{
	u32 bgmap = t4_get_mps_bg_map(adap, idx);
	u32 stat_ctl = t4_read_reg(adap, A_MPS_STAT_CTL);

#define GET_STAT(name) \
	t4_read_reg64(adap, \
		      (is_t4(adap->params.chip) ? \
		       PORT_REG(idx, A_MPS_PORT_STAT_##name##_L) :\
		       T5_PORT_REG(idx, A_MPS_PORT_STAT_##name##_L)))
#define GET_STAT_COM(name) t4_read_reg64(adap, A_MPS_STAT_##name##_L)

	p->tx_octets           = GET_STAT(TX_PORT_BYTES);
	p->tx_frames           = GET_STAT(TX_PORT_FRAMES);
	p->tx_bcast_frames     = GET_STAT(TX_PORT_BCAST);
	p->tx_mcast_frames     = GET_STAT(TX_PORT_MCAST);
	p->tx_ucast_frames     = GET_STAT(TX_PORT_UCAST);
	p->tx_error_frames     = GET_STAT(TX_PORT_ERROR);
	p->tx_frames_64        = GET_STAT(TX_PORT_64B);
	p->tx_frames_65_127    = GET_STAT(TX_PORT_65B_127B);
	p->tx_frames_128_255   = GET_STAT(TX_PORT_128B_255B);
	p->tx_frames_256_511   = GET_STAT(TX_PORT_256B_511B);
	p->tx_frames_512_1023  = GET_STAT(TX_PORT_512B_1023B);
	p->tx_frames_1024_1518 = GET_STAT(TX_PORT_1024B_1518B);
	p->tx_frames_1519_max  = GET_STAT(TX_PORT_1519B_MAX);
	p->tx_drop             = GET_STAT(TX_PORT_DROP);
	p->tx_pause            = GET_STAT(TX_PORT_PAUSE);
	p->tx_ppp0             = GET_STAT(TX_PORT_PPP0);
	p->tx_ppp1             = GET_STAT(TX_PORT_PPP1);
	p->tx_ppp2             = GET_STAT(TX_PORT_PPP2);
	p->tx_ppp3             = GET_STAT(TX_PORT_PPP3);
	p->tx_ppp4             = GET_STAT(TX_PORT_PPP4);
	p->tx_ppp5             = GET_STAT(TX_PORT_PPP5);
	p->tx_ppp6             = GET_STAT(TX_PORT_PPP6);
	p->tx_ppp7             = GET_STAT(TX_PORT_PPP7);

	if (CHELSIO_CHIP_VERSION(adap->params.chip) >= CHELSIO_T5) {
		if (stat_ctl & F_COUNTPAUSESTATTX) {
			p->tx_frames -= p->tx_pause;
			p->tx_octets -= p->tx_pause * 64;
		}
		if (stat_ctl & F_COUNTPAUSEMCTX)
			p->tx_mcast_frames -= p->tx_pause;
	}

	p->rx_octets           = GET_STAT(RX_PORT_BYTES);
	p->rx_frames           = GET_STAT(RX_PORT_FRAMES);
	p->rx_bcast_frames     = GET_STAT(RX_PORT_BCAST);
	p->rx_mcast_frames     = GET_STAT(RX_PORT_MCAST);
	p->rx_ucast_frames     = GET_STAT(RX_PORT_UCAST);
	p->rx_too_long         = GET_STAT(RX_PORT_MTU_ERROR);
	p->rx_jabber           = GET_STAT(RX_PORT_MTU_CRC_ERROR);
	p->rx_fcs_err          = GET_STAT(RX_PORT_CRC_ERROR);
	p->rx_len_err          = GET_STAT(RX_PORT_LEN_ERROR);
	p->rx_symbol_err       = GET_STAT(RX_PORT_SYM_ERROR);
	p->rx_runt             = GET_STAT(RX_PORT_LESS_64B);
	p->rx_frames_64        = GET_STAT(RX_PORT_64B);
	p->rx_frames_65_127    = GET_STAT(RX_PORT_65B_127B);
	p->rx_frames_128_255   = GET_STAT(RX_PORT_128B_255B);
	p->rx_frames_256_511   = GET_STAT(RX_PORT_256B_511B);
	p->rx_frames_512_1023  = GET_STAT(RX_PORT_512B_1023B);
	p->rx_frames_1024_1518 = GET_STAT(RX_PORT_1024B_1518B);
	p->rx_frames_1519_max  = GET_STAT(RX_PORT_1519B_MAX);
	p->rx_pause            = GET_STAT(RX_PORT_PAUSE);
	p->rx_ppp0             = GET_STAT(RX_PORT_PPP0);
	p->rx_ppp1             = GET_STAT(RX_PORT_PPP1);
	p->rx_ppp2             = GET_STAT(RX_PORT_PPP2);
	p->rx_ppp3             = GET_STAT(RX_PORT_PPP3);
	p->rx_ppp4             = GET_STAT(RX_PORT_PPP4);
	p->rx_ppp5             = GET_STAT(RX_PORT_PPP5);
	p->rx_ppp6             = GET_STAT(RX_PORT_PPP6);
	p->rx_ppp7             = GET_STAT(RX_PORT_PPP7);

	if (CHELSIO_CHIP_VERSION(adap->params.chip) >= CHELSIO_T5) {
		if (stat_ctl & F_COUNTPAUSESTATRX) {
			p->rx_frames -= p->rx_pause;
			p->rx_octets -= p->rx_pause * 64;
		}
		if (stat_ctl & F_COUNTPAUSEMCRX)
			p->rx_mcast_frames -= p->rx_pause;
	}

	p->rx_ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_DROP_FRAME) : 0;
	p->rx_ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_DROP_FRAME) : 0;
	p->rx_ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_DROP_FRAME) : 0;
	p->rx_ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_DROP_FRAME) : 0;
	p->rx_trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_TRUNC_FRAME) : 0;
	p->rx_trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_TRUNC_FRAME) : 0;
	p->rx_trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_TRUNC_FRAME) : 0;
	p->rx_trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_TRUNC_FRAME) : 0;

#undef GET_STAT
#undef GET_STAT_COM
}
/**
 * t4_get_port_stats - collect port statistics
 * @adap: the adapter
 * @idx: the port index
 * @p: the stats structure to fill
 *
 * Collect statistics related to the given port from HW.
 */
collect port statistics
@adap: the adapter
@idx: the port index
@p: the stats structure to fill

Collect statistics related to the given port from HW.
collect port statistics @adap : the adapter @idx : the port index @p : the stats structure to fill Collect statistics related to the given port from HW .
void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p)
{
	u32 bgmap = t4_get_mps_bg_map(adap, idx);
	u32 stat_ctl = t4_read_reg(adap, A_MPS_STAT_CTL);
#define GET_STAT(name) \
	t4_read_reg64(adap, \
		      (is_t4(adap->params.chip) ? \
		       PORT_REG(idx, A_MPS_PORT_STAT_##name##_L) :\
		       T5_PORT_REG(idx, A_MPS_PORT_STAT_##name##_L)))
#define GET_STAT_COM(name) t4_read_reg64(adap, A_MPS_STAT_##name##_L)
	p->tx_octets           = GET_STAT(TX_PORT_BYTES);
	p->tx_frames           = GET_STAT(TX_PORT_FRAMES);
	p->tx_bcast_frames     = GET_STAT(TX_PORT_BCAST);
	p->tx_mcast_frames     = GET_STAT(TX_PORT_MCAST);
	p->tx_ucast_frames     = GET_STAT(TX_PORT_UCAST);
	p->tx_error_frames     = GET_STAT(TX_PORT_ERROR);
	p->tx_frames_64        = GET_STAT(TX_PORT_64B);
	p->tx_frames_65_127    = GET_STAT(TX_PORT_65B_127B);
	p->tx_frames_128_255   = GET_STAT(TX_PORT_128B_255B);
	p->tx_frames_256_511   = GET_STAT(TX_PORT_256B_511B);
	p->tx_frames_512_1023  = GET_STAT(TX_PORT_512B_1023B);
	p->tx_frames_1024_1518 = GET_STAT(TX_PORT_1024B_1518B);
	p->tx_frames_1519_max  = GET_STAT(TX_PORT_1519B_MAX);
	p->tx_drop             = GET_STAT(TX_PORT_DROP);
	p->tx_pause            = GET_STAT(TX_PORT_PAUSE);
	p->tx_ppp0             = GET_STAT(TX_PORT_PPP0);
	p->tx_ppp1             = GET_STAT(TX_PORT_PPP1);
	p->tx_ppp2             = GET_STAT(TX_PORT_PPP2);
	p->tx_ppp3             = GET_STAT(TX_PORT_PPP3);
	p->tx_ppp4             = GET_STAT(TX_PORT_PPP4);
	p->tx_ppp5             = GET_STAT(TX_PORT_PPP5);
	p->tx_ppp6             = GET_STAT(TX_PORT_PPP6);
	p->tx_ppp7             = GET_STAT(TX_PORT_PPP7);
	if (CHELSIO_CHIP_VERSION(adap->params.chip) >= CHELSIO_T5) {
		if (stat_ctl & F_COUNTPAUSESTATTX) {
			p->tx_frames -= p->tx_pause;
			p->tx_octets -= p->tx_pause * 64;
		}
		if (stat_ctl & F_COUNTPAUSEMCTX)
			p->tx_mcast_frames -= p->tx_pause;
	}
	p->rx_octets           = GET_STAT(RX_PORT_BYTES);
	p->rx_frames           = GET_STAT(RX_PORT_FRAMES);
	p->rx_bcast_frames     = GET_STAT(RX_PORT_BCAST);
	p->rx_mcast_frames     = GET_STAT(RX_PORT_MCAST);
	p->rx_ucast_frames     = GET_STAT(RX_PORT_UCAST);
	p->rx_too_long         = GET_STAT(RX_PORT_MTU_ERROR);
	p->rx_jabber           = GET_STAT(RX_PORT_MTU_CRC_ERROR);
	p->rx_fcs_err          = GET_STAT(RX_PORT_CRC_ERROR);
	p->rx_len_err          = GET_STAT(RX_PORT_LEN_ERROR);
	p->rx_symbol_err       = GET_STAT(RX_PORT_SYM_ERROR);
	p->rx_runt             = GET_STAT(RX_PORT_LESS_64B);
	p->rx_frames_64        = GET_STAT(RX_PORT_64B);
	p->rx_frames_65_127    = GET_STAT(RX_PORT_65B_127B);
	p->rx_frames_128_255   = GET_STAT(RX_PORT_128B_255B);
	p->rx_frames_256_511   = GET_STAT(RX_PORT_256B_511B);
	p->rx_frames_512_1023  = GET_STAT(RX_PORT_512B_1023B);
	p->rx_frames_1024_1518 = GET_STAT(RX_PORT_1024B_1518B);
	p->rx_frames_1519_max  = GET_STAT(RX_PORT_1519B_MAX);
	p->rx_pause            = GET_STAT(RX_PORT_PAUSE);
	p->rx_ppp0             = GET_STAT(RX_PORT_PPP0);
	p->rx_ppp1             = GET_STAT(RX_PORT_PPP1);
	p->rx_ppp2             = GET_STAT(RX_PORT_PPP2);
	p->rx_ppp3             = GET_STAT(RX_PORT_PPP3);
	p->rx_ppp4             = GET_STAT(RX_PORT_PPP4);
	p->rx_ppp5             = GET_STAT(RX_PORT_PPP5);
	p->rx_ppp6             = GET_STAT(RX_PORT_PPP6);
	p->rx_ppp7             = GET_STAT(RX_PORT_PPP7);
	if (CHELSIO_CHIP_VERSION(adap->params.chip) >= CHELSIO_T5) {
		if (stat_ctl & F_COUNTPAUSESTATRX) {
			p->rx_frames -= p->rx_pause;
			p->rx_octets -= p->rx_pause * 64;
		}
		if (stat_ctl & F_COUNTPAUSEMCRX)
			p->rx_mcast_frames -= p->rx_pause;
	}
	p->rx_ovflow0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_DROP_FRAME) : 0;
	p->rx_ovflow1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_DROP_FRAME) : 0;
	p->rx_ovflow2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_DROP_FRAME) : 0;
	p->rx_ovflow3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_DROP_FRAME) : 0;
	p->rx_trunc0 = (bgmap & 1) ? GET_STAT_COM(RX_BG_0_MAC_TRUNC_FRAME) : 0;
	p->rx_trunc1 = (bgmap & 2) ? GET_STAT_COM(RX_BG_1_MAC_TRUNC_FRAME) : 0;
	p->rx_trunc2 = (bgmap & 4) ? GET_STAT_COM(RX_BG_2_MAC_TRUNC_FRAME) : 0;
	p->rx_trunc3 = (bgmap & 8) ? GET_STAT_COM(RX_BG_3_MAC_TRUNC_FRAME) : 0;
#undef GET_STAT
#undef GET_STAT_COM
}
void t4_get_port_stats ( struct adapter * adap , int idx , struct port_stats * p ) { u32 bgmap = t4_get_mps_bg_map ( adap , idx ) ; u32 stat_ctl = t4_read_reg ( adap , A_MPS_STAT_CTL ) ; #define GET_STAT ( name )  \
	t4_read_reg64(adap, \
		      (is_t4(adap->params.chip) ? \
		       PORT_REG(idx, A_MPS_PORT_STAT_##name##_L) :\
		       T5_PORT_REG(idx, A_MPS_PORT_STAT_##name##_L))) #define GET_STAT_COM ( name )  t4_read_reg64(adap, A_MPS_STAT_##name##_L) p -> tx_octets = GET_STAT ( TX_PORT_BYTES ) ; p -> tx_frames = GET_STAT ( TX_PORT_FRAMES ) ; p -> tx_bcast_frames = GET_STAT ( TX_PORT_BCAST ) ; p -> tx_mcast_frames = GET_STAT ( TX_PORT_MCAST ) ; p -> tx_ucast_frames = GET_STAT ( TX_PORT_UCAST ) ; p -> tx_error_frames = GET_STAT ( TX_PORT_ERROR ) ; p -> tx_frames_64 = GET_STAT ( TX_PORT_64B ) ; p -> tx_frames_65_127 = GET_STAT ( TX_PORT_65B_127B ) ; p -> tx_frames_128_255 = GET_STAT ( TX_PORT_128B_255B ) ; p -> tx_frames_256_511 = GET_STAT ( TX_PORT_256B_511B ) ; p -> tx_frames_512_1023 = GET_STAT ( TX_PORT_512B_1023B ) ; p -> tx_frames_1024_1518 = GET_STAT ( TX_PORT_1024B_1518B ) ; p -> tx_frames_1519_max = GET_STAT ( TX_PORT_1519B_MAX ) ; p -> tx_drop = GET_STAT ( TX_PORT_DROP ) ; p -> tx_pause = GET_STAT ( TX_PORT_PAUSE ) ; p -> tx_ppp0 = GET_STAT ( TX_PORT_PPP0 ) ; p -> tx_ppp1 = GET_STAT ( TX_PORT_PPP1 ) ; p -> tx_ppp2 = GET_STAT ( TX_PORT_PPP2 ) ; p -> tx_ppp3 = GET_STAT ( TX_PORT_PPP3 ) ; p -> tx_ppp4 = GET_STAT ( TX_PORT_PPP4 ) ; p -> tx_ppp5 = GET_STAT ( TX_PORT_PPP5 ) ; p -> tx_ppp6 = GET_STAT ( TX_PORT_PPP6 ) ; p -> tx_ppp7 = GET_STAT ( TX_PORT_PPP7 ) ; if ( CHELSIO_CHIP_VERSION ( adap -> params . chip ) >= CHELSIO_T5 ) { if ( stat_ctl & F_COUNTPAUSESTATTX ) { p -> tx_frames -= p -> tx_pause ; p -> tx_octets -= p -> tx_pause * 64 ; } if ( stat_ctl & F_COUNTPAUSEMCTX ) p -> tx_mcast_frames -= p -> tx_pause ; } p -> rx_octets = GET_STAT ( RX_PORT_BYTES ) ; p -> rx_frames = GET_STAT ( RX_PORT_FRAMES ) ; p -> rx_bcast_frames = GET_STAT ( RX_PORT_BCAST ) ; p -> rx_mcast_frames = GET_STAT ( RX_PORT_MCAST ) ; p -> rx_ucast_frames = GET_STAT ( RX_PORT_UCAST ) ; p -> rx_too_long = GET_STAT ( RX_PORT_MTU_ERROR ) ; p -> rx_jabber = GET_STAT ( RX_PORT_MTU_CRC_ERROR ) ; p -> rx_fcs_err = GET_STAT ( RX_PORT_CRC_ERROR ) ; p -> rx_len_err = GET_STAT ( RX_PORT_LEN_ERROR ) ; p -> rx_symbol_err = GET_STAT ( RX_PORT_SYM_ERROR ) ; p -> rx_runt = GET_STAT ( RX_PORT_LESS_64B ) ; p -> rx_frames_64 = GET_STAT ( RX_PORT_64B ) ; p -> rx_frames_65_127 = GET_STAT ( RX_PORT_65B_127B ) ; p -> rx_frames_128_255 = GET_STAT ( RX_PORT_128B_255B ) ; p -> rx_frames_256_511 = GET_STAT ( RX_PORT_256B_511B ) ; p -> rx_frames_512_1023 = GET_STAT ( RX_PORT_512B_1023B ) ; p -> rx_frames_1024_1518 = GET_STAT ( RX_PORT_1024B_1518B ) ; p -> rx_frames_1519_max = GET_STAT ( RX_PORT_1519B_MAX ) ; p -> rx_pause = GET_STAT ( RX_PORT_PAUSE ) ; p -> rx_ppp0 = GET_STAT ( RX_PORT_PPP0 ) ; p -> rx_ppp1 = GET_STAT ( RX_PORT_PPP1 ) ; p -> rx_ppp2 = GET_STAT ( RX_PORT_PPP2 ) ; p -> rx_ppp3 = GET_STAT ( RX_PORT_PPP3 ) ; p -> rx_ppp4 = GET_STAT ( RX_PORT_PPP4 ) ; p -> rx_ppp5 = GET_STAT ( RX_PORT_PPP5 ) ; p -> rx_ppp6 = GET_STAT ( RX_PORT_PPP6 ) ; p -> rx_ppp7 = GET_STAT ( RX_PORT_PPP7 ) ; if ( CHELSIO_CHIP_VERSION ( adap -> params . chip ) >= CHELSIO_T5 ) { if ( stat_ctl & F_COUNTPAUSESTATRX ) { p -> rx_frames -= p -> rx_pause ; p -> rx_octets -= p -> rx_pause * 64 ; } if ( stat_ctl & F_COUNTPAUSEMCRX ) p -> rx_mcast_frames -= p -> rx_pause ; } p -> rx_ovflow0 = ( bgmap & 1 ) ? GET_STAT_COM ( RX_BG_0_MAC_DROP_FRAME ) : 0 ; p -> rx_ovflow1 = ( bgmap & 2 ) ? GET_STAT_COM ( RX_BG_1_MAC_DROP_FRAME ) : 0 ; p -> rx_ovflow2 = ( bgmap & 4 ) ? GET_STAT_COM ( RX_BG_2_MAC_DROP_FRAME ) : 0 ; p -> rx_ovflow3 = ( bgmap & 8 ) ? GET_STAT_COM ( RX_BG_3_MAC_DROP_FRAME ) : 0 ; p -> rx_trunc0 = ( bgmap & 1 ) ? GET_STAT_COM ( RX_BG_0_MAC_TRUNC_FRAME ) : 0 ; p -> rx_trunc1 = ( bgmap & 2 ) ? GET_STAT_COM ( RX_BG_1_MAC_TRUNC_FRAME ) : 0 ; p -> rx_trunc2 = ( bgmap & 4 ) ? GET_STAT_COM ( RX_BG_2_MAC_TRUNC_FRAME ) : 0 ; p -> rx_trunc3 = ( bgmap & 8 ) ? GET_STAT_COM ( RX_BG_3_MAC_TRUNC_FRAME ) : 0 ; #undef  GET_STAT #undef  GET_STAT_COM }
t4_get_port_stats - collect port statistics
 @adap: the adapter
 @idx: the port index
 @p: the stats structure to fill
t4_get_port_stats - collect port statistics @adap : the adapter @idx : the port index @p : the stats structure to fill