ib_umem structure. Memory on MIC, however, must be mapped through SCIF for
access across PCI. This patch allows setup of context-based ib_umem mapping
routines.
-
-Also update mthca to support these changes
---
diff -urN a3/drivers/infiniband/core/umem.c a4/drivers/infiniband/core/umem.c
--- a3/drivers/infiniband/core/umem.c 2015-01-05 14:12:52.117593540 -0800
+ ops->page_count(umem) : ib_page_count_umem(umem);
+}
EXPORT_SYMBOL(ib_umem_page_count);
-diff -urN a3/drivers/infiniband/hw/mthca/mthca_memfree.c a4/drivers/infiniband/hw/mthca/mthca_memfree.c
---- a3/drivers/infiniband/hw/mthca/mthca_memfree.c 2015-01-05 14:12:52.112593540 -0800
-+++ a4/drivers/infiniband/hw/mthca/mthca_memfree.c 2015-01-05 14:36:00.825535043 -0800
-@@ -39,6 +39,12 @@
-
- #include <asm/page.h>
-
-+/* Must use the ib_umem routines to support the IB proxy server. */
-+#define MTHCA_IB_UMEM
-+#ifdef MTHCA_IB_UMEM
-+#include <rdma/ib_umem.h>
-+#endif
-+
- #include "mthca_memfree.h"
- #include "mthca_dev.h"
- #include "mthca_cmd.h"
-@@ -56,7 +62,11 @@
- struct mutex mutex;
- struct {
- u64 uvirt;
-+#ifdef MTHCA_IB_UMEM
-+ struct ib_umem *umem;
-+#else
- struct scatterlist mem;
-+#endif
- int refcount;
- } page[0];
- };
-@@ -446,7 +456,12 @@
- int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
- struct mthca_user_db_table *db_tab, int index, u64 uaddr)
- {
-+#ifdef MTHCA_IB_UMEM
-+ struct mthca_ucontext *context;
-+ struct ib_umem_chunk *chunk;
-+#else
- struct page *pages[1];
-+#endif
- int ret = 0;
- int i;
-
-@@ -472,6 +487,22 @@
- goto out;
- }
-
-+#ifdef MTHCA_IB_UMEM
-+ context = container_of(uar, struct mthca_ucontext, uar);
-+
-+ db_tab->page[i].umem = ib_umem_get(&context->ibucontext,
-+ uaddr & PAGE_MASK, PAGE_SIZE, 0, 0);
-+ if (IS_ERR(db_tab->page[i].umem)) {
-+ ret = PTR_ERR(db_tab->page[i].umem);
-+ goto out;
-+ }
-+
-+ chunk = list_entry(db_tab->page[i].umem->chunk_list.next,
-+ struct ib_umem_chunk, list);
-+
-+ ret = mthca_MAP_ICM_page(dev, sg_dma_address(&chunk->page_list[0]),
-+ mthca_uarc_virt(dev, uar, i));
-+#else
- ret = get_user_pages(current, current->mm, uaddr & PAGE_MASK, 1, 1, 0,
- pages, NULL);
- if (ret < 0)
-@@ -488,9 +519,14 @@
-
- ret = mthca_MAP_ICM_page(dev, sg_dma_address(&db_tab->page[i].mem),
- mthca_uarc_virt(dev, uar, i));
-+#endif
- if (ret) {
-+#ifdef MTHCA_IB_UMEM
-+ ib_umem_release(db_tab->page[i].umem);
-+#else
- pci_unmap_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
- put_page(sg_page(&db_tab->page[i].mem));
-+#endif
- goto out;
- }
-
-@@ -505,6 +541,9 @@
- void mthca_unmap_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
- struct mthca_user_db_table *db_tab, int index)
- {
-+#ifdef MTHCA_IB_UMEM
-+ int i;
-+#endif
- if (!mthca_is_memfree(dev))
- return;
-
-@@ -515,7 +554,16 @@
-
- mutex_lock(&db_tab->mutex);
-
-+#ifdef MTHCA_IB_UMEM
-+ i = index / MTHCA_DB_REC_PER_PAGE;
-+ if (!--db_tab->page[i].refcount) {
-+ mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, uar, i), 1);
-+ ib_umem_release(db_tab->page[i].umem);
-+ db_tab->page[i].uvirt = 0;
-+ }
-+#else
- --db_tab->page[index / MTHCA_DB_REC_PER_PAGE].refcount;
-+#endif
-
- mutex_unlock(&db_tab->mutex);
- }
-@@ -538,7 +586,11 @@
- for (i = 0; i < npages; ++i) {
- db_tab->page[i].refcount = 0;
- db_tab->page[i].uvirt = 0;
-+#ifdef MTHCA_IB_UMEM
-+ db_tab->page[i].umem = NULL;
-+#else
- sg_init_table(&db_tab->page[i].mem, 1);
-+#endif
- }
-
- return db_tab;
-@@ -555,8 +607,12 @@
- for (i = 0; i < dev->uar_table.uarc_size / MTHCA_ICM_PAGE_SIZE; ++i) {
- if (db_tab->page[i].uvirt) {
- mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, uar, i), 1);
-+#ifdef MTHCA_IB_UMEM
-+ ib_umem_release(db_tab->page[i].umem);
-+#else
- pci_unmap_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
- put_page(sg_page(&db_tab->page[i].mem));
-+#endif
- }
- }
-
diff -urN a3/include/rdma/ib_verbs.h a4/include/rdma/ib_verbs.h
--- a3/include/rdma/ib_verbs.h 2015-01-05 14:18:48.871578512 -0800
+++ a4/include/rdma/ib_verbs.h 2015-01-05 14:36:00.826535043 -0800