src/dpdk/drivers/net/hinic/hinic_pmd_ethdev.c
static int
hinic_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
{
	int i, err, q_num;
	u64 rx_discards_pmd = 0;
	struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
	struct hinic_vport_stats vport_stats;
	struct hinic_rxq	*rxq = NULL;
	struct hinic_rxq_stats rxq_stats;
	struct hinic_txq	*txq = NULL;
	struct hinic_txq_stats txq_stats;

	err = hinic_get_vport_stats(nic_dev->hwdev, &vport_stats);
	if (err) {
		PMD_DRV_LOG(ERR, "Get vport stats from fw failed, nic_dev: %s",
			nic_dev->proc_dev_name);
		return err;
	}

	dev->data->rx_mbuf_alloc_failed = 0;

	/* rx queue stats */
	q_num = (nic_dev->num_rq < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
			nic_dev->num_rq : RTE_ETHDEV_QUEUE_STAT_CNTRS;
	for (i = 0; i < q_num; i++) {
		rxq = nic_dev->rxqs[i];
		hinic_rxq_get_stats(rxq, &rxq_stats);
		stats->q_ipackets[i] = rxq_stats.packets;
		stats->q_ibytes[i] = rxq_stats.bytes;
		stats->q_errors[i] = rxq_stats.rx_discards;

		stats->ierrors += rxq_stats.errors;
		rx_discards_pmd += rxq_stats.rx_discards;
		dev->data->rx_mbuf_alloc_failed += rxq_stats.rx_nombuf;
	}

	/* tx queue stats */
	q_num = (nic_dev->num_sq < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
		nic_dev->num_sq : RTE_ETHDEV_QUEUE_STAT_CNTRS;
	for (i = 0; i < q_num; i++) {
		txq = nic_dev->txqs[i];
		hinic_txq_get_stats(txq, &txq_stats);
		stats->q_opackets[i] = txq_stats.packets;
		stats->q_obytes[i] = txq_stats.bytes;
		stats->oerrors += (txq_stats.tx_busy + txq_stats.off_errs);
	}

	/* vport stats */
	stats->oerrors += vport_stats.tx_discard_vport;

	stats->imissed = vport_stats.rx_discard_vport + rx_discards_pmd;

	stats->ipackets = (vport_stats.rx_unicast_pkts_vport +
			vport_stats.rx_multicast_pkts_vport +
			vport_stats.rx_broadcast_pkts_vport -
			rx_discards_pmd);

	stats->opackets = (vport_stats.tx_unicast_pkts_vport +
			vport_stats.tx_multicast_pkts_vport +
			vport_stats.tx_broadcast_pkts_vport);

	stats->ibytes = (vport_stats.rx_unicast_bytes_vport +
			vport_stats.rx_multicast_bytes_vport +
			vport_stats.rx_broadcast_bytes_vport);

	stats->obytes = (vport_stats.tx_unicast_bytes_vport +
			vport_stats.tx_multicast_bytes_vport +
			vport_stats.tx_broadcast_bytes_vport);
	return 0;
}
/**
 * DPDK callback to get device statistics.
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 * @param stats
 *   Stats structure output buffer.
 *
 * @return
 *   0 on success and stats is filled,
 *   negative error value otherwise.
 */
DPDK callback to get device statistics.
@param dev
Pointer to Ethernet device structure.
@param stats
Stats structure output buffer.

@return
0 on success and stats is filled,
negative error value otherwise.
DPDK callback to get device statistics . @param dev Pointer to Ethernet device structure . @param stats Stats structure output buffer . @return 0 on success and stats is filled negative error value otherwise .
static int
hinic_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
{
	int i, err, q_num;
	u64 rx_discards_pmd = 0;
	struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
	struct hinic_vport_stats vport_stats;
	struct hinic_rxq	*rxq = NULL;
	struct hinic_rxq_stats rxq_stats;
	struct hinic_txq	*txq = NULL;
	struct hinic_txq_stats txq_stats;
	err = hinic_get_vport_stats(nic_dev->hwdev, &vport_stats);
	if (err) {
		PMD_DRV_LOG(ERR, "Get vport stats from fw failed, nic_dev: %s",
			nic_dev->proc_dev_name);
		return err;
	}
	dev->data->rx_mbuf_alloc_failed = 0;
	q_num = (nic_dev->num_rq < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
			nic_dev->num_rq : RTE_ETHDEV_QUEUE_STAT_CNTRS;
	for (i = 0; i < q_num; i++) {
		rxq = nic_dev->rxqs[i];
		hinic_rxq_get_stats(rxq, &rxq_stats);
		stats->q_ipackets[i] = rxq_stats.packets;
		stats->q_ibytes[i] = rxq_stats.bytes;
		stats->q_errors[i] = rxq_stats.rx_discards;
		stats->ierrors += rxq_stats.errors;
		rx_discards_pmd += rxq_stats.rx_discards;
		dev->data->rx_mbuf_alloc_failed += rxq_stats.rx_nombuf;
	}
	q_num = (nic_dev->num_sq < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
		nic_dev->num_sq : RTE_ETHDEV_QUEUE_STAT_CNTRS;
	for (i = 0; i < q_num; i++) {
		txq = nic_dev->txqs[i];
		hinic_txq_get_stats(txq, &txq_stats);
		stats->q_opackets[i] = txq_stats.packets;
		stats->q_obytes[i] = txq_stats.bytes;
		stats->oerrors += (txq_stats.tx_busy + txq_stats.off_errs);
	}
	stats->oerrors += vport_stats.tx_discard_vport;
	stats->imissed = vport_stats.rx_discard_vport + rx_discards_pmd;
	stats->ipackets = (vport_stats.rx_unicast_pkts_vport +
			vport_stats.rx_multicast_pkts_vport +
			vport_stats.rx_broadcast_pkts_vport -
			rx_discards_pmd);
	stats->opackets = (vport_stats.tx_unicast_pkts_vport +
			vport_stats.tx_multicast_pkts_vport +
			vport_stats.tx_broadcast_pkts_vport);
	stats->ibytes = (vport_stats.rx_unicast_bytes_vport +
			vport_stats.rx_multicast_bytes_vport +
			vport_stats.rx_broadcast_bytes_vport);
	stats->obytes = (vport_stats.tx_unicast_bytes_vport +
			vport_stats.tx_multicast_bytes_vport +
			vport_stats.tx_broadcast_bytes_vport);
	return 0;
}
static int hinic_dev_stats_get ( struct rte_eth_dev * dev , struct rte_eth_stats * stats ) { int i , err , q_num ; u64 rx_discards_pmd = 0 ; struct hinic_nic_dev * nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV ( dev ) ; struct hinic_vport_stats vport_stats ; struct hinic_rxq * rxq = NULL ; struct hinic_rxq_stats rxq_stats ; struct hinic_txq * txq = NULL ; struct hinic_txq_stats txq_stats ; err = hinic_get_vport_stats ( nic_dev -> hwdev , & vport_stats ) ; if ( err ) { PMD_DRV_LOG ( ERR , " " , nic_dev -> proc_dev_name ) ; return err ; } dev -> data -> rx_mbuf_alloc_failed = 0 ; q_num = ( nic_dev -> num_rq < RTE_ETHDEV_QUEUE_STAT_CNTRS ) ? nic_dev -> num_rq : RTE_ETHDEV_QUEUE_STAT_CNTRS ; for ( i = 0 ; i < q_num ; i ++ ) { rxq = nic_dev -> rxqs [ i ] ; hinic_rxq_get_stats ( rxq , & rxq_stats ) ; stats -> q_ipackets [ i ] = rxq_stats . packets ; stats -> q_ibytes [ i ] = rxq_stats . bytes ; stats -> q_errors [ i ] = rxq_stats . rx_discards ; stats -> ierrors += rxq_stats . errors ; rx_discards_pmd += rxq_stats . rx_discards ; dev -> data -> rx_mbuf_alloc_failed += rxq_stats . rx_nombuf ; } q_num = ( nic_dev -> num_sq < RTE_ETHDEV_QUEUE_STAT_CNTRS ) ? nic_dev -> num_sq : RTE_ETHDEV_QUEUE_STAT_CNTRS ; for ( i = 0 ; i < q_num ; i ++ ) { txq = nic_dev -> txqs [ i ] ; hinic_txq_get_stats ( txq , & txq_stats ) ; stats -> q_opackets [ i ] = txq_stats . packets ; stats -> q_obytes [ i ] = txq_stats . bytes ; stats -> oerrors += ( txq_stats . tx_busy + txq_stats . off_errs ) ; } stats -> oerrors += vport_stats . tx_discard_vport ; stats -> imissed = vport_stats . rx_discard_vport + rx_discards_pmd ; stats -> ipackets = ( vport_stats . rx_unicast_pkts_vport + vport_stats . rx_multicast_pkts_vport + vport_stats . rx_broadcast_pkts_vport - rx_discards_pmd ) ; stats -> opackets = ( vport_stats . tx_unicast_pkts_vport + vport_stats . tx_multicast_pkts_vport + vport_stats . tx_broadcast_pkts_vport ) ; stats -> ibytes = ( vport_stats . rx_unicast_bytes_vport + vport_stats . rx_multicast_bytes_vport + vport_stats . rx_broadcast_bytes_vport ) ; stats -> obytes = ( vport_stats . tx_unicast_bytes_vport + vport_stats . tx_multicast_bytes_vport + vport_stats . tx_broadcast_bytes_vport ) ; return 0 ; }
DPDK callback to get device statistics.
DPDK callback to get device statistics .
/* rx queue stats */ /* tx queue stats */ /* vport stats */