diff options
author | Roland Dreier <rolandd@cisco.com> | 2005-07-07 20:57:16 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-07-07 21:23:49 -0400 |
commit | 5e0b537c7d94efe3fea0fee8e2533c3231a8af75 (patch) | |
tree | 108ecc2bd5c9fabc86f1c51b2e77421cf78ce433 /drivers/infiniband/hw/mthca/mthca_provider.c | |
parent | 56483ec1b70221f8c9838ccc9a89b43d9de66993 (diff) |
[PATCH] IB uverbs: add mthca user context support
Add support for managing userspace contexts to mthca.
Signed-off-by: Roland Dreier <rolandd@cisco.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/infiniband/hw/mthca/mthca_provider.c')
-rw-r--r-- | drivers/infiniband/hw/mthca/mthca_provider.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c index 0cc86f8e1850..bfd33a470020 100644 --- a/drivers/infiniband/hw/mthca/mthca_provider.c +++ b/drivers/infiniband/hw/mthca/mthca_provider.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. | 2 | * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. |
3 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. | 3 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. |
4 | * Copyright (c) 2005 Cisco Systems. All rights reserved. | ||
4 | * | 5 | * |
5 | * This software is available to you under a choice of one of two | 6 | * This software is available to you under a choice of one of two |
6 | * licenses. You may choose to be licensed under the terms of the GNU | 7 | * licenses. You may choose to be licensed under the terms of the GNU |
@@ -37,6 +38,8 @@ | |||
37 | 38 | ||
38 | #include "mthca_dev.h" | 39 | #include "mthca_dev.h" |
39 | #include "mthca_cmd.h" | 40 | #include "mthca_cmd.h" |
41 | #include "mthca_user.h" | ||
42 | #include "mthca_memfree.h" | ||
40 | 43 | ||
41 | static int mthca_query_device(struct ib_device *ibdev, | 44 | static int mthca_query_device(struct ib_device *ibdev, |
42 | struct ib_device_attr *props) | 45 | struct ib_device_attr *props) |
@@ -284,6 +287,59 @@ static int mthca_query_gid(struct ib_device *ibdev, u8 port, | |||
284 | return err; | 287 | return err; |
285 | } | 288 | } |
286 | 289 | ||
290 | static struct ib_ucontext *mthca_alloc_ucontext(struct ib_device *ibdev, | ||
291 | struct ib_udata *udata) | ||
292 | { | ||
293 | struct mthca_alloc_ucontext_resp uresp; | ||
294 | struct mthca_ucontext *context; | ||
295 | int err; | ||
296 | |||
297 | memset(&uresp, 0, sizeof uresp); | ||
298 | |||
299 | uresp.qp_tab_size = to_mdev(ibdev)->limits.num_qps; | ||
300 | if (mthca_is_memfree(to_mdev(ibdev))) | ||
301 | uresp.uarc_size = to_mdev(ibdev)->uar_table.uarc_size; | ||
302 | else | ||
303 | uresp.uarc_size = 0; | ||
304 | |||
305 | context = kmalloc(sizeof *context, GFP_KERNEL); | ||
306 | if (!context) | ||
307 | return ERR_PTR(-ENOMEM); | ||
308 | |||
309 | err = mthca_uar_alloc(to_mdev(ibdev), &context->uar); | ||
310 | if (err) { | ||
311 | kfree(context); | ||
312 | return ERR_PTR(err); | ||
313 | } | ||
314 | |||
315 | context->db_tab = mthca_init_user_db_tab(to_mdev(ibdev)); | ||
316 | if (IS_ERR(context->db_tab)) { | ||
317 | err = PTR_ERR(context->db_tab); | ||
318 | mthca_uar_free(to_mdev(ibdev), &context->uar); | ||
319 | kfree(context); | ||
320 | return ERR_PTR(err); | ||
321 | } | ||
322 | |||
323 | if (ib_copy_to_udata(udata, &uresp, sizeof uresp)) { | ||
324 | mthca_cleanup_user_db_tab(to_mdev(ibdev), &context->uar, context->db_tab); | ||
325 | mthca_uar_free(to_mdev(ibdev), &context->uar); | ||
326 | kfree(context); | ||
327 | return ERR_PTR(-EFAULT); | ||
328 | } | ||
329 | |||
330 | return &context->ibucontext; | ||
331 | } | ||
332 | |||
333 | static int mthca_dealloc_ucontext(struct ib_ucontext *context) | ||
334 | { | ||
335 | mthca_cleanup_user_db_tab(to_mdev(context->device), &to_mucontext(context)->uar, | ||
336 | to_mucontext(context)->db_tab); | ||
337 | mthca_uar_free(to_mdev(context->device), &to_mucontext(context)->uar); | ||
338 | kfree(to_mucontext(context)); | ||
339 | |||
340 | return 0; | ||
341 | } | ||
342 | |||
287 | static struct ib_pd *mthca_alloc_pd(struct ib_device *ibdev, | 343 | static struct ib_pd *mthca_alloc_pd(struct ib_device *ibdev, |
288 | struct ib_ucontext *context, | 344 | struct ib_ucontext *context, |
289 | struct ib_udata *udata) | 345 | struct ib_udata *udata) |
@@ -708,6 +764,8 @@ int mthca_register_device(struct mthca_dev *dev) | |||
708 | dev->ib_dev.modify_port = mthca_modify_port; | 764 | dev->ib_dev.modify_port = mthca_modify_port; |
709 | dev->ib_dev.query_pkey = mthca_query_pkey; | 765 | dev->ib_dev.query_pkey = mthca_query_pkey; |
710 | dev->ib_dev.query_gid = mthca_query_gid; | 766 | dev->ib_dev.query_gid = mthca_query_gid; |
767 | dev->ib_dev.alloc_ucontext = mthca_alloc_ucontext; | ||
768 | dev->ib_dev.dealloc_ucontext = mthca_dealloc_ucontext; | ||
711 | dev->ib_dev.alloc_pd = mthca_alloc_pd; | 769 | dev->ib_dev.alloc_pd = mthca_alloc_pd; |
712 | dev->ib_dev.dealloc_pd = mthca_dealloc_pd; | 770 | dev->ib_dev.dealloc_pd = mthca_dealloc_pd; |
713 | dev->ib_dev.create_ah = mthca_ah_create; | 771 | dev->ib_dev.create_ah = mthca_ah_create; |