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