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
] ||
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_LOCAL_DMA_LKEY
])
27 local_dma_lkey
= mnl_attr_get_u32(
28 nla_line
[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY
]);
30 users
= mnl_attr_get_u64(nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
31 if (rd_is_filtered_attr(rd
, "users", users
,
32 nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]))
35 if (nla_line
[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY
])
36 unsafe_global_rkey
= mnl_attr_get_u32(
37 nla_line
[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY
]);
39 if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
]) {
40 pid
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
41 comm
= get_task_name(pid
);
44 if (rd_is_filtered_attr(rd
, "pid", pid
,
45 nla_line
[RDMA_NLDEV_ATTR_RES_PID
]))
48 if (nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
])
49 ctxn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
51 if (rd_is_filtered_attr(rd
, "ctxn", ctxn
,
52 nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]))
55 if (nla_line
[RDMA_NLDEV_ATTR_RES_PDN
])
56 pdn
= mnl_attr_get_u32(nla_line
[RDMA_NLDEV_ATTR_RES_PDN
]);
57 if (rd_is_filtered_attr(rd
, "pdn", pdn
,
58 nla_line
[RDMA_NLDEV_ATTR_RES_PDN
]))
61 if (nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
])
62 /* discard const from mnl_attr_get_str */
63 comm
= (char *)mnl_attr_get_str(
64 nla_line
[RDMA_NLDEV_ATTR_RES_KERN_NAME
]);
67 jsonw_start_array(rd
->jw
);
69 print_dev(rd
, idx
, name
);
70 res_print_uint(rd
, "pdn", pdn
, nla_line
[RDMA_NLDEV_ATTR_RES_PDN
]);
71 print_key(rd
, "local_dma_lkey", local_dma_lkey
,
72 nla_line
[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY
]);
73 res_print_uint(rd
, "users", users
,
74 nla_line
[RDMA_NLDEV_ATTR_RES_USECNT
]);
75 print_key(rd
, "unsafe_global_rkey", unsafe_global_rkey
,
76 nla_line
[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY
]);
77 res_print_uint(rd
, "ctxn", ctxn
, nla_line
[RDMA_NLDEV_ATTR_RES_CTXN
]);
78 res_print_uint(rd
, "pid", pid
, nla_line
[RDMA_NLDEV_ATTR_RES_PID
]);
79 print_comm(rd
, comm
, nla_line
);
81 print_driver_table(rd
, nla_line
[RDMA_NLDEV_ATTR_DRIVER
]);
84 out
: if (nla_line
[RDMA_NLDEV_ATTR_RES_PID
])
89 int res_pd_idx_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
91 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
96 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
97 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
])
100 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
101 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
103 return res_pd_line(rd
, name
, idx
, tb
);
106 int res_pd_parse_cb(const struct nlmsghdr
*nlh
, void *data
)
108 struct nlattr
*tb
[RDMA_NLDEV_ATTR_MAX
] = {};
109 struct nlattr
*nla_table
, *nla_entry
;
110 struct rd
*rd
= data
;
115 mnl_attr_parse(nlh
, 0, rd_attr_cb
, tb
);
116 if (!tb
[RDMA_NLDEV_ATTR_DEV_INDEX
] || !tb
[RDMA_NLDEV_ATTR_DEV_NAME
] ||
117 !tb
[RDMA_NLDEV_ATTR_RES_PD
])
120 name
= mnl_attr_get_str(tb
[RDMA_NLDEV_ATTR_DEV_NAME
]);
121 idx
= mnl_attr_get_u32(tb
[RDMA_NLDEV_ATTR_DEV_INDEX
]);
122 nla_table
= tb
[RDMA_NLDEV_ATTR_RES_PD
];
124 mnl_attr_for_each_nested(nla_entry
, nla_table
) {
125 struct nlattr
*nla_line
[RDMA_NLDEV_ATTR_MAX
] = {};
127 ret
= mnl_attr_parse_nested(nla_entry
, rd_attr_cb
, nla_line
);
128 if (ret
!= MNL_CB_OK
)
131 ret
= res_pd_line(rd
, name
, idx
, nla_line
);
132 if (ret
!= MNL_CB_OK
)