On Thu, Sep 30, 2021 at 04:36:08PM +0800, Wenpeng Liang wrote: > From: Chengchang Tang <tangchengchang@xxxxxxxxxx> > > Add a new implementation for mmap by using the new mmap entry API. > > The new implementation prepares for subsequent features and is compatible > with the old implementation. And the old implementation using hard-coded > offset will not be extended in the future. > > Signed-off-by: Chengchang Tang <tangchengchang@xxxxxxxxxx> > Signed-off-by: Wenpeng Liang <liangwenpeng@xxxxxxxxxx> > drivers/infiniband/hw/hns/hns_roce_device.h | 21 +++ > drivers/infiniband/hw/hns/hns_roce_main.c | 148 +++++++++++++++++++- > include/uapi/rdma/hns-abi.h | 21 ++- > 3 files changed, 184 insertions(+), 6 deletions(-) > > diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h > index 9467c39e3d28..ca456948b2d8 100644 > +++ b/drivers/infiniband/hw/hns/hns_roce_device.h > @@ -225,11 +225,23 @@ struct hns_roce_uar { > unsigned long logic_idx; > }; > > +struct hns_user_mmap_entry { > + struct rdma_user_mmap_entry rdma_entry; > + u64 address; > + u8 mmap_flag; > +}; > + > +enum hns_roce_mmap_type { > + HNS_ROCE_MMAP_TYPE_DB = 1, > +}; > + > struct hns_roce_ucontext { > struct ib_ucontext ibucontext; > struct hns_roce_uar uar; > struct list_head page_list; > struct mutex page_mutex; > + bool mmap_key_support; > + struct rdma_user_mmap_entry *db_mmap_entry; This should be struct hns_user_mmap_entry > +struct rdma_user_mmap_entry *hns_roce_user_mmap_entry_insert( > + struct ib_ucontext *ucontext, u64 address, > + size_t length, u8 mmap_flag) And this should return the hns_user_mmap_entry too > +static void ucontext_get_config(struct hns_roce_ucontext *context, > + struct hns_roce_ib_alloc_ucontext *ucmd) > +{ > + struct hns_roce_dev *hr_dev = to_hr_dev(context->ibucontext.device); > + > + if (ucmd->comp & HNS_ROCE_ALLOC_UCTX_COMP_CONFIG && > + hr_dev->hw_rev != HNS_ROCE_HW_VER1) > + context->mmap_key_support = !!(ucmd->config & > + HNS_ROCE_UCTX_REQ_MMAP_KEY_EN); No need for !! when in a bool context > > +static int hns_roce_mmap(struct ib_ucontext *uctx, struct vm_area_struct *vma) > +{ > + struct hns_roce_ucontext *context = to_hr_ucontext(uctx); > + struct hns_roce_dev *hr_dev = to_hr_dev(uctx->device); > + struct ib_device *ibdev = &hr_dev->ib_dev; > + struct rdma_user_mmap_entry *rdma_entry; > + struct hns_user_mmap_entry *entry; > + phys_addr_t pfn; > + pgprot_t prot; > + int ret; > + > + if (!context->mmap_key_support) > + return hns_roce_legacy_mmap(uctx, vma); This shouldn't be necessary, Just call rdma_user_mmap_entry_insert_range() to insert the two pages at 0 and 1 when in legacy mode and always keep the mmap routine in new mode Jason