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
, struct nlattr
*attr
)
25 if (rd
->json_output
) {
26 jsonw_string_field(rd
->jw
, "poll-ctx",
27 poll_ctx_to_str(poll_ctx
));
30 pr_out("poll-ctx %s ", poll_ctx_to_str(poll_ctx
));
33 static int res_cq_line(struct rd
*rd
, const char *name
, int idx
,
34 struct nlattr
**nla_line
)
44 if (!nla_line
[RDMA_NLDEV_ATTR_RES_CQE
] ||
45 !nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
] ||
46 (!nla_line
[RDMA_NLDEV_ATTR_RES_PID
] &&
47 !nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
])) {
51 cqe
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CQE
]);
53 users
= mnl_attr_get_u64(nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
54 if (rd_check_is_filtered(rd
, "users", users
))
57 if (nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]) {
59 mnl_attr_get_u8(nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]);
60 if (rd_check_is_string_filtered(rd
, "poll-ctx",
61 poll_ctx_to_str(poll_ctx
)))
65 if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
]) {
66 pid
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
67 comm
= get_task_name(pid
);
70 if (rd_check_is_filtered(rd
, "pid", pid
))
73 if (nla_line
[RDMA_NLDEV_ATTR_RES_CQN
])
74 cqn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]);
75 if (rd_check_is_filtered(rd
, "cqn", cqn
))
77 if (nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
])
78 ctxn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
79 if (rd_check_is_filtered(rd
, "ctxn", ctxn
))
82 if (nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
])
83 /* discard const from mnl_attr_get_str */
84 comm
= (char *)mnl_attr_get_str(
85 nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
]);
88 jsonw_start_array(rd
->jw
);
90 print_dev(rd
, idx
, name
);
91 res_print_uint(rd
, "cqn", cqn
, nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]);
92 res_print_uint(rd
, "cqe", cqe
, nla_line
[RDMA_NLDEV_ATTR_RES_CQE
]);
93 res_print_uint(rd
, "users", users
,
94 nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
95 print_poll_ctx(rd
, poll_ctx
, nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]);
96 res_print_uint(rd
, "ctxn", ctxn
, nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
97 res_print_uint(rd
, "pid", pid
, nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
98 print_comm(rd
, comm
, nla_line
);
100 print_driver_table(rd
, nla_line
[RDMA_NLDEV_ATTR_DRIVER
]);
103 out
: if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
])
108 int res_cq_idx_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
110 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
111 struct rd
*rd
= data
;
115 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
116 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
])
119 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
120 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
122 return res_cq_line(rd
, name
, idx
, tb
);
125 int res_cq_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
127 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
128 struct nlattr
*nla_table
, *nla_entry
;
129 struct rd
*rd
= data
;
134 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
135 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
] ||
136 !tb
[RDMA_NLDEV_ATTR_RES_CQ
])
139 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
140 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
141 nla_table
= tb
[RDMA_NLDEV_ATTR_RES_CQ
];
143 mnl_attr_for_each_nested(nla_entry
, nla_table
) {
144 struct nlattr
*nla_line
[RDMA_NLDEV_ATTR_MAX
] = {};
146 ret
= mnl_attr_parse_nested(nla_entry
, rd_attr_cb
, nla_line
);
147 if (ret
!= MNL_CB_OK
)
150 ret
= res_cq_line(rd
, name
, idx
, nla_line
);
152 if (ret
!= MNL_CB_OK
)