]>
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 | ||
127ff956 | 20 | static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx, struct nlattr *attr) |
fcdd2e0c | 21 | { |
127ff956 LR |
22 | if (!attr) |
23 | return; | |
24 | ||
fcdd2e0c LR |
25 | if (rd->json_output) { |
26 | jsonw_string_field(rd->jw, "poll-ctx", | |
27 | poll_ctx_to_str(poll_ctx)); | |
28 | return; | |
29 | } | |
30 | pr_out("poll-ctx %s ", poll_ctx_to_str(poll_ctx)); | |
31 | } | |
32 | ||
83ea7228 LR |
33 | static int res_cq_line(struct rd *rd, const char *name, int idx, |
34 | struct nlattr *nla_entry) | |
35 | { | |
36 | struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; | |
37 | char *comm = NULL; | |
38 | uint32_t pid = 0; | |
39 | uint8_t poll_ctx = 0; | |
40 | uint32_t ctxn = 0; | |
41 | uint32_t cqn = 0; | |
42 | uint64_t users; | |
43 | uint32_t cqe; | |
44 | int err; | |
45 | ||
46 | err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); | |
47 | if (err != MNL_CB_OK) | |
48 | return MNL_CB_ERROR; | |
49 | ||
50 | if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] || | |
51 | !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] || | |
52 | (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && | |
53 | !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { | |
54 | return MNL_CB_ERROR; | |
55 | } | |
56 | ||
57 | cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]); | |
58 | ||
59 | users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
60 | if (rd_check_is_filtered(rd, "users", users)) | |
61 | goto out; | |
62 | ||
63 | if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) { | |
64 | poll_ctx = | |
65 | mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); | |
66 | if (rd_check_is_string_filtered(rd, "poll-ctx", | |
67 | poll_ctx_to_str(poll_ctx))) | |
68 | goto out; | |
69 | } | |
70 | ||
71 | if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { | |
72 | pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
73 | comm = get_task_name(pid); | |
74 | } | |
75 | ||
76 | if (rd_check_is_filtered(rd, "pid", pid)) | |
77 | goto out; | |
78 | ||
79 | if (nla_line[RDMA_NLDEV_ATTR_RES_CQN]) | |
80 | cqn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQN]); | |
81 | if (rd_check_is_filtered(rd, "cqn", cqn)) | |
82 | goto out; | |
83 | ||
84 | if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) | |
85 | ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
86 | if (rd_check_is_filtered(rd, "ctxn", ctxn)) | |
87 | goto out; | |
88 | ||
89 | if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) | |
90 | /* discard const from mnl_attr_get_str */ | |
91 | comm = (char *)mnl_attr_get_str( | |
92 | nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); | |
93 | ||
94 | if (rd->json_output) | |
95 | jsonw_start_array(rd->jw); | |
96 | ||
97 | print_dev(rd, idx, name); | |
127ff956 LR |
98 | res_print_uint(rd, "cqn", cqn, nla_line[RDMA_NLDEV_ATTR_RES_CQN]); |
99 | res_print_uint(rd, "cqe", cqe, nla_line[RDMA_NLDEV_ATTR_RES_CQE]); | |
100 | res_print_uint(rd, "users", users, | |
101 | nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
102 | print_poll_ctx(rd, poll_ctx, nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); | |
103 | res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
104 | res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
83ea7228 LR |
105 | print_comm(rd, comm, nla_line); |
106 | ||
83ea7228 LR |
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 | } |