]> git.proxmox.com Git - mirror_iproute2.git/blame - rdma/res-cq.c
Merge branch 'main' into next
[mirror_iproute2.git] / rdma / res-cq.c
CommitLineData
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
10static 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 20static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx, struct nlattr *attr)
fcdd2e0c 21{
127ff956
LR
22 if (!attr)
23 return;
b0a688a5
IK
24 print_color_string(PRINT_ANY, COLOR_NONE, "poll-ctx", "poll-ctx %s ",
25 poll_ctx_to_str(poll_ctx));
fcdd2e0c
LR
26}
27
8a56ef32
YF
28static 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
94323e96
MG
42static 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
83ea7228 56static int res_cq_line(struct rd *rd, const char *name, int idx,
5a823593 57 struct nlattr **nla_line)
83ea7228 58{
83ea7228
LR
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;
83ea7228
LR
66
67 if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] ||
f9313484 68 !nla_line[RDMA_NLDEV_ATTR_RES_USECNT])
83ea7228 69 return MNL_CB_ERROR;
83ea7228
LR
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]);
78728b7e
LR
74 if (rd_is_filtered_attr(rd, "users", users,
75 nla_line[RDMA_NLDEV_ATTR_RES_USECNT]))
83ea7228
LR
76 goto out;
77
78728b7e 78 if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX])
83ea7228
LR
79 poll_ctx =
80 mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
78728b7e
LR
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;
83ea7228
LR
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
78728b7e
LR
91 if (rd_is_filtered_attr(rd, "pid", pid,
92 nla_line[RDMA_NLDEV_ATTR_RES_PID]))
83ea7228
LR
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]);
78728b7e
LR
97 if (rd_is_filtered_attr(rd, "cqn", cqn,
98 nla_line[RDMA_NLDEV_ATTR_RES_CQN]))
83ea7228 99 goto out;
83ea7228
LR
100 if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
101 ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
78728b7e
LR
102 if (rd_is_filtered_attr(rd, "ctxn", ctxn,
103 nla_line[RDMA_NLDEV_ATTR_RES_CTXN]))
83ea7228
LR
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
b0a688a5 111 open_json_object(NULL);
83ea7228 112 print_dev(rd, idx, name);
127ff956
LR
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]);
8a56ef32 118 print_cq_dim_setting(rd, nla_line[RDMA_NLDEV_ATTR_DEV_DIM]);
127ff956
LR
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]);
83ea7228
LR
121 print_comm(rd, comm, nla_line);
122
83ea7228
LR
123 print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
124 newline(rd);
125
126out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
127 free(comm);
128 return MNL_CB_OK;
129}
130
5a823593
LR
131int 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
94323e96
MG
145 return (rd->show_raw) ? res_cq_line_raw(rd, name, idx, tb) :
146 res_cq_line(rd, name, idx, tb);
5a823593
LR
147}
148
fcdd2e0c
LR
149int 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;
83ea7228 154 int ret = MNL_CB_OK;
fcdd2e0c
LR
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) {
5a823593
LR
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
94323e96
MG
174 ret = (rd->show_raw) ? res_cq_line_raw(rd, name, idx, nla_line) :
175 res_cq_line(rd, name, idx, nla_line);
83ea7228
LR
176
177 if (ret != MNL_CB_OK)
178 break;
fcdd2e0c 179 }
83ea7228 180 return ret;
fcdd2e0c 181}