Blame rdma/res.h

Packit Service 3880ab
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
Packit Service 3880ab
/*
Packit Service 3880ab
 * res.h	RDMA tool
Packit Service 3880ab
 * Authors:     Leon Romanovsky <leonro@mellanox.com>
Packit Service 3880ab
 */
Packit Service 3880ab
#ifndef _RDMA_TOOL_RES_H_
Packit Service 3880ab
#define _RDMA_TOOL_RES_H_
Packit Service 3880ab
Packit Service 3880ab
#include "rdma.h"
Packit Service 3880ab
Packit Service 3880ab
int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback);
Packit Service 3880ab
int _res_send_idx_msg(struct rd *rd, uint32_t command, mnl_cb_t callback,
Packit Service 3880ab
		      uint32_t idx, uint32_t id);
Packit Service 3880ab
Packit Service 3880ab
int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data);
Packit Service 3880ab
int res_pd_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
Packit Service 3880ab
int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data);
Packit Service 3880ab
int res_mr_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
Packit Service 3880ab
int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data);
Packit Service 3880ab
int res_cq_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
Packit Service 3880ab
int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data);
Packit Service 3880ab
int res_cm_id_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
Packit Service 3880ab
int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data);
Packit Service 3880ab
int res_qp_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
Packit Service 3880ab
Packit Service 3880ab
static inline uint32_t res_get_command(uint32_t command, struct rd *rd)
Packit Service 3880ab
{
Packit Service 3880ab
	if (!rd->show_raw)
Packit Service 3880ab
		return command;
Packit Service 3880ab
Packit Service 3880ab
	switch (command) {
Packit Service 3880ab
	case RDMA_NLDEV_CMD_RES_QP_GET:
Packit Service 3880ab
		return RDMA_NLDEV_CMD_RES_QP_GET_RAW;
Packit Service 3880ab
	case RDMA_NLDEV_CMD_RES_CQ_GET:
Packit Service 3880ab
		return RDMA_NLDEV_CMD_RES_CQ_GET_RAW;
Packit Service 3880ab
	case RDMA_NLDEV_CMD_RES_MR_GET:
Packit Service 3880ab
		return RDMA_NLDEV_CMD_RES_MR_GET_RAW;
Packit Service 3880ab
	default:
Packit Service 3880ab
		return command;
Packit Service 3880ab
	}
Packit Service 3880ab
}
Packit Service 3880ab
Packit Service 3880ab
#define RES_FUNC(name, command, valid_filters, strict_port, id)                        \
Packit Service 3880ab
	static inline int _##name(struct rd *rd)                                       \
