]>
Commit | Line | Data |
---|---|---|
33552ade EA |
1 | // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
2 | /* | |
3 | * stat-mr.c RDMA tool | |
4 | * Authors: Erez Alfasi <ereza@mellanox.com> | |
5 | */ | |
6 | ||
7 | #include "res.h" | |
8 | #include "stat.h" | |
9 | #include <inttypes.h> | |
10 | ||
11 | static int stat_mr_line(struct rd *rd, const char *name, int idx, | |
12 | struct nlattr **nla_line) | |
13 | { | |
14 | uint32_t mrn = 0; | |
15 | int ret; | |
16 | ||
17 | if (nla_line[RDMA_NLDEV_ATTR_RES_MRN]) | |
18 | mrn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_MRN]); | |
19 | if (rd_is_filtered_attr(rd, "mrn", mrn, | |
20 | nla_line[RDMA_NLDEV_ATTR_RES_MRN])) | |
21 | goto out; | |
22 | ||
b0a688a5 | 23 | open_json_object(NULL); |
33552ade EA |
24 | print_dev(rd, idx, name); |
25 | res_print_uint(rd, "mrn", mrn, nla_line[RDMA_NLDEV_ATTR_RES_MRN]); | |
26 | ||
27 | if (nla_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS]) { | |
28 | ret = res_get_hwcounters( | |
29 | rd, nla_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS], true); | |
30 | if (ret != MNL_CB_OK) | |
31 | return ret; | |
32 | } | |
33 | ||
34 | newline(rd); | |
35 | out: | |
36 | return MNL_CB_OK; | |
37 | } | |
38 | ||
39 | int stat_mr_idx_parse_cb(const struct nlmsghdr *nlh, void *data) | |
40 | { | |
41 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
42 | struct rd *rd = data; | |
43 | const char *name; | |
44 | uint32_t idx; | |
45 | ||
46 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
47 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME]) | |
48 | return MNL_CB_ERROR; | |
49 | ||
50 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
51 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
52 | ||
53 | return stat_mr_line(rd, name, idx, tb); | |
54 | } | |
55 | ||
56 | int stat_mr_parse_cb(const struct nlmsghdr *nlh, void *data) | |
57 | { | |
58 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
59 | struct nlattr *nla_table, *nla_entry; | |
60 | struct rd *rd = data; | |
61 | int ret = MNL_CB_OK; | |
62 | const char *name; | |
63 | uint32_t idx; | |
64 | ||
65 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
66 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || | |
67 | !tb[RDMA_NLDEV_ATTR_RES_MR]) | |
68 | return MNL_CB_ERROR; | |
69 | ||
70 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
71 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
72 | nla_table = tb[RDMA_NLDEV_ATTR_RES_MR]; | |
73 | ||
74 | mnl_attr_for_each_nested(nla_entry, nla_table) { | |
75 | struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; | |
76 | ||
77 | ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); | |
78 | if (ret != MNL_CB_OK) | |
79 | break; | |
80 | ||
81 | ret = stat_mr_line(rd, name, idx, nla_line); | |
82 | if (ret != MNL_CB_OK) | |
83 | break; | |
84 | } | |
85 | return ret; | |
86 | } |