1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
4 * Authors: Leon Romanovsky <leonro@mellanox.com>
10 static const char *poll_ctx_to_str(uint8_t idx
)
12 static const char * const cm_id_states_str
[] = {
13 "DIRECT", "SOFTIRQ", "WORKQUEUE", "UNBOUND_WORKQUEUE"};
15 if (idx
< ARRAY_SIZE(cm_id_states_str
))
16 return cm_id_states_str
[idx
];
20 static void print_poll_ctx(struct rd
*rd
, uint8_t poll_ctx
)
22 if (rd
->json_output
) {
23 jsonw_string_field(rd
->jw
, "poll-ctx",
24 poll_ctx_to_str(poll_ctx
));
27 pr_out("poll-ctx %s ", poll_ctx_to_str(poll_ctx
));
30 int res_cq_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
32 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
33 struct nlattr
*nla_table
, *nla_entry
;
38 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
39 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
] ||
40 !tb
[RDMA_NLDEV_ATTR_RES_CQ
])
43 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
44 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
45 nla_table
= tb
[RDMA_NLDEV_ATTR_RES_CQ
];
47 mnl_attr_for_each_nested(nla_entry
, nla_table
) {
48 struct nlattr
*nla_line
[RDMA_NLDEV_ATTR_MAX
] = {};
58 err
= mnl_attr_parse_nested(nla_entry
, rd_attr_cb
, nla_line
);
62 if (!nla_line
[RDMA_NLDEV_ATTR_RES_CQE
] ||
63 !nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
] ||
64 (!nla_line
[RDMA_NLDEV_ATTR_RES_PID
] &&
65 !nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
])) {
69 cqe
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CQE
]);
71 users
= mnl_attr_get_u64(nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
72 if (rd_check_is_filtered(rd
, "users", users
))
75 if (nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]) {
76 poll_ctx
= mnl_attr_get_u8(
77 nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]);
78 if (rd_check_is_string_filtered(
79 rd
, "poll-ctx", poll_ctx_to_str(poll_ctx
)))
83 if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
]) {
84 pid
= mnl_attr_get_u32(
85 nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
86 comm
= get_task_name(pid
);
89 if (rd_check_is_filtered(rd
, "pid", pid
)) {
94 if (nla_line
[RDMA_NLDEV_ATTR_RES_CQN
])
95 cqn
= mnl_attr_get_u32(
96 nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]);
97 if (rd_check_is_filtered(rd
, "cqn", cqn
))
100 if (nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
])
101 ctxn
= mnl_attr_get_u32(
102 nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
103 if (rd_check_is_filtered(rd
, "ctxn", ctxn
))
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
]);
112 jsonw_start_array(rd
->jw
);
114 print_dev(rd
, idx
, name
);
115 res_print_uint(rd
, "cqe", cqe
);
116 res_print_uint(rd
, "users", users
);
117 if (nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
])
118 print_poll_ctx(rd
, poll_ctx
);
119 res_print_uint(rd
, "pid", pid
);
120 print_comm(rd
, comm
, nla_line
);
122 if (nla_line
[RDMA_NLDEV_ATTR_RES_CQN
])
123 res_print_uint(rd
, "cqn", cqn
);
124 if (nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
])
125 res_print_uint(rd
, "ctxn", ctxn
);
127 if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
])
130 print_driver_table(rd
, nla_line
[RDMA_NLDEV_ATTR_DRIVER
]);