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