]> git.proxmox.com Git - mirror_iproute2.git/blame - rdma/res-mr.c
Merge branch 'main' 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
e2bbf737
MG
10static int res_mr_line_raw(struct rd *rd, const char *name, int idx,
11 struct nlattr **nla_line)
12{
13 if (!nla_line[RDMA_NLDEV_ATTR_RES_RAW])
14 return MNL_CB_ERROR;
15
16 open_json_object(NULL);
17 print_dev(rd, idx, name);
18 print_raw_data(rd, nla_line);
19 newline(rd);
20
21 return MNL_CB_OK;
22}
23
46695227 24static int res_mr_line(struct rd *rd, const char *name, int idx,
5a823593 25 struct nlattr **nla_line)
46695227 26{
46695227
LR
27 uint32_t rkey = 0, lkey = 0;
28 uint64_t iova = 0, mrlen;
29 char *comm = NULL;
30 uint32_t pdn = 0;
31 uint32_t mrn = 0;
32 uint32_t pid = 0;
46695227 33
f9313484 34 if (!nla_line[RDMA_NLDEV_ATTR_RES_MRLEN])
46695227 35 return MNL_CB_ERROR;
46695227
LR
36
37 if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY])
38 rkey = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_RKEY]);
39 if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY])
40 lkey = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LKEY]);
41 if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA])
42 iova = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_IOVA]);
43
44 mrlen = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]);
78728b7e
LR
45 if (rd_is_filtered_attr(rd, "mrlen", mrlen,
46 nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]))
46695227
LR
47 goto out;
48
49 if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
50 pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
51 comm = get_task_name(pid);
52 }
53
78728b7e
LR
54 if (rd_is_filtered_attr(rd, "pid", pid,
55 nla_line[RDMA_NLDEV_ATTR_RES_PID]))
46695227
LR
56 goto out;
57
58 if (nla_line[RDMA_NLDEV_ATTR_RES_MRN])
59 mrn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_MRN]);
78728b7e
LR
60 if (rd_is_filtered_attr(rd, "mrn", mrn,
61 nla_line[RDMA_NLDEV_ATTR_RES_MRN]))
46695227
LR
62 goto out;
63
64 if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
65 pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
78728b7e
LR
66 if (rd_is_filtered_attr(rd, "pdn", pdn,
67 nla_line[RDMA_NLDEV_ATTR_RES_PDN]))
46695227
LR
68 goto out;
69
70 if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
71 /* discard const from mnl_attr_get_str */
72 comm = (char *)mnl_attr_get_str(
73 nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
b0a688a5 74 open_json_object(NULL);
46695227 75 print_dev(rd, idx, name);
127ff956
LR
76 res_print_uint(rd, "mrn", mrn, nla_line[RDMA_NLDEV_ATTR_RES_MRN]);
77 print_key(rd, "rkey", rkey, nla_line[RDMA_NLDEV_ATTR_RES_RKEY]);
78 print_key(rd, "lkey", lkey, nla_line[RDMA_NLDEV_ATTR_RES_LKEY]);
79 print_key(rd, "iova", iova, nla_line[RDMA_NLDEV_ATTR_RES_IOVA]);
80 res_print_uint(rd, "mrlen", mrlen, nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]);
81 res_print_uint(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
82 res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
46695227
LR
83 print_comm(rd, comm, nla_line);
84
46695227 85 print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
e2bbf737 86 print_raw_data(rd, nla_line);
46695227
LR
87 newline(rd);
88
89out:
90 if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
91 free(comm);
92 return MNL_CB_OK;
93}
5a823593
LR
94
95int res_mr_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
96{
97 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
98 struct rd *rd = data;
99 const char *name;
100 uint32_t idx;
101
102 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
103 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
104 return MNL_CB_ERROR;
105
106 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
107 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
108
e2bbf737
MG
109 return (rd->show_raw) ? res_mr_line_raw(rd, name, idx, tb) :
110 res_mr_line(rd, name, idx, tb);
5a823593
LR
111}
112
42ed283e
LR
113int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
114{
115 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
116 struct nlattr *nla_table, *nla_entry;
117 struct rd *rd = data;
46695227 118 int ret = MNL_CB_OK;
42ed283e
LR
119 const char *name;
120 uint32_t idx;
121
122 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
123 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
124 !tb[RDMA_NLDEV_ATTR_RES_MR])
125 return MNL_CB_ERROR;
126
127 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
128 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
129 nla_table = tb[RDMA_NLDEV_ATTR_RES_MR];
130
131 mnl_attr_for_each_nested(nla_entry, nla_table) {
5a823593
LR
132 struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
133
134 ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
135 if (ret != MNL_CB_OK)
136 break;
46695227 137
e2bbf737
MG
138 ret = (rd->show_raw) ? res_mr_line_raw(rd, name, idx, nla_line) :
139 res_mr_line(rd, name, idx, nla_line);
46695227
LR
140 if (ret != MNL_CB_OK)
141 break;
42ed283e 142 }
46695227 143 return ret;
42ed283e 144}