On 2021/6/4 3:12, Jason Gunthorpe wrote: > On Thu, Jun 03, 2021 at 03:37:13PM +0800, Weihang Li wrote: >> From: Xi Wang <wangxi11@xxxxxxxxxx> >> >> Classify the uar address by wrapping the uar type and start page as offset >> for hns rdma io mmap. >> >> Signed-off-by: Xi Wang <wangxi11@xxxxxxxxxx> >> Signed-off-by: Weihang Li <liweihang@xxxxxxxxxx> >> drivers/infiniband/hw/hns/hns_roce_main.c | 27 ++++++++++++++++++++++++--- >> include/uapi/rdma/hns-abi.h | 4 ++++ >> 2 files changed, 28 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c >> index 6c6e82b..9610bfd 100644 >> +++ b/drivers/infiniband/hw/hns/hns_roce_main.c >> @@ -338,12 +338,23 @@ static void hns_roce_dealloc_ucontext(struct ib_ucontext *ibcontext) >> hns_roce_uar_free(to_hr_dev(ibcontext->device), &context->uar); >> } >> >> -static int hns_roce_mmap(struct ib_ucontext *context, >> - struct vm_area_struct *vma) >> +/* command value is offset[15:8] */ >> +static int hns_roce_mmap_get_command(unsigned long offset) >> +{ >> + return (offset >> 8) & 0xff; >> +} >> + >> +/* index value is offset[63:16] | offset[7:0] */ >> +static unsigned long hns_roce_mmap_get_index(unsigned long offset) >> +{ >> + return ((offset >> 16) << 8) | (offset & 0xff); >> +} > > Please try to avoid using this command stuff copied from mlx drivers, > especially do not encode the qpn in this. > > The proper way is to request and return a mmap cookie through the > verb that causes the page to be allocated. For instance specifying a > new input parameter to the create QP udata and an output parameter > with the mmap cookie. > > You can look at what the mlx UAR stuff does for some idea how to > convert the old command style to a the preferred cookie style. > > Jason > Thank you, we'll look at the implementation of mlx and how to use the existing interfaces in the framework. Weihang