]>
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 | ||
23 | if (rd->json_output) | |
24 | jsonw_start_array(rd->jw); | |
25 | ||
26 | print_dev(rd, idx, name); | |
27 | res_print_uint(rd, "mrn", mrn, nla_line[RDMA_NLDEV_ATTR_RES_MRN]); | |
28 | ||
29 | if (nla_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS]) { | |
30 | ret = res_get_hwcounters( | |
31 | rd, nla_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS], true); | |
32 | if (ret != MNL_CB_OK) | |
33 | return ret; | |
34 | } | |
35 | ||
36 | newline(rd); | |
37 | out: | |
38 | return MNL_CB_OK; | |
39 | } | |
40 | ||
41 | int stat_mr_idx_parse_cb(const struct nlmsghdr *nlh, void *data) | |
42 | { | |
43 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
44 | struct rd *rd = data; | |
45 | const char *name; | |
46 | uint32_t idx; | |
47 | ||
48 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
49 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME]) | |
50 | return MNL_CB_ERROR; | |
51 | ||
52 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
53 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
54 | ||
55 | return stat_mr_line(rd, name, idx, tb); | |
56 | } | |
57 | ||
58 | int stat_mr_parse_cb(const struct nlmsghdr *nlh, void *data) | |
59 | { | |
60 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
61 | struct nlattr *nla_table, *nla_entry; | |
62 | struct rd *rd = data; | |
63 | int ret = MNL_CB_OK; | |
64 | const char *name; | |
65 | uint32_t idx; | |
66 | ||
67 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
68 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || | |
69 | !tb[RDMA_NLDEV_ATTR_RES_MR]) | |
70 | return MNL_CB_ERROR; | |
71 | ||
72 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
73 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
74 | nla_table = tb[RDMA_NLDEV_ATTR_RES_MR]; | |
75 | ||
76 | mnl_attr_for_each_nested(nla_entry, nla_table) { | |
77 | struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; | |
78 | ||
79 | ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); | |
80 | if (ret != MNL_CB_OK) | |
81 | break; | |
82 | ||
83 | ret = stat_mr_line(rd, name, idx, nla_line); | |
84 | if (ret != MNL_CB_OK) | |
85 | break; | |
86 | } | |
87 | return ret; | |
88 | } |