Packit Service 3880ab
	{                                                                              \
Packit Service 3880ab
		uint32_t idx, _command;                                                \
Packit Service 3880ab
		int ret;                                                               \
Packit Service 3880ab
		_command = res_get_command(command, rd);			       \
Packit Service 3880ab
		if (id) {                                                              \
Packit Service 3880ab
			ret = rd_doit_index(rd, &idx);                                 \
Packit Service 3880ab
			if (ret) {                                                     \
Packit Service 3880ab
				rd->suppress_errors = true;                            \
Packit Service 3880ab
				ret = _res_send_idx_msg(rd, _command,                  \
Packit Service 3880ab
							name##_idx_parse_cb,           \
Packit Service 3880ab
							idx, id);                      \
Packit Service 3880ab
				if (!ret || rd->show_raw)                              \
Packit Service 3880ab
					return ret;                                    \
Packit Service 3880ab
				/* Fallback for old systems without .doit callbacks.   \
Packit Service 3880ab
				 * Kernel that supports raw, for sure supports doit.   \
Packit Service 3880ab
				 */						       \
Packit Service 3880ab
			}                                                              \
Packit Service 3880ab
		}                                                                      \
Packit Service 3880ab
		return _res_send_msg(rd, _command, name##_parse_cb);                   \
Packit Service 3880ab
	}                                                                              \
Packit Service 3880ab
	static inline int name(struct rd *rd)                                          \
Packit Service 3880ab
	{                                                                              \
Packit Service 3880ab
		int ret = rd_build_filter(rd, valid_filters);                          \
Packit Service 3880ab
		if (ret)                                                               \
Packit Service 3880ab
			return ret;                                                    \
Packit Service 3880ab
		if ((uintptr_t)valid_filters != (uintptr_t)NULL) {                     \
Packit Service 3880ab
			ret = rd_set_arg_to_devname(rd);                               \
Packit Service 3880ab
			if (ret)                                                       \
Packit Service 3880ab
				return ret;                                            \
Packit Service 3880ab
		}                                                                      \
Packit Service 3880ab
		if (strict_port)                                                       \
Packit Service 3880ab
			return rd_exec_dev(rd, _##name);                               \
Packit Service 3880ab
		else                                                                   \
Packit Service 3880ab
			return rd_exec_link(rd, _##name, strict_port);                 \
Packit Service 3880ab
	}
Packit Service 3880ab
Packit Service 3880ab
static const
Packit Service 3880ab
struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = {
Packit Service 3880ab
	{ .name = "dev", .is_number = false },
Packit Service 3880ab
	{ .name = "users", .is_number = true },
Packit Service 3880ab
	{ .name = "pid", .is_number = true },
Packit Service 3880ab
	{ .name = "ctxn", .is_number = true },
Packit Service 3880ab
	{ .name = "pdn", .is_number = true, .is_doit = true },
Packit Service 3880ab
	{ .name = "ctxn", .is_number = true }
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
RES_FUNC(res_pd, RDMA_NLDEV_CMD_RES_PD_GET, pd_valid_filters, true,
Packit Service 3880ab
	 RDMA_NLDEV_ATTR_RES_PDN);
Packit Service 3880ab
Packit Service 3880ab
static const
Packit Service 3880ab
struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {
Packit Service 3880ab
	{ .name = "dev", .is_number = false },
Packit Service 3880ab
	{ .name = "rkey", .is_number = true },
Packit Service 3880ab
	{ .name = "lkey", .is_number = true },
Packit Service 3880ab
	{ .name = "mrlen", .is_number = true },
Packit Service 3880ab
	{ .name = "pid", .is_number = true },
Packit Service 3880ab
	{ .name = "mrn", .is_number = true, .is_doit = true },
Packit Service 3880ab
	{ .name = "pdn", .is_number = true }
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
RES_FUNC(res_mr, RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true,
Packit Service 3880ab
	 RDMA_NLDEV_ATTR_RES_MRN);
Packit Service 3880ab
Packit Service 3880ab
static const
Packit Service 3880ab
struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS] = {
Packit Service 3880ab
	{ .name = "dev", .is_number = false },
Packit Service 3880ab
	{ .name = "users", .is_number = true },
Packit Service 3880ab
	{ .name = "poll-ctx", .is_number = false },
Packit Service 3880ab
	{ .name = "pid", .is_number = true },
Packit Service 3880ab
	{ .name = "cqn", .is_number = true, .is_doit = true },
Packit Service 3880ab
	{ .name = "ctxn", .is_number = true }
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
RES_FUNC(res_cq, RDMA_NLDEV_CMD_RES_CQ_GET, cq_valid_filters, true,
Packit Service 3880ab
	 RDMA_NLDEV_ATTR_RES_CQN);
Packit Service 3880ab
Packit Service 3880ab
static const
Packit Service 3880ab
struct filters cm_id_valid_filters[MAX_NUMBER_OF_FILTERS] = {
Packit Service 3880ab
	{ .name = "link", .is_number = false },
Packit Service 3880ab
	{ .name = "lqpn", .is_number = true },
Packit Service 3880ab
	{ .name = "qp-type", .is_number = false },
Packit Service 3880ab
	{ .name = "state", .is_number = false },
Packit Service 3880ab
	{ .name = "ps", .is_number = false },
Packit Service 3880ab
	{ .name = "dev-type", .is_number = false },
Packit Service 3880ab
	{ .name = "transport-type", .is_number = false },
Packit Service 3880ab
	{ .name = "pid", .is_number = true },
Packit Service 3880ab
	{ .name = "src-addr", .is_number = false },
Packit Service 3880ab
	{ .name = "src-port", .is_number = true },
Packit Service 3880ab
	{ .name = "dst-addr", .is_number = false },
Packit Service 3880ab
	{ .name = "dst-port", .is_number = true },
Packit Service 3880ab
	{ .name = "cm-idn", .is_number = true, .is_doit = true }
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
RES_FUNC(res_cm_id, RDMA_NLDEV_CMD_RES_CM_ID_GET, cm_id_valid_filters, false,
Packit Service 3880ab
	 RDMA_NLDEV_ATTR_RES_CM_IDN);
Packit Service 3880ab
Packit Service 3880ab
static const struct
Packit Service 3880ab
filters qp_valid_filters[MAX_NUMBER_OF_FILTERS] = {
Packit Service 3880ab
	{ .name = "link", .is_number = false },
Packit Service 3880ab
	{ .name = "lqpn", .is_number = true, .is_doit = true },
Packit Service 3880ab
	{ .name = "rqpn", .is_number = true },
Packit Service 3880ab
	{ .name = "pid",  .is_number = true },
Packit Service 3880ab
	{ .name = "sq-psn", .is_number = true },
Packit Service 3880ab
	{ .name = "rq-psn", .is_number = true },
Packit Service 3880ab
	{ .name = "type", .is_number = false },
Packit Service 3880ab
	{ .name = "path-mig-state", .is_number = false },
Packit Service 3880ab
	{ .name = "state", .is_number = false },
Packit Service 3880ab
	{ .name = "pdn", .is_number = true },
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
RES_FUNC(res_qp, RDMA_NLDEV_CMD_RES_QP_GET, qp_valid_filters, false,
Packit Service 3880ab
	 RDMA_NLDEV_ATTR_RES_LQPN);
Packit Service 3880ab
Packit Service 3880ab
char *get_task_name(uint32_t pid);
Packit Service 3880ab
void print_dev(struct rd *rd, uint32_t idx, const char *name);
Packit Service 3880ab
void print_link(struct rd *rd, uint32_t idx, const char *name, uint32_t port,
Packit Service 3880ab
		struct nlattr **nla_line);
Packit Service 3880ab
void print_key(struct rd *rd, const char *name, uint64_t val,
Packit Service 3880ab
	       struct nlattr *nlattr);
Packit Service 3880ab
void res_print_uint(struct rd *rd, const char *name, uint64_t val,
Packit Service 3880ab
		    struct nlattr *nlattr);
Packit Service 3880ab
void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line);
Packit Service 3880ab
const char *qp_types_to_str(uint8_t idx);
Packit Service 3880ab
void print_qp_type(struct rd *rd, uint32_t val);
Packit Service 3880ab
#endif /* _RDMA_TOOL_RES_H_ */