aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatan Barak <matanb@mellanox.com>2017-04-04 06:31:43 -0400
committerDoug Ledford <dledford@redhat.com>2017-04-05 13:28:04 -0400
commit6be60aed126ccd4dfb4a60d1dc2ecec0bca21b2e (patch)
tree31764e2f00ed54dc264a7e71d1dd16830152b987
parent3832125624b75b54567be906e9aa67e1343be569 (diff)
IB/core: Add idr based standard types
This patch adds the standard idr based types. These types are used in downstream patches in order to initialize, destroy and lookup IB standard objects which are based on idr objects. An idr object requires filling out several parameters. Its op pointer should point to uverbs_idr_ops and its size should be at least the size of ib_uobject. We add a macro to make the type declaration easier. Signed-off-by: Matan Barak <matanb@mellanox.com> Reviewed-by: Yishai Hadas <yishaih@mellanox.com> Reviewed-by: Sean Hefty <sean.hefty@intel.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r--drivers/infiniband/core/Makefile2
-rw-r--r--drivers/infiniband/core/uverbs.h5
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c16
-rw-r--r--drivers/infiniband/core/uverbs_main.c8
-rw-r--r--drivers/infiniband/core/uverbs_std_types.c244
-rw-r--r--include/rdma/uverbs_std_types.h50
-rw-r--r--include/rdma/uverbs_types.h14
7 files changed, 329 insertions, 10 deletions
diff --git a/drivers/infiniband/core/Makefile b/drivers/infiniband/core/Makefile
index d29f910d98c9..6ebd9ad95010 100644
--- a/drivers/infiniband/core/Makefile
+++ b/drivers/infiniband/core/Makefile
@@ -30,4 +30,4 @@ ib_umad-y := user_mad.o
30ib_ucm-y := ucm.o 30ib_ucm-y := ucm.o
31 31
32ib_uverbs-y := uverbs_main.o uverbs_cmd.o uverbs_marshall.o \ 32ib_uverbs-y := uverbs_main.o uverbs_cmd.o uverbs_marshall.o \
33 rdma_core.o 33 rdma_core.o uverbs_std_types.o
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
index 6215735fa98e..cf0519dff3a2 100644
--- a/drivers/infiniband/core/uverbs.h
+++ b/drivers/infiniband/core/uverbs.h
@@ -201,9 +201,12 @@ void ib_uverbs_wq_event_handler(struct ib_event *event, void *context_ptr);
201void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr); 201void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr);
202void ib_uverbs_event_handler(struct ib_event_handler *handler, 202void ib_uverbs_event_handler(struct ib_event_handler *handler,
203 struct ib_event *event); 203 struct ib_event *event);
204void ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev, struct ib_xrcd *xrcd); 204int ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev, struct ib_xrcd *xrcd,
205 enum rdma_remove_reason why);
205 206
206int uverbs_dealloc_mw(struct ib_mw *mw); 207int uverbs_dealloc_mw(struct ib_mw *mw);
208void ib_uverbs_detach_umcast(struct ib_qp *qp,
209 struct ib_uqp_object *uobj);
207 210
208struct ib_uverbs_flow_spec { 211struct ib_uverbs_flow_spec {
209 union { 212 union {
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 03c4f68a88e1..79de69dc9f1c 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -958,19 +958,25 @@ out:
958 return ret; 958 return ret;
959} 959}
960 960
961void ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev, 961int ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev,
962 struct ib_xrcd *xrcd) 962 struct ib_xrcd *xrcd,
963 enum rdma_remove_reason why)
963{ 964{
964 struct inode *inode; 965 struct inode *inode;
966 int ret;
965 967
966 inode = xrcd->inode; 968 inode = xrcd->inode;
967 if (inode && !atomic_dec_and_test(&xrcd->usecnt)) 969 if (inode && !atomic_dec_and_test(&xrcd->usecnt))
968 return; 970 return 0;
969 971
970 ib_dealloc_xrcd(xrcd); 972 ret = ib_dealloc_xrcd(xrcd);
971 973
972 if (inode) 974 if (why == RDMA_REMOVE_DESTROY && ret)
975 atomic_inc(&xrcd->usecnt);
976 else if (inode)
973 xrcd_table_delete(dev, inode); 977 xrcd_table_delete(dev, inode);
978
979 return ret;
974} 980}
975 981
976ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, 982ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index f6812fb6cd0c..e1db6782d0d4 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -201,8 +201,8 @@ void ib_uverbs_release_uevent(struct ib_uverbs_file *file,
201 spin_unlock_irq(&file->async_file->lock); 201 spin_unlock_irq(&file->async_file->lock);
202} 202}
203 203
204static void ib_uverbs_detach_umcast(struct ib_qp *qp, 204void ib_uverbs_detach_umcast(struct ib_qp *qp,
205 struct ib_uqp_object *uobj) 205 struct ib_uqp_object *uobj)
206{ 206{
207 struct ib_uverbs_mcast_entry *mcast, *tmp; 207 struct ib_uverbs_mcast_entry *mcast, *tmp;
208 208
@@ -331,7 +331,9 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
331 container_of(uobj, struct ib_uxrcd_object, uobject); 331 container_of(uobj, struct ib_uxrcd_object, uobject);
332 332
333 idr_remove_uobj(uobj); 333 idr_remove_uobj(uobj);
334 ib_uverbs_dealloc_xrcd(file->device, xrcd); 334 ib_uverbs_dealloc_xrcd(file->device, xrcd,
335 file->ucontext ? RDMA_REMOVE_CLOSE :
336 RDMA_REMOVE_DRIVER_REMOVE);
335 kfree(uxrcd); 337 kfree(uxrcd);
336 } 338 }
337 mutex_unlock(&file->device->xrcd_tree_mutex); 339 mutex_unlock(&file->device->xrcd_tree_mutex);
diff --git a/drivers/infiniband/core/uverbs_std_types.c b/drivers/infiniband/core/uverbs_std_types.c
new file mode 100644
index 000000000000..a514556139e7
--- /dev/null
+++ b/drivers/infiniband/core/uverbs_std_types.c
@@ -0,0 +1,244 @@
1/*
2 * Copyright (c) 2017, Mellanox Technologies inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <rdma/uverbs_std_types.h>
34#include <rdma/ib_user_verbs.h>
35#include <rdma/ib_verbs.h>
36#include <linux/bug.h>
37#include <linux/file.h>
38#include "rdma_core.h"
39#include "uverbs.h"
40
41int uverbs_free_ah(struct ib_uobject *uobject,
42 enum rdma_remove_reason why)
43{
44 return ib_destroy_ah((struct ib_ah *)uobject->object);
45}
46
47int uverbs_free_flow(struct ib_uobject *uobject,
48 enum rdma_remove_reason why)
49{
50 return ib_destroy_flow((struct ib_flow *)uobject->object);
51}
52
53int uverbs_free_mw(struct ib_uobject *uobject,
54 enum rdma_remove_reason why)
55{
56 return uverbs_dealloc_mw((struct ib_mw *)uobject->object);
57}
58
59int uverbs_free_qp(struct ib_uobject *uobject,
60 enum rdma_remove_reason why)
61{
62 struct ib_qp *qp = uobject->object;
63 struct ib_uqp_object *uqp =
64 container_of(uobject, struct ib_uqp_object, uevent.uobject);
65 int ret;
66
67 if (why == RDMA_REMOVE_DESTROY) {
68 if (!list_empty(&uqp->mcast_list))
69 return -EBUSY;
70 } else if (qp == qp->real_qp) {
71 ib_uverbs_detach_umcast(qp, uqp);
72 }
73
74 ret = ib_destroy_qp(qp);
75 if (ret && why == RDMA_REMOVE_DESTROY)
76 return ret;
77
78 if (uqp->uxrcd)
79 atomic_dec(&uqp->uxrcd->refcnt);
80
81 ib_uverbs_release_uevent(uobject->context->ufile, &uqp->uevent);
82 return ret;
83}
84
85int uverbs_free_rwq_ind_tbl(struct ib_uobject *uobject,
86 enum rdma_remove_reason why)
87{
88 struct ib_rwq_ind_table *rwq_ind_tbl = uobject->object;
89 struct ib_wq **ind_tbl = rwq_ind_tbl->ind_tbl;
90 int ret;
91
92 ret = ib_destroy_rwq_ind_table(rwq_ind_tbl);
93 if (!ret || why != RDMA_REMOVE_DESTROY)