1
2
3
4
5
6#ifndef _RDMA_RESTRACK_H_
7#define _RDMA_RESTRACK_H_
8
9#include <linux/typecheck.h>
10#include <linux/sched.h>
11#include <linux/kref.h>
12#include <linux/completion.h>
13#include <linux/sched/task.h>
14#include <uapi/rdma/rdma_netlink.h>
15#include <linux/xarray.h>
16
17struct ib_device;
18struct sk_buff;
19
20
21
22
23enum rdma_restrack_type {
24
25
26
27 RDMA_RESTRACK_PD,
28
29
30
31 RDMA_RESTRACK_CQ,
32
33
34
35 RDMA_RESTRACK_QP,
36
37
38
39 RDMA_RESTRACK_CM_ID,
40
41
42
43 RDMA_RESTRACK_MR,
44
45
46
47 RDMA_RESTRACK_CTX,
48
49
50
51 RDMA_RESTRACK_COUNTER,
52
53
54
55 RDMA_RESTRACK_SRQ,
56
57
58
59 RDMA_RESTRACK_MAX
60};
61
62
63
64
65struct rdma_restrack_entry {
66
67
68
69
70
71
72
73
74 bool valid;
75
76
77
78
79
80
81
82 u8 no_track : 1;
83
84
85
86 struct kref kref;
87
88
89
90 struct completion comp;
91
92
93
94
95
96
97
98
99
100 struct task_struct *task;
101
102
103
104 const char *kern_name;
105
106
107
108 enum rdma_restrack_type type;
109
110
111
112 bool user;
113
114
115
116 u32 id;
117};
118
119int rdma_restrack_count(struct ib_device *dev,
120 enum rdma_restrack_type type);
121
122
123
124
125static inline bool rdma_is_kernel_res(const struct rdma_restrack_entry *res)
126{
127 return !res->user;
128}
129
130
131
132
133
134int __must_check rdma_restrack_get(struct rdma_restrack_entry *res);
135
136
137
138
139
140int rdma_restrack_put(struct rdma_restrack_entry *res);
141
142
143
144
145
146int rdma_nl_put_driver_u32(struct sk_buff *msg, const char *name, u32 value);
147int rdma_nl_put_driver_u32_hex(struct sk_buff *msg, const char *name,
148 u32 value);
149int rdma_nl_put_driver_u64(struct sk_buff *msg, const char *name, u64 value);
150int rdma_nl_put_driver_u64_hex(struct sk_buff *msg, const char *name,
151 u64 value);
152int rdma_nl_put_driver_string(struct sk_buff *msg, const char *name,
153 const char *str);
154int rdma_nl_stat_hwcounter_entry(struct sk_buff *msg, const char *name,
155 u64 value);
156
157struct rdma_restrack_entry *rdma_restrack_get_byid(struct ib_device *dev,
158 enum rdma_restrack_type type,
159 u32 id);
160
161
162
163
164
165
166
167
168static inline void rdma_restrack_no_track(struct rdma_restrack_entry *res)
169{
170 res->no_track = true;
171}
172static inline bool rdma_restrack_is_tracked(struct rdma_restrack_entry *res)
173{
174 return !res->no_track;
175}
176#endif
177