dm writecache: add cond_resched to loop in persistent_memory_claim()
[linux/fpc-iii.git] / drivers / infiniband / hw / mlx5 / restrack.c
blob8f6c04f12531c113c436808c1e847920e6e2c720
1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /*
3 * Copyright (c) 2019, Mellanox Technologies inc. All rights reserved.
4 */
6 #include <uapi/rdma/rdma_netlink.h>
7 #include <rdma/ib_umem_odp.h>
8 #include <rdma/restrack.h>
9 #include "mlx5_ib.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))
19 return 0;
21 table_attr = nla_nest_start(msg,
22 RDMA_NLDEV_ATTR_STAT_HWCOUNTERS);
24 if (!table_attr)
25 goto err;
27 if (rdma_nl_stat_hwcounter_entry(msg, "page_faults",
28 atomic64_read(&mr->odp_stats.faults)))
29 goto err_table;
30 if (rdma_nl_stat_hwcounter_entry(
31 msg, "page_invalidations",
32 atomic64_read(&mr->odp_stats.invalidations)))
33 goto err_table;
35 nla_nest_end(msg, table_attr);
36 return 0;
38 err_table:
39 nla_nest_cancel(msg, table_attr);
40 err:
41 return -EMSGSIZE;
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))
52 return 0;
54 table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER);
55 if (!table_attr)
56 goto err;
58 if (mr->is_odp_implicit) {
59 if (rdma_nl_put_driver_string(msg, "odp", "implicit"))
60 goto err;
61 } else {
62 if (rdma_nl_put_driver_string(msg, "odp", "explicit"))
63 goto err;
66 nla_nest_end(msg, table_attr);
67 return 0;
69 err:
70 nla_nest_cancel(msg, table_attr);
71 return -EMSGSIZE;
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);
80 return 0;
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);
89 return 0;