1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
4 * Authors: Leon Romanovsky <leonro@mellanox.com>
10 static int res_mr_line(struct rd
*rd
, const char *name
, int idx
,
11 struct nlattr
**nla_line
)
13 uint32_t rkey
= 0, lkey
= 0;
14 uint64_t iova
= 0, mrlen
;
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
])) {
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
]);
33 mrlen
= mnl_attr_get_u64(nla_line
[RDMA_NLDEV_ATTR_RES_MRLEN
]);
34 if (rd_is_filtered_attr(rd
, "mrlen", mrlen
,
35 nla_line
[RDMA_NLDEV_ATTR_RES_MRLEN
]))
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
);
43 if (rd_is_filtered_attr(rd
, "pid", pid
,
44 nla_line
[RDMA_NLDEV_ATTR_RES_PID
]))
47 if (nla_line
[RDMA_NLDEV_ATTR_RES_MRN
])
48 mrn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_MRN
]);
49 if (rd_is_filtered_attr(rd
, "mrn", mrn
,
50 nla_line
[RDMA_NLDEV_ATTR_RES_MRN
]))
53 if (nla_line
[RDMA_NLDEV_ATTR_RES_PDN
])
54 pdn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_PDN
]);
55 if (rd_is_filtered_attr(rd
, "pdn", pdn
,
56 nla_line
[RDMA_NLDEV_ATTR_RES_PDN
]))
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
]);
65 jsonw_start_array(rd
->jw
);
67 print_dev(rd
, idx
, name
);
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
]);
75 print_comm(rd
, comm
, nla_line
);
77 print_driver_table(rd
, nla_line
[RDMA_NLDEV_ATTR_DRIVER
]);
81 if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
])
86 int res_mr_idx_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
88 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
93 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
94 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
])
97 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
98 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
100 return res_mr_line(rd
, name
, idx
, tb
);
103 int res_mr_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
105 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
106 struct nlattr
*nla_table
, *nla_entry
;
107 struct rd
*rd
= data
;
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
])
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
];
121 mnl_attr_for_each_nested(nla_entry
, nla_table
) {
122 struct nlattr
*nla_line
[RDMA_NLDEV_ATTR_MAX
] = {};
124 ret
= mnl_attr_parse_nested(nla_entry
, rd_attr_cb
, nla_line
);
125 if (ret
!= MNL_CB_OK
)
128 ret
= res_mr_line(rd
, name
, idx
, nla_line
);
129 if (ret
!= MNL_CB_OK
)