summaryrefslogtreecommitdiffstats
path: root/rdma/res.h
blob: fd09ce7dc0847a6cb55e945aa7153b00e434abd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
/*
 * res.h	RDMA tool
 * Authors:     Leon Romanovsky <leonro@mellanox.com>
 */
#ifndef _RDMA_TOOL_RES_H_
#define _RDMA_TOOL_RES_H_

#include "rdma.h"

int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback);
int _res_send_idx_msg(struct rd *rd, uint32_t command, mnl_cb_t callback,
		      uint32_t idx, uint32_t id);

int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_pd_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_mr_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_cq_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_cm_id_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_qp_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_ctx_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_ctx_idx_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_srq_parse_cb(const struct nlmsghdr *nlh, void *data);
int res_srq_idx_parse_cb(const struct nlmsghdr *nlh, void *data);

static inline uint32_t res_get_command(uint32_t command, struct rd *rd)
{
	if (!rd->show_raw)
		return command;

	switch (command) {
	case RDMA_NLDEV_CMD_RES_QP_GET:
		return RDMA_NLDEV_CMD_RES_QP_GET_RAW;
	case RDMA_NLDEV_CMD_RES_CQ_GET:
		return RDMA_NLDEV_CMD_RES_CQ_GET_RAW;
	case RDMA_NLDEV_CMD_RES_MR_GET:
		return RDMA_NLDEV_CMD_RES_MR_GET_RAW;
	case RDMA_NLDEV_CMD_RES_SRQ_GET:
		return RDMA_NLDEV_CMD_RES_SRQ_GET_RAW;
	default:
		return command;
	}
}

#define RES_FUNC(name, command, valid_filters, strict_port, id)                        \
	static inline int _##name(struct rd *rd)                                       \
	{                                                                              \
		uint32_t idx, _command;                                                \
		int ret;                                                               \
		_command = res_get_command(command, rd);			       \
		if (id) {                                                              \
			ret = rd_doit_index(rd, &idx);                                 \
			if (ret) {                                                     \
				rd->suppress_errors = true;                            \
				ret = _res_send_idx_msg(rd, _command,                  \
							name##_idx_parse_cb,           \
							idx, id);                      \
				if (!ret || rd->show_raw)                              \
					return ret;                                    \
				/* Fallback for old systems without .doit callbacks.   \
				 * Kernel that supports raw, for sure supports doit.   \
				 */						       \
			}                                                              \
		}                                                                      \
		return _res_send_msg(rd, _command, name##_parse_cb);                   \
	}                                                                              \
	static inline int name(struct rd *rd)                                          \
	{                                                                              \
		int ret = rd_build_filter(rd, valid_filters);                          \
		if (ret)                                                               \
			return ret;                                                    \
		if ((uintptr_t)valid_filters != (uintptr_t)NULL) {                     \
			ret = rd_set_arg_to_devname(rd);                               \
			if (ret)                                                       \
				return ret;                                            \
		}                                                                      \
		if (strict_port)                                                       \
			return rd_exec_dev(rd, _##name);                               \
		else                                                                   \
			return rd_exec_link(rd, _##name, strict_port);                 \
	}

static const
struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = {
	{ .name = "dev", .is_number = false },
	{ .name = "users", .is_number = true },
	{ .name = "pid", .is_number = true },
	{ .name = "ctxn", .is_number = true },
	{ .name = "pdn", .is_number = true, .is_doit = true },
	{ .name = "ctxn", .is_number = true }
};

RES_FUNC(res_pd, RDMA_NLDEV_CMD_RES_PD_GET, pd_valid_filters, true,
	 RDMA_NLDEV_ATTR_RES_PDN);

static const
struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {
	{ .name = "dev", .is_number = false },
	{ .name = "rkey", .is_number = true },
	{ .name = "lkey", .is_number = true },
	{ .name = "mrlen", .is_number = true },
	{ .name = "pid", .is_number = true },
	{ .name = "mrn", .is_number = true, .is_doit = true },
	{ .name = "pdn", .is_number = true }
};

RES_FUNC(res_mr, RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true,
	 RDMA_NLDEV_ATTR_RES_MRN);

static const
struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS] = {
	{ .name = "dev", .is_number = false },
	{ .name = "users", .is_number = true },
	{ .name = "poll-ctx", .is_number = false },
	{ .name = "pid", .is_number = true },
	{ .name = "cqn", .is_number = true, .is_doit = true },
	{ .name = "ctxn", .is_number = true }
};

RES_FUNC(res_cq, RDMA_NLDEV_CMD_RES_CQ_GET, cq_valid_filters, true,
	 RDMA_NLDEV_ATTR_RES_CQN);

static const
struct filters cm_id_valid_filters[MAX_NUMBER_OF_FILTERS] = {
	{ .name = "link", .is_number = false },
	{ .name = "lqpn", .is_number = true },
	{ .name = "qp-type", .is_number = false },
	{ .name = "state", .is_number = false },
	{ .name = "ps", .is_number = false },
	{ .name = "dev-type", .is_number = false },
	{ .name = "transport-type", .is_number = false },
	{ .name = "pid", .is_number = true },
	{ .name = "src-addr", .is_number = false },
	{ .name = "src-port", .is_number = true },
	{ .name = "dst-addr", .is_number = false },
	{ .name = "dst-port", .is_number = true },
	{ .name = "cm-idn", .is_number = true, .is_doit = true }
};

RES_FUNC(res_cm_id, RDMA_NLDEV_CMD_RES_CM_ID_GET, cm_id_valid_filters, false,
	 RDMA_NLDEV_ATTR_RES_CM_IDN);

static const struct
filters qp_valid_filters[MAX_NUMBER_OF_FILTERS] = {
	{ .name = "link", .is_number = false },
	{ .name = "lqpn", .is_number = true, .is_doit = true },
	{ .name = "rqpn", .is_number = true },
	{ .name = "pid",  .is_number = true },
	{ .name = "sq-psn", .is_number = true },
	{ .name = "rq-psn", .is_number = true },
	{ .name = "type", .is_number = false },
	{ .name = "path-mig-state", .is_number = false },
	{ .name = "state", .is_number = false },
	{ .name = "pdn", .is_number = true },
};

RES_FUNC(res_qp, RDMA_NLDEV_CMD_RES_QP_GET, qp_valid_filters, false,
	 RDMA_NLDEV_ATTR_RES_LQPN);

static const
struct filters ctx_valid_filters[MAX_NUMBER_OF_FILTERS] = {
	{ .name = "dev", .is_number = false },
	{ .name = "pid", .is_number = true },
	{ .name = "ctxn", .is_number = true, .is_doit = true },
};

RES_FUNC(res_ctx, RDMA_NLDEV_CMD_RES_CTX_GET, ctx_valid_filters, true,
	 RDMA_NLDEV_ATTR_RES_CTXN);

static const
struct filters srq_valid_filters[MAX_NUMBER_OF_FILTERS] = {
	{ .name = "dev", .is_number = false },
	{ .name = "pid", .is_number = true },
	{ .name = "srqn", .is_number = true, .is_doit = true },
	{ .name = "type", .is_number = false },
	{ .name = "pdn", .is_number = true },
	{ .name = "cqn", .is_number = true },
	{ .name = "lqpn", .is_number = true },
};

RES_FUNC(res_srq, RDMA_NLDEV_CMD_RES_SRQ_GET, srq_valid_filters, true,
	 RDMA_NLDEV_ATTR_RES_SRQN);

void print_dev(uint32_t idx, const char *name);
void print_link(uint32_t idx, const char *name, uint32_t port, struct nlattr **nla_line);
void print_key(const char *name, uint64_t val, struct nlattr *nlattr);
void res_print_u32(const char *name, uint32_t val, struct nlattr *nlattr);
void res_print_u64(const char *name, uint64_t val, struct nlattr *nlattr);
void print_comm(const char *str, struct nlattr **nla_line);
const char *qp_types_to_str(uint8_t idx);
void print_qp_type(uint32_t val);
#endif /* _RDMA_TOOL_RES_H_ */