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
] ||
60 (!nla_line
[RDMA_NLDEV_ATTR_RES_PID
] &&
61 !nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
])) {
65 cqe
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CQE
]);
67 users
= mnl_attr_get_u64(nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
68 if (rd_is_filtered_attr(rd
, "users", users
,
69 nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]))
72 if (nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
])
74 mnl_attr_get_u8(nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]);
75 if (rd_is_string_filtered_attr(rd
, "poll-ctx",
76 poll_ctx_to_str(poll_ctx
),
77 nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]))
80 if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
]) {
81 pid
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
82 comm
= get_task_name(pid
);
85 if (rd_is_filtered_attr(rd
, "pid", pid
,
86 nla_line
[RDMA_NLDEV_ATTR_RES_PID
]))
89 if (nla_line
[RDMA_NLDEV_ATTR_RES_CQN
])
90 cqn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]);
91 if (rd_is_filtered_attr(rd
, "cqn", cqn
,
92 nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]))
94 if (nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
])
95 ctxn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
96 if (rd_is_filtered_attr(rd
, "ctxn", ctxn
,
97 nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]))
100 if (nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
])
101 /* discard const from mnl_attr_get_str */
102 comm
= (char *)mnl_attr_get_str(
103 nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
]);
106 jsonw_start_array(rd
->jw
);
108 print_dev(rd
, idx
, name
);
109 res_print_uint(rd
, "cqn", cqn
, nla_line
[RDMA_NLDEV_ATTR_RES_CQN
]);
110 res_print_uint(rd
, "cqe", cqe
, nla_line
[RDMA_NLDEV_ATTR_RES_CQE
]);
111 res_print_uint(rd
, "users", users
,
112 nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
113 print_poll_ctx(rd
, poll_ctx
, nla_line
[RDMA_NLDEV_ATTR_RES_POLL_CTX
]);
114 print_cq_dim_setting(rd
, nla_line
[RDMA_NLDEV_ATTR_DEV_DIM
]);
115 res_print_uint(rd
, "ctxn", ctxn
, nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
116 res_print_uint(rd
, "pid", pid
, nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
117 print_comm(rd
, comm
, nla_line
);
119 print_driver_table(rd
, nla_line
[RDMA_NLDEV_ATTR_DRIVER
]);
122 out
: if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
])
127 int res_cq_idx_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
129 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
130 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
])
138 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
139 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
141 return res_cq_line(rd
, name
, idx
, tb
);
144 int res_cq_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
146 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
147 struct nlattr
*nla_table
, *nla_entry
;
148 struct rd
*rd
= data
;
153 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
154 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
] ||
155 !tb
[RDMA_NLDEV_ATTR_RES_CQ
])
158 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
159 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
160 nla_table
= tb
[RDMA_NLDEV_ATTR_RES_CQ
];
162 mnl_attr_for_each_nested(nla_entry
, nla_table
) {
163 struct nlattr
*nla_line
[RDMA_NLDEV_ATTR_MAX
] = {};
165 ret
= mnl_attr_parse_nested(nla_entry
, rd_attr_cb
, nla_line
);
166 if (ret
!= MNL_CB_OK
)
169 ret
= res_cq_line(rd
, name
, idx
, nla_line
);
171 if (ret
!= MNL_CB_OK
)