From patchwork Sat Oct 27 10:56:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lijun Ou X-Patchwork-Id: 10658337 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41AD313A9 for ; Sat, 27 Oct 2018 10:54:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 382462B1A1 for ; Sat, 27 Oct 2018 10:54:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C95F2B5E8; Sat, 27 Oct 2018 10:54:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89BDC2B542 for ; Sat, 27 Oct 2018 10:54:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728457AbeJ0TfT (ORCPT ); Sat, 27 Oct 2018 15:35:19 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:52332 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728386AbeJ0TfT (ORCPT ); Sat, 27 Oct 2018 15:35:19 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id EB2A49DC5424A; Sat, 27 Oct 2018 18:54:42 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.408.0; Sat, 27 Oct 2018 18:54:39 +0800 From: Lijun Ou To: , CC: , Subject: [PATCH rdma-core 1/6] libhns: Add verb of creating srq for hip08 user mode Date: Sat, 27 Oct 2018 18:56:32 +0800 Message-ID: <1540637797-97065-2-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1540637797-97065-1-git-send-email-oulijun@huawei.com> References: <1540637797-97065-1-git-send-email-oulijun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Lijun Ou --- kernel-headers/rdma/hns-abi.h | 11 +++ providers/hns/hns_roce_u.c | 1 + providers/hns/hns_roce_u.h | 19 ++++- providers/hns/hns_roce_u_abi.h | 3 + providers/hns/hns_roce_u_hw_v2.h | 2 + providers/hns/hns_roce_u_verbs.c | 146 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 180 insertions(+), 2 deletions(-) diff --git a/kernel-headers/rdma/hns-abi.h b/kernel-headers/rdma/hns-abi.h index c1f8773..eb76b38 100644 --- a/kernel-headers/rdma/hns-abi.h +++ b/kernel-headers/rdma/hns-abi.h @@ -46,6 +46,17 @@ struct hns_roce_ib_create_cq_resp { __aligned_u64 cap_flags; }; +struct hns_roce_ib_create_srq { + __aligned_u64 buf_addr; + __aligned_u64 db_addr; + __aligned_u64 que_addr; +}; + +struct hns_roce_ib_create_srq_resp { + __u32 srqn; + __u32 reserved; +}; + struct hns_roce_ib_create_qp { __aligned_u64 buf_addr; __aligned_u64 db_addr; diff --git a/providers/hns/hns_roce_u.c b/providers/hns/hns_roce_u.c index 3597e9a..fe12b11 100644 --- a/providers/hns/hns_roce_u.c +++ b/providers/hns/hns_roce_u.c @@ -78,6 +78,7 @@ static const struct verbs_context_ops hns_common_ops = { .query_qp = hns_roce_u_query_qp, .reg_mr = hns_roce_u_reg_mr, .rereg_mr = hns_roce_u_rereg_mr, + .create_srq = hns_roce_u_create_srq, }; static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev, diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h index 93c917d..3ad1c14 100644 --- a/providers/hns/hns_roce_u.h +++ b/providers/hns/hns_roce_u.h @@ -95,6 +95,9 @@ struct hns_roce_buf { unsigned int length; }; +#define BIT_CNT_PER_BYTE 8 + + /* the sw doorbell type; */ enum hns_roce_db_type { HNS_ROCE_QP_TYPE_DB, @@ -154,8 +157,16 @@ struct hns_roce_cq { unsigned long flags; }; +struct hns_roce_idx_que { + struct hns_roce_buf buf; + int buf_size; + int entry_sz; + unsigned long *bitmap; + unsigned long use_cnt; +}; + struct hns_roce_srq { - struct ibv_srq ibv_srq; + struct verbs_srq verbs_srq; struct hns_roce_buf buf; pthread_spinlock_t lock; unsigned long *wrid; @@ -167,6 +178,7 @@ struct hns_roce_srq { int tail; unsigned int *db; unsigned short counter; + struct hns_roce_idx_que idx_que; }; struct hns_roce_wq { @@ -253,7 +265,8 @@ static inline struct hns_roce_cq *to_hr_cq(struct ibv_cq *ibv_cq) static inline struct hns_roce_srq *to_hr_srq(struct ibv_srq *ibv_srq) { - return container_of(ibv_srq, struct hns_roce_srq, ibv_srq); + return container_of(container_of(ibv_srq, struct verbs_srq, srq), + struct hns_roce_srq, verbs_srq); } static inline struct hns_roce_qp *to_hr_qp(struct ibv_qp *ibv_qp) @@ -288,6 +301,8 @@ int hns_roce_u_modify_cq(struct ibv_cq *cq, struct ibv_modify_cq_attr *attr); int hns_roce_u_destroy_cq(struct ibv_cq *cq); void hns_roce_u_cq_event(struct ibv_cq *cq); +struct ibv_srq *hns_roce_u_create_srq(struct ibv_pd *pd, + struct ibv_srq_init_attr *srq_init_attr); struct ibv_qp *hns_roce_u_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr); diff --git a/providers/hns/hns_roce_u_abi.h b/providers/hns/hns_roce_u_abi.h index 3b646b6..79fd7dd 100644 --- a/providers/hns/hns_roce_u_abi.h +++ b/providers/hns/hns_roce_u_abi.h @@ -46,4 +46,7 @@ DECLARE_DRV_CMD(hns_roce_create_qp, IB_USER_VERBS_CMD_CREATE_QP, DECLARE_DRV_CMD(hns_roce_alloc_ucontext, IB_USER_VERBS_CMD_GET_CONTEXT, empty, hns_roce_ib_alloc_ucontext_resp); +DECLARE_DRV_CMD(hns_roce_create_srq, IB_USER_VERBS_CMD_CREATE_SRQ, + hns_roce_ib_create_srq, hns_roce_ib_create_srq_resp); + #endif /* _HNS_ROCE_U_ABI_H */ diff --git a/providers/hns/hns_roce_u_hw_v2.h b/providers/hns/hns_roce_u_hw_v2.h index ff63bb2..3a019ef 100644 --- a/providers/hns/hns_roce_u_hw_v2.h +++ b/providers/hns/hns_roce_u_hw_v2.h @@ -52,6 +52,8 @@ enum { /* V2 REG DEFINITION */ #define ROCEE_VF_DB_CFG0_OFFSET 0x0230 +#define HNS_ROCE_IDX_QUE_ENTRY_SZ 4 + enum { HNS_ROCE_WQE_OP_SEND = 0x0, HNS_ROCE_WQE_OP_SEND_WITH_INV = 0x1, diff --git a/providers/hns/hns_roce_u_verbs.c b/providers/hns/hns_roce_u_verbs.c index b0f928e..2767667 100644 --- a/providers/hns/hns_roce_u_verbs.c +++ b/providers/hns/hns_roce_u_verbs.c @@ -277,6 +277,16 @@ static int align_queue_size(int req) return nent; } +static int align_srq_size(int req) +{ + int nent; + + for (nent = 1; nent < req; nent <<= 1) + ; + + return nent; +} + static void hns_roce_set_sq_sizes(struct hns_roce_qp *qp, struct ibv_qp_cap *cap, enum ibv_qp_type type) { @@ -434,6 +444,142 @@ int hns_roce_u_destroy_cq(struct ibv_cq *cq) return ret; } +static int hns_roce_create_idx_que(struct ibv_pd *pd, struct hns_roce_srq *srq) +{ + struct hns_roce_idx_que *idx_que = &srq->idx_que; + uint32_t bitmap_num; + int i; + + idx_que->entry_sz = HNS_ROCE_IDX_QUE_ENTRY_SZ; + + /* bits needed in bitmap*/ + bitmap_num = align(srq->max, BIT_CNT_PER_BYTE * sizeof(uint64_t)); + + idx_que->bitmap = calloc(1, bitmap_num / BIT_CNT_PER_BYTE); + if (!idx_que->bitmap) + return -1; + + /* bitmap_num indicates amount of u64 */ + bitmap_num = bitmap_num / (BIT_CNT_PER_BYTE * sizeof(uint64_t)); + + idx_que->buf_size = srq->max * idx_que->entry_sz; + if (hns_roce_alloc_buf(&idx_que->buf, align(idx_que->buf_size, 0x1000), + to_hr_dev(pd->context->device)->page_size)) { + free(idx_que->bitmap); + idx_que->bitmap = NULL; + return -1; + } + + memset(idx_que->buf.buf, 0, idx_que->buf_size); + + /*init the idx_que bitmap */ + for (i = 0; i < bitmap_num; ++i) + idx_que->bitmap[i] = ~(0UL); + + return 0; +} + +static int hns_roce_alloc_srq_buf(struct ibv_pd *pd, struct ibv_srq_attr *attr, + struct hns_roce_srq *srq) +{ + int srq_buf_size; + int srq_size; + + srq->wrid = calloc(1, srq->max * sizeof(unsigned long)); + if (!srq->wrid) + return -1; + + /* srq size */ + srq_size = srq->max_gs * sizeof(struct hns_roce_v2_wqe_data_seg); + + for (srq->wqe_shift = 4; 1 << srq->wqe_shift < srq_size; + ++srq->wqe_shift) + ; /* nothing */ + + srq_buf_size = srq->max << srq->wqe_shift; + + /* allocate srq wqe buf */ + if (hns_roce_alloc_buf(&srq->buf, srq_buf_size, + to_hr_dev(pd->context->device)->page_size)) { + free(srq->wrid); + return -1; + } + + memset(srq->buf.buf, 0, srq_buf_size); + + srq->head = 0; + srq->tail = srq->max - 1; + + return 0; +} + +struct ibv_srq *hns_roce_u_create_srq(struct ibv_pd *pd, + struct ibv_srq_init_attr *srq_init_attr) +{ + struct hns_roce_create_srq cmd; + struct hns_roce_create_srq_resp resp; + struct hns_roce_srq *srq; + int ret; + + if (srq_init_attr->attr.max_wr > (1 << 15) || + srq_init_attr->attr.max_sge > (1 << 8)) + return NULL; + + srq = calloc(1, sizeof(*srq)); + if (!srq) + return NULL; + + if (pthread_spin_init(&srq->lock, PTHREAD_PROCESS_PRIVATE)) + goto out; + + srq->max = align_srq_size(srq_init_attr->attr.max_wr + 1); + srq->max_gs = srq_init_attr->attr.max_sge; + + ret = hns_roce_create_idx_que(pd, srq); + if (ret) { + fprintf(stderr, "hns_roce_create_idx_que failed!\n"); + goto out; + } + + if (hns_roce_alloc_srq_buf(pd, &srq_init_attr->attr, srq)) { + fprintf(stderr, "hns_roce_alloc_srq_buf failed!\n"); + goto err_idx_que; + } + + srq->db = hns_roce_alloc_db(to_hr_ctx(pd->context), + HNS_ROCE_QP_TYPE_DB); + if (!srq->db) + goto err_srq_buf; + + *(srq->db) = 0; + cmd.buf_addr = (uintptr_t)srq->buf.buf; + cmd.que_addr = (uintptr_t)srq->idx_que.buf.buf; + cmd.db_addr = (uintptr_t)srq->db; + + ret = ibv_cmd_create_srq(pd, &srq->verbs_srq.srq, srq_init_attr, + &cmd.ibv_cmd, sizeof(cmd), &resp.ibv_resp, + sizeof(resp)); + if (ret) + goto err_srq_db; + + srq->srqn = resp.srqn; + return &srq->verbs_srq.srq; + +err_srq_db: + hns_roce_free_db(to_hr_ctx(pd->context), srq->db, HNS_ROCE_QP_TYPE_DB); + +err_srq_buf: + free(srq->wrid); + hns_roce_free_buf(&srq->buf); + +err_idx_que: + free(&srq->idx_que.bitmap); + hns_roce_free_buf(&srq->idx_que.buf); +out: + free(srq); + return NULL; +} + static int hns_roce_verify_qp(struct ibv_qp_init_attr *attr, struct hns_roce_context *context) { From patchwork Sat Oct 27 10:56:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lijun Ou X-Patchwork-Id: 10658343 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA00C13A9 for ; Sat, 27 Oct 2018 10:54:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D167D2B1A1 for ; Sat, 27 Oct 2018 10:54:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1EAC2B5E8; Sat, 27 Oct 2018 10:54:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7021C2B1A1 for ; Sat, 27 Oct 2018 10:54:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728474AbeJ0TfW (ORCPT ); Sat, 27 Oct 2018 15:35:22 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:14145 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728465AbeJ0TfW (ORCPT ); Sat, 27 Oct 2018 15:35:22 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 94ACC64A161D4; Sat, 27 Oct 2018 18:54:42 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.408.0; Sat, 27 Oct 2018 18:54:39 +0800 From: Lijun Ou To: , CC: , Subject: [PATCH rdma-core 2/6] libhns: Add modify srq verb for hip08 user mode Date: Sat, 27 Oct 2018 18:56:33 +0800 Message-ID: <1540637797-97065-3-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1540637797-97065-1-git-send-email-oulijun@huawei.com> References: <1540637797-97065-1-git-send-email-oulijun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch mainly implement the verbs of modifing srq for hip08 userspace library. Signed-off-by: Lijun Ou --- providers/hns/hns_roce_u.c | 1 + providers/hns/hns_roce_u.h | 2 ++ providers/hns/hns_roce_u_verbs.c | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/providers/hns/hns_roce_u.c b/providers/hns/hns_roce_u.c index fe12b11..81b74f3 100644 --- a/providers/hns/hns_roce_u.c +++ b/providers/hns/hns_roce_u.c @@ -79,6 +79,7 @@ static const struct verbs_context_ops hns_common_ops = { .reg_mr = hns_roce_u_reg_mr, .rereg_mr = hns_roce_u_rereg_mr, .create_srq = hns_roce_u_create_srq, + .modify_srq = hns_roce_u_modify_srq, }; static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev, diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h index 3ad1c14..dd9ba88 100644 --- a/providers/hns/hns_roce_u.h +++ b/providers/hns/hns_roce_u.h @@ -303,6 +303,8 @@ void hns_roce_u_cq_event(struct ibv_cq *cq); struct ibv_srq *hns_roce_u_create_srq(struct ibv_pd *pd, struct ibv_srq_init_attr *srq_init_attr); +int hns_roce_u_modify_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr, + int srq_attr_mask); struct ibv_qp *hns_roce_u_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr); diff --git a/providers/hns/hns_roce_u_verbs.c b/providers/hns/hns_roce_u_verbs.c index 2767667..379d78d 100644 --- a/providers/hns/hns_roce_u_verbs.c +++ b/providers/hns/hns_roce_u_verbs.c @@ -580,6 +580,15 @@ out: return NULL; } +int hns_roce_u_modify_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr, + int srq_attr_mask) +{ + struct ibv_modify_srq cmd; + + return ibv_cmd_modify_srq(srq, srq_attr, srq_attr_mask, &cmd, + sizeof(cmd)); +} + static int hns_roce_verify_qp(struct ibv_qp_init_attr *attr, struct hns_roce_context *context) { From patchwork Sat Oct 27 10:56:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lijun Ou X-Patchwork-Id: 10658335 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C7C1615A7 for ; Sat, 27 Oct 2018 10:54:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C19652B1A1 for ; Sat, 27 Oct 2018 10:54:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B36A62B5E8; Sat, 27 Oct 2018 10:54:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5687C2B1A1 for ; Sat, 27 Oct 2018 10:54:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728398AbeJ0TfT (ORCPT ); Sat, 27 Oct 2018 15:35:19 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:52333 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728477AbeJ0TfT (ORCPT ); Sat, 27 Oct 2018 15:35:19 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id E722C5130F7C5; Sat, 27 Oct 2018 18:54:42 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.408.0; Sat, 27 Oct 2018 18:54:40 +0800 From: Lijun Ou To: , CC: , Subject: [PATCH rdma-core 3/6] libhns: Add query srq verb for hip08 user mode Date: Sat, 27 Oct 2018 18:56:34 +0800 Message-ID: <1540637797-97065-4-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1540637797-97065-1-git-send-email-oulijun@huawei.com> References: <1540637797-97065-1-git-send-email-oulijun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch mainly implement the verbs of querying srq for hip08 userspace library. Signed-off-by: Lijun Ou --- providers/hns/hns_roce_u.c | 1 + providers/hns/hns_roce_u.h | 1 + providers/hns/hns_roce_u_verbs.c | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/providers/hns/hns_roce_u.c b/providers/hns/hns_roce_u.c index 81b74f3..9b46e25 100644 --- a/providers/hns/hns_roce_u.c +++ b/providers/hns/hns_roce_u.c @@ -80,6 +80,7 @@ static const struct verbs_context_ops hns_common_ops = { .rereg_mr = hns_roce_u_rereg_mr, .create_srq = hns_roce_u_create_srq, .modify_srq = hns_roce_u_modify_srq, + .query_srq = hns_roce_u_query_srq, }; static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev, diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h index dd9ba88..2b307e3 100644 --- a/providers/hns/hns_roce_u.h +++ b/providers/hns/hns_roce_u.h @@ -305,6 +305,7 @@ struct ibv_srq *hns_roce_u_create_srq(struct ibv_pd *pd, struct ibv_srq_init_attr *srq_init_attr); int hns_roce_u_modify_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr, int srq_attr_mask); +int hns_roce_u_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr); struct ibv_qp *hns_roce_u_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr); diff --git a/providers/hns/hns_roce_u_verbs.c b/providers/hns/hns_roce_u_verbs.c index 379d78d..5106a35 100644 --- a/providers/hns/hns_roce_u_verbs.c +++ b/providers/hns/hns_roce_u_verbs.c @@ -589,6 +589,13 @@ int hns_roce_u_modify_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr, sizeof(cmd)); } +int hns_roce_u_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr) +{ + struct ibv_query_srq cmd; + + return ibv_cmd_query_srq(srq, srq_attr, &cmd, sizeof(cmd)); +} + static int hns_roce_verify_qp(struct ibv_qp_init_attr *attr, struct hns_roce_context *context) { From patchwork Sat Oct 27 10:56:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lijun Ou X-Patchwork-Id: 10658345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1563C1751 for ; Sat, 27 Oct 2018 10:54:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DB512B1A1 for ; Sat, 27 Oct 2018 10:54:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 024412B562; Sat, 27 Oct 2018 10:54:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 951272B542 for ; Sat, 27 Oct 2018 10:54:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728465AbeJ0TfW (ORCPT ); Sat, 27 Oct 2018 15:35:22 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:14144 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728480AbeJ0TfW (ORCPT ); Sat, 27 Oct 2018 15:35:22 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 98BA862690875; Sat, 27 Oct 2018 18:54:42 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.408.0; Sat, 27 Oct 2018 18:54:40 +0800 From: Lijun Ou To: , CC: , Subject: [PATCH rdma-core 4/6] libhns: Add destroy srq verbs for hip08 user mode Date: Sat, 27 Oct 2018 18:56:35 +0800 Message-ID: <1540637797-97065-5-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1540637797-97065-1-git-send-email-oulijun@huawei.com> References: <1540637797-97065-1-git-send-email-oulijun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch mainly implement the verbs of destroying srq for hip08 userspace library. Signed-off-by: Lijun Ou --- providers/hns/hns_roce_u.c | 1 + providers/hns/hns_roce_u.h | 1 + providers/hns/hns_roce_u_verbs.c | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/providers/hns/hns_roce_u.c b/providers/hns/hns_roce_u.c index 9b46e25..58256ee 100644 --- a/providers/hns/hns_roce_u.c +++ b/providers/hns/hns_roce_u.c @@ -81,6 +81,7 @@ static const struct verbs_context_ops hns_common_ops = { .create_srq = hns_roce_u_create_srq, .modify_srq = hns_roce_u_modify_srq, .query_srq = hns_roce_u_query_srq, + .destroy_srq = hns_roce_u_destroy_srq, }; static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev, diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h index 2b307e3..5248a53 100644 --- a/providers/hns/hns_roce_u.h +++ b/providers/hns/hns_roce_u.h @@ -306,6 +306,7 @@ struct ibv_srq *hns_roce_u_create_srq(struct ibv_pd *pd, int hns_roce_u_modify_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr, int srq_attr_mask); int hns_roce_u_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr); +int hns_roce_u_destroy_srq(struct ibv_srq *srq); struct ibv_qp *hns_roce_u_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr); diff --git a/providers/hns/hns_roce_u_verbs.c b/providers/hns/hns_roce_u_verbs.c index 5106a35..6f54066 100644 --- a/providers/hns/hns_roce_u_verbs.c +++ b/providers/hns/hns_roce_u_verbs.c @@ -596,6 +596,25 @@ int hns_roce_u_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr) return ibv_cmd_query_srq(srq, srq_attr, &cmd, sizeof(cmd)); } +int hns_roce_u_destroy_srq(struct ibv_srq *srq) +{ + int ret; + + ret = ibv_cmd_destroy_srq(srq); + if (ret) + return ret; + + hns_roce_free_db(to_hr_ctx(srq->context), to_hr_srq(srq)->db, + HNS_ROCE_QP_TYPE_DB); + hns_roce_free_buf(&to_hr_srq(srq)->buf); + free(to_hr_srq(srq)->wrid); + hns_roce_free_buf(&to_hr_srq(srq)->idx_que.buf); + free(to_hr_srq(srq)->idx_que.bitmap); + free(to_hr_srq(srq)); + + return 0; +} + static int hns_roce_verify_qp(struct ibv_qp_init_attr *attr, struct hns_roce_context *context) { From patchwork Sat Oct 27 10:56:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lijun Ou X-Patchwork-Id: 10658339 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A06681751 for ; Sat, 27 Oct 2018 10:54:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98DD42B1A1 for ; Sat, 27 Oct 2018 10:54:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D4FB2B542; Sat, 27 Oct 2018 10:54:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 222482B562 for ; Sat, 27 Oct 2018 10:54:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728386AbeJ0TfU (ORCPT ); Sat, 27 Oct 2018 15:35:20 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:52334 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728480AbeJ0TfT (ORCPT ); Sat, 27 Oct 2018 15:35:19 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id F0541B5E24656; Sat, 27 Oct 2018 18:54:42 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.408.0; Sat, 27 Oct 2018 18:54:40 +0800 From: Lijun Ou To: , CC: , Subject: [PATCH rdma-core 5/6] libhns: Add the verb for posting srqwqe Date: Sat, 27 Oct 2018 18:56:36 +0800 Message-ID: <1540637797-97065-6-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1540637797-97065-1-git-send-email-oulijun@huawei.com> References: <1540637797-97065-1-git-send-email-oulijun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch mainly implements the srq recv verb for libhns. Signed-off-by: Lijun Ou --- providers/hns/hns_roce_u.h | 1 - providers/hns/hns_roce_u_hw_v2.c | 107 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h index 5248a53..a9c0113 100644 --- a/providers/hns/hns_roce_u.h +++ b/providers/hns/hns_roce_u.h @@ -162,7 +162,6 @@ struct hns_roce_idx_que { int buf_size; int entry_sz; unsigned long *bitmap; - unsigned long use_cnt; }; struct hns_roce_srq { diff --git a/providers/hns/hns_roce_u_hw_v2.c b/providers/hns/hns_roce_u_hw_v2.c index 4231193..bdf8bbb 100644 --- a/providers/hns/hns_roce_u_hw_v2.c +++ b/providers/hns/hns_roce_u_hw_v2.c @@ -30,6 +30,7 @@ * SOFTWARE. */ +#define _GNU_SOURCE #include #include #include @@ -148,6 +149,11 @@ static void *get_send_sge_ex(struct hns_roce_qp *qp, int n) return qp->buf.buf + qp->sge.offset + (n << qp->sge.sge_shift); } +static void *get_srq_wqe(struct hns_roce_srq *srq, int n) +{ + return srq->buf.buf + (n << srq->wqe_shift); +} + static int hns_roce_v2_wq_overflow(struct hns_roce_wq *wq, int nreq, struct hns_roce_cq *cq) { @@ -1136,6 +1142,106 @@ static int hns_roce_u_v2_destroy_qp(struct ibv_qp *ibqp) return ret; } +static void fill_idx_que(struct hns_roce_idx_que *idx_que, + int cur_idx, int wqe_idx) +{ + unsigned int *addr; + + addr = idx_que->buf.buf + cur_idx * idx_que->entry_sz; + *addr = wqe_idx; +} + +static int find_empty_entry(struct hns_roce_idx_que *idx_que) +{ + int bit_num; + int i; + + /* bitmap[i] is set zero if all bits are allocated */ + for (i = 0; idx_que->bitmap[i] == 0; ++i) + ; + bit_num = ffsl(idx_que->bitmap[i]); + idx_que->bitmap[i] &= ~(1ULL << (bit_num - 1)); + + return i * sizeof(uint64_t) * BIT_CNT_PER_BYTE + (bit_num - 1); +} + +static int hns_roce_u_v2_post_srq_recv(struct ibv_srq *ib_srq, + struct ibv_recv_wr *wr, + struct ibv_recv_wr **bad_wr) +{ + struct hns_roce_context *ctx = to_hr_ctx(ib_srq->context); + struct hns_roce_srq *srq = to_hr_srq(ib_srq); + struct hns_roce_v2_wqe_data_seg *dseg; + struct hns_roce_db srq_db; + int ret = 0; + int wqe_idx; + void *wqe; + int nreq; + int ind; + int i; + + pthread_spin_lock(&srq->lock); + + /* current idx of srqwq */ + ind = srq->head & (srq->max - 1); + + for (nreq = 0; wr; ++nreq, wr = wr->next) { + if (wr->num_sge > srq->max_gs) { + ret = -1; + *bad_wr = wr; + break; + } + + if (srq->head == srq->tail) { + /* SRQ is full*/ + ret = -1; + *bad_wr = wr; + break; + } + + wqe_idx = find_empty_entry(&srq->idx_que); + fill_idx_que(&srq->idx_que, ind, wqe_idx); + + wqe = get_srq_wqe(srq, wqe_idx); + dseg = (struct hns_roce_v2_wqe_data_seg *)wqe; + + for (i = 0; i < wr->num_sge; ++i) { + dseg[i].len = htole32(wr->sg_list[i].length); + dseg[i].lkey = htole32(wr->sg_list[i].lkey); + dseg[i].addr = htole64(wr->sg_list[i].addr); + } + + if (i < srq->max_gs) { + dseg->len = 0; + dseg->lkey = htole32(0x100); + dseg->addr = 0; + } + + srq->wrid[wqe_idx] = wr->wr_id; + ind = (ind + 1) & (srq->max - 1); + } + + if (nreq) { + srq->head += nreq; + + /* + * Make sure that descriptors are written before + * we write doorbell record. + */ + udma_to_device_barrier(); + + srq_db.byte_4 = htole32(2 << 24 | srq->srqn); + srq_db.parameter = htole32(srq->head); + + hns_roce_write64((uint32_t *)&srq_db, ctx, + ROCEE_VF_DB_CFG0_OFFSET); + } + + pthread_spin_unlock(&srq->lock); + + return ret; +} + const struct hns_roce_u_hw hns_roce_u_hw_v2 = { .hw_version = HNS_ROCE_HW_VER2, .hw_ops = { @@ -1145,5 +1251,6 @@ const struct hns_roce_u_hw hns_roce_u_hw_v2 = { .post_recv = hns_roce_u_v2_post_recv, .modify_qp = hns_roce_u_v2_modify_qp, .destroy_qp = hns_roce_u_v2_destroy_qp, + .post_srq_recv = hns_roce_u_v2_post_srq_recv, }, }; From patchwork Sat Oct 27 10:56:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lijun Ou X-Patchwork-Id: 10658341 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2727513A9 for ; Sat, 27 Oct 2018 10:54:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 207402B1A1 for ; Sat, 27 Oct 2018 10:54:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 149552B562; Sat, 27 Oct 2018 10:54:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B127E2B1A1 for ; Sat, 27 Oct 2018 10:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728488AbeJ0TfV (ORCPT ); Sat, 27 Oct 2018 15:35:21 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:14146 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728474AbeJ0TfV (ORCPT ); Sat, 27 Oct 2018 15:35:21 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9CD529D726BC9; Sat, 27 Oct 2018 18:54:42 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.408.0; Sat, 27 Oct 2018 18:54:40 +0800 From: Lijun Ou To: , CC: , Subject: [PATCH rdma-core 6/6] libhns: Update poll cq for supporting srq Date: Sat, 27 Oct 2018 18:56:37 +0800 Message-ID: <1540637797-97065-7-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1540637797-97065-1-git-send-email-oulijun@huawei.com> References: <1540637797-97065-1-git-send-email-oulijun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When poll cqe generated by srq wqe, it need to get the corresponding cqe and free the srq wqe index, write it into the queue and update the wqe index. This patch mainly implements the above operation. Signed-off-by: Lijun Ou --- providers/hns/hns_roce_u_hw_v2.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/providers/hns/hns_roce_u_hw_v2.c b/providers/hns/hns_roce_u_hw_v2.c index bdf8bbb..d00bd42 100644 --- a/providers/hns/hns_roce_u_hw_v2.c +++ b/providers/hns/hns_roce_u_hw_v2.c @@ -154,6 +154,21 @@ static void *get_srq_wqe(struct hns_roce_srq *srq, int n) return srq->buf.buf + (n << srq->wqe_shift); } +static void hns_roce_free_srq_wqe(struct hns_roce_srq *srq, int ind) +{ + uint32_t bitmap_num; + int bit_num; + + pthread_spin_lock(&srq->lock); + + bitmap_num = ind / (sizeof(uint64_t) * BIT_CNT_PER_BYTE); + bit_num = ind % (sizeof(uint64_t) * BIT_CNT_PER_BYTE); + srq->idx_que.bitmap[bitmap_num] |= (1ULL << bit_num); + srq->tail++; + + pthread_spin_unlock(&srq->lock); +} + static int hns_roce_v2_wq_overflow(struct hns_roce_wq *wq, int nreq, struct hns_roce_cq *cq) { @@ -268,6 +283,7 @@ static int hns_roce_v2_poll_one(struct hns_roce_cq *cq, struct hns_roce_wq *wq = NULL; struct hns_roce_v2_cqe *cqe = NULL; struct hns_roce_rinl_sge *sge_list; + struct hns_roce_srq *srq = NULL; uint32_t opcode; struct ibv_qp_attr attr; int attr_mask; @@ -305,6 +321,7 @@ static int hns_roce_v2_poll_one(struct hns_roce_cq *cq, } wc->qp_num = qpn & 0xffffff; + srq = (*cur_qp)->ibv_qp.srq ? to_hr_srq((*cur_qp)->ibv_qp.srq) : NULL; if (is_send) { wq = &(*cur_qp)->sq; /* @@ -325,6 +342,12 @@ static int hns_roce_v2_poll_one(struct hns_roce_cq *cq, /* write the wr_id of wq into the wc */ wc->wr_id = wq->wrid[wq->tail & (wq->wqe_cnt - 1)]; ++wq->tail; + } else if (srq) { + wqe_ctr = (uint16_t)(roce_get_field(cqe->byte_4, + CQE_BYTE_4_WQE_IDX_M, + CQE_BYTE_4_WQE_IDX_S)); + wc->wr_id = srq->wrid[wqe_ctr]; + hns_roce_free_srq_wqe(srq, wqe_ctr); } else { wq = &(*cur_qp)->rq; wc->wr_id = wq->wrid[wq->tail & (wq->wqe_cnt - 1)];