1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
4 * Authors: Leon Romanovsky <leonro@mellanox.com>
10 static int res_pd_line(struct rd
*rd
, const char *name
, int idx
,
11 struct nlattr
**nla_line
)
13 uint32_t local_dma_lkey
= 0, unsafe_global_rkey
= 0;
20 if (!nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
])
23 if (nla_line
[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY
])
24 local_dma_lkey
= mnl_attr_get_u32(
25 nla_line
[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY
]);
27 users
= mnl_attr_get_u64(nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
28 if (rd_is_filtered_attr(rd
, "users", users
,
29 nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]))
32 if (nla_line
[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY
])
33 unsafe_global_rkey
= mnl_attr_get_u32(
34 nla_line
[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY
]);
36 if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
]) {
37 pid
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
38 comm
= get_task_name(pid
);
41 if (rd_is_filtered_attr(rd
, "pid", pid
,
42 nla_line
[RDMA_NLDEV_ATTR_RES_PID
]))
45 if (nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
])
46 ctxn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
48 if (rd_is_filtered_attr(rd
, "ctxn", ctxn
,
49 nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]))
52 if (nla_line
[RDMA_NLDEV_ATTR_RES_PDN
])
53 pdn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_PDN
]);
54 if (rd_is_filtered_attr(rd
, "pdn", pdn
,
55 nla_line
[RDMA_NLDEV_ATTR_RES_PDN
]))
58 if (nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
])
59 /* discard const from mnl_attr_get_str */
60 comm
= (char *)mnl_attr_get_str(
61 nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
]);
63 open_json_object(NULL
);
64 print_dev(rd
, idx
, name
);
65 res_print_uint(rd
, "pdn", pdn
, nla_line
[RDMA_NLDEV_ATTR_RES_PDN
]);
66 print_key(rd
, "local_dma_lkey", local_dma_lkey
,
67 nla_line
[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY
]);
68 res_print_uint(rd
, "users", users
,
69 nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
70 print_key(rd
, "unsafe_global_rkey", unsafe_global_rkey
,
71 nla_line
[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY
]);
72 res_print_uint(rd
, "ctxn", ctxn
, nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
73 res_print_uint(rd
, "pid", pid
, nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
74 print_comm(rd
, comm
, nla_line
);
76 print_driver_table(rd
, nla_line
[RDMA_NLDEV_ATTR_DRIVER
]);
79 out
: if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
])
84 int res_pd_idx_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
86 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
91 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
92 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
])
95 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
96 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
98 return res_pd_line(rd
, name
, idx
, tb
);
101 int res_pd_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
103 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
104 struct nlattr
*nla_table
, *nla_entry
;
105 struct rd
*rd
= data
;
110 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
111 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
] ||
112 !tb
[RDMA_NLDEV_ATTR_RES_PD
])
115 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
116 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
117 nla_table
= tb
[RDMA_NLDEV_ATTR_RES_PD
];
119 mnl_attr_for_each_nested(nla_entry
, nla_table
) {
120 struct nlattr
*nla_line
[RDMA_NLDEV_ATTR_MAX
] = {};
122 ret
= mnl_attr_parse_nested(nla_entry
, rd_attr_cb
, nla_line
);
123 if (ret
!= MNL_CB_OK
)
126 ret
= res_pd_line(rd
, name
, idx
, nla_line
);
127 if (ret
!= MNL_CB_OK
)