]>
Commit | Line | Data |
---|---|---|
cc613127 LR |
1 | // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
2 | /* | |
3 | * res-pd.c RDMA tool | |
4 | * Authors: Leon Romanovsky <leonro@mellanox.com> | |
5 | */ | |
6 | ||
7 | #include "res.h" | |
8 | #include <inttypes.h> | |
9 | ||
f9a73796 | 10 | static int res_pd_line(struct rd *rd, const char *name, int idx, |
5a823593 | 11 | struct nlattr **nla_line) |
f9a73796 LR |
12 | { |
13 | uint32_t local_dma_lkey = 0, unsafe_global_rkey = 0; | |
f9a73796 LR |
14 | char *comm = NULL; |
15 | uint32_t ctxn = 0; | |
16 | uint32_t pid = 0; | |
17 | uint32_t pdn = 0; | |
18 | uint64_t users; | |
f9a73796 | 19 | |
f9313484 | 20 | if (!nla_line[RDMA_NLDEV_ATTR_RES_USECNT]) |
f9a73796 | 21 | return MNL_CB_ERROR; |
f9a73796 LR |
22 | |
23 | if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]) | |
24 | local_dma_lkey = mnl_attr_get_u32( | |
25 | nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]); | |
26 | ||
27 | users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
78728b7e LR |
28 | if (rd_is_filtered_attr(rd, "users", users, |
29 | nla_line[RDMA_NLDEV_ATTR_RES_USECNT])) | |
f9a73796 LR |
30 | goto out; |
31 | ||
32 | if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]) | |
33 | unsafe_global_rkey = mnl_attr_get_u32( | |
34 | nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]); | |
35 | ||
36 | if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { | |
37 | pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
38 | comm = get_task_name(pid); | |
39 | } | |
40 | ||
78728b7e LR |
41 | if (rd_is_filtered_attr(rd, "pid", pid, |
42 | nla_line[RDMA_NLDEV_ATTR_RES_PID])) | |
f9a73796 LR |
43 | goto out; |
44 | ||
45 | if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) | |
46 | ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
47 | ||
78728b7e LR |
48 | if (rd_is_filtered_attr(rd, "ctxn", ctxn, |
49 | nla_line[RDMA_NLDEV_ATTR_RES_CTXN])) | |
f9a73796 LR |
50 | goto out; |
51 | ||
52 | if (nla_line[RDMA_NLDEV_ATTR_RES_PDN]) | |
53 | pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]); | |
78728b7e LR |
54 | if (rd_is_filtered_attr(rd, "pdn", pdn, |
55 | nla_line[RDMA_NLDEV_ATTR_RES_PDN])) | |
f9a73796 LR |
56 | goto out; |
57 | ||
58 | if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) | |
59 | /* discard const from mnl_attr_get_str */ | |
60 | comm = (char *)mnl_attr_get_str( | |
61 | nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); | |
62 | ||
b0a688a5 | 63 | open_json_object(NULL); |
f9a73796 | 64 | print_dev(rd, idx, name); |
127ff956 LR |
65 | res_print_uint(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN]); |
66 | print_key(rd, "local_dma_lkey", local_dma_lkey, | |
67 | nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]); | |
68 | res_print_uint(rd, "users", users, | |
69 | nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
70 | print_key(rd, "unsafe_global_rkey", unsafe_global_rkey, | |
71 | nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]); | |
72 | res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
73 | res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
f9a73796 | 74 | print_comm(rd, comm, nla_line); |
f9a73796 LR |
75 | |
76 | print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); | |
77 | newline(rd); | |
78 | ||
79 | out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) | |
80 | free(comm); | |
81 | return MNL_CB_OK; | |
82 | } | |
83 | ||
5a823593 LR |
84 | int res_pd_idx_parse_cb(const struct nlmsghdr *nlh, void *data) |
85 | { | |
86 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
87 | struct rd *rd = data; | |
88 | const char *name; | |
89 | uint32_t idx; | |
90 | ||
91 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
92 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME]) | |
93 | return MNL_CB_ERROR; | |
94 | ||
95 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
96 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
97 | ||
98 | return res_pd_line(rd, name, idx, tb); | |
99 | } | |
100 | ||
cc613127 LR |
101 | int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data) |
102 | { | |
103 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
104 | struct nlattr *nla_table, *nla_entry; | |
105 | struct rd *rd = data; | |
f9a73796 | 106 | int ret = MNL_CB_OK; |
cc613127 LR |
107 | const char *name; |
108 | uint32_t idx; | |
109 | ||
110 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
111 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || | |
112 | !tb[RDMA_NLDEV_ATTR_RES_PD]) | |
113 | return MNL_CB_ERROR; | |
114 | ||
115 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
116 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
117 | nla_table = tb[RDMA_NLDEV_ATTR_RES_PD]; | |
118 | ||
119 | mnl_attr_for_each_nested(nla_entry, nla_table) { | |
5a823593 LR |
120 | struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; |
121 | ||
122 | ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); | |
123 | if (ret != MNL_CB_OK) | |
124 | break; | |
f9a73796 | 125 | |
5a823593 | 126 | ret = res_pd_line(rd, name, idx, nla_line); |
f9a73796 LR |
127 | if (ret != MNL_CB_OK) |
128 | break; | |
cc613127 | 129 | } |
f9a73796 | 130 | return ret; |
cc613127 | 131 | } |