]>
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 | 33 | static int res_cq_line(struct rd *rd, const char *name, int idx, |
5a823593 | 34 | struct nlattr **nla_line) |
83ea7228 | 35 | { |
83ea7228 LR |
36 | char *comm = NULL; |
37 | uint32_t pid = 0; | |
38 | uint8_t poll_ctx = 0; | |
39 | uint32_t ctxn = 0; | |
40 | uint32_t cqn = 0; | |
41 | uint64_t users; | |
42 | uint32_t cqe; | |
83ea7228 LR |
43 | |
44 | if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] || | |
45 | !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] || | |
46 | (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && | |
47 | !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { | |
48 | return MNL_CB_ERROR; | |
49 | } | |
50 | ||
51 | cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]); | |
52 | ||
53 | users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
78728b7e LR |
54 | if (rd_is_filtered_attr(rd, "users", users, |
55 | nla_line[RDMA_NLDEV_ATTR_RES_USECNT])) | |
83ea7228 LR |
56 | goto out; |
57 | ||
78728b7e | 58 | if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) |
83ea7228 LR |
59 | poll_ctx = |
60 | mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); | |
78728b7e LR |
61 | if (rd_is_string_filtered_attr(rd, "poll-ctx", |
62 | poll_ctx_to_str(poll_ctx), | |
63 | nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX])) | |
64 | goto out; | |
83ea7228 LR |
65 | |
66 | if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { | |
67 | pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
68 | comm = get_task_name(pid); | |
69 | } | |
70 | ||
78728b7e LR |
71 | if (rd_is_filtered_attr(rd, "pid", pid, |
72 | nla_line[RDMA_NLDEV_ATTR_RES_PID])) | |
83ea7228 LR |
73 | goto out; |
74 | ||
75 | if (nla_line[RDMA_NLDEV_ATTR_RES_CQN]) | |
76 | cqn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQN]); | |
78728b7e LR |
77 | if (rd_is_filtered_attr(rd, "cqn", cqn, |
78 | nla_line[RDMA_NLDEV_ATTR_RES_CQN])) | |
83ea7228 | 79 | goto out; |
83ea7228 LR |
80 | if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) |
81 | ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
78728b7e LR |
82 | if (rd_is_filtered_attr(rd, "ctxn", ctxn, |
83 | nla_line[RDMA_NLDEV_ATTR_RES_CTXN])) | |
83ea7228 LR |
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); | |
127ff956 LR |
95 | res_print_uint(rd, "cqn", cqn, nla_line[RDMA_NLDEV_ATTR_RES_CQN]); |
96 | res_print_uint(rd, "cqe", cqe, nla_line[RDMA_NLDEV_ATTR_RES_CQE]); | |
97 | res_print_uint(rd, "users", users, | |
98 | nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
99 | print_poll_ctx(rd, poll_ctx, nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); | |
100 | res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
101 | res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
83ea7228 LR |
102 | print_comm(rd, comm, nla_line); |
103 | ||
83ea7228 LR |
104 | print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); |
105 | newline(rd); | |
106 | ||
107 | out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) | |
108 | free(comm); | |
109 | return MNL_CB_OK; | |
110 | } | |
111 | ||
5a823593 LR |
112 | int res_cq_idx_parse_cb(const struct nlmsghdr *nlh, void *data) |
113 | { | |
114 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
115 | struct rd *rd = data; | |
116 | const char *name; | |
117 | uint32_t idx; | |
118 | ||
119 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
120 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME]) | |
121 | return MNL_CB_ERROR; | |
122 | ||
123 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
124 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
125 | ||
126 | return res_cq_line(rd, name, idx, tb); | |
127 | } | |
128 | ||
fcdd2e0c LR |
129 | int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data) |
130 | { | |
131 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
132 | struct nlattr *nla_table, *nla_entry; | |
133 | struct rd *rd = data; | |
83ea7228 | 134 | int ret = MNL_CB_OK; |
fcdd2e0c LR |
135 | const char *name; |
136 | uint32_t idx; | |
137 | ||
138 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
139 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || | |
140 | !tb[RDMA_NLDEV_ATTR_RES_CQ]) | |
141 | return MNL_CB_ERROR; | |
142 | ||
143 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
144 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
145 | nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ]; | |
146 | ||
147 | mnl_attr_for_each_nested(nla_entry, nla_table) { | |
5a823593 LR |
148 | struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; |
149 | ||
150 | ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); | |
151 | if (ret != MNL_CB_OK) | |
152 | break; | |
153 | ||
154 | ret = res_cq_line(rd, name, idx, nla_line); | |
83ea7228 LR |
155 | |
156 | if (ret != MNL_CB_OK) | |
157 | break; | |
fcdd2e0c | 158 | } |
83ea7228 | 159 | return ret; |
fcdd2e0c | 160 | } |