Skip to contentSkip to conversation

RDMA/hns: Add a new mmap implementation

PATCH Applied Wenpeng Liang 2 participants 2 messages Oct 28, 2021 – Oct 29, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 RDMA/hns: Add a new mmap implementation

From: Chengchang Tang <[email protected]>

Add a new implementation for mmap by using the new mmap entry API.

---
 drivers/infiniband/hw/hns/hns_roce_device.h |  23 ++++
 drivers/infiniband/hw/hns/hns_roce_main.c   | 142 ++++++++++++++++----
 include/rdma/ib_verbs.h                     |   8 ++
 3 files changed, 146 insertions(+), 27 deletions(-)
drivers/infiniband/hw/hns/hns_roce_device.h +23 -0
index e5dadcd118ac..b624799624dc 100644
@@ -225,11 +225,24 @@ struct hns_roce_uar {
 	unsigned long	logic_idx;
 };
 
+enum hns_roce_mmap_type {
+	HNS_ROCE_MMAP_TYPE_DB = 1,
+	HNS_ROCE_MMAP_TYPE_TPTR,
+};
+
+struct hns_user_mmap_entry {
+	struct rdma_user_mmap_entry rdma_entry;
+	enum hns_roce_mmap_type mmap_type;
+	u64 address;
+};
+
 struct hns_roce_ucontext {
 	struct ib_ucontext	ibucontext;
 	struct hns_roce_uar	uar;
 	struct list_head	page_list;
 	struct mutex		page_mutex;
+	struct hns_user_mmap_entry *db_mmap_entry;
+	struct hns_user_mmap_entry *tptr_mmap_entry;
 };
 
 struct hns_roce_pd {
@@ -1050,6 +1063,12 @@ static inline struct hns_roce_srq *to_hr_srq(struct ib_srq *ibsrq)
 	return container_of(ibsrq, struct hns_roce_srq, ibsrq);
 }
 
+static inline struct hns_user_mmap_entry *to_hns_mmap(
+					struct rdma_user_mmap_entry *rdma_entry)
+{
+	return container_of(rdma_entry, struct hns_user_mmap_entry, rdma_entry);
+}
+
 static inline void hns_roce_write64_k(__le32 val[2], void __iomem *dest)
 {
 	writeq(*(u64 *)val, dest);
@@ -1260,4 +1279,8 @@ int hns_roce_init(struct hns_roce_dev *hr_dev);
 void hns_roce_exit(struct hns_roce_dev *hr_dev);
 int hns_roce_fill_res_cq_entry(struct sk_buff *msg,
 			       struct ib_cq *ib_cq);
+struct hns_user_mmap_entry *hns_roce_user_mmap_entry_insert(
+				struct ib_ucontext *ucontext,
+				u64 address, size_t length,
+				enum hns_roce_mmap_type mmap_type);
 #endif /* _HNS_ROCE_DEVICE_H */
drivers/infiniband/hw/hns/hns_roce_main.c +115 -27

178 lines not on this page · raw message

include/rdma/ib_verbs.h +8 -0
index 61c73adccbbd..301689d31438 100644
@@ -2914,6 +2914,14 @@ int rdma_user_mmap_entry_insert_range(struct ib_ucontext *ucontext,
 				      size_t length, u32 min_pgoff,
 				      u32 max_pgoff);
 
+static inline int rdma_user_mmap_entry_insert_exact(struct ib_ucontext *ucontext,
+				      struct rdma_user_mmap_entry *entry,
+				      size_t length, u32 pgoff)
+{
+	return rdma_user_mmap_entry_insert_range(ucontext, entry, length,
+						 pgoff, pgoff);
+}
+
 struct rdma_user_mmap_entry *
 rdma_user_mmap_entry_get_pgoff(struct ib_ucontext *ucontext,
 			       unsigned long pgoff);
Signature · 1 line
2.33.0
maintainer Applied
#1 lore raw
Quoted 4 lines · Wenpeng Liang

From: Chengchang Tang <[email protected]>

Add a new implementation for mmap by using the new mmap entry API.

Quoted 8 lines
---
 drivers/infiniband/hw/hns/hns_roce_device.h |  23 ++++
 drivers/infiniband/hw/hns/hns_roce_main.c   | 142 ++++++++++++++++----
 include/rdma/ib_verbs.h                     |   8 ++
 3 files changed, 146 insertions(+), 27 deletions(-)

Applied to for-next, thanks

Quoted 17 lines
drivers/infiniband/hw/hns/hns_roce_main.c +1 -15
+static int hns_roce_mmap(struct ib_ucontext *uctx, struct vm_area_struct *vma)
 {
-	struct hns_roce_dev *hr_dev = to_hr_dev(context->device);
-
-	switch (vma->vm_pgoff) {
-	case 0:
-		return rdma_user_mmap_io(context, vma,
-					 to_hr_ucontext(context)->uar.pfn,
-					 PAGE_SIZE,
-					 pgprot_noncached(vma->vm_page_prot),
-					 NULL);
-
-	/* vm_pgoff: 1 -- TPTR */
-	case 1:
-		if (!hr_dev->tptr_dma_addr || !hr_dev->tptr_size)
-			return -EINVAL;
-		/*

drivers/infiniband/hw/hns/hns_roce_main.c static void hns_roce_dealloc_ucontext(struct ib_ucontext *ibcontext) · line 429

Quoted 10 lines
drivers/infiniband/hw/hns/hns_roce_main.c +2 -8
-		 * FIXME: using io_remap_pfn_range on the dma address returned
-		 * by dma_alloc_coherent is totally wrong.
-		 */
-		return rdma_user_mmap_io(context, vma,
-					 hr_dev->tptr_dma_addr >> PAGE_SHIFT,
-					 hr_dev->tptr_size,
-					 vma->vm_page_prot,
-					 NULL);
+	struct hns_roce_dev *hr_dev = to_hr_dev(uctx->device);
+	struct ib_device *ibdev = &hr_dev->ib_dev;

These two variables are unused, I deleted them

Jason