Skip to content

Commit 63a43a6

Browse files
hz-chengrleon
authored andcommitted
RDMA/erdma: Add hardware statistics support
First, we add a new command to query hardware statistics, and then implement two functions: ib_device_ops.alloc_hw_port_stats and ib_device_ops.get_hw_stats to allow rdma tool can get the statistics of erdma device. Signed-off-by: Cheng Xu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 68cf9d8 commit 63a43a6

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed

drivers/infiniband/hw/erdma/erdma_hw.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ enum CMDQ_COMMON_OPCODE {
146146
CMDQ_OPCODE_DESTROY_EQ = 1,
147147
CMDQ_OPCODE_QUERY_FW_INFO = 2,
148148
CMDQ_OPCODE_CONF_MTU = 3,
149+
CMDQ_OPCODE_GET_STATS = 4,
149150
CMDQ_OPCODE_CONF_DEVICE = 5,
150151
CMDQ_OPCODE_ALLOC_DB = 8,
151152
CMDQ_OPCODE_FREE_DB = 9,
@@ -359,6 +360,42 @@ struct erdma_cmdq_reflush_req {
359360

360361
#define ERDMA_HW_RESP_SIZE 256
361362

363+
struct erdma_cmdq_query_req {
364+
u64 hdr;
365+
u32 rsvd;
366+
u32 index;
367+
368+
u64 target_addr;
369+
u32 target_length;
370+
};
371+
372+
#define ERDMA_HW_RESP_MAGIC 0x5566
373+
374+
struct erdma_cmdq_query_resp_hdr {
375+
u16 magic;
376+
u8 ver;
377+
u8 length;
378+
379+
u32 index;
380+
u32 rsvd[2];
381+
};
382+
383+
struct erdma_cmdq_query_stats_resp {
384+
struct erdma_cmdq_query_resp_hdr hdr;
385+
386+
u64 tx_req_cnt;
387+
u64 tx_packets_cnt;
388+
u64 tx_bytes_cnt;
389+
u64 tx_drop_packets_cnt;
390+
u64 tx_bps_meter_drop_packets_cnt;
391+
u64 tx_pps_meter_drop_packets_cnt;
392+
u64 rx_packets_cnt;
393+
u64 rx_bytes_cnt;
394+
u64 rx_drop_packets_cnt;
395+
u64 rx_bps_meter_drop_packets_cnt;
396+
u64 rx_pps_meter_drop_packets_cnt;
397+
};
398+
362399
/* cap qword 0 definition */
363400
#define ERDMA_CMD_DEV_CAP_MAX_CQE_MASK GENMASK_ULL(47, 40)
364401
#define ERDMA_CMD_DEV_CAP_FLAGS_MASK GENMASK_ULL(31, 24)

drivers/infiniband/hw/erdma/erdma_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ static const struct ib_device_ops erdma_device_ops = {
468468
.driver_id = RDMA_DRIVER_ERDMA,
469469
.uverbs_abi_ver = ERDMA_ABI_VERSION,
470470

471+
.alloc_hw_port_stats = erdma_alloc_hw_port_stats,
471472
.alloc_mr = erdma_ib_alloc_mr,
472473
.alloc_pd = erdma_alloc_pd,
473474
.alloc_ucontext = erdma_alloc_ucontext,
@@ -479,6 +480,7 @@ static const struct ib_device_ops erdma_device_ops = {
479480
.destroy_cq = erdma_destroy_cq,
480481
.destroy_qp = erdma_destroy_qp,
481482
.get_dma_mr = erdma_get_dma_mr,
483+
.get_hw_stats = erdma_get_hw_stats,
482484
.get_port_immutable = erdma_get_port_immutable,
483485
.iw_accept = erdma_accept,
484486
.iw_add_ref = erdma_qp_get_ref,

drivers/infiniband/hw/erdma/erdma_verbs.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,3 +1708,93 @@ void erdma_port_event(struct erdma_dev *dev, enum ib_event_type reason)
17081708

17091709
ib_dispatch_event(&event);
17101710
}
1711+
1712+
enum counters {
1713+
ERDMA_STATS_TX_REQS_CNT,
1714+
ERDMA_STATS_TX_PACKETS_CNT,
1715+
ERDMA_STATS_TX_BYTES_CNT,
1716+
ERDMA_STATS_TX_DISABLE_DROP_CNT,
1717+
ERDMA_STATS_TX_BPS_METER_DROP_CNT,
1718+
ERDMA_STATS_TX_PPS_METER_DROP_CNT,
1719+
1720+
ERDMA_STATS_RX_PACKETS_CNT,
1721+
ERDMA_STATS_RX_BYTES_CNT,
1722+
ERDMA_STATS_RX_DISABLE_DROP_CNT,
1723+
ERDMA_STATS_RX_BPS_METER_DROP_CNT,
1724+
ERDMA_STATS_RX_PPS_METER_DROP_CNT,
1725+
1726+
ERDMA_STATS_MAX
1727+
};
1728+
1729+
static const struct rdma_stat_desc erdma_descs[] = {
1730+
[ERDMA_STATS_TX_REQS_CNT].name = "tx_reqs_cnt",
1731+
[ERDMA_STATS_TX_PACKETS_CNT].name = "tx_packets_cnt",
1732+
[ERDMA_STATS_TX_BYTES_CNT].name = "tx_bytes_cnt",
1733+
[ERDMA_STATS_TX_DISABLE_DROP_CNT].name = "tx_disable_drop_cnt",
1734+
[ERDMA_STATS_TX_BPS_METER_DROP_CNT].name = "tx_bps_limit_drop_cnt",
1735+
[ERDMA_STATS_TX_PPS_METER_DROP_CNT].name = "tx_pps_limit_drop_cnt",
1736+
[ERDMA_STATS_RX_PACKETS_CNT].name = "rx_packets_cnt",
1737+
[ERDMA_STATS_RX_BYTES_CNT].name = "rx_bytes_cnt",
1738+
[ERDMA_STATS_RX_DISABLE_DROP_CNT].name = "rx_disable_drop_cnt",
1739+
[ERDMA_STATS_RX_BPS_METER_DROP_CNT].name = "rx_bps_limit_drop_cnt",
1740+
[ERDMA_STATS_RX_PPS_METER_DROP_CNT].name = "rx_pps_limit_drop_cnt",
1741+
};
1742+
1743+
struct rdma_hw_stats *erdma_alloc_hw_port_stats(struct ib_device *device,
1744+
u32 port_num)
1745+
{
1746+
return rdma_alloc_hw_stats_struct(erdma_descs, ERDMA_STATS_MAX,
1747+
RDMA_HW_STATS_DEFAULT_LIFESPAN);
1748+
}
1749+
1750+
static int erdma_query_hw_stats(struct erdma_dev *dev,
1751+
struct rdma_hw_stats *stats)
1752+
{
1753+
struct erdma_cmdq_query_stats_resp *resp;
1754+
struct erdma_cmdq_query_req req;
1755+
dma_addr_t dma_addr;
1756+
int err;
1757+
1758+
erdma_cmdq_build_reqhdr(&req.hdr, CMDQ_SUBMOD_COMMON,
1759+
CMDQ_OPCODE_GET_STATS);
1760+
1761+
resp = dma_pool_zalloc(dev->resp_pool, GFP_KERNEL, &dma_addr);
1762+
if (!resp)
1763+
return -ENOMEM;
1764+
1765+
req.target_addr = dma_addr;
1766+
req.target_length = ERDMA_HW_RESP_SIZE;
1767+
1768+
err = erdma_post_cmd_wait(&dev->cmdq, &req, sizeof(req), NULL, NULL);
1769+
if (err)
1770+
goto out;
1771+
1772+
if (resp->hdr.magic != ERDMA_HW_RESP_MAGIC) {
1773+
err = -EINVAL;
1774+
goto out;
1775+
}
1776+
1777+
memcpy(&stats->value[0], &resp->tx_req_cnt,
1778+
sizeof(u64) * stats->num_counters);
1779+
1780+
out:
1781+
dma_pool_free(dev->resp_pool, resp, dma_addr);
1782+
1783+
return err;
1784+
}
1785+
1786+
int erdma_get_hw_stats(struct ib_device *ibdev, struct rdma_hw_stats *stats,
1787+
u32 port, int index)
1788+
{
1789+
struct erdma_dev *dev = to_edev(ibdev);
1790+
int ret;
1791+
1792+
if (port == 0)
1793+
return 0;
1794+
1795+
ret = erdma_query_hw_stats(dev, stats);
1796+
if (ret)
1797+
return ret;
1798+
1799+
return stats->num_counters;
1800+
}

drivers/infiniband/hw/erdma/erdma_verbs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,5 +361,9 @@ int erdma_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents,
361361
unsigned int *sg_offset);
362362
void erdma_port_event(struct erdma_dev *dev, enum ib_event_type reason);
363363
void erdma_set_mtu(struct erdma_dev *dev, u32 mtu);
364+
struct rdma_hw_stats *erdma_alloc_hw_port_stats(struct ib_device *device,
365+
u32 port_num);
366+
int erdma_get_hw_stats(struct ib_device *ibdev, struct rdma_hw_stats *stats,
367+
u32 port, int index);
364368

365369
#endif

0 commit comments

Comments
 (0)