Lines Matching refs:hr_dev

50 static int alloc_mr_key(struct hns_roce_dev *hr_dev, struct hns_roce_mr *mr)  in alloc_mr_key()  argument
52 struct hns_roce_ida *mtpt_ida = &hr_dev->mr_table.mtpt_ida; in alloc_mr_key()
53 struct ib_device *ibdev = &hr_dev->ib_dev; in alloc_mr_key()
67 err = hns_roce_table_get(hr_dev, &hr_dev->mr_table.mtpt_table, in alloc_mr_key()
80 static void free_mr_key(struct hns_roce_dev *hr_dev, struct hns_roce_mr *mr) in free_mr_key() argument
84 hns_roce_table_put(hr_dev, &hr_dev->mr_table.mtpt_table, obj); in free_mr_key()
85 ida_free(&hr_dev->mr_table.mtpt_ida.ida, (int)obj); in free_mr_key()
88 static int alloc_mr_pbl(struct hns_roce_dev *hr_dev, struct hns_roce_mr *mr, in alloc_mr_pbl() argument
91 struct ib_device *ibdev = &hr_dev->ib_dev; in alloc_mr_pbl()
96 mr->pbl_hop_num = is_fast ? 1 : hr_dev->caps.pbl_hop_num; in alloc_mr_pbl()
98 hr_dev->caps.pbl_buf_pg_sz + PAGE_SHIFT; in alloc_mr_pbl()
106 err = hns_roce_mtr_create(hr_dev, &mr->pbl_mtr, &buf_attr, in alloc_mr_pbl()
107 hr_dev->caps.pbl_ba_pg_sz + PAGE_SHIFT, in alloc_mr_pbl()
117 static void free_mr_pbl(struct hns_roce_dev *hr_dev, struct hns_roce_mr *mr) in free_mr_pbl() argument
119 hns_roce_mtr_destroy(hr_dev, &mr->pbl_mtr); in free_mr_pbl()
122 static void hns_roce_mr_free(struct hns_roce_dev *hr_dev, struct hns_roce_mr *mr) in hns_roce_mr_free() argument
124 struct ib_device *ibdev = &hr_dev->ib_dev; in hns_roce_mr_free()
128 ret = hns_roce_destroy_hw_ctx(hr_dev, HNS_ROCE_CMD_DESTROY_MPT, in hns_roce_mr_free()
130 (hr_dev->caps.num_mtpts - 1)); in hns_roce_mr_free()
136 free_mr_pbl(hr_dev, mr); in hns_roce_mr_free()
137 free_mr_key(hr_dev, mr); in hns_roce_mr_free()
140 static int hns_roce_mr_enable(struct hns_roce_dev *hr_dev, in hns_roce_mr_enable() argument
145 struct device *dev = hr_dev->dev; in hns_roce_mr_enable()
149 mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); in hns_roce_mr_enable()
154 ret = hr_dev->hw->write_mtpt(hr_dev, mailbox->buf, mr); in hns_roce_mr_enable()
156 ret = hr_dev->hw->frmr_write_mtpt(hr_dev, mailbox->buf, mr); in hns_roce_mr_enable()
162 ret = hns_roce_create_hw_ctx(hr_dev, mailbox, HNS_ROCE_CMD_CREATE_MPT, in hns_roce_mr_enable()
163 mtpt_idx & (hr_dev->caps.num_mtpts - 1)); in hns_roce_mr_enable()
172 hns_roce_free_cmd_mailbox(hr_dev, mailbox); in hns_roce_mr_enable()
177 void hns_roce_init_mr_table(struct hns_roce_dev *hr_dev) in hns_roce_init_mr_table() argument
179 struct hns_roce_ida *mtpt_ida = &hr_dev->mr_table.mtpt_ida; in hns_roce_init_mr_table()
182 mtpt_ida->max = hr_dev->caps.num_mtpts - 1; in hns_roce_init_mr_table()
183 mtpt_ida->min = hr_dev->caps.reserved_mrws; in hns_roce_init_mr_table()
188 struct hns_roce_dev *hr_dev = to_hr_dev(pd->device); in hns_roce_get_dma_mr() local
202 ret = alloc_mr_key(hr_dev, mr); in hns_roce_get_dma_mr()
206 ret = hns_roce_mr_enable(hr_dev, mr); in hns_roce_get_dma_mr()
214 free_mr_key(hr_dev, mr); in hns_roce_get_dma_mr()
225 struct hns_roce_dev *hr_dev = to_hr_dev(pd->device); in hns_roce_reg_user_mr() local
239 ret = alloc_mr_key(hr_dev, mr); in hns_roce_reg_user_mr()
243 ret = alloc_mr_pbl(hr_dev, mr, udata, start); in hns_roce_reg_user_mr()
247 ret = hns_roce_mr_enable(hr_dev, mr); in hns_roce_reg_user_mr()
256 free_mr_pbl(hr_dev, mr); in hns_roce_reg_user_mr()
258 free_mr_key(hr_dev, mr); in hns_roce_reg_user_mr()
269 struct hns_roce_dev *hr_dev = to_hr_dev(ibmr->device); in hns_roce_rereg_user_mr() local
270 struct ib_device *ib_dev = &hr_dev->ib_dev; in hns_roce_rereg_user_mr()
279 mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); in hns_roce_rereg_user_mr()
283 mtpt_idx = key_to_hw_index(mr->key) & (hr_dev->caps.num_mtpts - 1); in hns_roce_rereg_user_mr()
285 ret = hns_roce_cmd_mbox(hr_dev, 0, mailbox->dma, HNS_ROCE_CMD_QUERY_MPT, in hns_roce_rereg_user_mr()
290 ret = hns_roce_destroy_hw_ctx(hr_dev, HNS_ROCE_CMD_DESTROY_MPT, in hns_roce_rereg_user_mr()
306 free_mr_pbl(hr_dev, mr); in hns_roce_rereg_user_mr()
307 ret = alloc_mr_pbl(hr_dev, mr, udata, start); in hns_roce_rereg_user_mr()
315 ret = hr_dev->hw->rereg_write_mtpt(hr_dev, mr, flags, mailbox->buf); in hns_roce_rereg_user_mr()
321 ret = hns_roce_create_hw_ctx(hr_dev, mailbox, HNS_ROCE_CMD_CREATE_MPT, in hns_roce_rereg_user_mr()
331 hns_roce_free_cmd_mailbox(hr_dev, mailbox); in hns_roce_rereg_user_mr()
340 struct hns_roce_dev *hr_dev = to_hr_dev(ibmr->device); in hns_roce_dereg_mr() local
343 if (hr_dev->hw->dereg_mr) in hns_roce_dereg_mr()
344 hr_dev->hw->dereg_mr(hr_dev); in hns_roce_dereg_mr()
346 hns_roce_mr_free(hr_dev, mr); in hns_roce_dereg_mr()
355 struct hns_roce_dev *hr_dev = to_hr_dev(pd->device); in hns_roce_alloc_mr() local
356 struct device *dev = hr_dev->dev; in hns_roce_alloc_mr()
378 ret = alloc_mr_key(hr_dev, mr); in hns_roce_alloc_mr()
382 ret = alloc_mr_pbl(hr_dev, mr, NULL, 0); in hns_roce_alloc_mr()
386 ret = hns_roce_mr_enable(hr_dev, mr); in hns_roce_alloc_mr()
396 free_mr_pbl(hr_dev, mr); in hns_roce_alloc_mr()
398 free_mr_key(hr_dev, mr); in hns_roce_alloc_mr()
419 struct hns_roce_dev *hr_dev = to_hr_dev(ibmr->device); in hns_roce_map_mr_sg() local
420 struct ib_device *ibdev = &hr_dev->ib_dev; in hns_roce_map_mr_sg()
442 ret = hns_roce_mtr_map(hr_dev, mtr, mr->page_list, mr->npages); in hns_roce_map_mr_sg()
458 static void hns_roce_mw_free(struct hns_roce_dev *hr_dev, in hns_roce_mw_free() argument
461 struct device *dev = hr_dev->dev; in hns_roce_mw_free()
465 ret = hns_roce_destroy_hw_ctx(hr_dev, HNS_ROCE_CMD_DESTROY_MPT, in hns_roce_mw_free()
467 (hr_dev->caps.num_mtpts - 1)); in hns_roce_mw_free()
471 hns_roce_table_put(hr_dev, &hr_dev->mr_table.mtpt_table, in hns_roce_mw_free()
475 ida_free(&hr_dev->mr_table.mtpt_ida.ida, in hns_roce_mw_free()
479 static int hns_roce_mw_enable(struct hns_roce_dev *hr_dev, in hns_roce_mw_enable() argument
482 struct hns_roce_mr_table *mr_table = &hr_dev->mr_table; in hns_roce_mw_enable()
484 struct device *dev = hr_dev->dev; in hns_roce_mw_enable()
489 ret = hns_roce_table_get(hr_dev, &mr_table->mtpt_table, mtpt_idx); in hns_roce_mw_enable()
493 mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); in hns_roce_mw_enable()
499 ret = hr_dev->hw->mw_write_mtpt(mailbox->buf, mw); in hns_roce_mw_enable()
505 ret = hns_roce_create_hw_ctx(hr_dev, mailbox, HNS_ROCE_CMD_CREATE_MPT, in hns_roce_mw_enable()
506 mtpt_idx & (hr_dev->caps.num_mtpts - 1)); in hns_roce_mw_enable()
514 hns_roce_free_cmd_mailbox(hr_dev, mailbox); in hns_roce_mw_enable()
519 hns_roce_free_cmd_mailbox(hr_dev, mailbox); in hns_roce_mw_enable()
522 hns_roce_table_put(hr_dev, &mr_table->mtpt_table, mtpt_idx); in hns_roce_mw_enable()
529 struct hns_roce_dev *hr_dev = to_hr_dev(ibmw->device); in hns_roce_alloc_mw() local
530 struct hns_roce_ida *mtpt_ida = &hr_dev->mr_table.mtpt_ida; in hns_roce_alloc_mw()
531 struct ib_device *ibdev = &hr_dev->ib_dev; in hns_roce_alloc_mw()
548 mw->pbl_hop_num = hr_dev->caps.pbl_hop_num; in hns_roce_alloc_mw()
549 mw->pbl_ba_pg_sz = hr_dev->caps.pbl_ba_pg_sz; in hns_roce_alloc_mw()
550 mw->pbl_buf_pg_sz = hr_dev->caps.pbl_buf_pg_sz; in hns_roce_alloc_mw()
552 ret = hns_roce_mw_enable(hr_dev, mw); in hns_roce_alloc_mw()
559 hns_roce_mw_free(hr_dev, mw); in hns_roce_alloc_mw()
565 struct hns_roce_dev *hr_dev = to_hr_dev(ibmw->device); in hns_roce_dealloc_mw() local
568 hns_roce_mw_free(hr_dev, mw); in hns_roce_dealloc_mw()
572 static int mtr_map_region(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, in mtr_map_region() argument
587 mtts = hns_roce_hem_list_find_mtt(hr_dev, &mtr->hem_list, in mtr_map_region()
648 static void mtr_free_bufs(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr) in mtr_free_bufs() argument
658 hns_roce_buf_free(hr_dev, mtr->kmem); in mtr_free_bufs()
663 static int mtr_alloc_bufs(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, in mtr_alloc_bufs() argument
667 struct ib_device *ibdev = &hr_dev->ib_dev; in mtr_alloc_bufs()
683 mtr->kmem = hns_roce_buf_alloc(hr_dev, total_size, in mtr_alloc_bufs()
697 static int mtr_map_bufs(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, in mtr_map_bufs() argument
700 struct ib_device *ibdev = &hr_dev->ib_dev; in mtr_map_bufs()
711 npage = hns_roce_get_umem_bufs(hr_dev, pages, page_count, in mtr_map_bufs()
714 npage = hns_roce_get_kmem_bufs(hr_dev, pages, page_count, in mtr_map_bufs()
734 ret = hns_roce_mtr_map(hr_dev, mtr, pages, page_count); in mtr_map_bufs()
744 int hns_roce_mtr_map(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, in hns_roce_mtr_map() argument
747 struct ib_device *ibdev = &hr_dev->ib_dev; in hns_roce_mtr_map()
778 ret = mtr_map_region(hr_dev, mtr, r, &pages[r->offset], in hns_roce_mtr_map()
799 int hns_roce_mtr_find(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, in hns_roce_mtr_find() argument
835 mtts = hns_roce_hem_list_find_mtt(hr_dev, &mtr->hem_list, in hns_roce_mtr_find()
854 static int mtr_init_buf_cfg(struct hns_roce_dev *hr_dev, in mtr_init_buf_cfg() argument
912 static int mtr_alloc_mtt(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, in mtr_alloc_mtt() argument
920 ret = hns_roce_hem_list_request(hr_dev, &mtr->hem_list, in mtr_alloc_mtt()
934 static void mtr_free_mtt(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr) in mtr_free_mtt() argument
936 hns_roce_hem_list_release(hr_dev, &mtr->hem_list); in mtr_free_mtt()
949 int hns_roce_mtr_create(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, in hns_roce_mtr_create() argument
954 struct ib_device *ibdev = &hr_dev->ib_dev; in hns_roce_mtr_create()
959 buf_page_cnt = mtr_init_buf_cfg(hr_dev, buf_attr, &mtr->hem_cfg, in hns_roce_mtr_create()
968 ret = mtr_alloc_mtt(hr_dev, mtr, ba_page_shift); in hns_roce_mtr_create()
983 ret = mtr_alloc_bufs(hr_dev, mtr, buf_attr, udata, user_addr); in hns_roce_mtr_create()
990 ret = mtr_map_bufs(hr_dev, mtr, buf_page_cnt, buf_page_shift); in hns_roce_mtr_create()
996 mtr_free_bufs(hr_dev, mtr); in hns_roce_mtr_create()
998 mtr_free_mtt(hr_dev, mtr); in hns_roce_mtr_create()
1002 void hns_roce_mtr_destroy(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr) in hns_roce_mtr_destroy() argument
1005 hns_roce_hem_list_release(hr_dev, &mtr->hem_list); in hns_roce_mtr_destroy()
1008 mtr_free_bufs(hr_dev, mtr); in hns_roce_mtr_destroy()