]>
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 LR |
19 | |
20 | if (!nla_line[RDMA_NLDEV_ATTR_RES_USECNT] || | |
21 | (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && | |
22 | !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { | |
23 | return MNL_CB_ERROR; | |
24 | } | |
25 | ||
26 | if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]) | |
27 | local_dma_lkey = mnl_attr_get_u32( | |
28 | nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]); | |
29 | ||
30 | users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
78728b7e LR |
31 | if (rd_is_filtered_attr(rd, "users", users, |
32 | nla_line[RDMA_NLDEV_ATTR_RES_USECNT])) | |
f9a73796 LR |
33 | goto out; |
34 | ||
35 | if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]) | |
36 | unsafe_global_rkey = mnl_attr_get_u32( | |
37 | nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]); | |
38 | ||
39 | if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { | |
40 | pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
41 | comm = get_task_name(pid); | |
42 | } | |
43 | ||
78728b7e LR |
44 | if (rd_is_filtered_attr(rd, "pid", pid, |
45 | nla_line[RDMA_NLDEV_ATTR_RES_PID])) | |
f9a73796 LR |
46 | goto out; |
47 | ||
48 | if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) | |
49 | ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
50 | ||
78728b7e LR |
51 | if (rd_is_filtered_attr(rd, "ctxn", ctxn, |
52 | nla_line[RDMA_NLDEV_ATTR_RES_CTXN])) | |
f9a73796 LR |
53 | goto out; |
54 | ||
55 | if (nla_line[RDMA_NLDEV_ATTR_RES_PDN]) | |
56 | pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]); | |
78728b7e LR |
57 | if (rd_is_filtered_attr(rd, "pdn", pdn, |
58 | nla_line[RDMA_NLDEV_ATTR_RES_PDN])) | |
f9a73796 LR |
59 | goto out; |
60 | ||
61 | if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) | |
62 | /* discard const from mnl_attr_get_str */ | |
63 | comm = (char *)mnl_attr_get_str( | |
64 | nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); | |
65 | ||
66 | if (rd->json_output) | |
67 | jsonw_start_array(rd->jw); | |
68 | ||
69 | print_dev(rd, idx, name); | |
127ff956 LR |
70 | res_print_uint(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN]); |
71 | print_key(rd, "local_dma_lkey", local_dma_lkey, | |
72 | nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]); | |
73 | res_print_uint(rd, "users", users, | |
74 | nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
75 | print_key(rd, "unsafe_global_rkey", unsafe_global_rkey, | |
76 | nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]); | |
77 | res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
78 | res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
f9a73796 | 79 | print_comm(rd, comm, nla_line); |
f9a73796 LR |
80 | |
81 | print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); | |
82 | newline(rd); | |
83 | ||
84 | out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) | |
85 | free(comm); | |
86 | return MNL_CB_OK; | |
87 | } | |
88 | ||
5a823593 LR |
89 | int res_pd_idx_parse_cb(const struct nlmsghdr *nlh, void *data) |
90 | { | |
91 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
92 | struct rd *rd = data; | |
93 | const char *name; | |
94 | uint32_t idx; | |
95 | ||
96 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
97 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME]) | |
98 | return MNL_CB_ERROR; | |
99 | ||
100 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
101 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
102 | ||
103 | return res_pd_line(rd, name, idx, tb); | |
104 | } | |
105 | ||
cc613127 LR |
106 | int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data) |
107 | { | |
108 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
109 | struct nlattr *nla_table, *nla_entry; | |
110 | struct rd *rd = data; | |
f9a73796 | 111 | int ret = MNL_CB_OK; |
cc613127 LR |
112 | const char *name; |
113 | uint32_t idx; | |
114 | ||
115 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
116 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || | |
117 | !tb[RDMA_NLDEV_ATTR_RES_PD]) | |
118 | return MNL_CB_ERROR; | |
119 | ||
120 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
121 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
122 | nla_table = tb[RDMA_NLDEV_ATTR_RES_PD]; | |
123 | ||
124 | mnl_attr_for_each_nested(nla_entry, nla_table) { | |
5a823593 LR |
125 | struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; |
126 | ||
127 | ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); | |
128 | if (ret != MNL_CB_OK) | |
129 | break; | |
f9a73796 | 130 | |
5a823593 | 131 | ret = res_pd_line(rd, name, idx, nla_line); |
f9a73796 LR |
132 | if (ret != MNL_CB_OK) |
133 | break; | |
cc613127 | 134 | } |
f9a73796 | 135 | return ret; |
cc613127 | 136 | } |