]>
Commit | Line | Data |
---|---|---|
fcdd2e0c LR |
1 | // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
2 | /* | |
3 | * res-cq.c RDMA tool | |
4 | * Authors: Leon Romanovsky <leonro@mellanox.com> | |
5 | */ | |
6 | ||
7 | #include "res.h" | |
8 | #include <inttypes.h> | |
9 | ||
fcdd2e0c LR |
10 | static const char *poll_ctx_to_str(uint8_t idx) |
11 | { | |
12 | static const char * const cm_id_states_str[] = { | |
13 | "DIRECT", "SOFTIRQ", "WORKQUEUE", "UNBOUND_WORKQUEUE"}; | |
14 | ||
15 | if (idx < ARRAY_SIZE(cm_id_states_str)) | |
16 | return cm_id_states_str[idx]; | |
17 | return "UNKNOWN"; | |
18 | } | |
19 | ||
20 | static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx) | |
21 | { | |
22 | if (rd->json_output) { | |
23 | jsonw_string_field(rd->jw, "poll-ctx", | |
24 | poll_ctx_to_str(poll_ctx)); | |
25 | return; | |
26 | } | |
27 | pr_out("poll-ctx %s ", poll_ctx_to_str(poll_ctx)); | |
28 | } | |
29 | ||
83ea7228 LR |
30 | static int res_cq_line(struct rd *rd, const char *name, int idx, |
31 | struct nlattr *nla_entry) | |
32 | { | |
33 | struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; | |
34 | char *comm = NULL; | |
35 | uint32_t pid = 0; | |
36 | uint8_t poll_ctx = 0; | |
37 | uint32_t ctxn = 0; | |
38 | uint32_t cqn = 0; | |
39 | uint64_t users; | |
40 | uint32_t cqe; | |
41 | int err; | |
42 | ||
43 | err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); | |
44 | if (err != MNL_CB_OK) | |
45 | return MNL_CB_ERROR; | |
46 | ||
47 | if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] || | |
48 | !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] || | |
49 | (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && | |
50 | !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { | |
51 | return MNL_CB_ERROR; | |
52 | } | |
53 | ||
54 | cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]); | |
55 | ||
56 | users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
57 | if (rd_check_is_filtered(rd, "users", users)) | |
58 | goto out; | |
59 | ||
60 | if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) { | |
61 | poll_ctx = | |
62 | mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); | |
63 | if (rd_check_is_string_filtered(rd, "poll-ctx", | |
64 | poll_ctx_to_str(poll_ctx))) | |
65 | goto out; | |
66 | } | |
67 | ||
68 | if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { | |
69 | pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
70 | comm = get_task_name(pid); | |
71 | } | |
72 | ||
73 | if (rd_check_is_filtered(rd, "pid", pid)) | |
74 | goto out; | |
75 | ||
76 | if (nla_line[RDMA_NLDEV_ATTR_RES_CQN]) | |
77 | cqn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQN]); | |
78 | if (rd_check_is_filtered(rd, "cqn", cqn)) | |
79 | goto out; | |
80 | ||
81 | if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) | |
82 | ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
83 | if (rd_check_is_filtered(rd, "ctxn", ctxn)) | |
84 | goto out; | |
85 | ||
86 | if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) | |
87 | /* discard const from mnl_attr_get_str */ | |
88 | comm = (char *)mnl_attr_get_str( | |
89 | nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); | |
90 | ||
91 | if (rd->json_output) | |
92 | jsonw_start_array(rd->jw); | |
93 | ||
94 | print_dev(rd, idx, name); | |
95 | res_print_uint(rd, "cqe", cqe); | |
96 | res_print_uint(rd, "users", users); | |
97 | if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) | |
98 | print_poll_ctx(rd, poll_ctx); | |
99 | res_print_uint(rd, "pid", pid); | |
100 | print_comm(rd, comm, nla_line); | |
101 | ||
102 | if (nla_line[RDMA_NLDEV_ATTR_RES_CQN]) | |
103 | res_print_uint(rd, "cqn", cqn); | |
104 | if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) | |
105 | res_print_uint(rd, "ctxn", ctxn); | |
106 | ||
107 | print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); | |
108 | newline(rd); | |
109 | ||
110 | out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) | |
111 | free(comm); | |
112 | return MNL_CB_OK; | |
113 | } | |
114 | ||
fcdd2e0c LR |
115 | int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data) |
116 | { | |
117 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
118 | struct nlattr *nla_table, *nla_entry; | |
119 | struct rd *rd = data; | |
83ea7228 | 120 | int ret = MNL_CB_OK; |
fcdd2e0c LR |
121 | const char *name; |
122 | uint32_t idx; | |
123 | ||
124 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
125 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || | |
126 | !tb[RDMA_NLDEV_ATTR_RES_CQ]) | |
127 | return MNL_CB_ERROR; | |
128 | ||
129 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
130 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
131 | nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ]; | |
132 | ||
133 | mnl_attr_for_each_nested(nla_entry, nla_table) { | |
83ea7228 LR |
134 | ret = res_cq_line(rd, name, idx, nla_entry); |
135 | ||
136 | if (ret != MNL_CB_OK) | |
137 | break; | |
fcdd2e0c | 138 | } |
83ea7228 | 139 | return ret; |
fcdd2e0c | 140 | } |