src/dpdk/drivers/net/hns3/hns3_stats.c
int
hns3_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
		    unsigned int n)
{
	struct hns3_adapter *hns = dev->data->dev_private;
	struct hns3_pf *pf = &hns->pf;
	struct hns3_hw *hw = &hns->hw;
	struct hns3_mac_stats *mac_stats = &hw->mac_stats;
	struct hns3_reset_stats *reset_stats = &hw->reset.stats;
	struct hns3_rx_bd_errors_stats *rx_err_stats;
	struct hns3_rx_queue *rxq;
	uint16_t i, j;
	char *addr;
	int count;
	int ret;

	if (xstats == NULL)
		return 0;

	count = hns3_xstats_calc_num(dev);
	if ((int)n < count)
		return count;

	count = 0;

	ret = hns3_tqp_basic_stats_get(dev, xstats, &count);
	if (ret < 0)
		return ret;

	if (!hns->is_vf) {
		/* Update Mac stats */
		ret = hns3_query_update_mac_stats(dev);
		if (ret < 0) {
			hns3_err(hw, "Update Mac stats fail : %d", ret);
			return ret;
		}

		/* Get MAC stats from hw->hw_xstats.mac_stats struct */
		for (i = 0; i < HNS3_NUM_MAC_STATS; i++) {
			addr = (char *)mac_stats + hns3_mac_strings[i].offset;
			xstats[count].value = *(uint64_t *)addr;
			xstats[count].id = count;
			count++;
		}

		for (i = 0; i < HNS3_NUM_ERROR_INT_XSTATS; i++) {
			addr = (char *)&pf->abn_int_stats +
			       hns3_error_int_stats_strings[i].offset;
			xstats[count].value = *(uint64_t *)addr;
			xstats[count].id = count;
			count++;
		}
	}

	/* Get the reset stat */
	for (i = 0; i < HNS3_NUM_RESET_XSTATS; i++) {
		addr = (char *)reset_stats + hns3_reset_stats_strings[i].offset;
		xstats[count].value = *(uint64_t *)addr;
		xstats[count].id = count;
		count++;
	}

	/* Get the Rx BD errors stats */
	for (j = 0; j < dev->data->nb_rx_queues; j++) {
		for (i = 0; i < HNS3_NUM_RX_BD_ERROR_XSTATS; i++) {
			rxq = dev->data->rx_queues[j];
			if (rxq) {
				rx_err_stats = &rxq->err_stats;
				addr = (char *)rx_err_stats +
					hns3_rx_bd_error_strings[i].offset;
				xstats[count].value = *(uint64_t *)addr;
				xstats[count].id = count;
				count++;
			}
		}
	}

	hns3_tqp_dfx_stats_get(dev, xstats, &count);
	hns3_queue_stats_get(dev, xstats, &count);

	return count;
}
/*
 * Retrieve extended(tqp | Mac) statistics of an Ethernet device.
 * @param dev
 *   Pointer to Ethernet device.
 * @praram xstats
 *   A pointer to a table of structure of type *rte_eth_xstat*
 *   to be filled with device statistics ids and values.
 *   This parameter can be set to NULL if n is 0.
 * @param n
 *   The size of the xstats array (number of elements).
 * @return
 *   0 on fail, count(The size of the statistics elements) on success.
 */
