]>
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 | ||
10 | static void print_cqe(struct rd *rd, uint32_t val) | |
11 | { | |
12 | if (rd->json_output) | |
13 | jsonw_uint_field(rd->jw, "cqe", val); | |
14 | else | |
15 | pr_out("cqe %u ", val); | |
16 | } | |
17 | ||
18 | static const char *poll_ctx_to_str(uint8_t idx) | |
19 | { | |
20 | static const char * const cm_id_states_str[] = { | |
21 | "DIRECT", "SOFTIRQ", "WORKQUEUE", "UNBOUND_WORKQUEUE"}; | |
22 | ||
23 | if (idx < ARRAY_SIZE(cm_id_states_str)) | |
24 | return cm_id_states_str[idx]; | |
25 | return "UNKNOWN"; | |
26 | } | |
27 | ||
28 | static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx) | |
29 | { | |
30 | if (rd->json_output) { | |
31 | jsonw_string_field(rd->jw, "poll-ctx", | |
32 | poll_ctx_to_str(poll_ctx)); | |
33 | return; | |
34 | } | |
35 | pr_out("poll-ctx %s ", poll_ctx_to_str(poll_ctx)); | |
36 | } | |
37 | ||
38 | int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data) | |
39 | { | |
40 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
41 | struct nlattr *nla_table, *nla_entry; | |
42 | struct rd *rd = data; | |
43 | const char *name; | |
44 | uint32_t idx; | |
45 | ||
46 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
47 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || | |
48 | !tb[RDMA_NLDEV_ATTR_RES_CQ]) | |
49 | return MNL_CB_ERROR; | |
50 | ||
51 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
52 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
53 | nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ]; | |
54 | ||
55 | mnl_attr_for_each_nested(nla_entry, nla_table) { | |
56 | struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; | |
57 | char *comm = NULL; | |
58 | uint32_t pid = 0; | |
59 | uint8_t poll_ctx = 0; | |
60 | uint32_t ctxn = 0; | |
61 | uint32_t cqn = 0; | |
62 | uint64_t users; | |
63 | uint32_t cqe; | |
64 | int err; | |
65 | ||
66 | err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); | |
67 | if (err != MNL_CB_OK) | |
68 | return MNL_CB_ERROR; | |
69 | ||
70 | if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] || | |
71 | !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] || | |
72 | (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && | |
73 | !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { | |
74 | return MNL_CB_ERROR; | |
75 | } | |
76 | ||
77 | cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]); | |
78 | ||
79 | users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
80 | if (rd_check_is_filtered(rd, "users", users)) | |
81 | continue; | |
82 | ||
83 | if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) { | |
84 | poll_ctx = mnl_attr_get_u8( | |
85 | nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); | |
86 | if (rd_check_is_string_filtered( | |
87 | rd, "poll-ctx", poll_ctx_to_str(poll_ctx))) | |
88 | continue; | |
89 | } | |
90 | ||
91 | if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { | |
92 | pid = mnl_attr_get_u32( | |
93 | nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
94 | comm = get_task_name(pid); | |
95 | } | |
96 | ||
97 | if (rd_check_is_filtered(rd, "pid", pid)) { | |
98 | free(comm); | |
99 | continue; | |
100 | } | |
101 | ||
102 | if (nla_line[RDMA_NLDEV_ATTR_RES_CQN]) | |
103 | cqn = mnl_attr_get_u32( | |
104 | nla_line[RDMA_NLDEV_ATTR_RES_CQN]); | |
105 | if (rd_check_is_filtered(rd, "cqn", cqn)) | |
106 | continue; | |
107 | ||
108 | if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) | |
109 | ctxn = mnl_attr_get_u32( | |
110 | nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
111 | if (rd_check_is_filtered(rd, "ctxn", ctxn)) | |
112 | continue; | |
113 | ||
114 | if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) | |
115 | /* discard const from mnl_attr_get_str */ | |
116 | comm = (char *)mnl_attr_get_str( | |
117 | nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); | |
118 | ||
119 | if (rd->json_output) | |
120 | jsonw_start_array(rd->jw); | |
121 | ||
122 | print_dev(rd, idx, name); | |
123 | print_cqe(rd, cqe); | |
124 | print_users(rd, users); | |
125 | if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) | |
126 | print_poll_ctx(rd, poll_ctx); | |
127 | print_pid(rd, pid); | |
128 | print_comm(rd, comm, nla_line); | |
129 | ||
130 | if (nla_line[RDMA_NLDEV_ATTR_RES_CQN]) | |
131 | res_print_uint(rd, "cqn", cqn); | |
132 | if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) | |
133 | res_print_uint(rd, "ctxn", ctxn); | |
134 | ||
135 | if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) | |
136 | free(comm); | |
137 | ||
138 | print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); | |
139 | newline(rd); | |
140 | } | |
141 | return MNL_CB_OK; | |
142 | } | |
143 |