pd.c (8cbfaac3d0974ecf53b28db23ea8c105f491bb35) | pd.c (21a428a019c9a6d133e745b529b9bf18c1187e70) |
---|---|
1/* 2 * Copyright(c) 2016 Intel Corporation. 3 * 4 * This file is provided under a dual BSD/GPLv2 license. When using or 5 * redistributing this file, you may do so under either license. 6 * 7 * GPL LICENSE SUMMARY 8 * --- 36 unchanged lines hidden (view full) --- 45 * 46 */ 47 48#include <linux/slab.h> 49#include "pd.h" 50 51/** 52 * rvt_alloc_pd - allocate a protection domain | 1/* 2 * Copyright(c) 2016 Intel Corporation. 3 * 4 * This file is provided under a dual BSD/GPLv2 license. When using or 5 * redistributing this file, you may do so under either license. 6 * 7 * GPL LICENSE SUMMARY 8 * --- 36 unchanged lines hidden (view full) --- 45 * 46 */ 47 48#include <linux/slab.h> 49#include "pd.h" 50 51/** 52 * rvt_alloc_pd - allocate a protection domain |
53 * @ibdev: ib device | 53 * @ibpd: PD |
54 * @context: optional user context 55 * @udata: optional user data 56 * 57 * Allocate and keep track of a PD. 58 * 59 * Return: 0 on success 60 */ | 54 * @context: optional user context 55 * @udata: optional user data 56 * 57 * Allocate and keep track of a PD. 58 * 59 * Return: 0 on success 60 */ |
61struct ib_pd *rvt_alloc_pd(struct ib_device *ibdev, 62 struct ib_ucontext *context, 63 struct ib_udata *udata) | 61int rvt_alloc_pd(struct ib_pd *ibpd, struct ib_ucontext *context, 62 struct ib_udata *udata) |
64{ | 63{ |
64 struct ib_device *ibdev = ibpd->device; |
|
65 struct rvt_dev_info *dev = ib_to_rvt(ibdev); | 65 struct rvt_dev_info *dev = ib_to_rvt(ibdev); |
66 struct rvt_pd *pd; 67 struct ib_pd *ret; | 66 struct rvt_pd *pd = ibpd_to_rvtpd(ibpd); 67 int ret = 0; |
68 | 68 |
69 pd = kzalloc(sizeof(*pd), GFP_KERNEL); 70 if (!pd) { 71 ret = ERR_PTR(-ENOMEM); 72 goto bail; 73 } | |
74 /* 75 * While we could continue allocating protecetion domains, being 76 * constrained only by system resources. The IBTA spec defines that 77 * there is a max_pd limit that can be set and we need to check for 78 * that. 79 */ 80 81 spin_lock(&dev->n_pds_lock); 82 if (dev->n_pds_allocated == dev->dparms.props.max_pd) { 83 spin_unlock(&dev->n_pds_lock); | 69 /* 70 * While we could continue allocating protecetion domains, being 71 * constrained only by system resources. The IBTA spec defines that 72 * there is a max_pd limit that can be set and we need to check for 73 * that. 74 */ 75 76 spin_lock(&dev->n_pds_lock); 77 if (dev->n_pds_allocated == dev->dparms.props.max_pd) { 78 spin_unlock(&dev->n_pds_lock); |
84 kfree(pd); 85 ret = ERR_PTR(-ENOMEM); | 79 ret = -ENOMEM; |
86 goto bail; 87 } 88 89 dev->n_pds_allocated++; 90 spin_unlock(&dev->n_pds_lock); 91 92 /* ib_alloc_pd() will initialize pd->ibpd. */ 93 pd->user = !!udata; 94 | 80 goto bail; 81 } 82 83 dev->n_pds_allocated++; 84 spin_unlock(&dev->n_pds_lock); 85 86 /* ib_alloc_pd() will initialize pd->ibpd. */ 87 pd->user = !!udata; 88 |
95 ret = &pd->ibpd; 96 | |
97bail: 98 return ret; 99} 100 101/** 102 * rvt_dealloc_pd - Free PD 103 * @ibpd: Free up PD 104 * 105 * Return: always 0 106 */ | 89bail: 90 return ret; 91} 92 93/** 94 * rvt_dealloc_pd - Free PD 95 * @ibpd: Free up PD 96 * 97 * Return: always 0 98 */ |
107int rvt_dealloc_pd(struct ib_pd *ibpd) | 99void rvt_dealloc_pd(struct ib_pd *ibpd) |
108{ | 100{ |
109 struct rvt_pd *pd = ibpd_to_rvtpd(ibpd); | |
110 struct rvt_dev_info *dev = ib_to_rvt(ibpd->device); 111 112 spin_lock(&dev->n_pds_lock); 113 dev->n_pds_allocated--; 114 spin_unlock(&dev->n_pds_lock); | 101 struct rvt_dev_info *dev = ib_to_rvt(ibpd->device); 102 103 spin_lock(&dev->n_pds_lock); 104 dev->n_pds_allocated--; 105 spin_unlock(&dev->n_pds_lock); |
115 116 kfree(pd); 117 118 return 0; | |
119} | 106} |