Retrieve extended(tqp | Mac) statistics of an Ethernet device.
@param dev
Pointer to Ethernet device.
@praram xstats
A pointer to a table of structure of type *rte_eth_xstat
to be filled with device statistics ids and values.
This parameter can be set to NULL if n is 0.
@param n
The size of the xstats array (number of elements).
@return
0 on fail, count(The size of the statistics elements) on success.
Retrieve extended ( tqp | Mac ) statistics of an Ethernet device . @param dev Pointer to Ethernet device . @praram xstats A pointer to a table of structure of type * rte_eth_xstat to be filled with device statistics ids and values . This parameter can be set to NULL if n is 0 . @param n The size of the xstats array ( number of elements ) . @return 0 on fail count ( The size of the statistics elements ) on success .
int
hns3_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
		    unsigned int n)
{
	struct hns3_adapter *hns = dev->data->dev_private;
	struct hns3_pf *pf = &hns->pf;
	struct hns3_hw *hw = &hns->hw;
	struct hns3_mac_stats *mac_stats = &hw->mac_stats;
	struct hns3_reset_stats *reset_stats = &hw->reset.stats;
	struct hns3_rx_bd_errors_stats *rx_err_stats;
	struct hns3_rx_queue *rxq;
	uint16_t i, j;
	char *addr;
	int count;
	int ret;
	if (xstats == NULL)
		return 0;
	count = hns3_xstats_calc_num(dev);
	if ((int)n < count)
		return count;
	count = 0;
	ret = hns3_tqp_basic_stats_get(dev, xstats, &count);
	if (ret < 0)
		return ret;
	if (!hns->is_vf) {
		ret = hns3_query_update_mac_stats(dev);
		if (ret < 0) {
			hns3_err(hw, "Update Mac stats fail : %d", ret);
			return ret;
		}
		for (i = 0; i < HNS3_NUM_MAC_STATS; i++) {
			addr = (char *)mac_stats + hns3_mac_strings[i].offset;
			xstats[count].value = *(uint64_t *)addr;
			xstats[count].id = count;
			count++;
		}
		for (i = 0; i < HNS3_NUM_ERROR_INT_XSTATS; i++) {
			addr = (char *)&pf->abn_int_stats +
			       hns3_error_int_stats_strings[i].offset;
			xstats[count].value = *(uint64_t *)addr;
			xstats[count].id = count;
			count++;
		}
	}
	for (i = 0; i < HNS3_NUM_RESET_XSTATS; i++) {
		addr = (char *)reset_stats + hns3_reset_stats_strings[i].offset;
		xstats[count].value = *(uint64_t *)addr;
		xstats[count].id = count;
		count++;
	}
	for (j = 0; j < dev->data->nb_rx_queues; j++) {
		for (i = 0; i < HNS3_NUM_RX_BD_ERROR_XSTATS; i++) {
			rxq = dev->data->rx_queues[j];
			if (rxq) {
				rx_err_stats = &rxq->err_stats;
				addr = (char *)rx_err_stats +
					hns3_rx_bd_error_strings[i].offset;
				xstats[count].value = *(uint64_t *)addr;
				xstats[count].id = count;
				count++;
			}
		}
	}
	hns3_tqp_dfx_stats_get(dev, xstats, &count);
	hns3_queue_stats_get(dev, xstats, &count);
	return count;
}
int hns3_dev_xstats_get ( struct rte_eth_dev * dev , struct rte_eth_xstat * xstats , unsigned int n ) { struct hns3_adapter * hns = dev -> data -> dev_private ; struct hns3_pf * pf = & hns -> pf ; struct hns3_hw * hw = & hns -> hw ; struct hns3_mac_stats * mac_stats = & hw -> mac_stats ; struct hns3_reset_stats * reset_stats = & hw -> reset . stats ; struct hns3_rx_bd_errors_stats * rx_err_stats ; struct hns3_rx_queue * rxq ; uint16_t i , j ; char * addr ; int count ; int ret ; if ( xstats == NULL ) return 0 ; count = hns3_xstats_calc_num ( dev ) ; if ( ( int ) n < count ) return count ; count = 0 ; ret = hns3_tqp_basic_stats_get ( dev , xstats , & count ) ; if ( ret < 0 ) return ret ; if ( ! hns -> is_vf ) { ret = hns3_query_update_mac_stats ( dev ) ; if ( ret < 0 ) { hns3_err ( hw , " " , ret ) ; return ret ; } for ( i = 0 ; i < HNS3_NUM_MAC_STATS ; i ++ ) { addr = ( char * ) mac_stats + hns3_mac_strings [ i ] . offset ; xstats [ count ] . value = * ( uint64_t * ) addr ; xstats [ count ] . id = count ; count ++ ; } for ( i = 0 ; i < HNS3_NUM_ERROR_INT_XSTATS ; i ++ ) { addr = ( char * ) & pf -> abn_int_stats + hns3_error_int_stats_strings [ i ] . offset ; xstats [ count ] . value = * ( uint64_t * ) addr ; xstats [ count ] . id = count ; count ++ ; } } for ( i = 0 ; i < HNS3_NUM_RESET_XSTATS ; i ++ ) { addr = ( char * ) reset_stats + hns3_reset_stats_strings [ i ] . offset ; xstats [ count ] . value = * ( uint64_t * ) addr ; xstats [ count ] . id = count ; count ++ ; } for ( j = 0 ; j < dev -> data -> nb_rx_queues ; j ++ ) { for ( i = 0 ; i < HNS3_NUM_RX_BD_ERROR_XSTATS ; i ++ ) { rxq = dev -> data -> rx_queues [ j ] ; if ( rxq ) { rx_err_stats = & rxq -> err_stats ; addr = ( char * ) rx_err_stats + hns3_rx_bd_error_strings [ i ] . offset ; xstats [ count ] . value = * ( uint64_t * ) addr ; xstats [ count ] . id = count ; count ++ ; } } } hns3_tqp_dfx_stats_get ( dev , xstats , & count ) ; hns3_queue_stats_get ( dev , xstats , & count ) ; return count ; }
Retrieve extended(tqp | Mac) statistics of an Ethernet device.
Retrieve extended ( tqp | Mac ) statistics of an Ethernet device .
/* Update Mac stats */ /* Get MAC stats from hw->hw_xstats.mac_stats struct */ /* Get the reset stat */ /* Get the Rx BD errors stats */