Lines Matching +full:resource +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
3 * Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved.
18 * rdma_restrack_init() - initialize and allocate resource tracking
28 dev->res = kcalloc(RDMA_RESTRACK_MAX, sizeof(*rt), GFP_KERNEL); in rdma_restrack_init()
29 if (!dev->res) in rdma_restrack_init()
30 return -ENOMEM; in rdma_restrack_init()
32 rt = dev->res; in rdma_restrack_init()
41 * rdma_restrack_clean() - clean resource tracking
46 struct rdma_restrack_root *rt = dev->res; in rdma_restrack_clean()
50 struct xarray *xa = &dev->res[i].xa; in rdma_restrack_clean()
59 * rdma_restrack_count() - the current usage of specific object
67 struct rdma_restrack_root *rt = &dev->res[type]; in rdma_restrack_count()
69 XA_STATE(xas, &rt->xa, 0); in rdma_restrack_count()
72 xa_lock(&rt->xa); in rdma_restrack_count()
74 if (xa_get_mark(&rt->xa, e->id, RESTRACK_DD) && !show_details) in rdma_restrack_count()
78 xa_unlock(&rt->xa); in rdma_restrack_count()
85 switch (res->type) { in res_to_dev()
87 return container_of(res, struct ib_pd, res)->device; in res_to_dev()
89 return container_of(res, struct ib_cq, res)->device; in res_to_dev()
91 return container_of(res, struct ib_qp, res)->device; in res_to_dev()
94 res)->id.device; in res_to_dev()
96 return container_of(res, struct ib_mr, res)->device; in res_to_dev()
98 return container_of(res, struct ib_ucontext, res)->device; in res_to_dev()
100 return container_of(res, struct rdma_counter, res)->device; in res_to_dev()
102 return container_of(res, struct ib_srq, res)->device; in res_to_dev()
104 WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type); in res_to_dev()
110 * rdma_restrack_attach_task() - attach the task onto this resource,
112 * @res: resource entry
121 if (res->task) in rdma_restrack_attach_task()
122 put_task_struct(res->task); in rdma_restrack_attach_task()
124 res->task = task; in rdma_restrack_attach_task()
125 res->user = true; in rdma_restrack_attach_task()
129 * rdma_restrack_set_name() - set the task for this resource
130 * @res: resource entry
136 res->kern_name = caller; in rdma_restrack_set_name()
145 * rdma_restrack_parent_name() - set the restrack name properties based
147 * @dst: destination resource entry
148 * @parent: parent resource entry
154 dst->kern_name = parent->kern_name; in rdma_restrack_parent_name()
156 rdma_restrack_attach_task(dst, parent->task); in rdma_restrack_parent_name()
161 * rdma_restrack_new() - Initializes new restrack entry to allow _put() interface
169 kref_init(&res->kref); in rdma_restrack_new()
170 init_completion(&res->comp); in rdma_restrack_new()
171 res->type = type; in rdma_restrack_new()
176 * rdma_restrack_add() - add object to the reource tracking database
177 * @res: resource entry
188 if (res->no_track) in rdma_restrack_add()
191 rt = &dev->res[res->type]; in rdma_restrack_add()
193 if (res->type == RDMA_RESTRACK_QP) { in rdma_restrack_add()
197 WARN_ONCE(qp->qp_num >> 24 || qp->port >> 8, in rdma_restrack_add()
198 "QP number 0x%0X and port 0x%0X", qp->qp_num, in rdma_restrack_add()
199 qp->port); in rdma_restrack_add()
200 res->id = qp->qp_num; in rdma_restrack_add()
201 if (qp->qp_type == IB_QPT_SMI || qp->qp_type == IB_QPT_GSI) in rdma_restrack_add()
202 res->id |= qp->port << 24; in rdma_restrack_add()
203 ret = xa_insert(&rt->xa, res->id, res, GFP_KERNEL); in rdma_restrack_add()
205 res->id = 0; in rdma_restrack_add()
207 if (qp->qp_type >= IB_QPT_DRIVER) in rdma_restrack_add()
208 xa_set_mark(&rt->xa, res->id, RESTRACK_DD); in rdma_restrack_add()
209 } else if (res->type == RDMA_RESTRACK_COUNTER) { in rdma_restrack_add()
214 ret = xa_insert(&rt->xa, counter->id, res, GFP_KERNEL); in rdma_restrack_add()
215 res->id = ret ? 0 : counter->id; in rdma_restrack_add()
217 ret = xa_alloc_cyclic(&rt->xa, &res->id, res, xa_limit_32b, in rdma_restrack_add()
218 &rt->next_id, GFP_KERNEL); in rdma_restrack_add()
224 res->valid = true; in rdma_restrack_add()
230 return kref_get_unless_zero(&res->kref); in rdma_restrack_get()
235 * rdma_restrack_get_byid() - translate from ID to restrack object
237 * @type: resource track type
238 * @id: ID to take a look
240 * Return: Pointer to restrack entry or -ENOENT in case of error.
244 enum rdma_restrack_type type, u32 id) in rdma_restrack_get_byid() argument
246 struct rdma_restrack_root *rt = &dev->res[type]; in rdma_restrack_get_byid()
249 xa_lock(&rt->xa); in rdma_restrack_get_byid()
250 res = xa_load(&rt->xa, id); in rdma_restrack_get_byid()
252 res = ERR_PTR(-ENOENT); in rdma_restrack_get_byid()
253 xa_unlock(&rt->xa); in rdma_restrack_get_byid()
264 if (res->task) { in restrack_release()
265 put_task_struct(res->task); in restrack_release()
266 res->task = NULL; in restrack_release()
268 complete(&res->comp); in restrack_release()
273 return kref_put(&res->kref, restrack_release); in rdma_restrack_put()
278 * rdma_restrack_del() - delete object from the reource tracking database
279 * @res: resource entry
287 if (!res->valid) { in rdma_restrack_del()
288 if (res->task) { in rdma_restrack_del()
289 put_task_struct(res->task); in rdma_restrack_del()
290 res->task = NULL; in rdma_restrack_del()
295 if (res->no_track) in rdma_restrack_del()
302 rt = &dev->res[res->type]; in rdma_restrack_del()
304 old = xa_erase(&rt->xa, res->id); in rdma_restrack_del()
308 res->valid = false; in rdma_restrack_del()
310 wait_for_completion(&res->comp); in rdma_restrack_del()