net/bnxt: support xstats get by id

This patch adds support for xstats_get_by_id/xstats_get_names_by_id.

Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
This commit is contained in:
Ajit Khaparde 2017-09-28 16:43:32 -05:00 committed by Ferruh Yigit
parent 7ec39d8c52
commit 8892013668
3 changed files with 67 additions and 0 deletions

View File

@ -1569,6 +1569,8 @@ static const struct eth_dev_ops bnxt_dev_ops = {
.txq_info_get = bnxt_txq_info_get_op, .txq_info_get = bnxt_txq_info_get_op,
.dev_led_on = bnxt_dev_led_on_op, .dev_led_on = bnxt_dev_led_on_op,
.dev_led_off = bnxt_dev_led_off_op, .dev_led_off = bnxt_dev_led_off_op,
.xstats_get_by_id = bnxt_dev_xstats_get_by_id_op,
.xstats_get_names_by_id = bnxt_dev_xstats_get_names_by_id_op,
}; };
static bool bnxt_vf_pciid(uint16_t id) static bool bnxt_vf_pciid(uint16_t id)
@ -1648,6 +1650,9 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
rte_atomic64_init(&bp->rx_mbuf_alloc_fail); rte_atomic64_init(&bp->rx_mbuf_alloc_fail);
bp->dev_stopped = 1; bp->dev_stopped = 1;
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
goto skip_init;
if (bnxt_vf_pciid(pci_dev->id.device_id)) if (bnxt_vf_pciid(pci_dev->id.device_id))
bp->flags |= BNXT_FLAG_VF; bp->flags |= BNXT_FLAG_VF;
@ -1657,7 +1662,10 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
"Board initialization failed rc: %x\n", rc); "Board initialization failed rc: %x\n", rc);
goto error; goto error;
} }
skip_init:
eth_dev->dev_ops = &bnxt_dev_ops; eth_dev->dev_ops = &bnxt_dev_ops;
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
return 0;
eth_dev->rx_pkt_burst = &bnxt_recv_pkts; eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
eth_dev->tx_pkt_burst = &bnxt_xmit_pkts; eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
@ -1882,6 +1890,9 @@ bnxt_dev_uninit(struct rte_eth_dev *eth_dev) {
struct bnxt *bp = eth_dev->data->dev_private; struct bnxt *bp = eth_dev->data->dev_private;
int rc; int rc;
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
return -EPERM;
bnxt_disable_int(bp); bnxt_disable_int(bp);
bnxt_free_int(bp); bnxt_free_int(bp);
bnxt_free_mem(bp); bnxt_free_mem(bp);

View File

@ -358,3 +358,54 @@ void bnxt_dev_xstats_reset_op(struct rte_eth_dev *eth_dev)
if (!(bp->flags & BNXT_FLAG_PORT_STATS)) if (!(bp->flags & BNXT_FLAG_PORT_STATS))
RTE_LOG(ERR, PMD, "Operation not supported\n"); RTE_LOG(ERR, PMD, "Operation not supported\n");
} }
int bnxt_dev_xstats_get_by_id_op(struct rte_eth_dev *dev, const uint64_t *ids,
uint64_t *values, unsigned int limit)
{
/* Account for the Tx drop pkts aka the Anti spoof counter */
const unsigned int stat_cnt = RTE_DIM(bnxt_rx_stats_strings) +
RTE_DIM(bnxt_tx_stats_strings) + 1;
struct rte_eth_xstat xstats[stat_cnt];
uint64_t values_copy[stat_cnt];
uint16_t i;
if (!ids)
return bnxt_dev_xstats_get_op(dev, xstats, stat_cnt);
bnxt_dev_xstats_get_by_id_op(dev, NULL, values_copy, stat_cnt);
for (i = 0; i < limit; i++) {
if (ids[i] >= stat_cnt) {
RTE_LOG(ERR, PMD, "id value isn't valid");
return -1;
}
values[i] = values_copy[ids[i]];
}
return stat_cnt;
}
int bnxt_dev_xstats_get_names_by_id_op(struct rte_eth_dev *dev,
struct rte_eth_xstat_name *xstats_names,
const uint64_t *ids, unsigned int limit)
{
/* Account for the Tx drop pkts aka the Anti spoof counter */
const unsigned int stat_cnt = RTE_DIM(bnxt_rx_stats_strings) +
RTE_DIM(bnxt_tx_stats_strings) + 1;
struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
uint16_t i;
if (!ids)
return bnxt_dev_xstats_get_names_op(dev, xstats_names,
stat_cnt);
bnxt_dev_xstats_get_names_by_id_op(dev, xstats_names_copy, NULL,
stat_cnt);
for (i = 0; i < limit; i++) {
if (ids[i] >= stat_cnt) {
RTE_LOG(ERR, PMD, "id value isn't valid");
return -1;
}
strcpy(xstats_names[i].name,
xstats_names_copy[ids[i]].name);
}
return stat_cnt;
}

View File

@ -46,6 +46,11 @@ int bnxt_dev_xstats_get_names_op(__rte_unused struct rte_eth_dev *eth_dev,
int bnxt_dev_xstats_get_op(struct rte_eth_dev *eth_dev, int bnxt_dev_xstats_get_op(struct rte_eth_dev *eth_dev,
struct rte_eth_xstat *xstats, unsigned int n); struct rte_eth_xstat *xstats, unsigned int n);
void bnxt_dev_xstats_reset_op(struct rte_eth_dev *eth_dev); void bnxt_dev_xstats_reset_op(struct rte_eth_dev *eth_dev);
int bnxt_dev_xstats_get_by_id_op(struct rte_eth_dev *dev, const uint64_t *ids,
uint64_t *values, unsigned int limit);
int bnxt_dev_xstats_get_names_by_id_op(struct rte_eth_dev *dev,
struct rte_eth_xstat_name *xstats_names,
const uint64_t *ids, unsigned int limit);
struct bnxt_xstats_name_off { struct bnxt_xstats_name_off {
char name[RTE_ETH_XSTATS_NAME_SIZE]; char name[RTE_ETH_XSTATS_NAME_SIZE];