[MTHCA] feature: added support for registration of virtual memory from kernel
authorleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 14 Aug 2006 18:02:42 +0000 (18:02 +0000)
committerleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 14 Aug 2006 18:02:42 +0000 (18:02 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@449 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

hw/mthca/kernel/hca_memory.c
hw/mthca/kernel/ib_verbs.h
hw/mthca/kernel/mt_verbs.c
hw/mthca/kernel/mthca_provider.c
hw/mthca/kernel/mthca_provider.h

index 2a55c96..8c40b4d 100644 (file)
@@ -408,7 +408,7 @@ mlnx_map_phys_fmr (
        if (err) {\r
                status = errno_to_iberr(err);\r
                HCA_PRINT(TRACE_LEVEL_ERROR  , HCA_DBG_MEMORY  ,\r
-                       ("mthca_dereg_mr failed (%d) for mr %p\n",      err, h_fmr));\r
+                       ("ibv_map_phys_fmr failed (%d) for mr %p\n",    err, h_fmr));\r
                goto err_dealloc_fmr;\r
        }\r
 \r
@@ -494,7 +494,7 @@ mlnx_dealloc_fmr (
        if (err) {\r
                status = errno_to_iberr(err);\r
                HCA_PRINT(TRACE_LEVEL_ERROR  , HCA_DBG_MEMORY  ,\r
-                       ("mthca_dereg_mr failed (%d) for mr %p\n",      err, h_fmr));\r
+                       ("ibv_dealloc_fmr failed (%d) for mr %p\n",     err, h_fmr));\r
                goto err_dealloc_fmr;\r
        }\r
 \r
index a18b9eb..3d0be64 100644 (file)
@@ -776,8 +776,9 @@ struct ib_device {
                                                  int num_phys_buf,
                                                  mthca_qp_access_t mr_access_flags,
                                                  u64 *iova_start);
-       struct ib_mr *             (*reg_user_mr)(struct ib_pd *pd, 
-                                               void* __ptr64   vaddr, uint64_t length, uint64_t hca_va, mthca_qp_access_t acc);
+       struct ib_mr *                     (*reg_virt_mr)(struct ib_pd *pd, 
+                                               void* __ptr64   vaddr, uint64_t length, uint64_t hca_va,
+                                               mthca_qp_access_t acc, boolean_t um_call);
        int                        (*query_mr)(struct ib_mr *mr,
                                               struct ib_mr_attr *mr_attr);
        int                        (*dereg_mr)(struct ib_mr *mr);
index 3f09383..c427d95 100644 (file)
@@ -625,14 +625,8 @@ struct ib_mr *ibv_reg_mr(struct ib_pd *pd,
        struct ib_mr *ib_mr;
        int                          err;
        HCA_ENTER(HCA_DBG_MEMORY);
-       /* sanity check */
-       if (!um_call) {
-               err = -ENOSYS;
-               HCA_PRINT(TRACE_LEVEL_ERROR,HCA_DBG_MEMORY ,("ibv_reg_mr for kernel mode is not supported (%d)\n", err));
-               goto err_not_supported;
-       }
 
-       ib_mr = pd->device->reg_user_mr(pd, vaddr, length, hca_va, mr_access_flags);
+       ib_mr = pd->device->reg_virt_mr(pd, vaddr, length, hca_va, mr_access_flags, um_call);
        if (IS_ERR(ib_mr)) {
                err = PTR_ERR(ib_mr);
                HCA_PRINT(TRACE_LEVEL_ERROR,HCA_DBG_MEMORY ,("mthca_reg_user_mr failed (%d)\n", err));
@@ -649,7 +643,6 @@ struct ib_mr *ibv_reg_mr(struct ib_pd *pd,
        return ib_mr;
 
 err_reg_user_mr:
-err_not_supported:
        HCA_EXIT(HCA_DBG_MEMORY);
        return ERR_PTR(err);
 }
index 16a21d9..01a6b3e 100644 (file)
@@ -871,10 +871,9 @@ struct ib_mr *mthca_get_dma_mr(struct ib_pd *pd, mthca_qp_access_t acc)
        struct mthca_mr *mr;
        int err;
 
-       mr = kmalloc(sizeof *mr, GFP_KERNEL);
+       mr = kzalloc(sizeof *mr, GFP_KERNEL);
        if (!mr)
                return ERR_PTR(-ENOMEM);
-       RtlZeroMemory(mr, sizeof *mr);
 
        err = mthca_mr_alloc_notrans(to_mdev(pd->device),
                                     to_mpd(pd)->pd_num,
@@ -940,10 +939,9 @@ struct ib_mr *mthca_reg_phys_mr(struct ib_pd       *pd,
        buffer_list[0].size += buffer_list[0].addr & ((1Ui64 << shift) - 1);
        buffer_list[0].addr &= ~0Ui64 << shift;
 
-       mr = kmalloc(sizeof *mr, GFP_KERNEL);
+       mr = kzalloc(sizeof *mr, GFP_KERNEL);
        if (!mr)
                return ERR_PTR(-ENOMEM);
-       RtlZeroMemory(mr, sizeof *mr);
 
        npages = 0;
        for (i = 0; i < num_phys_buf; ++i)
@@ -988,8 +986,9 @@ struct ib_mr *mthca_reg_phys_mr(struct ib_pd       *pd,
        return &mr->ibmr;
 }
 
-struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd, 
-       void* __ptr64   vaddr, uint64_t length, uint64_t hca_va, mthca_qp_access_t acc)
+struct ib_mr *mthca_reg_virt_mr(struct ib_pd *pd, 
+       void* __ptr64   vaddr, uint64_t length, uint64_t hca_va,
+       mthca_qp_access_t acc, boolean_t um_call)
 {
        struct mthca_dev *dev = to_mdev(pd->device);
        struct mthca_mr *mr;
@@ -1024,10 +1023,11 @@ struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd,
 
        // try register the buffer
        iobuf_p = &mr->iobuf;
-       err =  iobuf_register( (u64)vaddr, length, TRUE
+       err =  iobuf_register( (u64)vaddr, length, um_call
                (acc & ~MTHCA_ACCESS_REMOTE_READ) ? IB_AC_LOCAL_WRITE : 0, iobuf_p );
        if (err)
                goto err_reg_mem;
+       mr->iobuf_used = TRUE;
 
        // allocate MTT's
        mr->mtt = mthca_alloc_mtt(dev, iobuf_p->nr_pages);
@@ -1117,13 +1117,11 @@ int mthca_dereg_mr(struct ib_mr *mr)
        struct mthca_mr *mmr = to_mmr(mr);
        struct mthca_dev* dev = to_mdev(mr->device);
 
-       if (mr->pd->ucontext) {
+       if (mr->pd->ucontext)
                MmUnsecureVirtualMemory ( mmr->secure_handle );
-               mthca_free_mr(dev, mmr);
+       mthca_free_mr(dev, mmr);
+       if (mmr->iobuf_used)
                iobuf_deregister(&mmr->iobuf);
-       }
-       else
-               mthca_free_mr(dev, mmr);
        kfree(mmr);
        return 0;
 }
@@ -1272,7 +1270,7 @@ int mthca_register_device(struct mthca_dev *dev)
        dev->ib_dev.poll_cq              = mthca_poll_cq;
        dev->ib_dev.get_dma_mr           = mthca_get_dma_mr;
        dev->ib_dev.reg_phys_mr          = mthca_reg_phys_mr;
-       dev->ib_dev.reg_user_mr          = mthca_reg_user_mr;
+       dev->ib_dev.reg_virt_mr                  = mthca_reg_virt_mr;
        dev->ib_dev.dereg_mr             = mthca_dereg_mr;
 
        if (dev->mthca_flags & MTHCA_FLAG_FMR) {
index 91a2d8b..574968f 100644 (file)
@@ -77,6 +77,7 @@ struct mthca_mr {
        //NB: the structure was not inserted here for not to mix driver and provider structures
        struct ib_mr      ibmr;
        struct mthca_mtt *mtt;
+       int                     iobuf_used;
        mt_iobuf_t      iobuf;
        void *secure_handle;
 };
@@ -420,8 +421,9 @@ struct ib_mr *mthca_reg_phys_mr(struct ib_pd       *pd,
                                       mthca_qp_access_t                 acc,
                                       u64                *iova_start);
 
-struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd, 
-        void* __ptr64  vaddr, uint64_t length, uint64_t hca_va, mthca_qp_access_t acc);
+struct ib_mr *mthca_reg_virt_mr(struct ib_pd *pd, 
+        void* __ptr64  vaddr, uint64_t length, uint64_t hca_va,
+        mthca_qp_access_t acc, boolean_t um_call);
 
 int mthca_dereg_mr(struct ib_mr *mr);