]> git.proxmox.com Git - mirror_iproute2.git/blob - rdma/res-cq.c
Merge branch 'master' into next
[mirror_iproute2.git] / rdma / res-cq.c
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 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, struct nlattr *attr)
21 {
22 if (!attr)
23 return;
24
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
33 static void print_cq_dim_setting(struct rd *rd, struct nlattr *attr)
34 {
35 uint8_t dim_setting;
36
37 if (!attr)
38 return;
39
40 dim_setting = mnl_attr_get_u8(attr);
41 if (dim_setting > 1)
42 return;
43
44 print_on_off(rd, "adaptive-moderation", dim_setting);
45 }
46
47 static int res_cq_line(struct rd *rd, const char *name, int idx,
48 struct nlattr **nla_line)
49 {
50 char *comm = NULL;
51 uint32_t pid = 0;
52 uint8_t poll_ctx = 0;
53 uint32_t ctxn = 0;
54 uint32_t cqn = 0;
55 uint64_t users;
56 uint32_t cqe;
57
58 if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] ||
59 !nla_line[RDMA_NLDEV_ATTR_RES_USECNT])
60 return MNL_CB_ERROR;
61
62 cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
63
64 users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
65 if (rd_is_filtered_attr(rd, "users", users,
66 nla_line[RDMA_NLDEV_ATTR_RES_USECNT]))
67 goto out;
68
69 if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX])
70 poll_ctx =
71 mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
72 if (rd_is_string_filtered_attr(rd, "poll-ctx",
73 poll_ctx_to_str(poll_ctx),
74 nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]))
75 goto out;
76
77 if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
78 pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
79 comm = get_task_name(pid);
80 }
81
82 if (rd_is_filtered_attr(rd, "pid", pid,
83 nla_line[RDMA_NLDEV_ATTR_RES_PID]))
84 goto out;
85
86 if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
87 cqn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
88 if (rd_is_filtered_attr(rd, "cqn", cqn,
89 nla_line[RDMA_NLDEV_ATTR_RES_CQN]))
90 goto out;
91 if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
92 ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
93 if (rd_is_filtered_attr(rd, "ctxn", ctxn,
94 nla_line[RDMA_NLDEV_ATTR_RES_CTXN]))
95 goto out;
96
97 if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
98 /* discard const from mnl_attr_get_str */
99 comm = (char *)mnl_attr_get_str(
100 nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
101
102 if (rd->json_output)
103 jsonw_start_array(rd->jw);
104
105 print_dev(rd, idx, name);
106 res_print_uint(rd, "cqn", cqn, nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
107 res_print_uint(rd, "cqe", cqe, nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
108 res_print_uint(rd, "users", users,
109 nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
110 print_poll_ctx(rd, poll_ctx, nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
111 print_cq_dim_setting(rd, nla_line[RDMA_NLDEV_ATTR_DEV_DIM]);
112 res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
113 res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
114 print_comm(rd, comm, nla_line);
115
116 print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
117 newline(rd);
118
119 out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
120 free(comm);
121 return MNL_CB_OK;
122 }
123
124 int res_cq_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
125 {
126 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
127 struct rd *rd = data;
128 const char *name;
129 uint32_t idx;
130
131 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
132 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
133 return MNL_CB_ERROR;
134
135 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
136 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
137
138 return res_cq_line(rd, name, idx, tb);
139 }
140
141 int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
142 {
143 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
144 struct nlattr *nla_table, *nla_entry;
145 struct rd *rd = data;
146 int ret = MNL_CB_OK;
147 const char *name;
148 uint32_t idx;
149
150 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
151 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
152 !tb[RDMA_NLDEV_ATTR_RES_CQ])
153 return MNL_CB_ERROR;
154
155 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
156 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
157 nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ];
158
159 mnl_attr_for_each_nested(nla_entry, nla_table) {
160 struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
161
162 ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
163 if (ret != MNL_CB_OK)
164 break;
165
166 ret = res_cq_line(rd, name, idx, nla_line);
167
168 if (ret != MNL_CB_OK)
169 break;
170 }
171 return ret;
172 }