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 void print_cq_dim_setting(struct rd
*rd
, struct nlattr
*attr
)
40 dim_setting
= mnl_attr_get_u8(attr
);
44 print_on_off(rd
, "adaptive-moderation", dim_setting
);
47 static int res_cq_line(struct rd
*rd
, const char *name
, int idx
,
48 struct nlattr
**nla_line
)
58 if (!nla_line
[RDMA_NLDEV_ATTR_RES_CQE
] ||
59 !nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
])
62 cqe
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CQE
]);
64 users
= mnl_attr_get_u64(nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
65 if (rd_is_filtered_attr(rd
, "users", users
,
66 nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]))
69 if (nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
])
71 mnl_attr_get_u8(nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]);
72 if (rd_is_string_filtered_attr(rd
, "poll-ctx",
73 poll_ctx_to_str(poll_ctx
),
74 nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]))
77 if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
]) {
78 pid
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
79 comm
= get_task_name(pid
);
82 if (rd_is_filtered_attr(rd
, "pid", pid
,
83 nla_line
[RDMA_NLDEV_ATTR_RES_PID
]))
86 if (nla_line
[RDMA_NLDEV_ATTR_RES_CQN
])
87 cqn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]);
88 if (rd_is_filtered_attr(rd
, "cqn", cqn
,
89 nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]))
91 if (nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
])
92 ctxn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
93 if (rd_is_filtered_attr(rd
, "ctxn", ctxn
,
94 nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]))
97 if (nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
])
98 /* discard const from mnl_attr_get_str */
99 comm
= (char *)mnl_attr_get_str(
100 nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
]);
103 jsonw_start_array(rd
->jw
);
105 print_dev(rd
, idx
, name
);
106 res_print_uint(rd
, "cqn", cqn
, nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]);
107 res_print_uint(rd
, "cqe", cqe
, nla_line
[RDMA_NLDEV_ATTR_RES_CQE
]);
108 res_print_uint(rd
, "users", users
,
109 nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
110 print_poll_ctx(rd
, poll_ctx
, nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]);
111 print_cq_dim_setting(rd
, nla_line
[RDMA_NLDEV_ATTR_DEV_DIM
]);
112 res_print_uint(rd
, "ctxn", ctxn
, nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
113 res_print_uint(rd
, "pid", pid
, nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
114 print_comm(rd
, comm
, nla_line
);
116 print_driver_table(rd
, nla_line
[RDMA_NLDEV_ATTR_DRIVER
]);
119 out
: if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
])
124 int res_cq_idx_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
126 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
127 struct rd
*rd
= data
;
131 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
132 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
])
135 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
136 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
138 return res_cq_line(rd
, name
, idx
, tb
);
141 int res_cq_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
143 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
144 struct nlattr
*nla_table
, *nla_entry
;
145 struct rd
*rd
= data
;
150 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
151 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
] ||
152 !tb
[RDMA_NLDEV_ATTR_RES_CQ
])
155 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
156 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
157 nla_table
= tb
[RDMA_NLDEV_ATTR_RES_CQ
];
159 mnl_attr_for_each_nested(nla_entry
, nla_table
) {
160 struct nlattr
*nla_line
[RDMA_NLDEV_ATTR_MAX
] = {};
162 ret
= mnl_attr_parse_nested(nla_entry
, rd_attr_cb
, nla_line
);
163 if (ret
!= MNL_CB_OK
)
166 ret
= res_cq_line(rd
, name
, idx
, nla_line
);
168 if (ret
!= MNL_CB_OK
)