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(rd
, "adaptive-moderation", dim_setting
);
42 static int res_cq_line(struct rd
*rd
, const char *name
, int idx
,
43 struct nlattr
**nla_line
)
53 if (!nla_line
[RDMA_NLDEV_ATTR_RES_CQE
] ||
54 !nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
])
57 cqe
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CQE
]);
59 users
= mnl_attr_get_u64(nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
60 if (rd_is_filtered_attr(rd
, "users", users
,
61 nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]))
64 if (nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
])
66 mnl_attr_get_u8(nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]);
67 if (rd_is_string_filtered_attr(rd
, "poll-ctx",
68 poll_ctx_to_str(poll_ctx
),
69 nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]))
72 if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
]) {
73 pid
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
74 comm
= get_task_name(pid
);
77 if (rd_is_filtered_attr(rd
, "pid", pid
,
78 nla_line
[RDMA_NLDEV_ATTR_RES_PID
]))
81 if (nla_line
[RDMA_NLDEV_ATTR_RES_CQN
])
82 cqn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]);
83 if (rd_is_filtered_attr(rd
, "cqn", cqn
,
84 nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]))
86 if (nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
])
87 ctxn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
88 if (rd_is_filtered_attr(rd
, "ctxn", ctxn
,
89 nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]))
92 if (nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
])
93 /* discard const from mnl_attr_get_str */
94 comm
= (char *)mnl_attr_get_str(
95 nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
]);
97 open_json_object(NULL
);
98 print_dev(rd
, idx
, name
);
99 res_print_uint(rd
, "cqn", cqn
, nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]);
100 res_print_uint(rd
, "cqe", cqe
, nla_line
[RDMA_NLDEV_ATTR_RES_CQE
]);
101 res_print_uint(rd
, "users", users
,
102 nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
103 print_poll_ctx(rd
, poll_ctx
, nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]);
104 print_cq_dim_setting(rd
, nla_line
[RDMA_NLDEV_ATTR_DEV_DIM
]);
105 res_print_uint(rd
, "ctxn", ctxn
, nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
106 res_print_uint(rd
, "pid", pid
, nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
107 print_comm(rd
, comm
, nla_line
);
109 print_driver_table(rd
, nla_line
[RDMA_NLDEV_ATTR_DRIVER
]);
112 out
: if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
])
117 int res_cq_idx_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
119 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
120 struct rd
*rd
= data
;
124 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
125 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
])
128 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
129 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
131 return res_cq_line(rd
, name
, idx
, tb
);
134 int res_cq_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
136 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
137 struct nlattr
*nla_table
, *nla_entry
;
138 struct rd
*rd
= data
;
143 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
144 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
] ||
145 !tb
[RDMA_NLDEV_ATTR_RES_CQ
])
148 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
149 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
150 nla_table
= tb
[RDMA_NLDEV_ATTR_RES_CQ
];
152 mnl_attr_for_each_nested(nla_entry
, nla_table
) {
153 struct nlattr
*nla_line
[RDMA_NLDEV_ATTR_MAX
] = {};
155 ret
= mnl_attr_parse_nested(nla_entry
, rd_attr_cb
, nla_line
);
156 if (ret
!= MNL_CB_OK
)
159 ret
= res_cq_line(rd
, name
, idx
, nla_line
);
161 if (ret
!= MNL_CB_OK
)