1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright(c) 2016 Intel Corporation.
6 #include <linux/slab.h>
10 * rvt_alloc_pd - allocate a protection domain
12 * @udata: optional user data
14 * Allocate and keep track of a PD.
16 * Return: 0 on success
18 int rvt_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
20 struct ib_device *ibdev = ibpd->device;
21 struct rvt_dev_info *dev = ib_to_rvt(ibdev);
22 struct rvt_pd *pd = ibpd_to_rvtpd(ibpd);
26 * While we could continue allocating protecetion domains, being
27 * constrained only by system resources. The IBTA spec defines that
28 * there is a max_pd limit that can be set and we need to check for
32 spin_lock(&dev->n_pds_lock);
33 if (dev->n_pds_allocated == dev->dparms.props.max_pd) {
34 spin_unlock(&dev->n_pds_lock);
39 dev->n_pds_allocated++;
40 spin_unlock(&dev->n_pds_lock);
42 /* ib_alloc_pd() will initialize pd->ibpd. */
50 * rvt_dealloc_pd - Free PD
52 * @udata: Valid user data or NULL for kernel object
56 int rvt_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
58 struct rvt_dev_info *dev = ib_to_rvt(ibpd->device);
60 spin_lock(&dev->n_pds_lock);
61 dev->n_pds_allocated--;
62 spin_unlock(&dev->n_pds_lock);