Commit 6fd610c5 authored by Xi Wang's avatar Xi Wang Committed by Jason Gunthorpe

RDMA/hns: Support 0 hop addressing for SRQ buffer

Add the zero hop addressing support by using mtr interface for SRQ buffer,
so the hns driver can support addressing hopnum between 0 to 3 for SRQ.

Link: https://lore.kernel.org/r/1586779091-51410-6-git-send-email-liweihang@huawei.comSigned-off-by: default avatarXi Wang <wangxi11@huawei.com>
Signed-off-by: default avatarWeihang Li <liweihang@huawei.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent d563099e
...@@ -528,11 +528,8 @@ struct hns_roce_cq { ...@@ -528,11 +528,8 @@ struct hns_roce_cq {
}; };
struct hns_roce_idx_que { struct hns_roce_idx_que {
struct hns_roce_buf idx_buf; struct hns_roce_mtr mtr;
int entry_sz; int entry_sz;
u32 buf_size;
struct ib_umem *umem;
struct hns_roce_mtt mtt;
unsigned long *bitmap; unsigned long *bitmap;
}; };
...@@ -547,12 +544,9 @@ struct hns_roce_srq { ...@@ -547,12 +544,9 @@ struct hns_roce_srq {
atomic_t refcount; atomic_t refcount;
struct completion free; struct completion free;
struct hns_roce_buf buf; struct hns_roce_mtr buf_mtr;
u64 *wrid; u64 *wrid;
struct ib_umem *umem;
u32 buf_size;
int page_shift;
struct hns_roce_mtt mtt;
struct hns_roce_idx_que idx_que; struct hns_roce_idx_que idx_que;
spinlock_t lock; spinlock_t lock;
int head; int head;
......
...@@ -2699,7 +2699,7 @@ static struct hns_roce_v2_cqe *next_cqe_sw_v2(struct hns_roce_cq *hr_cq) ...@@ -2699,7 +2699,7 @@ static struct hns_roce_v2_cqe *next_cqe_sw_v2(struct hns_roce_cq *hr_cq)
static void *get_srq_wqe(struct hns_roce_srq *srq, int n) static void *get_srq_wqe(struct hns_roce_srq *srq, int n)
{ {
return hns_roce_buf_offset(&srq->buf, n << srq->wqe_shift); return hns_roce_buf_offset(srq->buf_mtr.kmem, n << srq->wqe_shift);
} }
static void hns_roce_free_srq_wqe(struct hns_roce_srq *srq, int wqe_index) static void hns_roce_free_srq_wqe(struct hns_roce_srq *srq, int wqe_index)
...@@ -5699,43 +5699,45 @@ static void hns_roce_v2_write_srqc(struct hns_roce_dev *hr_dev, ...@@ -5699,43 +5699,45 @@ static void hns_roce_v2_write_srqc(struct hns_roce_dev *hr_dev,
dma_handle_idx >> 35); dma_handle_idx >> 35);
srq_context->idx_cur_blk_addr = srq_context->idx_cur_blk_addr =
cpu_to_le32(mtts_idx[0] >> PAGE_ADDR_SHIFT); cpu_to_le32(to_hr_hw_page_addr(mtts_idx[0]));
roce_set_field(srq_context->byte_44_idxbufpgsz_addr, roce_set_field(srq_context->byte_44_idxbufpgsz_addr,
SRQC_BYTE_44_SRQ_IDX_CUR_BLK_ADDR_M, SRQC_BYTE_44_SRQ_IDX_CUR_BLK_ADDR_M,
SRQC_BYTE_44_SRQ_IDX_CUR_BLK_ADDR_S, SRQC_BYTE_44_SRQ_IDX_CUR_BLK_ADDR_S,
mtts_idx[0] >> (32 + PAGE_ADDR_SHIFT)); upper_32_bits(to_hr_hw_page_addr(mtts_idx[0])));
roce_set_field(srq_context->byte_44_idxbufpgsz_addr, roce_set_field(srq_context->byte_44_idxbufpgsz_addr,
SRQC_BYTE_44_SRQ_IDX_HOP_NUM_M, SRQC_BYTE_44_SRQ_IDX_HOP_NUM_M,
SRQC_BYTE_44_SRQ_IDX_HOP_NUM_S, SRQC_BYTE_44_SRQ_IDX_HOP_NUM_S,
hr_dev->caps.idx_hop_num == HNS_ROCE_HOP_NUM_0 ? 0 : hr_dev->caps.idx_hop_num == HNS_ROCE_HOP_NUM_0 ? 0 :
hr_dev->caps.idx_hop_num); hr_dev->caps.idx_hop_num);
roce_set_field(srq_context->byte_44_idxbufpgsz_addr, roce_set_field(
SRQC_BYTE_44_SRQ_IDX_BA_PG_SZ_M, srq_context->byte_44_idxbufpgsz_addr,
SRQC_BYTE_44_SRQ_IDX_BA_PG_SZ_S, SRQC_BYTE_44_SRQ_IDX_BA_PG_SZ_M,
hr_dev->caps.idx_ba_pg_sz + PG_SHIFT_OFFSET); SRQC_BYTE_44_SRQ_IDX_BA_PG_SZ_S,
roce_set_field(srq_context->byte_44_idxbufpgsz_addr, to_hr_hw_page_shift(srq->idx_que.mtr.hem_cfg.ba_pg_shift));
SRQC_BYTE_44_SRQ_IDX_BUF_PG_SZ_M, roce_set_field(
SRQC_BYTE_44_SRQ_IDX_BUF_PG_SZ_S, srq_context->byte_44_idxbufpgsz_addr,
hr_dev->caps.idx_buf_pg_sz + PG_SHIFT_OFFSET); SRQC_BYTE_44_SRQ_IDX_BUF_PG_SZ_M,
SRQC_BYTE_44_SRQ_IDX_BUF_PG_SZ_S,
to_hr_hw_page_shift(srq->idx_que.mtr.hem_cfg.buf_pg_shift));
srq_context->idx_nxt_blk_addr = srq_context->idx_nxt_blk_addr =
cpu_to_le32(mtts_idx[1] >> PAGE_ADDR_SHIFT); cpu_to_le32(to_hr_hw_page_addr(mtts_idx[1]));
roce_set_field(srq_context->rsv_idxnxtblkaddr, roce_set_field(srq_context->rsv_idxnxtblkaddr,
SRQC_BYTE_52_SRQ_IDX_NXT_BLK_ADDR_M, SRQC_BYTE_52_SRQ_IDX_NXT_BLK_ADDR_M,
SRQC_BYTE_52_SRQ_IDX_NXT_BLK_ADDR_S, SRQC_BYTE_52_SRQ_IDX_NXT_BLK_ADDR_S,
mtts_idx[1] >> (32 + PAGE_ADDR_SHIFT)); upper_32_bits(to_hr_hw_page_addr(mtts_idx[1])));
roce_set_field(srq_context->byte_56_xrc_cqn, roce_set_field(srq_context->byte_56_xrc_cqn,
SRQC_BYTE_56_SRQ_XRC_CQN_M, SRQC_BYTE_56_SRQ_XRC_CQN_S, SRQC_BYTE_56_SRQ_XRC_CQN_M, SRQC_BYTE_56_SRQ_XRC_CQN_S,
cqn); cqn);
roce_set_field(srq_context->byte_56_xrc_cqn, roce_set_field(srq_context->byte_56_xrc_cqn,
SRQC_BYTE_56_SRQ_WQE_BA_PG_SZ_M, SRQC_BYTE_56_SRQ_WQE_BA_PG_SZ_M,
SRQC_BYTE_56_SRQ_WQE_BA_PG_SZ_S, SRQC_BYTE_56_SRQ_WQE_BA_PG_SZ_S,
hr_dev->caps.srqwqe_ba_pg_sz + PG_SHIFT_OFFSET); to_hr_hw_page_shift(srq->buf_mtr.hem_cfg.ba_pg_shift));
roce_set_field(srq_context->byte_56_xrc_cqn, roce_set_field(srq_context->byte_56_xrc_cqn,
SRQC_BYTE_56_SRQ_WQE_BUF_PG_SZ_M, SRQC_BYTE_56_SRQ_WQE_BUF_PG_SZ_M,
SRQC_BYTE_56_SRQ_WQE_BUF_PG_SZ_S, SRQC_BYTE_56_SRQ_WQE_BUF_PG_SZ_S,
hr_dev->caps.srqwqe_buf_pg_sz + PG_SHIFT_OFFSET); to_hr_hw_page_shift(srq->buf_mtr.hem_cfg.buf_pg_shift));
roce_set_bit(srq_context->db_record_addr_record_en, roce_set_bit(srq_context->db_record_addr_record_en,
SRQC_BYTE_60_SRQ_RECORD_EN_S, 0); SRQC_BYTE_60_SRQ_RECORD_EN_S, 0);
...@@ -5847,7 +5849,7 @@ static void fill_idx_queue(struct hns_roce_idx_que *idx_que, ...@@ -5847,7 +5849,7 @@ static void fill_idx_queue(struct hns_roce_idx_que *idx_que,
{ {
unsigned int *addr; unsigned int *addr;
addr = (unsigned int *)hns_roce_buf_offset(&idx_que->idx_buf, addr = (unsigned int *)hns_roce_buf_offset(idx_que->mtr.kmem,
cur_idx * idx_que->entry_sz); cur_idx * idx_que->entry_sz);
*addr = wqe_idx; *addr = wqe_idx;
} }
......
...@@ -77,56 +77,56 @@ static int hns_roce_hw_destroy_srq(struct hns_roce_dev *dev, ...@@ -77,56 +77,56 @@ static int hns_roce_hw_destroy_srq(struct hns_roce_dev *dev,
HNS_ROCE_CMD_TIMEOUT_MSECS); HNS_ROCE_CMD_TIMEOUT_MSECS);
} }
static int hns_roce_srq_alloc(struct hns_roce_dev *hr_dev, u32 pdn, u32 cqn, static int alloc_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
u16 xrcd, struct hns_roce_mtt *hr_mtt, u32 pdn, u32 cqn, u16 xrcd, u64 db_rec_addr)
u64 db_rec_addr, struct hns_roce_srq *srq)
{ {
struct hns_roce_srq_table *srq_table = &hr_dev->srq_table; struct hns_roce_srq_table *srq_table = &hr_dev->srq_table;
struct ib_device *ibdev = &hr_dev->ib_dev;
struct hns_roce_cmd_mailbox *mailbox; struct hns_roce_cmd_mailbox *mailbox;
dma_addr_t dma_handle_wqe; u64 mtts_wqe[MTT_MIN_COUNT] = { 0 };
dma_addr_t dma_handle_idx; u64 mtts_idx[MTT_MIN_COUNT] = { 0 };
u64 *mtts_wqe; dma_addr_t dma_handle_wqe = 0;
u64 *mtts_idx; dma_addr_t dma_handle_idx = 0;
int ret; int ret;
/* Get the physical address of srq buf */ /* Get the physical address of srq buf */
mtts_wqe = hns_roce_table_find(hr_dev, ret = hns_roce_mtr_find(hr_dev, &srq->buf_mtr, 0, mtts_wqe,
&hr_dev->mr_table.mtt_srqwqe_table, ARRAY_SIZE(mtts_wqe), &dma_handle_wqe);
srq->mtt.first_seg, if (ret < 1) {
&dma_handle_wqe); ibdev_err(ibdev, "Failed to find mtr for SRQ WQE\n");
if (!mtts_wqe) { return -ENOBUFS;
dev_err(hr_dev->dev, "Failed to find mtt for srq buf.\n");
return -EINVAL;
} }
/* Get physical address of idx que buf */ /* Get physical address of idx que buf */
mtts_idx = hns_roce_table_find(hr_dev, &hr_dev->mr_table.mtt_idx_table, ret = hns_roce_mtr_find(hr_dev, &srq->idx_que.mtr, 0, mtts_idx,
srq->idx_que.mtt.first_seg, ARRAY_SIZE(mtts_idx), &dma_handle_idx);
&dma_handle_idx); if (ret < 1) {
if (!mtts_idx) { ibdev_err(ibdev, "Failed to find mtr for SRQ idx\n");
dev_err(hr_dev->dev, return -ENOBUFS;
"Failed to find mtt for srq idx queue buf.\n");
return -EINVAL;
} }
ret = hns_roce_bitmap_alloc(&srq_table->bitmap, &srq->srqn); ret = hns_roce_bitmap_alloc(&srq_table->bitmap, &srq->srqn);
if (ret) { if (ret) {
dev_err(hr_dev->dev, ibdev_err(ibdev, "Failed to alloc SRQ number, err %d\n", ret);
"Failed to alloc a bit from srq bitmap.\n");
return -ENOMEM; return -ENOMEM;
} }
ret = hns_roce_table_get(hr_dev, &srq_table->table, srq->srqn); ret = hns_roce_table_get(hr_dev, &srq_table->table, srq->srqn);
if (ret) if (ret) {
ibdev_err(ibdev, "Failed to get SRQC table, err %d\n", ret);
goto err_out; goto err_out;
}
ret = xa_err(xa_store(&srq_table->xa, srq->srqn, srq, GFP_KERNEL)); ret = xa_err(xa_store(&srq_table->xa, srq->srqn, srq, GFP_KERNEL));
if (ret) if (ret) {
ibdev_err(ibdev, "Failed to store SRQC, err %d\n", ret);
goto err_put; goto err_put;
}
mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); mailbox = hns_roce_alloc_cmd_mailbox(hr_dev);
if (IS_ERR(mailbox)) { if (IS_ERR_OR_NULL(mailbox)) {
ret = PTR_ERR(mailbox); ret = -ENOMEM;
ibdev_err(ibdev, "Failed to alloc mailbox for SRQC\n");
goto err_xa; goto err_xa;
} }
...@@ -136,8 +136,10 @@ static int hns_roce_srq_alloc(struct hns_roce_dev *hr_dev, u32 pdn, u32 cqn, ...@@ -136,8 +136,10 @@ static int hns_roce_srq_alloc(struct hns_roce_dev *hr_dev, u32 pdn, u32 cqn,
ret = hns_roce_hw_create_srq(hr_dev, mailbox, srq->srqn); ret = hns_roce_hw_create_srq(hr_dev, mailbox, srq->srqn);
hns_roce_free_cmd_mailbox(hr_dev, mailbox); hns_roce_free_cmd_mailbox(hr_dev, mailbox);
if (ret) if (ret) {
ibdev_err(ibdev, "Failed to config SRQC, err %d\n", ret);
goto err_xa; goto err_xa;
}
atomic_set(&srq->refcount, 1); atomic_set(&srq->refcount, 1);
init_completion(&srq->free); init_completion(&srq->free);
...@@ -154,8 +156,7 @@ static int hns_roce_srq_alloc(struct hns_roce_dev *hr_dev, u32 pdn, u32 cqn, ...@@ -154,8 +156,7 @@ static int hns_roce_srq_alloc(struct hns_roce_dev *hr_dev, u32 pdn, u32 cqn,
return ret; return ret;
} }
static void hns_roce_srq_free(struct hns_roce_dev *hr_dev, static void free_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
struct hns_roce_srq *srq)
{ {
struct hns_roce_srq_table *srq_table = &hr_dev->srq_table; struct hns_roce_srq_table *srq_table = &hr_dev->srq_table;
int ret; int ret;
...@@ -175,185 +176,104 @@ static void hns_roce_srq_free(struct hns_roce_dev *hr_dev, ...@@ -175,185 +176,104 @@ static void hns_roce_srq_free(struct hns_roce_dev *hr_dev,
hns_roce_bitmap_free(&srq_table->bitmap, srq->srqn, BITMAP_NO_RR); hns_roce_bitmap_free(&srq_table->bitmap, srq->srqn, BITMAP_NO_RR);
} }
static int create_user_srq(struct hns_roce_srq *srq, struct ib_udata *udata, static int alloc_srq_buf(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
int srq_buf_size) struct ib_udata *udata, unsigned long addr)
{ {
struct hns_roce_dev *hr_dev = to_hr_dev(srq->ibsrq.device); struct ib_device *ibdev = &hr_dev->ib_dev;
struct hns_roce_ib_create_srq ucmd; struct hns_roce_buf_attr buf_attr = {};
int page_shift; int sge_size;
int page_count; int err;
int ret;
if (ib_copy_from_udata(&ucmd, udata, sizeof(ucmd)))
return -EFAULT;
srq->umem = sge_size = roundup_pow_of_two(max(HNS_ROCE_SGE_SIZE,
ib_umem_get(srq->ibsrq.device, ucmd.buf_addr, srq_buf_size, 0); HNS_ROCE_SGE_SIZE * srq->max_gs));
if (IS_ERR(srq->umem))
return PTR_ERR(srq->umem);
page_count = (ib_umem_page_count(srq->umem) + srq->wqe_shift = ilog2(sge_size);
(1 << hr_dev->caps.srqwqe_buf_pg_sz) - 1) /
(1 << hr_dev->caps.srqwqe_buf_pg_sz);
page_shift = PAGE_SHIFT + hr_dev->caps.srqwqe_buf_pg_sz;
ret = hns_roce_mtt_init(hr_dev, page_count, page_shift,
&srq->mtt);
if (ret)
goto err_user_buf;
ret = hns_roce_ib_umem_write_mtt(hr_dev, &srq->mtt, srq->umem); buf_attr.page_shift = hr_dev->caps.srqwqe_buf_pg_sz + PAGE_ADDR_SHIFT;
if (ret) buf_attr.region[0].size = srq->wqe_cnt * sge_size;
goto err_user_srq_mtt; buf_attr.region[0].hopnum = hr_dev->caps.srqwqe_hop_num;
buf_attr.region_count = 1;
/* config index queue BA */ buf_attr.fixed_page = true;
srq->idx_que.umem = ib_umem_get(srq->ibsrq.device, ucmd.que_addr,
srq->idx_que.buf_size, 0);
if (IS_ERR(srq->idx_que.umem)) {
dev_err(hr_dev->dev, "ib_umem_get error for index queue\n");
ret = PTR_ERR(srq->idx_que.umem);
goto err_user_srq_mtt;
}
page_count = DIV_ROUND_UP(ib_umem_page_count(srq->idx_que.umem), err = hns_roce_mtr_create(hr_dev, &srq->buf_mtr, &buf_attr,
1 << hr_dev->caps.idx_buf_pg_sz); hr_dev->caps.srqwqe_ba_pg_sz +
page_shift = PAGE_SHIFT + hr_dev->caps.idx_buf_pg_sz; PAGE_ADDR_SHIFT, udata, addr);
ret = hns_roce_mtt_init(hr_dev, page_count, page_shift, if (err)
&srq->idx_que.mtt); ibdev_err(ibdev, "Failed to alloc SRQ buf mtr, err %d\n", err);
if (ret) {
dev_err(hr_dev->dev, "hns_roce_mtt_init error for idx que\n");
goto err_user_idx_mtt;
}
ret = hns_roce_ib_umem_write_mtt(hr_dev, &srq->idx_que.mtt,
srq->idx_que.umem);
if (ret) {
dev_err(hr_dev->dev,
"hns_roce_ib_umem_write_mtt error for idx que\n");
goto err_user_idx_buf;
}
return 0; return err;
}
err_user_idx_buf:
hns_roce_mtt_cleanup(hr_dev, &srq->idx_que.mtt);
err_user_idx_mtt:
ib_umem_release(srq->idx_que.umem);
err_user_srq_mtt:
hns_roce_mtt_cleanup(hr_dev, &srq->mtt);
err_user_buf:
ib_umem_release(srq->umem);
return ret; static void free_srq_buf(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
{
hns_roce_mtr_destroy(hr_dev, &srq->buf_mtr);
} }
static int hns_roce_create_idx_que(struct ib_pd *pd, struct hns_roce_srq *srq, static int alloc_srq_idx(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
u32 page_shift) struct ib_udata *udata, unsigned long addr)
{ {
struct hns_roce_dev *hr_dev = to_hr_dev(pd->device);
struct hns_roce_idx_que *idx_que = &srq->idx_que; struct hns_roce_idx_que *idx_que = &srq->idx_que;
struct ib_device *ibdev = &hr_dev->ib_dev;
struct hns_roce_buf_attr buf_attr = {};
int err;
idx_que->bitmap = bitmap_zalloc(srq->wqe_cnt, GFP_KERNEL); srq->idx_que.entry_sz = HNS_ROCE_IDX_QUE_ENTRY_SZ;
if (!idx_que->bitmap)
return -ENOMEM; buf_attr.page_shift = hr_dev->caps.idx_buf_pg_sz + PAGE_ADDR_SHIFT;
buf_attr.region[0].size = srq->wqe_cnt * HNS_ROCE_IDX_QUE_ENTRY_SZ;
buf_attr.region[0].hopnum = hr_dev->caps.idx_hop_num;
buf_attr.region_count = 1;
buf_attr.fixed_page = true;
err = hns_roce_mtr_create(hr_dev, &idx_que->mtr, &buf_attr,
hr_dev->caps.idx_ba_pg_sz + PAGE_ADDR_SHIFT,
udata, addr);
if (err) {
ibdev_err(ibdev, "Failed to alloc SRQ idx mtr, err %d\n", err);
return err;
}
idx_que->buf_size = srq->idx_que.buf_size; if (!udata) {
idx_que->bitmap = bitmap_zalloc(srq->wqe_cnt, GFP_KERNEL);
if (!idx_que->bitmap) {
ibdev_err(ibdev, "Failed to alloc SRQ idx bitmap\n");
err = -ENOMEM;
goto err_idx_mtr;
}
if (hns_roce_buf_alloc(hr_dev, idx_que->buf_size, (1 << page_shift) * 2,
&idx_que->idx_buf, page_shift)) {
bitmap_free(idx_que->bitmap);
return -ENOMEM;
} }
return 0; return 0;
err_idx_mtr:
hns_roce_mtr_destroy(hr_dev, &idx_que->mtr);
return err;
} }
static int create_kernel_srq(struct hns_roce_srq *srq, int srq_buf_size) static void free_srq_idx(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
{ {
struct hns_roce_dev *hr_dev = to_hr_dev(srq->ibsrq.device); struct hns_roce_idx_que *idx_que = &srq->idx_que;
u32 page_shift = PAGE_SHIFT + hr_dev->caps.srqwqe_buf_pg_sz;
int ret;
if (hns_roce_buf_alloc(hr_dev, srq_buf_size, (1 << page_shift) * 2, bitmap_free(idx_que->bitmap);
&srq->buf, page_shift)) idx_que->bitmap = NULL;
return -ENOMEM; hns_roce_mtr_destroy(hr_dev, &idx_que->mtr);
}
static int alloc_srq_wrid(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
{
srq->head = 0; srq->head = 0;
srq->tail = srq->wqe_cnt - 1; srq->tail = srq->wqe_cnt - 1;
ret = hns_roce_mtt_init(hr_dev, srq->buf.npages, srq->buf.page_shift,
&srq->mtt);
if (ret)
goto err_kernel_buf;
ret = hns_roce_buf_write_mtt(hr_dev, &srq->mtt, &srq->buf);
if (ret)
goto err_kernel_srq_mtt;
page_shift = PAGE_SHIFT + hr_dev->caps.idx_buf_pg_sz;
ret = hns_roce_create_idx_que(srq->ibsrq.pd, srq, page_shift);
if (ret) {
dev_err(hr_dev->dev, "Create idx queue fail(%d)!\n", ret);
goto err_kernel_srq_mtt;
}
/* Init mtt table for idx_que */
ret = hns_roce_mtt_init(hr_dev, srq->idx_que.idx_buf.npages,
srq->idx_que.idx_buf.page_shift,
&srq->idx_que.mtt);
if (ret)
goto err_kernel_create_idx;
/* Write buffer address into the mtt table */
ret = hns_roce_buf_write_mtt(hr_dev, &srq->idx_que.mtt,
&srq->idx_que.idx_buf);
if (ret)
goto err_kernel_idx_buf;
srq->wrid = kvmalloc_array(srq->wqe_cnt, sizeof(u64), GFP_KERNEL); srq->wrid = kvmalloc_array(srq->wqe_cnt, sizeof(u64), GFP_KERNEL);
if (!srq->wrid) { if (!srq->wrid)
ret = -ENOMEM; return -ENOMEM;
goto err_kernel_idx_buf;
}
return 0; return 0;
err_kernel_idx_buf:
hns_roce_mtt_cleanup(hr_dev, &srq->idx_que.mtt);
err_kernel_create_idx:
hns_roce_buf_free(hr_dev, &srq->idx_que.idx_buf);
kfree(srq->idx_que.bitmap);
err_kernel_srq_mtt:
hns_roce_mtt_cleanup(hr_dev, &srq->mtt);
err_kernel_buf:
hns_roce_buf_free(hr_dev, &srq->buf);
return ret;
}
static void destroy_user_srq(struct hns_roce_dev *hr_dev,
struct hns_roce_srq *srq)
{
hns_roce_mtt_cleanup(hr_dev, &srq->idx_que.mtt);
ib_umem_release(srq->idx_que.umem);
hns_roce_mtt_cleanup(hr_dev, &srq->mtt);
ib_umem_release(srq->umem);
} }
static void destroy_kernel_srq(struct hns_roce_dev *hr_dev, static void free_srq_wrid(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
struct hns_roce_srq *srq)
{ {
kvfree(srq->wrid); kfree(srq->wrid);
hns_roce_mtt_cleanup(hr_dev, &srq->idx_que.mtt); srq->wrid = NULL;
hns_roce_buf_free(hr_dev, &srq->idx_que.idx_buf);
kfree(srq->idx_que.bitmap);
hns_roce_mtt_cleanup(hr_dev, &srq->mtt);
hns_roce_buf_free(hr_dev, &srq->buf);
} }
int hns_roce_create_srq(struct ib_srq *ib_srq, int hns_roce_create_srq(struct ib_srq *ib_srq,
...@@ -363,8 +283,8 @@ int hns_roce_create_srq(struct ib_srq *ib_srq, ...@@ -363,8 +283,8 @@ int hns_roce_create_srq(struct ib_srq *ib_srq,
struct hns_roce_dev *hr_dev = to_hr_dev(ib_srq->device); struct hns_roce_dev *hr_dev = to_hr_dev(ib_srq->device);
struct hns_roce_ib_create_srq_resp resp = {}; struct hns_roce_ib_create_srq_resp resp = {};
struct hns_roce_srq *srq = to_hr_srq(ib_srq); struct hns_roce_srq *srq = to_hr_srq(ib_srq);
int srq_desc_size; struct ib_device *ibdev = &hr_dev->ib_dev;
int srq_buf_size; struct hns_roce_ib_create_srq ucmd = {};
int ret = 0; int ret = 0;
u32 cqn; u32 cqn;
...@@ -379,41 +299,45 @@ int hns_roce_create_srq(struct ib_srq *ib_srq, ...@@ -379,41 +299,45 @@ int hns_roce_create_srq(struct ib_srq *ib_srq,
srq->wqe_cnt = roundup_pow_of_two(init_attr->attr.max_wr + 1); srq->wqe_cnt = roundup_pow_of_two(init_attr->attr.max_wr + 1);
srq->max_gs = init_attr->attr.max_sge; srq->max_gs = init_attr->attr.max_sge;
srq_desc_size = roundup_pow_of_two(max(HNS_ROCE_SGE_SIZE,
HNS_ROCE_SGE_SIZE * srq->max_gs));
srq->wqe_shift = ilog2(srq_desc_size);
srq_buf_size = srq->wqe_cnt * srq_desc_size;
srq->idx_que.entry_sz = HNS_ROCE_IDX_QUE_ENTRY_SZ;
srq->idx_que.buf_size = srq->wqe_cnt * srq->idx_que.entry_sz;
srq->mtt.mtt_type = MTT_TYPE_SRQWQE;
srq->idx_que.mtt.mtt_type = MTT_TYPE_IDX;
if (udata) { if (udata) {
ret = create_user_srq(srq, udata, srq_buf_size); ret = ib_copy_from_udata(&ucmd, udata, sizeof(ucmd));
if (ret) { if (ret) {
dev_err(hr_dev->dev, "Create user srq failed\n"); ibdev_err(ibdev, "Failed to copy SRQ udata, err %d\n",
goto err_srq; ret);
return ret;
} }
} else { }
ret = create_kernel_srq(srq, srq_buf_size);
ret = alloc_srq_buf(hr_dev, srq, udata, ucmd.buf_addr);
if (ret) {
ibdev_err(ibdev, "Failed to alloc SRQ buffer, err %d\n", ret);
return ret;
}
ret = alloc_srq_idx(hr_dev, srq, udata, ucmd.que_addr);
if (ret) {
ibdev_err(ibdev, "Failed to alloc SRQ idx, err %d\n", ret);
goto err_buf_alloc;
}
if (!udata) {
ret = alloc_srq_wrid(hr_dev, srq);
if (ret) { if (ret) {
dev_err(hr_dev->dev, "Create kernel srq failed\n"); ibdev_err(ibdev, "Failed to alloc SRQ wrid, err %d\n",
goto err_srq; ret);
goto err_idx_alloc;
} }
} }
cqn = ib_srq_has_cq(init_attr->srq_type) ? cqn = ib_srq_has_cq(init_attr->srq_type) ?
to_hr_cq(init_attr->ext.cq)->cqn : 0; to_hr_cq(init_attr->ext.cq)->cqn : 0;
srq->db_reg_l = hr_dev->reg_base + SRQ_DB_REG; srq->db_reg_l = hr_dev->reg_base + SRQ_DB_REG;
ret = hns_roce_srq_alloc(hr_dev, to_hr_pd(ib_srq->pd)->pdn, cqn, 0, ret = alloc_srqc(hr_dev, srq, to_hr_pd(ib_srq->pd)->pdn, cqn, 0, 0);
&srq->mtt, 0, srq); if (ret) {
if (ret) ibdev_err(ibdev, "Failed to alloc SRQ context, err %d\n", ret);
goto err_wrid; goto err_wrid_alloc;
}
srq->event = hns_roce_ib_srq_event; srq->event = hns_roce_ib_srq_event;
resp.srqn = srq->srqn; resp.srqn = srq->srqn;
...@@ -429,15 +353,13 @@ int hns_roce_create_srq(struct ib_srq *ib_srq, ...@@ -429,15 +353,13 @@ int hns_roce_create_srq(struct ib_srq *ib_srq,
return 0; return 0;
err_srqc_alloc: err_srqc_alloc:
hns_roce_srq_free(hr_dev, srq); free_srqc(hr_dev, srq);
err_wrid_alloc:
err_wrid: free_srq_wrid(hr_dev, srq);
if (udata) err_idx_alloc:
destroy_user_srq(hr_dev, srq); free_srq_idx(hr_dev, srq);
else err_buf_alloc:
destroy_kernel_srq(hr_dev, srq); free_srq_buf(hr_dev, srq);
err_srq:
return ret; return ret;
} }
...@@ -446,17 +368,10 @@ void hns_roce_destroy_srq(struct ib_srq *ibsrq, struct ib_udata *udata) ...@@ -446,17 +368,10 @@ void hns_roce_destroy_srq(struct ib_srq *ibsrq, struct ib_udata *udata)
struct hns_roce_dev *hr_dev = to_hr_dev(ibsrq->device); struct hns_roce_dev *hr_dev = to_hr_dev(ibsrq->device);
struct hns_roce_srq *srq = to_hr_srq(ibsrq); struct hns_roce_srq *srq = to_hr_srq(ibsrq);
hns_roce_srq_free(hr_dev, srq); free_srqc(hr_dev, srq);
hns_roce_mtt_cleanup(hr_dev, &srq->mtt); free_srq_idx(hr_dev, srq);
free_srq_wrid(hr_dev, srq);
if (udata) { free_srq_buf(hr_dev, srq);
hns_roce_mtt_cleanup(hr_dev, &srq->idx_que.mtt);
} else {
kvfree(srq->wrid);
hns_roce_buf_free(hr_dev, &srq->buf);
}
ib_umem_release(srq->idx_que.umem);
ib_umem_release(srq->umem);
} }
int hns_roce_init_srq_table(struct hns_roce_dev *hr_dev) int hns_roce_init_srq_table(struct hns_roce_dev *hr_dev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment