]>
Commit | Line | Data |
---|---|---|
cc613127 LR |
1 | /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ |
2 | /* | |
3 | * res.h RDMA tool | |
4 | * Authors: Leon Romanovsky <leonro@mellanox.com> | |
5 | */ | |
6 | #ifndef _RDMA_TOOL_RES_H_ | |
7 | #define _RDMA_TOOL_RES_H_ | |
8 | ||
9 | #include "rdma.h" | |
10 | ||
11 | int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback); | |
5a823593 LR |
12 | int _res_send_idx_msg(struct rd *rd, uint32_t command, mnl_cb_t callback, |
13 | uint32_t idx, uint32_t id); | |
14 | ||
cc613127 | 15 | int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data); |
5a823593 | 16 | int res_pd_idx_parse_cb(const struct nlmsghdr *nlh, void *data); |
42ed283e | 17 | int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data); |
5a823593 | 18 | int res_mr_idx_parse_cb(const struct nlmsghdr *nlh, void *data); |
fcdd2e0c | 19 | int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data); |
5a823593 | 20 | int res_cq_idx_parse_cb(const struct nlmsghdr *nlh, void *data); |
438fac3a | 21 | int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data); |
5a823593 | 22 | int res_cm_id_idx_parse_cb(const struct nlmsghdr *nlh, void *data); |
687daf98 | 23 | int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data); |
5a823593 | 24 | int res_qp_idx_parse_cb(const struct nlmsghdr *nlh, void *data); |
cc613127 | 25 | |
7c01e0fc MG |
26 | static inline uint32_t res_get_command(uint32_t command, struct rd *rd) |
27 | { | |
28 | if (!rd->show_raw) | |
29 | return command; | |
30 | ||
31 | switch (command) { | |
32 | case RDMA_NLDEV_CMD_RES_QP_GET: | |
33 | return RDMA_NLDEV_CMD_RES_QP_GET_RAW; | |
34 | default: | |
35 | return command; | |
36 | } | |
37 | } | |
38 | ||
5a823593 LR |
39 | #define RES_FUNC(name, command, valid_filters, strict_port, id) \ |
40 | static inline int _##name(struct rd *rd) \ | |
41 | { \ | |
7c01e0fc | 42 | uint32_t idx, _command; \ |
5a823593 | 43 | int ret; \ |
7c01e0fc | 44 | _command = res_get_command(command, rd); \ |
5a823593 LR |
45 | if (id) { \ |
46 | ret = rd_doit_index(rd, &idx); \ | |
47 | if (ret) { \ | |
8f5cfd23 | 48 | rd->suppress_errors = true; \ |
7c01e0fc | 49 | ret = _res_send_idx_msg(rd, _command, \ |
5a823593 LR |
50 | name##_idx_parse_cb, \ |
51 | idx, id); \ | |
7c01e0fc | 52 | if (!ret || rd->show_raw) \ |
5a823593 | 53 | return ret; \ |
7c01e0fc MG |
54 | /* Fallback for old systems without .doit callbacks. \ |
55 | * Kernel that supports raw, for sure supports doit. \ | |
56 | */ \ | |
5a823593 LR |
57 | } \ |
58 | } \ | |
7c01e0fc | 59 | return _res_send_msg(rd, _command, name##_parse_cb); \ |
5a823593 LR |
60 | } \ |
61 | static inline int name(struct rd *rd) \ | |
62 | { \ | |
63 | int ret = rd_build_filter(rd, valid_filters); \ | |
64 | if (ret) \ | |
65 | return ret; \ | |
66 | if ((uintptr_t)valid_filters != (uintptr_t)NULL) { \ | |
67 | ret = rd_set_arg_to_devname(rd); \ | |
68 | if (ret) \ | |
69 | return ret; \ | |
70 | } \ | |
71 | if (strict_port) \ | |
72 | return rd_exec_dev(rd, _##name); \ | |
73 | else \ | |
74 | return rd_exec_link(rd, _##name, strict_port); \ | |
cc613127 LR |
75 | } |
76 | ||
77 | static const | |
78 | struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = { | |
79 | { .name = "dev", .is_number = false }, | |
80 | { .name = "users", .is_number = true }, | |
81 | { .name = "pid", .is_number = true }, | |
82 | { .name = "ctxn", .is_number = true }, | |
5a823593 | 83 | { .name = "pdn", .is_number = true, .is_doit = true }, |
cc613127 LR |
84 | { .name = "ctxn", .is_number = true } |
85 | }; | |
86 | ||
5a823593 LR |
87 | RES_FUNC(res_pd, RDMA_NLDEV_CMD_RES_PD_GET, pd_valid_filters, true, |
88 | RDMA_NLDEV_ATTR_RES_PDN); | |
cc613127 | 89 | |
42ed283e LR |
90 | static const |
91 | struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = { | |
92 | { .name = "dev", .is_number = false }, | |
93 | { .name = "rkey", .is_number = true }, | |
94 | { .name = "lkey", .is_number = true }, | |
95 | { .name = "mrlen", .is_number = true }, | |
96 | { .name = "pid", .is_number = true }, | |
5a823593 | 97 | { .name = "mrn", .is_number = true, .is_doit = true }, |
42ed283e LR |
98 | { .name = "pdn", .is_number = true } |
99 | }; | |
100 | ||
5a823593 LR |
101 | RES_FUNC(res_mr, RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true, |
102 | RDMA_NLDEV_ATTR_RES_MRN); | |
42ed283e | 103 | |
fcdd2e0c LR |
104 | static const |
105 | struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS] = { | |
106 | { .name = "dev", .is_number = false }, | |
107 | { .name = "users", .is_number = true }, | |
108 | { .name = "poll-ctx", .is_number = false }, | |
109 | { .name = "pid", .is_number = true }, | |
5a823593 | 110 | { .name = "cqn", .is_number = true, .is_doit = true }, |
fcdd2e0c LR |
111 | { .name = "ctxn", .is_number = true } |
112 | }; | |
113 | ||
5a823593 LR |
114 | RES_FUNC(res_cq, RDMA_NLDEV_CMD_RES_CQ_GET, cq_valid_filters, true, |
115 | RDMA_NLDEV_ATTR_RES_CQN); | |
fcdd2e0c | 116 | |
438fac3a LR |
117 | static const |
118 | struct filters cm_id_valid_filters[MAX_NUMBER_OF_FILTERS] = { | |
119 | { .name = "link", .is_number = false }, | |
120 | { .name = "lqpn", .is_number = true }, | |
121 | { .name = "qp-type", .is_number = false }, | |
122 | { .name = "state", .is_number = false }, | |
123 | { .name = "ps", .is_number = false }, | |
124 | { .name = "dev-type", .is_number = false }, | |
125 | { .name = "transport-type", .is_number = false }, | |
126 | { .name = "pid", .is_number = true }, | |
127 | { .name = "src-addr", .is_number = false }, | |
128 | { .name = "src-port", .is_number = true }, | |
129 | { .name = "dst-addr", .is_number = false }, | |
130 | { .name = "dst-port", .is_number = true }, | |
5a823593 | 131 | { .name = "cm-idn", .is_number = true, .is_doit = true } |
438fac3a LR |
132 | }; |
133 | ||
5a823593 LR |
134 | RES_FUNC(res_cm_id, RDMA_NLDEV_CMD_RES_CM_ID_GET, cm_id_valid_filters, false, |
135 | RDMA_NLDEV_ATTR_RES_CM_IDN); | |
438fac3a | 136 | |
687daf98 LR |
137 | static const struct |
138 | filters qp_valid_filters[MAX_NUMBER_OF_FILTERS] = { | |
139 | { .name = "link", .is_number = false }, | |
5a823593 | 140 | { .name = "lqpn", .is_number = true, .is_doit = true }, |
687daf98 LR |
141 | { .name = "rqpn", .is_number = true }, |
142 | { .name = "pid", .is_number = true }, | |
143 | { .name = "sq-psn", .is_number = true }, | |
144 | { .name = "rq-psn", .is_number = true }, | |
145 | { .name = "type", .is_number = false }, | |
146 | { .name = "path-mig-state", .is_number = false }, | |
147 | { .name = "state", .is_number = false }, | |
148 | { .name = "pdn", .is_number = true }, | |
149 | }; | |
150 | ||
5a823593 LR |
151 | RES_FUNC(res_qp, RDMA_NLDEV_CMD_RES_QP_GET, qp_valid_filters, false, |
152 | RDMA_NLDEV_ATTR_RES_LQPN); | |
687daf98 | 153 | |
cc613127 LR |
154 | char *get_task_name(uint32_t pid); |
155 | void print_dev(struct rd *rd, uint32_t idx, const char *name); | |
438fac3a LR |
156 | void print_link(struct rd *rd, uint32_t idx, const char *name, uint32_t port, |
157 | struct nlattr **nla_line); | |
127ff956 LR |
158 | void print_key(struct rd *rd, const char *name, uint64_t val, |
159 | struct nlattr *nlattr); | |
160 | void res_print_uint(struct rd *rd, const char *name, uint64_t val, | |
161 | struct nlattr *nlattr); | |
cc613127 | 162 | void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line); |
438fac3a | 163 | const char *qp_types_to_str(uint8_t idx); |
cc613127 LR |
164 | |
165 | #endif /* _RDMA_TOOL_RES_H_ */ |