1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
3 * Copyright (c) 2019, Mellanox Technologies inc. All rights reserved.
6 #include <uapi/rdma/rdma_netlink.h>
7 #include <rdma/ib_umem_odp.h>
8 #include <rdma/restrack.h>
11 static int fill_stat_mr_entry(struct sk_buff
*msg
,
12 struct rdma_restrack_entry
*res
)
14 struct ib_mr
*ibmr
= container_of(res
, struct ib_mr
, res
);
15 struct mlx5_ib_mr
*mr
= to_mmr(ibmr
);
16 struct nlattr
*table_attr
;
18 if (!(mr
->access_flags
& IB_ACCESS_ON_DEMAND
))
21 table_attr
= nla_nest_start(msg
,
22 RDMA_NLDEV_ATTR_STAT_HWCOUNTERS
);
27 if (rdma_nl_stat_hwcounter_entry(msg
, "page_faults",
28 atomic64_read(&mr
->odp_stats
.faults
)))
30 if (rdma_nl_stat_hwcounter_entry(
31 msg
, "page_invalidations",
32 atomic64_read(&mr
->odp_stats
.invalidations
)))
35 nla_nest_end(msg
, table_attr
);
39 nla_nest_cancel(msg
, table_attr
);
44 static int fill_res_mr_entry(struct sk_buff
*msg
,
45 struct rdma_restrack_entry
*res
)
47 struct ib_mr
*ibmr
= container_of(res
, struct ib_mr
, res
);
48 struct mlx5_ib_mr
*mr
= to_mmr(ibmr
);
49 struct nlattr
*table_attr
;
51 if (!(mr
->access_flags
& IB_ACCESS_ON_DEMAND
))
54 table_attr
= nla_nest_start(msg
, RDMA_NLDEV_ATTR_DRIVER
);
58 if (mr
->is_odp_implicit
) {
59 if (rdma_nl_put_driver_string(msg
, "odp", "implicit"))
62 if (rdma_nl_put_driver_string(msg
, "odp", "explicit"))
66 nla_nest_end(msg
, table_attr
);
70 nla_nest_cancel(msg
, table_attr
);
74 int mlx5_ib_fill_res_entry(struct sk_buff
*msg
,
75 struct rdma_restrack_entry
*res
)
77 if (res
->type
== RDMA_RESTRACK_MR
)
78 return fill_res_mr_entry(msg
, res
);
83 int mlx5_ib_fill_stat_entry(struct sk_buff
*msg
,
84 struct rdma_restrack_entry
*res
)
86 if (res
->type
== RDMA_RESTRACK_MR
)
87 return fill_stat_mr_entry(msg
, res
);