aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c58
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.h14
2 files changed, 72 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
41static int mthca_query_device(struct ib_device *ibdev, 44static 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
290static 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
333static 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
287static struct ib_pd *mthca_alloc_pd(struct ib_device *ibdev, 343static 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;
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.h b/drivers/infiniband/hw/mthca/mthca_provider.h
index 4d976cccb1a8..27cd43cadd48 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.h
+++ b/drivers/infiniband/hw/mthca/mthca_provider.h
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * 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 * licenses. You may choose to be licensed under the terms of the GNU
@@ -54,6 +55,14 @@ struct mthca_uar {
54 int index; 55 int index;
55}; 56};
56 57
58struct mthca_user_db_table;
59
60struct mthca_ucontext {
61 struct ib_ucontext ibucontext;
62 struct mthca_uar uar;
63 struct mthca_user_db_table *db_tab;
64};
65
57struct mthca_mtt; 66struct mthca_mtt;
58 67
59struct mthca_mr { 68struct mthca_mr {
@@ -236,6 +245,11 @@ struct mthca_sqp {
236 dma_addr_t header_dma; 245 dma_addr_t header_dma;
237}; 246};
238 247
248static inline struct mthca_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
249{
250 return container_of(ibucontext, struct mthca_ucontext, ibucontext);
251}
252
239static inline struct mthca_fmr *to_mfmr(struct ib_fmr *ibmr) 253static inline struct mthca_fmr *to_mfmr(struct ib_fmr *ibmr)
240{ 254{
241 return container_of(ibmr, struct mthca_fmr, ibmr); 255 return container_of(ibmr, struct mthca_fmr, ibmr);