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
)
24 print_color_string(PRINT_ANY
, COLOR_NONE
, "poll-ctx", "poll-ctx %s ",
25 poll_ctx_to_str(poll_ctx
));
28 static void print_cq_dim_setting(struct rd
*rd
, struct nlattr
*attr
)
35 dim_setting
= mnl_attr_get_u8(attr
);
39 print_on_off(PRINT_ANY
, "adaptive-moderation", "adaptive-moderation %s ", dim_setting
);
42 static int res_cq_line_raw(struct rd
*rd
, const char *name
, int idx
,
43 struct nlattr
**nla_line
)
45 if (!nla_line
[RDMA_NLDEV_ATTR_RES_RAW
])
48 open_json_object(NULL
);
49 print_dev(rd
, idx
, name
);
50 print_raw_data(rd
, nla_line
);
56 static int res_cq_line(struct rd
*rd
, const char *name
, int idx
,
57 struct nlattr
**nla_line
)
67 if (!nla_line
[RDMA_NLDEV_ATTR_RES_CQE
] ||
68 !nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
])
71 cqe
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CQE
]);
73 users
= mnl_attr_get_u64(nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
74 if (rd_is_filtered_attr(rd
, "users", users
,
75 nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]))
78 if (nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
])
80 mnl_attr_get_u8(nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]);
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
]))
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
);
91 if (rd_is_filtered_attr(rd
, "pid", pid
,
92 nla_line
[RDMA_NLDEV_ATTR_RES_PID
]))
95 if (nla_line
[RDMA_NLDEV_ATTR_RES_CQN
])
96 cqn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]);
97 if (rd_is_filtered_attr(rd
, "cqn", cqn
,
98 nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]))
100 if (nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
])
101 ctxn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
102 if (rd_is_filtered_attr(rd
, "ctxn", ctxn
,
103 nla_line
[RDMA_NLDEV_ATTR_RES_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
]);
111 open_json_object(NULL
);
112 print_dev(rd
, idx
, name
);
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
]);
118 print_cq_dim_setting(rd
, nla_line
[RDMA_NLDEV_ATTR_DEV_DIM
]);
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
]);
121 print_comm(rd
, comm
, nla_line
);
123 print_driver_table(rd
, nla_line
[RDMA_NLDEV_ATTR_DRIVER
]);
126 out
: if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
])
131 int res_cq_idx_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
133 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
134 struct rd
*rd
= data
;
138 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
139 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
])
142 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
143 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
145 return (rd
->show_raw
) ? res_cq_line_raw(rd
, name
, idx
, tb
) :
146 res_cq_line(rd
, name
, idx
, tb
);
149 int res_cq_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
151 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
152 struct nlattr
*nla_table
, *nla_entry
;
153 struct rd
*rd
= data
;
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
])
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
];
167 mnl_attr_for_each_nested(nla_entry
, nla_table
) {
168 struct nlattr
*nla_line
[RDMA_NLDEV_ATTR_MAX
] = {};
170 ret
= mnl_attr_parse_nested(nla_entry
, rd_attr_cb
, nla_line
);
171 if (ret
!= MNL_CB_OK
)
174 ret
= (rd
->show_raw
) ? res_cq_line_raw(rd
, name
, idx
, nla_line
) :
175 res_cq_line(rd
, name
, idx
, nla_line
);
177 if (ret
!= MNL_CB_OK
)