]>
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]); | |
54 | if (rd_check_is_filtered(rd, "users", users)) | |
55 | goto out; | |
56 | ||
57 | if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) { | |
58 | poll_ctx = | |
59 | mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); | |
60 | if (rd_check_is_string_filtered(rd, "poll-ctx", | |
61 | poll_ctx_to_str(poll_ctx))) | |
62 | goto out; | |
63 | } | |
64 | ||
65 | if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { | |
66 | pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
67 | comm = get_task_name(pid); | |
68 | } | |
69 | ||
70 | if (rd_check_is_filtered(rd, "pid", pid)) | |
71 | goto out; | |
72 | ||
73 | if (nla_line[RDMA_NLDEV_ATTR_RES_CQN]) | |
74 | cqn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQN]); | |
75 | if (rd_check_is_filtered(rd, "cqn", cqn)) | |
76 | goto out; | |
83ea7228 LR |
77 | if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) |
78 | ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
79 | if (rd_check_is_filtered(rd, "ctxn", ctxn)) | |
80 | goto out; | |
81 | ||
82 | if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) | |
83 | /* discard const from mnl_attr_get_str */ | |
84 | comm = (char *)mnl_attr_get_str( | |
85 | nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); | |
86 | ||
87 | if (rd->json_output) | |
88 | jsonw_start_array(rd->jw); | |
89 | ||
90 | print_dev(rd, idx, name); | |
127ff956 LR |
91 | res_print_uint(rd, "cqn", cqn, nla_line[RDMA_NLDEV_ATTR_RES_CQN]); |
92 | res_print_uint(rd, "cqe", cqe, nla_line[RDMA_NLDEV_ATTR_RES_CQE]); | |
93 | res_print_uint(rd, "users", users, | |
94 | nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
95 | print_poll_ctx(rd, poll_ctx, nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); | |
96 | res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
97 | res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
83ea7228 LR |
98 | print_comm(rd, comm, nla_line); |
99 | ||
83ea7228 LR |
100 | print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); |
101 | newline(rd); | |
102 | ||
103 | out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) | |
104 | free(comm); | |
105 | return MNL_CB_OK; | |
106 | } | |
107 | ||
5a823593 LR |
108 | int res_cq_idx_parse_cb(const struct nlmsghdr *nlh, void *data) |
109 | { | |
110 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
111 | struct rd *rd = data; | |
112 | const char *name; | |
113 | uint32_t idx; | |
114 | ||
115 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
116 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME]) | |
117 | return MNL_CB_ERROR; | |
118 | ||
119 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
120 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
121 | ||
122 | return res_cq_line(rd, name, idx, tb); | |
123 | } | |
124 | ||
fcdd2e0c LR |
125 | int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data) |
126 | { | |
127 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
128 | struct nlattr *nla_table, *nla_entry; | |
129 | struct rd *rd = data; | |
83ea7228 | 130 | int ret = MNL_CB_OK; |
fcdd2e0c LR |
131 | const char *name; |
132 | uint32_t idx; | |
133 | ||
134 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
135 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || | |
136 | !tb[RDMA_NLDEV_ATTR_RES_CQ]) | |
137 | return MNL_CB_ERROR; | |
138 | ||
139 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
140 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
141 | nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ]; | |
142 | ||
143 | mnl_attr_for_each_nested(nla_entry, nla_table) { | |
5a823593 LR |
144 | struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; |
145 | ||
146 | ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); | |
147 | if (ret != MNL_CB_OK) | |
148 | break; | |
149 | ||
150 | ret = res_cq_line(rd, name, idx, nla_line); | |
83ea7228 LR |
151 | |
152 | if (ret != MNL_CB_OK) | |
153 | break; | |
fcdd2e0c | 154 | } |
83ea7228 | 155 | return ret; |
fcdd2e0c | 156 | } |