tree d6ce99ee31aa1da65531f67268695f89d9e876d2
parent 53b8b3ffd5e0b10f3c683096a663d0cc22179c43
author Roland Dreier <[EMAIL PROTECTED]> Fri, 08 Jul 2005 07:57:18 -0700
committer Linus Torvalds <[EMAIL PROTECTED]> Fri, 08 Jul 2005 08:23:49 -0700

[PATCH] IB uverbs: add mthca user PD support

Add support for userspace protection domains (PDs) to mthca.

Signed-off-by: Roland Dreier <[EMAIL PROTECTED]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>

 drivers/infiniband/hw/mthca/mthca_dev.h      |    3 ++-
 drivers/infiniband/hw/mthca/mthca_main.c     |    2 +-
 drivers/infiniband/hw/mthca/mthca_pd.c       |   24 +++++++++++++++---------
 drivers/infiniband/hw/mthca/mthca_provider.c |   10 +++++++++-
 drivers/infiniband/hw/mthca/mthca_provider.h |    1 +
 5 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/drivers/infiniband/hw/mthca/mthca_dev.h 
b/drivers/infiniband/hw/mthca/mthca_dev.h
--- a/drivers/infiniband/hw/mthca/mthca_dev.h
+++ b/drivers/infiniband/hw/mthca/mthca_dev.h
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright (c) 2005 Cisco Systems.  All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -378,7 +379,7 @@ void mthca_unregister_device(struct mthc
 int mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar);
 void mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar);
 
-int mthca_pd_alloc(struct mthca_dev *dev, struct mthca_pd *pd);
+int mthca_pd_alloc(struct mthca_dev *dev, int privileged, struct mthca_pd *pd);
 void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd);
 
 struct mthca_mtt *mthca_alloc_mtt(struct mthca_dev *dev, int size);
diff --git a/drivers/infiniband/hw/mthca/mthca_main.c 
b/drivers/infiniband/hw/mthca/mthca_main.c
--- a/drivers/infiniband/hw/mthca/mthca_main.c
+++ b/drivers/infiniband/hw/mthca/mthca_main.c
@@ -665,7 +665,7 @@ static int __devinit mthca_setup_hca(str
                goto err_pd_table_free;
        }
 
-       err = mthca_pd_alloc(dev, &dev->driver_pd);
+       err = mthca_pd_alloc(dev, 1, &dev->driver_pd);
        if (err) {
                mthca_err(dev, "Failed to create driver PD, "
                          "aborting.\n");
diff --git a/drivers/infiniband/hw/mthca/mthca_pd.c 
b/drivers/infiniband/hw/mthca/mthca_pd.c
--- a/drivers/infiniband/hw/mthca/mthca_pd.c
+++ b/drivers/infiniband/hw/mthca/mthca_pd.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2004 Topspin Communications.  All rights reserved.
+ * Copyright (c) 2005 Cisco Systems.  All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -37,23 +38,27 @@
 
 #include "mthca_dev.h"
 
-int mthca_pd_alloc(struct mthca_dev *dev, struct mthca_pd *pd)
+int mthca_pd_alloc(struct mthca_dev *dev, int privileged, struct mthca_pd *pd)
 {
-       int err;
+       int err = 0;
 
        might_sleep();
 
+       pd->privileged = privileged;
+
        atomic_set(&pd->sqp_count, 0);
        pd->pd_num = mthca_alloc(&dev->pd_table.alloc);
        if (pd->pd_num == -1)
                return -ENOMEM;
 
-       err = mthca_mr_alloc_notrans(dev, pd->pd_num,
-                                    MTHCA_MPT_FLAG_LOCAL_READ |
-                                    MTHCA_MPT_FLAG_LOCAL_WRITE,
-                                    &pd->ntmr);
-       if (err)
-               mthca_free(&dev->pd_table.alloc, pd->pd_num);
+       if (privileged) {
+               err = mthca_mr_alloc_notrans(dev, pd->pd_num,
+                                            MTHCA_MPT_FLAG_LOCAL_READ |
+                                            MTHCA_MPT_FLAG_LOCAL_WRITE,
+                                            &pd->ntmr);
+               if (err)
+                       mthca_free(&dev->pd_table.alloc, pd->pd_num);
+       }
 
        return err;
 }
@@ -61,7 +66,8 @@ int mthca_pd_alloc(struct mthca_dev *dev
 void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd)
 {
        might_sleep();
-       mthca_free_mr(dev, &pd->ntmr);
+       if (pd->privileged)
+               mthca_free_mr(dev, &pd->ntmr);
        mthca_free(&dev->pd_table.alloc, pd->pd_num);
 }
 
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c 
b/drivers/infiniband/hw/mthca/mthca_provider.c
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -368,12 +368,20 @@ static struct ib_pd *mthca_alloc_pd(stru
        if (!pd)
                return ERR_PTR(-ENOMEM);
 
-       err = mthca_pd_alloc(to_mdev(ibdev), pd);
+       err = mthca_pd_alloc(to_mdev(ibdev), !context, pd);
        if (err) {
                kfree(pd);
                return ERR_PTR(err);
        }
 
+       if (context) {
+               if (ib_copy_to_udata(udata, &pd->pd_num, sizeof (__u32))) {
+                       mthca_pd_free(to_mdev(ibdev), pd);
+                       kfree(pd);
+                       return ERR_PTR(-EFAULT);
+               }
+       }
+
        return &pd->ibpd;
 }
 
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.h 
b/drivers/infiniband/hw/mthca/mthca_provider.h
--- a/drivers/infiniband/hw/mthca/mthca_provider.h
+++ b/drivers/infiniband/hw/mthca/mthca_provider.h
@@ -92,6 +92,7 @@ struct mthca_pd {
        u32             pd_num;
        atomic_t        sqp_count;
        struct mthca_mr ntmr;
+       int             privileged;
 };
 
 struct mthca_eq {
-
To unsubscribe from this list: send the line "unsubscribe bk-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to