]> git.proxmox.com Git - mirror_iproute2.git/blame - rdma/res-mr.c
Merge branch 'master' into next
[mirror_iproute2.git] / rdma / res-mr.c
CommitLineData
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 10static 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]);
b0a688a5 60 open_json_object(NULL);
46695227 61 print_dev(rd, idx, name);
127ff956
LR
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]);
46695227
LR
69 print_comm(rd, comm, nla_line);
70
46695227
LR
71 print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
72 newline(rd);
73
74out:
75 if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
76 free(comm);
77 return MNL_CB_OK;
78}
5a823593
LR
79
80int 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
42ed283e
LR
97int 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;
46695227 102 int ret = MNL_CB_OK;
42ed283e
LR
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) {
5a823593
LR
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;
46695227 121
5a823593 122 ret = res_mr_line(rd, name, idx, nla_line);
46695227
LR
123 if (ret != MNL_CB_OK)
124 break;
42ed283e 125 }
46695227 126 return ret;
42ed283e 127}