1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
4 * Authors: Leon Romanovsky <leonro@mellanox.com>
10 static void print_cqe(struct rd
*rd
, uint32_t val
)
13 jsonw_uint_field(rd
->jw
, "cqe", val
);
15 pr_out("cqe %u ", val
);
18 static const char *poll_ctx_to_str(uint8_t idx
)
20 static const char * const cm_id_states_str
[] = {
21 "DIRECT", "SOFTIRQ", "WORKQUEUE", "UNBOUND_WORKQUEUE"};
23 if (idx
< ARRAY_SIZE(cm_id_states_str
))
24 return cm_id_states_str
[idx
];
28 static void print_poll_ctx(struct rd
*rd
, uint8_t poll_ctx
)
30 if (rd
->json_output
) {
31 jsonw_string_field(rd
->jw
, "poll-ctx",
32 poll_ctx_to_str(poll_ctx
));
35 pr_out("poll-ctx %s ", poll_ctx_to_str(poll_ctx
));
38 int res_cq_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
40 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
41 struct nlattr
*nla_table
, *nla_entry
;
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
])
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
];
55 mnl_attr_for_each_nested(nla_entry
, nla_table
) {
56 struct nlattr
*nla_line
[RDMA_NLDEV_ATTR_MAX
] = {};
66 err
= mnl_attr_parse_nested(nla_entry
, rd_attr_cb
, nla_line
);
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
])) {
77 cqe
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CQE
]);
79 users
= mnl_attr_get_u64(nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
80 if (rd_check_is_filtered(rd
, "users", users
))
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
)))
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
);
97 if (rd_check_is_filtered(rd
, "pid", pid
)) {
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
))
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
))
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
]);
120 jsonw_start_array(rd
->jw
);
122 print_dev(rd
, idx
, name
);
124 print_users(rd
, users
);
125 if (nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
])
126 print_poll_ctx(rd
, poll_ctx
);
128 print_comm(rd
, comm
, nla_line
);
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
);
135 if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
])
138 print_driver_table(rd
, nla_line
[RDMA_NLDEV_ATTR_DRIVER
]);