]> git.proxmox.com Git - mirror_iproute2.git/blame - rdma/res.h
rdma: Refactor out resource MR logic to separate file
[mirror_iproute2.git] / rdma / res.h
CommitLineData
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
11int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback);
12int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data);
42ed283e 13int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data);
cc613127
LR
14
15#define RES_FUNC(name, command, valid_filters, strict_port) \
16 static inline int _##name(struct rd *rd)\
17 { \
18 return _res_send_msg(rd, command, name##_parse_cb); \
19 } \
20 static inline int name(struct rd *rd) \
21 {\
22 int ret = rd_build_filter(rd, valid_filters); \
23 if (ret) \
24 return ret; \
25 if ((uintptr_t)valid_filters != (uintptr_t)NULL) { \
26 ret = rd_set_arg_to_devname(rd); \
27 if (ret) \
28 return ret;\
29 } \
30 if (strict_port) \
31 return rd_exec_dev(rd, _##name); \
32 else \
33 return rd_exec_link(rd, _##name, strict_port); \
34 }
35
36static const
37struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = {
38 { .name = "dev", .is_number = false },
39 { .name = "users", .is_number = true },
40 { .name = "pid", .is_number = true },
41 { .name = "ctxn", .is_number = true },
42 { .name = "pdn", .is_number = true },
43 { .name = "ctxn", .is_number = true }
44};
45
46RES_FUNC(res_pd, RDMA_NLDEV_CMD_RES_PD_GET, pd_valid_filters, true);
47
42ed283e
LR
48static const
49struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {
50 { .name = "dev", .is_number = false },
51 { .name = "rkey", .is_number = true },
52 { .name = "lkey", .is_number = true },
53 { .name = "mrlen", .is_number = true },
54 { .name = "pid", .is_number = true },
55 { .name = "mrn", .is_number = true },
56 { .name = "pdn", .is_number = true }
57};
58
59RES_FUNC(res_mr, RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true);
60
cc613127
LR
61char *get_task_name(uint32_t pid);
62void print_dev(struct rd *rd, uint32_t idx, const char *name);
63void print_users(struct rd *rd, uint64_t val);
64void print_key(struct rd *rd, const char *name, uint64_t val);
65void res_print_uint(struct rd *rd, const char *name, uint64_t val);
66void print_pid(struct rd *rd, uint32_t val);
67void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line);
68
69#endif /* _RDMA_TOOL_RES_H_ */