]>
Commit | Line | Data |
---|---|---|
33edc3b2 | 1 | /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ |
02d8883f LR |
2 | /* |
3 | * Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved. | |
4 | */ | |
5 | ||
6 | #ifndef _RDMA_RESTRACK_H_ | |
7 | #define _RDMA_RESTRACK_H_ | |
8 | ||
9 | #include <linux/typecheck.h> | |
02d8883f LR |
10 | #include <linux/sched.h> |
11 | #include <linux/kref.h> | |
12 | #include <linux/completion.h> | |
00313983 | 13 | #include <linux/sched/task.h> |
73937e8a | 14 | #include <uapi/rdma/rdma_netlink.h> |
fd47c2f9 | 15 | #include <linux/xarray.h> |
02d8883f | 16 | |
390d5772 JG |
17 | struct ib_device; |
18 | struct sk_buff; | |
19 | ||
02d8883f LR |
20 | /** |
21 | * enum rdma_restrack_type - HW objects to track | |
22 | */ | |
23 | enum rdma_restrack_type { | |
24 | /** | |
25 | * @RDMA_RESTRACK_PD: Protection domain (PD) | |
26 | */ | |
27 | RDMA_RESTRACK_PD, | |
28 | /** | |
29 | * @RDMA_RESTRACK_CQ: Completion queue (CQ) | |
30 | */ | |
31 | RDMA_RESTRACK_CQ, | |
32 | /** | |
33 | * @RDMA_RESTRACK_QP: Queue pair (QP) | |
34 | */ | |
35 | RDMA_RESTRACK_QP, | |
00313983 SW |
36 | /** |
37 | * @RDMA_RESTRACK_CM_ID: Connection Manager ID (CM_ID) | |
38 | */ | |
39 | RDMA_RESTRACK_CM_ID, | |
fccec5b8 SW |
40 | /** |
41 | * @RDMA_RESTRACK_MR: Memory Region (MR) | |
42 | */ | |
43 | RDMA_RESTRACK_MR, | |
60615210 LR |
44 | /** |
45 | * @RDMA_RESTRACK_CTX: Verbs contexts (CTX) | |
46 | */ | |
47 | RDMA_RESTRACK_CTX, | |
7ade1ff9 MZ |
48 | /** |
49 | * @RDMA_RESTRACK_COUNTER: Statistic Counter | |
50 | */ | |
51 | RDMA_RESTRACK_COUNTER, | |
02d8883f LR |
52 | /** |
53 | * @RDMA_RESTRACK_MAX: Last entry, used for array dclarations | |
54 | */ | |
55 | RDMA_RESTRACK_MAX | |
56 | }; | |
57 | ||
02d8883f LR |
58 | /** |
59 | * struct rdma_restrack_entry - metadata per-entry | |
60 | */ | |
61 | struct rdma_restrack_entry { | |
62 | /** | |
63 | * @valid: validity indicator | |
64 | * | |
65 | * The entries are filled during rdma_restrack_add, | |
66 | * can be attempted to be free during rdma_restrack_del. | |
67 | * | |
68 | * As an example for that, see mlx5 QPs with type MLX5_IB_QPT_HW_GSI | |
69 | */ | |
70 | bool valid; | |
2b1f7470 LR |
71 | /** |
72 | * @no_track: don't add this entry to restrack DB | |
73 | * | |
74 | * This field is used to mark an entry that doesn't need to be added to | |
75 | * internal restrack DB and presented later to the users at the nldev | |
76 | * query stage. | |
77 | */ | |
78 | u8 no_track : 1; | |
02d8883f LR |
79 | /* |
80 | * @kref: Protect destroy of the resource | |
81 | */ | |
82 | struct kref kref; | |
83 | /* | |
84 | * @comp: Signal that all consumers of resource are completed their work | |
85 | */ | |
86 | struct completion comp; | |
87 | /** | |
88 | * @task: owner of resource tracking entity | |
89 | * | |
90 | * There are two types of entities: created by user and created | |
91 | * by kernel. | |
92 | * | |
93 | * This is relevant for the entities created by users. | |
94 | * For the entities created by kernel, this pointer will be NULL. | |
95 | */ | |
96 | struct task_struct *task; | |
97 | /** | |
98 | * @kern_name: name of owner for the kernel created entities. | |
99 | */ | |
100 | const char *kern_name; | |
02d8883f LR |
101 | /** |
102 | * @type: various objects in restrack database | |
103 | */ | |
104 | enum rdma_restrack_type type; | |
af8d7037 SR |
105 | /** |
106 | * @user: user resource | |
107 | */ | |
108 | bool user; | |
fd47c2f9 LR |
109 | /** |
110 | * @id: ID to expose to users | |
111 | */ | |
112 | u32 id; | |
02d8883f LR |
113 | }; |
114 | ||
0ad699c0 | 115 | int rdma_restrack_count(struct ib_device *dev, |
60c78668 | 116 | enum rdma_restrack_type type); |
02d8883f LR |
117 | /** |
118 | * rdma_is_kernel_res() - check the owner of resource | |
119 | * @res: resource entry | |
120 | */ | |
b09c4d70 | 121 | static inline bool rdma_is_kernel_res(const struct rdma_restrack_entry *res) |
02d8883f | 122 | { |
af8d7037 | 123 | return !res->user; |
02d8883f LR |
124 | } |
125 | ||
126 | /** | |
127 | * rdma_restrack_get() - grab to protect resource from release | |
128 | * @res: resource entry | |
129 | */ | |
130 | int __must_check rdma_restrack_get(struct rdma_restrack_entry *res); | |
131 | ||
132 | /** | |
03286030 | 133 | * rdma_restrack_put() - release resource |
02d8883f LR |
134 | * @res: resource entry |
135 | */ | |
136 | int rdma_restrack_put(struct rdma_restrack_entry *res); | |
00313983 | 137 | |
73937e8a SW |
138 | /* |
139 | * Helper functions for rdma drivers when filling out | |
140 | * nldev driver attributes. | |
141 | */ | |
142 | int rdma_nl_put_driver_u32(struct sk_buff *msg, const char *name, u32 value); | |
143 | int rdma_nl_put_driver_u32_hex(struct sk_buff *msg, const char *name, | |
144 | u32 value); | |
145 | int rdma_nl_put_driver_u64(struct sk_buff *msg, const char *name, u64 value); | |
146 | int rdma_nl_put_driver_u64_hex(struct sk_buff *msg, const char *name, | |
147 | u64 value); | |
e1b95ae0 EA |
148 | int rdma_nl_put_driver_string(struct sk_buff *msg, const char *name, |
149 | const char *str); | |
4061ff7a EA |
150 | int rdma_nl_stat_hwcounter_entry(struct sk_buff *msg, const char *name, |
151 | u64 value); | |
e1b95ae0 | 152 | |
18c4c66f LR |
153 | struct rdma_restrack_entry *rdma_restrack_get_byid(struct ib_device *dev, |
154 | enum rdma_restrack_type type, | |
155 | u32 id); | |
2b1f7470 LR |
156 | |
157 | /** | |
158 | * rdma_restrack_no_track() - don't add resource to the DB | |
159 | * @res: resource entry | |
160 | * | |
161 | * Every user of thie API should be cross examined. | |
162 | * Probaby you don't need to use this function. | |
163 | */ | |
164 | static inline void rdma_restrack_no_track(struct rdma_restrack_entry *res) | |
165 | { | |
166 | res->no_track = true; | |
167 | } | |
168 | static inline bool rdma_restrack_is_tracked(struct rdma_restrack_entry *res) | |
169 | { | |
170 | return !res->no_track; | |
171 | } | |
02d8883f | 172 | #endif /* _RDMA_RESTRACK_H_ */ |