]> git.proxmox.com Git - mirror_iproute2.git/blob - rdma/res-mr.c
Merge branch 'master' into next
[mirror_iproute2.git] / rdma / res-mr.c
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
10 static int res_mr_line(struct rd *rd, const char *name, int idx,
11 struct nlattr **nla_line)
12 {
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;
19
20 if (!nla_line[RDMA_NLDEV_ATTR_RES_MRLEN])
21 return MNL_CB_ERROR;
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]);
31 if (rd_is_filtered_attr(rd, "mrlen", mrlen,
32 nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]))
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
40 if (rd_is_filtered_attr(rd, "pid", pid,
41 nla_line[RDMA_NLDEV_ATTR_RES_PID]))
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]);
46 if (rd_is_filtered_attr(rd, "mrn", mrn,
47 nla_line[RDMA_NLDEV_ATTR_RES_MRN]))
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]);
52 if (rd_is_filtered_attr(rd, "pdn", pdn,
53 nla_line[RDMA_NLDEV_ATTR_RES_PDN]))
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 open_json_object(NULL);
61 print_dev(rd, idx, name);
62 res_print_uint(rd, "mrn", mrn, nla_line[RDMA_NLDEV_ATTR_RES_MRN]);
63 print_key(rd, "rkey", rkey, nla_line[RDMA_NLDEV_ATTR_RES_RKEY]);
64 print_key(rd, "lkey", lkey, nla_line[RDMA_NLDEV_ATTR_RES_LKEY]);
65 print_key(rd, "iova", iova, nla_line[RDMA_NLDEV_ATTR_RES_IOVA]);
66 res_print_uint(rd, "mrlen", mrlen, nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]);
67 res_print_uint(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
68 res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
69 print_comm(rd, comm, nla_line);
70
71 print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
72 newline(rd);
73
74 out:
75 if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
76 free(comm);
77 return MNL_CB_OK;
78 }
79
80 int res_mr_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
81 {
82 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
83 struct rd *rd = data;
84 const char *name;
85 uint32_t idx;
86
87 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
88 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
89 return MNL_CB_ERROR;
90
91 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
92 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
93
94 return res_mr_line(rd, name, idx, tb);
95 }
96
97 int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
98 {
99 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
100 struct nlattr *nla_table, *nla_entry;
101 struct rd *rd = data;
102 int ret = MNL_CB_OK;
103 const char *name;
104 uint32_t idx;
105
106 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
107 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
108 !tb[RDMA_NLDEV_ATTR_RES_MR])
109 return MNL_CB_ERROR;
110
111 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
112 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
113 nla_table = tb[RDMA_NLDEV_ATTR_RES_MR];
114
115 mnl_attr_for_each_nested(nla_entry, nla_table) {
116 struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
117
118 ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
119 if (ret != MNL_CB_OK)
120 break;
121
122 ret = res_mr_line(rd, name, idx, nla_line);
123 if (ret != MNL_CB_OK)
124 break;
125 }
126 return ret;
127 }