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